@valon-technologies/gestalt 0.0.1-alpha.32 → 0.0.1-alpha.34
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/README.md +4 -5
- package/package.json +1 -1
- package/src/agent-access.ts +21 -29
- package/src/agent-conversions.ts +0 -37
- package/src/agent.ts +14 -20
- package/src/api.ts +17 -13
- package/src/app-access.ts +6 -17
- package/src/authorization.ts +619 -1436
- package/src/index.ts +45 -229
- package/src/internal/gen/v1/agent_pb.ts +110 -84
- package/src/internal/gen/v1/app_pb.ts +4 -19
- package/src/internal/gen/v1/authorization_pb.ts +407 -781
- package/src/internal/gen/v1/runtime_provider_pb.ts +1 -0
- package/src/internal/gen/v1/workflow_pb.ts +698 -722
- package/src/invocation-context.ts +15 -0
- package/src/provider-kind.ts +6 -6
- package/src/provider.ts +1 -1
- package/src/runtime.ts +15 -23
- package/src/workflow-access.ts +340 -385
- package/src/workflow.ts +1201 -2443
package/src/workflow-access.ts
CHANGED
|
@@ -13,77 +13,58 @@ import {
|
|
|
13
13
|
ENV_HOST_SERVICE_SOCKET,
|
|
14
14
|
ENV_HOST_SERVICE_TOKEN,
|
|
15
15
|
} from "./host-service.ts";
|
|
16
|
-
import type { Request } from "./api.ts";
|
|
16
|
+
import type { Request, SubjectInput } from "./api.ts";
|
|
17
|
+
import { jsonFromValue, structFromObject, type JsonObjectInput } from "./protocol.ts";
|
|
17
18
|
import {
|
|
18
|
-
|
|
19
|
+
subjectToProto,
|
|
19
20
|
workflowDefinitionFromProto,
|
|
20
|
-
|
|
21
|
-
workflowRunFromProto,
|
|
22
|
-
workflowRunSignalFromProto,
|
|
23
|
-
workflowScheduleFromProto,
|
|
21
|
+
workflowDefinitionSpecToProto,
|
|
24
22
|
workflowEventFromProto,
|
|
25
|
-
workflowEventMatchToProto,
|
|
26
23
|
workflowEventToProto,
|
|
24
|
+
workflowRunEventFromProto,
|
|
25
|
+
workflowRunFromProto,
|
|
26
|
+
workflowRunSignalFromProto,
|
|
27
27
|
workflowSignalToProto,
|
|
28
|
-
type
|
|
28
|
+
type GetWorkflowProviderRunOutputResponse,
|
|
29
|
+
type SignalWorkflowRunResponse,
|
|
29
30
|
type WorkflowDefinition,
|
|
30
|
-
type
|
|
31
|
-
type WorkflowRun,
|
|
32
|
-
type WorkflowRunSignal,
|
|
33
|
-
type WorkflowSchedule,
|
|
31
|
+
type WorkflowDefinitionSpec,
|
|
34
32
|
type WorkflowEvent,
|
|
35
|
-
type
|
|
33
|
+
type WorkflowRun,
|
|
34
|
+
type WorkflowRunEvent,
|
|
35
|
+
type WorkflowRunStatus,
|
|
36
36
|
type WorkflowSignal,
|
|
37
37
|
} from "./workflow.ts";
|
|
38
38
|
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
*
|
|
42
|
-
* Workflow calls call the facade. Provider runtimes still listen on
|
|
43
|
-
* GESTALT_PROVIDER_SOCKET.
|
|
44
|
-
*/
|
|
45
|
-
/** Shape accepted when starting a workflow run. */
|
|
46
|
-
export interface WorkflowStartRun {
|
|
39
|
+
/** Shape accepted when applying a workflow definition. */
|
|
40
|
+
export interface WorkflowApplyDefinition {
|
|
47
41
|
providerName: string;
|
|
48
|
-
|
|
42
|
+
spec?: WorkflowDefinitionSpec | undefined;
|
|
49
43
|
idempotencyKey?: string | undefined;
|
|
50
|
-
|
|
51
|
-
definitionId?: string | undefined;
|
|
44
|
+
requestedBySubjectId?: string | undefined;
|
|
52
45
|
}
|
|
53
46
|
|
|
54
|
-
/** Shape accepted when
|
|
55
|
-
export interface
|
|
56
|
-
|
|
57
|
-
signal?: WorkflowSignal | undefined;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Shape accepted when signaling a run or starting it if missing. */
|
|
61
|
-
export interface WorkflowSignalOrStartRun {
|
|
62
|
-
providerName: string;
|
|
63
|
-
workflowKey: string;
|
|
64
|
-
target?: BoundWorkflowTarget | undefined;
|
|
65
|
-
idempotencyKey?: string | undefined;
|
|
66
|
-
signal?: WorkflowSignal | undefined;
|
|
67
|
-
definitionId?: string | undefined;
|
|
47
|
+
/** Shape accepted when fetching a workflow definition. */
|
|
48
|
+
export interface WorkflowGetDefinition {
|
|
49
|
+
definitionId: string;
|
|
68
50
|
}
|
|
69
51
|
|
|
70
|
-
/** Shape accepted when
|
|
71
|
-
export interface
|
|
72
|
-
providerName: string;
|
|
73
|
-
target?: BoundWorkflowTarget | undefined;
|
|
74
|
-
idempotencyKey?: string | undefined;
|
|
75
|
-
}
|
|
52
|
+
/** Shape accepted when listing workflow definitions. */
|
|
53
|
+
export interface WorkflowListDefinitions {}
|
|
76
54
|
|
|
77
|
-
/** Shape accepted when
|
|
78
|
-
export interface
|
|
55
|
+
/** Shape accepted when pausing or resuming a workflow definition. */
|
|
56
|
+
export interface WorkflowSetDefinitionPaused {
|
|
79
57
|
definitionId: string;
|
|
58
|
+
paused: boolean;
|
|
59
|
+
requestedBySubjectId?: string | undefined;
|
|
80
60
|
}
|
|
81
61
|
|
|
82
|
-
/** Shape accepted when
|
|
83
|
-
export interface
|
|
62
|
+
/** Shape accepted when pausing or resuming a workflow activation. */
|
|
63
|
+
export interface WorkflowSetActivationPaused {
|
|
84
64
|
definitionId: string;
|
|
85
|
-
|
|
86
|
-
|
|
65
|
+
activationId: string;
|
|
66
|
+
paused: boolean;
|
|
67
|
+
requestedBySubjectId?: string | undefined;
|
|
87
68
|
}
|
|
88
69
|
|
|
89
70
|
/** Shape accepted when deleting a workflow definition. */
|
|
@@ -91,155 +72,117 @@ export interface WorkflowDeleteDefinition {
|
|
|
91
72
|
definitionId: string;
|
|
92
73
|
}
|
|
93
74
|
|
|
94
|
-
/** Shape accepted when
|
|
95
|
-
export interface
|
|
96
|
-
providerName: string;
|
|
97
|
-
cron: string;
|
|
98
|
-
timezone?: string | undefined;
|
|
99
|
-
target?: BoundWorkflowTarget | undefined;
|
|
100
|
-
paused?: boolean | undefined;
|
|
101
|
-
idempotencyKey?: string | undefined;
|
|
102
|
-
definitionId?: string | undefined;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/** Shape accepted when creating an event trigger. */
|
|
106
|
-
export interface WorkflowCreateTrigger {
|
|
75
|
+
/** Shape accepted when starting a workflow run. */
|
|
76
|
+
export interface WorkflowStartRun {
|
|
107
77
|
providerName: string;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
78
|
+
definitionId: string;
|
|
79
|
+
expectedDefinitionGeneration?: bigint | number | undefined;
|
|
80
|
+
input?: JsonObjectInput | undefined;
|
|
111
81
|
idempotencyKey?: string | undefined;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
/** Shape accepted when fetching a workflow schedule. */
|
|
116
|
-
export interface WorkflowGetSchedule {
|
|
117
|
-
scheduleId: string;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** Shape accepted when fetching an event trigger. */
|
|
121
|
-
export interface WorkflowGetTrigger {
|
|
122
|
-
triggerId: string;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** Shape accepted when updating a workflow schedule. */
|
|
126
|
-
export interface WorkflowUpdateSchedule {
|
|
127
|
-
scheduleId: string;
|
|
128
|
-
providerName?: string | undefined;
|
|
129
|
-
cron?: string | undefined;
|
|
130
|
-
timezone?: string | undefined;
|
|
131
|
-
target?: BoundWorkflowTarget | undefined;
|
|
132
|
-
paused?: boolean | undefined;
|
|
133
|
-
definitionId?: string | undefined;
|
|
82
|
+
workflowKey?: string | undefined;
|
|
83
|
+
createdBySubjectId?: string | undefined;
|
|
84
|
+
runAs?: SubjectInput | undefined;
|
|
134
85
|
}
|
|
135
86
|
|
|
136
|
-
/** Shape accepted when
|
|
137
|
-
export interface
|
|
138
|
-
|
|
139
|
-
providerName?: string | undefined;
|
|
140
|
-
match?: WorkflowEventMatch | undefined;
|
|
141
|
-
target?: BoundWorkflowTarget | undefined;
|
|
142
|
-
paused?: boolean | undefined;
|
|
143
|
-
definitionId?: string | undefined;
|
|
87
|
+
/** Shape accepted when fetching one workflow run. */
|
|
88
|
+
export interface WorkflowGetRun {
|
|
89
|
+
runId: string;
|
|
144
90
|
}
|
|
145
91
|
|
|
146
|
-
/** Shape accepted when
|
|
147
|
-
export interface
|
|
148
|
-
|
|
92
|
+
/** Shape accepted when listing workflow runs. */
|
|
93
|
+
export interface WorkflowListRuns {
|
|
94
|
+
pageSize?: number | undefined;
|
|
95
|
+
pageToken?: string | undefined;
|
|
96
|
+
status?: WorkflowRunStatus | undefined;
|
|
97
|
+
targetApp?: string | undefined;
|
|
149
98
|
}
|
|
150
99
|
|
|
151
|
-
/** Shape accepted when
|
|
152
|
-
export interface
|
|
153
|
-
|
|
100
|
+
/** Shape accepted when fetching workflow run events. */
|
|
101
|
+
export interface WorkflowGetRunEvents {
|
|
102
|
+
runId: string;
|
|
154
103
|
}
|
|
155
104
|
|
|
156
|
-
/** Shape accepted when
|
|
157
|
-
export interface
|
|
158
|
-
|
|
105
|
+
/** Shape accepted when fetching the terminal workflow run output. */
|
|
106
|
+
export interface WorkflowGetRunOutput {
|
|
107
|
+
runId: string;
|
|
159
108
|
}
|
|
160
109
|
|
|
161
|
-
/** Shape accepted when
|
|
162
|
-
export interface
|
|
163
|
-
|
|
110
|
+
/** Shape accepted when canceling a workflow run. */
|
|
111
|
+
export interface WorkflowCancelRun {
|
|
112
|
+
runId: string;
|
|
113
|
+
reason?: string | undefined;
|
|
164
114
|
}
|
|
165
115
|
|
|
166
|
-
/** Shape accepted when
|
|
167
|
-
export interface
|
|
168
|
-
|
|
116
|
+
/** Shape accepted when signaling an existing workflow run. */
|
|
117
|
+
export interface WorkflowSignalRun {
|
|
118
|
+
runId: string;
|
|
119
|
+
signal?: WorkflowSignal | undefined;
|
|
169
120
|
}
|
|
170
121
|
|
|
171
|
-
/** Shape accepted when
|
|
172
|
-
export interface
|
|
173
|
-
|
|
122
|
+
/** Shape accepted when signaling a run or starting it if missing. */
|
|
123
|
+
export interface WorkflowSignalOrStartRun {
|
|
124
|
+
providerName: string;
|
|
125
|
+
workflowKey: string;
|
|
126
|
+
definitionId: string;
|
|
127
|
+
expectedDefinitionGeneration?: bigint | number | undefined;
|
|
128
|
+
input?: JsonObjectInput | undefined;
|
|
129
|
+
idempotencyKey?: string | undefined;
|
|
130
|
+
createdBySubjectId?: string | undefined;
|
|
131
|
+
runAs?: SubjectInput | undefined;
|
|
132
|
+
signal?: WorkflowSignal | undefined;
|
|
174
133
|
}
|
|
175
134
|
|
|
176
|
-
/** Shape accepted when
|
|
177
|
-
export interface
|
|
178
|
-
|
|
135
|
+
/** Shape accepted when delivering an app event to workflow activations. */
|
|
136
|
+
export interface WorkflowDeliverEvent {
|
|
137
|
+
appName?: string | undefined;
|
|
179
138
|
providerName?: string | undefined;
|
|
139
|
+
event?: WorkflowEvent | undefined;
|
|
140
|
+
deliveredBySubjectId?: string | undefined;
|
|
180
141
|
}
|
|
181
142
|
|
|
182
143
|
/** Fakeable client contract for workflow calls. */
|
|
183
144
|
export interface Workflow {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
request: WorkflowSignalRun,
|
|
187
|
-
): Promise<WorkflowRunSignal>;
|
|
188
|
-
signalOrStartRun(
|
|
189
|
-
request: WorkflowSignalOrStartRun,
|
|
190
|
-
): Promise<WorkflowRunSignal>;
|
|
191
|
-
createDefinition(
|
|
192
|
-
request: WorkflowCreateDefinition,
|
|
145
|
+
applyDefinition(
|
|
146
|
+
request: WorkflowApplyDefinition,
|
|
193
147
|
): Promise<WorkflowDefinition>;
|
|
194
148
|
getDefinition(
|
|
195
149
|
request: WorkflowGetDefinition,
|
|
196
150
|
): Promise<WorkflowDefinition>;
|
|
197
|
-
|
|
198
|
-
request
|
|
151
|
+
listDefinitions(
|
|
152
|
+
request?: WorkflowListDefinitions,
|
|
153
|
+
): Promise<readonly WorkflowDefinition[]>;
|
|
154
|
+
setDefinitionPaused(
|
|
155
|
+
request: WorkflowSetDefinitionPaused,
|
|
156
|
+
): Promise<WorkflowDefinition>;
|
|
157
|
+
setActivationPaused(
|
|
158
|
+
request: WorkflowSetActivationPaused,
|
|
199
159
|
): Promise<WorkflowDefinition>;
|
|
200
160
|
deleteDefinition(request: WorkflowDeleteDefinition): Promise<void>;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
): Promise<
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
): Promise<
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
): Promise<
|
|
217
|
-
createTrigger(
|
|
218
|
-
request: WorkflowCreateTrigger,
|
|
219
|
-
): Promise<WorkflowEventTrigger>;
|
|
220
|
-
getTrigger(
|
|
221
|
-
request: WorkflowGetTrigger,
|
|
222
|
-
): Promise<WorkflowEventTrigger>;
|
|
223
|
-
updateTrigger(
|
|
224
|
-
request: WorkflowUpdateTrigger,
|
|
225
|
-
): Promise<WorkflowEventTrigger>;
|
|
226
|
-
deleteTrigger(request: WorkflowDeleteTrigger): Promise<void>;
|
|
227
|
-
pauseTrigger(
|
|
228
|
-
request: WorkflowPauseTrigger,
|
|
229
|
-
): Promise<WorkflowEventTrigger>;
|
|
230
|
-
resumeTrigger(
|
|
231
|
-
request: WorkflowResumeTrigger,
|
|
232
|
-
): Promise<WorkflowEventTrigger>;
|
|
233
|
-
publishEvent(request: WorkflowPublishEvent): Promise<WorkflowEvent>;
|
|
161
|
+
startRun(request: WorkflowStartRun): Promise<WorkflowRun>;
|
|
162
|
+
getRun(request: WorkflowGetRun): Promise<WorkflowRun>;
|
|
163
|
+
listRuns(request?: WorkflowListRuns): Promise<{
|
|
164
|
+
runs: readonly WorkflowRun[];
|
|
165
|
+
nextPageToken?: string | undefined;
|
|
166
|
+
}>;
|
|
167
|
+
getRunEvents(request: WorkflowGetRunEvents): Promise<readonly WorkflowRunEvent[]>;
|
|
168
|
+
getRunOutput(request: WorkflowGetRunOutput): Promise<GetWorkflowProviderRunOutputResponse>;
|
|
169
|
+
cancelRun(request: WorkflowCancelRun): Promise<WorkflowRun>;
|
|
170
|
+
signalRun(
|
|
171
|
+
request: WorkflowSignalRun,
|
|
172
|
+
): Promise<SignalWorkflowRunResponse>;
|
|
173
|
+
signalOrStartRun(
|
|
174
|
+
request: WorkflowSignalOrStartRun,
|
|
175
|
+
): Promise<SignalWorkflowRunResponse>;
|
|
176
|
+
deliverEvent(request: WorkflowDeliverEvent): Promise<WorkflowEvent>;
|
|
234
177
|
}
|
|
235
178
|
|
|
236
179
|
/**
|
|
237
|
-
* Client for
|
|
180
|
+
* Client for applying workflow definitions and controlling durable runs.
|
|
238
181
|
*
|
|
239
182
|
* The constructor accepts either a Gestalt request or an invocation token. Each
|
|
240
|
-
*
|
|
241
|
-
* constructed from a request,
|
|
242
|
-
*
|
|
183
|
+
* workflow call forwards that token to the workflow-provider facade. When
|
|
184
|
+
* constructed from a request, mutating calls reuse the request idempotency key
|
|
185
|
+
* unless the call provides one explicitly.
|
|
243
186
|
*/
|
|
244
187
|
class WorkflowImpl implements Workflow {
|
|
245
188
|
private readonly client: Client<typeof WorkflowProviderService>;
|
|
@@ -268,89 +211,83 @@ class WorkflowImpl implements Workflow {
|
|
|
268
211
|
this.client = createClient(WorkflowProviderService, transport);
|
|
269
212
|
}
|
|
270
213
|
|
|
271
|
-
/**
|
|
272
|
-
async
|
|
273
|
-
request:
|
|
274
|
-
): Promise<
|
|
275
|
-
return
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
/** Signals an existing workflow run. */
|
|
288
|
-
async signalRun(
|
|
289
|
-
request: WorkflowSignalRun,
|
|
290
|
-
): Promise<WorkflowRunSignal> {
|
|
291
|
-
return workflowRunSignalFromProto(
|
|
292
|
-
await this.client.signalRun({
|
|
293
|
-
runId: request.runId,
|
|
294
|
-
signal: workflowSignalToProto(request.signal),
|
|
295
|
-
invocationToken: this.invocationToken,
|
|
296
|
-
}),
|
|
214
|
+
/** Applies a durable workflow definition atomically. */
|
|
215
|
+
async applyDefinition(
|
|
216
|
+
request: WorkflowApplyDefinition,
|
|
217
|
+
): Promise<WorkflowDefinition> {
|
|
218
|
+
return requireDefinition(
|
|
219
|
+
workflowDefinitionFromProto(
|
|
220
|
+
await this.client.applyDefinition({
|
|
221
|
+
providerName: request.providerName,
|
|
222
|
+
spec: workflowDefinitionSpecToProto(request.spec),
|
|
223
|
+
invocationToken: this.invocationToken,
|
|
224
|
+
idempotencyKey: request.idempotencyKey?.trim() || this.idempotencyKey,
|
|
225
|
+
requestedBySubjectId: request.requestedBySubjectId ?? "",
|
|
226
|
+
}),
|
|
227
|
+
),
|
|
228
|
+
"Workflow.applyDefinition returned no definition",
|
|
297
229
|
);
|
|
298
230
|
}
|
|
299
231
|
|
|
300
|
-
/**
|
|
301
|
-
async
|
|
302
|
-
request:
|
|
303
|
-
): Promise<
|
|
304
|
-
return
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
definitionId: request.definitionId ?? "",
|
|
313
|
-
}),
|
|
232
|
+
/** Fetches one workflow definition. */
|
|
233
|
+
async getDefinition(
|
|
234
|
+
request: WorkflowGetDefinition,
|
|
235
|
+
): Promise<WorkflowDefinition> {
|
|
236
|
+
return requireDefinition(
|
|
237
|
+
workflowDefinitionFromProto(
|
|
238
|
+
await this.client.getDefinition({
|
|
239
|
+
definitionId: request.definitionId,
|
|
240
|
+
invocationToken: this.invocationToken,
|
|
241
|
+
}),
|
|
242
|
+
),
|
|
243
|
+
"Workflow.getDefinition returned no definition",
|
|
314
244
|
);
|
|
315
245
|
}
|
|
316
246
|
|
|
317
|
-
/**
|
|
318
|
-
async
|
|
319
|
-
|
|
320
|
-
): Promise<WorkflowDefinition> {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
idempotencyKey: request.idempotencyKey?.trim() || this.idempotencyKey,
|
|
327
|
-
}),
|
|
247
|
+
/** Lists workflow definitions visible to the current invocation token. */
|
|
248
|
+
async listDefinitions(
|
|
249
|
+
_request: WorkflowListDefinitions = {},
|
|
250
|
+
): Promise<readonly WorkflowDefinition[]> {
|
|
251
|
+
const response = await this.client.listDefinitions({
|
|
252
|
+
invocationToken: this.invocationToken,
|
|
253
|
+
});
|
|
254
|
+
return response.definitions.map((definition) =>
|
|
255
|
+
requireDefinition(workflowDefinitionFromProto(definition), "Workflow.listDefinitions returned an empty definition")
|
|
328
256
|
);
|
|
329
257
|
}
|
|
330
258
|
|
|
331
|
-
/**
|
|
332
|
-
async
|
|
333
|
-
request:
|
|
259
|
+
/** Pauses or resumes a workflow definition. */
|
|
260
|
+
async setDefinitionPaused(
|
|
261
|
+
request: WorkflowSetDefinitionPaused,
|
|
334
262
|
): Promise<WorkflowDefinition> {
|
|
335
|
-
return
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
263
|
+
return requireDefinition(
|
|
264
|
+
workflowDefinitionFromProto(
|
|
265
|
+
await this.client.setDefinitionPaused({
|
|
266
|
+
definitionId: request.definitionId,
|
|
267
|
+
paused: request.paused,
|
|
268
|
+
invocationToken: this.invocationToken,
|
|
269
|
+
requestedBySubjectId: request.requestedBySubjectId ?? "",
|
|
270
|
+
}),
|
|
271
|
+
),
|
|
272
|
+
"Workflow.setDefinitionPaused returned no definition",
|
|
340
273
|
);
|
|
341
274
|
}
|
|
342
275
|
|
|
343
|
-
/**
|
|
344
|
-
async
|
|
345
|
-
request:
|
|
276
|
+
/** Pauses or resumes one activation within a workflow definition. */
|
|
277
|
+
async setActivationPaused(
|
|
278
|
+
request: WorkflowSetActivationPaused,
|
|
346
279
|
): Promise<WorkflowDefinition> {
|
|
347
|
-
return
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
280
|
+
return requireDefinition(
|
|
281
|
+
workflowDefinitionFromProto(
|
|
282
|
+
await this.client.setActivationPaused({
|
|
283
|
+
definitionId: request.definitionId,
|
|
284
|
+
activationId: request.activationId,
|
|
285
|
+
paused: request.paused,
|
|
286
|
+
invocationToken: this.invocationToken,
|
|
287
|
+
requestedBySubjectId: request.requestedBySubjectId ?? "",
|
|
288
|
+
}),
|
|
289
|
+
),
|
|
290
|
+
"Workflow.setActivationPaused returned no definition",
|
|
354
291
|
);
|
|
355
292
|
}
|
|
356
293
|
|
|
@@ -364,183 +301,159 @@ class WorkflowImpl implements Workflow {
|
|
|
364
301
|
});
|
|
365
302
|
}
|
|
366
303
|
|
|
367
|
-
/**
|
|
368
|
-
async
|
|
369
|
-
request:
|
|
370
|
-
): Promise<
|
|
371
|
-
return
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
async getSchedule(
|
|
387
|
-
request: WorkflowGetSchedule,
|
|
388
|
-
): Promise<WorkflowSchedule> {
|
|
389
|
-
return workflowScheduleFromProto(
|
|
390
|
-
await this.client.getSchedule({
|
|
391
|
-
scheduleId: request.scheduleId,
|
|
392
|
-
invocationToken: this.invocationToken,
|
|
393
|
-
}),
|
|
304
|
+
/** Starts a workflow run immediately. */
|
|
305
|
+
async startRun(
|
|
306
|
+
request: WorkflowStartRun,
|
|
307
|
+
): Promise<WorkflowRun> {
|
|
308
|
+
return requireRun(
|
|
309
|
+
workflowRunFromProto(
|
|
310
|
+
await this.client.startRun({
|
|
311
|
+
providerName: request.providerName,
|
|
312
|
+
definitionId: request.definitionId,
|
|
313
|
+
expectedDefinitionGeneration: generationToBigInt(request.expectedDefinitionGeneration),
|
|
314
|
+
input: structFromObject(request.input),
|
|
315
|
+
idempotencyKey: request.idempotencyKey?.trim() || this.idempotencyKey,
|
|
316
|
+
workflowKey: request.workflowKey ?? "",
|
|
317
|
+
invocationToken: this.invocationToken,
|
|
318
|
+
createdBySubjectId: request.createdBySubjectId ?? "",
|
|
319
|
+
runAs: subjectToProto(request.runAs),
|
|
320
|
+
}),
|
|
321
|
+
),
|
|
322
|
+
"Workflow.startRun returned no run",
|
|
394
323
|
);
|
|
395
324
|
}
|
|
396
325
|
|
|
397
|
-
/**
|
|
398
|
-
async
|
|
399
|
-
request:
|
|
400
|
-
): Promise<
|
|
401
|
-
return
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
invocationToken: this.invocationToken,
|
|
410
|
-
definitionId: request.definitionId ?? "",
|
|
411
|
-
}),
|
|
326
|
+
/** Fetches one workflow run. */
|
|
327
|
+
async getRun(
|
|
328
|
+
request: WorkflowGetRun,
|
|
329
|
+
): Promise<WorkflowRun> {
|
|
330
|
+
return requireRun(
|
|
331
|
+
workflowRunFromProto(
|
|
332
|
+
await this.client.getRun({
|
|
333
|
+
runId: request.runId,
|
|
334
|
+
invocationToken: this.invocationToken,
|
|
335
|
+
}),
|
|
336
|
+
),
|
|
337
|
+
"Workflow.getRun returned no run",
|
|
412
338
|
);
|
|
413
339
|
}
|
|
414
340
|
|
|
415
|
-
/**
|
|
416
|
-
async
|
|
417
|
-
request:
|
|
418
|
-
): Promise<
|
|
419
|
-
await this.client.
|
|
420
|
-
|
|
341
|
+
/** Lists workflow runs visible to the current invocation token. */
|
|
342
|
+
async listRuns(
|
|
343
|
+
request: WorkflowListRuns = {},
|
|
344
|
+
): Promise<{ runs: readonly WorkflowRun[]; nextPageToken?: string | undefined }> {
|
|
345
|
+
const response = await this.client.listRuns({
|
|
346
|
+
pageSize: request.pageSize ?? 0,
|
|
347
|
+
pageToken: request.pageToken ?? "",
|
|
348
|
+
status: request.status ?? 0,
|
|
349
|
+
targetApp: request.targetApp ?? "",
|
|
421
350
|
invocationToken: this.invocationToken,
|
|
422
351
|
});
|
|
352
|
+
return {
|
|
353
|
+
runs: response.runs.map((run) => requireRun(workflowRunFromProto(run), "Workflow.listRuns returned an empty run")),
|
|
354
|
+
nextPageToken: response.nextPageToken || undefined,
|
|
355
|
+
};
|
|
423
356
|
}
|
|
424
357
|
|
|
425
|
-
/**
|
|
426
|
-
async
|
|
427
|
-
request:
|
|
428
|
-
): Promise<
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
/** Resumes a workflow schedule. */
|
|
438
|
-
async resumeSchedule(
|
|
439
|
-
request: WorkflowResumeSchedule,
|
|
440
|
-
): Promise<WorkflowSchedule> {
|
|
441
|
-
return workflowScheduleFromProto(
|
|
442
|
-
await this.client.resumeSchedule({
|
|
443
|
-
scheduleId: request.scheduleId,
|
|
444
|
-
invocationToken: this.invocationToken,
|
|
445
|
-
}),
|
|
446
|
-
);
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
/** Creates an event trigger. */
|
|
450
|
-
async createTrigger(
|
|
451
|
-
request: WorkflowCreateTrigger,
|
|
452
|
-
): Promise<WorkflowEventTrigger> {
|
|
453
|
-
return workflowEventTriggerFromProto(
|
|
454
|
-
await this.client.upsertEventTrigger({
|
|
455
|
-
providerName: request.providerName,
|
|
456
|
-
match: workflowEventMatchToProto(request.match),
|
|
457
|
-
target: boundWorkflowTargetToProto(request.target),
|
|
458
|
-
paused: request.paused ?? false,
|
|
459
|
-
invocationToken: this.invocationToken,
|
|
460
|
-
idempotencyKey: request.idempotencyKey?.trim() || this.idempotencyKey,
|
|
461
|
-
definitionId: request.definitionId ?? "",
|
|
462
|
-
}),
|
|
358
|
+
/** Fetches workflow run events. */
|
|
359
|
+
async getRunEvents(
|
|
360
|
+
request: WorkflowGetRunEvents,
|
|
361
|
+
): Promise<readonly WorkflowRunEvent[]> {
|
|
362
|
+
const response = await this.client.getRunEvents({
|
|
363
|
+
runId: request.runId,
|
|
364
|
+
invocationToken: this.invocationToken,
|
|
365
|
+
});
|
|
366
|
+
return response.events.map((event) =>
|
|
367
|
+
requireRunEvent(workflowRunEventFromProto(event), "Workflow.getRunEvents returned an empty event")
|
|
463
368
|
);
|
|
464
369
|
}
|
|
465
370
|
|
|
466
|
-
/** Fetches
|
|
467
|
-
async
|
|
468
|
-
request:
|
|
469
|
-
): Promise<
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
371
|
+
/** Fetches the terminal workflow run output. */
|
|
372
|
+
async getRunOutput(
|
|
373
|
+
request: WorkflowGetRunOutput,
|
|
374
|
+
): Promise<GetWorkflowProviderRunOutputResponse> {
|
|
375
|
+
const response = await this.client.getRunOutput({
|
|
376
|
+
runId: request.runId,
|
|
377
|
+
invocationToken: this.invocationToken,
|
|
378
|
+
});
|
|
379
|
+
return {
|
|
380
|
+
output: response.output === undefined
|
|
381
|
+
? undefined
|
|
382
|
+
: jsonFromValue(response.output),
|
|
383
|
+
};
|
|
476
384
|
}
|
|
477
385
|
|
|
478
|
-
/**
|
|
479
|
-
async
|
|
480
|
-
request:
|
|
481
|
-
): Promise<
|
|
482
|
-
return
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
}),
|
|
386
|
+
/** Cancels a workflow run. */
|
|
387
|
+
async cancelRun(
|
|
388
|
+
request: WorkflowCancelRun,
|
|
389
|
+
): Promise<WorkflowRun> {
|
|
390
|
+
return requireRun(
|
|
391
|
+
workflowRunFromProto(
|
|
392
|
+
await this.client.cancelRun({
|
|
393
|
+
runId: request.runId,
|
|
394
|
+
reason: request.reason ?? "",
|
|
395
|
+
invocationToken: this.invocationToken,
|
|
396
|
+
}),
|
|
397
|
+
),
|
|
398
|
+
"Workflow.cancelRun returned no run",
|
|
492
399
|
);
|
|
493
400
|
}
|
|
494
401
|
|
|
495
|
-
/**
|
|
496
|
-
async
|
|
497
|
-
request:
|
|
498
|
-
): Promise<
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
): Promise<WorkflowEventTrigger> {
|
|
509
|
-
return workflowEventTriggerFromProto(
|
|
510
|
-
await this.client.pauseEventTrigger({
|
|
511
|
-
triggerId: request.triggerId,
|
|
512
|
-
invocationToken: this.invocationToken,
|
|
513
|
-
}),
|
|
402
|
+
/** Signals an existing workflow run. */
|
|
403
|
+
async signalRun(
|
|
404
|
+
request: WorkflowSignalRun,
|
|
405
|
+
): Promise<SignalWorkflowRunResponse> {
|
|
406
|
+
return requireSignalResponse(
|
|
407
|
+
workflowRunSignalFromProto(
|
|
408
|
+
await this.client.signalRun({
|
|
409
|
+
runId: request.runId,
|
|
410
|
+
signal: workflowSignalToProto(request.signal),
|
|
411
|
+
invocationToken: this.invocationToken,
|
|
412
|
+
}),
|
|
413
|
+
),
|
|
414
|
+
"Workflow.signalRun returned no response",
|
|
514
415
|
);
|
|
515
416
|
}
|
|
516
417
|
|
|
517
|
-
/**
|
|
518
|
-
async
|
|
519
|
-
request:
|
|
520
|
-
): Promise<
|
|
521
|
-
return
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
418
|
+
/** Signals a workflow run, or starts it when no run exists for the key. */
|
|
419
|
+
async signalOrStartRun(
|
|
420
|
+
request: WorkflowSignalOrStartRun,
|
|
421
|
+
): Promise<SignalWorkflowRunResponse> {
|
|
422
|
+
return requireSignalResponse(
|
|
423
|
+
workflowRunSignalFromProto(
|
|
424
|
+
await this.client.signalOrStartRun({
|
|
425
|
+
providerName: request.providerName,
|
|
426
|
+
workflowKey: request.workflowKey,
|
|
427
|
+
definitionId: request.definitionId,
|
|
428
|
+
expectedDefinitionGeneration: generationToBigInt(request.expectedDefinitionGeneration),
|
|
429
|
+
input: structFromObject(request.input),
|
|
430
|
+
idempotencyKey: request.idempotencyKey?.trim() || this.idempotencyKey,
|
|
431
|
+
signal: workflowSignalToProto(request.signal),
|
|
432
|
+
invocationToken: this.invocationToken,
|
|
433
|
+
createdBySubjectId: request.createdBySubjectId ?? "",
|
|
434
|
+
runAs: subjectToProto(request.runAs),
|
|
435
|
+
}),
|
|
436
|
+
),
|
|
437
|
+
"Workflow.signalOrStartRun returned no response",
|
|
526
438
|
);
|
|
527
439
|
}
|
|
528
440
|
|
|
529
|
-
/**
|
|
530
|
-
async
|
|
531
|
-
request:
|
|
441
|
+
/** Delivers an event into workflow activation matching. */
|
|
442
|
+
async deliverEvent(
|
|
443
|
+
request: WorkflowDeliverEvent,
|
|
532
444
|
): Promise<WorkflowEvent> {
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
445
|
+
return requireEvent(
|
|
446
|
+
workflowEventFromProto(
|
|
447
|
+
await this.client.deliverEvent({
|
|
448
|
+
appName: request.appName ?? "",
|
|
449
|
+
event: workflowEventToProto(request.event),
|
|
450
|
+
deliveredBySubjectId: request.deliveredBySubjectId ?? "",
|
|
451
|
+
invocationToken: this.invocationToken,
|
|
452
|
+
providerName: request.providerName ?? "",
|
|
453
|
+
}),
|
|
454
|
+
),
|
|
455
|
+
"Workflow.deliverEvent returned no event",
|
|
539
456
|
);
|
|
540
|
-
if (event === undefined) {
|
|
541
|
-
throw new Error("Workflow.publishEvent returned no event");
|
|
542
|
-
}
|
|
543
|
-
return event;
|
|
544
457
|
}
|
|
545
458
|
}
|
|
546
459
|
|
|
@@ -564,3 +477,45 @@ function normalizeIdempotencyKey(requestOrToken: Request | string): string {
|
|
|
564
477
|
}
|
|
565
478
|
return requestOrToken.idempotencyKey.trim();
|
|
566
479
|
}
|
|
480
|
+
|
|
481
|
+
function generationToBigInt(value: bigint | number | undefined): bigint {
|
|
482
|
+
if (value === undefined) {
|
|
483
|
+
return 0n;
|
|
484
|
+
}
|
|
485
|
+
return typeof value === "bigint" ? value : BigInt(value);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function requireDefinition(value: WorkflowDefinition | undefined, message: string): WorkflowDefinition {
|
|
489
|
+
if (value === undefined) {
|
|
490
|
+
throw new Error(message);
|
|
491
|
+
}
|
|
492
|
+
return value;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function requireRun(value: WorkflowRun | undefined, message: string): WorkflowRun {
|
|
496
|
+
if (value === undefined) {
|
|
497
|
+
throw new Error(message);
|
|
498
|
+
}
|
|
499
|
+
return value;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function requireRunEvent(value: WorkflowRunEvent | undefined, message: string): WorkflowRunEvent {
|
|
503
|
+
if (value === undefined) {
|
|
504
|
+
throw new Error(message);
|
|
505
|
+
}
|
|
506
|
+
return value;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function requireSignalResponse(value: SignalWorkflowRunResponse | undefined, message: string): SignalWorkflowRunResponse {
|
|
510
|
+
if (value === undefined) {
|
|
511
|
+
throw new Error(message);
|
|
512
|
+
}
|
|
513
|
+
return value;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function requireEvent(value: WorkflowEvent | undefined, message: string): WorkflowEvent {
|
|
517
|
+
if (value === undefined) {
|
|
518
|
+
throw new Error(message);
|
|
519
|
+
}
|
|
520
|
+
return value;
|
|
521
|
+
}
|