@fireproof/core 0.18.0 → 0.19.0-dev-use-fix
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +29 -15
- package/chunk-AZVWSRER.js +208 -0
- package/chunk-AZVWSRER.js.map +1 -0
- package/chunk-H3A2HMMM.js +164 -0
- package/chunk-H3A2HMMM.js.map +1 -0
- package/chunk-NZNG6TQT.js +370 -0
- package/chunk-NZNG6TQT.js.map +1 -0
- package/chunk-VZGT7ZYP.js +22 -0
- package/chunk-VZGT7ZYP.js.map +1 -0
- package/chunk-ZHO4NMWL.js +39 -0
- package/chunk-ZHO4NMWL.js.map +1 -0
- package/index.cjs +4706 -0
- package/index.cjs.map +1 -0
- package/index.d.cts +1012 -0
- package/index.d.ts +1012 -0
- package/index.js +2856 -0
- package/index.js.map +1 -0
- package/metafile-cjs.json +1 -0
- package/metafile-esm.json +1 -0
- package/node-sys-container-E7LADX2Z.js +29 -0
- package/node-sys-container-E7LADX2Z.js.map +1 -0
- package/package.json +23 -109
- package/sqlite-data-store-3ST7XOLX.js +120 -0
- package/sqlite-data-store-3ST7XOLX.js.map +1 -0
- package/sqlite-meta-store-QOIMCSJ7.js +137 -0
- package/sqlite-meta-store-QOIMCSJ7.js.map +1 -0
- package/sqlite-wal-store-JFBQPOYT.js +123 -0
- package/sqlite-wal-store-JFBQPOYT.js.map +1 -0
- package/store-file-CSS5THFH.js +193 -0
- package/store-file-CSS5THFH.js.map +1 -0
- package/store-indexdb-DR4HELVP.js +20 -0
- package/store-indexdb-DR4HELVP.js.map +1 -0
- package/store-sql-BG6SMGQJ.js +344 -0
- package/store-sql-BG6SMGQJ.js.map +1 -0
- package/tests/blockstore/loader.test.ts +265 -0
- package/tests/blockstore/store.test.ts +164 -0
- package/tests/blockstore/transaction.test.ts +121 -0
- package/tests/fireproof/config.test.ts +212 -0
- package/tests/fireproof/crdt.test.ts +434 -0
- package/tests/fireproof/database.test.ts +466 -0
- package/tests/fireproof/fireproof.test.ts +602 -0
- package/tests/fireproof/hello.test.ts +54 -0
- package/tests/fireproof/indexer.test.ts +389 -0
- package/tests/helpers.ts +81 -0
- package/tests/react/useFireproof.test.tsx +19 -0
- package/tests/www/gallery.html +132 -0
- package/tests/www/iife.html +42 -0
- package/tests/www/todo-aws.html +232 -0
- package/tests/www/todo-ipfs.html +213 -0
- package/tests/www/todo-local.html +214 -0
- package/tests/www/todo-netlify.html +227 -0
- package/tests/www/todo.html +236 -0
- package/dist/browser/fireproof.cjs +0 -1172
- package/dist/browser/fireproof.cjs.map +0 -1
- package/dist/browser/fireproof.d.cts +0 -268
- package/dist/browser/fireproof.d.ts +0 -268
- package/dist/browser/fireproof.global.js +0 -24178
- package/dist/browser/fireproof.global.js.map +0 -1
- package/dist/browser/fireproof.js +0 -1147
- package/dist/browser/fireproof.js.map +0 -1
- package/dist/browser/metafile-cjs.json +0 -1
- package/dist/browser/metafile-esm.json +0 -1
- package/dist/browser/metafile-iife.json +0 -1
- package/dist/memory/fireproof.cjs +0 -1172
- package/dist/memory/fireproof.cjs.map +0 -1
- package/dist/memory/fireproof.d.cts +0 -268
- package/dist/memory/fireproof.d.ts +0 -268
- package/dist/memory/fireproof.global.js +0 -24178
- package/dist/memory/fireproof.global.js.map +0 -1
- package/dist/memory/fireproof.js +0 -1147
- package/dist/memory/fireproof.js.map +0 -1
- package/dist/memory/metafile-cjs.json +0 -1
- package/dist/memory/metafile-esm.json +0 -1
- package/dist/memory/metafile-iife.json +0 -1
- package/dist/node/fireproof.cjs +0 -1172
- package/dist/node/fireproof.cjs.map +0 -1
- package/dist/node/fireproof.d.cts +0 -268
- package/dist/node/fireproof.d.ts +0 -268
- package/dist/node/fireproof.global.js +0 -38540
- package/dist/node/fireproof.global.js.map +0 -1
- package/dist/node/fireproof.js +0 -1138
- package/dist/node/fireproof.js.map +0 -1
- package/dist/node/metafile-cjs.json +0 -1
- package/dist/node/metafile-esm.json +0 -1
- package/dist/node/metafile-iife.json +0 -1
package/index.d.cts
ADDED
@@ -0,0 +1,1012 @@
|
|
1
|
+
import { Result, Logger, ResolveOnce, EnvImpl } from '@adviser/cement';
|
2
|
+
export { Logger } from '@adviser/cement';
|
3
|
+
import { EventLink } from '@web3-storage/pail/clock/api';
|
4
|
+
import { Operation } from '@web3-storage/pail/crdt/api';
|
5
|
+
import { Version, Block, Link } from 'multiformats';
|
6
|
+
import { ToString } from '@ipld/dag-json';
|
7
|
+
import { CarReader } from '@ipld/car';
|
8
|
+
import { MemoryBlockstore } from '@web3-storage/pail/block';
|
9
|
+
import { BlockFetcher as BlockFetcher$1 } from '@web3-storage/pail/api';
|
10
|
+
import { ProllyNode as ProllyNode$1 } from 'prolly-trees/db-index';
|
11
|
+
import { EventBlock } from '@web3-storage/pail/clock';
|
12
|
+
import { PathLike, MakeDirectoryOptions, Stats, ObjectEncodingOptions, Dirent } from 'node:fs';
|
13
|
+
import { RunResult } from 'better-sqlite3';
|
14
|
+
|
15
|
+
interface GatewayOpts {
|
16
|
+
readonly gateway: Gateway;
|
17
|
+
}
|
18
|
+
declare class NotFoundError extends Error {
|
19
|
+
readonly code = "ENOENT";
|
20
|
+
}
|
21
|
+
declare function isNotFoundError(e: Error | Result<unknown> | unknown): e is NotFoundError;
|
22
|
+
type GetResult = Result<Uint8Array, NotFoundError | Error>;
|
23
|
+
type VoidResult = Result<void>;
|
24
|
+
interface Gateway {
|
25
|
+
buildUrl(baseUrl: URL, key: string): Promise<Result<URL>>;
|
26
|
+
start(baseUrl: URL): Promise<VoidResult>;
|
27
|
+
close(baseUrl: URL): Promise<VoidResult>;
|
28
|
+
destroy(baseUrl: URL): Promise<VoidResult>;
|
29
|
+
put(url: URL, body: Uint8Array): Promise<VoidResult>;
|
30
|
+
get(url: URL): Promise<GetResult>;
|
31
|
+
delete(url: URL): Promise<VoidResult>;
|
32
|
+
}
|
33
|
+
|
34
|
+
type BlockFetcher = BlockFetcher$1;
|
35
|
+
declare class CarTransaction extends MemoryBlockstore implements CarMakeable {
|
36
|
+
readonly parent: BaseBlockstore;
|
37
|
+
constructor(parent: BaseBlockstore, opts?: {
|
38
|
+
add: boolean;
|
39
|
+
});
|
40
|
+
get<T, C extends number, A extends number, V extends Version>(cid: AnyLink): Promise<Block<T, C, A, V> | undefined>;
|
41
|
+
superGet(cid: AnyLink): Promise<AnyBlock | undefined>;
|
42
|
+
}
|
43
|
+
declare class BaseBlockstore implements BlockFetcher {
|
44
|
+
readonly transactions: Set<CarTransaction>;
|
45
|
+
readonly ebOpts: BlockstoreRuntime;
|
46
|
+
readonly loader?: Loader;
|
47
|
+
readonly name?: string;
|
48
|
+
ready(): Promise<void>;
|
49
|
+
close(): Promise<void>;
|
50
|
+
destroy(): Promise<void>;
|
51
|
+
readonly logger: Logger;
|
52
|
+
constructor(ebOpts?: BlockstoreOpts);
|
53
|
+
get<T, C extends number, A extends number, V extends Version>(cid: AnyAnyLink): Promise<Block<T, C, A, V> | undefined>;
|
54
|
+
put(cid: AnyAnyLink, block: Uint8Array): Promise<void>;
|
55
|
+
lastTxMeta?: unknown;
|
56
|
+
transaction<M extends TransactionMeta>(fn: (t: CarTransaction) => Promise<M>, _opts?: {}): Promise<TransactionWrapper<M>>;
|
57
|
+
entries(): AsyncIterableIterator<AnyBlock>;
|
58
|
+
}
|
59
|
+
declare class EncryptedBlockstore extends BaseBlockstore {
|
60
|
+
readonly name: string;
|
61
|
+
readonly loader: Loader;
|
62
|
+
ready(): Promise<void>;
|
63
|
+
close(): Promise<void>;
|
64
|
+
destroy(): Promise<void>;
|
65
|
+
compacting: boolean;
|
66
|
+
readonly logger: Logger;
|
67
|
+
constructor(ebOpts: BlockstoreOpts);
|
68
|
+
get<T, C extends number, A extends number, V extends Version>(cid: AnyAnyLink): Promise<Block<T, C, A, V> | undefined>;
|
69
|
+
transaction<M extends TransactionMeta>(fn: (t: CarTransaction) => Promise<M>, opts?: {
|
70
|
+
noLoader: boolean;
|
71
|
+
}): Promise<TransactionWrapper<M>>;
|
72
|
+
getFile(car: AnyLink, cid: AnyLink, isPublic?: boolean): Promise<Uint8Array>;
|
73
|
+
compact(): Promise<void>;
|
74
|
+
defaultCompact(blocks: CompactionFetcher, logger: Logger): Promise<TransactionMeta>;
|
75
|
+
entries(): AsyncIterableIterator<AnyBlock>;
|
76
|
+
}
|
77
|
+
declare class CompactionFetcher implements BlockFetcher {
|
78
|
+
blockstore: EncryptedBlockstore;
|
79
|
+
loggedBlocks: CarTransaction;
|
80
|
+
constructor(blocks: EncryptedBlockstore);
|
81
|
+
get<T, C extends number, A extends number, V extends Version>(cid: AnyLink): Promise<Block<T, C, A, V> | undefined>;
|
82
|
+
}
|
83
|
+
type CompactFn = (blocks: CompactionFetcher) => Promise<TransactionMeta>;
|
84
|
+
interface BlockstoreOpts {
|
85
|
+
readonly logger?: Logger;
|
86
|
+
readonly applyMeta?: (meta: TransactionMeta, snap?: boolean) => Promise<void>;
|
87
|
+
readonly compact?: CompactFn;
|
88
|
+
readonly autoCompact?: number;
|
89
|
+
readonly crypto?: CryptoOpts;
|
90
|
+
readonly store?: StoreOpts;
|
91
|
+
readonly public?: boolean;
|
92
|
+
readonly meta?: DbMeta;
|
93
|
+
readonly name?: string;
|
94
|
+
readonly threshold?: number;
|
95
|
+
}
|
96
|
+
interface BlockstoreRuntime {
|
97
|
+
readonly logger: Logger;
|
98
|
+
readonly applyMeta: (meta: TransactionMeta, snap?: boolean) => Promise<void>;
|
99
|
+
readonly compact: CompactFn;
|
100
|
+
readonly autoCompact: number;
|
101
|
+
readonly crypto: CryptoOpts;
|
102
|
+
readonly store: StoreOpts;
|
103
|
+
readonly storeRuntime: StoreRuntime;
|
104
|
+
readonly public: boolean;
|
105
|
+
readonly meta?: DbMeta;
|
106
|
+
readonly name?: string;
|
107
|
+
readonly threshold: number;
|
108
|
+
}
|
109
|
+
|
110
|
+
type QueueFunction = () => Promise<void>;
|
111
|
+
declare class CommitQueue<T = void> {
|
112
|
+
readonly queue: QueueFunction[];
|
113
|
+
processing: boolean;
|
114
|
+
enqueue(fn: () => Promise<T>): Promise<T>;
|
115
|
+
processNext(): void;
|
116
|
+
}
|
117
|
+
|
118
|
+
type AbstractRemoteMetaStore = MetaStore & {
|
119
|
+
handleByteHeads(byteHeads: Uint8Array[], branch?: string): Promise<DbMeta[]>;
|
120
|
+
};
|
121
|
+
declare abstract class Loadable {
|
122
|
+
name: string;
|
123
|
+
abstract readonly logger: Logger;
|
124
|
+
abstract readonly ebOpts: BlockstoreRuntime;
|
125
|
+
remoteCarStore?: DataStore;
|
126
|
+
abstract carStore(): Promise<DataStore>;
|
127
|
+
carLog: CarLog;
|
128
|
+
remoteMetaStore?: AbstractRemoteMetaStore;
|
129
|
+
remoteFileStore?: DataStore;
|
130
|
+
abstract ready(): Promise<void>;
|
131
|
+
abstract close(): Promise<void>;
|
132
|
+
abstract fileStore(): Promise<DataStore>;
|
133
|
+
abstract remoteWAL(): Promise<RemoteWAL>;
|
134
|
+
abstract handleDbMetasFromStore(metas: DbMeta[]): Promise<void>;
|
135
|
+
}
|
136
|
+
declare class Loader implements Loadable {
|
137
|
+
readonly name: string;
|
138
|
+
readonly ebOpts: BlockstoreRuntime;
|
139
|
+
readonly commitQueue: CommitQueue<CarGroup>;
|
140
|
+
readonly isCompacting = false;
|
141
|
+
readonly carReaders: Map<string, Promise<CarReader>>;
|
142
|
+
readonly seenCompacted: Set<string>;
|
143
|
+
readonly processedCars: Set<string>;
|
144
|
+
carLog: CarLog;
|
145
|
+
key?: string;
|
146
|
+
keyId?: string;
|
147
|
+
remoteMetaStore?: AbstractRemoteMetaStore;
|
148
|
+
remoteCarStore?: DataStore;
|
149
|
+
remoteFileStore?: DataStore;
|
150
|
+
private getBlockCache;
|
151
|
+
private seenMeta;
|
152
|
+
private writeLimit;
|
153
|
+
carStore(): Promise<DataStore>;
|
154
|
+
fileStore(): Promise<DataStore>;
|
155
|
+
remoteWAL(): Promise<RemoteWAL>;
|
156
|
+
metaStore(): Promise<MetaStore>;
|
157
|
+
readonly onceReady: ResolveOnce<void, void>;
|
158
|
+
ready(): Promise<void>;
|
159
|
+
close(): Promise<void>;
|
160
|
+
destroy(): Promise<void>;
|
161
|
+
readonly logger: Logger;
|
162
|
+
constructor(name: string, ebOpts: BlockstoreOpts);
|
163
|
+
handleDbMetasFromStore(metas: DbMeta[]): Promise<void>;
|
164
|
+
mergeDbMetaIntoClock(meta: DbMeta): Promise<void>;
|
165
|
+
protected ingestKeyFromMeta(meta: DbMeta): Promise<void>;
|
166
|
+
loadCarHeaderFromMeta<T>({ cars: cids }: DbMeta): Promise<CarHeader<T>>;
|
167
|
+
_getKey(): Promise<string | undefined>;
|
168
|
+
commitFiles(t: CarTransaction, done: TransactionMeta, opts?: CommitOpts): Promise<CarGroup>;
|
169
|
+
_commitInternalFiles(t: CarTransaction, done: TransactionMeta, opts?: CommitOpts): Promise<CarGroup>;
|
170
|
+
loadFileCar(cid: AnyLink, isPublic?: boolean): Promise<CarReader>;
|
171
|
+
commit<T = TransactionMeta>(t: CarTransaction, done: T, opts?: CommitOpts): Promise<CarGroup>;
|
172
|
+
cacheTransaction(t: CarTransaction): Promise<void>;
|
173
|
+
cacheCarReader(carCidStr: string, reader: CarReader): Promise<void>;
|
174
|
+
_commitInternal<T>(t: CarTransaction, done: T, opts?: CommitOpts): Promise<CarGroup>;
|
175
|
+
prepareCarFilesFiles(roots: AnyLink[], t: CarTransaction, isPublic: boolean): Promise<{
|
176
|
+
cid: AnyLink;
|
177
|
+
bytes: Uint8Array;
|
178
|
+
}[]>;
|
179
|
+
prepareCarFiles(rootBlock: AnyBlock, t: CarTransaction, isPublic: boolean): Promise<{
|
180
|
+
cid: AnyLink;
|
181
|
+
bytes: Uint8Array;
|
182
|
+
}[]>;
|
183
|
+
private createCarFile;
|
184
|
+
protected makeFileCarHeader(result: FileTransactionMeta): TransactionMeta;
|
185
|
+
updateCarLog<T>(cids: CarGroup, fp: CarHeader<T>, compact: boolean): Promise<void>;
|
186
|
+
removeCidsForCompact(cid: AnyLink): Promise<void>;
|
187
|
+
entries(cache?: boolean): AsyncIterableIterator<AnyBlock>;
|
188
|
+
getBlock(cid: AnyLink): Promise<AnyBlock | Falsy>;
|
189
|
+
protected makeCarHeader<T>(meta: T, cars: CarLog, compact?: boolean): CarHeader<T>;
|
190
|
+
loadCar(cid: AnyLink): Promise<CarReader>;
|
191
|
+
protected storesLoadCar(cid: AnyLink, local: DataStore, remote?: DataStore, publicFiles?: boolean): Promise<CarReader>;
|
192
|
+
protected ensureDecryptedReader(reader: CarReader): Promise<CarReader>;
|
193
|
+
protected setKey(key: string): Promise<void>;
|
194
|
+
protected getMoreReaders(cids: AnyLink[]): Promise<void>;
|
195
|
+
}
|
196
|
+
|
197
|
+
declare abstract class VersionedStore {
|
198
|
+
readonly name: string;
|
199
|
+
readonly url: URL;
|
200
|
+
readonly logger: Logger;
|
201
|
+
constructor(name: string, url: URL, logger: Logger);
|
202
|
+
readonly _onStarted: (() => void)[];
|
203
|
+
onStarted(fn: () => void): void;
|
204
|
+
abstract start(): Promise<Result<void>>;
|
205
|
+
readonly _onClosed: (() => void)[];
|
206
|
+
onClosed(fn: () => void): void;
|
207
|
+
abstract close(): Promise<Result<void>>;
|
208
|
+
}
|
209
|
+
declare class MetaStore extends VersionedStore {
|
210
|
+
readonly tag: string;
|
211
|
+
readonly gateway: Gateway;
|
212
|
+
constructor(name: string, url: URL, logger: Logger, gateway: Gateway);
|
213
|
+
makeHeader({ cars, key }: DbMeta): ToString<DbMeta>;
|
214
|
+
parseHeader(headerData: ToString<DbMeta>): DbMeta;
|
215
|
+
start(): Promise<Result<void>>;
|
216
|
+
load(branch?: string): Promise<DbMeta[] | Falsy>;
|
217
|
+
save(meta: DbMeta, branch?: string): Promise<void>;
|
218
|
+
close(): Promise<Result<void>>;
|
219
|
+
destroy(): Promise<Result<void>>;
|
220
|
+
}
|
221
|
+
interface DataSaveOpts {
|
222
|
+
readonly public: boolean;
|
223
|
+
}
|
224
|
+
declare class DataStore extends VersionedStore {
|
225
|
+
readonly tag: string;
|
226
|
+
readonly gateway: Gateway;
|
227
|
+
constructor(name: string, url: URL, logger: Logger, gateway: Gateway);
|
228
|
+
start(): Promise<Result<void>>;
|
229
|
+
load(cid: AnyLink): Promise<AnyBlock>;
|
230
|
+
save(car: AnyBlock, opts?: DataSaveOpts): Promise<void>;
|
231
|
+
remove(cid: AnyLink): Promise<Result<void>>;
|
232
|
+
close(): Promise<Result<void>>;
|
233
|
+
destroy(): Promise<Result<void>>;
|
234
|
+
}
|
235
|
+
interface WALState {
|
236
|
+
operations: DbMeta[];
|
237
|
+
noLoaderOps: DbMeta[];
|
238
|
+
fileOperations: {
|
239
|
+
readonly cid: AnyLink;
|
240
|
+
readonly public: boolean;
|
241
|
+
}[];
|
242
|
+
}
|
243
|
+
declare class RemoteWAL extends VersionedStore {
|
244
|
+
readonly tag: string;
|
245
|
+
readonly loader: Loadable;
|
246
|
+
readonly _ready: ResolveOnce<void, void>;
|
247
|
+
private ready;
|
248
|
+
walState: WALState;
|
249
|
+
readonly processing: Promise<void> | undefined;
|
250
|
+
readonly processQueue: CommitQueue<void>;
|
251
|
+
readonly gateway: Gateway;
|
252
|
+
constructor(loader: Loadable, url: URL, logger: Logger, gateway: Gateway);
|
253
|
+
enqueue(dbMeta: DbMeta, opts: CommitOpts): Promise<void>;
|
254
|
+
enqueueFile(fileCid: AnyLink, publicFile?: boolean): Promise<void>;
|
255
|
+
_process(): Promise<void>;
|
256
|
+
_doProcess(): Promise<void>;
|
257
|
+
start(): Promise<VoidResult>;
|
258
|
+
load(): Promise<WALState | Falsy>;
|
259
|
+
save(state: WALState): Promise<void>;
|
260
|
+
close(): Promise<Result<undefined, Error>>;
|
261
|
+
destroy(): Promise<VoidResult>;
|
262
|
+
}
|
263
|
+
|
264
|
+
type AnyLink = Link<unknown, number, number, Version>;
|
265
|
+
type CarGroup = AnyLink[];
|
266
|
+
type CarLog = CarGroup[];
|
267
|
+
type AnyAnyLink = Link<unknown, number, number, Version>;
|
268
|
+
interface AnyBlock {
|
269
|
+
readonly cid: Link<unknown, number, number, Version>;
|
270
|
+
readonly bytes: Uint8Array;
|
271
|
+
}
|
272
|
+
interface CarMakeable {
|
273
|
+
entries(): Iterable<AnyBlock>;
|
274
|
+
get(cid: AnyLink): Promise<AnyBlock | undefined>;
|
275
|
+
}
|
276
|
+
interface CarHeader<T> {
|
277
|
+
readonly cars: CarLog;
|
278
|
+
readonly compact: CarLog;
|
279
|
+
readonly meta: T;
|
280
|
+
}
|
281
|
+
interface TransactionWrapper<M extends TransactionMeta> {
|
282
|
+
meta: M;
|
283
|
+
cars?: CarGroup;
|
284
|
+
t: CarTransaction;
|
285
|
+
}
|
286
|
+
type TransactionMeta = unknown;
|
287
|
+
interface CryptoOpts {
|
288
|
+
readonly importKey: typeof crypto.subtle.importKey;
|
289
|
+
readonly decrypt: (algo: {
|
290
|
+
name: string;
|
291
|
+
iv: Uint8Array;
|
292
|
+
tagLength: number;
|
293
|
+
}, key: CryptoKey, data: Uint8Array) => Promise<ArrayBuffer>;
|
294
|
+
readonly encrypt: (algo: {
|
295
|
+
name: string;
|
296
|
+
iv: Uint8Array;
|
297
|
+
tagLength: number;
|
298
|
+
}, key: CryptoKey, data: Uint8Array) => Promise<ArrayBuffer>;
|
299
|
+
readonly digestSHA256: (data: Uint8Array) => Promise<ArrayBuffer>;
|
300
|
+
readonly randomBytes: (size: number) => Uint8Array;
|
301
|
+
}
|
302
|
+
interface BlobLike {
|
303
|
+
stream: () => ReadableStream;
|
304
|
+
}
|
305
|
+
interface StoreFactory {
|
306
|
+
makeMetaStore?: (loader: Loadable) => Promise<MetaStore>;
|
307
|
+
makeDataStore?: (loader: Loadable) => Promise<DataStore>;
|
308
|
+
makeRemoteWAL?: (loader: Loadable) => Promise<RemoteWAL>;
|
309
|
+
encodeFile?: (blob: BlobLike) => Promise<{
|
310
|
+
cid: AnyLink;
|
311
|
+
blocks: AnyBlock[];
|
312
|
+
}>;
|
313
|
+
decodeFile?: (blocks: unknown, cid: AnyLink, meta: DocFileMeta) => Promise<File>;
|
314
|
+
}
|
315
|
+
interface StoreOpts extends StoreFactory {
|
316
|
+
readonly isIndex?: string;
|
317
|
+
readonly stores?: {
|
318
|
+
readonly base?: string | URL;
|
319
|
+
readonly meta?: string | URL;
|
320
|
+
readonly data?: string | URL;
|
321
|
+
readonly index?: string | URL;
|
322
|
+
readonly remoteWAL?: string | URL;
|
323
|
+
};
|
324
|
+
}
|
325
|
+
interface TestStore {
|
326
|
+
get(url: URL, key: string): Promise<Uint8Array>;
|
327
|
+
}
|
328
|
+
interface StoreRuntime {
|
329
|
+
makeMetaStore(loader: Loadable): Promise<MetaStore>;
|
330
|
+
makeDataStore(loader: Loadable): Promise<DataStore>;
|
331
|
+
makeRemoteWAL(loader: Loadable): Promise<RemoteWAL>;
|
332
|
+
encodeFile(blob: BlobLike): Promise<{
|
333
|
+
cid: AnyLink;
|
334
|
+
blocks: AnyBlock[];
|
335
|
+
}>;
|
336
|
+
decodeFile(blocks: unknown, cid: AnyLink, meta: DocFileMeta): Promise<File>;
|
337
|
+
}
|
338
|
+
interface CommitOpts {
|
339
|
+
readonly noLoader?: boolean;
|
340
|
+
readonly compact?: boolean;
|
341
|
+
readonly public?: boolean;
|
342
|
+
}
|
343
|
+
interface DbMeta {
|
344
|
+
readonly cars: CarGroup;
|
345
|
+
key?: string;
|
346
|
+
}
|
347
|
+
interface UploadMetaFnParams {
|
348
|
+
readonly name: string;
|
349
|
+
readonly branch: string;
|
350
|
+
}
|
351
|
+
type FnParamTypes = "data" | "file";
|
352
|
+
interface UploadDataFnParams {
|
353
|
+
readonly type: FnParamTypes;
|
354
|
+
readonly name: string;
|
355
|
+
readonly car: string;
|
356
|
+
readonly size: string;
|
357
|
+
}
|
358
|
+
interface DownloadDataFnParams {
|
359
|
+
readonly type: FnParamTypes;
|
360
|
+
readonly name: string;
|
361
|
+
readonly car: string;
|
362
|
+
}
|
363
|
+
interface DownloadMetaFnParams {
|
364
|
+
readonly name: string;
|
365
|
+
readonly branch: string;
|
366
|
+
}
|
367
|
+
interface Connection {
|
368
|
+
readonly loader?: Loadable;
|
369
|
+
readonly loaded: Promise<void>;
|
370
|
+
connectMeta({ loader }: {
|
371
|
+
loader?: Loadable;
|
372
|
+
}): void;
|
373
|
+
connectStorage({ loader }: {
|
374
|
+
loader?: Loadable;
|
375
|
+
}): void;
|
376
|
+
metaUpload(bytes: Uint8Array, params: UploadMetaFnParams): Promise<Uint8Array[] | Falsy>;
|
377
|
+
dataUpload(bytes: Uint8Array, params: UploadDataFnParams, opts?: {
|
378
|
+
public?: boolean;
|
379
|
+
}): Promise<void>;
|
380
|
+
metaDownload(params: DownloadMetaFnParams): Promise<Uint8Array[] | Falsy>;
|
381
|
+
dataDownload(params: DownloadDataFnParams): Promise<Uint8Array | Falsy>;
|
382
|
+
}
|
383
|
+
|
384
|
+
declare class TaskManager {
|
385
|
+
private readonly eventsWeHandled;
|
386
|
+
private readonly loader;
|
387
|
+
private queue;
|
388
|
+
private isProcessing;
|
389
|
+
readonly logger: Logger;
|
390
|
+
constructor(loader: Loader);
|
391
|
+
handleEvent(eventBlock: DbMetaEventBlock): Promise<void>;
|
392
|
+
private processQueue;
|
393
|
+
}
|
394
|
+
|
395
|
+
type CarClockHead = Link<DbMetaEventBlock, number, number, Version>[];
|
396
|
+
interface Connectable {
|
397
|
+
readonly blockstore: {
|
398
|
+
readonly loader?: Loader;
|
399
|
+
readonly ebOpts: BlockstoreOpts;
|
400
|
+
};
|
401
|
+
readonly name?: string;
|
402
|
+
}
|
403
|
+
declare abstract class ConnectionBase implements Connection {
|
404
|
+
readonly eventBlocks: MemoryBlockstore;
|
405
|
+
parents: CarClockHead;
|
406
|
+
loader?: Loadable;
|
407
|
+
taskManager?: TaskManager;
|
408
|
+
loaded: Promise<void>;
|
409
|
+
abstract metaUpload(bytes: Uint8Array, params: UploadMetaFnParams): Promise<Uint8Array[] | Falsy>;
|
410
|
+
abstract dataUpload(bytes: Uint8Array, params: UploadDataFnParams, opts?: {
|
411
|
+
public?: boolean;
|
412
|
+
}): Promise<void>;
|
413
|
+
abstract metaDownload(params: DownloadMetaFnParams): Promise<Uint8Array[] | Falsy>;
|
414
|
+
abstract dataDownload(params: DownloadDataFnParams): Promise<Uint8Array | Falsy>;
|
415
|
+
readonly logger: Logger;
|
416
|
+
constructor(logger: Logger);
|
417
|
+
refresh(): Promise<void>;
|
418
|
+
connect({ loader }: {
|
419
|
+
loader?: Loader;
|
420
|
+
}): void;
|
421
|
+
connectMeta({ loader }: {
|
422
|
+
loader?: Loader;
|
423
|
+
}): void;
|
424
|
+
onConnect(): Promise<void>;
|
425
|
+
connectStorage({ loader }: {
|
426
|
+
loader?: Loader;
|
427
|
+
}): void;
|
428
|
+
createEventBlock(bytes: Uint8Array): Promise<DbMetaEventBlock>;
|
429
|
+
decodeEventBlock(bytes: Uint8Array): Promise<DbMetaEventBlock>;
|
430
|
+
}
|
431
|
+
type DbMetaEventBlock = EventBlock<{
|
432
|
+
dbMeta: Uint8Array;
|
433
|
+
}>;
|
434
|
+
|
435
|
+
declare class ConnectREST extends ConnectionBase {
|
436
|
+
readonly baseUrl: URL;
|
437
|
+
constructor(base: string, logger: Logger);
|
438
|
+
dataUpload(bytes: Uint8Array, params: UploadDataFnParams): Promise<void>;
|
439
|
+
dataDownload(params: DownloadDataFnParams): Promise<Uint8Array | undefined>;
|
440
|
+
metaUpload(bytes: Uint8Array, params: UploadMetaFnParams): Promise<undefined>;
|
441
|
+
metaDownload(params: DownloadMetaFnParams): Promise<never[]>;
|
442
|
+
}
|
443
|
+
|
444
|
+
declare function toURL(pathOrUrl: string | URL, isIndex?: string): URL;
|
445
|
+
interface StoreFactoryItem {
|
446
|
+
readonly protocol: string;
|
447
|
+
readonly overrideBaseURL?: string;
|
448
|
+
readonly data: (logger: Logger) => Promise<Gateway>;
|
449
|
+
readonly meta: (logger: Logger) => Promise<Gateway>;
|
450
|
+
readonly wal: (logger: Logger) => Promise<Gateway>;
|
451
|
+
readonly test: (logger: Logger) => Promise<TestStore>;
|
452
|
+
}
|
453
|
+
declare function registerStoreProtocol(item: StoreFactoryItem): () => void;
|
454
|
+
declare function testStoreFactory(url: URL, ilogger?: Logger): Promise<TestStore>;
|
455
|
+
declare function toStoreRuntime(opts: StoreOpts, ilogger: Logger): StoreRuntime;
|
456
|
+
|
457
|
+
declare function parseCarFile<T>(reader: CarReader, logger: Logger): Promise<CarHeader<T>>;
|
458
|
+
|
459
|
+
type index$3_AnyAnyLink = AnyAnyLink;
|
460
|
+
type index$3_AnyBlock = AnyBlock;
|
461
|
+
type index$3_AnyLink = AnyLink;
|
462
|
+
type index$3_BaseBlockstore = BaseBlockstore;
|
463
|
+
declare const index$3_BaseBlockstore: typeof BaseBlockstore;
|
464
|
+
type index$3_BlobLike = BlobLike;
|
465
|
+
type index$3_BlockFetcher = BlockFetcher;
|
466
|
+
type index$3_CarClockHead = CarClockHead;
|
467
|
+
type index$3_CarGroup = CarGroup;
|
468
|
+
type index$3_CarTransaction = CarTransaction;
|
469
|
+
declare const index$3_CarTransaction: typeof CarTransaction;
|
470
|
+
type index$3_CommitOpts = CommitOpts;
|
471
|
+
type index$3_CompactionFetcher = CompactionFetcher;
|
472
|
+
declare const index$3_CompactionFetcher: typeof CompactionFetcher;
|
473
|
+
type index$3_ConnectREST = ConnectREST;
|
474
|
+
declare const index$3_ConnectREST: typeof ConnectREST;
|
475
|
+
type index$3_Connectable = Connectable;
|
476
|
+
type index$3_Connection = Connection;
|
477
|
+
type index$3_ConnectionBase = ConnectionBase;
|
478
|
+
declare const index$3_ConnectionBase: typeof ConnectionBase;
|
479
|
+
type index$3_CryptoOpts = CryptoOpts;
|
480
|
+
type index$3_DataSaveOpts = DataSaveOpts;
|
481
|
+
type index$3_DataStore = DataStore;
|
482
|
+
declare const index$3_DataStore: typeof DataStore;
|
483
|
+
type index$3_DbMeta = DbMeta;
|
484
|
+
type index$3_DbMetaEventBlock = DbMetaEventBlock;
|
485
|
+
type index$3_DownloadDataFnParams = DownloadDataFnParams;
|
486
|
+
type index$3_DownloadMetaFnParams = DownloadMetaFnParams;
|
487
|
+
type index$3_EncryptedBlockstore = EncryptedBlockstore;
|
488
|
+
declare const index$3_EncryptedBlockstore: typeof EncryptedBlockstore;
|
489
|
+
type index$3_Gateway = Gateway;
|
490
|
+
type index$3_GatewayOpts = GatewayOpts;
|
491
|
+
type index$3_GetResult = GetResult;
|
492
|
+
type index$3_Loadable = Loadable;
|
493
|
+
declare const index$3_Loadable: typeof Loadable;
|
494
|
+
type index$3_Loader = Loader;
|
495
|
+
declare const index$3_Loader: typeof Loader;
|
496
|
+
type index$3_MetaStore = MetaStore;
|
497
|
+
declare const index$3_MetaStore: typeof MetaStore;
|
498
|
+
type index$3_NotFoundError = NotFoundError;
|
499
|
+
declare const index$3_NotFoundError: typeof NotFoundError;
|
500
|
+
type index$3_RemoteWAL = RemoteWAL;
|
501
|
+
declare const index$3_RemoteWAL: typeof RemoteWAL;
|
502
|
+
type index$3_StoreFactory = StoreFactory;
|
503
|
+
type index$3_StoreFactoryItem = StoreFactoryItem;
|
504
|
+
type index$3_StoreOpts = StoreOpts;
|
505
|
+
type index$3_StoreRuntime = StoreRuntime;
|
506
|
+
type index$3_TestStore = TestStore;
|
507
|
+
type index$3_TransactionMeta = TransactionMeta;
|
508
|
+
type index$3_UploadDataFnParams = UploadDataFnParams;
|
509
|
+
type index$3_UploadMetaFnParams = UploadMetaFnParams;
|
510
|
+
type index$3_VoidResult = VoidResult;
|
511
|
+
type index$3_WALState = WALState;
|
512
|
+
declare const index$3_isNotFoundError: typeof isNotFoundError;
|
513
|
+
declare const index$3_parseCarFile: typeof parseCarFile;
|
514
|
+
declare const index$3_registerStoreProtocol: typeof registerStoreProtocol;
|
515
|
+
declare const index$3_testStoreFactory: typeof testStoreFactory;
|
516
|
+
declare const index$3_toStoreRuntime: typeof toStoreRuntime;
|
517
|
+
declare const index$3_toURL: typeof toURL;
|
518
|
+
declare namespace index$3 {
|
519
|
+
export { type index$3_AnyAnyLink as AnyAnyLink, type index$3_AnyBlock as AnyBlock, type index$3_AnyLink as AnyLink, index$3_BaseBlockstore as BaseBlockstore, type index$3_BlobLike as BlobLike, type index$3_BlockFetcher as BlockFetcher, type index$3_CarClockHead as CarClockHead, type index$3_CarGroup as CarGroup, index$3_CarTransaction as CarTransaction, type index$3_CommitOpts as CommitOpts, index$3_CompactionFetcher as CompactionFetcher, index$3_ConnectREST as ConnectREST, type index$3_Connectable as Connectable, type index$3_Connection as Connection, index$3_ConnectionBase as ConnectionBase, type index$3_CryptoOpts as CryptoOpts, type index$3_DataSaveOpts as DataSaveOpts, index$3_DataStore as DataStore, type index$3_DbMeta as DbMeta, type index$3_DbMetaEventBlock as DbMetaEventBlock, type index$3_DownloadDataFnParams as DownloadDataFnParams, type index$3_DownloadMetaFnParams as DownloadMetaFnParams, index$3_EncryptedBlockstore as EncryptedBlockstore, type index$3_Gateway as Gateway, type index$3_GatewayOpts as GatewayOpts, type index$3_GetResult as GetResult, index$3_Loadable as Loadable, index$3_Loader as Loader, index$3_MetaStore as MetaStore, index$3_NotFoundError as NotFoundError, index$3_RemoteWAL as RemoteWAL, type index$3_StoreFactory as StoreFactory, type index$3_StoreFactoryItem as StoreFactoryItem, type index$3_StoreOpts as StoreOpts, type index$3_StoreRuntime as StoreRuntime, type index$3_TestStore as TestStore, type index$3_TransactionMeta as TransactionMeta, type index$3_UploadDataFnParams as UploadDataFnParams, type index$3_UploadMetaFnParams as UploadMetaFnParams, type index$3_VoidResult as VoidResult, type index$3_WALState as WALState, index$3_isNotFoundError as isNotFoundError, index$3_parseCarFile as parseCarFile, index$3_registerStoreProtocol as registerStoreProtocol, index$3_testStoreFactory as testStoreFactory, index$3_toStoreRuntime as toStoreRuntime, index$3_toURL as toURL };
|
520
|
+
}
|
521
|
+
|
522
|
+
type Falsy = false | null | undefined;
|
523
|
+
declare function isFalsy(value: unknown): value is Falsy;
|
524
|
+
declare function throwFalsy<T>(value: T | Falsy): T;
|
525
|
+
declare function falsyToUndef<T>(value: T | Falsy): T | undefined;
|
526
|
+
interface ConfigOpts {
|
527
|
+
readonly public?: boolean;
|
528
|
+
readonly meta?: DbMeta;
|
529
|
+
readonly persistIndexes?: boolean;
|
530
|
+
readonly autoCompact?: number;
|
531
|
+
readonly crypto?: CryptoOpts;
|
532
|
+
readonly store?: StoreOpts;
|
533
|
+
readonly threshold?: number;
|
534
|
+
readonly logger?: Logger;
|
535
|
+
}
|
536
|
+
type ClockLink = EventLink<Operation>;
|
537
|
+
type ClockHead = ClockLink[];
|
538
|
+
type DocFragment = Uint8Array | string | number | boolean | null | AnyLink | DocFragment[] | object;
|
539
|
+
type DocLiteral = string | number | boolean | Uint8Array | unknown;
|
540
|
+
type DocObject = NonNullable<unknown>;
|
541
|
+
type DocTypes = DocObject;
|
542
|
+
type DocRecord<T extends DocObject> = T;
|
543
|
+
type UnknownDoc = DocRecord<never>;
|
544
|
+
type DocFiles = Record<string, DocFileMeta | File>;
|
545
|
+
interface DocBase {
|
546
|
+
readonly _id: string;
|
547
|
+
readonly _files?: DocFiles;
|
548
|
+
readonly _publicFiles?: DocFiles;
|
549
|
+
readonly _deleted?: boolean;
|
550
|
+
}
|
551
|
+
type DocWithId<T extends DocTypes> = DocBase & T;
|
552
|
+
type DocSet<T extends DocTypes> = Partial<DocBase> & T;
|
553
|
+
interface DocFileMeta {
|
554
|
+
readonly type: string;
|
555
|
+
readonly size: number;
|
556
|
+
readonly cid: AnyLink;
|
557
|
+
readonly car?: AnyLink;
|
558
|
+
url?: string;
|
559
|
+
file?: () => Promise<File>;
|
560
|
+
}
|
561
|
+
interface DocUpdate<T extends DocTypes> {
|
562
|
+
readonly id: string;
|
563
|
+
readonly value?: DocSet<T>;
|
564
|
+
readonly del?: boolean;
|
565
|
+
readonly clock?: ClockLink;
|
566
|
+
}
|
567
|
+
interface DocValue<T extends DocTypes> {
|
568
|
+
readonly doc: DocWithId<T>;
|
569
|
+
readonly del: boolean;
|
570
|
+
readonly cid: AnyLink;
|
571
|
+
}
|
572
|
+
type KeyLiteral = string | number | boolean;
|
573
|
+
type IndexKeyType = KeyLiteral | KeyLiteral[];
|
574
|
+
type IndexKey<K extends IndexKeyType> = [K, string];
|
575
|
+
interface IndexUpdate<K extends IndexKeyType> {
|
576
|
+
readonly key: IndexKey<K>;
|
577
|
+
readonly value?: DocFragment;
|
578
|
+
readonly del?: boolean;
|
579
|
+
}
|
580
|
+
interface IndexUpdateString {
|
581
|
+
readonly key: string;
|
582
|
+
readonly value?: DocFragment;
|
583
|
+
readonly del?: boolean;
|
584
|
+
}
|
585
|
+
interface IndexRow<K extends IndexKeyType, T extends DocObject, R extends DocFragment> {
|
586
|
+
readonly id: string;
|
587
|
+
readonly key: K;
|
588
|
+
readonly value: R;
|
589
|
+
readonly doc?: DocWithId<T>;
|
590
|
+
}
|
591
|
+
interface IndexRows<K extends IndexKeyType, T extends DocObject, R extends DocFragment = T> {
|
592
|
+
readonly rows: IndexRow<K, T, R>[];
|
593
|
+
}
|
594
|
+
interface CRDTMeta {
|
595
|
+
readonly head: ClockHead;
|
596
|
+
}
|
597
|
+
interface IndexTransactionMeta {
|
598
|
+
readonly indexes: Record<string, IdxMeta>;
|
599
|
+
}
|
600
|
+
interface FileTransactionMeta {
|
601
|
+
readonly files?: AnyLink[];
|
602
|
+
}
|
603
|
+
type MetaType$1 = CRDTMeta | IndexTransactionMeta | FileTransactionMeta;
|
604
|
+
interface IdxMeta {
|
605
|
+
readonly byId: AnyLink;
|
606
|
+
readonly byKey: AnyLink;
|
607
|
+
readonly map: string;
|
608
|
+
readonly name: string;
|
609
|
+
readonly head: ClockHead;
|
610
|
+
}
|
611
|
+
interface IdxMetaMap {
|
612
|
+
readonly indexes?: Map<string, IdxMeta>;
|
613
|
+
}
|
614
|
+
interface QueryOpts<K extends IndexKeyType> {
|
615
|
+
readonly descending?: boolean;
|
616
|
+
readonly limit?: number;
|
617
|
+
includeDocs?: boolean;
|
618
|
+
readonly range?: [IndexKeyType, IndexKeyType];
|
619
|
+
readonly key?: DocFragment;
|
620
|
+
readonly keys?: DocFragment[];
|
621
|
+
prefix?: IndexKeyType;
|
622
|
+
}
|
623
|
+
type EmitFn = (k: IndexKeyType, v?: DocFragment) => void;
|
624
|
+
type MapFn<T extends DocTypes> = (doc: DocWithId<T>, emit: EmitFn) => DocFragment | unknown;
|
625
|
+
interface ChangesOptions {
|
626
|
+
readonly dirty?: boolean;
|
627
|
+
readonly limit?: number;
|
628
|
+
}
|
629
|
+
interface ChangesResponseRow<T extends DocTypes> {
|
630
|
+
readonly key: string;
|
631
|
+
readonly value: DocWithId<T>;
|
632
|
+
readonly clock?: ClockLink;
|
633
|
+
}
|
634
|
+
interface ChangesResponse<T extends DocTypes> {
|
635
|
+
readonly clock: ClockHead;
|
636
|
+
readonly rows: ChangesResponseRow<T>[];
|
637
|
+
}
|
638
|
+
interface DbResponse {
|
639
|
+
readonly id: string;
|
640
|
+
readonly clock: ClockHead;
|
641
|
+
}
|
642
|
+
type UpdateListenerFn<T extends DocTypes> = (docs: DocWithId<T>[]) => Promise<void> | void;
|
643
|
+
type NoUpdateListenerFn = () => Promise<void> | void;
|
644
|
+
type ListenerFn<T extends DocTypes> = UpdateListenerFn<T> | NoUpdateListenerFn;
|
645
|
+
|
646
|
+
interface WriteQueue<T extends DocTypes> {
|
647
|
+
push(task: DocUpdate<T>): Promise<MetaType$1>;
|
648
|
+
}
|
649
|
+
|
650
|
+
declare class IndexTree<K extends IndexKeyType, R extends DocFragment> {
|
651
|
+
cid?: AnyLink;
|
652
|
+
root?: ProllyNode<K, R>;
|
653
|
+
}
|
654
|
+
interface ProllyIndexRow<K extends IndexKeyType, T extends DocFragment> {
|
655
|
+
readonly id: string;
|
656
|
+
readonly key: IndexKey<K>;
|
657
|
+
readonly value: T;
|
658
|
+
}
|
659
|
+
interface ProllyNode<K extends IndexKeyType, T extends DocFragment> extends ProllyNode$1 {
|
660
|
+
getAllEntries(): PromiseLike<{
|
661
|
+
[x: string]: unknown;
|
662
|
+
result: ProllyIndexRow<K, T>[];
|
663
|
+
}>;
|
664
|
+
getMany<KI extends IndexKeyType>(removeIds: KI[]): Promise<{
|
665
|
+
result: IndexKey<K>[];
|
666
|
+
}>;
|
667
|
+
range(a: string, b: string): Promise<{
|
668
|
+
result: ProllyIndexRow<K, T>[];
|
669
|
+
}>;
|
670
|
+
get(key: string): Promise<{
|
671
|
+
result: ProllyIndexRow<K, T>[];
|
672
|
+
}>;
|
673
|
+
bulk(bulk: (IndexUpdate<K> | IndexUpdateString)[]): PromiseLike<{
|
674
|
+
readonly root?: ProllyNode<K, T>;
|
675
|
+
readonly blocks: Block[];
|
676
|
+
}>;
|
677
|
+
readonly address: Promise<Link>;
|
678
|
+
readonly distance: number;
|
679
|
+
compare: (a: unknown, b: unknown) => number;
|
680
|
+
readonly cache: unknown;
|
681
|
+
readonly block: Promise<Block>;
|
682
|
+
}
|
683
|
+
|
684
|
+
declare function index$2<K extends IndexKeyType = string, T extends DocTypes = NonNullable<unknown>, R extends DocFragment = T>({ _crdt }: {
|
685
|
+
_crdt: CRDT<T> | CRDT<NonNullable<unknown>>;
|
686
|
+
}, name: string, mapFn?: MapFn<T>, meta?: IdxMeta): Index<K, T, R>;
|
687
|
+
declare class Index<K extends IndexKeyType, T extends DocTypes, R extends DocFragment = T> {
|
688
|
+
readonly blockstore: BaseBlockstore;
|
689
|
+
readonly crdt: CRDT<T>;
|
690
|
+
name: string;
|
691
|
+
mapFn?: MapFn<T>;
|
692
|
+
mapFnString: string;
|
693
|
+
byKey: IndexTree<K, R>;
|
694
|
+
byId: IndexTree<K, R>;
|
695
|
+
indexHead?: ClockHead;
|
696
|
+
includeDocsDefault: boolean;
|
697
|
+
initError?: Error;
|
698
|
+
ready(): Promise<void>;
|
699
|
+
close(): Promise<void>;
|
700
|
+
destroy(): Promise<void>;
|
701
|
+
readonly logger: Logger;
|
702
|
+
constructor(crdt: CRDT<T> | CRDT<NonNullable<unknown>>, name: string, mapFn?: MapFn<T>, meta?: IdxMeta);
|
703
|
+
applyMapFn(name: string, mapFn?: MapFn<T>, meta?: IdxMeta): void;
|
704
|
+
query(opts?: QueryOpts<K>): Promise<IndexRows<K, T, R>>;
|
705
|
+
_resetIndex(): void;
|
706
|
+
_hydrateIndex(): Promise<void>;
|
707
|
+
_updateIndex(): Promise<IndexTransactionMeta>;
|
708
|
+
}
|
709
|
+
|
710
|
+
interface ApplyHeadTask<T extends DocTypes> {
|
711
|
+
readonly newHead: ClockHead;
|
712
|
+
readonly prevHead: ClockHead;
|
713
|
+
readonly updates?: DocUpdate<T>[];
|
714
|
+
}
|
715
|
+
interface ApplyHeadQueue<T extends DocTypes> {
|
716
|
+
push(task: ApplyHeadTask<T>): AsyncGenerator<{
|
717
|
+
readonly updates: DocUpdate<T>[];
|
718
|
+
readonly all: boolean;
|
719
|
+
}, void, unknown>;
|
720
|
+
size(): number;
|
721
|
+
}
|
722
|
+
|
723
|
+
declare class CRDTClock<T extends DocTypes> {
|
724
|
+
head: ClockHead;
|
725
|
+
readonly zoomers: Set<() => void>;
|
726
|
+
readonly watchers: Set<(updates: DocUpdate<T>[]) => void>;
|
727
|
+
readonly emptyWatchers: Set<() => void>;
|
728
|
+
readonly blockstore: BaseBlockstore;
|
729
|
+
readonly applyHeadQueue: ApplyHeadQueue<T>;
|
730
|
+
readonly _ready: ResolveOnce<void, void>;
|
731
|
+
ready(): Promise<void>;
|
732
|
+
close(): Promise<void>;
|
733
|
+
readonly logger: Logger;
|
734
|
+
constructor(blockstore: BaseBlockstore);
|
735
|
+
setHead(head: ClockHead): void;
|
736
|
+
applyHead(newHead: ClockHead, prevHead: ClockHead, updates?: DocUpdate<T>[]): Promise<void>;
|
737
|
+
processUpdates(updatesAcc: DocUpdate<T>[], all: boolean, prevHead: ClockHead): Promise<void>;
|
738
|
+
notifyWatchers(updates: DocUpdate<T>[]): void;
|
739
|
+
onTick(fn: (updates: DocUpdate<T>[]) => void): void;
|
740
|
+
onTock(fn: () => void): void;
|
741
|
+
onZoom(fn: () => void): void;
|
742
|
+
int_applyHead(newHead: ClockHead, prevHead: ClockHead, localUpdates: boolean): Promise<void>;
|
743
|
+
}
|
744
|
+
|
745
|
+
declare class CRDT<T extends DocTypes> {
|
746
|
+
readonly name?: string;
|
747
|
+
readonly opts: ConfigOpts;
|
748
|
+
readonly onceReady: ResolveOnce<void, void>;
|
749
|
+
ready(): Promise<void>;
|
750
|
+
close(): Promise<void>;
|
751
|
+
destroy(): Promise<void>;
|
752
|
+
readonly blockstore: BaseBlockstore;
|
753
|
+
readonly indexBlockstore: BaseBlockstore;
|
754
|
+
readonly indexers: Map<string, Index<IndexKeyType, {}, {}>>;
|
755
|
+
readonly clock: CRDTClock<T>;
|
756
|
+
readonly logger: Logger;
|
757
|
+
constructor(name?: string, opts?: ConfigOpts);
|
758
|
+
bulk(updates: DocUpdate<T>[]): Promise<CRDTMeta>;
|
759
|
+
allDocs(): Promise<{
|
760
|
+
result: DocUpdate<T>[];
|
761
|
+
head: ClockHead;
|
762
|
+
}>;
|
763
|
+
vis(): Promise<string>;
|
764
|
+
getBlock(cidString: string): Promise<Block>;
|
765
|
+
get(key: string): Promise<DocValue<T> | Falsy>;
|
766
|
+
changes(since?: ClockHead, opts?: ChangesOptions): Promise<{
|
767
|
+
result: DocUpdate<T>[];
|
768
|
+
head: ClockHead;
|
769
|
+
}>;
|
770
|
+
compact(): Promise<void>;
|
771
|
+
}
|
772
|
+
|
773
|
+
declare class Database<DT extends DocTypes = NonNullable<unknown>> implements Connectable {
|
774
|
+
static databases: Map<string, Database<{}>>;
|
775
|
+
readonly name?: string;
|
776
|
+
readonly opts: ConfigOpts;
|
777
|
+
_listening: boolean;
|
778
|
+
readonly _listeners: Set<ListenerFn<DT>>;
|
779
|
+
readonly _noupdate_listeners: Set<ListenerFn<DT>>;
|
780
|
+
readonly _crdt: CRDT<DT>;
|
781
|
+
readonly _writeQueue: WriteQueue<DT>;
|
782
|
+
readonly blockstore: BaseBlockstore;
|
783
|
+
close(): Promise<void>;
|
784
|
+
destroy(): Promise<void>;
|
785
|
+
readonly _ready: ResolveOnce<void, void>;
|
786
|
+
ready(): Promise<void>;
|
787
|
+
readonly logger: Logger;
|
788
|
+
constructor(name?: string, opts?: ConfigOpts);
|
789
|
+
get<T extends DocTypes>(id: string): Promise<DocWithId<T>>;
|
790
|
+
put<T extends DocTypes>(doc: DocSet<T>): Promise<DbResponse>;
|
791
|
+
del(id: string): Promise<DbResponse>;
|
792
|
+
changes<T extends DocTypes>(since?: ClockHead, opts?: ChangesOptions): Promise<ChangesResponse<T>>;
|
793
|
+
allDocs<T extends DocTypes>(): Promise<{
|
794
|
+
rows: {
|
795
|
+
key: string;
|
796
|
+
value: DocWithId<T>;
|
797
|
+
}[];
|
798
|
+
clock: ClockHead;
|
799
|
+
}>;
|
800
|
+
allDocuments<T extends DocTypes>(): Promise<{
|
801
|
+
rows: {
|
802
|
+
key: string;
|
803
|
+
value: DocWithId<T>;
|
804
|
+
}[];
|
805
|
+
clock: ClockHead;
|
806
|
+
}>;
|
807
|
+
subscribe<T extends DocTypes>(listener: ListenerFn<T>, updates?: boolean): () => void;
|
808
|
+
query<K extends IndexKeyType, T extends DocTypes, R extends DocFragment = T>(field: string | MapFn<T>, opts?: QueryOpts<K>): Promise<IndexRows<K, T, R>>;
|
809
|
+
compact(): Promise<void>;
|
810
|
+
_notify(updates: DocUpdate<NonNullable<unknown>>[]): Promise<void>;
|
811
|
+
_no_update_notify(): Promise<void>;
|
812
|
+
}
|
813
|
+
declare function fireproof(name: string, opts?: ConfigOpts): Database;
|
814
|
+
|
815
|
+
interface NodeMap {
|
816
|
+
state: "seeded" | "browser" | "node";
|
817
|
+
join: (...args: string[]) => string;
|
818
|
+
dirname: (path: string) => string;
|
819
|
+
homedir: () => string;
|
820
|
+
fileURLToPath: (url: string | URL) => string;
|
821
|
+
mkdir: (path: PathLike, options?: {
|
822
|
+
recursive: boolean;
|
823
|
+
}) => Promise<string | undefined>;
|
824
|
+
readdir: (path: PathLike, options?: unknown) => Promise<unknown[]>;
|
825
|
+
rm: (path: PathLike, options?: MakeDirectoryOptions & {
|
826
|
+
recursive: boolean;
|
827
|
+
}) => Promise<void>;
|
828
|
+
copyFile: (source: PathLike, destination: PathLike) => Promise<void>;
|
829
|
+
readfile: (path: PathLike, options?: {
|
830
|
+
encoding: BufferEncoding;
|
831
|
+
flag?: string;
|
832
|
+
}) => Promise<string>;
|
833
|
+
stat: (path: PathLike) => Promise<Stats>;
|
834
|
+
unlink: (path: PathLike) => Promise<void>;
|
835
|
+
writefile: (path: PathLike, data: Uint8Array | string) => Promise<void>;
|
836
|
+
}
|
837
|
+
declare function join(...paths: string[]): string;
|
838
|
+
declare class sysContainer {
|
839
|
+
freight: NodeMap;
|
840
|
+
readonly id: string;
|
841
|
+
start(): Promise<void>;
|
842
|
+
readdir(path: PathLike, options?: (ObjectEncodingOptions & {
|
843
|
+
withFileTypes?: false | undefined;
|
844
|
+
recursive?: boolean;
|
845
|
+
}) | BufferEncoding | null | undefined): Promise<string[]>;
|
846
|
+
readdirent(path: PathLike, options: (ObjectEncodingOptions & {
|
847
|
+
withFileTypes: true;
|
848
|
+
recursive?: boolean;
|
849
|
+
}) | BufferEncoding | null | undefined): Promise<Dirent[]>;
|
850
|
+
readfile(path: PathLike, options?: {
|
851
|
+
encoding: BufferEncoding;
|
852
|
+
flag?: string;
|
853
|
+
}): Promise<Buffer>;
|
854
|
+
mkdir(path: PathLike, options: {
|
855
|
+
recursive: boolean;
|
856
|
+
}): Promise<string | undefined>;
|
857
|
+
rm(path: PathLike, options: MakeDirectoryOptions & {
|
858
|
+
recursive: boolean;
|
859
|
+
}): Promise<void>;
|
860
|
+
unlink(path: PathLike): Promise<void>;
|
861
|
+
writefile(path: PathLike, data: Uint8Array | string): Promise<void>;
|
862
|
+
copyFile(source: PathLike, destination: PathLike): Promise<void>;
|
863
|
+
stat(path: PathLike): Promise<Stats>;
|
864
|
+
fileURLToPath(url: string | URL): string;
|
865
|
+
dirname(path: string): string;
|
866
|
+
join(...args: string[]): string;
|
867
|
+
homedir: () => string;
|
868
|
+
logSeeded(method: string): void;
|
869
|
+
readonly env: EnvImpl;
|
870
|
+
}
|
871
|
+
declare const SysContainer: sysContainer;
|
872
|
+
|
873
|
+
declare function dataDir(name?: string, base?: string | URL): string;
|
874
|
+
|
875
|
+
interface LoggerOpts {
|
876
|
+
readonly logger?: Logger;
|
877
|
+
}
|
878
|
+
declare function ensureLogger(optsOrLogger: Partial<LoggerOpts> | Logger, componentName: string, ctx?: Record<string, unknown>): Logger;
|
879
|
+
type Joiner = (...toJoin: string[]) => string;
|
880
|
+
declare function getStore(url: URL, logger: Logger, joiner: Joiner): string;
|
881
|
+
declare function getKey(url: URL, logger: Logger): string;
|
882
|
+
declare function getName(url: URL, logger: Logger): string;
|
883
|
+
declare function exception2Result<T = void>(fn: () => Promise<T>): Promise<Result<T>>;
|
884
|
+
declare function exceptionWrapper<T, E extends Error>(fn: () => Promise<Result<T, E>>): Promise<Result<T, E>>;
|
885
|
+
|
886
|
+
declare function getPath(url: URL, logger: Logger): Promise<string>;
|
887
|
+
declare function getFileName(url: URL, key: string, logger: Logger): string;
|
888
|
+
declare function ensureIndexName(url: URL, name: string): string;
|
889
|
+
|
890
|
+
interface DBConnection {
|
891
|
+
connect(): Promise<void>;
|
892
|
+
readonly opts: SQLOpts;
|
893
|
+
}
|
894
|
+
interface SQLStore<IType, KType, OType = IType[]> {
|
895
|
+
readonly dbConn: DBConnection;
|
896
|
+
start(url: URL): Promise<void>;
|
897
|
+
insert(url: URL, ose: IType): Promise<RunResult>;
|
898
|
+
select(url: URL, car: KType): Promise<OType>;
|
899
|
+
delete(url: URL, car: KType): Promise<RunResult>;
|
900
|
+
close(url: URL): Promise<Result<void>>;
|
901
|
+
destroy(url: URL): Promise<Result<void>>;
|
902
|
+
}
|
903
|
+
interface SQLTableNames {
|
904
|
+
readonly data: string;
|
905
|
+
readonly meta: string;
|
906
|
+
readonly wal: string;
|
907
|
+
}
|
908
|
+
declare const DefaultSQLTableNames: SQLTableNames;
|
909
|
+
interface SQLOpts {
|
910
|
+
readonly url: URL;
|
911
|
+
readonly sqlFlavor: "sqlite" | "mysql" | "postgres";
|
912
|
+
readonly tableNames: SQLTableNames;
|
913
|
+
readonly logger: Logger;
|
914
|
+
readonly textEncoder: TextEncoder;
|
915
|
+
readonly textDecoder: TextDecoder;
|
916
|
+
}
|
917
|
+
interface WalKey {
|
918
|
+
readonly name: string;
|
919
|
+
readonly branch: string;
|
920
|
+
}
|
921
|
+
interface WalRecord extends WalKey {
|
922
|
+
readonly state: Uint8Array;
|
923
|
+
readonly updated_at: Date;
|
924
|
+
}
|
925
|
+
type WalSQLStore = SQLStore<WalRecord, WalKey>;
|
926
|
+
interface MetaType {
|
927
|
+
readonly name: string;
|
928
|
+
readonly branch: string;
|
929
|
+
readonly meta: Uint8Array;
|
930
|
+
}
|
931
|
+
interface MetaRecordKey {
|
932
|
+
readonly name: string;
|
933
|
+
readonly branch: string;
|
934
|
+
}
|
935
|
+
interface MetaRecord extends MetaRecordKey {
|
936
|
+
readonly meta: Uint8Array;
|
937
|
+
readonly updated_at: Date;
|
938
|
+
}
|
939
|
+
type MetaSQLStore = SQLStore<MetaRecord, MetaRecordKey>;
|
940
|
+
interface DataRecord {
|
941
|
+
readonly name: string;
|
942
|
+
readonly car: string;
|
943
|
+
readonly data: Uint8Array;
|
944
|
+
readonly updated_at: Date;
|
945
|
+
}
|
946
|
+
type DataSQLStore = SQLStore<DataRecord, string>;
|
947
|
+
|
948
|
+
declare function ensureSQLOpts(url: URL, opts: Partial<SQLOpts>, componentName: string, ctx?: Record<string, unknown>): SQLOpts;
|
949
|
+
|
950
|
+
type index$1_DBConnection = DBConnection;
|
951
|
+
type index$1_DataRecord = DataRecord;
|
952
|
+
type index$1_DataSQLStore = DataSQLStore;
|
953
|
+
declare const index$1_DefaultSQLTableNames: typeof DefaultSQLTableNames;
|
954
|
+
type index$1_MetaRecord = MetaRecord;
|
955
|
+
type index$1_MetaRecordKey = MetaRecordKey;
|
956
|
+
type index$1_MetaSQLStore = MetaSQLStore;
|
957
|
+
type index$1_MetaType = MetaType;
|
958
|
+
type index$1_SQLOpts = SQLOpts;
|
959
|
+
type index$1_SQLStore<IType, KType, OType = IType[]> = SQLStore<IType, KType, OType>;
|
960
|
+
type index$1_SQLTableNames = SQLTableNames;
|
961
|
+
type index$1_WalKey = WalKey;
|
962
|
+
type index$1_WalRecord = WalRecord;
|
963
|
+
type index$1_WalSQLStore = WalSQLStore;
|
964
|
+
declare const index$1_ensureSQLOpts: typeof ensureSQLOpts;
|
965
|
+
declare namespace index$1 {
|
966
|
+
export { type index$1_DBConnection as DBConnection, type index$1_DataRecord as DataRecord, type index$1_DataSQLStore as DataSQLStore, index$1_DefaultSQLTableNames as DefaultSQLTableNames, type index$1_MetaRecord as MetaRecord, type index$1_MetaRecordKey as MetaRecordKey, type index$1_MetaSQLStore as MetaSQLStore, type index$1_MetaType as MetaType, type index$1_SQLOpts as SQLOpts, type index$1_SQLStore as SQLStore, type index$1_SQLTableNames as SQLTableNames, type index$1_WalKey as WalKey, type index$1_WalRecord as WalRecord, type index$1_WalSQLStore as WalSQLStore, index$1_ensureSQLOpts as ensureSQLOpts };
|
967
|
+
}
|
968
|
+
|
969
|
+
declare function toCryptoOpts(cryptoOpts?: Partial<CryptoOpts>): CryptoOpts;
|
970
|
+
|
971
|
+
declare const crypto$1_toCryptoOpts: typeof toCryptoOpts;
|
972
|
+
declare namespace crypto$1 {
|
973
|
+
export { crypto$1_toCryptoOpts as toCryptoOpts };
|
974
|
+
}
|
975
|
+
|
976
|
+
declare function encodeFile(blob: BlobLike): Promise<{
|
977
|
+
cid: AnyLink;
|
978
|
+
blocks: AnyBlock[];
|
979
|
+
}>;
|
980
|
+
declare function decodeFile(blocks: unknown, cid: AnyLink, meta: DocFileMeta): Promise<File>;
|
981
|
+
|
982
|
+
declare const files_decodeFile: typeof decodeFile;
|
983
|
+
declare const files_encodeFile: typeof encodeFile;
|
984
|
+
declare namespace files {
|
985
|
+
export { files_decodeFile as decodeFile, files_encodeFile as encodeFile };
|
986
|
+
}
|
987
|
+
|
988
|
+
declare const FILESTORE_VERSION = "v0.19-file";
|
989
|
+
|
990
|
+
declare const INDEXDB_VERSION = "v0.19-indexdb";
|
991
|
+
|
992
|
+
declare const SQLITE_VERSION = "v0.19-sqlite";
|
993
|
+
|
994
|
+
declare const index_FILESTORE_VERSION: typeof FILESTORE_VERSION;
|
995
|
+
declare const index_INDEXDB_VERSION: typeof INDEXDB_VERSION;
|
996
|
+
type index_NodeMap = NodeMap;
|
997
|
+
declare const index_SQLITE_VERSION: typeof SQLITE_VERSION;
|
998
|
+
declare const index_SysContainer: typeof SysContainer;
|
999
|
+
declare const index_dataDir: typeof dataDir;
|
1000
|
+
declare const index_ensureIndexName: typeof ensureIndexName;
|
1001
|
+
declare const index_files: typeof files;
|
1002
|
+
declare const index_getFileName: typeof getFileName;
|
1003
|
+
declare const index_getPath: typeof getPath;
|
1004
|
+
declare const index_join: typeof join;
|
1005
|
+
declare namespace index {
|
1006
|
+
export { index_FILESTORE_VERSION as FILESTORE_VERSION, index_INDEXDB_VERSION as INDEXDB_VERSION, type index_NodeMap as NodeMap, index_SQLITE_VERSION as SQLITE_VERSION, index_SysContainer as SysContainer, crypto$1 as crypto, index_dataDir as dataDir, index_ensureIndexName as ensureIndexName, index_files as files, index_getFileName as getFileName, index_getPath as getPath, index_join as join, index$1 as sql };
|
1007
|
+
}
|
1008
|
+
|
1009
|
+
declare const PACKAGE_VERSION: string;
|
1010
|
+
|
1011
|
+
export { CRDT, type CRDTMeta, type ChangesOptions, type ChangesResponse, type ChangesResponseRow, type ClockHead, type ClockLink, type ConfigOpts, Database, type DbResponse, type DocBase, type DocFileMeta, type DocFiles, type DocFragment, type DocLiteral, type DocObject, type DocRecord, type DocSet, type DocTypes, type DocUpdate, type DocValue, type DocWithId, type Falsy, type FileTransactionMeta, type IdxMeta, type IdxMetaMap, Index, type IndexKey, type IndexKeyType, type IndexRow, type IndexRows, type IndexTransactionMeta, type IndexUpdate, type IndexUpdateString, type Joiner, type KeyLiteral, type ListenerFn, type LoggerOpts, type MapFn, type MetaType$1 as MetaType, type NoUpdateListenerFn, PACKAGE_VERSION, type QueryOpts, type UnknownDoc, type UpdateListenerFn, index$3 as blockstore, index$3 as bs, ensureLogger, exception2Result, exceptionWrapper, falsyToUndef, fireproof, getKey, getName, getStore, index$2 as index, isFalsy, index as rt, index as runtime, throwFalsy };
|
1012
|
+
declare module '@fireproof/core'
|