dexie 4.4.0 → 4.4.2
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 +39 -5
- package/dist/README.md +46 -0
- package/dist/dexie.d.ts +4 -4
- package/dist/dexie.js +1404 -929
- package/dist/dexie.js.map +1 -1
- package/dist/dexie.min.js +1 -1
- package/dist/dexie.min.js.map +1 -1
- package/dist/dexie.mjs +1404 -929
- package/dist/dexie.mjs.map +1 -1
- package/dist/modern/dexie.min.mjs +1 -1
- package/dist/modern/dexie.min.mjs.map +1 -1
- package/dist/modern/dexie.mjs +1249 -858
- package/dist/modern/dexie.mjs.map +1 -1
- package/package.json +6 -3
- package/testmuai-logo-white.svg +33 -0
- package/testmuai-logo.svg +33 -0
package/dist/modern/dexie.mjs
CHANGED
|
@@ -4,17 +4,20 @@
|
|
|
4
4
|
*
|
|
5
5
|
* By David Fahlander, david.fahlander@gmail.com
|
|
6
6
|
*
|
|
7
|
-
* Version 4.4.
|
|
7
|
+
* Version 4.4.2, Tue Mar 31 2026
|
|
8
8
|
*
|
|
9
9
|
* https://dexie.org
|
|
10
10
|
*
|
|
11
11
|
* Apache License Version 2.0, January 2004, http://www.apache.org/licenses/
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
const _global = typeof globalThis !== 'undefined'
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const _global = typeof globalThis !== 'undefined'
|
|
15
|
+
? globalThis
|
|
16
|
+
: typeof self !== 'undefined'
|
|
17
|
+
? self
|
|
18
|
+
: typeof window !== 'undefined'
|
|
19
|
+
? window
|
|
20
|
+
: global;
|
|
18
21
|
|
|
19
22
|
const keys = Object.keys;
|
|
20
23
|
const isArray = Array.isArray;
|
|
@@ -37,32 +40,38 @@ function hasOwn(obj, prop) {
|
|
|
37
40
|
function props(proto, extension) {
|
|
38
41
|
if (typeof extension === 'function')
|
|
39
42
|
extension = extension(getProto(proto));
|
|
40
|
-
(typeof Reflect ===
|
|
43
|
+
(typeof Reflect === 'undefined' ? keys : Reflect.ownKeys)(extension).forEach((key) => {
|
|
41
44
|
setProp(proto, key, extension[key]);
|
|
42
45
|
});
|
|
43
46
|
}
|
|
44
47
|
const defineProperty = Object.defineProperty;
|
|
45
48
|
function setProp(obj, prop, functionOrGetSet, options) {
|
|
46
|
-
defineProperty(obj, prop, extend(functionOrGetSet &&
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
defineProperty(obj, prop, extend(functionOrGetSet &&
|
|
50
|
+
hasOwn(functionOrGetSet, 'get') &&
|
|
51
|
+
typeof functionOrGetSet.get === 'function'
|
|
52
|
+
? {
|
|
53
|
+
get: functionOrGetSet.get,
|
|
54
|
+
set: functionOrGetSet.set,
|
|
55
|
+
configurable: true,
|
|
56
|
+
}
|
|
57
|
+
: { value: functionOrGetSet, configurable: true, writable: true }, options));
|
|
49
58
|
}
|
|
50
59
|
function derive(Child) {
|
|
51
60
|
return {
|
|
52
61
|
from: function (Parent) {
|
|
53
62
|
Child.prototype = Object.create(Parent.prototype);
|
|
54
|
-
setProp(Child.prototype,
|
|
63
|
+
setProp(Child.prototype, 'constructor', Child);
|
|
55
64
|
return {
|
|
56
|
-
extend: props.bind(null, Child.prototype)
|
|
65
|
+
extend: props.bind(null, Child.prototype),
|
|
57
66
|
};
|
|
58
|
-
}
|
|
67
|
+
},
|
|
59
68
|
};
|
|
60
69
|
}
|
|
61
70
|
const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
62
71
|
function getPropertyDescriptor(obj, prop) {
|
|
63
72
|
const pd = getOwnPropertyDescriptor(obj, prop);
|
|
64
73
|
let proto;
|
|
65
|
-
return pd || (proto = getProto(obj)) && getPropertyDescriptor(proto, prop);
|
|
74
|
+
return pd || ((proto = getProto(obj)) && getPropertyDescriptor(proto, prop));
|
|
66
75
|
}
|
|
67
76
|
const _slice = [].slice;
|
|
68
77
|
function slice(args, start, end) {
|
|
@@ -73,7 +82,7 @@ function override(origFunc, overridedFactory) {
|
|
|
73
82
|
}
|
|
74
83
|
function assert(b) {
|
|
75
84
|
if (!b)
|
|
76
|
-
throw new Error(
|
|
85
|
+
throw new Error('Assertion Failed');
|
|
77
86
|
}
|
|
78
87
|
function asap$1(fn) {
|
|
79
88
|
if (_global.setImmediate)
|
|
@@ -105,7 +114,9 @@ function getByKeyPath(obj, keyPath) {
|
|
|
105
114
|
var period = keyPath.indexOf('.');
|
|
106
115
|
if (period !== -1) {
|
|
107
116
|
var innerObj = obj[keyPath.substr(0, period)];
|
|
108
|
-
return innerObj == null
|
|
117
|
+
return innerObj == null
|
|
118
|
+
? undefined
|
|
119
|
+
: getByKeyPath(innerObj, keyPath.substr(period + 1));
|
|
109
120
|
}
|
|
110
121
|
return undefined;
|
|
111
122
|
}
|
|
@@ -125,7 +136,7 @@ function setByKeyPath(obj, keyPath, value) {
|
|
|
125
136
|
if (period !== -1) {
|
|
126
137
|
var currentKeyPath = keyPath.substr(0, period);
|
|
127
138
|
var remainingKeyPath = keyPath.substr(period + 1);
|
|
128
|
-
if (remainingKeyPath ===
|
|
139
|
+
if (remainingKeyPath === '')
|
|
129
140
|
if (value === undefined) {
|
|
130
141
|
if (isArray(obj) && !isNaN(parseInt(currentKeyPath)))
|
|
131
142
|
obj.splice(currentKeyPath, 1);
|
|
@@ -137,7 +148,7 @@ function setByKeyPath(obj, keyPath, value) {
|
|
|
137
148
|
else {
|
|
138
149
|
var innerObj = obj[currentKeyPath];
|
|
139
150
|
if (!innerObj || !hasOwn(obj, currentKeyPath))
|
|
140
|
-
innerObj =
|
|
151
|
+
innerObj = obj[currentKeyPath] = {};
|
|
141
152
|
setByKeyPath(innerObj, remainingKeyPath, value);
|
|
142
153
|
}
|
|
143
154
|
}
|
|
@@ -173,24 +184,23 @@ const concat = [].concat;
|
|
|
173
184
|
function flatten(a) {
|
|
174
185
|
return concat.apply([], a);
|
|
175
186
|
}
|
|
176
|
-
const intrinsicTypeNames =
|
|
177
|
-
.split(',')
|
|
178
|
-
|
|
187
|
+
const intrinsicTypeNames = 'BigUint64Array,BigInt64Array,Array,Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,FileSystemDirectoryHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey'
|
|
188
|
+
.split(',')
|
|
189
|
+
.concat(flatten([8, 16, 32, 64].map((num) => ['Int', 'Uint', 'Float'].map((t) => t + num + 'Array'))))
|
|
190
|
+
.filter((t) => _global[t]);
|
|
191
|
+
const intrinsicTypes = new Set(intrinsicTypeNames.map((t) => _global[t]));
|
|
179
192
|
function cloneSimpleObjectTree(o) {
|
|
180
193
|
const rv = {};
|
|
181
194
|
for (const k in o)
|
|
182
195
|
if (hasOwn(o, k)) {
|
|
183
196
|
const v = o[k];
|
|
184
|
-
rv[k] =
|
|
197
|
+
rv[k] =
|
|
198
|
+
!v || typeof v !== 'object' || intrinsicTypes.has(v.constructor)
|
|
199
|
+
? v
|
|
200
|
+
: cloneSimpleObjectTree(v);
|
|
185
201
|
}
|
|
186
202
|
return rv;
|
|
187
203
|
}
|
|
188
|
-
function objectIsEmpty(o) {
|
|
189
|
-
for (const k in o)
|
|
190
|
-
if (hasOwn(o, k))
|
|
191
|
-
return false;
|
|
192
|
-
return true;
|
|
193
|
-
}
|
|
194
204
|
let circularRefs = null;
|
|
195
205
|
function deepClone(any) {
|
|
196
206
|
circularRefs = new WeakMap();
|
|
@@ -230,13 +240,15 @@ const { toString } = {};
|
|
|
230
240
|
function toStringTag(o) {
|
|
231
241
|
return toString.call(o).slice(8, -1);
|
|
232
242
|
}
|
|
233
|
-
const iteratorSymbol = typeof Symbol !== 'undefined' ?
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
243
|
+
const iteratorSymbol = typeof Symbol !== 'undefined' ? Symbol.iterator : '@@iterator';
|
|
244
|
+
const getIteratorOf = typeof iteratorSymbol === 'symbol'
|
|
245
|
+
? function (x) {
|
|
246
|
+
var i;
|
|
247
|
+
return x != null && (i = x[iteratorSymbol]) && i.apply(x);
|
|
248
|
+
}
|
|
249
|
+
: function () {
|
|
250
|
+
return null;
|
|
251
|
+
};
|
|
240
252
|
function delArrayItem(a, x) {
|
|
241
253
|
const i = a.indexOf(x);
|
|
242
254
|
if (i >= 0)
|
|
@@ -253,7 +265,7 @@ function getArrayOf(arrayLike) {
|
|
|
253
265
|
return [arrayLike];
|
|
254
266
|
if ((it = getIteratorOf(arrayLike))) {
|
|
255
267
|
a = [];
|
|
256
|
-
while ((x = it.next()), !x.done)
|
|
268
|
+
while (((x = it.next()), !x.done))
|
|
257
269
|
a.push(x.value);
|
|
258
270
|
return a;
|
|
259
271
|
}
|
|
@@ -294,7 +306,7 @@ var dexieErrorNames = [
|
|
|
294
306
|
'Internal',
|
|
295
307
|
'DatabaseClosed',
|
|
296
308
|
'PrematureCommit',
|
|
297
|
-
'ForeignAwait'
|
|
309
|
+
'ForeignAwait',
|
|
298
310
|
];
|
|
299
311
|
var idbDomErrorNames = [
|
|
300
312
|
'Unknown',
|
|
@@ -310,28 +322,34 @@ var idbDomErrorNames = [
|
|
|
310
322
|
'Timeout',
|
|
311
323
|
'QuotaExceeded',
|
|
312
324
|
'Syntax',
|
|
313
|
-
'DataClone'
|
|
325
|
+
'DataClone',
|
|
314
326
|
];
|
|
315
327
|
var errorList = dexieErrorNames.concat(idbDomErrorNames);
|
|
316
328
|
var defaultTexts = {
|
|
317
|
-
VersionChanged:
|
|
318
|
-
DatabaseClosed:
|
|
319
|
-
Abort:
|
|
320
|
-
TransactionInactive:
|
|
321
|
-
MissingAPI:
|
|
329
|
+
VersionChanged: 'Database version changed by other database connection',
|
|
330
|
+
DatabaseClosed: 'Database has been closed',
|
|
331
|
+
Abort: 'Transaction aborted',
|
|
332
|
+
TransactionInactive: 'Transaction has already completed or failed',
|
|
333
|
+
MissingAPI: 'IndexedDB API missing. Please visit https://tinyurl.com/y2uuvskb',
|
|
322
334
|
};
|
|
323
335
|
function DexieError(name, msg) {
|
|
324
336
|
this.name = name;
|
|
325
337
|
this.message = msg;
|
|
326
338
|
}
|
|
327
|
-
derive(DexieError)
|
|
328
|
-
|
|
339
|
+
derive(DexieError)
|
|
340
|
+
.from(Error)
|
|
341
|
+
.extend({
|
|
342
|
+
toString: function () {
|
|
343
|
+
return this.name + ': ' + this.message;
|
|
344
|
+
},
|
|
329
345
|
});
|
|
330
346
|
function getMultiErrorMessage(msg, failures) {
|
|
331
|
-
return msg +
|
|
332
|
-
.
|
|
333
|
-
.
|
|
334
|
-
|
|
347
|
+
return (msg +
|
|
348
|
+
'. Errors: ' +
|
|
349
|
+
Object.keys(failures)
|
|
350
|
+
.map((key) => failures[key].toString())
|
|
351
|
+
.filter((v, i, s) => s.indexOf(v) === i)
|
|
352
|
+
.join('\n'));
|
|
335
353
|
}
|
|
336
354
|
function ModifyError(msg, failures, successCount, failedKeys) {
|
|
337
355
|
this.failures = failures;
|
|
@@ -341,16 +359,16 @@ function ModifyError(msg, failures, successCount, failedKeys) {
|
|
|
341
359
|
}
|
|
342
360
|
derive(ModifyError).from(DexieError);
|
|
343
361
|
function BulkError(msg, failures) {
|
|
344
|
-
this.name =
|
|
345
|
-
this.failures = Object.keys(failures).map(pos => failures[pos]);
|
|
362
|
+
this.name = 'BulkError';
|
|
363
|
+
this.failures = Object.keys(failures).map((pos) => failures[pos]);
|
|
346
364
|
this.failuresByPos = failures;
|
|
347
365
|
this.message = getMultiErrorMessage(msg, this.failures);
|
|
348
366
|
}
|
|
349
367
|
derive(BulkError).from(DexieError);
|
|
350
|
-
var errnames = errorList.reduce((obj, name) => (obj[name] = name +
|
|
368
|
+
var errnames = errorList.reduce((obj, name) => ((obj[name] = name + 'Error'), obj), {});
|
|
351
369
|
const BaseException = DexieError;
|
|
352
370
|
var exceptions = errorList.reduce((obj, name) => {
|
|
353
|
-
var fullName = name +
|
|
371
|
+
var fullName = name + 'Error';
|
|
354
372
|
function DexieError(msgOrInner, inner) {
|
|
355
373
|
this.name = fullName;
|
|
356
374
|
if (!msgOrInner) {
|
|
@@ -374,23 +392,30 @@ exceptions.Syntax = SyntaxError;
|
|
|
374
392
|
exceptions.Type = TypeError;
|
|
375
393
|
exceptions.Range = RangeError;
|
|
376
394
|
var exceptionMap = idbDomErrorNames.reduce((obj, name) => {
|
|
377
|
-
obj[name +
|
|
395
|
+
obj[name + 'Error'] = exceptions[name];
|
|
378
396
|
return obj;
|
|
379
397
|
}, {});
|
|
380
398
|
function mapError(domError, message) {
|
|
381
|
-
if (!domError ||
|
|
399
|
+
if (!domError ||
|
|
400
|
+
domError instanceof DexieError ||
|
|
401
|
+
domError instanceof TypeError ||
|
|
402
|
+
domError instanceof SyntaxError ||
|
|
403
|
+
!domError.name ||
|
|
404
|
+
!exceptionMap[domError.name])
|
|
382
405
|
return domError;
|
|
383
406
|
var rv = new exceptionMap[domError.name](message || domError.message, domError);
|
|
384
|
-
if (
|
|
385
|
-
setProp(rv,
|
|
407
|
+
if ('stack' in domError) {
|
|
408
|
+
setProp(rv, 'stack', {
|
|
409
|
+
get: function () {
|
|
386
410
|
return this.inner.stack;
|
|
387
|
-
}
|
|
411
|
+
},
|
|
412
|
+
});
|
|
388
413
|
}
|
|
389
414
|
return rv;
|
|
390
415
|
}
|
|
391
416
|
var fullNameExceptions = errorList.reduce((obj, name) => {
|
|
392
|
-
if ([
|
|
393
|
-
obj[name +
|
|
417
|
+
if (['Syntax', 'Type', 'Range'].indexOf(name) === -1)
|
|
418
|
+
obj[name + 'Error'] = exceptions[name];
|
|
394
419
|
return obj;
|
|
395
420
|
}, {});
|
|
396
421
|
fullNameExceptions.ModifyError = ModifyError;
|
|
@@ -398,7 +423,9 @@ fullNameExceptions.DexieError = DexieError;
|
|
|
398
423
|
fullNameExceptions.BulkError = BulkError;
|
|
399
424
|
|
|
400
425
|
function nop() { }
|
|
401
|
-
function mirror(val) {
|
|
426
|
+
function mirror(val) {
|
|
427
|
+
return val;
|
|
428
|
+
}
|
|
402
429
|
function pureFunctionChain(f1, f2) {
|
|
403
430
|
if (f1 == null || f1 === mirror)
|
|
404
431
|
return f2;
|
|
@@ -425,7 +452,9 @@ function hookCreatingChain(f1, f2) {
|
|
|
425
452
|
this.onerror = null;
|
|
426
453
|
var res2 = f2.apply(this, arguments);
|
|
427
454
|
if (onsuccess)
|
|
428
|
-
this.onsuccess = this.onsuccess
|
|
455
|
+
this.onsuccess = this.onsuccess
|
|
456
|
+
? callBoth(onsuccess, this.onsuccess)
|
|
457
|
+
: onsuccess;
|
|
429
458
|
if (onerror)
|
|
430
459
|
this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;
|
|
431
460
|
return res2 !== undefined ? res2 : res;
|
|
@@ -441,7 +470,9 @@ function hookDeletingChain(f1, f2) {
|
|
|
441
470
|
this.onsuccess = this.onerror = null;
|
|
442
471
|
f2.apply(this, arguments);
|
|
443
472
|
if (onsuccess)
|
|
444
|
-
this.onsuccess = this.onsuccess
|
|
473
|
+
this.onsuccess = this.onsuccess
|
|
474
|
+
? callBoth(onsuccess, this.onsuccess)
|
|
475
|
+
: onsuccess;
|
|
445
476
|
if (onerror)
|
|
446
477
|
this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;
|
|
447
478
|
};
|
|
@@ -458,12 +489,16 @@ function hookUpdatingChain(f1, f2) {
|
|
|
458
489
|
this.onerror = null;
|
|
459
490
|
var res2 = f2.apply(this, arguments);
|
|
460
491
|
if (onsuccess)
|
|
461
|
-
this.onsuccess = this.onsuccess
|
|
492
|
+
this.onsuccess = this.onsuccess
|
|
493
|
+
? callBoth(onsuccess, this.onsuccess)
|
|
494
|
+
: onsuccess;
|
|
462
495
|
if (onerror)
|
|
463
496
|
this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;
|
|
464
|
-
return res === undefined
|
|
465
|
-
|
|
466
|
-
|
|
497
|
+
return res === undefined
|
|
498
|
+
? res2 === undefined
|
|
499
|
+
? undefined
|
|
500
|
+
: res2
|
|
501
|
+
: extend(res, res2);
|
|
467
502
|
};
|
|
468
503
|
}
|
|
469
504
|
function reverseStoppableEventChain(f1, f2) {
|
|
@@ -499,18 +534,14 @@ function setDebug(value, filter) {
|
|
|
499
534
|
}
|
|
500
535
|
|
|
501
536
|
var INTERNAL = {};
|
|
502
|
-
const ZONE_ECHO_LIMIT = 100, [resolvedNativePromise, nativePromiseProto, resolvedGlobalPromise] = typeof Promise === 'undefined'
|
|
503
|
-
[]
|
|
504
|
-
(() => {
|
|
537
|
+
const ZONE_ECHO_LIMIT = 100, [resolvedNativePromise, nativePromiseProto, resolvedGlobalPromise] = typeof Promise === 'undefined'
|
|
538
|
+
? []
|
|
539
|
+
: (() => {
|
|
505
540
|
let globalP = Promise.resolve();
|
|
506
541
|
if (typeof crypto === 'undefined' || !crypto.subtle)
|
|
507
542
|
return [globalP, getProto(globalP), globalP];
|
|
508
|
-
const nativeP = crypto.subtle.digest(
|
|
509
|
-
return [
|
|
510
|
-
nativeP,
|
|
511
|
-
getProto(nativeP),
|
|
512
|
-
globalP
|
|
513
|
-
];
|
|
543
|
+
const nativeP = crypto.subtle.digest('SHA-512', new Uint8Array([0]));
|
|
544
|
+
return [nativeP, getProto(nativeP), globalP];
|
|
514
545
|
})(), nativePromiseThen = nativePromiseProto && nativePromiseProto.then;
|
|
515
546
|
const NativePromise = resolvedNativePromise && resolvedNativePromise.constructor;
|
|
516
547
|
const patchGlobalPromise = !!resolvedGlobalPromise;
|
|
@@ -537,7 +568,7 @@ var globalPSD = {
|
|
|
537
568
|
onunhandled: nop,
|
|
538
569
|
pgp: false,
|
|
539
570
|
env: {},
|
|
540
|
-
finalize: nop
|
|
571
|
+
finalize: nop,
|
|
541
572
|
};
|
|
542
573
|
var PSD = globalPSD;
|
|
543
574
|
var microtickQueue = [];
|
|
@@ -580,15 +611,15 @@ const thenProp = {
|
|
|
580
611
|
return then;
|
|
581
612
|
},
|
|
582
613
|
set: function (value) {
|
|
583
|
-
setProp(this, 'then', value && value.prototype === INTERNAL
|
|
584
|
-
thenProp
|
|
585
|
-
{
|
|
614
|
+
setProp(this, 'then', value && value.prototype === INTERNAL
|
|
615
|
+
? thenProp
|
|
616
|
+
: {
|
|
586
617
|
get: function () {
|
|
587
618
|
return value;
|
|
588
619
|
},
|
|
589
|
-
set: thenProp.set
|
|
620
|
+
set: thenProp.set,
|
|
590
621
|
});
|
|
591
|
-
}
|
|
622
|
+
},
|
|
592
623
|
};
|
|
593
624
|
props(DexiePromise.prototype, {
|
|
594
625
|
then: thenProp,
|
|
@@ -599,25 +630,27 @@ props(DexiePromise.prototype, {
|
|
|
599
630
|
if (arguments.length === 1)
|
|
600
631
|
return this.then(null, onRejected);
|
|
601
632
|
var type = arguments[0], handler = arguments[1];
|
|
602
|
-
return typeof type === 'function'
|
|
603
|
-
|
|
604
|
-
:
|
|
633
|
+
return typeof type === 'function'
|
|
634
|
+
? this.then(null, (err) =>
|
|
635
|
+
err instanceof type ? handler(err) : PromiseReject(err))
|
|
636
|
+
: this.then(null, (err) =>
|
|
605
637
|
err && err.name === type ? handler(err) : PromiseReject(err));
|
|
606
638
|
},
|
|
607
639
|
finally: function (onFinally) {
|
|
608
|
-
return this.then(value => {
|
|
640
|
+
return this.then((value) => {
|
|
609
641
|
return DexiePromise.resolve(onFinally()).then(() => value);
|
|
610
|
-
}, err => {
|
|
642
|
+
}, (err) => {
|
|
611
643
|
return DexiePromise.resolve(onFinally()).then(() => PromiseReject(err));
|
|
612
644
|
});
|
|
613
645
|
},
|
|
614
646
|
timeout: function (ms, msg) {
|
|
615
|
-
return ms < Infinity
|
|
616
|
-
new DexiePromise((resolve, reject) => {
|
|
647
|
+
return ms < Infinity
|
|
648
|
+
? new DexiePromise((resolve, reject) => {
|
|
617
649
|
var handle = setTimeout(() => reject(new exceptions.Timeout(msg)), ms);
|
|
618
650
|
this.then(resolve, reject).finally(clearTimeout.bind(null, handle));
|
|
619
|
-
})
|
|
620
|
-
|
|
651
|
+
})
|
|
652
|
+
: this;
|
|
653
|
+
},
|
|
621
654
|
});
|
|
622
655
|
if (typeof Symbol !== 'undefined' && Symbol.toStringTag)
|
|
623
656
|
setProp(DexiePromise.prototype, Symbol.toStringTag, 'Dexie.Promise');
|
|
@@ -631,20 +664,21 @@ function Listener(onFulfilled, onRejected, resolve, reject, zone) {
|
|
|
631
664
|
}
|
|
632
665
|
props(DexiePromise, {
|
|
633
666
|
all: function () {
|
|
634
|
-
var values = getArrayOf
|
|
667
|
+
var values = getArrayOf
|
|
668
|
+
.apply(null, arguments)
|
|
635
669
|
.map(onPossibleParallellAsync);
|
|
636
670
|
return new DexiePromise(function (resolve, reject) {
|
|
637
671
|
if (values.length === 0)
|
|
638
672
|
resolve([]);
|
|
639
673
|
var remaining = values.length;
|
|
640
|
-
values.forEach((a, i) => DexiePromise.resolve(a).then(x => {
|
|
674
|
+
values.forEach((a, i) => DexiePromise.resolve(a).then((x) => {
|
|
641
675
|
values[i] = x;
|
|
642
676
|
if (!--remaining)
|
|
643
677
|
resolve(values);
|
|
644
678
|
}, reject));
|
|
645
679
|
});
|
|
646
680
|
},
|
|
647
|
-
resolve: value => {
|
|
681
|
+
resolve: (value) => {
|
|
648
682
|
if (value instanceof DexiePromise)
|
|
649
683
|
return value;
|
|
650
684
|
if (value && typeof value.then === 'function')
|
|
@@ -656,25 +690,31 @@ props(DexiePromise, {
|
|
|
656
690
|
},
|
|
657
691
|
reject: PromiseReject,
|
|
658
692
|
race: function () {
|
|
659
|
-
var values = getArrayOf
|
|
693
|
+
var values = getArrayOf
|
|
694
|
+
.apply(null, arguments)
|
|
695
|
+
.map(onPossibleParallellAsync);
|
|
660
696
|
return new DexiePromise((resolve, reject) => {
|
|
661
|
-
values.map(value => DexiePromise.resolve(value).then(resolve, reject));
|
|
697
|
+
values.map((value) => DexiePromise.resolve(value).then(resolve, reject));
|
|
662
698
|
});
|
|
663
699
|
},
|
|
664
700
|
PSD: {
|
|
665
701
|
get: () => PSD,
|
|
666
|
-
set: value => PSD = value
|
|
702
|
+
set: (value) => (PSD = value),
|
|
667
703
|
},
|
|
668
704
|
totalEchoes: { get: () => totalEchoes },
|
|
669
705
|
newPSD: newScope,
|
|
670
706
|
usePSD: usePSD,
|
|
671
707
|
scheduler: {
|
|
672
708
|
get: () => asap,
|
|
673
|
-
set: value => {
|
|
709
|
+
set: (value) => {
|
|
710
|
+
asap = value;
|
|
711
|
+
},
|
|
674
712
|
},
|
|
675
713
|
rejectionMapper: {
|
|
676
714
|
get: () => rejectionMapper,
|
|
677
|
-
set: value => {
|
|
715
|
+
set: (value) => {
|
|
716
|
+
rejectionMapper = value;
|
|
717
|
+
},
|
|
678
718
|
},
|
|
679
719
|
follow: (fn, zoneProps) => {
|
|
680
720
|
return new DexiePromise((resolve, reject) => {
|
|
@@ -684,36 +724,43 @@ props(DexiePromise, {
|
|
|
684
724
|
psd.onunhandled = reject;
|
|
685
725
|
psd.finalize = callBoth(function () {
|
|
686
726
|
run_at_end_of_this_or_next_physical_tick(() => {
|
|
687
|
-
this.unhandleds.length === 0
|
|
727
|
+
this.unhandleds.length === 0
|
|
728
|
+
? resolve()
|
|
729
|
+
: reject(this.unhandleds[0]);
|
|
688
730
|
});
|
|
689
731
|
}, psd.finalize);
|
|
690
732
|
fn();
|
|
691
733
|
}, zoneProps, resolve, reject);
|
|
692
734
|
});
|
|
693
|
-
}
|
|
735
|
+
},
|
|
694
736
|
});
|
|
695
737
|
if (NativePromise) {
|
|
696
738
|
if (NativePromise.allSettled)
|
|
697
|
-
setProp(DexiePromise,
|
|
698
|
-
const possiblePromises = getArrayOf
|
|
699
|
-
|
|
739
|
+
setProp(DexiePromise, 'allSettled', function () {
|
|
740
|
+
const possiblePromises = getArrayOf
|
|
741
|
+
.apply(null, arguments)
|
|
742
|
+
.map(onPossibleParallellAsync);
|
|
743
|
+
return new DexiePromise((resolve) => {
|
|
700
744
|
if (possiblePromises.length === 0)
|
|
701
745
|
resolve([]);
|
|
702
746
|
let remaining = possiblePromises.length;
|
|
703
747
|
const results = new Array(remaining);
|
|
704
|
-
possiblePromises.forEach((p, i) => DexiePromise.resolve(p)
|
|
748
|
+
possiblePromises.forEach((p, i) => DexiePromise.resolve(p)
|
|
749
|
+
.then((value) => (results[i] = { status: 'fulfilled', value }), (reason) => (results[i] = { status: 'rejected', reason }))
|
|
705
750
|
.then(() => --remaining || resolve(results)));
|
|
706
751
|
});
|
|
707
752
|
});
|
|
708
753
|
if (NativePromise.any && typeof AggregateError !== 'undefined')
|
|
709
|
-
setProp(DexiePromise,
|
|
710
|
-
const possiblePromises = getArrayOf
|
|
754
|
+
setProp(DexiePromise, 'any', function () {
|
|
755
|
+
const possiblePromises = getArrayOf
|
|
756
|
+
.apply(null, arguments)
|
|
757
|
+
.map(onPossibleParallellAsync);
|
|
711
758
|
return new DexiePromise((resolve, reject) => {
|
|
712
759
|
if (possiblePromises.length === 0)
|
|
713
760
|
reject(new AggregateError([]));
|
|
714
761
|
let remaining = possiblePromises.length;
|
|
715
762
|
const failures = new Array(remaining);
|
|
716
|
-
possiblePromises.forEach((p, i) => DexiePromise.resolve(p).then(value => resolve(value), failure => {
|
|
763
|
+
possiblePromises.forEach((p, i) => DexiePromise.resolve(p).then((value) => resolve(value), (failure) => {
|
|
717
764
|
failures[i] = failure;
|
|
718
765
|
if (!--remaining)
|
|
719
766
|
reject(new AggregateError(failures));
|
|
@@ -725,7 +772,7 @@ if (NativePromise) {
|
|
|
725
772
|
}
|
|
726
773
|
function executePromiseTask(promise, fn) {
|
|
727
774
|
try {
|
|
728
|
-
fn(value => {
|
|
775
|
+
fn((value) => {
|
|
729
776
|
if (promise._state !== null)
|
|
730
777
|
return;
|
|
731
778
|
if (value === promise)
|
|
@@ -733,9 +780,9 @@ function executePromiseTask(promise, fn) {
|
|
|
733
780
|
var shouldExecuteTick = promise._lib && beginMicroTickScope();
|
|
734
781
|
if (value && typeof value.then === 'function') {
|
|
735
782
|
executePromiseTask(promise, (resolve, reject) => {
|
|
736
|
-
value instanceof DexiePromise
|
|
737
|
-
value._then(resolve, reject)
|
|
738
|
-
value.then(resolve, reject);
|
|
783
|
+
value instanceof DexiePromise
|
|
784
|
+
? value._then(resolve, reject)
|
|
785
|
+
: value.then(resolve, reject);
|
|
739
786
|
});
|
|
740
787
|
}
|
|
741
788
|
else {
|
|
@@ -798,7 +845,10 @@ function callListener(cb, promise, listener) {
|
|
|
798
845
|
var ret, value = promise._value;
|
|
799
846
|
if (!promise._state && rejectingErrors.length)
|
|
800
847
|
rejectingErrors = [];
|
|
801
|
-
ret =
|
|
848
|
+
ret =
|
|
849
|
+
debug && promise._consoleTask
|
|
850
|
+
? promise._consoleTask.run(() => cb(value))
|
|
851
|
+
: cb(value);
|
|
802
852
|
if (!promise._state && rejectingErrors.indexOf(value) === -1) {
|
|
803
853
|
markErrorAsHandled(promise);
|
|
804
854
|
}
|
|
@@ -843,7 +893,7 @@ function endMicroTickScope() {
|
|
|
843
893
|
function finalizePhysicalTick() {
|
|
844
894
|
var unhandledErrs = unhandledErrors;
|
|
845
895
|
unhandledErrors = [];
|
|
846
|
-
unhandledErrs.forEach(p => {
|
|
896
|
+
unhandledErrs.forEach((p) => {
|
|
847
897
|
p._PSD.onunhandled.call(null, p._value, p);
|
|
848
898
|
});
|
|
849
899
|
var finalizers = tickFinalizers.slice(0);
|
|
@@ -864,7 +914,7 @@ function run_at_end_of_this_or_next_physical_tick(fn) {
|
|
|
864
914
|
}, []);
|
|
865
915
|
}
|
|
866
916
|
function addPossiblyUnhandledError(promise) {
|
|
867
|
-
if (!unhandledErrors.some(p => p._value === promise._value))
|
|
917
|
+
if (!unhandledErrors.some((p) => p._value === promise._value))
|
|
868
918
|
unhandledErrors.push(promise);
|
|
869
919
|
}
|
|
870
920
|
function markErrorAsHandled(promise) {
|
|
@@ -909,16 +959,22 @@ function newScope(fn, props, a1, a2) {
|
|
|
909
959
|
psd.global = false;
|
|
910
960
|
psd.id = ++zone_id_counter;
|
|
911
961
|
globalPSD.env;
|
|
912
|
-
psd.env = patchGlobalPromise
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
962
|
+
psd.env = patchGlobalPromise
|
|
963
|
+
? {
|
|
964
|
+
Promise: DexiePromise,
|
|
965
|
+
PromiseProp: {
|
|
966
|
+
value: DexiePromise,
|
|
967
|
+
configurable: true,
|
|
968
|
+
writable: true,
|
|
969
|
+
},
|
|
970
|
+
all: DexiePromise.all,
|
|
971
|
+
race: DexiePromise.race,
|
|
972
|
+
allSettled: DexiePromise.allSettled,
|
|
973
|
+
any: DexiePromise.any,
|
|
974
|
+
resolve: DexiePromise.resolve,
|
|
975
|
+
reject: DexiePromise.reject,
|
|
976
|
+
}
|
|
977
|
+
: {};
|
|
922
978
|
if (props)
|
|
923
979
|
extend(psd, props);
|
|
924
980
|
++parent.ref;
|
|
@@ -949,12 +1005,14 @@ if (('' + nativePromiseThen).indexOf('[native code]') === -1) {
|
|
|
949
1005
|
incrementExpectedAwaits = decrementExpectedAwaits = nop;
|
|
950
1006
|
}
|
|
951
1007
|
function onPossibleParallellAsync(possiblePromise) {
|
|
952
|
-
if (task.echoes &&
|
|
1008
|
+
if (task.echoes &&
|
|
1009
|
+
possiblePromise &&
|
|
1010
|
+
possiblePromise.constructor === NativePromise) {
|
|
953
1011
|
incrementExpectedAwaits();
|
|
954
|
-
return possiblePromise.then(x => {
|
|
1012
|
+
return possiblePromise.then((x) => {
|
|
955
1013
|
decrementExpectedAwaits();
|
|
956
1014
|
return x;
|
|
957
|
-
}, e => {
|
|
1015
|
+
}, (e) => {
|
|
958
1016
|
decrementExpectedAwaits();
|
|
959
1017
|
return rejection(e);
|
|
960
1018
|
});
|
|
@@ -976,7 +1034,9 @@ function zoneLeaveEcho() {
|
|
|
976
1034
|
}
|
|
977
1035
|
function switchToZone(targetZone, bEnteringZone) {
|
|
978
1036
|
var currentZone = PSD;
|
|
979
|
-
if (bEnteringZone
|
|
1037
|
+
if (bEnteringZone
|
|
1038
|
+
? task.echoes && (!zoneEchoes++ || targetZone !== PSD)
|
|
1039
|
+
: zoneEchoes && (!--zoneEchoes || targetZone !== PSD)) {
|
|
980
1040
|
queueMicrotask(bEnteringZone ? zoneEnterEcho.bind(null, targetZone) : zoneLeaveEcho);
|
|
981
1041
|
}
|
|
982
1042
|
if (targetZone === PSD)
|
|
@@ -1002,16 +1062,18 @@ function switchToZone(targetZone, bEnteringZone) {
|
|
|
1002
1062
|
}
|
|
1003
1063
|
function snapShot() {
|
|
1004
1064
|
var GlobalPromise = _global.Promise;
|
|
1005
|
-
return patchGlobalPromise
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1065
|
+
return patchGlobalPromise
|
|
1066
|
+
? {
|
|
1067
|
+
Promise: GlobalPromise,
|
|
1068
|
+
PromiseProp: Object.getOwnPropertyDescriptor(_global, 'Promise'),
|
|
1069
|
+
all: GlobalPromise.all,
|
|
1070
|
+
race: GlobalPromise.race,
|
|
1071
|
+
allSettled: GlobalPromise.allSettled,
|
|
1072
|
+
any: GlobalPromise.any,
|
|
1073
|
+
resolve: GlobalPromise.resolve,
|
|
1074
|
+
reject: GlobalPromise.reject,
|
|
1075
|
+
}
|
|
1076
|
+
: {};
|
|
1015
1077
|
}
|
|
1016
1078
|
function usePSD(psd, fn, a1, a2, a3) {
|
|
1017
1079
|
var outerScope = PSD;
|
|
@@ -1024,20 +1086,22 @@ function usePSD(psd, fn, a1, a2, a3) {
|
|
|
1024
1086
|
}
|
|
1025
1087
|
}
|
|
1026
1088
|
function nativeAwaitCompatibleWrap(fn, zone, possibleAwait, cleanup) {
|
|
1027
|
-
return typeof fn !== 'function'
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1089
|
+
return typeof fn !== 'function'
|
|
1090
|
+
? fn
|
|
1091
|
+
: function () {
|
|
1092
|
+
var outerZone = PSD;
|
|
1093
|
+
if (possibleAwait)
|
|
1094
|
+
incrementExpectedAwaits();
|
|
1095
|
+
switchToZone(zone, true);
|
|
1096
|
+
try {
|
|
1097
|
+
return fn.apply(this, arguments);
|
|
1098
|
+
}
|
|
1099
|
+
finally {
|
|
1100
|
+
switchToZone(outerZone, false);
|
|
1101
|
+
if (cleanup)
|
|
1102
|
+
queueMicrotask(decrementExpectedAwaits);
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1041
1105
|
}
|
|
1042
1106
|
function execInGlobalContext(cb) {
|
|
1043
1107
|
if (Promise === NativePromise && task.echoes === 0) {
|
|
@@ -1055,7 +1119,7 @@ function execInGlobalContext(cb) {
|
|
|
1055
1119
|
var rejection = DexiePromise.reject;
|
|
1056
1120
|
|
|
1057
1121
|
function tempTransaction(db, mode, storeNames, fn) {
|
|
1058
|
-
if (!db.idbdb || (!db._state.openComplete &&
|
|
1122
|
+
if (!db.idbdb || (!db._state.openComplete && !PSD.letThrough && !db._vip)) {
|
|
1059
1123
|
if (db._state.openComplete) {
|
|
1060
1124
|
return rejection(new exceptions.DatabaseClosed(db._state.dbOpenError));
|
|
1061
1125
|
}
|
|
@@ -1073,45 +1137,53 @@ function tempTransaction(db, mode, storeNames, fn) {
|
|
|
1073
1137
|
db._state.PR1398_maxLoop = 3;
|
|
1074
1138
|
}
|
|
1075
1139
|
catch (ex) {
|
|
1076
|
-
if (ex.name === errnames.InvalidState &&
|
|
1140
|
+
if (ex.name === errnames.InvalidState &&
|
|
1141
|
+
db.isOpen() &&
|
|
1142
|
+
--db._state.PR1398_maxLoop > 0) {
|
|
1077
1143
|
console.warn('Dexie: Need to reopen db');
|
|
1078
1144
|
db.close({ disableAutoOpen: false });
|
|
1079
1145
|
return db.open().then(() => tempTransaction(db, mode, storeNames, fn));
|
|
1080
1146
|
}
|
|
1081
1147
|
return rejection(ex);
|
|
1082
1148
|
}
|
|
1083
|
-
return trans
|
|
1149
|
+
return trans
|
|
1150
|
+
._promise(mode, (resolve, reject) => {
|
|
1084
1151
|
return newScope(() => {
|
|
1085
1152
|
PSD.trans = trans;
|
|
1086
1153
|
return fn(resolve, reject, trans);
|
|
1087
1154
|
});
|
|
1088
|
-
})
|
|
1155
|
+
})
|
|
1156
|
+
.then((result) => {
|
|
1089
1157
|
if (mode === 'readwrite')
|
|
1090
1158
|
try {
|
|
1091
1159
|
trans.idbtrans.commit();
|
|
1092
1160
|
}
|
|
1093
1161
|
catch { }
|
|
1094
|
-
return mode === 'readonly'
|
|
1162
|
+
return mode === 'readonly'
|
|
1163
|
+
? result
|
|
1164
|
+
: trans._completion.then(() => result);
|
|
1095
1165
|
});
|
|
1096
1166
|
}
|
|
1097
1167
|
}
|
|
1098
1168
|
|
|
1099
|
-
const DEXIE_VERSION = '4.4.
|
|
1169
|
+
const DEXIE_VERSION = '4.4.2';
|
|
1100
1170
|
const maxString = String.fromCharCode(65535);
|
|
1101
1171
|
const minKey = -Infinity;
|
|
1102
|
-
const INVALID_KEY_ARGUMENT =
|
|
1103
|
-
const STRING_EXPECTED =
|
|
1172
|
+
const INVALID_KEY_ARGUMENT = 'Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.';
|
|
1173
|
+
const STRING_EXPECTED = 'String expected.';
|
|
1104
1174
|
const DEFAULT_MAX_CONNECTIONS = 1000;
|
|
1105
1175
|
const DBNAMES_DB = '__dbnames';
|
|
1106
1176
|
const READONLY = 'readonly';
|
|
1107
1177
|
const READWRITE = 'readwrite';
|
|
1108
1178
|
|
|
1109
1179
|
function combine(filter1, filter2) {
|
|
1110
|
-
return filter1
|
|
1111
|
-
filter2
|
|
1112
|
-
function () {
|
|
1113
|
-
|
|
1114
|
-
|
|
1180
|
+
return filter1
|
|
1181
|
+
? filter2
|
|
1182
|
+
? function () {
|
|
1183
|
+
return (filter1.apply(this, arguments) && filter2.apply(this, arguments));
|
|
1184
|
+
}
|
|
1185
|
+
: filter1
|
|
1186
|
+
: filter2;
|
|
1115
1187
|
}
|
|
1116
1188
|
|
|
1117
1189
|
const AnyRange = {
|
|
@@ -1119,13 +1191,13 @@ const AnyRange = {
|
|
|
1119
1191
|
lower: -Infinity,
|
|
1120
1192
|
lowerOpen: false,
|
|
1121
1193
|
upper: [[]],
|
|
1122
|
-
upperOpen: false
|
|
1194
|
+
upperOpen: false,
|
|
1123
1195
|
};
|
|
1124
1196
|
|
|
1125
1197
|
function workaroundForUndefinedPrimKey(keyPath) {
|
|
1126
|
-
return typeof keyPath ===
|
|
1198
|
+
return typeof keyPath === 'string' && !/\./.test(keyPath)
|
|
1127
1199
|
? (obj) => {
|
|
1128
|
-
if (obj[keyPath] === undefined &&
|
|
1200
|
+
if (obj[keyPath] === undefined && keyPath in obj) {
|
|
1129
1201
|
obj = deepClone(obj);
|
|
1130
1202
|
delete obj[keyPath];
|
|
1131
1203
|
}
|
|
@@ -1227,7 +1299,7 @@ function builtInDeletionTrigger(table, keys, res) {
|
|
|
1227
1299
|
|
|
1228
1300
|
class PropModification {
|
|
1229
1301
|
execute(value) {
|
|
1230
|
-
const spec = this[
|
|
1302
|
+
const spec = this['@@propmod'];
|
|
1231
1303
|
if (spec.add !== undefined) {
|
|
1232
1304
|
const term = spec.add;
|
|
1233
1305
|
if (isArray(term)) {
|
|
@@ -1248,7 +1320,9 @@ class PropModification {
|
|
|
1248
1320
|
if (spec.remove !== undefined) {
|
|
1249
1321
|
const subtrahend = spec.remove;
|
|
1250
1322
|
if (isArray(subtrahend)) {
|
|
1251
|
-
return isArray(value)
|
|
1323
|
+
return isArray(value)
|
|
1324
|
+
? value.filter((item) => !subtrahend.includes(item)).sort()
|
|
1325
|
+
: [];
|
|
1252
1326
|
}
|
|
1253
1327
|
if (typeof subtrahend === 'number')
|
|
1254
1328
|
return Number(value) - subtrahend;
|
|
@@ -1263,13 +1337,15 @@ class PropModification {
|
|
|
1263
1337
|
throw new TypeError(`Invalid subtrahend ${subtrahend}`);
|
|
1264
1338
|
}
|
|
1265
1339
|
const prefixToReplace = spec.replacePrefix?.[0];
|
|
1266
|
-
if (prefixToReplace &&
|
|
1340
|
+
if (prefixToReplace &&
|
|
1341
|
+
typeof value === 'string' &&
|
|
1342
|
+
value.startsWith(prefixToReplace)) {
|
|
1267
1343
|
return spec.replacePrefix[1] + value.substring(prefixToReplace.length);
|
|
1268
1344
|
}
|
|
1269
1345
|
return value;
|
|
1270
1346
|
}
|
|
1271
1347
|
constructor(spec) {
|
|
1272
|
-
this[
|
|
1348
|
+
this['@@propmod'] = spec;
|
|
1273
1349
|
}
|
|
1274
1350
|
}
|
|
1275
1351
|
|
|
@@ -1297,22 +1373,25 @@ class Table {
|
|
|
1297
1373
|
_trans(mode, fn, writeLocked) {
|
|
1298
1374
|
const trans = this._tx || PSD.trans;
|
|
1299
1375
|
const tableName = this.name;
|
|
1300
|
-
const task = debug &&
|
|
1376
|
+
const task = debug &&
|
|
1377
|
+
typeof console !== 'undefined' &&
|
|
1378
|
+
console.createTask &&
|
|
1379
|
+
console.createTask(`Dexie: ${mode === 'readonly' ? 'read' : 'write'} ${this.name}`);
|
|
1301
1380
|
function checkTableInTransaction(resolve, reject, trans) {
|
|
1302
1381
|
if (!trans.schema[tableName])
|
|
1303
|
-
throw new exceptions.NotFound(
|
|
1382
|
+
throw new exceptions.NotFound('Table ' + tableName + ' not part of transaction');
|
|
1304
1383
|
return fn(trans.idbtrans, trans);
|
|
1305
1384
|
}
|
|
1306
1385
|
const wasRootExec = beginMicroTickScope();
|
|
1307
1386
|
try {
|
|
1308
|
-
let p = trans && trans.db._novip === this.db._novip
|
|
1309
|
-
trans === PSD.trans
|
|
1310
|
-
trans._promise(mode, checkTableInTransaction, writeLocked)
|
|
1311
|
-
newScope(() => trans._promise(mode, checkTableInTransaction, writeLocked), { trans: trans, transless: PSD.transless || PSD })
|
|
1312
|
-
tempTransaction(this.db, mode, [this.name], checkTableInTransaction);
|
|
1387
|
+
let p = trans && trans.db._novip === this.db._novip
|
|
1388
|
+
? trans === PSD.trans
|
|
1389
|
+
? trans._promise(mode, checkTableInTransaction, writeLocked)
|
|
1390
|
+
: newScope(() => trans._promise(mode, checkTableInTransaction, writeLocked), { trans: trans, transless: PSD.transless || PSD })
|
|
1391
|
+
: tempTransaction(this.db, mode, [this.name], checkTableInTransaction);
|
|
1313
1392
|
if (task) {
|
|
1314
1393
|
p._consoleTask = task;
|
|
1315
|
-
p = p.catch(err => {
|
|
1394
|
+
p = p.catch((err) => {
|
|
1316
1395
|
console.trace(err);
|
|
1317
1396
|
return rejection(err);
|
|
1318
1397
|
});
|
|
@@ -1330,8 +1409,9 @@ class Table {
|
|
|
1330
1409
|
if (keyOrCrit == null)
|
|
1331
1410
|
return rejection(new exceptions.Type(`Invalid argument to Table.get()`));
|
|
1332
1411
|
return this._trans('readonly', (trans) => {
|
|
1333
|
-
return this.core
|
|
1334
|
-
.
|
|
1412
|
+
return this.core
|
|
1413
|
+
.get({ trans, key: keyOrCrit })
|
|
1414
|
+
.then((res) => this.hook.reading.fire(res));
|
|
1335
1415
|
}).then(cb);
|
|
1336
1416
|
}
|
|
1337
1417
|
where(indexOrCrit) {
|
|
@@ -1341,12 +1421,12 @@ class Table {
|
|
|
1341
1421
|
return new this.db.WhereClause(this, `[${indexOrCrit.join('+')}]`);
|
|
1342
1422
|
const keyPaths = keys(indexOrCrit);
|
|
1343
1423
|
if (keyPaths.length === 1)
|
|
1344
|
-
return this
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1424
|
+
return this.where(keyPaths[0]).equals(indexOrCrit[keyPaths[0]]);
|
|
1425
|
+
const compoundIndex = this.schema.indexes
|
|
1426
|
+
.concat(this.schema.primKey)
|
|
1427
|
+
.filter((ix) => {
|
|
1348
1428
|
if (ix.compound &&
|
|
1349
|
-
keyPaths.every(keyPath => ix.keyPath.indexOf(keyPath) >= 0)) {
|
|
1429
|
+
keyPaths.every((keyPath) => ix.keyPath.indexOf(keyPath) >= 0)) {
|
|
1350
1430
|
for (let i = 0; i < keyPaths.length; ++i) {
|
|
1351
1431
|
if (keyPaths.indexOf(ix.keyPath[i]) === -1)
|
|
1352
1432
|
return false;
|
|
@@ -1354,12 +1434,11 @@ class Table {
|
|
|
1354
1434
|
return true;
|
|
1355
1435
|
}
|
|
1356
1436
|
return false;
|
|
1357
|
-
})
|
|
1437
|
+
})
|
|
1438
|
+
.sort((a, b) => a.keyPath.length - b.keyPath.length)[0];
|
|
1358
1439
|
if (compoundIndex && this.db._maxKey !== maxString) {
|
|
1359
1440
|
const keyPathsInValidOrder = compoundIndex.keyPath.slice(0, keyPaths.length);
|
|
1360
|
-
return this
|
|
1361
|
-
.where(keyPathsInValidOrder)
|
|
1362
|
-
.equals(keyPathsInValidOrder.map(kp => indexOrCrit[kp]));
|
|
1441
|
+
return this.where(keyPathsInValidOrder).equals(keyPathsInValidOrder.map((kp) => indexOrCrit[kp]));
|
|
1363
1442
|
}
|
|
1364
1443
|
if (!compoundIndex && debug)
|
|
1365
1444
|
console.warn(`The query ${JSON.stringify(indexOrCrit)} on ${this.name} would benefit from a ` +
|
|
@@ -1373,21 +1452,24 @@ class Table {
|
|
|
1373
1452
|
const value = indexOrCrit[keyPath];
|
|
1374
1453
|
return [
|
|
1375
1454
|
prevIndex || index,
|
|
1376
|
-
prevIndex || !index
|
|
1377
|
-
combine(prevFilterFn, index && index.multi
|
|
1378
|
-
x => {
|
|
1455
|
+
prevIndex || !index
|
|
1456
|
+
? combine(prevFilterFn, index && index.multi
|
|
1457
|
+
? (x) => {
|
|
1379
1458
|
const prop = getByKeyPath(x, keyPath);
|
|
1380
|
-
return isArray(prop) &&
|
|
1381
|
-
|
|
1382
|
-
|
|
1459
|
+
return (isArray(prop) &&
|
|
1460
|
+
prop.some((item) => equals(value, item)));
|
|
1461
|
+
}
|
|
1462
|
+
: (x) => equals(value, getByKeyPath(x, keyPath)))
|
|
1463
|
+
: prevFilterFn,
|
|
1383
1464
|
];
|
|
1384
1465
|
}, [null, null]);
|
|
1385
|
-
return idx
|
|
1386
|
-
this.where(idx.name)
|
|
1387
|
-
.
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
this.
|
|
1466
|
+
return idx
|
|
1467
|
+
? this.where(idx.name)
|
|
1468
|
+
.equals(indexOrCrit[idx.keyPath])
|
|
1469
|
+
.filter(filterFunction)
|
|
1470
|
+
: compoundIndex
|
|
1471
|
+
? this.filter(filterFunction)
|
|
1472
|
+
: this.where(keyPaths).equals('');
|
|
1391
1473
|
}
|
|
1392
1474
|
filter(filterFunction) {
|
|
1393
1475
|
return this.toCollection().and(filterFunction);
|
|
@@ -1411,9 +1493,7 @@ class Table {
|
|
|
1411
1493
|
return new this.db.Collection(new this.db.WhereClause(this));
|
|
1412
1494
|
}
|
|
1413
1495
|
orderBy(index) {
|
|
1414
|
-
return new this.db.Collection(new this.db.WhereClause(this, isArray(index) ?
|
|
1415
|
-
`[${index.join('+')}]` :
|
|
1416
|
-
index));
|
|
1496
|
+
return new this.db.Collection(new this.db.WhereClause(this, isArray(index) ? `[${index.join('+')}]` : index));
|
|
1417
1497
|
}
|
|
1418
1498
|
reverse() {
|
|
1419
1499
|
return this.toCollection().reverse();
|
|
@@ -1423,13 +1503,17 @@ class Table {
|
|
|
1423
1503
|
this.schema.mappedClass = constructor;
|
|
1424
1504
|
if (constructor.prototype instanceof Entity) {
|
|
1425
1505
|
constructor = class extends constructor {
|
|
1426
|
-
get db() {
|
|
1427
|
-
|
|
1506
|
+
get db() {
|
|
1507
|
+
return db;
|
|
1508
|
+
}
|
|
1509
|
+
table() {
|
|
1510
|
+
return tableName;
|
|
1511
|
+
}
|
|
1428
1512
|
};
|
|
1429
1513
|
}
|
|
1430
1514
|
const inheritedProps = new Set();
|
|
1431
1515
|
for (let proto = constructor.prototype; proto; proto = getProto(proto)) {
|
|
1432
|
-
Object.getOwnPropertyNames(proto).forEach(propName => inheritedProps.add(propName));
|
|
1516
|
+
Object.getOwnPropertyNames(proto).forEach((propName) => inheritedProps.add(propName));
|
|
1433
1517
|
}
|
|
1434
1518
|
const readHook = (obj) => {
|
|
1435
1519
|
if (!obj)
|
|
@@ -1447,7 +1531,7 @@ class Table {
|
|
|
1447
1531
|
this.hook.reading.unsubscribe(this.schema.readHook);
|
|
1448
1532
|
}
|
|
1449
1533
|
this.schema.readHook = readHook;
|
|
1450
|
-
this.hook(
|
|
1534
|
+
this.hook('reading', readHook);
|
|
1451
1535
|
return constructor;
|
|
1452
1536
|
}
|
|
1453
1537
|
defineClass() {
|
|
@@ -1462,10 +1546,16 @@ class Table {
|
|
|
1462
1546
|
if (keyPath && auto) {
|
|
1463
1547
|
objToAdd = workaroundForUndefinedPrimKey(keyPath)(obj);
|
|
1464
1548
|
}
|
|
1465
|
-
return this._trans('readwrite', trans => {
|
|
1466
|
-
return this.core.mutate({
|
|
1467
|
-
|
|
1468
|
-
|
|
1549
|
+
return this._trans('readwrite', (trans) => {
|
|
1550
|
+
return this.core.mutate({
|
|
1551
|
+
trans,
|
|
1552
|
+
type: 'add',
|
|
1553
|
+
keys: key != null ? [key] : null,
|
|
1554
|
+
values: [objToAdd],
|
|
1555
|
+
});
|
|
1556
|
+
})
|
|
1557
|
+
.then((res) => res.numFailures ? DexiePromise.reject(res.failures[0]) : res.lastResult)
|
|
1558
|
+
.then((lastResult) => {
|
|
1469
1559
|
if (keyPath) {
|
|
1470
1560
|
try {
|
|
1471
1561
|
setByKeyPath(obj, keyPath, lastResult);
|
|
@@ -1477,20 +1567,22 @@ class Table {
|
|
|
1477
1567
|
}
|
|
1478
1568
|
upsert(key, modifications) {
|
|
1479
1569
|
const { keyPath } = this.schema.primKey;
|
|
1480
|
-
return this._trans('readwrite', trans => {
|
|
1481
|
-
return this.core.get({ trans, key }).then(existing => {
|
|
1570
|
+
return this._trans('readwrite', (trans) => {
|
|
1571
|
+
return this.core.get({ trans, key }).then((existing) => {
|
|
1482
1572
|
const obj = existing ?? {};
|
|
1483
1573
|
applyUpdateSpec(obj, modifications);
|
|
1484
1574
|
if (keyPath)
|
|
1485
1575
|
setByKeyPath(obj, keyPath, key);
|
|
1486
|
-
return this.core
|
|
1576
|
+
return this.core
|
|
1577
|
+
.mutate({
|
|
1487
1578
|
trans,
|
|
1488
1579
|
type: 'put',
|
|
1489
1580
|
values: [obj],
|
|
1490
1581
|
keys: [key],
|
|
1491
1582
|
upsert: true,
|
|
1492
|
-
updates: { keys: [key], changeSpecs: [modifications] }
|
|
1493
|
-
})
|
|
1583
|
+
updates: { keys: [key], changeSpecs: [modifications] },
|
|
1584
|
+
})
|
|
1585
|
+
.then((res) => res.numFailures ? DexiePromise.reject(res.failures[0]) : !!existing);
|
|
1494
1586
|
});
|
|
1495
1587
|
});
|
|
1496
1588
|
}
|
|
@@ -1498,11 +1590,11 @@ class Table {
|
|
|
1498
1590
|
if (typeof keyOrObject === 'object' && !isArray(keyOrObject)) {
|
|
1499
1591
|
const key = getByKeyPath(keyOrObject, this.schema.primKey.keyPath);
|
|
1500
1592
|
if (key === undefined)
|
|
1501
|
-
return rejection(new exceptions.InvalidArgument(
|
|
1502
|
-
return this.where(
|
|
1593
|
+
return rejection(new exceptions.InvalidArgument('Given object does not contain its primary key'));
|
|
1594
|
+
return this.where(':id').equals(key).modify(modifications);
|
|
1503
1595
|
}
|
|
1504
1596
|
else {
|
|
1505
|
-
return this.where(
|
|
1597
|
+
return this.where(':id').equals(keyOrObject).modify(modifications);
|
|
1506
1598
|
}
|
|
1507
1599
|
}
|
|
1508
1600
|
put(obj, key) {
|
|
@@ -1511,9 +1603,14 @@ class Table {
|
|
|
1511
1603
|
if (keyPath && auto) {
|
|
1512
1604
|
objToAdd = workaroundForUndefinedPrimKey(keyPath)(obj);
|
|
1513
1605
|
}
|
|
1514
|
-
return this._trans('readwrite', trans => this.core.mutate({
|
|
1515
|
-
|
|
1516
|
-
|
|
1606
|
+
return this._trans('readwrite', (trans) => this.core.mutate({
|
|
1607
|
+
trans,
|
|
1608
|
+
type: 'put',
|
|
1609
|
+
values: [objToAdd],
|
|
1610
|
+
keys: key != null ? [key] : null,
|
|
1611
|
+
}))
|
|
1612
|
+
.then((res) => res.numFailures ? DexiePromise.reject(res.failures[0]) : res.lastResult)
|
|
1613
|
+
.then((lastResult) => {
|
|
1517
1614
|
if (keyPath) {
|
|
1518
1615
|
try {
|
|
1519
1616
|
setByKeyPath(obj, keyPath, lastResult);
|
|
@@ -1524,38 +1621,49 @@ class Table {
|
|
|
1524
1621
|
});
|
|
1525
1622
|
}
|
|
1526
1623
|
delete(key) {
|
|
1527
|
-
return this._trans('readwrite', trans => this.core
|
|
1528
|
-
.
|
|
1529
|
-
.then(res =>
|
|
1624
|
+
return this._trans('readwrite', (trans) => this.core
|
|
1625
|
+
.mutate({ trans, type: 'delete', keys: [key] })
|
|
1626
|
+
.then((res) => builtInDeletionTrigger(this, [key], res))
|
|
1627
|
+
.then((res) => res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined));
|
|
1530
1628
|
}
|
|
1531
1629
|
clear() {
|
|
1532
|
-
return this._trans('readwrite', trans => this.core
|
|
1533
|
-
.
|
|
1534
|
-
.then(res => res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined);
|
|
1630
|
+
return this._trans('readwrite', (trans) => this.core
|
|
1631
|
+
.mutate({ trans, type: 'deleteRange', range: AnyRange })
|
|
1632
|
+
.then((res) => builtInDeletionTrigger(this, null, res))).then((res) => res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined);
|
|
1535
1633
|
}
|
|
1536
1634
|
bulkGet(keys) {
|
|
1537
|
-
return this._trans('readonly', trans => {
|
|
1538
|
-
return this.core
|
|
1635
|
+
return this._trans('readonly', (trans) => {
|
|
1636
|
+
return this.core
|
|
1637
|
+
.getMany({
|
|
1539
1638
|
keys,
|
|
1540
|
-
trans
|
|
1541
|
-
})
|
|
1639
|
+
trans,
|
|
1640
|
+
})
|
|
1641
|
+
.then((result) => result.map((res) => this.hook.reading.fire(res)));
|
|
1542
1642
|
});
|
|
1543
1643
|
}
|
|
1544
1644
|
bulkAdd(objects, keysOrOptions, options) {
|
|
1545
1645
|
const keys = Array.isArray(keysOrOptions) ? keysOrOptions : undefined;
|
|
1546
|
-
options =
|
|
1646
|
+
options =
|
|
1647
|
+
options || (keys ? undefined : keysOrOptions);
|
|
1547
1648
|
const wantResults = options ? options.allKeys : undefined;
|
|
1548
|
-
return this._trans('readwrite', trans => {
|
|
1649
|
+
return this._trans('readwrite', (trans) => {
|
|
1549
1650
|
const { auto, keyPath } = this.schema.primKey;
|
|
1550
1651
|
if (keyPath && keys)
|
|
1551
|
-
throw new exceptions.InvalidArgument(
|
|
1652
|
+
throw new exceptions.InvalidArgument('bulkAdd(): keys argument invalid on tables with inbound keys');
|
|
1552
1653
|
if (keys && keys.length !== objects.length)
|
|
1553
|
-
throw new exceptions.InvalidArgument(
|
|
1654
|
+
throw new exceptions.InvalidArgument('Arguments objects and keys must have the same length');
|
|
1554
1655
|
const numObjects = objects.length;
|
|
1555
|
-
let objectsToAdd = keyPath && auto
|
|
1556
|
-
objects.map(workaroundForUndefinedPrimKey(keyPath))
|
|
1557
|
-
objects;
|
|
1558
|
-
return this.core
|
|
1656
|
+
let objectsToAdd = keyPath && auto
|
|
1657
|
+
? objects.map(workaroundForUndefinedPrimKey(keyPath))
|
|
1658
|
+
: objects;
|
|
1659
|
+
return this.core
|
|
1660
|
+
.mutate({
|
|
1661
|
+
trans,
|
|
1662
|
+
type: 'add',
|
|
1663
|
+
keys: keys,
|
|
1664
|
+
values: objectsToAdd,
|
|
1665
|
+
wantResults,
|
|
1666
|
+
})
|
|
1559
1667
|
.then(({ numFailures, results, lastResult, failures }) => {
|
|
1560
1668
|
const result = wantResults ? results : lastResult;
|
|
1561
1669
|
if (numFailures === 0)
|
|
@@ -1566,19 +1674,27 @@ class Table {
|
|
|
1566
1674
|
}
|
|
1567
1675
|
bulkPut(objects, keysOrOptions, options) {
|
|
1568
1676
|
const keys = Array.isArray(keysOrOptions) ? keysOrOptions : undefined;
|
|
1569
|
-
options =
|
|
1677
|
+
options =
|
|
1678
|
+
options || (keys ? undefined : keysOrOptions);
|
|
1570
1679
|
const wantResults = options ? options.allKeys : undefined;
|
|
1571
|
-
return this._trans('readwrite', trans => {
|
|
1680
|
+
return this._trans('readwrite', (trans) => {
|
|
1572
1681
|
const { auto, keyPath } = this.schema.primKey;
|
|
1573
1682
|
if (keyPath && keys)
|
|
1574
|
-
throw new exceptions.InvalidArgument(
|
|
1683
|
+
throw new exceptions.InvalidArgument('bulkPut(): keys argument invalid on tables with inbound keys');
|
|
1575
1684
|
if (keys && keys.length !== objects.length)
|
|
1576
|
-
throw new exceptions.InvalidArgument(
|
|
1685
|
+
throw new exceptions.InvalidArgument('Arguments objects and keys must have the same length');
|
|
1577
1686
|
const numObjects = objects.length;
|
|
1578
|
-
let objectsToPut = keyPath && auto
|
|
1579
|
-
objects.map(workaroundForUndefinedPrimKey(keyPath))
|
|
1580
|
-
objects;
|
|
1581
|
-
return this.core
|
|
1687
|
+
let objectsToPut = keyPath && auto
|
|
1688
|
+
? objects.map(workaroundForUndefinedPrimKey(keyPath))
|
|
1689
|
+
: objects;
|
|
1690
|
+
return this.core
|
|
1691
|
+
.mutate({
|
|
1692
|
+
trans,
|
|
1693
|
+
type: 'put',
|
|
1694
|
+
keys: keys,
|
|
1695
|
+
values: objectsToPut,
|
|
1696
|
+
wantResults,
|
|
1697
|
+
})
|
|
1582
1698
|
.then(({ numFailures, results, lastResult, failures }) => {
|
|
1583
1699
|
const result = wantResults ? results : lastResult;
|
|
1584
1700
|
if (numFailures === 0)
|
|
@@ -1624,8 +1740,8 @@ class Table {
|
|
|
1624
1740
|
values: resultObjs,
|
|
1625
1741
|
updates: {
|
|
1626
1742
|
keys,
|
|
1627
|
-
changeSpecs
|
|
1628
|
-
}
|
|
1743
|
+
changeSpecs,
|
|
1744
|
+
},
|
|
1629
1745
|
})
|
|
1630
1746
|
.then(({ numFailures, failures }) => {
|
|
1631
1747
|
if (numFailures === 0)
|
|
@@ -1645,9 +1761,10 @@ class Table {
|
|
|
1645
1761
|
}
|
|
1646
1762
|
bulkDelete(keys) {
|
|
1647
1763
|
const numKeys = keys.length;
|
|
1648
|
-
return this._trans('readwrite', trans => {
|
|
1649
|
-
return this.core
|
|
1650
|
-
.
|
|
1764
|
+
return this._trans('readwrite', (trans) => {
|
|
1765
|
+
return this.core
|
|
1766
|
+
.mutate({ trans, type: 'delete', keys: keys })
|
|
1767
|
+
.then((res) => builtInDeletionTrigger(this, keys, res));
|
|
1651
1768
|
}).then(({ numFailures, lastResult, failures }) => {
|
|
1652
1769
|
if (numFailures === 0)
|
|
1653
1770
|
return lastResult;
|
|
@@ -1666,7 +1783,7 @@ function Events(ctx) {
|
|
|
1666
1783
|
evs[eventName].subscribe.apply(null, args);
|
|
1667
1784
|
return ctx;
|
|
1668
1785
|
}
|
|
1669
|
-
else if (typeof
|
|
1786
|
+
else if (typeof eventName === 'string') {
|
|
1670
1787
|
return evs[eventName];
|
|
1671
1788
|
}
|
|
1672
1789
|
};
|
|
@@ -1692,9 +1809,11 @@ function Events(ctx) {
|
|
|
1692
1809
|
}
|
|
1693
1810
|
},
|
|
1694
1811
|
unsubscribe: function (cb) {
|
|
1695
|
-
context.subscribers = context.subscribers.filter(function (fn) {
|
|
1812
|
+
context.subscribers = context.subscribers.filter(function (fn) {
|
|
1813
|
+
return fn !== cb;
|
|
1814
|
+
});
|
|
1696
1815
|
context.fire = context.subscribers.reduce(chainFunction, defaultFunction);
|
|
1697
|
-
}
|
|
1816
|
+
},
|
|
1698
1817
|
};
|
|
1699
1818
|
evs[eventName] = rv[eventName] = context;
|
|
1700
1819
|
return context;
|
|
@@ -1718,7 +1837,7 @@ function Events(ctx) {
|
|
|
1718
1837
|
});
|
|
1719
1838
|
}
|
|
1720
1839
|
else
|
|
1721
|
-
throw new exceptions.InvalidArgument(
|
|
1840
|
+
throw new exceptions.InvalidArgument('Invalid event config');
|
|
1722
1841
|
});
|
|
1723
1842
|
}
|
|
1724
1843
|
}
|
|
@@ -1734,18 +1853,20 @@ function createTableConstructor(db) {
|
|
|
1734
1853
|
this._tx = trans;
|
|
1735
1854
|
this.name = name;
|
|
1736
1855
|
this.schema = tableSchema;
|
|
1737
|
-
this.hook = db._allTables[name]
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1856
|
+
this.hook = db._allTables[name]
|
|
1857
|
+
? db._allTables[name].hook
|
|
1858
|
+
: Events(null, {
|
|
1859
|
+
creating: [hookCreatingChain, nop],
|
|
1860
|
+
reading: [pureFunctionChain, mirror],
|
|
1861
|
+
updating: [hookUpdatingChain, nop],
|
|
1862
|
+
deleting: [hookDeletingChain, nop],
|
|
1863
|
+
});
|
|
1743
1864
|
});
|
|
1744
1865
|
}
|
|
1745
1866
|
|
|
1746
1867
|
function isPlainKeyRange(ctx, ignoreLimitFilter) {
|
|
1747
|
-
return !(ctx.filter || ctx.algorithm || ctx.or) &&
|
|
1748
|
-
(ignoreLimitFilter ? ctx.justLimit : !ctx.replayFilter);
|
|
1868
|
+
return (!(ctx.filter || ctx.algorithm || ctx.or) &&
|
|
1869
|
+
(ignoreLimitFilter ? ctx.justLimit : !ctx.replayFilter));
|
|
1749
1870
|
}
|
|
1750
1871
|
function addFilter(ctx, fn) {
|
|
1751
1872
|
ctx.filter = combine(ctx.filter, fn);
|
|
@@ -1763,7 +1884,11 @@ function getIndexOrStore(ctx, coreSchema) {
|
|
|
1763
1884
|
return coreSchema.primaryKey;
|
|
1764
1885
|
const index = coreSchema.getIndexByKeyPath(ctx.index);
|
|
1765
1886
|
if (!index)
|
|
1766
|
-
throw new exceptions.Schema(
|
|
1887
|
+
throw new exceptions.Schema('KeyPath ' +
|
|
1888
|
+
ctx.index +
|
|
1889
|
+
' on object store ' +
|
|
1890
|
+
coreSchema.name +
|
|
1891
|
+
' is not indexed');
|
|
1767
1892
|
return index;
|
|
1768
1893
|
}
|
|
1769
1894
|
function openCursor(ctx, coreTable, trans) {
|
|
@@ -1775,19 +1900,22 @@ function openCursor(ctx, coreTable, trans) {
|
|
|
1775
1900
|
unique: !!ctx.unique,
|
|
1776
1901
|
query: {
|
|
1777
1902
|
index,
|
|
1778
|
-
range: ctx.range
|
|
1779
|
-
}
|
|
1903
|
+
range: ctx.range,
|
|
1904
|
+
},
|
|
1780
1905
|
});
|
|
1781
1906
|
}
|
|
1782
1907
|
function iter(ctx, fn, coreTrans, coreTable) {
|
|
1783
|
-
const filter = ctx.replayFilter
|
|
1908
|
+
const filter = ctx.replayFilter
|
|
1909
|
+
? combine(ctx.filter, ctx.replayFilter())
|
|
1910
|
+
: ctx.filter;
|
|
1784
1911
|
if (!ctx.or) {
|
|
1785
1912
|
return iterate(openCursor(ctx, coreTable, coreTrans), combine(ctx.algorithm, filter), fn, !ctx.keysOnly && ctx.valueMapper);
|
|
1786
1913
|
}
|
|
1787
1914
|
else {
|
|
1788
1915
|
const set = {};
|
|
1789
1916
|
const union = (item, cursor, advance) => {
|
|
1790
|
-
if (!filter ||
|
|
1917
|
+
if (!filter ||
|
|
1918
|
+
filter(cursor, advance, (result) => cursor.stop(result), (err) => cursor.fail(err))) {
|
|
1791
1919
|
var primaryKey = cursor.primaryKey;
|
|
1792
1920
|
var key = '' + primaryKey;
|
|
1793
1921
|
if (key === '[object ArrayBuffer]')
|
|
@@ -1800,19 +1928,26 @@ function iter(ctx, fn, coreTrans, coreTable) {
|
|
|
1800
1928
|
};
|
|
1801
1929
|
return Promise.all([
|
|
1802
1930
|
ctx.or._iterate(union, coreTrans),
|
|
1803
|
-
iterate(openCursor(ctx, coreTable, coreTrans), ctx.algorithm, union, !ctx.keysOnly && ctx.valueMapper)
|
|
1931
|
+
iterate(openCursor(ctx, coreTable, coreTrans), ctx.algorithm, union, !ctx.keysOnly && ctx.valueMapper),
|
|
1804
1932
|
]);
|
|
1805
1933
|
}
|
|
1806
1934
|
}
|
|
1807
1935
|
function iterate(cursorPromise, filter, fn, valueMapper) {
|
|
1808
1936
|
var mappedFn = valueMapper ? (x, c, a) => fn(valueMapper(x), c, a) : fn;
|
|
1809
1937
|
var wrappedFn = wrap(mappedFn);
|
|
1810
|
-
return cursorPromise.then(cursor => {
|
|
1938
|
+
return cursorPromise.then((cursor) => {
|
|
1811
1939
|
if (cursor) {
|
|
1812
1940
|
return cursor.start(() => {
|
|
1813
1941
|
var c = () => cursor.continue();
|
|
1814
|
-
if (!filter ||
|
|
1815
|
-
|
|
1942
|
+
if (!filter ||
|
|
1943
|
+
filter(cursor, (advancer) => (c = advancer), (val) => {
|
|
1944
|
+
cursor.stop(val);
|
|
1945
|
+
c = nop;
|
|
1946
|
+
}, (e) => {
|
|
1947
|
+
cursor.fail(e);
|
|
1948
|
+
c = nop;
|
|
1949
|
+
}))
|
|
1950
|
+
wrappedFn(cursor.value, cursor, (advancer) => (c = advancer));
|
|
1816
1951
|
c();
|
|
1817
1952
|
});
|
|
1818
1953
|
}
|
|
@@ -1822,15 +1957,15 @@ function iterate(cursorPromise, filter, fn, valueMapper) {
|
|
|
1822
1957
|
class Collection {
|
|
1823
1958
|
_read(fn, cb) {
|
|
1824
1959
|
var ctx = this._ctx;
|
|
1825
|
-
return ctx.error
|
|
1826
|
-
ctx.table._trans(null, rejection.bind(null, ctx.error))
|
|
1827
|
-
ctx.table._trans('readonly', fn).then(cb);
|
|
1960
|
+
return ctx.error
|
|
1961
|
+
? ctx.table._trans(null, rejection.bind(null, ctx.error))
|
|
1962
|
+
: ctx.table._trans('readonly', fn).then(cb);
|
|
1828
1963
|
}
|
|
1829
1964
|
_write(fn) {
|
|
1830
1965
|
var ctx = this._ctx;
|
|
1831
|
-
return ctx.error
|
|
1832
|
-
ctx.table._trans(null, rejection.bind(null, ctx.error))
|
|
1833
|
-
ctx.table._trans('readwrite', fn,
|
|
1966
|
+
return ctx.error
|
|
1967
|
+
? ctx.table._trans(null, rejection.bind(null, ctx.error))
|
|
1968
|
+
: ctx.table._trans('readwrite', fn, 'locked');
|
|
1834
1969
|
}
|
|
1835
1970
|
_addAlgorithm(fn) {
|
|
1836
1971
|
var ctx = this._ctx;
|
|
@@ -1852,25 +1987,29 @@ class Collection {
|
|
|
1852
1987
|
}
|
|
1853
1988
|
each(fn) {
|
|
1854
1989
|
var ctx = this._ctx;
|
|
1855
|
-
return this._read(trans => iter(ctx, fn, trans, ctx.table.core));
|
|
1990
|
+
return this._read((trans) => iter(ctx, fn, trans, ctx.table.core));
|
|
1856
1991
|
}
|
|
1857
1992
|
count(cb) {
|
|
1858
|
-
return this._read(trans => {
|
|
1993
|
+
return this._read((trans) => {
|
|
1859
1994
|
const ctx = this._ctx;
|
|
1860
1995
|
const coreTable = ctx.table.core;
|
|
1861
1996
|
if (isPlainKeyRange(ctx, true)) {
|
|
1862
|
-
return coreTable
|
|
1997
|
+
return coreTable
|
|
1998
|
+
.count({
|
|
1863
1999
|
trans,
|
|
1864
2000
|
query: {
|
|
1865
2001
|
index: getIndexOrStore(ctx, coreTable.schema),
|
|
1866
|
-
range: ctx.range
|
|
1867
|
-
}
|
|
1868
|
-
})
|
|
2002
|
+
range: ctx.range,
|
|
2003
|
+
},
|
|
2004
|
+
})
|
|
2005
|
+
.then((count) => Math.min(count, ctx.limit));
|
|
1869
2006
|
}
|
|
1870
2007
|
else {
|
|
1871
2008
|
var count = 0;
|
|
1872
|
-
return iter(ctx, () => {
|
|
1873
|
-
|
|
2009
|
+
return iter(ctx, () => {
|
|
2010
|
+
++count;
|
|
2011
|
+
return false;
|
|
2012
|
+
}, trans, coreTable).then(() => count);
|
|
1874
2013
|
}
|
|
1875
2014
|
}).then(cb);
|
|
1876
2015
|
}
|
|
@@ -1881,7 +2020,7 @@ class Collection {
|
|
|
1881
2020
|
return getval(obj[parts[i]], i - 1);
|
|
1882
2021
|
return obj[lastPart];
|
|
1883
2022
|
}
|
|
1884
|
-
var order = this._ctx.dir ===
|
|
2023
|
+
var order = this._ctx.dir === 'next' ? 1 : -1;
|
|
1885
2024
|
function sorter(a, b) {
|
|
1886
2025
|
var aVal = getval(a, lastIndex), bVal = getval(b, lastIndex);
|
|
1887
2026
|
return cmp(aVal, bVal) * order;
|
|
@@ -1891,25 +2030,27 @@ class Collection {
|
|
|
1891
2030
|
}).then(cb);
|
|
1892
2031
|
}
|
|
1893
2032
|
toArray(cb) {
|
|
1894
|
-
return this._read(trans => {
|
|
2033
|
+
return this._read((trans) => {
|
|
1895
2034
|
var ctx = this._ctx;
|
|
1896
2035
|
if (isPlainKeyRange(ctx, true) && ctx.limit > 0) {
|
|
1897
2036
|
const { valueMapper } = ctx;
|
|
1898
2037
|
const index = getIndexOrStore(ctx, ctx.table.core.schema);
|
|
1899
|
-
return ctx.table.core
|
|
2038
|
+
return ctx.table.core
|
|
2039
|
+
.query({
|
|
1900
2040
|
trans,
|
|
1901
2041
|
limit: ctx.limit,
|
|
1902
2042
|
values: true,
|
|
1903
2043
|
direction: ctx.dir === 'prev' ? 'prev' : undefined,
|
|
1904
2044
|
query: {
|
|
1905
2045
|
index,
|
|
1906
|
-
range: ctx.range
|
|
1907
|
-
}
|
|
1908
|
-
})
|
|
2046
|
+
range: ctx.range,
|
|
2047
|
+
},
|
|
2048
|
+
})
|
|
2049
|
+
.then(({ result }) => valueMapper ? result.map(valueMapper) : result);
|
|
1909
2050
|
}
|
|
1910
2051
|
else {
|
|
1911
2052
|
const a = [];
|
|
1912
|
-
return iter(ctx, item => a.push(item), trans, ctx.table.core).then(() => a);
|
|
2053
|
+
return iter(ctx, (item) => a.push(item), trans, ctx.table.core).then(() => a);
|
|
1913
2054
|
}
|
|
1914
2055
|
}, cb);
|
|
1915
2056
|
}
|
|
@@ -1939,7 +2080,7 @@ class Collection {
|
|
|
1939
2080
|
else {
|
|
1940
2081
|
addReplayFilter(ctx, () => {
|
|
1941
2082
|
var offsetLeft = offset;
|
|
1942
|
-
return () =>
|
|
2083
|
+
return () => --offsetLeft < 0;
|
|
1943
2084
|
});
|
|
1944
2085
|
}
|
|
1945
2086
|
return this;
|
|
@@ -1969,7 +2110,11 @@ class Collection {
|
|
|
1969
2110
|
return this;
|
|
1970
2111
|
}
|
|
1971
2112
|
first(cb) {
|
|
1972
|
-
return this.limit(1)
|
|
2113
|
+
return this.limit(1)
|
|
2114
|
+
.toArray(function (a) {
|
|
2115
|
+
return a[0];
|
|
2116
|
+
})
|
|
2117
|
+
.then(cb);
|
|
1973
2118
|
}
|
|
1974
2119
|
last(cb) {
|
|
1975
2120
|
return this.reverse().first(cb);
|
|
@@ -1988,7 +2133,7 @@ class Collection {
|
|
|
1988
2133
|
return new this.db.WhereClause(this._ctx.table, indexName, this);
|
|
1989
2134
|
}
|
|
1990
2135
|
reverse() {
|
|
1991
|
-
this._ctx.dir =
|
|
2136
|
+
this._ctx.dir = this._ctx.dir === 'prev' ? 'next' : 'prev';
|
|
1992
2137
|
if (this._ondirectionchange)
|
|
1993
2138
|
this._ondirectionchange(this._ctx.dir);
|
|
1994
2139
|
return this;
|
|
@@ -1999,16 +2144,20 @@ class Collection {
|
|
|
1999
2144
|
eachKey(cb) {
|
|
2000
2145
|
var ctx = this._ctx;
|
|
2001
2146
|
ctx.keysOnly = !ctx.isMatch;
|
|
2002
|
-
return this.each(function (val, cursor) {
|
|
2147
|
+
return this.each(function (val, cursor) {
|
|
2148
|
+
cb(cursor.key, cursor);
|
|
2149
|
+
});
|
|
2003
2150
|
}
|
|
2004
2151
|
eachUniqueKey(cb) {
|
|
2005
|
-
this._ctx.unique =
|
|
2152
|
+
this._ctx.unique = 'unique';
|
|
2006
2153
|
return this.eachKey(cb);
|
|
2007
2154
|
}
|
|
2008
2155
|
eachPrimaryKey(cb) {
|
|
2009
2156
|
var ctx = this._ctx;
|
|
2010
2157
|
ctx.keysOnly = !ctx.isMatch;
|
|
2011
|
-
return this.each(function (val, cursor) {
|
|
2158
|
+
return this.each(function (val, cursor) {
|
|
2159
|
+
cb(cursor.primaryKey, cursor);
|
|
2160
|
+
});
|
|
2012
2161
|
}
|
|
2013
2162
|
keys(cb) {
|
|
2014
2163
|
var ctx = this._ctx;
|
|
@@ -2016,14 +2165,16 @@ class Collection {
|
|
|
2016
2165
|
var a = [];
|
|
2017
2166
|
return this.each(function (item, cursor) {
|
|
2018
2167
|
a.push(cursor.key);
|
|
2019
|
-
})
|
|
2168
|
+
})
|
|
2169
|
+
.then(function () {
|
|
2020
2170
|
return a;
|
|
2021
|
-
})
|
|
2171
|
+
})
|
|
2172
|
+
.then(cb);
|
|
2022
2173
|
}
|
|
2023
2174
|
primaryKeys(cb) {
|
|
2024
2175
|
var ctx = this._ctx;
|
|
2025
2176
|
if (isPlainKeyRange(ctx, true) && ctx.limit > 0) {
|
|
2026
|
-
return this._read(trans => {
|
|
2177
|
+
return this._read((trans) => {
|
|
2027
2178
|
var index = getIndexOrStore(ctx, ctx.table.core.schema);
|
|
2028
2179
|
return ctx.table.core.query({
|
|
2029
2180
|
trans,
|
|
@@ -2032,25 +2183,33 @@ class Collection {
|
|
|
2032
2183
|
direction: ctx.dir === 'prev' ? 'prev' : undefined,
|
|
2033
2184
|
query: {
|
|
2034
2185
|
index,
|
|
2035
|
-
range: ctx.range
|
|
2036
|
-
}
|
|
2186
|
+
range: ctx.range,
|
|
2187
|
+
},
|
|
2037
2188
|
});
|
|
2038
|
-
})
|
|
2189
|
+
})
|
|
2190
|
+
.then(({ result }) => result)
|
|
2191
|
+
.then(cb);
|
|
2039
2192
|
}
|
|
2040
2193
|
ctx.keysOnly = !ctx.isMatch;
|
|
2041
2194
|
var a = [];
|
|
2042
2195
|
return this.each(function (item, cursor) {
|
|
2043
2196
|
a.push(cursor.primaryKey);
|
|
2044
|
-
})
|
|
2197
|
+
})
|
|
2198
|
+
.then(function () {
|
|
2045
2199
|
return a;
|
|
2046
|
-
})
|
|
2200
|
+
})
|
|
2201
|
+
.then(cb);
|
|
2047
2202
|
}
|
|
2048
2203
|
uniqueKeys(cb) {
|
|
2049
|
-
this._ctx.unique =
|
|
2204
|
+
this._ctx.unique = 'unique';
|
|
2050
2205
|
return this.keys(cb);
|
|
2051
2206
|
}
|
|
2052
2207
|
firstKey(cb) {
|
|
2053
|
-
return this.limit(1)
|
|
2208
|
+
return this.limit(1)
|
|
2209
|
+
.keys(function (a) {
|
|
2210
|
+
return a[0];
|
|
2211
|
+
})
|
|
2212
|
+
.then(cb);
|
|
2054
2213
|
}
|
|
2055
2214
|
lastKey(cb) {
|
|
2056
2215
|
return this.reverse().firstKey(cb);
|
|
@@ -2070,13 +2229,13 @@ class Collection {
|
|
|
2070
2229
|
}
|
|
2071
2230
|
modify(changes) {
|
|
2072
2231
|
var ctx = this._ctx;
|
|
2073
|
-
return this._write(trans => {
|
|
2232
|
+
return this._write((trans) => {
|
|
2074
2233
|
var modifyer;
|
|
2075
2234
|
if (typeof changes === 'function') {
|
|
2076
2235
|
modifyer = changes;
|
|
2077
2236
|
}
|
|
2078
2237
|
else {
|
|
2079
|
-
modifyer = item => applyUpdateSpec(item, changes);
|
|
2238
|
+
modifyer = (item) => applyUpdateSpec(item, changes);
|
|
2080
2239
|
}
|
|
2081
2240
|
const coreTable = ctx.table.core;
|
|
2082
2241
|
const { outbound, extractKey } = coreTable.schema.primaryKey;
|
|
@@ -2084,7 +2243,8 @@ class Collection {
|
|
|
2084
2243
|
const modifyChunkSize = this.db._options.modifyChunkSize;
|
|
2085
2244
|
if (modifyChunkSize) {
|
|
2086
2245
|
if (typeof modifyChunkSize == 'object') {
|
|
2087
|
-
limit =
|
|
2246
|
+
limit =
|
|
2247
|
+
modifyChunkSize[coreTable.name] || modifyChunkSize['*'] || 200;
|
|
2088
2248
|
}
|
|
2089
2249
|
else {
|
|
2090
2250
|
limit = modifyChunkSize;
|
|
@@ -2101,21 +2261,25 @@ class Collection {
|
|
|
2101
2261
|
}
|
|
2102
2262
|
};
|
|
2103
2263
|
const isUnconditionalDelete = changes === deleteCallback;
|
|
2104
|
-
return this.clone()
|
|
2264
|
+
return this.clone()
|
|
2265
|
+
.primaryKeys()
|
|
2266
|
+
.then((keys) => {
|
|
2105
2267
|
const criteria = isPlainKeyRange(ctx) &&
|
|
2106
2268
|
ctx.limit === Infinity &&
|
|
2107
2269
|
(typeof changes !== 'function' || isUnconditionalDelete) && {
|
|
2108
2270
|
index: ctx.index,
|
|
2109
|
-
range: ctx.range
|
|
2271
|
+
range: ctx.range,
|
|
2110
2272
|
};
|
|
2111
2273
|
const nextChunk = (offset) => {
|
|
2112
2274
|
const count = Math.min(limit, keys.length - offset);
|
|
2113
2275
|
const keysInChunk = keys.slice(offset, offset + count);
|
|
2114
|
-
return (isUnconditionalDelete
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2276
|
+
return (isUnconditionalDelete
|
|
2277
|
+
? Promise.resolve([])
|
|
2278
|
+
: coreTable.getMany({
|
|
2279
|
+
trans,
|
|
2280
|
+
keys: keysInChunk,
|
|
2281
|
+
cache: 'immutable',
|
|
2282
|
+
})).then((values) => {
|
|
2119
2283
|
const addValues = [];
|
|
2120
2284
|
const putValues = [];
|
|
2121
2285
|
const putKeys = outbound ? [] : null;
|
|
@@ -2125,13 +2289,14 @@ class Collection {
|
|
|
2125
2289
|
const origValue = values[i];
|
|
2126
2290
|
const ctx = {
|
|
2127
2291
|
value: deepClone(origValue),
|
|
2128
|
-
primKey: keys[offset + i]
|
|
2292
|
+
primKey: keys[offset + i],
|
|
2129
2293
|
};
|
|
2130
2294
|
if (modifyer.call(ctx, ctx.value, ctx) !== false) {
|
|
2131
2295
|
if (ctx.value == null) {
|
|
2132
2296
|
deleteKeys.push(keys[offset + i]);
|
|
2133
2297
|
}
|
|
2134
|
-
else if (!outbound &&
|
|
2298
|
+
else if (!outbound &&
|
|
2299
|
+
cmp(extractKey(origValue), extractKey(ctx.value)) !== 0) {
|
|
2135
2300
|
deleteKeys.push(keys[offset + i]);
|
|
2136
2301
|
addValues.push(ctx.value);
|
|
2137
2302
|
}
|
|
@@ -2143,38 +2308,47 @@ class Collection {
|
|
|
2143
2308
|
}
|
|
2144
2309
|
}
|
|
2145
2310
|
return Promise.resolve(addValues.length > 0 &&
|
|
2146
|
-
coreTable
|
|
2147
|
-
.
|
|
2311
|
+
coreTable
|
|
2312
|
+
.mutate({ trans, type: 'add', values: addValues })
|
|
2313
|
+
.then((res) => {
|
|
2148
2314
|
for (let pos in res.failures) {
|
|
2149
2315
|
deleteKeys.splice(parseInt(pos), 1);
|
|
2150
2316
|
}
|
|
2151
2317
|
applyMutateResult(addValues.length, res);
|
|
2152
|
-
}))
|
|
2153
|
-
|
|
2318
|
+
}))
|
|
2319
|
+
.then(() => (putValues.length > 0 ||
|
|
2320
|
+
(criteria && typeof changes === 'object')) &&
|
|
2321
|
+
coreTable
|
|
2322
|
+
.mutate({
|
|
2154
2323
|
trans,
|
|
2155
2324
|
type: 'put',
|
|
2156
2325
|
keys: putKeys,
|
|
2157
2326
|
values: putValues,
|
|
2158
2327
|
criteria,
|
|
2159
|
-
changeSpec: typeof changes !== 'function'
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2328
|
+
changeSpec: typeof changes !== 'function' && changes,
|
|
2329
|
+
isAdditionalChunk: offset > 0,
|
|
2330
|
+
})
|
|
2331
|
+
.then((res) => applyMutateResult(putValues.length, res)))
|
|
2332
|
+
.then(() => (deleteKeys.length > 0 ||
|
|
2333
|
+
(criteria && isUnconditionalDelete)) &&
|
|
2334
|
+
coreTable
|
|
2335
|
+
.mutate({
|
|
2164
2336
|
trans,
|
|
2165
2337
|
type: 'delete',
|
|
2166
2338
|
keys: deleteKeys,
|
|
2167
2339
|
criteria,
|
|
2168
|
-
isAdditionalChunk: offset > 0
|
|
2169
|
-
})
|
|
2170
|
-
.then(res =>
|
|
2171
|
-
|
|
2340
|
+
isAdditionalChunk: offset > 0,
|
|
2341
|
+
})
|
|
2342
|
+
.then((res) => builtInDeletionTrigger(ctx.table, deleteKeys, res))
|
|
2343
|
+
.then((res) => applyMutateResult(deleteKeys.length, res)))
|
|
2344
|
+
.then(() => {
|
|
2345
|
+
return (keys.length > offset + count && nextChunk(offset + limit));
|
|
2172
2346
|
});
|
|
2173
2347
|
});
|
|
2174
2348
|
};
|
|
2175
2349
|
return nextChunk(0).then(() => {
|
|
2176
2350
|
if (totalFailures.length > 0)
|
|
2177
|
-
throw new ModifyError(
|
|
2351
|
+
throw new ModifyError('Error modifying one or more objects', totalFailures, successCount, failedKeys);
|
|
2178
2352
|
return keys.length;
|
|
2179
2353
|
});
|
|
2180
2354
|
});
|
|
@@ -2186,14 +2360,17 @@ class Collection {
|
|
|
2186
2360
|
!ctx.table.schema.yProps &&
|
|
2187
2361
|
(ctx.isPrimKey || range.type === 3 ))
|
|
2188
2362
|
{
|
|
2189
|
-
return this._write(trans => {
|
|
2363
|
+
return this._write((trans) => {
|
|
2190
2364
|
const { primaryKey } = ctx.table.core.schema;
|
|
2191
2365
|
const coreRange = range;
|
|
2192
|
-
return ctx.table.core
|
|
2193
|
-
|
|
2366
|
+
return ctx.table.core
|
|
2367
|
+
.count({ trans, query: { index: primaryKey, range: coreRange } })
|
|
2368
|
+
.then((count) => {
|
|
2369
|
+
return ctx.table.core
|
|
2370
|
+
.mutate({ trans, type: 'deleteRange', range: coreRange })
|
|
2194
2371
|
.then(({ failures, numFailures }) => {
|
|
2195
2372
|
if (numFailures)
|
|
2196
|
-
throw new ModifyError(
|
|
2373
|
+
throw new ModifyError('Could not delete some values', Object.keys(failures).map((pos) => failures[pos]), count - numFailures);
|
|
2197
2374
|
return count - numFailures;
|
|
2198
2375
|
});
|
|
2199
2376
|
});
|
|
@@ -2202,7 +2379,7 @@ class Collection {
|
|
|
2202
2379
|
return this.modify(deleteCallback);
|
|
2203
2380
|
}
|
|
2204
2381
|
}
|
|
2205
|
-
const deleteCallback = (value, ctx) => ctx.value = null;
|
|
2382
|
+
const deleteCallback = (value, ctx) => (ctx.value = null);
|
|
2206
2383
|
|
|
2207
2384
|
function createCollectionConstructor(db) {
|
|
2208
2385
|
return makeClassConstructor(Collection.prototype, function Collection(whereClause, keyRangeGenerator) {
|
|
@@ -2221,11 +2398,13 @@ function createCollectionConstructor(db) {
|
|
|
2221
2398
|
this._ctx = {
|
|
2222
2399
|
table: table,
|
|
2223
2400
|
index: whereCtx.index,
|
|
2224
|
-
isPrimKey:
|
|
2401
|
+
isPrimKey: !whereCtx.index ||
|
|
2402
|
+
(table.schema.primKey.keyPath &&
|
|
2403
|
+
whereCtx.index === table.schema.primKey.name),
|
|
2225
2404
|
range: keyRange,
|
|
2226
2405
|
keysOnly: false,
|
|
2227
|
-
dir:
|
|
2228
|
-
unique:
|
|
2406
|
+
dir: 'next',
|
|
2407
|
+
unique: '',
|
|
2229
2408
|
algorithm: null,
|
|
2230
2409
|
filter: null,
|
|
2231
2410
|
replayFilter: null,
|
|
@@ -2235,7 +2414,7 @@ function createCollectionConstructor(db) {
|
|
|
2235
2414
|
limit: Infinity,
|
|
2236
2415
|
error: error,
|
|
2237
2416
|
or: whereCtx.or,
|
|
2238
|
-
valueMapper: readingHook !== mirror ? readingHook : null
|
|
2417
|
+
valueMapper: readingHook !== mirror ? readingHook : null,
|
|
2239
2418
|
};
|
|
2240
2419
|
});
|
|
2241
2420
|
}
|
|
@@ -2248,24 +2427,24 @@ function simpleCompareReverse(a, b) {
|
|
|
2248
2427
|
}
|
|
2249
2428
|
|
|
2250
2429
|
function fail(collectionOrWhereClause, err, T) {
|
|
2251
|
-
var collection = collectionOrWhereClause instanceof WhereClause
|
|
2252
|
-
new collectionOrWhereClause.Collection(collectionOrWhereClause)
|
|
2253
|
-
collectionOrWhereClause;
|
|
2430
|
+
var collection = collectionOrWhereClause instanceof WhereClause
|
|
2431
|
+
? new collectionOrWhereClause.Collection(collectionOrWhereClause)
|
|
2432
|
+
: collectionOrWhereClause;
|
|
2254
2433
|
collection._ctx.error = T ? new T(err) : new TypeError(err);
|
|
2255
2434
|
return collection;
|
|
2256
2435
|
}
|
|
2257
2436
|
function emptyCollection(whereClause) {
|
|
2258
|
-
return new whereClause.Collection(whereClause, () => rangeEqual(
|
|
2437
|
+
return new whereClause.Collection(whereClause, () => rangeEqual('')).limit(0);
|
|
2259
2438
|
}
|
|
2260
2439
|
function upperFactory(dir) {
|
|
2261
|
-
return dir ===
|
|
2262
|
-
(s) => s.toUpperCase()
|
|
2263
|
-
(s) => s.toLowerCase();
|
|
2440
|
+
return dir === 'next'
|
|
2441
|
+
? (s) => s.toUpperCase()
|
|
2442
|
+
: (s) => s.toLowerCase();
|
|
2264
2443
|
}
|
|
2265
2444
|
function lowerFactory(dir) {
|
|
2266
|
-
return dir ===
|
|
2267
|
-
(s) => s.toLowerCase()
|
|
2268
|
-
(s) => s.toUpperCase();
|
|
2445
|
+
return dir === 'next'
|
|
2446
|
+
? (s) => s.toLowerCase()
|
|
2447
|
+
: (s) => s.toUpperCase();
|
|
2269
2448
|
}
|
|
2270
2449
|
function nextCasing(key, lowerKey, upperNeedle, lowerNeedle, cmp, dir) {
|
|
2271
2450
|
var length = Math.min(key.length, lowerNeedle.length);
|
|
@@ -2284,32 +2463,40 @@ function nextCasing(key, lowerKey, upperNeedle, lowerNeedle, cmp, dir) {
|
|
|
2284
2463
|
if (cmp(key[i], lwrKeyChar) < 0)
|
|
2285
2464
|
llp = i;
|
|
2286
2465
|
}
|
|
2287
|
-
if (length < lowerNeedle.length && dir ===
|
|
2466
|
+
if (length < lowerNeedle.length && dir === 'next')
|
|
2288
2467
|
return key + upperNeedle.substr(key.length);
|
|
2289
|
-
if (length < key.length && dir ===
|
|
2468
|
+
if (length < key.length && dir === 'prev')
|
|
2290
2469
|
return key.substr(0, upperNeedle.length);
|
|
2291
|
-
return
|
|
2470
|
+
return llp < 0
|
|
2471
|
+
? null
|
|
2472
|
+
: key.substr(0, llp) + lowerNeedle[llp] + upperNeedle.substr(llp + 1);
|
|
2292
2473
|
}
|
|
2293
2474
|
function addIgnoreCaseAlgorithm(whereClause, match, needles, suffix) {
|
|
2294
2475
|
var upper, lower, compare, upperNeedles, lowerNeedles, direction, nextKeySuffix, needlesLen = needles.length;
|
|
2295
|
-
if (!needles.every(s => typeof s === 'string')) {
|
|
2476
|
+
if (!needles.every((s) => typeof s === 'string')) {
|
|
2296
2477
|
return fail(whereClause, STRING_EXPECTED);
|
|
2297
2478
|
}
|
|
2298
2479
|
function initDirection(dir) {
|
|
2299
2480
|
upper = upperFactory(dir);
|
|
2300
2481
|
lower = lowerFactory(dir);
|
|
2301
|
-
compare =
|
|
2302
|
-
var needleBounds = needles
|
|
2482
|
+
compare = dir === 'next' ? simpleCompare : simpleCompareReverse;
|
|
2483
|
+
var needleBounds = needles
|
|
2484
|
+
.map(function (needle) {
|
|
2303
2485
|
return { lower: lower(needle), upper: upper(needle) };
|
|
2304
|
-
})
|
|
2486
|
+
})
|
|
2487
|
+
.sort(function (a, b) {
|
|
2305
2488
|
return compare(a.lower, b.lower);
|
|
2306
2489
|
});
|
|
2307
|
-
upperNeedles = needleBounds.map(function (nb) {
|
|
2308
|
-
|
|
2490
|
+
upperNeedles = needleBounds.map(function (nb) {
|
|
2491
|
+
return nb.upper;
|
|
2492
|
+
});
|
|
2493
|
+
lowerNeedles = needleBounds.map(function (nb) {
|
|
2494
|
+
return nb.lower;
|
|
2495
|
+
});
|
|
2309
2496
|
direction = dir;
|
|
2310
|
-
nextKeySuffix =
|
|
2497
|
+
nextKeySuffix = dir === 'next' ? '' : suffix;
|
|
2311
2498
|
}
|
|
2312
|
-
initDirection(
|
|
2499
|
+
initDirection('next');
|
|
2313
2500
|
var c = new whereClause.Collection(whereClause, () => createRange(upperNeedles[0], lowerNeedles[needlesLen - 1] + suffix));
|
|
2314
2501
|
c._ondirectionchange = function (direction) {
|
|
2315
2502
|
initDirection(direction);
|
|
@@ -2329,12 +2516,15 @@ function addIgnoreCaseAlgorithm(whereClause, match, needles, suffix) {
|
|
|
2329
2516
|
var casing = nextCasing(key, lowerKey, upperNeedles[i], lowerNeedles[i], compare, direction);
|
|
2330
2517
|
if (casing === null && lowestPossibleCasing === null)
|
|
2331
2518
|
firstPossibleNeedle = i + 1;
|
|
2332
|
-
else if (lowestPossibleCasing === null ||
|
|
2519
|
+
else if (lowestPossibleCasing === null ||
|
|
2520
|
+
compare(lowestPossibleCasing, casing) > 0) {
|
|
2333
2521
|
lowestPossibleCasing = casing;
|
|
2334
2522
|
}
|
|
2335
2523
|
}
|
|
2336
2524
|
if (lowestPossibleCasing !== null) {
|
|
2337
|
-
advance(function () {
|
|
2525
|
+
advance(function () {
|
|
2526
|
+
cursor.continue(lowestPossibleCasing + nextKeySuffix);
|
|
2527
|
+
});
|
|
2338
2528
|
}
|
|
2339
2529
|
else {
|
|
2340
2530
|
advance(resolve);
|
|
@@ -2350,14 +2540,14 @@ function createRange(lower, upper, lowerOpen, upperOpen) {
|
|
|
2350
2540
|
lower,
|
|
2351
2541
|
upper,
|
|
2352
2542
|
lowerOpen,
|
|
2353
|
-
upperOpen
|
|
2543
|
+
upperOpen,
|
|
2354
2544
|
};
|
|
2355
2545
|
}
|
|
2356
2546
|
function rangeEqual(value) {
|
|
2357
2547
|
return {
|
|
2358
2548
|
type: 1 ,
|
|
2359
2549
|
lower: value,
|
|
2360
|
-
upper: value
|
|
2550
|
+
upper: value,
|
|
2361
2551
|
};
|
|
2362
2552
|
}
|
|
2363
2553
|
|
|
@@ -2369,8 +2559,10 @@ class WhereClause {
|
|
|
2369
2559
|
includeLower = includeLower !== false;
|
|
2370
2560
|
includeUpper = includeUpper === true;
|
|
2371
2561
|
try {
|
|
2372
|
-
if (
|
|
2373
|
-
(this._cmp(lower, upper) === 0 &&
|
|
2562
|
+
if (this._cmp(lower, upper) > 0 ||
|
|
2563
|
+
(this._cmp(lower, upper) === 0 &&
|
|
2564
|
+
(includeLower || includeUpper) &&
|
|
2565
|
+
!(includeLower && includeUpper)))
|
|
2374
2566
|
return emptyCollection(this);
|
|
2375
2567
|
return new this.Collection(this, () => createRange(lower, upper, !includeLower, !includeUpper));
|
|
2376
2568
|
}
|
|
@@ -2409,24 +2601,24 @@ class WhereClause {
|
|
|
2409
2601
|
return this.between(str, str + maxString, true, true);
|
|
2410
2602
|
}
|
|
2411
2603
|
startsWithIgnoreCase(str) {
|
|
2412
|
-
if (str ===
|
|
2604
|
+
if (str === '')
|
|
2413
2605
|
return this.startsWith(str);
|
|
2414
2606
|
return addIgnoreCaseAlgorithm(this, (x, a) => x.indexOf(a[0]) === 0, [str], maxString);
|
|
2415
2607
|
}
|
|
2416
2608
|
equalsIgnoreCase(str) {
|
|
2417
|
-
return addIgnoreCaseAlgorithm(this, (x, a) => x === a[0], [str],
|
|
2609
|
+
return addIgnoreCaseAlgorithm(this, (x, a) => x === a[0], [str], '');
|
|
2418
2610
|
}
|
|
2419
2611
|
anyOfIgnoreCase() {
|
|
2420
2612
|
var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
2421
2613
|
if (set.length === 0)
|
|
2422
2614
|
return emptyCollection(this);
|
|
2423
|
-
return addIgnoreCaseAlgorithm(this, (x, a) => a.indexOf(x) !== -1, set,
|
|
2615
|
+
return addIgnoreCaseAlgorithm(this, (x, a) => a.indexOf(x) !== -1, set, '');
|
|
2424
2616
|
}
|
|
2425
2617
|
startsWithAnyOfIgnoreCase() {
|
|
2426
2618
|
var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
2427
2619
|
if (set.length === 0)
|
|
2428
2620
|
return emptyCollection(this);
|
|
2429
|
-
return addIgnoreCaseAlgorithm(this, (x, a) => a.some(n => x.indexOf(n) === 0), set, maxString);
|
|
2621
|
+
return addIgnoreCaseAlgorithm(this, (x, a) => a.some((n) => x.indexOf(n) === 0), set, maxString);
|
|
2430
2622
|
}
|
|
2431
2623
|
anyOf() {
|
|
2432
2624
|
const set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
@@ -2440,10 +2632,8 @@ class WhereClause {
|
|
|
2440
2632
|
if (set.length === 0)
|
|
2441
2633
|
return emptyCollection(this);
|
|
2442
2634
|
const c = new this.Collection(this, () => createRange(set[0], set[set.length - 1]));
|
|
2443
|
-
c._ondirectionchange = direction => {
|
|
2444
|
-
compare =
|
|
2445
|
-
this._ascending :
|
|
2446
|
-
this._descending);
|
|
2635
|
+
c._ondirectionchange = (direction) => {
|
|
2636
|
+
compare = direction === 'next' ? this._ascending : this._descending;
|
|
2447
2637
|
set.sort(compare);
|
|
2448
2638
|
};
|
|
2449
2639
|
let i = 0;
|
|
@@ -2460,14 +2650,19 @@ class WhereClause {
|
|
|
2460
2650
|
return true;
|
|
2461
2651
|
}
|
|
2462
2652
|
else {
|
|
2463
|
-
advance(() => {
|
|
2653
|
+
advance(() => {
|
|
2654
|
+
cursor.continue(set[i]);
|
|
2655
|
+
});
|
|
2464
2656
|
return false;
|
|
2465
2657
|
}
|
|
2466
2658
|
});
|
|
2467
2659
|
return c;
|
|
2468
2660
|
}
|
|
2469
2661
|
notEqual(value) {
|
|
2470
|
-
return this.inAnyRange([
|
|
2662
|
+
return this.inAnyRange([
|
|
2663
|
+
[minKey, value],
|
|
2664
|
+
[value, this.db._maxKey],
|
|
2665
|
+
], { includeLowers: false, includeUppers: false });
|
|
2471
2666
|
}
|
|
2472
2667
|
noneOf() {
|
|
2473
2668
|
const set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
@@ -2479,20 +2674,21 @@ class WhereClause {
|
|
|
2479
2674
|
catch (e) {
|
|
2480
2675
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
2481
2676
|
}
|
|
2482
|
-
const ranges = set.reduce((res, val) => res ?
|
|
2483
|
-
res.concat([[res[res.length - 1][1], val]]) :
|
|
2484
|
-
[[minKey, val]], null);
|
|
2677
|
+
const ranges = set.reduce((res, val) => res ? res.concat([[res[res.length - 1][1], val]]) : [[minKey, val]], null);
|
|
2485
2678
|
ranges.push([set[set.length - 1], this.db._maxKey]);
|
|
2486
|
-
return this.inAnyRange(ranges, {
|
|
2679
|
+
return this.inAnyRange(ranges, {
|
|
2680
|
+
includeLowers: false,
|
|
2681
|
+
includeUppers: false,
|
|
2682
|
+
});
|
|
2487
2683
|
}
|
|
2488
2684
|
inAnyRange(ranges, options) {
|
|
2489
2685
|
const cmp = this._cmp, ascending = this._ascending, descending = this._descending, min = this._min, max = this._max;
|
|
2490
2686
|
if (ranges.length === 0)
|
|
2491
2687
|
return emptyCollection(this);
|
|
2492
|
-
if (!ranges.every(range => range[0] !== undefined &&
|
|
2688
|
+
if (!ranges.every((range) => range[0] !== undefined &&
|
|
2493
2689
|
range[1] !== undefined &&
|
|
2494
2690
|
ascending(range[0], range[1]) <= 0)) {
|
|
2495
|
-
return fail(this,
|
|
2691
|
+
return fail(this, 'First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower', exceptions.InvalidArgument);
|
|
2496
2692
|
}
|
|
2497
2693
|
const includeLowers = !options || options.includeLowers !== false;
|
|
2498
2694
|
const includeUppers = options && options.includeUppers === true;
|
|
@@ -2511,7 +2707,9 @@ class WhereClause {
|
|
|
2511
2707
|
return ranges;
|
|
2512
2708
|
}
|
|
2513
2709
|
let sortDirection = ascending;
|
|
2514
|
-
function rangeSorter(a, b) {
|
|
2710
|
+
function rangeSorter(a, b) {
|
|
2711
|
+
return sortDirection(a[0], b[0]);
|
|
2712
|
+
}
|
|
2515
2713
|
let set;
|
|
2516
2714
|
try {
|
|
2517
2715
|
set = ranges.reduce(addRange, []);
|
|
@@ -2521,19 +2719,19 @@ class WhereClause {
|
|
|
2521
2719
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
2522
2720
|
}
|
|
2523
2721
|
let rangePos = 0;
|
|
2524
|
-
const keyIsBeyondCurrentEntry = includeUppers
|
|
2525
|
-
key => ascending(key, set[rangePos][1]) > 0
|
|
2526
|
-
key => ascending(key, set[rangePos][1]) >= 0;
|
|
2527
|
-
const keyIsBeforeCurrentEntry = includeLowers
|
|
2528
|
-
key => descending(key, set[rangePos][0]) > 0
|
|
2529
|
-
key => descending(key, set[rangePos][0]) >= 0;
|
|
2722
|
+
const keyIsBeyondCurrentEntry = includeUppers
|
|
2723
|
+
? (key) => ascending(key, set[rangePos][1]) > 0
|
|
2724
|
+
: (key) => ascending(key, set[rangePos][1]) >= 0;
|
|
2725
|
+
const keyIsBeforeCurrentEntry = includeLowers
|
|
2726
|
+
? (key) => descending(key, set[rangePos][0]) > 0
|
|
2727
|
+
: (key) => descending(key, set[rangePos][0]) >= 0;
|
|
2530
2728
|
function keyWithinCurrentRange(key) {
|
|
2531
2729
|
return !keyIsBeyondCurrentEntry(key) && !keyIsBeforeCurrentEntry(key);
|
|
2532
2730
|
}
|
|
2533
2731
|
let checkKey = keyIsBeyondCurrentEntry;
|
|
2534
2732
|
const c = new this.Collection(this, () => createRange(set[0][0], set[set.length - 1][1], !includeLowers, !includeUppers));
|
|
2535
|
-
c._ondirectionchange = direction => {
|
|
2536
|
-
if (direction ===
|
|
2733
|
+
c._ondirectionchange = (direction) => {
|
|
2734
|
+
if (direction === 'next') {
|
|
2537
2735
|
checkKey = keyIsBeyondCurrentEntry;
|
|
2538
2736
|
sortDirection = ascending;
|
|
2539
2737
|
}
|
|
@@ -2555,7 +2753,8 @@ class WhereClause {
|
|
|
2555
2753
|
if (keyWithinCurrentRange(key)) {
|
|
2556
2754
|
return true;
|
|
2557
2755
|
}
|
|
2558
|
-
else if (this._cmp(key, set[rangePos][1]) === 0 ||
|
|
2756
|
+
else if (this._cmp(key, set[rangePos][1]) === 0 ||
|
|
2757
|
+
this._cmp(key, set[rangePos][0]) === 0) {
|
|
2559
2758
|
return false;
|
|
2560
2759
|
}
|
|
2561
2760
|
else {
|
|
@@ -2572,8 +2771,8 @@ class WhereClause {
|
|
|
2572
2771
|
}
|
|
2573
2772
|
startsWithAnyOf() {
|
|
2574
2773
|
const set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
2575
|
-
if (!set.every(s => typeof s === 'string')) {
|
|
2576
|
-
return fail(this,
|
|
2774
|
+
if (!set.every((s) => typeof s === 'string')) {
|
|
2775
|
+
return fail(this, 'startsWithAnyOf() only works with strings');
|
|
2577
2776
|
}
|
|
2578
2777
|
if (set.length === 0)
|
|
2579
2778
|
return emptyCollection(this);
|
|
@@ -2586,13 +2785,13 @@ function createWhereClauseConstructor(db) {
|
|
|
2586
2785
|
this.db = db;
|
|
2587
2786
|
this._ctx = {
|
|
2588
2787
|
table: table,
|
|
2589
|
-
index: index ===
|
|
2590
|
-
or: orCollection
|
|
2788
|
+
index: index === ':id' ? null : index,
|
|
2789
|
+
or: orCollection,
|
|
2591
2790
|
};
|
|
2592
2791
|
this._cmp = this._ascending = cmp;
|
|
2593
2792
|
this._descending = (a, b) => cmp(b, a);
|
|
2594
|
-
this._max = (a, b) => cmp(a, b) > 0 ? a : b;
|
|
2595
|
-
this._min = (a, b) => cmp(a, b) < 0 ? a : b;
|
|
2793
|
+
this._max = (a, b) => (cmp(a, b) > 0 ? a : b);
|
|
2794
|
+
this._min = (a, b) => (cmp(a, b) < 0 ? a : b);
|
|
2596
2795
|
this._IDBKeyRange = db._deps.IDBKeyRange;
|
|
2597
2796
|
if (!this._IDBKeyRange)
|
|
2598
2797
|
throw new exceptions.MissingAPI();
|
|
@@ -2651,9 +2850,9 @@ class Transaction {
|
|
|
2651
2850
|
assert(!this.idbtrans);
|
|
2652
2851
|
if (!idbtrans && !idbdb) {
|
|
2653
2852
|
switch (dbOpenError && dbOpenError.name) {
|
|
2654
|
-
case
|
|
2853
|
+
case 'DatabaseClosedError':
|
|
2655
2854
|
throw new exceptions.DatabaseClosed(dbOpenError);
|
|
2656
|
-
case
|
|
2855
|
+
case 'MissingAPIError':
|
|
2657
2856
|
throw new exceptions.MissingAPI(dbOpenError.message, dbOpenError);
|
|
2658
2857
|
default:
|
|
2659
2858
|
throw new exceptions.OpenFailed(dbOpenError);
|
|
@@ -2662,39 +2861,45 @@ class Transaction {
|
|
|
2662
2861
|
if (!this.active)
|
|
2663
2862
|
throw new exceptions.TransactionInactive();
|
|
2664
2863
|
assert(this._completion._state === null);
|
|
2665
|
-
idbtrans = this.idbtrans =
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2864
|
+
idbtrans = this.idbtrans =
|
|
2865
|
+
idbtrans ||
|
|
2866
|
+
(this.db.core
|
|
2867
|
+
? this.db.core.transaction(this.storeNames, this.mode, { durability: this.chromeTransactionDurability })
|
|
2868
|
+
: idbdb.transaction(this.storeNames, this.mode, {
|
|
2869
|
+
durability: this.chromeTransactionDurability,
|
|
2870
|
+
}));
|
|
2871
|
+
idbtrans.onerror = wrap((ev) => {
|
|
2670
2872
|
preventDefault(ev);
|
|
2671
2873
|
this._reject(idbtrans.error);
|
|
2672
2874
|
});
|
|
2673
|
-
idbtrans.onabort = wrap(ev => {
|
|
2875
|
+
idbtrans.onabort = wrap((ev) => {
|
|
2674
2876
|
preventDefault(ev);
|
|
2675
2877
|
this.active && this._reject(new exceptions.Abort(idbtrans.error));
|
|
2676
2878
|
this.active = false;
|
|
2677
|
-
this.on(
|
|
2879
|
+
this.on('abort').fire(ev);
|
|
2678
2880
|
});
|
|
2679
2881
|
idbtrans.oncomplete = wrap(() => {
|
|
2680
2882
|
this.active = false;
|
|
2681
2883
|
this._resolve();
|
|
2682
2884
|
if ('mutatedParts' in idbtrans) {
|
|
2683
|
-
globalEvents.storagemutated.fire(idbtrans[
|
|
2885
|
+
globalEvents.storagemutated.fire(idbtrans['mutatedParts']);
|
|
2684
2886
|
}
|
|
2685
2887
|
});
|
|
2686
2888
|
return this;
|
|
2687
2889
|
}
|
|
2688
2890
|
_promise(mode, fn, bWriteLock) {
|
|
2689
2891
|
if (mode === 'readwrite' && this.mode !== 'readwrite')
|
|
2690
|
-
return rejection(new exceptions.ReadOnly(
|
|
2892
|
+
return rejection(new exceptions.ReadOnly('Transaction is readonly'));
|
|
2691
2893
|
if (!this.active)
|
|
2692
2894
|
return rejection(new exceptions.TransactionInactive());
|
|
2693
2895
|
if (this._locked()) {
|
|
2694
2896
|
return new DexiePromise((resolve, reject) => {
|
|
2695
|
-
this._blockedFuncs.push([
|
|
2897
|
+
this._blockedFuncs.push([
|
|
2898
|
+
() => {
|
|
2696
2899
|
this._promise(mode, fn, bWriteLock).then(resolve, reject);
|
|
2697
|
-
},
|
|
2900
|
+
},
|
|
2901
|
+
PSD,
|
|
2902
|
+
]);
|
|
2698
2903
|
});
|
|
2699
2904
|
}
|
|
2700
2905
|
else if (bWriteLock) {
|
|
@@ -2736,14 +2941,16 @@ class Transaction {
|
|
|
2736
2941
|
(function spin() {
|
|
2737
2942
|
++root._spinCount;
|
|
2738
2943
|
while (root._waitingQueue.length)
|
|
2739
|
-
|
|
2944
|
+
root._waitingQueue.shift()();
|
|
2740
2945
|
if (root._waitingFor)
|
|
2741
2946
|
store.get(-Infinity).onsuccess = spin;
|
|
2742
|
-
}()
|
|
2947
|
+
})();
|
|
2743
2948
|
}
|
|
2744
2949
|
var currentWaitPromise = root._waitingFor;
|
|
2745
2950
|
return new DexiePromise((resolve, reject) => {
|
|
2746
|
-
promise
|
|
2951
|
+
promise
|
|
2952
|
+
.then((res) => root._waitingQueue.push(wrap(resolve.bind(null, res))), (err) => root._waitingQueue.push(wrap(reject.bind(null, err))))
|
|
2953
|
+
.finally(() => {
|
|
2747
2954
|
if (root._waitingFor === currentWaitPromise) {
|
|
2748
2955
|
root._waitingFor = null;
|
|
2749
2956
|
}
|
|
@@ -2759,12 +2966,12 @@ class Transaction {
|
|
|
2759
2966
|
}
|
|
2760
2967
|
}
|
|
2761
2968
|
table(tableName) {
|
|
2762
|
-
const memoizedTables =
|
|
2969
|
+
const memoizedTables = this._memoizedTables || (this._memoizedTables = {});
|
|
2763
2970
|
if (hasOwn(memoizedTables, tableName))
|
|
2764
2971
|
return memoizedTables[tableName];
|
|
2765
2972
|
const tableSchema = this.schema[tableName];
|
|
2766
2973
|
if (!tableSchema) {
|
|
2767
|
-
throw new exceptions.NotFound(
|
|
2974
|
+
throw new exceptions.NotFound('Table ' + tableName + ' not part of transaction');
|
|
2768
2975
|
}
|
|
2769
2976
|
const transactionBoundTable = new this.db.Table(tableName, tableSchema, this);
|
|
2770
2977
|
transactionBoundTable.core = this.db.core.table(tableName);
|
|
@@ -2776,10 +2983,10 @@ class Transaction {
|
|
|
2776
2983
|
function createTransactionConstructor(db) {
|
|
2777
2984
|
return makeClassConstructor(Transaction.prototype, function Transaction(mode, storeNames, dbschema, chromeTransactionDurability, parent) {
|
|
2778
2985
|
if (mode !== 'readonly')
|
|
2779
|
-
storeNames.forEach(storeName => {
|
|
2986
|
+
storeNames.forEach((storeName) => {
|
|
2780
2987
|
const yProps = dbschema[storeName]?.yProps;
|
|
2781
2988
|
if (yProps)
|
|
2782
|
-
storeNames = storeNames.concat(yProps.map(p => p.updatesTable));
|
|
2989
|
+
storeNames = storeNames.concat(yProps.map((p) => p.updatesTable));
|
|
2783
2990
|
});
|
|
2784
2991
|
this.db = db;
|
|
2785
2992
|
this.mode = mode;
|
|
@@ -2787,7 +2994,7 @@ function createTransactionConstructor(db) {
|
|
|
2787
2994
|
this.schema = dbschema;
|
|
2788
2995
|
this.chromeTransactionDurability = chromeTransactionDurability;
|
|
2789
2996
|
this.idbtrans = null;
|
|
2790
|
-
this.on = Events(this,
|
|
2997
|
+
this.on = Events(this, 'complete', 'error', 'abort');
|
|
2791
2998
|
this.parent = parent || null;
|
|
2792
2999
|
this.active = true;
|
|
2793
3000
|
this._reculock = 0;
|
|
@@ -2804,13 +3011,13 @@ function createTransactionConstructor(db) {
|
|
|
2804
3011
|
this._completion.then(() => {
|
|
2805
3012
|
this.active = false;
|
|
2806
3013
|
this.on.complete.fire();
|
|
2807
|
-
}, e => {
|
|
3014
|
+
}, (e) => {
|
|
2808
3015
|
var wasActive = this.active;
|
|
2809
3016
|
this.active = false;
|
|
2810
3017
|
this.on.error.fire(e);
|
|
2811
|
-
this.parent
|
|
2812
|
-
this.parent._reject(e)
|
|
2813
|
-
wasActive && this.idbtrans && this.idbtrans.abort();
|
|
3018
|
+
this.parent
|
|
3019
|
+
? this.parent._reject(e)
|
|
3020
|
+
: wasActive && this.idbtrans && this.idbtrans.abort();
|
|
2814
3021
|
return rejection(e);
|
|
2815
3022
|
});
|
|
2816
3023
|
});
|
|
@@ -2824,14 +3031,19 @@ function createIndexSpec(name, keyPath, unique, multi, auto, compound, isPrimKey
|
|
|
2824
3031
|
multi,
|
|
2825
3032
|
auto,
|
|
2826
3033
|
compound,
|
|
2827
|
-
src: (unique && !isPrimKey ? '&' : '') +
|
|
2828
|
-
|
|
3034
|
+
src: (unique && !isPrimKey ? '&' : '') +
|
|
3035
|
+
(multi ? '*' : '') +
|
|
3036
|
+
(auto ? '++' : '') +
|
|
3037
|
+
nameFromKeyPath(keyPath),
|
|
3038
|
+
type,
|
|
2829
3039
|
};
|
|
2830
3040
|
}
|
|
2831
3041
|
function nameFromKeyPath(keyPath) {
|
|
2832
|
-
return typeof keyPath === 'string'
|
|
2833
|
-
keyPath
|
|
2834
|
-
|
|
3042
|
+
return typeof keyPath === 'string'
|
|
3043
|
+
? keyPath
|
|
3044
|
+
: keyPath
|
|
3045
|
+
? '[' + [].join.call(keyPath, '+') + ']'
|
|
3046
|
+
: '';
|
|
2835
3047
|
}
|
|
2836
3048
|
|
|
2837
3049
|
function createTableSchema(name, primKey, indexes) {
|
|
@@ -2867,16 +3079,16 @@ function getKeyExtractor(keyPath) {
|
|
|
2867
3079
|
return getSinglePathKeyExtractor(keyPath);
|
|
2868
3080
|
}
|
|
2869
3081
|
else {
|
|
2870
|
-
return obj => getByKeyPath(obj, keyPath);
|
|
3082
|
+
return (obj) => getByKeyPath(obj, keyPath);
|
|
2871
3083
|
}
|
|
2872
3084
|
}
|
|
2873
3085
|
function getSinglePathKeyExtractor(keyPath) {
|
|
2874
3086
|
const split = keyPath.split('.');
|
|
2875
3087
|
if (split.length === 1) {
|
|
2876
|
-
return obj => obj[keyPath];
|
|
3088
|
+
return (obj) => obj[keyPath];
|
|
2877
3089
|
}
|
|
2878
3090
|
else {
|
|
2879
|
-
return obj => getByKeyPath(obj, keyPath);
|
|
3091
|
+
return (obj) => getByKeyPath(obj, keyPath);
|
|
2880
3092
|
}
|
|
2881
3093
|
}
|
|
2882
3094
|
|
|
@@ -2885,22 +3097,22 @@ function arrayify(arrayLike) {
|
|
|
2885
3097
|
}
|
|
2886
3098
|
let _id_counter = 0;
|
|
2887
3099
|
function getKeyPathAlias(keyPath) {
|
|
2888
|
-
return keyPath == null
|
|
2889
|
-
|
|
2890
|
-
typeof keyPath === 'string'
|
|
2891
|
-
keyPath
|
|
2892
|
-
`[${keyPath.join('+')}]`;
|
|
3100
|
+
return keyPath == null
|
|
3101
|
+
? ':id'
|
|
3102
|
+
: typeof keyPath === 'string'
|
|
3103
|
+
? keyPath
|
|
3104
|
+
: `[${keyPath.join('+')}]`;
|
|
2893
3105
|
}
|
|
2894
3106
|
function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
2895
3107
|
function extractSchema(db, trans) {
|
|
2896
3108
|
const tables = arrayify(db.objectStoreNames);
|
|
2897
|
-
const tempStore = tables.length > 0
|
|
2898
|
-
? trans.objectStore(tables[0])
|
|
2899
|
-
: {};
|
|
3109
|
+
const tempStore = tables.length > 0 ? trans.objectStore(tables[0]) : {};
|
|
2900
3110
|
return {
|
|
2901
3111
|
schema: {
|
|
2902
3112
|
name: db.name,
|
|
2903
|
-
tables: tables
|
|
3113
|
+
tables: tables
|
|
3114
|
+
.map((table) => trans.objectStore(table))
|
|
3115
|
+
.map((store) => {
|
|
2904
3116
|
const { keyPath, autoIncrement } = store;
|
|
2905
3117
|
const compound = isArray(keyPath);
|
|
2906
3118
|
const outbound = keyPath == null;
|
|
@@ -2915,10 +3127,11 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
2915
3127
|
keyPath,
|
|
2916
3128
|
autoIncrement,
|
|
2917
3129
|
unique: true,
|
|
2918
|
-
extractKey: getKeyExtractor(keyPath)
|
|
3130
|
+
extractKey: getKeyExtractor(keyPath),
|
|
2919
3131
|
},
|
|
2920
|
-
indexes: arrayify(store.indexNames)
|
|
2921
|
-
.map(
|
|
3132
|
+
indexes: arrayify(store.indexNames)
|
|
3133
|
+
.map((indexName) => store.index(indexName))
|
|
3134
|
+
.map((index) => {
|
|
2922
3135
|
const { name, unique, multiEntry, keyPath } = index;
|
|
2923
3136
|
const compound = isArray(keyPath);
|
|
2924
3137
|
const result = {
|
|
@@ -2927,40 +3140,42 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
2927
3140
|
keyPath,
|
|
2928
3141
|
unique,
|
|
2929
3142
|
multiEntry,
|
|
2930
|
-
extractKey: getKeyExtractor(keyPath)
|
|
3143
|
+
extractKey: getKeyExtractor(keyPath),
|
|
2931
3144
|
};
|
|
2932
3145
|
indexByKeyPath[getKeyPathAlias(keyPath)] = result;
|
|
2933
3146
|
return result;
|
|
2934
3147
|
}),
|
|
2935
|
-
getIndexByKeyPath: (keyPath) => indexByKeyPath[getKeyPathAlias(keyPath)]
|
|
3148
|
+
getIndexByKeyPath: (keyPath) => indexByKeyPath[getKeyPathAlias(keyPath)],
|
|
2936
3149
|
};
|
|
2937
|
-
indexByKeyPath[
|
|
3150
|
+
indexByKeyPath[':id'] = result.primaryKey;
|
|
2938
3151
|
if (keyPath != null) {
|
|
2939
3152
|
indexByKeyPath[getKeyPathAlias(keyPath)] = result.primaryKey;
|
|
2940
3153
|
}
|
|
2941
3154
|
return result;
|
|
2942
|
-
})
|
|
3155
|
+
}),
|
|
2943
3156
|
},
|
|
2944
|
-
hasGetAll: tables.length > 0 &&
|
|
2945
|
-
|
|
3157
|
+
hasGetAll: tables.length > 0 &&
|
|
3158
|
+
'getAll' in tempStore &&
|
|
3159
|
+
!(typeof navigator !== 'undefined' &&
|
|
3160
|
+
/Safari/.test(navigator.userAgent) &&
|
|
2946
3161
|
!/(Chrome\/|Edge\/)/.test(navigator.userAgent) &&
|
|
2947
3162
|
[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604),
|
|
2948
|
-
hasIdb3Features: 'getAllRecords' in tempStore
|
|
3163
|
+
hasIdb3Features: 'getAllRecords' in tempStore,
|
|
2949
3164
|
};
|
|
2950
3165
|
}
|
|
2951
3166
|
function makeIDBKeyRange(range) {
|
|
2952
3167
|
if (range.type === 3 )
|
|
2953
3168
|
return null;
|
|
2954
3169
|
if (range.type === 4 )
|
|
2955
|
-
throw new Error(
|
|
3170
|
+
throw new Error('Cannot convert never type to IDBKeyRange');
|
|
2956
3171
|
const { lower, upper, lowerOpen, upperOpen } = range;
|
|
2957
|
-
const idbRange = lower === undefined
|
|
2958
|
-
upper === undefined
|
|
2959
|
-
null
|
|
2960
|
-
IdbKeyRange.upperBound(upper, !!upperOpen)
|
|
2961
|
-
upper === undefined
|
|
2962
|
-
IdbKeyRange.lowerBound(lower, !!lowerOpen)
|
|
2963
|
-
IdbKeyRange.bound(lower, upper, !!lowerOpen, !!upperOpen);
|
|
3172
|
+
const idbRange = lower === undefined
|
|
3173
|
+
? upper === undefined
|
|
3174
|
+
? null
|
|
3175
|
+
: IdbKeyRange.upperBound(upper, !!upperOpen)
|
|
3176
|
+
: upper === undefined
|
|
3177
|
+
? IdbKeyRange.lowerBound(lower, !!lowerOpen)
|
|
3178
|
+
: IdbKeyRange.bound(lower, upper, !!lowerOpen, !!upperOpen);
|
|
2964
3179
|
return idbRange;
|
|
2965
3180
|
}
|
|
2966
3181
|
function createDbCoreTable(tableSchema) {
|
|
@@ -2970,89 +3185,97 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
2970
3185
|
resolve = wrap(resolve);
|
|
2971
3186
|
const store = trans.objectStore(tableName);
|
|
2972
3187
|
const outbound = store.keyPath == null;
|
|
2973
|
-
const isAddOrPut = type ===
|
|
3188
|
+
const isAddOrPut = type === 'put' || type === 'add';
|
|
2974
3189
|
if (!isAddOrPut && type !== 'delete' && type !== 'deleteRange')
|
|
2975
|
-
throw new Error(
|
|
3190
|
+
throw new Error('Invalid operation type: ' + type);
|
|
2976
3191
|
const { length } = keys || values || { length: 1 };
|
|
2977
3192
|
if (keys && values && keys.length !== values.length) {
|
|
2978
|
-
throw new Error(
|
|
3193
|
+
throw new Error('Given keys array must have same length as given values array.');
|
|
2979
3194
|
}
|
|
2980
3195
|
if (length === 0)
|
|
2981
|
-
return resolve({
|
|
3196
|
+
return resolve({
|
|
3197
|
+
numFailures: 0,
|
|
3198
|
+
failures: {},
|
|
3199
|
+
results: [],
|
|
3200
|
+
lastResult: undefined,
|
|
3201
|
+
});
|
|
2982
3202
|
let req;
|
|
2983
3203
|
const reqs = [];
|
|
2984
3204
|
const failures = [];
|
|
2985
3205
|
let numFailures = 0;
|
|
2986
|
-
const errorHandler = event => {
|
|
3206
|
+
const errorHandler = (event) => {
|
|
2987
3207
|
++numFailures;
|
|
2988
3208
|
preventDefault(event);
|
|
2989
3209
|
};
|
|
2990
3210
|
if (type === 'deleteRange') {
|
|
2991
3211
|
if (range.type === 4 )
|
|
2992
|
-
return resolve({
|
|
3212
|
+
return resolve({
|
|
3213
|
+
numFailures,
|
|
3214
|
+
failures,
|
|
3215
|
+
results: [],
|
|
3216
|
+
lastResult: undefined,
|
|
3217
|
+
});
|
|
2993
3218
|
if (range.type === 3 )
|
|
2994
|
-
reqs.push(req = store.clear());
|
|
3219
|
+
reqs.push((req = store.clear()));
|
|
2995
3220
|
else
|
|
2996
|
-
reqs.push(req = store.delete(makeIDBKeyRange(range)));
|
|
3221
|
+
reqs.push((req = store.delete(makeIDBKeyRange(range))));
|
|
2997
3222
|
}
|
|
2998
3223
|
else {
|
|
2999
|
-
const [args1, args2] = isAddOrPut
|
|
3000
|
-
outbound
|
|
3001
|
-
[values, keys]
|
|
3002
|
-
[values, null]
|
|
3003
|
-
[keys, null];
|
|
3224
|
+
const [args1, args2] = isAddOrPut
|
|
3225
|
+
? outbound
|
|
3226
|
+
? [values, keys]
|
|
3227
|
+
: [values, null]
|
|
3228
|
+
: [keys, null];
|
|
3004
3229
|
if (isAddOrPut) {
|
|
3005
3230
|
for (let i = 0; i < length; ++i) {
|
|
3006
|
-
reqs.push(req = (args2 && args2[i] !== undefined
|
|
3007
|
-
store[type](args1[i], args2[i])
|
|
3008
|
-
store[type](args1[i])));
|
|
3231
|
+
reqs.push((req = (args2 && args2[i] !== undefined
|
|
3232
|
+
? store[type](args1[i], args2[i])
|
|
3233
|
+
: store[type](args1[i]))));
|
|
3009
3234
|
req.onerror = errorHandler;
|
|
3010
3235
|
}
|
|
3011
3236
|
}
|
|
3012
3237
|
else {
|
|
3013
3238
|
for (let i = 0; i < length; ++i) {
|
|
3014
|
-
reqs.push(req = store[type](args1[i]));
|
|
3239
|
+
reqs.push((req = store[type](args1[i])));
|
|
3015
3240
|
req.onerror = errorHandler;
|
|
3016
3241
|
}
|
|
3017
3242
|
}
|
|
3018
3243
|
}
|
|
3019
|
-
const done = event => {
|
|
3244
|
+
const done = (event) => {
|
|
3020
3245
|
const lastResult = event.target.result;
|
|
3021
3246
|
reqs.forEach((req, i) => req.error != null && (failures[i] = req.error));
|
|
3022
3247
|
resolve({
|
|
3023
3248
|
numFailures,
|
|
3024
3249
|
failures,
|
|
3025
|
-
results: type ===
|
|
3026
|
-
lastResult
|
|
3250
|
+
results: type === 'delete' ? keys : reqs.map((req) => req.result),
|
|
3251
|
+
lastResult,
|
|
3027
3252
|
});
|
|
3028
3253
|
};
|
|
3029
|
-
req.onerror = event => {
|
|
3254
|
+
req.onerror = (event) => {
|
|
3030
3255
|
errorHandler(event);
|
|
3031
3256
|
done(event);
|
|
3032
3257
|
};
|
|
3033
3258
|
req.onsuccess = done;
|
|
3034
3259
|
});
|
|
3035
3260
|
}
|
|
3036
|
-
function openCursor({ trans, values, query, reverse, unique }) {
|
|
3261
|
+
function openCursor({ trans, values, query, reverse, unique, }) {
|
|
3037
3262
|
return new Promise((resolve, reject) => {
|
|
3038
3263
|
resolve = wrap(resolve);
|
|
3039
3264
|
const { index, range } = query;
|
|
3040
3265
|
const store = trans.objectStore(tableName);
|
|
3041
|
-
const source = index.isPrimaryKey ?
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
source.openCursor(makeIDBKeyRange(range), direction) :
|
|
3053
|
-
source.openKeyCursor(makeIDBKeyRange(range), direction);
|
|
3266
|
+
const source = index.isPrimaryKey ? store : store.index(index.name);
|
|
3267
|
+
const direction = reverse
|
|
3268
|
+
? unique
|
|
3269
|
+
? 'prevunique'
|
|
3270
|
+
: 'prev'
|
|
3271
|
+
: unique
|
|
3272
|
+
? 'nextunique'
|
|
3273
|
+
: 'next';
|
|
3274
|
+
const req = values || !('openKeyCursor' in source)
|
|
3275
|
+
? source.openCursor(makeIDBKeyRange(range), direction)
|
|
3276
|
+
: source.openKeyCursor(makeIDBKeyRange(range), direction);
|
|
3054
3277
|
req.onerror = eventRejectHandler(reject);
|
|
3055
|
-
req.onsuccess = wrap(ev => {
|
|
3278
|
+
req.onsuccess = wrap((ev) => {
|
|
3056
3279
|
const cursor = req.result;
|
|
3057
3280
|
if (!cursor) {
|
|
3058
3281
|
resolve(null);
|
|
@@ -3065,10 +3288,18 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3065
3288
|
if (_cursorContinuePrimaryKey)
|
|
3066
3289
|
_cursorContinuePrimaryKey = _cursorContinuePrimaryKey.bind(cursor);
|
|
3067
3290
|
const _cursorAdvance = cursor.advance.bind(cursor);
|
|
3068
|
-
const doThrowCursorIsNotStarted = () => {
|
|
3069
|
-
|
|
3291
|
+
const doThrowCursorIsNotStarted = () => {
|
|
3292
|
+
throw new Error('Cursor not started');
|
|
3293
|
+
};
|
|
3294
|
+
const doThrowCursorIsStopped = () => {
|
|
3295
|
+
throw new Error('Cursor not stopped');
|
|
3296
|
+
};
|
|
3070
3297
|
cursor.trans = trans;
|
|
3071
|
-
cursor.stop =
|
|
3298
|
+
cursor.stop =
|
|
3299
|
+
cursor.continue =
|
|
3300
|
+
cursor.continuePrimaryKey =
|
|
3301
|
+
cursor.advance =
|
|
3302
|
+
doThrowCursorIsNotStarted;
|
|
3072
3303
|
cursor.fail = wrap(reject);
|
|
3073
3304
|
cursor.next = function () {
|
|
3074
3305
|
let gotOne = 1;
|
|
@@ -3079,8 +3310,12 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3079
3310
|
resolveIteration = wrap(resolveIteration);
|
|
3080
3311
|
req.onerror = eventRejectHandler(rejectIteration);
|
|
3081
3312
|
cursor.fail = rejectIteration;
|
|
3082
|
-
cursor.stop = value => {
|
|
3083
|
-
cursor.stop =
|
|
3313
|
+
cursor.stop = (value) => {
|
|
3314
|
+
cursor.stop =
|
|
3315
|
+
cursor.continue =
|
|
3316
|
+
cursor.continuePrimaryKey =
|
|
3317
|
+
cursor.advance =
|
|
3318
|
+
doThrowCursorIsStopped;
|
|
3084
3319
|
resolveIteration(value);
|
|
3085
3320
|
};
|
|
3086
3321
|
});
|
|
@@ -3095,11 +3330,13 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3095
3330
|
}
|
|
3096
3331
|
else {
|
|
3097
3332
|
cursor.done = true;
|
|
3098
|
-
cursor.start = () => {
|
|
3333
|
+
cursor.start = () => {
|
|
3334
|
+
throw new Error('Cursor behind last entry');
|
|
3335
|
+
};
|
|
3099
3336
|
cursor.stop();
|
|
3100
3337
|
}
|
|
3101
3338
|
};
|
|
3102
|
-
req.onsuccess = wrap(ev => {
|
|
3339
|
+
req.onsuccess = wrap((ev) => {
|
|
3103
3340
|
req.onsuccess = guardedCallback;
|
|
3104
3341
|
guardedCallback();
|
|
3105
3342
|
});
|
|
@@ -3130,26 +3367,26 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3130
3367
|
const options = {
|
|
3131
3368
|
query: idbKeyRange,
|
|
3132
3369
|
count: nonInfinitLimit,
|
|
3133
|
-
direction
|
|
3370
|
+
direction,
|
|
3134
3371
|
};
|
|
3135
|
-
const req = values
|
|
3136
|
-
source.getAll(options)
|
|
3137
|
-
source.getAllKeys(options);
|
|
3138
|
-
req.onsuccess = event => resolve({ result: event.target.result });
|
|
3372
|
+
const req = values
|
|
3373
|
+
? source.getAll(options)
|
|
3374
|
+
: source.getAllKeys(options);
|
|
3375
|
+
req.onsuccess = (event) => resolve({ result: event.target.result });
|
|
3139
3376
|
req.onerror = eventRejectHandler(reject);
|
|
3140
3377
|
}
|
|
3141
3378
|
else if (hasGetAll && direction === 'next') {
|
|
3142
|
-
const req = values
|
|
3143
|
-
source.getAll(idbKeyRange, nonInfinitLimit)
|
|
3144
|
-
source.getAllKeys(idbKeyRange, nonInfinitLimit);
|
|
3379
|
+
const req = values
|
|
3380
|
+
? source.getAll(idbKeyRange, nonInfinitLimit)
|
|
3381
|
+
: source.getAllKeys(idbKeyRange, nonInfinitLimit);
|
|
3145
3382
|
req.onsuccess = (event) => resolve({ result: event.target.result });
|
|
3146
3383
|
req.onerror = eventRejectHandler(reject);
|
|
3147
3384
|
}
|
|
3148
3385
|
else {
|
|
3149
3386
|
let count = 0;
|
|
3150
|
-
const req = values || !('openKeyCursor' in source)
|
|
3151
|
-
source.openCursor(idbKeyRange, direction)
|
|
3152
|
-
source.openKeyCursor(idbKeyRange, direction);
|
|
3387
|
+
const req = values || !('openKeyCursor' in source)
|
|
3388
|
+
? source.openCursor(idbKeyRange, direction)
|
|
3389
|
+
: source.openKeyCursor(idbKeyRange, direction);
|
|
3153
3390
|
const result = [];
|
|
3154
3391
|
req.onsuccess = () => {
|
|
3155
3392
|
const cursor = req.result;
|
|
@@ -3178,7 +3415,7 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3178
3415
|
let keyCount = 0;
|
|
3179
3416
|
let callbackCount = 0;
|
|
3180
3417
|
let req;
|
|
3181
|
-
const successHandler = event => {
|
|
3418
|
+
const successHandler = (event) => {
|
|
3182
3419
|
const req = event.target;
|
|
3183
3420
|
if ((result[req._pos] = req.result) != null)
|
|
3184
3421
|
;
|
|
@@ -3205,7 +3442,7 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3205
3442
|
resolve = wrap(resolve);
|
|
3206
3443
|
const store = trans.objectStore(tableName);
|
|
3207
3444
|
const req = store.get(key);
|
|
3208
|
-
req.onsuccess = event => resolve(event.target.result);
|
|
3445
|
+
req.onsuccess = (event) => resolve(event.target.result);
|
|
3209
3446
|
req.onerror = eventRejectHandler(reject);
|
|
3210
3447
|
});
|
|
3211
3448
|
},
|
|
@@ -3218,18 +3455,18 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3218
3455
|
const source = index.isPrimaryKey ? store : store.index(index.name);
|
|
3219
3456
|
const idbKeyRange = makeIDBKeyRange(range);
|
|
3220
3457
|
const req = idbKeyRange ? source.count(idbKeyRange) : source.count();
|
|
3221
|
-
req.onsuccess = wrap(ev => resolve(ev.target.result));
|
|
3458
|
+
req.onsuccess = wrap((ev) => resolve(ev.target.result));
|
|
3222
3459
|
req.onerror = eventRejectHandler(reject);
|
|
3223
3460
|
});
|
|
3224
|
-
}
|
|
3461
|
+
},
|
|
3225
3462
|
};
|
|
3226
3463
|
}
|
|
3227
3464
|
const { schema, hasGetAll, hasIdb3Features } = extractSchema(db, tmpTrans);
|
|
3228
|
-
const tables = schema.tables.map(tableSchema => createDbCoreTable(tableSchema));
|
|
3465
|
+
const tables = schema.tables.map((tableSchema) => createDbCoreTable(tableSchema));
|
|
3229
3466
|
const tableMap = {};
|
|
3230
|
-
tables.forEach(table => tableMap[table.name] = table);
|
|
3467
|
+
tables.forEach((table) => (tableMap[table.name] = table));
|
|
3231
3468
|
return {
|
|
3232
|
-
stack:
|
|
3469
|
+
stack: 'dbcore',
|
|
3233
3470
|
transaction: db.transaction.bind(db),
|
|
3234
3471
|
table(name) {
|
|
3235
3472
|
const result = tableMap[name];
|
|
@@ -3239,7 +3476,7 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3239
3476
|
},
|
|
3240
3477
|
MIN_KEY: -Infinity,
|
|
3241
3478
|
MAX_KEY: getMaxKey(IdbKeyRange),
|
|
3242
|
-
schema
|
|
3479
|
+
schema,
|
|
3243
3480
|
};
|
|
3244
3481
|
}
|
|
3245
3482
|
|
|
@@ -3249,16 +3486,16 @@ function createMiddlewareStack(stackImpl, middlewares) {
|
|
|
3249
3486
|
function createMiddlewareStacks(middlewares, idbdb, { IDBKeyRange, indexedDB }, tmpTrans) {
|
|
3250
3487
|
const dbcore = createMiddlewareStack(createDBCore(idbdb, IDBKeyRange, tmpTrans), middlewares.dbcore);
|
|
3251
3488
|
return {
|
|
3252
|
-
dbcore
|
|
3489
|
+
dbcore,
|
|
3253
3490
|
};
|
|
3254
3491
|
}
|
|
3255
3492
|
function generateMiddlewareStacks(db, tmpTrans) {
|
|
3256
3493
|
const idbdb = tmpTrans.db;
|
|
3257
3494
|
const stacks = createMiddlewareStacks(db._middlewares, idbdb, db._deps, tmpTrans);
|
|
3258
3495
|
db.core = stacks.dbcore;
|
|
3259
|
-
db.tables.forEach(table => {
|
|
3496
|
+
db.tables.forEach((table) => {
|
|
3260
3497
|
const tableName = table.name;
|
|
3261
|
-
if (db.core.schema.tables.some(tbl => tbl.name === tableName)) {
|
|
3498
|
+
if (db.core.schema.tables.some((tbl) => tbl.name === tableName)) {
|
|
3262
3499
|
table.core = db.core.table(tableName);
|
|
3263
3500
|
if (db[tableName] instanceof db.Table) {
|
|
3264
3501
|
db[tableName].core = table.core;
|
|
@@ -3268,17 +3505,24 @@ function generateMiddlewareStacks(db, tmpTrans) {
|
|
|
3268
3505
|
}
|
|
3269
3506
|
|
|
3270
3507
|
function setApiOnPlace(db, objs, tableNames, dbschema) {
|
|
3271
|
-
tableNames.forEach(tableName => {
|
|
3508
|
+
tableNames.forEach((tableName) => {
|
|
3272
3509
|
const schema = dbschema[tableName];
|
|
3273
|
-
objs.forEach(obj => {
|
|
3510
|
+
objs.forEach((obj) => {
|
|
3274
3511
|
const propDesc = getPropertyDescriptor(obj, tableName);
|
|
3275
|
-
if (!propDesc || (
|
|
3512
|
+
if (!propDesc || ('value' in propDesc && propDesc.value === undefined)) {
|
|
3276
3513
|
if (obj === db.Transaction.prototype || obj instanceof db.Transaction) {
|
|
3277
3514
|
setProp(obj, tableName, {
|
|
3278
|
-
get() {
|
|
3515
|
+
get() {
|
|
3516
|
+
return this.table(tableName);
|
|
3517
|
+
},
|
|
3279
3518
|
set(value) {
|
|
3280
|
-
defineProperty(this, tableName, {
|
|
3281
|
-
|
|
3519
|
+
defineProperty(this, tableName, {
|
|
3520
|
+
value,
|
|
3521
|
+
writable: true,
|
|
3522
|
+
configurable: true,
|
|
3523
|
+
enumerable: true,
|
|
3524
|
+
});
|
|
3525
|
+
},
|
|
3282
3526
|
});
|
|
3283
3527
|
}
|
|
3284
3528
|
else {
|
|
@@ -3289,7 +3533,7 @@ function setApiOnPlace(db, objs, tableNames, dbschema) {
|
|
|
3289
3533
|
});
|
|
3290
3534
|
}
|
|
3291
3535
|
function removeTablesApi(db, objs) {
|
|
3292
|
-
objs.forEach(obj => {
|
|
3536
|
+
objs.forEach((obj) => {
|
|
3293
3537
|
for (let key in obj) {
|
|
3294
3538
|
if (obj[key] instanceof db.Table)
|
|
3295
3539
|
delete obj[key];
|
|
@@ -3301,8 +3545,9 @@ function lowerVersionFirst(a, b) {
|
|
|
3301
3545
|
}
|
|
3302
3546
|
function runUpgraders(db, oldVersion, idbUpgradeTrans, reject) {
|
|
3303
3547
|
const globalSchema = db._dbSchema;
|
|
3304
|
-
if (idbUpgradeTrans.objectStoreNames.contains('$meta') &&
|
|
3305
|
-
globalSchema.$meta
|
|
3548
|
+
if (idbUpgradeTrans.objectStoreNames.contains('$meta') &&
|
|
3549
|
+
!globalSchema.$meta) {
|
|
3550
|
+
globalSchema.$meta = createTableSchema('$meta', parseIndexSyntax('')[0], []);
|
|
3306
3551
|
db._storeNames.push('$meta');
|
|
3307
3552
|
}
|
|
3308
3553
|
const trans = db._createTransaction('readwrite', db._storeNames, globalSchema);
|
|
@@ -3314,7 +3559,7 @@ function runUpgraders(db, oldVersion, idbUpgradeTrans, reject) {
|
|
|
3314
3559
|
PSD.trans = trans;
|
|
3315
3560
|
PSD.transless = transless;
|
|
3316
3561
|
if (oldVersion === 0) {
|
|
3317
|
-
keys(globalSchema).forEach(tableName => {
|
|
3562
|
+
keys(globalSchema).forEach((tableName) => {
|
|
3318
3563
|
createTable(idbUpgradeTrans, tableName, globalSchema[tableName].primKey, globalSchema[tableName].indexes);
|
|
3319
3564
|
});
|
|
3320
3565
|
generateMiddlewareStacks(db, idbUpgradeTrans);
|
|
@@ -3323,15 +3568,18 @@ function runUpgraders(db, oldVersion, idbUpgradeTrans, reject) {
|
|
|
3323
3568
|
else {
|
|
3324
3569
|
generateMiddlewareStacks(db, idbUpgradeTrans);
|
|
3325
3570
|
return getExistingVersion(db, trans, oldVersion)
|
|
3326
|
-
.then(oldVersion => updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans))
|
|
3571
|
+
.then((oldVersion) => updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans))
|
|
3327
3572
|
.catch(rejectTransaction);
|
|
3328
3573
|
}
|
|
3329
3574
|
});
|
|
3330
3575
|
}
|
|
3331
3576
|
function patchCurrentVersion(db, idbUpgradeTrans) {
|
|
3332
3577
|
createMissingTables(db._dbSchema, idbUpgradeTrans);
|
|
3333
|
-
if (idbUpgradeTrans.db.version % 10 === 0 &&
|
|
3334
|
-
idbUpgradeTrans.
|
|
3578
|
+
if (idbUpgradeTrans.db.version % 10 === 0 &&
|
|
3579
|
+
!idbUpgradeTrans.objectStoreNames.contains('$meta')) {
|
|
3580
|
+
idbUpgradeTrans.db
|
|
3581
|
+
.createObjectStore('$meta')
|
|
3582
|
+
.add(Math.ceil(idbUpgradeTrans.db.version / 10 - 1), 'version');
|
|
3335
3583
|
}
|
|
3336
3584
|
const globalSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
|
|
3337
3585
|
adjustToExistingIndexNames(db, db._dbSchema, idbUpgradeTrans);
|
|
@@ -3342,7 +3590,7 @@ function patchCurrentVersion(db, idbUpgradeTrans) {
|
|
|
3342
3590
|
return;
|
|
3343
3591
|
}
|
|
3344
3592
|
const store = idbUpgradeTrans.objectStore(tableChange.name);
|
|
3345
|
-
tableChange.add.forEach(idx => {
|
|
3593
|
+
tableChange.add.forEach((idx) => {
|
|
3346
3594
|
if (debug)
|
|
3347
3595
|
console.debug(`Dexie upgrade patch: Creating missing index ${tableChange.name}.${idx.src}`);
|
|
3348
3596
|
addIndex(store, idx);
|
|
@@ -3351,7 +3599,10 @@ function patchCurrentVersion(db, idbUpgradeTrans) {
|
|
|
3351
3599
|
}
|
|
3352
3600
|
function getExistingVersion(db, trans, oldVersion) {
|
|
3353
3601
|
if (trans.storeNames.includes('$meta')) {
|
|
3354
|
-
return trans
|
|
3602
|
+
return trans
|
|
3603
|
+
.table('$meta')
|
|
3604
|
+
.get('version')
|
|
3605
|
+
.then((metaVersion) => {
|
|
3355
3606
|
return metaVersion != null ? metaVersion : oldVersion;
|
|
3356
3607
|
});
|
|
3357
3608
|
}
|
|
@@ -3362,12 +3613,12 @@ function getExistingVersion(db, trans, oldVersion) {
|
|
|
3362
3613
|
function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
|
|
3363
3614
|
const queue = [];
|
|
3364
3615
|
const versions = db._versions;
|
|
3365
|
-
let globalSchema = db._dbSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
|
|
3366
|
-
const versToRun = versions.filter(v => v._cfg.version >= oldVersion);
|
|
3616
|
+
let globalSchema = (db._dbSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans));
|
|
3617
|
+
const versToRun = versions.filter((v) => v._cfg.version >= oldVersion);
|
|
3367
3618
|
if (versToRun.length === 0) {
|
|
3368
3619
|
return DexiePromise.resolve();
|
|
3369
3620
|
}
|
|
3370
|
-
versToRun.forEach(version => {
|
|
3621
|
+
versToRun.forEach((version) => {
|
|
3371
3622
|
queue.push(() => {
|
|
3372
3623
|
const oldSchema = globalSchema;
|
|
3373
3624
|
const newSchema = version._cfg.dbschema;
|
|
@@ -3375,21 +3626,21 @@ function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
|
|
|
3375
3626
|
adjustToExistingIndexNames(db, newSchema, idbUpgradeTrans);
|
|
3376
3627
|
globalSchema = db._dbSchema = newSchema;
|
|
3377
3628
|
const diff = getSchemaDiff(oldSchema, newSchema);
|
|
3378
|
-
diff.add.forEach(tuple => {
|
|
3629
|
+
diff.add.forEach((tuple) => {
|
|
3379
3630
|
createTable(idbUpgradeTrans, tuple[0], tuple[1].primKey, tuple[1].indexes);
|
|
3380
3631
|
});
|
|
3381
|
-
diff.change.forEach(change => {
|
|
3632
|
+
diff.change.forEach((change) => {
|
|
3382
3633
|
if (change.recreate) {
|
|
3383
|
-
throw new exceptions.Upgrade(
|
|
3634
|
+
throw new exceptions.Upgrade('Not yet support for changing primary key');
|
|
3384
3635
|
}
|
|
3385
3636
|
else {
|
|
3386
3637
|
const store = idbUpgradeTrans.objectStore(change.name);
|
|
3387
|
-
change.add.forEach(idx => addIndex(store, idx));
|
|
3388
|
-
change.change.forEach(idx => {
|
|
3638
|
+
change.add.forEach((idx) => addIndex(store, idx));
|
|
3639
|
+
change.change.forEach((idx) => {
|
|
3389
3640
|
store.deleteIndex(idx.name);
|
|
3390
3641
|
addIndex(store, idx);
|
|
3391
3642
|
});
|
|
3392
|
-
change.del.forEach(idxName => store.deleteIndex(idxName));
|
|
3643
|
+
change.del.forEach((idxName) => store.deleteIndex(idxName));
|
|
3393
3644
|
}
|
|
3394
3645
|
});
|
|
3395
3646
|
const contentUpgrade = version._cfg.contentUpgrade;
|
|
@@ -3397,7 +3648,7 @@ function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
|
|
|
3397
3648
|
generateMiddlewareStacks(db, idbUpgradeTrans);
|
|
3398
3649
|
trans._memoizedTables = {};
|
|
3399
3650
|
let upgradeSchema = shallowClone(newSchema);
|
|
3400
|
-
diff.del.forEach(table => {
|
|
3651
|
+
diff.del.forEach((table) => {
|
|
3401
3652
|
upgradeSchema[table] = oldSchema[table];
|
|
3402
3653
|
});
|
|
3403
3654
|
removeTablesApi(db, [db.Transaction.prototype]);
|
|
@@ -3417,23 +3668,24 @@ function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
|
|
|
3417
3668
|
}
|
|
3418
3669
|
}
|
|
3419
3670
|
});
|
|
3420
|
-
return
|
|
3421
|
-
DexiePromise.resolve(returnValue)
|
|
3671
|
+
return returnValue && typeof returnValue.then === 'function'
|
|
3672
|
+
? DexiePromise.resolve(returnValue)
|
|
3673
|
+
: promiseFollowed.then(() => returnValue);
|
|
3422
3674
|
}
|
|
3423
3675
|
});
|
|
3424
|
-
queue.push(idbtrans => {
|
|
3676
|
+
queue.push((idbtrans) => {
|
|
3425
3677
|
const newSchema = version._cfg.dbschema;
|
|
3426
3678
|
deleteRemovedTables(newSchema, idbtrans);
|
|
3427
3679
|
removeTablesApi(db, [db.Transaction.prototype]);
|
|
3428
3680
|
setApiOnPlace(db, [db.Transaction.prototype], db._storeNames, db._dbSchema);
|
|
3429
3681
|
trans.schema = db._dbSchema;
|
|
3430
3682
|
});
|
|
3431
|
-
queue.push(idbtrans => {
|
|
3683
|
+
queue.push((idbtrans) => {
|
|
3432
3684
|
if (db.idbdb.objectStoreNames.contains('$meta')) {
|
|
3433
3685
|
if (Math.ceil(db.idbdb.version / 10) === version._cfg.version) {
|
|
3434
3686
|
db.idbdb.deleteObjectStore('$meta');
|
|
3435
3687
|
delete db._dbSchema.$meta;
|
|
3436
|
-
db._storeNames = db._storeNames.filter(name => name !== '$meta');
|
|
3688
|
+
db._storeNames = db._storeNames.filter((name) => name !== '$meta');
|
|
3437
3689
|
}
|
|
3438
3690
|
else {
|
|
3439
3691
|
idbtrans.objectStore('$meta').put(version._cfg.version, 'version');
|
|
@@ -3442,8 +3694,9 @@ function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
|
|
|
3442
3694
|
});
|
|
3443
3695
|
});
|
|
3444
3696
|
function runQueue() {
|
|
3445
|
-
return queue.length
|
|
3446
|
-
DexiePromise.resolve()
|
|
3697
|
+
return queue.length
|
|
3698
|
+
? DexiePromise.resolve(queue.shift()(trans.idbtrans)).then(runQueue)
|
|
3699
|
+
: DexiePromise.resolve();
|
|
3447
3700
|
}
|
|
3448
3701
|
return runQueue().then(() => {
|
|
3449
3702
|
createMissingTables(globalSchema, idbUpgradeTrans);
|
|
@@ -3453,7 +3706,7 @@ function getSchemaDiff(oldSchema, newSchema) {
|
|
|
3453
3706
|
const diff = {
|
|
3454
3707
|
del: [],
|
|
3455
3708
|
add: [],
|
|
3456
|
-
change: []
|
|
3709
|
+
change: [],
|
|
3457
3710
|
};
|
|
3458
3711
|
let table;
|
|
3459
3712
|
for (table in oldSchema) {
|
|
@@ -3472,11 +3725,12 @@ function getSchemaDiff(oldSchema, newSchema) {
|
|
|
3472
3725
|
recreate: false,
|
|
3473
3726
|
del: [],
|
|
3474
3727
|
add: [],
|
|
3475
|
-
change: []
|
|
3728
|
+
change: [],
|
|
3476
3729
|
};
|
|
3477
|
-
if (
|
|
3478
|
-
'' + (oldDef.primKey.keyPath || '')
|
|
3479
|
-
(
|
|
3730
|
+
if (
|
|
3731
|
+
'' + (oldDef.primKey.keyPath || '') !==
|
|
3732
|
+
'' + (newDef.primKey.keyPath || '') ||
|
|
3733
|
+
oldDef.primKey.auto !== newDef.primKey.auto) {
|
|
3480
3734
|
change.recreate = true;
|
|
3481
3735
|
diff.change.push(change);
|
|
3482
3736
|
}
|
|
@@ -3495,7 +3749,9 @@ function getSchemaDiff(oldSchema, newSchema) {
|
|
|
3495
3749
|
else if (oldIdx.src !== newIdx.src)
|
|
3496
3750
|
change.change.push(newIdx);
|
|
3497
3751
|
}
|
|
3498
|
-
if (change.del.length > 0 ||
|
|
3752
|
+
if (change.del.length > 0 ||
|
|
3753
|
+
change.add.length > 0 ||
|
|
3754
|
+
change.change.length > 0) {
|
|
3499
3755
|
diff.change.push(change);
|
|
3500
3756
|
}
|
|
3501
3757
|
}
|
|
@@ -3504,14 +3760,14 @@ function getSchemaDiff(oldSchema, newSchema) {
|
|
|
3504
3760
|
return diff;
|
|
3505
3761
|
}
|
|
3506
3762
|
function createTable(idbtrans, tableName, primKey, indexes) {
|
|
3507
|
-
const store = idbtrans.db.createObjectStore(tableName, primKey.keyPath
|
|
3508
|
-
{ keyPath: primKey.keyPath, autoIncrement: primKey.auto }
|
|
3509
|
-
{ autoIncrement: primKey.auto });
|
|
3510
|
-
indexes.forEach(idx => addIndex(store, idx));
|
|
3763
|
+
const store = idbtrans.db.createObjectStore(tableName, primKey.keyPath
|
|
3764
|
+
? { keyPath: primKey.keyPath, autoIncrement: primKey.auto }
|
|
3765
|
+
: { autoIncrement: primKey.auto });
|
|
3766
|
+
indexes.forEach((idx) => addIndex(store, idx));
|
|
3511
3767
|
return store;
|
|
3512
3768
|
}
|
|
3513
3769
|
function createMissingTables(newSchema, idbtrans) {
|
|
3514
|
-
keys(newSchema).forEach(tableName => {
|
|
3770
|
+
keys(newSchema).forEach((tableName) => {
|
|
3515
3771
|
if (!idbtrans.db.objectStoreNames.contains(tableName)) {
|
|
3516
3772
|
if (debug)
|
|
3517
3773
|
console.debug('Dexie: Creating missing table', tableName);
|
|
@@ -3520,23 +3776,28 @@ function createMissingTables(newSchema, idbtrans) {
|
|
|
3520
3776
|
});
|
|
3521
3777
|
}
|
|
3522
3778
|
function deleteRemovedTables(newSchema, idbtrans) {
|
|
3523
|
-
[].slice
|
|
3779
|
+
[].slice
|
|
3780
|
+
.call(idbtrans.db.objectStoreNames)
|
|
3781
|
+
.forEach((storeName) => newSchema[storeName] == null && idbtrans.db.deleteObjectStore(storeName));
|
|
3524
3782
|
}
|
|
3525
3783
|
function addIndex(store, idx) {
|
|
3526
|
-
store.createIndex(idx.name, idx.keyPath, {
|
|
3784
|
+
store.createIndex(idx.name, idx.keyPath, {
|
|
3785
|
+
unique: idx.unique,
|
|
3786
|
+
multiEntry: idx.multi,
|
|
3787
|
+
});
|
|
3527
3788
|
}
|
|
3528
3789
|
function buildGlobalSchema(db, idbdb, tmpTrans) {
|
|
3529
3790
|
const globalSchema = {};
|
|
3530
3791
|
const dbStoreNames = slice(idbdb.objectStoreNames, 0);
|
|
3531
|
-
dbStoreNames.forEach(storeName => {
|
|
3792
|
+
dbStoreNames.forEach((storeName) => {
|
|
3532
3793
|
const store = tmpTrans.objectStore(storeName);
|
|
3533
3794
|
let keyPath = store.keyPath;
|
|
3534
|
-
const primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath ||
|
|
3795
|
+
const primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath || '', true, false, !!store.autoIncrement, keyPath && typeof keyPath !== 'string', true);
|
|
3535
3796
|
const indexes = [];
|
|
3536
3797
|
for (let j = 0; j < store.indexNames.length; ++j) {
|
|
3537
3798
|
const idbindex = store.index(store.indexNames[j]);
|
|
3538
3799
|
keyPath = idbindex.keyPath;
|
|
3539
|
-
var index = createIndexSpec(idbindex.name, keyPath, !!idbindex.unique, !!idbindex.multiEntry, false, keyPath && typeof keyPath !==
|
|
3800
|
+
var index = createIndexSpec(idbindex.name, keyPath, !!idbindex.unique, !!idbindex.multiEntry, false, keyPath && typeof keyPath !== 'string', false);
|
|
3540
3801
|
indexes.push(index);
|
|
3541
3802
|
}
|
|
3542
3803
|
globalSchema[storeName] = createTableSchema(storeName, primKey, indexes);
|
|
@@ -3545,14 +3806,15 @@ function buildGlobalSchema(db, idbdb, tmpTrans) {
|
|
|
3545
3806
|
}
|
|
3546
3807
|
function readGlobalSchema(db, idbdb, tmpTrans) {
|
|
3547
3808
|
db.verno = idbdb.version / 10;
|
|
3548
|
-
const globalSchema = db._dbSchema = buildGlobalSchema(db, idbdb, tmpTrans);
|
|
3809
|
+
const globalSchema = (db._dbSchema = buildGlobalSchema(db, idbdb, tmpTrans));
|
|
3549
3810
|
db._storeNames = slice(idbdb.objectStoreNames, 0);
|
|
3550
3811
|
setApiOnPlace(db, [db._allTables], keys(globalSchema), globalSchema);
|
|
3551
3812
|
}
|
|
3552
3813
|
function verifyInstalledSchema(db, tmpTrans) {
|
|
3553
3814
|
const installedSchema = buildGlobalSchema(db, db.idbdb, tmpTrans);
|
|
3554
3815
|
const diff = getSchemaDiff(installedSchema, db._dbSchema);
|
|
3555
|
-
return !(diff.add.length ||
|
|
3816
|
+
return !(diff.add.length ||
|
|
3817
|
+
diff.change.some((ch) => ch.add.length || ch.change.length));
|
|
3556
3818
|
}
|
|
3557
3819
|
function adjustToExistingIndexNames(db, schema, idbtrans) {
|
|
3558
3820
|
const storeNames = idbtrans.db.objectStoreNames;
|
|
@@ -3563,7 +3825,9 @@ function adjustToExistingIndexNames(db, schema, idbtrans) {
|
|
|
3563
3825
|
for (let j = 0; j < store.indexNames.length; ++j) {
|
|
3564
3826
|
const indexName = store.indexNames[j];
|
|
3565
3827
|
const keyPath = store.index(indexName).keyPath;
|
|
3566
|
-
const dexieName = typeof keyPath === 'string'
|
|
3828
|
+
const dexieName = typeof keyPath === 'string'
|
|
3829
|
+
? keyPath
|
|
3830
|
+
: '[' + slice(keyPath).join('+') + ']';
|
|
3567
3831
|
if (schema[storeName]) {
|
|
3568
3832
|
const indexSpec = schema[storeName].idxByName[dexieName];
|
|
3569
3833
|
if (indexSpec) {
|
|
@@ -3574,9 +3838,11 @@ function adjustToExistingIndexNames(db, schema, idbtrans) {
|
|
|
3574
3838
|
}
|
|
3575
3839
|
}
|
|
3576
3840
|
}
|
|
3577
|
-
if (typeof navigator !== 'undefined' &&
|
|
3841
|
+
if (typeof navigator !== 'undefined' &&
|
|
3842
|
+
/Safari/.test(navigator.userAgent) &&
|
|
3578
3843
|
!/(Chrome\/|Edge\/)/.test(navigator.userAgent) &&
|
|
3579
|
-
_global.WorkerGlobalScope &&
|
|
3844
|
+
_global.WorkerGlobalScope &&
|
|
3845
|
+
_global instanceof _global.WorkerGlobalScope &&
|
|
3580
3846
|
[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604) {
|
|
3581
3847
|
db._hasGetAll = false;
|
|
3582
3848
|
}
|
|
@@ -3586,8 +3852,10 @@ function parseIndexSyntax(primKeyAndIndexes) {
|
|
|
3586
3852
|
const typeSplit = index.split(':');
|
|
3587
3853
|
const type = typeSplit[1]?.trim();
|
|
3588
3854
|
index = typeSplit[0].trim();
|
|
3589
|
-
const name = index.replace(/([&*]|\+\+)/g,
|
|
3590
|
-
const keyPath = /^\[/.test(name)
|
|
3855
|
+
const name = index.replace(/([&*]|\+\+)/g, '');
|
|
3856
|
+
const keyPath = /^\[/.test(name)
|
|
3857
|
+
? name.match(/^\[(.*)\]$/)[1].split('+')
|
|
3858
|
+
: name;
|
|
3591
3859
|
return createIndexSpec(name, keyPath || null, /\&/.test(index), /\*/.test(index), /\+\+/.test(index), isArray(keyPath), indexNum === 0, type);
|
|
3592
3860
|
});
|
|
3593
3861
|
}
|
|
@@ -3654,21 +3922,22 @@ function createVersionConstructor(db) {
|
|
|
3654
3922
|
storesSource: null,
|
|
3655
3923
|
dbschema: {},
|
|
3656
3924
|
tables: {},
|
|
3657
|
-
contentUpgrade: null
|
|
3925
|
+
contentUpgrade: null,
|
|
3658
3926
|
};
|
|
3659
3927
|
});
|
|
3660
3928
|
}
|
|
3661
3929
|
|
|
3662
3930
|
const connections = createConnectionsManager();
|
|
3663
3931
|
function createConnectionsManager() {
|
|
3664
|
-
if (typeof FinalizationRegistry !== 'undefined' &&
|
|
3932
|
+
if (typeof FinalizationRegistry !== 'undefined' &&
|
|
3933
|
+
typeof WeakRef !== 'undefined') {
|
|
3665
3934
|
const _refs = new Set();
|
|
3666
3935
|
const _registry = new FinalizationRegistry((ref) => {
|
|
3667
3936
|
_refs.delete(ref);
|
|
3668
3937
|
});
|
|
3669
3938
|
const toArray = () => {
|
|
3670
3939
|
return Array.from(_refs)
|
|
3671
|
-
.map(ref => ref.deref())
|
|
3940
|
+
.map((ref) => ref.deref())
|
|
3672
3941
|
.filter((db) => db !== undefined);
|
|
3673
3942
|
};
|
|
3674
3943
|
const add = (db) => {
|
|
@@ -3717,19 +3986,19 @@ function createConnectionsManager() {
|
|
|
3717
3986
|
}
|
|
3718
3987
|
|
|
3719
3988
|
function getDbNamesTable(indexedDB, IDBKeyRange) {
|
|
3720
|
-
let dbNamesDB = indexedDB[
|
|
3989
|
+
let dbNamesDB = indexedDB['_dbNamesDB'];
|
|
3721
3990
|
if (!dbNamesDB) {
|
|
3722
|
-
dbNamesDB = indexedDB[
|
|
3991
|
+
dbNamesDB = indexedDB['_dbNamesDB'] = new Dexie$1(DBNAMES_DB, {
|
|
3723
3992
|
addons: [],
|
|
3724
3993
|
indexedDB,
|
|
3725
3994
|
IDBKeyRange,
|
|
3726
3995
|
});
|
|
3727
|
-
dbNamesDB.version(1).stores({ dbnames:
|
|
3996
|
+
dbNamesDB.version(1).stores({ dbnames: 'name' });
|
|
3728
3997
|
}
|
|
3729
|
-
return dbNamesDB.table(
|
|
3998
|
+
return dbNamesDB.table('dbnames');
|
|
3730
3999
|
}
|
|
3731
4000
|
function hasDatabasesNative(indexedDB) {
|
|
3732
|
-
return indexedDB && typeof indexedDB.databases ===
|
|
4001
|
+
return indexedDB && typeof indexedDB.databases === 'function';
|
|
3733
4002
|
}
|
|
3734
4003
|
function getDatabaseNames({ indexedDB, IDBKeyRange, }) {
|
|
3735
4004
|
return hasDatabasesNative(indexedDB)
|
|
@@ -3771,15 +4040,17 @@ function idbReady() {
|
|
|
3771
4040
|
}
|
|
3772
4041
|
|
|
3773
4042
|
function isEmptyRange(node) {
|
|
3774
|
-
return !(
|
|
4043
|
+
return !('from' in node);
|
|
3775
4044
|
}
|
|
3776
4045
|
const RangeSet = function (fromOrTree, to) {
|
|
3777
4046
|
if (this) {
|
|
3778
|
-
extend(this, arguments.length
|
|
4047
|
+
extend(this, arguments.length
|
|
4048
|
+
? { d: 1, from: fromOrTree, to: arguments.length > 1 ? to : fromOrTree }
|
|
4049
|
+
: { d: 0 });
|
|
3779
4050
|
}
|
|
3780
4051
|
else {
|
|
3781
4052
|
const rv = new RangeSet();
|
|
3782
|
-
if (fromOrTree &&
|
|
4053
|
+
if (fromOrTree && 'd' in fromOrTree) {
|
|
3783
4054
|
extend(rv, fromOrTree);
|
|
3784
4055
|
}
|
|
3785
4056
|
return rv;
|
|
@@ -3795,7 +4066,7 @@ props(RangeSet.prototype, {
|
|
|
3795
4066
|
return this;
|
|
3796
4067
|
},
|
|
3797
4068
|
addKeys(keys) {
|
|
3798
|
-
keys.forEach(key => addRange(this, key, key));
|
|
4069
|
+
keys.forEach((key) => addRange(this, key, key));
|
|
3799
4070
|
return this;
|
|
3800
4071
|
},
|
|
3801
4072
|
hasKey(key) {
|
|
@@ -3804,7 +4075,7 @@ props(RangeSet.prototype, {
|
|
|
3804
4075
|
},
|
|
3805
4076
|
[iteratorSymbol]() {
|
|
3806
4077
|
return getRangeSetIterator(this);
|
|
3807
|
-
}
|
|
4078
|
+
},
|
|
3808
4079
|
});
|
|
3809
4080
|
function addRange(target, from, to) {
|
|
3810
4081
|
const diff = cmp(from, to);
|
|
@@ -3847,7 +4118,7 @@ function addRange(target, from, to) {
|
|
|
3847
4118
|
}
|
|
3848
4119
|
}
|
|
3849
4120
|
function mergeRanges(target, newSet) {
|
|
3850
|
-
function _addRangeSet(target, { from, to, l, r }) {
|
|
4121
|
+
function _addRangeSet(target, { from, to, l, r, }) {
|
|
3851
4122
|
addRange(target, from, to);
|
|
3852
4123
|
if (l)
|
|
3853
4124
|
_addRangeSet(target, l);
|
|
@@ -3876,7 +4147,9 @@ function rangesOverlap(rangeSet1, rangeSet2) {
|
|
|
3876
4147
|
return false;
|
|
3877
4148
|
}
|
|
3878
4149
|
function getRangeSetIterator(node) {
|
|
3879
|
-
let state = isEmptyRange(node)
|
|
4150
|
+
let state = isEmptyRange(node)
|
|
4151
|
+
? null
|
|
4152
|
+
: { s: 0, n: node };
|
|
3880
4153
|
return {
|
|
3881
4154
|
next(key) {
|
|
3882
4155
|
const keyProvided = arguments.length > 0;
|
|
@@ -3912,9 +4185,9 @@ function getRangeSetIterator(node) {
|
|
|
3912
4185
|
}
|
|
3913
4186
|
function rebalance(target) {
|
|
3914
4187
|
const diff = (target.r?.d || 0) - (target.l?.d || 0);
|
|
3915
|
-
const r = diff > 1 ?
|
|
4188
|
+
const r = diff > 1 ? 'r' : diff < -1 ? 'l' : '';
|
|
3916
4189
|
if (r) {
|
|
3917
|
-
const l = r ===
|
|
4190
|
+
const l = r === 'r' ? 'l' : 'r';
|
|
3918
4191
|
const rootClone = { ...target };
|
|
3919
4192
|
const oldRootRight = target[r];
|
|
3920
4193
|
target.from = oldRootRight.from;
|
|
@@ -3931,7 +4204,7 @@ function computeDepth({ r, l }) {
|
|
|
3931
4204
|
}
|
|
3932
4205
|
|
|
3933
4206
|
function extendObservabilitySet(target, newSet) {
|
|
3934
|
-
keys(newSet).forEach(part => {
|
|
4207
|
+
keys(newSet).forEach((part) => {
|
|
3935
4208
|
if (target[part])
|
|
3936
4209
|
mergeRanges(target[part], newSet[part]);
|
|
3937
4210
|
else
|
|
@@ -3941,7 +4214,9 @@ function extendObservabilitySet(target, newSet) {
|
|
|
3941
4214
|
}
|
|
3942
4215
|
|
|
3943
4216
|
function obsSetsOverlap(os1, os2) {
|
|
3944
|
-
return os1.all ||
|
|
4217
|
+
return (os1.all ||
|
|
4218
|
+
os2.all ||
|
|
4219
|
+
Object.keys(os1).some((key) => os2[key] && rangesOverlap(os2[key], os1[key])));
|
|
3945
4220
|
}
|
|
3946
4221
|
|
|
3947
4222
|
const cache = {};
|
|
@@ -4006,9 +4281,7 @@ function dexieOpen(db) {
|
|
|
4006
4281
|
const state = db._state;
|
|
4007
4282
|
const { indexedDB } = db._deps;
|
|
4008
4283
|
if (state.isBeingOpened || db.idbdb)
|
|
4009
|
-
return state.dbReadyPromise.then(() => state.dbOpenError ?
|
|
4010
|
-
rejection(state.dbOpenError) :
|
|
4011
|
-
db);
|
|
4284
|
+
return state.dbReadyPromise.then(() => state.dbOpenError ? rejection(state.dbOpenError) : db);
|
|
4012
4285
|
state.isBeingOpened = true;
|
|
4013
4286
|
state.dbOpenError = null;
|
|
4014
4287
|
state.openComplete = false;
|
|
@@ -4026,14 +4299,14 @@ function dexieOpen(db) {
|
|
|
4026
4299
|
if (!indexedDB)
|
|
4027
4300
|
throw new exceptions.MissingAPI();
|
|
4028
4301
|
const dbName = db.name;
|
|
4029
|
-
const req = state.autoSchema || !nativeVerToOpen
|
|
4030
|
-
indexedDB.open(dbName)
|
|
4031
|
-
indexedDB.open(dbName, nativeVerToOpen);
|
|
4302
|
+
const req = state.autoSchema || !nativeVerToOpen
|
|
4303
|
+
? indexedDB.open(dbName)
|
|
4304
|
+
: indexedDB.open(dbName, nativeVerToOpen);
|
|
4032
4305
|
if (!req)
|
|
4033
4306
|
throw new exceptions.MissingAPI();
|
|
4034
4307
|
req.onerror = eventRejectHandler(reject);
|
|
4035
4308
|
req.onblocked = wrap(db._fireOnBlocked);
|
|
4036
|
-
req.onupgradeneeded = wrap(e => {
|
|
4309
|
+
req.onupgradeneeded = wrap((e) => {
|
|
4037
4310
|
upgradeTransaction = req.transaction;
|
|
4038
4311
|
if (state.autoSchema && !db._options.allowEmptyDB) {
|
|
4039
4312
|
req.onerror = preventDefault;
|
|
@@ -4057,7 +4330,7 @@ function dexieOpen(db) {
|
|
|
4057
4330
|
}, reject);
|
|
4058
4331
|
req.onsuccess = wrap(() => {
|
|
4059
4332
|
upgradeTransaction = null;
|
|
4060
|
-
const idbdb = db.idbdb = req.result;
|
|
4333
|
+
const idbdb = (db.idbdb = req.result);
|
|
4061
4334
|
const objectStoreNames = slice(idbdb.objectStoreNames);
|
|
4062
4335
|
if (objectStoreNames.length > 0)
|
|
4063
4336
|
try {
|
|
@@ -4079,9 +4352,9 @@ function dexieOpen(db) {
|
|
|
4079
4352
|
catch (e) {
|
|
4080
4353
|
}
|
|
4081
4354
|
connections.add(db);
|
|
4082
|
-
idbdb.onversionchange = wrap(ev => {
|
|
4355
|
+
idbdb.onversionchange = wrap((ev) => {
|
|
4083
4356
|
state.vcFired = true;
|
|
4084
|
-
db.on(
|
|
4357
|
+
db.on('versionchange').fire(ev);
|
|
4085
4358
|
});
|
|
4086
4359
|
idbdb.onclose = wrap(() => {
|
|
4087
4360
|
db.close({ disableAutoOpen: false });
|
|
@@ -4090,16 +4363,16 @@ function dexieOpen(db) {
|
|
|
4090
4363
|
_onDatabaseCreated(db._deps, dbName);
|
|
4091
4364
|
resolve();
|
|
4092
4365
|
}, reject);
|
|
4093
|
-
}).catch(err => {
|
|
4366
|
+
}).catch((err) => {
|
|
4094
4367
|
switch (err?.name) {
|
|
4095
|
-
case
|
|
4368
|
+
case 'UnknownError':
|
|
4096
4369
|
if (state.PR1398_maxLoop > 0) {
|
|
4097
4370
|
state.PR1398_maxLoop--;
|
|
4098
4371
|
console.warn('Dexie: Workaround for Chrome UnknownError on open()');
|
|
4099
4372
|
return tryOpenDB();
|
|
4100
4373
|
}
|
|
4101
4374
|
break;
|
|
4102
|
-
case
|
|
4375
|
+
case 'VersionError':
|
|
4103
4376
|
if (nativeVerToOpen > 0) {
|
|
4104
4377
|
nativeVerToOpen = 0;
|
|
4105
4378
|
return tryOpenDB();
|
|
@@ -4110,8 +4383,11 @@ function dexieOpen(db) {
|
|
|
4110
4383
|
});
|
|
4111
4384
|
return DexiePromise.race([
|
|
4112
4385
|
openCanceller,
|
|
4113
|
-
(typeof navigator === 'undefined'
|
|
4114
|
-
|
|
4386
|
+
(typeof navigator === 'undefined'
|
|
4387
|
+
? DexiePromise.resolve()
|
|
4388
|
+
: idbReady()).then(tryOpenDB),
|
|
4389
|
+
])
|
|
4390
|
+
.then(() => {
|
|
4115
4391
|
throwIfCancelled();
|
|
4116
4392
|
state.onReadyBeingFired = [];
|
|
4117
4393
|
return DexiePromise.resolve(vip(() => db.on.ready.fire(db.vip))).then(function fireRemainders() {
|
|
@@ -4121,12 +4397,14 @@ function dexieOpen(db) {
|
|
|
4121
4397
|
return DexiePromise.resolve(vip(() => remainders(db.vip))).then(fireRemainders);
|
|
4122
4398
|
}
|
|
4123
4399
|
});
|
|
4124
|
-
})
|
|
4400
|
+
})
|
|
4401
|
+
.finally(() => {
|
|
4125
4402
|
if (state.openCanceller === openCanceller) {
|
|
4126
4403
|
state.onReadyBeingFired = null;
|
|
4127
4404
|
state.isBeingOpened = false;
|
|
4128
4405
|
}
|
|
4129
|
-
})
|
|
4406
|
+
})
|
|
4407
|
+
.catch((err) => {
|
|
4130
4408
|
state.dbOpenError = err;
|
|
4131
4409
|
try {
|
|
4132
4410
|
upgradeTransaction && upgradeTransaction.abort();
|
|
@@ -4136,16 +4414,19 @@ function dexieOpen(db) {
|
|
|
4136
4414
|
db._close();
|
|
4137
4415
|
}
|
|
4138
4416
|
return rejection(err);
|
|
4139
|
-
})
|
|
4417
|
+
})
|
|
4418
|
+
.finally(() => {
|
|
4140
4419
|
state.openComplete = true;
|
|
4141
4420
|
resolveDbReady();
|
|
4142
|
-
})
|
|
4421
|
+
})
|
|
4422
|
+
.then(() => {
|
|
4143
4423
|
if (wasCreated) {
|
|
4144
4424
|
const everything = {};
|
|
4145
|
-
db.tables.forEach(table => {
|
|
4146
|
-
table.schema.indexes.forEach(idx => {
|
|
4425
|
+
db.tables.forEach((table) => {
|
|
4426
|
+
table.schema.indexes.forEach((idx) => {
|
|
4147
4427
|
if (idx.name)
|
|
4148
|
-
everything[`idb://${db.name}/${table.name}/${idx.name}`] =
|
|
4428
|
+
everything[`idb://${db.name}/${table.name}/${idx.name}`] =
|
|
4429
|
+
new RangeSet(-Infinity, [[[]]]);
|
|
4149
4430
|
});
|
|
4150
4431
|
everything[`idb://${db.name}/${table.name}/`] = everything[`idb://${db.name}/${table.name}/:dels`] = new RangeSet(-Infinity, [[[]]]);
|
|
4151
4432
|
});
|
|
@@ -4157,14 +4438,17 @@ function dexieOpen(db) {
|
|
|
4157
4438
|
}
|
|
4158
4439
|
|
|
4159
4440
|
function awaitIterator(iterator) {
|
|
4160
|
-
var callNext = result => iterator.next(result), doThrow = error => iterator.throw(error), onSuccess = step(callNext), onError = step(doThrow);
|
|
4441
|
+
var callNext = (result) => iterator.next(result), doThrow = (error) => iterator.throw(error), onSuccess = step(callNext), onError = step(doThrow);
|
|
4161
4442
|
function step(getNext) {
|
|
4162
4443
|
return (val) => {
|
|
4163
4444
|
var next = getNext(val), value = next.value;
|
|
4164
|
-
return next.done
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
value
|
|
4445
|
+
return next.done
|
|
4446
|
+
? value
|
|
4447
|
+
: !value || typeof value.then !== 'function'
|
|
4448
|
+
? isArray(value)
|
|
4449
|
+
? Promise.all(value).then(onSuccess, onError)
|
|
4450
|
+
: onSuccess(value)
|
|
4451
|
+
: value.then(onSuccess, onError);
|
|
4168
4452
|
};
|
|
4169
4453
|
}
|
|
4170
4454
|
return step(callNext)();
|
|
@@ -4173,7 +4457,7 @@ function awaitIterator(iterator) {
|
|
|
4173
4457
|
function extractTransactionArgs(mode, _tableArgs_, scopeFunc) {
|
|
4174
4458
|
var i = arguments.length;
|
|
4175
4459
|
if (i < 2)
|
|
4176
|
-
throw new exceptions.InvalidArgument(
|
|
4460
|
+
throw new exceptions.InvalidArgument('Too few arguments');
|
|
4177
4461
|
var args = new Array(i - 1);
|
|
4178
4462
|
while (--i)
|
|
4179
4463
|
args[i - 1] = arguments[i];
|
|
@@ -4188,7 +4472,7 @@ function enterTransactionScope(db, mode, storeNames, parentTransaction, scopeFun
|
|
|
4188
4472
|
trans.explicit = true;
|
|
4189
4473
|
const zoneProps = {
|
|
4190
4474
|
trans: trans,
|
|
4191
|
-
transless: transless
|
|
4475
|
+
transless: transless,
|
|
4192
4476
|
};
|
|
4193
4477
|
if (parentTransaction) {
|
|
4194
4478
|
trans.idbtrans = parentTransaction.idbtrans;
|
|
@@ -4200,10 +4484,14 @@ function enterTransactionScope(db, mode, storeNames, parentTransaction, scopeFun
|
|
|
4200
4484
|
db._state.PR1398_maxLoop = 3;
|
|
4201
4485
|
}
|
|
4202
4486
|
catch (ex) {
|
|
4203
|
-
if (ex.name === errnames.InvalidState &&
|
|
4487
|
+
if (ex.name === errnames.InvalidState &&
|
|
4488
|
+
db.isOpen() &&
|
|
4489
|
+
--db._state.PR1398_maxLoop > 0) {
|
|
4204
4490
|
console.warn('Dexie: Need to reopen db');
|
|
4205
4491
|
db.close({ disableAutoOpen: false });
|
|
4206
|
-
return db
|
|
4492
|
+
return db
|
|
4493
|
+
.open()
|
|
4494
|
+
.then(() => enterTransactionScope(db, mode, storeNames, null, scopeFunc));
|
|
4207
4495
|
}
|
|
4208
4496
|
return rejection(ex);
|
|
4209
4497
|
}
|
|
@@ -4220,20 +4508,25 @@ function enterTransactionScope(db, mode, storeNames, parentTransaction, scopeFun
|
|
|
4220
4508
|
var decrementor = decrementExpectedAwaits.bind(null, null);
|
|
4221
4509
|
returnValue.then(decrementor, decrementor);
|
|
4222
4510
|
}
|
|
4223
|
-
else if (typeof returnValue.next === 'function' &&
|
|
4511
|
+
else if (typeof returnValue.next === 'function' &&
|
|
4512
|
+
typeof returnValue.throw === 'function') {
|
|
4224
4513
|
returnValue = awaitIterator(returnValue);
|
|
4225
4514
|
}
|
|
4226
4515
|
}
|
|
4227
4516
|
}, zoneProps);
|
|
4228
|
-
return (returnValue && typeof returnValue.then === 'function'
|
|
4229
|
-
|
|
4230
|
-
x
|
|
4231
|
-
|
|
4232
|
-
|
|
4517
|
+
return (returnValue && typeof returnValue.then === 'function'
|
|
4518
|
+
?
|
|
4519
|
+
DexiePromise.resolve(returnValue).then((x) => trans.active
|
|
4520
|
+
? x
|
|
4521
|
+
: rejection(new exceptions.PrematureCommit('Transaction committed too early. See http://bit.ly/2kdckMn')))
|
|
4522
|
+
:
|
|
4523
|
+
promiseFollowed.then(() => returnValue))
|
|
4524
|
+
.then((x) => {
|
|
4233
4525
|
if (parentTransaction)
|
|
4234
4526
|
trans._resolve();
|
|
4235
4527
|
return trans._completion.then(() => x);
|
|
4236
|
-
})
|
|
4528
|
+
})
|
|
4529
|
+
.catch((e) => {
|
|
4237
4530
|
trans._reject(e);
|
|
4238
4531
|
return rejection(e);
|
|
4239
4532
|
});
|
|
@@ -4256,8 +4549,13 @@ function createVirtualIndexMiddleware(down) {
|
|
|
4256
4549
|
const allVirtualIndexes = [];
|
|
4257
4550
|
function addVirtualIndexes(keyPath, keyTail, lowLevelIndex) {
|
|
4258
4551
|
const keyPathAlias = getKeyPathAlias(keyPath);
|
|
4259
|
-
const indexList = (indexLookup[keyPathAlias] =
|
|
4260
|
-
|
|
4552
|
+
const indexList = (indexLookup[keyPathAlias] =
|
|
4553
|
+
indexLookup[keyPathAlias] || []);
|
|
4554
|
+
const keyLength = keyPath == null
|
|
4555
|
+
? 0
|
|
4556
|
+
: typeof keyPath === 'string'
|
|
4557
|
+
? 1
|
|
4558
|
+
: keyPath.length;
|
|
4261
4559
|
const isVirtual = keyTail > 0;
|
|
4262
4560
|
const virtualIndex = {
|
|
4263
4561
|
...lowLevelIndex,
|
|
@@ -4269,23 +4567,23 @@ function createVirtualIndexMiddleware(down) {
|
|
|
4269
4567
|
keyTail,
|
|
4270
4568
|
keyLength,
|
|
4271
4569
|
extractKey: getKeyExtractor(keyPath),
|
|
4272
|
-
unique: !isVirtual && lowLevelIndex.unique
|
|
4570
|
+
unique: !isVirtual && lowLevelIndex.unique,
|
|
4273
4571
|
};
|
|
4274
4572
|
indexList.push(virtualIndex);
|
|
4275
4573
|
if (!virtualIndex.isPrimaryKey) {
|
|
4276
4574
|
allVirtualIndexes.push(virtualIndex);
|
|
4277
4575
|
}
|
|
4278
4576
|
if (keyLength > 1) {
|
|
4279
|
-
const virtualKeyPath = keyLength === 2
|
|
4280
|
-
keyPath[0]
|
|
4281
|
-
keyPath.slice(0, keyLength - 1);
|
|
4577
|
+
const virtualKeyPath = keyLength === 2
|
|
4578
|
+
? keyPath[0]
|
|
4579
|
+
: keyPath.slice(0, keyLength - 1);
|
|
4282
4580
|
addVirtualIndexes(virtualKeyPath, keyTail + 1, lowLevelIndex);
|
|
4283
4581
|
}
|
|
4284
4582
|
indexList.sort((a, b) => a.keyTail - b.keyTail);
|
|
4285
4583
|
return virtualIndex;
|
|
4286
4584
|
}
|
|
4287
4585
|
const primaryKey = addVirtualIndexes(schema.primaryKey.keyPath, 0, schema.primaryKey);
|
|
4288
|
-
indexLookup[
|
|
4586
|
+
indexLookup[':id'] = [primaryKey];
|
|
4289
4587
|
for (const index of schema.indexes) {
|
|
4290
4588
|
addVirtualIndexes(index.keyPath, 0, index);
|
|
4291
4589
|
}
|
|
@@ -4295,24 +4593,26 @@ function createVirtualIndexMiddleware(down) {
|
|
|
4295
4593
|
}
|
|
4296
4594
|
function translateRange(range, keyTail) {
|
|
4297
4595
|
return {
|
|
4298
|
-
type: range.type === 1
|
|
4299
|
-
2
|
|
4300
|
-
range.type,
|
|
4596
|
+
type: range.type === 1
|
|
4597
|
+
? 2
|
|
4598
|
+
: range.type,
|
|
4301
4599
|
lower: pad(range.lower, range.lowerOpen ? down.MAX_KEY : down.MIN_KEY, keyTail),
|
|
4302
4600
|
lowerOpen: true,
|
|
4303
4601
|
upper: pad(range.upper, range.upperOpen ? down.MIN_KEY : down.MAX_KEY, keyTail),
|
|
4304
|
-
upperOpen: true
|
|
4602
|
+
upperOpen: true,
|
|
4305
4603
|
};
|
|
4306
4604
|
}
|
|
4307
4605
|
function translateRequest(req) {
|
|
4308
4606
|
const index = req.query.index;
|
|
4309
|
-
return index.isVirtual
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4607
|
+
return index.isVirtual
|
|
4608
|
+
? {
|
|
4609
|
+
...req,
|
|
4610
|
+
query: {
|
|
4611
|
+
index: index.lowLevelIndex,
|
|
4612
|
+
range: translateRange(req.query.range, index.keyTail),
|
|
4613
|
+
},
|
|
4314
4614
|
}
|
|
4315
|
-
|
|
4615
|
+
: req;
|
|
4316
4616
|
}
|
|
4317
4617
|
const result = {
|
|
4318
4618
|
...table,
|
|
@@ -4320,7 +4620,7 @@ function createVirtualIndexMiddleware(down) {
|
|
|
4320
4620
|
...schema,
|
|
4321
4621
|
primaryKey,
|
|
4322
4622
|
indexes: allVirtualIndexes,
|
|
4323
|
-
getIndexByKeyPath: findBestIndex
|
|
4623
|
+
getIndexByKeyPath: findBestIndex,
|
|
4324
4624
|
},
|
|
4325
4625
|
count(req) {
|
|
4326
4626
|
return table.count(translateRequest(req));
|
|
@@ -4329,61 +4629,62 @@ function createVirtualIndexMiddleware(down) {
|
|
|
4329
4629
|
return table.query(translateRequest(req));
|
|
4330
4630
|
},
|
|
4331
4631
|
openCursor(req) {
|
|
4332
|
-
const { keyTail, isVirtual, keyLength } = req.query
|
|
4632
|
+
const { keyTail, isVirtual, keyLength } = req.query
|
|
4633
|
+
.index;
|
|
4333
4634
|
if (!isVirtual)
|
|
4334
4635
|
return table.openCursor(req);
|
|
4335
4636
|
function createVirtualCursor(cursor) {
|
|
4336
4637
|
function _continue(key) {
|
|
4337
|
-
key != null
|
|
4338
|
-
cursor.continue(pad(key, req.reverse ? down.MAX_KEY : down.MIN_KEY, keyTail))
|
|
4339
|
-
req.unique
|
|
4340
|
-
cursor.continue(cursor.key
|
|
4341
|
-
.
|
|
4342
|
-
? down.MIN_KEY
|
|
4343
|
-
|
|
4344
|
-
cursor.continue();
|
|
4638
|
+
key != null
|
|
4639
|
+
? cursor.continue(pad(key, req.reverse ? down.MAX_KEY : down.MIN_KEY, keyTail))
|
|
4640
|
+
: req.unique
|
|
4641
|
+
? cursor.continue(cursor.key
|
|
4642
|
+
.slice(0, keyLength)
|
|
4643
|
+
.concat(req.reverse ? down.MIN_KEY : down.MAX_KEY, keyTail))
|
|
4644
|
+
: cursor.continue();
|
|
4345
4645
|
}
|
|
4346
4646
|
const virtualCursor = Object.create(cursor, {
|
|
4347
4647
|
continue: { value: _continue },
|
|
4348
4648
|
continuePrimaryKey: {
|
|
4349
4649
|
value(key, primaryKey) {
|
|
4350
4650
|
cursor.continuePrimaryKey(pad(key, down.MAX_KEY, keyTail), primaryKey);
|
|
4351
|
-
}
|
|
4651
|
+
},
|
|
4352
4652
|
},
|
|
4353
4653
|
primaryKey: {
|
|
4354
4654
|
get() {
|
|
4355
4655
|
return cursor.primaryKey;
|
|
4356
|
-
}
|
|
4656
|
+
},
|
|
4357
4657
|
},
|
|
4358
4658
|
key: {
|
|
4359
4659
|
get() {
|
|
4360
4660
|
const key = cursor.key;
|
|
4361
|
-
return keyLength === 1
|
|
4362
|
-
key[0]
|
|
4363
|
-
key.slice(0, keyLength);
|
|
4364
|
-
}
|
|
4661
|
+
return keyLength === 1
|
|
4662
|
+
? key[0]
|
|
4663
|
+
: key.slice(0, keyLength);
|
|
4664
|
+
},
|
|
4365
4665
|
},
|
|
4366
4666
|
value: {
|
|
4367
4667
|
get() {
|
|
4368
4668
|
return cursor.value;
|
|
4369
|
-
}
|
|
4370
|
-
}
|
|
4669
|
+
},
|
|
4670
|
+
},
|
|
4371
4671
|
});
|
|
4372
4672
|
return virtualCursor;
|
|
4373
4673
|
}
|
|
4374
|
-
return table
|
|
4375
|
-
.
|
|
4376
|
-
|
|
4674
|
+
return table
|
|
4675
|
+
.openCursor(translateRequest(req))
|
|
4676
|
+
.then((cursor) => cursor && createVirtualCursor(cursor));
|
|
4677
|
+
},
|
|
4377
4678
|
};
|
|
4378
4679
|
return result;
|
|
4379
|
-
}
|
|
4680
|
+
},
|
|
4380
4681
|
};
|
|
4381
4682
|
}
|
|
4382
4683
|
const virtualIndexMiddleware = {
|
|
4383
|
-
stack:
|
|
4384
|
-
name:
|
|
4684
|
+
stack: 'dbcore',
|
|
4685
|
+
name: 'VirtualIndexMiddleware',
|
|
4385
4686
|
level: 1,
|
|
4386
|
-
create: createVirtualIndexMiddleware
|
|
4687
|
+
create: createVirtualIndexMiddleware,
|
|
4387
4688
|
};
|
|
4388
4689
|
|
|
4389
4690
|
function getObjectDiff(a, b, rv, prfx) {
|
|
@@ -4427,8 +4728,8 @@ function getEffectiveKeys(primaryKey, req) {
|
|
|
4427
4728
|
}
|
|
4428
4729
|
|
|
4429
4730
|
const hooksMiddleware = {
|
|
4430
|
-
stack:
|
|
4431
|
-
name:
|
|
4731
|
+
stack: 'dbcore',
|
|
4732
|
+
name: 'HooksMiddleware',
|
|
4432
4733
|
level: 2,
|
|
4433
4734
|
create: (downCore) => ({
|
|
4434
4735
|
...downCore,
|
|
@@ -4463,22 +4764,24 @@ const hooksMiddleware = {
|
|
|
4463
4764
|
const dxTrans = PSD.trans;
|
|
4464
4765
|
const keys = req.keys || getEffectiveKeys(primaryKey, req);
|
|
4465
4766
|
if (!keys)
|
|
4466
|
-
throw new Error(
|
|
4467
|
-
req =
|
|
4468
|
-
|
|
4469
|
-
|
|
4767
|
+
throw new Error('Keys missing');
|
|
4768
|
+
req =
|
|
4769
|
+
req.type === 'add' || req.type === 'put'
|
|
4770
|
+
? { ...req, keys }
|
|
4771
|
+
: { ...req };
|
|
4470
4772
|
if (req.type !== 'delete')
|
|
4471
4773
|
req.values = [...req.values];
|
|
4472
4774
|
if (req.keys)
|
|
4473
4775
|
req.keys = [...req.keys];
|
|
4474
|
-
return getExistingValues(downTable, req, keys).then(existingValues => {
|
|
4776
|
+
return getExistingValues(downTable, req, keys).then((existingValues) => {
|
|
4475
4777
|
const contexts = keys.map((key, i) => {
|
|
4476
4778
|
const existingValue = existingValues[i];
|
|
4477
4779
|
const ctx = { onerror: null, onsuccess: null };
|
|
4478
4780
|
if (req.type === 'delete') {
|
|
4479
4781
|
deleting.fire.call(ctx, key, existingValue, dxTrans);
|
|
4480
4782
|
}
|
|
4481
|
-
else if (req.type === 'add' ||
|
|
4783
|
+
else if (req.type === 'add' ||
|
|
4784
|
+
existingValue === undefined) {
|
|
4482
4785
|
const generatedPrimaryKey = creating.fire.call(ctx, key, req.values[i], dxTrans);
|
|
4483
4786
|
if (key == null && generatedPrimaryKey != null) {
|
|
4484
4787
|
key = generatedPrimaryKey;
|
|
@@ -4493,9 +4796,10 @@ const hooksMiddleware = {
|
|
|
4493
4796
|
const additionalChanges = updating.fire.call(ctx, objectDiff, key, existingValue, dxTrans);
|
|
4494
4797
|
if (additionalChanges) {
|
|
4495
4798
|
const requestedValue = req.values[i];
|
|
4496
|
-
Object.keys(additionalChanges).forEach(keyPath => {
|
|
4799
|
+
Object.keys(additionalChanges).forEach((keyPath) => {
|
|
4497
4800
|
if (hasOwn(requestedValue, keyPath)) {
|
|
4498
|
-
requestedValue[keyPath] =
|
|
4801
|
+
requestedValue[keyPath] =
|
|
4802
|
+
additionalChanges[keyPath];
|
|
4499
4803
|
}
|
|
4500
4804
|
else {
|
|
4501
4805
|
setByKeyPath(requestedValue, keyPath, additionalChanges[keyPath]);
|
|
@@ -4505,7 +4809,9 @@ const hooksMiddleware = {
|
|
|
4505
4809
|
}
|
|
4506
4810
|
return ctx;
|
|
4507
4811
|
});
|
|
4508
|
-
return downTable
|
|
4812
|
+
return downTable
|
|
4813
|
+
.mutate(req)
|
|
4814
|
+
.then(({ failures, results, numFailures, lastResult }) => {
|
|
4509
4815
|
for (let i = 0; i < keys.length; ++i) {
|
|
4510
4816
|
const primKey = results ? results[i] : keys[i];
|
|
4511
4817
|
const ctx = contexts[i];
|
|
@@ -4513,15 +4819,17 @@ const hooksMiddleware = {
|
|
|
4513
4819
|
ctx.onerror && ctx.onerror(failures[i]);
|
|
4514
4820
|
}
|
|
4515
4821
|
else {
|
|
4516
|
-
ctx.onsuccess &&
|
|
4517
|
-
req.
|
|
4518
|
-
|
|
4519
|
-
|
|
4822
|
+
ctx.onsuccess &&
|
|
4823
|
+
ctx.onsuccess(req.type === 'put' && existingValues[i]
|
|
4824
|
+
? req.values[i]
|
|
4825
|
+
: primKey
|
|
4826
|
+
);
|
|
4520
4827
|
}
|
|
4521
4828
|
}
|
|
4522
4829
|
return { failures, results, numFailures, lastResult };
|
|
4523
|
-
})
|
|
4524
|
-
|
|
4830
|
+
})
|
|
4831
|
+
.catch((error) => {
|
|
4832
|
+
contexts.forEach((ctx) => ctx.onerror && ctx.onerror(error));
|
|
4525
4833
|
return Promise.reject(error);
|
|
4526
4834
|
});
|
|
4527
4835
|
});
|
|
@@ -4530,30 +4838,52 @@ const hooksMiddleware = {
|
|
|
4530
4838
|
return deleteNextChunk(req.trans, req.range, 10000);
|
|
4531
4839
|
}
|
|
4532
4840
|
function deleteNextChunk(trans, range, limit) {
|
|
4533
|
-
return downTable
|
|
4841
|
+
return downTable
|
|
4842
|
+
.query({
|
|
4843
|
+
trans,
|
|
4844
|
+
values: false,
|
|
4845
|
+
query: { index: primaryKey, range },
|
|
4846
|
+
limit,
|
|
4847
|
+
})
|
|
4534
4848
|
.then(({ result }) => {
|
|
4535
|
-
return addPutOrDelete({
|
|
4849
|
+
return addPutOrDelete({
|
|
4850
|
+
type: 'delete',
|
|
4851
|
+
keys: result,
|
|
4852
|
+
trans,
|
|
4853
|
+
}).then((res) => {
|
|
4536
4854
|
if (res.numFailures > 0)
|
|
4537
4855
|
return Promise.reject(res.failures[0]);
|
|
4538
4856
|
if (result.length < limit) {
|
|
4539
|
-
return {
|
|
4857
|
+
return {
|
|
4858
|
+
failures: [],
|
|
4859
|
+
numFailures: 0,
|
|
4860
|
+
lastResult: undefined,
|
|
4861
|
+
};
|
|
4540
4862
|
}
|
|
4541
4863
|
else {
|
|
4542
|
-
return deleteNextChunk(trans, {
|
|
4864
|
+
return deleteNextChunk(trans, {
|
|
4865
|
+
...range,
|
|
4866
|
+
lower: result[result.length - 1],
|
|
4867
|
+
lowerOpen: true,
|
|
4868
|
+
}, limit);
|
|
4543
4869
|
}
|
|
4544
4870
|
});
|
|
4545
4871
|
});
|
|
4546
4872
|
}
|
|
4547
|
-
}
|
|
4873
|
+
},
|
|
4548
4874
|
};
|
|
4549
4875
|
return tableMiddleware;
|
|
4550
4876
|
},
|
|
4551
|
-
})
|
|
4877
|
+
}),
|
|
4552
4878
|
};
|
|
4553
4879
|
function getExistingValues(table, req, effectiveKeys) {
|
|
4554
|
-
return req.type ===
|
|
4880
|
+
return req.type === 'add'
|
|
4555
4881
|
? Promise.resolve([])
|
|
4556
|
-
: table.getMany({
|
|
4882
|
+
: table.getMany({
|
|
4883
|
+
trans: req.trans,
|
|
4884
|
+
keys: effectiveKeys,
|
|
4885
|
+
cache: 'immutable',
|
|
4886
|
+
});
|
|
4557
4887
|
}
|
|
4558
4888
|
|
|
4559
4889
|
function getFromTransactionCache(keys, cache, clone) {
|
|
@@ -4576,7 +4906,7 @@ function getFromTransactionCache(keys, cache, clone) {
|
|
|
4576
4906
|
}
|
|
4577
4907
|
}
|
|
4578
4908
|
const cacheExistingValuesMiddleware = {
|
|
4579
|
-
stack:
|
|
4909
|
+
stack: 'dbcore',
|
|
4580
4910
|
level: -1,
|
|
4581
4911
|
create: (core) => {
|
|
4582
4912
|
return {
|
|
@@ -4588,21 +4918,21 @@ const cacheExistingValuesMiddleware = {
|
|
|
4588
4918
|
if (!req.cache) {
|
|
4589
4919
|
return table.getMany(req);
|
|
4590
4920
|
}
|
|
4591
|
-
const cachedResult = getFromTransactionCache(req.keys, req.trans[
|
|
4921
|
+
const cachedResult = getFromTransactionCache(req.keys, req.trans['_cache'], req.cache === 'clone');
|
|
4592
4922
|
if (cachedResult) {
|
|
4593
4923
|
return DexiePromise.resolve(cachedResult);
|
|
4594
4924
|
}
|
|
4595
4925
|
return table.getMany(req).then((res) => {
|
|
4596
|
-
req.trans[
|
|
4926
|
+
req.trans['_cache'] = {
|
|
4597
4927
|
keys: req.keys,
|
|
4598
|
-
values: req.cache ===
|
|
4928
|
+
values: req.cache === 'clone' ? deepClone(res) : res,
|
|
4599
4929
|
};
|
|
4600
4930
|
return res;
|
|
4601
4931
|
});
|
|
4602
4932
|
},
|
|
4603
4933
|
mutate: (req) => {
|
|
4604
|
-
if (req.type !==
|
|
4605
|
-
req.trans[
|
|
4934
|
+
if (req.type !== 'add')
|
|
4935
|
+
req.trans['_cache'] = null;
|
|
4606
4936
|
return table.mutate(req);
|
|
4607
4937
|
},
|
|
4608
4938
|
};
|
|
@@ -4635,9 +4965,9 @@ function isCachableRequest(type, req) {
|
|
|
4635
4965
|
}
|
|
4636
4966
|
|
|
4637
4967
|
const observabilityMiddleware = {
|
|
4638
|
-
stack:
|
|
4968
|
+
stack: 'dbcore',
|
|
4639
4969
|
level: 0,
|
|
4640
|
-
name:
|
|
4970
|
+
name: 'Observability',
|
|
4641
4971
|
create: (core) => {
|
|
4642
4972
|
const dbName = core.schema.name;
|
|
4643
4973
|
const FULL_RANGE = new RangeSet(core.MIN_KEY, core.MAX_KEY);
|
|
@@ -4654,7 +4984,9 @@ const observabilityMiddleware = {
|
|
|
4654
4984
|
const { schema } = table;
|
|
4655
4985
|
const { primaryKey, indexes } = schema;
|
|
4656
4986
|
const { extractKey, outbound } = primaryKey;
|
|
4657
|
-
const indexesWithAutoIncPK = primaryKey.autoIncrement &&
|
|
4987
|
+
const indexesWithAutoIncPK = primaryKey.autoIncrement &&
|
|
4988
|
+
indexes.filter((index) => index.compound &&
|
|
4989
|
+
index.keyPath.includes(primaryKey.keyPath));
|
|
4658
4990
|
const tableClone = {
|
|
4659
4991
|
...table,
|
|
4660
4992
|
mutate: (req) => {
|
|
@@ -4665,20 +4997,25 @@ const observabilityMiddleware = {
|
|
|
4665
4997
|
return (mutatedParts[part] ||
|
|
4666
4998
|
(mutatedParts[part] = new RangeSet()));
|
|
4667
4999
|
};
|
|
4668
|
-
const pkRangeSet = getRangeSet(
|
|
4669
|
-
const delsRangeSet = getRangeSet(
|
|
5000
|
+
const pkRangeSet = getRangeSet('');
|
|
5001
|
+
const delsRangeSet = getRangeSet(':dels');
|
|
4670
5002
|
const { type } = req;
|
|
4671
|
-
let [keys, newObjs] = req.type ===
|
|
5003
|
+
let [keys, newObjs] = req.type === 'deleteRange'
|
|
4672
5004
|
? [req.range]
|
|
4673
|
-
: req.type ===
|
|
5005
|
+
: req.type === 'delete'
|
|
4674
5006
|
? [req.keys]
|
|
4675
5007
|
: req.values.length < 50
|
|
4676
|
-
? [
|
|
5008
|
+
? [
|
|
5009
|
+
getEffectiveKeys(primaryKey, req).filter((id) => id),
|
|
5010
|
+
req.values,
|
|
5011
|
+
]
|
|
4677
5012
|
: [];
|
|
4678
|
-
const oldCache = req.trans[
|
|
5013
|
+
const oldCache = req.trans['_cache'];
|
|
4679
5014
|
if (isArray(keys)) {
|
|
4680
5015
|
pkRangeSet.addKeys(keys);
|
|
4681
|
-
const oldObjs = type === 'delete' || keys.length === newObjs.length
|
|
5016
|
+
const oldObjs = type === 'delete' || keys.length === newObjs.length
|
|
5017
|
+
? getFromTransactionCache(keys, oldCache)
|
|
5018
|
+
: null;
|
|
4682
5019
|
if (!oldObjs) {
|
|
4683
5020
|
delsRangeSet.addKeys(keys);
|
|
4684
5021
|
}
|
|
@@ -4689,7 +5026,7 @@ const observabilityMiddleware = {
|
|
|
4689
5026
|
else if (keys) {
|
|
4690
5027
|
const range = {
|
|
4691
5028
|
from: keys.lower ?? core.MIN_KEY,
|
|
4692
|
-
to: keys.upper ?? core.MAX_KEY
|
|
5029
|
+
to: keys.upper ?? core.MAX_KEY,
|
|
4693
5030
|
};
|
|
4694
5031
|
delsRangeSet.add(range);
|
|
4695
5032
|
pkRangeSet.add(range);
|
|
@@ -4697,15 +5034,15 @@ const observabilityMiddleware = {
|
|
|
4697
5034
|
else {
|
|
4698
5035
|
pkRangeSet.add(FULL_RANGE);
|
|
4699
5036
|
delsRangeSet.add(FULL_RANGE);
|
|
4700
|
-
schema.indexes.forEach(idx => getRangeSet(idx.name).add(FULL_RANGE));
|
|
5037
|
+
schema.indexes.forEach((idx) => getRangeSet(idx.name).add(FULL_RANGE));
|
|
4701
5038
|
}
|
|
4702
5039
|
return table.mutate(req).then((res) => {
|
|
4703
5040
|
if (keys && (req.type === 'add' || req.type === 'put')) {
|
|
4704
5041
|
pkRangeSet.addKeys(res.results);
|
|
4705
5042
|
if (indexesWithAutoIncPK) {
|
|
4706
|
-
indexesWithAutoIncPK.forEach(idx => {
|
|
4707
|
-
const idxVals = req.values.map(v => idx.extractKey(v));
|
|
4708
|
-
const pkPos = idx.keyPath.findIndex(prop => prop === primaryKey.keyPath);
|
|
5043
|
+
indexesWithAutoIncPK.forEach((idx) => {
|
|
5044
|
+
const idxVals = req.values.map((v) => idx.extractKey(v));
|
|
5045
|
+
const pkPos = idx.keyPath.findIndex((prop) => prop === primaryKey.keyPath);
|
|
4709
5046
|
for (let i = 0, len = res.results.length; i < len; ++i) {
|
|
4710
5047
|
idxVals[i][pkPos] = res.results[i];
|
|
4711
5048
|
}
|
|
@@ -4733,9 +5070,10 @@ const observabilityMiddleware = {
|
|
|
4733
5070
|
tableClone[method] = function (req) {
|
|
4734
5071
|
const { subscr } = PSD;
|
|
4735
5072
|
const isLiveQuery = !!subscr;
|
|
4736
|
-
let cachable = isCachableContext(PSD, table) &&
|
|
5073
|
+
let cachable = isCachableContext(PSD, table) &&
|
|
5074
|
+
isCachableRequest(method, req);
|
|
4737
5075
|
const obsSet = cachable
|
|
4738
|
-
? req.obsSet = {}
|
|
5076
|
+
? (req.obsSet = {})
|
|
4739
5077
|
: subscr;
|
|
4740
5078
|
if (isLiveQuery) {
|
|
4741
5079
|
const getRangeSet = (indexName) => {
|
|
@@ -4743,21 +5081,23 @@ const observabilityMiddleware = {
|
|
|
4743
5081
|
return (obsSet[part] ||
|
|
4744
5082
|
(obsSet[part] = new RangeSet()));
|
|
4745
5083
|
};
|
|
4746
|
-
const pkRangeSet = getRangeSet(
|
|
4747
|
-
const delsRangeSet = getRangeSet(
|
|
5084
|
+
const pkRangeSet = getRangeSet('');
|
|
5085
|
+
const delsRangeSet = getRangeSet(':dels');
|
|
4748
5086
|
const [queriedIndex, queriedRanges] = readSubscribers[method](req);
|
|
4749
|
-
if (method === 'query' &&
|
|
5087
|
+
if (method === 'query' &&
|
|
5088
|
+
queriedIndex.isPrimaryKey &&
|
|
5089
|
+
!req.values) {
|
|
4750
5090
|
delsRangeSet.add(queriedRanges);
|
|
4751
5091
|
}
|
|
4752
5092
|
else {
|
|
4753
|
-
getRangeSet(queriedIndex.name ||
|
|
5093
|
+
getRangeSet(queriedIndex.name || '').add(queriedRanges);
|
|
4754
5094
|
}
|
|
4755
5095
|
if (!queriedIndex.isPrimaryKey) {
|
|
4756
|
-
if (method ===
|
|
5096
|
+
if (method === 'count') {
|
|
4757
5097
|
delsRangeSet.add(FULL_RANGE);
|
|
4758
5098
|
}
|
|
4759
5099
|
else {
|
|
4760
|
-
const keysPromise = method ===
|
|
5100
|
+
const keysPromise = method === 'query' &&
|
|
4761
5101
|
outbound &&
|
|
4762
5102
|
req.values &&
|
|
4763
5103
|
table.query({
|
|
@@ -4765,9 +5105,9 @@ const observabilityMiddleware = {
|
|
|
4765
5105
|
values: false,
|
|
4766
5106
|
});
|
|
4767
5107
|
return table[method].apply(this, arguments).then((res) => {
|
|
4768
|
-
if (method ===
|
|
5108
|
+
if (method === 'query') {
|
|
4769
5109
|
if (outbound && req.values) {
|
|
4770
|
-
return keysPromise.then(({ result: resultingKeys }) => {
|
|
5110
|
+
return keysPromise.then(({ result: resultingKeys, }) => {
|
|
4771
5111
|
pkRangeSet.addKeys(resultingKeys);
|
|
4772
5112
|
return res;
|
|
4773
5113
|
});
|
|
@@ -4782,9 +5122,10 @@ const observabilityMiddleware = {
|
|
|
4782
5122
|
delsRangeSet.addKeys(pKeys);
|
|
4783
5123
|
}
|
|
4784
5124
|
}
|
|
4785
|
-
else if (method ===
|
|
5125
|
+
else if (method === 'openCursor') {
|
|
4786
5126
|
const cursor = res;
|
|
4787
|
-
const wantValues = req
|
|
5127
|
+
const wantValues = req
|
|
5128
|
+
.values;
|
|
4788
5129
|
return (cursor &&
|
|
4789
5130
|
Object.create(cursor, {
|
|
4790
5131
|
key: {
|
|
@@ -4802,7 +5143,8 @@ const observabilityMiddleware = {
|
|
|
4802
5143
|
},
|
|
4803
5144
|
value: {
|
|
4804
5145
|
get() {
|
|
4805
|
-
wantValues &&
|
|
5146
|
+
wantValues &&
|
|
5147
|
+
pkRangeSet.addKey(cursor.primaryKey);
|
|
4806
5148
|
return cursor.value;
|
|
4807
5149
|
},
|
|
4808
5150
|
},
|
|
@@ -4823,13 +5165,15 @@ const observabilityMiddleware = {
|
|
|
4823
5165
|
};
|
|
4824
5166
|
function trackAffectedIndexes(getRangeSet, schema, oldObjs, newObjs) {
|
|
4825
5167
|
function addAffectedIndex(ix) {
|
|
4826
|
-
const rangeSet = getRangeSet(ix.name ||
|
|
5168
|
+
const rangeSet = getRangeSet(ix.name || '');
|
|
4827
5169
|
function extractKey(obj) {
|
|
4828
5170
|
return obj != null ? ix.extractKey(obj) : null;
|
|
4829
5171
|
}
|
|
4830
5172
|
const addKeyOrKeys = (key) => ix.multiEntry && isArray(key)
|
|
4831
|
-
?
|
|
4832
|
-
|
|
5173
|
+
?
|
|
5174
|
+
key.forEach((key) => rangeSet.addKey(key))
|
|
5175
|
+
:
|
|
5176
|
+
rangeSet.addKey(key);
|
|
4833
5177
|
(oldObjs || newObjs).forEach((_, i) => {
|
|
4834
5178
|
const oldKey = oldObjs && extractKey(oldObjs[i]);
|
|
4835
5179
|
const newKey = newObjs && extractKey(newObjs[i]);
|
|
@@ -5036,7 +5380,8 @@ function findCompatibleQuery(dbName, tableName, type, req) {
|
|
|
5036
5380
|
const reqDirection = req.direction ?? 'next';
|
|
5037
5381
|
const equalEntry = entries.find((entry) => entry.req.limit === req.limit &&
|
|
5038
5382
|
entry.req.values === req.values &&
|
|
5039
|
-
(entry.req.direction ?? 'next') ===
|
|
5383
|
+
(entry.req.direction ?? 'next') ===
|
|
5384
|
+
reqDirection &&
|
|
5040
5385
|
areRangesEqual(entry.req.query.range, req.query.range));
|
|
5041
5386
|
if (equalEntry)
|
|
5042
5387
|
return [
|
|
@@ -5048,7 +5393,8 @@ function findCompatibleQuery(dbName, tableName, type, req) {
|
|
|
5048
5393
|
const superEntry = entries.find((entry) => {
|
|
5049
5394
|
const limit = 'limit' in entry.req ? entry.req.limit : Infinity;
|
|
5050
5395
|
return (limit >= req.limit &&
|
|
5051
|
-
(entry.req.direction ?? 'next') ===
|
|
5396
|
+
(entry.req.direction ?? 'next') ===
|
|
5397
|
+
reqDirection &&
|
|
5052
5398
|
(req.values ? entry.req.values : true) &&
|
|
5053
5399
|
isSuperRange(entry.req.query.range, req.query.range));
|
|
5054
5400
|
});
|
|
@@ -5061,7 +5407,7 @@ function findCompatibleQuery(dbName, tableName, type, req) {
|
|
|
5061
5407
|
|
|
5062
5408
|
function subscribeToCacheEntry(cacheEntry, container, requery, signal) {
|
|
5063
5409
|
cacheEntry.subscribers.add(requery);
|
|
5064
|
-
signal.addEventListener(
|
|
5410
|
+
signal.addEventListener('abort', () => {
|
|
5065
5411
|
cacheEntry.subscribers.delete(requery);
|
|
5066
5412
|
if (cacheEntry.subscribers.size === 0) {
|
|
5067
5413
|
enqueForDeletion(cacheEntry, container);
|
|
@@ -5098,7 +5444,9 @@ const cacheMiddleware = {
|
|
|
5098
5444
|
if (tblCache) {
|
|
5099
5445
|
const table = core.table(storeName);
|
|
5100
5446
|
const ops = tblCache.optimisticOps.filter((op) => op.trans === idbtrans);
|
|
5101
|
-
if (idbtrans._explicit &&
|
|
5447
|
+
if (idbtrans._explicit &&
|
|
5448
|
+
wasCommitted &&
|
|
5449
|
+
idbtrans.mutatedParts) {
|
|
5102
5450
|
for (const entries of Object.values(tblCache.queries.query)) {
|
|
5103
5451
|
for (const entry of entries.slice()) {
|
|
5104
5452
|
if (obsSetsOverlap(entry.obsSet, idbtrans.mutatedParts)) {
|
|
@@ -5124,7 +5472,9 @@ const cacheMiddleware = {
|
|
|
5124
5472
|
}
|
|
5125
5473
|
else if (modRes !== entry.res) {
|
|
5126
5474
|
entry.res = modRes;
|
|
5127
|
-
entry.promise = DexiePromise.resolve({
|
|
5475
|
+
entry.promise = DexiePromise.resolve({
|
|
5476
|
+
result: modRes,
|
|
5477
|
+
});
|
|
5128
5478
|
}
|
|
5129
5479
|
}
|
|
5130
5480
|
else {
|
|
@@ -5172,7 +5522,9 @@ const cacheMiddleware = {
|
|
|
5172
5522
|
if (!tblCache)
|
|
5173
5523
|
return downTable.mutate(req);
|
|
5174
5524
|
const promise = downTable.mutate(req);
|
|
5175
|
-
if ((req.type === 'add' || req.type === 'put') &&
|
|
5525
|
+
if ((req.type === 'add' || req.type === 'put') &&
|
|
5526
|
+
(req.values.length >= 50 ||
|
|
5527
|
+
getEffectiveKeys(primKey, req).some((key) => key == null))) {
|
|
5176
5528
|
promise.then((res) => {
|
|
5177
5529
|
const reqWithResolvedKeys = {
|
|
5178
5530
|
...req,
|
|
@@ -5186,11 +5538,12 @@ const cacheMiddleware = {
|
|
|
5186
5538
|
};
|
|
5187
5539
|
setByKeyPath(valueWithKey, primKey.keyPath, res.results[i]);
|
|
5188
5540
|
return valueWithKey;
|
|
5189
|
-
})
|
|
5541
|
+
}),
|
|
5190
5542
|
};
|
|
5191
5543
|
const adjustedReq = adjustOptimisticFromFailures(tblCache, reqWithResolvedKeys, res);
|
|
5192
5544
|
tblCache.optimisticOps.push(adjustedReq);
|
|
5193
|
-
queueMicrotask(() => req.mutatedParts &&
|
|
5545
|
+
queueMicrotask(() => req.mutatedParts &&
|
|
5546
|
+
signalSubscribersLazily(req.mutatedParts));
|
|
5194
5547
|
});
|
|
5195
5548
|
}
|
|
5196
5549
|
else {
|
|
@@ -5214,16 +5567,20 @@ const cacheMiddleware = {
|
|
|
5214
5567
|
return promise;
|
|
5215
5568
|
},
|
|
5216
5569
|
query(req) {
|
|
5217
|
-
if (!isCachableContext(PSD, downTable) ||
|
|
5570
|
+
if (!isCachableContext(PSD, downTable) ||
|
|
5571
|
+
!isCachableRequest('query', req))
|
|
5218
5572
|
return downTable.query(req);
|
|
5219
|
-
const freezeResults = PSD.trans?.db._options.cache ===
|
|
5573
|
+
const freezeResults = PSD.trans?.db._options.cache ===
|
|
5574
|
+
'immutable';
|
|
5220
5575
|
const { requery, signal } = PSD;
|
|
5221
5576
|
let [cacheEntry, exactMatch, tblCache, container] = findCompatibleQuery(dbName, tableName, 'query', req);
|
|
5222
5577
|
if (cacheEntry && exactMatch) {
|
|
5223
5578
|
cacheEntry.obsSet = req.obsSet;
|
|
5224
5579
|
}
|
|
5225
5580
|
else {
|
|
5226
|
-
const promise = downTable
|
|
5581
|
+
const promise = downTable
|
|
5582
|
+
.query(req)
|
|
5583
|
+
.then((res) => {
|
|
5227
5584
|
const result = res.result;
|
|
5228
5585
|
if (cacheEntry)
|
|
5229
5586
|
cacheEntry.res = result;
|
|
@@ -5237,7 +5594,8 @@ const cacheMiddleware = {
|
|
|
5237
5594
|
res.result = deepClone(result);
|
|
5238
5595
|
}
|
|
5239
5596
|
return res;
|
|
5240
|
-
})
|
|
5597
|
+
})
|
|
5598
|
+
.catch((error) => {
|
|
5241
5599
|
if (container && cacheEntry)
|
|
5242
5600
|
delArrayItem(container, cacheEntry);
|
|
5243
5601
|
return Promise.reject(error);
|
|
@@ -5263,7 +5621,7 @@ const cacheMiddleware = {
|
|
|
5263
5621
|
},
|
|
5264
5622
|
objs: new Map(),
|
|
5265
5623
|
optimisticOps: [],
|
|
5266
|
-
unsignaledParts: {}
|
|
5624
|
+
unsignaledParts: {},
|
|
5267
5625
|
};
|
|
5268
5626
|
}
|
|
5269
5627
|
tblCache.queries.query[req.query.index.name || ''] = container;
|
|
@@ -5290,7 +5648,7 @@ function vipify(target, vipDb) {
|
|
|
5290
5648
|
if (prop === 'db')
|
|
5291
5649
|
return vipDb;
|
|
5292
5650
|
return Reflect.get(target, prop, receiver);
|
|
5293
|
-
}
|
|
5651
|
+
},
|
|
5294
5652
|
});
|
|
5295
5653
|
}
|
|
5296
5654
|
|
|
@@ -5306,13 +5664,13 @@ let Dexie$1 = class Dexie {
|
|
|
5306
5664
|
IDBKeyRange: deps.IDBKeyRange,
|
|
5307
5665
|
cache: 'cloned',
|
|
5308
5666
|
maxConnections: DEFAULT_MAX_CONNECTIONS,
|
|
5309
|
-
...options
|
|
5667
|
+
...options,
|
|
5310
5668
|
};
|
|
5311
5669
|
this._deps = {
|
|
5312
5670
|
indexedDB: options.indexedDB,
|
|
5313
|
-
IDBKeyRange: options.IDBKeyRange
|
|
5671
|
+
IDBKeyRange: options.IDBKeyRange,
|
|
5314
5672
|
};
|
|
5315
|
-
const { addons
|
|
5673
|
+
const { addons } = options;
|
|
5316
5674
|
this._dbSchema = {};
|
|
5317
5675
|
this._versions = [];
|
|
5318
5676
|
this._storeNames = [];
|
|
@@ -5332,7 +5690,7 @@ let Dexie$1 = class Dexie {
|
|
|
5332
5690
|
PR1398_maxLoop: 3,
|
|
5333
5691
|
autoOpen: options.autoOpen,
|
|
5334
5692
|
};
|
|
5335
|
-
state.dbReadyPromise = new DexiePromise(resolve => {
|
|
5693
|
+
state.dbReadyPromise = new DexiePromise((resolve) => {
|
|
5336
5694
|
state.dbReadyResolve = resolve;
|
|
5337
5695
|
});
|
|
5338
5696
|
state.openCanceller = new DexiePromise((_, reject) => {
|
|
@@ -5340,7 +5698,9 @@ let Dexie$1 = class Dexie {
|
|
|
5340
5698
|
});
|
|
5341
5699
|
this._state = state;
|
|
5342
5700
|
this.name = name;
|
|
5343
|
-
this.on = Events(this,
|
|
5701
|
+
this.on = Events(this, 'populate', 'blocked', 'versionchange', 'close', {
|
|
5702
|
+
ready: [promisableChain, nop],
|
|
5703
|
+
});
|
|
5344
5704
|
this.once = (event, callback) => {
|
|
5345
5705
|
const fn = (...args) => {
|
|
5346
5706
|
this.on(event).unsubscribe(fn);
|
|
@@ -5348,7 +5708,7 @@ let Dexie$1 = class Dexie {
|
|
|
5348
5708
|
};
|
|
5349
5709
|
return this.on(event, fn);
|
|
5350
5710
|
};
|
|
5351
|
-
this.on.ready.subscribe = override(this.on.ready.subscribe, subscribe => {
|
|
5711
|
+
this.on.ready.subscribe = override(this.on.ready.subscribe, (subscribe) => {
|
|
5352
5712
|
return (subscriber, bSticky) => {
|
|
5353
5713
|
Dexie.vip(() => {
|
|
5354
5714
|
const state = this._state;
|
|
@@ -5380,14 +5740,14 @@ let Dexie$1 = class Dexie {
|
|
|
5380
5740
|
this.Transaction = createTransactionConstructor(this);
|
|
5381
5741
|
this.Version = createVersionConstructor(this);
|
|
5382
5742
|
this.WhereClause = createWhereClauseConstructor(this);
|
|
5383
|
-
this.on(
|
|
5743
|
+
this.on('versionchange', (ev) => {
|
|
5384
5744
|
if (ev.newVersion > 0)
|
|
5385
5745
|
console.warn(`Another connection wants to upgrade database '${this.name}'. Closing db now to resume the upgrade.`);
|
|
5386
5746
|
else
|
|
5387
5747
|
console.warn(`Another connection wants to delete database '${this.name}'. Closing db now to resume the delete request.`);
|
|
5388
5748
|
this.close({ disableAutoOpen: false });
|
|
5389
5749
|
});
|
|
5390
|
-
this.on(
|
|
5750
|
+
this.on('blocked', (ev) => {
|
|
5391
5751
|
if (!ev.newVersion || ev.newVersion < ev.oldVersion)
|
|
5392
5752
|
console.warn(`Dexie.delete('${this.name}') was blocked`);
|
|
5393
5753
|
else
|
|
@@ -5395,11 +5755,12 @@ let Dexie$1 = class Dexie {
|
|
|
5395
5755
|
});
|
|
5396
5756
|
this._maxKey = getMaxKey(options.IDBKeyRange);
|
|
5397
5757
|
this._createTransaction = (mode, storeNames, dbschema, parentTransaction) => new this.Transaction(mode, storeNames, dbschema, this._options.chromeTransactionDurability, parentTransaction);
|
|
5398
|
-
this._fireOnBlocked = ev => {
|
|
5399
|
-
this.on(
|
|
5400
|
-
connections
|
|
5401
|
-
.
|
|
5402
|
-
.
|
|
5758
|
+
this._fireOnBlocked = (ev) => {
|
|
5759
|
+
this.on('blocked').fire(ev);
|
|
5760
|
+
connections
|
|
5761
|
+
.toArray()
|
|
5762
|
+
.filter((c) => c.name === this.name && c !== this && !c._state.vcFired)
|
|
5763
|
+
.map((c) => c.on('versionchange').fire(ev));
|
|
5403
5764
|
};
|
|
5404
5765
|
this.use(cacheExistingValuesMiddleware);
|
|
5405
5766
|
this.use(cacheMiddleware);
|
|
@@ -5416,27 +5777,27 @@ let Dexie$1 = class Dexie {
|
|
|
5416
5777
|
if (rv instanceof Table)
|
|
5417
5778
|
return vipify(rv, vipDB);
|
|
5418
5779
|
if (prop === 'tables')
|
|
5419
|
-
return rv.map(t => vipify(t, vipDB));
|
|
5780
|
+
return rv.map((t) => vipify(t, vipDB));
|
|
5420
5781
|
if (prop === '_createTransaction')
|
|
5421
5782
|
return function () {
|
|
5422
5783
|
const tx = rv.apply(this, arguments);
|
|
5423
5784
|
return vipify(tx, vipDB);
|
|
5424
5785
|
};
|
|
5425
5786
|
return rv;
|
|
5426
|
-
}
|
|
5787
|
+
},
|
|
5427
5788
|
});
|
|
5428
5789
|
this.vip = vipDB;
|
|
5429
|
-
addons.forEach(addon => addon(this));
|
|
5790
|
+
addons.forEach((addon) => addon(this));
|
|
5430
5791
|
}
|
|
5431
5792
|
version(versionNumber) {
|
|
5432
5793
|
if (isNaN(versionNumber) || versionNumber < 0.1)
|
|
5433
5794
|
throw new exceptions.Type(`Given version is not a positive number`);
|
|
5434
5795
|
versionNumber = Math.round(versionNumber * 10) / 10;
|
|
5435
5796
|
if (this.idbdb || this._state.isBeingOpened)
|
|
5436
|
-
throw new exceptions.Schema(
|
|
5797
|
+
throw new exceptions.Schema('Cannot add version when database is open');
|
|
5437
5798
|
this.verno = Math.max(this.verno, versionNumber);
|
|
5438
5799
|
const versions = this._versions;
|
|
5439
|
-
var versionInstance = versions.filter(v => v._cfg.version === versionNumber)[0];
|
|
5800
|
+
var versionInstance = versions.filter((v) => v._cfg.version === versionNumber)[0];
|
|
5440
5801
|
if (versionInstance)
|
|
5441
5802
|
return versionInstance;
|
|
5442
5803
|
versionInstance = new this.Version(versionNumber);
|
|
@@ -5447,33 +5808,43 @@ let Dexie$1 = class Dexie {
|
|
|
5447
5808
|
return versionInstance;
|
|
5448
5809
|
}
|
|
5449
5810
|
_whenReady(fn) {
|
|
5450
|
-
return
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
reject(new exceptions.DatabaseClosed());
|
|
5457
|
-
return;
|
|
5811
|
+
return this.idbdb &&
|
|
5812
|
+
(this._state.openComplete || PSD.letThrough || this._vip)
|
|
5813
|
+
? fn()
|
|
5814
|
+
: new DexiePromise((resolve, reject) => {
|
|
5815
|
+
if (this._state.openComplete) {
|
|
5816
|
+
return reject(new exceptions.DatabaseClosed(this._state.dbOpenError));
|
|
5458
5817
|
}
|
|
5459
|
-
this.
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5818
|
+
if (!this._state.isBeingOpened) {
|
|
5819
|
+
if (!this._state.autoOpen) {
|
|
5820
|
+
reject(new exceptions.DatabaseClosed());
|
|
5821
|
+
return;
|
|
5822
|
+
}
|
|
5823
|
+
this.open().catch(nop);
|
|
5824
|
+
}
|
|
5825
|
+
this._state.dbReadyPromise.then(resolve, reject);
|
|
5826
|
+
}).then(fn);
|
|
5463
5827
|
}
|
|
5464
5828
|
use({ stack, create, level, name }) {
|
|
5465
5829
|
if (name)
|
|
5466
5830
|
this.unuse({ stack, name });
|
|
5467
5831
|
const middlewares = this._middlewares[stack] || (this._middlewares[stack] = []);
|
|
5468
|
-
middlewares.push({
|
|
5832
|
+
middlewares.push({
|
|
5833
|
+
stack,
|
|
5834
|
+
create,
|
|
5835
|
+
level: level == null ? 10 : level,
|
|
5836
|
+
name,
|
|
5837
|
+
});
|
|
5469
5838
|
middlewares.sort((a, b) => a.level - b.level);
|
|
5470
5839
|
return this;
|
|
5471
5840
|
}
|
|
5472
|
-
unuse({ stack, name, create }) {
|
|
5841
|
+
unuse({ stack, name, create, }) {
|
|
5473
5842
|
if (stack && this._middlewares[stack]) {
|
|
5474
|
-
this._middlewares[stack] = this._middlewares[stack].filter(mw => create
|
|
5475
|
-
|
|
5476
|
-
|
|
5843
|
+
this._middlewares[stack] = this._middlewares[stack].filter((mw) => create
|
|
5844
|
+
? mw.create !== create
|
|
5845
|
+
: name
|
|
5846
|
+
? mw.name !== name
|
|
5847
|
+
: false);
|
|
5477
5848
|
}
|
|
5478
5849
|
return this;
|
|
5479
5850
|
}
|
|
@@ -5493,7 +5864,7 @@ let Dexie$1 = class Dexie {
|
|
|
5493
5864
|
this.idbdb = null;
|
|
5494
5865
|
}
|
|
5495
5866
|
if (!state.isBeingOpened) {
|
|
5496
|
-
state.dbReadyPromise = new DexiePromise(resolve => {
|
|
5867
|
+
state.dbReadyPromise = new DexiePromise((resolve) => {
|
|
5497
5868
|
state.dbReadyResolve = resolve;
|
|
5498
5869
|
});
|
|
5499
5870
|
state.openCanceller = new DexiePromise((_, reject) => {
|
|
@@ -5513,8 +5884,7 @@ let Dexie$1 = class Dexie {
|
|
|
5513
5884
|
}
|
|
5514
5885
|
else {
|
|
5515
5886
|
this._close();
|
|
5516
|
-
state.autoOpen = this._options.autoOpen ||
|
|
5517
|
-
state.isBeingOpened;
|
|
5887
|
+
state.autoOpen = this._options.autoOpen || state.isBeingOpened;
|
|
5518
5888
|
state.openComplete = false;
|
|
5519
5889
|
state.dbOpenError = null;
|
|
5520
5890
|
}
|
|
@@ -5534,7 +5904,7 @@ let Dexie$1 = class Dexie {
|
|
|
5534
5904
|
req.onblocked = this._fireOnBlocked;
|
|
5535
5905
|
};
|
|
5536
5906
|
if (hasInvalidArguments)
|
|
5537
|
-
throw new exceptions.InvalidArgument(
|
|
5907
|
+
throw new exceptions.InvalidArgument('Invalid closeOptions argument to db.delete()');
|
|
5538
5908
|
if (state.isBeingOpened) {
|
|
5539
5909
|
state.dbReadyPromise.then(doDelete);
|
|
5540
5910
|
}
|
|
@@ -5551,7 +5921,7 @@ let Dexie$1 = class Dexie {
|
|
|
5551
5921
|
}
|
|
5552
5922
|
hasBeenClosed() {
|
|
5553
5923
|
const dbOpenError = this._state.dbOpenError;
|
|
5554
|
-
return dbOpenError &&
|
|
5924
|
+
return dbOpenError && dbOpenError.name === 'DatabaseClosed';
|
|
5555
5925
|
}
|
|
5556
5926
|
hasFailed() {
|
|
5557
5927
|
return this._state.dbOpenError !== null;
|
|
@@ -5560,7 +5930,7 @@ let Dexie$1 = class Dexie {
|
|
|
5560
5930
|
return this._state.autoSchema;
|
|
5561
5931
|
}
|
|
5562
5932
|
get tables() {
|
|
5563
|
-
return keys(this._allTables).map(name => this._allTables[name]);
|
|
5933
|
+
return keys(this._allTables).map((name) => this._allTables[name]);
|
|
5564
5934
|
}
|
|
5565
5935
|
transaction() {
|
|
5566
5936
|
const args = extractTransactionArgs.apply(this, arguments);
|
|
@@ -5568,60 +5938,67 @@ let Dexie$1 = class Dexie {
|
|
|
5568
5938
|
}
|
|
5569
5939
|
_transaction(mode, tables, scopeFunc) {
|
|
5570
5940
|
let parentTransaction = PSD.trans;
|
|
5571
|
-
if (!parentTransaction ||
|
|
5941
|
+
if (!parentTransaction ||
|
|
5942
|
+
parentTransaction.db !== this ||
|
|
5943
|
+
mode.indexOf('!') !== -1)
|
|
5572
5944
|
parentTransaction = null;
|
|
5573
5945
|
const onlyIfCompatible = mode.indexOf('?') !== -1;
|
|
5574
5946
|
mode = mode.replace('!', '').replace('?', '');
|
|
5575
5947
|
let idbMode, storeNames;
|
|
5576
5948
|
try {
|
|
5577
|
-
storeNames = tables.map(table => {
|
|
5949
|
+
storeNames = tables.map((table) => {
|
|
5578
5950
|
var storeName = table instanceof this.Table ? table.name : table;
|
|
5579
5951
|
if (typeof storeName !== 'string')
|
|
5580
|
-
throw new TypeError(
|
|
5952
|
+
throw new TypeError('Invalid table argument to Dexie.transaction(). Only Table or String are allowed');
|
|
5581
5953
|
return storeName;
|
|
5582
5954
|
});
|
|
5583
|
-
if (mode ==
|
|
5955
|
+
if (mode == 'r' || mode === READONLY)
|
|
5584
5956
|
idbMode = READONLY;
|
|
5585
|
-
else if (mode ==
|
|
5957
|
+
else if (mode == 'rw' || mode == READWRITE)
|
|
5586
5958
|
idbMode = READWRITE;
|
|
5587
5959
|
else
|
|
5588
|
-
throw new exceptions.InvalidArgument(
|
|
5960
|
+
throw new exceptions.InvalidArgument('Invalid transaction mode: ' + mode);
|
|
5589
5961
|
if (parentTransaction) {
|
|
5590
5962
|
if (parentTransaction.mode === READONLY && idbMode === READWRITE) {
|
|
5591
5963
|
if (onlyIfCompatible) {
|
|
5592
5964
|
parentTransaction = null;
|
|
5593
5965
|
}
|
|
5594
5966
|
else
|
|
5595
|
-
throw new exceptions.SubTransaction(
|
|
5967
|
+
throw new exceptions.SubTransaction('Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY');
|
|
5596
5968
|
}
|
|
5597
5969
|
if (parentTransaction) {
|
|
5598
|
-
storeNames.forEach(storeName => {
|
|
5599
|
-
if (parentTransaction &&
|
|
5970
|
+
storeNames.forEach((storeName) => {
|
|
5971
|
+
if (parentTransaction &&
|
|
5972
|
+
parentTransaction.storeNames.indexOf(storeName) === -1) {
|
|
5600
5973
|
if (onlyIfCompatible) {
|
|
5601
5974
|
parentTransaction = null;
|
|
5602
5975
|
}
|
|
5603
5976
|
else
|
|
5604
|
-
throw new exceptions.SubTransaction(
|
|
5605
|
-
" not included in parent transaction.");
|
|
5977
|
+
throw new exceptions.SubTransaction('Table ' + storeName + ' not included in parent transaction.');
|
|
5606
5978
|
}
|
|
5607
5979
|
});
|
|
5608
5980
|
}
|
|
5609
|
-
if (onlyIfCompatible &&
|
|
5981
|
+
if (onlyIfCompatible &&
|
|
5982
|
+
parentTransaction &&
|
|
5983
|
+
!parentTransaction.active) {
|
|
5610
5984
|
parentTransaction = null;
|
|
5611
5985
|
}
|
|
5612
5986
|
}
|
|
5613
5987
|
}
|
|
5614
5988
|
catch (e) {
|
|
5615
|
-
return parentTransaction
|
|
5616
|
-
parentTransaction._promise(null, (_, reject) => {
|
|
5617
|
-
|
|
5989
|
+
return parentTransaction
|
|
5990
|
+
? parentTransaction._promise(null, (_, reject) => {
|
|
5991
|
+
reject(e);
|
|
5992
|
+
})
|
|
5993
|
+
: rejection(e);
|
|
5618
5994
|
}
|
|
5619
5995
|
const enterTransaction = enterTransactionScope.bind(null, this, idbMode, storeNames, parentTransaction, scopeFunc);
|
|
5620
|
-
return
|
|
5621
|
-
parentTransaction._promise(idbMode, enterTransaction,
|
|
5622
|
-
PSD.trans
|
|
5623
|
-
|
|
5624
|
-
|
|
5996
|
+
return parentTransaction
|
|
5997
|
+
? parentTransaction._promise(idbMode, enterTransaction, 'lock')
|
|
5998
|
+
: PSD.trans
|
|
5999
|
+
?
|
|
6000
|
+
usePSD(PSD.transless, () => this._whenReady(enterTransaction))
|
|
6001
|
+
: this._whenReady(enterTransaction);
|
|
5625
6002
|
}
|
|
5626
6003
|
table(tableName) {
|
|
5627
6004
|
if (!hasOwn(this._allTables, tableName)) {
|
|
@@ -5631,15 +6008,15 @@ let Dexie$1 = class Dexie {
|
|
|
5631
6008
|
}
|
|
5632
6009
|
};
|
|
5633
6010
|
|
|
5634
|
-
const symbolObservable = typeof Symbol !==
|
|
6011
|
+
const symbolObservable = typeof Symbol !== 'undefined' && 'observable' in Symbol
|
|
5635
6012
|
? Symbol.observable
|
|
5636
|
-
:
|
|
6013
|
+
: '@@observable';
|
|
5637
6014
|
class Observable {
|
|
5638
6015
|
constructor(subscribe) {
|
|
5639
6016
|
this._subscribe = subscribe;
|
|
5640
6017
|
}
|
|
5641
6018
|
subscribe(x, error, complete) {
|
|
5642
|
-
return this._subscribe(!x || typeof x ===
|
|
6019
|
+
return this._subscribe(!x || typeof x === 'function' ? { next: x, error, complete } : x);
|
|
5643
6020
|
}
|
|
5644
6021
|
[symbolObservable]() {
|
|
5645
6022
|
return this;
|
|
@@ -5649,8 +6026,11 @@ class Observable {
|
|
|
5649
6026
|
let domDeps;
|
|
5650
6027
|
try {
|
|
5651
6028
|
domDeps = {
|
|
5652
|
-
indexedDB: _global.indexedDB ||
|
|
5653
|
-
|
|
6029
|
+
indexedDB: _global.indexedDB ||
|
|
6030
|
+
_global.mozIndexedDB ||
|
|
6031
|
+
_global.webkitIndexedDB ||
|
|
6032
|
+
_global.msIndexedDB,
|
|
6033
|
+
IDBKeyRange: _global.IDBKeyRange || _global.webkitIDBKeyRange,
|
|
5654
6034
|
};
|
|
5655
6035
|
}
|
|
5656
6036
|
catch (e) {
|
|
@@ -5724,22 +6104,32 @@ function liveQuery(querier) {
|
|
|
5724
6104
|
signal: abortController.signal,
|
|
5725
6105
|
requery: doQuery,
|
|
5726
6106
|
querier,
|
|
5727
|
-
trans: null
|
|
6107
|
+
trans: null,
|
|
5728
6108
|
};
|
|
5729
6109
|
const ret = execute(ctx);
|
|
6110
|
+
if (!startedListening) {
|
|
6111
|
+
globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, mutationListener);
|
|
6112
|
+
startedListening = true;
|
|
6113
|
+
}
|
|
5730
6114
|
Promise.resolve(ret).then((result) => {
|
|
5731
6115
|
hasValue = true;
|
|
5732
6116
|
currentValue = result;
|
|
5733
6117
|
if (closed || ctx.signal.aborted) {
|
|
5734
6118
|
return;
|
|
5735
6119
|
}
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
|
|
6120
|
+
if (shouldNotify()) {
|
|
6121
|
+
doQuery();
|
|
6122
|
+
}
|
|
6123
|
+
else {
|
|
6124
|
+
currentObs = subscr;
|
|
6125
|
+
if (shouldNotify()) {
|
|
6126
|
+
doQuery();
|
|
6127
|
+
}
|
|
6128
|
+
else {
|
|
6129
|
+
accumMuts = {};
|
|
6130
|
+
execInGlobalContext(() => !closed && observer.next && observer.next(result));
|
|
6131
|
+
}
|
|
5741
6132
|
}
|
|
5742
|
-
execInGlobalContext(() => !closed && observer.next && observer.next(result));
|
|
5743
6133
|
}, (err) => {
|
|
5744
6134
|
hasValue = false;
|
|
5745
6135
|
if (!['DatabaseClosedError', 'AbortError'].includes(err?.name)) {
|
|
@@ -5768,10 +6158,13 @@ props(Dexie, {
|
|
|
5768
6158
|
return db.delete();
|
|
5769
6159
|
},
|
|
5770
6160
|
exists(name) {
|
|
5771
|
-
return new Dexie(name, { addons: [] })
|
|
6161
|
+
return new Dexie(name, { addons: [] })
|
|
6162
|
+
.open()
|
|
6163
|
+
.then((db) => {
|
|
5772
6164
|
db.close();
|
|
5773
6165
|
return true;
|
|
5774
|
-
})
|
|
6166
|
+
})
|
|
6167
|
+
.catch('NoSuchDatabaseError', () => false);
|
|
5775
6168
|
},
|
|
5776
6169
|
getDatabaseNames(cb) {
|
|
5777
6170
|
try {
|
|
@@ -5788,9 +6181,9 @@ props(Dexie, {
|
|
|
5788
6181
|
return Class;
|
|
5789
6182
|
},
|
|
5790
6183
|
ignoreTransaction(scopeFunc) {
|
|
5791
|
-
return PSD.trans
|
|
5792
|
-
usePSD(PSD.transless, scopeFunc)
|
|
5793
|
-
scopeFunc();
|
|
6184
|
+
return PSD.trans
|
|
6185
|
+
? usePSD(PSD.transless || globalPSD, scopeFunc)
|
|
6186
|
+
: scopeFunc();
|
|
5794
6187
|
},
|
|
5795
6188
|
vip,
|
|
5796
6189
|
async: function (generatorFn) {
|
|
@@ -5818,23 +6211,20 @@ props(Dexie, {
|
|
|
5818
6211
|
}
|
|
5819
6212
|
},
|
|
5820
6213
|
currentTransaction: {
|
|
5821
|
-
get: () => PSD.trans || null
|
|
6214
|
+
get: () => PSD.trans || null,
|
|
5822
6215
|
},
|
|
5823
6216
|
waitFor: function (promiseOrFunction, optionalTimeout) {
|
|
5824
|
-
const promise = DexiePromise.resolve(typeof promiseOrFunction === 'function'
|
|
5825
|
-
Dexie.ignoreTransaction(promiseOrFunction)
|
|
5826
|
-
promiseOrFunction)
|
|
5827
|
-
|
|
5828
|
-
return PSD.trans ?
|
|
5829
|
-
PSD.trans.waitFor(promise) :
|
|
5830
|
-
promise;
|
|
6217
|
+
const promise = DexiePromise.resolve(typeof promiseOrFunction === 'function'
|
|
6218
|
+
? Dexie.ignoreTransaction(promiseOrFunction)
|
|
6219
|
+
: promiseOrFunction).timeout(optionalTimeout || 60000);
|
|
6220
|
+
return PSD.trans ? PSD.trans.waitFor(promise) : promise;
|
|
5831
6221
|
},
|
|
5832
6222
|
Promise: DexiePromise,
|
|
5833
6223
|
debug: {
|
|
5834
6224
|
get: () => debug,
|
|
5835
|
-
set: value => {
|
|
6225
|
+
set: (value) => {
|
|
5836
6226
|
setDebug(value);
|
|
5837
|
-
}
|
|
6227
|
+
},
|
|
5838
6228
|
},
|
|
5839
6229
|
derive: derive,
|
|
5840
6230
|
extend: extend,
|
|
@@ -5855,24 +6245,25 @@ props(Dexie, {
|
|
|
5855
6245
|
minKey: minKey,
|
|
5856
6246
|
addons: [],
|
|
5857
6247
|
connections: {
|
|
5858
|
-
get: connections.toArray
|
|
6248
|
+
get: connections.toArray,
|
|
5859
6249
|
},
|
|
5860
6250
|
errnames: errnames,
|
|
5861
6251
|
dependencies: domDeps,
|
|
5862
6252
|
cache,
|
|
5863
6253
|
semVer: DEXIE_VERSION,
|
|
5864
6254
|
version: DEXIE_VERSION.split('.')
|
|
5865
|
-
.map(n => parseInt(n))
|
|
5866
|
-
.reduce((p, c, i) => p +
|
|
6255
|
+
.map((n) => parseInt(n))
|
|
6256
|
+
.reduce((p, c, i) => p + c / Math.pow(10, i * 2)),
|
|
5867
6257
|
});
|
|
5868
6258
|
Dexie.maxKey = getMaxKey(Dexie.dependencies.IDBKeyRange);
|
|
5869
6259
|
|
|
5870
|
-
if (typeof dispatchEvent !== 'undefined' &&
|
|
5871
|
-
|
|
6260
|
+
if (typeof dispatchEvent !== 'undefined' &&
|
|
6261
|
+
typeof addEventListener !== 'undefined') {
|
|
6262
|
+
globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, (updatedParts) => {
|
|
5872
6263
|
if (!propagatingLocally) {
|
|
5873
6264
|
let event;
|
|
5874
6265
|
event = new CustomEvent(STORAGE_MUTATED_DOM_EVENT_NAME, {
|
|
5875
|
-
detail: updatedParts
|
|
6266
|
+
detail: updatedParts,
|
|
5876
6267
|
});
|
|
5877
6268
|
propagatingLocally = true;
|
|
5878
6269
|
dispatchEvent(event);
|
|
@@ -5903,7 +6294,7 @@ let createBC = () => { };
|
|
|
5903
6294
|
if (typeof BroadcastChannel !== 'undefined') {
|
|
5904
6295
|
createBC = () => {
|
|
5905
6296
|
bc = new BroadcastChannel(STORAGE_MUTATED_DOM_EVENT_NAME);
|
|
5906
|
-
bc.onmessage = ev => ev.data && propagateLocally(ev.data);
|
|
6297
|
+
bc.onmessage = (ev) => ev.data && propagateLocally(ev.data);
|
|
5907
6298
|
};
|
|
5908
6299
|
createBC();
|
|
5909
6300
|
if (typeof bc.unref === 'function') {
|