@temporal-contract/worker 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/activity.cjs +27 -2
- package/dist/activity.d.cts +3 -2
- package/dist/activity.d.mts +3 -2
- package/dist/activity.mjs +3 -2
- package/dist/{handler-BP9xAycT.mjs → handler-B7B5QHez.mjs} +52 -30
- package/dist/{errors-B50uht6a.d.cts → handler-Czi-kgwZ.d.cts} +129 -115
- package/dist/{handler-Cc951VQp.cjs → handler-D9BllGor.cjs} +53 -31
- package/dist/{errors-DgUMRes-.d.mts → handler-DThqdaaS.d.mts} +129 -115
- 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 +26 -20
- package/.turbo/turbo-build.log +0 -25
- package/CHANGELOG.md +0 -9
- package/src/activity.ts +0 -15
- package/src/errors.ts +0 -173
- package/src/handler.spec.ts +0 -499
- package/src/handler.ts +0 -605
- package/src/workflow.ts +0 -20
- package/tsconfig.json +0 -9
- package/vitest.config.ts +0 -12
|
@@ -1,9 +1,106 @@
|
|
|
1
1
|
import { ActivityOptions, WorkflowInfo } from "@temporalio/workflow";
|
|
2
|
+
import { Future, Result } from "@swan-io/boxed";
|
|
2
3
|
import { ActivityDefinition, ContractDefinition, QueryDefinition, SignalDefinition, UpdateDefinition, WorkerInferInput, WorkerInferOutput, WorkerInferWorkflowContextActivities } from "@temporal-contract/contract";
|
|
3
4
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
4
5
|
|
|
6
|
+
//#region src/errors.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Base error class for worker errors
|
|
9
|
+
*/
|
|
10
|
+
declare class WorkerError extends Error {
|
|
11
|
+
constructor(message: string, cause?: unknown);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Activity error class that should be used to wrap all technical exceptions
|
|
15
|
+
* Forces proper error handling and enables retry policies
|
|
16
|
+
*/
|
|
17
|
+
declare class ActivityError extends Error {
|
|
18
|
+
readonly code: string;
|
|
19
|
+
readonly cause?: unknown;
|
|
20
|
+
constructor(code: string, message: string, cause?: unknown);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Error thrown when an activity definition is not found in the contract
|
|
24
|
+
*/
|
|
25
|
+
declare class ActivityDefinitionNotFoundError extends WorkerError {
|
|
26
|
+
readonly activityName: string;
|
|
27
|
+
readonly availableDefinitions: readonly string[];
|
|
28
|
+
constructor(activityName: string, availableDefinitions?: readonly string[]);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Error thrown when activity input validation fails
|
|
32
|
+
*/
|
|
33
|
+
declare class ActivityInputValidationError extends WorkerError {
|
|
34
|
+
readonly activityName: string;
|
|
35
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
36
|
+
constructor(activityName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Error thrown when activity output validation fails
|
|
40
|
+
*/
|
|
41
|
+
declare class ActivityOutputValidationError extends WorkerError {
|
|
42
|
+
readonly activityName: string;
|
|
43
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
44
|
+
constructor(activityName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Error thrown when workflow input validation fails
|
|
48
|
+
*/
|
|
49
|
+
declare class WorkflowInputValidationError extends WorkerError {
|
|
50
|
+
readonly workflowName: string;
|
|
51
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
52
|
+
constructor(workflowName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Error thrown when workflow output validation fails
|
|
56
|
+
*/
|
|
57
|
+
declare class WorkflowOutputValidationError extends WorkerError {
|
|
58
|
+
readonly workflowName: string;
|
|
59
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
60
|
+
constructor(workflowName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Error thrown when signal input validation fails
|
|
64
|
+
*/
|
|
65
|
+
declare class SignalInputValidationError extends WorkerError {
|
|
66
|
+
readonly signalName: string;
|
|
67
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
68
|
+
constructor(signalName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Error thrown when query input validation fails
|
|
72
|
+
*/
|
|
73
|
+
declare class QueryInputValidationError extends WorkerError {
|
|
74
|
+
readonly queryName: string;
|
|
75
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
76
|
+
constructor(queryName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Error thrown when query output validation fails
|
|
80
|
+
*/
|
|
81
|
+
declare class QueryOutputValidationError extends WorkerError {
|
|
82
|
+
readonly queryName: string;
|
|
83
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
84
|
+
constructor(queryName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Error thrown when update input validation fails
|
|
88
|
+
*/
|
|
89
|
+
declare class UpdateInputValidationError extends WorkerError {
|
|
90
|
+
readonly updateName: string;
|
|
91
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
92
|
+
constructor(updateName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Error thrown when update output validation fails
|
|
96
|
+
*/
|
|
97
|
+
declare class UpdateOutputValidationError extends WorkerError {
|
|
98
|
+
readonly updateName: string;
|
|
99
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
100
|
+
constructor(updateName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
5
103
|
//#region src/handler.d.ts
|
|
6
|
-
|
|
7
104
|
/**
|
|
8
105
|
* Workflow context with typed activities (workflow + global) and workflow info
|
|
9
106
|
* Note: activities is typed as 'any' to work around TypeScript generic type inference limitations with Zod tuples
|
|
@@ -19,11 +116,10 @@ interface WorkflowContext<TContract extends ContractDefinition, TWorkflowName ex
|
|
|
19
116
|
*/
|
|
20
117
|
type WorkflowImplementation<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]> = (context: WorkflowContext<TContract, TWorkflowName>, args: WorkerInferInput<TContract["workflows"][TWorkflowName]>) => Promise<WorkerInferOutput<TContract["workflows"][TWorkflowName]>>;
|
|
21
118
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* The actual types will be enforced at runtime by Zod validation
|
|
119
|
+
* Activity implementation using Result pattern
|
|
120
|
+
* Returns Future<Result<Output, ActivityError>> instead of throwing exceptions
|
|
25
121
|
*/
|
|
26
|
-
type
|
|
122
|
+
type BoxedActivityImplementation<TActivity extends ActivityDefinition> = (args: WorkerInferInput<TActivity>) => Future<Result<WorkerInferOutput<TActivity>, ActivityError>>;
|
|
27
123
|
/**
|
|
28
124
|
* Signal handler implementation
|
|
29
125
|
*/
|
|
@@ -39,7 +135,7 @@ type UpdateHandlerImplementation<TUpdate extends UpdateDefinition> = (args: Work
|
|
|
39
135
|
/**
|
|
40
136
|
* Map of all activity implementations for a contract (global + all workflow-specific)
|
|
41
137
|
*/
|
|
42
|
-
type ActivityImplementations<T extends ContractDefinition> = (T["activities"] extends Record<string, ActivityDefinition> ? { [K in keyof T["activities"]]:
|
|
138
|
+
type ActivityImplementations<T extends ContractDefinition> = (T["activities"] extends Record<string, ActivityDefinition> ? { [K in keyof T["activities"]]: BoxedActivityImplementation<T["activities"][K]> } : {}) & UnionToIntersection<{ [K in keyof T["workflows"]]: T["workflows"][K]["activities"] extends Record<string, ActivityDefinition> ? { [A in keyof T["workflows"][K]["activities"]]: BoxedActivityImplementation<T["workflows"][K]["activities"][A]> } : {} }[keyof T["workflows"]]>;
|
|
43
139
|
/**
|
|
44
140
|
* Utility type to convert union to intersection
|
|
45
141
|
*/
|
|
@@ -98,30 +194,44 @@ interface DeclareWorkflowOptions<TContract extends ContractDefinition, TWorkflow
|
|
|
98
194
|
updates?: TContract["workflows"][TWorkflowName]["updates"] extends Record<string, UpdateDefinition> ? { [K in keyof TContract["workflows"][TWorkflowName]["updates"]]: UpdateHandlerImplementation<TContract["workflows"][TWorkflowName]["updates"][K]> } : never;
|
|
99
195
|
}
|
|
100
196
|
/**
|
|
101
|
-
* Create a typed activities handler with automatic validation
|
|
197
|
+
* Create a typed activities handler with automatic validation and Result pattern
|
|
198
|
+
*
|
|
199
|
+
* This wraps all activity implementations with:
|
|
200
|
+
* - Validation at network boundaries
|
|
201
|
+
* - Result<T, ActivityError> pattern for explicit error handling
|
|
202
|
+
* - Automatic conversion from Result to Promise (throwing on Error)
|
|
102
203
|
*
|
|
103
|
-
* This wraps all activity implementations with Zod validation at network boundaries.
|
|
104
204
|
* TypeScript ensures ALL activities (global + workflow-specific) are implemented.
|
|
105
205
|
*
|
|
106
206
|
* Use this to create the activities object for the Temporal Worker.
|
|
107
207
|
*
|
|
108
208
|
* @example
|
|
109
209
|
* ```ts
|
|
110
|
-
* import { declareActivitiesHandler } from '@temporal-contract/worker';
|
|
210
|
+
* import { declareActivitiesHandler, ActivityError } from '@temporal-contract/worker/activity';
|
|
211
|
+
* import { Result, Future } from '@swan-io/boxed';
|
|
111
212
|
* import myContract from './contract';
|
|
112
213
|
*
|
|
113
214
|
* export const activitiesHandler = declareActivitiesHandler({
|
|
114
215
|
* contract: myContract,
|
|
115
216
|
* activities: {
|
|
116
|
-
* //
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* return
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
217
|
+
* // Activity returns Result instead of throwing
|
|
218
|
+
* // All technical exceptions must be wrapped in ActivityError for retry policies
|
|
219
|
+
* sendEmail: (args) => {
|
|
220
|
+
* return Future.make(async resolve => {
|
|
221
|
+
* try {
|
|
222
|
+
* await emailService.send(args);
|
|
223
|
+
* resolve(Result.Ok({ sent: true }));
|
|
224
|
+
* } catch (error) {
|
|
225
|
+
* // Wrap technical errors in ActivityError to enable retries
|
|
226
|
+
* resolve(Result.Error(
|
|
227
|
+
* new ActivityError(
|
|
228
|
+
* 'EMAIL_SEND_FAILED',
|
|
229
|
+
* 'Failed to send email',
|
|
230
|
+
* error // Original error as cause for debugging
|
|
231
|
+
* )
|
|
232
|
+
* ));
|
|
233
|
+
* }
|
|
234
|
+
* });
|
|
125
235
|
* },
|
|
126
236
|
* },
|
|
127
237
|
* });
|
|
@@ -203,100 +313,4 @@ declare function declareActivitiesHandler<T extends ContractDefinition>(options:
|
|
|
203
313
|
*/
|
|
204
314
|
declare function declareWorkflow<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]>(options: DeclareWorkflowOptions<TContract, TWorkflowName>): (args: WorkerInferInput<TContract["workflows"][TWorkflowName]>) => Promise<WorkerInferOutput<TContract["workflows"][TWorkflowName]>>;
|
|
205
315
|
//#endregion
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Base error class for worker errors
|
|
209
|
-
*/
|
|
210
|
-
declare class WorkerError extends Error {
|
|
211
|
-
constructor(message: string);
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Error thrown when an activity implementation is not found
|
|
215
|
-
*/
|
|
216
|
-
declare class ActivityImplementationNotFoundError extends WorkerError {
|
|
217
|
-
readonly activityName: string;
|
|
218
|
-
readonly availableActivities: readonly string[];
|
|
219
|
-
constructor(activityName: string, availableActivities: readonly string[]);
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Error thrown when an activity definition is not found in the contract
|
|
223
|
-
*/
|
|
224
|
-
declare class ActivityDefinitionNotFoundError extends WorkerError {
|
|
225
|
-
readonly activityName: string;
|
|
226
|
-
readonly availableDefinitions: readonly string[];
|
|
227
|
-
constructor(activityName: string, availableDefinitions: readonly string[]);
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Error thrown when activity input validation fails
|
|
231
|
-
*/
|
|
232
|
-
declare class ActivityInputValidationError extends WorkerError {
|
|
233
|
-
readonly activityName: string;
|
|
234
|
-
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
235
|
-
constructor(activityName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Error thrown when activity output validation fails
|
|
239
|
-
*/
|
|
240
|
-
declare class ActivityOutputValidationError extends WorkerError {
|
|
241
|
-
readonly activityName: string;
|
|
242
|
-
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
243
|
-
constructor(activityName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Error thrown when workflow input validation fails
|
|
247
|
-
*/
|
|
248
|
-
declare class WorkflowInputValidationError extends WorkerError {
|
|
249
|
-
readonly workflowName: string;
|
|
250
|
-
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
251
|
-
constructor(workflowName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Error thrown when workflow output validation fails
|
|
255
|
-
*/
|
|
256
|
-
declare class WorkflowOutputValidationError extends WorkerError {
|
|
257
|
-
readonly workflowName: string;
|
|
258
|
-
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
259
|
-
constructor(workflowName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Error thrown when signal input validation fails
|
|
263
|
-
*/
|
|
264
|
-
declare class SignalInputValidationError extends WorkerError {
|
|
265
|
-
readonly signalName: string;
|
|
266
|
-
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
267
|
-
constructor(signalName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Error thrown when query input validation fails
|
|
271
|
-
*/
|
|
272
|
-
declare class QueryInputValidationError extends WorkerError {
|
|
273
|
-
readonly queryName: string;
|
|
274
|
-
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
275
|
-
constructor(queryName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Error thrown when query output validation fails
|
|
279
|
-
*/
|
|
280
|
-
declare class QueryOutputValidationError extends WorkerError {
|
|
281
|
-
readonly queryName: string;
|
|
282
|
-
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
283
|
-
constructor(queryName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Error thrown when update input validation fails
|
|
287
|
-
*/
|
|
288
|
-
declare class UpdateInputValidationError extends WorkerError {
|
|
289
|
-
readonly updateName: string;
|
|
290
|
-
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
291
|
-
constructor(updateName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Error thrown when update output validation fails
|
|
295
|
-
*/
|
|
296
|
-
declare class UpdateOutputValidationError extends WorkerError {
|
|
297
|
-
readonly updateName: string;
|
|
298
|
-
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
299
|
-
constructor(updateName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
300
|
-
}
|
|
301
|
-
//#endregion
|
|
302
|
-
export { declareActivitiesHandler as C, WorkflowImplementation as S, QueryHandlerImplementation as _, QueryInputValidationError as a, UpdateHandlerImplementation as b, UpdateInputValidationError as c, WorkflowInputValidationError as d, WorkflowOutputValidationError as f, DeclareWorkflowOptions as g, DeclareActivitiesHandlerOptions as h, ActivityOutputValidationError as i, UpdateOutputValidationError as l, ActivityImplementations as m, ActivityImplementationNotFoundError as n, QueryOutputValidationError as o, ActivitiesHandler as p, ActivityInputValidationError as r, SignalInputValidationError as s, ActivityDefinitionNotFoundError as t, WorkerError as u, RawActivityImplementation as v, declareWorkflow as w, WorkflowContext as x, SignalHandlerImplementation as y };
|
|
316
|
+
export { WorkflowInputValidationError as C, WorkerError as S, QueryInputValidationError as _, DeclareWorkflowOptions as a, UpdateInputValidationError as b, UpdateHandlerImplementation as c, declareActivitiesHandler as d, declareWorkflow as f, ActivityOutputValidationError as g, ActivityInputValidationError as h, DeclareActivitiesHandlerOptions as i, WorkflowContext as l, ActivityError as m, ActivityImplementations as n, QueryHandlerImplementation as o, ActivityDefinitionNotFoundError as p, BoxedActivityImplementation as r, SignalHandlerImplementation as s, ActivitiesHandler as t, WorkflowImplementation as u, QueryOutputValidationError as v, WorkflowOutputValidationError as w, UpdateOutputValidationError as x, SignalInputValidationError as y };
|
package/dist/workflow.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_handler = require('./handler-
|
|
1
|
+
const require_handler = require('./handler-D9BllGor.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 {
|
|
1
|
+
import { C as WorkflowInputValidationError, S as WorkerError, _ as QueryInputValidationError, a as DeclareWorkflowOptions, b as UpdateInputValidationError, c as UpdateHandlerImplementation, f as declareWorkflow, l as WorkflowContext, o as QueryHandlerImplementation, s as SignalHandlerImplementation, u as WorkflowImplementation, v as QueryOutputValidationError, w as WorkflowOutputValidationError, x as UpdateOutputValidationError, y as SignalInputValidationError } from "./handler-Czi-kgwZ.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 {
|
|
1
|
+
import { C as WorkflowInputValidationError, S as WorkerError, _ as QueryInputValidationError, a as DeclareWorkflowOptions, b as UpdateInputValidationError, c as UpdateHandlerImplementation, f as declareWorkflow, l as WorkflowContext, o as QueryHandlerImplementation, s as SignalHandlerImplementation, u as WorkflowImplementation, v as QueryOutputValidationError, w as WorkflowOutputValidationError, x as UpdateOutputValidationError, y as SignalInputValidationError } from "./handler-DThqdaaS.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-B7B5QHez.mjs";
|
|
2
2
|
|
|
3
3
|
export { QueryInputValidationError, QueryOutputValidationError, SignalInputValidationError, UpdateInputValidationError, UpdateOutputValidationError, WorkerError, WorkflowInputValidationError, WorkflowOutputValidationError, declareWorkflow };
|
package/package.json
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporal-contract/worker",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "Worker utilities with Result/Future pattern for implementing temporal-contract workflows and activities",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"temporal",
|
|
7
|
+
"typescript",
|
|
8
|
+
"contract",
|
|
9
|
+
"worker",
|
|
10
|
+
"result",
|
|
11
|
+
"future"
|
|
12
|
+
],
|
|
6
13
|
"homepage": "https://github.com/btravers/temporal-contract#readme",
|
|
7
14
|
"bugs": {
|
|
8
15
|
"url": "https://github.com/btravers/temporal-contract/issues"
|
|
@@ -12,17 +19,9 @@
|
|
|
12
19
|
"url": "https://github.com/btravers/temporal-contract.git",
|
|
13
20
|
"directory": "packages/worker"
|
|
14
21
|
},
|
|
15
|
-
"author": "Benoit TRAVERS <benoit.travers.frgmail.com>",
|
|
16
22
|
"license": "MIT",
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
"typescript",
|
|
20
|
-
"contract",
|
|
21
|
-
"worker"
|
|
22
|
-
],
|
|
23
|
-
"main": "./dist/index.cjs",
|
|
24
|
-
"module": "./dist/index.mjs",
|
|
25
|
-
"types": "./dist/index.d.mts",
|
|
23
|
+
"author": "Benoit TRAVERS <benoit.travers.frgmail.com>",
|
|
24
|
+
"type": "module",
|
|
26
25
|
"exports": {
|
|
27
26
|
"./activity": {
|
|
28
27
|
"import": {
|
|
@@ -46,28 +45,35 @@
|
|
|
46
45
|
},
|
|
47
46
|
"./package.json": "./package.json"
|
|
48
47
|
},
|
|
48
|
+
"main": "./dist/index.cjs",
|
|
49
|
+
"module": "./dist/index.mjs",
|
|
50
|
+
"types": "./dist/index.d.mts",
|
|
51
|
+
"files": [
|
|
52
|
+
"dist"
|
|
53
|
+
],
|
|
49
54
|
"dependencies": {
|
|
50
55
|
"@standard-schema/spec": "1.0.0",
|
|
51
|
-
"@
|
|
56
|
+
"@swan-io/boxed": "3.2.1",
|
|
57
|
+
"@temporal-contract/contract": "0.0.4"
|
|
52
58
|
},
|
|
53
59
|
"devDependencies": {
|
|
54
60
|
"@temporalio/workflow": "1.13.2",
|
|
55
|
-
"@types/node": "
|
|
61
|
+
"@types/node": "25.0.1",
|
|
56
62
|
"@vitest/coverage-v8": "4.0.15",
|
|
57
|
-
"tsdown": "0.17.
|
|
63
|
+
"tsdown": "0.17.3",
|
|
58
64
|
"typescript": "5.9.3",
|
|
59
65
|
"vitest": "4.0.15",
|
|
60
66
|
"zod": "4.1.13",
|
|
61
|
-
"@temporal-contract/tsconfig": "0.0.
|
|
67
|
+
"@temporal-contract/tsconfig": "0.0.4"
|
|
62
68
|
},
|
|
63
69
|
"peerDependencies": {
|
|
64
70
|
"@temporalio/workflow": ">=1.13.0 <2.0.0"
|
|
65
71
|
},
|
|
66
72
|
"scripts": {
|
|
67
|
-
"dev": "tsdown src/activity.ts src/workflow.ts --format cjs,esm --dts --watch",
|
|
68
73
|
"build": "tsdown src/activity.ts src/workflow.ts --format cjs,esm --dts --clean",
|
|
69
|
-
"
|
|
74
|
+
"dev": "tsdown src/activity.ts src/workflow.ts --format cjs,esm --dts --watch",
|
|
70
75
|
"test": "vitest run",
|
|
71
|
-
"test:watch": "vitest"
|
|
76
|
+
"test:watch": "vitest",
|
|
77
|
+
"typecheck": "tsc --noEmit"
|
|
72
78
|
}
|
|
73
79
|
}
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @temporal-contract/worker@0.0.2 build /home/runner/work/temporal-contract/temporal-contract/packages/worker
|
|
3
|
-
> tsdown src/activity.ts src/workflow.ts --format cjs,esm --dts --clean
|
|
4
|
-
|
|
5
|
-
[34mℹ[39m tsdown [2mv0.17.2[22m powered by rolldown [2mv1.0.0-beta.53[22m
|
|
6
|
-
[34mℹ[39m entry: [34msrc/activity.ts, src/workflow.ts[39m
|
|
7
|
-
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
8
|
-
[34mℹ[39m Build start
|
|
9
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mworkflow.cjs[22m [2m 0.75 kB[22m [2m│ gzip: 0.19 kB[22m
|
|
10
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mactivity.cjs[22m [2m 0.55 kB[22m [2m│ gzip: 0.19 kB[22m
|
|
11
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mhandler-Cc951VQp.cjs [2m16.80 kB[22m [2m│ gzip: 3.09 kB[22m
|
|
12
|
-
[34mℹ[39m [33m[CJS][39m 3 files, total: 18.10 kB
|
|
13
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mworkflow.mjs[22m [2m 0.56 kB[22m [2m│ gzip: 0.20 kB[22m
|
|
14
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mactivity.mjs[22m [2m 0.42 kB[22m [2m│ gzip: 0.18 kB[22m
|
|
15
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mhandler-BP9xAycT.mjs [2m15.01 kB[22m [2m│ gzip: 3.00 kB[22m
|
|
16
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mworkflow.d.mts[22m[39m [2m 0.92 kB[22m [2m│ gzip: 0.27 kB[22m
|
|
17
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mactivity.d.mts[22m[39m [2m 0.67 kB[22m [2m│ gzip: 0.23 kB[22m
|
|
18
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32merrors-DgUMRes-.d.mts[39m [2m13.22 kB[22m [2m│ gzip: 2.81 kB[22m
|
|
19
|
-
[34mℹ[39m [34m[ESM][39m 6 files, total: 30.79 kB
|
|
20
|
-
[32m✔[39m Build complete in [32m4048ms[39m
|
|
21
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mworkflow.d.cts[22m[39m [2m 0.92 kB[22m [2m│ gzip: 0.27 kB[22m
|
|
22
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mactivity.d.cts[22m[39m [2m 0.67 kB[22m [2m│ gzip: 0.23 kB[22m
|
|
23
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32merrors-B50uht6a.d.cts[39m [2m13.22 kB[22m [2m│ gzip: 2.81 kB[22m
|
|
24
|
-
[34mℹ[39m [33m[CJS][39m 3 files, total: 14.80 kB
|
|
25
|
-
[32m✔[39m Build complete in [32m4051ms[39m
|
package/CHANGELOG.md
DELETED
package/src/activity.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// Entry point for activities
|
|
2
|
-
export { declareActivitiesHandler } from "./handler.js";
|
|
3
|
-
export type {
|
|
4
|
-
RawActivityImplementation,
|
|
5
|
-
ActivityImplementations,
|
|
6
|
-
DeclareActivitiesHandlerOptions,
|
|
7
|
-
ActivitiesHandler,
|
|
8
|
-
} from "./handler.js";
|
|
9
|
-
export {
|
|
10
|
-
WorkerError,
|
|
11
|
-
ActivityImplementationNotFoundError,
|
|
12
|
-
ActivityDefinitionNotFoundError,
|
|
13
|
-
ActivityInputValidationError,
|
|
14
|
-
ActivityOutputValidationError,
|
|
15
|
-
} from "./errors.js";
|
package/src/errors.ts
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Base error class for worker errors
|
|
5
|
-
*/
|
|
6
|
-
export class WorkerError extends Error {
|
|
7
|
-
constructor(message: string) {
|
|
8
|
-
super(message);
|
|
9
|
-
this.name = "WorkerError";
|
|
10
|
-
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
11
|
-
if (Error.captureStackTrace) {
|
|
12
|
-
Error.captureStackTrace(this, this.constructor);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Error thrown when an activity implementation is not found
|
|
19
|
-
*/
|
|
20
|
-
export class ActivityImplementationNotFoundError extends WorkerError {
|
|
21
|
-
constructor(
|
|
22
|
-
public readonly activityName: string,
|
|
23
|
-
public readonly availableActivities: readonly string[],
|
|
24
|
-
) {
|
|
25
|
-
super(
|
|
26
|
-
`Activity implementation not found for: "${activityName}". ` +
|
|
27
|
-
`Available activities: ${availableActivities.length > 0 ? availableActivities.join(", ") : "none"}`,
|
|
28
|
-
);
|
|
29
|
-
this.name = "ActivityImplementationNotFoundError";
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Error thrown when an activity definition is not found in the contract
|
|
35
|
-
*/
|
|
36
|
-
export class ActivityDefinitionNotFoundError extends WorkerError {
|
|
37
|
-
constructor(
|
|
38
|
-
public readonly activityName: string,
|
|
39
|
-
public readonly availableDefinitions: readonly string[],
|
|
40
|
-
) {
|
|
41
|
-
super(
|
|
42
|
-
`Activity definition not found in contract for: "${activityName}". ` +
|
|
43
|
-
`Available definitions: ${availableDefinitions.length > 0 ? availableDefinitions.join(", ") : "none"}`,
|
|
44
|
-
);
|
|
45
|
-
this.name = "ActivityDefinitionNotFoundError";
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Error thrown when activity input validation fails
|
|
51
|
-
*/
|
|
52
|
-
export class ActivityInputValidationError extends WorkerError {
|
|
53
|
-
constructor(
|
|
54
|
-
public readonly activityName: string,
|
|
55
|
-
public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,
|
|
56
|
-
) {
|
|
57
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
58
|
-
super(`Activity "${activityName}" input validation failed: ${message}`);
|
|
59
|
-
this.name = "ActivityInputValidationError";
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Error thrown when activity output validation fails
|
|
65
|
-
*/
|
|
66
|
-
export class ActivityOutputValidationError extends WorkerError {
|
|
67
|
-
constructor(
|
|
68
|
-
public readonly activityName: string,
|
|
69
|
-
public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,
|
|
70
|
-
) {
|
|
71
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
72
|
-
super(`Activity "${activityName}" output validation failed: ${message}`);
|
|
73
|
-
this.name = "ActivityOutputValidationError";
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Error thrown when workflow input validation fails
|
|
79
|
-
*/
|
|
80
|
-
export class WorkflowInputValidationError extends WorkerError {
|
|
81
|
-
constructor(
|
|
82
|
-
public readonly workflowName: string,
|
|
83
|
-
public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,
|
|
84
|
-
) {
|
|
85
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
86
|
-
super(`Workflow "${workflowName}" input validation failed: ${message}`);
|
|
87
|
-
this.name = "WorkflowInputValidationError";
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Error thrown when workflow output validation fails
|
|
93
|
-
*/
|
|
94
|
-
export class WorkflowOutputValidationError extends WorkerError {
|
|
95
|
-
constructor(
|
|
96
|
-
public readonly workflowName: string,
|
|
97
|
-
public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,
|
|
98
|
-
) {
|
|
99
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
100
|
-
super(`Workflow "${workflowName}" output validation failed: ${message}`);
|
|
101
|
-
this.name = "WorkflowOutputValidationError";
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Error thrown when signal input validation fails
|
|
107
|
-
*/
|
|
108
|
-
export class SignalInputValidationError extends WorkerError {
|
|
109
|
-
constructor(
|
|
110
|
-
public readonly signalName: string,
|
|
111
|
-
public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,
|
|
112
|
-
) {
|
|
113
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
114
|
-
super(`Signal "${signalName}" input validation failed: ${message}`);
|
|
115
|
-
this.name = "SignalInputValidationError";
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Error thrown when query input validation fails
|
|
121
|
-
*/
|
|
122
|
-
export class QueryInputValidationError extends WorkerError {
|
|
123
|
-
constructor(
|
|
124
|
-
public readonly queryName: string,
|
|
125
|
-
public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,
|
|
126
|
-
) {
|
|
127
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
128
|
-
super(`Query "${queryName}" input validation failed: ${message}`);
|
|
129
|
-
this.name = "QueryInputValidationError";
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Error thrown when query output validation fails
|
|
135
|
-
*/
|
|
136
|
-
export class QueryOutputValidationError extends WorkerError {
|
|
137
|
-
constructor(
|
|
138
|
-
public readonly queryName: string,
|
|
139
|
-
public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,
|
|
140
|
-
) {
|
|
141
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
142
|
-
super(`Query "${queryName}" output validation failed: ${message}`);
|
|
143
|
-
this.name = "QueryOutputValidationError";
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Error thrown when update input validation fails
|
|
149
|
-
*/
|
|
150
|
-
export class UpdateInputValidationError extends WorkerError {
|
|
151
|
-
constructor(
|
|
152
|
-
public readonly updateName: string,
|
|
153
|
-
public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,
|
|
154
|
-
) {
|
|
155
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
156
|
-
super(`Update "${updateName}" input validation failed: ${message}`);
|
|
157
|
-
this.name = "UpdateInputValidationError";
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Error thrown when update output validation fails
|
|
163
|
-
*/
|
|
164
|
-
export class UpdateOutputValidationError extends WorkerError {
|
|
165
|
-
constructor(
|
|
166
|
-
public readonly updateName: string,
|
|
167
|
-
public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,
|
|
168
|
-
) {
|
|
169
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
170
|
-
super(`Update "${updateName}" output validation failed: ${message}`);
|
|
171
|
-
this.name = "UpdateOutputValidationError";
|
|
172
|
-
}
|
|
173
|
-
}
|