@moostjs/event-wf 0.3.11 → 0.3.13

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 CHANGED
@@ -12,20 +12,20 @@ function getWfMate() {
12
12
  const LOGGER_TITLE = 'moost-wf';
13
13
  const CONTEXT_TYPE = 'WF';
14
14
  class MoostWf {
15
- constructor(opts) {
15
+ constructor(opts, debug) {
16
16
  this.opts = opts;
17
+ this.debug = debug;
17
18
  this.toInit = [];
18
- const wfAppOpts = opts?.wooksWf;
19
- if (wfAppOpts && wfAppOpts instanceof eventWf.WooksWf) {
20
- this.wfApp = wfAppOpts;
19
+ if (opts && opts instanceof eventWf.WooksWf) {
20
+ this.wfApp = opts;
21
21
  }
22
- else if (wfAppOpts) {
23
- this.wfApp = eventWf.createWfApp(wfAppOpts);
22
+ else if (opts) {
23
+ this.wfApp = eventWf.createWfApp(opts);
24
24
  }
25
25
  else {
26
26
  this.wfApp = eventWf.createWfApp();
27
27
  }
28
- if (!opts?.debug) {
28
+ if (!debug) {
29
29
  moost.getMoostInfact().silent(true);
30
30
  }
31
31
  }
@@ -35,13 +35,13 @@ class MoostWf {
35
35
  getIterceptorHandler: () => this.moost?.getGlobalInterceptorHandler(),
36
36
  getControllerInstance: () => this.moost,
37
37
  callControllerMethod: () => undefined,
38
- logErrors: this.opts?.debug,
38
+ logErrors: this.debug,
39
39
  })();
40
40
  return response;
41
41
  }
42
42
  onInit(moost) {
43
43
  this.moost = moost;
44
- this.toInit.forEach(fn => fn());
44
+ this.toInit.forEach((fn) => fn());
45
45
  }
46
46
  getWfApp() {
47
47
  return this.wfApp;
@@ -67,7 +67,7 @@ class MoostWf {
67
67
  bindHandler(opts) {
68
68
  let fn;
69
69
  for (const handler of opts.handlers) {
70
- if (!(['WF_STEP', 'WF_FLOW'].includes(handler.type)))
70
+ if (!['WF_STEP', 'WF_FLOW'].includes(handler.type))
71
71
  continue;
72
72
  const schemaId = handler.path;
73
73
  const path = typeof schemaId === 'string'
@@ -75,7 +75,8 @@ class MoostWf {
75
75
  : typeof opts.method === 'string'
76
76
  ? opts.method
77
77
  : '';
78
- const targetPath = `${opts.prefix || ''}/${path}`.replace(/\/\/+/g, '/') + `${path.endsWith('//') ? '/' : ''}`; // explicit double slash "//" -> force url to end with slash
78
+ const targetPath = `${opts.prefix || ''}/${path}`.replace(/\/\/+/g, '/') +
79
+ `${path.endsWith('//') ? '/' : ''}`;
79
80
  if (!fn) {
80
81
  fn = moost.defineMoostEventHandler({
81
82
  contextType: CONTEXT_TYPE,
@@ -101,7 +102,7 @@ class MoostWf {
101
102
  }
102
103
  const _fn = fn;
103
104
  this.toInit.push(() => {
104
- this.wfApp.flow(targetPath, wfSchema || [], _fn);
105
+ this.wfApp.flow(targetPath, wfSchema || [], opts.prefix, _fn);
105
106
  opts.logHandler(`${''}(${handler.type})${''}${targetPath}`);
106
107
  });
107
108
  }
package/dist/index.d.ts CHANGED
@@ -1,70 +1,39 @@
1
- import { Moost } from 'moost';
2
- import { StepRetriableError } from '@prostojs/wf';
3
- import { TFlowOutput } from '@prostojs/wf';
4
- import { TMoostAdapter } from 'moost';
5
- import { TMoostAdapterOptions } from 'moost';
6
- import { TWooksWfOptions } from '@wooksjs/event-wf';
7
- import { TWorkflowSchema } from '@prostojs/wf';
8
- import { TWorkflowSpy } from '@prostojs/wf';
9
- import { useWFContext } from '@wooksjs/event-wf';
10
- import { WooksWf } from '@wooksjs/event-wf';
11
-
12
- export declare class MoostWf<T> implements TMoostAdapter<TWfHandlerMeta> {
13
- protected opts?: TMoostWfOpts<T> | undefined;
14
- protected wfApp: WooksWf<T>;
15
- constructor(opts?: TMoostWfOpts<T> | undefined);
16
- onNotFound(): Promise<unknown>;
17
- protected moost?: Moost;
18
- protected toInit: (() => void)[];
19
- onInit(moost: Moost): void;
20
- getWfApp(): WooksWf<T>;
21
- attachSpy<I>(fn: TWorkflowSpy<T, I>): () => void;
22
- detachSpy<I>(fn: TWorkflowSpy<T, I>): void;
23
- start<I>(schemaId: string, initialContext: T, input?: I): Promise<TFlowOutput<T, I>>;
24
- resume<I>(schemaId: string, state: {
25
- context: T;
26
- indexes: number[];
27
- }, input?: I): Promise<TFlowOutput<T, I>>;
28
- bindHandler<T extends object = object>(opts: TMoostAdapterOptions<TWfHandlerMeta, T>): void;
29
- }
30
-
31
- export { StepRetriableError }
32
-
33
- export { TFlowOutput }
34
-
35
- export declare interface TMoostWfOpts<T> {
36
- /**
37
- * wooksWf options or instance
38
- */
39
- wooksWf?: WooksWf<T> | TWooksWfOptions;
40
- /**
41
- * more internal logs are printed when true
42
- */
43
- debug?: boolean;
44
- }
45
-
46
- export declare interface TWfHandlerMeta {
47
- path: string;
48
- }
49
-
50
- export { TWorkflowSchema }
51
-
52
- export { useWFContext }
53
-
54
- export declare const WfCtx: (name?: string) => ParameterDecorator & PropertyDecorator;
55
-
56
- export declare const WfIndexes: () => ParameterDecorator & PropertyDecorator;
57
-
58
- export declare const WfInput: (name?: string) => ParameterDecorator & PropertyDecorator;
59
-
60
- export declare function WFlow(path?: string): MethodDecorator;
61
-
62
- export declare const WfResume: () => ParameterDecorator & PropertyDecorator;
63
-
64
- export declare const WfSchemaId: () => ParameterDecorator & PropertyDecorator;
65
-
66
- export declare function WSchema<T>(schema: TWorkflowSchema<T>): MethodDecorator;
67
-
68
- export declare function WStep(path?: string): MethodDecorator;
69
-
70
- export { }
1
+ import { TMoostAdapter, Moost, TMoostAdapterOptions } from 'moost';
2
+ import { WooksWf, TWooksWfOptions } from '@wooksjs/event-wf';
3
+ export { useWFContext } from '@wooksjs/event-wf';
4
+ import { TWorkflowSpy, TFlowOutput, TWorkflowSchema } from '@prostojs/wf';
5
+ export { StepRetriableError, TFlowOutput, TWorkflowSchema } from '@prostojs/wf';
6
+
7
+ interface TWfHandlerMeta {
8
+ path: string;
9
+ }
10
+ declare class MoostWf<T> implements TMoostAdapter<TWfHandlerMeta> {
11
+ protected opts?: WooksWf<T> | TWooksWfOptions | undefined;
12
+ private readonly debug?;
13
+ protected wfApp: WooksWf<T>;
14
+ constructor(opts?: WooksWf<T> | TWooksWfOptions | undefined, debug?: boolean | undefined);
15
+ onNotFound(): Promise<unknown>;
16
+ protected moost?: Moost;
17
+ protected toInit: (() => void)[];
18
+ onInit(moost: Moost): void;
19
+ getWfApp(): WooksWf<T>;
20
+ attachSpy<I>(fn: TWorkflowSpy<T, I>): () => void;
21
+ detachSpy<I>(fn: TWorkflowSpy<T, I>): void;
22
+ start<I>(schemaId: string, initialContext: T, input?: I): Promise<TFlowOutput<T, I>>;
23
+ resume<I>(schemaId: string, state: {
24
+ context: T;
25
+ indexes: number[];
26
+ }, input?: I): Promise<TFlowOutput<T, I>>;
27
+ bindHandler<T extends object = object>(opts: TMoostAdapterOptions<TWfHandlerMeta, T>): void;
28
+ }
29
+
30
+ declare function WStep(path?: string): MethodDecorator;
31
+ declare function WFlow(path?: string): MethodDecorator;
32
+ declare function WSchema<T>(schema: TWorkflowSchema<T>): MethodDecorator;
33
+ declare const WfCtx: (name?: string) => ParameterDecorator & PropertyDecorator;
34
+ declare const WfResume: () => ParameterDecorator & PropertyDecorator;
35
+ declare const WfIndexes: () => ParameterDecorator & PropertyDecorator;
36
+ declare const WfSchemaId: () => ParameterDecorator & PropertyDecorator;
37
+ declare const WfInput: (name?: string) => ParameterDecorator & PropertyDecorator;
38
+
39
+ export { MoostWf, type TWfHandlerMeta, WFlow, WSchema, WStep, WfCtx, WfIndexes, WfInput, WfResume, WfSchemaId };
package/dist/index.mjs CHANGED
@@ -11,20 +11,20 @@ function getWfMate() {
11
11
  const LOGGER_TITLE = 'moost-wf';
12
12
  const CONTEXT_TYPE = 'WF';
13
13
  class MoostWf {
14
- constructor(opts) {
14
+ constructor(opts, debug) {
15
15
  this.opts = opts;
16
+ this.debug = debug;
16
17
  this.toInit = [];
17
- const wfAppOpts = opts?.wooksWf;
18
- if (wfAppOpts && wfAppOpts instanceof WooksWf) {
19
- this.wfApp = wfAppOpts;
18
+ if (opts && opts instanceof WooksWf) {
19
+ this.wfApp = opts;
20
20
  }
21
- else if (wfAppOpts) {
22
- this.wfApp = createWfApp(wfAppOpts);
21
+ else if (opts) {
22
+ this.wfApp = createWfApp(opts);
23
23
  }
24
24
  else {
25
25
  this.wfApp = createWfApp();
26
26
  }
27
- if (!opts?.debug) {
27
+ if (!debug) {
28
28
  getMoostInfact().silent(true);
29
29
  }
30
30
  }
@@ -34,13 +34,13 @@ class MoostWf {
34
34
  getIterceptorHandler: () => this.moost?.getGlobalInterceptorHandler(),
35
35
  getControllerInstance: () => this.moost,
36
36
  callControllerMethod: () => undefined,
37
- logErrors: this.opts?.debug,
37
+ logErrors: this.debug,
38
38
  })();
39
39
  return response;
40
40
  }
41
41
  onInit(moost) {
42
42
  this.moost = moost;
43
- this.toInit.forEach(fn => fn());
43
+ this.toInit.forEach((fn) => fn());
44
44
  }
45
45
  getWfApp() {
46
46
  return this.wfApp;
@@ -66,7 +66,7 @@ class MoostWf {
66
66
  bindHandler(opts) {
67
67
  let fn;
68
68
  for (const handler of opts.handlers) {
69
- if (!(['WF_STEP', 'WF_FLOW'].includes(handler.type)))
69
+ if (!['WF_STEP', 'WF_FLOW'].includes(handler.type))
70
70
  continue;
71
71
  const schemaId = handler.path;
72
72
  const path = typeof schemaId === 'string'
@@ -74,7 +74,8 @@ class MoostWf {
74
74
  : typeof opts.method === 'string'
75
75
  ? opts.method
76
76
  : '';
77
- const targetPath = `${opts.prefix || ''}/${path}`.replace(/\/\/+/g, '/') + `${path.endsWith('//') ? '/' : ''}`; // explicit double slash "//" -> force url to end with slash
77
+ const targetPath = `${opts.prefix || ''}/${path}`.replace(/\/\/+/g, '/') +
78
+ `${path.endsWith('//') ? '/' : ''}`;
78
79
  if (!fn) {
79
80
  fn = defineMoostEventHandler({
80
81
  contextType: CONTEXT_TYPE,
@@ -100,7 +101,7 @@ class MoostWf {
100
101
  }
101
102
  const _fn = fn;
102
103
  this.toInit.push(() => {
103
- this.wfApp.flow(targetPath, wfSchema || [], _fn);
104
+ this.wfApp.flow(targetPath, wfSchema || [], opts.prefix, _fn);
104
105
  opts.logHandler(`${''}(${handler.type})${''}${targetPath}`);
105
106
  });
106
107
  }
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@moostjs/event-wf",
3
- "version": "0.3.11",
3
+ "version": "0.3.13",
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
9
  "exports": {
10
+ "./package.json": "./package.json",
10
11
  ".": {
11
12
  "import": "./dist/index.mjs",
12
13
  "require": "./dist/index.cjs",
@@ -36,13 +37,13 @@
36
37
  },
37
38
  "peerDependencies": {},
38
39
  "dependencies": {
39
- "moost": "0.3.11",
40
- "wooks": "^0.4.11",
41
- "@wooksjs/event-core": "^0.4.11",
42
- "@wooksjs/event-wf": "^0.4.11",
40
+ "moost": "0.3.13",
41
+ "wooks": "^0.4.15",
42
+ "@wooksjs/event-core": "^0.4.15",
43
+ "@wooksjs/event-wf": "^0.4.15",
43
44
  "@prostojs/infact": "^0.1.13",
44
45
  "@prostojs/mate": "^0.2.1",
45
- "@prostojs/wf": "^0.0.10"
46
+ "@prostojs/wf": "^0.0.12"
46
47
  },
47
48
  "homepage": "https://github.com/moostjs/moostjs/tree/main/packages/event-wf#readme"
48
49
  }