@rotorsoft/act 0.33.1 → 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.
Files changed (38) hide show
  1. package/README.md +1 -1
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/@types/act.d.ts +25 -31
  4. package/dist/@types/act.d.ts.map +1 -1
  5. package/dist/@types/adapters/console-logger.d.ts +2 -0
  6. package/dist/@types/adapters/console-logger.d.ts.map +1 -1
  7. package/dist/@types/adapters/in-memory-cache.d.ts +7 -1
  8. package/dist/@types/adapters/in-memory-cache.d.ts.map +1 -1
  9. package/dist/@types/builders/state-builder.d.ts +2 -2
  10. package/dist/@types/builders/state-builder.d.ts.map +1 -1
  11. package/dist/@types/config.d.ts +0 -1
  12. package/dist/@types/config.d.ts.map +1 -1
  13. package/dist/@types/internal/drain-cycle.d.ts.map +1 -1
  14. package/dist/@types/internal/event-sourcing.d.ts.map +1 -1
  15. package/dist/@types/internal/index.d.ts +2 -2
  16. package/dist/@types/internal/index.d.ts.map +1 -1
  17. package/dist/@types/ports.d.ts.map +1 -1
  18. package/dist/@types/types/action.d.ts +6 -6
  19. package/dist/@types/types/action.d.ts.map +1 -1
  20. package/dist/@types/types/errors.d.ts +19 -19
  21. package/dist/@types/types/errors.d.ts.map +1 -1
  22. package/dist/@types/types/ports.d.ts +11 -10
  23. package/dist/@types/types/ports.d.ts.map +1 -1
  24. package/dist/@types/types/registry.d.ts +13 -4
  25. package/dist/@types/types/registry.d.ts.map +1 -1
  26. package/dist/@types/types/schemas.d.ts +19 -19
  27. package/dist/@types/types/schemas.d.ts.map +1 -1
  28. package/dist/@types/utils.d.ts.map +1 -1
  29. package/dist/{chunk-IDEYGKT4.js → chunk-AWT7TU22.js} +9 -9
  30. package/dist/{chunk-IDEYGKT4.js.map → chunk-AWT7TU22.js.map} +1 -1
  31. package/dist/index.cjs +57 -53
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.js +45 -41
  34. package/dist/index.js.map +1 -1
  35. package/dist/types/index.cjs +7 -7
  36. package/dist/types/index.cjs.map +1 -1
  37. package/dist/types/index.js +1 -1
  38. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  TargetSchema,
14
14
  ValidationError,
15
15
  ZodEmpty
16
- } from "./chunk-IDEYGKT4.js";
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 { ZodError, prettifyError } from "zod";
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 function(adapter) {
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 && callback({
1602
+ callback?.({
1595
1603
  event,
1596
1604
  state: state2,
1597
1605
  version,
@@ -1700,7 +1708,7 @@ async function action(me, action2, target, payload, reactingTo, skipValidation =
1700
1708
  };
1701
1709
  });
1702
1710
  const last = snapshots.at(-1);
1703
- const snapped = me.snap && me.snap(last);
1711
+ const snapped = me.snap?.(last);
1704
1712
  cache().set(stream, {
1705
1713
  state: last.state,
1706
1714
  version: last.event.version,
@@ -1881,6 +1889,17 @@ function buildDrain(logger) {
1881
1889
  var DEFAULT_MAX_SUBSCRIBED_STREAMS = 1e3;
1882
1890
  var DEFAULT_SETTLE_DEBOUNCE_MS = 10;
1883
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
+ */
1884
1903
  constructor(registry, _states = /* @__PURE__ */ new Map(), batchHandlers = /* @__PURE__ */ new Map(), options = {}) {
1885
1904
  this.registry = registry;
1886
1905
  this._states = _states;
@@ -1968,12 +1987,6 @@ var Act = class {
1968
1987
  this._emitter.off(event, listener);
1969
1988
  return this;
1970
1989
  }
1971
- /**
1972
- * Create a new Act orchestrator.
1973
- *
1974
- * @param registry The registry of state, event, and action schemas
1975
- * @param states Map of state names to their (potentially merged) state definitions
1976
- */
1977
1990
  /** Batch handlers for static-target projections (target → handler) */
1978
1991
  _batch_handlers;
1979
1992
  /** Event-sourcing handlers, optionally wrapped with trace decorators */
@@ -2119,14 +2132,9 @@ var Act = class {
2119
2132
  *
2120
2133
  * For small result sets, consider using {@link query_array} instead.
2121
2134
  *
2122
- * @param query - The query filter
2123
- * @param query.stream - Filter by stream ID
2124
- * @param query.name - Filter by event name
2125
- * @param query.after - Filter events after this event ID
2126
- * @param query.before - Filter events before this event ID
2127
- * @param query.created_after - Filter events after this timestamp
2128
- * @param query.created_before - Filter events before this timestamp
2129
- * @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`)
2130
2138
  * @param callback - Optional callback invoked for each matching event
2131
2139
  * @returns Object with first event, last event, and total count
2132
2140
  *
@@ -2162,11 +2170,12 @@ var Act = class {
2162
2170
  * @see {@link query_array} for loading events into memory
2163
2171
  */
2164
2172
  async query(query, callback) {
2165
- let first = void 0, last = void 0;
2173
+ let first;
2174
+ let last;
2166
2175
  const count = await store().query((e) => {
2167
- !first && (first = e);
2176
+ if (!first) first = e;
2168
2177
  last = e;
2169
- callback && callback(e);
2178
+ callback?.(e);
2170
2179
  }, query);
2171
2180
  return { first, last, count };
2172
2181
  }
@@ -2217,10 +2226,8 @@ var Act = class {
2217
2226
  * Call `correlate()` before `drain()` to discover target streams. For a higher-level
2218
2227
  * API that handles debouncing, correlation, and signaling automatically, use {@link settle}.
2219
2228
  *
2220
- * @param options - Drain configuration options
2221
- * @param options.streamLimit - Maximum number of streams to process per cycle (default: 10)
2222
- * @param options.eventLimit - Maximum events to fetch per stream (default: 10)
2223
- * @param options.leaseMillis - Lease duration in milliseconds (default: 10000)
2229
+ * @param options - Drain configuration — see {@link DrainOptions} for fields
2230
+ * (`streamLimit`, `eventLimit`, `leaseMillis`).
2224
2231
  * @returns Drain statistics with fetched, leased, acked, and blocked counts
2225
2232
  *
2226
2233
  * @example In tests and scripts
@@ -2255,8 +2262,8 @@ var Act = class {
2255
2262
  * the next drain cycle.
2256
2263
  *
2257
2264
  * @param query - Query filter to scan for new correlations
2258
- * @param query.after - Start scanning after this event ID (default: -1)
2259
- * @param query.limit - Maximum events to scan (default: 10)
2265
+ * @param query - Scan filter see {@link Query} for fields (typically
2266
+ * `{ after: <event-id>, limit: <count> }`)
2260
2267
  * @returns Object with newly leased streams and last scanned event ID
2261
2268
  *
2262
2269
  * @example Manual correlation
@@ -2303,9 +2310,8 @@ var Act = class {
2303
2310
  *
2304
2311
  * **Note:** Only one correlation worker can run at a time per Act instance.
2305
2312
  *
2306
- * @param query - Query filter for correlation scans
2307
- * @param query.after - Initial starting point (default: -1, start from beginning)
2308
- * @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 }`)
2309
2315
  * @param frequency - Correlation frequency in milliseconds (default: 10000)
2310
2316
  * @param callback - Optional callback invoked with newly discovered streams
2311
2317
  * @returns `true` if worker started, `false` if already running
@@ -2472,14 +2478,11 @@ var Act = class {
2472
2478
  * fully catches up paginated streams (e.g. after `reset()` on a long
2473
2479
  * projection) without forcing callers to loop.
2474
2480
  *
2475
- * @param options - Settle configuration options
2476
- * @param options.debounceMs - Debounce window in milliseconds (default: 10)
2477
- * @param options.correlate - Query filter for correlation scans (default: `{ after: -1, limit: 100 }`)
2478
- * @param options.maxPasses - Cap on correlate→drain loops (default: `Infinity`).
2479
- * Early-exit on no-progress means the cap only matters in pathological cases.
2480
- * @param options.streamLimit - Maximum streams per drain cycle (default: 10)
2481
- * @param options.eventLimit - Maximum events per stream (default: 10)
2482
- * @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).
2483
2486
  *
2484
2487
  * @example API mutations
2485
2488
  * ```typescript
@@ -2742,7 +2745,8 @@ function action_builder(state2) {
2742
2745
  throw new Error(`Duplicate action "${action2}"`);
2743
2746
  internal.actions[action2] = schema;
2744
2747
  function given(rules) {
2745
- (internal.given ??= {})[action2] = rules;
2748
+ internal.given ??= {};
2749
+ internal.given[action2] = rules;
2746
2750
  return { emit };
2747
2751
  }
2748
2752
  function emit(handler) {