@temporal-contract/worker 0.2.0 → 1.0.0

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.mjs CHANGED
@@ -1,102 +1,12 @@
1
- import { n as ActivityInputValidationError, r as ActivityOutputValidationError, t as ActivityDefinitionNotFoundError } from "./errors-Di6Ja4Rt.mjs";
2
-
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
1
+ import { a as ActivityInputValidationError, i as ActivityDefinitionNotFoundError, o as ActivityOutputValidationError, r as extractHandlerInput } from "./internal-BoNcEtYh.mjs";
2
+ import { ApplicationFailure } from "@temporalio/common";
81
3
  //#region src/activity.ts
82
4
  /**
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
5
+ * Create a typed activities handler with automatic validation and Result pattern.
96
6
  *
97
7
  * This wraps all activity implementations with:
98
8
  * - Validation at network boundaries
99
- * - Result<T, ActivityError> pattern for explicit error handling
9
+ * - `Result<T, ApplicationFailure>` pattern for explicit error handling
100
10
  * - Automatic conversion from Result to Promise (throwing on Error)
101
11
  *
102
12
  * TypeScript ensures ALL activities (global + workflow-specific) are implemented.
@@ -105,28 +15,30 @@ var ActivityError = class ActivityError extends Error {
105
15
  *
106
16
  * @example
107
17
  * ```ts
108
- * import { declareActivitiesHandler, ActivityError } from '@temporal-contract/worker/activity';
18
+ * import { declareActivitiesHandler, ApplicationFailure } from '@temporal-contract/worker/activity';
109
19
  * import { Result, Future } from '@swan-io/boxed';
110
20
  * import myContract from './contract';
111
21
  *
112
22
  * export const activities = declareActivitiesHandler({
113
23
  * contract: myContract,
114
24
  * activities: {
115
- * // Activity returns Result instead of throwing
116
- * // All technical exceptions must be wrapped in ActivityError for retry policies
25
+ * // Activity returns Result instead of throwing.
117
26
  * sendEmail: (args) => {
118
- * return Future.make(async resolve => {
27
+ * return Future.make(async (resolve) => {
119
28
  * try {
120
29
  * await emailService.send(args);
121
30
  * resolve(Result.Ok({ sent: true }));
122
31
  * } catch (error) {
123
- * // Wrap technical errors in ActivityError to enable retries
32
+ * // Wrap technical errors in ApplicationFailure. `nonRetryable`
33
+ * // is per-instance: set it to true on permanent failures so
34
+ * // Temporal stops retrying immediately.
124
35
  * resolve(Result.Error(
125
- * new ActivityError(
126
- * 'EMAIL_SEND_FAILED',
127
- * 'Failed to send email',
128
- * error // Original error as cause for debugging
129
- * )
36
+ * ApplicationFailure.create({
37
+ * type: 'EMAIL_SEND_FAILED',
38
+ * message: 'Failed to send email',
39
+ * nonRetryable: false,
40
+ * cause: error instanceof Error ? error : undefined,
41
+ * }),
130
42
  * ));
131
43
  * }
132
44
  * });
@@ -143,13 +55,26 @@ var ActivityError = class ActivityError extends Error {
143
55
  * taskQueue: contract.taskQueue,
144
56
  * });
145
57
  * ```
58
+ *
59
+ * @remarks
60
+ * The wrapper accepts implementations in the
61
+ * `Future<Result<T, ApplicationFailure>>` shape and produces ordinary
62
+ * Promise-returning Temporal handlers (Result.Error → thrown
63
+ * `ApplicationFailure`; Result.Ok → output validated against the
64
+ * contract and resolved). It does **not** hide Temporal's
65
+ * `@temporalio/activity` runtime: inside the body you can still call
66
+ * `Context.current()` from `@temporalio/activity` to access heartbeats
67
+ * (`heartbeat(details)`, `heartbeatDetails`), activity info (attempt
68
+ * number, workflow IDs), and the async-completion task token. See the
69
+ * "Working with the Activity Context" section of the worker
70
+ * implementation guide for end-to-end examples.
146
71
  */
147
72
  function declareActivitiesHandler(options) {
148
73
  const { contract, activities } = options;
149
74
  const wrappedActivities = {};
150
75
  function makeWrapped(activityName, activityDef, activityImpl) {
151
76
  return async (...args) => {
152
- const input = args.length === 1 ? args[0] : args;
77
+ const input = extractHandlerInput(args);
153
78
  const inputResult = await activityDef.input["~standard"].validate(input);
154
79
  if (inputResult.issues) throw new ActivityInputValidationError(activityName, inputResult.issues);
155
80
  const result = await activityImpl(inputResult.value);
@@ -178,7 +103,7 @@ function declareActivitiesHandler(options) {
178
103
  }
179
104
  return wrappedActivities;
180
105
  }
181
-
182
106
  //#endregion
183
- export { ActivityDefinitionNotFoundError, ActivityError, ActivityInputValidationError, ActivityOutputValidationError, declareActivitiesHandler, getWorkflowActivities, getWorkflowActivityNames, getWorkflowNames, isWorkflowActivity };
107
+ export { ActivityDefinitionNotFoundError, ActivityInputValidationError, ActivityOutputValidationError, ApplicationFailure, declareActivitiesHandler };
108
+
184
109
  //# sourceMappingURL=activity.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"activity.mjs","names":[],"sources":["../src/activity-utils.ts","../src/activity.ts"],"sourcesContent":["// Helper utilities for working with activities\nimport { ActivityDefinition, ContractDefinition } from \"@temporal-contract/contract\";\n\n/**\n * Extract activity definitions for a specific workflow from a contract\n *\n * This includes both:\n * - Workflow-specific activities defined under workflow.activities\n * - Global activities defined under contract.activities\n *\n * @param contract - The contract definition\n * @param workflowName - The name of the workflow\n * @returns Activity definitions for the workflow (workflow-specific + global activities merged)\n *\n * @example\n * ```ts\n * const orderWorkflowActivities = getWorkflowActivities(myContract, 'processOrder');\n * // Returns: { processPayment: ActivityDef, reserveInventory: ActivityDef, sendEmail: ActivityDef }\n * // where sendEmail is a global activity\n * ```\n */\nexport function getWorkflowActivities<\n TContract extends ContractDefinition,\n TWorkflowName extends keyof TContract[\"workflows\"],\n>(contract: TContract, workflowName: TWorkflowName): Record<string, ActivityDefinition> {\n const workflowDef = contract.workflows[workflowName as string];\n const workflowActivities =\n (workflowDef as { activities?: Record<string, ActivityDefinition> })?.activities || {};\n const globalActivities = contract.activities || {};\n\n // Merge global and workflow-specific activities\n // Workflow-specific activities take precedence over global ones with the same name\n return {\n ...globalActivities,\n ...workflowActivities,\n };\n}\n\n/**\n * Extract all activity names for a specific workflow from a contract\n *\n * @param contract - The contract definition\n * @param workflowName - The name of the workflow\n * @returns Array of activity names (strings) available for the workflow\n *\n * @example\n * ```ts\n * const activityNames = getWorkflowActivityNames(myContract, 'processOrder');\n * // Returns: ['processPayment', 'reserveInventory', 'sendEmail']\n * ```\n */\nexport function getWorkflowActivityNames<\n TContract extends ContractDefinition,\n TWorkflowName extends keyof TContract[\"workflows\"],\n>(contract: TContract, workflowName: TWorkflowName): string[] {\n const activities = getWorkflowActivities(contract, workflowName);\n return Object.keys(activities);\n}\n\n/**\n * Check if an activity belongs to a specific workflow\n *\n * @param contract - The contract definition\n * @param workflowName - The name of the workflow\n * @param activityName - The name of the activity to check\n * @returns True if the activity is available for the workflow, false otherwise\n *\n * @example\n * ```ts\n * if (isWorkflowActivity(myContract, 'processOrder', 'processPayment')) {\n * // Activity is available for this workflow\n * }\n * ```\n */\nexport function isWorkflowActivity<\n TContract extends ContractDefinition,\n TWorkflowName extends keyof TContract[\"workflows\"],\n>(contract: TContract, workflowName: TWorkflowName, activityName: string): boolean {\n const activities = getWorkflowActivities(contract, workflowName);\n return activityName in activities;\n}\n\n/**\n * Get all workflow names from a contract\n *\n * @param contract - The contract definition\n * @returns Array of workflow names defined in the contract\n *\n * @example\n * ```ts\n * const workflows = getWorkflowNames(myContract);\n * // Returns: ['processOrder', 'processRefund']\n * ```\n */\nexport function getWorkflowNames<TContract extends ContractDefinition>(\n contract: TContract,\n): Array<keyof TContract[\"workflows\"]> {\n return Object.keys(contract.workflows) as Array<keyof TContract[\"workflows\"]>;\n}\n","// Entry point for activities\nimport { ActivityDefinition, ContractDefinition } from \"@temporal-contract/contract\";\nimport { Future, Result } from \"@swan-io/boxed\";\nimport { WorkerInferInput, WorkerInferOutput } from \"./types.js\";\nimport {\n ActivityDefinitionNotFoundError,\n ActivityInputValidationError,\n ActivityOutputValidationError,\n} from \"./errors.js\";\n\nexport {\n ActivityDefinitionNotFoundError,\n ActivityInputValidationError,\n ActivityOutputValidationError,\n} from \"./errors.js\";\n\nexport {\n getWorkflowActivities,\n getWorkflowActivityNames,\n isWorkflowActivity,\n getWorkflowNames,\n} from \"./activity-utils.js\";\n\n/**\n * Activity error class that should be used to wrap all technical exceptions\n * Forces proper error handling and enables retry policies\n */\nexport class ActivityError extends Error {\n constructor(\n public readonly code: string,\n message: string,\n cause?: unknown,\n ) {\n super(message, { cause });\n this.name = \"ActivityError\";\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, ActivityError);\n }\n }\n}\n\n/**\n * Activity implementation using Future/Result pattern\n *\n * Returns Future<Result<Output, ActivityError>> for explicit error handling instead of throwing exceptions.\n * All errors must be wrapped in ActivityError to enable proper retry policies.\n */\ntype BoxedActivityImplementation<TActivity extends ActivityDefinition> = (\n args: WorkerInferInput<TActivity>,\n) => Future<Result<WorkerInferOutput<TActivity>, ActivityError>>;\n\n/**\n * Map of all activity implementations for a contract (global + all workflow-specific)\n */\ntype ContractBoxedActivitiesImplementations<TContract extends ContractDefinition> =\n // Global activities\n (TContract[\"activities\"] extends Record<string, ActivityDefinition>\n ? BoxedActivitiesImplementations<TContract[\"activities\"]>\n : {}) &\n // All workflow-specific activities merged\n {\n [TWorkflow in keyof TContract[\"workflows\"]]: TContract[\"workflows\"][TWorkflow][\"activities\"] extends Record<\n string,\n ActivityDefinition\n >\n ? BoxedActivitiesImplementations<TContract[\"workflows\"][TWorkflow][\"activities\"]>\n : {};\n };\n\ntype BoxedActivitiesImplementations<TActivities extends Record<string, ActivityDefinition>> = {\n [K in keyof TActivities]: BoxedActivityImplementation<TActivities[K]>;\n};\n\n/**\n * Options for creating activities handler\n */\ntype DeclareActivitiesHandlerOptions<TContract extends ContractDefinition> = {\n contract: TContract;\n activities: ContractBoxedActivitiesImplementations<TContract>;\n};\n\ntype ActivityImplementation<TActivity extends ActivityDefinition> = (\n args: WorkerInferInput<TActivity>,\n) => Promise<WorkerInferOutput<TActivity>>;\n\ntype ActivitiesImplementations<TActivities extends Record<string, ActivityDefinition>> = {\n [K in keyof TActivities]: ActivityImplementation<TActivities[K]>;\n};\n\ntype UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (\n k: infer I,\n) => void\n ? I\n : never;\n\n/**\n * Activities handler ready for Temporal Worker\n *\n * Flat structure: all activities (global + all workflow-specific) are at the root level\n */\nexport type ActivitiesHandler<TContract extends ContractDefinition> =\n // Global activities\n (TContract[\"activities\"] extends Record<string, ActivityDefinition>\n ? ActivitiesImplementations<TContract[\"activities\"]>\n : {}) &\n // All workflow-specific activities merged at root level (flat)\n UnionToIntersection<\n {\n [TWorkflow in keyof TContract[\"workflows\"]]: TContract[\"workflows\"][TWorkflow][\"activities\"] extends Record<\n string,\n ActivityDefinition\n >\n ? ActivitiesImplementations<TContract[\"workflows\"][TWorkflow][\"activities\"]>\n : {};\n }[keyof TContract[\"workflows\"]]\n >;\n\n/**\n * Create a typed activities handler with automatic validation and Result pattern\n *\n * This wraps all activity implementations with:\n * - Validation at network boundaries\n * - Result<T, ActivityError> pattern for explicit error handling\n * - Automatic conversion from Result to Promise (throwing on Error)\n *\n * TypeScript ensures ALL activities (global + workflow-specific) are implemented.\n *\n * Use this to create the activities object for the Temporal Worker.\n *\n * @example\n * ```ts\n * import { declareActivitiesHandler, ActivityError } from '@temporal-contract/worker/activity';\n * import { Result, Future } from '@swan-io/boxed';\n * import myContract from './contract';\n *\n * export const activities = declareActivitiesHandler({\n * contract: myContract,\n * activities: {\n * // Activity returns Result instead of throwing\n * // All technical exceptions must be wrapped in ActivityError for retry policies\n * sendEmail: (args) => {\n * return Future.make(async resolve => {\n * try {\n * await emailService.send(args);\n * resolve(Result.Ok({ sent: true }));\n * } catch (error) {\n * // Wrap technical errors in ActivityError to enable retries\n * resolve(Result.Error(\n * new ActivityError(\n * 'EMAIL_SEND_FAILED',\n * 'Failed to send email',\n * error // Original error as cause for debugging\n * )\n * ));\n * }\n * });\n * },\n * },\n * });\n *\n * // Use with Temporal Worker\n * import { Worker } from '@temporalio/worker';\n *\n * const worker = await Worker.create({\n * workflowsPath: require.resolve('./workflows'),\n * activities: activities,\n * taskQueue: contract.taskQueue,\n * });\n * ```\n */\nexport function declareActivitiesHandler<TContract extends ContractDefinition>(\n options: DeclareActivitiesHandlerOptions<TContract>,\n): ActivitiesHandler<TContract> {\n const { contract, activities } = options;\n\n // Prepare Temporal-compatible activities with validation and Result unwrapping\n const wrappedActivities = {} as ActivitiesHandler<TContract>;\n\n // Helper to create a wrapped implementation from a definition and impl\n function makeWrapped(\n activityName: string,\n activityDef: ActivityDefinition,\n activityImpl: (args: unknown) => Future<Result<unknown, ActivityError>>,\n ) {\n return async (...args: unknown[]) => {\n // Extract single parameter (Temporal passes arguments as an array)\n const input = args.length === 1 ? args[0] : args;\n\n // Validate input\n const inputResult = await activityDef.input[\"~standard\"].validate(input);\n if (inputResult.issues) {\n throw new ActivityInputValidationError(activityName, inputResult.issues);\n }\n\n // Execute boxed activity (returns Future<Result<T, ActivityError>>)\n const futureResult = activityImpl(inputResult.value);\n\n // Await Future and unwrap Result\n const result = await futureResult;\n\n // Process result: validate output or throw error\n if (result.isOk()) {\n // Validate output on success\n const outputResult = await activityDef.output[\"~standard\"].validate(result.value);\n if (outputResult.issues) {\n throw new ActivityOutputValidationError(activityName, outputResult.issues);\n }\n return outputResult.value;\n } else {\n // Convert Result.Error to thrown ActivityError for Temporal\n throw result.error;\n }\n };\n }\n\n // 1) Wrap global activities defined directly under contract.activities\n if (contract.activities) {\n for (const [activityName, impl] of Object.entries(activities)) {\n // Skip workflow namespaces if present at root\n if (contract.workflows && activityName in contract.workflows) {\n continue;\n }\n\n const activityDef = contract.activities[activityName];\n if (!activityDef) {\n throw new ActivityDefinitionNotFoundError(activityName, Object.keys(contract.activities));\n }\n\n // Assign wrapped global activity\n (wrappedActivities as Record<string, unknown>)[activityName] = makeWrapped(\n activityName,\n activityDef,\n impl as (args: unknown) => Future<Result<unknown, ActivityError>>,\n );\n }\n }\n\n // 2) Wrap workflow-scoped activities at root level (flat)\n if (contract.workflows) {\n for (const [workflowName, workflowDef] of Object.entries(contract.workflows)) {\n const wfActivitiesImpl = (activities as Record<string, unknown>)[workflowName] as\n | Record<string, unknown>\n | undefined;\n if (!wfActivitiesImpl) {\n // If no implementations provided for this workflow, skip (TypeScript typing should enforce completeness for declared ones)\n continue;\n }\n\n const wfDefs = workflowDef.activities ?? {};\n\n for (const [activityName, impl] of Object.entries(wfActivitiesImpl)) {\n const activityDef = wfDefs[activityName];\n if (!activityDef) {\n throw new ActivityDefinitionNotFoundError(\n `${workflowName}.${activityName}`,\n Object.keys(wfDefs),\n );\n }\n\n // Assign workflow activity directly at root level (flat structure)\n (wrappedActivities as Record<string, unknown>)[activityName] = makeWrapped(\n `${workflowName}.${activityName}`,\n activityDef,\n impl as (args: unknown) => Future<Result<unknown, ActivityError>>,\n );\n }\n }\n }\n\n return wrappedActivities;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,sBAGd,UAAqB,cAAiE;CAEtF,MAAM,qBADc,SAAS,UAAU,eAEiC,cAAc,EAAE;AAKxF,QAAO;EACL,GALuB,SAAS,cAAc,EAAE;EAMhD,GAAG;EACJ;;;;;;;;;;;;;;;AAgBH,SAAgB,yBAGd,UAAqB,cAAuC;CAC5D,MAAM,aAAa,sBAAsB,UAAU,aAAa;AAChE,QAAO,OAAO,KAAK,WAAW;;;;;;;;;;;;;;;;;AAkBhC,SAAgB,mBAGd,UAAqB,cAA6B,cAA+B;AAEjF,QAAO,gBADY,sBAAsB,UAAU,aAAa;;;;;;;;;;;;;;AAgBlE,SAAgB,iBACd,UACqC;AACrC,QAAO,OAAO,KAAK,SAAS,UAAU;;;;;;;;;ACtExC,IAAa,gBAAb,MAAa,sBAAsB,MAAM;CACvC,YACE,A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K,MAAM,CAAC,cAAc,SAAS,OAAO,QAAQ,iBAAiB,EAAE;GACnE,MAAM,cAAc,OAAO;AAC3B,OAAI,CAAC,YACH,OAAM,IAAI,gCACR,GAAG,aAAa,GAAG,gBACnB,OAAO,KAAK,OAAO,CACpB;AAIH,GAAC,kBAA8C,gBAAgB,YAC7D,GAAG,aAAa,GAAG,gBACnB,aACA,KACD;;;AAKP,QAAO"}
1
+ {"version":3,"file":"activity.mjs","names":[],"sources":["../src/activity.ts"],"sourcesContent":["// Entry point for activity implementations.\n//\n// Activities run *outside* the workflow sandbox, so they can use any\n// implementation of the Result/Future pattern — we standardize on\n// `@swan-io/boxed` here for its richer API. Workflow code (see workflow.ts)\n// must use `@temporal-contract/boxed` instead, since it's compatible with\n// Temporal's deterministic replay machinery.\n//\n// Errors flow through Temporal's `ApplicationFailure` (re-exported from\n// `@temporalio/common`) — it's the SDK's first-class failure shape, so we\n// don't wrap it in a custom class. `ApplicationFailure` exposes\n// `nonRetryable`, `type`, `details`, and `category` natively, and survives\n// the activity → workflow serialization boundary unchanged.\nimport { ActivityDefinition, ContractDefinition } from \"@temporal-contract/contract\";\nimport { Future, Result } from \"@swan-io/boxed\";\nimport { ApplicationFailure } from \"@temporalio/common\";\nimport { WorkerInferInput, WorkerInferOutput } from \"./types.js\";\nimport {\n ActivityDefinitionNotFoundError,\n ActivityInputValidationError,\n ActivityOutputValidationError,\n} from \"./errors.js\";\nimport { extractHandlerInput } from \"./internal.js\";\n\nexport {\n ActivityDefinitionNotFoundError,\n ActivityInputValidationError,\n ActivityOutputValidationError,\n} from \"./errors.js\";\n\n// Re-export the canonical activity-failure class so consumers don't need\n// a separate `@temporalio/common` import to construct one.\nexport { ApplicationFailure } from \"@temporalio/common\";\n\n/**\n * Activity implementation using Future/Result pattern.\n *\n * Returns `Future<Result<Output, ApplicationFailure>>` for explicit error\n * handling instead of throwing. The wrapper rethrows `Result.Error`\n * payloads at the activity boundary; Temporal recognizes\n * `ApplicationFailure` natively and applies the configured retry policy\n * (with `nonRetryable: true` opting an instance out per-call).\n */\ntype BoxedActivityImplementation<TActivity extends ActivityDefinition> = (\n args: WorkerInferInput<TActivity>,\n) => Future<Result<WorkerInferOutput<TActivity>, ApplicationFailure>>;\n\n/**\n * Map of all activity implementations for a contract (global + all workflow-specific)\n */\ntype ContractBoxedActivitiesImplementations<TContract extends ContractDefinition> =\n // Global activities\n (TContract[\"activities\"] extends Record<string, ActivityDefinition>\n ? BoxedActivitiesImplementations<TContract[\"activities\"]>\n : {}) &\n // All workflow-specific activities merged\n {\n [TWorkflow in keyof TContract[\"workflows\"]]: TContract[\"workflows\"][TWorkflow][\"activities\"] extends Record<\n string,\n ActivityDefinition\n >\n ? BoxedActivitiesImplementations<TContract[\"workflows\"][TWorkflow][\"activities\"]>\n : {};\n };\n\ntype BoxedActivitiesImplementations<TActivities extends Record<string, ActivityDefinition>> = {\n [K in keyof TActivities]: BoxedActivityImplementation<TActivities[K]>;\n};\n\n/**\n * Options for creating activities handler\n */\ntype DeclareActivitiesHandlerOptions<TContract extends ContractDefinition> = {\n contract: TContract;\n activities: ContractBoxedActivitiesImplementations<TContract>;\n};\n\ntype ActivityImplementation<TActivity extends ActivityDefinition> = (\n args: WorkerInferInput<TActivity>,\n) => Promise<WorkerInferOutput<TActivity>>;\n\ntype ActivitiesImplementations<TActivities extends Record<string, ActivityDefinition>> = {\n [K in keyof TActivities]: ActivityImplementation<TActivities[K]>;\n};\n\ntype UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (\n k: infer I,\n) => void\n ? I\n : never;\n\n/**\n * Activities handler ready for Temporal Worker\n *\n * Flat structure: all activities (global + all workflow-specific) are at the root level\n */\nexport type ActivitiesHandler<TContract extends ContractDefinition> =\n // Global activities\n (TContract[\"activities\"] extends Record<string, ActivityDefinition>\n ? ActivitiesImplementations<TContract[\"activities\"]>\n : {}) &\n // All workflow-specific activities merged at root level (flat)\n UnionToIntersection<\n {\n [TWorkflow in keyof TContract[\"workflows\"]]: TContract[\"workflows\"][TWorkflow][\"activities\"] extends Record<\n string,\n ActivityDefinition\n >\n ? ActivitiesImplementations<TContract[\"workflows\"][TWorkflow][\"activities\"]>\n : {};\n }[keyof TContract[\"workflows\"]]\n >;\n\n/**\n * Create a typed activities handler with automatic validation and Result pattern.\n *\n * This wraps all activity implementations with:\n * - Validation at network boundaries\n * - `Result<T, ApplicationFailure>` pattern for explicit error handling\n * - Automatic conversion from Result to Promise (throwing on Error)\n *\n * TypeScript ensures ALL activities (global + workflow-specific) are implemented.\n *\n * Use this to create the activities object for the Temporal Worker.\n *\n * @example\n * ```ts\n * import { declareActivitiesHandler, ApplicationFailure } from '@temporal-contract/worker/activity';\n * import { Result, Future } from '@swan-io/boxed';\n * import myContract from './contract';\n *\n * export const activities = declareActivitiesHandler({\n * contract: myContract,\n * activities: {\n * // Activity returns Result instead of throwing.\n * sendEmail: (args) => {\n * return Future.make(async (resolve) => {\n * try {\n * await emailService.send(args);\n * resolve(Result.Ok({ sent: true }));\n * } catch (error) {\n * // Wrap technical errors in ApplicationFailure. `nonRetryable`\n * // is per-instance: set it to true on permanent failures so\n * // Temporal stops retrying immediately.\n * resolve(Result.Error(\n * ApplicationFailure.create({\n * type: 'EMAIL_SEND_FAILED',\n * message: 'Failed to send email',\n * nonRetryable: false,\n * cause: error instanceof Error ? error : undefined,\n * }),\n * ));\n * }\n * });\n * },\n * },\n * });\n *\n * // Use with Temporal Worker\n * import { Worker } from '@temporalio/worker';\n *\n * const worker = await Worker.create({\n * workflowsPath: require.resolve('./workflows'),\n * activities: activities,\n * taskQueue: contract.taskQueue,\n * });\n * ```\n *\n * @remarks\n * The wrapper accepts implementations in the\n * `Future<Result<T, ApplicationFailure>>` shape and produces ordinary\n * Promise-returning Temporal handlers (Result.Error → thrown\n * `ApplicationFailure`; Result.Ok → output validated against the\n * contract and resolved). It does **not** hide Temporal's\n * `@temporalio/activity` runtime: inside the body you can still call\n * `Context.current()` from `@temporalio/activity` to access heartbeats\n * (`heartbeat(details)`, `heartbeatDetails`), activity info (attempt\n * number, workflow IDs), and the async-completion task token. See the\n * \"Working with the Activity Context\" section of the worker\n * implementation guide for end-to-end examples.\n */\nexport function declareActivitiesHandler<TContract extends ContractDefinition>(\n options: DeclareActivitiesHandlerOptions<TContract>,\n): ActivitiesHandler<TContract> {\n const { contract, activities } = options;\n\n // Prepare Temporal-compatible activities with validation and Result unwrapping\n const wrappedActivities = {} as ActivitiesHandler<TContract>;\n\n // Helper to create a wrapped implementation from a definition and impl\n function makeWrapped(\n activityName: string,\n activityDef: ActivityDefinition,\n activityImpl: (args: unknown) => Future<Result<unknown, ApplicationFailure>>,\n ) {\n return async (...args: unknown[]) => {\n const input = extractHandlerInput(args);\n\n // Validate input\n const inputResult = await activityDef.input[\"~standard\"].validate(input);\n if (inputResult.issues) {\n throw new ActivityInputValidationError(activityName, inputResult.issues);\n }\n\n // Execute boxed activity (returns Future<Result<T, ApplicationFailure>>)\n const futureResult = activityImpl(inputResult.value);\n\n // Await Future and unwrap Result\n const result = await futureResult;\n\n // Process result: validate output or throw error\n if (result.isOk()) {\n // Validate output on success\n const outputResult = await activityDef.output[\"~standard\"].validate(result.value);\n if (outputResult.issues) {\n throw new ActivityOutputValidationError(activityName, outputResult.issues);\n }\n return outputResult.value;\n } else {\n // Convert Result.Error to thrown ApplicationFailure for Temporal.\n // Temporal recognizes this class natively and applies the\n // configured retry policy (honoring `nonRetryable: true`).\n throw result.error;\n }\n };\n }\n\n // 1) Wrap global activities defined directly under contract.activities\n if (contract.activities) {\n for (const [activityName, impl] of Object.entries(activities)) {\n // Skip workflow namespaces if present at root\n if (contract.workflows && activityName in contract.workflows) {\n continue;\n }\n\n const activityDef = contract.activities[activityName];\n if (!activityDef) {\n throw new ActivityDefinitionNotFoundError(activityName, Object.keys(contract.activities));\n }\n\n // Assign wrapped global activity\n (wrappedActivities as Record<string, unknown>)[activityName] = makeWrapped(\n activityName,\n activityDef,\n impl as (args: unknown) => Future<Result<unknown, ApplicationFailure>>,\n );\n }\n }\n\n // 2) Wrap workflow-scoped activities at root level (flat)\n if (contract.workflows) {\n for (const [workflowName, workflowDef] of Object.entries(contract.workflows)) {\n const wfActivitiesImpl = (activities as Record<string, unknown>)[workflowName] as\n | Record<string, unknown>\n | undefined;\n if (!wfActivitiesImpl) {\n // If no implementations provided for this workflow, skip (TypeScript typing should enforce completeness for declared ones)\n continue;\n }\n\n const wfDefs = workflowDef.activities ?? {};\n\n for (const [activityName, impl] of Object.entries(wfActivitiesImpl)) {\n const activityDef = wfDefs[activityName];\n if (!activityDef) {\n throw new ActivityDefinitionNotFoundError(\n `${workflowName}.${activityName}`,\n Object.keys(wfDefs),\n );\n }\n\n // Assign workflow activity directly at root level (flat structure)\n (wrappedActivities as Record<string, unknown>)[activityName] = makeWrapped(\n `${workflowName}.${activityName}`,\n activityDef,\n impl as (args: unknown) => Future<Result<unknown, ApplicationFailure>>,\n );\n }\n }\n }\n\n return wrappedActivities;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqLA,SAAgB,yBACd,SAC8B;CAC9B,MAAM,EAAE,UAAU,eAAe;CAGjC,MAAM,oBAAoB,EAAE;CAG5B,SAAS,YACP,cACA,aACA,cACA;AACA,SAAO,OAAO,GAAG,SAAoB;GACnC,MAAM,QAAQ,oBAAoB,KAAK;GAGvC,MAAM,cAAc,MAAM,YAAY,MAAM,aAAa,SAAS,MAAM;AACxE,OAAI,YAAY,OACd,OAAM,IAAI,6BAA6B,cAAc,YAAY,OAAO;GAO1E,MAAM,SAAS,MAHM,aAAa,YAAY,MAGb;AAGjC,OAAI,OAAO,MAAM,EAAE;IAEjB,MAAM,eAAe,MAAM,YAAY,OAAO,aAAa,SAAS,OAAO,MAAM;AACjF,QAAI,aAAa,OACf,OAAM,IAAI,8BAA8B,cAAc,aAAa,OAAO;AAE5E,WAAO,aAAa;SAKpB,OAAM,OAAO;;;AAMnB,KAAI,SAAS,WACX,MAAK,MAAM,CAAC,cAAc,SAAS,OAAO,QAAQ,WAAW,EAAE;AAE7D,MAAI,SAAS,aAAa,gBAAgB,SAAS,UACjD;EAGF,MAAM,cAAc,SAAS,WAAW;AACxC,MAAI,CAAC,YACH,OAAM,IAAI,gCAAgC,cAAc,OAAO,KAAK,SAAS,WAAW,CAAC;AAI1F,oBAA8C,gBAAgB,YAC7D,cACA,aACA,KACD;;AAKL,KAAI,SAAS,UACX,MAAK,MAAM,CAAC,cAAc,gBAAgB,OAAO,QAAQ,SAAS,UAAU,EAAE;EAC5E,MAAM,mBAAoB,WAAuC;AAGjE,MAAI,CAAC,iBAEH;EAGF,MAAM,SAAS,YAAY,cAAc,EAAE;AAE3C,OAAK,MAAM,CAAC,cAAc,SAAS,OAAO,QAAQ,iBAAiB,EAAE;GACnE,MAAM,cAAc,OAAO;AAC3B,OAAI,CAAC,YACH,OAAM,IAAI,gCACR,GAAG,aAAa,GAAG,gBACnB,OAAO,KAAK,OAAO,CACpB;AAIF,qBAA8C,gBAAgB,YAC7D,GAAG,aAAa,GAAG,gBACnB,aACA,KACD;;;AAKP,QAAO"}
@@ -132,6 +132,18 @@ declare class ChildWorkflowNotFoundError extends WorkerError {
132
132
  declare class ChildWorkflowError extends WorkerError {
133
133
  constructor(message: string, cause?: unknown);
134
134
  }
135
+ /**
136
+ * Error returned in the `Result.Error` branch when a typed cancellation
137
+ * scope is cancelled via Temporal's cancellation propagation. Returned by
138
+ * both `context.cancellableScope` (when the workflow or an ancestor scope
139
+ * cancels) and `context.nonCancellableScope` (when cancellation is raised
140
+ * from inside the scope). Distinct from arbitrary thrown errors so call
141
+ * sites can branch on cancellation explicitly while still surfacing
142
+ * non-cancellation errors as Future rejections.
143
+ */
144
+ declare class WorkflowCancelledError extends WorkerError {
145
+ constructor(cause?: unknown);
146
+ }
135
147
  //#endregion
136
- 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 };
137
- //# sourceMappingURL=errors-4jH78z8m.d.cts.map
148
+ export { WorkerInferOutput as _, ChildWorkflowNotFoundError as a, SignalInputValidationError as c, WorkflowCancelledError as d, WorkflowInputValidationError as f, WorkerInferInput as g, ClientInferOutput as h, ChildWorkflowError as i, UpdateInputValidationError as l, ClientInferInput as m, ActivityInputValidationError as n, QueryInputValidationError as o, WorkflowOutputValidationError as p, ActivityOutputValidationError as r, QueryOutputValidationError as s, ActivityDefinitionNotFoundError as t, UpdateOutputValidationError as u };
149
+ //# sourceMappingURL=errors-CG1y7SHO.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors-4jH78z8m.d.cts","names":[],"sources":["../src/types.ts","../src/errors.ts"],"mappings":";;;;;;AAOA;;KAAY,gBAAA;EAA6B,KAAA,EAAO,SAAA;AAAA,KAAe,gBAAA,CAAiB,WAAA,CAC9E,CAAA;;;;;KAOU,iBAAA;EAA8B,MAAA,EAAQ,SAAA;AAAA,KAAe,gBAAA,CAAiB,UAAA,CAChF,CAAA;;;;;KAOU,gBAAA;EAA6B,KAAA,EAAO,SAAA;AAAA,KAAe,gBAAA,CAAiB,UAAA,CAC9E,CAAA;;;;;KAOU,iBAAA;EAA8B,MAAA,EAAQ,SAAA;AAAA,KAAe,gBAAA,CAAiB,WAAA,CAChF,CAAA;;;;;;uBC3Ba,WAAA,SAAoB,KAAA;EAAA,UACxB,WAAA,CAAa,OAAA,UAAiB,KAAA;AAAA;;;;cAa5B,+BAAA,SAAwC,WAAA;EAAA,SAEjC,YAAA;EAAA,SACA,oBAAA;cADA,YAAA,UACA,oBAAA;AAAA;;;;cAaP,4BAAA,SAAqC,WAAA;EAAA,SAE9B,YAAA;EA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A,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;AAAA;;;AArH3D;cAgIa,2BAAA,SAAoC,WAAA;EAAA,SAE7B,UAAA;EAAA,SACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;cADvC,UAAA,UACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;AAAA;;;;cAW9C,0BAAA,SAAmC,WAAA;EAAA,SAE5B,YAAA;EAAA,SACA,kBAAA;cADA,YAAA,UACA,kBAAA;AAAA;;;;cAWP,kBAAA,SAA2B,WAAA;cAC1B,OAAA,UAAiB,KAAA;AAAA;;;;;;;;;;cAelB,sBAAA,SAA+B,WAAA;cAC9B,KAAA;AAAA"}
@@ -132,6 +132,18 @@ declare class ChildWorkflowNotFoundError extends WorkerError {
132
132
  declare class ChildWorkflowError extends WorkerError {
133
133
  constructor(message: string, cause?: unknown);
134
134
  }
135
+ /**
136
+ * Error returned in the `Result.Error` branch when a typed cancellation
137
+ * scope is cancelled via Temporal's cancellation propagation. Returned by
138
+ * both `context.cancellableScope` (when the workflow or an ancestor scope
139
+ * cancels) and `context.nonCancellableScope` (when cancellation is raised
140
+ * from inside the scope). Distinct from arbitrary thrown errors so call
141
+ * sites can branch on cancellation explicitly while still surfacing
142
+ * non-cancellation errors as Future rejections.
143
+ */
144
+ declare class WorkflowCancelledError extends WorkerError {
145
+ constructor(cause?: unknown);
146
+ }
135
147
  //#endregion
136
- 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 };
137
- //# sourceMappingURL=errors-CmTXZ3JW.d.mts.map
148
+ export { WorkerInferOutput as _, ChildWorkflowNotFoundError as a, SignalInputValidationError as c, WorkflowCancelledError as d, WorkflowInputValidationError as f, WorkerInferInput as g, ClientInferOutput as h, ChildWorkflowError as i, UpdateInputValidationError as l, ClientInferInput as m, ActivityInputValidationError as n, QueryInputValidationError as o, WorkflowOutputValidationError as p, ActivityOutputValidationError as r, QueryOutputValidationError as s, ActivityDefinitionNotFoundError as t, UpdateOutputValidationError as u };
149
+ //# sourceMappingURL=errors-DZhaNhwr.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors-CmTXZ3JW.d.mts","names":[],"sources":["../src/types.ts","../src/errors.ts"],"mappings":";;;;;;AAOA;;KAAY,gBAAA;EAA6B,KAAA,EAAO,SAAA;AAAA,KAAe,gBAAA,CAAiB,WAAA,CAC9E,CAAA;;;;;KAOU,iBAAA;EAA8B,MAAA,EAAQ,SAAA;AAAA,KAAe,gBAAA,CAAiB,UAAA,CAChF,CAAA;;;;;KAOU,gBAAA;EAA6B,KAAA,EAAO,SAAA;AAAA,KAAe,gBAAA,CAAiB,UAAA,CAC9E,CAAA;;;;;KAOU,iBAAA;EAA8B,MAAA,EAAQ,SAAA;AAAA,KAAe,gBAAA,CAAiB,WAAA,CAChF,CAAA;;;;;;uBC3Ba,WAAA,SAAoB,KAAA;EAAA,UACxB,WAAA,CAAa,OAAA,UAAiB,KAAA;AAAA;;;;cAa5B,+BAAA,SAAwC,WAAA;EAAA,SAEjC,YAAA;EAAA,SACA,oBAAA;cADA,YAAA,UACA,oBAAA;AAAA;;;;cAaP,4BAAA,SAAqC,WAAA;EAAA,SAE9B,YAAA;EAAA,SACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;cADvC,YAAA,UACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;AAAA;;;;cAW9C,6BAAA,SAAsC,WAAA;EAAA,SAE/B,YAAA;EAAA,SACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;cADvC,YAAA,UACA,MAAA,E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