@wooksjs/event-wf 0.7.11 → 0.7.12
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 +46 -77
- package/dist/index.mjs +7 -16
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -1,42 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key$2; i < n; i++) {
|
|
10
|
-
key$2 = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key$2) && key$2 !== except) __defProp(to, key$2, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key$2),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key$2)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
const __wooksjs_event_core = __toESM(require("@wooksjs/event-core"));
|
|
25
|
-
const __wooksjs_event_http = __toESM(require("@wooksjs/event-http"));
|
|
26
|
-
const __wooksjs_http_body = __toESM(require("@wooksjs/http-body"));
|
|
27
|
-
const node_crypto = __toESM(require("node:crypto"));
|
|
28
|
-
const __prostojs_wf = __toESM(require("@prostojs/wf"));
|
|
29
|
-
const wooks = __toESM(require("wooks"));
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _wooksjs_event_core = require("@wooksjs/event-core");
|
|
3
|
+
let _wooksjs_event_http = require("@wooksjs/event-http");
|
|
4
|
+
let _wooksjs_http_body = require("@wooksjs/http-body");
|
|
5
|
+
let node_crypto = require("node:crypto");
|
|
6
|
+
let _prostojs_wf = require("@prostojs/wf");
|
|
7
|
+
let wooks = require("wooks");
|
|
30
8
|
|
|
31
9
|
//#region packages/event-wf/src/wf-kind.ts
|
|
32
|
-
const wfKind = (0,
|
|
33
|
-
schemaId: (0,
|
|
34
|
-
stepId: (0,
|
|
35
|
-
inputContext: (0,
|
|
36
|
-
indexes: (0,
|
|
37
|
-
input: (0,
|
|
10
|
+
const wfKind = (0, _wooksjs_event_core.defineEventKind)("WF", {
|
|
11
|
+
schemaId: (0, _wooksjs_event_core.slot)(),
|
|
12
|
+
stepId: (0, _wooksjs_event_core.slot)(),
|
|
13
|
+
inputContext: (0, _wooksjs_event_core.slot)(),
|
|
14
|
+
indexes: (0, _wooksjs_event_core.slot)(),
|
|
15
|
+
input: (0, _wooksjs_event_core.slot)()
|
|
38
16
|
});
|
|
39
|
-
const resumeKey = (0,
|
|
17
|
+
const resumeKey = (0, _wooksjs_event_core.key)("wf.resume");
|
|
40
18
|
|
|
41
19
|
//#endregion
|
|
42
20
|
//#region packages/event-wf/src/composables/wf-state.ts
|
|
@@ -49,7 +27,7 @@ const resumeKey = (0, __wooksjs_event_core.key)("wf.resume");
|
|
|
49
27
|
* const stepInput = input<MyInput>()
|
|
50
28
|
* ```
|
|
51
29
|
*/
|
|
52
|
-
const useWfState = (0,
|
|
30
|
+
const useWfState = (0, _wooksjs_event_core.defineWook)((c) => ({
|
|
53
31
|
ctx: () => c.get(wfKind.keys.inputContext),
|
|
54
32
|
input: () => c.get(wfKind.keys.input),
|
|
55
33
|
schemaId: c.get(wfKind.keys.schemaId),
|
|
@@ -62,15 +40,15 @@ const useWfState = (0, __wooksjs_event_core.defineWook)((c) => ({
|
|
|
62
40
|
//#region packages/event-wf/src/event-wf.ts
|
|
63
41
|
/** Creates a WF event context for a fresh workflow execution and runs `fn` inside it. */
|
|
64
42
|
function createWfContext(options, seeds, fn) {
|
|
65
|
-
return (0,
|
|
66
|
-
(0,
|
|
43
|
+
return (0, _wooksjs_event_core.createEventContext)(options, wfKind, seeds, () => {
|
|
44
|
+
(0, _wooksjs_event_core.current)().set(resumeKey, false);
|
|
67
45
|
return fn();
|
|
68
46
|
});
|
|
69
47
|
}
|
|
70
48
|
/** Creates a WF event context for resuming a paused workflow and runs `fn` inside it. */
|
|
71
49
|
function resumeWfContext(options, seeds, fn) {
|
|
72
|
-
return (0,
|
|
73
|
-
(0,
|
|
50
|
+
return (0, _wooksjs_event_core.createEventContext)(options, wfKind, seeds, () => {
|
|
51
|
+
(0, _wooksjs_event_core.current)().set(resumeKey, true);
|
|
74
52
|
return fn();
|
|
75
53
|
});
|
|
76
54
|
}
|
|
@@ -78,11 +56,11 @@ function resumeWfContext(options, seeds, fn) {
|
|
|
78
56
|
//#endregion
|
|
79
57
|
//#region packages/event-wf/src/outlets/outlet-context.ts
|
|
80
58
|
/** Registered outlet handlers, keyed by name */
|
|
81
|
-
const outletsRegistryKey = (0,
|
|
59
|
+
const outletsRegistryKey = (0, _wooksjs_event_core.key)("wf.outlets.registry");
|
|
82
60
|
/** Active state strategy for current request */
|
|
83
|
-
const stateStrategyKey = (0,
|
|
61
|
+
const stateStrategyKey = (0, _wooksjs_event_core.key)("wf.outlets.stateStrategy");
|
|
84
62
|
/** Finished response set by workflow steps */
|
|
85
|
-
const wfFinishedKey = (0,
|
|
63
|
+
const wfFinishedKey = (0, _wooksjs_event_core.key)("wf.outlets.finished");
|
|
86
64
|
|
|
87
65
|
//#endregion
|
|
88
66
|
//#region packages/event-wf/src/outlets/use-wf-outlet.ts
|
|
@@ -93,7 +71,7 @@ const wfFinishedKey = (0, __wooksjs_event_core.key)("wf.outlets.finished");
|
|
|
93
71
|
* `outletEmail(to, template)`. This composable is for advanced cases
|
|
94
72
|
* where steps need to inspect or modify outlet state directly.
|
|
95
73
|
*/
|
|
96
|
-
const useWfOutlet = (0,
|
|
74
|
+
const useWfOutlet = (0, _wooksjs_event_core.defineWook)((ctx) => ({
|
|
97
75
|
getStateStrategy: () => ctx.get(stateStrategyKey),
|
|
98
76
|
getOutlets: () => ctx.get(outletsRegistryKey),
|
|
99
77
|
getOutlet: (name) => ctx.get(outletsRegistryKey)?.get(name) ?? null
|
|
@@ -113,7 +91,7 @@ const useWfOutlet = (0, __wooksjs_event_core.defineWook)((ctx) => ({
|
|
|
113
91
|
* useWfFinished().set({ type: 'data', value: { success: true } })
|
|
114
92
|
* ```
|
|
115
93
|
*/
|
|
116
|
-
const useWfFinished = (0,
|
|
94
|
+
const useWfFinished = (0, _wooksjs_event_core.defineWook)((ctx) => ({
|
|
117
95
|
set: (response) => ctx.set(wfFinishedKey, response),
|
|
118
96
|
get: () => ctx.has(wfFinishedKey) ? ctx.get(wfFinishedKey) : void 0
|
|
119
97
|
}));
|
|
@@ -147,14 +125,14 @@ async function handleWfOutletRequest(config, deps) {
|
|
|
147
125
|
];
|
|
148
126
|
const tokenWrite = tok.write ?? "body";
|
|
149
127
|
const wfidName = config.wfidName ?? "wfid";
|
|
150
|
-
const ctx = (0,
|
|
128
|
+
const ctx = (0, _wooksjs_event_core.current)();
|
|
151
129
|
const registry = new Map(config.outlets.map((o) => [o.name, o]));
|
|
152
130
|
ctx.set(outletsRegistryKey, registry);
|
|
153
131
|
ctx.set(wfFinishedKey, void 0);
|
|
154
|
-
const { parseBody } = (0,
|
|
155
|
-
const { params } = (0,
|
|
156
|
-
const { getCookie } = (0,
|
|
157
|
-
const response = (0,
|
|
132
|
+
const { parseBody } = (0, _wooksjs_http_body.useBody)();
|
|
133
|
+
const { params } = (0, _wooksjs_event_http.useUrlParams)();
|
|
134
|
+
const { getCookie } = (0, _wooksjs_event_http.useCookies)();
|
|
135
|
+
const response = (0, _wooksjs_event_http.useResponse)();
|
|
158
136
|
const body = await parseBody().catch(() => void 0);
|
|
159
137
|
const queryParams = params();
|
|
160
138
|
let token;
|
|
@@ -274,11 +252,10 @@ function createHttpOutlet(opts) {
|
|
|
274
252
|
name: "http",
|
|
275
253
|
tokenDelivery: "caller",
|
|
276
254
|
async deliver(request, _token) {
|
|
277
|
-
|
|
255
|
+
return { response: opts?.transform ? opts.transform(request.payload, request.context) : typeof request.payload === "object" && request.payload !== null ? {
|
|
278
256
|
...request.payload,
|
|
279
257
|
...request.context
|
|
280
|
-
} : request.payload;
|
|
281
|
-
return { response: body };
|
|
258
|
+
} : request.payload };
|
|
282
259
|
}
|
|
283
260
|
};
|
|
284
261
|
}
|
|
@@ -548,23 +525,22 @@ var WfStateStoreMemory = class {
|
|
|
548
525
|
//#endregion
|
|
549
526
|
//#region packages/event-wf/src/workflow.ts
|
|
550
527
|
/** Workflow engine that resolves steps via Wooks router lookup. */
|
|
551
|
-
var WooksWorkflow = class extends
|
|
552
|
-
constructor(wooks
|
|
528
|
+
var WooksWorkflow = class extends _prostojs_wf.Workflow {
|
|
529
|
+
constructor(wooks) {
|
|
553
530
|
super([]);
|
|
554
|
-
this.wooks = wooks
|
|
531
|
+
this.wooks = wooks;
|
|
555
532
|
}
|
|
556
533
|
resolveStep(stepId) {
|
|
557
534
|
const stepIdNorm = `/${stepId}`.replace(/\/{2,}/gu, "/");
|
|
558
535
|
try {
|
|
559
|
-
const ctx = (0,
|
|
536
|
+
const ctx = (0, _wooksjs_event_core.current)();
|
|
560
537
|
const found = this.wooks.lookup("WF_STEP", stepIdNorm);
|
|
561
538
|
if (found.handlers?.length) {
|
|
562
539
|
ctx.set(wfKind.keys.stepId, stepIdNorm);
|
|
563
540
|
return found.handlers[0]();
|
|
564
541
|
}
|
|
565
542
|
} catch {
|
|
566
|
-
const
|
|
567
|
-
const found = router.lookup("WF_STEP", stepIdNorm);
|
|
543
|
+
const found = this.wooks.getRouter().lookup("WF_STEP", stepIdNorm);
|
|
568
544
|
if (found?.route?.handlers.length) return found.route.handlers[0]();
|
|
569
545
|
}
|
|
570
546
|
throw new Error(`Step "${stepIdNorm}" not found.`);
|
|
@@ -580,9 +556,6 @@ const wfShortcuts = {
|
|
|
580
556
|
};
|
|
581
557
|
/** Wooks adapter for defining and executing workflow schemas with step-based routing. */
|
|
582
558
|
var WooksWf = class extends wooks.WooksAdapterBase {
|
|
583
|
-
logger;
|
|
584
|
-
wf;
|
|
585
|
-
eventContextOptions;
|
|
586
559
|
constructor(opts, wooks$1) {
|
|
587
560
|
super(wooks$1, opts?.logger, opts?.router);
|
|
588
561
|
this.opts = opts;
|
|
@@ -600,7 +573,7 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
600
573
|
}
|
|
601
574
|
/** Registers a workflow step with the given id and handler. */
|
|
602
575
|
step(id, opts) {
|
|
603
|
-
const step = (0,
|
|
576
|
+
const step = (0, _prostojs_wf.createStep)(id, opts);
|
|
604
577
|
return this.on("WF_STEP", id, () => step);
|
|
605
578
|
}
|
|
606
579
|
/** Registers a workflow flow schema with the given id. */
|
|
@@ -646,19 +619,16 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
646
619
|
async _start(schemaId, inputContext, indexes, opts, parentCtx) {
|
|
647
620
|
const { input, spy, cleanup } = opts ?? {};
|
|
648
621
|
const resume = !!indexes?.length;
|
|
649
|
-
|
|
650
|
-
const ctxOptions = parentCtx ? {
|
|
622
|
+
return (resume ? resumeWfContext : createWfContext)(parentCtx ? {
|
|
651
623
|
...this.eventContextOptions,
|
|
652
624
|
parent: parentCtx
|
|
653
|
-
} : this.eventContextOptions
|
|
654
|
-
const seeds = {
|
|
625
|
+
} : this.eventContextOptions, {
|
|
655
626
|
inputContext,
|
|
656
627
|
schemaId,
|
|
657
628
|
stepId: null,
|
|
658
629
|
indexes,
|
|
659
630
|
input
|
|
660
|
-
}
|
|
661
|
-
return factory(ctxOptions, seeds, async () => {
|
|
631
|
+
}, async () => {
|
|
662
632
|
const { handlers: foundHandlers } = this.wooks.lookup("WF_FLOW", `/${schemaId}`.replace(/^\/+/u, "/"));
|
|
663
633
|
const handlers = foundHandlers || this.opts?.onNotFound && [this.opts.onNotFound] || null;
|
|
664
634
|
if (handlers && handlers.length > 0) {
|
|
@@ -668,8 +638,7 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
668
638
|
if (spy) spy(...args);
|
|
669
639
|
if (firstStep && args[0] === "step") {
|
|
670
640
|
firstStep = false;
|
|
671
|
-
|
|
672
|
-
ctx.set(wfKind.keys.input, void 0);
|
|
641
|
+
(0, _wooksjs_event_core.current)().set(wfKind.keys.input, void 0);
|
|
673
642
|
}
|
|
674
643
|
};
|
|
675
644
|
try {
|
|
@@ -732,8 +701,8 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
732
701
|
* await app.start('my-flow', { data: 'hello' })
|
|
733
702
|
* ```
|
|
734
703
|
*/
|
|
735
|
-
function createWfApp(opts, wooks$
|
|
736
|
-
return new WooksWf(opts, wooks$
|
|
704
|
+
function createWfApp(opts, wooks$2) {
|
|
705
|
+
return new WooksWf(opts, wooks$2);
|
|
737
706
|
}
|
|
738
707
|
|
|
739
708
|
//#endregion
|
|
@@ -742,7 +711,7 @@ exports.HandleStateStrategy = HandleStateStrategy;
|
|
|
742
711
|
Object.defineProperty(exports, 'StepRetriableError', {
|
|
743
712
|
enumerable: true,
|
|
744
713
|
get: function () {
|
|
745
|
-
return
|
|
714
|
+
return _prostojs_wf.StepRetriableError;
|
|
746
715
|
}
|
|
747
716
|
});
|
|
748
717
|
exports.WfStateStoreMemory = WfStateStoreMemory;
|
|
@@ -761,13 +730,13 @@ exports.resumeWfContext = resumeWfContext;
|
|
|
761
730
|
Object.defineProperty(exports, 'useLogger', {
|
|
762
731
|
enumerable: true,
|
|
763
732
|
get: function () {
|
|
764
|
-
return
|
|
733
|
+
return _wooksjs_event_core.useLogger;
|
|
765
734
|
}
|
|
766
735
|
});
|
|
767
736
|
Object.defineProperty(exports, 'useRouteParams', {
|
|
768
737
|
enumerable: true,
|
|
769
738
|
get: function () {
|
|
770
|
-
return
|
|
739
|
+
return _wooksjs_event_core.useRouteParams;
|
|
771
740
|
}
|
|
772
741
|
});
|
|
773
742
|
exports.useWfFinished = useWfFinished;
|
package/dist/index.mjs
CHANGED
|
@@ -251,11 +251,10 @@ function createHttpOutlet(opts) {
|
|
|
251
251
|
name: "http",
|
|
252
252
|
tokenDelivery: "caller",
|
|
253
253
|
async deliver(request, _token) {
|
|
254
|
-
|
|
254
|
+
return { response: opts?.transform ? opts.transform(request.payload, request.context) : typeof request.payload === "object" && request.payload !== null ? {
|
|
255
255
|
...request.payload,
|
|
256
256
|
...request.context
|
|
257
|
-
} : request.payload;
|
|
258
|
-
return { response: body };
|
|
257
|
+
} : request.payload };
|
|
259
258
|
}
|
|
260
259
|
};
|
|
261
260
|
}
|
|
@@ -540,8 +539,7 @@ var WooksWorkflow = class extends Workflow {
|
|
|
540
539
|
return found.handlers[0]();
|
|
541
540
|
}
|
|
542
541
|
} catch {
|
|
543
|
-
const
|
|
544
|
-
const found = router.lookup("WF_STEP", stepIdNorm);
|
|
542
|
+
const found = this.wooks.getRouter().lookup("WF_STEP", stepIdNorm);
|
|
545
543
|
if (found?.route?.handlers.length) return found.route.handlers[0]();
|
|
546
544
|
}
|
|
547
545
|
throw new Error(`Step "${stepIdNorm}" not found.`);
|
|
@@ -557,9 +555,6 @@ const wfShortcuts = {
|
|
|
557
555
|
};
|
|
558
556
|
/** Wooks adapter for defining and executing workflow schemas with step-based routing. */
|
|
559
557
|
var WooksWf = class extends WooksAdapterBase {
|
|
560
|
-
logger;
|
|
561
|
-
wf;
|
|
562
|
-
eventContextOptions;
|
|
563
558
|
constructor(opts, wooks) {
|
|
564
559
|
super(wooks, opts?.logger, opts?.router);
|
|
565
560
|
this.opts = opts;
|
|
@@ -623,19 +618,16 @@ var WooksWf = class extends WooksAdapterBase {
|
|
|
623
618
|
async _start(schemaId, inputContext, indexes, opts, parentCtx) {
|
|
624
619
|
const { input, spy, cleanup } = opts ?? {};
|
|
625
620
|
const resume = !!indexes?.length;
|
|
626
|
-
|
|
627
|
-
const ctxOptions = parentCtx ? {
|
|
621
|
+
return (resume ? resumeWfContext : createWfContext)(parentCtx ? {
|
|
628
622
|
...this.eventContextOptions,
|
|
629
623
|
parent: parentCtx
|
|
630
|
-
} : this.eventContextOptions
|
|
631
|
-
const seeds = {
|
|
624
|
+
} : this.eventContextOptions, {
|
|
632
625
|
inputContext,
|
|
633
626
|
schemaId,
|
|
634
627
|
stepId: null,
|
|
635
628
|
indexes,
|
|
636
629
|
input
|
|
637
|
-
}
|
|
638
|
-
return factory(ctxOptions, seeds, async () => {
|
|
630
|
+
}, async () => {
|
|
639
631
|
const { handlers: foundHandlers } = this.wooks.lookup("WF_FLOW", `/${schemaId}`.replace(/^\/+/u, "/"));
|
|
640
632
|
const handlers = foundHandlers || this.opts?.onNotFound && [this.opts.onNotFound] || null;
|
|
641
633
|
if (handlers && handlers.length > 0) {
|
|
@@ -645,8 +637,7 @@ var WooksWf = class extends WooksAdapterBase {
|
|
|
645
637
|
if (spy) spy(...args);
|
|
646
638
|
if (firstStep && args[0] === "step") {
|
|
647
639
|
firstStep = false;
|
|
648
|
-
|
|
649
|
-
ctx.set(wfKind.keys.input, void 0);
|
|
640
|
+
current().set(wfKind.keys.input, void 0);
|
|
650
641
|
}
|
|
651
642
|
};
|
|
652
643
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-wf",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.12",
|
|
4
4
|
"description": "@wooksjs/event-wf",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -42,17 +42,17 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"typescript": "^5.9.3",
|
|
44
44
|
"vitest": "^3.2.4",
|
|
45
|
-
"@wooksjs/event-core": "^0.7.
|
|
46
|
-
"@wooksjs/event-http": "^0.7.
|
|
47
|
-
"@wooksjs/http-body": "^0.7.
|
|
48
|
-
"wooks": "^0.7.
|
|
45
|
+
"@wooksjs/event-core": "^0.7.12",
|
|
46
|
+
"@wooksjs/event-http": "^0.7.12",
|
|
47
|
+
"@wooksjs/http-body": "^0.7.12",
|
|
48
|
+
"wooks": "^0.7.12"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@prostojs/logger": "^0.4.3",
|
|
52
|
-
"@wooksjs/event-core": "^0.7.
|
|
53
|
-
"@wooksjs/
|
|
54
|
-
"
|
|
55
|
-
"
|
|
52
|
+
"@wooksjs/event-core": "^0.7.12",
|
|
53
|
+
"@wooksjs/http-body": "^0.7.12",
|
|
54
|
+
"wooks": "^0.7.12",
|
|
55
|
+
"@wooksjs/event-http": "^0.7.12"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"@wooksjs/event-http": {
|