@zakkster/lite-signal 1.7.0-alpha.5 → 1.7.0-alpha.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.7.0-alpha.6] -- 2026-08-20
8
+
9
+ Backports the **1.4.5 `createRegistry` input validation** (all four findings) onto
10
+ the 1.7.0-alpha.5 engine. Supersedes 1.7.0-alpha.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.7.0-alpha.4] -- 2026-08-18
8
49
 
9
50
  **Torture-suite and test parity with the shipped 1.4.4 canonical suite.** This is
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.7.0-alpha.3
2
+ * @zakkster/lite-signal v1.7.0-alpha.6
3
3
  * --------------------
4
4
  * 1.7.0 -- flushStrategy: registry-level effect-delivery policy.
5
5
  *
@@ -237,10 +237,134 @@ export class CapacityError extends Error {
237
237
  * Error prefixed `"CycleError:"`.
238
238
  * @returns {Registry}
239
239
  */
240
+ /** The only config keys {@link createRegistry} recognizes. Anything else is
241
+ * rejected at construction with a did-you-mean hint (fail closed on an
242
+ * unverified state -- an unknown key is an error, never a silent ignore). */
243
+ const ALLOWED_KEYS = ["maxNodes", "maxLinks", "prealloc", "onCapacityExceeded", "maxFlushPasses", "flushStrategy"];
244
+
245
+ /** Ceiling on eager pool construction: `(maxNodes + maxLinks)` objects. A finite
246
+ * but absurd `maxNodes` (e.g. `1e9`, a plausible typo for `1e5`) that would
247
+ * otherwise OOM the process is refused BY NAME at construction rather than
248
+ * allocating forever. Only the `"eager"` path is bounded; `"lazy"` keeps its
249
+ * unbounded ledger. `1 << 24` == 16777216. */
250
+ const EAGER_CONSTRUCT_CEILING = 1 << 24;
251
+
252
+ /**
253
+ * Levenshtein edit distance between two short strings. Cold: called only on the
254
+ * constructor error path, over the known option names, so its per-call array
255
+ * allocation never touches any hot path.
256
+ * @param {string} a
257
+ * @param {string} b
258
+ * @returns {number}
259
+ */
260
+ function editDistance(a, b) {
261
+ const m = a.length;
262
+ const n = b.length;
263
+ const prev = new Array(n + 1);
264
+ const cur = new Array(n + 1);
265
+ for (let j = 0; j <= n; j++) prev[j] = j;
266
+ for (let i = 1; i <= m; i++) {
267
+ cur[0] = i;
268
+ for (let j = 1; j <= n; j++) {
269
+ const cost = a.charCodeAt(i - 1) === b.charCodeAt(j - 1) ? 0 : 1;
270
+ let min = prev[j] + 1;
271
+ if (cur[j - 1] + 1 < min) min = cur[j - 1] + 1;
272
+ if (prev[j - 1] + cost < min) min = prev[j - 1] + cost;
273
+ cur[j] = min;
274
+ }
275
+ for (let j = 0; j <= n; j++) prev[j] = cur[j];
276
+ }
277
+ return prev[n];
278
+ }
279
+
280
+ /**
281
+ * The closest known config key to `key` within edit distance 2 (case-folded so
282
+ * `preAlloc`/`MAXNODES` resolve), or null when nothing is close. Cold path only.
283
+ * @param {string} key
284
+ * @returns {string|null}
285
+ */
286
+ function suggestKey(key) {
287
+ const lk = key.toLowerCase();
288
+ let best = null;
289
+ let bestD = 3;
290
+ for (let i = 0; i < ALLOWED_KEYS.length; i++) {
291
+ const d = editDistance(lk, ALLOWED_KEYS[i].toLowerCase());
292
+ if (d < bestD) { bestD = d; best = ALLOWED_KEYS[i]; }
293
+ }
294
+ return bestD <= 2 ? best : null;
295
+ }
296
+
297
+ /**
298
+ * Render a rejected value for an error message, e.g. `42 (number)`.
299
+ * Cold: this runs only on a throw path, never on any hot path. `String(symbol)`
300
+ * throws, so symbols are stringified defensively.
301
+ * @param {*} v
302
+ * @returns {string}
303
+ */
304
+ function received(v) {
305
+ return (typeof v === "symbol" ? v.toString() : String(v)) + " (" + typeof v + ")";
306
+ }
307
+
308
+ /**
309
+ * Validate that a numeric option is a finite integer >= 1. Cold: constructor
310
+ * error path only. Throws a {@link TypeError} prefixed `createRegistry: "<name>"`.
311
+ * @param {*} v
312
+ * @param {string} name
313
+ */
314
+ function requirePositiveInt(v, name) {
315
+ if (!Number.isInteger(v) || v < 1) {
316
+ throw new TypeError(
317
+ 'createRegistry: "' + name + '" must be a finite integer >= 1, received ' + received(v) + '.'
318
+ );
319
+ }
320
+ }
321
+
240
322
  export function createRegistry(config) {
241
323
  const NODE_PTR = Symbol("node_ptr");
242
324
  const NODE_GEN = Symbol("node_gen");
243
325
 
326
+ // --- 1.4.5 backport: createRegistry input validation (all cold, constructor-only).
327
+ // Config-shape gate: accept `undefined` or a non-null, non-array object; reject
328
+ // `null`, primitives and arrays BY NAME rather than dying later on `config.maxNodes`
329
+ // or an internal `nextFree` read (fail closed on an unverified state).
330
+ if (config !== undefined && (config === null || typeof config !== "object" || Array.isArray(config))) {
331
+ throw new TypeError(
332
+ 'createRegistry: "config" must be a plain object or undefined, received ' + received(config) + '.'
333
+ );
334
+ }
335
+ if (config !== undefined) {
336
+ // Per-option validation BY NAME -- a bad value throws `createRegistry: "<option>"`
337
+ // at construction, not a delayed internal TypeError on first use.
338
+ if (config.maxNodes !== undefined) requirePositiveInt(config.maxNodes, "maxNodes");
339
+ if (config.maxLinks !== undefined) requirePositiveInt(config.maxLinks, "maxLinks");
340
+ if (config.maxFlushPasses !== undefined) requirePositiveInt(config.maxFlushPasses, "maxFlushPasses");
341
+ if (config.prealloc !== undefined && config.prealloc !== "eager" && config.prealloc !== "lazy") {
342
+ throw new TypeError(
343
+ 'createRegistry: "prealloc" must be "eager" or "lazy", received ' + received(config.prealloc) + '.'
344
+ );
345
+ }
346
+ if (config.onCapacityExceeded !== undefined && config.onCapacityExceeded !== "throw" && config.onCapacityExceeded !== "grow") {
347
+ throw new TypeError(
348
+ 'createRegistry: "onCapacityExceeded" must be "throw" or "grow", received ' + received(config.onCapacityExceeded) + '.'
349
+ );
350
+ }
351
+ // Unknown-key rejection with a did-you-mean hint (`preAlloc` -> `prealloc`,
352
+ // `maxNods` -> `maxNodes`). Own enumerable keys only; cold path.
353
+ const badKeys = Object.keys(config);
354
+ for (let bi = 0; bi < badKeys.length; bi++) {
355
+ const bk = badKeys[bi];
356
+ if (ALLOWED_KEYS.indexOf(bk) === -1) {
357
+ const hint = suggestKey(bk);
358
+ throw new TypeError(
359
+ 'createRegistry: "' + bk + '" is not a recognized option' +
360
+ (hint !== null ? ' (did you mean "' + hint + '"?)' : '') +
361
+ '. Allowed: ' + ALLOWED_KEYS.join(", ") + '.'
362
+ );
363
+ }
364
+ }
365
+ }
366
+ // --- end 1.4.5 backport.
367
+
244
368
  let currentNodesCapacity = (config !== undefined && config.maxNodes !== undefined) ? config.maxNodes : 1024;
245
369
  let currentLinkCapacity = (config !== undefined && config.maxLinks !== undefined) ? config.maxLinks : currentNodesCapacity * 4;
246
370
  const policy = (config !== undefined && config.onCapacityExceeded !== undefined) ? config.onCapacityExceeded : "throw";
@@ -264,6 +388,20 @@ export function createRegistry(config) {
264
388
  // steady state is identical after warm-up, but the heap no longer carries
265
389
  // never-used live objects for every major GC to mark.
266
390
  const prealloc = (config !== undefined && config.prealloc !== undefined) ? config.prealloc : "eager";
391
+ // Eager-construction ceiling (cold): `"eager"` builds `(maxNodes + maxLinks)`
392
+ // objects up front; a finite-but-absurd capacity (e.g. `1e9`) would OOM the
393
+ // process with an uncatchable SIGABRT, not a throw. Refuse BY NAME before
394
+ // allocating. Named for the larger driver. `"lazy"` keeps its unbounded ledger.
395
+ if (prealloc === "eager" && (currentNodesCapacity + currentLinkCapacity) > EAGER_CONSTRUCT_CEILING) {
396
+ const driver = currentLinkCapacity > currentNodesCapacity ? "maxLinks" : "maxNodes";
397
+ throw new TypeError(
398
+ 'createRegistry: "' + driver + '" eager construction of ' +
399
+ (currentNodesCapacity + currentLinkCapacity) + ' objects (maxNodes ' +
400
+ currentNodesCapacity + ' + maxLinks ' + currentLinkCapacity + ') exceeds the ceiling of ' +
401
+ EAGER_CONSTRUCT_CEILING + '. Use prealloc:"lazy" for an unbounded on-demand ledger, ' +
402
+ 'or lower the capacity.'
403
+ );
404
+ }
267
405
  const nodePool = [];
268
406
  let freeNodeHead = null;
269
407
  const linkPool = [];
@@ -1801,6 +1939,12 @@ export function createRegistry(config) {
1801
1939
  pooledLinks: currentLinkCapacity - activeLinks,
1802
1940
  linkPoolCapacity: currentLinkCapacity,
1803
1941
  nodePoolCapacity: currentNodesCapacity,
1942
+ // 1.4.5 backport: TRUE pool population (nodePool.length / linkPool.length),
1943
+ // distinct from the *Capacity ledgers above. Under prealloc:"lazy" (or a
1944
+ // silently-flipped `prealloc` typo) population stays 0 while capacity reads
1945
+ // the ledger -- so a mis-set prealloc is now observable, not telemetry-blind.
1946
+ nodePoolPopulation: nodePool.length,
1947
+ linkPoolPopulation: linkPool.length,
1804
1948
  activeNodes,
1805
1949
  // 1.4: cumulative lifecycle counters (monotonic; reset by destroy()).
1806
1950
  // Derive: allocationRate = deltatotalAllocations/deltat; poolReuseRate =
package/llms.txt CHANGED
@@ -31,7 +31,7 @@ triggering write -- no `queueMicrotask`, no promises, no scheduler ticks.
31
31
  - **isTracking**: `isTracking()` returns true iff a read right now would record a dependency on this registry (for wrappers that lazily allocate signals).
32
32
  - **onCleanup**: registers teardown for the current computation; fires before each re-run and once on dispose. Works in effects and computeds.
33
33
  - **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.
34
- - **Registry**: `createRegistry({ maxNodes, maxLinks, prealloc, onCapacityExceeded, maxFlushPasses, flushStrategy })` 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. `flushStrategy` (1.7.0; `"eager"` default | `"sab"` | `"manual"`) chooses when effects deliver; every registry also exposes `r.flush()`.
34
+ - **Registry**: `createRegistry({ maxNodes, maxLinks, prealloc, onCapacityExceeded, maxFlushPasses, flushStrategy })` 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. `flushStrategy` (1.7.0; `"eager"` default | `"sab"` | `"manual"`) chooses when effects deliver; every registry also exposes `r.flush()`. **Config is validated at construction (1.7.0-alpha.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**.
35
35
  - **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.
36
36
 
37
37
  ## Architecture invariants
@@ -59,7 +59,8 @@ triggering write -- no `queueMicrotask`, no promises, no scheduler ticks.
59
59
 
60
60
  ## Version notes
61
61
 
62
- - **1.7.0-alpha.4** (current): **torture-suite + test parity with the shipped 1.4.4
62
+ - **1.7.0-alpha.6** (current): backports the **1.4.5 `createRegistry` input validation** (all four findings) onto the 1.7.0-alpha.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.7.0-alpha.6]`.
63
+ - **1.7.0-alpha.4**: **torture-suite + test parity with the shipped 1.4.4
63
64
  canonical suite** -- verification-only, the `Signal.js`/`Signal.d.ts` engine is
64
65
  UNCHANGED (shasum-identical). Five scenarios were ported to bring `bench/torture/`
65
66
  from 17 to **22** (19 semantic + 3 soak): `lifecycle-torture`, `owner-torture`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zakkster/lite-signal",
3
- "version": "1.7.0-alpha.5",
3
+ "version": "1.7.0-alpha.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",