@temporal-contract/worker 2.0.0 → 2.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-BzG1KhEK.mjs","names":[],"sources":["../src/errors.ts","../src/internal.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { summarizeIssues } from \"@temporal-contract/contract\";\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 = summarizeIssues(issues);\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 = summarizeIssues(issues);\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 = summarizeIssues(issues);\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 = summarizeIssues(issues);\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 = summarizeIssues(issues);\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 = summarizeIssues(issues);\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 = summarizeIssues(issues);\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 = summarizeIssues(issues);\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 = summarizeIssues(issues);\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 *\n * When the child execution itself fails (Temporal's `ChildWorkflowFailure`),\n * `cause` is set to the *unwrapped* underlying failure (`ApplicationFailure`,\n * `TimeoutFailure`, `TerminatedFailure`, etc.) lifted from Temporal's wrapper —\n * mirroring the client-side `WorkflowFailedError.cause` behavior, so callers\n * can branch on the failure category in one step instead of unwrapping twice.\n */\nexport class ChildWorkflowError extends WorkerError {\n constructor(message: string, cause?: unknown) {\n super(message, cause);\n this.name = \"ChildWorkflowError\";\n }\n}\n\n/**\n * Discriminated variant of {@link ChildWorkflowError} surfaced when a child\n * workflow operation (start, execute, or wait-for-result) was cancelled —\n * either because the parent workflow itself was cancelled, the child was\n * explicitly cancelled, or its enclosing cancellation scope was. Detected via\n * `@temporalio/workflow`'s `isCancellation(...)`, which sees through nested\n * `ChildWorkflowFailure` / `CancelledFailure` chains.\n *\n * Extends {@link ChildWorkflowError} so existing `instanceof ChildWorkflowError`\n * checks still match cancellation, while `instanceof ChildWorkflowCancelledError`\n * lets call sites narrow further when they need to branch on cancellation\n * explicitly without inspecting `error.cause` against a Temporal SDK class —\n * the worker-side analogue of the client-side cause-forwarding pattern.\n */\nexport class ChildWorkflowCancelledError extends ChildWorkflowError {\n constructor(\n public readonly workflowName: string,\n cause?: unknown,\n ) {\n super(`Child workflow \"${workflowName}\" was cancelled`, cause);\n this.name = \"ChildWorkflowCancelledError\";\n }\n}\n\n/**\n * Error surfaced in the `err(...)` branch of a `ResultAsync` when a typed\n * cancellation scope is cancelled via Temporal's cancellation propagation.\n * Returned by both `context.cancellableScope` (when the workflow or an\n * ancestor scope cancels) and `context.nonCancellableScope` (when\n * cancellation is raised from inside the scope). Distinct from arbitrary\n * thrown errors so call sites can branch on cancellation explicitly.\n *\n * Non-cancellation errors thrown inside a scope surface as a sibling\n * {@link WorkflowScopeError} on the same `err(...)` channel, so callers can\n * use `instanceof` to discriminate without falling back to `try/catch`.\n */\nexport class WorkflowCancelledError extends WorkerError {\n constructor(cause?: unknown) {\n super(\"Workflow cancellation scope was cancelled\", cause);\n this.name = \"WorkflowCancelledError\";\n }\n}\n\n/**\n * Error surfaced in the `err(...)` branch of a `ResultAsync` when the\n * function passed to `cancellableScope` / `nonCancellableScope` throws a\n * non-cancellation error.\n *\n * The original error is preserved on `cause` so call sites can introspect\n * it without losing identity:\n *\n * @example\n * ```ts\n * const result = await context.cancellableScope(async () => {\n * return await context.activities.processStep(args);\n * });\n *\n * if (result.isErr()) {\n * if (result.error instanceof WorkflowCancelledError) {\n * // graceful cancellation\n * } else if (result.error instanceof WorkflowScopeError) {\n * // domain error — `result.error.cause` is the original throwable\n * }\n * }\n * ```\n *\n * Introduced so the scope helpers route every failure through neverthrow's\n * railway. Previously, non-cancellation errors were re-thrown out of the\n * helper, which became a `ResultAsync` rejection (`new ResultAsync(promise)`\n * does not catch) — they leaked as unhandled rejections rather than\n * surfacing on the typed error channel callers actually inspect.\n */\nexport class WorkflowScopeError extends WorkerError {\n constructor(cause: unknown) {\n const message =\n cause instanceof Error\n ? `Workflow cancellation scope caught a non-cancellation error: ${cause.message}`\n : \"Workflow cancellation scope caught a non-cancellation error\";\n super(message, cause);\n this.name = \"WorkflowScopeError\";\n }\n}\n","/**\n * Internal helpers shared across the worker package's entry points.\n *\n * Not part of the public API — this module is not listed in the package's\n * `exports` map, so consumers can't import from `@temporal-contract/worker/internal`.\n * In-package tests import it directly via relative path.\n */\nimport { isCancellation, makeContinueAsNewFunc, proxyActivities } from \"@temporalio/workflow\";\nimport type { ActivityOptions, ContinueAsNewOptions } from \"@temporalio/workflow\";\nimport { ChildWorkflowFailure } from \"@temporalio/common\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport {\n type ActivityDefinition,\n type ContractDefinition,\n summarizeIssues,\n} from \"@temporal-contract/contract\";\nimport {\n ChildWorkflowCancelledError,\n ChildWorkflowError,\n ChildWorkflowNotFoundError,\n WorkflowInputValidationError,\n} from \"./errors.js\";\n\n/**\n * Build the message attached to a `ChildWorkflowError` for input/output\n * validation failures. Centralized so the worker formats child-workflow\n * validation diagnostics identically across call sites. Composes the shared\n * `summarizeIssues` from `@temporal-contract/contract`.\n */\nexport function formatChildWorkflowValidationMessage(\n workflowName: string,\n direction: \"input\" | \"output\",\n issues: ReadonlyArray<StandardSchemaV1.Issue>,\n): string {\n return `Child workflow \"${workflowName}\" ${direction} validation failed: ${summarizeIssues(issues)}`;\n}\n\n// Re-export the shared `_internal_makeResultAsync` helper from the contract\n// package so worker call sites can wrap their `() => Promise<Result<T, E>>`\n// work functions identically to the client side. This closes the\n// `new ResultAsync(work())` gap — the bare constructor doesn't catch\n// rejections, so a synchronous throw or a rejected promise from `work()`\n// would otherwise escape neverthrow's railway as an unhandled rejection.\nexport { _internal_makeResultAsync as makeResultAsync } from \"@temporal-contract/contract/result-async\";\n\n/**\n * Extract the single payload from a Temporal handler's `...args` array.\n *\n * Temporal invokes handlers with whatever was passed via `args: [...]` at the\n * call site. The typed-contract layer always sends `args: [validatedInput]`,\n * so the common case is a one-element array containing the wrapped input.\n *\n * If a non-typed-contract caller passes multiple positional arguments\n * (`args: [a, b, c]`), we surface the whole array as the input — the schema\n * will then reject it unless the contract specifically modeled a tuple.\n */\nexport function extractHandlerInput(args: unknown[]): unknown {\n return args.length === 1 ? args[0] : args;\n}\n\ntype ActivityFn = (...args: unknown[]) => Promise<unknown>;\n\n/**\n * Build the raw `Record<name, fn>` proxy of activities for a workflow,\n * applying per-activity `ActivityOptions` overrides where requested.\n *\n * **Fast path (no overrides):** a single `proxyActivities(defaultOptions)`\n * call is made and returned directly. The proxy synthesizes a function for\n * any property access by name, so downstream code that looks up\n * `proxy[activityName]` works identically to before.\n *\n * **Override path:** one extra `proxyActivities(merged)` call is made *only*\n * for each activity that has an override. Activities without an entry keep\n * using the single default proxy. The result is a `Proxy` that returns the\n * override-bound function for named keys and falls back to the default proxy\n * for everything else — so the per-execution overhead scales with the number\n * of overrides, not the number of activities.\n *\n * Per-override merge is shallow: the override's properties replace the\n * default's, including the entire nested `retry` block. This matches\n * Temporal's \"one ActivityOptions per `proxyActivities` call\" semantics.\n */\nexport function buildRawActivitiesProxy(\n workflowActivities: Record<string, ActivityDefinition> | undefined,\n contractActivities: Record<string, ActivityDefinition> | undefined,\n defaultOptions: ActivityOptions,\n overrides: Partial<Record<string, ActivityOptions>> | undefined,\n): Record<string, ActivityFn> {\n const defaultProxy = proxyActivities<Record<string, ActivityFn>>(defaultOptions);\n\n // Fast path: no overrides → use the single default proxy directly.\n // (`createValidatedActivities` accesses by name, so the Proxy's get-trap\n // suffices; we don't need an enumerable map.)\n const overrideEntries = overrides\n ? Object.entries(overrides).filter(\n (entry): entry is [string, ActivityOptions] => entry[1] !== undefined,\n )\n : [];\n if (overrideEntries.length === 0) {\n return defaultProxy;\n }\n\n // Validate every override key corresponds to a declared activity.\n // Without this, a typo at runtime (or a stale options bag from a renamed\n // activity) silently builds a proxy for a non-existent activity.\n const declared = new Set<string>([\n ...Object.keys(workflowActivities ?? {}),\n ...Object.keys(contractActivities ?? {}),\n ]);\n for (const [name] of overrideEntries) {\n if (!declared.has(name)) {\n throw new Error(\n `activityOptionsByName entry \"${name}\" does not match any declared activity. Available: ${[...declared].join(\", \") || \"none\"}.`,\n );\n }\n }\n\n // Override path: build one proxy per override; combine with the default\n // proxy via a get-trap so unmatched keys still get the default options.\n const overriddenFns: Record<string, ActivityFn> = {};\n for (const [name, override] of overrideEntries) {\n const mergedOptions: ActivityOptions = { ...defaultOptions, ...override };\n const overrideProxy = proxyActivities<Record<string, ActivityFn>>(mergedOptions);\n const fn = overrideProxy[name];\n if (fn !== undefined) {\n overriddenFns[name] = fn;\n }\n }\n\n return new Proxy(overriddenFns, {\n get(target, prop) {\n if (typeof prop !== \"string\") return undefined;\n return target[prop] ?? defaultProxy[prop];\n },\n });\n}\n\n/**\n * Continue-as-new options the typed wrapper does not own. `workflowType` and\n * `taskQueue` are derived from the contract; everything else is forwarded to\n * Temporal's `makeContinueAsNewFunc`.\n */\nexport type TypedContinueAsNewOptions = Omit<ContinueAsNewOptions, \"workflowType\" | \"taskQueue\">;\n\n/**\n * Build the typed `continueAsNew` function bound to the running workflow's\n * contract. Two overloads — same-workflow and cross-contract — share one\n * implementation; the public type signature lives on `WorkflowContext` so\n * call sites are type-safe.\n *\n * Validation runs *before* Temporal's `makeContinueAsNewFunc(...)` is invoked.\n * On failure, throws a `WorkflowInputValidationError` (matching the behaviour\n * of `declareWorkflow`'s incoming-input validation), which surfaces back to\n * Temporal as a workflow failure rather than silently proceeding with an\n * invalid run.\n *\n * Temporal's `continueAsNew` never returns — it throws a `ContinueAsNew`\n * exception that the runtime intercepts. The returned function preserves\n * `Promise<never>` to encode that.\n *\n * @internal\n */\nexport function createContinueAsNew(\n currentContract: ContractDefinition,\n currentWorkflowName: string | number | symbol,\n) {\n return async function continueAsNew(\n arg1: unknown,\n arg2?: unknown,\n arg3?: unknown,\n arg4?: TypedContinueAsNewOptions,\n ): Promise<never> {\n // Cross-contract dispatch is only triggered when the call signature\n // unambiguously matches `(contract, workflowName, args, options?)`:\n //\n // 1. `arg1` is a non-null object that *looks like* a contract — it has a\n // string `taskQueue` and a non-null `workflows` object.\n // 2. `arg2` is a string — the destination workflow name.\n // 3. `arg2` resolves to a workflow definition on `arg1.workflows` with a\n // Standard Schema `input.~standard.validate` function.\n //\n // Without (2)+(3), a same-workflow input that happens to have `taskQueue`\n // and `workflows` keys (or `workflows = null`, where `typeof === \"object\"`)\n // would be silently misclassified. The full triple of structural checks\n // makes the false-positive surface vanishingly small.\n const isCrossContract = looksLikeCrossContractCall(arg1, arg2);\n\n let targetContract: ContractDefinition;\n let targetName: string;\n let rawArgs: unknown;\n let options: TypedContinueAsNewOptions | undefined;\n\n if (isCrossContract) {\n targetContract = arg1 as ContractDefinition;\n targetName = arg2 as string;\n rawArgs = arg3;\n options = arg4;\n } else {\n targetContract = currentContract;\n targetName = String(currentWorkflowName);\n rawArgs = arg1;\n options = arg2 as TypedContinueAsNewOptions | undefined;\n }\n\n const targetDef = targetContract.workflows[targetName];\n if (!targetDef) {\n throw new WorkflowInputValidationError(targetName, [\n {\n message: `continueAsNew target workflow \"${targetName}\" is not declared on the supplied contract.`,\n },\n ]);\n }\n\n const inputResult = await targetDef.input[\"~standard\"].validate(rawArgs);\n if (inputResult.issues) {\n throw new WorkflowInputValidationError(targetName, inputResult.issues);\n }\n\n // workflowType/taskQueue come from the destination contract; user\n // options are spread last so power users can override (e.g. retry,\n // memo). The public TypedContinueAsNewOptions type Omits workflowType\n // and taskQueue so this isn't a footgun on the typed call path.\n const fn = makeContinueAsNewFunc({\n workflowType: targetName,\n taskQueue: targetContract.taskQueue,\n ...options,\n });\n\n await fn(inputResult.value);\n // Unreachable — Temporal's continueAsNew throws to terminate the run.\n /* c8 ignore next */\n return undefined as never;\n };\n}\n\n/**\n * Structural check: does `(arg1, arg2)` look like the\n * `(contract, workflowName, ...)` cross-contract overload of `continueAsNew`?\n *\n * Returns `true` only when:\n * 1. `arg1` is a non-null object with a string `taskQueue` and a non-null\n * object `workflows` (handles `workflows: null`, where\n * `typeof null === \"object\"`).\n * 2. `arg2` is a string.\n *\n * Both halves matter. A same-workflow input that happens to contain\n * `taskQueue` and `workflows` keys would otherwise be misclassified — but\n * none of the same-workflow signatures (`continueAsNew(args)`,\n * `continueAsNew(args, options)`) accept a string as `arg2`, so the\n * second check makes the false-positive surface vanishingly small.\n *\n * We deliberately do *not* check that `arg1.workflows[arg2]` is a valid\n * workflow definition. If it isn't, the dispatcher falls through to the\n * `targetContract.workflows[targetName]` lookup which throws a clear\n * \"target workflow X is not declared\" error — better than silently\n * misrouting a typo back to the current workflow.\n */\nfunction looksLikeCrossContractCall(arg1: unknown, arg2: unknown): boolean {\n if (typeof arg1 !== \"object\" || arg1 === null) return false;\n if (typeof arg2 !== \"string\") return false;\n const candidate = arg1 as Record<string, unknown>;\n if (typeof candidate[\"taskQueue\"] !== \"string\") return false;\n const workflows = candidate[\"workflows\"];\n return typeof workflows === \"object\" && workflows !== null;\n}\n\n/**\n * Map a thrown error from `startChild` / `executeChild` / `handle.result()`\n * (the worker-side child-workflow API) into the discriminated union surfaced\n * by the typed worker. Mirrors the client's `classifyResultError`:\n *\n * - Cancellation (detected via `@temporalio/workflow`'s `isCancellation`,\n * which sees through nested `ChildWorkflowFailure → CancelledFailure`\n * chains) → {@link ChildWorkflowCancelledError}, with the original error\n * carried as `cause`.\n * - Temporal's `ChildWorkflowFailure` (a wrapper whose actionable failure —\n * `ApplicationFailure`, `TimeoutFailure`, `TerminatedFailure`, etc. — lives\n * on its `cause` field) → {@link ChildWorkflowError}, with that *inner*\n * cause forwarded so consumers can match `err.cause instanceof\n * ApplicationFailure` without unwrapping twice. (If the wrapper's `cause`\n * is `undefined`, the wrapper itself is forwarded so identity is\n * preserved.)\n * - Anything else → {@link ChildWorkflowError} carrying the raw thrown value\n * as `cause`.\n *\n * The `operation` discriminator drives the human-readable error message so\n * call sites don't have to format their own.\n *\n * Note: `ChildWorkflowNotFoundError` is *not* produced here — it's only\n * thrown from the input-validation path when the workflow definition is\n * missing on the contract, before any Temporal call happens.\n */\nexport function classifyChildWorkflowError(\n operation: \"startChild\" | \"executeChild\" | \"result\",\n error: unknown,\n childWorkflowName: string,\n): ChildWorkflowError | ChildWorkflowCancelledError | ChildWorkflowNotFoundError {\n // Cancellation takes priority: a cancelled child surfaces as a\n // `ChildWorkflowFailure` whose cause is a `CancelledFailure`, and we want\n // the cancellation discriminant rather than the generic wrapper.\n if (isCancellation(error)) {\n return new ChildWorkflowCancelledError(childWorkflowName, error);\n }\n\n // Temporal wraps the actionable failure (ApplicationFailure, TimeoutFailure,\n // TerminatedFailure, etc.) inside a ChildWorkflowFailure. Forward the\n // inner cause so consumers can branch on the failure category without\n // unwrapping twice. Fall back to the wrapper itself if `cause` is missing\n // so callers don't lose the error identity.\n if (error instanceof ChildWorkflowFailure) {\n const inner = error.cause ?? error;\n const innerMessage = inner instanceof Error ? inner.message : String(inner);\n return new ChildWorkflowError(\n `${describeChildWorkflowOperation(operation, childWorkflowName)}: ${innerMessage}`,\n inner,\n );\n }\n\n const message = error instanceof Error ? error.message : String(error);\n return new ChildWorkflowError(\n `${describeChildWorkflowOperation(operation, childWorkflowName)}: ${message}`,\n error,\n );\n}\n\nfunction describeChildWorkflowOperation(\n operation: \"startChild\" | \"executeChild\" | \"result\",\n childWorkflowName: string,\n): string {\n switch (operation) {\n case \"startChild\":\n return `Failed to start child workflow \"${childWorkflowName}\"`;\n case \"executeChild\":\n return `Failed to execute child workflow \"${childWorkflowName}\"`;\n case \"result\":\n return `Child workflow \"${childWorkflowName}\" execution failed`;\n }\n}\n"],"mappings":";;;;;;;;AAMA,IAAe,cAAf,cAAmC,MAAM;CACvC,YAAsB,SAAiB,OAAiB;AACtD,QAAM,SAAS,EAAE,OAAO,CAAC;AACzB,OAAK,OAAO;AAEZ,MAAI,MAAM,kBACR,OAAM,kBAAkB,MAAM,KAAK,YAAY;;;;;;AAQrD,IAAa,kCAAb,cAAqD,YAAY;CAC/D,YACE,cACA,uBAA0D,EAAE,EAC5D;EACA,MAAM,YAAY,qBAAqB,SAAS,IAAI,qBAAqB,KAAK,KAAK,GAAG;AACtF,QACE,uCAAuC,aAAa,2BAA2B,YAChF;AANe,OAAA,eAAA;AACA,OAAA,uBAAA;AAMhB,OAAK,OAAO;;;;;;AAOhB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,+BAA+B,WAAW,kBAAkB,CAAC,IAAI,WACpE,MACD;;AAGH,SAAS,+BACP,WACA,mBACQ;AACR,SAAQ,WAAR;EACE,KAAK,aACH,QAAO,mCAAmC,kBAAkB;EAC9D,KAAK,eACH,QAAO,qCAAqC,kBAAkB;EAChE,KAAK,SACH,QAAO,mBAAmB,kBAAkB"}
@@ -1,47 +1,7 @@
1
+ let _temporal_contract_contract = require("@temporal-contract/contract");
1
2
  let _temporalio_workflow = require("@temporalio/workflow");
2
- //#region src/format.ts
3
- /**
4
- * Pattern for string keys safe to render with dot notation. A "safe" key is a
5
- * JavaScript identifier (letters/digits/underscore/$, not starting with a
6
- * digit). Anything else — keys containing dots, spaces, leading digits, the
7
- * empty string, the literal string `"0"` etc. — gets bracket-quoted so the
8
- * path is unambiguous. Reserved words are accepted: we are formatting a
9
- * diagnostic, not generating runnable code.
10
- */
11
- const SAFE_IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
12
- /**
13
- * Render a Standard Schema {@link StandardSchemaV1.Issue} into a human-readable
14
- * string that includes the failing field's path.
15
- */
16
- function formatIssue(issue) {
17
- if (issue.path === void 0 || issue.path.length === 0) return issue.message;
18
- let path = "";
19
- for (let i = 0; i < issue.path.length; i++) {
20
- const segment = issue.path[i];
21
- const key = segment !== null && typeof segment === "object" && "key" in segment ? segment.key : segment;
22
- if (typeof key === "number") path += `[${key}]`;
23
- else if (typeof key === "string" && SAFE_IDENTIFIER.test(key)) path += i === 0 ? key : `.${key}`;
24
- else if (typeof key === "string") path += `[${JSON.stringify(key)}]`;
25
- else path += `[${String(key)}]`;
26
- }
27
- return `at ${path}: ${issue.message}`;
28
- }
29
- /**
30
- * Join a list of validation issues into a single message, with each issue
31
- * rendered via {@link formatIssue} so field paths surface in the error text.
32
- */
33
- function summarizeIssues(issues) {
34
- return issues.map(formatIssue).join("; ");
35
- }
36
- /**
37
- * Build the message attached to a `ChildWorkflowError` for input/output
38
- * validation failures. Centralized so the worker and any future call sites
39
- * format identically.
40
- */
41
- function formatChildWorkflowValidationMessage(workflowName, direction, issues) {
42
- return `Child workflow "${workflowName}" ${direction} validation failed: ${summarizeIssues(issues)}`;
43
- }
44
- //#endregion
3
+ let _temporalio_common = require("@temporalio/common");
4
+ require("@temporal-contract/contract/result-async");
45
5
  //#region src/errors.ts
46
6
  /**
47
7
  * Base error class for worker errors
@@ -70,7 +30,7 @@ var ActivityDefinitionNotFoundError = class extends WorkerError {
70
30
  */
71
31
  var ActivityInputValidationError = class extends WorkerError {
72
32
  constructor(activityName, issues) {
73
- const message = summarizeIssues(issues);
33
+ const message = (0, _temporal_contract_contract.summarizeIssues)(issues);
74
34
  super(`Activity "${activityName}" input validation failed: ${message}`);
75
35
  this.activityName = activityName;
76
36
  this.issues = issues;
@@ -82,7 +42,7 @@ var ActivityInputValidationError = class extends WorkerError {
82
42
  */
83
43
  var ActivityOutputValidationError = class extends WorkerError {
84
44
  constructor(activityName, issues) {
85
- const message = summarizeIssues(issues);
45
+ const message = (0, _temporal_contract_contract.summarizeIssues)(issues);
86
46
  super(`Activity "${activityName}" output validation failed: ${message}`);
87
47
  this.activityName = activityName;
88
48
  this.issues = issues;
@@ -94,7 +54,7 @@ var ActivityOutputValidationError = class extends WorkerError {
94
54
  */
95
55
  var WorkflowInputValidationError = class extends WorkerError {
96
56
  constructor(workflowName, issues) {
97
- const message = summarizeIssues(issues);
57
+ const message = (0, _temporal_contract_contract.summarizeIssues)(issues);
98
58
  super(`Workflow "${workflowName}" input validation failed: ${message}`);
99
59
  this.workflowName = workflowName;
100
60
  this.issues = issues;
@@ -106,7 +66,7 @@ var WorkflowInputValidationError = class extends WorkerError {
106
66
  */
107
67
  var WorkflowOutputValidationError = class extends WorkerError {
108
68
  constructor(workflowName, issues) {
109
- const message = summarizeIssues(issues);
69
+ const message = (0, _temporal_contract_contract.summarizeIssues)(issues);
110
70
  super(`Workflow "${workflowName}" output validation failed: ${message}`);
111
71
  this.workflowName = workflowName;
112
72
  this.issues = issues;
@@ -118,7 +78,7 @@ var WorkflowOutputValidationError = class extends WorkerError {
118
78
  */
119
79
  var SignalInputValidationError = class extends WorkerError {
120
80
  constructor(signalName, issues) {
121
- const message = summarizeIssues(issues);
81
+ const message = (0, _temporal_contract_contract.summarizeIssues)(issues);
122
82
  super(`Signal "${signalName}" input validation failed: ${message}`);
123
83
  this.signalName = signalName;
124
84
  this.issues = issues;
@@ -130,7 +90,7 @@ var SignalInputValidationError = class extends WorkerError {
130
90
  */
131
91
  var QueryInputValidationError = class extends WorkerError {
132
92
  constructor(queryName, issues) {
133
- const message = summarizeIssues(issues);
93
+ const message = (0, _temporal_contract_contract.summarizeIssues)(issues);
134
94
  super(`Query "${queryName}" input validation failed: ${message}`);
135
95
  this.queryName = queryName;
136
96
  this.issues = issues;
@@ -142,7 +102,7 @@ var QueryInputValidationError = class extends WorkerError {
142
102
  */
143
103
  var QueryOutputValidationError = class extends WorkerError {
144
104
  constructor(queryName, issues) {
145
- const message = summarizeIssues(issues);
105
+ const message = (0, _temporal_contract_contract.summarizeIssues)(issues);
146
106
  super(`Query "${queryName}" output validation failed: ${message}`);
147
107
  this.queryName = queryName;
148
108
  this.issues = issues;
@@ -154,7 +114,7 @@ var QueryOutputValidationError = class extends WorkerError {
154
114
  */
155
115
  var UpdateInputValidationError = class extends WorkerError {
156
116
  constructor(updateName, issues) {
157
- const message = summarizeIssues(issues);
117
+ const message = (0, _temporal_contract_contract.summarizeIssues)(issues);
158
118
  super(`Update "${updateName}" input validation failed: ${message}`);
159
119
  this.updateName = updateName;
160
120
  this.issues = issues;
@@ -166,7 +126,7 @@ var UpdateInputValidationError = class extends WorkerError {
166
126
  */
167
127
  var UpdateOutputValidationError = class extends WorkerError {
168
128
  constructor(updateName, issues) {
169
- const message = summarizeIssues(issues);
129
+ const message = (0, _temporal_contract_contract.summarizeIssues)(issues);
170
130
  super(`Update "${updateName}" output validation failed: ${message}`);
171
131
  this.updateName = updateName;
172
132
  this.issues = issues;
@@ -186,7 +146,13 @@ var ChildWorkflowNotFoundError = class extends WorkerError {
186
146
  }
187
147
  };
188
148
  /**
189
- * Generic error for child workflow operations
149
+ * Generic error for child workflow operations.
150
+ *
151
+ * When the child execution itself fails (Temporal's `ChildWorkflowFailure`),
152
+ * `cause` is set to the *unwrapped* underlying failure (`ApplicationFailure`,
153
+ * `TimeoutFailure`, `TerminatedFailure`, etc.) lifted from Temporal's wrapper —
154
+ * mirroring the client-side `WorkflowFailedError.cause` behavior, so callers
155
+ * can branch on the failure category in one step instead of unwrapping twice.
190
156
  */
191
157
  var ChildWorkflowError = class extends WorkerError {
192
158
  constructor(message, cause) {
@@ -195,13 +161,37 @@ var ChildWorkflowError = class extends WorkerError {
195
161
  }
196
162
  };
197
163
  /**
164
+ * Discriminated variant of {@link ChildWorkflowError} surfaced when a child
165
+ * workflow operation (start, execute, or wait-for-result) was cancelled —
166
+ * either because the parent workflow itself was cancelled, the child was
167
+ * explicitly cancelled, or its enclosing cancellation scope was. Detected via
168
+ * `@temporalio/workflow`'s `isCancellation(...)`, which sees through nested
169
+ * `ChildWorkflowFailure` / `CancelledFailure` chains.
170
+ *
171
+ * Extends {@link ChildWorkflowError} so existing `instanceof ChildWorkflowError`
172
+ * checks still match cancellation, while `instanceof ChildWorkflowCancelledError`
173
+ * lets call sites narrow further when they need to branch on cancellation
174
+ * explicitly without inspecting `error.cause` against a Temporal SDK class —
175
+ * the worker-side analogue of the client-side cause-forwarding pattern.
176
+ */
177
+ var ChildWorkflowCancelledError = class extends ChildWorkflowError {
178
+ constructor(workflowName, cause) {
179
+ super(`Child workflow "${workflowName}" was cancelled`, cause);
180
+ this.workflowName = workflowName;
181
+ this.name = "ChildWorkflowCancelledError";
182
+ }
183
+ };
184
+ /**
198
185
  * Error surfaced in the `err(...)` branch of a `ResultAsync` when a typed
199
186
  * cancellation scope is cancelled via Temporal's cancellation propagation.
200
187
  * Returned by both `context.cancellableScope` (when the workflow or an
201
188
  * ancestor scope cancels) and `context.nonCancellableScope` (when
202
189
  * cancellation is raised from inside the scope). Distinct from arbitrary
203
- * thrown errors so call sites can branch on cancellation explicitly while
204
- * still surfacing non-cancellation errors as ResultAsync rejections.
190
+ * thrown errors so call sites can branch on cancellation explicitly.
191
+ *
192
+ * Non-cancellation errors thrown inside a scope surface as a sibling
193
+ * {@link WorkflowScopeError} on the same `err(...)` channel, so callers can
194
+ * use `instanceof` to discriminate without falling back to `try/catch`.
205
195
  */
206
196
  var WorkflowCancelledError = class extends WorkerError {
207
197
  constructor(cause) {
@@ -209,6 +199,42 @@ var WorkflowCancelledError = class extends WorkerError {
209
199
  this.name = "WorkflowCancelledError";
210
200
  }
211
201
  };
202
+ /**
203
+ * Error surfaced in the `err(...)` branch of a `ResultAsync` when the
204
+ * function passed to `cancellableScope` / `nonCancellableScope` throws a
205
+ * non-cancellation error.
206
+ *
207
+ * The original error is preserved on `cause` so call sites can introspect
208
+ * it without losing identity:
209
+ *
210
+ * @example
211
+ * ```ts
212
+ * const result = await context.cancellableScope(async () => {
213
+ * return await context.activities.processStep(args);
214
+ * });
215
+ *
216
+ * if (result.isErr()) {
217
+ * if (result.error instanceof WorkflowCancelledError) {
218
+ * // graceful cancellation
219
+ * } else if (result.error instanceof WorkflowScopeError) {
220
+ * // domain error — `result.error.cause` is the original throwable
221
+ * }
222
+ * }
223
+ * ```
224
+ *
225
+ * Introduced so the scope helpers route every failure through neverthrow's
226
+ * railway. Previously, non-cancellation errors were re-thrown out of the
227
+ * helper, which became a `ResultAsync` rejection (`new ResultAsync(promise)`
228
+ * does not catch) — they leaked as unhandled rejections rather than
229
+ * surfacing on the typed error channel callers actually inspect.
230
+ */
231
+ var WorkflowScopeError = class extends WorkerError {
232
+ constructor(cause) {
233
+ const message = cause instanceof Error ? `Workflow cancellation scope caught a non-cancellation error: ${cause.message}` : "Workflow cancellation scope caught a non-cancellation error";
234
+ super(message, cause);
235
+ this.name = "WorkflowScopeError";
236
+ }
237
+ };
212
238
  //#endregion
213
239
  //#region src/internal.ts
214
240
  /**
@@ -219,6 +245,15 @@ var WorkflowCancelledError = class extends WorkerError {
219
245
  * In-package tests import it directly via relative path.
220
246
  */
221
247
  /**
248
+ * Build the message attached to a `ChildWorkflowError` for input/output
249
+ * validation failures. Centralized so the worker formats child-workflow
250
+ * validation diagnostics identically across call sites. Composes the shared
251
+ * `summarizeIssues` from `@temporal-contract/contract`.
252
+ */
253
+ function formatChildWorkflowValidationMessage(workflowName, direction, issues) {
254
+ return `Child workflow "${workflowName}" ${direction} validation failed: ${(0, _temporal_contract_contract.summarizeIssues)(issues)}`;
255
+ }
256
+ /**
222
257
  * Extract the single payload from a Temporal handler's `...args` array.
223
258
  *
224
259
  * Temporal invokes handlers with whatever was passed via `args: [...]` at the
@@ -348,6 +383,49 @@ function looksLikeCrossContractCall(arg1, arg2) {
348
383
  const workflows = candidate["workflows"];
349
384
  return typeof workflows === "object" && workflows !== null;
350
385
  }
386
+ /**
387
+ * Map a thrown error from `startChild` / `executeChild` / `handle.result()`
388
+ * (the worker-side child-workflow API) into the discriminated union surfaced
389
+ * by the typed worker. Mirrors the client's `classifyResultError`:
390
+ *
391
+ * - Cancellation (detected via `@temporalio/workflow`'s `isCancellation`,
392
+ * which sees through nested `ChildWorkflowFailure → CancelledFailure`
393
+ * chains) → {@link ChildWorkflowCancelledError}, with the original error
394
+ * carried as `cause`.
395
+ * - Temporal's `ChildWorkflowFailure` (a wrapper whose actionable failure —
396
+ * `ApplicationFailure`, `TimeoutFailure`, `TerminatedFailure`, etc. — lives
397
+ * on its `cause` field) → {@link ChildWorkflowError}, with that *inner*
398
+ * cause forwarded so consumers can match `err.cause instanceof
399
+ * ApplicationFailure` without unwrapping twice. (If the wrapper's `cause`
400
+ * is `undefined`, the wrapper itself is forwarded so identity is
401
+ * preserved.)
402
+ * - Anything else → {@link ChildWorkflowError} carrying the raw thrown value
403
+ * as `cause`.
404
+ *
405
+ * The `operation` discriminator drives the human-readable error message so
406
+ * call sites don't have to format their own.
407
+ *
408
+ * Note: `ChildWorkflowNotFoundError` is *not* produced here — it's only
409
+ * thrown from the input-validation path when the workflow definition is
410
+ * missing on the contract, before any Temporal call happens.
411
+ */
412
+ function classifyChildWorkflowError(operation, error, childWorkflowName) {
413
+ if ((0, _temporalio_workflow.isCancellation)(error)) return new ChildWorkflowCancelledError(childWorkflowName, error);
414
+ if (error instanceof _temporalio_common.ChildWorkflowFailure) {
415
+ const inner = error.cause ?? error;
416
+ const innerMessage = inner instanceof Error ? inner.message : String(inner);
417
+ return new ChildWorkflowError(`${describeChildWorkflowOperation(operation, childWorkflowName)}: ${innerMessage}`, inner);
418
+ }
419
+ const message = error instanceof Error ? error.message : String(error);
420
+ return new ChildWorkflowError(`${describeChildWorkflowOperation(operation, childWorkflowName)}: ${message}`, error);
421
+ }
422
+ function describeChildWorkflowOperation(operation, childWorkflowName) {
423
+ switch (operation) {
424
+ case "startChild": return `Failed to start child workflow "${childWorkflowName}"`;
425
+ case "executeChild": return `Failed to execute child workflow "${childWorkflowName}"`;
426
+ case "result": return `Child workflow "${childWorkflowName}" execution failed`;
427
+ }
428
+ }
351
429
  //#endregion
352
430
  Object.defineProperty(exports, "ActivityDefinitionNotFoundError", {
353
431
  enumerable: true,
@@ -367,6 +445,12 @@ Object.defineProperty(exports, "ActivityOutputValidationError", {
367
445
  return ActivityOutputValidationError;
368
446
  }
369
447
  });
448
+ Object.defineProperty(exports, "ChildWorkflowCancelledError", {
449
+ enumerable: true,
450
+ get: function() {
451
+ return ChildWorkflowCancelledError;
452
+ }
453
+ });
370
454
  Object.defineProperty(exports, "ChildWorkflowError", {
371
455
  enumerable: true,
372
456
  get: function() {
@@ -427,12 +511,24 @@ Object.defineProperty(exports, "WorkflowOutputValidationError", {
427
511
  return WorkflowOutputValidationError;
428
512
  }
429
513
  });
514
+ Object.defineProperty(exports, "WorkflowScopeError", {
515
+ enumerable: true,
516
+ get: function() {
517
+ return WorkflowScopeError;
518
+ }
519
+ });
430
520
  Object.defineProperty(exports, "buildRawActivitiesProxy", {
431
521
  enumerable: true,
432
522
  get: function() {
433
523
  return buildRawActivitiesProxy;
434
524
  }
435
525
  });
526
+ Object.defineProperty(exports, "classifyChildWorkflowError", {
527
+ enumerable: true,
528
+ get: function() {
529
+ return classifyChildWorkflowError;
530
+ }
531
+ });
436
532
  Object.defineProperty(exports, "createContinueAsNew", {
437
533
  enumerable: true,
438
534
  get: function() {
package/dist/worker.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ActivitiesHandler } from "./activity.mjs";
2
- import { Worker, WorkerOptions } from "@temporalio/worker";
3
2
  import { ContractDefinition } from "@temporal-contract/contract";
3
+ import { Worker, WorkerOptions } from "@temporalio/worker";
4
4
 
5
5
  //#region src/worker.d.ts
6
6
  /**