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