@rotorsoft/act 0.29.1 → 0.30.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/dist/.tsbuildinfo +1 -1
- package/dist/@types/act.d.ts +14 -11
- package/dist/@types/act.d.ts.map +1 -1
- package/dist/index.cjs +29 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1105,24 +1105,22 @@ var Act = class {
|
|
|
1105
1105
|
* }
|
|
1106
1106
|
* ```
|
|
1107
1107
|
*
|
|
1108
|
-
* @example Reaction triggering another action
|
|
1108
|
+
* @example Reaction triggering another action (reactingTo auto-injected)
|
|
1109
1109
|
* ```typescript
|
|
1110
1110
|
* const app = act()
|
|
1111
1111
|
* .withState(Order)
|
|
1112
1112
|
* .withState(Inventory)
|
|
1113
1113
|
* .on("OrderPlaced")
|
|
1114
|
-
* .do(async (event,
|
|
1115
|
-
* //
|
|
1116
|
-
*
|
|
1114
|
+
* .do(async function reduceInventory(event, _stream, app) {
|
|
1115
|
+
* // Inside reaction handlers, reactingTo is auto-injected when omitted.
|
|
1116
|
+
* // The triggering event is used by default, maintaining the correlation chain.
|
|
1117
|
+
* await app.do(
|
|
1117
1118
|
* "reduceStock",
|
|
1118
|
-
* {
|
|
1119
|
-
*
|
|
1120
|
-
* actor: event.meta.causation.action.actor
|
|
1121
|
-
* },
|
|
1122
|
-
* { amount: event.data.items.length },
|
|
1123
|
-
* event // Pass event for correlation tracking
|
|
1119
|
+
* { stream: "inventory-1", actor: { id: "sys", name: "system" } },
|
|
1120
|
+
* { amount: event.data.items.length }
|
|
1124
1121
|
* );
|
|
1125
|
-
*
|
|
1122
|
+
* // To use a different correlation, pass reactingTo explicitly:
|
|
1123
|
+
* // await app.do("reduceStock", target, payload, customEvent);
|
|
1126
1124
|
* })
|
|
1127
1125
|
* .to("inventory-1")
|
|
1128
1126
|
* .build();
|
|
@@ -1258,6 +1256,11 @@ var Act = class {
|
|
|
1258
1256
|
* This is called by the main `drain` loop after fetching new events.
|
|
1259
1257
|
* It handles reactions, supporting retries, blocking, and error handling.
|
|
1260
1258
|
*
|
|
1259
|
+
* Each handler receives a scoped `IAct` proxy that auto-injects the
|
|
1260
|
+
* triggering event as `reactingTo` when `do()` is called without it,
|
|
1261
|
+
* maintaining correlation chains by default (#587). Handlers can still
|
|
1262
|
+
* pass an explicit `reactingTo` to override this behavior.
|
|
1263
|
+
*
|
|
1261
1264
|
* @internal
|
|
1262
1265
|
* @param lease The lease to handle
|
|
1263
1266
|
* @param payloads The reactions to handle
|
|
@@ -1268,10 +1271,24 @@ var Act = class {
|
|
|
1268
1271
|
const stream = lease.stream;
|
|
1269
1272
|
let at = payloads.at(0).event.id, handled = 0;
|
|
1270
1273
|
lease.retry > 0 && logger3.warn(`Retrying ${stream}@${at} (${lease.retry}).`);
|
|
1274
|
+
const doAction = this.do.bind(this);
|
|
1275
|
+
const scopedApp = {
|
|
1276
|
+
do: doAction,
|
|
1277
|
+
load: this.load.bind(this),
|
|
1278
|
+
query: this.query.bind(this),
|
|
1279
|
+
query_array: this.query_array.bind(this)
|
|
1280
|
+
};
|
|
1271
1281
|
for (const payload of payloads) {
|
|
1272
1282
|
const { event, handler, options } = payload;
|
|
1283
|
+
scopedApp.do = (action2, target, payload2, reactingTo, skipValidation) => doAction(
|
|
1284
|
+
action2,
|
|
1285
|
+
target,
|
|
1286
|
+
payload2,
|
|
1287
|
+
reactingTo ?? event,
|
|
1288
|
+
skipValidation
|
|
1289
|
+
);
|
|
1273
1290
|
try {
|
|
1274
|
-
await handler(event, stream,
|
|
1291
|
+
await handler(event, stream, scopedApp);
|
|
1275
1292
|
at = event.id;
|
|
1276
1293
|
handled++;
|
|
1277
1294
|
} catch (error) {
|