@xylabs/indexed-db 5.0.84 → 5.0.87
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 +195 -391
- package/package.json +10 -10
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,23 +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
|
-
The name of the IndexedDB database.
|
|
108
|
-
|
|
109
|
-
***
|
|
110
|
-
|
|
111
|
-
### storeName
|
|
112
|
-
|
|
113
|
-
```ts
|
|
114
|
-
readonly storeName: S;
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
The name of the object store within the database.
|
|
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. |
|
|
118
111
|
|
|
119
112
|
## Methods
|
|
120
113
|
|
|
@@ -141,18 +134,16 @@ KeyValueStore.clear
|
|
|
141
134
|
### delete()
|
|
142
135
|
|
|
143
136
|
```ts
|
|
144
|
-
delete(key): Promise<void>;
|
|
137
|
+
delete(key: StoreKey<T, S>): Promise<void>;
|
|
145
138
|
```
|
|
146
139
|
|
|
147
140
|
Deletes the entry with the given key.
|
|
148
141
|
|
|
149
142
|
### Parameters
|
|
150
143
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
`StoreKey`\<`T`, `S`\>
|
|
154
|
-
|
|
155
|
-
The key of the entry to delete
|
|
144
|
+
| Parameter | Type | Description |
|
|
145
|
+
| ------ | ------ | ------ |
|
|
146
|
+
| `key` | `StoreKey`\<`T`, `S`\> | The key of the entry to delete |
|
|
156
147
|
|
|
157
148
|
### Returns
|
|
158
149
|
|
|
@@ -169,18 +160,16 @@ KeyValueStore.delete
|
|
|
169
160
|
### get()
|
|
170
161
|
|
|
171
162
|
```ts
|
|
172
|
-
get(key): Promise<StoreValue<T, S> | undefined>;
|
|
163
|
+
get(key: StoreKey<T, S>): Promise<StoreValue<T, S> | undefined>;
|
|
173
164
|
```
|
|
174
165
|
|
|
175
166
|
Retrieves the value associated with the given key.
|
|
176
167
|
|
|
177
168
|
### Parameters
|
|
178
169
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
`StoreKey`\<`T`, `S`\>
|
|
182
|
-
|
|
183
|
-
The key to look up
|
|
170
|
+
| Parameter | Type | Description |
|
|
171
|
+
| ------ | ------ | ------ |
|
|
172
|
+
| `key` | `StoreKey`\<`T`, `S`\> | The key to look up |
|
|
184
173
|
|
|
185
174
|
### Returns
|
|
186
175
|
|
|
@@ -219,24 +208,17 @@ KeyValueStore.keys
|
|
|
219
208
|
### set()
|
|
220
209
|
|
|
221
210
|
```ts
|
|
222
|
-
set(key, value): Promise<void>;
|
|
211
|
+
set(key: StoreKey<T, S>, value: StoreValue<T, S>): Promise<void>;
|
|
223
212
|
```
|
|
224
213
|
|
|
225
214
|
Sets a value for the given key, creating or updating the entry.
|
|
226
215
|
|
|
227
216
|
### Parameters
|
|
228
217
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
`StoreKey`\<`T`, `S`\>
|
|
232
|
-
|
|
233
|
-
The key to set
|
|
234
|
-
|
|
235
|
-
#### value
|
|
236
|
-
|
|
237
|
-
`StoreValue`\<`T`, `S`\>
|
|
238
|
-
|
|
239
|
-
The value to store
|
|
218
|
+
| Parameter | Type | Description |
|
|
219
|
+
| ------ | ------ | ------ |
|
|
220
|
+
| `key` | `StoreKey`\<`T`, `S`\> | The key to set |
|
|
221
|
+
| `value` | `StoreValue`\<`T`, `S`\> | The value to store |
|
|
240
222
|
|
|
241
223
|
### Returns
|
|
242
224
|
|
|
@@ -253,24 +235,22 @@ KeyValueStore.set
|
|
|
253
235
|
### withDb()
|
|
254
236
|
|
|
255
237
|
```ts
|
|
256
|
-
withDb<R>(callback): Promise<R>;
|
|
238
|
+
withDb<R>(callback: (db: IDBPDatabase<T>) => R | Promise<R>): Promise<R>;
|
|
257
239
|
```
|
|
258
240
|
|
|
259
241
|
Opens the underlying IndexedDB database and passes it to the callback.
|
|
260
242
|
|
|
261
243
|
### Type Parameters
|
|
262
244
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
`R`
|
|
245
|
+
| Type Parameter | Default type |
|
|
246
|
+
| ------ | ------ |
|
|
247
|
+
| `R` | `StoreValue`\<`T`, `S`\> |
|
|
266
248
|
|
|
267
249
|
### Parameters
|
|
268
250
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
(`db`) => `R` \| `Promise`\<`R`\>
|
|
272
|
-
|
|
273
|
-
Function to execute with the database
|
|
251
|
+
| Parameter | Type | Description |
|
|
252
|
+
| ------ | ------ | ------ |
|
|
253
|
+
| `callback` | (`db`: `IDBPDatabase`\<`T`\>) => `R` \| `Promise`\<`R`\> | Function to execute with the database |
|
|
274
254
|
|
|
275
255
|
### Returns
|
|
276
256
|
|
|
@@ -287,7 +267,7 @@ The result of the callback
|
|
|
287
267
|
***
|
|
288
268
|
|
|
289
269
|
```ts
|
|
290
|
-
function buildStandardIndexName(index): string;
|
|
270
|
+
function buildStandardIndexName(index: IndexDescription): string;
|
|
291
271
|
```
|
|
292
272
|
|
|
293
273
|
Given an index description, this will build the index
|
|
@@ -295,11 +275,9 @@ name in standard form
|
|
|
295
275
|
|
|
296
276
|
## Parameters
|
|
297
277
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
[`IndexDescription`](#../type-aliases/IndexDescription)
|
|
301
|
-
|
|
302
|
-
The index description
|
|
278
|
+
| Parameter | Type | Description |
|
|
279
|
+
| ------ | ------ | ------ |
|
|
280
|
+
| `index` | [`IndexDescription`](#../type-aliases/IndexDescription) | The index description |
|
|
303
281
|
|
|
304
282
|
## Returns
|
|
305
283
|
|
|
@@ -315,32 +293,20 @@ The index name in standard form
|
|
|
315
293
|
|
|
316
294
|
```ts
|
|
317
295
|
function checkDbNeedsUpgrade(
|
|
318
|
-
dbName,
|
|
319
|
-
stores,
|
|
320
|
-
logger
|
|
296
|
+
dbName: string,
|
|
297
|
+
stores: Record<string, IndexDescription[]>,
|
|
298
|
+
logger?: Logger): Promise<number>;
|
|
321
299
|
```
|
|
322
300
|
|
|
323
301
|
Checks whether any store in the database needs an upgrade and returns the appropriate version number.
|
|
324
302
|
|
|
325
303
|
## Parameters
|
|
326
304
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
`string`
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
### stores
|
|
334
|
-
|
|
335
|
-
`Record`\<`string`, [`IndexDescription`](#../type-aliases/IndexDescription)[]\>
|
|
336
|
-
|
|
337
|
-
Map of store names to their expected index descriptions
|
|
338
|
-
|
|
339
|
-
### logger?
|
|
340
|
-
|
|
341
|
-
`Logger`
|
|
342
|
-
|
|
343
|
-
Optional logger for diagnostics
|
|
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 |
|
|
344
310
|
|
|
345
311
|
## Returns
|
|
346
312
|
|
|
@@ -356,45 +322,28 @@ The version to open (current version + 1 if upgrade needed, otherwise current ve
|
|
|
356
322
|
|
|
357
323
|
```ts
|
|
358
324
|
function createStoreDuringUpgrade<DBTypes>(
|
|
359
|
-
db
|
|
360
|
-
storeName
|
|
361
|
-
indexes,
|
|
362
|
-
logger
|
|
325
|
+
db: IDBPDatabase<DBTypes>,
|
|
326
|
+
storeName: StoreNames<DBTypes>,
|
|
327
|
+
indexes: IndexDescription[],
|
|
328
|
+
logger?: Logger): void;
|
|
363
329
|
```
|
|
364
330
|
|
|
365
331
|
Creates an object store with the specified indexes during a version upgrade transaction.
|
|
366
332
|
|
|
367
333
|
## Type Parameters
|
|
368
334
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
`DBTypes` *extends* `unknown`
|
|
335
|
+
| Type Parameter | Default type |
|
|
336
|
+
| ------ | ------ |
|
|
337
|
+
| `DBTypes` *extends* `unknown` | `unknown` |
|
|
372
338
|
|
|
373
339
|
## Parameters
|
|
374
340
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
`IDBPDatabase`\<`DBTypes`\>
|
|
378
|
-
|
|
379
|
-
The
|
|
380
|
-
|
|
381
|
-
### storeName
|
|
382
|
-
|
|
383
|
-
`StoreNames`\<`DBTypes`\>
|
|
384
|
-
|
|
385
|
-
The name of the store to create
|
|
386
|
-
|
|
387
|
-
### indexes
|
|
388
|
-
|
|
389
|
-
[`IndexDescription`](#../type-aliases/IndexDescription)[]
|
|
390
|
-
|
|
391
|
-
The index descriptions to create on the store
|
|
392
|
-
|
|
393
|
-
### logger?
|
|
394
|
-
|
|
395
|
-
`Logger`
|
|
396
|
-
|
|
397
|
-
Optional logger for diagnostics
|
|
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 |
|
|
398
347
|
|
|
399
348
|
## Returns
|
|
400
349
|
|
|
@@ -408,38 +357,28 @@ Optional logger for diagnostics
|
|
|
408
357
|
|
|
409
358
|
```ts
|
|
410
359
|
function getExistingIndexes<T>(
|
|
411
|
-
db
|
|
412
|
-
|
|
413
|
-
|
|
360
|
+
db:
|
|
361
|
+
| string
|
|
362
|
+
| IDBPDatabase<ObjectStore<T>>,
|
|
363
|
+
storeName: StoreNames<ObjectStore<T>>,
|
|
364
|
+
logger?: Logger): Promise<IndexDescription[] | null>;
|
|
414
365
|
```
|
|
415
366
|
|
|
416
367
|
Retrieves the existing index descriptions for a store. Accepts either a database instance or a database name.
|
|
417
368
|
|
|
418
369
|
## Type Parameters
|
|
419
370
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
`T` *extends* `object`
|
|
371
|
+
| Type Parameter | Default type |
|
|
372
|
+
| ------ | ------ |
|
|
373
|
+
| `T` *extends* `object` | `object` |
|
|
423
374
|
|
|
424
375
|
## Parameters
|
|
425
376
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
The IndexedDB database instance or database name
|
|
429
|
-
|
|
430
|
-
`
|
|
431
|
-
|
|
432
|
-
### storeName
|
|
433
|
-
|
|
434
|
-
`StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
|
|
435
|
-
|
|
436
|
-
The name of the store to inspect
|
|
437
|
-
|
|
438
|
-
### logger?
|
|
439
|
-
|
|
440
|
-
`Logger`
|
|
441
|
-
|
|
442
|
-
Optional logger for diagnostics
|
|
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 |
|
|
443
382
|
|
|
444
383
|
## Returns
|
|
445
384
|
|
|
@@ -455,11 +394,11 @@ An array of index descriptions, or null if the store does not exist
|
|
|
455
394
|
|
|
456
395
|
```ts
|
|
457
396
|
function withDb<DBTypes, R>(
|
|
458
|
-
dbName,
|
|
459
|
-
callback
|
|
460
|
-
expectedIndexes
|
|
461
|
-
logger
|
|
462
|
-
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>;
|
|
463
402
|
```
|
|
464
403
|
|
|
465
404
|
Opens an IndexedDB database, automatically upgrading if needed, and passes it to the callback.
|
|
@@ -467,45 +406,20 @@ Uses a mutex to serialize access to the same database by default.
|
|
|
467
406
|
|
|
468
407
|
## Type Parameters
|
|
469
408
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
`DBTypes` *extends* `unknown`
|
|
473
|
-
|
|
474
|
-
### R
|
|
475
|
-
|
|
476
|
-
`R` = `object`
|
|
409
|
+
| Type Parameter | Default type |
|
|
410
|
+
| ------ | ------ |
|
|
411
|
+
| `DBTypes` *extends* `unknown` | `unknown` |
|
|
412
|
+
| `R` | `object` |
|
|
477
413
|
|
|
478
414
|
## Parameters
|
|
479
415
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
`string`
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
(`db`) => `R` \| `Promise`\<`R`\>
|
|
489
|
-
|
|
490
|
-
Function to execute with the opened database
|
|
491
|
-
|
|
492
|
-
### expectedIndexes?
|
|
493
|
-
|
|
494
|
-
`Record`\<`string`, [`IndexDescription`](#../type-aliases/IndexDescription)[]\>
|
|
495
|
-
|
|
496
|
-
Optional map of store names to their expected indexes (triggers upgrade check)
|
|
497
|
-
|
|
498
|
-
### logger?
|
|
499
|
-
|
|
500
|
-
`Logger`
|
|
501
|
-
|
|
502
|
-
Optional logger for diagnostics
|
|
503
|
-
|
|
504
|
-
### lock?
|
|
505
|
-
|
|
506
|
-
`boolean` = `true`
|
|
507
|
-
|
|
508
|
-
Whether to use a mutex to serialize access (defaults to 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) |
|
|
509
423
|
|
|
510
424
|
## Returns
|
|
511
425
|
|
|
@@ -521,12 +435,12 @@ The result of the callback
|
|
|
521
435
|
|
|
522
436
|
```ts
|
|
523
437
|
function withDbByVersion<DBTypes, R>(
|
|
524
|
-
dbName,
|
|
525
|
-
callback
|
|
526
|
-
version
|
|
527
|
-
expectedIndexes
|
|
528
|
-
logger
|
|
529
|
-
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>;
|
|
530
444
|
```
|
|
531
445
|
|
|
532
446
|
Opens an IndexedDB database at a specific version, handling upgrade events, and passes it to the callback.
|
|
@@ -534,51 +448,21 @@ The database is automatically closed after the callback completes.
|
|
|
534
448
|
|
|
535
449
|
## Type Parameters
|
|
536
450
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
`DBTypes` *extends* `unknown`
|
|
540
|
-
|
|
541
|
-
### R
|
|
542
|
-
|
|
543
|
-
`R` = `object`
|
|
451
|
+
| Type Parameter | Default type |
|
|
452
|
+
| ------ | ------ |
|
|
453
|
+
| `DBTypes` *extends* `unknown` | `unknown` |
|
|
454
|
+
| `R` | `object` |
|
|
544
455
|
|
|
545
456
|
## Parameters
|
|
546
457
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
`string`
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
(`db`) => `R` \| `Promise`\<`R`\>
|
|
556
|
-
|
|
557
|
-
Function to execute with the opened database
|
|
558
|
-
|
|
559
|
-
### version?
|
|
560
|
-
|
|
561
|
-
`number`
|
|
562
|
-
|
|
563
|
-
Optional specific version to open (undefined for latest)
|
|
564
|
-
|
|
565
|
-
### expectedIndexes?
|
|
566
|
-
|
|
567
|
-
`Record`\<`string`, [`IndexDescription`](#../type-aliases/IndexDescription)[]\>
|
|
568
|
-
|
|
569
|
-
Optional map of store names to indexes to create during upgrade
|
|
570
|
-
|
|
571
|
-
### logger?
|
|
572
|
-
|
|
573
|
-
`Logger`
|
|
574
|
-
|
|
575
|
-
Optional logger for diagnostics
|
|
576
|
-
|
|
577
|
-
### lock?
|
|
578
|
-
|
|
579
|
-
`boolean` = `true`
|
|
580
|
-
|
|
581
|
-
Whether to use a mutex to serialize access (defaults to 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) |
|
|
582
466
|
|
|
583
467
|
## Returns
|
|
584
468
|
|
|
@@ -594,49 +478,31 @@ The result of the callback
|
|
|
594
478
|
|
|
595
479
|
```ts
|
|
596
480
|
function withReadOnlyStore<T, R>(
|
|
597
|
-
db
|
|
598
|
-
storeName
|
|
599
|
-
callback
|
|
600
|
-
|
|
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>;
|
|
601
487
|
```
|
|
602
488
|
|
|
603
489
|
Opens a read-only transaction on the specified store and passes it to the callback.
|
|
604
490
|
|
|
605
491
|
## Type Parameters
|
|
606
492
|
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
`T` *extends* `object`
|
|
610
|
-
|
|
611
|
-
### R
|
|
612
|
-
|
|
613
|
-
`R` = `T`
|
|
493
|
+
| Type Parameter | Default type |
|
|
494
|
+
| ------ | ------ |
|
|
495
|
+
| `T` *extends* `object` | `object` |
|
|
496
|
+
| `R` | `T` |
|
|
614
497
|
|
|
615
498
|
## Parameters
|
|
616
499
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
`IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
### storeName
|
|
624
|
-
|
|
625
|
-
`StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
|
|
626
|
-
|
|
627
|
-
The name of the object store to open
|
|
628
|
-
|
|
629
|
-
### callback
|
|
630
|
-
|
|
631
|
-
(`store`) => `R` \| `Promise`\<`R`\>
|
|
632
|
-
|
|
633
|
-
Function to execute with the read-only store
|
|
634
|
-
|
|
635
|
-
### logger?
|
|
636
|
-
|
|
637
|
-
`Logger`
|
|
638
|
-
|
|
639
|
-
Optional logger for diagnostics
|
|
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 |
|
|
640
506
|
|
|
641
507
|
## Returns
|
|
642
508
|
|
|
@@ -652,49 +518,31 @@ The result of the callback
|
|
|
652
518
|
|
|
653
519
|
```ts
|
|
654
520
|
function withReadWriteStore<T, R>(
|
|
655
|
-
db
|
|
656
|
-
storeName
|
|
657
|
-
callback
|
|
658
|
-
|
|
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>;
|
|
659
527
|
```
|
|
660
528
|
|
|
661
529
|
Opens a read-write transaction on the specified store and passes it to the callback.
|
|
662
530
|
|
|
663
531
|
## Type Parameters
|
|
664
532
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
`T` *extends* `object`
|
|
668
|
-
|
|
669
|
-
### R
|
|
670
|
-
|
|
671
|
-
`R` = `T`
|
|
533
|
+
| Type Parameter | Default type |
|
|
534
|
+
| ------ | ------ |
|
|
535
|
+
| `T` *extends* `object` | `object` |
|
|
536
|
+
| `R` | `T` |
|
|
672
537
|
|
|
673
538
|
## Parameters
|
|
674
539
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
`IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
### storeName
|
|
682
|
-
|
|
683
|
-
`StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
|
|
684
|
-
|
|
685
|
-
The name of the object store to open
|
|
686
|
-
|
|
687
|
-
### callback
|
|
688
|
-
|
|
689
|
-
(`store`) => `R` \| `Promise`\<`R`\>
|
|
690
|
-
|
|
691
|
-
Function to execute with the read-write store
|
|
692
|
-
|
|
693
|
-
### logger?
|
|
694
|
-
|
|
695
|
-
`Logger`
|
|
696
|
-
|
|
697
|
-
Optional logger for diagnostics
|
|
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 |
|
|
698
546
|
|
|
699
547
|
## Returns
|
|
700
548
|
|
|
@@ -710,11 +558,13 @@ The result of the callback
|
|
|
710
558
|
|
|
711
559
|
```ts
|
|
712
560
|
function withStore<T, R, M>(
|
|
713
|
-
db
|
|
714
|
-
storeName
|
|
715
|
-
callback
|
|
716
|
-
|
|
717
|
-
|
|
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>;
|
|
718
568
|
```
|
|
719
569
|
|
|
720
570
|
Opens a transaction on the specified store with the given mode and passes the store to the callback.
|
|
@@ -722,49 +572,21 @@ If the store does not exist, the callback receives null.
|
|
|
722
572
|
|
|
723
573
|
## Type Parameters
|
|
724
574
|
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
`T` *extends* `object`
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
`R` = `T`
|
|
732
|
-
|
|
733
|
-
### M
|
|
734
|
-
|
|
735
|
-
`M` *extends* `"readonly"` \| `"readwrite"` = `"readonly"`
|
|
575
|
+
| Type Parameter | Default type |
|
|
576
|
+
| ------ | ------ |
|
|
577
|
+
| `T` *extends* `object` | `object` |
|
|
578
|
+
| `R` | `T` |
|
|
579
|
+
| `M` *extends* `"readonly"` \| `"readwrite"` | `"readonly"` |
|
|
736
580
|
|
|
737
581
|
## Parameters
|
|
738
582
|
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
`IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
`StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
|
|
748
|
-
|
|
749
|
-
The name of the object store to open
|
|
750
|
-
|
|
751
|
-
### callback
|
|
752
|
-
|
|
753
|
-
(`store`) => `R` \| `Promise`\<`R`\>
|
|
754
|
-
|
|
755
|
-
Function to execute with the store (or null if it doesn't exist)
|
|
756
|
-
|
|
757
|
-
### mode
|
|
758
|
-
|
|
759
|
-
`M`
|
|
760
|
-
|
|
761
|
-
The transaction mode ('readonly' or 'readwrite')
|
|
762
|
-
|
|
763
|
-
### logger?
|
|
764
|
-
|
|
765
|
-
`Logger`
|
|
766
|
-
|
|
767
|
-
Optional logger for diagnostics
|
|
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 |
|
|
768
590
|
|
|
769
591
|
## Returns
|
|
770
592
|
|
|
@@ -784,9 +606,9 @@ Generic IndexedDB schema type that maps store names to their value types.
|
|
|
784
606
|
|
|
785
607
|
## Type Parameters
|
|
786
608
|
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
`T` *extends* `EmptyObject`
|
|
609
|
+
| Type Parameter | Default type |
|
|
610
|
+
| ------ | ------ |
|
|
611
|
+
| `T` *extends* `EmptyObject` | `EmptyObject` |
|
|
790
612
|
|
|
791
613
|
## Indexable
|
|
792
614
|
|
|
@@ -803,40 +625,22 @@ Generic IndexedDB schema type that maps store names to their value types.
|
|
|
803
625
|
***
|
|
804
626
|
|
|
805
627
|
```ts
|
|
806
|
-
type IndexDescription =
|
|
628
|
+
type IndexDescription = {
|
|
629
|
+
key: Record<string, IndexDirection>;
|
|
630
|
+
multiEntry?: boolean;
|
|
631
|
+
unique?: boolean;
|
|
632
|
+
};
|
|
807
633
|
```
|
|
808
634
|
|
|
809
635
|
Description of index(es) to be created on a store
|
|
810
636
|
|
|
811
637
|
## Properties
|
|
812
638
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
The key(s) to index
|
|
820
|
-
|
|
821
|
-
***
|
|
822
|
-
|
|
823
|
-
### multiEntry?
|
|
824
|
-
|
|
825
|
-
```ts
|
|
826
|
-
optional multiEntry: boolean;
|
|
827
|
-
```
|
|
828
|
-
|
|
829
|
-
Is the indexed value an array
|
|
830
|
-
|
|
831
|
-
***
|
|
832
|
-
|
|
833
|
-
### unique?
|
|
834
|
-
|
|
835
|
-
```ts
|
|
836
|
-
optional unique: boolean;
|
|
837
|
-
```
|
|
838
|
-
|
|
839
|
-
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 |
|
|
840
644
|
|
|
841
645
|
### <a id="IndexDirection"></a>IndexDirection
|
|
842
646
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/indexed-db",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.87",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hex",
|
|
@@ -52,21 +52,21 @@
|
|
|
52
52
|
"!**/*.test.*"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@xylabs/exists": "~5.0.
|
|
56
|
-
"@xylabs/logger": "~5.0.
|
|
57
|
-
"@xylabs/object": "~5.0.
|
|
58
|
-
"@xylabs/storage": "~5.0.
|
|
55
|
+
"@xylabs/exists": "~5.0.87",
|
|
56
|
+
"@xylabs/logger": "~5.0.87",
|
|
57
|
+
"@xylabs/object": "~5.0.87",
|
|
58
|
+
"@xylabs/storage": "~5.0.87",
|
|
59
59
|
"async-mutex": "~0.5.0",
|
|
60
60
|
"idb": "~8.0.3"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
64
|
-
"@xylabs/tsconfig": "~7.4.
|
|
65
|
-
"@xylabs/tsconfig-dom": "~7.4.
|
|
63
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.24",
|
|
64
|
+
"@xylabs/tsconfig": "~7.4.24",
|
|
65
|
+
"@xylabs/tsconfig-dom": "~7.4.24",
|
|
66
66
|
"fake-indexeddb": "~6.2.5",
|
|
67
|
-
"jsdom": "~
|
|
67
|
+
"jsdom": "~29.0.1",
|
|
68
68
|
"typescript": "~5.9.3",
|
|
69
|
-
"vitest": "
|
|
69
|
+
"vitest": "^4.1.0"
|
|
70
70
|
},
|
|
71
71
|
"engines": {
|
|
72
72
|
"node": ">=18"
|