@temporal-contract/worker 0.0.7 → 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 +47 -34
- package/dist/activity-utils-B3vP03_P.d.mts +68 -0
- package/dist/activity-utils-B3vP03_P.d.mts.map +1 -0
- package/dist/activity-utils-RsXOceIH.d.cts +68 -0
- package/dist/activity-utils-RsXOceIH.d.cts.map +1 -0
- package/dist/activity.cjs +1 -0
- package/dist/activity.d.cts +99 -3
- package/dist/activity.d.cts.map +1 -0
- package/dist/activity.d.mts +99 -3
- package/dist/activity.d.mts.map +1 -0
- package/dist/activity.mjs +3 -2
- package/dist/activity.mjs.map +1 -0
- package/dist/{errors-C1RFkCuD.d.mts → errors-4jH78z8m.d.cts} +2 -2
- package/dist/errors-4jH78z8m.d.cts.map +1 -0
- package/dist/{errors-BqYWpdvd.d.cts → errors-CmTXZ3JW.d.mts} +2 -2
- package/dist/errors-CmTXZ3JW.d.mts.map +1 -0
- package/dist/{errors-BqVTpfcf.mjs → errors-Di6Ja4Rt.mjs} +2 -1
- package/dist/errors-Di6Ja4Rt.mjs.map +1 -0
- package/dist/worker.cjs +11 -5
- package/dist/worker.d.cts +14 -8
- package/dist/worker.d.cts.map +1 -0
- package/dist/worker.d.mts +14 -8
- package/dist/worker.d.mts.map +1 -0
- package/dist/worker.mjs +12 -6
- package/dist/worker.mjs.map +1 -0
- package/dist/workflow.cjs +92 -106
- package/dist/workflow.d.cts +35 -35
- package/dist/workflow.d.cts.map +1 -0
- package/dist/workflow.d.mts +35 -35
- package/dist/workflow.d.mts.map +1 -0
- package/dist/workflow.mjs +94 -108
- package/dist/workflow.mjs.map +1 -0
- package/package.json +18 -14
- package/dist/activity-Csptpwgf.d.cts +0 -162
- package/dist/activity-UOnp_bSX.d.mts +0 -162
|
@@ -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":"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"}
|
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
|
|
43
|
+
* Helper to resolve a workflow file path relative to the current module's URL.
|
|
44
44
|
*
|
|
45
|
-
* Useful
|
|
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
|
-
*
|
|
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(
|
|
66
|
+
return (0, node_url.fileURLToPath)(new URL(relativePath, baseURL));
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
//#endregion
|
package/dist/worker.d.cts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ActivitiesHandler } from "./activity.cjs";
|
|
2
2
|
import { ContractDefinition } from "@temporal-contract/contract";
|
|
3
3
|
import { Worker, WorkerOptions } from "@temporalio/worker";
|
|
4
4
|
|
|
5
5
|
//#region src/worker.d.ts
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* Options for creating a Temporal worker
|
|
9
8
|
*/
|
|
10
|
-
|
|
9
|
+
type CreateWorkerOptions<TContract extends ContractDefinition> = Omit<WorkerOptions, "activities" | "taskQueue"> & {
|
|
11
10
|
/**
|
|
12
11
|
* The contract definition for this worker
|
|
13
12
|
*/
|
|
@@ -16,7 +15,7 @@ interface CreateWorkerOptions<TContract extends ContractDefinition> extends Omit
|
|
|
16
15
|
* Activities handler for this worker
|
|
17
16
|
*/
|
|
18
17
|
activities: ActivitiesHandler<TContract>;
|
|
19
|
-
}
|
|
18
|
+
};
|
|
20
19
|
/**
|
|
21
20
|
* Create a typed Temporal worker with contract-based configuration
|
|
22
21
|
*
|
|
@@ -47,9 +46,14 @@ interface CreateWorkerOptions<TContract extends ContractDefinition> extends Omit
|
|
|
47
46
|
*/
|
|
48
47
|
declare function createWorker<TContract extends ContractDefinition>(options: CreateWorkerOptions<TContract>): Promise<Worker>;
|
|
49
48
|
/**
|
|
50
|
-
* Helper to
|
|
49
|
+
* Helper to resolve a workflow file path relative to the current module's URL.
|
|
50
|
+
*
|
|
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.
|
|
51
54
|
*
|
|
52
|
-
*
|
|
55
|
+
* @param baseURL - The base URL to resolve from, typically `import.meta.url`
|
|
56
|
+
* @param relativePath - Relative path to the workflows file, **including extension**
|
|
53
57
|
*
|
|
54
58
|
* @example
|
|
55
59
|
* ```ts
|
|
@@ -58,11 +62,13 @@ declare function createWorker<TContract extends ContractDefinition>(options: Cre
|
|
|
58
62
|
* const worker = await createWorker({
|
|
59
63
|
* contract: myContract,
|
|
60
64
|
* connection,
|
|
61
|
-
*
|
|
65
|
+
* // Include the extension explicitly to work in both source (.ts) and build (.js) contexts
|
|
66
|
+
* workflowsPath: workflowsPathFromURL(import.meta.url, './workflows.js'),
|
|
62
67
|
* activities,
|
|
63
68
|
* });
|
|
64
69
|
* ```
|
|
65
70
|
*/
|
|
66
71
|
declare function workflowsPathFromURL(baseURL: string, relativePath: string): string;
|
|
67
72
|
//#endregion
|
|
68
|
-
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"}
|
package/dist/worker.d.mts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ActivitiesHandler } from "./activity.mjs";
|
|
2
2
|
import { Worker, WorkerOptions } from "@temporalio/worker";
|
|
3
3
|
import { ContractDefinition } from "@temporal-contract/contract";
|
|
4
4
|
|
|
5
5
|
//#region src/worker.d.ts
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* Options for creating a Temporal worker
|
|
9
8
|
*/
|
|
10
|
-
|
|
9
|
+
type CreateWorkerOptions<TContract extends ContractDefinition> = Omit<WorkerOptions, "activities" | "taskQueue"> & {
|
|
11
10
|
/**
|
|
12
11
|
* The contract definition for this worker
|
|
13
12
|
*/
|
|
@@ -16,7 +15,7 @@ interface CreateWorkerOptions<TContract extends ContractDefinition> extends Omit
|
|
|
16
15
|
* Activities handler for this worker
|
|
17
16
|
*/
|
|
18
17
|
activities: ActivitiesHandler<TContract>;
|
|
19
|
-
}
|
|
18
|
+
};
|
|
20
19
|
/**
|
|
21
20
|
* Create a typed Temporal worker with contract-based configuration
|
|
22
21
|
*
|
|
@@ -47,9 +46,14 @@ interface CreateWorkerOptions<TContract extends ContractDefinition> extends Omit
|
|
|
47
46
|
*/
|
|
48
47
|
declare function createWorker<TContract extends ContractDefinition>(options: CreateWorkerOptions<TContract>): Promise<Worker>;
|
|
49
48
|
/**
|
|
50
|
-
* Helper to
|
|
49
|
+
* Helper to resolve a workflow file path relative to the current module's URL.
|
|
50
|
+
*
|
|
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.
|
|
51
54
|
*
|
|
52
|
-
*
|
|
55
|
+
* @param baseURL - The base URL to resolve from, typically `import.meta.url`
|
|
56
|
+
* @param relativePath - Relative path to the workflows file, **including extension**
|
|
53
57
|
*
|
|
54
58
|
* @example
|
|
55
59
|
* ```ts
|
|
@@ -58,11 +62,13 @@ declare function createWorker<TContract extends ContractDefinition>(options: Cre
|
|
|
58
62
|
* const worker = await createWorker({
|
|
59
63
|
* contract: myContract,
|
|
60
64
|
* connection,
|
|
61
|
-
*
|
|
65
|
+
* // Include the extension explicitly to work in both source (.ts) and build (.js) contexts
|
|
66
|
+
* workflowsPath: workflowsPathFromURL(import.meta.url, './workflows.js'),
|
|
62
67
|
* activities,
|
|
63
68
|
* });
|
|
64
69
|
* ```
|
|
65
70
|
*/
|
|
66
71
|
declare function workflowsPathFromURL(baseURL: string, relativePath: string): string;
|
|
67
72
|
//#endregion
|
|
68
|
-
export { CreateWorkerOptions, createWorker, workflowsPathFromURL };
|
|
73
|
+
export { CreateWorkerOptions, createWorker, workflowsPathFromURL };
|
|
74
|
+
//# sourceMappingURL=worker.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.mts","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"}
|
package/dist/worker.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Worker } from "@temporalio/worker";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
|
-
import { extname } from "node:path";
|
|
4
3
|
|
|
5
4
|
//#region src/worker.ts
|
|
6
5
|
/**
|
|
@@ -40,9 +39,14 @@ async function createWorker(options) {
|
|
|
40
39
|
});
|
|
41
40
|
}
|
|
42
41
|
/**
|
|
43
|
-
* Helper to
|
|
42
|
+
* Helper to resolve a workflow file path relative to the current module's URL.
|
|
44
43
|
*
|
|
45
|
-
* Useful
|
|
44
|
+
* Useful when using ES modules (`import.meta.url`) to locate workflow files.
|
|
45
|
+
* The `relativePath` should include the file extension explicitly (e.g. `./workflows.js`)
|
|
46
|
+
* to ensure the resolved path is unambiguous in both source and built contexts.
|
|
47
|
+
*
|
|
48
|
+
* @param baseURL - The base URL to resolve from, typically `import.meta.url`
|
|
49
|
+
* @param relativePath - Relative path to the workflows file, **including extension**
|
|
46
50
|
*
|
|
47
51
|
* @example
|
|
48
52
|
* ```ts
|
|
@@ -51,14 +55,16 @@ async function createWorker(options) {
|
|
|
51
55
|
* const worker = await createWorker({
|
|
52
56
|
* contract: myContract,
|
|
53
57
|
* connection,
|
|
54
|
-
*
|
|
58
|
+
* // Include the extension explicitly to work in both source (.ts) and build (.js) contexts
|
|
59
|
+
* workflowsPath: workflowsPathFromURL(import.meta.url, './workflows.js'),
|
|
55
60
|
* activities,
|
|
56
61
|
* });
|
|
57
62
|
* ```
|
|
58
63
|
*/
|
|
59
64
|
function workflowsPathFromURL(baseURL, relativePath) {
|
|
60
|
-
return fileURLToPath(new URL(
|
|
65
|
+
return fileURLToPath(new URL(relativePath, baseURL));
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
//#endregion
|
|
64
|
-
export { createWorker, workflowsPathFromURL };
|
|
69
|
+
export { createWorker, workflowsPathFromURL };
|
|
70
|
+
//# sourceMappingURL=worker.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.mjs","names":[],"sources":["../src/worker.ts"],"sourcesContent":["// Entry point for worker creation utilities\nimport { ContractDefinition } from \"@temporal-contract/contract\";\nimport { Worker, WorkerOptions } from \"@temporalio/worker\";\nimport { fileURLToPath } from \"node:url\";\nimport type { ActivitiesHandler } from \"./activity.js\";\n\n/**\n * Options for creating a Temporal worker\n */\nexport type CreateWorkerOptions<TContract extends ContractDefinition> = Omit<\n WorkerOptions,\n \"activities\" | \"taskQueue\"\n> & {\n /**\n * The contract definition for this worker\n */\n contract: TContract;\n\n /**\n * Activities handler for this worker\n */\n activities: ActivitiesHandler<TContract>;\n};\n\n/**\n * Create a typed Temporal worker with contract-based configuration\n *\n * This helper simplifies worker creation by:\n * - Using the contract's task queue automatically\n * - Providing type-safe configuration\n *\n * @example\n * ```ts\n * import { NativeConnection } from '@temporalio/worker';\n * import { createWorker } from '@temporal-contract/worker/worker';\n * import { activities } from './activities';\n * import myContract from './contract';\n *\n * const connection = await NativeConnection.connect({\n * address: 'localhost:7233',\n * });\n *\n * const worker = await createWorker({\n * contract: myContract,\n * connection,\n * workflowsPath: require.resolve('./workflows'),\n * activities,\n * });\n *\n * await worker.run();\n * ```\n */\nexport async function createWorker<TContract extends ContractDefinition>(\n options: CreateWorkerOptions<TContract>,\n): Promise<Worker> {\n const { contract, activities, ...workerOptions } = options;\n\n // Create the worker with contract's task queue\n return await Worker.create({\n ...workerOptions,\n activities,\n taskQueue: contract.taskQueue,\n });\n}\n\n/**\n * Helper to resolve a workflow file path relative to the current module's URL.\n *\n * Useful when using ES modules (`import.meta.url`) to locate workflow files.\n * The `relativePath` should include the file extension explicitly (e.g. `./workflows.js`)\n * to ensure the resolved path is unambiguous in both source and built contexts.\n *\n * @param baseURL - The base URL to resolve from, typically `import.meta.url`\n * @param relativePath - Relative path to the workflows file, **including extension**\n *\n * @example\n * ```ts\n * import { workflowsPathFromURL } from '@temporal-contract/worker/worker';\n *\n * const worker = await createWorker({\n * contract: myContract,\n * connection,\n * // Include the extension explicitly to work in both source (.ts) and build (.js) contexts\n * workflowsPath: workflowsPathFromURL(import.meta.url, './workflows.js'),\n * activities,\n * });\n * ```\n */\nexport function workflowsPathFromURL(baseURL: string, relativePath: string): string {\n return fileURLToPath(new URL(relativePath, baseURL));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,eAAsB,aACpB,SACiB;CACjB,MAAM,EAAE,UAAU,YAAY,GAAG,kBAAkB;AAGnD,QAAO,MAAM,OAAO,OAAO;EACzB,GAAG;EACH;EACA,WAAW,SAAS;EACrB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AA0BJ,SAAgB,qBAAqB,SAAiB,cAA8B;AAClF,QAAO,cAAc,IAAI,IAAI,cAAc,QAAQ,CAAC"}
|
package/dist/workflow.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
|
let _temporal_contract_boxed = require("@temporal-contract/boxed");
|
|
3
4
|
let _temporalio_workflow = require("@temporalio/workflow");
|
|
@@ -17,53 +18,53 @@ let _temporalio_workflow = require("@temporalio/workflow");
|
|
|
17
18
|
* @example
|
|
18
19
|
* ```ts
|
|
19
20
|
* // workflows/processOrder.ts
|
|
20
|
-
* import { declareWorkflow } from '@temporal-contract/worker';
|
|
21
|
+
* import { declareWorkflow } from '@temporal-contract/worker/workflow';
|
|
21
22
|
* import myContract from '../contract';
|
|
22
23
|
*
|
|
23
24
|
* export const processOrder = declareWorkflow({
|
|
24
25
|
* workflowName: 'processOrder',
|
|
25
26
|
* contract: myContract,
|
|
26
|
-
*
|
|
27
|
+
* activityOptions: {
|
|
28
|
+
* startToCloseTimeout: '1 minute',
|
|
29
|
+
* },
|
|
30
|
+
* implementation: async (context, args) => {
|
|
27
31
|
* // context.activities: typed activities (workflow + global)
|
|
28
32
|
* // context.info: WorkflowInfo
|
|
29
33
|
*
|
|
30
|
-
* const inventory = await context.activities.validateInventory(
|
|
34
|
+
* const inventory = await context.activities.validateInventory({
|
|
35
|
+
* orderId: args.orderId,
|
|
36
|
+
* });
|
|
31
37
|
*
|
|
32
38
|
* if (!inventory.available) {
|
|
33
|
-
*
|
|
39
|
+
* return { orderId: args.orderId, status: 'out_of_stock' };
|
|
34
40
|
* }
|
|
35
41
|
*
|
|
36
|
-
* const payment = await context.activities.chargePayment(
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* customerId,
|
|
41
|
-
* 'Order processed',
|
|
42
|
-
* 'Your order has been processed'
|
|
43
|
-
* );
|
|
42
|
+
* const payment = await context.activities.chargePayment({
|
|
43
|
+
* customerId: args.customerId,
|
|
44
|
+
* amount: 100,
|
|
45
|
+
* });
|
|
44
46
|
*
|
|
45
47
|
* return {
|
|
46
|
-
* orderId,
|
|
48
|
+
* orderId: args.orderId,
|
|
47
49
|
* status: payment.success ? 'success' : 'failed',
|
|
48
50
|
* transactionId: payment.transactionId,
|
|
49
51
|
* };
|
|
50
52
|
* },
|
|
51
|
-
* activityOptions: {
|
|
52
|
-
* startToCloseTimeout: '1 minute',
|
|
53
|
-
* },
|
|
54
53
|
* });
|
|
55
54
|
* ```
|
|
56
55
|
*
|
|
57
56
|
* Then in your worker setup:
|
|
58
57
|
* ```ts
|
|
59
58
|
* // worker.ts
|
|
60
|
-
* import {
|
|
61
|
-
* import {
|
|
59
|
+
* import { createWorker } from '@temporal-contract/worker/worker';
|
|
60
|
+
* import { activities } from './activities';
|
|
61
|
+
* import myContract from './contract';
|
|
62
62
|
*
|
|
63
|
-
* const worker = await
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
63
|
+
* const worker = await createWorker({
|
|
64
|
+
* contract: myContract,
|
|
65
|
+
* connection,
|
|
66
|
+
* workflowsPath: workflowsPathFromURL(import.meta.url, './workflows.js'),
|
|
67
|
+
* activities,
|
|
67
68
|
* });
|
|
68
69
|
* ```
|
|
69
70
|
*/
|
|
@@ -76,20 +77,20 @@ function declareWorkflow({ workflowName, contract, implementation, activityOptio
|
|
|
76
77
|
const validatedInput = inputResult.value;
|
|
77
78
|
let contextActivities = {};
|
|
78
79
|
if (definition.activities || contract.activities) contextActivities = createValidatedActivities((0, _temporalio_workflow.proxyActivities)(activityOptions), definition.activities, contract.activities);
|
|
79
|
-
async function validateChildWorkflowOutput(childDefinition, result
|
|
80
|
-
const outputResult
|
|
81
|
-
if (outputResult
|
|
82
|
-
return _temporal_contract_boxed.Result.Ok(outputResult
|
|
80
|
+
async function validateChildWorkflowOutput(childDefinition, result, childWorkflowName) {
|
|
81
|
+
const outputResult = await childDefinition.output["~standard"].validate(result);
|
|
82
|
+
if (outputResult.issues) return _temporal_contract_boxed.Result.Error(new require_errors.ChildWorkflowError(`Child workflow "${childWorkflowName}" output validation failed: ${outputResult.issues.map((i) => i.message).join("; ")}`));
|
|
83
|
+
return _temporal_contract_boxed.Result.Ok(outputResult.value);
|
|
83
84
|
}
|
|
84
|
-
async function getAndValidateChildWorkflow(childContract, childWorkflowName, args
|
|
85
|
+
async function getAndValidateChildWorkflow(childContract, childWorkflowName, args) {
|
|
85
86
|
const childDefinition = childContract.workflows[childWorkflowName];
|
|
86
87
|
if (!childDefinition) return _temporal_contract_boxed.Result.Error(new require_errors.ChildWorkflowNotFoundError(String(childWorkflowName), Object.keys(childContract.workflows)));
|
|
87
|
-
const inputResult
|
|
88
|
-
if (inputResult
|
|
89
|
-
const validatedInput
|
|
88
|
+
const inputResult = await childDefinition.input["~standard"].validate(args);
|
|
89
|
+
if (inputResult.issues) return _temporal_contract_boxed.Result.Error(new require_errors.ChildWorkflowError(`Child workflow "${String(childWorkflowName)}" input validation failed: ${inputResult.issues.map((i) => i.message).join("; ")}`));
|
|
90
|
+
const validatedInput = inputResult.value;
|
|
90
91
|
return _temporal_contract_boxed.Result.Ok({
|
|
91
92
|
definition: childDefinition,
|
|
92
|
-
validatedInput
|
|
93
|
+
validatedInput,
|
|
93
94
|
taskQueue: childContract.taskQueue
|
|
94
95
|
});
|
|
95
96
|
}
|
|
@@ -97,107 +98,92 @@ function declareWorkflow({ workflowName, contract, implementation, activityOptio
|
|
|
97
98
|
return {
|
|
98
99
|
workflowId: handle.workflowId,
|
|
99
100
|
result: () => {
|
|
100
|
-
return _temporal_contract_boxed.Future.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
})();
|
|
101
|
+
return _temporal_contract_boxed.Future.fromAsync(async () => {
|
|
102
|
+
try {
|
|
103
|
+
return validateChildWorkflowOutput(childDefinition, await handle.result(), childWorkflowName);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
return _temporal_contract_boxed.Result.Error(new require_errors.ChildWorkflowError(`Child workflow execution failed: ${error instanceof Error ? error.message : String(error)}`, error));
|
|
106
|
+
}
|
|
108
107
|
});
|
|
109
108
|
}
|
|
110
109
|
};
|
|
111
110
|
}
|
|
112
111
|
function createStartChildWorkflow(childContract, childWorkflowName, options) {
|
|
113
|
-
return _temporal_contract_boxed.Future.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
resolve(_temporal_contract_boxed.Result.Ok(typedHandle));
|
|
129
|
-
} catch (error) {
|
|
130
|
-
resolve(_temporal_contract_boxed.Result.Error(new require_errors.ChildWorkflowError(`Failed to start child workflow: ${error instanceof Error ? error.message : String(error)}`, error)));
|
|
131
|
-
}
|
|
132
|
-
})();
|
|
112
|
+
return _temporal_contract_boxed.Future.fromAsync(async () => {
|
|
113
|
+
const validationResult = await getAndValidateChildWorkflow(childContract, childWorkflowName, options.args);
|
|
114
|
+
if (validationResult.isError()) return _temporal_contract_boxed.Result.Error(validationResult.error);
|
|
115
|
+
const { definition: childDefinition, validatedInput, taskQueue } = validationResult.value;
|
|
116
|
+
try {
|
|
117
|
+
const { args: _args, ...temporalOptions } = options;
|
|
118
|
+
const typedHandle = createTypedChildHandle(await (0, _temporalio_workflow.startChild)(childWorkflowName, {
|
|
119
|
+
...temporalOptions,
|
|
120
|
+
taskQueue,
|
|
121
|
+
args: [validatedInput]
|
|
122
|
+
}), childDefinition, String(childWorkflowName));
|
|
123
|
+
return _temporal_contract_boxed.Result.Ok(typedHandle);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
return _temporal_contract_boxed.Result.Error(new require_errors.ChildWorkflowError(`Failed to start child workflow: ${error instanceof Error ? error.message : String(error)}`, error));
|
|
126
|
+
}
|
|
133
127
|
});
|
|
134
128
|
}
|
|
135
129
|
function createExecuteChildWorkflow(childContract, childWorkflowName, options) {
|
|
136
|
-
return _temporal_contract_boxed.Future.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
resolve(_temporal_contract_boxed.Result.Error(outputValidationResult.error));
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
resolve(_temporal_contract_boxed.Result.Ok(outputValidationResult.value));
|
|
156
|
-
} catch (error) {
|
|
157
|
-
resolve(_temporal_contract_boxed.Result.Error(new require_errors.ChildWorkflowError(`Failed to execute child workflow: ${error instanceof Error ? error.message : String(error)}`, error)));
|
|
158
|
-
}
|
|
159
|
-
})();
|
|
130
|
+
return _temporal_contract_boxed.Future.fromAsync(async () => {
|
|
131
|
+
const validationResult = await getAndValidateChildWorkflow(childContract, childWorkflowName, options.args);
|
|
132
|
+
if (validationResult.isError()) return _temporal_contract_boxed.Result.Error(validationResult.error);
|
|
133
|
+
const { definition: childDefinition, validatedInput, taskQueue } = validationResult.value;
|
|
134
|
+
try {
|
|
135
|
+
const { args: _args, ...temporalOptions } = options;
|
|
136
|
+
const outputValidationResult = await validateChildWorkflowOutput(childDefinition, await (0, _temporalio_workflow.executeChild)(childWorkflowName, {
|
|
137
|
+
...temporalOptions,
|
|
138
|
+
taskQueue,
|
|
139
|
+
args: [validatedInput]
|
|
140
|
+
}), String(childWorkflowName));
|
|
141
|
+
if (outputValidationResult.isError()) return _temporal_contract_boxed.Result.Error(outputValidationResult.error);
|
|
142
|
+
return _temporal_contract_boxed.Result.Ok(outputValidationResult.value);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
return _temporal_contract_boxed.Result.Error(new require_errors.ChildWorkflowError(`Failed to execute child workflow: ${error instanceof Error ? error.message : String(error)}`, error));
|
|
145
|
+
}
|
|
160
146
|
});
|
|
161
147
|
}
|
|
162
148
|
function createDefineSignal(signalName, handler) {
|
|
163
149
|
if (!definition.signals) throw new Error(`Signal "${String(signalName)}" cannot be defined: workflow "${String(workflowName)}" has no signals in its contract`);
|
|
164
150
|
const signalDef = definition.signals[signalName];
|
|
165
151
|
if (!signalDef) throw new Error(`Signal "${String(signalName)}" not found in workflow "${String(workflowName)}" contract`);
|
|
166
|
-
(0, _temporalio_workflow.setHandler)((0, _temporalio_workflow.defineSignal)(signalName), async (...args
|
|
167
|
-
const input
|
|
168
|
-
const inputResult
|
|
169
|
-
if (inputResult
|
|
170
|
-
await handler(inputResult
|
|
152
|
+
(0, _temporalio_workflow.setHandler)((0, _temporalio_workflow.defineSignal)(signalName), async (...args) => {
|
|
153
|
+
const input = args.length === 1 ? args[0] : args;
|
|
154
|
+
const inputResult = await signalDef.input["~standard"].validate(input);
|
|
155
|
+
if (inputResult.issues) throw new require_errors.SignalInputValidationError(signalName, inputResult.issues);
|
|
156
|
+
await handler(inputResult.value);
|
|
171
157
|
});
|
|
172
158
|
}
|
|
173
159
|
function createDefineQuery(queryName, handler) {
|
|
174
160
|
if (!definition.queries) throw new Error(`Query "${String(queryName)}" cannot be defined: workflow "${String(workflowName)}" has no queries in its contract`);
|
|
175
161
|
const queryDef = definition.queries[queryName];
|
|
176
162
|
if (!queryDef) throw new Error(`Query "${String(queryName)}" not found in workflow "${String(workflowName)}" contract`);
|
|
177
|
-
(0, _temporalio_workflow.setHandler)((0, _temporalio_workflow.defineQuery)(queryName), (...args
|
|
178
|
-
const input
|
|
179
|
-
const inputResult
|
|
180
|
-
if (inputResult
|
|
181
|
-
if (inputResult
|
|
182
|
-
const result
|
|
183
|
-
const outputResult
|
|
184
|
-
if (outputResult
|
|
185
|
-
if (outputResult
|
|
186
|
-
return outputResult
|
|
163
|
+
(0, _temporalio_workflow.setHandler)((0, _temporalio_workflow.defineQuery)(queryName), (...args) => {
|
|
164
|
+
const input = args.length === 1 ? args[0] : args;
|
|
165
|
+
const inputResult = queryDef.input["~standard"].validate(input);
|
|
166
|
+
if (inputResult instanceof Promise) throw new Error(`Query "${String(queryName)}" validation must be synchronous. Use a schema library that supports synchronous validation for queries.`);
|
|
167
|
+
if (inputResult.issues) throw new require_errors.QueryInputValidationError(queryName, inputResult.issues);
|
|
168
|
+
const result = handler(inputResult.value);
|
|
169
|
+
const outputResult = queryDef.output["~standard"].validate(result);
|
|
170
|
+
if (outputResult instanceof Promise) throw new Error(`Query "${String(queryName)}" output validation must be synchronous. Use a schema library that supports synchronous validation for queries.`);
|
|
171
|
+
if (outputResult.issues) throw new require_errors.QueryOutputValidationError(queryName, outputResult.issues);
|
|
172
|
+
return outputResult.value;
|
|
187
173
|
});
|
|
188
174
|
}
|
|
189
175
|
function createDefineUpdate(updateName, handler) {
|
|
190
176
|
if (!definition.updates) throw new Error(`Update "${String(updateName)}" cannot be defined: workflow "${String(workflowName)}" has no updates in its contract`);
|
|
191
177
|
const updateDef = definition.updates[updateName];
|
|
192
178
|
if (!updateDef) throw new Error(`Update "${String(updateName)}" not found in workflow "${String(workflowName)}" contract`);
|
|
193
|
-
(0, _temporalio_workflow.setHandler)((0, _temporalio_workflow.defineUpdate)(updateName), async (...args
|
|
194
|
-
const input
|
|
195
|
-
const inputResult
|
|
196
|
-
if (inputResult
|
|
197
|
-
const result
|
|
198
|
-
const outputResult
|
|
199
|
-
if (outputResult
|
|
200
|
-
return outputResult
|
|
179
|
+
(0, _temporalio_workflow.setHandler)((0, _temporalio_workflow.defineUpdate)(updateName), async (...args) => {
|
|
180
|
+
const input = args.length === 1 ? args[0] : args;
|
|
181
|
+
const inputResult = await updateDef.input["~standard"].validate(input);
|
|
182
|
+
if (inputResult.issues) throw new require_errors.UpdateInputValidationError(updateName, inputResult.issues);
|
|
183
|
+
const result = await handler(inputResult.value);
|
|
184
|
+
const outputResult = await updateDef.output["~standard"].validate(result);
|
|
185
|
+
if (outputResult.issues) throw new require_errors.UpdateOutputValidationError(updateName, outputResult.issues);
|
|
186
|
+
return outputResult.value;
|
|
201
187
|
});
|
|
202
188
|
}
|
|
203
189
|
const result = await implementation({
|