@wooksjs/event-wf 0.3.8 → 0.3.10
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 +24 -11
- package/dist/index.d.ts +9 -4
- package/dist/index.mjs +24 -11
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -94,17 +94,17 @@ 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
|
-
start(schemaId, inputContext, input) {
|
|
102
|
-
return this._start(schemaId, inputContext, undefined, input);
|
|
101
|
+
start(schemaId, inputContext, input, cleanup) {
|
|
102
|
+
return this._start(schemaId, inputContext, undefined, input, cleanup);
|
|
103
103
|
}
|
|
104
|
-
resume(schemaId, inputContext, indexes, input) {
|
|
105
|
-
return this._start(schemaId, inputContext, indexes, input);
|
|
104
|
+
resume(schemaId, inputContext, indexes, input, cleanup) {
|
|
105
|
+
return this._start(schemaId, inputContext, indexes, input, cleanup);
|
|
106
106
|
}
|
|
107
|
-
_start(schemaId, inputContext, indexes, input) {
|
|
107
|
+
_start(schemaId, inputContext, indexes, input, cleanup) {
|
|
108
108
|
var _a, _b;
|
|
109
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
110
|
const resume = !!(indexes === null || indexes === void 0 ? void 0 : indexes.length);
|
|
@@ -122,19 +122,31 @@ 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
|
}
|
|
139
|
+
if (cleanup) {
|
|
140
|
+
restoreCtx();
|
|
141
|
+
cleanup();
|
|
142
|
+
}
|
|
135
143
|
clearCtx();
|
|
136
144
|
return result;
|
|
137
145
|
}
|
|
146
|
+
if (cleanup) {
|
|
147
|
+
restoreCtx();
|
|
148
|
+
cleanup();
|
|
149
|
+
}
|
|
138
150
|
clearCtx();
|
|
139
151
|
throw new Error('Unknown schemaId: ' + schemaId);
|
|
140
152
|
});
|
|
@@ -169,13 +181,14 @@ function createWfApp(opts, wooks) {
|
|
|
169
181
|
}
|
|
170
182
|
|
|
171
183
|
function useWfState() {
|
|
172
|
-
const { store } = useWFContext();
|
|
184
|
+
const { store, getCtx } = useWFContext();
|
|
173
185
|
const event = store('event');
|
|
174
186
|
return {
|
|
175
187
|
ctx: () => event.get('inputContext'),
|
|
176
188
|
input: () => event.get('input'),
|
|
177
189
|
schemaId: event.get('schemaId'),
|
|
178
190
|
indexes: () => event.get('indexes'),
|
|
191
|
+
resume: getCtx().resume,
|
|
179
192
|
};
|
|
180
193
|
}
|
|
181
194
|
|
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,10 +139,10 @@ 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[]>>;
|
|
138
|
-
start<I>(schemaId: string, inputContext: T, input?: I): Promise<TFlowOutput<T, I>>;
|
|
139
|
-
resume<I>(schemaId: string, inputContext: T, indexes: number[], input?: I): Promise<TFlowOutput<T, I>>;
|
|
140
|
-
protected _start<I>(schemaId: string, inputContext: T, indexes?: number[], input?: I): Promise<TFlowOutput<T, I>>;
|
|
142
|
+
flow(id: string, schema: TWorkflowSchema<T>, init?: () => void | Promise<void>): TProstoRouterPathHandle<Record<string, string | string[]>>;
|
|
143
|
+
start<I>(schemaId: string, inputContext: T, input?: I, cleanup?: () => void): Promise<TFlowOutput<T, I>>;
|
|
144
|
+
resume<I>(schemaId: string, inputContext: T, indexes: number[], input?: I, cleanup?: () => void): Promise<TFlowOutput<T, I>>;
|
|
145
|
+
protected _start<I>(schemaId: string, inputContext: T, indexes?: number[], input?: I, cleanup?: () => void): Promise<TFlowOutput<T, I>>;
|
|
141
146
|
protected onError(e: Error): void;
|
|
142
147
|
protected error(e: string | Error): void;
|
|
143
148
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -92,17 +92,17 @@ 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
|
-
start(schemaId, inputContext, input) {
|
|
100
|
-
return this._start(schemaId, inputContext, undefined, input);
|
|
99
|
+
start(schemaId, inputContext, input, cleanup) {
|
|
100
|
+
return this._start(schemaId, inputContext, undefined, input, cleanup);
|
|
101
101
|
}
|
|
102
|
-
resume(schemaId, inputContext, indexes, input) {
|
|
103
|
-
return this._start(schemaId, inputContext, indexes, input);
|
|
102
|
+
resume(schemaId, inputContext, indexes, input, cleanup) {
|
|
103
|
+
return this._start(schemaId, inputContext, indexes, input, cleanup);
|
|
104
104
|
}
|
|
105
|
-
_start(schemaId, inputContext, indexes, input) {
|
|
105
|
+
_start(schemaId, inputContext, indexes, input, cleanup) {
|
|
106
106
|
var _a, _b;
|
|
107
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
108
108
|
const resume = !!(indexes === null || indexes === void 0 ? void 0 : indexes.length);
|
|
@@ -120,19 +120,31 @@ 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
|
}
|
|
137
|
+
if (cleanup) {
|
|
138
|
+
restoreCtx();
|
|
139
|
+
cleanup();
|
|
140
|
+
}
|
|
133
141
|
clearCtx();
|
|
134
142
|
return result;
|
|
135
143
|
}
|
|
144
|
+
if (cleanup) {
|
|
145
|
+
restoreCtx();
|
|
146
|
+
cleanup();
|
|
147
|
+
}
|
|
136
148
|
clearCtx();
|
|
137
149
|
throw new Error('Unknown schemaId: ' + schemaId);
|
|
138
150
|
});
|
|
@@ -167,13 +179,14 @@ function createWfApp(opts, wooks) {
|
|
|
167
179
|
}
|
|
168
180
|
|
|
169
181
|
function useWfState() {
|
|
170
|
-
const { store } = useWFContext();
|
|
182
|
+
const { store, getCtx } = useWFContext();
|
|
171
183
|
const event = store('event');
|
|
172
184
|
return {
|
|
173
185
|
ctx: () => event.get('inputContext'),
|
|
174
186
|
input: () => event.get('input'),
|
|
175
187
|
schemaId: event.get('schemaId'),
|
|
176
188
|
indexes: () => event.get('indexes'),
|
|
189
|
+
resume: getCtx().resume,
|
|
177
190
|
};
|
|
178
191
|
}
|
|
179
192
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-wf",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
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.10",
|
|
29
|
+
"@wooksjs/event-core": "0.3.10"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@prostojs/logger": "^0.3.6",
|