@temporal-contract/worker 0.0.1 → 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/README.md +14 -93
- package/dist/activity.cjs +1 -1
- package/dist/activity.d.cts +1 -1
- package/dist/activity.d.mts +1 -1
- package/dist/activity.mjs +1 -1
- package/dist/{errors-CqX81ysy.d.cts → errors-B50uht6a.d.cts} +19 -19
- package/dist/{errors-oc-Iiwmu.d.mts → errors-DgUMRes-.d.mts} +19 -19
- package/dist/{handler-aA2RFdV7.mjs → handler-BP9xAycT.mjs} +73 -106
- package/dist/{handler-B3KY0uDx.cjs → handler-Cc951VQp.cjs} +73 -106
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.d.cts +1 -1
- package/dist/workflow.d.mts +1 -1
- package/dist/workflow.mjs +1 -1
- package/package.json +9 -5
- package/.turbo/turbo-build.log +0 -25
- package/src/activity.ts +0 -15
- package/src/errors.ts +0 -164
- package/src/handler.spec.ts +0 -525
- package/src/handler.ts +0 -621
- package/src/workflow.ts +0 -20
- package/tsconfig.json +0 -9
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { defineQuery, defineSignal, defineUpdate, proxyActivities, setHandler, workflowInfo } from "@temporalio/workflow";
|
|
2
|
-
import { ZodError } from "zod";
|
|
3
2
|
|
|
4
3
|
//#region src/errors.ts
|
|
5
4
|
/**
|
|
@@ -38,10 +37,11 @@ var ActivityDefinitionNotFoundError = class extends WorkerError {
|
|
|
38
37
|
* Error thrown when activity input validation fails
|
|
39
38
|
*/
|
|
40
39
|
var ActivityInputValidationError = class extends WorkerError {
|
|
41
|
-
constructor(activityName,
|
|
42
|
-
|
|
40
|
+
constructor(activityName, issues) {
|
|
41
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
42
|
+
super(`Activity "${activityName}" input validation failed: ${message}`);
|
|
43
43
|
this.activityName = activityName;
|
|
44
|
-
this.
|
|
44
|
+
this.issues = issues;
|
|
45
45
|
this.name = "ActivityInputValidationError";
|
|
46
46
|
}
|
|
47
47
|
};
|
|
@@ -49,10 +49,11 @@ var ActivityInputValidationError = class extends WorkerError {
|
|
|
49
49
|
* Error thrown when activity output validation fails
|
|
50
50
|
*/
|
|
51
51
|
var ActivityOutputValidationError = class extends WorkerError {
|
|
52
|
-
constructor(activityName,
|
|
53
|
-
|
|
52
|
+
constructor(activityName, issues) {
|
|
53
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
54
|
+
super(`Activity "${activityName}" output validation failed: ${message}`);
|
|
54
55
|
this.activityName = activityName;
|
|
55
|
-
this.
|
|
56
|
+
this.issues = issues;
|
|
56
57
|
this.name = "ActivityOutputValidationError";
|
|
57
58
|
}
|
|
58
59
|
};
|
|
@@ -60,10 +61,11 @@ var ActivityOutputValidationError = class extends WorkerError {
|
|
|
60
61
|
* Error thrown when workflow input validation fails
|
|
61
62
|
*/
|
|
62
63
|
var WorkflowInputValidationError = class extends WorkerError {
|
|
63
|
-
constructor(workflowName,
|
|
64
|
-
|
|
64
|
+
constructor(workflowName, issues) {
|
|
65
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
66
|
+
super(`Workflow "${workflowName}" input validation failed: ${message}`);
|
|
65
67
|
this.workflowName = workflowName;
|
|
66
|
-
this.
|
|
68
|
+
this.issues = issues;
|
|
67
69
|
this.name = "WorkflowInputValidationError";
|
|
68
70
|
}
|
|
69
71
|
};
|
|
@@ -71,10 +73,11 @@ var WorkflowInputValidationError = class extends WorkerError {
|
|
|
71
73
|
* Error thrown when workflow output validation fails
|
|
72
74
|
*/
|
|
73
75
|
var WorkflowOutputValidationError = class extends WorkerError {
|
|
74
|
-
constructor(workflowName,
|
|
75
|
-
|
|
76
|
+
constructor(workflowName, issues) {
|
|
77
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
78
|
+
super(`Workflow "${workflowName}" output validation failed: ${message}`);
|
|
76
79
|
this.workflowName = workflowName;
|
|
77
|
-
this.
|
|
80
|
+
this.issues = issues;
|
|
78
81
|
this.name = "WorkflowOutputValidationError";
|
|
79
82
|
}
|
|
80
83
|
};
|
|
@@ -82,10 +85,11 @@ var WorkflowOutputValidationError = class extends WorkerError {
|
|
|
82
85
|
* Error thrown when signal input validation fails
|
|
83
86
|
*/
|
|
84
87
|
var SignalInputValidationError = class extends WorkerError {
|
|
85
|
-
constructor(signalName,
|
|
86
|
-
|
|
88
|
+
constructor(signalName, issues) {
|
|
89
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
90
|
+
super(`Signal "${signalName}" input validation failed: ${message}`);
|
|
87
91
|
this.signalName = signalName;
|
|
88
|
-
this.
|
|
92
|
+
this.issues = issues;
|
|
89
93
|
this.name = "SignalInputValidationError";
|
|
90
94
|
}
|
|
91
95
|
};
|
|
@@ -93,10 +97,11 @@ var SignalInputValidationError = class extends WorkerError {
|
|
|
93
97
|
* Error thrown when query input validation fails
|
|
94
98
|
*/
|
|
95
99
|
var QueryInputValidationError = class extends WorkerError {
|
|
96
|
-
constructor(queryName,
|
|
97
|
-
|
|
100
|
+
constructor(queryName, issues) {
|
|
101
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
102
|
+
super(`Query "${queryName}" input validation failed: ${message}`);
|
|
98
103
|
this.queryName = queryName;
|
|
99
|
-
this.
|
|
104
|
+
this.issues = issues;
|
|
100
105
|
this.name = "QueryInputValidationError";
|
|
101
106
|
}
|
|
102
107
|
};
|
|
@@ -104,10 +109,11 @@ var QueryInputValidationError = class extends WorkerError {
|
|
|
104
109
|
* Error thrown when query output validation fails
|
|
105
110
|
*/
|
|
106
111
|
var QueryOutputValidationError = class extends WorkerError {
|
|
107
|
-
constructor(queryName,
|
|
108
|
-
|
|
112
|
+
constructor(queryName, issues) {
|
|
113
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
114
|
+
super(`Query "${queryName}" output validation failed: ${message}`);
|
|
109
115
|
this.queryName = queryName;
|
|
110
|
-
this.
|
|
116
|
+
this.issues = issues;
|
|
111
117
|
this.name = "QueryOutputValidationError";
|
|
112
118
|
}
|
|
113
119
|
};
|
|
@@ -115,10 +121,11 @@ var QueryOutputValidationError = class extends WorkerError {
|
|
|
115
121
|
* Error thrown when update input validation fails
|
|
116
122
|
*/
|
|
117
123
|
var UpdateInputValidationError = class extends WorkerError {
|
|
118
|
-
constructor(updateName,
|
|
119
|
-
|
|
124
|
+
constructor(updateName, issues) {
|
|
125
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
126
|
+
super(`Update "${updateName}" input validation failed: ${message}`);
|
|
120
127
|
this.updateName = updateName;
|
|
121
|
-
this.
|
|
128
|
+
this.issues = issues;
|
|
122
129
|
this.name = "UpdateInputValidationError";
|
|
123
130
|
}
|
|
124
131
|
};
|
|
@@ -126,10 +133,11 @@ var UpdateInputValidationError = class extends WorkerError {
|
|
|
126
133
|
* Error thrown when update output validation fails
|
|
127
134
|
*/
|
|
128
135
|
var UpdateOutputValidationError = class extends WorkerError {
|
|
129
|
-
constructor(updateName,
|
|
130
|
-
|
|
136
|
+
constructor(updateName, issues) {
|
|
137
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
138
|
+
super(`Update "${updateName}" output validation failed: ${message}`);
|
|
131
139
|
this.updateName = updateName;
|
|
132
|
-
this.
|
|
140
|
+
this.issues = issues;
|
|
133
141
|
this.name = "UpdateOutputValidationError";
|
|
134
142
|
}
|
|
135
143
|
};
|
|
@@ -151,22 +159,15 @@ function createValidatedActivities(rawActivities, workflowActivitiesDefinition,
|
|
|
151
159
|
for (const [activityName, activityDef] of Object.entries(allActivitiesDefinition)) {
|
|
152
160
|
const rawActivity = rawActivities[activityName];
|
|
153
161
|
if (!rawActivity) throw new ActivityImplementationNotFoundError(activityName, Object.keys(rawActivities));
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
const result = await rawActivity(validatedInput);
|
|
163
|
-
try {
|
|
164
|
-
return activityDef.output.parse(result);
|
|
165
|
-
} catch (error) {
|
|
166
|
-
if (error instanceof ZodError) throw new ActivityOutputValidationError(activityName, error);
|
|
167
|
-
throw error;
|
|
168
|
-
}
|
|
162
|
+
const wrappedActivity = async (input) => {
|
|
163
|
+
const inputResult = await activityDef.input["~standard"].validate(input);
|
|
164
|
+
if (inputResult.issues) throw new ActivityInputValidationError(activityName, inputResult.issues);
|
|
165
|
+
const result = await rawActivity(inputResult.value);
|
|
166
|
+
const outputResult = await activityDef.output["~standard"].validate(result);
|
|
167
|
+
if (outputResult.issues) throw new ActivityOutputValidationError(activityName, outputResult.issues);
|
|
168
|
+
return outputResult.value;
|
|
169
169
|
};
|
|
170
|
+
validatedActivities[activityName] = wrappedActivity;
|
|
170
171
|
}
|
|
171
172
|
return validatedActivities;
|
|
172
173
|
}
|
|
@@ -224,20 +225,12 @@ function declareActivitiesHandler(options) {
|
|
|
224
225
|
}
|
|
225
226
|
if (!activityDef) throw new ActivityDefinitionNotFoundError(activityName, allDefinitions);
|
|
226
227
|
wrappedActivities[activityName] = async (input) => {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
const result = await activityImpl(validatedInput);
|
|
235
|
-
try {
|
|
236
|
-
return activityDef.output.parse(result);
|
|
237
|
-
} catch (error) {
|
|
238
|
-
if (error instanceof ZodError) throw new ActivityOutputValidationError(activityName, error);
|
|
239
|
-
throw error;
|
|
240
|
-
}
|
|
228
|
+
const inputResult = await activityDef.input["~standard"].validate(input);
|
|
229
|
+
if (inputResult.issues) throw new ActivityInputValidationError(activityName, inputResult.issues);
|
|
230
|
+
const result = await activityImpl(inputResult.value);
|
|
231
|
+
const outputResult = await activityDef.output["~standard"].validate(result);
|
|
232
|
+
if (outputResult.issues) throw new ActivityOutputValidationError(activityName, outputResult.issues);
|
|
233
|
+
return outputResult.value;
|
|
241
234
|
};
|
|
242
235
|
}
|
|
243
236
|
return {
|
|
@@ -314,13 +307,9 @@ function declareWorkflow(options) {
|
|
|
314
307
|
const definition = contract.workflows[workflowName];
|
|
315
308
|
return async (args) => {
|
|
316
309
|
const singleArg = Array.isArray(args) ? args[0] : args;
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
} catch (error) {
|
|
321
|
-
if (error instanceof ZodError) throw new WorkflowInputValidationError(String(workflowName), error);
|
|
322
|
-
throw error;
|
|
323
|
-
}
|
|
310
|
+
const inputResult = await definition.input["~standard"].validate(singleArg);
|
|
311
|
+
if (inputResult.issues) throw new WorkflowInputValidationError(String(workflowName), inputResult.issues);
|
|
312
|
+
const validatedInput = inputResult.value;
|
|
324
313
|
if (definition.signals && signals) {
|
|
325
314
|
const signalDefs = definition.signals;
|
|
326
315
|
const signalHandlers = signals;
|
|
@@ -328,14 +317,9 @@ function declareWorkflow(options) {
|
|
|
328
317
|
const handler = signalHandlers[signalName];
|
|
329
318
|
if (handler) setHandler(defineSignal(signalName), async (...args$1) => {
|
|
330
319
|
const input = args$1.length === 1 ? args$1[0] : args$1;
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
} catch (error) {
|
|
335
|
-
if (error instanceof ZodError) throw new SignalInputValidationError(signalName, error);
|
|
336
|
-
throw error;
|
|
337
|
-
}
|
|
338
|
-
await handler(validatedInput$1);
|
|
320
|
+
const inputResult$1 = await signalDef.input["~standard"].validate(input);
|
|
321
|
+
if (inputResult$1.issues) throw new SignalInputValidationError(signalName, inputResult$1.issues);
|
|
322
|
+
await handler(inputResult$1.value);
|
|
339
323
|
});
|
|
340
324
|
}
|
|
341
325
|
}
|
|
@@ -346,20 +330,14 @@ function declareWorkflow(options) {
|
|
|
346
330
|
const handler = queryHandlers[queryName];
|
|
347
331
|
if (handler) setHandler(defineQuery(queryName), (...args$1) => {
|
|
348
332
|
const input = args$1.length === 1 ? args$1[0] : args$1;
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
try {
|
|
358
|
-
return queryDef.output.parse(result$1);
|
|
359
|
-
} catch (error) {
|
|
360
|
-
if (error instanceof ZodError) throw new QueryOutputValidationError(queryName, error);
|
|
361
|
-
throw error;
|
|
362
|
-
}
|
|
333
|
+
const inputResult$1 = queryDef.input["~standard"].validate(input);
|
|
334
|
+
if (inputResult$1 instanceof Promise) throw new Error(`Query "${queryName}" validation must be synchronous. Use a schema library that supports synchronous validation for queries.`);
|
|
335
|
+
if (inputResult$1.issues) throw new QueryInputValidationError(queryName, inputResult$1.issues);
|
|
336
|
+
const result$1 = handler(inputResult$1.value);
|
|
337
|
+
const outputResult$1 = queryDef.output["~standard"].validate(result$1);
|
|
338
|
+
if (outputResult$1 instanceof Promise) throw new Error(`Query "${queryName}" output validation must be synchronous. Use a schema library that supports synchronous validation for queries.`);
|
|
339
|
+
if (outputResult$1.issues) throw new QueryOutputValidationError(queryName, outputResult$1.issues);
|
|
340
|
+
return outputResult$1.value;
|
|
363
341
|
});
|
|
364
342
|
}
|
|
365
343
|
}
|
|
@@ -370,20 +348,12 @@ function declareWorkflow(options) {
|
|
|
370
348
|
const handler = updateHandlers[updateName];
|
|
371
349
|
if (handler) setHandler(defineUpdate(updateName), async (...args$1) => {
|
|
372
350
|
const input = args$1.length === 1 ? args$1[0] : args$1;
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
const result$1 = await handler(validatedInput$1);
|
|
381
|
-
try {
|
|
382
|
-
return updateDef.output.parse(result$1);
|
|
383
|
-
} catch (error) {
|
|
384
|
-
if (error instanceof ZodError) throw new UpdateOutputValidationError(updateName, error);
|
|
385
|
-
throw error;
|
|
386
|
-
}
|
|
351
|
+
const inputResult$1 = await updateDef.input["~standard"].validate(input);
|
|
352
|
+
if (inputResult$1.issues) throw new UpdateInputValidationError(updateName, inputResult$1.issues);
|
|
353
|
+
const result$1 = await handler(inputResult$1.value);
|
|
354
|
+
const outputResult$1 = await updateDef.output["~standard"].validate(result$1);
|
|
355
|
+
if (outputResult$1.issues) throw new UpdateOutputValidationError(updateName, outputResult$1.issues);
|
|
356
|
+
return outputResult$1.value;
|
|
387
357
|
});
|
|
388
358
|
}
|
|
389
359
|
}
|
|
@@ -396,12 +366,9 @@ function declareWorkflow(options) {
|
|
|
396
366
|
activities: contextActivities,
|
|
397
367
|
info: workflowInfo()
|
|
398
368
|
}, validatedInput);
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
if (error instanceof ZodError) throw new WorkflowOutputValidationError(String(workflowName), error);
|
|
403
|
-
throw error;
|
|
404
|
-
}
|
|
369
|
+
const outputResult = await definition.output["~standard"].validate(result);
|
|
370
|
+
if (outputResult.issues) throw new WorkflowOutputValidationError(String(workflowName), outputResult.issues);
|
|
371
|
+
return outputResult.value;
|
|
405
372
|
};
|
|
406
373
|
}
|
|
407
374
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
let __temporalio_workflow = require("@temporalio/workflow");
|
|
2
|
-
let zod = require("zod");
|
|
3
2
|
|
|
4
3
|
//#region src/errors.ts
|
|
5
4
|
/**
|
|
@@ -38,10 +37,11 @@ var ActivityDefinitionNotFoundError = class extends WorkerError {
|
|
|
38
37
|
* Error thrown when activity input validation fails
|
|
39
38
|
*/
|
|
40
39
|
var ActivityInputValidationError = class extends WorkerError {
|
|
41
|
-
constructor(activityName,
|
|
42
|
-
|
|
40
|
+
constructor(activityName, issues) {
|
|
41
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
42
|
+
super(`Activity "${activityName}" input validation failed: ${message}`);
|
|
43
43
|
this.activityName = activityName;
|
|
44
|
-
this.
|
|
44
|
+
this.issues = issues;
|
|
45
45
|
this.name = "ActivityInputValidationError";
|
|
46
46
|
}
|
|
47
47
|
};
|
|
@@ -49,10 +49,11 @@ var ActivityInputValidationError = class extends WorkerError {
|
|
|
49
49
|
* Error thrown when activity output validation fails
|
|
50
50
|
*/
|
|
51
51
|
var ActivityOutputValidationError = class extends WorkerError {
|
|
52
|
-
constructor(activityName,
|
|
53
|
-
|
|
52
|
+
constructor(activityName, issues) {
|
|
53
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
54
|
+
super(`Activity "${activityName}" output validation failed: ${message}`);
|
|
54
55
|
this.activityName = activityName;
|
|
55
|
-
this.
|
|
56
|
+
this.issues = issues;
|
|
56
57
|
this.name = "ActivityOutputValidationError";
|
|
57
58
|
}
|
|
58
59
|
};
|
|
@@ -60,10 +61,11 @@ var ActivityOutputValidationError = class extends WorkerError {
|
|
|
60
61
|
* Error thrown when workflow input validation fails
|
|
61
62
|
*/
|
|
62
63
|
var WorkflowInputValidationError = class extends WorkerError {
|
|
63
|
-
constructor(workflowName,
|
|
64
|
-
|
|
64
|
+
constructor(workflowName, issues) {
|
|
65
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
66
|
+
super(`Workflow "${workflowName}" input validation failed: ${message}`);
|
|
65
67
|
this.workflowName = workflowName;
|
|
66
|
-
this.
|
|
68
|
+
this.issues = issues;
|
|
67
69
|
this.name = "WorkflowInputValidationError";
|
|
68
70
|
}
|
|
69
71
|
};
|
|
@@ -71,10 +73,11 @@ var WorkflowInputValidationError = class extends WorkerError {
|
|
|
71
73
|
* Error thrown when workflow output validation fails
|
|
72
74
|
*/
|
|
73
75
|
var WorkflowOutputValidationError = class extends WorkerError {
|
|
74
|
-
constructor(workflowName,
|
|
75
|
-
|
|
76
|
+
constructor(workflowName, issues) {
|
|
77
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
78
|
+
super(`Workflow "${workflowName}" output validation failed: ${message}`);
|
|
76
79
|
this.workflowName = workflowName;
|
|
77
|
-
this.
|
|
80
|
+
this.issues = issues;
|
|
78
81
|
this.name = "WorkflowOutputValidationError";
|
|
79
82
|
}
|
|
80
83
|
};
|
|
@@ -82,10 +85,11 @@ var WorkflowOutputValidationError = class extends WorkerError {
|
|
|
82
85
|
* Error thrown when signal input validation fails
|
|
83
86
|
*/
|
|
84
87
|
var SignalInputValidationError = class extends WorkerError {
|
|
85
|
-
constructor(signalName,
|
|
86
|
-
|
|
88
|
+
constructor(signalName, issues) {
|
|
89
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
90
|
+
super(`Signal "${signalName}" input validation failed: ${message}`);
|
|
87
91
|
this.signalName = signalName;
|
|
88
|
-
this.
|
|
92
|
+
this.issues = issues;
|
|
89
93
|
this.name = "SignalInputValidationError";
|
|
90
94
|
}
|
|
91
95
|
};
|
|
@@ -93,10 +97,11 @@ var SignalInputValidationError = class extends WorkerError {
|
|
|
93
97
|
* Error thrown when query input validation fails
|
|
94
98
|
*/
|
|
95
99
|
var QueryInputValidationError = class extends WorkerError {
|
|
96
|
-
constructor(queryName,
|
|
97
|
-
|
|
100
|
+
constructor(queryName, issues) {
|
|
101
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
102
|
+
super(`Query "${queryName}" input validation failed: ${message}`);
|
|
98
103
|
this.queryName = queryName;
|
|
99
|
-
this.
|
|
104
|
+
this.issues = issues;
|
|
100
105
|
this.name = "QueryInputValidationError";
|
|
101
106
|
}
|
|
102
107
|
};
|
|
@@ -104,10 +109,11 @@ var QueryInputValidationError = class extends WorkerError {
|
|
|
104
109
|
* Error thrown when query output validation fails
|
|
105
110
|
*/
|
|
106
111
|
var QueryOutputValidationError = class extends WorkerError {
|
|
107
|
-
constructor(queryName,
|
|
108
|
-
|
|
112
|
+
constructor(queryName, issues) {
|
|
113
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
114
|
+
super(`Query "${queryName}" output validation failed: ${message}`);
|
|
109
115
|
this.queryName = queryName;
|
|
110
|
-
this.
|
|
116
|
+
this.issues = issues;
|
|
111
117
|
this.name = "QueryOutputValidationError";
|
|
112
118
|
}
|
|
113
119
|
};
|
|
@@ -115,10 +121,11 @@ var QueryOutputValidationError = class extends WorkerError {
|
|
|
115
121
|
* Error thrown when update input validation fails
|
|
116
122
|
*/
|
|
117
123
|
var UpdateInputValidationError = class extends WorkerError {
|
|
118
|
-
constructor(updateName,
|
|
119
|
-
|
|
124
|
+
constructor(updateName, issues) {
|
|
125
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
126
|
+
super(`Update "${updateName}" input validation failed: ${message}`);
|
|
120
127
|
this.updateName = updateName;
|
|
121
|
-
this.
|
|
128
|
+
this.issues = issues;
|
|
122
129
|
this.name = "UpdateInputValidationError";
|
|
123
130
|
}
|
|
124
131
|
};
|
|
@@ -126,10 +133,11 @@ var UpdateInputValidationError = class extends WorkerError {
|
|
|
126
133
|
* Error thrown when update output validation fails
|
|
127
134
|
*/
|
|
128
135
|
var UpdateOutputValidationError = class extends WorkerError {
|
|
129
|
-
constructor(updateName,
|
|
130
|
-
|
|
136
|
+
constructor(updateName, issues) {
|
|
137
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
138
|
+
super(`Update "${updateName}" output validation failed: ${message}`);
|
|
131
139
|
this.updateName = updateName;
|
|
132
|
-
this.
|
|
140
|
+
this.issues = issues;
|
|
133
141
|
this.name = "UpdateOutputValidationError";
|
|
134
142
|
}
|
|
135
143
|
};
|
|
@@ -151,22 +159,15 @@ function createValidatedActivities(rawActivities, workflowActivitiesDefinition,
|
|
|
151
159
|
for (const [activityName, activityDef] of Object.entries(allActivitiesDefinition)) {
|
|
152
160
|
const rawActivity = rawActivities[activityName];
|
|
153
161
|
if (!rawActivity) throw new ActivityImplementationNotFoundError(activityName, Object.keys(rawActivities));
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
const result = await rawActivity(validatedInput);
|
|
163
|
-
try {
|
|
164
|
-
return activityDef.output.parse(result);
|
|
165
|
-
} catch (error) {
|
|
166
|
-
if (error instanceof zod.ZodError) throw new ActivityOutputValidationError(activityName, error);
|
|
167
|
-
throw error;
|
|
168
|
-
}
|
|
162
|
+
const wrappedActivity = async (input) => {
|
|
163
|
+
const inputResult = await activityDef.input["~standard"].validate(input);
|
|
164
|
+
if (inputResult.issues) throw new ActivityInputValidationError(activityName, inputResult.issues);
|
|
165
|
+
const result = await rawActivity(inputResult.value);
|
|
166
|
+
const outputResult = await activityDef.output["~standard"].validate(result);
|
|
167
|
+
if (outputResult.issues) throw new ActivityOutputValidationError(activityName, outputResult.issues);
|
|
168
|
+
return outputResult.value;
|
|
169
169
|
};
|
|
170
|
+
validatedActivities[activityName] = wrappedActivity;
|
|
170
171
|
}
|
|
171
172
|
return validatedActivities;
|
|
172
173
|
}
|
|
@@ -224,20 +225,12 @@ function declareActivitiesHandler(options) {
|
|
|
224
225
|
}
|
|
225
226
|
if (!activityDef) throw new ActivityDefinitionNotFoundError(activityName, allDefinitions);
|
|
226
227
|
wrappedActivities[activityName] = async (input) => {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
const result = await activityImpl(validatedInput);
|
|
235
|
-
try {
|
|
236
|
-
return activityDef.output.parse(result);
|
|
237
|
-
} catch (error) {
|
|
238
|
-
if (error instanceof zod.ZodError) throw new ActivityOutputValidationError(activityName, error);
|
|
239
|
-
throw error;
|
|
240
|
-
}
|
|
228
|
+
const inputResult = await activityDef.input["~standard"].validate(input);
|
|
229
|
+
if (inputResult.issues) throw new ActivityInputValidationError(activityName, inputResult.issues);
|
|
230
|
+
const result = await activityImpl(inputResult.value);
|
|
231
|
+
const outputResult = await activityDef.output["~standard"].validate(result);
|
|
232
|
+
if (outputResult.issues) throw new ActivityOutputValidationError(activityName, outputResult.issues);
|
|
233
|
+
return outputResult.value;
|
|
241
234
|
};
|
|
242
235
|
}
|
|
243
236
|
return {
|
|
@@ -314,13 +307,9 @@ function declareWorkflow(options) {
|
|
|
314
307
|
const definition = contract.workflows[workflowName];
|
|
315
308
|
return async (args) => {
|
|
316
309
|
const singleArg = Array.isArray(args) ? args[0] : args;
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
} catch (error) {
|
|
321
|
-
if (error instanceof zod.ZodError) throw new WorkflowInputValidationError(String(workflowName), error);
|
|
322
|
-
throw error;
|
|
323
|
-
}
|
|
310
|
+
const inputResult = await definition.input["~standard"].validate(singleArg);
|
|
311
|
+
if (inputResult.issues) throw new WorkflowInputValidationError(String(workflowName), inputResult.issues);
|
|
312
|
+
const validatedInput = inputResult.value;
|
|
324
313
|
if (definition.signals && signals) {
|
|
325
314
|
const signalDefs = definition.signals;
|
|
326
315
|
const signalHandlers = signals;
|
|
@@ -328,14 +317,9 @@ function declareWorkflow(options) {
|
|
|
328
317
|
const handler = signalHandlers[signalName];
|
|
329
318
|
if (handler) (0, __temporalio_workflow.setHandler)((0, __temporalio_workflow.defineSignal)(signalName), async (...args$1) => {
|
|
330
319
|
const input = args$1.length === 1 ? args$1[0] : args$1;
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
} catch (error) {
|
|
335
|
-
if (error instanceof zod.ZodError) throw new SignalInputValidationError(signalName, error);
|
|
336
|
-
throw error;
|
|
337
|
-
}
|
|
338
|
-
await handler(validatedInput$1);
|
|
320
|
+
const inputResult$1 = await signalDef.input["~standard"].validate(input);
|
|
321
|
+
if (inputResult$1.issues) throw new SignalInputValidationError(signalName, inputResult$1.issues);
|
|
322
|
+
await handler(inputResult$1.value);
|
|
339
323
|
});
|
|
340
324
|
}
|
|
341
325
|
}
|
|
@@ -346,20 +330,14 @@ function declareWorkflow(options) {
|
|
|
346
330
|
const handler = queryHandlers[queryName];
|
|
347
331
|
if (handler) (0, __temporalio_workflow.setHandler)((0, __temporalio_workflow.defineQuery)(queryName), (...args$1) => {
|
|
348
332
|
const input = args$1.length === 1 ? args$1[0] : args$1;
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
try {
|
|
358
|
-
return queryDef.output.parse(result$1);
|
|
359
|
-
} catch (error) {
|
|
360
|
-
if (error instanceof zod.ZodError) throw new QueryOutputValidationError(queryName, error);
|
|
361
|
-
throw error;
|
|
362
|
-
}
|
|
333
|
+
const inputResult$1 = queryDef.input["~standard"].validate(input);
|
|
334
|
+
if (inputResult$1 instanceof Promise) throw new Error(`Query "${queryName}" validation must be synchronous. Use a schema library that supports synchronous validation for queries.`);
|
|
335
|
+
if (inputResult$1.issues) throw new QueryInputValidationError(queryName, inputResult$1.issues);
|
|
336
|
+
const result$1 = handler(inputResult$1.value);
|
|
337
|
+
const outputResult$1 = queryDef.output["~standard"].validate(result$1);
|
|
338
|
+
if (outputResult$1 instanceof Promise) throw new Error(`Query "${queryName}" output validation must be synchronous. Use a schema library that supports synchronous validation for queries.`);
|
|
339
|
+
if (outputResult$1.issues) throw new QueryOutputValidationError(queryName, outputResult$1.issues);
|
|
340
|
+
return outputResult$1.value;
|
|
363
341
|
});
|
|
364
342
|
}
|
|
365
343
|
}
|
|
@@ -370,20 +348,12 @@ function declareWorkflow(options) {
|
|
|
370
348
|
const handler = updateHandlers[updateName];
|
|
371
349
|
if (handler) (0, __temporalio_workflow.setHandler)((0, __temporalio_workflow.defineUpdate)(updateName), async (...args$1) => {
|
|
372
350
|
const input = args$1.length === 1 ? args$1[0] : args$1;
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
const result$1 = await handler(validatedInput$1);
|
|
381
|
-
try {
|
|
382
|
-
return updateDef.output.parse(result$1);
|
|
383
|
-
} catch (error) {
|
|
384
|
-
if (error instanceof zod.ZodError) throw new UpdateOutputValidationError(updateName, error);
|
|
385
|
-
throw error;
|
|
386
|
-
}
|
|
351
|
+
const inputResult$1 = await updateDef.input["~standard"].validate(input);
|
|
352
|
+
if (inputResult$1.issues) throw new UpdateInputValidationError(updateName, inputResult$1.issues);
|
|
353
|
+
const result$1 = await handler(inputResult$1.value);
|
|
354
|
+
const outputResult$1 = await updateDef.output["~standard"].validate(result$1);
|
|
355
|
+
if (outputResult$1.issues) throw new UpdateOutputValidationError(updateName, outputResult$1.issues);
|
|
356
|
+
return outputResult$1.value;
|
|
387
357
|
});
|
|
388
358
|
}
|
|
389
359
|
}
|
|
@@ -396,12 +366,9 @@ function declareWorkflow(options) {
|
|
|
396
366
|
activities: contextActivities,
|
|
397
367
|
info: (0, __temporalio_workflow.workflowInfo)()
|
|
398
368
|
}, validatedInput);
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
if (error instanceof zod.ZodError) throw new WorkflowOutputValidationError(String(workflowName), error);
|
|
403
|
-
throw error;
|
|
404
|
-
}
|
|
369
|
+
const outputResult = await definition.output["~standard"].validate(result);
|
|
370
|
+
if (outputResult.issues) throw new WorkflowOutputValidationError(String(workflowName), outputResult.issues);
|
|
371
|
+
return outputResult.value;
|
|
405
372
|
};
|
|
406
373
|
}
|
|
407
374
|
|
package/dist/workflow.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_handler = require('./handler-
|
|
1
|
+
const require_handler = require('./handler-Cc951VQp.cjs');
|
|
2
2
|
|
|
3
3
|
exports.QueryInputValidationError = require_handler.QueryInputValidationError;
|
|
4
4
|
exports.QueryOutputValidationError = require_handler.QueryOutputValidationError;
|
package/dist/workflow.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { S as WorkflowImplementation, _ as QueryHandlerImplementation, a as QueryInputValidationError, b as UpdateHandlerImplementation, c as UpdateInputValidationError, d as WorkflowInputValidationError, f as WorkflowOutputValidationError, g as DeclareWorkflowOptions, l as UpdateOutputValidationError, o as QueryOutputValidationError, s as SignalInputValidationError, u as WorkerError, w as declareWorkflow, x as WorkflowContext, y as SignalHandlerImplementation } from "./errors-
|
|
1
|
+
import { S as WorkflowImplementation, _ as QueryHandlerImplementation, a as QueryInputValidationError, b as UpdateHandlerImplementation, c as UpdateInputValidationError, d as WorkflowInputValidationError, f as WorkflowOutputValidationError, g as DeclareWorkflowOptions, l as UpdateOutputValidationError, o as QueryOutputValidationError, s as SignalInputValidationError, u as WorkerError, w as declareWorkflow, x as WorkflowContext, y as SignalHandlerImplementation } from "./errors-B50uht6a.cjs";
|
|
2
2
|
export { type DeclareWorkflowOptions, type QueryHandlerImplementation, QueryInputValidationError, QueryOutputValidationError, type SignalHandlerImplementation, SignalInputValidationError, type UpdateHandlerImplementation, UpdateInputValidationError, UpdateOutputValidationError, WorkerError, type WorkflowContext, type WorkflowImplementation, WorkflowInputValidationError, WorkflowOutputValidationError, declareWorkflow };
|
package/dist/workflow.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { S as WorkflowImplementation, _ as QueryHandlerImplementation, a as QueryInputValidationError, b as UpdateHandlerImplementation, c as UpdateInputValidationError, d as WorkflowInputValidationError, f as WorkflowOutputValidationError, g as DeclareWorkflowOptions, l as UpdateOutputValidationError, o as QueryOutputValidationError, s as SignalInputValidationError, u as WorkerError, w as declareWorkflow, x as WorkflowContext, y as SignalHandlerImplementation } from "./errors-
|
|
1
|
+
import { S as WorkflowImplementation, _ as QueryHandlerImplementation, a as QueryInputValidationError, b as UpdateHandlerImplementation, c as UpdateInputValidationError, d as WorkflowInputValidationError, f as WorkflowOutputValidationError, g as DeclareWorkflowOptions, l as UpdateOutputValidationError, o as QueryOutputValidationError, s as SignalInputValidationError, u as WorkerError, w as declareWorkflow, x as WorkflowContext, y as SignalHandlerImplementation } from "./errors-DgUMRes-.mjs";
|
|
2
2
|
export { type DeclareWorkflowOptions, type QueryHandlerImplementation, QueryInputValidationError, QueryOutputValidationError, type SignalHandlerImplementation, SignalInputValidationError, type UpdateHandlerImplementation, UpdateInputValidationError, UpdateOutputValidationError, WorkerError, type WorkflowContext, type WorkflowImplementation, WorkflowInputValidationError, WorkflowOutputValidationError, declareWorkflow };
|
package/dist/workflow.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { c as QueryOutputValidationError, d as UpdateOutputValidationError, f as WorkerError, l as SignalInputValidationError, m as WorkflowOutputValidationError, n as declareWorkflow, p as WorkflowInputValidationError, s as QueryInputValidationError, u as UpdateInputValidationError } from "./handler-
|
|
1
|
+
import { c as QueryOutputValidationError, d as UpdateOutputValidationError, f as WorkerError, l as SignalInputValidationError, m as WorkflowOutputValidationError, n as declareWorkflow, p as WorkflowInputValidationError, s as QueryInputValidationError, u as UpdateInputValidationError } from "./handler-BP9xAycT.mjs";
|
|
2
2
|
|
|
3
3
|
export { QueryInputValidationError, QueryOutputValidationError, SignalInputValidationError, UpdateInputValidationError, UpdateOutputValidationError, WorkerError, WorkflowInputValidationError, WorkflowOutputValidationError, declareWorkflow };
|