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