@temporal-contract/worker 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,126 +2,47 @@
2
2
 
3
3
  > Type-safe worker implementation for Temporal
4
4
 
5
+ [![npm version](https://img.shields.io/npm/v/@temporal-contract/worker.svg?logo=npm)](https://www.npmjs.com/package/@temporal-contract/worker)
6
+
5
7
  ## Installation
6
8
 
7
9
  ```bash
8
10
  pnpm add @temporal-contract/worker @temporal-contract/contract @temporalio/workflow zod
9
11
  ```
10
12
 
11
- ## Important: Separate Entry Points
12
-
13
- Use **separate imports** for better tree-shaking:
14
-
15
- - **`@temporal-contract/worker/activity`** — For activity files
16
- - **`@temporal-contract/worker/workflow`** — For workflow files
17
-
18
- ## Quick Start
19
-
20
- ### 1. Implement Activities
13
+ ## Quick Example
21
14
 
22
15
  ```typescript
23
16
  // activities.ts
24
17
  import { declareActivitiesHandler } from '@temporal-contract/worker/activity';
25
- import { myContract } from './contract';
26
18
 
27
19
  export const activities = declareActivitiesHandler({
28
20
  contract: myContract,
29
21
  activities: {
30
- sendEmail: async ({ to, subject, body }) => {
31
- await emailService.send({ to, subject, body });
32
- return { sent: true };
33
- },
34
- processPayment: async ({ customerId, amount }) => {
35
- const txId = await paymentGateway.charge(customerId, amount);
36
- return { transactionId: txId, success: true };
37
- },
38
- },
22
+ sendEmail: async ({ to, body }) => ({ sent: true })
23
+ }
39
24
  });
40
- ```
41
25
 
42
- ### 2. Implement Workflows
43
-
44
- ```typescript
45
26
  // workflows.ts
46
27
  import { declareWorkflow } from '@temporal-contract/worker/workflow';
47
- import { myContract } from './contract';
48
28
 
49
29
  export const processOrder = declareWorkflow({
50
30
  workflowName: 'processOrder',
51
31
  contract: myContract,
52
- implementation: async (context, { orderId, customerId }) => {
53
- const payment = await context.activities.processPayment({ customerId, amount: 100 });
54
- await context.activities.sendEmail({ to: customerId, subject: 'Confirmed', body: 'Done!' });
55
-
56
- return {
57
- status: payment.success ? 'success' : 'failed',
58
- transactionId: payment.transactionId,
59
- };
60
- },
61
- });
62
- ```
63
-
64
- ### 3. Start Worker
65
-
66
- ```typescript
67
- // worker.ts
68
- import { Worker } from '@temporalio/worker';
69
- import { activities } from './activities';
70
-
71
- const worker = await Worker.create({
72
- workflowsPath: require.resolve('./workflows'),
73
- activities: activities.activities,
74
- taskQueue: activities.contract.taskQueue,
32
+ implementation: async (context, input) => {
33
+ await context.activities.sendEmail({ to: 'user@example.com', body: 'Done!' });
34
+ return { success: true };
35
+ }
75
36
  });
76
-
77
- await worker.run();
78
- ```
79
-
80
- ## Features
81
-
82
- ✅ **Automatic validation** — Input/output validated with Zod at network boundaries
83
- ✅ **Type inference** — Full TypeScript inference from contract
84
- ✅ **Typed context** — Activities and workflow info fully typed
85
- ✅ **Signals, queries, updates** — Type-safe handlers with validation
86
-
87
- ## Utility Types
88
-
89
- For cleaner activity signatures:
90
-
91
- ```typescript
92
- import type { ActivityHandler, WorkflowActivityHandler } from '@temporal-contract/contract';
93
-
94
- const sendEmail: ActivityHandler<typeof myContract, 'sendEmail'> =
95
- async ({ to, subject, body }) => {
96
- // Fully typed without explicit annotations
97
- return { sent: true };
98
- };
99
- ```
100
-
101
- See [Activity Handlers documentation](../../docs/ACTIVITY_HANDLERS.md) for details.
102
-
103
- ## Error Handling
104
-
105
- Custom error classes with contextual info:
106
-
107
- ```typescript
108
- import { ActivityDefinitionNotFoundError } from '@temporal-contract/worker';
109
-
110
- // Errors include helpful context
111
- if (error instanceof ActivityDefinitionNotFoundError) {
112
- console.error('Not found:', error.activityName);
113
- console.error('Available:', error.availableActivities);
114
- }
115
37
  ```
116
38
 
117
- ---
39
+ ## Documentation
118
40
 
119
- ## Learn More
41
+ 📖 **[Read the full documentation →](https://btravers.github.io/temporal-contract)**
120
42
 
121
- - [Main README](../../README.md) — Quick start guide
122
- - [Worker Implementation](../../docs/CONTRACT_HANDLER.md) — Complete guide
123
- - [Entry Points](../../docs/ENTRY_POINTS.md) — Why separate entry points
124
- - [Activity Handlers](../../docs/ACTIVITY_HANDLERS.md) — Type utilities
43
+ - [API Reference](https://btravers.github.io/temporal-contract/api/worker)
44
+ - [Worker Implementation Guide](https://btravers.github.io/temporal-contract/guide/worker-implementation)
45
+ - [Examples](https://btravers.github.io/temporal-contract/examples/)
125
46
 
126
47
  ## License
127
48
 
package/dist/activity.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_handler = require('./handler-B3KY0uDx.cjs');
1
+ const require_handler = require('./handler-Cc951VQp.cjs');
2
2
 
3
3
  exports.ActivityDefinitionNotFoundError = require_handler.ActivityDefinitionNotFoundError;
4
4
  exports.ActivityImplementationNotFoundError = require_handler.ActivityImplementationNotFoundError;
@@ -1,2 +1,2 @@
1
- import { C as declareActivitiesHandler, h as DeclareActivitiesHandlerOptions, i as ActivityOutputValidationError, m as ActivityImplementations, n as ActivityImplementationNotFoundError, p as ActivitiesHandler, r as ActivityInputValidationError, t as ActivityDefinitionNotFoundError, u as WorkerError, v as RawActivityImplementation } from "./errors-CqX81ysy.cjs";
1
+ import { C as declareActivitiesHandler, h as DeclareActivitiesHandlerOptions, i as ActivityOutputValidationError, m as ActivityImplementations, n as ActivityImplementationNotFoundError, p as ActivitiesHandler, r as ActivityInputValidationError, t as ActivityDefinitionNotFoundError, u as WorkerError, v as RawActivityImplementation } from "./errors-B50uht6a.cjs";
2
2
  export { type ActivitiesHandler, ActivityDefinitionNotFoundError, ActivityImplementationNotFoundError, type ActivityImplementations, ActivityInputValidationError, ActivityOutputValidationError, type DeclareActivitiesHandlerOptions, type RawActivityImplementation, WorkerError, declareActivitiesHandler };
@@ -1,2 +1,2 @@
1
- import { C as declareActivitiesHandler, h as DeclareActivitiesHandlerOptions, i as ActivityOutputValidationError, m as ActivityImplementations, n as ActivityImplementationNotFoundError, p as ActivitiesHandler, r as ActivityInputValidationError, t as ActivityDefinitionNotFoundError, u as WorkerError, v as RawActivityImplementation } from "./errors-oc-Iiwmu.mjs";
1
+ import { C as declareActivitiesHandler, h as DeclareActivitiesHandlerOptions, i as ActivityOutputValidationError, m as ActivityImplementations, n as ActivityImplementationNotFoundError, p as ActivitiesHandler, r as ActivityInputValidationError, t as ActivityDefinitionNotFoundError, u as WorkerError, v as RawActivityImplementation } from "./errors-DgUMRes-.mjs";
2
2
  export { type ActivitiesHandler, ActivityDefinitionNotFoundError, ActivityImplementationNotFoundError, type ActivityImplementations, ActivityInputValidationError, ActivityOutputValidationError, type DeclareActivitiesHandlerOptions, type RawActivityImplementation, WorkerError, declareActivitiesHandler };
package/dist/activity.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { a as ActivityInputValidationError, f as WorkerError, i as ActivityImplementationNotFoundError, o as ActivityOutputValidationError, r as ActivityDefinitionNotFoundError, t as declareActivitiesHandler } from "./handler-aA2RFdV7.mjs";
1
+ import { a as ActivityInputValidationError, f as WorkerError, i as ActivityImplementationNotFoundError, o as ActivityOutputValidationError, r as ActivityDefinitionNotFoundError, t as declareActivitiesHandler } from "./handler-BP9xAycT.mjs";
2
2
 
3
3
  export { ActivityDefinitionNotFoundError, ActivityImplementationNotFoundError, ActivityInputValidationError, ActivityOutputValidationError, WorkerError, declareActivitiesHandler };
@@ -1,6 +1,6 @@
1
1
  import { ActivityOptions, WorkflowInfo } from "@temporalio/workflow";
2
2
  import { ActivityDefinition, ContractDefinition, QueryDefinition, SignalDefinition, UpdateDefinition, WorkerInferInput, WorkerInferOutput, WorkerInferWorkflowContextActivities } from "@temporal-contract/contract";
3
- import { z } from "zod";
3
+ import { StandardSchemaV1 } from "@standard-schema/spec";
4
4
 
5
5
  //#region src/handler.d.ts
6
6
 
@@ -231,72 +231,72 @@ declare class ActivityDefinitionNotFoundError extends WorkerError {
231
231
  */
232
232
  declare class ActivityInputValidationError extends WorkerError {
233
233
  readonly activityName: string;
234
- readonly zodError: z.ZodError;
235
- constructor(activityName: string, zodError: z.ZodError);
234
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
235
+ constructor(activityName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
236
236
  }
237
237
  /**
238
238
  * Error thrown when activity output validation fails
239
239
  */
240
240
  declare class ActivityOutputValidationError extends WorkerError {
241
241
  readonly activityName: string;
242
- readonly zodError: z.ZodError;
243
- constructor(activityName: string, zodError: z.ZodError);
242
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
243
+ constructor(activityName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
244
244
  }
245
245
  /**
246
246
  * Error thrown when workflow input validation fails
247
247
  */
248
248
  declare class WorkflowInputValidationError extends WorkerError {
249
249
  readonly workflowName: string;
250
- readonly zodError: z.ZodError;
251
- constructor(workflowName: string, zodError: z.ZodError);
250
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
251
+ constructor(workflowName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
252
252
  }
253
253
  /**
254
254
  * Error thrown when workflow output validation fails
255
255
  */
256
256
  declare class WorkflowOutputValidationError extends WorkerError {
257
257
  readonly workflowName: string;
258
- readonly zodError: z.ZodError;
259
- constructor(workflowName: string, zodError: z.ZodError);
258
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
259
+ constructor(workflowName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
260
260
  }
261
261
  /**
262
262
  * Error thrown when signal input validation fails
263
263
  */
264
264
  declare class SignalInputValidationError extends WorkerError {
265
265
  readonly signalName: string;
266
- readonly zodError: z.ZodError;
267
- constructor(signalName: string, zodError: z.ZodError);
266
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
267
+ constructor(signalName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
268
268
  }
269
269
  /**
270
270
  * Error thrown when query input validation fails
271
271
  */
272
272
  declare class QueryInputValidationError extends WorkerError {
273
273
  readonly queryName: string;
274
- readonly zodError: z.ZodError;
275
- constructor(queryName: string, zodError: z.ZodError);
274
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
275
+ constructor(queryName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
276
276
  }
277
277
  /**
278
278
  * Error thrown when query output validation fails
279
279
  */
280
280
  declare class QueryOutputValidationError extends WorkerError {
281
281
  readonly queryName: string;
282
- readonly zodError: z.ZodError;
283
- constructor(queryName: string, zodError: z.ZodError);
282
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
283
+ constructor(queryName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
284
284
  }
285
285
  /**
286
286
  * Error thrown when update input validation fails
287
287
  */
288
288
  declare class UpdateInputValidationError extends WorkerError {
289
289
  readonly updateName: string;
290
- readonly zodError: z.ZodError;
291
- constructor(updateName: string, zodError: z.ZodError);
290
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
291
+ constructor(updateName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
292
292
  }
293
293
  /**
294
294
  * Error thrown when update output validation fails
295
295
  */
296
296
  declare class UpdateOutputValidationError extends WorkerError {
297
297
  readonly updateName: string;
298
- readonly zodError: z.ZodError;
299
- constructor(updateName: string, zodError: z.ZodError);
298
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
299
+ constructor(updateName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
300
300
  }
301
301
  //#endregion
302
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 };
@@ -1,6 +1,6 @@
1
1
  import { ActivityOptions, WorkflowInfo } from "@temporalio/workflow";
2
- import { z } from "zod";
3
2
  import { ActivityDefinition, ContractDefinition, QueryDefinition, SignalDefinition, UpdateDefinition, WorkerInferInput, WorkerInferOutput, WorkerInferWorkflowContextActivities } from "@temporal-contract/contract";
3
+ import { StandardSchemaV1 } from "@standard-schema/spec";
4
4
 
5
5
  //#region src/handler.d.ts
6
6
 
@@ -231,72 +231,72 @@ declare class ActivityDefinitionNotFoundError extends WorkerError {
231
231
  */
232
232
  declare class ActivityInputValidationError extends WorkerError {
233
233
  readonly activityName: string;
234
- readonly zodError: z.ZodError;
235
- constructor(activityName: string, zodError: z.ZodError);
234
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
235
+ constructor(activityName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
236
236
  }
237
237
  /**
238
238
  * Error thrown when activity output validation fails
239
239
  */
240
240
  declare class ActivityOutputValidationError extends WorkerError {
241
241
  readonly activityName: string;
242
- readonly zodError: z.ZodError;
243
- constructor(activityName: string, zodError: z.ZodError);
242
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
243
+ constructor(activityName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
244
244
  }
245
245
  /**
246
246
  * Error thrown when workflow input validation fails
247
247
  */
248
248
  declare class WorkflowInputValidationError extends WorkerError {
249
249
  readonly workflowName: string;
250
- readonly zodError: z.ZodError;
251
- constructor(workflowName: string, zodError: z.ZodError);
250
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
251
+ constructor(workflowName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
252
252
  }
253
253
  /**
254
254
  * Error thrown when workflow output validation fails
255
255
  */
256
256
  declare class WorkflowOutputValidationError extends WorkerError {
257
257
  readonly workflowName: string;
258
- readonly zodError: z.ZodError;
259
- constructor(workflowName: string, zodError: z.ZodError);
258
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
259
+ constructor(workflowName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
260
260
  }
261
261
  /**
262
262
  * Error thrown when signal input validation fails
263
263
  */
264
264
  declare class SignalInputValidationError extends WorkerError {
265
265
  readonly signalName: string;
266
- readonly zodError: z.ZodError;
267
- constructor(signalName: string, zodError: z.ZodError);
266
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
267
+ constructor(signalName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
268
268
  }
269
269
  /**
270
270
  * Error thrown when query input validation fails
271
271
  */
272
272
  declare class QueryInputValidationError extends WorkerError {
273
273
  readonly queryName: string;
274
- readonly zodError: z.ZodError;
275
- constructor(queryName: string, zodError: z.ZodError);
274
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
275
+ constructor(queryName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
276
276
  }
277
277
  /**
278
278
  * Error thrown when query output validation fails
279
279
  */
280
280
  declare class QueryOutputValidationError extends WorkerError {
281
281
  readonly queryName: string;
282
- readonly zodError: z.ZodError;
283
- constructor(queryName: string, zodError: z.ZodError);
282
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
283
+ constructor(queryName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
284
284
  }
285
285
  /**
286
286
  * Error thrown when update input validation fails
287
287
  */
288
288
  declare class UpdateInputValidationError extends WorkerError {
289
289
  readonly updateName: string;
290
- readonly zodError: z.ZodError;
291
- constructor(updateName: string, zodError: z.ZodError);
290
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
291
+ constructor(updateName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
292
292
  }
293
293
  /**
294
294
  * Error thrown when update output validation fails
295
295
  */
296
296
  declare class UpdateOutputValidationError extends WorkerError {
297
297
  readonly updateName: string;
298
- readonly zodError: z.ZodError;
299
- constructor(updateName: string, zodError: z.ZodError);
298
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
299
+ constructor(updateName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
300
300
  }
301
301
  //#endregion
302
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 };