indexeddbshim 17.7.0 → 19.0.0
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 +13 -3
- package/dist/DOMException.d.ts +5 -9
- package/dist/DOMException.d.ts.map +1 -1
- package/dist/DOMStringList.d.ts +1 -2
- package/dist/DOMStringList.d.ts.map +1 -1
- package/dist/IDBCursor.d.ts +106 -52
- package/dist/IDBCursor.d.ts.map +1 -1
- package/dist/IDBFactory.d.ts.map +1 -1
- package/dist/IDBIndex.d.ts +8 -7
- package/dist/IDBIndex.d.ts.map +1 -1
- package/dist/IDBKeyRange.d.ts +3 -3
- package/dist/IDBKeyRange.d.ts.map +1 -1
- package/dist/IDBObjectStore.d.ts +12 -12
- package/dist/IDBObjectStore.d.ts.map +1 -1
- package/dist/IDBRequest.d.ts +2 -2
- package/dist/IDBRequest.d.ts.map +1 -1
- package/dist/IDBTransaction.d.ts +13 -13
- package/dist/IDBTransaction.d.ts.map +1 -1
- package/dist/Key.d.ts +14 -15
- package/dist/Key.d.ts.map +1 -1
- package/dist/Sca.d.ts +2 -2
- package/dist/Sca.d.ts.map +1 -1
- package/dist/cmp.d.ts +3 -3
- package/dist/cmp.d.ts.map +1 -1
- package/dist/indexeddbshim-Key.js +37 -46
- package/dist/indexeddbshim-Key.js.map +1 -1
- package/dist/indexeddbshim-Key.min.js +2 -2
- package/dist/indexeddbshim-Key.min.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs +254 -215
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.js +251 -450
- package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js +3 -3
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
- package/dist/indexeddbshim-node.cjs +254 -215
- package/dist/indexeddbshim-node.cjs.map +1 -1
- package/dist/indexeddbshim-noninvasive.js +251 -450
- package/dist/indexeddbshim-noninvasive.js.map +1 -1
- package/dist/indexeddbshim-noninvasive.min.js +3 -3
- package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
- package/dist/indexeddbshim.js +251 -450
- package/dist/indexeddbshim.js.map +1 -1
- package/dist/indexeddbshim.min.js +3 -3
- package/dist/indexeddbshim.min.js.map +1 -1
- package/dist/nodeWebSQL.d.ts +2 -2
- package/dist/nodeWebSQL.d.ts.map +1 -1
- package/dist/setGlobalVars.d.ts +1 -2
- package/dist/setGlobalVars.d.ts.map +1 -1
- package/dist/util.d.ts +35 -22
- package/dist/util.d.ts.map +1 -1
- package/package.json +1 -4
- package/src/CFG.js +1 -1
- package/src/DOMException.js +9 -11
- package/src/DOMStringList.js +6 -11
- package/src/Event.js +1 -4
- package/src/IDBCursor.js +98 -47
- package/src/IDBFactory.js +12 -11
- package/src/IDBIndex.js +10 -12
- package/src/IDBKeyRange.js +6 -5
- package/src/IDBObjectStore.js +32 -27
- package/src/IDBRequest.js +1 -1
- package/src/IDBTransaction.js +11 -11
- package/src/IDBVersionChangeEvent.js +1 -4
- package/src/Key.js +32 -31
- package/src/Sca.js +1 -1
- package/src/cmp.js +2 -2
- package/src/nodeWebSQL.js +5 -2
- package/src/setGlobalVars.js +8 -19
- package/src/util.js +42 -17
package/src/IDBCursor.js
CHANGED
|
@@ -23,16 +23,16 @@ const cursorDirections = ['next', 'prev', 'nextunique', 'prevunique'];
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* @typedef {IDBCursor & {
|
|
26
|
-
* primaryKey: import('./Key.js').Key,
|
|
27
|
-
* key: import('./Key.js').Key,
|
|
26
|
+
* primaryKey: import('./Key.js').Key|null|undefined,
|
|
27
|
+
* key: import('./Key.js').Key|null|undefined,
|
|
28
28
|
* direction: string,
|
|
29
29
|
* source: import('./IDBObjectStore.js').IDBObjectStoreFull|
|
|
30
30
|
* import('./IDBIndex.js').IDBIndexFull,
|
|
31
31
|
* __request: import('./IDBRequest.js').IDBRequestFull,
|
|
32
32
|
* __advanceCount: Integer|undefined,
|
|
33
33
|
* __indexSource: boolean,
|
|
34
|
-
* __key: import('./Key.js').Key,
|
|
35
|
-
* __primaryKey: import('./Key.js').Key,
|
|
34
|
+
* __key: import('./Key.js').Key|null|undefined,
|
|
35
|
+
* __primaryKey: import('./Key.js').Key|null|undefined,
|
|
36
36
|
* __value: import('./Key.js').Value,
|
|
37
37
|
* __store: import('./IDBObjectStore.js').IDBObjectStoreFull,
|
|
38
38
|
* __range: import('./IDBKeyRange.js').IDBKeyRangeFull|undefined,
|
|
@@ -40,11 +40,14 @@ const cursorDirections = ['next', 'prev', 'nextunique', 'prevunique'];
|
|
|
40
40
|
* __valueColumnName: string,
|
|
41
41
|
* __keyOnly: boolean,
|
|
42
42
|
* __valueDecoder: {
|
|
43
|
-
* decode: (str: string) =>
|
|
43
|
+
* decode: (str: string) => import('./Key.js').Value,
|
|
44
44
|
* },
|
|
45
45
|
* __count: boolean,
|
|
46
46
|
* __prefetchedIndex: Integer,
|
|
47
|
-
* __prefetchedData: null|
|
|
47
|
+
* __prefetchedData: null|{
|
|
48
|
+
* length: number;
|
|
49
|
+
* item(index: number): unknown;
|
|
50
|
+
* }|{
|
|
48
51
|
* data: RowItemNonNull[],
|
|
49
52
|
* length: Integer,
|
|
50
53
|
* item: (index: Integer) => RowItemNonNull
|
|
@@ -58,7 +61,14 @@ const cursorDirections = ['next', 'prev', 'nextunique', 'prevunique'];
|
|
|
58
61
|
* __multiEntryExhausted: boolean,
|
|
59
62
|
* __invalidateCache: () => void,
|
|
60
63
|
* __gotValue: boolean,
|
|
61
|
-
* __find: (
|
|
64
|
+
* __find: (
|
|
65
|
+
* key: import('./Key.js').Key|undefined,
|
|
66
|
+
* primaryKey: import('./Key.js').Key|undefined,
|
|
67
|
+
* tx: WebSQLTransaction,
|
|
68
|
+
* success: KeySuccess,
|
|
69
|
+
* error: FindError,
|
|
70
|
+
* recordsToLoad?: Integer
|
|
71
|
+
* ) => void,
|
|
62
72
|
* __findBasic: (
|
|
63
73
|
* key: import('./Key.js').Key|undefined,
|
|
64
74
|
* primaryKey: import('./Key.js').Key|undefined,
|
|
@@ -79,17 +89,17 @@ const cursorDirections = ['next', 'prev', 'nextunique', 'prevunique'];
|
|
|
79
89
|
* __decode: (
|
|
80
90
|
* rowItem: RowItemNonNull,
|
|
81
91
|
* callback: (
|
|
82
|
-
* key: import('./Key.js').Key,
|
|
92
|
+
* key: import('./Key.js').Key|undefined,
|
|
83
93
|
* val: import('./Key.js').Value,
|
|
84
|
-
* primaryKey: import('./Key.js').Key,
|
|
94
|
+
* primaryKey: import('./Key.js').Key|undefined,
|
|
85
95
|
* encKey?: string
|
|
86
96
|
* ) => void
|
|
87
97
|
* ) => void,
|
|
88
98
|
* __sourceOrEffectiveObjStoreDeleted: () => void,
|
|
89
99
|
* __continue: (key?: import('./Key.js').Key, advanceContinue?: boolean) => void,
|
|
90
100
|
* __continueFinish: (
|
|
91
|
-
* key: import('./Key.js').Key,
|
|
92
|
-
* primaryKey: import('./Key.js').Key,
|
|
101
|
+
* key: import('./Key.js').Key|undefined,
|
|
102
|
+
* primaryKey: import('./Key.js').Key|undefined,
|
|
93
103
|
* advanceState: boolean
|
|
94
104
|
* ) => void
|
|
95
105
|
* }} IDBCursorFull
|
|
@@ -122,7 +132,7 @@ const IDBCursorAlias = IDBCursor;
|
|
|
122
132
|
* import('./IDBIndex.js').IDBIndexFull} source
|
|
123
133
|
* @param {string} keyColumnName
|
|
124
134
|
* @param {string} valueColumnName
|
|
125
|
-
* @param {boolean} count
|
|
135
|
+
* @param {boolean} [count]
|
|
126
136
|
* @this {IDBCursorFull}
|
|
127
137
|
* @returns {void}
|
|
128
138
|
*/
|
|
@@ -161,7 +171,7 @@ IDBCursor.__super = function IDBCursor (query, direction, store, source, keyColu
|
|
|
161
171
|
this.__valueColumnName = valueColumnName;
|
|
162
172
|
this.__keyOnly = valueColumnName === 'key';
|
|
163
173
|
this.__valueDecoder = this.__keyOnly ? Key : Sca;
|
|
164
|
-
this.__count = count;
|
|
174
|
+
this.__count = Boolean(count);
|
|
165
175
|
this.__prefetchedIndex = -1;
|
|
166
176
|
this.__continuationKey = undefined;
|
|
167
177
|
this.__continuationPrimaryKey = undefined;
|
|
@@ -183,25 +193,38 @@ IDBCursor.__super = function IDBCursor (query, direction, store, source, keyColu
|
|
|
183
193
|
|
|
184
194
|
/**
|
|
185
195
|
*
|
|
186
|
-
* @param {
|
|
196
|
+
* @param {IDBKeyRange} query
|
|
197
|
+
* @param {string} direction
|
|
198
|
+
* @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
|
|
199
|
+
* @param {import('./IDBObjectStore.js').IDBObjectStoreFull|
|
|
200
|
+
* import('./IDBIndex.js').IDBIndexFull} source
|
|
201
|
+
* @param {string} keyColumnName
|
|
202
|
+
* @param {string} valueColumnName
|
|
203
|
+
* @param {boolean} [count]
|
|
187
204
|
* @returns {IDBCursorFull}
|
|
188
205
|
*/
|
|
189
|
-
IDBCursor.__createInstance = function (
|
|
206
|
+
IDBCursor.__createInstance = function (query, direction, store, source, keyColumnName, valueColumnName, count) {
|
|
190
207
|
const IDBCursor = IDBCursorAlias.__super;
|
|
191
208
|
IDBCursor.prototype = IDBCursorAlias.prototype;
|
|
192
209
|
|
|
193
210
|
// @ts-expect-error It's ok
|
|
194
|
-
return new IDBCursor(
|
|
211
|
+
return new IDBCursor(
|
|
212
|
+
query, direction, store, source, keyColumnName, valueColumnName, count
|
|
213
|
+
);
|
|
195
214
|
};
|
|
196
215
|
|
|
197
216
|
/**
|
|
198
217
|
*
|
|
199
|
-
* @param {
|
|
218
|
+
* @param {import('./Key.js').Key|undefined} key
|
|
219
|
+
* @param {import('./Key.js').Key|undefined} primaryKey
|
|
220
|
+
* @param {WebSQLTransaction} tx
|
|
221
|
+
* @param {KeySuccess} success
|
|
222
|
+
* @param {FindError} error
|
|
223
|
+
* @param {Integer} [recordsToLoad]
|
|
200
224
|
* @this {IDBCursorFull}
|
|
201
225
|
* @returns {void}
|
|
202
226
|
*/
|
|
203
|
-
IDBCursor.prototype.__find = function (
|
|
204
|
-
const [key, primaryKey, tx, success, error, recordsToLoad] = args;
|
|
227
|
+
IDBCursor.prototype.__find = function (key, primaryKey, tx, success, error, recordsToLoad) {
|
|
205
228
|
if (this.__multiEntryIndex) {
|
|
206
229
|
this.__findMultiEntry(key, primaryKey, tx, success, error, recordsToLoad);
|
|
207
230
|
} else {
|
|
@@ -211,9 +234,9 @@ IDBCursor.prototype.__find = function (...args /* key, tx, success, error, recor
|
|
|
211
234
|
|
|
212
235
|
/**
|
|
213
236
|
* @typedef {(
|
|
214
|
-
* k: import('./Key.js').Key,
|
|
237
|
+
* k: import('./Key.js').Key|undefined,
|
|
215
238
|
* val: import('./Key.js').Value,
|
|
216
|
-
* primKey: import('./Key.js').Key
|
|
239
|
+
* primKey: import('./Key.js').Key|undefined
|
|
217
240
|
* ) => void} KeySuccess
|
|
218
241
|
*/
|
|
219
242
|
|
|
@@ -319,7 +342,7 @@ IDBCursor.prototype.__findBasic = function (key, primaryKey, tx, success, error,
|
|
|
319
342
|
} else if (data.rows.length > 1) {
|
|
320
343
|
me.__prefetchedIndex = 0;
|
|
321
344
|
me.__prefetchedData = data.rows;
|
|
322
|
-
if (CFG.DEBUG) { console.log('Preloaded ' +
|
|
345
|
+
if (CFG.DEBUG) { console.log('Preloaded ' + data.rows.length + ' records for cursor'); }
|
|
323
346
|
me.__decode(/** @type {RowItemNonNull} */ (data.rows.item(0)), success);
|
|
324
347
|
} else if (data.rows.length === 1) {
|
|
325
348
|
me.__decode(/** @type {RowItemNonNull} */ (data.rows.item(0)), success);
|
|
@@ -449,7 +472,9 @@ IDBCursor.prototype.__findMultiEntry = function (key, primaryKey, tx, success, e
|
|
|
449
472
|
for (let i = 0; i < data.rows.length; i++) {
|
|
450
473
|
const rowItem = /** @type {RowItemNonNull} */ (data.rows.item(i));
|
|
451
474
|
const rowKey = Key.decode(rowItem[me.__keyColumnName], true);
|
|
452
|
-
const matches = Key.findMultiEntryMatches(
|
|
475
|
+
const matches = Key.findMultiEntryMatches(
|
|
476
|
+
/** @type {import('./Key.js').Key} */ (rowKey), me.__range
|
|
477
|
+
);
|
|
453
478
|
ct += matches.length;
|
|
454
479
|
}
|
|
455
480
|
success(undefined, ct, undefined);
|
|
@@ -470,7 +495,9 @@ IDBCursor.prototype.__findMultiEntry = function (key, primaryKey, tx, success, e
|
|
|
470
495
|
for (let i = 0; i < data.rows.length; i++) {
|
|
471
496
|
const rowItem = /** @type {RowItemNonNull} */ (data.rows.item(i));
|
|
472
497
|
const rowKey = Key.decode(rowItem[me.__keyColumnName], true);
|
|
473
|
-
const matches = Key.findMultiEntryMatches(
|
|
498
|
+
const matches = Key.findMultiEntryMatches(
|
|
499
|
+
/** @type {import('./Key.js').Key} */ (rowKey), me.__range
|
|
500
|
+
);
|
|
474
501
|
|
|
475
502
|
for (const matchingKey of matches) {
|
|
476
503
|
/**
|
|
@@ -542,11 +569,11 @@ IDBCursor.prototype.__findMultiEntry = function (key, primaryKey, tx, success, e
|
|
|
542
569
|
};
|
|
543
570
|
|
|
544
571
|
/**
|
|
545
|
-
* @typedef {
|
|
572
|
+
* @typedef {import('./Key.js').Value} StructuredCloneValue
|
|
546
573
|
*/
|
|
547
574
|
|
|
548
575
|
/**
|
|
549
|
-
* @typedef {
|
|
576
|
+
* @typedef {import('./Key.js').Key} IndexedDBKey
|
|
550
577
|
*/
|
|
551
578
|
|
|
552
579
|
/**
|
|
@@ -558,9 +585,9 @@ IDBCursor.prototype.__findMultiEntry = function (key, primaryKey, tx, success, e
|
|
|
558
585
|
|
|
559
586
|
/**
|
|
560
587
|
* @callback SuccessCallback
|
|
561
|
-
* @param {IndexedDBKey} key
|
|
588
|
+
* @param {IndexedDBKey|undefined} key
|
|
562
589
|
* @param {StructuredCloneValue} value
|
|
563
|
-
* @param {IndexedDBKey} primaryKey
|
|
590
|
+
* @param {IndexedDBKey|undefined} primaryKey
|
|
564
591
|
* @returns {void}
|
|
565
592
|
*/
|
|
566
593
|
|
|
@@ -600,9 +627,9 @@ IDBCursor.prototype.__onsuccess = function (success) {
|
|
|
600
627
|
*
|
|
601
628
|
* @param {RowItemNonNull} rowItem
|
|
602
629
|
* @param {(
|
|
603
|
-
* key: import('./Key.js').Key,
|
|
630
|
+
* key: import('./Key.js').Key|undefined,
|
|
604
631
|
* val: import('./Key.js').Value,
|
|
605
|
-
* primaryKey: import('./Key.js').Key,
|
|
632
|
+
* primaryKey: import('./Key.js').Key|undefined,
|
|
606
633
|
* encKey?: string
|
|
607
634
|
* ) => void} callback
|
|
608
635
|
* @this {IDBCursorFull}
|
|
@@ -691,8 +718,8 @@ IDBCursor.prototype.__continue = function (key, advanceContinue) {
|
|
|
691
718
|
|
|
692
719
|
/**
|
|
693
720
|
*
|
|
694
|
-
* @param {import('./Key.js').Key} key
|
|
695
|
-
* @param {import('./Key.js').Key} primaryKey
|
|
721
|
+
* @param {import('./Key.js').Key|undefined} key
|
|
722
|
+
* @param {import('./Key.js').Key|undefined} primaryKey
|
|
696
723
|
* @param {boolean} advanceState
|
|
697
724
|
* @this {IDBCursorFull}
|
|
698
725
|
* @returns {void}
|
|
@@ -707,9 +734,9 @@ IDBCursor.prototype.__continueFinish = function (key, primaryKey, advanceState)
|
|
|
707
734
|
me.__store.transaction
|
|
708
735
|
).__pushToQueue(me.__request, function cursorContinue (tx, args, success, error, executeNextRequest) {
|
|
709
736
|
/**
|
|
710
|
-
* @param {import('./Key.js').Key} k
|
|
737
|
+
* @param {import('./Key.js').Key|undefined} k
|
|
711
738
|
* @param {import('./Key.js').Value} val
|
|
712
|
-
* @param {import('./Key.js').Key} primKey
|
|
739
|
+
* @param {import('./Key.js').Key|undefined} primKey
|
|
713
740
|
* @returns {void}
|
|
714
741
|
*/
|
|
715
742
|
function triggerSuccess (k, val, primKey) {
|
|
@@ -752,7 +779,7 @@ IDBCursor.prototype.__continueFinish = function (key, primaryKey, advanceState)
|
|
|
752
779
|
// We have pre-loaded data for the cursor
|
|
753
780
|
me.__prefetchedIndex++;
|
|
754
781
|
if (me.__prefetchedIndex < me.__prefetchedData.length) {
|
|
755
|
-
me.__decode(me.__prefetchedData.item(me.__prefetchedIndex), function (k, val, primKey, encKey) {
|
|
782
|
+
me.__decode(/** @type {RowItemNonNull} */ (me.__prefetchedData.item(me.__prefetchedIndex)), function (k, val, primKey, encKey) {
|
|
756
783
|
/**
|
|
757
784
|
* @returns {void}
|
|
758
785
|
*/
|
|
@@ -901,12 +928,18 @@ IDBCursor.prototype.advance = function (count) {
|
|
|
901
928
|
};
|
|
902
929
|
|
|
903
930
|
/**
|
|
904
|
-
*
|
|
931
|
+
* The `{query, count, direction}` options shape shared by
|
|
932
|
+
* `getAll`/`getAllKeys`/`getAllRecords`.
|
|
933
|
+
* @typedef {{
|
|
934
|
+
* query?: import('./Key.js').Value,
|
|
935
|
+
* count?: Integer,
|
|
936
|
+
* direction?: string
|
|
937
|
+
* }} GetAllOptions
|
|
905
938
|
*/
|
|
906
939
|
|
|
907
940
|
/**
|
|
908
941
|
*
|
|
909
|
-
* @param {
|
|
942
|
+
* @param {import('./Key.js').Value} valueToUpdate
|
|
910
943
|
* @this {IDBCursorFull}
|
|
911
944
|
* @returns {IDBRequest}
|
|
912
945
|
*/
|
|
@@ -1045,16 +1078,22 @@ Object.defineProperty(IDBCursorWithValue.prototype, 'constructor', {
|
|
|
1045
1078
|
const IDBCursorWithValueAlias = IDBCursorWithValue;
|
|
1046
1079
|
/**
|
|
1047
1080
|
*
|
|
1048
|
-
* @param {
|
|
1081
|
+
* @param {IDBKeyRange} query
|
|
1082
|
+
* @param {string} direction
|
|
1083
|
+
* @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
|
|
1084
|
+
* @param {import('./IDBObjectStore.js').IDBObjectStoreFull|
|
|
1085
|
+
* import('./IDBIndex.js').IDBIndexFull} source
|
|
1086
|
+
* @param {string} keyColumnName
|
|
1087
|
+
* @param {string} valueColumnName
|
|
1088
|
+
* @param {boolean} [count]
|
|
1049
1089
|
* @returns {IDBCursorWithValueFull}
|
|
1050
1090
|
*/
|
|
1051
|
-
IDBCursorWithValue.__createInstance = function (
|
|
1091
|
+
IDBCursorWithValue.__createInstance = function (query, direction, store, source, keyColumnName, valueColumnName, count) {
|
|
1052
1092
|
/**
|
|
1053
1093
|
* @class
|
|
1054
1094
|
* @this {IDBCursorWithValueFull}
|
|
1055
1095
|
*/
|
|
1056
1096
|
function IDBCursorWithValue () {
|
|
1057
|
-
const [query, direction, store, source, keyColumnName, valueColumnName, count] = args;
|
|
1058
1097
|
IDBCursor.__super.call(this, query, direction, store, source, keyColumnName, valueColumnName, count);
|
|
1059
1098
|
// @ts-expect-error It's ok
|
|
1060
1099
|
this[Symbol.toStringTag] = 'IDBCursorWithValue';
|
|
@@ -1078,12 +1117,16 @@ Object.defineProperty(IDBCursorWithValue, 'prototype', {
|
|
|
1078
1117
|
/**
|
|
1079
1118
|
* Validates `direction` and fills in defaults for the `{query, count,
|
|
1080
1119
|
* direction}` shape shared by `getAll`/`getAllKeys`/`getAllRecords`.
|
|
1081
|
-
* @param {
|
|
1120
|
+
* @param {unknown} options
|
|
1082
1121
|
* @throws {TypeError}
|
|
1083
|
-
* @returns {{
|
|
1122
|
+
* @returns {{
|
|
1123
|
+
* query: import('./Key.js').Value|undefined,
|
|
1124
|
+
* count: Integer|undefined,
|
|
1125
|
+
* direction: string
|
|
1126
|
+
* }}
|
|
1084
1127
|
*/
|
|
1085
1128
|
function normalizeGetAllOptions (options) {
|
|
1086
|
-
const {query, count, direction = 'next'} = /** @type {
|
|
1129
|
+
const {query, count, direction = 'next'} = /** @type {GetAllOptions} */ (options ?? {});
|
|
1087
1130
|
if (!cursorDirections.includes(direction)) {
|
|
1088
1131
|
throw new TypeError('`' + direction + '` is not a valid direction');
|
|
1089
1132
|
}
|
|
@@ -1104,7 +1147,11 @@ function normalizeGetAllOptions (options) {
|
|
|
1104
1147
|
* first argument wins regardless of how many arguments were actually passed.
|
|
1105
1148
|
* @param {IArguments} args
|
|
1106
1149
|
* @throws {TypeError}
|
|
1107
|
-
* @returns {{
|
|
1150
|
+
* @returns {{
|
|
1151
|
+
* query: import('./Key.js').Value|undefined,
|
|
1152
|
+
* count: Integer|undefined,
|
|
1153
|
+
* direction: string
|
|
1154
|
+
* }}
|
|
1108
1155
|
*/
|
|
1109
1156
|
function parseGetAllArgs (args) {
|
|
1110
1157
|
const arg0 = args[0];
|
|
@@ -1124,7 +1171,11 @@ function parseGetAllArgs (args) {
|
|
|
1124
1171
|
* form to disambiguate against.
|
|
1125
1172
|
* @param {IArguments} args
|
|
1126
1173
|
* @throws {TypeError}
|
|
1127
|
-
* @returns {{
|
|
1174
|
+
* @returns {{
|
|
1175
|
+
* query: import('./Key.js').Value|undefined,
|
|
1176
|
+
* count: Integer|undefined,
|
|
1177
|
+
* direction: string
|
|
1178
|
+
* }}
|
|
1128
1179
|
*/
|
|
1129
1180
|
function parseGetAllRecordsArgs (args) {
|
|
1130
1181
|
return normalizeGetAllOptions(args[0]);
|
|
@@ -1231,7 +1282,7 @@ function collectAll (source, query, count, direction, mode) {
|
|
|
1231
1282
|
Object.defineProperty(state, 'direction', {writable: false, value: direction});
|
|
1232
1283
|
|
|
1233
1284
|
return tx.__addToTransactionQueue(function collectAllOp (sqlTx, args, success, error) {
|
|
1234
|
-
/** @type {
|
|
1285
|
+
/** @type {unknown[]} */
|
|
1235
1286
|
const results = [];
|
|
1236
1287
|
const recordsToLoad = count || CFG.cursorPreloadPackSize || 100;
|
|
1237
1288
|
|
|
@@ -1272,7 +1323,7 @@ function collectAll (source, query, count, direction, mode) {
|
|
|
1272
1323
|
state.__prefetchedIndex++;
|
|
1273
1324
|
if (state.__prefetchedIndex < state.__prefetchedData.length) {
|
|
1274
1325
|
IDBCursor.prototype.__decode.call(
|
|
1275
|
-
state, state.__prefetchedData.item(state.__prefetchedIndex),
|
|
1326
|
+
state, /** @type {RowItemNonNull} */ (state.__prefetchedData.item(state.__prefetchedIndex)),
|
|
1276
1327
|
/**
|
|
1277
1328
|
* @param {import('./Key.js').Key} k
|
|
1278
1329
|
* @param {import('./Key.js').Value} val
|
package/src/IDBFactory.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/* eslint-disable sonarjs/no-invariant-returns -- Convenient here */
|
|
2
|
-
// eslint-disable-next-line no-restricted-imports -- Can be polyfilled
|
|
3
|
-
import path from 'node:path';
|
|
4
2
|
import SyncPromise from 'sync-promise-expanded';
|
|
5
3
|
|
|
6
4
|
import {createEvent} from './Event.js';
|
|
@@ -367,7 +365,7 @@ function cleanupDatabaseResources (__openDatabase, name, escapedDatabaseName, da
|
|
|
367
365
|
}
|
|
368
366
|
if (fs && CFG.deleteDatabaseFiles !== false) {
|
|
369
367
|
closeCachedWebSQLConnections(name, () => {
|
|
370
|
-
fs.unlink(
|
|
368
|
+
fs.unlink(util.joinPath(CFG.databaseBasePath || '', escapedDatabaseName), (err) => {
|
|
371
369
|
if (err && err.code !== 'ENOENT') { // Ignore if file is already deleted
|
|
372
370
|
const removalError = /** @type {Error & {code?: number}} */ (
|
|
373
371
|
new Error('Error removing database file: ' + escapedDatabaseName + ' ' + err)
|
|
@@ -383,7 +381,7 @@ function cleanupDatabaseResources (__openDatabase, name, escapedDatabaseName, da
|
|
|
383
381
|
}
|
|
384
382
|
|
|
385
383
|
const sqliteDB = __openDatabase(
|
|
386
|
-
|
|
384
|
+
util.joinPath(CFG.databaseBasePath || '', escapedDatabaseName),
|
|
387
385
|
'1',
|
|
388
386
|
name,
|
|
389
387
|
CFG.DEFAULT_DB_SIZE
|
|
@@ -451,7 +449,7 @@ function createSysDB (__openDatabase, success, failure) {
|
|
|
451
449
|
sysdb = __openDatabase(
|
|
452
450
|
typeof CFG.memoryDatabase === 'string'
|
|
453
451
|
? CFG.memoryDatabase
|
|
454
|
-
:
|
|
452
|
+
: util.joinPath(
|
|
455
453
|
(typeof CFG.sysDatabaseBasePath === 'string'
|
|
456
454
|
? CFG.sysDatabaseBasePath
|
|
457
455
|
: (CFG.databaseBasePath || '')),
|
|
@@ -647,7 +645,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
647
645
|
let sysdbFinishedCb = function (systx, err, cb) {
|
|
648
646
|
if (err) {
|
|
649
647
|
/**
|
|
650
|
-
* @param {
|
|
648
|
+
* @param {unknown} [errorToShow]
|
|
651
649
|
* @returns {void}
|
|
652
650
|
*/
|
|
653
651
|
const manualRevert = function (errorToShow) {
|
|
@@ -681,7 +679,10 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
681
679
|
},
|
|
682
680
|
function () {
|
|
683
681
|
isRevertingSysdb = false;
|
|
684
|
-
|
|
682
|
+
// eslint-disable-next-line promise/no-callback-in-promise -- Convenient
|
|
683
|
+
cb(/** @type {(Error & {code?: number})|undefined} */ (
|
|
684
|
+
errorToShow || reportError
|
|
685
|
+
));
|
|
685
686
|
}
|
|
686
687
|
);
|
|
687
688
|
};
|
|
@@ -720,14 +721,14 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
720
721
|
new IDBVersionChangeEvent('upgradeneeded', {oldVersion, newVersion: version})
|
|
721
722
|
);
|
|
722
723
|
req.__result = connection;
|
|
723
|
-
connection.__upgradeTransaction = req.__transaction =
|
|
724
|
+
connection.__upgradeTransaction = req.__transaction = connection.__versionTransaction = IDBTransaction.__createInstance(connection, connection.objectStoreNames, 'versionchange');
|
|
724
725
|
req.__done = true;
|
|
725
726
|
|
|
726
727
|
req.transaction.__addNonRequestToTransactionQueue(
|
|
727
728
|
/**
|
|
728
729
|
* @param {import('websql-configurable/lib/websql/WebSQLTransaction.js').default} tx
|
|
729
|
-
* @param {
|
|
730
|
-
* @param {(result?:
|
|
730
|
+
* @param {unknown[]} args
|
|
731
|
+
* @param {(result?: unknown, req?: import('./IDBRequest.js').IDBRequestFull) => void} finished
|
|
731
732
|
* @returns {void}
|
|
732
733
|
*/
|
|
733
734
|
function onupgradeneeded (tx, args, finished /* , error */) {
|
|
@@ -963,7 +964,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
963
964
|
db = websqlDBCache[name][version];
|
|
964
965
|
} else {
|
|
965
966
|
db = /** @type {DatabaseFull} */ (me.__openDatabase(
|
|
966
|
-
useMemoryDatabase ? CFG.memoryDatabase :
|
|
967
|
+
useMemoryDatabase ? CFG.memoryDatabase : util.joinPath(CFG.databaseBasePath || '', escapedDatabaseName),
|
|
967
968
|
'1',
|
|
968
969
|
name,
|
|
969
970
|
CFG.DEFAULT_DB_SIZE
|
package/src/IDBIndex.js
CHANGED
|
@@ -68,7 +68,7 @@ const IDBIndexAlias = IDBIndex;
|
|
|
68
68
|
* __keyPath: import('./Key.js').KeyPath,
|
|
69
69
|
* __recreated?: boolean,
|
|
70
70
|
* __fetchIndexData: (
|
|
71
|
-
* range:
|
|
71
|
+
* range: Query,
|
|
72
72
|
* opType: "value"|"key"|"count",
|
|
73
73
|
* nullDisallowed: boolean,
|
|
74
74
|
* count?: number
|
|
@@ -497,7 +497,7 @@ IDBIndex.__updateIndexList = function (store, tx, success, failure) {
|
|
|
497
497
|
};
|
|
498
498
|
|
|
499
499
|
/**
|
|
500
|
-
* @typedef {
|
|
500
|
+
* @typedef {import('./Key.js').Value|IDBKeyRange} Query
|
|
501
501
|
*/
|
|
502
502
|
|
|
503
503
|
/**
|
|
@@ -766,7 +766,7 @@ IDBIndex.prototype.__renameIndex = function (store, oldName, newName, colInfoToP
|
|
|
766
766
|
})
|
|
767
767
|
);
|
|
768
768
|
SyncPromise.all(indexCreations).then(finish).catch(
|
|
769
|
-
/** @type {(reason:
|
|
769
|
+
/** @type {(reason: unknown) => PromiseLike<never>} */
|
|
770
770
|
(error)
|
|
771
771
|
).catch((err) => {
|
|
772
772
|
console.log('Index rename error');
|
|
@@ -779,14 +779,10 @@ IDBIndex.prototype.__renameIndex = function (store, oldName, newName, colInfoToP
|
|
|
779
779
|
});
|
|
780
780
|
};
|
|
781
781
|
|
|
782
|
-
/**
|
|
783
|
-
* @typedef {any} AnyValue
|
|
784
|
-
*/
|
|
785
|
-
|
|
786
782
|
/* eslint-disable unicorn/no-top-level-side-effects -- Would be good */
|
|
787
783
|
Object.defineProperty(IDBIndex, Symbol.hasInstance, {
|
|
788
784
|
/**
|
|
789
|
-
* @param {
|
|
785
|
+
* @param {unknown} obj
|
|
790
786
|
* @returns {boolean}
|
|
791
787
|
*/
|
|
792
788
|
value: (obj) => util.isObj(obj) &&
|
|
@@ -819,7 +815,9 @@ Object.defineProperty(IDBIndex, 'prototype', {
|
|
|
819
815
|
* @param {string[]} sqlValues
|
|
820
816
|
* @param {WebSQLTransaction} tx
|
|
821
817
|
* @param {null|undefined} args
|
|
822
|
-
* @param {(
|
|
818
|
+
* @param {(
|
|
819
|
+
* result: number|undefined|[]|import('./Key.js').Value|import('./Key.js').Value[]
|
|
820
|
+
* ) => void} success
|
|
823
821
|
* @param {(tx: WebSQLTransaction, err: (Error & {code?: number})) => void} error
|
|
824
822
|
* @returns {void}
|
|
825
823
|
*/
|
|
@@ -859,7 +857,7 @@ function executeFetchIndexData (
|
|
|
859
857
|
* @param {{
|
|
860
858
|
* value: string
|
|
861
859
|
* }} record
|
|
862
|
-
* @returns {
|
|
860
|
+
* @returns {import('./Key.js').Value}
|
|
863
861
|
*/
|
|
864
862
|
(record) => { // when opType is value
|
|
865
863
|
return Sca.decode(util.unescapeSQLiteResponse(record.value));
|
|
@@ -874,9 +872,9 @@ function executeFetchIndexData (
|
|
|
874
872
|
);
|
|
875
873
|
let record;
|
|
876
874
|
if (hasKey && (
|
|
877
|
-
(multiChecks && range.some(
|
|
875
|
+
(multiChecks && /** @type {import('./Key.js').ValueType[]} */ (range).some(
|
|
878
876
|
/**
|
|
879
|
-
* @param {
|
|
877
|
+
* @param {import('./Key.js').ValueType} check
|
|
880
878
|
* @returns {boolean}
|
|
881
879
|
*/
|
|
882
880
|
(check) => rowKey.includes(check)
|
package/src/IDBKeyRange.js
CHANGED
|
@@ -27,8 +27,8 @@ function IDBKeyRange () {
|
|
|
27
27
|
const IDBKeyRangeAlias = IDBKeyRange;
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* @param {import('./Key.js').
|
|
31
|
-
* @param {import('./Key.js').
|
|
30
|
+
* @param {import('./Key.js').Value} lower
|
|
31
|
+
* @param {import('./Key.js').Value} upper
|
|
32
32
|
* @param {boolean} lowerOpen
|
|
33
33
|
* @param {boolean} upperOpen
|
|
34
34
|
* @returns {import('./IDBKeyRange.js').IDBKeyRangeFull}
|
|
@@ -238,10 +238,11 @@ function setSQLForKeyRange (
|
|
|
238
238
|
function convertValueToKeyRange (value, nullDisallowed) {
|
|
239
239
|
if (util.instanceOf(value, IDBKeyRange)) {
|
|
240
240
|
// We still need to validate IDBKeyRange-like objects (the above check is based on loose duck-typing)
|
|
241
|
-
|
|
242
|
-
|
|
241
|
+
const range = /** @type {IDBKeyRangeFull} */ (value);
|
|
242
|
+
if (range.toString() !== '[object IDBKeyRange]') {
|
|
243
|
+
return IDBKeyRange.__createInstance(range.lower, range.upper, range.lowerOpen, range.upperOpen);
|
|
243
244
|
}
|
|
244
|
-
return
|
|
245
|
+
return range;
|
|
245
246
|
}
|
|
246
247
|
if (util.isNullish(value)) {
|
|
247
248
|
if (nullDisallowed) {
|