@temporal-contract/worker 0.0.5 → 0.0.7
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 +23 -0
- package/dist/activity-Csptpwgf.d.cts +162 -0
- package/dist/activity-UOnp_bSX.d.mts +162 -0
- package/dist/activity.cjs +190 -7
- package/dist/activity.d.cts +3 -2
- package/dist/activity.d.mts +3 -2
- package/dist/activity.mjs +182 -2
- package/dist/errors-BqVTpfcf.mjs +155 -0
- package/dist/errors-BqYWpdvd.d.cts +137 -0
- package/dist/errors-C1RFkCuD.d.mts +137 -0
- package/dist/errors-DjSZg-93.cjs +227 -0
- package/dist/worker.cjs +65 -0
- package/dist/worker.d.cts +68 -0
- package/dist/worker.d.mts +68 -0
- package/dist/worker.mjs +64 -0
- package/dist/workflow.cjs +255 -12
- package/dist/workflow.d.cts +299 -2
- package/dist/workflow.d.mts +299 -2
- package/dist/workflow.mjs +244 -2
- package/package.json +26 -14
- package/dist/handler-BAzNuAZz.cjs +0 -597
- package/dist/handler-Cp9h_XCy.d.cts +0 -560
- package/dist/handler-DFFpSaGN.mjs +0 -502
- package/dist/handler-uAeIi9f0.d.mts +0 -560
package/dist/activity.mjs
CHANGED
|
@@ -1,3 +1,183 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as ActivityInputValidationError, r as ActivityOutputValidationError, t as ActivityDefinitionNotFoundError } from "./errors-BqVTpfcf.mjs";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
//#region src/activity-utils.ts
|
|
4
|
+
/**
|
|
5
|
+
* Extract activity definitions for a specific workflow from a contract
|
|
6
|
+
*
|
|
7
|
+
* This includes both:
|
|
8
|
+
* - Workflow-specific activities defined under workflow.activities
|
|
9
|
+
* - Global activities defined under contract.activities
|
|
10
|
+
*
|
|
11
|
+
* @param contract - The contract definition
|
|
12
|
+
* @param workflowName - The name of the workflow
|
|
13
|
+
* @returns Activity definitions for the workflow (workflow-specific + global activities merged)
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const orderWorkflowActivities = getWorkflowActivities(myContract, 'processOrder');
|
|
18
|
+
* // Returns: { processPayment: ActivityDef, reserveInventory: ActivityDef, sendEmail: ActivityDef }
|
|
19
|
+
* // where sendEmail is a global activity
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function getWorkflowActivities(contract, workflowName) {
|
|
23
|
+
const workflowActivities = contract.workflows[workflowName]?.activities || {};
|
|
24
|
+
return {
|
|
25
|
+
...contract.activities || {},
|
|
26
|
+
...workflowActivities
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Extract all activity names for a specific workflow from a contract
|
|
31
|
+
*
|
|
32
|
+
* @param contract - The contract definition
|
|
33
|
+
* @param workflowName - The name of the workflow
|
|
34
|
+
* @returns Array of activity names (strings) available for the workflow
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const activityNames = getWorkflowActivityNames(myContract, 'processOrder');
|
|
39
|
+
* // Returns: ['processPayment', 'reserveInventory', 'sendEmail']
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
function getWorkflowActivityNames(contract, workflowName) {
|
|
43
|
+
const activities = getWorkflowActivities(contract, workflowName);
|
|
44
|
+
return Object.keys(activities);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Check if an activity belongs to a specific workflow
|
|
48
|
+
*
|
|
49
|
+
* @param contract - The contract definition
|
|
50
|
+
* @param workflowName - The name of the workflow
|
|
51
|
+
* @param activityName - The name of the activity to check
|
|
52
|
+
* @returns True if the activity is available for the workflow, false otherwise
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* if (isWorkflowActivity(myContract, 'processOrder', 'processPayment')) {
|
|
57
|
+
* // Activity is available for this workflow
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
function isWorkflowActivity(contract, workflowName, activityName) {
|
|
62
|
+
return activityName in getWorkflowActivities(contract, workflowName);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get all workflow names from a contract
|
|
66
|
+
*
|
|
67
|
+
* @param contract - The contract definition
|
|
68
|
+
* @returns Array of workflow names defined in the contract
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const workflows = getWorkflowNames(myContract);
|
|
73
|
+
* // Returns: ['processOrder', 'processRefund']
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
function getWorkflowNames(contract) {
|
|
77
|
+
return Object.keys(contract.workflows);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/activity.ts
|
|
82
|
+
/**
|
|
83
|
+
* Activity error class that should be used to wrap all technical exceptions
|
|
84
|
+
* Forces proper error handling and enables retry policies
|
|
85
|
+
*/
|
|
86
|
+
var ActivityError = class ActivityError extends Error {
|
|
87
|
+
constructor(code, message, cause) {
|
|
88
|
+
super(message, { cause });
|
|
89
|
+
this.code = code;
|
|
90
|
+
this.name = "ActivityError";
|
|
91
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, ActivityError);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Create a typed activities handler with automatic validation and Result pattern
|
|
96
|
+
*
|
|
97
|
+
* This wraps all activity implementations with:
|
|
98
|
+
* - Validation at network boundaries
|
|
99
|
+
* - Result<T, ActivityError> pattern for explicit error handling
|
|
100
|
+
* - Automatic conversion from Result to Promise (throwing on Error)
|
|
101
|
+
*
|
|
102
|
+
* TypeScript ensures ALL activities (global + workflow-specific) are implemented.
|
|
103
|
+
*
|
|
104
|
+
* Use this to create the activities object for the Temporal Worker.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* import { declareActivitiesHandler, ActivityError } from '@temporal-contract/worker/activity';
|
|
109
|
+
* import { Result, Future } from '@swan-io/boxed';
|
|
110
|
+
* import myContract from './contract';
|
|
111
|
+
*
|
|
112
|
+
* export const activities = declareActivitiesHandler({
|
|
113
|
+
* contract: myContract,
|
|
114
|
+
* activities: {
|
|
115
|
+
* // Activity returns Result instead of throwing
|
|
116
|
+
* // All technical exceptions must be wrapped in ActivityError for retry policies
|
|
117
|
+
* sendEmail: (args) => {
|
|
118
|
+
* return Future.make(async resolve => {
|
|
119
|
+
* try {
|
|
120
|
+
* await emailService.send(args);
|
|
121
|
+
* resolve(Result.Ok({ sent: true }));
|
|
122
|
+
* } catch (error) {
|
|
123
|
+
* // Wrap technical errors in ActivityError to enable retries
|
|
124
|
+
* resolve(Result.Error(
|
|
125
|
+
* new ActivityError(
|
|
126
|
+
* 'EMAIL_SEND_FAILED',
|
|
127
|
+
* 'Failed to send email',
|
|
128
|
+
* error // Original error as cause for debugging
|
|
129
|
+
* )
|
|
130
|
+
* ));
|
|
131
|
+
* }
|
|
132
|
+
* });
|
|
133
|
+
* },
|
|
134
|
+
* },
|
|
135
|
+
* });
|
|
136
|
+
*
|
|
137
|
+
* // Use with Temporal Worker
|
|
138
|
+
* import { Worker } from '@temporalio/worker';
|
|
139
|
+
*
|
|
140
|
+
* const worker = await Worker.create({
|
|
141
|
+
* workflowsPath: require.resolve('./workflows'),
|
|
142
|
+
* activities: activities,
|
|
143
|
+
* taskQueue: contract.taskQueue,
|
|
144
|
+
* });
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
function declareActivitiesHandler(options) {
|
|
148
|
+
const { contract, activities } = options;
|
|
149
|
+
const wrappedActivities = {};
|
|
150
|
+
function makeWrapped(activityName, activityDef, activityImpl) {
|
|
151
|
+
return async (...args) => {
|
|
152
|
+
const input = args.length === 1 ? args[0] : args;
|
|
153
|
+
const inputResult = await activityDef.input["~standard"].validate(input);
|
|
154
|
+
if (inputResult.issues) throw new ActivityInputValidationError(activityName, inputResult.issues);
|
|
155
|
+
const result = await activityImpl(inputResult.value);
|
|
156
|
+
if (result.isOk()) {
|
|
157
|
+
const outputResult = await activityDef.output["~standard"].validate(result.value);
|
|
158
|
+
if (outputResult.issues) throw new ActivityOutputValidationError(activityName, outputResult.issues);
|
|
159
|
+
return outputResult.value;
|
|
160
|
+
} else throw result.error;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
if (contract.activities) for (const [activityName, impl] of Object.entries(activities)) {
|
|
164
|
+
if (contract.workflows && activityName in contract.workflows) continue;
|
|
165
|
+
const activityDef = contract.activities[activityName];
|
|
166
|
+
if (!activityDef) throw new ActivityDefinitionNotFoundError(activityName, Object.keys(contract.activities));
|
|
167
|
+
wrappedActivities[activityName] = makeWrapped(activityName, activityDef, impl);
|
|
168
|
+
}
|
|
169
|
+
if (contract.workflows) for (const [workflowName, workflowDef] of Object.entries(contract.workflows)) {
|
|
170
|
+
const wfActivitiesImpl = activities[workflowName];
|
|
171
|
+
if (!wfActivitiesImpl) continue;
|
|
172
|
+
const wfDefs = workflowDef.activities ?? {};
|
|
173
|
+
for (const [activityName, impl] of Object.entries(wfActivitiesImpl)) {
|
|
174
|
+
const activityDef = wfDefs[activityName];
|
|
175
|
+
if (!activityDef) throw new ActivityDefinitionNotFoundError(`${workflowName}.${activityName}`, Object.keys(wfDefs));
|
|
176
|
+
wrappedActivities[activityName] = makeWrapped(`${workflowName}.${activityName}`, activityDef, impl);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return wrappedActivities;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
//#endregion
|
|
183
|
+
export { ActivityDefinitionNotFoundError, ActivityError, ActivityInputValidationError, ActivityOutputValidationError, declareActivitiesHandler, getWorkflowActivities, getWorkflowActivityNames, getWorkflowNames, isWorkflowActivity };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
//#region src/errors.ts
|
|
2
|
+
/**
|
|
3
|
+
* Base error class for worker errors
|
|
4
|
+
*/
|
|
5
|
+
var WorkerError = class extends Error {
|
|
6
|
+
constructor(message, cause) {
|
|
7
|
+
super(message, { cause });
|
|
8
|
+
this.name = "WorkerError";
|
|
9
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Error thrown when an activity definition is not found in the contract
|
|
14
|
+
*/
|
|
15
|
+
var ActivityDefinitionNotFoundError = class extends WorkerError {
|
|
16
|
+
constructor(activityName, availableDefinitions = []) {
|
|
17
|
+
const available = availableDefinitions.length > 0 ? availableDefinitions.join(", ") : "none";
|
|
18
|
+
super(`Activity definition not found for: "${activityName}". Available activities: ${available}`);
|
|
19
|
+
this.activityName = activityName;
|
|
20
|
+
this.availableDefinitions = availableDefinitions;
|
|
21
|
+
this.name = "ActivityDefinitionNotFoundError";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Error thrown when activity input validation fails
|
|
26
|
+
*/
|
|
27
|
+
var ActivityInputValidationError = class extends WorkerError {
|
|
28
|
+
constructor(activityName, issues) {
|
|
29
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
30
|
+
super(`Activity "${activityName}" input validation failed: ${message}`);
|
|
31
|
+
this.activityName = activityName;
|
|
32
|
+
this.issues = issues;
|
|
33
|
+
this.name = "ActivityInputValidationError";
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Error thrown when activity output validation fails
|
|
38
|
+
*/
|
|
39
|
+
var ActivityOutputValidationError = class extends WorkerError {
|
|
40
|
+
constructor(activityName, issues) {
|
|
41
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
42
|
+
super(`Activity "${activityName}" output validation failed: ${message}`);
|
|
43
|
+
this.activityName = activityName;
|
|
44
|
+
this.issues = issues;
|
|
45
|
+
this.name = "ActivityOutputValidationError";
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Error thrown when workflow input validation fails
|
|
50
|
+
*/
|
|
51
|
+
var WorkflowInputValidationError = class extends WorkerError {
|
|
52
|
+
constructor(workflowName, issues) {
|
|
53
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
54
|
+
super(`Workflow "${workflowName}" input validation failed: ${message}`);
|
|
55
|
+
this.workflowName = workflowName;
|
|
56
|
+
this.issues = issues;
|
|
57
|
+
this.name = "WorkflowInputValidationError";
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Error thrown when workflow output validation fails
|
|
62
|
+
*/
|
|
63
|
+
var WorkflowOutputValidationError = class extends WorkerError {
|
|
64
|
+
constructor(workflowName, issues) {
|
|
65
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
66
|
+
super(`Workflow "${workflowName}" output validation failed: ${message}`);
|
|
67
|
+
this.workflowName = workflowName;
|
|
68
|
+
this.issues = issues;
|
|
69
|
+
this.name = "WorkflowOutputValidationError";
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Error thrown when signal input validation fails
|
|
74
|
+
*/
|
|
75
|
+
var SignalInputValidationError = class extends WorkerError {
|
|
76
|
+
constructor(signalName, issues) {
|
|
77
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
78
|
+
super(`Signal "${signalName}" input validation failed: ${message}`);
|
|
79
|
+
this.signalName = signalName;
|
|
80
|
+
this.issues = issues;
|
|
81
|
+
this.name = "SignalInputValidationError";
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Error thrown when query input validation fails
|
|
86
|
+
*/
|
|
87
|
+
var QueryInputValidationError = class extends WorkerError {
|
|
88
|
+
constructor(queryName, issues) {
|
|
89
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
90
|
+
super(`Query "${queryName}" input validation failed: ${message}`);
|
|
91
|
+
this.queryName = queryName;
|
|
92
|
+
this.issues = issues;
|
|
93
|
+
this.name = "QueryInputValidationError";
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Error thrown when query output validation fails
|
|
98
|
+
*/
|
|
99
|
+
var QueryOutputValidationError = class extends WorkerError {
|
|
100
|
+
constructor(queryName, issues) {
|
|
101
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
102
|
+
super(`Query "${queryName}" output validation failed: ${message}`);
|
|
103
|
+
this.queryName = queryName;
|
|
104
|
+
this.issues = issues;
|
|
105
|
+
this.name = "QueryOutputValidationError";
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Error thrown when update input validation fails
|
|
110
|
+
*/
|
|
111
|
+
var UpdateInputValidationError = class extends WorkerError {
|
|
112
|
+
constructor(updateName, issues) {
|
|
113
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
114
|
+
super(`Update "${updateName}" input validation failed: ${message}`);
|
|
115
|
+
this.updateName = updateName;
|
|
116
|
+
this.issues = issues;
|
|
117
|
+
this.name = "UpdateInputValidationError";
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Error thrown when update output validation fails
|
|
122
|
+
*/
|
|
123
|
+
var UpdateOutputValidationError = class extends WorkerError {
|
|
124
|
+
constructor(updateName, issues) {
|
|
125
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
126
|
+
super(`Update "${updateName}" output validation failed: ${message}`);
|
|
127
|
+
this.updateName = updateName;
|
|
128
|
+
this.issues = issues;
|
|
129
|
+
this.name = "UpdateOutputValidationError";
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Error thrown when a child workflow is not found in the contract
|
|
134
|
+
*/
|
|
135
|
+
var ChildWorkflowNotFoundError = class extends WorkerError {
|
|
136
|
+
constructor(workflowName, availableWorkflows = []) {
|
|
137
|
+
const available = availableWorkflows.length > 0 ? availableWorkflows.join(", ") : "none";
|
|
138
|
+
super(`Child workflow not found: "${workflowName}". Available workflows: ${available}`);
|
|
139
|
+
this.workflowName = workflowName;
|
|
140
|
+
this.availableWorkflows = availableWorkflows;
|
|
141
|
+
this.name = "ChildWorkflowNotFoundError";
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Generic error for child workflow operations
|
|
146
|
+
*/
|
|
147
|
+
var ChildWorkflowError = class extends WorkerError {
|
|
148
|
+
constructor(message, cause) {
|
|
149
|
+
super(message, cause);
|
|
150
|
+
this.name = "ChildWorkflowError";
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
155
|
+
export { ChildWorkflowNotFoundError as a, SignalInputValidationError as c, WorkflowInputValidationError as d, WorkflowOutputValidationError as f, ChildWorkflowError as i, UpdateInputValidationError as l, ActivityInputValidationError as n, QueryInputValidationError as o, ActivityOutputValidationError as r, QueryOutputValidationError as s, ActivityDefinitionNotFoundError as t, UpdateOutputValidationError as u };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { AnySchema } from "@temporal-contract/contract";
|
|
2
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Infer input type from a definition (worker perspective)
|
|
8
|
+
* Worker receives the output type (after input schema parsing/transformation)
|
|
9
|
+
*/
|
|
10
|
+
type WorkerInferInput<T extends {
|
|
11
|
+
input: AnySchema;
|
|
12
|
+
}> = StandardSchemaV1.InferOutput<T["input"]>;
|
|
13
|
+
/**
|
|
14
|
+
* Infer output type from a definition (worker perspective)
|
|
15
|
+
* Worker returns the input type (before output schema parsing/transformation)
|
|
16
|
+
*/
|
|
17
|
+
type WorkerInferOutput<T extends {
|
|
18
|
+
output: AnySchema;
|
|
19
|
+
}> = StandardSchemaV1.InferInput<T["output"]>;
|
|
20
|
+
/**
|
|
21
|
+
* Infer input type from a definition (client perspective)
|
|
22
|
+
* Client sends the input type (before input schema parsing/transformation)
|
|
23
|
+
*/
|
|
24
|
+
type ClientInferInput<T extends {
|
|
25
|
+
input: AnySchema;
|
|
26
|
+
}> = StandardSchemaV1.InferInput<T["input"]>;
|
|
27
|
+
/**
|
|
28
|
+
* Infer output type from a definition (client perspective)
|
|
29
|
+
* Client receives the output type (after output schema parsing/transformation)
|
|
30
|
+
*/
|
|
31
|
+
type ClientInferOutput<T extends {
|
|
32
|
+
output: AnySchema;
|
|
33
|
+
}> = StandardSchemaV1.InferOutput<T["output"]>;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/errors.d.ts
|
|
36
|
+
/**
|
|
37
|
+
* Base error class for worker errors
|
|
38
|
+
*/
|
|
39
|
+
declare abstract class WorkerError extends Error {
|
|
40
|
+
protected constructor(message: string, cause?: unknown);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Error thrown when an activity definition is not found in the contract
|
|
44
|
+
*/
|
|
45
|
+
declare class ActivityDefinitionNotFoundError extends WorkerError {
|
|
46
|
+
readonly activityName: string;
|
|
47
|
+
readonly availableDefinitions: readonly string[];
|
|
48
|
+
constructor(activityName: string, availableDefinitions?: readonly string[]);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Error thrown when activity input validation fails
|
|
52
|
+
*/
|
|
53
|
+
declare class ActivityInputValidationError extends WorkerError {
|
|
54
|
+
readonly activityName: string;
|
|
55
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
56
|
+
constructor(activityName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Error thrown when activity output validation fails
|
|
60
|
+
*/
|
|
61
|
+
declare class ActivityOutputValidationError extends WorkerError {
|
|
62
|
+
readonly activityName: string;
|
|
63
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
64
|
+
constructor(activityName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Error thrown when workflow input validation fails
|
|
68
|
+
*/
|
|
69
|
+
declare class WorkflowInputValidationError extends WorkerError {
|
|
70
|
+
readonly workflowName: string;
|
|
71
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
72
|
+
constructor(workflowName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Error thrown when workflow output validation fails
|
|
76
|
+
*/
|
|
77
|
+
declare class WorkflowOutputValidationError extends WorkerError {
|
|
78
|
+
readonly workflowName: string;
|
|
79
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
80
|
+
constructor(workflowName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Error thrown when signal input validation fails
|
|
84
|
+
*/
|
|
85
|
+
declare class SignalInputValidationError extends WorkerError {
|
|
86
|
+
readonly signalName: string;
|
|
87
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
88
|
+
constructor(signalName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Error thrown when query input validation fails
|
|
92
|
+
*/
|
|
93
|
+
declare class QueryInputValidationError extends WorkerError {
|
|
94
|
+
readonly queryName: string;
|
|
95
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
96
|
+
constructor(queryName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Error thrown when query output validation fails
|
|
100
|
+
*/
|
|
101
|
+
declare class QueryOutputValidationError extends WorkerError {
|
|
102
|
+
readonly queryName: string;
|
|
103
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
104
|
+
constructor(queryName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Error thrown when update input validation fails
|
|
108
|
+
*/
|
|
109
|
+
declare class UpdateInputValidationError extends WorkerError {
|
|
110
|
+
readonly updateName: string;
|
|
111
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
112
|
+
constructor(updateName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Error thrown when update output validation fails
|
|
116
|
+
*/
|
|
117
|
+
declare class UpdateOutputValidationError extends WorkerError {
|
|
118
|
+
readonly updateName: string;
|
|
119
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
120
|
+
constructor(updateName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Error thrown when a child workflow is not found in the contract
|
|
124
|
+
*/
|
|
125
|
+
declare class ChildWorkflowNotFoundError extends WorkerError {
|
|
126
|
+
readonly workflowName: string;
|
|
127
|
+
readonly availableWorkflows: readonly string[];
|
|
128
|
+
constructor(workflowName: string, availableWorkflows?: readonly string[]);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Generic error for child workflow operations
|
|
132
|
+
*/
|
|
133
|
+
declare class ChildWorkflowError extends WorkerError {
|
|
134
|
+
constructor(message: string, cause?: unknown);
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
export { ChildWorkflowNotFoundError as a, SignalInputValidationError as c, WorkflowInputValidationError as d, WorkflowOutputValidationError as f, WorkerInferOutput as g, WorkerInferInput as h, ChildWorkflowError as i, UpdateInputValidationError as l, ClientInferOutput as m, ActivityInputValidationError as n, QueryInputValidationError as o, ClientInferInput as p, ActivityOutputValidationError as r, QueryOutputValidationError as s, ActivityDefinitionNotFoundError as t, UpdateOutputValidationError as u };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { AnySchema } from "@temporal-contract/contract";
|
|
2
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Infer input type from a definition (worker perspective)
|
|
8
|
+
* Worker receives the output type (after input schema parsing/transformation)
|
|
9
|
+
*/
|
|
10
|
+
type WorkerInferInput<T extends {
|
|
11
|
+
input: AnySchema;
|
|
12
|
+
}> = StandardSchemaV1.InferOutput<T["input"]>;
|
|
13
|
+
/**
|
|
14
|
+
* Infer output type from a definition (worker perspective)
|
|
15
|
+
* Worker returns the input type (before output schema parsing/transformation)
|
|
16
|
+
*/
|
|
17
|
+
type WorkerInferOutput<T extends {
|
|
18
|
+
output: AnySchema;
|
|
19
|
+
}> = StandardSchemaV1.InferInput<T["output"]>;
|
|
20
|
+
/**
|
|
21
|
+
* Infer input type from a definition (client perspective)
|
|
22
|
+
* Client sends the input type (before input schema parsing/transformation)
|
|
23
|
+
*/
|
|
24
|
+
type ClientInferInput<T extends {
|
|
25
|
+
input: AnySchema;
|
|
26
|
+
}> = StandardSchemaV1.InferInput<T["input"]>;
|
|
27
|
+
/**
|
|
28
|
+
* Infer output type from a definition (client perspective)
|
|
29
|
+
* Client receives the output type (after output schema parsing/transformation)
|
|
30
|
+
*/
|
|
31
|
+
type ClientInferOutput<T extends {
|
|
32
|
+
output: AnySchema;
|
|
33
|
+
}> = StandardSchemaV1.InferOutput<T["output"]>;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/errors.d.ts
|
|
36
|
+
/**
|
|
37
|
+
* Base error class for worker errors
|
|
38
|
+
*/
|
|
39
|
+
declare abstract class WorkerError extends Error {
|
|
40
|
+
protected constructor(message: string, cause?: unknown);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Error thrown when an activity definition is not found in the contract
|
|
44
|
+
*/
|
|
45
|
+
declare class ActivityDefinitionNotFoundError extends WorkerError {
|
|
46
|
+
readonly activityName: string;
|
|
47
|
+
readonly availableDefinitions: readonly string[];
|
|
48
|
+
constructor(activityName: string, availableDefinitions?: readonly string[]);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Error thrown when activity input validation fails
|
|
52
|
+
*/
|
|
53
|
+
declare class ActivityInputValidationError extends WorkerError {
|
|
54
|
+
readonly activityName: string;
|
|
55
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
56
|
+
constructor(activityName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Error thrown when activity output validation fails
|
|
60
|
+
*/
|
|
61
|
+
declare class ActivityOutputValidationError extends WorkerError {
|
|
62
|
+
readonly activityName: string;
|
|
63
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
64
|
+
constructor(activityName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Error thrown when workflow input validation fails
|
|
68
|
+
*/
|
|
69
|
+
declare class WorkflowInputValidationError extends WorkerError {
|
|
70
|
+
readonly workflowName: string;
|
|
71
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
72
|
+
constructor(workflowName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Error thrown when workflow output validation fails
|
|
76
|
+
*/
|
|
77
|
+
declare class WorkflowOutputValidationError extends WorkerError {
|
|
78
|
+
readonly workflowName: string;
|
|
79
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
80
|
+
constructor(workflowName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Error thrown when signal input validation fails
|
|
84
|
+
*/
|
|
85
|
+
declare class SignalInputValidationError extends WorkerError {
|
|
86
|
+
readonly signalName: string;
|
|
87
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
88
|
+
constructor(signalName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Error thrown when query input validation fails
|
|
92
|
+
*/
|
|
93
|
+
declare class QueryInputValidationError extends WorkerError {
|
|
94
|
+
readonly queryName: string;
|
|
95
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
96
|
+
constructor(queryName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Error thrown when query output validation fails
|
|
100
|
+
*/
|
|
101
|
+
declare class QueryOutputValidationError extends WorkerError {
|
|
102
|
+
readonly queryName: string;
|
|
103
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
104
|
+
constructor(queryName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Error thrown when update input validation fails
|
|
108
|
+
*/
|
|
109
|
+
declare class UpdateInputValidationError extends WorkerError {
|
|
110
|
+
readonly updateName: string;
|
|
111
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
112
|
+
constructor(updateName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Error thrown when update output validation fails
|
|
116
|
+
*/
|
|
117
|
+
declare class UpdateOutputValidationError extends WorkerError {
|
|
118
|
+
readonly updateName: string;
|
|
119
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
120
|
+
constructor(updateName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Error thrown when a child workflow is not found in the contract
|
|
124
|
+
*/
|
|
125
|
+
declare class ChildWorkflowNotFoundError extends WorkerError {
|
|
126
|
+
readonly workflowName: string;
|
|
127
|
+
readonly availableWorkflows: readonly string[];
|
|
128
|
+
constructor(workflowName: string, availableWorkflows?: readonly string[]);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Generic error for child workflow operations
|
|
132
|
+
*/
|
|
133
|
+
declare class ChildWorkflowError extends WorkerError {
|
|
134
|
+
constructor(message: string, cause?: unknown);
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
export { ChildWorkflowNotFoundError as a, SignalInputValidationError as c, WorkflowInputValidationError as d, WorkflowOutputValidationError as f, WorkerInferOutput as g, WorkerInferInput as h, ChildWorkflowError as i, UpdateInputValidationError as l, ClientInferOutput as m, ActivityInputValidationError as n, QueryInputValidationError as o, ClientInferInput as p, ActivityOutputValidationError as r, QueryOutputValidationError as s, ActivityDefinitionNotFoundError as t, UpdateOutputValidationError as u };
|