@fireproof/core 0.19.100 → 0.19.101

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. package/{chunk-OFGPKRCM.js → chunk-3EB3ENHT.js} +54 -25
  2. package/chunk-3EB3ENHT.js.map +1 -0
  3. package/chunk-HQ7D3PEU.js +61 -0
  4. package/chunk-HQ7D3PEU.js.map +1 -0
  5. package/chunk-PZ5AY32C.js +10 -0
  6. package/deno-filesystem-Q2IJ7YDR.js +57 -0
  7. package/deno-filesystem-Q2IJ7YDR.js.map +1 -0
  8. package/{gateway-5FCWPX5W.js → gateway-GK5QZ6KP.js} +13 -12
  9. package/gateway-GK5QZ6KP.js.map +1 -0
  10. package/{gateway-H7UD6TNB.js → gateway-TQTGDRCN.js} +9 -8
  11. package/gateway-TQTGDRCN.js.map +1 -0
  12. package/index.cjs +2158 -1718
  13. package/index.cjs.map +1 -1
  14. package/index.d.cts +261 -117
  15. package/index.d.ts +261 -117
  16. package/index.global.js +11834 -11354
  17. package/index.global.js.map +1 -1
  18. package/index.js +1865 -1519
  19. package/index.js.map +1 -1
  20. package/{key-bag-file-WADZBHYG.js → key-bag-file-VOSSK46F.js} +4 -3
  21. package/{key-bag-file-WADZBHYG.js.map → key-bag-file-VOSSK46F.js.map} +1 -1
  22. package/{key-bag-indexdb-PGVAI3FJ.js → key-bag-indexdb-AXTQOSMC.js} +4 -3
  23. package/{key-bag-indexdb-PGVAI3FJ.js.map → key-bag-indexdb-AXTQOSMC.js.map} +1 -1
  24. package/key-bag-memory-LWE6ARPX.js +29 -0
  25. package/key-bag-memory-LWE6ARPX.js.map +1 -0
  26. package/metafile-cjs.json +1 -1
  27. package/metafile-esm.json +1 -1
  28. package/metafile-iife.json +1 -1
  29. package/{node-filesystem-INX4ZTHE.js → node-filesystem-CFRXFSO7.js} +6 -9
  30. package/node-filesystem-CFRXFSO7.js.map +1 -0
  31. package/package.json +1 -1
  32. package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +129 -0
  33. package/tests/blockstore/keyed-crypto.test.ts +63 -227
  34. package/tests/blockstore/loader.test.ts +19 -11
  35. package/tests/blockstore/store.test.ts +23 -19
  36. package/tests/blockstore/transaction.test.ts +12 -12
  37. package/tests/fireproof/all-gateway.test.ts +201 -193
  38. package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +324 -316
  39. package/tests/fireproof/crdt.test.ts +67 -16
  40. package/tests/fireproof/database.test.ts +183 -21
  41. package/tests/fireproof/fireproof.test.ts +83 -74
  42. package/tests/fireproof/hello.test.ts +18 -14
  43. package/tests/fireproof/indexer.test.ts +53 -43
  44. package/tests/fireproof/utils.test.ts +18 -6
  45. package/tests/gateway/file/loader-config.test.ts +303 -0
  46. package/tests/gateway/indexdb/loader-config.test.ts +75 -0
  47. package/tests/helpers.ts +27 -9
  48. package/tests/react/useFireproof.test.tsx +1 -1
  49. package/{utils-QO2HIWGI.js → utils-STA2C35G.js} +4 -3
  50. package/utils-STA2C35G.js.map +1 -0
  51. package/chunk-OFGPKRCM.js.map +0 -1
  52. package/chunk-WS3YRPIA.js +0 -75
  53. package/chunk-WS3YRPIA.js.map +0 -1
  54. package/gateway-5FCWPX5W.js.map +0 -1
  55. package/gateway-H7UD6TNB.js.map +0 -1
  56. package/mem-filesystem-YPPJV7Q2.js +0 -41
  57. package/mem-filesystem-YPPJV7Q2.js.map +0 -1
  58. package/node-filesystem-INX4ZTHE.js.map +0 -1
  59. package/tests/fireproof/config.test.ts +0 -172
  60. /package/{utils-QO2HIWGI.js.map → chunk-PZ5AY32C.js.map} +0 -0
  61. /package/tests/fireproof/{fireproof.test.fixture.ts → fireproof.fixture.ts} +0 -0
package/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { Future, Logger, URI, Result, CoerceURI, ResolveOnce, ResolveSeq, CryptoRuntime, CTCryptoKey, EnvFactoryOpts, Env, runtimeFn } from '@adviser/cement';
1
+ import { Future, Logger, URI, Result, ResolveOnce, ResolveSeq, CoerceURI, CryptoRuntime, CTCryptoKey, EnvFactoryOpts, Env, runtimeFn } from '@adviser/cement';
2
2
  export { Logger, Result } from '@adviser/cement';
3
3
  import { EventLink } from '@web3-storage/pail/clock/api';
4
4
  import { Operation } from '@web3-storage/pail/crdt/api';
@@ -8,7 +8,6 @@ import { BlockFetcher as BlockFetcher$1 } from '@web3-storage/pail/api';
8
8
  import { CarReader } from '@ipld/car';
9
9
  import { IDBPDatabase } from 'idb';
10
10
  import { EventBlock } from '@web3-storage/pail/clock';
11
- import { PathLike, MakeDirectoryOptions, Stats } from 'fs';
12
11
  import { ProllyNode as ProllyNode$1 } from 'prolly-trees/db-index';
13
12
  import { Block as Block$2 } from 'multiformats/block';
14
13
 
@@ -59,7 +58,6 @@ declare class NotFoundError extends Error {
59
58
  readonly code = "ENOENT";
60
59
  }
61
60
  declare function isNotFoundError(e: Error | Result<unknown> | unknown): e is NotFoundError;
62
- declare function dataDir(sthis: SuperThis, name?: string, base?: CoerceURI): URI;
63
61
  declare function UInt8ArrayEqual(a: Uint8Array, b: Uint8Array): boolean;
64
62
 
65
63
  interface KeyBagCtx {
@@ -134,6 +132,7 @@ interface KeyBagProviderFactoryItem {
134
132
  readonly factory: KeyBackProviderFactory;
135
133
  }
136
134
  declare function registerKeyBagProviderFactory(item: KeyBagProviderFactoryItem): void;
135
+ declare function defaultKeyBagOpts(sthis: SuperThis, kbo?: Partial<KeyBagOpts>): KeyBagRuntime;
137
136
  declare function getKeyBag(sthis: SuperThis, kbo?: Partial<KeyBagOpts>): Promise<KeyBag>;
138
137
 
139
138
  type keyBag_KeyBackProviderFactory = KeyBackProviderFactory;
@@ -149,10 +148,11 @@ type keyBag_KeyBagProviderIndexDB = KeyBagProviderIndexDB;
149
148
  declare const keyBag_KeyBagProviderIndexDB: typeof KeyBagProviderIndexDB;
150
149
  type keyBag_KeyBagRuntime = KeyBagRuntime;
151
150
  type keyBag_KeyItem = KeyItem;
151
+ declare const keyBag_defaultKeyBagOpts: typeof defaultKeyBagOpts;
152
152
  declare const keyBag_getKeyBag: typeof getKeyBag;
153
153
  declare const keyBag_registerKeyBagProviderFactory: typeof registerKeyBagProviderFactory;
154
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 };
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_defaultKeyBagOpts as defaultKeyBagOpts, keyBag_getKeyBag as getKeyBag, keyBag_registerKeyBagProviderFactory as registerKeyBagProviderFactory };
156
156
  }
157
157
 
158
158
  declare class TaskManager {
@@ -167,7 +167,6 @@ declare class TaskManager {
167
167
  }
168
168
 
169
169
  declare class Loader implements Loadable {
170
- readonly name: string;
171
170
  readonly ebOpts: BlockstoreRuntime;
172
171
  readonly commitQueue: CommitQueue<CarGroup>;
173
172
  readonly isCompacting = false;
@@ -175,7 +174,7 @@ declare class Loader implements Loadable {
175
174
  readonly seenCompacted: Set<string>;
176
175
  readonly processedCars: Set<string>;
177
176
  readonly sthis: SuperThis;
178
- readonly taskManager?: TaskManager;
177
+ readonly taskManager: TaskManager;
179
178
  carLog: CarLog;
180
179
  remoteMetaStore?: MetaStore;
181
180
  remoteCarStore?: DataStore;
@@ -183,17 +182,21 @@ declare class Loader implements Loadable {
183
182
  private getBlockCache;
184
183
  private seenMeta;
185
184
  private writeLimit;
186
- keyBag(): Promise<KeyBag>;
185
+ readonly _carStore: ResolveOnce<DataStore, void>;
187
186
  carStore(): Promise<DataStore>;
187
+ readonly _fileStore: ResolveOnce<DataStore, void>;
188
188
  fileStore(): Promise<DataStore>;
189
+ readonly _WALStore: ResolveOnce<WALStore, void>;
189
190
  WALStore(): Promise<WALStore>;
191
+ readonly _metaStore: ResolveOnce<MetaStore, void>;
190
192
  metaStore(): Promise<MetaStore>;
193
+ keyBag(): Promise<KeyBag>;
191
194
  readonly onceReady: ResolveOnce<void>;
192
195
  ready(): Promise<void>;
193
196
  close(): Promise<void>;
194
197
  destroy(): Promise<void>;
195
198
  readonly logger: Logger;
196
- constructor(name: string, ebOpts: BlockstoreOpts, sthis: SuperThis);
199
+ constructor(sthis: SuperThis, ebOpts: BlockstoreOpts);
197
200
  handleDbMetasFromStore(metas: DbMeta[]): Promise<void>;
198
201
  mergeDbMetaIntoClock(meta: DbMeta): Promise<void>;
199
202
  loadCarHeaderFromMeta<T>({ cars: cids }: DbMeta): Promise<CarHeader<T>>;
@@ -228,20 +231,21 @@ declare class BaseBlockstore implements BlockFetcher {
228
231
  readonly ebOpts: BlockstoreRuntime;
229
232
  readonly sthis: SuperThis;
230
233
  readonly loader?: Loader;
231
- readonly name?: string;
232
234
  ready(): Promise<void>;
233
235
  close(): Promise<void>;
234
236
  destroy(): Promise<void>;
237
+ compact(): Promise<void>;
235
238
  readonly logger: Logger;
236
- constructor(ebOpts?: BlockstoreOpts);
239
+ constructor(ebOpts: BlockstoreOpts);
237
240
  get<T, C extends number, A extends number, V extends Version>(cid: AnyAnyLink): Promise<Block$1<T, C, A, V> | undefined>;
238
241
  put(cid: AnyAnyLink, block: Uint8Array): Promise<void>;
239
242
  lastTxMeta?: unknown;
240
243
  transaction<M extends TransactionMeta>(fn: (t: CarTransaction) => Promise<M>, _opts?: CarTransactionOpts): Promise<TransactionWrapper<M>>;
244
+ openTransaction(opts?: CarTransactionOpts): CarTransaction;
245
+ commitTransaction<M extends TransactionMeta>(t: CarTransaction, done: M, opts: CarTransactionOpts): Promise<TransactionWrapper<M>>;
241
246
  entries(): AsyncIterableIterator<AnyBlock>;
242
247
  }
243
248
  declare class EncryptedBlockstore extends BaseBlockstore {
244
- readonly name: string;
245
249
  readonly loader: Loader;
246
250
  ready(): Promise<void>;
247
251
  close(): Promise<void>;
@@ -265,6 +269,26 @@ declare class CompactionFetcher implements BlockFetcher {
265
269
  get<T, C extends number, A extends number, V extends Version>(cid: AnyLink): Promise<Block$1<T, C, A, V> | undefined>;
266
270
  }
267
271
 
272
+ interface GatewayOpts {
273
+ readonly gateway: Gateway;
274
+ }
275
+ type GetResult = Result<Uint8Array, NotFoundError | Error>;
276
+ type VoidResult = Result<void>;
277
+ interface TestGateway {
278
+ get(url: URI, key: string): Promise<Uint8Array>;
279
+ }
280
+ type UnsubscribeResult = Result<() => void>;
281
+ interface Gateway {
282
+ buildUrl(baseUrl: URI, key: string): Promise<Result<URI>>;
283
+ start(baseUrl: URI): Promise<Result<URI>>;
284
+ close(baseUrl: URI): Promise<VoidResult>;
285
+ destroy(baseUrl: URI): Promise<VoidResult>;
286
+ put(url: URI, body: Uint8Array): Promise<VoidResult>;
287
+ get(url: URI): Promise<GetResult>;
288
+ delete(url: URI): Promise<VoidResult>;
289
+ subscribe?(url: URI, callback: (meta: Uint8Array) => void): Promise<UnsubscribeResult>;
290
+ }
291
+
268
292
  type AnyLink = Link<unknown, number, number, Version>;
269
293
  type CarGroup = AnyLink[];
270
294
  type CarLog = CarGroup[];
@@ -362,20 +386,42 @@ interface StoreFactory {
362
386
  }>;
363
387
  decodeFile?: (blocks: unknown, cid: AnyLink, meta: DocFileMeta) => Promise<File>;
364
388
  }
365
- interface StoreOpts extends StoreFactory {
366
- readonly isIndex?: string;
367
- readonly stores?: {
368
- readonly base?: CoerceURI;
369
- readonly meta?: CoerceURI;
370
- readonly data?: CoerceURI;
371
- readonly index?: CoerceURI;
372
- readonly wal?: CoerceURI;
373
- };
389
+ interface StoreUrls {
390
+ readonly meta: CoerceURI;
391
+ readonly data: CoerceURI;
392
+ readonly wal: CoerceURI;
393
+ }
394
+ interface StoreEnDeFile {
395
+ readonly encodeFile: (blob: BlobLike) => Promise<{
396
+ cid: AnyLink;
397
+ blocks: AnyBlock[];
398
+ }>;
399
+ readonly decodeFile: (blocks: unknown, cid: AnyLink, meta: DocFileMeta) => Promise<File>;
400
+ }
401
+ interface StoreUrlsOpts {
402
+ readonly base?: CoerceURI;
403
+ readonly data?: Partial<StoreUrls>;
404
+ readonly idx?: Partial<StoreUrls>;
405
+ }
406
+ interface StoreURIs {
407
+ readonly meta: URI;
408
+ readonly data: URI;
409
+ readonly file: URI;
410
+ readonly wal: URI;
411
+ }
412
+ interface StoreURIRuntime {
413
+ readonly data: StoreURIs;
414
+ readonly idx: StoreURIs;
415
+ }
416
+ interface StoreFactoryItem {
417
+ readonly sthis: SuperThis;
418
+ readonly url: URI;
419
+ readonly keybag: KeyBag;
374
420
  }
375
421
  interface StoreRuntime {
376
- makeMetaStore(loader: Loadable): Promise<MetaStore>;
377
- makeDataStore(loader: Loadable): Promise<DataStore>;
378
- makeWALStore(loader: Loadable): Promise<WALStore>;
422
+ makeMetaStore(sfi: StoreFactoryItem): Promise<MetaStore>;
423
+ makeDataStore(sfi: StoreFactoryItem): Promise<DataStore>;
424
+ makeWALStore(sfi: StoreFactoryItem): Promise<WALStore>;
379
425
  encodeFile(blob: BlobLike): Promise<{
380
426
  cid: AnyLink;
381
427
  blocks: AnyBlock[];
@@ -403,6 +449,7 @@ interface Connection {
403
449
  }
404
450
  interface BaseStore {
405
451
  readonly storeType: StoreType;
452
+ readonly realGateway: Gateway;
406
453
  url(): URI;
407
454
  readonly name: string;
408
455
  onStarted(fn: () => void): void;
@@ -413,14 +460,16 @@ interface BaseStore {
413
460
  readonly ready?: () => Promise<void>;
414
461
  start(): Promise<Result<URI>>;
415
462
  }
463
+ interface DbMetaEvent {
464
+ readonly eventCid: CarClockLink;
465
+ readonly parents: string[];
466
+ readonly dbMeta: DbMeta;
467
+ }
416
468
  interface MetaStore extends BaseStore {
417
469
  readonly storeType: "meta";
418
470
  load(branch?: string): Promise<DbMeta[] | Falsy>;
419
471
  save(meta: DbMeta, branch?: string): Promise<Result<void>>;
420
- handleByteHeads(byteHeads: Uint8Array, branch?: string): Promise<{
421
- eventCid: CarClockLink;
422
- dbMeta: DbMeta;
423
- }[]>;
472
+ handleByteHeads(byteHeads: Uint8Array, branch?: string): Promise<DbMetaEvent[]>;
424
473
  }
425
474
  interface DataSaveOpts {
426
475
  readonly public: boolean;
@@ -454,46 +503,53 @@ type CompactFetcher = BlockFetcher & {
454
503
  readonly loggedBlocks: CarTransaction;
455
504
  };
456
505
  type CompactFn = (blocks: CompactFetcher) => Promise<TransactionMeta>;
506
+ interface StoreRuntimeUrls {
507
+ readonly meta: URI;
508
+ readonly data: URI;
509
+ readonly wal: URI;
510
+ }
457
511
  type BlockstoreOpts = Partial<{
458
512
  readonly logger: Logger;
459
513
  readonly applyMeta: (meta: TransactionMeta, snap?: boolean) => Promise<void>;
460
514
  readonly compact: CompactFn;
461
515
  readonly autoCompact: number;
462
516
  readonly crypto: CryptoRuntime;
463
- readonly store: StoreOpts;
464
- readonly keyBag: KeyBagOpts;
465
517
  readonly public: boolean;
466
518
  readonly meta: DbMeta;
467
- readonly name: string;
468
519
  readonly threshold: number;
469
- }>;
520
+ readonly storeEnDeFile: Partial<StoreEnDeFile>;
521
+ }> & {
522
+ readonly keyBag: KeyBagRuntime;
523
+ readonly storeUrls: StoreURIs;
524
+ readonly storeRuntime: StoreRuntime;
525
+ };
470
526
  interface BlockstoreRuntime {
471
527
  readonly logger: Logger;
472
528
  readonly applyMeta: (meta: TransactionMeta, snap?: boolean) => Promise<void>;
473
529
  readonly compact: CompactFn;
474
530
  readonly autoCompact: number;
475
531
  readonly crypto: CryptoRuntime;
476
- readonly store: StoreOpts;
477
532
  readonly storeRuntime: StoreRuntime;
478
- readonly keyBag: Partial<KeyBagOpts>;
533
+ readonly keyBag: KeyBagRuntime;
534
+ readonly storeUrls: StoreURIs;
479
535
  readonly meta?: DbMeta;
480
- readonly name?: string;
481
536
  readonly threshold: number;
482
537
  }
483
538
  interface Loadable {
484
- readonly name: string;
485
539
  readonly sthis: SuperThis;
486
540
  readonly ebOpts: BlockstoreRuntime;
487
- remoteCarStore?: DataStore;
488
- carStore(): Promise<DataStore>;
489
541
  carLog: CarLog;
490
542
  remoteMetaStore?: MetaStore;
491
543
  remoteFileStore?: DataStore;
492
- taskManager?: TaskManager;
544
+ remoteCarStore?: DataStore;
545
+ readonly taskManager: TaskManager;
493
546
  ready(): Promise<void>;
494
547
  close(): Promise<void>;
548
+ keyBag(): Promise<KeyBag>;
549
+ metaStore(): Promise<MetaStore>;
495
550
  fileStore(): Promise<DataStore>;
496
551
  WALStore(): Promise<WALStore>;
552
+ carStore(): Promise<DataStore>;
497
553
  handleDbMetasFromStore(metas: DbMeta[]): Promise<void>;
498
554
  }
499
555
  type DbMetaEventBlock = EventBlock<{
@@ -502,44 +558,17 @@ type DbMetaEventBlock = EventBlock<{
502
558
  type CarClockLink = Link<DbMetaEventBlock, number, number, Version>;
503
559
  type CarClockHead = CarClockLink[];
504
560
 
505
- interface GatewayOpts {
506
- readonly gateway: Gateway;
507
- }
508
- type GetResult = Result<Uint8Array, NotFoundError | Error>;
509
- type VoidResult = Result<void>;
510
- interface TestGateway {
511
- get(url: URI, key: string): Promise<Uint8Array>;
512
- }
513
- type UnsubscribeResult = Result<() => void>;
514
- interface Gateway {
515
- buildUrl(baseUrl: URI, key: string): Promise<Result<URI>>;
516
- start(baseUrl: URI): Promise<Result<URI>>;
517
- close(baseUrl: URI): Promise<VoidResult>;
518
- destroy(baseUrl: URI): Promise<VoidResult>;
519
- put(url: URI, body: Uint8Array): Promise<VoidResult>;
520
- get(url: URI): Promise<GetResult>;
521
- delete(url: URI): Promise<VoidResult>;
522
- subscribe?(url: URI, callback: (meta: Uint8Array) => void): Promise<UnsubscribeResult>;
523
- }
524
-
525
- interface GatewayFactoryItem {
526
- readonly protocol: string;
527
- readonly overrideBaseURL?: string;
528
- readonly overrideRegistration?: boolean;
529
- readonly gateway: (sthis: SuperThis) => Promise<Gateway>;
530
- readonly test: (sthis: SuperThis) => Promise<TestGateway>;
531
- }
532
- interface GatewayReady {
561
+ interface GatewayInstances {
533
562
  readonly gateway: Gateway;
534
563
  readonly test: TestGateway;
535
564
  }
536
- declare function getGatewayFromURL(url: URI, sthis: SuperThis): Promise<GatewayReady | undefined>;
537
- declare function registerStoreProtocol(item: GatewayFactoryItem): () => void;
565
+ interface GatewayReady extends GatewayInstances {
566
+ readonly url: URI;
567
+ }
568
+ declare function getStartedGateway(sthis: SuperThis, url: URI): Promise<Result<GatewayReady>>;
538
569
  declare function testStoreFactory(url: URI, sthis: SuperThis): Promise<TestGateway>;
539
- declare function ensureStart<T>(store: T & {
540
- start: () => Promise<Result<URI>>;
541
- }, logger: Logger): Promise<T>;
542
- declare function toStoreRuntime(opts: StoreOpts, sthis: SuperThis): StoreRuntime;
570
+ declare function ensureStoreEnDeFile(ende?: Partial<StoreEnDeFile>): StoreEnDeFile;
571
+ declare function toStoreRuntime(sthis: SuperThis, endeOpts?: Partial<StoreEnDeFile>): StoreRuntime;
543
572
 
544
573
  declare class FragmentGateway implements Gateway {
545
574
  readonly sthis: SuperThis;
@@ -559,13 +588,20 @@ declare class FragmentGateway implements Gateway {
559
588
  delete(url: URI): Promise<VoidResult>;
560
589
  }
561
590
 
562
- interface Connectable {
563
- readonly blockstore: {
564
- readonly loader?: Loader;
565
- readonly ebOpts: BlockstoreRuntime;
566
- };
567
- readonly name?: string;
591
+ interface GatewayFactoryItem {
592
+ readonly protocol: string;
593
+ readonly isDefault?: boolean;
594
+ readonly defaultURI: (sthis: SuperThis) => URI;
595
+ readonly gateway: (sthis: SuperThis) => Promise<Gateway>;
596
+ readonly test: (sthis: SuperThis) => Promise<TestGateway>;
568
597
  }
598
+ declare function getDefaultURI(sthis: SuperThis, protocol?: string): URI;
599
+ declare function registerStoreProtocol(item: GatewayFactoryItem): () => void;
600
+ declare function getGatewayFactoryItem(protocol: string): GatewayFactoryItem | undefined;
601
+ declare function fileGatewayFactoryItem(): GatewayFactoryItem;
602
+
603
+ declare function parseCarFile<T>(reader: CarReader, logger: Logger): Promise<CarHeader<T>>;
604
+
569
605
  declare abstract class ConnectionBase implements Connection {
570
606
  loader?: Loadable;
571
607
  taskManager?: TaskManager;
@@ -586,8 +622,6 @@ declare abstract class ConnectionBase implements Connection {
586
622
  }): Promise<void>;
587
623
  }
588
624
 
589
- declare function parseCarFile<T>(reader: CarReader, logger: Logger): Promise<CarHeader<T>>;
590
-
591
625
  declare function setCryptoKeyFromGatewayMetaPayload(uri: URI, sthis: SuperThis, data: Uint8Array): Promise<Result<DbMeta | undefined>>;
592
626
  declare function addCryptoKeyToGatewayMetaPayload(uri: URI, sthis: SuperThis, body: Uint8Array): Promise<Result<Uint8Array>>;
593
627
 
@@ -620,13 +654,13 @@ type index$3_CompactFetcher = CompactFetcher;
620
654
  type index$3_CompactFn = CompactFn;
621
655
  type index$3_CompactionFetcher = CompactionFetcher;
622
656
  declare const index$3_CompactionFetcher: typeof CompactionFetcher;
623
- type index$3_Connectable = Connectable;
624
657
  type index$3_Connection = Connection;
625
658
  type index$3_ConnectionBase = ConnectionBase;
626
659
  declare const index$3_ConnectionBase: typeof ConnectionBase;
627
660
  type index$3_DataSaveOpts = DataSaveOpts;
628
661
  type index$3_DataStore = DataStore;
629
662
  type index$3_DbMeta = DbMeta;
663
+ type index$3_DbMetaEvent = DbMetaEvent;
630
664
  type index$3_DbMetaEventBlock = DbMetaEventBlock;
631
665
  type index$3_EncryptedBlock = EncryptedBlock;
632
666
  type index$3_EncryptedBlockstore = EncryptedBlockstore;
@@ -648,9 +682,15 @@ type index$3_Loadable = Loadable;
648
682
  type index$3_Loader = Loader;
649
683
  declare const index$3_Loader: typeof Loader;
650
684
  type index$3_MetaStore = MetaStore;
685
+ type index$3_StoreEnDeFile = StoreEnDeFile;
651
686
  type index$3_StoreFactory = StoreFactory;
652
- type index$3_StoreOpts = StoreOpts;
687
+ type index$3_StoreFactoryItem = StoreFactoryItem;
653
688
  type index$3_StoreRuntime = StoreRuntime;
689
+ type index$3_StoreRuntimeUrls = StoreRuntimeUrls;
690
+ type index$3_StoreURIRuntime = StoreURIRuntime;
691
+ type index$3_StoreURIs = StoreURIs;
692
+ type index$3_StoreUrls = StoreUrls;
693
+ type index$3_StoreUrlsOpts = StoreUrlsOpts;
654
694
  type index$3_TestGateway = TestGateway;
655
695
  type index$3_TransactionMeta = TransactionMeta;
656
696
  type index$3_TransactionWrapper<M extends TransactionMeta> = TransactionWrapper<M>;
@@ -659,8 +699,11 @@ type index$3_VoidResult = VoidResult;
659
699
  type index$3_WALState = WALState;
660
700
  type index$3_WALStore = WALStore;
661
701
  declare const index$3_addCryptoKeyToGatewayMetaPayload: typeof addCryptoKeyToGatewayMetaPayload;
662
- declare const index$3_ensureStart: typeof ensureStart;
663
- declare const index$3_getGatewayFromURL: typeof getGatewayFromURL;
702
+ declare const index$3_ensureStoreEnDeFile: typeof ensureStoreEnDeFile;
703
+ declare const index$3_fileGatewayFactoryItem: typeof fileGatewayFactoryItem;
704
+ declare const index$3_getDefaultURI: typeof getDefaultURI;
705
+ declare const index$3_getGatewayFactoryItem: typeof getGatewayFactoryItem;
706
+ declare const index$3_getStartedGateway: typeof getStartedGateway;
664
707
  declare const index$3_parseCarFile: typeof parseCarFile;
665
708
  declare const index$3_registerStoreProtocol: typeof registerStoreProtocol;
666
709
  declare const index$3_setCryptoKeyFromGatewayMetaPayload: typeof setCryptoKeyFromGatewayMetaPayload;
@@ -668,35 +711,66 @@ declare const index$3_testStoreFactory: typeof testStoreFactory;
668
711
  declare const index$3_toCIDBlock: typeof toCIDBlock;
669
712
  declare const index$3_toStoreRuntime: typeof toStoreRuntime;
670
713
  declare namespace index$3 {
671
- 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 };
714
+ 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_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_DbMetaEvent as DbMetaEvent, 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_StoreEnDeFile as StoreEnDeFile, type index$3_StoreFactory as StoreFactory, type index$3_StoreFactoryItem as StoreFactoryItem, type index$3_StoreRuntime as StoreRuntime, type index$3_StoreRuntimeUrls as StoreRuntimeUrls, type index$3_StoreURIRuntime as StoreURIRuntime, type index$3_StoreURIs as StoreURIs, type index$3_StoreUrls as StoreUrls, type index$3_StoreUrlsOpts as StoreUrlsOpts, 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_ensureStoreEnDeFile as ensureStoreEnDeFile, index$3_fileGatewayFactoryItem as fileGatewayFactoryItem, index$3_getDefaultURI as getDefaultURI, index$3_getGatewayFactoryItem as getGatewayFactoryItem, index$3_getStartedGateway as getStartedGateway, 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 };
672
715
  }
673
716
 
674
717
  type Falsy = false | null | undefined;
675
718
  declare function isFalsy(value: unknown): value is Falsy;
719
+ declare enum PARAM {
720
+ SUFFIX = "suffix",
721
+ URL_GEN = "urlGen",
722
+ STORE_KEY = "storekey",
723
+ STORE = "store",
724
+ KEY = "key",
725
+ INDEX = "index",
726
+ NAME = "name",
727
+ VERSION = "version",
728
+ FRAG_SIZE = "fragSize",
729
+ IV_VERIFY = "ivVerify",
730
+ IV_HASH = "ivHash",
731
+ FRAG_FID = "fid",
732
+ FRAG_OFS = "ofs",
733
+ FRAG_LEN = "len",
734
+ FRAG_HEAD = "headerSize"
735
+ }
676
736
  declare function throwFalsy<T>(value: T | Falsy): T;
677
737
  declare function falsyToUndef<T>(value: T | Falsy): T | undefined;
678
738
  type StoreType = "data" | "wal" | "meta";
739
+ interface FPStats {
740
+ isFile(): boolean;
741
+ isDirectory(): boolean;
742
+ isBlockDevice(): boolean;
743
+ isCharacterDevice(): boolean;
744
+ isSymbolicLink(): boolean;
745
+ isFIFO(): boolean;
746
+ isSocket(): boolean;
747
+ uid: number | Falsy;
748
+ gid: number | Falsy;
749
+ size: number | Falsy;
750
+ atime: Date | Falsy;
751
+ mtime: Date | Falsy;
752
+ ctime: Date | Falsy;
753
+ birthtime: Date | Falsy;
754
+ }
679
755
  interface SysFileSystem {
680
756
  start(): Promise<SysFileSystem>;
681
- mkdir(path: PathLike, options?: {
757
+ mkdir(path: string, options?: {
682
758
  recursive: boolean;
683
759
  }): Promise<string | undefined>;
684
- readdir(path: PathLike, options?: unknown): Promise<string[]>;
685
- rm(path: PathLike, options?: MakeDirectoryOptions & {
760
+ readdir(path: string): Promise<string[]>;
761
+ rm(path: string, options?: {
686
762
  recursive: boolean;
687
763
  }): Promise<void>;
688
- copyFile(source: PathLike, destination: PathLike): Promise<void>;
689
- readfile(path: PathLike, options?: {
690
- encoding: BufferEncoding;
691
- flag?: string;
692
- }): Promise<Uint8Array>;
693
- stat(path: PathLike): Promise<Stats>;
694
- unlink(path: PathLike): Promise<void>;
695
- writefile(path: PathLike, data: Uint8Array | string): Promise<void>;
764
+ copyFile(source: string, destination: string): Promise<void>;
765
+ readfile(path: string): Promise<Uint8Array>;
766
+ stat(path: string): Promise<FPStats>;
767
+ unlink(path: string): Promise<void>;
768
+ writefile(path: string, data: Uint8Array | string): Promise<void>;
696
769
  }
697
770
  interface PathOps {
698
771
  join(...args: string[]): string;
699
772
  dirname(path: string): string;
773
+ basename(path: string): string;
700
774
  }
701
775
  interface TextEndeCoder {
702
776
  encode(input: string): Uint8Array;
@@ -716,12 +790,14 @@ interface SuperThis {
716
790
  readonly pathOps: PathOps;
717
791
  readonly ctx: Record<string, unknown>;
718
792
  readonly txt: TextEndeCoder;
719
- nextId(bytes?: number): {
793
+ timeOrderedNextId(time?: number): {
720
794
  str: string;
721
- bin: Uint8Array;
795
+ toString: () => string;
722
796
  };
723
- timeOrderedNextId(time?: number): {
797
+ nextId(bytes?: number): {
724
798
  str: string;
799
+ bin: Uint8Array;
800
+ toString: () => string;
725
801
  };
726
802
  start(): Promise<void>;
727
803
  clone(override: Partial<SuperThisOpts>): SuperThis;
@@ -729,10 +805,11 @@ interface SuperThis {
729
805
  interface ConfigOpts extends Partial<SuperThisOpts> {
730
806
  readonly public?: boolean;
731
807
  readonly meta?: DbMeta;
732
- readonly persistIndexes?: boolean;
733
808
  readonly autoCompact?: number;
734
- readonly store?: StoreOpts;
809
+ readonly storeUrls?: StoreUrlsOpts;
810
+ readonly storeEnDe?: StoreEnDeFile;
735
811
  readonly threshold?: number;
812
+ readonly keyBag?: Partial<KeyBagOpts>;
736
813
  }
737
814
  type ClockLink = EventLink<Operation>;
738
815
  type ClockHead = ClockLink[];
@@ -902,13 +979,11 @@ interface ProllyNode<K extends IndexKeyType, T extends DocFragment> extends Prol
902
979
  readonly block: Promise<Block$1>;
903
980
  }
904
981
 
905
- declare function index$2<K extends IndexKeyType = string, T extends DocTypes = NonNullable<unknown>, R extends DocFragment = T>(sthis: SuperThis, { _crdt }: {
906
- _crdt: CRDT<T> | CRDT<NonNullable<unknown>>;
907
- }, name: string, mapFn?: MapFn<T>, meta?: IdxMeta): Index<K, T, R>;
982
+ declare function index$2<K extends IndexKeyType = string, T extends DocTypes = NonNullable<unknown>, R extends DocFragment = T>(refDb: HasCRDT<T>, name: string, mapFn?: MapFn<T>, meta?: IdxMeta): Index<K, T, R>;
908
983
  declare class Index<K extends IndexKeyType, T extends DocTypes, R extends DocFragment = T> {
909
984
  readonly blockstore: BaseBlockstore;
910
985
  readonly crdt: CRDT<T>;
911
- name: string;
986
+ readonly name: string;
912
987
  mapFn?: MapFn<T>;
913
988
  mapFnString: string;
914
989
  byKey: IndexTree<K, R>;
@@ -917,8 +992,6 @@ declare class Index<K extends IndexKeyType, T extends DocTypes, R extends DocFra
917
992
  includeDocsDefault: boolean;
918
993
  initError?: Error;
919
994
  ready(): Promise<void>;
920
- close(): Promise<void>;
921
- destroy(): Promise<void>;
922
995
  readonly logger: Logger;
923
996
  constructor(sthis: SuperThis, crdt: CRDT<T> | CRDT<NonNullable<unknown>>, name: string, mapFn?: MapFn<T>, meta?: IdxMeta);
924
997
  applyMapFn(name: string, mapFn?: MapFn<T>, meta?: IdxMeta): void;
@@ -948,6 +1021,7 @@ declare class CRDTClock<T extends DocTypes> {
948
1021
  readonly emptyWatchers: Set<() => void>;
949
1022
  readonly blockstore: BaseBlockstore;
950
1023
  readonly applyHeadQueue: ApplyHeadQueue<T>;
1024
+ transaction?: CarTransaction;
951
1025
  readonly _ready: ResolveOnce<void>;
952
1026
  ready(): Promise<void>;
953
1027
  close(): Promise<void>;
@@ -963,16 +1037,18 @@ declare class CRDTClock<T extends DocTypes> {
963
1037
  int_applyHead(newHead: ClockHead, prevHead: ClockHead, localUpdates: boolean): Promise<void>;
964
1038
  }
965
1039
 
1040
+ interface HasCRDT<T extends DocTypes> {
1041
+ readonly crdt: CRDT<T> | CRDT<NonNullable<unknown>>;
1042
+ }
966
1043
  declare class CRDT<T extends DocTypes> {
967
- readonly name?: string;
968
- readonly opts: ConfigOpts;
1044
+ readonly opts: DatabaseOpts;
969
1045
  readonly blockstore: BaseBlockstore;
970
1046
  readonly indexBlockstore: BaseBlockstore;
971
1047
  readonly indexers: Map<string, Index<IndexKeyType, NonNullable<unknown>>>;
972
1048
  readonly clock: CRDTClock<T>;
973
1049
  readonly logger: Logger;
974
1050
  readonly sthis: SuperThis;
975
- constructor(sthis: SuperThis, name?: string, opts?: ConfigOpts);
1051
+ constructor(sthis: SuperThis, opts: DatabaseOpts);
976
1052
  bulk(updates: DocUpdate<T>[]): Promise<CRDTMeta>;
977
1053
  readonly onceReady: ResolveOnce<void>;
978
1054
  ready(): Promise<void>;
@@ -992,23 +1068,90 @@ declare class CRDT<T extends DocTypes> {
992
1068
  compact(): Promise<void>;
993
1069
  }
994
1070
 
995
- declare class Database<DT extends DocTypes = NonNullable<unknown>> implements Connectable {
996
- static databases: Map<string, Database>;
1071
+ declare function keyConfigOpts(sthis: SuperThis, name?: string, opts?: ConfigOpts): string;
1072
+ interface DatabaseOpts {
997
1073
  readonly name?: string;
998
- readonly opts: ConfigOpts;
1074
+ readonly meta?: DbMeta;
1075
+ readonly storeUrls: StoreURIRuntime;
1076
+ readonly storeEnDe: StoreEnDeFile;
1077
+ readonly keyBag: KeyBagRuntime;
1078
+ }
1079
+ interface Database<DT extends DocTypes = NonNullable<unknown>> extends HasCRDT<DT> {
1080
+ readonly logger: Logger;
1081
+ readonly sthis: SuperThis;
1082
+ readonly id: string;
1083
+ name(): string;
1084
+ onClosed(fn: () => void): void;
1085
+ close(): Promise<void>;
1086
+ destroy(): Promise<void>;
1087
+ ready(): Promise<void>;
1088
+ get<T extends DocTypes>(id: string): Promise<DocWithId<T>>;
1089
+ put<T extends DocTypes>(doc: DocSet<T>): Promise<DocResponse>;
1090
+ del(id: string): Promise<DocResponse>;
1091
+ changes<T extends DocTypes>(since?: ClockHead, opts?: ChangesOptions): Promise<ChangesResponse<T>>;
1092
+ allDocs<T extends DocTypes>(opts?: AllDocsQueryOpts): Promise<AllDocsResponse<T>>;
1093
+ allDocuments<T extends DocTypes>(): Promise<{
1094
+ rows: {
1095
+ key: string;
1096
+ value: DocWithId<T>;
1097
+ }[];
1098
+ clock: ClockHead;
1099
+ }>;
1100
+ subscribe<T extends DocTypes>(listener: ListenerFn<T>, updates?: boolean): () => void;
1101
+ query<K extends IndexKeyType, T extends DocTypes, R extends DocFragment = T>(field: string | MapFn<T>, opts?: QueryOpts<K>): Promise<IndexRows<K, T, R>>;
1102
+ compact(): Promise<void>;
1103
+ }
1104
+ declare function isDatabase<T extends DocTypes = NonNullable<unknown>>(db: unknown): db is Database<T>;
1105
+ declare function DatabaseFactory<T extends DocTypes = NonNullable<unknown>>(name: string | undefined, opts?: ConfigOpts): Database<T>;
1106
+ declare class DatabaseShell<DT extends DocTypes = NonNullable<unknown>> implements Database<DT> {
1107
+ readonly ref: DatabaseImpl<DT>;
1108
+ constructor(ref: DatabaseImpl<DT>);
1109
+ get id(): string;
1110
+ get logger(): Logger;
1111
+ get sthis(): SuperThis;
1112
+ get crdt(): CRDT<DT>;
1113
+ name(): string;
1114
+ onClosed(fn: () => void): void;
1115
+ close(): Promise<void>;
1116
+ destroy(): Promise<void>;
1117
+ ready(): Promise<void>;
1118
+ get<T extends DocTypes>(id: string): Promise<DocWithId<T>>;
1119
+ put<T extends DocTypes>(doc: DocSet<T>): Promise<DocResponse>;
1120
+ del(id: string): Promise<DocResponse>;
1121
+ changes<T extends DocTypes>(since?: ClockHead, opts?: ChangesOptions): Promise<ChangesResponse<T>>;
1122
+ allDocs<T extends DocTypes>(opts?: AllDocsQueryOpts): Promise<AllDocsResponse<T>>;
1123
+ allDocuments<T extends DocTypes>(): Promise<{
1124
+ rows: {
1125
+ key: string;
1126
+ value: DocWithId<T>;
1127
+ }[];
1128
+ clock: ClockHead;
1129
+ }>;
1130
+ subscribe<T extends DocTypes>(listener: ListenerFn<T>, updates?: boolean): () => void;
1131
+ query<K extends IndexKeyType, T extends DocTypes, R extends DocFragment = T>(field: string | MapFn<T>, opts?: QueryOpts<K>): Promise<IndexRows<K, T, R>>;
1132
+ compact(): Promise<void>;
1133
+ }
1134
+ declare class DatabaseImpl<DT extends DocTypes = NonNullable<unknown>> implements Database<DT> {
1135
+ readonly opts: DatabaseOpts;
999
1136
  _listening: boolean;
1000
1137
  readonly _listeners: Set<ListenerFn<DT>>;
1001
1138
  readonly _noupdate_listeners: Set<ListenerFn<DT>>;
1002
- readonly _crdt: CRDT<DT>;
1139
+ readonly crdt: CRDT<DT>;
1003
1140
  readonly _writeQueue: WriteQueue<DT>;
1004
- readonly blockstore: BaseBlockstore;
1141
+ readonly shells: Set<DatabaseShell<DT>>;
1142
+ addShell(shell: DatabaseShell<DT>): void;
1143
+ readonly _onClosedFns: Set<() => void>;
1144
+ onClosed(fn: () => void): void;
1005
1145
  close(): Promise<void>;
1146
+ shellClose(db: DatabaseShell<DT>): Promise<void>;
1006
1147
  destroy(): Promise<void>;
1007
1148
  readonly _ready: ResolveOnce<void>;
1008
1149
  ready(): Promise<void>;
1009
1150
  readonly logger: Logger;
1010
1151
  readonly sthis: SuperThis;
1011
- constructor(name?: string, opts?: ConfigOpts);
1152
+ readonly id: string;
1153
+ constructor(sthis: SuperThis, opts: DatabaseOpts);
1154
+ name(): string;
1012
1155
  get<T extends DocTypes>(id: string): Promise<DocWithId<T>>;
1013
1156
  put<T extends DocTypes>(doc: DocSet<T>): Promise<DocResponse>;
1014
1157
  del(id: string): Promise<DocResponse>;
@@ -1027,6 +1170,7 @@ declare class Database<DT extends DocTypes = NonNullable<unknown>> implements Co
1027
1170
  _notify(updates: DocUpdate<NonNullable<unknown>>[]): Promise<void>;
1028
1171
  _no_update_notify(): Promise<void>;
1029
1172
  }
1173
+ declare function toStoreURIRuntime(sthis: SuperThis, name?: string, sopts?: StoreUrlsOpts): StoreURIRuntime;
1030
1174
  declare function fireproof(name: string, opts?: ConfigOpts): Database;
1031
1175
 
1032
1176
  declare function getFileSystem(url: URI): Promise<SysFileSystem>;
@@ -1130,5 +1274,5 @@ declare namespace index {
1130
1274
 
1131
1275
  declare const PACKAGE_VERSION: string;
1132
1276
 
1133
- 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 };
1277
+ export { type AllDocsQueryOpts, type AllDocsResponse, CRDT, type CRDTEntry, type CRDTMeta, type ChangesOptions, type ChangesResponse, type ChangesResponseRow, type ClockHead, type ClockLink, type ConfigOpts, type Database, DatabaseFactory, type DatabaseOpts, DatabaseShell, 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 FPStats, type Falsy, type FileTransactionMeta, type HasCRDT, 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, PARAM, 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, ensureLogger, ensureSuperLog, ensureSuperThis, exceptionWrapper, falsyToUndef, fireproof, getKey, getName, getStore, index$2 as index, isDatabase, isFalsy, isNotFoundError, keyConfigOpts, index as rt, index as runtime, throwFalsy, toStoreURIRuntime };
1134
1278
  declare module '@fireproof/core'