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/dexie.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
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
|
*
|
|
@@ -48,10 +48,13 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
48
48
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
var _global = typeof globalThis !== 'undefined'
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
var _global = typeof globalThis !== 'undefined'
|
|
52
|
+
? globalThis
|
|
53
|
+
: typeof self !== 'undefined'
|
|
54
|
+
? self
|
|
55
|
+
: typeof window !== 'undefined'
|
|
56
|
+
? window
|
|
57
|
+
: global;
|
|
55
58
|
|
|
56
59
|
var keys = Object.keys;
|
|
57
60
|
var isArray = Array.isArray;
|
|
@@ -74,32 +77,38 @@ function hasOwn(obj, prop) {
|
|
|
74
77
|
function props(proto, extension) {
|
|
75
78
|
if (typeof extension === 'function')
|
|
76
79
|
extension = extension(getProto(proto));
|
|
77
|
-
(typeof Reflect ===
|
|
80
|
+
(typeof Reflect === 'undefined' ? keys : Reflect.ownKeys)(extension).forEach(function (key) {
|
|
78
81
|
setProp(proto, key, extension[key]);
|
|
79
82
|
});
|
|
80
83
|
}
|
|
81
84
|
var defineProperty = Object.defineProperty;
|
|
82
85
|
function setProp(obj, prop, functionOrGetSet, options) {
|
|
83
|
-
defineProperty(obj, prop, extend(functionOrGetSet &&
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
defineProperty(obj, prop, extend(functionOrGetSet &&
|
|
87
|
+
hasOwn(functionOrGetSet, 'get') &&
|
|
88
|
+
typeof functionOrGetSet.get === 'function'
|
|
89
|
+
? {
|
|
90
|
+
get: functionOrGetSet.get,
|
|
91
|
+
set: functionOrGetSet.set,
|
|
92
|
+
configurable: true,
|
|
93
|
+
}
|
|
94
|
+
: { value: functionOrGetSet, configurable: true, writable: true }, options));
|
|
86
95
|
}
|
|
87
96
|
function derive(Child) {
|
|
88
97
|
return {
|
|
89
98
|
from: function (Parent) {
|
|
90
99
|
Child.prototype = Object.create(Parent.prototype);
|
|
91
|
-
setProp(Child.prototype,
|
|
100
|
+
setProp(Child.prototype, 'constructor', Child);
|
|
92
101
|
return {
|
|
93
|
-
extend: props.bind(null, Child.prototype)
|
|
102
|
+
extend: props.bind(null, Child.prototype),
|
|
94
103
|
};
|
|
95
|
-
}
|
|
104
|
+
},
|
|
96
105
|
};
|
|
97
106
|
}
|
|
98
107
|
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
99
108
|
function getPropertyDescriptor(obj, prop) {
|
|
100
109
|
var pd = getOwnPropertyDescriptor(obj, prop);
|
|
101
110
|
var proto;
|
|
102
|
-
return pd || (proto = getProto(obj)) && getPropertyDescriptor(proto, prop);
|
|
111
|
+
return pd || ((proto = getProto(obj)) && getPropertyDescriptor(proto, prop));
|
|
103
112
|
}
|
|
104
113
|
var _slice = [].slice;
|
|
105
114
|
function slice(args, start, end) {
|
|
@@ -110,7 +119,7 @@ function override(origFunc, overridedFactory) {
|
|
|
110
119
|
}
|
|
111
120
|
function assert(b) {
|
|
112
121
|
if (!b)
|
|
113
|
-
throw new Error(
|
|
122
|
+
throw new Error('Assertion Failed');
|
|
114
123
|
}
|
|
115
124
|
function asap$1(fn) {
|
|
116
125
|
if (_global.setImmediate)
|
|
@@ -142,7 +151,9 @@ function getByKeyPath(obj, keyPath) {
|
|
|
142
151
|
var period = keyPath.indexOf('.');
|
|
143
152
|
if (period !== -1) {
|
|
144
153
|
var innerObj = obj[keyPath.substr(0, period)];
|
|
145
|
-
return innerObj == null
|
|
154
|
+
return innerObj == null
|
|
155
|
+
? undefined
|
|
156
|
+
: getByKeyPath(innerObj, keyPath.substr(period + 1));
|
|
146
157
|
}
|
|
147
158
|
return undefined;
|
|
148
159
|
}
|
|
@@ -162,7 +173,7 @@ function setByKeyPath(obj, keyPath, value) {
|
|
|
162
173
|
if (period !== -1) {
|
|
163
174
|
var currentKeyPath = keyPath.substr(0, period);
|
|
164
175
|
var remainingKeyPath = keyPath.substr(period + 1);
|
|
165
|
-
if (remainingKeyPath ===
|
|
176
|
+
if (remainingKeyPath === '')
|
|
166
177
|
if (value === undefined) {
|
|
167
178
|
if (isArray(obj) && !isNaN(parseInt(currentKeyPath)))
|
|
168
179
|
obj.splice(currentKeyPath, 1);
|
|
@@ -174,7 +185,7 @@ function setByKeyPath(obj, keyPath, value) {
|
|
|
174
185
|
else {
|
|
175
186
|
var innerObj = obj[currentKeyPath];
|
|
176
187
|
if (!innerObj || !hasOwn(obj, currentKeyPath))
|
|
177
|
-
innerObj =
|
|
188
|
+
innerObj = obj[currentKeyPath] = {};
|
|
178
189
|
setByKeyPath(innerObj, remainingKeyPath, value);
|
|
179
190
|
}
|
|
180
191
|
}
|
|
@@ -210,24 +221,25 @@ var concat = [].concat;
|
|
|
210
221
|
function flatten(a) {
|
|
211
222
|
return concat.apply([], a);
|
|
212
223
|
}
|
|
213
|
-
var intrinsicTypeNames =
|
|
214
|
-
.split(',')
|
|
224
|
+
var intrinsicTypeNames = 'BigUint64Array,BigInt64Array,Array,Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,FileSystemDirectoryHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey'
|
|
225
|
+
.split(',')
|
|
226
|
+
.concat(flatten([8, 16, 32, 64].map(function (num) {
|
|
227
|
+
return ['Int', 'Uint', 'Float'].map(function (t) { return t + num + 'Array'; });
|
|
228
|
+
})))
|
|
229
|
+
.filter(function (t) { return _global[t]; });
|
|
215
230
|
var intrinsicTypes = new Set(intrinsicTypeNames.map(function (t) { return _global[t]; }));
|
|
216
231
|
function cloneSimpleObjectTree(o) {
|
|
217
232
|
var rv = {};
|
|
218
233
|
for (var k in o)
|
|
219
234
|
if (hasOwn(o, k)) {
|
|
220
235
|
var v = o[k];
|
|
221
|
-
rv[k] =
|
|
236
|
+
rv[k] =
|
|
237
|
+
!v || typeof v !== 'object' || intrinsicTypes.has(v.constructor)
|
|
238
|
+
? v
|
|
239
|
+
: cloneSimpleObjectTree(v);
|
|
222
240
|
}
|
|
223
241
|
return rv;
|
|
224
242
|
}
|
|
225
|
-
function objectIsEmpty(o) {
|
|
226
|
-
for (var k in o)
|
|
227
|
-
if (hasOwn(o, k))
|
|
228
|
-
return false;
|
|
229
|
-
return true;
|
|
230
|
-
}
|
|
231
243
|
var circularRefs = null;
|
|
232
244
|
function deepClone(any) {
|
|
233
245
|
circularRefs = new WeakMap();
|
|
@@ -267,13 +279,15 @@ var toString = {}.toString;
|
|
|
267
279
|
function toStringTag(o) {
|
|
268
280
|
return toString.call(o).slice(8, -1);
|
|
269
281
|
}
|
|
270
|
-
var iteratorSymbol = typeof Symbol !== 'undefined' ?
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
var
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
282
|
+
var iteratorSymbol = typeof Symbol !== 'undefined' ? Symbol.iterator : '@@iterator';
|
|
283
|
+
var getIteratorOf = typeof iteratorSymbol === 'symbol'
|
|
284
|
+
? function (x) {
|
|
285
|
+
var i;
|
|
286
|
+
return x != null && (i = x[iteratorSymbol]) && i.apply(x);
|
|
287
|
+
}
|
|
288
|
+
: function () {
|
|
289
|
+
return null;
|
|
290
|
+
};
|
|
277
291
|
function delArrayItem(a, x) {
|
|
278
292
|
var i = a.indexOf(x);
|
|
279
293
|
if (i >= 0)
|
|
@@ -290,7 +304,7 @@ function getArrayOf(arrayLike) {
|
|
|
290
304
|
return [arrayLike];
|
|
291
305
|
if ((it = getIteratorOf(arrayLike))) {
|
|
292
306
|
a = [];
|
|
293
|
-
while ((x = it.next()), !x.done)
|
|
307
|
+
while (((x = it.next()), !x.done))
|
|
294
308
|
a.push(x.value);
|
|
295
309
|
return a;
|
|
296
310
|
}
|
|
@@ -331,7 +345,7 @@ var dexieErrorNames = [
|
|
|
331
345
|
'Internal',
|
|
332
346
|
'DatabaseClosed',
|
|
333
347
|
'PrematureCommit',
|
|
334
|
-
'ForeignAwait'
|
|
348
|
+
'ForeignAwait',
|
|
335
349
|
];
|
|
336
350
|
var idbDomErrorNames = [
|
|
337
351
|
'Unknown',
|
|
@@ -347,28 +361,34 @@ var idbDomErrorNames = [
|
|
|
347
361
|
'Timeout',
|
|
348
362
|
'QuotaExceeded',
|
|
349
363
|
'Syntax',
|
|
350
|
-
'DataClone'
|
|
364
|
+
'DataClone',
|
|
351
365
|
];
|
|
352
366
|
var errorList = dexieErrorNames.concat(idbDomErrorNames);
|
|
353
367
|
var defaultTexts = {
|
|
354
|
-
VersionChanged:
|
|
355
|
-
DatabaseClosed:
|
|
356
|
-
Abort:
|
|
357
|
-
TransactionInactive:
|
|
358
|
-
MissingAPI:
|
|
368
|
+
VersionChanged: 'Database version changed by other database connection',
|
|
369
|
+
DatabaseClosed: 'Database has been closed',
|
|
370
|
+
Abort: 'Transaction aborted',
|
|
371
|
+
TransactionInactive: 'Transaction has already completed or failed',
|
|
372
|
+
MissingAPI: 'IndexedDB API missing. Please visit https://tinyurl.com/y2uuvskb',
|
|
359
373
|
};
|
|
360
374
|
function DexieError(name, msg) {
|
|
361
375
|
this.name = name;
|
|
362
376
|
this.message = msg;
|
|
363
377
|
}
|
|
364
|
-
derive(DexieError)
|
|
365
|
-
|
|
378
|
+
derive(DexieError)
|
|
379
|
+
.from(Error)
|
|
380
|
+
.extend({
|
|
381
|
+
toString: function () {
|
|
382
|
+
return this.name + ': ' + this.message;
|
|
383
|
+
},
|
|
366
384
|
});
|
|
367
385
|
function getMultiErrorMessage(msg, failures) {
|
|
368
|
-
return msg +
|
|
369
|
-
.
|
|
370
|
-
.
|
|
371
|
-
|
|
386
|
+
return (msg +
|
|
387
|
+
'. Errors: ' +
|
|
388
|
+
Object.keys(failures)
|
|
389
|
+
.map(function (key) { return failures[key].toString(); })
|
|
390
|
+
.filter(function (v, i, s) { return s.indexOf(v) === i; })
|
|
391
|
+
.join('\n'));
|
|
372
392
|
}
|
|
373
393
|
function ModifyError(msg, failures, successCount, failedKeys) {
|
|
374
394
|
this.failures = failures;
|
|
@@ -378,16 +398,16 @@ function ModifyError(msg, failures, successCount, failedKeys) {
|
|
|
378
398
|
}
|
|
379
399
|
derive(ModifyError).from(DexieError);
|
|
380
400
|
function BulkError(msg, failures) {
|
|
381
|
-
this.name =
|
|
401
|
+
this.name = 'BulkError';
|
|
382
402
|
this.failures = Object.keys(failures).map(function (pos) { return failures[pos]; });
|
|
383
403
|
this.failuresByPos = failures;
|
|
384
404
|
this.message = getMultiErrorMessage(msg, this.failures);
|
|
385
405
|
}
|
|
386
406
|
derive(BulkError).from(DexieError);
|
|
387
|
-
var errnames = errorList.reduce(function (obj, name) { return (obj[name] = name +
|
|
407
|
+
var errnames = errorList.reduce(function (obj, name) { return ((obj[name] = name + 'Error'), obj); }, {});
|
|
388
408
|
var BaseException = DexieError;
|
|
389
409
|
var exceptions = errorList.reduce(function (obj, name) {
|
|
390
|
-
var fullName = name +
|
|
410
|
+
var fullName = name + 'Error';
|
|
391
411
|
function DexieError(msgOrInner, inner) {
|
|
392
412
|
this.name = fullName;
|
|
393
413
|
if (!msgOrInner) {
|
|
@@ -411,23 +431,30 @@ exceptions.Syntax = SyntaxError;
|
|
|
411
431
|
exceptions.Type = TypeError;
|
|
412
432
|
exceptions.Range = RangeError;
|
|
413
433
|
var exceptionMap = idbDomErrorNames.reduce(function (obj, name) {
|
|
414
|
-
obj[name +
|
|
434
|
+
obj[name + 'Error'] = exceptions[name];
|
|
415
435
|
return obj;
|
|
416
436
|
}, {});
|
|
417
437
|
function mapError(domError, message) {
|
|
418
|
-
if (!domError ||
|
|
438
|
+
if (!domError ||
|
|
439
|
+
domError instanceof DexieError ||
|
|
440
|
+
domError instanceof TypeError ||
|
|
441
|
+
domError instanceof SyntaxError ||
|
|
442
|
+
!domError.name ||
|
|
443
|
+
!exceptionMap[domError.name])
|
|
419
444
|
return domError;
|
|
420
445
|
var rv = new exceptionMap[domError.name](message || domError.message, domError);
|
|
421
|
-
if (
|
|
422
|
-
setProp(rv,
|
|
446
|
+
if ('stack' in domError) {
|
|
447
|
+
setProp(rv, 'stack', {
|
|
448
|
+
get: function () {
|
|
423
449
|
return this.inner.stack;
|
|
424
|
-
}
|
|
450
|
+
},
|
|
451
|
+
});
|
|
425
452
|
}
|
|
426
453
|
return rv;
|
|
427
454
|
}
|
|
428
455
|
var fullNameExceptions = errorList.reduce(function (obj, name) {
|
|
429
|
-
if ([
|
|
430
|
-
obj[name +
|
|
456
|
+
if (['Syntax', 'Type', 'Range'].indexOf(name) === -1)
|
|
457
|
+
obj[name + 'Error'] = exceptions[name];
|
|
431
458
|
return obj;
|
|
432
459
|
}, {});
|
|
433
460
|
fullNameExceptions.ModifyError = ModifyError;
|
|
@@ -435,7 +462,9 @@ fullNameExceptions.DexieError = DexieError;
|
|
|
435
462
|
fullNameExceptions.BulkError = BulkError;
|
|
436
463
|
|
|
437
464
|
function nop() { }
|
|
438
|
-
function mirror(val) {
|
|
465
|
+
function mirror(val) {
|
|
466
|
+
return val;
|
|
467
|
+
}
|
|
439
468
|
function pureFunctionChain(f1, f2) {
|
|
440
469
|
if (f1 == null || f1 === mirror)
|
|
441
470
|
return f2;
|
|
@@ -462,7 +491,9 @@ function hookCreatingChain(f1, f2) {
|
|
|
462
491
|
this.onerror = null;
|
|
463
492
|
var res2 = f2.apply(this, arguments);
|
|
464
493
|
if (onsuccess)
|
|
465
|
-
this.onsuccess = this.onsuccess
|
|
494
|
+
this.onsuccess = this.onsuccess
|
|
495
|
+
? callBoth(onsuccess, this.onsuccess)
|
|
496
|
+
: onsuccess;
|
|
466
497
|
if (onerror)
|
|
467
498
|
this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;
|
|
468
499
|
return res2 !== undefined ? res2 : res;
|
|
@@ -478,7 +509,9 @@ function hookDeletingChain(f1, f2) {
|
|
|
478
509
|
this.onsuccess = this.onerror = null;
|
|
479
510
|
f2.apply(this, arguments);
|
|
480
511
|
if (onsuccess)
|
|
481
|
-
this.onsuccess = this.onsuccess
|
|
512
|
+
this.onsuccess = this.onsuccess
|
|
513
|
+
? callBoth(onsuccess, this.onsuccess)
|
|
514
|
+
: onsuccess;
|
|
482
515
|
if (onerror)
|
|
483
516
|
this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;
|
|
484
517
|
};
|
|
@@ -495,12 +528,16 @@ function hookUpdatingChain(f1, f2) {
|
|
|
495
528
|
this.onerror = null;
|
|
496
529
|
var res2 = f2.apply(this, arguments);
|
|
497
530
|
if (onsuccess)
|
|
498
|
-
this.onsuccess = this.onsuccess
|
|
531
|
+
this.onsuccess = this.onsuccess
|
|
532
|
+
? callBoth(onsuccess, this.onsuccess)
|
|
533
|
+
: onsuccess;
|
|
499
534
|
if (onerror)
|
|
500
535
|
this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;
|
|
501
|
-
return res === undefined
|
|
502
|
-
|
|
503
|
-
|
|
536
|
+
return res === undefined
|
|
537
|
+
? res2 === undefined
|
|
538
|
+
? undefined
|
|
539
|
+
: res2
|
|
540
|
+
: extend(res, res2);
|
|
504
541
|
};
|
|
505
542
|
}
|
|
506
543
|
function reverseStoppableEventChain(f1, f2) {
|
|
@@ -536,18 +573,14 @@ function setDebug(value, filter) {
|
|
|
536
573
|
}
|
|
537
574
|
|
|
538
575
|
var INTERNAL = {};
|
|
539
|
-
var ZONE_ECHO_LIMIT = 100, _a$1 = typeof Promise === 'undefined'
|
|
540
|
-
[]
|
|
541
|
-
(function () {
|
|
576
|
+
var ZONE_ECHO_LIMIT = 100, _a$1 = typeof Promise === 'undefined'
|
|
577
|
+
? []
|
|
578
|
+
: (function () {
|
|
542
579
|
var globalP = Promise.resolve();
|
|
543
580
|
if (typeof crypto === 'undefined' || !crypto.subtle)
|
|
544
581
|
return [globalP, getProto(globalP), globalP];
|
|
545
|
-
var nativeP = crypto.subtle.digest(
|
|
546
|
-
return [
|
|
547
|
-
nativeP,
|
|
548
|
-
getProto(nativeP),
|
|
549
|
-
globalP
|
|
550
|
-
];
|
|
582
|
+
var nativeP = crypto.subtle.digest('SHA-512', new Uint8Array([0]));
|
|
583
|
+
return [nativeP, getProto(nativeP), globalP];
|
|
551
584
|
})(), resolvedNativePromise = _a$1[0], nativePromiseProto = _a$1[1], resolvedGlobalPromise = _a$1[2], nativePromiseThen = nativePromiseProto && nativePromiseProto.then;
|
|
552
585
|
var NativePromise = resolvedNativePromise && resolvedNativePromise.constructor;
|
|
553
586
|
var patchGlobalPromise = !!resolvedGlobalPromise;
|
|
@@ -574,7 +607,7 @@ var globalPSD = {
|
|
|
574
607
|
onunhandled: nop,
|
|
575
608
|
pgp: false,
|
|
576
609
|
env: {},
|
|
577
|
-
finalize: nop
|
|
610
|
+
finalize: nop,
|
|
578
611
|
};
|
|
579
612
|
var PSD = globalPSD;
|
|
580
613
|
var microtickQueue = [];
|
|
@@ -618,15 +651,15 @@ var thenProp = {
|
|
|
618
651
|
return then;
|
|
619
652
|
},
|
|
620
653
|
set: function (value) {
|
|
621
|
-
setProp(this, 'then', value && value.prototype === INTERNAL
|
|
622
|
-
thenProp
|
|
623
|
-
{
|
|
654
|
+
setProp(this, 'then', value && value.prototype === INTERNAL
|
|
655
|
+
? thenProp
|
|
656
|
+
: {
|
|
624
657
|
get: function () {
|
|
625
658
|
return value;
|
|
626
659
|
},
|
|
627
|
-
set: thenProp.set
|
|
660
|
+
set: thenProp.set,
|
|
628
661
|
});
|
|
629
|
-
}
|
|
662
|
+
},
|
|
630
663
|
};
|
|
631
664
|
props(DexiePromise.prototype, {
|
|
632
665
|
then: thenProp,
|
|
@@ -637,9 +670,10 @@ props(DexiePromise.prototype, {
|
|
|
637
670
|
if (arguments.length === 1)
|
|
638
671
|
return this.then(null, onRejected);
|
|
639
672
|
var type = arguments[0], handler = arguments[1];
|
|
640
|
-
return typeof type === 'function'
|
|
641
|
-
|
|
642
|
-
|
|
673
|
+
return typeof type === 'function'
|
|
674
|
+
? this.then(null, function (err) {
|
|
675
|
+
return err instanceof type ? handler(err) : PromiseReject(err);
|
|
676
|
+
})
|
|
643
677
|
: this.then(null, function (err) {
|
|
644
678
|
return err && err.name === type ? handler(err) : PromiseReject(err);
|
|
645
679
|
});
|
|
@@ -653,12 +687,13 @@ props(DexiePromise.prototype, {
|
|
|
653
687
|
},
|
|
654
688
|
timeout: function (ms, msg) {
|
|
655
689
|
var _this = this;
|
|
656
|
-
return ms < Infinity
|
|
657
|
-
new DexiePromise(function (resolve, reject) {
|
|
690
|
+
return ms < Infinity
|
|
691
|
+
? new DexiePromise(function (resolve, reject) {
|
|
658
692
|
var handle = setTimeout(function () { return reject(new exceptions.Timeout(msg)); }, ms);
|
|
659
693
|
_this.then(resolve, reject).finally(clearTimeout.bind(null, handle));
|
|
660
|
-
})
|
|
661
|
-
|
|
694
|
+
})
|
|
695
|
+
: this;
|
|
696
|
+
},
|
|
662
697
|
});
|
|
663
698
|
if (typeof Symbol !== 'undefined' && Symbol.toStringTag)
|
|
664
699
|
setProp(DexiePromise.prototype, Symbol.toStringTag, 'Dexie.Promise');
|
|
@@ -672,17 +707,20 @@ function Listener(onFulfilled, onRejected, resolve, reject, zone) {
|
|
|
672
707
|
}
|
|
673
708
|
props(DexiePromise, {
|
|
674
709
|
all: function () {
|
|
675
|
-
var values = getArrayOf
|
|
710
|
+
var values = getArrayOf
|
|
711
|
+
.apply(null, arguments)
|
|
676
712
|
.map(onPossibleParallellAsync);
|
|
677
713
|
return new DexiePromise(function (resolve, reject) {
|
|
678
714
|
if (values.length === 0)
|
|
679
715
|
resolve([]);
|
|
680
716
|
var remaining = values.length;
|
|
681
|
-
values.forEach(function (a, i) {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
717
|
+
values.forEach(function (a, i) {
|
|
718
|
+
return DexiePromise.resolve(a).then(function (x) {
|
|
719
|
+
values[i] = x;
|
|
720
|
+
if (!--remaining)
|
|
721
|
+
resolve(values);
|
|
722
|
+
}, reject);
|
|
723
|
+
});
|
|
686
724
|
});
|
|
687
725
|
},
|
|
688
726
|
resolve: function (value) {
|
|
@@ -697,25 +735,31 @@ props(DexiePromise, {
|
|
|
697
735
|
},
|
|
698
736
|
reject: PromiseReject,
|
|
699
737
|
race: function () {
|
|
700
|
-
var values = getArrayOf
|
|
738
|
+
var values = getArrayOf
|
|
739
|
+
.apply(null, arguments)
|
|
740
|
+
.map(onPossibleParallellAsync);
|
|
701
741
|
return new DexiePromise(function (resolve, reject) {
|
|
702
742
|
values.map(function (value) { return DexiePromise.resolve(value).then(resolve, reject); });
|
|
703
743
|
});
|
|
704
744
|
},
|
|
705
745
|
PSD: {
|
|
706
746
|
get: function () { return PSD; },
|
|
707
|
-
set: function (value) { return PSD = value; }
|
|
747
|
+
set: function (value) { return (PSD = value); },
|
|
708
748
|
},
|
|
709
749
|
totalEchoes: { get: function () { return totalEchoes; } },
|
|
710
750
|
newPSD: newScope,
|
|
711
751
|
usePSD: usePSD,
|
|
712
752
|
scheduler: {
|
|
713
753
|
get: function () { return asap; },
|
|
714
|
-
set: function (value) {
|
|
754
|
+
set: function (value) {
|
|
755
|
+
asap = value;
|
|
756
|
+
},
|
|
715
757
|
},
|
|
716
758
|
rejectionMapper: {
|
|
717
759
|
get: function () { return rejectionMapper; },
|
|
718
|
-
set: function (value) {
|
|
760
|
+
set: function (value) {
|
|
761
|
+
rejectionMapper = value;
|
|
762
|
+
},
|
|
719
763
|
},
|
|
720
764
|
follow: function (fn, zoneProps) {
|
|
721
765
|
return new DexiePromise(function (resolve, reject) {
|
|
@@ -726,40 +770,51 @@ props(DexiePromise, {
|
|
|
726
770
|
psd.finalize = callBoth(function () {
|
|
727
771
|
var _this = this;
|
|
728
772
|
run_at_end_of_this_or_next_physical_tick(function () {
|
|
729
|
-
_this.unhandleds.length === 0
|
|
773
|
+
_this.unhandleds.length === 0
|
|
774
|
+
? resolve()
|
|
775
|
+
: reject(_this.unhandleds[0]);
|
|
730
776
|
});
|
|
731
777
|
}, psd.finalize);
|
|
732
778
|
fn();
|
|
733
779
|
}, zoneProps, resolve, reject);
|
|
734
780
|
});
|
|
735
|
-
}
|
|
781
|
+
},
|
|
736
782
|
});
|
|
737
783
|
if (NativePromise) {
|
|
738
784
|
if (NativePromise.allSettled)
|
|
739
|
-
setProp(DexiePromise,
|
|
740
|
-
var possiblePromises = getArrayOf
|
|
785
|
+
setProp(DexiePromise, 'allSettled', function () {
|
|
786
|
+
var possiblePromises = getArrayOf
|
|
787
|
+
.apply(null, arguments)
|
|
788
|
+
.map(onPossibleParallellAsync);
|
|
741
789
|
return new DexiePromise(function (resolve) {
|
|
742
790
|
if (possiblePromises.length === 0)
|
|
743
791
|
resolve([]);
|
|
744
792
|
var remaining = possiblePromises.length;
|
|
745
793
|
var results = new Array(remaining);
|
|
746
|
-
possiblePromises.forEach(function (p, i) {
|
|
747
|
-
|
|
794
|
+
possiblePromises.forEach(function (p, i) {
|
|
795
|
+
return DexiePromise.resolve(p)
|
|
796
|
+
.then(function (value) { return (results[i] = { status: 'fulfilled', value: value }); }, function (reason) { return (results[i] = { status: 'rejected', reason: reason }); })
|
|
797
|
+
.then(function () { return --remaining || resolve(results); });
|
|
798
|
+
});
|
|
748
799
|
});
|
|
749
800
|
});
|
|
750
801
|
if (NativePromise.any && typeof AggregateError !== 'undefined')
|
|
751
|
-
setProp(DexiePromise,
|
|
752
|
-
var possiblePromises = getArrayOf
|
|
802
|
+
setProp(DexiePromise, 'any', function () {
|
|
803
|
+
var possiblePromises = getArrayOf
|
|
804
|
+
.apply(null, arguments)
|
|
805
|
+
.map(onPossibleParallellAsync);
|
|
753
806
|
return new DexiePromise(function (resolve, reject) {
|
|
754
807
|
if (possiblePromises.length === 0)
|
|
755
808
|
reject(new AggregateError([]));
|
|
756
809
|
var remaining = possiblePromises.length;
|
|
757
810
|
var failures = new Array(remaining);
|
|
758
|
-
possiblePromises.forEach(function (p, i) {
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
811
|
+
possiblePromises.forEach(function (p, i) {
|
|
812
|
+
return DexiePromise.resolve(p).then(function (value) { return resolve(value); }, function (failure) {
|
|
813
|
+
failures[i] = failure;
|
|
814
|
+
if (!--remaining)
|
|
815
|
+
reject(new AggregateError(failures));
|
|
816
|
+
});
|
|
817
|
+
});
|
|
763
818
|
});
|
|
764
819
|
});
|
|
765
820
|
if (NativePromise.withResolvers)
|
|
@@ -775,9 +830,9 @@ function executePromiseTask(promise, fn) {
|
|
|
775
830
|
var shouldExecuteTick = promise._lib && beginMicroTickScope();
|
|
776
831
|
if (value && typeof value.then === 'function') {
|
|
777
832
|
executePromiseTask(promise, function (resolve, reject) {
|
|
778
|
-
value instanceof DexiePromise
|
|
779
|
-
value._then(resolve, reject)
|
|
780
|
-
value.then(resolve, reject);
|
|
833
|
+
value instanceof DexiePromise
|
|
834
|
+
? value._then(resolve, reject)
|
|
835
|
+
: value.then(resolve, reject);
|
|
781
836
|
});
|
|
782
837
|
}
|
|
783
838
|
else {
|
|
@@ -840,7 +895,10 @@ function callListener(cb, promise, listener) {
|
|
|
840
895
|
var ret, value = promise._value;
|
|
841
896
|
if (!promise._state && rejectingErrors.length)
|
|
842
897
|
rejectingErrors = [];
|
|
843
|
-
ret =
|
|
898
|
+
ret =
|
|
899
|
+
debug && promise._consoleTask
|
|
900
|
+
? promise._consoleTask.run(function () { return cb(value); })
|
|
901
|
+
: cb(value);
|
|
844
902
|
if (!promise._state && rejectingErrors.indexOf(value) === -1) {
|
|
845
903
|
markErrorAsHandled(promise);
|
|
846
904
|
}
|
|
@@ -951,16 +1009,22 @@ function newScope(fn, props, a1, a2) {
|
|
|
951
1009
|
psd.global = false;
|
|
952
1010
|
psd.id = ++zone_id_counter;
|
|
953
1011
|
globalPSD.env;
|
|
954
|
-
psd.env = patchGlobalPromise
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
1012
|
+
psd.env = patchGlobalPromise
|
|
1013
|
+
? {
|
|
1014
|
+
Promise: DexiePromise,
|
|
1015
|
+
PromiseProp: {
|
|
1016
|
+
value: DexiePromise,
|
|
1017
|
+
configurable: true,
|
|
1018
|
+
writable: true,
|
|
1019
|
+
},
|
|
1020
|
+
all: DexiePromise.all,
|
|
1021
|
+
race: DexiePromise.race,
|
|
1022
|
+
allSettled: DexiePromise.allSettled,
|
|
1023
|
+
any: DexiePromise.any,
|
|
1024
|
+
resolve: DexiePromise.resolve,
|
|
1025
|
+
reject: DexiePromise.reject,
|
|
1026
|
+
}
|
|
1027
|
+
: {};
|
|
964
1028
|
if (props)
|
|
965
1029
|
extend(psd, props);
|
|
966
1030
|
++parent.ref;
|
|
@@ -991,7 +1055,9 @@ if (('' + nativePromiseThen).indexOf('[native code]') === -1) {
|
|
|
991
1055
|
incrementExpectedAwaits = decrementExpectedAwaits = nop;
|
|
992
1056
|
}
|
|
993
1057
|
function onPossibleParallellAsync(possiblePromise) {
|
|
994
|
-
if (task.echoes &&
|
|
1058
|
+
if (task.echoes &&
|
|
1059
|
+
possiblePromise &&
|
|
1060
|
+
possiblePromise.constructor === NativePromise) {
|
|
995
1061
|
incrementExpectedAwaits();
|
|
996
1062
|
return possiblePromise.then(function (x) {
|
|
997
1063
|
decrementExpectedAwaits();
|
|
@@ -1018,7 +1084,9 @@ function zoneLeaveEcho() {
|
|
|
1018
1084
|
}
|
|
1019
1085
|
function switchToZone(targetZone, bEnteringZone) {
|
|
1020
1086
|
var currentZone = PSD;
|
|
1021
|
-
if (bEnteringZone
|
|
1087
|
+
if (bEnteringZone
|
|
1088
|
+
? task.echoes && (!zoneEchoes++ || targetZone !== PSD)
|
|
1089
|
+
: zoneEchoes && (!--zoneEchoes || targetZone !== PSD)) {
|
|
1022
1090
|
queueMicrotask(bEnteringZone ? zoneEnterEcho.bind(null, targetZone) : zoneLeaveEcho);
|
|
1023
1091
|
}
|
|
1024
1092
|
if (targetZone === PSD)
|
|
@@ -1044,16 +1112,18 @@ function switchToZone(targetZone, bEnteringZone) {
|
|
|
1044
1112
|
}
|
|
1045
1113
|
function snapShot() {
|
|
1046
1114
|
var GlobalPromise = _global.Promise;
|
|
1047
|
-
return patchGlobalPromise
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1115
|
+
return patchGlobalPromise
|
|
1116
|
+
? {
|
|
1117
|
+
Promise: GlobalPromise,
|
|
1118
|
+
PromiseProp: Object.getOwnPropertyDescriptor(_global, 'Promise'),
|
|
1119
|
+
all: GlobalPromise.all,
|
|
1120
|
+
race: GlobalPromise.race,
|
|
1121
|
+
allSettled: GlobalPromise.allSettled,
|
|
1122
|
+
any: GlobalPromise.any,
|
|
1123
|
+
resolve: GlobalPromise.resolve,
|
|
1124
|
+
reject: GlobalPromise.reject,
|
|
1125
|
+
}
|
|
1126
|
+
: {};
|
|
1057
1127
|
}
|
|
1058
1128
|
function usePSD(psd, fn, a1, a2, a3) {
|
|
1059
1129
|
var outerScope = PSD;
|
|
@@ -1066,20 +1136,22 @@ function usePSD(psd, fn, a1, a2, a3) {
|
|
|
1066
1136
|
}
|
|
1067
1137
|
}
|
|
1068
1138
|
function nativeAwaitCompatibleWrap(fn, zone, possibleAwait, cleanup) {
|
|
1069
|
-
return typeof fn !== 'function'
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1139
|
+
return typeof fn !== 'function'
|
|
1140
|
+
? fn
|
|
1141
|
+
: function () {
|
|
1142
|
+
var outerZone = PSD;
|
|
1143
|
+
if (possibleAwait)
|
|
1144
|
+
incrementExpectedAwaits();
|
|
1145
|
+
switchToZone(zone, true);
|
|
1146
|
+
try {
|
|
1147
|
+
return fn.apply(this, arguments);
|
|
1148
|
+
}
|
|
1149
|
+
finally {
|
|
1150
|
+
switchToZone(outerZone, false);
|
|
1151
|
+
if (cleanup)
|
|
1152
|
+
queueMicrotask(decrementExpectedAwaits);
|
|
1153
|
+
}
|
|
1154
|
+
};
|
|
1083
1155
|
}
|
|
1084
1156
|
function execInGlobalContext(cb) {
|
|
1085
1157
|
if (Promise === NativePromise && task.echoes === 0) {
|
|
@@ -1097,7 +1169,7 @@ function execInGlobalContext(cb) {
|
|
|
1097
1169
|
var rejection = DexiePromise.reject;
|
|
1098
1170
|
|
|
1099
1171
|
function tempTransaction(db, mode, storeNames, fn) {
|
|
1100
|
-
if (!db.idbdb || (!db._state.openComplete &&
|
|
1172
|
+
if (!db.idbdb || (!db._state.openComplete && !PSD.letThrough && !db._vip)) {
|
|
1101
1173
|
if (db._state.openComplete) {
|
|
1102
1174
|
return rejection(new exceptions.DatabaseClosed(db._state.dbOpenError));
|
|
1103
1175
|
}
|
|
@@ -1106,7 +1178,9 @@ function tempTransaction(db, mode, storeNames, fn) {
|
|
|
1106
1178
|
return rejection(new exceptions.DatabaseClosed());
|
|
1107
1179
|
db.open().catch(nop);
|
|
1108
1180
|
}
|
|
1109
|
-
return db._state.dbReadyPromise.then(function () {
|
|
1181
|
+
return db._state.dbReadyPromise.then(function () {
|
|
1182
|
+
return tempTransaction(db, mode, storeNames, fn);
|
|
1183
|
+
});
|
|
1110
1184
|
}
|
|
1111
1185
|
else {
|
|
1112
1186
|
var trans = db._createTransaction(mode, storeNames, db._dbSchema);
|
|
@@ -1115,45 +1189,53 @@ function tempTransaction(db, mode, storeNames, fn) {
|
|
|
1115
1189
|
db._state.PR1398_maxLoop = 3;
|
|
1116
1190
|
}
|
|
1117
1191
|
catch (ex) {
|
|
1118
|
-
if (ex.name === errnames.InvalidState &&
|
|
1192
|
+
if (ex.name === errnames.InvalidState &&
|
|
1193
|
+
db.isOpen() &&
|
|
1194
|
+
--db._state.PR1398_maxLoop > 0) {
|
|
1119
1195
|
console.warn('Dexie: Need to reopen db');
|
|
1120
1196
|
db.close({ disableAutoOpen: false });
|
|
1121
1197
|
return db.open().then(function () { return tempTransaction(db, mode, storeNames, fn); });
|
|
1122
1198
|
}
|
|
1123
1199
|
return rejection(ex);
|
|
1124
1200
|
}
|
|
1125
|
-
return trans
|
|
1201
|
+
return trans
|
|
1202
|
+
._promise(mode, function (resolve, reject) {
|
|
1126
1203
|
return newScope(function () {
|
|
1127
1204
|
PSD.trans = trans;
|
|
1128
1205
|
return fn(resolve, reject, trans);
|
|
1129
1206
|
});
|
|
1130
|
-
})
|
|
1207
|
+
})
|
|
1208
|
+
.then(function (result) {
|
|
1131
1209
|
if (mode === 'readwrite')
|
|
1132
1210
|
try {
|
|
1133
1211
|
trans.idbtrans.commit();
|
|
1134
1212
|
}
|
|
1135
1213
|
catch (_a) { }
|
|
1136
|
-
return mode === 'readonly'
|
|
1214
|
+
return mode === 'readonly'
|
|
1215
|
+
? result
|
|
1216
|
+
: trans._completion.then(function () { return result; });
|
|
1137
1217
|
});
|
|
1138
1218
|
}
|
|
1139
1219
|
}
|
|
1140
1220
|
|
|
1141
|
-
var DEXIE_VERSION = '4.4.
|
|
1221
|
+
var DEXIE_VERSION = '4.4.2';
|
|
1142
1222
|
var maxString = String.fromCharCode(65535);
|
|
1143
1223
|
var minKey = -Infinity;
|
|
1144
|
-
var INVALID_KEY_ARGUMENT =
|
|
1145
|
-
var STRING_EXPECTED =
|
|
1224
|
+
var INVALID_KEY_ARGUMENT = 'Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.';
|
|
1225
|
+
var STRING_EXPECTED = 'String expected.';
|
|
1146
1226
|
var DEFAULT_MAX_CONNECTIONS = 1000;
|
|
1147
1227
|
var DBNAMES_DB = '__dbnames';
|
|
1148
1228
|
var READONLY = 'readonly';
|
|
1149
1229
|
var READWRITE = 'readwrite';
|
|
1150
1230
|
|
|
1151
1231
|
function combine(filter1, filter2) {
|
|
1152
|
-
return filter1
|
|
1153
|
-
filter2
|
|
1154
|
-
function () {
|
|
1155
|
-
|
|
1156
|
-
|
|
1232
|
+
return filter1
|
|
1233
|
+
? filter2
|
|
1234
|
+
? function () {
|
|
1235
|
+
return (filter1.apply(this, arguments) && filter2.apply(this, arguments));
|
|
1236
|
+
}
|
|
1237
|
+
: filter1
|
|
1238
|
+
: filter2;
|
|
1157
1239
|
}
|
|
1158
1240
|
|
|
1159
1241
|
var AnyRange = {
|
|
@@ -1161,13 +1243,13 @@ var AnyRange = {
|
|
|
1161
1243
|
lower: -Infinity,
|
|
1162
1244
|
lowerOpen: false,
|
|
1163
1245
|
upper: [[]],
|
|
1164
|
-
upperOpen: false
|
|
1246
|
+
upperOpen: false,
|
|
1165
1247
|
};
|
|
1166
1248
|
|
|
1167
1249
|
function workaroundForUndefinedPrimKey(keyPath) {
|
|
1168
|
-
return typeof keyPath ===
|
|
1250
|
+
return typeof keyPath === 'string' && !/\./.test(keyPath)
|
|
1169
1251
|
? function (obj) {
|
|
1170
|
-
if (obj[keyPath] === undefined &&
|
|
1252
|
+
if (obj[keyPath] === undefined && keyPath in obj) {
|
|
1171
1253
|
obj = deepClone(obj);
|
|
1172
1254
|
delete obj[keyPath];
|
|
1173
1255
|
}
|
|
@@ -1272,11 +1354,11 @@ function builtInDeletionTrigger(table, keys, res) {
|
|
|
1272
1354
|
|
|
1273
1355
|
var PropModification = (function () {
|
|
1274
1356
|
function PropModification(spec) {
|
|
1275
|
-
this[
|
|
1357
|
+
this['@@propmod'] = spec;
|
|
1276
1358
|
}
|
|
1277
1359
|
PropModification.prototype.execute = function (value) {
|
|
1278
1360
|
var _a;
|
|
1279
|
-
var spec = this[
|
|
1361
|
+
var spec = this['@@propmod'];
|
|
1280
1362
|
if (spec.add !== undefined) {
|
|
1281
1363
|
var term = spec.add;
|
|
1282
1364
|
if (isArray(term)) {
|
|
@@ -1297,7 +1379,9 @@ var PropModification = (function () {
|
|
|
1297
1379
|
if (spec.remove !== undefined) {
|
|
1298
1380
|
var subtrahend_1 = spec.remove;
|
|
1299
1381
|
if (isArray(subtrahend_1)) {
|
|
1300
|
-
return isArray(value)
|
|
1382
|
+
return isArray(value)
|
|
1383
|
+
? value.filter(function (item) { return !subtrahend_1.includes(item); }).sort()
|
|
1384
|
+
: [];
|
|
1301
1385
|
}
|
|
1302
1386
|
if (typeof subtrahend_1 === 'number')
|
|
1303
1387
|
return Number(value) - subtrahend_1;
|
|
@@ -1312,7 +1396,9 @@ var PropModification = (function () {
|
|
|
1312
1396
|
throw new TypeError("Invalid subtrahend ".concat(subtrahend_1));
|
|
1313
1397
|
}
|
|
1314
1398
|
var prefixToReplace = (_a = spec.replacePrefix) === null || _a === void 0 ? void 0 : _a[0];
|
|
1315
|
-
if (prefixToReplace &&
|
|
1399
|
+
if (prefixToReplace &&
|
|
1400
|
+
typeof value === 'string' &&
|
|
1401
|
+
value.startsWith(prefixToReplace)) {
|
|
1316
1402
|
return spec.replacePrefix[1] + value.substring(prefixToReplace.length);
|
|
1317
1403
|
}
|
|
1318
1404
|
return value;
|
|
@@ -1346,19 +1432,24 @@ var Table = (function () {
|
|
|
1346
1432
|
Table.prototype._trans = function (mode, fn, writeLocked) {
|
|
1347
1433
|
var trans = this._tx || PSD.trans;
|
|
1348
1434
|
var tableName = this.name;
|
|
1349
|
-
var task = debug &&
|
|
1435
|
+
var task = debug &&
|
|
1436
|
+
typeof console !== 'undefined' &&
|
|
1437
|
+
console.createTask &&
|
|
1438
|
+
console.createTask("Dexie: ".concat(mode === 'readonly' ? 'read' : 'write', " ").concat(this.name));
|
|
1350
1439
|
function checkTableInTransaction(resolve, reject, trans) {
|
|
1351
1440
|
if (!trans.schema[tableName])
|
|
1352
|
-
throw new exceptions.NotFound(
|
|
1441
|
+
throw new exceptions.NotFound('Table ' + tableName + ' not part of transaction');
|
|
1353
1442
|
return fn(trans.idbtrans, trans);
|
|
1354
1443
|
}
|
|
1355
1444
|
var wasRootExec = beginMicroTickScope();
|
|
1356
1445
|
try {
|
|
1357
|
-
var p = trans && trans.db._novip === this.db._novip
|
|
1358
|
-
trans === PSD.trans
|
|
1359
|
-
trans._promise(mode, checkTableInTransaction, writeLocked)
|
|
1360
|
-
newScope(function () {
|
|
1361
|
-
|
|
1446
|
+
var p = trans && trans.db._novip === this.db._novip
|
|
1447
|
+
? trans === PSD.trans
|
|
1448
|
+
? trans._promise(mode, checkTableInTransaction, writeLocked)
|
|
1449
|
+
: newScope(function () {
|
|
1450
|
+
return trans._promise(mode, checkTableInTransaction, writeLocked);
|
|
1451
|
+
}, { trans: trans, transless: PSD.transless || PSD })
|
|
1452
|
+
: tempTransaction(this.db, mode, [this.name], checkTableInTransaction);
|
|
1362
1453
|
if (task) {
|
|
1363
1454
|
p._consoleTask = task;
|
|
1364
1455
|
p = p.catch(function (err) {
|
|
@@ -1380,7 +1471,8 @@ var Table = (function () {
|
|
|
1380
1471
|
if (keyOrCrit == null)
|
|
1381
1472
|
return rejection(new exceptions.Type("Invalid argument to Table.get()"));
|
|
1382
1473
|
return this._trans('readonly', function (trans) {
|
|
1383
|
-
return _this.core
|
|
1474
|
+
return _this.core
|
|
1475
|
+
.get({ trans: trans, key: keyOrCrit })
|
|
1384
1476
|
.then(function (res) { return _this.hook.reading.fire(res); });
|
|
1385
1477
|
}).then(cb);
|
|
1386
1478
|
};
|
|
@@ -1391,10 +1483,10 @@ var Table = (function () {
|
|
|
1391
1483
|
return new this.db.WhereClause(this, "[".concat(indexOrCrit.join('+'), "]"));
|
|
1392
1484
|
var keyPaths = keys(indexOrCrit);
|
|
1393
1485
|
if (keyPaths.length === 1)
|
|
1394
|
-
return this
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1486
|
+
return this.where(keyPaths[0]).equals(indexOrCrit[keyPaths[0]]);
|
|
1487
|
+
var compoundIndex = this.schema.indexes
|
|
1488
|
+
.concat(this.schema.primKey)
|
|
1489
|
+
.filter(function (ix) {
|
|
1398
1490
|
if (ix.compound &&
|
|
1399
1491
|
keyPaths.every(function (keyPath) { return ix.keyPath.indexOf(keyPath) >= 0; })) {
|
|
1400
1492
|
for (var i = 0; i < keyPaths.length; ++i) {
|
|
@@ -1404,12 +1496,11 @@ var Table = (function () {
|
|
|
1404
1496
|
return true;
|
|
1405
1497
|
}
|
|
1406
1498
|
return false;
|
|
1407
|
-
})
|
|
1499
|
+
})
|
|
1500
|
+
.sort(function (a, b) { return a.keyPath.length - b.keyPath.length; })[0];
|
|
1408
1501
|
if (compoundIndex && this.db._maxKey !== maxString) {
|
|
1409
1502
|
var keyPathsInValidOrder = compoundIndex.keyPath.slice(0, keyPaths.length);
|
|
1410
|
-
return this
|
|
1411
|
-
.where(keyPathsInValidOrder)
|
|
1412
|
-
.equals(keyPathsInValidOrder.map(function (kp) { return indexOrCrit[kp]; }));
|
|
1503
|
+
return this.where(keyPathsInValidOrder).equals(keyPathsInValidOrder.map(function (kp) { return indexOrCrit[kp]; }));
|
|
1413
1504
|
}
|
|
1414
1505
|
if (!compoundIndex && debug)
|
|
1415
1506
|
console.warn("The query ".concat(JSON.stringify(indexOrCrit), " on ").concat(this.name, " would benefit from a ") +
|
|
@@ -1424,21 +1515,24 @@ var Table = (function () {
|
|
|
1424
1515
|
var value = indexOrCrit[keyPath];
|
|
1425
1516
|
return [
|
|
1426
1517
|
prevIndex || index,
|
|
1427
|
-
prevIndex || !index
|
|
1428
|
-
combine(prevFilterFn, index && index.multi
|
|
1429
|
-
function (x) {
|
|
1518
|
+
prevIndex || !index
|
|
1519
|
+
? combine(prevFilterFn, index && index.multi
|
|
1520
|
+
? function (x) {
|
|
1430
1521
|
var prop = getByKeyPath(x, keyPath);
|
|
1431
|
-
return isArray(prop) &&
|
|
1432
|
-
|
|
1433
|
-
|
|
1522
|
+
return (isArray(prop) &&
|
|
1523
|
+
prop.some(function (item) { return equals(value, item); }));
|
|
1524
|
+
}
|
|
1525
|
+
: function (x) { return equals(value, getByKeyPath(x, keyPath)); })
|
|
1526
|
+
: prevFilterFn,
|
|
1434
1527
|
];
|
|
1435
1528
|
}, [null, null]), idx = _a[0], filterFunction = _a[1];
|
|
1436
|
-
return idx
|
|
1437
|
-
this.where(idx.name)
|
|
1438
|
-
.
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
this.
|
|
1529
|
+
return idx
|
|
1530
|
+
? this.where(idx.name)
|
|
1531
|
+
.equals(indexOrCrit[idx.keyPath])
|
|
1532
|
+
.filter(filterFunction)
|
|
1533
|
+
: compoundIndex
|
|
1534
|
+
? this.filter(filterFunction)
|
|
1535
|
+
: this.where(keyPaths).equals('');
|
|
1442
1536
|
};
|
|
1443
1537
|
Table.prototype.filter = function (filterFunction) {
|
|
1444
1538
|
return this.toCollection().and(filterFunction);
|
|
@@ -1462,9 +1556,7 @@ var Table = (function () {
|
|
|
1462
1556
|
return new this.db.Collection(new this.db.WhereClause(this));
|
|
1463
1557
|
};
|
|
1464
1558
|
Table.prototype.orderBy = function (index) {
|
|
1465
|
-
return new this.db.Collection(new this.db.WhereClause(this, isArray(index) ?
|
|
1466
|
-
"[".concat(index.join('+'), "]") :
|
|
1467
|
-
index));
|
|
1559
|
+
return new this.db.Collection(new this.db.WhereClause(this, isArray(index) ? "[".concat(index.join('+'), "]") : index));
|
|
1468
1560
|
};
|
|
1469
1561
|
Table.prototype.reverse = function () {
|
|
1470
1562
|
return this.toCollection().reverse();
|
|
@@ -1479,17 +1571,23 @@ var Table = (function () {
|
|
|
1479
1571
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
1480
1572
|
}
|
|
1481
1573
|
Object.defineProperty(class_1.prototype, "db", {
|
|
1482
|
-
get: function () {
|
|
1574
|
+
get: function () {
|
|
1575
|
+
return db;
|
|
1576
|
+
},
|
|
1483
1577
|
enumerable: false,
|
|
1484
1578
|
configurable: true
|
|
1485
1579
|
});
|
|
1486
|
-
class_1.prototype.table = function () {
|
|
1580
|
+
class_1.prototype.table = function () {
|
|
1581
|
+
return tableName;
|
|
1582
|
+
};
|
|
1487
1583
|
return class_1;
|
|
1488
1584
|
}(constructor));
|
|
1489
1585
|
}
|
|
1490
1586
|
var inheritedProps = new Set();
|
|
1491
1587
|
for (var proto = constructor.prototype; proto; proto = getProto(proto)) {
|
|
1492
|
-
Object.getOwnPropertyNames(proto).forEach(function (propName) {
|
|
1588
|
+
Object.getOwnPropertyNames(proto).forEach(function (propName) {
|
|
1589
|
+
return inheritedProps.add(propName);
|
|
1590
|
+
});
|
|
1493
1591
|
}
|
|
1494
1592
|
var readHook = function (obj) {
|
|
1495
1593
|
if (!obj)
|
|
@@ -1507,7 +1605,7 @@ var Table = (function () {
|
|
|
1507
1605
|
this.hook.reading.unsubscribe(this.schema.readHook);
|
|
1508
1606
|
}
|
|
1509
1607
|
this.schema.readHook = readHook;
|
|
1510
|
-
this.hook(
|
|
1608
|
+
this.hook('reading', readHook);
|
|
1511
1609
|
return constructor;
|
|
1512
1610
|
};
|
|
1513
1611
|
Table.prototype.defineClass = function () {
|
|
@@ -1524,8 +1622,16 @@ var Table = (function () {
|
|
|
1524
1622
|
objToAdd = workaroundForUndefinedPrimKey(keyPath)(obj);
|
|
1525
1623
|
}
|
|
1526
1624
|
return this._trans('readwrite', function (trans) {
|
|
1527
|
-
return _this.core.mutate({
|
|
1528
|
-
|
|
1625
|
+
return _this.core.mutate({
|
|
1626
|
+
trans: trans,
|
|
1627
|
+
type: 'add',
|
|
1628
|
+
keys: key != null ? [key] : null,
|
|
1629
|
+
values: [objToAdd],
|
|
1630
|
+
});
|
|
1631
|
+
})
|
|
1632
|
+
.then(function (res) {
|
|
1633
|
+
return res.numFailures ? DexiePromise.reject(res.failures[0]) : res.lastResult;
|
|
1634
|
+
})
|
|
1529
1635
|
.then(function (lastResult) {
|
|
1530
1636
|
if (keyPath) {
|
|
1531
1637
|
try {
|
|
@@ -1545,14 +1651,18 @@ var Table = (function () {
|
|
|
1545
1651
|
applyUpdateSpec(obj, modifications);
|
|
1546
1652
|
if (keyPath)
|
|
1547
1653
|
setByKeyPath(obj, keyPath, key);
|
|
1548
|
-
return _this.core
|
|
1654
|
+
return _this.core
|
|
1655
|
+
.mutate({
|
|
1549
1656
|
trans: trans,
|
|
1550
1657
|
type: 'put',
|
|
1551
1658
|
values: [obj],
|
|
1552
1659
|
keys: [key],
|
|
1553
1660
|
upsert: true,
|
|
1554
|
-
updates: { keys: [key], changeSpecs: [modifications] }
|
|
1555
|
-
})
|
|
1661
|
+
updates: { keys: [key], changeSpecs: [modifications] },
|
|
1662
|
+
})
|
|
1663
|
+
.then(function (res) {
|
|
1664
|
+
return res.numFailures ? DexiePromise.reject(res.failures[0]) : !!existing;
|
|
1665
|
+
});
|
|
1556
1666
|
});
|
|
1557
1667
|
});
|
|
1558
1668
|
};
|
|
@@ -1560,11 +1670,11 @@ var Table = (function () {
|
|
|
1560
1670
|
if (typeof keyOrObject === 'object' && !isArray(keyOrObject)) {
|
|
1561
1671
|
var key = getByKeyPath(keyOrObject, this.schema.primKey.keyPath);
|
|
1562
1672
|
if (key === undefined)
|
|
1563
|
-
return rejection(new exceptions.InvalidArgument(
|
|
1564
|
-
return this.where(
|
|
1673
|
+
return rejection(new exceptions.InvalidArgument('Given object does not contain its primary key'));
|
|
1674
|
+
return this.where(':id').equals(key).modify(modifications);
|
|
1565
1675
|
}
|
|
1566
1676
|
else {
|
|
1567
|
-
return this.where(
|
|
1677
|
+
return this.where(':id').equals(keyOrObject).modify(modifications);
|
|
1568
1678
|
}
|
|
1569
1679
|
};
|
|
1570
1680
|
Table.prototype.put = function (obj, key) {
|
|
@@ -1574,8 +1684,17 @@ var Table = (function () {
|
|
|
1574
1684
|
if (keyPath && auto) {
|
|
1575
1685
|
objToAdd = workaroundForUndefinedPrimKey(keyPath)(obj);
|
|
1576
1686
|
}
|
|
1577
|
-
return this._trans('readwrite', function (trans) {
|
|
1578
|
-
|
|
1687
|
+
return this._trans('readwrite', function (trans) {
|
|
1688
|
+
return _this.core.mutate({
|
|
1689
|
+
trans: trans,
|
|
1690
|
+
type: 'put',
|
|
1691
|
+
values: [objToAdd],
|
|
1692
|
+
keys: key != null ? [key] : null,
|
|
1693
|
+
});
|
|
1694
|
+
})
|
|
1695
|
+
.then(function (res) {
|
|
1696
|
+
return res.numFailures ? DexiePromise.reject(res.failures[0]) : res.lastResult;
|
|
1697
|
+
})
|
|
1579
1698
|
.then(function (lastResult) {
|
|
1580
1699
|
if (keyPath) {
|
|
1581
1700
|
try {
|
|
@@ -1588,41 +1707,60 @@ var Table = (function () {
|
|
|
1588
1707
|
};
|
|
1589
1708
|
Table.prototype.delete = function (key) {
|
|
1590
1709
|
var _this = this;
|
|
1591
|
-
return this._trans('readwrite', function (trans) {
|
|
1592
|
-
|
|
1593
|
-
|
|
1710
|
+
return this._trans('readwrite', function (trans) {
|
|
1711
|
+
return _this.core
|
|
1712
|
+
.mutate({ trans: trans, type: 'delete', keys: [key] })
|
|
1713
|
+
.then(function (res) { return builtInDeletionTrigger(_this, [key], res); })
|
|
1714
|
+
.then(function (res) {
|
|
1715
|
+
return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined;
|
|
1716
|
+
});
|
|
1717
|
+
});
|
|
1594
1718
|
};
|
|
1595
1719
|
Table.prototype.clear = function () {
|
|
1596
1720
|
var _this = this;
|
|
1597
|
-
return this._trans('readwrite', function (trans) {
|
|
1598
|
-
|
|
1599
|
-
|
|
1721
|
+
return this._trans('readwrite', function (trans) {
|
|
1722
|
+
return _this.core
|
|
1723
|
+
.mutate({ trans: trans, type: 'deleteRange', range: AnyRange })
|
|
1724
|
+
.then(function (res) { return builtInDeletionTrigger(_this, null, res); });
|
|
1725
|
+
}).then(function (res) {
|
|
1726
|
+
return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined;
|
|
1727
|
+
});
|
|
1600
1728
|
};
|
|
1601
1729
|
Table.prototype.bulkGet = function (keys) {
|
|
1602
1730
|
var _this = this;
|
|
1603
1731
|
return this._trans('readonly', function (trans) {
|
|
1604
|
-
return _this.core
|
|
1732
|
+
return _this.core
|
|
1733
|
+
.getMany({
|
|
1605
1734
|
keys: keys,
|
|
1606
|
-
trans: trans
|
|
1607
|
-
})
|
|
1735
|
+
trans: trans,
|
|
1736
|
+
})
|
|
1737
|
+
.then(function (result) { return result.map(function (res) { return _this.hook.reading.fire(res); }); });
|
|
1608
1738
|
});
|
|
1609
1739
|
};
|
|
1610
1740
|
Table.prototype.bulkAdd = function (objects, keysOrOptions, options) {
|
|
1611
1741
|
var _this = this;
|
|
1612
1742
|
var keys = Array.isArray(keysOrOptions) ? keysOrOptions : undefined;
|
|
1613
|
-
options =
|
|
1743
|
+
options =
|
|
1744
|
+
options || (keys ? undefined : keysOrOptions);
|
|
1614
1745
|
var wantResults = options ? options.allKeys : undefined;
|
|
1615
1746
|
return this._trans('readwrite', function (trans) {
|
|
1616
1747
|
var _a = _this.schema.primKey, auto = _a.auto, keyPath = _a.keyPath;
|
|
1617
1748
|
if (keyPath && keys)
|
|
1618
|
-
throw new exceptions.InvalidArgument(
|
|
1749
|
+
throw new exceptions.InvalidArgument('bulkAdd(): keys argument invalid on tables with inbound keys');
|
|
1619
1750
|
if (keys && keys.length !== objects.length)
|
|
1620
|
-
throw new exceptions.InvalidArgument(
|
|
1751
|
+
throw new exceptions.InvalidArgument('Arguments objects and keys must have the same length');
|
|
1621
1752
|
var numObjects = objects.length;
|
|
1622
|
-
var objectsToAdd = keyPath && auto
|
|
1623
|
-
objects.map(workaroundForUndefinedPrimKey(keyPath))
|
|
1624
|
-
objects;
|
|
1625
|
-
return _this.core
|
|
1753
|
+
var objectsToAdd = keyPath && auto
|
|
1754
|
+
? objects.map(workaroundForUndefinedPrimKey(keyPath))
|
|
1755
|
+
: objects;
|
|
1756
|
+
return _this.core
|
|
1757
|
+
.mutate({
|
|
1758
|
+
trans: trans,
|
|
1759
|
+
type: 'add',
|
|
1760
|
+
keys: keys,
|
|
1761
|
+
values: objectsToAdd,
|
|
1762
|
+
wantResults: wantResults,
|
|
1763
|
+
})
|
|
1626
1764
|
.then(function (_a) {
|
|
1627
1765
|
var numFailures = _a.numFailures, results = _a.results, lastResult = _a.lastResult, failures = _a.failures;
|
|
1628
1766
|
var result = wantResults ? results : lastResult;
|
|
@@ -1635,19 +1773,27 @@ var Table = (function () {
|
|
|
1635
1773
|
Table.prototype.bulkPut = function (objects, keysOrOptions, options) {
|
|
1636
1774
|
var _this = this;
|
|
1637
1775
|
var keys = Array.isArray(keysOrOptions) ? keysOrOptions : undefined;
|
|
1638
|
-
options =
|
|
1776
|
+
options =
|
|
1777
|
+
options || (keys ? undefined : keysOrOptions);
|
|
1639
1778
|
var wantResults = options ? options.allKeys : undefined;
|
|
1640
1779
|
return this._trans('readwrite', function (trans) {
|
|
1641
1780
|
var _a = _this.schema.primKey, auto = _a.auto, keyPath = _a.keyPath;
|
|
1642
1781
|
if (keyPath && keys)
|
|
1643
|
-
throw new exceptions.InvalidArgument(
|
|
1782
|
+
throw new exceptions.InvalidArgument('bulkPut(): keys argument invalid on tables with inbound keys');
|
|
1644
1783
|
if (keys && keys.length !== objects.length)
|
|
1645
|
-
throw new exceptions.InvalidArgument(
|
|
1784
|
+
throw new exceptions.InvalidArgument('Arguments objects and keys must have the same length');
|
|
1646
1785
|
var numObjects = objects.length;
|
|
1647
|
-
var objectsToPut = keyPath && auto
|
|
1648
|
-
objects.map(workaroundForUndefinedPrimKey(keyPath))
|
|
1649
|
-
objects;
|
|
1650
|
-
return _this.core
|
|
1786
|
+
var objectsToPut = keyPath && auto
|
|
1787
|
+
? objects.map(workaroundForUndefinedPrimKey(keyPath))
|
|
1788
|
+
: objects;
|
|
1789
|
+
return _this.core
|
|
1790
|
+
.mutate({
|
|
1791
|
+
trans: trans,
|
|
1792
|
+
type: 'put',
|
|
1793
|
+
keys: keys,
|
|
1794
|
+
values: objectsToPut,
|
|
1795
|
+
wantResults: wantResults,
|
|
1796
|
+
})
|
|
1651
1797
|
.then(function (_a) {
|
|
1652
1798
|
var numFailures = _a.numFailures, results = _a.results, lastResult = _a.lastResult, failures = _a.failures;
|
|
1653
1799
|
var result = wantResults ? results : lastResult;
|
|
@@ -1697,8 +1843,8 @@ var Table = (function () {
|
|
|
1697
1843
|
values: resultObjs,
|
|
1698
1844
|
updates: {
|
|
1699
1845
|
keys: keys,
|
|
1700
|
-
changeSpecs: changeSpecs
|
|
1701
|
-
}
|
|
1846
|
+
changeSpecs: changeSpecs,
|
|
1847
|
+
},
|
|
1702
1848
|
})
|
|
1703
1849
|
.then(function (_a) {
|
|
1704
1850
|
var numFailures = _a.numFailures, failures = _a.failures;
|
|
@@ -1722,7 +1868,8 @@ var Table = (function () {
|
|
|
1722
1868
|
var _this = this;
|
|
1723
1869
|
var numKeys = keys.length;
|
|
1724
1870
|
return this._trans('readwrite', function (trans) {
|
|
1725
|
-
return _this.core
|
|
1871
|
+
return _this.core
|
|
1872
|
+
.mutate({ trans: trans, type: 'delete', keys: keys })
|
|
1726
1873
|
.then(function (res) { return builtInDeletionTrigger(_this, keys, res); });
|
|
1727
1874
|
}).then(function (_a) {
|
|
1728
1875
|
var numFailures = _a.numFailures, lastResult = _a.lastResult, failures = _a.failures;
|
|
@@ -1744,7 +1891,7 @@ function Events(ctx) {
|
|
|
1744
1891
|
evs[eventName].subscribe.apply(null, args);
|
|
1745
1892
|
return ctx;
|
|
1746
1893
|
}
|
|
1747
|
-
else if (typeof
|
|
1894
|
+
else if (typeof eventName === 'string') {
|
|
1748
1895
|
return evs[eventName];
|
|
1749
1896
|
}
|
|
1750
1897
|
};
|
|
@@ -1770,9 +1917,11 @@ function Events(ctx) {
|
|
|
1770
1917
|
}
|
|
1771
1918
|
},
|
|
1772
1919
|
unsubscribe: function (cb) {
|
|
1773
|
-
context.subscribers = context.subscribers.filter(function (fn) {
|
|
1920
|
+
context.subscribers = context.subscribers.filter(function (fn) {
|
|
1921
|
+
return fn !== cb;
|
|
1922
|
+
});
|
|
1774
1923
|
context.fire = context.subscribers.reduce(chainFunction, defaultFunction);
|
|
1775
|
-
}
|
|
1924
|
+
},
|
|
1776
1925
|
};
|
|
1777
1926
|
evs[eventName] = rv[eventName] = context;
|
|
1778
1927
|
return context;
|
|
@@ -1796,7 +1945,7 @@ function Events(ctx) {
|
|
|
1796
1945
|
});
|
|
1797
1946
|
}
|
|
1798
1947
|
else
|
|
1799
|
-
throw new exceptions.InvalidArgument(
|
|
1948
|
+
throw new exceptions.InvalidArgument('Invalid event config');
|
|
1800
1949
|
});
|
|
1801
1950
|
}
|
|
1802
1951
|
}
|
|
@@ -1812,18 +1961,20 @@ function createTableConstructor(db) {
|
|
|
1812
1961
|
this._tx = trans;
|
|
1813
1962
|
this.name = name;
|
|
1814
1963
|
this.schema = tableSchema;
|
|
1815
|
-
this.hook = db._allTables[name]
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1964
|
+
this.hook = db._allTables[name]
|
|
1965
|
+
? db._allTables[name].hook
|
|
1966
|
+
: Events(null, {
|
|
1967
|
+
creating: [hookCreatingChain, nop],
|
|
1968
|
+
reading: [pureFunctionChain, mirror],
|
|
1969
|
+
updating: [hookUpdatingChain, nop],
|
|
1970
|
+
deleting: [hookDeletingChain, nop],
|
|
1971
|
+
});
|
|
1821
1972
|
});
|
|
1822
1973
|
}
|
|
1823
1974
|
|
|
1824
1975
|
function isPlainKeyRange(ctx, ignoreLimitFilter) {
|
|
1825
|
-
return !(ctx.filter || ctx.algorithm || ctx.or) &&
|
|
1826
|
-
(ignoreLimitFilter ? ctx.justLimit : !ctx.replayFilter);
|
|
1976
|
+
return (!(ctx.filter || ctx.algorithm || ctx.or) &&
|
|
1977
|
+
(ignoreLimitFilter ? ctx.justLimit : !ctx.replayFilter));
|
|
1827
1978
|
}
|
|
1828
1979
|
function addFilter(ctx, fn) {
|
|
1829
1980
|
ctx.filter = combine(ctx.filter, fn);
|
|
@@ -1841,7 +1992,11 @@ function getIndexOrStore(ctx, coreSchema) {
|
|
|
1841
1992
|
return coreSchema.primaryKey;
|
|
1842
1993
|
var index = coreSchema.getIndexByKeyPath(ctx.index);
|
|
1843
1994
|
if (!index)
|
|
1844
|
-
throw new exceptions.Schema(
|
|
1995
|
+
throw new exceptions.Schema('KeyPath ' +
|
|
1996
|
+
ctx.index +
|
|
1997
|
+
' on object store ' +
|
|
1998
|
+
coreSchema.name +
|
|
1999
|
+
' is not indexed');
|
|
1845
2000
|
return index;
|
|
1846
2001
|
}
|
|
1847
2002
|
function openCursor(ctx, coreTable, trans) {
|
|
@@ -1853,19 +2008,22 @@ function openCursor(ctx, coreTable, trans) {
|
|
|
1853
2008
|
unique: !!ctx.unique,
|
|
1854
2009
|
query: {
|
|
1855
2010
|
index: index,
|
|
1856
|
-
range: ctx.range
|
|
1857
|
-
}
|
|
2011
|
+
range: ctx.range,
|
|
2012
|
+
},
|
|
1858
2013
|
});
|
|
1859
2014
|
}
|
|
1860
2015
|
function iter(ctx, fn, coreTrans, coreTable) {
|
|
1861
|
-
var filter = ctx.replayFilter
|
|
2016
|
+
var filter = ctx.replayFilter
|
|
2017
|
+
? combine(ctx.filter, ctx.replayFilter())
|
|
2018
|
+
: ctx.filter;
|
|
1862
2019
|
if (!ctx.or) {
|
|
1863
2020
|
return iterate(openCursor(ctx, coreTable, coreTrans), combine(ctx.algorithm, filter), fn, !ctx.keysOnly && ctx.valueMapper);
|
|
1864
2021
|
}
|
|
1865
2022
|
else {
|
|
1866
2023
|
var set_1 = {};
|
|
1867
2024
|
var union = function (item, cursor, advance) {
|
|
1868
|
-
if (!filter ||
|
|
2025
|
+
if (!filter ||
|
|
2026
|
+
filter(cursor, advance, function (result) { return cursor.stop(result); }, function (err) { return cursor.fail(err); })) {
|
|
1869
2027
|
var primaryKey = cursor.primaryKey;
|
|
1870
2028
|
var key = '' + primaryKey;
|
|
1871
2029
|
if (key === '[object ArrayBuffer]')
|
|
@@ -1878,7 +2036,7 @@ function iter(ctx, fn, coreTrans, coreTable) {
|
|
|
1878
2036
|
};
|
|
1879
2037
|
return Promise.all([
|
|
1880
2038
|
ctx.or._iterate(union, coreTrans),
|
|
1881
|
-
iterate(openCursor(ctx, coreTable, coreTrans), ctx.algorithm, union, !ctx.keysOnly && ctx.valueMapper)
|
|
2039
|
+
iterate(openCursor(ctx, coreTable, coreTrans), ctx.algorithm, union, !ctx.keysOnly && ctx.valueMapper),
|
|
1882
2040
|
]);
|
|
1883
2041
|
}
|
|
1884
2042
|
}
|
|
@@ -1889,8 +2047,15 @@ function iterate(cursorPromise, filter, fn, valueMapper) {
|
|
|
1889
2047
|
if (cursor) {
|
|
1890
2048
|
return cursor.start(function () {
|
|
1891
2049
|
var c = function () { return cursor.continue(); };
|
|
1892
|
-
if (!filter ||
|
|
1893
|
-
|
|
2050
|
+
if (!filter ||
|
|
2051
|
+
filter(cursor, function (advancer) { return (c = advancer); }, function (val) {
|
|
2052
|
+
cursor.stop(val);
|
|
2053
|
+
c = nop;
|
|
2054
|
+
}, function (e) {
|
|
2055
|
+
cursor.fail(e);
|
|
2056
|
+
c = nop;
|
|
2057
|
+
}))
|
|
2058
|
+
wrappedFn(cursor.value, cursor, function (advancer) { return (c = advancer); });
|
|
1894
2059
|
c();
|
|
1895
2060
|
});
|
|
1896
2061
|
}
|
|
@@ -1902,15 +2067,15 @@ var Collection = (function () {
|
|
|
1902
2067
|
}
|
|
1903
2068
|
Collection.prototype._read = function (fn, cb) {
|
|
1904
2069
|
var ctx = this._ctx;
|
|
1905
|
-
return ctx.error
|
|
1906
|
-
ctx.table._trans(null, rejection.bind(null, ctx.error))
|
|
1907
|
-
ctx.table._trans('readonly', fn).then(cb);
|
|
2070
|
+
return ctx.error
|
|
2071
|
+
? ctx.table._trans(null, rejection.bind(null, ctx.error))
|
|
2072
|
+
: ctx.table._trans('readonly', fn).then(cb);
|
|
1908
2073
|
};
|
|
1909
2074
|
Collection.prototype._write = function (fn) {
|
|
1910
2075
|
var ctx = this._ctx;
|
|
1911
|
-
return ctx.error
|
|
1912
|
-
ctx.table._trans(null, rejection.bind(null, ctx.error))
|
|
1913
|
-
ctx.table._trans('readwrite', fn,
|
|
2076
|
+
return ctx.error
|
|
2077
|
+
? ctx.table._trans(null, rejection.bind(null, ctx.error))
|
|
2078
|
+
: ctx.table._trans('readwrite', fn, 'locked');
|
|
1914
2079
|
};
|
|
1915
2080
|
Collection.prototype._addAlgorithm = function (fn) {
|
|
1916
2081
|
var ctx = this._ctx;
|
|
@@ -1940,18 +2105,22 @@ var Collection = (function () {
|
|
|
1940
2105
|
var ctx = _this._ctx;
|
|
1941
2106
|
var coreTable = ctx.table.core;
|
|
1942
2107
|
if (isPlainKeyRange(ctx, true)) {
|
|
1943
|
-
return coreTable
|
|
2108
|
+
return coreTable
|
|
2109
|
+
.count({
|
|
1944
2110
|
trans: trans,
|
|
1945
2111
|
query: {
|
|
1946
2112
|
index: getIndexOrStore(ctx, coreTable.schema),
|
|
1947
|
-
range: ctx.range
|
|
1948
|
-
}
|
|
1949
|
-
})
|
|
2113
|
+
range: ctx.range,
|
|
2114
|
+
},
|
|
2115
|
+
})
|
|
2116
|
+
.then(function (count) { return Math.min(count, ctx.limit); });
|
|
1950
2117
|
}
|
|
1951
2118
|
else {
|
|
1952
2119
|
var count = 0;
|
|
1953
|
-
return iter(ctx, function () {
|
|
1954
|
-
|
|
2120
|
+
return iter(ctx, function () {
|
|
2121
|
+
++count;
|
|
2122
|
+
return false;
|
|
2123
|
+
}, trans, coreTable).then(function () { return count; });
|
|
1955
2124
|
}
|
|
1956
2125
|
}).then(cb);
|
|
1957
2126
|
};
|
|
@@ -1962,7 +2131,7 @@ var Collection = (function () {
|
|
|
1962
2131
|
return getval(obj[parts[i]], i - 1);
|
|
1963
2132
|
return obj[lastPart];
|
|
1964
2133
|
}
|
|
1965
|
-
var order = this._ctx.dir ===
|
|
2134
|
+
var order = this._ctx.dir === 'next' ? 1 : -1;
|
|
1966
2135
|
function sorter(a, b) {
|
|
1967
2136
|
var aVal = getval(a, lastIndex), bVal = getval(b, lastIndex);
|
|
1968
2137
|
return cmp(aVal, bVal) * order;
|
|
@@ -1978,16 +2147,18 @@ var Collection = (function () {
|
|
|
1978
2147
|
if (isPlainKeyRange(ctx, true) && ctx.limit > 0) {
|
|
1979
2148
|
var valueMapper_1 = ctx.valueMapper;
|
|
1980
2149
|
var index = getIndexOrStore(ctx, ctx.table.core.schema);
|
|
1981
|
-
return ctx.table.core
|
|
2150
|
+
return ctx.table.core
|
|
2151
|
+
.query({
|
|
1982
2152
|
trans: trans,
|
|
1983
2153
|
limit: ctx.limit,
|
|
1984
2154
|
values: true,
|
|
1985
2155
|
direction: ctx.dir === 'prev' ? 'prev' : undefined,
|
|
1986
2156
|
query: {
|
|
1987
2157
|
index: index,
|
|
1988
|
-
range: ctx.range
|
|
1989
|
-
}
|
|
1990
|
-
})
|
|
2158
|
+
range: ctx.range,
|
|
2159
|
+
},
|
|
2160
|
+
})
|
|
2161
|
+
.then(function (_a) {
|
|
1991
2162
|
var result = _a.result;
|
|
1992
2163
|
return valueMapper_1 ? result.map(valueMapper_1) : result;
|
|
1993
2164
|
});
|
|
@@ -2024,7 +2195,7 @@ var Collection = (function () {
|
|
|
2024
2195
|
else {
|
|
2025
2196
|
addReplayFilter(ctx, function () {
|
|
2026
2197
|
var offsetLeft = offset;
|
|
2027
|
-
return function () { return
|
|
2198
|
+
return function () { return --offsetLeft < 0; };
|
|
2028
2199
|
});
|
|
2029
2200
|
}
|
|
2030
2201
|
return this;
|
|
@@ -2054,7 +2225,11 @@ var Collection = (function () {
|
|
|
2054
2225
|
return this;
|
|
2055
2226
|
};
|
|
2056
2227
|
Collection.prototype.first = function (cb) {
|
|
2057
|
-
return this.limit(1)
|
|
2228
|
+
return this.limit(1)
|
|
2229
|
+
.toArray(function (a) {
|
|
2230
|
+
return a[0];
|
|
2231
|
+
})
|
|
2232
|
+
.then(cb);
|
|
2058
2233
|
};
|
|
2059
2234
|
Collection.prototype.last = function (cb) {
|
|
2060
2235
|
return this.reverse().first(cb);
|
|
@@ -2073,7 +2248,7 @@ var Collection = (function () {
|
|
|
2073
2248
|
return new this.db.WhereClause(this._ctx.table, indexName, this);
|
|
2074
2249
|
};
|
|
2075
2250
|
Collection.prototype.reverse = function () {
|
|
2076
|
-
this._ctx.dir =
|
|
2251
|
+
this._ctx.dir = this._ctx.dir === 'prev' ? 'next' : 'prev';
|
|
2077
2252
|
if (this._ondirectionchange)
|
|
2078
2253
|
this._ondirectionchange(this._ctx.dir);
|
|
2079
2254
|
return this;
|
|
@@ -2084,16 +2259,20 @@ var Collection = (function () {
|
|
|
2084
2259
|
Collection.prototype.eachKey = function (cb) {
|
|
2085
2260
|
var ctx = this._ctx;
|
|
2086
2261
|
ctx.keysOnly = !ctx.isMatch;
|
|
2087
|
-
return this.each(function (val, cursor) {
|
|
2262
|
+
return this.each(function (val, cursor) {
|
|
2263
|
+
cb(cursor.key, cursor);
|
|
2264
|
+
});
|
|
2088
2265
|
};
|
|
2089
2266
|
Collection.prototype.eachUniqueKey = function (cb) {
|
|
2090
|
-
this._ctx.unique =
|
|
2267
|
+
this._ctx.unique = 'unique';
|
|
2091
2268
|
return this.eachKey(cb);
|
|
2092
2269
|
};
|
|
2093
2270
|
Collection.prototype.eachPrimaryKey = function (cb) {
|
|
2094
2271
|
var ctx = this._ctx;
|
|
2095
2272
|
ctx.keysOnly = !ctx.isMatch;
|
|
2096
|
-
return this.each(function (val, cursor) {
|
|
2273
|
+
return this.each(function (val, cursor) {
|
|
2274
|
+
cb(cursor.primaryKey, cursor);
|
|
2275
|
+
});
|
|
2097
2276
|
};
|
|
2098
2277
|
Collection.prototype.keys = function (cb) {
|
|
2099
2278
|
var ctx = this._ctx;
|
|
@@ -2101,9 +2280,11 @@ var Collection = (function () {
|
|
|
2101
2280
|
var a = [];
|
|
2102
2281
|
return this.each(function (item, cursor) {
|
|
2103
2282
|
a.push(cursor.key);
|
|
2104
|
-
})
|
|
2283
|
+
})
|
|
2284
|
+
.then(function () {
|
|
2105
2285
|
return a;
|
|
2106
|
-
})
|
|
2286
|
+
})
|
|
2287
|
+
.then(cb);
|
|
2107
2288
|
};
|
|
2108
2289
|
Collection.prototype.primaryKeys = function (cb) {
|
|
2109
2290
|
var ctx = this._ctx;
|
|
@@ -2117,28 +2298,36 @@ var Collection = (function () {
|
|
|
2117
2298
|
direction: ctx.dir === 'prev' ? 'prev' : undefined,
|
|
2118
2299
|
query: {
|
|
2119
2300
|
index: index,
|
|
2120
|
-
range: ctx.range
|
|
2121
|
-
}
|
|
2301
|
+
range: ctx.range,
|
|
2302
|
+
},
|
|
2122
2303
|
});
|
|
2123
|
-
})
|
|
2304
|
+
})
|
|
2305
|
+
.then(function (_a) {
|
|
2124
2306
|
var result = _a.result;
|
|
2125
2307
|
return result;
|
|
2126
|
-
})
|
|
2308
|
+
})
|
|
2309
|
+
.then(cb);
|
|
2127
2310
|
}
|
|
2128
2311
|
ctx.keysOnly = !ctx.isMatch;
|
|
2129
2312
|
var a = [];
|
|
2130
2313
|
return this.each(function (item, cursor) {
|
|
2131
2314
|
a.push(cursor.primaryKey);
|
|
2132
|
-
})
|
|
2315
|
+
})
|
|
2316
|
+
.then(function () {
|
|
2133
2317
|
return a;
|
|
2134
|
-
})
|
|
2318
|
+
})
|
|
2319
|
+
.then(cb);
|
|
2135
2320
|
};
|
|
2136
2321
|
Collection.prototype.uniqueKeys = function (cb) {
|
|
2137
|
-
this._ctx.unique =
|
|
2322
|
+
this._ctx.unique = 'unique';
|
|
2138
2323
|
return this.keys(cb);
|
|
2139
2324
|
};
|
|
2140
2325
|
Collection.prototype.firstKey = function (cb) {
|
|
2141
|
-
return this.limit(1)
|
|
2326
|
+
return this.limit(1)
|
|
2327
|
+
.keys(function (a) {
|
|
2328
|
+
return a[0];
|
|
2329
|
+
})
|
|
2330
|
+
.then(cb);
|
|
2142
2331
|
};
|
|
2143
2332
|
Collection.prototype.lastKey = function (cb) {
|
|
2144
2333
|
return this.reverse().firstKey(cb);
|
|
@@ -2173,7 +2362,8 @@ var Collection = (function () {
|
|
|
2173
2362
|
var modifyChunkSize = _this.db._options.modifyChunkSize;
|
|
2174
2363
|
if (modifyChunkSize) {
|
|
2175
2364
|
if (typeof modifyChunkSize == 'object') {
|
|
2176
|
-
limit =
|
|
2365
|
+
limit =
|
|
2366
|
+
modifyChunkSize[coreTable.name] || modifyChunkSize['*'] || 200;
|
|
2177
2367
|
}
|
|
2178
2368
|
else {
|
|
2179
2369
|
limit = modifyChunkSize;
|
|
@@ -2191,21 +2381,25 @@ var Collection = (function () {
|
|
|
2191
2381
|
}
|
|
2192
2382
|
};
|
|
2193
2383
|
var isUnconditionalDelete = changes === deleteCallback;
|
|
2194
|
-
return _this.clone()
|
|
2384
|
+
return _this.clone()
|
|
2385
|
+
.primaryKeys()
|
|
2386
|
+
.then(function (keys) {
|
|
2195
2387
|
var criteria = isPlainKeyRange(ctx) &&
|
|
2196
2388
|
ctx.limit === Infinity &&
|
|
2197
2389
|
(typeof changes !== 'function' || isUnconditionalDelete) && {
|
|
2198
2390
|
index: ctx.index,
|
|
2199
|
-
range: ctx.range
|
|
2391
|
+
range: ctx.range,
|
|
2200
2392
|
};
|
|
2201
2393
|
var nextChunk = function (offset) {
|
|
2202
2394
|
var count = Math.min(limit, keys.length - offset);
|
|
2203
2395
|
var keysInChunk = keys.slice(offset, offset + count);
|
|
2204
|
-
return (isUnconditionalDelete
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2396
|
+
return (isUnconditionalDelete
|
|
2397
|
+
? Promise.resolve([])
|
|
2398
|
+
: coreTable.getMany({
|
|
2399
|
+
trans: trans,
|
|
2400
|
+
keys: keysInChunk,
|
|
2401
|
+
cache: 'immutable',
|
|
2402
|
+
})).then(function (values) {
|
|
2209
2403
|
var addValues = [];
|
|
2210
2404
|
var putValues = [];
|
|
2211
2405
|
var putKeys = outbound ? [] : null;
|
|
@@ -2215,13 +2409,14 @@ var Collection = (function () {
|
|
|
2215
2409
|
var origValue = values[i];
|
|
2216
2410
|
var ctx_1 = {
|
|
2217
2411
|
value: deepClone(origValue),
|
|
2218
|
-
primKey: keys[offset + i]
|
|
2412
|
+
primKey: keys[offset + i],
|
|
2219
2413
|
};
|
|
2220
2414
|
if (modifyer.call(ctx_1, ctx_1.value, ctx_1) !== false) {
|
|
2221
2415
|
if (ctx_1.value == null) {
|
|
2222
2416
|
deleteKeys.push(keys[offset + i]);
|
|
2223
2417
|
}
|
|
2224
|
-
else if (!outbound &&
|
|
2418
|
+
else if (!outbound &&
|
|
2419
|
+
cmp(extractKey(origValue), extractKey(ctx_1.value)) !== 0) {
|
|
2225
2420
|
deleteKeys.push(keys[offset + i]);
|
|
2226
2421
|
addValues.push(ctx_1.value);
|
|
2227
2422
|
}
|
|
@@ -2233,38 +2428,53 @@ var Collection = (function () {
|
|
|
2233
2428
|
}
|
|
2234
2429
|
}
|
|
2235
2430
|
return Promise.resolve(addValues.length > 0 &&
|
|
2236
|
-
coreTable
|
|
2431
|
+
coreTable
|
|
2432
|
+
.mutate({ trans: trans, type: 'add', values: addValues })
|
|
2237
2433
|
.then(function (res) {
|
|
2238
2434
|
for (var pos in res.failures) {
|
|
2239
2435
|
deleteKeys.splice(parseInt(pos), 1);
|
|
2240
2436
|
}
|
|
2241
2437
|
applyMutateResult(addValues.length, res);
|
|
2242
|
-
}))
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2438
|
+
}))
|
|
2439
|
+
.then(function () {
|
|
2440
|
+
return (putValues.length > 0 ||
|
|
2441
|
+
(criteria && typeof changes === 'object')) &&
|
|
2442
|
+
coreTable
|
|
2443
|
+
.mutate({
|
|
2444
|
+
trans: trans,
|
|
2445
|
+
type: 'put',
|
|
2446
|
+
keys: putKeys,
|
|
2447
|
+
values: putValues,
|
|
2448
|
+
criteria: criteria,
|
|
2449
|
+
changeSpec: typeof changes !== 'function' && changes,
|
|
2450
|
+
isAdditionalChunk: offset > 0,
|
|
2451
|
+
})
|
|
2452
|
+
.then(function (res) { return applyMutateResult(putValues.length, res); });
|
|
2453
|
+
})
|
|
2454
|
+
.then(function () {
|
|
2455
|
+
return (deleteKeys.length > 0 ||
|
|
2456
|
+
(criteria && isUnconditionalDelete)) &&
|
|
2457
|
+
coreTable
|
|
2458
|
+
.mutate({
|
|
2459
|
+
trans: trans,
|
|
2460
|
+
type: 'delete',
|
|
2461
|
+
keys: deleteKeys,
|
|
2462
|
+
criteria: criteria,
|
|
2463
|
+
isAdditionalChunk: offset > 0,
|
|
2464
|
+
})
|
|
2465
|
+
.then(function (res) {
|
|
2466
|
+
return builtInDeletionTrigger(ctx.table, deleteKeys, res);
|
|
2467
|
+
})
|
|
2468
|
+
.then(function (res) { return applyMutateResult(deleteKeys.length, res); });
|
|
2469
|
+
})
|
|
2470
|
+
.then(function () {
|
|
2471
|
+
return (keys.length > offset + count && nextChunk(offset + limit));
|
|
2262
2472
|
});
|
|
2263
2473
|
});
|
|
2264
2474
|
};
|
|
2265
2475
|
return nextChunk(0).then(function () {
|
|
2266
2476
|
if (totalFailures.length > 0)
|
|
2267
|
-
throw new ModifyError(
|
|
2477
|
+
throw new ModifyError('Error modifying one or more objects', totalFailures, successCount, failedKeys);
|
|
2268
2478
|
return keys.length;
|
|
2269
2479
|
});
|
|
2270
2480
|
});
|
|
@@ -2279,12 +2489,15 @@ var Collection = (function () {
|
|
|
2279
2489
|
return this._write(function (trans) {
|
|
2280
2490
|
var primaryKey = ctx.table.core.schema.primaryKey;
|
|
2281
2491
|
var coreRange = range;
|
|
2282
|
-
return ctx.table.core
|
|
2283
|
-
|
|
2492
|
+
return ctx.table.core
|
|
2493
|
+
.count({ trans: trans, query: { index: primaryKey, range: coreRange } })
|
|
2494
|
+
.then(function (count) {
|
|
2495
|
+
return ctx.table.core
|
|
2496
|
+
.mutate({ trans: trans, type: 'deleteRange', range: coreRange })
|
|
2284
2497
|
.then(function (_a) {
|
|
2285
2498
|
var failures = _a.failures, numFailures = _a.numFailures;
|
|
2286
2499
|
if (numFailures)
|
|
2287
|
-
throw new ModifyError(
|
|
2500
|
+
throw new ModifyError('Could not delete some values', Object.keys(failures).map(function (pos) { return failures[pos]; }), count - numFailures);
|
|
2288
2501
|
return count - numFailures;
|
|
2289
2502
|
});
|
|
2290
2503
|
});
|
|
@@ -2294,7 +2507,7 @@ var Collection = (function () {
|
|
|
2294
2507
|
};
|
|
2295
2508
|
return Collection;
|
|
2296
2509
|
}());
|
|
2297
|
-
var deleteCallback = function (value, ctx) { return ctx.value = null; };
|
|
2510
|
+
var deleteCallback = function (value, ctx) { return (ctx.value = null); };
|
|
2298
2511
|
|
|
2299
2512
|
function createCollectionConstructor(db) {
|
|
2300
2513
|
return makeClassConstructor(Collection.prototype, function Collection(whereClause, keyRangeGenerator) {
|
|
@@ -2313,11 +2526,13 @@ function createCollectionConstructor(db) {
|
|
|
2313
2526
|
this._ctx = {
|
|
2314
2527
|
table: table,
|
|
2315
2528
|
index: whereCtx.index,
|
|
2316
|
-
isPrimKey:
|
|
2529
|
+
isPrimKey: !whereCtx.index ||
|
|
2530
|
+
(table.schema.primKey.keyPath &&
|
|
2531
|
+
whereCtx.index === table.schema.primKey.name),
|
|
2317
2532
|
range: keyRange,
|
|
2318
2533
|
keysOnly: false,
|
|
2319
|
-
dir:
|
|
2320
|
-
unique:
|
|
2534
|
+
dir: 'next',
|
|
2535
|
+
unique: '',
|
|
2321
2536
|
algorithm: null,
|
|
2322
2537
|
filter: null,
|
|
2323
2538
|
replayFilter: null,
|
|
@@ -2327,7 +2542,7 @@ function createCollectionConstructor(db) {
|
|
|
2327
2542
|
limit: Infinity,
|
|
2328
2543
|
error: error,
|
|
2329
2544
|
or: whereCtx.or,
|
|
2330
|
-
valueMapper: readingHook !== mirror ? readingHook : null
|
|
2545
|
+
valueMapper: readingHook !== mirror ? readingHook : null,
|
|
2331
2546
|
};
|
|
2332
2547
|
});
|
|
2333
2548
|
}
|
|
@@ -2340,24 +2555,24 @@ function simpleCompareReverse(a, b) {
|
|
|
2340
2555
|
}
|
|
2341
2556
|
|
|
2342
2557
|
function fail(collectionOrWhereClause, err, T) {
|
|
2343
|
-
var collection = collectionOrWhereClause instanceof WhereClause
|
|
2344
|
-
new collectionOrWhereClause.Collection(collectionOrWhereClause)
|
|
2345
|
-
collectionOrWhereClause;
|
|
2558
|
+
var collection = collectionOrWhereClause instanceof WhereClause
|
|
2559
|
+
? new collectionOrWhereClause.Collection(collectionOrWhereClause)
|
|
2560
|
+
: collectionOrWhereClause;
|
|
2346
2561
|
collection._ctx.error = T ? new T(err) : new TypeError(err);
|
|
2347
2562
|
return collection;
|
|
2348
2563
|
}
|
|
2349
2564
|
function emptyCollection(whereClause) {
|
|
2350
|
-
return new whereClause.Collection(whereClause, function () { return rangeEqual(
|
|
2565
|
+
return new whereClause.Collection(whereClause, function () { return rangeEqual(''); }).limit(0);
|
|
2351
2566
|
}
|
|
2352
2567
|
function upperFactory(dir) {
|
|
2353
|
-
return dir ===
|
|
2354
|
-
function (s) { return s.toUpperCase(); }
|
|
2355
|
-
function (s) { return s.toLowerCase(); };
|
|
2568
|
+
return dir === 'next'
|
|
2569
|
+
? function (s) { return s.toUpperCase(); }
|
|
2570
|
+
: function (s) { return s.toLowerCase(); };
|
|
2356
2571
|
}
|
|
2357
2572
|
function lowerFactory(dir) {
|
|
2358
|
-
return dir ===
|
|
2359
|
-
function (s) { return s.toLowerCase(); }
|
|
2360
|
-
function (s) { return s.toUpperCase(); };
|
|
2573
|
+
return dir === 'next'
|
|
2574
|
+
? function (s) { return s.toLowerCase(); }
|
|
2575
|
+
: function (s) { return s.toUpperCase(); };
|
|
2361
2576
|
}
|
|
2362
2577
|
function nextCasing(key, lowerKey, upperNeedle, lowerNeedle, cmp, dir) {
|
|
2363
2578
|
var length = Math.min(key.length, lowerNeedle.length);
|
|
@@ -2376,11 +2591,13 @@ function nextCasing(key, lowerKey, upperNeedle, lowerNeedle, cmp, dir) {
|
|
|
2376
2591
|
if (cmp(key[i], lwrKeyChar) < 0)
|
|
2377
2592
|
llp = i;
|
|
2378
2593
|
}
|
|
2379
|
-
if (length < lowerNeedle.length && dir ===
|
|
2594
|
+
if (length < lowerNeedle.length && dir === 'next')
|
|
2380
2595
|
return key + upperNeedle.substr(key.length);
|
|
2381
|
-
if (length < key.length && dir ===
|
|
2596
|
+
if (length < key.length && dir === 'prev')
|
|
2382
2597
|
return key.substr(0, upperNeedle.length);
|
|
2383
|
-
return
|
|
2598
|
+
return llp < 0
|
|
2599
|
+
? null
|
|
2600
|
+
: key.substr(0, llp) + lowerNeedle[llp] + upperNeedle.substr(llp + 1);
|
|
2384
2601
|
}
|
|
2385
2602
|
function addIgnoreCaseAlgorithm(whereClause, match, needles, suffix) {
|
|
2386
2603
|
var upper, lower, compare, upperNeedles, lowerNeedles, direction, nextKeySuffix, needlesLen = needles.length;
|
|
@@ -2390,19 +2607,27 @@ function addIgnoreCaseAlgorithm(whereClause, match, needles, suffix) {
|
|
|
2390
2607
|
function initDirection(dir) {
|
|
2391
2608
|
upper = upperFactory(dir);
|
|
2392
2609
|
lower = lowerFactory(dir);
|
|
2393
|
-
compare =
|
|
2394
|
-
var needleBounds = needles
|
|
2610
|
+
compare = dir === 'next' ? simpleCompare : simpleCompareReverse;
|
|
2611
|
+
var needleBounds = needles
|
|
2612
|
+
.map(function (needle) {
|
|
2395
2613
|
return { lower: lower(needle), upper: upper(needle) };
|
|
2396
|
-
})
|
|
2614
|
+
})
|
|
2615
|
+
.sort(function (a, b) {
|
|
2397
2616
|
return compare(a.lower, b.lower);
|
|
2398
2617
|
});
|
|
2399
|
-
upperNeedles = needleBounds.map(function (nb) {
|
|
2400
|
-
|
|
2618
|
+
upperNeedles = needleBounds.map(function (nb) {
|
|
2619
|
+
return nb.upper;
|
|
2620
|
+
});
|
|
2621
|
+
lowerNeedles = needleBounds.map(function (nb) {
|
|
2622
|
+
return nb.lower;
|
|
2623
|
+
});
|
|
2401
2624
|
direction = dir;
|
|
2402
|
-
nextKeySuffix =
|
|
2625
|
+
nextKeySuffix = dir === 'next' ? '' : suffix;
|
|
2403
2626
|
}
|
|
2404
|
-
initDirection(
|
|
2405
|
-
var c = new whereClause.Collection(whereClause, function () {
|
|
2627
|
+
initDirection('next');
|
|
2628
|
+
var c = new whereClause.Collection(whereClause, function () {
|
|
2629
|
+
return createRange(upperNeedles[0], lowerNeedles[needlesLen - 1] + suffix);
|
|
2630
|
+
});
|
|
2406
2631
|
c._ondirectionchange = function (direction) {
|
|
2407
2632
|
initDirection(direction);
|
|
2408
2633
|
};
|
|
@@ -2421,12 +2646,15 @@ function addIgnoreCaseAlgorithm(whereClause, match, needles, suffix) {
|
|
|
2421
2646
|
var casing = nextCasing(key, lowerKey, upperNeedles[i], lowerNeedles[i], compare, direction);
|
|
2422
2647
|
if (casing === null && lowestPossibleCasing === null)
|
|
2423
2648
|
firstPossibleNeedle = i + 1;
|
|
2424
|
-
else if (lowestPossibleCasing === null ||
|
|
2649
|
+
else if (lowestPossibleCasing === null ||
|
|
2650
|
+
compare(lowestPossibleCasing, casing) > 0) {
|
|
2425
2651
|
lowestPossibleCasing = casing;
|
|
2426
2652
|
}
|
|
2427
2653
|
}
|
|
2428
2654
|
if (lowestPossibleCasing !== null) {
|
|
2429
|
-
advance(function () {
|
|
2655
|
+
advance(function () {
|
|
2656
|
+
cursor.continue(lowestPossibleCasing + nextKeySuffix);
|
|
2657
|
+
});
|
|
2430
2658
|
}
|
|
2431
2659
|
else {
|
|
2432
2660
|
advance(resolve);
|
|
@@ -2442,14 +2670,14 @@ function createRange(lower, upper, lowerOpen, upperOpen) {
|
|
|
2442
2670
|
lower: lower,
|
|
2443
2671
|
upper: upper,
|
|
2444
2672
|
lowerOpen: lowerOpen,
|
|
2445
|
-
upperOpen: upperOpen
|
|
2673
|
+
upperOpen: upperOpen,
|
|
2446
2674
|
};
|
|
2447
2675
|
}
|
|
2448
2676
|
function rangeEqual(value) {
|
|
2449
2677
|
return {
|
|
2450
2678
|
type: 1 ,
|
|
2451
2679
|
lower: value,
|
|
2452
|
-
upper: value
|
|
2680
|
+
upper: value,
|
|
2453
2681
|
};
|
|
2454
2682
|
}
|
|
2455
2683
|
|
|
@@ -2467,10 +2695,14 @@ var WhereClause = (function () {
|
|
|
2467
2695
|
includeLower = includeLower !== false;
|
|
2468
2696
|
includeUpper = includeUpper === true;
|
|
2469
2697
|
try {
|
|
2470
|
-
if (
|
|
2471
|
-
(this._cmp(lower, upper) === 0 &&
|
|
2698
|
+
if (this._cmp(lower, upper) > 0 ||
|
|
2699
|
+
(this._cmp(lower, upper) === 0 &&
|
|
2700
|
+
(includeLower || includeUpper) &&
|
|
2701
|
+
!(includeLower && includeUpper)))
|
|
2472
2702
|
return emptyCollection(this);
|
|
2473
|
-
return new this.Collection(this, function () {
|
|
2703
|
+
return new this.Collection(this, function () {
|
|
2704
|
+
return createRange(lower, upper, !includeLower, !includeUpper);
|
|
2705
|
+
});
|
|
2474
2706
|
}
|
|
2475
2707
|
catch (e) {
|
|
2476
2708
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
@@ -2489,12 +2721,16 @@ var WhereClause = (function () {
|
|
|
2489
2721
|
WhereClause.prototype.aboveOrEqual = function (value) {
|
|
2490
2722
|
if (value == null)
|
|
2491
2723
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
2492
|
-
return new this.Collection(this, function () {
|
|
2724
|
+
return new this.Collection(this, function () {
|
|
2725
|
+
return createRange(value, undefined, false);
|
|
2726
|
+
});
|
|
2493
2727
|
};
|
|
2494
2728
|
WhereClause.prototype.below = function (value) {
|
|
2495
2729
|
if (value == null)
|
|
2496
2730
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
2497
|
-
return new this.Collection(this, function () {
|
|
2731
|
+
return new this.Collection(this, function () {
|
|
2732
|
+
return createRange(undefined, value, false, true);
|
|
2733
|
+
});
|
|
2498
2734
|
};
|
|
2499
2735
|
WhereClause.prototype.belowOrEqual = function (value) {
|
|
2500
2736
|
if (value == null)
|
|
@@ -2507,18 +2743,18 @@ var WhereClause = (function () {
|
|
|
2507
2743
|
return this.between(str, str + maxString, true, true);
|
|
2508
2744
|
};
|
|
2509
2745
|
WhereClause.prototype.startsWithIgnoreCase = function (str) {
|
|
2510
|
-
if (str ===
|
|
2746
|
+
if (str === '')
|
|
2511
2747
|
return this.startsWith(str);
|
|
2512
2748
|
return addIgnoreCaseAlgorithm(this, function (x, a) { return x.indexOf(a[0]) === 0; }, [str], maxString);
|
|
2513
2749
|
};
|
|
2514
2750
|
WhereClause.prototype.equalsIgnoreCase = function (str) {
|
|
2515
|
-
return addIgnoreCaseAlgorithm(this, function (x, a) { return x === a[0]; }, [str],
|
|
2751
|
+
return addIgnoreCaseAlgorithm(this, function (x, a) { return x === a[0]; }, [str], '');
|
|
2516
2752
|
};
|
|
2517
2753
|
WhereClause.prototype.anyOfIgnoreCase = function () {
|
|
2518
2754
|
var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
2519
2755
|
if (set.length === 0)
|
|
2520
2756
|
return emptyCollection(this);
|
|
2521
|
-
return addIgnoreCaseAlgorithm(this, function (x, a) { return a.indexOf(x) !== -1; }, set,
|
|
2757
|
+
return addIgnoreCaseAlgorithm(this, function (x, a) { return a.indexOf(x) !== -1; }, set, '');
|
|
2522
2758
|
};
|
|
2523
2759
|
WhereClause.prototype.startsWithAnyOfIgnoreCase = function () {
|
|
2524
2760
|
var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
@@ -2538,11 +2774,11 @@ var WhereClause = (function () {
|
|
|
2538
2774
|
}
|
|
2539
2775
|
if (set.length === 0)
|
|
2540
2776
|
return emptyCollection(this);
|
|
2541
|
-
var c = new this.Collection(this, function () {
|
|
2777
|
+
var c = new this.Collection(this, function () {
|
|
2778
|
+
return createRange(set[0], set[set.length - 1]);
|
|
2779
|
+
});
|
|
2542
2780
|
c._ondirectionchange = function (direction) {
|
|
2543
|
-
compare =
|
|
2544
|
-
_this._ascending :
|
|
2545
|
-
_this._descending);
|
|
2781
|
+
compare = direction === 'next' ? _this._ascending : _this._descending;
|
|
2546
2782
|
set.sort(compare);
|
|
2547
2783
|
};
|
|
2548
2784
|
var i = 0;
|
|
@@ -2559,14 +2795,19 @@ var WhereClause = (function () {
|
|
|
2559
2795
|
return true;
|
|
2560
2796
|
}
|
|
2561
2797
|
else {
|
|
2562
|
-
advance(function () {
|
|
2798
|
+
advance(function () {
|
|
2799
|
+
cursor.continue(set[i]);
|
|
2800
|
+
});
|
|
2563
2801
|
return false;
|
|
2564
2802
|
}
|
|
2565
2803
|
});
|
|
2566
2804
|
return c;
|
|
2567
2805
|
};
|
|
2568
2806
|
WhereClause.prototype.notEqual = function (value) {
|
|
2569
|
-
return this.inAnyRange([
|
|
2807
|
+
return this.inAnyRange([
|
|
2808
|
+
[minKey, value],
|
|
2809
|
+
[value, this.db._maxKey],
|
|
2810
|
+
], { includeLowers: false, includeUppers: false });
|
|
2570
2811
|
};
|
|
2571
2812
|
WhereClause.prototype.noneOf = function () {
|
|
2572
2813
|
var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
@@ -2578,11 +2819,14 @@ var WhereClause = (function () {
|
|
|
2578
2819
|
catch (e) {
|
|
2579
2820
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
2580
2821
|
}
|
|
2581
|
-
var ranges = set.reduce(function (res, val) {
|
|
2582
|
-
res.concat([[res[res.length - 1][1], val]]) :
|
|
2583
|
-
|
|
2822
|
+
var ranges = set.reduce(function (res, val) {
|
|
2823
|
+
return res ? res.concat([[res[res.length - 1][1], val]]) : [[minKey, val]];
|
|
2824
|
+
}, null);
|
|
2584
2825
|
ranges.push([set[set.length - 1], this.db._maxKey]);
|
|
2585
|
-
return this.inAnyRange(ranges, {
|
|
2826
|
+
return this.inAnyRange(ranges, {
|
|
2827
|
+
includeLowers: false,
|
|
2828
|
+
includeUppers: false,
|
|
2829
|
+
});
|
|
2586
2830
|
};
|
|
2587
2831
|
WhereClause.prototype.inAnyRange = function (ranges, options) {
|
|
2588
2832
|
var _this = this;
|
|
@@ -2594,7 +2838,7 @@ var WhereClause = (function () {
|
|
|
2594
2838
|
range[1] !== undefined &&
|
|
2595
2839
|
ascending(range[0], range[1]) <= 0;
|
|
2596
2840
|
})) {
|
|
2597
|
-
return fail(this,
|
|
2841
|
+
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);
|
|
2598
2842
|
}
|
|
2599
2843
|
var includeLowers = !options || options.includeLowers !== false;
|
|
2600
2844
|
var includeUppers = options && options.includeUppers === true;
|
|
@@ -2613,7 +2857,9 @@ var WhereClause = (function () {
|
|
|
2613
2857
|
return ranges;
|
|
2614
2858
|
}
|
|
2615
2859
|
var sortDirection = ascending;
|
|
2616
|
-
function rangeSorter(a, b) {
|
|
2860
|
+
function rangeSorter(a, b) {
|
|
2861
|
+
return sortDirection(a[0], b[0]);
|
|
2862
|
+
}
|
|
2617
2863
|
var set;
|
|
2618
2864
|
try {
|
|
2619
2865
|
set = ranges.reduce(addRange, []);
|
|
@@ -2623,19 +2869,21 @@ var WhereClause = (function () {
|
|
|
2623
2869
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
2624
2870
|
}
|
|
2625
2871
|
var rangePos = 0;
|
|
2626
|
-
var keyIsBeyondCurrentEntry = includeUppers
|
|
2627
|
-
function (key) { return ascending(key, set[rangePos][1]) > 0; }
|
|
2628
|
-
function (key) { return ascending(key, set[rangePos][1]) >= 0; };
|
|
2629
|
-
var keyIsBeforeCurrentEntry = includeLowers
|
|
2630
|
-
function (key) { return descending(key, set[rangePos][0]) > 0; }
|
|
2631
|
-
function (key) { return descending(key, set[rangePos][0]) >= 0; };
|
|
2872
|
+
var keyIsBeyondCurrentEntry = includeUppers
|
|
2873
|
+
? function (key) { return ascending(key, set[rangePos][1]) > 0; }
|
|
2874
|
+
: function (key) { return ascending(key, set[rangePos][1]) >= 0; };
|
|
2875
|
+
var keyIsBeforeCurrentEntry = includeLowers
|
|
2876
|
+
? function (key) { return descending(key, set[rangePos][0]) > 0; }
|
|
2877
|
+
: function (key) { return descending(key, set[rangePos][0]) >= 0; };
|
|
2632
2878
|
function keyWithinCurrentRange(key) {
|
|
2633
2879
|
return !keyIsBeyondCurrentEntry(key) && !keyIsBeforeCurrentEntry(key);
|
|
2634
2880
|
}
|
|
2635
2881
|
var checkKey = keyIsBeyondCurrentEntry;
|
|
2636
|
-
var c = new this.Collection(this, function () {
|
|
2882
|
+
var c = new this.Collection(this, function () {
|
|
2883
|
+
return createRange(set[0][0], set[set.length - 1][1], !includeLowers, !includeUppers);
|
|
2884
|
+
});
|
|
2637
2885
|
c._ondirectionchange = function (direction) {
|
|
2638
|
-
if (direction ===
|
|
2886
|
+
if (direction === 'next') {
|
|
2639
2887
|
checkKey = keyIsBeyondCurrentEntry;
|
|
2640
2888
|
sortDirection = ascending;
|
|
2641
2889
|
}
|
|
@@ -2657,7 +2905,8 @@ var WhereClause = (function () {
|
|
|
2657
2905
|
if (keyWithinCurrentRange(key)) {
|
|
2658
2906
|
return true;
|
|
2659
2907
|
}
|
|
2660
|
-
else if (_this._cmp(key, set[rangePos][1]) === 0 ||
|
|
2908
|
+
else if (_this._cmp(key, set[rangePos][1]) === 0 ||
|
|
2909
|
+
_this._cmp(key, set[rangePos][0]) === 0) {
|
|
2661
2910
|
return false;
|
|
2662
2911
|
}
|
|
2663
2912
|
else {
|
|
@@ -2675,7 +2924,7 @@ var WhereClause = (function () {
|
|
|
2675
2924
|
WhereClause.prototype.startsWithAnyOf = function () {
|
|
2676
2925
|
var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
2677
2926
|
if (!set.every(function (s) { return typeof s === 'string'; })) {
|
|
2678
|
-
return fail(this,
|
|
2927
|
+
return fail(this, 'startsWithAnyOf() only works with strings');
|
|
2679
2928
|
}
|
|
2680
2929
|
if (set.length === 0)
|
|
2681
2930
|
return emptyCollection(this);
|
|
@@ -2689,13 +2938,13 @@ function createWhereClauseConstructor(db) {
|
|
|
2689
2938
|
this.db = db;
|
|
2690
2939
|
this._ctx = {
|
|
2691
2940
|
table: table,
|
|
2692
|
-
index: index ===
|
|
2693
|
-
or: orCollection
|
|
2941
|
+
index: index === ':id' ? null : index,
|
|
2942
|
+
or: orCollection,
|
|
2694
2943
|
};
|
|
2695
2944
|
this._cmp = this._ascending = cmp;
|
|
2696
2945
|
this._descending = function (a, b) { return cmp(b, a); };
|
|
2697
|
-
this._max = function (a, b) { return cmp(a, b) > 0 ? a : b; };
|
|
2698
|
-
this._min = function (a, b) { return cmp(a, b) < 0 ? a : b; };
|
|
2946
|
+
this._max = function (a, b) { return (cmp(a, b) > 0 ? a : b); };
|
|
2947
|
+
this._min = function (a, b) { return (cmp(a, b) < 0 ? a : b); };
|
|
2699
2948
|
this._IDBKeyRange = db._deps.IDBKeyRange;
|
|
2700
2949
|
if (!this._IDBKeyRange)
|
|
2701
2950
|
throw new exceptions.MissingAPI();
|
|
@@ -2757,9 +3006,9 @@ var Transaction = (function () {
|
|
|
2757
3006
|
assert(!this.idbtrans);
|
|
2758
3007
|
if (!idbtrans && !idbdb) {
|
|
2759
3008
|
switch (dbOpenError && dbOpenError.name) {
|
|
2760
|
-
case
|
|
3009
|
+
case 'DatabaseClosedError':
|
|
2761
3010
|
throw new exceptions.DatabaseClosed(dbOpenError);
|
|
2762
|
-
case
|
|
3011
|
+
case 'MissingAPIError':
|
|
2763
3012
|
throw new exceptions.MissingAPI(dbOpenError.message, dbOpenError);
|
|
2764
3013
|
default:
|
|
2765
3014
|
throw new exceptions.OpenFailed(dbOpenError);
|
|
@@ -2768,10 +3017,13 @@ var Transaction = (function () {
|
|
|
2768
3017
|
if (!this.active)
|
|
2769
3018
|
throw new exceptions.TransactionInactive();
|
|
2770
3019
|
assert(this._completion._state === null);
|
|
2771
|
-
idbtrans = this.idbtrans =
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
3020
|
+
idbtrans = this.idbtrans =
|
|
3021
|
+
idbtrans ||
|
|
3022
|
+
(this.db.core
|
|
3023
|
+
? this.db.core.transaction(this.storeNames, this.mode, { durability: this.chromeTransactionDurability })
|
|
3024
|
+
: idbdb.transaction(this.storeNames, this.mode, {
|
|
3025
|
+
durability: this.chromeTransactionDurability,
|
|
3026
|
+
}));
|
|
2775
3027
|
idbtrans.onerror = wrap(function (ev) {
|
|
2776
3028
|
preventDefault(ev);
|
|
2777
3029
|
_this._reject(idbtrans.error);
|
|
@@ -2780,13 +3032,13 @@ var Transaction = (function () {
|
|
|
2780
3032
|
preventDefault(ev);
|
|
2781
3033
|
_this.active && _this._reject(new exceptions.Abort(idbtrans.error));
|
|
2782
3034
|
_this.active = false;
|
|
2783
|
-
_this.on(
|
|
3035
|
+
_this.on('abort').fire(ev);
|
|
2784
3036
|
});
|
|
2785
3037
|
idbtrans.oncomplete = wrap(function () {
|
|
2786
3038
|
_this.active = false;
|
|
2787
3039
|
_this._resolve();
|
|
2788
3040
|
if ('mutatedParts' in idbtrans) {
|
|
2789
|
-
globalEvents.storagemutated.fire(idbtrans[
|
|
3041
|
+
globalEvents.storagemutated.fire(idbtrans['mutatedParts']);
|
|
2790
3042
|
}
|
|
2791
3043
|
});
|
|
2792
3044
|
return this;
|
|
@@ -2794,14 +3046,17 @@ var Transaction = (function () {
|
|
|
2794
3046
|
Transaction.prototype._promise = function (mode, fn, bWriteLock) {
|
|
2795
3047
|
var _this = this;
|
|
2796
3048
|
if (mode === 'readwrite' && this.mode !== 'readwrite')
|
|
2797
|
-
return rejection(new exceptions.ReadOnly(
|
|
3049
|
+
return rejection(new exceptions.ReadOnly('Transaction is readonly'));
|
|
2798
3050
|
if (!this.active)
|
|
2799
3051
|
return rejection(new exceptions.TransactionInactive());
|
|
2800
3052
|
if (this._locked()) {
|
|
2801
3053
|
return new DexiePromise(function (resolve, reject) {
|
|
2802
|
-
_this._blockedFuncs.push([
|
|
3054
|
+
_this._blockedFuncs.push([
|
|
3055
|
+
function () {
|
|
2803
3056
|
_this._promise(mode, fn, bWriteLock).then(resolve, reject);
|
|
2804
|
-
},
|
|
3057
|
+
},
|
|
3058
|
+
PSD,
|
|
3059
|
+
]);
|
|
2805
3060
|
});
|
|
2806
3061
|
}
|
|
2807
3062
|
else if (bWriteLock) {
|
|
@@ -2843,14 +3098,16 @@ var Transaction = (function () {
|
|
|
2843
3098
|
(function spin() {
|
|
2844
3099
|
++root._spinCount;
|
|
2845
3100
|
while (root._waitingQueue.length)
|
|
2846
|
-
|
|
3101
|
+
root._waitingQueue.shift()();
|
|
2847
3102
|
if (root._waitingFor)
|
|
2848
3103
|
store.get(-Infinity).onsuccess = spin;
|
|
2849
|
-
}()
|
|
3104
|
+
})();
|
|
2850
3105
|
}
|
|
2851
3106
|
var currentWaitPromise = root._waitingFor;
|
|
2852
3107
|
return new DexiePromise(function (resolve, reject) {
|
|
2853
|
-
promise
|
|
3108
|
+
promise
|
|
3109
|
+
.then(function (res) { return root._waitingQueue.push(wrap(resolve.bind(null, res))); }, function (err) { return root._waitingQueue.push(wrap(reject.bind(null, err))); })
|
|
3110
|
+
.finally(function () {
|
|
2854
3111
|
if (root._waitingFor === currentWaitPromise) {
|
|
2855
3112
|
root._waitingFor = null;
|
|
2856
3113
|
}
|
|
@@ -2866,12 +3123,12 @@ var Transaction = (function () {
|
|
|
2866
3123
|
}
|
|
2867
3124
|
};
|
|
2868
3125
|
Transaction.prototype.table = function (tableName) {
|
|
2869
|
-
var memoizedTables =
|
|
3126
|
+
var memoizedTables = this._memoizedTables || (this._memoizedTables = {});
|
|
2870
3127
|
if (hasOwn(memoizedTables, tableName))
|
|
2871
3128
|
return memoizedTables[tableName];
|
|
2872
3129
|
var tableSchema = this.schema[tableName];
|
|
2873
3130
|
if (!tableSchema) {
|
|
2874
|
-
throw new exceptions.NotFound(
|
|
3131
|
+
throw new exceptions.NotFound('Table ' + tableName + ' not part of transaction');
|
|
2875
3132
|
}
|
|
2876
3133
|
var transactionBoundTable = new this.db.Table(tableName, tableSchema, this);
|
|
2877
3134
|
transactionBoundTable.core = this.db.core.table(tableName);
|
|
@@ -2897,7 +3154,7 @@ function createTransactionConstructor(db) {
|
|
|
2897
3154
|
this.schema = dbschema;
|
|
2898
3155
|
this.chromeTransactionDurability = chromeTransactionDurability;
|
|
2899
3156
|
this.idbtrans = null;
|
|
2900
|
-
this.on = Events(this,
|
|
3157
|
+
this.on = Events(this, 'complete', 'error', 'abort');
|
|
2901
3158
|
this.parent = parent || null;
|
|
2902
3159
|
this.active = true;
|
|
2903
3160
|
this._reculock = 0;
|
|
@@ -2918,9 +3175,9 @@ function createTransactionConstructor(db) {
|
|
|
2918
3175
|
var wasActive = _this.active;
|
|
2919
3176
|
_this.active = false;
|
|
2920
3177
|
_this.on.error.fire(e);
|
|
2921
|
-
_this.parent
|
|
2922
|
-
_this.parent._reject(e)
|
|
2923
|
-
wasActive && _this.idbtrans && _this.idbtrans.abort();
|
|
3178
|
+
_this.parent
|
|
3179
|
+
? _this.parent._reject(e)
|
|
3180
|
+
: wasActive && _this.idbtrans && _this.idbtrans.abort();
|
|
2924
3181
|
return rejection(e);
|
|
2925
3182
|
});
|
|
2926
3183
|
});
|
|
@@ -2934,14 +3191,19 @@ function createIndexSpec(name, keyPath, unique, multi, auto, compound, isPrimKey
|
|
|
2934
3191
|
multi: multi,
|
|
2935
3192
|
auto: auto,
|
|
2936
3193
|
compound: compound,
|
|
2937
|
-
src: (unique && !isPrimKey ? '&' : '') +
|
|
2938
|
-
|
|
3194
|
+
src: (unique && !isPrimKey ? '&' : '') +
|
|
3195
|
+
(multi ? '*' : '') +
|
|
3196
|
+
(auto ? '++' : '') +
|
|
3197
|
+
nameFromKeyPath(keyPath),
|
|
3198
|
+
type: type,
|
|
2939
3199
|
};
|
|
2940
3200
|
}
|
|
2941
3201
|
function nameFromKeyPath(keyPath) {
|
|
2942
|
-
return typeof keyPath === 'string'
|
|
2943
|
-
keyPath
|
|
2944
|
-
|
|
3202
|
+
return typeof keyPath === 'string'
|
|
3203
|
+
? keyPath
|
|
3204
|
+
: keyPath
|
|
3205
|
+
? '[' + [].join.call(keyPath, '+') + ']'
|
|
3206
|
+
: '';
|
|
2945
3207
|
}
|
|
2946
3208
|
|
|
2947
3209
|
function createTableSchema(name, primKey, indexes) {
|
|
@@ -2995,22 +3257,22 @@ function arrayify(arrayLike) {
|
|
|
2995
3257
|
}
|
|
2996
3258
|
var _id_counter = 0;
|
|
2997
3259
|
function getKeyPathAlias(keyPath) {
|
|
2998
|
-
return keyPath == null
|
|
2999
|
-
|
|
3000
|
-
typeof keyPath === 'string'
|
|
3001
|
-
keyPath
|
|
3002
|
-
"[".concat(keyPath.join('+'), "]");
|
|
3260
|
+
return keyPath == null
|
|
3261
|
+
? ':id'
|
|
3262
|
+
: typeof keyPath === 'string'
|
|
3263
|
+
? keyPath
|
|
3264
|
+
: "[".concat(keyPath.join('+'), "]");
|
|
3003
3265
|
}
|
|
3004
3266
|
function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
3005
3267
|
function extractSchema(db, trans) {
|
|
3006
3268
|
var tables = arrayify(db.objectStoreNames);
|
|
3007
|
-
var tempStore = tables.length > 0
|
|
3008
|
-
? trans.objectStore(tables[0])
|
|
3009
|
-
: {};
|
|
3269
|
+
var tempStore = tables.length > 0 ? trans.objectStore(tables[0]) : {};
|
|
3010
3270
|
return {
|
|
3011
3271
|
schema: {
|
|
3012
3272
|
name: db.name,
|
|
3013
|
-
tables: tables
|
|
3273
|
+
tables: tables
|
|
3274
|
+
.map(function (table) { return trans.objectStore(table); })
|
|
3275
|
+
.map(function (store) {
|
|
3014
3276
|
var keyPath = store.keyPath, autoIncrement = store.autoIncrement;
|
|
3015
3277
|
var compound = isArray(keyPath);
|
|
3016
3278
|
var outbound = keyPath == null;
|
|
@@ -3025,9 +3287,10 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3025
3287
|
keyPath: keyPath,
|
|
3026
3288
|
autoIncrement: autoIncrement,
|
|
3027
3289
|
unique: true,
|
|
3028
|
-
extractKey: getKeyExtractor(keyPath)
|
|
3290
|
+
extractKey: getKeyExtractor(keyPath),
|
|
3029
3291
|
},
|
|
3030
|
-
indexes: arrayify(store.indexNames)
|
|
3292
|
+
indexes: arrayify(store.indexNames)
|
|
3293
|
+
.map(function (indexName) { return store.index(indexName); })
|
|
3031
3294
|
.map(function (index) {
|
|
3032
3295
|
var name = index.name, unique = index.unique, multiEntry = index.multiEntry, keyPath = index.keyPath;
|
|
3033
3296
|
var compound = isArray(keyPath);
|
|
@@ -3037,40 +3300,44 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3037
3300
|
keyPath: keyPath,
|
|
3038
3301
|
unique: unique,
|
|
3039
3302
|
multiEntry: multiEntry,
|
|
3040
|
-
extractKey: getKeyExtractor(keyPath)
|
|
3303
|
+
extractKey: getKeyExtractor(keyPath),
|
|
3041
3304
|
};
|
|
3042
3305
|
indexByKeyPath[getKeyPathAlias(keyPath)] = result;
|
|
3043
3306
|
return result;
|
|
3044
3307
|
}),
|
|
3045
|
-
getIndexByKeyPath: function (keyPath) {
|
|
3308
|
+
getIndexByKeyPath: function (keyPath) {
|
|
3309
|
+
return indexByKeyPath[getKeyPathAlias(keyPath)];
|
|
3310
|
+
},
|
|
3046
3311
|
};
|
|
3047
|
-
indexByKeyPath[
|
|
3312
|
+
indexByKeyPath[':id'] = result.primaryKey;
|
|
3048
3313
|
if (keyPath != null) {
|
|
3049
3314
|
indexByKeyPath[getKeyPathAlias(keyPath)] = result.primaryKey;
|
|
3050
3315
|
}
|
|
3051
3316
|
return result;
|
|
3052
|
-
})
|
|
3317
|
+
}),
|
|
3053
3318
|
},
|
|
3054
|
-
hasGetAll: tables.length > 0 &&
|
|
3055
|
-
|
|
3319
|
+
hasGetAll: tables.length > 0 &&
|
|
3320
|
+
'getAll' in tempStore &&
|
|
3321
|
+
!(typeof navigator !== 'undefined' &&
|
|
3322
|
+
/Safari/.test(navigator.userAgent) &&
|
|
3056
3323
|
!/(Chrome\/|Edge\/)/.test(navigator.userAgent) &&
|
|
3057
3324
|
[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604),
|
|
3058
|
-
hasIdb3Features: 'getAllRecords' in tempStore
|
|
3325
|
+
hasIdb3Features: 'getAllRecords' in tempStore,
|
|
3059
3326
|
};
|
|
3060
3327
|
}
|
|
3061
3328
|
function makeIDBKeyRange(range) {
|
|
3062
3329
|
if (range.type === 3 )
|
|
3063
3330
|
return null;
|
|
3064
3331
|
if (range.type === 4 )
|
|
3065
|
-
throw new Error(
|
|
3332
|
+
throw new Error('Cannot convert never type to IDBKeyRange');
|
|
3066
3333
|
var lower = range.lower, upper = range.upper, lowerOpen = range.lowerOpen, upperOpen = range.upperOpen;
|
|
3067
|
-
var idbRange = lower === undefined
|
|
3068
|
-
upper === undefined
|
|
3069
|
-
null
|
|
3070
|
-
IdbKeyRange.upperBound(upper, !!upperOpen)
|
|
3071
|
-
upper === undefined
|
|
3072
|
-
IdbKeyRange.lowerBound(lower, !!lowerOpen)
|
|
3073
|
-
IdbKeyRange.bound(lower, upper, !!lowerOpen, !!upperOpen);
|
|
3334
|
+
var idbRange = lower === undefined
|
|
3335
|
+
? upper === undefined
|
|
3336
|
+
? null
|
|
3337
|
+
: IdbKeyRange.upperBound(upper, !!upperOpen)
|
|
3338
|
+
: upper === undefined
|
|
3339
|
+
? IdbKeyRange.lowerBound(lower, !!lowerOpen)
|
|
3340
|
+
: IdbKeyRange.bound(lower, upper, !!lowerOpen, !!upperOpen);
|
|
3074
3341
|
return idbRange;
|
|
3075
3342
|
}
|
|
3076
3343
|
function createDbCoreTable(tableSchema) {
|
|
@@ -3081,15 +3348,20 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3081
3348
|
resolve = wrap(resolve);
|
|
3082
3349
|
var store = trans.objectStore(tableName);
|
|
3083
3350
|
var outbound = store.keyPath == null;
|
|
3084
|
-
var isAddOrPut = type ===
|
|
3351
|
+
var isAddOrPut = type === 'put' || type === 'add';
|
|
3085
3352
|
if (!isAddOrPut && type !== 'delete' && type !== 'deleteRange')
|
|
3086
|
-
throw new Error(
|
|
3353
|
+
throw new Error('Invalid operation type: ' + type);
|
|
3087
3354
|
var length = (keys || values || { length: 1 }).length;
|
|
3088
3355
|
if (keys && values && keys.length !== values.length) {
|
|
3089
|
-
throw new Error(
|
|
3356
|
+
throw new Error('Given keys array must have same length as given values array.');
|
|
3090
3357
|
}
|
|
3091
3358
|
if (length === 0)
|
|
3092
|
-
return resolve({
|
|
3359
|
+
return resolve({
|
|
3360
|
+
numFailures: 0,
|
|
3361
|
+
failures: {},
|
|
3362
|
+
results: [],
|
|
3363
|
+
lastResult: undefined,
|
|
3364
|
+
});
|
|
3093
3365
|
var req;
|
|
3094
3366
|
var reqs = [];
|
|
3095
3367
|
var failures = [];
|
|
@@ -3100,29 +3372,34 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3100
3372
|
};
|
|
3101
3373
|
if (type === 'deleteRange') {
|
|
3102
3374
|
if (range.type === 4 )
|
|
3103
|
-
return resolve({
|
|
3375
|
+
return resolve({
|
|
3376
|
+
numFailures: numFailures,
|
|
3377
|
+
failures: failures,
|
|
3378
|
+
results: [],
|
|
3379
|
+
lastResult: undefined,
|
|
3380
|
+
});
|
|
3104
3381
|
if (range.type === 3 )
|
|
3105
|
-
reqs.push(req = store.clear());
|
|
3382
|
+
reqs.push((req = store.clear()));
|
|
3106
3383
|
else
|
|
3107
|
-
reqs.push(req = store.delete(makeIDBKeyRange(range)));
|
|
3384
|
+
reqs.push((req = store.delete(makeIDBKeyRange(range))));
|
|
3108
3385
|
}
|
|
3109
3386
|
else {
|
|
3110
|
-
var _a = isAddOrPut
|
|
3111
|
-
outbound
|
|
3112
|
-
[values, keys]
|
|
3113
|
-
[values, null]
|
|
3114
|
-
[keys, null], args1 = _a[0], args2 = _a[1];
|
|
3387
|
+
var _a = isAddOrPut
|
|
3388
|
+
? outbound
|
|
3389
|
+
? [values, keys]
|
|
3390
|
+
: [values, null]
|
|
3391
|
+
: [keys, null], args1 = _a[0], args2 = _a[1];
|
|
3115
3392
|
if (isAddOrPut) {
|
|
3116
3393
|
for (var i = 0; i < length; ++i) {
|
|
3117
|
-
reqs.push(req = (args2 && args2[i] !== undefined
|
|
3118
|
-
store[type](args1[i], args2[i])
|
|
3119
|
-
store[type](args1[i])));
|
|
3394
|
+
reqs.push((req = (args2 && args2[i] !== undefined
|
|
3395
|
+
? store[type](args1[i], args2[i])
|
|
3396
|
+
: store[type](args1[i]))));
|
|
3120
3397
|
req.onerror = errorHandler;
|
|
3121
3398
|
}
|
|
3122
3399
|
}
|
|
3123
3400
|
else {
|
|
3124
3401
|
for (var i = 0; i < length; ++i) {
|
|
3125
|
-
reqs.push(req = store[type](args1[i]));
|
|
3402
|
+
reqs.push((req = store[type](args1[i])));
|
|
3126
3403
|
req.onerror = errorHandler;
|
|
3127
3404
|
}
|
|
3128
3405
|
}
|
|
@@ -3133,8 +3410,8 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3133
3410
|
resolve({
|
|
3134
3411
|
numFailures: numFailures,
|
|
3135
3412
|
failures: failures,
|
|
3136
|
-
results: type ===
|
|
3137
|
-
lastResult: lastResult
|
|
3413
|
+
results: type === 'delete' ? keys : reqs.map(function (req) { return req.result; }),
|
|
3414
|
+
lastResult: lastResult,
|
|
3138
3415
|
});
|
|
3139
3416
|
};
|
|
3140
3417
|
req.onerror = function (event) {
|
|
@@ -3150,19 +3427,17 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3150
3427
|
resolve = wrap(resolve);
|
|
3151
3428
|
var index = query.index, range = query.range;
|
|
3152
3429
|
var store = trans.objectStore(tableName);
|
|
3153
|
-
var source = index.isPrimaryKey ?
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
source.openCursor(makeIDBKeyRange(range), direction) :
|
|
3165
|
-
source.openKeyCursor(makeIDBKeyRange(range), direction);
|
|
3430
|
+
var source = index.isPrimaryKey ? store : store.index(index.name);
|
|
3431
|
+
var direction = reverse
|
|
3432
|
+
? unique
|
|
3433
|
+
? 'prevunique'
|
|
3434
|
+
: 'prev'
|
|
3435
|
+
: unique
|
|
3436
|
+
? 'nextunique'
|
|
3437
|
+
: 'next';
|
|
3438
|
+
var req = values || !('openKeyCursor' in source)
|
|
3439
|
+
? source.openCursor(makeIDBKeyRange(range), direction)
|
|
3440
|
+
: source.openKeyCursor(makeIDBKeyRange(range), direction);
|
|
3166
3441
|
req.onerror = eventRejectHandler(reject);
|
|
3167
3442
|
req.onsuccess = wrap(function (ev) {
|
|
3168
3443
|
var cursor = req.result;
|
|
@@ -3177,15 +3452,25 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3177
3452
|
if (_cursorContinuePrimaryKey)
|
|
3178
3453
|
_cursorContinuePrimaryKey = _cursorContinuePrimaryKey.bind(cursor);
|
|
3179
3454
|
var _cursorAdvance = cursor.advance.bind(cursor);
|
|
3180
|
-
var doThrowCursorIsNotStarted = function () {
|
|
3181
|
-
|
|
3455
|
+
var doThrowCursorIsNotStarted = function () {
|
|
3456
|
+
throw new Error('Cursor not started');
|
|
3457
|
+
};
|
|
3458
|
+
var doThrowCursorIsStopped = function () {
|
|
3459
|
+
throw new Error('Cursor not stopped');
|
|
3460
|
+
};
|
|
3182
3461
|
cursor.trans = trans;
|
|
3183
|
-
cursor.stop =
|
|
3462
|
+
cursor.stop =
|
|
3463
|
+
cursor.continue =
|
|
3464
|
+
cursor.continuePrimaryKey =
|
|
3465
|
+
cursor.advance =
|
|
3466
|
+
doThrowCursorIsNotStarted;
|
|
3184
3467
|
cursor.fail = wrap(reject);
|
|
3185
3468
|
cursor.next = function () {
|
|
3186
3469
|
var _this = this;
|
|
3187
3470
|
var gotOne = 1;
|
|
3188
|
-
return this.start(function () {
|
|
3471
|
+
return this.start(function () {
|
|
3472
|
+
return gotOne-- ? _this.continue() : _this.stop();
|
|
3473
|
+
}).then(function () { return _this; });
|
|
3189
3474
|
};
|
|
3190
3475
|
cursor.start = function (callback) {
|
|
3191
3476
|
var iterationPromise = new Promise(function (resolveIteration, rejectIteration) {
|
|
@@ -3193,7 +3478,11 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3193
3478
|
req.onerror = eventRejectHandler(rejectIteration);
|
|
3194
3479
|
cursor.fail = rejectIteration;
|
|
3195
3480
|
cursor.stop = function (value) {
|
|
3196
|
-
cursor.stop =
|
|
3481
|
+
cursor.stop =
|
|
3482
|
+
cursor.continue =
|
|
3483
|
+
cursor.continuePrimaryKey =
|
|
3484
|
+
cursor.advance =
|
|
3485
|
+
doThrowCursorIsStopped;
|
|
3197
3486
|
resolveIteration(value);
|
|
3198
3487
|
};
|
|
3199
3488
|
});
|
|
@@ -3208,7 +3497,9 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3208
3497
|
}
|
|
3209
3498
|
else {
|
|
3210
3499
|
cursor.done = true;
|
|
3211
|
-
cursor.start = function () {
|
|
3500
|
+
cursor.start = function () {
|
|
3501
|
+
throw new Error('Cursor behind last entry');
|
|
3502
|
+
};
|
|
3212
3503
|
cursor.stop();
|
|
3213
3504
|
}
|
|
3214
3505
|
};
|
|
@@ -3244,26 +3535,28 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3244
3535
|
var options = {
|
|
3245
3536
|
query: idbKeyRange,
|
|
3246
3537
|
count: nonInfinitLimit,
|
|
3247
|
-
direction: direction
|
|
3538
|
+
direction: direction,
|
|
3248
3539
|
};
|
|
3249
|
-
var req = values
|
|
3250
|
-
source.getAll(options)
|
|
3251
|
-
source.getAllKeys(options);
|
|
3540
|
+
var req = values
|
|
3541
|
+
? source.getAll(options)
|
|
3542
|
+
: source.getAllKeys(options);
|
|
3252
3543
|
req.onsuccess = function (event) { return resolve({ result: event.target.result }); };
|
|
3253
3544
|
req.onerror = eventRejectHandler(reject);
|
|
3254
3545
|
}
|
|
3255
3546
|
else if (hasGetAll && direction === 'next') {
|
|
3256
|
-
var req = values
|
|
3257
|
-
source.getAll(idbKeyRange, nonInfinitLimit)
|
|
3258
|
-
source.getAllKeys(idbKeyRange, nonInfinitLimit);
|
|
3259
|
-
req.onsuccess = function (event) {
|
|
3547
|
+
var req = values
|
|
3548
|
+
? source.getAll(idbKeyRange, nonInfinitLimit)
|
|
3549
|
+
: source.getAllKeys(idbKeyRange, nonInfinitLimit);
|
|
3550
|
+
req.onsuccess = function (event) {
|
|
3551
|
+
return resolve({ result: event.target.result });
|
|
3552
|
+
};
|
|
3260
3553
|
req.onerror = eventRejectHandler(reject);
|
|
3261
3554
|
}
|
|
3262
3555
|
else {
|
|
3263
3556
|
var count_1 = 0;
|
|
3264
|
-
var req_1 = values || !('openKeyCursor' in source)
|
|
3265
|
-
source.openCursor(idbKeyRange, direction)
|
|
3266
|
-
source.openKeyCursor(idbKeyRange, direction);
|
|
3557
|
+
var req_1 = values || !('openKeyCursor' in source)
|
|
3558
|
+
? source.openCursor(idbKeyRange, direction)
|
|
3559
|
+
: source.openKeyCursor(idbKeyRange, direction);
|
|
3267
3560
|
var result_1 = [];
|
|
3268
3561
|
req_1.onsuccess = function () {
|
|
3269
3562
|
var cursor = req_1.result;
|
|
@@ -3335,18 +3628,22 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3335
3628
|
var source = index.isPrimaryKey ? store : store.index(index.name);
|
|
3336
3629
|
var idbKeyRange = makeIDBKeyRange(range);
|
|
3337
3630
|
var req = idbKeyRange ? source.count(idbKeyRange) : source.count();
|
|
3338
|
-
req.onsuccess = wrap(function (ev) {
|
|
3631
|
+
req.onsuccess = wrap(function (ev) {
|
|
3632
|
+
return resolve(ev.target.result);
|
|
3633
|
+
});
|
|
3339
3634
|
req.onerror = eventRejectHandler(reject);
|
|
3340
3635
|
});
|
|
3341
|
-
}
|
|
3636
|
+
},
|
|
3342
3637
|
};
|
|
3343
3638
|
}
|
|
3344
3639
|
var _a = extractSchema(db, tmpTrans), schema = _a.schema, hasGetAll = _a.hasGetAll, hasIdb3Features = _a.hasIdb3Features;
|
|
3345
|
-
var tables = schema.tables.map(function (tableSchema) {
|
|
3640
|
+
var tables = schema.tables.map(function (tableSchema) {
|
|
3641
|
+
return createDbCoreTable(tableSchema);
|
|
3642
|
+
});
|
|
3346
3643
|
var tableMap = {};
|
|
3347
|
-
tables.forEach(function (table) { return tableMap[table.name] = table; });
|
|
3644
|
+
tables.forEach(function (table) { return (tableMap[table.name] = table); });
|
|
3348
3645
|
return {
|
|
3349
|
-
stack:
|
|
3646
|
+
stack: 'dbcore',
|
|
3350
3647
|
transaction: db.transaction.bind(db),
|
|
3351
3648
|
table: function (name) {
|
|
3352
3649
|
var result = tableMap[name];
|
|
@@ -3356,7 +3653,7 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3356
3653
|
},
|
|
3357
3654
|
MIN_KEY: -Infinity,
|
|
3358
3655
|
MAX_KEY: getMaxKey(IdbKeyRange),
|
|
3359
|
-
schema: schema
|
|
3656
|
+
schema: schema,
|
|
3360
3657
|
};
|
|
3361
3658
|
}
|
|
3362
3659
|
|
|
@@ -3370,7 +3667,7 @@ function createMiddlewareStacks(middlewares, idbdb, _a, tmpTrans) {
|
|
|
3370
3667
|
var IDBKeyRange = _a.IDBKeyRange; _a.indexedDB;
|
|
3371
3668
|
var dbcore = createMiddlewareStack(createDBCore(idbdb, IDBKeyRange, tmpTrans), middlewares.dbcore);
|
|
3372
3669
|
return {
|
|
3373
|
-
dbcore: dbcore
|
|
3670
|
+
dbcore: dbcore,
|
|
3374
3671
|
};
|
|
3375
3672
|
}
|
|
3376
3673
|
function generateMiddlewareStacks(db, tmpTrans) {
|
|
@@ -3393,13 +3690,20 @@ function setApiOnPlace(db, objs, tableNames, dbschema) {
|
|
|
3393
3690
|
var schema = dbschema[tableName];
|
|
3394
3691
|
objs.forEach(function (obj) {
|
|
3395
3692
|
var propDesc = getPropertyDescriptor(obj, tableName);
|
|
3396
|
-
if (!propDesc || (
|
|
3693
|
+
if (!propDesc || ('value' in propDesc && propDesc.value === undefined)) {
|
|
3397
3694
|
if (obj === db.Transaction.prototype || obj instanceof db.Transaction) {
|
|
3398
3695
|
setProp(obj, tableName, {
|
|
3399
|
-
get: function () {
|
|
3696
|
+
get: function () {
|
|
3697
|
+
return this.table(tableName);
|
|
3698
|
+
},
|
|
3400
3699
|
set: function (value) {
|
|
3401
|
-
defineProperty(this, tableName, {
|
|
3402
|
-
|
|
3700
|
+
defineProperty(this, tableName, {
|
|
3701
|
+
value: value,
|
|
3702
|
+
writable: true,
|
|
3703
|
+
configurable: true,
|
|
3704
|
+
enumerable: true,
|
|
3705
|
+
});
|
|
3706
|
+
},
|
|
3403
3707
|
});
|
|
3404
3708
|
}
|
|
3405
3709
|
else {
|
|
@@ -3422,8 +3726,9 @@ function lowerVersionFirst(a, b) {
|
|
|
3422
3726
|
}
|
|
3423
3727
|
function runUpgraders(db, oldVersion, idbUpgradeTrans, reject) {
|
|
3424
3728
|
var globalSchema = db._dbSchema;
|
|
3425
|
-
if (idbUpgradeTrans.objectStoreNames.contains('$meta') &&
|
|
3426
|
-
globalSchema.$meta
|
|
3729
|
+
if (idbUpgradeTrans.objectStoreNames.contains('$meta') &&
|
|
3730
|
+
!globalSchema.$meta) {
|
|
3731
|
+
globalSchema.$meta = createTableSchema('$meta', parseIndexSyntax('')[0], []);
|
|
3427
3732
|
db._storeNames.push('$meta');
|
|
3428
3733
|
}
|
|
3429
3734
|
var trans = db._createTransaction('readwrite', db._storeNames, globalSchema);
|
|
@@ -3444,15 +3749,20 @@ function runUpgraders(db, oldVersion, idbUpgradeTrans, reject) {
|
|
|
3444
3749
|
else {
|
|
3445
3750
|
generateMiddlewareStacks(db, idbUpgradeTrans);
|
|
3446
3751
|
return getExistingVersion(db, trans, oldVersion)
|
|
3447
|
-
.then(function (oldVersion) {
|
|
3752
|
+
.then(function (oldVersion) {
|
|
3753
|
+
return updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans);
|
|
3754
|
+
})
|
|
3448
3755
|
.catch(rejectTransaction);
|
|
3449
3756
|
}
|
|
3450
3757
|
});
|
|
3451
3758
|
}
|
|
3452
3759
|
function patchCurrentVersion(db, idbUpgradeTrans) {
|
|
3453
3760
|
createMissingTables(db._dbSchema, idbUpgradeTrans);
|
|
3454
|
-
if (idbUpgradeTrans.db.version % 10 === 0 &&
|
|
3455
|
-
idbUpgradeTrans.
|
|
3761
|
+
if (idbUpgradeTrans.db.version % 10 === 0 &&
|
|
3762
|
+
!idbUpgradeTrans.objectStoreNames.contains('$meta')) {
|
|
3763
|
+
idbUpgradeTrans.db
|
|
3764
|
+
.createObjectStore('$meta')
|
|
3765
|
+
.add(Math.ceil(idbUpgradeTrans.db.version / 10 - 1), 'version');
|
|
3456
3766
|
}
|
|
3457
3767
|
var globalSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
|
|
3458
3768
|
adjustToExistingIndexNames(db, db._dbSchema, idbUpgradeTrans);
|
|
@@ -3478,7 +3788,10 @@ function patchCurrentVersion(db, idbUpgradeTrans) {
|
|
|
3478
3788
|
}
|
|
3479
3789
|
function getExistingVersion(db, trans, oldVersion) {
|
|
3480
3790
|
if (trans.storeNames.includes('$meta')) {
|
|
3481
|
-
return trans
|
|
3791
|
+
return trans
|
|
3792
|
+
.table('$meta')
|
|
3793
|
+
.get('version')
|
|
3794
|
+
.then(function (metaVersion) {
|
|
3482
3795
|
return metaVersion != null ? metaVersion : oldVersion;
|
|
3483
3796
|
});
|
|
3484
3797
|
}
|
|
@@ -3489,7 +3802,7 @@ function getExistingVersion(db, trans, oldVersion) {
|
|
|
3489
3802
|
function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
|
|
3490
3803
|
var queue = [];
|
|
3491
3804
|
var versions = db._versions;
|
|
3492
|
-
var globalSchema = db._dbSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
|
|
3805
|
+
var globalSchema = (db._dbSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans));
|
|
3493
3806
|
var versToRun = versions.filter(function (v) { return v._cfg.version >= oldVersion; });
|
|
3494
3807
|
if (versToRun.length === 0) {
|
|
3495
3808
|
return DexiePromise.resolve();
|
|
@@ -3507,7 +3820,7 @@ function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
|
|
|
3507
3820
|
});
|
|
3508
3821
|
diff.change.forEach(function (change) {
|
|
3509
3822
|
if (change.recreate) {
|
|
3510
|
-
throw new exceptions.Upgrade(
|
|
3823
|
+
throw new exceptions.Upgrade('Not yet support for changing primary key');
|
|
3511
3824
|
}
|
|
3512
3825
|
else {
|
|
3513
3826
|
var store_1 = idbUpgradeTrans.objectStore(change.name);
|
|
@@ -3544,8 +3857,9 @@ function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
|
|
|
3544
3857
|
}
|
|
3545
3858
|
}
|
|
3546
3859
|
});
|
|
3547
|
-
return
|
|
3548
|
-
DexiePromise.resolve(returnValue_1)
|
|
3860
|
+
return returnValue_1 && typeof returnValue_1.then === 'function'
|
|
3861
|
+
? DexiePromise.resolve(returnValue_1)
|
|
3862
|
+
: promiseFollowed.then(function () { return returnValue_1; });
|
|
3549
3863
|
}
|
|
3550
3864
|
});
|
|
3551
3865
|
queue.push(function (idbtrans) {
|
|
@@ -3569,8 +3883,9 @@ function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
|
|
|
3569
3883
|
});
|
|
3570
3884
|
});
|
|
3571
3885
|
function runQueue() {
|
|
3572
|
-
return queue.length
|
|
3573
|
-
DexiePromise.resolve()
|
|
3886
|
+
return queue.length
|
|
3887
|
+
? DexiePromise.resolve(queue.shift()(trans.idbtrans)).then(runQueue)
|
|
3888
|
+
: DexiePromise.resolve();
|
|
3574
3889
|
}
|
|
3575
3890
|
return runQueue().then(function () {
|
|
3576
3891
|
createMissingTables(globalSchema, idbUpgradeTrans);
|
|
@@ -3580,7 +3895,7 @@ function getSchemaDiff(oldSchema, newSchema) {
|
|
|
3580
3895
|
var diff = {
|
|
3581
3896
|
del: [],
|
|
3582
3897
|
add: [],
|
|
3583
|
-
change: []
|
|
3898
|
+
change: [],
|
|
3584
3899
|
};
|
|
3585
3900
|
var table;
|
|
3586
3901
|
for (table in oldSchema) {
|
|
@@ -3599,11 +3914,12 @@ function getSchemaDiff(oldSchema, newSchema) {
|
|
|
3599
3914
|
recreate: false,
|
|
3600
3915
|
del: [],
|
|
3601
3916
|
add: [],
|
|
3602
|
-
change: []
|
|
3917
|
+
change: [],
|
|
3603
3918
|
};
|
|
3604
|
-
if (
|
|
3605
|
-
'' + (oldDef.primKey.keyPath || '')
|
|
3606
|
-
(
|
|
3919
|
+
if (
|
|
3920
|
+
'' + (oldDef.primKey.keyPath || '') !==
|
|
3921
|
+
'' + (newDef.primKey.keyPath || '') ||
|
|
3922
|
+
oldDef.primKey.auto !== newDef.primKey.auto) {
|
|
3607
3923
|
change.recreate = true;
|
|
3608
3924
|
diff.change.push(change);
|
|
3609
3925
|
}
|
|
@@ -3622,7 +3938,9 @@ function getSchemaDiff(oldSchema, newSchema) {
|
|
|
3622
3938
|
else if (oldIdx.src !== newIdx.src)
|
|
3623
3939
|
change.change.push(newIdx);
|
|
3624
3940
|
}
|
|
3625
|
-
if (change.del.length > 0 ||
|
|
3941
|
+
if (change.del.length > 0 ||
|
|
3942
|
+
change.add.length > 0 ||
|
|
3943
|
+
change.change.length > 0) {
|
|
3626
3944
|
diff.change.push(change);
|
|
3627
3945
|
}
|
|
3628
3946
|
}
|
|
@@ -3631,9 +3949,9 @@ function getSchemaDiff(oldSchema, newSchema) {
|
|
|
3631
3949
|
return diff;
|
|
3632
3950
|
}
|
|
3633
3951
|
function createTable(idbtrans, tableName, primKey, indexes) {
|
|
3634
|
-
var store = idbtrans.db.createObjectStore(tableName, primKey.keyPath
|
|
3635
|
-
{ keyPath: primKey.keyPath, autoIncrement: primKey.auto }
|
|
3636
|
-
{ autoIncrement: primKey.auto });
|
|
3952
|
+
var store = idbtrans.db.createObjectStore(tableName, primKey.keyPath
|
|
3953
|
+
? { keyPath: primKey.keyPath, autoIncrement: primKey.auto }
|
|
3954
|
+
: { autoIncrement: primKey.auto });
|
|
3637
3955
|
indexes.forEach(function (idx) { return addIndex(store, idx); });
|
|
3638
3956
|
return store;
|
|
3639
3957
|
}
|
|
@@ -3647,12 +3965,17 @@ function createMissingTables(newSchema, idbtrans) {
|
|
|
3647
3965
|
});
|
|
3648
3966
|
}
|
|
3649
3967
|
function deleteRemovedTables(newSchema, idbtrans) {
|
|
3650
|
-
[].slice
|
|
3968
|
+
[].slice
|
|
3969
|
+
.call(idbtrans.db.objectStoreNames)
|
|
3970
|
+
.forEach(function (storeName) {
|
|
3651
3971
|
return newSchema[storeName] == null && idbtrans.db.deleteObjectStore(storeName);
|
|
3652
3972
|
});
|
|
3653
3973
|
}
|
|
3654
3974
|
function addIndex(store, idx) {
|
|
3655
|
-
store.createIndex(idx.name, idx.keyPath, {
|
|
3975
|
+
store.createIndex(idx.name, idx.keyPath, {
|
|
3976
|
+
unique: idx.unique,
|
|
3977
|
+
multiEntry: idx.multi,
|
|
3978
|
+
});
|
|
3656
3979
|
}
|
|
3657
3980
|
function buildGlobalSchema(db, idbdb, tmpTrans) {
|
|
3658
3981
|
var globalSchema = {};
|
|
@@ -3660,12 +3983,12 @@ function buildGlobalSchema(db, idbdb, tmpTrans) {
|
|
|
3660
3983
|
dbStoreNames.forEach(function (storeName) {
|
|
3661
3984
|
var store = tmpTrans.objectStore(storeName);
|
|
3662
3985
|
var keyPath = store.keyPath;
|
|
3663
|
-
var primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath ||
|
|
3986
|
+
var primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath || '', true, false, !!store.autoIncrement, keyPath && typeof keyPath !== 'string', true);
|
|
3664
3987
|
var indexes = [];
|
|
3665
3988
|
for (var j = 0; j < store.indexNames.length; ++j) {
|
|
3666
3989
|
var idbindex = store.index(store.indexNames[j]);
|
|
3667
3990
|
keyPath = idbindex.keyPath;
|
|
3668
|
-
var index = createIndexSpec(idbindex.name, keyPath, !!idbindex.unique, !!idbindex.multiEntry, false, keyPath && typeof keyPath !==
|
|
3991
|
+
var index = createIndexSpec(idbindex.name, keyPath, !!idbindex.unique, !!idbindex.multiEntry, false, keyPath && typeof keyPath !== 'string', false);
|
|
3669
3992
|
indexes.push(index);
|
|
3670
3993
|
}
|
|
3671
3994
|
globalSchema[storeName] = createTableSchema(storeName, primKey, indexes);
|
|
@@ -3674,14 +3997,15 @@ function buildGlobalSchema(db, idbdb, tmpTrans) {
|
|
|
3674
3997
|
}
|
|
3675
3998
|
function readGlobalSchema(db, idbdb, tmpTrans) {
|
|
3676
3999
|
db.verno = idbdb.version / 10;
|
|
3677
|
-
var globalSchema = db._dbSchema = buildGlobalSchema(db, idbdb, tmpTrans);
|
|
4000
|
+
var globalSchema = (db._dbSchema = buildGlobalSchema(db, idbdb, tmpTrans));
|
|
3678
4001
|
db._storeNames = slice(idbdb.objectStoreNames, 0);
|
|
3679
4002
|
setApiOnPlace(db, [db._allTables], keys(globalSchema), globalSchema);
|
|
3680
4003
|
}
|
|
3681
4004
|
function verifyInstalledSchema(db, tmpTrans) {
|
|
3682
4005
|
var installedSchema = buildGlobalSchema(db, db.idbdb, tmpTrans);
|
|
3683
4006
|
var diff = getSchemaDiff(installedSchema, db._dbSchema);
|
|
3684
|
-
return !(diff.add.length ||
|
|
4007
|
+
return !(diff.add.length ||
|
|
4008
|
+
diff.change.some(function (ch) { return ch.add.length || ch.change.length; }));
|
|
3685
4009
|
}
|
|
3686
4010
|
function adjustToExistingIndexNames(db, schema, idbtrans) {
|
|
3687
4011
|
var storeNames = idbtrans.db.objectStoreNames;
|
|
@@ -3692,7 +4016,9 @@ function adjustToExistingIndexNames(db, schema, idbtrans) {
|
|
|
3692
4016
|
for (var j = 0; j < store.indexNames.length; ++j) {
|
|
3693
4017
|
var indexName = store.indexNames[j];
|
|
3694
4018
|
var keyPath = store.index(indexName).keyPath;
|
|
3695
|
-
var dexieName = typeof keyPath === 'string'
|
|
4019
|
+
var dexieName = typeof keyPath === 'string'
|
|
4020
|
+
? keyPath
|
|
4021
|
+
: '[' + slice(keyPath).join('+') + ']';
|
|
3696
4022
|
if (schema[storeName]) {
|
|
3697
4023
|
var indexSpec = schema[storeName].idxByName[dexieName];
|
|
3698
4024
|
if (indexSpec) {
|
|
@@ -3703,9 +4029,11 @@ function adjustToExistingIndexNames(db, schema, idbtrans) {
|
|
|
3703
4029
|
}
|
|
3704
4030
|
}
|
|
3705
4031
|
}
|
|
3706
|
-
if (typeof navigator !== 'undefined' &&
|
|
4032
|
+
if (typeof navigator !== 'undefined' &&
|
|
4033
|
+
/Safari/.test(navigator.userAgent) &&
|
|
3707
4034
|
!/(Chrome\/|Edge\/)/.test(navigator.userAgent) &&
|
|
3708
|
-
_global.WorkerGlobalScope &&
|
|
4035
|
+
_global.WorkerGlobalScope &&
|
|
4036
|
+
_global instanceof _global.WorkerGlobalScope &&
|
|
3709
4037
|
[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604) {
|
|
3710
4038
|
db._hasGetAll = false;
|
|
3711
4039
|
}
|
|
@@ -3716,8 +4044,10 @@ function parseIndexSyntax(primKeyAndIndexes) {
|
|
|
3716
4044
|
var typeSplit = index.split(':');
|
|
3717
4045
|
var type = (_a = typeSplit[1]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
3718
4046
|
index = typeSplit[0].trim();
|
|
3719
|
-
var name = index.replace(/([&*]|\+\+)/g,
|
|
3720
|
-
var keyPath = /^\[/.test(name)
|
|
4047
|
+
var name = index.replace(/([&*]|\+\+)/g, '');
|
|
4048
|
+
var keyPath = /^\[/.test(name)
|
|
4049
|
+
? name.match(/^\[(.*)\]$/)[1].split('+')
|
|
4050
|
+
: name;
|
|
3721
4051
|
return createIndexSpec(name, keyPath || null, /\&/.test(index), /\*/.test(index), /\+\+/.test(index), isArray(keyPath), indexNum === 0, type);
|
|
3722
4052
|
});
|
|
3723
4053
|
}
|
|
@@ -3788,14 +4118,15 @@ function createVersionConstructor(db) {
|
|
|
3788
4118
|
storesSource: null,
|
|
3789
4119
|
dbschema: {},
|
|
3790
4120
|
tables: {},
|
|
3791
|
-
contentUpgrade: null
|
|
4121
|
+
contentUpgrade: null,
|
|
3792
4122
|
};
|
|
3793
4123
|
});
|
|
3794
4124
|
}
|
|
3795
4125
|
|
|
3796
4126
|
var connections = createConnectionsManager();
|
|
3797
4127
|
function createConnectionsManager() {
|
|
3798
|
-
if (typeof FinalizationRegistry !== 'undefined' &&
|
|
4128
|
+
if (typeof FinalizationRegistry !== 'undefined' &&
|
|
4129
|
+
typeof WeakRef !== 'undefined') {
|
|
3799
4130
|
var _refs_1 = new Set();
|
|
3800
4131
|
var _registry_1 = new FinalizationRegistry(function (ref) {
|
|
3801
4132
|
_refs_1.delete(ref);
|
|
@@ -3851,19 +4182,19 @@ function createConnectionsManager() {
|
|
|
3851
4182
|
}
|
|
3852
4183
|
|
|
3853
4184
|
function getDbNamesTable(indexedDB, IDBKeyRange) {
|
|
3854
|
-
var dbNamesDB = indexedDB[
|
|
4185
|
+
var dbNamesDB = indexedDB['_dbNamesDB'];
|
|
3855
4186
|
if (!dbNamesDB) {
|
|
3856
|
-
dbNamesDB = indexedDB[
|
|
4187
|
+
dbNamesDB = indexedDB['_dbNamesDB'] = new Dexie$1(DBNAMES_DB, {
|
|
3857
4188
|
addons: [],
|
|
3858
4189
|
indexedDB: indexedDB,
|
|
3859
4190
|
IDBKeyRange: IDBKeyRange,
|
|
3860
4191
|
});
|
|
3861
|
-
dbNamesDB.version(1).stores({ dbnames:
|
|
4192
|
+
dbNamesDB.version(1).stores({ dbnames: 'name' });
|
|
3862
4193
|
}
|
|
3863
|
-
return dbNamesDB.table(
|
|
4194
|
+
return dbNamesDB.table('dbnames');
|
|
3864
4195
|
}
|
|
3865
4196
|
function hasDatabasesNative(indexedDB) {
|
|
3866
|
-
return indexedDB && typeof indexedDB.databases ===
|
|
4197
|
+
return indexedDB && typeof indexedDB.databases === 'function';
|
|
3867
4198
|
}
|
|
3868
4199
|
function getDatabaseNames(_a) {
|
|
3869
4200
|
var indexedDB = _a.indexedDB, IDBKeyRange = _a.IDBKeyRange;
|
|
@@ -3911,15 +4242,17 @@ function idbReady() {
|
|
|
3911
4242
|
|
|
3912
4243
|
var _a;
|
|
3913
4244
|
function isEmptyRange(node) {
|
|
3914
|
-
return !(
|
|
4245
|
+
return !('from' in node);
|
|
3915
4246
|
}
|
|
3916
4247
|
var RangeSet = function (fromOrTree, to) {
|
|
3917
4248
|
if (this) {
|
|
3918
|
-
extend(this, arguments.length
|
|
4249
|
+
extend(this, arguments.length
|
|
4250
|
+
? { d: 1, from: fromOrTree, to: arguments.length > 1 ? to : fromOrTree }
|
|
4251
|
+
: { d: 0 });
|
|
3919
4252
|
}
|
|
3920
4253
|
else {
|
|
3921
4254
|
var rv = new RangeSet();
|
|
3922
|
-
if (fromOrTree &&
|
|
4255
|
+
if (fromOrTree && 'd' in fromOrTree) {
|
|
3923
4256
|
extend(rv, fromOrTree);
|
|
3924
4257
|
}
|
|
3925
4258
|
return rv;
|
|
@@ -4019,7 +4352,9 @@ function rangesOverlap(rangeSet1, rangeSet2) {
|
|
|
4019
4352
|
return false;
|
|
4020
4353
|
}
|
|
4021
4354
|
function getRangeSetIterator(node) {
|
|
4022
|
-
var state = isEmptyRange(node)
|
|
4355
|
+
var state = isEmptyRange(node)
|
|
4356
|
+
? null
|
|
4357
|
+
: { s: 0, n: node };
|
|
4023
4358
|
return {
|
|
4024
4359
|
next: function (key) {
|
|
4025
4360
|
var keyProvided = arguments.length > 0;
|
|
@@ -4056,9 +4391,9 @@ function getRangeSetIterator(node) {
|
|
|
4056
4391
|
function rebalance(target) {
|
|
4057
4392
|
var _a, _b;
|
|
4058
4393
|
var diff = (((_a = target.r) === null || _a === void 0 ? void 0 : _a.d) || 0) - (((_b = target.l) === null || _b === void 0 ? void 0 : _b.d) || 0);
|
|
4059
|
-
var r = diff > 1 ?
|
|
4394
|
+
var r = diff > 1 ? 'r' : diff < -1 ? 'l' : '';
|
|
4060
4395
|
if (r) {
|
|
4061
|
-
var l = r ===
|
|
4396
|
+
var l = r === 'r' ? 'l' : 'r';
|
|
4062
4397
|
var rootClone = __assign({}, target);
|
|
4063
4398
|
var oldRootRight = target[r];
|
|
4064
4399
|
target.from = oldRootRight.from;
|
|
@@ -4086,7 +4421,9 @@ function extendObservabilitySet(target, newSet) {
|
|
|
4086
4421
|
}
|
|
4087
4422
|
|
|
4088
4423
|
function obsSetsOverlap(os1, os2) {
|
|
4089
|
-
return os1.all ||
|
|
4424
|
+
return (os1.all ||
|
|
4425
|
+
os2.all ||
|
|
4426
|
+
Object.keys(os1).some(function (key) { return os2[key] && rangesOverlap(os2[key], os1[key]); }));
|
|
4090
4427
|
}
|
|
4091
4428
|
|
|
4092
4429
|
var cache = {};
|
|
@@ -4156,9 +4493,9 @@ function dexieOpen(db) {
|
|
|
4156
4493
|
var state = db._state;
|
|
4157
4494
|
var indexedDB = db._deps.indexedDB;
|
|
4158
4495
|
if (state.isBeingOpened || db.idbdb)
|
|
4159
|
-
return state.dbReadyPromise.then(function () {
|
|
4160
|
-
rejection(state.dbOpenError) :
|
|
4161
|
-
|
|
4496
|
+
return state.dbReadyPromise.then(function () {
|
|
4497
|
+
return state.dbOpenError ? rejection(state.dbOpenError) : db;
|
|
4498
|
+
});
|
|
4162
4499
|
state.isBeingOpened = true;
|
|
4163
4500
|
state.dbOpenError = null;
|
|
4164
4501
|
state.openComplete = false;
|
|
@@ -4171,97 +4508,102 @@ function dexieOpen(db) {
|
|
|
4171
4508
|
}
|
|
4172
4509
|
var resolveDbReady = state.dbReadyResolve,
|
|
4173
4510
|
upgradeTransaction = null, wasCreated = false;
|
|
4174
|
-
var tryOpenDB = function () {
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
else {
|
|
4198
|
-
upgradeTransaction.onerror = eventRejectHandler(reject);
|
|
4199
|
-
var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion;
|
|
4200
|
-
wasCreated = oldVer < 1;
|
|
4201
|
-
db.idbdb = req.result;
|
|
4202
|
-
if (schemaPatchMode) {
|
|
4203
|
-
patchCurrentVersion(db, upgradeTransaction);
|
|
4511
|
+
var tryOpenDB = function () {
|
|
4512
|
+
return new DexiePromise(function (resolve, reject) {
|
|
4513
|
+
throwIfCancelled();
|
|
4514
|
+
if (!indexedDB)
|
|
4515
|
+
throw new exceptions.MissingAPI();
|
|
4516
|
+
var dbName = db.name;
|
|
4517
|
+
var req = state.autoSchema || !nativeVerToOpen
|
|
4518
|
+
? indexedDB.open(dbName)
|
|
4519
|
+
: indexedDB.open(dbName, nativeVerToOpen);
|
|
4520
|
+
if (!req)
|
|
4521
|
+
throw new exceptions.MissingAPI();
|
|
4522
|
+
req.onerror = eventRejectHandler(reject);
|
|
4523
|
+
req.onblocked = wrap(db._fireOnBlocked);
|
|
4524
|
+
req.onupgradeneeded = wrap(function (e) {
|
|
4525
|
+
upgradeTransaction = req.transaction;
|
|
4526
|
+
if (state.autoSchema && !db._options.allowEmptyDB) {
|
|
4527
|
+
req.onerror = preventDefault;
|
|
4528
|
+
upgradeTransaction.abort();
|
|
4529
|
+
req.result.close();
|
|
4530
|
+
var delreq = indexedDB.deleteDatabase(dbName);
|
|
4531
|
+
delreq.onsuccess = delreq.onerror = wrap(function () {
|
|
4532
|
+
reject(new exceptions.NoSuchDatabase("Database ".concat(dbName, " doesnt exist")));
|
|
4533
|
+
});
|
|
4204
4534
|
}
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
if (objectStoreNames.length > 0)
|
|
4213
|
-
try {
|
|
4214
|
-
var tmpTrans = idbdb.transaction(safariMultiStoreFix(objectStoreNames), 'readonly');
|
|
4215
|
-
if (state.autoSchema)
|
|
4216
|
-
readGlobalSchema(db, idbdb, tmpTrans);
|
|
4217
|
-
else {
|
|
4218
|
-
adjustToExistingIndexNames(db, db._dbSchema, tmpTrans);
|
|
4219
|
-
if (!verifyInstalledSchema(db, tmpTrans) && !schemaPatchMode) {
|
|
4220
|
-
console.warn("Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Dexie will add missing parts and increment native version number to workaround this.");
|
|
4221
|
-
idbdb.close();
|
|
4222
|
-
nativeVerToOpen = idbdb.version + 1;
|
|
4223
|
-
schemaPatchMode = true;
|
|
4224
|
-
return resolve(tryOpenDB());
|
|
4225
|
-
}
|
|
4535
|
+
else {
|
|
4536
|
+
upgradeTransaction.onerror = eventRejectHandler(reject);
|
|
4537
|
+
var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion;
|
|
4538
|
+
wasCreated = oldVer < 1;
|
|
4539
|
+
db.idbdb = req.result;
|
|
4540
|
+
if (schemaPatchMode) {
|
|
4541
|
+
patchCurrentVersion(db, upgradeTransaction);
|
|
4226
4542
|
}
|
|
4227
|
-
|
|
4228
|
-
}
|
|
4229
|
-
catch (e) {
|
|
4543
|
+
runUpgraders(db, oldVer / 10, upgradeTransaction, reject);
|
|
4230
4544
|
}
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
db.
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4545
|
+
}, reject);
|
|
4546
|
+
req.onsuccess = wrap(function () {
|
|
4547
|
+
upgradeTransaction = null;
|
|
4548
|
+
var idbdb = (db.idbdb = req.result);
|
|
4549
|
+
var objectStoreNames = slice(idbdb.objectStoreNames);
|
|
4550
|
+
if (objectStoreNames.length > 0)
|
|
4551
|
+
try {
|
|
4552
|
+
var tmpTrans = idbdb.transaction(safariMultiStoreFix(objectStoreNames), 'readonly');
|
|
4553
|
+
if (state.autoSchema)
|
|
4554
|
+
readGlobalSchema(db, idbdb, tmpTrans);
|
|
4555
|
+
else {
|
|
4556
|
+
adjustToExistingIndexNames(db, db._dbSchema, tmpTrans);
|
|
4557
|
+
if (!verifyInstalledSchema(db, tmpTrans) && !schemaPatchMode) {
|
|
4558
|
+
console.warn("Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Dexie will add missing parts and increment native version number to workaround this.");
|
|
4559
|
+
idbdb.close();
|
|
4560
|
+
nativeVerToOpen = idbdb.version + 1;
|
|
4561
|
+
schemaPatchMode = true;
|
|
4562
|
+
return resolve(tryOpenDB());
|
|
4563
|
+
}
|
|
4564
|
+
}
|
|
4565
|
+
generateMiddlewareStacks(db, tmpTrans);
|
|
4566
|
+
}
|
|
4567
|
+
catch (e) {
|
|
4568
|
+
}
|
|
4569
|
+
connections.add(db);
|
|
4570
|
+
idbdb.onversionchange = wrap(function (ev) {
|
|
4571
|
+
state.vcFired = true;
|
|
4572
|
+
db.on('versionchange').fire(ev);
|
|
4573
|
+
});
|
|
4574
|
+
idbdb.onclose = wrap(function () {
|
|
4575
|
+
db.close({ disableAutoOpen: false });
|
|
4576
|
+
});
|
|
4577
|
+
if (wasCreated)
|
|
4578
|
+
_onDatabaseCreated(db._deps, dbName);
|
|
4579
|
+
resolve();
|
|
4580
|
+
}, reject);
|
|
4581
|
+
}).catch(function (err) {
|
|
4582
|
+
switch (err === null || err === void 0 ? void 0 : err.name) {
|
|
4583
|
+
case 'UnknownError':
|
|
4584
|
+
if (state.PR1398_maxLoop > 0) {
|
|
4585
|
+
state.PR1398_maxLoop--;
|
|
4586
|
+
console.warn('Dexie: Workaround for Chrome UnknownError on open()');
|
|
4587
|
+
return tryOpenDB();
|
|
4588
|
+
}
|
|
4589
|
+
break;
|
|
4590
|
+
case 'VersionError':
|
|
4591
|
+
if (nativeVerToOpen > 0) {
|
|
4592
|
+
nativeVerToOpen = 0;
|
|
4593
|
+
return tryOpenDB();
|
|
4594
|
+
}
|
|
4595
|
+
break;
|
|
4596
|
+
}
|
|
4597
|
+
return DexiePromise.reject(err);
|
|
4598
|
+
});
|
|
4599
|
+
};
|
|
4261
4600
|
return DexiePromise.race([
|
|
4262
4601
|
openCanceller,
|
|
4263
|
-
(typeof navigator === 'undefined'
|
|
4264
|
-
|
|
4602
|
+
(typeof navigator === 'undefined'
|
|
4603
|
+
? DexiePromise.resolve()
|
|
4604
|
+
: idbReady()).then(tryOpenDB),
|
|
4605
|
+
])
|
|
4606
|
+
.then(function () {
|
|
4265
4607
|
throwIfCancelled();
|
|
4266
4608
|
state.onReadyBeingFired = [];
|
|
4267
4609
|
return DexiePromise.resolve(vip(function () { return db.on.ready.fire(db.vip); })).then(function fireRemainders() {
|
|
@@ -4271,12 +4613,14 @@ function dexieOpen(db) {
|
|
|
4271
4613
|
return DexiePromise.resolve(vip(function () { return remainders_1(db.vip); })).then(fireRemainders);
|
|
4272
4614
|
}
|
|
4273
4615
|
});
|
|
4274
|
-
})
|
|
4616
|
+
})
|
|
4617
|
+
.finally(function () {
|
|
4275
4618
|
if (state.openCanceller === openCanceller) {
|
|
4276
4619
|
state.onReadyBeingFired = null;
|
|
4277
4620
|
state.isBeingOpened = false;
|
|
4278
4621
|
}
|
|
4279
|
-
})
|
|
4622
|
+
})
|
|
4623
|
+
.catch(function (err) {
|
|
4280
4624
|
state.dbOpenError = err;
|
|
4281
4625
|
try {
|
|
4282
4626
|
upgradeTransaction && upgradeTransaction.abort();
|
|
@@ -4286,16 +4630,19 @@ function dexieOpen(db) {
|
|
|
4286
4630
|
db._close();
|
|
4287
4631
|
}
|
|
4288
4632
|
return rejection(err);
|
|
4289
|
-
})
|
|
4633
|
+
})
|
|
4634
|
+
.finally(function () {
|
|
4290
4635
|
state.openComplete = true;
|
|
4291
4636
|
resolveDbReady();
|
|
4292
|
-
})
|
|
4637
|
+
})
|
|
4638
|
+
.then(function () {
|
|
4293
4639
|
if (wasCreated) {
|
|
4294
4640
|
var everything_1 = {};
|
|
4295
4641
|
db.tables.forEach(function (table) {
|
|
4296
4642
|
table.schema.indexes.forEach(function (idx) {
|
|
4297
4643
|
if (idx.name)
|
|
4298
|
-
everything_1["idb://".concat(db.name, "/").concat(table.name, "/").concat(idx.name)] =
|
|
4644
|
+
everything_1["idb://".concat(db.name, "/").concat(table.name, "/").concat(idx.name)] =
|
|
4645
|
+
new RangeSet(-Infinity, [[[]]]);
|
|
4299
4646
|
});
|
|
4300
4647
|
everything_1["idb://".concat(db.name, "/").concat(table.name, "/")] = everything_1["idb://".concat(db.name, "/").concat(table.name, "/:dels")] = new RangeSet(-Infinity, [[[]]]);
|
|
4301
4648
|
});
|
|
@@ -4311,10 +4658,13 @@ function awaitIterator(iterator) {
|
|
|
4311
4658
|
function step(getNext) {
|
|
4312
4659
|
return function (val) {
|
|
4313
4660
|
var next = getNext(val), value = next.value;
|
|
4314
|
-
return next.done
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
value
|
|
4661
|
+
return next.done
|
|
4662
|
+
? value
|
|
4663
|
+
: !value || typeof value.then !== 'function'
|
|
4664
|
+
? isArray(value)
|
|
4665
|
+
? Promise.all(value).then(onSuccess, onError)
|
|
4666
|
+
: onSuccess(value)
|
|
4667
|
+
: value.then(onSuccess, onError);
|
|
4318
4668
|
};
|
|
4319
4669
|
}
|
|
4320
4670
|
return step(callNext)();
|
|
@@ -4323,7 +4673,7 @@ function awaitIterator(iterator) {
|
|
|
4323
4673
|
function extractTransactionArgs(mode, _tableArgs_, scopeFunc) {
|
|
4324
4674
|
var i = arguments.length;
|
|
4325
4675
|
if (i < 2)
|
|
4326
|
-
throw new exceptions.InvalidArgument(
|
|
4676
|
+
throw new exceptions.InvalidArgument('Too few arguments');
|
|
4327
4677
|
var args = new Array(i - 1);
|
|
4328
4678
|
while (--i)
|
|
4329
4679
|
args[i - 1] = arguments[i];
|
|
@@ -4338,7 +4688,7 @@ function enterTransactionScope(db, mode, storeNames, parentTransaction, scopeFun
|
|
|
4338
4688
|
trans.explicit = true;
|
|
4339
4689
|
var zoneProps = {
|
|
4340
4690
|
trans: trans,
|
|
4341
|
-
transless: transless
|
|
4691
|
+
transless: transless,
|
|
4342
4692
|
};
|
|
4343
4693
|
if (parentTransaction) {
|
|
4344
4694
|
trans.idbtrans = parentTransaction.idbtrans;
|
|
@@ -4350,10 +4700,16 @@ function enterTransactionScope(db, mode, storeNames, parentTransaction, scopeFun
|
|
|
4350
4700
|
db._state.PR1398_maxLoop = 3;
|
|
4351
4701
|
}
|
|
4352
4702
|
catch (ex) {
|
|
4353
|
-
if (ex.name === errnames.InvalidState &&
|
|
4703
|
+
if (ex.name === errnames.InvalidState &&
|
|
4704
|
+
db.isOpen() &&
|
|
4705
|
+
--db._state.PR1398_maxLoop > 0) {
|
|
4354
4706
|
console.warn('Dexie: Need to reopen db');
|
|
4355
4707
|
db.close({ disableAutoOpen: false });
|
|
4356
|
-
return db
|
|
4708
|
+
return db
|
|
4709
|
+
.open()
|
|
4710
|
+
.then(function () {
|
|
4711
|
+
return enterTransactionScope(db, mode, storeNames, null, scopeFunc);
|
|
4712
|
+
});
|
|
4357
4713
|
}
|
|
4358
4714
|
return rejection(ex);
|
|
4359
4715
|
}
|
|
@@ -4370,20 +4726,27 @@ function enterTransactionScope(db, mode, storeNames, parentTransaction, scopeFun
|
|
|
4370
4726
|
var decrementor = decrementExpectedAwaits.bind(null, null);
|
|
4371
4727
|
returnValue.then(decrementor, decrementor);
|
|
4372
4728
|
}
|
|
4373
|
-
else if (typeof returnValue.next === 'function' &&
|
|
4729
|
+
else if (typeof returnValue.next === 'function' &&
|
|
4730
|
+
typeof returnValue.throw === 'function') {
|
|
4374
4731
|
returnValue = awaitIterator(returnValue);
|
|
4375
4732
|
}
|
|
4376
4733
|
}
|
|
4377
4734
|
}, zoneProps);
|
|
4378
|
-
return (returnValue && typeof returnValue.then === 'function'
|
|
4379
|
-
|
|
4380
|
-
x
|
|
4381
|
-
|
|
4382
|
-
|
|
4735
|
+
return (returnValue && typeof returnValue.then === 'function'
|
|
4736
|
+
?
|
|
4737
|
+
DexiePromise.resolve(returnValue).then(function (x) {
|
|
4738
|
+
return trans.active
|
|
4739
|
+
? x
|
|
4740
|
+
: rejection(new exceptions.PrematureCommit('Transaction committed too early. See http://bit.ly/2kdckMn'));
|
|
4741
|
+
})
|
|
4742
|
+
:
|
|
4743
|
+
promiseFollowed.then(function () { return returnValue; }))
|
|
4744
|
+
.then(function (x) {
|
|
4383
4745
|
if (parentTransaction)
|
|
4384
4746
|
trans._resolve();
|
|
4385
4747
|
return trans._completion.then(function () { return x; });
|
|
4386
|
-
})
|
|
4748
|
+
})
|
|
4749
|
+
.catch(function (e) {
|
|
4387
4750
|
trans._reject(e);
|
|
4388
4751
|
return rejection(e);
|
|
4389
4752
|
});
|
|
@@ -4404,8 +4767,13 @@ function createVirtualIndexMiddleware(down) {
|
|
|
4404
4767
|
var allVirtualIndexes = [];
|
|
4405
4768
|
function addVirtualIndexes(keyPath, keyTail, lowLevelIndex) {
|
|
4406
4769
|
var keyPathAlias = getKeyPathAlias(keyPath);
|
|
4407
|
-
var indexList = (indexLookup[keyPathAlias] =
|
|
4408
|
-
|
|
4770
|
+
var indexList = (indexLookup[keyPathAlias] =
|
|
4771
|
+
indexLookup[keyPathAlias] || []);
|
|
4772
|
+
var keyLength = keyPath == null
|
|
4773
|
+
? 0
|
|
4774
|
+
: typeof keyPath === 'string'
|
|
4775
|
+
? 1
|
|
4776
|
+
: keyPath.length;
|
|
4409
4777
|
var isVirtual = keyTail > 0;
|
|
4410
4778
|
var virtualIndex = __assign(__assign({}, lowLevelIndex), { name: isVirtual
|
|
4411
4779
|
? "".concat(keyPathAlias, "(virtual-from:").concat(lowLevelIndex.name, ")")
|
|
@@ -4415,16 +4783,16 @@ function createVirtualIndexMiddleware(down) {
|
|
|
4415
4783
|
allVirtualIndexes.push(virtualIndex);
|
|
4416
4784
|
}
|
|
4417
4785
|
if (keyLength > 1) {
|
|
4418
|
-
var virtualKeyPath = keyLength === 2
|
|
4419
|
-
keyPath[0]
|
|
4420
|
-
keyPath.slice(0, keyLength - 1);
|
|
4786
|
+
var virtualKeyPath = keyLength === 2
|
|
4787
|
+
? keyPath[0]
|
|
4788
|
+
: keyPath.slice(0, keyLength - 1);
|
|
4421
4789
|
addVirtualIndexes(virtualKeyPath, keyTail + 1, lowLevelIndex);
|
|
4422
4790
|
}
|
|
4423
4791
|
indexList.sort(function (a, b) { return a.keyTail - b.keyTail; });
|
|
4424
4792
|
return virtualIndex;
|
|
4425
4793
|
}
|
|
4426
4794
|
var primaryKey = addVirtualIndexes(schema.primaryKey.keyPath, 0, schema.primaryKey);
|
|
4427
|
-
indexLookup[
|
|
4795
|
+
indexLookup[':id'] = [primaryKey];
|
|
4428
4796
|
for (var _i = 0, _a = schema.indexes; _i < _a.length; _i++) {
|
|
4429
4797
|
var index = _a[_i];
|
|
4430
4798
|
addVirtualIndexes(index.keyPath, 0, index);
|
|
@@ -4435,80 +4803,82 @@ function createVirtualIndexMiddleware(down) {
|
|
|
4435
4803
|
}
|
|
4436
4804
|
function translateRange(range, keyTail) {
|
|
4437
4805
|
return {
|
|
4438
|
-
type: range.type === 1
|
|
4439
|
-
2
|
|
4440
|
-
range.type,
|
|
4806
|
+
type: range.type === 1
|
|
4807
|
+
? 2
|
|
4808
|
+
: range.type,
|
|
4441
4809
|
lower: pad(range.lower, range.lowerOpen ? down.MAX_KEY : down.MIN_KEY, keyTail),
|
|
4442
4810
|
lowerOpen: true,
|
|
4443
4811
|
upper: pad(range.upper, range.upperOpen ? down.MIN_KEY : down.MAX_KEY, keyTail),
|
|
4444
|
-
upperOpen: true
|
|
4812
|
+
upperOpen: true,
|
|
4445
4813
|
};
|
|
4446
4814
|
}
|
|
4447
4815
|
function translateRequest(req) {
|
|
4448
4816
|
var index = req.query.index;
|
|
4449
|
-
return index.isVirtual
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4817
|
+
return index.isVirtual
|
|
4818
|
+
? __assign(__assign({}, req), { query: {
|
|
4819
|
+
index: index.lowLevelIndex,
|
|
4820
|
+
range: translateRange(req.query.range, index.keyTail),
|
|
4821
|
+
} }) : req;
|
|
4453
4822
|
}
|
|
4454
4823
|
var result = __assign(__assign({}, table), { schema: __assign(__assign({}, schema), { primaryKey: primaryKey, indexes: allVirtualIndexes, getIndexByKeyPath: findBestIndex }), count: function (req) {
|
|
4455
4824
|
return table.count(translateRequest(req));
|
|
4456
4825
|
}, query: function (req) {
|
|
4457
4826
|
return table.query(translateRequest(req));
|
|
4458
4827
|
}, openCursor: function (req) {
|
|
4459
|
-
var _a = req.query
|
|
4828
|
+
var _a = req.query
|
|
4829
|
+
.index, keyTail = _a.keyTail, isVirtual = _a.isVirtual, keyLength = _a.keyLength;
|
|
4460
4830
|
if (!isVirtual)
|
|
4461
4831
|
return table.openCursor(req);
|
|
4462
4832
|
function createVirtualCursor(cursor) {
|
|
4463
4833
|
function _continue(key) {
|
|
4464
|
-
key != null
|
|
4465
|
-
cursor.continue(pad(key, req.reverse ? down.MAX_KEY : down.MIN_KEY, keyTail))
|
|
4466
|
-
req.unique
|
|
4467
|
-
cursor.continue(cursor.key
|
|
4468
|
-
.
|
|
4469
|
-
? down.MIN_KEY
|
|
4470
|
-
|
|
4471
|
-
cursor.continue();
|
|
4834
|
+
key != null
|
|
4835
|
+
? cursor.continue(pad(key, req.reverse ? down.MAX_KEY : down.MIN_KEY, keyTail))
|
|
4836
|
+
: req.unique
|
|
4837
|
+
? cursor.continue(cursor.key
|
|
4838
|
+
.slice(0, keyLength)
|
|
4839
|
+
.concat(req.reverse ? down.MIN_KEY : down.MAX_KEY, keyTail))
|
|
4840
|
+
: cursor.continue();
|
|
4472
4841
|
}
|
|
4473
4842
|
var virtualCursor = Object.create(cursor, {
|
|
4474
4843
|
continue: { value: _continue },
|
|
4475
4844
|
continuePrimaryKey: {
|
|
4476
4845
|
value: function (key, primaryKey) {
|
|
4477
4846
|
cursor.continuePrimaryKey(pad(key, down.MAX_KEY, keyTail), primaryKey);
|
|
4478
|
-
}
|
|
4847
|
+
},
|
|
4479
4848
|
},
|
|
4480
4849
|
primaryKey: {
|
|
4481
4850
|
get: function () {
|
|
4482
4851
|
return cursor.primaryKey;
|
|
4483
|
-
}
|
|
4852
|
+
},
|
|
4484
4853
|
},
|
|
4485
4854
|
key: {
|
|
4486
4855
|
get: function () {
|
|
4487
4856
|
var key = cursor.key;
|
|
4488
|
-
return keyLength === 1
|
|
4489
|
-
key[0]
|
|
4490
|
-
key.slice(0, keyLength);
|
|
4491
|
-
}
|
|
4857
|
+
return keyLength === 1
|
|
4858
|
+
? key[0]
|
|
4859
|
+
: key.slice(0, keyLength);
|
|
4860
|
+
},
|
|
4492
4861
|
},
|
|
4493
4862
|
value: {
|
|
4494
4863
|
get: function () {
|
|
4495
4864
|
return cursor.value;
|
|
4496
|
-
}
|
|
4497
|
-
}
|
|
4865
|
+
},
|
|
4866
|
+
},
|
|
4498
4867
|
});
|
|
4499
4868
|
return virtualCursor;
|
|
4500
4869
|
}
|
|
4501
|
-
return table
|
|
4870
|
+
return table
|
|
4871
|
+
.openCursor(translateRequest(req))
|
|
4502
4872
|
.then(function (cursor) { return cursor && createVirtualCursor(cursor); });
|
|
4503
4873
|
} });
|
|
4504
4874
|
return result;
|
|
4505
4875
|
} });
|
|
4506
4876
|
}
|
|
4507
4877
|
var virtualIndexMiddleware = {
|
|
4508
|
-
stack:
|
|
4509
|
-
name:
|
|
4878
|
+
stack: 'dbcore',
|
|
4879
|
+
name: 'VirtualIndexMiddleware',
|
|
4510
4880
|
level: 1,
|
|
4511
|
-
create: createVirtualIndexMiddleware
|
|
4881
|
+
create: createVirtualIndexMiddleware,
|
|
4512
4882
|
};
|
|
4513
4883
|
|
|
4514
4884
|
function getObjectDiff(a, b, rv, prfx) {
|
|
@@ -4552,127 +4922,155 @@ function getEffectiveKeys(primaryKey, req) {
|
|
|
4552
4922
|
}
|
|
4553
4923
|
|
|
4554
4924
|
var hooksMiddleware = {
|
|
4555
|
-
stack:
|
|
4556
|
-
name:
|
|
4925
|
+
stack: 'dbcore',
|
|
4926
|
+
name: 'HooksMiddleware',
|
|
4557
4927
|
level: 2,
|
|
4558
|
-
create: function (downCore) {
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
var _a = dxTrans.table(tableName).hook, deleting = _a.deleting, creating = _a.creating, updating = _a.updating;
|
|
4564
|
-
switch (req.type) {
|
|
4565
|
-
case 'add':
|
|
4566
|
-
if (creating.fire === nop)
|
|
4567
|
-
break;
|
|
4568
|
-
return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
|
|
4569
|
-
case 'put':
|
|
4570
|
-
if (creating.fire === nop && updating.fire === nop)
|
|
4571
|
-
break;
|
|
4572
|
-
return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
|
|
4573
|
-
case 'delete':
|
|
4574
|
-
if (deleting.fire === nop)
|
|
4575
|
-
break;
|
|
4576
|
-
return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
|
|
4577
|
-
case 'deleteRange':
|
|
4578
|
-
if (deleting.fire === nop)
|
|
4579
|
-
break;
|
|
4580
|
-
return dxTrans._promise('readwrite', function () { return deleteRange(req); }, true);
|
|
4581
|
-
}
|
|
4582
|
-
return downTable.mutate(req);
|
|
4583
|
-
function addPutOrDelete(req) {
|
|
4928
|
+
create: function (downCore) {
|
|
4929
|
+
return (__assign(__assign({}, downCore), { table: function (tableName) {
|
|
4930
|
+
var downTable = downCore.table(tableName);
|
|
4931
|
+
var primaryKey = downTable.schema.primaryKey;
|
|
4932
|
+
var tableMiddleware = __assign(__assign({}, downTable), { mutate: function (req) {
|
|
4584
4933
|
var dxTrans = PSD.trans;
|
|
4585
|
-
var
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4934
|
+
var _a = dxTrans.table(tableName).hook, deleting = _a.deleting, creating = _a.creating, updating = _a.updating;
|
|
4935
|
+
switch (req.type) {
|
|
4936
|
+
case 'add':
|
|
4937
|
+
if (creating.fire === nop)
|
|
4938
|
+
break;
|
|
4939
|
+
return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
|
|
4940
|
+
case 'put':
|
|
4941
|
+
if (creating.fire === nop && updating.fire === nop)
|
|
4942
|
+
break;
|
|
4943
|
+
return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
|
|
4944
|
+
case 'delete':
|
|
4945
|
+
if (deleting.fire === nop)
|
|
4946
|
+
break;
|
|
4947
|
+
return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
|
|
4948
|
+
case 'deleteRange':
|
|
4949
|
+
if (deleting.fire === nop)
|
|
4950
|
+
break;
|
|
4951
|
+
return dxTrans._promise('readwrite', function () { return deleteRange(req); }, true);
|
|
4952
|
+
}
|
|
4953
|
+
return downTable.mutate(req);
|
|
4954
|
+
function addPutOrDelete(req) {
|
|
4955
|
+
var dxTrans = PSD.trans;
|
|
4956
|
+
var keys = req.keys || getEffectiveKeys(primaryKey, req);
|
|
4957
|
+
if (!keys)
|
|
4958
|
+
throw new Error('Keys missing');
|
|
4959
|
+
req =
|
|
4960
|
+
req.type === 'add' || req.type === 'put'
|
|
4961
|
+
? __assign(__assign({}, req), { keys: keys }) : __assign({}, req);
|
|
4962
|
+
if (req.type !== 'delete')
|
|
4963
|
+
req.values = __spreadArray([], req.values, true);
|
|
4964
|
+
if (req.keys)
|
|
4965
|
+
req.keys = __spreadArray([], req.keys, true);
|
|
4966
|
+
return getExistingValues(downTable, req, keys).then(function (existingValues) {
|
|
4967
|
+
var contexts = keys.map(function (key, i) {
|
|
4968
|
+
var existingValue = existingValues[i];
|
|
4969
|
+
var ctx = { onerror: null, onsuccess: null };
|
|
4970
|
+
if (req.type === 'delete') {
|
|
4971
|
+
deleting.fire.call(ctx, key, existingValue, dxTrans);
|
|
4608
4972
|
}
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
requestedValue_1[keyPath] = additionalChanges_1[keyPath];
|
|
4618
|
-
}
|
|
4619
|
-
else {
|
|
4620
|
-
setByKeyPath(requestedValue_1, keyPath, additionalChanges_1[keyPath]);
|
|
4973
|
+
else if (req.type === 'add' ||
|
|
4974
|
+
existingValue === undefined) {
|
|
4975
|
+
var generatedPrimaryKey = creating.fire.call(ctx, key, req.values[i], dxTrans);
|
|
4976
|
+
if (key == null && generatedPrimaryKey != null) {
|
|
4977
|
+
key = generatedPrimaryKey;
|
|
4978
|
+
req.keys[i] = key;
|
|
4979
|
+
if (!primaryKey.outbound) {
|
|
4980
|
+
setByKeyPath(req.values[i], primaryKey.keyPath, key);
|
|
4621
4981
|
}
|
|
4622
|
-
}
|
|
4982
|
+
}
|
|
4623
4983
|
}
|
|
4624
|
-
|
|
4625
|
-
|
|
4984
|
+
else {
|
|
4985
|
+
var objectDiff = getObjectDiff(existingValue, req.values[i]);
|
|
4986
|
+
var additionalChanges_1 = updating.fire.call(ctx, objectDiff, key, existingValue, dxTrans);
|
|
4987
|
+
if (additionalChanges_1) {
|
|
4988
|
+
var requestedValue_1 = req.values[i];
|
|
4989
|
+
Object.keys(additionalChanges_1).forEach(function (keyPath) {
|
|
4990
|
+
if (hasOwn(requestedValue_1, keyPath)) {
|
|
4991
|
+
requestedValue_1[keyPath] =
|
|
4992
|
+
additionalChanges_1[keyPath];
|
|
4993
|
+
}
|
|
4994
|
+
else {
|
|
4995
|
+
setByKeyPath(requestedValue_1, keyPath, additionalChanges_1[keyPath]);
|
|
4996
|
+
}
|
|
4997
|
+
});
|
|
4998
|
+
}
|
|
4999
|
+
}
|
|
5000
|
+
return ctx;
|
|
5001
|
+
});
|
|
5002
|
+
return downTable
|
|
5003
|
+
.mutate(req)
|
|
5004
|
+
.then(function (_a) {
|
|
5005
|
+
var failures = _a.failures, results = _a.results, numFailures = _a.numFailures, lastResult = _a.lastResult;
|
|
5006
|
+
for (var i = 0; i < keys.length; ++i) {
|
|
5007
|
+
var primKey = results ? results[i] : keys[i];
|
|
5008
|
+
var ctx = contexts[i];
|
|
5009
|
+
if (primKey == null) {
|
|
5010
|
+
ctx.onerror && ctx.onerror(failures[i]);
|
|
5011
|
+
}
|
|
5012
|
+
else {
|
|
5013
|
+
ctx.onsuccess &&
|
|
5014
|
+
ctx.onsuccess(req.type === 'put' && existingValues[i]
|
|
5015
|
+
? req.values[i]
|
|
5016
|
+
: primKey
|
|
5017
|
+
);
|
|
5018
|
+
}
|
|
5019
|
+
}
|
|
5020
|
+
return { failures: failures, results: results, numFailures: numFailures, lastResult: lastResult };
|
|
5021
|
+
})
|
|
5022
|
+
.catch(function (error) {
|
|
5023
|
+
contexts.forEach(function (ctx) { return ctx.onerror && ctx.onerror(error); });
|
|
5024
|
+
return Promise.reject(error);
|
|
5025
|
+
});
|
|
4626
5026
|
});
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
5027
|
+
}
|
|
5028
|
+
function deleteRange(req) {
|
|
5029
|
+
return deleteNextChunk(req.trans, req.range, 10000);
|
|
5030
|
+
}
|
|
5031
|
+
function deleteNextChunk(trans, range, limit) {
|
|
5032
|
+
return downTable
|
|
5033
|
+
.query({
|
|
5034
|
+
trans: trans,
|
|
5035
|
+
values: false,
|
|
5036
|
+
query: { index: primaryKey, range: range },
|
|
5037
|
+
limit: limit,
|
|
5038
|
+
})
|
|
5039
|
+
.then(function (_a) {
|
|
5040
|
+
var result = _a.result;
|
|
5041
|
+
return addPutOrDelete({
|
|
5042
|
+
type: 'delete',
|
|
5043
|
+
keys: result,
|
|
5044
|
+
trans: trans,
|
|
5045
|
+
}).then(function (res) {
|
|
5046
|
+
if (res.numFailures > 0)
|
|
5047
|
+
return Promise.reject(res.failures[0]);
|
|
5048
|
+
if (result.length < limit) {
|
|
5049
|
+
return {
|
|
5050
|
+
failures: [],
|
|
5051
|
+
numFailures: 0,
|
|
5052
|
+
lastResult: undefined,
|
|
5053
|
+
};
|
|
4634
5054
|
}
|
|
4635
5055
|
else {
|
|
4636
|
-
|
|
4637
|
-
req.values[i] :
|
|
4638
|
-
primKey
|
|
4639
|
-
);
|
|
5056
|
+
return deleteNextChunk(trans, __assign(__assign({}, range), { lower: result[result.length - 1], lowerOpen: true }), limit);
|
|
4640
5057
|
}
|
|
4641
|
-
}
|
|
4642
|
-
return { failures: failures, results: results, numFailures: numFailures, lastResult: lastResult };
|
|
4643
|
-
}).catch(function (error) {
|
|
4644
|
-
contexts.forEach(function (ctx) { return ctx.onerror && ctx.onerror(error); });
|
|
4645
|
-
return Promise.reject(error);
|
|
5058
|
+
});
|
|
4646
5059
|
});
|
|
4647
|
-
}
|
|
4648
|
-
}
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
function deleteNextChunk(trans, range, limit) {
|
|
4653
|
-
return downTable.query({ trans: trans, values: false, query: { index: primaryKey, range: range }, limit: limit })
|
|
4654
|
-
.then(function (_a) {
|
|
4655
|
-
var result = _a.result;
|
|
4656
|
-
return addPutOrDelete({ type: 'delete', keys: result, trans: trans }).then(function (res) {
|
|
4657
|
-
if (res.numFailures > 0)
|
|
4658
|
-
return Promise.reject(res.failures[0]);
|
|
4659
|
-
if (result.length < limit) {
|
|
4660
|
-
return { failures: [], numFailures: 0, lastResult: undefined };
|
|
4661
|
-
}
|
|
4662
|
-
else {
|
|
4663
|
-
return deleteNextChunk(trans, __assign(__assign({}, range), { lower: result[result.length - 1], lowerOpen: true }), limit);
|
|
4664
|
-
}
|
|
4665
|
-
});
|
|
4666
|
-
});
|
|
4667
|
-
}
|
|
4668
|
-
} });
|
|
4669
|
-
return tableMiddleware;
|
|
4670
|
-
} })); }
|
|
5060
|
+
}
|
|
5061
|
+
} });
|
|
5062
|
+
return tableMiddleware;
|
|
5063
|
+
} }));
|
|
5064
|
+
},
|
|
4671
5065
|
};
|
|
4672
5066
|
function getExistingValues(table, req, effectiveKeys) {
|
|
4673
|
-
return req.type ===
|
|
5067
|
+
return req.type === 'add'
|
|
4674
5068
|
? Promise.resolve([])
|
|
4675
|
-
: table.getMany({
|
|
5069
|
+
: table.getMany({
|
|
5070
|
+
trans: req.trans,
|
|
5071
|
+
keys: effectiveKeys,
|
|
5072
|
+
cache: 'immutable',
|
|
5073
|
+
});
|
|
4676
5074
|
}
|
|
4677
5075
|
|
|
4678
5076
|
function getFromTransactionCache(keys, cache, clone) {
|
|
@@ -4695,7 +5093,7 @@ function getFromTransactionCache(keys, cache, clone) {
|
|
|
4695
5093
|
}
|
|
4696
5094
|
}
|
|
4697
5095
|
var cacheExistingValuesMiddleware = {
|
|
4698
|
-
stack:
|
|
5096
|
+
stack: 'dbcore',
|
|
4699
5097
|
level: -1,
|
|
4700
5098
|
create: function (core) {
|
|
4701
5099
|
return {
|
|
@@ -4705,20 +5103,20 @@ var cacheExistingValuesMiddleware = {
|
|
|
4705
5103
|
if (!req.cache) {
|
|
4706
5104
|
return table.getMany(req);
|
|
4707
5105
|
}
|
|
4708
|
-
var cachedResult = getFromTransactionCache(req.keys, req.trans[
|
|
5106
|
+
var cachedResult = getFromTransactionCache(req.keys, req.trans['_cache'], req.cache === 'clone');
|
|
4709
5107
|
if (cachedResult) {
|
|
4710
5108
|
return DexiePromise.resolve(cachedResult);
|
|
4711
5109
|
}
|
|
4712
5110
|
return table.getMany(req).then(function (res) {
|
|
4713
|
-
req.trans[
|
|
5111
|
+
req.trans['_cache'] = {
|
|
4714
5112
|
keys: req.keys,
|
|
4715
|
-
values: req.cache ===
|
|
5113
|
+
values: req.cache === 'clone' ? deepClone(res) : res,
|
|
4716
5114
|
};
|
|
4717
5115
|
return res;
|
|
4718
5116
|
});
|
|
4719
5117
|
}, mutate: function (req) {
|
|
4720
|
-
if (req.type !==
|
|
4721
|
-
req.trans[
|
|
5118
|
+
if (req.type !== 'add')
|
|
5119
|
+
req.trans['_cache'] = null;
|
|
4722
5120
|
return table.mutate(req);
|
|
4723
5121
|
} });
|
|
4724
5122
|
},
|
|
@@ -4750,9 +5148,9 @@ function isCachableRequest(type, req) {
|
|
|
4750
5148
|
}
|
|
4751
5149
|
|
|
4752
5150
|
var observabilityMiddleware = {
|
|
4753
|
-
stack:
|
|
5151
|
+
stack: 'dbcore',
|
|
4754
5152
|
level: 0,
|
|
4755
|
-
name:
|
|
5153
|
+
name: 'Observability',
|
|
4756
5154
|
create: function (core) {
|
|
4757
5155
|
var dbName = core.schema.name;
|
|
4758
5156
|
var FULL_RANGE = new RangeSet(core.MIN_KEY, core.MAX_KEY);
|
|
@@ -4766,7 +5164,11 @@ var observabilityMiddleware = {
|
|
|
4766
5164
|
var schema = table.schema;
|
|
4767
5165
|
var primaryKey = schema.primaryKey, indexes = schema.indexes;
|
|
4768
5166
|
var extractKey = primaryKey.extractKey, outbound = primaryKey.outbound;
|
|
4769
|
-
var indexesWithAutoIncPK = primaryKey.autoIncrement &&
|
|
5167
|
+
var indexesWithAutoIncPK = primaryKey.autoIncrement &&
|
|
5168
|
+
indexes.filter(function (index) {
|
|
5169
|
+
return index.compound &&
|
|
5170
|
+
index.keyPath.includes(primaryKey.keyPath);
|
|
5171
|
+
});
|
|
4770
5172
|
var tableClone = __assign(__assign({}, table), { mutate: function (req) {
|
|
4771
5173
|
var _a, _b;
|
|
4772
5174
|
var trans = req.trans;
|
|
@@ -4776,20 +5178,25 @@ var observabilityMiddleware = {
|
|
|
4776
5178
|
return (mutatedParts[part] ||
|
|
4777
5179
|
(mutatedParts[part] = new RangeSet()));
|
|
4778
5180
|
};
|
|
4779
|
-
var pkRangeSet = getRangeSet(
|
|
4780
|
-
var delsRangeSet = getRangeSet(
|
|
5181
|
+
var pkRangeSet = getRangeSet('');
|
|
5182
|
+
var delsRangeSet = getRangeSet(':dels');
|
|
4781
5183
|
var type = req.type;
|
|
4782
|
-
var _c = req.type ===
|
|
5184
|
+
var _c = req.type === 'deleteRange'
|
|
4783
5185
|
? [req.range]
|
|
4784
|
-
: req.type ===
|
|
5186
|
+
: req.type === 'delete'
|
|
4785
5187
|
? [req.keys]
|
|
4786
5188
|
: req.values.length < 50
|
|
4787
|
-
? [
|
|
5189
|
+
? [
|
|
5190
|
+
getEffectiveKeys(primaryKey, req).filter(function (id) { return id; }),
|
|
5191
|
+
req.values,
|
|
5192
|
+
]
|
|
4788
5193
|
: [], keys = _c[0], newObjs = _c[1];
|
|
4789
|
-
var oldCache = req.trans[
|
|
5194
|
+
var oldCache = req.trans['_cache'];
|
|
4790
5195
|
if (isArray(keys)) {
|
|
4791
5196
|
pkRangeSet.addKeys(keys);
|
|
4792
|
-
var oldObjs = type === 'delete' || keys.length === newObjs.length
|
|
5197
|
+
var oldObjs = type === 'delete' || keys.length === newObjs.length
|
|
5198
|
+
? getFromTransactionCache(keys, oldCache)
|
|
5199
|
+
: null;
|
|
4793
5200
|
if (!oldObjs) {
|
|
4794
5201
|
delsRangeSet.addKeys(keys);
|
|
4795
5202
|
}
|
|
@@ -4800,7 +5207,7 @@ var observabilityMiddleware = {
|
|
|
4800
5207
|
else if (keys) {
|
|
4801
5208
|
var range = {
|
|
4802
5209
|
from: (_a = keys.lower) !== null && _a !== void 0 ? _a : core.MIN_KEY,
|
|
4803
|
-
to: (_b = keys.upper) !== null && _b !== void 0 ? _b : core.MAX_KEY
|
|
5210
|
+
to: (_b = keys.upper) !== null && _b !== void 0 ? _b : core.MAX_KEY,
|
|
4804
5211
|
};
|
|
4805
5212
|
delsRangeSet.add(range);
|
|
4806
5213
|
pkRangeSet.add(range);
|
|
@@ -4808,7 +5215,9 @@ var observabilityMiddleware = {
|
|
|
4808
5215
|
else {
|
|
4809
5216
|
pkRangeSet.add(FULL_RANGE);
|
|
4810
5217
|
delsRangeSet.add(FULL_RANGE);
|
|
4811
|
-
schema.indexes.forEach(function (idx) {
|
|
5218
|
+
schema.indexes.forEach(function (idx) {
|
|
5219
|
+
return getRangeSet(idx.name).add(FULL_RANGE);
|
|
5220
|
+
});
|
|
4812
5221
|
}
|
|
4813
5222
|
return table.mutate(req).then(function (res) {
|
|
4814
5223
|
if (keys && (req.type === 'add' || req.type === 'put')) {
|
|
@@ -4847,9 +5256,10 @@ var observabilityMiddleware = {
|
|
|
4847
5256
|
tableClone[method] = function (req) {
|
|
4848
5257
|
var subscr = PSD.subscr;
|
|
4849
5258
|
var isLiveQuery = !!subscr;
|
|
4850
|
-
var cachable = isCachableContext(PSD, table) &&
|
|
5259
|
+
var cachable = isCachableContext(PSD, table) &&
|
|
5260
|
+
isCachableRequest(method, req);
|
|
4851
5261
|
var obsSet = cachable
|
|
4852
|
-
? req.obsSet = {}
|
|
5262
|
+
? (req.obsSet = {})
|
|
4853
5263
|
: subscr;
|
|
4854
5264
|
if (isLiveQuery) {
|
|
4855
5265
|
var getRangeSet = function (indexName) {
|
|
@@ -4857,26 +5267,28 @@ var observabilityMiddleware = {
|
|
|
4857
5267
|
return (obsSet[part] ||
|
|
4858
5268
|
(obsSet[part] = new RangeSet()));
|
|
4859
5269
|
};
|
|
4860
|
-
var pkRangeSet_1 = getRangeSet(
|
|
4861
|
-
var delsRangeSet_1 = getRangeSet(
|
|
5270
|
+
var pkRangeSet_1 = getRangeSet('');
|
|
5271
|
+
var delsRangeSet_1 = getRangeSet(':dels');
|
|
4862
5272
|
var _a = readSubscribers[method](req), queriedIndex = _a[0], queriedRanges = _a[1];
|
|
4863
|
-
if (method === 'query' &&
|
|
5273
|
+
if (method === 'query' &&
|
|
5274
|
+
queriedIndex.isPrimaryKey &&
|
|
5275
|
+
!req.values) {
|
|
4864
5276
|
delsRangeSet_1.add(queriedRanges);
|
|
4865
5277
|
}
|
|
4866
5278
|
else {
|
|
4867
|
-
getRangeSet(queriedIndex.name ||
|
|
5279
|
+
getRangeSet(queriedIndex.name || '').add(queriedRanges);
|
|
4868
5280
|
}
|
|
4869
5281
|
if (!queriedIndex.isPrimaryKey) {
|
|
4870
|
-
if (method ===
|
|
5282
|
+
if (method === 'count') {
|
|
4871
5283
|
delsRangeSet_1.add(FULL_RANGE);
|
|
4872
5284
|
}
|
|
4873
5285
|
else {
|
|
4874
|
-
var keysPromise_1 = method ===
|
|
5286
|
+
var keysPromise_1 = method === 'query' &&
|
|
4875
5287
|
outbound &&
|
|
4876
5288
|
req.values &&
|
|
4877
5289
|
table.query(__assign(__assign({}, req), { values: false }));
|
|
4878
5290
|
return table[method].apply(this, arguments).then(function (res) {
|
|
4879
|
-
if (method ===
|
|
5291
|
+
if (method === 'query') {
|
|
4880
5292
|
if (outbound && req.values) {
|
|
4881
5293
|
return keysPromise_1.then(function (_a) {
|
|
4882
5294
|
var resultingKeys = _a.result;
|
|
@@ -4894,9 +5306,10 @@ var observabilityMiddleware = {
|
|
|
4894
5306
|
delsRangeSet_1.addKeys(pKeys);
|
|
4895
5307
|
}
|
|
4896
5308
|
}
|
|
4897
|
-
else if (method ===
|
|
5309
|
+
else if (method === 'openCursor') {
|
|
4898
5310
|
var cursor_1 = res;
|
|
4899
|
-
var wantValues_1 = req
|
|
5311
|
+
var wantValues_1 = req
|
|
5312
|
+
.values;
|
|
4900
5313
|
return (cursor_1 &&
|
|
4901
5314
|
Object.create(cursor_1, {
|
|
4902
5315
|
key: {
|
|
@@ -4914,7 +5327,8 @@ var observabilityMiddleware = {
|
|
|
4914
5327
|
},
|
|
4915
5328
|
value: {
|
|
4916
5329
|
get: function () {
|
|
4917
|
-
wantValues_1 &&
|
|
5330
|
+
wantValues_1 &&
|
|
5331
|
+
pkRangeSet_1.addKey(cursor_1.primaryKey);
|
|
4918
5332
|
return cursor_1.value;
|
|
4919
5333
|
},
|
|
4920
5334
|
},
|
|
@@ -4934,13 +5348,17 @@ var observabilityMiddleware = {
|
|
|
4934
5348
|
};
|
|
4935
5349
|
function trackAffectedIndexes(getRangeSet, schema, oldObjs, newObjs) {
|
|
4936
5350
|
function addAffectedIndex(ix) {
|
|
4937
|
-
var rangeSet = getRangeSet(ix.name ||
|
|
5351
|
+
var rangeSet = getRangeSet(ix.name || '');
|
|
4938
5352
|
function extractKey(obj) {
|
|
4939
5353
|
return obj != null ? ix.extractKey(obj) : null;
|
|
4940
5354
|
}
|
|
4941
|
-
var addKeyOrKeys = function (key) {
|
|
4942
|
-
|
|
4943
|
-
|
|
5355
|
+
var addKeyOrKeys = function (key) {
|
|
5356
|
+
return ix.multiEntry && isArray(key)
|
|
5357
|
+
?
|
|
5358
|
+
key.forEach(function (key) { return rangeSet.addKey(key); })
|
|
5359
|
+
:
|
|
5360
|
+
rangeSet.addKey(key);
|
|
5361
|
+
};
|
|
4944
5362
|
(oldObjs || newObjs).forEach(function (_, i) {
|
|
4945
5363
|
var oldKey = oldObjs && extractKey(oldObjs[i]);
|
|
4946
5364
|
var newKey = newObjs && extractKey(newObjs[i]);
|
|
@@ -5154,7 +5572,8 @@ function findCompatibleQuery(dbName, tableName, type, req) {
|
|
|
5154
5572
|
var _a;
|
|
5155
5573
|
return entry.req.limit === req.limit &&
|
|
5156
5574
|
entry.req.values === req.values &&
|
|
5157
|
-
((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') ===
|
|
5575
|
+
((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') ===
|
|
5576
|
+
reqDirection_1 &&
|
|
5158
5577
|
areRangesEqual(entry.req.query.range, req.query.range);
|
|
5159
5578
|
});
|
|
5160
5579
|
if (equalEntry)
|
|
@@ -5168,7 +5587,8 @@ function findCompatibleQuery(dbName, tableName, type, req) {
|
|
|
5168
5587
|
var _a;
|
|
5169
5588
|
var limit = 'limit' in entry.req ? entry.req.limit : Infinity;
|
|
5170
5589
|
return (limit >= req.limit &&
|
|
5171
|
-
((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') ===
|
|
5590
|
+
((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') ===
|
|
5591
|
+
reqDirection_1 &&
|
|
5172
5592
|
(req.values ? entry.req.values : true) &&
|
|
5173
5593
|
isSuperRange(entry.req.query.range, req.query.range));
|
|
5174
5594
|
});
|
|
@@ -5183,7 +5603,7 @@ function findCompatibleQuery(dbName, tableName, type, req) {
|
|
|
5183
5603
|
|
|
5184
5604
|
function subscribeToCacheEntry(cacheEntry, container, requery, signal) {
|
|
5185
5605
|
cacheEntry.subscribers.add(requery);
|
|
5186
|
-
signal.addEventListener(
|
|
5606
|
+
signal.addEventListener('abort', function () {
|
|
5187
5607
|
cacheEntry.subscribers.delete(requery);
|
|
5188
5608
|
if (cacheEntry.subscribers.size === 0) {
|
|
5189
5609
|
enqueForDeletion(cacheEntry, container);
|
|
@@ -5219,14 +5639,18 @@ var cacheMiddleware = {
|
|
|
5219
5639
|
if (tblCache) {
|
|
5220
5640
|
var table = core.table(storeName);
|
|
5221
5641
|
var ops = tblCache.optimisticOps.filter(function (op) { return op.trans === idbtrans; });
|
|
5222
|
-
if (idbtrans._explicit &&
|
|
5642
|
+
if (idbtrans._explicit &&
|
|
5643
|
+
wasCommitted &&
|
|
5644
|
+
idbtrans.mutatedParts) {
|
|
5223
5645
|
for (var _a = 0, _b = Object.values(tblCache.queries.query); _a < _b.length; _a++) {
|
|
5224
5646
|
var entries = _b[_a];
|
|
5225
5647
|
for (var _c = 0, _d = entries.slice(); _c < _d.length; _c++) {
|
|
5226
5648
|
var entry = _d[_c];
|
|
5227
5649
|
if (obsSetsOverlap(entry.obsSet, idbtrans.mutatedParts)) {
|
|
5228
5650
|
delArrayItem(entries, entry);
|
|
5229
|
-
entry.subscribers.forEach(function (requery) {
|
|
5651
|
+
entry.subscribers.forEach(function (requery) {
|
|
5652
|
+
return affectedSubscribers_1.add(requery);
|
|
5653
|
+
});
|
|
5230
5654
|
}
|
|
5231
5655
|
}
|
|
5232
5656
|
}
|
|
@@ -5245,18 +5669,24 @@ var cacheMiddleware = {
|
|
|
5245
5669
|
var modRes = applyOptimisticOps(entry.res, entry.req, ops, table, entry, freezeResults);
|
|
5246
5670
|
if (entry.dirty) {
|
|
5247
5671
|
delArrayItem(entries, entry);
|
|
5248
|
-
entry.subscribers.forEach(function (requery) {
|
|
5672
|
+
entry.subscribers.forEach(function (requery) {
|
|
5673
|
+
return affectedSubscribers_1.add(requery);
|
|
5674
|
+
});
|
|
5249
5675
|
}
|
|
5250
5676
|
else if (modRes !== entry.res) {
|
|
5251
5677
|
entry.res = modRes;
|
|
5252
|
-
entry.promise = DexiePromise.resolve({
|
|
5678
|
+
entry.promise = DexiePromise.resolve({
|
|
5679
|
+
result: modRes,
|
|
5680
|
+
});
|
|
5253
5681
|
}
|
|
5254
5682
|
}
|
|
5255
5683
|
else {
|
|
5256
5684
|
if (entry.dirty) {
|
|
5257
5685
|
delArrayItem(entries, entry);
|
|
5258
5686
|
}
|
|
5259
|
-
entry.subscribers.forEach(function (requery) {
|
|
5687
|
+
entry.subscribers.forEach(function (requery) {
|
|
5688
|
+
return affectedSubscribers_1.add(requery);
|
|
5689
|
+
});
|
|
5260
5690
|
}
|
|
5261
5691
|
}
|
|
5262
5692
|
}
|
|
@@ -5294,7 +5724,9 @@ var cacheMiddleware = {
|
|
|
5294
5724
|
if (!tblCache)
|
|
5295
5725
|
return downTable.mutate(req);
|
|
5296
5726
|
var promise = downTable.mutate(req);
|
|
5297
|
-
if ((req.type === 'add' || req.type === 'put') &&
|
|
5727
|
+
if ((req.type === 'add' || req.type === 'put') &&
|
|
5728
|
+
(req.values.length >= 50 ||
|
|
5729
|
+
getEffectiveKeys(primKey, req).some(function (key) { return key == null; }))) {
|
|
5298
5730
|
promise.then(function (res) {
|
|
5299
5731
|
var reqWithResolvedKeys = __assign(__assign({}, req), { values: req.values.map(function (value, i) {
|
|
5300
5732
|
var _a;
|
|
@@ -5308,7 +5740,10 @@ var cacheMiddleware = {
|
|
|
5308
5740
|
}) });
|
|
5309
5741
|
var adjustedReq = adjustOptimisticFromFailures(tblCache, reqWithResolvedKeys, res);
|
|
5310
5742
|
tblCache.optimisticOps.push(adjustedReq);
|
|
5311
|
-
queueMicrotask(function () {
|
|
5743
|
+
queueMicrotask(function () {
|
|
5744
|
+
return req.mutatedParts &&
|
|
5745
|
+
signalSubscribersLazily(req.mutatedParts);
|
|
5746
|
+
});
|
|
5312
5747
|
});
|
|
5313
5748
|
}
|
|
5314
5749
|
else {
|
|
@@ -5332,16 +5767,20 @@ var cacheMiddleware = {
|
|
|
5332
5767
|
return promise;
|
|
5333
5768
|
}, query: function (req) {
|
|
5334
5769
|
var _a;
|
|
5335
|
-
if (!isCachableContext(PSD, downTable) ||
|
|
5770
|
+
if (!isCachableContext(PSD, downTable) ||
|
|
5771
|
+
!isCachableRequest('query', req))
|
|
5336
5772
|
return downTable.query(req);
|
|
5337
|
-
var freezeResults = ((_a = PSD.trans) === null || _a === void 0 ? void 0 : _a.db._options.cache) ===
|
|
5773
|
+
var freezeResults = ((_a = PSD.trans) === null || _a === void 0 ? void 0 : _a.db._options.cache) ===
|
|
5774
|
+
'immutable';
|
|
5338
5775
|
var _b = PSD, requery = _b.requery, signal = _b.signal;
|
|
5339
5776
|
var _c = findCompatibleQuery(dbName, tableName, 'query', req), cacheEntry = _c[0], exactMatch = _c[1], tblCache = _c[2], container = _c[3];
|
|
5340
5777
|
if (cacheEntry && exactMatch) {
|
|
5341
5778
|
cacheEntry.obsSet = req.obsSet;
|
|
5342
5779
|
}
|
|
5343
5780
|
else {
|
|
5344
|
-
var promise = downTable
|
|
5781
|
+
var promise = downTable
|
|
5782
|
+
.query(req)
|
|
5783
|
+
.then(function (res) {
|
|
5345
5784
|
var result = res.result;
|
|
5346
5785
|
if (cacheEntry)
|
|
5347
5786
|
cacheEntry.res = result;
|
|
@@ -5355,7 +5794,8 @@ var cacheMiddleware = {
|
|
|
5355
5794
|
res.result = deepClone(result);
|
|
5356
5795
|
}
|
|
5357
5796
|
return res;
|
|
5358
|
-
})
|
|
5797
|
+
})
|
|
5798
|
+
.catch(function (error) {
|
|
5359
5799
|
if (container && cacheEntry)
|
|
5360
5800
|
delArrayItem(container, cacheEntry);
|
|
5361
5801
|
return Promise.reject(error);
|
|
@@ -5381,7 +5821,7 @@ var cacheMiddleware = {
|
|
|
5381
5821
|
},
|
|
5382
5822
|
objs: new Map(),
|
|
5383
5823
|
optimisticOps: [],
|
|
5384
|
-
unsignaledParts: {}
|
|
5824
|
+
unsignaledParts: {},
|
|
5385
5825
|
};
|
|
5386
5826
|
}
|
|
5387
5827
|
tblCache.queries.query[req.query.index.name || ''] = container;
|
|
@@ -5406,7 +5846,7 @@ function vipify(target, vipDb) {
|
|
|
5406
5846
|
if (prop === 'db')
|
|
5407
5847
|
return vipDb;
|
|
5408
5848
|
return Reflect.get(target, prop, receiver);
|
|
5409
|
-
}
|
|
5849
|
+
},
|
|
5410
5850
|
});
|
|
5411
5851
|
}
|
|
5412
5852
|
|
|
@@ -5421,7 +5861,7 @@ var Dexie$1 = (function () {
|
|
|
5421
5861
|
indexedDB: deps.indexedDB, IDBKeyRange: deps.IDBKeyRange, cache: 'cloned', maxConnections: DEFAULT_MAX_CONNECTIONS }, options);
|
|
5422
5862
|
this._deps = {
|
|
5423
5863
|
indexedDB: options.indexedDB,
|
|
5424
|
-
IDBKeyRange: options.IDBKeyRange
|
|
5864
|
+
IDBKeyRange: options.IDBKeyRange,
|
|
5425
5865
|
};
|
|
5426
5866
|
var addons = options.addons;
|
|
5427
5867
|
this._dbSchema = {};
|
|
@@ -5451,7 +5891,9 @@ var Dexie$1 = (function () {
|
|
|
5451
5891
|
});
|
|
5452
5892
|
this._state = state;
|
|
5453
5893
|
this.name = name;
|
|
5454
|
-
this.on = Events(this,
|
|
5894
|
+
this.on = Events(this, 'populate', 'blocked', 'versionchange', 'close', {
|
|
5895
|
+
ready: [promisableChain, nop],
|
|
5896
|
+
});
|
|
5455
5897
|
this.once = function (event, callback) {
|
|
5456
5898
|
var fn = function () {
|
|
5457
5899
|
var args = [];
|
|
@@ -5495,26 +5937,29 @@ var Dexie$1 = (function () {
|
|
|
5495
5937
|
this.Transaction = createTransactionConstructor(this);
|
|
5496
5938
|
this.Version = createVersionConstructor(this);
|
|
5497
5939
|
this.WhereClause = createWhereClauseConstructor(this);
|
|
5498
|
-
this.on(
|
|
5940
|
+
this.on('versionchange', function (ev) {
|
|
5499
5941
|
if (ev.newVersion > 0)
|
|
5500
5942
|
console.warn("Another connection wants to upgrade database '".concat(_this.name, "'. Closing db now to resume the upgrade."));
|
|
5501
5943
|
else
|
|
5502
5944
|
console.warn("Another connection wants to delete database '".concat(_this.name, "'. Closing db now to resume the delete request."));
|
|
5503
5945
|
_this.close({ disableAutoOpen: false });
|
|
5504
5946
|
});
|
|
5505
|
-
this.on(
|
|
5947
|
+
this.on('blocked', function (ev) {
|
|
5506
5948
|
if (!ev.newVersion || ev.newVersion < ev.oldVersion)
|
|
5507
5949
|
console.warn("Dexie.delete('".concat(_this.name, "') was blocked"));
|
|
5508
5950
|
else
|
|
5509
5951
|
console.warn("Upgrade '".concat(_this.name, "' blocked by other connection holding version ").concat(ev.oldVersion / 10));
|
|
5510
5952
|
});
|
|
5511
5953
|
this._maxKey = getMaxKey(options.IDBKeyRange);
|
|
5512
|
-
this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) {
|
|
5954
|
+
this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) {
|
|
5955
|
+
return new _this.Transaction(mode, storeNames, dbschema, _this._options.chromeTransactionDurability, parentTransaction);
|
|
5956
|
+
};
|
|
5513
5957
|
this._fireOnBlocked = function (ev) {
|
|
5514
|
-
_this.on(
|
|
5515
|
-
connections
|
|
5958
|
+
_this.on('blocked').fire(ev);
|
|
5959
|
+
connections
|
|
5960
|
+
.toArray()
|
|
5516
5961
|
.filter(function (c) { return c.name === _this.name && c !== _this && !c._state.vcFired; })
|
|
5517
|
-
.map(function (c) { return c.on(
|
|
5962
|
+
.map(function (c) { return c.on('versionchange').fire(ev); });
|
|
5518
5963
|
};
|
|
5519
5964
|
this.use(cacheExistingValuesMiddleware);
|
|
5520
5965
|
this.use(cacheMiddleware);
|
|
@@ -5538,7 +5983,7 @@ var Dexie$1 = (function () {
|
|
|
5538
5983
|
return vipify(tx, vipDB);
|
|
5539
5984
|
};
|
|
5540
5985
|
return rv;
|
|
5541
|
-
}
|
|
5986
|
+
},
|
|
5542
5987
|
});
|
|
5543
5988
|
this.vip = vipDB;
|
|
5544
5989
|
addons.forEach(function (addon) { return addon(_this); });
|
|
@@ -5548,7 +5993,7 @@ var Dexie$1 = (function () {
|
|
|
5548
5993
|
throw new exceptions.Type("Given version is not a positive number");
|
|
5549
5994
|
versionNumber = Math.round(versionNumber * 10) / 10;
|
|
5550
5995
|
if (this.idbdb || this._state.isBeingOpened)
|
|
5551
|
-
throw new exceptions.Schema(
|
|
5996
|
+
throw new exceptions.Schema('Cannot add version when database is open');
|
|
5552
5997
|
this.verno = Math.max(this.verno, versionNumber);
|
|
5553
5998
|
var versions = this._versions;
|
|
5554
5999
|
var versionInstance = versions.filter(function (v) { return v._cfg.version === versionNumber; })[0];
|
|
@@ -5563,26 +6008,34 @@ var Dexie$1 = (function () {
|
|
|
5563
6008
|
};
|
|
5564
6009
|
Dexie.prototype._whenReady = function (fn) {
|
|
5565
6010
|
var _this = this;
|
|
5566
|
-
return
|
|
5567
|
-
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
reject(new exceptions.DatabaseClosed());
|
|
5573
|
-
return;
|
|
6011
|
+
return this.idbdb &&
|
|
6012
|
+
(this._state.openComplete || PSD.letThrough || this._vip)
|
|
6013
|
+
? fn()
|
|
6014
|
+
: new DexiePromise(function (resolve, reject) {
|
|
6015
|
+
if (_this._state.openComplete) {
|
|
6016
|
+
return reject(new exceptions.DatabaseClosed(_this._state.dbOpenError));
|
|
5574
6017
|
}
|
|
5575
|
-
_this.
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
6018
|
+
if (!_this._state.isBeingOpened) {
|
|
6019
|
+
if (!_this._state.autoOpen) {
|
|
6020
|
+
reject(new exceptions.DatabaseClosed());
|
|
6021
|
+
return;
|
|
6022
|
+
}
|
|
6023
|
+
_this.open().catch(nop);
|
|
6024
|
+
}
|
|
6025
|
+
_this._state.dbReadyPromise.then(resolve, reject);
|
|
6026
|
+
}).then(fn);
|
|
5579
6027
|
};
|
|
5580
6028
|
Dexie.prototype.use = function (_a) {
|
|
5581
6029
|
var stack = _a.stack, create = _a.create, level = _a.level, name = _a.name;
|
|
5582
6030
|
if (name)
|
|
5583
6031
|
this.unuse({ stack: stack, name: name });
|
|
5584
6032
|
var middlewares = this._middlewares[stack] || (this._middlewares[stack] = []);
|
|
5585
|
-
middlewares.push({
|
|
6033
|
+
middlewares.push({
|
|
6034
|
+
stack: stack,
|
|
6035
|
+
create: create,
|
|
6036
|
+
level: level == null ? 10 : level,
|
|
6037
|
+
name: name,
|
|
6038
|
+
});
|
|
5586
6039
|
middlewares.sort(function (a, b) { return a.level - b.level; });
|
|
5587
6040
|
return this;
|
|
5588
6041
|
};
|
|
@@ -5590,9 +6043,11 @@ var Dexie$1 = (function () {
|
|
|
5590
6043
|
var stack = _a.stack, name = _a.name, create = _a.create;
|
|
5591
6044
|
if (stack && this._middlewares[stack]) {
|
|
5592
6045
|
this._middlewares[stack] = this._middlewares[stack].filter(function (mw) {
|
|
5593
|
-
return create
|
|
5594
|
-
|
|
5595
|
-
|
|
6046
|
+
return create
|
|
6047
|
+
? mw.create !== create
|
|
6048
|
+
: name
|
|
6049
|
+
? mw.name !== name
|
|
6050
|
+
: false;
|
|
5596
6051
|
});
|
|
5597
6052
|
}
|
|
5598
6053
|
return this;
|
|
@@ -5635,8 +6090,7 @@ var Dexie$1 = (function () {
|
|
|
5635
6090
|
}
|
|
5636
6091
|
else {
|
|
5637
6092
|
this._close();
|
|
5638
|
-
state.autoOpen = this._options.autoOpen ||
|
|
5639
|
-
state.isBeingOpened;
|
|
6093
|
+
state.autoOpen = this._options.autoOpen || state.isBeingOpened;
|
|
5640
6094
|
state.openComplete = false;
|
|
5641
6095
|
state.dbOpenError = null;
|
|
5642
6096
|
}
|
|
@@ -5658,7 +6112,7 @@ var Dexie$1 = (function () {
|
|
|
5658
6112
|
req.onblocked = _this._fireOnBlocked;
|
|
5659
6113
|
};
|
|
5660
6114
|
if (hasInvalidArguments)
|
|
5661
|
-
throw new exceptions.InvalidArgument(
|
|
6115
|
+
throw new exceptions.InvalidArgument('Invalid closeOptions argument to db.delete()');
|
|
5662
6116
|
if (state.isBeingOpened) {
|
|
5663
6117
|
state.dbReadyPromise.then(doDelete);
|
|
5664
6118
|
}
|
|
@@ -5675,7 +6129,7 @@ var Dexie$1 = (function () {
|
|
|
5675
6129
|
};
|
|
5676
6130
|
Dexie.prototype.hasBeenClosed = function () {
|
|
5677
6131
|
var dbOpenError = this._state.dbOpenError;
|
|
5678
|
-
return dbOpenError &&
|
|
6132
|
+
return dbOpenError && dbOpenError.name === 'DatabaseClosed';
|
|
5679
6133
|
};
|
|
5680
6134
|
Dexie.prototype.hasFailed = function () {
|
|
5681
6135
|
return this._state.dbOpenError !== null;
|
|
@@ -5698,7 +6152,9 @@ var Dexie$1 = (function () {
|
|
|
5698
6152
|
Dexie.prototype._transaction = function (mode, tables, scopeFunc) {
|
|
5699
6153
|
var _this = this;
|
|
5700
6154
|
var parentTransaction = PSD.trans;
|
|
5701
|
-
if (!parentTransaction ||
|
|
6155
|
+
if (!parentTransaction ||
|
|
6156
|
+
parentTransaction.db !== this ||
|
|
6157
|
+
mode.indexOf('!') !== -1)
|
|
5702
6158
|
parentTransaction = null;
|
|
5703
6159
|
var onlyIfCompatible = mode.indexOf('?') !== -1;
|
|
5704
6160
|
mode = mode.replace('!', '').replace('?', '');
|
|
@@ -5707,51 +6163,56 @@ var Dexie$1 = (function () {
|
|
|
5707
6163
|
storeNames = tables.map(function (table) {
|
|
5708
6164
|
var storeName = table instanceof _this.Table ? table.name : table;
|
|
5709
6165
|
if (typeof storeName !== 'string')
|
|
5710
|
-
throw new TypeError(
|
|
6166
|
+
throw new TypeError('Invalid table argument to Dexie.transaction(). Only Table or String are allowed');
|
|
5711
6167
|
return storeName;
|
|
5712
6168
|
});
|
|
5713
|
-
if (mode ==
|
|
6169
|
+
if (mode == 'r' || mode === READONLY)
|
|
5714
6170
|
idbMode = READONLY;
|
|
5715
|
-
else if (mode ==
|
|
6171
|
+
else if (mode == 'rw' || mode == READWRITE)
|
|
5716
6172
|
idbMode = READWRITE;
|
|
5717
6173
|
else
|
|
5718
|
-
throw new exceptions.InvalidArgument(
|
|
6174
|
+
throw new exceptions.InvalidArgument('Invalid transaction mode: ' + mode);
|
|
5719
6175
|
if (parentTransaction) {
|
|
5720
6176
|
if (parentTransaction.mode === READONLY && idbMode === READWRITE) {
|
|
5721
6177
|
if (onlyIfCompatible) {
|
|
5722
6178
|
parentTransaction = null;
|
|
5723
6179
|
}
|
|
5724
6180
|
else
|
|
5725
|
-
throw new exceptions.SubTransaction(
|
|
6181
|
+
throw new exceptions.SubTransaction('Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY');
|
|
5726
6182
|
}
|
|
5727
6183
|
if (parentTransaction) {
|
|
5728
6184
|
storeNames.forEach(function (storeName) {
|
|
5729
|
-
if (parentTransaction &&
|
|
6185
|
+
if (parentTransaction &&
|
|
6186
|
+
parentTransaction.storeNames.indexOf(storeName) === -1) {
|
|
5730
6187
|
if (onlyIfCompatible) {
|
|
5731
6188
|
parentTransaction = null;
|
|
5732
6189
|
}
|
|
5733
6190
|
else
|
|
5734
|
-
throw new exceptions.SubTransaction(
|
|
5735
|
-
" not included in parent transaction.");
|
|
6191
|
+
throw new exceptions.SubTransaction('Table ' + storeName + ' not included in parent transaction.');
|
|
5736
6192
|
}
|
|
5737
6193
|
});
|
|
5738
6194
|
}
|
|
5739
|
-
if (onlyIfCompatible &&
|
|
6195
|
+
if (onlyIfCompatible &&
|
|
6196
|
+
parentTransaction &&
|
|
6197
|
+
!parentTransaction.active) {
|
|
5740
6198
|
parentTransaction = null;
|
|
5741
6199
|
}
|
|
5742
6200
|
}
|
|
5743
6201
|
}
|
|
5744
6202
|
catch (e) {
|
|
5745
|
-
return parentTransaction
|
|
5746
|
-
parentTransaction._promise(null, function (_, reject) {
|
|
5747
|
-
|
|
6203
|
+
return parentTransaction
|
|
6204
|
+
? parentTransaction._promise(null, function (_, reject) {
|
|
6205
|
+
reject(e);
|
|
6206
|
+
})
|
|
6207
|
+
: rejection(e);
|
|
5748
6208
|
}
|
|
5749
6209
|
var enterTransaction = enterTransactionScope.bind(null, this, idbMode, storeNames, parentTransaction, scopeFunc);
|
|
5750
|
-
return
|
|
5751
|
-
parentTransaction._promise(idbMode, enterTransaction,
|
|
5752
|
-
PSD.trans
|
|
5753
|
-
|
|
5754
|
-
|
|
6210
|
+
return parentTransaction
|
|
6211
|
+
? parentTransaction._promise(idbMode, enterTransaction, 'lock')
|
|
6212
|
+
: PSD.trans
|
|
6213
|
+
?
|
|
6214
|
+
usePSD(PSD.transless, function () { return _this._whenReady(enterTransaction); })
|
|
6215
|
+
: this._whenReady(enterTransaction);
|
|
5755
6216
|
};
|
|
5756
6217
|
Dexie.prototype.table = function (tableName) {
|
|
5757
6218
|
if (!hasOwn(this._allTables, tableName)) {
|
|
@@ -5762,15 +6223,15 @@ var Dexie$1 = (function () {
|
|
|
5762
6223
|
return Dexie;
|
|
5763
6224
|
}());
|
|
5764
6225
|
|
|
5765
|
-
var symbolObservable = typeof Symbol !==
|
|
6226
|
+
var symbolObservable = typeof Symbol !== 'undefined' && 'observable' in Symbol
|
|
5766
6227
|
? Symbol.observable
|
|
5767
|
-
:
|
|
6228
|
+
: '@@observable';
|
|
5768
6229
|
var Observable = (function () {
|
|
5769
6230
|
function Observable(subscribe) {
|
|
5770
6231
|
this._subscribe = subscribe;
|
|
5771
6232
|
}
|
|
5772
6233
|
Observable.prototype.subscribe = function (x, error, complete) {
|
|
5773
|
-
return this._subscribe(!x || typeof x ===
|
|
6234
|
+
return this._subscribe(!x || typeof x === 'function' ? { next: x, error: error, complete: complete } : x);
|
|
5774
6235
|
};
|
|
5775
6236
|
Observable.prototype[symbolObservable] = function () {
|
|
5776
6237
|
return this;
|
|
@@ -5781,8 +6242,11 @@ var Observable = (function () {
|
|
|
5781
6242
|
var domDeps;
|
|
5782
6243
|
try {
|
|
5783
6244
|
domDeps = {
|
|
5784
|
-
indexedDB: _global.indexedDB ||
|
|
5785
|
-
|
|
6245
|
+
indexedDB: _global.indexedDB ||
|
|
6246
|
+
_global.mozIndexedDB ||
|
|
6247
|
+
_global.webkitIndexedDB ||
|
|
6248
|
+
_global.msIndexedDB,
|
|
6249
|
+
IDBKeyRange: _global.IDBKeyRange || _global.webkitIDBKeyRange,
|
|
5786
6250
|
};
|
|
5787
6251
|
}
|
|
5788
6252
|
catch (e) {
|
|
@@ -5856,22 +6320,32 @@ function liveQuery(querier) {
|
|
|
5856
6320
|
signal: abortController.signal,
|
|
5857
6321
|
requery: doQuery,
|
|
5858
6322
|
querier: querier,
|
|
5859
|
-
trans: null
|
|
6323
|
+
trans: null,
|
|
5860
6324
|
};
|
|
5861
6325
|
var ret = execute(ctx);
|
|
6326
|
+
if (!startedListening) {
|
|
6327
|
+
globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, mutationListener);
|
|
6328
|
+
startedListening = true;
|
|
6329
|
+
}
|
|
5862
6330
|
Promise.resolve(ret).then(function (result) {
|
|
5863
6331
|
hasValue = true;
|
|
5864
6332
|
currentValue = result;
|
|
5865
6333
|
if (closed || ctx.signal.aborted) {
|
|
5866
6334
|
return;
|
|
5867
6335
|
}
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
6336
|
+
if (shouldNotify()) {
|
|
6337
|
+
doQuery();
|
|
6338
|
+
}
|
|
6339
|
+
else {
|
|
6340
|
+
currentObs = subscr;
|
|
6341
|
+
if (shouldNotify()) {
|
|
6342
|
+
doQuery();
|
|
6343
|
+
}
|
|
6344
|
+
else {
|
|
6345
|
+
accumMuts = {};
|
|
6346
|
+
execInGlobalContext(function () { return !closed && observer.next && observer.next(result); });
|
|
6347
|
+
}
|
|
5873
6348
|
}
|
|
5874
|
-
execInGlobalContext(function () { return !closed && observer.next && observer.next(result); });
|
|
5875
6349
|
}, function (err) {
|
|
5876
6350
|
hasValue = false;
|
|
5877
6351
|
if (!['DatabaseClosedError', 'AbortError'].includes(err === null || err === void 0 ? void 0 : err.name)) {
|
|
@@ -5899,10 +6373,13 @@ props(Dexie, __assign(__assign({}, fullNameExceptions), {
|
|
|
5899
6373
|
return db.delete();
|
|
5900
6374
|
},
|
|
5901
6375
|
exists: function (name) {
|
|
5902
|
-
return new Dexie(name, { addons: [] })
|
|
6376
|
+
return new Dexie(name, { addons: [] })
|
|
6377
|
+
.open()
|
|
6378
|
+
.then(function (db) {
|
|
5903
6379
|
db.close();
|
|
5904
6380
|
return true;
|
|
5905
|
-
})
|
|
6381
|
+
})
|
|
6382
|
+
.catch('NoSuchDatabaseError', function () { return false; });
|
|
5906
6383
|
},
|
|
5907
6384
|
getDatabaseNames: function (cb) {
|
|
5908
6385
|
try {
|
|
@@ -5918,9 +6395,9 @@ props(Dexie, __assign(__assign({}, fullNameExceptions), {
|
|
|
5918
6395
|
}
|
|
5919
6396
|
return Class;
|
|
5920
6397
|
}, ignoreTransaction: function (scopeFunc) {
|
|
5921
|
-
return PSD.trans
|
|
5922
|
-
usePSD(PSD.transless, scopeFunc)
|
|
5923
|
-
scopeFunc();
|
|
6398
|
+
return PSD.trans
|
|
6399
|
+
? usePSD(PSD.transless || globalPSD, scopeFunc)
|
|
6400
|
+
: scopeFunc();
|
|
5924
6401
|
}, vip: vip, async: function (generatorFn) {
|
|
5925
6402
|
return function () {
|
|
5926
6403
|
try {
|
|
@@ -5945,22 +6422,19 @@ props(Dexie, __assign(__assign({}, fullNameExceptions), {
|
|
|
5945
6422
|
}
|
|
5946
6423
|
},
|
|
5947
6424
|
currentTransaction: {
|
|
5948
|
-
get: function () { return PSD.trans || null; }
|
|
6425
|
+
get: function () { return PSD.trans || null; },
|
|
5949
6426
|
}, waitFor: function (promiseOrFunction, optionalTimeout) {
|
|
5950
|
-
var promise = DexiePromise.resolve(typeof promiseOrFunction === 'function'
|
|
5951
|
-
Dexie.ignoreTransaction(promiseOrFunction)
|
|
5952
|
-
promiseOrFunction)
|
|
5953
|
-
|
|
5954
|
-
return PSD.trans ?
|
|
5955
|
-
PSD.trans.waitFor(promise) :
|
|
5956
|
-
promise;
|
|
6427
|
+
var promise = DexiePromise.resolve(typeof promiseOrFunction === 'function'
|
|
6428
|
+
? Dexie.ignoreTransaction(promiseOrFunction)
|
|
6429
|
+
: promiseOrFunction).timeout(optionalTimeout || 60000);
|
|
6430
|
+
return PSD.trans ? PSD.trans.waitFor(promise) : promise;
|
|
5957
6431
|
},
|
|
5958
6432
|
Promise: DexiePromise,
|
|
5959
6433
|
debug: {
|
|
5960
6434
|
get: function () { return debug; },
|
|
5961
6435
|
set: function (value) {
|
|
5962
6436
|
setDebug(value);
|
|
5963
|
-
}
|
|
6437
|
+
},
|
|
5964
6438
|
},
|
|
5965
6439
|
derive: derive, extend: extend, props: props, override: override,
|
|
5966
6440
|
Events: Events, on: globalEvents, liveQuery: liveQuery, extendObservabilitySet: extendObservabilitySet,
|
|
@@ -5968,21 +6442,22 @@ props(Dexie, __assign(__assign({}, fullNameExceptions), {
|
|
|
5968
6442
|
minKey: minKey,
|
|
5969
6443
|
addons: [],
|
|
5970
6444
|
connections: {
|
|
5971
|
-
get: connections.toArray
|
|
6445
|
+
get: connections.toArray,
|
|
5972
6446
|
},
|
|
5973
6447
|
errnames: errnames,
|
|
5974
6448
|
dependencies: domDeps, cache: cache,
|
|
5975
6449
|
semVer: DEXIE_VERSION, version: DEXIE_VERSION.split('.')
|
|
5976
6450
|
.map(function (n) { return parseInt(n); })
|
|
5977
|
-
.reduce(function (p, c, i) { return p +
|
|
6451
|
+
.reduce(function (p, c, i) { return p + c / Math.pow(10, i * 2); }) }));
|
|
5978
6452
|
Dexie.maxKey = getMaxKey(Dexie.dependencies.IDBKeyRange);
|
|
5979
6453
|
|
|
5980
|
-
if (typeof dispatchEvent !== 'undefined' &&
|
|
6454
|
+
if (typeof dispatchEvent !== 'undefined' &&
|
|
6455
|
+
typeof addEventListener !== 'undefined') {
|
|
5981
6456
|
globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, function (updatedParts) {
|
|
5982
6457
|
if (!propagatingLocally) {
|
|
5983
6458
|
var event_1;
|
|
5984
6459
|
event_1 = new CustomEvent(STORAGE_MUTATED_DOM_EVENT_NAME, {
|
|
5985
|
-
detail: updatedParts
|
|
6460
|
+
detail: updatedParts,
|
|
5986
6461
|
});
|
|
5987
6462
|
propagatingLocally = true;
|
|
5988
6463
|
dispatchEvent(event_1);
|