@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.
@@ -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
- * Raw activity implementation function (receives typed args as tuple)
23
- * Note: We use 'any' for args/return to work around TypeScript limitations with generic Zod tuple inference
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 RawActivityImplementation<TActivity extends ActivityDefinition> = (args: WorkerInferInput<TActivity>) => Promise<WorkerInferOutput<TActivity>>;
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"]]: RawActivityImplementation<T["activities"][K]> } : {}) & UnionToIntersection<{ [K in keyof T["workflows"]]: T["workflows"][K]["activities"] extends Record<string, ActivityDefinition> ? { [A in keyof T["workflows"][K]["activities"]]: RawActivityImplementation<T["workflows"][K]["activities"][A]> } : {} }[keyof T["workflows"]]>;
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
- * // Global activities
117
- * sendEmail: async (to, subject, body) => {
118
- * await emailService.send({ to, subject, body });
119
- * return { sent: true };
120
- * },
121
- * // Workflow-specific activities
122
- * validateInventory: async (orderId) => {
123
- * const available = await inventory.check(orderId);
124
- * return { available };
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
- //#region src/errors.d.ts
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-Cc951VQp.cjs');
1
+ const require_handler = require('./handler-D9BllGor.cjs');
2
2
 
3
3
  exports.QueryInputValidationError = require_handler.QueryInputValidationError;
4
4
  exports.QueryOutputValidationError = require_handler.QueryOutputValidationError;
@@ -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-B50uht6a.cjs";
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 };
@@ -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-DgUMRes-.mjs";
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-BP9xAycT.mjs";
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.2",
4
- "type": "module",
5
- "description": "Worker utilities for implementing temporal-contract workflows and activities",
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
- "keywords": [
18
- "temporal",
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
- "@temporal-contract/contract": "0.0.2"
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": "24.10.2",
61
+ "@types/node": "25.0.1",
56
62
  "@vitest/coverage-v8": "4.0.15",
57
- "tsdown": "0.17.2",
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.2"
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
- "typecheck": "tsc --noEmit",
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
  }
@@ -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
- ℹ tsdown v0.17.2 powered by rolldown v1.0.0-beta.53
6
- ℹ entry: src/activity.ts, src/workflow.ts
7
- ℹ tsconfig: tsconfig.json
8
- ℹ Build start
9
- ℹ [CJS] dist/workflow.cjs  0.75 kB │ gzip: 0.19 kB
10
- ℹ [CJS] dist/activity.cjs  0.55 kB │ gzip: 0.19 kB
11
- ℹ [CJS] dist/handler-Cc951VQp.cjs 16.80 kB │ gzip: 3.09 kB
12
- ℹ [CJS] 3 files, total: 18.10 kB
13
- ℹ [ESM] dist/workflow.mjs  0.56 kB │ gzip: 0.20 kB
14
- ℹ [ESM] dist/activity.mjs  0.42 kB │ gzip: 0.18 kB
15
- ℹ [ESM] dist/handler-BP9xAycT.mjs 15.01 kB │ gzip: 3.00 kB
16
- ℹ [ESM] dist/workflow.d.mts  0.92 kB │ gzip: 0.27 kB
17
- ℹ [ESM] dist/activity.d.mts  0.67 kB │ gzip: 0.23 kB
18
- ℹ [ESM] dist/errors-DgUMRes-.d.mts 13.22 kB │ gzip: 2.81 kB
19
- ℹ [ESM] 6 files, total: 30.79 kB
20
- ✔ Build complete in 4048ms
21
- ℹ [CJS] dist/workflow.d.cts  0.92 kB │ gzip: 0.27 kB
22
- ℹ [CJS] dist/activity.d.cts  0.67 kB │ gzip: 0.23 kB
23
- ℹ [CJS] dist/errors-B50uht6a.d.cts 13.22 kB │ gzip: 2.81 kB
24
- ℹ [CJS] 3 files, total: 14.80 kB
25
- ✔ Build complete in 4051ms
package/CHANGELOG.md DELETED
@@ -1,9 +0,0 @@
1
- # @temporal-contract/worker
2
-
3
- ## 0.0.2
4
-
5
- ### Patch Changes
6
-
7
- - Release version 0.0.2
8
- - Updated dependencies
9
- - @temporal-contract/contract@0.0.2
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
- }