arrowbase 0.1.1
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 +27 -0
- package/COMPATIBILITY.md +398 -0
- package/LICENSE +21 -0
- package/MIGRATING.md +238 -0
- package/README.md +897 -0
- package/RELEASE_NOTES.md +68 -0
- package/dist/arrow.d.ts +93 -0
- package/dist/arrow.js +5366 -0
- package/dist/arrow.js.map +1 -0
- package/dist/broadcast.d.ts +173 -0
- package/dist/broadcast.js +319 -0
- package/dist/broadcast.js.map +1 -0
- package/dist/collection-DGlKgOGi.d.ts +1932 -0
- package/dist/idb.d.ts +146 -0
- package/dist/idb.js +6193 -0
- package/dist/idb.js.map +1 -0
- package/dist/index.d.ts +1802 -0
- package/dist/index.js +13924 -0
- package/dist/index.js.map +1 -0
- package/dist/query-CzV9E57Y.d.ts +279 -0
- package/dist/react.d.ts +51 -0
- package/dist/react.js +1633 -0
- package/dist/react.js.map +1 -0
- package/dist/tanstack.d.ts +51 -0
- package/dist/tanstack.js +191 -0
- package/dist/tanstack.js.map +1 -0
- package/dist/types-CSoU6uED.d.ts +50 -0
- package/package.json +139 -0
package/dist/idb.d.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { C as Collection, a as CompiledSchema } from './collection-DGlKgOGi.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* IndexedDB persistence adapter for ArrowBase.
|
|
5
|
+
*
|
|
6
|
+
* Optional subpath (`arrowbase/idb`). Stores a single snapshot per
|
|
7
|
+
* collection under a caller-supplied key in one object store. Writes
|
|
8
|
+
* are debounced so bursts of mutations cause at most one IDB round-trip
|
|
9
|
+
* per window.
|
|
10
|
+
*
|
|
11
|
+
* ### Usage
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { Collection, defineSchema } from 'arrowbase';
|
|
15
|
+
* import { IdbPersistence } from 'arrowbase/idb';
|
|
16
|
+
*
|
|
17
|
+
* const schema = defineSchema({ ... });
|
|
18
|
+
*
|
|
19
|
+
* // 1. Try to restore the last snapshot. Falls back to a fresh
|
|
20
|
+
* // collection when the key is empty.
|
|
21
|
+
* const persist = await IdbPersistence.open(schema, {
|
|
22
|
+
* dbName: 'my-app',
|
|
23
|
+
* key: 'features',
|
|
24
|
+
* capacity: 10_000,
|
|
25
|
+
* });
|
|
26
|
+
* const collection = persist.collection;
|
|
27
|
+
*
|
|
28
|
+
* // 2. Subscribe to mutations and auto-snapshot with a debounce.
|
|
29
|
+
* persist.start({ debounceMs: 500 });
|
|
30
|
+
*
|
|
31
|
+
* // 3. Force an immediate flush before unload, etc.
|
|
32
|
+
* window.addEventListener('beforeunload', () => { persist.flush(); });
|
|
33
|
+
*
|
|
34
|
+
* // 4. Tear down on shutdown.
|
|
35
|
+
* await persist.close();
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* ### Formats
|
|
39
|
+
*
|
|
40
|
+
* - `'arbs'` (default) — ArrowBase's native binary snapshot. Fast,
|
|
41
|
+
* preserves ranged offsets, round-trips soft-deletes exactly.
|
|
42
|
+
* - `'arrow-ipc'` — standard Apache Arrow IPC file. Portable across
|
|
43
|
+
* the Arrow ecosystem at the cost of a rebuild on restore. Requires
|
|
44
|
+
* the optional `apache-arrow` peer dependency.
|
|
45
|
+
*
|
|
46
|
+
* ### Storage layout
|
|
47
|
+
*
|
|
48
|
+
* One IDB object store. Keys are caller-supplied strings (typically the
|
|
49
|
+
* collection name). Values are `{ format, bytes, version, savedAt }`
|
|
50
|
+
* records. Storing metadata alongside the bytes keeps the schema
|
|
51
|
+
* self-describing and lets us detect format changes cheaply.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
type IdbPersistenceFormat = 'arbs' | 'arrow-ipc';
|
|
55
|
+
interface IdbPersistenceOpenOptions {
|
|
56
|
+
/** Name of the IDB database. Defaults to `"arrowbase"`. */
|
|
57
|
+
dbName?: string;
|
|
58
|
+
/** Name of the object store inside the database. Defaults to `"snapshots"`. */
|
|
59
|
+
storeName?: string;
|
|
60
|
+
/** Key under which this collection's snapshot is stored. Required. */
|
|
61
|
+
key: string;
|
|
62
|
+
/**
|
|
63
|
+
* Snapshot format. Defaults to `'arbs'`. `'arrow-ipc'` requires
|
|
64
|
+
* `apache-arrow` to be installed.
|
|
65
|
+
*/
|
|
66
|
+
format?: IdbPersistenceFormat;
|
|
67
|
+
/** Passed through to `Collection.create` when no snapshot exists. */
|
|
68
|
+
capacity?: number;
|
|
69
|
+
/** Optional callback for async errors during save (debounced writes). */
|
|
70
|
+
onError?: (err: unknown) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Inject a custom `IDBFactory` (e.g., `fake-indexeddb` for tests).
|
|
73
|
+
* Defaults to `globalThis.indexedDB`.
|
|
74
|
+
*/
|
|
75
|
+
indexedDB?: IDBFactory;
|
|
76
|
+
}
|
|
77
|
+
interface IdbPersistenceStartOptions {
|
|
78
|
+
/**
|
|
79
|
+
* Coalesce change events inside this many ms, then write once.
|
|
80
|
+
* Defaults to 250ms.
|
|
81
|
+
*/
|
|
82
|
+
debounceMs?: number;
|
|
83
|
+
/**
|
|
84
|
+
* If true, write an initial snapshot immediately on start() even
|
|
85
|
+
* when no change has occurred yet. Defaults to false — we assume
|
|
86
|
+
* the caller already restored the state or intentionally started
|
|
87
|
+
* with an empty collection.
|
|
88
|
+
*/
|
|
89
|
+
saveImmediately?: boolean;
|
|
90
|
+
}
|
|
91
|
+
declare class IdbPersistence {
|
|
92
|
+
/** The live collection, either freshly created or restored. */
|
|
93
|
+
readonly collection: Collection;
|
|
94
|
+
private readonly db;
|
|
95
|
+
private readonly storeName;
|
|
96
|
+
private readonly key;
|
|
97
|
+
private format;
|
|
98
|
+
private readonly onError?;
|
|
99
|
+
/**
|
|
100
|
+
* Open the adapter and restore any existing snapshot.
|
|
101
|
+
*
|
|
102
|
+
* If the key is empty, a fresh collection is created using the
|
|
103
|
+
* supplied schema + capacity (default 1024). The caller can then
|
|
104
|
+
* call `start()` to begin auto-persisting future mutations.
|
|
105
|
+
*/
|
|
106
|
+
static open(schema: CompiledSchema, options: IdbPersistenceOpenOptions): Promise<IdbPersistence>;
|
|
107
|
+
private saveTimer;
|
|
108
|
+
private unsubscribe;
|
|
109
|
+
private closed;
|
|
110
|
+
private dirtyDuringSave;
|
|
111
|
+
private savingPromise;
|
|
112
|
+
private debounceMs;
|
|
113
|
+
private constructor();
|
|
114
|
+
/**
|
|
115
|
+
* Subscribe to collection mutations and begin debounced auto-saving.
|
|
116
|
+
* Safe to call multiple times — only the first has effect.
|
|
117
|
+
*/
|
|
118
|
+
start(options?: IdbPersistenceStartOptions): void;
|
|
119
|
+
/**
|
|
120
|
+
* Stop subscribing. Any pending debounced write is cancelled; call
|
|
121
|
+
* `flush()` first if you need to persist the current state.
|
|
122
|
+
*/
|
|
123
|
+
stop(): void;
|
|
124
|
+
/**
|
|
125
|
+
* Write the current collection state immediately, bypassing debounce.
|
|
126
|
+
* Resolves after the IDB transaction completes.
|
|
127
|
+
*/
|
|
128
|
+
flush(): Promise<void>;
|
|
129
|
+
/** Stop + close the underlying IDB connection. Idempotent. */
|
|
130
|
+
close(): Promise<void>;
|
|
131
|
+
/** Switch between snapshot formats. Takes effect on the next save. */
|
|
132
|
+
setFormat(format: IdbPersistenceFormat): void;
|
|
133
|
+
private scheduleSave;
|
|
134
|
+
private doSave;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Remove a stored snapshot. Mostly useful for tests and for "wipe
|
|
138
|
+
* local cache" UX.
|
|
139
|
+
*/
|
|
140
|
+
declare function deleteStoredSnapshot(key: string, options?: {
|
|
141
|
+
dbName?: string;
|
|
142
|
+
storeName?: string;
|
|
143
|
+
indexedDB?: IDBFactory;
|
|
144
|
+
}): Promise<void>;
|
|
145
|
+
|
|
146
|
+
export { IdbPersistence, type IdbPersistenceFormat, type IdbPersistenceOpenOptions, type IdbPersistenceStartOptions, deleteStoredSnapshot };
|