@temporal-contract/worker 0.1.0 → 0.2.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/README.md CHANGED
@@ -41,6 +41,7 @@ import { declareWorkflow } from "@temporal-contract/worker/workflow";
41
41
  export const processOrder = declareWorkflow({
42
42
  workflowName: "processOrder",
43
43
  contract: myContract,
44
+ activityOptions: { startToCloseTimeout: "1 minute" },
44
45
  implementation: async ({ activities }, input) => {
45
46
  // Activities return plain values (Result is unwrapped internally)
46
47
  await activities.sendEmail({ to: "user@example.com", body: "Done!" });
@@ -77,9 +78,10 @@ import { declareWorkflow } from "@temporal-contract/worker/workflow";
77
78
  export const parentWorkflow = declareWorkflow({
78
79
  workflowName: "parentWorkflow",
79
80
  contract: myContract,
80
- implementation: async ({ executeChildWorkflow }, input) => {
81
+ activityOptions: { startToCloseTimeout: "1 minute" },
82
+ implementation: async (context, input) => {
81
83
  // Execute child workflow from same contract and wait for result
82
- const childResult = await executeChildWorkflow(myContract, "processPayment", {
84
+ const childResult = await context.executeChildWorkflow(myContract, "processPayment", {
83
85
  workflowId: `payment-${input.orderId}`,
84
86
  args: { amount: input.totalAmount },
85
87
  });
@@ -90,7 +92,7 @@ export const parentWorkflow = declareWorkflow({
90
92
  });
91
93
 
92
94
  // Execute child workflow from another contract (another worker)
93
- const notificationResult = await executeChildWorkflow(
95
+ const notificationResult = await context.executeChildWorkflow(
94
96
  notificationContract,
95
97
  "sendNotification",
96
98
  {
@@ -100,7 +102,7 @@ export const parentWorkflow = declareWorkflow({
100
102
  );
101
103
 
102
104
  // Or start child workflow without waiting
103
- const handleResult = await startChildWorkflow(myContract, "sendEmail", {
105
+ const handleResult = await context.startChildWorkflow(myContract, "sendEmail", {
104
106
  workflowId: `email-${input.orderId}`,
105
107
  args: { to: "user@example.com", body: "Order received" },
106
108
  });
@@ -0,0 +1,68 @@
1
+ import { ActivityDefinition, ContractDefinition } from "@temporal-contract/contract";
2
+
3
+ //#region src/activity-utils.d.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
+ declare function getWorkflowActivities<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]>(contract: TContract, workflowName: TWorkflowName): Record<string, ActivityDefinition>;
23
+ /**
24
+ * Extract all activity names for a specific workflow from a contract
25
+ *
26
+ * @param contract - The contract definition
27
+ * @param workflowName - The name of the workflow
28
+ * @returns Array of activity names (strings) available for the workflow
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const activityNames = getWorkflowActivityNames(myContract, 'processOrder');
33
+ * // Returns: ['processPayment', 'reserveInventory', 'sendEmail']
34
+ * ```
35
+ */
36
+ declare function getWorkflowActivityNames<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]>(contract: TContract, workflowName: TWorkflowName): string[];
37
+ /**
38
+ * Check if an activity belongs to a specific workflow
39
+ *
40
+ * @param contract - The contract definition
41
+ * @param workflowName - The name of the workflow
42
+ * @param activityName - The name of the activity to check
43
+ * @returns True if the activity is available for the workflow, false otherwise
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * if (isWorkflowActivity(myContract, 'processOrder', 'processPayment')) {
48
+ * // Activity is available for this workflow
49
+ * }
50
+ * ```
51
+ */
52
+ declare function isWorkflowActivity<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]>(contract: TContract, workflowName: TWorkflowName, activityName: string): boolean;
53
+ /**
54
+ * Get all workflow names from a contract
55
+ *
56
+ * @param contract - The contract definition
57
+ * @returns Array of workflow names defined in the contract
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const workflows = getWorkflowNames(myContract);
62
+ * // Returns: ['processOrder', 'processRefund']
63
+ * ```
64
+ */
65
+ declare function getWorkflowNames<TContract extends ContractDefinition>(contract: TContract): Array<keyof TContract["workflows"]>;
66
+ //#endregion
67
+ export { isWorkflowActivity as i, getWorkflowActivityNames as n, getWorkflowNames as r, getWorkflowActivities as t };
68
+ //# sourceMappingURL=activity-utils-B3vP03_P.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activity-utils-B3vP03_P.d.mts","names":[],"sources":["../src/activity-utils.ts"],"mappings":";;;;;AAqBA;;;;;;;;;;;;;;;;iBAAgB,qBAAA,mBACI,kBAAA,8BACU,SAAA,cAAA,CAC5B,QAAA,EAAU,SAAA,EAAW,YAAA,EAAc,aAAA,GAAgB,MAAA,SAAe,kBAAA;;;;;;;AA2BpE;;;;;;;iBAAgB,wBAAA,mBACI,kBAAA,8BACU,SAAA,cAAA,CAC5B,QAAA,EAAU,SAAA,EAAW,YAAA,EAAc,aAAA;;;;;;;;;;;;AAoBrC;;;;iBAAgB,kBAAA,mBACI,kBAAA,8BACU,SAAA,cAAA,CAC5B,QAAA,EAAU,SAAA,EAAW,YAAA,EAAc,aAAA,EAAe,YAAA;;;;;;;;;;;;;iBAiBpC,gBAAA,mBAAmC,kBAAA,CAAA,CACjD,QAAA,EAAU,SAAA,GACT,KAAA,OAAY,SAAA"}
@@ -0,0 +1,68 @@
1
+ import { ActivityDefinition, ContractDefinition } from "@temporal-contract/contract";
2
+
3
+ //#region src/activity-utils.d.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
+ declare function getWorkflowActivities<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]>(contract: TContract, workflowName: TWorkflowName): Record<string, ActivityDefinition>;
23
+ /**
24
+ * Extract all activity names for a specific workflow from a contract
25
+ *
26
+ * @param contract - The contract definition
27
+ * @param workflowName - The name of the workflow
28
+ * @returns Array of activity names (strings) available for the workflow
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const activityNames = getWorkflowActivityNames(myContract, 'processOrder');
33
+ * // Returns: ['processPayment', 'reserveInventory', 'sendEmail']
34
+ * ```
35
+ */
36
+ declare function getWorkflowActivityNames<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]>(contract: TContract, workflowName: TWorkflowName): string[];
37
+ /**
38
+ * Check if an activity belongs to a specific workflow
39
+ *
40
+ * @param contract - The contract definition
41
+ * @param workflowName - The name of the workflow
42
+ * @param activityName - The name of the activity to check
43
+ * @returns True if the activity is available for the workflow, false otherwise
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * if (isWorkflowActivity(myContract, 'processOrder', 'processPayment')) {
48
+ * // Activity is available for this workflow
49
+ * }
50
+ * ```
51
+ */
52
+ declare function isWorkflowActivity<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]>(contract: TContract, workflowName: TWorkflowName, activityName: string): boolean;
53
+ /**
54
+ * Get all workflow names from a contract
55
+ *
56
+ * @param contract - The contract definition
57
+ * @returns Array of workflow names defined in the contract
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const workflows = getWorkflowNames(myContract);
62
+ * // Returns: ['processOrder', 'processRefund']
63
+ * ```
64
+ */
65
+ declare function getWorkflowNames<TContract extends ContractDefinition>(contract: TContract): Array<keyof TContract["workflows"]>;
66
+ //#endregion
67
+ export { isWorkflowActivity as i, getWorkflowActivityNames as n, getWorkflowNames as r, getWorkflowActivities as t };
68
+ //# sourceMappingURL=activity-utils-RsXOceIH.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activity-utils-RsXOceIH.d.cts","names":[],"sources":["../src/activity-utils.ts"],"mappings":";;;;;AAqBA;;;;;;;;;;;;;;;;iBAAgB,qBAAA,mBACI,kBAAA,8BACU,SAAA,cAAA,CAC5B,QAAA,EAAU,SAAA,EAAW,YAAA,EAAc,aAAA,GAAgB,MAAA,SAAe,kBAAA;;;;;;;AA2BpE;;;;;;;iBAAgB,wBAAA,mBACI,kBAAA,8BACU,SAAA,cAAA,CAC5B,QAAA,EAAU,SAAA,EAAW,YAAA,EAAc,aAAA;;;;;;;;;;;;AAoBrC;;;;iBAAgB,kBAAA,mBACI,kBAAA,8BACU,SAAA,cAAA,CAC5B,QAAA,EAAU,SAAA,EAAW,YAAA,EAAc,aAAA,EAAe,YAAA;;;;;;;;;;;;;iBAiBpC,gBAAA,mBAAmC,kBAAA,CAAA,CACjD,QAAA,EAAU,SAAA,GACT,KAAA,OAAY,SAAA"}
package/dist/activity.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
2
  const require_errors = require('./errors-DjSZg-93.cjs');
2
3
 
3
4
  //#region src/activity-utils.ts
@@ -1,3 +1,99 @@
1
- import { n as ActivityInputValidationError, r as ActivityOutputValidationError, t as ActivityDefinitionNotFoundError } from "./errors-CXpHOFmk.cjs";
2
- import { a as getWorkflowActivityNames, i as getWorkflowActivities, n as ActivityError, o as getWorkflowNames, r as declareActivitiesHandler, s as isWorkflowActivity, t as ActivitiesHandler } from "./activity-5pVNjW7l.cjs";
3
- export { ActivitiesHandler, ActivityDefinitionNotFoundError, ActivityError, ActivityInputValidationError, ActivityOutputValidationError, declareActivitiesHandler, getWorkflowActivities, getWorkflowActivityNames, getWorkflowNames, isWorkflowActivity };
1
+ import { g as WorkerInferOutput, h as WorkerInferInput, n as ActivityInputValidationError, r as ActivityOutputValidationError, t as ActivityDefinitionNotFoundError } from "./errors-4jH78z8m.cjs";
2
+ import { i as isWorkflowActivity, n as getWorkflowActivityNames, r as getWorkflowNames, t as getWorkflowActivities } from "./activity-utils-RsXOceIH.cjs";
3
+ import { ActivityDefinition, ContractDefinition } from "@temporal-contract/contract";
4
+ import { Future, Result } from "@swan-io/boxed";
5
+
6
+ //#region src/activity.d.ts
7
+ /**
8
+ * Activity error class that should be used to wrap all technical exceptions
9
+ * Forces proper error handling and enables retry policies
10
+ */
11
+ declare class ActivityError extends Error {
12
+ readonly code: string;
13
+ constructor(code: string, message: string, cause?: unknown);
14
+ }
15
+ /**
16
+ * Activity implementation using Future/Result pattern
17
+ *
18
+ * Returns Future<Result<Output, ActivityError>> for explicit error handling instead of throwing exceptions.
19
+ * All errors must be wrapped in ActivityError to enable proper retry policies.
20
+ */
21
+ type BoxedActivityImplementation<TActivity extends ActivityDefinition> = (args: WorkerInferInput<TActivity>) => Future<Result<WorkerInferOutput<TActivity>, ActivityError>>;
22
+ /**
23
+ * Map of all activity implementations for a contract (global + all workflow-specific)
24
+ */
25
+ type ContractBoxedActivitiesImplementations<TContract extends ContractDefinition> = (TContract["activities"] extends Record<string, ActivityDefinition> ? BoxedActivitiesImplementations<TContract["activities"]> : {}) & { [TWorkflow in keyof TContract["workflows"]]: TContract["workflows"][TWorkflow]["activities"] extends Record<string, ActivityDefinition> ? BoxedActivitiesImplementations<TContract["workflows"][TWorkflow]["activities"]> : {} };
26
+ type BoxedActivitiesImplementations<TActivities extends Record<string, ActivityDefinition>> = { [K in keyof TActivities]: BoxedActivityImplementation<TActivities[K]> };
27
+ /**
28
+ * Options for creating activities handler
29
+ */
30
+ type DeclareActivitiesHandlerOptions<TContract extends ContractDefinition> = {
31
+ contract: TContract;
32
+ activities: ContractBoxedActivitiesImplementations<TContract>;
33
+ };
34
+ type ActivityImplementation<TActivity extends ActivityDefinition> = (args: WorkerInferInput<TActivity>) => Promise<WorkerInferOutput<TActivity>>;
35
+ type ActivitiesImplementations<TActivities extends Record<string, ActivityDefinition>> = { [K in keyof TActivities]: ActivityImplementation<TActivities[K]> };
36
+ type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
37
+ /**
38
+ * Activities handler ready for Temporal Worker
39
+ *
40
+ * Flat structure: all activities (global + all workflow-specific) are at the root level
41
+ */
42
+ type ActivitiesHandler<TContract extends ContractDefinition> = (TContract["activities"] extends Record<string, ActivityDefinition> ? ActivitiesImplementations<TContract["activities"]> : {}) & UnionToIntersection<{ [TWorkflow in keyof TContract["workflows"]]: TContract["workflows"][TWorkflow]["activities"] extends Record<string, ActivityDefinition> ? ActivitiesImplementations<TContract["workflows"][TWorkflow]["activities"]> : {} }[keyof TContract["workflows"]]>;
43
+ /**
44
+ * Create a typed activities handler with automatic validation and Result pattern
45
+ *
46
+ * This wraps all activity implementations with:
47
+ * - Validation at network boundaries
48
+ * - Result<T, ActivityError> pattern for explicit error handling
49
+ * - Automatic conversion from Result to Promise (throwing on Error)
50
+ *
51
+ * TypeScript ensures ALL activities (global + workflow-specific) are implemented.
52
+ *
53
+ * Use this to create the activities object for the Temporal Worker.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { declareActivitiesHandler, ActivityError } from '@temporal-contract/worker/activity';
58
+ * import { Result, Future } from '@swan-io/boxed';
59
+ * import myContract from './contract';
60
+ *
61
+ * export const activities = declareActivitiesHandler({
62
+ * contract: myContract,
63
+ * activities: {
64
+ * // Activity returns Result instead of throwing
65
+ * // All technical exceptions must be wrapped in ActivityError for retry policies
66
+ * sendEmail: (args) => {
67
+ * return Future.make(async resolve => {
68
+ * try {
69
+ * await emailService.send(args);
70
+ * resolve(Result.Ok({ sent: true }));
71
+ * } catch (error) {
72
+ * // Wrap technical errors in ActivityError to enable retries
73
+ * resolve(Result.Error(
74
+ * new ActivityError(
75
+ * 'EMAIL_SEND_FAILED',
76
+ * 'Failed to send email',
77
+ * error // Original error as cause for debugging
78
+ * )
79
+ * ));
80
+ * }
81
+ * });
82
+ * },
83
+ * },
84
+ * });
85
+ *
86
+ * // Use with Temporal Worker
87
+ * import { Worker } from '@temporalio/worker';
88
+ *
89
+ * const worker = await Worker.create({
90
+ * workflowsPath: require.resolve('./workflows'),
91
+ * activities: activities,
92
+ * taskQueue: contract.taskQueue,
93
+ * });
94
+ * ```
95
+ */
96
+ declare function declareActivitiesHandler<TContract extends ContractDefinition>(options: DeclareActivitiesHandlerOptions<TContract>): ActivitiesHandler<TContract>;
97
+ //#endregion
98
+ export { ActivitiesHandler, ActivityDefinitionNotFoundError, ActivityError, ActivityInputValidationError, ActivityOutputValidationError, declareActivitiesHandler, getWorkflowActivities, getWorkflowActivityNames, getWorkflowNames, isWorkflowActivity };
99
+ //# sourceMappingURL=activity.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activity.d.cts","names":[],"sources":["../src/activity.ts"],"mappings":";;;;;;;AA2BA;;;cAAa,aAAA,SAAsB,KAAA;EAAA,SAEf,IAAA;cAAA,IAAA,UAChB,OAAA,UACA,KAAA;AAAA;;;;;;AASH;KAQI,2BAAA,mBAA8C,kBAAA,KACjD,IAAA,EAAM,gBAAA,CAAiB,SAAA,MACpB,MAAA,CAAO,MAAA,CAAO,iBAAA,CAAkB,SAAA,GAAY,aAAA;;;;KAK5C,sCAAA,mBAAyD,kBAAA,KAE3D,SAAA,uBAAgC,MAAA,SAAe,kBAAA,IAC5C,8BAAA,CAA+B,SAAA,8CAIX,SAAA,gBAAyB,SAAA,cAAuB,SAAA,wBAAiC,MAAA,SAEnG,kBAAA,IAEE,8BAAA,CAA+B,SAAA,cAAuB,SAAA;AAAA,KAI3D,8BAAA,qBAAmD,MAAA,SAAe,kBAAA,mBACzD,WAAA,GAAc,2BAAA,CAA4B,WAAA,CAAY,CAAA;;;;KAM/D,+BAAA,mBAAkD,kBAAA;EACrD,QAAA,EAAU,SAAA;EACV,UAAA,EAAY,sCAAA,CAAuC,SAAA;AAAA;AAAA,KAGhD,sBAAA,mBAAyC,kBAAA,KAC5C,IAAA,EAAM,gBAAA,CAAiB,SAAA,MACpB,OAAA,CAAQ,iBAAA,CAAkB,SAAA;AAAA,KAE1B,yBAAA,qBAA8C,MAAA,SAAe,kBAAA,mBACpD,WAAA,GAAc,sBAAA,CAAuB,WAAA,CAAY,CAAA;AAAA,KAG1D,mBAAA,OAA0B,CAAA,oBAAqB,CAAA,EAAG,CAAA,6BACrD,CAAA,sBAEE,CAAA;;;AA3C0D;;;KAmDlD,iBAAA,mBAAoC,kBAAA,KAE7C,SAAA,uBAAgC,MAAA,SAAe,kBAAA,IAC5C,yBAAA,CAA0B,SAAA,wBAG5B,mBAAA,uBAEwB,SAAA,gBAAyB,SAAA,cAAuB,SAAA,wBAAiC,MAAA,SAEnG,kBAAA,IAEE,yBAAA,CAA0B,SAAA,cAAuB,SAAA,8BAE/C,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAjD2D;;;;;;;;;;;;;;;;;;;;;AAKJ;iBAoGrD,wBAAA,mBAA2C,kBAAA,CAAA,CACzD,OAAA,EAAS,+BAAA,CAAgC,SAAA,IACxC,iBAAA,CAAkB,SAAA"}
@@ -1,3 +1,99 @@
1
- import { n as ActivityInputValidationError, r as ActivityOutputValidationError, t as ActivityDefinitionNotFoundError } from "./errors-Vr-sKdW7.mjs";
2
- import { a as getWorkflowActivityNames, i as getWorkflowActivities, n as ActivityError, o as getWorkflowNames, r as declareActivitiesHandler, s as isWorkflowActivity, t as ActivitiesHandler } from "./activity-BUEBZ7SL.mjs";
3
- export { ActivitiesHandler, ActivityDefinitionNotFoundError, ActivityError, ActivityInputValidationError, ActivityOutputValidationError, declareActivitiesHandler, getWorkflowActivities, getWorkflowActivityNames, getWorkflowNames, isWorkflowActivity };
1
+ import { g as WorkerInferOutput, h as WorkerInferInput, n as ActivityInputValidationError, r as ActivityOutputValidationError, t as ActivityDefinitionNotFoundError } from "./errors-CmTXZ3JW.mjs";
2
+ import { i as isWorkflowActivity, n as getWorkflowActivityNames, r as getWorkflowNames, t as getWorkflowActivities } from "./activity-utils-B3vP03_P.mjs";
3
+ import { ActivityDefinition, ContractDefinition } from "@temporal-contract/contract";
4
+ import { Future, Result } from "@swan-io/boxed";
5
+
6
+ //#region src/activity.d.ts
7
+ /**
8
+ * Activity error class that should be used to wrap all technical exceptions
9
+ * Forces proper error handling and enables retry policies
10
+ */
11
+ declare class ActivityError extends Error {
12
+ readonly code: string;
13
+ constructor(code: string, message: string, cause?: unknown);
14
+ }
15
+ /**
16
+ * Activity implementation using Future/Result pattern
17
+ *
18
+ * Returns Future<Result<Output, ActivityError>> for explicit error handling instead of throwing exceptions.
19
+ * All errors must be wrapped in ActivityError to enable proper retry policies.
20
+ */
21
+ type BoxedActivityImplementation<TActivity extends ActivityDefinition> = (args: WorkerInferInput<TActivity>) => Future<Result<WorkerInferOutput<TActivity>, ActivityError>>;
22
+ /**
23
+ * Map of all activity implementations for a contract (global + all workflow-specific)
24
+ */
25
+ type ContractBoxedActivitiesImplementations<TContract extends ContractDefinition> = (TContract["activities"] extends Record<string, ActivityDefinition> ? BoxedActivitiesImplementations<TContract["activities"]> : {}) & { [TWorkflow in keyof TContract["workflows"]]: TContract["workflows"][TWorkflow]["activities"] extends Record<string, ActivityDefinition> ? BoxedActivitiesImplementations<TContract["workflows"][TWorkflow]["activities"]> : {} };
26
+ type BoxedActivitiesImplementations<TActivities extends Record<string, ActivityDefinition>> = { [K in keyof TActivities]: BoxedActivityImplementation<TActivities[K]> };
27
+ /**
28
+ * Options for creating activities handler
29
+ */
30
+ type DeclareActivitiesHandlerOptions<TContract extends ContractDefinition> = {
31
+ contract: TContract;
32
+ activities: ContractBoxedActivitiesImplementations<TContract>;
33
+ };
34
+ type ActivityImplementation<TActivity extends ActivityDefinition> = (args: WorkerInferInput<TActivity>) => Promise<WorkerInferOutput<TActivity>>;
35
+ type ActivitiesImplementations<TActivities extends Record<string, ActivityDefinition>> = { [K in keyof TActivities]: ActivityImplementation<TActivities[K]> };
36
+ type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
37
+ /**
38
+ * Activities handler ready for Temporal Worker
39
+ *
40
+ * Flat structure: all activities (global + all workflow-specific) are at the root level
41
+ */
42
+ type ActivitiesHandler<TContract extends ContractDefinition> = (TContract["activities"] extends Record<string, ActivityDefinition> ? ActivitiesImplementations<TContract["activities"]> : {}) & UnionToIntersection<{ [TWorkflow in keyof TContract["workflows"]]: TContract["workflows"][TWorkflow]["activities"] extends Record<string, ActivityDefinition> ? ActivitiesImplementations<TContract["workflows"][TWorkflow]["activities"]> : {} }[keyof TContract["workflows"]]>;
43
+ /**
44
+ * Create a typed activities handler with automatic validation and Result pattern
45
+ *
46
+ * This wraps all activity implementations with:
47
+ * - Validation at network boundaries
48
+ * - Result<T, ActivityError> pattern for explicit error handling
49
+ * - Automatic conversion from Result to Promise (throwing on Error)
50
+ *
51
+ * TypeScript ensures ALL activities (global + workflow-specific) are implemented.
52
+ *
53
+ * Use this to create the activities object for the Temporal Worker.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { declareActivitiesHandler, ActivityError } from '@temporal-contract/worker/activity';
58
+ * import { Result, Future } from '@swan-io/boxed';
59
+ * import myContract from './contract';
60
+ *
61
+ * export const activities = declareActivitiesHandler({
62
+ * contract: myContract,
63
+ * activities: {
64
+ * // Activity returns Result instead of throwing
65
+ * // All technical exceptions must be wrapped in ActivityError for retry policies
66
+ * sendEmail: (args) => {
67
+ * return Future.make(async resolve => {
68
+ * try {
69
+ * await emailService.send(args);
70
+ * resolve(Result.Ok({ sent: true }));
71
+ * } catch (error) {
72
+ * // Wrap technical errors in ActivityError to enable retries
73
+ * resolve(Result.Error(
74
+ * new ActivityError(
75
+ * 'EMAIL_SEND_FAILED',
76
+ * 'Failed to send email',
77
+ * error // Original error as cause for debugging
78
+ * )
79
+ * ));
80
+ * }
81
+ * });
82
+ * },
83
+ * },
84
+ * });
85
+ *
86
+ * // Use with Temporal Worker
87
+ * import { Worker } from '@temporalio/worker';
88
+ *
89
+ * const worker = await Worker.create({
90
+ * workflowsPath: require.resolve('./workflows'),
91
+ * activities: activities,
92
+ * taskQueue: contract.taskQueue,
93
+ * });
94
+ * ```
95
+ */
96
+ declare function declareActivitiesHandler<TContract extends ContractDefinition>(options: DeclareActivitiesHandlerOptions<TContract>): ActivitiesHandler<TContract>;
97
+ //#endregion
98
+ export { ActivitiesHandler, ActivityDefinitionNotFoundError, ActivityError, ActivityInputValidationError, ActivityOutputValidationError, declareActivitiesHandler, getWorkflowActivities, getWorkflowActivityNames, getWorkflowNames, isWorkflowActivity };
99
+ //# sourceMappingURL=activity.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activity.d.mts","names":[],"sources":["../src/activity.ts"],"mappings":";;;;;;;AA2BA;;;cAAa,aAAA,SAAsB,KAAA;EAAA,SAEf,IAAA;cAAA,IAAA,UAChB,OAAA,UACA,KAAA;AAAA;;;;;;AASH;KAQI,2BAAA,mBAA8C,kBAAA,KACjD,IAAA,EAAM,gBAAA,CAAiB,SAAA,MACpB,MAAA,CAAO,MAAA,CAAO,iBAAA,CAAkB,SAAA,GAAY,aAAA;;;;KAK5C,sCAAA,mBAAyD,kBAAA,KAE3D,SAAA,uBAAgC,MAAA,SAAe,kBAAA,IAC5C,8BAAA,CAA+B,SAAA,8CAIX,SAAA,gBAAyB,SAAA,cAAuB,SAAA,wBAAiC,MAAA,SAEnG,kBAAA,IAEE,8BAAA,CAA+B,SAAA,cAAuB,SAAA;AAAA,KAI3D,8BAAA,qBAAmD,MAAA,SAAe,kBAAA,mBACzD,WAAA,GAAc,2BAAA,CAA4B,WAAA,CAAY,CAAA;;;;KAM/D,+BAAA,mBAAkD,kBAAA;EACrD,QAAA,EAAU,SAAA;EACV,UAAA,EAAY,sCAAA,CAAuC,SAAA;AAAA;AAAA,KAGhD,sBAAA,mBAAyC,kBAAA,KAC5C,IAAA,EAAM,gBAAA,CAAiB,SAAA,MACpB,OAAA,CAAQ,iBAAA,CAAkB,SAAA;AAAA,KAE1B,yBAAA,qBAA8C,MAAA,SAAe,kBAAA,mBACpD,WAAA,GAAc,sBAAA,CAAuB,WAAA,CAAY,CAAA;AAAA,KAG1D,mBAAA,OAA0B,CAAA,oBAAqB,CAAA,EAAG,CAAA,6BACrD,CAAA,sBAEE,CAAA;;;AA3C0D;;;KAmDlD,iBAAA,mBAAoC,kBAAA,KAE7C,SAAA,uBAAgC,MAAA,SAAe,kBAAA,IAC5C,yBAAA,CAA0B,SAAA,wBAG5B,mBAAA,uBAEwB,SAAA,gBAAyB,SAAA,cAAuB,SAAA,wBAAiC,MAAA,SAEnG,kBAAA,IAEE,yBAAA,CAA0B,SAAA,cAAuB,SAAA,8BAE/C,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAjD2D;;;;;;;;;;;;;;;;;;;;;AAKJ;iBAoGrD,wBAAA,mBAA2C,kBAAA,CAAA,CACzD,OAAA,EAAS,+BAAA,CAAgC,SAAA,IACxC,iBAAA,CAAkB,SAAA"}
package/dist/activity.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as ActivityInputValidationError, r as ActivityOutputValidationError, t as ActivityDefinitionNotFoundError } from "./errors-BqVTpfcf.mjs";
1
+ import { n as ActivityInputValidationError, r as ActivityOutputValidationError, t as ActivityDefinitionNotFoundError } from "./errors-Di6Ja4Rt.mjs";
2
2
 
3
3
  //#region src/activity-utils.ts
4
4
  /**
@@ -180,4 +180,5 @@ function declareActivitiesHandler(options) {
180
180
  }
181
181
 
182
182
  //#endregion
183
- export { ActivityDefinitionNotFoundError, ActivityError, ActivityInputValidationError, ActivityOutputValidationError, declareActivitiesHandler, getWorkflowActivities, getWorkflowActivityNames, getWorkflowNames, isWorkflowActivity };
183
+ export { ActivityDefinitionNotFoundError, ActivityError, ActivityInputValidationError, ActivityOutputValidationError, declareActivitiesHandler, getWorkflowActivities, getWorkflowActivityNames, getWorkflowNames, isWorkflowActivity };
184
+ //# sourceMappingURL=activity.mjs.map
@@ -0,0 +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,AAAgB,MAChB,SACA,OACA;AACA,QAAM,SAAS,EAAE,OAAO,CAAC;EAJT;AAKhB,OAAK,OAAO;AAEZ,MAAI,MAAM,kBACR,OAAM,kBAAkB,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsIlD,SAAgB,yBACd,SAC8B;CAC9B,MAAM,EAAE,UAAU,eAAe;CAGjC,MAAM,oBAAoB,EAAE;CAG5B,SAAS,YACP,cACA,aACA,cACA;AACA,SAAO,OAAO,GAAG,SAAoB;GAEnC,MAAM,QAAQ,KAAK,WAAW,IAAI,KAAK,KAAK;GAG5C,MAAM,cAAc,MAAM,YAAY,MAAM,aAAa,SAAS,MAAM;AACxE,OAAI,YAAY,OACd,OAAM,IAAI,6BAA6B,cAAc,YAAY,OAAO;GAO1E,MAAM,SAAS,MAHM,aAAa,YAAY,MAAM;AAMpD,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;SAGpB,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;AAI3F,EAAC,kBAA8C,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;AAIH,GAAC,kBAA8C,gBAAgB,YAC7D,GAAG,aAAa,GAAG,gBACnB,aACA,KACD;;;AAKP,QAAO"}
@@ -133,4 +133,5 @@ declare class ChildWorkflowError extends WorkerError {
133
133
  constructor(message: string, cause?: unknown);
134
134
  }
135
135
  //#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 };
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
@@ -0,0 +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;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,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;AAAA;;;;cAW9C,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,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;AAAA;;;;cAW9C,0BAAA,SAAmC,WAAA;EAAA,SAE5B,UAAA;EAAA,SACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;cADvC,UAAA,UACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;AAAA;;;;cAW9C,yBAAA,SAAkC,WAAA;EAAA,SAE3B,SAAA;EAAA,SACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;cADvC,SAAA,UACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;AAAA;;;;cAW9C,0BAAA,SAAmC,WAAA;EAAA,SAE5B,SAAA;EAAA,SACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;cADvC,SAAA,UACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;AAAA;AA1HG;;;AAAA,cAqIjD,0BAAA,SAAmC,WAAA;EAAA,SAE5B,UAAA;EAAA,SACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;cADvC,UAAA,UACA,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"}
@@ -133,4 +133,5 @@ declare class ChildWorkflowError extends WorkerError {
133
133
  constructor(message: string, cause?: unknown);
134
134
  }
135
135
  //#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 };
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
@@ -0,0 +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,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;AAAA;;;;cAW9C,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,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;AAAA;;;;cAW9C,0BAAA,SAAmC,WAAA;EAAA,SAE5B,UAAA;EAAA,SACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;cADvC,UAAA,UACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;AAAA;;;;cAW9C,yBAAA,SAAkC,WAAA;EAAA,SAE3B,SAAA;EAAA,SACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;cADvC,SAAA,UACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;AAAA;;;;cAW9C,0BAAA,SAAmC,WAAA;EAAA,SAE5B,SAAA;EAAA,SACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;cADvC,SAAA,UACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;AAAA;AA1HG;;;AAAA,cAqIjD,0BAAA,SAAmC,WAAA;EAAA,SAE5B,UAAA;EAAA,SACA,MAAA,EAAQ,aAAA,CAAc,gBAAA,CAAiB,KAAA;cADvC,UAAA,UACA,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"}
@@ -152,4 +152,5 @@ var ChildWorkflowError = class extends WorkerError {
152
152
  };
153
153
 
154
154
  //#endregion
155
- export { ChildWorkflowNotFoundError as a, SignalInputValidationError as c, WorkflowInputValidationError as d, WorkflowOutputValidationError as f, ChildWorkflowError as i, UpdateInputValidationError as l, ActivityInputValidationError as n, QueryInputValidationError as o, ActivityOutputValidationError as r, QueryOutputValidationError as s, ActivityDefinitionNotFoundError as t, UpdateOutputValidationError as u };
155
+ export { ChildWorkflowNotFoundError as a, SignalInputValidationError as c, WorkflowInputValidationError as d, WorkflowOutputValidationError as f, ChildWorkflowError as i, UpdateInputValidationError as l, ActivityInputValidationError as n, QueryInputValidationError as o, ActivityOutputValidationError as r, QueryOutputValidationError as s, ActivityDefinitionNotFoundError as t, UpdateOutputValidationError as u };
156
+ //# sourceMappingURL=errors-Di6Ja4Rt.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-Di6Ja4Rt.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n/**\n * Base error class for worker errors\n */\nabstract class WorkerError extends Error {\n protected constructor(message: string, cause?: unknown) {\n super(message, { cause });\n this.name = \"WorkerError\";\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n}\n\n/**\n * Error thrown when an activity definition is not found in the contract\n */\nexport class ActivityDefinitionNotFoundError extends WorkerError {\n constructor(\n public readonly activityName: string,\n public readonly availableDefinitions: readonly string[] = [],\n ) {\n const available = availableDefinitions.length > 0 ? availableDefinitions.join(\", \") : \"none\";\n super(\n `Activity definition not found for: \"${activityName}\". Available activities: ${available}`,\n );\n this.name = \"ActivityDefinitionNotFoundError\";\n }\n}\n\n/**\n * Error thrown when activity input validation fails\n */\nexport class ActivityInputValidationError extends WorkerError {\n constructor(\n public readonly activityName: string,\n public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,\n ) {\n const message = issues.map((issue) => issue.message).join(\"; \");\n super(`Activity \"${activityName}\" input validation failed: ${message}`);\n this.name = \"ActivityInputValidationError\";\n }\n}\n\n/**\n * Error thrown when activity output validation fails\n */\nexport class ActivityOutputValidationError extends WorkerError {\n constructor(\n public readonly activityName: string,\n public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,\n ) {\n const message = issues.map((issue) => issue.message).join(\"; \");\n super(`Activity \"${activityName}\" output validation failed: ${message}`);\n this.name = \"ActivityOutputValidationError\";\n }\n}\n\n/**\n * Error thrown when workflow input validation fails\n */\nexport class WorkflowInputValidationError extends WorkerError {\n constructor(\n public readonly workflowName: string,\n public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,\n ) {\n const message = issues.map((issue) => issue.message).join(\"; \");\n super(`Workflow \"${workflowName}\" input validation failed: ${message}`);\n this.name = \"WorkflowInputValidationError\";\n }\n}\n\n/**\n * Error thrown when workflow output validation fails\n */\nexport class WorkflowOutputValidationError extends WorkerError {\n constructor(\n public readonly workflowName: string,\n public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,\n ) {\n const message = issues.map((issue) => issue.message).join(\"; \");\n super(`Workflow \"${workflowName}\" output validation failed: ${message}`);\n this.name = \"WorkflowOutputValidationError\";\n }\n}\n\n/**\n * Error thrown when signal input validation fails\n */\nexport class SignalInputValidationError extends WorkerError {\n constructor(\n public readonly signalName: string,\n public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,\n ) {\n const message = issues.map((issue) => issue.message).join(\"; \");\n super(`Signal \"${signalName}\" input validation failed: ${message}`);\n this.name = \"SignalInputValidationError\";\n }\n}\n\n/**\n * Error thrown when query input validation fails\n */\nexport class QueryInputValidationError extends WorkerError {\n constructor(\n public readonly queryName: string,\n public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,\n ) {\n const message = issues.map((issue) => issue.message).join(\"; \");\n super(`Query \"${queryName}\" input validation failed: ${message}`);\n this.name = \"QueryInputValidationError\";\n }\n}\n\n/**\n * Error thrown when query output validation fails\n */\nexport class QueryOutputValidationError extends WorkerError {\n constructor(\n public readonly queryName: string,\n public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,\n ) {\n const message = issues.map((issue) => issue.message).join(\"; \");\n super(`Query \"${queryName}\" output validation failed: ${message}`);\n this.name = \"QueryOutputValidationError\";\n }\n}\n\n/**\n * Error thrown when update input validation fails\n */\nexport class UpdateInputValidationError extends WorkerError {\n constructor(\n public readonly updateName: string,\n public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,\n ) {\n const message = issues.map((issue) => issue.message).join(\"; \");\n super(`Update \"${updateName}\" input validation failed: ${message}`);\n this.name = \"UpdateInputValidationError\";\n }\n}\n\n/**\n * Error thrown when update output validation fails\n */\nexport class UpdateOutputValidationError extends WorkerError {\n constructor(\n public readonly updateName: string,\n public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,\n ) {\n const message = issues.map((issue) => issue.message).join(\"; \");\n super(`Update \"${updateName}\" output validation failed: ${message}`);\n this.name = \"UpdateOutputValidationError\";\n }\n}\n\n/**\n * Error thrown when a child workflow is not found in the contract\n */\nexport class ChildWorkflowNotFoundError extends WorkerError {\n constructor(\n public readonly workflowName: string,\n public readonly availableWorkflows: readonly string[] = [],\n ) {\n const available = availableWorkflows.length > 0 ? availableWorkflows.join(\", \") : \"none\";\n super(`Child workflow not found: \"${workflowName}\". Available workflows: ${available}`);\n this.name = \"ChildWorkflowNotFoundError\";\n }\n}\n\n/**\n * Generic error for child workflow operations\n */\nexport class ChildWorkflowError extends WorkerError {\n constructor(message: string, cause?: unknown) {\n super(message, cause);\n this.name = \"ChildWorkflowError\";\n }\n}\n"],"mappings":";;;;AAKA,IAAe,cAAf,cAAmC,MAAM;CACvC,AAAU,YAAY,SAAiB,OAAiB;AACtD,QAAM,SAAS,EAAE,OAAO,CAAC;AACzB,OAAK,OAAO;AAEZ,MAAI,MAAM,kBACR,OAAM,kBAAkB,MAAM,KAAK,YAAY;;;;;;AAQrD,IAAa,kCAAb,cAAqD,YAAY;CAC/D,YACE,AAAgB,cAChB,AAAgB,uBAA0C,EAAE,EAC5D;EACA,MAAM,YAAY,qBAAqB,SAAS,IAAI,qBAAqB,KAAK,KAAK,GAAG;AACtF,QACE,uCAAuC,aAAa,2BAA2B,YAChF;EANe;EACA;AAMhB,OAAK,OAAO;;;;;;AAOhB,IAAa,+BAAb,cAAkD,YAAY;CAC5D,YACE,AAAgB,cAChB,AAAgB,QAChB;EACA,MAAM,UAAU,OAAO,KAAK,UAAU,MAAM,QAAQ,CAAC,KAAK,KAAK;AAC/D,QAAM,aAAa,aAAa,6BAA6B,UAAU;EAJvD;EACA;AAIhB,OAAK,OAAO;;;;;;AAOhB,IAAa,gCAAb,cAAmD,YAAY;CAC7D,YACE,AAAgB,cAChB,AAAgB,QAChB;EACA,MAAM,UAAU,OAAO,KAAK,UAAU,MAAM,QAAQ,CAAC,KAAK,KAAK;AAC/D,QAAM,aAAa,aAAa,8BAA8B,UAAU;EAJxD;EACA;AAIhB,OAAK,OAAO;;;;;;AAOhB,IAAa,+BAAb,cAAkD,YAAY;CAC5D,YACE,AAAgB,cAChB,AAAgB,QAChB;EACA,MAAM,UAAU,OAAO,KAAK,UAAU,MAAM,QAAQ,CAAC,KAAK,KAAK;AAC/D,QAAM,aAAa,aAAa,6BAA6B,UAAU;EAJvD;EACA;AAIhB,OAAK,OAAO;;;;;;AAOhB,IAAa,gCAAb,cAAmD,YAAY;CAC7D,YACE,AAAgB,cAChB,AAAgB,QAChB;EACA,MAAM,UAAU,OAAO,KAAK,UAAU,MAAM,QAAQ,CAAC,KAAK,KAAK;AAC/D,QAAM,aAAa,aAAa,8BAA8B,UAAU;EAJxD;EACA;AAIhB,OAAK,OAAO;;;;;;AAOhB,IAAa,6BAAb,cAAgD,YAAY;CAC1D,YACE,AAAgB,YAChB,AAAgB,QAChB;EACA,MAAM,UAAU,OAAO,KAAK,UAAU,MAAM,QAAQ,CAAC,KAAK,KAAK;AAC/D,QAAM,WAAW,WAAW,6BAA6B,UAAU;EAJnD;EACA;AAIhB,OAAK,OAAO;;;;;;AAOhB,IAAa,4BAAb,cAA+C,YAAY;CACzD,YACE,AAAgB,WAChB,AAAgB,QAChB;EACA,MAAM,UAAU,OAAO,KAAK,UAAU,MAAM,QAAQ,CAAC,KAAK,KAAK;AAC/D,QAAM,UAAU,UAAU,6BAA6B,UAAU;EAJjD;EACA;AAIhB,OAAK,OAAO;;;;;;AAOhB,IAAa,6BAAb,cAAgD,YAAY;CAC1D,YACE,AAAgB,WAChB,AAAgB,QAChB;EACA,MAAM,UAAU,OAAO,KAAK,UAAU,MAAM,QAAQ,CAAC,KAAK,KAAK;AAC/D,QAAM,UAAU,UAAU,8BAA8B,UAAU;EAJlD;EACA;AAIhB,OAAK,OAAO;;;;;;AAOhB,IAAa,6BAAb,cAAgD,YAAY;CAC1D,YACE,AAAgB,YAChB,AAAgB,QAChB;EACA,MAAM,UAAU,OAAO,KAAK,UAAU,MAAM,QAAQ,CAAC,KAAK,KAAK;AAC/D,QAAM,WAAW,WAAW,6BAA6B,UAAU;EAJnD;EACA;AAIhB,OAAK,OAAO;;;;;;AAOhB,IAAa,8BAAb,cAAiD,YAAY;CAC3D,YACE,AAAgB,YAChB,AAAgB,QAChB;EACA,MAAM,UAAU,OAAO,KAAK,UAAU,MAAM,QAAQ,CAAC,KAAK,KAAK;AAC/D,QAAM,WAAW,WAAW,8BAA8B,UAAU;EAJpD;EACA;AAIhB,OAAK,OAAO;;;;;;AAOhB,IAAa,6BAAb,cAAgD,YAAY;CAC1D,YACE,AAAgB,cAChB,AAAgB,qBAAwC,EAAE,EAC1D;EACA,MAAM,YAAY,mBAAmB,SAAS,IAAI,mBAAmB,KAAK,KAAK,GAAG;AAClF,QAAM,8BAA8B,aAAa,0BAA0B,YAAY;EAJvE;EACA;AAIhB,OAAK,OAAO;;;;;;AAOhB,IAAa,qBAAb,cAAwC,YAAY;CAClD,YAAY,SAAiB,OAAiB;AAC5C,QAAM,SAAS,MAAM;AACrB,OAAK,OAAO"}
package/dist/worker.cjs CHANGED
@@ -1,6 +1,6 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
2
  let _temporalio_worker = require("@temporalio/worker");
2
3
  let node_url = require("node:url");
3
- let node_path = require("node:path");
4
4
 
5
5
  //#region src/worker.ts
6
6
  /**
@@ -40,9 +40,14 @@ async function createWorker(options) {
40
40
  });
41
41
  }
42
42
  /**
43
- * Helper to create a workflowsPath from a file URL
43
+ * Helper to resolve a workflow file path relative to the current module's URL.
44
44
  *
45
- * Useful for creating the workflowsPath option when using ES modules
45
+ * Useful when using ES modules (`import.meta.url`) to locate workflow files.
46
+ * The `relativePath` should include the file extension explicitly (e.g. `./workflows.js`)
47
+ * to ensure the resolved path is unambiguous in both source and built contexts.
48
+ *
49
+ * @param baseURL - The base URL to resolve from, typically `import.meta.url`
50
+ * @param relativePath - Relative path to the workflows file, **including extension**
46
51
  *
47
52
  * @example
48
53
  * ```ts
@@ -51,13 +56,14 @@ async function createWorker(options) {
51
56
  * const worker = await createWorker({
52
57
  * contract: myContract,
53
58
  * connection,
54
- * workflowsPath: workflowsPathFromURL(import.meta.url, './workflows'),
59
+ * // Include the extension explicitly to work in both source (.ts) and build (.js) contexts
60
+ * workflowsPath: workflowsPathFromURL(import.meta.url, './workflows.js'),
55
61
  * activities,
56
62
  * });
57
63
  * ```
58
64
  */
59
65
  function workflowsPathFromURL(baseURL, relativePath) {
60
- return (0, node_url.fileURLToPath)(new URL(`${relativePath}${(0, node_path.extname)(baseURL)}`, baseURL));
66
+ return (0, node_url.fileURLToPath)(new URL(relativePath, baseURL));
61
67
  }
62
68
 
63
69
  //#endregion
package/dist/worker.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as ActivitiesHandler } from "./activity-5pVNjW7l.cjs";
1
+ import { ActivitiesHandler } from "./activity.cjs";
2
2
  import { ContractDefinition } from "@temporal-contract/contract";
3
3
  import { Worker, WorkerOptions } from "@temporalio/worker";
4
4
 
@@ -6,7 +6,7 @@ import { Worker, WorkerOptions } from "@temporalio/worker";
6
6
  /**
7
7
  * Options for creating a Temporal worker
8
8
  */
9
- interface CreateWorkerOptions<TContract extends ContractDefinition> extends Omit<WorkerOptions, "activities" | "taskQueue"> {
9
+ type CreateWorkerOptions<TContract extends ContractDefinition> = Omit<WorkerOptions, "activities" | "taskQueue"> & {
10
10
  /**
11
11
  * The contract definition for this worker
12
12
  */
@@ -15,7 +15,7 @@ interface CreateWorkerOptions<TContract extends ContractDefinition> extends Omit
15
15
  * Activities handler for this worker
16
16
  */
17
17
  activities: ActivitiesHandler<TContract>;
18
- }
18
+ };
19
19
  /**
20
20
  * Create a typed Temporal worker with contract-based configuration
21
21
  *
@@ -46,9 +46,14 @@ interface CreateWorkerOptions<TContract extends ContractDefinition> extends Omit
46
46
  */
47
47
  declare function createWorker<TContract extends ContractDefinition>(options: CreateWorkerOptions<TContract>): Promise<Worker>;
48
48
  /**
49
- * Helper to create a workflowsPath from a file URL
49
+ * Helper to resolve a workflow file path relative to the current module's URL.
50
50
  *
51
- * Useful for creating the workflowsPath option when using ES modules
51
+ * Useful when using ES modules (`import.meta.url`) to locate workflow files.
52
+ * The `relativePath` should include the file extension explicitly (e.g. `./workflows.js`)
53
+ * to ensure the resolved path is unambiguous in both source and built contexts.
54
+ *
55
+ * @param baseURL - The base URL to resolve from, typically `import.meta.url`
56
+ * @param relativePath - Relative path to the workflows file, **including extension**
52
57
  *
53
58
  * @example
54
59
  * ```ts
@@ -57,11 +62,13 @@ declare function createWorker<TContract extends ContractDefinition>(options: Cre
57
62
  * const worker = await createWorker({
58
63
  * contract: myContract,
59
64
  * connection,
60
- * workflowsPath: workflowsPathFromURL(import.meta.url, './workflows'),
65
+ * // Include the extension explicitly to work in both source (.ts) and build (.js) contexts
66
+ * workflowsPath: workflowsPathFromURL(import.meta.url, './workflows.js'),
61
67
  * activities,
62
68
  * });
63
69
  * ```
64
70
  */
65
71
  declare function workflowsPathFromURL(baseURL: string, relativePath: string): string;
66
72
  //#endregion
67
- export { CreateWorkerOptions, createWorker, workflowsPathFromURL };
73
+ export { CreateWorkerOptions, createWorker, workflowsPathFromURL };
74
+ //# sourceMappingURL=worker.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.cts","names":[],"sources":["../src/worker.ts"],"mappings":";;;;;;;AASA;KAAY,mBAAA,mBAAsC,kBAAA,IAAsB,IAAA,CACtE,aAAA;EAD6B;;;EAO7B,QAAA,EAAU,SAAA;EAAA;;;EAKV,UAAA,EAAY,iBAAA,CAAkB,SAAA;AAAA;;;;;;;;;;;;AA+BhC;;;;;;;;;;;;;;;;;iBAAsB,YAAA,mBAA+B,kBAAA,CAAA,CACnD,OAAA,EAAS,mBAAA,CAAoB,SAAA,IAC5B,OAAA,CAAQ,MAAA;;AAkCX;;;;;;;;;;;;;;;;;;;;;;iBAAgB,oBAAA,CAAqB,OAAA,UAAiB,YAAA"}