@xyo-network/diviner-boundwitness-indexeddb 2.96.2 → 2.97.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,11 @@
1
1
  import { BoundWitness } from '@xyo-network/boundwitness-model';
2
2
  import { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract';
3
3
  import { BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model';
4
+ import { Schema } from '@xyo-network/payload-model';
4
5
  import { IndexedDbBoundWitnessDivinerParams } from './Params';
5
6
  export declare class IndexedDbBoundWitnessDiviner<TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams, TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload, TOut extends BoundWitness = BoundWitness> extends BoundWitnessDiviner<TParams, TIn, TOut> {
6
- static configSchemas: string[];
7
+ static configSchemas: Schema[];
8
+ static defaultConfigSchema: Schema;
7
9
  /**
8
10
  * The database name. If not supplied via config, it defaults
9
11
  * to the archivist's name and if archivist's name is not supplied,
@@ -1 +1 @@
1
- {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAsC,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAqC,MAAM,yCAAyC,CAAA;AAK5H,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAA;AAmB7D,qBAAa,4BAA4B,CACvC,OAAO,SAAS,kCAAkC,GAAG,kCAAkC,EACvF,GAAG,SAAS,+BAA+B,GAAG,+BAA+B,EAC7E,IAAI,SAAS,YAAY,GAAG,YAAY,CACxC,SAAQ,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/C,OAAgB,aAAa,WAA6C;IAE1E;;;;;;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undwitness-model';
2
2
  import { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract';
3
3
  import { BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model';
4
+ import { Schema } from '@xyo-network/payload-model';
4
5
  import { IndexedDbBoundWitnessDivinerParams } from './Params';
5
6
  export declare class IndexedDbBoundWitnessDiviner<TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams, TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload, TOut extends BoundWitness = BoundWitness> extends BoundWitnessDiviner<TParams, TIn, TOut> {
6
- static configSchemas: string[];
7
+ static configSchemas: Schema[];
8
+ static defaultConfigSchema: Schema;
7
9
  /**
8
10
  * The database name. If not supplied via config, it defaults
9
11
  * to the archivist's name and if archivist's name is not supplied,
@@ -1 +1 @@
1
- {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAsC,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAqC,MAAM,yCAAyC,CAAA;AAK5H,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAA;AAmB7D,qBAAa,4BAA4B,CACvC,OAAO,SAAS,kCAAkC,GAAG,kCAAkC,EACvF,GAAG,SAAS,+BAA+B,GAAG,+BAA+B,EAC7E,IAAI,SAAS,YAAY,GAAG,YAAY,CACxC,SAAQ,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/C,OAAgB,aAAa,WAA6C;IAE1E;;;;;;OAMG;IACH,IAAI,MAAM,WAET;IAED;;OAEG;IACH,IAAI,SAAS,WAEZ;IAED;;;OAGG;IACH,IAAI,SAAS,WAEZ;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cA0DhD,YAAY;IAQrC;;;OAGG;YACW,mBAAmB;IAwBjC;;;;OAIG;YACW,QAAQ;CAcvB"}
1
+ {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAsC,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAqC,MAAM,yCAAyC,CAAA;AAE5H,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAInD,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAA;AAmB7D,qBAAa,4BAA4B,CACvC,OAAO,SAAS,kCAAkC,GAAG,kCAAkC,EACvF,GAAG,SAAS,+BAA+B,GAAG,+BAA+B,EAC7E,IAAI,SAAS,YAAY,GAAG,YAAY,CACxC,SAAQ,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/C,OAAgB,aAAa,EAAE,MAAM,EAAE,CAAqE;IAC5G,OAAgB,mBAAmB,EAAE,MAAM,CAA2C;IAEtF;;;;;;OAMG;IACH,IAAI,MAAM,WAET;IAED;;OAEG;IACH,IAAI,SAAS,WAEZ;IAED;;;OAGG;IACH,IAAI,SAAS,WAEZ;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cA0DhD,YAAY;IAQrC;;;OAGG;YACW,mBAAmB;IAwBjC;;;;OAIG;YACW,QAAQ;CAcvB"}
@@ -1,9 +1,11 @@
1
1
  import { BoundWitness } from '@xyo-network/boundwitness-model';
2
2
  import { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract';
3
3
  import { BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model';
4
+ import { Schema } from '@xyo-network/payload-model';
4
5
  import { IndexedDbBoundWitnessDivinerParams } from './Params';
5
6
  export declare class IndexedDbBoundWitnessDiviner<TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams, TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload, TOut extends BoundWitness = BoundWitness> extends BoundWitnessDiviner<TParams, TIn, TOut> {
6
- static configSchemas: string[];
7
+ static configSchemas: Schema[];
8
+ static defaultConfigSchema: Schema;
7
9
  /**
8
10
  * The database name. If not supplied via config, it defaults
9
11
  * to the archivist's name and if archivist's name is not supplied,
@@ -1 +1 @@
1
- {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAsC,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAqC,MAAM,yCAAyC,CAAA;AAK5H,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAA;AAmB7D,qBAAa,4BAA4B,CACvC,OAAO,SAAS,kCAAkC,GAAG,kCAAkC,EACvF,GAAG,SAAS,+BAA+B,GAAG,+BAA+B,EAC7E,IAAI,SAAS,YAAY,GAAG,YAAY,CACxC,SAAQ,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/C,OAAgB,aAAa,WAA6C;IAE1E;;;;;;OAMG;IACH,IAAI,MAAM,WAET;IAED;;OAEG;IACH,IAAI,SAAS,WAEZ;IAED;;;OAGG;IACH,IAAI,SAAS,WAEZ;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cA0DhD,YAAY;IAQrC;;;OAGG;YACW,mBAAmB;IAwBjC;;;;OAIG;YACW,QAAQ;CAcvB"}
1
+ {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAsC,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAqC,MAAM,yCAAyC,CAAA;AAE5H,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAInD,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAA;AAmB7D,qBAAa,4BAA4B,CACvC,OAAO,SAAS,kCAAkC,GAAG,kCAAkC,EACvF,GAAG,SAAS,+BAA+B,GAAG,+BAA+B,EAC7E,IAAI,SAAS,YAAY,GAAG,YAAY,CACxC,SAAQ,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/C,OAAgB,aAAa,EAAE,MAAM,EAAE,CAAqE;IAC5G,OAAgB,mBAAmB,EAAE,MAAM,CAA2C;IAEtF;;;;;;OAMG;IACH,IAAI,MAAM,WAET;IAED;;OAEG;IACH,IAAI,SAAS,WAEZ;IAED;;;OAGG;IACH,IAAI,SAAS,WAEZ;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cA0DhD,YAAY;IAQrC;;;OAGG;YACW,mBAAmB;IAwBjC;;;;OAIG;YACW,QAAQ;CAcvB"}
@@ -57,8 +57,10 @@ var IndexedDbBoundWitnessDiviner = class extends import_diviner_boundwitness_abs
57
57
  __name(this, "IndexedDbBoundWitnessDiviner");
58
58
  }
59
59
  static configSchemas = [
60
+ ...super.configSchemas,
60
61
  IndexedDbBoundWitnessDivinerConfigSchema
61
62
  ];
63
+ static defaultConfigSchema = IndexedDbBoundWitnessDivinerConfigSchema;
62
64
  /**
63
65
  * The database name. If not supplied via config, it defaults
64
66
  * to the archivist's name and if archivist's name is not supplied,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts"],"sourcesContent":["export * from './Config'\nexport * from './Diviner'\nexport * from './Params'\nexport * from './Schema'\n","import { BoundWitnessDivinerSchema } from '@xyo-network/diviner-boundwitness-model'\n\nexport const IndexedDbBoundWitnessDivinerSchema = `${BoundWitnessDivinerSchema}.indexeddb`\nexport type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema\n","import { IndexDescription } from '@xyo-network/archivist-model'\nimport { DivinerConfig } from '@xyo-network/diviner-model'\n\nimport { IndexedDbBoundWitnessDivinerSchema } from './Schema'\n\nexport const IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config`\nexport type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema\n\nexport type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{\n /**\n * The database name\n */\n dbName?: string\n /**\n * The version of the DB, defaults to 1\n */\n dbVersion?: number\n schema: IndexedDbBoundWitnessDivinerConfigSchema\n /**\n * The storage configuration\n * // TODO: Hoist to main diviner config\n */\n storage?: {\n /**\n * The indexes to create on the object store\n */\n indexes?: IndexDescription[]\n }\n /**\n * The name of the object store\n */\n storeName?: string\n}>\n","import { containsAll } from '@xylabs/array'\nimport { exists } from '@xylabs/exists'\nimport { IndexedDbArchivist } from '@xyo-network/archivist-indexeddb'\nimport { BoundWitness, BoundWitnessSchema, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport { BoundWitnessDivinerQueryPayload, isBoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { IDBPDatabase, openDB } from 'idb'\n\nimport { IndexedDbBoundWitnessDivinerConfigSchema } from './Config'\nimport { IndexedDbBoundWitnessDivinerParams } from './Params'\n\ninterface BoundWitnessStore {\n [s: string]: BoundWitness\n}\n\ntype ValueFilter = (bw?: BoundWitness | null) => boolean\n\nconst bwValueFilter = (\n key: keyof Pick<BoundWitness, 'addresses' | 'payload_hashes' | 'payload_schemas'>,\n values?: string[],\n): ValueFilter | undefined => {\n if (!values || values?.length === 0) return undefined\n return (bw) => {\n if (!bw) return false\n return containsAll(bw[key], values)\n }\n}\n\nexport class IndexedDbBoundWitnessDiviner<\n TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override configSchemas = [IndexedDbBoundWitnessDivinerConfigSchema]\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the archivist's name and if archivist's name is not supplied,\n * it defaults to `archivist`. This behavior\n * biases towards a single, isolated DB per archivist which seems to\n * make the most sense for 99% of use cases.\n */\n get dbName() {\n return this.config?.dbName ?? this.config?.archivist ?? IndexedDbArchivist.defaultDbName\n }\n\n /**\n * The database version. If not supplied via config, it defaults to 1.\n */\n get dbVersion() {\n return this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion\n }\n\n /**\n * The name of the object store. If not supplied via config, it defaults\n * to `payloads`.\n */\n get storeName() {\n return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n const query = payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop()\n if (!query) return []\n\n const result = await this.tryUseDb(async (db) => {\n const { addresses, payload_hashes, payload_schemas, limit, offset, order } = query\n const tx = db.transaction(this.storeName, 'readonly')\n const store = tx.objectStore(this.storeName)\n const results: TOut[] = []\n let parsedOffset = offset ?? 0\n const parsedLimit = limit ?? 10\n const direction: IDBCursorDirection = order === 'desc' ? 'prev' : 'next'\n const valueFilters: ValueFilter[] = [\n bwValueFilter('addresses', addresses),\n bwValueFilter('payload_hashes', payload_hashes),\n bwValueFilter('payload_schemas', payload_schemas),\n ].filter(exists)\n // Only iterate over BWs\n let cursor = await store.index(IndexedDbArchivist.schemaIndexName).openCursor(IDBKeyRange.only(BoundWitnessSchema), direction)\n\n // If we're filtering on more than just the schema, we need to\n // iterate through all the results\n if (valueFilters.length === 0) {\n // Skip records until the offset is reached\n while (cursor && parsedOffset > 0) {\n cursor = await cursor.advance(parsedOffset)\n parsedOffset = 0 // Reset offset after skipping\n }\n }\n // Collect results up to the limit\n while (cursor && results.length < parsedLimit) {\n const value = cursor.value\n if (value) {\n // If we're filtering on more than just the schema\n if (valueFilters.length > 0) {\n // Ensure all filters pass\n if (valueFilters.every((filter) => filter(value))) {\n // Then save the value\n results.push(value)\n }\n } else {\n // Otherwise just save the value\n results.push(value)\n }\n }\n cursor = await cursor.continue()\n }\n await tx.done\n // Remove any metadata before returning to the client\n return await Promise.all(\n results.filter(isBoundWitness).map((bw) => {\n return PayloadBuilder.build(bw)\n }),\n )\n })\n return result ?? []\n }\n\n protected override async startHandler() {\n await super.startHandler()\n // NOTE: Do not eager initialize the DB here. It will cause the\n // DB to be created by this process and then the DB will be\n // in a bad state for other processes that need to create the DB.\n return true\n }\n\n /**\n * Checks that the desired DB/objectStore exists and is initialized to the correct version\n * @returns The initialized DB or undefined if it does not exist in the desired state\n */\n private async tryGetInitializedDb(): Promise<IDBPDatabase<BoundWitnessStore> | undefined> {\n // Enumerate the DBs\n const dbs = await indexedDB.databases()\n // Check that the DB exists at the desired version\n const dbExists = dbs.some((db) => {\n return db.name === this.dbName && db.version === this.dbVersion\n })\n // If the DB exists at the desired version\n if (dbExists) {\n // If the db does exist, open it\n const db = await openDB<BoundWitnessStore>(this.dbName, this.dbVersion)\n // Check that the desired objectStore exists\n const storeExists = db.objectStoreNames.contains(this.storeName)\n // If the correct db/version/objectStore exists\n if (storeExists) {\n return db\n } else {\n // Otherwise close the db so the process that is going to update the\n // db can open it\n db.close()\n }\n }\n }\n\n /**\n * Executes a callback with the initialized DB and then closes the db\n * @param callback The method to execute with the initialized DB\n * @returns\n */\n private async tryUseDb<T>(callback: (db: IDBPDatabase<BoundWitnessStore>) => Promise<T> | T): Promise<T | undefined> {\n // Get the initialized DB\n const db = await this.tryGetInitializedDb()\n if (db) {\n try {\n // Perform the callback\n return await callback(db)\n } finally {\n // Close the DB\n db.close()\n }\n }\n return undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAA,wCAA0C;AAEnC,IAAMA,qCAAqC,GAAGC,2DAAAA;;;ACG9C,IAAMC,2CAA2C,GAAGC,kCAAAA;;;ACL3D,mBAA4B;AAC5B,oBAAuB;AACvB,iCAAmC;AACnC,gCAAiE;AACjE,2CAAoC;AACpC,IAAAC,qCAAmF;AACnF,6BAA+B;AAC/B,iBAAqC;AAWrC,IAAMC,gBAAgB,wBACpBC,KACAC,WAAAA;AAEA,MAAI,CAACA,UAAUA,QAAQC,WAAW;AAAG,WAAOC;AAC5C,SAAO,CAACC,OAAAA;AACN,QAAI,CAACA;AAAI,aAAO;AAChB,eAAOC,0BAAYD,GAAGJ,GAAAA,GAAMC,MAAAA;EAC9B;AACF,GATsB;AAWf,IAAMK,+BAAN,cAIGC,yDAAAA;EAjCV,OAiCUA;;;EACR,OAAgBC,gBAAgB;IAACC;;;;;;;;;EASjC,IAAIC,SAAS;AACX,WAAO,KAAKC,QAAQD,UAAU,KAAKC,QAAQC,aAAaC,8CAAmBC;EAC7E;;;;EAKA,IAAIC,YAAY;AACd,WAAO,KAAKJ,QAAQI,aAAaF,8CAAmBG;EACtD;;;;;EAMA,IAAIC,YAAY;AACd,WAAO,KAAKN,QAAQM,aAAaJ,8CAAmBK;EACtD;EAEA,MAAyBC,cAAcC,UAAmC;AACxE,UAAMC,QAAQD,UAAUE,OAAOC,oEAAAA,GAAoCC,IAAAA;AACnE,QAAI,CAACH;AAAO,aAAO,CAAA;AAEnB,UAAMI,SAAS,MAAM,KAAKC,SAAS,OAAOC,OAAAA;AACxC,YAAM,EAAEC,WAAWC,gBAAgBC,iBAAiBC,OAAO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AA;AAIZ,WAAO;EACT;;;;;EAMA,MAAcC,sBAA4E;AAExF,UAAMC,MAAM,MAAMC,UAAUC,UAAS;AAErC,UAAMC,WAAWH,IAAII,KAAK,CAAC1C,OAAAA;AACzB,aAAOA,GAAG2C,SAAS,KAAK5D,UAAUiB,GAAG4C,YAAY,KAAKxD;IACxD,CAAA;AAEA,QAAIqD,UAAU;AAEZ,YAAMzC,KAAK,UAAM6C,mBAA0B,KAAK9D,QAAQ,KAAKK,SAAS;AAEtE,YAAM0D,cAAc9C,GAAG+C,iBAAiBC,SAAS,KAAK1D,SAAS;AAE/D,UAAIwD,aAAa;AACf,eAAO9C;MACT,OAAO;AAGLA,WAAGiD,MAAK;MACV;IACF;EACF;;;;;;EAOA,MAAclD,SAAYmD,UAA2F;AAEnH,UAAMlD,KAAK,MAAM,KAAKqC,oBAAmB;AACzC,QAAIrC,IAAI;AACN,UAAI;AAEF,eAAO,MAAMkD,SAASlD,EAAAA;MACxB,UAAA;AAEEA,WAAGiD,MAAK;MACV;IACF;AACA,WAAOzE;EACT;AACF;","names":["IndexedDbBoundWitnessDivinerSchema","BoundWitnessDivinerSchema","IndexedDbBoundWitnessDivinerConfigSchema","IndexedDbBoundWitnessDivinerSchema","import_diviner_boundwitness_model","bwValueFilter","key","values","length","undefined","bw","containsAll","IndexedDbBoundWitnessDiviner","BoundWitnessDiviner","configSchemas","IndexedDbBoundWitnessDivinerConfigSchema","dbName","config","archivist","IndexedDbArchivist","defaultDbName","dbVersion","defaultDbVersion","storeName","defaultStoreName","divineHandler","payloads","query","filter","isBoundWitnessDivinerQueryPayload","pop","result","tryUseDb","db","addresses","payload_hashes","payload_schemas","limit","offset","order","tx","transaction","store","objectStore","results","parsedOffset","parsedLimit","direction","valueFilters","exists","cursor","index","schemaIndexName","openCursor","IDBKeyRange","only","BoundWitnessSchema","advance","value","every","push","continue","done","Promise","all","isBoundWitness","map","PayloadBuilder","build","startHandler","tryGetInitializedDb","dbs","indexedDB","databases","dbExists","some","name","version","openDB","storeExists","objectStoreNames","contains","close","callback"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts"],"sourcesContent":["export * from './Config'\nexport * from './Diviner'\nexport * from './Params'\nexport * from './Schema'\n","import { BoundWitnessDivinerSchema } from '@xyo-network/diviner-boundwitness-model'\n\nexport const IndexedDbBoundWitnessDivinerSchema = `${BoundWitnessDivinerSchema}.indexeddb`\nexport type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema\n","import { IndexDescription } from '@xyo-network/archivist-model'\nimport { DivinerConfig } from '@xyo-network/diviner-model'\n\nimport { IndexedDbBoundWitnessDivinerSchema } from './Schema'\n\nexport const IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config`\nexport type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema\n\nexport type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{\n /**\n * The database name\n */\n dbName?: string\n /**\n * The version of the DB, defaults to 1\n */\n dbVersion?: number\n schema: IndexedDbBoundWitnessDivinerConfigSchema\n /**\n * The storage configuration\n * // TODO: Hoist to main diviner config\n */\n storage?: {\n /**\n * The indexes to create on the object store\n */\n indexes?: IndexDescription[]\n }\n /**\n * The name of the object store\n */\n storeName?: string\n}>\n","import { containsAll } from '@xylabs/array'\nimport { exists } from '@xylabs/exists'\nimport { IndexedDbArchivist } from '@xyo-network/archivist-indexeddb'\nimport { BoundWitness, BoundWitnessSchema, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport { BoundWitnessDivinerQueryPayload, isBoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Schema } from '@xyo-network/payload-model'\nimport { IDBPDatabase, openDB } from 'idb'\n\nimport { IndexedDbBoundWitnessDivinerConfigSchema } from './Config'\nimport { IndexedDbBoundWitnessDivinerParams } from './Params'\n\ninterface BoundWitnessStore {\n [s: string]: BoundWitness\n}\n\ntype ValueFilter = (bw?: BoundWitness | null) => boolean\n\nconst bwValueFilter = (\n key: keyof Pick<BoundWitness, 'addresses' | 'payload_hashes' | 'payload_schemas'>,\n values?: string[],\n): ValueFilter | undefined => {\n if (!values || values?.length === 0) return undefined\n return (bw) => {\n if (!bw) return false\n return containsAll(bw[key], values)\n }\n}\n\nexport class IndexedDbBoundWitnessDiviner<\n TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override configSchemas: Schema[] = [...super.configSchemas, IndexedDbBoundWitnessDivinerConfigSchema]\n static override defaultConfigSchema: Schema = IndexedDbBoundWitnessDivinerConfigSchema\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the archivist's name and if archivist's name is not supplied,\n * it defaults to `archivist`. This behavior\n * biases towards a single, isolated DB per archivist which seems to\n * make the most sense for 99% of use cases.\n */\n get dbName() {\n return this.config?.dbName ?? this.config?.archivist ?? IndexedDbArchivist.defaultDbName\n }\n\n /**\n * The database version. If not supplied via config, it defaults to 1.\n */\n get dbVersion() {\n return this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion\n }\n\n /**\n * The name of the object store. If not supplied via config, it defaults\n * to `payloads`.\n */\n get storeName() {\n return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n const query = payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop()\n if (!query) return []\n\n const result = await this.tryUseDb(async (db) => {\n const { addresses, payload_hashes, payload_schemas, limit, offset, order } = query\n const tx = db.transaction(this.storeName, 'readonly')\n const store = tx.objectStore(this.storeName)\n const results: TOut[] = []\n let parsedOffset = offset ?? 0\n const parsedLimit = limit ?? 10\n const direction: IDBCursorDirection = order === 'desc' ? 'prev' : 'next'\n const valueFilters: ValueFilter[] = [\n bwValueFilter('addresses', addresses),\n bwValueFilter('payload_hashes', payload_hashes),\n bwValueFilter('payload_schemas', payload_schemas),\n ].filter(exists)\n // Only iterate over BWs\n let cursor = await store.index(IndexedDbArchivist.schemaIndexName).openCursor(IDBKeyRange.only(BoundWitnessSchema), direction)\n\n // If we're filtering on more than just the schema, we need to\n // iterate through all the results\n if (valueFilters.length === 0) {\n // Skip records until the offset is reached\n while (cursor && parsedOffset > 0) {\n cursor = await cursor.advance(parsedOffset)\n parsedOffset = 0 // Reset offset after skipping\n }\n }\n // Collect results up to the limit\n while (cursor && results.length < parsedLimit) {\n const value = cursor.value\n if (value) {\n // If we're filtering on more than just the schema\n if (valueFilters.length > 0) {\n // Ensure all filters pass\n if (valueFilters.every((filter) => filter(value))) {\n // Then save the value\n results.push(value)\n }\n } else {\n // Otherwise just save the value\n results.push(value)\n }\n }\n cursor = await cursor.continue()\n }\n await tx.done\n // Remove any metadata before returning to the client\n return await Promise.all(\n results.filter(isBoundWitness).map((bw) => {\n return PayloadBuilder.build(bw)\n }),\n )\n })\n return result ?? []\n }\n\n protected override async startHandler() {\n await super.startHandler()\n // NOTE: Do not eager initialize the DB here. It will cause the\n // DB to be created by this process and then the DB will be\n // in a bad state for other processes that need to create the DB.\n return true\n }\n\n /**\n * Checks that the desired DB/objectStore exists and is initialized to the correct version\n * @returns The initialized DB or undefined if it does not exist in the desired state\n */\n private async tryGetInitializedDb(): Promise<IDBPDatabase<BoundWitnessStore> | undefined> {\n // Enumerate the DBs\n const dbs = await indexedDB.databases()\n // Check that the DB exists at the desired version\n const dbExists = dbs.some((db) => {\n return db.name === this.dbName && db.version === this.dbVersion\n })\n // If the DB exists at the desired version\n if (dbExists) {\n // If the db does exist, open it\n const db = await openDB<BoundWitnessStore>(this.dbName, this.dbVersion)\n // Check that the desired objectStore exists\n const storeExists = db.objectStoreNames.contains(this.storeName)\n // If the correct db/version/objectStore exists\n if (storeExists) {\n return db\n } else {\n // Otherwise close the db so the process that is going to update the\n // db can open it\n db.close()\n }\n }\n }\n\n /**\n * Executes a callback with the initialized DB and then closes the db\n * @param callback The method to execute with the initialized DB\n * @returns\n */\n private async tryUseDb<T>(callback: (db: IDBPDatabase<BoundWitnessStore>) => Promise<T> | T): Promise<T | undefined> {\n // Get the initialized DB\n const db = await this.tryGetInitializedDb()\n if (db) {\n try {\n // Perform the callback\n return await callback(db)\n } finally {\n // Close the DB\n db.close()\n }\n }\n return undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAA,wCAA0C;AAEnC,IAAMA,qCAAqC,GAAGC,2DAAAA;;;ACG9C,IAAMC,2CAA2C,GAAGC,kCAAAA;;;ACL3D,mBAA4B;AAC5B,oBAAuB;AACvB,iCAAmC;AACnC,gCAAiE;AACjE,2CAAoC;AACpC,IAAAC,qCAAmF;AACnF,6BAA+B;AAE/B,iBAAqC;AAWrC,IAAMC,gBAAgB,wBACpBC,KACAC,WAAAA;AAEA,MAAI,CAACA,UAAUA,QAAQC,WAAW;AAAG,WAAOC;AAC5C,SAAO,CAACC,OAAAA;AACN,QAAI,CAACA;AAAI,aAAO;AAChB,eAAOC,0BAAYD,GAAGJ,GAAAA,GAAMC,MAAAA;EAC9B;AACF,GATsB;AAWf,IAAMK,+BAAN,cAIGC,yDAAAA;EAlCV,OAkCUA;;;EACR,OAAgBC,gBAA0B;OAAI,MAAMA;IAAeC;;EACnE,OAAgBC,sBAA8BD;;;;;;;;EAS9C,IAAIE,SAAS;AACX,WAAO,KAAKC,QAAQD,UAAU,KAAKC,QAAQC,aAAaC,8CAAmBC;EAC7E;;;;EAKA,IAAIC,YAAY;AACd,WAAO,KAAKJ,QAAQI,aAAaF,8CAAmBG;EACtD;;;;;EAMA,IAAIC,YAAY;AACd,WAAO,KAAKN,QAAQM,a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AMrB,GAAGsB;AAET,aAAO,MAAMC,QAAQC,IACnBpB,QAAQhB,OAAOqC,wCAAAA,EAAgBC,IAAI,CAACzD,OAAAA;AAClC,eAAO0D,sCAAeC,MAAM3D,EAAAA;MAC9B,CAAA,CAAA;IAEJ,CAAA;AACA,WAAOsB,UAAU,CAAA;EACnB;EAEA,MAAyBsC,eAAe;AACtC,UAAM,MAAMA,aAAAA;AAIZ,WAAO;EACT;;;;;EAMA,MAAcC,sBAA4E;AAExF,UAAMC,MAAM,MAAMC,UAAUC,UAAS;AAErC,UAAMC,WAAWH,IAAII,KAAK,CAAC1C,OAAAA;AACzB,aAAOA,GAAG2C,SAAS,KAAK5D,UAAUiB,GAAG4C,YAAY,KAAKxD;IACxD,CAAA;AAEA,QAAIqD,UAAU;AAEZ,YAAMzC,KAAK,UAAM6C,mBAA0B,KAAK9D,QAAQ,KAAKK,SAAS;AAEtE,YAAM0D,cAAc9C,GAAG+C,iBAAiBC,SAAS,KAAK1D,SAAS;AAE/D,UAAIwD,aAAa;AACf,eAAO9C;MACT,OAAO;AAGLA,WAAGiD,MAAK;MACV;IACF;EACF;;;;;;EAOA,MAAclD,SAAYmD,UAA2F;AAEnH,UAAMlD,KAAK,MAAM,KAAKqC,oBAAmB;AACzC,QAAIrC,IAAI;AACN,UAAI;AAEF,eAAO,MAAMkD,SAASlD,EAAAA;MACxB,UAAA;AAEEA,WAAGiD,MAAK;MACV;IACF;AACA,WAAO1E;EACT;AACF;","names":["IndexedDbBoundWitnessDivinerSchema","BoundWitnessDivinerSchema","IndexedDbBoundWitnessDivinerConfigSchema","IndexedDbBoundWitnessDivinerSchema","import_diviner_boundwitness_model","bwValueFilter","key","values","length","undefined","bw","containsAll","IndexedDbBoundWitnessDiviner","BoundWitnessDiviner","configSchemas","IndexedDbBoundWitnessDivinerConfigSchema","defaultConfigSchema","dbName","config","archivist","IndexedDbArchivist","defaultDbName","dbVersion","defaultDbVersion","storeName","defaultStoreName","divineHandler","payloads","query","filter","isBoundWitnessDivinerQueryPayload","pop","result","tryUseDb","db","addresses","payload_hashes","payload_schemas","limit","offset","order","tx","transaction","store","objectStore","results","parsedOffset","parsedLimit","direction","valueFilters","exists","cursor","index","schemaIndexName","openCursor","IDBKeyRange","only","BoundWitnessSchema","advance","value","every","push","continue","done","Promise","all","isBoundWitness","map","PayloadBuilder","build","startHandler","tryGetInitializedDb","dbs","indexedDB","databases","dbExists","some","name","version","openDB","storeExists","objectStoreNames","contains","close","callback"]}
@@ -31,8 +31,10 @@ var IndexedDbBoundWitnessDiviner = class extends BoundWitnessDiviner {
31
31
  __name(this, "IndexedDbBoundWitnessDiviner");
32
32
  }
33
33
  static configSchemas = [
34
+ ...super.configSchemas,
34
35
  IndexedDbBoundWitnessDivinerConfigSchema
35
36
  ];
37
+ static defaultConfigSchema = IndexedDbBoundWitnessDivinerConfigSchema;
36
38
  /**
37
39
  * The database name. If not supplied via config, it defaults
38
40
  * to the archivist's name and if archivist's name is not supplied,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts"],"sourcesContent":["import { BoundWitnessDivinerSchema } from '@xyo-network/diviner-boundwitness-model'\n\nexport const IndexedDbBoundWitnessDivinerSchema = `${BoundWitnessDivinerSchema}.indexeddb`\nexport type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema\n","import { IndexDescription } from '@xyo-network/archivist-model'\nimport { DivinerConfig } from '@xyo-network/diviner-model'\n\nimport { IndexedDbBoundWitnessDivinerSchema } from './Schema'\n\nexport const IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config`\nexport type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema\n\nexport type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{\n /**\n * The database name\n */\n dbName?: string\n /**\n * The version of the DB, defaults to 1\n */\n dbVersion?: number\n schema: IndexedDbBoundWitnessDivinerConfigSchema\n /**\n * The storage configuration\n * // TODO: Hoist to main diviner config\n */\n storage?: {\n /**\n * The indexes to create on the object store\n */\n indexes?: IndexDescription[]\n }\n /**\n * The name of the object store\n */\n storeName?: string\n}>\n","import { containsAll } from '@xylabs/array'\nimport { exists } from '@xylabs/exists'\nimport { IndexedDbArchivist } from '@xyo-network/archivist-indexeddb'\nimport { BoundWitness, BoundWitnessSchema, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport { BoundWitnessDivinerQueryPayload, isBoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { IDBPDatabase, openDB } from 'idb'\n\nimport { IndexedDbBoundWitnessDivinerConfigSchema } from './Config'\nimport { IndexedDbBoundWitnessDivinerParams } from './Params'\n\ninterface BoundWitnessStore {\n [s: string]: BoundWitness\n}\n\ntype ValueFilter = (bw?: BoundWitness | null) => boolean\n\nconst bwValueFilter = (\n key: keyof Pick<BoundWitness, 'addresses' | 'payload_hashes' | 'payload_schemas'>,\n values?: string[],\n): ValueFilter | undefined => {\n if (!values || values?.length === 0) return undefined\n return (bw) => {\n if (!bw) return false\n return containsAll(bw[key], values)\n }\n}\n\nexport class IndexedDbBoundWitnessDiviner<\n TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override configSchemas = [IndexedDbBoundWitnessDivinerConfigSchema]\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the archivist's name and if archivist's name is not supplied,\n * it defaults to `archivist`. This behavior\n * biases towards a single, isolated DB per archivist which seems to\n * make the most sense for 99% of use cases.\n */\n get dbName() {\n return this.config?.dbName ?? this.config?.archivist ?? IndexedDbArchivist.defaultDbName\n }\n\n /**\n * The database version. If not supplied via config, it defaults to 1.\n */\n get dbVersion() {\n return this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion\n }\n\n /**\n * The name of the object store. If not supplied via config, it defaults\n * to `payloads`.\n */\n get storeName() {\n return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n const query = payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop()\n if (!query) return []\n\n const result = await this.tryUseDb(async (db) => {\n const { addresses, payload_hashes, payload_schemas, limit, offset, order } = query\n const tx = db.transaction(this.storeName, 'readonly')\n const store = tx.objectStore(this.storeName)\n const results: TOut[] = []\n let parsedOffset = offset ?? 0\n const parsedLimit = limit ?? 10\n const direction: IDBCursorDirection = order === 'desc' ? 'prev' : 'next'\n const valueFilters: ValueFilter[] = [\n bwValueFilter('addresses', addresses),\n bwValueFilter('payload_hashes', payload_hashes),\n bwValueFilter('payload_schemas', payload_schemas),\n ].filter(exists)\n // Only iterate over BWs\n let cursor = await store.index(IndexedDbArchivist.schemaIndexName).openCursor(IDBKeyRange.only(BoundWitnessSchema), direction)\n\n // If we're filtering on more than just the schema, we need to\n // iterate through all the results\n if (valueFilters.length === 0) {\n // Skip records until the offset is reached\n while (cursor && parsedOffset > 0) {\n cursor = await cursor.advance(parsedOffset)\n parsedOffset = 0 // Reset offset after skipping\n }\n }\n // Collect results up to the limit\n while (cursor && results.length < parsedLimit) {\n const value = cursor.value\n if (value) {\n // If we're filtering on more than just the schema\n if (valueFilters.length > 0) {\n // Ensure all filters pass\n if (valueFilters.every((filter) => filter(value))) {\n // Then save the value\n results.push(value)\n }\n } else {\n // Otherwise just save the value\n results.push(value)\n }\n }\n cursor = await cursor.continue()\n }\n await tx.done\n // Remove any metadata before returning to the client\n return await Promise.all(\n results.filter(isBoundWitness).map((bw) => {\n return PayloadBuilder.build(bw)\n }),\n )\n })\n return result ?? []\n }\n\n protected override async startHandler() {\n await super.startHandler()\n // NOTE: Do not eager initialize the DB here. It will cause the\n // DB to be created by this process and then the DB will be\n // in a bad state for other processes that need to create the DB.\n return true\n }\n\n /**\n * Checks that the desired DB/objectStore exists and is initialized to the correct version\n * @returns The initialized DB or undefined if it does not exist in the desired state\n */\n private async tryGetInitializedDb(): Promise<IDBPDatabase<BoundWitnessStore> | undefined> {\n // Enumerate the DBs\n const dbs = await indexedDB.databases()\n // Check that the DB exists at the desired version\n const dbExists = dbs.some((db) => {\n return db.name === this.dbName && db.version === this.dbVersion\n })\n // If the DB exists at the desired version\n if (dbExists) {\n // If the db does exist, open it\n const db = await openDB<BoundWitnessStore>(this.dbName, this.dbVersion)\n // Check that the desired objectStore exists\n const storeExists = db.objectStoreNames.contains(this.storeName)\n // If the correct db/version/objectStore exists\n if (storeExists) {\n return db\n } else {\n // Otherwise close the db so the process that is going to update the\n // db can open it\n db.close()\n }\n }\n }\n\n /**\n * Executes a callback with the initialized DB and then closes the db\n * @param callback The method to execute with the initialized DB\n * @returns\n */\n private async tryUseDb<T>(callback: (db: IDBPDatabase<BoundWitnessStore>) => Promise<T> | T): Promise<T | undefined> {\n // Get the initialized DB\n const db = await this.tryGetInitializedDb()\n if (db) {\n try {\n // Perform the callback\n return await callback(db)\n } finally {\n // Close the DB\n db.close()\n }\n }\n return undefined\n }\n}\n"],"mappings":";;;;AAAA,SAASA,iCAAiC;AAEnC,IAAMC,qCAAqC,GAAGD,yBAAAA;;;ACG9C,IAAME,2CAA2C,GAAGC,kCAAAA;;;ACL3D,SAASC,mBAAmB;AAC5B,SAASC,cAAc;AACvB,SAASC,0BAA0B;AACnC,SAAuBC,oBAAoBC,sBAAsB;AACjE,SAASC,2BAA2B;AACpC,SAA0CC,yCAAyC;AACnF,SAASC,sBAAsB;AAC/B,SAAuBC,cAAc;AAWrC,IAAMC,gBAAgB,wBACpBC,KACAC,WAAAA;AAEA,MAAI,CAACA,UAAUA,QAAQC,WAAW;AAAG,WAAOC;AAC5C,SAAO,CAACC,OAAAA;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,EAAAA;MACxB,UAAA;AAEEA,WAAGiD,MAAK;MACV;IACF;AACA,WAAOzE;EACT;AACF;","names":["BoundWitnessDivinerSchema","IndexedDbBoundWitnessDivinerSchema","IndexedDbBoundWitnessDivinerConfigSchema","IndexedDbBoundWitnessDivinerSchema","containsAll","exists","IndexedDbArchivist","BoundWitnessSchema","isBoundWitness","BoundWitnessDiviner","isBoundWitnessDivinerQueryPayload","PayloadBuilder","openDB","bwValueFilter","key","values","length","undefined","bw","containsAll","IndexedDbBoundWitnessDiviner","BoundWitnessDiviner","configSchemas","IndexedDbBoundWitnessDivinerConfigSchema","dbName","config","archivist","IndexedDbArchivist","defaultDbName","dbVersion","defaultDbVersion","storeName","defaultStoreName","divineHandler","payloads","query","filter","isBoundWitnessDivinerQueryPayload","pop","result","tryUseDb","db","addresses","payload_hashes","payload_schemas","limit","offset","order","tx","transaction","store","objectStore","results","parsedOffset","parsedLimit","direction","valueFilters","exists","cursor","index","schemaIndexName","openCursor","IDBKeyRange","only","BoundWitnessSchema","advance","value","every","push","continue","done","Promise","all","isBoundWitness","map","PayloadBuilder","build","startHandler","tryGetInitializedDb","dbs","indexedDB","databases","dbExists","some","name","version","openDB","storeExists","objectStoreNames","contains","close","callback"]}
1
+ {"version":3,"sources":["../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts"],"sourcesContent":["import { BoundWitnessDivinerSchema } from '@xyo-network/diviner-boundwitness-model'\n\nexport const IndexedDbBoundWitnessDivinerSchema = `${BoundWitnessDivinerSchema}.indexeddb`\nexport type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema\n","import { IndexDescription } from '@xyo-network/archivist-model'\nimport { DivinerConfig } from '@xyo-network/diviner-model'\n\nimport { IndexedDbBoundWitnessDivinerSchema } from './Schema'\n\nexport const IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config`\nexport type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema\n\nexport type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{\n /**\n * The database name\n */\n dbName?: string\n /**\n * The version of the DB, defaults to 1\n */\n dbVersion?: number\n schema: IndexedDbBoundWitnessDivinerConfigSchema\n /**\n * The storage configuration\n * // TODO: Hoist to main diviner config\n */\n storage?: {\n /**\n * The indexes to create on the object store\n */\n indexes?: IndexDescription[]\n }\n /**\n * The name of the object store\n */\n storeName?: string\n}>\n","import { containsAll } from '@xylabs/array'\nimport { exists } from '@xylabs/exists'\nimport { IndexedDbArchivist } from '@xyo-network/archivist-indexeddb'\nimport { BoundWitness, BoundWitnessSchema, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport { BoundWitnessDivinerQueryPayload, isBoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Schema } from '@xyo-network/payload-model'\nimport { IDBPDatabase, openDB } from 'idb'\n\nimport { IndexedDbBoundWitnessDivinerConfigSchema } from './Config'\nimport { IndexedDbBoundWitnessDivinerParams } from './Params'\n\ninterface BoundWitnessStore {\n [s: string]: BoundWitness\n}\n\ntype ValueFilter = (bw?: BoundWitness | null) => boolean\n\nconst bwValueFilter = (\n key: keyof Pick<BoundWitness, 'addresses' | 'payload_hashes' | 'payload_schemas'>,\n values?: string[],\n): ValueFilter | undefined => {\n if (!values || values?.length === 0) return undefined\n return (bw) => {\n if (!bw) return false\n return containsAll(bw[key], values)\n }\n}\n\nexport class IndexedDbBoundWitnessDiviner<\n TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override configSchemas: Schema[] = [...super.configSchemas, IndexedDbBoundWitnessDivinerConfigSchema]\n static override defaultConfigSchema: Schema = IndexedDbBoundWitnessDivinerConfigSchema\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the archivist's name and if archivist's name is not supplied,\n * it defaults to `archivist`. This behavior\n * biases towards a single, isolated DB per archivist which seems to\n * make the most sense for 99% of use cases.\n */\n get dbName() {\n return this.config?.dbName ?? this.config?.archivist ?? IndexedDbArchivist.defaultDbName\n }\n\n /**\n * The database version. If not supplied via config, it defaults to 1.\n */\n get dbVersion() {\n return this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion\n }\n\n /**\n * The name of the object store. If not supplied via config, it defaults\n * to `payloads`.\n */\n get storeName() {\n return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n const query = payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop()\n if (!query) return []\n\n const result = await this.tryUseDb(async (db) => {\n const { addresses, payload_hashes, payload_schemas, limit, offset, order } = query\n const tx = db.transaction(this.storeName, 'readonly')\n const store = tx.objectStore(this.storeName)\n const results: TOut[] = []\n let parsedOffset = offset ?? 0\n const parsedLimit = limit ?? 10\n const direction: IDBCursorDirection = order === 'desc' ? 'prev' : 'next'\n const valueFilters: ValueFilter[] = [\n bwValueFilter('addresses', addresses),\n bwValueFilter('payload_hashes', payload_hashes),\n bwValueFilter('payload_schemas', payload_schemas),\n ].filter(exists)\n // Only iterate over BWs\n let cursor = await store.index(IndexedDbArchivist.schemaIndexName).openCursor(IDBKeyRange.only(BoundWitnessSchema), direction)\n\n // If we're filtering on more than just the schema, we need to\n // iterate through all the results\n if (valueFilters.length === 0) {\n // Skip records until the offset is reached\n while (cursor && parsedOffset > 0) {\n cursor = await cursor.advance(parsedOffset)\n parsedOffset = 0 // Reset offset after skipping\n }\n }\n // Collect results up to the limit\n while (cursor && results.length < parsedLimit) {\n const value = cursor.value\n if (value) {\n // If we're filtering on more than just the schema\n if (valueFilters.length > 0) {\n // Ensure all filters pass\n if (valueFilters.every((filter) => filter(value))) {\n // Then save the value\n results.push(value)\n }\n } else {\n // Otherwise just save the value\n results.push(value)\n }\n }\n cursor = await cursor.continue()\n }\n await tx.done\n // Remove any metadata before returning to the client\n return await Promise.all(\n results.filter(isBoundWitness).map((bw) => {\n return PayloadBuilder.build(bw)\n }),\n )\n })\n return result ?? []\n }\n\n protected override async startHandler() {\n await super.startHandler()\n // NOTE: Do not eager initialize the DB here. It will cause the\n // DB to be created by this process and then the DB will be\n // in a bad state for other processes that need to create the DB.\n return true\n }\n\n /**\n * Checks that the desired DB/objectStore exists and is initialized to the correct version\n * @returns The initialized DB or undefined if it does not exist in the desired state\n */\n private async tryGetInitializedDb(): Promise<IDBPDatabase<BoundWitnessStore> | undefined> {\n // Enumerate the DBs\n const dbs = await indexedDB.databases()\n // Check that the DB exists at the desired version\n const dbExists = dbs.some((db) => {\n return db.name === this.dbName && db.version === this.dbVersion\n })\n // If the DB exists at the desired version\n if (dbExists) {\n // If the db does exist, open it\n const db = await openDB<BoundWitnessStore>(this.dbName, this.dbVersion)\n // Check that the desired objectStore exists\n const storeExists = db.objectStoreNames.contains(this.storeName)\n // If the correct db/version/objectStore exists\n if (storeExists) {\n return db\n } else {\n // Otherwise close the db so the process that is going to update the\n // db can open it\n db.close()\n }\n }\n }\n\n /**\n * Executes a callback with the initialized DB and then closes the db\n * @param callback The method to execute with the initialized DB\n * @returns\n */\n private async tryUseDb<T>(callback: (db: IDBPDatabase<BoundWitnessStore>) => Promise<T> | T): Promise<T | undefined> {\n // Get the initialized DB\n const db = await this.tryGetInitializedDb()\n if (db) {\n try {\n // Perform the callback\n return await callback(db)\n } finally {\n // Close the DB\n db.close()\n }\n }\n return undefined\n }\n}\n"],"mappings":";;;;AAAA,SAASA,iCAAiC;AAEnC,IAAMC,qCAAqC,GAAGD,yBAAAA;;;ACG9C,IAAME,2CAA2C,GAAGC,kCAAAA;;;ACL3D,SAASC,mBAAmB;AAC5B,SAASC,cAAc;AACvB,SAASC,0B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S;AAEtE,YAAM0D,cAAc9C,GAAG+C,iBAAiBC,SAAS,KAAK1D,SAAS;AAE/D,UAAIwD,aAAa;AACf,eAAO9C;MACT,OAAO;AAGLA,WAAGiD,MAAK;MACV;IACF;EACF;;;;;;EAOA,MAAclD,SAAYmD,UAA2F;AAEnH,UAAMlD,KAAK,MAAM,KAAKqC,oBAAmB;AACzC,QAAIrC,IAAI;AACN,UAAI;AAEF,eAAO,MAAMkD,SAASlD,EAAAA;MACxB,UAAA;AAEEA,WAAGiD,MAAK;MACV;IACF;AACA,WAAO1E;EACT;AACF;","names":["BoundWitnessDivinerSchema","IndexedDbBoundWitnessDivinerSchema","IndexedDbBoundWitnessDivinerConfigSchema","IndexedDbBoundWitnessDivinerSchema","containsAll","exists","IndexedDbArchivist","BoundWitnessSchema","isBoundWitness","BoundWitnessDiviner","isBoundWitnessDivinerQueryPayload","PayloadBuilder","openDB","bwValueFilter","key","values","length","undefined","bw","containsAll","IndexedDbBoundWitnessDiviner","BoundWitnessDiviner","configSchemas","IndexedDbBoundWitnessDivinerConfigSchema","defaultConfigSchema","dbName","config","archivist","IndexedDbArchivist","defaultDbName","dbVersion","defaultDbVersion","storeName","defaultStoreName","divineHandler","payloads","query","filter","isBoundWitnessDivinerQueryPayload","pop","result","tryUseDb","db","addresses","payload_hashes","payload_schemas","limit","offset","order","tx","transaction","store","objectStore","results","parsedOffset","parsedLimit","direction","valueFilters","exists","cursor","index","schemaIndexName","openCursor","IDBKeyRange","only","BoundWitnessSchema","advance","value","every","push","continue","done","Promise","all","isBoundWitness","map","PayloadBuilder","build","startHandler","tryGetInitializedDb","dbs","indexedDB","databases","dbExists","some","name","version","openDB","storeExists","objectStoreNames","contains","close","callback"]}
@@ -1,9 +1,11 @@
1
1
  import { BoundWitness } from '@xyo-network/boundwitness-model';
2
2
  import { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract';
3
3
  import { BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model';
4
+ import { Schema } from '@xyo-network/payload-model';
4
5
  import { IndexedDbBoundWitnessDivinerParams } from './Params';
5
6
  export declare class IndexedDbBoundWitnessDiviner<TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams, TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload, TOut extends BoundWitness = BoundWitness> extends BoundWitnessDiviner<TParams, TIn, TOut> {
6
- static configSchemas: string[];
7
+ static configSchemas: Schema[];
8
+ static defaultConfigSchema: Schema;
7
9
  /**
8
10
  * The database name. If not supplied via config, it defaults
9
11
  * to the archivist's name and if archivist's name is not supplied,
@@ -1 +1 @@
1
- {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAsC,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAqC,MAAM,yCAAyC,CAAA;AAK5H,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAA;AAmB7D,qBAAa,4BAA4B,CACvC,OAAO,SAAS,kCAAkC,GAAG,kCAAkC,EACvF,GAAG,SAAS,+BAA+B,GAAG,+BAA+B,EAC7E,IAAI,SAAS,YAAY,GAAG,YAAY,CACxC,SAAQ,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/C,OAAgB,aAAa,WAA6C;IAE1E;;;;;;OAMG;IACH,IAAI,MAAM,WAET;IAED;;OAEG;IACH,IAAI,SAAS,WAEZ;IAED;;;OAGG;IACH,IAAI,SAAS,WAEZ;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cA0DhD,YAAY;IAQrC;;;OAGG;YACW,mBAAmB;IAwBjC;;;;OAIG;YACW,QAAQ;CAcvB"}
1
+ {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAsC,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAqC,MAAM,yCAAyC,CAAA;AAE5H,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAInD,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAA;AAmB7D,qBAAa,4BAA4B,CACvC,OAAO,SAAS,kCAAkC,GAAG,kCAAkC,EACvF,GAAG,SAAS,+BAA+B,GAAG,+BAA+B,EAC7E,IAAI,SAAS,YAAY,GAAG,YAAY,CACxC,SAAQ,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/C,OAAgB,aAAa,EAAE,MAAM,EAAE,CAAqE;IAC5G,OAAgB,mBAAmB,EAAE,MAAM,CAA2C;IAEtF;;;;;;OAMG;IACH,IAAI,MAAM,WAET;IAED;;OAEG;IACH,IAAI,SAAS,WAEZ;IAED;;;OAGG;IACH,IAAI,SAAS,WAEZ;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cA0DhD,YAAY;IAQrC;;;OAGG;YACW,mBAAmB;IAwBjC;;;;OAIG;YACW,QAAQ;CAcvB"}
@@ -1,9 +1,11 @@
1
1
  import { BoundWitness } from '@xyo-network/boundwitness-model';
2
2
  import { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract';
3
3
  import { BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model';
4
+ import { Schema } from '@xyo-network/payload-model';
4
5
  import { IndexedDbBoundWitnessDivinerParams } from './Params';
5
6
  export declare class IndexedDbBoundWitnessDiviner<TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams, TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload, TOut extends BoundWitness = BoundWitness> extends BoundWitnessDiviner<TParams, TIn, TOut> {
6
- static configSchemas: string[];
7
+ static configSchemas: Schema[];
8
+ static defaultConfigSchema: Schema;
7
9
  /**
8
10
  * The database name. If not supplied via config, it defaults
9
11
  * to the archivist's name and if archivist's name is not supplied,
@@ -1 +1 @@
1
- {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAsC,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAqC,MAAM,yCAAyC,CAAA;AAK5H,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAA;AAmB7D,qBAAa,4BAA4B,CACvC,OAAO,SAAS,kCAAkC,GAAG,kCAAkC,EACvF,GAAG,SAAS,+BAA+B,GAAG,+BAA+B,EAC7E,IAAI,SAAS,YAAY,GAAG,YAAY,CACxC,SAAQ,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/C,OAAgB,aAAa,WAA6C;IAE1E;;;;;;OAMG;IACH,IAAI,MAAM,WAET;IAED;;OAEG;IACH,IAAI,SAAS,WAEZ;IAED;;;OAGG;IACH,IAAI,SAAS,WAEZ;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cA0DhD,YAAY;IAQrC;;;OAGG;YACW,mBAAmB;IAwBjC;;;;OAIG;YACW,QAAQ;CAcvB"}
1
+ {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAsC,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAqC,MAAM,yCAAyC,CAAA;AAE5H,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAInD,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAA;AAmB7D,qBAAa,4BAA4B,CACvC,OAAO,SAAS,kCAAkC,GAAG,kCAAkC,EACvF,GAAG,SAAS,+BAA+B,GAAG,+BAA+B,EAC7E,IAAI,SAAS,YAAY,GAAG,YAAY,CACxC,SAAQ,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/C,OAAgB,aAAa,EAAE,MAAM,EAAE,CAAqE;IAC5G,OAAgB,mBAAmB,EAAE,MAAM,CAA2C;IAEtF;;;;;;OAMG;IACH,IAAI,MAAM,WAET;IAED;;OAEG;IACH,IAAI,SAAS,WAEZ;IAED;;;OAGG;IACH,IAAI,SAAS,WAEZ;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cA0DhD,YAAY;IAQrC;;;OAGG;YACW,mBAAmB;IAwBjC;;;;OAIG;YACW,QAAQ;CAcvB"}
@@ -1,9 +1,11 @@
1
1
  import { BoundWitness } from '@xyo-network/boundwitness-model';
2
2
  import { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract';
3
3
  import { BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model';
4
+ import { Schema } from '@xyo-network/payload-model';
4
5
  import { IndexedDbBoundWitnessDivinerParams } from './Params';
5
6
  export declare class IndexedDbBoundWitnessDiviner<TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams, TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload, TOut extends BoundWitness = BoundWitness> extends BoundWitnessDiviner<TParams, TIn, TOut> {
6
- static configSchemas: string[];
7
+ static configSchemas: Schema[];
8
+ static defaultConfigSchema: Schema;
7
9
  /**
8
10
  * The database name. If not supplied via config, it defaults
9
11
  * to the archivist's name and if archivist's name is not supplied,
@@ -1 +1 @@
1
- {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAsC,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAqC,MAAM,yCAAyC,CAAA;AAK5H,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAA;AAmB7D,qBAAa,4BAA4B,CACvC,OAAO,SAAS,kCAAkC,GAAG,kCAAkC,EACvF,GAAG,SAAS,+BAA+B,GAAG,+BAA+B,EAC7E,IAAI,SAAS,YAAY,GAAG,YAAY,CACxC,SAAQ,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/C,OAAgB,aAAa,WAA6C;IAE1E;;;;;;OAMG;IACH,IAAI,MAAM,WAET;IAED;;OAEG;IACH,IAAI,SAAS,WAEZ;IAED;;;OAGG;IACH,IAAI,SAAS,WAEZ;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cA0DhD,YAAY;IAQrC;;;OAGG;YACW,mBAAmB;IAwBjC;;;;OAIG;YACW,QAAQ;CAcvB"}
1
+ {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAsC,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAqC,MAAM,yCAAyC,CAAA;AAE5H,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAInD,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAA;AAmB7D,qBAAa,4BAA4B,CACvC,OAAO,SAAS,kCAAkC,GAAG,kCAAkC,EACvF,GAAG,SAAS,+BAA+B,GAAG,+BAA+B,EAC7E,IAAI,SAAS,YAAY,GAAG,YAAY,CACxC,SAAQ,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/C,OAAgB,aAAa,EAAE,MAAM,EAAE,CAAqE;IAC5G,OAAgB,mBAAmB,EAAE,MAAM,CAA2C;IAEtF;;;;;;OAMG;IACH,IAAI,MAAM,WAET;IAED;;OAEG;IACH,IAAI,SAAS,WAEZ;IAED;;;OAGG;IACH,IAAI,SAAS,WAEZ;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cA0DhD,YAAY;IAQrC;;;OAGG;YACW,mBAAmB;IAwBjC;;;;OAIG;YACW,QAAQ;CAcvB"}
@@ -2,7 +2,9 @@
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
5
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __reflectGet = Reflect.get;
6
8
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
9
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
10
  var __export = (target, all) => {
@@ -22,6 +24,7 @@ var __publicField = (obj, key, value) => {
22
24
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
23
25
  return value;
24
26
  };
27
+ var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
25
28
 
26
29
  // src/index.ts
27
30
  var src_exports = {};
@@ -171,8 +174,10 @@ var _IndexedDbBoundWitnessDiviner = class _IndexedDbBoundWitnessDiviner extends
171
174
  };
172
175
  __name(_IndexedDbBoundWitnessDiviner, "IndexedDbBoundWitnessDiviner");
173
176
  __publicField(_IndexedDbBoundWitnessDiviner, "configSchemas", [
177
+ ...__superGet(_IndexedDbBoundWitnessDiviner, _IndexedDbBoundWitnessDiviner, "configSchemas"),
174
178
  IndexedDbBoundWitnessDivinerConfigSchema
175
179
  ]);
180
+ __publicField(_IndexedDbBoundWitnessDiviner, "defaultConfigSchema", IndexedDbBoundWitnessDivinerConfigSchema);
176
181
  var IndexedDbBoundWitnessDiviner = _IndexedDbBoundWitnessDiviner;
177
182
  // Annotate the CommonJS export names for ESM import in node:
178
183
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts"],"sourcesContent":["export * from './Config'\nexport * from './Diviner'\nexport * from './Params'\nexport * from './Schema'\n","import { BoundWitnessDivinerSchema } from '@xyo-network/diviner-boundwitness-model'\n\nexport const IndexedDbBoundWitnessDivinerSchema = `${BoundWitnessDivinerSchema}.indexeddb`\nexport type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema\n","import { IndexDescription } from '@xyo-network/archivist-model'\nimport { DivinerConfig } from '@xyo-network/diviner-model'\n\nimport { IndexedDbBoundWitnessDivinerSchema } from './Schema'\n\nexport const IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config`\nexport type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema\n\nexport type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{\n /**\n * The database name\n */\n dbName?: string\n /**\n * The version of the DB, defaults to 1\n */\n dbVersion?: number\n schema: IndexedDbBoundWitnessDivinerConfigSchema\n /**\n * The storage configuration\n * // TODO: Hoist to main diviner config\n */\n storage?: {\n /**\n * The indexes to create on the object store\n */\n indexes?: IndexDescription[]\n }\n /**\n * The name of the object store\n */\n storeName?: string\n}>\n","import { containsAll } from '@xylabs/array'\nimport { exists } from '@xylabs/exists'\nimport { IndexedDbArchivist } from '@xyo-network/archivist-indexeddb'\nimport { BoundWitness, BoundWitnessSchema, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport { BoundWitnessDivinerQueryPayload, isBoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { IDBPDatabase, openDB } from 'idb'\n\nimport { IndexedDbBoundWitnessDivinerConfigSchema } from './Config'\nimport { IndexedDbBoundWitnessDivinerParams } from './Params'\n\ninterface BoundWitnessStore {\n [s: string]: BoundWitness\n}\n\ntype ValueFilter = (bw?: BoundWitness | null) => boolean\n\nconst bwValueFilter = (\n key: keyof Pick<BoundWitness, 'addresses' | 'payload_hashes' | 'payload_schemas'>,\n values?: string[],\n): ValueFilter | undefined => {\n if (!values || values?.length === 0) return undefined\n return (bw) => {\n if (!bw) return false\n return containsAll(bw[key], values)\n }\n}\n\nexport class IndexedDbBoundWitnessDiviner<\n TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override configSchemas = [IndexedDbBoundWitnessDivinerConfigSchema]\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the archivist's name and if archivist's name is not supplied,\n * it defaults to `archivist`. This behavior\n * biases towards a single, isolated DB per archivist which seems to\n * make the most sense for 99% of use cases.\n */\n get dbName() {\n return this.config?.dbName ?? this.config?.archivist ?? IndexedDbArchivist.defaultDbName\n }\n\n /**\n * The database version. If not supplied via config, it defaults to 1.\n */\n get dbVersion() {\n return this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion\n }\n\n /**\n * The name of the object store. If not supplied via config, it defaults\n * to `payloads`.\n */\n get storeName() {\n return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n const query = payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop()\n if (!query) return []\n\n const result = await this.tryUseDb(async (db) => {\n const { addresses, payload_hashes, payload_schemas, limit, offset, order } = query\n const tx = db.transaction(this.storeName, 'readonly')\n const store = tx.objectStore(this.storeName)\n const results: TOut[] = []\n let parsedOffset = offset ?? 0\n const parsedLimit = limit ?? 10\n const direction: IDBCursorDirection = order === 'desc' ? 'prev' : 'next'\n const valueFilters: ValueFilter[] = [\n bwValueFilter('addresses', addresses),\n bwValueFilter('payload_hashes', payload_hashes),\n bwValueFilter('payload_schemas', payload_schemas),\n ].filter(exists)\n // Only iterate over BWs\n let cursor = await store.index(IndexedDbArchivist.schemaIndexName).openCursor(IDBKeyRange.only(BoundWitnessSchema), direction)\n\n // If we're filtering on more than just the schema, we need to\n // iterate through all the results\n if (valueFilters.length === 0) {\n // Skip records until the offset is reached\n while (cursor && parsedOffset > 0) {\n cursor = await cursor.advance(parsedOffset)\n parsedOffset = 0 // Reset offset after skipping\n }\n }\n // Collect results up to the limit\n while (cursor && results.length < parsedLimit) {\n const value = cursor.value\n if (value) {\n // If we're filtering on more than just the schema\n if (valueFilters.length > 0) {\n // Ensure all filters pass\n if (valueFilters.every((filter) => filter(value))) {\n // Then save the value\n results.push(value)\n }\n } else {\n // Otherwise just save the value\n results.push(value)\n }\n }\n cursor = await cursor.continue()\n }\n await tx.done\n // Remove any metadata before returning to the client\n return await Promise.all(\n results.filter(isBoundWitness).map((bw) => {\n return PayloadBuilder.build(bw)\n }),\n )\n })\n return result ?? []\n }\n\n protected override async startHandler() {\n await super.startHandler()\n // NOTE: Do not eager initialize the DB here. It will cause the\n // DB to be created by this process and then the DB will be\n // in a bad state for other processes that need to create the DB.\n return true\n }\n\n /**\n * Checks that the desired DB/objectStore exists and is initialized to the correct version\n * @returns The initialized DB or undefined if it does not exist in the desired state\n */\n private async tryGetInitializedDb(): Promise<IDBPDatabase<BoundWitnessStore> | undefined> {\n // Enumerate the DBs\n const dbs = await indexedDB.databases()\n // Check that the DB exists at the desired version\n const dbExists = dbs.some((db) => {\n return db.name === this.dbName && db.version === this.dbVersion\n })\n // If the DB exists at the desired version\n if (dbExists) {\n // If the db does exist, open it\n const db = await openDB<BoundWitnessStore>(this.dbName, this.dbVersion)\n // Check that the desired objectStore exists\n const storeExists = db.objectStoreNames.contains(this.storeName)\n // If the correct db/version/objectStore exists\n if (storeExists) {\n return db\n } else {\n // Otherwise close the db so the process that is going to update the\n // db can open it\n db.close()\n }\n }\n }\n\n /**\n * Executes a callback with the initialized DB and then closes the db\n * @param callback The method to execute with the initialized DB\n * @returns\n */\n private async tryUseDb<T>(callback: (db: IDBPDatabase<BoundWitnessStore>) => Promise<T> | T): Promise<T | undefined> {\n // Get the initialized DB\n const db = await this.tryGetInitializedDb()\n if (db) {\n try {\n // Perform the callback\n return await callback(db)\n } finally {\n // Close the DB\n db.close()\n }\n }\n return undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAA,wCAA0C;AAEnC,IAAMA,qCAAqC,GAAGC,2DAAAA;;;ACG9C,IAAMC,2CAA2C,GAAGC,kCAAAA;;;ACL3D,mBAA4B;AAC5B,oBAAuB;AACvB,iCAAmC;AACnC,gCAAiE;AACjE,2CAAoC;AACpC,IAAAC,qCAAmF;AACnF,6BAA+B;AAC/B,iBAAqC;AAWrC,IAAMC,gBAAgB,wBACpBC,KACAC,WAAAA;AAEA,MAAI,CAACA,WAAUA,iCAAQC,YAAW;AAAG,WAAOC;AAC5C,SAAO,CAACC,OAAAA;AACN,QAAI,CAACA;AAAI,aAAO;AAChB,eAAOC,0BAAYD,GAAGJ,GAAAA,GAAMC,MAAAA;EAC9B;AACF,GATsB;AAWf,IAAMK,gCAAN,MAAMA,sCAIHC,yDAAAA;;;;;;;;EAUR,IAAIC,SAAS;AA3Cf;AA4CI,aAAO,UAAKC,WAAL,mB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WitnessDivinerSchema","IndexedDbBoundWitnessDivinerConfigSchema","IndexedDbBoundWitnessDivinerSchema","import_diviner_boundwitness_model","bwValueFilter","key","values","length","undefined","bw","containsAll","IndexedDbBoundWitnessDiviner","BoundWitnessDiviner","dbName","config","archivist","IndexedDbArchivist","defaultDbName","dbVersion","defaultDbVersion","storeName","defaultStoreName","divineHandler","payloads","query","filter","isBoundWitnessDivinerQueryPayload","pop","result","tryUseDb","db","addresses","payload_hashes","payload_schemas","limit","offset","order","tx","transaction","store","objectStore","results","parsedOffset","parsedLimit","direction","valueFilters","exists","cursor","index","schemaIndexName","openCursor","IDBKeyRange","only","BoundWitnessSchema","advance","value","every","push","continue","done","Promise","all","isBoundWitness","map","PayloadBuilder","build","startHandler","tryGetInitializedDb","dbs","indexedDB","databases","dbExists","some","name","version","openDB","storeExists","objectStoreNames","contains","close","callback","configSchemas","IndexedDbBoundWitnessDivinerConfigSchema"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts"],"sourcesContent":["export * from './Config'\nexport * from './Diviner'\nexport * from './Params'\nexport * from './Schema'\n","import { BoundWitnessDivinerSchema } from '@xyo-network/diviner-boundwitness-model'\n\nexport const IndexedDbBoundWitnessDivinerSchema = `${BoundWitnessDivinerSchema}.indexeddb`\nexport type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema\n","import { IndexDescription } from '@xyo-network/archivist-model'\nimport { DivinerConfig } from '@xyo-network/diviner-model'\n\nimport { IndexedDbBoundWitnessDivinerSchema } from './Schema'\n\nexport const IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config`\nexport type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema\n\nexport type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{\n /**\n * The database name\n */\n dbName?: string\n /**\n * The version of the DB, defaults to 1\n */\n dbVersion?: number\n schema: IndexedDbBoundWitnessDivinerConfigSchema\n /**\n * The storage configuration\n * // TODO: Hoist to main diviner config\n */\n storage?: {\n /**\n * The indexes to create on the object store\n */\n indexes?: IndexDescription[]\n }\n /**\n * The name of the object store\n */\n storeName?: string\n}>\n","import { containsAll } from '@xylabs/array'\nimport { exists } from '@xylabs/exists'\nimport { IndexedDbArchivist } from '@xyo-network/archivist-indexeddb'\nimport { BoundWitness, BoundWitnessSchema, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport { BoundWitnessDivinerQueryPayload, isBoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Schema } from '@xyo-network/payload-model'\nimport { IDBPDatabase, openDB } from 'idb'\n\nimport { IndexedDbBoundWitnessDivinerConfigSchema } from './Config'\nimport { IndexedDbBoundWitnessDivinerParams } from './Params'\n\ninterface BoundWitnessStore {\n [s: string]: BoundWitness\n}\n\ntype ValueFilter = (bw?: BoundWitness | null) => boolean\n\nconst bwValueFilter = (\n key: keyof Pick<BoundWitness, 'addresses' | 'payload_hashes' | 'payload_schemas'>,\n values?: string[],\n): ValueFilter | undefined => {\n if (!values || values?.length === 0) return undefined\n return (bw) => {\n if (!bw) return false\n return containsAll(bw[key], values)\n }\n}\n\nexport class IndexedDbBoundWitnessDiviner<\n TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override configSchemas: Schema[] = [...super.configSchemas, IndexedDbBoundWitnessDivinerConfigSchema]\n static override defaultConfigSchema: Schema = IndexedDbBoundWitnessDivinerConfigSchema\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the archivist's name and if archivist's name is not supplied,\n * it defaults to `archivist`. This behavior\n * biases towards a single, isolated DB per archivist which seems to\n * make the most sense for 99% of use cases.\n */\n get dbName() {\n return this.config?.dbName ?? this.config?.archivist ?? IndexedDbArchivist.defaultDbName\n }\n\n /**\n * The database version. If not supplied via config, it defaults to 1.\n */\n get dbVersion() {\n return this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion\n }\n\n /**\n * The name of the object store. If not supplied via config, it defaults\n * to `payloads`.\n */\n get storeName() {\n return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n const query = payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop()\n if (!query) return []\n\n const result = await this.tryUseDb(async (db) => {\n const { addresses, payload_hashes, payload_schemas, limit, offset, order } = query\n const tx = db.transaction(this.storeName, 'readonly')\n const store = tx.objectStore(this.storeName)\n const results: TOut[] = []\n let parsedOffset = offset ?? 0\n const parsedLimit = limit ?? 10\n const direction: IDBCursorDirection = order === 'desc' ? 'prev' : 'next'\n const valueFilters: ValueFilter[] = [\n bwValueFilter('addresses', addresses),\n bwValueFilter('payload_hashes', payload_hashes),\n bwValueFilter('payload_schemas', payload_schemas),\n ].filter(exists)\n // Only iterate over BWs\n let cursor = await store.index(IndexedDbArchivist.schemaIndexName).openCursor(IDBKeyRange.only(BoundWitnessSchema), direction)\n\n // If we're filtering on more than just the schema, we need to\n // iterate through all the results\n if (valueFilters.length === 0) {\n // Skip records until the offset is reached\n while (cursor && parsedOffset > 0) {\n cursor = await cursor.advance(parsedOffset)\n parsedOffset = 0 // Reset offset after skipping\n }\n }\n // Collect results up to the limit\n while (cursor && results.length < parsedLimit) {\n const value = cursor.value\n if (value) {\n // If we're filtering on more than just the schema\n if (valueFilters.length > 0) {\n // Ensure all filters pass\n if (valueFilters.every((filter) => filter(value))) {\n // Then save the value\n results.push(value)\n }\n } else {\n // Otherwise just save the value\n results.push(value)\n }\n }\n cursor = await cursor.continue()\n }\n await tx.done\n // Remove any metadata before returning to the client\n return await Promise.all(\n results.filter(isBoundWitness).map((bw) => {\n return PayloadBuilder.build(bw)\n }),\n )\n })\n return result ?? []\n }\n\n protected override async startHandler() {\n await super.startHandler()\n // NOTE: Do not eager initialize the DB here. It will cause the\n // DB to be created by this process and then the DB will be\n // in a bad state for other processes that need to create the DB.\n return true\n }\n\n /**\n * Checks that the desired DB/objectStore exists and is initialized to the correct version\n * @returns The initialized DB or undefined if it does not exist in the desired state\n */\n private async tryGetInitializedDb(): Promise<IDBPDatabase<BoundWitnessStore> | undefined> {\n // Enumerate the DBs\n const dbs = await indexedDB.databases()\n // Check that the DB exists at the desired version\n const dbExists = dbs.some((db) => {\n return db.name === this.dbName && db.version === this.dbVersion\n })\n // If the DB exists at the desired version\n if (dbExists) {\n // If the db does exist, open it\n const db = await openDB<BoundWitnessStore>(this.dbName, this.dbVersion)\n // Check that the desired objectStore exists\n const storeExists = db.objectStoreNames.contains(this.storeName)\n // If the correct db/version/objectStore exists\n if (storeExists) {\n return db\n } else {\n // Otherwise close the db so the process that is going to update the\n // db can open it\n db.close()\n }\n }\n }\n\n /**\n * Executes a callback with the initialized DB and then closes the db\n * @param callback The method to execute with the initialized DB\n * @returns\n */\n private async tryUseDb<T>(callback: (db: IDBPDatabase<BoundWitnessStore>) => Promise<T> | T): Promise<T | undefined> {\n // Get the initialized DB\n const db = await this.tryGetInitializedDb()\n if (db) {\n try {\n // Perform the callback\n return await callback(db)\n } finally {\n // Close the DB\n db.close()\n }\n }\n return undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAA,wCAA0C;AAEnC,IAAMA,qCAAqC,GAAGC,2DAAAA;;;ACG9C,IAAMC,2CAA2C,GAAGC,kCAAAA;;;ACL3D,mBAA4B;AAC5B,oBAAuB;AACvB,iCAAmC;AACnC,gCAAiE;AACjE,2CAAoC;AACpC,IAAAC,qCAAmF;AACnF,6BAA+B;AAE/B,iBAAqC;AAWrC,IAAMC,g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F;;;;;;EAOA,MAAclD,SAAYmD,UAA2F;AAEnH,UAAMlD,KAAK,MAAM,KAAKqC,oBAAmB;AACzC,QAAIrC,IAAI;AACN,UAAI;AAEF,eAAO,MAAMkD,SAASlD,EAAAA;MACxB,UAAA;AAEEA,WAAGiD,MAAK;MACV;IACF;AACA,WAAOvE;EACT;AACF;AA/IUI;AACR,cALWD,+BAKKsE,iBAA0B;KAAI,yEAAMA;EAAeC;;AACnE,cANWvE,+BAMKwE,uBAA8BD;AANzC,IAAMvE,+BAAN;","names":["IndexedDbBoundWitnessDivinerSchema","BoundWitnessDivinerSchema","IndexedDbBoundWitnessDivinerConfigSchema","IndexedDbBoundWitnessDivinerSchema","import_diviner_boundwitness_model","bwValueFilter","key","values","length","undefined","bw","containsAll","IndexedDbBoundWitnessDiviner","BoundWitnessDiviner","dbName","config","archivist","IndexedDbArchivist","defaultDbName","dbVersion","defaultDbVersion","storeName","defaultStoreName","divineHandler","payloads","query","filter","isBoundWitnessDivinerQueryPayload","pop","result","tryUseDb","db","addresses","payload_hashes","payload_schemas","limit","offset","order","tx","transaction","store","objectStore","results","parsedOffset","parsedLimit","direction","valueFilters","exists","cursor","index","schemaIndexName","openCursor","IDBKeyRange","only","BoundWitnessSchema","advance","value","every","push","continue","done","Promise","all","isBoundWitness","map","PayloadBuilder","build","startHandler","tryGetInitializedDb","dbs","indexedDB","databases","dbExists","some","name","version","openDB","storeExists","objectStoreNames","contains","close","callback","configSchemas","IndexedDbBoundWitnessDivinerConfigSchema","defaultConfigSchema"]}
@@ -1,10 +1,13 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __getProtoOf = Object.getPrototypeOf;
3
+ var __reflectGet = Reflect.get;
2
4
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
5
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
6
  var __publicField = (obj, key, value) => {
5
7
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
8
  return value;
7
9
  };
10
+ var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
8
11
 
9
12
  // src/Schema.ts
10
13
  import { BoundWitnessDivinerSchema } from "@xyo-network/diviner-boundwitness-model";
@@ -145,8 +148,10 @@ var _IndexedDbBoundWitnessDiviner = class _IndexedDbBoundWitnessDiviner extends
145
148
  };
146
149
  __name(_IndexedDbBoundWitnessDiviner, "IndexedDbBoundWitnessDiviner");
147
150
  __publicField(_IndexedDbBoundWitnessDiviner, "configSchemas", [
151
+ ...__superGet(_IndexedDbBoundWitnessDiviner, _IndexedDbBoundWitnessDiviner, "configSchemas"),
148
152
  IndexedDbBoundWitnessDivinerConfigSchema
149
153
  ]);
154
+ __publicField(_IndexedDbBoundWitnessDiviner, "defaultConfigSchema", IndexedDbBoundWitnessDivinerConfigSchema);
150
155
  var IndexedDbBoundWitnessDiviner = _IndexedDbBoundWitnessDiviner;
151
156
  export {
152
157
  IndexedDbBoundWitnessDiviner,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts"],"sourcesContent":["import { BoundWitnessDivinerSchema } from '@xyo-network/diviner-boundwitness-model'\n\nexport const IndexedDbBoundWitnessDivinerSchema = `${BoundWitnessDivinerSchema}.indexeddb`\nexport type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema\n","import { IndexDescription } from '@xyo-network/archivist-model'\nimport { DivinerConfig } from '@xyo-network/diviner-model'\n\nimport { IndexedDbBoundWitnessDivinerSchema } from './Schema'\n\nexport const IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config`\nexport type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema\n\nexport type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{\n /**\n * The database name\n */\n dbName?: string\n /**\n * The version of the DB, defaults to 1\n */\n dbVersion?: number\n schema: IndexedDbBoundWitnessDivinerConfigSchema\n /**\n * The storage configuration\n * // TODO: Hoist to main diviner config\n */\n storage?: {\n /**\n * The indexes to create on the object store\n */\n indexes?: IndexDescription[]\n }\n /**\n * The name of the object store\n */\n storeName?: string\n}>\n","import { containsAll } from '@xylabs/array'\nimport { exists } from '@xylabs/exists'\nimport { IndexedDbArchivist } from '@xyo-network/archivist-indexeddb'\nimport { BoundWitness, BoundWitnessSchema, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport { BoundWitnessDivinerQueryPayload, isBoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { IDBPDatabase, openDB } from 'idb'\n\nimport { IndexedDbBoundWitnessDivinerConfigSchema } from './Config'\nimport { IndexedDbBoundWitnessDivinerParams } from './Params'\n\ninterface BoundWitnessStore {\n [s: string]: BoundWitness\n}\n\ntype ValueFilter = (bw?: BoundWitness | null) => boolean\n\nconst bwValueFilter = (\n key: keyof Pick<BoundWitness, 'addresses' | 'payload_hashes' | 'payload_schemas'>,\n values?: string[],\n): ValueFilter | undefined => {\n if (!values || values?.length === 0) return undefined\n return (bw) => {\n if (!bw) return false\n return containsAll(bw[key], values)\n }\n}\n\nexport class IndexedDbBoundWitnessDiviner<\n TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override configSchemas = [IndexedDbBoundWitnessDivinerConfigSchema]\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the archivist's name and if archivist's name is not supplied,\n * it defaults to `archivist`. This behavior\n * biases towards a single, isolated DB per archivist which seems to\n * make the most sense for 99% of use cases.\n */\n get dbName() {\n return this.config?.dbName ?? this.config?.archivist ?? IndexedDbArchivist.defaultDbName\n }\n\n /**\n * The database version. If not supplied via config, it defaults to 1.\n */\n get dbVersion() {\n return this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion\n }\n\n /**\n * The name of the object store. If not supplied via config, it defaults\n * to `payloads`.\n */\n get storeName() {\n return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n const query = payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop()\n if (!query) return []\n\n const result = await this.tryUseDb(async (db) => {\n const { addresses, payload_hashes, payload_schemas, limit, offset, order } = query\n const tx = db.transaction(this.storeName, 'readonly')\n const store = tx.objectStore(this.storeName)\n const results: TOut[] = []\n let parsedOffset = offset ?? 0\n const parsedLimit = limit ?? 10\n const direction: IDBCursorDirection = order === 'desc' ? 'prev' : 'next'\n const valueFilters: ValueFilter[] = [\n bwValueFilter('addresses', addresses),\n bwValueFilter('payload_hashes', payload_hashes),\n bwValueFilter('payload_schemas', payload_schemas),\n ].filter(exists)\n // Only iterate over BWs\n let cursor = await store.index(IndexedDbArchivist.schemaIndexName).openCursor(IDBKeyRange.only(BoundWitnessSchema), direction)\n\n // If we're filtering on more than just the schema, we need to\n // iterate through all the results\n if (valueFilters.length === 0) {\n // Skip records until the offset is reached\n while (cursor && parsedOffset > 0) {\n cursor = await cursor.advance(parsedOffset)\n parsedOffset = 0 // Reset offset after skipping\n }\n }\n // Collect results up to the limit\n while (cursor && results.length < parsedLimit) {\n const value = cursor.value\n if (value) {\n // If we're filtering on more than just the schema\n if (valueFilters.length > 0) {\n // Ensure all filters pass\n if (valueFilters.every((filter) => filter(value))) {\n // Then save the value\n results.push(value)\n }\n } else {\n // Otherwise just save the value\n results.push(value)\n }\n }\n cursor = await cursor.continue()\n }\n await tx.done\n // Remove any metadata before returning to the client\n return await Promise.all(\n results.filter(isBoundWitness).map((bw) => {\n return PayloadBuilder.build(bw)\n }),\n )\n })\n return result ?? []\n }\n\n protected override async startHandler() {\n await super.startHandler()\n // NOTE: Do not eager initialize the DB here. It will cause the\n // DB to be created by this process and then the DB will be\n // in a bad state for other processes that need to create the DB.\n return true\n }\n\n /**\n * Checks that the desired DB/objectStore exists and is initialized to the correct version\n * @returns The initialized DB or undefined if it does not exist in the desired state\n */\n private async tryGetInitializedDb(): Promise<IDBPDatabase<BoundWitnessStore> | undefined> {\n // Enumerate the DBs\n const dbs = await indexedDB.databases()\n // Check that the DB exists at the desired version\n const dbExists = dbs.some((db) => {\n return db.name === this.dbName && db.version === this.dbVersion\n })\n // If the DB exists at the desired version\n if (dbExists) {\n // If the db does exist, open it\n const db = await openDB<BoundWitnessStore>(this.dbName, this.dbVersion)\n // Check that the desired objectStore exists\n const storeExists = db.objectStoreNames.contains(this.storeName)\n // If the correct db/version/objectStore exists\n if (storeExists) {\n return db\n } else {\n // Otherwise close the db so the process that is going to update the\n // db can open it\n db.close()\n }\n }\n }\n\n /**\n * Executes a callback with the initialized DB and then closes the db\n * @param callback The method to execute with the initialized DB\n * @returns\n */\n private async tryUseDb<T>(callback: (db: IDBPDatabase<BoundWitnessStore>) => Promise<T> | T): Promise<T | undefined> {\n // Get the initialized DB\n const db = await this.tryGetInitializedDb()\n if (db) {\n try {\n // Perform the callback\n return await callback(db)\n } finally {\n // Close the DB\n db.close()\n }\n }\n return undefined\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAASA,iCAAiC;AAEnC,IAAMC,qCAAqC,GAAGD,yBAAAA;;;ACG9C,IAAME,2CAA2C,GAAGC,kCAAAA;;;ACL3D,SAASC,mBAAmB;AAC5B,SAASC,cAAc;AACvB,SAASC,0BAA0B;AACnC,SAAuBC,oBAAoBC,sBAAsB;AACjE,SAASC,2BAA2B;AACpC,SAA0CC,yCAAyC;AACnF,SAASC,sBAAsB;AAC/B,SAAuBC,cAAc;AAWrC,IAAMC,gBAAgB,wBACpBC,KACAC,WAAAA;AAEA,MAAI,CAACA,WAAUA,iCAAQC,YAAW;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oBAAmB;AACzC,QAAIrC,IAAI;AACN,UAAI;AAEF,eAAO,MAAMkD,SAASlD,EAAAA;MACxB,UAAA;AAEEA,WAAGiD,MAAK;MACV;IACF;AACA,WAAOvE;EACT;AACF;AA9IUI;AACR,cALWD,+BAKKsE,iBAAgB;EAACC;;AAL5B,IAAMvE,+BAAN;","names":["BoundWitnessDivinerSchema","IndexedDbBoundWitnessDivinerSchema","IndexedDbBoundWitnessDivinerConfigSchema","IndexedDbBoundWitnessDivinerSchema","containsAll","exists","IndexedDbArchivist","BoundWitnessSchema","isBoundWitness","BoundWitnessDiviner","isBoundWitnessDivinerQueryPayload","PayloadBuilder","openDB","bwValueFilter","key","values","length","undefined","bw","containsAll","IndexedDbBoundWitnessDiviner","BoundWitnessDiviner","dbName","config","archivist","IndexedDbArchivist","defaultDbName","dbVersion","defaultDbVersion","storeName","defaultStoreName","divineHandler","payloads","query","filter","isBoundWitnessDivinerQueryPayload","pop","result","tryUseDb","db","addresses","payload_hashes","payload_schemas","limit","offset","order","tx","transaction","store","objectStore","results","parsedOffset","parsedLimit","direction","valueFilters","exists","cursor","index","schemaIndexName","openCursor","IDBKeyRange","only","BoundWitnessSchema","advance","value","every","push","continue","done","Promise","all","isBoundWitness","map","PayloadBuilder","build","startHandler","tryGetInitializedDb","dbs","indexedDB","databases","dbExists","some","name","version","openDB","storeExists","objectStoreNames","contains","close","callback","configSchemas","IndexedDbBoundWitnessDivinerConfigSchema"]}
1
+ {"version":3,"sources":["../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts"],"sourcesContent":["import { BoundWitnessDivinerSchema } from '@xyo-network/diviner-boundwitness-model'\n\nexport const IndexedDbBoundWitnessDivinerSchema = `${BoundWitnessDivinerSchema}.indexeddb`\nexport type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema\n","import { IndexDescription } from '@xyo-network/archivist-model'\nimport { DivinerConfig } from '@xyo-network/diviner-model'\n\nimport { IndexedDbBoundWitnessDivinerSchema } from './Schema'\n\nexport const IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config`\nexport type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema\n\nexport type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{\n /**\n * The database name\n */\n dbName?: string\n /**\n * The version of the DB, defaults to 1\n */\n dbVersion?: number\n schema: IndexedDbBoundWitnessDivinerConfigSchema\n /**\n * The storage configuration\n * // TODO: Hoist to main diviner config\n */\n storage?: {\n /**\n * The indexes to create on the object store\n */\n indexes?: IndexDescription[]\n }\n /**\n * The name of the object store\n */\n storeName?: string\n}>\n","import { containsAll } from '@xylabs/array'\nimport { exists } from '@xylabs/exists'\nimport { IndexedDbArchivist } from '@xyo-network/archivist-indexeddb'\nimport { BoundWitness, BoundWitnessSchema, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport { BoundWitnessDivinerQueryPayload, isBoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Schema } from '@xyo-network/payload-model'\nimport { IDBPDatabase, openDB } from 'idb'\n\nimport { IndexedDbBoundWitnessDivinerConfigSchema } from './Config'\nimport { IndexedDbBoundWitnessDivinerParams } from './Params'\n\ninterface BoundWitnessStore {\n [s: string]: BoundWitness\n}\n\ntype ValueFilter = (bw?: BoundWitness | null) => boolean\n\nconst bwValueFilter = (\n key: keyof Pick<BoundWitness, 'addresses' | 'payload_hashes' | 'payload_schemas'>,\n values?: string[],\n): ValueFilter | undefined => {\n if (!values || values?.length === 0) return undefined\n return (bw) => {\n if (!bw) return false\n return containsAll(bw[key], values)\n }\n}\n\nexport class IndexedDbBoundWitnessDiviner<\n TParams extends IndexedDbBoundWitnessDivinerParams = IndexedDbBoundWitnessDivinerParams,\n TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,\n TOut extends BoundWitness = BoundWitness,\n> extends BoundWitnessDiviner<TParams, TIn, TOut> {\n static override configSchemas: Schema[] = [...super.configSchemas, IndexedDbBoundWitnessDivinerConfigSchema]\n static override defaultConfigSchema: Schema = IndexedDbBoundWitnessDivinerConfigSchema\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the archivist's name and if archivist's name is not supplied,\n * it defaults to `archivist`. This behavior\n * biases towards a single, isolated DB per archivist which seems to\n * make the most sense for 99% of use cases.\n */\n get dbName() {\n return this.config?.dbName ?? this.config?.archivist ?? IndexedDbArchivist.defaultDbName\n }\n\n /**\n * The database version. If not supplied via config, it defaults to 1.\n */\n get dbVersion() {\n return this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion\n }\n\n /**\n * The name of the object store. If not supplied via config, it defaults\n * to `payloads`.\n */\n get storeName() {\n return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n const query = payloads?.filter(isBoundWitnessDivinerQueryPayload)?.pop()\n if (!query) return []\n\n const result = await this.tryUseDb(async (db) => {\n const { addresses, payload_hashes, payload_schemas, limit, offset, order } = query\n const tx = db.transaction(this.storeName, 'readonly')\n const store = tx.objectStore(this.storeName)\n const results: TOut[] = []\n let parsedOffset = offset ?? 0\n const parsedLimit = limit ?? 10\n const direction: IDBCursorDirection = order === 'desc' ? 'prev' : 'next'\n const valueFilters: ValueFilter[] = [\n bwValueFilter('addresses', addresses),\n bwValueFilter('payload_hashes', payload_hashes),\n bwValueFilter('payload_schemas', payload_schemas),\n ].filter(exists)\n // Only iterate over BWs\n let cursor = await store.index(IndexedDbArchivist.schemaIndexName).openCursor(IDBKeyRange.only(BoundWitnessSchema), direction)\n\n // If we're filtering on more than just the schema, we need to\n // iterate through all the results\n if (valueFilters.length === 0) {\n // Skip records until the offset is reached\n while (cursor && parsedOffset > 0) {\n cursor = await cursor.advance(parsedOffset)\n parsedOffset = 0 // Reset offset after skipping\n }\n }\n // Collect results up to the limit\n while (cursor && results.length < parsedLimit) {\n const value = cursor.value\n if (value) {\n // If we're filtering on more than just the schema\n if (valueFilters.length > 0) {\n // Ensure all filters pass\n if (valueFilters.every((filter) => filter(value))) {\n // Then save the value\n results.push(value)\n }\n } else {\n // Otherwise just save the value\n results.push(value)\n }\n }\n cursor = await cursor.continue()\n }\n await tx.done\n // Remove any metadata before returning to the client\n return await Promise.all(\n results.filter(isBoundWitness).map((bw) => {\n return PayloadBuilder.build(bw)\n }),\n )\n })\n return result ?? []\n }\n\n protected override async startHandler() {\n await super.startHandler()\n // NOTE: Do not eager initialize the DB here. It will cause the\n // DB to be created by this process and then the DB will be\n // in a bad state for other processes that need to create the DB.\n return true\n }\n\n /**\n * Checks that the desired DB/objectStore exists and is initialized to the correct version\n * @returns The initialized DB or undefined if it does not exist in the desired state\n */\n private async tryGetInitializedDb(): Promise<IDBPDatabase<BoundWitnessStore> | undefined> {\n // Enumerate the DBs\n const dbs = await indexedDB.databases()\n // Check that the DB exists at the desired version\n const dbExists = dbs.some((db) => {\n return db.name === this.dbName && db.version === this.dbVersion\n })\n // If the DB exists at the desired version\n if (dbExists) {\n // If the db does exist, open it\n const db = await openDB<BoundWitnessStore>(this.dbName, this.dbVersion)\n // Check that the desired objectStore exists\n const storeExists = db.objectStoreNames.contains(this.storeName)\n // If the correct db/version/objectStore exists\n if (storeExists) {\n return db\n } else {\n // Otherwise close the db so the process that is going to update the\n // db can open it\n db.close()\n }\n }\n }\n\n /**\n * Executes a callback with the initialized DB and then closes the db\n * @param callback The method to execute with the initialized DB\n * @returns\n */\n private async tryUseDb<T>(callback: (db: IDBPDatabase<BoundWitnessStore>) => Promise<T> | T): Promise<T | undefined> {\n // Get the initialized DB\n const db = await this.tryGetInitializedDb()\n if (db) {\n try {\n // Perform the callback\n return await callback(db)\n } finally {\n // Close the DB\n db.close()\n }\n }\n return undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAASA,i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K5D,UAAUiB,GAAG4C,YAAY,KAAKxD;IACxD,CAAA;AAEA,QAAIqD,UAAU;AAEZ,YAAMzC,KAAK,MAAM6C,OAA0B,KAAK9D,QAAQ,KAAKK,SAAS;AAEtE,YAAM0D,cAAc9C,GAAG+C,iBAAiBC,SAAS,KAAK1D,SAAS;AAE/D,UAAIwD,aAAa;AACf,eAAO9C;MACT,OAAO;AAGLA,WAAGiD,MAAK;MACV;IACF;EACF;;;;;;EAOA,MAAclD,SAAYmD,UAA2F;AAEnH,UAAMlD,KAAK,MAAM,KAAKqC,oBAAmB;AACzC,QAAIrC,IAAI;AACN,UAAI;AAEF,eAAO,MAAMkD,SAASlD,EAAAA;MACxB,UAAA;AAEEA,WAAGiD,MAAK;MACV;IACF;AACA,WAAOvE;EACT;AACF;AA/IUI;AACR,cALWD,+BAKKsE,iBAA0B;KAAI,yEAAMA;EAAeC;;AACnE,cANWvE,+BAMKwE,uBAA8BD;AANzC,IAAMvE,+BAAN;","names":["BoundWitnessDivinerSchema","IndexedDbBoundWitnessDivinerSchema","IndexedDbBoundWitnessDivinerConfigSchema","IndexedDbBoundWitnessDivinerSchema","containsAll","exists","IndexedDbArchivist","BoundWitnessSchema","isBoundWitness","BoundWitnessDiviner","isBoundWitnessDivinerQueryPayload","PayloadBuilder","openDB","bwValueFilter","key","values","length","undefined","bw","containsAll","IndexedDbBoundWitnessDiviner","BoundWitnessDiviner","dbName","config","archivist","IndexedDbArchivist","defaultDbName","dbVersion","defaultDbVersion","storeName","defaultStoreName","divineHandler","payloads","query","filter","isBoundWitnessDivinerQueryPayload","pop","result","tryUseDb","db","addresses","payload_hashes","payload_schemas","limit","offset","order","tx","transaction","store","objectStore","results","parsedOffset","parsedLimit","direction","valueFilters","exists","cursor","index","schemaIndexName","openCursor","IDBKeyRange","only","BoundWitnessSchema","advance","value","every","push","continue","done","Promise","all","isBoundWitness","map","PayloadBuilder","build","startHandler","tryGetInitializedDb","dbs","indexedDB","databases","dbExists","some","name","version","openDB","storeExists","objectStoreNames","contains","close","callback","configSchemas","IndexedDbBoundWitnessDivinerConfigSchema","defaultConfigSchema"]}
package/package.json CHANGED
@@ -12,25 +12,25 @@
12
12
  "dependencies": {
13
13
  "@xylabs/array": "^3.1.8",
14
14
  "@xylabs/exists": "^3.1.8",
15
- "@xyo-network/archivist-indexeddb": "~2.96.2",
16
- "@xyo-network/archivist-model": "~2.96.2",
17
- "@xyo-network/boundwitness-model": "~2.96.2",
18
- "@xyo-network/diviner-boundwitness-abstract": "~2.96.2",
19
- "@xyo-network/diviner-boundwitness-model": "~2.96.2",
20
- "@xyo-network/diviner-model": "~2.96.2",
21
- "@xyo-network/module-model": "~2.96.2",
22
- "@xyo-network/payload-builder": "~2.96.2",
15
+ "@xyo-network/archivist-indexeddb": "~2.97.1",
16
+ "@xyo-network/archivist-model": "~2.97.1",
17
+ "@xyo-network/boundwitness-model": "~2.97.1",
18
+ "@xyo-network/diviner-boundwitness-abstract": "~2.97.1",
19
+ "@xyo-network/diviner-boundwitness-model": "~2.97.1",
20
+ "@xyo-network/diviner-model": "~2.97.1",
21
+ "@xyo-network/module-model": "~2.97.1",
22
+ "@xyo-network/payload-builder": "~2.97.1",
23
+ "@xyo-network/payload-model": "~2.97.1",
23
24
  "idb": "^8.0.0"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@xylabs/ts-scripts-yarn3": "^3.9.1",
27
28
  "@xylabs/tsconfig": "^3.9.1",
28
- "@xyo-network/account": "~2.96.2",
29
- "@xyo-network/archivist-indexeddb": "~2.96.2",
30
- "@xyo-network/boundwitness-builder": "~2.96.2",
31
- "@xyo-network/node-memory": "~2.96.2",
32
- "@xyo-network/payload-builder": "~2.96.2",
33
- "@xyo-network/payload-model": "~2.96.2",
29
+ "@xyo-network/account": "~2.97.1",
30
+ "@xyo-network/archivist-indexeddb": "~2.97.1",
31
+ "@xyo-network/boundwitness-builder": "~2.97.1",
32
+ "@xyo-network/node-memory": "~2.97.1",
33
+ "@xyo-network/payload-builder": "~2.97.1",
34
34
  "fake-indexeddb": "^5.0.2",
35
35
  "typescript": "^5.4.5"
36
36
  },
@@ -73,6 +73,6 @@
73
73
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
74
74
  },
75
75
  "sideEffects": false,
76
- "version": "2.96.2",
76
+ "version": "2.97.1",
77
77
  "type": "module"
78
78
  }
package/src/Diviner.ts CHANGED
@@ -5,6 +5,7 @@ import { BoundWitness, BoundWitnessSchema, isBoundWitness } from '@xyo-network/b
5
5
  import { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'
6
6
  import { BoundWitnessDivinerQueryPayload, isBoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'
7
7
  import { PayloadBuilder } from '@xyo-network/payload-builder'
8
+ import { Schema } from '@xyo-network/payload-model'
8
9
  import { IDBPDatabase, openDB } from 'idb'
9
10
 
10
11
  import { IndexedDbBoundWitnessDivinerConfigSchema } from './Config'
@@ -32,7 +33,8 @@ export class IndexedDbBoundWitnessDiviner<
32
33
  TIn extends BoundWitnessDivinerQueryPayload = BoundWitnessDivinerQueryPayload,
33
34
  TOut extends BoundWitness = BoundWitness,
34
35
  > extends BoundWitnessDiviner<TParams, TIn, TOut> {
35
- static override configSchemas = [IndexedDbBoundWitnessDivinerConfigSchema]
36
+ static override configSchemas: Schema[] = [...super.configSchemas, IndexedDbBoundWitnessDivinerConfigSchema]
37
+ static override defaultConfigSchema: Schema = IndexedDbBoundWitnessDivinerConfigSchema
36
38
 
37
39
  /**
38
40
  * The database name. If not supplied via config, it defaults