@yieldstar/core 0.2.2 → 0.4.0-alpha.1
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/base/event.d.ts +6 -0
- package/dist/base/event.d.ts.map +1 -1
- package/dist/base/map.d.ts +21 -0
- package/dist/base/map.d.ts.map +1 -0
- package/dist/base/map.test.d.ts +2 -0
- package/dist/base/map.test.d.ts.map +1 -0
- package/dist/base/middleware.d.ts +9 -0
- package/dist/base/middleware.d.ts.map +1 -0
- package/dist/base/runtime.d.ts +2 -2
- package/dist/base/runtime.d.ts.map +1 -1
- package/dist/base/workflow.d.ts +8 -8
- package/dist/base/workflow.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +62 -1
- package/dist/lib/workflow-runner.d.ts +1 -1
- package/dist/lib/workflow-runner.d.ts.map +1 -1
- package/dist/utils/map.d.ts +21 -0
- package/dist/utils/map.d.ts.map +1 -0
- package/dist/utils/map.test.d.ts +2 -0
- package/dist/utils/map.test.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/base/event.ts +10 -0
- package/src/base/middleware.ts +16 -0
- package/src/base/runtime.ts +7 -3
- package/src/base/workflow.ts +17 -9
- package/src/index.ts +9 -4
- package/src/lib/workflow-runner.ts +9 -5
- package/src/utils/map.test.ts +43 -0
- package/src/utils/map.ts +75 -0
- package/tsconfig.tsbuildinfo +1 -1
package/dist/base/event.d.ts
CHANGED
|
@@ -12,4 +12,10 @@ export type ExecutionEvent<EventParams = any> = {
|
|
|
12
12
|
executionId: string;
|
|
13
13
|
params: EventParams;
|
|
14
14
|
};
|
|
15
|
+
export type WorkflowEvent<EventParams = any, Context extends ReadonlyMap<any, any> = ReadonlyMap<any, any>> = {
|
|
16
|
+
workflowId: string;
|
|
17
|
+
executionId: string;
|
|
18
|
+
params: EventParams;
|
|
19
|
+
context: Context;
|
|
20
|
+
};
|
|
15
21
|
//# sourceMappingURL=event.d.ts.map
|
package/dist/base/event.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/base/event.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,CACtB,UAAU,SAAS,MAAM,EACzB,WAAW,GAAG,GAAG,IACf,WAAW,SAAS,IAAI,GACxB;IACE,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB,GACD;IACE,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC;AAEN,MAAM,MAAM,cAAc,CAAC,WAAW,GAAG,GAAG,IAAI;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC"}
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/base/event.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,CACtB,UAAU,SAAS,MAAM,EACzB,WAAW,GAAG,GAAG,IACf,WAAW,SAAS,IAAI,GACxB;IACE,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB,GACD;IACE,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC;AAEN,MAAM,MAAM,cAAc,CAAC,WAAW,GAAG,GAAG,IAAI;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,aAAa,CACvB,WAAW,GAAG,GAAG,EACjB,OAAO,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,IAC3D;IACF,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class ReadOnlyMap<K, V> implements ReadonlyMap<K, V> {
|
|
2
|
+
private sourceMap;
|
|
3
|
+
constructor(sourceMap: Map<K, V>);
|
|
4
|
+
get(key: K): V | undefined;
|
|
5
|
+
has(key: K): boolean;
|
|
6
|
+
get size(): number;
|
|
7
|
+
entries(): ReturnType<Map<K, V>["entries"]>;
|
|
8
|
+
keys(): ReturnType<Map<K, V>["keys"]>;
|
|
9
|
+
values(): ReturnType<Map<K, V>["values"]>;
|
|
10
|
+
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
|
|
11
|
+
[Symbol.iterator](): ReturnType<Map<K, V>[typeof Symbol.iterator]>;
|
|
12
|
+
}
|
|
13
|
+
export declare class FreezableMap<K, V> extends Map<K, V> {
|
|
14
|
+
private frozen;
|
|
15
|
+
freeze(): void;
|
|
16
|
+
isFrozen(): boolean;
|
|
17
|
+
set(key: K, value: V): this;
|
|
18
|
+
delete(key: K): boolean;
|
|
19
|
+
clear(): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/base/map.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAW,CAAC,CAAC,EAAE,CAAC,CAAE,YAAW,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC;IACzD,OAAO,CAAC,SAAS,CAAY;gBAEjB,SAAS,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAIhC,GAAG,CAAC,GAAG,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utionEvent } from "./event";
|
|
3
|
+
import { FreezableMap } from "../utils/map";
|
|
4
|
+
export type MiddlewareEvent = ExecutionEvent & {
|
|
5
|
+
context: FreezableMap<string, any>;
|
|
6
|
+
};
|
|
7
|
+
export type MiddlewareNext = () => Promise<Response>;
|
|
8
|
+
export type MiddlewareFunction = (req: Request, event: MiddlewareEvent, next: MiddlewareNext, logger: Logger) => Promise<Response>;
|
|
9
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/base/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG;IAC7C,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC;AAErD,MAAM,MAAM,kBAAkB,GAAG,CAC/B,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,eAAe,EACtB,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,MAAM,KACX,OAAO,CAAC,QAAQ,CAAC,CAAC"}
|
package/dist/base/runtime.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Logger } from "pino";
|
|
2
2
|
import type { WorkflowResult } from "./step";
|
|
3
|
-
import type {
|
|
4
|
-
export type EventProcessor<EventParams = any, Result = any> = (event:
|
|
3
|
+
import type { WorkflowEvent } from "./event";
|
|
4
|
+
export type EventProcessor<EventParams = any, Result = any, Context extends ReadonlyMap<any, any> = ReadonlyMap<any, any>> = (event: WorkflowEvent<EventParams, Context>, logger: Logger) => Promise<void | WorkflowResult<Result>>;
|
|
5
5
|
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/base/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/base/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,MAAM,cAAc,CACxB,WAAW,GAAG,GAAG,EACjB,MAAM,GAAG,GAAG,EACZ,OAAO,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,IAC3D,CACF,KAAK,EAAE,aAAa,CAAC,WAAW,EAAE,OAAO,CAAC,EAC1C,MAAM,EAAE,MAAM,KACX,OAAO,CAAC,IAAI,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC"}
|
package/dist/base/workflow.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { Logger } from "pino";
|
|
2
2
|
import { HeapClient } from "./heap";
|
|
3
3
|
import { StepResponse, WorkflowResult } from "./step";
|
|
4
|
-
import type {
|
|
5
|
-
export type WorkflowGeneratorParams<EventParams
|
|
6
|
-
event:
|
|
4
|
+
import type { WorkflowEvent } from "./event";
|
|
5
|
+
export type WorkflowGeneratorParams<EventParams, Context extends ReadonlyMap<any, any>> = {
|
|
6
|
+
event: WorkflowEvent<EventParams, Context>;
|
|
7
7
|
heapClient: HeapClient;
|
|
8
8
|
logger: Logger;
|
|
9
9
|
};
|
|
10
|
-
export type WorkflowGenerator<EventParams, Result
|
|
11
|
-
export type WorkflowGeneratorReturnType<CG> = CG extends WorkflowGenerator<infer EventParams, infer Result> ? Result : never;
|
|
12
|
-
export type WorkflowRouter = Record<string, WorkflowGenerator<any, any>>;
|
|
13
|
-
export type EventOfWorkflow<W extends WorkflowGenerator<any, any>> = Parameters<W>[0]["event"];
|
|
14
|
-
export type EventParamsOf<W extends WorkflowGenerator<any, any>> = Parameters<W>[0]["event"]["params"];
|
|
10
|
+
export type WorkflowGenerator<EventParams, Result, Context extends Map<any, any>> = (genParams: WorkflowGeneratorParams<EventParams, Context>) => AsyncGenerator<StepResponse, WorkflowResult<Result>, StepResponse>;
|
|
11
|
+
export type WorkflowGeneratorReturnType<CG> = CG extends WorkflowGenerator<infer EventParams, infer Result, infer Context> ? Result : never;
|
|
12
|
+
export type WorkflowRouter = Record<string, WorkflowGenerator<any, any, any>>;
|
|
13
|
+
export type EventOfWorkflow<W extends WorkflowGenerator<any, any, any>> = Parameters<W>[0]["event"];
|
|
14
|
+
export type EventParamsOf<W extends WorkflowGenerator<any, any, any>> = Parameters<W>[0]["event"]["params"];
|
|
15
15
|
//# sourceMappingURL=workflow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/base/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/base/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,UA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,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,10 @@ export type { HeapClient, HeapRecord } from "./base/heap";
|
|
|
2
2
|
export type { WorkflowInvoker } from "./base/invoker";
|
|
3
3
|
export type { EventProcessor } from "./base/runtime";
|
|
4
4
|
export type { SchedulerClient } from "./base/scheduler";
|
|
5
|
+
export type { ExecutionEvent, TriggerEvent, WorkflowEvent } from "./base/event";
|
|
6
|
+
export type { MiddlewareNext, MiddlewareEvent, MiddlewareFunction, } from "./base/middleware";
|
|
5
7
|
export type { WorkflowGenerator, WorkflowGeneratorReturnType, WorkflowRouter, EventOfWorkflow, EventParamsOf, } from "./base/workflow";
|
|
6
|
-
export type { TriggerEvent as TriggerEvent, ExecutionEvent as ExecutionEvent, } from "./base/event";
|
|
7
8
|
export { StepCacheCheck, StepDelay, StepError, StepInvalid, StepKey, StepResponse, StepResult, WorkflowDelay, WorkflowRestart, WorkflowResult, } from "./base/step";
|
|
8
9
|
export { WorkflowRunner } from "./lib/workflow-runner";
|
|
10
|
+
export { ReadOnlyMap, FreezableMap } from "./utils/map";
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC1D,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC1D,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEhF,YAAY,EACV,cAAc,EACd,eAAe,EACf,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,cAAc,EACd,eAAe,EACf,aAAa,GACd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,cAAc,EACd,SAAS,EACT,SAAS,EACT,WAAW,EACX,OAAO,EACP,YAAY,EACZ,UAAU,EACV,aAAa,EACb,eAAe,EACf,cAAc,GACf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -136,6 +136,65 @@ class WorkflowRunner {
|
|
|
136
136
|
throw new Error("Workflow runner critical error. This is likely because your worklow and worker are referencing different versions of @yieldstar/core.");
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
+
// src/utils/map.ts
|
|
140
|
+
class ReadOnlyMap {
|
|
141
|
+
sourceMap;
|
|
142
|
+
constructor(sourceMap) {
|
|
143
|
+
this.sourceMap = sourceMap;
|
|
144
|
+
}
|
|
145
|
+
get(key) {
|
|
146
|
+
return this.sourceMap.get(key);
|
|
147
|
+
}
|
|
148
|
+
has(key) {
|
|
149
|
+
return this.sourceMap.has(key);
|
|
150
|
+
}
|
|
151
|
+
get size() {
|
|
152
|
+
return this.sourceMap.size;
|
|
153
|
+
}
|
|
154
|
+
entries() {
|
|
155
|
+
return this.sourceMap.entries();
|
|
156
|
+
}
|
|
157
|
+
keys() {
|
|
158
|
+
return this.sourceMap.keys();
|
|
159
|
+
}
|
|
160
|
+
values() {
|
|
161
|
+
return this.sourceMap.values();
|
|
162
|
+
}
|
|
163
|
+
forEach(callbackfn, thisArg) {
|
|
164
|
+
return this.sourceMap.forEach(callbackfn, thisArg);
|
|
165
|
+
}
|
|
166
|
+
[Symbol.iterator]() {
|
|
167
|
+
return this.sourceMap[Symbol.iterator]();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
class FreezableMap extends Map {
|
|
172
|
+
frozen = false;
|
|
173
|
+
freeze() {
|
|
174
|
+
this.frozen = true;
|
|
175
|
+
}
|
|
176
|
+
isFrozen() {
|
|
177
|
+
return this.frozen;
|
|
178
|
+
}
|
|
179
|
+
set(key, value) {
|
|
180
|
+
if (this.frozen) {
|
|
181
|
+
throw new Error("Cannot call set on a frozen map");
|
|
182
|
+
}
|
|
183
|
+
return super.set(key, value);
|
|
184
|
+
}
|
|
185
|
+
delete(key) {
|
|
186
|
+
if (this.frozen) {
|
|
187
|
+
throw new Error("Cannot call delete on a frozen map");
|
|
188
|
+
}
|
|
189
|
+
return super.delete(key);
|
|
190
|
+
}
|
|
191
|
+
clear() {
|
|
192
|
+
if (this.frozen) {
|
|
193
|
+
throw new Error("Cannot call clear on a frozen map");
|
|
194
|
+
}
|
|
195
|
+
return super.clear();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
139
198
|
export {
|
|
140
199
|
WorkflowRunner,
|
|
141
200
|
WorkflowResult,
|
|
@@ -147,5 +206,7 @@ export {
|
|
|
147
206
|
StepInvalid,
|
|
148
207
|
StepError,
|
|
149
208
|
StepDelay,
|
|
150
|
-
StepCacheCheck
|
|
209
|
+
StepCacheCheck,
|
|
210
|
+
ReadOnlyMap,
|
|
211
|
+
FreezableMap
|
|
151
212
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Logger } from "pino";
|
|
2
2
|
import type { WorkflowGenerator, HeapClient, SchedulerClient, EventProcessor } from "..";
|
|
3
|
-
export declare class WorkflowRunner<Router extends Record<string, WorkflowGenerator<any, any>>> {
|
|
3
|
+
export declare class WorkflowRunner<Router extends Record<string, WorkflowGenerator<any, any, any>>> {
|
|
4
4
|
private heapClient;
|
|
5
5
|
private schedulerClient;
|
|
6
6
|
private router;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-runner.d.ts","sourceRoot":"","sources":["../../src/lib/workflow-runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EACV,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,cAAc,EAEf,MAAM,IAAI,CAAC;AAGZ,qBAAa,cAAc,CACzB,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"workflow-runner.d.ts","sourceRoot":"","sources":["../../src/lib/workflow-runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EACV,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,cAAc,EAEf,MAAM,IAAI,CAAC;AAGZ,qBAAa,cAAc,CACzB,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAE/D,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE;QAClB,UAAU,EAAE,UAAU,CAAC;QACvB,eAAe,EAAE,eAAe,CAAC;QACjC,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;KAChB;IAMD,GAAG,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CA0B3B;YAEY,YAAY;CAgC3B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class ReadOnlyMap<K, V> implements ReadonlyMap<K, V> {
|
|
2
|
+
private sourceMap;
|
|
3
|
+
constructor(sourceMap: Map<K, V>);
|
|
4
|
+
get(key: K): V | undefined;
|
|
5
|
+
has(key: K): boolean;
|
|
6
|
+
get size(): number;
|
|
7
|
+
entries(): ReturnType<Map<K, V>["entries"]>;
|
|
8
|
+
keys(): ReturnType<Map<K, V>["keys"]>;
|
|
9
|
+
values(): ReturnType<Map<K, V>["values"]>;
|
|
10
|
+
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
|
|
11
|
+
[Symbol.iterator](): ReturnType<Map<K, V>[typeof Symbol.iterator]>;
|
|
12
|
+
}
|
|
13
|
+
export declare class FreezableMap<K, V> extends Map<K, V> {
|
|
14
|
+
private frozen;
|
|
15
|
+
freeze(): void;
|
|
16
|
+
isFrozen(): boolean;
|
|
17
|
+
set(key: K, value: V): this;
|
|
18
|
+
delete(key: K): boolean;
|
|
19
|
+
clear(): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/utils/map.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAW,CAAC,CAAC,EAAE,CAAC,CAAE,YAAW,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC;IACzD,OAAO,CAAC,SAAS,CAAY;gBAEjB,SAAS,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAIhC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAI1B,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAIpB,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAI3C,IAAI,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAIrC,MAAM,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAIzC,OAAO,CACL,UAAU,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,EACtD,OAAO,CAAC,EAAE,GAAG,GACZ,IAAI;IAIP,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC;CAGnE;AAED,qBAAa,YAAY,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,MAAM,CAAS;IAEvB,MAAM,IAAI,IAAI;IAId,QAAQ,IAAI,OAAO;IAInB,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAO3B,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAOvB,KAAK,IAAI,IAAI;CAMd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.test.d.ts","sourceRoot":"","sources":["../../src/utils/map.test.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
package/src/base/event.ts
CHANGED
|
@@ -18,3 +18,13 @@ export type ExecutionEvent<EventParams = any> = {
|
|
|
18
18
|
executionId: string;
|
|
19
19
|
params: EventParams;
|
|
20
20
|
};
|
|
21
|
+
|
|
22
|
+
export type WorkflowEvent<
|
|
23
|
+
EventParams = any,
|
|
24
|
+
Context extends ReadonlyMap<any, any> = ReadonlyMap<any, any>
|
|
25
|
+
> = {
|
|
26
|
+
workflowId: string;
|
|
27
|
+
executionId: string;
|
|
28
|
+
params: EventParams;
|
|
29
|
+
context: Context;
|
|
30
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Logger } from "pino";
|
|
2
|
+
import { ExecutionEvent } from "./event";
|
|
3
|
+
import { FreezableMap } from "../utils/map";
|
|
4
|
+
|
|
5
|
+
export type MiddlewareEvent = ExecutionEvent & {
|
|
6
|
+
context: FreezableMap<string, any>;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type MiddlewareNext = () => Promise<Response>;
|
|
10
|
+
|
|
11
|
+
export type MiddlewareFunction = (
|
|
12
|
+
req: Request,
|
|
13
|
+
event: MiddlewareEvent,
|
|
14
|
+
next: MiddlewareNext,
|
|
15
|
+
logger: Logger
|
|
16
|
+
) => Promise<Response>;
|
package/src/base/runtime.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { Logger } from "pino";
|
|
2
2
|
import type { WorkflowResult } from "./step";
|
|
3
|
-
import type {
|
|
3
|
+
import type { WorkflowEvent } from "./event";
|
|
4
4
|
|
|
5
|
-
export type EventProcessor<
|
|
6
|
-
|
|
5
|
+
export type EventProcessor<
|
|
6
|
+
EventParams = any,
|
|
7
|
+
Result = any,
|
|
8
|
+
Context extends ReadonlyMap<any, any> = ReadonlyMap<any, any>
|
|
9
|
+
> = (
|
|
10
|
+
event: WorkflowEvent<EventParams, Context>,
|
|
7
11
|
logger: Logger
|
|
8
12
|
) => Promise<void | WorkflowResult<Result>>;
|
package/src/base/workflow.ts
CHANGED
|
@@ -1,29 +1,37 @@
|
|
|
1
1
|
import type { Logger } from "pino";
|
|
2
2
|
import { HeapClient } from "./heap";
|
|
3
3
|
import { StepResponse, WorkflowResult } from "./step";
|
|
4
|
-
import type {
|
|
4
|
+
import type { WorkflowEvent } from "./event";
|
|
5
5
|
|
|
6
|
-
export type WorkflowGeneratorParams<
|
|
7
|
-
|
|
6
|
+
export type WorkflowGeneratorParams<
|
|
7
|
+
EventParams,
|
|
8
|
+
Context extends ReadonlyMap<any, any>
|
|
9
|
+
> = {
|
|
10
|
+
event: WorkflowEvent<EventParams, Context>;
|
|
8
11
|
heapClient: HeapClient;
|
|
9
12
|
logger: Logger;
|
|
10
13
|
};
|
|
11
14
|
|
|
12
|
-
export type WorkflowGenerator<
|
|
13
|
-
|
|
15
|
+
export type WorkflowGenerator<
|
|
16
|
+
EventParams,
|
|
17
|
+
Result,
|
|
18
|
+
Context extends Map<any, any>
|
|
19
|
+
> = (
|
|
20
|
+
genParams: WorkflowGeneratorParams<EventParams, Context>
|
|
14
21
|
) => AsyncGenerator<StepResponse, WorkflowResult<Result>, StepResponse>;
|
|
15
22
|
|
|
16
23
|
export type WorkflowGeneratorReturnType<CG> = CG extends WorkflowGenerator<
|
|
17
24
|
infer EventParams,
|
|
18
|
-
infer Result
|
|
25
|
+
infer Result,
|
|
26
|
+
infer Context
|
|
19
27
|
>
|
|
20
28
|
? Result
|
|
21
29
|
: never;
|
|
22
30
|
|
|
23
|
-
export type WorkflowRouter = Record<string, WorkflowGenerator<any, any>>;
|
|
31
|
+
export type WorkflowRouter = Record<string, WorkflowGenerator<any, any, any>>;
|
|
24
32
|
|
|
25
|
-
export type EventOfWorkflow<W extends WorkflowGenerator<any, any>> =
|
|
33
|
+
export type EventOfWorkflow<W extends WorkflowGenerator<any, any, any>> =
|
|
26
34
|
Parameters<W>[0]["event"];
|
|
27
35
|
|
|
28
|
-
export type EventParamsOf<W extends WorkflowGenerator<any, any>> =
|
|
36
|
+
export type EventParamsOf<W extends WorkflowGenerator<any, any, any>> =
|
|
29
37
|
Parameters<W>[0]["event"]["params"];
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,14 @@ export type { HeapClient, HeapRecord } from "./base/heap";
|
|
|
2
2
|
export type { WorkflowInvoker } from "./base/invoker";
|
|
3
3
|
export type { EventProcessor } from "./base/runtime";
|
|
4
4
|
export type { SchedulerClient } from "./base/scheduler";
|
|
5
|
+
export type { ExecutionEvent, TriggerEvent, WorkflowEvent } from "./base/event";
|
|
6
|
+
|
|
7
|
+
export type {
|
|
8
|
+
MiddlewareNext,
|
|
9
|
+
MiddlewareEvent,
|
|
10
|
+
MiddlewareFunction,
|
|
11
|
+
} from "./base/middleware";
|
|
12
|
+
|
|
5
13
|
export type {
|
|
6
14
|
WorkflowGenerator,
|
|
7
15
|
WorkflowGeneratorReturnType,
|
|
@@ -9,10 +17,6 @@ export type {
|
|
|
9
17
|
EventOfWorkflow,
|
|
10
18
|
EventParamsOf,
|
|
11
19
|
} from "./base/workflow";
|
|
12
|
-
export type {
|
|
13
|
-
TriggerEvent as TriggerEvent,
|
|
14
|
-
ExecutionEvent as ExecutionEvent,
|
|
15
|
-
} from "./base/event";
|
|
16
20
|
|
|
17
21
|
export {
|
|
18
22
|
StepCacheCheck,
|
|
@@ -28,3 +32,4 @@ export {
|
|
|
28
32
|
} from "./base/step";
|
|
29
33
|
|
|
30
34
|
export { WorkflowRunner } from "./lib/workflow-runner";
|
|
35
|
+
export { ReadOnlyMap, FreezableMap } from "./utils/map";
|
|
@@ -4,12 +4,12 @@ import type {
|
|
|
4
4
|
HeapClient,
|
|
5
5
|
SchedulerClient,
|
|
6
6
|
EventProcessor,
|
|
7
|
-
|
|
7
|
+
WorkflowEvent,
|
|
8
8
|
} from "..";
|
|
9
9
|
import { StepDelay, WorkflowDelay, WorkflowResult } from "..";
|
|
10
10
|
|
|
11
11
|
export class WorkflowRunner<
|
|
12
|
-
Router extends Record<string, WorkflowGenerator<any, any>>
|
|
12
|
+
Router extends Record<string, WorkflowGenerator<any, any, any>>
|
|
13
13
|
> {
|
|
14
14
|
private heapClient: HeapClient;
|
|
15
15
|
private schedulerClient: SchedulerClient;
|
|
@@ -54,9 +54,13 @@ export class WorkflowRunner<
|
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
private async runWorkflows<
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
private async runWorkflows<
|
|
58
|
+
EventParams,
|
|
59
|
+
Result,
|
|
60
|
+
Context extends Map<any, any>
|
|
61
|
+
>(params: {
|
|
62
|
+
workflow: WorkflowGenerator<EventParams, Result, Context>;
|
|
63
|
+
event: WorkflowEvent<EventParams, Context>;
|
|
60
64
|
logger: Logger;
|
|
61
65
|
}): Promise<WorkflowResult<Result> | WorkflowDelay> {
|
|
62
66
|
const { workflow, event, logger } = params;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { ReadOnlyMap, FreezableMap } from "./map";
|
|
3
|
+
|
|
4
|
+
test("ReadOnlyMap", () => {
|
|
5
|
+
const originalMap = new Map<string, any>();
|
|
6
|
+
originalMap.set("key", "value");
|
|
7
|
+
|
|
8
|
+
const readOnlyMap = new ReadOnlyMap(originalMap);
|
|
9
|
+
|
|
10
|
+
// Reading should work
|
|
11
|
+
expect(readOnlyMap.get("key")).toBe("value");
|
|
12
|
+
expect(readOnlyMap.has("key")).toBe(true);
|
|
13
|
+
expect(readOnlyMap.size).toBe(1);
|
|
14
|
+
|
|
15
|
+
expect("set" in readOnlyMap).toBe(false);
|
|
16
|
+
expect("delete" in readOnlyMap).toBe(false);
|
|
17
|
+
expect("clear" in readOnlyMap).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("FreezableMap", () => {
|
|
21
|
+
const freezableMap = new FreezableMap<string, any>();
|
|
22
|
+
freezableMap.set("key", "value");
|
|
23
|
+
|
|
24
|
+
// Before freezing, modifications should work
|
|
25
|
+
expect(freezableMap.get("key")).toBe("value");
|
|
26
|
+
freezableMap.set("key2", "value2");
|
|
27
|
+
expect(freezableMap.get("key2")).toBe("value2");
|
|
28
|
+
|
|
29
|
+
// Freeze the map
|
|
30
|
+
freezableMap.freeze();
|
|
31
|
+
expect(freezableMap.isFrozen()).toBe(true);
|
|
32
|
+
|
|
33
|
+
// After freezing, modifications should throw
|
|
34
|
+
expect(() => freezableMap.set("key3", "value3")).toThrow(
|
|
35
|
+
"Cannot call set on a frozen map"
|
|
36
|
+
);
|
|
37
|
+
expect(() => freezableMap.delete("key")).toThrow(
|
|
38
|
+
"Cannot call delete on a frozen map"
|
|
39
|
+
);
|
|
40
|
+
expect(() => freezableMap.clear()).toThrow(
|
|
41
|
+
"Cannot call clear on a frozen map"
|
|
42
|
+
);
|
|
43
|
+
});
|
package/src/utils/map.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export class ReadOnlyMap<K, V> implements ReadonlyMap<K, V> {
|
|
2
|
+
private sourceMap: Map<K, V>;
|
|
3
|
+
|
|
4
|
+
constructor(sourceMap: Map<K, V>) {
|
|
5
|
+
this.sourceMap = sourceMap;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
get(key: K): V | undefined {
|
|
9
|
+
return this.sourceMap.get(key);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
has(key: K): boolean {
|
|
13
|
+
return this.sourceMap.has(key);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get size(): number {
|
|
17
|
+
return this.sourceMap.size;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
entries(): ReturnType<Map<K, V>["entries"]> {
|
|
21
|
+
return this.sourceMap.entries();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
keys(): ReturnType<Map<K, V>["keys"]> {
|
|
25
|
+
return this.sourceMap.keys();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
values(): ReturnType<Map<K, V>["values"]> {
|
|
29
|
+
return this.sourceMap.values();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
forEach(
|
|
33
|
+
callbackfn: (value: V, key: K, map: Map<K, V>) => void,
|
|
34
|
+
thisArg?: any
|
|
35
|
+
): void {
|
|
36
|
+
return this.sourceMap.forEach(callbackfn, thisArg);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
[Symbol.iterator](): ReturnType<Map<K, V>[typeof Symbol.iterator]> {
|
|
40
|
+
return this.sourceMap[Symbol.iterator]();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class FreezableMap<K, V> extends Map<K, V> {
|
|
45
|
+
private frozen = false;
|
|
46
|
+
|
|
47
|
+
freeze(): void {
|
|
48
|
+
this.frozen = true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
isFrozen(): boolean {
|
|
52
|
+
return this.frozen;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
set(key: K, value: V): this {
|
|
56
|
+
if (this.frozen) {
|
|
57
|
+
throw new Error("Cannot call set on a frozen map");
|
|
58
|
+
}
|
|
59
|
+
return super.set(key, value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
delete(key: K): boolean {
|
|
63
|
+
if (this.frozen) {
|
|
64
|
+
throw new Error("Cannot call delete on a frozen map");
|
|
65
|
+
}
|
|
66
|
+
return super.delete(key);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
clear(): void {
|
|
70
|
+
if (this.frozen) {
|
|
71
|
+
throw new Error("Cannot call clear on a frozen map");
|
|
72
|
+
}
|
|
73
|
+
return super.clear();
|
|
74
|
+
}
|
|
75
|
+
}
|