@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 +23 -25
- package/dist/index.cjs +22 -15
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +22 -15
- package/package.json +15 -15
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
|
-
|
|
81
|
-
|
|
82
|
-
place
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
.
|
|
94
|
-
|
|
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)({
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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.
|
|
244
|
+
* The activities as a provider, from the contract. Two call forms, one port.
|
|
241
245
|
*
|
|
242
246
|
* ```ts
|
|
243
|
-
* TemporalActivities(orderContract)({ place: PlaceOrder },
|
|
247
|
+
* TemporalActivities(orderContract)({ inject: { place: PlaceOrder }, sync: ({ place }) => ({ fulfillOrder: { … } }) })
|
|
244
248
|
* TemporalActivities(orderContract)([fulfillOrder, chargeOrder])
|
|
245
249
|
* ```
|
|
246
250
|
*
|
|
247
|
-
* The first
|
|
248
|
-
* typed for the contract. The
|
|
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(
|
|
257
|
-
|
|
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.
|
|
216
|
+
* The activities as a provider, from the contract. Two call forms, one port.
|
|
217
217
|
*
|
|
218
218
|
* ```ts
|
|
219
|
-
* TemporalActivities(orderContract)({ place: PlaceOrder },
|
|
219
|
+
* TemporalActivities(orderContract)({ inject: { place: PlaceOrder }, sync: ({ place }) => ({ fulfillOrder: { … } }) })
|
|
220
220
|
* TemporalActivities(orderContract)([fulfillOrder, chargeOrder])
|
|
221
221
|
* ```
|
|
222
222
|
*
|
|
223
|
-
* The first
|
|
224
|
-
* typed for the contract. The
|
|
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.
|
|
216
|
+
* The activities as a provider, from the contract. Two call forms, one port.
|
|
217
217
|
*
|
|
218
218
|
* ```ts
|
|
219
|
-
* TemporalActivities(orderContract)({ place: PlaceOrder },
|
|
219
|
+
* TemporalActivities(orderContract)({ inject: { place: PlaceOrder }, sync: ({ place }) => ({ fulfillOrder: { … } }) })
|
|
220
220
|
* TemporalActivities(orderContract)([fulfillOrder, chargeOrder])
|
|
221
221
|
* ```
|
|
222
222
|
*
|
|
223
|
-
* The first
|
|
224
|
-
* typed for the contract. The
|
|
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)({
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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.
|
|
243
|
+
* The activities as a provider, from the contract. Two call forms, one port.
|
|
240
244
|
*
|
|
241
245
|
* ```ts
|
|
242
|
-
* TemporalActivities(orderContract)({ place: PlaceOrder },
|
|
246
|
+
* TemporalActivities(orderContract)({ inject: { place: PlaceOrder }, sync: ({ place }) => ({ fulfillOrder: { … } }) })
|
|
243
247
|
* TemporalActivities(orderContract)([fulfillOrder, chargeOrder])
|
|
244
248
|
* ```
|
|
245
249
|
*
|
|
246
|
-
* The first
|
|
247
|
-
* typed for the contract. The
|
|
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(
|
|
256
|
-
|
|
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.
|
|
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.
|
|
51
|
-
"@temporalio/client": "1.
|
|
52
|
-
"@temporalio/common": "1.
|
|
53
|
-
"@temporalio/worker": "1.
|
|
54
|
-
"@temporalio/workflow": "1.
|
|
55
|
-
"@types/node": "26.
|
|
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.
|
|
63
|
-
"@btravstack/config": "0.
|
|
64
|
-
"@btravstack/core": "0.
|
|
65
|
-
"@btravstack/di": "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.
|
|
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.
|
|
77
|
-
"@btravstack/core": "^0.
|
|
78
|
-
"@btravstack/di": "^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"
|