@voyantjs/workflows 0.0.0 → 0.6.8

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.
Files changed (61) hide show
  1. package/dist/auth/index.d.ts +26 -0
  2. package/dist/auth/index.d.ts.map +1 -0
  3. package/dist/auth/index.js +137 -0
  4. package/dist/conditions.d.ts +29 -0
  5. package/dist/conditions.d.ts.map +1 -0
  6. package/dist/conditions.js +5 -0
  7. package/dist/handler/index.d.ts +104 -0
  8. package/dist/handler/index.d.ts.map +1 -0
  9. package/dist/handler/index.js +238 -0
  10. package/dist/index.d.ts +6 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +10 -0
  13. package/dist/protocol/index.d.ts +187 -0
  14. package/dist/protocol/index.d.ts.map +1 -0
  15. package/dist/protocol/index.js +7 -0
  16. package/dist/rate-limit/index.d.ts +40 -0
  17. package/dist/rate-limit/index.d.ts.map +1 -0
  18. package/dist/rate-limit/index.js +139 -0
  19. package/dist/runtime/ctx.d.ts +102 -0
  20. package/dist/runtime/ctx.d.ts.map +1 -0
  21. package/dist/runtime/ctx.js +607 -0
  22. package/dist/runtime/determinism.d.ts +19 -0
  23. package/dist/runtime/determinism.d.ts.map +1 -0
  24. package/dist/runtime/determinism.js +61 -0
  25. package/dist/runtime/errors.d.ts +21 -0
  26. package/dist/runtime/errors.d.ts.map +1 -0
  27. package/dist/runtime/errors.js +45 -0
  28. package/dist/runtime/executor.d.ts +159 -0
  29. package/dist/runtime/executor.d.ts.map +1 -0
  30. package/dist/runtime/executor.js +225 -0
  31. package/dist/runtime/journal.d.ts +55 -0
  32. package/dist/runtime/journal.d.ts.map +1 -0
  33. package/dist/runtime/journal.js +28 -0
  34. package/dist/testing/index.d.ts +117 -0
  35. package/dist/testing/index.d.ts.map +1 -0
  36. package/dist/testing/index.js +595 -0
  37. package/dist/trigger.d.ts +122 -0
  38. package/dist/trigger.d.ts.map +1 -0
  39. package/dist/trigger.js +23 -0
  40. package/dist/types.d.ts +63 -0
  41. package/dist/types.d.ts.map +1 -0
  42. package/dist/types.js +3 -0
  43. package/dist/workflow.d.ts +212 -0
  44. package/dist/workflow.d.ts.map +1 -0
  45. package/dist/workflow.js +46 -0
  46. package/package.json +30 -30
  47. package/src/auth/index.ts +46 -52
  48. package/src/conditions.ts +13 -13
  49. package/src/handler/index.ts +110 -106
  50. package/src/index.ts +7 -7
  51. package/src/protocol/index.ts +137 -71
  52. package/src/rate-limit/index.ts +77 -78
  53. package/src/runtime/ctx.ts +354 -342
  54. package/src/runtime/determinism.ts +27 -27
  55. package/src/runtime/errors.ts +17 -17
  56. package/src/runtime/executor.ts +179 -172
  57. package/src/runtime/journal.ts +25 -25
  58. package/src/testing/index.ts +268 -202
  59. package/src/trigger.ts +64 -71
  60. package/src/types.ts +16 -18
  61. package/src/workflow.ts +154 -152
@@ -7,22 +7,22 @@
7
7
 
8
8
  export interface ClockState {
9
9
  /** Base wall-clock time recorded at run start. */
10
- readonly baseWallClock: number;
10
+ readonly baseWallClock: number
11
11
  /** Offset from baseWallClock at which ctx.now() should return — set by the executor when replaying journaled events. */
12
- offset: number;
12
+ offset: number
13
13
  }
14
14
 
15
15
  export function createClock(runStartedAt: number): ClockState {
16
- return { baseWallClock: runStartedAt, offset: 0 };
16
+ return { baseWallClock: runStartedAt, offset: 0 }
17
17
  }
18
18
 
19
19
  export function now(clock: ClockState): number {
20
- return clock.baseWallClock + clock.offset;
20
+ return clock.baseWallClock + clock.offset
21
21
  }
22
22
 
23
23
  /** Advance the clock to the event currently being replayed. */
24
24
  export function advanceClockTo(clock: ClockState, eventAt: number): void {
25
- clock.offset = eventAt - clock.baseWallClock;
25
+ clock.offset = eventAt - clock.baseWallClock
26
26
  }
27
27
 
28
28
  /**
@@ -30,46 +30,46 @@ export function advanceClockTo(clock: ClockState, eventAt: number): void {
30
30
  * from a 32-bit hash of the run id. Not cryptographic.
31
31
  */
32
32
  export function seededRandom(seed: number): () => number {
33
- let state = seed >>> 0;
33
+ let state = seed >>> 0
34
34
  return () => {
35
- state = (state + 0x6d2b79f5) >>> 0;
36
- let t = state;
37
- t = Math.imul(t ^ (t >>> 15), t | 1);
38
- t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
39
- return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
40
- };
35
+ state = (state + 0x6d2b79f5) >>> 0
36
+ let t = state
37
+ t = Math.imul(t ^ (t >>> 15), t | 1)
38
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61)
39
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296
40
+ }
41
41
  }
42
42
 
43
43
  export function hashSeed(runId: string): number {
44
44
  // FNV-1a 32-bit
45
- let hash = 0x811c9dc5;
45
+ let hash = 0x811c9dc5
46
46
  for (let i = 0; i < runId.length; i++) {
47
- hash ^= runId.charCodeAt(i);
48
- hash = Math.imul(hash, 0x01000193);
47
+ hash ^= runId.charCodeAt(i)
48
+ hash = Math.imul(hash, 0x01000193)
49
49
  }
50
- return hash >>> 0;
50
+ return hash >>> 0
51
51
  }
52
52
 
53
53
  export function createRandom(runId: string): () => number {
54
- return seededRandom(hashSeed(runId));
54
+ return seededRandom(hashSeed(runId))
55
55
  }
56
56
 
57
- const HEX = "0123456789abcdef";
57
+ const HEX = "0123456789abcdef"
58
58
 
59
59
  export function createRandomUUID(rng: () => number): () => string {
60
60
  // v4-shaped deterministic UUID. Not cryptographically random; matches
61
61
  // the style of crypto.randomUUID but is reproducible across replays.
62
62
  return () => {
63
- const bytes = new Uint8Array(16);
64
- for (let i = 0; i < 16; i++) bytes[i] = Math.floor(rng() * 256);
65
- bytes[6] = (bytes[6]! & 0x0f) | 0x40; // version 4 (high nibble of byte 6)
66
- bytes[8] = (bytes[8]! & 0x3f) | 0x80; // variant RFC 4122 (high bits of byte 8)
67
- let s = "";
63
+ const bytes = new Uint8Array(16)
64
+ for (let i = 0; i < 16; i++) bytes[i] = Math.floor(rng() * 256)
65
+ bytes[6] = (bytes[6]! & 0x0f) | 0x40 // version 4 (high nibble of byte 6)
66
+ bytes[8] = (bytes[8]! & 0x3f) | 0x80 // variant RFC 4122 (high bits of byte 8)
67
+ let s = ""
68
68
  for (let i = 0; i < 16; i++) {
69
- const b = bytes[i]!;
70
- s += HEX[b >>> 4]! + HEX[b & 0x0f]!;
69
+ const b = bytes[i]!
70
+ s += HEX[b >>> 4]! + HEX[b & 0x0f]!
71
71
  }
72
72
  // s is 32 hex chars; slice into 8-4-4-4-12 groups.
73
- return `${s.slice(0, 8)}-${s.slice(8, 12)}-${s.slice(12, 16)}-${s.slice(16, 20)}-${s.slice(20, 32)}`;
74
- };
73
+ return `${s.slice(0, 8)}-${s.slice(8, 12)}-${s.slice(12, 16)}-${s.slice(16, 20)}-${s.slice(20, 32)}`
74
+ }
75
75
  }
@@ -3,25 +3,25 @@
3
3
  // waitpoint yield or run cancellation. They must not be caught by user
4
4
  // code (the executor re-throws if it observes one being swallowed).
5
5
 
6
- const WAITPOINT_PENDING = Symbol.for("voyant.workflows.waitpointPending");
7
- const RUN_CANCELLED = Symbol.for("voyant.workflows.runCancelled");
8
- const COMPENSATE_REQUESTED = Symbol.for("voyant.workflows.compensateRequested");
6
+ const WAITPOINT_PENDING = Symbol.for("voyant.workflows.waitpointPending")
7
+ const RUN_CANCELLED = Symbol.for("voyant.workflows.runCancelled")
8
+ const COMPENSATE_REQUESTED = Symbol.for("voyant.workflows.compensateRequested")
9
9
 
10
10
  export class WaitpointPendingSignal extends Error {
11
- readonly [WAITPOINT_PENDING] = true as const;
12
- readonly waitpointId: string;
11
+ readonly [WAITPOINT_PENDING] = true as const
12
+ readonly waitpointId: string
13
13
  constructor(waitpointId: string) {
14
- super(`waitpoint pending: ${waitpointId}`);
15
- this.name = "WaitpointPendingSignal";
16
- this.waitpointId = waitpointId;
14
+ super(`waitpoint pending: ${waitpointId}`)
15
+ this.name = "WaitpointPendingSignal"
16
+ this.waitpointId = waitpointId
17
17
  }
18
18
  }
19
19
 
20
20
  export class RunCancelledSignal extends Error {
21
- readonly [RUN_CANCELLED] = true as const;
21
+ readonly [RUN_CANCELLED] = true as const
22
22
  constructor(reason?: string) {
23
- super(reason ?? "run cancelled");
24
- this.name = "RunCancelledSignal";
23
+ super(reason ?? "run cancelled")
24
+ this.name = "RunCancelledSignal"
25
25
  }
26
26
  }
27
27
 
@@ -30,7 +30,7 @@ export function isWaitpointPending(err: unknown): err is WaitpointPendingSignal
30
30
  typeof err === "object" &&
31
31
  err !== null &&
32
32
  (err as { [WAITPOINT_PENDING]?: true })[WAITPOINT_PENDING] === true
33
- );
33
+ )
34
34
  }
35
35
 
36
36
  export function isRunCancelled(err: unknown): err is RunCancelledSignal {
@@ -38,14 +38,14 @@ export function isRunCancelled(err: unknown): err is RunCancelledSignal {
38
38
  typeof err === "object" &&
39
39
  err !== null &&
40
40
  (err as { [RUN_CANCELLED]?: true })[RUN_CANCELLED] === true
41
- );
41
+ )
42
42
  }
43
43
 
44
44
  export class CompensateRequestedSignal extends Error {
45
- readonly [COMPENSATE_REQUESTED] = true as const;
45
+ readonly [COMPENSATE_REQUESTED] = true as const
46
46
  constructor() {
47
- super("compensate requested");
48
- this.name = "CompensateRequestedSignal";
47
+ super("compensate requested")
48
+ this.name = "CompensateRequestedSignal"
49
49
  }
50
50
  }
51
51
 
@@ -54,5 +54,5 @@ export function isCompensateRequested(err: unknown): err is CompensateRequestedS
54
54
  typeof err === "object" &&
55
55
  err !== null &&
56
56
  (err as { [COMPENSATE_REQUESTED]?: true })[COMPENSATE_REQUESTED] === true
57
- );
57
+ )
58
58
  }