@graphrefly/graphrefly 0.21.0 → 0.22.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/README.md +7 -5
- package/dist/chunk-44HD4BTA.js +47 -0
- package/dist/chunk-44HD4BTA.js.map +1 -0
- package/dist/chunk-7TAQJHQV.js +103 -0
- package/dist/chunk-7TAQJHQV.js.map +1 -0
- package/dist/chunk-BLD3IFYF.js +6827 -0
- package/dist/chunk-BLD3IFYF.js.map +1 -0
- package/dist/{chunk-ZTCDY5NQ.js → chunk-EQUZ5NLD.js} +34 -45
- package/dist/chunk-EQUZ5NLD.js.map +1 -0
- package/dist/{chunk-VOQFK7YN.js → chunk-IR3KMOLX.js} +358 -128
- package/dist/chunk-IR3KMOLX.js.map +1 -0
- package/dist/{chunk-XWBVAO2R.js → chunk-MQBQOFDS.js} +20 -11
- package/dist/chunk-MQBQOFDS.js.map +1 -0
- package/dist/chunk-NXC35KC5.js +2417 -0
- package/dist/chunk-NXC35KC5.js.map +1 -0
- package/dist/chunk-QA3RP5NH.js +2234 -0
- package/dist/chunk-QA3RP5NH.js.map +1 -0
- package/dist/chunk-RHI3GHZW.js +115 -0
- package/dist/chunk-RHI3GHZW.js.map +1 -0
- package/dist/{chunk-7IGHIFTT.js → chunk-TH6COGOP.js} +15 -26
- package/dist/chunk-TH6COGOP.js.map +1 -0
- package/dist/compat/nestjs/index.cjs +3366 -2259
- package/dist/compat/nestjs/index.cjs.map +1 -1
- package/dist/compat/nestjs/index.d.cts +6 -4
- package/dist/compat/nestjs/index.d.ts +6 -4
- package/dist/compat/nestjs/index.js +8 -8
- package/dist/core/index.cjs +1611 -1218
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +3 -2
- package/dist/core/index.d.ts +3 -2
- package/dist/core/index.js +37 -34
- package/dist/extra/index.cjs +7387 -6089
- package/dist/extra/index.cjs.map +1 -1
- package/dist/extra/index.d.cts +4 -4
- package/dist/extra/index.d.ts +4 -4
- package/dist/extra/index.js +57 -30
- package/dist/graph/index.cjs +3107 -2216
- package/dist/graph/index.cjs.map +1 -1
- package/dist/graph/index.d.cts +5 -3
- package/dist/graph/index.d.ts +5 -3
- package/dist/graph/index.js +24 -11
- package/dist/graph-DFr0diXB.d.ts +1128 -0
- package/dist/graph-ab1yPwIB.d.cts +1128 -0
- package/dist/{index-8a605sg9.d.ts → index-BHm3Ba5q.d.ts} +2 -2
- package/dist/{index-DuN3bhtm.d.ts → index-BbYZma8G.d.ts} +1697 -586
- package/dist/{index-SFzE_KTa.d.cts → index-BvWfZCTt.d.cts} +1697 -586
- package/dist/index-C9z6rU9P.d.cts +388 -0
- package/dist/{index-BjtlNirP.d.cts → index-D36MAQ3f.d.ts} +4 -4
- package/dist/{index-VHA43cGP.d.cts → index-DLE1Sp-L.d.cts} +2 -2
- package/dist/{index-CgSiUouz.d.ts → index-DrJq9B1T.d.cts} +4 -4
- package/dist/index-DsGxLfwL.d.ts +315 -0
- package/dist/index-Dy04P4W3.d.cts +315 -0
- package/dist/index-HdJx_BjO.d.ts +388 -0
- package/dist/index.cjs +9781 -7878
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +214 -37
- package/dist/index.d.ts +214 -37
- package/dist/index.js +905 -638
- package/dist/index.js.map +1 -1
- package/dist/meta--fr9sxRM.d.cts +41 -0
- package/dist/meta-n3FoVWML.d.ts +41 -0
- package/dist/node-C5UD5MGq.d.cts +1146 -0
- package/dist/node-C5UD5MGq.d.ts +1146 -0
- package/dist/{observable-DcBwQY7t.d.ts → observable-CQRBtEbq.d.ts} +1 -1
- package/dist/{observable-C8Kx_O6k.d.cts → observable-DWydVy5b.d.cts} +1 -1
- package/dist/patterns/reactive-layout/index.cjs +3102 -2132
- package/dist/patterns/reactive-layout/index.cjs.map +1 -1
- package/dist/patterns/reactive-layout/index.d.cts +5 -3
- package/dist/patterns/reactive-layout/index.d.ts +5 -3
- package/dist/patterns/reactive-layout/index.js +5 -4
- package/dist/storage-Bew05Xy6.d.cts +182 -0
- package/dist/storage-C9fZfMfM.d.ts +182 -0
- package/package.json +1 -1
- package/dist/chunk-2UDLYZHT.js +0 -2117
- package/dist/chunk-2UDLYZHT.js.map +0 -1
- package/dist/chunk-4MQ2J6IG.js +0 -1631
- package/dist/chunk-4MQ2J6IG.js.map +0 -1
- package/dist/chunk-7IGHIFTT.js.map +0 -1
- package/dist/chunk-DOSLSFKL.js +0 -162
- package/dist/chunk-DOSLSFKL.js.map +0 -1
- package/dist/chunk-ECN37NVS.js +0 -6227
- package/dist/chunk-ECN37NVS.js.map +0 -1
- package/dist/chunk-G66H6ZRK.js +0 -111
- package/dist/chunk-G66H6ZRK.js.map +0 -1
- package/dist/chunk-VOQFK7YN.js.map +0 -1
- package/dist/chunk-WZ2Z2CRV.js +0 -32
- package/dist/chunk-WZ2Z2CRV.js.map +0 -1
- package/dist/chunk-XWBVAO2R.js.map +0 -1
- package/dist/chunk-ZTCDY5NQ.js.map +0 -1
- package/dist/graph-KsTe57nI.d.cts +0 -750
- package/dist/graph-mILUUqW8.d.ts +0 -750
- package/dist/index-B2SvPEbc.d.ts +0 -257
- package/dist/index-BHfg_Ez3.d.ts +0 -629
- package/dist/index-Bc_diYYJ.d.cts +0 -629
- package/dist/index-UudxGnzc.d.cts +0 -257
- package/dist/meta-BnG7XAaE.d.cts +0 -778
- package/dist/meta-BnG7XAaE.d.ts +0 -778
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export { B as BlockAdapters, C as CanvasMeasureAdapter, a as CanvasMeasureAdapterOptions, b as CanvasModule, c as CharPosition, d as CliMeasureAdapter, e as CliMeasureAdapterOptions, f as ContentBlock, I as ImageMeasurer, g as ImageSizeAdapter, L as LayoutLine, h as LineBreaksResult, j as MeasuredBlock, M as MeasurementAdapter, N as NodeCanvasMeasureAdapter, P as PositionedBlock, k as PrecomputedAdapter, l as PrecomputedAdapterOptions, m as PreparedSegment, R as ReactiveBlockLayoutBundle, n as ReactiveBlockLayoutOptions, o as ReactiveLayoutBundle, p as ReactiveLayoutOptions, S as SegmentBreakKind, q as SegmentMeasureStats, r as SvgBoundsAdapter, s as SvgMeasurer, t as analyzeAndMeasure, u as computeBlockFlow, v as computeCharPositions, w as computeLineBreaks, x as computeTotalHeight, y as measureBlock, z as measureBlocks, A as reactiveBlockLayout, D as reactiveLayout } from '../../index-
|
|
2
|
-
import '../../
|
|
3
|
-
import '../../graph-
|
|
1
|
+
export { B as BlockAdapters, C as CanvasMeasureAdapter, a as CanvasMeasureAdapterOptions, b as CanvasModule, c as CharPosition, d as CliMeasureAdapter, e as CliMeasureAdapterOptions, f as ContentBlock, I as ImageMeasurer, g as ImageSizeAdapter, L as LayoutLine, h as LineBreaksResult, j as MeasuredBlock, M as MeasurementAdapter, N as NodeCanvasMeasureAdapter, P as PositionedBlock, k as PrecomputedAdapter, l as PrecomputedAdapterOptions, m as PreparedSegment, R as ReactiveBlockLayoutBundle, n as ReactiveBlockLayoutOptions, o as ReactiveLayoutBundle, p as ReactiveLayoutOptions, S as SegmentBreakKind, q as SegmentMeasureStats, r as SvgBoundsAdapter, s as SvgMeasurer, t as analyzeAndMeasure, u as computeBlockFlow, v as computeCharPositions, w as computeLineBreaks, x as computeTotalHeight, y as measureBlock, z as measureBlocks, A as reactiveBlockLayout, D as reactiveLayout } from '../../index-DLE1Sp-L.cjs';
|
|
2
|
+
import '../../node-C5UD5MGq.cjs';
|
|
3
|
+
import '../../graph-ab1yPwIB.cjs';
|
|
4
|
+
import '../../meta--fr9sxRM.cjs';
|
|
5
|
+
import '../../storage-Bew05Xy6.cjs';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export { B as BlockAdapters, C as CanvasMeasureAdapter, a as CanvasMeasureAdapterOptions, b as CanvasModule, c as CharPosition, d as CliMeasureAdapter, e as CliMeasureAdapterOptions, f as ContentBlock, I as ImageMeasurer, g as ImageSizeAdapter, L as LayoutLine, h as LineBreaksResult, j as MeasuredBlock, M as MeasurementAdapter, N as NodeCanvasMeasureAdapter, P as PositionedBlock, k as PrecomputedAdapter, l as PrecomputedAdapterOptions, m as PreparedSegment, R as ReactiveBlockLayoutBundle, n as ReactiveBlockLayoutOptions, o as ReactiveLayoutBundle, p as ReactiveLayoutOptions, S as SegmentBreakKind, q as SegmentMeasureStats, r as SvgBoundsAdapter, s as SvgMeasurer, t as analyzeAndMeasure, u as computeBlockFlow, v as computeCharPositions, w as computeLineBreaks, x as computeTotalHeight, y as measureBlock, z as measureBlocks, A as reactiveBlockLayout, D as reactiveLayout } from '../../index-
|
|
2
|
-
import '../../
|
|
3
|
-
import '../../graph-
|
|
1
|
+
export { B as BlockAdapters, C as CanvasMeasureAdapter, a as CanvasMeasureAdapterOptions, b as CanvasModule, c as CharPosition, d as CliMeasureAdapter, e as CliMeasureAdapterOptions, f as ContentBlock, I as ImageMeasurer, g as ImageSizeAdapter, L as LayoutLine, h as LineBreaksResult, j as MeasuredBlock, M as MeasurementAdapter, N as NodeCanvasMeasureAdapter, P as PositionedBlock, k as PrecomputedAdapter, l as PrecomputedAdapterOptions, m as PreparedSegment, R as ReactiveBlockLayoutBundle, n as ReactiveBlockLayoutOptions, o as ReactiveLayoutBundle, p as ReactiveLayoutOptions, S as SegmentBreakKind, q as SegmentMeasureStats, r as SvgBoundsAdapter, s as SvgMeasurer, t as analyzeAndMeasure, u as computeBlockFlow, v as computeCharPositions, w as computeLineBreaks, x as computeTotalHeight, y as measureBlock, z as measureBlocks, A as reactiveBlockLayout, D as reactiveLayout } from '../../index-BHm3Ba5q.js';
|
|
2
|
+
import '../../node-C5UD5MGq.js';
|
|
3
|
+
import '../../graph-DFr0diXB.js';
|
|
4
|
+
import '../../meta-n3FoVWML.js';
|
|
5
|
+
import '../../storage-C9fZfMfM.js';
|
|
@@ -14,10 +14,11 @@ import {
|
|
|
14
14
|
measureBlocks,
|
|
15
15
|
reactiveBlockLayout,
|
|
16
16
|
reactiveLayout
|
|
17
|
-
} from "../../chunk-
|
|
18
|
-
import "../../chunk-
|
|
19
|
-
import "../../chunk-
|
|
20
|
-
import "../../chunk-
|
|
17
|
+
} from "../../chunk-EQUZ5NLD.js";
|
|
18
|
+
import "../../chunk-NXC35KC5.js";
|
|
19
|
+
import "../../chunk-TH6COGOP.js";
|
|
20
|
+
import "../../chunk-7TAQJHQV.js";
|
|
21
|
+
import "../../chunk-QA3RP5NH.js";
|
|
21
22
|
export {
|
|
22
23
|
CanvasMeasureAdapter,
|
|
23
24
|
CliMeasureAdapter,
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { N as Node } from './node-C5UD5MGq.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Storage tier primitive — unified persistence surface (roadmap §3.1).
|
|
5
|
+
*
|
|
6
|
+
* A {@link StorageTier} is the single abstraction used by:
|
|
7
|
+
* - {@link Graph.attachStorage} — snapshot cascade with per-tier cadence
|
|
8
|
+
* - {@link Graph.fromStorage} — hot-boot from the first tier that hits
|
|
9
|
+
* - {@link cascadingCache} — keyed lookup cache with auto-promotion
|
|
10
|
+
*
|
|
11
|
+
* Factory functions cover the common backends: {@link memoryStorage},
|
|
12
|
+
* {@link dictStorage}, {@link fileStorage}, {@link sqliteStorage} (sync), and
|
|
13
|
+
* {@link indexedDbStorage} (async). {@link fromIDBRequest} /
|
|
14
|
+
* {@link fromIDBTransaction} wrap raw IndexedDB primitives as reactive sources
|
|
15
|
+
* — they belong here as the browser-runtime neighbors of `indexedDbStorage`.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Single persistence primitive — supports sync and async backends alike via
|
|
20
|
+
* `void | Promise<void>` returns. `debounceMs` / `compactEvery` / `filter`
|
|
21
|
+
* are per-tier cadence controls honored by {@link Graph.attachStorage};
|
|
22
|
+
* {@link cascadingCache} ignores them (it has its own eviction policy).
|
|
23
|
+
*/
|
|
24
|
+
interface StorageTier {
|
|
25
|
+
/** Read a value. Returns `null` (or resolves to `null`) on miss. */
|
|
26
|
+
load(key: string): unknown | Promise<unknown>;
|
|
27
|
+
/** Write a record. Sync tiers return `void`; async tiers return `Promise<void>`. */
|
|
28
|
+
save(key: string, data: unknown): void | Promise<void>;
|
|
29
|
+
/** Delete a value. Optional — tiers without `clear` are append/overwrite-only. */
|
|
30
|
+
clear?(key: string): void | Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Debounce saves on this tier (ms). Hot tier: `0` (sync-through).
|
|
33
|
+
* Warm: `1000`. Cold: `60000`. Each tier holds its own last-save baseline,
|
|
34
|
+
* so cold flushes aren't penalized by hot flushes.
|
|
35
|
+
*/
|
|
36
|
+
debounceMs?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Every Nth record is a full snapshot; others are diffs against this
|
|
39
|
+
* tier's own baseline. Default `10`. Set `1` for always-full;
|
|
40
|
+
* `Number.POSITIVE_INFINITY` is unsafe — WAL replay needs periodic anchors.
|
|
41
|
+
*/
|
|
42
|
+
compactEvery?: number;
|
|
43
|
+
/** Pre-save filter — return `false` to skip this record on this tier. */
|
|
44
|
+
filter?: (key: string, record: unknown) => boolean;
|
|
45
|
+
}
|
|
46
|
+
/** Handle returned by {@link Graph.attachStorage} — dispose to stop observing. */
|
|
47
|
+
interface StorageHandle {
|
|
48
|
+
dispose(): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* In-memory storage tier (process-local; useful for tests and hot tier).
|
|
52
|
+
*
|
|
53
|
+
* @returns Sync {@link StorageTier} with JSON-cloned isolation.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { memoryStorage } from "@graphrefly/graphrefly-ts";
|
|
58
|
+
*
|
|
59
|
+
* const hot = memoryStorage();
|
|
60
|
+
* graph.attachStorage([hot]);
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @category extra
|
|
64
|
+
*/
|
|
65
|
+
declare function memoryStorage(): StorageTier;
|
|
66
|
+
/**
|
|
67
|
+
* Dict-backed storage tier — stores JSON-cloned values under caller keys in
|
|
68
|
+
* a caller-owned plain object. Useful for embedding in a parent state shape.
|
|
69
|
+
*
|
|
70
|
+
* @param storage - Caller-owned object used as the backing store.
|
|
71
|
+
* @returns Sync {@link StorageTier}.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { dictStorage } from "@graphrefly/graphrefly-ts";
|
|
76
|
+
*
|
|
77
|
+
* const state: Record<string, unknown> = {};
|
|
78
|
+
* graph.attachStorage([dictStorage(state)]);
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @category extra
|
|
82
|
+
*/
|
|
83
|
+
declare function dictStorage(storage: Record<string, unknown>): StorageTier;
|
|
84
|
+
/**
|
|
85
|
+
* Atomic JSON file storage tier (one file per key in a directory, temp + rename).
|
|
86
|
+
*
|
|
87
|
+
* Keys are sanitized to filesystem-safe names (`[^a-zA-Z0-9_-]` → `%<hex>`).
|
|
88
|
+
* `load` returns `null` for missing files, empty files, or invalid JSON.
|
|
89
|
+
*
|
|
90
|
+
* @param dir - Directory where per-key JSON files are written.
|
|
91
|
+
* @returns Sync {@link StorageTier}.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { fileStorage, memoryStorage } from "@graphrefly/graphrefly-ts";
|
|
96
|
+
*
|
|
97
|
+
* graph.attachStorage([memoryStorage(), fileStorage("./checkpoints")]);
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @category extra
|
|
101
|
+
*/
|
|
102
|
+
declare function fileStorage(dir: string): StorageTier;
|
|
103
|
+
/**
|
|
104
|
+
* SQLite storage tier using Node.js `node:sqlite` ({@link DatabaseSync}).
|
|
105
|
+
*
|
|
106
|
+
* Returns a {@link StorageTier} extended with `close()` — the caller owns the
|
|
107
|
+
* connection and should close it when discarding the tier.
|
|
108
|
+
*
|
|
109
|
+
* **Runtime:** Requires Node 22.5+ with `node:sqlite` enabled.
|
|
110
|
+
*
|
|
111
|
+
* @param path - SQLite database file path.
|
|
112
|
+
* @returns Sync {@link StorageTier} with an idempotent `close()` method.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* import { sqliteStorage, memoryStorage } from "@graphrefly/graphrefly-ts";
|
|
117
|
+
*
|
|
118
|
+
* const cold = sqliteStorage("./graphs.sqlite");
|
|
119
|
+
* graph.attachStorage([memoryStorage(), cold]);
|
|
120
|
+
* // ... later, on shutdown:
|
|
121
|
+
* cold.close();
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @category extra
|
|
125
|
+
*/
|
|
126
|
+
declare function sqliteStorage(path: string): StorageTier & {
|
|
127
|
+
close(): void;
|
|
128
|
+
};
|
|
129
|
+
type IndexedDbStorageSpec = {
|
|
130
|
+
dbName: string;
|
|
131
|
+
storeName: string;
|
|
132
|
+
/** Object-store key under which snapshots are written. @default `"graphrefly_checkpoint"`. */
|
|
133
|
+
key?: string;
|
|
134
|
+
version?: number;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Wraps an `IDBRequest` as a one-shot reactive source.
|
|
138
|
+
*
|
|
139
|
+
* @param req - Request whose callbacks are converted to protocol messages.
|
|
140
|
+
* @returns `Node<T>` that emits `DATA` once on success then `COMPLETE`;
|
|
141
|
+
* emits `ERROR` on failure.
|
|
142
|
+
*
|
|
143
|
+
* @category extra
|
|
144
|
+
*/
|
|
145
|
+
declare function fromIDBRequest<T>(req: IDBRequest<T>): Node<T>;
|
|
146
|
+
/**
|
|
147
|
+
* Wraps an `IDBTransaction` terminal lifecycle as a one-shot reactive source.
|
|
148
|
+
*
|
|
149
|
+
* @param tx - Transaction to observe.
|
|
150
|
+
* @returns `Node<void>` that emits `DATA` (`undefined`) then `COMPLETE` on
|
|
151
|
+
* success; emits `ERROR` on `error`/`abort`.
|
|
152
|
+
*
|
|
153
|
+
* @category extra
|
|
154
|
+
*/
|
|
155
|
+
declare function fromIDBTransaction(tx: IDBTransaction): Node<void>;
|
|
156
|
+
/**
|
|
157
|
+
* IndexedDB-backed async storage tier (browser runtime).
|
|
158
|
+
*
|
|
159
|
+
* All three methods return `Promise`s — pairs naturally with a warm/cold
|
|
160
|
+
* cadence where async writes are debounced per tier via
|
|
161
|
+
* {@link Graph.attachStorage}. Writes use `readwrite` transactions; reads use
|
|
162
|
+
* `readonly`. Missing records resolve to `null`.
|
|
163
|
+
*
|
|
164
|
+
* @param spec - Database name, store name, optional `key` (default
|
|
165
|
+
* `"graphrefly_checkpoint"`) and schema `version` (default `1`).
|
|
166
|
+
* @returns Async {@link StorageTier}.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* import { indexedDbStorage, memoryStorage } from "@graphrefly/graphrefly-ts";
|
|
171
|
+
*
|
|
172
|
+
* graph.attachStorage([
|
|
173
|
+
* memoryStorage(),
|
|
174
|
+
* indexedDbStorage({ dbName: "myApp", storeName: "checkpoints" }),
|
|
175
|
+
* ]);
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @category extra
|
|
179
|
+
*/
|
|
180
|
+
declare function indexedDbStorage(spec: IndexedDbStorageSpec): StorageTier;
|
|
181
|
+
|
|
182
|
+
export { type IndexedDbStorageSpec as I, type StorageHandle as S, type StorageTier as a, fromIDBRequest as b, fromIDBTransaction as c, dictStorage as d, fileStorage as f, indexedDbStorage as i, memoryStorage as m, sqliteStorage as s };
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { N as Node } from './node-C5UD5MGq.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Storage tier primitive — unified persistence surface (roadmap §3.1).
|
|
5
|
+
*
|
|
6
|
+
* A {@link StorageTier} is the single abstraction used by:
|
|
7
|
+
* - {@link Graph.attachStorage} — snapshot cascade with per-tier cadence
|
|
8
|
+
* - {@link Graph.fromStorage} — hot-boot from the first tier that hits
|
|
9
|
+
* - {@link cascadingCache} — keyed lookup cache with auto-promotion
|
|
10
|
+
*
|
|
11
|
+
* Factory functions cover the common backends: {@link memoryStorage},
|
|
12
|
+
* {@link dictStorage}, {@link fileStorage}, {@link sqliteStorage} (sync), and
|
|
13
|
+
* {@link indexedDbStorage} (async). {@link fromIDBRequest} /
|
|
14
|
+
* {@link fromIDBTransaction} wrap raw IndexedDB primitives as reactive sources
|
|
15
|
+
* — they belong here as the browser-runtime neighbors of `indexedDbStorage`.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Single persistence primitive — supports sync and async backends alike via
|
|
20
|
+
* `void | Promise<void>` returns. `debounceMs` / `compactEvery` / `filter`
|
|
21
|
+
* are per-tier cadence controls honored by {@link Graph.attachStorage};
|
|
22
|
+
* {@link cascadingCache} ignores them (it has its own eviction policy).
|
|
23
|
+
*/
|
|
24
|
+
interface StorageTier {
|
|
25
|
+
/** Read a value. Returns `null` (or resolves to `null`) on miss. */
|
|
26
|
+
load(key: string): unknown | Promise<unknown>;
|
|
27
|
+
/** Write a record. Sync tiers return `void`; async tiers return `Promise<void>`. */
|
|
28
|
+
save(key: string, data: unknown): void | Promise<void>;
|
|
29
|
+
/** Delete a value. Optional — tiers without `clear` are append/overwrite-only. */
|
|
30
|
+
clear?(key: string): void | Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Debounce saves on this tier (ms). Hot tier: `0` (sync-through).
|
|
33
|
+
* Warm: `1000`. Cold: `60000`. Each tier holds its own last-save baseline,
|
|
34
|
+
* so cold flushes aren't penalized by hot flushes.
|
|
35
|
+
*/
|
|
36
|
+
debounceMs?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Every Nth record is a full snapshot; others are diffs against this
|
|
39
|
+
* tier's own baseline. Default `10`. Set `1` for always-full;
|
|
40
|
+
* `Number.POSITIVE_INFINITY` is unsafe — WAL replay needs periodic anchors.
|
|
41
|
+
*/
|
|
42
|
+
compactEvery?: number;
|
|
43
|
+
/** Pre-save filter — return `false` to skip this record on this tier. */
|
|
44
|
+
filter?: (key: string, record: unknown) => boolean;
|
|
45
|
+
}
|
|
46
|
+
/** Handle returned by {@link Graph.attachStorage} — dispose to stop observing. */
|
|
47
|
+
interface StorageHandle {
|
|
48
|
+
dispose(): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* In-memory storage tier (process-local; useful for tests and hot tier).
|
|
52
|
+
*
|
|
53
|
+
* @returns Sync {@link StorageTier} with JSON-cloned isolation.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { memoryStorage } from "@graphrefly/graphrefly-ts";
|
|
58
|
+
*
|
|
59
|
+
* const hot = memoryStorage();
|
|
60
|
+
* graph.attachStorage([hot]);
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @category extra
|
|
64
|
+
*/
|
|
65
|
+
declare function memoryStorage(): StorageTier;
|
|
66
|
+
/**
|
|
67
|
+
* Dict-backed storage tier — stores JSON-cloned values under caller keys in
|
|
68
|
+
* a caller-owned plain object. Useful for embedding in a parent state shape.
|
|
69
|
+
*
|
|
70
|
+
* @param storage - Caller-owned object used as the backing store.
|
|
71
|
+
* @returns Sync {@link StorageTier}.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { dictStorage } from "@graphrefly/graphrefly-ts";
|
|
76
|
+
*
|
|
77
|
+
* const state: Record<string, unknown> = {};
|
|
78
|
+
* graph.attachStorage([dictStorage(state)]);
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @category extra
|
|
82
|
+
*/
|
|
83
|
+
declare function dictStorage(storage: Record<string, unknown>): StorageTier;
|
|
84
|
+
/**
|
|
85
|
+
* Atomic JSON file storage tier (one file per key in a directory, temp + rename).
|
|
86
|
+
*
|
|
87
|
+
* Keys are sanitized to filesystem-safe names (`[^a-zA-Z0-9_-]` → `%<hex>`).
|
|
88
|
+
* `load` returns `null` for missing files, empty files, or invalid JSON.
|
|
89
|
+
*
|
|
90
|
+
* @param dir - Directory where per-key JSON files are written.
|
|
91
|
+
* @returns Sync {@link StorageTier}.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { fileStorage, memoryStorage } from "@graphrefly/graphrefly-ts";
|
|
96
|
+
*
|
|
97
|
+
* graph.attachStorage([memoryStorage(), fileStorage("./checkpoints")]);
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @category extra
|
|
101
|
+
*/
|
|
102
|
+
declare function fileStorage(dir: string): StorageTier;
|
|
103
|
+
/**
|
|
104
|
+
* SQLite storage tier using Node.js `node:sqlite` ({@link DatabaseSync}).
|
|
105
|
+
*
|
|
106
|
+
* Returns a {@link StorageTier} extended with `close()` — the caller owns the
|
|
107
|
+
* connection and should close it when discarding the tier.
|
|
108
|
+
*
|
|
109
|
+
* **Runtime:** Requires Node 22.5+ with `node:sqlite` enabled.
|
|
110
|
+
*
|
|
111
|
+
* @param path - SQLite database file path.
|
|
112
|
+
* @returns Sync {@link StorageTier} with an idempotent `close()` method.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* import { sqliteStorage, memoryStorage } from "@graphrefly/graphrefly-ts";
|
|
117
|
+
*
|
|
118
|
+
* const cold = sqliteStorage("./graphs.sqlite");
|
|
119
|
+
* graph.attachStorage([memoryStorage(), cold]);
|
|
120
|
+
* // ... later, on shutdown:
|
|
121
|
+
* cold.close();
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @category extra
|
|
125
|
+
*/
|
|
126
|
+
declare function sqliteStorage(path: string): StorageTier & {
|
|
127
|
+
close(): void;
|
|
128
|
+
};
|
|
129
|
+
type IndexedDbStorageSpec = {
|
|
130
|
+
dbName: string;
|
|
131
|
+
storeName: string;
|
|
132
|
+
/** Object-store key under which snapshots are written. @default `"graphrefly_checkpoint"`. */
|
|
133
|
+
key?: string;
|
|
134
|
+
version?: number;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Wraps an `IDBRequest` as a one-shot reactive source.
|
|
138
|
+
*
|
|
139
|
+
* @param req - Request whose callbacks are converted to protocol messages.
|
|
140
|
+
* @returns `Node<T>` that emits `DATA` once on success then `COMPLETE`;
|
|
141
|
+
* emits `ERROR` on failure.
|
|
142
|
+
*
|
|
143
|
+
* @category extra
|
|
144
|
+
*/
|
|
145
|
+
declare function fromIDBRequest<T>(req: IDBRequest<T>): Node<T>;
|
|
146
|
+
/**
|
|
147
|
+
* Wraps an `IDBTransaction` terminal lifecycle as a one-shot reactive source.
|
|
148
|
+
*
|
|
149
|
+
* @param tx - Transaction to observe.
|
|
150
|
+
* @returns `Node<void>` that emits `DATA` (`undefined`) then `COMPLETE` on
|
|
151
|
+
* success; emits `ERROR` on `error`/`abort`.
|
|
152
|
+
*
|
|
153
|
+
* @category extra
|
|
154
|
+
*/
|
|
155
|
+
declare function fromIDBTransaction(tx: IDBTransaction): Node<void>;
|
|
156
|
+
/**
|
|
157
|
+
* IndexedDB-backed async storage tier (browser runtime).
|
|
158
|
+
*
|
|
159
|
+
* All three methods return `Promise`s — pairs naturally with a warm/cold
|
|
160
|
+
* cadence where async writes are debounced per tier via
|
|
161
|
+
* {@link Graph.attachStorage}. Writes use `readwrite` transactions; reads use
|
|
162
|
+
* `readonly`. Missing records resolve to `null`.
|
|
163
|
+
*
|
|
164
|
+
* @param spec - Database name, store name, optional `key` (default
|
|
165
|
+
* `"graphrefly_checkpoint"`) and schema `version` (default `1`).
|
|
166
|
+
* @returns Async {@link StorageTier}.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* import { indexedDbStorage, memoryStorage } from "@graphrefly/graphrefly-ts";
|
|
171
|
+
*
|
|
172
|
+
* graph.attachStorage([
|
|
173
|
+
* memoryStorage(),
|
|
174
|
+
* indexedDbStorage({ dbName: "myApp", storeName: "checkpoints" }),
|
|
175
|
+
* ]);
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @category extra
|
|
179
|
+
*/
|
|
180
|
+
declare function indexedDbStorage(spec: IndexedDbStorageSpec): StorageTier;
|
|
181
|
+
|
|
182
|
+
export { type IndexedDbStorageSpec as I, type StorageHandle as S, type StorageTier as a, fromIDBRequest as b, fromIDBTransaction as c, dictStorage as d, fileStorage as f, indexedDbStorage as i, memoryStorage as m, sqliteStorage as s };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphrefly/graphrefly",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"packageManager": "pnpm@10.33.0+sha512.10568bb4a6afb58c9eb3630da90cc9516417abebd3fabbe6739f0ae795728da1491e9db5a544c76ad8eb7570f5c4bb3d6c637b2cb41bfdcdb47fa823c8649319",
|
|
5
5
|
"description": "Reactive harness layer for agent workflows. Describe automations in plain language, trace every decision, enforce policies, persist checkpoints. Zero dependencies.",
|
|
6
6
|
"repository": {
|