@wooksjs/event-wf 0.3.8 → 0.3.9
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/dist/index.cjs +11 -6
- package/dist/index.d.ts +6 -1
- package/dist/index.mjs +11 -6
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -94,9 +94,9 @@ class WooksWf extends wooks.WooksAdapterBase {
|
|
|
94
94
|
const step = wf.createStep(id, opts);
|
|
95
95
|
return this.on('WF_STEP', id, () => step);
|
|
96
96
|
}
|
|
97
|
-
flow(id, schema) {
|
|
97
|
+
flow(id, schema, init) {
|
|
98
98
|
this.wf.register(id, schema);
|
|
99
|
-
return this.on('WF_FLOW', id, () => id);
|
|
99
|
+
return this.on('WF_FLOW', id, () => ({ init, id }));
|
|
100
100
|
}
|
|
101
101
|
start(schemaId, inputContext, input) {
|
|
102
102
|
return this._start(schemaId, inputContext, undefined, input);
|
|
@@ -122,13 +122,17 @@ class WooksWf extends wooks.WooksAdapterBase {
|
|
|
122
122
|
let result = {};
|
|
123
123
|
for (const handler of handlers) {
|
|
124
124
|
restoreCtx();
|
|
125
|
-
const
|
|
125
|
+
const { id, init } = (yield handler());
|
|
126
|
+
if (init) {
|
|
127
|
+
yield init();
|
|
128
|
+
restoreCtx();
|
|
129
|
+
}
|
|
126
130
|
if (resume) {
|
|
127
|
-
result = yield this.wf.resume(
|
|
131
|
+
result = yield this.wf.resume(id, { context: inputContext, indexes }, input);
|
|
128
132
|
break;
|
|
129
133
|
}
|
|
130
134
|
else {
|
|
131
|
-
result = yield this.wf.start(
|
|
135
|
+
result = yield this.wf.start(id, inputContext, input);
|
|
132
136
|
break;
|
|
133
137
|
}
|
|
134
138
|
}
|
|
@@ -169,13 +173,14 @@ function createWfApp(opts, wooks) {
|
|
|
169
173
|
}
|
|
170
174
|
|
|
171
175
|
function useWfState() {
|
|
172
|
-
const { store } = useWFContext();
|
|
176
|
+
const { store, getCtx } = useWFContext();
|
|
173
177
|
const event = store('event');
|
|
174
178
|
return {
|
|
175
179
|
ctx: () => event.get('inputContext'),
|
|
176
180
|
input: () => event.get('input'),
|
|
177
181
|
schemaId: event.get('schemaId'),
|
|
178
182
|
indexes: () => event.get('indexes'),
|
|
183
|
+
resume: getCtx().resume,
|
|
179
184
|
};
|
|
180
185
|
}
|
|
181
186
|
|
package/dist/index.d.ts
CHANGED
|
@@ -65,6 +65,8 @@ export declare function resumeWfContext(data: Omit<TWFEventData, 'type'>, option
|
|
|
65
65
|
setStore: <K_2 extends "resume" | keyof TGenericContextStore<TWFEventData>>(key: K_2, v: (TWFContextStore & TGenericContextStore<TWFEventData>)[K_2]) => void;
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
+
export { TStepHandler }
|
|
69
|
+
|
|
68
70
|
export declare interface TWFContextStore {
|
|
69
71
|
resume: boolean;
|
|
70
72
|
}
|
|
@@ -86,6 +88,8 @@ export declare interface TWooksWfOptions {
|
|
|
86
88
|
router?: TWooksOptions['router'];
|
|
87
89
|
}
|
|
88
90
|
|
|
91
|
+
export { TWorkflowSchema }
|
|
92
|
+
|
|
89
93
|
/**
|
|
90
94
|
* Wrapper on top of useEventContext that provides
|
|
91
95
|
* proper context types for WF event
|
|
@@ -118,6 +122,7 @@ export declare function useWfState(): {
|
|
|
118
122
|
input: <I>() => I | undefined;
|
|
119
123
|
schemaId: string;
|
|
120
124
|
indexes: () => number[] | undefined;
|
|
125
|
+
resume: boolean;
|
|
121
126
|
};
|
|
122
127
|
|
|
123
128
|
export declare const wfShortcuts: {
|
|
@@ -134,7 +139,7 @@ export declare class WooksWf<T> extends WooksAdapterBase {
|
|
|
134
139
|
input?: D;
|
|
135
140
|
handler: string | TStepHandler<T, I, D>;
|
|
136
141
|
}): TProstoRouterPathHandle<Record<string, string | string[]>>;
|
|
137
|
-
flow(id: string, schema: TWorkflowSchema<T>): TProstoRouterPathHandle<Record<string, string | string[]>>;
|
|
142
|
+
flow(id: string, schema: TWorkflowSchema<T>, init?: () => void | Promise<void>): TProstoRouterPathHandle<Record<string, string | string[]>>;
|
|
138
143
|
start<I>(schemaId: string, inputContext: T, input?: I): Promise<TFlowOutput<T, I>>;
|
|
139
144
|
resume<I>(schemaId: string, inputContext: T, indexes: number[], input?: I): Promise<TFlowOutput<T, I>>;
|
|
140
145
|
protected _start<I>(schemaId: string, inputContext: T, indexes?: number[], input?: I): Promise<TFlowOutput<T, I>>;
|
package/dist/index.mjs
CHANGED
|
@@ -92,9 +92,9 @@ class WooksWf extends WooksAdapterBase {
|
|
|
92
92
|
const step = createStep(id, opts);
|
|
93
93
|
return this.on('WF_STEP', id, () => step);
|
|
94
94
|
}
|
|
95
|
-
flow(id, schema) {
|
|
95
|
+
flow(id, schema, init) {
|
|
96
96
|
this.wf.register(id, schema);
|
|
97
|
-
return this.on('WF_FLOW', id, () => id);
|
|
97
|
+
return this.on('WF_FLOW', id, () => ({ init, id }));
|
|
98
98
|
}
|
|
99
99
|
start(schemaId, inputContext, input) {
|
|
100
100
|
return this._start(schemaId, inputContext, undefined, input);
|
|
@@ -120,13 +120,17 @@ class WooksWf extends WooksAdapterBase {
|
|
|
120
120
|
let result = {};
|
|
121
121
|
for (const handler of handlers) {
|
|
122
122
|
restoreCtx();
|
|
123
|
-
const
|
|
123
|
+
const { id, init } = (yield handler());
|
|
124
|
+
if (init) {
|
|
125
|
+
yield init();
|
|
126
|
+
restoreCtx();
|
|
127
|
+
}
|
|
124
128
|
if (resume) {
|
|
125
|
-
result = yield this.wf.resume(
|
|
129
|
+
result = yield this.wf.resume(id, { context: inputContext, indexes }, input);
|
|
126
130
|
break;
|
|
127
131
|
}
|
|
128
132
|
else {
|
|
129
|
-
result = yield this.wf.start(
|
|
133
|
+
result = yield this.wf.start(id, inputContext, input);
|
|
130
134
|
break;
|
|
131
135
|
}
|
|
132
136
|
}
|
|
@@ -167,13 +171,14 @@ function createWfApp(opts, wooks) {
|
|
|
167
171
|
}
|
|
168
172
|
|
|
169
173
|
function useWfState() {
|
|
170
|
-
const { store } = useWFContext();
|
|
174
|
+
const { store, getCtx } = useWFContext();
|
|
171
175
|
const event = store('event');
|
|
172
176
|
return {
|
|
173
177
|
ctx: () => event.get('inputContext'),
|
|
174
178
|
input: () => event.get('input'),
|
|
175
179
|
schemaId: event.get('schemaId'),
|
|
176
180
|
indexes: () => event.get('indexes'),
|
|
181
|
+
resume: getCtx().resume,
|
|
177
182
|
};
|
|
178
183
|
}
|
|
179
184
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-wf",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"description": "@wooksjs/event-wf",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"author": "Artem Maltsev",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"wooks": "0.3.
|
|
29
|
-
"@wooksjs/event-core": "0.3.
|
|
28
|
+
"wooks": "0.3.9",
|
|
29
|
+
"@wooksjs/event-core": "0.3.9"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@prostojs/logger": "^0.3.6",
|