@moostjs/event-wf 0.5.20 → 0.5.22

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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.cjs +172 -143
  3. package/dist/index.mjs +132 -132
  4. package/package.json +18 -11
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 moostjs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs CHANGED
@@ -1,164 +1,193 @@
1
- 'use strict';
1
+ "use strict";
2
+ //#region rolldown:runtime
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
2
23
 
3
- var eventWf = require('@wooksjs/event-wf');
4
- var moost = require('moost');
5
- var eventCore = require('@wooksjs/event-core');
6
- var wf = require('@prostojs/wf');
24
+ //#endregion
25
+ const __wooksjs_event_wf = __toESM(require("@wooksjs/event-wf"));
26
+ const moost = __toESM(require("moost"));
27
+ const __wooksjs_event_core = __toESM(require("@wooksjs/event-core"));
28
+ const __prostojs_wf = __toESM(require("@prostojs/wf"));
7
29
 
30
+ //#region packages/event-wf/src/meta-types.ts
8
31
  function getWfMate() {
9
- return moost.getMoostMate();
32
+ return (0, moost.getMoostMate)();
10
33
  }
11
34
 
35
+ //#endregion
36
+ //#region packages/event-wf/src/decorators/wf.decorator.ts
12
37
  function Step(path) {
13
- return getWfMate().decorate('handlers', { path, type: 'WF_STEP' }, true);
38
+ return getWfMate().decorate("handlers", {
39
+ path,
40
+ type: "WF_STEP"
41
+ }, true);
14
42
  }
15
43
  function Workflow(path) {
16
- return getWfMate().decorate('handlers', { path, type: 'WF_FLOW' }, true);
44
+ return getWfMate().decorate("handlers", {
45
+ path,
46
+ type: "WF_FLOW"
47
+ }, true);
17
48
  }
18
49
  function WorkflowSchema(schema) {
19
- return getWfMate().decorate('wfSchema', schema);
50
+ return getWfMate().decorate("wfSchema", schema);
20
51
  }
21
52
  const WorkflowParam = (name) => {
22
- switch (name) {
23
- case 'state': {
24
- return moost.Resolve(() => eventWf.useWfState(), 'Workflow-State');
25
- }
26
- case 'resume': {
27
- return moost.Resolve(() => eventWf.useWfState().resume, 'Workflow-Resume');
28
- }
29
- case 'indexes': {
30
- return moost.Resolve(() => eventWf.useWfState().indexes, 'Workflow-Indexes');
31
- }
32
- case 'schemaId': {
33
- return moost.Resolve(() => eventWf.useWfState().schemaId, 'Workflow-SchemaId');
34
- }
35
- case 'stepId': {
36
- return moost.Resolve(() => eventWf.useWfState().stepId(), 'Workflow-StepId');
37
- }
38
- case 'context': {
39
- return moost.Resolve(() => eventWf.useWfState().ctx(), 'Workflow-Context');
40
- }
41
- case 'input': {
42
- return moost.Resolve(() => eventWf.useWfState().input(), 'Workflow-Input');
43
- }
44
- }
53
+ switch (name) {
54
+ case "state": return (0, moost.Resolve)(() => (0, __wooksjs_event_wf.useWfState)(), "Workflow-State");
55
+ case "resume": return (0, moost.Resolve)(() => (0, __wooksjs_event_wf.useWfState)().resume, "Workflow-Resume");
56
+ case "indexes": return (0, moost.Resolve)(() => (0, __wooksjs_event_wf.useWfState)().indexes, "Workflow-Indexes");
57
+ case "schemaId": return (0, moost.Resolve)(() => (0, __wooksjs_event_wf.useWfState)().schemaId, "Workflow-SchemaId");
58
+ case "stepId": return (0, moost.Resolve)(() => (0, __wooksjs_event_wf.useWfState)().stepId(), "Workflow-StepId");
59
+ case "context": return (0, moost.Resolve)(() => (0, __wooksjs_event_wf.useWfState)().ctx(), "Workflow-Context");
60
+ case "input": return (0, moost.Resolve)(() => (0, __wooksjs_event_wf.useWfState)().input(), "Workflow-Input");
61
+ }
45
62
  };
46
63
 
47
- const LOGGER_TITLE = 'moost-wf';
48
- const CONTEXT_TYPE = 'WF';
49
- class MoostWf {
50
- constructor(opts, debug) {
51
- this.opts = opts;
52
- this.debug = debug;
53
- this.name = 'workflow';
54
- this.toInit = [];
55
- if (opts && opts instanceof eventWf.WooksWf) {
56
- this.wfApp = opts;
57
- }
58
- else if (opts) {
59
- this.wfApp = eventWf.createWfApp(opts);
60
- }
61
- else {
62
- this.wfApp = eventWf.createWfApp();
63
- }
64
- }
65
- async onNotFound() {
66
- return moost.defineMoostEventHandler({
67
- loggerTitle: LOGGER_TITLE,
68
- getIterceptorHandler: () => this.moost?.getGlobalInterceptorHandler(),
69
- getControllerInstance: () => this.moost,
70
- callControllerMethod: () => new Error('WF Handler not found'),
71
- logErrors: this.debug,
72
- targetPath: '',
73
- handlerType: '__SYSTEM__',
74
- })();
75
- }
76
- onInit(moost) {
77
- this.moost = moost;
78
- this.toInit.forEach(fn => {
79
- fn();
80
- });
81
- }
82
- getWfApp() {
83
- return this.wfApp;
84
- }
85
- attachSpy(fn) {
86
- return this.wfApp.attachSpy(fn);
87
- }
88
- detachSpy(fn) {
89
- this.wfApp.detachSpy(fn);
90
- }
91
- start(schemaId, initialContext, input) {
92
- return this.wfApp.start(schemaId, initialContext, input, () => { }, () => {
93
- const scopeId = eventCore.useEventId().getId();
94
- moost.getMoostInfact().unregisterScope(scopeId);
95
- });
96
- }
97
- resume(state, input) {
98
- return this.wfApp.resume(state, input, () => { }, () => {
99
- const scopeId = eventCore.useEventId().getId();
100
- moost.getMoostInfact().unregisterScope(scopeId);
101
- });
102
- }
103
- bindHandler(opts) {
104
- let fn;
105
- for (const handler of opts.handlers) {
106
- if (!['WF_STEP', 'WF_FLOW'].includes(handler.type)) {
107
- continue;
108
- }
109
- const schemaId = handler.path;
110
- const path = typeof schemaId === 'string' ? schemaId : typeof opts.method === 'string' ? opts.method : '';
111
- const targetPath = `${`${opts.prefix || ''}/${path}`.replace(/\/\/+/g, '/')}${path.endsWith('//') ? '/' : ''}`;
112
- fn = moost.defineMoostEventHandler({
113
- contextType: CONTEXT_TYPE,
114
- loggerTitle: LOGGER_TITLE,
115
- getIterceptorHandler: opts.getIterceptorHandler,
116
- getControllerInstance: opts.getInstance,
117
- controllerMethod: opts.method,
118
- resolveArgs: opts.resolveArgs,
119
- manualUnscope: true,
120
- targetPath,
121
- handlerType: handler.type,
122
- });
123
- if (handler.type === 'WF_STEP') {
124
- this.wfApp.step(targetPath, {
125
- handler: fn,
126
- });
127
- opts.logHandler(`${''}(${handler.type})${''}${targetPath}`);
128
- }
129
- else {
130
- const mate = getWfMate();
131
- let wfSchema = mate.read(opts.fakeInstance, opts.method)?.wfSchema;
132
- if (!wfSchema) {
133
- wfSchema = mate.read(opts.fakeInstance)?.wfSchema;
134
- }
135
- const _fn = (async () => {
136
- moost.setControllerContext(this.moost, 'bindHandler', targetPath);
137
- return fn();
138
- });
139
- this.toInit.push(() => {
140
- this.wfApp.flow(targetPath, wfSchema || [], opts.prefix === '/' ? '' : opts.prefix, _fn);
141
- opts.logHandler(`${''}(${handler.type})${''}${targetPath}`);
142
- });
143
- }
144
- }
145
- }
64
+ //#endregion
65
+ //#region packages/event-wf/src/event-wf.ts
66
+ function _define_property(obj, key, value) {
67
+ if (key in obj) Object.defineProperty(obj, key, {
68
+ value,
69
+ enumerable: true,
70
+ configurable: true,
71
+ writable: true
72
+ });
73
+ else obj[key] = value;
74
+ return obj;
146
75
  }
76
+ const LOGGER_TITLE = "moost-wf";
77
+ const CONTEXT_TYPE = "WF";
78
+ var MoostWf = class {
79
+ async onNotFound() {
80
+ return (0, moost.defineMoostEventHandler)({
81
+ loggerTitle: LOGGER_TITLE,
82
+ getIterceptorHandler: () => this.moost?.getGlobalInterceptorHandler(),
83
+ getControllerInstance: () => this.moost,
84
+ callControllerMethod: () => new Error("WF Handler not found"),
85
+ logErrors: this.debug,
86
+ targetPath: "",
87
+ handlerType: "__SYSTEM__"
88
+ })();
89
+ }
90
+ onInit(moost$1) {
91
+ this.moost = moost$1;
92
+ this.toInit.forEach((fn) => {
93
+ fn();
94
+ });
95
+ }
96
+ getWfApp() {
97
+ return this.wfApp;
98
+ }
99
+ attachSpy(fn) {
100
+ return this.wfApp.attachSpy(fn);
101
+ }
102
+ detachSpy(fn) {
103
+ this.wfApp.detachSpy(fn);
104
+ }
105
+ start(schemaId, initialContext, input) {
106
+ return this.wfApp.start(schemaId, initialContext, input, () => {}, () => {
107
+ const scopeId = (0, __wooksjs_event_core.useEventId)().getId();
108
+ (0, moost.getMoostInfact)().unregisterScope(scopeId);
109
+ });
110
+ }
111
+ resume(state, input) {
112
+ return this.wfApp.resume(state, input, () => {}, () => {
113
+ const scopeId = (0, __wooksjs_event_core.useEventId)().getId();
114
+ (0, moost.getMoostInfact)().unregisterScope(scopeId);
115
+ });
116
+ }
117
+ bindHandler(opts) {
118
+ let fn;
119
+ for (const handler of opts.handlers) {
120
+ if (!["WF_STEP", "WF_FLOW"].includes(handler.type)) continue;
121
+ const schemaId = handler.path;
122
+ const path = typeof schemaId === "string" ? schemaId : typeof opts.method === "string" ? opts.method : "";
123
+ const targetPath = `${`${opts.prefix || ""}/${path}`.replace(/\/\/+/g, "/")}${path.endsWith("//") ? "/" : ""}`;
124
+ fn = (0, moost.defineMoostEventHandler)({
125
+ contextType: CONTEXT_TYPE,
126
+ loggerTitle: LOGGER_TITLE,
127
+ getIterceptorHandler: opts.getIterceptorHandler,
128
+ getControllerInstance: opts.getInstance,
129
+ controllerMethod: opts.method,
130
+ resolveArgs: opts.resolveArgs,
131
+ manualUnscope: true,
132
+ targetPath,
133
+ handlerType: handler.type
134
+ });
135
+ if (handler.type === "WF_STEP") {
136
+ this.wfApp.step(targetPath, { handler: fn });
137
+ opts.logHandler(`${"\x1B[36m"}(${handler.type})${"\x1B[32m"}${targetPath}`);
138
+ } else {
139
+ const mate = getWfMate();
140
+ let wfSchema = mate.read(opts.fakeInstance, opts.method)?.wfSchema;
141
+ if (!wfSchema) wfSchema = mate.read(opts.fakeInstance)?.wfSchema;
142
+ const _fn = async () => {
143
+ (0, moost.setControllerContext)(this.moost, "bindHandler", targetPath);
144
+ return fn();
145
+ };
146
+ this.toInit.push(() => {
147
+ this.wfApp.flow(targetPath, wfSchema || [], opts.prefix === "/" ? "" : opts.prefix, _fn);
148
+ opts.logHandler(`${"\x1B[36m"}(${handler.type})${"\x1B[32m"}${targetPath}`);
149
+ });
150
+ }
151
+ }
152
+ }
153
+ constructor(opts, debug) {
154
+ _define_property(this, "opts", void 0);
155
+ _define_property(this, "debug", void 0);
156
+ _define_property(this, "name", void 0);
157
+ _define_property(this, "wfApp", void 0);
158
+ _define_property(this, "moost", void 0);
159
+ _define_property(this, "toInit", void 0);
160
+ this.opts = opts;
161
+ this.debug = debug;
162
+ this.name = "workflow";
163
+ this.toInit = [];
164
+ if (opts && opts instanceof __wooksjs_event_wf.WooksWf) this.wfApp = opts;
165
+ else if (opts) this.wfApp = (0, __wooksjs_event_wf.createWfApp)(opts);
166
+ else this.wfApp = (0, __wooksjs_event_wf.createWfApp)();
167
+ }
168
+ };
147
169
 
148
- Object.defineProperty(exports, "useWFContext", {
170
+ //#endregion
171
+ exports.MoostWf = MoostWf
172
+ exports.Step = Step
173
+ Object.defineProperty(exports, 'StepRetriableError', {
149
174
  enumerable: true,
150
- get: function () { return eventWf.useWFContext; }
175
+ get: function () {
176
+ return __prostojs_wf.StepRetriableError;
177
+ }
151
178
  });
152
- Object.defineProperty(exports, "useWfState", {
179
+ exports.Workflow = Workflow
180
+ exports.WorkflowParam = WorkflowParam
181
+ exports.WorkflowSchema = WorkflowSchema
182
+ Object.defineProperty(exports, 'useWFContext', {
153
183
  enumerable: true,
154
- get: function () { return eventWf.useWfState; }
184
+ get: function () {
185
+ return __wooksjs_event_wf.useWFContext;
186
+ }
155
187
  });
156
- Object.defineProperty(exports, "StepRetriableError", {
188
+ Object.defineProperty(exports, 'useWfState', {
157
189
  enumerable: true,
158
- get: function () { return wf.StepRetriableError; }
159
- });
160
- exports.MoostWf = MoostWf;
161
- exports.Step = Step;
162
- exports.Workflow = Workflow;
163
- exports.WorkflowParam = WorkflowParam;
164
- exports.WorkflowSchema = WorkflowSchema;
190
+ get: function () {
191
+ return __wooksjs_event_wf.useWfState;
192
+ }
193
+ });
package/dist/index.mjs CHANGED
@@ -1,147 +1,147 @@
1
- import { useWfState, WooksWf, createWfApp } from '@wooksjs/event-wf';
2
- export { useWFContext, useWfState } from '@wooksjs/event-wf';
3
- import { getMoostMate, Resolve, defineMoostEventHandler, getMoostInfact, setControllerContext } from 'moost';
4
- import { useEventId } from '@wooksjs/event-core';
5
- export { StepRetriableError } from '@prostojs/wf';
1
+ import { WooksWf, createWfApp, useWFContext, useWfState } from "@wooksjs/event-wf";
2
+ import { Resolve, defineMoostEventHandler, getMoostInfact, getMoostMate, setControllerContext } from "moost";
3
+ import { useEventId } from "@wooksjs/event-core";
4
+ import { StepRetriableError } from "@prostojs/wf";
6
5
 
6
+ //#region packages/event-wf/src/meta-types.ts
7
7
  function getWfMate() {
8
- return getMoostMate();
8
+ return getMoostMate();
9
9
  }
10
10
 
11
+ //#endregion
12
+ //#region packages/event-wf/src/decorators/wf.decorator.ts
11
13
  function Step(path) {
12
- return getWfMate().decorate('handlers', { path, type: 'WF_STEP' }, true);
14
+ return getWfMate().decorate("handlers", {
15
+ path,
16
+ type: "WF_STEP"
17
+ }, true);
13
18
  }
14
19
  function Workflow(path) {
15
- return getWfMate().decorate('handlers', { path, type: 'WF_FLOW' }, true);
20
+ return getWfMate().decorate("handlers", {
21
+ path,
22
+ type: "WF_FLOW"
23
+ }, true);
16
24
  }
17
25
  function WorkflowSchema(schema) {
18
- return getWfMate().decorate('wfSchema', schema);
26
+ return getWfMate().decorate("wfSchema", schema);
19
27
  }
20
28
  const WorkflowParam = (name) => {
21
- switch (name) {
22
- case 'state': {
23
- return Resolve(() => useWfState(), 'Workflow-State');
24
- }
25
- case 'resume': {
26
- return Resolve(() => useWfState().resume, 'Workflow-Resume');
27
- }
28
- case 'indexes': {
29
- return Resolve(() => useWfState().indexes, 'Workflow-Indexes');
30
- }
31
- case 'schemaId': {
32
- return Resolve(() => useWfState().schemaId, 'Workflow-SchemaId');
33
- }
34
- case 'stepId': {
35
- return Resolve(() => useWfState().stepId(), 'Workflow-StepId');
36
- }
37
- case 'context': {
38
- return Resolve(() => useWfState().ctx(), 'Workflow-Context');
39
- }
40
- case 'input': {
41
- return Resolve(() => useWfState().input(), 'Workflow-Input');
42
- }
43
- }
29
+ switch (name) {
30
+ case "state": return Resolve(() => useWfState(), "Workflow-State");
31
+ case "resume": return Resolve(() => useWfState().resume, "Workflow-Resume");
32
+ case "indexes": return Resolve(() => useWfState().indexes, "Workflow-Indexes");
33
+ case "schemaId": return Resolve(() => useWfState().schemaId, "Workflow-SchemaId");
34
+ case "stepId": return Resolve(() => useWfState().stepId(), "Workflow-StepId");
35
+ case "context": return Resolve(() => useWfState().ctx(), "Workflow-Context");
36
+ case "input": return Resolve(() => useWfState().input(), "Workflow-Input");
37
+ }
44
38
  };
45
39
 
46
- const LOGGER_TITLE = 'moost-wf';
47
- const CONTEXT_TYPE = 'WF';
48
- class MoostWf {
49
- constructor(opts, debug) {
50
- this.opts = opts;
51
- this.debug = debug;
52
- this.name = 'workflow';
53
- this.toInit = [];
54
- if (opts && opts instanceof WooksWf) {
55
- this.wfApp = opts;
56
- }
57
- else if (opts) {
58
- this.wfApp = createWfApp(opts);
59
- }
60
- else {
61
- this.wfApp = createWfApp();
62
- }
63
- }
64
- async onNotFound() {
65
- return defineMoostEventHandler({
66
- loggerTitle: LOGGER_TITLE,
67
- getIterceptorHandler: () => this.moost?.getGlobalInterceptorHandler(),
68
- getControllerInstance: () => this.moost,
69
- callControllerMethod: () => new Error('WF Handler not found'),
70
- logErrors: this.debug,
71
- targetPath: '',
72
- handlerType: '__SYSTEM__',
73
- })();
74
- }
75
- onInit(moost) {
76
- this.moost = moost;
77
- this.toInit.forEach(fn => {
78
- fn();
79
- });
80
- }
81
- getWfApp() {
82
- return this.wfApp;
83
- }
84
- attachSpy(fn) {
85
- return this.wfApp.attachSpy(fn);
86
- }
87
- detachSpy(fn) {
88
- this.wfApp.detachSpy(fn);
89
- }
90
- start(schemaId, initialContext, input) {
91
- return this.wfApp.start(schemaId, initialContext, input, () => { }, () => {
92
- const scopeId = useEventId().getId();
93
- getMoostInfact().unregisterScope(scopeId);
94
- });
95
- }
96
- resume(state, input) {
97
- return this.wfApp.resume(state, input, () => { }, () => {
98
- const scopeId = useEventId().getId();
99
- getMoostInfact().unregisterScope(scopeId);
100
- });
101
- }
102
- bindHandler(opts) {
103
- let fn;
104
- for (const handler of opts.handlers) {
105
- if (!['WF_STEP', 'WF_FLOW'].includes(handler.type)) {
106
- continue;
107
- }
108
- const schemaId = handler.path;
109
- const path = typeof schemaId === 'string' ? schemaId : typeof opts.method === 'string' ? opts.method : '';
110
- const targetPath = `${`${opts.prefix || ''}/${path}`.replace(/\/\/+/g, '/')}${path.endsWith('//') ? '/' : ''}`;
111
- fn = defineMoostEventHandler({
112
- contextType: CONTEXT_TYPE,
113
- loggerTitle: LOGGER_TITLE,
114
- getIterceptorHandler: opts.getIterceptorHandler,
115
- getControllerInstance: opts.getInstance,
116
- controllerMethod: opts.method,
117
- resolveArgs: opts.resolveArgs,
118
- manualUnscope: true,
119
- targetPath,
120
- handlerType: handler.type,
121
- });
122
- if (handler.type === 'WF_STEP') {
123
- this.wfApp.step(targetPath, {
124
- handler: fn,
125
- });
126
- opts.logHandler(`${''}(${handler.type})${''}${targetPath}`);
127
- }
128
- else {
129
- const mate = getWfMate();
130
- let wfSchema = mate.read(opts.fakeInstance, opts.method)?.wfSchema;
131
- if (!wfSchema) {
132
- wfSchema = mate.read(opts.fakeInstance)?.wfSchema;
133
- }
134
- const _fn = (async () => {
135
- setControllerContext(this.moost, 'bindHandler', targetPath);
136
- return fn();
137
- });
138
- this.toInit.push(() => {
139
- this.wfApp.flow(targetPath, wfSchema || [], opts.prefix === '/' ? '' : opts.prefix, _fn);
140
- opts.logHandler(`${''}(${handler.type})${''}${targetPath}`);
141
- });
142
- }
143
- }
144
- }
40
+ //#endregion
41
+ //#region packages/event-wf/src/event-wf.ts
42
+ function _define_property(obj, key, value) {
43
+ if (key in obj) Object.defineProperty(obj, key, {
44
+ value,
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true
48
+ });
49
+ else obj[key] = value;
50
+ return obj;
145
51
  }
52
+ const LOGGER_TITLE = "moost-wf";
53
+ const CONTEXT_TYPE = "WF";
54
+ var MoostWf = class {
55
+ async onNotFound() {
56
+ return defineMoostEventHandler({
57
+ loggerTitle: LOGGER_TITLE,
58
+ getIterceptorHandler: () => this.moost?.getGlobalInterceptorHandler(),
59
+ getControllerInstance: () => this.moost,
60
+ callControllerMethod: () => new Error("WF Handler not found"),
61
+ logErrors: this.debug,
62
+ targetPath: "",
63
+ handlerType: "__SYSTEM__"
64
+ })();
65
+ }
66
+ onInit(moost) {
67
+ this.moost = moost;
68
+ this.toInit.forEach((fn) => {
69
+ fn();
70
+ });
71
+ }
72
+ getWfApp() {
73
+ return this.wfApp;
74
+ }
75
+ attachSpy(fn) {
76
+ return this.wfApp.attachSpy(fn);
77
+ }
78
+ detachSpy(fn) {
79
+ this.wfApp.detachSpy(fn);
80
+ }
81
+ start(schemaId, initialContext, input) {
82
+ return this.wfApp.start(schemaId, initialContext, input, () => {}, () => {
83
+ const scopeId = useEventId().getId();
84
+ getMoostInfact().unregisterScope(scopeId);
85
+ });
86
+ }
87
+ resume(state, input) {
88
+ return this.wfApp.resume(state, input, () => {}, () => {
89
+ const scopeId = useEventId().getId();
90
+ getMoostInfact().unregisterScope(scopeId);
91
+ });
92
+ }
93
+ bindHandler(opts) {
94
+ let fn;
95
+ for (const handler of opts.handlers) {
96
+ if (!["WF_STEP", "WF_FLOW"].includes(handler.type)) continue;
97
+ const schemaId = handler.path;
98
+ const path = typeof schemaId === "string" ? schemaId : typeof opts.method === "string" ? opts.method : "";
99
+ const targetPath = `${`${opts.prefix || ""}/${path}`.replace(/\/\/+/g, "/")}${path.endsWith("//") ? "/" : ""}`;
100
+ fn = defineMoostEventHandler({
101
+ contextType: CONTEXT_TYPE,
102
+ loggerTitle: LOGGER_TITLE,
103
+ getIterceptorHandler: opts.getIterceptorHandler,
104
+ getControllerInstance: opts.getInstance,
105
+ controllerMethod: opts.method,
106
+ resolveArgs: opts.resolveArgs,
107
+ manualUnscope: true,
108
+ targetPath,
109
+ handlerType: handler.type
110
+ });
111
+ if (handler.type === "WF_STEP") {
112
+ this.wfApp.step(targetPath, { handler: fn });
113
+ opts.logHandler(`${"\x1B[36m"}(${handler.type})${"\x1B[32m"}${targetPath}`);
114
+ } else {
115
+ const mate = getWfMate();
116
+ let wfSchema = mate.read(opts.fakeInstance, opts.method)?.wfSchema;
117
+ if (!wfSchema) wfSchema = mate.read(opts.fakeInstance)?.wfSchema;
118
+ const _fn = async () => {
119
+ setControllerContext(this.moost, "bindHandler", targetPath);
120
+ return fn();
121
+ };
122
+ this.toInit.push(() => {
123
+ this.wfApp.flow(targetPath, wfSchema || [], opts.prefix === "/" ? "" : opts.prefix, _fn);
124
+ opts.logHandler(`${"\x1B[36m"}(${handler.type})${"\x1B[32m"}${targetPath}`);
125
+ });
126
+ }
127
+ }
128
+ }
129
+ constructor(opts, debug) {
130
+ _define_property(this, "opts", void 0);
131
+ _define_property(this, "debug", void 0);
132
+ _define_property(this, "name", void 0);
133
+ _define_property(this, "wfApp", void 0);
134
+ _define_property(this, "moost", void 0);
135
+ _define_property(this, "toInit", void 0);
136
+ this.opts = opts;
137
+ this.debug = debug;
138
+ this.name = "workflow";
139
+ this.toInit = [];
140
+ if (opts && opts instanceof WooksWf) this.wfApp = opts;
141
+ else if (opts) this.wfApp = createWfApp(opts);
142
+ else this.wfApp = createWfApp();
143
+ }
144
+ };
146
145
 
147
- export { MoostWf, Step, Workflow, WorkflowParam, WorkflowSchema };
146
+ //#endregion
147
+ export { MoostWf, Step, StepRetriableError, Workflow, WorkflowParam, WorkflowSchema, useWFContext, useWfState };
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@moostjs/event-wf",
3
- "version": "0.5.20",
3
+ "version": "0.5.22",
4
4
  "description": "@moostjs/event-wf",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
8
  "sideEffects": false,
9
+ "type": "module",
9
10
  "exports": {
10
11
  "./package.json": "./package.json",
11
12
  ".": {
13
+ "types": "./dist/index.d.ts",
12
14
  "import": "./dist/index.mjs",
13
- "require": "./dist/index.cjs",
14
- "types": "./dist/index.d.ts"
15
+ "require": "./dist/index.cjs"
15
16
  }
16
17
  },
17
18
  "files": [
@@ -35,15 +36,21 @@
35
36
  "bugs": {
36
37
  "url": "https://github.com/moostjs/moostjs/issues"
37
38
  },
38
- "peerDependencies": {},
39
39
  "dependencies": {
40
- "moost": "0.5.20",
41
- "wooks": "^0.5.20",
42
- "@wooksjs/event-core": "^0.5.20",
43
- "@wooksjs/event-wf": "^0.5.20",
44
40
  "@prostojs/infact": "^0.3.3",
45
41
  "@prostojs/mate": "^0.3.3",
46
- "@prostojs/wf": "^0.0.18"
42
+ "@prostojs/wf": "^0.0.18",
43
+ "@wooksjs/event-core": "^0.5.25",
44
+ "@wooksjs/event-wf": "^0.5.25",
45
+ "wooks": "^0.5.25",
46
+ "moost": "^0.5.22"
47
47
  },
48
- "homepage": "https://github.com/moostjs/moostjs/tree/main/packages/event-wf#readme"
49
- }
48
+ "homepage": "https://github.com/moostjs/moostjs/tree/main/packages/event-wf#readme",
49
+ "devDependencies": {
50
+ "vitest": "^3.0.5"
51
+ },
52
+ "scripts": {
53
+ "pub": "pnpm publish --access public",
54
+ "test": "vitest"
55
+ }
56
+ }