@xylabs/indexed-db 4.4.33 → 4.4.34
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/IndexDescription.d.ts +30 -0
- package/dist/browser/IndexDescription.d.ts.map +1 -0
- package/dist/browser/IndexedDbKeyValueStore.d.ts +17 -0
- package/dist/browser/IndexedDbKeyValueStore.d.ts.map +1 -0
- package/dist/browser/ObjectStore.d.ts +5 -0
- package/dist/browser/ObjectStore.d.ts.map +1 -0
- package/dist/browser/checkDbNeedsUpgrade.d.ts +7 -0
- package/dist/browser/checkDbNeedsUpgrade.d.ts.map +1 -0
- package/dist/browser/createStoreDuringUpgrade.d.ts +5 -0
- package/dist/browser/createStoreDuringUpgrade.d.ts.map +1 -0
- package/dist/{neutral/createStore.d.ts → browser/getExistingIndexes.d.ts} +2 -2
- package/dist/browser/getExistingIndexes.d.ts.map +1 -0
- package/dist/browser/index.d.ts +11 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.mjs +233 -0
- package/dist/browser/index.mjs.map +1 -0
- package/dist/browser/withDb.d.ts +6 -0
- package/dist/browser/withDb.d.ts.map +1 -0
- package/dist/browser/withReadOnlyStore.d.ts +6 -0
- package/dist/browser/withReadOnlyStore.d.ts.map +1 -0
- package/dist/browser/withReadWriteStore.d.ts +6 -0
- package/dist/browser/withReadWriteStore.d.ts.map +1 -0
- package/dist/browser/withStore.d.ts +8 -0
- package/dist/browser/withStore.d.ts.map +1 -0
- package/dist/neutral/IndexDescription.d.ts +0 -4
- package/dist/neutral/IndexDescription.d.ts.map +1 -1
- package/dist/neutral/IndexedDbKeyValueStore.d.ts +3 -3
- package/dist/neutral/IndexedDbKeyValueStore.d.ts.map +1 -1
- package/dist/neutral/checkDbNeedsUpgrade.d.ts +7 -0
- package/dist/neutral/checkDbNeedsUpgrade.d.ts.map +1 -0
- package/dist/neutral/createStoreDuringUpgrade.d.ts +5 -0
- package/dist/neutral/createStoreDuringUpgrade.d.ts.map +1 -0
- package/dist/neutral/getExistingIndexes.d.ts +2 -1
- package/dist/neutral/getExistingIndexes.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +3 -1
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +131 -33
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/withDb.d.ts +3 -1
- package/dist/neutral/withDb.d.ts.map +1 -1
- package/dist/neutral/withReadOnlyStore.d.ts +2 -1
- package/dist/neutral/withReadOnlyStore.d.ts.map +1 -1
- package/dist/neutral/withReadWriteStore.d.ts +2 -1
- package/dist/neutral/withReadWriteStore.d.ts.map +1 -1
- package/dist/neutral/withStore.d.ts +8 -0
- package/dist/neutral/withStore.d.ts.map +1 -0
- package/dist/node/IndexDescription.d.ts +30 -0
- package/dist/node/IndexDescription.d.ts.map +1 -0
- package/dist/node/IndexedDbKeyValueStore.d.ts +17 -0
- package/dist/node/IndexedDbKeyValueStore.d.ts.map +1 -0
- package/dist/node/ObjectStore.d.ts +5 -0
- package/dist/node/ObjectStore.d.ts.map +1 -0
- package/dist/node/checkDbNeedsUpgrade.d.ts +7 -0
- package/dist/node/checkDbNeedsUpgrade.d.ts.map +1 -0
- package/dist/node/createStoreDuringUpgrade.d.ts +5 -0
- package/dist/node/createStoreDuringUpgrade.d.ts.map +1 -0
- package/dist/node/getExistingIndexes.d.ts +7 -0
- package/dist/node/getExistingIndexes.d.ts.map +1 -0
- package/dist/node/index.d.ts +11 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.mjs +233 -0
- package/dist/node/index.mjs.map +1 -0
- package/dist/node/withDb.d.ts +6 -0
- package/dist/node/withDb.d.ts.map +1 -0
- package/dist/node/withReadOnlyStore.d.ts +6 -0
- package/dist/node/withReadOnlyStore.d.ts.map +1 -0
- package/dist/node/withReadWriteStore.d.ts +6 -0
- package/dist/node/withReadWriteStore.d.ts.map +1 -0
- package/dist/node/withStore.d.ts +8 -0
- package/dist/node/withStore.d.ts.map +1 -0
- package/package.json +23 -9
- package/src/IndexDescription.ts +0 -4
- package/src/IndexedDbKeyValueStore.ts +3 -3
- package/src/checkDbNeedsUpgrade.ts +37 -0
- package/src/{createStore.ts → createStoreDuringUpgrade.ts} +17 -10
- package/src/getExistingIndexes.ts +39 -20
- package/src/index.ts +3 -1
- package/src/withDb.ts +48 -2
- package/src/withReadOnlyStore.ts +5 -8
- package/src/withReadWriteStore.ts +5 -8
- package/src/withStore.ts +34 -0
- package/xy.config.ts +2 -2
- package/dist/neutral/createStore.d.ts.map +0 -1
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
// src/checkDbNeedsUpgrade.ts
|
|
2
|
+
import { exists } from "@xylabs/exists";
|
|
3
|
+
|
|
4
|
+
// src/withDb.ts
|
|
5
|
+
import { openDB } from "idb";
|
|
6
|
+
|
|
1
7
|
// src/IndexDescription.ts
|
|
2
8
|
var IndexSeparator = "-";
|
|
3
9
|
var buildStandardIndexName = (index) => {
|
|
@@ -7,19 +13,27 @@ var buildStandardIndexName = (index) => {
|
|
|
7
13
|
return `${prefix}_${indexKeys.join(IndexSeparator)}`;
|
|
8
14
|
};
|
|
9
15
|
|
|
10
|
-
// src/
|
|
11
|
-
function
|
|
16
|
+
// src/createStoreDuringUpgrade.ts
|
|
17
|
+
function createStoreDuringUpgrade(db, storeName, indexes, logger) {
|
|
12
18
|
logger?.log(`Creating store ${storeName}`);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
let store;
|
|
20
|
+
try {
|
|
21
|
+
store = db.createObjectStore(storeName, {
|
|
22
|
+
// If it isn't explicitly set, create a value by auto incrementing.
|
|
23
|
+
autoIncrement: true
|
|
24
|
+
});
|
|
25
|
+
} catch {
|
|
26
|
+
logger?.warn(`Failed to create store: ${storeName} already exists`);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
logger?.log(`Creating store: created ${storeName}`);
|
|
17
30
|
store.name = storeName;
|
|
18
31
|
for (const {
|
|
19
32
|
key,
|
|
20
33
|
multiEntry,
|
|
21
34
|
unique
|
|
22
35
|
} of indexes) {
|
|
36
|
+
logger?.log(`Creating store: index ${key}`);
|
|
23
37
|
const indexKeys = Object.keys(key);
|
|
24
38
|
const keys = indexKeys.length === 1 ? indexKeys[0] : indexKeys;
|
|
25
39
|
const indexName = buildStandardIndexName({ key, unique });
|
|
@@ -28,21 +42,83 @@ function createStore(db, storeName, indexes, logger) {
|
|
|
28
42
|
}
|
|
29
43
|
}
|
|
30
44
|
|
|
31
|
-
// src/
|
|
32
|
-
async function
|
|
33
|
-
const
|
|
34
|
-
const
|
|
45
|
+
// src/withDb.ts
|
|
46
|
+
async function withDb(dbName, callback, expectedIndexes, logger) {
|
|
47
|
+
const versionToOpen = expectedIndexes === void 0 ? void 0 : await checkDbNeedsUpgrade(dbName, expectedIndexes, logger);
|
|
48
|
+
const db = await openDB(dbName, versionToOpen, {
|
|
49
|
+
blocked(currentVersion, blockedVersion, event) {
|
|
50
|
+
logger?.warn(`IndexedDb: Blocked from upgrading from ${currentVersion} to ${blockedVersion}`, event);
|
|
51
|
+
},
|
|
52
|
+
blocking(currentVersion, blockedVersion, event) {
|
|
53
|
+
logger?.warn(`IndexedDb: Blocking upgrade from ${currentVersion} to ${blockedVersion}`, event);
|
|
54
|
+
},
|
|
55
|
+
terminated() {
|
|
56
|
+
logger?.log("IndexedDb: Terminated");
|
|
57
|
+
},
|
|
58
|
+
upgrade(db2, oldVersion, newVersion, transaction) {
|
|
59
|
+
if (oldVersion !== newVersion) {
|
|
60
|
+
logger?.log(`IndexedDb: Upgrading from ${oldVersion} to ${newVersion}`);
|
|
61
|
+
const objectStores = transaction.objectStoreNames;
|
|
62
|
+
for (const name of objectStores) {
|
|
63
|
+
try {
|
|
64
|
+
db2.deleteObjectStore(name);
|
|
65
|
+
} catch {
|
|
66
|
+
console.log(`IndexedDb: Failed to delete existing object store ${name}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (expectedIndexes) {
|
|
71
|
+
for (const [storeName, indexes] of Object.entries(expectedIndexes)) {
|
|
72
|
+
if (db2.objectStoreNames.contains(storeName)) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const indexesToCreate = indexes.map((idx) => ({
|
|
76
|
+
...idx,
|
|
77
|
+
name: buildStandardIndexName(idx)
|
|
78
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
79
|
+
})).reduce((acc, idx) => acc.set(idx.name, idx), /* @__PURE__ */ new Map()).values();
|
|
80
|
+
createStoreDuringUpgrade(db2, storeName, [...indexesToCreate], logger);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
try {
|
|
86
|
+
return await callback(db);
|
|
87
|
+
} finally {
|
|
88
|
+
db.close();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/withStore.ts
|
|
93
|
+
async function withStore(db, storeName, callback, mode, logger) {
|
|
94
|
+
logger?.log("withStore", storeName, mode);
|
|
95
|
+
let transaction = void 0;
|
|
96
|
+
logger?.log("withStore:transaction");
|
|
97
|
+
let store = null;
|
|
98
|
+
try {
|
|
99
|
+
transaction = db.transaction(storeName, mode);
|
|
100
|
+
store = transaction.objectStore(storeName);
|
|
101
|
+
} catch (ex) {
|
|
102
|
+
logger?.log("withStore:catch", ex);
|
|
103
|
+
}
|
|
35
104
|
try {
|
|
36
105
|
return await callback(store);
|
|
37
106
|
} finally {
|
|
38
|
-
|
|
107
|
+
logger?.log("withStore:finally");
|
|
108
|
+
await transaction?.done;
|
|
39
109
|
}
|
|
40
110
|
}
|
|
41
111
|
|
|
112
|
+
// src/withReadOnlyStore.ts
|
|
113
|
+
async function withReadOnlyStore(db, storeName, callback, logger) {
|
|
114
|
+
return await withStore(db, storeName, callback, "readonly", logger);
|
|
115
|
+
}
|
|
116
|
+
|
|
42
117
|
// src/getExistingIndexes.ts
|
|
43
|
-
async function
|
|
118
|
+
async function getExistingIndexesInternal(db, storeName, logger) {
|
|
119
|
+
logger?.log("getExistingIndexesInternal", storeName);
|
|
44
120
|
return await withReadOnlyStore(db, storeName, (store) => {
|
|
45
|
-
return [...store.indexNames].map((indexName) => {
|
|
121
|
+
return store ? [...store.indexNames].map((indexName) => {
|
|
46
122
|
const index = store.index(indexName);
|
|
47
123
|
const key = {};
|
|
48
124
|
if (Array.isArray(index.keyPath)) {
|
|
@@ -53,25 +129,50 @@ async function getExistingIndexes(db, storeName) {
|
|
|
53
129
|
key[index.keyPath] = 1;
|
|
54
130
|
}
|
|
55
131
|
const desc = {
|
|
56
|
-
name: indexName,
|
|
57
132
|
key,
|
|
58
133
|
unique: index.unique,
|
|
59
134
|
multiEntry: index.multiEntry
|
|
60
135
|
};
|
|
61
136
|
return desc;
|
|
137
|
+
}) : null;
|
|
138
|
+
}, logger);
|
|
139
|
+
}
|
|
140
|
+
async function getExistingIndexes(db, storeName, logger) {
|
|
141
|
+
logger?.log("getExistingIndexes", storeName);
|
|
142
|
+
if (typeof db === "string") {
|
|
143
|
+
return await withDb(db, async (db2) => {
|
|
144
|
+
return await getExistingIndexesInternal(db2, storeName, logger);
|
|
62
145
|
});
|
|
63
|
-
}
|
|
146
|
+
}
|
|
147
|
+
return await getExistingIndexesInternal(db, storeName, logger);
|
|
64
148
|
}
|
|
65
149
|
|
|
66
|
-
// src/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
|
|
150
|
+
// src/checkDbNeedsUpgrade.ts
|
|
151
|
+
async function checkStoreNeedsUpgrade(db, storeName, indexes, logger) {
|
|
152
|
+
logger?.log("checkStoreNeedsUpgrade", storeName, indexes);
|
|
153
|
+
const existingIndexes = await getExistingIndexes(db, storeName, logger);
|
|
154
|
+
if (existingIndexes === null) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
const existingIndexNames = new Set(existingIndexes.map(({ key, unique }) => buildStandardIndexName({ key, unique })).filter(exists));
|
|
158
|
+
for (const { key, unique } of indexes) {
|
|
159
|
+
const indexName = buildStandardIndexName({ key, unique });
|
|
160
|
+
if (!existingIndexNames.has(indexName)) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
74
163
|
}
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
async function checkDbNeedsUpgrade(dbName, stores, logger) {
|
|
167
|
+
logger?.log("checkDbNeedsUpgrade", dbName, stores);
|
|
168
|
+
return await withDb(dbName, async (db) => {
|
|
169
|
+
for (const [storeName, indexes] of Object.entries(stores)) {
|
|
170
|
+
if (await checkStoreNeedsUpgrade(db, storeName, indexes, logger)) {
|
|
171
|
+
return db.version + 1;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return db.version;
|
|
175
|
+
});
|
|
75
176
|
}
|
|
76
177
|
|
|
77
178
|
// src/IndexedDbKeyValueStore.ts
|
|
@@ -113,23 +214,20 @@ var IndexedDbKeyValueStore = class {
|
|
|
113
214
|
};
|
|
114
215
|
|
|
115
216
|
// src/withReadWriteStore.ts
|
|
116
|
-
async function withReadWriteStore(db, storeName, callback) {
|
|
117
|
-
|
|
118
|
-
const store = transaction.objectStore(storeName);
|
|
119
|
-
try {
|
|
120
|
-
return await callback(store);
|
|
121
|
-
} finally {
|
|
122
|
-
await transaction.done;
|
|
123
|
-
}
|
|
217
|
+
async function withReadWriteStore(db, storeName, callback, logger) {
|
|
218
|
+
return await withStore(db, storeName, callback, "readwrite", logger);
|
|
124
219
|
}
|
|
125
220
|
export {
|
|
126
221
|
IndexSeparator,
|
|
127
222
|
IndexedDbKeyValueStore,
|
|
128
223
|
buildStandardIndexName,
|
|
129
|
-
|
|
224
|
+
checkDbNeedsUpgrade,
|
|
225
|
+
checkStoreNeedsUpgrade,
|
|
226
|
+
createStoreDuringUpgrade,
|
|
130
227
|
getExistingIndexes,
|
|
131
228
|
withDb,
|
|
132
229
|
withReadOnlyStore,
|
|
133
|
-
withReadWriteStore
|
|
230
|
+
withReadWriteStore,
|
|
231
|
+
withStore
|
|
134
232
|
};
|
|
135
233
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/IndexDescription.ts","../../src/createStore.ts","../../src/withReadOnlyStore.ts","../../src/getExistingIndexes.ts","../../src/withDb.ts","../../src/IndexedDbKeyValueStore.ts","../../src/withReadWriteStore.ts"],"sourcesContent":["/**\n * The index direction (1 for ascending, -1 for descending)\n */\nexport type IndexDirection = -1 | 1\n\n/**\n * Description of index(es) to be created on a store\n */\nexport type IndexDescription = {\n /**\n * The key(s) to index\n */\n key: Record<string, IndexDirection>\n /**\n * Is the indexed value an array\n */\n multiEntry?: boolean\n /**\n * The name of the index\n */\n name?: string\n /**\n * If true, the index must enforce uniqueness on the key\n */\n unique?: boolean\n}\n\nexport const IndexSeparator = '-'\n\n/**\n * Given an index description, this will build the index\n * name in standard form\n * @param index The index description\n * @returns The index name in standard form\n */\nexport const buildStandardIndexName = (index: IndexDescription) => {\n const { key, unique } = index\n const prefix = unique ? 'UX' : 'IX'\n const indexKeys = Object.keys(key)\n return `${prefix}_${indexKeys.join(IndexSeparator)}`\n}\n","import type { Logger } from '@xylabs/logger'\nimport type { EmptyObject } from '@xylabs/object'\nimport type {\n IDBPDatabase, IndexNames, StoreNames,\n} from 'idb'\n\nimport {\n buildStandardIndexName,\n type IndexDescription,\n} from './IndexDescription.ts'\nimport type { ObjectStore } from './ObjectStore.ts'\n\nexport function createStore<T extends EmptyObject = EmptyObject>(\n db: IDBPDatabase<ObjectStore<T>>,\n storeName: StoreNames<ObjectStore<T>>,\n indexes: IndexDescription[],\n logger?: Logger,\n) {\n logger?.log(`Creating store ${storeName}`)\n // Create the store\n const store = db.createObjectStore(storeName, {\n // If it isn't explicitly set, create a value by auto incrementing.\n autoIncrement: true,\n })\n // Name the store\n store.name = storeName\n // Create an index on the hash\n for (const {\n key, multiEntry, unique,\n } of indexes) {\n const indexKeys = Object.keys(key)\n const keys = indexKeys.length === 1 ? indexKeys[0] : indexKeys\n const indexName = buildStandardIndexName({ key, unique }) as IndexNames<ObjectStore<T>, StoreNames<ObjectStore<T>>>\n console.log('createIndex', indexName, keys, { multiEntry, unique })\n store.createIndex(indexName, keys, { multiEntry, unique })\n }\n}\n","import type { EmptyObject } from '@xylabs/object'\nimport type {\n IDBPDatabase, IDBPObjectStore, StoreNames,\n} from 'idb'\n\nimport type { ObjectStore } from './ObjectStore.ts'\n\nexport async function withReadOnlyStore<T extends EmptyObject = EmptyObject, R = T>(\n db: IDBPDatabase<ObjectStore<T>>,\n storeName: StoreNames<ObjectStore<T>>,\n callback: (store: IDBPObjectStore<ObjectStore<T>, [StoreNames<ObjectStore<T>>], StoreNames<ObjectStore<T>>, string>) => Promise<R> | R,\n): Promise<R> {\n const transaction = db.transaction(storeName, 'readonly')\n const store = transaction.objectStore(storeName)\n try {\n return await callback(store)\n } finally {\n await transaction.done\n }\n}\n","import type { EmptyObject } from '@xylabs/object'\nimport type { IDBPDatabase, StoreNames } from 'idb'\n\nimport {\n type IndexDescription,\n type IndexDirection,\n} from './IndexDescription.ts'\nimport type { ObjectStore } from './ObjectStore.ts'\nimport { withReadOnlyStore } from './withReadOnlyStore.ts'\n\nexport async function getExistingIndexes<T extends EmptyObject = EmptyObject>(\n db: IDBPDatabase<ObjectStore<T>>,\n storeName: StoreNames<ObjectStore<T>>,\n): Promise<IndexDescription[]> {\n return await withReadOnlyStore(db, storeName, (store) => {\n return [...store.indexNames].map((indexName) => {\n const index = store.index(indexName)\n const key: Record<string, IndexDirection> = {}\n if (Array.isArray(index.keyPath)) {\n for (const keyPath of index.keyPath) {\n key[keyPath] = 1\n }\n } else {\n key[index.keyPath] = 1\n }\n const desc: IndexDescription = {\n name: indexName as string,\n key,\n unique: index.unique,\n multiEntry: index.multiEntry,\n }\n return desc\n })\n })\n}\n","import type { EmptyObject } from '@xylabs/object'\nimport type { DBSchema, IDBPDatabase } from 'idb'\nimport { openDB } from 'idb'\n\nexport async function withDb<DBTypes extends DBSchema | unknown = unknown, R = EmptyObject>(\n dbName: string,\n callback: (db: IDBPDatabase<DBTypes>) => Promise<R> | R,\n): Promise<R> {\n const db = await openDB<DBTypes>(dbName)\n try {\n return await callback(db)\n } finally {\n db.close()\n }\n}\n","import type { KeyValueStore } from '@xylabs/storage'\nimport type {\n DBSchema,\n IDBPDatabase, StoreKey, StoreNames, StoreValue,\n} from 'idb'\n\nimport { withDb } from './withDb.ts'\n\n/**\n * An IndexedDB key/value store.\n */\nexport class IndexedDbKeyValueStore<T extends DBSchema, S extends StoreNames<T>> implements KeyValueStore<StoreValue<T, S>, StoreKey<T, S>> {\n constructor(readonly dbName: string, readonly storeName: S) {}\n\n async clear?(): Promise<void> {\n return await this.withDb((db) => {\n return db.clear(this.storeName)\n })\n }\n\n async delete(key: string): Promise<void> {\n return await this.withDb((db) => {\n return db.delete(this.storeName, key)\n })\n }\n\n async get(key: string) {\n return await this.withDb((db) => {\n return db.get(this.storeName, key) ?? undefined\n })\n }\n\n async keys?(): Promise<StoreKey<T, S>[]> {\n return await this.withDb((db) => {\n return db.getAllKeys(this.storeName)\n })\n }\n\n async set(key: string, value: StoreValue<T, S>): Promise<void> {\n return await this.withDb((db) => {\n return db.put(this.storeName, value, key)\n })\n }\n\n async withDb<R = StoreValue<T, S>>(\n callback: (db: IDBPDatabase<T>) =>\n Promise<R> | R,\n ) {\n return await withDb<T, R>(this.dbName, (db) => {\n return callback(db)\n })\n }\n}\n","import type { EmptyObject } from '@xylabs/object'\nimport type {\n IDBPDatabase, IDBPObjectStore, StoreNames,\n} from 'idb'\n\nimport type { ObjectStore } from './ObjectStore.ts'\n\nexport async function withReadWriteStore<T extends EmptyObject = EmptyObject, R = T>(\n db: IDBPDatabase<ObjectStore<T>>,\n storeName: StoreNames<ObjectStore<T>>,\n callback: (store: IDBPObjectStore<ObjectStore<T>, [StoreNames<ObjectStore<T>>], StoreNames<ObjectStore<T>>, string>) => Promise<R> | R,\n): Promise<R> {\n const transaction = db.transaction(storeName, 'readwrite')\n const store = transaction.objectStore(storeName)\n try {\n return await callback(store)\n } finally {\n await transaction.done\n }\n}\n"],"mappings":";AA2BO,IAAM,iBAAiB;AAQvB,IAAM,yBAAyB,CAAC,UAA4B;AACjE,QAAM,EAAE,KAAK,OAAO,IAAI;AACxB,QAAM,SAAS,SAAS,OAAO;AAC/B,QAAM,YAAY,OAAO,KAAK,GAAG;AACjC,SAAO,GAAG,MAAM,IAAI,UAAU,KAAK,cAAc,CAAC;AACpD;;;AC5BO,SAAS,YACd,IACA,WACA,SACA,QACA;AACA,UAAQ,IAAI,kBAAkB,SAAS,EAAE;AAEzC,QAAM,QAAQ,GAAG,kBAAkB,WAAW;AAAA;AAAA,IAE5C,eAAe;AAAA,EACjB,CAAC;AAED,QAAM,OAAO;AAEb,aAAW;AAAA,IACT;AAAA,IAAK;AAAA,IAAY;AAAA,EACnB,KAAK,SAAS;AACZ,UAAM,YAAY,OAAO,KAAK,GAAG;AACjC,UAAM,OAAO,UAAU,WAAW,IAAI,UAAU,CAAC,IAAI;AACrD,UAAM,YAAY,uBAAuB,EAAE,KAAK,OAAO,CAAC;AACxD,YAAQ,IAAI,eAAe,WAAW,MAAM,EAAE,YAAY,OAAO,CAAC;AAClE,UAAM,YAAY,WAAW,MAAM,EAAE,YAAY,OAAO,CAAC;AAAA,EAC3D;AACF;;;AC7BA,eAAsB,kBACpB,IACA,WACA,UACY;AACZ,QAAM,cAAc,GAAG,YAAY,WAAW,UAAU;AACxD,QAAM,QAAQ,YAAY,YAAY,SAAS;AAC/C,MAAI;AACF,WAAO,MAAM,SAAS,KAAK;AAAA,EAC7B,UAAE;AACA,UAAM,YAAY;AAAA,EACpB;AACF;;;ACTA,eAAsB,mBACpB,IACA,WAC6B;AAC7B,SAAO,MAAM,kBAAkB,IAAI,WAAW,CAAC,UAAU;AACvD,WAAO,CAAC,GAAG,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AAAA,IACrC,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,IAAI,KAAa,OAAwC;AAC7D,WAAO,MAAM,KAAK,OAAO,CAAC,OAAO;AAC/B,aAAO,GAAG,IAAI,KAAK,WAAW,OAAO,GAAG;AAAA,IAC1C,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,OACJ,UAEA;AACA,WAAO,MAAM,OAAa,KAAK,QAAQ,CAAC,OAAO;AAC7C,aAAO,SAAS,EAAE;AAAA,IACpB,CAAC;AAAA,EACH;AACF;;;AC7CA,eAAsB,mBACpB,IACA,WACA,UACY;AACZ,QAAM,cAAc,GAAG,YAAY,WAAW,WAAW;AACzD,QAAM,QAAQ,YAAY,YAAY,SAAS;AAC/C,MAAI;AACF,WAAO,MAAM,SAAS,KAAK;AAAA,EAC7B,UAAE;AACA,UAAM,YAAY;AAAA,EACpB;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/checkDbNeedsUpgrade.ts","../../src/withDb.ts","../../src/IndexDescription.ts","../../src/createStoreDuringUpgrade.ts","../../src/withStore.ts","../../src/withReadOnlyStore.ts","../../src/getExistingIndexes.ts","../../src/IndexedDbKeyValueStore.ts","../../src/withReadWriteStore.ts"],"sourcesContent":["import { exists } from '@xylabs/exists'\nimport type { Logger } from '@xylabs/logger'\nimport type { IDBPDatabase } from 'idb'\n\nimport { getExistingIndexes } from './getExistingIndexes.ts'\nimport { buildStandardIndexName, type IndexDescription } from './IndexDescription.ts'\nimport type { ObjectStore } from './ObjectStore.ts'\nimport { withDb } from './withDb.ts'\n\nexport async function checkStoreNeedsUpgrade(db: IDBPDatabase<ObjectStore<object>>, storeName: string, indexes: IndexDescription[], logger?: Logger) {\n logger?.log('checkStoreNeedsUpgrade', storeName, indexes)\n const existingIndexes = await getExistingIndexes(db, storeName, logger)\n if (existingIndexes === null) {\n // the store does not exist, so we need to trigger upgrade (no existing indexes)\n return true\n }\n const existingIndexNames = new Set(existingIndexes.map(({ key, unique }) => buildStandardIndexName({ key, unique })).filter(exists))\n for (const { key, unique } of indexes) {\n const indexName = buildStandardIndexName({ key, unique })\n if (!existingIndexNames.has(indexName)) {\n return true\n }\n }\n return false\n}\n\nexport async function checkDbNeedsUpgrade(dbName: string, stores: Record<string, IndexDescription[]>, logger?: Logger) {\n logger?.log('checkDbNeedsUpgrade', dbName, stores)\n return await withDb<ObjectStore, number>(dbName, async (db) => {\n for (const [storeName, indexes] of Object.entries(stores)) {\n if (await checkStoreNeedsUpgrade(db, storeName, indexes, logger)) {\n return db.version + 1\n }\n }\n return db.version\n })\n}\n","import type { Logger } from '@xylabs/logger'\nimport type { EmptyObject } from '@xylabs/object'\nimport type {\n DBSchema, IDBPDatabase, StoreNames,\n} from 'idb'\nimport { openDB } from 'idb'\n\nimport { checkDbNeedsUpgrade } from './checkDbNeedsUpgrade.ts'\nimport { createStoreDuringUpgrade } from './createStoreDuringUpgrade.ts'\nimport { buildStandardIndexName, type IndexDescription } from './IndexDescription.ts'\n\nexport async function withDb<DBTypes extends DBSchema | unknown = unknown, R = EmptyObject>(\n dbName: string,\n callback: (db: IDBPDatabase<DBTypes>) => Promise<R> | R,\n expectedIndexes?: Record<string, IndexDescription[]>,\n logger?: Logger,\n): Promise<R> {\n const versionToOpen = expectedIndexes === undefined ? undefined : await checkDbNeedsUpgrade(dbName, expectedIndexes, logger)\n const db = await openDB<DBTypes>(dbName, versionToOpen, {\n blocked(currentVersion, blockedVersion, event) {\n logger?.warn(`IndexedDb: Blocked from upgrading from ${currentVersion} to ${blockedVersion}`, event)\n },\n blocking(currentVersion, blockedVersion, event) {\n logger?.warn(`IndexedDb: Blocking upgrade from ${currentVersion} to ${blockedVersion}`, event)\n },\n terminated() {\n logger?.log('IndexedDb: Terminated')\n },\n upgrade(db, oldVersion, newVersion, transaction) {\n if (oldVersion !== newVersion) {\n logger?.log(`IndexedDb: Upgrading from ${oldVersion} to ${newVersion}`)\n const objectStores = transaction.objectStoreNames\n for (const name of objectStores) {\n try {\n db.deleteObjectStore(name)\n } catch {\n console.log(`IndexedDb: Failed to delete existing object store ${name}`)\n }\n }\n }\n if (expectedIndexes) {\n for (const [storeName, indexes] of Object.entries(expectedIndexes)) {\n if (db.objectStoreNames.contains(storeName as StoreNames<DBTypes>)) {\n continue\n }\n const indexesToCreate = indexes.map(idx => ({\n ...idx,\n name: buildStandardIndexName(idx),\n // eslint-disable-next-line unicorn/no-array-reduce\n })).reduce((acc, idx) => acc.set(idx.name, idx), new Map<string, IndexDescription>()).values()\n createStoreDuringUpgrade(db, storeName as StoreNames<DBTypes>, [...indexesToCreate], logger)\n }\n }\n },\n })\n try {\n return await callback(db)\n } finally {\n db.close()\n }\n}\n","/**\n * The index direction (1 for ascending, -1 for descending)\n */\nexport type IndexDirection = -1 | 1\n\n/**\n * Description of index(es) to be created on a store\n */\nexport type IndexDescription = {\n /**\n * The key(s) to index\n */\n key: Record<string, IndexDirection>\n /**\n * Is the indexed value an array\n */\n multiEntry?: boolean\n /**\n * If true, the index must enforce uniqueness on the key\n */\n unique?: boolean\n}\n\nexport const IndexSeparator = '-'\n\n/**\n * Given an index description, this will build the index\n * name in standard form\n * @param index The index description\n * @returns The index name in standard form\n */\nexport const buildStandardIndexName = (index: IndexDescription) => {\n const { key, unique } = index\n const prefix = unique ? 'UX' : 'IX'\n const indexKeys = Object.keys(key)\n return `${prefix}_${indexKeys.join(IndexSeparator)}`\n}\n","import type { Logger } from '@xylabs/logger'\nimport type {\n DBSchema,\n IDBPDatabase, IDBPObjectStore, IndexNames, StoreNames,\n} from 'idb'\n\nimport {\n buildStandardIndexName,\n type IndexDescription,\n} from './IndexDescription.ts'\n\nexport function createStoreDuringUpgrade<DBTypes extends DBSchema | unknown = unknown>(\n db: IDBPDatabase<DBTypes>,\n storeName: StoreNames<DBTypes>,\n indexes: IndexDescription[],\n logger?: Logger,\n) {\n logger?.log(`Creating store ${storeName}`)\n // Create the store\n let store: IDBPObjectStore<DBTypes, ArrayLike<StoreNames<DBTypes>>, StoreNames<DBTypes>, 'versionchange'> | undefined\n try {\n store = db.createObjectStore(storeName, {\n // If it isn't explicitly set, create a value by auto incrementing.\n autoIncrement: true,\n })\n } catch {\n logger?.warn(`Failed to create store: ${storeName} already exists`)\n return\n }\n logger?.log(`Creating store: created ${storeName}`)\n // Name the store\n store.name = storeName\n // Create an index on the hash\n for (const {\n key, multiEntry, unique,\n } of indexes) {\n logger?.log(`Creating store: index ${key}`)\n const indexKeys = Object.keys(key)\n const keys = indexKeys.length === 1 ? indexKeys[0] : indexKeys\n const indexName = buildStandardIndexName({ key, unique }) as IndexNames<DBTypes, StoreNames<DBTypes>>\n console.log('createIndex', indexName, keys, { multiEntry, unique })\n store.createIndex(indexName, keys, { multiEntry, unique })\n }\n}\n","import type { Logger } from '@xylabs/logger'\nimport type { EmptyObject } from '@xylabs/object'\nimport type {\n IDBPDatabase, IDBPObjectStore, IDBPTransaction, StoreNames,\n} from 'idb'\n\nimport type { ObjectStore } from './ObjectStore.ts'\n\nexport async function withStore<T extends EmptyObject = EmptyObject, R = T, M extends 'readonly' | 'readwrite' = 'readonly'>(\n db: IDBPDatabase<ObjectStore<T>>,\n storeName: StoreNames<ObjectStore<T>>,\n callback: (store: IDBPObjectStore<ObjectStore<T>,\n [StoreNames<ObjectStore<T>>], StoreNames<ObjectStore<T>>, M> | null) => Promise<R> | R,\n mode: M,\n logger?: Logger,\n): Promise<R> {\n logger?.log('withStore', storeName, mode)\n let transaction: IDBPTransaction<ObjectStore<T>, [StoreNames<ObjectStore<T>>], M> | undefined = undefined\n logger?.log('withStore:transaction')\n let store = null\n try {\n transaction = db.transaction(storeName, mode)\n // we do this in a try/catch because the store might not exist\n store = transaction.objectStore(storeName)\n } catch (ex) {\n logger?.log('withStore:catch', ex)\n }\n try {\n return await callback(store)\n } finally {\n logger?.log('withStore:finally')\n await transaction?.done\n }\n}\n","import type { Logger } from '@xylabs/logger'\nimport type { EmptyObject } from '@xylabs/object'\nimport type {\n IDBPDatabase, IDBPObjectStore, StoreNames,\n} from 'idb'\n\nimport type { ObjectStore } from './ObjectStore.ts'\nimport { withStore } from './withStore.ts'\n\nexport async function withReadOnlyStore<T extends EmptyObject = EmptyObject, R = T>(\n db: IDBPDatabase<ObjectStore<T>>,\n storeName: StoreNames<ObjectStore<T>>,\n callback: (store: IDBPObjectStore<ObjectStore<T>, [StoreNames<ObjectStore<T>>], StoreNames<ObjectStore<T>>, 'readonly'> | null) => Promise<R> | R,\n logger?: Logger,\n): Promise<R> {\n return await withStore(db, storeName, callback, 'readonly', logger)\n}\n","import type { Logger } from '@xylabs/logger'\nimport type { EmptyObject } from '@xylabs/object'\nimport type { IDBPDatabase, StoreNames } from 'idb'\n\nimport {\n type IndexDescription,\n type IndexDirection,\n} from './IndexDescription.ts'\nimport type { ObjectStore } from './ObjectStore.ts'\nimport { withDb } from './withDb.ts'\nimport { withReadOnlyStore } from './withReadOnlyStore.ts'\n\nasync function getExistingIndexesInternal<T extends EmptyObject = EmptyObject>(\n db: IDBPDatabase<ObjectStore<T>>,\n storeName: StoreNames<ObjectStore<T>>,\n logger?: Logger,\n): Promise<IndexDescription[] | null> {\n logger?.log('getExistingIndexesInternal', storeName)\n return await withReadOnlyStore(db, storeName, (store) => {\n return store\n ? [...store.indexNames].map((indexName) => {\n const index = store.index(indexName)\n const key: Record<string, IndexDirection> = {}\n if (Array.isArray(index.keyPath)) {\n for (const keyPath of index.keyPath) {\n key[keyPath] = 1\n }\n } else {\n key[index.keyPath] = 1\n }\n const desc: IndexDescription = {\n key,\n unique: index.unique,\n multiEntry: index.multiEntry,\n }\n return desc\n })\n : null\n }, logger)\n}\n\nexport async function getExistingIndexes<T extends EmptyObject = EmptyObject>(\n db: IDBPDatabase<ObjectStore<T>> | string,\n storeName: StoreNames<ObjectStore<T>>,\n logger?: Logger,\n): Promise<IndexDescription[] | null> {\n logger?.log('getExistingIndexes', storeName)\n if (typeof db === 'string') {\n return await withDb<ObjectStore<T>, IndexDescription[] | null>(db, async (db) => {\n return await getExistingIndexesInternal(db, storeName, logger)\n })\n }\n return await getExistingIndexesInternal(db, storeName, logger)\n}\n","import type { KeyValueStore } from '@xylabs/storage'\nimport type {\n DBSchema,\n IDBPDatabase, StoreKey, StoreNames, StoreValue,\n} from 'idb'\n\nimport { withDb } from './withDb.ts'\n\n/**\n * An IndexedDB key/value store.\n */\nexport class IndexedDbKeyValueStore<T extends DBSchema, S extends StoreNames<T>> implements KeyValueStore<StoreValue<T, S>, StoreKey<T, S>> {\n constructor(readonly dbName: string, readonly storeName: S) {}\n\n async clear?(): Promise<void> {\n return await this.withDb((db) => {\n return db.clear(this.storeName)\n })\n }\n\n async delete(key: StoreKey<T, S>): Promise<void> {\n return await this.withDb((db) => {\n return db.delete(this.storeName, key)\n })\n }\n\n async get(key: StoreKey<T, S>) {\n return await this.withDb((db) => {\n return db.get(this.storeName, key) ?? undefined\n })\n }\n\n async keys?(): Promise<StoreKey<T, S>[]> {\n return await this.withDb((db) => {\n return db.getAllKeys(this.storeName)\n })\n }\n\n async set(key: StoreKey<T, S>, value: StoreValue<T, S>): Promise<StoreKey<T, S>> {\n return await this.withDb((db) => {\n return db.put(this.storeName, value, key)\n })\n }\n\n async withDb<R = StoreValue<T, S>>(\n callback: (db: IDBPDatabase<T>) =>\n Promise<R> | R,\n ) {\n return await withDb<T, R>(this.dbName, (db) => {\n return callback(db)\n })\n }\n}\n","import type { Logger } from '@xylabs/logger'\nimport type { EmptyObject } from '@xylabs/object'\nimport type {\n IDBPDatabase, IDBPObjectStore, StoreNames,\n} from 'idb'\n\nimport type { ObjectStore } from './ObjectStore.ts'\nimport { withStore } from './withStore.ts'\n\nexport async function withReadWriteStore<T extends EmptyObject = EmptyObject, R = T>(\n db: IDBPDatabase<ObjectStore<T>>,\n storeName: StoreNames<ObjectStore<T>>,\n callback: (store: IDBPObjectStore<ObjectStore<T>, [StoreNames<ObjectStore<T>>], StoreNames<ObjectStore<T>>, 'readwrite'> | null) => Promise<R> | R,\n logger?: Logger,\n): Promise<R> {\n return await withStore(db, storeName, callback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AM,IAAI,KAAqB;AAC7B,WAAO,MAAM,KAAK,OAAO,CAAC,OAAO;AAC/B,aAAO,GAAG,IAAI,KAAK,WAAW,GAAG,KAAK;AAAA,IACxC,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,OAAmC;AACvC,WAAO,MAAM,KAAK,OAAO,CAAC,OAAO;AAC/B,aAAO,GAAG,WAAW,KAAK,SAAS;AAAA,IACrC,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,IAAI,KAAqB,OAAkD;AAC/E,WAAO,MAAM,KAAK,OAAO,CAAC,OAAO;AAC/B,aAAO,GAAG,IAAI,KAAK,WAAW,OAAO,GAAG;AAAA,IAC1C,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,OACJ,UAEA;AACA,WAAO,MAAM,OAAa,KAAK,QAAQ,CAAC,OAAO;AAC7C,aAAO,SAAS,EAAE;AAAA,IACpB,CAAC;AAAA,EACH;AACF;;;AC3CA,eAAsB,mBACpB,IACA,WACA,UACA,QACY;AACZ,SAAO,MAAM,UAAU,IAAI,WAAW,UAAU,aAAa,MAAM;AACrE;","names":["db","db"]}
|
package/dist/neutral/withDb.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { Logger } from '@xylabs/logger';
|
|
1
2
|
import type { EmptyObject } from '@xylabs/object';
|
|
2
3
|
import type { DBSchema, IDBPDatabase } from 'idb';
|
|
3
|
-
|
|
4
|
+
import { type IndexDescription } from './IndexDescription.ts';
|
|
5
|
+
export declare function withDb<DBTypes extends DBSchema | unknown = unknown, R = EmptyObject>(dbName: string, callback: (db: IDBPDatabase<DBTypes>) => Promise<R> | R, expectedIndexes?: Record<string, IndexDescription[]>, logger?: Logger): Promise<R>;
|
|
4
6
|
//# sourceMappingURL=withDb.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withDb.d.ts","sourceRoot":"","sources":["../../src/withDb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"withDb.d.ts","sourceRoot":"","sources":["../../src/withDb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EACV,QAAQ,EAAE,YAAY,EACvB,MAAM,KAAK,CAAA;AAKZ,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAErF,wBAAsB,MAAM,CAAC,OAAO,SAAS,QAAQ,GAAG,OAAO,GAAG,OAAO,EAAE,CAAC,GAAG,WAAW,EACxF,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,CAAC,EAAE,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EACvD,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAC,EACpD,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,CAAC,CAAC,CA4CZ"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { Logger } from '@xylabs/logger';
|
|
1
2
|
import type { EmptyObject } from '@xylabs/object';
|
|
2
3
|
import type { IDBPDatabase, IDBPObjectStore, StoreNames } from 'idb';
|
|
3
4
|
import type { ObjectStore } from './ObjectStore.ts';
|
|
4
|
-
export declare function withReadOnlyStore<T extends EmptyObject = EmptyObject, R = T>(db: IDBPDatabase<ObjectStore<T>>, storeName: StoreNames<ObjectStore<T>>, callback: (store: IDBPObjectStore<ObjectStore<T>, [StoreNames<ObjectStore<T>>], StoreNames<ObjectStore<T>>,
|
|
5
|
+
export declare function withReadOnlyStore<T extends EmptyObject = EmptyObject, R = T>(db: IDBPDatabase<ObjectStore<T>>, storeName: StoreNames<ObjectStore<T>>, callback: (store: IDBPObjectStore<ObjectStore<T>, [StoreNames<ObjectStore<T>>], StoreNames<ObjectStore<T>>, 'readonly'> | null) => Promise<R> | R, logger?: Logger): Promise<R>;
|
|
5
6
|
//# sourceMappingURL=withReadOnlyStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withReadOnlyStore.d.ts","sourceRoot":"","sources":["../../src/withReadOnlyStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EACV,YAAY,EAAE,eAAe,EAAE,UAAU,EAC1C,MAAM,KAAK,CAAA;AAEZ,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"withReadOnlyStore.d.ts","sourceRoot":"","sources":["../../src/withReadOnlyStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EACV,YAAY,EAAE,eAAe,EAAE,UAAU,EAC1C,MAAM,KAAK,CAAA;AAEZ,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAGnD,wBAAsB,iBAAiB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAAE,CAAC,GAAG,CAAC,EAChF,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAChC,SAAS,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EACrC,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EACjJ,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,CAAC,CAAC,CAEZ"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { Logger } from '@xylabs/logger';
|
|
1
2
|
import type { EmptyObject } from '@xylabs/object';
|
|
2
3
|
import type { IDBPDatabase, IDBPObjectStore, StoreNames } from 'idb';
|
|
3
4
|
import type { ObjectStore } from './ObjectStore.ts';
|
|
4
|
-
export declare function withReadWriteStore<T extends EmptyObject = EmptyObject, R = T>(db: IDBPDatabase<ObjectStore<T>>, storeName: StoreNames<ObjectStore<T>>, callback: (store: IDBPObjectStore<ObjectStore<T>, [StoreNames<ObjectStore<T>>], StoreNames<ObjectStore<T>>,
|
|
5
|
+
export declare function withReadWriteStore<T extends EmptyObject = EmptyObject, R = T>(db: IDBPDatabase<ObjectStore<T>>, storeName: StoreNames<ObjectStore<T>>, callback: (store: IDBPObjectStore<ObjectStore<T>, [StoreNames<ObjectStore<T>>], StoreNames<ObjectStore<T>>, 'readwrite'> | null) => Promise<R> | R, logger?: Logger): Promise<R>;
|
|
5
6
|
//# sourceMappingURL=withReadWriteStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withReadWriteStore.d.ts","sourceRoot":"","sources":["../../src/withReadWriteStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EACV,YAAY,EAAE,eAAe,EAAE,UAAU,EAC1C,MAAM,KAAK,CAAA;AAEZ,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"withReadWriteStore.d.ts","sourceRoot":"","sources":["../../src/withReadWriteStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EACV,YAAY,EAAE,eAAe,EAAE,UAAU,EAC1C,MAAM,KAAK,CAAA;AAEZ,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAGnD,wBAAsB,kBAAkB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAAE,CAAC,GAAG,CAAC,EACjF,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAChC,SAAS,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EACrC,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,GAAG,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAClJ,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,CAAC,CAAC,CAEZ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Logger } from '@xylabs/logger';
|
|
2
|
+
import type { EmptyObject } from '@xylabs/object';
|
|
3
|
+
import type { IDBPDatabase, IDBPObjectStore, StoreNames } from 'idb';
|
|
4
|
+
import type { ObjectStore } from './ObjectStore.ts';
|
|
5
|
+
export declare function withStore<T extends EmptyObject = EmptyObject, R = T, M extends 'readonly' | 'readwrite' = 'readonly'>(db: IDBPDatabase<ObjectStore<T>>, storeName: StoreNames<ObjectStore<T>>, callback: (store: IDBPObjectStore<ObjectStore<T>, [
|
|
6
|
+
StoreNames<ObjectStore<T>>
|
|
7
|
+
], StoreNames<ObjectStore<T>>, M> | null) => Promise<R> | R, mode: M, logger?: Logger): Promise<R>;
|
|
8
|
+
//# sourceMappingURL=withStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withStore.d.ts","sourceRoot":"","sources":["../../src/withStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EACV,YAAY,EAAE,eAAe,EAAmB,UAAU,EAC3D,MAAM,KAAK,CAAA;AAEZ,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD,wBAAsB,SAAS,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,UAAU,GAAG,WAAW,GAAG,UAAU,EACzH,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAChC,SAAS,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EACrC,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,EAC9C;IAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EACxF,IAAI,EAAE,CAAC,EACP,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,CAAC,CAAC,CAkBZ"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The index direction (1 for ascending, -1 for descending)
|
|
3
|
+
*/
|
|
4
|
+
export type IndexDirection = -1 | 1;
|
|
5
|
+
/**
|
|
6
|
+
* Description of index(es) to be created on a store
|
|
7
|
+
*/
|
|
8
|
+
export type IndexDescription = {
|
|
9
|
+
/**
|
|
10
|
+
* The key(s) to index
|
|
11
|
+
*/
|
|
12
|
+
key: Record<string, IndexDirection>;
|
|
13
|
+
/**
|
|
14
|
+
* Is the indexed value an array
|
|
15
|
+
*/
|
|
16
|
+
multiEntry?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* If true, the index must enforce uniqueness on the key
|
|
19
|
+
*/
|
|
20
|
+
unique?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export declare const IndexSeparator = "-";
|
|
23
|
+
/**
|
|
24
|
+
* Given an index description, this will build the index
|
|
25
|
+
* name in standard form
|
|
26
|
+
* @param index The index description
|
|
27
|
+
* @returns The index name in standard form
|
|
28
|
+
*/
|
|
29
|
+
export declare const buildStandardIndexName: (index: IndexDescription) => string;
|
|
30
|
+
//# sourceMappingURL=IndexDescription.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndexDescription.d.ts","sourceRoot":"","sources":["../../src/IndexDescription.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,GAAG,CAAC,CAAA;AAEnC;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IACnC;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,cAAc,MAAM,CAAA;AAEjC;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,UAAW,gBAAgB,WAK7D,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { KeyValueStore } from '@xylabs/storage';
|
|
2
|
+
import type { DBSchema, IDBPDatabase, StoreKey, StoreNames, StoreValue } from 'idb';
|
|
3
|
+
/**
|
|
4
|
+
* An IndexedDB key/value store.
|
|
5
|
+
*/
|
|
6
|
+
export declare class IndexedDbKeyValueStore<T extends DBSchema, S extends StoreNames<T>> implements KeyValueStore<StoreValue<T, S>, StoreKey<T, S>> {
|
|
7
|
+
readonly dbName: string;
|
|
8
|
+
readonly storeName: S;
|
|
9
|
+
constructor(dbName: string, storeName: S);
|
|
10
|
+
clear?(): Promise<void>;
|
|
11
|
+
delete(key: StoreKey<T, S>): Promise<void>;
|
|
12
|
+
get(key: StoreKey<T, S>): Promise<StoreValue<T, S> | undefined>;
|
|
13
|
+
keys?(): Promise<StoreKey<T, S>[]>;
|
|
14
|
+
set(key: StoreKey<T, S>, value: StoreValue<T, S>): Promise<StoreKey<T, S>>;
|
|
15
|
+
withDb<R = StoreValue<T, S>>(callback: (db: IDBPDatabase<T>) => Promise<R> | R): Promise<R>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=IndexedDbKeyValueStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndexedDbKeyValueStore.d.ts","sourceRoot":"","sources":["../../src/IndexedDbKeyValueStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAC/C,MAAM,KAAK,CAAA;AAIZ;;GAEG;AACH,qBAAa,sBAAsB,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7H,QAAQ,CAAC,MAAM,EAAE,MAAM;IAAE,QAAQ,CAAC,SAAS,EAAE,CAAC;gBAArC,MAAM,EAAE,MAAM,EAAW,SAAS,EAAE,CAAC;IAEpD,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;IAMvB,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAM1C,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;IAMvB,IAAI,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAMlC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAM1E,MAAM,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EAC/B,QAAQ,EAAE,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC,KAC5B,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;CAMnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObjectStore.d.ts","sourceRoot":"","sources":["../../src/ObjectStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAEjD,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW;IAC9D,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAA;CACf"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Logger } from '@xylabs/logger';
|
|
2
|
+
import type { IDBPDatabase } from 'idb';
|
|
3
|
+
import { type IndexDescription } from './IndexDescription.ts';
|
|
4
|
+
import type { ObjectStore } from './ObjectStore.ts';
|
|
5
|
+
export declare function checkStoreNeedsUpgrade(db: IDBPDatabase<ObjectStore<object>>, storeName: string, indexes: IndexDescription[], logger?: Logger): Promise<boolean>;
|
|
6
|
+
export declare function checkDbNeedsUpgrade(dbName: string, stores: Record<string, IndexDescription[]>, logger?: Logger): Promise<number>;
|
|
7
|
+
//# sourceMappingURL=checkDbNeedsUpgrade.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkDbNeedsUpgrade.d.ts","sourceRoot":"","sources":["../../src/checkDbNeedsUpgrade.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,KAAK,CAAA;AAGvC,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAGnD,wBAAsB,sBAAsB,CAAC,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,oBAelJ;AAED,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,mBAUpH"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Logger } from '@xylabs/logger';
|
|
2
|
+
import type { DBSchema, IDBPDatabase, StoreNames } from 'idb';
|
|
3
|
+
import { type IndexDescription } from './IndexDescription.ts';
|
|
4
|
+
export declare function createStoreDuringUpgrade<DBTypes extends DBSchema | unknown = unknown>(db: IDBPDatabase<DBTypes>, storeName: StoreNames<DBTypes>, indexes: IndexDescription[], logger?: Logger): void;
|
|
5
|
+
//# sourceMappingURL=createStoreDuringUpgrade.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createStoreDuringUpgrade.d.ts","sourceRoot":"","sources":["../../src/createStoreDuringUpgrade.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EAA+B,UAAU,EACtD,MAAM,KAAK,CAAA;AAEZ,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,uBAAuB,CAAA;AAE9B,wBAAgB,wBAAwB,CAAC,OAAO,SAAS,QAAQ,GAAG,OAAO,GAAG,OAAO,EACnF,EAAE,EAAE,YAAY,CAAC,OAAO,CAAC,EACzB,SAAS,EAAE,UAAU,CAAC,OAAO,CAAC,EAC9B,OAAO,EAAE,gBAAgB,EAAE,EAC3B,MAAM,CAAC,EAAE,MAAM,QA4BhB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Logger } from '@xylabs/logger';
|
|
2
|
+
import type { EmptyObject } from '@xylabs/object';
|
|
3
|
+
import type { IDBPDatabase, StoreNames } from 'idb';
|
|
4
|
+
import { type IndexDescription } from './IndexDescription.ts';
|
|
5
|
+
import type { ObjectStore } from './ObjectStore.ts';
|
|
6
|
+
export declare function getExistingIndexes<T extends EmptyObject = EmptyObject>(db: IDBPDatabase<ObjectStore<T>> | string, storeName: StoreNames<ObjectStore<T>>, logger?: Logger): Promise<IndexDescription[] | null>;
|
|
7
|
+
//# sourceMappingURL=getExistingIndexes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getExistingIndexes.d.ts","sourceRoot":"","sources":["../../src/getExistingIndexes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAEnD,OAAO,EACL,KAAK,gBAAgB,EAEtB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAiCnD,wBAAsB,kBAAkB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAC1E,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,EACzC,SAAS,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EACrC,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAQpC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './checkDbNeedsUpgrade.ts';
|
|
2
|
+
export * from './createStoreDuringUpgrade.ts';
|
|
3
|
+
export * from './getExistingIndexes.ts';
|
|
4
|
+
export * from './IndexDescription.ts';
|
|
5
|
+
export * from './IndexedDbKeyValueStore.ts';
|
|
6
|
+
export * from './ObjectStore.ts';
|
|
7
|
+
export * from './withDb.ts';
|
|
8
|
+
export * from './withReadOnlyStore.ts';
|
|
9
|
+
export * from './withReadWriteStore.ts';
|
|
10
|
+
export * from './withStore.ts';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,yBAAyB,CAAA;AACvC,cAAc,uBAAuB,CAAA;AACrC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AACvC,cAAc,gBAAgB,CAAA"}
|