@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.
- package/dist/auth/index.d.ts +26 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +137 -0
- package/dist/conditions.d.ts +29 -0
- package/dist/conditions.d.ts.map +1 -0
- package/dist/conditions.js +5 -0
- package/dist/handler/index.d.ts +104 -0
- package/dist/handler/index.d.ts.map +1 -0
- package/dist/handler/index.js +238 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/protocol/index.d.ts +187 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +7 -0
- package/dist/rate-limit/index.d.ts +40 -0
- package/dist/rate-limit/index.d.ts.map +1 -0
- package/dist/rate-limit/index.js +139 -0
- package/dist/runtime/ctx.d.ts +102 -0
- package/dist/runtime/ctx.d.ts.map +1 -0
- package/dist/runtime/ctx.js +607 -0
- package/dist/runtime/determinism.d.ts +19 -0
- package/dist/runtime/determinism.d.ts.map +1 -0
- package/dist/runtime/determinism.js +61 -0
- package/dist/runtime/errors.d.ts +21 -0
- package/dist/runtime/errors.d.ts.map +1 -0
- package/dist/runtime/errors.js +45 -0
- package/dist/runtime/executor.d.ts +159 -0
- package/dist/runtime/executor.d.ts.map +1 -0
- package/dist/runtime/executor.js +225 -0
- package/dist/runtime/journal.d.ts +55 -0
- package/dist/runtime/journal.d.ts.map +1 -0
- package/dist/runtime/journal.js +28 -0
- package/dist/testing/index.d.ts +117 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +595 -0
- package/dist/trigger.d.ts +122 -0
- package/dist/trigger.d.ts.map +1 -0
- package/dist/trigger.js +23 -0
- package/dist/types.d.ts +63 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/workflow.d.ts +212 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +46 -0
- package/package.json +30 -30
- package/src/auth/index.ts +46 -52
- package/src/conditions.ts +13 -13
- package/src/handler/index.ts +110 -106
- package/src/index.ts +7 -7
- package/src/protocol/index.ts +137 -71
- package/src/rate-limit/index.ts +77 -78
- package/src/runtime/ctx.ts +354 -342
- package/src/runtime/determinism.ts +27 -27
- package/src/runtime/errors.ts +17 -17
- package/src/runtime/executor.ts +179 -172
- package/src/runtime/journal.ts +25 -25
- package/src/testing/index.ts +268 -202
- package/src/trigger.ts +64 -71
- package/src/types.ts +16 -18
- 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
|
|
66
|
-
bytes[8] = (bytes[8]! & 0x3f) | 0x80
|
|
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
|
}
|
package/src/runtime/errors.ts
CHANGED
|
@@ -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
|
}
|