@xylabs/indexed-db 5.0.95 → 5.0.96
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 +424 -273
- package/dist/browser/IndexDescription.d.ts +2 -2
- package/dist/browser/IndexDescription.d.ts.map +1 -1
- package/dist/browser/ObjectStore.d.ts +1 -3
- package/dist/browser/ObjectStore.d.ts.map +1 -1
- package/dist/browser/index.mjs.map +1 -1
- package/dist/neutral/IndexDescription.d.ts +2 -2
- package/dist/neutral/IndexDescription.d.ts.map +1 -1
- package/dist/neutral/ObjectStore.d.ts +1 -3
- package/dist/neutral/ObjectStore.d.ts.map +1 -1
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/node/IndexDescription.d.ts +2 -2
- package/dist/node/IndexDescription.d.ts.map +1 -1
- package/dist/node/ObjectStore.d.ts +1 -3
- package/dist/node/ObjectStore.d.ts.map +1 -1
- package/dist/node/index.mjs.map +1 -1
- package/package.json +15 -15
package/README.md
CHANGED
|
@@ -1,70 +1,52 @@
|
|
|
1
1
|
# @xylabs/indexed-db
|
|
2
2
|
|
|
3
|
-
[![
|
|
3
|
+
[![npm][npm-badge]][npm-link]
|
|
4
|
+
[![license][license-badge]][license-link]
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
[![npm-badge][]][npm-link]
|
|
7
|
-
[![npm-downloads-badge][]][npm-link]
|
|
8
|
-
[![jsdelivr-badge][]][jsdelivr-link]
|
|
9
|
-
[![npm-license-badge][]](LICENSE)
|
|
10
|
-
[![codacy-badge][]][codacy-link]
|
|
11
|
-
[![codeclimate-badge][]][codeclimate-link]
|
|
12
|
-
[![snyk-badge][]][snyk-link]
|
|
13
|
-
[![socket-badge][]][socket-link]
|
|
6
|
+
> Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
14
7
|
|
|
8
|
+
## Install
|
|
15
9
|
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
Using npm:
|
|
18
11
|
|
|
12
|
+
```sh
|
|
13
|
+
npm install {{name}}
|
|
14
|
+
```
|
|
19
15
|
|
|
20
|
-
|
|
16
|
+
Using yarn:
|
|
21
17
|
|
|
22
|
-
|
|
18
|
+
```sh
|
|
19
|
+
yarn add {{name}}
|
|
20
|
+
```
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
Using pnpm:
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
```sh
|
|
25
|
+
pnpm add {{name}}
|
|
26
|
+
```
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
| ------ | ------ |
|
|
30
|
-
| [IndexedDbKeyValueStore](#classes/IndexedDbKeyValueStore) | An IndexedDB key/value store. |
|
|
28
|
+
Using bun:
|
|
31
29
|
|
|
32
|
-
|
|
30
|
+
```sh
|
|
31
|
+
bun add {{name}}
|
|
32
|
+
```
|
|
33
33
|
|
|
34
|
-
| Interface | Description |
|
|
35
|
-
| ------ | ------ |
|
|
36
|
-
| [ObjectStore](#interfaces/ObjectStore) | Generic IndexedDB schema type that maps store names to their value types. |
|
|
37
34
|
|
|
38
|
-
##
|
|
35
|
+
## License
|
|
39
36
|
|
|
40
|
-
|
|
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 |
|
|
37
|
+
See the [LICENSE](LICENSE) file for license rights and limitations (LGPL-3.0-only).
|
|
44
38
|
|
|
45
|
-
##
|
|
39
|
+
## Reference
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
| ------ | ------ |
|
|
49
|
-
| [IndexSeparator](#variables/IndexSeparator) | Separator used between key names when building standard index names. |
|
|
41
|
+
### packages
|
|
50
42
|
|
|
51
|
-
|
|
43
|
+
### indexed-db
|
|
52
44
|
|
|
53
|
-
|
|
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. |
|
|
45
|
+
### .temp-typedoc
|
|
64
46
|
|
|
65
|
-
### classes
|
|
47
|
+
### classes
|
|
66
48
|
|
|
67
|
-
|
|
49
|
+
### <a id="IndexedDbKeyValueStore"></a>IndexedDbKeyValueStore
|
|
68
50
|
|
|
69
51
|
[**@xylabs/indexed-db**](#../README)
|
|
70
52
|
|
|
@@ -74,10 +56,13 @@ An IndexedDB key/value store.
|
|
|
74
56
|
|
|
75
57
|
## Type Parameters
|
|
76
58
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
59
|
+
### T
|
|
60
|
+
|
|
61
|
+
`T` *extends* `DBSchema`
|
|
62
|
+
|
|
63
|
+
### S
|
|
64
|
+
|
|
65
|
+
`S` *extends* `StoreNames`\<`T`\>
|
|
81
66
|
|
|
82
67
|
## Implements
|
|
83
68
|
|
|
@@ -88,15 +73,18 @@ An IndexedDB key/value store.
|
|
|
88
73
|
### Constructor
|
|
89
74
|
|
|
90
75
|
```ts
|
|
91
|
-
new IndexedDbKeyValueStore<T, S>(dbName
|
|
76
|
+
new IndexedDbKeyValueStore<T, S>(dbName, storeName): IndexedDbKeyValueStore<T, S>;
|
|
92
77
|
```
|
|
93
78
|
|
|
94
79
|
### Parameters
|
|
95
80
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
81
|
+
#### dbName
|
|
82
|
+
|
|
83
|
+
`string`
|
|
84
|
+
|
|
85
|
+
#### storeName
|
|
86
|
+
|
|
87
|
+
`S`
|
|
100
88
|
|
|
101
89
|
### Returns
|
|
102
90
|
|
|
@@ -104,10 +92,23 @@ new IndexedDbKeyValueStore<T, S>(dbName: string, storeName: S): IndexedDbKeyValu
|
|
|
104
92
|
|
|
105
93
|
## Properties
|
|
106
94
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
95
|
+
### dbName
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
readonly dbName: string;
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The name of the IndexedDB database.
|
|
102
|
+
|
|
103
|
+
***
|
|
104
|
+
|
|
105
|
+
### storeName
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
readonly storeName: S;
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The name of the object store within the database.
|
|
111
112
|
|
|
112
113
|
## Methods
|
|
113
114
|
|
|
@@ -134,16 +135,18 @@ KeyValueStore.clear
|
|
|
134
135
|
### delete()
|
|
135
136
|
|
|
136
137
|
```ts
|
|
137
|
-
delete(key
|
|
138
|
+
delete(key): Promise<void>;
|
|
138
139
|
```
|
|
139
140
|
|
|
140
141
|
Deletes the entry with the given key.
|
|
141
142
|
|
|
142
143
|
### Parameters
|
|
143
144
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
#### key
|
|
146
|
+
|
|
147
|
+
`StoreKey`\<`T`, `S`\>
|
|
148
|
+
|
|
149
|
+
The key of the entry to delete
|
|
147
150
|
|
|
148
151
|
### Returns
|
|
149
152
|
|
|
@@ -160,16 +163,18 @@ KeyValueStore.delete
|
|
|
160
163
|
### get()
|
|
161
164
|
|
|
162
165
|
```ts
|
|
163
|
-
get(key
|
|
166
|
+
get(key): Promise<StoreValue<T, S> | undefined>;
|
|
164
167
|
```
|
|
165
168
|
|
|
166
169
|
Retrieves the value associated with the given key.
|
|
167
170
|
|
|
168
171
|
### Parameters
|
|
169
172
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
+
#### key
|
|
174
|
+
|
|
175
|
+
`StoreKey`\<`T`, `S`\>
|
|
176
|
+
|
|
177
|
+
The key to look up
|
|
173
178
|
|
|
174
179
|
### Returns
|
|
175
180
|
|
|
@@ -208,17 +213,24 @@ KeyValueStore.keys
|
|
|
208
213
|
### set()
|
|
209
214
|
|
|
210
215
|
```ts
|
|
211
|
-
set(key
|
|
216
|
+
set(key, value): Promise<void>;
|
|
212
217
|
```
|
|
213
218
|
|
|
214
219
|
Sets a value for the given key, creating or updating the entry.
|
|
215
220
|
|
|
216
221
|
### Parameters
|
|
217
222
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
223
|
+
#### key
|
|
224
|
+
|
|
225
|
+
`StoreKey`\<`T`, `S`\>
|
|
226
|
+
|
|
227
|
+
The key to set
|
|
228
|
+
|
|
229
|
+
#### value
|
|
230
|
+
|
|
231
|
+
`StoreValue`\<`T`, `S`\>
|
|
232
|
+
|
|
233
|
+
The value to store
|
|
222
234
|
|
|
223
235
|
### Returns
|
|
224
236
|
|
|
@@ -235,22 +247,24 @@ KeyValueStore.set
|
|
|
235
247
|
### withDb()
|
|
236
248
|
|
|
237
249
|
```ts
|
|
238
|
-
withDb<R>(callback
|
|
250
|
+
withDb<R>(callback): Promise<R>;
|
|
239
251
|
```
|
|
240
252
|
|
|
241
253
|
Opens the underlying IndexedDB database and passes it to the callback.
|
|
242
254
|
|
|
243
255
|
### Type Parameters
|
|
244
256
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
257
|
+
#### R
|
|
258
|
+
|
|
259
|
+
`R` = `StoreValue`\<`T`, `S`\>
|
|
248
260
|
|
|
249
261
|
### Parameters
|
|
250
262
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
263
|
+
#### callback
|
|
264
|
+
|
|
265
|
+
(`db`) => `R` \| `Promise`\<`R`\>
|
|
266
|
+
|
|
267
|
+
Function to execute with the database
|
|
254
268
|
|
|
255
269
|
### Returns
|
|
256
270
|
|
|
@@ -258,16 +272,16 @@ Opens the underlying IndexedDB database and passes it to the callback.
|
|
|
258
272
|
|
|
259
273
|
The result of the callback
|
|
260
274
|
|
|
261
|
-
### functions
|
|
275
|
+
### functions
|
|
262
276
|
|
|
263
|
-
|
|
277
|
+
### <a id="buildStandardIndexName"></a>buildStandardIndexName
|
|
264
278
|
|
|
265
279
|
[**@xylabs/indexed-db**](#../README)
|
|
266
280
|
|
|
267
281
|
***
|
|
268
282
|
|
|
269
283
|
```ts
|
|
270
|
-
function buildStandardIndexName(index
|
|
284
|
+
function buildStandardIndexName(index): string;
|
|
271
285
|
```
|
|
272
286
|
|
|
273
287
|
Given an index description, this will build the index
|
|
@@ -275,9 +289,11 @@ name in standard form
|
|
|
275
289
|
|
|
276
290
|
## Parameters
|
|
277
291
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
292
|
+
### index
|
|
293
|
+
|
|
294
|
+
[`IndexDescription`](#../interfaces/IndexDescription)
|
|
295
|
+
|
|
296
|
+
The index description
|
|
281
297
|
|
|
282
298
|
## Returns
|
|
283
299
|
|
|
@@ -285,7 +301,7 @@ name in standard form
|
|
|
285
301
|
|
|
286
302
|
The index name in standard form
|
|
287
303
|
|
|
288
|
-
|
|
304
|
+
### <a id="checkDbNeedsUpgrade"></a>checkDbNeedsUpgrade
|
|
289
305
|
|
|
290
306
|
[**@xylabs/indexed-db**](#../README)
|
|
291
307
|
|
|
@@ -293,20 +309,32 @@ The index name in standard form
|
|
|
293
309
|
|
|
294
310
|
```ts
|
|
295
311
|
function checkDbNeedsUpgrade(
|
|
296
|
-
dbName
|
|
297
|
-
stores
|
|
298
|
-
logger
|
|
312
|
+
dbName,
|
|
313
|
+
stores,
|
|
314
|
+
logger?): Promise<number>;
|
|
299
315
|
```
|
|
300
316
|
|
|
301
317
|
Checks whether any store in the database needs an upgrade and returns the appropriate version number.
|
|
302
318
|
|
|
303
319
|
## Parameters
|
|
304
320
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
321
|
+
### dbName
|
|
322
|
+
|
|
323
|
+
`string`
|
|
324
|
+
|
|
325
|
+
The name of the database to check
|
|
326
|
+
|
|
327
|
+
### stores
|
|
328
|
+
|
|
329
|
+
`Record`\<`string`, [`IndexDescription`](#../interfaces/IndexDescription)[]\>
|
|
330
|
+
|
|
331
|
+
Map of store names to their expected index descriptions
|
|
332
|
+
|
|
333
|
+
### logger?
|
|
334
|
+
|
|
335
|
+
`Logger`
|
|
336
|
+
|
|
337
|
+
Optional logger for diagnostics
|
|
310
338
|
|
|
311
339
|
## Returns
|
|
312
340
|
|
|
@@ -314,7 +342,7 @@ Checks whether any store in the database needs an upgrade and returns the approp
|
|
|
314
342
|
|
|
315
343
|
The version to open (current version + 1 if upgrade needed, otherwise current version)
|
|
316
344
|
|
|
317
|
-
|
|
345
|
+
### <a id="createStoreDuringUpgrade"></a>createStoreDuringUpgrade
|
|
318
346
|
|
|
319
347
|
[**@xylabs/indexed-db**](#../README)
|
|
320
348
|
|
|
@@ -322,34 +350,51 @@ The version to open (current version + 1 if upgrade needed, otherwise current ve
|
|
|
322
350
|
|
|
323
351
|
```ts
|
|
324
352
|
function createStoreDuringUpgrade<DBTypes>(
|
|
325
|
-
db
|
|
326
|
-
storeName
|
|
327
|
-
indexes
|
|
328
|
-
logger
|
|
353
|
+
db,
|
|
354
|
+
storeName,
|
|
355
|
+
indexes,
|
|
356
|
+
logger?): void;
|
|
329
357
|
```
|
|
330
358
|
|
|
331
359
|
Creates an object store with the specified indexes during a version upgrade transaction.
|
|
332
360
|
|
|
333
361
|
## Type Parameters
|
|
334
362
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
363
|
+
### DBTypes
|
|
364
|
+
|
|
365
|
+
`DBTypes` *extends* `unknown` = `unknown`
|
|
338
366
|
|
|
339
367
|
## Parameters
|
|
340
368
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
369
|
+
### db
|
|
370
|
+
|
|
371
|
+
`IDBPDatabase`\<`DBTypes`\>
|
|
372
|
+
|
|
373
|
+
The IndexedDB database instance (during upgrade)
|
|
374
|
+
|
|
375
|
+
### storeName
|
|
376
|
+
|
|
377
|
+
`StoreNames`\<`DBTypes`\>
|
|
378
|
+
|
|
379
|
+
The name of the store to create
|
|
380
|
+
|
|
381
|
+
### indexes
|
|
382
|
+
|
|
383
|
+
[`IndexDescription`](#../interfaces/IndexDescription)[]
|
|
384
|
+
|
|
385
|
+
The index descriptions to create on the store
|
|
386
|
+
|
|
387
|
+
### logger?
|
|
388
|
+
|
|
389
|
+
`Logger`
|
|
390
|
+
|
|
391
|
+
Optional logger for diagnostics
|
|
347
392
|
|
|
348
393
|
## Returns
|
|
349
394
|
|
|
350
395
|
`void`
|
|
351
396
|
|
|
352
|
-
|
|
397
|
+
### <a id="getExistingIndexes"></a>getExistingIndexes
|
|
353
398
|
|
|
354
399
|
[**@xylabs/indexed-db**](#../README)
|
|
355
400
|
|
|
@@ -357,36 +402,47 @@ Creates an object store with the specified indexes during a version upgrade tran
|
|
|
357
402
|
|
|
358
403
|
```ts
|
|
359
404
|
function getExistingIndexes<T>(
|
|
360
|
-
db
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
storeName: StoreNames<ObjectStore<T>>,
|
|
364
|
-
logger?: Logger): Promise<IndexDescription[] | null>;
|
|
405
|
+
db,
|
|
406
|
+
storeName,
|
|
407
|
+
logger?): Promise<IndexDescription[] | null>;
|
|
365
408
|
```
|
|
366
409
|
|
|
367
410
|
Retrieves the existing index descriptions for a store. Accepts either a database instance or a database name.
|
|
368
411
|
|
|
369
412
|
## Type Parameters
|
|
370
413
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
414
|
+
### T
|
|
415
|
+
|
|
416
|
+
`T` *extends* `object` = `object`
|
|
374
417
|
|
|
375
418
|
## Parameters
|
|
376
419
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
420
|
+
### db
|
|
421
|
+
|
|
422
|
+
\| `string`
|
|
423
|
+
\| `IDBPDatabase`\<[`ObjectStore`](#../type-aliases/ObjectStore)\<`T`\>\>
|
|
424
|
+
|
|
425
|
+
The IndexedDB database instance or database name
|
|
426
|
+
|
|
427
|
+
### storeName
|
|
428
|
+
|
|
429
|
+
`StoreNames`\<[`ObjectStore`](#../type-aliases/ObjectStore)\<`T`\>\>
|
|
430
|
+
|
|
431
|
+
The name of the store to inspect
|
|
432
|
+
|
|
433
|
+
### logger?
|
|
434
|
+
|
|
435
|
+
`Logger`
|
|
436
|
+
|
|
437
|
+
Optional logger for diagnostics
|
|
382
438
|
|
|
383
439
|
## Returns
|
|
384
440
|
|
|
385
|
-
`Promise`\<[`IndexDescription`](#../
|
|
441
|
+
`Promise`\<[`IndexDescription`](#../interfaces/IndexDescription)[] \| `null`\>
|
|
386
442
|
|
|
387
443
|
An array of index descriptions, or null if the store does not exist
|
|
388
444
|
|
|
389
|
-
|
|
445
|
+
### <a id="withDb"></a>withDb
|
|
390
446
|
|
|
391
447
|
[**@xylabs/indexed-db**](#../README)
|
|
392
448
|
|
|
@@ -394,11 +450,11 @@ An array of index descriptions, or null if the store does not exist
|
|
|
394
450
|
|
|
395
451
|
```ts
|
|
396
452
|
function withDb<DBTypes, R>(
|
|
397
|
-
dbName
|
|
398
|
-
callback
|
|
399
|
-
expectedIndexes
|
|
400
|
-
logger
|
|
401
|
-
lock
|
|
453
|
+
dbName,
|
|
454
|
+
callback,
|
|
455
|
+
expectedIndexes?,
|
|
456
|
+
logger?,
|
|
457
|
+
lock?): Promise<R>;
|
|
402
458
|
```
|
|
403
459
|
|
|
404
460
|
Opens an IndexedDB database, automatically upgrading if needed, and passes it to the callback.
|
|
@@ -406,20 +462,45 @@ Uses a mutex to serialize access to the same database by default.
|
|
|
406
462
|
|
|
407
463
|
## Type Parameters
|
|
408
464
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
465
|
+
### DBTypes
|
|
466
|
+
|
|
467
|
+
`DBTypes` *extends* `unknown` = `unknown`
|
|
468
|
+
|
|
469
|
+
### R
|
|
470
|
+
|
|
471
|
+
`R` = `object`
|
|
413
472
|
|
|
414
473
|
## Parameters
|
|
415
474
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
475
|
+
### dbName
|
|
476
|
+
|
|
477
|
+
`string`
|
|
478
|
+
|
|
479
|
+
The name of the database to open
|
|
480
|
+
|
|
481
|
+
### callback
|
|
482
|
+
|
|
483
|
+
(`db`) => `R` \| `Promise`\<`R`\>
|
|
484
|
+
|
|
485
|
+
Function to execute with the opened database
|
|
486
|
+
|
|
487
|
+
### expectedIndexes?
|
|
488
|
+
|
|
489
|
+
`Record`\<`string`, [`IndexDescription`](#../interfaces/IndexDescription)[]\>
|
|
490
|
+
|
|
491
|
+
Optional map of store names to their expected indexes (triggers upgrade check)
|
|
492
|
+
|
|
493
|
+
### logger?
|
|
494
|
+
|
|
495
|
+
`Logger`
|
|
496
|
+
|
|
497
|
+
Optional logger for diagnostics
|
|
498
|
+
|
|
499
|
+
### lock?
|
|
500
|
+
|
|
501
|
+
`boolean` = `true`
|
|
502
|
+
|
|
503
|
+
Whether to use a mutex to serialize access (defaults to true)
|
|
423
504
|
|
|
424
505
|
## Returns
|
|
425
506
|
|
|
@@ -427,7 +508,7 @@ Uses a mutex to serialize access to the same database by default.
|
|
|
427
508
|
|
|
428
509
|
The result of the callback
|
|
429
510
|
|
|
430
|
-
|
|
511
|
+
### <a id="withDbByVersion"></a>withDbByVersion
|
|
431
512
|
|
|
432
513
|
[**@xylabs/indexed-db**](#../README)
|
|
433
514
|
|
|
@@ -435,12 +516,12 @@ The result of the callback
|
|
|
435
516
|
|
|
436
517
|
```ts
|
|
437
518
|
function withDbByVersion<DBTypes, R>(
|
|
438
|
-
dbName
|
|
439
|
-
callback
|
|
440
|
-
version
|
|
441
|
-
expectedIndexes
|
|
442
|
-
logger
|
|
443
|
-
lock
|
|
519
|
+
dbName,
|
|
520
|
+
callback,
|
|
521
|
+
version?,
|
|
522
|
+
expectedIndexes?,
|
|
523
|
+
logger?,
|
|
524
|
+
lock?): Promise<R>;
|
|
444
525
|
```
|
|
445
526
|
|
|
446
527
|
Opens an IndexedDB database at a specific version, handling upgrade events, and passes it to the callback.
|
|
@@ -448,21 +529,51 @@ The database is automatically closed after the callback completes.
|
|
|
448
529
|
|
|
449
530
|
## Type Parameters
|
|
450
531
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
532
|
+
### DBTypes
|
|
533
|
+
|
|
534
|
+
`DBTypes` *extends* `unknown` = `unknown`
|
|
535
|
+
|
|
536
|
+
### R
|
|
537
|
+
|
|
538
|
+
`R` = `object`
|
|
455
539
|
|
|
456
540
|
## Parameters
|
|
457
541
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
542
|
+
### dbName
|
|
543
|
+
|
|
544
|
+
`string`
|
|
545
|
+
|
|
546
|
+
The name of the database to open
|
|
547
|
+
|
|
548
|
+
### callback
|
|
549
|
+
|
|
550
|
+
(`db`) => `R` \| `Promise`\<`R`\>
|
|
551
|
+
|
|
552
|
+
Function to execute with the opened database
|
|
553
|
+
|
|
554
|
+
### version?
|
|
555
|
+
|
|
556
|
+
`number`
|
|
557
|
+
|
|
558
|
+
Optional specific version to open (undefined for latest)
|
|
559
|
+
|
|
560
|
+
### expectedIndexes?
|
|
561
|
+
|
|
562
|
+
`Record`\<`string`, [`IndexDescription`](#../interfaces/IndexDescription)[]\>
|
|
563
|
+
|
|
564
|
+
Optional map of store names to indexes to create during upgrade
|
|
565
|
+
|
|
566
|
+
### logger?
|
|
567
|
+
|
|
568
|
+
`Logger`
|
|
569
|
+
|
|
570
|
+
Optional logger for diagnostics
|
|
571
|
+
|
|
572
|
+
### lock?
|
|
573
|
+
|
|
574
|
+
`boolean` = `true`
|
|
575
|
+
|
|
576
|
+
Whether to use a mutex to serialize access (defaults to true)
|
|
466
577
|
|
|
467
578
|
## Returns
|
|
468
579
|
|
|
@@ -470,7 +581,7 @@ The database is automatically closed after the callback completes.
|
|
|
470
581
|
|
|
471
582
|
The result of the callback
|
|
472
583
|
|
|
473
|
-
|
|
584
|
+
### <a id="withReadOnlyStore"></a>withReadOnlyStore
|
|
474
585
|
|
|
475
586
|
[**@xylabs/indexed-db**](#../README)
|
|
476
587
|
|
|
@@ -478,31 +589,49 @@ The result of the callback
|
|
|
478
589
|
|
|
479
590
|
```ts
|
|
480
591
|
function withReadOnlyStore<T, R>(
|
|
481
|
-
db
|
|
482
|
-
storeName
|
|
483
|
-
callback
|
|
484
|
-
|
|
485
|
-
| null) => R | Promise<R>,
|
|
486
|
-
logger?: Logger): Promise<R>;
|
|
592
|
+
db,
|
|
593
|
+
storeName,
|
|
594
|
+
callback,
|
|
595
|
+
logger?): Promise<R>;
|
|
487
596
|
```
|
|
488
597
|
|
|
489
598
|
Opens a read-only transaction on the specified store and passes it to the callback.
|
|
490
599
|
|
|
491
600
|
## Type Parameters
|
|
492
601
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
602
|
+
### T
|
|
603
|
+
|
|
604
|
+
`T` *extends* `object` = `object`
|
|
605
|
+
|
|
606
|
+
### R
|
|
607
|
+
|
|
608
|
+
`R` = `T`
|
|
497
609
|
|
|
498
610
|
## Parameters
|
|
499
611
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
612
|
+
### db
|
|
613
|
+
|
|
614
|
+
`IDBPDatabase`\<[`ObjectStore`](#../type-aliases/ObjectStore)\<`T`\>\>
|
|
615
|
+
|
|
616
|
+
The IndexedDB database instance
|
|
617
|
+
|
|
618
|
+
### storeName
|
|
619
|
+
|
|
620
|
+
`StoreNames`\<[`ObjectStore`](#../type-aliases/ObjectStore)\<`T`\>\>
|
|
621
|
+
|
|
622
|
+
The name of the object store to open
|
|
623
|
+
|
|
624
|
+
### callback
|
|
625
|
+
|
|
626
|
+
(`store`) => `R` \| `Promise`\<`R`\>
|
|
627
|
+
|
|
628
|
+
Function to execute with the read-only store
|
|
629
|
+
|
|
630
|
+
### logger?
|
|
631
|
+
|
|
632
|
+
`Logger`
|
|
633
|
+
|
|
634
|
+
Optional logger for diagnostics
|
|
506
635
|
|
|
507
636
|
## Returns
|
|
508
637
|
|
|
@@ -510,7 +639,7 @@ Opens a read-only transaction on the specified store and passes it to the callba
|
|
|
510
639
|
|
|
511
640
|
The result of the callback
|
|
512
641
|
|
|
513
|
-
|
|
642
|
+
### <a id="withReadWriteStore"></a>withReadWriteStore
|
|
514
643
|
|
|
515
644
|
[**@xylabs/indexed-db**](#../README)
|
|
516
645
|
|
|
@@ -518,31 +647,49 @@ The result of the callback
|
|
|
518
647
|
|
|
519
648
|
```ts
|
|
520
649
|
function withReadWriteStore<T, R>(
|
|
521
|
-
db
|
|
522
|
-
storeName
|
|
523
|
-
callback
|
|
524
|
-
|
|
525
|
-
| null) => R | Promise<R>,
|
|
526
|
-
logger?: Logger): Promise<R>;
|
|
650
|
+
db,
|
|
651
|
+
storeName,
|
|
652
|
+
callback,
|
|
653
|
+
logger?): Promise<R>;
|
|
527
654
|
```
|
|
528
655
|
|
|
529
656
|
Opens a read-write transaction on the specified store and passes it to the callback.
|
|
530
657
|
|
|
531
658
|
## Type Parameters
|
|
532
659
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
660
|
+
### T
|
|
661
|
+
|
|
662
|
+
`T` *extends* `object` = `object`
|
|
663
|
+
|
|
664
|
+
### R
|
|
665
|
+
|
|
666
|
+
`R` = `T`
|
|
537
667
|
|
|
538
668
|
## Parameters
|
|
539
669
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
670
|
+
### db
|
|
671
|
+
|
|
672
|
+
`IDBPDatabase`\<[`ObjectStore`](#../type-aliases/ObjectStore)\<`T`\>\>
|
|
673
|
+
|
|
674
|
+
The IndexedDB database instance
|
|
675
|
+
|
|
676
|
+
### storeName
|
|
677
|
+
|
|
678
|
+
`StoreNames`\<[`ObjectStore`](#../type-aliases/ObjectStore)\<`T`\>\>
|
|
679
|
+
|
|
680
|
+
The name of the object store to open
|
|
681
|
+
|
|
682
|
+
### callback
|
|
683
|
+
|
|
684
|
+
(`store`) => `R` \| `Promise`\<`R`\>
|
|
685
|
+
|
|
686
|
+
Function to execute with the read-write store
|
|
687
|
+
|
|
688
|
+
### logger?
|
|
689
|
+
|
|
690
|
+
`Logger`
|
|
691
|
+
|
|
692
|
+
Optional logger for diagnostics
|
|
546
693
|
|
|
547
694
|
## Returns
|
|
548
695
|
|
|
@@ -550,7 +697,7 @@ Opens a read-write transaction on the specified store and passes it to the callb
|
|
|
550
697
|
|
|
551
698
|
The result of the callback
|
|
552
699
|
|
|
553
|
-
|
|
700
|
+
### <a id="withStore"></a>withStore
|
|
554
701
|
|
|
555
702
|
[**@xylabs/indexed-db**](#../README)
|
|
556
703
|
|
|
@@ -558,13 +705,11 @@ The result of the callback
|
|
|
558
705
|
|
|
559
706
|
```ts
|
|
560
707
|
function withStore<T, R, M>(
|
|
561
|
-
db
|
|
562
|
-
storeName
|
|
563
|
-
callback
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
mode: M,
|
|
567
|
-
logger?: Logger): Promise<R>;
|
|
708
|
+
db,
|
|
709
|
+
storeName,
|
|
710
|
+
callback,
|
|
711
|
+
mode,
|
|
712
|
+
logger?): Promise<R>;
|
|
568
713
|
```
|
|
569
714
|
|
|
570
715
|
Opens a transaction on the specified store with the given mode and passes the store to the callback.
|
|
@@ -572,21 +717,49 @@ If the store does not exist, the callback receives null.
|
|
|
572
717
|
|
|
573
718
|
## Type Parameters
|
|
574
719
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
720
|
+
### T
|
|
721
|
+
|
|
722
|
+
`T` *extends* `object` = `object`
|
|
723
|
+
|
|
724
|
+
### R
|
|
725
|
+
|
|
726
|
+
`R` = `T`
|
|
727
|
+
|
|
728
|
+
### M
|
|
729
|
+
|
|
730
|
+
`M` *extends* `"readonly"` \| `"readwrite"` = `"readonly"`
|
|
580
731
|
|
|
581
732
|
## Parameters
|
|
582
733
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
734
|
+
### db
|
|
735
|
+
|
|
736
|
+
`IDBPDatabase`\<[`ObjectStore`](#../type-aliases/ObjectStore)\<`T`\>\>
|
|
737
|
+
|
|
738
|
+
The IndexedDB database instance
|
|
739
|
+
|
|
740
|
+
### storeName
|
|
741
|
+
|
|
742
|
+
`StoreNames`\<[`ObjectStore`](#../type-aliases/ObjectStore)\<`T`\>\>
|
|
743
|
+
|
|
744
|
+
The name of the object store to open
|
|
745
|
+
|
|
746
|
+
### callback
|
|
747
|
+
|
|
748
|
+
(`store`) => `R` \| `Promise`\<`R`\>
|
|
749
|
+
|
|
750
|
+
Function to execute with the store (or null if it doesn't exist)
|
|
751
|
+
|
|
752
|
+
### mode
|
|
753
|
+
|
|
754
|
+
`M`
|
|
755
|
+
|
|
756
|
+
The transaction mode ('readonly' or 'readwrite')
|
|
757
|
+
|
|
758
|
+
### logger?
|
|
759
|
+
|
|
760
|
+
`Logger`
|
|
761
|
+
|
|
762
|
+
Optional logger for diagnostics
|
|
590
763
|
|
|
591
764
|
## Returns
|
|
592
765
|
|
|
@@ -594,55 +767,49 @@ If the store does not exist, the callback receives null.
|
|
|
594
767
|
|
|
595
768
|
The result of the callback
|
|
596
769
|
|
|
597
|
-
### interfaces
|
|
770
|
+
### interfaces
|
|
598
771
|
|
|
599
|
-
|
|
772
|
+
### <a id="IndexDescription"></a>IndexDescription
|
|
600
773
|
|
|
601
774
|
[**@xylabs/indexed-db**](#../README)
|
|
602
775
|
|
|
603
776
|
***
|
|
604
777
|
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
## Type Parameters
|
|
778
|
+
Description of index(es) to be created on a store
|
|
608
779
|
|
|
609
|
-
|
|
610
|
-
| ------ | ------ |
|
|
611
|
-
| `T` *extends* `EmptyObject` | `EmptyObject` |
|
|
780
|
+
## Properties
|
|
612
781
|
|
|
613
|
-
|
|
782
|
+
### key
|
|
614
783
|
|
|
615
784
|
```ts
|
|
616
|
-
|
|
785
|
+
key: Record<string, IndexDirection>;
|
|
617
786
|
```
|
|
618
787
|
|
|
619
|
-
|
|
788
|
+
The key(s) to index
|
|
620
789
|
|
|
621
|
-
|
|
790
|
+
***
|
|
622
791
|
|
|
623
|
-
|
|
792
|
+
### multiEntry?
|
|
793
|
+
|
|
794
|
+
```ts
|
|
795
|
+
optional multiEntry?: boolean;
|
|
796
|
+
```
|
|
797
|
+
|
|
798
|
+
Is the indexed value an array
|
|
624
799
|
|
|
625
800
|
***
|
|
626
801
|
|
|
802
|
+
### unique?
|
|
803
|
+
|
|
627
804
|
```ts
|
|
628
|
-
|
|
629
|
-
key: Record<string, IndexDirection>;
|
|
630
|
-
multiEntry?: boolean;
|
|
631
|
-
unique?: boolean;
|
|
632
|
-
};
|
|
805
|
+
optional unique?: boolean;
|
|
633
806
|
```
|
|
634
807
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
## Properties
|
|
808
|
+
If true, the index must enforce uniqueness on the key
|
|
638
809
|
|
|
639
|
-
|
|
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 |
|
|
810
|
+
### type-aliases
|
|
644
811
|
|
|
645
|
-
|
|
812
|
+
### <a id="IndexDirection"></a>IndexDirection
|
|
646
813
|
|
|
647
814
|
[**@xylabs/indexed-db**](#../README)
|
|
648
815
|
|
|
@@ -654,56 +821,40 @@ type IndexDirection = -1 | 1;
|
|
|
654
821
|
|
|
655
822
|
The index direction (1 for ascending, -1 for descending)
|
|
656
823
|
|
|
657
|
-
###
|
|
658
|
-
|
|
659
|
-
### <a id="IndexSeparator"></a>IndexSeparator
|
|
824
|
+
### <a id="ObjectStore"></a>ObjectStore
|
|
660
825
|
|
|
661
826
|
[**@xylabs/indexed-db**](#../README)
|
|
662
827
|
|
|
663
828
|
***
|
|
664
829
|
|
|
665
830
|
```ts
|
|
666
|
-
|
|
831
|
+
type ObjectStore<T> = Record<string, T>;
|
|
667
832
|
```
|
|
668
833
|
|
|
669
|
-
|
|
834
|
+
Generic IndexedDB schema type that maps store names to their value types.
|
|
670
835
|
|
|
836
|
+
## Type Parameters
|
|
671
837
|
|
|
672
|
-
|
|
838
|
+
### T
|
|
673
839
|
|
|
674
|
-
|
|
840
|
+
`T` *extends* `EmptyObject` = `EmptyObject`
|
|
675
841
|
|
|
676
|
-
|
|
677
|
-
- [Matt Jones](https://github.com/jonesmac)
|
|
678
|
-
- [Joel Carter](https://github.com/JoelBCarter)
|
|
679
|
-
- [Jordan Trouw](https://github.com/jordantrouw)
|
|
842
|
+
### variables
|
|
680
843
|
|
|
681
|
-
|
|
844
|
+
### <a id="IndexSeparator"></a>IndexSeparator
|
|
682
845
|
|
|
683
|
-
|
|
846
|
+
[**@xylabs/indexed-db**](#../README)
|
|
684
847
|
|
|
685
|
-
|
|
848
|
+
***
|
|
686
849
|
|
|
687
|
-
|
|
850
|
+
```ts
|
|
851
|
+
const IndexSeparator: "-" = '-';
|
|
852
|
+
```
|
|
853
|
+
|
|
854
|
+
Separator used between key names when building standard index names.
|
|
688
855
|
|
|
689
|
-
[logo]: https://cdn.xy.company/img/brand/XYPersistentCompany_Logo_Icon_Colored.svg
|
|
690
856
|
|
|
691
|
-
[main-build]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml/badge.svg
|
|
692
|
-
[main-build-link]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml
|
|
693
857
|
[npm-badge]: https://img.shields.io/npm/v/@xylabs/indexed-db.svg
|
|
694
858
|
[npm-link]: https://www.npmjs.com/package/@xylabs/indexed-db
|
|
695
|
-
[
|
|
696
|
-
[
|
|
697
|
-
[codeclimate-badge]: https://api.codeclimate.com/v1/badges/c5eb068f806f0b047ea7/maintainability
|
|
698
|
-
[codeclimate-link]: https://codeclimate.com/github/xylabs/sdk-js/maintainability
|
|
699
|
-
[snyk-badge]: https://snyk.io/test/github/xylabs/sdk-js/badge.svg?targetFile=package.json
|
|
700
|
-
[snyk-link]: https://snyk.io/test/github/xylabs/sdk-js?targetFile=package.json
|
|
701
|
-
|
|
702
|
-
[npm-downloads-badge]: https://img.shields.io/npm/dw/@xylabs/indexed-db
|
|
703
|
-
[npm-license-badge]: https://img.shields.io/npm/l/@xylabs/indexed-db
|
|
704
|
-
|
|
705
|
-
[jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/@xylabs/indexed-db/badge
|
|
706
|
-
[jsdelivr-link]: https://www.jsdelivr.com/package/npm/@xylabs/indexed-db
|
|
707
|
-
|
|
708
|
-
[socket-badge]: https://socket.dev/api/badge/npm/package/@xylabs/indexed-db
|
|
709
|
-
[socket-link]: https://socket.dev/npm/package/@xylabs/indexed-db
|
|
859
|
+
[license-badge]: https://img.shields.io/npm/l/@xylabs/indexed-db.svg
|
|
860
|
+
[license-link]: https://github.com/xylabs/sdk-js/blob/main/LICENSE
|