From 42e18f2ce7ce8a185b5c9bc5c19b463874cdbd1a Mon Sep 17 00:00:00 2001 From: Benoit TRAVERS Date: Fri, 24 Jul 2026 09:11:02 +0200 Subject: [PATCH] chore: adopt @btravstack config 0.2.x (tsconfig, oxlint, lefthook, oxfmt) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - @btravstack/tsconfig 0.2.0: verbatimModuleSyntax + moduleDetection:force, drop types:["node"]. oxlint --fix added `type` specifiers to type-only imports so the non-eliding verbatimModuleSyntax build resolves. - @btravstack/oxlint 0.2.1: consistent-type-imports (inline, disallowTypeAnnotations off — idiomatic `vi.importActual` mocks stay) - @btravstack/lefthook: lefthook.yml extends the shared base + local excludes - .oxfmtrc.json: organizeImports -> sortImports (was silently off) --- .changeset/adopt-lefthook-oxfmt.md | 5 ++ .oxfmtrc.json | 5 +- docs/.vitepress/theme/index.ts | 1 + docs/scripts/copy-docs.ts | 1 - .../order-processing-client/src/client.ts | 7 +-- .../order-processing-contract/src/contract.ts | 1 + .../src/application/activities.ts | 5 +- .../src/application/worker.ts | 10 ++-- .../src/application/workflows.ts | 2 +- .../src/dependencies.ts | 11 ++-- .../src/domain/entities/order.schema.ts | 10 ++-- .../usecases/create-shipment.usecase.ts | 2 +- .../usecases/process-payment.usecase.ts | 2 +- .../usecases/reserve-inventory.usecase.ts | 2 +- .../adapters/inventory.adapter.ts | 2 +- .../adapters/payment.adapter.ts | 2 +- .../adapters/shipping.adapter.ts | 2 +- .../src/integration.spec.ts | 18 ++++--- knip.json | 1 + lefthook.yml | 20 +++---- package.json | 1 + packages/client/src/__tests__/client.spec.ts | 12 +++-- packages/client/src/client.spec.ts | 29 +++++----- packages/client/src/client.ts | 41 +++++++------- packages/client/src/errors.spec.ts | 21 ++++---- packages/client/src/errors.ts | 2 +- packages/client/src/interceptors.ts | 3 +- packages/client/src/internal.ts | 12 ++--- packages/client/src/schedule.spec.ts | 7 +-- packages/client/src/schedule.ts | 5 +- packages/client/src/types-inference.spec.ts | 3 +- packages/client/src/types.ts | 2 +- packages/contract/src/builder.spec.ts | 3 +- packages/contract/src/builder.ts | 3 +- packages/contract/src/errors.spec.ts | 1 + packages/contract/src/errors.ts | 1 + packages/contract/src/format.spec.ts | 3 +- packages/contract/src/helpers.spec.ts | 3 +- packages/contract/src/result-async.spec.ts | 3 +- packages/contract/src/types-inference.spec.ts | 1 + packages/contract/src/types.spec.ts | 1 + packages/testing/src/extension.spec.ts | 1 + packages/testing/src/global-setup.spec.ts | 1 + .../src/__tests__/inprocess.contract.ts | 2 +- .../src/__tests__/inprocess.workflows.ts | 1 + .../worker/src/__tests__/test.workflows.ts | 5 +- .../__tests__/time-skipping.inprocess.spec.ts | 12 +++-- packages/worker/src/__tests__/worker.spec.ts | 14 ++--- packages/worker/src/activities-proxy.spec.ts | 9 ++-- packages/worker/src/activities-proxy.ts | 17 +++--- .../src/activity-contract-errors.spec.ts | 9 ++-- packages/worker/src/activity.spec.ts | 7 +-- packages/worker/src/activity.ts | 13 ++--- packages/worker/src/cancellation.spec.ts | 2 +- packages/worker/src/cancellation.ts | 1 + packages/worker/src/child-workflow.spec.ts | 21 ++++---- packages/worker/src/child-workflow.ts | 7 +-- packages/worker/src/continue-as-new.spec.ts | 5 +- packages/worker/src/contract-errors.ts | 5 +- packages/worker/src/errors.spec.ts | 5 +- packages/worker/src/handlers.spec.ts | 2 +- packages/worker/src/handlers.ts | 1 + packages/worker/src/internal.ts | 15 +++--- packages/worker/src/types-inference.spec.ts | 3 +- packages/worker/src/worker.spec.ts | 5 +- packages/worker/src/worker.ts | 8 +-- packages/worker/src/workflow-errors.spec.ts | 4 +- packages/worker/src/workflow-options.spec.ts | 7 +-- packages/worker/src/workflow-proxy.spec.ts | 6 +-- packages/worker/src/workflow.spec.ts | 3 +- packages/worker/src/workflow.ts | 47 ++++++++-------- pnpm-lock.yaml | 54 ++++++++++++------- pnpm-workspace.yaml | 6 ++- 73 files changed, 316 insertions(+), 248 deletions(-) create mode 100644 .changeset/adopt-lefthook-oxfmt.md diff --git a/.changeset/adopt-lefthook-oxfmt.md b/.changeset/adopt-lefthook-oxfmt.md new file mode 100644 index 00000000..ed89ad2f --- /dev/null +++ b/.changeset/adopt-lefthook-oxfmt.md @@ -0,0 +1,5 @@ +--- +"@temporal-contract/contract": patch +--- + +Enable oxfmt import sorting (the `.oxfmtrc.json` used a key oxfmt 0.58 dropped, so sorting was silently off) and adopt the shared `@btravstack/lefthook` hooks preset. diff --git a/.oxfmtrc.json b/.oxfmtrc.json index 8dffb741..7b59bd4d 100644 --- a/.oxfmtrc.json +++ b/.oxfmtrc.json @@ -1,8 +1,5 @@ { "$schema": "./node_modules/oxfmt/configuration_schema.json", "ignorePatterns": ["pnpm-lock.yaml"], - "organizeImports": { - "sortImports": true, - "separateGroups": true - } + "sortImports": true } diff --git a/docs/.vitepress/theme/index.ts b/docs/.vitepress/theme/index.ts index eecbcc8f..d0c50ff3 100644 --- a/docs/.vitepress/theme/index.ts +++ b/docs/.vitepress/theme/index.ts @@ -1,4 +1,5 @@ import Theme from "@btravstack/theme"; + import "./custom.css"; export default Theme; diff --git a/docs/scripts/copy-docs.ts b/docs/scripts/copy-docs.ts index b60987e1..bc9ae3b2 100644 --- a/docs/scripts/copy-docs.ts +++ b/docs/scripts/copy-docs.ts @@ -4,7 +4,6 @@ import "@temporal-contract/client"; import "@temporal-contract/contract"; import "@temporal-contract/testing/global-setup"; import "@temporal-contract/worker/activity"; - import { cp, mkdir, rm } from "node:fs/promises"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; diff --git a/examples/order-processing-client/src/client.ts b/examples/order-processing-client/src/client.ts index 3bcc04f8..be7d8d2b 100644 --- a/examples/order-processing-client/src/client.ts +++ b/examples/order-processing-client/src/client.ts @@ -1,11 +1,12 @@ -import { Client, Connection } from "@temporalio/client"; import { TypedClient } from "@temporal-contract/client"; import { orderProcessingContract, - OrderSchema, + type OrderSchema, } from "@temporal-contract/sample-order-processing-contract"; -import type { z } from "zod"; +import { Client, Connection } from "@temporalio/client"; import { matchTags } from "unthrown"; +import type { z } from "zod"; + import { logger } from "./logger.js"; type Order = z.infer; diff --git a/examples/order-processing-contract/src/contract.ts b/examples/order-processing-contract/src/contract.ts index b1edb726..fa8dc3ee 100644 --- a/examples/order-processing-contract/src/contract.ts +++ b/examples/order-processing-contract/src/contract.ts @@ -1,5 +1,6 @@ import { defineContract } from "@temporal-contract/contract"; import { z } from "zod"; + import { OrderSchema, OrderItemSchema, diff --git a/examples/order-processing-worker/src/application/activities.ts b/examples/order-processing-worker/src/application/activities.ts index d662e42a..8a2a200a 100644 --- a/examples/order-processing-worker/src/application/activities.ts +++ b/examples/order-processing-worker/src/application/activities.ts @@ -1,6 +1,7 @@ -import { fromPromise } from "unthrown"; -import { declareActivitiesHandler, qualify } from "@temporal-contract/worker/activity"; import { orderProcessingContract } from "@temporal-contract/sample-order-processing-contract"; +import { declareActivitiesHandler, qualify } from "@temporal-contract/worker/activity"; +import { fromPromise } from "unthrown"; + import { sendNotificationUseCase, processPaymentUseCase, diff --git a/examples/order-processing-worker/src/application/worker.ts b/examples/order-processing-worker/src/application/worker.ts index d30b8e36..d9454775 100644 --- a/examples/order-processing-worker/src/application/worker.ts +++ b/examples/order-processing-worker/src/application/worker.ts @@ -1,10 +1,12 @@ -import { NativeConnection } from "@temporalio/worker"; -import { createWorker } from "@temporal-contract/worker/worker"; -import { orderProcessingContract } from "@temporal-contract/sample-order-processing-contract"; import { extname } from "node:path"; import { fileURLToPath } from "node:url"; -import { activities } from "./activities.js"; + +import { orderProcessingContract } from "@temporal-contract/sample-order-processing-contract"; +import { createWorker } from "@temporal-contract/worker/worker"; +import { NativeConnection } from "@temporalio/worker"; + import { logger } from "../logger.js"; +import { activities } from "./activities.js"; function workflowPath(filename: string): string { return fileURLToPath(new URL(`./${filename}${extname(import.meta.url)}`, import.meta.url)); diff --git a/examples/order-processing-worker/src/application/workflows.ts b/examples/order-processing-worker/src/application/workflows.ts index 4a445913..76d27e4d 100644 --- a/examples/order-processing-worker/src/application/workflows.ts +++ b/examples/order-processing-worker/src/application/workflows.ts @@ -1,6 +1,6 @@ +import { orderProcessingContract } from "@temporal-contract/sample-order-processing-contract"; import { declareWorkflow } from "@temporal-contract/worker/workflow"; import { isCancellation, log } from "@temporalio/workflow"; -import { orderProcessingContract } from "@temporal-contract/sample-order-processing-contract"; /** * Process Order Workflow Implementation diff --git a/examples/order-processing-worker/src/dependencies.ts b/examples/order-processing-worker/src/dependencies.ts index d5da2af4..babbff55 100644 --- a/examples/order-processing-worker/src/dependencies.ts +++ b/examples/order-processing-worker/src/dependencies.ts @@ -3,19 +3,18 @@ * Centralizes the instantiation and wiring of all domain and infrastructure components */ +import { CreateShipmentUseCase } from "./domain/usecases/create-shipment.usecase.js"; // Domain import { ProcessPaymentUseCase } from "./domain/usecases/process-payment.usecase.js"; -import { ReserveInventoryUseCase } from "./domain/usecases/reserve-inventory.usecase.js"; +import { RefundPaymentUseCase } from "./domain/usecases/refund-payment.usecase.js"; import { ReleaseInventoryUseCase } from "./domain/usecases/release-inventory.usecase.js"; -import { CreateShipmentUseCase } from "./domain/usecases/create-shipment.usecase.js"; +import { ReserveInventoryUseCase } from "./domain/usecases/reserve-inventory.usecase.js"; import { SendNotificationUseCase } from "./domain/usecases/send-notification.usecase.js"; -import { RefundPaymentUseCase } from "./domain/usecases/refund-payment.usecase.js"; - +import { MockInventoryAdapter } from "./infrastructure/adapters/inventory.adapter.js"; +import { ConsoleNotificationAdapter } from "./infrastructure/adapters/notification.adapter.js"; // Infrastructure import { MockPaymentAdapter } from "./infrastructure/adapters/payment.adapter.js"; -import { MockInventoryAdapter } from "./infrastructure/adapters/inventory.adapter.js"; import { MockShippingAdapter } from "./infrastructure/adapters/shipping.adapter.js"; -import { ConsoleNotificationAdapter } from "./infrastructure/adapters/notification.adapter.js"; // ============================================================================ // Adapters diff --git a/examples/order-processing-worker/src/domain/entities/order.schema.ts b/examples/order-processing-worker/src/domain/entities/order.schema.ts index 1240ff86..97c4cb60 100644 --- a/examples/order-processing-worker/src/domain/entities/order.schema.ts +++ b/examples/order-processing-worker/src/domain/entities/order.schema.ts @@ -5,13 +5,13 @@ * The schemas themselves are defined in the contract package. */ -import type { z } from "zod"; import { - OrderItemSchema, - PaymentResultSchema, - InventoryReservationSchema, - ShippingResultSchema, + type OrderItemSchema, + type PaymentResultSchema, + type InventoryReservationSchema, + type ShippingResultSchema, } from "@temporal-contract/sample-order-processing-contract"; +import type { z } from "zod"; export type OrderItem = z.infer; export type PaymentResult = z.infer; diff --git a/examples/order-processing-worker/src/domain/usecases/create-shipment.usecase.ts b/examples/order-processing-worker/src/domain/usecases/create-shipment.usecase.ts index 77a13c7e..a5933b5a 100644 --- a/examples/order-processing-worker/src/domain/usecases/create-shipment.usecase.ts +++ b/examples/order-processing-worker/src/domain/usecases/create-shipment.usecase.ts @@ -1,5 +1,5 @@ -import type { ShippingPort } from "../ports/shipping.port.js"; import type { ShippingResult } from "../entities/order.schema.js"; +import type { ShippingPort } from "../ports/shipping.port.js"; /** * Create Shipment Use Case diff --git a/examples/order-processing-worker/src/domain/usecases/process-payment.usecase.ts b/examples/order-processing-worker/src/domain/usecases/process-payment.usecase.ts index 67ea3f11..6840c881 100644 --- a/examples/order-processing-worker/src/domain/usecases/process-payment.usecase.ts +++ b/examples/order-processing-worker/src/domain/usecases/process-payment.usecase.ts @@ -1,5 +1,5 @@ -import type { PaymentPort } from "../ports/payment.port.js"; import type { PaymentResult } from "../entities/order.schema.js"; +import type { PaymentPort } from "../ports/payment.port.js"; /** * Process Payment Use Case diff --git a/examples/order-processing-worker/src/domain/usecases/reserve-inventory.usecase.ts b/examples/order-processing-worker/src/domain/usecases/reserve-inventory.usecase.ts index 9e8d1b24..3a9cf28d 100644 --- a/examples/order-processing-worker/src/domain/usecases/reserve-inventory.usecase.ts +++ b/examples/order-processing-worker/src/domain/usecases/reserve-inventory.usecase.ts @@ -1,5 +1,5 @@ -import type { InventoryPort } from "../ports/inventory.port.js"; import type { InventoryReservation, OrderItem } from "../entities/order.schema.js"; +import type { InventoryPort } from "../ports/inventory.port.js"; /** * Reserve Inventory Use Case diff --git a/examples/order-processing-worker/src/infrastructure/adapters/inventory.adapter.ts b/examples/order-processing-worker/src/infrastructure/adapters/inventory.adapter.ts index bcfb8f60..56433182 100644 --- a/examples/order-processing-worker/src/infrastructure/adapters/inventory.adapter.ts +++ b/examples/order-processing-worker/src/infrastructure/adapters/inventory.adapter.ts @@ -1,5 +1,5 @@ -import type { InventoryPort } from "../../domain/ports/inventory.port.js"; import type { InventoryReservation, OrderItem } from "../../domain/entities/order.schema.js"; +import type { InventoryPort } from "../../domain/ports/inventory.port.js"; import { logger } from "../../logger.js"; /** diff --git a/examples/order-processing-worker/src/infrastructure/adapters/payment.adapter.ts b/examples/order-processing-worker/src/infrastructure/adapters/payment.adapter.ts index d7254b86..0cf44d16 100644 --- a/examples/order-processing-worker/src/infrastructure/adapters/payment.adapter.ts +++ b/examples/order-processing-worker/src/infrastructure/adapters/payment.adapter.ts @@ -1,5 +1,5 @@ -import type { PaymentPort } from "../../domain/ports/payment.port.js"; import type { PaymentResult } from "../../domain/entities/order.schema.js"; +import type { PaymentPort } from "../../domain/ports/payment.port.js"; import { logger } from "../../logger.js"; /** diff --git a/examples/order-processing-worker/src/infrastructure/adapters/shipping.adapter.ts b/examples/order-processing-worker/src/infrastructure/adapters/shipping.adapter.ts index 3a91e4d5..0e40162a 100644 --- a/examples/order-processing-worker/src/infrastructure/adapters/shipping.adapter.ts +++ b/examples/order-processing-worker/src/infrastructure/adapters/shipping.adapter.ts @@ -1,5 +1,5 @@ -import type { ShippingPort } from "../../domain/ports/shipping.port.js"; import type { ShippingResult } from "../../domain/entities/order.schema.js"; +import type { ShippingPort } from "../../domain/ports/shipping.port.js"; import { logger } from "../../logger.js"; /** diff --git a/examples/order-processing-worker/src/integration.spec.ts b/examples/order-processing-worker/src/integration.spec.ts index 53140ae6..fa7ead55 100644 --- a/examples/order-processing-worker/src/integration.spec.ts +++ b/examples/order-processing-worker/src/integration.spec.ts @@ -1,17 +1,19 @@ -import { describe, expect, vi, beforeEach } from "vitest"; -import { Worker } from "@temporalio/worker"; +import { extname } from "node:path"; +import { fileURLToPath } from "node:url"; + import { TypedClient, WorkflowValidationError } from "@temporal-contract/client"; -import { it as baseIt } from "@temporal-contract/testing/extension"; import { orderProcessingContract, - OrderSchema, + type OrderSchema, } from "@temporal-contract/sample-order-processing-contract"; -import { activities } from "./application/activities.js"; -import { extname } from "node:path"; -import { fileURLToPath } from "node:url"; +import { it as baseIt } from "@temporal-contract/testing/extension"; +import { Client } from "@temporalio/client"; +import { Worker } from "@temporalio/worker"; +import { describe, expect, vi, beforeEach } from "vitest"; import type { z } from "zod"; + +import { activities } from "./application/activities.js"; import { paymentAdapter } from "./dependencies.js"; -import { Client } from "@temporalio/client"; type Order = z.infer; diff --git a/knip.json b/knip.json index ee97244c..754effa9 100644 --- a/knip.json +++ b/knip.json @@ -4,6 +4,7 @@ "ignoreDependencies": [ "@btravstack/typedoc", "@btravstack/oxlint", + "@btravstack/lefthook", "typedoc-plugin-markdown", "@changesets/config" ], diff --git a/lefthook.yml b/lefthook.yml index 51a704af..cd77974b 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -1,16 +1,10 @@ +# Shared hooks come from @btravstack/lefthook (format + lint + commit-msg). +extends: + - node_modules/@btravstack/lefthook/lefthook.yml + +# Repo-specific excludes (the shared base sets none so they merge in here). pre-commit: - parallel: true commands: format: - glob: "**/*.{ts,tsx,js,jsx,json,yaml,yml,md}" - exclude: "pnpm-lock.yaml" - run: pnpm oxfmt {staged_files} - stage_fixed: true - lint: - glob: "**/*.{ts,tsx,js,jsx}" - run: pnpm oxlint {staged_files} - -commit-msg: - commands: - commitlint: - run: pnpm exec commitlint --edit {1} + exclude: + - "pnpm-lock.yaml" diff --git a/package.json b/package.json index 2bdab7a8..2d8a13d1 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ }, "devDependencies": { "@btravstack/commitlint": "catalog:", + "@btravstack/lefthook": "catalog:", "@btravstack/oxlint": "catalog:", "@changesets/cli": "catalog:", "@commitlint/cli": "catalog:", diff --git a/packages/client/src/__tests__/client.spec.ts b/packages/client/src/__tests__/client.spec.ts index d72fef63..f3db97ac 100644 --- a/packages/client/src/__tests__/client.spec.ts +++ b/packages/client/src/__tests__/client.spec.ts @@ -1,12 +1,14 @@ -import { describe, expect, vi, beforeEach } from "vitest"; +import { extname } from "node:path"; +import { fileURLToPath } from "node:url"; + +import { it as baseIt } from "@temporal-contract/testing/extension"; +import { Client } from "@temporalio/client"; import { Worker } from "@temporalio/worker"; +import { describe, expect, vi, beforeEach } from "vitest"; + import { TypedClient } from "../client.js"; import { WorkflowValidationError } from "../errors.js"; -import { it as baseIt } from "@temporal-contract/testing/extension"; -import { extname } from "node:path"; -import { fileURLToPath } from "node:url"; import { testContract } from "./test.contract.js"; -import { Client } from "@temporalio/client"; // ============================================================================ // Test Setup diff --git a/packages/client/src/client.spec.ts b/packages/client/src/client.spec.ts index 5fd8a792..d0887acf 100644 --- a/packages/client/src/client.spec.ts +++ b/packages/client/src/client.spec.ts @@ -1,6 +1,20 @@ +import { defineContract, defineSearchAttribute, defineWorkflow } from "@temporal-contract/contract"; +import { ContractError } from "@temporal-contract/contract/errors"; +import { + type Client, + WorkflowExecutionAlreadyStartedError, + WorkflowFailedError as TemporalWorkflowFailedError, +} from "@temporalio/client"; +import { + ApplicationFailure, + defineSearchAttributeKey, + TypedSearchAttributes, + WorkflowNotFoundError as TemporalWorkflowNotFoundError, +} from "@temporalio/common"; +import { Err } from "unthrown"; import { describe, it, expect, vi, beforeEach } from "vitest"; import { z } from "zod"; -import { defineContract, defineSearchAttribute, defineWorkflow } from "@temporal-contract/contract"; + import { readTypedSearchAttributes, TypedClient } from "./client.js"; import { QueryValidationError, @@ -13,19 +27,6 @@ import { WorkflowNotFoundError, WorkflowValidationError, } from "./errors.js"; -import { - Client, - WorkflowExecutionAlreadyStartedError, - WorkflowFailedError as TemporalWorkflowFailedError, -} from "@temporalio/client"; -import { - ApplicationFailure, - defineSearchAttributeKey, - TypedSearchAttributes, - WorkflowNotFoundError as TemporalWorkflowNotFoundError, -} from "@temporalio/common"; -import { ContractError } from "@temporal-contract/contract/errors"; -import { Err } from "unthrown"; import type { ClientInterceptor } from "./interceptors.js"; // Create mock workflow object diff --git a/packages/client/src/client.ts b/packages/client/src/client.ts index 57dcf248..f0d230b6 100644 --- a/packages/client/src/client.ts +++ b/packages/client/src/client.ts @@ -1,6 +1,3 @@ -import { Client, WorkflowHandle } from "@temporalio/client"; -import type { WorkflowSignalWithStartOptions, WorkflowStartOptions } from "@temporalio/client"; -import { defineSearchAttributeKey, TypedSearchAttributes } from "@temporalio/common"; import type { StandardSchemaV1 } from "@standard-schema/spec"; import type { AnyWorkflowDefinition, @@ -12,20 +9,14 @@ import type { SignalNamesOf, } from "@temporal-contract/contract"; import { TechnicalError, type ContractErrorUnion } from "@temporal-contract/contract/errors"; -import { - chainInterceptors, - type ClientCallError, - type ClientInterceptor, - type ClientInterceptorArgs, -} from "./interceptors.js"; -import type { - ClientInferInput, - ClientInferOutput, - ClientInferWorkflowQueries, - ClientInferWorkflowSignals, - ClientInferWorkflowUpdates, -} from "./types.js"; +import { type Client, type WorkflowHandle } from "@temporalio/client"; +import type { WorkflowSignalWithStartOptions, WorkflowStartOptions } from "@temporalio/client"; +import { WorkflowExecutionAlreadyStartedError } from "@temporalio/client"; +import { WorkflowFailedError as TemporalWorkflowFailedError } from "@temporalio/client"; +import { defineSearchAttributeKey, type TypedSearchAttributes } from "@temporalio/common"; +import { WorkflowNotFoundError as TemporalWorkflowNotFoundError } from "@temporalio/common"; import { type AsyncResult, type Result, Ok, Err, fromPromise } from "unthrown"; + import { type TemporalFailure, WorkflowAlreadyStartedError, @@ -38,7 +29,12 @@ import { UpdateValidationError, RuntimeClientError, } from "./errors.js"; -import { TypedScheduleClient } from "./schedule.js"; +import { + chainInterceptors, + type ClientCallError, + type ClientInterceptor, + type ClientInterceptorArgs, +} from "./interceptors.js"; import { assertNoDefect, classifyHandleError, @@ -48,9 +44,14 @@ import { rehydrateWorkflowContractError, toTypedSearchAttributes, } from "./internal.js"; -import { WorkflowExecutionAlreadyStartedError } from "@temporalio/client"; -import { WorkflowFailedError as TemporalWorkflowFailedError } from "@temporalio/client"; -import { WorkflowNotFoundError as TemporalWorkflowNotFoundError } from "@temporalio/common"; +import { TypedScheduleClient } from "./schedule.js"; +import type { + ClientInferInput, + ClientInferOutput, + ClientInferWorkflowQueries, + ClientInferWorkflowSignals, + ClientInferWorkflowUpdates, +} from "./types.js"; /** * Typed `searchAttributes` map for a workflow, derived from the workflow's diff --git a/packages/client/src/errors.spec.ts b/packages/client/src/errors.spec.ts index 288ba950..d7afe654 100644 --- a/packages/client/src/errors.spec.ts +++ b/packages/client/src/errors.spec.ts @@ -1,12 +1,3 @@ -/** - * Coverage for the path-aware issue formatting in client validation errors, - * plus the `WorkflowFailedError.cause` typing contract. - * - * Mirrors the worker-side test (#141 closes both surfaces); the helpers are - * intentionally duplicated across packages so each entry point has its own - * formatting source of truth. - */ -import { describe, expect, expectTypeOf, it } from "vitest"; import type { StandardSchemaV1 } from "@standard-schema/spec"; import type { ActivityFailure, @@ -17,12 +8,22 @@ import type { TerminatedFailure, TimeoutFailure, } from "@temporalio/common"; +/** + * Coverage for the path-aware issue formatting in client validation errors, + * plus the `WorkflowFailedError.cause` typing contract. + * + * Mirrors the worker-side test (#141 closes both surfaces); the helpers are + * intentionally duplicated across packages so each entry point has its own + * formatting source of truth. + */ +import { describe, expect, expectTypeOf, it } from "vitest"; + import { QueryValidationError, SignalValidationError, type TemporalFailure, UpdateValidationError, - WorkflowFailedError, + type WorkflowFailedError, WorkflowValidationError, } from "./errors.js"; diff --git a/packages/client/src/errors.ts b/packages/client/src/errors.ts index 80706dda..5d9f45f0 100644 --- a/packages/client/src/errors.ts +++ b/packages/client/src/errors.ts @@ -1,6 +1,5 @@ import type { StandardSchemaV1 } from "@standard-schema/spec"; import { summarizeIssues } from "@temporal-contract/contract"; -import { TaggedError } from "unthrown"; import type { ActivityFailure, ApplicationFailure, @@ -10,6 +9,7 @@ import type { TerminatedFailure, TimeoutFailure, } from "@temporalio/common"; +import { TaggedError } from "unthrown"; /** * Union of the actionable Temporal failure types that can surface as the diff --git a/packages/client/src/interceptors.ts b/packages/client/src/interceptors.ts index c6bbef30..514ece07 100644 --- a/packages/client/src/interceptors.ts +++ b/packages/client/src/interceptors.ts @@ -1,3 +1,4 @@ +import type { AnyContractError } from "@temporal-contract/contract/errors"; /** * Client-side interceptors — the trace-propagation / retry / observability * seam of the typed client, mirroring amqp-contract's @@ -16,7 +17,7 @@ * - **short-circuit** — return your own `AsyncResult` without calling `next`. */ import type { AsyncResult } from "unthrown"; -import type { AnyContractError } from "@temporal-contract/contract/errors"; + import type { QueryValidationError, RuntimeClientError, diff --git a/packages/client/src/internal.ts b/packages/client/src/internal.ts index c8543df7..ff12c957 100644 --- a/packages/client/src/internal.ts +++ b/packages/client/src/internal.ts @@ -1,3 +1,9 @@ +import type { AnyWorkflowDefinition, SearchAttributeDefinition } from "@temporal-contract/contract"; +import { + _internal_rehydrateContractError, + type AnyContractError, +} from "@temporal-contract/contract/errors"; +import { _internal_makeAsyncResult } from "@temporal-contract/contract/result-async"; /** * Internal helpers shared across the client package's modules. * @@ -14,12 +20,6 @@ import { TypedSearchAttributes, WorkflowNotFoundError as TemporalWorkflowNotFoundError, } from "@temporalio/common"; -import type { AnyWorkflowDefinition, SearchAttributeDefinition } from "@temporal-contract/contract"; -import { - _internal_rehydrateContractError, - type AnyContractError, -} from "@temporal-contract/contract/errors"; -import { _internal_makeAsyncResult } from "@temporal-contract/contract/result-async"; import { Ok, Err, type AsyncResult, type Result } from "unthrown"; // `assertNoDefect` narrows an internally-built `Result` (known to carry only diff --git a/packages/client/src/schedule.spec.ts b/packages/client/src/schedule.spec.ts index ad1be903..2dd59bc3 100644 --- a/packages/client/src/schedule.spec.ts +++ b/packages/client/src/schedule.spec.ts @@ -1,3 +1,6 @@ +import { defineContract, defineSearchAttribute, defineWorkflow } from "@temporal-contract/contract"; +import type { Client } from "@temporalio/client"; +import { TypedSearchAttributes } from "@temporalio/common"; /** * Coverage for `TypedClient.schedule` — typed wrapper around Temporal's * `ScheduleClient`. @@ -6,9 +9,7 @@ */ import { beforeEach, describe, expect, it, vi } from "vitest"; import { z } from "zod"; -import type { Client } from "@temporalio/client"; -import { TypedSearchAttributes } from "@temporalio/common"; -import { defineContract, defineSearchAttribute, defineWorkflow } from "@temporal-contract/contract"; + import { TypedClient } from "./client.js"; import { RuntimeClientError, WorkflowNotFoundError, WorkflowValidationError } from "./errors.js"; diff --git a/packages/client/src/schedule.ts b/packages/client/src/schedule.ts index db8995c1..90cf83b2 100644 --- a/packages/client/src/schedule.ts +++ b/packages/client/src/schedule.ts @@ -1,3 +1,4 @@ +import type { ContractDefinition } from "@temporal-contract/contract"; import type { ScheduleClient, ScheduleDescription, @@ -7,12 +8,12 @@ import type { ScheduleOverlapPolicy, ScheduleSpec, } from "@temporalio/client"; -import type { ContractDefinition } from "@temporal-contract/contract"; import { type AsyncResult, type Result, Ok, Err, fromPromise } from "unthrown"; + import type { TypedSearchAttributeMap } from "./client.js"; -import type { ClientInferInput } from "./types.js"; import { RuntimeClientError, WorkflowNotFoundError, WorkflowValidationError } from "./errors.js"; import { assertNoDefect, makeAsyncResult, toTypedSearchAttributes } from "./internal.js"; +import type { ClientInferInput } from "./types.js"; /** * Workflow-action–level overrides forwarded to Temporal's diff --git a/packages/client/src/types-inference.spec.ts b/packages/client/src/types-inference.spec.ts index 51524974..33dff89b 100644 --- a/packages/client/src/types-inference.spec.ts +++ b/packages/client/src/types-inference.spec.ts @@ -1,3 +1,4 @@ +import { defineContract, defineSignal, defineWorkflow } from "@temporal-contract/contract"; /** * Type-level tests for the typed-client surface. * @@ -18,7 +19,7 @@ */ import { describe, expectTypeOf, it } from "vitest"; import { z } from "zod"; -import { defineContract, defineSignal, defineWorkflow } from "@temporal-contract/contract"; + import type { TypedSignalWithStartOptions, TypedWorkflowStartOptions } from "./client.js"; const contractWithSignal = defineContract({ diff --git a/packages/client/src/types.ts b/packages/client/src/types.ts index 0b670741..c24eca39 100644 --- a/packages/client/src/types.ts +++ b/packages/client/src/types.ts @@ -1,4 +1,3 @@ -import type { AsyncResult } from "unthrown"; import type { ActivityDefinition, AnyWorkflowDefinition, @@ -7,6 +6,7 @@ import type { UpdateDefinition, ContractDefinition, } from "@temporal-contract/contract"; +import type { AsyncResult } from "unthrown"; // The direction-aware schema inference primitives live in // `@temporal-contract/contract` (single source of truth shared with the diff --git a/packages/contract/src/builder.spec.ts b/packages/contract/src/builder.spec.ts index 6288af74..78387802 100644 --- a/packages/contract/src/builder.spec.ts +++ b/packages/contract/src/builder.spec.ts @@ -1,7 +1,8 @@ import { describe, expect, it } from "vitest"; -import { defineContract } from "./builder.js"; import { z } from "zod"; +import { defineContract } from "./builder.js"; + describe("Contract Builder", () => { describe("defineContract", () => { it("should create a contract with workflows", () => { diff --git a/packages/contract/src/builder.ts b/packages/contract/src/builder.ts index e45fc057..9dea273c 100644 --- a/packages/contract/src/builder.ts +++ b/packages/contract/src/builder.ts @@ -1,5 +1,6 @@ -import { z } from "zod"; import type { StandardSchemaV1 } from "@standard-schema/spec"; +import { z } from "zod"; + import type { ActivityDefinition, AnyWorkflowDefinition, diff --git a/packages/contract/src/errors.spec.ts b/packages/contract/src/errors.spec.ts index a3be6cd6..a22b39f3 100644 --- a/packages/contract/src/errors.spec.ts +++ b/packages/contract/src/errors.spec.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from "vitest"; import { z } from "zod"; + import { _internal_buildErrorConstructors, _internal_rehydrateContractError, diff --git a/packages/contract/src/errors.ts b/packages/contract/src/errors.ts index f284cd5d..1175b33f 100644 --- a/packages/contract/src/errors.ts +++ b/packages/contract/src/errors.ts @@ -19,6 +19,7 @@ * string-matching failure types. */ import { TaggedError } from "unthrown"; + import type { AnySchema, ErrorDefinition, InferErrorData, InferErrorDataInput } from "./types.js"; /** diff --git a/packages/contract/src/format.spec.ts b/packages/contract/src/format.spec.ts index c8b4078b..b0203e41 100644 --- a/packages/contract/src/format.spec.ts +++ b/packages/contract/src/format.spec.ts @@ -1,3 +1,4 @@ +import type { StandardSchemaV1 } from "@standard-schema/spec"; /** * Coverage for the shared Standard Schema issue formatters. * @@ -9,7 +10,7 @@ * validation error messages. */ import { describe, expect, it } from "vitest"; -import type { StandardSchemaV1 } from "@standard-schema/spec"; + import { formatIssue, summarizeIssues } from "./format.js"; function issue( diff --git a/packages/contract/src/helpers.spec.ts b/packages/contract/src/helpers.spec.ts index e452476f..4e4f624b 100644 --- a/packages/contract/src/helpers.spec.ts +++ b/packages/contract/src/helpers.spec.ts @@ -1,4 +1,6 @@ import { describe, expect, it } from "vitest"; +import { z } from "zod"; + import { defineActivity, defineQuery, @@ -6,7 +8,6 @@ import { defineUpdate, defineWorkflow, } from "./builder.js"; -import { z } from "zod"; describe("Helper Functions", () => { describe("defineActivity", () => { diff --git a/packages/contract/src/result-async.spec.ts b/packages/contract/src/result-async.spec.ts index 91a7fe5c..e8b8db37 100644 --- a/packages/contract/src/result-async.spec.ts +++ b/packages/contract/src/result-async.spec.ts @@ -1,3 +1,4 @@ +import { Ok, Err } from "unthrown"; /** * Coverage for the shared `_internal_makeAsyncResult` helper. * @@ -10,7 +11,7 @@ * and `worker/src/internal.ts`. */ import { describe, expect, it } from "vitest"; -import { Ok, Err } from "unthrown"; + import { _internal_makeAsyncResult } from "./result-async.js"; class TestError extends Error { diff --git a/packages/contract/src/types-inference.spec.ts b/packages/contract/src/types-inference.spec.ts index 0d543d83..a1d16acb 100644 --- a/packages/contract/src/types-inference.spec.ts +++ b/packages/contract/src/types-inference.spec.ts @@ -8,6 +8,7 @@ */ import { describe, expectTypeOf, it } from "vitest"; import { z } from "zod"; + import { defineContract, defineActivity, diff --git a/packages/contract/src/types.spec.ts b/packages/contract/src/types.spec.ts index 31535e30..3041ed2e 100644 --- a/packages/contract/src/types.spec.ts +++ b/packages/contract/src/types.spec.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from "vitest"; import { z } from "zod"; + import type { ActivityDefinition, AnyWorkflowDefinition, diff --git a/packages/testing/src/extension.spec.ts b/packages/testing/src/extension.spec.ts index 29b38d88..35bd3611 100644 --- a/packages/testing/src/extension.spec.ts +++ b/packages/testing/src/extension.spec.ts @@ -9,6 +9,7 @@ * cleanup is deliberately left to the test framework). */ import { afterAll, describe, expect, vi } from "vitest"; + import { it } from "./extension.js"; const mocks = vi.hoisted(() => { diff --git a/packages/testing/src/global-setup.spec.ts b/packages/testing/src/global-setup.spec.ts index 76dec856..e133f447 100644 --- a/packages/testing/src/global-setup.spec.ts +++ b/packages/testing/src/global-setup.spec.ts @@ -9,6 +9,7 @@ */ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import type { TestProject } from "vitest/node"; + import setup from "./global-setup.js"; type StartedContainer = { diff --git a/packages/worker/src/__tests__/inprocess.contract.ts b/packages/worker/src/__tests__/inprocess.contract.ts index 4d501cc0..29b07ad3 100644 --- a/packages/worker/src/__tests__/inprocess.contract.ts +++ b/packages/worker/src/__tests__/inprocess.contract.ts @@ -1,5 +1,5 @@ -import { z } from "zod"; import { defineActivity, defineContract, defineWorkflow } from "@temporal-contract/contract"; +import { z } from "zod"; // Composition-first: resources are defined individually, then composed into // the contract (never inlined in `defineContract`). diff --git a/packages/worker/src/__tests__/inprocess.workflows.ts b/packages/worker/src/__tests__/inprocess.workflows.ts index 20929652..33daedf2 100644 --- a/packages/worker/src/__tests__/inprocess.workflows.ts +++ b/packages/worker/src/__tests__/inprocess.workflows.ts @@ -1,4 +1,5 @@ import { sleep } from "@temporalio/workflow"; + import { ContractError, declareWorkflow } from "../workflow.js"; import { inprocessContract } from "./inprocess.contract.js"; diff --git a/packages/worker/src/__tests__/test.workflows.ts b/packages/worker/src/__tests__/test.workflows.ts index b891b360..9153b776 100644 --- a/packages/worker/src/__tests__/test.workflows.ts +++ b/packages/worker/src/__tests__/test.workflows.ts @@ -1,7 +1,8 @@ -import { testContract } from "./test.contract.js"; -import { declareWorkflow } from "../workflow.js"; import { sleep } from "@temporalio/workflow"; +import { declareWorkflow } from "../workflow.js"; +import { testContract } from "./test.contract.js"; + export const simpleWorkflow = declareWorkflow({ workflowName: "simpleWorkflow", contract: testContract, diff --git a/packages/worker/src/__tests__/time-skipping.inprocess.spec.ts b/packages/worker/src/__tests__/time-skipping.inprocess.spec.ts index 93721a15..1999eb07 100644 --- a/packages/worker/src/__tests__/time-skipping.inprocess.spec.ts +++ b/packages/worker/src/__tests__/time-skipping.inprocess.spec.ts @@ -1,3 +1,9 @@ +import { extname } from "node:path"; +import { fileURLToPath } from "node:url"; + +import { ContractError, TypedClient, type ClientInterceptor } from "@temporal-contract/client"; +import { it } from "@temporal-contract/testing/time-skipping"; +import { Ok, Err, type AsyncResult } from "unthrown"; /** * Full contract-pipeline coverage against the time-skipping * `TestWorkflowEnvironment` (`@temporal-contract/testing/time-skipping`) — @@ -13,11 +19,7 @@ * - time skipping (an hour-long `sleep` resolving immediately). */ import { describe, expect } from "vitest"; -import { extname } from "node:path"; -import { fileURLToPath } from "node:url"; -import { Ok, Err, type AsyncResult } from "unthrown"; -import { it } from "@temporal-contract/testing/time-skipping"; -import { ContractError, TypedClient, type ClientInterceptor } from "@temporal-contract/client"; + import { composeActivityMiddleware, declareActivitiesHandler, diff --git a/packages/worker/src/__tests__/worker.spec.ts b/packages/worker/src/__tests__/worker.spec.ts index b9bfb2c0..cbe3c056 100644 --- a/packages/worker/src/__tests__/worker.spec.ts +++ b/packages/worker/src/__tests__/worker.spec.ts @@ -1,14 +1,16 @@ -import { describe, expect, vi, beforeEach } from "vitest"; -import { Worker } from "@temporalio/worker"; -import { TypedClient, WorkflowValidationError } from "@temporal-contract/client"; -import { it as baseIt } from "@temporal-contract/testing/extension"; -import { Ok, Err, type AsyncResult } from "unthrown"; import { extname } from "node:path"; import { fileURLToPath } from "node:url"; -import { testContract } from "./test.contract.js"; + +import { TypedClient, WorkflowValidationError } from "@temporal-contract/client"; +import { it as baseIt } from "@temporal-contract/testing/extension"; import { Client, WorkflowFailedError } from "@temporalio/client"; +import { type Worker } from "@temporalio/worker"; +import { Ok, Err, type AsyncResult } from "unthrown"; +import { describe, expect, vi, beforeEach } from "vitest"; + import { ApplicationFailure, declareActivitiesHandler } from "../activity.js"; import { createWorker } from "../worker.js"; +import { testContract } from "./test.contract.js"; // unthrown has no `okAsync`/`errAsync`; lift a sync `Result` with `.toAsync()`. const okAsync = (value: T): AsyncResult => Ok(value).toAsync(); diff --git a/packages/worker/src/activities-proxy.spec.ts b/packages/worker/src/activities-proxy.spec.ts index 55145d54..7151a80b 100644 --- a/packages/worker/src/activities-proxy.spec.ts +++ b/packages/worker/src/activities-proxy.spec.ts @@ -1,3 +1,7 @@ +import type { ActivityDefinition } from "@temporal-contract/contract"; +import { ContractError } from "@temporal-contract/contract/errors"; +import { ApplicationFailure, CancelledFailure } from "@temporalio/common"; +import type { AsyncResult } from "unthrown"; /** * Runtime coverage for `createValidatedActivities` — specifically the * Result-shaped wrapper that activities with a declared `errors` map get on @@ -6,11 +10,8 @@ * `ActivityError` fallback for everything else. */ import { describe, expect, it } from "vitest"; -import type { AsyncResult } from "unthrown"; import { z } from "zod"; -import { ApplicationFailure, CancelledFailure } from "@temporalio/common"; -import type { ActivityDefinition } from "@temporal-contract/contract"; -import { ContractError } from "@temporal-contract/contract/errors"; + import { createValidatedActivities } from "./activities-proxy.js"; import { ActivityCancelledError, ActivityError } from "./errors.js"; diff --git a/packages/worker/src/activities-proxy.ts b/packages/worker/src/activities-proxy.ts index 263e269c..bcfdd489 100644 --- a/packages/worker/src/activities-proxy.ts +++ b/packages/worker/src/activities-proxy.ts @@ -1,11 +1,3 @@ -/** - * Activity inference types + the validated-activities proxy used by - * `declareWorkflow`. Split out of `workflow.ts` to keep that file focused - * on `declareWorkflow` and its `WorkflowContext` type. Not part of the - * worker package's public exports. - */ -import { isCancellation } from "@temporalio/workflow"; -import { ActivityFailure, ApplicationFailure } from "@temporalio/common"; import type { ActivityDefinition, AnyWorkflowDefinition, @@ -17,7 +9,16 @@ import { _internal_rehydrateContractError, type ContractErrorUnion, } from "@temporal-contract/contract/errors"; +import { ActivityFailure, ApplicationFailure } from "@temporalio/common"; +/** + * Activity inference types + the validated-activities proxy used by + * `declareWorkflow`. Split out of `workflow.ts` to keep that file focused + * on `declareWorkflow` and its `WorkflowContext` type. Not part of the + * worker package's public exports. + */ +import { isCancellation } from "@temporalio/workflow"; import { Ok, Err, type AsyncResult } from "unthrown"; + import { ActivityCancelledError, ActivityError, diff --git a/packages/worker/src/activity-contract-errors.spec.ts b/packages/worker/src/activity-contract-errors.spec.ts index 58df0e5e..178f7cc5 100644 --- a/packages/worker/src/activity-contract-errors.spec.ts +++ b/packages/worker/src/activity-contract-errors.spec.ts @@ -1,3 +1,6 @@ +import { defineContract } from "@temporal-contract/contract"; +import { ContractError } from "@temporal-contract/contract/errors"; +import { Ok, Err, type AsyncResult } from "unthrown"; /** * Runtime coverage for `declareActivitiesHandler`'s contract-declared typed * errors, middleware chain, and dependency context — the boundary where an @@ -6,11 +9,8 @@ * `nonRetryable` from the contract). */ import { describe, expect, it, vi } from "vitest"; -import { Ok, Err, type AsyncResult } from "unthrown"; import { z } from "zod"; -import { defineContract } from "@temporal-contract/contract"; -import { ContractError } from "@temporal-contract/contract/errors"; -import { ContractErrorDataValidationError } from "./errors.js"; + import { ApplicationFailure, composeActivityMiddleware, @@ -18,6 +18,7 @@ import { defineActivityMiddleware, type ActivityMiddleware, } from "./activity.js"; +import { ContractErrorDataValidationError } from "./errors.js"; const okAsync = (value: T): AsyncResult => Ok(value).toAsync(); const errAsync = (error: E): AsyncResult => Err(error).toAsync(); diff --git a/packages/worker/src/activity.spec.ts b/packages/worker/src/activity.spec.ts index 6c166513..317237bb 100644 --- a/packages/worker/src/activity.spec.ts +++ b/packages/worker/src/activity.spec.ts @@ -1,13 +1,14 @@ -import { describe, expect, it } from "vitest"; +import type { ContractDefinition } from "@temporal-contract/contract"; import { Ok, Err, fromSafePromise, type AsyncResult } from "unthrown"; +import { describe, expect, it } from "vitest"; import { z } from "zod"; + +import { ApplicationFailure, declareActivitiesHandler, qualify } from "./activity.js"; import { ActivityDefinitionNotFoundError, ActivityInputValidationError, ActivityOutputValidationError, } from "./errors.js"; -import type { ContractDefinition } from "@temporal-contract/contract"; -import { ApplicationFailure, declareActivitiesHandler, qualify } from "./activity.js"; // unthrown has no `okAsync`/`errAsync`; lift a sync `Result` with `.toAsync()`. const okAsync = (value: T): AsyncResult => Ok(value).toAsync(); diff --git a/packages/worker/src/activity.ts b/packages/worker/src/activity.ts index 100d26ba..c4fc168a 100644 --- a/packages/worker/src/activity.ts +++ b/packages/worker/src/activity.ts @@ -17,9 +17,9 @@ // (`type` = error name, `details[0]` = validated data, `nonRetryable` from // the contract) at the boundary. import { - ActivityDefinition, - ContractDefinition, - ErrorDefinition, + type ActivityDefinition, + type ContractDefinition, + type ErrorDefinition, } from "@temporal-contract/contract"; import { _internal_buildErrorConstructors, @@ -28,16 +28,17 @@ import { type ContractErrorConstructors, type ContractErrorInputUnion, } from "@temporal-contract/contract/errors"; -import type { AsyncResult } from "unthrown"; import { ApplicationFailure } from "@temporalio/common"; -import { WorkerInferInput, WorkerInferOutput } from "./types.js"; +import type { AsyncResult } from "unthrown"; + +import { contractErrorToApplicationFailure } from "./contract-errors.js"; import { ActivityDefinitionNotFoundError, ActivityInputValidationError, ActivityOutputValidationError, } from "./errors.js"; -import { contractErrorToApplicationFailure } from "./contract-errors.js"; import { extractHandlerInput, makeAsyncResult } from "./internal.js"; +import { type WorkerInferInput, type WorkerInferOutput } from "./types.js"; export { ActivityDefinitionNotFoundError, diff --git a/packages/worker/src/cancellation.spec.ts b/packages/worker/src/cancellation.spec.ts index 491a9204..d5c377f8 100644 --- a/packages/worker/src/cancellation.spec.ts +++ b/packages/worker/src/cancellation.spec.ts @@ -1,3 +1,4 @@ +import { defineContract, defineWorkflow } from "@temporal-contract/contract"; /** * Coverage for the typed cancellation-scope helpers * ({@link cancellableScope}, {@link nonCancellableScope}). @@ -21,7 +22,6 @@ */ import { describe, expect, it, vi } from "vitest"; import { z } from "zod"; -import { defineContract, defineWorkflow } from "@temporal-contract/contract"; const CANCEL_MARKER = "__CANCEL__"; diff --git a/packages/worker/src/cancellation.ts b/packages/worker/src/cancellation.ts index 6812d483..a5a83dc3 100644 --- a/packages/worker/src/cancellation.ts +++ b/packages/worker/src/cancellation.ts @@ -14,6 +14,7 @@ */ import { CancellationScope, isCancellation } from "@temporalio/workflow"; import { type AsyncResult, type Result, Ok, Err } from "unthrown"; + import { WorkflowCancelledError } from "./errors.js"; import { makeAsyncResult } from "./internal.js"; diff --git a/packages/worker/src/child-workflow.spec.ts b/packages/worker/src/child-workflow.spec.ts index cb088d18..10369d42 100644 --- a/packages/worker/src/child-workflow.spec.ts +++ b/packages/worker/src/child-workflow.spec.ts @@ -1,3 +1,12 @@ +import { + ApplicationFailure, + CancelledFailure, + ChildWorkflowFailure, + TerminatedFailure, + TimeoutFailure, + TimeoutType, +} from "@temporalio/common"; +import { RetryState } from "@temporalio/common"; /** * Unit coverage for `classifyChildWorkflowError`. Mirrors the client-side * `classifyResultError` discrimination pattern so worker-side child-workflow @@ -8,21 +17,13 @@ * #11 (`WorkflowFailedError.cause` typing). */ import { describe, expect, it } from "vitest"; -import { - ApplicationFailure, - CancelledFailure, - ChildWorkflowFailure, - TerminatedFailure, - TimeoutFailure, - TimeoutType, -} from "@temporalio/common"; -import { RetryState } from "@temporalio/common"; -import { classifyChildWorkflowError } from "./internal.js"; + import { ChildWorkflowCancelledError, ChildWorkflowError, ChildWorkflowNotFoundError, } from "./errors.js"; +import { classifyChildWorkflowError } from "./internal.js"; // Minimal stand-in for a `WorkflowExecution`. The classify helper never // inspects the field — it only reads `.cause` off the wrapper — so the diff --git a/packages/worker/src/child-workflow.ts b/packages/worker/src/child-workflow.ts index b2ee281e..7a4e87c5 100644 --- a/packages/worker/src/child-workflow.ts +++ b/packages/worker/src/child-workflow.ts @@ -5,15 +5,16 @@ */ import type { AnyWorkflowDefinition, ContractDefinition } from "@temporal-contract/contract"; import { - ChildWorkflowHandle, - ChildWorkflowOptions, + type ChildWorkflowHandle, + type ChildWorkflowOptions, executeChild, startChild, type Workflow, } from "@temporalio/workflow"; import { type AsyncResult, type Result, Ok, Err } from "unthrown"; + import { - ChildWorkflowCancelledError, + type ChildWorkflowCancelledError, ChildWorkflowError, ChildWorkflowNotFoundError, } from "./errors.js"; diff --git a/packages/worker/src/continue-as-new.spec.ts b/packages/worker/src/continue-as-new.spec.ts index 481a4a9d..d32cbc1d 100644 --- a/packages/worker/src/continue-as-new.spec.ts +++ b/packages/worker/src/continue-as-new.spec.ts @@ -1,3 +1,5 @@ +import { defineActivity, defineContract, defineWorkflow } from "@temporal-contract/contract"; +import type { ContinueAsNewOptions } from "@temporalio/workflow"; /** * Coverage for the typed `context.continueAsNew(...)` helper. * @@ -14,8 +16,7 @@ */ import { afterEach, describe, expect, it, vi } from "vitest"; import { z } from "zod"; -import type { ContinueAsNewOptions } from "@temporalio/workflow"; -import { defineActivity, defineContract, defineWorkflow } from "@temporal-contract/contract"; + import { WorkflowInputValidationError } from "./errors.js"; type CapturedCall = { options: ContinueAsNewOptions; args: unknown[] }; diff --git a/packages/worker/src/contract-errors.ts b/packages/worker/src/contract-errors.ts index 4e6916fc..dbaa8ef2 100644 --- a/packages/worker/src/contract-errors.ts +++ b/packages/worker/src/contract-errors.ts @@ -1,3 +1,5 @@ +import type { ErrorDefinition } from "@temporal-contract/contract"; +import type { AnyContractError } from "@temporal-contract/contract/errors"; /** * Worker-side bridge between contract-declared typed errors and Temporal's * `ApplicationFailure`. @@ -7,8 +9,7 @@ * `./activity` and `./workflow`. */ import { ApplicationFailure } from "@temporalio/common"; -import type { ErrorDefinition } from "@temporal-contract/contract"; -import type { AnyContractError } from "@temporal-contract/contract/errors"; + import { ContractErrorDataValidationError } from "./errors.js"; /** diff --git a/packages/worker/src/errors.spec.ts b/packages/worker/src/errors.spec.ts index 6ce3d775..a2d43fde 100644 --- a/packages/worker/src/errors.spec.ts +++ b/packages/worker/src/errors.spec.ts @@ -1,3 +1,5 @@ +import type { StandardSchemaV1 } from "@standard-schema/spec"; +import { ApplicationFailure } from "@temporalio/common"; /** * Coverage for the path-aware issue formatting in worker validation errors * and in `formatChildWorkflowValidationMessage` (the workflow.ts call site @@ -10,8 +12,7 @@ * Closes #141. */ import { describe, expect, it } from "vitest"; -import { ApplicationFailure } from "@temporalio/common"; -import type { StandardSchemaV1 } from "@standard-schema/spec"; + import { ActivityInputValidationError, ActivityOutputValidationError, diff --git a/packages/worker/src/handlers.spec.ts b/packages/worker/src/handlers.spec.ts index aaed86c0..529692c7 100644 --- a/packages/worker/src/handlers.spec.ts +++ b/packages/worker/src/handlers.spec.ts @@ -1,3 +1,4 @@ +import { defineWorkflow } from "@temporal-contract/contract"; /** * Coverage for the hoisted signal/query/update bind helpers * (`bindSignalHandler`, `bindQueryHandler`, `bindUpdateHandler`). @@ -17,7 +18,6 @@ */ import { describe, expect, it, vi } from "vitest"; import { z } from "zod"; -import { defineWorkflow } from "@temporal-contract/contract"; const captured: Array<{ kind: string; diff --git a/packages/worker/src/handlers.ts b/packages/worker/src/handlers.ts index 0a5cb1fd..54d91d4e 100644 --- a/packages/worker/src/handlers.ts +++ b/packages/worker/src/handlers.ts @@ -16,6 +16,7 @@ import type { UpdateDefinition, } from "@temporal-contract/contract"; import { defineQuery, defineSignal, defineUpdate, setHandler } from "@temporalio/workflow"; + import { QueryInputValidationError, QueryOutputValidationError, diff --git a/packages/worker/src/internal.ts b/packages/worker/src/internal.ts index 943f091f..0bf94799 100644 --- a/packages/worker/src/internal.ts +++ b/packages/worker/src/internal.ts @@ -1,3 +1,10 @@ +import type { StandardSchemaV1 } from "@standard-schema/spec"; +import { + type ActivityDefinition, + type ContractDefinition, + summarizeIssues, +} from "@temporal-contract/contract"; +import { ChildWorkflowFailure } from "@temporalio/common"; /** * Internal helpers shared across the worker package's entry points. * @@ -7,13 +14,7 @@ */ import { isCancellation, makeContinueAsNewFunc, proxyActivities } from "@temporalio/workflow"; import type { ActivityOptions, ContinueAsNewOptions } from "@temporalio/workflow"; -import { ChildWorkflowFailure } from "@temporalio/common"; -import type { StandardSchemaV1 } from "@standard-schema/spec"; -import { - type ActivityDefinition, - type ContractDefinition, - summarizeIssues, -} from "@temporal-contract/contract"; + import { ChildWorkflowCancelledError, ChildWorkflowError, diff --git a/packages/worker/src/types-inference.spec.ts b/packages/worker/src/types-inference.spec.ts index 00528f91..5ead22d0 100644 --- a/packages/worker/src/types-inference.spec.ts +++ b/packages/worker/src/types-inference.spec.ts @@ -1,3 +1,4 @@ +import { defineActivity } from "@temporal-contract/contract"; /** * Type-level tests for the worker- and client-side inference helpers. * @@ -7,7 +8,7 @@ */ import { describe, expectTypeOf, it } from "vitest"; import { z } from "zod"; -import { defineActivity } from "@temporal-contract/contract"; + import type { ClientInferInput, ClientInferOutput, diff --git a/packages/worker/src/worker.spec.ts b/packages/worker/src/worker.spec.ts index ca4cc203..c9c05cb2 100644 --- a/packages/worker/src/worker.spec.ts +++ b/packages/worker/src/worker.spec.ts @@ -1,8 +1,9 @@ +import type { ContractDefinition } from "@temporal-contract/contract"; +import { type NativeConnection, Worker } from "@temporalio/worker"; import { describe, expect, it, vi, beforeEach } from "vitest"; import { z } from "zod"; -import type { ContractDefinition } from "@temporal-contract/contract"; + import { createWorker, createWorkerOrThrow, workflowsPathFromURL } from "./worker.js"; -import { NativeConnection, Worker } from "@temporalio/worker"; // Mock @temporalio/worker vi.mock("@temporalio/worker", () => ({ diff --git a/packages/worker/src/worker.ts b/packages/worker/src/worker.ts index 57267b7d..367e6dce 100644 --- a/packages/worker/src/worker.ts +++ b/packages/worker/src/worker.ts @@ -1,9 +1,11 @@ +import { fileURLToPath } from "node:url"; + // Entry point for worker creation utilities -import { ContractDefinition } from "@temporal-contract/contract"; +import { type ContractDefinition } from "@temporal-contract/contract"; import { TechnicalError } from "@temporal-contract/contract/errors"; -import { Worker, WorkerOptions } from "@temporalio/worker"; -import { fileURLToPath } from "node:url"; +import { Worker, type WorkerOptions } from "@temporalio/worker"; import { fromPromise, type AsyncResult } from "unthrown"; + import type { ActivitiesHandler } from "./activity.js"; // Modeled creation failure — `createWorker` surfaces it on the Err channel diff --git a/packages/worker/src/workflow-errors.spec.ts b/packages/worker/src/workflow-errors.spec.ts index c62dbbe8..7335975a 100644 --- a/packages/worker/src/workflow-errors.spec.ts +++ b/packages/worker/src/workflow-errors.spec.ts @@ -1,3 +1,5 @@ +import { defineContract } from "@temporal-contract/contract"; +import { ApplicationFailure } from "@temporalio/common"; /** * Runtime coverage for workflow-level contract errors: a * `throw context.errors.X(...)` from the implementation must leave the @@ -10,8 +12,6 @@ */ import { describe, expect, it, vi } from "vitest"; import { z } from "zod"; -import { defineContract } from "@temporal-contract/contract"; -import { ApplicationFailure } from "@temporalio/common"; vi.mock("@temporalio/workflow", async () => { const actual = diff --git a/packages/worker/src/workflow-options.spec.ts b/packages/worker/src/workflow-options.spec.ts index 0eefb022..92620af9 100644 --- a/packages/worker/src/workflow-options.spec.ts +++ b/packages/worker/src/workflow-options.spec.ts @@ -1,3 +1,5 @@ +import { defineActivity, defineContract, defineWorkflow } from "@temporal-contract/contract"; +import type { ActivityOptions } from "@temporalio/workflow"; /** * Type-level coverage for `declareWorkflow`'s `activityOptionsByName`. * @@ -8,9 +10,8 @@ */ import { describe, expectTypeOf, it } from "vitest"; import { z } from "zod"; -import { defineActivity, defineContract, defineWorkflow } from "@temporal-contract/contract"; -import type { ActivityOptions } from "@temporalio/workflow"; -import { declareWorkflow } from "./workflow.js"; + +import { type declareWorkflow } from "./workflow.js"; const contract = defineContract({ taskQueue: "tq", diff --git a/packages/worker/src/workflow-proxy.spec.ts b/packages/worker/src/workflow-proxy.spec.ts index 6f19675d..b8d1cb81 100644 --- a/packages/worker/src/workflow-proxy.spec.ts +++ b/packages/worker/src/workflow-proxy.spec.ts @@ -1,3 +1,6 @@ +import type { ActivityDefinition } from "@temporal-contract/contract"; +import { defineActivity, defineContract, defineWorkflow } from "@temporal-contract/contract"; +import type { ActivityOptions } from "@temporalio/workflow"; /** * Runtime coverage for `buildRawActivitiesProxy` — the helper that wires * per-activity `ActivityOptions` overrides into Temporal's `proxyActivities`. @@ -9,9 +12,6 @@ */ import { afterEach, describe, expect, it, vi } from "vitest"; import { z } from "zod"; -import type { ActivityOptions } from "@temporalio/workflow"; -import type { ActivityDefinition } from "@temporal-contract/contract"; -import { defineActivity, defineContract, defineWorkflow } from "@temporal-contract/contract"; const proxyCalls: ActivityOptions[] = []; diff --git a/packages/worker/src/workflow.spec.ts b/packages/worker/src/workflow.spec.ts index b87243c7..d7e22914 100644 --- a/packages/worker/src/workflow.spec.ts +++ b/packages/worker/src/workflow.spec.ts @@ -1,3 +1,4 @@ +import { defineContract, defineWorkflow } from "@temporal-contract/contract"; /** * Runtime coverage for `declareWorkflow`'s `.name` surfacing. * @@ -9,7 +10,7 @@ */ import { describe, expect, it } from "vitest"; import { z } from "zod"; -import { defineContract, defineWorkflow } from "@temporal-contract/contract"; + import { declareWorkflow } from "./workflow.js"; const contract = defineContract({ diff --git a/packages/worker/src/workflow.ts b/packages/worker/src/workflow.ts index 8352196a..16e3ea0d 100644 --- a/packages/worker/src/workflow.ts +++ b/packages/worker/src/workflow.ts @@ -21,16 +21,29 @@ import { ContractError, type ContractErrorConstructors, } from "@temporal-contract/contract/errors"; +import { type ActivityOptions, type WorkflowInfo, workflowInfo } from "@temporalio/workflow"; +import type { AsyncResult } from "unthrown"; + import { - ChildWorkflowCancelledError, - ChildWorkflowError, - ChildWorkflowNotFoundError, - WorkflowCancelledError, + createValidatedActivities, + type WorkflowInferWorkflowContextActivities, +} from "./activities-proxy.js"; +import { cancellableScope, nonCancellableScope } from "./cancellation.js"; +import { + createStartChildWorkflow, + createExecuteChildWorkflow, + type TypedChildWorkflowHandle, + type TypedChildWorkflowOptions, +} from "./child-workflow.js"; +import { contractErrorToApplicationFailure } from "./contract-errors.js"; +import { + type ChildWorkflowCancelledError, + type ChildWorkflowError, + type ChildWorkflowNotFoundError, + type WorkflowCancelledError, WorkflowInputValidationError, WorkflowOutputValidationError, } from "./errors.js"; -import { contractErrorToApplicationFailure } from "./contract-errors.js"; -import { cancellableScope, nonCancellableScope } from "./cancellation.js"; import { bindQueryHandler, bindSignalHandler, @@ -39,13 +52,6 @@ import { type SignalHandlerImplementation, type UpdateHandlerImplementation, } from "./handlers.js"; -import { - ClientInferInput, - ClientInferOutput, - WorkerInferInput, - WorkerInferOutput, -} from "./types.js"; -import type { AsyncResult } from "unthrown"; import { buildRawActivitiesProxy, createContinueAsNew, @@ -53,16 +59,11 @@ import { type TypedContinueAsNewOptions, } from "./internal.js"; import { - createStartChildWorkflow, - createExecuteChildWorkflow, - type TypedChildWorkflowHandle, - type TypedChildWorkflowOptions, -} from "./child-workflow.js"; -import { - createValidatedActivities, - type WorkflowInferWorkflowContextActivities, -} from "./activities-proxy.js"; -import { type ActivityOptions, type WorkflowInfo, workflowInfo } from "@temporalio/workflow"; + type ClientInferInput, + type ClientInferOutput, + type WorkerInferInput, + type WorkerInferOutput, +} from "./types.js"; export { ActivityCancelledError, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 70c454d8..1eb0ecb9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,15 +9,18 @@ catalogs: '@btravstack/commitlint': specifier: 0.1.0 version: 0.1.0 + '@btravstack/lefthook': + specifier: 0.1.1 + version: 0.1.1 '@btravstack/oxlint': - specifier: 0.1.0 - version: 0.1.0 + specifier: 0.2.1 + version: 0.2.1 '@btravstack/theme': specifier: 1.7.0 version: 1.7.0 '@btravstack/tsconfig': - specifier: 0.1.0 - version: 0.1.0 + specifier: 0.2.0 + version: 0.2.0 '@btravstack/typedoc': specifier: 0.1.0 version: 0.1.0 @@ -124,9 +127,12 @@ importers: '@btravstack/commitlint': specifier: 'catalog:' version: 0.1.0(@commitlint/cli@21.2.1(@types/node@26.1.1)(conventional-commits-parser@7.0.1)(typescript@6.0.3)) + '@btravstack/lefthook': + specifier: 'catalog:' + version: 0.1.1(lefthook@2.1.10) '@btravstack/oxlint': specifier: 'catalog:' - version: 0.1.0(oxlint@1.73.0) + version: 0.2.1(oxlint@1.73.0) '@changesets/cli': specifier: 'catalog:' version: 2.31.0(@types/node@26.1.1) @@ -169,7 +175,7 @@ importers: version: 1.7.0(vitepress@1.6.4(@algolia/client-search@5.53.0)(@types/node@26.1.1)(jiti@2.7.0)(postcss@8.5.19)(terser@5.48.0)(tsx@4.23.1)(typescript@6.0.3)(yaml@2.9.0))(vue@3.5.35(typescript@6.0.3)) '@btravstack/tsconfig': specifier: 'catalog:' - version: 0.1.0 + version: 0.2.0 '@types/node': specifier: 'catalog:' version: 26.1.1 @@ -212,7 +218,7 @@ importers: devDependencies: '@btravstack/tsconfig': specifier: 'catalog:' - version: 0.1.0 + version: 0.2.0 '@types/node': specifier: 'catalog:' version: 26.1.1 @@ -234,7 +240,7 @@ importers: devDependencies: '@btravstack/tsconfig': specifier: 'catalog:' - version: 0.1.0 + version: 0.2.0 '@types/node': specifier: 'catalog:' version: 26.1.1 @@ -274,7 +280,7 @@ importers: devDependencies: '@btravstack/tsconfig': specifier: 'catalog:' - version: 0.1.0 + version: 0.2.0 '@temporal-contract/client': specifier: workspace:* version: link:../../packages/client @@ -314,7 +320,7 @@ importers: devDependencies: '@btravstack/tsconfig': specifier: 'catalog:' - version: 0.1.0 + version: 0.2.0 '@btravstack/typedoc': specifier: 'catalog:' version: 0.1.0(typedoc-plugin-markdown@4.12.0(typedoc@0.28.20(typescript@6.0.3)))(typedoc@0.28.20(typescript@6.0.3)) @@ -375,7 +381,7 @@ importers: devDependencies: '@btravstack/tsconfig': specifier: 'catalog:' - version: 0.1.0 + version: 0.2.0 '@btravstack/typedoc': specifier: 'catalog:' version: 0.1.0(typedoc-plugin-markdown@4.12.0(typedoc@0.28.20(typescript@6.0.3)))(typedoc@0.28.20(typescript@6.0.3)) @@ -421,7 +427,7 @@ importers: devDependencies: '@btravstack/tsconfig': specifier: 'catalog:' - version: 0.1.0 + version: 0.2.0 '@btravstack/typedoc': specifier: 'catalog:' version: 0.1.0(typedoc-plugin-markdown@4.12.0(typedoc@0.28.20(typescript@6.0.3)))(typedoc@0.28.20(typescript@6.0.3)) @@ -467,7 +473,7 @@ importers: devDependencies: '@btravstack/tsconfig': specifier: 'catalog:' - version: 0.1.0 + version: 0.2.0 '@btravstack/typedoc': specifier: 'catalog:' version: 0.1.0(typedoc-plugin-markdown@4.12.0(typedoc@0.28.20(typescript@6.0.3)))(typedoc@0.28.20(typescript@6.0.3)) @@ -651,8 +657,14 @@ packages: peerDependencies: '@commitlint/cli': '>=21' - '@btravstack/oxlint@0.1.0': - resolution: {integrity: sha512-/UIfVydE3nEExRqE03vUoAAQSdPqVNOzZl0QSa9ikXftezoLQfNgJcFCKW6+D2cJnM180JR0o0W7dmkQHhLogQ==} + '@btravstack/lefthook@0.1.1': + resolution: {integrity: sha512-5KFOHHrJzHm5xqtxVtsVWfm862h7ivAlRGWngtSteEZxn3aNdEwIxchts0NBX1ICg+TNL5XcIRmiPIRCyOOOvQ==} + engines: {node: '>=20'} + peerDependencies: + lefthook: '>=2' + + '@btravstack/oxlint@0.2.1': + resolution: {integrity: sha512-BflvYgQL67f0SVlgorKCC9tAZMor0vBpN0wkuO/SSsNsiOYMXlFEVJuUaL/ULwZYsDbeoSrzBblg1LLaIAMnHA==} engines: {node: '>=20'} peerDependencies: oxlint: '>=1' @@ -666,8 +678,8 @@ packages: vue: optional: true - '@btravstack/tsconfig@0.1.0': - resolution: {integrity: sha512-xRkISG6jY5vLpaDJCptyOjvmUeyH6M/i6shhoE6WFGBc+JToc/dyO/511Zi6NPYVTHamNbxOG/e6dpclBWIz2A==} + '@btravstack/tsconfig@0.2.0': + resolution: {integrity: sha512-0VZt4DNJlY+XgAeCS4HybgsG0kdWDGjRwBiDdQZ6pYPUo1ayjM4AIH1oPatL5+YQvICTqrSaXTHSa8DnP+GXbg==} engines: {node: '>=20'} '@btravstack/typedoc@0.1.0': @@ -5168,7 +5180,11 @@ snapshots: '@commitlint/cli': 21.2.1(@types/node@26.1.1)(conventional-commits-parser@7.0.1)(typescript@6.0.3) '@commitlint/config-conventional': 21.2.0 - '@btravstack/oxlint@0.1.0(oxlint@1.73.0)': + '@btravstack/lefthook@0.1.1(lefthook@2.1.10)': + dependencies: + lefthook: 2.1.10 + + '@btravstack/oxlint@0.2.1(oxlint@1.73.0)': dependencies: oxlint: 1.73.0 @@ -5178,7 +5194,7 @@ snapshots: optionalDependencies: vue: 3.5.35(typescript@6.0.3) - '@btravstack/tsconfig@0.1.0': {} + '@btravstack/tsconfig@0.2.0': {} '@btravstack/typedoc@0.1.0(typedoc-plugin-markdown@4.12.0(typedoc@0.28.20(typescript@6.0.3)))(typedoc@0.28.20(typescript@6.0.3))': dependencies: diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 029e414f..fab9081d 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -11,9 +11,10 @@ packages: catalog: "@btravstack/commitlint": 0.1.0 - "@btravstack/oxlint": 0.1.0 + "@btravstack/lefthook": 0.1.1 + "@btravstack/oxlint": 0.2.1 "@btravstack/theme": 1.7.0 - "@btravstack/tsconfig": 0.1.0 + "@btravstack/tsconfig": 0.2.0 "@btravstack/typedoc": 0.1.0 "@changesets/cli": 2.31.0 "@commitlint/cli": 21.2.1 @@ -94,6 +95,7 @@ minimumReleaseAgeStrict: true # third-party supply-chain risk, which does not apply to our own org's libraries. minimumReleaseAgeExclude: - "@btravstack/commitlint" + - "@btravstack/lefthook" - "@btravstack/oxlint" - "@btravstack/theme" - "@btravstack/tsconfig"