@wooksjs/event-wf 0.4.0 → 0.4.2

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
@@ -90,6 +90,12 @@ class WooksWf extends wooks.WooksAdapterBase {
90
90
  this.logger = (opts === null || opts === void 0 ? void 0 : opts.logger) || this.getLogger('wooks-wf');
91
91
  this.wf = new WooksWorkflow(this.wooks);
92
92
  }
93
+ attachSpy(fn) {
94
+ return this.wf.attachSpy(fn);
95
+ }
96
+ detachSpy(fn) {
97
+ return this.wf.detachSpy(fn);
98
+ }
93
99
  step(id, opts) {
94
100
  const step = wf.createStep(id, opts);
95
101
  return this.on('WF_STEP', id, () => step);
@@ -98,13 +104,13 @@ class WooksWf extends wooks.WooksAdapterBase {
98
104
  this.wf.register(id, schema);
99
105
  return this.on('WF_FLOW', id, () => ({ init, id }));
100
106
  }
101
- start(schemaId, inputContext, input, cleanup) {
102
- return this._start(schemaId, inputContext, undefined, input, cleanup);
107
+ start(schemaId, inputContext, input, spy, cleanup) {
108
+ return this._start(schemaId, inputContext, undefined, input, spy, cleanup);
103
109
  }
104
- resume(schemaId, inputContext, indexes, input, cleanup) {
105
- return this._start(schemaId, inputContext, indexes, input, cleanup);
110
+ resume(schemaId, state, input, spy, cleanup) {
111
+ return this._start(schemaId, state.context, state.indexes, input, spy, cleanup);
106
112
  }
107
- _start(schemaId, inputContext, indexes, input, cleanup) {
113
+ _start(schemaId, inputContext, indexes, input, spy, cleanup) {
108
114
  var _a, _b;
109
115
  return __awaiter(this, void 0, void 0, function* () {
110
116
  const resume = !!(indexes === null || indexes === void 0 ? void 0 : indexes.length);
@@ -130,11 +136,11 @@ class WooksWf extends wooks.WooksAdapterBase {
130
136
  }
131
137
  restoreCtx();
132
138
  if (resume) {
133
- result = yield this.wf.resume(id, { context: inputContext, indexes }, input);
139
+ result = yield this.wf.resume(id, { context: inputContext, indexes }, input, spy);
134
140
  break;
135
141
  }
136
142
  else {
137
- result = yield this.wf.start(id, inputContext, input);
143
+ result = yield this.wf.start(id, inputContext, input, spy);
138
144
  break;
139
145
  }
140
146
  }
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ import { TStepHandler } from '@prostojs/wf';
9
9
  import { TWooksHandler } from 'wooks';
10
10
  import { TWooksOptions } from 'wooks';
11
11
  import { TWorkflowSchema } from '@prostojs/wf';
12
+ import { TWorkflowSpy } from '@prostojs/wf';
12
13
  import { Wooks } from 'wooks';
13
14
  import { WooksAdapterBase } from 'wooks';
14
15
  import { Workflow } from '@prostojs/wf';
@@ -135,14 +136,19 @@ export declare class WooksWf<T> extends WooksAdapterBase {
135
136
  protected logger: TConsoleBase;
136
137
  protected wf: WooksWorkflow<T>;
137
138
  constructor(opts?: TWooksWfOptions | undefined, wooks?: Wooks | WooksAdapterBase);
139
+ attachSpy<I>(fn: TWorkflowSpy<T, I>): () => void;
140
+ detachSpy<I>(fn: TWorkflowSpy<T, I>): void;
138
141
  step<I = any, D = any>(id: string, opts: {
139
142
  input?: D;
140
143
  handler: string | TStepHandler<T, I, D>;
141
144
  }): TProstoRouterPathHandle<Record<string, string | string[]>>;
142
145
  flow(id: string, schema: TWorkflowSchema<T>, init?: () => void | Promise<void>): TProstoRouterPathHandle<Record<string, string | string[]>>;
143
- start<I>(schemaId: string, inputContext: T, input?: I, cleanup?: () => void): Promise<TFlowOutput<T, I>>;
144
- resume<I>(schemaId: string, inputContext: T, indexes: number[], input?: I, cleanup?: () => void): Promise<TFlowOutput<T, I>>;
145
- protected _start<I>(schemaId: string, inputContext: T, indexes?: number[], input?: I, cleanup?: () => void): Promise<TFlowOutput<T, I>>;
146
+ start<I>(schemaId: string, inputContext: T, input?: I, spy?: TWorkflowSpy<T, I>, cleanup?: () => void): Promise<TFlowOutput<T, I>>;
147
+ resume<I>(schemaId: string, state: {
148
+ indexes: number[];
149
+ context: T;
150
+ }, input?: I, spy?: TWorkflowSpy<T, I>, cleanup?: () => void): Promise<TFlowOutput<T, I>>;
151
+ protected _start<I>(schemaId: string, inputContext: T, indexes?: number[], input?: I, spy?: TWorkflowSpy<T, I>, cleanup?: () => void): Promise<TFlowOutput<T, I>>;
146
152
  protected onError(e: Error): void;
147
153
  protected error(e: string | Error): void;
148
154
  }
package/dist/index.mjs CHANGED
@@ -88,6 +88,12 @@ class WooksWf extends WooksAdapterBase {
88
88
  this.logger = (opts === null || opts === void 0 ? void 0 : opts.logger) || this.getLogger('wooks-wf');
89
89
  this.wf = new WooksWorkflow(this.wooks);
90
90
  }
91
+ attachSpy(fn) {
92
+ return this.wf.attachSpy(fn);
93
+ }
94
+ detachSpy(fn) {
95
+ return this.wf.detachSpy(fn);
96
+ }
91
97
  step(id, opts) {
92
98
  const step = createStep(id, opts);
93
99
  return this.on('WF_STEP', id, () => step);
@@ -96,13 +102,13 @@ class WooksWf extends WooksAdapterBase {
96
102
  this.wf.register(id, schema);
97
103
  return this.on('WF_FLOW', id, () => ({ init, id }));
98
104
  }
99
- start(schemaId, inputContext, input, cleanup) {
100
- return this._start(schemaId, inputContext, undefined, input, cleanup);
105
+ start(schemaId, inputContext, input, spy, cleanup) {
106
+ return this._start(schemaId, inputContext, undefined, input, spy, cleanup);
101
107
  }
102
- resume(schemaId, inputContext, indexes, input, cleanup) {
103
- return this._start(schemaId, inputContext, indexes, input, cleanup);
108
+ resume(schemaId, state, input, spy, cleanup) {
109
+ return this._start(schemaId, state.context, state.indexes, input, spy, cleanup);
104
110
  }
105
- _start(schemaId, inputContext, indexes, input, cleanup) {
111
+ _start(schemaId, inputContext, indexes, input, spy, cleanup) {
106
112
  var _a, _b;
107
113
  return __awaiter(this, void 0, void 0, function* () {
108
114
  const resume = !!(indexes === null || indexes === void 0 ? void 0 : indexes.length);
@@ -128,11 +134,11 @@ class WooksWf extends WooksAdapterBase {
128
134
  }
129
135
  restoreCtx();
130
136
  if (resume) {
131
- result = yield this.wf.resume(id, { context: inputContext, indexes }, input);
137
+ result = yield this.wf.resume(id, { context: inputContext, indexes }, input, spy);
132
138
  break;
133
139
  }
134
140
  else {
135
- result = yield this.wf.start(id, inputContext, input);
141
+ result = yield this.wf.start(id, inputContext, input, spy);
136
142
  break;
137
143
  }
138
144
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-wf",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "@wooksjs/event-wf",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -25,12 +25,12 @@
25
25
  "author": "Artem Maltsev",
26
26
  "license": "MIT",
27
27
  "peerDependencies": {
28
- "wooks": "0.4.0",
29
- "@wooksjs/event-core": "0.4.0"
28
+ "wooks": "0.4.2",
29
+ "@wooksjs/event-core": "0.4.2"
30
30
  },
31
31
  "dependencies": {
32
32
  "@prostojs/logger": "^0.3.6",
33
- "@prostojs/wf": "^0.0.3"
33
+ "@prostojs/wf": "^0.0.6"
34
34
  },
35
35
  "bugs": {
36
36
  "url": "https://github.com/wooksjs/wooksjs/issues"