@outputai/core 0.10.0 → 0.10.1-next.09ed166.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/bus.js +58 -20
- package/src/bus.spec.js +135 -77
- package/src/consts.js +2 -1
- package/src/helpers/object.js +48 -35
- package/src/helpers/object.spec.js +123 -75
- package/src/hooks/index.d.ts +48 -45
- package/src/hooks/index.js +49 -44
- package/src/hooks/index.spec.js +74 -102
- package/src/interface/workflow.js +92 -85
- package/src/interface/workflow.spec.js +135 -142
- package/src/sdk/helpers/objects.d.ts +24 -19
- package/src/sdk/runtime/events.d.ts +4 -6
- package/src/sdk/runtime/events.js +2 -15
- package/src/sdk/runtime/events.spec.js +14 -92
- package/src/worker/global_functions.js +2 -2
- package/src/worker/global_functions.spec.js +3 -3
- package/src/worker/index.js +3 -3
- package/src/worker/index.spec.js +6 -6
- package/src/worker/interceptors/activity.js +4 -4
- package/src/worker/interceptors/activity.spec.js +9 -9
- package/src/worker/interceptors/workflow.js +5 -5
- package/src/worker/interceptors/workflow.spec.js +7 -7
- package/src/worker/loader/activities.js +56 -40
- package/src/worker/loader/activities.spec.js +21 -22
- package/src/worker/loader/workflows.spec.js +1 -2
- package/src/worker/log_hooks.js +9 -9
- package/src/worker/log_hooks.spec.js +2 -2
- package/src/worker/sinks.js +8 -8
- package/src/worker/sinks.spec.js +9 -9
- package/src/worker/webpack_loaders/consts.js +6 -0
- package/src/worker/webpack_loaders/tools.js +1 -146
- package/src/worker/webpack_loaders/tools.spec.js +0 -23
- package/src/worker/webpack_loaders/workflow_rewriter/collect_target_imports.js +24 -32
- package/src/worker/webpack_loaders/workflow_rewriter/collect_target_imports.spec.js +82 -279
- package/src/worker/webpack_loaders/workflow_rewriter/index.mjs +6 -7
- package/src/worker/webpack_loaders/workflow_rewriter/index.spec.js +57 -119
- package/src/worker/webpack_loaders/workflow_rewriter/rewrite_activity_calls.js +88 -0
- package/src/worker/webpack_loaders/workflow_rewriter/rewrite_activity_calls.spec.js +165 -0
- package/src/worker/webpack_loaders/workflow_validator/index.mjs +96 -29
- package/src/worker/webpack_loaders/workflow_validator/index.spec.js +110 -583
- package/src/worker/webpack_loaders/{npm_workflow_export_resolve.js → workflow_validator/npm_workflow_export_resolve.js} +1 -1
- package/src/worker/webpack_loaders/{npm_workflow_export_resolve.spec.js → workflow_validator/npm_workflow_export_resolve.spec.js} +1 -1
- package/src/worker/webpack_loaders/workflow_rewriter/rewrite_fn_bodies.js +0 -193
- package/src/worker/webpack_loaders/workflow_rewriter/rewrite_fn_bodies.spec.js +0 -123
|
@@ -95,98 +95,86 @@ describe( 'clone', () => {
|
|
|
95
95
|
} );
|
|
96
96
|
|
|
97
97
|
describe( 'deepMerge', () => {
|
|
98
|
-
it( '
|
|
98
|
+
it( 'returns a clone when only the base object is provided', () => {
|
|
99
99
|
const a = {
|
|
100
|
-
|
|
101
|
-
b: {
|
|
102
|
-
c: 2
|
|
103
|
-
}
|
|
100
|
+
nested: { value: 1 }
|
|
104
101
|
};
|
|
105
|
-
const
|
|
106
|
-
a: false,
|
|
107
|
-
b: {
|
|
108
|
-
c: true
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
expect( deepMerge( a, b ) ).toEqual( {
|
|
112
|
-
a: false,
|
|
113
|
-
b: {
|
|
114
|
-
c: true
|
|
115
|
-
}
|
|
116
|
-
} );
|
|
117
|
-
} );
|
|
102
|
+
const result = deepMerge( a );
|
|
118
103
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const b = {
|
|
124
|
-
a: false,
|
|
125
|
-
b: true
|
|
126
|
-
};
|
|
127
|
-
expect( deepMerge( a, b ) ).toEqual( {
|
|
128
|
-
a: false,
|
|
129
|
-
b: true
|
|
104
|
+
a.nested.value = 2;
|
|
105
|
+
|
|
106
|
+
expect( result ).toEqual( {
|
|
107
|
+
nested: { value: 1 }
|
|
130
108
|
} );
|
|
131
109
|
} );
|
|
132
110
|
|
|
133
|
-
it( '
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
111
|
+
it( 'Throws when first argument is not a plain object', () => {
|
|
112
|
+
expect( () => deepMerge( null ) ).toThrow( Error );
|
|
113
|
+
} );
|
|
114
|
+
|
|
115
|
+
it( 'merges multiple objects from left to right using rightmost values', () => {
|
|
116
|
+
expect( deepMerge(
|
|
117
|
+
{
|
|
118
|
+
a: 1,
|
|
119
|
+
nested: {
|
|
120
|
+
a: 'base',
|
|
121
|
+
kept: true
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
b: 2,
|
|
126
|
+
nested: {
|
|
127
|
+
a: 'first',
|
|
128
|
+
b: 'first'
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
a: 3,
|
|
133
|
+
nested: {
|
|
134
|
+
b: 'second',
|
|
135
|
+
c: 'second'
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
) ).toEqual( {
|
|
139
|
+
a: 3,
|
|
140
|
+
b: 2,
|
|
141
|
+
nested: {
|
|
142
|
+
a: 'first',
|
|
143
|
+
b: 'second',
|
|
144
|
+
c: 'second',
|
|
145
|
+
kept: true
|
|
146
|
+
}
|
|
143
147
|
} );
|
|
144
148
|
} );
|
|
145
149
|
|
|
146
|
-
it( '
|
|
147
|
-
|
|
148
|
-
a: 1
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
150
|
+
it( 'ignores non-object values among multiple overlays', () => {
|
|
151
|
+
expect( deepMerge(
|
|
152
|
+
{ a: 1 },
|
|
153
|
+
null,
|
|
154
|
+
{ b: 2 },
|
|
155
|
+
undefined,
|
|
156
|
+
{ a: 3 }
|
|
157
|
+
) ).toEqual( {
|
|
158
|
+
a: 3,
|
|
159
|
+
b: 2
|
|
160
|
+
} );
|
|
157
161
|
} );
|
|
162
|
+
} );
|
|
158
163
|
|
|
159
|
-
|
|
164
|
+
describe( 'deepMergeWithResolver', () => {
|
|
165
|
+
it( 'returns a clone when only the base object and resolver are provided', () => {
|
|
160
166
|
const a = {
|
|
161
|
-
|
|
167
|
+
nested: { value: 1 }
|
|
162
168
|
};
|
|
163
|
-
|
|
164
|
-
expect( deepMerge( a, undefined ) ).toEqual( { a: 1 } );
|
|
165
|
-
} );
|
|
169
|
+
const result = deepMergeWithResolver( a, ( x, y ) => x + y );
|
|
166
170
|
|
|
167
|
-
|
|
168
|
-
const a = {
|
|
169
|
-
a: 1
|
|
170
|
-
};
|
|
171
|
-
const result = deepMerge( a, null );
|
|
172
|
-
a.a = 2;
|
|
173
|
-
expect( result.a ).toEqual( 1 );
|
|
174
|
-
} );
|
|
171
|
+
a.nested.value = 2;
|
|
175
172
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
expect( () => deepMerge( 'a' ) ).toThrow( Error );
|
|
180
|
-
expect( () => deepMerge( true ) ).toThrow( Error );
|
|
181
|
-
expect( () => deepMerge( /a/ ) ).toThrow( Error );
|
|
182
|
-
expect( () => deepMerge( [] ) ).toThrow( Error );
|
|
183
|
-
expect( () => deepMerge( class Foo {}, class Foo {} ) ).toThrow( Error );
|
|
184
|
-
expect( () => deepMerge( Number.constructor, Number.constructor ) ).toThrow( Error );
|
|
185
|
-
expect( () => deepMerge( Number.constructor.prototype, Number.constructor.prototype ) ).toThrow( Error );
|
|
173
|
+
expect( result ).toEqual( {
|
|
174
|
+
nested: { value: 1 }
|
|
175
|
+
} );
|
|
186
176
|
} );
|
|
187
|
-
} );
|
|
188
177
|
|
|
189
|
-
describe( 'deepMergeWithResolver', () => {
|
|
190
178
|
it( 'uses resolver for existing leaf values, including nested leaves', () => {
|
|
191
179
|
const a = {
|
|
192
180
|
cost: { total: 1 },
|
|
@@ -235,6 +223,66 @@ describe( 'deepMergeWithResolver', () => {
|
|
|
235
223
|
expect( () => deepMergeWithResolver( [], {}, ( x, y ) => x + y ) ).toThrow( Error );
|
|
236
224
|
expect( () => deepMergeWithResolver( 'a', {}, ( x, y ) => x + y ) ).toThrow( Error );
|
|
237
225
|
} );
|
|
226
|
+
|
|
227
|
+
it( 'throws when last argument is not a resolver function', () => {
|
|
228
|
+
expect( () => deepMergeWithResolver( { a: 1 }, { a: 2 } ) )
|
|
229
|
+
.toThrow( 'Last argument (resolver) is not a function.' );
|
|
230
|
+
} );
|
|
231
|
+
|
|
232
|
+
it( 'merges multiple objects using the resolver from left to right', () => {
|
|
233
|
+
const resolver = vi.fn( ( x, y ) => `${ x }:${ y }` );
|
|
234
|
+
|
|
235
|
+
expect( deepMergeWithResolver(
|
|
236
|
+
{
|
|
237
|
+
a: 'base',
|
|
238
|
+
nested: {
|
|
239
|
+
count: 1,
|
|
240
|
+
kept: 'yes'
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
a: 'first',
|
|
245
|
+
nested: {
|
|
246
|
+
count: 2,
|
|
247
|
+
firstOnly: true
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
a: 'second',
|
|
252
|
+
nested: {
|
|
253
|
+
count: 3,
|
|
254
|
+
secondOnly: true
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
resolver
|
|
258
|
+
) ).toEqual( {
|
|
259
|
+
a: 'base:first:second',
|
|
260
|
+
nested: {
|
|
261
|
+
count: '1:2:3',
|
|
262
|
+
firstOnly: true,
|
|
263
|
+
kept: 'yes',
|
|
264
|
+
secondOnly: true
|
|
265
|
+
}
|
|
266
|
+
} );
|
|
267
|
+
expect( resolver ).toHaveBeenCalledTimes( 4 );
|
|
268
|
+
} );
|
|
269
|
+
|
|
270
|
+
it( 'ignores non-object values among multiple resolver overlays', () => {
|
|
271
|
+
const resolver = vi.fn( ( x, y ) => x + y );
|
|
272
|
+
|
|
273
|
+
expect( deepMergeWithResolver(
|
|
274
|
+
{ a: 1 },
|
|
275
|
+
null,
|
|
276
|
+
{ a: 2 },
|
|
277
|
+
undefined,
|
|
278
|
+
{ b: 3 },
|
|
279
|
+
resolver
|
|
280
|
+
) ).toEqual( {
|
|
281
|
+
a: 3,
|
|
282
|
+
b: 3
|
|
283
|
+
} );
|
|
284
|
+
expect( resolver ).toHaveBeenCalledOnce();
|
|
285
|
+
} );
|
|
238
286
|
} );
|
|
239
287
|
|
|
240
288
|
describe( 'isPlainObject', () => {
|
package/src/hooks/index.d.ts
CHANGED
|
@@ -99,35 +99,19 @@ export interface Aggregations {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
|
-
* Common
|
|
102
|
+
* Common hook payload fields
|
|
103
103
|
*/
|
|
104
104
|
export interface HookPayloadBase {
|
|
105
105
|
/** UUID v4 stamped per emit. Stable per-emit idempotency key. */
|
|
106
106
|
eventId: string;
|
|
107
107
|
/** Timestamp of the event */
|
|
108
108
|
eventDate: number;
|
|
109
|
-
/** Information about the current workflow execution */
|
|
110
|
-
workflowDetails: WorkflowDetails;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Common hook payload fields for events associated with an activity.
|
|
115
|
-
*/
|
|
116
|
-
export interface ActivityPayloadBase extends HookPayloadBase {
|
|
117
|
-
/** Temporal's activityInfo(). */
|
|
118
|
-
activityInfo: Info;
|
|
119
|
-
/** Output component kind for the activity, e.g. step or evaluator. */
|
|
120
|
-
outputActivityKind: string;
|
|
121
109
|
}
|
|
122
110
|
|
|
123
111
|
/**
|
|
124
112
|
* Payload passed to the onError() handler when a workflow, activity or runtime error occurs.
|
|
125
113
|
*/
|
|
126
|
-
export interface ErrorHookPayload {
|
|
127
|
-
/** UUID v4 stamped per emit. Stable per-emit idempotency key. */
|
|
128
|
-
eventId: string;
|
|
129
|
-
/** Timestamp of the event */
|
|
130
|
-
eventDate: number;
|
|
114
|
+
export interface ErrorHookPayload extends HookPayloadBase {
|
|
131
115
|
/** Origin of the error: workflow execution, activity execution, or runtime. */
|
|
132
116
|
source: 'workflow' | 'activity' | 'runtime';
|
|
133
117
|
/** Information about the current workflow execution */
|
|
@@ -135,45 +119,60 @@ export interface ErrorHookPayload {
|
|
|
135
119
|
/** Temporal's activityInfo(). If source is activity */
|
|
136
120
|
activityInfo?: Info;
|
|
137
121
|
/** Output component kind for the activity, e.g. step, evaluator, or internal_step. */
|
|
138
|
-
outputActivityKind
|
|
122
|
+
outputActivityKind: string;
|
|
139
123
|
/** Attribute totals collected during the activity execution. */
|
|
140
124
|
aggregations?: Aggregations | null;
|
|
141
125
|
/** The error thrown. */
|
|
142
126
|
error: Error;
|
|
143
127
|
}
|
|
144
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Common hook payload fields for events associated with an workflow.
|
|
131
|
+
*/
|
|
132
|
+
export interface WorkflowPayloadBase extends HookPayloadBase {
|
|
133
|
+
/** Information about the current workflow execution */
|
|
134
|
+
workflowDetails: WorkflowDetails;
|
|
135
|
+
}
|
|
136
|
+
|
|
145
137
|
/**
|
|
146
138
|
* Payload passed to the onWorkflowStart() handler when a workflow run begins.
|
|
147
139
|
*/
|
|
148
|
-
export type WorkflowStartHookPayload =
|
|
140
|
+
export type WorkflowStartHookPayload = WorkflowPayloadBase;
|
|
149
141
|
|
|
150
142
|
/**
|
|
151
143
|
* Payload passed to the onWorkflowEnd() handler when a workflow run completes successfully.
|
|
152
144
|
*/
|
|
153
|
-
export type WorkflowEndHookPayload =
|
|
145
|
+
export type WorkflowEndHookPayload = WorkflowPayloadBase;
|
|
154
146
|
|
|
155
147
|
/**
|
|
156
148
|
* Payload passed to the onWorkflowError() handler when a workflow run fails.
|
|
157
149
|
*/
|
|
158
|
-
export interface WorkflowErrorHookPayload extends
|
|
150
|
+
export interface WorkflowErrorHookPayload extends WorkflowPayloadBase {
|
|
159
151
|
/** The error thrown. */
|
|
160
152
|
error: Error;
|
|
161
153
|
}
|
|
162
154
|
|
|
163
155
|
/**
|
|
164
|
-
* Common
|
|
156
|
+
* Common hook payload fields for events associated with an activity.
|
|
165
157
|
*/
|
|
166
|
-
export
|
|
158
|
+
export interface ActivityPayloadBase extends HookPayloadBase {
|
|
159
|
+
/** Information about the current workflow execution */
|
|
160
|
+
workflowDetails: WorkflowDetails;
|
|
161
|
+
/** Temporal's activityInfo(). */
|
|
162
|
+
activityInfo: Info;
|
|
163
|
+
/** Output component kind for the activity, e.g. step, evaluator, or internal_step. */
|
|
164
|
+
outputActivityKind: string;
|
|
165
|
+
}
|
|
167
166
|
|
|
168
167
|
/**
|
|
169
168
|
* Payload passed to the onActivityStart() handler when an activity starts.
|
|
170
169
|
*/
|
|
171
|
-
export type ActivityStartHookPayload =
|
|
170
|
+
export type ActivityStartHookPayload = ActivityPayloadBase;
|
|
172
171
|
|
|
173
172
|
/**
|
|
174
173
|
* Payload passed to the onActivityEnd() handler when an activity completes successfully.
|
|
175
174
|
*/
|
|
176
|
-
export interface ActivityEndHookPayload extends
|
|
175
|
+
export interface ActivityEndHookPayload extends ActivityPayloadBase {
|
|
177
176
|
/** Attribute totals collected during the activity execution. */
|
|
178
177
|
aggregations: Aggregations | null;
|
|
179
178
|
}
|
|
@@ -181,7 +180,7 @@ export interface ActivityEndHookPayload extends ActivityHookPayload {
|
|
|
181
180
|
/**
|
|
182
181
|
* Payload passed to the onActivityError() handler when an activity fails.
|
|
183
182
|
*/
|
|
184
|
-
export interface ActivityErrorHookPayload extends
|
|
183
|
+
export interface ActivityErrorHookPayload extends ActivityPayloadBase {
|
|
185
184
|
/** Attribute totals collected during the activity execution. */
|
|
186
185
|
aggregations: Aggregations | null;
|
|
187
186
|
/** The error thrown. */
|
|
@@ -233,8 +232,6 @@ export declare function onWorkflowError( handler: ( payload: WorkflowErrorHookPa
|
|
|
233
232
|
/**
|
|
234
233
|
* Register a handler to be invoked when an activity starts.
|
|
235
234
|
*
|
|
236
|
-
* Excludes internal activities.
|
|
237
|
-
*
|
|
238
235
|
* @param handler - Function called with the activity start payload.
|
|
239
236
|
*/
|
|
240
237
|
export declare function onActivityStart( handler: ( payload: ActivityStartHookPayload ) => void ): void;
|
|
@@ -242,8 +239,6 @@ export declare function onActivityStart( handler: ( payload: ActivityStartHookPa
|
|
|
242
239
|
/**
|
|
243
240
|
* Register a handler to be invoked when an activity completes successfully.
|
|
244
241
|
*
|
|
245
|
-
* Excludes internal activities.
|
|
246
|
-
*
|
|
247
242
|
* @param handler - Function called with the activity end payload.
|
|
248
243
|
*/
|
|
249
244
|
export declare function onActivityEnd( handler: ( payload: ActivityEndHookPayload ) => void ): void;
|
|
@@ -251,24 +246,32 @@ export declare function onActivityEnd( handler: ( payload: ActivityEndHookPayloa
|
|
|
251
246
|
/**
|
|
252
247
|
* Register a handler to be invoked when an activity fails.
|
|
253
248
|
*
|
|
254
|
-
* Excludes internal activities.
|
|
255
|
-
*
|
|
256
249
|
* @param handler - Function called with the activity error payload.
|
|
257
250
|
*/
|
|
258
251
|
export declare function onActivityError( handler: ( payload: ActivityErrorHookPayload ) => void ): void;
|
|
259
252
|
|
|
260
|
-
/**
|
|
261
|
-
|
|
262
|
-
*/
|
|
263
|
-
|
|
264
|
-
/** Temporal's activityInfo(). */
|
|
265
|
-
activityInfo
|
|
266
|
-
/** Output component kind
|
|
253
|
+
/** Framework metadata, optional activity context, and the emitted payload. */
|
|
254
|
+
export type ExternalHookPayload<TPayload = unknown> = HookPayloadBase & {
|
|
255
|
+
/** Information about the current workflow execution, when emitted from an activity. */
|
|
256
|
+
workflowDetails?: WorkflowDetails;
|
|
257
|
+
/** Temporal's activityInfo(), when emitted from an activity. */
|
|
258
|
+
activityInfo?: Info;
|
|
259
|
+
/** Output component kind, when emitted from an activity. */
|
|
267
260
|
outputActivityKind?: string;
|
|
268
|
-
|
|
261
|
+
/** The emitted payload */
|
|
262
|
+
payload: TPayload | undefined;
|
|
263
|
+
};
|
|
269
264
|
|
|
270
|
-
|
|
271
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Emit a custom event from the current activity.
|
|
267
|
+
*
|
|
268
|
+
* @param eventName - The name of the event to emit.
|
|
269
|
+
* @param payload - Optional value forwarded to on() handlers.
|
|
270
|
+
*/
|
|
271
|
+
export declare function emit(
|
|
272
|
+
eventName: string,
|
|
273
|
+
payload?: unknown
|
|
274
|
+
): boolean;
|
|
272
275
|
|
|
273
276
|
/**
|
|
274
277
|
* Register a handler to be invoked when a given event happens
|
|
@@ -276,7 +279,7 @@ export type OnHookPayload<TAttributes extends Record<string, unknown> = Record<s
|
|
|
276
279
|
* @param eventName - The name of the event to subscribe
|
|
277
280
|
* @param handler - Function called with the event payload
|
|
278
281
|
*/
|
|
279
|
-
export declare function on<
|
|
282
|
+
export declare function on<TPayload = unknown>(
|
|
280
283
|
eventName: string,
|
|
281
|
-
handler: (
|
|
284
|
+
handler: ( event: ExternalHookPayload<TPayload> ) => void
|
|
282
285
|
): void;
|
package/src/hooks/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BusEventType
|
|
1
|
+
import { mainEventBus, stepEventBus } from '#bus';
|
|
2
|
+
import { BusEventType } from '#consts';
|
|
3
3
|
import { createChildLogger } from '#logger';
|
|
4
4
|
|
|
5
5
|
const log = createChildLogger( 'Hooks' );
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Invokes
|
|
8
|
+
* Invokes a function within a try catch and log the error
|
|
9
9
|
*
|
|
10
10
|
* @param {Function} fn
|
|
11
11
|
* @param {any} args - Args to invoke the function with
|
|
12
12
|
* @param {string} hookName - hookName to identify this hook function in the logs
|
|
13
13
|
*/
|
|
14
|
-
const
|
|
14
|
+
const callHookCb = async ( fn, args, hookName ) => {
|
|
15
15
|
try {
|
|
16
16
|
await fn( args );
|
|
17
17
|
} catch ( error ) {
|
|
@@ -19,50 +19,55 @@ const safeInvoke = async ( fn, args, hookName ) => {
|
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
// General Life-cycle
|
|
23
|
+
// --------------------------------------
|
|
24
|
+
const onError = cb => {
|
|
25
|
+
mainEventBus.on( BusEventType.ACTIVITY_ERROR, async payload =>
|
|
26
|
+
callHookCb( cb, { source: 'activity', ...payload }, 'onError' ) );
|
|
27
|
+
mainEventBus.on( BusEventType.WORKFLOW_ERROR, async payload =>
|
|
28
|
+
callHookCb( cb, { source: 'workflow', ...payload }, 'onError' ) );
|
|
29
|
+
mainEventBus.on( BusEventType.RUNTIME_ERROR, async payload =>
|
|
30
|
+
callHookCb( cb, { source: 'runtime', ...payload }, 'onError' ) );
|
|
30
31
|
};
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
export const onBeforeWorkerStart = handler => messageBus.on( BusEventType.WORKER_BEFORE_START, () =>
|
|
34
|
-
safeInvoke( handler, undefined, 'onBeforeWorkerStart' ) );
|
|
33
|
+
const onBeforeWorkerStart = cb => mainEventBus.on( BusEventType.WORKER_BEFORE_START, () => callHookCb( cb, undefined, 'onBeforeWorkerStart' ) );
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
// Workflow Life-cycle
|
|
36
|
+
// --------------------------------------
|
|
37
|
+
const onWorkflowStart = cb => mainEventBus.on( BusEventType.WORKFLOW_START, payload => callHookCb( cb, payload, 'onWorkflowStart' ) );
|
|
38
|
+
const onWorkflowEnd = cb => mainEventBus.on( BusEventType.WORKFLOW_END, payload => callHookCb( cb, payload, 'onWorkflowEnd' ) );
|
|
39
|
+
const onWorkflowError = cb => mainEventBus.on( BusEventType.WORKFLOW_ERROR, payload => callHookCb( cb, payload, 'onWorkflowError' ) );
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
// Activity Life-cycle
|
|
42
|
+
// --------------------------------------
|
|
43
|
+
const onActivityStart = cb => mainEventBus.on( BusEventType.ACTIVITY_START, fields => callHookCb( cb, fields, 'onActivityStart' ) );
|
|
44
|
+
const onActivityEnd = cb => mainEventBus.on( BusEventType.ACTIVITY_END, fields => callHookCb( cb, fields, 'onActivityEnd' ) );
|
|
45
|
+
const onActivityError = cb => mainEventBus.on( BusEventType.ACTIVITY_ERROR, fields => callHookCb( cb, fields, 'onActivityError' ) );
|
|
42
46
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
/** Internal activities do not trigger hooks */
|
|
52
|
-
const shouldEmitActivityEvent = outputActivityKind => outputActivityKind !== ComponentType.INTERNAL_STEP;
|
|
53
|
-
|
|
54
|
-
/** Listen to workflow start events, excludes catalog workflow */
|
|
55
|
-
export const onActivityStart = handler => messageBus.on( BusEventType.ACTIVITY_START, ( { outputActivityKind, ...eventFields } ) =>
|
|
56
|
-
shouldEmitActivityEvent( outputActivityKind ) ? safeInvoke( handler, { outputActivityKind, ...eventFields }, 'onActivityStart' ) : null );
|
|
57
|
-
|
|
58
|
-
/** Listen to workflow end events, excludes catalog workflow */
|
|
59
|
-
export const onActivityEnd = handler => messageBus.on( BusEventType.ACTIVITY_END, ( { outputActivityKind, ...eventFields } ) =>
|
|
60
|
-
shouldEmitActivityEvent( outputActivityKind ) ? safeInvoke( handler, { outputActivityKind, ...eventFields }, 'onActivityEnd' ) : null );
|
|
47
|
+
// Generic Events
|
|
48
|
+
// --------------------------------------
|
|
49
|
+
/** Listen to both sdk and custom events */
|
|
50
|
+
const on = ( eventName, cb ) => {
|
|
51
|
+
stepEventBus.on( `sdk:${eventName}`, payload => callHookCb( cb, payload, eventName ) );
|
|
52
|
+
stepEventBus.on( `usr:${eventName}`, payload => callHookCb( cb, payload, eventName ) );
|
|
53
|
+
};
|
|
61
54
|
|
|
62
|
-
/**
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Emits a custom event
|
|
57
|
+
* @param {string} eventName
|
|
58
|
+
* @param {any} payload
|
|
59
|
+
*/
|
|
60
|
+
const emit = ( eventName, payload ) => stepEventBus.emit( `usr:${eventName}`, payload );
|
|
65
61
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
export {
|
|
63
|
+
emit,
|
|
64
|
+
on,
|
|
65
|
+
onActivityEnd,
|
|
66
|
+
onActivityError,
|
|
67
|
+
onActivityStart,
|
|
68
|
+
onBeforeWorkerStart,
|
|
69
|
+
onError,
|
|
70
|
+
onWorkflowEnd,
|
|
71
|
+
onWorkflowError,
|
|
72
|
+
onWorkflowStart
|
|
73
|
+
};
|