@zakkster/lite-signal 1.9.0-preview.5 → 1.9.0-preview.6

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.9.0-preview.6] -- 2026-08-20
8
+
9
+ Backports the **1.4.5 `createRegistry` input validation** (all four findings) onto
10
+ the 1.9.0-preview.5 engine. Supersedes 1.9.0-preview.5. 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.9.0-preview.5] -- 2026-08-18
8
49
 
9
50
  Packaging-only cut. **The engine is UNCHANGED** -- `Signal.js` is behaviourally
package/Signal.d.ts CHANGED
@@ -177,6 +177,16 @@ export interface RegistryStats {
177
177
  /** Node-pool capacity ledger. Doubles under the `"grow"` policy; under `"lazy"`
178
178
  * prealloc it may exceed the count of physically constructed nodes. */
179
179
  nodePoolCapacity: number;
180
+ /** TRUE node-pool population: the number of `ReactiveNode`s physically constructed
181
+ * (`nodePool.length`), distinct from the `nodePoolCapacity` ledger. Under
182
+ * `prealloc:"lazy"` (or a silently-flipped `prealloc` typo) this stays 0 until
183
+ * first demand while capacity reads the ledger -- so a mis-set `prealloc` is
184
+ * observable here rather than telemetry-blind. Added in the 1.4.5 backport. */
185
+ nodePoolPopulation: number;
186
+ /** TRUE link-pool population: the number of `ReactiveLink`s physically constructed
187
+ * (`linkPool.length`), distinct from the `linkPoolCapacity` ledger. Added in the
188
+ * 1.4.5 backport. */
189
+ linkPoolPopulation: number;
180
190
  /** Number of nodes currently allocated (signals + computeds + alive effects). */
181
191
  activeNodes: number;
182
192
  /**
package/Signal.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @zakkster/lite-signal v1.9.0-preview.5
2
+ * @zakkster/lite-signal v1.9.0-preview.6
3
3
  * Copyright (c) Zahary Shinikchiev <shinikchiev@yahoo.com>
4
4
  * MIT License
5
5
  * --------------------
@@ -301,10 +301,134 @@ export class CapacityError extends Error {
301
301
  * Error prefixed `"CycleError:"`.
302
302
  * @returns {Registry}
303
303
  */
304
+ /** The only config keys {@link createRegistry} recognizes. Anything else is
305
+ * rejected at construction with a did-you-mean hint (fail closed on an
306
+ * unverified state -- an unknown key is an error, never a silent ignore). */
307
+ const ALLOWED_KEYS = ["maxNodes", "maxLinks", "prealloc", "onCapacityExceeded", "maxFlushPasses", "flushStrategy"];
308
+
309
+ /** Ceiling on eager pool construction: `(maxNodes + maxLinks)` objects. A finite
310
+ * but absurd `maxNodes` (e.g. `1e9`, a plausible typo for `1e5`) that would
311
+ * otherwise OOM the process is refused BY NAME at construction rather than
312
+ * allocating forever. Only the `"eager"` path is bounded; `"lazy"` keeps its
313
+ * unbounded ledger. `1 << 24` == 16777216. */
314
+ const EAGER_CONSTRUCT_CEILING = 1 << 24;
315
+
316
+ /**
317
+ * Levenshtein edit distance between two short strings. Cold: called only on the
318
+ * constructor error path, over the known option names, so its per-call array
319
+ * allocation never touches any hot path.
320
+ * @param {string} a
321
+ * @param {string} b
322
+ * @returns {number}
323
+ */
324
+ function editDistance(a, b) {
325
+ const m = a.length;
326
+ const n = b.length;
327
+ const prev = new Array(n + 1);
328
+ const cur = new Array(n + 1);
329
+ for (let j = 0; j <= n; j++) prev[j] = j;
330
+ for (let i = 1; i <= m; i++) {
331
+ cur[0] = i;
332
+ for (let j = 1; j <= n; j++) {
333
+ const cost = a.charCodeAt(i - 1) === b.charCodeAt(j - 1) ? 0 : 1;
334
+ let min = prev[j] + 1;
335
+ if (cur[j - 1] + 1 < min) min = cur[j - 1] + 1;
336
+ if (prev[j - 1] + cost < min) min = prev[j - 1] + cost;
337
+ cur[j] = min;
338
+ }
339
+ for (let j = 0; j <= n; j++) prev[j] = cur[j];
340
+ }
341
+ return prev[n];
342
+ }
343
+
344
+ /**
345
+ * The closest known config key to `key` within edit distance 2 (case-folded so
346
+ * `preAlloc`/`MAXNODES` resolve), or null when nothing is close. Cold path only.
347
+ * @param {string} key
348
+ * @returns {string|null}
349
+ */
350
+ function suggestKey(key) {
351
+ const lk = key.toLowerCase();
352
+ let best = null;
353
+ let bestD = 3;
354
+ for (let i = 0; i < ALLOWED_KEYS.length; i++) {
355
+ const d = editDistance(lk, ALLOWED_KEYS[i].toLowerCase());
356
+ if (d < bestD) { bestD = d; best = ALLOWED_KEYS[i]; }
357
+ }
358
+ return bestD <= 2 ? best : null;
359
+ }
360
+
361
+ /**
362
+ * Render a rejected value for an error message, e.g. `42 (number)`.
363
+ * Cold: this runs only on a throw path, never on any hot path. `String(symbol)`
364
+ * throws, so symbols are stringified defensively.
365
+ * @param {*} v
366
+ * @returns {string}
367
+ */
368
+ function received(v) {
369
+ return (typeof v === "symbol" ? v.toString() : String(v)) + " (" + typeof v + ")";
370
+ }
371
+
372
+ /**
373
+ * Validate that a numeric option is a finite integer >= 1. Cold: constructor
374
+ * error path only. Throws a {@link TypeError} prefixed `createRegistry: "<name>"`.
375
+ * @param {*} v
376
+ * @param {string} name
377
+ */
378
+ function requirePositiveInt(v, name) {
379
+ if (!Number.isInteger(v) || v < 1) {
380
+ throw new TypeError(
381
+ 'createRegistry: "' + name + '" must be a finite integer >= 1, received ' + received(v) + '.'
382
+ );
383
+ }
384
+ }
385
+
304
386
  export function createRegistry(config) {
305
387
  const NODE_PTR = Symbol("node_ptr");
306
388
  const NODE_GEN = Symbol("node_gen");
307
389
 
390
+ // --- 1.4.5 backport: createRegistry input validation (all cold, constructor-only).
391
+ // Config-shape gate: accept `undefined` or a non-null, non-array object; reject
392
+ // `null`, primitives and arrays BY NAME rather than dying later on `config.maxNodes`
393
+ // or an internal `nextFree` read (fail closed on an unverified state).
394
+ if (config !== undefined && (config === null || typeof config !== "object" || Array.isArray(config))) {
395
+ throw new TypeError(
396
+ 'createRegistry: "config" must be a plain object or undefined, received ' + received(config) + '.'
397
+ );
398
+ }
399
+ if (config !== undefined) {
400
+ // Per-option validation BY NAME -- a bad value throws `createRegistry: "<option>"`
401
+ // at construction, not a delayed internal TypeError on first use.
402
+ if (config.maxNodes !== undefined) requirePositiveInt(config.maxNodes, "maxNodes");
403
+ if (config.maxLinks !== undefined) requirePositiveInt(config.maxLinks, "maxLinks");
404
+ if (config.maxFlushPasses !== undefined) requirePositiveInt(config.maxFlushPasses, "maxFlushPasses");
405
+ if (config.prealloc !== undefined && config.prealloc !== "eager" && config.prealloc !== "lazy") {
406
+ throw new TypeError(
407
+ 'createRegistry: "prealloc" must be "eager" or "lazy", received ' + received(config.prealloc) + '.'
408
+ );
409
+ }
410
+ if (config.onCapacityExceeded !== undefined && config.onCapacityExceeded !== "throw" && config.onCapacityExceeded !== "grow") {
411
+ throw new TypeError(
412
+ 'createRegistry: "onCapacityExceeded" must be "throw" or "grow", received ' + received(config.onCapacityExceeded) + '.'
413
+ );
414
+ }
415
+ // Unknown-key rejection with a did-you-mean hint (`preAlloc` -> `prealloc`,
416
+ // `maxNods` -> `maxNodes`). Own enumerable keys only; cold path.
417
+ const badKeys = Object.keys(config);
418
+ for (let bi = 0; bi < badKeys.length; bi++) {
419
+ const bk = badKeys[bi];
420
+ if (ALLOWED_KEYS.indexOf(bk) === -1) {
421
+ const hint = suggestKey(bk);
422
+ throw new TypeError(
423
+ 'createRegistry: "' + bk + '" is not a recognized option' +
424
+ (hint !== null ? ' (did you mean "' + hint + '"?)' : '') +
425
+ '. Allowed: ' + ALLOWED_KEYS.join(", ") + '.'
426
+ );
427
+ }
428
+ }
429
+ }
430
+ // --- end 1.4.5 backport.
431
+
308
432
  let currentNodesCapacity = (config !== undefined && config.maxNodes !== undefined) ? config.maxNodes : 1024;
309
433
  let currentLinkCapacity = (config !== undefined && config.maxLinks !== undefined) ? config.maxLinks : currentNodesCapacity * 4;
310
434
  const policy = (config !== undefined && config.onCapacityExceeded !== undefined) ? config.onCapacityExceeded : "throw";
@@ -328,6 +452,20 @@ export function createRegistry(config) {
328
452
  // steady state is identical after warm-up, but the heap no longer carries
329
453
  // never-used live objects for every major GC to mark.
330
454
  const prealloc = (config !== undefined && config.prealloc !== undefined) ? config.prealloc : "eager";
455
+ // Eager-construction ceiling (cold): `"eager"` builds `(maxNodes + maxLinks)`
456
+ // objects up front; a finite-but-absurd capacity (e.g. `1e9`) would OOM the
457
+ // process with an uncatchable SIGABRT, not a throw. Refuse BY NAME before
458
+ // allocating. Named for the larger driver. `"lazy"` keeps its unbounded ledger.
459
+ if (prealloc === "eager" && (currentNodesCapacity + currentLinkCapacity) > EAGER_CONSTRUCT_CEILING) {
460
+ const driver = currentLinkCapacity > currentNodesCapacity ? "maxLinks" : "maxNodes";
461
+ throw new TypeError(
462
+ 'createRegistry: "' + driver + '" eager construction of ' +
463
+ (currentNodesCapacity + currentLinkCapacity) + ' objects (maxNodes ' +
464
+ currentNodesCapacity + ' + maxLinks ' + currentLinkCapacity + ') exceeds the ceiling of ' +
465
+ EAGER_CONSTRUCT_CEILING + '. Use prealloc:"lazy" for an unbounded on-demand ledger, ' +
466
+ 'or lower the capacity.'
467
+ );
468
+ }
331
469
  const nodePool = [];
332
470
  let freeNodeHead = null;
333
471
  const linkPool = [];
@@ -1896,6 +2034,12 @@ export function createRegistry(config) {
1896
2034
  pooledLinks: currentLinkCapacity - activeLinks,
1897
2035
  linkPoolCapacity: currentLinkCapacity,
1898
2036
  nodePoolCapacity: currentNodesCapacity,
2037
+ // 1.4.5 backport: TRUE pool population (nodePool.length / linkPool.length),
2038
+ // distinct from the *Capacity ledgers above. Under prealloc:"lazy" (or a
2039
+ // silently-flipped `prealloc` typo) population stays 0 while capacity reads
2040
+ // the ledger -- so a mis-set prealloc is now observable, not telemetry-blind.
2041
+ nodePoolPopulation: nodePool.length,
2042
+ linkPoolPopulation: linkPool.length,
1899
2043
  activeNodes,
1900
2044
  // 1.4: cumulative lifecycle counters (monotonic; reset by destroy()).
1901
2045
  // 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.9.0-preview.6, 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.9.0-preview.5** (current): a **packaging-only cut** -- the engine is
56
+ - **1.9.0-preview.6** (current): backports the **1.4.5 `createRegistry` input validation** (all four findings) onto the 1.9.0-preview.5 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.9.0-preview.6]`.
57
+ - **1.9.0-preview.5**: a **packaging-only cut** -- the engine is
57
58
  behaviourally unchanged from preview.4 (`Signal.js` differs only in its header
58
59
  banner string). Two fixes make the tarball honour its own manifest. (1) The
59
60
  promised **`Signal.d.ts` now ships**: since 1.5.0 `package.json` has advertised
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zakkster/lite-signal",
3
- "version": "1.9.0-preview.5",
3
+ "version": "1.9.0-preview.6",
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",