@zakkster/lite-signal 1.5.0-rc.2 → 1.5.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/CHANGELOG.md CHANGED
@@ -4,6 +4,63 @@ All notable changes to `@zakkster/lite-signal` are documented here.
4
4
  Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
5
5
  This project follows [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [1.5.0] -- 2026-08-21
8
+
9
+ **Stable 1.5.0.** Graduates `1.5.0-rc.3` to the release line with **no further engine
10
+ change** -- `Signal.js` / `Signal.d.ts` are byte-identical to rc.3 past the version
11
+ header, and the zero-GC gates (`bench/torture/run.mjs` 22/22) are unchanged. This is
12
+ the first stable to carry the **1.4.5 `createRegistry` input validation** (folded in
13
+ at rc.3; see below) on top of the 1.5.0 surface: `signalBox` / `computedBox`,
14
+ `createRoot`, and `getOwner` / `runWithOwner`. Drop-in over 1.4.5 for the callable
15
+ API; the only observable delta on existing code is `stats()` growing 11 -> 13 keys
16
+ (purely additive). The full rc/beta history is retained below.
17
+
18
+ ## [1.5.0-rc.3] -- 2026-08-20
19
+
20
+ Backports the **1.4.5 `createRegistry` input validation** (all four findings) onto
21
+ the rc.2 engine. This is the first engine change since the RC line began -- the hot
22
+ paths are still byte-identical to 1.4.0; only `createRegistry`'s *cold* construction
23
+ path gained validation, so the zero-GC gates (`bench/torture/run.mjs` 22/22) are
24
+ unchanged. If you had a typo in your registry config, you will now hear about it.
25
+
26
+ ### Added -- createRegistry validates its config (fail closed)
27
+
28
+ - **Bounded eager construction.** `prealloc:"eager"` with a non-finite or absurd
29
+ capacity (`maxNodes:Infinity`, `maxNodes:1e9`) previously ran an unbounded
30
+ construction loop and killed the process with an **uncatchable SIGABRT**. It now
31
+ throws a `TypeError` **by name**, before allocating, gated on `(maxNodes+maxLinks)`
32
+ against a ceiling of `1<<24` (16,777,216) objects. `prealloc:"lazy"` keeps its
33
+ unbounded on-demand ledger, untouched.
34
+ - **Per-option validation by name.** `maxNodes` / `maxLinks` / `maxFlushPasses` must
35
+ be finite integers `>= 1`; `prealloc` must be exactly `"eager"` | `"lazy"`;
36
+ `onCapacityExceeded` must be exactly `"throw"` | `"grow"`. Each bad value throws a
37
+ `TypeError` prefixed `createRegistry: "<option>"` at construction -- not a delayed
38
+ internal `nextFree` TypeError on first use.
39
+ - **Config-shape gate.** A non-object, `null`, or array `config` throws
40
+ `createRegistry: "config"` rather than dying later.
41
+ - **Unknown-key rejection with did-you-mean.** An unrecognized key throws with a
42
+ Levenshtein suggestion (`maxNods` -> `maxNodes`, `preAlloc` -> `prealloc`) instead
43
+ of being silently ignored.
44
+ - **`stats()` gains `nodePoolPopulation` / `linkPoolPopulation`** -- the TRUE count
45
+ of physically constructed nodes/links (`nodePool.length` / `linkPool.length`),
46
+ distinct from the `*Capacity` ledgers. A silently mis-set `prealloc` is now
47
+ observable (population 0 under lazy) instead of telemetry-blind. **This is the one
48
+ observable API change: `stats()` grows 11 -> 13 keys, purely additive** -- no
49
+ existing key changed; only an exact key-*count* assertion is affected (updated
50
+ in `test/03-pool.test.mjs`).
51
+
52
+ ### Tests
53
+
54
+ `test/30-config-validation.test.mjs` adds the full 25-config matrix, the did-you-mean
55
+ cases, the eager ceiling, the population contract, and the three OOM rows as isolated
56
+ child-process cases (`test/30-config-oom.child.mjs`) proving the fixed engine throws
57
+ + exits 0 under a 256 MB cap where the unvalidated engine died.
58
+
59
+ ## [1.5.0-rc.2] -- 2026-08-18
60
+
61
+ Version-only bump over rc.1; engine byte-identical past the header. Superseded by
62
+ rc.3, the first entry to carry an engine change.
63
+
7
64
  ## [1.5.0-rc.1] -- 2026-07-27
8
65
 
9
66
  Release candidate for 1.5.0. Promotes `1.5.0-beta.8` with **no engine change** --
package/Signal.d.ts CHANGED
@@ -122,6 +122,16 @@ export interface RegistryStats {
122
122
  /** Node-pool capacity ledger. Doubles under the `"grow"` policy; under `"lazy"`
123
123
  * prealloc it may exceed the count of physically constructed nodes. */
124
124
  nodePoolCapacity: number;
125
+ /** TRUE node-pool population: the number of `ReactiveNode`s physically constructed
126
+ * (`nodePool.length`), distinct from the `nodePoolCapacity` ledger. Under
127
+ * `prealloc:"lazy"` (or a silently-flipped `prealloc` typo) this stays 0 until
128
+ * first demand while capacity reads the ledger -- so a mis-set `prealloc` is
129
+ * observable here rather than telemetry-blind. Added in the 1.4.5 backport. */
130
+ nodePoolPopulation: number;
131
+ /** TRUE link-pool population: the number of `ReactiveLink`s physically constructed
132
+ * (`linkPool.length`), distinct from the `linkPoolCapacity` ledger. Added in the
133
+ * 1.4.5 backport. */
134
+ linkPoolPopulation: number;
125
135
  /** Number of nodes currently allocated (signals + computeds + alive effects). */
126
136
  activeNodes: number;
127
137
  /**
package/Signal.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @zakkster/lite-signal v1.5.0-rc.1
2
+ * @zakkster/lite-signal v1.5.0
3
3
  * --------------------
4
4
  * Hybrid Doubly-Linked-List Reactive Graph Engine -- decoupled (Signal1_3) base
5
5
  * with the two 1.1.3 performance fixes ported in:
@@ -209,10 +209,134 @@ export class CapacityError extends Error {
209
209
  * Error prefixed `"CycleError:"`.
210
210
  * @returns {Registry}
211
211
  */
212
+ /** The only config keys {@link createRegistry} recognizes. Anything else is
213
+ * rejected at construction with a did-you-mean hint (fail closed on an
214
+ * unverified state -- an unknown key is an error, never a silent ignore). */
215
+ const ALLOWED_KEYS = ["maxNodes", "maxLinks", "prealloc", "onCapacityExceeded", "maxFlushPasses"];
216
+
217
+ /** Ceiling on eager pool construction: `(maxNodes + maxLinks)` objects. A finite
218
+ * but absurd `maxNodes` (e.g. `1e9`, a plausible typo for `1e5`) that would
219
+ * otherwise OOM the process is refused BY NAME at construction rather than
220
+ * allocating forever. Only the `"eager"` path is bounded; `"lazy"` keeps its
221
+ * unbounded ledger. `1 << 24` == 16777216. */
222
+ const EAGER_CONSTRUCT_CEILING = 1 << 24;
223
+
224
+ /**
225
+ * Levenshtein edit distance between two short strings. Cold: called only on the
226
+ * constructor error path, over the known option names, so its per-call array
227
+ * allocation never touches any hot path.
228
+ * @param {string} a
229
+ * @param {string} b
230
+ * @returns {number}
231
+ */
232
+ function editDistance(a, b) {
233
+ const m = a.length;
234
+ const n = b.length;
235
+ const prev = new Array(n + 1);
236
+ const cur = new Array(n + 1);
237
+ for (let j = 0; j <= n; j++) prev[j] = j;
238
+ for (let i = 1; i <= m; i++) {
239
+ cur[0] = i;
240
+ for (let j = 1; j <= n; j++) {
241
+ const cost = a.charCodeAt(i - 1) === b.charCodeAt(j - 1) ? 0 : 1;
242
+ let min = prev[j] + 1;
243
+ if (cur[j - 1] + 1 < min) min = cur[j - 1] + 1;
244
+ if (prev[j - 1] + cost < min) min = prev[j - 1] + cost;
245
+ cur[j] = min;
246
+ }
247
+ for (let j = 0; j <= n; j++) prev[j] = cur[j];
248
+ }
249
+ return prev[n];
250
+ }
251
+
252
+ /**
253
+ * The closest known config key to `key` within edit distance 2 (case-folded so
254
+ * `preAlloc`/`MAXNODES` resolve), or null when nothing is close. Cold path only.
255
+ * @param {string} key
256
+ * @returns {string|null}
257
+ */
258
+ function suggestKey(key) {
259
+ const lk = key.toLowerCase();
260
+ let best = null;
261
+ let bestD = 3;
262
+ for (let i = 0; i < ALLOWED_KEYS.length; i++) {
263
+ const d = editDistance(lk, ALLOWED_KEYS[i].toLowerCase());
264
+ if (d < bestD) { bestD = d; best = ALLOWED_KEYS[i]; }
265
+ }
266
+ return bestD <= 2 ? best : null;
267
+ }
268
+
269
+ /**
270
+ * Render a rejected value for an error message, e.g. `42 (number)`.
271
+ * Cold: this runs only on a throw path, never on any hot path. `String(symbol)`
272
+ * throws, so symbols are stringified defensively.
273
+ * @param {*} v
274
+ * @returns {string}
275
+ */
276
+ function received(v) {
277
+ return (typeof v === "symbol" ? v.toString() : String(v)) + " (" + typeof v + ")";
278
+ }
279
+
280
+ /**
281
+ * Validate that a numeric option is a finite integer >= 1. Cold: constructor
282
+ * error path only. Throws a {@link TypeError} prefixed `createRegistry: "<name>"`.
283
+ * @param {*} v
284
+ * @param {string} name
285
+ */
286
+ function requirePositiveInt(v, name) {
287
+ if (!Number.isInteger(v) || v < 1) {
288
+ throw new TypeError(
289
+ 'createRegistry: "' + name + '" must be a finite integer >= 1, received ' + received(v) + '.'
290
+ );
291
+ }
292
+ }
293
+
212
294
  export function createRegistry(config) {
213
295
  const NODE_PTR = Symbol("node_ptr");
214
296
  const NODE_GEN = Symbol("node_gen");
215
297
 
298
+ // --- 1.4.5 backport: createRegistry input validation (all cold, constructor-only).
299
+ // Config-shape gate: accept `undefined` or a non-null, non-array object; reject
300
+ // `null`, primitives and arrays BY NAME rather than dying later on `config.maxNodes`
301
+ // or an internal `nextFree` read (fail closed on an unverified state).
302
+ if (config !== undefined && (config === null || typeof config !== "object" || Array.isArray(config))) {
303
+ throw new TypeError(
304
+ 'createRegistry: "config" must be a plain object or undefined, received ' + received(config) + '.'
305
+ );
306
+ }
307
+ if (config !== undefined) {
308
+ // Per-option validation BY NAME -- a bad value throws `createRegistry: "<option>"`
309
+ // at construction, not a delayed internal TypeError on first use.
310
+ if (config.maxNodes !== undefined) requirePositiveInt(config.maxNodes, "maxNodes");
311
+ if (config.maxLinks !== undefined) requirePositiveInt(config.maxLinks, "maxLinks");
312
+ if (config.maxFlushPasses !== undefined) requirePositiveInt(config.maxFlushPasses, "maxFlushPasses");
313
+ if (config.prealloc !== undefined && config.prealloc !== "eager" && config.prealloc !== "lazy") {
314
+ throw new TypeError(
315
+ 'createRegistry: "prealloc" must be "eager" or "lazy", received ' + received(config.prealloc) + '.'
316
+ );
317
+ }
318
+ if (config.onCapacityExceeded !== undefined && config.onCapacityExceeded !== "throw" && config.onCapacityExceeded !== "grow") {
319
+ throw new TypeError(
320
+ 'createRegistry: "onCapacityExceeded" must be "throw" or "grow", received ' + received(config.onCapacityExceeded) + '.'
321
+ );
322
+ }
323
+ // Unknown-key rejection with a did-you-mean hint (`preAlloc` -> `prealloc`,
324
+ // `maxNods` -> `maxNodes`). Own enumerable keys only; cold path.
325
+ const badKeys = Object.keys(config);
326
+ for (let bi = 0; bi < badKeys.length; bi++) {
327
+ const bk = badKeys[bi];
328
+ if (ALLOWED_KEYS.indexOf(bk) === -1) {
329
+ const hint = suggestKey(bk);
330
+ throw new TypeError(
331
+ 'createRegistry: "' + bk + '" is not a recognized option' +
332
+ (hint !== null ? ' (did you mean "' + hint + '"?)' : '') +
333
+ '. Allowed: ' + ALLOWED_KEYS.join(", ") + '.'
334
+ );
335
+ }
336
+ }
337
+ }
338
+ // --- end 1.4.5 backport.
339
+
216
340
  let currentNodesCapacity = (config !== undefined && config.maxNodes !== undefined) ? config.maxNodes : 1024;
217
341
  let currentLinkCapacity = (config !== undefined && config.maxLinks !== undefined) ? config.maxLinks : currentNodesCapacity * 4;
218
342
  const policy = (config !== undefined && config.onCapacityExceeded !== undefined) ? config.onCapacityExceeded : "throw";
@@ -225,6 +349,20 @@ export function createRegistry(config) {
225
349
  // steady state is identical after warm-up, but the heap no longer carries
226
350
  // never-used live objects for every major GC to mark.
227
351
  const prealloc = (config !== undefined && config.prealloc !== undefined) ? config.prealloc : "eager";
352
+ // Eager-construction ceiling (cold): `"eager"` builds `(maxNodes + maxLinks)`
353
+ // objects up front; a finite-but-absurd capacity (e.g. `1e9`) would OOM the
354
+ // process with an uncatchable SIGABRT, not a throw. Refuse BY NAME before
355
+ // allocating. Named for the larger driver. `"lazy"` keeps its unbounded ledger.
356
+ if (prealloc === "eager" && (currentNodesCapacity + currentLinkCapacity) > EAGER_CONSTRUCT_CEILING) {
357
+ const driver = currentLinkCapacity > currentNodesCapacity ? "maxLinks" : "maxNodes";
358
+ throw new TypeError(
359
+ 'createRegistry: "' + driver + '" eager construction of ' +
360
+ (currentNodesCapacity + currentLinkCapacity) + ' objects (maxNodes ' +
361
+ currentNodesCapacity + ' + maxLinks ' + currentLinkCapacity + ') exceeds the ceiling of ' +
362
+ EAGER_CONSTRUCT_CEILING + '. Use prealloc:"lazy" for an unbounded on-demand ledger, ' +
363
+ 'or lower the capacity.'
364
+ );
365
+ }
228
366
  const nodePool = [];
229
367
  let freeNodeHead = null;
230
368
  const linkPool = [];
@@ -1562,6 +1700,12 @@ export function createRegistry(config) {
1562
1700
  pooledLinks: currentLinkCapacity - activeLinks,
1563
1701
  linkPoolCapacity: currentLinkCapacity,
1564
1702
  nodePoolCapacity: currentNodesCapacity,
1703
+ // 1.4.5 backport: TRUE pool population (nodePool.length / linkPool.length),
1704
+ // distinct from the *Capacity ledgers above. Under prealloc:"lazy" (or a
1705
+ // silently-flipped `prealloc` typo) population stays 0 while capacity reads
1706
+ // the ledger -- so a mis-set prealloc is now observable, not telemetry-blind.
1707
+ nodePoolPopulation: nodePool.length,
1708
+ linkPoolPopulation: linkPool.length,
1565
1709
  activeNodes,
1566
1710
  // 1.4: cumulative lifecycle counters (monotonic; reset by destroy()).
1567
1711
  // Derive: allocationRate = deltatotalAllocations/deltat; poolReuseRate =
package/llms.txt CHANGED
@@ -25,7 +25,7 @@ triggering write -- no `queueMicrotask`, no promises, no scheduler ticks.
25
25
  - **isTracking**: `isTracking()` returns true iff a read right now would record a dependency on this registry (for wrappers that lazily allocate signals).
26
26
  - **onCleanup**: registers teardown for the current computation; fires before each re-run and once on dispose. Works in effects and computeds.
27
27
  - **Observer-lifecycle introspection** (1.1.4; top-level + per-registry): `hasObservers(handle)` returns true iff a signal/computed has >=1 live observer right now (O(1); a `peek` does not count). `observeObservers(handle, { onConnect?, onDisconnect? })` fires on the 0->1 and 1->0 observer transitions (after registration; transition-only) and returns an idempotent unobserve -- the auto-pause hook for tickers (lite-time/lite-raf start a source only while it's watched). `forEachObserver(handle, fn)` / `forEachSource(handle, fn)` walk the live graph in either direction, passing a `{ kind, value }` descriptor (`kind` is `"signal" | "computed" | "effect"`) -- for inspection (lite-devtools). The surface is gated by an internal counter: zero steady-state cost when nothing is observed. `hasObservers`/`forEach*` no-op on a non-handle; `observeObservers` throws `TypeError`. **Node identity (1.1.5):** `nodeId(handle)` returns the node's stable per-allocation id, `describe(handle)` returns the handle's own `{ id, kind, value }` descriptor, and `forEach*` descriptors now carry `id` too; a descriptor is **re-walkable** (pass it back into `forEachObserver`/`forEachSource`) -- the recursion primitive lite-devtools uses to walk the full DAG. **Owner-tree introspection (1.2.1):** `forEachOwned(handle, fn)` walks a node's owned children (lifetime-binding edges from the 1.2 owner tree -- invisible through dep/sub); `ownerOf(handle)` returns the owner's descriptor or `undefined` for top-level / stale handles. **Stale-handle guard (1.2.1):** the entire introspection surface plus `peek()`/`read()`/`set()` is now generation-checked. A handle held across the 1.2 owner-cascade auto-dispose used to resolve `NODE_PTR` ungated and silently report the recycled slot's NEW resident; 1.2.1 surfaces stale handles as `undefined` (or `TypeError`, for `observeObservers`) -- same ABA discipline `dispose()` always had. Descriptors are gen-stamped so the re-walkable contract survives the guard. **Push-based mutation hook (1.2.1):** `onGraphMutation(fn)` registers a single nullable listener invoked synchronously at every mutation point with three integers `(opcode, intA, intB)` -- opcodes `1` node-create / `2` node-dispose / `3` link-add / `4` link-remove / `5` recompute. Zero-cost gate when no listener is registered (one branch-predicted null check); allocation-free dispatch when registered. The connection point for push-based devtools/studio. Contract: observe only -- never throw, never mutate.
28
- - **Registry**: `createRegistry({ maxNodes, maxLinks, prealloc, onCapacityExceeded, maxFlushPasses })` creates an isolated reactive world with its own pools. Useful for tests, plugins, multi-tenant sandboxes. Top-level helpers use a default registry created at module load. `prealloc` (1.3.0; `"eager"` default | `"lazy"`) chooses up-front vs on-demand pool construction; `onCapacityExceeded` (`"throw"` default | `"grow"`) chooses fail-fast vs chunked-incremental growth bounded by the 16x link ceiling.
28
+ - **Registry**: `createRegistry({ maxNodes, maxLinks, prealloc, onCapacityExceeded, maxFlushPasses })` creates an isolated reactive world with its own pools. Useful for tests, plugins, multi-tenant sandboxes. Top-level helpers use a default registry created at module load. `prealloc` (1.3.0; `"eager"` default | `"lazy"`) chooses up-front vs on-demand pool construction; `onCapacityExceeded` (`"throw"` default | `"grow"`) chooses fail-fast vs chunked-incremental growth bounded by the 16x link ceiling. **Config is validated at construction (1.5.0, backported from 1.4.5):** every option is checked BY NAME (`maxNodes`/`maxLinks`/`maxFlushPasses` finite integer `>= 1`; `prealloc` exactly `"eager"`|`"lazy"`; `onCapacityExceeded` exactly `"throw"`|`"grow"`), a bad shape or unknown key throws a `TypeError` prefixed `createRegistry: "<name>"` with a did-you-mean hint, and an absurd eager capacity (`maxNodes:Infinity`/`1e9`) is refused before it can OOM the process. `stats()` gains `nodePoolPopulation` / `linkPoolPopulation` (true constructed-object counts, distinct from the `*Capacity` ledgers) -> **13 keys**.
29
29
  - **CapacityError**: thrown when a fixed-size pool is exhausted under the `"throw"` policy, or when a `"grow"` policy hits the 16× starting-capacity ceiling on links.
30
30
 
31
31
  ## Architecture invariants
@@ -53,7 +53,24 @@ triggering write -- no `queueMicrotask`, no promises, no scheduler ticks.
53
53
 
54
54
  ## Version notes
55
55
 
56
- - **1.5.0-rc.1** (current): release candidate for 1.5.0. **No engine change** --
56
+ - **1.5.0** (current): stable. Graduates rc.3 with **no further engine change** --
57
+ `Signal.js`/`Signal.d.ts` byte-identical to rc.3 past the header, `bench/torture/run.mjs`
58
+ unchanged at 22/22. First stable to carry the **1.4.5 `createRegistry` input
59
+ validation** (folded in at rc.3) atop the 1.5.0 surface (`signalBox`/`computedBox`,
60
+ `createRoot`, `getOwner`/`runWithOwner`). Drop-in over 1.4.5; the one observable delta
61
+ on existing code is `stats()` growing 11 -> 13 keys (additive). See CHANGELOG `[1.5.0]`.
62
+ - **1.5.0-rc.3**: backports the **1.4.5 `createRegistry` input validation**
63
+ (all four findings) onto the rc.2 engine. First engine change since the RC line
64
+ began -- but only `createRegistry`'s *cold* construction path moved; hot paths stay
65
+ byte-identical to 1.4.0 and `bench/torture/run.mjs` is unchanged at 22/22. Bad
66
+ config now throws a named `TypeError` (unknown keys get a did-you-mean); an absurd
67
+ eager capacity is refused before it can OOM the process; `stats()` grows 11 -> 13
68
+ keys (adds `nodePoolPopulation`/`linkPoolPopulation`, purely additive). New suite
69
+ `test/30-config-validation.test.mjs` (matrix + ceiling + population + OOM child
70
+ processes). See CHANGELOG `[1.5.0-rc.3]`.
71
+ - **1.5.0-rc.2**: version-only bump over rc.1; engine byte-identical past the header.
72
+ Superseded by rc.3.
73
+ - **1.5.0-rc.1**: release candidate for 1.5.0. **No engine change** --
57
74
  `Signal.js` and `Signal.d.ts` are FROZEN: byte-identical to beta.8, hot paths
58
75
  byte-identical to 1.4.0. This RC brings the torture surface to full **parity
59
76
  with 1.4.4**: `bench/torture/run.mjs` now registers the complete **22-scenario
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zakkster/lite-signal",
3
- "version": "1.5.0-rc.2",
3
+ "version": "1.5.0",
4
4
  "description": "Zero-GC reactive graph. Monomorphic object pool, versioned push-pull propagation, 32-bit modular versioning. Built for hot paths and long-running processes.",
5
5
  "author": "Zahary Shinikchiev <shinikchiev@yahoo.com>",
6
6
  "license": "MIT",