@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
package/src/trigger.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
// Triggering workflows from server code, plus event filter declarations.
|
|
2
2
|
// Authoritative contract in docs/sdk-surface.md §6.
|
|
3
3
|
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
EnvironmentName,
|
|
7
|
-
RunStatus,
|
|
8
|
-
} from "./types.js";
|
|
9
|
-
import type { WorkflowHandle, EnvironmentContext } from "./workflow.js";
|
|
4
|
+
import type { Duration, EnvironmentName, RunStatus } from "./types.js"
|
|
5
|
+
import type { EnvironmentContext, WorkflowHandle } from "./workflow.js"
|
|
10
6
|
|
|
11
7
|
// ---- workflows.* ----
|
|
12
8
|
|
|
@@ -15,86 +11,86 @@ export interface WorkflowsClient {
|
|
|
15
11
|
workflow: WorkflowHandle<TIn, TOut> | string,
|
|
16
12
|
input: TIn,
|
|
17
13
|
opts?: TriggerOptions,
|
|
18
|
-
): Promise<Run<TOut
|
|
14
|
+
): Promise<Run<TOut>>
|
|
19
15
|
|
|
20
|
-
signal(runId: string, name: string, payload: unknown, opts?: { nonce?: string }): Promise<void
|
|
21
|
-
completeToken(tokenId: string, payload: unknown): Promise<void
|
|
16
|
+
signal(runId: string, name: string, payload: unknown, opts?: { nonce?: string }): Promise<void>
|
|
17
|
+
completeToken(tokenId: string, payload: unknown): Promise<void>
|
|
22
18
|
|
|
23
|
-
cancel(runId: string, opts?: { compensate?: boolean; reason?: string }): Promise<void
|
|
24
|
-
retry(runId: string, opts: { mode: "re-trigger" | "resume" }): Promise<Run
|
|
25
|
-
replay(runId: string, opts?: { fromStepId?: string; input?: unknown }): Promise<Run
|
|
19
|
+
cancel(runId: string, opts?: { compensate?: boolean; reason?: string }): Promise<void>
|
|
20
|
+
retry(runId: string, opts: { mode: "re-trigger" | "resume" }): Promise<Run>
|
|
21
|
+
replay(runId: string, opts?: { fromStepId?: string; input?: unknown }): Promise<Run>
|
|
26
22
|
|
|
27
|
-
get(runId: string): Promise<RunDetail
|
|
28
|
-
list(opts?: ListRunsOptions): Promise<{ runs: RunSummary[]; nextCursor?: string }
|
|
23
|
+
get(runId: string): Promise<RunDetail>
|
|
24
|
+
list(opts?: ListRunsOptions): Promise<{ runs: RunSummary[]; nextCursor?: string }>
|
|
29
25
|
|
|
30
|
-
mintAccessToken(opts: MintAccessTokenOptions): Promise<PublicAccessToken
|
|
26
|
+
mintAccessToken(opts: MintAccessTokenOptions): Promise<PublicAccessToken>
|
|
31
27
|
}
|
|
32
28
|
|
|
33
29
|
export interface TriggerOptions {
|
|
34
|
-
idempotencyKey?: string
|
|
35
|
-
delay?: Duration | Date
|
|
36
|
-
debounce?: { key: string; delay: Duration; mode?: "leading" | "trailing" }
|
|
37
|
-
ttl?: Duration
|
|
38
|
-
tags?: string[]
|
|
39
|
-
priority?: number
|
|
40
|
-
concurrencyKey?: string
|
|
41
|
-
lockToVersion?: string
|
|
42
|
-
environment?: EnvironmentName
|
|
43
|
-
issuePublicAccessToken?: boolean
|
|
30
|
+
idempotencyKey?: string
|
|
31
|
+
delay?: Duration | Date
|
|
32
|
+
debounce?: { key: string; delay: Duration; mode?: "leading" | "trailing" }
|
|
33
|
+
ttl?: Duration
|
|
34
|
+
tags?: string[]
|
|
35
|
+
priority?: number
|
|
36
|
+
concurrencyKey?: string
|
|
37
|
+
lockToVersion?: string
|
|
38
|
+
environment?: EnvironmentName
|
|
39
|
+
issuePublicAccessToken?: boolean
|
|
44
40
|
}
|
|
45
41
|
|
|
46
42
|
export interface Run<TOut = unknown> {
|
|
47
|
-
id: string
|
|
48
|
-
workflowId: string
|
|
49
|
-
status: RunStatus
|
|
50
|
-
startedAt: number
|
|
51
|
-
accessToken?: string
|
|
43
|
+
id: string
|
|
44
|
+
workflowId: string
|
|
45
|
+
status: RunStatus
|
|
46
|
+
startedAt: number
|
|
47
|
+
accessToken?: string
|
|
52
48
|
/** Phantom; used only for TypeScript inference. */
|
|
53
|
-
readonly __output?: TOut
|
|
49
|
+
readonly __output?: TOut
|
|
54
50
|
}
|
|
55
51
|
|
|
56
52
|
export interface RunSummary {
|
|
57
|
-
id: string
|
|
58
|
-
workflowId: string
|
|
59
|
-
status: RunStatus
|
|
60
|
-
startedAt: number
|
|
61
|
-
completedAt?: number
|
|
62
|
-
tags: string[]
|
|
63
|
-
environment: EnvironmentName
|
|
53
|
+
id: string
|
|
54
|
+
workflowId: string
|
|
55
|
+
status: RunStatus
|
|
56
|
+
startedAt: number
|
|
57
|
+
completedAt?: number
|
|
58
|
+
tags: string[]
|
|
59
|
+
environment: EnvironmentName
|
|
64
60
|
}
|
|
65
61
|
|
|
66
62
|
export interface RunDetail<TOut = unknown> extends RunSummary {
|
|
67
|
-
version: string
|
|
68
|
-
input: unknown
|
|
69
|
-
output?: TOut
|
|
70
|
-
error?: unknown
|
|
71
|
-
durationMs?: number
|
|
63
|
+
version: string
|
|
64
|
+
input: unknown
|
|
65
|
+
output?: TOut
|
|
66
|
+
error?: unknown
|
|
67
|
+
durationMs?: number
|
|
72
68
|
// ... full shape in docs/runtime-protocol.md §4.2
|
|
73
69
|
}
|
|
74
70
|
|
|
75
71
|
export interface ListRunsOptions {
|
|
76
|
-
workflowId?: string
|
|
77
|
-
status?: RunStatus | RunStatus[]
|
|
78
|
-
environment?: EnvironmentName
|
|
79
|
-
tag?: string
|
|
80
|
-
since?: Date | number
|
|
81
|
-
until?: Date | number
|
|
82
|
-
cursor?: string
|
|
83
|
-
limit?: number
|
|
72
|
+
workflowId?: string
|
|
73
|
+
status?: RunStatus | RunStatus[]
|
|
74
|
+
environment?: EnvironmentName
|
|
75
|
+
tag?: string
|
|
76
|
+
since?: Date | number
|
|
77
|
+
until?: Date | number
|
|
78
|
+
cursor?: string
|
|
79
|
+
limit?: number
|
|
84
80
|
}
|
|
85
81
|
|
|
86
82
|
export interface MintAccessTokenOptions {
|
|
87
83
|
target:
|
|
88
84
|
| { kind: "run"; runId: string }
|
|
89
85
|
| { kind: "workflow"; workflowId: string }
|
|
90
|
-
| { kind: "tag"; tag: string }
|
|
91
|
-
scope: ("read" | "trigger" | "cancel")[]
|
|
92
|
-
ttl?: Duration
|
|
86
|
+
| { kind: "tag"; tag: string }
|
|
87
|
+
scope: ("read" | "trigger" | "cancel")[]
|
|
88
|
+
ttl?: Duration
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
export interface PublicAccessToken {
|
|
96
|
-
token: string
|
|
97
|
-
exp: number
|
|
92
|
+
token: string
|
|
93
|
+
exp: number
|
|
98
94
|
}
|
|
99
95
|
|
|
100
96
|
/**
|
|
@@ -109,30 +105,27 @@ export const workflows: WorkflowsClient = new Proxy({} as WorkflowsClient, {
|
|
|
109
105
|
throw new Error(
|
|
110
106
|
`@voyantjs/workflows: workflows.${method}() requires the Voyant Cloud client. ` +
|
|
111
107
|
`Install + configure it via @voyantjs/client, or see docs/sdk-surface.md §6.`,
|
|
112
|
-
)
|
|
113
|
-
}
|
|
108
|
+
)
|
|
109
|
+
}
|
|
114
110
|
},
|
|
115
|
-
})
|
|
111
|
+
})
|
|
116
112
|
|
|
117
113
|
// ---- trigger.on ----
|
|
118
114
|
|
|
119
115
|
export interface EventFilterHandle {
|
|
120
|
-
readonly id: string
|
|
121
|
-
readonly event: string
|
|
116
|
+
readonly id: string
|
|
117
|
+
readonly event: string
|
|
122
118
|
}
|
|
123
119
|
|
|
124
120
|
export interface EventFilterDeclaration<T> {
|
|
125
|
-
target: WorkflowHandle<T, unknown
|
|
126
|
-
match?: (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
) => boolean;
|
|
130
|
-
scope?: string;
|
|
131
|
-
input?: (payload: T) => unknown;
|
|
121
|
+
target: WorkflowHandle<T, unknown>
|
|
122
|
+
match?: (payload: T, ctx: { environment: EnvironmentContext; project: { id: string } }) => boolean
|
|
123
|
+
scope?: string
|
|
124
|
+
input?: (payload: T) => unknown
|
|
132
125
|
}
|
|
133
126
|
|
|
134
127
|
export interface TriggerApi {
|
|
135
|
-
on<T = unknown>(event: string, filter: EventFilterDeclaration<T>): EventFilterHandle
|
|
128
|
+
on<T = unknown>(event: string, filter: EventFilterDeclaration<T>): EventFilterHandle
|
|
136
129
|
}
|
|
137
130
|
|
|
138
131
|
export const trigger: TriggerApi = {
|
|
@@ -141,6 +134,6 @@ export const trigger: TriggerApi = {
|
|
|
141
134
|
"@voyantjs/workflows: trigger.on() must be collected by `voyant workflows build` and " +
|
|
142
135
|
"registered with the orchestrator at deploy time; it has no runtime behavior when " +
|
|
143
136
|
"called directly. See docs/sdk-surface.md §6.2.",
|
|
144
|
-
)
|
|
137
|
+
)
|
|
145
138
|
},
|
|
146
|
-
}
|
|
139
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// Core type aliases used across the SDK.
|
|
2
2
|
// Authoritative definitions in docs/sdk-surface.md §0 and §2.
|
|
3
3
|
|
|
4
|
-
export type Duration =
|
|
5
|
-
| number
|
|
6
|
-
| `${number}${"ms" | "s" | "m" | "h" | "d" | "w"}`;
|
|
4
|
+
export type Duration = number | `${number}${"ms" | "s" | "m" | "h" | "d" | "w"}`
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* Cloudflare Container instance types — the set Voyant Cloud honors
|
|
@@ -31,9 +29,9 @@ export type MachineType =
|
|
|
31
29
|
| "standard-2"
|
|
32
30
|
| "standard-3"
|
|
33
31
|
| "standard-4"
|
|
34
|
-
| (string & {})
|
|
32
|
+
| (string & {})
|
|
35
33
|
|
|
36
|
-
export type EnvironmentName = "production" | "preview" | "development"
|
|
34
|
+
export type EnvironmentName = "production" | "preview" | "development"
|
|
37
35
|
|
|
38
36
|
export type RunStatus =
|
|
39
37
|
| "pending"
|
|
@@ -46,7 +44,7 @@ export type RunStatus =
|
|
|
46
44
|
| "cancelled_by_version_sunset"
|
|
47
45
|
| "compensated"
|
|
48
46
|
| "compensation_failed"
|
|
49
|
-
| "timed_out"
|
|
47
|
+
| "timed_out"
|
|
50
48
|
|
|
51
49
|
export type ExecutionStatus =
|
|
52
50
|
| "CREATED"
|
|
@@ -55,27 +53,27 @@ export type ExecutionStatus =
|
|
|
55
53
|
| "EXECUTING_WITH_WAITPOINTS"
|
|
56
54
|
| "SUSPENDED"
|
|
57
55
|
| "PENDING_CANCEL"
|
|
58
|
-
| "FINISHED"
|
|
56
|
+
| "FINISHED"
|
|
59
57
|
|
|
60
|
-
export type WaitpointKind = "DATETIME" | "EVENT" | "SIGNAL" | "RUN" | "MANUAL"
|
|
58
|
+
export type WaitpointKind = "DATETIME" | "EVENT" | "SIGNAL" | "RUN" | "MANUAL"
|
|
61
59
|
|
|
62
60
|
export interface RetryPolicy {
|
|
63
|
-
max?: number
|
|
64
|
-
backoff?: "exponential" | "linear" | "fixed"
|
|
65
|
-
initial?: Duration
|
|
66
|
-
maxDelay?: Duration
|
|
61
|
+
max?: number
|
|
62
|
+
backoff?: "exponential" | "linear" | "fixed"
|
|
63
|
+
initial?: Duration
|
|
64
|
+
maxDelay?: Duration
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
export interface RateLimitSpec {
|
|
70
|
-
key: string | ((input: unknown, ctx: { run: { id: string }; project: { id: string } }) => string)
|
|
71
|
-
limit: number | ((input: unknown) => number)
|
|
72
|
-
units?: number | ((input: unknown) => number)
|
|
73
|
-
window: Duration
|
|
74
|
-
onLimit?: "queue" | "fail"
|
|
68
|
+
key: string | ((input: unknown, ctx: { run: { id: string }; project: { id: string } }) => string)
|
|
69
|
+
limit: number | ((input: unknown) => number)
|
|
70
|
+
units?: number | ((input: unknown) => number)
|
|
71
|
+
window: Duration
|
|
72
|
+
onLimit?: "queue" | "fail"
|
|
75
73
|
}
|
|
76
74
|
|
|
77
75
|
export type RunTrigger =
|
|
78
76
|
| { kind: "api"; actor?: string; accessTokenId?: string }
|
|
79
77
|
| { kind: "schedule"; scheduleId: string }
|
|
80
78
|
| { kind: "event"; eventId: string; eventType: string; filterId: string }
|
|
81
|
-
| { kind: "parent"; parentRunId: string; parentStepId: string }
|
|
79
|
+
| { kind: "parent"; parentRunId: string; parentStepId: string }
|