@xylabs/indexed-db 5.0.82 → 5.0.84

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.
Files changed (80) hide show
  1. package/README.md +132 -3
  2. package/dist/browser/IndexDescription.d.ts +1 -0
  3. package/dist/browser/IndexDescription.d.ts.map +1 -1
  4. package/dist/browser/IndexedDbKeyValueStore.d.ts +23 -0
  5. package/dist/browser/IndexedDbKeyValueStore.d.ts.map +1 -1
  6. package/dist/browser/ObjectStore.d.ts +1 -0
  7. package/dist/browser/ObjectStore.d.ts.map +1 -1
  8. package/dist/browser/checkDbNeedsUpgrade.d.ts +7 -0
  9. package/dist/browser/checkDbNeedsUpgrade.d.ts.map +1 -1
  10. package/dist/browser/checkStoreNeedsUpgrade.d.ts +8 -0
  11. package/dist/browser/checkStoreNeedsUpgrade.d.ts.map +1 -1
  12. package/dist/browser/createStoreDuringUpgrade.d.ts +7 -0
  13. package/dist/browser/createStoreDuringUpgrade.d.ts.map +1 -1
  14. package/dist/browser/getExistingIndexes.d.ts +7 -0
  15. package/dist/browser/getExistingIndexes.d.ts.map +1 -1
  16. package/dist/browser/index.mjs +23 -0
  17. package/dist/browser/index.mjs.map +1 -1
  18. package/dist/browser/withDb.d.ts +10 -0
  19. package/dist/browser/withDb.d.ts.map +1 -1
  20. package/dist/browser/withDbByVersion.d.ts +11 -0
  21. package/dist/browser/withDbByVersion.d.ts.map +1 -1
  22. package/dist/browser/withReadOnlyStore.d.ts +8 -0
  23. package/dist/browser/withReadOnlyStore.d.ts.map +1 -1
  24. package/dist/browser/withReadWriteStore.d.ts +8 -0
  25. package/dist/browser/withReadWriteStore.d.ts.map +1 -1
  26. package/dist/browser/withStore.d.ts +10 -0
  27. package/dist/browser/withStore.d.ts.map +1 -1
  28. package/dist/neutral/IndexDescription.d.ts +1 -0
  29. package/dist/neutral/IndexDescription.d.ts.map +1 -1
  30. package/dist/neutral/IndexedDbKeyValueStore.d.ts +23 -0
  31. package/dist/neutral/IndexedDbKeyValueStore.d.ts.map +1 -1
  32. package/dist/neutral/ObjectStore.d.ts +1 -0
  33. package/dist/neutral/ObjectStore.d.ts.map +1 -1
  34. package/dist/neutral/checkDbNeedsUpgrade.d.ts +7 -0
  35. package/dist/neutral/checkDbNeedsUpgrade.d.ts.map +1 -1
  36. package/dist/neutral/checkStoreNeedsUpgrade.d.ts +8 -0
  37. package/dist/neutral/checkStoreNeedsUpgrade.d.ts.map +1 -1
  38. package/dist/neutral/createStoreDuringUpgrade.d.ts +7 -0
  39. package/dist/neutral/createStoreDuringUpgrade.d.ts.map +1 -1
  40. package/dist/neutral/getExistingIndexes.d.ts +7 -0
  41. package/dist/neutral/getExistingIndexes.d.ts.map +1 -1
  42. package/dist/neutral/index.mjs +23 -0
  43. package/dist/neutral/index.mjs.map +1 -1
  44. package/dist/neutral/withDb.d.ts +10 -0
  45. package/dist/neutral/withDb.d.ts.map +1 -1
  46. package/dist/neutral/withDbByVersion.d.ts +11 -0
  47. package/dist/neutral/withDbByVersion.d.ts.map +1 -1
  48. package/dist/neutral/withReadOnlyStore.d.ts +8 -0
  49. package/dist/neutral/withReadOnlyStore.d.ts.map +1 -1
  50. package/dist/neutral/withReadWriteStore.d.ts +8 -0
  51. package/dist/neutral/withReadWriteStore.d.ts.map +1 -1
  52. package/dist/neutral/withStore.d.ts +10 -0
  53. package/dist/neutral/withStore.d.ts.map +1 -1
  54. package/dist/node/IndexDescription.d.ts +1 -0
  55. package/dist/node/IndexDescription.d.ts.map +1 -1
  56. package/dist/node/IndexedDbKeyValueStore.d.ts +23 -0
  57. package/dist/node/IndexedDbKeyValueStore.d.ts.map +1 -1
  58. package/dist/node/ObjectStore.d.ts +1 -0
  59. package/dist/node/ObjectStore.d.ts.map +1 -1
  60. package/dist/node/checkDbNeedsUpgrade.d.ts +7 -0
  61. package/dist/node/checkDbNeedsUpgrade.d.ts.map +1 -1
  62. package/dist/node/checkStoreNeedsUpgrade.d.ts +8 -0
  63. package/dist/node/checkStoreNeedsUpgrade.d.ts.map +1 -1
  64. package/dist/node/createStoreDuringUpgrade.d.ts +7 -0
  65. package/dist/node/createStoreDuringUpgrade.d.ts.map +1 -1
  66. package/dist/node/getExistingIndexes.d.ts +7 -0
  67. package/dist/node/getExistingIndexes.d.ts.map +1 -1
  68. package/dist/node/index.mjs +23 -0
  69. package/dist/node/index.mjs.map +1 -1
  70. package/dist/node/withDb.d.ts +10 -0
  71. package/dist/node/withDb.d.ts.map +1 -1
  72. package/dist/node/withDbByVersion.d.ts +11 -0
  73. package/dist/node/withDbByVersion.d.ts.map +1 -1
  74. package/dist/node/withReadOnlyStore.d.ts +8 -0
  75. package/dist/node/withReadOnlyStore.d.ts.map +1 -1
  76. package/dist/node/withReadWriteStore.d.ts +8 -0
  77. package/dist/node/withReadWriteStore.d.ts.map +1 -1
  78. package/dist/node/withStore.d.ts +10 -0
  79. package/dist/node/withStore.d.ts.map +1 -1
  80. package/package.json +9 -9
package/README.md CHANGED
@@ -104,6 +104,8 @@ new IndexedDbKeyValueStore<T, S>(dbName, storeName): IndexedDbKeyValueStore<T, S
104
104
  readonly dbName: string;
105
105
  ```
106
106
 
107
+ The name of the IndexedDB database.
108
+
107
109
  ***
108
110
 
109
111
  ### storeName
@@ -112,6 +114,8 @@ readonly dbName: string;
112
114
  readonly storeName: S;
113
115
  ```
114
116
 
117
+ The name of the object store within the database.
118
+
115
119
  ## Methods
116
120
 
117
121
  ### clear()?
@@ -120,6 +124,8 @@ readonly storeName: S;
120
124
  optional clear(): Promise<void>;
121
125
  ```
122
126
 
127
+ Removes all entries from the store.
128
+
123
129
  ### Returns
124
130
 
125
131
  `Promise`\<`void`\>
@@ -138,12 +144,16 @@ KeyValueStore.clear
138
144
  delete(key): Promise<void>;
139
145
  ```
140
146
 
147
+ Deletes the entry with the given key.
148
+
141
149
  ### Parameters
142
150
 
143
151
  #### key
144
152
 
145
153
  `StoreKey`\<`T`, `S`\>
146
154
 
155
+ The key of the entry to delete
156
+
147
157
  ### Returns
148
158
 
149
159
  `Promise`\<`void`\>
@@ -162,7 +172,7 @@ KeyValueStore.delete
162
172
  get(key): Promise<StoreValue<T, S> | undefined>;
163
173
  ```
164
174
 
165
- Returns a promise that resolves to the value for the given key.
175
+ Retrieves the value associated with the given key.
166
176
 
167
177
  ### Parameters
168
178
 
@@ -170,12 +180,14 @@ Returns a promise that resolves to the value for the given key.
170
180
 
171
181
  `StoreKey`\<`T`, `S`\>
172
182
 
173
- The key to get the value for.
183
+ The key to look up
174
184
 
175
185
  ### Returns
176
186
 
177
187
  `Promise`\<`StoreValue`\<`T`, `S`\> \| `undefined`\>
178
188
 
189
+ The value, or undefined if not found
190
+
179
191
  ### Implementation of
180
192
 
181
193
  ```ts
@@ -190,7 +202,7 @@ KeyValueStore.get
190
202
  optional keys(): Promise<StoreKey<T, S>[]>;
191
203
  ```
192
204
 
193
- The keys an array of keys.
205
+ Returns all keys in the store.
194
206
 
195
207
  ### Returns
196
208
 
@@ -210,16 +222,22 @@ KeyValueStore.keys
210
222
  set(key, value): Promise<void>;
211
223
  ```
212
224
 
225
+ Sets a value for the given key, creating or updating the entry.
226
+
213
227
  ### Parameters
214
228
 
215
229
  #### key
216
230
 
217
231
  `StoreKey`\<`T`, `S`\>
218
232
 
233
+ The key to set
234
+
219
235
  #### value
220
236
 
221
237
  `StoreValue`\<`T`, `S`\>
222
238
 
239
+ The value to store
240
+
223
241
  ### Returns
224
242
 
225
243
  `Promise`\<`void`\>
@@ -238,6 +256,8 @@ KeyValueStore.set
238
256
  withDb<R>(callback): Promise<R>;
239
257
  ```
240
258
 
259
+ Opens the underlying IndexedDB database and passes it to the callback.
260
+
241
261
  ### Type Parameters
242
262
 
243
263
  #### R
@@ -250,10 +270,14 @@ withDb<R>(callback): Promise<R>;
250
270
 
251
271
  (`db`) => `R` \| `Promise`\<`R`\>
252
272
 
273
+ Function to execute with the database
274
+
253
275
  ### Returns
254
276
 
255
277
  `Promise`\<`R`\>
256
278
 
279
+ The result of the callback
280
+
257
281
  ### functions
258
282
 
259
283
  ### <a id="buildStandardIndexName"></a>buildStandardIndexName
@@ -296,24 +320,34 @@ function checkDbNeedsUpgrade(
296
320
  logger?): Promise<number>;
297
321
  ```
298
322
 
323
+ Checks whether any store in the database needs an upgrade and returns the appropriate version number.
324
+
299
325
  ## Parameters
300
326
 
301
327
  ### dbName
302
328
 
303
329
  `string`
304
330
 
331
+ The name of the database to check
332
+
305
333
  ### stores
306
334
 
307
335
  `Record`\<`string`, [`IndexDescription`](#../type-aliases/IndexDescription)[]\>
308
336
 
337
+ Map of store names to their expected index descriptions
338
+
309
339
  ### logger?
310
340
 
311
341
  `Logger`
312
342
 
343
+ Optional logger for diagnostics
344
+
313
345
  ## Returns
314
346
 
315
347
  `Promise`\<`number`\>
316
348
 
349
+ The version to open (current version + 1 if upgrade needed, otherwise current version)
350
+
317
351
  ### <a id="createStoreDuringUpgrade"></a>createStoreDuringUpgrade
318
352
 
319
353
  [**@xylabs/indexed-db**](#../README)
@@ -328,6 +362,8 @@ function createStoreDuringUpgrade<DBTypes>(
328
362
  logger?): void;
329
363
  ```
330
364
 
365
+ Creates an object store with the specified indexes during a version upgrade transaction.
366
+
331
367
  ## Type Parameters
332
368
 
333
369
  ### DBTypes
@@ -340,18 +376,26 @@ function createStoreDuringUpgrade<DBTypes>(
340
376
 
341
377
  `IDBPDatabase`\<`DBTypes`\>
342
378
 
379
+ The IndexedDB database instance (during upgrade)
380
+
343
381
  ### storeName
344
382
 
345
383
  `StoreNames`\<`DBTypes`\>
346
384
 
385
+ The name of the store to create
386
+
347
387
  ### indexes
348
388
 
349
389
  [`IndexDescription`](#../type-aliases/IndexDescription)[]
350
390
 
391
+ The index descriptions to create on the store
392
+
351
393
  ### logger?
352
394
 
353
395
  `Logger`
354
396
 
397
+ Optional logger for diagnostics
398
+
355
399
  ## Returns
356
400
 
357
401
  `void`
@@ -369,6 +413,8 @@ function getExistingIndexes<T>(
369
413
  logger?): Promise<IndexDescription[] | null>;
370
414
  ```
371
415
 
416
+ Retrieves the existing index descriptions for a store. Accepts either a database instance or a database name.
417
+
372
418
  ## Type Parameters
373
419
 
374
420
  ### T
@@ -379,20 +425,28 @@ logger?): Promise<IndexDescription[] | null>;
379
425
 
380
426
  ### db
381
427
 
428
+ The IndexedDB database instance or database name
429
+
382
430
  `string` | `IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
383
431
 
384
432
  ### storeName
385
433
 
386
434
  `StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
387
435
 
436
+ The name of the store to inspect
437
+
388
438
  ### logger?
389
439
 
390
440
  `Logger`
391
441
 
442
+ Optional logger for diagnostics
443
+
392
444
  ## Returns
393
445
 
394
446
  `Promise`\<[`IndexDescription`](#../type-aliases/IndexDescription)[] \| `null`\>
395
447
 
448
+ An array of index descriptions, or null if the store does not exist
449
+
396
450
  ### <a id="withDb"></a>withDb
397
451
 
398
452
  [**@xylabs/indexed-db**](#../README)
@@ -408,6 +462,9 @@ function withDb<DBTypes, R>(
408
462
  lock?): Promise<R>;
409
463
  ```
410
464
 
465
+ Opens an IndexedDB database, automatically upgrading if needed, and passes it to the callback.
466
+ Uses a mutex to serialize access to the same database by default.
467
+
411
468
  ## Type Parameters
412
469
 
413
470
  ### DBTypes
@@ -424,26 +481,38 @@ lock?): Promise<R>;
424
481
 
425
482
  `string`
426
483
 
484
+ The name of the database to open
485
+
427
486
  ### callback
428
487
 
429
488
  (`db`) => `R` \| `Promise`\<`R`\>
430
489
 
490
+ Function to execute with the opened database
491
+
431
492
  ### expectedIndexes?
432
493
 
433
494
  `Record`\<`string`, [`IndexDescription`](#../type-aliases/IndexDescription)[]\>
434
495
 
496
+ Optional map of store names to their expected indexes (triggers upgrade check)
497
+
435
498
  ### logger?
436
499
 
437
500
  `Logger`
438
501
 
502
+ Optional logger for diagnostics
503
+
439
504
  ### lock?
440
505
 
441
506
  `boolean` = `true`
442
507
 
508
+ Whether to use a mutex to serialize access (defaults to true)
509
+
443
510
  ## Returns
444
511
 
445
512
  `Promise`\<`R`\>
446
513
 
514
+ The result of the callback
515
+
447
516
  ### <a id="withDbByVersion"></a>withDbByVersion
448
517
 
449
518
  [**@xylabs/indexed-db**](#../README)
@@ -460,6 +529,9 @@ function withDbByVersion<DBTypes, R>(
460
529
  lock?): Promise<R>;
461
530
  ```
462
531
 
532
+ Opens an IndexedDB database at a specific version, handling upgrade events, and passes it to the callback.
533
+ The database is automatically closed after the callback completes.
534
+
463
535
  ## Type Parameters
464
536
 
465
537
  ### DBTypes
@@ -476,30 +548,44 @@ lock?): Promise<R>;
476
548
 
477
549
  `string`
478
550
 
551
+ The name of the database to open
552
+
479
553
  ### callback
480
554
 
481
555
  (`db`) => `R` \| `Promise`\<`R`\>
482
556
 
557
+ Function to execute with the opened database
558
+
483
559
  ### version?
484
560
 
485
561
  `number`
486
562
 
563
+ Optional specific version to open (undefined for latest)
564
+
487
565
  ### expectedIndexes?
488
566
 
489
567
  `Record`\<`string`, [`IndexDescription`](#../type-aliases/IndexDescription)[]\>
490
568
 
569
+ Optional map of store names to indexes to create during upgrade
570
+
491
571
  ### logger?
492
572
 
493
573
  `Logger`
494
574
 
575
+ Optional logger for diagnostics
576
+
495
577
  ### lock?
496
578
 
497
579
  `boolean` = `true`
498
580
 
581
+ Whether to use a mutex to serialize access (defaults to true)
582
+
499
583
  ## Returns
500
584
 
501
585
  `Promise`\<`R`\>
502
586
 
587
+ The result of the callback
588
+
503
589
  ### <a id="withReadOnlyStore"></a>withReadOnlyStore
504
590
 
505
591
  [**@xylabs/indexed-db**](#../README)
@@ -514,6 +600,8 @@ function withReadOnlyStore<T, R>(
514
600
  logger?): Promise<R>;
515
601
  ```
516
602
 
603
+ Opens a read-only transaction on the specified store and passes it to the callback.
604
+
517
605
  ## Type Parameters
518
606
 
519
607
  ### T
@@ -530,22 +618,32 @@ logger?): Promise<R>;
530
618
 
531
619
  `IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
532
620
 
621
+ The IndexedDB database instance
622
+
533
623
  ### storeName
534
624
 
535
625
  `StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
536
626
 
627
+ The name of the object store to open
628
+
537
629
  ### callback
538
630
 
539
631
  (`store`) => `R` \| `Promise`\<`R`\>
540
632
 
633
+ Function to execute with the read-only store
634
+
541
635
  ### logger?
542
636
 
543
637
  `Logger`
544
638
 
639
+ Optional logger for diagnostics
640
+
545
641
  ## Returns
546
642
 
547
643
  `Promise`\<`R`\>
548
644
 
645
+ The result of the callback
646
+
549
647
  ### <a id="withReadWriteStore"></a>withReadWriteStore
550
648
 
551
649
  [**@xylabs/indexed-db**](#../README)
@@ -560,6 +658,8 @@ function withReadWriteStore<T, R>(
560
658
  logger?): Promise<R>;
561
659
  ```
562
660
 
661
+ Opens a read-write transaction on the specified store and passes it to the callback.
662
+
563
663
  ## Type Parameters
564
664
 
565
665
  ### T
@@ -576,22 +676,32 @@ logger?): Promise<R>;
576
676
 
577
677
  `IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
578
678
 
679
+ The IndexedDB database instance
680
+
579
681
  ### storeName
580
682
 
581
683
  `StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
582
684
 
685
+ The name of the object store to open
686
+
583
687
  ### callback
584
688
 
585
689
  (`store`) => `R` \| `Promise`\<`R`\>
586
690
 
691
+ Function to execute with the read-write store
692
+
587
693
  ### logger?
588
694
 
589
695
  `Logger`
590
696
 
697
+ Optional logger for diagnostics
698
+
591
699
  ## Returns
592
700
 
593
701
  `Promise`\<`R`\>
594
702
 
703
+ The result of the callback
704
+
595
705
  ### <a id="withStore"></a>withStore
596
706
 
597
707
  [**@xylabs/indexed-db**](#../README)
@@ -607,6 +717,9 @@ function withStore<T, R, M>(
607
717
  logger?): Promise<R>;
608
718
  ```
609
719
 
720
+ Opens a transaction on the specified store with the given mode and passes the store to the callback.
721
+ If the store does not exist, the callback receives null.
722
+
610
723
  ## Type Parameters
611
724
 
612
725
  ### T
@@ -627,26 +740,38 @@ logger?): Promise<R>;
627
740
 
628
741
  `IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
629
742
 
743
+ The IndexedDB database instance
744
+
630
745
  ### storeName
631
746
 
632
747
  `StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
633
748
 
749
+ The name of the object store to open
750
+
634
751
  ### callback
635
752
 
636
753
  (`store`) => `R` \| `Promise`\<`R`\>
637
754
 
755
+ Function to execute with the store (or null if it doesn't exist)
756
+
638
757
  ### mode
639
758
 
640
759
  `M`
641
760
 
761
+ The transaction mode ('readonly' or 'readwrite')
762
+
642
763
  ### logger?
643
764
 
644
765
  `Logger`
645
766
 
767
+ Optional logger for diagnostics
768
+
646
769
  ## Returns
647
770
 
648
771
  `Promise`\<`R`\>
649
772
 
773
+ The result of the callback
774
+
650
775
  ### interfaces
651
776
 
652
777
  ### <a id="ObjectStore"></a>ObjectStore
@@ -655,6 +780,8 @@ logger?): Promise<R>;
655
780
 
656
781
  ***
657
782
 
783
+ Generic IndexedDB schema type that maps store names to their value types.
784
+
658
785
  ## Type Parameters
659
786
 
660
787
  ### T
@@ -735,6 +862,8 @@ The index direction (1 for ascending, -1 for descending)
735
862
  const IndexSeparator: "-" = '-';
736
863
  ```
737
864
 
865
+ Separator used between key names when building standard index names.
866
+
738
867
 
739
868
  Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
740
869
 
@@ -19,6 +19,7 @@ export type IndexDescription = {
19
19
  */
20
20
  unique?: boolean;
21
21
  };
22
+ /** Separator used between key names when building standard index names. */
22
23
  export declare const IndexSeparator = "-";
23
24
  /**
24
25
  * Given an index description, this will build the index
@@ -1 +1 @@
1
- {"version":3,"file":"IndexDescription.d.ts","sourceRoot":"","sources":["../../src/IndexDescription.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,GAAG,CAAC,CAAA;AAEnC;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IACnC;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,cAAc,MAAM,CAAA;AAEjC;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GAAI,OAAO,gBAAgB,WAK7D,CAAA"}
1
+ {"version":3,"file":"IndexDescription.d.ts","sourceRoot":"","sources":["../../src/IndexDescription.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,GAAG,CAAC,CAAA;AAEnC;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IACnC;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,2EAA2E;AAC3E,eAAO,MAAM,cAAc,MAAM,CAAA;AAEjC;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GAAI,OAAO,gBAAgB,WAK7D,CAAA"}
@@ -4,14 +4,37 @@ import type { DBSchema, IDBPDatabase, StoreKey, StoreNames, StoreValue } from 'i
4
4
  * An IndexedDB key/value store.
5
5
  */
6
6
  export declare class IndexedDbKeyValueStore<T extends DBSchema, S extends StoreNames<T>> implements KeyValueStore<StoreValue<T, S>, StoreKey<T, S>> {
7
+ /** The name of the IndexedDB database. */
7
8
  readonly dbName: string;
9
+ /** The name of the object store within the database. */
8
10
  readonly storeName: S;
9
11
  constructor(dbName: string, storeName: S);
12
+ /** Removes all entries from the store. */
10
13
  clear?(): Promise<void>;
14
+ /**
15
+ * Deletes the entry with the given key.
16
+ * @param key The key of the entry to delete
17
+ */
11
18
  delete(key: StoreKey<T, S>): Promise<void>;
19
+ /**
20
+ * Retrieves the value associated with the given key.
21
+ * @param key The key to look up
22
+ * @returns The value, or undefined if not found
23
+ */
12
24
  get(key: StoreKey<T, S>): Promise<StoreValue<T, S> | undefined>;
25
+ /** Returns all keys in the store. */
13
26
  keys?(): Promise<StoreKey<T, S>[]>;
27
+ /**
28
+ * Sets a value for the given key, creating or updating the entry.
29
+ * @param key The key to set
30
+ * @param value The value to store
31
+ */
14
32
  set(key: StoreKey<T, S>, value: StoreValue<T, S>): Promise<void>;
33
+ /**
34
+ * Opens the underlying IndexedDB database and passes it to the callback.
35
+ * @param callback Function to execute with the database
36
+ * @returns The result of the callback
37
+ */
15
38
  withDb<R = StoreValue<T, S>>(callback: (db: IDBPDatabase<T>) => Promise<R> | R): Promise<R>;
16
39
  }
17
40
  //# sourceMappingURL=IndexedDbKeyValueStore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"IndexedDbKeyValueStore.d.ts","sourceRoot":"","sources":["../../src/IndexedDbKeyValueStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAC/C,MAAM,KAAK,CAAA;AAIZ;;GAEG;AACH,qBAAa,sBAAsB,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACzI,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAA;gBAET,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAKlC,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;IAMvB,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAM1C,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;IAQvB,IAAI,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAMlC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAMhE,MAAM,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EAC/B,QAAQ,EAAE,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC,KAC5B,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;CAMnB"}
1
+ {"version":3,"file":"IndexedDbKeyValueStore.d.ts","sourceRoot":"","sources":["../../src/IndexedDbKeyValueStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAC/C,MAAM,KAAK,CAAA;AAIZ;;GAEG;AACH,qBAAa,sBAAsB,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACzI,0CAA0C;IAC1C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,wDAAwD;IACxD,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAA;gBAET,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAKxC,0CAA0C;IACpC,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;IAM7B;;;OAGG;IACG,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAMhD;;;;OAIG;IACG,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;IAQ7B,qCAAqC;IAC/B,IAAI,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAMxC;;;;OAIG;IACG,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtE;;;;OAIG;IACG,MAAM,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EAC/B,QAAQ,EAAE,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC,KAC5B,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;CAMnB"}
@@ -1,4 +1,5 @@
1
1
  import type { EmptyObject } from '@xylabs/object';
2
+ /** Generic IndexedDB schema type that maps store names to their value types. */
2
3
  export interface ObjectStore<T extends EmptyObject = EmptyObject> {
3
4
  [s: string]: T;
4
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ObjectStore.d.ts","sourceRoot":"","sources":["../../src/ObjectStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAEjD,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW;IAC9D,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAA;CACf"}
1
+ {"version":3,"file":"ObjectStore.d.ts","sourceRoot":"","sources":["../../src/ObjectStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAEjD,gFAAgF;AAChF,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW;IAC9D,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAA;CACf"}
@@ -1,4 +1,11 @@
1
1
  import type { Logger } from '@xylabs/logger';
2
2
  import { type IndexDescription } from './IndexDescription.ts';
3
+ /**
4
+ * Checks whether any store in the database needs an upgrade and returns the appropriate version number.
5
+ * @param dbName The name of the database to check
6
+ * @param stores Map of store names to their expected index descriptions
7
+ * @param logger Optional logger for diagnostics
8
+ * @returns The version to open (current version + 1 if upgrade needed, otherwise current version)
9
+ */
3
10
  export declare function checkDbNeedsUpgrade(dbName: string, stores: Record<string, IndexDescription[]>, logger?: Logger): Promise<number>;
4
11
  //# sourceMappingURL=checkDbNeedsUpgrade.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkDbNeedsUpgrade.d.ts","sourceRoot":"","sources":["../../src/checkDbNeedsUpgrade.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAG5C,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAI7D,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,mBAUpH"}
1
+ {"version":3,"file":"checkDbNeedsUpgrade.d.ts","sourceRoot":"","sources":["../../src/checkDbNeedsUpgrade.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAG5C,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAI7D;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,mBAUpH"}
@@ -2,5 +2,13 @@ import type { Logger } from '@xylabs/logger';
2
2
  import type { IDBPDatabase } from 'idb';
3
3
  import { type IndexDescription } from './IndexDescription.ts';
4
4
  import type { ObjectStore } from './ObjectStore.ts';
5
+ /**
6
+ * Checks whether a store needs an upgrade by comparing its existing indexes against expected indexes.
7
+ * @param db The IndexedDB database instance
8
+ * @param storeName The name of the store to check
9
+ * @param indexes The expected index descriptions
10
+ * @param logger Optional logger for diagnostics
11
+ * @returns True if the store is missing or has missing indexes
12
+ */
5
13
  export declare function checkStoreNeedsUpgrade(db: IDBPDatabase<ObjectStore<object>>, storeName: string, indexes: IndexDescription[], logger?: Logger): Promise<boolean>;
6
14
  //# sourceMappingURL=checkStoreNeedsUpgrade.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkStoreNeedsUpgrade.d.ts","sourceRoot":"","sources":["../../src/checkStoreNeedsUpgrade.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,KAAK,CAAA;AAGvC,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD,wBAAsB,sBAAsB,CAAC,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,oBAelJ"}
1
+ {"version":3,"file":"checkStoreNeedsUpgrade.d.ts","sourceRoot":"","sources":["../../src/checkStoreNeedsUpgrade.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,KAAK,CAAA;AAGvC,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAAC,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,oBAelJ"}
@@ -1,5 +1,12 @@
1
1
  import type { Logger } from '@xylabs/logger';
2
2
  import type { DBSchema, IDBPDatabase, StoreNames } from 'idb';
3
3
  import { type IndexDescription } from './IndexDescription.ts';
4
+ /**
5
+ * Creates an object store with the specified indexes during a version upgrade transaction.
6
+ * @param db The IndexedDB database instance (during upgrade)
7
+ * @param storeName The name of the store to create
8
+ * @param indexes The index descriptions to create on the store
9
+ * @param logger Optional logger for diagnostics
10
+ */
4
11
  export declare function createStoreDuringUpgrade<DBTypes extends DBSchema | unknown = unknown>(db: IDBPDatabase<DBTypes>, storeName: StoreNames<DBTypes>, indexes: IndexDescription[], logger?: Logger): void;
5
12
  //# sourceMappingURL=createStoreDuringUpgrade.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createStoreDuringUpgrade.d.ts","sourceRoot":"","sources":["../../src/createStoreDuringUpgrade.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EAA+B,UAAU,EACtD,MAAM,KAAK,CAAA;AAEZ,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,uBAAuB,CAAA;AAE9B,wBAAgB,wBAAwB,CAAC,OAAO,SAAS,QAAQ,GAAG,OAAO,GAAG,OAAO,EACnF,EAAE,EAAE,YAAY,CAAC,OAAO,CAAC,EACzB,SAAS,EAAE,UAAU,CAAC,OAAO,CAAC,EAC9B,OAAO,EAAE,gBAAgB,EAAE,EAC3B,MAAM,CAAC,EAAE,MAAM,QA4BhB"}
1
+ {"version":3,"file":"createStoreDuringUpgrade.d.ts","sourceRoot":"","sources":["../../src/createStoreDuringUpgrade.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EAA+B,UAAU,EACtD,MAAM,KAAK,CAAA;AAEZ,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,uBAAuB,CAAA;AAE9B;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,SAAS,QAAQ,GAAG,OAAO,GAAG,OAAO,EACnF,EAAE,EAAE,YAAY,CAAC,OAAO,CAAC,EACzB,SAAS,EAAE,UAAU,CAAC,OAAO,CAAC,EAC9B,OAAO,EAAE,gBAAgB,EAAE,EAC3B,MAAM,CAAC,EAAE,MAAM,QA4BhB"}
@@ -3,5 +3,12 @@ import type { EmptyObject } from '@xylabs/object';
3
3
  import type { IDBPDatabase, StoreNames } from 'idb';
4
4
  import { type IndexDescription } from './IndexDescription.ts';
5
5
  import type { ObjectStore } from './ObjectStore.ts';
6
+ /**
7
+ * Retrieves the existing index descriptions for a store. Accepts either a database instance or a database name.
8
+ * @param db The IndexedDB database instance or database name
9
+ * @param storeName The name of the store to inspect
10
+ * @param logger Optional logger for diagnostics
11
+ * @returns An array of index descriptions, or null if the store does not exist
12
+ */
6
13
  export declare function getExistingIndexes<T extends EmptyObject = EmptyObject>(db: IDBPDatabase<ObjectStore<T>> | string, storeName: StoreNames<ObjectStore<T>>, logger?: Logger): Promise<IndexDescription[] | null>;
7
14
  //# sourceMappingURL=getExistingIndexes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getExistingIndexes.d.ts","sourceRoot":"","sources":["../../src/getExistingIndexes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAEnD,OAAO,EACL,KAAK,gBAAgB,EAEtB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAiCnD,wBAAsB,kBAAkB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAC1E,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,EACzC,SAAS,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EACrC,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAQpC"}
1
+ {"version":3,"file":"getExistingIndexes.d.ts","sourceRoot":"","sources":["../../src/getExistingIndexes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAEnD,OAAO,EACL,KAAK,gBAAgB,EAEtB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAiCnD;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAC1E,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,EACzC,SAAS,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EACrC,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAQpC"}
@@ -191,37 +191,60 @@ async function withDb(dbName, callback, expectedIndexes, logger, lock = true) {
191
191
 
192
192
  // src/IndexedDbKeyValueStore.ts
193
193
  var IndexedDbKeyValueStore = class {
194
+ /** The name of the IndexedDB database. */
194
195
  dbName;
196
+ /** The name of the object store within the database. */
195
197
  storeName;
196
198
  constructor(dbName, storeName) {
197
199
  this.dbName = dbName;
198
200
  this.storeName = storeName;
199
201
  }
202
+ /** Removes all entries from the store. */
200
203
  async clear() {
201
204
  return await this.withDb((db) => {
202
205
  return db.clear(this.storeName);
203
206
  });
204
207
  }
208
+ /**
209
+ * Deletes the entry with the given key.
210
+ * @param key The key of the entry to delete
211
+ */
205
212
  async delete(key) {
206
213
  return await this.withDb((db) => {
207
214
  return db.delete(this.storeName, key);
208
215
  });
209
216
  }
217
+ /**
218
+ * Retrieves the value associated with the given key.
219
+ * @param key The key to look up
220
+ * @returns The value, or undefined if not found
221
+ */
210
222
  async get(key) {
211
223
  return await this.withDb((db) => {
212
224
  return db.get(this.storeName, key) ?? void 0;
213
225
  });
214
226
  }
227
+ /** Returns all keys in the store. */
215
228
  async keys() {
216
229
  return await this.withDb((db) => {
217
230
  return db.getAllKeys(this.storeName);
218
231
  });
219
232
  }
233
+ /**
234
+ * Sets a value for the given key, creating or updating the entry.
235
+ * @param key The key to set
236
+ * @param value The value to store
237
+ */
220
238
  async set(key, value) {
221
239
  return await this.withDb(async (db) => {
222
240
  await db.put(this.storeName, value, key);
223
241
  });
224
242
  }
243
+ /**
244
+ * Opens the underlying IndexedDB database and passes it to the callback.
245
+ * @param callback Function to execute with the database
246
+ * @returns The result of the callback
247
+ */
225
248
  async withDb(callback) {
226
249
  return await withDb(this.dbName, (db) => {
227
250
  return callback(db);