@xyo-network/archivist-indexeddb 2.60.3 → 2.60.5
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/cjs/IndexedDbArchivist.js +51 -13
- package/dist/cjs/IndexedDbArchivist.js.map +1 -1
- package/dist/docs.json +1971 -1802
- package/dist/esm/IndexedDbArchivist.js +46 -9
- package/dist/esm/IndexedDbArchivist.js.map +1 -1
- package/dist/types/IndexedDbArchivist.d.ts +35 -9
- package/dist/types/IndexedDbArchivist.d.ts.map +1 -1
- package/package.json +14 -13
- package/src/IndexedDbArchivist.ts +57 -17
|
@@ -1,59 +1,97 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var IndexedDbArchivist_1;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.IndexedDbArchivist = exports.IndexedDbArchivistConfigSchema = void 0;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
6
|
+
const assert_1 = require("@xylabs/assert");
|
|
5
7
|
const abstract_archivist_1 = require("@xyo-network/abstract-archivist");
|
|
6
8
|
const archivist_model_1 = require("@xyo-network/archivist-model");
|
|
7
9
|
const core_1 = require("@xyo-network/core");
|
|
8
10
|
const module_1 = require("@xyo-network/module");
|
|
9
11
|
const idb_keyval_1 = require("idb-keyval");
|
|
10
|
-
exports.IndexedDbArchivistConfigSchema = 'network.xyo.module.config.archivist.
|
|
11
|
-
let IndexedDbArchivist = class IndexedDbArchivist extends abstract_archivist_1.AbstractArchivist {
|
|
12
|
+
exports.IndexedDbArchivistConfigSchema = 'network.xyo.module.config.archivist.indexeddb';
|
|
13
|
+
let IndexedDbArchivist = IndexedDbArchivist_1 = class IndexedDbArchivist extends abstract_archivist_1.AbstractArchivist {
|
|
14
|
+
/**
|
|
15
|
+
* The database name. If not supplied via config, it defaults
|
|
16
|
+
* to the module name (not guaranteed to be unique) and if module
|
|
17
|
+
* name is not supplied, it defaults to `archivist`. This behavior
|
|
18
|
+
* biases towards a single, isolated DB per archivist which seems to
|
|
19
|
+
* make the most sense for 99% of use cases.
|
|
20
|
+
*/
|
|
21
|
+
get dbName() {
|
|
22
|
+
var _a, _b, _c, _d;
|
|
23
|
+
return (_d = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.dbName) !== null && _b !== void 0 ? _b : (_c = this.config) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : IndexedDbArchivist_1.defaultDbName;
|
|
24
|
+
}
|
|
12
25
|
get queries() {
|
|
13
26
|
return [archivist_model_1.ArchivistAllQuerySchema, archivist_model_1.ArchivistClearQuerySchema, archivist_model_1.ArchivistDeleteQuerySchema, archivist_model_1.ArchivistInsertQuerySchema, ...super.queries];
|
|
14
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* The name of the object store. If not supplied via config, it defaults
|
|
30
|
+
* to `payloads`. The limitation of the current IndexedDB wrapper we're
|
|
31
|
+
* using is that it only supports a single object store per DB. See here:
|
|
32
|
+
* https://github.com/jakearchibald/idb-keyval/blob/main/custom-stores.md#defining-a-custom-database--store-name
|
|
33
|
+
* If this becomes a problem or we need migrations/transactions, we can
|
|
34
|
+
* move to this more-flexible library, which they recommend (and who
|
|
35
|
+
* recommends them for our simple use case of key-value storage):
|
|
36
|
+
* https://www.npmjs.com/package/idb
|
|
37
|
+
*/
|
|
38
|
+
get storeName() {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
return (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.storeName) !== null && _b !== void 0 ? _b : IndexedDbArchivist_1.defaultStoreName;
|
|
41
|
+
}
|
|
42
|
+
get db() {
|
|
43
|
+
return (0, assert_1.assertEx)(this._db, 'DB not initialized');
|
|
44
|
+
}
|
|
15
45
|
all() {
|
|
16
|
-
var _a;
|
|
17
46
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
const result = yield (0, idb_keyval_1.entries)(
|
|
47
|
+
const result = yield (0, idb_keyval_1.entries)(this.db);
|
|
19
48
|
return result.map(([_hash, payload]) => payload);
|
|
20
49
|
});
|
|
21
50
|
}
|
|
22
51
|
clear() {
|
|
23
|
-
var _a;
|
|
24
52
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
yield (0, idb_keyval_1.clear)(
|
|
53
|
+
yield (0, idb_keyval_1.clear)(this.db);
|
|
26
54
|
});
|
|
27
55
|
}
|
|
28
56
|
delete(hashes) {
|
|
29
|
-
var _a;
|
|
30
57
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
yield (0, idb_keyval_1.delMany)(hashes,
|
|
58
|
+
yield (0, idb_keyval_1.delMany)(hashes, this.db);
|
|
32
59
|
return hashes.map((_) => true);
|
|
33
60
|
});
|
|
34
61
|
}
|
|
35
62
|
get(hashes) {
|
|
36
|
-
var _a;
|
|
37
63
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const result = yield (0, idb_keyval_1.getMany)(hashes,
|
|
64
|
+
const result = yield (0, idb_keyval_1.getMany)(hashes, this.db);
|
|
39
65
|
return result;
|
|
40
66
|
});
|
|
41
67
|
}
|
|
42
68
|
insert(payloads) {
|
|
43
|
-
var _a;
|
|
44
69
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
45
70
|
const entries = yield Promise.all(payloads.map((payload) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
46
71
|
const hash = yield core_1.PayloadHasher.hashAsync(payload);
|
|
47
72
|
return [hash, payload];
|
|
48
73
|
})));
|
|
49
|
-
yield (0, idb_keyval_1.setMany)(entries,
|
|
74
|
+
yield (0, idb_keyval_1.setMany)(entries, this.db);
|
|
50
75
|
const result = yield this.bindQueryResult({ payloads, schema: archivist_model_1.ArchivistInsertQuerySchema }, payloads);
|
|
51
76
|
return [result[0]];
|
|
52
77
|
});
|
|
53
78
|
}
|
|
79
|
+
start() {
|
|
80
|
+
const _super = Object.create(null, {
|
|
81
|
+
start: { get: () => super.start }
|
|
82
|
+
});
|
|
83
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
yield _super.start.call(this);
|
|
85
|
+
// NOTE: We could defer this creation to first access but we
|
|
86
|
+
// want to fail fast here in case something is wrong
|
|
87
|
+
this._db = (0, idb_keyval_1.createStore)(this.dbName, this.storeName);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
54
90
|
};
|
|
55
91
|
IndexedDbArchivist.configSchema = exports.IndexedDbArchivistConfigSchema;
|
|
56
|
-
IndexedDbArchivist =
|
|
92
|
+
IndexedDbArchivist.defaultDbName = 'archivist';
|
|
93
|
+
IndexedDbArchivist.defaultStoreName = 'payloads';
|
|
94
|
+
IndexedDbArchivist = IndexedDbArchivist_1 = tslib_1.__decorate([
|
|
57
95
|
(0, module_1.creatableModule)()
|
|
58
96
|
], IndexedDbArchivist);
|
|
59
97
|
exports.IndexedDbArchivist = IndexedDbArchivist;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IndexedDbArchivist.js","sourceRoot":"","sources":["../../src/IndexedDbArchivist.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IndexedDbArchivist.js","sourceRoot":"","sources":["../../src/IndexedDbArchivist.ts"],"names":[],"mappings":";;;;;AAAA,2CAAyC;AACzC,wEAAmE;AACnE,kEAQqC;AAErC,4CAAiD;AACjD,gDAAsE;AAEtE,2CAA6F;AAGhF,QAAA,8BAA8B,GAAmC,+CAA+C,CAAA;AAiBtH,IAAM,kBAAkB,0BAAxB,MAAM,kBAGX,SAAQ,sCAAsC;IAO9C;;;;;;OAMG;IACH,IAAI,MAAM;;QACR,OAAO,MAAA,MAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,MAAM,mCAAI,MAAA,IAAI,CAAC,MAAM,0CAAE,IAAI,mCAAI,oBAAkB,CAAC,aAAa,CAAA;IACrF,CAAC;IAED,IAAa,OAAO;QAClB,OAAO,CAAC,yCAAuB,EAAE,2CAAyB,EAAE,4C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