-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: dispatch Event Plugin * feat: version bump * feat: lint and build fix * feat: test fix * feat: pr comments fixes * feat: pr comments fix, test fix * feat: test fix * feat: test fix * feat: conflict
- Loading branch information
1 parent
45ba659
commit 242c9c7
Showing
39 changed files
with
690 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# @ballerine/workflow-core | ||
|
||
## 0.6.11 | ||
|
||
### Patch Changes | ||
|
||
- Version bump | ||
|
||
## 0.6.10 | ||
|
||
### Patch Changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "@ballerine/workflow-core", | ||
"author": "Ballerine <[email protected]>", | ||
"version": "0.6.10", | ||
"version": "0.6.11", | ||
"description": "workflow-core", | ||
"module": "./dist/esm/index.js", | ||
"main": "./dist/cjs/index.js", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/workflow-core/src/lib/plugins/external-plugin/dispatch-event-plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { IDispatchEventPluginParams } from './types'; | ||
import { WorkflowRunner } from '../../../lib/workflow-runner'; | ||
import { Transformer, Transformers } from '../../../lib/utils'; | ||
import { AnyRecord, isErrorWithMessage } from '@ballerine/common'; | ||
|
||
export type IDispatchEventPluginParamsWithTransfomers = Omit< | ||
IDispatchEventPluginParams, | ||
'transformers' | ||
> & { | ||
transformers: ReturnType<WorkflowRunner['fetchTransformers']>; | ||
}; | ||
|
||
export class DispatchEventPlugin { | ||
public static pluginKind = 'dispatch-event'; | ||
name: string; | ||
eventName: string; | ||
payload?: AnyRecord; | ||
stateNames: string[]; | ||
errorAction?: string; | ||
successAction?: string; | ||
transformers?: Transformers; | ||
displayName: string | undefined; | ||
|
||
constructor(pluginParams: IDispatchEventPluginParamsWithTransfomers) { | ||
this.name = pluginParams.name; | ||
this.payload = pluginParams.payload; | ||
this.eventName = pluginParams.eventName; | ||
this.stateNames = pluginParams.stateNames; | ||
this.errorAction = pluginParams.errorAction; | ||
this.displayName = pluginParams.displayName; | ||
this.transformers = pluginParams.transformers; | ||
this.successAction = pluginParams.successAction; | ||
} | ||
|
||
async getPluginEvent(record: AnyRecord) { | ||
return { | ||
eventName: this.eventName, | ||
event: { | ||
type: this.eventName, | ||
payload: await this.__transformData(this.transformers || [], { | ||
...record, | ||
...this.payload, | ||
}), | ||
state: this.stateNames[0] ?? '', | ||
}, | ||
}; | ||
} | ||
|
||
private async __transformData(transformers: Transformers, record: AnyRecord) { | ||
let mutatedRecord = record; | ||
|
||
for (const transformer of transformers) { | ||
mutatedRecord = await this.__transformByTransformer(transformer, mutatedRecord); | ||
} | ||
|
||
return mutatedRecord; | ||
} | ||
|
||
private async __transformByTransformer(transformer: Transformer, record: AnyRecord) { | ||
try { | ||
return (await transformer.transform(record, { input: 'json', output: 'json' })) as AnyRecord; | ||
} catch (error) { | ||
throw new Error( | ||
`Error transforming data: ${ | ||
isErrorWithMessage(error) ? error.message : '' | ||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
} for transformer mapping: ${JSON.stringify(transformer.mapping)}`, | ||
); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/workflow-core/src/lib/plugins/external-plugin/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.