@xyo-network/diviner-boundwitness-indexeddb 2.102.7 → 2.103.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.
- package/dist/browser/Config.d.cts +1 -1
- package/dist/browser/Config.d.cts.map +1 -1
- package/dist/browser/Config.d.mts +1 -1
- package/dist/browser/Config.d.mts.map +1 -1
- package/dist/browser/Config.d.ts +1 -1
- package/dist/browser/Config.d.ts.map +1 -1
- package/dist/browser/Diviner.d.cts.map +1 -1
- package/dist/browser/Diviner.d.mts.map +1 -1
- package/dist/browser/Diviner.d.ts.map +1 -1
- package/dist/browser/Schema.d.cts +1 -1
- package/dist/browser/Schema.d.cts.map +1 -1
- package/dist/browser/Schema.d.mts +1 -1
- package/dist/browser/Schema.d.mts.map +1 -1
- package/dist/browser/Schema.d.ts +1 -1
- package/dist/browser/Schema.d.ts.map +1 -1
- package/dist/browser/index.cjs +5 -1
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +5 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/Config.d.cts +1 -1
- package/dist/neutral/Config.d.cts.map +1 -1
- package/dist/neutral/Config.d.mts +1 -1
- package/dist/neutral/Config.d.mts.map +1 -1
- package/dist/neutral/Config.d.ts +1 -1
- package/dist/neutral/Config.d.ts.map +1 -1
- package/dist/neutral/Diviner.d.cts.map +1 -1
- package/dist/neutral/Diviner.d.mts.map +1 -1
- package/dist/neutral/Diviner.d.ts.map +1 -1
- package/dist/neutral/Schema.d.cts +1 -1
- package/dist/neutral/Schema.d.cts.map +1 -1
- package/dist/neutral/Schema.d.mts +1 -1
- package/dist/neutral/Schema.d.mts.map +1 -1
- package/dist/neutral/Schema.d.ts +1 -1
- package/dist/neutral/Schema.d.ts.map +1 -1
- package/dist/neutral/index.cjs +5 -1
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +5 -1
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/Config.d.cts +1 -1
- package/dist/node/Config.d.cts.map +1 -1
- package/dist/node/Config.d.mts +1 -1
- package/dist/node/Config.d.mts.map +1 -1
- package/dist/node/Config.d.ts +1 -1
- package/dist/node/Config.d.ts.map +1 -1
- package/dist/node/Diviner.d.cts.map +1 -1
- package/dist/node/Diviner.d.mts.map +1 -1
- package/dist/node/Diviner.d.ts.map +1 -1
- package/dist/node/Schema.d.cts +1 -1
- package/dist/node/Schema.d.cts.map +1 -1
- package/dist/node/Schema.d.mts +1 -1
- package/dist/node/Schema.d.mts.map +1 -1
- package/dist/node/Schema.d.ts +1 -1
- package/dist/node/Schema.d.ts.map +1 -1
- package/dist/node/index.cjs +5 -1
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +5 -1
- package/dist/node/index.js.map +1 -1
- package/package.json +15 -15
- package/src/Config.ts +1 -1
- package/src/Diviner.ts +5 -1
- package/src/Schema.ts +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IndexDescription } from '@xyo-network/archivist-model';
|
|
2
2
|
import { DivinerConfig } from '@xyo-network/diviner-model';
|
|
3
|
-
export declare const IndexedDbBoundWitnessDivinerConfigSchema:
|
|
3
|
+
export declare const IndexedDbBoundWitnessDivinerConfigSchema: "network.xyo.diviner.boundwitness.indexeddb.config";
|
|
4
4
|
export type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema;
|
|
5
5
|
export type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,eAAO,MAAM,wCAAwC,
|
|
1
|
+
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,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,6 +1,6 @@
|
|
|
1
1
|
import { IndexDescription } from '@xyo-network/archivist-model';
|
|
2
2
|
import { DivinerConfig } from '@xyo-network/diviner-model';
|
|
3
|
-
export declare const IndexedDbBoundWitnessDivinerConfigSchema:
|
|
3
|
+
export declare const IndexedDbBoundWitnessDivinerConfigSchema: "network.xyo.diviner.boundwitness.indexeddb.config";
|
|
4
4
|
export type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema;
|
|
5
5
|
export type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,eAAO,MAAM,wCAAwC,
|
|
1
|
+
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,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"}
|
package/dist/browser/Config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IndexDescription } from '@xyo-network/archivist-model';
|
|
2
2
|
import { DivinerConfig } from '@xyo-network/diviner-model';
|
|
3
|
-
export declare const IndexedDbBoundWitnessDivinerConfigSchema:
|
|
3
|
+
export declare const IndexedDbBoundWitnessDivinerConfigSchema: "network.xyo.diviner.boundwitness.indexeddb.config";
|
|
4
4
|
export type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema;
|
|
5
5
|
export type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,eAAO,MAAM,wCAAwC,
|
|
1
|
+
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,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 +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;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,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAqE;IACrH,gBAAyB,mBAAmB,EAAE,MAAM,CAA2C;IAE/F;;;;;;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;
|
|
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,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAqE;IACrH,gBAAyB,mBAAmB,EAAE,MAAM,CAA2C;IAE/F;;;;;;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;cA8DhD,YAAY;IAQrC;;;OAGG;YACW,mBAAmB;IAwBjC;;;;OAIG;YACW,QAAQ;CAcvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts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AEZ;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;
|
|
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,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAqE;IACrH,gBAAyB,mBAAmB,EAAE,MAAM,CAA2C;IAE/F;;;;;;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;cA8DhD,YAAY;IAQrC;;;OAGG;YACW,mBAAmB;IAwBjC;;;;OAIG;YACW,QAAQ;CAcvB"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const IndexedDbBoundWitnessDivinerSchema:
|
|
1
|
+
export declare const IndexedDbBoundWitnessDivinerSchema: "network.xyo.diviner.boundwitness.indexeddb";
|
|
2
2
|
export type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema;
|
|
3
3
|
//# sourceMappingURL=Schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,8CAAoD,CAAA;AACnG,MAAM,MAAM,kCAAkC,GAAG,OAAO,kCAAkC,CAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const IndexedDbBoundWitnessDivinerSchema:
|
|
1
|
+
export declare const IndexedDbBoundWitnessDivinerSchema: "network.xyo.diviner.boundwitness.indexeddb";
|
|
2
2
|
export type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema;
|
|
3
3
|
//# sourceMappingURL=Schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,8CAAoD,CAAA;AACnG,MAAM,MAAM,kCAAkC,GAAG,OAAO,kCAAkC,CAAA"}
|
package/dist/browser/Schema.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const IndexedDbBoundWitnessDivinerSchema:
|
|
1
|
+
export declare const IndexedDbBoundWitnessDivinerSchema: "network.xyo.diviner.boundwitness.indexeddb";
|
|
2
2
|
export type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema;
|
|
3
3
|
//# sourceMappingURL=Schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,8CAAoD,CAAA;AACnG,MAAM,MAAM,kCAAkC,GAAG,OAAO,kCAAkC,CAAA"}
|
package/dist/browser/index.cjs
CHANGED
|
@@ -119,7 +119,11 @@ var IndexedDbBoundWitnessDiviner = class extends import_diviner_boundwitness_abs
|
|
|
119
119
|
results.push(value);
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
try {
|
|
123
|
+
cursor = await cursor.continue();
|
|
124
|
+
} catch {
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
123
127
|
}
|
|
124
128
|
await tx.done;
|
|
125
129
|
return await Promise.all(results.filter(import_boundwitness_model.isBoundWitness).map((bw) => {
|
|
@@ -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 { 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 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 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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O;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"]}
|
|
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` as const\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` 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","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 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 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 try {\n cursor = await cursor.continue()\n } catch {\n break\n }\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 //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AUC,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"]}
|
package/dist/browser/index.js
CHANGED
|
@@ -93,7 +93,11 @@ var IndexedDbBoundWitnessDiviner = class extends BoundWitnessDiviner {
|
|
|
93
93
|
results.push(value);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
|
|
96
|
+
try {
|
|
97
|
+
cursor = await cursor.continue();
|
|
98
|
+
} catch {
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
97
101
|
}
|
|
98
102
|
await tx.done;
|
|
99
103
|
return await Promise.all(results.filter(isBoundWitness).map((bw) => {
|
|
@@ -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 { 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 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 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;AAE/B,SAAuBC,cAAc;AAWrC,IAAMC,gBAAgB,wBACpBC,KACAC,WAAAA;AAEA,MAAI,CAACA,UAAUA,QAAQC,WAAW;AAAG,WAAOC;AAC5C,SAAO,CAACC,OAAAA;AACN,QAAI,CAACA;AAAI,aAAO;AAChB,WAAOC,YAAYD,GAAGJ,GAAAA,GAAMC,MAAAA;EAC9B;AACF,GATsB;AAWf,IAAMK,+BAAN,cAIGC,oBAAAA;EAlCV,OAkCUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;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ema","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
|
+
{"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 { IndexDescription } from '@xyo-network/archivist-model'\nimport { DivinerConfig } from '@xyo-network/diviner-model'\n\nimport { IndexedDbBoundWitnessDivinerSchema } from './Schema'\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","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 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 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 try {\n cursor = await cursor.continue()\n } catch {\n break\n }\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,sBAA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AE/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,6 +1,6 @@
|
|
|
1
1
|
import { IndexDescription } from '@xyo-network/archivist-model';
|
|
2
2
|
import { DivinerConfig } from '@xyo-network/diviner-model';
|
|
3
|
-
export declare const IndexedDbBoundWitnessDivinerConfigSchema:
|
|
3
|
+
export declare const IndexedDbBoundWitnessDivinerConfigSchema: "network.xyo.diviner.boundwitness.indexeddb.config";
|
|
4
4
|
export type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema;
|
|
5
5
|
export type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,eAAO,MAAM,wCAAwC,
|
|
1
|
+
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,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,6 +1,6 @@
|
|
|
1
1
|
import { IndexDescription } from '@xyo-network/archivist-model';
|
|
2
2
|
import { DivinerConfig } from '@xyo-network/diviner-model';
|
|
3
|
-
export declare const IndexedDbBoundWitnessDivinerConfigSchema:
|
|
3
|
+
export declare const IndexedDbBoundWitnessDivinerConfigSchema: "network.xyo.diviner.boundwitness.indexeddb.config";
|
|
4
4
|
export type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema;
|
|
5
5
|
export type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,eAAO,MAAM,wCAAwC,
|
|
1
|
+
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,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"}
|
package/dist/neutral/Config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IndexDescription } from '@xyo-network/archivist-model';
|
|
2
2
|
import { DivinerConfig } from '@xyo-network/diviner-model';
|
|
3
|
-
export declare const IndexedDbBoundWitnessDivinerConfigSchema:
|
|
3
|
+
export declare const IndexedDbBoundWitnessDivinerConfigSchema: "network.xyo.diviner.boundwitness.indexeddb.config";
|
|
4
4
|
export type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema;
|
|
5
5
|
export type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,eAAO,MAAM,wCAAwC,
|
|
1
|
+
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,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 +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,4CAA4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,"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,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAqE;IACrH,gBAAyB,mBAAmB,EAAE,MAAM,CAA2C;IAE/F;;;;;;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;cA8DhD,YAAY;IAQrC;;;OAGG;YACW,mBAAmB;IAwBjC;;;;OAIG;YACW,QAAQ;CAcvB"}
|
|
@@ -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;AAE5H,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAInD,OAAO,EAA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I,SAAS,WAEZ;IAED;;;OAGG;IACH,IAAI,SAAS,WAEZ;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cA8DhD,YAAY;IAQrC;;;OAGG;YACW,mBAAmB;IAwBjC;;;;OAIG;YACW,QAAQ;CAcvB"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const IndexedDbBoundWitnessDivinerSchema:
|
|
1
|
+
export declare const IndexedDbBoundWitnessDivinerSchema: "network.xyo.diviner.boundwitness.indexeddb";
|
|
2
2
|
export type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema;
|
|
3
3
|
//# sourceMappingURL=Schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,8CAAoD,CAAA;AACnG,MAAM,MAAM,kCAAkC,GAAG,OAAO,kCAAkC,CAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const IndexedDbBoundWitnessDivinerSchema:
|
|
1
|
+
export declare const IndexedDbBoundWitnessDivinerSchema: "network.xyo.diviner.boundwitness.indexeddb";
|
|
2
2
|
export type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema;
|
|
3
3
|
//# sourceMappingURL=Schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,8CAAoD,CAAA;AACnG,MAAM,MAAM,kCAAkC,GAAG,OAAO,kCAAkC,CAAA"}
|
package/dist/neutral/Schema.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const IndexedDbBoundWitnessDivinerSchema:
|
|
1
|
+
export declare const IndexedDbBoundWitnessDivinerSchema: "network.xyo.diviner.boundwitness.indexeddb";
|
|
2
2
|
export type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema;
|
|
3
3
|
//# sourceMappingURL=Schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,8CAAoD,CAAA;AACnG,MAAM,MAAM,kCAAkC,GAAG,OAAO,kCAAkC,CAAA"}
|
package/dist/neutral/index.cjs
CHANGED
|
@@ -119,7 +119,11 @@ var IndexedDbBoundWitnessDiviner = class extends import_diviner_boundwitness_abs
|
|
|
119
119
|
results.push(value);
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
try {
|
|
123
|
+
cursor = await cursor.continue();
|
|
124
|
+
} catch {
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
123
127
|
}
|
|
124
128
|
await tx.done;
|
|
125
129
|
return await Promise.all(results.filter(import_boundwitness_model.isBoundWitness).map((bw) => {
|
|
@@ -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 { 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 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 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,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;;;;;;;;EASvD,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,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,EAA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sC,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"]}
|
|
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` as const\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` 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","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 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 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 try {\n cursor = await cursor.continue()\n } catch {\n break\n }\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,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;;;;;;;;EASvD,IAAIE,SAAS;AACX,WAAO,KAAKC,QAAQD,UAAU,KAAKC,QAAQC,aAAaC,8CAAmBC;EAC7E;;;;EAKA,IAAIC,YAAY;AACd,WAAO,KAAKJ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,oBAAQgB,KAAKF,KAAAA;UACf;QACF;AACA,YAAI;AACFR,mBAAS,MAAMA,OAAOW,SAAQ;QAChC,QAAQ;AACN;QACF;MACF;AACA,YAAMrB,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"]}
|
package/dist/neutral/index.js
CHANGED
|
@@ -93,7 +93,11 @@ var IndexedDbBoundWitnessDiviner = class extends BoundWitnessDiviner {
|
|
|
93
93
|
results.push(value);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
|
|
96
|
+
try {
|
|
97
|
+
cursor = await cursor.continue();
|
|
98
|
+
} catch {
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
97
101
|
}
|
|
98
102
|
await tx.done;
|
|
99
103
|
return await Promise.all(results.filter(isBoundWitness).map((bw) => {
|
|
@@ -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 { 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 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 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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AAKK,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":["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
|
+
{"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 { IndexDescription } from '@xyo-network/archivist-model'\nimport { DivinerConfig } from '@xyo-network/diviner-model'\n\nimport { IndexedDbBoundWitnessDivinerSchema } from './Schema'\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","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 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 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 try {\n cursor = await cursor.continue()\n } catch {\n break\n }\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;AAE/B,SAAuBC,cAAc;AAWrC,IAAMC,gBAAgB,wBACpBC,KACAC,WAAAA;AAEA,MAAI,CAACA,UAAUA,QAAQC,WAAW;AAAG,WAAOC;AAC5C,SAAO,CAACC,OAAAA;AACN,QAAI,CAACA;AAAI,aAAO;AAChB,WAAOC,YAAYD,GAAGJ,GAAAA,GAAMC,MAAAA;EAC9B;AACF,GATsB;AAWf,IAAMK,+BAAN,cAIGC,oBAAAA;EAlCV,OAkCUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;;;;;;;;EASvD,IAAIE,SAAS;AACX,WAAO,KAAKC,QAAQD,UAAU,KAAKC,QAAQC,aAAaC,mBAAmBC;EAC7E;;;;EAKA,IAAIC,YAAY;AACd,WAAO,KAAKJ,QAAQI,aAAaF,mBAAmBG;EACtD;;;;;EAMA,IAAIC,YAAY;AACd,WAAO,KAAKN,QAAQM,aAAaJ,mBAAmBK;EACtD;EAEA,MAAyBC,cAAcC,UAAmC;AACxE,UAAMC,QAAQD,UAAUE,OAAOC,iCAAAA,GAAoCC,IAAAA;AACnE,QAAI,CAACH;AAAO,aAAO,CAAA;AAEnB,UAAMI,SAAS,MAAM,KAAKC,SAAS,OAAOC,OAAAA;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;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,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,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"]}
|
package/dist/node/Config.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IndexDescription } from '@xyo-network/archivist-model';
|
|
2
2
|
import { DivinerConfig } from '@xyo-network/diviner-model';
|
|
3
|
-
export declare const IndexedDbBoundWitnessDivinerConfigSchema:
|
|
3
|
+
export declare const IndexedDbBoundWitnessDivinerConfigSchema: "network.xyo.diviner.boundwitness.indexeddb.config";
|
|
4
4
|
export type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema;
|
|
5
5
|
export type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,eAAO,MAAM,wCAAwC,
|
|
1
|
+
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,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"}
|
package/dist/node/Config.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IndexDescription } from '@xyo-network/archivist-model';
|
|
2
2
|
import { DivinerConfig } from '@xyo-network/diviner-model';
|
|
3
|
-
export declare const IndexedDbBoundWitnessDivinerConfigSchema:
|
|
3
|
+
export declare const IndexedDbBoundWitnessDivinerConfigSchema: "network.xyo.diviner.boundwitness.indexeddb.config";
|
|
4
4
|
export type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema;
|
|
5
5
|
export type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,eAAO,MAAM,wCAAwC,
|
|
1
|
+
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,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"}
|
package/dist/node/Config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IndexDescription } from '@xyo-network/archivist-model';
|
|
2
2
|
import { DivinerConfig } from '@xyo-network/diviner-model';
|
|
3
|
-
export declare const IndexedDbBoundWitnessDivinerConfigSchema:
|
|
3
|
+
export declare const IndexedDbBoundWitnessDivinerConfigSchema: "network.xyo.diviner.boundwitness.indexeddb.config";
|
|
4
4
|
export type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema;
|
|
5
5
|
export type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,eAAO,MAAM,wCAAwC,
|
|
1
|
+
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,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 +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;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,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAqE;IACrH,gBAAyB,mBAAmB,EAAE,MAAM,CAA2C;IAE/F;;;;;;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;
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings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aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cA8DhD,YAAY;IAQrC;;;OAGG;YACW,mBAAmB;IAwBjC;;;;OAIG;YACW,QAAQ;CAcvB"}
|
|
@@ -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;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,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAqE;IACrH,gBAAyB,mBAAmB,EAAE,MAAM,CAA2C;IAE/F;;;;;;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;
|
|
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,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAqE;IACrH,gBAAyB,mBAAmB,EAAE,MAAM,CAA2C;IAE/F;;;;;;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;cA8DhD,YAAY;IAQrC;;;OAGG;YACW,mBAAmB;IAwBjC;;;;OAIG;YACW,QAAQ;CAcvB"}
|
package/dist/node/Schema.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const IndexedDbBoundWitnessDivinerSchema:
|
|
1
|
+
export declare const IndexedDbBoundWitnessDivinerSchema: "network.xyo.diviner.boundwitness.indexeddb";
|
|
2
2
|
export type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema;
|
|
3
3
|
//# sourceMappingURL=Schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,8CAAoD,CAAA;AACnG,MAAM,MAAM,kCAAkC,GAAG,OAAO,kCAAkC,CAAA"}
|
package/dist/node/Schema.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const IndexedDbBoundWitnessDivinerSchema:
|
|
1
|
+
export declare const IndexedDbBoundWitnessDivinerSchema: "network.xyo.diviner.boundwitness.indexeddb";
|
|
2
2
|
export type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema;
|
|
3
3
|
//# sourceMappingURL=Schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,8CAAoD,CAAA;AACnG,MAAM,MAAM,kCAAkC,GAAG,OAAO,kCAAkC,CAAA"}
|
package/dist/node/Schema.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const IndexedDbBoundWitnessDivinerSchema:
|
|
1
|
+
export declare const IndexedDbBoundWitnessDivinerSchema: "network.xyo.diviner.boundwitness.indexeddb";
|
|
2
2
|
export type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema;
|
|
3
3
|
//# sourceMappingURL=Schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kCAAkC,8CAAoD,CAAA;AACnG,MAAM,MAAM,kCAAkC,GAAG,OAAO,kCAAkC,CAAA"}
|
package/dist/node/index.cjs
CHANGED
|
@@ -123,7 +123,11 @@ var _IndexedDbBoundWitnessDiviner = class _IndexedDbBoundWitnessDiviner extends
|
|
|
123
123
|
results.push(value);
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
|
|
126
|
+
try {
|
|
127
|
+
cursor = await cursor.continue();
|
|
128
|
+
} catch {
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
127
131
|
}
|
|
128
132
|
await tx.done;
|
|
129
133
|
return await Promise.all(results.filter(import_boundwitness_model.isBoundWitness).map((bw) => {
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -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 { 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 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 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,WAAUA,iCAAQC,YAAW;AAAG,WAAOC;AAC5C,SAAO,CAACC,OAAAA;AACN,QAAI,CAACA;AAAI,aAAO;AAChB,eAAOC,0BAAYD,GAAGJ,GAAAA,GAAMC,MAA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;IACF;AACA,WAAOvE;EACT;AACF;AA/IUI;AACR,cALWD,+BAKcsE,iBAA0B;KAAI,yEAAMA;EAAeC;;AAC5E,cANWvE,+BAMcwE,uBAA8BD;AANlD,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
|
+
{"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` as const\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` 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","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 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 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 try {\n cursor = await cursor.continue()\n } catch {\n break\n }\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,wCA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G4C,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,WAAOvE;EACT;AACF;AAnJUI;AACR,cALWD,+BAKcsE,iBAA0B;KAAI,yEAAMA;EAAeC;;AAC5E,cANWvE,+BAMcwE,uBAA8BD;AANlD,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"]}
|
package/dist/node/index.js
CHANGED
|
@@ -97,7 +97,11 @@ var _IndexedDbBoundWitnessDiviner = class _IndexedDbBoundWitnessDiviner extends
|
|
|
97
97
|
results.push(value);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
|
|
100
|
+
try {
|
|
101
|
+
cursor = await cursor.continue();
|
|
102
|
+
} catch {
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
101
105
|
}
|
|
102
106
|
await tx.done;
|
|
103
107
|
return await Promise.all(results.filter(isBoundWitness).map((bw) => {
|
package/dist/node/index.js.map
CHANGED
|
@@ -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 { 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 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 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;AAE/B,SAAuBC,cAAc;AAWrC,IAAMC,gBAAgB,wBACpBC,KACAC,WAAAA;AAEA,MAAI,CAACA,WAAUA,iCAAQC,YAAW;AAAG,WAAOC;AAC5C,SAAO,CAACC,OAAAA;AACN,QAAI,CAACA;AAAI,aAAO;AAChB,WAAOC,YAAYD,GAAGJ,GAAAA,GAAMC,MAAAA;EAC9B;AACF,GATsB;AAWf,IAAMK,gCAAN,MAAMA,sCAIHC,oBA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KAAI,yEAAMA;EAAeC;;AAC5E,cANWvE,+BAMcwE,uBAA8BD;AANlD,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"]}
|
|
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 { IndexDescription } from '@xyo-network/archivist-model'\nimport { DivinerConfig } from '@xyo-network/diviner-model'\n\nimport { IndexedDbBoundWitnessDivinerSchema } from './Schema'\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","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 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 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 try {\n cursor = await cursor.continue()\n } catch {\n break\n }\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,kC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;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;AAnJUI;AACR,cALWD,+BAKcsE,iBAA0B;KAAI,yEAAMA;EAAeC;;AAC5E,cANWvE,+BAMcwE,uBAA8BD;AANlD,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.3.3",
|
|
14
14
|
"@xylabs/exists": "^3.3.3",
|
|
15
|
-
"@xyo-network/archivist-indexeddb": "~2.
|
|
16
|
-
"@xyo-network/archivist-model": "~2.
|
|
17
|
-
"@xyo-network/boundwitness-model": "~2.
|
|
18
|
-
"@xyo-network/diviner-boundwitness-abstract": "~2.
|
|
19
|
-
"@xyo-network/diviner-boundwitness-model": "~2.
|
|
20
|
-
"@xyo-network/diviner-model": "~2.
|
|
21
|
-
"@xyo-network/module-model": "~2.
|
|
22
|
-
"@xyo-network/payload-builder": "~2.
|
|
23
|
-
"@xyo-network/payload-model": "~2.
|
|
15
|
+
"@xyo-network/archivist-indexeddb": "~2.103.1",
|
|
16
|
+
"@xyo-network/archivist-model": "~2.103.1",
|
|
17
|
+
"@xyo-network/boundwitness-model": "~2.103.1",
|
|
18
|
+
"@xyo-network/diviner-boundwitness-abstract": "~2.103.1",
|
|
19
|
+
"@xyo-network/diviner-boundwitness-model": "~2.103.1",
|
|
20
|
+
"@xyo-network/diviner-model": "~2.103.1",
|
|
21
|
+
"@xyo-network/module-model": "~2.103.1",
|
|
22
|
+
"@xyo-network/payload-builder": "~2.103.1",
|
|
23
|
+
"@xyo-network/payload-model": "~2.103.1",
|
|
24
24
|
"idb": "^8.0.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@xylabs/ts-scripts-yarn3": "^3.10.4",
|
|
28
28
|
"@xylabs/tsconfig": "^3.10.4",
|
|
29
|
-
"@xyo-network/account": "~2.
|
|
30
|
-
"@xyo-network/archivist-indexeddb": "~2.
|
|
31
|
-
"@xyo-network/boundwitness-builder": "~2.
|
|
32
|
-
"@xyo-network/node-memory": "~2.
|
|
33
|
-
"@xyo-network/payload-builder": "~2.
|
|
29
|
+
"@xyo-network/account": "~2.103.1",
|
|
30
|
+
"@xyo-network/archivist-indexeddb": "~2.103.1",
|
|
31
|
+
"@xyo-network/boundwitness-builder": "~2.103.1",
|
|
32
|
+
"@xyo-network/node-memory": "~2.103.1",
|
|
33
|
+
"@xyo-network/payload-builder": "~2.103.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.
|
|
76
|
+
"version": "2.103.1",
|
|
77
77
|
"type": "module"
|
|
78
78
|
}
|
package/src/Config.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { DivinerConfig } from '@xyo-network/diviner-model'
|
|
|
3
3
|
|
|
4
4
|
import { IndexedDbBoundWitnessDivinerSchema } from './Schema'
|
|
5
5
|
|
|
6
|
-
export const IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config`
|
|
6
|
+
export const IndexedDbBoundWitnessDivinerConfigSchema = `${IndexedDbBoundWitnessDivinerSchema}.config` as const
|
|
7
7
|
export type IndexedDbBoundWitnessDivinerConfigSchema = typeof IndexedDbBoundWitnessDivinerConfigSchema
|
|
8
8
|
|
|
9
9
|
export type IndexedDbBoundWitnessDivinerConfig = DivinerConfig<{
|
package/src/Diviner.ts
CHANGED
|
@@ -107,7 +107,11 @@ export class IndexedDbBoundWitnessDiviner<
|
|
|
107
107
|
results.push(value)
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
|
|
110
|
+
try {
|
|
111
|
+
cursor = await cursor.continue()
|
|
112
|
+
} catch {
|
|
113
|
+
break
|
|
114
|
+
}
|
|
111
115
|
}
|
|
112
116
|
await tx.done
|
|
113
117
|
// Remove any metadata before returning to the client
|
package/src/Schema.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { BoundWitnessDivinerSchema } from '@xyo-network/diviner-boundwitness-model'
|
|
2
2
|
|
|
3
|
-
export const IndexedDbBoundWitnessDivinerSchema = `${BoundWitnessDivinerSchema}.indexeddb`
|
|
3
|
+
export const IndexedDbBoundWitnessDivinerSchema = `${BoundWitnessDivinerSchema}.indexeddb` as const
|
|
4
4
|
export type IndexedDbBoundWitnessDivinerSchema = typeof IndexedDbBoundWitnessDivinerSchema
|