Skip to content

abso-core

Public
Check passed

Versions 174 to 175

Compare

+35 −1 in 3 places
Lines 1–20 at 175 (were 1–3 at 174)
1+/** Internal values may expose an exact streaming representation without changing public toJSON. */
2+const streamingValues = new WeakMap<object, () => unknown>();
3+export function registerJsonChunkValue(value: object, representation: () => unknown): void {
4+ streamingValues.set(value, representation);
5+}
6+
7+/** A JSON string backed by bounded, replayable UTF-16 chunks. */
8+export class JsonStringChunks {
9+ readonly chunks: () => Iterable<string>;
10+ constructor(chunks: () => Iterable<string>) {
11+ this.chunks = chunks;
12+ }
13+ toJSON(): string {
14+ return [...this.chunks()].join("");
15+ }
16+}
118/** JSON.stringify-compatible chunks for canonical data, without a whole-value string.
219 * Individual input strings and object key lists still belong to the caller.
320 */
Lines 33–42 at 175 (were 16–22 at 174)
1633 yield '"';
1734 }
1835 const normalize = (value: unknown, key: string): unknown => {
36+ if (value instanceof JsonStringChunks) return value;
1937 if (value !== null && typeof value === "object") {
38+ const streaming = streamingValues.get(value);
39+ if (streaming) return streaming();
2040 const toJSON = (value as { toJSON?: unknown }).toJSON;
2141 if (typeof toJSON === "function") return toJSON.call(value, key);
2242 }
Lines 44–64 at 175 (were 24–30 at 174)
2444 };
2545 const omitted = (value: unknown) => value === undefined || typeof value === "function" || typeof value === "symbol";
2646 function* encode(value: unknown): IterableIterator<string> {
27− if (typeof value === "string") yield* string(value);
47+ if (value instanceof JsonStringChunks) {
48+ yield '"';
49+ let pending = "";
50+ for (const chunk of value.chunks()) {
51+ if (typeof chunk !== "string" || chunk.length > 16384) throw Error("JSON string chunk exceeds bound");
52+ const text = pending + chunk;
53+ let end = text.length;
54+ const last = text.charCodeAt(end - 1);
55+ if (last >= 0xd800 && last <= 0xdbff) end--;
56+ pending = text.slice(end);
57+ if (end) yield JSON.stringify(text.slice(0, end)).slice(1, -1);
58+ }
59+ if (pending) yield JSON.stringify(pending).slice(1, -1);
60+ yield '"';
61+ } else if (typeof value === "string") yield* string(value);
2862 else if (value === null || typeof value === "boolean" || typeof value === "number") yield JSON.stringify(value);
2963 else if (typeof value !== "object" || value === null) throw Error("unsupported canonical JSON value");
3064 else {
MCP
compare on this site's /mcp
CLI
abso diff 174 175 src/engine/json-value-chunks.ts --json
JSON
/christopher/abso-core/compare/174..175?file=src%2Fengine%2Fjson-value-chunks.ts&format=json