@fireproof/core 0.19.110 → 0.19.112-dev-web

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. package/{chunk-OFGPKRCM.js → chunk-GZANCVTS.js} +3 -1
  2. package/chunk-GZANCVTS.js.map +1 -0
  3. package/{chunk-WS3YRPIA.js → chunk-LNFBDD6E.js} +4 -4
  4. package/chunk-LNFBDD6E.js.map +1 -0
  5. package/deno.json +1 -2
  6. package/{gateway-H7UD6TNB.js → gateway@skip-esm-O655UEIP.js} +3 -3
  7. package/gateway@skip-esm-O655UEIP.js.map +1 -0
  8. package/{gateway-5FCWPX5W.js → gateway@skip-iife-OZ2V32XH.js} +5 -5
  9. package/gateway@skip-iife-OZ2V32XH.js.map +1 -0
  10. package/index.cjs +32 -30
  11. package/index.cjs.map +1 -1
  12. package/index.global.js +417 -178
  13. package/index.global.js.map +1 -1
  14. package/index.js +11 -11
  15. package/index.js.map +1 -1
  16. package/{key-bag-file-WADZBHYG.js → key-bag-file-4TYN2H7F.js} +3 -3
  17. package/{key-bag-indexdb-PGVAI3FJ.js → key-bag-indexdb-JEOAS4WM.js} +3 -3
  18. package/{mem-filesystem-YPPJV7Q2.js → mem-filesystem@skip-iife-CJI7IIKV.js} +4 -4
  19. package/mem-filesystem@skip-iife-CJI7IIKV.js.map +1 -0
  20. package/metafile-cjs.json +1 -1
  21. package/metafile-esm.json +1 -1
  22. package/metafile-iife.json +1 -1
  23. package/{node-filesystem-INX4ZTHE.js → node-filesystem@skip-iife-O74VAABQ.js} +4 -4
  24. package/node-filesystem@skip-iife-O74VAABQ.js.map +1 -0
  25. package/package.json +15 -6
  26. package/tests/blockstore/keyed-crypto.test.ts +2 -2
  27. package/tests/blockstore/store.test.ts +3 -5
  28. package/tests/fireproof/all-gateway.test.ts +11 -9
  29. package/{utils-QO2HIWGI.js → utils-L7MUZUJX.js} +3 -3
  30. package/web/bundle-not-impl-UH74NK5L.js +5 -0
  31. package/web/bundle-not-impl-UH74NK5L.js.map +1 -0
  32. package/web/chunk-2DC5ZIR4.js +7 -0
  33. package/web/chunk-2DC5ZIR4.js.map +1 -0
  34. package/web/chunk-Q5W7UNMP.js +292 -0
  35. package/web/chunk-Q5W7UNMP.js.map +1 -0
  36. package/web/chunk-S4HRSKEO.js +75 -0
  37. package/web/chunk-S4HRSKEO.js.map +1 -0
  38. package/web/gateway@skip-esm-GI5PRACF.js +165 -0
  39. package/web/gateway@skip-esm-GI5PRACF.js.map +1 -0
  40. package/web/index.cjs +4138 -0
  41. package/web/index.cjs.map +1 -0
  42. package/web/index.d.cts +1139 -0
  43. package/web/index.d.ts +1139 -0
  44. package/web/index.js +3478 -0
  45. package/web/index.js.map +1 -0
  46. package/web/key-bag-file-4SJQGORQ.js +54 -0
  47. package/web/key-bag-file-4SJQGORQ.js.map +1 -0
  48. package/web/key-bag-indexdb-GSQOUUVQ.js +50 -0
  49. package/web/key-bag-indexdb-GSQOUUVQ.js.map +1 -0
  50. package/web/metafile-cjs.json +1 -0
  51. package/web/metafile-esm.json +1 -0
  52. package/web/utils-EFZJNXH5.js +14 -0
  53. package/web/utils-EFZJNXH5.js.map +1 -0
  54. package/chunk-OFGPKRCM.js.map +0 -1
  55. package/chunk-WS3YRPIA.js.map +0 -1
  56. package/gateway-5FCWPX5W.js.map +0 -1
  57. package/gateway-H7UD6TNB.js.map +0 -1
  58. package/mem-filesystem-YPPJV7Q2.js.map +0 -1
  59. package/node-filesystem-INX4ZTHE.js.map +0 -1
  60. /package/{key-bag-file-WADZBHYG.js.map → key-bag-file-4TYN2H7F.js.map} +0 -0
  61. /package/{key-bag-indexdb-PGVAI3FJ.js.map → key-bag-indexdb-JEOAS4WM.js.map} +0 -0
  62. /package/{utils-QO2HIWGI.js.map → utils-L7MUZUJX.js.map} +0 -0
package/web/index.d.ts ADDED
@@ -0,0 +1,1139 @@
1
+ import { Future, Logger, URI, Result, CoerceURI, ResolveOnce, ResolveSeq, CryptoRuntime, CTCryptoKey, EnvFactoryOpts, Env, runtimeFn } from '@adviser/cement';
2
+ export { Logger, Result } from '@adviser/cement';
3
+ import { EventLink } from '@web3-storage/pail/clock/api';
4
+ import { Operation } from '@web3-storage/pail/crdt/api';
5
+ import { ByteView, ArrayBufferView, Version, Block as Block$1, Link, CID, BlockView, MultihashHasher } from 'multiformats';
6
+ import { MemoryBlockstore } from '@web3-storage/pail/block';
7
+ import { BlockFetcher as BlockFetcher$1 } from '@web3-storage/pail/api';
8
+ import { CarReader } from '@ipld/car';
9
+ import { IDBPDatabase } from 'idb';
10
+ import { EventBlock } from '@web3-storage/pail/clock';
11
+ import { PathLike, MakeDirectoryOptions, Stats } from 'fs';
12
+ import { ProllyNode as ProllyNode$1 } from 'prolly-trees/db-index';
13
+ import { Block as Block$2 } from 'multiformats/block';
14
+
15
+ interface BlockEncoder<Code extends number, T> {
16
+ name: string;
17
+ code: Code;
18
+ encode(data: T): ByteView<T> | PromiseLike<ByteView<T>>;
19
+ }
20
+ interface BlockDecoder<Code extends number, T> {
21
+ code: Code;
22
+ decode(bytes: ByteView<T> | ArrayBufferView<T>): T | PromiseLike<T>;
23
+ }
24
+ interface BlockCodec<Code extends number, T> extends BlockEncoder<Code, T>, BlockDecoder<Code, T> {
25
+ }
26
+
27
+ declare const codecInterface_ArrayBufferView: typeof ArrayBufferView;
28
+ type codecInterface_BlockCodec<Code extends number, T> = BlockCodec<Code, T>;
29
+ type codecInterface_BlockDecoder<Code extends number, T> = BlockDecoder<Code, T>;
30
+ type codecInterface_BlockEncoder<Code extends number, T> = BlockEncoder<Code, T>;
31
+ declare const codecInterface_ByteView: typeof ByteView;
32
+ declare namespace codecInterface {
33
+ export { codecInterface_ArrayBufferView as ArrayBufferView, type codecInterface_BlockCodec as BlockCodec, type codecInterface_BlockDecoder as BlockDecoder, type codecInterface_BlockEncoder as BlockEncoder, codecInterface_ByteView as ByteView };
34
+ }
35
+
36
+ type QueueFunction<T = void> = () => Promise<T>;
37
+ declare class CommitQueue<T = void> {
38
+ readonly queue: QueueFunction<void>[];
39
+ processing: boolean;
40
+ readonly _waitIdleItems: Set<Future<void>>;
41
+ waitIdle(): Promise<void>;
42
+ enqueue(fn: QueueFunction<T>): Promise<T>;
43
+ processNext(): void;
44
+ }
45
+
46
+ declare function ensureSuperThis(osthis?: Partial<SuperThisOpts>): SuperThis;
47
+ declare function ensureSuperLog(sthis: SuperThis, componentName: string, ctx?: Record<string, unknown>): SuperThis;
48
+ declare function ensureLogger(sthis: SuperThis, componentName: string, ctx?: Record<string, unknown>): Logger;
49
+ type Joiner = (...toJoin: string[]) => string;
50
+ interface Store {
51
+ readonly store: StoreType;
52
+ readonly name: string;
53
+ }
54
+ declare function getStore(url: URI, sthis: SuperThis, joiner: Joiner): Store;
55
+ declare function getKey(url: URI, logger: Logger): string;
56
+ declare function getName(sthis: SuperThis, url: URI): string;
57
+ declare function exceptionWrapper<T, E extends Error>(fn: () => Promise<Result<T, E>>): Promise<Result<T, E>>;
58
+ declare class NotFoundError extends Error {
59
+ readonly code = "ENOENT";
60
+ }
61
+ declare function isNotFoundError(e: Error | Result<unknown> | unknown): e is NotFoundError;
62
+ declare function dataDir(sthis: SuperThis, name?: string, base?: CoerceURI): URI;
63
+ declare function UInt8ArrayEqual(a: Uint8Array, b: Uint8Array): boolean;
64
+
65
+ interface KeyBagCtx {
66
+ readonly dirName: string;
67
+ readonly sysFS: SysFileSystem;
68
+ readonly fName: string;
69
+ }
70
+ declare class KeyBagProviderFile implements KeyBagProvider {
71
+ _prepare(id: string): Promise<KeyBagCtx>;
72
+ private readonly url;
73
+ readonly logger: Logger;
74
+ readonly sthis: SuperThis;
75
+ constructor(url: URI, sthis: SuperThis);
76
+ get(id: string): Promise<KeyItem | undefined>;
77
+ set(id: string, item: KeyItem): Promise<void>;
78
+ }
79
+
80
+ declare class KeyBagProviderIndexDB implements KeyBagProvider {
81
+ readonly _db: ResolveOnce<IDBPDatabase<unknown>>;
82
+ readonly dbName: string;
83
+ readonly url: URI;
84
+ readonly logger: Logger;
85
+ readonly sthis: SuperThis;
86
+ constructor(url: URI, sthis: SuperThis);
87
+ _prepare(): Promise<IDBPDatabase<unknown>>;
88
+ get(id: string): Promise<KeyItem | undefined>;
89
+ set(id: string, item: KeyItem): Promise<void>;
90
+ }
91
+
92
+ declare class KeyBag {
93
+ readonly rt: KeyBagRuntime;
94
+ readonly logger: Logger;
95
+ constructor(rt: KeyBagRuntime);
96
+ readonly _warnOnce: ResolveOnce<void>;
97
+ subtleKey(key: string): Promise<CryptoKey>;
98
+ ensureKeyFromUrl(url: URI, keyFactory: () => string): Promise<Result<URI>>;
99
+ toKeyWithFingerPrint(keyStr: string): Promise<Result<KeyWithFingerPrint>>;
100
+ readonly _seq: ResolveSeq<Result<KeyWithFingerPrint>>;
101
+ setNamedKey(name: string, key: string): Promise<Result<KeyWithFingerPrint>>;
102
+ _setNamedKey(name: string, key: string): Promise<Result<KeyWithFingerPrint>>;
103
+ getNamedExtractableKey(name: string, failIfNotFound?: boolean): Promise<Result<KeyWithFingerExtract>>;
104
+ getNamedKey(name: string, failIfNotFound?: boolean): Promise<Result<KeyWithFingerPrint>>;
105
+ }
106
+ interface KeyItem {
107
+ readonly name: string;
108
+ readonly key: string;
109
+ }
110
+ type KeyBagFile = Record<string, KeyItem>;
111
+ interface KeyBagOpts {
112
+ readonly url: CoerceURI;
113
+ readonly crypto: CryptoRuntime;
114
+ readonly keyLength: number;
115
+ readonly keyRuntime: KeyBagRuntime;
116
+ }
117
+ interface KeyBagProvider {
118
+ get(id: string): Promise<KeyItem | undefined>;
119
+ set(id: string, item: KeyItem): Promise<void>;
120
+ }
121
+ interface KeyBagRuntime {
122
+ readonly url: URI;
123
+ readonly crypto: CryptoRuntime;
124
+ readonly logger: Logger;
125
+ readonly sthis: SuperThis;
126
+ readonly keyLength: number;
127
+ getBag(): Promise<KeyBagProvider>;
128
+ id(): string;
129
+ }
130
+ type KeyBackProviderFactory = (url: URI, sthis: SuperThis) => Promise<KeyBagProvider>;
131
+ interface KeyBagProviderFactoryItem {
132
+ readonly protocol: string;
133
+ readonly override?: boolean;
134
+ readonly factory: KeyBackProviderFactory;
135
+ }
136
+ declare function registerKeyBagProviderFactory(item: KeyBagProviderFactoryItem): void;
137
+ declare function getKeyBag(sthis: SuperThis, kbo?: Partial<KeyBagOpts>): Promise<KeyBag>;
138
+
139
+ type keyBag_KeyBackProviderFactory = KeyBackProviderFactory;
140
+ type keyBag_KeyBag = KeyBag;
141
+ declare const keyBag_KeyBag: typeof KeyBag;
142
+ type keyBag_KeyBagFile = KeyBagFile;
143
+ type keyBag_KeyBagOpts = KeyBagOpts;
144
+ type keyBag_KeyBagProvider = KeyBagProvider;
145
+ type keyBag_KeyBagProviderFactoryItem = KeyBagProviderFactoryItem;
146
+ type keyBag_KeyBagProviderFile = KeyBagProviderFile;
147
+ declare const keyBag_KeyBagProviderFile: typeof KeyBagProviderFile;
148
+ type keyBag_KeyBagProviderIndexDB = KeyBagProviderIndexDB;
149
+ declare const keyBag_KeyBagProviderIndexDB: typeof KeyBagProviderIndexDB;
150
+ type keyBag_KeyBagRuntime = KeyBagRuntime;
151
+ type keyBag_KeyItem = KeyItem;
152
+ declare const keyBag_getKeyBag: typeof getKeyBag;
153
+ declare const keyBag_registerKeyBagProviderFactory: typeof registerKeyBagProviderFactory;
154
+ declare namespace keyBag {
155
+ export { type keyBag_KeyBackProviderFactory as KeyBackProviderFactory, keyBag_KeyBag as KeyBag, type keyBag_KeyBagFile as KeyBagFile, type keyBag_KeyBagOpts as KeyBagOpts, type keyBag_KeyBagProvider as KeyBagProvider, type keyBag_KeyBagProviderFactoryItem as KeyBagProviderFactoryItem, keyBag_KeyBagProviderFile as KeyBagProviderFile, keyBag_KeyBagProviderIndexDB as KeyBagProviderIndexDB, type keyBag_KeyBagRuntime as KeyBagRuntime, type keyBag_KeyItem as KeyItem, keyBag_getKeyBag as getKeyBag, keyBag_registerKeyBagProviderFactory as registerKeyBagProviderFactory };
156
+ }
157
+
158
+ declare class TaskManager {
159
+ private readonly eventsWeHandled;
160
+ private queue;
161
+ private isProcessing;
162
+ readonly logger: Logger;
163
+ readonly callback: (dbMeta: DbMeta) => Promise<void>;
164
+ constructor(sthis: SuperThis, callback: (dbMeta: DbMeta) => Promise<void>);
165
+ handleEvent(cid: CarClockLink, parents: string[], dbMeta: DbMeta): Promise<void>;
166
+ private processQueue;
167
+ }
168
+
169
+ declare class Loader implements Loadable {
170
+ readonly name: string;
171
+ readonly ebOpts: BlockstoreRuntime;
172
+ readonly commitQueue: CommitQueue<CarGroup>;
173
+ readonly isCompacting = false;
174
+ readonly carReaders: Map<string, Promise<CarReader>>;
175
+ readonly seenCompacted: Set<string>;
176
+ readonly processedCars: Set<string>;
177
+ readonly sthis: SuperThis;
178
+ readonly taskManager?: TaskManager;
179
+ carLog: CarLog;
180
+ remoteMetaStore?: MetaStore;
181
+ remoteCarStore?: DataStore;
182
+ remoteFileStore?: DataStore;
183
+ private getBlockCache;
184
+ private seenMeta;
185
+ private writeLimit;
186
+ keyBag(): Promise<KeyBag>;
187
+ carStore(): Promise<DataStore>;
188
+ fileStore(): Promise<DataStore>;
189
+ WALStore(): Promise<WALStore>;
190
+ metaStore(): Promise<MetaStore>;
191
+ readonly onceReady: ResolveOnce<void>;
192
+ ready(): Promise<void>;
193
+ close(): Promise<void>;
194
+ destroy(): Promise<void>;
195
+ readonly logger: Logger;
196
+ constructor(name: string, ebOpts: BlockstoreOpts, sthis: SuperThis);
197
+ handleDbMetasFromStore(metas: DbMeta[]): Promise<void>;
198
+ mergeDbMetaIntoClock(meta: DbMeta): Promise<void>;
199
+ loadCarHeaderFromMeta<T>({ cars: cids }: DbMeta): Promise<CarHeader<T>>;
200
+ commitFiles(t: CarTransaction, done: TransactionMeta): Promise<CarGroup>;
201
+ loadFileCar(cid: AnyLink): Promise<CarReader>;
202
+ commit<T = TransactionMeta>(t: CarTransaction, done: T, opts?: CommitOpts): Promise<CarGroup>;
203
+ updateCarLog<T>(cids: CarGroup, fp: CarHeader<T>, compact: boolean): Promise<void>;
204
+ cacheTransaction(t: CarTransaction): Promise<void>;
205
+ cacheCarReader(carCidStr: string, reader: CarReader): Promise<void>;
206
+ removeCidsForCompact(cid: AnyLink): Promise<void>;
207
+ entries(cache?: boolean): AsyncIterableIterator<AnyBlock>;
208
+ getBlock(cid: AnyLink): Promise<AnyBlock | Falsy>;
209
+ loadCar(cid: AnyLink): Promise<CarReader>;
210
+ makeDecoderAndCarReader(cid: AnyLink, local: DataStore, remote?: DataStore): Promise<CarReader>;
211
+ protected storesLoadCar(cid: AnyLink, local: DataStore, remote?: DataStore): Promise<CarReader>;
212
+ protected getMoreReaders(cids: AnyLink[]): Promise<void>;
213
+ }
214
+
215
+ type BlockFetcher = BlockFetcher$1;
216
+ interface CarTransactionOpts {
217
+ readonly add: boolean;
218
+ readonly noLoader: boolean;
219
+ }
220
+ declare class CarTransaction extends MemoryBlockstore implements CarMakeable {
221
+ readonly parent: BaseBlockstore;
222
+ constructor(parent: BaseBlockstore, opts?: CarTransactionOpts);
223
+ get<T, C extends number, A extends number, V extends Version>(cid: AnyLink): Promise<Block$1<T, C, A, V> | undefined>;
224
+ superGet(cid: AnyLink): Promise<AnyBlock | undefined>;
225
+ }
226
+ declare class BaseBlockstore implements BlockFetcher {
227
+ readonly transactions: Set<CarTransaction>;
228
+ readonly ebOpts: BlockstoreRuntime;
229
+ readonly sthis: SuperThis;
230
+ readonly loader?: Loader;
231
+ readonly name?: string;
232
+ ready(): Promise<void>;
233
+ close(): Promise<void>;
234
+ destroy(): Promise<void>;
235
+ compact(): Promise<void>;
236
+ readonly logger: Logger;
237
+ constructor(ebOpts?: BlockstoreOpts);
238
+ get<T, C extends number, A extends number, V extends Version>(cid: AnyAnyLink): Promise<Block$1<T, C, A, V> | undefined>;
239
+ put(cid: AnyAnyLink, block: Uint8Array): Promise<void>;
240
+ lastTxMeta?: unknown;
241
+ transaction<M extends TransactionMeta>(fn: (t: CarTransaction) => Promise<M>, _opts?: CarTransactionOpts): Promise<TransactionWrapper<M>>;
242
+ openTransaction(opts?: CarTransactionOpts): CarTransaction;
243
+ commitTransaction<M extends TransactionMeta>(t: CarTransaction, done: M, opts: CarTransactionOpts): Promise<TransactionWrapper<M>>;
244
+ entries(): AsyncIterableIterator<AnyBlock>;
245
+ }
246
+ declare class EncryptedBlockstore extends BaseBlockstore {
247
+ readonly name: string;
248
+ readonly loader: Loader;
249
+ ready(): Promise<void>;
250
+ close(): Promise<void>;
251
+ destroy(): Promise<void>;
252
+ compacting: boolean;
253
+ readonly logger: Logger;
254
+ constructor(sthis: SuperThis, ebOpts: BlockstoreOpts);
255
+ get<T, C extends number, A extends number, V extends Version>(cid: AnyAnyLink): Promise<Block$1<T, C, A, V> | undefined>;
256
+ transaction<M extends TransactionMeta>(fn: (t: CarTransaction) => Promise<M>, opts?: {
257
+ noLoader: boolean;
258
+ }): Promise<TransactionWrapper<M>>;
259
+ getFile(car: AnyLink, cid: AnyLink): Promise<Uint8Array>;
260
+ compact(): Promise<void>;
261
+ defaultCompact(blocks: CompactionFetcher, logger: Logger): Promise<TransactionMeta>;
262
+ entries(): AsyncIterableIterator<AnyBlock>;
263
+ }
264
+ declare class CompactionFetcher implements BlockFetcher {
265
+ readonly blockstore: EncryptedBlockstore;
266
+ readonly loggedBlocks: CarTransaction;
267
+ constructor(blocks: EncryptedBlockstore);
268
+ get<T, C extends number, A extends number, V extends Version>(cid: AnyLink): Promise<Block$1<T, C, A, V> | undefined>;
269
+ }
270
+
271
+ type AnyLink = Link<unknown, number, number, Version>;
272
+ type CarGroup = AnyLink[];
273
+ type CarLog = CarGroup[];
274
+ type AnyAnyLink = Link<unknown, number, number, Version>;
275
+ type AnyLinkFn = (cid: AnyLink) => Promise<AnyBlock | undefined>;
276
+ interface AnyBlock {
277
+ readonly cid: Link<unknown, number, number, Version>;
278
+ readonly bytes: Uint8Array;
279
+ }
280
+ interface CIDBlock {
281
+ readonly cid: CID<unknown, number, number, Version>;
282
+ readonly bytes: Uint8Array;
283
+ }
284
+ declare function toCIDBlock(block: AnyBlock): CIDBlock;
285
+ interface AnyAnyBlock {
286
+ readonly cid: AnyAnyLink;
287
+ readonly bytes: Uint8Array;
288
+ }
289
+ interface IvKeyIdData {
290
+ readonly iv: Uint8Array;
291
+ readonly keyId: Uint8Array;
292
+ readonly data: Uint8Array;
293
+ }
294
+ interface IvAndBytes {
295
+ readonly bytes: Uint8Array;
296
+ readonly iv: Uint8Array;
297
+ }
298
+ interface BytesWithIv {
299
+ readonly bytes: Uint8Array;
300
+ readonly iv?: Uint8Array;
301
+ }
302
+ interface AnyDecodedBlock {
303
+ readonly cid: AnyLink;
304
+ readonly bytes: Uint8Array;
305
+ readonly value: Uint8Array;
306
+ }
307
+ interface CarMakeable {
308
+ entries(): Iterable<AnyBlock>;
309
+ get(cid: AnyLink): Promise<AnyBlock | undefined>;
310
+ }
311
+ interface CarHeader<T> {
312
+ readonly cars: CarLog;
313
+ readonly compact: CarLog;
314
+ readonly meta: T;
315
+ }
316
+ interface TransactionWrapper<M extends TransactionMeta> {
317
+ meta: M;
318
+ cars?: CarGroup;
319
+ t: CarTransaction;
320
+ }
321
+ type TransactionMeta = unknown;
322
+ interface EncryptedBlock {
323
+ readonly value: IvAndBytes;
324
+ }
325
+ interface KeyMaterial {
326
+ readonly key: Uint8Array;
327
+ readonly keyStr: string;
328
+ }
329
+ interface KeyWithFingerPrint {
330
+ readonly fingerPrint: string;
331
+ readonly key: CTCryptoKey;
332
+ }
333
+ interface KeyWithFingerExtract extends KeyWithFingerPrint {
334
+ extract(): Promise<KeyMaterial>;
335
+ }
336
+ interface CodecOpts {
337
+ readonly ivCalc: "random" | "hash";
338
+ readonly noIVVerify: boolean;
339
+ }
340
+ interface KeyedCrypto {
341
+ readonly ivLength: number;
342
+ readonly logger: Logger;
343
+ readonly crypto: CryptoRuntime;
344
+ readonly url: URI;
345
+ fingerPrint(): Promise<string>;
346
+ algo(iv?: Uint8Array): {
347
+ name: string;
348
+ iv: Uint8Array;
349
+ tagLength: number;
350
+ };
351
+ codec(iv?: Uint8Array, codecOpts?: Partial<CodecOpts>): BlockCodec<number, Uint8Array>;
352
+ _decrypt(data: IvAndBytes): Promise<Uint8Array>;
353
+ _encrypt(data: BytesWithIv): Promise<Uint8Array>;
354
+ }
355
+ interface BlobLike {
356
+ stream: () => ReadableStream;
357
+ }
358
+ interface StoreFactory {
359
+ makeMetaStore?: (loader: Loadable) => Promise<MetaStore>;
360
+ makeDataStore?: (loader: Loadable) => Promise<DataStore>;
361
+ makeWALStore?: (loader: Loadable) => Promise<WALStore>;
362
+ encodeFile?: (blob: BlobLike) => Promise<{
363
+ cid: AnyLink;
364
+ blocks: AnyBlock[];
365
+ }>;
366
+ decodeFile?: (blocks: unknown, cid: AnyLink, meta: DocFileMeta) => Promise<File>;
367
+ }
368
+ interface StoreOpts extends StoreFactory {
369
+ readonly isIndex?: string;
370
+ readonly stores?: {
371
+ readonly base?: CoerceURI;
372
+ readonly meta?: CoerceURI;
373
+ readonly data?: CoerceURI;
374
+ readonly index?: CoerceURI;
375
+ readonly wal?: CoerceURI;
376
+ };
377
+ }
378
+ interface StoreRuntime {
379
+ makeMetaStore(loader: Loadable): Promise<MetaStore>;
380
+ makeDataStore(loader: Loadable): Promise<DataStore>;
381
+ makeWALStore(loader: Loadable): Promise<WALStore>;
382
+ encodeFile(blob: BlobLike): Promise<{
383
+ cid: AnyLink;
384
+ blocks: AnyBlock[];
385
+ }>;
386
+ decodeFile(blocks: unknown, cid: AnyLink, meta: DocFileMeta): Promise<File>;
387
+ }
388
+ interface CommitOpts {
389
+ readonly noLoader?: boolean;
390
+ readonly compact?: boolean;
391
+ }
392
+ interface DbMeta {
393
+ readonly cars: CarGroup;
394
+ key?: string;
395
+ }
396
+ type LoadHandler = (dbMetas: DbMeta[]) => Promise<void>;
397
+ interface Connection {
398
+ readonly loader?: Loadable;
399
+ readonly loaded: Promise<void>;
400
+ dashboardUrl?: URI;
401
+ connectMeta_X({ loader }: {
402
+ loader?: Loadable;
403
+ }): void;
404
+ connectStorage_X({ loader }: {
405
+ loader?: Loadable;
406
+ }): void;
407
+ }
408
+ interface BaseStore {
409
+ readonly storeType: StoreType;
410
+ url(): URI;
411
+ readonly name: string;
412
+ onStarted(fn: () => void): void;
413
+ onClosed(fn: () => void): void;
414
+ keyedCrypto(): Promise<KeyedCrypto>;
415
+ close(): Promise<Result<void>>;
416
+ destroy(): Promise<Result<void>>;
417
+ readonly ready?: () => Promise<void>;
418
+ start(): Promise<Result<URI>>;
419
+ }
420
+ interface MetaStore extends BaseStore {
421
+ readonly storeType: "meta";
422
+ load(branch?: string): Promise<DbMeta[] | Falsy>;
423
+ save(meta: DbMeta, branch?: string): Promise<Result<void>>;
424
+ handleByteHeads(byteHeads: Uint8Array, branch?: string): Promise<{
425
+ eventCid: CarClockLink;
426
+ dbMeta: DbMeta;
427
+ }[]>;
428
+ }
429
+ interface DataSaveOpts {
430
+ readonly public: boolean;
431
+ }
432
+ interface DataStore extends BaseStore {
433
+ readonly storeType: "data";
434
+ load(cid: AnyLink): Promise<AnyBlock>;
435
+ save(car: AnyBlock, opts?: DataSaveOpts): Promise<void>;
436
+ remove(cid: AnyLink): Promise<Result<void>>;
437
+ }
438
+ interface WALState {
439
+ operations: DbMeta[];
440
+ noLoaderOps: DbMeta[];
441
+ fileOperations: {
442
+ readonly cid: AnyLink;
443
+ readonly public: boolean;
444
+ }[];
445
+ }
446
+ interface WALStore extends BaseStore {
447
+ readonly storeType: "wal";
448
+ ready(): Promise<void>;
449
+ readonly processing?: Promise<void> | undefined;
450
+ readonly processQueue: CommitQueue<void>;
451
+ process(): Promise<void>;
452
+ enqueue(dbMeta: DbMeta, opts: CommitOpts): Promise<void>;
453
+ enqueueFile(fileCid: AnyLink): Promise<void>;
454
+ load(): Promise<WALState | Falsy>;
455
+ save(state: WALState): Promise<void>;
456
+ }
457
+ type CompactFetcher = BlockFetcher & {
458
+ readonly loggedBlocks: CarTransaction;
459
+ };
460
+ type CompactFn = (blocks: CompactFetcher) => Promise<TransactionMeta>;
461
+ type BlockstoreOpts = Partial<{
462
+ readonly logger: Logger;
463
+ readonly applyMeta: (meta: TransactionMeta, snap?: boolean) => Promise<void>;
464
+ readonly compact: CompactFn;
465
+ readonly autoCompact: number;
466
+ readonly crypto: CryptoRuntime;
467
+ readonly store: StoreOpts;
468
+ readonly keyBag: KeyBagOpts;
469
+ readonly public: boolean;
470
+ readonly meta: DbMeta;
471
+ readonly name: string;
472
+ readonly threshold: number;
473
+ }>;
474
+ interface BlockstoreRuntime {
475
+ readonly logger: Logger;
476
+ readonly applyMeta: (meta: TransactionMeta, snap?: boolean) => Promise<void>;
477
+ readonly compact: CompactFn;
478
+ readonly autoCompact: number;
479
+ readonly crypto: CryptoRuntime;
480
+ readonly store: StoreOpts;
481
+ readonly storeRuntime: StoreRuntime;
482
+ readonly keyBag: Partial<KeyBagOpts>;
483
+ readonly meta?: DbMeta;
484
+ readonly name?: string;
485
+ readonly threshold: number;
486
+ }
487
+ interface Loadable {
488
+ readonly name: string;
489
+ readonly sthis: SuperThis;
490
+ readonly ebOpts: BlockstoreRuntime;
491
+ remoteCarStore?: DataStore;
492
+ carStore(): Promise<DataStore>;
493
+ carLog: CarLog;
494
+ remoteMetaStore?: MetaStore;
495
+ remoteFileStore?: DataStore;
496
+ taskManager?: TaskManager;
497
+ ready(): Promise<void>;
498
+ close(): Promise<void>;
499
+ fileStore(): Promise<DataStore>;
500
+ WALStore(): Promise<WALStore>;
501
+ handleDbMetasFromStore(metas: DbMeta[]): Promise<void>;
502
+ }
503
+ type DbMetaEventBlock = EventBlock<{
504
+ dbMeta: Uint8Array;
505
+ }>;
506
+ type CarClockLink = Link<DbMetaEventBlock, number, number, Version>;
507
+ type CarClockHead = CarClockLink[];
508
+
509
+ interface GatewayOpts {
510
+ readonly gateway: Gateway;
511
+ }
512
+ type GetResult = Result<Uint8Array, NotFoundError | Error>;
513
+ type VoidResult = Result<void>;
514
+ interface TestGateway {
515
+ get(url: URI, key: string): Promise<Uint8Array>;
516
+ }
517
+ type UnsubscribeResult = Result<() => void>;
518
+ interface Gateway {
519
+ buildUrl(baseUrl: URI, key: string): Promise<Result<URI>>;
520
+ start(baseUrl: URI): Promise<Result<URI>>;
521
+ close(baseUrl: URI): Promise<VoidResult>;
522
+ destroy(baseUrl: URI): Promise<VoidResult>;
523
+ put(url: URI, body: Uint8Array): Promise<VoidResult>;
524
+ get(url: URI): Promise<GetResult>;
525
+ delete(url: URI): Promise<VoidResult>;
526
+ subscribe?(url: URI, callback: (meta: Uint8Array) => void): Promise<UnsubscribeResult>;
527
+ }
528
+
529
+ interface GatewayFactoryItem {
530
+ readonly protocol: string;
531
+ readonly overrideBaseURL?: string;
532
+ readonly overrideRegistration?: boolean;
533
+ readonly gateway: (sthis: SuperThis) => Promise<Gateway>;
534
+ readonly test: (sthis: SuperThis) => Promise<TestGateway>;
535
+ }
536
+ interface GatewayReady {
537
+ readonly gateway: Gateway;
538
+ readonly test: TestGateway;
539
+ }
540
+ declare function getGatewayFromURL(url: URI, sthis: SuperThis): Promise<GatewayReady | undefined>;
541
+ declare function registerStoreProtocol(item: GatewayFactoryItem): () => void;
542
+ declare function testStoreFactory(url: URI, sthis: SuperThis): Promise<TestGateway>;
543
+ declare function ensureStart<T>(store: T & {
544
+ start: () => Promise<Result<URI>>;
545
+ }, logger: Logger): Promise<T>;
546
+ declare function toStoreRuntime(opts: StoreOpts, sthis: SuperThis): StoreRuntime;
547
+
548
+ declare class FragmentGateway implements Gateway {
549
+ readonly sthis: SuperThis;
550
+ readonly logger: Logger;
551
+ readonly fidLength = 4;
552
+ readonly innerGW: Gateway;
553
+ headerSize: number;
554
+ constructor(sthis: SuperThis, innerGW: Gateway);
555
+ slicer(url: URI, body: Uint8Array): Promise<VoidResult>[];
556
+ buildUrl(baseUrl: URI, key: string): Promise<Result<URI>>;
557
+ destroy(iurl: URI): Promise<Result<void>>;
558
+ start(url: URI): Promise<Result<URI>>;
559
+ close(url: URI): Promise<VoidResult>;
560
+ put(url: URI, body: Uint8Array): Promise<VoidResult>;
561
+ get(url: URI): Promise<GetResult>;
562
+ subscribe(url: URI, callback: (msg: Uint8Array) => void): Promise<UnsubscribeResult>;
563
+ delete(url: URI): Promise<VoidResult>;
564
+ }
565
+
566
+ interface Connectable {
567
+ readonly blockstore: {
568
+ readonly loader?: Loader;
569
+ readonly ebOpts: BlockstoreRuntime;
570
+ };
571
+ readonly name?: string;
572
+ }
573
+ declare abstract class ConnectionBase implements Connection {
574
+ loader?: Loadable;
575
+ taskManager?: TaskManager;
576
+ loaded: Promise<void>;
577
+ readonly url: URI;
578
+ readonly logger: Logger;
579
+ constructor(url: URI, logger: Logger);
580
+ refresh(): Promise<void>;
581
+ connect_X({ loader }: {
582
+ readonly loader?: Loadable;
583
+ }): Promise<void>;
584
+ connectMeta_X({ loader }: {
585
+ loader?: Loadable;
586
+ }): Promise<void>;
587
+ abstract onConnect(): Promise<void>;
588
+ connectStorage_X({ loader }: {
589
+ loader?: Loadable;
590
+ }): Promise<void>;
591
+ }
592
+
593
+ declare function parseCarFile<T>(reader: CarReader, logger: Logger): Promise<CarHeader<T>>;
594
+
595
+ declare function setCryptoKeyFromGatewayMetaPayload(uri: URI, sthis: SuperThis, data: Uint8Array): Promise<Result<DbMeta | undefined>>;
596
+ declare function addCryptoKeyToGatewayMetaPayload(uri: URI, sthis: SuperThis, body: Uint8Array): Promise<Result<Uint8Array>>;
597
+
598
+ type index$3_AnyAnyBlock = AnyAnyBlock;
599
+ type index$3_AnyAnyLink = AnyAnyLink;
600
+ type index$3_AnyBlock = AnyBlock;
601
+ type index$3_AnyDecodedBlock = AnyDecodedBlock;
602
+ type index$3_AnyLink = AnyLink;
603
+ type index$3_AnyLinkFn = AnyLinkFn;
604
+ type index$3_BaseBlockstore = BaseBlockstore;
605
+ declare const index$3_BaseBlockstore: typeof BaseBlockstore;
606
+ type index$3_BaseStore = BaseStore;
607
+ type index$3_BlobLike = BlobLike;
608
+ type index$3_BlockFetcher = BlockFetcher;
609
+ type index$3_BlockstoreOpts = BlockstoreOpts;
610
+ type index$3_BlockstoreRuntime = BlockstoreRuntime;
611
+ type index$3_BytesWithIv = BytesWithIv;
612
+ type index$3_CIDBlock = CIDBlock;
613
+ type index$3_CarClockHead = CarClockHead;
614
+ type index$3_CarClockLink = CarClockLink;
615
+ type index$3_CarGroup = CarGroup;
616
+ type index$3_CarHeader<T> = CarHeader<T>;
617
+ type index$3_CarLog = CarLog;
618
+ type index$3_CarMakeable = CarMakeable;
619
+ type index$3_CarTransaction = CarTransaction;
620
+ declare const index$3_CarTransaction: typeof CarTransaction;
621
+ type index$3_CodecOpts = CodecOpts;
622
+ type index$3_CommitOpts = CommitOpts;
623
+ type index$3_CompactFetcher = CompactFetcher;
624
+ type index$3_CompactFn = CompactFn;
625
+ type index$3_CompactionFetcher = CompactionFetcher;
626
+ declare const index$3_CompactionFetcher: typeof CompactionFetcher;
627
+ type index$3_Connectable = Connectable;
628
+ type index$3_Connection = Connection;
629
+ type index$3_ConnectionBase = ConnectionBase;
630
+ declare const index$3_ConnectionBase: typeof ConnectionBase;
631
+ type index$3_DataSaveOpts = DataSaveOpts;
632
+ type index$3_DataStore = DataStore;
633
+ type index$3_DbMeta = DbMeta;
634
+ type index$3_DbMetaEventBlock = DbMetaEventBlock;
635
+ type index$3_EncryptedBlock = EncryptedBlock;
636
+ type index$3_EncryptedBlockstore = EncryptedBlockstore;
637
+ declare const index$3_EncryptedBlockstore: typeof EncryptedBlockstore;
638
+ type index$3_FragmentGateway = FragmentGateway;
639
+ declare const index$3_FragmentGateway: typeof FragmentGateway;
640
+ type index$3_Gateway = Gateway;
641
+ type index$3_GatewayFactoryItem = GatewayFactoryItem;
642
+ type index$3_GatewayOpts = GatewayOpts;
643
+ type index$3_GetResult = GetResult;
644
+ type index$3_IvAndBytes = IvAndBytes;
645
+ type index$3_IvKeyIdData = IvKeyIdData;
646
+ type index$3_KeyMaterial = KeyMaterial;
647
+ type index$3_KeyWithFingerExtract = KeyWithFingerExtract;
648
+ type index$3_KeyWithFingerPrint = KeyWithFingerPrint;
649
+ type index$3_KeyedCrypto = KeyedCrypto;
650
+ type index$3_LoadHandler = LoadHandler;
651
+ type index$3_Loadable = Loadable;
652
+ type index$3_Loader = Loader;
653
+ declare const index$3_Loader: typeof Loader;
654
+ type index$3_MetaStore = MetaStore;
655
+ type index$3_StoreFactory = StoreFactory;
656
+ type index$3_StoreOpts = StoreOpts;
657
+ type index$3_StoreRuntime = StoreRuntime;
658
+ type index$3_TestGateway = TestGateway;
659
+ type index$3_TransactionMeta = TransactionMeta;
660
+ type index$3_TransactionWrapper<M extends TransactionMeta> = TransactionWrapper<M>;
661
+ type index$3_UnsubscribeResult = UnsubscribeResult;
662
+ type index$3_VoidResult = VoidResult;
663
+ type index$3_WALState = WALState;
664
+ type index$3_WALStore = WALStore;
665
+ declare const index$3_addCryptoKeyToGatewayMetaPayload: typeof addCryptoKeyToGatewayMetaPayload;
666
+ declare const index$3_ensureStart: typeof ensureStart;
667
+ declare const index$3_getGatewayFromURL: typeof getGatewayFromURL;
668
+ declare const index$3_parseCarFile: typeof parseCarFile;
669
+ declare const index$3_registerStoreProtocol: typeof registerStoreProtocol;
670
+ declare const index$3_setCryptoKeyFromGatewayMetaPayload: typeof setCryptoKeyFromGatewayMetaPayload;
671
+ declare const index$3_testStoreFactory: typeof testStoreFactory;
672
+ declare const index$3_toCIDBlock: typeof toCIDBlock;
673
+ declare const index$3_toStoreRuntime: typeof toStoreRuntime;
674
+ declare namespace index$3 {
675
+ export { type index$3_AnyAnyBlock as AnyAnyBlock, type index$3_AnyAnyLink as AnyAnyLink, type index$3_AnyBlock as AnyBlock, type index$3_AnyDecodedBlock as AnyDecodedBlock, type index$3_AnyLink as AnyLink, type index$3_AnyLinkFn as AnyLinkFn, index$3_BaseBlockstore as BaseBlockstore, type index$3_BaseStore as BaseStore, type index$3_BlobLike as BlobLike, type index$3_BlockFetcher as BlockFetcher, type index$3_BlockstoreOpts as BlockstoreOpts, type index$3_BlockstoreRuntime as BlockstoreRuntime, type index$3_BytesWithIv as BytesWithIv, type index$3_CIDBlock as CIDBlock, type index$3_CarClockHead as CarClockHead, type index$3_CarClockLink as CarClockLink, type index$3_CarGroup as CarGroup, type index$3_CarHeader as CarHeader, type index$3_CarLog as CarLog, type index$3_CarMakeable as CarMakeable, index$3_CarTransaction as CarTransaction, type index$3_CodecOpts as CodecOpts, type index$3_CommitOpts as CommitOpts, type index$3_CompactFetcher as CompactFetcher, type index$3_CompactFn as CompactFn, index$3_CompactionFetcher as CompactionFetcher, type index$3_Connectable as Connectable, type index$3_Connection as Connection, index$3_ConnectionBase as ConnectionBase, type index$3_DataSaveOpts as DataSaveOpts, type index$3_DataStore as DataStore, type index$3_DbMeta as DbMeta, type index$3_DbMetaEventBlock as DbMetaEventBlock, type index$3_EncryptedBlock as EncryptedBlock, index$3_EncryptedBlockstore as EncryptedBlockstore, index$3_FragmentGateway as FragmentGateway, type index$3_Gateway as Gateway, type index$3_GatewayFactoryItem as GatewayFactoryItem, type index$3_GatewayOpts as GatewayOpts, type index$3_GetResult as GetResult, type index$3_IvAndBytes as IvAndBytes, type index$3_IvKeyIdData as IvKeyIdData, type index$3_KeyMaterial as KeyMaterial, type index$3_KeyWithFingerExtract as KeyWithFingerExtract, type index$3_KeyWithFingerPrint as KeyWithFingerPrint, type index$3_KeyedCrypto as KeyedCrypto, type index$3_LoadHandler as LoadHandler, type index$3_Loadable as Loadable, index$3_Loader as Loader, type index$3_MetaStore as MetaStore, type index$3_StoreFactory as StoreFactory, type index$3_StoreOpts as StoreOpts, type index$3_StoreRuntime as StoreRuntime, type index$3_TestGateway as TestGateway, type index$3_TransactionMeta as TransactionMeta, type index$3_TransactionWrapper as TransactionWrapper, type index$3_UnsubscribeResult as UnsubscribeResult, type index$3_VoidResult as VoidResult, type index$3_WALState as WALState, type index$3_WALStore as WALStore, index$3_addCryptoKeyToGatewayMetaPayload as addCryptoKeyToGatewayMetaPayload, index$3_ensureStart as ensureStart, index$3_getGatewayFromURL as getGatewayFromURL, index$3_parseCarFile as parseCarFile, index$3_registerStoreProtocol as registerStoreProtocol, index$3_setCryptoKeyFromGatewayMetaPayload as setCryptoKeyFromGatewayMetaPayload, index$3_testStoreFactory as testStoreFactory, index$3_toCIDBlock as toCIDBlock, index$3_toStoreRuntime as toStoreRuntime };
676
+ }
677
+
678
+ type Falsy = false | null | undefined;
679
+ declare function isFalsy(value: unknown): value is Falsy;
680
+ declare function throwFalsy<T>(value: T | Falsy): T;
681
+ declare function falsyToUndef<T>(value: T | Falsy): T | undefined;
682
+ type StoreType = "data" | "wal" | "meta";
683
+ interface SysFileSystem {
684
+ start(): Promise<SysFileSystem>;
685
+ mkdir(path: PathLike, options?: {
686
+ recursive: boolean;
687
+ }): Promise<string | undefined>;
688
+ readdir(path: PathLike, options?: unknown): Promise<string[]>;
689
+ rm(path: PathLike, options?: MakeDirectoryOptions & {
690
+ recursive: boolean;
691
+ }): Promise<void>;
692
+ copyFile(source: PathLike, destination: PathLike): Promise<void>;
693
+ readfile(path: PathLike, options?: {
694
+ encoding: BufferEncoding;
695
+ flag?: string;
696
+ }): Promise<Uint8Array>;
697
+ stat(path: PathLike): Promise<Stats>;
698
+ unlink(path: PathLike): Promise<void>;
699
+ writefile(path: PathLike, data: Uint8Array | string): Promise<void>;
700
+ }
701
+ interface PathOps {
702
+ join(...args: string[]): string;
703
+ dirname(path: string): string;
704
+ }
705
+ interface TextEndeCoder {
706
+ encode(input: string): Uint8Array;
707
+ decode(input: Uint8Array): string;
708
+ }
709
+ interface SuperThisOpts {
710
+ readonly logger: Logger;
711
+ readonly pathOps: PathOps;
712
+ readonly crypto: CryptoRuntime;
713
+ readonly env: EnvFactoryOpts;
714
+ readonly txt: TextEndeCoder;
715
+ readonly ctx: Record<string, unknown>;
716
+ }
717
+ interface SuperThis {
718
+ readonly logger: Logger;
719
+ readonly env: Env;
720
+ readonly pathOps: PathOps;
721
+ readonly ctx: Record<string, unknown>;
722
+ readonly txt: TextEndeCoder;
723
+ nextId(bytes?: number): {
724
+ str: string;
725
+ bin: Uint8Array;
726
+ };
727
+ timeOrderedNextId(time?: number): {
728
+ str: string;
729
+ };
730
+ start(): Promise<void>;
731
+ clone(override: Partial<SuperThisOpts>): SuperThis;
732
+ }
733
+ interface ConfigOpts extends Partial<SuperThisOpts> {
734
+ readonly public?: boolean;
735
+ readonly meta?: DbMeta;
736
+ readonly persistIndexes?: boolean;
737
+ readonly autoCompact?: number;
738
+ readonly store?: StoreOpts;
739
+ readonly threshold?: number;
740
+ }
741
+ type ClockLink = EventLink<Operation>;
742
+ type ClockHead = ClockLink[];
743
+ type DocFragment = Uint8Array | string | number | boolean | null | AnyLink | DocFragment[] | object;
744
+ type DocLiteral = string | number | boolean | Uint8Array | unknown;
745
+ type DocObject = NonNullable<unknown>;
746
+ type DocTypes = DocObject;
747
+ type DocRecord<T extends DocObject> = T;
748
+ type UnknownDoc = DocRecord<never>;
749
+ type DocFiles = Record<string, DocFileMeta | File>;
750
+ interface DocBase {
751
+ readonly _id: string;
752
+ readonly _files?: DocFiles;
753
+ readonly _publicFiles?: DocFiles;
754
+ readonly _deleted?: boolean;
755
+ }
756
+ type DocWithId<T extends DocTypes> = DocBase & T;
757
+ type DocSet<T extends DocTypes> = Partial<DocBase> & T;
758
+ interface DocFileMeta {
759
+ readonly type: string;
760
+ readonly size: number;
761
+ readonly cid: AnyLink;
762
+ readonly car?: AnyLink;
763
+ url?: string;
764
+ file?: () => Promise<File>;
765
+ }
766
+ interface DocUpdate<T extends DocTypes> {
767
+ readonly id: string;
768
+ readonly value?: DocSet<T>;
769
+ readonly del?: boolean;
770
+ readonly clock?: ClockLink;
771
+ }
772
+ interface DocValue<T extends DocTypes> {
773
+ readonly doc: DocWithId<T>;
774
+ readonly del: boolean;
775
+ readonly cid: AnyLink;
776
+ }
777
+ type KeyLiteral = string | number | boolean;
778
+ type IndexKeyType = KeyLiteral | KeyLiteral[];
779
+ type IndexKey<K extends IndexKeyType> = [K, string];
780
+ interface IndexUpdate<K extends IndexKeyType> {
781
+ readonly key: IndexKey<K>;
782
+ readonly value?: DocFragment;
783
+ readonly del?: boolean;
784
+ }
785
+ interface IndexUpdateString {
786
+ readonly key: string;
787
+ readonly value?: DocFragment;
788
+ readonly del?: boolean;
789
+ }
790
+ interface IndexRow<K extends IndexKeyType, T extends DocObject, R extends DocFragment> {
791
+ readonly id: string;
792
+ readonly key: K;
793
+ readonly value: R;
794
+ readonly doc?: DocWithId<T>;
795
+ }
796
+ interface IndexRows<K extends IndexKeyType, T extends DocObject, R extends DocFragment = T> {
797
+ readonly rows: IndexRow<K, T, R>[];
798
+ }
799
+ interface CRDTMeta {
800
+ readonly head: ClockHead;
801
+ }
802
+ interface IndexTransactionMeta {
803
+ readonly indexes: Record<string, IdxMeta>;
804
+ }
805
+ interface FileTransactionMeta {
806
+ readonly files?: AnyLink[];
807
+ }
808
+ type MetaType = CRDTMeta | IndexTransactionMeta | FileTransactionMeta;
809
+ interface IdxMeta {
810
+ readonly byId: AnyLink;
811
+ readonly byKey: AnyLink;
812
+ readonly map: string;
813
+ readonly name: string;
814
+ readonly head: ClockHead;
815
+ }
816
+ interface IdxMetaMap {
817
+ readonly indexes?: Map<string, IdxMeta>;
818
+ }
819
+ interface QueryOpts<K extends IndexKeyType> {
820
+ readonly descending?: boolean;
821
+ readonly limit?: number;
822
+ includeDocs?: boolean;
823
+ readonly range?: [IndexKeyType, IndexKeyType];
824
+ readonly key?: DocFragment;
825
+ readonly keys?: DocFragment[];
826
+ prefix?: IndexKeyType;
827
+ }
828
+ interface AllDocsQueryOpts extends QueryOpts<string> {
829
+ readonly key?: string;
830
+ readonly keys?: string[];
831
+ prefix?: string;
832
+ }
833
+ interface AllDocsResponse<T extends DocTypes> {
834
+ readonly rows: {
835
+ readonly key: string;
836
+ readonly value: DocWithId<T>;
837
+ }[];
838
+ readonly clock: ClockHead;
839
+ readonly name?: string;
840
+ }
841
+ type EmitFn = (k: IndexKeyType, v?: DocFragment) => void;
842
+ type MapFn<T extends DocTypes> = (doc: DocWithId<T>, emit: EmitFn) => DocFragment | unknown;
843
+ interface ChangesOptions {
844
+ readonly dirty?: boolean;
845
+ readonly limit?: number;
846
+ }
847
+ interface ChangesResponseRow<T extends DocTypes> {
848
+ readonly key: string;
849
+ readonly value: DocWithId<T>;
850
+ readonly clock?: ClockLink;
851
+ }
852
+ interface ChangesResponse<T extends DocTypes> {
853
+ readonly clock: ClockHead;
854
+ readonly rows: ChangesResponseRow<T>[];
855
+ readonly name?: string;
856
+ }
857
+ interface DocResponse {
858
+ readonly id: string;
859
+ readonly clock: ClockHead;
860
+ readonly name?: string;
861
+ }
862
+ type UpdateListenerFn<T extends DocTypes> = (docs: DocWithId<T>[]) => Promise<void> | void;
863
+ type NoUpdateListenerFn = () => Promise<void> | void;
864
+ type ListenerFn<T extends DocTypes> = UpdateListenerFn<T> | NoUpdateListenerFn;
865
+ interface CRDTEntry {
866
+ data: string;
867
+ parents: string[];
868
+ cid: string;
869
+ }
870
+
871
+ interface WriteQueue<T extends DocTypes> {
872
+ push(task: DocUpdate<T>): Promise<MetaType>;
873
+ }
874
+
875
+ declare class IndexTree<K extends IndexKeyType, R extends DocFragment> {
876
+ cid?: AnyLink;
877
+ root?: ProllyNode<K, R>;
878
+ }
879
+ interface ProllyIndexRow<K extends IndexKeyType, T extends DocFragment> {
880
+ readonly id: string;
881
+ readonly key: IndexKey<K>;
882
+ readonly value: T;
883
+ }
884
+ interface ProllyNode<K extends IndexKeyType, T extends DocFragment> extends ProllyNode$1 {
885
+ getAllEntries(): PromiseLike<{
886
+ [x: string]: unknown;
887
+ result: ProllyIndexRow<K, T>[];
888
+ }>;
889
+ getMany<KI extends IndexKeyType>(removeIds: KI[]): Promise<{
890
+ result: IndexKey<K>[];
891
+ }>;
892
+ range(a: string, b: string): Promise<{
893
+ result: ProllyIndexRow<K, T>[];
894
+ }>;
895
+ get(key: string): Promise<{
896
+ result: ProllyIndexRow<K, T>[];
897
+ }>;
898
+ bulk(bulk: (IndexUpdate<K> | IndexUpdateString)[]): PromiseLike<{
899
+ readonly root?: ProllyNode<K, T>;
900
+ readonly blocks: Block$1[];
901
+ }>;
902
+ readonly address: Promise<Link>;
903
+ readonly distance: number;
904
+ compare: (a: unknown, b: unknown) => number;
905
+ readonly cache: unknown;
906
+ readonly block: Promise<Block$1>;
907
+ }
908
+
909
+ declare function index$2<K extends IndexKeyType = string, T extends DocTypes = NonNullable<unknown>, R extends DocFragment = T>(sthis: SuperThis, { _crdt }: {
910
+ _crdt: CRDT<T> | CRDT<NonNullable<unknown>>;
911
+ }, name: string, mapFn?: MapFn<T>, meta?: IdxMeta): Index<K, T, R>;
912
+ declare class Index<K extends IndexKeyType, T extends DocTypes, R extends DocFragment = T> {
913
+ readonly blockstore: BaseBlockstore;
914
+ readonly crdt: CRDT<T>;
915
+ name: string;
916
+ mapFn?: MapFn<T>;
917
+ mapFnString: string;
918
+ byKey: IndexTree<K, R>;
919
+ byId: IndexTree<K, R>;
920
+ indexHead?: ClockHead;
921
+ includeDocsDefault: boolean;
922
+ initError?: Error;
923
+ ready(): Promise<void>;
924
+ close(): Promise<void>;
925
+ destroy(): Promise<void>;
926
+ readonly logger: Logger;
927
+ constructor(sthis: SuperThis, crdt: CRDT<T> | CRDT<NonNullable<unknown>>, name: string, mapFn?: MapFn<T>, meta?: IdxMeta);
928
+ applyMapFn(name: string, mapFn?: MapFn<T>, meta?: IdxMeta): void;
929
+ query(opts?: QueryOpts<K>): Promise<IndexRows<K, T, R>>;
930
+ _resetIndex(): void;
931
+ _hydrateIndex(): Promise<void>;
932
+ _updateIndex(): Promise<IndexTransactionMeta>;
933
+ }
934
+
935
+ interface ApplyHeadTask<T extends DocTypes> {
936
+ readonly newHead: ClockHead;
937
+ readonly prevHead: ClockHead;
938
+ readonly updates?: DocUpdate<T>[];
939
+ }
940
+ interface ApplyHeadQueue<T extends DocTypes> {
941
+ push(task: ApplyHeadTask<T>): AsyncGenerator<{
942
+ readonly updates: DocUpdate<T>[];
943
+ readonly all: boolean;
944
+ }, void, unknown>;
945
+ size(): number;
946
+ }
947
+
948
+ declare class CRDTClock<T extends DocTypes> {
949
+ head: ClockHead;
950
+ readonly zoomers: Set<() => void>;
951
+ readonly watchers: Set<(updates: DocUpdate<T>[]) => void>;
952
+ readonly emptyWatchers: Set<() => void>;
953
+ readonly blockstore: BaseBlockstore;
954
+ readonly applyHeadQueue: ApplyHeadQueue<T>;
955
+ transaction?: CarTransaction;
956
+ readonly _ready: ResolveOnce<void>;
957
+ ready(): Promise<void>;
958
+ close(): Promise<void>;
959
+ readonly logger: Logger;
960
+ constructor(blockstore: BaseBlockstore);
961
+ setHead(head: ClockHead): void;
962
+ applyHead(newHead: ClockHead, prevHead: ClockHead, updates?: DocUpdate<T>[]): Promise<void>;
963
+ processUpdates(updatesAcc: DocUpdate<T>[], all: boolean, prevHead: ClockHead): Promise<void>;
964
+ notifyWatchers(updates: DocUpdate<T>[]): void;
965
+ onTick(fn: (updates: DocUpdate<T>[]) => void): void;
966
+ onTock(fn: () => void): void;
967
+ onZoom(fn: () => void): void;
968
+ int_applyHead(newHead: ClockHead, prevHead: ClockHead, localUpdates: boolean): Promise<void>;
969
+ }
970
+
971
+ declare class CRDT<T extends DocTypes> {
972
+ readonly name?: string;
973
+ readonly opts: ConfigOpts;
974
+ readonly blockstore: BaseBlockstore;
975
+ readonly indexBlockstore: BaseBlockstore;
976
+ readonly indexers: Map<string, Index<IndexKeyType, NonNullable<unknown>>>;
977
+ readonly clock: CRDTClock<T>;
978
+ readonly logger: Logger;
979
+ readonly sthis: SuperThis;
980
+ constructor(sthis: SuperThis, name?: string, opts?: ConfigOpts);
981
+ bulk(updates: DocUpdate<T>[]): Promise<CRDTMeta>;
982
+ readonly onceReady: ResolveOnce<void>;
983
+ ready(): Promise<void>;
984
+ close(): Promise<void>;
985
+ destroy(): Promise<void>;
986
+ allDocs(): Promise<{
987
+ result: DocUpdate<T>[];
988
+ head: ClockHead;
989
+ }>;
990
+ vis(): Promise<string>;
991
+ getBlock(cidString: string): Promise<Block$1>;
992
+ get(key: string): Promise<DocValue<T> | Falsy>;
993
+ changes(since?: ClockHead, opts?: ChangesOptions): Promise<{
994
+ result: DocUpdate<T>[];
995
+ head: ClockHead;
996
+ }>;
997
+ compact(): Promise<void>;
998
+ }
999
+
1000
+ declare class Database<DT extends DocTypes = NonNullable<unknown>> implements Connectable {
1001
+ static databases: Map<string, Database>;
1002
+ readonly name?: string;
1003
+ readonly opts: ConfigOpts;
1004
+ _listening: boolean;
1005
+ readonly _listeners: Set<ListenerFn<DT>>;
1006
+ readonly _noupdate_listeners: Set<ListenerFn<DT>>;
1007
+ readonly _crdt: CRDT<DT>;
1008
+ readonly _writeQueue: WriteQueue<DT>;
1009
+ readonly blockstore: BaseBlockstore;
1010
+ close(): Promise<void>;
1011
+ destroy(): Promise<void>;
1012
+ readonly _ready: ResolveOnce<void>;
1013
+ ready(): Promise<void>;
1014
+ readonly logger: Logger;
1015
+ readonly sthis: SuperThis;
1016
+ constructor(name?: string, opts?: ConfigOpts);
1017
+ get<T extends DocTypes>(id: string): Promise<DocWithId<T>>;
1018
+ put<T extends DocTypes>(doc: DocSet<T>): Promise<DocResponse>;
1019
+ del(id: string): Promise<DocResponse>;
1020
+ changes<T extends DocTypes>(since?: ClockHead, opts?: ChangesOptions): Promise<ChangesResponse<T>>;
1021
+ allDocs<T extends DocTypes>(opts?: AllDocsQueryOpts): Promise<AllDocsResponse<T>>;
1022
+ allDocuments<T extends DocTypes>(): Promise<{
1023
+ rows: {
1024
+ key: string;
1025
+ value: DocWithId<T>;
1026
+ }[];
1027
+ clock: ClockHead;
1028
+ }>;
1029
+ subscribe<T extends DocTypes>(listener: ListenerFn<T>, updates?: boolean): () => void;
1030
+ query<K extends IndexKeyType, T extends DocTypes, R extends DocFragment = T>(field: string | MapFn<T>, opts?: QueryOpts<K>): Promise<IndexRows<K, T, R>>;
1031
+ compact(): Promise<void>;
1032
+ _notify(updates: DocUpdate<NonNullable<unknown>>[]): Promise<void>;
1033
+ _no_update_notify(): Promise<void>;
1034
+ }
1035
+ declare function fireproof(name: string, opts?: ConfigOpts): Database;
1036
+
1037
+ declare function getFileSystem(url: URI): Promise<SysFileSystem>;
1038
+ declare function getPath(url: URI, sthis: SuperThis): string;
1039
+ declare function getFileName(url: URI, sthis: SuperThis): string;
1040
+ declare function toArrayBuffer(buffer: Buffer | string): Uint8Array;
1041
+
1042
+ declare function encodeFile(blob: BlobLike): Promise<{
1043
+ cid: AnyLink;
1044
+ blocks: AnyBlock[];
1045
+ }>;
1046
+ declare function decodeFile(blocks: unknown, cid: AnyLink, meta: DocFileMeta): Promise<File>;
1047
+
1048
+ declare const files_decodeFile: typeof decodeFile;
1049
+ declare const files_encodeFile: typeof encodeFile;
1050
+ declare namespace files {
1051
+ export { files_decodeFile as decodeFile, files_encodeFile as encodeFile };
1052
+ }
1053
+
1054
+ declare class BlockIvKeyIdCodec implements BlockCodec<0x300539, Uint8Array> {
1055
+ readonly code = 3147065;
1056
+ readonly name = "Fireproof@encrypted-block:aes-gcm";
1057
+ readonly ko: KeyedCrypto;
1058
+ readonly iv?: Uint8Array;
1059
+ readonly opts: Partial<CodecOpts>;
1060
+ constructor(ko: KeyedCrypto, iv?: Uint8Array, opts?: CodecOpts);
1061
+ encode(data: Uint8Array): Promise<Uint8Array>;
1062
+ decode(abytes: Uint8Array | ArrayBuffer): Promise<Uint8Array>;
1063
+ }
1064
+ declare function keyedCryptoFactory(url: URI, kb: KeyBag, sthis: SuperThis): Promise<KeyedCrypto>;
1065
+
1066
+ type keyedCrypto_BlockIvKeyIdCodec = BlockIvKeyIdCodec;
1067
+ declare const keyedCrypto_BlockIvKeyIdCodec: typeof BlockIvKeyIdCodec;
1068
+ declare const keyedCrypto_keyedCryptoFactory: typeof keyedCryptoFactory;
1069
+ declare namespace keyedCrypto {
1070
+ export { keyedCrypto_BlockIvKeyIdCodec as BlockIvKeyIdCodec, keyedCrypto_keyedCryptoFactory as keyedCryptoFactory };
1071
+ }
1072
+
1073
+ declare const Block: typeof Block$2;
1074
+ interface DecodeInput<T, Code extends number, Alg extends number> {
1075
+ bytes: ByteView<T>;
1076
+ codec: BlockDecoder<Code, T>;
1077
+ hasher: MultihashHasher<Alg>;
1078
+ }
1079
+ declare function decode<T, Code extends number, Alg extends number>({ bytes, codec, hasher, }: DecodeInput<T, Code, Alg>): Promise<BlockView<T, Code, Alg>>;
1080
+ interface EncodeInput<T, Code extends number, Alg extends number> {
1081
+ value: T;
1082
+ codec: BlockEncoder<Code, T>;
1083
+ hasher: MultihashHasher<Alg>;
1084
+ }
1085
+ declare function encode<T, Code extends number, Alg extends number>({ value, codec, hasher, }: EncodeInput<T, Code, Alg>): Promise<BlockView<T, Code, Alg>>;
1086
+ interface CreateInput<T, Code extends number, Alg extends number, V extends Version> {
1087
+ bytes: ByteView<T>;
1088
+ cid: Link<T, Code, Alg, V>;
1089
+ hasher: MultihashHasher<Alg>;
1090
+ codec: BlockDecoder<Code, T>;
1091
+ }
1092
+ declare function create<T, Code extends number, Alg extends number, V extends Version>({ bytes, cid, hasher, codec, }: CreateInput<T, Code, Alg, V>): Promise<BlockView<T, Code, Alg, V>>;
1093
+ type CreateUnsafeInput<T, Code extends number, Alg extends number, V extends Version> = {
1094
+ cid: Link<T, Code, Alg, V>;
1095
+ value: T;
1096
+ codec?: BlockDecoder<Code, T>;
1097
+ bytes: ByteView<T>;
1098
+ } | {
1099
+ cid: Link<T, Code, Alg, V>;
1100
+ value?: undefined;
1101
+ codec: BlockDecoder<Code, T>;
1102
+ bytes: ByteView<T>;
1103
+ };
1104
+ declare function createUnsafe<T, Code extends number, Alg extends number, V extends Version>({ bytes, cid, value: maybeValue, codec, }: CreateUnsafeInput<T, Code, Alg, V>): Promise<BlockView<T, Code, Alg, V>>;
1105
+
1106
+ declare const block_Block: typeof Block;
1107
+ declare const block_create: typeof create;
1108
+ declare const block_createUnsafe: typeof createUnsafe;
1109
+ declare const block_decode: typeof decode;
1110
+ declare const block_encode: typeof encode;
1111
+ declare namespace block {
1112
+ export { block_Block as Block, block_create as create, block_createUnsafe as createUnsafe, block_decode as decode, block_encode as encode };
1113
+ }
1114
+
1115
+ declare const index$1_block: typeof block;
1116
+ declare namespace index$1 {
1117
+ export { index$1_block as block, codecInterface as codec };
1118
+ }
1119
+
1120
+ declare const FILESTORE_VERSION = "v0.19-file";
1121
+
1122
+ declare const INDEXDB_VERSION = "v0.19-indexdb";
1123
+
1124
+ declare const index_FILESTORE_VERSION: typeof FILESTORE_VERSION;
1125
+ declare const index_INDEXDB_VERSION: typeof INDEXDB_VERSION;
1126
+ declare const index_files: typeof files;
1127
+ declare const index_getFileName: typeof getFileName;
1128
+ declare const index_getFileSystem: typeof getFileSystem;
1129
+ declare const index_getPath: typeof getPath;
1130
+ declare const index_runtimeFn: typeof runtimeFn;
1131
+ declare const index_toArrayBuffer: typeof toArrayBuffer;
1132
+ declare namespace index {
1133
+ export { index_FILESTORE_VERSION as FILESTORE_VERSION, index_INDEXDB_VERSION as INDEXDB_VERSION, index_files as files, index_getFileName as getFileName, index_getFileSystem as getFileSystem, index_getPath as getPath, keyBag as kb, keyedCrypto as kc, index$1 as mf, index_runtimeFn as runtimeFn, index_toArrayBuffer as toArrayBuffer };
1134
+ }
1135
+
1136
+ declare const PACKAGE_VERSION: string;
1137
+
1138
+ export { type AllDocsQueryOpts, type AllDocsResponse, CRDT, type CRDTEntry, type CRDTMeta, type ChangesOptions, type ChangesResponse, type ChangesResponseRow, type ClockHead, type ClockLink, type ConfigOpts, type Connectable, Database, type DocBase, type DocFileMeta, type DocFiles, type DocFragment, type DocLiteral, type DocObject, type DocRecord, type DocResponse, 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 MapFn, type MetaType, type NoUpdateListenerFn, NotFoundError, PACKAGE_VERSION, type PathOps, type QueryOpts, type Store, type StoreType, type SuperThis, type SuperThisOpts, type SysFileSystem, type TextEndeCoder, UInt8ArrayEqual, type UnknownDoc, type UpdateListenerFn, index$3 as blockstore, index$3 as bs, dataDir, ensureLogger, ensureSuperLog, ensureSuperThis, exceptionWrapper, falsyToUndef, fireproof, getKey, getName, getStore, index$2 as index, isFalsy, isNotFoundError, index as rt, index as runtime, throwFalsy };
1139
+ declare module '@fireproof/core'