@pretable/stream-adapter 0.10.0 → 0.11.0
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/dist/index.cjs +393 -359
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +54 -42
- package/dist/index.d.cts.map +1 -0
- package/dist/{index.d.ts → index.d.mts} +54 -42
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +392 -357
- package/dist/index.mjs.map +1 -0
- package/package.json +5 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["create","push","isArrayNode","isComplete","finish","create","push","isObjectNode","finish"],"sources":["../src/create-batcher.ts","../src/connect-element-stream.ts","../src/connect-partial-stream.ts","../src/parse-element-stream.ts","../src/parse-partial-stream.ts"],"sourcesContent":["import type { RowModelLike, TransactionBatcher } from \"./types\";\n\n/**\n * Create a `requestAnimationFrame`-batched mutator that coalesces\n * `add` / `update` / `remove` calls into a single `applyTransaction` per\n * frame. Use this when driving a row model from a stream that emits faster\n * than the browser can render.\n *\n * @example\n * ```ts\n * const batcher = createBatcher(rowModel);\n * batcher.add([{ id: \"1\", name: \"Ada\" }]);\n * batcher.update([{ id: \"1\", changes: { age: 36 } }]);\n * batcher.flush(); // optional — RAF will flush automatically\n * ```\n *\n * @public\n */\nexport function createBatcher<\n TRow extends object,\n TRowId extends string | number,\n>(rowModel: RowModelLike<TRow, TRowId>): TransactionBatcher<TRow, TRowId> {\n let addBuffer: TRow[] = [];\n let updateBuffer: Array<{\n id: TRowId;\n changes: Partial<TRow>;\n }> = [];\n let removeBuffer: TRowId[] = [];\n let rafId: number | null = null;\n let disposed = false;\n let rejectError!: (error: unknown) => void;\n const errorListeners = new Set<(error: unknown) => void>();\n let failed = false;\n let failure: unknown;\n const error = new Promise<never>((_resolve, reject) => {\n rejectError = reject;\n });\n // A connector may attach after the RAF callback fires. Keep that race from\n // surfacing as an unhandled rejection while preserving the rejection for\n // every consumer that awaits the public channel.\n error.catch(() => undefined);\n\n function fail(error: unknown): void {\n if (disposed) return;\n disposed = true;\n failed = true;\n failure = error;\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n rafId = null;\n }\n addBuffer = [];\n updateBuffer = [];\n removeBuffer = [];\n const listeners = [...errorListeners];\n errorListeners.clear();\n for (const listener of listeners) {\n try {\n listener(error);\n } catch {\n // A hostile observer cannot replace the exact model failure.\n }\n }\n rejectError(error);\n }\n\n function scheduleFlush(): void {\n if (rafId !== null || disposed) return;\n rafId = requestAnimationFrame(() => {\n rafId = null;\n if (disposed) return;\n try {\n applyBuffered();\n } catch (error) {\n fail(error);\n }\n });\n }\n\n function applyBuffered(): void {\n if (\n addBuffer.length === 0 &&\n updateBuffer.length === 0 &&\n removeBuffer.length === 0\n ) {\n return;\n }\n\n const bufferedAdds = addBuffer;\n const bufferedUpdates = updateBuffer;\n const bufferedRemovals = removeBuffer;\n addBuffer = [];\n updateBuffer = [];\n removeBuffer = [];\n\n const transaction: {\n add?: TRow[];\n update?: Array<{ id: TRowId; changes: Partial<TRow> }>;\n remove?: TRowId[];\n } = {};\n\n if (bufferedAdds.length > 0) {\n transaction.add = bufferedAdds.map((row) => ({ ...row }));\n }\n if (bufferedUpdates.length > 0) {\n transaction.update = bufferedUpdates.map(({ id, changes }) => ({\n id,\n changes: { ...changes },\n }));\n }\n if (bufferedRemovals.length > 0) {\n transaction.remove = [...bufferedRemovals];\n }\n\n rowModel.applyTransaction(transaction);\n }\n\n return {\n error,\n subscribeError(listener) {\n if (failed) {\n try {\n listener(failure);\n } catch {\n // Keep the exact model failure on `error` observable.\n }\n return () => undefined;\n }\n if (disposed) return () => undefined;\n errorListeners.add(listener);\n return () => errorListeners.delete(listener);\n },\n add(rows) {\n if (disposed) return;\n addBuffer.push(...rows);\n scheduleFlush();\n },\n update(patches) {\n if (disposed) return;\n updateBuffer.push(...patches);\n scheduleFlush();\n },\n remove(ids) {\n if (disposed) return;\n removeBuffer.push(...ids);\n scheduleFlush();\n },\n flush() {\n if (disposed) return;\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n rafId = null;\n }\n applyBuffered();\n },\n dispose() {\n if (disposed) return;\n disposed = true;\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n rafId = null;\n }\n addBuffer = [];\n updateBuffer = [];\n removeBuffer = [];\n errorListeners.clear();\n },\n };\n}\n","import type { RowModelLike, StreamConnection } from \"./types\";\nimport { createBatcher } from \"./create-batcher\";\n\n/**\n * Drive a row model from an `AsyncIterable<TRow>`. Each yielded row is added\n * via a {@link createBatcher | RAF batcher}; the returned\n * {@link StreamConnection} resolves `done` when the stream ends and\n * supports `dispose()` for early cancellation.\n *\n * Pair with {@link parseElementStream} to turn a raw UTF-8 string stream\n * (e.g., from `fetch().body`) into a row stream end-to-end.\n *\n * @public\n */\nexport function connectElementStream<\n TRow extends object,\n TRowId extends string | number,\n>(\n rowModel: RowModelLike<TRow, TRowId>,\n stream: AsyncIterable<TRow>,\n): StreamConnection {\n const iterator = stream[Symbol.asyncIterator]();\n const batcher = createBatcher(rowModel);\n let disposed = false;\n let sourceClosed = false;\n\n let resolveDone!: () => void;\n let rejectDone!: (err: unknown) => void;\n const done = new Promise<void>((resolve, reject) => {\n resolveDone = resolve;\n rejectDone = reject;\n });\n // Swallow unhandled-rejection warnings if the caller hasn't attached a\n // handler before the stream rejects. Consumers that await `done` still\n // observe the rejection — attaching `.catch` here doesn't consume it.\n done.catch(() => undefined);\n\n const closeSource = () => {\n if (sourceClosed) return;\n sourceClosed = true;\n try {\n const closing = iterator.return?.();\n if (closing !== undefined)\n void Promise.resolve(closing).catch(() => undefined);\n } catch {\n // Source closure is best-effort; the transaction/source failure remains\n // the exact public rejection.\n }\n };\n\n let settled = false;\n const settle = (\n failure?: { readonly error: unknown },\n flush = true,\n close = failure !== undefined,\n ) => {\n if (settled) return;\n settled = true;\n disposed = true;\n if (close) closeSource();\n let finalFailure = failure;\n if (flush) {\n try {\n batcher.flush();\n } catch (error) {\n finalFailure ??= { error };\n }\n }\n batcher.dispose();\n if (finalFailure === undefined) resolveDone();\n else rejectDone(finalFailure.error);\n };\n\n batcher.subscribeError((error: unknown) => {\n settle({ error }, false, true);\n });\n\n void (async () => {\n try {\n while (!disposed) {\n const result = await iterator.next();\n if (disposed) return;\n if (result.done) {\n settle();\n return;\n }\n batcher.add([result.value]);\n }\n } catch (err) {\n settle({ error: err }, true, true);\n }\n })().catch((error: unknown) => settle({ error }));\n\n return {\n done,\n dispose() {\n if (disposed) return;\n settle(undefined, true, true);\n },\n };\n}\n","import type { RowModelLike, StreamConnection } from \"./types\";\nimport { createBatcher } from \"./create-batcher\";\n\nfunction sameValueZero<T extends string | number>(left: T, right: T): boolean {\n return (\n left === right ||\n (typeof left === \"number\" &&\n typeof right === \"number\" &&\n Number.isNaN(left) &&\n Number.isNaN(right))\n );\n}\n\n/**\n * Options for {@link connectPartialStream}. `rowId` is the fixed target for\n * every partial update. Unknown targets are reported through `onIssue`; an\n * optional `createRow` factory may turn the partial into a complete row to add.\n *\n * @public\n */\nexport interface PartialStreamOptions<\n TRow extends object,\n TRowId extends string | number,\n> {\n readonly rowId: TRowId;\n readonly onIssue?: (issue: {\n readonly code: \"unknown-update-id\";\n readonly rowId: TRowId;\n }) => void;\n readonly createRow?: (partial: Partial<TRow>, id: TRowId) => TRow;\n}\n\n/**\n * Drive a row model from an `AsyncIterable<Partial<TRow>>`. Every yielded\n * partial updates the fixed `options.rowId` via a RAF-batched\n * `{ id, changes }` transaction. A missing target is reported instead of\n * fabricating a row; provide `createRow` when the stream is allowed to add one.\n *\n * Pair with {@link parsePartialStream} for end-to-end partial-update\n * streaming over UTF-8 strings.\n *\n * @public\n */\nexport function connectPartialStream<\n TRow extends object,\n TRowId extends string | number,\n>(\n rowModel: RowModelLike<TRow, TRowId>,\n stream: AsyncIterable<Partial<TRow>>,\n options: PartialStreamOptions<TRow, TRowId>,\n): StreamConnection {\n const iterator = stream[Symbol.asyncIterator]();\n const issueAwareRowModel: RowModelLike<TRow, TRowId> = {\n applyTransaction(transaction) {\n const result = rowModel.applyTransaction(transaction);\n if (result === undefined || result.issues === undefined) return result;\n\n let targetMissing = false;\n for (const issue of result.issues) {\n if (\n issue.code !== \"unknown-update-id\" ||\n issue.rowId === undefined ||\n !sameValueZero(issue.rowId, options.rowId)\n ) {\n continue;\n }\n targetMissing = true;\n options.onIssue?.({\n code: \"unknown-update-id\",\n rowId: options.rowId,\n });\n }\n\n if (targetMissing && options.createRow !== undefined) {\n const updates = transaction.update ?? [];\n const combinedChanges: Partial<TRow> = {};\n let hasTargetUpdate = false;\n for (const update of updates) {\n if (!sameValueZero(update.id, options.rowId)) continue;\n Object.assign(combinedChanges, update.changes);\n hasTargetUpdate = true;\n }\n if (hasTargetUpdate) {\n const row = options.createRow(combinedChanges, options.rowId);\n rowModel.applyTransaction({ add: [row] });\n }\n }\n\n return result;\n },\n };\n const batcher = createBatcher(issueAwareRowModel);\n let disposed = false;\n let sourceClosed = false;\n\n let resolveDone!: () => void;\n let rejectDone!: (err: unknown) => void;\n const done = new Promise<void>((resolve, reject) => {\n resolveDone = resolve;\n rejectDone = reject;\n });\n // Swallow unhandled-rejection warnings if the caller hasn't attached a\n // handler before the stream rejects. Consumers that await `done` still\n // observe the rejection — attaching `.catch` here doesn't consume it.\n done.catch(() => undefined);\n\n const closeSource = () => {\n if (sourceClosed) return;\n sourceClosed = true;\n try {\n const closing = iterator.return?.();\n if (closing !== undefined)\n void Promise.resolve(closing).catch(() => undefined);\n } catch {\n // Source closure is best-effort; preserve the exact primary failure.\n }\n };\n\n let settled = false;\n const settle = (\n failure?: { readonly error: unknown },\n flush = true,\n close = failure !== undefined,\n ) => {\n if (settled) return;\n settled = true;\n disposed = true;\n if (close) closeSource();\n let finalFailure = failure;\n if (flush) {\n try {\n batcher.flush();\n } catch (error) {\n finalFailure ??= { error };\n }\n }\n batcher.dispose();\n if (finalFailure === undefined) resolveDone();\n else rejectDone(finalFailure.error);\n };\n\n batcher.subscribeError((error: unknown) => {\n settle({ error }, false, true);\n });\n\n void (async () => {\n try {\n while (!disposed) {\n const result = await iterator.next();\n if (disposed) return;\n if (result.done) {\n settle();\n return;\n }\n batcher.update([{ id: options.rowId, changes: result.value }]);\n }\n } catch (err) {\n settle({ error: err }, true, true);\n }\n })().catch((error: unknown) => settle({ error }));\n\n return {\n done,\n dispose() {\n if (disposed) return;\n settle(undefined, true, true);\n },\n };\n}\n","import {\n create,\n push,\n finish,\n isArrayNode,\n isComplete,\n} from \"@cacheplane/json-stream\";\nimport type { StreamState } from \"@cacheplane/json-stream\";\n\n/**\n * Parse a UTF-8 string stream into an `AsyncIterable<TRow>`. Built on\n * `@cacheplane/json-stream`'s incremental JSON parser; emits each\n * complete top-level array element as a typed row.\n *\n * Pair with {@link connectElementStream} for end-to-end element-stream\n * → grid wiring.\n *\n * @public\n */\nexport async function* parseElementStream<TRow>(\n stream: AsyncIterable<string>,\n): AsyncIterable<TRow> {\n let state: StreamState = create();\n let yieldedCount = 0;\n\n for await (const chunk of stream) {\n state = push(state, chunk);\n\n if (state.error) {\n throw new Error(state.error.message);\n }\n\n if (state.rootId !== null) {\n const root = state.nodes[state.rootId];\n if (!isArrayNode(root)) {\n throw new Error(\n `parseElementStream expects root to be an array, got \"${root.kind}\"`,\n );\n }\n\n while (yieldedCount < root.children.length) {\n const childNode = state.nodes[root.children[yieldedCount]];\n if (!isComplete(childNode)) break;\n if (childNode.value !== undefined) {\n yield childNode.value as TRow;\n }\n yieldedCount++;\n }\n }\n }\n\n state = finish(state);\n\n if (state.error) {\n throw new Error(state.error.message);\n }\n\n if (state.rootId !== null) {\n const root = state.nodes[state.rootId];\n if (isArrayNode(root)) {\n while (yieldedCount < root.children.length) {\n const childNode = state.nodes[root.children[yieldedCount]];\n if (isComplete(childNode) && childNode.value !== undefined) {\n yield childNode.value as TRow;\n }\n yieldedCount++;\n }\n }\n }\n}\n","import { create, push, finish, isObjectNode } from \"@cacheplane/json-stream\";\nimport type { StreamState } from \"@cacheplane/json-stream\";\n\n/**\n * Parse a UTF-8 string stream into an `AsyncIterable<Partial<TRow>>`.\n *\n * The root must be a single JSON **object**, not an array — a non-object root\n * throws. Each yielded value is the cumulative snapshot of that object as more\n * keys resolve, not a delta, so the last value yielded is the complete row.\n * Useful when an LLM is streaming partial JSON for one row and you want\n * field-by-field updates instead of waiting for the object to close.\n *\n * For a stream of many complete rows, use {@link parseElementStream}, which\n * does take a top-level array.\n *\n * Pair with {@link connectPartialStream} for end-to-end partial-stream\n * → grid wiring.\n *\n * @public\n */\nexport async function* parsePartialStream<TRow>(\n stream: AsyncIterable<string>,\n): AsyncIterable<Partial<TRow>> {\n let state: StreamState = create();\n let lastValue: Record<string, unknown> | undefined;\n\n for await (const chunk of stream) {\n state = push(state, chunk);\n\n if (state.error) {\n throw new Error(state.error.message);\n }\n\n if (state.rootId !== null) {\n const root = state.nodes[state.rootId];\n if (!isObjectNode(root)) {\n throw new Error(\n `parsePartialStream expects root to be an object, got \"${root.kind}\"`,\n );\n }\n\n // Skip the initial empty-object state — only yield once at least one\n // key has fully resolved. Without this guard, the very first yield\n // would be `{}`, which translates to spurious no-op transactions\n // downstream in connectPartialStream.\n if (\n root.value !== undefined &&\n root.value !== lastValue &&\n Object.keys(root.value).length > 0\n ) {\n lastValue = root.value;\n yield root.value as Partial<TRow>;\n }\n }\n }\n\n state = finish(state);\n\n if (state.error) {\n throw new Error(state.error.message);\n }\n\n if (state.rootId !== null) {\n const root = state.nodes[state.rootId];\n if (\n isObjectNode(root) &&\n root.value !== undefined &&\n root.value !== lastValue &&\n Object.keys(root.value).length > 0\n ) {\n yield root.value as Partial<TRow>;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,cAGd,UAAwE;CACxE,IAAI,YAAoB,CAAC;CACzB,IAAI,eAGC,CAAC;CACN,IAAI,eAAyB,CAAC;CAC9B,IAAI,QAAuB;CAC3B,IAAI,WAAW;CACf,IAAI;CACJ,MAAM,iCAAiB,IAA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MAAM,OAAO;CAGrC,IAAI,MAAM,WAAW,MAAM;EACzB,MAAM,OAAO,MAAM,MAAM,MAAM;EAC/B,QAAIF,qCAAY,IAAI,GAClB,OAAO,eAAe,KAAK,SAAS,QAAQ;GAC1C,MAAM,YAAY,MAAM,MAAM,KAAK,SAAS;GAC5C,QAAIC,oCAAW,SAAS,KAAK,UAAU,UAAU,QAC/C,MAAM,UAAU;GAElB;EACF;CAEJ;AACF;;;;;;;;;;;;;;;;;;;;;ACjDA,gBAAuB,mBACrB,QAC8B;CAC9B,IAAI,YAAqBE,gCAAO;CAChC,IAAI;CAEJ,WAAW,MAAM,SAAS,QAAQ;EAChC,YAAQC,8BAAK,OAAO,KAAK;EAEzB,IAAI,MAAM,OACR,MAAM,IAAI,MAAM,MAAM,MAAM,OAAO;EAGrC,IAAI,MAAM,WAAW,MAAM;GACzB,MAAM,OAAO,MAAM,MAAM,MAAM;GAC/B,IAAI,KAACC,sCAAa,IAAI,GACpB,MAAM,IAAI,MACR,yDAAyD,KAAK,KAAK,EACrE;GAOF,IACE,KAAK,UAAU,UACf,KAAK,UAAU,aACf,OAAO,KAAK,KAAK,KAAK,CAAC,CAAC,SAAS,GACjC;IACA,YAAY,KAAK;IACjB,MAAM,KAAK;GACb;EACF;CACF;CAEA,YAAQC,gCAAO,KAAK;CAEpB,IAAI,MAAM,OACR,MAAM,IAAI,MAAM,MAAM,MAAM,OAAO;CAGrC,IAAI,MAAM,WAAW,MAAM;EACzB,MAAM,OAAO,MAAM,MAAM,MAAM;EAC/B,QACED,sCAAa,IAAI,KACjB,KAAK,UAAU,UACf,KAAK,UAAU,aACf,OAAO,KAAK,KAAK,KAAK,CAAC,CAAC,SAAS,GAEjC,MAAM,KAAK;CAEf;AACF"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Structural contract for a row model that accepts atomic row transactions.
|
|
3
4
|
* The adapter depends only on this ID-generic shape, so callers may pass a
|
|
@@ -6,19 +7,19 @@
|
|
|
6
7
|
* @public
|
|
7
8
|
*/
|
|
8
9
|
interface RowModelLike<TRow extends object, TRowId extends string | number> {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
readonly applyTransaction: (transaction: {
|
|
11
|
+
add?: TRow[];
|
|
12
|
+
update?: {
|
|
13
|
+
id: TRowId;
|
|
14
|
+
changes: Partial<TRow>;
|
|
15
|
+
}[];
|
|
16
|
+
remove?: TRowId[];
|
|
17
|
+
}) => void | {
|
|
18
|
+
readonly issues?: readonly {
|
|
19
|
+
readonly code: string;
|
|
20
|
+
readonly rowId?: TRowId;
|
|
21
|
+
}[];
|
|
22
|
+
};
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* RAF-batched mutator returned by {@link createBatcher}. Buffer
|
|
@@ -30,18 +31,18 @@ interface RowModelLike<TRow extends object, TRowId extends string | number> {
|
|
|
30
31
|
* @public
|
|
31
32
|
*/
|
|
32
33
|
interface TransactionBatcher<TRow extends object, TRowId extends string | number> {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
/** Rejects with the exact model error from a scheduled RAF transaction. */
|
|
35
|
+
readonly error: Promise<never>;
|
|
36
|
+
/** Observes a scheduled model failure synchronously before later races. */
|
|
37
|
+
readonly subscribeError: (listener: (error: unknown) => void) => () => void;
|
|
38
|
+
readonly add: (rows: readonly TRow[]) => void;
|
|
39
|
+
readonly update: (patches: readonly {
|
|
40
|
+
readonly id: TRowId;
|
|
41
|
+
readonly changes: Partial<TRow>;
|
|
42
|
+
}[]) => void;
|
|
43
|
+
readonly remove: (ids: readonly TRowId[]) => void;
|
|
44
|
+
readonly flush: () => void;
|
|
45
|
+
readonly dispose: () => void;
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* Handle returned by the `connect*Stream` functions. `done` resolves
|
|
@@ -51,10 +52,11 @@ interface TransactionBatcher<TRow extends object, TRowId extends string | number
|
|
|
51
52
|
* @public
|
|
52
53
|
*/
|
|
53
54
|
interface StreamConnection {
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
readonly done: Promise<void>;
|
|
56
|
+
readonly dispose: () => void;
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/create-batcher.d.ts
|
|
58
60
|
/**
|
|
59
61
|
* Create a `requestAnimationFrame`-batched mutator that coalesces
|
|
60
62
|
* `add` / `update` / `remove` calls into a single `applyTransaction` per
|
|
@@ -72,7 +74,8 @@ interface StreamConnection {
|
|
|
72
74
|
* @public
|
|
73
75
|
*/
|
|
74
76
|
declare function createBatcher<TRow extends object, TRowId extends string | number>(rowModel: RowModelLike<TRow, TRowId>): TransactionBatcher<TRow, TRowId>;
|
|
75
|
-
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/connect-element-stream.d.ts
|
|
76
79
|
/**
|
|
77
80
|
* Drive a row model from an `AsyncIterable<TRow>`. Each yielded row is added
|
|
78
81
|
* via a {@link createBatcher | RAF batcher}; the returned
|
|
@@ -85,7 +88,8 @@ declare function createBatcher<TRow extends object, TRowId extends string | numb
|
|
|
85
88
|
* @public
|
|
86
89
|
*/
|
|
87
90
|
declare function connectElementStream<TRow extends object, TRowId extends string | number>(rowModel: RowModelLike<TRow, TRowId>, stream: AsyncIterable<TRow>): StreamConnection;
|
|
88
|
-
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/connect-partial-stream.d.ts
|
|
89
93
|
/**
|
|
90
94
|
* Options for {@link connectPartialStream}. `rowId` is the fixed target for
|
|
91
95
|
* every partial update. Unknown targets are reported through `onIssue`; an
|
|
@@ -94,12 +98,12 @@ declare function connectElementStream<TRow extends object, TRowId extends string
|
|
|
94
98
|
* @public
|
|
95
99
|
*/
|
|
96
100
|
interface PartialStreamOptions<TRow extends object, TRowId extends string | number> {
|
|
101
|
+
readonly rowId: TRowId;
|
|
102
|
+
readonly onIssue?: (issue: {
|
|
103
|
+
readonly code: "unknown-update-id";
|
|
97
104
|
readonly rowId: TRowId;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
readonly rowId: TRowId;
|
|
101
|
-
}) => void;
|
|
102
|
-
readonly createRow?: (partial: Partial<TRow>, id: TRowId) => TRow;
|
|
105
|
+
}) => void;
|
|
106
|
+
readonly createRow?: (partial: Partial<TRow>, id: TRowId) => TRow;
|
|
103
107
|
}
|
|
104
108
|
/**
|
|
105
109
|
* Drive a row model from an `AsyncIterable<Partial<TRow>>`. Every yielded
|
|
@@ -113,7 +117,8 @@ interface PartialStreamOptions<TRow extends object, TRowId extends string | numb
|
|
|
113
117
|
* @public
|
|
114
118
|
*/
|
|
115
119
|
declare function connectPartialStream<TRow extends object, TRowId extends string | number>(rowModel: RowModelLike<TRow, TRowId>, stream: AsyncIterable<Partial<TRow>>, options: PartialStreamOptions<TRow, TRowId>): StreamConnection;
|
|
116
|
-
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/parse-element-stream.d.ts
|
|
117
122
|
/**
|
|
118
123
|
* Parse a UTF-8 string stream into an `AsyncIterable<TRow>`. Built on
|
|
119
124
|
* `@cacheplane/json-stream`'s incremental JSON parser; emits each
|
|
@@ -125,13 +130,19 @@ declare function connectPartialStream<TRow extends object, TRowId extends string
|
|
|
125
130
|
* @public
|
|
126
131
|
*/
|
|
127
132
|
declare function parseElementStream<TRow>(stream: AsyncIterable<string>): AsyncIterable<TRow>;
|
|
128
|
-
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/parse-partial-stream.d.ts
|
|
129
135
|
/**
|
|
130
136
|
* Parse a UTF-8 string stream into an `AsyncIterable<Partial<TRow>>`.
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
137
|
+
*
|
|
138
|
+
* The root must be a single JSON **object**, not an array — a non-object root
|
|
139
|
+
* throws. Each yielded value is the cumulative snapshot of that object as more
|
|
140
|
+
* keys resolve, not a delta, so the last value yielded is the complete row.
|
|
141
|
+
* Useful when an LLM is streaming partial JSON for one row and you want
|
|
142
|
+
* field-by-field updates instead of waiting for the object to close.
|
|
143
|
+
*
|
|
144
|
+
* For a stream of many complete rows, use {@link parseElementStream}, which
|
|
145
|
+
* does take a top-level array.
|
|
135
146
|
*
|
|
136
147
|
* Pair with {@link connectPartialStream} for end-to-end partial-stream
|
|
137
148
|
* → grid wiring.
|
|
@@ -139,5 +150,6 @@ declare function parseElementStream<TRow>(stream: AsyncIterable<string>): AsyncI
|
|
|
139
150
|
* @public
|
|
140
151
|
*/
|
|
141
152
|
declare function parsePartialStream<TRow>(stream: AsyncIterable<string>): AsyncIterable<Partial<TRow>>;
|
|
142
|
-
|
|
153
|
+
//#endregion
|
|
143
154
|
export { type PartialStreamOptions, type RowModelLike, type StreamConnection, type TransactionBatcher, connectElementStream, connectPartialStream, createBatcher, parseElementStream, parsePartialStream };
|
|
155
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/create-batcher.ts","../src/connect-element-stream.ts","../src/connect-partial-stream.ts","../src/parse-element-stream.ts","../src/parse-partial-stream.ts"],"mappings":";;;;;;;;UAOiB,aACf,qBACA;WAES,mBAAmB;IAC1B,MAAM;IACN;MACE,IAAI;MACJ,SAAS,QAAQ;;IAEnB,SAAS;;aAEA;eACE;eACA,QAAQ;;;;;;;;;;;;;UAcN,mBACf,qBACA;;WAGS,OAAO;;WAEP,iBAAiB,WAAW;WAC5B,MAAM,eAAe;WACrB,SACP;aACW,IAAI;aACJ,SAAS,QAAQ;;WAGrB,SAAS,cAAc;WACvB;WACA;;;;;;;;;UAUM;WACN,MAAM;WACN;;;;;;;;;;;;;;;;;;;;iBC9CK,cACd,qBACA,gCACA,UAAU,aAAa,MAAM,UAAU,mBAAmB,MAAM;;;;;;;;;;;;;;iBCPlD,qBACd,qBACA,gCAEA,UAAU,aAAa,MAAM,SAC7B,QAAQ,cAAc,QACrB;;;;;;;;;;UCAc,qBACf,qBACA;WAES,OAAO;WACP,WAAW;aACT;aACA,OAAO;;WAET,aAAa,SAAS,QAAQ,OAAO,IAAI,WAAW;;;;;;;;;;;;;iBAc/C,qBACd,qBACA,gCAEA,UAAU,aAAa,MAAM,SAC7B,QAAQ,cAAc,QAAQ,QAC9B,SAAS,qBAAqB,MAAM,UACnC;;;;;;;;;;;;;iBC/BoB,mBAAmB,MACxC,QAAQ,wBACP,cAAc;;;;;;;;;;;;;;;;;;;;iBCDM,mBAAmB,MACxC,QAAQ,wBACP,cAAc,QAAQ"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Structural contract for a row model that accepts atomic row transactions.
|
|
3
4
|
* The adapter depends only on this ID-generic shape, so callers may pass a
|
|
@@ -6,19 +7,19 @@
|
|
|
6
7
|
* @public
|
|
7
8
|
*/
|
|
8
9
|
interface RowModelLike<TRow extends object, TRowId extends string | number> {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
readonly applyTransaction: (transaction: {
|
|
11
|
+
add?: TRow[];
|
|
12
|
+
update?: {
|
|
13
|
+
id: TRowId;
|
|
14
|
+
changes: Partial<TRow>;
|
|
15
|
+
}[];
|
|
16
|
+
remove?: TRowId[];
|
|
17
|
+
}) => void | {
|
|
18
|
+
readonly issues?: readonly {
|
|
19
|
+
readonly code: string;
|
|
20
|
+
readonly rowId?: TRowId;
|
|
21
|
+
}[];
|
|
22
|
+
};
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* RAF-batched mutator returned by {@link createBatcher}. Buffer
|
|
@@ -30,18 +31,18 @@ interface RowModelLike<TRow extends object, TRowId extends string | number> {
|
|
|
30
31
|
* @public
|
|
31
32
|
*/
|
|
32
33
|
interface TransactionBatcher<TRow extends object, TRowId extends string | number> {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
/** Rejects with the exact model error from a scheduled RAF transaction. */
|
|
35
|
+
readonly error: Promise<never>;
|
|
36
|
+
/** Observes a scheduled model failure synchronously before later races. */
|
|
37
|
+
readonly subscribeError: (listener: (error: unknown) => void) => () => void;
|
|
38
|
+
readonly add: (rows: readonly TRow[]) => void;
|
|
39
|
+
readonly update: (patches: readonly {
|
|
40
|
+
readonly id: TRowId;
|
|
41
|
+
readonly changes: Partial<TRow>;
|
|
42
|
+
}[]) => void;
|
|
43
|
+
readonly remove: (ids: readonly TRowId[]) => void;
|
|
44
|
+
readonly flush: () => void;
|
|
45
|
+
readonly dispose: () => void;
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* Handle returned by the `connect*Stream` functions. `done` resolves
|
|
@@ -51,10 +52,11 @@ interface TransactionBatcher<TRow extends object, TRowId extends string | number
|
|
|
51
52
|
* @public
|
|
52
53
|
*/
|
|
53
54
|
interface StreamConnection {
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
readonly done: Promise<void>;
|
|
56
|
+
readonly dispose: () => void;
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/create-batcher.d.ts
|
|
58
60
|
/**
|
|
59
61
|
* Create a `requestAnimationFrame`-batched mutator that coalesces
|
|
60
62
|
* `add` / `update` / `remove` calls into a single `applyTransaction` per
|
|
@@ -72,7 +74,8 @@ interface StreamConnection {
|
|
|
72
74
|
* @public
|
|
73
75
|
*/
|
|
74
76
|
declare function createBatcher<TRow extends object, TRowId extends string | number>(rowModel: RowModelLike<TRow, TRowId>): TransactionBatcher<TRow, TRowId>;
|
|
75
|
-
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/connect-element-stream.d.ts
|
|
76
79
|
/**
|
|
77
80
|
* Drive a row model from an `AsyncIterable<TRow>`. Each yielded row is added
|
|
78
81
|
* via a {@link createBatcher | RAF batcher}; the returned
|
|
@@ -85,7 +88,8 @@ declare function createBatcher<TRow extends object, TRowId extends string | numb
|
|
|
85
88
|
* @public
|
|
86
89
|
*/
|
|
87
90
|
declare function connectElementStream<TRow extends object, TRowId extends string | number>(rowModel: RowModelLike<TRow, TRowId>, stream: AsyncIterable<TRow>): StreamConnection;
|
|
88
|
-
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/connect-partial-stream.d.ts
|
|
89
93
|
/**
|
|
90
94
|
* Options for {@link connectPartialStream}. `rowId` is the fixed target for
|
|
91
95
|
* every partial update. Unknown targets are reported through `onIssue`; an
|
|
@@ -94,12 +98,12 @@ declare function connectElementStream<TRow extends object, TRowId extends string
|
|
|
94
98
|
* @public
|
|
95
99
|
*/
|
|
96
100
|
interface PartialStreamOptions<TRow extends object, TRowId extends string | number> {
|
|
101
|
+
readonly rowId: TRowId;
|
|
102
|
+
readonly onIssue?: (issue: {
|
|
103
|
+
readonly code: "unknown-update-id";
|
|
97
104
|
readonly rowId: TRowId;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
readonly rowId: TRowId;
|
|
101
|
-
}) => void;
|
|
102
|
-
readonly createRow?: (partial: Partial<TRow>, id: TRowId) => TRow;
|
|
105
|
+
}) => void;
|
|
106
|
+
readonly createRow?: (partial: Partial<TRow>, id: TRowId) => TRow;
|
|
103
107
|
}
|
|
104
108
|
/**
|
|
105
109
|
* Drive a row model from an `AsyncIterable<Partial<TRow>>`. Every yielded
|
|
@@ -113,7 +117,8 @@ interface PartialStreamOptions<TRow extends object, TRowId extends string | numb
|
|
|
113
117
|
* @public
|
|
114
118
|
*/
|
|
115
119
|
declare function connectPartialStream<TRow extends object, TRowId extends string | number>(rowModel: RowModelLike<TRow, TRowId>, stream: AsyncIterable<Partial<TRow>>, options: PartialStreamOptions<TRow, TRowId>): StreamConnection;
|
|
116
|
-
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/parse-element-stream.d.ts
|
|
117
122
|
/**
|
|
118
123
|
* Parse a UTF-8 string stream into an `AsyncIterable<TRow>`. Built on
|
|
119
124
|
* `@cacheplane/json-stream`'s incremental JSON parser; emits each
|
|
@@ -125,13 +130,19 @@ declare function connectPartialStream<TRow extends object, TRowId extends string
|
|
|
125
130
|
* @public
|
|
126
131
|
*/
|
|
127
132
|
declare function parseElementStream<TRow>(stream: AsyncIterable<string>): AsyncIterable<TRow>;
|
|
128
|
-
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/parse-partial-stream.d.ts
|
|
129
135
|
/**
|
|
130
136
|
* Parse a UTF-8 string stream into an `AsyncIterable<Partial<TRow>>`.
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
137
|
+
*
|
|
138
|
+
* The root must be a single JSON **object**, not an array — a non-object root
|
|
139
|
+
* throws. Each yielded value is the cumulative snapshot of that object as more
|
|
140
|
+
* keys resolve, not a delta, so the last value yielded is the complete row.
|
|
141
|
+
* Useful when an LLM is streaming partial JSON for one row and you want
|
|
142
|
+
* field-by-field updates instead of waiting for the object to close.
|
|
143
|
+
*
|
|
144
|
+
* For a stream of many complete rows, use {@link parseElementStream}, which
|
|
145
|
+
* does take a top-level array.
|
|
135
146
|
*
|
|
136
147
|
* Pair with {@link connectPartialStream} for end-to-end partial-stream
|
|
137
148
|
* → grid wiring.
|
|
@@ -139,5 +150,6 @@ declare function parseElementStream<TRow>(stream: AsyncIterable<string>): AsyncI
|
|
|
139
150
|
* @public
|
|
140
151
|
*/
|
|
141
152
|
declare function parsePartialStream<TRow>(stream: AsyncIterable<string>): AsyncIterable<Partial<TRow>>;
|
|
142
|
-
|
|
153
|
+
//#endregion
|
|
143
154
|
export { type PartialStreamOptions, type RowModelLike, type StreamConnection, type TransactionBatcher, connectElementStream, connectPartialStream, createBatcher, parseElementStream, parsePartialStream };
|
|
155
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/create-batcher.ts","../src/connect-element-stream.ts","../src/connect-partial-stream.ts","../src/parse-element-stream.ts","../src/parse-partial-stream.ts"],"mappings":";;;;;;;;UAOiB,aACf,qBACA;WAES,mBAAmB;IAC1B,MAAM;IACN;MACE,IAAI;MACJ,SAAS,QAAQ;;IAEnB,SAAS;;aAEA;eACE;eACA,QAAQ;;;;;;;;;;;;;UAcN,mBACf,qBACA;;WAGS,OAAO;;WAEP,iBAAiB,WAAW;WAC5B,MAAM,eAAe;WACrB,SACP;aACW,IAAI;aACJ,SAAS,QAAQ;;WAGrB,SAAS,cAAc;WACvB;WACA;;;;;;;;;UAUM;WACN,MAAM;WACN;;;;;;;;;;;;;;;;;;;;iBC9CK,cACd,qBACA,gCACA,UAAU,aAAa,MAAM,UAAU,mBAAmB,MAAM;;;;;;;;;;;;;;iBCPlD,qBACd,qBACA,gCAEA,UAAU,aAAa,MAAM,SAC7B,QAAQ,cAAc,QACrB;;;;;;;;;;UCAc,qBACf,qBACA;WAES,OAAO;WACP,WAAW;aACT;aACA,OAAO;;WAET,aAAa,SAAS,QAAQ,OAAO,IAAI,WAAW;;;;;;;;;;;;;iBAc/C,qBACd,qBACA,gCAEA,UAAU,aAAa,MAAM,SAC7B,QAAQ,cAAc,QAAQ,QAC9B,SAAS,qBAAqB,MAAM,UACnC;;;;;;;;;;;;;iBC/BoB,mBAAmB,MACxC,QAAQ,wBACP,cAAc;;;;;;;;;;;;;;;;;;;;iBCDM,mBAAmB,MACxC,QAAQ,wBACP,cAAc,QAAQ"}
|