@moostjs/event-wf 0.3.9 → 0.3.11
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 +120 -151
- package/dist/index.mjs +118 -149
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -5,167 +5,136 @@ var eventWf = require('@wooksjs/event-wf');
|
|
|
5
5
|
var eventCore = require('@wooksjs/event-core');
|
|
6
6
|
var wf = require('@prostojs/wf');
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
12
|
-
purpose with or without fee is hereby granted.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
15
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
16
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
17
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
18
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
19
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
20
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
21
|
-
***************************************************************************** */
|
|
22
|
-
/* global Reflect, Promise */
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
8
|
+
function getWfMate() {
|
|
9
|
+
return moost.getMoostMate();
|
|
33
10
|
}
|
|
34
11
|
|
|
35
|
-
|
|
36
|
-
|
|
12
|
+
const LOGGER_TITLE = 'moost-wf';
|
|
13
|
+
const CONTEXT_TYPE = 'WF';
|
|
14
|
+
class MoostWf {
|
|
15
|
+
constructor(opts) {
|
|
16
|
+
this.opts = opts;
|
|
17
|
+
this.toInit = [];
|
|
18
|
+
const wfAppOpts = opts?.wooksWf;
|
|
19
|
+
if (wfAppOpts && wfAppOpts instanceof eventWf.WooksWf) {
|
|
20
|
+
this.wfApp = wfAppOpts;
|
|
21
|
+
}
|
|
22
|
+
else if (wfAppOpts) {
|
|
23
|
+
this.wfApp = eventWf.createWfApp(wfAppOpts);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
this.wfApp = eventWf.createWfApp();
|
|
27
|
+
}
|
|
28
|
+
if (!opts?.debug) {
|
|
29
|
+
moost.getMoostInfact().silent(true);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async onNotFound() {
|
|
33
|
+
const response = await moost.defineMoostEventHandler({
|
|
34
|
+
loggerTitle: LOGGER_TITLE,
|
|
35
|
+
getIterceptorHandler: () => this.moost?.getGlobalInterceptorHandler(),
|
|
36
|
+
getControllerInstance: () => this.moost,
|
|
37
|
+
callControllerMethod: () => undefined,
|
|
38
|
+
logErrors: this.opts?.debug,
|
|
39
|
+
})();
|
|
40
|
+
return response;
|
|
41
|
+
}
|
|
42
|
+
onInit(moost) {
|
|
43
|
+
this.moost = moost;
|
|
44
|
+
this.toInit.forEach(fn => fn());
|
|
45
|
+
}
|
|
46
|
+
getWfApp() {
|
|
47
|
+
return this.wfApp;
|
|
48
|
+
}
|
|
49
|
+
attachSpy(fn) {
|
|
50
|
+
return this.wfApp.attachSpy(fn);
|
|
51
|
+
}
|
|
52
|
+
detachSpy(fn) {
|
|
53
|
+
return this.wfApp.detachSpy(fn);
|
|
54
|
+
}
|
|
55
|
+
start(schemaId, initialContext, input) {
|
|
56
|
+
return this.wfApp.start(schemaId, initialContext, input, () => { }, () => {
|
|
57
|
+
const scopeId = eventCore.useEventId().getId();
|
|
58
|
+
moost.getMoostInfact().unregisterScope(scopeId);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
resume(schemaId, state, input) {
|
|
62
|
+
return this.wfApp.resume(schemaId, state, input, () => { }, () => {
|
|
63
|
+
const scopeId = eventCore.useEventId().getId();
|
|
64
|
+
moost.getMoostInfact().unregisterScope(scopeId);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
bindHandler(opts) {
|
|
68
|
+
let fn;
|
|
69
|
+
for (const handler of opts.handlers) {
|
|
70
|
+
if (!(['WF_STEP', 'WF_FLOW'].includes(handler.type)))
|
|
71
|
+
continue;
|
|
72
|
+
const schemaId = handler.path;
|
|
73
|
+
const path = typeof schemaId === 'string'
|
|
74
|
+
? schemaId
|
|
75
|
+
: typeof opts.method === 'string'
|
|
76
|
+
? opts.method
|
|
77
|
+
: '';
|
|
78
|
+
const targetPath = `${opts.prefix || ''}/${path}`.replace(/\/\/+/g, '/') + `${path.endsWith('//') ? '/' : ''}`; // explicit double slash "//" -> force url to end with slash
|
|
79
|
+
if (!fn) {
|
|
80
|
+
fn = moost.defineMoostEventHandler({
|
|
81
|
+
contextType: CONTEXT_TYPE,
|
|
82
|
+
loggerTitle: LOGGER_TITLE,
|
|
83
|
+
getIterceptorHandler: opts.getIterceptorHandler,
|
|
84
|
+
getControllerInstance: opts.getInstance,
|
|
85
|
+
controllerMethod: opts.method,
|
|
86
|
+
resolveArgs: opts.resolveArgs,
|
|
87
|
+
manualUnscope: true,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if (handler.type === 'WF_STEP') {
|
|
91
|
+
this.wfApp.step(targetPath, {
|
|
92
|
+
handler: fn,
|
|
93
|
+
});
|
|
94
|
+
opts.logHandler(`${'[36m'}(${handler.type})${'[32m'}${targetPath}`);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const mate = getWfMate();
|
|
98
|
+
let wfSchema = mate.read(opts.fakeInstance, opts.method)?.wfSchema;
|
|
99
|
+
if (!wfSchema) {
|
|
100
|
+
wfSchema = mate.read(opts.fakeInstance)?.wfSchema;
|
|
101
|
+
}
|
|
102
|
+
const _fn = fn;
|
|
103
|
+
this.toInit.push(() => {
|
|
104
|
+
this.wfApp.flow(targetPath, wfSchema || [], _fn);
|
|
105
|
+
opts.logHandler(`${'[36m'}(${handler.type})${'[32m'}${targetPath}`);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
37
110
|
}
|
|
38
111
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
class MoostWf {
|
|
42
|
-
constructor(opts) {
|
|
43
|
-
this.opts = opts;
|
|
44
|
-
this.toInit = [];
|
|
45
|
-
const wfAppOpts = opts === null || opts === void 0 ? void 0 : opts.wooksWf;
|
|
46
|
-
if (wfAppOpts && wfAppOpts instanceof eventWf.WooksWf) {
|
|
47
|
-
this.wfApp = wfAppOpts;
|
|
48
|
-
}
|
|
49
|
-
else if (wfAppOpts) {
|
|
50
|
-
this.wfApp = eventWf.createWfApp(wfAppOpts);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
this.wfApp = eventWf.createWfApp();
|
|
54
|
-
}
|
|
55
|
-
if (!(opts === null || opts === void 0 ? void 0 : opts.debug)) {
|
|
56
|
-
moost.getMoostInfact().silent(true);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
onNotFound() {
|
|
60
|
-
var _a;
|
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
const response = yield moost.defineMoostEventHandler({
|
|
63
|
-
loggerTitle: LOGGER_TITLE,
|
|
64
|
-
getIterceptorHandler: () => { var _a; return (_a = this.moost) === null || _a === void 0 ? void 0 : _a.getGlobalInterceptorHandler(); },
|
|
65
|
-
getControllerInstance: () => this.moost,
|
|
66
|
-
callControllerMethod: () => undefined,
|
|
67
|
-
logErrors: (_a = this.opts) === null || _a === void 0 ? void 0 : _a.debug,
|
|
68
|
-
})();
|
|
69
|
-
return response;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
onInit(moost) {
|
|
73
|
-
this.moost = moost;
|
|
74
|
-
this.toInit.forEach(fn => fn());
|
|
75
|
-
}
|
|
76
|
-
getWfApp() {
|
|
77
|
-
return this.wfApp;
|
|
78
|
-
}
|
|
79
|
-
attachSpy(fn) {
|
|
80
|
-
return this.wfApp.attachSpy(fn);
|
|
81
|
-
}
|
|
82
|
-
detachSpy(fn) {
|
|
83
|
-
return this.wfApp.detachSpy(fn);
|
|
84
|
-
}
|
|
85
|
-
start(schemaId, initialContext, input) {
|
|
86
|
-
return this.wfApp.start(schemaId, initialContext, input, () => { }, () => {
|
|
87
|
-
const scopeId = eventCore.useEventId().getId();
|
|
88
|
-
moost.getMoostInfact().unregisterScope(scopeId);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
resume(schemaId, state, input) {
|
|
92
|
-
return this.wfApp.resume(schemaId, state, input, () => { }, () => {
|
|
93
|
-
const scopeId = eventCore.useEventId().getId();
|
|
94
|
-
moost.getMoostInfact().unregisterScope(scopeId);
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
bindHandler(opts) {
|
|
98
|
-
var _a, _b;
|
|
99
|
-
let fn;
|
|
100
|
-
for (const handler of opts.handlers) {
|
|
101
|
-
if (!(['WF_STEP', 'WF_FLOW'].includes(handler.type)))
|
|
102
|
-
continue;
|
|
103
|
-
const schemaId = handler.path;
|
|
104
|
-
const path = typeof schemaId === 'string'
|
|
105
|
-
? schemaId
|
|
106
|
-
: typeof opts.method === 'string'
|
|
107
|
-
? opts.method
|
|
108
|
-
: '';
|
|
109
|
-
const targetPath = `${opts.prefix || ''}/${path}`.replace(/\/\/+/g, '/') + `${path.endsWith('//') ? '/' : ''}`; // explicit double slash "//" -> force url to end with slash
|
|
110
|
-
if (!fn) {
|
|
111
|
-
fn = moost.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
|
-
});
|
|
120
|
-
}
|
|
121
|
-
if (handler.type === 'WF_STEP') {
|
|
122
|
-
this.wfApp.step(targetPath, {
|
|
123
|
-
handler: fn,
|
|
124
|
-
});
|
|
125
|
-
opts.logHandler(`${'[36m'}(${handler.type})${'[32m'}${targetPath}`);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
const mate = getWfMate();
|
|
129
|
-
let wfSchema = (_a = mate.read(opts.fakeInstance, opts.method)) === null || _a === void 0 ? void 0 : _a.wfSchema;
|
|
130
|
-
if (!wfSchema) {
|
|
131
|
-
wfSchema = (_b = mate.read(opts.fakeInstance)) === null || _b === void 0 ? void 0 : _b.wfSchema;
|
|
132
|
-
}
|
|
133
|
-
const _fn = fn;
|
|
134
|
-
this.toInit.push(() => {
|
|
135
|
-
this.wfApp.flow(targetPath, wfSchema || [], _fn);
|
|
136
|
-
opts.logHandler(`${'[36m'}(${handler.type})${'[32m'}${targetPath}`);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
112
|
+
function WStep(path) {
|
|
113
|
+
return getWfMate().decorate('handlers', { path, type: 'WF_STEP' }, true);
|
|
141
114
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return
|
|
151
|
-
}
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
const WfSchemaId = () => moost.Resolve(() => eventWf.useWfState().schemaId);
|
|
159
|
-
const WfInput = (name) => moost.Resolve(() => {
|
|
160
|
-
const i = eventWf.useWfState().input();
|
|
161
|
-
return typeof i !== 'undefined' ? (name ? i[name] : i) : undefined;
|
|
115
|
+
function WFlow(path) {
|
|
116
|
+
return getWfMate().decorate('handlers', { path, type: 'WF_FLOW' }, true);
|
|
117
|
+
}
|
|
118
|
+
function WSchema(schema) {
|
|
119
|
+
return getWfMate().decorate('wfSchema', schema);
|
|
120
|
+
}
|
|
121
|
+
const WfCtx = (name) => moost.Resolve(() => {
|
|
122
|
+
const c = eventWf.useWfState().ctx();
|
|
123
|
+
return name ? c[name] : c;
|
|
124
|
+
}, name || 'WfCtx');
|
|
125
|
+
const WfResume = () => moost.Resolve(() => eventWf.useWfState().resume);
|
|
126
|
+
const WfIndexes = () => moost.Resolve(() => eventWf.useWfState().indexes);
|
|
127
|
+
const WfSchemaId = () => moost.Resolve(() => eventWf.useWfState().schemaId);
|
|
128
|
+
const WfInput = (name) => moost.Resolve(() => {
|
|
129
|
+
const i = eventWf.useWfState().input();
|
|
130
|
+
return typeof i !== 'undefined' ? (name ? i[name] : i) : undefined;
|
|
162
131
|
}, name || 'WfInput');
|
|
163
132
|
|
|
164
|
-
Object.defineProperty(exports,
|
|
133
|
+
Object.defineProperty(exports, "useWFContext", {
|
|
165
134
|
enumerable: true,
|
|
166
135
|
get: function () { return eventWf.useWFContext; }
|
|
167
136
|
});
|
|
168
|
-
Object.defineProperty(exports,
|
|
137
|
+
Object.defineProperty(exports, "StepRetriableError", {
|
|
169
138
|
enumerable: true,
|
|
170
139
|
get: function () { return wf.StepRetriableError; }
|
|
171
140
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -4,160 +4,129 @@ export { useWFContext } from '@wooksjs/event-wf';
|
|
|
4
4
|
import { useEventId } from '@wooksjs/event-core';
|
|
5
5
|
export { StepRetriableError } from '@prostojs/wf';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
-
purpose with or without fee is hereby granted.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
-
***************************************************************************** */
|
|
21
|
-
/* global Reflect, Promise */
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
25
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
26
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
27
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
28
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
29
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
30
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
31
|
-
});
|
|
7
|
+
function getWfMate() {
|
|
8
|
+
return getMoostMate();
|
|
32
9
|
}
|
|
33
10
|
|
|
34
|
-
|
|
35
|
-
|
|
11
|
+
const LOGGER_TITLE = 'moost-wf';
|
|
12
|
+
const CONTEXT_TYPE = 'WF';
|
|
13
|
+
class MoostWf {
|
|
14
|
+
constructor(opts) {
|
|
15
|
+
this.opts = opts;
|
|
16
|
+
this.toInit = [];
|
|
17
|
+
const wfAppOpts = opts?.wooksWf;
|
|
18
|
+
if (wfAppOpts && wfAppOpts instanceof WooksWf) {
|
|
19
|
+
this.wfApp = wfAppOpts;
|
|
20
|
+
}
|
|
21
|
+
else if (wfAppOpts) {
|
|
22
|
+
this.wfApp = createWfApp(wfAppOpts);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.wfApp = createWfApp();
|
|
26
|
+
}
|
|
27
|
+
if (!opts?.debug) {
|
|
28
|
+
getMoostInfact().silent(true);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async onNotFound() {
|
|
32
|
+
const response = await defineMoostEventHandler({
|
|
33
|
+
loggerTitle: LOGGER_TITLE,
|
|
34
|
+
getIterceptorHandler: () => this.moost?.getGlobalInterceptorHandler(),
|
|
35
|
+
getControllerInstance: () => this.moost,
|
|
36
|
+
callControllerMethod: () => undefined,
|
|
37
|
+
logErrors: this.opts?.debug,
|
|
38
|
+
})();
|
|
39
|
+
return response;
|
|
40
|
+
}
|
|
41
|
+
onInit(moost) {
|
|
42
|
+
this.moost = moost;
|
|
43
|
+
this.toInit.forEach(fn => fn());
|
|
44
|
+
}
|
|
45
|
+
getWfApp() {
|
|
46
|
+
return this.wfApp;
|
|
47
|
+
}
|
|
48
|
+
attachSpy(fn) {
|
|
49
|
+
return this.wfApp.attachSpy(fn);
|
|
50
|
+
}
|
|
51
|
+
detachSpy(fn) {
|
|
52
|
+
return this.wfApp.detachSpy(fn);
|
|
53
|
+
}
|
|
54
|
+
start(schemaId, initialContext, input) {
|
|
55
|
+
return this.wfApp.start(schemaId, initialContext, input, () => { }, () => {
|
|
56
|
+
const scopeId = useEventId().getId();
|
|
57
|
+
getMoostInfact().unregisterScope(scopeId);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
resume(schemaId, state, input) {
|
|
61
|
+
return this.wfApp.resume(schemaId, state, input, () => { }, () => {
|
|
62
|
+
const scopeId = useEventId().getId();
|
|
63
|
+
getMoostInfact().unregisterScope(scopeId);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
bindHandler(opts) {
|
|
67
|
+
let fn;
|
|
68
|
+
for (const handler of opts.handlers) {
|
|
69
|
+
if (!(['WF_STEP', 'WF_FLOW'].includes(handler.type)))
|
|
70
|
+
continue;
|
|
71
|
+
const schemaId = handler.path;
|
|
72
|
+
const path = typeof schemaId === 'string'
|
|
73
|
+
? schemaId
|
|
74
|
+
: typeof opts.method === 'string'
|
|
75
|
+
? opts.method
|
|
76
|
+
: '';
|
|
77
|
+
const targetPath = `${opts.prefix || ''}/${path}`.replace(/\/\/+/g, '/') + `${path.endsWith('//') ? '/' : ''}`; // explicit double slash "//" -> force url to end with slash
|
|
78
|
+
if (!fn) {
|
|
79
|
+
fn = defineMoostEventHandler({
|
|
80
|
+
contextType: CONTEXT_TYPE,
|
|
81
|
+
loggerTitle: LOGGER_TITLE,
|
|
82
|
+
getIterceptorHandler: opts.getIterceptorHandler,
|
|
83
|
+
getControllerInstance: opts.getInstance,
|
|
84
|
+
controllerMethod: opts.method,
|
|
85
|
+
resolveArgs: opts.resolveArgs,
|
|
86
|
+
manualUnscope: true,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (handler.type === 'WF_STEP') {
|
|
90
|
+
this.wfApp.step(targetPath, {
|
|
91
|
+
handler: fn,
|
|
92
|
+
});
|
|
93
|
+
opts.logHandler(`${'[36m'}(${handler.type})${'[32m'}${targetPath}`);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const mate = getWfMate();
|
|
97
|
+
let wfSchema = mate.read(opts.fakeInstance, opts.method)?.wfSchema;
|
|
98
|
+
if (!wfSchema) {
|
|
99
|
+
wfSchema = mate.read(opts.fakeInstance)?.wfSchema;
|
|
100
|
+
}
|
|
101
|
+
const _fn = fn;
|
|
102
|
+
this.toInit.push(() => {
|
|
103
|
+
this.wfApp.flow(targetPath, wfSchema || [], _fn);
|
|
104
|
+
opts.logHandler(`${'[36m'}(${handler.type})${'[32m'}${targetPath}`);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
36
109
|
}
|
|
37
110
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class MoostWf {
|
|
41
|
-
constructor(opts) {
|
|
42
|
-
this.opts = opts;
|
|
43
|
-
this.toInit = [];
|
|
44
|
-
const wfAppOpts = opts === null || opts === void 0 ? void 0 : opts.wooksWf;
|
|
45
|
-
if (wfAppOpts && wfAppOpts instanceof WooksWf) {
|
|
46
|
-
this.wfApp = wfAppOpts;
|
|
47
|
-
}
|
|
48
|
-
else if (wfAppOpts) {
|
|
49
|
-
this.wfApp = createWfApp(wfAppOpts);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
this.wfApp = createWfApp();
|
|
53
|
-
}
|
|
54
|
-
if (!(opts === null || opts === void 0 ? void 0 : opts.debug)) {
|
|
55
|
-
getMoostInfact().silent(true);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
onNotFound() {
|
|
59
|
-
var _a;
|
|
60
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
const response = yield defineMoostEventHandler({
|
|
62
|
-
loggerTitle: LOGGER_TITLE,
|
|
63
|
-
getIterceptorHandler: () => { var _a; return (_a = this.moost) === null || _a === void 0 ? void 0 : _a.getGlobalInterceptorHandler(); },
|
|
64
|
-
getControllerInstance: () => this.moost,
|
|
65
|
-
callControllerMethod: () => undefined,
|
|
66
|
-
logErrors: (_a = this.opts) === null || _a === void 0 ? void 0 : _a.debug,
|
|
67
|
-
})();
|
|
68
|
-
return response;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
onInit(moost) {
|
|
72
|
-
this.moost = moost;
|
|
73
|
-
this.toInit.forEach(fn => fn());
|
|
74
|
-
}
|
|
75
|
-
getWfApp() {
|
|
76
|
-
return this.wfApp;
|
|
77
|
-
}
|
|
78
|
-
attachSpy(fn) {
|
|
79
|
-
return this.wfApp.attachSpy(fn);
|
|
80
|
-
}
|
|
81
|
-
detachSpy(fn) {
|
|
82
|
-
return this.wfApp.detachSpy(fn);
|
|
83
|
-
}
|
|
84
|
-
start(schemaId, initialContext, input) {
|
|
85
|
-
return this.wfApp.start(schemaId, initialContext, input, () => { }, () => {
|
|
86
|
-
const scopeId = useEventId().getId();
|
|
87
|
-
getMoostInfact().unregisterScope(scopeId);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
resume(schemaId, state, input) {
|
|
91
|
-
return this.wfApp.resume(schemaId, state, input, () => { }, () => {
|
|
92
|
-
const scopeId = useEventId().getId();
|
|
93
|
-
getMoostInfact().unregisterScope(scopeId);
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
bindHandler(opts) {
|
|
97
|
-
var _a, _b;
|
|
98
|
-
let fn;
|
|
99
|
-
for (const handler of opts.handlers) {
|
|
100
|
-
if (!(['WF_STEP', 'WF_FLOW'].includes(handler.type)))
|
|
101
|
-
continue;
|
|
102
|
-
const schemaId = handler.path;
|
|
103
|
-
const path = typeof schemaId === 'string'
|
|
104
|
-
? schemaId
|
|
105
|
-
: typeof opts.method === 'string'
|
|
106
|
-
? opts.method
|
|
107
|
-
: '';
|
|
108
|
-
const targetPath = `${opts.prefix || ''}/${path}`.replace(/\/\/+/g, '/') + `${path.endsWith('//') ? '/' : ''}`; // explicit double slash "//" -> force url to end with slash
|
|
109
|
-
if (!fn) {
|
|
110
|
-
fn = defineMoostEventHandler({
|
|
111
|
-
contextType: CONTEXT_TYPE,
|
|
112
|
-
loggerTitle: LOGGER_TITLE,
|
|
113
|
-
getIterceptorHandler: opts.getIterceptorHandler,
|
|
114
|
-
getControllerInstance: opts.getInstance,
|
|
115
|
-
controllerMethod: opts.method,
|
|
116
|
-
resolveArgs: opts.resolveArgs,
|
|
117
|
-
manualUnscope: true,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
if (handler.type === 'WF_STEP') {
|
|
121
|
-
this.wfApp.step(targetPath, {
|
|
122
|
-
handler: fn,
|
|
123
|
-
});
|
|
124
|
-
opts.logHandler(`${'[36m'}(${handler.type})${'[32m'}${targetPath}`);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
const mate = getWfMate();
|
|
128
|
-
let wfSchema = (_a = mate.read(opts.fakeInstance, opts.method)) === null || _a === void 0 ? void 0 : _a.wfSchema;
|
|
129
|
-
if (!wfSchema) {
|
|
130
|
-
wfSchema = (_b = mate.read(opts.fakeInstance)) === null || _b === void 0 ? void 0 : _b.wfSchema;
|
|
131
|
-
}
|
|
132
|
-
const _fn = fn;
|
|
133
|
-
this.toInit.push(() => {
|
|
134
|
-
this.wfApp.flow(targetPath, wfSchema || [], _fn);
|
|
135
|
-
opts.logHandler(`${'[36m'}(${handler.type})${'[32m'}${targetPath}`);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
111
|
+
function WStep(path) {
|
|
112
|
+
return getWfMate().decorate('handlers', { path, type: 'WF_STEP' }, true);
|
|
140
113
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return
|
|
150
|
-
}
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
const WfSchemaId = () => Resolve(() => useWfState().schemaId);
|
|
158
|
-
const WfInput = (name) => Resolve(() => {
|
|
159
|
-
const i = useWfState().input();
|
|
160
|
-
return typeof i !== 'undefined' ? (name ? i[name] : i) : undefined;
|
|
114
|
+
function WFlow(path) {
|
|
115
|
+
return getWfMate().decorate('handlers', { path, type: 'WF_FLOW' }, true);
|
|
116
|
+
}
|
|
117
|
+
function WSchema(schema) {
|
|
118
|
+
return getWfMate().decorate('wfSchema', schema);
|
|
119
|
+
}
|
|
120
|
+
const WfCtx = (name) => Resolve(() => {
|
|
121
|
+
const c = useWfState().ctx();
|
|
122
|
+
return name ? c[name] : c;
|
|
123
|
+
}, name || 'WfCtx');
|
|
124
|
+
const WfResume = () => Resolve(() => useWfState().resume);
|
|
125
|
+
const WfIndexes = () => Resolve(() => useWfState().indexes);
|
|
126
|
+
const WfSchemaId = () => Resolve(() => useWfState().schemaId);
|
|
127
|
+
const WfInput = (name) => Resolve(() => {
|
|
128
|
+
const i = useWfState().input();
|
|
129
|
+
return typeof i !== 'undefined' ? (name ? i[name] : i) : undefined;
|
|
161
130
|
}, name || 'WfInput');
|
|
162
131
|
|
|
163
132
|
export { MoostWf, WFlow, WSchema, WStep, WfCtx, WfIndexes, WfInput, WfResume, WfSchemaId };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/event-wf",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.11",
|
|
4
4
|
"description": "@moostjs/event-wf",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"moost": "0.3.
|
|
40
|
-
"wooks": "^0.4.
|
|
41
|
-
"@wooksjs/event-core": "^0.4.
|
|
42
|
-
"@wooksjs/event-wf": "^0.4.
|
|
39
|
+
"moost": "0.3.11",
|
|
40
|
+
"wooks": "^0.4.11",
|
|
41
|
+
"@wooksjs/event-core": "^0.4.11",
|
|
42
|
+
"@wooksjs/event-wf": "^0.4.11",
|
|
43
43
|
"@prostojs/infact": "^0.1.13",
|
|
44
44
|
"@prostojs/mate": "^0.2.1",
|
|
45
45
|
"@prostojs/wf": "^0.0.10"
|