Skip to content

@btravstack/temporal-worker


@btravstack/temporal-worker

Classes

TemporalConfig

Defined in: packages/temporal-worker/src/temporal-runtime.ts:64

Where the Temporal service is, as a service: temporal() binds it from the environment — TEMPORAL_ADDRESS (default 127.0.0.1:7233), TEMPORAL_NAMESPACE (default default) and the shutdown budgets below — unless pinned, and anything else in the graph may read it.

Extends

  • PortInstance<"TemporalConfig", { address: string; forceAfterMs: number; gracePeriodMs: number; namespace: string; }>

Constructors

Constructor
ts
new TemporalConfig(): TemporalConfig;

Defined in: packages/di/dist/index.d.mts:16

Returns

TemporalConfig

Inherited from
ts
Port("TemporalConfig")<{
  readonly address: string;
  readonly namespace: string;
  / Temporal's shutdownGraceTime, in milliseconds. /
  readonly gracePeriodMs: number;
  / Temporal's shutdownForceTime, in milliseconds. /
  readonly forceAfterMs: number;
}>.constructor

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
[ID]readonly"TemporalConfig"-Port("TemporalConfig").[ID]packages/di/dist/index.d.mts:12
[SERVICE]readonlyobject-Port("TemporalConfig").[SERVICE]packages/di/dist/index.d.mts:13
[SERVICE].addressreadonlystring--packages/temporal-worker/src/temporal-runtime.ts:65
[SERVICE].forceAfterMsreadonlynumberTemporal's shutdownForceTime, in milliseconds.-packages/temporal-worker/src/temporal-runtime.ts:70
[SERVICE].gracePeriodMsreadonlynumberTemporal's shutdownGraceTime, in milliseconds.-packages/temporal-worker/src/temporal-runtime.ts:68
[SERVICE].namespacereadonlystring--packages/temporal-worker/src/temporal-runtime.ts:66
portIdreadonly"TemporalConfig"-Port("TemporalConfig").portIdpackages/di/dist/index.d.mts:17

TemporalConnection

Defined in: packages/temporal-worker/src/temporal-runtime.ts:77

The connection, as a resource of the graph: di opens it with the scope and closes it on every exit path, startup failure included.

Extends

  • PortInstance<"TemporalConnection", NativeConnection>

Constructors

Constructor
ts
new TemporalConnection(): TemporalConnection;

Defined in: packages/di/dist/index.d.mts:16

Returns

TemporalConnection

Inherited from
ts
Port("TemporalConnection")<NativeConnection>.constructor

Properties

PropertyModifierTypeInherited fromDefined in
[ID]readonly"TemporalConnection"Port("TemporalConnection").[ID]packages/di/dist/index.d.mts:12
[SERVICE]readonlyNativeConnectionPort("TemporalConnection").[SERVICE]packages/di/dist/index.d.mts:13
portIdreadonly"TemporalConnection"Port("TemporalConnection").portIdpackages/di/dist/index.d.mts:17

TemporalRuntime

Defined in: packages/temporal-worker/src/temporal-runtime.ts:93

The runtime's port: what temporal() provides, and what the module start boots must export.

Extends

Constructors

Constructor
ts
new TemporalRuntime(): TemporalRuntime;

Defined in: packages/di/dist/index.d.mts:16

Returns

TemporalRuntime

Inherited from
ts
RuntimePort<Runtime<never, TemporalInfo>>.constructor

Properties

PropertyModifierTypeInherited fromDefined in
[ID]readonly"Runtime"RuntimePort.[ID]packages/di/dist/index.d.mts:12
[SERVICE]readonlyRuntimeRuntimePort.[SERVICE]packages/di/dist/index.d.mts:13
portIdreadonly"Runtime"RuntimePort.portIdpackages/di/dist/index.d.mts:17

TemporalUnreachable

Defined in: packages/temporal-worker/src/temporal-runtime.ts:85

The service at TemporalConfig.address did not answer. Modeled rather than left a defect because an operator can act on it — the address is wrong or the service is down, and neither is a bug in this code — so runMain exits 1, a startup Err, not the 70 a defect earns.

Extends

  • TaggedErrorInstance<"TemporalUnreachable", { address: string; cause: unknown; }>

Constructors

Constructor
ts
new TemporalUnreachable(args): TemporalUnreachable;

Defined in: node_modules/.pnpm/unthrown@5.8.0/node_modules/unthrown/dist/index.d.mts:2034

Parameters
ParameterType
argsobject & object
Returns

TemporalUnreachable

Inherited from
ts
TaggedError("TemporalUnreachable")<{
  readonly address: string;
  readonly cause: unknown;
}>.constructor

Properties

PropertyModifierTypeOverridesInherited fromDefined in
_tagreadonly"TemporalUnreachable"-TaggedError("TemporalUnreachable")._tagnode_modules/.pnpm/unthrown@5.8.0/node_modules/unthrown/dist/index.d.mts:2011
addressreadonlystring-TaggedError("TemporalUnreachable").addresspackages/temporal-worker/src/temporal-runtime.ts:86
causepublicunknown-TaggedError("TemporalUnreachable").causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
messagepublicstringTaggedError("TemporalUnreachable").message-packages/temporal-worker/src/temporal-runtime.ts:89
namepublicstring-TaggedError("TemporalUnreachable").namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
stack?publicstring-TaggedError("TemporalUnreachable").stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076

Type Aliases

ActivitiesInstanceOf

ts
type ActivitiesInstanceOf<C> = PortInstance<"TemporalActivities", ActivitiesOf<C>>;

Defined in: packages/temporal-worker/src/temporal-runtime.ts:142

The activities port's instance for C — the module's one need.

Type Parameters

Type Parameter
C extends ContractDefinition

ActivitiesPortOf

ts
type ActivitiesPortOf<C> = PortClassOf<"TemporalActivities", ActivitiesOf<C>>;

Defined in: packages/temporal-worker/src/temporal-runtime.ts:136

The activities port class, typed for C: what TemporalActivities(contract)(…).port is.

Type Parameters

Type Parameter
C extends ContractDefinition

ActivityInputOf

ts
type ActivityInputOf<C> = InputOfEntry<ActivitiesRecordOf<C>[ActivitiesKeyOf<C>]>;

Defined in: packages/temporal-worker/src/workflow-activities.ts:42

The validated activity input, typed by the contract: the union of every activity's own input.

Type Parameters

Type Parameter
C extends ContractDefinition

ActivityInputPortOf

ts
type ActivityInputPortOf<C> = PortClassOf<"ActivityInput", ActivityInputOf<C>>;

Defined in: packages/temporal-worker/src/workflow-activities.ts:47

The seeded port's class, typed for C: what ActivityInput(contract) answers.

Type Parameters

Type Parameter
C extends ContractDefinition

TemporalInfo

ts
type TemporalInfo = object;

Defined in: packages/temporal-worker/src/temporal-runtime.ts:43

What the worker publishes once it is polling, read back through RunningApp.runtimeInfo().

Properties

PropertyModifierTypeDefined in
namespacereadonlystringpackages/temporal-worker/src/temporal-runtime.ts:45
taskQueuereadonlystringpackages/temporal-worker/src/temporal-runtime.ts:44

TemporalModuleOptions

ts
type TemporalModuleOptions<C, ActivitiesError, ActivitiesNeeds, Declared, Unit, I, P, X, N> = TemporalTuning<Unit> & object & NeedsGate<Imports<I, C, Unit>, Provides<P, C, ActivitiesError, ActivitiesNeeds>, N> & UnitGate<Unit, Declared>;

Defined in: packages/temporal-worker/src/temporal-module.ts:59

Type Declaration

NameTypeDescriptionDefined in
activitiesProvider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds> & objectThe application's activity implementations — what TemporalActivities(contract)(…) returns. Its _declaredUnit phantom carries every port its pieces read off context.unit, which is what UnitGate checks unit.activity against.packages/temporal-worker/src/temporal-module.ts:82
contractCThe temporal-contract contract; the task queue this worker polls is read off it.packages/temporal-worker/src/temporal-module.ts:74
exports?XThe application's own exports; TemporalRuntime is added, since start resolves it.packages/temporal-worker/src/temporal-module.ts:88
imports?I-packages/temporal-worker/src/temporal-module.ts:85
needs?NWhat this root's OWN providers expect from outside. di's gate is re-stated over the augmented tuples below, so forgetting one is an error at THIS call.packages/temporal-worker/src/temporal-module.ts:93
provides?P-packages/temporal-worker/src/temporal-module.ts:86
workflowsWorkflowSource-packages/temporal-worker/src/temporal-module.ts:75

Type Parameters

Type Parameter
C extends ContractDefinition
ActivitiesError
ActivitiesNeeds
Declared
Unit extends AnyUnitModule | undefined
I extends readonly AnyModule[]
P extends readonly AnyProvider[]
X extends readonly Exportable<Imports<I, C, Unit>, Provides<P, C, ActivitiesError, ActivitiesNeeds>>[]
N extends readonly AnyPort[]

TemporalOptions

ts
type TemporalOptions<C, Unit> = TemporalTuning<Unit> & object;

Defined in: packages/temporal-worker/src/temporal-runtime.ts:181

Type Declaration

NameTypeDescriptionDefined in
contractCThe contract; the task queue this worker polls is read off it, and the activities port is typed by it. The starter calls declareActivitiesHandler itself, with its unit middleware in place.packages/temporal-worker/src/temporal-runtime.ts:190
workflowsWorkflowSource-packages/temporal-worker/src/temporal-runtime.ts:191

Type Parameters

Type ParameterDefault type
C extends ContractDefinition-
Unit extends AnyUnitModule | undefinedundefined

WorkflowActivitiesPortOf

ts
type WorkflowActivitiesPortOf<C, K> = PortClassOf<`${typeof WORKFLOW_ACTIVITIES_PREFIX}${K}`, ActivitiesRecordOf<C>[K]>;

Defined in: packages/temporal-worker/src/workflow-activities.ts:95

The port one piece targets. Its id carries the key, which is what makes two slices claiming one workflow di's duplicate-provider defect rather than a silent merge.

Type Parameters

Type Parameter
C extends ContractDefinition
K extends ActivitiesKeyOf<C>

WorkflowSource

ts
type WorkflowSource = 
  | {
  workflowsPath: string;
}
  | {
  workflowBundle: WorkflowBundleWithSourceMap;
};

Defined in: packages/temporal-worker/src/temporal-runtime.ts:54

Where the workflow sandbox's code comes from. Two arms because the two callers genuinely differ: a process points at the module and lets Temporal bundle it, while a spec hands over a bundle it built and memoised once — bundling per test is the most expensive thing a suite does.

Functions

ActivityInput()

ts
function ActivityInput<C>(contract): ActivityInputPortOf<C>;

Defined in: packages/temporal-worker/src/workflow-activities.ts:80

The validated activity input as a port: the one thing the worker seeds the fork with, so a unit.activity module derives a tenant — or anything else — from the invocation rather than from an ambient record.

ts
const Input = ActivityInput(orderContract);
const ActivityUnit = Module("ActivityUnit")({
  needs: [Input],
  provides: [Provider(Tenant)({ inject: { input: Input }, sync: ({ input }) => input.tenantId })],
  exports: [Tenant],
});

contract is read for its TYPE only. One Port(...) call fixed per contract at the type level, the move TemporalActivitiesPort makes, so a module built for one contract cannot read another's input.

Type Parameters

Type Parameter
C extends ContractDefinition

Parameters

ParameterType
contractC

Returns

ActivityInputPortOf<C>


temporal()

ts
function temporal<C, Unit>(options): Module<Provided, ConfigInvalid | TemporalUnreachable, 
  | Env
  | Scope
  | ActivitiesInstanceOf<C>
  | UnitNeedsOf<Unit>>;

Defined in: packages/temporal-worker/src/temporal-runtime.ts:219

The Temporal starter: a module providing the runtime, its configuration (bound from the TEMPORAL_* variables unless pinned) and the connection (a resource opened with the scope and closed with it; a service that will not answer is a modeled TemporalUnreachable). Import it next to the application, export TemporalRuntime, provide the activities — the activities port is a need of this module.

Each configuration field is pinned on its own: a pinned field reads nothing from the environment, and a field left unpinned still does.

Type Parameters

Type ParameterDefault type
C extends ContractDefinition-
Unit extends AnyUnitModule | undefinedundefined

Parameters

ParameterType
optionsTemporalOptions<C, Unit>

Returns

Module<Provided, ConfigInvalid | TemporalUnreachable, | Env | Scope | ActivitiesInstanceOf<C> | UnitNeedsOf<Unit>>


TemporalActivities()

ts
function TemporalActivities<C>(contract): Whole<C> & Compose<C>;

Defined in: packages/temporal-worker/src/temporal-module.ts:274

The activities as a provider, from the contract. Two call forms, one port.

ts
TemporalActivities(orderContract)({ inject: { place: PlaceOrder }, sync: ({ place }) => ({ fulfillOrder: { … } }) })
TemporalActivities(orderContract)([fulfillOrder, chargeOrder])

The first is { inject, unit?, sync }, whose sync hands back the whole activities record — one unit: record for every entry in it. The second takes the pieces TemporalWorkflowActivities(contract, key) builds: they are the provider's deps, keyed by the contract key each piece's port id carries, so the services record IS the activities record. Every key must be covered, and two slices claiming one key are di's duplicate-provider defect at build.

Type Parameters

Type Parameter
C extends ContractDefinition

Parameters

ParameterType
contractC

Returns

Whole<C> & Compose<C>


TemporalModule()

ts
function TemporalModule<Name>(name): <C, ActivitiesError, ActivitiesNeeds, Declared, Unit, I, P, X, N>(options) => Module<ResolvedExports<readonly [typeof TemporalRuntime, X]>, 
  | ErrOf<readonly [Provider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>, P][number]>
  | ErrOfModule<readonly [I, TemporalStarter<C, Unit>][number]>, 
  | Exclude<NeedOf<readonly [Provider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>, P][number]>, Available<readonly [I, TemporalStarter<C, Unit>], readonly [Provider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>, P]>>
  | Exclude<NeedsOfModule<readonly [I, TemporalStarter<C, Unit>][number]>, Available<readonly [I, TemporalStarter<C, Unit>], readonly [Provider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>, P]>>>;

Defined in: packages/temporal-worker/src/temporal-module.ts:119

Module(name)({...}) for a Temporal worker deployment: everything a di module takes, plus the contract, the activities provider and the workflow source. The sugar imports the starter, provides the activities and exports TemporalRuntime, handing back exactly the module Module(...) would have declared over the augmented tuples.

ts
export const OrderTemporalWorker = TemporalModule("OrderTemporalWorker")({
  contract: orderContract,
  activities: orderActivities,
  workflows: { workflowsPath: workflowsPathFromURL(import.meta.url, "./workflows.js") },
  imports: [OrderApplicationModule, OrderPersistenceModule, FulfillmentModule],
});
await runMain(OrderTemporalWorker);

Type Parameters

Type Parameter
Name extends string

Parameters

ParameterType
nameName

Returns

<C, ActivitiesError, ActivitiesNeeds, Declared, Unit, I, P, X, N>(options) => Module<ResolvedExports<readonly [typeof TemporalRuntime, X]>, | ErrOf<readonly [Provider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>, P][number]> | ErrOfModule<readonly [I, TemporalStarter<C, Unit>][number]>, | Exclude<NeedOf<readonly [Provider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>, P][number]>, Available<readonly [I, TemporalStarter<C, Unit>], readonly [Provider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>, P]>> | Exclude<NeedsOfModule<readonly [I, TemporalStarter<C, Unit>][number]>, Available<readonly [I, TemporalStarter<C, Unit>], readonly [Provider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>, P]>>>


TemporalWorkflowActivities()

ts
function TemporalWorkflowActivities<C, K>(contract, key): <D, U>(options) => MintedActivities<C, K, InstanceType<D[keyof D]>, U>;

Defined in: packages/temporal-worker/src/workflow-activities.ts:142

One workflow's activities, as a provider on a port of its own.

A worker that polls one queue for several workflows is several pieces, each declaring the services its own activities call; TemporalActivities(contract)([...]) composes them. contract is read for its TYPE only, and types both key and the record — so an activity the workflow does not declare is a compile error here rather than at startup.

key is any top-level key of the activities record, which includes a contract-global activity as well as a workflow; the name is imprecise in that one case deliberately, since narrowing it would lock such a contract out of the split.

There is no name to give: the key IS the port's name.

unit declares the ports the activities read off context.unit, resolved out of the fork the attempt opened; the root's unit.activity module must export every one of them.

Type Parameters

Type Parameter
C extends ContractDefinition
K extends string

Parameters

ParameterType
contractC
keyK

Returns

<D, U>(options) => MintedActivities<C, K, InstanceType<D[keyof D]>, U>

Released under the MIT License.