@rotorsoft/act 0.33.0 → 0.33.2
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 +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/act.d.ts +25 -31
- package/dist/@types/act.d.ts.map +1 -1
- package/dist/@types/adapters/console-logger.d.ts +2 -0
- package/dist/@types/adapters/console-logger.d.ts.map +1 -1
- package/dist/@types/adapters/in-memory-cache.d.ts +7 -1
- package/dist/@types/adapters/in-memory-cache.d.ts.map +1 -1
- package/dist/@types/builders/state-builder.d.ts +2 -2
- package/dist/@types/builders/state-builder.d.ts.map +1 -1
- package/dist/@types/config.d.ts +2 -1
- package/dist/@types/config.d.ts.map +1 -1
- package/dist/@types/internal/drain-cycle.d.ts.map +1 -1
- package/dist/@types/internal/event-sourcing.d.ts.map +1 -1
- package/dist/@types/internal/index.d.ts +2 -2
- package/dist/@types/internal/index.d.ts.map +1 -1
- package/dist/@types/ports.d.ts +6 -1
- package/dist/@types/ports.d.ts.map +1 -1
- package/dist/@types/types/action.d.ts +6 -6
- package/dist/@types/types/action.d.ts.map +1 -1
- package/dist/@types/types/errors.d.ts +19 -19
- package/dist/@types/types/errors.d.ts.map +1 -1
- package/dist/@types/types/ports.d.ts +11 -10
- package/dist/@types/types/ports.d.ts.map +1 -1
- package/dist/@types/types/registry.d.ts +13 -4
- package/dist/@types/types/registry.d.ts.map +1 -1
- package/dist/@types/types/schemas.d.ts +19 -19
- package/dist/@types/types/schemas.d.ts.map +1 -1
- package/dist/@types/utils.d.ts.map +1 -1
- package/dist/{chunk-IDEYGKT4.js → chunk-AWT7TU22.js} +9 -9
- package/dist/{chunk-IDEYGKT4.js.map → chunk-AWT7TU22.js.map} +1 -1
- package/dist/index.cjs +66 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +54 -41
- package/dist/index.js.map +1 -1
- package/dist/types/index.cjs +7 -7
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.js +1 -1
- package/package.json +7 -3
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
TargetSchema,
|
|
14
14
|
ValidationError,
|
|
15
15
|
ZodEmpty
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-AWT7TU22.js";
|
|
17
17
|
|
|
18
18
|
// src/adapters/console-logger.ts
|
|
19
19
|
var LEVEL_VALUES = {
|
|
@@ -67,8 +67,10 @@ var ConsoleLogger = class _ConsoleLogger {
|
|
|
67
67
|
this.debug = threshold <= 20 ? write.bind(this, "debug", 20) : noop;
|
|
68
68
|
this.trace = threshold <= 10 ? write.bind(this, "trace", 10) : noop;
|
|
69
69
|
}
|
|
70
|
+
/** No-op — `console.log` has no resources to release. */
|
|
70
71
|
async dispose() {
|
|
71
72
|
}
|
|
73
|
+
/** @inheritDoc */
|
|
72
74
|
child(bindings) {
|
|
73
75
|
return new _ConsoleLogger({
|
|
74
76
|
level: this.level,
|
|
@@ -193,28 +195,34 @@ var InMemoryCache = class {
|
|
|
193
195
|
constructor(options) {
|
|
194
196
|
this._entries = new LruMap(options?.maxSize ?? 1e3);
|
|
195
197
|
}
|
|
198
|
+
/** @inheritDoc */
|
|
196
199
|
async get(stream) {
|
|
197
200
|
return this._entries.get(stream);
|
|
198
201
|
}
|
|
202
|
+
/** @inheritDoc */
|
|
199
203
|
async set(stream, entry) {
|
|
200
204
|
this._entries.set(stream, entry);
|
|
201
205
|
}
|
|
206
|
+
/** @inheritDoc */
|
|
202
207
|
async invalidate(stream) {
|
|
203
208
|
this._entries.delete(stream);
|
|
204
209
|
}
|
|
210
|
+
/** @inheritDoc */
|
|
205
211
|
async clear() {
|
|
206
212
|
this._entries.clear();
|
|
207
213
|
}
|
|
214
|
+
/** @inheritDoc */
|
|
208
215
|
async dispose() {
|
|
209
216
|
this._entries.clear();
|
|
210
217
|
}
|
|
218
|
+
/** Current number of entries held by the LRU. */
|
|
211
219
|
get size() {
|
|
212
220
|
return this._entries.size;
|
|
213
221
|
}
|
|
214
222
|
};
|
|
215
223
|
|
|
216
224
|
// src/utils.ts
|
|
217
|
-
import {
|
|
225
|
+
import { prettifyError, ZodError } from "zod";
|
|
218
226
|
|
|
219
227
|
// src/config.ts
|
|
220
228
|
import * as fs from "fs";
|
|
@@ -738,7 +746,7 @@ var InMemoryStore = class {
|
|
|
738
746
|
var ExitCodes = ["ERROR", "EXIT"];
|
|
739
747
|
var adapters = /* @__PURE__ */ new Map();
|
|
740
748
|
function port(injector) {
|
|
741
|
-
return
|
|
749
|
+
return (adapter) => {
|
|
742
750
|
if (!adapters.has(injector.name)) {
|
|
743
751
|
const injected = injector(adapter);
|
|
744
752
|
adapters.set(injector.name, injected);
|
|
@@ -1530,8 +1538,8 @@ var block = (leases) => store().block(leases);
|
|
|
1530
1538
|
var subscribe = (streams) => store().subscribe(streams);
|
|
1531
1539
|
|
|
1532
1540
|
// src/internal/event-sourcing.ts
|
|
1533
|
-
import { patch } from "@rotorsoft/act-patch";
|
|
1534
1541
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
1542
|
+
import { patch } from "@rotorsoft/act-patch";
|
|
1535
1543
|
async function snap(snapshot) {
|
|
1536
1544
|
try {
|
|
1537
1545
|
const { id, stream, name, meta, version } = snapshot.event;
|
|
@@ -1591,7 +1599,7 @@ async function load(me, stream, callback, asOf) {
|
|
|
1591
1599
|
`Skipping unknown event "${String(e.name)}" on stream "${stream}" (id=${e.id}) \u2014 no reducer in state "${me.name}"`
|
|
1592
1600
|
);
|
|
1593
1601
|
}
|
|
1594
|
-
callback
|
|
1602
|
+
callback?.({
|
|
1595
1603
|
event,
|
|
1596
1604
|
state: state2,
|
|
1597
1605
|
version,
|
|
@@ -1607,6 +1615,15 @@ async function load(me, stream, callback, asOf) {
|
|
|
1607
1615
|
...cached ? { after: cached.event_id } : { with_snaps: true, ...asOf }
|
|
1608
1616
|
}
|
|
1609
1617
|
);
|
|
1618
|
+
if (replayed > 0 && !timeTravel && event) {
|
|
1619
|
+
await cache().set(stream, {
|
|
1620
|
+
state: state2,
|
|
1621
|
+
version,
|
|
1622
|
+
event_id: event.id,
|
|
1623
|
+
patches,
|
|
1624
|
+
snaps
|
|
1625
|
+
});
|
|
1626
|
+
}
|
|
1610
1627
|
return { event, state: state2, version, patches, snaps, cache_hit, replayed };
|
|
1611
1628
|
}
|
|
1612
1629
|
async function action(me, action2, target, payload, reactingTo, skipValidation = false) {
|
|
@@ -1691,7 +1708,7 @@ async function action(me, action2, target, payload, reactingTo, skipValidation =
|
|
|
1691
1708
|
};
|
|
1692
1709
|
});
|
|
1693
1710
|
const last = snapshots.at(-1);
|
|
1694
|
-
const snapped = me.snap
|
|
1711
|
+
const snapped = me.snap?.(last);
|
|
1695
1712
|
cache().set(stream, {
|
|
1696
1713
|
state: last.state,
|
|
1697
1714
|
version: last.event.version,
|
|
@@ -1872,6 +1889,17 @@ function buildDrain(logger) {
|
|
|
1872
1889
|
var DEFAULT_MAX_SUBSCRIBED_STREAMS = 1e3;
|
|
1873
1890
|
var DEFAULT_SETTLE_DEBOUNCE_MS = 10;
|
|
1874
1891
|
var Act = class {
|
|
1892
|
+
/**
|
|
1893
|
+
* Create a new Act orchestrator. Prefer the {@link act} builder over
|
|
1894
|
+
* direct construction — `act()...build()` wires the registry, merges
|
|
1895
|
+
* partial states, and collects batch handlers from registered slices
|
|
1896
|
+
* and projections in one pass.
|
|
1897
|
+
*
|
|
1898
|
+
* @param registry Schemas for every event and action across registered states
|
|
1899
|
+
* @param _states Merged map of state name → state definition
|
|
1900
|
+
* @param batchHandlers Static-target projection batch handlers (target → handler)
|
|
1901
|
+
* @param options Tuning knobs — see {@link ActOptions}
|
|
1902
|
+
*/
|
|
1875
1903
|
constructor(registry, _states = /* @__PURE__ */ new Map(), batchHandlers = /* @__PURE__ */ new Map(), options = {}) {
|
|
1876
1904
|
this.registry = registry;
|
|
1877
1905
|
this._states = _states;
|
|
@@ -1959,12 +1987,6 @@ var Act = class {
|
|
|
1959
1987
|
this._emitter.off(event, listener);
|
|
1960
1988
|
return this;
|
|
1961
1989
|
}
|
|
1962
|
-
/**
|
|
1963
|
-
* Create a new Act orchestrator.
|
|
1964
|
-
*
|
|
1965
|
-
* @param registry The registry of state, event, and action schemas
|
|
1966
|
-
* @param states Map of state names to their (potentially merged) state definitions
|
|
1967
|
-
*/
|
|
1968
1990
|
/** Batch handlers for static-target projections (target → handler) */
|
|
1969
1991
|
_batch_handlers;
|
|
1970
1992
|
/** Event-sourcing handlers, optionally wrapped with trace decorators */
|
|
@@ -2110,14 +2132,9 @@ var Act = class {
|
|
|
2110
2132
|
*
|
|
2111
2133
|
* For small result sets, consider using {@link query_array} instead.
|
|
2112
2134
|
*
|
|
2113
|
-
* @param query -
|
|
2114
|
-
*
|
|
2115
|
-
*
|
|
2116
|
-
* @param query.after - Filter events after this event ID
|
|
2117
|
-
* @param query.before - Filter events before this event ID
|
|
2118
|
-
* @param query.created_after - Filter events after this timestamp
|
|
2119
|
-
* @param query.created_before - Filter events before this timestamp
|
|
2120
|
-
* @param query.limit - Maximum number of events to return
|
|
2135
|
+
* @param query - Filter criteria — see {@link Query} for available fields
|
|
2136
|
+
* (`stream`, `name`, `after`, `before`, `created_after`, `created_before`,
|
|
2137
|
+
* `limit`, `with_snaps`, `stream_exact`)
|
|
2121
2138
|
* @param callback - Optional callback invoked for each matching event
|
|
2122
2139
|
* @returns Object with first event, last event, and total count
|
|
2123
2140
|
*
|
|
@@ -2153,11 +2170,12 @@ var Act = class {
|
|
|
2153
2170
|
* @see {@link query_array} for loading events into memory
|
|
2154
2171
|
*/
|
|
2155
2172
|
async query(query, callback) {
|
|
2156
|
-
let first
|
|
2173
|
+
let first;
|
|
2174
|
+
let last;
|
|
2157
2175
|
const count = await store().query((e) => {
|
|
2158
|
-
!first
|
|
2176
|
+
if (!first) first = e;
|
|
2159
2177
|
last = e;
|
|
2160
|
-
callback
|
|
2178
|
+
callback?.(e);
|
|
2161
2179
|
}, query);
|
|
2162
2180
|
return { first, last, count };
|
|
2163
2181
|
}
|
|
@@ -2208,10 +2226,8 @@ var Act = class {
|
|
|
2208
2226
|
* Call `correlate()` before `drain()` to discover target streams. For a higher-level
|
|
2209
2227
|
* API that handles debouncing, correlation, and signaling automatically, use {@link settle}.
|
|
2210
2228
|
*
|
|
2211
|
-
* @param options - Drain configuration
|
|
2212
|
-
*
|
|
2213
|
-
* @param options.eventLimit - Maximum events to fetch per stream (default: 10)
|
|
2214
|
-
* @param options.leaseMillis - Lease duration in milliseconds (default: 10000)
|
|
2229
|
+
* @param options - Drain configuration — see {@link DrainOptions} for fields
|
|
2230
|
+
* (`streamLimit`, `eventLimit`, `leaseMillis`).
|
|
2215
2231
|
* @returns Drain statistics with fetched, leased, acked, and blocked counts
|
|
2216
2232
|
*
|
|
2217
2233
|
* @example In tests and scripts
|
|
@@ -2246,8 +2262,8 @@ var Act = class {
|
|
|
2246
2262
|
* the next drain cycle.
|
|
2247
2263
|
*
|
|
2248
2264
|
* @param query - Query filter to scan for new correlations
|
|
2249
|
-
* @param query
|
|
2250
|
-
*
|
|
2265
|
+
* @param query - Scan filter — see {@link Query} for fields (typically
|
|
2266
|
+
* `{ after: <event-id>, limit: <count> }`)
|
|
2251
2267
|
* @returns Object with newly leased streams and last scanned event ID
|
|
2252
2268
|
*
|
|
2253
2269
|
* @example Manual correlation
|
|
@@ -2294,9 +2310,8 @@ var Act = class {
|
|
|
2294
2310
|
*
|
|
2295
2311
|
* **Note:** Only one correlation worker can run at a time per Act instance.
|
|
2296
2312
|
*
|
|
2297
|
-
* @param query - Query filter for correlation scans
|
|
2298
|
-
*
|
|
2299
|
-
* @param query.limit - Events to scan per cycle (default: 100)
|
|
2313
|
+
* @param query - Query filter for correlation scans — see {@link Query}
|
|
2314
|
+
* (typically `{ after: -1, limit: 100 }`)
|
|
2300
2315
|
* @param frequency - Correlation frequency in milliseconds (default: 10000)
|
|
2301
2316
|
* @param callback - Optional callback invoked with newly discovered streams
|
|
2302
2317
|
* @returns `true` if worker started, `false` if already running
|
|
@@ -2463,14 +2478,11 @@ var Act = class {
|
|
|
2463
2478
|
* fully catches up paginated streams (e.g. after `reset()` on a long
|
|
2464
2479
|
* projection) without forcing callers to loop.
|
|
2465
2480
|
*
|
|
2466
|
-
* @param options - Settle configuration
|
|
2467
|
-
*
|
|
2468
|
-
*
|
|
2469
|
-
*
|
|
2470
|
-
*
|
|
2471
|
-
* @param options.streamLimit - Maximum streams per drain cycle (default: 10)
|
|
2472
|
-
* @param options.eventLimit - Maximum events per stream (default: 10)
|
|
2473
|
-
* @param options.leaseMillis - Lease duration in milliseconds (default: 10000)
|
|
2481
|
+
* @param options - Settle configuration — see {@link SettleOptions} for fields:
|
|
2482
|
+
* `debounceMs` (default 10), `correlate` (default `{ after: -1, limit: 100 }`),
|
|
2483
|
+
* `maxPasses` (default `Infinity` — kill-switch for runaway loops),
|
|
2484
|
+
* `streamLimit` (default 10), `eventLimit` (default 10),
|
|
2485
|
+
* `leaseMillis` (default 10000).
|
|
2474
2486
|
*
|
|
2475
2487
|
* @example API mutations
|
|
2476
2488
|
* ```typescript
|
|
@@ -2733,7 +2745,8 @@ function action_builder(state2) {
|
|
|
2733
2745
|
throw new Error(`Duplicate action "${action2}"`);
|
|
2734
2746
|
internal.actions[action2] = schema;
|
|
2735
2747
|
function given(rules) {
|
|
2736
|
-
|
|
2748
|
+
internal.given ??= {};
|
|
2749
|
+
internal.given[action2] = rules;
|
|
2737
2750
|
return { emit };
|
|
2738
2751
|
}
|
|
2739
2752
|
function emit(handler) {
|