@temporal-contract/contract@7.0.0
Minor Changes
-
dc4a0cd: Cross-project DNA alignment with amqp-contract (#301, #302, #303, #304).
Breaking — AsyncResult-returning creation (#301). The runtime factories now model creation failures on the
Errchannel instead of throwing, matching the org-wideTyped*.create()shape:TypedClient.create({ contract, client, interceptors? })→AsyncResult<TypedClient, TechnicalError>(single options object; surfaces a missing Schedule API and eager-connection failures viaconnection.ensureConnected).createWorker(options)→AsyncResult<Worker, TechnicalError>(bundling/connection failures modeled).TechnicalError(tag@temporal-contract/TechnicalError) is exported from@temporal-contract/contract/errorsand re-exported by client and worker.- Migration: deprecated throwing aliases
TypedClient.createOrThrow(contract, client)andcreateWorkerOrThrow(options)preserve the old behavior and will be removed in a future major.
Breaking — unified context model (#302).
declareActivitiesHandler's middleware option now takes a single middleware (compose chains withcomposeActivityMiddleware(...), outermost-first) instead of an array, andnexttakes an object patch:next({ context })extends the typed context flowing downstream (shallow-merged; bounded genericsTContextOut extends TContextInaccumulate acrosscomposeActivityMiddleware's overloads — amqp-contract's model).defineActivityMiddlewarepins a middleware's context types;EmptyContextis the empty seed.next({ input })replaces the positionalnext(input)substitution (still re-validated against the contract schema).createContextnow seeds the accumulated context;helpers.contextis the seed plus every middleware injection (an empty object when unconfigured, no longerundefined).- Client interceptors:
TypedClient.create({ interceptors })wrapsstartWorkflow/executeWorkflow/signalWithStartand handle-levelsignal/query/update, outermost-first, outside validation — patch args vianext({ input }), retry by callingnextagain, short-circuit by returning without callingnext. - The demesne
Layer.forkScoperecipe is documented as the recommendedcreateContextengine for scoped, resource-releasing contexts.
Testing — in-process story (#303). New
@temporal-contract/testing/time-skippingentry point: a Vitest fixture (itwith a worker-scopedtestEnv) pluscreateTimeSkippingEnvironment()wrapping Temporal's time-skippingTestWorkflowEnvironment— full contract-pipeline tests (validation, middleware, typed errors, rehydration) without Docker.@temporalio/testing ^1is a new peer dependency of the testing package.Consistency cleanup (#304).
activityOptionsondeclareWorkflowis now optional when every reachable activity carries contract-leveldefaultOptions(or anactivityOptionsByNameentry) — a descriptive declaration-time error lists uncovered activities otherwise. The direction-aware inference primitives (ClientInferInput/ClientInferOutput/WorkerInferInput/WorkerInferOutput) are centralized in@temporal-contract/contract(worker/client re-export them unchanged). The obsoletemigrating-to-neverthrowguide is removed, stale JSDoc fixed, and docs/examples adopt the composition-first rule (define resources first, then reference them indefineContract). -
52d4c01: Contract-declared typed domain errors, activity middleware + typed dependency context, and contract-level default activity options.
- Typed domain errors —
defineActivity/defineWorkflowaccept anerrorsmap ({ data?: StandardSchema, message?, nonRetryable? }per name). Activity implementations receive typed constructors via a new helpers argument ((args, { errors }) => Err(errors.PaymentDeclined({ reason }))); the worker serializes them asApplicationFailure(type= error name,details[0]= validated payload,nonRetryablefrom the contract). On the workflow side, errors-declaring activities now returnAsyncResult<Output, ContractError union | ActivityError | ActivityCancelledError>(mirroring the child-workflow API); activities without declared errors keep the throwingPromiseshape. Workflows can declare their own errors and fail withthrow context.errors.X(data); the typed client rehydrates matching failures intoContractErroronexecuteWorkflowandhandle.result(). New@temporal-contract/contract/errorsentry point exportsContractErrorand the supporting types. - Activity middleware + typed context —
declareActivitiesHandleracceptscreateContext(typed dependency injection, surfaced to implementations ashelpers.context) andmiddleware(contract-aware chain running inside the validation boundary, operating on the unthrownAsyncResult). - Contract-level activity option defaults —
defineActivityacceptsdefaultOptions(timeouts, retry policy). Merge precedence at the worker:declareWorkflowactivityOptions< contractdefaultOptions<activityOptionsByName.
- Typed domain errors —
Patch Changes
-
1ec704a: Require unthrown >= 4.1.0 (peer range
^4→^4.1.0).unthrown 4.1 renames several operators and deprecates the old aliases (
orElse→flatMapErr,recover→recoverErr,unwrap/unwrapErr/unwrapOr/unwrapOrElse→get/getErr/getOr/getOrElse). The packages' own code never used the deprecated names, so no runtime behavior changes — the docs and guides now reference the new names, and raising the peer minimum guarantees the renamed operators exist for consumers following them.