@temporal-contract/worker 0.1.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/README.md +13 -12
- package/dist/activity.cjs +44 -118
- package/dist/activity.d.cts +109 -3
- package/dist/activity.d.cts.map +1 -0
- package/dist/activity.d.mts +109 -3
- package/dist/activity.d.mts.map +1 -0
- package/dist/activity.mjs +33 -107
- package/dist/activity.mjs.map +1 -0
- package/dist/{errors-Vr-sKdW7.d.mts → errors-CG1y7SHO.d.cts} +14 -1
- package/dist/errors-CG1y7SHO.d.cts.map +1 -0
- package/dist/{errors-CXpHOFmk.d.cts → errors-DZhaNhwr.d.mts} +14 -1
- package/dist/errors-DZhaNhwr.d.mts.map +1 -0
- package/dist/internal-BoNcEtYh.mjs +354 -0
- package/dist/internal-BoNcEtYh.mjs.map +1 -0
- package/dist/internal-Tj4m4f_K.cjs +453 -0
- package/dist/worker.cjs +12 -8
- package/dist/worker.d.cts +14 -7
- package/dist/worker.d.cts.map +1 -0
- package/dist/worker.d.mts +14 -7
- package/dist/worker.d.mts.map +1 -0
- package/dist/worker.mjs +13 -8
- package/dist/worker.mjs.map +1 -0
- package/dist/workflow.cjs +269 -172
- package/dist/workflow.d.cts +184 -60
- package/dist/workflow.d.cts.map +1 -0
- package/dist/workflow.d.mts +184 -60
- package/dist/workflow.d.mts.map +1 -0
- package/dist/workflow.mjs +254 -157
- package/dist/workflow.mjs.map +1 -0
- package/package.json +24 -23
- package/dist/activity-5pVNjW7l.d.cts +0 -161
- package/dist/activity-BUEBZ7SL.d.mts +0 -161
- package/dist/errors-BqVTpfcf.mjs +0 -155
- package/dist/errors-DjSZg-93.cjs +0 -227
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporal-contract/worker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Worker utilities with Result/Future pattern for implementing temporal-contract workflows and activities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contract",
|
|
@@ -14,13 +14,16 @@
|
|
|
14
14
|
"bugs": {
|
|
15
15
|
"url": "https://github.com/btravers/temporal-contract/issues"
|
|
16
16
|
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "Benoit TRAVERS <benoit.travers.fr@gmail.com>",
|
|
17
19
|
"repository": {
|
|
18
20
|
"type": "git",
|
|
19
21
|
"url": "https://github.com/btravers/temporal-contract.git",
|
|
20
22
|
"directory": "packages/worker"
|
|
21
23
|
},
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
24
27
|
"type": "module",
|
|
25
28
|
"exports": {
|
|
26
29
|
"./activity": {
|
|
@@ -55,34 +58,32 @@
|
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
60
|
},
|
|
58
|
-
"main": "./dist/index.cjs",
|
|
59
|
-
"module": "./dist/index.mjs",
|
|
60
|
-
"types": "./dist/index.d.mts",
|
|
61
|
-
"files": [
|
|
62
|
-
"dist"
|
|
63
|
-
],
|
|
64
61
|
"dependencies": {
|
|
65
62
|
"@standard-schema/spec": "1.1.0",
|
|
66
63
|
"@swan-io/boxed": "3.2.1",
|
|
67
|
-
"@temporal-contract/boxed": "
|
|
68
|
-
"@temporal-contract/contract": "
|
|
64
|
+
"@temporal-contract/boxed": "1.0.0",
|
|
65
|
+
"@temporal-contract/contract": "1.0.0"
|
|
69
66
|
},
|
|
70
67
|
"devDependencies": {
|
|
71
|
-
"@temporalio/client": "1.
|
|
72
|
-
"@temporalio/
|
|
73
|
-
"@temporalio/
|
|
74
|
-
"@
|
|
75
|
-
"@
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
68
|
+
"@temporalio/client": "1.16.1",
|
|
69
|
+
"@temporalio/common": "1.16.1",
|
|
70
|
+
"@temporalio/worker": "1.16.1",
|
|
71
|
+
"@temporalio/workflow": "1.16.1",
|
|
72
|
+
"@types/node": "24.12.2",
|
|
73
|
+
"@vitest/coverage-v8": "4.1.5",
|
|
74
|
+
"tsdown": "0.21.10",
|
|
75
|
+
"typedoc": "0.28.19",
|
|
76
|
+
"typedoc-plugin-markdown": "4.11.0",
|
|
77
|
+
"typescript": "6.0.3",
|
|
78
|
+
"vitest": "4.1.5",
|
|
79
|
+
"zod": "4.3.6",
|
|
80
|
+
"@temporal-contract/client": "1.0.0",
|
|
81
|
+
"@temporal-contract/testing": "1.0.0",
|
|
82
|
+
"@temporal-contract/tsconfig": "1.0.0",
|
|
83
83
|
"@temporal-contract/typedoc": "0.1.0"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
|
+
"@temporalio/common": "^1",
|
|
86
87
|
"@temporalio/worker": "^1",
|
|
87
88
|
"@temporalio/workflow": "^1"
|
|
88
89
|
},
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { g as WorkerInferOutput, h as WorkerInferInput } from "./errors-CXpHOFmk.cjs";
|
|
2
|
-
import { ActivityDefinition, ContractDefinition } from "@temporal-contract/contract";
|
|
3
|
-
import { Future, Result } from "@swan-io/boxed";
|
|
4
|
-
|
|
5
|
-
//#region src/activity-utils.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* Extract activity definitions for a specific workflow from a contract
|
|
8
|
-
*
|
|
9
|
-
* This includes both:
|
|
10
|
-
* - Workflow-specific activities defined under workflow.activities
|
|
11
|
-
* - Global activities defined under contract.activities
|
|
12
|
-
*
|
|
13
|
-
* @param contract - The contract definition
|
|
14
|
-
* @param workflowName - The name of the workflow
|
|
15
|
-
* @returns Activity definitions for the workflow (workflow-specific + global activities merged)
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* const orderWorkflowActivities = getWorkflowActivities(myContract, 'processOrder');
|
|
20
|
-
* // Returns: { processPayment: ActivityDef, reserveInventory: ActivityDef, sendEmail: ActivityDef }
|
|
21
|
-
* // where sendEmail is a global activity
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
declare function getWorkflowActivities<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]>(contract: TContract, workflowName: TWorkflowName): Record<string, ActivityDefinition>;
|
|
25
|
-
/**
|
|
26
|
-
* Extract all activity names for a specific workflow from a contract
|
|
27
|
-
*
|
|
28
|
-
* @param contract - The contract definition
|
|
29
|
-
* @param workflowName - The name of the workflow
|
|
30
|
-
* @returns Array of activity names (strings) available for the workflow
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* const activityNames = getWorkflowActivityNames(myContract, 'processOrder');
|
|
35
|
-
* // Returns: ['processPayment', 'reserveInventory', 'sendEmail']
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
declare function getWorkflowActivityNames<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]>(contract: TContract, workflowName: TWorkflowName): string[];
|
|
39
|
-
/**
|
|
40
|
-
* Check if an activity belongs to a specific workflow
|
|
41
|
-
*
|
|
42
|
-
* @param contract - The contract definition
|
|
43
|
-
* @param workflowName - The name of the workflow
|
|
44
|
-
* @param activityName - The name of the activity to check
|
|
45
|
-
* @returns True if the activity is available for the workflow, false otherwise
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```ts
|
|
49
|
-
* if (isWorkflowActivity(myContract, 'processOrder', 'processPayment')) {
|
|
50
|
-
* // Activity is available for this workflow
|
|
51
|
-
* }
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
declare function isWorkflowActivity<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]>(contract: TContract, workflowName: TWorkflowName, activityName: string): boolean;
|
|
55
|
-
/**
|
|
56
|
-
* Get all workflow names from a contract
|
|
57
|
-
*
|
|
58
|
-
* @param contract - The contract definition
|
|
59
|
-
* @returns Array of workflow names defined in the contract
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```ts
|
|
63
|
-
* const workflows = getWorkflowNames(myContract);
|
|
64
|
-
* // Returns: ['processOrder', 'processRefund']
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
declare function getWorkflowNames<TContract extends ContractDefinition>(contract: TContract): Array<keyof TContract["workflows"]>;
|
|
68
|
-
//#endregion
|
|
69
|
-
//#region src/activity.d.ts
|
|
70
|
-
/**
|
|
71
|
-
* Activity error class that should be used to wrap all technical exceptions
|
|
72
|
-
* Forces proper error handling and enables retry policies
|
|
73
|
-
*/
|
|
74
|
-
declare class ActivityError extends Error {
|
|
75
|
-
readonly code: string;
|
|
76
|
-
constructor(code: string, message: string, cause?: unknown);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Activity implementation using Future/Result pattern
|
|
80
|
-
*
|
|
81
|
-
* Returns Future<Result<Output, ActivityError>> for explicit error handling instead of throwing exceptions.
|
|
82
|
-
* All errors must be wrapped in ActivityError to enable proper retry policies.
|
|
83
|
-
*/
|
|
84
|
-
type BoxedActivityImplementation<TActivity extends ActivityDefinition> = (args: WorkerInferInput<TActivity>) => Future<Result<WorkerInferOutput<TActivity>, ActivityError>>;
|
|
85
|
-
/**
|
|
86
|
-
* Map of all activity implementations for a contract (global + all workflow-specific)
|
|
87
|
-
*/
|
|
88
|
-
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"]> : {} };
|
|
89
|
-
type BoxedActivitiesImplementations<TActivities extends Record<string, ActivityDefinition>> = { [K in keyof TActivities]: BoxedActivityImplementation<TActivities[K]> };
|
|
90
|
-
/**
|
|
91
|
-
* Options for creating activities handler
|
|
92
|
-
*/
|
|
93
|
-
interface DeclareActivitiesHandlerOptions<TContract extends ContractDefinition> {
|
|
94
|
-
contract: TContract;
|
|
95
|
-
activities: ContractBoxedActivitiesImplementations<TContract>;
|
|
96
|
-
}
|
|
97
|
-
type ActivityImplementation<TActivity extends ActivityDefinition> = (args: WorkerInferInput<TActivity>) => Promise<WorkerInferOutput<TActivity>>;
|
|
98
|
-
type ActivitiesImplementations<TActivities extends Record<string, ActivityDefinition>> = { [K in keyof TActivities]: ActivityImplementation<TActivities[K]> };
|
|
99
|
-
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
100
|
-
/**
|
|
101
|
-
* Activities handler ready for Temporal Worker
|
|
102
|
-
*
|
|
103
|
-
* Flat structure: all activities (global + all workflow-specific) are at the root level
|
|
104
|
-
*/
|
|
105
|
-
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"]]>;
|
|
106
|
-
/**
|
|
107
|
-
* Create a typed activities handler with automatic validation and Result pattern
|
|
108
|
-
*
|
|
109
|
-
* This wraps all activity implementations with:
|
|
110
|
-
* - Validation at network boundaries
|
|
111
|
-
* - Result<T, ActivityError> pattern for explicit error handling
|
|
112
|
-
* - Automatic conversion from Result to Promise (throwing on Error)
|
|
113
|
-
*
|
|
114
|
-
* TypeScript ensures ALL activities (global + workflow-specific) are implemented.
|
|
115
|
-
*
|
|
116
|
-
* Use this to create the activities object for the Temporal Worker.
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```ts
|
|
120
|
-
* import { declareActivitiesHandler, ActivityError } from '@temporal-contract/worker/activity';
|
|
121
|
-
* import { Result, Future } from '@swan-io/boxed';
|
|
122
|
-
* import myContract from './contract';
|
|
123
|
-
*
|
|
124
|
-
* export const activities = declareActivitiesHandler({
|
|
125
|
-
* contract: myContract,
|
|
126
|
-
* activities: {
|
|
127
|
-
* // Activity returns Result instead of throwing
|
|
128
|
-
* // All technical exceptions must be wrapped in ActivityError for retry policies
|
|
129
|
-
* sendEmail: (args) => {
|
|
130
|
-
* return Future.make(async resolve => {
|
|
131
|
-
* try {
|
|
132
|
-
* await emailService.send(args);
|
|
133
|
-
* resolve(Result.Ok({ sent: true }));
|
|
134
|
-
* } catch (error) {
|
|
135
|
-
* // Wrap technical errors in ActivityError to enable retries
|
|
136
|
-
* resolve(Result.Error(
|
|
137
|
-
* new ActivityError(
|
|
138
|
-
* 'EMAIL_SEND_FAILED',
|
|
139
|
-
* 'Failed to send email',
|
|
140
|
-
* error // Original error as cause for debugging
|
|
141
|
-
* )
|
|
142
|
-
* ));
|
|
143
|
-
* }
|
|
144
|
-
* });
|
|
145
|
-
* },
|
|
146
|
-
* },
|
|
147
|
-
* });
|
|
148
|
-
*
|
|
149
|
-
* // Use with Temporal Worker
|
|
150
|
-
* import { Worker } from '@temporalio/worker';
|
|
151
|
-
*
|
|
152
|
-
* const worker = await Worker.create({
|
|
153
|
-
* workflowsPath: require.resolve('./workflows'),
|
|
154
|
-
* activities: activities,
|
|
155
|
-
* taskQueue: contract.taskQueue,
|
|
156
|
-
* });
|
|
157
|
-
* ```
|
|
158
|
-
*/
|
|
159
|
-
declare function declareActivitiesHandler<TContract extends ContractDefinition>(options: DeclareActivitiesHandlerOptions<TContract>): ActivitiesHandler<TContract>;
|
|
160
|
-
//#endregion
|
|
161
|
-
export { getWorkflowActivityNames as a, getWorkflowActivities as i, ActivityError as n, getWorkflowNames as o, declareActivitiesHandler as r, isWorkflowActivity as s, ActivitiesHandler as t };
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { g as WorkerInferOutput, h as WorkerInferInput } from "./errors-Vr-sKdW7.mjs";
|
|
2
|
-
import { ActivityDefinition, ContractDefinition } from "@temporal-contract/contract";
|
|
3
|
-
import { Future, Result } from "@swan-io/boxed";
|
|
4
|
-
|
|
5
|
-
//#region src/activity-utils.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* Extract activity definitions for a specific workflow from a contract
|
|
8
|
-
*
|
|
9
|
-
* This includes both:
|
|
10
|
-
* - Workflow-specific activities defined under workflow.activities
|
|
11
|
-
* - Global activities defined under contract.activities
|
|
12
|
-
*
|
|
13
|
-
* @param contract - The contract definition
|
|
14
|
-
* @param workflowName - The name of the workflow
|
|
15
|
-
* @returns Activity definitions for the workflow (workflow-specific + global activities merged)
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* const orderWorkflowActivities = getWorkflowActivities(myContract, 'processOrder');
|
|
20
|
-
* // Returns: { processPayment: ActivityDef, reserveInventory: ActivityDef, sendEmail: ActivityDef }
|
|
21
|
-
* // where sendEmail is a global activity
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
declare function getWorkflowActivities<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]>(contract: TContract, workflowName: TWorkflowName): Record<string, ActivityDefinition>;
|
|
25
|
-
/**
|
|
26
|
-
* Extract all activity names for a specific workflow from a contract
|
|
27
|
-
*
|
|
28
|
-
* @param contract - The contract definition
|
|
29
|
-
* @param workflowName - The name of the workflow
|
|
30
|
-
* @returns Array of activity names (strings) available for the workflow
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* const activityNames = getWorkflowActivityNames(myContract, 'processOrder');
|
|
35
|
-
* // Returns: ['processPayment', 'reserveInventory', 'sendEmail']
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
declare function getWorkflowActivityNames<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]>(contract: TContract, workflowName: TWorkflowName): string[];
|
|
39
|
-
/**
|
|
40
|
-
* Check if an activity belongs to a specific workflow
|
|
41
|
-
*
|
|
42
|
-
* @param contract - The contract definition
|
|
43
|
-
* @param workflowName - The name of the workflow
|
|
44
|
-
* @param activityName - The name of the activity to check
|
|
45
|
-
* @returns True if the activity is available for the workflow, false otherwise
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```ts
|
|
49
|
-
* if (isWorkflowActivity(myContract, 'processOrder', 'processPayment')) {
|
|
50
|
-
* // Activity is available for this workflow
|
|
51
|
-
* }
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
declare function isWorkflowActivity<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]>(contract: TContract, workflowName: TWorkflowName, activityName: string): boolean;
|
|
55
|
-
/**
|
|
56
|
-
* Get all workflow names from a contract
|
|
57
|
-
*
|
|
58
|
-
* @param contract - The contract definition
|
|
59
|
-
* @returns Array of workflow names defined in the contract
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```ts
|
|
63
|
-
* const workflows = getWorkflowNames(myContract);
|
|
64
|
-
* // Returns: ['processOrder', 'processRefund']
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
declare function getWorkflowNames<TContract extends ContractDefinition>(contract: TContract): Array<keyof TContract["workflows"]>;
|
|
68
|
-
//#endregion
|
|
69
|
-
//#region src/activity.d.ts
|
|
70
|
-
/**
|
|
71
|
-
* Activity error class that should be used to wrap all technical exceptions
|
|
72
|
-
* Forces proper error handling and enables retry policies
|
|
73
|
-
*/
|
|
74
|
-
declare class ActivityError extends Error {
|
|
75
|
-
readonly code: string;
|
|
76
|
-
constructor(code: string, message: string, cause?: unknown);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Activity implementation using Future/Result pattern
|
|
80
|
-
*
|
|
81
|
-
* Returns Future<Result<Output, ActivityError>> for explicit error handling instead of throwing exceptions.
|
|
82
|
-
* All errors must be wrapped in ActivityError to enable proper retry policies.
|
|
83
|
-
*/
|
|
84
|
-
type BoxedActivityImplementation<TActivity extends ActivityDefinition> = (args: WorkerInferInput<TActivity>) => Future<Result<WorkerInferOutput<TActivity>, ActivityError>>;
|
|
85
|
-
/**
|
|
86
|
-
* Map of all activity implementations for a contract (global + all workflow-specific)
|
|
87
|
-
*/
|
|
88
|
-
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"]> : {} };
|
|
89
|
-
type BoxedActivitiesImplementations<TActivities extends Record<string, ActivityDefinition>> = { [K in keyof TActivities]: BoxedActivityImplementation<TActivities[K]> };
|
|
90
|
-
/**
|
|
91
|
-
* Options for creating activities handler
|
|
92
|
-
*/
|
|
93
|
-
interface DeclareActivitiesHandlerOptions<TContract extends ContractDefinition> {
|
|
94
|
-
contract: TContract;
|
|
95
|
-
activities: ContractBoxedActivitiesImplementations<TContract>;
|
|
96
|
-
}
|
|
97
|
-
type ActivityImplementation<TActivity extends ActivityDefinition> = (args: WorkerInferInput<TActivity>) => Promise<WorkerInferOutput<TActivity>>;
|
|
98
|
-
type ActivitiesImplementations<TActivities extends Record<string, ActivityDefinition>> = { [K in keyof TActivities]: ActivityImplementation<TActivities[K]> };
|
|
99
|
-
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
100
|
-
/**
|
|
101
|
-
* Activities handler ready for Temporal Worker
|
|
102
|
-
*
|
|
103
|
-
* Flat structure: all activities (global + all workflow-specific) are at the root level
|
|
104
|
-
*/
|
|
105
|
-
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"]]>;
|
|
106
|
-
/**
|
|
107
|
-
* Create a typed activities handler with automatic validation and Result pattern
|
|
108
|
-
*
|
|
109
|
-
* This wraps all activity implementations with:
|
|
110
|
-
* - Validation at network boundaries
|
|
111
|
-
* - Result<T, ActivityError> pattern for explicit error handling
|
|
112
|
-
* - Automatic conversion from Result to Promise (throwing on Error)
|
|
113
|
-
*
|
|
114
|
-
* TypeScript ensures ALL activities (global + workflow-specific) are implemented.
|
|
115
|
-
*
|
|
116
|
-
* Use this to create the activities object for the Temporal Worker.
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```ts
|
|
120
|
-
* import { declareActivitiesHandler, ActivityError } from '@temporal-contract/worker/activity';
|
|
121
|
-
* import { Result, Future } from '@swan-io/boxed';
|
|
122
|
-
* import myContract from './contract';
|
|
123
|
-
*
|
|
124
|
-
* export const activities = declareActivitiesHandler({
|
|
125
|
-
* contract: myContract,
|
|
126
|
-
* activities: {
|
|
127
|
-
* // Activity returns Result instead of throwing
|
|
128
|
-
* // All technical exceptions must be wrapped in ActivityError for retry policies
|
|
129
|
-
* sendEmail: (args) => {
|
|
130
|
-
* return Future.make(async resolve => {
|
|
131
|
-
* try {
|
|
132
|
-
* await emailService.send(args);
|
|
133
|
-
* resolve(Result.Ok({ sent: true }));
|
|
134
|
-
* } catch (error) {
|
|
135
|
-
* // Wrap technical errors in ActivityError to enable retries
|
|
136
|
-
* resolve(Result.Error(
|
|
137
|
-
* new ActivityError(
|
|
138
|
-
* 'EMAIL_SEND_FAILED',
|
|
139
|
-
* 'Failed to send email',
|
|
140
|
-
* error // Original error as cause for debugging
|
|
141
|
-
* )
|
|
142
|
-
* ));
|
|
143
|
-
* }
|
|
144
|
-
* });
|
|
145
|
-
* },
|
|
146
|
-
* },
|
|
147
|
-
* });
|
|
148
|
-
*
|
|
149
|
-
* // Use with Temporal Worker
|
|
150
|
-
* import { Worker } from '@temporalio/worker';
|
|
151
|
-
*
|
|
152
|
-
* const worker = await Worker.create({
|
|
153
|
-
* workflowsPath: require.resolve('./workflows'),
|
|
154
|
-
* activities: activities,
|
|
155
|
-
* taskQueue: contract.taskQueue,
|
|
156
|
-
* });
|
|
157
|
-
* ```
|
|
158
|
-
*/
|
|
159
|
-
declare function declareActivitiesHandler<TContract extends ContractDefinition>(options: DeclareActivitiesHandlerOptions<TContract>): ActivitiesHandler<TContract>;
|
|
160
|
-
//#endregion
|
|
161
|
-
export { getWorkflowActivityNames as a, getWorkflowActivities as i, ActivityError as n, getWorkflowNames as o, declareActivitiesHandler as r, isWorkflowActivity as s, ActivitiesHandler as t };
|
package/dist/errors-BqVTpfcf.mjs
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
//#region src/errors.ts
|
|
2
|
-
/**
|
|
3
|
-
* Base error class for worker errors
|
|
4
|
-
*/
|
|
5
|
-
var WorkerError = class extends Error {
|
|
6
|
-
constructor(message, cause) {
|
|
7
|
-
super(message, { cause });
|
|
8
|
-
this.name = "WorkerError";
|
|
9
|
-
if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Error thrown when an activity definition is not found in the contract
|
|
14
|
-
*/
|
|
15
|
-
var ActivityDefinitionNotFoundError = class extends WorkerError {
|
|
16
|
-
constructor(activityName, availableDefinitions = []) {
|
|
17
|
-
const available = availableDefinitions.length > 0 ? availableDefinitions.join(", ") : "none";
|
|
18
|
-
super(`Activity definition not found for: "${activityName}". Available activities: ${available}`);
|
|
19
|
-
this.activityName = activityName;
|
|
20
|
-
this.availableDefinitions = availableDefinitions;
|
|
21
|
-
this.name = "ActivityDefinitionNotFoundError";
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Error thrown when activity input validation fails
|
|
26
|
-
*/
|
|
27
|
-
var ActivityInputValidationError = class extends WorkerError {
|
|
28
|
-
constructor(activityName, issues) {
|
|
29
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
30
|
-
super(`Activity "${activityName}" input validation failed: ${message}`);
|
|
31
|
-
this.activityName = activityName;
|
|
32
|
-
this.issues = issues;
|
|
33
|
-
this.name = "ActivityInputValidationError";
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Error thrown when activity output validation fails
|
|
38
|
-
*/
|
|
39
|
-
var ActivityOutputValidationError = class extends WorkerError {
|
|
40
|
-
constructor(activityName, issues) {
|
|
41
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
42
|
-
super(`Activity "${activityName}" output validation failed: ${message}`);
|
|
43
|
-
this.activityName = activityName;
|
|
44
|
-
this.issues = issues;
|
|
45
|
-
this.name = "ActivityOutputValidationError";
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Error thrown when workflow input validation fails
|
|
50
|
-
*/
|
|
51
|
-
var WorkflowInputValidationError = class extends WorkerError {
|
|
52
|
-
constructor(workflowName, issues) {
|
|
53
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
54
|
-
super(`Workflow "${workflowName}" input validation failed: ${message}`);
|
|
55
|
-
this.workflowName = workflowName;
|
|
56
|
-
this.issues = issues;
|
|
57
|
-
this.name = "WorkflowInputValidationError";
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Error thrown when workflow output validation fails
|
|
62
|
-
*/
|
|
63
|
-
var WorkflowOutputValidationError = class extends WorkerError {
|
|
64
|
-
constructor(workflowName, issues) {
|
|
65
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
66
|
-
super(`Workflow "${workflowName}" output validation failed: ${message}`);
|
|
67
|
-
this.workflowName = workflowName;
|
|
68
|
-
this.issues = issues;
|
|
69
|
-
this.name = "WorkflowOutputValidationError";
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Error thrown when signal input validation fails
|
|
74
|
-
*/
|
|
75
|
-
var SignalInputValidationError = class extends WorkerError {
|
|
76
|
-
constructor(signalName, issues) {
|
|
77
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
78
|
-
super(`Signal "${signalName}" input validation failed: ${message}`);
|
|
79
|
-
this.signalName = signalName;
|
|
80
|
-
this.issues = issues;
|
|
81
|
-
this.name = "SignalInputValidationError";
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Error thrown when query input validation fails
|
|
86
|
-
*/
|
|
87
|
-
var QueryInputValidationError = class extends WorkerError {
|
|
88
|
-
constructor(queryName, issues) {
|
|
89
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
90
|
-
super(`Query "${queryName}" input validation failed: ${message}`);
|
|
91
|
-
this.queryName = queryName;
|
|
92
|
-
this.issues = issues;
|
|
93
|
-
this.name = "QueryInputValidationError";
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
* Error thrown when query output validation fails
|
|
98
|
-
*/
|
|
99
|
-
var QueryOutputValidationError = class extends WorkerError {
|
|
100
|
-
constructor(queryName, issues) {
|
|
101
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
102
|
-
super(`Query "${queryName}" output validation failed: ${message}`);
|
|
103
|
-
this.queryName = queryName;
|
|
104
|
-
this.issues = issues;
|
|
105
|
-
this.name = "QueryOutputValidationError";
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Error thrown when update input validation fails
|
|
110
|
-
*/
|
|
111
|
-
var UpdateInputValidationError = class extends WorkerError {
|
|
112
|
-
constructor(updateName, issues) {
|
|
113
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
114
|
-
super(`Update "${updateName}" input validation failed: ${message}`);
|
|
115
|
-
this.updateName = updateName;
|
|
116
|
-
this.issues = issues;
|
|
117
|
-
this.name = "UpdateInputValidationError";
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
/**
|
|
121
|
-
* Error thrown when update output validation fails
|
|
122
|
-
*/
|
|
123
|
-
var UpdateOutputValidationError = class extends WorkerError {
|
|
124
|
-
constructor(updateName, issues) {
|
|
125
|
-
const message = issues.map((issue) => issue.message).join("; ");
|
|
126
|
-
super(`Update "${updateName}" output validation failed: ${message}`);
|
|
127
|
-
this.updateName = updateName;
|
|
128
|
-
this.issues = issues;
|
|
129
|
-
this.name = "UpdateOutputValidationError";
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* Error thrown when a child workflow is not found in the contract
|
|
134
|
-
*/
|
|
135
|
-
var ChildWorkflowNotFoundError = class extends WorkerError {
|
|
136
|
-
constructor(workflowName, availableWorkflows = []) {
|
|
137
|
-
const available = availableWorkflows.length > 0 ? availableWorkflows.join(", ") : "none";
|
|
138
|
-
super(`Child workflow not found: "${workflowName}". Available workflows: ${available}`);
|
|
139
|
-
this.workflowName = workflowName;
|
|
140
|
-
this.availableWorkflows = availableWorkflows;
|
|
141
|
-
this.name = "ChildWorkflowNotFoundError";
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
/**
|
|
145
|
-
* Generic error for child workflow operations
|
|
146
|
-
*/
|
|
147
|
-
var ChildWorkflowError = class extends WorkerError {
|
|
148
|
-
constructor(message, cause) {
|
|
149
|
-
super(message, cause);
|
|
150
|
-
this.name = "ChildWorkflowError";
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
|
|
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 };
|