@zakkster/lite-signal 1.8.0-alpha.6 → 1.8.0-alpha.7

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,47 @@ 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.8.0-alpha.7] -- 2026-08-20
8
+
9
+ Backports the **1.4.5 `createRegistry` input validation** (all four findings) onto
10
+ the 1.8.0-alpha.6 engine. Supersedes 1.8.0-alpha.6. Only `createRegistry`'s *cold*
11
+ construction path changed -- the hot paths are byte-identical and the zero-GC gates
12
+ (`bench/torture/run.mjs` 22/22) are unchanged. If you had a typo in your registry
13
+ config, you will now hear about it.
14
+
15
+ ### Added -- createRegistry validates its config (fail closed)
16
+
17
+ - **Bounded eager construction.** `prealloc:"eager"` with a non-finite or absurd
18
+ capacity (`maxNodes:Infinity`, `maxNodes:1e9`) previously ran an unbounded
19
+ construction loop and killed the process with an **uncatchable SIGABRT**. It now
20
+ throws a `TypeError` **by name**, before allocating, gated on `(maxNodes+maxLinks)`
21
+ against a ceiling of `1<<24` (16,777,216) objects. `prealloc:"lazy"` keeps its
22
+ unbounded on-demand ledger, untouched.
23
+ - **Per-option validation by name.** `maxNodes` / `maxLinks` / `maxFlushPasses` must
24
+ be finite integers `>= 1`; `prealloc` must be exactly `"eager"` | `"lazy"`;
25
+ `onCapacityExceeded` must be exactly `"throw"` | `"grow"`. Each bad value throws a
26
+ `TypeError` prefixed `createRegistry: "<option>"` at construction -- not a delayed
27
+ internal `nextFree` TypeError on first use.
28
+ - **Config-shape gate.** A non-object, `null`, or array `config` throws
29
+ `createRegistry: "config"` rather than dying later.
30
+ - **Unknown-key rejection with did-you-mean.** An unrecognized key throws with a
31
+ Levenshtein suggestion (`maxNods` -> `maxNodes`, `preAlloc` -> `prealloc`) instead
32
+ of being silently ignored.
33
+ - **`flushStrategy` stays a first-class option.** It is a recognized key (its own native value-guard is unchanged); only misspelled *keys* are rejected.
34
+ - **`stats()` gains `nodePoolPopulation` / `linkPoolPopulation`** -- the TRUE count
35
+ of physically constructed nodes/links, distinct from the `*Capacity` ledgers. A
36
+ silently mis-set `prealloc` is now observable (population 0 under lazy) instead of
37
+ telemetry-blind. **The one observable API change: `stats()` grows to 14 keys,
38
+ purely additive** -- no existing key changed; only an exact key-*count* assertion
39
+ is affected (updated in `test/03-pool.test.mjs`).
40
+
41
+ ### Tests
42
+
43
+ New `test/*-config-validation.test.mjs` adds the full config matrix, the did-you-mean
44
+ cases, the eager ceiling, the population contract, and the three OOM rows as isolated
45
+ child-process cases proving the fixed engine throws + exits 0 under a 256 MB cap where
46
+ the unvalidated engine died.
47
+
7
48
  ## [1.8.0-alpha.5] -- 2026-08-18
8
49
 
9
50
  Brings the `bench/torture/` suite and the throwing-`equals` unit test to **full
package/Signal.d.ts CHANGED
@@ -136,6 +136,16 @@ export interface RegistryStats {
136
136
  /** Node-pool capacity ledger. Doubles under the `"grow"` policy; under `"lazy"`
137
137
  * prealloc it may exceed the count of physically constructed nodes. */
138
138
  nodePoolCapacity: number;
139
+ /** TRUE node-pool population: the number of `ReactiveNode`s physically constructed
140
+ * (`nodePool.length`), distinct from the `nodePoolCapacity` ledger. Under
141
+ * `prealloc:"lazy"` (or a silently-flipped `prealloc` typo) this stays 0 until
142
+ * first demand while capacity reads the ledger -- so a mis-set `prealloc` is
143
+ * observable here rather than telemetry-blind. Added in the 1.4.5 backport. */
144
+ nodePoolPopulation: number;
145
+ /** TRUE link-pool population: the number of `ReactiveLink`s physically constructed
146
+ * (`linkPool.length`), distinct from the `linkPoolCapacity` ledger. Added in the
147
+ * 1.4.5 backport. */
148
+ linkPoolPopulation: number;
139
149
  /** Number of nodes currently allocated (signals + computeds + alive effects). */
140
150
  activeNodes: number;
141
151
  /**
package/Signal.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @zakkster/lite-signal v1.8.0-alpha.4
2
+ * @zakkster/lite-signal v1.8.0-alpha.7
3
3
  * Copyright (c) Zahary Shinikchiev <shinikchiev@yahoo.com>
4
4
  * MIT License
5
5
  * --------------------
@@ -274,10 +274,134 @@ export class CapacityError extends Error {
274
274
  * Error prefixed `"CycleError:"`.
275
275
  * @returns {Registry}
276
276
  */
277
+ /** The only config keys {@link createRegistry} recognizes. Anything else is
278
+ * rejected at construction with a did-you-mean hint (fail closed on an
279
+ * unverified state -- an unknown key is an error, never a silent ignore). */
280
+ const ALLOWED_KEYS = ["maxNodes", "maxLinks", "prealloc", "onCapacityExceeded", "maxFlushPasses", "flushStrategy"];
281
+
282
+ /** Ceiling on eager pool construction: `(maxNodes + maxLinks)` objects. A finite
283
+ * but absurd `maxNodes` (e.g. `1e9`, a plausible typo for `1e5`) that would
284
+ * otherwise OOM the process is refused BY NAME at construction rather than
285
+ * allocating forever. Only the `"eager"` path is bounded; `"lazy"` keeps its
286
+ * unbounded ledger. `1 << 24` == 16777216. */
287
+ const EAGER_CONSTRUCT_CEILING = 1 << 24;
288
+
289
+ /**
290
+ * Levenshtein edit distance between two short strings. Cold: called only on the
291
+ * constructor error path, over the known option names, so its per-call array
292
+ * allocation never touches any hot path.
293
+ * @param {string} a
294
+ * @param {string} b
295
+ * @returns {number}
296
+ */
297
+ function editDistance(a, b) {
298
+ const m = a.length;
299
+ const n = b.length;
300
+ const prev = new Array(n + 1);
301
+ const cur = new Array(n + 1);
302
+ for (let j = 0; j <= n; j++) prev[j] = j;
303
+ for (let i = 1; i <= m; i++) {
304
+ cur[0] = i;
305
+ for (let j = 1; j <= n; j++) {
306
+ const cost = a.charCodeAt(i - 1) === b.charCodeAt(j - 1) ? 0 : 1;
307
+ let min = prev[j] + 1;
308
+ if (cur[j - 1] + 1 < min) min = cur[j - 1] + 1;
309
+ if (prev[j - 1] + cost < min) min = prev[j - 1] + cost;
310
+ cur[j] = min;
311
+ }
312
+ for (let j = 0; j <= n; j++) prev[j] = cur[j];
313
+ }
314
+ return prev[n];
315
+ }
316
+
317
+ /**
318
+ * The closest known config key to `key` within edit distance 2 (case-folded so
319
+ * `preAlloc`/`MAXNODES` resolve), or null when nothing is close. Cold path only.
320
+ * @param {string} key
321
+ * @returns {string|null}
322
+ */
323
+ function suggestKey(key) {
324
+ const lk = key.toLowerCase();
325
+ let best = null;
326
+ let bestD = 3;
327
+ for (let i = 0; i < ALLOWED_KEYS.length; i++) {
328
+ const d = editDistance(lk, ALLOWED_KEYS[i].toLowerCase());
329
+ if (d < bestD) { bestD = d; best = ALLOWED_KEYS[i]; }
330
+ }
331
+ return bestD <= 2 ? best : null;
332
+ }
333
+
334
+ /**
335
+ * Render a rejected value for an error message, e.g. `42 (number)`.
336
+ * Cold: this runs only on a throw path, never on any hot path. `String(symbol)`
337
+ * throws, so symbols are stringified defensively.
338
+ * @param {*} v
339
+ * @returns {string}
340
+ */
341
+ function received(v) {
342
+ return (typeof v === "symbol" ? v.toString() : String(v)) + " (" + typeof v + ")";
343
+ }
344
+
345
+ /**
346
+ * Validate that a numeric option is a finite integer >= 1. Cold: constructor
347
+ * error path only. Throws a {@link TypeError} prefixed `createRegistry: "<name>"`.
348
+ * @param {*} v
349
+ * @param {string} name
350
+ */
351
+ function requirePositiveInt(v, name) {
352
+ if (!Number.isInteger(v) || v < 1) {
353
+ throw new TypeError(
354
+ 'createRegistry: "' + name + '" must be a finite integer >= 1, received ' + received(v) + '.'
355
+ );
356
+ }
357
+ }
358
+
277
359
  export function createRegistry(config) {
278
360
  const NODE_PTR = Symbol("node_ptr");
279
361
  const NODE_GEN = Symbol("node_gen");
280
362
 
363
+ // --- 1.4.5 backport: createRegistry input validation (all cold, constructor-only).
364
+ // Config-shape gate: accept `undefined` or a non-null, non-array object; reject
365
+ // `null`, primitives and arrays BY NAME rather than dying later on `config.maxNodes`
366
+ // or an internal `nextFree` read (fail closed on an unverified state).
367
+ if (config !== undefined && (config === null || typeof config !== "object" || Array.isArray(config))) {
368
+ throw new TypeError(
369
+ 'createRegistry: "config" must be a plain object or undefined, received ' + received(config) + '.'
370
+ );
371
+ }
372
+ if (config !== undefined) {
373
+ // Per-option validation BY NAME -- a bad value throws `createRegistry: "<option>"`
374
+ // at construction, not a delayed internal TypeError on first use.
375
+ if (config.maxNodes !== undefined) requirePositiveInt(config.maxNodes, "maxNodes");
376
+ if (config.maxLinks !== undefined) requirePositiveInt(config.maxLinks, "maxLinks");
377
+ if (config.maxFlushPasses !== undefined) requirePositiveInt(config.maxFlushPasses, "maxFlushPasses");
378
+ if (config.prealloc !== undefined && config.prealloc !== "eager" && config.prealloc !== "lazy") {
379
+ throw new TypeError(
380
+ 'createRegistry: "prealloc" must be "eager" or "lazy", received ' + received(config.prealloc) + '.'
381
+ );
382
+ }
383
+ if (config.onCapacityExceeded !== undefined && config.onCapacityExceeded !== "throw" && config.onCapacityExceeded !== "grow") {
384
+ throw new TypeError(
385
+ 'createRegistry: "onCapacityExceeded" must be "throw" or "grow", received ' + received(config.onCapacityExceeded) + '.'
386
+ );
387
+ }
388
+ // Unknown-key rejection with a did-you-mean hint (`preAlloc` -> `prealloc`,
389
+ // `maxNods` -> `maxNodes`). Own enumerable keys only; cold path.
390
+ const badKeys = Object.keys(config);
391
+ for (let bi = 0; bi < badKeys.length; bi++) {
392
+ const bk = badKeys[bi];
393
+ if (ALLOWED_KEYS.indexOf(bk) === -1) {
394
+ const hint = suggestKey(bk);
395
+ throw new TypeError(
396
+ 'createRegistry: "' + bk + '" is not a recognized option' +
397
+ (hint !== null ? ' (did you mean "' + hint + '"?)' : '') +
398
+ '. Allowed: ' + ALLOWED_KEYS.join(", ") + '.'
399
+ );
400
+ }
401
+ }
402
+ }
403
+ // --- end 1.4.5 backport.
404
+
281
405
  let currentNodesCapacity = (config !== undefined && config.maxNodes !== undefined) ? config.maxNodes : 1024;
282
406
  let currentLinkCapacity = (config !== undefined && config.maxLinks !== undefined) ? config.maxLinks : currentNodesCapacity * 4;
283
407
  const policy = (config !== undefined && config.onCapacityExceeded !== undefined) ? config.onCapacityExceeded : "throw";
@@ -301,6 +425,20 @@ export function createRegistry(config) {
301
425
  // steady state is identical after warm-up, but the heap no longer carries
302
426
  // never-used live objects for every major GC to mark.
303
427
  const prealloc = (config !== undefined && config.prealloc !== undefined) ? config.prealloc : "eager";
428
+ // Eager-construction ceiling (cold): `"eager"` builds `(maxNodes + maxLinks)`
429
+ // objects up front; a finite-but-absurd capacity (e.g. `1e9`) would OOM the
430
+ // process with an uncatchable SIGABRT, not a throw. Refuse BY NAME before
431
+ // allocating. Named for the larger driver. `"lazy"` keeps its unbounded ledger.
432
+ if (prealloc === "eager" && (currentNodesCapacity + currentLinkCapacity) > EAGER_CONSTRUCT_CEILING) {
433
+ const driver = currentLinkCapacity > currentNodesCapacity ? "maxLinks" : "maxNodes";
434
+ throw new TypeError(
435
+ 'createRegistry: "' + driver + '" eager construction of ' +
436
+ (currentNodesCapacity + currentLinkCapacity) + ' objects (maxNodes ' +
437
+ currentNodesCapacity + ' + maxLinks ' + currentLinkCapacity + ') exceeds the ceiling of ' +
438
+ EAGER_CONSTRUCT_CEILING + '. Use prealloc:"lazy" for an unbounded on-demand ledger, ' +
439
+ 'or lower the capacity.'
440
+ );
441
+ }
304
442
  const nodePool = [];
305
443
  let freeNodeHead = null;
306
444
  const linkPool = [];
@@ -1858,6 +1996,12 @@ export function createRegistry(config) {
1858
1996
  pooledLinks: currentLinkCapacity - activeLinks,
1859
1997
  linkPoolCapacity: currentLinkCapacity,
1860
1998
  nodePoolCapacity: currentNodesCapacity,
1999
+ // 1.4.5 backport: TRUE pool population (nodePool.length / linkPool.length),
2000
+ // distinct from the *Capacity ledgers above. Under prealloc:"lazy" (or a
2001
+ // silently-flipped `prealloc` typo) population stays 0 while capacity reads
2002
+ // the ledger -- so a mis-set prealloc is now observable, not telemetry-blind.
2003
+ nodePoolPopulation: nodePool.length,
2004
+ linkPoolPopulation: linkPool.length,
1861
2005
  activeNodes,
1862
2006
  // 1.4: cumulative lifecycle counters (monotonic; reset by destroy()).
1863
2007
  // Derive: allocationRate = deltatotalAllocations/deltat; poolReuseRate =
package/llms.txt CHANGED
@@ -25,7 +25,7 @@ triggering write -- no `queueMicrotask`, no promises, no scheduler ticks.
25
25
  - **onCleanup**: registers teardown for the current computation; fires before each re-run and once on dispose. Works in effects and computeds.
26
26
  - **Returned cleanup (1.8.0)**: an EFFECT body may `return` a cleanup function (Solid/Vue/Reflex-compatible). Runs at the same points as onCleanup (before each re-run, once on dispose) and is APPENDED after any onCleanup registered in the same body, so the two styles compose in call order. Non-function returns are ignored; a self-disposed body registers nothing (gen-guarded). COMPUTEDS ARE EXCLUDED: a computed returning a function keeps treating it as the VALUE. Cost: one `typeof` per effect run, off the mark/pull path; `executeEffect` is the only body whose sha256 changed 1.7.0 -> 1.8.0.
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.8.0-alpha.7, backported from 1.4.5):** every option is checked BY NAME (the six recognized keys include `flushStrategy`), 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) -> **14 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,8 @@ triggering write -- no `queueMicrotask`, no promises, no scheduler ticks.
53
53
 
54
54
  ## Version notes
55
55
 
56
- - **1.8.0-alpha.4** (current): the **effect-cleanup-return minor**. An EFFECT body
56
+ - **1.8.0-alpha.7** (current): backports the **1.4.5 `createRegistry` input validation** (all four findings) onto the 1.8.0-alpha.6 engine. Only `createRegistry`'s *cold* path moved; hot paths stay byte-identical and `bench/torture/run.mjs` is unchanged at 22/22. Bad config now throws a named `TypeError` (unknown keys get a did-you-mean); an absurd eager capacity is refused before it can OOM the process; `stats()` grows to 14 keys (adds `nodePoolPopulation`/`linkPoolPopulation`, purely additive). New `test/*-config-validation.test.mjs` (matrix + ceiling + population + OOM child processes). See CHANGELOG `[1.8.0-alpha.7]`.
57
+ - **1.8.0-alpha.4**: the **effect-cleanup-return minor**. An EFFECT body
57
58
  may now `return` a cleanup function (Solid/Vue/Reflex-compatible), run at the same
58
59
  points as imperative `onCleanup` -- before each re-run and once on dispose -- and
59
60
  APPENDED after any `onCleanup` from the same body, so both compose in call order.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zakkster/lite-signal",
3
- "version": "1.8.0-alpha.6",
3
+ "version": "1.8.0-alpha.7",
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",