@temporal-contract/worker 0.0.5 → 0.0.6

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.
@@ -0,0 +1,137 @@
1
+ import { AnySchema } from "@temporal-contract/contract";
2
+ import { StandardSchemaV1 } from "@standard-schema/spec";
3
+
4
+ //#region src/types.d.ts
5
+
6
+ /**
7
+ * Infer input type from a definition (worker perspective)
8
+ * Worker receives the output type (after input schema parsing/transformation)
9
+ */
10
+ type WorkerInferInput<T extends {
11
+ input: AnySchema;
12
+ }> = StandardSchemaV1.InferOutput<T["input"]>;
13
+ /**
14
+ * Infer output type from a definition (worker perspective)
15
+ * Worker returns the input type (before output schema parsing/transformation)
16
+ */
17
+ type WorkerInferOutput<T extends {
18
+ output: AnySchema;
19
+ }> = StandardSchemaV1.InferInput<T["output"]>;
20
+ /**
21
+ * Infer input type from a definition (client perspective)
22
+ * Client sends the input type (before input schema parsing/transformation)
23
+ */
24
+ type ClientInferInput<T extends {
25
+ input: AnySchema;
26
+ }> = StandardSchemaV1.InferInput<T["input"]>;
27
+ /**
28
+ * Infer output type from a definition (client perspective)
29
+ * Client receives the output type (after output schema parsing/transformation)
30
+ */
31
+ type ClientInferOutput<T extends {
32
+ output: AnySchema;
33
+ }> = StandardSchemaV1.InferOutput<T["output"]>;
34
+ //#endregion
35
+ //#region src/errors.d.ts
36
+ /**
37
+ * Base error class for worker errors
38
+ */
39
+ declare abstract class WorkerError extends Error {
40
+ protected constructor(message: string, cause?: unknown);
41
+ }
42
+ /**
43
+ * Error thrown when an activity definition is not found in the contract
44
+ */
45
+ declare class ActivityDefinitionNotFoundError extends WorkerError {
46
+ readonly activityName: string;
47
+ readonly availableDefinitions: readonly string[];
48
+ constructor(activityName: string, availableDefinitions?: readonly string[]);
49
+ }
50
+ /**
51
+ * Error thrown when activity input validation fails
52
+ */
53
+ declare class ActivityInputValidationError extends WorkerError {
54
+ readonly activityName: string;
55
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
56
+ constructor(activityName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
57
+ }
58
+ /**
59
+ * Error thrown when activity output validation fails
60
+ */
61
+ declare class ActivityOutputValidationError extends WorkerError {
62
+ readonly activityName: string;
63
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
64
+ constructor(activityName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
65
+ }
66
+ /**
67
+ * Error thrown when workflow input validation fails
68
+ */
69
+ declare class WorkflowInputValidationError extends WorkerError {
70
+ readonly workflowName: string;
71
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
72
+ constructor(workflowName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
73
+ }
74
+ /**
75
+ * Error thrown when workflow output validation fails
76
+ */
77
+ declare class WorkflowOutputValidationError extends WorkerError {
78
+ readonly workflowName: string;
79
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
80
+ constructor(workflowName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
81
+ }
82
+ /**
83
+ * Error thrown when signal input validation fails
84
+ */
85
+ declare class SignalInputValidationError extends WorkerError {
86
+ readonly signalName: string;
87
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
88
+ constructor(signalName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
89
+ }
90
+ /**
91
+ * Error thrown when query input validation fails
92
+ */
93
+ declare class QueryInputValidationError extends WorkerError {
94
+ readonly queryName: string;
95
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
96
+ constructor(queryName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
97
+ }
98
+ /**
99
+ * Error thrown when query output validation fails
100
+ */
101
+ declare class QueryOutputValidationError extends WorkerError {
102
+ readonly queryName: string;
103
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
104
+ constructor(queryName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
105
+ }
106
+ /**
107
+ * Error thrown when update input validation fails
108
+ */
109
+ declare class UpdateInputValidationError extends WorkerError {
110
+ readonly updateName: string;
111
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
112
+ constructor(updateName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
113
+ }
114
+ /**
115
+ * Error thrown when update output validation fails
116
+ */
117
+ declare class UpdateOutputValidationError extends WorkerError {
118
+ readonly updateName: string;
119
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
120
+ constructor(updateName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
121
+ }
122
+ /**
123
+ * Error thrown when a child workflow is not found in the contract
124
+ */
125
+ declare class ChildWorkflowNotFoundError extends WorkerError {
126
+ readonly workflowName: string;
127
+ readonly availableWorkflows: readonly string[];
128
+ constructor(workflowName: string, availableWorkflows?: readonly string[]);
129
+ }
130
+ /**
131
+ * Generic error for child workflow operations
132
+ */
133
+ declare class ChildWorkflowError extends WorkerError {
134
+ constructor(message: string, cause?: unknown);
135
+ }
136
+ //#endregion
137
+ 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 };
@@ -0,0 +1,137 @@
1
+ import { AnySchema } from "@temporal-contract/contract";
2
+ import { StandardSchemaV1 } from "@standard-schema/spec";
3
+
4
+ //#region src/types.d.ts
5
+
6
+ /**
7
+ * Infer input type from a definition (worker perspective)
8
+ * Worker receives the output type (after input schema parsing/transformation)
9
+ */
10
+ type WorkerInferInput<T extends {
11
+ input: AnySchema;
12
+ }> = StandardSchemaV1.InferOutput<T["input"]>;
13
+ /**
14
+ * Infer output type from a definition (worker perspective)
15
+ * Worker returns the input type (before output schema parsing/transformation)
16
+ */
17
+ type WorkerInferOutput<T extends {
18
+ output: AnySchema;
19
+ }> = StandardSchemaV1.InferInput<T["output"]>;
20
+ /**
21
+ * Infer input type from a definition (client perspective)
22
+ * Client sends the input type (before input schema parsing/transformation)
23
+ */
24
+ type ClientInferInput<T extends {
25
+ input: AnySchema;
26
+ }> = StandardSchemaV1.InferInput<T["input"]>;
27
+ /**
28
+ * Infer output type from a definition (client perspective)
29
+ * Client receives the output type (after output schema parsing/transformation)
30
+ */
31
+ type ClientInferOutput<T extends {
32
+ output: AnySchema;
33
+ }> = StandardSchemaV1.InferOutput<T["output"]>;
34
+ //#endregion
35
+ //#region src/errors.d.ts
36
+ /**
37
+ * Base error class for worker errors
38
+ */
39
+ declare abstract class WorkerError extends Error {
40
+ protected constructor(message: string, cause?: unknown);
41
+ }
42
+ /**
43
+ * Error thrown when an activity definition is not found in the contract
44
+ */
45
+ declare class ActivityDefinitionNotFoundError extends WorkerError {
46
+ readonly activityName: string;
47
+ readonly availableDefinitions: readonly string[];
48
+ constructor(activityName: string, availableDefinitions?: readonly string[]);
49
+ }
50
+ /**
51
+ * Error thrown when activity input validation fails
52
+ */
53
+ declare class ActivityInputValidationError extends WorkerError {
54
+ readonly activityName: string;
55
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
56
+ constructor(activityName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
57
+ }
58
+ /**
59
+ * Error thrown when activity output validation fails
60
+ */
61
+ declare class ActivityOutputValidationError extends WorkerError {
62
+ readonly activityName: string;
63
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
64
+ constructor(activityName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
65
+ }
66
+ /**
67
+ * Error thrown when workflow input validation fails
68
+ */
69
+ declare class WorkflowInputValidationError extends WorkerError {
70
+ readonly workflowName: string;
71
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
72
+ constructor(workflowName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
73
+ }
74
+ /**
75
+ * Error thrown when workflow output validation fails
76
+ */
77
+ declare class WorkflowOutputValidationError extends WorkerError {
78
+ readonly workflowName: string;
79
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
80
+ constructor(workflowName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
81
+ }
82
+ /**
83
+ * Error thrown when signal input validation fails
84
+ */
85
+ declare class SignalInputValidationError extends WorkerError {
86
+ readonly signalName: string;
87
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
88
+ constructor(signalName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
89
+ }
90
+ /**
91
+ * Error thrown when query input validation fails
92
+ */
93
+ declare class QueryInputValidationError extends WorkerError {
94
+ readonly queryName: string;
95
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
96
+ constructor(queryName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
97
+ }
98
+ /**
99
+ * Error thrown when query output validation fails
100
+ */
101
+ declare class QueryOutputValidationError extends WorkerError {
102
+ readonly queryName: string;
103
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
104
+ constructor(queryName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
105
+ }
106
+ /**
107
+ * Error thrown when update input validation fails
108
+ */
109
+ declare class UpdateInputValidationError extends WorkerError {
110
+ readonly updateName: string;
111
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
112
+ constructor(updateName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
113
+ }
114
+ /**
115
+ * Error thrown when update output validation fails
116
+ */
117
+ declare class UpdateOutputValidationError extends WorkerError {
118
+ readonly updateName: string;
119
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
120
+ constructor(updateName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
121
+ }
122
+ /**
123
+ * Error thrown when a child workflow is not found in the contract
124
+ */
125
+ declare class ChildWorkflowNotFoundError extends WorkerError {
126
+ readonly workflowName: string;
127
+ readonly availableWorkflows: readonly string[];
128
+ constructor(workflowName: string, availableWorkflows?: readonly string[]);
129
+ }
130
+ /**
131
+ * Generic error for child workflow operations
132
+ */
133
+ declare class ChildWorkflowError extends WorkerError {
134
+ constructor(message: string, cause?: unknown);
135
+ }
136
+ //#endregion
137
+ 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 };
@@ -0,0 +1,227 @@
1
+
2
+ //#region src/errors.ts
3
+ /**
4
+ * Base error class for worker errors
5
+ */
6
+ var WorkerError = class extends Error {
7
+ constructor(message, cause) {
8
+ super(message, { cause });
9
+ this.name = "WorkerError";
10
+ if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
11
+ }
12
+ };
13
+ /**
14
+ * Error thrown when an activity definition is not found in the contract
15
+ */
16
+ var ActivityDefinitionNotFoundError = class extends WorkerError {
17
+ constructor(activityName, availableDefinitions = []) {
18
+ const available = availableDefinitions.length > 0 ? availableDefinitions.join(", ") : "none";
19
+ super(`Activity definition not found for: "${activityName}". Available activities: ${available}`);
20
+ this.activityName = activityName;
21
+ this.availableDefinitions = availableDefinitions;
22
+ this.name = "ActivityDefinitionNotFoundError";
23
+ }
24
+ };
25
+ /**
26
+ * Error thrown when activity input validation fails
27
+ */
28
+ var ActivityInputValidationError = class extends WorkerError {
29
+ constructor(activityName, issues) {
30
+ const message = issues.map((issue) => issue.message).join("; ");
31
+ super(`Activity "${activityName}" input validation failed: ${message}`);
32
+ this.activityName = activityName;
33
+ this.issues = issues;
34
+ this.name = "ActivityInputValidationError";
35
+ }
36
+ };
37
+ /**
38
+ * Error thrown when activity output validation fails
39
+ */
40
+ var ActivityOutputValidationError = class extends WorkerError {
41
+ constructor(activityName, issues) {
42
+ const message = issues.map((issue) => issue.message).join("; ");
43
+ super(`Activity "${activityName}" output validation failed: ${message}`);
44
+ this.activityName = activityName;
45
+ this.issues = issues;
46
+ this.name = "ActivityOutputValidationError";
47
+ }
48
+ };
49
+ /**
50
+ * Error thrown when workflow input validation fails
51
+ */
52
+ var WorkflowInputValidationError = class extends WorkerError {
53
+ constructor(workflowName, issues) {
54
+ const message = issues.map((issue) => issue.message).join("; ");
55
+ super(`Workflow "${workflowName}" input validation failed: ${message}`);
56
+ this.workflowName = workflowName;
57
+ this.issues = issues;
58
+ this.name = "WorkflowInputValidationError";
59
+ }
60
+ };
61
+ /**
62
+ * Error thrown when workflow output validation fails
63
+ */
64
+ var WorkflowOutputValidationError = class extends WorkerError {
65
+ constructor(workflowName, issues) {
66
+ const message = issues.map((issue) => issue.message).join("; ");
67
+ super(`Workflow "${workflowName}" output validation failed: ${message}`);
68
+ this.workflowName = workflowName;
69
+ this.issues = issues;
70
+ this.name = "WorkflowOutputValidationError";
71
+ }
72
+ };
73
+ /**
74
+ * Error thrown when signal input validation fails
75
+ */
76
+ var SignalInputValidationError = class extends WorkerError {
77
+ constructor(signalName, issues) {
78
+ const message = issues.map((issue) => issue.message).join("; ");
79
+ super(`Signal "${signalName}" input validation failed: ${message}`);
80
+ this.signalName = signalName;
81
+ this.issues = issues;
82
+ this.name = "SignalInputValidationError";
83
+ }
84
+ };
85
+ /**
86
+ * Error thrown when query input validation fails
87
+ */
88
+ var QueryInputValidationError = class extends WorkerError {
89
+ constructor(queryName, issues) {
90
+ const message = issues.map((issue) => issue.message).join("; ");
91
+ super(`Query "${queryName}" input validation failed: ${message}`);
92
+ this.queryName = queryName;
93
+ this.issues = issues;
94
+ this.name = "QueryInputValidationError";
95
+ }
96
+ };
97
+ /**
98
+ * Error thrown when query output validation fails
99
+ */
100
+ var QueryOutputValidationError = class extends WorkerError {
101
+ constructor(queryName, issues) {
102
+ const message = issues.map((issue) => issue.message).join("; ");
103
+ super(`Query "${queryName}" output validation failed: ${message}`);
104
+ this.queryName = queryName;
105
+ this.issues = issues;
106
+ this.name = "QueryOutputValidationError";
107
+ }
108
+ };
109
+ /**
110
+ * Error thrown when update input validation fails
111
+ */
112
+ var UpdateInputValidationError = class extends WorkerError {
113
+ constructor(updateName, issues) {
114
+ const message = issues.map((issue) => issue.message).join("; ");
115
+ super(`Update "${updateName}" input validation failed: ${message}`);
116
+ this.updateName = updateName;
117
+ this.issues = issues;
118
+ this.name = "UpdateInputValidationError";
119
+ }
120
+ };
121
+ /**
122
+ * Error thrown when update output validation fails
123
+ */
124
+ var UpdateOutputValidationError = class extends WorkerError {
125
+ constructor(updateName, issues) {
126
+ const message = issues.map((issue) => issue.message).join("; ");
127
+ super(`Update "${updateName}" output validation failed: ${message}`);
128
+ this.updateName = updateName;
129
+ this.issues = issues;
130
+ this.name = "UpdateOutputValidationError";
131
+ }
132
+ };
133
+ /**
134
+ * Error thrown when a child workflow is not found in the contract
135
+ */
136
+ var ChildWorkflowNotFoundError = class extends WorkerError {
137
+ constructor(workflowName, availableWorkflows = []) {
138
+ const available = availableWorkflows.length > 0 ? availableWorkflows.join(", ") : "none";
139
+ super(`Child workflow not found: "${workflowName}". Available workflows: ${available}`);
140
+ this.workflowName = workflowName;
141
+ this.availableWorkflows = availableWorkflows;
142
+ this.name = "ChildWorkflowNotFoundError";
143
+ }
144
+ };
145
+ /**
146
+ * Generic error for child workflow operations
147
+ */
148
+ var ChildWorkflowError = class extends WorkerError {
149
+ constructor(message, cause) {
150
+ super(message, cause);
151
+ this.name = "ChildWorkflowError";
152
+ }
153
+ };
154
+
155
+ //#endregion
156
+ Object.defineProperty(exports, 'ActivityDefinitionNotFoundError', {
157
+ enumerable: true,
158
+ get: function () {
159
+ return ActivityDefinitionNotFoundError;
160
+ }
161
+ });
162
+ Object.defineProperty(exports, 'ActivityInputValidationError', {
163
+ enumerable: true,
164
+ get: function () {
165
+ return ActivityInputValidationError;
166
+ }
167
+ });
168
+ Object.defineProperty(exports, 'ActivityOutputValidationError', {
169
+ enumerable: true,
170
+ get: function () {
171
+ return ActivityOutputValidationError;
172
+ }
173
+ });
174
+ Object.defineProperty(exports, 'ChildWorkflowError', {
175
+ enumerable: true,
176
+ get: function () {
177
+ return ChildWorkflowError;
178
+ }
179
+ });
180
+ Object.defineProperty(exports, 'ChildWorkflowNotFoundError', {
181
+ enumerable: true,
182
+ get: function () {
183
+ return ChildWorkflowNotFoundError;
184
+ }
185
+ });
186
+ Object.defineProperty(exports, 'QueryInputValidationError', {
187
+ enumerable: true,
188
+ get: function () {
189
+ return QueryInputValidationError;
190
+ }
191
+ });
192
+ Object.defineProperty(exports, 'QueryOutputValidationError', {
193
+ enumerable: true,
194
+ get: function () {
195
+ return QueryOutputValidationError;
196
+ }
197
+ });
198
+ Object.defineProperty(exports, 'SignalInputValidationError', {
199
+ enumerable: true,
200
+ get: function () {
201
+ return SignalInputValidationError;
202
+ }
203
+ });
204
+ Object.defineProperty(exports, 'UpdateInputValidationError', {
205
+ enumerable: true,
206
+ get: function () {
207
+ return UpdateInputValidationError;
208
+ }
209
+ });
210
+ Object.defineProperty(exports, 'UpdateOutputValidationError', {
211
+ enumerable: true,
212
+ get: function () {
213
+ return UpdateOutputValidationError;
214
+ }
215
+ });
216
+ Object.defineProperty(exports, 'WorkflowInputValidationError', {
217
+ enumerable: true,
218
+ get: function () {
219
+ return WorkflowInputValidationError;
220
+ }
221
+ });
222
+ Object.defineProperty(exports, 'WorkflowOutputValidationError', {
223
+ enumerable: true,
224
+ get: function () {
225
+ return WorkflowOutputValidationError;
226
+ }
227
+ });
@@ -0,0 +1,65 @@
1
+ let _temporalio_worker = require("@temporalio/worker");
2
+ let node_url = require("node:url");
3
+ let node_path = require("node:path");
4
+
5
+ //#region src/worker.ts
6
+ /**
7
+ * Create a typed Temporal worker with contract-based configuration
8
+ *
9
+ * This helper simplifies worker creation by:
10
+ * - Using the contract's task queue automatically
11
+ * - Providing type-safe configuration
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { NativeConnection } from '@temporalio/worker';
16
+ * import { createWorker } from '@temporal-contract/worker/worker';
17
+ * import { activities } from './activities';
18
+ * import myContract from './contract';
19
+ *
20
+ * const connection = await NativeConnection.connect({
21
+ * address: 'localhost:7233',
22
+ * });
23
+ *
24
+ * const worker = await createWorker({
25
+ * contract: myContract,
26
+ * connection,
27
+ * workflowsPath: require.resolve('./workflows'),
28
+ * activities,
29
+ * });
30
+ *
31
+ * await worker.run();
32
+ * ```
33
+ */
34
+ async function createWorker(options) {
35
+ const { contract, activities, ...workerOptions } = options;
36
+ return await _temporalio_worker.Worker.create({
37
+ ...workerOptions,
38
+ activities,
39
+ taskQueue: contract.taskQueue
40
+ });
41
+ }
42
+ /**
43
+ * Helper to create a workflowsPath from a file URL
44
+ *
45
+ * Useful for creating the workflowsPath option when using ES modules
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { workflowsPathFromURL } from '@temporal-contract/worker/worker';
50
+ *
51
+ * const worker = await createWorker({
52
+ * contract: myContract,
53
+ * connection,
54
+ * workflowsPath: workflowsPathFromURL(import.meta.url, './workflows'),
55
+ * activities,
56
+ * });
57
+ * ```
58
+ */
59
+ function workflowsPathFromURL(baseURL, relativePath) {
60
+ return (0, node_url.fileURLToPath)(new URL(`${relativePath}${(0, node_path.extname)(baseURL)}`, baseURL));
61
+ }
62
+
63
+ //#endregion
64
+ exports.createWorker = createWorker;
65
+ exports.workflowsPathFromURL = workflowsPathFromURL;
@@ -0,0 +1,68 @@
1
+ import { ActivitiesHandler } from "./activity.cjs";
2
+ import { ContractDefinition } from "@temporal-contract/contract";
3
+ import { Worker, WorkerOptions } from "@temporalio/worker";
4
+
5
+ //#region src/worker.d.ts
6
+
7
+ /**
8
+ * Options for creating a Temporal worker
9
+ */
10
+ interface CreateWorkerOptions<TContract extends ContractDefinition> extends Omit<WorkerOptions, "activities" | "taskQueue"> {
11
+ /**
12
+ * The contract definition for this worker
13
+ */
14
+ contract: TContract;
15
+ /**
16
+ * Activities handler for this worker
17
+ */
18
+ activities: ActivitiesHandler<TContract>;
19
+ }
20
+ /**
21
+ * Create a typed Temporal worker with contract-based configuration
22
+ *
23
+ * This helper simplifies worker creation by:
24
+ * - Using the contract's task queue automatically
25
+ * - Providing type-safe configuration
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { NativeConnection } from '@temporalio/worker';
30
+ * import { createWorker } from '@temporal-contract/worker/worker';
31
+ * import { activities } from './activities';
32
+ * import myContract from './contract';
33
+ *
34
+ * const connection = await NativeConnection.connect({
35
+ * address: 'localhost:7233',
36
+ * });
37
+ *
38
+ * const worker = await createWorker({
39
+ * contract: myContract,
40
+ * connection,
41
+ * workflowsPath: require.resolve('./workflows'),
42
+ * activities,
43
+ * });
44
+ *
45
+ * await worker.run();
46
+ * ```
47
+ */
48
+ declare function createWorker<TContract extends ContractDefinition>(options: CreateWorkerOptions<TContract>): Promise<Worker>;
49
+ /**
50
+ * Helper to create a workflowsPath from a file URL
51
+ *
52
+ * Useful for creating the workflowsPath option when using ES modules
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import { workflowsPathFromURL } from '@temporal-contract/worker/worker';
57
+ *
58
+ * const worker = await createWorker({
59
+ * contract: myContract,
60
+ * connection,
61
+ * workflowsPath: workflowsPathFromURL(import.meta.url, './workflows'),
62
+ * activities,
63
+ * });
64
+ * ```
65
+ */
66
+ declare function workflowsPathFromURL(baseURL: string, relativePath: string): string;
67
+ //#endregion
68
+ export { CreateWorkerOptions, createWorker, workflowsPathFromURL };
@@ -0,0 +1,68 @@
1
+ import { ActivitiesHandler } from "./activity.mjs";
2
+ import { Worker, WorkerOptions } from "@temporalio/worker";
3
+ import { ContractDefinition } from "@temporal-contract/contract";
4
+
5
+ //#region src/worker.d.ts
6
+
7
+ /**
8
+ * Options for creating a Temporal worker
9
+ */
10
+ interface CreateWorkerOptions<TContract extends ContractDefinition> extends Omit<WorkerOptions, "activities" | "taskQueue"> {
11
+ /**
12
+ * The contract definition for this worker
13
+ */
14
+ contract: TContract;
15
+ /**
16
+ * Activities handler for this worker
17
+ */
18
+ activities: ActivitiesHandler<TContract>;
19
+ }
20
+ /**
21
+ * Create a typed Temporal worker with contract-based configuration
22
+ *
23
+ * This helper simplifies worker creation by:
24
+ * - Using the contract's task queue automatically
25
+ * - Providing type-safe configuration
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { NativeConnection } from '@temporalio/worker';
30
+ * import { createWorker } from '@temporal-contract/worker/worker';
31
+ * import { activities } from './activities';
32
+ * import myContract from './contract';
33
+ *
34
+ * const connection = await NativeConnection.connect({
35
+ * address: 'localhost:7233',
36
+ * });
37
+ *
38
+ * const worker = await createWorker({
39
+ * contract: myContract,
40
+ * connection,
41
+ * workflowsPath: require.resolve('./workflows'),
42
+ * activities,
43
+ * });
44
+ *
45
+ * await worker.run();
46
+ * ```
47
+ */
48
+ declare function createWorker<TContract extends ContractDefinition>(options: CreateWorkerOptions<TContract>): Promise<Worker>;
49
+ /**
50
+ * Helper to create a workflowsPath from a file URL
51
+ *
52
+ * Useful for creating the workflowsPath option when using ES modules
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import { workflowsPathFromURL } from '@temporal-contract/worker/worker';
57
+ *
58
+ * const worker = await createWorker({
59
+ * contract: myContract,
60
+ * connection,
61
+ * workflowsPath: workflowsPathFromURL(import.meta.url, './workflows'),
62
+ * activities,
63
+ * });
64
+ * ```
65
+ */
66
+ declare function workflowsPathFromURL(baseURL: string, relativePath: string): string;
67
+ //#endregion
68
+ export { CreateWorkerOptions, createWorker, workflowsPathFromURL };