@xylabs/indexed-db 4.13.20 → 4.13.21

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 (2) hide show
  1. package/README.md +719 -3
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -12,13 +12,729 @@
12
12
  [![snyk-badge][]][snyk-link]
13
13
  [![socket-badge][]][socket-link]
14
14
 
15
- Version: 4.13.19
16
15
 
17
16
  Base functionality used throughout XY Labs TypeScript/JavaScript libraries
18
17
 
19
- ## Documentation
18
+ ## API Documentation
19
+
20
+ **@xylabs/indexed-db**
21
+
22
+ ***
23
+
24
+ ## Classes
25
+
26
+ - [IndexedDbKeyValueStore](#classes/IndexedDbKeyValueStore)
27
+
28
+ ## Interfaces
29
+
30
+ - [ObjectStore](#interfaces/ObjectStore)
31
+
32
+ ## Type Aliases
33
+
34
+ - [IndexDirection](#type-aliases/IndexDirection)
35
+ - [IndexDescription](#type-aliases/IndexDescription)
36
+
37
+ ## Variables
38
+
39
+ - [IndexSeparator](#variables/IndexSeparator)
40
+
41
+ ## Functions
42
+
43
+ - [buildStandardIndexName](#functions/buildStandardIndexName)
44
+ - [checkDbNeedsUpgrade](#functions/checkDbNeedsUpgrade)
45
+ - [createStoreDuringUpgrade](#functions/createStoreDuringUpgrade)
46
+ - [getExistingIndexes](#functions/getExistingIndexes)
47
+ - [withDb](#functions/withDb)
48
+ - [withDbByVersion](#functions/withDbByVersion)
49
+ - [withReadOnlyStore](#functions/withReadOnlyStore)
50
+ - [withReadWriteStore](#functions/withReadWriteStore)
51
+ - [withStore](#functions/withStore)
52
+
53
+ ### classes
54
+
55
+ ### <a id="IndexedDbKeyValueStore"></a>IndexedDbKeyValueStore
56
+
57
+ [**@xylabs/indexed-db**](#../README)
58
+
59
+ ***
60
+
61
+ An IndexedDB key/value store.
62
+
63
+ ## Type Parameters
64
+
65
+ ### T
66
+
67
+ `T` *extends* `DBSchema`
68
+
69
+ ### S
70
+
71
+ `S` *extends* `StoreNames`\<`T`\>
72
+
73
+ ## Implements
74
+
75
+ - `KeyValueStore`\<`StoreValue`\<`T`, `S`\>, `StoreKey`\<`T`, `S`\>\>
76
+
77
+ ## Constructors
78
+
79
+ ### Constructor
80
+
81
+ ```ts
82
+ new IndexedDbKeyValueStore<T, S>(dbName, storeName): IndexedDbKeyValueStore<T, S>;
83
+ ```
84
+
85
+ ### Parameters
86
+
87
+ #### dbName
88
+
89
+ `string`
90
+
91
+ #### storeName
92
+
93
+ `S`
94
+
95
+ ### Returns
96
+
97
+ `IndexedDbKeyValueStore`\<`T`, `S`\>
98
+
99
+ ## Properties
100
+
101
+ ### dbName
102
+
103
+ ```ts
104
+ readonly dbName: string;
105
+ ```
106
+
107
+ ***
108
+
109
+ ### storeName
110
+
111
+ ```ts
112
+ readonly storeName: S;
113
+ ```
114
+
115
+ ## Methods
116
+
117
+ ### clear()?
118
+
119
+ ```ts
120
+ optional clear(): Promise<void>;
121
+ ```
122
+
123
+ ### Returns
124
+
125
+ `Promise`\<`void`\>
126
+
127
+ ### Implementation of
128
+
129
+ ```ts
130
+ KeyValueStore.clear
131
+ ```
132
+
133
+ ***
134
+
135
+ ### delete()
136
+
137
+ ```ts
138
+ delete(key): Promise<void>;
139
+ ```
140
+
141
+ ### Parameters
142
+
143
+ #### key
144
+
145
+ `StoreKey`\<`T`, `S`\>
146
+
147
+ ### Returns
148
+
149
+ `Promise`\<`void`\>
150
+
151
+ ### Implementation of
152
+
153
+ ```ts
154
+ KeyValueStore.delete
155
+ ```
156
+
157
+ ***
158
+
159
+ ### get()
160
+
161
+ ```ts
162
+ get(key): Promise<undefined | StoreValue<T, S>>;
163
+ ```
164
+
165
+ Returns a promise that resolves to the value for the given key.
166
+
167
+ ### Parameters
168
+
169
+ #### key
170
+
171
+ `StoreKey`\<`T`, `S`\>
172
+
173
+ The key to get the value for.
174
+
175
+ ### Returns
176
+
177
+ `Promise`\<`undefined` \| `StoreValue`\<`T`, `S`\>\>
178
+
179
+ ### Implementation of
180
+
181
+ ```ts
182
+ KeyValueStore.get
183
+ ```
184
+
185
+ ***
186
+
187
+ ### keys()?
188
+
189
+ ```ts
190
+ optional keys(): Promise<StoreKey<T, S>[]>;
191
+ ```
192
+
193
+ The keys an array of keys.
194
+
195
+ ### Returns
196
+
197
+ `Promise`\<`StoreKey`\<`T`, `S`\>[]\>
198
+
199
+ ### Implementation of
200
+
201
+ ```ts
202
+ KeyValueStore.keys
203
+ ```
204
+
205
+ ***
206
+
207
+ ### set()
208
+
209
+ ```ts
210
+ set(key, value): Promise<void>;
211
+ ```
212
+
213
+ ### Parameters
214
+
215
+ #### key
216
+
217
+ `StoreKey`\<`T`, `S`\>
218
+
219
+ #### value
220
+
221
+ `StoreValue`\<`T`, `S`\>
222
+
223
+ ### Returns
224
+
225
+ `Promise`\<`void`\>
226
+
227
+ ### Implementation of
228
+
229
+ ```ts
230
+ KeyValueStore.set
231
+ ```
232
+
233
+ ***
234
+
235
+ ### withDb()
236
+
237
+ ```ts
238
+ withDb<R>(callback): Promise<R>;
239
+ ```
240
+
241
+ ### Type Parameters
242
+
243
+ #### R
244
+
245
+ `R` = `StoreValue`\<`T`, `S`\>
246
+
247
+ ### Parameters
248
+
249
+ #### callback
250
+
251
+ (`db`) => `R` \| `Promise`\<`R`\>
252
+
253
+ ### Returns
254
+
255
+ `Promise`\<`R`\>
256
+
257
+ ### functions
258
+
259
+ ### <a id="buildStandardIndexName"></a>buildStandardIndexName
260
+
261
+ [**@xylabs/indexed-db**](#../README)
262
+
263
+ ***
264
+
265
+ ```ts
266
+ function buildStandardIndexName(index): string;
267
+ ```
268
+
269
+ Given an index description, this will build the index
270
+ name in standard form
271
+
272
+ ## Parameters
273
+
274
+ ### index
275
+
276
+ [`IndexDescription`](#../type-aliases/IndexDescription)
277
+
278
+ The index description
279
+
280
+ ## Returns
281
+
282
+ `string`
283
+
284
+ The index name in standard form
285
+
286
+ ### <a id="checkDbNeedsUpgrade"></a>checkDbNeedsUpgrade
287
+
288
+ [**@xylabs/indexed-db**](#../README)
289
+
290
+ ***
291
+
292
+ ```ts
293
+ function checkDbNeedsUpgrade(
294
+ dbName,
295
+ stores,
296
+ logger?): Promise<number>;
297
+ ```
298
+
299
+ ## Parameters
300
+
301
+ ### dbName
302
+
303
+ `string`
304
+
305
+ ### stores
306
+
307
+ `Record`\<`string`, [`IndexDescription`](#../type-aliases/IndexDescription)[]\>
308
+
309
+ ### logger?
310
+
311
+ `Logger`
312
+
313
+ ## Returns
314
+
315
+ `Promise`\<`number`\>
316
+
317
+ ### <a id="createStoreDuringUpgrade"></a>createStoreDuringUpgrade
318
+
319
+ [**@xylabs/indexed-db**](#../README)
320
+
321
+ ***
322
+
323
+ ```ts
324
+ function createStoreDuringUpgrade<DBTypes>(
325
+ db,
326
+ storeName,
327
+ indexes,
328
+ logger?): void;
329
+ ```
330
+
331
+ ## Type Parameters
332
+
333
+ ### DBTypes
334
+
335
+ `DBTypes` *extends* `unknown` = `unknown`
336
+
337
+ ## Parameters
338
+
339
+ ### db
340
+
341
+ `IDBPDatabase`\<`DBTypes`\>
342
+
343
+ ### storeName
344
+
345
+ `StoreNames`\<`DBTypes`\>
346
+
347
+ ### indexes
348
+
349
+ [`IndexDescription`](#../type-aliases/IndexDescription)[]
350
+
351
+ ### logger?
352
+
353
+ `Logger`
354
+
355
+ ## Returns
356
+
357
+ `void`
358
+
359
+ ### <a id="getExistingIndexes"></a>getExistingIndexes
360
+
361
+ [**@xylabs/indexed-db**](#../README)
362
+
363
+ ***
364
+
365
+ ```ts
366
+ function getExistingIndexes<T>(
367
+ db,
368
+ storeName,
369
+ logger?): Promise<null | IndexDescription[]>;
370
+ ```
371
+
372
+ ## Type Parameters
373
+
374
+ ### T
375
+
376
+ `T` *extends* `object` = `object`
377
+
378
+ ## Parameters
379
+
380
+ ### db
381
+
382
+ `string` | `IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
383
+
384
+ ### storeName
385
+
386
+ `StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
387
+
388
+ ### logger?
389
+
390
+ `Logger`
391
+
392
+ ## Returns
393
+
394
+ `Promise`\<`null` \| [`IndexDescription`](#../type-aliases/IndexDescription)[]\>
395
+
396
+ ### <a id="withDb"></a>withDb
397
+
398
+ [**@xylabs/indexed-db**](#../README)
399
+
400
+ ***
401
+
402
+ ```ts
403
+ function withDb<DBTypes, R>(
404
+ dbName,
405
+ callback,
406
+ expectedIndexes?,
407
+ logger?,
408
+ lock?): Promise<R>;
409
+ ```
410
+
411
+ ## Type Parameters
412
+
413
+ ### DBTypes
414
+
415
+ `DBTypes` *extends* `unknown` = `unknown`
416
+
417
+ ### R
418
+
419
+ `R` = `object`
420
+
421
+ ## Parameters
422
+
423
+ ### dbName
424
+
425
+ `string`
426
+
427
+ ### callback
428
+
429
+ (`db`) => `R` \| `Promise`\<`R`\>
430
+
431
+ ### expectedIndexes?
432
+
433
+ `Record`\<`string`, [`IndexDescription`](#../type-aliases/IndexDescription)[]\>
434
+
435
+ ### logger?
436
+
437
+ `Logger`
438
+
439
+ ### lock?
440
+
441
+ `boolean` = `true`
442
+
443
+ ## Returns
444
+
445
+ `Promise`\<`R`\>
446
+
447
+ ### <a id="withDbByVersion"></a>withDbByVersion
448
+
449
+ [**@xylabs/indexed-db**](#../README)
450
+
451
+ ***
452
+
453
+ ```ts
454
+ function withDbByVersion<DBTypes, R>(
455
+ dbName,
456
+ callback,
457
+ version?,
458
+ expectedIndexes?,
459
+ logger?,
460
+ lock?): Promise<R>;
461
+ ```
462
+
463
+ ## Type Parameters
464
+
465
+ ### DBTypes
466
+
467
+ `DBTypes` *extends* `unknown` = `unknown`
468
+
469
+ ### R
470
+
471
+ `R` = `object`
472
+
473
+ ## Parameters
474
+
475
+ ### dbName
476
+
477
+ `string`
478
+
479
+ ### callback
480
+
481
+ (`db`) => `R` \| `Promise`\<`R`\>
482
+
483
+ ### version?
484
+
485
+ `number`
486
+
487
+ ### expectedIndexes?
488
+
489
+ `Record`\<`string`, [`IndexDescription`](#../type-aliases/IndexDescription)[]\>
490
+
491
+ ### logger?
492
+
493
+ `Logger`
494
+
495
+ ### lock?
496
+
497
+ `boolean` = `true`
498
+
499
+ ## Returns
500
+
501
+ `Promise`\<`R`\>
502
+
503
+ ### <a id="withReadOnlyStore"></a>withReadOnlyStore
504
+
505
+ [**@xylabs/indexed-db**](#../README)
506
+
507
+ ***
508
+
509
+ ```ts
510
+ function withReadOnlyStore<T, R>(
511
+ db,
512
+ storeName,
513
+ callback,
514
+ logger?): Promise<R>;
515
+ ```
516
+
517
+ ## Type Parameters
518
+
519
+ ### T
520
+
521
+ `T` *extends* `object` = `object`
522
+
523
+ ### R
524
+
525
+ `R` = `T`
526
+
527
+ ## Parameters
528
+
529
+ ### db
530
+
531
+ `IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
532
+
533
+ ### storeName
534
+
535
+ `StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
536
+
537
+ ### callback
538
+
539
+ (`store`) => `R` \| `Promise`\<`R`\>
540
+
541
+ ### logger?
542
+
543
+ `Logger`
544
+
545
+ ## Returns
546
+
547
+ `Promise`\<`R`\>
548
+
549
+ ### <a id="withReadWriteStore"></a>withReadWriteStore
550
+
551
+ [**@xylabs/indexed-db**](#../README)
552
+
553
+ ***
554
+
555
+ ```ts
556
+ function withReadWriteStore<T, R>(
557
+ db,
558
+ storeName,
559
+ callback,
560
+ logger?): Promise<R>;
561
+ ```
562
+
563
+ ## Type Parameters
564
+
565
+ ### T
566
+
567
+ `T` *extends* `object` = `object`
568
+
569
+ ### R
570
+
571
+ `R` = `T`
572
+
573
+ ## Parameters
574
+
575
+ ### db
576
+
577
+ `IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
578
+
579
+ ### storeName
580
+
581
+ `StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
582
+
583
+ ### callback
584
+
585
+ (`store`) => `R` \| `Promise`\<`R`\>
586
+
587
+ ### logger?
588
+
589
+ `Logger`
590
+
591
+ ## Returns
592
+
593
+ `Promise`\<`R`\>
594
+
595
+ ### <a id="withStore"></a>withStore
596
+
597
+ [**@xylabs/indexed-db**](#../README)
598
+
599
+ ***
600
+
601
+ ```ts
602
+ function withStore<T, R, M>(
603
+ db,
604
+ storeName,
605
+ callback,
606
+ mode,
607
+ logger?): Promise<R>;
608
+ ```
609
+
610
+ ## Type Parameters
611
+
612
+ ### T
613
+
614
+ `T` *extends* `object` = `object`
615
+
616
+ ### R
617
+
618
+ `R` = `T`
619
+
620
+ ### M
621
+
622
+ `M` *extends* `"readonly"` \| `"readwrite"` = `"readonly"`
623
+
624
+ ## Parameters
625
+
626
+ ### db
627
+
628
+ `IDBPDatabase`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
629
+
630
+ ### storeName
631
+
632
+ `StoreNames`\<[`ObjectStore`](#../interfaces/ObjectStore)\<`T`\>\>
633
+
634
+ ### callback
635
+
636
+ (`store`) => `R` \| `Promise`\<`R`\>
637
+
638
+ ### mode
639
+
640
+ `M`
641
+
642
+ ### logger?
643
+
644
+ `Logger`
645
+
646
+ ## Returns
647
+
648
+ `Promise`\<`R`\>
649
+
650
+ ### interfaces
651
+
652
+ ### <a id="ObjectStore"></a>ObjectStore
653
+
654
+ [**@xylabs/indexed-db**](#../README)
655
+
656
+ ***
657
+
658
+ ## Type Parameters
659
+
660
+ ### T
661
+
662
+ `T` *extends* `EmptyObject` = `EmptyObject`
663
+
664
+ ## Indexable
665
+
666
+ ```ts
667
+ [s: string]: T
668
+ ```
669
+
670
+ ### type-aliases
671
+
672
+ ### <a id="IndexDescription"></a>IndexDescription
673
+
674
+ [**@xylabs/indexed-db**](#../README)
675
+
676
+ ***
677
+
678
+ ```ts
679
+ type IndexDescription = object;
680
+ ```
681
+
682
+ Description of index(es) to be created on a store
683
+
684
+ ## Properties
685
+
686
+ ### key
687
+
688
+ ```ts
689
+ key: Record<string, IndexDirection>;
690
+ ```
691
+
692
+ The key(s) to index
693
+
694
+ ***
695
+
696
+ ### multiEntry?
697
+
698
+ ```ts
699
+ optional multiEntry: boolean;
700
+ ```
701
+
702
+ Is the indexed value an array
703
+
704
+ ***
705
+
706
+ ### unique?
707
+
708
+ ```ts
709
+ optional unique: boolean;
710
+ ```
711
+
712
+ If true, the index must enforce uniqueness on the key
713
+
714
+ ### <a id="IndexDirection"></a>IndexDirection
715
+
716
+ [**@xylabs/indexed-db**](#../README)
717
+
718
+ ***
719
+
720
+ ```ts
721
+ type IndexDirection = -1 | 1;
722
+ ```
723
+
724
+ The index direction (1 for ascending, -1 for descending)
725
+
726
+ ### variables
727
+
728
+ ### <a id="IndexSeparator"></a>IndexSeparator
729
+
730
+ [**@xylabs/indexed-db**](#../README)
731
+
732
+ ***
733
+
734
+ ```ts
735
+ const IndexSeparator: "-" = '-';
736
+ ```
20
737
 
21
- Coming Soon!
22
738
 
23
739
  Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
24
740
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/indexed-db",
3
- "version": "4.13.20",
3
+ "version": "4.13.21",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "hex",
@@ -54,10 +54,10 @@
54
54
  "src"
55
55
  ],
56
56
  "dependencies": {
57
- "@xylabs/exists": "^4.13.20",
58
- "@xylabs/logger": "^4.13.20",
59
- "@xylabs/object": "^4.13.20",
60
- "@xylabs/storage": "^4.13.20",
57
+ "@xylabs/exists": "^4.13.21",
58
+ "@xylabs/logger": "^4.13.21",
59
+ "@xylabs/object": "^4.13.21",
60
+ "@xylabs/storage": "^4.13.21",
61
61
  "async-mutex": "^0.5.0",
62
62
  "idb": "^8.0.3"
63
63
  },