@xyo-network/archivist-indexeddb 2.75.0 → 2.75.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/IndexedDbArchivist.d.cts +52 -0
- package/dist/browser/IndexedDbArchivist.d.cts.map +1 -0
- package/dist/browser/IndexedDbArchivist.js +8 -10
- package/dist/browser/IndexedDbArchivist.js.map +1 -1
- package/dist/browser/index.d.cts +2 -0
- package/dist/browser/index.d.cts.map +1 -0
- package/dist/browser/index.js +1 -110
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/sample.archivist.xyo.cjs +19 -0
- package/dist/browser/sample.archivist.xyo.cjs.map +1 -0
- package/dist/browser/sample.archivist.xyo.js +22 -0
- package/dist/browser/sample.archivist.xyo.js.map +1 -0
- package/dist/docs.json +22913 -0
- package/dist/node/IndexedDbArchivist.d.cts +52 -0
- package/dist/node/IndexedDbArchivist.d.cts.map +1 -0
- package/dist/node/IndexedDbArchivist.js +17 -13
- package/dist/node/IndexedDbArchivist.js.map +1 -1
- package/dist/node/IndexedDbArchivist.mjs +23 -19
- package/dist/node/IndexedDbArchivist.mjs.map +1 -1
- package/dist/node/index.d.cts +2 -0
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.js +119 -3
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +112 -1
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/sample.archivist.xyo.js +23 -0
- package/dist/node/sample.archivist.xyo.js.map +1 -0
- package/dist/node/sample.archivist.xyo.mjs +23 -0
- package/dist/node/sample.archivist.xyo.mjs.map +1 -0
- package/package.json +14 -14
- package/dist/browser/sample.archivist.xyo.json +0 -16
- package/dist/node/sample.archivist.xyo.json +0 -16
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { AbstractArchivist } from '@xyo-network/archivist-abstract';
|
|
2
|
+
import { ArchivistConfig, ArchivistModuleEventData, ArchivistParams } from '@xyo-network/archivist-model';
|
|
3
|
+
import { AnyConfigSchema } from '@xyo-network/module';
|
|
4
|
+
import { Payload } from '@xyo-network/payload-model';
|
|
5
|
+
export type IndexedDbArchivistConfigSchema = 'network.xyo.archivist.indexeddb.config';
|
|
6
|
+
export declare const IndexedDbArchivistConfigSchema: IndexedDbArchivistConfigSchema;
|
|
7
|
+
export type IndexedDbArchivistConfig = ArchivistConfig<{
|
|
8
|
+
/**
|
|
9
|
+
* The database name
|
|
10
|
+
*/
|
|
11
|
+
dbName?: string;
|
|
12
|
+
schema: IndexedDbArchivistConfigSchema;
|
|
13
|
+
/**
|
|
14
|
+
* The name of the object store
|
|
15
|
+
*/
|
|
16
|
+
storeName?: string;
|
|
17
|
+
}>;
|
|
18
|
+
export type IndexedDbArchivistParams = ArchivistParams<AnyConfigSchema<IndexedDbArchivistConfig>>;
|
|
19
|
+
export declare class IndexedDbArchivist<TParams extends IndexedDbArchivistParams = IndexedDbArchivistParams, TEventData extends ArchivistModuleEventData = ArchivistModuleEventData> extends AbstractArchivist<TParams, TEventData> {
|
|
20
|
+
static configSchemas: "network.xyo.archivist.indexeddb.config"[];
|
|
21
|
+
static defaultDbName: string;
|
|
22
|
+
static defaultStoreName: string;
|
|
23
|
+
private _db;
|
|
24
|
+
/**
|
|
25
|
+
* The database name. If not supplied via config, it defaults
|
|
26
|
+
* to the module name (not guaranteed to be unique) and if module
|
|
27
|
+
* name is not supplied, it defaults to `archivist`. This behavior
|
|
28
|
+
* biases towards a single, isolated DB per archivist which seems to
|
|
29
|
+
* make the most sense for 99% of use cases.
|
|
30
|
+
*/
|
|
31
|
+
get dbName(): string;
|
|
32
|
+
get queries(): string[];
|
|
33
|
+
/**
|
|
34
|
+
* The name of the object store. If not supplied via config, it defaults
|
|
35
|
+
* to `payloads`. The limitation of the current IndexedDB wrapper we're
|
|
36
|
+
* using is that it only supports a single object store per DB. See here:
|
|
37
|
+
* https://github.com/jakearchibald/idb-keyval/blob/main/custom-stores.md#defining-a-custom-database--store-name
|
|
38
|
+
* If this becomes a problem or we need migrations/transactions, we can
|
|
39
|
+
* move to this more-flexible library, which they recommend (and who
|
|
40
|
+
* recommends them for our simple use case of key-value storage):
|
|
41
|
+
* https://www.npmjs.com/package/idb
|
|
42
|
+
*/
|
|
43
|
+
get storeName(): string;
|
|
44
|
+
private get db();
|
|
45
|
+
protected allHandler(): Promise<Payload[]>;
|
|
46
|
+
protected clearHandler(): Promise<void>;
|
|
47
|
+
protected deleteHandler(hashes: string[]): Promise<string[]>;
|
|
48
|
+
protected getHandler(hashes: string[]): Promise<Payload[]>;
|
|
49
|
+
protected insertHandler(payloads: Payload[]): Promise<Payload[]>;
|
|
50
|
+
protected startHandler(): Promise<boolean>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=IndexedDbArchivist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndexedDbArchivist.d.ts","sourceRoot":"","sources":["../../src/IndexedDbArchivist.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AACnE,OAAO,EAGL,eAAe,EAGf,wBAAwB,EACxB,eAAe,EAChB,MAAM,8BAA8B,CAAA;AAErC,OAAO,EAAE,eAAe,EAAmB,MAAM,qBAAqB,CAAA;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAGpD,MAAM,MAAM,8BAA8B,GAAG,wCAAwC,CAAA;AACrF,eAAO,MAAM,8BAA8B,EAAE,8BAAyE,CAAA;AAEtH,MAAM,MAAM,wBAAwB,GAAG,eAAe,CAAC;IACrD;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,8BAA8B,CAAA;IACtC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAC,CAAA;AAEF,MAAM,MAAM,wBAAwB,GAAG,eAAe,CAAC,eAAe,CAAC,wBAAwB,CAAC,CAAC,CAAA;AAEjG,qBACa,kBAAkB,CAC7B,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,EACnE,UAAU,SAAS,wBAAwB,GAAG,wBAAwB,CACtE,SAAQ,iBAAiB,CAAC,OAAO,EAAE,UAAU,CAAC;IAC9C,OAAgB,aAAa,6CAAmC;IAChE,MAAM,CAAC,aAAa,SAAc;IAClC,MAAM,CAAC,gBAAgB,SAAa;IAEpC,OAAO,CAAC,GAAG,CAAsB;IAEjC;;;;;;OAMG;IACH,IAAI,MAAM,WAET;IAED,IAAa,OAAO,aAEnB;IACD;;;;;;;;;OASG;IACH,IAAI,SAAS,WAEZ;IAED,OAAO,KAAK,EAAE,GAEb;cAEwB,UAAU,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;cAKhC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;cAI7B,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;cAWlD,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;cAIhD,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;cAYtD,YAAY;CAOtC"}
|
|
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
8
|
var __export = (target, all) => {
|
|
8
9
|
for (var name in all)
|
|
@@ -17,6 +18,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
18
|
return to;
|
|
18
19
|
};
|
|
19
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var __publicField = (obj, key, value) => {
|
|
22
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/IndexedDbArchivist.ts
|
|
20
27
|
var IndexedDbArchivist_exports = {};
|
|
21
28
|
__export(IndexedDbArchivist_exports, {
|
|
22
29
|
IndexedDbArchivist: () => IndexedDbArchivist,
|
|
@@ -40,16 +47,9 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
40
47
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
41
48
|
}
|
|
42
49
|
__name(_ts_decorate, "_ts_decorate");
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
__name(this, "IndexedDbArchivist");
|
|
47
|
-
}
|
|
48
|
-
static configSchemas = [
|
|
49
|
-
IndexedDbArchivistConfigSchema
|
|
50
|
-
];
|
|
51
|
-
static defaultDbName = "archivist";
|
|
52
|
-
static defaultStoreName = "payloads";
|
|
50
|
+
var IndexedDbArchivistConfigSchema = "network.xyo.archivist.indexeddb.config";
|
|
51
|
+
var _a;
|
|
52
|
+
var IndexedDbArchivist = (_a = class extends import_archivist_abstract.AbstractArchivist {
|
|
53
53
|
_db;
|
|
54
54
|
/**
|
|
55
55
|
* The database name. If not supplied via config, it defaults
|
|
@@ -59,7 +59,8 @@ let IndexedDbArchivist = class IndexedDbArchivist2 extends import_archivist_abst
|
|
|
59
59
|
* make the most sense for 99% of use cases.
|
|
60
60
|
*/
|
|
61
61
|
get dbName() {
|
|
62
|
-
|
|
62
|
+
var _a2, _b;
|
|
63
|
+
return ((_a2 = this.config) == null ? void 0 : _a2.dbName) ?? ((_b = this.config) == null ? void 0 : _b.name) ?? _a.defaultDbName;
|
|
63
64
|
}
|
|
64
65
|
get queries() {
|
|
65
66
|
return [
|
|
@@ -81,7 +82,8 @@ let IndexedDbArchivist = class IndexedDbArchivist2 extends import_archivist_abst
|
|
|
81
82
|
* https://www.npmjs.com/package/idb
|
|
82
83
|
*/
|
|
83
84
|
get storeName() {
|
|
84
|
-
|
|
85
|
+
var _a2;
|
|
86
|
+
return ((_a2 = this.config) == null ? void 0 : _a2.storeName) ?? _a.defaultStoreName;
|
|
85
87
|
}
|
|
86
88
|
get db() {
|
|
87
89
|
return (0, import_assert.assertEx)(this._db, "DB not initialized");
|
|
@@ -121,7 +123,9 @@ let IndexedDbArchivist = class IndexedDbArchivist2 extends import_archivist_abst
|
|
|
121
123
|
this._db = (0, import_idb_keyval.createStore)(this.dbName, this.storeName);
|
|
122
124
|
return true;
|
|
123
125
|
}
|
|
124
|
-
}
|
|
126
|
+
}, __name(_a, "IndexedDbArchivist"), __publicField(_a, "configSchemas", [
|
|
127
|
+
IndexedDbArchivistConfigSchema
|
|
128
|
+
]), __publicField(_a, "defaultDbName", "archivist"), __publicField(_a, "defaultStoreName", "payloads"), _a);
|
|
125
129
|
IndexedDbArchivist = _ts_decorate([
|
|
126
130
|
(0, import_module.creatableModule)()
|
|
127
131
|
], IndexedDbArchivist);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/IndexedDbArchivist.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractArchivist } from '@xyo-network/archivist-abstract'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistConfig,\n ArchivistDeleteQuerySchema,\n ArchivistInsertQuerySchema,\n ArchivistModuleEventData,\n ArchivistParams,\n} from '@xyo-network/archivist-model'\nimport { PayloadHasher } from '@xyo-network/core'\nimport { AnyConfigSchema, creatableModule } from '@xyo-network/module'\nimport { Payload } from '@xyo-network/payload-model'\nimport { clear, createStore, delMany, entries, getMany, setMany, UseStore } from 'idb-keyval'\n\nexport type IndexedDbArchivistConfigSchema = 'network.xyo.archivist.indexeddb.config'\nexport const IndexedDbArchivistConfigSchema: IndexedDbArchivistConfigSchema = 'network.xyo.archivist.indexeddb.config'\n\nexport type IndexedDbArchivistConfig = ArchivistConfig<{\n /**\n * The database name\n */\n dbName?: string\n schema: IndexedDbArchivistConfigSchema\n /**\n * The name of the object store\n */\n storeName?: string\n}>\n\nexport type IndexedDbArchivistParams = ArchivistParams<AnyConfigSchema<IndexedDbArchivistConfig>>\n\n@creatableModule()\nexport class IndexedDbArchivist<\n TParams extends IndexedDbArchivistParams = IndexedDbArchivistParams,\n TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,\n> extends AbstractArchivist<TParams, TEventData> {\n static override configSchemas = [IndexedDbArchivistConfigSchema]\n static defaultDbName = 'archivist'\n static defaultStoreName = 'payloads'\n\n private _db: UseStore | undefined\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the module name (not guaranteed to be unique) and if module\n * name is not supplied, 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?.name ?? IndexedDbArchivist.defaultDbName\n }\n\n override get queries() {\n return [ArchivistAllQuerySchema, ArchivistClearQuerySchema, ArchivistDeleteQuerySchema, ArchivistInsertQuerySchema, ...super.queries]\n }\n /**\n * The name of the object store. If not supplied via config, it defaults\n * to `payloads`. The limitation of the current IndexedDB wrapper we're\n * using is that it only supports a single object store per DB. See here:\n * https://github.com/jakearchibald/idb-keyval/blob/main/custom-stores.md#defining-a-custom-database--store-name\n * If this becomes a problem or we need migrations/transactions, we can\n * move to this more-flexible library, which they recommend (and who\n * recommends them for our simple use case of key-value storage):\n * https://www.npmjs.com/package/idb\n */\n get storeName() {\n return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName\n }\n\n private get db(): UseStore {\n return assertEx(this._db, 'DB not initialized')\n }\n\n protected override async allHandler(): Promise<Payload[]> {\n const result = await entries<string, Payload>(this.db)\n return result.map<Payload>(([_hash, payload]) => payload)\n }\n\n protected override async clearHandler(): Promise<void> {\n await clear(this.db)\n }\n\n protected override async deleteHandler(hashes: string[]): Promise<string[]> {\n const payloadPairs: [string, Payload][] = await Promise.all(\n (await this.get(hashes)).map<Promise<[string, Payload]>>(async (payload) => [await PayloadHasher.hashAsync(payload), payload]),\n )\n\n const foundHashesToDelete = payloadPairs.map(([hash, _]) => hash)\n await delMany(foundHashesToDelete, this.db)\n\n return foundHashesToDelete\n }\n\n protected override async getHandler(hashes: string[]): Promise<Payload[]> {\n return (await getMany<Payload>(hashes, this.db)).filter((result) => result !== undefined)\n }\n\n protected override async insertHandler(payloads: Payload[]): Promise<Payload[]> {\n const entries = await Promise.all(\n payloads.map<Promise<[string, Payload]>>(async (payload) => {\n const hash = await PayloadHasher.hashAsync(payload)\n return [hash, payload]\n }),\n )\n await setMany(entries, this.db)\n\n return payloads\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 = createStore(this.dbName, this.storeName)\n return true\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/IndexedDbArchivist.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractArchivist } from '@xyo-network/archivist-abstract'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistConfig,\n ArchivistDeleteQuerySchema,\n ArchivistInsertQuerySchema,\n ArchivistModuleEventData,\n ArchivistParams,\n} from '@xyo-network/archivist-model'\nimport { PayloadHasher } from '@xyo-network/core'\nimport { AnyConfigSchema, creatableModule } from '@xyo-network/module'\nimport { Payload } from '@xyo-network/payload-model'\nimport { clear, createStore, delMany, entries, getMany, setMany, UseStore } from 'idb-keyval'\n\nexport type IndexedDbArchivistConfigSchema = 'network.xyo.archivist.indexeddb.config'\nexport const IndexedDbArchivistConfigSchema: IndexedDbArchivistConfigSchema = 'network.xyo.archivist.indexeddb.config'\n\nexport type IndexedDbArchivistConfig = ArchivistConfig<{\n /**\n * The database name\n */\n dbName?: string\n schema: IndexedDbArchivistConfigSchema\n /**\n * The name of the object store\n */\n storeName?: string\n}>\n\nexport type IndexedDbArchivistParams = ArchivistParams<AnyConfigSchema<IndexedDbArchivistConfig>>\n\n@creatableModule()\nexport class IndexedDbArchivist<\n TParams extends IndexedDbArchivistParams = IndexedDbArchivistParams,\n TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,\n> extends AbstractArchivist<TParams, TEventData> {\n static override configSchemas = [IndexedDbArchivistConfigSchema]\n static defaultDbName = 'archivist'\n static defaultStoreName = 'payloads'\n\n private _db: UseStore | undefined\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the module name (not guaranteed to be unique) and if module\n * name is not supplied, 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?.name ?? IndexedDbArchivist.defaultDbName\n }\n\n override get queries() {\n return [ArchivistAllQuerySchema, ArchivistClearQuerySchema, ArchivistDeleteQuerySchema, ArchivistInsertQuerySchema, ...super.queries]\n }\n /**\n * The name of the object store. If not supplied via config, it defaults\n * to `payloads`. The limitation of the current IndexedDB wrapper we're\n * using is that it only supports a single object store per DB. See here:\n * https://github.com/jakearchibald/idb-keyval/blob/main/custom-stores.md#defining-a-custom-database--store-name\n * If this becomes a problem or we need migrations/transactions, we can\n * move to this more-flexible library, which they recommend (and who\n * recommends them for our simple use case of key-value storage):\n * https://www.npmjs.com/package/idb\n */\n get storeName() {\n return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName\n }\n\n private get db(): UseStore {\n return assertEx(this._db, 'DB not initialized')\n }\n\n protected override async allHandler(): Promise<Payload[]> {\n const result = await entries<string, Payload>(this.db)\n return result.map<Payload>(([_hash, payload]) => payload)\n }\n\n protected override async clearHandler(): Promise<void> {\n await clear(this.db)\n }\n\n protected override async deleteHandler(hashes: string[]): Promise<string[]> {\n const payloadPairs: [string, Payload][] = await Promise.all(\n (await this.get(hashes)).map<Promise<[string, Payload]>>(async (payload) => [await PayloadHasher.hashAsync(payload), payload]),\n )\n\n const foundHashesToDelete = payloadPairs.map(([hash, _]) => hash)\n await delMany(foundHashesToDelete, this.db)\n\n return foundHashesToDelete\n }\n\n protected override async getHandler(hashes: string[]): Promise<Payload[]> {\n return (await getMany<Payload>(hashes, this.db)).filter((result) => result !== undefined)\n }\n\n protected override async insertHandler(payloads: Payload[]): Promise<Payload[]> {\n const entries = await Promise.all(\n payloads.map<Promise<[string, Payload]>>(async (payload) => {\n const hash = await PayloadHasher.hashAsync(payload)\n return [hash, payload]\n }),\n )\n await setMany(entries, this.db)\n\n return payloads\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 = createStore(this.dbName, this.storeName)\n return true\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oBAAyB;AACzB,gCAAkC;AAClC,6BAQO;AACP,kBAA8B;AAC9B,oBAAiD;AAEjD,wBAAiF;;;;;;;;;;;;AAG1E,IAAMA,iCAAiE;;AAiB9E,IAAaC,sBAAN,mBAGGC,4CAAAA;EAKAC;;;;;;;;EASR,IAAIC,SAAS;;AACX,aAAOC,MAAA,KAAKC,WAAL,gBAAAD,IAAaD,aAAU,UAAKE,WAAL,mBAAaC,SAAQN,GAAmBO;EACxE;EAEA,IAAaC,UAAU;AACrB,WAAO;MAACC;MAAyBC;MAA2BC;MAA4BC;SAA+B,MAAMJ;;EAC/H;;;;;;;;;;;EAWA,IAAIK,YAAY;;AACd,aAAOT,MAAA,KAAKC,WAAL,gBAAAD,IAAaS,cAAab,GAAmBc;EACtD;EAEA,IAAYC,KAAe;AACzB,eAAOC,wBAAS,KAAKd,KAAK,oBAAA;EAC5B;EAEA,MAAyBe,aAAiC;AACxD,UAAMC,SAAS,UAAMC,2BAAyB,KAAKJ,EAAE;AACrD,WAAOG,OAAOE,IAAa,CAAC,CAACC,OAAOC,OAAAA,MAAaA,OAAAA;EACnD;EAEA,MAAyBC,eAA8B;AACrD,cAAMC,yBAAM,KAAKT,EAAE;EACrB;EAEA,MAAyBU,cAAcC,QAAqC;AAC1E,UAAMC,eAAoC,MAAMC,QAAQC,KACrD,MAAM,KAAKC,IAAIJ,MAAAA,GAASN,IAAgC,OAAOE,YAAY;MAAC,MAAMS,0BAAcC,UAAUV,OAAAA;MAAUA;KAAQ,CAAA;AAG/H,UAAMW,sBAAsBN,aAAaP,IAAI,CAAC,CAACc,MAAMC,CAAAA,MAAOD,IAAAA;AAC5D,cAAME,2BAAQH,qBAAqB,KAAKlB,EAAE;AAE1C,WAAOkB;EACT;EAEA,MAAyBI,WAAWX,QAAsC;AACxE,YAAQ,UAAMY,2BAAiBZ,QAAQ,KAAKX,EAAE,GAAGwB,OAAO,CAACrB,WAAWA,WAAWsB,MAAAA;EACjF;EAEA,MAAyBC,cAAcC,UAAyC;AAC9E,UAAMvB,WAAU,MAAMS,QAAQC,IAC5Ba,SAAStB,IAAgC,OAAOE,YAAAA;AAC9C,YAAMY,OAAO,MAAMH,0BAAcC,UAAUV,OAAAA;AAC3C,aAAO;QAACY;QAAMZ;;IAChB,CAAA,CAAA;AAEF,cAAMqB,2BAAQxB,UAAS,KAAKJ,EAAE;AAE9B,WAAO2B;EACT;EAEA,MAAyBE,eAAe;AACtC,UAAM,MAAMA,aAAAA;AAGZ,SAAK1C,UAAM2C,+BAAY,KAAK1C,QAAQ,KAAKU,SAAS;AAClD,WAAO;EACT;AACF,GAlFUZ,kCACR,cAJK,IAIW6C,iBAAgB;EAAC/C;IACjC,cALK,IAKEQ,iBAAgB,cACvB,cANK,IAMEO,oBAAmB,aANrB;AAAMd,qBAAAA,aAAAA;MADZ+C,+BAAAA;GACY/C,kBAAAA;","names":["IndexedDbArchivistConfigSchema","IndexedDbArchivist","AbstractArchivist","_db","dbName","_a","config","name","defaultDbName","queries","ArchivistAllQuerySchema","ArchivistClearQuerySchema","ArchivistDeleteQuerySchema","ArchivistInsertQuerySchema","storeName","defaultStoreName","db","assertEx","allHandler","result","entries","map","_hash","payload","clearHandler","clear","deleteHandler","hashes","payloadPairs","Promise","all","get","PayloadHasher","hashAsync","foundHashesToDelete","hash","_","delMany","getHandler","getMany","filter","undefined","insertHandler","payloads","setMany","startHandler","createStore","configSchemas","creatableModule"]}
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __publicField = (obj, key, value) => {
|
|
5
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
return value;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/IndexedDbArchivist.ts
|
|
10
|
+
import { assertEx } from "@xylabs/assert";
|
|
11
|
+
import { AbstractArchivist } from "@xyo-network/archivist-abstract";
|
|
12
|
+
import { ArchivistAllQuerySchema, ArchivistClearQuerySchema, ArchivistDeleteQuerySchema, ArchivistInsertQuerySchema } from "@xyo-network/archivist-model";
|
|
13
|
+
import { PayloadHasher } from "@xyo-network/core";
|
|
14
|
+
import { creatableModule } from "@xyo-network/module";
|
|
15
|
+
import { clear, createStore, delMany, entries, getMany, setMany } from "idb-keyval";
|
|
3
16
|
function _ts_decorate(decorators, target, key, desc) {
|
|
4
17
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5
18
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -11,22 +24,9 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
11
24
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
12
25
|
}
|
|
13
26
|
__name(_ts_decorate, "_ts_decorate");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import { PayloadHasher } from "@xyo-network/core";
|
|
18
|
-
import { creatableModule } from "@xyo-network/module";
|
|
19
|
-
import { clear, createStore, delMany, entries, getMany, setMany } from "idb-keyval";
|
|
20
|
-
const IndexedDbArchivistConfigSchema = "network.xyo.archivist.indexeddb.config";
|
|
21
|
-
let IndexedDbArchivist = class IndexedDbArchivist2 extends AbstractArchivist {
|
|
22
|
-
static {
|
|
23
|
-
__name(this, "IndexedDbArchivist");
|
|
24
|
-
}
|
|
25
|
-
static configSchemas = [
|
|
26
|
-
IndexedDbArchivistConfigSchema
|
|
27
|
-
];
|
|
28
|
-
static defaultDbName = "archivist";
|
|
29
|
-
static defaultStoreName = "payloads";
|
|
27
|
+
var IndexedDbArchivistConfigSchema = "network.xyo.archivist.indexeddb.config";
|
|
28
|
+
var _a;
|
|
29
|
+
var IndexedDbArchivist = (_a = class extends AbstractArchivist {
|
|
30
30
|
_db;
|
|
31
31
|
/**
|
|
32
32
|
* The database name. If not supplied via config, it defaults
|
|
@@ -36,7 +36,8 @@ let IndexedDbArchivist = class IndexedDbArchivist2 extends AbstractArchivist {
|
|
|
36
36
|
* make the most sense for 99% of use cases.
|
|
37
37
|
*/
|
|
38
38
|
get dbName() {
|
|
39
|
-
|
|
39
|
+
var _a2, _b;
|
|
40
|
+
return ((_a2 = this.config) == null ? void 0 : _a2.dbName) ?? ((_b = this.config) == null ? void 0 : _b.name) ?? _a.defaultDbName;
|
|
40
41
|
}
|
|
41
42
|
get queries() {
|
|
42
43
|
return [
|
|
@@ -58,7 +59,8 @@ let IndexedDbArchivist = class IndexedDbArchivist2 extends AbstractArchivist {
|
|
|
58
59
|
* https://www.npmjs.com/package/idb
|
|
59
60
|
*/
|
|
60
61
|
get storeName() {
|
|
61
|
-
|
|
62
|
+
var _a2;
|
|
63
|
+
return ((_a2 = this.config) == null ? void 0 : _a2.storeName) ?? _a.defaultStoreName;
|
|
62
64
|
}
|
|
63
65
|
get db() {
|
|
64
66
|
return assertEx(this._db, "DB not initialized");
|
|
@@ -98,7 +100,9 @@ let IndexedDbArchivist = class IndexedDbArchivist2 extends AbstractArchivist {
|
|
|
98
100
|
this._db = createStore(this.dbName, this.storeName);
|
|
99
101
|
return true;
|
|
100
102
|
}
|
|
101
|
-
}
|
|
103
|
+
}, __name(_a, "IndexedDbArchivist"), __publicField(_a, "configSchemas", [
|
|
104
|
+
IndexedDbArchivistConfigSchema
|
|
105
|
+
]), __publicField(_a, "defaultDbName", "archivist"), __publicField(_a, "defaultStoreName", "payloads"), _a);
|
|
102
106
|
IndexedDbArchivist = _ts_decorate([
|
|
103
107
|
creatableModule()
|
|
104
108
|
], IndexedDbArchivist);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/IndexedDbArchivist.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractArchivist } from '@xyo-network/archivist-abstract'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistConfig,\n ArchivistDeleteQuerySchema,\n ArchivistInsertQuerySchema,\n ArchivistModuleEventData,\n ArchivistParams,\n} from '@xyo-network/archivist-model'\nimport { PayloadHasher } from '@xyo-network/core'\nimport { AnyConfigSchema, creatableModule } from '@xyo-network/module'\nimport { Payload } from '@xyo-network/payload-model'\nimport { clear, createStore, delMany, entries, getMany, setMany, UseStore } from 'idb-keyval'\n\nexport type IndexedDbArchivistConfigSchema = 'network.xyo.archivist.indexeddb.config'\nexport const IndexedDbArchivistConfigSchema: IndexedDbArchivistConfigSchema = 'network.xyo.archivist.indexeddb.config'\n\nexport type IndexedDbArchivistConfig = ArchivistConfig<{\n /**\n * The database name\n */\n dbName?: string\n schema: IndexedDbArchivistConfigSchema\n /**\n * The name of the object store\n */\n storeName?: string\n}>\n\nexport type IndexedDbArchivistParams = ArchivistParams<AnyConfigSchema<IndexedDbArchivistConfig>>\n\n@creatableModule()\nexport class IndexedDbArchivist<\n TParams extends IndexedDbArchivistParams = IndexedDbArchivistParams,\n TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,\n> extends AbstractArchivist<TParams, TEventData> {\n static override configSchemas = [IndexedDbArchivistConfigSchema]\n static defaultDbName = 'archivist'\n static defaultStoreName = 'payloads'\n\n private _db: UseStore | undefined\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the module name (not guaranteed to be unique) and if module\n * name is not supplied, 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?.name ?? IndexedDbArchivist.defaultDbName\n }\n\n override get queries() {\n return [ArchivistAllQuerySchema, ArchivistClearQuerySchema, ArchivistDeleteQuerySchema, ArchivistInsertQuerySchema, ...super.queries]\n }\n /**\n * The name of the object store. If not supplied via config, it defaults\n * to `payloads`. The limitation of the current IndexedDB wrapper we're\n * using is that it only supports a single object store per DB. See here:\n * https://github.com/jakearchibald/idb-keyval/blob/main/custom-stores.md#defining-a-custom-database--store-name\n * If this becomes a problem or we need migrations/transactions, we can\n * move to this more-flexible library, which they recommend (and who\n * recommends them for our simple use case of key-value storage):\n * https://www.npmjs.com/package/idb\n */\n get storeName() {\n return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName\n }\n\n private get db(): UseStore {\n return assertEx(this._db, 'DB not initialized')\n }\n\n protected override async allHandler(): Promise<Payload[]> {\n const result = await entries<string, Payload>(this.db)\n return result.map<Payload>(([_hash, payload]) => payload)\n }\n\n protected override async clearHandler(): Promise<void> {\n await clear(this.db)\n }\n\n protected override async deleteHandler(hashes: string[]): Promise<string[]> {\n const payloadPairs: [string, Payload][] = await Promise.all(\n (await this.get(hashes)).map<Promise<[string, Payload]>>(async (payload) => [await PayloadHasher.hashAsync(payload), payload]),\n )\n\n const foundHashesToDelete = payloadPairs.map(([hash, _]) => hash)\n await delMany(foundHashesToDelete, this.db)\n\n return foundHashesToDelete\n }\n\n protected override async getHandler(hashes: string[]): Promise<Payload[]> {\n return (await getMany<Payload>(hashes, this.db)).filter((result) => result !== undefined)\n }\n\n protected override async insertHandler(payloads: Payload[]): Promise<Payload[]> {\n const entries = await Promise.all(\n payloads.map<Promise<[string, Payload]>>(async (payload) => {\n const hash = await PayloadHasher.hashAsync(payload)\n return [hash, payload]\n }),\n )\n await setMany(entries, this.db)\n\n return payloads\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 = createStore(this.dbName, this.storeName)\n return true\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/IndexedDbArchivist.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractArchivist } from '@xyo-network/archivist-abstract'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistConfig,\n ArchivistDeleteQuerySchema,\n ArchivistInsertQuerySchema,\n ArchivistModuleEventData,\n ArchivistParams,\n} from '@xyo-network/archivist-model'\nimport { PayloadHasher } from '@xyo-network/core'\nimport { AnyConfigSchema, creatableModule } from '@xyo-network/module'\nimport { Payload } from '@xyo-network/payload-model'\nimport { clear, createStore, delMany, entries, getMany, setMany, UseStore } from 'idb-keyval'\n\nexport type IndexedDbArchivistConfigSchema = 'network.xyo.archivist.indexeddb.config'\nexport const IndexedDbArchivistConfigSchema: IndexedDbArchivistConfigSchema = 'network.xyo.archivist.indexeddb.config'\n\nexport type IndexedDbArchivistConfig = ArchivistConfig<{\n /**\n * The database name\n */\n dbName?: string\n schema: IndexedDbArchivistConfigSchema\n /**\n * The name of the object store\n */\n storeName?: string\n}>\n\nexport type IndexedDbArchivistParams = ArchivistParams<AnyConfigSchema<IndexedDbArchivistConfig>>\n\n@creatableModule()\nexport class IndexedDbArchivist<\n TParams extends IndexedDbArchivistParams = IndexedDbArchivistParams,\n TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,\n> extends AbstractArchivist<TParams, TEventData> {\n static override configSchemas = [IndexedDbArchivistConfigSchema]\n static defaultDbName = 'archivist'\n static defaultStoreName = 'payloads'\n\n private _db: UseStore | undefined\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the module name (not guaranteed to be unique) and if module\n * name is not supplied, 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?.name ?? IndexedDbArchivist.defaultDbName\n }\n\n override get queries() {\n return [ArchivistAllQuerySchema, ArchivistClearQuerySchema, ArchivistDeleteQuerySchema, ArchivistInsertQuerySchema, ...super.queries]\n }\n /**\n * The name of the object store. If not supplied via config, it defaults\n * to `payloads`. The limitation of the current IndexedDB wrapper we're\n * using is that it only supports a single object store per DB. See here:\n * https://github.com/jakearchibald/idb-keyval/blob/main/custom-stores.md#defining-a-custom-database--store-name\n * If this becomes a problem or we need migrations/transactions, we can\n * move to this more-flexible library, which they recommend (and who\n * recommends them for our simple use case of key-value storage):\n * https://www.npmjs.com/package/idb\n */\n get storeName() {\n return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName\n }\n\n private get db(): UseStore {\n return assertEx(this._db, 'DB not initialized')\n }\n\n protected override async allHandler(): Promise<Payload[]> {\n const result = await entries<string, Payload>(this.db)\n return result.map<Payload>(([_hash, payload]) => payload)\n }\n\n protected override async clearHandler(): Promise<void> {\n await clear(this.db)\n }\n\n protected override async deleteHandler(hashes: string[]): Promise<string[]> {\n const payloadPairs: [string, Payload][] = await Promise.all(\n (await this.get(hashes)).map<Promise<[string, Payload]>>(async (payload) => [await PayloadHasher.hashAsync(payload), payload]),\n )\n\n const foundHashesToDelete = payloadPairs.map(([hash, _]) => hash)\n await delMany(foundHashesToDelete, this.db)\n\n return foundHashesToDelete\n }\n\n protected override async getHandler(hashes: string[]): Promise<Payload[]> {\n return (await getMany<Payload>(hashes, this.db)).filter((result) => result !== undefined)\n }\n\n protected override async insertHandler(payloads: Payload[]): Promise<Payload[]> {\n const entries = await Promise.all(\n payloads.map<Promise<[string, Payload]>>(async (payload) => {\n const hash = await PayloadHasher.hashAsync(payload)\n return [hash, payload]\n }),\n )\n await setMany(entries, this.db)\n\n return payloads\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 = createStore(this.dbName, this.storeName)\n return true\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,yBAAyB;AAClC,SACEC,yBACAC,2BAEAC,4BACAC,kCAGK;AACP,SAASC,qBAAqB;AAC9B,SAA0BC,uBAAuB;AAEjD,SAASC,OAAOC,aAAaC,SAASC,SAASC,SAASC,eAAyB;;;;;;;;;;;;AAG1E,IAAMC,iCAAiE;;AAiB9E,IAAaC,sBAAN,mBAGGC,kBAAAA;EAKAC;;;;;;;;EASR,IAAIC,SAAS;;AACX,aAAOC,MAAA,KAAKC,WAAL,gBAAAD,IAAaD,aAAU,UAAKE,WAAL,mBAAaC,SAAQN,GAAmBO;EACxE;EAEA,IAAaC,UAAU;AACrB,WAAO;MAACC;MAAyBC;MAA2BC;MAA4BC;SAA+B,MAAMJ;;EAC/H;;;;;;;;;;;EAWA,IAAIK,YAAY;;AACd,aAAOT,MAAA,KAAKC,WAAL,gBAAAD,IAAaS,cAAab,GAAmBc;EACtD;EAEA,IAAYC,KAAe;AACzB,WAAOC,SAAS,KAAKd,KAAK,oBAAA;EAC5B;EAEA,MAAyBe,aAAiC;AACxD,UAAMC,SAAS,MAAMC,QAAyB,KAAKJ,EAAE;AACrD,WAAOG,OAAOE,IAAa,CAAC,CAACC,OAAOC,OAAAA,MAAaA,OAAAA;EACnD;EAEA,MAAyBC,eAA8B;AACrD,UAAMC,MAAM,KAAKT,EAAE;EACrB;EAEA,MAAyBU,cAAcC,QAAqC;AAC1E,UAAMC,eAAoC,MAAMC,QAAQC,KACrD,MAAM,KAAKC,IAAIJ,MAAAA,GAASN,IAAgC,OAAOE,YAAY;MAAC,MAAMS,cAAcC,UAAUV,OAAAA;MAAUA;KAAQ,CAAA;AAG/H,UAAMW,sBAAsBN,aAAaP,IAAI,CAAC,CAACc,MAAMC,CAAAA,MAAOD,IAAAA;AAC5D,UAAME,QAAQH,qBAAqB,KAAKlB,EAAE;AAE1C,WAAOkB;EACT;EAEA,MAAyBI,WAAWX,QAAsC;AACxE,YAAQ,MAAMY,QAAiBZ,QAAQ,KAAKX,EAAE,GAAGwB,OAAO,CAACrB,WAAWA,WAAWsB,MAAAA;EACjF;EAEA,MAAyBC,cAAcC,UAAyC;AAC9E,UAAMvB,WAAU,MAAMS,QAAQC,IAC5Ba,SAAStB,IAAgC,OAAOE,YAAAA;AAC9C,YAAMY,OAAO,MAAMH,cAAcC,UAAUV,OAAAA;AAC3C,aAAO;QAACY;QAAMZ;;IAChB,CAAA,CAAA;AAEF,UAAMqB,QAAQxB,UAAS,KAAKJ,EAAE;AAE9B,WAAO2B;EACT;EAEA,MAAyBE,eAAe;AACtC,UAAM,MAAMA,aAAAA;AAGZ,SAAK1C,MAAM2C,YAAY,KAAK1C,QAAQ,KAAKU,SAAS;AAClD,WAAO;EACT;AACF,GAlFUZ,kCACR,cAJK,IAIW6C,iBAAgB;EAAC/C;IACjC,cALK,IAKEQ,iBAAgB,cACvB,cANK,IAMEO,oBAAmB,aANrB;AAAMd,qBAAAA,aAAAA;EADZ+C,gBAAAA;GACY/C,kBAAAA;","names":["assertEx","AbstractArchivist","ArchivistAllQuerySchema","ArchivistClearQuerySchema","ArchivistDeleteQuerySchema","ArchivistInsertQuerySchema","PayloadHasher","creatableModule","clear","createStore","delMany","entries","getMany","setMany","IndexedDbArchivistConfigSchema","IndexedDbArchivist","AbstractArchivist","_db","dbName","_a","config","name","defaultDbName","queries","ArchivistAllQuerySchema","ArchivistClearQuerySchema","ArchivistDeleteQuerySchema","ArchivistInsertQuerySchema","storeName","defaultStoreName","db","assertEx","allHandler","result","entries","map","_hash","payload","clearHandler","clear","deleteHandler","hashes","payloadPairs","Promise","all","get","PayloadHasher","hashAsync","foundHashesToDelete","hash","_","delMany","getHandler","getMany","filter","undefined","insertHandler","payloads","setMany","startHandler","createStore","configSchemas","creatableModule"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA"}
|
package/dist/node/index.js
CHANGED
|
@@ -3,6 +3,12 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
6
12
|
var __copyProps = (to, from, except, desc) => {
|
|
7
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
14
|
for (let key of __getOwnPropNames(from))
|
|
@@ -11,13 +17,123 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
11
17
|
}
|
|
12
18
|
return to;
|
|
13
19
|
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var __publicField = (obj, key, value) => {
|
|
22
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/index.ts
|
|
16
27
|
var src_exports = {};
|
|
28
|
+
__export(src_exports, {
|
|
29
|
+
IndexedDbArchivist: () => IndexedDbArchivist,
|
|
30
|
+
IndexedDbArchivistConfigSchema: () => IndexedDbArchivistConfigSchema
|
|
31
|
+
});
|
|
17
32
|
module.exports = __toCommonJS(src_exports);
|
|
18
|
-
|
|
33
|
+
|
|
34
|
+
// src/IndexedDbArchivist.ts
|
|
35
|
+
var import_assert = require("@xylabs/assert");
|
|
36
|
+
var import_archivist_abstract = require("@xyo-network/archivist-abstract");
|
|
37
|
+
var import_archivist_model = require("@xyo-network/archivist-model");
|
|
38
|
+
var import_core = require("@xyo-network/core");
|
|
39
|
+
var import_module = require("@xyo-network/module");
|
|
40
|
+
var import_idb_keyval = require("idb-keyval");
|
|
41
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
42
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
43
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
44
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
45
|
+
else
|
|
46
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
47
|
+
if (d = decorators[i])
|
|
48
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
49
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
50
|
+
}
|
|
51
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
52
|
+
var IndexedDbArchivistConfigSchema = "network.xyo.archivist.indexeddb.config";
|
|
53
|
+
var _a;
|
|
54
|
+
var IndexedDbArchivist = (_a = class extends import_archivist_abstract.AbstractArchivist {
|
|
55
|
+
_db;
|
|
56
|
+
/**
|
|
57
|
+
* The database name. If not supplied via config, it defaults
|
|
58
|
+
* to the module name (not guaranteed to be unique) and if module
|
|
59
|
+
* name is not supplied, it defaults to `archivist`. This behavior
|
|
60
|
+
* biases towards a single, isolated DB per archivist which seems to
|
|
61
|
+
* make the most sense for 99% of use cases.
|
|
62
|
+
*/
|
|
63
|
+
get dbName() {
|
|
64
|
+
var _a2, _b;
|
|
65
|
+
return ((_a2 = this.config) == null ? void 0 : _a2.dbName) ?? ((_b = this.config) == null ? void 0 : _b.name) ?? _a.defaultDbName;
|
|
66
|
+
}
|
|
67
|
+
get queries() {
|
|
68
|
+
return [
|
|
69
|
+
import_archivist_model.ArchivistAllQuerySchema,
|
|
70
|
+
import_archivist_model.ArchivistClearQuerySchema,
|
|
71
|
+
import_archivist_model.ArchivistDeleteQuerySchema,
|
|
72
|
+
import_archivist_model.ArchivistInsertQuerySchema,
|
|
73
|
+
...super.queries
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The name of the object store. If not supplied via config, it defaults
|
|
78
|
+
* to `payloads`. The limitation of the current IndexedDB wrapper we're
|
|
79
|
+
* using is that it only supports a single object store per DB. See here:
|
|
80
|
+
* https://github.com/jakearchibald/idb-keyval/blob/main/custom-stores.md#defining-a-custom-database--store-name
|
|
81
|
+
* If this becomes a problem or we need migrations/transactions, we can
|
|
82
|
+
* move to this more-flexible library, which they recommend (and who
|
|
83
|
+
* recommends them for our simple use case of key-value storage):
|
|
84
|
+
* https://www.npmjs.com/package/idb
|
|
85
|
+
*/
|
|
86
|
+
get storeName() {
|
|
87
|
+
var _a2;
|
|
88
|
+
return ((_a2 = this.config) == null ? void 0 : _a2.storeName) ?? _a.defaultStoreName;
|
|
89
|
+
}
|
|
90
|
+
get db() {
|
|
91
|
+
return (0, import_assert.assertEx)(this._db, "DB not initialized");
|
|
92
|
+
}
|
|
93
|
+
async allHandler() {
|
|
94
|
+
const result = await (0, import_idb_keyval.entries)(this.db);
|
|
95
|
+
return result.map(([_hash, payload]) => payload);
|
|
96
|
+
}
|
|
97
|
+
async clearHandler() {
|
|
98
|
+
await (0, import_idb_keyval.clear)(this.db);
|
|
99
|
+
}
|
|
100
|
+
async deleteHandler(hashes) {
|
|
101
|
+
const payloadPairs = await Promise.all((await this.get(hashes)).map(async (payload) => [
|
|
102
|
+
await import_core.PayloadHasher.hashAsync(payload),
|
|
103
|
+
payload
|
|
104
|
+
]));
|
|
105
|
+
const foundHashesToDelete = payloadPairs.map(([hash, _]) => hash);
|
|
106
|
+
await (0, import_idb_keyval.delMany)(foundHashesToDelete, this.db);
|
|
107
|
+
return foundHashesToDelete;
|
|
108
|
+
}
|
|
109
|
+
async getHandler(hashes) {
|
|
110
|
+
return (await (0, import_idb_keyval.getMany)(hashes, this.db)).filter((result) => result !== void 0);
|
|
111
|
+
}
|
|
112
|
+
async insertHandler(payloads) {
|
|
113
|
+
const entries2 = await Promise.all(payloads.map(async (payload) => {
|
|
114
|
+
const hash = await import_core.PayloadHasher.hashAsync(payload);
|
|
115
|
+
return [
|
|
116
|
+
hash,
|
|
117
|
+
payload
|
|
118
|
+
];
|
|
119
|
+
}));
|
|
120
|
+
await (0, import_idb_keyval.setMany)(entries2, this.db);
|
|
121
|
+
return payloads;
|
|
122
|
+
}
|
|
123
|
+
async startHandler() {
|
|
124
|
+
await super.startHandler();
|
|
125
|
+
this._db = (0, import_idb_keyval.createStore)(this.dbName, this.storeName);
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
}, __name(_a, "IndexedDbArchivist"), __publicField(_a, "configSchemas", [
|
|
129
|
+
IndexedDbArchivistConfigSchema
|
|
130
|
+
]), __publicField(_a, "defaultDbName", "archivist"), __publicField(_a, "defaultStoreName", "payloads"), _a);
|
|
131
|
+
IndexedDbArchivist = _ts_decorate([
|
|
132
|
+
(0, import_module.creatableModule)()
|
|
133
|
+
], IndexedDbArchivist);
|
|
19
134
|
// Annotate the CommonJS export names for ESM import in node:
|
|
20
135
|
0 && (module.exports = {
|
|
21
|
-
|
|
136
|
+
IndexedDbArchivist,
|
|
137
|
+
IndexedDbArchivistConfigSchema
|
|
22
138
|
});
|
|
23
139
|
//# sourceMappingURL=index.js.map
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './IndexedDbArchivist'\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/IndexedDbArchivist.ts"],"sourcesContent":["export * from './IndexedDbArchivist'\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractArchivist } from '@xyo-network/archivist-abstract'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistConfig,\n ArchivistDeleteQuerySchema,\n ArchivistInsertQuerySchema,\n ArchivistModuleEventData,\n ArchivistParams,\n} from '@xyo-network/archivist-model'\nimport { PayloadHasher } from '@xyo-network/core'\nimport { AnyConfigSchema, creatableModule } from '@xyo-network/module'\nimport { Payload } from '@xyo-network/payload-model'\nimport { clear, createStore, delMany, entries, getMany, setMany, UseStore } from 'idb-keyval'\n\nexport type IndexedDbArchivistConfigSchema = 'network.xyo.archivist.indexeddb.config'\nexport const IndexedDbArchivistConfigSchema: IndexedDbArchivistConfigSchema = 'network.xyo.archivist.indexeddb.config'\n\nexport type IndexedDbArchivistConfig = ArchivistConfig<{\n /**\n * The database name\n */\n dbName?: string\n schema: IndexedDbArchivistConfigSchema\n /**\n * The name of the object store\n */\n storeName?: string\n}>\n\nexport type IndexedDbArchivistParams = ArchivistParams<AnyConfigSchema<IndexedDbArchivistConfig>>\n\n@creatableModule()\nexport class IndexedDbArchivist<\n TParams extends IndexedDbArchivistParams = IndexedDbArchivistParams,\n TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,\n> extends AbstractArchivist<TParams, TEventData> {\n static override configSchemas = [IndexedDbArchivistConfigSchema]\n static defaultDbName = 'archivist'\n static defaultStoreName = 'payloads'\n\n private _db: UseStore | undefined\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the module name (not guaranteed to be unique) and if module\n * name is not supplied, 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?.name ?? IndexedDbArchivist.defaultDbName\n }\n\n override get queries() {\n return [ArchivistAllQuerySchema, ArchivistClearQuerySchema, ArchivistDeleteQuerySchema, ArchivistInsertQuerySchema, ...super.queries]\n }\n /**\n * The name of the object store. If not supplied via config, it defaults\n * to `payloads`. The limitation of the current IndexedDB wrapper we're\n * using is that it only supports a single object store per DB. See here:\n * https://github.com/jakearchibald/idb-keyval/blob/main/custom-stores.md#defining-a-custom-database--store-name\n * If this becomes a problem or we need migrations/transactions, we can\n * move to this more-flexible library, which they recommend (and who\n * recommends them for our simple use case of key-value storage):\n * https://www.npmjs.com/package/idb\n */\n get storeName() {\n return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName\n }\n\n private get db(): UseStore {\n return assertEx(this._db, 'DB not initialized')\n }\n\n protected override async allHandler(): Promise<Payload[]> {\n const result = await entries<string, Payload>(this.db)\n return result.map<Payload>(([_hash, payload]) => payload)\n }\n\n protected override async clearHandler(): Promise<void> {\n await clear(this.db)\n }\n\n protected override async deleteHandler(hashes: string[]): Promise<string[]> {\n const payloadPairs: [string, Payload][] = await Promise.all(\n (await this.get(hashes)).map<Promise<[string, Payload]>>(async (payload) => [await PayloadHasher.hashAsync(payload), payload]),\n )\n\n const foundHashesToDelete = payloadPairs.map(([hash, _]) => hash)\n await delMany(foundHashesToDelete, this.db)\n\n return foundHashesToDelete\n }\n\n protected override async getHandler(hashes: string[]): Promise<Payload[]> {\n return (await getMany<Payload>(hashes, this.db)).filter((result) => result !== undefined)\n }\n\n protected override async insertHandler(payloads: Payload[]): Promise<Payload[]> {\n const entries = await Promise.all(\n payloads.map<Promise<[string, Payload]>>(async (payload) => {\n const hash = await PayloadHasher.hashAsync(payload)\n return [hash, payload]\n }),\n )\n await setMany(entries, this.db)\n\n return payloads\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 = createStore(this.dbName, this.storeName)\n return true\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;ACAA,oBAAyB;AACzB,gCAAkC;AAClC,6BAQO;AACP,kBAA8B;AAC9B,oBAAiD;AAEjD,wBAAiF;;;;;;;;;;;;AAG1E,IAAMA,iCAAiE;;AAiB9E,IAAaC,sBAAN,mBAGGC,4CAAAA;EAKAC;;;;;;;;EASR,IAAIC,SAAS;;AACX,aAAOC,MAAA,KAAKC,WAAL,gBAAAD,IAAaD,aAAU,UAAKE,WAAL,mBAAaC,SAAQN,GAAmBO;EACxE;EAEA,IAAaC,UAAU;AACrB,WAAO;MAACC;MAAyBC;MAA2BC;MAA4BC;SAA+B,MAAMJ;;EAC/H;;;;;;;;;;;EAWA,IAAIK,YAAY;;AACd,aAAOT,MAAA,KAAKC,WAAL,gBAAAD,IAAaS,cAAab,GAAmBc;EACtD;EAEA,IAAYC,KAAe;AACzB,eAAOC,wBAAS,KAAKd,KAAK,oBAAA;EAC5B;EAEA,MAAyBe,aAAiC;AACxD,UAAMC,SAAS,UAAMC,2BAAyB,KAAKJ,EAAE;AACrD,WAAOG,OAAOE,IAAa,CAAC,CAACC,OAAOC,OAAAA,MAAaA,OAAAA;EACnD;EAEA,MAAyBC,eAA8B;AACrD,cAAMC,yBAAM,KAAKT,EAAE;EACrB;EAEA,MAAyBU,cAAcC,QAAqC;AAC1E,UAAMC,eAAoC,MAAMC,QAAQC,KACrD,MAAM,KAAKC,IAAIJ,MAAAA,GAASN,IAAgC,OAAOE,YAAY;MAAC,MAAMS,0BAAcC,UAAUV,OAAAA;MAAUA;KAAQ,CAAA;AAG/H,UAAMW,sBAAsBN,aAAaP,IAAI,CAAC,CAACc,MAAMC,CAAAA,MAAOD,IAAAA;AAC5D,cAAME,2BAAQH,qBAAqB,KAAKlB,EAAE;AAE1C,WAAOkB;EACT;EAEA,MAAyBI,WAAWX,QAAsC;AACxE,YAAQ,UAAMY,2BAAiBZ,QAAQ,KAAKX,EAAE,GAAGwB,OAAO,CAACrB,WAAWA,WAAWsB,MAAAA;EACjF;EAEA,MAAyBC,cAAcC,UAAyC;AAC9E,UAAMvB,WAAU,MAAMS,QAAQC,IAC5Ba,SAAStB,IAAgC,OAAOE,YAAAA;AAC9C,YAAMY,OAAO,MAAMH,0BAAcC,UAAUV,OAAAA;AAC3C,aAAO;QAACY;QAAMZ;;IAChB,CAAA,CAAA;AAEF,cAAMqB,2BAAQxB,UAAS,KAAKJ,EAAE;AAE9B,WAAO2B;EACT;EAEA,MAAyBE,eAAe;AACtC,UAAM,MAAMA,aAAAA;AAGZ,SAAK1C,UAAM2C,+BAAY,KAAK1C,QAAQ,KAAKU,SAAS;AAClD,WAAO;EACT;AACF,GAlFUZ,kCACR,cAJK,IAIW6C,iBAAgB;EAAC/C;IACjC,cALK,IAKEQ,iBAAgB,cACvB,cANK,IAMEO,oBAAmB,aANrB;AAAMd,qBAAAA,aAAAA;MADZ+C,+BAAAA;GACY/C,kBAAAA;","names":["IndexedDbArchivistConfigSchema","IndexedDbArchivist","AbstractArchivist","_db","dbName","_a","config","name","defaultDbName","queries","ArchivistAllQuerySchema","ArchivistClearQuerySchema","ArchivistDeleteQuerySchema","ArchivistInsertQuerySchema","storeName","defaultStoreName","db","assertEx","allHandler","result","entries","map","_hash","payload","clearHandler","clear","deleteHandler","hashes","payloadPairs","Promise","all","get","PayloadHasher","hashAsync","foundHashesToDelete","hash","_","delMany","getHandler","getMany","filter","undefined","insertHandler","payloads","setMany","startHandler","createStore","configSchemas","creatableModule"]}
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,2 +1,113 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __publicField = (obj, key, value) => {
|
|
5
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
return value;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/IndexedDbArchivist.ts
|
|
10
|
+
import { assertEx } from "@xylabs/assert";
|
|
11
|
+
import { AbstractArchivist } from "@xyo-network/archivist-abstract";
|
|
12
|
+
import { ArchivistAllQuerySchema, ArchivistClearQuerySchema, ArchivistDeleteQuerySchema, ArchivistInsertQuerySchema } from "@xyo-network/archivist-model";
|
|
13
|
+
import { PayloadHasher } from "@xyo-network/core";
|
|
14
|
+
import { creatableModule } from "@xyo-network/module";
|
|
15
|
+
import { clear, createStore, delMany, entries, getMany, setMany } from "idb-keyval";
|
|
16
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
17
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
18
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
19
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
+
else
|
|
21
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
22
|
+
if (d = decorators[i])
|
|
23
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
24
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
25
|
+
}
|
|
26
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
27
|
+
var IndexedDbArchivistConfigSchema = "network.xyo.archivist.indexeddb.config";
|
|
28
|
+
var _a;
|
|
29
|
+
var IndexedDbArchivist = (_a = class extends AbstractArchivist {
|
|
30
|
+
_db;
|
|
31
|
+
/**
|
|
32
|
+
* The database name. If not supplied via config, it defaults
|
|
33
|
+
* to the module name (not guaranteed to be unique) and if module
|
|
34
|
+
* name is not supplied, it defaults to `archivist`. This behavior
|
|
35
|
+
* biases towards a single, isolated DB per archivist which seems to
|
|
36
|
+
* make the most sense for 99% of use cases.
|
|
37
|
+
*/
|
|
38
|
+
get dbName() {
|
|
39
|
+
var _a2, _b;
|
|
40
|
+
return ((_a2 = this.config) == null ? void 0 : _a2.dbName) ?? ((_b = this.config) == null ? void 0 : _b.name) ?? _a.defaultDbName;
|
|
41
|
+
}
|
|
42
|
+
get queries() {
|
|
43
|
+
return [
|
|
44
|
+
ArchivistAllQuerySchema,
|
|
45
|
+
ArchivistClearQuerySchema,
|
|
46
|
+
ArchivistDeleteQuerySchema,
|
|
47
|
+
ArchivistInsertQuerySchema,
|
|
48
|
+
...super.queries
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The name of the object store. If not supplied via config, it defaults
|
|
53
|
+
* to `payloads`. The limitation of the current IndexedDB wrapper we're
|
|
54
|
+
* using is that it only supports a single object store per DB. See here:
|
|
55
|
+
* https://github.com/jakearchibald/idb-keyval/blob/main/custom-stores.md#defining-a-custom-database--store-name
|
|
56
|
+
* If this becomes a problem or we need migrations/transactions, we can
|
|
57
|
+
* move to this more-flexible library, which they recommend (and who
|
|
58
|
+
* recommends them for our simple use case of key-value storage):
|
|
59
|
+
* https://www.npmjs.com/package/idb
|
|
60
|
+
*/
|
|
61
|
+
get storeName() {
|
|
62
|
+
var _a2;
|
|
63
|
+
return ((_a2 = this.config) == null ? void 0 : _a2.storeName) ?? _a.defaultStoreName;
|
|
64
|
+
}
|
|
65
|
+
get db() {
|
|
66
|
+
return assertEx(this._db, "DB not initialized");
|
|
67
|
+
}
|
|
68
|
+
async allHandler() {
|
|
69
|
+
const result = await entries(this.db);
|
|
70
|
+
return result.map(([_hash, payload]) => payload);
|
|
71
|
+
}
|
|
72
|
+
async clearHandler() {
|
|
73
|
+
await clear(this.db);
|
|
74
|
+
}
|
|
75
|
+
async deleteHandler(hashes) {
|
|
76
|
+
const payloadPairs = await Promise.all((await this.get(hashes)).map(async (payload) => [
|
|
77
|
+
await PayloadHasher.hashAsync(payload),
|
|
78
|
+
payload
|
|
79
|
+
]));
|
|
80
|
+
const foundHashesToDelete = payloadPairs.map(([hash, _]) => hash);
|
|
81
|
+
await delMany(foundHashesToDelete, this.db);
|
|
82
|
+
return foundHashesToDelete;
|
|
83
|
+
}
|
|
84
|
+
async getHandler(hashes) {
|
|
85
|
+
return (await getMany(hashes, this.db)).filter((result) => result !== void 0);
|
|
86
|
+
}
|
|
87
|
+
async insertHandler(payloads) {
|
|
88
|
+
const entries2 = await Promise.all(payloads.map(async (payload) => {
|
|
89
|
+
const hash = await PayloadHasher.hashAsync(payload);
|
|
90
|
+
return [
|
|
91
|
+
hash,
|
|
92
|
+
payload
|
|
93
|
+
];
|
|
94
|
+
}));
|
|
95
|
+
await setMany(entries2, this.db);
|
|
96
|
+
return payloads;
|
|
97
|
+
}
|
|
98
|
+
async startHandler() {
|
|
99
|
+
await super.startHandler();
|
|
100
|
+
this._db = createStore(this.dbName, this.storeName);
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
}, __name(_a, "IndexedDbArchivist"), __publicField(_a, "configSchemas", [
|
|
104
|
+
IndexedDbArchivistConfigSchema
|
|
105
|
+
]), __publicField(_a, "defaultDbName", "archivist"), __publicField(_a, "defaultStoreName", "payloads"), _a);
|
|
106
|
+
IndexedDbArchivist = _ts_decorate([
|
|
107
|
+
creatableModule()
|
|
108
|
+
], IndexedDbArchivist);
|
|
109
|
+
export {
|
|
110
|
+
IndexedDbArchivist,
|
|
111
|
+
IndexedDbArchivistConfigSchema
|
|
112
|
+
};
|
|
2
113
|
//# sourceMappingURL=index.mjs.map
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/
|
|
1
|
+
{"version":3,"sources":["../../src/IndexedDbArchivist.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractArchivist } from '@xyo-network/archivist-abstract'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistConfig,\n ArchivistDeleteQuerySchema,\n ArchivistInsertQuerySchema,\n ArchivistModuleEventData,\n ArchivistParams,\n} from '@xyo-network/archivist-model'\nimport { PayloadHasher } from '@xyo-network/core'\nimport { AnyConfigSchema, creatableModule } from '@xyo-network/module'\nimport { Payload } from '@xyo-network/payload-model'\nimport { clear, createStore, delMany, entries, getMany, setMany, UseStore } from 'idb-keyval'\n\nexport type IndexedDbArchivistConfigSchema = 'network.xyo.archivist.indexeddb.config'\nexport const IndexedDbArchivistConfigSchema: IndexedDbArchivistConfigSchema = 'network.xyo.archivist.indexeddb.config'\n\nexport type IndexedDbArchivistConfig = ArchivistConfig<{\n /**\n * The database name\n */\n dbName?: string\n schema: IndexedDbArchivistConfigSchema\n /**\n * The name of the object store\n */\n storeName?: string\n}>\n\nexport type IndexedDbArchivistParams = ArchivistParams<AnyConfigSchema<IndexedDbArchivistConfig>>\n\n@creatableModule()\nexport class IndexedDbArchivist<\n TParams extends IndexedDbArchivistParams = IndexedDbArchivistParams,\n TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,\n> extends AbstractArchivist<TParams, TEventData> {\n static override configSchemas = [IndexedDbArchivistConfigSchema]\n static defaultDbName = 'archivist'\n static defaultStoreName = 'payloads'\n\n private _db: UseStore | undefined\n\n /**\n * The database name. If not supplied via config, it defaults\n * to the module name (not guaranteed to be unique) and if module\n * name is not supplied, 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?.name ?? IndexedDbArchivist.defaultDbName\n }\n\n override get queries() {\n return [ArchivistAllQuerySchema, ArchivistClearQuerySchema, ArchivistDeleteQuerySchema, ArchivistInsertQuerySchema, ...super.queries]\n }\n /**\n * The name of the object store. If not supplied via config, it defaults\n * to `payloads`. The limitation of the current IndexedDB wrapper we're\n * using is that it only supports a single object store per DB. See here:\n * https://github.com/jakearchibald/idb-keyval/blob/main/custom-stores.md#defining-a-custom-database--store-name\n * If this becomes a problem or we need migrations/transactions, we can\n * move to this more-flexible library, which they recommend (and who\n * recommends them for our simple use case of key-value storage):\n * https://www.npmjs.com/package/idb\n */\n get storeName() {\n return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName\n }\n\n private get db(): UseStore {\n return assertEx(this._db, 'DB not initialized')\n }\n\n protected override async allHandler(): Promise<Payload[]> {\n const result = await entries<string, Payload>(this.db)\n return result.map<Payload>(([_hash, payload]) => payload)\n }\n\n protected override async clearHandler(): Promise<void> {\n await clear(this.db)\n }\n\n protected override async deleteHandler(hashes: string[]): Promise<string[]> {\n const payloadPairs: [string, Payload][] = await Promise.all(\n (await this.get(hashes)).map<Promise<[string, Payload]>>(async (payload) => [await PayloadHasher.hashAsync(payload), payload]),\n )\n\n const foundHashesToDelete = payloadPairs.map(([hash, _]) => hash)\n await delMany(foundHashesToDelete, this.db)\n\n return foundHashesToDelete\n }\n\n protected override async getHandler(hashes: string[]): Promise<Payload[]> {\n return (await getMany<Payload>(hashes, this.db)).filter((result) => result !== undefined)\n }\n\n protected override async insertHandler(payloads: Payload[]): Promise<Payload[]> {\n const entries = await Promise.all(\n payloads.map<Promise<[string, Payload]>>(async (payload) => {\n const hash = await PayloadHasher.hashAsync(payload)\n return [hash, payload]\n }),\n )\n await setMany(entries, this.db)\n\n return payloads\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 = createStore(this.dbName, this.storeName)\n return true\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,yBAAyB;AAClC,SACEC,yBACAC,2BAEAC,4BACAC,kCAGK;AACP,SAASC,qBAAqB;AAC9B,SAA0BC,uBAAuB;AAEjD,SAASC,OAAOC,aAAaC,SAASC,SAASC,SAASC,eAAyB;;;;;;;;;;;;AAG1E,IAAMC,iCAAiE;;AAiB9E,IAAaC,sBAAN,mBAGGC,kBAAAA;EAKAC;;;;;;;;EASR,IAAIC,SAAS;;AACX,aAAOC,MAAA,KAAKC,WAAL,gBAAAD,IAAaD,aAAU,UAAKE,WAAL,mBAAaC,SAAQN,GAAmBO;EACxE;EAEA,IAAaC,UAAU;AACrB,WAAO;MAACC;MAAyBC;MAA2BC;MAA4BC;SAA+B,MAAMJ;;EAC/H;;;;;;;;;;;EAWA,IAAIK,YAAY;;AACd,aAAOT,MAAA,KAAKC,WAAL,gBAAAD,IAAaS,cAAab,GAAmBc;EACtD;EAEA,IAAYC,KAAe;AACzB,WAAOC,SAAS,KAAKd,KAAK,oBAAA;EAC5B;EAEA,MAAyBe,aAAiC;AACxD,UAAMC,SAAS,MAAMC,QAAyB,KAAKJ,EAAE;AACrD,WAAOG,OAAOE,IAAa,CAAC,CAACC,OAAOC,OAAAA,MAAaA,OAAAA;EACnD;EAEA,MAAyBC,eAA8B;AACrD,UAAMC,MAAM,KAAKT,EAAE;EACrB;EAEA,MAAyBU,cAAcC,QAAqC;AAC1E,UAAMC,eAAoC,MAAMC,QAAQC,KACrD,MAAM,KAAKC,IAAIJ,MAAAA,GAASN,IAAgC,OAAOE,YAAY;MAAC,MAAMS,cAAcC,UAAUV,OAAAA;MAAUA;KAAQ,CAAA;AAG/H,UAAMW,sBAAsBN,aAAaP,IAAI,CAAC,CAACc,MAAMC,CAAAA,MAAOD,IAAAA;AAC5D,UAAME,QAAQH,qBAAqB,KAAKlB,EAAE;AAE1C,WAAOkB;EACT;EAEA,MAAyBI,WAAWX,QAAsC;AACxE,YAAQ,MAAMY,QAAiBZ,QAAQ,KAAKX,EAAE,GAAGwB,OAAO,CAACrB,WAAWA,WAAWsB,MAAAA;EACjF;EAEA,MAAyBC,cAAcC,UAAyC;AAC9E,UAAMvB,WAAU,MAAMS,QAAQC,IAC5Ba,SAAStB,IAAgC,OAAOE,YAAAA;AAC9C,YAAMY,OAAO,MAAMH,cAAcC,UAAUV,OAAAA;AAC3C,aAAO;QAACY;QAAMZ;;IAChB,CAAA,CAAA;AAEF,UAAMqB,QAAQxB,UAAS,KAAKJ,EAAE;AAE9B,WAAO2B;EACT;EAEA,MAAyBE,eAAe;AACtC,UAAM,MAAMA,aAAAA;AAGZ,SAAK1C,MAAM2C,YAAY,KAAK1C,QAAQ,KAAKU,SAAS;AAClD,WAAO;EACT;AACF,GAlFUZ,kCACR,cAJK,IAIW6C,iBAAgB;EAAC/C;IACjC,cALK,IAKEQ,iBAAgB,cACvB,cANK,IAMEO,oBAAmB,aANrB;AAAMd,qBAAAA,aAAAA;EADZ+C,gBAAAA;GACY/C,kBAAAA;","names":["assertEx","AbstractArchivist","ArchivistAllQuerySchema","ArchivistClearQuerySchema","ArchivistDeleteQuerySchema","ArchivistInsertQuerySchema","PayloadHasher","creatableModule","clear","createStore","delMany","entries","getMany","setMany","IndexedDbArchivistConfigSchema","IndexedDbArchivist","AbstractArchivist","_db","dbName","_a","config","name","defaultDbName","queries","ArchivistAllQuerySchema","ArchivistClearQuerySchema","ArchivistDeleteQuerySchema","ArchivistInsertQuerySchema","storeName","defaultStoreName","db","assertEx","allHandler","result","entries","map","_hash","payload","clearHandler","clear","deleteHandler","hashes","payloadPairs","Promise","all","get","PayloadHasher","hashAsync","foundHashesToDelete","hash","_","delMany","getHandler","getMany","filter","undefined","insertHandler","payloads","setMany","startHandler","createStore","configSchemas","creatableModule"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/sample.archivist.xyo.json
|
|
2
|
+
var payloads = [
|
|
3
|
+
{
|
|
4
|
+
schema: "network.xyo.test.1"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
schema: "network.xyo.test.2"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
schema: "network.xyo.test.3"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
schema: "network.xyo.test.4"
|
|
14
|
+
}
|
|
15
|
+
];
|
|
16
|
+
var sample_archivist_xyo_default = {
|
|
17
|
+
payloads
|
|
18
|
+
};
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
payloads
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=sample.archivist.xyo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/sample.archivist.xyo.json"],"sourcesContent":["{\n \"payloads\": [\n {\n \"schema\": \"network.xyo.test.1\"\n },\n {\n \"schema\": \"network.xyo.test.2\"\n },\n {\n \"schema\": \"network.xyo.test.3\"\n },\n {\n \"schema\": \"network.xyo.test.4\"\n }\n ]\n}"],"mappings":";AACE,eAAY;AAAA,EACV;AAAA,IACE,QAAU;AAAA,EACZ;AAAA,EACA;AAAA,IACE,QAAU;AAAA,EACZ;AAAA,EACA;AAAA,IACE,QAAU;AAAA,EACZ;AAAA,EACA;AAAA,IACE,QAAU;AAAA,EACZ;AACF;AAdF;AAAA,EACE;AAcF;","names":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/sample.archivist.xyo.json
|
|
2
|
+
var payloads = [
|
|
3
|
+
{
|
|
4
|
+
schema: "network.xyo.test.1"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
schema: "network.xyo.test.2"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
schema: "network.xyo.test.3"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
schema: "network.xyo.test.4"
|
|
14
|
+
}
|
|
15
|
+
];
|
|
16
|
+
var sample_archivist_xyo_default = {
|
|
17
|
+
payloads
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
sample_archivist_xyo_default as default,
|
|
21
|
+
payloads
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=sample.archivist.xyo.mjs.map
|