You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**Assembler** (`src/assembler.js`, implementation in `src/core/assembler.js`) interprets the token stream and reconstructs JavaScript objects. Plain class — no `EventEmitter` inheritance in 3.x.
119
119
- Used internally by all streamers via `streamBase`.
120
+
- Reads only packed tokens (`keyValue`, `stringValue`, `numberValue`); streamed chunks are ignored.
120
121
-`Assembler.connectTo(stream, {onDone: asm => …})` is substrate-aware: accepts either a Node `Readable` (attaches `'data'` listener) or a Web `ReadableStream` (pumps via `getReader()`). Detection via `typeof stream.getReader === 'function'`. `asm.onDone(fn)` can set/clear the callback after construction.
121
122
- For hot paths, prefer a manual `for await (const tok of readable) asm.consume(tok)` loop over `connectTo` — no async-closure overhead, errors propagate directly. `FlexAssembler` has the same shape.
122
123
-`asm.tapChain` is a function for use in `chain()`.
Copy file name to clipboardExpand all lines: ARCHITECTURE.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -150,6 +150,7 @@ All filters are built on `filterBase` (`src/filters/filter-base.js`):
150
150
- It maintains a path stack tracking the current JSON position.
151
151
-`filter` option: a string, RegExp, or function `(stack, chunk) → boolean` that determines whether to accept or reject each subobject.
152
152
-`makeStackDiffer` generates structural tokens (start/end object/array, key tokens) to reconstruct the surrounding JSON envelope when filtering.
153
+
- Keys are tracked only from `keyValue` tokens, so key-based paths and parent recreation need packed keys from upstream (the parser's default). Replayed parent keys are always packed; their streamed form mirrors upstream unless `streamKeys` is set.
`Assembler` — a plain class (no `EventEmitter` inheritance) that interprets the token stream and reconstructs JavaScript objects. 3.0 dropped the `'done'` event in favor of an `onDone` callback option.
199
+
`Assembler` — a plain class (no `EventEmitter` inheritance) that interprets the token stream and reconstructs JavaScript objects. It reads only packed tokens (`keyValue`, `stringValue`, `numberValue`); streamed chunks are ignored, so the parser must pack keys, strings, and numbers (its default). 3.0 dropped the `'done'` event in favor of an `onDone` callback option.
200
200
201
201
Constructor options:
202
202
- `reviver` (function) — like `JSON.parse` reviver. Called as `reviver(key, value)`.
@@ -399,6 +399,9 @@ All filters are built on `filterBase` and accept these common options:
399
399
- **RegExp** — matches when `regExp.test(stack.join(separator))`.
- `pathSeparator` (string, default: `'.'`) — separator for path matching.
402
+
- `streamKeys` (boolean; seeded by `streamValues`) — replay parent keys as `startKey`/`stringChunk`/`endKey` too. Default: mirrors upstream (on once streamed keys were received). Replayed keys are always emitted as `keyValue`.
403
+
- `packKeys` — deprecated no-op on filters (still configures the parser in a `withParser()` bag).
404
+
- Input requirement: key-based paths and parent recreation need packed keys (`keyValue`) from upstream — the parser's default.
402
405
- `once` (boolean) — if true, stop filtering after the first match.
403
406
- `maxDepth` (number, default: `1024`) — maximum JSON nesting depth to evaluate; a token nested deeper throws a `RangeError`. A guard for untrusted input with unbounded nesting. Pass `Infinity` to disable.
404
407
- `streamKeys` (boolean) — control key streaming in output.
@@ -407,7 +410,7 @@ Each filter ships in both substrates. The Node entry (`stream-json/filters/<name
407
410
408
411
### pick(options)
409
412
410
-
Passes only matching subobjects, discards everything else.
413
+
Passes only matching subobjects, discards everything else. Key-based paths need packed keys (`keyValue`) from upstream — the parser's default.
Replaces matching subobjects with a replacement value.
430
+
Replaces matching subobjects with a replacement value. Needs packed keys (`keyValue`) from upstream — the parser's default; replayed parent keys are always packed.
428
431
429
432
Extra option:
430
433
- `replacement` — the replacement:
@@ -450,7 +453,7 @@ chain([parser(), replace({
450
453
451
454
### ignore(options)
452
455
453
-
Removes matching subobjects completely. A variant of Replace with `replacement = none`.
456
+
Removes matching subobjects completely. A variant of Replace with `replacement = none`. Needs packed keys (`keyValue`) from upstream — the parser's default; replayed parent keys are always packed.
454
457
455
458
```js
456
459
import {ignore} from 'stream-json/filters/ignore.js';
Keeps matching subobjects while preserving the surrounding JSON structure.
468
+
Keeps matching subobjects while preserving the surrounding JSON structure. Needs packed keys (`keyValue`) from upstream — the parser's default; replayed parent keys are always packed.
466
469
467
470
Extra option:
468
471
- `acceptObjects` (boolean) — if true, accepts entire objects (not just tokens).
The differ honors `streamKeys`, `streamValues`, `packKeys`, and `pathSeparator` from the filter's options.
513
+
The differ honors `streamKeys`, `streamValues`, and `pathSeparator` from the filter's options. It always replays `keyValue`; the streamed form follows `streamKeys`, which by default mirrors upstream.
511
514
512
515
## Streamers
513
516
514
-
All streamers are built on `streamBase` and produce `{key, value}` objects. Each is generic in the assembled value type — `streamArray<T>()`, `streamValues<T>()`, `streamObject<T>()` (and their `.withParser<T>()`) carry `T` through to the item's `value` field; the default is `unknown`. The item shape is the exported `KeyedValue<K, T>` type (`stream-json/streamers/stream-base.js`): `K` is `string` for `streamObject` (the property name) and `number` for `streamArray` (the array index) and `streamValues` (a sequential counter); `StreamArrayItem<T>` / `StreamObjectItem<T>` / `StreamValuesItem<T>` are aliases of it.
517
+
All streamers are built on `streamBase` and produce `{key, value}` objects. They read only packed tokens (`keyValue`, `stringValue`, `numberValue`) — the parser's default. Each is generic in the assembled value type — `streamArray<T>()`, `streamValues<T>()`, `streamObject<T>()` (and their `.withParser<T>()`) carry `T` through to the item's `value` field; the default is `unknown`. The item shape is the exported `KeyedValue<K, T>` type (`stream-json/streamers/stream-base.js`): `K` is `string` for `streamObject` (the property name) and `number` for `streamArray` (the array index) and `streamValues` (a sequential counter); `StreamArrayItem<T>` / `StreamObjectItem<T>` / `StreamValuesItem<T>` are aliases of it.
515
518
516
519
Common option:
517
520
- `objectFilter` (function) `(asm) => boolean|null` — called during assembly. Return `true` to accept, `false` to reject (abandon assembly), `null`/`undefined` for undecided.
@@ -626,7 +629,7 @@ Creates a `gen(parser(options), fn(options))` pipeline — a function for use in
626
629
627
630
Browser-safe Web-only entry: `stream-json/web/utils/with-parser.js` (has only `asWebStream`).
628
631
629
-
Most components export `.withParser(options)`, `.withParserAsStream(options)`, and `.withParserAsWebStream(options)` static methods as a convenience:
632
+
Most components export `.withParser(options)`, `.withParserAsStream(options)`, and `.withParserAsWebStream(options)` static methods as a convenience. They prepend `packKeys: true` to the options bag, so the parser packs keys even under `packValues: false` (filters and streamers need them); the bare utility adds nothing:
Like Assembler but with custom containers (Map, Set, custom classes) at specific paths. Standalone clone — same API surface (`connectTo`, `tapChain`, `onDone`). `FlexAssembler.connectTo` is substrate-aware: accepts either a Node `Readable` or a Web `ReadableStream`.
689
+
Like Assembler but with custom containers (Map, Set, custom classes) at specific paths. Reads only packed tokens, like Assembler. Standalone clone — same API surface (`connectTo`, `tapChain`, `onDone`). `FlexAssembler.connectTo` is substrate-aware: accepts either a Node `Readable` or a Web `ReadableStream`.
687
690
688
691
Options:
689
692
- `objectRules` — array of rules for objects: `{filter, create, add, finalize?}`.
Copy file name to clipboardExpand all lines: llms.txt
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,7 @@ For the SAX-style event API on Web, use the `EventTarget`-based variants from `s
67
67
68
68
### Assembler
69
69
70
-
`Assembler` — class that reconstructs JS objects from tokens. Receives a per-value callback via the `onDone` option.
70
+
`Assembler` — class that reconstructs JS objects from tokens. Reads only packed tokens (`keyValue`, `stringValue`, `numberValue`); streamed chunks are ignored. Receives a per-value callback via the `onDone` option.
71
71
72
72
```js
73
73
import Assembler from 'stream-json/assembler.js';
@@ -118,7 +118,7 @@ e.addEventListener('keyValue', ev => console.log(ev.detail));
118
118
119
119
## Filters
120
120
121
-
All filters accept `{filter, pathSeparator, once, streamKeys, maxDepth}` options. `filter` can be a string, RegExp, or `(stack, chunk) => boolean`. `maxDepth` caps the JSON nesting depth a filter evaluates (default `1024`; a deeper token throws a `RangeError`, `Infinity` disables the limit).
121
+
All filters accept `{filter, pathSeparator, once, maxDepth, streamKeys}` options. Key-based paths and parent recreation need packed keys from upstream (the parser's default). Replayed parent keys are always packed; their streamed form mirrors upstream unless `streamKeys` says otherwise. `packKeys` on a filter is a deprecated no-op. `filter` can be a string, RegExp, or `(stack, chunk) => boolean`. `maxDepth` caps the JSON nesting depth a filter evaluates (default `1024`; a deeper token throws a `RangeError`, `Infinity` disables the limit).
122
122
123
123
- **`pick(options)`** — passes only matching subobjects, discards the rest.
124
124
- **`replace(options)`** — replaces matching subobjects. Extra option: `replacement` (function, token, or array of tokens).
@@ -143,7 +143,7 @@ chain([
143
143
144
144
## Streamers
145
145
146
-
Assemble complete JS objects from a token stream. All produce `{key, value}` objects, generic in the assembled value type (`streamArray<T>()`, `streamValues<T>()`, `streamObject<T>()`; `value` defaults to `unknown`). The item shape is the exported `KeyedValue<K, T>` type — `key` is a `string` for `streamObject`, a `number` for the others.
146
+
Assemble complete JS objects from a token stream. They read only packed tokens (`keyValue`, `stringValue`, `numberValue`) — the parser's default. All produce `{key, value}` objects, generic in the assembled value type (`streamArray<T>()`, `streamValues<T>()`, `streamObject<T>()`; `value` defaults to `unknown`). The item shape is the exported `KeyedValue<K, T>` type — `key` is a `string` for `streamObject`, a `number` for the others.
147
147
148
148
- **`streamValues(options)`** — streams successive JSON values. Use with `jsonStreaming` or after `pick`.
149
149
- **`streamArray(options)`** — streams elements of a single top-level array.
0 commit comments