@xylabs/indexed-db 5.0.83 → 5.0.86
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/README.md +246 -313
- package/dist/browser/IndexDescription.d.ts +1 -0
- package/dist/browser/IndexDescription.d.ts.map +1 -1
- package/dist/browser/IndexedDbKeyValueStore.d.ts +23 -0
- package/dist/browser/IndexedDbKeyValueStore.d.ts.map +1 -1
- package/dist/browser/ObjectStore.d.ts +1 -0
- package/dist/browser/ObjectStore.d.ts.map +1 -1
- package/dist/browser/checkDbNeedsUpgrade.d.ts +7 -0
- package/dist/browser/checkDbNeedsUpgrade.d.ts.map +1 -1
- package/dist/browser/checkStoreNeedsUpgrade.d.ts +8 -0
- package/dist/browser/checkStoreNeedsUpgrade.d.ts.map +1 -1
- package/dist/browser/createStoreDuringUpgrade.d.ts +7 -0
- package/dist/browser/createStoreDuringUpgrade.d.ts.map +1 -1
- package/dist/browser/getExistingIndexes.d.ts +7 -0
- package/dist/browser/getExistingIndexes.d.ts.map +1 -1
- package/dist/browser/index.mjs +23 -0
- package/dist/browser/index.mjs.map +1 -1
- package/dist/browser/withDb.d.ts +10 -0
- package/dist/browser/withDb.d.ts.map +1 -1
- package/dist/browser/withDbByVersion.d.ts +11 -0
- package/dist/browser/withDbByVersion.d.ts.map +1 -1
- package/dist/browser/withReadOnlyStore.d.ts +8 -0
- package/dist/browser/withReadOnlyStore.d.ts.map +1 -1
- package/dist/browser/withReadWriteStore.d.ts +8 -0
- package/dist/browser/withReadWriteStore.d.ts.map +1 -1
- package/dist/browser/withStore.d.ts +10 -0
- package/dist/browser/withStore.d.ts.map +1 -1
- package/dist/neutral/IndexDescription.d.ts +1 -0
- package/dist/neutral/IndexDescription.d.ts.map +1 -1
- package/dist/neutral/IndexedDbKeyValueStore.d.ts +23 -0
- package/dist/neutral/IndexedDbKeyValueStore.d.ts.map +1 -1
- package/dist/neutral/ObjectStore.d.ts +1 -0
- package/dist/neutral/ObjectStore.d.ts.map +1 -1
- package/dist/neutral/checkDbNeedsUpgrade.d.ts +7 -0
- package/dist/neutral/checkDbNeedsUpgrade.d.ts.map +1 -1
- package/dist/neutral/checkStoreNeedsUpgrade.d.ts +8 -0
- package/dist/neutral/checkStoreNeedsUpgrade.d.ts.map +1 -1
- package/dist/neutral/createStoreDuringUpgrade.d.ts +7 -0
- package/dist/neutral/createStoreDuringUpgrade.d.ts.map +1 -1
- package/dist/neutral/getExistingIndexes.d.ts +7 -0
- package/dist/neutral/getExistingIndexes.d.ts.map +1 -1
- package/dist/neutral/index.mjs +23 -0
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/withDb.d.ts +10 -0
- package/dist/neutral/withDb.d.ts.map +1 -1
- package/dist/neutral/withDbByVersion.d.ts +11 -0
- package/dist/neutral/withDbByVersion.d.ts.map +1 -1
- package/dist/neutral/withReadOnlyStore.d.ts +8 -0
- package/dist/neutral/withReadOnlyStore.d.ts.map +1 -1
- package/dist/neutral/withReadWriteStore.d.ts +8 -0
- package/dist/neutral/withReadWriteStore.d.ts.map +1 -1
- package/dist/neutral/withStore.d.ts +10 -0
- package/dist/neutral/withStore.d.ts.map +1 -1
- package/dist/node/IndexDescription.d.ts +1 -0
- package/dist/node/IndexDescription.d.ts.map +1 -1
- package/dist/node/IndexedDbKeyValueStore.d.ts +23 -0
- package/dist/node/IndexedDbKeyValueStore.d.ts.map +1 -1
- package/dist/node/ObjectStore.d.ts +1 -0
- package/dist/node/ObjectStore.d.ts.map +1 -1
- package/dist/node/checkDbNeedsUpgrade.d.ts +7 -0
- package/dist/node/checkDbNeedsUpgrade.d.ts.map +1 -1
- package/dist/node/checkStoreNeedsUpgrade.d.ts +8 -0
- package/dist/node/checkStoreNeedsUpgrade.d.ts.map +1 -1
- package/dist/node/createStoreDuringUpgrade.d.ts +7 -0
- package/dist/node/createStoreDuringUpgrade.d.ts.map +1 -1
- package/dist/node/getExistingIndexes.d.ts +7 -0
- package/dist/node/getExistingIndexes.d.ts.map +1 -1
- package/dist/node/index.mjs +23 -0
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/withDb.d.ts +10 -0
- package/dist/node/withDb.d.ts.map +1 -1
- package/dist/node/withDbByVersion.d.ts +11 -0
- package/dist/node/withDbByVersion.d.ts.map +1 -1
- package/dist/node/withReadOnlyStore.d.ts +8 -0
- package/dist/node/withReadOnlyStore.d.ts.map +1 -1
- package/dist/node/withReadWriteStore.d.ts +8 -0
- package/dist/node/withReadWriteStore.d.ts.map +1 -1
- package/dist/node/withStore.d.ts +10 -0
- package/dist/node/withStore.d.ts.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
17
17
|
|
|
18
|
+
|
|
19
|
+
|
|
18
20
|
## Reference
|
|
19
21
|
|
|
20
22
|
**@xylabs/indexed-db**
|
|
@@ -23,32 +25,42 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
23
25
|
|
|
24
26
|
## Classes
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
| Class | Description |
|
|
29
|
+
| ------ | ------ |
|
|
30
|
+
| [IndexedDbKeyValueStore](#classes/IndexedDbKeyValueStore) | An IndexedDB key/value store. |
|
|
27
31
|
|
|
28
32
|
## Interfaces
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
| Interface | Description |
|
|
35
|
+
| ------ | ------ |
|
|
36
|
+
| [ObjectStore](#interfaces/ObjectStore) | Generic IndexedDB schema type that maps store names to their value types. |
|
|
31
37
|
|
|
32
38
|
## Type Aliases
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
| Type Alias | Description |
|
|
41
|
+
| ------ | ------ |
|
|
42
|
+
| [IndexDirection](#type-aliases/IndexDirection) | The index direction (1 for ascending, -1 for descending) |
|
|
43
|
+
| [IndexDescription](#type-aliases/IndexDescription) | Description of index(es) to be created on a store |
|
|
36
44
|
|
|
37
45
|
## Variables
|
|
38
46
|
|
|
39
|
-
|
|
47
|
+
| Variable | Description |
|
|
48
|
+
| ------ | ------ |
|
|
49
|
+
| [IndexSeparator](#variables/IndexSeparator) | Separator used between key names when building standard index names. |
|
|
40
50
|
|
|
41
51
|
## Functions
|
|
42
52
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
| Function | Description |
|
|
54
|
+
| ------ | ------ |
|
|
55
|
+
| [buildStandardIndexName](#functions/buildStandardIndexName) | Given an index description, this will build the index name in standard form |
|
|
56
|
+
| [checkDbNeedsUpgrade](#functions/checkDbNeedsUpgrade) | Checks whether any store in the database needs an upgrade and returns the appropriate version number. |
|
|
57
|
+
| [createStoreDuringUpgrade](#functions/createStoreDuringUpgrade) | Creates an object store with the specified indexes during a version upgrade transaction. |
|
|
58
|
+
| [getExistingIndexes](#functions/getExistingIndexes) | Retrieves the existing index descriptions for a store. Accepts either a database instance or a database name. |
|
|
59
|
+
| [withDb](#functions/withDb) | Opens an IndexedDB database, automatically upgrading if needed, and passes it to the callback. Uses a mutex to serialize access to the same database by default. |
|
|
60
|
+
| [withDbByVersion](#functions/withDbByVersion) | Opens an IndexedDB database at a specific version, handling upgrade events, and passes it to the callback. The database is automatically closed after the callback completes. |
|
|
61
|
+
| [withReadOnlyStore](#functions/withReadOnlyStore) | Opens a read-only transaction on the specified store and passes it to the callback. |
|
|
62
|
+
| [withReadWriteStore](#functions/withReadWriteStore) | Opens a read-write transaction on the specified store and passes it to the callback. |
|
|
63
|
+
| [withStore](#functions/withStore) | Opens a transaction on the specified store with the given mode and passes the store to the callback. If the store does not exist, the callback receives null. |
|
|
52
64
|
|
|
53
65
|
### classes
|
|
54
66
|
|
|
@@ -62,13 +74,10 @@ An IndexedDB key/value store.
|
|
|
62
74
|
|
|
63
75
|
## Type Parameters
|
|
64
76
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
`T` *extends* `DBSchema`
|
|
68
|
-
|
|
69
|
-
### S
|
|
70
|
-
|
|
71
|
-
`S` *extends* `StoreNames`\<`T`\>
|
|
77
|
+
| Type Parameter |
|
|
78
|
+
| ------ |
|
|
79
|
+
| `T` *extends* `DBSchema` |
|
|
80
|
+
| `S` *extends* `StoreNames`\<`T`\> |
|
|
72
81
|
|
|
73
82
|
## Implements
|
|
74
83
|
|
|
@@ -79,18 +88,15 @@ An IndexedDB key/value store.
|
|
|
79
88
|
### Constructor
|
|
80
89
|
|
|
81
90
|
```ts
|
|
82
|
-
new IndexedDbKeyValueStore<T, S>(dbName, storeName): IndexedDbKeyValueStore<T, S>;
|
|
91
|
+
new IndexedDbKeyValueStore<T, S>(dbName: string, storeName: S): IndexedDbKeyValueStore<T, S>;
|
|
83
92
|
```
|
|
84
93
|
|
|
85
94
|
### Parameters
|
|
86
95
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
`string`
|
|
90
|
-
|
|
91
|
-
#### storeName
|
|
92
|
-
|
|
93
|
-
`S`
|
|
96
|
+
| Parameter | Type |
|
|
97
|
+
| ------ | ------ |
|
|
98
|
+
| `dbName` | `string` |
|
|
99
|
+
| `storeName` | `S` |
|
|
94
100
|
|
|
95
101
|
### Returns
|
|
96
102
|
|
|
@@ -98,19 +104,10 @@ new IndexedDbKeyValueStore<T, S>(dbName, storeName): IndexedDbKeyValueStore<T, S
|
|
|
98
104
|
|
|
99
105
|
## Properties
|
|
100
106
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
readonly
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
***
|
|
108
|
-
|
|
109
|
-
### storeName
|
|
110
|
-
|
|
111
|
-
```ts
|
|
112
|
-
readonly storeName: S;
|
|
113
|
-
```
|
|
107
|
+
| Property | Modifier | Type | Description |
|
|
108
|
+
| ------ | ------ | ------ | ------ |
|
|
109
|
+
| <a id="dbname"></a> `dbName` | `readonly` | `string` | The name of the IndexedDB database. |
|
|
110
|
+
| <a id="storename"></a> `storeName` | `readonly` | `S` | The name of the object store within the database. |
|
|
114
111
|
|
|
115
112
|
## Methods
|
|
116
113
|
|
|
@@ -120,6 +117,8 @@ readonly storeName: S;
|
|
|
120
117
|
optional clear(): Promise<void>;
|
|
121
118
|
```
|
|
122
119
|
|
|
120
|
+
Removes all entries from the store.
|
|
121
|
+
|
|
123
122
|
### Returns
|
|
124
123
|
|
|
125
124
|
`Promise`\<`void`\>
|
|
@@ -135,14 +134,16 @@ KeyValueStore.clear
|
|
|
135
134
|
### delete()
|
|
136
135
|
|
|
137
136
|
```ts
|
|
138
|
-
delete(key): Promise<void>;
|
|
137
|
+
delete(key: StoreKey<T, S>): Promise<void>;
|
|
139
138
|
```
|
|
140
139
|
|
|
141
|
-
|
|
140
|
+
Deletes the entry with the given key.
|
|
142
141
|
|
|
143
|
-
|
|
142
|
+
### Parameters
|
|
144
143
|
|
|
145
|
-
|
|
144
|
+
| Parameter | Type | Description |
|
|
145
|
+
| ------ | ------ | ------ |
|
|
146
|
+
| `key` | `StoreKey`\<`T`, `S`\> | The key of the entry to delete |
|
|
146
147
|
|
|
147
148
|
### Returns
|
|
148
149
|
|
|
@@ -159,23 +160,23 @@ KeyValueStore.delete
|
|
|
159
160
|
### get()
|
|
160
161
|
|
|
161
162
|
```ts
|
|
162
|
-
get(key): Promise<StoreValue<T, S> | undefined>;
|
|
163
|
+
get(key: StoreKey<T, S>): Promise<StoreValue<T, S> | undefined>;
|
|
163
164
|
```
|
|
164
165
|
|
|
165
|
-
|
|
166
|
+
Retrieves the value associated with the given key.
|
|
166
167
|
|
|
167
168
|
### Parameters
|
|
168
169
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
`StoreKey`\<`T`, `S`\>
|
|
172
|
-
|
|
173
|
-
The key to get the value for.
|
|
170
|
+
| Parameter | Type | Description |
|
|
171
|
+
| ------ | ------ | ------ |
|
|
172
|
+
| `key` | `StoreKey`\<`T`, `S`\> | The key to look up |
|
|
174
173
|
|
|
175
174
|
### Returns
|
|
176
175
|
|
|
177
176
|
`Promise`\<`StoreValue`\<`T`, `S`\> \| `undefined`\>
|
|
178
177
|
|
|
178
|
+
The value, or undefined if not found
|
|
179
|
+
|
|
179
180
|
### Implementation of
|
|
180
181
|
|
|
181
182
|
```ts
|
|
@@ -190,7 +191,7 @@ KeyValueStore.get
|
|
|
190
191
|
optional keys(): Promise<StoreKey<T, S>[]>;
|
|
191
192
|
```
|
|
192
193
|
|
|
193
|
-
|
|
194
|
+
Returns all keys in the store.
|
|
194
195
|
|
|
195
196
|
### Returns
|
|
196
197
|
|
|
@@ -207,18 +208,17 @@ KeyValueStore.keys
|
|
|
207
208
|
### set()
|
|
208
209
|
|
|
209
210
|
```ts
|
|
210
|
-
set(key, value): Promise<void>;
|
|
211
|
+
set(key: StoreKey<T, S>, value: StoreValue<T, S>): Promise<void>;
|
|
211
212
|
```
|
|
212
213
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
#### key
|
|
216
|
-
|
|
217
|
-
`StoreKey`\<`T`, `S`\>
|
|
214
|
+
Sets a value for the given key, creating or updating the entry.
|
|
218
215
|
|
|
219
|
-
|
|
216
|
+
### Parameters
|
|
220
217
|
|
|
221
|
-
|
|
218
|
+
| Parameter | Type | Description |
|
|
219
|
+
| ------ | ------ | ------ |
|
|
220
|
+
| `key` | `StoreKey`\<`T`, `S`\> | The key to set |
|
|
221
|
+
| `value` | `StoreValue`\<`T`, `S`\> | The value to store |
|
|
222
222
|
|
|
223
223
|
### Returns
|
|
224
224
|
|
|
@@ -235,25 +235,29 @@ KeyValueStore.set
|
|
|
235
235
|
### withDb()
|
|
236
236
|
|
|
237
237
|
```ts
|
|
238
|
-
withDb<R>(callback): Promise<R>;
|
|
238
|
+
withDb<R>(callback: (db: IDBPDatabase<T>) => R | Promise<R>): Promise<R>;
|
|
239
239
|
```
|
|
240
240
|
|
|
241
|
-
|
|
241
|
+
Opens the underlying IndexedDB database and passes it to the callback.
|
|
242
242
|
|
|
243
|
-
|
|
243
|
+
### Type Parameters
|
|
244
244
|
|
|
245
|
-
|
|
245
|
+
| Type Parameter | Default type |
|
|
246
|
+
| ------ | ------ |
|
|
247
|
+
| `R` | `StoreValue`\<`T`, `S`\> |
|
|
246
248
|
|
|
247
249
|
### Parameters
|
|
248
250
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
(`db`) => `R` \| `Promise`\<`R`\>
|
|
251
|
+
| Parameter | Type | Description |
|
|
252
|
+
| ------ | ------ | ------ |
|
|
253
|
+
| `callback` | (`db`: `IDBPDatabase`\<`T`\>) => `R` \| `Promise`\<`R`\> | Function to execute with the database |
|
|
252
254
|
|
|
253
255
|
### Returns
|
|
254
256
|
|
|
255
257
|
`Promise`\<`R`\>
|
|
256
258
|
|
|
259
|
+
The result of the callback
|
|
260
|
+
|
|
257
261
|
### functions
|
|
258
262
|
|
|
259
263
|
### <a id="buildStandardIndexName"></a>buildStandardIndexName
|
|
@@ -263,7 +267,7 @@ withDb<R>(callback): Promise<R>;
|
|
|
263
267
|
***
|
|
264
268
|
|
|
265
269
|
```ts
|
|
266
|
-
function buildStandardIndexName(index): string;
|
|
270
|
+
function buildStandardIndexName(index: IndexDescription): string;
|
|
267
271
|
```
|
|
268
272
|
|
|
269
273
|
Given an index description, this will build the index
|
|
@@ -271,11 +275,9 @@ name in standard form
|
|
|
271
275
|
|
|
272
276
|
## Parameters
|
|
273
277
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
[`IndexDescription`](#../type-aliases/IndexDescription)
|
|
277
|
-
|
|
278
|
-
The index description
|
|
278
|
+
| Parameter | Type | Description |
|
|
279
|
+
| ------ | ------ | ------ |
|
|
280
|
+
| `index` | [`IndexDescription`](#../type-aliases/IndexDescription) | The index description |
|
|
279
281
|
|
|
280
282
|
## Returns
|
|
281
283
|
|
|
@@ -291,29 +293,27 @@ The index name in standard form
|
|
|
291
293
|
|
|
292
294
|
```ts
|
|
293
295
|
function checkDbNeedsUpgrade(
|
|
294
|
-
dbName,
|
|
295
|
-
stores,
|
|
296
|
-
logger
|
|
296
|
+
dbName: string,
|
|
297
|
+
stores: Record<string, IndexDescription[]>,
|
|
298
|
+
logger?: Logger): Promise<number>;
|
|
297
299
|
```
|
|
298
300
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
### dbName
|
|
302
|
-
|
|
303
|
-
`string`
|
|
304
|
-
|
|
305
|
-
### stores
|
|
306
|
-
|
|
307
|
-
`Record`\<`string`, [`IndexDescription`](#../type-aliases/IndexDescription)[]\>
|
|
301
|
+
Checks whether any store in the database needs an upgrade and returns the appropriate version number.
|
|
308
302
|
|
|
309
|
-
|
|
303
|
+
## Parameters
|
|
310
304
|
|
|
311
|
-
|
|
305
|
+
| Parameter | Type | Description |
|
|
306
|
+
| ------ | ------ | ------ |
|
|
307
|
+
| `dbName` | `string` | The name of the database to check |
|
|
308
|
+
| `stores` | `Record`\<`string`, [`IndexDescription`](#../type-aliases/IndexDescription)[]\> | Map of store names to their expected index descriptions |
|
|
309
|
+
| `logger?` | `Logger` | Optional logger for diagnostics |
|
|
312
310
|
|
|
313
311
|
## Returns
|
|
314
312
|
|
|
315
313
|
`Promise`\<`number`\>
|
|
316
314
|
|
|
315
|
+
The version to open (current version + 1 if upgrade needed, otherwise current version)
|
|
316
|
+
|
|
317
317
|
### <a id="createStoreDuringUpgrade"></a>createStoreDuringUpgrade
|
|
318
318
|
|
|
319
319
|
[**@xylabs/indexed-db**](#../README)
|
|
@@ -322,35 +322,28 @@ logger?): Promise<number>;
|
|
|
322
322
|
|
|
323
323
|
```ts
|
|
324
324
|
function createStoreDuringUpgrade<DBTypes>(
|
|
325
|
-
db
|
|
326
|
-
storeName
|
|
327
|
-
indexes,
|
|
328
|
-
logger
|
|
325
|
+
db: IDBPDatabase<DBTypes>,
|
|
326
|
+
storeName: StoreNames<DBTypes>,
|
|
327
|
+
indexes: IndexDescription[],
|
|
328
|
+
logger?: Logger): void;
|
|
329
329
|
```
|
|
330
330
|
|
|
331
|
-
|
|
331
|
+
Creates an object store with the specified indexes during a version upgrade transaction.
|
|
332
332
|
|
|
333
|
-
|
|
333
|
+
## Type Parameters
|
|
334
334
|
|
|
335
|
-
|
|
335
|
+
| Type Parameter | Default type |
|
|
336
|
+
| ------ | ------ |
|
|
337
|
+
| `DBTypes` *extends* `unknown` | `unknown` |
|
|
336
338
|
|
|
337
339
|
## Parameters
|
|
338
340
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
`IDBPDatabase`\<`DBTypes`\>
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
`StoreNames`\<`DBTypes`\>
|
|
346
|
-
|
|
347
|
-
### indexes
|
|
348
|
-
|
|
349
|
-
[`IndexDescription`](#../type-aliases/IndexDescription)[]
|
|
350
|
-
|
|
351
|
-
### logger?
|
|
352
|
-
|
|
353
|
-
`Logger`
|
|
341
|
+
| Parameter | Type | Description |
|
|
342
|
+
| ------ | ------ | ------ |
|
|
343
|
+
| `db` | `IDBPDatabase`\<`DBTypes`\> | The IndexedDB database instance (during upgrade) |
|
|
344
|
+
| `storeName` | `StoreNames`\<`DBTypes`\> | The name of the store to create |
|
|
345
|
+
| `indexes` | [`IndexDescription`](#../type-aliases/IndexDescription)[] | The index descriptions to create on the store |
|
|
346
|
+
| `logger?` | `Logger` | Optional logger for diagnostics |
|
|
354
347
|
|
|
355
348
|
## Returns
|
|
356
349
|
|
|
@@ -364,35 +357,35 @@ function createStoreDuringUpgrade<DBTypes>(
|
|
|
364
357
|
|
|
365
358
|
```ts
|
|
366
359
|
function getExistingIndexes<T>(
|
|
367
|
-
db
|
|
368
|
-
|
|
369
|
-
|
|
360
|
+
db:
|
|
361
|
+
| string
|
|
362
|
+
| IDBPDatabase<ObjectStore<T>>,
|
|
363
|
+
storeName: StoreNames<ObjectStore<T>>,
|
|
364
|
+
logger?: Logger): Promise<IndexDescription[] | null>;
|
|
370
365
|
```
|
|
371
366
|
|
|
372
|
-
|
|
367
|
+
Retrieves the existing index descriptions for a store. Accepts either a database instance or a database name.
|
|
373
368
|
|
|
374
|
-
|
|
369
|
+
## Type Parameters
|
|
375
370
|
|
|
376
|
-
|
|
371
|
+
| Type Parameter | Default type |
|
|
372
|
+
| ------ | ------ |
|
|
373
|
+
| `T` *extends* `object` | `object` |
|
|
377
374
|
|
|
378
375
|
## Parameters
|
|
379
376
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
`
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
`StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
|
|
387
|
-
|
|
388
|
-
### logger?
|
|
389
|
-
|
|
390
|
-
`Logger`
|
|
377
|
+
| Parameter | Type | Description |
|
|
378
|
+
| ------ | ------ | ------ |
|
|
379
|
+
| `db` | \| `string` \| `IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\> | The IndexedDB database instance or database name |
|
|
380
|
+
| `storeName` | `StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\> | The name of the store to inspect |
|
|
381
|
+
| `logger?` | `Logger` | Optional logger for diagnostics |
|
|
391
382
|
|
|
392
383
|
## Returns
|
|
393
384
|
|
|
394
385
|
`Promise`\<[`IndexDescription`](#../type-aliases/IndexDescription)[] \| `null`\>
|
|
395
386
|
|
|
387
|
+
An array of index descriptions, or null if the store does not exist
|
|
388
|
+
|
|
396
389
|
### <a id="withDb"></a>withDb
|
|
397
390
|
|
|
398
391
|
[**@xylabs/indexed-db**](#../README)
|
|
@@ -401,49 +394,39 @@ logger?): Promise<IndexDescription[] | null>;
|
|
|
401
394
|
|
|
402
395
|
```ts
|
|
403
396
|
function withDb<DBTypes, R>(
|
|
404
|
-
dbName,
|
|
405
|
-
callback
|
|
406
|
-
expectedIndexes
|
|
407
|
-
logger
|
|
408
|
-
lock
|
|
397
|
+
dbName: string,
|
|
398
|
+
callback: (db: IDBPDatabase<DBTypes>) => R | Promise<R>,
|
|
399
|
+
expectedIndexes?: Record<string, IndexDescription[]>,
|
|
400
|
+
logger?: Logger,
|
|
401
|
+
lock?: boolean): Promise<R>;
|
|
409
402
|
```
|
|
410
403
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
### DBTypes
|
|
414
|
-
|
|
415
|
-
`DBTypes` *extends* `unknown` = `unknown`
|
|
404
|
+
Opens an IndexedDB database, automatically upgrading if needed, and passes it to the callback.
|
|
405
|
+
Uses a mutex to serialize access to the same database by default.
|
|
416
406
|
|
|
417
|
-
|
|
407
|
+
## Type Parameters
|
|
418
408
|
|
|
419
|
-
|
|
409
|
+
| Type Parameter | Default type |
|
|
410
|
+
| ------ | ------ |
|
|
411
|
+
| `DBTypes` *extends* `unknown` | `unknown` |
|
|
412
|
+
| `R` | `object` |
|
|
420
413
|
|
|
421
414
|
## Parameters
|
|
422
415
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
`string`
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
### expectedIndexes?
|
|
432
|
-
|
|
433
|
-
`Record`\<`string`, [`IndexDescription`](#../type-aliases/IndexDescription)[]\>
|
|
434
|
-
|
|
435
|
-
### logger?
|
|
436
|
-
|
|
437
|
-
`Logger`
|
|
438
|
-
|
|
439
|
-
### lock?
|
|
440
|
-
|
|
441
|
-
`boolean` = `true`
|
|
416
|
+
| Parameter | Type | Default value | Description |
|
|
417
|
+
| ------ | ------ | ------ | ------ |
|
|
418
|
+
| `dbName` | `string` | `undefined` | The name of the database to open |
|
|
419
|
+
| `callback` | (`db`: `IDBPDatabase`\<`DBTypes`\>) => `R` \| `Promise`\<`R`\> | `undefined` | Function to execute with the opened database |
|
|
420
|
+
| `expectedIndexes?` | `Record`\<`string`, [`IndexDescription`](#../type-aliases/IndexDescription)[]\> | `undefined` | Optional map of store names to their expected indexes (triggers upgrade check) |
|
|
421
|
+
| `logger?` | `Logger` | `undefined` | Optional logger for diagnostics |
|
|
422
|
+
| `lock?` | `boolean` | `true` | Whether to use a mutex to serialize access (defaults to true) |
|
|
442
423
|
|
|
443
424
|
## Returns
|
|
444
425
|
|
|
445
426
|
`Promise`\<`R`\>
|
|
446
427
|
|
|
428
|
+
The result of the callback
|
|
429
|
+
|
|
447
430
|
### <a id="withDbByVersion"></a>withDbByVersion
|
|
448
431
|
|
|
449
432
|
[**@xylabs/indexed-db**](#../README)
|
|
@@ -452,54 +435,41 @@ lock?): Promise<R>;
|
|
|
452
435
|
|
|
453
436
|
```ts
|
|
454
437
|
function withDbByVersion<DBTypes, R>(
|
|
455
|
-
dbName,
|
|
456
|
-
callback
|
|
457
|
-
version
|
|
458
|
-
expectedIndexes
|
|
459
|
-
logger
|
|
460
|
-
lock
|
|
438
|
+
dbName: string,
|
|
439
|
+
callback: (db: IDBPDatabase<DBTypes>) => R | Promise<R>,
|
|
440
|
+
version?: number,
|
|
441
|
+
expectedIndexes?: Record<string, IndexDescription[]>,
|
|
442
|
+
logger?: Logger,
|
|
443
|
+
lock?: boolean): Promise<R>;
|
|
461
444
|
```
|
|
462
445
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
### DBTypes
|
|
446
|
+
Opens an IndexedDB database at a specific version, handling upgrade events, and passes it to the callback.
|
|
447
|
+
The database is automatically closed after the callback completes.
|
|
466
448
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
### R
|
|
449
|
+
## Type Parameters
|
|
470
450
|
|
|
471
|
-
|
|
451
|
+
| Type Parameter | Default type |
|
|
452
|
+
| ------ | ------ |
|
|
453
|
+
| `DBTypes` *extends* `unknown` | `unknown` |
|
|
454
|
+
| `R` | `object` |
|
|
472
455
|
|
|
473
456
|
## Parameters
|
|
474
457
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
`string`
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
### version?
|
|
484
|
-
|
|
485
|
-
`number`
|
|
486
|
-
|
|
487
|
-
### expectedIndexes?
|
|
488
|
-
|
|
489
|
-
`Record`\<`string`, [`IndexDescription`](#../type-aliases/IndexDescription)[]\>
|
|
490
|
-
|
|
491
|
-
### logger?
|
|
492
|
-
|
|
493
|
-
`Logger`
|
|
494
|
-
|
|
495
|
-
### lock?
|
|
496
|
-
|
|
497
|
-
`boolean` = `true`
|
|
458
|
+
| Parameter | Type | Default value | Description |
|
|
459
|
+
| ------ | ------ | ------ | ------ |
|
|
460
|
+
| `dbName` | `string` | `undefined` | The name of the database to open |
|
|
461
|
+
| `callback` | (`db`: `IDBPDatabase`\<`DBTypes`\>) => `R` \| `Promise`\<`R`\> | `undefined` | Function to execute with the opened database |
|
|
462
|
+
| `version?` | `number` | `undefined` | Optional specific version to open (undefined for latest) |
|
|
463
|
+
| `expectedIndexes?` | `Record`\<`string`, [`IndexDescription`](#../type-aliases/IndexDescription)[]\> | `undefined` | Optional map of store names to indexes to create during upgrade |
|
|
464
|
+
| `logger?` | `Logger` | `undefined` | Optional logger for diagnostics |
|
|
465
|
+
| `lock?` | `boolean` | `true` | Whether to use a mutex to serialize access (defaults to true) |
|
|
498
466
|
|
|
499
467
|
## Returns
|
|
500
468
|
|
|
501
469
|
`Promise`\<`R`\>
|
|
502
470
|
|
|
471
|
+
The result of the callback
|
|
472
|
+
|
|
503
473
|
### <a id="withReadOnlyStore"></a>withReadOnlyStore
|
|
504
474
|
|
|
505
475
|
[**@xylabs/indexed-db**](#../README)
|
|
@@ -508,44 +478,38 @@ lock?): Promise<R>;
|
|
|
508
478
|
|
|
509
479
|
```ts
|
|
510
480
|
function withReadOnlyStore<T, R>(
|
|
511
|
-
db
|
|
512
|
-
storeName
|
|
513
|
-
callback
|
|
514
|
-
|
|
481
|
+
db: IDBPDatabase<ObjectStore<T>>,
|
|
482
|
+
storeName: StoreNames<ObjectStore<T>>,
|
|
483
|
+
callback: (store:
|
|
484
|
+
| IDBPObjectStore<ObjectStore<T>, [StoreNames<ObjectStore<T>>], StoreNames<ObjectStore<T>>, "readonly">
|
|
485
|
+
| null) => R | Promise<R>,
|
|
486
|
+
logger?: Logger): Promise<R>;
|
|
515
487
|
```
|
|
516
488
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
### T
|
|
489
|
+
Opens a read-only transaction on the specified store and passes it to the callback.
|
|
520
490
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
### R
|
|
491
|
+
## Type Parameters
|
|
524
492
|
|
|
525
|
-
|
|
493
|
+
| Type Parameter | Default type |
|
|
494
|
+
| ------ | ------ |
|
|
495
|
+
| `T` *extends* `object` | `object` |
|
|
496
|
+
| `R` | `T` |
|
|
526
497
|
|
|
527
498
|
## Parameters
|
|
528
499
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
`IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
`StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
|
|
536
|
-
|
|
537
|
-
### callback
|
|
538
|
-
|
|
539
|
-
(`store`) => `R` \| `Promise`\<`R`\>
|
|
540
|
-
|
|
541
|
-
### logger?
|
|
542
|
-
|
|
543
|
-
`Logger`
|
|
500
|
+
| Parameter | Type | Description |
|
|
501
|
+
| ------ | ------ | ------ |
|
|
502
|
+
| `db` | `IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\> | The IndexedDB database instance |
|
|
503
|
+
| `storeName` | `StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\> | The name of the object store to open |
|
|
504
|
+
| `callback` | (`store`: \| `IDBPObjectStore`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>, \[`StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>\], `StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>, `"readonly"`\> \| `null`) => `R` \| `Promise`\<`R`\> | Function to execute with the read-only store |
|
|
505
|
+
| `logger?` | `Logger` | Optional logger for diagnostics |
|
|
544
506
|
|
|
545
507
|
## Returns
|
|
546
508
|
|
|
547
509
|
`Promise`\<`R`\>
|
|
548
510
|
|
|
511
|
+
The result of the callback
|
|
512
|
+
|
|
549
513
|
### <a id="withReadWriteStore"></a>withReadWriteStore
|
|
550
514
|
|
|
551
515
|
[**@xylabs/indexed-db**](#../README)
|
|
@@ -554,44 +518,38 @@ logger?): Promise<R>;
|
|
|
554
518
|
|
|
555
519
|
```ts
|
|
556
520
|
function withReadWriteStore<T, R>(
|
|
557
|
-
db
|
|
558
|
-
storeName
|
|
559
|
-
callback
|
|
560
|
-
|
|
521
|
+
db: IDBPDatabase<ObjectStore<T>>,
|
|
522
|
+
storeName: StoreNames<ObjectStore<T>>,
|
|
523
|
+
callback: (store:
|
|
524
|
+
| IDBPObjectStore<ObjectStore<T>, [StoreNames<ObjectStore<T>>], StoreNames<ObjectStore<T>>, "readwrite">
|
|
525
|
+
| null) => R | Promise<R>,
|
|
526
|
+
logger?: Logger): Promise<R>;
|
|
561
527
|
```
|
|
562
528
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
### T
|
|
529
|
+
Opens a read-write transaction on the specified store and passes it to the callback.
|
|
566
530
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
### R
|
|
531
|
+
## Type Parameters
|
|
570
532
|
|
|
571
|
-
|
|
533
|
+
| Type Parameter | Default type |
|
|
534
|
+
| ------ | ------ |
|
|
535
|
+
| `T` *extends* `object` | `object` |
|
|
536
|
+
| `R` | `T` |
|
|
572
537
|
|
|
573
538
|
## Parameters
|
|
574
539
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
`IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
`StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
|
|
582
|
-
|
|
583
|
-
### callback
|
|
584
|
-
|
|
585
|
-
(`store`) => `R` \| `Promise`\<`R`\>
|
|
586
|
-
|
|
587
|
-
### logger?
|
|
588
|
-
|
|
589
|
-
`Logger`
|
|
540
|
+
| Parameter | Type | Description |
|
|
541
|
+
| ------ | ------ | ------ |
|
|
542
|
+
| `db` | `IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\> | The IndexedDB database instance |
|
|
543
|
+
| `storeName` | `StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\> | The name of the object store to open |
|
|
544
|
+
| `callback` | (`store`: \| `IDBPObjectStore`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>, \[`StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>\], `StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>, `"readwrite"`\> \| `null`) => `R` \| `Promise`\<`R`\> | Function to execute with the read-write store |
|
|
545
|
+
| `logger?` | `Logger` | Optional logger for diagnostics |
|
|
590
546
|
|
|
591
547
|
## Returns
|
|
592
548
|
|
|
593
549
|
`Promise`\<`R`\>
|
|
594
550
|
|
|
551
|
+
The result of the callback
|
|
552
|
+
|
|
595
553
|
### <a id="withStore"></a>withStore
|
|
596
554
|
|
|
597
555
|
[**@xylabs/indexed-db**](#../README)
|
|
@@ -600,53 +558,42 @@ logger?): Promise<R>;
|
|
|
600
558
|
|
|
601
559
|
```ts
|
|
602
560
|
function withStore<T, R, M>(
|
|
603
|
-
db
|
|
604
|
-
storeName
|
|
605
|
-
callback
|
|
606
|
-
|
|
607
|
-
|
|
561
|
+
db: IDBPDatabase<ObjectStore<T>>,
|
|
562
|
+
storeName: StoreNames<ObjectStore<T>>,
|
|
563
|
+
callback: (store:
|
|
564
|
+
| IDBPObjectStore<ObjectStore<T>, [StoreNames<ObjectStore<T>>], StoreNames<ObjectStore<T>>, M>
|
|
565
|
+
| null) => R | Promise<R>,
|
|
566
|
+
mode: M,
|
|
567
|
+
logger?: Logger): Promise<R>;
|
|
608
568
|
```
|
|
609
569
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
### T
|
|
613
|
-
|
|
614
|
-
`T` *extends* `object` = `object`
|
|
615
|
-
|
|
616
|
-
### R
|
|
570
|
+
Opens a transaction on the specified store with the given mode and passes the store to the callback.
|
|
571
|
+
If the store does not exist, the callback receives null.
|
|
617
572
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
### M
|
|
573
|
+
## Type Parameters
|
|
621
574
|
|
|
622
|
-
|
|
575
|
+
| Type Parameter | Default type |
|
|
576
|
+
| ------ | ------ |
|
|
577
|
+
| `T` *extends* `object` | `object` |
|
|
578
|
+
| `R` | `T` |
|
|
579
|
+
| `M` *extends* `"readonly"` \| `"readwrite"` | `"readonly"` |
|
|
623
580
|
|
|
624
581
|
## Parameters
|
|
625
582
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
`IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
`
|
|
633
|
-
|
|
634
|
-
### callback
|
|
635
|
-
|
|
636
|
-
(`store`) => `R` \| `Promise`\<`R`\>
|
|
637
|
-
|
|
638
|
-
### mode
|
|
639
|
-
|
|
640
|
-
`M`
|
|
641
|
-
|
|
642
|
-
### logger?
|
|
643
|
-
|
|
644
|
-
`Logger`
|
|
583
|
+
| Parameter | Type | Description |
|
|
584
|
+
| ------ | ------ | ------ |
|
|
585
|
+
| `db` | `IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\> | The IndexedDB database instance |
|
|
586
|
+
| `storeName` | `StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\> | The name of the object store to open |
|
|
587
|
+
| `callback` | (`store`: \| `IDBPObjectStore`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>, \[`StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>\], `StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>, `M`\> \| `null`) => `R` \| `Promise`\<`R`\> | Function to execute with the store (or null if it doesn't exist) |
|
|
588
|
+
| `mode` | `M` | The transaction mode ('readonly' or 'readwrite') |
|
|
589
|
+
| `logger?` | `Logger` | Optional logger for diagnostics |
|
|
645
590
|
|
|
646
591
|
## Returns
|
|
647
592
|
|
|
648
593
|
`Promise`\<`R`\>
|
|
649
594
|
|
|
595
|
+
The result of the callback
|
|
596
|
+
|
|
650
597
|
### interfaces
|
|
651
598
|
|
|
652
599
|
### <a id="ObjectStore"></a>ObjectStore
|
|
@@ -655,11 +602,13 @@ logger?): Promise<R>;
|
|
|
655
602
|
|
|
656
603
|
***
|
|
657
604
|
|
|
658
|
-
|
|
605
|
+
Generic IndexedDB schema type that maps store names to their value types.
|
|
659
606
|
|
|
660
|
-
|
|
607
|
+
## Type Parameters
|
|
661
608
|
|
|
662
|
-
|
|
609
|
+
| Type Parameter | Default type |
|
|
610
|
+
| ------ | ------ |
|
|
611
|
+
| `T` *extends* `EmptyObject` | `EmptyObject` |
|
|
663
612
|
|
|
664
613
|
## Indexable
|
|
665
614
|
|
|
@@ -676,40 +625,22 @@ logger?): Promise<R>;
|
|
|
676
625
|
***
|
|
677
626
|
|
|
678
627
|
```ts
|
|
679
|
-
type IndexDescription =
|
|
628
|
+
type IndexDescription = {
|
|
629
|
+
key: Record<string, IndexDirection>;
|
|
630
|
+
multiEntry?: boolean;
|
|
631
|
+
unique?: boolean;
|
|
632
|
+
};
|
|
680
633
|
```
|
|
681
634
|
|
|
682
635
|
Description of index(es) to be created on a store
|
|
683
636
|
|
|
684
637
|
## Properties
|
|
685
638
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
The key(s) to index
|
|
693
|
-
|
|
694
|
-
***
|
|
695
|
-
|
|
696
|
-
### multiEntry?
|
|
697
|
-
|
|
698
|
-
```ts
|
|
699
|
-
optional multiEntry: boolean;
|
|
700
|
-
```
|
|
701
|
-
|
|
702
|
-
Is the indexed value an array
|
|
703
|
-
|
|
704
|
-
***
|
|
705
|
-
|
|
706
|
-
### unique?
|
|
707
|
-
|
|
708
|
-
```ts
|
|
709
|
-
optional unique: boolean;
|
|
710
|
-
```
|
|
711
|
-
|
|
712
|
-
If true, the index must enforce uniqueness on the key
|
|
639
|
+
| Property | Type | Description |
|
|
640
|
+
| ------ | ------ | ------ |
|
|
641
|
+
| <a id="key"></a> `key` | `Record`\<`string`, [`IndexDirection`](#IndexDirection)\> | The key(s) to index |
|
|
642
|
+
| <a id="multientry"></a> `multiEntry?` | `boolean` | Is the indexed value an array |
|
|
643
|
+
| <a id="unique"></a> `unique?` | `boolean` | If true, the index must enforce uniqueness on the key |
|
|
713
644
|
|
|
714
645
|
### <a id="IndexDirection"></a>IndexDirection
|
|
715
646
|
|
|
@@ -735,6 +666,8 @@ The index direction (1 for ascending, -1 for descending)
|
|
|
735
666
|
const IndexSeparator: "-" = '-';
|
|
736
667
|
```
|
|
737
668
|
|
|
669
|
+
Separator used between key names when building standard index names.
|
|
670
|
+
|
|
738
671
|
|
|
739
672
|
Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
|
|
740
673
|
|