@fireproof/core 0.17.2 → 0.17.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. package/dist/browser/fireproof.cjs +10 -6
  2. package/dist/browser/fireproof.cjs.map +1 -1
  3. package/dist/browser/fireproof.d.cts +15 -12
  4. package/dist/browser/fireproof.d.ts +15 -12
  5. package/dist/browser/fireproof.global.js +174 -107
  6. package/dist/browser/fireproof.global.js.map +1 -1
  7. package/dist/browser/fireproof.js +14 -6
  8. package/dist/browser/fireproof.js.map +1 -1
  9. package/dist/browser/metafile-cjs.json +1 -1
  10. package/dist/browser/metafile-esm.json +1 -1
  11. package/dist/browser/metafile-iife.json +1 -1
  12. package/dist/memory/fireproof.cjs +10 -6
  13. package/dist/memory/fireproof.cjs.map +1 -1
  14. package/dist/memory/fireproof.d.cts +15 -12
  15. package/dist/memory/fireproof.d.ts +15 -12
  16. package/dist/memory/fireproof.global.js +174 -107
  17. package/dist/memory/fireproof.global.js.map +1 -1
  18. package/dist/memory/fireproof.js +14 -6
  19. package/dist/memory/fireproof.js.map +1 -1
  20. package/dist/memory/metafile-cjs.json +1 -1
  21. package/dist/memory/metafile-esm.json +1 -1
  22. package/dist/memory/metafile-iife.json +1 -1
  23. package/dist/node/fireproof.cjs +4 -5
  24. package/dist/node/fireproof.cjs.map +1 -1
  25. package/dist/node/fireproof.d.cts +15 -12
  26. package/dist/node/fireproof.d.ts +15 -12
  27. package/dist/node/fireproof.global.js +169 -98
  28. package/dist/node/fireproof.global.js.map +1 -1
  29. package/dist/node/fireproof.js +4 -5
  30. package/dist/node/fireproof.js.map +1 -1
  31. package/dist/node/metafile-cjs.json +1 -1
  32. package/dist/node/metafile-esm.json +1 -1
  33. package/dist/node/metafile-iife.json +1 -1
  34. package/package.json +8 -5
@@ -84,7 +84,12 @@ var import_encrypted_blockstore2 = require("@fireproof/encrypted-blockstore");
84
84
 
85
85
  // src/eb-web.ts
86
86
  var crypto = __toESM(require("@fireproof/encrypted-blockstore/crypto-web"), 1);
87
- var store = __toESM(require("@fireproof/encrypted-blockstore/store-web"), 1);
87
+ var import_store_web = require("@fireproof/encrypted-blockstore/store-web");
88
+ var store = {
89
+ makeDataStore: import_store_web.makeDataStore,
90
+ makeMetaStore: import_store_web.makeMetaStore,
91
+ makeRemoteWAL: import_store_web.makeRemoteWAL
92
+ };
88
93
 
89
94
  // src/crdt-helpers.ts
90
95
  var import_block = require("multiformats/block");
@@ -166,10 +171,8 @@ var UnixFSFileBuilder = class {
166
171
 
167
172
  // src/crdt-helpers.ts
168
173
  function time(tag) {
169
- console.time(tag);
170
174
  }
171
175
  function timeEnd(tag) {
172
- console.timeEnd(tag);
173
176
  }
174
177
  async function applyBulkUpdateToCrdt(tblocks, head, updates) {
175
178
  let result = null;
@@ -296,6 +299,7 @@ async function getValueFromLink(blocks, link) {
296
299
  if (!block)
297
300
  throw new Error(`Missing linked block ${link.toString()}`);
298
301
  const { value } = await (0, import_block.decode)({ bytes: block.bytes, hasher: import_sha2.sha256, codec });
302
+ value.cid = link;
299
303
  readFiles(blocks, value);
300
304
  return value;
301
305
  }
@@ -918,7 +922,7 @@ async function advanceBlocks(newHead, tblocks, head) {
918
922
  try {
919
923
  head = await (0, import_clock2.advance)(tblocks, head, cid);
920
924
  } catch (e) {
921
- console.error("failed to advance", cid.toString(), e);
925
+ console.log("failed to advance head:", cid.toString());
922
926
  continue;
923
927
  }
924
928
  }
@@ -948,8 +952,8 @@ var CRDT = class {
948
952
  return { head: this.clock.head };
949
953
  },
950
954
  autoCompact: this.opts.autoCompact || 100,
951
- crypto,
952
- store,
955
+ crypto: this.opts.crypto || crypto,
956
+ store: this.opts.store || store,
953
957
  public: this.opts.public,
954
958
  meta: this.opts.meta
955
959
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fireproof.ts","../../src/database.ts","../../src/write-queue.ts","../../src/crdt.ts","../../src/eb-web.ts","../../src/crdt-helpers.ts","../../src/files.ts","../../src/indexer-helpers.ts","../../src/index.ts","../../src/crdt-clock.ts","../../src/apply-head-queue.ts"],"sourcesContent":["export * from './database'\nexport * from \"./types\"\n","import { uuidv7 } from 'uuidv7'\n\nimport { WriteQueue, writeQueue } from './write-queue'\nimport { CRDT } from './crdt'\nimport { index } from './index'\nimport type {\n CRDTMeta,\n DocUpdate,\n ClockHead,\n Doc,\n ConfigOpts,\n MapFn,\n QueryOpts,\n ChangesOptions,\n DocRecord\n} from './types'\nimport { DbResponse, ChangesResponse } from './types'\nimport { EncryptedBlockstore } from '@fireproof/encrypted-blockstore'\n\ntype DbName = string | null\n\nexport class Database {\n static databases: Map<string, Database> = new Map()\n\n name: DbName\n opts: ConfigOpts = {}\n\n _listening = false\n _listeners: Set<ListenerFn> = new Set()\n _noupdate_listeners: Set<ListenerFn> = new Set()\n _crdt: CRDT\n _writeQueue: WriteQueue\n\n blockstore: EncryptedBlockstore\n\n constructor(name?: string, opts?: ConfigOpts) {\n this.name = name || null\n this.opts = opts || this.opts\n this._crdt = new CRDT(name, this.opts)\n this.blockstore = this._crdt.blockstore // for connector compatibility\n this._writeQueue = writeQueue(async (updates: DocUpdate[]) => {\n return await this._crdt.bulk(updates)\n }) //, Infinity)\n this._crdt.clock.onTock(() => {\n this._no_update_notify()\n })\n }\n\n async get<T extends DocRecord<T> = {}>(id: string): Promise<Doc<T>> {\n const got = await this._crdt.get(id).catch(e => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n e.message = `Not found: ${id} - ` + e.message\n throw e\n })\n if (!got) throw new Error(`Not found: ${id}`)\n const { doc } = got\n return { _id: id, ...doc } as Doc<T>\n }\n\n async put<T extends DocRecord<T> = {}>(doc: Doc<T>): Promise<DbResponse> {\n const { _id, ...value } = doc\n const docId = _id || uuidv7()\n const result: CRDTMeta = await this._writeQueue.push({ key: docId, value } as DocUpdate)\n return { id: docId, clock: result?.head } as DbResponse\n }\n\n async del(id: string): Promise<DbResponse> {\n const result = await this._writeQueue.push({ key: id, del: true })\n return { id, clock: result?.head } as DbResponse\n }\n\n async changes<T extends DocRecord<T> = {}>(since: ClockHead = [], opts: ChangesOptions = {}): Promise<ChangesResponse<T>> {\n const { result, head } = await this._crdt.changes(since, opts)\n const rows = result.map(({ key, value, del, clock }) => ({\n key,\n value: (del ? { _id: key, _deleted: true } : { _id: key, ...value }) as Doc<T>,\n clock\n }))\n return { rows, clock: head }\n }\n\n async allDocs<T extends DocRecord<T> = {}>() {\n const { result, head } = await this._crdt.allDocs()\n const rows = result.map(({ key, value, del }) => ({\n key,\n value: (del ? { _id: key, _deleted: true } : { _id: key, ...value }) as Doc<T>\n }))\n return { rows, clock: head }\n }\n\n async allDocuments<T extends DocRecord<T> = {}>() {\n return this.allDocs<T>()\n }\n\n subscribe(listener: ListenerFn | NoUpdateListenerFn, updates?: boolean): () => void {\n if (updates) {\n if (!this._listening) {\n this._listening = true\n this._crdt.clock.onTick((updates: DocUpdate[]) => {\n void this._notify(updates)\n })\n }\n this._listeners.add(listener)\n return () => {\n this._listeners.delete(listener)\n }\n } else {\n this._noupdate_listeners.add(listener)\n return () => {\n this._noupdate_listeners.delete(listener)\n }\n }\n }\n\n // todo if we add this onto dbs in fireproof.ts then we can make index.ts a separate package\n async query<T extends DocRecord<T> = {}>(field: string | MapFn, opts: QueryOpts = {}) {\n const idx =\n typeof field === 'string'\n ? index({ _crdt: this._crdt }, field)\n : index({ _crdt: this._crdt }, makeName(field.toString()), field)\n return await idx.query<T>(opts)\n }\n\n async compact() {\n await this._crdt.compact()\n }\n\n async _notify(updates: DocUpdate[]) {\n if (this._listeners.size) {\n const docs: Doc[] = updates.map(({ key, value }) => ({ _id: key, ...value }))\n for (const listener of this._listeners) {\n await (async () => await listener(docs))().catch((e: Error) => {\n console.error('subscriber error', e)\n })\n }\n }\n }\n\n async _no_update_notify() {\n if (this._noupdate_listeners.size) {\n for (const listener of this._noupdate_listeners) {\n await (async () => await listener([]))().catch((e: Error) => {\n console.error('subscriber error', e)\n })\n }\n }\n }\n}\n\ntype UpdateListenerFn = <T extends DocRecord<T>>(docs: Doc<T>[]) => Promise<void> | void\ntype NoUpdateListenerFn = () => Promise<void> | void\ntype ListenerFn = UpdateListenerFn | NoUpdateListenerFn\n\nexport function fireproof(name: string, opts?: ConfigOpts): Database {\n if (!Database.databases.has(name)) {\n Database.databases.set(name, new Database(name, opts))\n }\n return Database.databases.get(name)!\n}\n\nfunction makeName(fnString: string) {\n const regex = /\\(([^,()]+,\\s*[^,()]+|\\[[^\\]]+\\],\\s*[^,()]+)\\)/g\n let found: RegExpExecArray | null = null\n const matches = Array.from(fnString.matchAll(regex), match => match[1].trim())\n if (matches.length === 0) {\n found = /=>\\s*(.*)/.exec(fnString)\n }\n if (!found) {\n return fnString\n } else {\n // it's a consise arrow function, match everything after the arrow\n return found[1]\n }\n}\n","import { CRDTMeta, DocUpdate } from './types'\n\ntype WorkerFunction = (tasks: DocUpdate[]) => Promise<CRDTMeta>;\n\nexport type WriteQueue = {\n push(task: DocUpdate): Promise<CRDTMeta>;\n};\n\nexport function writeQueue(worker: WorkerFunction, payload: number = Infinity, unbounded: boolean = false): WriteQueue {\n const queue: {\n task: DocUpdate;\n resolve: (result: CRDTMeta) => void;\n reject: (error: Error) => void;\n }[] = []\n let isProcessing = false\n\n async function process() {\n if (isProcessing || queue.length === 0) return\n isProcessing = true\n\n const tasksToProcess = queue.splice(0, payload)\n const updates = tasksToProcess.map(item => item.task)\n\n if (unbounded) {\n // Run all updates in parallel and resolve/reject them individually\n const promises = updates.map(async (update, index) => {\n try {\n const result = await worker([update])\n tasksToProcess[index].resolve(result)\n } catch (error) {\n tasksToProcess[index].reject(error as Error)\n }\n })\n\n await Promise.all(promises)\n } else {\n // Original logic: Run updates in a batch and resolve/reject them together\n try {\n const result = await worker(updates)\n tasksToProcess.forEach(task => task.resolve(result))\n } catch (error) {\n tasksToProcess.forEach(task => task.reject(error as Error))\n }\n }\n\n isProcessing = false\n void process()\n }\n\n return {\n push(task: DocUpdate): Promise<CRDTMeta> {\n return new Promise<CRDTMeta>((resolve, reject) => {\n queue.push({ task, resolve, reject })\n void process()\n })\n }\n }\n}\n","import {\n EncryptedBlockstore,\n type CompactionFetcher,\n type TransactionMeta,\n type CarTransaction\n} from '@fireproof/encrypted-blockstore'\n\nimport { store, crypto } from './eb-web'\n\nimport {\n clockChangesSince,\n applyBulkUpdateToCrdt,\n getValueFromCrdt,\n readFiles,\n getAllEntries,\n clockVis,\n getBlock,\n doCompact\n} from './crdt-helpers'\nimport type {\n DocUpdate,\n CRDTMeta,\n ClockHead,\n ConfigOpts,\n ChangesOptions,\n IdxMetaMap\n} from './types'\nimport { index, type Index } from './index'\nimport { CRDTClock } from './crdt-clock'\n\nexport class CRDT {\n name: string | null\n opts: ConfigOpts = {}\n ready: Promise<void>\n blockstore: EncryptedBlockstore\n indexBlockstore: EncryptedBlockstore\n\n indexers: Map<string, Index> = new Map()\n\n clock: CRDTClock = new CRDTClock()\n\n constructor(name?: string, opts?: ConfigOpts) {\n this.name = name || null\n this.opts = opts || this.opts\n this.blockstore = new EncryptedBlockstore({\n name,\n applyMeta: async (meta: TransactionMeta) => {\n const crdtMeta = meta as unknown as CRDTMeta\n await this.clock.applyHead(crdtMeta.head, [])\n },\n compact: async (blocks: CompactionFetcher) => {\n await doCompact(blocks, this.clock.head)\n return { head: this.clock.head } as TransactionMeta\n },\n autoCompact: this.opts.autoCompact || 100,\n crypto,\n store,\n public: this.opts.public,\n meta: this.opts.meta\n })\n this.clock.blockstore = this.blockstore\n this.indexBlockstore = new EncryptedBlockstore({\n name: this.opts.persistIndexes && this.name ? this.name + '.idx' : undefined,\n applyMeta: async (meta: TransactionMeta) => {\n const idxCarMeta = meta as unknown as IdxMetaMap\n for (const [name, idx] of Object.entries(idxCarMeta.indexes)) {\n index({ _crdt: this }, name, undefined, idx as any)\n }\n },\n crypto,\n public: this.opts.public,\n store\n })\n this.ready = Promise.all([this.blockstore.ready, this.indexBlockstore.ready]).then(() => {})\n this.clock.onZoom(() => {\n for (const idx of this.indexers.values()) {\n idx._resetIndex()\n }\n })\n }\n\n async bulk(updates: DocUpdate[]): Promise<CRDTMeta> {\n await this.ready\n const prevHead = [...this.clock.head]\n const meta = (await this.blockstore.transaction(\n async (blocks: CarTransaction): Promise<TransactionMeta> => {\n const { head } = await applyBulkUpdateToCrdt(blocks, this.clock.head, updates)\n updates = updates.map(({ key, value, del, clock }) => {\n readFiles(this.blockstore, { doc: value })\n return { key, value, del, clock }\n })\n return { head } as TransactionMeta\n }\n )) as CRDTMeta\n await this.clock.applyHead(meta.head, prevHead, updates)\n return meta\n }\n\n // if (snap) await this.clock.applyHead(crdtMeta.head, this.clock.head)\n\n async allDocs() {\n await this.ready\n const result: DocUpdate[] = []\n for await (const entry of getAllEntries(this.blockstore, this.clock.head)) {\n result.push(entry)\n }\n return { result, head: this.clock.head }\n }\n\n async vis() {\n await this.ready\n const txt: string[] = []\n for await (const line of clockVis(this.blockstore, this.clock.head)) {\n txt.push(line)\n }\n return txt.join('\\n')\n }\n\n async getBlock(cidString: string) {\n await this.ready\n return await getBlock(this.blockstore, cidString)\n }\n\n async get(key: string) {\n await this.ready\n const result = await getValueFromCrdt(this.blockstore, this.clock.head, key)\n if (result.del) return null\n return result\n }\n\n async changes(since: ClockHead = [], opts: ChangesOptions = {}) {\n await this.ready\n return await clockChangesSince(this.blockstore, this.clock.head, since, opts)\n }\n\n async compact() {\n return await this.blockstore.compact()\n }\n}\n","import * as crypto from '@fireproof/encrypted-blockstore/crypto-web'\nimport * as store from '@fireproof/encrypted-blockstore/store-web'\n\nexport { store, crypto }\n","import { encode, decode, Block } from 'multiformats/block'\nimport { parse } from 'multiformats/link'\nimport { sha256 as hasher } from 'multiformats/hashes/sha2'\nimport * as codec from '@ipld/dag-cbor'\nimport { put, get, entries, root } from '@web3-storage/pail/crdt'\nimport { Operation, PutOperation } from '@web3-storage/pail/src/crdt/api'\nimport { EventFetcher, vis } from '@web3-storage/pail/clock'\nimport * as Batch from '@web3-storage/pail/crdt/batch'\n\nimport {\n type EncryptedBlockstore,\n type CompactionFetcher,\n CarTransaction,\n TransactionMeta,\n BlockFetcher\n} from '@fireproof/encrypted-blockstore'\nimport type {\n DocUpdate,\n ClockHead,\n AnyLink,\n DocValue,\n CRDTMeta,\n ChangesOptions,\n Doc,\n DocFileMeta,\n DocFiles\n} from './types'\nimport { decodeFile, encodeFile } from './files'\nimport { Result } from '@web3-storage/pail/src/crdt/api'\n\nfunction time(tag: string) {\n console.time(tag)\n}\n\nfunction timeEnd(tag: string) {\n console.timeEnd(tag)\n}\n\nexport async function applyBulkUpdateToCrdt(\n tblocks: CarTransaction,\n head: ClockHead,\n updates: DocUpdate[]\n): Promise<CRDTMeta> {\n let result: Result | null = null\n // const batch = await Batch.create(tblocks, init.cid)\n // console.log('applyBulkUpdateToCrdt', updates.length)\n if (updates.length > 1) {\n // throw new Error('batch not implemented')\n const batch = await Batch.create(tblocks, head)\n for (const update of updates) {\n const link = await writeDocContent(tblocks, update)\n await batch.put(update.key, link)\n }\n result = await batch.commit()\n // console.log('batch result', result)\n } else {\n for (const update of updates) {\n const link = await writeDocContent(tblocks, update)\n result = await put(tblocks, head, update.key, link)\n const resRoot = result.root.toString()\n const isReturned = result.additions.some(a => a.cid.toString() === resRoot)\n if (!isReturned) {\n const hasRoot = await tblocks.get(result.root) // is a db-wide get\n if (!hasRoot) {\n throw new Error(\n `missing root in additions: ${result.additions.length} ${resRoot} keys: ${updates\n .map(u => u.key)\n .toString()}`\n )\n }\n }\n }\n }\n if (!result) throw new Error('Missing result')\n\n if (result.event) {\n for (const { cid, bytes } of [...result.additions, ...result.removals, result.event]) {\n tblocks.putSync(cid, bytes)\n }\n }\n return { head: result.head } as CRDTMeta\n}\n\n// this whole thing can get pulled outside of the write queue\nasync function writeDocContent(blocks: CarTransaction, update: DocUpdate): Promise<AnyLink> {\n let value: DocValue\n if (update.del) {\n value = { del: true }\n } else {\n await processFiles(blocks, update.value as Doc)\n value = { doc: update.value }\n }\n const block = await encode({ value, hasher, codec })\n blocks.putSync(block.cid, block.bytes)\n return block.cid\n}\n\nasync function processFiles(blocks: CarTransaction, doc: Doc) {\n if (doc._files) {\n await processFileset(blocks, doc._files)\n }\n if (doc._publicFiles) {\n await processFileset(blocks, doc._publicFiles, true)\n }\n}\n\nasync function processFileset(blocks: CarTransaction, files: DocFiles, publicFiles = false) {\n const dbBlockstore = blocks.parent\n const t = new CarTransaction(dbBlockstore) // maybe this should move to encrypted-blockstore\n const didPut = []\n // let totalSize = 0\n for (const filename in files) {\n if (File === files[filename].constructor) {\n const file = files[filename] as File\n\n // totalSize += file.size\n const { cid, blocks: fileBlocks } = await encodeFile(file)\n didPut.push(filename)\n for (const block of fileBlocks) {\n t.putSync(block.cid, block.bytes)\n }\n files[filename] = { cid, type: file.type, size: file.size } as DocFileMeta\n }\n }\n // todo option to bypass this limit\n // if (totalSize > 1024 * 1024 * 1) throw new Error('Sync limit for files in a single update is 1MB')\n if (didPut.length) {\n const car = await dbBlockstore.loader?.commitFiles(t, { files } as unknown as TransactionMeta, {\n public: publicFiles\n })\n if (car) {\n for (const name of didPut) {\n files[name] = { car, ...files[name] } as DocFileMeta\n }\n }\n }\n}\n\nexport async function getValueFromCrdt(\n blocks: EncryptedBlockstore,\n head: ClockHead,\n key: string\n): Promise<DocValue> {\n if (!head.length) throw new Error('Getting from an empty database')\n const link = await get(blocks, head, key)\n if (!link) throw new Error(`Missing key ${key}`)\n return await getValueFromLink(blocks, link)\n}\n\nexport function readFiles(blocks: EncryptedBlockstore, { doc }: DocValue) {\n if (!doc) return\n if (doc._files) {\n readFileset(blocks, doc._files)\n }\n if (doc._publicFiles) {\n readFileset(blocks, doc._publicFiles, true)\n }\n}\n\nfunction readFileset(blocks: EncryptedBlockstore, files: DocFiles, isPublic = false) {\n for (const filename in files) {\n const fileMeta = files[filename] as DocFileMeta\n if (fileMeta.cid) {\n if (isPublic) {\n fileMeta.url = `https://${fileMeta.cid.toString()}.ipfs.w3s.link/`\n }\n if (fileMeta.car) {\n fileMeta.file = async () =>\n await decodeFile(\n {\n get: async (cid: AnyLink) => {\n return await blocks.getFile(fileMeta.car!, cid, isPublic)\n }\n },\n fileMeta.cid,\n fileMeta\n )\n }\n }\n files[filename] = fileMeta\n }\n}\n\nasync function getValueFromLink(blocks: BlockFetcher, link: AnyLink): Promise<DocValue> {\n const block = await blocks.get(link)\n if (!block) throw new Error(`Missing linked block ${link.toString()}`)\n const { value } = (await decode({ bytes: block.bytes, hasher, codec })) as { value: DocValue }\n readFiles(blocks as EncryptedBlockstore, value)\n return value\n}\n\nclass DirtyEventFetcher<T> extends EventFetcher<T> {\n // @ts-ignore\n async get(link) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return await super.get(link)\n } catch (e) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n console.error('missing event', link.toString(), e)\n return { value: null }\n }\n }\n}\n\nexport async function clockChangesSince(\n blocks: BlockFetcher,\n head: ClockHead,\n since: ClockHead,\n opts: ChangesOptions\n): Promise<{ result: DocUpdate[]; head: ClockHead }> {\n const eventsFetcher = (\n opts.dirty ? new DirtyEventFetcher<Operation>(blocks) : new EventFetcher<Operation>(blocks)\n ) as EventFetcher<Operation>\n const keys: Set<string> = new Set()\n const updates = await gatherUpdates(\n blocks,\n eventsFetcher,\n head,\n since,\n [],\n keys,\n new Set<string>(),\n opts.limit || Infinity\n )\n return { result: updates.reverse(), head }\n}\n\nasync function gatherUpdates(\n blocks: BlockFetcher,\n eventsFetcher: EventFetcher<Operation>,\n head: ClockHead,\n since: ClockHead,\n updates: DocUpdate[] = [],\n keys: Set<string>,\n didLinks: Set<string>,\n limit: number\n): Promise<DocUpdate[]> {\n if (limit <= 0) return updates\n // if (Math.random() < 0.001) console.log('gatherUpdates', head.length, since.length, updates.length)\n const sHead = head.map(l => l.toString())\n for (const link of since) {\n if (sHead.includes(link.toString())) {\n return updates\n }\n }\n for (const link of head) {\n if (didLinks.has(link.toString())) continue\n didLinks.add(link.toString())\n const { value: event } = await eventsFetcher.get(link)\n if (!event) continue\n const { type } = event.data\n let ops = [] as PutOperation[]\n if (type === 'batch') {\n ops = event.data.ops as PutOperation[]\n } else if (type === 'put') {\n ops = [event.data] as PutOperation[]\n }\n for (let i = ops.length - 1; i >= 0; i--) {\n const { key, value } = ops[i];\n if (!keys.has(key)) {\n // todo option to see all updates\n const docValue = await getValueFromLink(blocks, value)\n updates.push({ key, value: docValue.doc, del: docValue.del, clock: link })\n limit--\n keys.add(key)\n }\n }\n if (event.parents) {\n updates = await gatherUpdates(\n blocks,\n eventsFetcher,\n event.parents,\n since,\n updates,\n keys,\n didLinks,\n limit\n )\n }\n }\n return updates\n}\n\nexport async function* getAllEntries(blocks: BlockFetcher, head: ClockHead) {\n // return entries(blocks, head)\n for await (const [key, link] of entries(blocks, head)) {\n const docValue = await getValueFromLink(blocks, link)\n yield { key, value: docValue.doc, del: docValue.del } as DocUpdate\n }\n}\n\nexport async function* clockVis(blocks: EncryptedBlockstore, head: ClockHead) {\n for await (const line of vis(blocks, head)) {\n yield line\n }\n}\n\nlet isCompacting = false\nexport async function doCompact(blockLog: CompactionFetcher, head: ClockHead) {\n if (isCompacting) {\n console.log('already compacting')\n return\n }\n isCompacting = true\n\n time('compact head')\n for (const cid of head) {\n const bl = await blockLog.get(cid)\n if (!bl) throw new Error('Missing head block: ' + cid.toString())\n }\n timeEnd('compact head')\n\n // for await (const blk of blocks.entries()) {\n // const bl = await blockLog.get(blk.cid)\n // if (!bl) throw new Error('Missing tblock: ' + blk.cid.toString())\n // }\n\n // todo maybe remove\n // for await (const blk of blocks.loader!.entries()) {\n // const bl = await blockLog.get(blk.cid)\n // if (!bl) throw new Error('Missing db block: ' + blk.cid.toString())\n // }\n\n time('compact all entries')\n for await (const _entry of getAllEntries(blockLog, head)) {\n // result.push(entry)\n void 1\n }\n timeEnd('compact all entries')\n\n // time(\"compact crdt entries\")\n // for await (const [, link] of entries(blockLog, head)) {\n // const bl = await blockLog.get(link)\n // if (!bl) throw new Error('Missing entry block: ' + link.toString())\n // }\n // timeEnd(\"compact crdt entries\")\n\n time('compact clock vis')\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n for await (const _line of vis(blockLog, head)) {\n void 1\n }\n timeEnd('compact clock vis')\n\n time('compact root')\n const result = await root(blockLog, head)\n timeEnd('compact root')\n\n time('compact root blocks')\n for (const { cid, bytes } of [...result.additions, ...result.removals]) {\n blockLog.loggedBlocks.putSync(cid, bytes)\n }\n timeEnd('compact root blocks')\n\n time('compact changes')\n await clockChangesSince(blockLog, head, [], {})\n timeEnd('compact changes')\n\n isCompacting = false\n}\n\nexport async function getBlock(blocks: BlockFetcher, cidString: string) {\n const block = await blocks.get(parse(cidString))\n if (!block) throw new Error(`Missing block ${cidString}`)\n const { cid, value } = await decode({ bytes: block.bytes, codec, hasher })\n return new Block({ cid, value, bytes: block.bytes })\n}\n","// from https://github.com/web3-storage/w3up/blob/main/packages/upload-client/src/unixfs.js#L165\nimport * as UnixFS from '@ipld/unixfs'\nimport * as raw from 'multiformats/codecs/raw'\nimport { withMaxChunkSize } from '@ipld/unixfs/file/chunker/fixed'\nimport { withWidth } from '@ipld/unixfs/file/layout/balanced'\n\nimport type { View } from '@ipld/unixfs'\nimport { AnyBlock, AnyLink, DocFileMeta } from './types'\n// import type { Block } from 'multiformats/dist/types/src/block'\n\nimport { exporter, ReadableStorage } from 'ipfs-unixfs-exporter'\n\n// /** @param {import('@ipld/unixfs').View} writer */\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\nconst queuingStrategy = UnixFS.withCapacity()\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\nconst settings = UnixFS.configure({\n fileChunkEncoder: raw,\n smallFileEncoder: raw,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n chunker: withMaxChunkSize(1024 * 1024),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n fileLayout: withWidth(1024)\n})\n\nexport async function encodeFile(blob: BlobLike): Promise<{ cid: AnyLink; blocks: AnyBlock[] }> {\n const readable = createFileEncoderStream(blob)\n const blocks = await collect(readable)\n return { cid: blocks.at(-1).cid, blocks }\n}\n\nexport async function decodeFile(blocks: unknown, cid: AnyLink, meta: DocFileMeta): Promise<File> {\n const entry = await exporter(cid.toString(), blocks as ReadableStorage, { length: meta.size })\n const chunks = []\n for await (const chunk of entry.content()) chunks.push(chunk as Buffer)\n return new File(chunks, entry.name, { type: meta.type, lastModified: 0 })\n}\n\nfunction createFileEncoderStream(blob: BlobLike) {\n /** @type {TransformStream<import('@ipld/unixfs').Block, import('@ipld/unixfs').Block>} */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n const { readable, writable } = new TransformStream({}, queuingStrategy)\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n const unixfsWriter = UnixFS.createWriter({ writable, settings })\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n const fileBuilder = new UnixFSFileBuilder('', blob)\n void (async () => {\n await fileBuilder.finalize(unixfsWriter)\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n await unixfsWriter.close()\n })()\n return readable\n}\n\nasync function collect<T>(collectable: ReadableStream<T>): Promise<T[]> {\n // /** @type {T[]} */\n const chunks: T[] = []\n await collectable.pipeTo(\n new WritableStream({\n write(chunk) {\n chunks.push(chunk)\n }\n })\n )\n return chunks\n}\n\nclass UnixFSFileBuilder {\n #file\n name: string\n constructor(name: string, file: BlobLike) {\n this.name = name\n this.#file = file\n }\n\n async finalize(writer: View) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n const unixfsFileWriter = UnixFS.createFileWriter(writer)\n await this.#file.stream().pipeTo(\n new WritableStream({\n async write(chunk) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n await unixfsFileWriter.write(chunk as Uint8Array)\n }\n })\n )\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n return await unixfsFileWriter.close()\n }\n}\n\n// ts-unused-exports:disable-next-line\nexport interface BlobLike {\n /**\n * Returns a ReadableStream which yields the Blob data.\n */\n stream: () => ReadableStream\n}\n","import type { Block, Link } from 'multiformats'\nimport { create } from 'multiformats/block'\nimport { sha256 as hasher } from 'multiformats/hashes/sha2'\nimport * as codec from '@ipld/dag-cbor'\n\n// @ts-ignore\nimport charwise from 'charwise'\n// @ts-ignore\nimport * as DbIndex from 'prolly-trees/db-index'\n// @ts-ignore\nimport { bf, simpleCompare } from 'prolly-trees/utils'\n// @ts-ignore\nimport { nocache as cache } from 'prolly-trees/cache'\n// @ts-ignore\nimport { ProllyNode as BaseNode } from 'prolly-trees/base'\n\nimport { AnyLink, DocUpdate, MapFn, DocFragment, IndexKey, IndexUpdate, QueryOpts, IndexRow, AnyBlock, Doc, DocRecord } from './types'\nimport { CarTransaction, BlockFetcher } from '@fireproof/encrypted-blockstore'\nimport { CRDT } from './crdt'\n\nexport class IndexTree {\n cid: AnyLink | null = null\n root: ProllyNode | null = null\n}\n\ntype CompareRef = string | number\ntype CompareKey = [string | number, CompareRef]\n\nconst refCompare = (aRef: CompareRef, bRef: CompareRef) => {\n if (Number.isNaN(aRef)) return -1\n if (Number.isNaN(bRef)) throw new Error('ref may not be Infinity or NaN')\n if (aRef === Infinity) return 1\n // if (!Number.isFinite(bRef)) throw new Error('ref may not be Infinity or NaN')\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n return simpleCompare(aRef, bRef) as number\n}\n\nconst compare = (a: CompareKey, b: CompareKey) => {\n const [aKey, aRef] = a\n const [bKey, bRef] = b\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n const comp: number = simpleCompare(aKey, bKey)\n if (comp !== 0) return comp\n return refCompare(aRef, bRef)\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\nexport const byKeyOpts: StaticProllyOptions = { cache, chunker: bf(30), codec, hasher, compare }\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\nexport const byIdOpts: StaticProllyOptions = { cache, chunker: bf(30), codec, hasher, compare: simpleCompare }\n\nexport function indexEntriesForChanges(\n changes: DocUpdate[],\n mapFn: MapFn\n): { key: [string, string]; value: DocFragment }[] {\n const indexEntries: { key: [string, string]; value: DocFragment }[] = []\n changes.forEach(({ key: _id, value, del }) => {\n if (del || !value) return\n let mapCalled = false\n const mapReturn = mapFn({ _id, ...value }, (k: DocFragment, v?: DocFragment) => {\n mapCalled = true\n if (typeof k === 'undefined') return\n indexEntries.push({\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n key: [charwise.encode(k) as string, _id],\n value: v || null\n })\n })\n if (!mapCalled && mapReturn) {\n indexEntries.push({\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n key: [charwise.encode(mapReturn) as string, _id],\n value: null\n })\n }\n })\n return indexEntries\n}\n\nfunction makeProllyGetBlock(blocks: BlockFetcher): (address: AnyLink) => Promise<AnyBlock> {\n return async (address: AnyLink) => {\n const block = await blocks.get(address)\n if (!block) throw new Error(`Missing block ${address.toString()}`)\n const { cid, bytes } = block\n return create({ cid, bytes, hasher, codec }) as Promise<AnyBlock>\n }\n}\n\nexport async function bulkIndex(tblocks: CarTransaction, inIndex: IndexTree, indexEntries: IndexUpdate[], opts: StaticProllyOptions): Promise<IndexTree> {\n if (!indexEntries.length) return inIndex\n if (!inIndex.root) {\n if (!inIndex.cid) {\n let returnRootBlock: Block | null = null\n let returnNode: ProllyNode | null = null\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n for await (const node of await DbIndex.create({ get: makeProllyGetBlock(tblocks), list: indexEntries, ...opts }) as ProllyNode[]) {\n const block = await node.block\n await tblocks.put(block.cid, block.bytes)\n returnRootBlock = block\n returnNode = node\n }\n if (!returnNode || !returnRootBlock) throw new Error('failed to create index')\n return { root: returnNode, cid: returnRootBlock.cid }\n } else {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n inIndex.root = await DbIndex.load({ cid: inIndex.cid, get: makeProllyGetBlock(tblocks), ...opts }) as ProllyNode\n }\n }\n const { root, blocks: newBlocks } = await inIndex.root.bulk(indexEntries)\n if (root) {\n for await (const block of newBlocks) {\n await tblocks.put(block.cid, block.bytes)\n }\n return { root, cid: (await root.block).cid }\n } else {\n return { root: null, cid: null }\n }\n}\n\nexport async function loadIndex(tblocks: BlockFetcher, cid: AnyLink, opts: StaticProllyOptions): Promise<ProllyNode> {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n return await DbIndex.load({ cid, get: makeProllyGetBlock(tblocks), ...opts }) as ProllyNode\n}\n\nexport async function applyQuery<T extends DocRecord<T> = {}>(crdt: CRDT, resp: { result: IndexRow<T>[] }, query: QueryOpts) {\n if (query.descending) {\n resp.result = resp.result.reverse()\n }\n if (query.limit) {\n resp.result = resp.result.slice(0, query.limit)\n }\n if (query.includeDocs) {\n resp.result = await Promise.all(\n resp.result.map(async row => {\n const val = await crdt.get(row.id)\n const doc = val ? ({ _id: row.id, ...val.doc } as Doc<T>) : null\n return { ...row, doc }\n })\n )\n }\n return {\n rows: resp.result.map(row => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n row.key = (charwise.decode(row.key) as IndexKey)\n if (row.row && !row.value) {\n row.value = row.row\n delete row.row\n }\n return row\n })\n }\n}\n\nexport function encodeRange(range: [DocFragment, DocFragment]): [IndexKey, IndexKey] {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n return range.map(key => charwise.encode(key) as IndexKey) as [IndexKey, IndexKey]\n}\n\nexport function encodeKey(key: DocFragment): string {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n return charwise.encode(key) as string\n}\n\n// ProllyNode type based on the ProllyNode from 'prolly-trees/base'\ninterface ProllyNode extends BaseNode {\n getAllEntries<T extends DocRecord<T> = {}>(): PromiseLike<{ [x: string]: any; result: IndexRow<T>[] }>\n getMany(removeIds: string[]): Promise<{ [x: string]: any; result: IndexKey[] }>\n range<T extends DocRecord<T> = {}>(a: IndexKey, b: IndexKey): Promise<{ result: IndexRow<T>[] }>\n get<T extends DocRecord<T> = {}>(key: string): Promise<{ result: IndexRow<T>[] }>\n bulk(bulk: IndexUpdate[]): PromiseLike<{ root: ProllyNode | null; blocks: Block[] }>\n address: Promise<Link>\n distance: number\n compare: (a: any, b: any) => number\n cache: any\n block: Promise<Block>\n}\n\ninterface StaticProllyOptions {\n cache: any\n chunker: (entry: any, distance: number) => boolean\n codec: any\n hasher: any\n compare: (a: any, b: any) => number\n}\n","import type {\n ClockHead,\n DocUpdate,\n MapFn,\n IndexUpdate,\n QueryOpts,\n IdxMeta,\n DocFragment,\n IdxMetaMap,\n IndexRow,\n Doc,\n DocRecord,\n} from './types'\nimport { EncryptedBlockstore, TransactionMeta } from '@fireproof/encrypted-blockstore'\nimport {\n bulkIndex,\n indexEntriesForChanges,\n byIdOpts,\n byKeyOpts,\n IndexTree,\n applyQuery,\n encodeRange,\n encodeKey,\n loadIndex\n} from './indexer-helpers'\nimport { CRDT } from './crdt'\n\nexport function index(\n { _crdt }: { _crdt: CRDT },\n name: string,\n mapFn?: MapFn,\n meta?: IdxMeta\n): Index {\n if (mapFn && meta) throw new Error('cannot provide both mapFn and meta')\n if (mapFn && mapFn.constructor.name !== 'Function') throw new Error('mapFn must be a function')\n if (_crdt.indexers.has(name)) {\n const idx = _crdt.indexers.get(name)!\n idx.applyMapFn(name, mapFn, meta)\n } else {\n const idx = new Index(_crdt, name, mapFn, meta)\n _crdt.indexers.set(name, idx)\n }\n return _crdt.indexers.get(name)!\n}\n\nexport class Index {\n blockstore: EncryptedBlockstore\n crdt: CRDT\n name: string | null = null\n mapFn: MapFn | null = null\n mapFnString: string = ''\n byKey = new IndexTree()\n byId = new IndexTree()\n indexHead: ClockHead | undefined = undefined\n includeDocsDefault: boolean = false\n initError: Error | null = null\n ready: Promise<void>\n\n constructor(crdt: CRDT, name: string, mapFn?: MapFn, meta?: IdxMeta) {\n this.blockstore = crdt.indexBlockstore\n this.crdt = crdt\n this.applyMapFn(name, mapFn, meta)\n if (!(this.mapFnString || this.initError)) throw new Error('missing mapFnString')\n this.ready = this.blockstore.ready.then(() => {})\n // .then((header: IdxCarHeader) => {\n // // @ts-ignore\n // if (header.head) throw new Error('cannot have head in idx header')\n // if (header.indexes === undefined) throw new Error('missing indexes in idx header')\n // // for (const [name, idx] of Object.entries(header.indexes)) {\n // // index({ _crdt: crdt }, name, undefined, idx as IdxMeta)\n // // }\n // })\n }\n\n applyMapFn<T extends DocRecord<T> = {}>(name: string, mapFn?: MapFn, meta?: IdxMeta) {\n if (mapFn && meta) throw new Error('cannot provide both mapFn and meta')\n if (this.name && this.name !== name) throw new Error('cannot change name')\n this.name = name\n try {\n if (meta) {\n // hydrating from header\n if (\n this.indexHead &&\n this.indexHead.map(c => c.toString()).join() !== meta.head.map(c => c.toString()).join()\n ) {\n throw new Error('cannot apply meta to existing index')\n }\n\n if (this.mapFnString) {\n // we already initialized from application code\n if (this.mapFnString !== meta.map) {\n console.log(\n 'cannot apply different mapFn meta: old mapFnString',\n this.mapFnString,\n 'new mapFnString',\n meta.map\n )\n // throw new Error('cannot apply different mapFn meta')\n } else {\n this.byId.cid = meta.byId\n this.byKey.cid = meta.byKey\n this.indexHead = meta.head\n }\n } else {\n // we are first\n this.mapFnString = meta.map\n this.byId.cid = meta.byId\n this.byKey.cid = meta.byKey\n this.indexHead = meta.head\n }\n } else {\n if (this.mapFn) {\n // we already initialized from application code\n if (mapFn) {\n if (this.mapFn.toString() !== mapFn.toString())\n throw new Error('cannot apply different mapFn app2')\n }\n } else {\n // application code is creating an index\n if (!mapFn) {\n mapFn = (doc) => doc[name as keyof Doc<T>] ?? undefined\n }\n if (this.mapFnString) {\n // we already loaded from a header\n if (this.mapFnString !== mapFn.toString())\n throw new Error('cannot apply different mapFn app')\n } else {\n // we are first\n this.mapFnString = mapFn.toString()\n }\n this.mapFn = mapFn\n }\n }\n const matches = /=>\\s*(.*)/.test(this.mapFnString)\n this.includeDocsDefault = matches\n } catch (e) {\n this.initError = e as Error\n }\n }\n\n async query<T extends DocRecord<T> = {}>(opts: QueryOpts = {}): Promise<{ rows: IndexRow<T>[] }> {\n // this._resetIndex()\n await this._updateIndex()\n await this._hydrateIndex()\n if (!this.byKey.root) return await applyQuery(this.crdt, { result: [] }, opts)\n if (this.includeDocsDefault && opts.includeDocs === undefined) opts.includeDocs = true\n if (opts.range) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n const { result, ...all } = await this.byKey.root.range<T>(...encodeRange(opts.range))\n return await applyQuery(this.crdt, { result, ...all }, opts)\n }\n if (opts.key) {\n const encodedKey = encodeKey(opts.key)\n return await applyQuery(this.crdt, await this.byKey.root.get(encodedKey), opts)\n }\n if (Array.isArray(opts.keys)) {\n const results = await Promise.all(\n opts.keys.map(async (key: DocFragment) => {\n const encodedKey = encodeKey(key)\n return (await applyQuery(this.crdt, await this.byKey.root!.get<T>(encodedKey), opts)).rows\n })\n )\n return { rows: results.flat() }\n }\n if (opts.prefix) {\n if (!Array.isArray(opts.prefix)) opts.prefix = [opts.prefix]\n const start = [...opts.prefix, NaN]\n const end = [...opts.prefix, Infinity]\n const encodedR = encodeRange([start, end])\n return await applyQuery(this.crdt, await this.byKey.root.range(...encodedR), opts)\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n const { result, ...all } = await this.byKey.root.getAllEntries<T>() // funky return type\n return await applyQuery(\n this.crdt,\n {\n result: result.map(({ key: [k, id], value }) => ({ key: k, id, value })),\n ...all\n },\n opts\n )\n }\n\n _resetIndex() {\n this.byId = new IndexTree()\n this.byKey = new IndexTree()\n this.indexHead = undefined\n }\n\n async _hydrateIndex() {\n if (this.byId.root && this.byKey.root) return\n if (!this.byId.cid || !this.byKey.cid) return\n this.byId.root = await loadIndex(this.blockstore, this.byId.cid, byIdOpts)\n this.byKey.root = await loadIndex(this.blockstore, this.byKey.cid, byKeyOpts)\n }\n\n async _updateIndex() {\n await this.ready\n if (this.initError) throw this.initError\n if (!this.mapFn) throw new Error('No map function defined')\n let result: DocUpdate[], head: ClockHead\n if (!this.indexHead || this.indexHead.length === 0) {\n ;({ result, head } = await this.crdt.allDocs())\n } else {\n ;({ result, head } = await this.crdt.changes(this.indexHead))\n }\n if (result.length === 0) {\n this.indexHead = head\n return { byId: this.byId, byKey: this.byKey }\n }\n let staleKeyIndexEntries: IndexUpdate[] = []\n let removeIdIndexEntries: IndexUpdate[] = []\n if (this.byId.root) {\n const removeIds = result.map(({ key }) => key)\n const { result: oldChangeEntries } = (await this.byId.root.getMany(removeIds)) as {\n result: Array<[string, string] | string>\n }\n staleKeyIndexEntries = oldChangeEntries.map(key => ({ key, del: true }))\n removeIdIndexEntries = oldChangeEntries.map(key => ({ key: key[1], del: true }))\n }\n const indexEntries = indexEntriesForChanges(result, this.mapFn) // use a getter to translate from string\n const byIdIndexEntries: DocUpdate[] = indexEntries.map(({ key }) => ({\n key: key[1],\n value: key\n }))\n const indexerMeta: IdxMetaMap = {indexes: new Map()}\n\n for (const [name, indexer] of this.crdt.indexers) {\n if (indexer.indexHead) {\n indexerMeta.indexes.set(name, {\n byId: indexer.byId.cid,\n byKey: indexer.byKey.cid,\n head: indexer.indexHead,\n map: indexer.mapFnString,\n name: indexer.name\n } as IdxMeta)\n }\n }\n return await this.blockstore.transaction(async (tblocks): Promise<TransactionMeta> => {\n this.byId = await bulkIndex(\n tblocks,\n this.byId,\n removeIdIndexEntries.concat(byIdIndexEntries),\n byIdOpts\n )\n this.byKey = await bulkIndex(\n tblocks,\n this.byKey,\n staleKeyIndexEntries.concat(indexEntries),\n byKeyOpts\n )\n this.indexHead = head\n const idxMeta = {\n byId: this.byId.cid,\n byKey: this.byKey.cid,\n head,\n map: this.mapFnString,\n name: this.name\n } as IdxMeta\n indexerMeta.indexes.set(this.name!, idxMeta) // should this move to after commit?\n return indexerMeta as unknown as TransactionMeta\n })\n }\n}\n","import { clockChangesSince } from './crdt-helpers'\nimport type { EncryptedBlockstore, CarTransaction } from '@fireproof/encrypted-blockstore'\nimport type { DocUpdate, ClockHead } from './types'\nimport { advance } from '@web3-storage/pail/clock'\nimport { root } from '@web3-storage/pail/crdt'\nimport { applyHeadQueue, ApplyHeadQueue } from './apply-head-queue'\n\nexport class CRDTClock {\n // todo: track local and remote clocks independently, merge on read\n // that way we can drop the whole remote if we need to\n // should go with making sure the local clock only references locally available blockstore on write\n head: ClockHead = []\n\n zoomers: Set<() => void> = new Set()\n watchers: Set<(updates: DocUpdate[]) => void> = new Set()\n emptyWatchers: Set<() => void> = new Set()\n\n blockstore: EncryptedBlockstore | null = null\n\n applyHeadQueue: ApplyHeadQueue\n\n constructor() {\n this.applyHeadQueue = applyHeadQueue(this.int_applyHead.bind(this))\n }\n\n setHead(head: ClockHead) {\n this.head = head\n }\n\n async applyHead(newHead: ClockHead, prevHead: ClockHead, updates: DocUpdate[] | null = null) {\n for await (const { updates: updatesAcc, all } of this.applyHeadQueue.push({\n newHead,\n prevHead,\n updates\n })) {\n this.processUpdates(updatesAcc, all, prevHead)\n }\n }\n\n async processUpdates(updatesAcc: DocUpdate[], all: boolean, prevHead: ClockHead) {\n let internalUpdates = updatesAcc\n if (this.watchers.size && !all) {\n const changes = await clockChangesSince(this.blockstore!, this.head, prevHead, {})\n internalUpdates = changes.result\n }\n this.zoomers.forEach(fn => fn())\n this.notifyWatchers(internalUpdates || [])\n }\n\n notifyWatchers(updates: DocUpdate[]) {\n this.emptyWatchers.forEach(fn => fn())\n this.watchers.forEach(fn => fn(updates || []))\n }\n\n onTick(fn: (updates: DocUpdate[]) => void) {\n this.watchers.add(fn)\n }\n\n onTock(fn: () => void) {\n this.emptyWatchers.add(fn)\n }\n\n onZoom(fn: () => void) {\n this.zoomers.add(fn)\n }\n\n async int_applyHead(newHead: ClockHead, prevHead: ClockHead, localUpdates: boolean) {\n const ogHead = sortClockHead(this.head)\n newHead = sortClockHead(newHead)\n if (compareClockHeads(ogHead, newHead)) {\n return\n }\n const ogPrev = sortClockHead(prevHead)\n if (compareClockHeads(ogHead, ogPrev)) {\n this.setHead(newHead)\n return\n }\n let head = this.head\n const noLoader = !localUpdates\n // const noLoader = this.head.length === 1 && !updates?.length\n if (!this.blockstore) throw new Error('missing blockstore')\n await validateBlocks(newHead, this.blockstore)\n await this.blockstore.transaction(\n async (tblocks: CarTransaction) => {\n head = await advanceBlocks(newHead, tblocks, head)\n const result = await root(tblocks, head)\n for (const { cid, bytes } of [...result.additions, ...result.removals]) {\n tblocks.putSync(cid, bytes)\n }\n return { head }\n },\n { noLoader }\n )\n this.setHead(head)\n }\n}\n\n// Helper functions\nfunction sortClockHead(clockHead: ClockHead) {\n return clockHead.sort((a, b) => a.toString().localeCompare(b.toString()))\n}\n\nasync function validateBlocks(newHead: ClockHead, blockstore: EncryptedBlockstore | null) {\n newHead.map(async cid => {\n const got = await blockstore!.get(cid)\n if (!got) {\n throw new Error('int_applyHead missing block: ' + cid.toString())\n }\n })\n}\n\nfunction compareClockHeads(head1: ClockHead, head2: ClockHead) {\n return head1.toString() === head2.toString()\n}\n\nasync function advanceBlocks(newHead: ClockHead, tblocks: CarTransaction, head: ClockHead) {\n for (const cid of newHead) {\n try {\n head = await advance(tblocks, head, cid)\n } catch (e) {\n console.error('failed to advance', cid.toString(), e)\n continue\n }\n }\n return head\n}\n","import { ClockHead, DocUpdate } from './types'\n\ntype ApplyHeadWorkerFunction = (newHead: ClockHead, prevHead: ClockHead, localUpdates: boolean) => Promise<void>\n\ntype ApplyHeadTask = {\n newHead: ClockHead\n prevHead: ClockHead\n updates: DocUpdate[] | null\n}\n\nexport type ApplyHeadQueue = {\n push(task: ApplyHeadTask): AsyncGenerator<{ updates: DocUpdate[]; all: boolean }, void, unknown>\n}\n\nexport function applyHeadQueue(worker: ApplyHeadWorkerFunction): ApplyHeadQueue {\n const queue: ApplyHeadTask[] = []\n let isProcessing = false\n\n async function* process() {\n if (isProcessing || queue.length === 0) return\n isProcessing = true\n const allUpdates: DocUpdate[] = []\n try {\n while (queue.length > 0) {\n queue.sort((a, b) => (b.updates ? 1 : -1))\n const task = queue.shift()\n if (!task) continue\n\n await worker(task.newHead, task.prevHead, task.updates !== null)\n\n if (task.updates) {\n allUpdates.push(...task.updates)\n }\n // Yield the updates if there are no tasks with updates left in the queue or the current task has updates\n if (!queue.some(t => t.updates) || task.updates) {\n const allTasksHaveUpdates = queue.every(task => task.updates !== null)\n yield { updates: allUpdates, all: allTasksHaveUpdates }\n allUpdates.length = 0\n }\n }\n } finally {\n isProcessing = false\n const generator = process()\n let result = await generator.next()\n while (!result.done) {\n result = await generator.next()\n }\n }\n }\n\n return {\n push(\n task: ApplyHeadTask\n ): AsyncGenerator<{ updates: DocUpdate[]; all: boolean }, void, unknown> {\n queue.push(task)\n return process()\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAuB;;;ACQhB,SAAS,WAAW,QAAwB,UAAkB,UAAU,YAAqB,OAAmB;AACrH,QAAM,QAIA,CAAC;AACP,MAAI,eAAe;AAEnB,iBAAe,UAAU;AACvB,QAAI,gBAAgB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A,MAAM,oBAAoB;AACxB,QAAI,KAAK,oBAAoB,MAAM;AACjC,iBAAW,YAAY,KAAK,qBAAqB;AAC/C,eAAO,YAAY,MAAM,SAAS,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,MAAa;AAC3D,kBAAQ,MAAM,oBAAoB,CAAC;AAAA,QACrC,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;AAMO,SAAS,UAAU,MAAc,MAA6B;AACnE,MAAI,CAAC,SAAS,UAAU,IAAI,IAAI,GAAG;AACjC,aAAS,UAAU,IAAI,MAAM,IAAI,SAAS,MAAM,IAAI,CAAC;AAAA,EACvD;AACA,SAAO,SAAS,UAAU,IAAI,IAAI;AACpC;AAEA,SAAS,SAAS,UAAkB;AAClC,QAAM,QAAQ;AACd,MAAI,QAAgC;AACpC,QAAM,UAAU,MAAM,KAAK,SAAS,SAAS,KAAK,GAAG,WAAS,MAAM,CAAC,EAAE,KAAK,CAAC;AAC7E,MAAI,QAAQ,WAAW,GAAG;AACxB,YAAQ,YAAY,KAAK,QAAQ;AAAA,EACnC;AACA,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT,OAAO;AAEL,WAAO,MAAM,CAAC;AAAA,EAChB;AACF;","names":["index","import_encrypted_blockstore","hasher","import_block","import_sha2","codec","cache","hasher","charwise","root","result","all","import_clock","import_crdt","task","name","updates"]}
1
+ {"version":3,"sources":["../../src/fireproof.ts","../../src/database.ts","../../src/write-queue.ts","../../src/crdt.ts","../../src/eb-web.ts","../../src/crdt-helpers.ts","../../src/files.ts","../../src/indexer-helpers.ts","../../src/index.ts","../../src/crdt-clock.ts","../../src/apply-head-queue.ts"],"sourcesContent":["export * from './database'\nexport * from \"./types\"\n","import { uuidv7 } from 'uuidv7'\n\nimport { WriteQueue, writeQueue } from './write-queue'\nimport { CRDT } from './crdt'\nimport { index } from './index'\nimport type {\n CRDTMeta,\n DocUpdate,\n ClockHead,\n Doc,\n ConfigOpts,\n MapFn,\n QueryOpts,\n ChangesOptions,\n DocRecord\n} from './types'\nimport { DbResponse, ChangesResponse } from './types'\nimport { EncryptedBlockstore } from '@fireproof/encrypted-blockstore'\n\ntype DbName = string | null\n\nexport class Database {\n static databases: Map<string, Database> = new Map()\n\n name: DbName\n opts: ConfigOpts = {}\n\n _listening = false\n _listeners: Set<ListenerFn> = new Set()\n _noupdate_listeners: Set<ListenerFn> = new Set()\n _crdt: CRDT\n _writeQueue: WriteQueue\n blockstore: EncryptedBlockstore\n\n constructor(name?: string, opts?: ConfigOpts) {\n this.name = name || null\n this.opts = opts || this.opts\n this._crdt = new CRDT(name, this.opts)\n this.blockstore = this._crdt.blockstore // for connector compatibility\n this._writeQueue = writeQueue(async (updates: DocUpdate[]) => {\n return await this._crdt.bulk(updates)\n }) //, Infinity)\n this._crdt.clock.onTock(() => {\n this._no_update_notify()\n })\n }\n\n async get<T extends DocRecord<T> = {}>(id: string): Promise<Doc<T>> {\n const got = await this._crdt.get(id).catch(e => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n e.message = `Not found: ${id} - ` + e.message\n throw e\n })\n if (!got) throw new Error(`Not found: ${id}`)\n const { doc } = got\n return { _id: id, ...doc } as Doc<T>\n }\n\n async put<T extends DocRecord<T> = {}>(doc: Doc<T>): Promise<DbResponse> {\n const { _id, ...value } = doc\n const docId = _id || uuidv7()\n const result: CRDTMeta = await this._writeQueue.push({ key: docId, value } as DocUpdate)\n return { id: docId, clock: result?.head } as DbResponse\n }\n\n async del(id: string): Promise<DbResponse> {\n const result = await this._writeQueue.push({ key: id, del: true })\n return { id, clock: result?.head } as DbResponse\n }\n\n async changes<T extends DocRecord<T> = {}>(since: ClockHead = [], opts: ChangesOptions = {}): Promise<ChangesResponse<T>> {\n const { result, head } = await this._crdt.changes(since, opts)\n const rows = result.map(({ key, value, del, clock }) => ({\n key,\n value: (del ? { _id: key, _deleted: true } : { _id: key, ...value }) as Doc<T>,\n clock\n }))\n return { rows, clock: head }\n }\n\n async allDocs<T extends DocRecord<T> = {}>() {\n const { result, head } = await this._crdt.allDocs()\n const rows = result.map(({ key, value, del }) => ({\n key,\n value: (del ? { _id: key, _deleted: true } : { _id: key, ...value }) as Doc<T>\n }))\n return { rows, clock: head }\n }\n\n async allDocuments<T extends DocRecord<T> = {}>() {\n return this.allDocs<T>()\n }\n\n subscribe(listener: ListenerFn | NoUpdateListenerFn, updates?: boolean): () => void {\n if (updates) {\n if (!this._listening) {\n this._listening = true\n this._crdt.clock.onTick((updates: DocUpdate[]) => {\n void this._notify(updates)\n })\n }\n this._listeners.add(listener)\n return () => {\n this._listeners.delete(listener)\n }\n } else {\n this._noupdate_listeners.add(listener)\n return () => {\n this._noupdate_listeners.delete(listener)\n }\n }\n }\n\n // todo if we add this onto dbs in fireproof.ts then we can make index.ts a separate package\n async query<T extends DocRecord<T> = {}>(field: string | MapFn, opts: QueryOpts = {}) {\n const idx =\n typeof field === 'string'\n ? index({ _crdt: this._crdt }, field)\n : index({ _crdt: this._crdt }, makeName(field.toString()), field)\n return await idx.query<T>(opts)\n }\n\n async compact() {\n await this._crdt.compact()\n }\n\n async _notify(updates: DocUpdate[]) {\n if (this._listeners.size) {\n const docs: Doc[] = updates.map(({ key, value }) => ({ _id: key, ...value }))\n for (const listener of this._listeners) {\n await (async () => await listener(docs))().catch((e: Error) => {\n console.error('subscriber error', e)\n })\n }\n }\n }\n\n async _no_update_notify() {\n if (this._noupdate_listeners.size) {\n for (const listener of this._noupdate_listeners) {\n await (async () => await listener([]))().catch((e: Error) => {\n console.error('subscriber error', e)\n })\n }\n }\n }\n}\n\ntype UpdateListenerFn = <T extends DocRecord<T>>(docs: Doc<T>[]) => Promise<void> | void\ntype NoUpdateListenerFn = () => Promise<void> | void\ntype ListenerFn = UpdateListenerFn | NoUpdateListenerFn\n\nexport function fireproof(name: string, opts?: ConfigOpts): Database {\n if (!Database.databases.has(name)) {\n Database.databases.set(name, new Database(name, opts))\n }\n return Database.databases.get(name)!\n}\n\nfunction makeName(fnString: string) {\n const regex = /\\(([^,()]+,\\s*[^,()]+|\\[[^\\]]+\\],\\s*[^,()]+)\\)/g\n let found: RegExpExecArray | null = null\n const matches = Array.from(fnString.matchAll(regex), match => match[1].trim())\n if (matches.length === 0) {\n found = /=>\\s*(.*)/.exec(fnString)\n }\n if (!found) {\n return fnString\n } else {\n // it's a consise arrow function, match everything after the arrow\n return found[1]\n }\n}\n","import { CRDTMeta, DocUpdate } from './types'\n\ntype WorkerFunction = (tasks: DocUpdate[]) => Promise<CRDTMeta>;\n\nexport type WriteQueue = {\n push(task: DocUpdate): Promise<CRDTMeta>;\n};\n\nexport function writeQueue(worker: WorkerFunction, payload: number = Infinity, unbounded: boolean = false): WriteQueue {\n const queue: {\n task: DocUpdate;\n resolve: (result: CRDTMeta) => void;\n reject: (error: Error) => void;\n }[] = []\n let isProcessing = false\n\n async function process() {\n if (isProcessing || queue.length === 0) return\n isProcessing = true\n\n const tasksToProcess = queue.splice(0, payload)\n const updates = tasksToProcess.map(item => item.task)\n\n if (unbounded) {\n // Run all updates in parallel and resolve/reject them individually\n const promises = updates.map(async (update, index) => {\n try {\n const result = await worker([update])\n tasksToProcess[index].resolve(result)\n } catch (error) {\n tasksToProcess[index].reject(error as Error)\n }\n })\n\n await Promise.all(promises)\n } else {\n // Original logic: Run updates in a batch and resolve/reject them together\n try {\n const result = await worker(updates)\n tasksToProcess.forEach(task => task.resolve(result))\n } catch (error) {\n tasksToProcess.forEach(task => task.reject(error as Error))\n }\n }\n\n isProcessing = false\n void process()\n }\n\n return {\n push(task: DocUpdate): Promise<CRDTMeta> {\n return new Promise<CRDTMeta>((resolve, reject) => {\n queue.push({ task, resolve, reject })\n void process()\n })\n }\n }\n}\n","import {\n EncryptedBlockstore,\n type CompactionFetcher,\n type TransactionMeta,\n type CarTransaction\n} from '@fireproof/encrypted-blockstore'\n\nimport { store, crypto } from './eb-web'\n\nimport {\n clockChangesSince,\n applyBulkUpdateToCrdt,\n getValueFromCrdt,\n readFiles,\n getAllEntries,\n clockVis,\n getBlock,\n doCompact\n} from './crdt-helpers'\nimport type {\n DocUpdate,\n CRDTMeta,\n ClockHead,\n ConfigOpts,\n ChangesOptions,\n IdxMetaMap\n} from './types'\nimport { index, type Index } from './index'\nimport { CRDTClock } from './crdt-clock'\n\nexport class CRDT {\n name: string | null\n opts: ConfigOpts = {}\n ready: Promise<void>\n blockstore: EncryptedBlockstore\n indexBlockstore: EncryptedBlockstore\n\n indexers: Map<string, Index> = new Map()\n\n clock: CRDTClock = new CRDTClock()\n\n constructor(name?: string, opts?: ConfigOpts) {\n this.name = name || null\n this.opts = opts || this.opts\n this.blockstore = new EncryptedBlockstore({\n name,\n applyMeta: async (meta: TransactionMeta) => {\n const crdtMeta = meta as unknown as CRDTMeta\n await this.clock.applyHead(crdtMeta.head, [])\n },\n compact: async (blocks: CompactionFetcher) => {\n await doCompact(blocks, this.clock.head)\n return { head: this.clock.head } as TransactionMeta\n },\n autoCompact: this.opts.autoCompact || 100,\n crypto: this.opts.crypto || crypto,\n store: this.opts.store || store,\n public: this.opts.public,\n meta: this.opts.meta\n })\n this.clock.blockstore = this.blockstore\n this.indexBlockstore = new EncryptedBlockstore({\n name: this.opts.persistIndexes && this.name ? this.name + '.idx' : undefined,\n applyMeta: async (meta: TransactionMeta) => {\n const idxCarMeta = meta as unknown as IdxMetaMap\n for (const [name, idx] of Object.entries(idxCarMeta.indexes)) {\n index({ _crdt: this }, name, undefined, idx as any)\n }\n },\n crypto,\n public: this.opts.public,\n store\n })\n this.ready = Promise.all([this.blockstore.ready, this.indexBlockstore.ready]).then(() => {})\n this.clock.onZoom(() => {\n for (const idx of this.indexers.values()) {\n idx._resetIndex()\n }\n })\n }\n\n async bulk(updates: DocUpdate[]): Promise<CRDTMeta> {\n await this.ready\n const prevHead = [...this.clock.head]\n \n const meta = (await this.blockstore.transaction(\n async (blocks: CarTransaction): Promise<TransactionMeta> => {\n const { head } = await applyBulkUpdateToCrdt(blocks, this.clock.head, updates)\n updates = updates.map(({ key, value, del, clock }) => {\n readFiles(this.blockstore, { doc: value })\n return { key, value, del, clock }\n })\n return { head } as TransactionMeta\n }\n )) as CRDTMeta\n await this.clock.applyHead(meta.head, prevHead, updates)\n return meta\n }\n\n // if (snap) await this.clock.applyHead(crdtMeta.head, this.clock.head)\n\n async allDocs() {\n await this.ready\n const result: DocUpdate[] = []\n for await (const entry of getAllEntries(this.blockstore, this.clock.head)) {\n result.push(entry)\n }\n return { result, head: this.clock.head }\n }\n\n async vis() {\n await this.ready\n const txt: string[] = []\n for await (const line of clockVis(this.blockstore, this.clock.head)) {\n txt.push(line)\n }\n return txt.join('\\n')\n }\n\n async getBlock(cidString: string) {\n await this.ready\n return await getBlock(this.blockstore, cidString)\n }\n\n async get(key: string) {\n await this.ready\n const result = await getValueFromCrdt(this.blockstore, this.clock.head, key)\n if (result.del) return null\n return result\n }\n\n async changes(since: ClockHead = [], opts: ChangesOptions = {}) {\n await this.ready\n return await clockChangesSince(this.blockstore, this.clock.head, since, opts)\n }\n\n async compact() {\n return await this.blockstore.compact()\n }\n}\n","import { StoreOpts } from '@fireproof/encrypted-blockstore'\nimport * as crypto from '@fireproof/encrypted-blockstore/crypto-web'\nimport {\n makeDataStore,\n makeMetaStore,\n makeRemoteWAL\n} from '@fireproof/encrypted-blockstore/store-web'\n\nconst store = {\n makeDataStore,\n makeMetaStore,\n makeRemoteWAL\n} as StoreOpts\n\nexport { store, crypto }\n","import { encode, decode, Block } from 'multiformats/block'\nimport { parse } from 'multiformats/link'\nimport { sha256 as hasher } from 'multiformats/hashes/sha2'\nimport * as codec from '@ipld/dag-cbor'\nimport { put, get, entries, root } from '@web3-storage/pail/crdt'\nimport { Operation, PutOperation } from '@web3-storage/pail/src/crdt/api'\nimport { EventFetcher, vis } from '@web3-storage/pail/clock'\nimport * as Batch from '@web3-storage/pail/crdt/batch'\n\nimport {\n type EncryptedBlockstore,\n type CompactionFetcher,\n CarTransaction,\n TransactionMeta,\n BlockFetcher\n} from '@fireproof/encrypted-blockstore'\nimport type {\n DocUpdate,\n ClockHead,\n AnyLink,\n DocValue,\n CRDTMeta,\n ChangesOptions,\n Doc,\n DocFileMeta,\n DocFiles\n} from './types'\nimport { decodeFile, encodeFile } from './files'\nimport { Result } from '@web3-storage/pail/src/crdt/api'\n\nfunction time(tag: string) {\n // console.time(tag)\n}\n\nfunction timeEnd(tag: string) {\n // console.timeEnd(tag)\n}\n\nexport async function applyBulkUpdateToCrdt(\n tblocks: CarTransaction,\n head: ClockHead,\n updates: DocUpdate[]\n): Promise<CRDTMeta> {\n let result: Result | null = null\n // const batch = await Batch.create(tblocks, init.cid)\n // console.log('applyBulkUpdateToCrdt', updates.length)\n if (updates.length > 1) {\n // throw new Error('batch not implemented')\n const batch = await Batch.create(tblocks, head)\n for (const update of updates) {\n const link = await writeDocContent(tblocks, update)\n await batch.put(update.key, link)\n }\n result = await batch.commit()\n // console.log('batch result', result)\n } else {\n for (const update of updates) {\n const link = await writeDocContent(tblocks, update)\n result = await put(tblocks, head, update.key, link)\n const resRoot = result.root.toString()\n const isReturned = result.additions.some(a => a.cid.toString() === resRoot)\n if (!isReturned) {\n const hasRoot = await tblocks.get(result.root) // is a db-wide get\n if (!hasRoot) {\n throw new Error(\n `missing root in additions: ${result.additions.length} ${resRoot} keys: ${updates\n .map(u => u.key)\n .toString()}`\n )\n }\n }\n }\n }\n if (!result) throw new Error('Missing result')\n\n if (result.event) {\n for (const { cid, bytes } of [...result.additions, ...result.removals, result.event]) {\n tblocks.putSync(cid, bytes)\n }\n }\n return { head: result.head } as CRDTMeta\n}\n\n// this whole thing can get pulled outside of the write queue\nasync function writeDocContent(blocks: CarTransaction, update: DocUpdate): Promise<AnyLink> {\n let value: DocValue\n if (update.del) {\n value = { del: true }\n } else {\n await processFiles(blocks, update.value as Doc)\n value = { doc: update.value }\n }\n const block = await encode({ value, hasher, codec })\n blocks.putSync(block.cid, block.bytes)\n return block.cid\n}\n\nasync function processFiles(blocks: CarTransaction, doc: Doc) {\n if (doc._files) {\n await processFileset(blocks, doc._files)\n }\n if (doc._publicFiles) {\n await processFileset(blocks, doc._publicFiles, true)\n }\n}\n\nasync function processFileset(blocks: CarTransaction, files: DocFiles, publicFiles = false) {\n const dbBlockstore = blocks.parent\n const t = new CarTransaction(dbBlockstore) // maybe this should move to encrypted-blockstore\n const didPut = []\n // let totalSize = 0\n for (const filename in files) {\n if (File === files[filename].constructor) {\n const file = files[filename] as File\n\n // totalSize += file.size\n const { cid, blocks: fileBlocks } = await encodeFile(file)\n didPut.push(filename)\n for (const block of fileBlocks) {\n t.putSync(block.cid, block.bytes)\n }\n files[filename] = { cid, type: file.type, size: file.size } as DocFileMeta\n }\n }\n // todo option to bypass this limit\n // if (totalSize > 1024 * 1024 * 1) throw new Error('Sync limit for files in a single update is 1MB')\n if (didPut.length) {\n const car = await dbBlockstore.loader?.commitFiles(t, { files } as unknown as TransactionMeta, {\n public: publicFiles\n })\n if (car) {\n for (const name of didPut) {\n files[name] = { car, ...files[name] } as DocFileMeta\n }\n }\n }\n}\n\nexport async function getValueFromCrdt(\n blocks: EncryptedBlockstore,\n head: ClockHead,\n key: string\n): Promise<DocValue> {\n if (!head.length) throw new Error('Getting from an empty database')\n const link = await get(blocks, head, key)\n if (!link) throw new Error(`Missing key ${key}`)\n return await getValueFromLink(blocks, link)\n}\n\nexport function readFiles(blocks: EncryptedBlockstore, { doc }: DocValue) {\n if (!doc) return\n if (doc._files) {\n readFileset(blocks, doc._files)\n }\n if (doc._publicFiles) {\n readFileset(blocks, doc._publicFiles, true)\n }\n}\n\nfunction readFileset(blocks: EncryptedBlockstore, files: DocFiles, isPublic = false) {\n for (const filename in files) {\n const fileMeta = files[filename] as DocFileMeta\n if (fileMeta.cid) {\n if (isPublic) {\n fileMeta.url = `https://${fileMeta.cid.toString()}.ipfs.w3s.link/`\n }\n if (fileMeta.car) {\n fileMeta.file = async () =>\n await decodeFile(\n {\n get: async (cid: AnyLink) => {\n return await blocks.getFile(fileMeta.car!, cid, isPublic)\n }\n },\n fileMeta.cid,\n fileMeta\n )\n }\n }\n files[filename] = fileMeta\n }\n}\n\nasync function getValueFromLink(blocks: BlockFetcher, link: AnyLink): Promise<DocValue> {\n const block = await blocks.get(link)\n if (!block) throw new Error(`Missing linked block ${link.toString()}`)\n const { value } = (await decode({ bytes: block.bytes, hasher, codec })) as { value: DocValue }\n value.cid = link\n readFiles(blocks as EncryptedBlockstore, value)\n return value\n}\n\nclass DirtyEventFetcher<T> extends EventFetcher<T> {\n // @ts-ignore\n async get(link) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return await super.get(link)\n } catch (e) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n console.error('missing event', link.toString(), e)\n return { value: null }\n }\n }\n}\n\nexport async function clockChangesSince(\n blocks: BlockFetcher,\n head: ClockHead,\n since: ClockHead,\n opts: ChangesOptions\n): Promise<{ result: DocUpdate[]; head: ClockHead }> {\n const eventsFetcher = (\n opts.dirty ? new DirtyEventFetcher<Operation>(blocks) : new EventFetcher<Operation>(blocks)\n ) as EventFetcher<Operation>\n const keys: Set<string> = new Set()\n const updates = await gatherUpdates(\n blocks,\n eventsFetcher,\n head,\n since,\n [],\n keys,\n new Set<string>(),\n opts.limit || Infinity\n )\n return { result: updates.reverse(), head }\n}\n\nasync function gatherUpdates(\n blocks: BlockFetcher,\n eventsFetcher: EventFetcher<Operation>,\n head: ClockHead,\n since: ClockHead,\n updates: DocUpdate[] = [],\n keys: Set<string>,\n didLinks: Set<string>,\n limit: number\n): Promise<DocUpdate[]> {\n if (limit <= 0) return updates\n // if (Math.random() < 0.001) console.log('gatherUpdates', head.length, since.length, updates.length)\n const sHead = head.map(l => l.toString())\n for (const link of since) {\n if (sHead.includes(link.toString())) {\n return updates\n }\n }\n for (const link of head) {\n if (didLinks.has(link.toString())) continue\n didLinks.add(link.toString())\n const { value: event } = await eventsFetcher.get(link)\n if (!event) continue\n const { type } = event.data\n let ops = [] as PutOperation[]\n if (type === 'batch') {\n ops = event.data.ops as PutOperation[]\n } else if (type === 'put') {\n ops = [event.data] as PutOperation[]\n }\n for (let i = ops.length - 1; i >= 0; i--) {\n const { key, value } = ops[i];\n if (!keys.has(key)) {\n // todo option to see all updates\n const docValue = await getValueFromLink(blocks, value)\n updates.push({ key, value: docValue.doc, del: docValue.del, clock: link })\n limit--\n keys.add(key)\n }\n }\n if (event.parents) {\n updates = await gatherUpdates(\n blocks,\n eventsFetcher,\n event.parents,\n since,\n updates,\n keys,\n didLinks,\n limit\n )\n }\n }\n return updates\n}\n\nexport async function* getAllEntries(blocks: BlockFetcher, head: ClockHead) {\n // return entries(blocks, head)\n for await (const [key, link] of entries(blocks, head)) {\n const docValue = await getValueFromLink(blocks, link)\n yield { key, value: docValue.doc, del: docValue.del } as DocUpdate\n }\n}\n\nexport async function* clockVis(blocks: EncryptedBlockstore, head: ClockHead) {\n for await (const line of vis(blocks, head)) {\n yield line\n }\n}\n\nlet isCompacting = false\nexport async function doCompact(blockLog: CompactionFetcher, head: ClockHead) {\n if (isCompacting) {\n console.log('already compacting')\n return\n }\n isCompacting = true\n\n time('compact head')\n for (const cid of head) {\n const bl = await blockLog.get(cid)\n if (!bl) throw new Error('Missing head block: ' + cid.toString())\n }\n timeEnd('compact head')\n\n // for await (const blk of blocks.entries()) {\n // const bl = await blockLog.get(blk.cid)\n // if (!bl) throw new Error('Missing tblock: ' + blk.cid.toString())\n // }\n\n // todo maybe remove\n // for await (const blk of blocks.loader!.entries()) {\n // const bl = await blockLog.get(blk.cid)\n // if (!bl) throw new Error('Missing db block: ' + blk.cid.toString())\n // }\n\n time('compact all entries')\n for await (const _entry of getAllEntries(blockLog, head)) {\n // result.push(entry)\n void 1\n }\n timeEnd('compact all entries')\n\n // time(\"compact crdt entries\")\n // for await (const [, link] of entries(blockLog, head)) {\n // const bl = await blockLog.get(link)\n // if (!bl) throw new Error('Missing entry block: ' + link.toString())\n // }\n // timeEnd(\"compact crdt entries\")\n\n time('compact clock vis')\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n for await (const _line of vis(blockLog, head)) {\n void 1\n }\n timeEnd('compact clock vis')\n\n time('compact root')\n const result = await root(blockLog, head)\n timeEnd('compact root')\n\n time('compact root blocks')\n for (const { cid, bytes } of [...result.additions, ...result.removals]) {\n blockLog.loggedBlocks.putSync(cid, bytes)\n }\n timeEnd('compact root blocks')\n\n time('compact changes')\n await clockChangesSince(blockLog, head, [], {})\n timeEnd('compact changes')\n\n isCompacting = false\n}\n\nexport async function getBlock(blocks: BlockFetcher, cidString: string) {\n const block = await blocks.get(parse(cidString))\n if (!block) throw new Error(`Missing block ${cidString}`)\n const { cid, value } = await decode({ bytes: block.bytes, codec, hasher })\n return new Block({ cid, value, bytes: block.bytes })\n}\n","// from https://github.com/web3-storage/w3up/blob/main/packages/upload-client/src/unixfs.js#L165\nimport * as UnixFS from '@ipld/unixfs'\nimport * as raw from 'multiformats/codecs/raw'\nimport { withMaxChunkSize } from '@ipld/unixfs/file/chunker/fixed'\nimport { withWidth } from '@ipld/unixfs/file/layout/balanced'\n\nimport type { View } from '@ipld/unixfs'\nimport { AnyBlock, AnyLink, DocFileMeta } from './types'\n// import type { Block } from 'multiformats/dist/types/src/block'\n\nimport { exporter, ReadableStorage } from 'ipfs-unixfs-exporter'\n\n// /** @param {import('@ipld/unixfs').View} writer */\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\nconst queuingStrategy = UnixFS.withCapacity()\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\nconst settings = UnixFS.configure({\n fileChunkEncoder: raw,\n smallFileEncoder: raw,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n chunker: withMaxChunkSize(1024 * 1024),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n fileLayout: withWidth(1024)\n})\n\nexport async function encodeFile(blob: BlobLike): Promise<{ cid: AnyLink; blocks: AnyBlock[] }> {\n const readable = createFileEncoderStream(blob)\n const blocks = await collect(readable)\n return { cid: blocks.at(-1).cid, blocks }\n}\n\nexport async function decodeFile(blocks: unknown, cid: AnyLink, meta: DocFileMeta): Promise<File> {\n const entry = await exporter(cid.toString(), blocks as ReadableStorage, { length: meta.size })\n const chunks = []\n for await (const chunk of entry.content()) chunks.push(chunk as Buffer)\n return new File(chunks, entry.name, { type: meta.type, lastModified: 0 })\n}\n\nfunction createFileEncoderStream(blob: BlobLike) {\n /** @type {TransformStream<import('@ipld/unixfs').Block, import('@ipld/unixfs').Block>} */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n const { readable, writable } = new TransformStream({}, queuingStrategy)\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n const unixfsWriter = UnixFS.createWriter({ writable, settings })\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n const fileBuilder = new UnixFSFileBuilder('', blob)\n void (async () => {\n await fileBuilder.finalize(unixfsWriter)\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n await unixfsWriter.close()\n })()\n return readable\n}\n\nasync function collect<T>(collectable: ReadableStream<T>): Promise<T[]> {\n // /** @type {T[]} */\n const chunks: T[] = []\n await collectable.pipeTo(\n new WritableStream({\n write(chunk) {\n chunks.push(chunk)\n }\n })\n )\n return chunks\n}\n\nclass UnixFSFileBuilder {\n #file\n name: string\n constructor(name: string, file: BlobLike) {\n this.name = name\n this.#file = file\n }\n\n async finalize(writer: View) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n const unixfsFileWriter = UnixFS.createFileWriter(writer)\n await this.#file.stream().pipeTo(\n new WritableStream({\n async write(chunk) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n await unixfsFileWriter.write(chunk as Uint8Array)\n }\n })\n )\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n return await unixfsFileWriter.close()\n }\n}\n\n\nexport interface BlobLike {\n /**\n * Returns a ReadableStream which yields the Blob data.\n */\n stream: () => ReadableStream\n}\n","import type { Block, Link } from 'multiformats'\nimport { create } from 'multiformats/block'\nimport { sha256 as hasher } from 'multiformats/hashes/sha2'\nimport * as codec from '@ipld/dag-cbor'\n\n// @ts-ignore\nimport charwise from 'charwise'\n// @ts-ignore\nimport * as DbIndex from 'prolly-trees/db-index'\n// @ts-ignore\nimport { bf, simpleCompare } from 'prolly-trees/utils'\n// @ts-ignore\nimport { nocache as cache } from 'prolly-trees/cache'\n// @ts-ignore\nimport { ProllyNode as BaseNode } from 'prolly-trees/base'\n\nimport { AnyLink, DocUpdate, MapFn, DocFragment, IndexKey, IndexUpdate, QueryOpts, IndexRow, AnyBlock, Doc, DocRecord } from './types'\nimport { CarTransaction, BlockFetcher } from '@fireproof/encrypted-blockstore'\nimport { CRDT } from './crdt'\n\nexport class IndexTree {\n cid: AnyLink | null = null\n root: ProllyNode | null = null\n}\n\ntype CompareRef = string | number\ntype CompareKey = [string | number, CompareRef]\n\nconst refCompare = (aRef: CompareRef, bRef: CompareRef) => {\n if (Number.isNaN(aRef)) return -1\n if (Number.isNaN(bRef)) throw new Error('ref may not be Infinity or NaN')\n if (aRef === Infinity) return 1\n // if (!Number.isFinite(bRef)) throw new Error('ref may not be Infinity or NaN')\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n return simpleCompare(aRef, bRef) as number\n}\n\nconst compare = (a: CompareKey, b: CompareKey) => {\n const [aKey, aRef] = a\n const [bKey, bRef] = b\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n const comp: number = simpleCompare(aKey, bKey)\n if (comp !== 0) return comp\n return refCompare(aRef, bRef)\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\nexport const byKeyOpts: StaticProllyOptions = { cache, chunker: bf(30), codec, hasher, compare }\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\nexport const byIdOpts: StaticProllyOptions = { cache, chunker: bf(30), codec, hasher, compare: simpleCompare }\n\nexport function indexEntriesForChanges(\n changes: DocUpdate[],\n mapFn: MapFn\n): { key: [string, string]; value: DocFragment }[] {\n const indexEntries: { key: [string, string]; value: DocFragment }[] = []\n changes.forEach(({ key: _id, value, del }) => {\n if (del || !value) return\n let mapCalled = false\n const mapReturn = mapFn({ _id, ...value }, (k: DocFragment, v?: DocFragment) => {\n mapCalled = true\n if (typeof k === 'undefined') return\n indexEntries.push({\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n key: [charwise.encode(k) as string, _id],\n value: v || null\n })\n })\n if (!mapCalled && mapReturn) {\n indexEntries.push({\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n key: [charwise.encode(mapReturn) as string, _id],\n value: null\n })\n }\n })\n return indexEntries\n}\n\nfunction makeProllyGetBlock(blocks: BlockFetcher): (address: AnyLink) => Promise<AnyBlock> {\n return async (address: AnyLink) => {\n const block = await blocks.get(address)\n if (!block) throw new Error(`Missing block ${address.toString()}`)\n const { cid, bytes } = block\n return create({ cid, bytes, hasher, codec }) as Promise<AnyBlock>\n }\n}\n\nexport async function bulkIndex(tblocks: CarTransaction, inIndex: IndexTree, indexEntries: IndexUpdate[], opts: StaticProllyOptions): Promise<IndexTree> {\n if (!indexEntries.length) return inIndex\n if (!inIndex.root) {\n if (!inIndex.cid) {\n let returnRootBlock: Block | null = null\n let returnNode: ProllyNode | null = null\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n for await (const node of await DbIndex.create({ get: makeProllyGetBlock(tblocks), list: indexEntries, ...opts }) as ProllyNode[]) {\n const block = await node.block\n await tblocks.put(block.cid, block.bytes)\n returnRootBlock = block\n returnNode = node\n }\n if (!returnNode || !returnRootBlock) throw new Error('failed to create index')\n return { root: returnNode, cid: returnRootBlock.cid }\n } else {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n inIndex.root = await DbIndex.load({ cid: inIndex.cid, get: makeProllyGetBlock(tblocks), ...opts }) as ProllyNode\n }\n }\n const { root, blocks: newBlocks } = await inIndex.root.bulk(indexEntries)\n if (root) {\n for await (const block of newBlocks) {\n await tblocks.put(block.cid, block.bytes)\n }\n return { root, cid: (await root.block).cid }\n } else {\n return { root: null, cid: null }\n }\n}\n\nexport async function loadIndex(tblocks: BlockFetcher, cid: AnyLink, opts: StaticProllyOptions): Promise<ProllyNode> {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n return await DbIndex.load({ cid, get: makeProllyGetBlock(tblocks), ...opts }) as ProllyNode\n}\n\nexport async function applyQuery<T extends DocRecord<T> = {}>(crdt: CRDT, resp: { result: IndexRow<T>[] }, query: QueryOpts) {\n if (query.descending) {\n resp.result = resp.result.reverse()\n }\n if (query.limit) {\n resp.result = resp.result.slice(0, query.limit)\n }\n if (query.includeDocs) {\n resp.result = await Promise.all(\n resp.result.map(async row => {\n const val = await crdt.get(row.id)\n const doc = val ? ({ _id: row.id, ...val.doc } as Doc<T>) : null\n return { ...row, doc }\n })\n )\n }\n return {\n rows: resp.result.map(row => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n row.key = (charwise.decode(row.key) as IndexKey)\n if (row.row && !row.value) {\n row.value = row.row\n delete row.row\n }\n return row\n })\n }\n}\n\nexport function encodeRange(range: [DocFragment, DocFragment]): [IndexKey, IndexKey] {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n return range.map(key => charwise.encode(key) as IndexKey) as [IndexKey, IndexKey]\n}\n\nexport function encodeKey(key: DocFragment): string {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n return charwise.encode(key) as string\n}\n\n// ProllyNode type based on the ProllyNode from 'prolly-trees/base'\ninterface ProllyNode extends BaseNode {\n getAllEntries<T extends DocRecord<T> = {}>(): PromiseLike<{ [x: string]: any; result: IndexRow<T>[] }>\n getMany(removeIds: string[]): Promise<{ [x: string]: any; result: IndexKey[] }>\n range<T extends DocRecord<T> = {}>(a: IndexKey, b: IndexKey): Promise<{ result: IndexRow<T>[] }>\n get<T extends DocRecord<T> = {}>(key: string): Promise<{ result: IndexRow<T>[] }>\n bulk(bulk: IndexUpdate[]): PromiseLike<{ root: ProllyNode | null; blocks: Block[] }>\n address: Promise<Link>\n distance: number\n compare: (a: any, b: any) => number\n cache: any\n block: Promise<Block>\n}\n\ninterface StaticProllyOptions {\n cache: any\n chunker: (entry: any, distance: number) => boolean\n codec: any\n hasher: any\n compare: (a: any, b: any) => number\n}\n","import type {\n ClockHead,\n DocUpdate,\n MapFn,\n IndexUpdate,\n QueryOpts,\n IdxMeta,\n DocFragment,\n IdxMetaMap,\n IndexRow,\n Doc,\n DocRecord,\n} from './types'\nimport { EncryptedBlockstore, TransactionMeta } from '@fireproof/encrypted-blockstore'\nimport {\n bulkIndex,\n indexEntriesForChanges,\n byIdOpts,\n byKeyOpts,\n IndexTree,\n applyQuery,\n encodeRange,\n encodeKey,\n loadIndex\n} from './indexer-helpers'\nimport { CRDT } from './crdt'\n\nexport function index(\n { _crdt }: { _crdt: CRDT },\n name: string,\n mapFn?: MapFn,\n meta?: IdxMeta\n): Index {\n if (mapFn && meta) throw new Error('cannot provide both mapFn and meta')\n if (mapFn && mapFn.constructor.name !== 'Function') throw new Error('mapFn must be a function')\n if (_crdt.indexers.has(name)) {\n const idx = _crdt.indexers.get(name)!\n idx.applyMapFn(name, mapFn, meta)\n } else {\n const idx = new Index(_crdt, name, mapFn, meta)\n _crdt.indexers.set(name, idx)\n }\n return _crdt.indexers.get(name)!\n}\n\nexport class Index {\n blockstore: EncryptedBlockstore\n crdt: CRDT\n name: string | null = null\n mapFn: MapFn | null = null\n mapFnString: string = ''\n byKey = new IndexTree()\n byId = new IndexTree()\n indexHead: ClockHead | undefined = undefined\n includeDocsDefault: boolean = false\n initError: Error | null = null\n ready: Promise<void>\n\n constructor(crdt: CRDT, name: string, mapFn?: MapFn, meta?: IdxMeta) {\n this.blockstore = crdt.indexBlockstore\n this.crdt = crdt\n this.applyMapFn(name, mapFn, meta)\n if (!(this.mapFnString || this.initError)) throw new Error('missing mapFnString')\n this.ready = this.blockstore.ready.then(() => {})\n // .then((header: IdxCarHeader) => {\n // // @ts-ignore\n // if (header.head) throw new Error('cannot have head in idx header')\n // if (header.indexes === undefined) throw new Error('missing indexes in idx header')\n // // for (const [name, idx] of Object.entries(header.indexes)) {\n // // index({ _crdt: crdt }, name, undefined, idx as IdxMeta)\n // // }\n // })\n }\n\n applyMapFn<T extends DocRecord<T> = {}>(name: string, mapFn?: MapFn, meta?: IdxMeta) {\n if (mapFn && meta) throw new Error('cannot provide both mapFn and meta')\n if (this.name && this.name !== name) throw new Error('cannot change name')\n this.name = name\n try {\n if (meta) {\n // hydrating from header\n if (\n this.indexHead &&\n this.indexHead.map(c => c.toString()).join() !== meta.head.map(c => c.toString()).join()\n ) {\n throw new Error('cannot apply meta to existing index')\n }\n\n if (this.mapFnString) {\n // we already initialized from application code\n if (this.mapFnString !== meta.map) {\n console.log(\n 'cannot apply different mapFn meta: old mapFnString',\n this.mapFnString,\n 'new mapFnString',\n meta.map\n )\n // throw new Error('cannot apply different mapFn meta')\n } else {\n this.byId.cid = meta.byId\n this.byKey.cid = meta.byKey\n this.indexHead = meta.head\n }\n } else {\n // we are first\n this.mapFnString = meta.map\n this.byId.cid = meta.byId\n this.byKey.cid = meta.byKey\n this.indexHead = meta.head\n }\n } else {\n if (this.mapFn) {\n // we already initialized from application code\n if (mapFn) {\n if (this.mapFn.toString() !== mapFn.toString())\n throw new Error('cannot apply different mapFn app2')\n }\n } else {\n // application code is creating an index\n if (!mapFn) {\n mapFn = (doc) => doc[name as keyof Doc<T>] ?? undefined\n }\n if (this.mapFnString) {\n // we already loaded from a header\n if (this.mapFnString !== mapFn.toString())\n throw new Error('cannot apply different mapFn app')\n } else {\n // we are first\n this.mapFnString = mapFn.toString()\n }\n this.mapFn = mapFn\n }\n }\n const matches = /=>\\s*(.*)/.test(this.mapFnString)\n this.includeDocsDefault = matches\n } catch (e) {\n this.initError = e as Error\n }\n }\n\n async query<T extends DocRecord<T> = {}>(opts: QueryOpts = {}): Promise<{ rows: IndexRow<T>[] }> {\n // this._resetIndex()\n await this._updateIndex()\n await this._hydrateIndex()\n if (!this.byKey.root) return await applyQuery(this.crdt, { result: [] }, opts)\n if (this.includeDocsDefault && opts.includeDocs === undefined) opts.includeDocs = true\n if (opts.range) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n const { result, ...all } = await this.byKey.root.range<T>(...encodeRange(opts.range))\n return await applyQuery(this.crdt, { result, ...all }, opts)\n }\n if (opts.key) {\n const encodedKey = encodeKey(opts.key)\n return await applyQuery(this.crdt, await this.byKey.root.get(encodedKey), opts)\n }\n if (Array.isArray(opts.keys)) {\n const results = await Promise.all(\n opts.keys.map(async (key: DocFragment) => {\n const encodedKey = encodeKey(key)\n return (await applyQuery(this.crdt, await this.byKey.root!.get<T>(encodedKey), opts)).rows\n })\n )\n return { rows: results.flat() }\n }\n if (opts.prefix) {\n if (!Array.isArray(opts.prefix)) opts.prefix = [opts.prefix]\n const start = [...opts.prefix, NaN]\n const end = [...opts.prefix, Infinity]\n const encodedR = encodeRange([start, end])\n return await applyQuery(this.crdt, await this.byKey.root.range(...encodedR), opts)\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n const { result, ...all } = await this.byKey.root.getAllEntries<T>() // funky return type\n return await applyQuery(\n this.crdt,\n {\n result: result.map(({ key: [k, id], value }) => ({ key: k, id, value })),\n ...all\n },\n opts\n )\n }\n\n _resetIndex() {\n this.byId = new IndexTree()\n this.byKey = new IndexTree()\n this.indexHead = undefined\n }\n\n async _hydrateIndex() {\n if (this.byId.root && this.byKey.root) return\n if (!this.byId.cid || !this.byKey.cid) return\n this.byId.root = await loadIndex(this.blockstore, this.byId.cid, byIdOpts)\n this.byKey.root = await loadIndex(this.blockstore, this.byKey.cid, byKeyOpts)\n }\n\n async _updateIndex() {\n await this.ready\n if (this.initError) throw this.initError\n if (!this.mapFn) throw new Error('No map function defined')\n let result: DocUpdate[], head: ClockHead\n if (!this.indexHead || this.indexHead.length === 0) {\n ;({ result, head } = await this.crdt.allDocs())\n } else {\n ;({ result, head } = await this.crdt.changes(this.indexHead))\n }\n if (result.length === 0) {\n this.indexHead = head\n return { byId: this.byId, byKey: this.byKey }\n }\n let staleKeyIndexEntries: IndexUpdate[] = []\n let removeIdIndexEntries: IndexUpdate[] = []\n if (this.byId.root) {\n const removeIds = result.map(({ key }) => key)\n const { result: oldChangeEntries } = (await this.byId.root.getMany(removeIds)) as {\n result: Array<[string, string] | string>\n }\n staleKeyIndexEntries = oldChangeEntries.map(key => ({ key, del: true }))\n removeIdIndexEntries = oldChangeEntries.map(key => ({ key: key[1], del: true }))\n }\n const indexEntries = indexEntriesForChanges(result, this.mapFn) // use a getter to translate from string\n const byIdIndexEntries: DocUpdate[] = indexEntries.map(({ key }) => ({\n key: key[1],\n value: key\n }))\n const indexerMeta: IdxMetaMap = {indexes: new Map()}\n\n for (const [name, indexer] of this.crdt.indexers) {\n if (indexer.indexHead) {\n indexerMeta.indexes.set(name, {\n byId: indexer.byId.cid,\n byKey: indexer.byKey.cid,\n head: indexer.indexHead,\n map: indexer.mapFnString,\n name: indexer.name\n } as IdxMeta)\n }\n }\n return await this.blockstore.transaction(async (tblocks): Promise<TransactionMeta> => {\n this.byId = await bulkIndex(\n tblocks,\n this.byId,\n removeIdIndexEntries.concat(byIdIndexEntries),\n byIdOpts\n )\n this.byKey = await bulkIndex(\n tblocks,\n this.byKey,\n staleKeyIndexEntries.concat(indexEntries),\n byKeyOpts\n )\n this.indexHead = head\n const idxMeta = {\n byId: this.byId.cid,\n byKey: this.byKey.cid,\n head,\n map: this.mapFnString,\n name: this.name\n } as IdxMeta\n indexerMeta.indexes.set(this.name!, idxMeta) // should this move to after commit?\n return indexerMeta as unknown as TransactionMeta\n })\n }\n}\n","import { clockChangesSince } from './crdt-helpers'\nimport type { EncryptedBlockstore, CarTransaction } from '@fireproof/encrypted-blockstore'\nimport type { DocUpdate, ClockHead } from './types'\nimport { advance } from '@web3-storage/pail/clock'\nimport { root } from '@web3-storage/pail/crdt'\nimport { applyHeadQueue, ApplyHeadQueue } from './apply-head-queue'\n\nexport class CRDTClock {\n // todo: track local and remote clocks independently, merge on read\n // that way we can drop the whole remote if we need to\n // should go with making sure the local clock only references locally available blockstore on write\n head: ClockHead = []\n\n zoomers: Set<() => void> = new Set()\n watchers: Set<(updates: DocUpdate[]) => void> = new Set()\n emptyWatchers: Set<() => void> = new Set()\n\n blockstore: EncryptedBlockstore | null = null\n\n applyHeadQueue: ApplyHeadQueue\n\n constructor() {\n this.applyHeadQueue = applyHeadQueue(this.int_applyHead.bind(this))\n }\n\n setHead(head: ClockHead) {\n this.head = head\n }\n\n async applyHead(newHead: ClockHead, prevHead: ClockHead, updates: DocUpdate[] | null = null) {\n for await (const { updates: updatesAcc, all } of this.applyHeadQueue.push({\n newHead,\n prevHead,\n updates\n })) {\n this.processUpdates(updatesAcc, all, prevHead)\n }\n }\n\n async processUpdates(updatesAcc: DocUpdate[], all: boolean, prevHead: ClockHead) {\n let internalUpdates = updatesAcc\n if (this.watchers.size && !all) {\n const changes = await clockChangesSince(this.blockstore!, this.head, prevHead, {})\n internalUpdates = changes.result\n }\n this.zoomers.forEach(fn => fn())\n this.notifyWatchers(internalUpdates || [])\n }\n\n notifyWatchers(updates: DocUpdate[]) {\n this.emptyWatchers.forEach(fn => fn())\n this.watchers.forEach(fn => fn(updates || []))\n }\n\n onTick(fn: (updates: DocUpdate[]) => void) {\n this.watchers.add(fn)\n }\n\n onTock(fn: () => void) {\n this.emptyWatchers.add(fn)\n }\n\n onZoom(fn: () => void) {\n this.zoomers.add(fn)\n }\n\n async int_applyHead(newHead: ClockHead, prevHead: ClockHead, localUpdates: boolean) {\n const ogHead = sortClockHead(this.head)\n newHead = sortClockHead(newHead)\n if (compareClockHeads(ogHead, newHead)) {\n return\n }\n const ogPrev = sortClockHead(prevHead)\n if (compareClockHeads(ogHead, ogPrev)) {\n this.setHead(newHead)\n return\n }\n let head = this.head\n const noLoader = !localUpdates\n // const noLoader = this.head.length === 1 && !updates?.length\n if (!this.blockstore) throw new Error('missing blockstore')\n await validateBlocks(newHead, this.blockstore)\n await this.blockstore.transaction(\n async (tblocks: CarTransaction) => {\n head = await advanceBlocks(newHead, tblocks, head)\n const result = await root(tblocks, head)\n for (const { cid, bytes } of [...result.additions, ...result.removals]) {\n tblocks.putSync(cid, bytes)\n }\n return { head }\n },\n { noLoader }\n )\n this.setHead(head)\n }\n}\n\n// Helper functions\nfunction sortClockHead(clockHead: ClockHead) {\n return clockHead.sort((a, b) => a.toString().localeCompare(b.toString()))\n}\n\nasync function validateBlocks(newHead: ClockHead, blockstore: EncryptedBlockstore | null) {\n newHead.map(async cid => {\n const got = await blockstore!.get(cid)\n if (!got) {\n throw new Error('int_applyHead missing block: ' + cid.toString())\n }\n })\n}\n\nfunction compareClockHeads(head1: ClockHead, head2: ClockHead) {\n return head1.toString() === head2.toString()\n}\n\nasync function advanceBlocks(newHead: ClockHead, tblocks: CarTransaction, head: ClockHead) {\n for (const cid of newHead) {\n try {\n head = await advance(tblocks, head, cid)\n } catch (e) {\n console.log('failed to advance head:', cid.toString())\n continue\n }\n }\n return head\n}\n","import { ClockHead, DocUpdate } from './types'\n\ntype ApplyHeadWorkerFunction = (newHead: ClockHead, prevHead: ClockHead, localUpdates: boolean) => Promise<void>\n\ntype ApplyHeadTask = {\n newHead: ClockHead\n prevHead: ClockHead\n updates: DocUpdate[] | null\n}\n\nexport type ApplyHeadQueue = {\n push(task: ApplyHeadTask): AsyncGenerator<{ updates: DocUpdate[]; all: boolean }, void, unknown>\n}\n\nexport function applyHeadQueue(worker: ApplyHeadWorkerFunction): ApplyHeadQueue {\n const queue: ApplyHeadTask[] = []\n let isProcessing = false\n\n async function* process() {\n if (isProcessing || queue.length === 0) return\n isProcessing = true\n const allUpdates: DocUpdate[] = []\n try {\n while (queue.length > 0) {\n queue.sort((a, b) => (b.updates ? 1 : -1))\n const task = queue.shift()\n if (!task) continue\n\n await worker(task.newHead, task.prevHead, task.updates !== null)\n\n if (task.updates) {\n allUpdates.push(...task.updates)\n }\n // Yield the updates if there are no tasks with updates left in the queue or the current task has updates\n if (!queue.some(t => t.updates) || task.updates) {\n const allTasksHaveUpdates = queue.every(task => task.updates !== null)\n yield { updates: allUpdates, all: allTasksHaveUpdates }\n allUpdates.length = 0\n }\n }\n } finally {\n isProcessing = false\n const generator = process()\n let result = await generator.next()\n while (!result.done) {\n result = await generator.next()\n }\n }\n }\n\n return {\n push(\n task: ApplyHeadTask\n ): AsyncGenerator<{ updates: DocUpdate[]; all: boolean }, void, unknown> {\n queue.push(task)\n return process()\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAuB;;;ACQhB,SAAS,WAAW,QAAwB,UAAkB,UAAU,YAAqB,OAAmB;AACrH,QAAM,QAIA,CAAC;AACP,MAAI,eAAe;AAEnB,iBAAe,UAAU;AACvB,QAAI,gBAAgB,MAAM,WAAW;AAAG;AACxC,mBAAe;AAEf,UAAM,iBAAiB,MAAM,OAAO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AAA,EAEA,MAAM,oBAAoB;AACxB,QAAI,KAAK,oBAAoB,MAAM;AACjC,iBAAW,YAAY,KAAK,qBAAqB;AAC/C,eAAO,YAAY,MAAM,SAAS,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,MAAa;AAC3D,kBAAQ,MAAM,oBAAoB,CAAC;AAAA,QACrC,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;AAMO,SAAS,UAAU,MAAc,MAA6B;AACnE,MAAI,CAAC,SAAS,UAAU,IAAI,IAAI,GAAG;AACjC,aAAS,UAAU,IAAI,MAAM,IAAI,SAAS,MAAM,IAAI,CAAC;AAAA,EACvD;AACA,SAAO,SAAS,UAAU,IAAI,IAAI;AACpC;AAEA,SAAS,SAAS,UAAkB;AAClC,QAAM,QAAQ;AACd,MAAI,QAAgC;AACpC,QAAM,UAAU,MAAM,KAAK,SAAS,SAAS,KAAK,GAAG,WAAS,MAAM,CAAC,EAAE,KAAK,CAAC;AAC7E,MAAI,QAAQ,WAAW,GAAG;AACxB,YAAQ,YAAY,KAAK,QAAQ;AAAA,EACnC;AACA,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT,OAAO;AAEL,WAAO,MAAM,CAAC;AAAA,EAChB;AACF;","names":["index","import_encrypted_blockstore","hasher","import_block","import_sha2","codec","cache","hasher","charwise","root","result","all","import_clock","import_crdt","task","name","updates"]}
@@ -2,7 +2,7 @@ import { Link, Block } from 'multiformats';
2
2
  import { EventLink } from '@web3-storage/pail/clock/api';
3
3
  import { Operation } from '@web3-storage/pail/crdt/api';
4
4
  import * as _fireproof_encrypted_blockstore from '@fireproof/encrypted-blockstore';
5
- import { DbMeta, EncryptedBlockstore } from '@fireproof/encrypted-blockstore';
5
+ import { DbMeta, CryptoOpts, StoreOpts, EncryptedBlockstore } from '@fireproof/encrypted-blockstore';
6
6
  import * as multiformats_dist_types_src_block from 'multiformats/dist/types/src/block';
7
7
  import { ProllyNode as ProllyNode$1 } from 'prolly-trees/base';
8
8
 
@@ -11,6 +11,8 @@ type ConfigOpts = {
11
11
  meta?: DbMeta;
12
12
  persistIndexes?: boolean;
13
13
  autoCompact?: number;
14
+ crypto?: CryptoOpts;
15
+ store?: StoreOpts;
14
16
  };
15
17
  type ClockLink = EventLink<Operation>;
16
18
  type ClockHead = ClockLink[];
@@ -44,6 +46,7 @@ type DocUpdate = {
44
46
  type DocValue = {
45
47
  doc?: DocBase;
46
48
  del?: boolean;
49
+ cid?: AnyLink;
47
50
  };
48
51
  type IndexKey = [string, string] | string;
49
52
  type IndexUpdate = {
@@ -166,27 +169,27 @@ declare class Index {
166
169
  [x: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | {
167
170
  [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
168
171
  } | null)[] | {
169
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
172
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null;
170
173
  } | null)[] | {
171
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
174
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null;
172
175
  } | null)[] | {
173
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
176
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null;
174
177
  } | null)[] | {
175
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
178
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
176
179
  } | null)[] | {
177
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
180
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
178
181
  } | null)[] | {
179
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
182
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
180
183
  } | null)[] | {
181
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
184
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
182
185
  } | null)[] | {
183
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
186
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
184
187
  } | null)[] | {
185
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
188
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
186
189
  } | null)[] | {
187
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
190
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
188
191
  } | null)[] | {
189
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
192
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
190
193
  } | null;
191
194
  } | {
192
195
  byId: IndexTree;
@@ -2,7 +2,7 @@ import { Link, Block } from 'multiformats';
2
2
  import { EventLink } from '@web3-storage/pail/clock/api';
3
3
  import { Operation } from '@web3-storage/pail/crdt/api';
4
4
  import * as _fireproof_encrypted_blockstore from '@fireproof/encrypted-blockstore';
5
- import { DbMeta, EncryptedBlockstore } from '@fireproof/encrypted-blockstore';
5
+ import { DbMeta, CryptoOpts, StoreOpts, EncryptedBlockstore } from '@fireproof/encrypted-blockstore';
6
6
  import * as multiformats_dist_types_src_block from 'multiformats/dist/types/src/block';
7
7
  import { ProllyNode as ProllyNode$1 } from 'prolly-trees/base';
8
8
 
@@ -11,6 +11,8 @@ type ConfigOpts = {
11
11
  meta?: DbMeta;
12
12
  persistIndexes?: boolean;
13
13
  autoCompact?: number;
14
+ crypto?: CryptoOpts;
15
+ store?: StoreOpts;
14
16
  };
15
17
  type ClockLink = EventLink<Operation>;
16
18
  type ClockHead = ClockLink[];
@@ -44,6 +46,7 @@ type DocUpdate = {
44
46
  type DocValue = {
45
47
  doc?: DocBase;
46
48
  del?: boolean;
49
+ cid?: AnyLink;
47
50
  };
48
51
  type IndexKey = [string, string] | string;
49
52
  type IndexUpdate = {
@@ -166,27 +169,27 @@ declare class Index {
166
169
  [x: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | {
167
170
  [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
168
171
  } | null)[] | {
169
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
172
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null;
170
173
  } | null)[] | {
171
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
174
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null;
172
175
  } | null)[] | {
173
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
176
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null;
174
177
  } | null)[] | {
175
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
178
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
176
179
  } | null)[] | {
177
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
180
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
178
181
  } | null)[] | {
179
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
182
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
180
183
  } | null)[] | {
181
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
184
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
182
185
  } | null)[] | {
183
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
186
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
184
187
  } | null)[] | {
185
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
188
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
186
189
  } | null)[] | {
187
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
190
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
188
191
  } | null)[] | {
189
- [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
192
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
190
193
  } | null;
191
194
  } | {
192
195
  byId: IndexTree;