@wooksjs/event-wf 0.5.25 → 0.6.1
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 -14
- package/dist/index.d.ts +11 -0
- package/dist/index.mjs +17 -6
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
//#region rolldown:runtime
|
|
3
2
|
var __create = Object.create;
|
|
4
3
|
var __defProp = Object.defineProperty;
|
|
@@ -47,6 +46,11 @@ function resumeWfContext(data, options) {
|
|
|
47
46
|
options
|
|
48
47
|
});
|
|
49
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Wrapper on top of useEventContext that provides
|
|
51
|
+
* proper context types for WF event
|
|
52
|
+
* @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
|
|
53
|
+
*/
|
|
50
54
|
function useWFContext() {
|
|
51
55
|
return (0, __wooksjs_event_core.useAsyncEventContext)("WF");
|
|
52
56
|
}
|
|
@@ -103,7 +107,7 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
103
107
|
constructor(opts, wooks$1) {
|
|
104
108
|
super(wooks$1, opts?.logger, opts?.router);
|
|
105
109
|
this.opts = opts;
|
|
106
|
-
this.logger = opts?.logger || this.getLogger(
|
|
110
|
+
this.logger = opts?.logger || this.getLogger(`[96m[wooks-wf]`);
|
|
107
111
|
this.wf = new WooksWorkflow(this.wooks);
|
|
108
112
|
}
|
|
109
113
|
attachSpy(fn) {
|
|
@@ -124,7 +128,7 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
124
128
|
}));
|
|
125
129
|
}
|
|
126
130
|
start(schemaId, inputContext, input, spy, cleanup) {
|
|
127
|
-
return this._start(schemaId, inputContext,
|
|
131
|
+
return this._start(schemaId, inputContext, void 0, input, spy, cleanup);
|
|
128
132
|
}
|
|
129
133
|
resume(state, input, spy, cleanup) {
|
|
130
134
|
return this._start(state.schemaId, state.context, state.indexes, input, spy, cleanup);
|
|
@@ -149,7 +153,7 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
149
153
|
if (firstStep && args[0] === "step") {
|
|
150
154
|
firstStep = false;
|
|
151
155
|
const { store } = useWFContext();
|
|
152
|
-
store("event").set("input",
|
|
156
|
+
store("event").set("input", void 0);
|
|
153
157
|
}
|
|
154
158
|
};
|
|
155
159
|
try {
|
|
@@ -185,25 +189,31 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
185
189
|
}
|
|
186
190
|
onError(e) {
|
|
187
191
|
if (this.opts?.onError) this.opts.onError(e);
|
|
188
|
-
else {
|
|
192
|
+
else {
|
|
189
193
|
this.error(e.message);
|
|
190
194
|
process.exit(1);
|
|
191
195
|
}
|
|
192
196
|
}
|
|
193
197
|
error(e) {
|
|
194
|
-
if (typeof e === "string") console.error(
|
|
195
|
-
else console.error(
|
|
198
|
+
if (typeof e === "string") console.error(`[31mERROR: [0m${e}`);
|
|
199
|
+
else console.error(`[31mERROR: [0m${e.message}`);
|
|
196
200
|
}
|
|
197
201
|
};
|
|
202
|
+
/**
|
|
203
|
+
* Factory for WooksWf App
|
|
204
|
+
* @param opts TWooksWfOptions
|
|
205
|
+
* @param wooks Wooks | WooksAdapterBase
|
|
206
|
+
* @returns WooksWf
|
|
207
|
+
*/
|
|
198
208
|
function createWfApp(opts, wooks$1) {
|
|
199
209
|
return new WooksWf(opts, wooks$1);
|
|
200
210
|
}
|
|
201
211
|
|
|
202
212
|
//#endregion
|
|
203
|
-
exports.WooksWf = WooksWf
|
|
204
|
-
exports.createWfApp = createWfApp
|
|
205
|
-
exports.createWfContext = createWfContext
|
|
206
|
-
exports.resumeWfContext = resumeWfContext
|
|
207
|
-
exports.useWFContext = useWFContext
|
|
208
|
-
exports.useWfState = useWfState
|
|
209
|
-
exports.wfShortcuts = wfShortcuts
|
|
213
|
+
exports.WooksWf = WooksWf;
|
|
214
|
+
exports.createWfApp = createWfApp;
|
|
215
|
+
exports.createWfContext = createWfContext;
|
|
216
|
+
exports.resumeWfContext = resumeWfContext;
|
|
217
|
+
exports.useWFContext = useWFContext;
|
|
218
|
+
exports.useWfState = useWfState;
|
|
219
|
+
exports.wfShortcuts = wfShortcuts;
|
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,11 @@ interface TWFContextStore {
|
|
|
29
29
|
|
|
30
30
|
declare function createWfContext(data: Omit<TWFEventData, 'type'>, options: TEventOptions): <T>(cb: (...a: any[]) => T) => T;
|
|
31
31
|
declare function resumeWfContext(data: Omit<TWFEventData, 'type'>, options: TEventOptions): <T>(cb: (...a: any[]) => T) => T;
|
|
32
|
+
/**
|
|
33
|
+
* Wrapper on top of useEventContext that provides
|
|
34
|
+
* proper context types for WF event
|
|
35
|
+
* @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
|
|
36
|
+
*/
|
|
32
37
|
declare function useWFContext<T extends TEmpty>(): _wooksjs_event_core.TCtxHelpers<TWFContextStore & T & _wooksjs_event_core.TGenericContextStore<TWFEventData>>;
|
|
33
38
|
|
|
34
39
|
declare class WooksWorkflow<T, IR> extends Workflow<T, IR> {
|
|
@@ -71,6 +76,12 @@ declare class WooksWf<T = any, IR = any> extends WooksAdapterBase {
|
|
|
71
76
|
protected onError(e: Error): void;
|
|
72
77
|
protected error(e: string | Error): void;
|
|
73
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Factory for WooksWf App
|
|
81
|
+
* @param opts TWooksWfOptions
|
|
82
|
+
* @param wooks Wooks | WooksAdapterBase
|
|
83
|
+
* @returns WooksWf
|
|
84
|
+
*/
|
|
74
85
|
declare function createWfApp<T>(opts?: TWooksWfOptions, wooks?: Wooks | WooksAdapterBase): WooksWf<T, any>;
|
|
75
86
|
|
|
76
87
|
export { type TWFContextStore, type TWFEventData, type TWooksWfOptions, WooksWf, createWfApp, createWfContext, resumeWfContext, useWFContext, useWfState, wfShortcuts };
|
package/dist/index.mjs
CHANGED
|
@@ -23,6 +23,11 @@ function resumeWfContext(data, options) {
|
|
|
23
23
|
options
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Wrapper on top of useEventContext that provides
|
|
28
|
+
* proper context types for WF event
|
|
29
|
+
* @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
|
|
30
|
+
*/
|
|
26
31
|
function useWFContext() {
|
|
27
32
|
return useAsyncEventContext("WF");
|
|
28
33
|
}
|
|
@@ -79,7 +84,7 @@ var WooksWf = class extends WooksAdapterBase {
|
|
|
79
84
|
constructor(opts, wooks) {
|
|
80
85
|
super(wooks, opts?.logger, opts?.router);
|
|
81
86
|
this.opts = opts;
|
|
82
|
-
this.logger = opts?.logger || this.getLogger(
|
|
87
|
+
this.logger = opts?.logger || this.getLogger(`[96m[wooks-wf]`);
|
|
83
88
|
this.wf = new WooksWorkflow(this.wooks);
|
|
84
89
|
}
|
|
85
90
|
attachSpy(fn) {
|
|
@@ -100,7 +105,7 @@ var WooksWf = class extends WooksAdapterBase {
|
|
|
100
105
|
}));
|
|
101
106
|
}
|
|
102
107
|
start(schemaId, inputContext, input, spy, cleanup) {
|
|
103
|
-
return this._start(schemaId, inputContext,
|
|
108
|
+
return this._start(schemaId, inputContext, void 0, input, spy, cleanup);
|
|
104
109
|
}
|
|
105
110
|
resume(state, input, spy, cleanup) {
|
|
106
111
|
return this._start(state.schemaId, state.context, state.indexes, input, spy, cleanup);
|
|
@@ -125,7 +130,7 @@ var WooksWf = class extends WooksAdapterBase {
|
|
|
125
130
|
if (firstStep && args[0] === "step") {
|
|
126
131
|
firstStep = false;
|
|
127
132
|
const { store } = useWFContext();
|
|
128
|
-
store("event").set("input",
|
|
133
|
+
store("event").set("input", void 0);
|
|
129
134
|
}
|
|
130
135
|
};
|
|
131
136
|
try {
|
|
@@ -161,16 +166,22 @@ var WooksWf = class extends WooksAdapterBase {
|
|
|
161
166
|
}
|
|
162
167
|
onError(e) {
|
|
163
168
|
if (this.opts?.onError) this.opts.onError(e);
|
|
164
|
-
else {
|
|
169
|
+
else {
|
|
165
170
|
this.error(e.message);
|
|
166
171
|
process.exit(1);
|
|
167
172
|
}
|
|
168
173
|
}
|
|
169
174
|
error(e) {
|
|
170
|
-
if (typeof e === "string") console.error(
|
|
171
|
-
else console.error(
|
|
175
|
+
if (typeof e === "string") console.error(`[31mERROR: [0m${e}`);
|
|
176
|
+
else console.error(`[31mERROR: [0m${e.message}`);
|
|
172
177
|
}
|
|
173
178
|
};
|
|
179
|
+
/**
|
|
180
|
+
* Factory for WooksWf App
|
|
181
|
+
* @param opts TWooksWfOptions
|
|
182
|
+
* @param wooks Wooks | WooksAdapterBase
|
|
183
|
+
* @returns WooksWf
|
|
184
|
+
*/
|
|
174
185
|
function createWfApp(opts, wooks) {
|
|
175
186
|
return new WooksWf(opts, wooks);
|
|
176
187
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-wf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "@wooksjs/event-wf",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"author": "Artem Maltsev",
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
36
|
+
"@prostojs/logger": "^0.4.3",
|
|
37
|
+
"@wooksjs/event-core": "^0.6.1",
|
|
38
|
+
"wooks": "^0.6.1"
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
|
-
"@prostojs/logger": "^0.4.3",
|
|
41
41
|
"@prostojs/wf": "^0.0.18"
|
|
42
42
|
},
|
|
43
43
|
"bugs": {
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
},
|
|
46
46
|
"homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/event-wf#readme",
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"typescript": "^5.
|
|
49
|
-
"vitest": "^2.
|
|
48
|
+
"typescript": "^5.8.3",
|
|
49
|
+
"vitest": "^3.2.4"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "rolldown -c ../../rolldown.config.mjs"
|