@xyo-network/diviner-boundwitness-indexeddb 5.2.27 → 5.3.0

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,6 +1,8 @@
1
1
  import type { IndexDescription } from '@xyo-network/archivist-model';
2
2
  import type { DivinerConfig } from '@xyo-network/diviner-model';
3
- export declare const IndexedDbBoundWitnessDivinerConfigSchema: "network.xyo.diviner.boundwitness.indexeddb.config";
3
+ export declare const IndexedDbBoundWitnessDivinerConfigSchema: string & {
4
+ readonly __schema: true;
5
+ };
4
6
  export type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema;
5
7
  export type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{
6
8
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI/D,eAAO,MAAM,wCAAwC,qDAA0D,CAAA;AAC/G,MAAM,MAAM,wCAAwC,GAAG,OAAO,wCAAwC,CAAA;AAEtG,MAAM,MAAM,kCAAkC,GAAG,aAAa,CAAC;IAC7D;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,wCAAwC,CAAA;IAChD;;;OAGG;IACH,OAAO,CAAC,EAAE;QACR;;WAEG;QACH,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;KAC7B,CAAA;IACD;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAC,CAAA"}
1
+ {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAK/D,eAAO,MAAM,wCAAwC;;CAAiE,CAAA;AACtH,MAAM,MAAM,wCAAwC,GAAG,OAAO,wCAAwC,CAAA;AAEtG,MAAM,MAAM,kCAAkC,GAAG,aAAa,CAAC;IAC7D;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,wCAAwC,CAAA;IAChD;;;OAGG;IACH,OAAO,CAAC,EAAE;QACR;;WAEG;QACH,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;KAC7B,CAAA;IACD;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAC,CAAA"}
@@ -1,9 +1,12 @@
1
+ // src/Config.ts
2
+ import { asSchema } from "@xyo-network/payload-model";
3
+
1
4
  // src/Schema.ts
2
5
  import { BoundWitnessDivinerSchema } from "@xyo-network/diviner-boundwitness-model";
3
6
  var IndexedDbBoundWitnessDivinerSchema = `${BoundWitnessDivinerSchema}.indexeddb`;
4
7
 
5
8
  // src/Config.ts
6
- var IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config`;
9
+ var IndexedDbBoundWitnessDivinerConfigSchema = asSchema(`${IndexedDbBoundWitnessDivinerSchema}.config`, true);
7
10
 
8
11
  // src/Diviner.ts
9
12
  import {
@@ -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` as const\nexport type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema\n","import type { IndexDescription } from '@xyo-network/archivist-model'\nimport type { DivinerConfig } from '@xyo-network/diviner-model'\n\nimport { IndexedDbBoundWitnessDivinerSchema } from './Schema.ts'\n\nexport const IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config` as const\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","/// <reference lib=\"dom\" />\n\nimport {\n assertEx, containsAll, exists,\n} from '@xylabs/sdk-js'\nimport { IndexedDbArchivist } from '@xyo-network/archivist-indexeddb'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport type { BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { isBoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport type {\n Schema, Sequence, WithStorageMeta,\n} from '@xyo-network/payload-model'\nimport type { IDBPCursorWithValue, IDBPDatabase } from 'idb'\nimport { openDB } from 'idb'\n\nimport { IndexedDbBoundWitnessDivinerConfigSchema } from './Config.ts'\nimport type { IndexedDbBoundWitnessDivinerParams } from './Params.ts'\n\ninterface BoundWitnessStore {\n [s: string]: WithStorageMeta<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 readonly configSchemas: Schema[] = [...super.configSchemas, IndexedDbBoundWitnessDivinerConfigSchema]\n static override readonly 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 the archivist default version.\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?.find(isBoundWitnessDivinerQueryPayload)\n if (!query) return []\n const result = await this.tryUseDb(async (db) => {\n const {\n addresses, payload_hashes, payload_schemas, limit, cursor, order,\n } = query\n const tx = db.transaction(this.storeName, 'readonly')\n const store = tx.objectStore(this.storeName)\n const results: TOut[] = []\n const parsedCursor = cursor\n const parsedLimit = limit ?? 10\n const valueFilters: ValueFilter[] = [\n isBoundWitness,\n bwValueFilter('addresses', addresses),\n bwValueFilter('payload_hashes', payload_hashes),\n bwValueFilter('payload_schemas', payload_schemas),\n ].filter(exists)\n const direction: IDBCursorDirection = order === 'desc' ? 'prev' : 'next'\n\n // Iterate all records using the sequence index\n const sequenceIndex = assertEx(store.index(IndexedDbArchivist.sequenceIndexName), () => 'Failed to get sequence index')\n let dbCursor: IDBPCursorWithValue<BoundWitnessStore, [string], string, string, 'readonly'> | null\n = await sequenceIndex.openCursor(null, direction)\n\n // If a cursor was supplied\n if (parsedCursor !== undefined) {\n let currentSequence: Sequence | undefined\n // Skip records until the supplied cursor offset is reached\n while (dbCursor && currentSequence !== parsedCursor) {\n // Find the sequence of the current record\n const current: WithStorageMeta<BoundWitness> = dbCursor.value\n currentSequence = current?._sequence\n // Advance one record beyond the cursor\n dbCursor = await dbCursor.advance(1)\n }\n }\n\n // Collect results up to the limit\n while (dbCursor && results.length < parsedLimit) {\n const value = dbCursor.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 try {\n dbCursor = await dbCursor.continue()\n } catch {\n break\n }\n }\n await tx.done\n // Remove any metadata before returning to the client\n return results\n })\n return result ?? []\n }\n\n protected override async startHandler() {\n await super.startHandler()\n // 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 }\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\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)\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,SAAS,iCAAiC;AAEnC,IAAM,qCAAqC,GAAG,yBAAyB;;;ACGvE,IAAM,2CAA2C,GAAG,kCAAkC;;;ACH7F;AAAA,EACE;AAAA,EAAU;AAAA,EAAa;AAAA,OAClB;AACP,SAAS,0BAA0B;AAEnC,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AAEpC,SAAS,yCAAyC;AAKlD,SAAS,cAAc;AAWvB,IAAM,gBAAgB,CACpB,KACA,WAC4B;AAC5B,MAAI,CAAC,UAAU,QAAQ,WAAW,EAAG,QAAO;AAC5C,SAAO,CAAC,OAAO;AACb,QAAI,CAAC,GAAI,QAAO;AAChB,WAAO,YAAY,GAAG,GAAG,GAAG,MAAM;AAAA,EACpC;AACF;AAEO,IAAM,+BAAN,cAIG,oBAAwC;AAAA,EAChD,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,wCAAwC;AAAA,EACpH,OAAyB,sBAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASvD,IAAI,SAAS;AACX,WAAO,KAAK,QAAQ,UAAU,KAAK,QAAQ,aAAa,mBAAmB;AAAA,EAC7E;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,YAAY;AACd,WAAO,KAAK,QAAQ,aAAa,mBAAmB;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,YAAY;AACd,WAAO,KAAK,QAAQ,aAAa,mBAAmB;AAAA,EACtD;AAAA,EAEA,MAAyB,cAAc,UAAmC;AACxE,UAAM,QAAQ,UAAU,KAAK,iCAAiC;AAC9D,QAAI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AAAA,IACT,CAAC;AACD,WAAO,UAAU,CAAC;AAAA,EACpB;AAAA,EAEA,MAAyB,eAAe;AACtC,UAAM,MAAM,aAAa;AAAA,EAI3B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAc,sBAA4E;AAExF,UAAM,MAAM,MAAM,UAAU,UAAU;AAEtC,UAAM,WAAW,IAAI,KAAK,CAAC,OAAO;AAChC,aAAO,GAAG,SAAS,KAAK;AAAA,IAC1B,CAAC;AAED,QAAI,UAAU;AAEZ,YAAM,KAAK,MAAM,OAA0B,KAAK,MAAM;AAEtD,YAAM,cAAc,GAAG,iBAAiB,SAAS,KAAK,SAAS;AAE/D,UAAI,aAAa;AACf,eAAO;AAAA,MACT,OAAO;AAGL,WAAG,MAAM;AAAA,MACX;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAc,SAAY,UAA2F;AAEnH,UAAM,KAAK,MAAM,KAAK,oBAAoB;AAC1C,QAAI,IAAI;AACN,UAAI;AAEF,eAAO,MAAM,SAAS,EAAE;AAAA,MAC1B,UAAE;AAEA,WAAG,MAAM;AAAA,MACX;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/Config.ts","../../src/Schema.ts","../../src/Diviner.ts"],"sourcesContent":["import type { IndexDescription } from '@xyo-network/archivist-model'\nimport type { DivinerConfig } from '@xyo-network/diviner-model'\nimport { asSchema } from '@xyo-network/payload-model'\n\nimport { IndexedDbBoundWitnessDivinerSchema } from './Schema.ts'\n\nexport const IndexedDbBoundWitnessDivinerConfigSchema = asSchema(`${IndexedDbBoundWitnessDivinerSchema}.config`, true)\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 { BoundWitnessDivinerSchema } from '@xyo-network/diviner-boundwitness-model'\n\nexport const IndexedDbBoundWitnessDivinerSchema = `${BoundWitnessDivinerSchema}.indexeddb` as const\nexport type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema\n","/// <reference lib=\"dom\" />\n\nimport {\n assertEx, containsAll, exists,\n} from '@xylabs/sdk-js'\nimport { IndexedDbArchivist } from '@xyo-network/archivist-indexeddb'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'\nimport type { BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { isBoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport type {\n Schema, Sequence, WithStorageMeta,\n} from '@xyo-network/payload-model'\nimport type { IDBPCursorWithValue, IDBPDatabase } from 'idb'\nimport { openDB } from 'idb'\n\nimport { IndexedDbBoundWitnessDivinerConfigSchema } from './Config.ts'\nimport type { IndexedDbBoundWitnessDivinerParams } from './Params.ts'\n\ninterface BoundWitnessStore {\n [s: string]: WithStorageMeta<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 readonly configSchemas: Schema[] = [...super.configSchemas, IndexedDbBoundWitnessDivinerConfigSchema]\n static override readonly 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 the archivist default version.\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?.find(isBoundWitnessDivinerQueryPayload)\n if (!query) return []\n const result = await this.tryUseDb(async (db) => {\n const {\n addresses, payload_hashes, payload_schemas, limit, cursor, order,\n } = query\n const tx = db.transaction(this.storeName, 'readonly')\n const store = tx.objectStore(this.storeName)\n const results: TOut[] = []\n const parsedCursor = cursor\n const parsedLimit = limit ?? 10\n const valueFilters: ValueFilter[] = [\n isBoundWitness,\n bwValueFilter('addresses', addresses),\n bwValueFilter('payload_hashes', payload_hashes),\n bwValueFilter('payload_schemas', payload_schemas),\n ].filter(exists)\n const direction: IDBCursorDirection = order === 'desc' ? 'prev' : 'next'\n\n // Iterate all records using the sequence index\n const sequenceIndex = assertEx(store.index(IndexedDbArchivist.sequenceIndexName), () => 'Failed to get sequence index')\n let dbCursor: IDBPCursorWithValue<BoundWitnessStore, [string], string, string, 'readonly'> | null\n = await sequenceIndex.openCursor(null, direction)\n\n // If a cursor was supplied\n if (parsedCursor !== undefined) {\n let currentSequence: Sequence | undefined\n // Skip records until the supplied cursor offset is reached\n while (dbCursor && currentSequence !== parsedCursor) {\n // Find the sequence of the current record\n const current: WithStorageMeta<BoundWitness> = dbCursor.value\n currentSequence = current?._sequence\n // Advance one record beyond the cursor\n dbCursor = await dbCursor.advance(1)\n }\n }\n\n // Collect results up to the limit\n while (dbCursor && results.length < parsedLimit) {\n const value = dbCursor.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 try {\n dbCursor = await dbCursor.continue()\n } catch {\n break\n }\n }\n await tx.done\n // Remove any metadata before returning to the client\n return results\n })\n return result ?? []\n }\n\n protected override async startHandler() {\n await super.startHandler()\n // 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 }\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\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)\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":";AAEA,SAAS,gBAAgB;;;ACFzB,SAAS,iCAAiC;AAEnC,IAAM,qCAAqC,GAAG,yBAAyB;;;ADIvE,IAAM,2CAA2C,SAAS,GAAG,kCAAkC,WAAW,IAAI;;;AEJrH;AAAA,EACE;AAAA,EAAU;AAAA,EAAa;AAAA,OAClB;AACP,SAAS,0BAA0B;AAEnC,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AAEpC,SAAS,yCAAyC;AAKlD,SAAS,cAAc;AAWvB,IAAM,gBAAgB,CACpB,KACA,WAC4B;AAC5B,MAAI,CAAC,UAAU,QAAQ,WAAW,EAAG,QAAO;AAC5C,SAAO,CAAC,OAAO;AACb,QAAI,CAAC,GAAI,QAAO;AAChB,WAAO,YAAY,GAAG,GAAG,GAAG,MAAM;AAAA,EACpC;AACF;AAEO,IAAM,+BAAN,cAIG,oBAAwC;AAAA,EAChD,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,wCAAwC;AAAA,EACpH,OAAyB,sBAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASvD,IAAI,SAAS;AACX,WAAO,KAAK,QAAQ,UAAU,KAAK,QAAQ,aAAa,mBAAmB;AAAA,EAC7E;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,YAAY;AACd,WAAO,KAAK,QAAQ,aAAa,mBAAmB;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,YAAY;AACd,WAAO,KAAK,QAAQ,aAAa,mBAAmB;AAAA,EACtD;AAAA,EAEA,MAAyB,cAAc,UAAmC;AACxE,UAAM,QAAQ,UAAU,KAAK,iCAAiC;AAC9D,QAAI,CAAC,MAAO,QAAO,CAAC;AACpB,UAAM,SAAS,MAAM,KAAK,SAAS,OAAO,OAAO;AAC/C,YAAM;AAAA,QACJ;AAAA,QA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EAI3B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAc,sBAA4E;AAExF,UAAM,MAAM,MAAM,UAAU,UAAU;AAEtC,UAAM,WAAW,IAAI,KAAK,CAAC,OAAO;AAChC,aAAO,GAAG,SAAS,KAAK;AAAA,IAC1B,CAAC;AAED,QAAI,UAAU;AAEZ,YAAM,KAAK,MAAM,OAA0B,KAAK,MAAM;AAEtD,YAAM,cAAc,GAAG,iBAAiB,SAAS,KAAK,SAAS;AAE/D,UAAI,aAAa;AACf,eAAO;AAAA,MACT,OAAO;AAGL,WAAG,MAAM;AAAA,MACX;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAc,SAAY,UAA2F;AAEnH,UAAM,KAAK,MAAM,KAAK,oBAAoB;AAC1C,QAAI,IAAI;AACN,UAAI;AAEF,eAAO,MAAM,SAAS,EAAE;AAAA,MAC1B,UAAE;AAEA,WAAG,MAAM;AAAA,MACX;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/diviner-boundwitness-indexeddb",
3
- "version": "5.2.27",
3
+ "version": "5.3.0",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -37,14 +37,14 @@
37
37
  ],
38
38
  "dependencies": {
39
39
  "@xylabs/sdk-js": "~5.0.64",
40
- "@xyo-network/archivist-indexeddb": "~5.2.27",
41
- "@xyo-network/archivist-model": "~5.2.27",
42
- "@xyo-network/boundwitness-model": "~5.2.27",
43
- "@xyo-network/diviner-boundwitness-abstract": "~5.2.27",
44
- "@xyo-network/diviner-boundwitness-model": "~5.2.27",
45
- "@xyo-network/diviner-model": "~5.2.27",
46
- "@xyo-network/module-model": "~5.2.27",
47
- "@xyo-network/payload-model": "~5.2.27",
40
+ "@xyo-network/archivist-indexeddb": "~5.3.0",
41
+ "@xyo-network/archivist-model": "~5.3.0",
42
+ "@xyo-network/boundwitness-model": "~5.3.0",
43
+ "@xyo-network/diviner-boundwitness-abstract": "~5.3.0",
44
+ "@xyo-network/diviner-boundwitness-model": "~5.3.0",
45
+ "@xyo-network/diviner-model": "~5.3.0",
46
+ "@xyo-network/module-model": "~5.3.0",
47
+ "@xyo-network/payload-model": "~5.3.0",
48
48
  "idb": "~8.0.3"
49
49
  },
50
50
  "devDependencies": {
@@ -52,10 +52,10 @@
52
52
  "@xylabs/ts-scripts-yarn3": "~7.3.2",
53
53
  "@xylabs/tsconfig": "~7.3.2",
54
54
  "@xylabs/vitest-extended": "~5.0.64",
55
- "@xyo-network/archivist-indexeddb": "~5.2.27",
56
- "@xyo-network/boundwitness-builder": "~5.2.27",
57
- "@xyo-network/node-memory": "~5.2.27",
58
- "@xyo-network/payload-builder": "~5.2.27",
55
+ "@xyo-network/archivist-indexeddb": "~5.3.0",
56
+ "@xyo-network/boundwitness-builder": "~5.3.0",
57
+ "@xyo-network/node-memory": "~5.3.0",
58
+ "@xyo-network/payload-builder": "~5.3.0",
59
59
  "fake-indexeddb": "~6.2.5",
60
60
  "typescript": "~5.9.3",
61
61
  "vitest": "~4.0.18"
package/src/Config.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import type { IndexDescription } from '@xyo-network/archivist-model'
2
2
  import type { DivinerConfig } from '@xyo-network/diviner-model'
3
+ import { asSchema } from '@xyo-network/payload-model'
3
4
 
4
5
  import { IndexedDbBoundWitnessDivinerSchema } from './Schema.ts'
5
6
 
6
- export const IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config` as const
7
+ export const IndexedDbBoundWitnessDivinerConfigSchema = asSchema(`${IndexedDbBoundWitnessDivinerSchema}.config`, true)
7
8
  export type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema
8
9
 
9
10
  export type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{