@xyo-network/diviner-payload-indexeddb 2.87.0-rc.2

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.
Files changed (77) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +13 -0
  3. package/dist/browser/Config.d.cts +30 -0
  4. package/dist/browser/Config.d.cts.map +1 -0
  5. package/dist/browser/Config.d.mts +30 -0
  6. package/dist/browser/Config.d.mts.map +1 -0
  7. package/dist/browser/Config.d.ts +30 -0
  8. package/dist/browser/Config.d.ts.map +1 -0
  9. package/dist/browser/Diviner.d.cts +38 -0
  10. package/dist/browser/Diviner.d.cts.map +1 -0
  11. package/dist/browser/Diviner.d.mts +38 -0
  12. package/dist/browser/Diviner.d.mts.map +1 -0
  13. package/dist/browser/Diviner.d.ts +38 -0
  14. package/dist/browser/Diviner.d.ts.map +1 -0
  15. package/dist/browser/Params.d.cts +5 -0
  16. package/dist/browser/Params.d.cts.map +1 -0
  17. package/dist/browser/Params.d.mts +5 -0
  18. package/dist/browser/Params.d.mts.map +1 -0
  19. package/dist/browser/Params.d.ts +5 -0
  20. package/dist/browser/Params.d.ts.map +1 -0
  21. package/dist/browser/Schema.d.cts +3 -0
  22. package/dist/browser/Schema.d.cts.map +1 -0
  23. package/dist/browser/Schema.d.mts +3 -0
  24. package/dist/browser/Schema.d.mts.map +1 -0
  25. package/dist/browser/Schema.d.ts +3 -0
  26. package/dist/browser/Schema.d.ts.map +1 -0
  27. package/dist/browser/index.cjs +156 -0
  28. package/dist/browser/index.cjs.map +1 -0
  29. package/dist/browser/index.d.cts +5 -0
  30. package/dist/browser/index.d.cts.map +1 -0
  31. package/dist/browser/index.d.mts +5 -0
  32. package/dist/browser/index.d.mts.map +1 -0
  33. package/dist/browser/index.d.ts +5 -0
  34. package/dist/browser/index.d.ts.map +1 -0
  35. package/dist/browser/index.js +135 -0
  36. package/dist/browser/index.js.map +1 -0
  37. package/dist/node/Config.d.cts +30 -0
  38. package/dist/node/Config.d.cts.map +1 -0
  39. package/dist/node/Config.d.mts +30 -0
  40. package/dist/node/Config.d.mts.map +1 -0
  41. package/dist/node/Config.d.ts +30 -0
  42. package/dist/node/Config.d.ts.map +1 -0
  43. package/dist/node/Diviner.d.cts +38 -0
  44. package/dist/node/Diviner.d.cts.map +1 -0
  45. package/dist/node/Diviner.d.mts +38 -0
  46. package/dist/node/Diviner.d.mts.map +1 -0
  47. package/dist/node/Diviner.d.ts +38 -0
  48. package/dist/node/Diviner.d.ts.map +1 -0
  49. package/dist/node/Params.d.cts +5 -0
  50. package/dist/node/Params.d.cts.map +1 -0
  51. package/dist/node/Params.d.mts +5 -0
  52. package/dist/node/Params.d.mts.map +1 -0
  53. package/dist/node/Params.d.ts +5 -0
  54. package/dist/node/Params.d.ts.map +1 -0
  55. package/dist/node/Schema.d.cts +3 -0
  56. package/dist/node/Schema.d.cts.map +1 -0
  57. package/dist/node/Schema.d.mts +3 -0
  58. package/dist/node/Schema.d.mts.map +1 -0
  59. package/dist/node/Schema.d.ts +3 -0
  60. package/dist/node/Schema.d.ts.map +1 -0
  61. package/dist/node/index.cjs +171 -0
  62. package/dist/node/index.cjs.map +1 -0
  63. package/dist/node/index.d.cts +5 -0
  64. package/dist/node/index.d.cts.map +1 -0
  65. package/dist/node/index.d.mts +5 -0
  66. package/dist/node/index.d.mts.map +1 -0
  67. package/dist/node/index.d.ts +5 -0
  68. package/dist/node/index.d.ts.map +1 -0
  69. package/dist/node/index.js +144 -0
  70. package/dist/node/index.js.map +1 -0
  71. package/package.json +76 -0
  72. package/src/Config.ts +33 -0
  73. package/src/Diviner.ts +156 -0
  74. package/src/Params.ts +6 -0
  75. package/src/Schema.ts +4 -0
  76. package/src/index.ts +4 -0
  77. package/typedoc.json +5 -0
@@ -0,0 +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 { PayloadDivinerSchema } from '@xyo-network/diviner-payload-model'\n\nexport const IndexedDbPayloadDivinerSchema = `${PayloadDivinerSchema}.indexeddb`\nexport type IndexedDbPayloadDivinerSchema = typeof IndexedDbPayloadDivinerSchema\n","import { IndexDescription } from '@xyo-network/archivist-model'\nimport { DivinerConfig } from '@xyo-network/diviner-model'\n\nimport { IndexedDbPayloadDivinerSchema } from './Schema'\n\nexport const IndexedDbPayloadDivinerConfigSchema = `${IndexedDbPayloadDivinerSchema}.config`\nexport type IndexedDbPayloadDivinerConfigSchema = typeof IndexedDbPayloadDivinerConfigSchema\n\nexport type IndexedDbPayloadDivinerConfig = 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: IndexedDbPayloadDivinerConfigSchema\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 { assertEx } from '@xylabs/assert'\nimport { IndexSeparator } from '@xyo-network/archivist-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'\nimport { isPayloadDivinerQueryPayload, PayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { AnyObject } from '@xyo-network/object'\nimport { Payload } from '@xyo-network/payload-model'\nimport { IDBPDatabase, IDBPObjectStore, openDB } from 'idb'\n\nimport { IndexedDbPayloadDivinerConfigSchema } from './Config'\nimport { IndexedDbPayloadDivinerParams } from './Params'\n\ninterface PayloadStore {\n [s: string]: Payload\n}\n\nexport class IndexedDbPayloadDiviner<\n TParams extends IndexedDbPayloadDivinerParams = IndexedDbPayloadDivinerParams,\n TIn extends PayloadDivinerQueryPayload = PayloadDivinerQueryPayload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends PayloadDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [IndexedDbPayloadDivinerConfigSchema]\n static defaultDbName = 'archivist'\n static defaultDbVersion = 1\n static defaultStoreName = 'payloads'\n\n private _db: IDBPDatabase<PayloadStore> | undefined\n\n /**\n * The database name. If not supplied via config it defaults to\n * `archivist`. This behavior biases towards a single, isolated\n * DB per archivist which seems to make the most sense for 99% of\n * use cases.\n */\n get dbName() {\n return this.config?.dbName ?? IndexedDbPayloadDiviner.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 ?? IndexedDbPayloadDiviner.defaultDbVersion\n }\n\n /**\n * The database indexes.\n */\n get indexes() {\n return this.config?.storage?.indexes ?? []\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 ?? IndexedDbPayloadDiviner.defaultStoreName\n }\n\n private get db(): IDBPDatabase<PayloadStore> {\n return assertEx(this._db, 'DB not initialized')\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n const query = assertEx(payloads?.filter(isPayloadDivinerQueryPayload)?.pop(), 'Missing query payload')\n if (!query) return []\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { schemas, limit, offset, hash, order, schema: _schema, sources, ...props } = query as unknown as TIn & { sources?: string[] }\n const tx = this.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 assertEx((schemas?.length ?? 1) === 1, 'IndexedDbPayloadDiviner: Only one filter schema supported')\n const filterSchema = schemas?.[0]\n const filter = filterSchema ? { schema: filterSchema, ...props } : { ...props }\n const direction: IDBCursorDirection = order === 'desc' ? 'prev' : 'next'\n const suggestedIndex = this.selectBestIndex(filter, store)\n const filterValues = this.getKeyValuesFromQuery(suggestedIndex, filter)\n let cursor = suggestedIndex\n ? // Conditionally filter on schemas\n await store.index(suggestedIndex).openCursor(IDBKeyRange.only(filterValues.length === 1 ? filterValues[0] : filterValues), direction)\n : // Just iterate all records\n await store.openCursor(suggestedIndex, direction)\n\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 // Collect results up to the limit\n while (cursor && results.length < parsedLimit) {\n results.push(cursor.value)\n cursor = await cursor.continue()\n }\n await tx.done\n // Remove any metadata before returning to the client\n return results.map((payload) => PayloadHasher.jsonPayload(payload))\n }\n\n protected override async startHandler() {\n await super.startHandler()\n // NOTE: We could defer this creation to first access but we\n // want to fail fast here in case something is wrong\n this._db = await openDB<PayloadStore>(this.dbName, this.dbVersion)\n return true\n }\n\n private getKeyValuesFromQuery(indexName: string | null, query: AnyObject): unknown[] {\n if (!indexName) return []\n // Function to extract fields from an index name\n const extractFields = (indexName: string): string[] => {\n return indexName\n .slice(3)\n .split(IndexSeparator)\n .map((field) => field.toLowerCase())\n }\n\n // Extracting the relevant fields from the index name\n const indexFields = extractFields(indexName)\n\n // Collecting the values for these fields from the query object\n return indexFields.map((field) => query[field as keyof AnyObject])\n }\n\n private selectBestIndex(query: AnyObject, store: IDBPObjectStore<PayloadStore>): string | null {\n // List of available indexes\n const { indexNames } = store\n\n // Function to extract fields from an index name\n const extractFields = (indexName: string): string[] => {\n return indexName\n .slice(3)\n .split(IndexSeparator)\n .map((field) => field.toLowerCase())\n }\n\n // Convert query object keys to a set for easier comparison\n const queryKeys = new Set(Object.keys(query).map((key) => key.toLowerCase()))\n\n // Find the best matching index\n let bestMatch: { indexName: string; matchCount: number } = { indexName: '', matchCount: 0 }\n\n for (const indexName of indexNames) {\n const indexFields = extractFields(indexName)\n const matchCount = indexFields.filter((field) => queryKeys.has(field)).length\n if (matchCount > bestMatch.matchCount) {\n bestMatch = {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tB,UAAMC,cAAcN,cAAcD,SAAAA;AAGlC,WAAOO,YAAYb,IAAI,CAACW,UAAUhD,MAAMgD,KAAAA,CAAyB;EACnE;EAEQxB,gBAAgBxB,OAAkBe,OAAqD;AAE7F,UAAM,EAAEoC,WAAU,IAAKpC;AAGvB,UAAM6B,gBAAgB,wBAACD,cAAAA;AACrB,aAAOA,UACJE,MAAM,CAAA,EACNC,MAAMC,qCAAAA,EACNV,IAAI,CAACW,UAAUA,MAAMC,YAAW,CAAA;IACrC,GALsB;AAQtB,UAAMG,YAAY,IAAIC,IAAIC,OAAOC,KAAKvD,KAAAA,EAAOqC,IAAI,CAACmB,QAAQA,IAAIP,YAAW,CAAA,CAAA;AAGzE,QAAIQ,YAAuD;MAAEd,WAAW;MAAIe,YAAY;IAAE;AAE1F,eAAWf,aAAaQ,YAAY;AAClC,YAAMD,cAAcN,cAAcD,SAAAA;AAClC,YAAMe,aAAaR,YAAYjD,OAAO,CAAC+C,UAAUI,UAAUO,IAAIX,KAAAA,CAAAA,EAAQ5B;AACvE,UAAIsC,aAAaD,UAAUC,YAAY;AACrCD,oBAAY;UAAEd;UAAWe;QAAW;MACtC;IACF;AACA,WAAOD,UAAUC,aAAa,IAAID,UAAUd,YAAY;EAC1D;AACF;","names":["IndexedDbPayloadDivinerSchema","PayloadDivinerSchema","IndexedDbPayloadDivinerConfigSchema","IndexedDbPayloadDivinerSchema","import_diviner_payload_model","IndexedDbPayloadDiviner","PayloadDiviner","configSchemas","IndexedDbPayloadDivinerConfigSchema","defaultDbName","defaultDbVersion","defaultStoreName","_db","dbName","config","dbVersion","indexes","storage","storeName","db","assertEx","divineHandler","payloads","query","filter","isPayloadDivinerQueryPayload","pop","schemas","limit","offset","hash","order","schema","_schema","sources","props","tx","transaction","store","objectStore","results","parsedOffset","parsedLimit","length","filterSchema","direction","suggestedIndex","selectBestIndex","filterValues","getKeyValuesFromQuery","cursor","index","openCursor","IDBKeyRange","only","advance","push","value","continue","done","map","payload","PayloadHasher","jsonPayload","startHandler","openDB","indexName","extractFields","slice","split","IndexSeparator","field","toLowerCase","indexFields","indexNames","queryKeys","Set","Object","keys","key","bestMatch","matchCount","has"]}
@@ -0,0 +1,5 @@
1
+ export * from './Config';
2
+ export * from './Diviner';
3
+ export * from './Params';
4
+ export * from './Schema';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA"}
@@ -0,0 +1,5 @@
1
+ export * from './Config';
2
+ export * from './Diviner';
3
+ export * from './Params';
4
+ export * from './Schema';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA"}
@@ -0,0 +1,5 @@
1
+ export * from './Config';
2
+ export * from './Diviner';
3
+ export * from './Params';
4
+ export * from './Schema';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA"}
@@ -0,0 +1,135 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/Schema.ts
5
+ import { PayloadDivinerSchema } from "@xyo-network/diviner-payload-model";
6
+ var IndexedDbPayloadDivinerSchema = `${PayloadDivinerSchema}.indexeddb`;
7
+
8
+ // src/Config.ts
9
+ var IndexedDbPayloadDivinerConfigSchema = `${IndexedDbPayloadDivinerSchema}.config`;
10
+
11
+ // src/Diviner.ts
12
+ import { assertEx } from "@xylabs/assert";
13
+ import { IndexSeparator } from "@xyo-network/archivist-model";
14
+ import { PayloadDiviner } from "@xyo-network/diviner-payload-abstract";
15
+ import { isPayloadDivinerQueryPayload } from "@xyo-network/diviner-payload-model";
16
+ import { PayloadHasher } from "@xyo-network/hash";
17
+ import { openDB } from "idb";
18
+ var IndexedDbPayloadDiviner = class _IndexedDbPayloadDiviner extends PayloadDiviner {
19
+ static {
20
+ __name(this, "IndexedDbPayloadDiviner");
21
+ }
22
+ static configSchemas = [
23
+ IndexedDbPayloadDivinerConfigSchema
24
+ ];
25
+ static defaultDbName = "archivist";
26
+ static defaultDbVersion = 1;
27
+ static defaultStoreName = "payloads";
28
+ _db;
29
+ /**
30
+ * The database name. If not supplied via config it defaults to
31
+ * `archivist`. This behavior biases towards a single, isolated
32
+ * DB per archivist which seems to make the most sense for 99% of
33
+ * use cases.
34
+ */
35
+ get dbName() {
36
+ return this.config?.dbName ?? _IndexedDbPayloadDiviner.defaultDbName;
37
+ }
38
+ /**
39
+ * The database version. If not supplied via config, it defaults to 1.
40
+ */
41
+ get dbVersion() {
42
+ return this.config?.dbVersion ?? _IndexedDbPayloadDiviner.defaultDbVersion;
43
+ }
44
+ /**
45
+ * The database indexes.
46
+ */
47
+ get indexes() {
48
+ return this.config?.storage?.indexes ?? [];
49
+ }
50
+ /**
51
+ * The name of the object store. If not supplied via config, it defaults
52
+ * to `payloads`.
53
+ */
54
+ get storeName() {
55
+ return this.config?.storeName ?? _IndexedDbPayloadDiviner.defaultStoreName;
56
+ }
57
+ get db() {
58
+ return assertEx(this._db, "DB not initialized");
59
+ }
60
+ async divineHandler(payloads) {
61
+ const query = assertEx(payloads?.filter(isPayloadDivinerQueryPayload)?.pop(), "Missing query payload");
62
+ if (!query)
63
+ return [];
64
+ const { schemas, limit, offset, hash, order, schema: _schema, sources, ...props } = query;
65
+ const tx = this.db.transaction(this.storeName, "readonly");
66
+ const store = tx.objectStore(this.storeName);
67
+ const results = [];
68
+ let parsedOffset = offset ?? 0;
69
+ const parsedLimit = limit ?? 10;
70
+ assertEx((schemas?.length ?? 1) === 1, "IndexedDbPayloadDiviner: Only one filter schema supported");
71
+ const filterSchema = schemas?.[0];
72
+ const filter = filterSchema ? {
73
+ schema: filterSchema,
74
+ ...props
75
+ } : {
76
+ ...props
77
+ };
78
+ const direction = order === "desc" ? "prev" : "next";
79
+ const suggestedIndex = this.selectBestIndex(filter, store);
80
+ const filterValues = this.getKeyValuesFromQuery(suggestedIndex, filter);
81
+ let cursor = suggestedIndex ? await store.index(suggestedIndex).openCursor(IDBKeyRange.only(filterValues.length === 1 ? filterValues[0] : filterValues), direction) : await store.openCursor(suggestedIndex, direction);
82
+ while (cursor && parsedOffset > 0) {
83
+ cursor = await cursor.advance(parsedOffset);
84
+ parsedOffset = 0;
85
+ }
86
+ while (cursor && results.length < parsedLimit) {
87
+ results.push(cursor.value);
88
+ cursor = await cursor.continue();
89
+ }
90
+ await tx.done;
91
+ return results.map((payload) => PayloadHasher.jsonPayload(payload));
92
+ }
93
+ async startHandler() {
94
+ await super.startHandler();
95
+ this._db = await openDB(this.dbName, this.dbVersion);
96
+ return true;
97
+ }
98
+ getKeyValuesFromQuery(indexName, query) {
99
+ if (!indexName)
100
+ return [];
101
+ const extractFields = /* @__PURE__ */ __name((indexName2) => {
102
+ return indexName2.slice(3).split(IndexSeparator).map((field) => field.toLowerCase());
103
+ }, "extractFields");
104
+ const indexFields = extractFields(indexName);
105
+ return indexFields.map((field) => query[field]);
106
+ }
107
+ selectBestIndex(query, store) {
108
+ const { indexNames } = store;
109
+ const extractFields = /* @__PURE__ */ __name((indexName) => {
110
+ return indexName.slice(3).split(IndexSeparator).map((field) => field.toLowerCase());
111
+ }, "extractFields");
112
+ const queryKeys = new Set(Object.keys(query).map((key) => key.toLowerCase()));
113
+ let bestMatch = {
114
+ indexName: "",
115
+ matchCount: 0
116
+ };
117
+ for (const indexName of indexNames) {
118
+ const indexFields = extractFields(indexName);
119
+ const matchCount = indexFields.filter((field) => queryKeys.has(field)).length;
120
+ if (matchCount > bestMatch.matchCount) {
121
+ bestMatch = {
122
+ indexName,
123
+ matchCount
124
+ };
125
+ }
126
+ }
127
+ return bestMatch.matchCount > 0 ? bestMatch.indexName : null;
128
+ }
129
+ };
130
+ export {
131
+ IndexedDbPayloadDiviner,
132
+ IndexedDbPayloadDivinerConfigSchema,
133
+ IndexedDbPayloadDivinerSchema
134
+ };
135
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts"],"sourcesContent":["import { PayloadDivinerSchema } from '@xyo-network/diviner-payload-model'\n\nexport const IndexedDbPayloadDivinerSchema = `${PayloadDivinerSchema}.indexeddb`\nexport type IndexedDbPayloadDivinerSchema = typeof IndexedDbPayloadDivinerSchema\n","import { IndexDescription } from '@xyo-network/archivist-model'\nimport { DivinerConfig } from '@xyo-network/diviner-model'\n\nimport { IndexedDbPayloadDivinerSchema } from './Schema'\n\nexport const IndexedDbPayloadDivinerConfigSchema = `${IndexedDbPayloadDivinerSchema}.config`\nexport type IndexedDbPayloadDivinerConfigSchema = typeof IndexedDbPayloadDivinerConfigSchema\n\nexport type IndexedDbPayloadDivinerConfig = 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: IndexedDbPayloadDivinerConfigSchema\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 { assertEx } from '@xylabs/assert'\nimport { IndexSeparator } from '@xyo-network/archivist-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'\nimport { isPayloadDivinerQueryPayload, PayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { AnyObject } from '@xyo-network/object'\nimport { Payload } from '@xyo-network/payload-model'\nimport { IDBPDatabase, IDBPObjectStore, openDB } from 'idb'\n\nimport { IndexedDbPayloadDivinerConfigSchema } from './Config'\nimport { IndexedDbPayloadDivinerParams } from './Params'\n\ninterface PayloadStore {\n [s: string]: Payload\n}\n\nexport class IndexedDbPayloadDiviner<\n TParams extends IndexedDbPayloadDivinerParams = IndexedDbPayloadDivinerParams,\n TIn extends PayloadDivinerQueryPayload = PayloadDivinerQueryPayload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends PayloadDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [IndexedDbPayloadDivinerConfigSchema]\n static defaultDbName = 'archivist'\n static defaultDbVersion = 1\n static defaultStoreName = 'payloads'\n\n private _db: IDBPDatabase<PayloadStore> | undefined\n\n /**\n * The database name. If not supplied via config it defaults to\n * `archivist`. This behavior biases towards a single, isolated\n * DB per archivist which seems to make the most sense for 99% of\n * use cases.\n */\n get dbName() {\n return this.config?.dbName ?? IndexedDbPayloadDiviner.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 ?? IndexedDbPayloadDiviner.defaultDbVersion\n }\n\n /**\n * The database indexes.\n */\n get indexes() {\n return this.config?.storage?.indexes ?? []\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 ?? IndexedDbPayloadDiviner.defaultStoreName\n }\n\n private get db(): IDBPDatabase<PayloadStore> {\n return assertEx(this._db, 'DB not initialized')\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n const query = assertEx(payloads?.filter(isPayloadDivinerQueryPayload)?.pop(), 'Missing query payload')\n if (!query) return []\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { schemas, limit, offset, hash, order, schema: _schema, sources, ...props } = query as unknown as TIn & { sources?: string[] }\n const tx = this.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 assertEx((schemas?.length ?? 1) === 1, 'IndexedDbPayloadDiviner: Only one filter schema supported')\n const filterSchema = schemas?.[0]\n const filter = filterSchema ? { schema: filterSchema, ...props } : { ...props }\n const direction: IDBCursorDirection = order === 'desc' ? 'prev' : 'next'\n const suggestedIndex = this.selectBestIndex(filter, store)\n const filterValues = this.getKeyValuesFromQuery(suggestedIndex, filter)\n let cursor = suggestedIndex\n ? // Conditionally filter on schemas\n await store.index(suggestedIndex).openCursor(IDBKeyRange.only(filterValues.length === 1 ? filterValues[0] : filterValues), direction)\n : // Just iterate all records\n await store.openCursor(suggestedIndex, direction)\n\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 // Collect results up to the limit\n while (cursor && results.length < parsedLimit) {\n results.push(cursor.value)\n cursor = await cursor.continue()\n }\n await tx.done\n // Remove any metadata before returning to the client\n return results.map((payload) => PayloadHasher.jsonPayload(payload))\n }\n\n protected override async startHandler() {\n await super.startHandler()\n // NOTE: We could defer this creation to first access but we\n // want to fail fast here in case something is wrong\n this._db = await openDB<PayloadStore>(this.dbName, this.dbVersion)\n return true\n }\n\n private getKeyValuesFromQuery(indexName: string | null, query: AnyObject): unknown[] {\n if (!indexName) return []\n // Function to extract fields from an index name\n const extractFields = (indexName: string): string[] => {\n return indexName\n .slice(3)\n .split(IndexSeparator)\n .map((field) => field.toLowerCase())\n }\n\n // Extracting the relevant fields from the index name\n const indexFields = extractFields(indexName)\n\n // Collecting the values for these fields from the query object\n return indexFields.map((field) => query[field as keyof AnyObject])\n }\n\n private selectBestIndex(query: AnyObject, store: IDBPObjectStore<PayloadStore>): string | null {\n // List of available indexes\n const { indexNames } = store\n\n // Function to extract fields from an index name\n const extractFields = (indexName: string): string[] => {\n return indexName\n .slice(3)\n .split(IndexSeparator)\n .map((field) => field.toLowerCase())\n }\n\n // Convert query object keys to a set for easier comparison\n const queryKeys = new Set(Object.keys(query).map((key) => key.toLowerCase()))\n\n // Find the best matching index\n let bestMatch: { indexName: string; matchCount: number } = { indexName: '', matchCount: 0 }\n\n for (const indexName of indexNames) {\n const indexFields = extractFields(indexName)\n const matchCount = indexFields.filter((field) => queryKeys.has(field)).length\n if (matchCount > bestMatch.matchCount) {\n bestMatch = { indexName, matchCount }\n }\n }\n return bestMatch.matchCount > 0 ? bestMatch.indexName : null\n }\n}\n"],"mappings":";;;;AAAA,SAASA,4BAA4B;AAE9B,IAAMC,gCAAgC,GAAGD,oBAAAA;;;ACGzC,IAAME,sCAAsC,GAAGC,6BAAAA;;;ACLtD,SAASC,gBAAgB;AACzB,SAASC,sBAAsB;AAE/B,SAASC,sBAAsB;AAC/B,SAASC,oCAAgE;AACzE,SAASC,qBAAqB;AAG9B,SAAwCC,cAAc;AAS/C,IAAMC,0BAAN,MAAMA,iCAKHC,eAAAA;EAtBV,OAsBUA;;;EACR,OAAgBC,gBAAgB;IAACC;;EACjC,OAAOC,gBAAgB;EACvB,OAAOC,mBAAmB;EAC1B,OAAOC,mBAAmB;EAElBC;;;;;;;EAQR,IAAIC,SAAS;AACX,WAAO,KAAKC,QAAQD,UAAUR,yBAAwBI;EACxD;;;;EAKA,IAAIM,YAAY;AACd,WAAO,KAAKD,QAAQC,aAAaV,yBAAwBK;EAC3D;;;;EAKA,IAAIM,UAAU;AACZ,WAAO,KAAKF,QAAQG,SAASD,WAAW,CAAA;EAC1C;;;;;EAMA,IAAIE,YAAY;AACd,WAAO,KAAKJ,QAAQI,aAAab,yBAAwBM;EAC3D;EAEA,IAAYQ,KAAiC;AAC3C,WAA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adDivinerSchema","IndexedDbPayloadDivinerConfigSchema","IndexedDbPayloadDivinerSchema","assertEx","IndexSeparator","PayloadDiviner","isPayloadDivinerQueryPayload","PayloadHasher","openDB","IndexedDbPayloadDiviner","PayloadDiviner","configSchemas","IndexedDbPayloadDivinerConfigSchema","defaultDbName","defaultDbVersion","defaultStoreName","_db","dbName","config","dbVersion","indexes","storage","storeName","db","assertEx","divineHandler","payloads","query","filter","isPayloadDivinerQueryPayload","pop","schemas","limit","offset","hash","order","schema","_schema","sources","props","tx","transaction","store","objectStore","results","parsedOffset","parsedLimit","length","filterSchema","direction","suggestedIndex","selectBestIndex","filterValues","getKeyValuesFromQuery","cursor","index","openCursor","IDBKeyRange","only","advance","push","value","continue","done","map","payload","PayloadHasher","jsonPayload","startHandler","openDB","indexName","extractFields","slice","split","IndexSeparator","field","toLowerCase","indexFields","indexNames","queryKeys","Set","Object","keys","key","bestMatch","matchCount","has"]}
@@ -0,0 +1,30 @@
1
+ import { IndexDescription } from '@xyo-network/archivist-model';
2
+ import { DivinerConfig } from '@xyo-network/diviner-model';
3
+ export declare const IndexedDbPayloadDivinerConfigSchema: string;
4
+ export type IndexedDbPayloadDivinerConfigSchema = typeof IndexedDbPayloadDivinerConfigSchema;
5
+ export type IndexedDbPayloadDivinerConfig = DivinerConfig<{
6
+ /**
7
+ * The database name
8
+ */
9
+ dbName?: string;
10
+ /**
11
+ * The version of the DB, defaults to 1
12
+ */
13
+ dbVersion?: number;
14
+ schema: IndexedDbPayloadDivinerConfigSchema;
15
+ /**
16
+ * The storage configuration
17
+ * // TODO: Hoist to main diviner config
18
+ */
19
+ storage?: {
20
+ /**
21
+ * The indexes to create on the object store
22
+ */
23
+ indexes?: IndexDescription[];
24
+ };
25
+ /**
26
+ * The name of the object store
27
+ */
28
+ storeName?: string;
29
+ }>;
30
+ //# sourceMappingURL=Config.d.ts.map
@@ -0,0 +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,mCAAmC,QAA4C,CAAA;AAC5F,MAAM,MAAM,mCAAmC,GAAG,OAAO,mCAAmC,CAAA;AAE5F,MAAM,MAAM,6BAA6B,GAAG,aAAa,CAAC;IACxD;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,mCAAmC,CAAA;IAC3C;;;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"}
@@ -0,0 +1,30 @@
1
+ import { IndexDescription } from '@xyo-network/archivist-model';
2
+ import { DivinerConfig } from '@xyo-network/diviner-model';
3
+ export declare const IndexedDbPayloadDivinerConfigSchema: string;
4
+ export type IndexedDbPayloadDivinerConfigSchema = typeof IndexedDbPayloadDivinerConfigSchema;
5
+ export type IndexedDbPayloadDivinerConfig = DivinerConfig<{
6
+ /**
7
+ * The database name
8
+ */
9
+ dbName?: string;
10
+ /**
11
+ * The version of the DB, defaults to 1
12
+ */
13
+ dbVersion?: number;
14
+ schema: IndexedDbPayloadDivinerConfigSchema;
15
+ /**
16
+ * The storage configuration
17
+ * // TODO: Hoist to main diviner config
18
+ */
19
+ storage?: {
20
+ /**
21
+ * The indexes to create on the object store
22
+ */
23
+ indexes?: IndexDescription[];
24
+ };
25
+ /**
26
+ * The name of the object store
27
+ */
28
+ storeName?: string;
29
+ }>;
30
+ //# sourceMappingURL=Config.d.ts.map
@@ -0,0 +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,mCAAmC,QAA4C,CAAA;AAC5F,MAAM,MAAM,mCAAmC,GAAG,OAAO,mCAAmC,CAAA;AAE5F,MAAM,MAAM,6BAA6B,GAAG,aAAa,CAAC;IACxD;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,mCAAmC,CAAA;IAC3C;;;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"}
@@ -0,0 +1,30 @@
1
+ import { IndexDescription } from '@xyo-network/archivist-model';
2
+ import { DivinerConfig } from '@xyo-network/diviner-model';
3
+ export declare const IndexedDbPayloadDivinerConfigSchema: string;
4
+ export type IndexedDbPayloadDivinerConfigSchema = typeof IndexedDbPayloadDivinerConfigSchema;
5
+ export type IndexedDbPayloadDivinerConfig = DivinerConfig<{
6
+ /**
7
+ * The database name
8
+ */
9
+ dbName?: string;
10
+ /**
11
+ * The version of the DB, defaults to 1
12
+ */
13
+ dbVersion?: number;
14
+ schema: IndexedDbPayloadDivinerConfigSchema;
15
+ /**
16
+ * The storage configuration
17
+ * // TODO: Hoist to main diviner config
18
+ */
19
+ storage?: {
20
+ /**
21
+ * The indexes to create on the object store
22
+ */
23
+ indexes?: IndexDescription[];
24
+ };
25
+ /**
26
+ * The name of the object store
27
+ */
28
+ storeName?: string;
29
+ }>;
30
+ //# sourceMappingURL=Config.d.ts.map
@@ -0,0 +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,mCAAmC,QAA4C,CAAA;AAC5F,MAAM,MAAM,mCAAmC,GAAG,OAAO,mCAAmC,CAAA;AAE5F,MAAM,MAAM,6BAA6B,GAAG,aAAa,CAAC;IACxD;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,mCAAmC,CAAA;IAC3C;;;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"}
@@ -0,0 +1,38 @@
1
+ import { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model';
2
+ import { PayloadDiviner } from '@xyo-network/diviner-payload-abstract';
3
+ import { PayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model';
4
+ import { Payload } from '@xyo-network/payload-model';
5
+ import { IndexedDbPayloadDivinerParams } from './Params';
6
+ export declare class IndexedDbPayloadDiviner<TParams extends IndexedDbPayloadDivinerParams = IndexedDbPayloadDivinerParams, TIn extends PayloadDivinerQueryPayload = PayloadDivinerQueryPayload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>> extends PayloadDiviner<TParams, TIn, TOut, TEventData> {
7
+ static configSchemas: string[];
8
+ static defaultDbName: string;
9
+ static defaultDbVersion: number;
10
+ static defaultStoreName: string;
11
+ private _db;
12
+ /**
13
+ * The database name. If not supplied via config it defaults to
14
+ * `archivist`. This behavior biases towards a single, isolated
15
+ * DB per archivist which seems to make the most sense for 99% of
16
+ * use cases.
17
+ */
18
+ get dbName(): string;
19
+ /**
20
+ * The database version. If not supplied via config, it defaults to 1.
21
+ */
22
+ get dbVersion(): number;
23
+ /**
24
+ * The database indexes.
25
+ */
26
+ get indexes(): import("@xyo-network/archivist-model").IndexDescription[];
27
+ /**
28
+ * The name of the object store. If not supplied via config, it defaults
29
+ * to `payloads`.
30
+ */
31
+ get storeName(): string;
32
+ private get db();
33
+ protected divineHandler(payloads?: TIn[]): Promise<TOut[]>;
34
+ protected startHandler(): Promise<boolean>;
35
+ private getKeyValuesFromQuery;
36
+ private selectBestIndex;
37
+ }
38
+ //# sourceMappingURL=Diviner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AACtE,OAAO,EAAgC,0BAA0B,EAAE,MAAM,oCAAoC,CAAA;AAG7G,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAIpD,OAAO,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAA;AAMxD,qBAAa,uBAAuB,CAClC,OAAO,SAAS,6BAA6B,GAAG,6BAA6B,EAC7E,GAAG,SAAS,0BAA0B,GAAG,0BAA0B,EACnE,IAAI,SAAS,OAAO,GAAG,OAAO,EAC9B,UAAU,SAAS,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,CACxI,SAAQ,cAAc,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACtD,OAAgB,aAAa,WAAwC;IACrE,MAAM,CAAC,aAAa,SAAc;IAClC,MAAM,CAAC,gBAAgB,SAAI;IAC3B,MAAM,CAAC,gBAAgB,SAAa;IAEpC,OAAO,CAAC,GAAG,CAAwC;IAEnD;;;;;OAKG;IACH,IAAI,MAAM,WAET;IAED;;OAEG;IACH,IAAI,SAAS,WAEZ;IAED;;OAEG;IACH,IAAI,OAAO,8DAEV;IAED;;;OAGG;IACH,IAAI,SAAS,WAEZ;IAED,OAAO,KAAK,EAAE,GAEb;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cAqChD,YAAY;IAQrC,OAAO,CAAC,qBAAqB;IAiB7B,OAAO,CAAC,eAAe;CA2BxB"}
@@ -0,0 +1,38 @@
1
+ import { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model';
2
+ import { PayloadDiviner } from '@xyo-network/diviner-payload-abstract';
3
+ import { PayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model';
4
+ import { Payload } from '@xyo-network/payload-model';
5
+ import { IndexedDbPayloadDivinerParams } from './Params';
6
+ export declare class IndexedDbPayloadDiviner<TParams extends IndexedDbPayloadDivinerParams = IndexedDbPayloadDivinerParams, TIn extends PayloadDivinerQueryPayload = PayloadDivinerQueryPayload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>> extends PayloadDiviner<TParams, TIn, TOut, TEventData> {
7
+ static configSchemas: string[];
8
+ static defaultDbName: string;
9
+ static defaultDbVersion: number;
10
+ static defaultStoreName: string;
11
+ private _db;
12
+ /**
13
+ * The database name. If not supplied via config it defaults to
14
+ * `archivist`. This behavior biases towards a single, isolated
15
+ * DB per archivist which seems to make the most sense for 99% of
16
+ * use cases.
17
+ */
18
+ get dbName(): string;
19
+ /**
20
+ * The database version. If not supplied via config, it defaults to 1.
21
+ */
22
+ get dbVersion(): number;
23
+ /**
24
+ * The database indexes.
25
+ */
26
+ get indexes(): import("@xyo-network/archivist-model").IndexDescription[];
27
+ /**
28
+ * The name of the object store. If not supplied via config, it defaults
29
+ * to `payloads`.
30
+ */
31
+ get storeName(): string;
32
+ private get db();
33
+ protected divineHandler(payloads?: TIn[]): Promise<TOut[]>;
34
+ protected startHandler(): Promise<boolean>;
35
+ private getKeyValuesFromQuery;
36
+ private selectBestIndex;
37
+ }
38
+ //# sourceMappingURL=Diviner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AACtE,OAAO,EAAgC,0BAA0B,EAAE,MAAM,oCAAoC,CAAA;AAG7G,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAIpD,OAAO,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAA;AAMxD,qBAAa,uBAAuB,CAClC,OAAO,SAAS,6BAA6B,GAAG,6BAA6B,EAC7E,GAAG,SAAS,0BAA0B,GAAG,0BAA0B,EACnE,IAAI,SAAS,OAAO,GAAG,OAAO,EAC9B,UAAU,SAAS,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,CACxI,SAAQ,cAAc,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACtD,OAAgB,aAAa,WAAwC;IACrE,MAAM,CAAC,aAAa,SAAc;IAClC,MAAM,CAAC,gBAAgB,SAAI;IAC3B,MAAM,CAAC,gBAAgB,SAAa;IAEpC,OAAO,CAAC,GAAG,CAAwC;IAEnD;;;;;OAKG;IACH,IAAI,MAAM,WAET;IAED;;OAEG;IACH,IAAI,SAAS,WAEZ;IAED;;OAEG;IACH,IAAI,OAAO,8DAEV;IAED;;;OAGG;IACH,IAAI,SAAS,WAEZ;IAED,OAAO,KAAK,EAAE,GAEb;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cAqChD,YAAY;IAQrC,OAAO,CAAC,qBAAqB;IAiB7B,OAAO,CAAC,eAAe;CA2BxB"}
@@ -0,0 +1,38 @@
1
+ import { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model';
2
+ import { PayloadDiviner } from '@xyo-network/diviner-payload-abstract';
3
+ import { PayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model';
4
+ import { Payload } from '@xyo-network/payload-model';
5
+ import { IndexedDbPayloadDivinerParams } from './Params';
6
+ export declare class IndexedDbPayloadDiviner<TParams extends IndexedDbPayloadDivinerParams = IndexedDbPayloadDivinerParams, TIn extends PayloadDivinerQueryPayload = PayloadDivinerQueryPayload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>> extends PayloadDiviner<TParams, TIn, TOut, TEventData> {
7
+ static configSchemas: string[];
8
+ static defaultDbName: string;
9
+ static defaultDbVersion: number;
10
+ static defaultStoreName: string;
11
+ private _db;
12
+ /**
13
+ * The database name. If not supplied via config it defaults to
14
+ * `archivist`. This behavior biases towards a single, isolated
15
+ * DB per archivist which seems to make the most sense for 99% of
16
+ * use cases.
17
+ */
18
+ get dbName(): string;
19
+ /**
20
+ * The database version. If not supplied via config, it defaults to 1.
21
+ */
22
+ get dbVersion(): number;
23
+ /**
24
+ * The database indexes.
25
+ */
26
+ get indexes(): import("@xyo-network/archivist-model").IndexDescription[];
27
+ /**
28
+ * The name of the object store. If not supplied via config, it defaults
29
+ * to `payloads`.
30
+ */
31
+ get storeName(): string;
32
+ private get db();
33
+ protected divineHandler(payloads?: TIn[]): Promise<TOut[]>;
34
+ protected startHandler(): Promise<boolean>;
35
+ private getKeyValuesFromQuery;
36
+ private selectBestIndex;
37
+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AqB;IAiB7B,OAAO,CAAC,eAAe;CA2BxB"}
@@ -0,0 +1,5 @@
1
+ import { DivinerParams } from '@xyo-network/diviner-model';
2
+ import { AnyConfigSchema } from '@xyo-network/module-model';
3
+ import { IndexedDbPayloadDivinerConfig } from './Config';
4
+ export type IndexedDbPayloadDivinerParams = DivinerParams<AnyConfigSchema<IndexedDbPayloadDivinerConfig>>;
5
+ //# sourceMappingURL=Params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Params.d.ts","sourceRoot":"","sources":["../../src/Params.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAE3D,OAAO,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAA;AAExD,MAAM,MAAM,6BAA6B,GAAG,aAAa,CAAC,eAAe,CAAC,6BAA6B,CAAC,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { DivinerParams } from '@xyo-network/diviner-model';
2
+ import { AnyConfigSchema } from '@xyo-network/module-model';
3
+ import { IndexedDbPayloadDivinerConfig } from './Config';
4
+ export type IndexedDbPayloadDivinerParams = DivinerParams<AnyConfigSchema<IndexedDbPayloadDivinerConfig>>;
5
+ //# sourceMappingURL=Params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Params.d.ts","sourceRoot":"","sources":["../../src/Params.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAE3D,OAAO,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAA;AAExD,MAAM,MAAM,6BAA6B,GAAG,aAAa,CAAC,eAAe,CAAC,6BAA6B,CAAC,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { DivinerParams } from '@xyo-network/diviner-model';
2
+ import { AnyConfigSchema } from '@xyo-network/module-model';
3
+ import { IndexedDbPayloadDivinerConfig } from './Config';
4
+ export type IndexedDbPayloadDivinerParams = DivinerParams<AnyConfigSchema<IndexedDbPayloadDivinerConfig>>;
5
+ //# sourceMappingURL=Params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Params.d.ts","sourceRoot":"","sources":["../../src/Params.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAE3D,OAAO,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAA;AAExD,MAAM,MAAM,6BAA6B,GAAG,aAAa,CAAC,eAAe,CAAC,6BAA6B,CAAC,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ export declare const IndexedDbPayloadDivinerSchema: string;
2
+ export type IndexedDbPayloadDivinerSchema = typeof IndexedDbPayloadDivinerSchema;
3
+ //# sourceMappingURL=Schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,6BAA6B,QAAsC,CAAA;AAChF,MAAM,MAAM,6BAA6B,GAAG,OAAO,6BAA6B,CAAA"}
@@ -0,0 +1,3 @@
1
+ export declare const IndexedDbPayloadDivinerSchema: string;
2
+ export type IndexedDbPayloadDivinerSchema = typeof IndexedDbPayloadDivinerSchema;
3
+ //# sourceMappingURL=Schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,6BAA6B,QAAsC,CAAA;AAChF,MAAM,MAAM,6BAA6B,GAAG,OAAO,6BAA6B,CAAA"}
@@ -0,0 +1,3 @@
1
+ export declare const IndexedDbPayloadDivinerSchema: string;
2
+ export type IndexedDbPayloadDivinerSchema = typeof IndexedDbPayloadDivinerSchema;
3
+ //# sourceMappingURL=Schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,6BAA6B,QAAsC,CAAA;AAChF,MAAM,MAAM,6BAA6B,GAAG,OAAO,6BAA6B,CAAA"}