@temporal-contract/contract 0.0.2 → 0.0.3
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/package.json +5 -2
- package/.turbo/turbo-build.log +0 -17
- package/CHANGELOG.md +0 -7
- package/src/builder.spec.ts +0 -717
- package/src/builder.ts +0 -286
- package/src/helpers.spec.ts +0 -122
- package/src/index.ts +0 -55
- package/src/types.spec.ts +0 -637
- package/src/types.ts +0 -429
- package/tsconfig.json +0 -9
- package/vitest.config.ts +0 -12
package/src/types.ts
DELETED
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Base types for validation schemas
|
|
5
|
-
* Any schema that implements the Standard Schema specification
|
|
6
|
-
* This includes Zod, Valibot, ArkType, and other compatible libraries
|
|
7
|
-
*/
|
|
8
|
-
export type AnySchema = StandardSchemaV1;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Definition of an activity
|
|
12
|
-
*/
|
|
13
|
-
export interface ActivityDefinition<
|
|
14
|
-
TInput extends AnySchema = AnySchema,
|
|
15
|
-
TOutput extends AnySchema = AnySchema,
|
|
16
|
-
> {
|
|
17
|
-
readonly input: TInput;
|
|
18
|
-
readonly output: TOutput;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Definition of a signal
|
|
23
|
-
*/
|
|
24
|
-
export interface SignalDefinition<TInput extends AnySchema = AnySchema> {
|
|
25
|
-
readonly input: TInput;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Definition of a query
|
|
30
|
-
*/
|
|
31
|
-
export interface QueryDefinition<
|
|
32
|
-
TInput extends AnySchema = AnySchema,
|
|
33
|
-
TOutput extends AnySchema = AnySchema,
|
|
34
|
-
> {
|
|
35
|
-
readonly input: TInput;
|
|
36
|
-
readonly output: TOutput;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Definition of an update
|
|
41
|
-
*/
|
|
42
|
-
export interface UpdateDefinition<
|
|
43
|
-
TInput extends AnySchema = AnySchema,
|
|
44
|
-
TOutput extends AnySchema = AnySchema,
|
|
45
|
-
> {
|
|
46
|
-
readonly input: TInput;
|
|
47
|
-
readonly output: TOutput;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Definition of a workflow
|
|
52
|
-
*/
|
|
53
|
-
export interface WorkflowDefinition<
|
|
54
|
-
TActivities extends Record<string, ActivityDefinition> = Record<string, ActivityDefinition>,
|
|
55
|
-
TSignals extends Record<string, SignalDefinition> = Record<string, SignalDefinition>,
|
|
56
|
-
TQueries extends Record<string, QueryDefinition> = Record<string, QueryDefinition>,
|
|
57
|
-
TUpdates extends Record<string, UpdateDefinition> = Record<string, UpdateDefinition>,
|
|
58
|
-
> {
|
|
59
|
-
readonly input: AnySchema;
|
|
60
|
-
readonly output: AnySchema;
|
|
61
|
-
readonly activities?: TActivities;
|
|
62
|
-
readonly signals?: TSignals;
|
|
63
|
-
readonly queries?: TQueries;
|
|
64
|
-
readonly updates?: TUpdates;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Contract definition containing workflows and optional global activities
|
|
69
|
-
*/
|
|
70
|
-
export interface ContractDefinition<
|
|
71
|
-
TWorkflows extends Record<string, WorkflowDefinition> = Record<string, WorkflowDefinition>,
|
|
72
|
-
TActivities extends Record<string, ActivityDefinition> = Record<string, ActivityDefinition>,
|
|
73
|
-
> {
|
|
74
|
-
readonly taskQueue: string;
|
|
75
|
-
readonly workflows: TWorkflows;
|
|
76
|
-
readonly activities?: TActivities;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Infer input type from a definition (worker perspective)
|
|
81
|
-
* Worker receives the output type (after input schema parsing/transformation)
|
|
82
|
-
*/
|
|
83
|
-
export type WorkerInferInput<T extends { input: AnySchema }> = StandardSchemaV1.InferOutput<
|
|
84
|
-
T["input"]
|
|
85
|
-
>;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Infer output type from a definition (worker perspective)
|
|
89
|
-
* Worker returns the input type (before output schema parsing/transformation)
|
|
90
|
-
*/
|
|
91
|
-
export type WorkerInferOutput<T extends { output: AnySchema }> = StandardSchemaV1.InferInput<
|
|
92
|
-
T["output"]
|
|
93
|
-
>;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Infer input type from a definition (client perspective)
|
|
97
|
-
* Client sends the input type (before input schema parsing/transformation)
|
|
98
|
-
*/
|
|
99
|
-
export type ClientInferInput<T extends { input: AnySchema }> = StandardSchemaV1.InferInput<
|
|
100
|
-
T["input"]
|
|
101
|
-
>;
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Infer output type from a definition (client perspective)
|
|
105
|
-
* Client receives the output type (after output schema parsing/transformation)
|
|
106
|
-
*/
|
|
107
|
-
export type ClientInferOutput<T extends { output: AnySchema }> = StandardSchemaV1.InferOutput<
|
|
108
|
-
T["output"]
|
|
109
|
-
>;
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* WORKER PERSPECTIVE
|
|
113
|
-
* Worker receives z.output of input (parsed data) and returns z.input of output (raw data)
|
|
114
|
-
*/
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Infer workflow function signature from worker perspective
|
|
118
|
-
* Worker receives z.input and returns z.output
|
|
119
|
-
*/
|
|
120
|
-
export type WorkerInferWorkflow<TWorkflow extends WorkflowDefinition> = (
|
|
121
|
-
args: WorkerInferInput<TWorkflow>,
|
|
122
|
-
) => Promise<WorkerInferOutput<TWorkflow>>;
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Infer activity function signature from worker perspective
|
|
126
|
-
* Worker receives z.input and returns z.output
|
|
127
|
-
*/
|
|
128
|
-
export type WorkerInferActivity<TActivity extends ActivityDefinition> = (
|
|
129
|
-
args: WorkerInferInput<TActivity>,
|
|
130
|
-
) => Promise<WorkerInferOutput<TActivity>>;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Infer signal handler signature from worker perspective
|
|
134
|
-
* Worker receives z.input
|
|
135
|
-
*/
|
|
136
|
-
export type WorkerInferSignal<TSignal extends SignalDefinition> = (
|
|
137
|
-
args: WorkerInferInput<TSignal>,
|
|
138
|
-
) => Promise<void>;
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Infer query handler signature from worker perspective
|
|
142
|
-
* Worker receives z.input and returns z.output
|
|
143
|
-
*/
|
|
144
|
-
export type WorkerInferQuery<TQuery extends QueryDefinition> = (
|
|
145
|
-
args: WorkerInferInput<TQuery>,
|
|
146
|
-
) => Promise<WorkerInferOutput<TQuery>>;
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Infer update handler signature from worker perspective
|
|
150
|
-
* Worker receives z.input and returns z.output
|
|
151
|
-
*/
|
|
152
|
-
export type WorkerInferUpdate<TUpdate extends UpdateDefinition> = (
|
|
153
|
-
args: WorkerInferInput<TUpdate>,
|
|
154
|
-
) => Promise<WorkerInferOutput<TUpdate>>;
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* CLIENT PERSPECTIVE
|
|
158
|
-
* Client sends z.output and receives z.input
|
|
159
|
-
*/
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Infer workflow function signature from client perspective
|
|
163
|
-
* Client sends z.output and receives z.input
|
|
164
|
-
*/
|
|
165
|
-
export type ClientInferWorkflow<TWorkflow extends WorkflowDefinition> = (
|
|
166
|
-
args: ClientInferInput<TWorkflow>,
|
|
167
|
-
) => Promise<ClientInferOutput<TWorkflow>>;
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Infer activity function signature from client perspective
|
|
171
|
-
* Client sends z.output and receives z.input
|
|
172
|
-
*/
|
|
173
|
-
export type ClientInferActivity<TActivity extends ActivityDefinition> = (
|
|
174
|
-
args: ClientInferInput<TActivity>,
|
|
175
|
-
) => Promise<ClientInferOutput<TActivity>>;
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Infer signal handler signature from client perspective
|
|
179
|
-
* Client sends z.output
|
|
180
|
-
*/
|
|
181
|
-
export type ClientInferSignal<TSignal extends SignalDefinition> = (
|
|
182
|
-
args: ClientInferInput<TSignal>,
|
|
183
|
-
) => Promise<void>;
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Infer query handler signature from client perspective
|
|
187
|
-
* Client sends z.output and receives z.input
|
|
188
|
-
*/
|
|
189
|
-
export type ClientInferQuery<TQuery extends QueryDefinition> = (
|
|
190
|
-
args: ClientInferInput<TQuery>,
|
|
191
|
-
) => Promise<ClientInferOutput<TQuery>>;
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Infer update handler signature from client perspective
|
|
195
|
-
* Client sends z.output and receives z.input
|
|
196
|
-
*/
|
|
197
|
-
export type ClientInferUpdate<TUpdate extends UpdateDefinition> = (
|
|
198
|
-
args: ClientInferInput<TUpdate>,
|
|
199
|
-
) => Promise<ClientInferOutput<TUpdate>>;
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* WORKER PERSPECTIVE - Contract-level types
|
|
203
|
-
*/
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Infer all workflows from a contract (worker perspective)
|
|
207
|
-
*/
|
|
208
|
-
export type WorkerInferWorkflows<TContract extends ContractDefinition> = {
|
|
209
|
-
[K in keyof TContract["workflows"]]: WorkerInferWorkflow<TContract["workflows"][K]>;
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Infer all activities from a contract (worker perspective)
|
|
214
|
-
*/
|
|
215
|
-
export type WorkerInferActivities<TContract extends ContractDefinition> =
|
|
216
|
-
TContract["activities"] extends Record<string, ActivityDefinition>
|
|
217
|
-
? {
|
|
218
|
-
[K in keyof TContract["activities"]]: WorkerInferActivity<TContract["activities"][K]>;
|
|
219
|
-
}
|
|
220
|
-
: {};
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Infer activities from a workflow definition (worker perspective)
|
|
224
|
-
*/
|
|
225
|
-
export type WorkerInferWorkflowActivities<T extends WorkflowDefinition> =
|
|
226
|
-
T["activities"] extends Record<string, ActivityDefinition>
|
|
227
|
-
? {
|
|
228
|
-
[K in keyof T["activities"]]: WorkerInferActivity<T["activities"][K]>;
|
|
229
|
-
}
|
|
230
|
-
: {};
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Infer signals from a workflow definition (worker perspective)
|
|
234
|
-
*/
|
|
235
|
-
export type WorkerInferWorkflowSignals<T extends WorkflowDefinition> =
|
|
236
|
-
T["signals"] extends Record<string, SignalDefinition>
|
|
237
|
-
? {
|
|
238
|
-
[K in keyof T["signals"]]: WorkerInferSignal<T["signals"][K]>;
|
|
239
|
-
}
|
|
240
|
-
: {};
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Infer queries from a workflow definition (worker perspective)
|
|
244
|
-
*/
|
|
245
|
-
export type WorkerInferWorkflowQueries<T extends WorkflowDefinition> =
|
|
246
|
-
T["queries"] extends Record<string, QueryDefinition>
|
|
247
|
-
? {
|
|
248
|
-
[K in keyof T["queries"]]: WorkerInferQuery<T["queries"][K]>;
|
|
249
|
-
}
|
|
250
|
-
: {};
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Infer updates from a workflow definition (worker perspective)
|
|
254
|
-
*/
|
|
255
|
-
export type WorkerInferWorkflowUpdates<T extends WorkflowDefinition> =
|
|
256
|
-
T["updates"] extends Record<string, UpdateDefinition>
|
|
257
|
-
? {
|
|
258
|
-
[K in keyof T["updates"]]: WorkerInferUpdate<T["updates"][K]>;
|
|
259
|
-
}
|
|
260
|
-
: {};
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Infer all activities available in a workflow context (worker perspective)
|
|
264
|
-
* Combines workflow-specific activities with global activities
|
|
265
|
-
*/
|
|
266
|
-
export type WorkerInferWorkflowContextActivities<
|
|
267
|
-
TContract extends ContractDefinition,
|
|
268
|
-
TWorkflowName extends keyof TContract["workflows"],
|
|
269
|
-
> = WorkerInferWorkflowActivities<TContract["workflows"][TWorkflowName]> &
|
|
270
|
-
WorkerInferActivities<TContract>;
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* CLIENT PERSPECTIVE - Contract-level types
|
|
274
|
-
*/
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Infer all workflows from a contract (client perspective)
|
|
278
|
-
*/
|
|
279
|
-
export type ClientInferWorkflows<TContract extends ContractDefinition> = {
|
|
280
|
-
[K in keyof TContract["workflows"]]: ClientInferWorkflow<TContract["workflows"][K]>;
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Infer all activities from a contract (client perspective)
|
|
285
|
-
*/
|
|
286
|
-
export type ClientInferActivities<TContract extends ContractDefinition> =
|
|
287
|
-
TContract["activities"] extends Record<string, ActivityDefinition>
|
|
288
|
-
? {
|
|
289
|
-
[K in keyof TContract["activities"]]: ClientInferActivity<TContract["activities"][K]>;
|
|
290
|
-
}
|
|
291
|
-
: {};
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Infer activities from a workflow definition (client perspective)
|
|
295
|
-
*/
|
|
296
|
-
export type ClientInferWorkflowActivities<T extends WorkflowDefinition> =
|
|
297
|
-
T["activities"] extends Record<string, ActivityDefinition>
|
|
298
|
-
? {
|
|
299
|
-
[K in keyof T["activities"]]: ClientInferActivity<T["activities"][K]>;
|
|
300
|
-
}
|
|
301
|
-
: {};
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Infer signals from a workflow definition (client perspective)
|
|
305
|
-
*/
|
|
306
|
-
export type ClientInferWorkflowSignals<T extends WorkflowDefinition> =
|
|
307
|
-
T["signals"] extends Record<string, SignalDefinition>
|
|
308
|
-
? {
|
|
309
|
-
[K in keyof T["signals"]]: ClientInferSignal<T["signals"][K]>;
|
|
310
|
-
}
|
|
311
|
-
: {};
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Infer queries from a workflow definition (client perspective)
|
|
315
|
-
*/
|
|
316
|
-
export type ClientInferWorkflowQueries<T extends WorkflowDefinition> =
|
|
317
|
-
T["queries"] extends Record<string, QueryDefinition>
|
|
318
|
-
? {
|
|
319
|
-
[K in keyof T["queries"]]: ClientInferQuery<T["queries"][K]>;
|
|
320
|
-
}
|
|
321
|
-
: {};
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Infer updates from a workflow definition (client perspective)
|
|
325
|
-
*/
|
|
326
|
-
export type ClientInferWorkflowUpdates<T extends WorkflowDefinition> =
|
|
327
|
-
T["updates"] extends Record<string, UpdateDefinition>
|
|
328
|
-
? {
|
|
329
|
-
[K in keyof T["updates"]]: ClientInferUpdate<T["updates"][K]>;
|
|
330
|
-
}
|
|
331
|
-
: {};
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Infer all activities available in a workflow context (client perspective)
|
|
335
|
-
* Combines workflow-specific activities with global activities
|
|
336
|
-
*/
|
|
337
|
-
export type ClientInferWorkflowContextActivities<
|
|
338
|
-
TContract extends ContractDefinition,
|
|
339
|
-
TWorkflowName extends keyof TContract["workflows"],
|
|
340
|
-
> = ClientInferWorkflowActivities<TContract["workflows"][TWorkflowName]> &
|
|
341
|
-
ClientInferActivities<TContract>;
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* UTILITY TYPES FOR ACTIVITY HANDLERS
|
|
345
|
-
*/
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Extract workflow names from a contract as a union type
|
|
349
|
-
*
|
|
350
|
-
* @example
|
|
351
|
-
* ```typescript
|
|
352
|
-
* type MyWorkflowNames = InferWorkflowNames<typeof myContract>;
|
|
353
|
-
* // "processOrder" | "sendNotification"
|
|
354
|
-
* ```
|
|
355
|
-
*/
|
|
356
|
-
export type InferWorkflowNames<TContract extends ContractDefinition> =
|
|
357
|
-
keyof TContract["workflows"] & string;
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Extract activity names from a contract (global activities) as a union type
|
|
361
|
-
*
|
|
362
|
-
* @example
|
|
363
|
-
* ```typescript
|
|
364
|
-
* type MyActivityNames = InferActivityNames<typeof myContract>;
|
|
365
|
-
* // "log" | "sendEmail"
|
|
366
|
-
* ```
|
|
367
|
-
*/
|
|
368
|
-
export type InferActivityNames<TContract extends ContractDefinition> =
|
|
369
|
-
TContract["activities"] extends Record<string, ActivityDefinition>
|
|
370
|
-
? keyof TContract["activities"] & string
|
|
371
|
-
: never;
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Extract all workflows from a contract with their definitions
|
|
375
|
-
*
|
|
376
|
-
* @example
|
|
377
|
-
* ```typescript
|
|
378
|
-
* type MyWorkflows = InferContractWorkflows<typeof myContract>;
|
|
379
|
-
* ```
|
|
380
|
-
*/
|
|
381
|
-
export type InferContractWorkflows<TContract extends ContractDefinition> = TContract["workflows"];
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Infer the handler type for a global activity from a contract
|
|
385
|
-
*
|
|
386
|
-
* @example
|
|
387
|
-
* ```typescript
|
|
388
|
-
* const log: ActivityHandler<typeof myContract, "log"> = async ({ level, message }) => {
|
|
389
|
-
* logger[level](message);
|
|
390
|
-
* };
|
|
391
|
-
* ```
|
|
392
|
-
*/
|
|
393
|
-
export type ActivityHandler<
|
|
394
|
-
TContract extends ContractDefinition,
|
|
395
|
-
TActivityName extends keyof TContract["activities"],
|
|
396
|
-
> =
|
|
397
|
-
TContract["activities"] extends Record<string, ActivityDefinition>
|
|
398
|
-
? (
|
|
399
|
-
args: WorkerInferInput<TContract["activities"][TActivityName]>,
|
|
400
|
-
) => Promise<WorkerInferOutput<TContract["activities"][TActivityName]>>
|
|
401
|
-
: never;
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* Infer the handler type for a workflow-specific activity from a contract
|
|
405
|
-
*
|
|
406
|
-
* @example
|
|
407
|
-
* ```typescript
|
|
408
|
-
* const processPayment: WorkflowActivityHandler<
|
|
409
|
-
* typeof myContract,
|
|
410
|
-
* "processOrder",
|
|
411
|
-
* "processPayment"
|
|
412
|
-
* > = async ({ customerId, amount }) => {
|
|
413
|
-
* // Implementation
|
|
414
|
-
* return { transactionId, status: "success" as const, paidAmount: amount };
|
|
415
|
-
* };
|
|
416
|
-
* ```
|
|
417
|
-
*/
|
|
418
|
-
export type WorkflowActivityHandler<
|
|
419
|
-
TContract extends ContractDefinition,
|
|
420
|
-
TWorkflowName extends keyof TContract["workflows"],
|
|
421
|
-
TActivityName extends keyof TContract["workflows"][TWorkflowName]["activities"],
|
|
422
|
-
> =
|
|
423
|
-
TContract["workflows"][TWorkflowName]["activities"] extends Record<string, ActivityDefinition>
|
|
424
|
-
? (
|
|
425
|
-
args: WorkerInferInput<TContract["workflows"][TWorkflowName]["activities"][TActivityName]>,
|
|
426
|
-
) => Promise<
|
|
427
|
-
WorkerInferOutput<TContract["workflows"][TWorkflowName]["activities"][TActivityName]>
|
|
428
|
-
>
|
|
429
|
-
: never;
|
package/tsconfig.json
DELETED
package/vitest.config.ts
DELETED