indexeddbshim 16.1.0 → 17.1.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 +65 -3
- package/badges/licenses-badge-dev.svg +1 -1
- package/badges/licenses-badge.svg +1 -1
- package/dist/CFG.d.ts +1 -0
- package/dist/CFG.d.ts.map +1 -1
- package/dist/DOMException.d.ts.map +1 -1
- package/dist/DOMStringList.d.ts.map +1 -1
- package/dist/IDBCursor.d.ts +12 -3
- package/dist/IDBCursor.d.ts.map +1 -1
- package/dist/IDBDatabase.d.ts +2 -1
- package/dist/IDBDatabase.d.ts.map +1 -1
- package/dist/IDBFactory.d.ts +2 -1
- package/dist/IDBFactory.d.ts.map +1 -1
- package/dist/IDBIndex.d.ts +2 -1
- package/dist/IDBIndex.d.ts.map +1 -1
- package/dist/IDBKeyRange.d.ts +1 -1
- package/dist/IDBKeyRange.d.ts.map +1 -1
- package/dist/IDBObjectStore.d.ts +2 -1
- package/dist/IDBObjectStore.d.ts.map +1 -1
- package/dist/IDBRequest.d.ts +5 -3
- package/dist/IDBRequest.d.ts.map +1 -1
- package/dist/IDBTransaction.d.ts +23 -1
- package/dist/IDBTransaction.d.ts.map +1 -1
- package/dist/Key.d.ts.map +1 -1
- package/dist/Sca.d.ts.map +1 -1
- package/dist/UnicodeIdentifiers.d.ts.map +1 -1
- package/dist/browser-noninvasive.d.ts.map +1 -1
- package/dist/indexeddbshim-Key.js +1863 -1669
- 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 +2373 -1893
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.js +3124 -2285
- package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js +9 -2
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
- package/dist/indexeddbshim-node.cjs +2373 -1893
- package/dist/indexeddbshim-node.cjs.map +1 -1
- package/dist/indexeddbshim-noninvasive.js +3123 -2284
- package/dist/indexeddbshim-noninvasive.js.map +1 -1
- package/dist/indexeddbshim-noninvasive.min.js +9 -2
- package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
- package/dist/indexeddbshim.js +3120 -2282
- package/dist/indexeddbshim.js.map +1 -1
- package/dist/indexeddbshim.min.js +9 -2
- package/dist/indexeddbshim.min.js.map +1 -1
- package/dist/node-UnicodeIdentifiers.d.ts +2 -2
- package/dist/node-UnicodeIdentifiers.d.ts.map +1 -1
- package/dist/node.d.ts +2 -2
- package/dist/node.d.ts.map +1 -1
- package/dist/nodeSQLiteDatabase.d.ts +65 -0
- package/dist/nodeSQLiteDatabase.d.ts.map +1 -0
- package/dist/nodeWebSQL.d.ts.map +1 -1
- package/dist/util.d.ts +5 -0
- package/dist/util.d.ts.map +1 -1
- package/package.json +118 -106
- package/src/CFG.js +5 -3
- package/src/DOMException.js +11 -9
- package/src/DOMStringList.js +8 -3
- package/src/Event.js +2 -0
- package/src/IDBCursor.js +152 -95
- package/src/IDBDatabase.js +9 -6
- package/src/IDBFactory.js +31 -20
- package/src/IDBIndex.js +83 -79
- package/src/IDBKeyRange.js +42 -35
- package/src/IDBObjectStore.js +83 -77
- package/src/IDBRequest.js +28 -15
- package/src/IDBTransaction.js +40 -6
- package/src/IDBVersionChangeEvent.js +2 -0
- package/src/Key.js +28 -14
- package/src/Sca.js +2 -1
- package/src/UnicodeIdentifiers.js +2 -2
- package/src/browser-UnicodeIdentifiers.js +0 -1
- package/src/browser-noninvasive.js +0 -1
- package/src/browser.js +0 -1
- package/src/node-UnicodeIdentifiers.js +6 -2
- package/src/node.js +6 -2
- package/src/nodeSQLiteDatabase.js +174 -0
- package/src/nodeWebSQL.js +1 -3
- package/src/setGlobalVars.js +13 -13
- package/src/util.js +75 -15
|
@@ -1,1235 +1,1403 @@
|
|
|
1
|
-
/*! indexeddbshim -
|
|
1
|
+
/*! indexeddbshim - v17.1.0 - 8/6/2026 */
|
|
2
2
|
|
|
3
3
|
(function (global, factory) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
5
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
6
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.IDBKeyUtils = {}));
|
|
7
7
|
})(this, (function (exports) { 'use strict';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* escapeDatabaseName: (name: string) => string,
|
|
43
|
-
* unescapeDatabaseName: (name: string) => string,
|
|
44
|
-
* databaseCharacterEscapeList: string|false,
|
|
45
|
-
* databaseNameLengthLimit: number|false,
|
|
46
|
-
* escapeNFDForDatabaseNames: boolean,
|
|
47
|
-
* addSQLiteExtension: boolean,
|
|
48
|
-
* memoryDatabase: string,
|
|
49
|
-
* deleteDatabaseFiles: boolean,
|
|
50
|
-
* databaseBasePath: string,
|
|
51
|
-
* sysDatabaseBasePath: string,
|
|
52
|
-
* sqlBusyTimeout: number,
|
|
53
|
-
* sqlTrace: () => void,
|
|
54
|
-
* sqlProfile: () => void,
|
|
55
|
-
* createIndexes: boolean
|
|
56
|
-
* }} ConfigValues
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @typedef {ValueOf<ConfigValues>} ConfigValue
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
/** @type {{[key: string]: ConfigValue}} */
|
|
64
|
-
const map = {};
|
|
65
|
-
const CFG = /** @type {ConfigValues} */{};
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* @typedef {keyof ConfigValues} KeyofConfigValues
|
|
69
|
-
*/
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @typedef {KeyofConfigValues[]} Config
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
/** @type {Config} */
|
|
76
|
-
[
|
|
77
|
-
// Boolean for verbose reporting
|
|
78
|
-
'DEBUG',
|
|
79
|
-
// Effectively defaults to false (ignored unless `true`)
|
|
80
|
-
|
|
81
|
-
// Boolean (effectively defaults to true) on whether to cache WebSQL
|
|
82
|
-
// `openDatabase` instances
|
|
83
|
-
'cacheDatabaseInstances',
|
|
84
|
-
// Boolean on whether to auto-name databases (based on an
|
|
85
|
-
// auto-increment) when the empty string is supplied; useful with
|
|
86
|
-
// `memoryDatabase`; defaults to `false` which means the empty string
|
|
87
|
-
// will be used as the (valid) database name
|
|
88
|
-
'autoName',
|
|
89
|
-
// Determines whether the slow-performing `Object.setPrototypeOf`
|
|
90
|
-
// calls required for full WebIDL compliance will be used. Probably
|
|
91
|
-
// only needed for testing or environments where full introspection
|
|
92
|
-
// on class relationships is required; see
|
|
93
|
-
// http://stackoverflow.com/questions/41927589/rationales-consequences-of-webidl-class-inheritance-requirements
|
|
94
|
-
'fullIDLSupport',
|
|
95
|
-
// Effectively defaults to false (ignored unless `true`)
|
|
96
|
-
|
|
97
|
-
// Boolean on whether to perform origin checks in `IDBFactory` methods
|
|
98
|
-
// Effectively defaults to `true` (must be set to `false` to cancel checks)
|
|
99
|
-
'checkOrigin',
|
|
100
|
-
// Used by `IDBCursor` continue methods for number of records to cache;
|
|
101
|
-
// Defaults to 100
|
|
102
|
-
'cursorPreloadPackSize',
|
|
103
|
-
// See optional API (`shimIndexedDB.__setUnicodeIdentifiers`);
|
|
104
|
-
// or just use the Unicode builds which invoke this method
|
|
105
|
-
// automatically using the large, fully spec-compliant, regular
|
|
106
|
-
// expression strings of `src/UnicodeIdentifiers.js`)
|
|
107
|
-
// In the non-Unicode builds, defaults to /[$A-Z_a-z]/
|
|
108
|
-
'UnicodeIDStart',
|
|
109
|
-
// In the non-Unicode builds, defaults to /[$0-9A-Z_a-z]/
|
|
110
|
-
'UnicodeIDContinue',
|
|
111
|
-
// Used by SCA.js for optional restructuring of typeson-registry
|
|
112
|
-
// Structured Cloning Algorithm; should only be needed for ensuring data
|
|
113
|
-
// created in 3.* versions of IndexedDBShim continue to work; see the
|
|
114
|
-
// library `typeson-registry-sca-reverter` to get a function to do this
|
|
115
|
-
'registerSCA',
|
|
116
|
-
// BROWSER-SPECIFIC CONFIG
|
|
117
|
-
'avoidAutoShim',
|
|
118
|
-
// Where WebSQL is detected but where `indexedDB` is
|
|
119
|
-
// missing or poor support is known (non-Chrome Android or
|
|
120
|
-
// non-Safari iOS9), the shim will be auto-applied without
|
|
121
|
-
// `shimIndexedDB.__useShim()`. Set this to `true` to avoid forcing
|
|
122
|
-
// the shim for such cases.
|
|
123
|
-
|
|
124
|
-
// -----------SQL CONFIG----------
|
|
125
|
-
// Object (`window` in the browser) on which there may be an
|
|
126
|
-
// `openDatabase` method (if any) for WebSQL. (The browser
|
|
127
|
-
// throws if attempting to call `openDatabase` without the window
|
|
128
|
-
// so this is why the config doesn't just allow the function.)
|
|
129
|
-
// Defaults to `window` or `self` in browser builds or
|
|
130
|
-
// a singleton object with the `openDatabase` method set to
|
|
131
|
-
// the "websql" package in Node.
|
|
132
|
-
'win',
|
|
133
|
-
// For internal `openDatabase` calls made by `IDBFactory` methods;
|
|
134
|
-
// per the WebSQL spec, "User agents are expected to use the display name
|
|
135
|
-
// and the estimated database size to optimize the user experience.
|
|
136
|
-
// For example, a user agent could use the estimated size to suggest an
|
|
137
|
-
// initial quota to the user. This allows a site that is aware that it
|
|
138
|
-
// will try to use hundreds of megabytes to declare this upfront, instead
|
|
139
|
-
// of the user agent prompting the user for permission to increase the
|
|
140
|
-
// quota every five megabytes."
|
|
141
|
-
// Defaults to (4 * 1024 * 1024) or (25 * 1024 * 1024) in Safari
|
|
142
|
-
'DEFAULT_DB_SIZE',
|
|
143
|
-
// Whether to create indexes on SQLite tables (and also whether to try
|
|
144
|
-
// dropping)
|
|
145
|
-
// Effectively defaults to `false` (ignored unless `true`)
|
|
146
|
-
'useSQLiteIndexes',
|
|
147
|
-
// NODE-IMPINGING SETTINGS (created for sake of limitations in Node
|
|
148
|
-
// or desktop file system implementation but applied by default in
|
|
149
|
-
// browser for parity)
|
|
150
|
-
|
|
151
|
-
// File system module with `unlink` to remove deleted database files
|
|
152
|
-
'fs',
|
|
153
|
-
// Used when setting global shims to determine whether to try to add
|
|
154
|
-
// other globals shimmed by the library (`ShimDOMException`,
|
|
155
|
-
// `ShimDOMStringList`, `ShimEvent`, `ShimCustomEvent`, `ShimEventTarget`)
|
|
156
|
-
// Effectively defaults to `false` (ignored unless `true`)
|
|
157
|
-
'addNonIDBGlobals',
|
|
158
|
-
// Used when setting global shims to determine whether to try to overwrite
|
|
159
|
-
// other globals shimmed by the library (`DOMException`, `DOMStringList`,
|
|
160
|
-
// `Event`, `CustomEvent`, `EventTarget`)
|
|
161
|
-
// Effectively defaults to `false` (ignored unless `true`)
|
|
162
|
-
'replaceNonIDBGlobals',
|
|
163
|
-
// Overcoming limitations with node-sqlite3/storing database name on
|
|
164
|
-
// file systems
|
|
165
|
-
// https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
|
166
|
-
// Defaults to prefixing database with `D_`, escaping
|
|
167
|
-
// `databaseCharacterEscapeList`, escaping NUL, and
|
|
168
|
-
// escaping upper case letters, as well as enforcing
|
|
169
|
-
// `databaseNameLengthLimit`
|
|
170
|
-
'escapeDatabaseName',
|
|
171
|
-
// Not used internally; usable as a convenience method
|
|
172
|
-
'unescapeDatabaseName',
|
|
173
|
-
// Defaults to global regex representing the following
|
|
174
|
-
// (characters nevertheless commonly reserved in modern,
|
|
175
|
-
// Unicode-supporting systems): 0x00-0x1F 0x7F " * / : < > ? \ |
|
|
176
|
-
'databaseCharacterEscapeList',
|
|
177
|
-
// Defaults to 254 (shortest typical modern file length limit)
|
|
178
|
-
'databaseNameLengthLimit',
|
|
179
|
-
// Boolean defaulting to true on whether to escape NFD-escaping
|
|
180
|
-
// characters to avoid clashes on MacOS which performs NFD on files
|
|
181
|
-
'escapeNFDForDatabaseNames',
|
|
182
|
-
// Boolean on whether to add the `.sqlite` extension to file names;
|
|
183
|
-
// defaults to `true`
|
|
184
|
-
'addSQLiteExtension',
|
|
185
|
-
// Various types of in-memory databases that can auto-delete
|
|
186
|
-
['memoryDatabase',
|
|
187
|
-
/**
|
|
188
|
-
* @param {string} val
|
|
189
|
-
* @throws {TypeError}
|
|
190
|
-
* @returns {void}
|
|
191
|
-
*/
|
|
192
|
-
val => {
|
|
193
|
-
if (!/^(?::memory:|file::memory:(\?[^#]*)?(#.*)?)?$/u.test(/** @type {string} */val)) {
|
|
194
|
-
throw new TypeError('`memoryDatabase` must be the empty string, ":memory:", or a ' + '"file::memory:[?queryString][#hash] URL".');
|
|
195
|
-
}
|
|
196
|
-
}],
|
|
197
|
-
// NODE-SPECIFIC CONFIG
|
|
198
|
-
// Boolean on whether to delete the database file itself after
|
|
199
|
-
// `deleteDatabase`; defaults to `true` as the database will be empty
|
|
200
|
-
'deleteDatabaseFiles', 'databaseBasePath', 'sysDatabaseBasePath',
|
|
201
|
-
// NODE-SPECIFIC WEBSQL CONFIG
|
|
202
|
-
'sqlBusyTimeout',
|
|
203
|
-
// Defaults to 1000
|
|
204
|
-
'sqlTrace',
|
|
205
|
-
// Callback not used by default
|
|
206
|
-
'sqlProfile',
|
|
207
|
-
// Callback not used by default
|
|
208
|
-
|
|
209
|
-
'createIndexes'].forEach(prop => {
|
|
210
|
-
/** @type {(val: any) => void} */
|
|
211
|
-
let validator;
|
|
212
|
-
if (Array.isArray(prop)) {
|
|
213
|
-
[prop, validator] = prop;
|
|
9
|
+
function _arrayLikeToArray(r, a) {
|
|
10
|
+
(null == a || a > r.length) && (a = r.length);
|
|
11
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
12
|
+
return n;
|
|
13
|
+
}
|
|
14
|
+
function _arrayWithHoles(r) {
|
|
15
|
+
if (Array.isArray(r)) return r;
|
|
16
|
+
}
|
|
17
|
+
function _arrayWithoutHoles(r) {
|
|
18
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
19
|
+
}
|
|
20
|
+
function _createForOfIteratorHelper(r, e) {
|
|
21
|
+
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
22
|
+
if (!t) {
|
|
23
|
+
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
|
|
24
|
+
t && (r = t);
|
|
25
|
+
var n = 0,
|
|
26
|
+
F = function () {};
|
|
27
|
+
return {
|
|
28
|
+
s: F,
|
|
29
|
+
n: function () {
|
|
30
|
+
return n >= r.length ? {
|
|
31
|
+
done: true
|
|
32
|
+
} : {
|
|
33
|
+
done: false,
|
|
34
|
+
value: r[n++]
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
e: function (r) {
|
|
38
|
+
throw r;
|
|
39
|
+
},
|
|
40
|
+
f: F
|
|
41
|
+
};
|
|
214
42
|
}
|
|
215
|
-
|
|
216
|
-
get() {
|
|
217
|
-
return map[prop];
|
|
218
|
-
},
|
|
219
|
-
set(val) {
|
|
220
|
-
if (validator) {
|
|
221
|
-
validator(val);
|
|
222
|
-
}
|
|
223
|
-
map[prop] = val;
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Creates a native DOMException, for browsers that support it.
|
|
230
|
-
* @param {string} name
|
|
231
|
-
* @param {string} message
|
|
232
|
-
* @returns {DOMException}
|
|
233
|
-
*/
|
|
234
|
-
function createNativeDOMException(name, message) {
|
|
235
|
-
// @ts-expect-error It's ok
|
|
236
|
-
return new DOMException.prototype.constructor(message, name || 'DOMException');
|
|
43
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
237
44
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
NoModificationAllowedError: 7,
|
|
260
|
-
NotFoundError: 8,
|
|
261
|
-
NotSupportedError: 9,
|
|
262
|
-
InUseAttributeError: 10,
|
|
263
|
-
InvalidStateError: 11,
|
|
264
|
-
SyntaxError: 12,
|
|
265
|
-
InvalidModificationError: 13,
|
|
266
|
-
NamespaceError: 14,
|
|
267
|
-
InvalidAccessError: 15,
|
|
268
|
-
TypeMismatchError: 17,
|
|
269
|
-
SecurityError: 18,
|
|
270
|
-
NetworkError: 19,
|
|
271
|
-
AbortError: 20,
|
|
272
|
-
URLMismatchError: 21,
|
|
273
|
-
QuotaExceededError: 22,
|
|
274
|
-
TimeoutError: 23,
|
|
275
|
-
InvalidNodeTypeError: 24,
|
|
276
|
-
DataCloneError: 25,
|
|
277
|
-
EncodingError: 0,
|
|
278
|
-
NotReadableError: 0,
|
|
279
|
-
UnknownError: 0,
|
|
280
|
-
ConstraintError: 0,
|
|
281
|
-
DataError: 0,
|
|
282
|
-
TransactionInactiveError: 0,
|
|
283
|
-
ReadOnlyError: 0,
|
|
284
|
-
VersionError: 0,
|
|
285
|
-
OperationError: 0,
|
|
286
|
-
NotAllowedError: 0
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* @typedef {"INDEX_SIZE_ERR"|"DOMSTRING_SIZE_ERR"|"HIERARCHY_REQUEST_ERR"|
|
|
291
|
-
* "WRONG_DOCUMENT_ERR"|"INVALID_CHARACTER_ERR"|"NO_DATA_ALLOWED_ERR"|
|
|
292
|
-
* "NO_MODIFICATION_ALLOWED_ERR"|"NOT_FOUND_ERR"|"NOT_SUPPORTED_ERR"|
|
|
293
|
-
* "INUSE_ATTRIBUTE_ERR"|"INVALID_STATE_ERR"|"SYNTAX_ERR"|
|
|
294
|
-
* "INVALID_MODIFICATION_ERR"|"NAMESPACE_ERR"|"INVALID_ACCESS_ERR"|
|
|
295
|
-
* "VALIDATION_ERR"|"TYPE_MISMATCH_ERR"|"SECURITY_ERR"|"NETWORK_ERR"|
|
|
296
|
-
* "ABORT_ERR"|"URL_MISMATCH_ERR"|"QUOTA_EXCEEDED_ERR"|"TIMEOUT_ERR"|
|
|
297
|
-
* "INVALID_NODE_TYPE_ERR"|"DATA_CLONE_ERR"} LegacyCode
|
|
298
|
-
*/
|
|
299
|
-
|
|
300
|
-
const legacyCodes = {
|
|
301
|
-
INDEX_SIZE_ERR: 1,
|
|
302
|
-
DOMSTRING_SIZE_ERR: 2,
|
|
303
|
-
HIERARCHY_REQUEST_ERR: 3,
|
|
304
|
-
WRONG_DOCUMENT_ERR: 4,
|
|
305
|
-
INVALID_CHARACTER_ERR: 5,
|
|
306
|
-
NO_DATA_ALLOWED_ERR: 6,
|
|
307
|
-
NO_MODIFICATION_ALLOWED_ERR: 7,
|
|
308
|
-
NOT_FOUND_ERR: 8,
|
|
309
|
-
NOT_SUPPORTED_ERR: 9,
|
|
310
|
-
INUSE_ATTRIBUTE_ERR: 10,
|
|
311
|
-
INVALID_STATE_ERR: 11,
|
|
312
|
-
SYNTAX_ERR: 12,
|
|
313
|
-
INVALID_MODIFICATION_ERR: 13,
|
|
314
|
-
NAMESPACE_ERR: 14,
|
|
315
|
-
INVALID_ACCESS_ERR: 15,
|
|
316
|
-
VALIDATION_ERR: 16,
|
|
317
|
-
TYPE_MISMATCH_ERR: 17,
|
|
318
|
-
SECURITY_ERR: 18,
|
|
319
|
-
NETWORK_ERR: 19,
|
|
320
|
-
ABORT_ERR: 20,
|
|
321
|
-
URL_MISMATCH_ERR: 21,
|
|
322
|
-
QUOTA_EXCEEDED_ERR: 22,
|
|
323
|
-
TIMEOUT_ERR: 23,
|
|
324
|
-
INVALID_NODE_TYPE_ERR: 24,
|
|
325
|
-
DATA_CLONE_ERR: 25
|
|
45
|
+
var o,
|
|
46
|
+
a = true,
|
|
47
|
+
u = false;
|
|
48
|
+
return {
|
|
49
|
+
s: function () {
|
|
50
|
+
t = t.call(r);
|
|
51
|
+
},
|
|
52
|
+
n: function () {
|
|
53
|
+
var r = t.next();
|
|
54
|
+
return a = r.done, r;
|
|
55
|
+
},
|
|
56
|
+
e: function (r) {
|
|
57
|
+
u = true, o = r;
|
|
58
|
+
},
|
|
59
|
+
f: function () {
|
|
60
|
+
try {
|
|
61
|
+
a || null == t.return || t.return();
|
|
62
|
+
} finally {
|
|
63
|
+
if (u) throw o;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
326
66
|
};
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
});
|
|
351
|
-
if (name !== undefined) {
|
|
352
|
-
Object.defineProperty(this, 'name', {
|
|
353
|
-
configurable: true,
|
|
354
|
-
enumerable: true,
|
|
355
|
-
writable: true,
|
|
356
|
-
value: this._name
|
|
357
|
-
});
|
|
67
|
+
}
|
|
68
|
+
function _iterableToArray(r) {
|
|
69
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
70
|
+
}
|
|
71
|
+
function _iterableToArrayLimit(r, l) {
|
|
72
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
73
|
+
if (null != t) {
|
|
74
|
+
var e,
|
|
75
|
+
n,
|
|
76
|
+
i,
|
|
77
|
+
u,
|
|
78
|
+
a = [],
|
|
79
|
+
f = true,
|
|
80
|
+
o = false;
|
|
81
|
+
try {
|
|
82
|
+
if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
83
|
+
} catch (r) {
|
|
84
|
+
o = true, n = r;
|
|
85
|
+
} finally {
|
|
86
|
+
try {
|
|
87
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
88
|
+
} finally {
|
|
89
|
+
if (o) throw n;
|
|
358
90
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
91
|
+
}
|
|
92
|
+
return a;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function _nonIterableRest() {
|
|
96
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
97
|
+
}
|
|
98
|
+
function _nonIterableSpread() {
|
|
99
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
100
|
+
}
|
|
101
|
+
function _slicedToArray(r, e) {
|
|
102
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
103
|
+
}
|
|
104
|
+
function _taggedTemplateLiteral(e, t) {
|
|
105
|
+
return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, {
|
|
106
|
+
raw: {
|
|
107
|
+
value: Object.freeze(t)
|
|
108
|
+
}
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
function _toConsumableArray(r) {
|
|
112
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
113
|
+
}
|
|
114
|
+
function _typeof(o) {
|
|
115
|
+
"@babel/helpers - typeof";
|
|
116
|
+
|
|
117
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
118
|
+
return typeof o;
|
|
119
|
+
} : function (o) {
|
|
120
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
121
|
+
}, _typeof(o);
|
|
122
|
+
}
|
|
123
|
+
function _unsupportedIterableToArray(r, a) {
|
|
124
|
+
if (r) {
|
|
125
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
126
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
127
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @typedef {T[keyof T]} ValueOf<T>
|
|
133
|
+
* @template T
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @typedef {{unlink: (path: string, cb: import('fs').NoParamCallback) => void}} FSApi
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @typedef {{
|
|
142
|
+
* DEBUG: boolean,
|
|
143
|
+
* cacheDatabaseInstances: boolean,
|
|
144
|
+
* autoName: boolean,
|
|
145
|
+
* fullIDLSupport: boolean,
|
|
146
|
+
* checkOrigin: boolean,
|
|
147
|
+
* cursorPreloadPackSize: number,
|
|
148
|
+
* UnicodeIDStart: string,
|
|
149
|
+
* UnicodeIDContinue: string,
|
|
150
|
+
* registerSCA: (
|
|
151
|
+
* preset: import('typeson').Preset
|
|
152
|
+
* ) => import('typeson').Preset,
|
|
153
|
+
* avoidAutoShim: boolean,
|
|
154
|
+
* win: {
|
|
155
|
+
* openDatabase: (name: string, version: string, displayName: string, estimatedSize: number) => import('websql-configurable').default
|
|
156
|
+
* },
|
|
157
|
+
* DEFAULT_DB_SIZE: number,
|
|
158
|
+
* useSQLiteIndexes: boolean,
|
|
159
|
+
* fs: FSApi,
|
|
160
|
+
* addNonIDBGlobals: boolean,
|
|
161
|
+
* replaceNonIDBGlobals: boolean,
|
|
162
|
+
* escapeDatabaseName: (name: string) => string,
|
|
163
|
+
* unescapeDatabaseName: (name: string) => string,
|
|
164
|
+
* databaseCharacterEscapeList: string|false,
|
|
165
|
+
* databaseNameLengthLimit: number|false,
|
|
166
|
+
* escapeNFDForDatabaseNames: boolean,
|
|
167
|
+
* addSQLiteExtension: boolean,
|
|
168
|
+
* memoryDatabase: string,
|
|
169
|
+
* deleteDatabaseFiles: boolean,
|
|
170
|
+
* databaseBasePath: string,
|
|
171
|
+
* sysDatabaseBasePath: string,
|
|
172
|
+
* sqlBusyTimeout: number,
|
|
173
|
+
* sqlTrace: () => void,
|
|
174
|
+
* sqlProfile: () => void,
|
|
175
|
+
* escapeNULForSQLiteStatements: boolean,
|
|
176
|
+
* createIndexes: boolean
|
|
177
|
+
* }} ConfigValues
|
|
178
|
+
*/
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @typedef {ValueOf<ConfigValues>} ConfigValue
|
|
182
|
+
*/
|
|
183
|
+
|
|
184
|
+
/** @type {{[key: string]: ConfigValue}} */
|
|
185
|
+
var map = {};
|
|
186
|
+
var CFG = /** @type {ConfigValues} */{};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @typedef {keyof ConfigValues} KeyofConfigValues
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* @typedef {KeyofConfigValues[]} Config
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
/** @type {Config} */
|
|
197
|
+
// eslint-disable-next-line unicorn/no-top-level-side-effects -- Would be good
|
|
198
|
+
[
|
|
199
|
+
// Boolean for verbose reporting
|
|
200
|
+
'DEBUG',
|
|
201
|
+
// Effectively defaults to false (ignored unless `true`)
|
|
202
|
+
|
|
203
|
+
// Boolean (effectively defaults to true) on whether to cache WebSQL
|
|
204
|
+
// `openDatabase` instances
|
|
205
|
+
'cacheDatabaseInstances',
|
|
206
|
+
// Boolean on whether to auto-name databases (based on an
|
|
207
|
+
// auto-increment) when the empty string is supplied; useful with
|
|
208
|
+
// `memoryDatabase`; defaults to `false` which means the empty string
|
|
209
|
+
// will be used as the (valid) database name
|
|
210
|
+
'autoName',
|
|
211
|
+
// Determines whether the slow-performing `Object.setPrototypeOf`
|
|
212
|
+
// calls required for full WebIDL compliance will be used. Probably
|
|
213
|
+
// only needed for testing or environments where full introspection
|
|
214
|
+
// on class relationships is required; see
|
|
215
|
+
// https://stackoverflow.com/questions/41927589/rationales-consequences-of-webidl-class-inheritance-requirements
|
|
216
|
+
'fullIDLSupport',
|
|
217
|
+
// Effectively defaults to false (ignored unless `true`)
|
|
218
|
+
|
|
219
|
+
// Boolean on whether to perform origin checks in `IDBFactory` methods
|
|
220
|
+
// Effectively defaults to `true` (must be set to `false` to cancel checks)
|
|
221
|
+
'checkOrigin',
|
|
222
|
+
// Used by `IDBCursor` continue methods for number of records to cache;
|
|
223
|
+
// Defaults to 100
|
|
224
|
+
'cursorPreloadPackSize',
|
|
225
|
+
// See optional API (`shimIndexedDB.__setUnicodeIdentifiers`);
|
|
226
|
+
// or just use the Unicode builds which invoke this method
|
|
227
|
+
// automatically using the large, fully spec-compliant, regular
|
|
228
|
+
// expression strings of `src/UnicodeIdentifiers.js`)
|
|
229
|
+
// In the non-Unicode builds, defaults to /[$A-Z_a-z]/
|
|
230
|
+
'UnicodeIDStart',
|
|
231
|
+
// In the non-Unicode builds, defaults to /[$0-9A-Z_a-z]/
|
|
232
|
+
'UnicodeIDContinue',
|
|
233
|
+
// Used by SCA.js for optional restructuring of typeson-registry
|
|
234
|
+
// Structured Cloning Algorithm; should only be needed for ensuring data
|
|
235
|
+
// created in 3.* versions of IndexedDBShim continue to work; see the
|
|
236
|
+
// library `typeson-registry-sca-reverter` to get a function to do this
|
|
237
|
+
'registerSCA',
|
|
238
|
+
// BROWSER-SPECIFIC CONFIG
|
|
239
|
+
'avoidAutoShim',
|
|
240
|
+
// Where WebSQL is detected but where `indexedDB` is
|
|
241
|
+
// missing or poor support is known (non-Chrome Android or
|
|
242
|
+
// non-Safari iOS9), the shim will be auto-applied without
|
|
243
|
+
// `shimIndexedDB.__useShim()`. Set this to `true` to avoid forcing
|
|
244
|
+
// the shim for such cases.
|
|
245
|
+
|
|
246
|
+
// -----------SQL CONFIG----------
|
|
247
|
+
// Object (`window` in the browser) on which there may be an
|
|
248
|
+
// `openDatabase` method (if any) for WebSQL. (The browser
|
|
249
|
+
// throws if attempting to call `openDatabase` without the window
|
|
250
|
+
// so this is why the config doesn't just allow the function.)
|
|
251
|
+
// Defaults to `window` or `self` in browser builds or
|
|
252
|
+
// a singleton object with the `openDatabase` method set to
|
|
253
|
+
// the "websql" package in Node.
|
|
254
|
+
'win',
|
|
255
|
+
// For internal `openDatabase` calls made by `IDBFactory` methods;
|
|
256
|
+
// per the WebSQL spec, "User agents are expected to use the display name
|
|
257
|
+
// and the estimated database size to optimize the user experience.
|
|
258
|
+
// For example, a user agent could use the estimated size to suggest an
|
|
259
|
+
// initial quota to the user. This allows a site that is aware that it
|
|
260
|
+
// will try to use hundreds of megabytes to declare this upfront, instead
|
|
261
|
+
// of the user agent prompting the user for permission to increase the
|
|
262
|
+
// quota every five megabytes."
|
|
263
|
+
// Defaults to (4 * 1024 * 1024) or (25 * 1024 * 1024) in Safari
|
|
264
|
+
'DEFAULT_DB_SIZE',
|
|
265
|
+
// Whether to create indexes on SQLite tables (and also whether to try
|
|
266
|
+
// dropping)
|
|
267
|
+
// Effectively defaults to `false` (ignored unless `true`)
|
|
268
|
+
'useSQLiteIndexes',
|
|
269
|
+
// NODE-IMPINGING SETTINGS (created for sake of limitations in Node
|
|
270
|
+
// or desktop file system implementation but applied by default in
|
|
271
|
+
// browser for parity)
|
|
272
|
+
|
|
273
|
+
// File system module with `unlink` to remove deleted database files
|
|
274
|
+
'fs',
|
|
275
|
+
// Used when setting global shims to determine whether to try to add
|
|
276
|
+
// other globals shimmed by the library (`ShimDOMException`,
|
|
277
|
+
// `ShimDOMStringList`, `ShimEvent`, `ShimCustomEvent`, `ShimEventTarget`)
|
|
278
|
+
// Effectively defaults to `false` (ignored unless `true`)
|
|
279
|
+
'addNonIDBGlobals',
|
|
280
|
+
// Used when setting global shims to determine whether to try to overwrite
|
|
281
|
+
// other globals shimmed by the library (`DOMException`, `DOMStringList`,
|
|
282
|
+
// `Event`, `CustomEvent`, `EventTarget`)
|
|
283
|
+
// Effectively defaults to `false` (ignored unless `true`)
|
|
284
|
+
'replaceNonIDBGlobals',
|
|
285
|
+
// Overcoming limitations with node-sqlite3/storing database name on
|
|
286
|
+
// file systems
|
|
287
|
+
// https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
|
288
|
+
// Defaults to prefixing database with `D_`, escaping
|
|
289
|
+
// `databaseCharacterEscapeList`, escaping NUL, and
|
|
290
|
+
// escaping upper case letters, as well as enforcing
|
|
291
|
+
// `databaseNameLengthLimit`
|
|
292
|
+
'escapeDatabaseName',
|
|
293
|
+
// Not used internally; usable as a convenience method
|
|
294
|
+
'unescapeDatabaseName',
|
|
295
|
+
// Defaults to global regex representing the following
|
|
296
|
+
// (characters nevertheless commonly reserved in modern,
|
|
297
|
+
// Unicode-supporting systems): 0x00-0x1F 0x7F " * / : < > ? \ |
|
|
298
|
+
'databaseCharacterEscapeList',
|
|
299
|
+
// Defaults to 254 (shortest typical modern file length limit)
|
|
300
|
+
'databaseNameLengthLimit',
|
|
301
|
+
// Boolean defaulting to true on whether to escape NFD-escaping
|
|
302
|
+
// characters to avoid clashes on MacOS which performs NFD on files
|
|
303
|
+
'escapeNFDForDatabaseNames',
|
|
304
|
+
// Boolean on whether to add the `.sqlite` extension to file names;
|
|
305
|
+
// defaults to `true`
|
|
306
|
+
'addSQLiteExtension',
|
|
307
|
+
// Various types of in-memory databases that can auto-delete
|
|
308
|
+
['memoryDatabase',
|
|
309
|
+
/**
|
|
310
|
+
* @param {string} val
|
|
311
|
+
* @throws {TypeError}
|
|
312
|
+
* @returns {void}
|
|
313
|
+
*/
|
|
314
|
+
function (val) {
|
|
315
|
+
if (!/^(?::memory:|file::memory:(\?(?:[\0-"\$-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?(#(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?)?$/.test(/** @type {string} */val)) {
|
|
316
|
+
throw new TypeError('`memoryDatabase` must be the empty string, ":memory:", or a ' + '"file::memory:[?queryString][#hash] URL".');
|
|
317
|
+
}
|
|
318
|
+
}],
|
|
319
|
+
// NODE-SPECIFIC CONFIG
|
|
320
|
+
// Boolean on whether to delete the database file itself after
|
|
321
|
+
// `deleteDatabase`; defaults to `true` as the database will be empty
|
|
322
|
+
'deleteDatabaseFiles', 'databaseBasePath', 'sysDatabaseBasePath',
|
|
323
|
+
// NODE-SPECIFIC WEBSQL CONFIG
|
|
324
|
+
'sqlBusyTimeout',
|
|
325
|
+
// Defaults to 1000
|
|
326
|
+
'sqlTrace',
|
|
327
|
+
// Callback not used by default
|
|
328
|
+
'sqlProfile',
|
|
329
|
+
// Callback not used by default
|
|
330
|
+
// Defaults to true except in Node builds where we can preserve literal NUL with better-sqlite3
|
|
331
|
+
'escapeNULForSQLiteStatements', 'createIndexes'].forEach(function (prop) {
|
|
332
|
+
/** @type {(val: any) => void} */
|
|
333
|
+
var validator;
|
|
334
|
+
if (Array.isArray(prop)) {
|
|
335
|
+
var _prop = prop;
|
|
336
|
+
var _prop2 = _slicedToArray(_prop, 2);
|
|
337
|
+
prop = _prop2[0];
|
|
338
|
+
validator = _prop2[1];
|
|
339
|
+
}
|
|
340
|
+
Object.defineProperty(CFG, prop, {
|
|
341
|
+
get: function get() {
|
|
342
|
+
return map[prop];
|
|
343
|
+
},
|
|
344
|
+
set: function set(val) {
|
|
345
|
+
if (validator) {
|
|
346
|
+
validator(val);
|
|
366
347
|
}
|
|
348
|
+
map[prop] = val;
|
|
367
349
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Creates a native DOMException, for browsers that support it.
|
|
355
|
+
* @param {string} name
|
|
356
|
+
* @param {string} message
|
|
357
|
+
* @returns {DOMException}
|
|
358
|
+
*/
|
|
359
|
+
function createNativeDOMException(name, message) {
|
|
360
|
+
// @ts-expect-error It's ok
|
|
361
|
+
return new DOMException.prototype.constructor(message, name || 'DOMException');
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// From web-platform-tests testharness.js name_code_map (though not in new spec)
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* @typedef {"IndexSizeError"|"HierarchyRequestError"|"WrongDocumentError"|
|
|
368
|
+
* "InvalidCharacterError"|"NoModificationAllowedError"|"NotFoundError"|
|
|
369
|
+
* "NotSupportedError"|"InUseAttributeError"|"InvalidStateError"|
|
|
370
|
+
* "SyntaxError"|"InvalidModificationError"|"NamespaceError"|
|
|
371
|
+
* "InvalidAccessError"|"TypeMismatchError"|"SecurityError"|
|
|
372
|
+
* "NetworkError"|"AbortError"|"URLMismatchError"|"QuotaExceededError"|
|
|
373
|
+
* "TimeoutError"|"InvalidNodeTypeError"|"DataCloneError"|"EncodingError"|
|
|
374
|
+
* "NotReadableError"|"UnknownError"|"ConstraintError"|"DataError"|
|
|
375
|
+
* "TransactionInactiveError"|"ReadOnlyError"|"VersionError"|
|
|
376
|
+
* "OperationError"|"NotAllowedError"} Code
|
|
377
|
+
*/
|
|
378
|
+
|
|
379
|
+
var codes = {
|
|
380
|
+
IndexSizeError: 1,
|
|
381
|
+
HierarchyRequestError: 3,
|
|
382
|
+
WrongDocumentError: 4,
|
|
383
|
+
InvalidCharacterError: 5,
|
|
384
|
+
NoModificationAllowedError: 7,
|
|
385
|
+
NotFoundError: 8,
|
|
386
|
+
NotSupportedError: 9,
|
|
387
|
+
InUseAttributeError: 10,
|
|
388
|
+
InvalidStateError: 11,
|
|
389
|
+
SyntaxError: 12,
|
|
390
|
+
InvalidModificationError: 13,
|
|
391
|
+
NamespaceError: 14,
|
|
392
|
+
InvalidAccessError: 15,
|
|
393
|
+
TypeMismatchError: 17,
|
|
394
|
+
SecurityError: 18,
|
|
395
|
+
NetworkError: 19,
|
|
396
|
+
AbortError: 20,
|
|
397
|
+
URLMismatchError: 21,
|
|
398
|
+
QuotaExceededError: 22,
|
|
399
|
+
TimeoutError: 23,
|
|
400
|
+
InvalidNodeTypeError: 24,
|
|
401
|
+
DataCloneError: 25,
|
|
402
|
+
EncodingError: 0,
|
|
403
|
+
NotReadableError: 0,
|
|
404
|
+
UnknownError: 0,
|
|
405
|
+
ConstraintError: 0,
|
|
406
|
+
DataError: 0,
|
|
407
|
+
TransactionInactiveError: 0,
|
|
408
|
+
ReadOnlyError: 0,
|
|
409
|
+
VersionError: 0,
|
|
410
|
+
OperationError: 0,
|
|
411
|
+
NotAllowedError: 0
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* @typedef {"INDEX_SIZE_ERR"|"DOMSTRING_SIZE_ERR"|"HIERARCHY_REQUEST_ERR"|
|
|
416
|
+
* "WRONG_DOCUMENT_ERR"|"INVALID_CHARACTER_ERR"|"NO_DATA_ALLOWED_ERR"|
|
|
417
|
+
* "NO_MODIFICATION_ALLOWED_ERR"|"NOT_FOUND_ERR"|"NOT_SUPPORTED_ERR"|
|
|
418
|
+
* "INUSE_ATTRIBUTE_ERR"|"INVALID_STATE_ERR"|"SYNTAX_ERR"|
|
|
419
|
+
* "INVALID_MODIFICATION_ERR"|"NAMESPACE_ERR"|"INVALID_ACCESS_ERR"|
|
|
420
|
+
* "VALIDATION_ERR"|"TYPE_MISMATCH_ERR"|"SECURITY_ERR"|"NETWORK_ERR"|
|
|
421
|
+
* "ABORT_ERR"|"URL_MISMATCH_ERR"|"QUOTA_EXCEEDED_ERR"|"TIMEOUT_ERR"|
|
|
422
|
+
* "INVALID_NODE_TYPE_ERR"|"DATA_CLONE_ERR"} LegacyCode
|
|
423
|
+
*/
|
|
424
|
+
|
|
425
|
+
var legacyCodes = {
|
|
426
|
+
INDEX_SIZE_ERR: 1,
|
|
427
|
+
DOMSTRING_SIZE_ERR: 2,
|
|
428
|
+
HIERARCHY_REQUEST_ERR: 3,
|
|
429
|
+
WRONG_DOCUMENT_ERR: 4,
|
|
430
|
+
INVALID_CHARACTER_ERR: 5,
|
|
431
|
+
NO_DATA_ALLOWED_ERR: 6,
|
|
432
|
+
NO_MODIFICATION_ALLOWED_ERR: 7,
|
|
433
|
+
NOT_FOUND_ERR: 8,
|
|
434
|
+
NOT_SUPPORTED_ERR: 9,
|
|
435
|
+
INUSE_ATTRIBUTE_ERR: 10,
|
|
436
|
+
INVALID_STATE_ERR: 11,
|
|
437
|
+
SYNTAX_ERR: 12,
|
|
438
|
+
INVALID_MODIFICATION_ERR: 13,
|
|
439
|
+
NAMESPACE_ERR: 14,
|
|
440
|
+
INVALID_ACCESS_ERR: 15,
|
|
441
|
+
VALIDATION_ERR: 16,
|
|
442
|
+
TYPE_MISMATCH_ERR: 17,
|
|
443
|
+
SECURITY_ERR: 18,
|
|
444
|
+
NETWORK_ERR: 19,
|
|
445
|
+
ABORT_ERR: 20,
|
|
446
|
+
URL_MISMATCH_ERR: 21,
|
|
447
|
+
QUOTA_EXCEEDED_ERR: 22,
|
|
448
|
+
TIMEOUT_ERR: 23,
|
|
449
|
+
INVALID_NODE_TYPE_ERR: 24,
|
|
450
|
+
DATA_CLONE_ERR: 25
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
*
|
|
455
|
+
* @returns {typeof DOMException}
|
|
456
|
+
*/
|
|
457
|
+
function createNonNativeDOMExceptionClass() {
|
|
458
|
+
/**
|
|
459
|
+
* @param {string|undefined} message
|
|
460
|
+
* @param {Code|LegacyCode} name
|
|
461
|
+
* @returns {void}
|
|
462
|
+
*/
|
|
463
|
+
function DOMException(message, name) {
|
|
464
|
+
// const err = Error.prototype.constructor.call(this, message); // Any use to this? Won't set this.message
|
|
465
|
+
this[Symbol.toStringTag] = 'DOMException';
|
|
466
|
+
this._code = Object.hasOwn(codes, name) ? codes[(/** @type {Code} */name)] : legacyCodes[(/** @type {LegacyCode} */name)] || 0;
|
|
467
|
+
this._name = name || 'Error';
|
|
468
|
+
// We avoid `String()` in this next line as it converts Symbols
|
|
469
|
+
this._message = message === undefined ? '' : '' + message; // eslint-disable-line no-implicit-coercion -- Don't convert symbols
|
|
470
|
+
Object.defineProperty(this, 'code', {
|
|
401
471
|
configurable: true,
|
|
402
472
|
enumerable: true,
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
406
|
-
});
|
|
407
|
-
// @ts-expect-error It's ok
|
|
408
|
-
DOMException.prototype = new DummyDOMException();
|
|
409
|
-
DOMException.prototype[Symbol.toStringTag] = 'DOMExceptionPrototype';
|
|
410
|
-
Object.defineProperty(DOMException, 'prototype', {
|
|
411
|
-
writable: false
|
|
412
|
-
});
|
|
413
|
-
const keys = Object.keys(codes);
|
|
414
|
-
|
|
415
|
-
/** @type {(keyof codes)[]} */
|
|
416
|
-
keys.forEach(codeName => {
|
|
417
|
-
Object.defineProperty(DOMException.prototype, codeName, {
|
|
418
|
-
enumerable: true,
|
|
419
|
-
configurable: false,
|
|
420
|
-
value: codes[codeName]
|
|
421
|
-
});
|
|
422
|
-
Object.defineProperty(DOMException, codeName, {
|
|
423
|
-
enumerable: true,
|
|
424
|
-
configurable: false,
|
|
425
|
-
value: codes[codeName]
|
|
426
|
-
});
|
|
473
|
+
writable: true,
|
|
474
|
+
value: this._code
|
|
427
475
|
});
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
enumerable: true,
|
|
432
|
-
configurable: false,
|
|
433
|
-
value: legacyCodes[codeName]
|
|
434
|
-
});
|
|
435
|
-
Object.defineProperty(DOMException, codeName, {
|
|
476
|
+
if (name !== undefined) {
|
|
477
|
+
Object.defineProperty(this, 'name', {
|
|
478
|
+
configurable: true,
|
|
436
479
|
enumerable: true,
|
|
437
|
-
|
|
438
|
-
value:
|
|
480
|
+
writable: true,
|
|
481
|
+
value: this._name
|
|
439
482
|
});
|
|
440
|
-
});
|
|
441
|
-
Object.defineProperty(DOMException.prototype, 'constructor', {
|
|
442
|
-
writable: true,
|
|
443
|
-
configurable: true,
|
|
444
|
-
enumerable: false,
|
|
445
|
-
value: DOMException
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
// @ts-expect-error We don't need all its properties
|
|
449
|
-
return DOMException;
|
|
450
|
-
}
|
|
451
|
-
const ShimNonNativeDOMException = createNonNativeDOMExceptionClass();
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* Creates a generic Error object.
|
|
455
|
-
* @param {string} name
|
|
456
|
-
* @param {string} message
|
|
457
|
-
* @returns {Error}
|
|
458
|
-
*/
|
|
459
|
-
function createNonNativeDOMException(name, message) {
|
|
460
|
-
return new ShimNonNativeDOMException(message, name);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
/**
|
|
464
|
-
* @typedef {{
|
|
465
|
-
* message: string|DOMString
|
|
466
|
-
* }} ErrorLike
|
|
467
|
-
*/
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Logs detailed error information to the console.
|
|
471
|
-
* @param {string} name
|
|
472
|
-
* @param {string} message
|
|
473
|
-
* @param {string|ErrorLike|boolean|null} [error]
|
|
474
|
-
* @returns {void}
|
|
475
|
-
*/
|
|
476
|
-
function logError(name, message, error) {
|
|
477
|
-
if (CFG.DEBUG) {
|
|
478
|
-
const msg = error && typeof error === 'object' && error.message ? error.message : (/** @type {string} */error);
|
|
479
|
-
const method = typeof console.error === 'function' ? 'error' : 'log';
|
|
480
|
-
console[method](name + ': ' + message + '. ' + (msg || ''));
|
|
481
|
-
if (console.trace) {
|
|
482
|
-
console.trace();
|
|
483
|
-
}
|
|
484
483
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
* @param {ArbitraryValue} obj
|
|
493
|
-
* @returns {boolean}
|
|
494
|
-
*/
|
|
495
|
-
function isErrorOrDOMErrorOrDOMException(obj) {
|
|
496
|
-
return obj && typeof obj === 'object' &&
|
|
497
|
-
// We don't use util.isObj here as mutual dependency causing problems in Babel with browser
|
|
498
|
-
typeof obj.name === 'string';
|
|
499
|
-
}
|
|
500
|
-
let test,
|
|
501
|
-
useNativeDOMException = false;
|
|
502
|
-
|
|
503
|
-
// Test whether we can use the browser's native DOMException class
|
|
504
|
-
try {
|
|
505
|
-
test = createNativeDOMException('test name', 'test message');
|
|
506
|
-
if (isErrorOrDOMErrorOrDOMException(test) && test.name === 'test name' && test.message === 'test message') {
|
|
507
|
-
// Native DOMException works as expected
|
|
508
|
-
useNativeDOMException = true;
|
|
484
|
+
if (message !== undefined) {
|
|
485
|
+
Object.defineProperty(this, 'message', {
|
|
486
|
+
configurable: true,
|
|
487
|
+
enumerable: false,
|
|
488
|
+
writable: true,
|
|
489
|
+
value: this._message
|
|
490
|
+
});
|
|
509
491
|
}
|
|
510
|
-
} catch (err) {}
|
|
511
|
-
const createDOMException = useNativeDOMException
|
|
512
|
-
// eslint-disable-next-line @stylistic/operator-linebreak -- Need JSDoc
|
|
513
|
-
?
|
|
514
|
-
/**
|
|
515
|
-
* @param {string} name
|
|
516
|
-
* @param {string} message
|
|
517
|
-
* @param {ErrorLike} [error]
|
|
518
|
-
* @returns {DOMException}
|
|
519
|
-
*/
|
|
520
|
-
function (name, message, error) {
|
|
521
|
-
logError(name, message, error);
|
|
522
|
-
return createNativeDOMException(name, message);
|
|
523
492
|
}
|
|
524
|
-
// eslint-disable-next-line @stylistic/operator-linebreak -- Need JSDoc
|
|
525
|
-
:
|
|
526
|
-
/**
|
|
527
|
-
* @param {string} name
|
|
528
|
-
* @param {string} message
|
|
529
|
-
* @param {ErrorLike} [error]
|
|
530
|
-
* @returns {Error}
|
|
531
|
-
*/
|
|
532
|
-
function (name, message, error) {
|
|
533
|
-
logError(name, message, error);
|
|
534
|
-
return createNonNativeDOMException(name, message);
|
|
535
|
-
};
|
|
536
493
|
|
|
537
|
-
|
|
538
|
-
/* eslint-disable sonarjs/no-control-regex -- Needed */
|
|
494
|
+
// Necessary for W3C tests which complains if `DOMException` has properties on its "own" prototype
|
|
539
495
|
|
|
496
|
+
// class DummyDOMException extends Error {}; // Sometimes causing problems in Node
|
|
497
|
+
/* eslint-disable func-name-matching -- See above */
|
|
540
498
|
/**
|
|
541
|
-
* @
|
|
499
|
+
* @class
|
|
542
500
|
*/
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
501
|
+
var DummyDOMException = function DOMException() {/* */};
|
|
502
|
+
/* eslint-enable func-name-matching -- See above */
|
|
503
|
+
DummyDOMException.prototype = Object.create(Error.prototype); // Intended for subclassing
|
|
504
|
+
/** @type {const} */
|
|
505
|
+
['name', 'message'].forEach(function (prop) {
|
|
506
|
+
Object.defineProperty(DummyDOMException.prototype, prop, {
|
|
507
|
+
enumerable: true,
|
|
508
|
+
/**
|
|
509
|
+
* @this {DOMException}
|
|
510
|
+
* @returns {string}
|
|
511
|
+
*/
|
|
512
|
+
get: function get() {
|
|
513
|
+
if (!(this instanceof DOMException ||
|
|
514
|
+
// @ts-expect-error Just checking
|
|
515
|
+
this instanceof DummyDOMException ||
|
|
516
|
+
// @ts-expect-error Just checking
|
|
517
|
+
this instanceof Error)) {
|
|
518
|
+
throw new TypeError('Illegal invocation');
|
|
519
|
+
}
|
|
520
|
+
return this[prop === 'name' ? '_name' : '_message'];
|
|
555
521
|
}
|
|
556
|
-
return (precedingLow || '') + '^3' + unmatchedLowSurrogate.codePointAt().toString(16).padStart(4, '0');
|
|
557
522
|
});
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
function isObj(obj) {
|
|
575
|
-
return obj !== null && typeof obj === 'object';
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
/**
|
|
579
|
-
*
|
|
580
|
-
* @param {object} obj
|
|
581
|
-
* @returns {boolean}
|
|
582
|
-
*/
|
|
583
|
-
function isDate(obj) {
|
|
584
|
-
return isObj(obj) && 'getDate' in obj && typeof obj.getDate === 'function';
|
|
585
|
-
}
|
|
523
|
+
});
|
|
524
|
+
// DOMException uses the same `toString` as `Error`
|
|
525
|
+
Object.defineProperty(DummyDOMException.prototype, 'code', {
|
|
526
|
+
configurable: true,
|
|
527
|
+
enumerable: true,
|
|
528
|
+
get: function get() {
|
|
529
|
+
throw new TypeError('Illegal invocation');
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
// @ts-expect-error It's ok
|
|
533
|
+
DOMException.prototype = new DummyDOMException();
|
|
534
|
+
DOMException.prototype[Symbol.toStringTag] = 'DOMExceptionPrototype';
|
|
535
|
+
Object.defineProperty(DOMException, 'prototype', {
|
|
536
|
+
writable: false
|
|
537
|
+
});
|
|
538
|
+
var keys = Object.keys(codes);
|
|
586
539
|
|
|
587
|
-
/**
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
540
|
+
/** @type {(keyof codes)[]} */
|
|
541
|
+
keys.forEach(function (codeName) {
|
|
542
|
+
Object.defineProperty(DOMException.prototype, codeName, {
|
|
543
|
+
enumerable: true,
|
|
544
|
+
configurable: false,
|
|
545
|
+
value: codes[codeName]
|
|
546
|
+
});
|
|
547
|
+
Object.defineProperty(DOMException, codeName, {
|
|
548
|
+
enumerable: true,
|
|
549
|
+
configurable: false,
|
|
550
|
+
value: codes[codeName]
|
|
551
|
+
});
|
|
552
|
+
});
|
|
553
|
+
/** @type {(keyof legacyCodes)[]} */
|
|
554
|
+
Object.keys(legacyCodes).forEach(function (codeName) {
|
|
555
|
+
Object.defineProperty(DOMException.prototype, codeName, {
|
|
556
|
+
enumerable: true,
|
|
557
|
+
configurable: false,
|
|
558
|
+
value: legacyCodes[codeName]
|
|
559
|
+
});
|
|
560
|
+
Object.defineProperty(DOMException, codeName, {
|
|
561
|
+
enumerable: true,
|
|
562
|
+
configurable: false,
|
|
563
|
+
value: legacyCodes[codeName]
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
Object.defineProperty(DOMException.prototype, 'constructor', {
|
|
567
|
+
writable: true,
|
|
568
|
+
configurable: true,
|
|
569
|
+
enumerable: false,
|
|
570
|
+
value: DOMException
|
|
571
|
+
});
|
|
595
572
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
573
|
+
// @ts-expect-error We don't need all its properties
|
|
574
|
+
return DOMException;
|
|
575
|
+
}
|
|
576
|
+
var ShimNonNativeDOMException = createNonNativeDOMExceptionClass();
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Creates a generic Error object.
|
|
580
|
+
* @param {string} name
|
|
581
|
+
* @param {string} message
|
|
582
|
+
* @returns {Error}
|
|
583
|
+
*/
|
|
584
|
+
function createNonNativeDOMException(name, message) {
|
|
585
|
+
return new ShimNonNativeDOMException(message, name);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* @typedef {{
|
|
590
|
+
* message: string|DOMString
|
|
591
|
+
* }} ErrorLike
|
|
592
|
+
*/
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Logs detailed error information to the console.
|
|
596
|
+
* @param {string} name
|
|
597
|
+
* @param {string} message
|
|
598
|
+
* @param {string|ErrorLike|boolean|null} [error]
|
|
599
|
+
* @returns {void}
|
|
600
|
+
*/
|
|
601
|
+
function logError(name, message, error) {
|
|
602
|
+
if (!CFG.DEBUG) {
|
|
603
|
+
return;
|
|
603
604
|
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
*/
|
|
610
|
-
function isBinary(obj) {
|
|
611
|
-
return isObj(obj) && 'byteLength' in obj && typeof obj.byteLength === 'number' && ('slice' in obj && typeof obj.slice === 'function' ||
|
|
612
|
-
// `TypedArray` (view on buffer) or `ArrayBuffer`
|
|
613
|
-
'getFloat64' in obj && typeof obj.getFloat64 === 'function' // `DataView` (view on buffer)
|
|
614
|
-
);
|
|
605
|
+
var msg = error && _typeof(error) === 'object' && error.message ? error.message : (/** @type {string} */error);
|
|
606
|
+
var method = typeof console.error === 'function' ? 'error' : 'log';
|
|
607
|
+
console[method](name + ': ' + message + '. ' + (msg || ''));
|
|
608
|
+
if (console.trace) {
|
|
609
|
+
console.trace();
|
|
615
610
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* @typedef {any} ArbitraryValue
|
|
615
|
+
*/
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* @param {ArbitraryValue} obj
|
|
619
|
+
* @returns {boolean}
|
|
620
|
+
*/
|
|
621
|
+
function isErrorOrDOMErrorOrDOMException(obj) {
|
|
622
|
+
return obj && _typeof(obj) === 'object' &&
|
|
623
|
+
// We don't use util.isObj here as mutual dependency causing problems in Babel with browser
|
|
624
|
+
typeof obj.name === 'string';
|
|
625
|
+
}
|
|
626
|
+
var test,
|
|
627
|
+
useNativeDOMException = false;
|
|
628
|
+
|
|
629
|
+
// Test whether we can use the browser's native DOMException class
|
|
630
|
+
try {
|
|
631
|
+
test = createNativeDOMException('test name', 'test message');
|
|
632
|
+
if (isErrorOrDOMErrorOrDOMException(test) && test.name === 'test name' && test.message === 'test message') {
|
|
633
|
+
// Native DOMException works as expected
|
|
634
|
+
useNativeDOMException = true;
|
|
623
635
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
636
|
+
} catch (err) {}
|
|
637
|
+
var createDOMException = useNativeDOMException
|
|
638
|
+
// eslint-disable-next-line @stylistic/operator-linebreak -- Need JSDoc
|
|
639
|
+
?
|
|
640
|
+
/**
|
|
641
|
+
* @param {string} name
|
|
642
|
+
* @param {string} message
|
|
643
|
+
* @param {ErrorLike} [error]
|
|
644
|
+
* @returns {DOMException}
|
|
645
|
+
*/
|
|
646
|
+
function (name, message, error) {
|
|
647
|
+
logError(name, message, error);
|
|
648
|
+
return createNativeDOMException(name, message);
|
|
649
|
+
}
|
|
650
|
+
// eslint-disable-next-line @stylistic/operator-linebreak -- Need JSDoc
|
|
651
|
+
:
|
|
652
|
+
/**
|
|
653
|
+
* @param {string} name
|
|
654
|
+
* @param {string} message
|
|
655
|
+
* @param {ErrorLike} [error]
|
|
656
|
+
* @returns {Error}
|
|
657
|
+
*/
|
|
658
|
+
function (name, message, error) {
|
|
659
|
+
logError(name, message, error);
|
|
660
|
+
return createNonNativeDOMException(name, message);
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* @typedef {number} Integer
|
|
665
|
+
*/
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* @param {string} arg
|
|
669
|
+
* @returns {string}
|
|
670
|
+
*/
|
|
671
|
+
function escapeUnmatchedSurrogates(arg) {
|
|
672
|
+
// https://stackoverflow.com/a/6701665/271577
|
|
673
|
+
return arg.replaceAll(/((?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])))(?!(?:(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))|(^|(?:[\0-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))((?:(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/g, function (_, unmatchedHighSurrogate, precedingLow, unmatchedLowSurrogate) {
|
|
674
|
+
// Could add a corresponding surrogate for compatibility with `node-sqlite3`: https://bugs.python.org/issue12569 and https://stackoverflow.com/a/6701665/271577
|
|
675
|
+
// but Chrome having problems
|
|
676
|
+
if (unmatchedHighSurrogate) {
|
|
677
|
+
return '^2' + unmatchedHighSurrogate.codePointAt().toString(16).padStart(4, '0');
|
|
656
678
|
}
|
|
657
|
-
return
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
/**
|
|
661
|
-
* @typedef {NodeJS.TypedArray|DataView} ArrayBufferView
|
|
662
|
-
*/
|
|
663
|
-
|
|
664
|
-
/**
|
|
665
|
-
* @typedef {ArrayBufferView|ArrayBuffer} BufferSource
|
|
666
|
-
*/
|
|
667
|
-
|
|
668
|
-
/**
|
|
669
|
-
* @typedef {"number"|"date"|"string"|"binary"|"array"} KeyType
|
|
670
|
-
*/
|
|
671
|
-
|
|
672
|
-
/**
|
|
673
|
-
* @typedef {any} Value
|
|
674
|
-
*/
|
|
675
|
-
|
|
676
|
-
/**
|
|
677
|
-
* @typedef {any} Key
|
|
678
|
-
* @todo Specify possible value more precisely
|
|
679
|
-
*/
|
|
680
|
-
|
|
681
|
-
/**
|
|
682
|
-
* @typedef {KeyPath[]} KeyPathArray
|
|
683
|
-
*/
|
|
684
|
-
/**
|
|
685
|
-
* @typedef {string|KeyPathArray} KeyPath
|
|
686
|
-
*/
|
|
687
|
-
|
|
688
|
-
/**
|
|
689
|
-
* @typedef {object} KeyValueObject
|
|
690
|
-
* @property {KeyType|"NaN"|"null"|"undefined"|"boolean"|"object"|"symbol"|
|
|
691
|
-
* "function"|"bigint"} type If not `KeyType`, indicates invalid value
|
|
692
|
-
* @property {Value} [value]
|
|
693
|
-
* @property {boolean} [invalid]
|
|
694
|
-
* @property {string} [message]
|
|
695
|
-
* @todo Specify acceptable `value` more precisely
|
|
696
|
-
*/
|
|
697
|
-
|
|
698
|
-
/**
|
|
699
|
-
* @typedef {number|string|Date|ArrayBuffer} ValueTypePrimitive
|
|
700
|
-
*/
|
|
701
|
-
/**
|
|
702
|
-
* @typedef {ValueType[]} ValueTypeArray
|
|
703
|
-
*/
|
|
704
|
-
/**
|
|
705
|
-
* @typedef {ValueTypePrimitive|ValueTypeArray} ValueType
|
|
706
|
-
*/
|
|
707
|
-
|
|
708
|
-
/**
|
|
709
|
-
* Encodes the keys based on their types. This is required to maintain collations
|
|
710
|
-
* We leave space for future keys.
|
|
711
|
-
* @type {{[key: string]: Integer|string}}
|
|
712
|
-
*/
|
|
713
|
-
const keyTypeToEncodedChar = {
|
|
714
|
-
invalid: 100,
|
|
715
|
-
number: 200,
|
|
716
|
-
date: 300,
|
|
717
|
-
string: 400,
|
|
718
|
-
binary: 500,
|
|
719
|
-
array: 600
|
|
720
|
-
};
|
|
721
|
-
const keyTypes = /** @type {(KeyType|"invalid")[]} */Object.keys(keyTypeToEncodedChar);
|
|
722
|
-
keyTypes.forEach(k => {
|
|
723
|
-
keyTypeToEncodedChar[k] = String.fromCodePoint(/** @type {number} */keyTypeToEncodedChar[k]);
|
|
679
|
+
return (precedingLow || '') + '^3' + unmatchedLowSurrogate.codePointAt().toString(16).padStart(4, '0');
|
|
724
680
|
});
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* The escaping of unmatched surrogates was needed by Chrome but not Node.
|
|
685
|
+
* @param {string} arg
|
|
686
|
+
* @returns {string}
|
|
687
|
+
*/
|
|
688
|
+
function escapeSQLiteStatement(arg) {
|
|
689
|
+
var escaped = arg.replaceAll('^', '^^');
|
|
690
|
+
return escapeUnmatchedSurrogates(CFG.escapeNULForSQLiteStatements === false ? escaped : escaped.replaceAll('\0', '^0'));
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
*
|
|
695
|
+
* @param {AnyValue} obj
|
|
696
|
+
* @returns {obj is object}
|
|
697
|
+
*/
|
|
698
|
+
function isObj(obj) {
|
|
699
|
+
return obj !== null && _typeof(obj) === 'object';
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
*
|
|
704
|
+
* @param {object} obj
|
|
705
|
+
* @returns {boolean}
|
|
706
|
+
*/
|
|
707
|
+
function isDate(obj) {
|
|
708
|
+
return isObj(obj) && 'getDate' in obj && typeof obj.getDate === 'function';
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
*
|
|
713
|
+
* @param {object} obj
|
|
714
|
+
* @returns {boolean}
|
|
715
|
+
*/
|
|
716
|
+
function isBlob(obj) {
|
|
717
|
+
return isObj(obj) && 'size' in obj && typeof obj.size === 'number' && 'slice' in obj && typeof obj.slice === 'function' && !('lastModified' in obj);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
*
|
|
722
|
+
* @param {object} obj
|
|
723
|
+
* @returns {boolean}
|
|
724
|
+
*/
|
|
725
|
+
function isFile(obj) {
|
|
726
|
+
return isObj(obj) && 'name' in obj && typeof obj.name === 'string' && 'slice' in obj && typeof obj.slice === 'function' && 'lastModified' in obj;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
*
|
|
731
|
+
* @param {AnyValue} obj
|
|
732
|
+
* @returns {boolean}
|
|
733
|
+
*/
|
|
734
|
+
function isBinary(obj) {
|
|
735
|
+
return isObj(obj) && 'byteLength' in obj && typeof obj.byteLength === 'number' && ('slice' in obj && typeof obj.slice === 'function' ||
|
|
736
|
+
// `TypedArray` (view on buffer) or `ArrayBuffer`
|
|
737
|
+
'getFloat64' in obj && typeof obj.getFloat64 === 'function' // `DataView` (view on buffer)
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* @param {AnyValue} v
|
|
743
|
+
* @returns {v is null|undefined}
|
|
744
|
+
*/
|
|
745
|
+
function isNullish(v) {
|
|
746
|
+
return v === null || v === undefined;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* Compares two keys.
|
|
751
|
+
* @param {import('./Key.js').Key} first
|
|
752
|
+
* @param {import('./Key.js').Key} second
|
|
753
|
+
* @returns {0|1|-1}
|
|
754
|
+
*/
|
|
755
|
+
function cmp(first, second) {
|
|
756
|
+
var encodedKey1 = /** @type {string} */_encode(first);
|
|
757
|
+
var encodedKey2 = /** @type {string} */_encode(second);
|
|
758
|
+
var result = encodedKey1 > encodedKey2 ? 1 : encodedKey1 === encodedKey2 ? 0 : -1;
|
|
759
|
+
if (CFG.DEBUG) {
|
|
760
|
+
// verify that the keys encoded correctly
|
|
761
|
+
var decodedKey1 = _decode(encodedKey1);
|
|
762
|
+
var decodedKey2 = _decode(encodedKey2);
|
|
763
|
+
if (_typeof(first) === 'object') {
|
|
764
|
+
first = JSON.stringify(first);
|
|
765
|
+
decodedKey1 = JSON.stringify(decodedKey1);
|
|
766
|
+
}
|
|
767
|
+
if (_typeof(second) === 'object') {
|
|
768
|
+
second = JSON.stringify(second);
|
|
769
|
+
decodedKey2 = JSON.stringify(decodedKey2);
|
|
770
|
+
}
|
|
744
771
|
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
772
|
+
// Encoding/decoding mismatches are usually due to a loss of
|
|
773
|
+
// floating-point precision
|
|
774
|
+
if (decodedKey1 !== first) {
|
|
775
|
+
console.warn(first + ' was incorrectly encoded as ' + decodedKey1);
|
|
776
|
+
}
|
|
777
|
+
if (decodedKey2 !== second) {
|
|
778
|
+
console.warn(second + ' was incorrectly encoded as ' + decodedKey2);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
return result;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
var _templateObject, _templateObject2;
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* @typedef {NodeJS.TypedArray|DataView} ArrayBufferView
|
|
788
|
+
*/
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* @typedef {ArrayBufferView|ArrayBuffer} BufferSource
|
|
792
|
+
*/
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* @typedef {"number"|"date"|"string"|"binary"|"array"} KeyType
|
|
796
|
+
*/
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* @typedef {any} Value
|
|
800
|
+
*/
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* @typedef {any} Key
|
|
804
|
+
* @todo Specify possible value more precisely
|
|
805
|
+
*/
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* @typedef {KeyPath[]} KeyPathArray
|
|
809
|
+
*/
|
|
810
|
+
/**
|
|
811
|
+
* @typedef {string|KeyPathArray} KeyPath
|
|
812
|
+
*/
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* @typedef {object} KeyValueObject
|
|
816
|
+
* @property {KeyType|"NaN"|"null"|"undefined"|"boolean"|"object"|"symbol"|
|
|
817
|
+
* "function"|"bigint"} type If not `KeyType`, indicates invalid value
|
|
818
|
+
* @property {Value} [value]
|
|
819
|
+
* @property {boolean} [invalid]
|
|
820
|
+
* @property {string} [message]
|
|
821
|
+
* @todo Specify acceptable `value` more precisely
|
|
822
|
+
*/
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* @typedef {number|string|Date|ArrayBuffer} ValueTypePrimitive
|
|
826
|
+
*/
|
|
827
|
+
/**
|
|
828
|
+
* @typedef {ValueType[]} ValueTypeArray
|
|
829
|
+
*/
|
|
830
|
+
/**
|
|
831
|
+
* @typedef {ValueTypePrimitive|ValueTypeArray} ValueType
|
|
832
|
+
*/
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* Encodes the keys based on their types. This is required to maintain collations
|
|
836
|
+
* We leave space for future keys.
|
|
837
|
+
* @type {{[key: string]: Integer|string}}
|
|
838
|
+
*/
|
|
839
|
+
var keyTypeToEncodedChar = {
|
|
840
|
+
invalid: 100,
|
|
841
|
+
number: 200,
|
|
842
|
+
date: 300,
|
|
843
|
+
string: 400,
|
|
844
|
+
binary: 500,
|
|
845
|
+
array: 600
|
|
846
|
+
};
|
|
847
|
+
|
|
848
|
+
/* eslint-disable unicorn/no-top-level-side-effects -- Would be good */
|
|
849
|
+
var keyTypes = /** @type {(KeyType|"invalid")[]} */Object.keys(keyTypeToEncodedChar);
|
|
850
|
+
keyTypes.forEach(function (k) {
|
|
851
|
+
keyTypeToEncodedChar[k] = String.fromCodePoint(/** @type {number} */keyTypeToEncodedChar[k]);
|
|
852
|
+
});
|
|
853
|
+
/* eslint-enable unicorn/no-top-level-side-effects -- Would be good */
|
|
854
|
+
|
|
855
|
+
var encodedCharToKeyType = keyTypes.reduce(function (o, k) {
|
|
856
|
+
o[keyTypeToEncodedChar[k]] = k;
|
|
857
|
+
return o;
|
|
858
|
+
}, /** @type {{[key: string]: KeyType|"invalid"}} */{});
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* The sign values for numbers, ordered from least to greatest.
|
|
862
|
+
* - "negativeInfinity": Sorts below all other values.
|
|
863
|
+
* - "bigNegative": Negative values less than or equal to negative one.
|
|
864
|
+
* - "smallNegative": Negative values between negative one and zero, noninclusive.
|
|
865
|
+
* - "smallPositive": Positive values between zero and one, including zero but not one.
|
|
866
|
+
* - "largePositive": Positive values greater than or equal to one.
|
|
867
|
+
* - "positiveInfinity": Sorts above all other values.
|
|
868
|
+
*/
|
|
869
|
+
var signValues = ['negativeInfinity', 'bigNegative', 'smallNegative', 'smallPositive', 'bigPositive', 'positiveInfinity'];
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* @typedef {any} AnyValue
|
|
873
|
+
*/
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* @type {{
|
|
877
|
+
* [key: string]: {
|
|
878
|
+
* encode: (param: any, inArray?: boolean) => string,
|
|
879
|
+
* decode: (param: string, inArray?: boolean) => any
|
|
880
|
+
* }
|
|
881
|
+
* }}
|
|
882
|
+
*/
|
|
883
|
+
var types = {
|
|
884
|
+
invalid: {
|
|
885
|
+
/**
|
|
886
|
+
* @returns {string}
|
|
887
|
+
*/
|
|
888
|
+
encode: function encode() {
|
|
889
|
+
return keyTypeToEncodedChar.invalid + '-';
|
|
767
890
|
},
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
// Non-negative cases:
|
|
818
|
-
// Negative exponent case:
|
|
819
|
-
} else if (key < 1) {
|
|
820
|
-
sign = signValues.indexOf('smallPositive');
|
|
821
|
-
exponent = flipBase32(padBase32Exponent(significantDigitIndex));
|
|
822
|
-
mantissa = padBase32Mantissa(key32);
|
|
891
|
+
/**
|
|
892
|
+
* @returns {undefined}
|
|
893
|
+
*/
|
|
894
|
+
decode: function decode() {
|
|
895
|
+
return undefined;
|
|
896
|
+
}
|
|
897
|
+
},
|
|
898
|
+
// Numbers are represented in a lexically sortable base-32 sign-exponent-mantissa
|
|
899
|
+
// notation.
|
|
900
|
+
//
|
|
901
|
+
// sign: takes a value between zero and five, inclusive. Represents infinite cases
|
|
902
|
+
// and the signs of both the exponent and the fractional part of the number.
|
|
903
|
+
// exponent: padded to two base-32 digits, represented by the 32's compliment in the
|
|
904
|
+
// "smallPositive" and "bigNegative" cases to ensure proper lexical sorting.
|
|
905
|
+
// mantissa: also called the fractional part. Normed 11-digit base-32 representation.
|
|
906
|
+
// Represented by the 32's compliment in the "smallNegative" and "bigNegative"
|
|
907
|
+
// cases to ensure proper lexical sorting.
|
|
908
|
+
number: {
|
|
909
|
+
// The encode step checks for six numeric cases and generates 14-digit encoded
|
|
910
|
+
// sign-exponent-mantissa strings.
|
|
911
|
+
/**
|
|
912
|
+
* @param {number} key
|
|
913
|
+
* @returns {string}
|
|
914
|
+
*/
|
|
915
|
+
encode: function encode(key) {
|
|
916
|
+
var key32 = key === Number.MIN_VALUE
|
|
917
|
+
// Mocha test `IDBFactory/cmp-spec.js` exposed problem for some
|
|
918
|
+
// Node (and Chrome) versions with `Number.MIN_VALUE` being treated
|
|
919
|
+
// as 0
|
|
920
|
+
// https://stackoverflow.com/questions/43305403/number-min-value-and-tostring
|
|
921
|
+
? '0.' + '0'.repeat(214) + '2' : Math.abs(key).toString(32);
|
|
922
|
+
// Get the index of the decimal.
|
|
923
|
+
var decimalIndex = key32.indexOf('.');
|
|
924
|
+
// Remove the decimal.
|
|
925
|
+
key32 = decimalIndex !== -1 ? key32.replace('.', '') : key32;
|
|
926
|
+
// Get the index of the first significant digit.
|
|
927
|
+
var significantDigitIndex = key32.search(/(?:[\0-\/1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/);
|
|
928
|
+
// Truncate leading zeros.
|
|
929
|
+
key32 = key32.slice(significantDigitIndex);
|
|
930
|
+
var sign, exponent, mantissa;
|
|
931
|
+
|
|
932
|
+
// Finite cases:
|
|
933
|
+
if (Number.isFinite(Number(key))) {
|
|
934
|
+
// Negative cases:
|
|
935
|
+
if (key < 0) {
|
|
936
|
+
// Negative exponent case:
|
|
937
|
+
if (key > -1) {
|
|
938
|
+
sign = signValues.indexOf('smallNegative');
|
|
939
|
+
exponent = padBase32Exponent(significantDigitIndex);
|
|
823
940
|
// Non-negative exponent case:
|
|
824
941
|
} else {
|
|
825
|
-
sign = signValues.indexOf('
|
|
826
|
-
exponent = padBase32Exponent(decimalIndex !== -1 ? decimalIndex : key32.length);
|
|
827
|
-
mantissa = padBase32Mantissa(key32);
|
|
942
|
+
sign = signValues.indexOf('bigNegative');
|
|
943
|
+
exponent = flipBase32(padBase32Exponent(decimalIndex !== -1 ? decimalIndex : key32.length));
|
|
828
944
|
}
|
|
829
|
-
|
|
945
|
+
mantissa = flipBase32(padBase32Mantissa(key32));
|
|
946
|
+
// Non-negative cases:
|
|
947
|
+
// Negative exponent case:
|
|
948
|
+
} else if (key < 1) {
|
|
949
|
+
sign = signValues.indexOf('smallPositive');
|
|
950
|
+
exponent = flipBase32(padBase32Exponent(significantDigitIndex));
|
|
951
|
+
mantissa = padBase32Mantissa(key32);
|
|
952
|
+
// Non-negative exponent case:
|
|
830
953
|
} else {
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
}
|
|
835
|
-
return keyTypeToEncodedChar.number + '-' + sign + exponent + mantissa;
|
|
836
|
-
},
|
|
837
|
-
// The decode step must interpret the sign, reflip values encoded as the 32's complements,
|
|
838
|
-
// apply signs to the exponent and mantissa, do the base-32 power operation, and return
|
|
839
|
-
// the original JavaScript number values.
|
|
840
|
-
/**
|
|
841
|
-
* @param {string} key
|
|
842
|
-
* @returns {number}
|
|
843
|
-
*/
|
|
844
|
-
decode(key) {
|
|
845
|
-
const sign = Number(key.slice(2, 3));
|
|
846
|
-
let exponent = key.slice(3, 5);
|
|
847
|
-
let mantissa = key.slice(5, 16);
|
|
848
|
-
switch (signValues[sign]) {
|
|
849
|
-
case 'negativeInfinity':
|
|
850
|
-
return Number.NEGATIVE_INFINITY;
|
|
851
|
-
case 'positiveInfinity':
|
|
852
|
-
return Number.POSITIVE_INFINITY;
|
|
853
|
-
case 'bigPositive':
|
|
854
|
-
return pow32(mantissa, exponent);
|
|
855
|
-
case 'smallPositive':
|
|
856
|
-
exponent = negate(flipBase32(exponent));
|
|
857
|
-
return pow32(mantissa, exponent);
|
|
858
|
-
case 'smallNegative':
|
|
859
|
-
exponent = negate(exponent);
|
|
860
|
-
mantissa = flipBase32(mantissa);
|
|
861
|
-
return -pow32(mantissa, exponent);
|
|
862
|
-
case 'bigNegative':
|
|
863
|
-
exponent = flipBase32(exponent);
|
|
864
|
-
mantissa = flipBase32(mantissa);
|
|
865
|
-
return -pow32(mantissa, exponent);
|
|
866
|
-
default:
|
|
867
|
-
throw new Error('Invalid number.');
|
|
954
|
+
sign = signValues.indexOf('bigPositive');
|
|
955
|
+
exponent = padBase32Exponent(decimalIndex !== -1 ? decimalIndex : key32.length);
|
|
956
|
+
mantissa = padBase32Mantissa(key32);
|
|
868
957
|
}
|
|
958
|
+
// Infinite cases:
|
|
959
|
+
} else {
|
|
960
|
+
exponent = zeros(2);
|
|
961
|
+
mantissa = zeros(11);
|
|
962
|
+
sign = signValues.indexOf(key > 0 ? 'positiveInfinity' : 'negativeInfinity');
|
|
869
963
|
}
|
|
964
|
+
return keyTypeToEncodedChar.number + '-' + sign + exponent + mantissa;
|
|
870
965
|
},
|
|
871
|
-
//
|
|
872
|
-
//
|
|
873
|
-
//
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
}
|
|
903
|
-
return key;
|
|
966
|
+
// The decode step must interpret the sign, reflip values encoded as the 32's complements,
|
|
967
|
+
// apply signs to the exponent and mantissa, do the base-32 power operation, and return
|
|
968
|
+
// the original JavaScript number values.
|
|
969
|
+
/**
|
|
970
|
+
* @param {string} key
|
|
971
|
+
* @returns {number}
|
|
972
|
+
*/
|
|
973
|
+
decode: function decode(key) {
|
|
974
|
+
var sign = Number(key.slice(2, 3));
|
|
975
|
+
var exponent = key.slice(3, 5);
|
|
976
|
+
var mantissa = key.slice(5, 16);
|
|
977
|
+
switch (signValues[sign]) {
|
|
978
|
+
case 'negativeInfinity':
|
|
979
|
+
return -Infinity;
|
|
980
|
+
case 'positiveInfinity':
|
|
981
|
+
return Infinity;
|
|
982
|
+
case 'bigPositive':
|
|
983
|
+
return pow32(mantissa, exponent);
|
|
984
|
+
case 'smallPositive':
|
|
985
|
+
exponent = negate(flipBase32(exponent));
|
|
986
|
+
return pow32(mantissa, exponent);
|
|
987
|
+
case 'smallNegative':
|
|
988
|
+
exponent = negate(exponent);
|
|
989
|
+
mantissa = flipBase32(mantissa);
|
|
990
|
+
return -pow32(mantissa, exponent);
|
|
991
|
+
case 'bigNegative':
|
|
992
|
+
exponent = flipBase32(exponent);
|
|
993
|
+
mantissa = flipBase32(mantissa);
|
|
994
|
+
return -pow32(mantissa, exponent);
|
|
995
|
+
default:
|
|
996
|
+
throw new Error('Invalid number.');
|
|
904
997
|
}
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
* @returns {ValueTypeArray}
|
|
926
|
-
*/
|
|
927
|
-
decode(key) {
|
|
928
|
-
const decoded = JSON.parse(key.slice(2));
|
|
929
|
-
decoded.pop(); // remove the extra item
|
|
930
|
-
for (let i = 0; i < decoded.length; i++) {
|
|
931
|
-
const item = decoded[i];
|
|
932
|
-
const decodedItem = decode(item, true); // decode the item
|
|
933
|
-
decoded[i] = decodedItem;
|
|
934
|
-
}
|
|
935
|
-
return decoded;
|
|
998
|
+
}
|
|
999
|
+
},
|
|
1000
|
+
// Strings are encoded as JSON strings (with quotes and unicode characters escaped).
|
|
1001
|
+
//
|
|
1002
|
+
// If the strings are in an array, then some extra encoding is done to make sorting work correctly:
|
|
1003
|
+
// Since we can't force all strings to be the same length, we need to ensure that characters line-up properly
|
|
1004
|
+
// for sorting, while also accounting for the extra characters that are added when the array itself is encoded as JSON.
|
|
1005
|
+
// To do this, each character of the string is prepended with a dash ("-"), and a space is added to the end of the string.
|
|
1006
|
+
// This effectively doubles the size of every string, but it ensures that when two arrays of strings are compared,
|
|
1007
|
+
// the indexes of each string's characters line up with each other.
|
|
1008
|
+
string: {
|
|
1009
|
+
/**
|
|
1010
|
+
* @param {string} key
|
|
1011
|
+
* @param {boolean} [inArray]
|
|
1012
|
+
* @returns {string}
|
|
1013
|
+
*/
|
|
1014
|
+
encode: function encode(key, inArray) {
|
|
1015
|
+
if (inArray) {
|
|
1016
|
+
// prepend each character with a dash, and append a space to the end
|
|
1017
|
+
key = key.replaceAll(/((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/g, '-$1') + ' ';
|
|
936
1018
|
}
|
|
1019
|
+
return keyTypeToEncodedChar.string + '-' + key;
|
|
937
1020
|
},
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
1021
|
+
/**
|
|
1022
|
+
* @param {string} key
|
|
1023
|
+
* @param {boolean} [inArray]
|
|
1024
|
+
* @returns {string}
|
|
1025
|
+
*/
|
|
1026
|
+
decode: function decode(key, inArray) {
|
|
1027
|
+
key = key.slice(2);
|
|
1028
|
+
if (inArray) {
|
|
1029
|
+
// remove the space at the end, and the dash before each character
|
|
1030
|
+
key = key.slice(0, -1).replaceAll(/-((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/g, '$1');
|
|
1031
|
+
}
|
|
1032
|
+
return key;
|
|
1033
|
+
}
|
|
1034
|
+
},
|
|
1035
|
+
// Arrays are encoded as JSON strings.
|
|
1036
|
+
// An extra, value is added to each array during encoding to make
|
|
1037
|
+
// empty arrays sort correctly.
|
|
1038
|
+
array: {
|
|
1039
|
+
/**
|
|
1040
|
+
* @param {ValueTypeArray} key
|
|
1041
|
+
* @returns {string}
|
|
1042
|
+
*/
|
|
1043
|
+
encode: function encode(key) {
|
|
1044
|
+
var encoded = [];
|
|
1045
|
+
var _iterator = _createForOfIteratorHelper(key.entries()),
|
|
1046
|
+
_step;
|
|
1047
|
+
try {
|
|
1048
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1049
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
1050
|
+
i = _step$value[0],
|
|
1051
|
+
item = _step$value[1];
|
|
1052
|
+
var encodedItem = _encode(item, true); // encode the array item
|
|
1053
|
+
encoded[i] = encodedItem;
|
|
1054
|
+
}
|
|
1055
|
+
} catch (err) {
|
|
1056
|
+
_iterator.e(err);
|
|
1057
|
+
} finally {
|
|
1058
|
+
_iterator.f();
|
|
953
1059
|
}
|
|
1060
|
+
encoded.push(keyTypeToEncodedChar.invalid + '-'); // append an extra item, so empty arrays sort correctly
|
|
1061
|
+
var encodedKey = JSON.stringify(encoded);
|
|
1062
|
+
if (CFG.escapeNULForSQLiteStatements === false) {
|
|
1063
|
+
encodedKey = encodedKey.replaceAll(String.raw(_templateObject || (_templateObject = _taggedTemplateLiteral(["\0"], ["\\u0000"]))), '\0');
|
|
1064
|
+
}
|
|
1065
|
+
return keyTypeToEncodedChar.array + '-' + encodedKey;
|
|
954
1066
|
},
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
: '');
|
|
964
|
-
},
|
|
965
|
-
/**
|
|
966
|
-
* @param {string} key
|
|
967
|
-
* @returns {ArrayBuffer}
|
|
968
|
-
*/
|
|
969
|
-
decode(key) {
|
|
970
|
-
// Set the entries in buffer's [[ArrayBufferData]] to those in `value`
|
|
971
|
-
const k = key.slice(2);
|
|
972
|
-
const arr = k.length ? k.split(',').map(s => Number.parseInt(s)) : [];
|
|
973
|
-
const buffer = new ArrayBuffer(arr.length);
|
|
974
|
-
const uint8 = new Uint8Array(buffer);
|
|
975
|
-
uint8.set(arr);
|
|
976
|
-
return buffer;
|
|
1067
|
+
/**
|
|
1068
|
+
* @param {string} key
|
|
1069
|
+
* @returns {ValueTypeArray}
|
|
1070
|
+
*/
|
|
1071
|
+
decode: function decode(key) {
|
|
1072
|
+
var decodedKey = key.slice(2);
|
|
1073
|
+
if (CFG.escapeNULForSQLiteStatements === false) {
|
|
1074
|
+
decodedKey = decodedKey.replaceAll('\0', String.raw(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\0"], ["\\u0000"]))));
|
|
977
1075
|
}
|
|
1076
|
+
var decoded = JSON.parse(decodedKey);
|
|
1077
|
+
decoded.pop(); // remove the extra item
|
|
1078
|
+
for (var i = 0; i < decoded.length; i++) {
|
|
1079
|
+
var item = decoded[i];
|
|
1080
|
+
var decodedItem = _decode(item, true); // decode the item
|
|
1081
|
+
decoded[i] = decodedItem;
|
|
1082
|
+
}
|
|
1083
|
+
return decoded;
|
|
978
1084
|
}
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
*/
|
|
996
|
-
function padBase32Mantissa(s) {
|
|
997
|
-
return (s + zeros(11)).slice(0, 11);
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
/**
|
|
1001
|
-
* Flips each digit of a base-32 encoded string.
|
|
1002
|
-
* @param {string} encoded
|
|
1003
|
-
* @returns {string}
|
|
1004
|
-
*/
|
|
1005
|
-
function flipBase32(encoded) {
|
|
1006
|
-
let flipped = '';
|
|
1007
|
-
for (const ch of encoded) {
|
|
1008
|
-
flipped += (31 - Number.parseInt(ch, 32)).toString(32);
|
|
1009
|
-
}
|
|
1010
|
-
return flipped;
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
/**
|
|
1014
|
-
* Base-32 power function.
|
|
1015
|
-
* RESEARCH: This function does not precisely decode floats because it performs
|
|
1016
|
-
* floating point arithmetic to recover values. But can the original values be
|
|
1017
|
-
* recovered exactly?
|
|
1018
|
-
* Someone may have already figured out a good way to store JavaScript floats as
|
|
1019
|
-
* binary strings and convert back. Barring a better method, however, one route
|
|
1020
|
-
* may be to generate decimal strings that `parseFloat` decodes predictably.
|
|
1021
|
-
* @param {string} mantissa
|
|
1022
|
-
* @param {string} exponent
|
|
1023
|
-
* @returns {number}
|
|
1024
|
-
*/
|
|
1025
|
-
function pow32(mantissa, exponent) {
|
|
1026
|
-
const exp = Number.parseInt(exponent, 32);
|
|
1027
|
-
if (exp < 0) {
|
|
1028
|
-
return roundToPrecision(Number.parseInt(mantissa, 32) * 32 ** (exp - 10));
|
|
1085
|
+
},
|
|
1086
|
+
// Dates are encoded as ISO 8601 strings, in UTC time zone.
|
|
1087
|
+
date: {
|
|
1088
|
+
/**
|
|
1089
|
+
* @param {Date} key
|
|
1090
|
+
* @returns {string}
|
|
1091
|
+
*/
|
|
1092
|
+
encode: function encode(key) {
|
|
1093
|
+
return keyTypeToEncodedChar.date + '-' + key.toJSON();
|
|
1094
|
+
},
|
|
1095
|
+
/**
|
|
1096
|
+
* @param {string} key
|
|
1097
|
+
* @returns {Date}
|
|
1098
|
+
*/
|
|
1099
|
+
decode: function decode(key) {
|
|
1100
|
+
return new Date(key.slice(2));
|
|
1029
1101
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1102
|
+
},
|
|
1103
|
+
binary: {
|
|
1104
|
+
// `ArrayBuffer`/Views on buffers (`TypedArray` or `DataView`)
|
|
1105
|
+
/**
|
|
1106
|
+
* @param {BufferSource} key
|
|
1107
|
+
* @returns {string}
|
|
1108
|
+
*/
|
|
1109
|
+
encode: function encode(key) {
|
|
1110
|
+
return keyTypeToEncodedChar.binary + '-' + (key.byteLength ? _toConsumableArray(getCopyBytesHeldByBufferSource(key)).map(function (b) {
|
|
1111
|
+
return String(b).padStart(3, '0');
|
|
1112
|
+
}) // e.g., '255,005,254,000,001,033'
|
|
1113
|
+
: '');
|
|
1114
|
+
},
|
|
1115
|
+
/**
|
|
1116
|
+
* @param {string} key
|
|
1117
|
+
* @returns {ArrayBuffer}
|
|
1118
|
+
*/
|
|
1119
|
+
decode: function decode(key) {
|
|
1120
|
+
// Set the entries in buffer's [[ArrayBufferData]] to those in `value`
|
|
1121
|
+
var k = key.slice(2);
|
|
1122
|
+
var arr = k.length ? k.split(',').map(Number) : [];
|
|
1123
|
+
var buffer = new ArrayBuffer(arr.length);
|
|
1124
|
+
var uint8 = new Uint8Array(buffer);
|
|
1125
|
+
uint8.set(arr);
|
|
1126
|
+
return buffer;
|
|
1036
1127
|
}
|
|
1037
|
-
const expansion = mantissa + zeros(exp - 11);
|
|
1038
|
-
return Number.parseInt(expansion, 32);
|
|
1039
1128
|
}
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1129
|
+
};
|
|
1130
|
+
|
|
1131
|
+
/**
|
|
1132
|
+
* Return a padded base-32 exponent value.
|
|
1133
|
+
* @param {number} n
|
|
1134
|
+
* @returns {string}
|
|
1135
|
+
*/
|
|
1136
|
+
function padBase32Exponent(n) {
|
|
1137
|
+
var exp = n.toString(32);
|
|
1138
|
+
return exp.length === 1 ? '0' + exp : exp;
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
/**
|
|
1142
|
+
* Return a padded base-32 mantissa.
|
|
1143
|
+
* @param {string} s
|
|
1144
|
+
* @returns {string}
|
|
1145
|
+
*/
|
|
1146
|
+
function padBase32Mantissa(s) {
|
|
1147
|
+
return (s + zeros(11)).slice(0, 11);
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* Flips each digit of a base-32 encoded string.
|
|
1152
|
+
* @param {string} encoded
|
|
1153
|
+
* @returns {string}
|
|
1154
|
+
*/
|
|
1155
|
+
function flipBase32(encoded) {
|
|
1156
|
+
var flipped = '';
|
|
1157
|
+
var _iterator2 = _createForOfIteratorHelper(encoded),
|
|
1158
|
+
_step2;
|
|
1159
|
+
try {
|
|
1160
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
1161
|
+
var ch = _step2.value;
|
|
1162
|
+
flipped += (31 - Number.parseInt(ch, 32)).toString(32);
|
|
1163
|
+
}
|
|
1164
|
+
} catch (err) {
|
|
1165
|
+
_iterator2.e(err);
|
|
1166
|
+
} finally {
|
|
1167
|
+
_iterator2.f();
|
|
1052
1168
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1169
|
+
return flipped;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* Base-32 power function.
|
|
1174
|
+
* RESEARCH: This function does not precisely decode floats because it performs
|
|
1175
|
+
* floating point arithmetic to recover values. But can the original values be
|
|
1176
|
+
* recovered exactly?
|
|
1177
|
+
* Someone may have already figured out a good way to store JavaScript floats as
|
|
1178
|
+
* binary strings and convert back. Barring a better method, however, one route
|
|
1179
|
+
* may be to generate decimal strings that `parseFloat` decodes predictably.
|
|
1180
|
+
* @param {string} mantissa
|
|
1181
|
+
* @param {string} exponent
|
|
1182
|
+
* @returns {number}
|
|
1183
|
+
*/
|
|
1184
|
+
function pow32(mantissa, exponent) {
|
|
1185
|
+
var exp = Number.parseInt(exponent, 32);
|
|
1186
|
+
if (exp < 0) {
|
|
1187
|
+
return roundToPrecision(Number.parseInt(mantissa, 32) * Math.pow(32, exp - 10));
|
|
1061
1188
|
}
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
function negate(s) {
|
|
1069
|
-
return '-' + s;
|
|
1189
|
+
if (exp < 11) {
|
|
1190
|
+
var whole = mantissa.slice(0, exp);
|
|
1191
|
+
var wholeNum = Number.parseInt(whole, 32);
|
|
1192
|
+
var fraction = mantissa.slice(exp);
|
|
1193
|
+
var fractionNum = Number.parseInt(fraction, 32) * Math.pow(32, exp - 11);
|
|
1194
|
+
return roundToPrecision(wholeNum + fractionNum);
|
|
1070
1195
|
}
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1196
|
+
var expansion = mantissa + zeros(exp - 11);
|
|
1197
|
+
return Number.parseInt(expansion, 32);
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/**
|
|
1201
|
+
* @typedef {number} Float
|
|
1202
|
+
*/
|
|
1203
|
+
|
|
1204
|
+
/**
|
|
1205
|
+
* @param {Float} num
|
|
1206
|
+
* @param {Float} [precision]
|
|
1207
|
+
* @returns {Float}
|
|
1208
|
+
*/
|
|
1209
|
+
function roundToPrecision(num) {
|
|
1210
|
+
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 16;
|
|
1211
|
+
return Number(num.toPrecision(precision));
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
/**
|
|
1215
|
+
* Returns a string of n zeros.
|
|
1216
|
+
* @param {number} n
|
|
1217
|
+
* @returns {string}
|
|
1218
|
+
*/
|
|
1219
|
+
function zeros(n) {
|
|
1220
|
+
return '0'.repeat(n);
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
/**
|
|
1224
|
+
* Negates numeric strings.
|
|
1225
|
+
* @param {string} s
|
|
1226
|
+
* @returns {string}
|
|
1227
|
+
*/
|
|
1228
|
+
function negate(s) {
|
|
1229
|
+
return '-' + s;
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
/**
|
|
1233
|
+
* @param {Key} key
|
|
1234
|
+
* @returns {KeyType|"invalid"}
|
|
1235
|
+
*/
|
|
1236
|
+
function getKeyType(key) {
|
|
1237
|
+
if (Array.isArray(key)) {
|
|
1238
|
+
return 'array';
|
|
1088
1239
|
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
* Keys must be strings, numbers (besides `NaN`), Dates (if value is not
|
|
1092
|
-
* `NaN`), binary objects or Arrays.
|
|
1093
|
-
* @param {Value} input The key input
|
|
1094
|
-
* @param {Value[]|null|undefined} [seen] An array of already seen keys
|
|
1095
|
-
* @returns {KeyValueObject}
|
|
1096
|
-
*/
|
|
1097
|
-
function convertValueToKey(input, seen) {
|
|
1098
|
-
return convertValueToKeyValueDecoded(input, seen, false, true);
|
|
1240
|
+
if (isDate(key)) {
|
|
1241
|
+
return 'date';
|
|
1099
1242
|
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
* Currently not in use.
|
|
1103
|
-
* @param {Value} input
|
|
1104
|
-
* @returns {KeyValueObject}
|
|
1105
|
-
*/
|
|
1106
|
-
function convertValueToMultiEntryKey(input) {
|
|
1107
|
-
return convertValueToKeyValueDecoded(input, null, true, true);
|
|
1243
|
+
if (isBinary(key)) {
|
|
1244
|
+
return 'binary';
|
|
1108
1245
|
}
|
|
1109
|
-
|
|
1110
|
-
/**
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1246
|
+
var keyType = _typeof(key);
|
|
1247
|
+
return ['string', 'number'].includes(keyType) ? (/** @type {"string"|"number"} */keyType) : 'invalid';
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
/**
|
|
1251
|
+
* Keys must be strings, numbers (besides `NaN`), Dates (if value is not
|
|
1252
|
+
* `NaN`), binary objects or Arrays.
|
|
1253
|
+
* @param {Value} input The key input
|
|
1254
|
+
* @param {Value[]|null|undefined} [seen] An array of already seen keys
|
|
1255
|
+
* @returns {KeyValueObject}
|
|
1256
|
+
*/
|
|
1257
|
+
function convertValueToKey(input, seen) {
|
|
1258
|
+
return convertValueToKeyValueDecoded(input, seen, false, true);
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
/**
|
|
1262
|
+
* Currently not in use.
|
|
1263
|
+
* @param {Value} input
|
|
1264
|
+
* @returns {KeyValueObject}
|
|
1265
|
+
*/
|
|
1266
|
+
function convertValueToMultiEntryKey(input) {
|
|
1267
|
+
return convertValueToKeyValueDecoded(input, null, true, true);
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
*
|
|
1272
|
+
* @param {BufferSource} O
|
|
1273
|
+
* @throws {TypeError}
|
|
1274
|
+
* @see https://heycam.github.io/webidl/#ref-for-dfn-get-buffer-source-copy-2
|
|
1275
|
+
* @returns {Uint8Array}
|
|
1276
|
+
*/
|
|
1277
|
+
function getCopyBytesHeldByBufferSource(O) {
|
|
1278
|
+
var offset = 0;
|
|
1279
|
+
var length;
|
|
1280
|
+
if (ArrayBuffer.isView(O)) {
|
|
1281
|
+
// Has [[ViewedArrayBuffer]] internal slot
|
|
1282
|
+
var arrayBuffer = O.buffer;
|
|
1283
|
+
if (arrayBuffer === undefined) {
|
|
1284
|
+
throw new TypeError('Could not copy the bytes held by a buffer source as the buffer was undefined.');
|
|
1130
1285
|
}
|
|
1131
|
-
//
|
|
1132
|
-
//
|
|
1133
|
-
|
|
1134
|
-
//
|
|
1135
|
-
/** @type {ArrayBuffer} */
|
|
1136
|
-
'buffer' in O && O.buffer || O, offset, length);
|
|
1286
|
+
offset = O.byteOffset; // [[ByteOffset]] (will also throw as desired if detached)
|
|
1287
|
+
length = O.byteLength; // [[ByteLength]] (will also throw as desired if detached)
|
|
1288
|
+
} else {
|
|
1289
|
+
length = O.byteLength; // [[ArrayBufferByteLength]] on ArrayBuffer (will also throw as desired if detached)
|
|
1137
1290
|
}
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
type,
|
|
1163
|
-
|
|
1291
|
+
// const octets = new Uint8Array(input);
|
|
1292
|
+
// const octets = types.binary.decode(types.binary.encode(input));
|
|
1293
|
+
return new Uint8Array(
|
|
1294
|
+
// Should allow DataView
|
|
1295
|
+
/** @type {ArrayBuffer} */
|
|
1296
|
+
'buffer' in O && O.buffer || O, offset, length);
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
/**
|
|
1300
|
+
* Shortcut utility to avoid returning full keys from `convertValueToKey`
|
|
1301
|
+
* and subsequent need to process in calling code unless `fullKeys` is
|
|
1302
|
+
* set; may throw.
|
|
1303
|
+
* @param {Value} input
|
|
1304
|
+
* @param {Value[]|null} [seen]
|
|
1305
|
+
* @param {boolean} [multiEntry]
|
|
1306
|
+
* @param {boolean} [fullKeys]
|
|
1307
|
+
* @throws {TypeError} See `getCopyBytesHeldByBufferSource`
|
|
1308
|
+
* @todo Document other allowable `input`
|
|
1309
|
+
* @returns {KeyValueObject}
|
|
1310
|
+
*/
|
|
1311
|
+
function convertValueToKeyValueDecoded(input, seen, multiEntry, fullKeys) {
|
|
1312
|
+
seen || (seen = []);
|
|
1313
|
+
if (seen.includes(input)) {
|
|
1314
|
+
return {
|
|
1315
|
+
type: 'array',
|
|
1316
|
+
invalid: true,
|
|
1317
|
+
message: 'An array key cannot be circular'
|
|
1164
1318
|
};
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
type,
|
|
1181
|
-
value: 0
|
|
1182
|
-
};
|
|
1183
|
-
}
|
|
1184
|
-
return /** @type {{type: KeyType; value: Value}} */ret;
|
|
1185
|
-
}
|
|
1186
|
-
case 'string':
|
|
1187
|
-
{
|
|
1188
|
-
return /** @type {{type: KeyType; value: Value}} */ret;
|
|
1319
|
+
}
|
|
1320
|
+
var type = getKeyType(input);
|
|
1321
|
+
var ret = {
|
|
1322
|
+
type: type,
|
|
1323
|
+
value: input
|
|
1324
|
+
};
|
|
1325
|
+
switch (type) {
|
|
1326
|
+
case 'number':
|
|
1327
|
+
{
|
|
1328
|
+
if (Number.isNaN(input)) {
|
|
1329
|
+
// List as 'NaN' type for convenience of consumers in reporting errors
|
|
1330
|
+
return {
|
|
1331
|
+
type: 'NaN',
|
|
1332
|
+
invalid: true
|
|
1333
|
+
};
|
|
1189
1334
|
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
// https://heycam.github.io/webidl/#ref-for-dfn-get-buffer-source-copy-2
|
|
1195
|
-
const octets = getCopyBytesHeldByBufferSource(/** @type {BufferSource} */input);
|
|
1335
|
+
|
|
1336
|
+
// https://github.com/w3c/IndexedDB/issues/375
|
|
1337
|
+
// https://github.com/w3c/IndexedDB/pull/386
|
|
1338
|
+
if (Object.is(input, -0)) {
|
|
1196
1339
|
return {
|
|
1197
|
-
type:
|
|
1198
|
-
value:
|
|
1340
|
+
type: type,
|
|
1341
|
+
value: 0
|
|
1199
1342
|
};
|
|
1200
1343
|
}
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1344
|
+
return /** @type {{type: KeyType; value: Value}} */ret;
|
|
1345
|
+
}
|
|
1346
|
+
case 'string':
|
|
1347
|
+
{
|
|
1348
|
+
return /** @type {{type: KeyType; value: Value}} */ret;
|
|
1349
|
+
}
|
|
1350
|
+
case 'binary':
|
|
1351
|
+
{
|
|
1352
|
+
// May throw (if detached)
|
|
1353
|
+
// Get a copy of the bytes held by the buffer source
|
|
1354
|
+
// https://heycam.github.io/webidl/#ref-for-dfn-get-buffer-source-copy-2
|
|
1355
|
+
var octets = getCopyBytesHeldByBufferSource(/** @type {BufferSource} */input);
|
|
1356
|
+
return {
|
|
1357
|
+
type: 'binary',
|
|
1358
|
+
value: octets
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
case 'array':
|
|
1362
|
+
{
|
|
1363
|
+
// May throw (from binary)
|
|
1364
|
+
var arr = /** @type {Array<any>} */input;
|
|
1365
|
+
var len = arr.length;
|
|
1366
|
+
seen.push(input);
|
|
1367
|
+
|
|
1368
|
+
/** @type {(KeyValueObject|Value)[]} */
|
|
1369
|
+
var keys = [];
|
|
1370
|
+
var _loop = function _loop() {
|
|
1211
1371
|
// We cannot iterate here with array extras as we must ensure sparse arrays are invalidated
|
|
1212
1372
|
if (!multiEntry && !Object.hasOwn(arr, i)) {
|
|
1213
1373
|
return {
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1374
|
+
v: {
|
|
1375
|
+
type: type,
|
|
1376
|
+
invalid: true,
|
|
1377
|
+
message: 'Does not have own index property'
|
|
1378
|
+
}
|
|
1217
1379
|
};
|
|
1218
1380
|
}
|
|
1219
1381
|
try {
|
|
1220
|
-
|
|
1221
|
-
|
|
1382
|
+
var entry = arr[i];
|
|
1383
|
+
var key = convertValueToKeyValueDecoded(entry, seen, false, fullKeys); // Though steps do not list rethrowing, the next is returnifabrupt when not multiEntry
|
|
1222
1384
|
if (key.invalid) {
|
|
1223
1385
|
if (multiEntry) {
|
|
1224
|
-
continue
|
|
1386
|
+
return 0; // continue
|
|
1225
1387
|
}
|
|
1226
1388
|
return {
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1389
|
+
v: {
|
|
1390
|
+
type: type,
|
|
1391
|
+
invalid: true,
|
|
1392
|
+
message: 'Bad array entry value-to-key conversion'
|
|
1393
|
+
}
|
|
1230
1394
|
};
|
|
1231
1395
|
}
|
|
1232
|
-
if (!multiEntry || !fullKeys && keys.every(
|
|
1396
|
+
if (!multiEntry || !fullKeys && keys.every(function (k) {
|
|
1397
|
+
return cmp(k, key.value) !== 0;
|
|
1398
|
+
}) || fullKeys && keys.every(function (k) {
|
|
1399
|
+
return cmp(k, key) !== 0;
|
|
1400
|
+
})) {
|
|
1233
1401
|
keys.push(fullKeys ? key : key.value);
|
|
1234
1402
|
}
|
|
1235
1403
|
} catch (err) {
|
|
@@ -1237,299 +1405,317 @@
|
|
|
1237
1405
|
throw err;
|
|
1238
1406
|
}
|
|
1239
1407
|
}
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
case 'date':
|
|
1247
|
-
{
|
|
1248
|
-
const date = /** @type {Date} */input;
|
|
1249
|
-
if (!Number.isNaN(date.getTime())) {
|
|
1250
|
-
return fullKeys ? {
|
|
1251
|
-
type,
|
|
1252
|
-
value: date.getTime()
|
|
1253
|
-
} : {
|
|
1254
|
-
type,
|
|
1255
|
-
value: new Date(date)
|
|
1256
|
-
};
|
|
1257
|
-
}
|
|
1258
|
-
return {
|
|
1259
|
-
type,
|
|
1260
|
-
invalid: true,
|
|
1261
|
-
message: 'Not a valid date'
|
|
1262
|
-
};
|
|
1263
|
-
// Falls through
|
|
1408
|
+
},
|
|
1409
|
+
_ret;
|
|
1410
|
+
for (var i = 0; i < len; i++) {
|
|
1411
|
+
_ret = _loop();
|
|
1412
|
+
if (_ret === 0) continue;
|
|
1413
|
+
if (_ret) return _ret.v;
|
|
1264
1414
|
}
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1415
|
+
return {
|
|
1416
|
+
type: type,
|
|
1417
|
+
value: keys
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
case 'date':
|
|
1421
|
+
{
|
|
1422
|
+
var date = /** @type {Date} */input;
|
|
1423
|
+
if (!Number.isNaN(date.getTime())) {
|
|
1424
|
+
return fullKeys ? {
|
|
1425
|
+
type: type,
|
|
1426
|
+
value: date.getTime()
|
|
1427
|
+
} : {
|
|
1428
|
+
type: type,
|
|
1429
|
+
value: new Date(date)
|
|
1275
1430
|
};
|
|
1276
1431
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
* @returns {KeyValueObject}
|
|
1297
|
-
*/
|
|
1298
|
-
function convertValueToKeyRethrowingAndIfInvalid(input, seen) {
|
|
1299
|
-
const key = convertValueToKey(input, seen);
|
|
1300
|
-
if (key.invalid) {
|
|
1301
|
-
throw createDOMException('DataError', key.message || 'Not a valid key; type: ' + key.type);
|
|
1302
|
-
}
|
|
1303
|
-
return key;
|
|
1432
|
+
return {
|
|
1433
|
+
type: type,
|
|
1434
|
+
invalid: true,
|
|
1435
|
+
message: 'Not a valid date'
|
|
1436
|
+
};
|
|
1437
|
+
// Falls through
|
|
1438
|
+
}
|
|
1439
|
+
case 'invalid':
|
|
1440
|
+
default:
|
|
1441
|
+
{
|
|
1442
|
+
// Other `typeof` types which are not valid keys:
|
|
1443
|
+
// 'undefined', 'boolean', 'object' (including `null`), 'symbol', 'function'
|
|
1444
|
+
var _type = input === null ? 'null' : _typeof(input); // Convert `null` for convenience of consumers in reporting errors
|
|
1445
|
+
return {
|
|
1446
|
+
type: _type,
|
|
1447
|
+
invalid: true,
|
|
1448
|
+
message: 'Not a valid key; type ' + _type
|
|
1449
|
+
};
|
|
1450
|
+
}
|
|
1304
1451
|
}
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
/**
|
|
1455
|
+
*
|
|
1456
|
+
* @param {Key} key
|
|
1457
|
+
* @param {boolean} [fullKeys]
|
|
1458
|
+
* @returns {KeyValueObject}
|
|
1459
|
+
* @todo Document other allowable `key`?
|
|
1460
|
+
*/
|
|
1461
|
+
function convertValueToMultiEntryKeyDecoded(key, fullKeys) {
|
|
1462
|
+
return convertValueToKeyValueDecoded(key, null, true, fullKeys);
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
/**
|
|
1466
|
+
* An internal utility.
|
|
1467
|
+
* @param {Value} input
|
|
1468
|
+
* @param {Value[]|null|undefined} [seen]
|
|
1469
|
+
* @throws {DOMException} `DataError`
|
|
1470
|
+
* @returns {KeyValueObject}
|
|
1471
|
+
*/
|
|
1472
|
+
function convertValueToKeyRethrowingAndIfInvalid(input, seen) {
|
|
1473
|
+
var key = convertValueToKey(input, seen);
|
|
1474
|
+
if (key.invalid) {
|
|
1475
|
+
throw createDOMException('DataError', key.message || 'Not a valid key; type: ' + key.type);
|
|
1316
1476
|
}
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1477
|
+
return key;
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
/**
|
|
1481
|
+
*
|
|
1482
|
+
* @param {Value} value
|
|
1483
|
+
* @param {KeyPath} keyPath
|
|
1484
|
+
* @param {boolean} multiEntry
|
|
1485
|
+
* @returns {KeyValueObject|KeyPathEvaluateValue}
|
|
1486
|
+
* @todo Document other possible return?
|
|
1487
|
+
*/
|
|
1488
|
+
function extractKeyFromValueUsingKeyPath(value, keyPath, multiEntry) {
|
|
1489
|
+
return extractKeyValueDecodedFromValueUsingKeyPath(value, keyPath, multiEntry, true);
|
|
1490
|
+
}
|
|
1491
|
+
/**
|
|
1492
|
+
* Not currently in use.
|
|
1493
|
+
* @param {Value} value
|
|
1494
|
+
* @param {KeyPath} keyPath
|
|
1495
|
+
* @param {boolean} multiEntry
|
|
1496
|
+
* @returns {KeyPathEvaluateValue}
|
|
1497
|
+
*/
|
|
1498
|
+
function evaluateKeyPathOnValue(value, keyPath, multiEntry) {
|
|
1499
|
+
return evaluateKeyPathOnValueToDecodedValue(value, keyPath);
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
/**
|
|
1503
|
+
* May throw, return `{failure: true}` (e.g., non-object on keyPath resolution)
|
|
1504
|
+
* or `{invalid: true}` (e.g., `NaN`).
|
|
1505
|
+
* @param {Value} value
|
|
1506
|
+
* @param {KeyPath} keyPath
|
|
1507
|
+
* @param {boolean} [multiEntry]
|
|
1508
|
+
* @param {boolean} [fullKeys]
|
|
1509
|
+
* @returns {KeyValueObject|KeyPathEvaluateValue}
|
|
1510
|
+
* @todo Document other possible return?
|
|
1511
|
+
*/
|
|
1512
|
+
function extractKeyValueDecodedFromValueUsingKeyPath(value, keyPath, multiEntry, fullKeys) {
|
|
1513
|
+
var r = evaluateKeyPathOnValueToDecodedValue(value, keyPath);
|
|
1514
|
+
if (r.failure) {
|
|
1515
|
+
return r;
|
|
1326
1516
|
}
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
* May throw, return `{failure: true}` (e.g., non-object on keyPath resolution)
|
|
1330
|
-
* or `{invalid: true}` (e.g., `NaN`).
|
|
1331
|
-
* @param {Value} value
|
|
1332
|
-
* @param {KeyPath} keyPath
|
|
1333
|
-
* @param {boolean} [multiEntry]
|
|
1334
|
-
* @param {boolean} [fullKeys]
|
|
1335
|
-
* @returns {KeyValueObject|KeyPathEvaluateValue}
|
|
1336
|
-
* @todo Document other possible return?
|
|
1337
|
-
*/
|
|
1338
|
-
function extractKeyValueDecodedFromValueUsingKeyPath(value, keyPath, multiEntry, fullKeys) {
|
|
1339
|
-
const r = evaluateKeyPathOnValueToDecodedValue(value, keyPath);
|
|
1340
|
-
if (r.failure) {
|
|
1341
|
-
return r;
|
|
1342
|
-
}
|
|
1343
|
-
if (!multiEntry) {
|
|
1344
|
-
return convertValueToKeyValueDecoded(r.value, null, false, fullKeys);
|
|
1345
|
-
}
|
|
1346
|
-
return convertValueToMultiEntryKeyDecoded(r.value, fullKeys);
|
|
1517
|
+
if (!multiEntry) {
|
|
1518
|
+
return convertValueToKeyValueDecoded(r.value, null, false, fullKeys);
|
|
1347
1519
|
}
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
result.push(key.value);
|
|
1388
|
-
return false;
|
|
1389
|
-
}) ? {
|
|
1390
|
-
failure: true
|
|
1391
|
-
} : {
|
|
1392
|
-
value: result
|
|
1393
|
-
};
|
|
1394
|
-
}
|
|
1395
|
-
if (keyPath === '') {
|
|
1396
|
-
return {
|
|
1397
|
-
value
|
|
1398
|
-
};
|
|
1399
|
-
}
|
|
1400
|
-
const identifiers = keyPath.split('.');
|
|
1401
|
-
return identifiers.some(idntfr => {
|
|
1402
|
-
if (idntfr === 'length' && (typeof value === 'string' || Array.isArray(value))) {
|
|
1403
|
-
value = value.length;
|
|
1404
|
-
} else if (isBlob(value)) {
|
|
1405
|
-
switch (idntfr) {
|
|
1406
|
-
case 'size':
|
|
1407
|
-
case 'type':
|
|
1408
|
-
value = /** @type {Blob} */value[idntfr];
|
|
1409
|
-
break;
|
|
1410
|
-
}
|
|
1411
|
-
} else if (isFile(value)) {
|
|
1412
|
-
switch (idntfr) {
|
|
1413
|
-
case 'name':
|
|
1414
|
-
case 'lastModified':
|
|
1415
|
-
value = /** @type {File} */value[idntfr];
|
|
1416
|
-
break;
|
|
1417
|
-
case 'lastModifiedDate':
|
|
1418
|
-
value = new Date(/** @type {File} */value.lastModified);
|
|
1419
|
-
break;
|
|
1420
|
-
}
|
|
1421
|
-
} else if (!isObj(value) || !Object.hasOwn(value, idntfr)) {
|
|
1520
|
+
return convertValueToMultiEntryKeyDecoded(r.value, fullKeys);
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
/**
|
|
1524
|
+
* Unused?
|
|
1525
|
+
* @typedef {object} KeyPathEvaluateFailure
|
|
1526
|
+
* @property {boolean} failure
|
|
1527
|
+
*/
|
|
1528
|
+
|
|
1529
|
+
/**
|
|
1530
|
+
* @typedef {KeyPathEvaluateValueValue[]} KeyPathEvaluateValueValueArray
|
|
1531
|
+
*/
|
|
1532
|
+
|
|
1533
|
+
/**
|
|
1534
|
+
* @typedef {undefined|number|string|Date|object|KeyPathEvaluateValueValueArray} KeyPathEvaluateValueValue
|
|
1535
|
+
*/
|
|
1536
|
+
|
|
1537
|
+
/**
|
|
1538
|
+
* @typedef {object} KeyPathEvaluateValue
|
|
1539
|
+
* @property {KeyPathEvaluateValueValue} [value]
|
|
1540
|
+
* @property {boolean} [failure]
|
|
1541
|
+
*/
|
|
1542
|
+
|
|
1543
|
+
/**
|
|
1544
|
+
* Returns the value of an inline key based on a key path (wrapped in an
|
|
1545
|
+
* object with key `value`) or `{failure: true}`
|
|
1546
|
+
* @param {Value} value
|
|
1547
|
+
* @param {KeyPath} keyPath
|
|
1548
|
+
* @param {boolean} [multiEntry]
|
|
1549
|
+
* @param {boolean} [fullKeys]
|
|
1550
|
+
* @returns {KeyPathEvaluateValue}
|
|
1551
|
+
*/
|
|
1552
|
+
function evaluateKeyPathOnValueToDecodedValue(value, keyPath, multiEntry, fullKeys) {
|
|
1553
|
+
if (Array.isArray(keyPath)) {
|
|
1554
|
+
/** @type {KeyPathEvaluateValueValueArray} */
|
|
1555
|
+
var result = [];
|
|
1556
|
+
return keyPath.some(function (item) {
|
|
1557
|
+
var key = evaluateKeyPathOnValueToDecodedValue(value, item);
|
|
1558
|
+
if (key.failure) {
|
|
1422
1559
|
return true;
|
|
1423
|
-
} else {
|
|
1424
|
-
value = /** @type {{[key: string]: KeyPathEvaluateValueValue}} */value[idntfr];
|
|
1425
|
-
return value === undefined;
|
|
1426
1560
|
}
|
|
1561
|
+
result.push(key.value);
|
|
1427
1562
|
return false;
|
|
1428
1563
|
}) ? {
|
|
1429
1564
|
failure: true
|
|
1430
1565
|
} : {
|
|
1431
|
-
value
|
|
1566
|
+
value: result
|
|
1432
1567
|
};
|
|
1433
1568
|
}
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
* @param {Key} key
|
|
1439
|
-
* @param {string} keyPath
|
|
1440
|
-
* @returns {void}
|
|
1441
|
-
*/
|
|
1442
|
-
function injectKeyIntoValueUsingKeyPath(value, key, keyPath) {
|
|
1443
|
-
const identifiers = keyPath.split('.');
|
|
1444
|
-
const last = identifiers.pop();
|
|
1445
|
-
identifiers.forEach(identifier => {
|
|
1446
|
-
const hop = Object.hasOwn(value, identifier);
|
|
1447
|
-
if (!hop) {
|
|
1448
|
-
value[identifier] = {};
|
|
1449
|
-
}
|
|
1450
|
-
value = value[identifier];
|
|
1451
|
-
});
|
|
1452
|
-
value[(/** @type {string} */last)] = key; // key is already a `keyValue` in our processing so no need to convert
|
|
1569
|
+
if (keyPath === '') {
|
|
1570
|
+
return {
|
|
1571
|
+
value: value
|
|
1572
|
+
};
|
|
1453
1573
|
}
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1574
|
+
var identifiers = keyPath.split('.');
|
|
1575
|
+
return identifiers.some(function (idntfr) {
|
|
1576
|
+
if (idntfr === 'length' && (typeof value === 'string' || Array.isArray(value))) {
|
|
1577
|
+
value = value.length;
|
|
1578
|
+
} else if (isBlob(value)) {
|
|
1579
|
+
switch (idntfr) {
|
|
1580
|
+
case 'size':
|
|
1581
|
+
case 'type':
|
|
1582
|
+
value = /** @type {Blob} */value[idntfr];
|
|
1583
|
+
break;
|
|
1584
|
+
}
|
|
1585
|
+
} else if (isFile(value)) {
|
|
1586
|
+
switch (idntfr) {
|
|
1587
|
+
case 'name':
|
|
1588
|
+
case 'lastModified':
|
|
1589
|
+
value = /** @type {File} */value[idntfr];
|
|
1590
|
+
break;
|
|
1591
|
+
case 'lastModifiedDate':
|
|
1592
|
+
value = new Date(/** @type {File} */value.lastModified);
|
|
1593
|
+
break;
|
|
1594
|
+
}
|
|
1595
|
+
} else if (!isObj(value) || !Object.hasOwn(value, idntfr)) {
|
|
1596
|
+
return true;
|
|
1597
|
+
} else {
|
|
1598
|
+
value = /** @type {{[key: string]: KeyPathEvaluateValueValue}} */value[idntfr];
|
|
1599
|
+
return value === undefined;
|
|
1600
|
+
}
|
|
1601
|
+
return false;
|
|
1602
|
+
}) ? {
|
|
1603
|
+
failure: true
|
|
1604
|
+
} : {
|
|
1605
|
+
value: value
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
/**
|
|
1610
|
+
* Sets the inline key value.
|
|
1611
|
+
* @param {{[key: string]: AnyValue}} value
|
|
1612
|
+
* @param {Key} key
|
|
1613
|
+
* @param {string} keyPath
|
|
1614
|
+
* @returns {void}
|
|
1615
|
+
*/
|
|
1616
|
+
function injectKeyIntoValueUsingKeyPath(value, key, keyPath) {
|
|
1617
|
+
var identifiers = keyPath.split('.');
|
|
1618
|
+
var last = identifiers.pop();
|
|
1619
|
+
identifiers.forEach(function (identifier) {
|
|
1620
|
+
var hop = Object.hasOwn(value, identifier);
|
|
1621
|
+
if (!hop) {
|
|
1622
|
+
value[identifier] = {};
|
|
1623
|
+
}
|
|
1624
|
+
value = value[identifier];
|
|
1625
|
+
});
|
|
1626
|
+
value[(/** @type {string} */last)] = key; // key is already a `keyValue` in our processing so no need to convert
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
/**
|
|
1630
|
+
*
|
|
1631
|
+
* @param {Value} value
|
|
1632
|
+
* @param {string} keyPath
|
|
1633
|
+
* @see https://github.com/w3c/IndexedDB/pull/146
|
|
1634
|
+
* @returns {boolean}
|
|
1635
|
+
*/
|
|
1636
|
+
function checkKeyCouldBeInjectedIntoValue(value, keyPath) {
|
|
1637
|
+
var identifiers = keyPath.split('.');
|
|
1638
|
+
identifiers.pop();
|
|
1639
|
+
var _iterator3 = _createForOfIteratorHelper(identifiers),
|
|
1640
|
+
_step3;
|
|
1641
|
+
try {
|
|
1642
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
1643
|
+
var identifier = _step3.value;
|
|
1466
1644
|
if (!isObj(value)) {
|
|
1467
1645
|
return false;
|
|
1468
1646
|
}
|
|
1469
|
-
|
|
1647
|
+
var hop = Object.hasOwn(value, identifier);
|
|
1470
1648
|
if (!hop) {
|
|
1471
1649
|
return true;
|
|
1472
1650
|
}
|
|
1473
1651
|
value = /** @type {{[key: string]: Value}} */value[identifier];
|
|
1474
1652
|
}
|
|
1475
|
-
|
|
1653
|
+
} catch (err) {
|
|
1654
|
+
_iterator3.e(err);
|
|
1655
|
+
} finally {
|
|
1656
|
+
_iterator3.f();
|
|
1476
1657
|
}
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
upperMatch = true;
|
|
1496
|
-
}
|
|
1497
|
-
return lowerMatch && upperMatch;
|
|
1658
|
+
return isObj(value);
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
/**
|
|
1662
|
+
*
|
|
1663
|
+
* @param {Key} key
|
|
1664
|
+
* @param {import('./IDBKeyRange.js').IDBKeyRangeFull} range
|
|
1665
|
+
* @param {boolean} [checkCached]
|
|
1666
|
+
* @returns {boolean}
|
|
1667
|
+
*/
|
|
1668
|
+
function isKeyInRange(key, range, checkCached) {
|
|
1669
|
+
var lowerMatch = range.lower === undefined;
|
|
1670
|
+
var upperMatch = range.upper === undefined;
|
|
1671
|
+
var encodedKey = _encode(key, true);
|
|
1672
|
+
var lower = checkCached ? range.__lowerCached : _encode(range.lower, true);
|
|
1673
|
+
var upper = checkCached ? range.__upperCached : _encode(range.upper, true);
|
|
1674
|
+
if (!lowerMatch && (range.lowerOpen && encodedKey !== null && lower !== null && encodedKey > lower || !range.lowerOpen && (!encodedKey && !lower || encodedKey !== null && lower !== null && encodedKey >= lower))) {
|
|
1675
|
+
lowerMatch = true;
|
|
1498
1676
|
}
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
* Determines whether an index entry matches a multi-entry key value.
|
|
1502
|
-
* @param {string} encodedEntry The entry value (already encoded)
|
|
1503
|
-
* @param {string} encodedKey The full index key (already encoded)
|
|
1504
|
-
* @returns {boolean}
|
|
1505
|
-
*/
|
|
1506
|
-
function isMultiEntryMatch(encodedEntry, encodedKey) {
|
|
1507
|
-
const keyType = encodedCharToKeyType[encodedKey.slice(0, 1)];
|
|
1508
|
-
if (keyType === 'array') {
|
|
1509
|
-
return encodedKey.indexOf(encodedEntry) > 1;
|
|
1510
|
-
}
|
|
1511
|
-
return encodedKey === encodedEntry;
|
|
1677
|
+
if (!upperMatch && (range.upperOpen && encodedKey !== null && upper !== null && encodedKey < upper || !range.upperOpen && (!encodedKey && !upper || encodedKey !== null && upper !== null && encodedKey <= upper))) {
|
|
1678
|
+
upperMatch = true;
|
|
1512
1679
|
}
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1680
|
+
return lowerMatch && upperMatch;
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
/**
|
|
1684
|
+
* Determines whether an index entry matches a multi-entry key value.
|
|
1685
|
+
* @param {string} encodedEntry The entry value (already encoded)
|
|
1686
|
+
* @param {string} encodedKey The full index key (already encoded)
|
|
1687
|
+
* @returns {boolean}
|
|
1688
|
+
*/
|
|
1689
|
+
function isMultiEntryMatch(encodedEntry, encodedKey) {
|
|
1690
|
+
var keyType = encodedCharToKeyType[encodedKey.slice(0, 1)];
|
|
1691
|
+
if (keyType === 'array') {
|
|
1692
|
+
return encodedKey.indexOf(encodedEntry) > 1;
|
|
1693
|
+
}
|
|
1694
|
+
return encodedKey === encodedEntry;
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
/**
|
|
1698
|
+
*
|
|
1699
|
+
* @param {Key} keyEntry
|
|
1700
|
+
* @param {import('./IDBKeyRange.js').IDBKeyRangeFull|undefined} range
|
|
1701
|
+
* @returns {Key[]}
|
|
1702
|
+
*/
|
|
1703
|
+
function findMultiEntryMatches(keyEntry, range) {
|
|
1704
|
+
var matches = [];
|
|
1705
|
+
if (Array.isArray(keyEntry)) {
|
|
1706
|
+
var _iterator4 = _createForOfIteratorHelper(keyEntry),
|
|
1707
|
+
_step4;
|
|
1708
|
+
try {
|
|
1709
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
1710
|
+
var key = _step4.value;
|
|
1524
1711
|
if (Array.isArray(key)) {
|
|
1525
1712
|
if (range && range.lower === range.upper) {
|
|
1526
1713
|
continue;
|
|
1527
1714
|
}
|
|
1528
1715
|
if (key.length === 1) {
|
|
1529
|
-
// eslint-disable-next-line sonarjs/updated-loop-counter -- Convenient
|
|
1530
1716
|
key = key[0];
|
|
1531
1717
|
} else {
|
|
1532
|
-
|
|
1718
|
+
var nested = findMultiEntryMatches(key, range);
|
|
1533
1719
|
if (nested.length > 0) {
|
|
1534
1720
|
matches.push(key);
|
|
1535
1721
|
}
|
|
@@ -1540,270 +1726,278 @@
|
|
|
1540
1726
|
matches.push(key);
|
|
1541
1727
|
}
|
|
1542
1728
|
}
|
|
1543
|
-
}
|
|
1544
|
-
|
|
1729
|
+
} catch (err) {
|
|
1730
|
+
_iterator4.e(err);
|
|
1731
|
+
} finally {
|
|
1732
|
+
_iterator4.f();
|
|
1545
1733
|
}
|
|
1546
|
-
|
|
1734
|
+
} else if (isNullish(range) || isKeyInRange(keyEntry, range, true)) {
|
|
1735
|
+
matches.push(keyEntry);
|
|
1547
1736
|
}
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
}
|
|
1576
|
-
return array;
|
|
1577
|
-
}
|
|
1578
|
-
case 'date':
|
|
1579
|
-
{
|
|
1580
|
-
return new Date(value);
|
|
1581
|
-
}
|
|
1582
|
-
case 'binary':
|
|
1583
|
-
{
|
|
1584
|
-
const len = value.length;
|
|
1585
|
-
const buffer = new ArrayBuffer(len);
|
|
1586
|
-
// Set the entries in buffer's [[ArrayBufferData]] to those in `value`
|
|
1587
|
-
const uint8 = new Uint8Array(buffer, value.byteOffset || 0, value.byteLength);
|
|
1588
|
-
uint8.set(value);
|
|
1589
|
-
return buffer;
|
|
1737
|
+
return matches;
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
/**
|
|
1741
|
+
* Not currently in use but keeping for spec parity.
|
|
1742
|
+
* @param {Key} key
|
|
1743
|
+
* @throws {Error} Upon a "bad key"
|
|
1744
|
+
* @returns {ValueType}
|
|
1745
|
+
*/
|
|
1746
|
+
function convertKeyToValue(key) {
|
|
1747
|
+
var type = key.type,
|
|
1748
|
+
value = key.value;
|
|
1749
|
+
switch (type) {
|
|
1750
|
+
case 'number':
|
|
1751
|
+
case 'string':
|
|
1752
|
+
{
|
|
1753
|
+
return value;
|
|
1754
|
+
}
|
|
1755
|
+
case 'array':
|
|
1756
|
+
{
|
|
1757
|
+
var array = [];
|
|
1758
|
+
var len = value.length;
|
|
1759
|
+
var index = 0;
|
|
1760
|
+
while (index < len) {
|
|
1761
|
+
var entry = convertKeyToValue(value[index]);
|
|
1762
|
+
array[index] = entry;
|
|
1763
|
+
index++;
|
|
1590
1764
|
}
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
return types[getKeyType(key)].encode(key, inArray);
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
/**
|
|
1613
|
-
*
|
|
1614
|
-
* @param {Key} key
|
|
1615
|
-
* @param {boolean} [inArray]
|
|
1616
|
-
* @throws {Error} Invalid number
|
|
1617
|
-
* @returns {undefined|ValueType}
|
|
1618
|
-
*/
|
|
1619
|
-
function decode(key, inArray) {
|
|
1620
|
-
if (typeof key !== 'string') {
|
|
1621
|
-
return undefined;
|
|
1622
|
-
}
|
|
1623
|
-
return types[encodedCharToKeyType[key.slice(0, 1)]].decode(key, inArray);
|
|
1765
|
+
return array;
|
|
1766
|
+
}
|
|
1767
|
+
case 'date':
|
|
1768
|
+
{
|
|
1769
|
+
return new Date(value);
|
|
1770
|
+
}
|
|
1771
|
+
case 'binary':
|
|
1772
|
+
{
|
|
1773
|
+
var _len = value.length;
|
|
1774
|
+
var buffer = new ArrayBuffer(_len);
|
|
1775
|
+
// Set the entries in buffer's [[ArrayBufferData]] to those in `value`
|
|
1776
|
+
var uint8 = new Uint8Array(buffer, value.byteOffset || 0, value.byteLength);
|
|
1777
|
+
uint8.set(value);
|
|
1778
|
+
return buffer;
|
|
1779
|
+
}
|
|
1780
|
+
case 'invalid':
|
|
1781
|
+
default:
|
|
1782
|
+
throw new Error('Bad key');
|
|
1624
1783
|
}
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
/**
|
|
1787
|
+
*
|
|
1788
|
+
* @param {Key} key
|
|
1789
|
+
* @param {boolean} [inArray]
|
|
1790
|
+
* @returns {string|null}
|
|
1791
|
+
*/
|
|
1792
|
+
function _encode(key, inArray) {
|
|
1793
|
+
// Bad keys like `null`, `object`, `boolean`, 'function', 'symbol' should not be passed here due to prior validation
|
|
1794
|
+
if (key === undefined) {
|
|
1795
|
+
return null;
|
|
1634
1796
|
}
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
* @param {DOMException|Error} exception
|
|
1650
|
-
* @returns {void}
|
|
1651
|
-
*/
|
|
1652
|
-
|
|
1653
|
-
/**
|
|
1654
|
-
*
|
|
1655
|
-
* @param {SQLTransaction} tx
|
|
1656
|
-
* @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
|
|
1657
|
-
* @param {CurrentNumberCallback} func
|
|
1658
|
-
* @param {SQLFailureCallback} sqlFailCb
|
|
1659
|
-
* @returns {void}
|
|
1660
|
-
*/
|
|
1661
|
-
function getCurrentNumber(tx, store, func, sqlFailCb) {
|
|
1662
|
-
tx.executeSql('SELECT "currNum" FROM __sys__ WHERE "name" = ?', [escapeSQLiteStatement(store.__currentName)], function (tx, data) {
|
|
1663
|
-
if (data.rows.length !== 1) {
|
|
1664
|
-
func(1);
|
|
1665
|
-
} else {
|
|
1666
|
-
func(data.rows.item(0).currNum);
|
|
1667
|
-
}
|
|
1668
|
-
}, function (tx, error) {
|
|
1669
|
-
sqlFailCb(createDOMException('DataError', 'Could not get the auto increment value for key', error));
|
|
1670
|
-
return false;
|
|
1671
|
-
});
|
|
1797
|
+
// array, date, number, string, binary (should already have detected "invalid")
|
|
1798
|
+
return types[getKeyType(key)].encode(key, inArray);
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
/**
|
|
1802
|
+
*
|
|
1803
|
+
* @param {Key} key
|
|
1804
|
+
* @param {boolean} [inArray]
|
|
1805
|
+
* @throws {Error} Invalid number
|
|
1806
|
+
* @returns {undefined|ValueType}
|
|
1807
|
+
*/
|
|
1808
|
+
function _decode(key, inArray) {
|
|
1809
|
+
if (typeof key !== 'string') {
|
|
1810
|
+
return undefined;
|
|
1672
1811
|
}
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1812
|
+
return types[encodedCharToKeyType[key.slice(0, 1)]].decode(key, inArray);
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
/**
|
|
1816
|
+
*
|
|
1817
|
+
* @param {Key} key
|
|
1818
|
+
* @param {boolean} [inArray]
|
|
1819
|
+
* @returns {undefined|ValueType}
|
|
1820
|
+
*/
|
|
1821
|
+
function roundTrip(key, inArray) {
|
|
1822
|
+
return _decode(_encode(key, inArray), inArray);
|
|
1823
|
+
}
|
|
1824
|
+
var MAX_ALLOWED_CURRENT_NUMBER = 9007199254740992; // 2 ^ 53 (Also equal to `Number.MAX_SAFE_INTEGER + 1`)
|
|
1825
|
+
|
|
1826
|
+
/**
|
|
1827
|
+
* @typedef {number} Integer
|
|
1828
|
+
*/
|
|
1829
|
+
|
|
1830
|
+
/**
|
|
1831
|
+
* @callback CurrentNumberCallback
|
|
1832
|
+
* @param {Integer} cn The current number
|
|
1833
|
+
* @returns {void}
|
|
1834
|
+
*/
|
|
1835
|
+
|
|
1836
|
+
/**
|
|
1837
|
+
* @callback SQLFailureCallback
|
|
1838
|
+
* @param {DOMException|Error} exception
|
|
1839
|
+
* @returns {void}
|
|
1840
|
+
*/
|
|
1841
|
+
|
|
1842
|
+
/**
|
|
1843
|
+
*
|
|
1844
|
+
* @param {SQLTransaction} tx
|
|
1845
|
+
* @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
|
|
1846
|
+
* @param {CurrentNumberCallback} func
|
|
1847
|
+
* @param {SQLFailureCallback} sqlFailCb
|
|
1848
|
+
* @returns {void}
|
|
1849
|
+
*/
|
|
1850
|
+
function getCurrentNumber(tx, store, func, sqlFailCb) {
|
|
1851
|
+
tx.executeSql('SELECT "currNum" FROM __sys__ WHERE "name" = ?', [escapeSQLiteStatement(store.__currentName)], function (tx, data) {
|
|
1852
|
+
if (data.rows.length !== 1) {
|
|
1853
|
+
func(1);
|
|
1854
|
+
} else {
|
|
1855
|
+
func(data.rows.item(0).currNum);
|
|
1688
1856
|
}
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
num = num === MAX_ALLOWED_CURRENT_NUMBER ? num + 2 // Since incrementing by one will have no effect in JavaScript on this unsafe max, we represent the max as a number incremented by two. The getting of the current number is never returned to the user and is only used in safe comparisons, so it is safe for us to represent it in this manner
|
|
1710
|
-
: num + 1;
|
|
1711
|
-
return assignCurrentNumber(tx, store, num, successCb, failCb);
|
|
1857
|
+
}, function (tx, error) {
|
|
1858
|
+
sqlFailCb(createDOMException('DataError', 'Could not get the auto increment value for key', error));
|
|
1859
|
+
return false;
|
|
1860
|
+
});
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
/**
|
|
1864
|
+
*
|
|
1865
|
+
* @param {SQLTransaction} tx
|
|
1866
|
+
* @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
|
|
1867
|
+
* @param {Integer} num
|
|
1868
|
+
* @param {CurrentNumberCallback} successCb
|
|
1869
|
+
* @param {SQLFailureCallback} failCb
|
|
1870
|
+
* @returns {void}
|
|
1871
|
+
*/
|
|
1872
|
+
function assignCurrentNumber(tx, store, num, successCb, failCb) {
|
|
1873
|
+
var sql = 'UPDATE __sys__ SET "currNum" = ? WHERE "name" = ?';
|
|
1874
|
+
var sqlValues = [num, escapeSQLiteStatement(store.__currentName)];
|
|
1875
|
+
if (CFG.DEBUG) {
|
|
1876
|
+
console.log(sql, sqlValues);
|
|
1712
1877
|
}
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1878
|
+
tx.executeSql(sql, sqlValues, function () {
|
|
1879
|
+
successCb(num);
|
|
1880
|
+
}, function (tx, err) {
|
|
1881
|
+
failCb(createDOMException('UnknownError', 'Could not set the auto increment value for key', err));
|
|
1882
|
+
return false;
|
|
1883
|
+
});
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
/**
|
|
1887
|
+
* Bump up the auto-inc counter if the key path-resolved value is valid
|
|
1888
|
+
* (greater than old value and >=1) OR if a manually passed in key is
|
|
1889
|
+
* valid (numeric and >= 1) and >= any primaryKey.
|
|
1890
|
+
* @param {SQLTransaction} tx
|
|
1891
|
+
* @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
|
|
1892
|
+
* @param {Integer} num
|
|
1893
|
+
* @param {CurrentNumberCallback} successCb
|
|
1894
|
+
* @param {SQLFailureCallback} failCb
|
|
1895
|
+
* @returns {void}
|
|
1896
|
+
*/
|
|
1897
|
+
function setCurrentNumber(tx, store, num, successCb, failCb) {
|
|
1898
|
+
num = 1 + (num === MAX_ALLOWED_CURRENT_NUMBER
|
|
1899
|
+
// Since incrementing by one will have no effect in JavaScript on this
|
|
1900
|
+
// unsafe max, we represent the max as a number incremented by two.
|
|
1901
|
+
// The getting of the current number is never returned to the user and
|
|
1902
|
+
// is only used in safe comparisons, so it is safe for us to represent
|
|
1903
|
+
// it in this manner
|
|
1904
|
+
? num + 1 : num);
|
|
1905
|
+
return assignCurrentNumber(tx, store, num, successCb, failCb);
|
|
1906
|
+
}
|
|
1907
|
+
|
|
1908
|
+
/**
|
|
1909
|
+
* @callback KeyForStoreCallback
|
|
1910
|
+
* @param {"failure"|null} arg1
|
|
1911
|
+
* @param {Integer} [arg2]
|
|
1912
|
+
* @param {Integer} [arg3]
|
|
1913
|
+
* @returns {void}
|
|
1914
|
+
*/
|
|
1915
|
+
|
|
1916
|
+
/**
|
|
1917
|
+
*
|
|
1918
|
+
* @param {SQLTransaction} tx
|
|
1919
|
+
* @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
|
|
1920
|
+
* @param {KeyForStoreCallback} cb
|
|
1921
|
+
* @param {SQLFailureCallback} sqlFailCb
|
|
1922
|
+
* @returns {void}
|
|
1923
|
+
*/
|
|
1924
|
+
function generateKeyForStore(tx, store, cb, sqlFailCb) {
|
|
1925
|
+
getCurrentNumber(tx, store, function (key) {
|
|
1926
|
+
if (key > MAX_ALLOWED_CURRENT_NUMBER) {
|
|
1927
|
+
// 2 ^ 53 (See <https://github.com/w3c/IndexedDB/issues/147>)
|
|
1928
|
+
cb('failure');
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1931
|
+
// Increment current number by 1 (we cannot leverage SQLite's
|
|
1932
|
+
// autoincrement (and decrement when not needed), as decrementing
|
|
1933
|
+
// will be overwritten/ignored upon the next insert)
|
|
1934
|
+
setCurrentNumber(tx, store, key, function () {
|
|
1935
|
+
cb(null, key, key);
|
|
1936
|
+
}, sqlFailCb);
|
|
1937
|
+
}, sqlFailCb);
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
// Fractional or numbers exceeding the max do not get changed in the result
|
|
1941
|
+
// per https://github.com/w3c/IndexedDB/issues/147
|
|
1942
|
+
// so we do not return a key
|
|
1943
|
+
/**
|
|
1944
|
+
*
|
|
1945
|
+
* @param {SQLTransaction} tx
|
|
1946
|
+
* @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
|
|
1947
|
+
* @param {Key} key
|
|
1948
|
+
* @param {(num?: Integer) => void} successCb
|
|
1949
|
+
* @param {SQLFailureCallback} sqlFailCb
|
|
1950
|
+
* @returns {void}
|
|
1951
|
+
*/
|
|
1952
|
+
function possiblyUpdateKeyGenerator(tx, store, key, successCb, sqlFailCb) {
|
|
1953
|
+
// Per https://github.com/w3c/IndexedDB/issues/147 , non-finite numbers
|
|
1954
|
+
// (or numbers larger than the max) are now to have the explicit effect of
|
|
1955
|
+
// setting the current number (up to the max), so we do not optimize them
|
|
1956
|
+
// out here
|
|
1957
|
+
if (typeof key !== 'number' || key < 1) {
|
|
1958
|
+
// Optimize with no need to get the current number
|
|
1959
|
+
// Auto-increment attempted with a bad key;
|
|
1960
|
+
// we are not to change the current number, but the steps don't call for failure
|
|
1961
|
+
// Numbers < 1 are optimized out as they will never be greater than the current number which must be at least 1
|
|
1962
|
+
successCb();
|
|
1963
|
+
} else {
|
|
1964
|
+
// If auto-increment and the keyPath item is a valid numeric key, get the old auto-increment to compare if the new is higher
|
|
1965
|
+
// to determine which to use and whether to update the current number
|
|
1966
|
+
getCurrentNumber(tx, store, function (cn) {
|
|
1967
|
+
var value = Math.floor(Math.min(key, MAX_ALLOWED_CURRENT_NUMBER));
|
|
1968
|
+
var useNewKeyForAutoInc = value >= cn;
|
|
1969
|
+
if (useNewKeyForAutoInc) {
|
|
1970
|
+
setCurrentNumber(tx, store, value, function () {
|
|
1971
|
+
successCb(cn); // Supply old current number in case needs to be reverted
|
|
1972
|
+
}, sqlFailCb);
|
|
1973
|
+
} else {
|
|
1974
|
+
// Not updated
|
|
1975
|
+
successCb();
|
|
1736
1976
|
}
|
|
1737
|
-
// Increment current number by 1 (we cannot leverage SQLite's
|
|
1738
|
-
// autoincrement (and decrement when not needed), as decrementing
|
|
1739
|
-
// will be overwritten/ignored upon the next insert)
|
|
1740
|
-
setCurrentNumber(tx, store, key, function () {
|
|
1741
|
-
cb(null, key, key);
|
|
1742
|
-
}, sqlFailCb);
|
|
1743
1977
|
}, sqlFailCb);
|
|
1744
1978
|
}
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
// Numbers < 1 are optimized out as they will never be greater than the current number which must be at least 1
|
|
1768
|
-
successCb();
|
|
1769
|
-
} else {
|
|
1770
|
-
// If auto-increment and the keyPath item is a valid numeric key, get the old auto-increment to compare if the new is higher
|
|
1771
|
-
// to determine which to use and whether to update the current number
|
|
1772
|
-
getCurrentNumber(tx, store, function (cn) {
|
|
1773
|
-
const value = Math.floor(Math.min(key, MAX_ALLOWED_CURRENT_NUMBER));
|
|
1774
|
-
const useNewKeyForAutoInc = value >= cn;
|
|
1775
|
-
if (useNewKeyForAutoInc) {
|
|
1776
|
-
setCurrentNumber(tx, store, value, function () {
|
|
1777
|
-
successCb(cn); // Supply old current number in case needs to be reverted
|
|
1778
|
-
}, sqlFailCb);
|
|
1779
|
-
} else {
|
|
1780
|
-
// Not updated
|
|
1781
|
-
successCb();
|
|
1782
|
-
}
|
|
1783
|
-
}, sqlFailCb);
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
|
|
1787
|
-
exports.assignCurrentNumber = assignCurrentNumber;
|
|
1788
|
-
exports.checkKeyCouldBeInjectedIntoValue = checkKeyCouldBeInjectedIntoValue;
|
|
1789
|
-
exports.convertKeyToValue = convertKeyToValue;
|
|
1790
|
-
exports.convertValueToKey = convertValueToKey;
|
|
1791
|
-
exports.convertValueToKeyRethrowingAndIfInvalid = convertValueToKeyRethrowingAndIfInvalid;
|
|
1792
|
-
exports.convertValueToKeyValueDecoded = convertValueToKeyValueDecoded;
|
|
1793
|
-
exports.convertValueToMultiEntryKey = convertValueToMultiEntryKey;
|
|
1794
|
-
exports.convertValueToMultiEntryKeyDecoded = convertValueToMultiEntryKeyDecoded;
|
|
1795
|
-
exports.decode = decode;
|
|
1796
|
-
exports.encode = encode;
|
|
1797
|
-
exports.evaluateKeyPathOnValue = evaluateKeyPathOnValue;
|
|
1798
|
-
exports.extractKeyFromValueUsingKeyPath = extractKeyFromValueUsingKeyPath;
|
|
1799
|
-
exports.extractKeyValueDecodedFromValueUsingKeyPath = extractKeyValueDecodedFromValueUsingKeyPath;
|
|
1800
|
-
exports.findMultiEntryMatches = findMultiEntryMatches;
|
|
1801
|
-
exports.generateKeyForStore = generateKeyForStore;
|
|
1802
|
-
exports.injectKeyIntoValueUsingKeyPath = injectKeyIntoValueUsingKeyPath;
|
|
1803
|
-
exports.isKeyInRange = isKeyInRange;
|
|
1804
|
-
exports.isMultiEntryMatch = isMultiEntryMatch;
|
|
1805
|
-
exports.possiblyUpdateKeyGenerator = possiblyUpdateKeyGenerator;
|
|
1806
|
-
exports.roundTrip = roundTrip;
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
exports.assignCurrentNumber = assignCurrentNumber;
|
|
1982
|
+
exports.checkKeyCouldBeInjectedIntoValue = checkKeyCouldBeInjectedIntoValue;
|
|
1983
|
+
exports.convertKeyToValue = convertKeyToValue;
|
|
1984
|
+
exports.convertValueToKey = convertValueToKey;
|
|
1985
|
+
exports.convertValueToKeyRethrowingAndIfInvalid = convertValueToKeyRethrowingAndIfInvalid;
|
|
1986
|
+
exports.convertValueToKeyValueDecoded = convertValueToKeyValueDecoded;
|
|
1987
|
+
exports.convertValueToMultiEntryKey = convertValueToMultiEntryKey;
|
|
1988
|
+
exports.convertValueToMultiEntryKeyDecoded = convertValueToMultiEntryKeyDecoded;
|
|
1989
|
+
exports.decode = _decode;
|
|
1990
|
+
exports.encode = _encode;
|
|
1991
|
+
exports.evaluateKeyPathOnValue = evaluateKeyPathOnValue;
|
|
1992
|
+
exports.extractKeyFromValueUsingKeyPath = extractKeyFromValueUsingKeyPath;
|
|
1993
|
+
exports.extractKeyValueDecodedFromValueUsingKeyPath = extractKeyValueDecodedFromValueUsingKeyPath;
|
|
1994
|
+
exports.findMultiEntryMatches = findMultiEntryMatches;
|
|
1995
|
+
exports.generateKeyForStore = generateKeyForStore;
|
|
1996
|
+
exports.injectKeyIntoValueUsingKeyPath = injectKeyIntoValueUsingKeyPath;
|
|
1997
|
+
exports.isKeyInRange = isKeyInRange;
|
|
1998
|
+
exports.isMultiEntryMatch = isMultiEntryMatch;
|
|
1999
|
+
exports.possiblyUpdateKeyGenerator = possiblyUpdateKeyGenerator;
|
|
2000
|
+
exports.roundTrip = roundTrip;
|
|
1807
2001
|
|
|
1808
2002
|
}));
|
|
1809
2003
|
//# sourceMappingURL=indexeddbshim-Key.js.map
|