@btravstack/temporal-worker 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -74,30 +74,28 @@ import { P } from "unthrown";
74
74
  // cases it declares — closures over them, no context read at call time — on
75
75
  // the starter's own activities port, typed by the contract (a worker serves
76
76
  // one activities record, so there is nothing to name).
77
- const orderActivities = TemporalActivities(contract)(
78
- { place: PlaceOrder },
79
- {
80
- sync: ({ place }) => ({
81
- placeOrder: {
82
- place: (args, { errors }) =>
83
- place
84
- .execute(TenantId(args.tenantId), args.orderId, args.quantity)
85
- .mapErrCases((matcher) =>
86
- matcher
87
- .with(P.tag("DuplicateOrder"), (error) =>
88
- errors.OrderAlreadyPlaced({ id: error.id }),
89
- )
90
- .with(P.tag("InvalidOrderId"), (error) =>
91
- errors.InvalidOrderId({ id: error.id }),
92
- )
93
- .with(P.tag("InvalidQuantity"), (error) =>
94
- errors.InvalidQuantity({ id: error.id }),
95
- ),
96
- ),
97
- },
98
- }),
99
- },
100
- );
77
+ const orderActivities = TemporalActivities(contract)({
78
+ inject: { place: PlaceOrder },
79
+ sync: ({ place }) => ({
80
+ placeOrder: {
81
+ place: (args, { errors }) =>
82
+ place
83
+ .execute(TenantId(args.tenantId), args.orderId, args.quantity)
84
+ .mapErrCases((matcher) =>
85
+ matcher
86
+ .with(P.tag("DuplicateOrder"), (error) =>
87
+ errors.OrderAlreadyPlaced({ id: error.id }),
88
+ )
89
+ .with(P.tag("InvalidOrderId"), (error) =>
90
+ errors.InvalidOrderId({ id: error.id }),
91
+ )
92
+ .with(P.tag("InvalidQuantity"), (error) =>
93
+ errors.InvalidQuantity({ id: error.id }),
94
+ ),
95
+ ),
96
+ },
97
+ }),
98
+ });
101
99
 
102
100
  // The composition root: a di module, plus the contract, the activities
103
101
  // provider and the workflow source — and nothing else to know.
@@ -124,7 +122,7 @@ startup `Err`, not a defect. `runtimeInfo()` reads `{ taskQueue, namespace }`
124
122
  back once the worker is polling.
125
123
 
126
124
  A worker polling for several workflows can be several slices instead of one
127
- record: `TemporalWorkflowActivities(contract, key)({ name: Dep }, arm)` mints a
125
+ record: `TemporalWorkflowActivities(contract, key)({ inject: { name: Dep }, ...arm })` mints a
128
126
  provider for ONE workflow's activities (or a contract-global activity),
129
127
  typed by the key alone, and `TemporalActivities(contract)([...])` composes an
130
128
  array of them into the same activities provider `TemporalModule` takes — the
package/dist/index.cjs CHANGED
@@ -111,7 +111,8 @@ const temporal = (options) => {
111
111
  needs: [_btravstack_config.Env, activities],
112
112
  provides: [
113
113
  config,
114
- (0, _btravstack_di.Provider)(TemporalConnection)({ config: TemporalConfig }, {
114
+ (0, _btravstack_di.Provider)(TemporalConnection)({
115
+ inject: { config: TemporalConfig },
115
116
  acquire: ({ config: bound }) => (0, unthrown.fromPromise)(_temporalio_worker.NativeConnection.connect({ address: bound.address }), (cause) => new TemporalUnreachable({
116
117
  address: bound.address,
117
118
  cause
@@ -119,14 +120,17 @@ const temporal = (options) => {
119
120
  release: (connection) => connection.close().catch((cause) => heldByWorker(cause) ? void 0 : Promise.reject(cause))
120
121
  }),
121
122
  (0, _btravstack_di.Provider)(TemporalRuntime)({
122
- connection: TemporalConnection,
123
- config: TemporalConfig,
124
- activities
125
- }, { sync: ({ connection, config: bound, activities: impls }) => ({
126
- name: "temporal",
127
- resolves: [],
128
- start: (host) => createWorker(host, connection, bound, impls, options)
129
- }) })
123
+ inject: {
124
+ connection: TemporalConnection,
125
+ config: TemporalConfig,
126
+ activities
127
+ },
128
+ sync: ({ connection, config: bound, activities: impls }) => ({
129
+ name: "temporal",
130
+ resolves: [],
131
+ start: (host) => createWorker(host, connection, bound, impls, options)
132
+ })
133
+ })
130
134
  ],
131
135
  exports: [
132
136
  TemporalRuntime,
@@ -237,15 +241,15 @@ const TemporalModule = (name) => (options) => {
237
241
  });
238
242
  };
239
243
  /**
240
- * The activities as a provider, from the contract. Three call forms, one port.
244
+ * The activities as a provider, from the contract. Two call forms, one port.
241
245
  *
242
246
  * ```ts
243
- * TemporalActivities(orderContract)({ place: PlaceOrder }, { sync: ({ place }) => ({ fulfillOrder: { … } }) })
247
+ * TemporalActivities(orderContract)({ inject: { place: PlaceOrder }, sync: ({ place }) => ({ fulfillOrder: { … } }) })
244
248
  * TemporalActivities(orderContract)([fulfillOrder, chargeOrder])
245
249
  * ```
246
250
  *
247
- * The first two are di's own `Provider(port)` on the starter's activities port
248
- * typed for the contract. The third takes the pieces
251
+ * The first is di's own `Provider(port)` on the starter's activities port
252
+ * typed for the contract. The second takes the pieces
249
253
  * `TemporalWorkflowActivities(contract, key)` builds: they are the provider's
250
254
  * deps, keyed by the contract key each piece's port id carries, so the services
251
255
  * record IS the activities record. Every key must be covered, and two slices
@@ -253,8 +257,11 @@ const TemporalModule = (name) => (options) => {
253
257
  */
254
258
  const TemporalActivities = (contract) => {
255
259
  const build = (0, _btravstack_di.Provider)(TemporalActivitiesPort);
256
- const compose = (pieces) => build(Object.fromEntries(pieces.map((piece) => [piece.port.portId.slice(27), piece.port])), { sync: (services) => services });
257
- return ((first, second) => second === void 0 && Array.isArray(first) ? compose(first) : build(first, second));
260
+ const compose = (pieces) => build({
261
+ inject: Object.fromEntries(pieces.map((piece) => [piece.port.portId.slice(27), piece.port])),
262
+ sync: (services) => services
263
+ });
264
+ return ((first) => Array.isArray(first) ? compose(first) : build(first));
258
265
  };
259
266
  //#endregion
260
267
  exports.TemporalActivities = TemporalActivities;
package/dist/index.d.cts CHANGED
@@ -213,15 +213,15 @@ type Compose<C extends ContractDefinition> = <const T extends readonly PieceOf<C
213
213
  readonly port: ActivitiesPortOf<C>;
214
214
  };
215
215
  /**
216
- * The activities as a provider, from the contract. Three call forms, one port.
216
+ * The activities as a provider, from the contract. Two call forms, one port.
217
217
  *
218
218
  * ```ts
219
- * TemporalActivities(orderContract)({ place: PlaceOrder }, { sync: ({ place }) => ({ fulfillOrder: { … } }) })
219
+ * TemporalActivities(orderContract)({ inject: { place: PlaceOrder }, sync: ({ place }) => ({ fulfillOrder: { … } }) })
220
220
  * TemporalActivities(orderContract)([fulfillOrder, chargeOrder])
221
221
  * ```
222
222
  *
223
- * The first two are di's own `Provider(port)` on the starter's activities port
224
- * typed for the contract. The third takes the pieces
223
+ * The first is di's own `Provider(port)` on the starter's activities port
224
+ * typed for the contract. The second takes the pieces
225
225
  * `TemporalWorkflowActivities(contract, key)` builds: they are the provider's
226
226
  * deps, keyed by the contract key each piece's port id carries, so the services
227
227
  * record IS the activities record. Every key must be covered, and two slices
package/dist/index.d.mts CHANGED
@@ -213,15 +213,15 @@ type Compose<C extends ContractDefinition> = <const T extends readonly PieceOf<C
213
213
  readonly port: ActivitiesPortOf<C>;
214
214
  };
215
215
  /**
216
- * The activities as a provider, from the contract. Three call forms, one port.
216
+ * The activities as a provider, from the contract. Two call forms, one port.
217
217
  *
218
218
  * ```ts
219
- * TemporalActivities(orderContract)({ place: PlaceOrder }, { sync: ({ place }) => ({ fulfillOrder: { … } }) })
219
+ * TemporalActivities(orderContract)({ inject: { place: PlaceOrder }, sync: ({ place }) => ({ fulfillOrder: { … } }) })
220
220
  * TemporalActivities(orderContract)([fulfillOrder, chargeOrder])
221
221
  * ```
222
222
  *
223
- * The first two are di's own `Provider(port)` on the starter's activities port
224
- * typed for the contract. The third takes the pieces
223
+ * The first is di's own `Provider(port)` on the starter's activities port
224
+ * typed for the contract. The second takes the pieces
225
225
  * `TemporalWorkflowActivities(contract, key)` builds: they are the provider's
226
226
  * deps, keyed by the contract key each piece's port id carries, so the services
227
227
  * record IS the activities record. Every key must be covered, and two slices
package/dist/index.mjs CHANGED
@@ -110,7 +110,8 @@ const temporal = (options) => {
110
110
  needs: [Env, activities],
111
111
  provides: [
112
112
  config,
113
- Provider(TemporalConnection)({ config: TemporalConfig }, {
113
+ Provider(TemporalConnection)({
114
+ inject: { config: TemporalConfig },
114
115
  acquire: ({ config: bound }) => fromPromise(NativeConnection.connect({ address: bound.address }), (cause) => new TemporalUnreachable({
115
116
  address: bound.address,
116
117
  cause
@@ -118,14 +119,17 @@ const temporal = (options) => {
118
119
  release: (connection) => connection.close().catch((cause) => heldByWorker(cause) ? void 0 : Promise.reject(cause))
119
120
  }),
120
121
  Provider(TemporalRuntime)({
121
- connection: TemporalConnection,
122
- config: TemporalConfig,
123
- activities
124
- }, { sync: ({ connection, config: bound, activities: impls }) => ({
125
- name: "temporal",
126
- resolves: [],
127
- start: (host) => createWorker(host, connection, bound, impls, options)
128
- }) })
122
+ inject: {
123
+ connection: TemporalConnection,
124
+ config: TemporalConfig,
125
+ activities
126
+ },
127
+ sync: ({ connection, config: bound, activities: impls }) => ({
128
+ name: "temporal",
129
+ resolves: [],
130
+ start: (host) => createWorker(host, connection, bound, impls, options)
131
+ })
132
+ })
129
133
  ],
130
134
  exports: [
131
135
  TemporalRuntime,
@@ -236,15 +240,15 @@ const TemporalModule = (name) => (options) => {
236
240
  });
237
241
  };
238
242
  /**
239
- * The activities as a provider, from the contract. Three call forms, one port.
243
+ * The activities as a provider, from the contract. Two call forms, one port.
240
244
  *
241
245
  * ```ts
242
- * TemporalActivities(orderContract)({ place: PlaceOrder }, { sync: ({ place }) => ({ fulfillOrder: { … } }) })
246
+ * TemporalActivities(orderContract)({ inject: { place: PlaceOrder }, sync: ({ place }) => ({ fulfillOrder: { … } }) })
243
247
  * TemporalActivities(orderContract)([fulfillOrder, chargeOrder])
244
248
  * ```
245
249
  *
246
- * The first two are di's own `Provider(port)` on the starter's activities port
247
- * typed for the contract. The third takes the pieces
250
+ * The first is di's own `Provider(port)` on the starter's activities port
251
+ * typed for the contract. The second takes the pieces
248
252
  * `TemporalWorkflowActivities(contract, key)` builds: they are the provider's
249
253
  * deps, keyed by the contract key each piece's port id carries, so the services
250
254
  * record IS the activities record. Every key must be covered, and two slices
@@ -252,8 +256,11 @@ const TemporalModule = (name) => (options) => {
252
256
  */
253
257
  const TemporalActivities = (contract) => {
254
258
  const build = Provider(TemporalActivitiesPort);
255
- const compose = (pieces) => build(Object.fromEntries(pieces.map((piece) => [piece.port.portId.slice(27), piece.port])), { sync: (services) => services });
256
- return ((first, second) => second === void 0 && Array.isArray(first) ? compose(first) : build(first, second));
259
+ const compose = (pieces) => build({
260
+ inject: Object.fromEntries(pieces.map((piece) => [piece.port.portId.slice(27), piece.port])),
261
+ sync: (services) => services
262
+ });
263
+ return ((first) => Array.isArray(first) ? compose(first) : build(first));
257
264
  };
258
265
  //#endregion
259
266
  export { TemporalActivities, TemporalConfig, TemporalConnection, TemporalModule, TemporalRuntime, TemporalUnreachable, TemporalWorkflowActivities, temporal };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btravstack/temporal-worker",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "The Temporal worker runtime for @btravstack/core: one unit per activity attempt, and a drain that honours the kernel's deadline",
5
5
  "keywords": [
6
6
  "graceful-shutdown",
@@ -47,24 +47,24 @@
47
47
  "@btravstack/tsconfig": "0.2.0",
48
48
  "@temporal-contract/contract": "8.0.0-beta.5",
49
49
  "@temporal-contract/worker": "8.0.0-beta.5",
50
- "@temporalio/activity": "1.22.0",
51
- "@temporalio/client": "1.22.0",
52
- "@temporalio/common": "1.22.0",
53
- "@temporalio/worker": "1.22.0",
54
- "@temporalio/workflow": "1.22.0",
55
- "@types/node": "26.2.0",
50
+ "@temporalio/activity": "1.23.0",
51
+ "@temporalio/client": "1.23.0",
52
+ "@temporalio/common": "1.23.0",
53
+ "@temporalio/worker": "1.23.0",
54
+ "@temporalio/workflow": "1.23.0",
55
+ "@types/node": "26.4.0",
56
56
  "@unthrown/vitest": "5.7.0",
57
57
  "@vitest/coverage-v8": "4.1.11",
58
58
  "tsdown": "0.22.14",
59
59
  "typescript": "7.0.2",
60
60
  "unthrown": "5.7.0",
61
61
  "vitest": "4.1.11",
62
- "zod": "4.4.3",
63
- "@btravstack/config": "0.7.0",
64
- "@btravstack/core": "0.7.0",
65
- "@btravstack/di": "0.7.0",
62
+ "zod": "4.5.1",
63
+ "@btravstack/config": "0.9.0",
64
+ "@btravstack/core": "0.9.0",
65
+ "@btravstack/di": "0.9.0",
66
66
  "@btravstack/internal-test-infra": "0.0.0",
67
- "@btravstack/testing": "0.7.0"
67
+ "@btravstack/testing": "0.9.0"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "@temporal-contract/contract": "^8.0.0-beta",
@@ -73,9 +73,9 @@
73
73
  "@temporalio/common": "^1.22.0",
74
74
  "@temporalio/worker": "^1.22.0",
75
75
  "unthrown": "^5.0.0",
76
- "@btravstack/config": "^0.7.0",
77
- "@btravstack/core": "^0.7.0",
78
- "@btravstack/di": "^0.7.0"
76
+ "@btravstack/config": "^0.9.0",
77
+ "@btravstack/core": "^0.9.0",
78
+ "@btravstack/di": "^0.9.0"
79
79
  },
80
80
  "engines": {
81
81
  "node": ">=22"