@wooksjs/event-wf 0.4.26 → 0.4.28

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/README.md CHANGED
@@ -78,4 +78,4 @@ Contributions to the `@wooksjs/event-wf` project are welcome. If you find any bu
78
78
 
79
79
  ## License
80
80
 
81
- `@wooksjs/event-wf` is licensed under the [MIT license](https://github.com/wooksjs/wooksjs/blob/main/LICENSE).
81
+ `@wooksjs/event-wf` is licensed under the [MIT license](https://github.com/wooksjs/wooksjs/blob/main/LICENSE).
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var eventCore = require('@wooksjs/event-core');
4
- var wooks = require('wooks');
5
4
  var wf = require('@prostojs/wf');
5
+ var wooks = require('wooks');
6
6
 
7
7
  function createWfContext(data, options) {
8
8
  return eventCore.createEventContext({
@@ -28,24 +28,36 @@ function useWFContext() {
28
28
  return eventCore.useEventContext('WF');
29
29
  }
30
30
 
31
+ function useWfState() {
32
+ const { store, getCtx } = useWFContext();
33
+ const event = store('event');
34
+ return {
35
+ ctx: () => event.get('inputContext'),
36
+ input: () => event.get('input'),
37
+ schemaId: event.get('schemaId'),
38
+ indexes: () => event.get('indexes'),
39
+ resume: getCtx().resume,
40
+ };
41
+ }
42
+
31
43
  class WooksWorkflow extends wf.Workflow {
32
44
  constructor(wooks) {
33
45
  super([]);
34
46
  this.wooks = wooks;
35
47
  }
36
48
  resolveStep(stepId) {
37
- const stepIdNorm = ('/' + stepId).replace(/\/\/+/g, '/');
49
+ const stepIdNorm = `/${stepId}`.replace(/\/\/+/g, '/');
38
50
  try {
39
51
  useWFContext();
40
52
  const found = this.wooks.lookup('WF_STEP', stepIdNorm);
41
- if (found?.handlers?.length) {
53
+ if (found.handlers?.length) {
42
54
  return found.handlers[0]();
43
55
  }
44
56
  }
45
- catch (e) {
57
+ catch (error) {
46
58
  const router = this.wooks.getRouter();
47
59
  const found = router.lookup('WF_STEP', stepIdNorm);
48
- if (found?.route?.handlers?.length) {
60
+ if (found?.route?.handlers.length) {
49
61
  return found.route.handlers[0]();
50
62
  }
51
63
  }
@@ -68,7 +80,7 @@ class WooksWf extends wooks.WooksAdapterBase {
68
80
  return this.wf.attachSpy(fn);
69
81
  }
70
82
  detachSpy(fn) {
71
- return this.wf.detachSpy(fn);
83
+ this.wf.detachSpy(fn);
72
84
  }
73
85
  step(id, opts) {
74
86
  const step = wf.createStep(id, opts);
@@ -76,7 +88,10 @@ class WooksWf extends wooks.WooksAdapterBase {
76
88
  }
77
89
  flow(id, schema, prefix, init) {
78
90
  this.wf.register(id, schema, prefix);
79
- return this.on('WF_FLOW', id, () => ({ init, id }));
91
+ return this.on('WF_FLOW', id, () => ({
92
+ init,
93
+ id,
94
+ }));
80
95
  }
81
96
  start(schemaId, inputContext, input, spy, cleanup) {
82
97
  return this._start(schemaId, inputContext, undefined, input, spy, cleanup);
@@ -92,11 +107,9 @@ class WooksWf extends wooks.WooksAdapterBase {
92
107
  indexes,
93
108
  input,
94
109
  }, this.mergeEventOptions(this.opts?.eventOptions));
95
- const { handlers: foundHandlers } = this.wooks.lookup('WF_FLOW', '/' + schemaId);
96
- const handlers = foundHandlers ||
97
- (this.opts?.onNotFound && [this.opts.onNotFound]) ||
98
- null;
99
- if (handlers && handlers.length) {
110
+ const { handlers: foundHandlers } = this.wooks.lookup('WF_FLOW', `/${schemaId}`);
111
+ const handlers = foundHandlers || (this.opts?.onNotFound && [this.opts.onNotFound]) || null;
112
+ if (handlers && handlers.length > 0) {
100
113
  let result = {};
101
114
  let firstStep = true;
102
115
  const _spy = (...args) => {
@@ -129,9 +142,9 @@ class WooksWf extends wooks.WooksAdapterBase {
129
142
  }
130
143
  }
131
144
  }
132
- catch (e) {
145
+ catch (error) {
133
146
  clean();
134
- throw e;
147
+ throw error;
135
148
  }
136
149
  clean();
137
150
  clearCtx();
@@ -145,7 +158,7 @@ class WooksWf extends wooks.WooksAdapterBase {
145
158
  }
146
159
  }
147
160
  clearCtx();
148
- throw new Error('Unknown schemaId: ' + schemaId);
161
+ throw new Error(`Unknown schemaId: ${schemaId}`);
149
162
  }
150
163
  onError(e) {
151
164
  if (this.opts?.onError) {
@@ -158,10 +171,10 @@ class WooksWf extends wooks.WooksAdapterBase {
158
171
  }
159
172
  error(e) {
160
173
  if (typeof e === 'string') {
161
- console.error('' + 'ERROR: ' + '' + e);
174
+ console.error(`${''}ERROR: ${''}${e}`);
162
175
  }
163
176
  else {
164
- console.error('' + 'ERROR: ' + '' + e.message);
177
+ console.error(`${''}ERROR: ${''}${e.message}`);
165
178
  }
166
179
  }
167
180
  }
@@ -169,18 +182,6 @@ function createWfApp(opts, wooks) {
169
182
  return new WooksWf(opts, wooks);
170
183
  }
171
184
 
172
- function useWfState() {
173
- const { store, getCtx } = useWFContext();
174
- const event = store('event');
175
- return {
176
- ctx: () => event.get('inputContext'),
177
- input: () => event.get('input'),
178
- schemaId: event.get('schemaId'),
179
- indexes: () => event.get('indexes'),
180
- resume: getCtx().resume,
181
- };
182
- }
183
-
184
185
  exports.WooksWf = WooksWf;
185
186
  exports.createWfApp = createWfApp;
186
187
  exports.createWfContext = createWfContext;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,18 @@
1
1
  import * as _wooksjs_event_core from '@wooksjs/event-core';
2
2
  import { TEventOptions, TEmpty } from '@wooksjs/event-core';
3
3
  import * as _prostojs_router from '@prostojs/router';
4
- import { Wooks, TWooksHandler, TWooksOptions, WooksAdapterBase } from 'wooks';
5
4
  import { TConsoleBase } from '@prostojs/logger';
6
5
  import { Workflow, Step, TWorkflowSpy, TStepHandler, TWorkflowSchema, TFlowOutput } from '@prostojs/wf';
7
6
  export { TStepHandler, TWorkflowSchema } from '@prostojs/wf';
7
+ import { Wooks, TWooksHandler, TWooksOptions, WooksAdapterBase } from 'wooks';
8
+
9
+ declare function useWfState(): {
10
+ ctx: <T>() => T;
11
+ input: <I>() => I | undefined;
12
+ schemaId: string | undefined;
13
+ indexes: () => number[] | undefined;
14
+ resume: boolean;
15
+ };
8
16
 
9
17
  interface TWFEventData {
10
18
  schemaId: string;
@@ -29,7 +37,7 @@ declare function createWfContext(data: Omit<TWFEventData, 'type'>, options: TEve
29
37
  };
30
38
  init: <K2_1 extends keyof Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_1, getter: () => Required<Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>[K2_1]) => Required<Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>[K2_1];
31
39
  set: <K2_2 extends keyof Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_2, v: Required<(TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>)[K]>[K2_2]) => Required<(TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>)[K]>[K2_2];
32
- get: <K2_3 extends keyof Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_3) => Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K][K2_3];
40
+ get: <K2_3 extends keyof Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_3) => Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K][K2_3] | undefined;
33
41
  has: <K2_4 extends keyof Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_4) => boolean;
34
42
  del: <K2_5 extends keyof Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_5) => void;
35
43
  entries: () => [string, unknown][];
@@ -50,7 +58,7 @@ declare function resumeWfContext(data: Omit<TWFEventData, 'type'>, options: TEve
50
58
  };
51
59
  init: <K2_1 extends keyof Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_1, getter: () => Required<Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>[K2_1]) => Required<Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>[K2_1];
52
60
  set: <K2_2 extends keyof Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_2, v: Required<(TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>)[K]>[K2_2]) => Required<(TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>)[K]>[K2_2];
53
- get: <K2_3 extends keyof Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_3) => Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K][K2_3];
61
+ get: <K2_3 extends keyof Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_3) => Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K][K2_3] | undefined;
54
62
  has: <K2_4 extends keyof Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_4) => boolean;
55
63
  del: <K2_5 extends keyof Required<TWFContextStore & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_5) => void;
56
64
  entries: () => [string, unknown][];
@@ -76,7 +84,7 @@ declare function useWFContext<T extends TEmpty>(): {
76
84
  };
77
85
  init: <K2_1 extends keyof Required<TWFContextStore & T & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_1, getter: () => Required<Required<TWFContextStore & T & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>[K2_1]) => Required<Required<TWFContextStore & T & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>[K2_1];
78
86
  set: <K2_2 extends keyof Required<TWFContextStore & T & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_2, v: Required<(TWFContextStore & T & _wooksjs_event_core.TGenericContextStore<TWFEventData>)[K]>[K2_2]) => Required<(TWFContextStore & T & _wooksjs_event_core.TGenericContextStore<TWFEventData>)[K]>[K2_2];
79
- get: <K2_3 extends keyof Required<TWFContextStore & T & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_3) => Required<TWFContextStore & T & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K][K2_3];
87
+ get: <K2_3 extends keyof Required<TWFContextStore & T & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_3) => Required<TWFContextStore & T & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K][K2_3] | undefined;
80
88
  has: <K2_4 extends keyof Required<TWFContextStore & T & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_4) => boolean;
81
89
  del: <K2_5 extends keyof Required<TWFContextStore & T & _wooksjs_event_core.TGenericContextStore<TWFEventData>>[K]>(key2: K2_5) => void;
82
90
  entries: () => [string, unknown][];
@@ -89,7 +97,7 @@ declare function useWFContext<T extends TEmpty>(): {
89
97
  declare class WooksWorkflow<T, IR> extends Workflow<T, IR> {
90
98
  protected wooks: Wooks;
91
99
  constructor(wooks: Wooks);
92
- protected resolveStep<I, IR>(stepId: string): Step<T, I, IR>;
100
+ protected resolveStep<I, IR2>(stepId: string): Step<T, I, IR2>;
93
101
  }
94
102
 
95
103
  declare const wfShortcuts: {
@@ -97,8 +105,8 @@ declare const wfShortcuts: {
97
105
  step: string;
98
106
  };
99
107
  interface TWooksWfOptions {
100
- onError?(e: Error): void;
101
- onNotFound?: TWooksHandler<unknown>;
108
+ onError?: (e: Error) => void;
109
+ onNotFound?: TWooksHandler;
102
110
  onUnknownFlow?: (schemaId: string, raiseError: () => void) => unknown;
103
111
  logger?: TConsoleBase;
104
112
  eventOptions?: TEventOptions;
@@ -134,12 +142,4 @@ declare class WooksWf<T = any, IR = any> extends WooksAdapterBase {
134
142
  */
135
143
  declare function createWfApp<T>(opts?: TWooksWfOptions, wooks?: Wooks | WooksAdapterBase): WooksWf<T, any>;
136
144
 
137
- declare function useWfState(): {
138
- ctx: <T>() => T;
139
- input: <I>() => I | undefined;
140
- schemaId: string;
141
- indexes: () => number[] | undefined;
142
- resume: boolean;
143
- };
144
-
145
145
  export { type TWFContextStore, type TWFEventData, type TWooksWfOptions, WooksWf, createWfApp, createWfContext, resumeWfContext, useWFContext, useWfState, wfShortcuts };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createEventContext, useEventContext } from '@wooksjs/event-core';
2
- import { WooksAdapterBase } from 'wooks';
3
2
  import { Workflow, createStep } from '@prostojs/wf';
3
+ import { WooksAdapterBase } from 'wooks';
4
4
 
5
5
  function createWfContext(data, options) {
6
6
  return createEventContext({
@@ -26,24 +26,36 @@ function useWFContext() {
26
26
  return useEventContext('WF');
27
27
  }
28
28
 
29
+ function useWfState() {
30
+ const { store, getCtx } = useWFContext();
31
+ const event = store('event');
32
+ return {
33
+ ctx: () => event.get('inputContext'),
34
+ input: () => event.get('input'),
35
+ schemaId: event.get('schemaId'),
36
+ indexes: () => event.get('indexes'),
37
+ resume: getCtx().resume,
38
+ };
39
+ }
40
+
29
41
  class WooksWorkflow extends Workflow {
30
42
  constructor(wooks) {
31
43
  super([]);
32
44
  this.wooks = wooks;
33
45
  }
34
46
  resolveStep(stepId) {
35
- const stepIdNorm = ('/' + stepId).replace(/\/\/+/g, '/');
47
+ const stepIdNorm = `/${stepId}`.replace(/\/\/+/g, '/');
36
48
  try {
37
49
  useWFContext();
38
50
  const found = this.wooks.lookup('WF_STEP', stepIdNorm);
39
- if (found?.handlers?.length) {
51
+ if (found.handlers?.length) {
40
52
  return found.handlers[0]();
41
53
  }
42
54
  }
43
- catch (e) {
55
+ catch (error) {
44
56
  const router = this.wooks.getRouter();
45
57
  const found = router.lookup('WF_STEP', stepIdNorm);
46
- if (found?.route?.handlers?.length) {
58
+ if (found?.route?.handlers.length) {
47
59
  return found.route.handlers[0]();
48
60
  }
49
61
  }
@@ -66,7 +78,7 @@ class WooksWf extends WooksAdapterBase {
66
78
  return this.wf.attachSpy(fn);
67
79
  }
68
80
  detachSpy(fn) {
69
- return this.wf.detachSpy(fn);
81
+ this.wf.detachSpy(fn);
70
82
  }
71
83
  step(id, opts) {
72
84
  const step = createStep(id, opts);
@@ -74,7 +86,10 @@ class WooksWf extends WooksAdapterBase {
74
86
  }
75
87
  flow(id, schema, prefix, init) {
76
88
  this.wf.register(id, schema, prefix);
77
- return this.on('WF_FLOW', id, () => ({ init, id }));
89
+ return this.on('WF_FLOW', id, () => ({
90
+ init,
91
+ id,
92
+ }));
78
93
  }
79
94
  start(schemaId, inputContext, input, spy, cleanup) {
80
95
  return this._start(schemaId, inputContext, undefined, input, spy, cleanup);
@@ -90,11 +105,9 @@ class WooksWf extends WooksAdapterBase {
90
105
  indexes,
91
106
  input,
92
107
  }, this.mergeEventOptions(this.opts?.eventOptions));
93
- const { handlers: foundHandlers } = this.wooks.lookup('WF_FLOW', '/' + schemaId);
94
- const handlers = foundHandlers ||
95
- (this.opts?.onNotFound && [this.opts.onNotFound]) ||
96
- null;
97
- if (handlers && handlers.length) {
108
+ const { handlers: foundHandlers } = this.wooks.lookup('WF_FLOW', `/${schemaId}`);
109
+ const handlers = foundHandlers || (this.opts?.onNotFound && [this.opts.onNotFound]) || null;
110
+ if (handlers && handlers.length > 0) {
98
111
  let result = {};
99
112
  let firstStep = true;
100
113
  const _spy = (...args) => {
@@ -127,9 +140,9 @@ class WooksWf extends WooksAdapterBase {
127
140
  }
128
141
  }
129
142
  }
130
- catch (e) {
143
+ catch (error) {
131
144
  clean();
132
- throw e;
145
+ throw error;
133
146
  }
134
147
  clean();
135
148
  clearCtx();
@@ -143,7 +156,7 @@ class WooksWf extends WooksAdapterBase {
143
156
  }
144
157
  }
145
158
  clearCtx();
146
- throw new Error('Unknown schemaId: ' + schemaId);
159
+ throw new Error(`Unknown schemaId: ${schemaId}`);
147
160
  }
148
161
  onError(e) {
149
162
  if (this.opts?.onError) {
@@ -156,10 +169,10 @@ class WooksWf extends WooksAdapterBase {
156
169
  }
157
170
  error(e) {
158
171
  if (typeof e === 'string') {
159
- console.error('' + 'ERROR: ' + '' + e);
172
+ console.error(`${''}ERROR: ${''}${e}`);
160
173
  }
161
174
  else {
162
- console.error('' + 'ERROR: ' + '' + e.message);
175
+ console.error(`${''}ERROR: ${''}${e.message}`);
163
176
  }
164
177
  }
165
178
  }
@@ -167,16 +180,4 @@ function createWfApp(opts, wooks) {
167
180
  return new WooksWf(opts, wooks);
168
181
  }
169
182
 
170
- function useWfState() {
171
- const { store, getCtx } = useWFContext();
172
- const event = store('event');
173
- return {
174
- ctx: () => event.get('inputContext'),
175
- input: () => event.get('input'),
176
- schemaId: event.get('schemaId'),
177
- indexes: () => event.get('indexes'),
178
- resume: getCtx().resume,
179
- };
180
- }
181
-
182
183
  export { WooksWf, createWfApp, createWfContext, resumeWfContext, useWFContext, useWfState, wfShortcuts };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-wf",
3
- "version": "0.4.26",
3
+ "version": "0.4.28",
4
4
  "description": "@wooksjs/event-wf",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -33,8 +33,8 @@
33
33
  "author": "Artem Maltsev",
34
34
  "license": "MIT",
35
35
  "peerDependencies": {
36
- "wooks": "0.4.26",
37
- "@wooksjs/event-core": "0.4.26"
36
+ "wooks": "0.4.28",
37
+ "@wooksjs/event-core": "0.4.28"
38
38
  },
39
39
  "dependencies": {
40
40
  "@prostojs/logger": "^0.4.0",