Skip to content

@btravstack/temporal


@btravstack/temporal

Classes

TemporalConfig

Defined in: packages/temporal/src/temporal-runtime.ts:58

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

Extends

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

Constructors

Constructor
ts
new TemporalConfig(): TemporalConfig;

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

Returns

TemporalConfig

Inherited from
ts
Port("TemporalConfig")<{
  readonly address: string;
  readonly namespace: string;
}>.constructor

Properties

PropertyModifierTypeInherited fromDefined in
[ID]readonly"TemporalConfig"Port("TemporalConfig").[ID]packages/di/dist/index.d.mts:11
[SERVICE]readonlyobjectPort("TemporalConfig").[SERVICE]packages/di/dist/index.d.mts:12
[SERVICE].addressreadonlystring-packages/temporal/src/temporal-runtime.ts:59
[SERVICE].namespacereadonlystring-packages/temporal/src/temporal-runtime.ts:60
portIdreadonly"TemporalConfig"Port("TemporalConfig").portIdpackages/di/dist/index.d.mts:16

TemporalConnection

Defined in: packages/temporal/src/temporal-runtime.ts:67

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:15

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:11
[SERVICE]readonlyNativeConnectionPort("TemporalConnection").[SERVICE]packages/di/dist/index.d.mts:12
portIdreadonly"TemporalConnection"Port("TemporalConnection").portIdpackages/di/dist/index.d.mts:16

TemporalRuntime

Defined in: packages/temporal/src/temporal-runtime.ts:83

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:15

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:11
[SERVICE]readonlyRuntimeRuntimePort.[SERVICE]packages/di/dist/index.d.mts:12
portIdreadonly"Runtime"RuntimePort.portIdpackages/di/dist/index.d.mts:16

TemporalUnreachable

Defined in: packages/temporal/src/temporal-runtime.ts:75

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.5.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.5.0/node_modules/unthrown/dist/index.d.mts:2011
addressreadonlystring-TaggedError("TemporalUnreachable").addresspackages/temporal/src/temporal-runtime.ts:76
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/src/temporal-runtime.ts:79
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/src/temporal-runtime.ts:110

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/src/temporal-runtime.ts:104

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

Type Parameters

Type Parameter
C extends ContractDefinition

TemporalInfo

ts
type TemporalInfo = object;

Defined in: packages/temporal/src/temporal-runtime.ts:37

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

Properties

PropertyModifierTypeDefined in
namespacereadonlystringpackages/temporal/src/temporal-runtime.ts:39
taskQueuereadonlystringpackages/temporal/src/temporal-runtime.ts:38

TemporalModuleOptions

ts
type TemporalModuleOptions<C, ActivitiesError, ActivitiesNeeds, I, P, X> = object;

Defined in: packages/temporal/src/temporal-module.ts:51

Type Parameters

Type Parameter
C extends ContractDefinition
ActivitiesError
ActivitiesNeeds
I extends readonly AnyModule[]
P extends readonly AnyProvider[]
X extends readonly Exportable<Imports<I, C>, Provides<P, C, ActivitiesError, ActivitiesNeeds>>[]

Properties

PropertyModifierTypeDescriptionDefined in
activitiesreadonlyProvider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>The application's activity implementations — TemporalActivities(contract)(deps, arm), the provider that builds the record for THIS contract from the services it closes over.packages/temporal/src/temporal-module.ts:62
address?readonlystringPins TemporalConfig.address instead of reading TEMPORAL_ADDRESS.packages/temporal/src/temporal-module.ts:65
contractreadonlyCThe temporal-contract contract; the task queue this worker polls is read off it.packages/temporal/src/temporal-module.ts:60
exports?readonlyXThe application's own exports; TemporalRuntime is added, since start resolves it.packages/temporal/src/temporal-module.ts:75
forceAfter?readonlyDurationTemporal's shutdownForceTime. Default 15 seconds. Keep it at or below the kernel's drainTimeoutMs.packages/temporal/src/temporal-module.ts:71
gracePeriod?readonlyDurationTemporal's shutdownGraceTime. Default 10 seconds.packages/temporal/src/temporal-module.ts:69
imports?readonlyI-packages/temporal/src/temporal-module.ts:72
namespace?readonlystringPins TemporalConfig.namespace instead of reading TEMPORAL_NAMESPACE.packages/temporal/src/temporal-module.ts:67
provides?readonlyP-packages/temporal/src/temporal-module.ts:73
workflowsreadonlyWorkflowSource-packages/temporal/src/temporal-module.ts:63

TemporalOptions

ts
type TemporalOptions<C> = object;

Defined in: packages/temporal/src/temporal-runtime.ts:115

Type Parameters

Type Parameter
C extends ContractDefinition

Properties

PropertyModifierTypeDescriptionDefined in
address?readonlystringPins TemporalConfig.address instead of reading TEMPORAL_ADDRESS.packages/temporal/src/temporal-runtime.ts:127
contractreadonlyCThe temporal-contract contract; the task queue this worker polls is read off it, and the activities port is typed by it — the record declareActivitiesHandler takes for contract, which the composition root provides through TemporalActivities(contract)(deps, arm). The starter calls declareActivitiesHandler itself, with its unit middleware in place.packages/temporal/src/temporal-runtime.ts:124
forceAfter?readonlyDurationTemporal's shutdownForceTime. Default 15 seconds. Keep it at or below the kernel's drainTimeoutMs.packages/temporal/src/temporal-runtime.ts:131
gracePeriod?readonlyDurationTemporal's shutdownGraceTime. Default 10 seconds.packages/temporal/src/temporal-runtime.ts:133
namespace?readonlystringPins TemporalConfig.namespace instead of reading TEMPORAL_NAMESPACE.packages/temporal/src/temporal-runtime.ts:129
workflowsreadonlyWorkflowSource-packages/temporal/src/temporal-runtime.ts:125

WorkflowActivitiesPortOf

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

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

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/src/temporal-runtime.ts:48

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

temporal()

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

Defined in: packages/temporal/src/temporal-runtime.ts:158

The Temporal starter: a module providing the runtime (TemporalRuntime), its configuration (TemporalConfig, bound from TEMPORAL_ADDRESS / TEMPORAL_NAMESPACE unless pinned here) and the connection (TemporalConnection, 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, and provide the activities (TemporalActivities(contract)(deps, arm)) — that is the whole of the transport wiring. The activities port is a need of this module, so a composition root that forgets to provide it fails at Module(...), di's own gate.

With both configuration fields pinned the module reads nothing from the environment (the declared Env need and ConfigInvalid stay — the kernel discharges the one, a pinned config never produces the other); pin only one and the other still comes from the environment.

Type Parameters

Type Parameter
C extends ContractDefinition

Parameters

ParameterType
optionsTemporalOptions<C>

Returns

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


TemporalActivities()

ts
function TemporalActivities<C>(contract): {
<D, O>  (deps, options): Provider<PortInstance<"TemporalActivities", NoInfer<ContractResultActivitiesImplementations<C, EmptyContext>>>, ErrorOf<O>, InstanceType<D[number]> | ScopeOf<O>> & object;
<O>  (options): Provider<PortInstance<"TemporalActivities", NoInfer<ContractResultActivitiesImplementations<C, EmptyContext>>>, ErrorOf<O>, ScopeOf<O>> & object;
} & Compose<C>;

Defined in: packages/temporal/src/temporal-module.ts:187

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

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

The first two are di's own Provider(port) on the starter's activities port typed for the contract — any arm, same typing. The third takes the piecesTemporalWorkflowActivities(contract, key) builds, one per top-level key of the record: di constructs every piece first (they are the provider's deps, in array order) and this reassembles the record from them. Every key must be covered, and two slices claiming one key are two providers for one port — di's duplicate-provider defect at build, which is the point.

Type Parameters

Type Parameter
C extends ContractDefinition

Parameters

ParameterType
contractC

Returns

{ <D, O> (deps, options): Provider<PortInstance<"TemporalActivities", NoInfer<ContractResultActivitiesImplementations<C, EmptyContext>>>, ErrorOf<O>, InstanceType<D[number]> | ScopeOf<O>> & object; <O> (options): Provider<PortInstance<"TemporalActivities", NoInfer<ContractResultActivitiesImplementations<C, EmptyContext>>>, ErrorOf<O>, ScopeOf<O>> & object; } & Compose<C>


TemporalModule()

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

Defined in: packages/temporal/src/temporal-module.ts:101

Module(name)({...}) for a Temporal worker deployment: everything a di module takes, plus the contract, the activities provider and the workflow source, and nothing else to know. The sugar imports the starter (temporal({ contract, workflows })), provides the activities, and exports TemporalRuntime — so a root that would otherwise write those lines and remember that start needs the runtime exported writes none of them. It hands back exactly the module Module(...) would have declared over the augmented imports/provides/exports (spelled from di's own pieces), so the kernel, start's gate and di's see nothing new: syntax over the same primitives, one source of truth.

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, I, P, X>(options) => Module<ResolvedExports<readonly [typeof TemporalRuntime, X]>, | ErrOf<readonly [Provider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>, P][number]> | ErrOfModule<readonly [I, TemporalStarter<C>][number]>, | Exclude<NeedOf<readonly [Provider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>, P][number]>, Available<readonly [I, TemporalStarter<C>], readonly [Provider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>, P]>> | Exclude<NeedsOfModule<readonly [I, TemporalStarter<C>][number]>, Available<readonly [I, TemporalStarter<C>], readonly [Provider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>, P]>>>


TemporalWorkflowActivities()

ts
function TemporalWorkflowActivities<C, K>(contract, key): {
<D, O>  (deps, options): Provider<PortInstance<`TemporalWorkflowActivities:${K}`, ActivitiesRecordOf<C>[K]>, ErrorOf<O>, InstanceType<D[number]> | ScopeOf<O>> & object;
<O>  (options): Provider<PortInstance<`TemporalWorkflowActivities:${K}`, ActivitiesRecordOf<C>[K]>, ErrorOf<O>, ScopeOf<O>> & object;
};

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

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 — it is what types key and the record, so an activity the workflow does not declare, or one whose input has drifted, 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: narrowing to workflow keys would cost extra type code and lock a contract with global activities out of the split.

There is no name to give: the key IS the port's name. The return is di's own Provider(port), so every arm is available exactly as on TemporalActivities(contract).

Type Parameters

Type Parameter
C extends ContractDefinition
K extends string

Parameters

ParameterType
contractC
keyK

Returns

{ <D, O> (deps, options): Provider<PortInstance<`TemporalWorkflowActivities:${K}`, ActivitiesRecordOf<C>[K]>, ErrorOf<O>, InstanceType<D[number]> | ScopeOf<O>> & object; <O> (options): Provider<PortInstance<`TemporalWorkflowActivities:${K}`, ActivitiesRecordOf<C>[K]>, ErrorOf<O>, ScopeOf<O>> & object; }

Released under the MIT License.