@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
new TemporalConfig(): TemporalConfig;Defined in: packages/di/dist/index.d.mts:15
Returns
Inherited from
Port("TemporalConfig")<{
readonly address: string;
readonly namespace: string;
}>.constructorProperties
| Property | Modifier | Type | Inherited from | Defined in |
|---|---|---|---|---|
[ID] | readonly | "TemporalConfig" | Port("TemporalConfig").[ID] | packages/di/dist/index.d.mts:11 |
[SERVICE] | readonly | object | Port("TemporalConfig").[SERVICE] | packages/di/dist/index.d.mts:12 |
[SERVICE].address | readonly | string | - | packages/temporal/src/temporal-runtime.ts:59 |
[SERVICE].namespace | readonly | string | - | packages/temporal/src/temporal-runtime.ts:60 |
portId | readonly | "TemporalConfig" | Port("TemporalConfig").portId | packages/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
new TemporalConnection(): TemporalConnection;Defined in: packages/di/dist/index.d.mts:15
Returns
Inherited from
Port("TemporalConnection")<NativeConnection>.constructorProperties
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
RuntimePort<Runtime<never,TemporalInfo>>
Constructors
Constructor
new TemporalRuntime(): TemporalRuntime;Defined in: packages/di/dist/index.d.mts:15
Returns
Inherited from
RuntimePort<Runtime<never, TemporalInfo>>.constructorProperties
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
new TemporalUnreachable(args): TemporalUnreachable;Defined in: node_modules/.pnpm/unthrown@5.5.0/node_modules/unthrown/dist/index.d.mts:2034
Parameters
| Parameter | Type |
|---|---|
args | object & object |
Returns
Inherited from
TaggedError("TemporalUnreachable")<{
readonly address: string;
readonly cause: unknown;
}>.constructorProperties
| Property | Modifier | Type | Overrides | Inherited from | Defined in |
|---|---|---|---|---|---|
_tag | readonly | "TemporalUnreachable" | - | TaggedError("TemporalUnreachable")._tag | node_modules/.pnpm/unthrown@5.5.0/node_modules/unthrown/dist/index.d.mts:2011 |
address | readonly | string | - | TaggedError("TemporalUnreachable").address | packages/temporal/src/temporal-runtime.ts:76 |
cause | public | unknown | - | TaggedError("TemporalUnreachable").cause | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24 |
message | public | string | TaggedError("TemporalUnreachable").message | - | packages/temporal/src/temporal-runtime.ts:79 |
name | public | string | - | TaggedError("TemporalUnreachable").name | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074 |
stack? | public | string | - | TaggedError("TemporalUnreachable").stack | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076 |
Type Aliases
ActivitiesInstanceOf
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
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
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
| Property | Modifier | Type | Defined in |
|---|---|---|---|
namespace | readonly | string | packages/temporal/src/temporal-runtime.ts:39 |
taskQueue | readonly | string | packages/temporal/src/temporal-runtime.ts:38 |
TemporalModuleOptions
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
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
activities | readonly | Provider<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? | readonly | string | Pins TemporalConfig.address instead of reading TEMPORAL_ADDRESS. | packages/temporal/src/temporal-module.ts:65 |
contract | readonly | C | The temporal-contract contract; the task queue this worker polls is read off it. | packages/temporal/src/temporal-module.ts:60 |
exports? | readonly | X | The application's own exports; TemporalRuntime is added, since start resolves it. | packages/temporal/src/temporal-module.ts:75 |
forceAfter? | readonly | Duration | Temporal's shutdownForceTime. Default 15 seconds. Keep it at or below the kernel's drainTimeoutMs. | packages/temporal/src/temporal-module.ts:71 |
gracePeriod? | readonly | Duration | Temporal's shutdownGraceTime. Default 10 seconds. | packages/temporal/src/temporal-module.ts:69 |
imports? | readonly | I | - | packages/temporal/src/temporal-module.ts:72 |
namespace? | readonly | string | Pins TemporalConfig.namespace instead of reading TEMPORAL_NAMESPACE. | packages/temporal/src/temporal-module.ts:67 |
provides? | readonly | P | - | packages/temporal/src/temporal-module.ts:73 |
workflows | readonly | WorkflowSource | - | packages/temporal/src/temporal-module.ts:63 |
TemporalOptions
type TemporalOptions<C> = object;Defined in: packages/temporal/src/temporal-runtime.ts:115
Type Parameters
| Type Parameter |
|---|
C extends ContractDefinition |
Properties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
address? | readonly | string | Pins TemporalConfig.address instead of reading TEMPORAL_ADDRESS. | packages/temporal/src/temporal-runtime.ts:127 |
contract | readonly | C | The 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? | readonly | Duration | Temporal's shutdownForceTime. Default 15 seconds. Keep it at or below the kernel's drainTimeoutMs. | packages/temporal/src/temporal-runtime.ts:131 |
gracePeriod? | readonly | Duration | Temporal's shutdownGraceTime. Default 10 seconds. | packages/temporal/src/temporal-runtime.ts:133 |
namespace? | readonly | string | Pins TemporalConfig.namespace instead of reading TEMPORAL_NAMESPACE. | packages/temporal/src/temporal-runtime.ts:129 |
workflows | readonly | WorkflowSource | - | packages/temporal/src/temporal-runtime.ts:125 |
WorkflowActivitiesPortOf
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
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()
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
| Parameter | Type |
|---|---|
options | TemporalOptions<C> |
Returns
Module<Provided, ConfigInvalid | TemporalUnreachable, Env | Scope | ActivitiesInstanceOf<C>>
TemporalActivities()
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.
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
| Parameter | Type |
|---|---|
contract | C |
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()
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.
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
| Parameter | Type |
|---|---|
name | Name |
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()
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
| Parameter | Type |
|---|---|
contract | C |
key | K |
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; }