dexie 4.4.0 → 4.4.2-pr2297.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -5
- package/dist/README.md +46 -0
- package/dist/dexie.d.ts +4 -4
- package/dist/dexie.js +1427 -931
- 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 +1427 -931
- 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 +1269 -860
- 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-pr2297.1, Thu Apr 16 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,24 +227,25 @@
|
|
|
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
|
}
|
|
231
|
-
function objectIsEmpty(o) {
|
|
232
|
-
for (var k in o)
|
|
233
|
-
if (hasOwn(o, k))
|
|
234
|
-
return false;
|
|
235
|
-
return true;
|
|
236
|
-
}
|
|
237
249
|
var circularRefs = null;
|
|
238
250
|
function deepClone(any) {
|
|
239
251
|
circularRefs = new WeakMap();
|
|
@@ -273,13 +285,15 @@
|
|
|
273
285
|
function toStringTag(o) {
|
|
274
286
|
return toString.call(o).slice(8, -1);
|
|
275
287
|
}
|
|
276
|
-
var iteratorSymbol = typeof Symbol !== 'undefined' ?
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
+
};
|
|
283
297
|
function delArrayItem(a, x) {
|
|
284
298
|
var i = a.indexOf(x);
|
|
285
299
|
if (i >= 0)
|
|
@@ -296,7 +310,7 @@
|
|
|
296
310
|
return [arrayLike];
|
|
297
311
|
if ((it = getIteratorOf(arrayLike))) {
|
|
298
312
|
a = [];
|
|
299
|
-
while ((x = it.next()), !x.done)
|
|
313
|
+
while (((x = it.next()), !x.done))
|
|
300
314
|
a.push(x.value);
|
|
301
315
|
return a;
|
|
302
316
|
}
|
|
@@ -337,7 +351,7 @@
|
|
|
337
351
|
'Internal',
|
|
338
352
|
'DatabaseClosed',
|
|
339
353
|
'PrematureCommit',
|
|
340
|
-
'ForeignAwait'
|
|
354
|
+
'ForeignAwait',
|
|
341
355
|
];
|
|
342
356
|
var idbDomErrorNames = [
|
|
343
357
|
'Unknown',
|
|
@@ -353,28 +367,34 @@
|
|
|
353
367
|
'Timeout',
|
|
354
368
|
'QuotaExceeded',
|
|
355
369
|
'Syntax',
|
|
356
|
-
'DataClone'
|
|
370
|
+
'DataClone',
|
|
357
371
|
];
|
|
358
372
|
var errorList = dexieErrorNames.concat(idbDomErrorNames);
|
|
359
373
|
var defaultTexts = {
|
|
360
|
-
VersionChanged:
|
|
361
|
-
DatabaseClosed:
|
|
362
|
-
Abort:
|
|
363
|
-
TransactionInactive:
|
|
364
|
-
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',
|
|
365
379
|
};
|
|
366
380
|
function DexieError(name, msg) {
|
|
367
381
|
this.name = name;
|
|
368
382
|
this.message = msg;
|
|
369
383
|
}
|
|
370
|
-
derive(DexieError)
|
|
371
|
-
|
|
384
|
+
derive(DexieError)
|
|
385
|
+
.from(Error)
|
|
386
|
+
.extend({
|
|
387
|
+
toString: function () {
|
|
388
|
+
return this.name + ': ' + this.message;
|
|
389
|
+
},
|
|
372
390
|
});
|
|
373
391
|
function getMultiErrorMessage(msg, failures) {
|
|
374
|
-
return msg +
|
|
375
|
-
.
|
|
376
|
-
.
|
|
377
|
-
|
|
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'));
|
|
378
398
|
}
|
|
379
399
|
function ModifyError(msg, failures, successCount, failedKeys) {
|
|
380
400
|
this.failures = failures;
|
|
@@ -384,16 +404,16 @@
|
|
|
384
404
|
}
|
|
385
405
|
derive(ModifyError).from(DexieError);
|
|
386
406
|
function BulkError(msg, failures) {
|
|
387
|
-
this.name =
|
|
407
|
+
this.name = 'BulkError';
|
|
388
408
|
this.failures = Object.keys(failures).map(function (pos) { return failures[pos]; });
|
|
389
409
|
this.failuresByPos = failures;
|
|
390
410
|
this.message = getMultiErrorMessage(msg, this.failures);
|
|
391
411
|
}
|
|
392
412
|
derive(BulkError).from(DexieError);
|
|
393
|
-
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); }, {});
|
|
394
414
|
var BaseException = DexieError;
|
|
395
415
|
var exceptions = errorList.reduce(function (obj, name) {
|
|
396
|
-
var fullName = name +
|
|
416
|
+
var fullName = name + 'Error';
|
|
397
417
|
function DexieError(msgOrInner, inner) {
|
|
398
418
|
this.name = fullName;
|
|
399
419
|
if (!msgOrInner) {
|
|
@@ -417,23 +437,30 @@
|
|
|
417
437
|
exceptions.Type = TypeError;
|
|
418
438
|
exceptions.Range = RangeError;
|
|
419
439
|
var exceptionMap = idbDomErrorNames.reduce(function (obj, name) {
|
|
420
|
-
obj[name +
|
|
440
|
+
obj[name + 'Error'] = exceptions[name];
|
|
421
441
|
return obj;
|
|
422
442
|
}, {});
|
|
423
443
|
function mapError(domError, message) {
|
|
424
|
-
if (!domError ||
|
|
444
|
+
if (!domError ||
|
|
445
|
+
domError instanceof DexieError ||
|
|
446
|
+
domError instanceof TypeError ||
|
|
447
|
+
domError instanceof SyntaxError ||
|
|
448
|
+
!domError.name ||
|
|
449
|
+
!exceptionMap[domError.name])
|
|
425
450
|
return domError;
|
|
426
451
|
var rv = new exceptionMap[domError.name](message || domError.message, domError);
|
|
427
|
-
if (
|
|
428
|
-
setProp(rv,
|
|
452
|
+
if ('stack' in domError) {
|
|
453
|
+
setProp(rv, 'stack', {
|
|
454
|
+
get: function () {
|
|
429
455
|
return this.inner.stack;
|
|
430
|
-
}
|
|
456
|
+
},
|
|
457
|
+
});
|
|
431
458
|
}
|
|
432
459
|
return rv;
|
|
433
460
|
}
|
|
434
461
|
var fullNameExceptions = errorList.reduce(function (obj, name) {
|
|
435
|
-
if ([
|
|
436
|
-
obj[name +
|
|
462
|
+
if (['Syntax', 'Type', 'Range'].indexOf(name) === -1)
|
|
463
|
+
obj[name + 'Error'] = exceptions[name];
|
|
437
464
|
return obj;
|
|
438
465
|
}, {});
|
|
439
466
|
fullNameExceptions.ModifyError = ModifyError;
|
|
@@ -441,7 +468,9 @@
|
|
|
441
468
|
fullNameExceptions.BulkError = BulkError;
|
|
442
469
|
|
|
443
470
|
function nop() { }
|
|
444
|
-
function mirror(val) {
|
|
471
|
+
function mirror(val) {
|
|
472
|
+
return val;
|
|
473
|
+
}
|
|
445
474
|
function pureFunctionChain(f1, f2) {
|
|
446
475
|
if (f1 == null || f1 === mirror)
|
|
447
476
|
return f2;
|
|
@@ -468,7 +497,9 @@
|
|
|
468
497
|
this.onerror = null;
|
|
469
498
|
var res2 = f2.apply(this, arguments);
|
|
470
499
|
if (onsuccess)
|
|
471
|
-
this.onsuccess = this.onsuccess
|
|
500
|
+
this.onsuccess = this.onsuccess
|
|
501
|
+
? callBoth(onsuccess, this.onsuccess)
|
|
502
|
+
: onsuccess;
|
|
472
503
|
if (onerror)
|
|
473
504
|
this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;
|
|
474
505
|
return res2 !== undefined ? res2 : res;
|
|
@@ -484,7 +515,9 @@
|
|
|
484
515
|
this.onsuccess = this.onerror = null;
|
|
485
516
|
f2.apply(this, arguments);
|
|
486
517
|
if (onsuccess)
|
|
487
|
-
this.onsuccess = this.onsuccess
|
|
518
|
+
this.onsuccess = this.onsuccess
|
|
519
|
+
? callBoth(onsuccess, this.onsuccess)
|
|
520
|
+
: onsuccess;
|
|
488
521
|
if (onerror)
|
|
489
522
|
this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;
|
|
490
523
|
};
|
|
@@ -501,12 +534,16 @@
|
|
|
501
534
|
this.onerror = null;
|
|
502
535
|
var res2 = f2.apply(this, arguments);
|
|
503
536
|
if (onsuccess)
|
|
504
|
-
this.onsuccess = this.onsuccess
|
|
537
|
+
this.onsuccess = this.onsuccess
|
|
538
|
+
? callBoth(onsuccess, this.onsuccess)
|
|
539
|
+
: onsuccess;
|
|
505
540
|
if (onerror)
|
|
506
541
|
this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;
|
|
507
|
-
return res === undefined
|
|
508
|
-
|
|
509
|
-
|
|
542
|
+
return res === undefined
|
|
543
|
+
? res2 === undefined
|
|
544
|
+
? undefined
|
|
545
|
+
: res2
|
|
546
|
+
: extend(res, res2);
|
|
510
547
|
};
|
|
511
548
|
}
|
|
512
549
|
function reverseStoppableEventChain(f1, f2) {
|
|
@@ -542,18 +579,14 @@
|
|
|
542
579
|
}
|
|
543
580
|
|
|
544
581
|
var INTERNAL = {};
|
|
545
|
-
var ZONE_ECHO_LIMIT = 100, _a$1 = typeof Promise === 'undefined'
|
|
546
|
-
[]
|
|
547
|
-
(function () {
|
|
582
|
+
var ZONE_ECHO_LIMIT = 100, _a$1 = typeof Promise === 'undefined'
|
|
583
|
+
? []
|
|
584
|
+
: (function () {
|
|
548
585
|
var globalP = Promise.resolve();
|
|
549
586
|
if (typeof crypto === 'undefined' || !crypto.subtle)
|
|
550
587
|
return [globalP, getProto(globalP), globalP];
|
|
551
|
-
var nativeP = crypto.subtle.digest(
|
|
552
|
-
return [
|
|
553
|
-
nativeP,
|
|
554
|
-
getProto(nativeP),
|
|
555
|
-
globalP
|
|
556
|
-
];
|
|
588
|
+
var nativeP = crypto.subtle.digest('SHA-512', new Uint8Array([0]));
|
|
589
|
+
return [nativeP, getProto(nativeP), globalP];
|
|
557
590
|
})(), resolvedNativePromise = _a$1[0], nativePromiseProto = _a$1[1], resolvedGlobalPromise = _a$1[2], nativePromiseThen = nativePromiseProto && nativePromiseProto.then;
|
|
558
591
|
var NativePromise = resolvedNativePromise && resolvedNativePromise.constructor;
|
|
559
592
|
var patchGlobalPromise = !!resolvedGlobalPromise;
|
|
@@ -580,7 +613,7 @@
|
|
|
580
613
|
onunhandled: nop,
|
|
581
614
|
pgp: false,
|
|
582
615
|
env: {},
|
|
583
|
-
finalize: nop
|
|
616
|
+
finalize: nop,
|
|
584
617
|
};
|
|
585
618
|
var PSD = globalPSD;
|
|
586
619
|
var microtickQueue = [];
|
|
@@ -624,15 +657,15 @@
|
|
|
624
657
|
return then;
|
|
625
658
|
},
|
|
626
659
|
set: function (value) {
|
|
627
|
-
setProp(this, 'then', value && value.prototype === INTERNAL
|
|
628
|
-
thenProp
|
|
629
|
-
{
|
|
660
|
+
setProp(this, 'then', value && value.prototype === INTERNAL
|
|
661
|
+
? thenProp
|
|
662
|
+
: {
|
|
630
663
|
get: function () {
|
|
631
664
|
return value;
|
|
632
665
|
},
|
|
633
|
-
set: thenProp.set
|
|
666
|
+
set: thenProp.set,
|
|
634
667
|
});
|
|
635
|
-
}
|
|
668
|
+
},
|
|
636
669
|
};
|
|
637
670
|
props(DexiePromise.prototype, {
|
|
638
671
|
then: thenProp,
|
|
@@ -643,9 +676,10 @@
|
|
|
643
676
|
if (arguments.length === 1)
|
|
644
677
|
return this.then(null, onRejected);
|
|
645
678
|
var type = arguments[0], handler = arguments[1];
|
|
646
|
-
return typeof type === 'function'
|
|
647
|
-
|
|
648
|
-
|
|
679
|
+
return typeof type === 'function'
|
|
680
|
+
? this.then(null, function (err) {
|
|
681
|
+
return err instanceof type ? handler(err) : PromiseReject(err);
|
|
682
|
+
})
|
|
649
683
|
: this.then(null, function (err) {
|
|
650
684
|
return err && err.name === type ? handler(err) : PromiseReject(err);
|
|
651
685
|
});
|
|
@@ -659,12 +693,13 @@
|
|
|
659
693
|
},
|
|
660
694
|
timeout: function (ms, msg) {
|
|
661
695
|
var _this = this;
|
|
662
|
-
return ms < Infinity
|
|
663
|
-
new DexiePromise(function (resolve, reject) {
|
|
696
|
+
return ms < Infinity
|
|
697
|
+
? new DexiePromise(function (resolve, reject) {
|
|
664
698
|
var handle = setTimeout(function () { return reject(new exceptions.Timeout(msg)); }, ms);
|
|
665
699
|
_this.then(resolve, reject).finally(clearTimeout.bind(null, handle));
|
|
666
|
-
})
|
|
667
|
-
|
|
700
|
+
})
|
|
701
|
+
: this;
|
|
702
|
+
},
|
|
668
703
|
});
|
|
669
704
|
if (typeof Symbol !== 'undefined' && Symbol.toStringTag)
|
|
670
705
|
setProp(DexiePromise.prototype, Symbol.toStringTag, 'Dexie.Promise');
|
|
@@ -678,17 +713,20 @@
|
|
|
678
713
|
}
|
|
679
714
|
props(DexiePromise, {
|
|
680
715
|
all: function () {
|
|
681
|
-
var values = getArrayOf
|
|
716
|
+
var values = getArrayOf
|
|
717
|
+
.apply(null, arguments)
|
|
682
718
|
.map(onPossibleParallellAsync);
|
|
683
719
|
return new DexiePromise(function (resolve, reject) {
|
|
684
720
|
if (values.length === 0)
|
|
685
721
|
resolve([]);
|
|
686
722
|
var remaining = values.length;
|
|
687
|
-
values.forEach(function (a, i) {
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
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
|
+
});
|
|
692
730
|
});
|
|
693
731
|
},
|
|
694
732
|
resolve: function (value) {
|
|
@@ -703,25 +741,31 @@
|
|
|
703
741
|
},
|
|
704
742
|
reject: PromiseReject,
|
|
705
743
|
race: function () {
|
|
706
|
-
var values = getArrayOf
|
|
744
|
+
var values = getArrayOf
|
|
745
|
+
.apply(null, arguments)
|
|
746
|
+
.map(onPossibleParallellAsync);
|
|
707
747
|
return new DexiePromise(function (resolve, reject) {
|
|
708
748
|
values.map(function (value) { return DexiePromise.resolve(value).then(resolve, reject); });
|
|
709
749
|
});
|
|
710
750
|
},
|
|
711
751
|
PSD: {
|
|
712
752
|
get: function () { return PSD; },
|
|
713
|
-
set: function (value) { return PSD = value; }
|
|
753
|
+
set: function (value) { return (PSD = value); },
|
|
714
754
|
},
|
|
715
755
|
totalEchoes: { get: function () { return totalEchoes; } },
|
|
716
756
|
newPSD: newScope,
|
|
717
757
|
usePSD: usePSD,
|
|
718
758
|
scheduler: {
|
|
719
759
|
get: function () { return asap; },
|
|
720
|
-
set: function (value) {
|
|
760
|
+
set: function (value) {
|
|
761
|
+
asap = value;
|
|
762
|
+
},
|
|
721
763
|
},
|
|
722
764
|
rejectionMapper: {
|
|
723
765
|
get: function () { return rejectionMapper; },
|
|
724
|
-
set: function (value) {
|
|
766
|
+
set: function (value) {
|
|
767
|
+
rejectionMapper = value;
|
|
768
|
+
},
|
|
725
769
|
},
|
|
726
770
|
follow: function (fn, zoneProps) {
|
|
727
771
|
return new DexiePromise(function (resolve, reject) {
|
|
@@ -732,40 +776,51 @@
|
|
|
732
776
|
psd.finalize = callBoth(function () {
|
|
733
777
|
var _this = this;
|
|
734
778
|
run_at_end_of_this_or_next_physical_tick(function () {
|
|
735
|
-
_this.unhandleds.length === 0
|
|
779
|
+
_this.unhandleds.length === 0
|
|
780
|
+
? resolve()
|
|
781
|
+
: reject(_this.unhandleds[0]);
|
|
736
782
|
});
|
|
737
783
|
}, psd.finalize);
|
|
738
784
|
fn();
|
|
739
785
|
}, zoneProps, resolve, reject);
|
|
740
786
|
});
|
|
741
|
-
}
|
|
787
|
+
},
|
|
742
788
|
});
|
|
743
789
|
if (NativePromise) {
|
|
744
790
|
if (NativePromise.allSettled)
|
|
745
|
-
setProp(DexiePromise,
|
|
746
|
-
var possiblePromises = getArrayOf
|
|
791
|
+
setProp(DexiePromise, 'allSettled', function () {
|
|
792
|
+
var possiblePromises = getArrayOf
|
|
793
|
+
.apply(null, arguments)
|
|
794
|
+
.map(onPossibleParallellAsync);
|
|
747
795
|
return new DexiePromise(function (resolve) {
|
|
748
796
|
if (possiblePromises.length === 0)
|
|
749
797
|
resolve([]);
|
|
750
798
|
var remaining = possiblePromises.length;
|
|
751
799
|
var results = new Array(remaining);
|
|
752
|
-
possiblePromises.forEach(function (p, i) {
|
|
753
|
-
|
|
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
|
+
});
|
|
754
805
|
});
|
|
755
806
|
});
|
|
756
807
|
if (NativePromise.any && typeof AggregateError !== 'undefined')
|
|
757
|
-
setProp(DexiePromise,
|
|
758
|
-
var possiblePromises = getArrayOf
|
|
808
|
+
setProp(DexiePromise, 'any', function () {
|
|
809
|
+
var possiblePromises = getArrayOf
|
|
810
|
+
.apply(null, arguments)
|
|
811
|
+
.map(onPossibleParallellAsync);
|
|
759
812
|
return new DexiePromise(function (resolve, reject) {
|
|
760
813
|
if (possiblePromises.length === 0)
|
|
761
814
|
reject(new AggregateError([]));
|
|
762
815
|
var remaining = possiblePromises.length;
|
|
763
816
|
var failures = new Array(remaining);
|
|
764
|
-
possiblePromises.forEach(function (p, i) {
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
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
|
+
});
|
|
769
824
|
});
|
|
770
825
|
});
|
|
771
826
|
if (NativePromise.withResolvers)
|
|
@@ -781,9 +836,9 @@
|
|
|
781
836
|
var shouldExecuteTick = promise._lib && beginMicroTickScope();
|
|
782
837
|
if (value && typeof value.then === 'function') {
|
|
783
838
|
executePromiseTask(promise, function (resolve, reject) {
|
|
784
|
-
value instanceof DexiePromise
|
|
785
|
-
value._then(resolve, reject)
|
|
786
|
-
value.then(resolve, reject);
|
|
839
|
+
value instanceof DexiePromise
|
|
840
|
+
? value._then(resolve, reject)
|
|
841
|
+
: value.then(resolve, reject);
|
|
787
842
|
});
|
|
788
843
|
}
|
|
789
844
|
else {
|
|
@@ -846,7 +901,10 @@
|
|
|
846
901
|
var ret, value = promise._value;
|
|
847
902
|
if (!promise._state && rejectingErrors.length)
|
|
848
903
|
rejectingErrors = [];
|
|
849
|
-
ret =
|
|
904
|
+
ret =
|
|
905
|
+
debug && promise._consoleTask
|
|
906
|
+
? promise._consoleTask.run(function () { return cb(value); })
|
|
907
|
+
: cb(value);
|
|
850
908
|
if (!promise._state && rejectingErrors.indexOf(value) === -1) {
|
|
851
909
|
markErrorAsHandled(promise);
|
|
852
910
|
}
|
|
@@ -957,16 +1015,22 @@
|
|
|
957
1015
|
psd.global = false;
|
|
958
1016
|
psd.id = ++zone_id_counter;
|
|
959
1017
|
globalPSD.env;
|
|
960
|
-
psd.env = patchGlobalPromise
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
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
|
+
: {};
|
|
970
1034
|
if (props)
|
|
971
1035
|
extend(psd, props);
|
|
972
1036
|
++parent.ref;
|
|
@@ -997,7 +1061,9 @@
|
|
|
997
1061
|
incrementExpectedAwaits = decrementExpectedAwaits = nop;
|
|
998
1062
|
}
|
|
999
1063
|
function onPossibleParallellAsync(possiblePromise) {
|
|
1000
|
-
if (task.echoes &&
|
|
1064
|
+
if (task.echoes &&
|
|
1065
|
+
possiblePromise &&
|
|
1066
|
+
possiblePromise.constructor === NativePromise) {
|
|
1001
1067
|
incrementExpectedAwaits();
|
|
1002
1068
|
return possiblePromise.then(function (x) {
|
|
1003
1069
|
decrementExpectedAwaits();
|
|
@@ -1024,7 +1090,9 @@
|
|
|
1024
1090
|
}
|
|
1025
1091
|
function switchToZone(targetZone, bEnteringZone) {
|
|
1026
1092
|
var currentZone = PSD;
|
|
1027
|
-
if (bEnteringZone
|
|
1093
|
+
if (bEnteringZone
|
|
1094
|
+
? task.echoes && (!zoneEchoes++ || targetZone !== PSD)
|
|
1095
|
+
: zoneEchoes && (!--zoneEchoes || targetZone !== PSD)) {
|
|
1028
1096
|
queueMicrotask(bEnteringZone ? zoneEnterEcho.bind(null, targetZone) : zoneLeaveEcho);
|
|
1029
1097
|
}
|
|
1030
1098
|
if (targetZone === PSD)
|
|
@@ -1050,16 +1118,18 @@
|
|
|
1050
1118
|
}
|
|
1051
1119
|
function snapShot() {
|
|
1052
1120
|
var GlobalPromise = _global.Promise;
|
|
1053
|
-
return patchGlobalPromise
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
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
|
+
: {};
|
|
1063
1133
|
}
|
|
1064
1134
|
function usePSD(psd, fn, a1, a2, a3) {
|
|
1065
1135
|
var outerScope = PSD;
|
|
@@ -1072,20 +1142,22 @@
|
|
|
1072
1142
|
}
|
|
1073
1143
|
}
|
|
1074
1144
|
function nativeAwaitCompatibleWrap(fn, zone, possibleAwait, cleanup) {
|
|
1075
|
-
return typeof fn !== 'function'
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
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
|
+
};
|
|
1089
1161
|
}
|
|
1090
1162
|
function execInGlobalContext(cb) {
|
|
1091
1163
|
if (Promise === NativePromise && task.echoes === 0) {
|
|
@@ -1102,8 +1174,16 @@
|
|
|
1102
1174
|
}
|
|
1103
1175
|
var rejection = DexiePromise.reject;
|
|
1104
1176
|
|
|
1105
|
-
function
|
|
1106
|
-
|
|
1177
|
+
function isWebKitInjectKeyError(ex) {
|
|
1178
|
+
return ((ex === null || ex === void 0 ? void 0 : ex.name) === 'UnknownError' &&
|
|
1179
|
+
typeof (ex === null || ex === void 0 ? void 0 : ex.message) === 'string' &&
|
|
1180
|
+
ex.message.includes('inject key'));
|
|
1181
|
+
}
|
|
1182
|
+
var WEBKIT_INJECT_KEY_MAX_RETRIES = 20;
|
|
1183
|
+
var WEBKIT_INJECT_KEY_BASE_DELAY_MS = 100;
|
|
1184
|
+
function tempTransaction(db, mode, storeNames, fn, _webkitRetry) {
|
|
1185
|
+
if (_webkitRetry === void 0) { _webkitRetry = 0; }
|
|
1186
|
+
if (!db.idbdb || (!db._state.openComplete && !PSD.letThrough && !db._vip)) {
|
|
1107
1187
|
if (db._state.openComplete) {
|
|
1108
1188
|
return rejection(new exceptions.DatabaseClosed(db._state.dbOpenError));
|
|
1109
1189
|
}
|
|
@@ -1112,7 +1192,9 @@
|
|
|
1112
1192
|
return rejection(new exceptions.DatabaseClosed());
|
|
1113
1193
|
db.open().catch(nop);
|
|
1114
1194
|
}
|
|
1115
|
-
return db._state.dbReadyPromise.then(function () {
|
|
1195
|
+
return db._state.dbReadyPromise.then(function () {
|
|
1196
|
+
return tempTransaction(db, mode, storeNames, fn);
|
|
1197
|
+
});
|
|
1116
1198
|
}
|
|
1117
1199
|
else {
|
|
1118
1200
|
var trans = db._createTransaction(mode, storeNames, db._dbSchema);
|
|
@@ -1121,45 +1203,66 @@
|
|
|
1121
1203
|
db._state.PR1398_maxLoop = 3;
|
|
1122
1204
|
}
|
|
1123
1205
|
catch (ex) {
|
|
1124
|
-
if (ex.name === errnames.InvalidState &&
|
|
1206
|
+
if (ex.name === errnames.InvalidState &&
|
|
1207
|
+
db.isOpen() &&
|
|
1208
|
+
--db._state.PR1398_maxLoop > 0) {
|
|
1125
1209
|
console.warn('Dexie: Need to reopen db');
|
|
1126
1210
|
db.close({ disableAutoOpen: false });
|
|
1127
1211
|
return db.open().then(function () { return tempTransaction(db, mode, storeNames, fn); });
|
|
1128
1212
|
}
|
|
1129
1213
|
return rejection(ex);
|
|
1130
1214
|
}
|
|
1131
|
-
return trans
|
|
1215
|
+
return trans
|
|
1216
|
+
._promise(mode, function (resolve, reject) {
|
|
1132
1217
|
return newScope(function () {
|
|
1133
1218
|
PSD.trans = trans;
|
|
1134
1219
|
return fn(resolve, reject, trans);
|
|
1135
1220
|
});
|
|
1136
|
-
})
|
|
1221
|
+
})
|
|
1222
|
+
.then(function (result) {
|
|
1137
1223
|
if (mode === 'readwrite')
|
|
1138
1224
|
try {
|
|
1139
1225
|
trans.idbtrans.commit();
|
|
1140
1226
|
}
|
|
1141
1227
|
catch (_a) { }
|
|
1142
|
-
return mode === 'readonly'
|
|
1228
|
+
return mode === 'readonly'
|
|
1229
|
+
? result
|
|
1230
|
+
: trans._completion.then(function () { return result; });
|
|
1231
|
+
})
|
|
1232
|
+
.catch(function (ex) {
|
|
1233
|
+
if (isWebKitInjectKeyError(ex) &&
|
|
1234
|
+
_webkitRetry < WEBKIT_INJECT_KEY_MAX_RETRIES) {
|
|
1235
|
+
var delay_1 = WEBKIT_INJECT_KEY_BASE_DELAY_MS * Math.pow(1.5, _webkitRetry);
|
|
1236
|
+
if (_webkitRetry === 0) {
|
|
1237
|
+
console.warn('Dexie: WebKit "Cannot inject key" workaround — retrying transaction');
|
|
1238
|
+
}
|
|
1239
|
+
return new Promise(function (resolve) { return setTimeout(resolve, delay_1); }).then(function () {
|
|
1240
|
+
return tempTransaction(db, mode, storeNames, fn, _webkitRetry + 1);
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
return rejection(ex);
|
|
1143
1244
|
});
|
|
1144
1245
|
}
|
|
1145
1246
|
}
|
|
1146
1247
|
|
|
1147
|
-
var DEXIE_VERSION = '4.4.
|
|
1248
|
+
var DEXIE_VERSION = '4.4.2-pr2297.1';
|
|
1148
1249
|
var maxString = String.fromCharCode(65535);
|
|
1149
1250
|
var minKey = -Infinity;
|
|
1150
|
-
var INVALID_KEY_ARGUMENT =
|
|
1151
|
-
var STRING_EXPECTED =
|
|
1251
|
+
var INVALID_KEY_ARGUMENT = 'Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.';
|
|
1252
|
+
var STRING_EXPECTED = 'String expected.';
|
|
1152
1253
|
var DEFAULT_MAX_CONNECTIONS = 1000;
|
|
1153
1254
|
var DBNAMES_DB = '__dbnames';
|
|
1154
1255
|
var READONLY = 'readonly';
|
|
1155
1256
|
var READWRITE = 'readwrite';
|
|
1156
1257
|
|
|
1157
1258
|
function combine(filter1, filter2) {
|
|
1158
|
-
return filter1
|
|
1159
|
-
filter2
|
|
1160
|
-
function () {
|
|
1161
|
-
|
|
1162
|
-
|
|
1259
|
+
return filter1
|
|
1260
|
+
? filter2
|
|
1261
|
+
? function () {
|
|
1262
|
+
return (filter1.apply(this, arguments) && filter2.apply(this, arguments));
|
|
1263
|
+
}
|
|
1264
|
+
: filter1
|
|
1265
|
+
: filter2;
|
|
1163
1266
|
}
|
|
1164
1267
|
|
|
1165
1268
|
var AnyRange = {
|
|
@@ -1167,13 +1270,13 @@
|
|
|
1167
1270
|
lower: -Infinity,
|
|
1168
1271
|
lowerOpen: false,
|
|
1169
1272
|
upper: [[]],
|
|
1170
|
-
upperOpen: false
|
|
1273
|
+
upperOpen: false,
|
|
1171
1274
|
};
|
|
1172
1275
|
|
|
1173
1276
|
function workaroundForUndefinedPrimKey(keyPath) {
|
|
1174
|
-
return typeof keyPath ===
|
|
1277
|
+
return typeof keyPath === 'string' && !/\./.test(keyPath)
|
|
1175
1278
|
? function (obj) {
|
|
1176
|
-
if (obj[keyPath] === undefined &&
|
|
1279
|
+
if (obj[keyPath] === undefined && keyPath in obj) {
|
|
1177
1280
|
obj = deepClone(obj);
|
|
1178
1281
|
delete obj[keyPath];
|
|
1179
1282
|
}
|
|
@@ -1278,11 +1381,11 @@
|
|
|
1278
1381
|
|
|
1279
1382
|
var PropModification = (function () {
|
|
1280
1383
|
function PropModification(spec) {
|
|
1281
|
-
this[
|
|
1384
|
+
this['@@propmod'] = spec;
|
|
1282
1385
|
}
|
|
1283
1386
|
PropModification.prototype.execute = function (value) {
|
|
1284
1387
|
var _a;
|
|
1285
|
-
var spec = this[
|
|
1388
|
+
var spec = this['@@propmod'];
|
|
1286
1389
|
if (spec.add !== undefined) {
|
|
1287
1390
|
var term = spec.add;
|
|
1288
1391
|
if (isArray(term)) {
|
|
@@ -1303,7 +1406,9 @@
|
|
|
1303
1406
|
if (spec.remove !== undefined) {
|
|
1304
1407
|
var subtrahend_1 = spec.remove;
|
|
1305
1408
|
if (isArray(subtrahend_1)) {
|
|
1306
|
-
return isArray(value)
|
|
1409
|
+
return isArray(value)
|
|
1410
|
+
? value.filter(function (item) { return !subtrahend_1.includes(item); }).sort()
|
|
1411
|
+
: [];
|
|
1307
1412
|
}
|
|
1308
1413
|
if (typeof subtrahend_1 === 'number')
|
|
1309
1414
|
return Number(value) - subtrahend_1;
|
|
@@ -1318,7 +1423,9 @@
|
|
|
1318
1423
|
throw new TypeError("Invalid subtrahend ".concat(subtrahend_1));
|
|
1319
1424
|
}
|
|
1320
1425
|
var prefixToReplace = (_a = spec.replacePrefix) === null || _a === void 0 ? void 0 : _a[0];
|
|
1321
|
-
if (prefixToReplace &&
|
|
1426
|
+
if (prefixToReplace &&
|
|
1427
|
+
typeof value === 'string' &&
|
|
1428
|
+
value.startsWith(prefixToReplace)) {
|
|
1322
1429
|
return spec.replacePrefix[1] + value.substring(prefixToReplace.length);
|
|
1323
1430
|
}
|
|
1324
1431
|
return value;
|
|
@@ -1352,19 +1459,24 @@
|
|
|
1352
1459
|
Table.prototype._trans = function (mode, fn, writeLocked) {
|
|
1353
1460
|
var trans = this._tx || PSD.trans;
|
|
1354
1461
|
var tableName = this.name;
|
|
1355
|
-
var task = debug &&
|
|
1462
|
+
var task = debug &&
|
|
1463
|
+
typeof console !== 'undefined' &&
|
|
1464
|
+
console.createTask &&
|
|
1465
|
+
console.createTask("Dexie: ".concat(mode === 'readonly' ? 'read' : 'write', " ").concat(this.name));
|
|
1356
1466
|
function checkTableInTransaction(resolve, reject, trans) {
|
|
1357
1467
|
if (!trans.schema[tableName])
|
|
1358
|
-
throw new exceptions.NotFound(
|
|
1468
|
+
throw new exceptions.NotFound('Table ' + tableName + ' not part of transaction');
|
|
1359
1469
|
return fn(trans.idbtrans, trans);
|
|
1360
1470
|
}
|
|
1361
1471
|
var wasRootExec = beginMicroTickScope();
|
|
1362
1472
|
try {
|
|
1363
|
-
var p = trans && trans.db._novip === this.db._novip
|
|
1364
|
-
trans === PSD.trans
|
|
1365
|
-
trans._promise(mode, checkTableInTransaction, writeLocked)
|
|
1366
|
-
newScope(function () {
|
|
1367
|
-
|
|
1473
|
+
var p = trans && trans.db._novip === this.db._novip
|
|
1474
|
+
? trans === PSD.trans
|
|
1475
|
+
? trans._promise(mode, checkTableInTransaction, writeLocked)
|
|
1476
|
+
: newScope(function () {
|
|
1477
|
+
return trans._promise(mode, checkTableInTransaction, writeLocked);
|
|
1478
|
+
}, { trans: trans, transless: PSD.transless || PSD })
|
|
1479
|
+
: tempTransaction(this.db, mode, [this.name], checkTableInTransaction);
|
|
1368
1480
|
if (task) {
|
|
1369
1481
|
p._consoleTask = task;
|
|
1370
1482
|
p = p.catch(function (err) {
|
|
@@ -1386,7 +1498,8 @@
|
|
|
1386
1498
|
if (keyOrCrit == null)
|
|
1387
1499
|
return rejection(new exceptions.Type("Invalid argument to Table.get()"));
|
|
1388
1500
|
return this._trans('readonly', function (trans) {
|
|
1389
|
-
return _this.core
|
|
1501
|
+
return _this.core
|
|
1502
|
+
.get({ trans: trans, key: keyOrCrit })
|
|
1390
1503
|
.then(function (res) { return _this.hook.reading.fire(res); });
|
|
1391
1504
|
}).then(cb);
|
|
1392
1505
|
};
|
|
@@ -1397,10 +1510,10 @@
|
|
|
1397
1510
|
return new this.db.WhereClause(this, "[".concat(indexOrCrit.join('+'), "]"));
|
|
1398
1511
|
var keyPaths = keys(indexOrCrit);
|
|
1399
1512
|
if (keyPaths.length === 1)
|
|
1400
|
-
return this
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1513
|
+
return this.where(keyPaths[0]).equals(indexOrCrit[keyPaths[0]]);
|
|
1514
|
+
var compoundIndex = this.schema.indexes
|
|
1515
|
+
.concat(this.schema.primKey)
|
|
1516
|
+
.filter(function (ix) {
|
|
1404
1517
|
if (ix.compound &&
|
|
1405
1518
|
keyPaths.every(function (keyPath) { return ix.keyPath.indexOf(keyPath) >= 0; })) {
|
|
1406
1519
|
for (var i = 0; i < keyPaths.length; ++i) {
|
|
@@ -1410,12 +1523,11 @@
|
|
|
1410
1523
|
return true;
|
|
1411
1524
|
}
|
|
1412
1525
|
return false;
|
|
1413
|
-
})
|
|
1526
|
+
})
|
|
1527
|
+
.sort(function (a, b) { return a.keyPath.length - b.keyPath.length; })[0];
|
|
1414
1528
|
if (compoundIndex && this.db._maxKey !== maxString) {
|
|
1415
1529
|
var keyPathsInValidOrder = compoundIndex.keyPath.slice(0, keyPaths.length);
|
|
1416
|
-
return this
|
|
1417
|
-
.where(keyPathsInValidOrder)
|
|
1418
|
-
.equals(keyPathsInValidOrder.map(function (kp) { return indexOrCrit[kp]; }));
|
|
1530
|
+
return this.where(keyPathsInValidOrder).equals(keyPathsInValidOrder.map(function (kp) { return indexOrCrit[kp]; }));
|
|
1419
1531
|
}
|
|
1420
1532
|
if (!compoundIndex && debug)
|
|
1421
1533
|
console.warn("The query ".concat(JSON.stringify(indexOrCrit), " on ").concat(this.name, " would benefit from a ") +
|
|
@@ -1430,21 +1542,24 @@
|
|
|
1430
1542
|
var value = indexOrCrit[keyPath];
|
|
1431
1543
|
return [
|
|
1432
1544
|
prevIndex || index,
|
|
1433
|
-
prevIndex || !index
|
|
1434
|
-
combine(prevFilterFn, index && index.multi
|
|
1435
|
-
function (x) {
|
|
1545
|
+
prevIndex || !index
|
|
1546
|
+
? combine(prevFilterFn, index && index.multi
|
|
1547
|
+
? function (x) {
|
|
1436
1548
|
var prop = getByKeyPath(x, keyPath);
|
|
1437
|
-
return isArray(prop) &&
|
|
1438
|
-
|
|
1439
|
-
|
|
1549
|
+
return (isArray(prop) &&
|
|
1550
|
+
prop.some(function (item) { return equals(value, item); }));
|
|
1551
|
+
}
|
|
1552
|
+
: function (x) { return equals(value, getByKeyPath(x, keyPath)); })
|
|
1553
|
+
: prevFilterFn,
|
|
1440
1554
|
];
|
|
1441
1555
|
}, [null, null]), idx = _a[0], filterFunction = _a[1];
|
|
1442
|
-
return idx
|
|
1443
|
-
this.where(idx.name)
|
|
1444
|
-
.
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
this.
|
|
1556
|
+
return idx
|
|
1557
|
+
? this.where(idx.name)
|
|
1558
|
+
.equals(indexOrCrit[idx.keyPath])
|
|
1559
|
+
.filter(filterFunction)
|
|
1560
|
+
: compoundIndex
|
|
1561
|
+
? this.filter(filterFunction)
|
|
1562
|
+
: this.where(keyPaths).equals('');
|
|
1448
1563
|
};
|
|
1449
1564
|
Table.prototype.filter = function (filterFunction) {
|
|
1450
1565
|
return this.toCollection().and(filterFunction);
|
|
@@ -1468,9 +1583,7 @@
|
|
|
1468
1583
|
return new this.db.Collection(new this.db.WhereClause(this));
|
|
1469
1584
|
};
|
|
1470
1585
|
Table.prototype.orderBy = function (index) {
|
|
1471
|
-
return new this.db.Collection(new this.db.WhereClause(this, isArray(index) ?
|
|
1472
|
-
"[".concat(index.join('+'), "]") :
|
|
1473
|
-
index));
|
|
1586
|
+
return new this.db.Collection(new this.db.WhereClause(this, isArray(index) ? "[".concat(index.join('+'), "]") : index));
|
|
1474
1587
|
};
|
|
1475
1588
|
Table.prototype.reverse = function () {
|
|
1476
1589
|
return this.toCollection().reverse();
|
|
@@ -1485,17 +1598,23 @@
|
|
|
1485
1598
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
1486
1599
|
}
|
|
1487
1600
|
Object.defineProperty(class_1.prototype, "db", {
|
|
1488
|
-
get: function () {
|
|
1601
|
+
get: function () {
|
|
1602
|
+
return db;
|
|
1603
|
+
},
|
|
1489
1604
|
enumerable: false,
|
|
1490
1605
|
configurable: true
|
|
1491
1606
|
});
|
|
1492
|
-
class_1.prototype.table = function () {
|
|
1607
|
+
class_1.prototype.table = function () {
|
|
1608
|
+
return tableName;
|
|
1609
|
+
};
|
|
1493
1610
|
return class_1;
|
|
1494
1611
|
}(constructor));
|
|
1495
1612
|
}
|
|
1496
1613
|
var inheritedProps = new Set();
|
|
1497
1614
|
for (var proto = constructor.prototype; proto; proto = getProto(proto)) {
|
|
1498
|
-
Object.getOwnPropertyNames(proto).forEach(function (propName) {
|
|
1615
|
+
Object.getOwnPropertyNames(proto).forEach(function (propName) {
|
|
1616
|
+
return inheritedProps.add(propName);
|
|
1617
|
+
});
|
|
1499
1618
|
}
|
|
1500
1619
|
var readHook = function (obj) {
|
|
1501
1620
|
if (!obj)
|
|
@@ -1513,7 +1632,7 @@
|
|
|
1513
1632
|
this.hook.reading.unsubscribe(this.schema.readHook);
|
|
1514
1633
|
}
|
|
1515
1634
|
this.schema.readHook = readHook;
|
|
1516
|
-
this.hook(
|
|
1635
|
+
this.hook('reading', readHook);
|
|
1517
1636
|
return constructor;
|
|
1518
1637
|
};
|
|
1519
1638
|
Table.prototype.defineClass = function () {
|
|
@@ -1530,8 +1649,16 @@
|
|
|
1530
1649
|
objToAdd = workaroundForUndefinedPrimKey(keyPath)(obj);
|
|
1531
1650
|
}
|
|
1532
1651
|
return this._trans('readwrite', function (trans) {
|
|
1533
|
-
return _this.core.mutate({
|
|
1534
|
-
|
|
1652
|
+
return _this.core.mutate({
|
|
1653
|
+
trans: trans,
|
|
1654
|
+
type: 'add',
|
|
1655
|
+
keys: key != null ? [key] : null,
|
|
1656
|
+
values: [objToAdd],
|
|
1657
|
+
});
|
|
1658
|
+
})
|
|
1659
|
+
.then(function (res) {
|
|
1660
|
+
return res.numFailures ? DexiePromise.reject(res.failures[0]) : res.lastResult;
|
|
1661
|
+
})
|
|
1535
1662
|
.then(function (lastResult) {
|
|
1536
1663
|
if (keyPath) {
|
|
1537
1664
|
try {
|
|
@@ -1551,14 +1678,18 @@
|
|
|
1551
1678
|
applyUpdateSpec(obj, modifications);
|
|
1552
1679
|
if (keyPath)
|
|
1553
1680
|
setByKeyPath(obj, keyPath, key);
|
|
1554
|
-
return _this.core
|
|
1681
|
+
return _this.core
|
|
1682
|
+
.mutate({
|
|
1555
1683
|
trans: trans,
|
|
1556
1684
|
type: 'put',
|
|
1557
1685
|
values: [obj],
|
|
1558
1686
|
keys: [key],
|
|
1559
1687
|
upsert: true,
|
|
1560
|
-
updates: { keys: [key], changeSpecs: [modifications] }
|
|
1561
|
-
})
|
|
1688
|
+
updates: { keys: [key], changeSpecs: [modifications] },
|
|
1689
|
+
})
|
|
1690
|
+
.then(function (res) {
|
|
1691
|
+
return res.numFailures ? DexiePromise.reject(res.failures[0]) : !!existing;
|
|
1692
|
+
});
|
|
1562
1693
|
});
|
|
1563
1694
|
});
|
|
1564
1695
|
};
|
|
@@ -1566,11 +1697,11 @@
|
|
|
1566
1697
|
if (typeof keyOrObject === 'object' && !isArray(keyOrObject)) {
|
|
1567
1698
|
var key = getByKeyPath(keyOrObject, this.schema.primKey.keyPath);
|
|
1568
1699
|
if (key === undefined)
|
|
1569
|
-
return rejection(new exceptions.InvalidArgument(
|
|
1570
|
-
return this.where(
|
|
1700
|
+
return rejection(new exceptions.InvalidArgument('Given object does not contain its primary key'));
|
|
1701
|
+
return this.where(':id').equals(key).modify(modifications);
|
|
1571
1702
|
}
|
|
1572
1703
|
else {
|
|
1573
|
-
return this.where(
|
|
1704
|
+
return this.where(':id').equals(keyOrObject).modify(modifications);
|
|
1574
1705
|
}
|
|
1575
1706
|
};
|
|
1576
1707
|
Table.prototype.put = function (obj, key) {
|
|
@@ -1580,8 +1711,17 @@
|
|
|
1580
1711
|
if (keyPath && auto) {
|
|
1581
1712
|
objToAdd = workaroundForUndefinedPrimKey(keyPath)(obj);
|
|
1582
1713
|
}
|
|
1583
|
-
return this._trans('readwrite', function (trans) {
|
|
1584
|
-
|
|
1714
|
+
return this._trans('readwrite', function (trans) {
|
|
1715
|
+
return _this.core.mutate({
|
|
1716
|
+
trans: trans,
|
|
1717
|
+
type: 'put',
|
|
1718
|
+
values: [objToAdd],
|
|
1719
|
+
keys: key != null ? [key] : null,
|
|
1720
|
+
});
|
|
1721
|
+
})
|
|
1722
|
+
.then(function (res) {
|
|
1723
|
+
return res.numFailures ? DexiePromise.reject(res.failures[0]) : res.lastResult;
|
|
1724
|
+
})
|
|
1585
1725
|
.then(function (lastResult) {
|
|
1586
1726
|
if (keyPath) {
|
|
1587
1727
|
try {
|
|
@@ -1594,41 +1734,60 @@
|
|
|
1594
1734
|
};
|
|
1595
1735
|
Table.prototype.delete = function (key) {
|
|
1596
1736
|
var _this = this;
|
|
1597
|
-
return this._trans('readwrite', function (trans) {
|
|
1598
|
-
|
|
1599
|
-
|
|
1737
|
+
return this._trans('readwrite', function (trans) {
|
|
1738
|
+
return _this.core
|
|
1739
|
+
.mutate({ trans: trans, type: 'delete', keys: [key] })
|
|
1740
|
+
.then(function (res) { return builtInDeletionTrigger(_this, [key], res); })
|
|
1741
|
+
.then(function (res) {
|
|
1742
|
+
return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined;
|
|
1743
|
+
});
|
|
1744
|
+
});
|
|
1600
1745
|
};
|
|
1601
1746
|
Table.prototype.clear = function () {
|
|
1602
1747
|
var _this = this;
|
|
1603
|
-
return this._trans('readwrite', function (trans) {
|
|
1604
|
-
|
|
1605
|
-
|
|
1748
|
+
return this._trans('readwrite', function (trans) {
|
|
1749
|
+
return _this.core
|
|
1750
|
+
.mutate({ trans: trans, type: 'deleteRange', range: AnyRange })
|
|
1751
|
+
.then(function (res) { return builtInDeletionTrigger(_this, null, res); });
|
|
1752
|
+
}).then(function (res) {
|
|
1753
|
+
return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined;
|
|
1754
|
+
});
|
|
1606
1755
|
};
|
|
1607
1756
|
Table.prototype.bulkGet = function (keys) {
|
|
1608
1757
|
var _this = this;
|
|
1609
1758
|
return this._trans('readonly', function (trans) {
|
|
1610
|
-
return _this.core
|
|
1759
|
+
return _this.core
|
|
1760
|
+
.getMany({
|
|
1611
1761
|
keys: keys,
|
|
1612
|
-
trans: trans
|
|
1613
|
-
})
|
|
1762
|
+
trans: trans,
|
|
1763
|
+
})
|
|
1764
|
+
.then(function (result) { return result.map(function (res) { return _this.hook.reading.fire(res); }); });
|
|
1614
1765
|
});
|
|
1615
1766
|
};
|
|
1616
1767
|
Table.prototype.bulkAdd = function (objects, keysOrOptions, options) {
|
|
1617
1768
|
var _this = this;
|
|
1618
1769
|
var keys = Array.isArray(keysOrOptions) ? keysOrOptions : undefined;
|
|
1619
|
-
options =
|
|
1770
|
+
options =
|
|
1771
|
+
options || (keys ? undefined : keysOrOptions);
|
|
1620
1772
|
var wantResults = options ? options.allKeys : undefined;
|
|
1621
1773
|
return this._trans('readwrite', function (trans) {
|
|
1622
1774
|
var _a = _this.schema.primKey, auto = _a.auto, keyPath = _a.keyPath;
|
|
1623
1775
|
if (keyPath && keys)
|
|
1624
|
-
throw new exceptions.InvalidArgument(
|
|
1776
|
+
throw new exceptions.InvalidArgument('bulkAdd(): keys argument invalid on tables with inbound keys');
|
|
1625
1777
|
if (keys && keys.length !== objects.length)
|
|
1626
|
-
throw new exceptions.InvalidArgument(
|
|
1778
|
+
throw new exceptions.InvalidArgument('Arguments objects and keys must have the same length');
|
|
1627
1779
|
var numObjects = objects.length;
|
|
1628
|
-
var objectsToAdd = keyPath && auto
|
|
1629
|
-
objects.map(workaroundForUndefinedPrimKey(keyPath))
|
|
1630
|
-
objects;
|
|
1631
|
-
return _this.core
|
|
1780
|
+
var objectsToAdd = keyPath && auto
|
|
1781
|
+
? objects.map(workaroundForUndefinedPrimKey(keyPath))
|
|
1782
|
+
: objects;
|
|
1783
|
+
return _this.core
|
|
1784
|
+
.mutate({
|
|
1785
|
+
trans: trans,
|
|
1786
|
+
type: 'add',
|
|
1787
|
+
keys: keys,
|
|
1788
|
+
values: objectsToAdd,
|
|
1789
|
+
wantResults: wantResults,
|
|
1790
|
+
})
|
|
1632
1791
|
.then(function (_a) {
|
|
1633
1792
|
var numFailures = _a.numFailures, results = _a.results, lastResult = _a.lastResult, failures = _a.failures;
|
|
1634
1793
|
var result = wantResults ? results : lastResult;
|
|
@@ -1641,19 +1800,27 @@
|
|
|
1641
1800
|
Table.prototype.bulkPut = function (objects, keysOrOptions, options) {
|
|
1642
1801
|
var _this = this;
|
|
1643
1802
|
var keys = Array.isArray(keysOrOptions) ? keysOrOptions : undefined;
|
|
1644
|
-
options =
|
|
1803
|
+
options =
|
|
1804
|
+
options || (keys ? undefined : keysOrOptions);
|
|
1645
1805
|
var wantResults = options ? options.allKeys : undefined;
|
|
1646
1806
|
return this._trans('readwrite', function (trans) {
|
|
1647
1807
|
var _a = _this.schema.primKey, auto = _a.auto, keyPath = _a.keyPath;
|
|
1648
1808
|
if (keyPath && keys)
|
|
1649
|
-
throw new exceptions.InvalidArgument(
|
|
1809
|
+
throw new exceptions.InvalidArgument('bulkPut(): keys argument invalid on tables with inbound keys');
|
|
1650
1810
|
if (keys && keys.length !== objects.length)
|
|
1651
|
-
throw new exceptions.InvalidArgument(
|
|
1811
|
+
throw new exceptions.InvalidArgument('Arguments objects and keys must have the same length');
|
|
1652
1812
|
var numObjects = objects.length;
|
|
1653
|
-
var objectsToPut = keyPath && auto
|
|
1654
|
-
objects.map(workaroundForUndefinedPrimKey(keyPath))
|
|
1655
|
-
objects;
|
|
1656
|
-
return _this.core
|
|
1813
|
+
var objectsToPut = keyPath && auto
|
|
1814
|
+
? objects.map(workaroundForUndefinedPrimKey(keyPath))
|
|
1815
|
+
: objects;
|
|
1816
|
+
return _this.core
|
|
1817
|
+
.mutate({
|
|
1818
|
+
trans: trans,
|
|
1819
|
+
type: 'put',
|
|
1820
|
+
keys: keys,
|
|
1821
|
+
values: objectsToPut,
|
|
1822
|
+
wantResults: wantResults,
|
|
1823
|
+
})
|
|
1657
1824
|
.then(function (_a) {
|
|
1658
1825
|
var numFailures = _a.numFailures, results = _a.results, lastResult = _a.lastResult, failures = _a.failures;
|
|
1659
1826
|
var result = wantResults ? results : lastResult;
|
|
@@ -1703,8 +1870,8 @@
|
|
|
1703
1870
|
values: resultObjs,
|
|
1704
1871
|
updates: {
|
|
1705
1872
|
keys: keys,
|
|
1706
|
-
changeSpecs: changeSpecs
|
|
1707
|
-
}
|
|
1873
|
+
changeSpecs: changeSpecs,
|
|
1874
|
+
},
|
|
1708
1875
|
})
|
|
1709
1876
|
.then(function (_a) {
|
|
1710
1877
|
var numFailures = _a.numFailures, failures = _a.failures;
|
|
@@ -1728,7 +1895,8 @@
|
|
|
1728
1895
|
var _this = this;
|
|
1729
1896
|
var numKeys = keys.length;
|
|
1730
1897
|
return this._trans('readwrite', function (trans) {
|
|
1731
|
-
return _this.core
|
|
1898
|
+
return _this.core
|
|
1899
|
+
.mutate({ trans: trans, type: 'delete', keys: keys })
|
|
1732
1900
|
.then(function (res) { return builtInDeletionTrigger(_this, keys, res); });
|
|
1733
1901
|
}).then(function (_a) {
|
|
1734
1902
|
var numFailures = _a.numFailures, lastResult = _a.lastResult, failures = _a.failures;
|
|
@@ -1750,7 +1918,7 @@
|
|
|
1750
1918
|
evs[eventName].subscribe.apply(null, args);
|
|
1751
1919
|
return ctx;
|
|
1752
1920
|
}
|
|
1753
|
-
else if (typeof
|
|
1921
|
+
else if (typeof eventName === 'string') {
|
|
1754
1922
|
return evs[eventName];
|
|
1755
1923
|
}
|
|
1756
1924
|
};
|
|
@@ -1776,9 +1944,11 @@
|
|
|
1776
1944
|
}
|
|
1777
1945
|
},
|
|
1778
1946
|
unsubscribe: function (cb) {
|
|
1779
|
-
context.subscribers = context.subscribers.filter(function (fn) {
|
|
1947
|
+
context.subscribers = context.subscribers.filter(function (fn) {
|
|
1948
|
+
return fn !== cb;
|
|
1949
|
+
});
|
|
1780
1950
|
context.fire = context.subscribers.reduce(chainFunction, defaultFunction);
|
|
1781
|
-
}
|
|
1951
|
+
},
|
|
1782
1952
|
};
|
|
1783
1953
|
evs[eventName] = rv[eventName] = context;
|
|
1784
1954
|
return context;
|
|
@@ -1802,7 +1972,7 @@
|
|
|
1802
1972
|
});
|
|
1803
1973
|
}
|
|
1804
1974
|
else
|
|
1805
|
-
throw new exceptions.InvalidArgument(
|
|
1975
|
+
throw new exceptions.InvalidArgument('Invalid event config');
|
|
1806
1976
|
});
|
|
1807
1977
|
}
|
|
1808
1978
|
}
|
|
@@ -1818,18 +1988,20 @@
|
|
|
1818
1988
|
this._tx = trans;
|
|
1819
1989
|
this.name = name;
|
|
1820
1990
|
this.schema = tableSchema;
|
|
1821
|
-
this.hook = db._allTables[name]
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1991
|
+
this.hook = db._allTables[name]
|
|
1992
|
+
? db._allTables[name].hook
|
|
1993
|
+
: Events(null, {
|
|
1994
|
+
creating: [hookCreatingChain, nop],
|
|
1995
|
+
reading: [pureFunctionChain, mirror],
|
|
1996
|
+
updating: [hookUpdatingChain, nop],
|
|
1997
|
+
deleting: [hookDeletingChain, nop],
|
|
1998
|
+
});
|
|
1827
1999
|
});
|
|
1828
2000
|
}
|
|
1829
2001
|
|
|
1830
2002
|
function isPlainKeyRange(ctx, ignoreLimitFilter) {
|
|
1831
|
-
return !(ctx.filter || ctx.algorithm || ctx.or) &&
|
|
1832
|
-
(ignoreLimitFilter ? ctx.justLimit : !ctx.replayFilter);
|
|
2003
|
+
return (!(ctx.filter || ctx.algorithm || ctx.or) &&
|
|
2004
|
+
(ignoreLimitFilter ? ctx.justLimit : !ctx.replayFilter));
|
|
1833
2005
|
}
|
|
1834
2006
|
function addFilter(ctx, fn) {
|
|
1835
2007
|
ctx.filter = combine(ctx.filter, fn);
|
|
@@ -1847,7 +2019,11 @@
|
|
|
1847
2019
|
return coreSchema.primaryKey;
|
|
1848
2020
|
var index = coreSchema.getIndexByKeyPath(ctx.index);
|
|
1849
2021
|
if (!index)
|
|
1850
|
-
throw new exceptions.Schema(
|
|
2022
|
+
throw new exceptions.Schema('KeyPath ' +
|
|
2023
|
+
ctx.index +
|
|
2024
|
+
' on object store ' +
|
|
2025
|
+
coreSchema.name +
|
|
2026
|
+
' is not indexed');
|
|
1851
2027
|
return index;
|
|
1852
2028
|
}
|
|
1853
2029
|
function openCursor(ctx, coreTable, trans) {
|
|
@@ -1859,19 +2035,22 @@
|
|
|
1859
2035
|
unique: !!ctx.unique,
|
|
1860
2036
|
query: {
|
|
1861
2037
|
index: index,
|
|
1862
|
-
range: ctx.range
|
|
1863
|
-
}
|
|
2038
|
+
range: ctx.range,
|
|
2039
|
+
},
|
|
1864
2040
|
});
|
|
1865
2041
|
}
|
|
1866
2042
|
function iter(ctx, fn, coreTrans, coreTable) {
|
|
1867
|
-
var filter = ctx.replayFilter
|
|
2043
|
+
var filter = ctx.replayFilter
|
|
2044
|
+
? combine(ctx.filter, ctx.replayFilter())
|
|
2045
|
+
: ctx.filter;
|
|
1868
2046
|
if (!ctx.or) {
|
|
1869
2047
|
return iterate(openCursor(ctx, coreTable, coreTrans), combine(ctx.algorithm, filter), fn, !ctx.keysOnly && ctx.valueMapper);
|
|
1870
2048
|
}
|
|
1871
2049
|
else {
|
|
1872
2050
|
var set_1 = {};
|
|
1873
2051
|
var union = function (item, cursor, advance) {
|
|
1874
|
-
if (!filter ||
|
|
2052
|
+
if (!filter ||
|
|
2053
|
+
filter(cursor, advance, function (result) { return cursor.stop(result); }, function (err) { return cursor.fail(err); })) {
|
|
1875
2054
|
var primaryKey = cursor.primaryKey;
|
|
1876
2055
|
var key = '' + primaryKey;
|
|
1877
2056
|
if (key === '[object ArrayBuffer]')
|
|
@@ -1884,7 +2063,7 @@
|
|
|
1884
2063
|
};
|
|
1885
2064
|
return Promise.all([
|
|
1886
2065
|
ctx.or._iterate(union, coreTrans),
|
|
1887
|
-
iterate(openCursor(ctx, coreTable, coreTrans), ctx.algorithm, union, !ctx.keysOnly && ctx.valueMapper)
|
|
2066
|
+
iterate(openCursor(ctx, coreTable, coreTrans), ctx.algorithm, union, !ctx.keysOnly && ctx.valueMapper),
|
|
1888
2067
|
]);
|
|
1889
2068
|
}
|
|
1890
2069
|
}
|
|
@@ -1895,8 +2074,15 @@
|
|
|
1895
2074
|
if (cursor) {
|
|
1896
2075
|
return cursor.start(function () {
|
|
1897
2076
|
var c = function () { return cursor.continue(); };
|
|
1898
|
-
if (!filter ||
|
|
1899
|
-
|
|
2077
|
+
if (!filter ||
|
|
2078
|
+
filter(cursor, function (advancer) { return (c = advancer); }, function (val) {
|
|
2079
|
+
cursor.stop(val);
|
|
2080
|
+
c = nop;
|
|
2081
|
+
}, function (e) {
|
|
2082
|
+
cursor.fail(e);
|
|
2083
|
+
c = nop;
|
|
2084
|
+
}))
|
|
2085
|
+
wrappedFn(cursor.value, cursor, function (advancer) { return (c = advancer); });
|
|
1900
2086
|
c();
|
|
1901
2087
|
});
|
|
1902
2088
|
}
|
|
@@ -1908,15 +2094,15 @@
|
|
|
1908
2094
|
}
|
|
1909
2095
|
Collection.prototype._read = function (fn, cb) {
|
|
1910
2096
|
var ctx = this._ctx;
|
|
1911
|
-
return ctx.error
|
|
1912
|
-
ctx.table._trans(null, rejection.bind(null, ctx.error))
|
|
1913
|
-
ctx.table._trans('readonly', fn).then(cb);
|
|
2097
|
+
return ctx.error
|
|
2098
|
+
? ctx.table._trans(null, rejection.bind(null, ctx.error))
|
|
2099
|
+
: ctx.table._trans('readonly', fn).then(cb);
|
|
1914
2100
|
};
|
|
1915
2101
|
Collection.prototype._write = function (fn) {
|
|
1916
2102
|
var ctx = this._ctx;
|
|
1917
|
-
return ctx.error
|
|
1918
|
-
ctx.table._trans(null, rejection.bind(null, ctx.error))
|
|
1919
|
-
ctx.table._trans('readwrite', fn,
|
|
2103
|
+
return ctx.error
|
|
2104
|
+
? ctx.table._trans(null, rejection.bind(null, ctx.error))
|
|
2105
|
+
: ctx.table._trans('readwrite', fn, 'locked');
|
|
1920
2106
|
};
|
|
1921
2107
|
Collection.prototype._addAlgorithm = function (fn) {
|
|
1922
2108
|
var ctx = this._ctx;
|
|
@@ -1946,18 +2132,22 @@
|
|
|
1946
2132
|
var ctx = _this._ctx;
|
|
1947
2133
|
var coreTable = ctx.table.core;
|
|
1948
2134
|
if (isPlainKeyRange(ctx, true)) {
|
|
1949
|
-
return coreTable
|
|
2135
|
+
return coreTable
|
|
2136
|
+
.count({
|
|
1950
2137
|
trans: trans,
|
|
1951
2138
|
query: {
|
|
1952
2139
|
index: getIndexOrStore(ctx, coreTable.schema),
|
|
1953
|
-
range: ctx.range
|
|
1954
|
-
}
|
|
1955
|
-
})
|
|
2140
|
+
range: ctx.range,
|
|
2141
|
+
},
|
|
2142
|
+
})
|
|
2143
|
+
.then(function (count) { return Math.min(count, ctx.limit); });
|
|
1956
2144
|
}
|
|
1957
2145
|
else {
|
|
1958
2146
|
var count = 0;
|
|
1959
|
-
return iter(ctx, function () {
|
|
1960
|
-
|
|
2147
|
+
return iter(ctx, function () {
|
|
2148
|
+
++count;
|
|
2149
|
+
return false;
|
|
2150
|
+
}, trans, coreTable).then(function () { return count; });
|
|
1961
2151
|
}
|
|
1962
2152
|
}).then(cb);
|
|
1963
2153
|
};
|
|
@@ -1968,13 +2158,13 @@
|
|
|
1968
2158
|
return getval(obj[parts[i]], i - 1);
|
|
1969
2159
|
return obj[lastPart];
|
|
1970
2160
|
}
|
|
1971
|
-
var order = this._ctx.dir ===
|
|
2161
|
+
var order = this._ctx.dir === 'next' ? 1 : -1;
|
|
1972
2162
|
function sorter(a, b) {
|
|
1973
2163
|
var aVal = getval(a, lastIndex), bVal = getval(b, lastIndex);
|
|
1974
2164
|
return cmp(aVal, bVal) * order;
|
|
1975
2165
|
}
|
|
1976
2166
|
return this.toArray(function (a) {
|
|
1977
|
-
return a.sort(sorter);
|
|
2167
|
+
return a.slice().sort(sorter);
|
|
1978
2168
|
}).then(cb);
|
|
1979
2169
|
};
|
|
1980
2170
|
Collection.prototype.toArray = function (cb) {
|
|
@@ -1984,16 +2174,18 @@
|
|
|
1984
2174
|
if (isPlainKeyRange(ctx, true) && ctx.limit > 0) {
|
|
1985
2175
|
var valueMapper_1 = ctx.valueMapper;
|
|
1986
2176
|
var index = getIndexOrStore(ctx, ctx.table.core.schema);
|
|
1987
|
-
return ctx.table.core
|
|
2177
|
+
return ctx.table.core
|
|
2178
|
+
.query({
|
|
1988
2179
|
trans: trans,
|
|
1989
2180
|
limit: ctx.limit,
|
|
1990
2181
|
values: true,
|
|
1991
2182
|
direction: ctx.dir === 'prev' ? 'prev' : undefined,
|
|
1992
2183
|
query: {
|
|
1993
2184
|
index: index,
|
|
1994
|
-
range: ctx.range
|
|
1995
|
-
}
|
|
1996
|
-
})
|
|
2185
|
+
range: ctx.range,
|
|
2186
|
+
},
|
|
2187
|
+
})
|
|
2188
|
+
.then(function (_a) {
|
|
1997
2189
|
var result = _a.result;
|
|
1998
2190
|
return valueMapper_1 ? result.map(valueMapper_1) : result;
|
|
1999
2191
|
});
|
|
@@ -2030,7 +2222,7 @@
|
|
|
2030
2222
|
else {
|
|
2031
2223
|
addReplayFilter(ctx, function () {
|
|
2032
2224
|
var offsetLeft = offset;
|
|
2033
|
-
return function () { return
|
|
2225
|
+
return function () { return --offsetLeft < 0; };
|
|
2034
2226
|
});
|
|
2035
2227
|
}
|
|
2036
2228
|
return this;
|
|
@@ -2060,7 +2252,11 @@
|
|
|
2060
2252
|
return this;
|
|
2061
2253
|
};
|
|
2062
2254
|
Collection.prototype.first = function (cb) {
|
|
2063
|
-
return this.limit(1)
|
|
2255
|
+
return this.limit(1)
|
|
2256
|
+
.toArray(function (a) {
|
|
2257
|
+
return a[0];
|
|
2258
|
+
})
|
|
2259
|
+
.then(cb);
|
|
2064
2260
|
};
|
|
2065
2261
|
Collection.prototype.last = function (cb) {
|
|
2066
2262
|
return this.reverse().first(cb);
|
|
@@ -2079,7 +2275,7 @@
|
|
|
2079
2275
|
return new this.db.WhereClause(this._ctx.table, indexName, this);
|
|
2080
2276
|
};
|
|
2081
2277
|
Collection.prototype.reverse = function () {
|
|
2082
|
-
this._ctx.dir =
|
|
2278
|
+
this._ctx.dir = this._ctx.dir === 'prev' ? 'next' : 'prev';
|
|
2083
2279
|
if (this._ondirectionchange)
|
|
2084
2280
|
this._ondirectionchange(this._ctx.dir);
|
|
2085
2281
|
return this;
|
|
@@ -2090,16 +2286,20 @@
|
|
|
2090
2286
|
Collection.prototype.eachKey = function (cb) {
|
|
2091
2287
|
var ctx = this._ctx;
|
|
2092
2288
|
ctx.keysOnly = !ctx.isMatch;
|
|
2093
|
-
return this.each(function (val, cursor) {
|
|
2289
|
+
return this.each(function (val, cursor) {
|
|
2290
|
+
cb(cursor.key, cursor);
|
|
2291
|
+
});
|
|
2094
2292
|
};
|
|
2095
2293
|
Collection.prototype.eachUniqueKey = function (cb) {
|
|
2096
|
-
this._ctx.unique =
|
|
2294
|
+
this._ctx.unique = 'unique';
|
|
2097
2295
|
return this.eachKey(cb);
|
|
2098
2296
|
};
|
|
2099
2297
|
Collection.prototype.eachPrimaryKey = function (cb) {
|
|
2100
2298
|
var ctx = this._ctx;
|
|
2101
2299
|
ctx.keysOnly = !ctx.isMatch;
|
|
2102
|
-
return this.each(function (val, cursor) {
|
|
2300
|
+
return this.each(function (val, cursor) {
|
|
2301
|
+
cb(cursor.primaryKey, cursor);
|
|
2302
|
+
});
|
|
2103
2303
|
};
|
|
2104
2304
|
Collection.prototype.keys = function (cb) {
|
|
2105
2305
|
var ctx = this._ctx;
|
|
@@ -2107,9 +2307,11 @@
|
|
|
2107
2307
|
var a = [];
|
|
2108
2308
|
return this.each(function (item, cursor) {
|
|
2109
2309
|
a.push(cursor.key);
|
|
2110
|
-
})
|
|
2310
|
+
})
|
|
2311
|
+
.then(function () {
|
|
2111
2312
|
return a;
|
|
2112
|
-
})
|
|
2313
|
+
})
|
|
2314
|
+
.then(cb);
|
|
2113
2315
|
};
|
|
2114
2316
|
Collection.prototype.primaryKeys = function (cb) {
|
|
2115
2317
|
var ctx = this._ctx;
|
|
@@ -2123,28 +2325,36 @@
|
|
|
2123
2325
|
direction: ctx.dir === 'prev' ? 'prev' : undefined,
|
|
2124
2326
|
query: {
|
|
2125
2327
|
index: index,
|
|
2126
|
-
range: ctx.range
|
|
2127
|
-
}
|
|
2328
|
+
range: ctx.range,
|
|
2329
|
+
},
|
|
2128
2330
|
});
|
|
2129
|
-
})
|
|
2331
|
+
})
|
|
2332
|
+
.then(function (_a) {
|
|
2130
2333
|
var result = _a.result;
|
|
2131
2334
|
return result;
|
|
2132
|
-
})
|
|
2335
|
+
})
|
|
2336
|
+
.then(cb);
|
|
2133
2337
|
}
|
|
2134
2338
|
ctx.keysOnly = !ctx.isMatch;
|
|
2135
2339
|
var a = [];
|
|
2136
2340
|
return this.each(function (item, cursor) {
|
|
2137
2341
|
a.push(cursor.primaryKey);
|
|
2138
|
-
})
|
|
2342
|
+
})
|
|
2343
|
+
.then(function () {
|
|
2139
2344
|
return a;
|
|
2140
|
-
})
|
|
2345
|
+
})
|
|
2346
|
+
.then(cb);
|
|
2141
2347
|
};
|
|
2142
2348
|
Collection.prototype.uniqueKeys = function (cb) {
|
|
2143
|
-
this._ctx.unique =
|
|
2349
|
+
this._ctx.unique = 'unique';
|
|
2144
2350
|
return this.keys(cb);
|
|
2145
2351
|
};
|
|
2146
2352
|
Collection.prototype.firstKey = function (cb) {
|
|
2147
|
-
return this.limit(1)
|
|
2353
|
+
return this.limit(1)
|
|
2354
|
+
.keys(function (a) {
|
|
2355
|
+
return a[0];
|
|
2356
|
+
})
|
|
2357
|
+
.then(cb);
|
|
2148
2358
|
};
|
|
2149
2359
|
Collection.prototype.lastKey = function (cb) {
|
|
2150
2360
|
return this.reverse().firstKey(cb);
|
|
@@ -2179,7 +2389,8 @@
|
|
|
2179
2389
|
var modifyChunkSize = _this.db._options.modifyChunkSize;
|
|
2180
2390
|
if (modifyChunkSize) {
|
|
2181
2391
|
if (typeof modifyChunkSize == 'object') {
|
|
2182
|
-
limit =
|
|
2392
|
+
limit =
|
|
2393
|
+
modifyChunkSize[coreTable.name] || modifyChunkSize['*'] || 200;
|
|
2183
2394
|
}
|
|
2184
2395
|
else {
|
|
2185
2396
|
limit = modifyChunkSize;
|
|
@@ -2197,21 +2408,25 @@
|
|
|
2197
2408
|
}
|
|
2198
2409
|
};
|
|
2199
2410
|
var isUnconditionalDelete = changes === deleteCallback;
|
|
2200
|
-
return _this.clone()
|
|
2411
|
+
return _this.clone()
|
|
2412
|
+
.primaryKeys()
|
|
2413
|
+
.then(function (keys) {
|
|
2201
2414
|
var criteria = isPlainKeyRange(ctx) &&
|
|
2202
2415
|
ctx.limit === Infinity &&
|
|
2203
2416
|
(typeof changes !== 'function' || isUnconditionalDelete) && {
|
|
2204
2417
|
index: ctx.index,
|
|
2205
|
-
range: ctx.range
|
|
2418
|
+
range: ctx.range,
|
|
2206
2419
|
};
|
|
2207
2420
|
var nextChunk = function (offset) {
|
|
2208
2421
|
var count = Math.min(limit, keys.length - offset);
|
|
2209
2422
|
var keysInChunk = keys.slice(offset, offset + count);
|
|
2210
|
-
return (isUnconditionalDelete
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2423
|
+
return (isUnconditionalDelete
|
|
2424
|
+
? Promise.resolve([])
|
|
2425
|
+
: coreTable.getMany({
|
|
2426
|
+
trans: trans,
|
|
2427
|
+
keys: keysInChunk,
|
|
2428
|
+
cache: 'immutable',
|
|
2429
|
+
})).then(function (values) {
|
|
2215
2430
|
var addValues = [];
|
|
2216
2431
|
var putValues = [];
|
|
2217
2432
|
var putKeys = outbound ? [] : null;
|
|
@@ -2221,13 +2436,14 @@
|
|
|
2221
2436
|
var origValue = values[i];
|
|
2222
2437
|
var ctx_1 = {
|
|
2223
2438
|
value: deepClone(origValue),
|
|
2224
|
-
primKey: keys[offset + i]
|
|
2439
|
+
primKey: keys[offset + i],
|
|
2225
2440
|
};
|
|
2226
2441
|
if (modifyer.call(ctx_1, ctx_1.value, ctx_1) !== false) {
|
|
2227
2442
|
if (ctx_1.value == null) {
|
|
2228
2443
|
deleteKeys.push(keys[offset + i]);
|
|
2229
2444
|
}
|
|
2230
|
-
else if (!outbound &&
|
|
2445
|
+
else if (!outbound &&
|
|
2446
|
+
cmp(extractKey(origValue), extractKey(ctx_1.value)) !== 0) {
|
|
2231
2447
|
deleteKeys.push(keys[offset + i]);
|
|
2232
2448
|
addValues.push(ctx_1.value);
|
|
2233
2449
|
}
|
|
@@ -2239,38 +2455,53 @@
|
|
|
2239
2455
|
}
|
|
2240
2456
|
}
|
|
2241
2457
|
return Promise.resolve(addValues.length > 0 &&
|
|
2242
|
-
coreTable
|
|
2458
|
+
coreTable
|
|
2459
|
+
.mutate({ trans: trans, type: 'add', values: addValues })
|
|
2243
2460
|
.then(function (res) {
|
|
2244
2461
|
for (var pos in res.failures) {
|
|
2245
2462
|
deleteKeys.splice(parseInt(pos), 1);
|
|
2246
2463
|
}
|
|
2247
2464
|
applyMutateResult(addValues.length, res);
|
|
2248
|
-
}))
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2465
|
+
}))
|
|
2466
|
+
.then(function () {
|
|
2467
|
+
return (putValues.length > 0 ||
|
|
2468
|
+
(criteria && typeof changes === 'object')) &&
|
|
2469
|
+
coreTable
|
|
2470
|
+
.mutate({
|
|
2471
|
+
trans: trans,
|
|
2472
|
+
type: 'put',
|
|
2473
|
+
keys: putKeys,
|
|
2474
|
+
values: putValues,
|
|
2475
|
+
criteria: criteria,
|
|
2476
|
+
changeSpec: typeof changes !== 'function' && changes,
|
|
2477
|
+
isAdditionalChunk: offset > 0,
|
|
2478
|
+
})
|
|
2479
|
+
.then(function (res) { return applyMutateResult(putValues.length, res); });
|
|
2480
|
+
})
|
|
2481
|
+
.then(function () {
|
|
2482
|
+
return (deleteKeys.length > 0 ||
|
|
2483
|
+
(criteria && isUnconditionalDelete)) &&
|
|
2484
|
+
coreTable
|
|
2485
|
+
.mutate({
|
|
2486
|
+
trans: trans,
|
|
2487
|
+
type: 'delete',
|
|
2488
|
+
keys: deleteKeys,
|
|
2489
|
+
criteria: criteria,
|
|
2490
|
+
isAdditionalChunk: offset > 0,
|
|
2491
|
+
})
|
|
2492
|
+
.then(function (res) {
|
|
2493
|
+
return builtInDeletionTrigger(ctx.table, deleteKeys, res);
|
|
2494
|
+
})
|
|
2495
|
+
.then(function (res) { return applyMutateResult(deleteKeys.length, res); });
|
|
2496
|
+
})
|
|
2497
|
+
.then(function () {
|
|
2498
|
+
return (keys.length > offset + count && nextChunk(offset + limit));
|
|
2268
2499
|
});
|
|
2269
2500
|
});
|
|
2270
2501
|
};
|
|
2271
2502
|
return nextChunk(0).then(function () {
|
|
2272
2503
|
if (totalFailures.length > 0)
|
|
2273
|
-
throw new ModifyError(
|
|
2504
|
+
throw new ModifyError('Error modifying one or more objects', totalFailures, successCount, failedKeys);
|
|
2274
2505
|
return keys.length;
|
|
2275
2506
|
});
|
|
2276
2507
|
});
|
|
@@ -2285,12 +2516,15 @@
|
|
|
2285
2516
|
return this._write(function (trans) {
|
|
2286
2517
|
var primaryKey = ctx.table.core.schema.primaryKey;
|
|
2287
2518
|
var coreRange = range;
|
|
2288
|
-
return ctx.table.core
|
|
2289
|
-
|
|
2519
|
+
return ctx.table.core
|
|
2520
|
+
.count({ trans: trans, query: { index: primaryKey, range: coreRange } })
|
|
2521
|
+
.then(function (count) {
|
|
2522
|
+
return ctx.table.core
|
|
2523
|
+
.mutate({ trans: trans, type: 'deleteRange', range: coreRange })
|
|
2290
2524
|
.then(function (_a) {
|
|
2291
2525
|
var failures = _a.failures, numFailures = _a.numFailures;
|
|
2292
2526
|
if (numFailures)
|
|
2293
|
-
throw new ModifyError(
|
|
2527
|
+
throw new ModifyError('Could not delete some values', Object.keys(failures).map(function (pos) { return failures[pos]; }), count - numFailures);
|
|
2294
2528
|
return count - numFailures;
|
|
2295
2529
|
});
|
|
2296
2530
|
});
|
|
@@ -2300,7 +2534,7 @@
|
|
|
2300
2534
|
};
|
|
2301
2535
|
return Collection;
|
|
2302
2536
|
}());
|
|
2303
|
-
var deleteCallback = function (value, ctx) { return ctx.value = null; };
|
|
2537
|
+
var deleteCallback = function (value, ctx) { return (ctx.value = null); };
|
|
2304
2538
|
|
|
2305
2539
|
function createCollectionConstructor(db) {
|
|
2306
2540
|
return makeClassConstructor(Collection.prototype, function Collection(whereClause, keyRangeGenerator) {
|
|
@@ -2319,11 +2553,13 @@
|
|
|
2319
2553
|
this._ctx = {
|
|
2320
2554
|
table: table,
|
|
2321
2555
|
index: whereCtx.index,
|
|
2322
|
-
isPrimKey:
|
|
2556
|
+
isPrimKey: !whereCtx.index ||
|
|
2557
|
+
(table.schema.primKey.keyPath &&
|
|
2558
|
+
whereCtx.index === table.schema.primKey.name),
|
|
2323
2559
|
range: keyRange,
|
|
2324
2560
|
keysOnly: false,
|
|
2325
|
-
dir:
|
|
2326
|
-
unique:
|
|
2561
|
+
dir: 'next',
|
|
2562
|
+
unique: '',
|
|
2327
2563
|
algorithm: null,
|
|
2328
2564
|
filter: null,
|
|
2329
2565
|
replayFilter: null,
|
|
@@ -2333,7 +2569,7 @@
|
|
|
2333
2569
|
limit: Infinity,
|
|
2334
2570
|
error: error,
|
|
2335
2571
|
or: whereCtx.or,
|
|
2336
|
-
valueMapper: readingHook !== mirror ? readingHook : null
|
|
2572
|
+
valueMapper: readingHook !== mirror ? readingHook : null,
|
|
2337
2573
|
};
|
|
2338
2574
|
});
|
|
2339
2575
|
}
|
|
@@ -2346,24 +2582,24 @@
|
|
|
2346
2582
|
}
|
|
2347
2583
|
|
|
2348
2584
|
function fail(collectionOrWhereClause, err, T) {
|
|
2349
|
-
var collection = collectionOrWhereClause instanceof WhereClause
|
|
2350
|
-
new collectionOrWhereClause.Collection(collectionOrWhereClause)
|
|
2351
|
-
collectionOrWhereClause;
|
|
2585
|
+
var collection = collectionOrWhereClause instanceof WhereClause
|
|
2586
|
+
? new collectionOrWhereClause.Collection(collectionOrWhereClause)
|
|
2587
|
+
: collectionOrWhereClause;
|
|
2352
2588
|
collection._ctx.error = T ? new T(err) : new TypeError(err);
|
|
2353
2589
|
return collection;
|
|
2354
2590
|
}
|
|
2355
2591
|
function emptyCollection(whereClause) {
|
|
2356
|
-
return new whereClause.Collection(whereClause, function () { return rangeEqual(
|
|
2592
|
+
return new whereClause.Collection(whereClause, function () { return rangeEqual(''); }).limit(0);
|
|
2357
2593
|
}
|
|
2358
2594
|
function upperFactory(dir) {
|
|
2359
|
-
return dir ===
|
|
2360
|
-
function (s) { return s.toUpperCase(); }
|
|
2361
|
-
function (s) { return s.toLowerCase(); };
|
|
2595
|
+
return dir === 'next'
|
|
2596
|
+
? function (s) { return s.toUpperCase(); }
|
|
2597
|
+
: function (s) { return s.toLowerCase(); };
|
|
2362
2598
|
}
|
|
2363
2599
|
function lowerFactory(dir) {
|
|
2364
|
-
return dir ===
|
|
2365
|
-
function (s) { return s.toLowerCase(); }
|
|
2366
|
-
function (s) { return s.toUpperCase(); };
|
|
2600
|
+
return dir === 'next'
|
|
2601
|
+
? function (s) { return s.toLowerCase(); }
|
|
2602
|
+
: function (s) { return s.toUpperCase(); };
|
|
2367
2603
|
}
|
|
2368
2604
|
function nextCasing(key, lowerKey, upperNeedle, lowerNeedle, cmp, dir) {
|
|
2369
2605
|
var length = Math.min(key.length, lowerNeedle.length);
|
|
@@ -2382,11 +2618,13 @@
|
|
|
2382
2618
|
if (cmp(key[i], lwrKeyChar) < 0)
|
|
2383
2619
|
llp = i;
|
|
2384
2620
|
}
|
|
2385
|
-
if (length < lowerNeedle.length && dir ===
|
|
2621
|
+
if (length < lowerNeedle.length && dir === 'next')
|
|
2386
2622
|
return key + upperNeedle.substr(key.length);
|
|
2387
|
-
if (length < key.length && dir ===
|
|
2623
|
+
if (length < key.length && dir === 'prev')
|
|
2388
2624
|
return key.substr(0, upperNeedle.length);
|
|
2389
|
-
return
|
|
2625
|
+
return llp < 0
|
|
2626
|
+
? null
|
|
2627
|
+
: key.substr(0, llp) + lowerNeedle[llp] + upperNeedle.substr(llp + 1);
|
|
2390
2628
|
}
|
|
2391
2629
|
function addIgnoreCaseAlgorithm(whereClause, match, needles, suffix) {
|
|
2392
2630
|
var upper, lower, compare, upperNeedles, lowerNeedles, direction, nextKeySuffix, needlesLen = needles.length;
|
|
@@ -2396,19 +2634,27 @@
|
|
|
2396
2634
|
function initDirection(dir) {
|
|
2397
2635
|
upper = upperFactory(dir);
|
|
2398
2636
|
lower = lowerFactory(dir);
|
|
2399
|
-
compare =
|
|
2400
|
-
var needleBounds = needles
|
|
2637
|
+
compare = dir === 'next' ? simpleCompare : simpleCompareReverse;
|
|
2638
|
+
var needleBounds = needles
|
|
2639
|
+
.map(function (needle) {
|
|
2401
2640
|
return { lower: lower(needle), upper: upper(needle) };
|
|
2402
|
-
})
|
|
2641
|
+
})
|
|
2642
|
+
.sort(function (a, b) {
|
|
2403
2643
|
return compare(a.lower, b.lower);
|
|
2404
2644
|
});
|
|
2405
|
-
upperNeedles = needleBounds.map(function (nb) {
|
|
2406
|
-
|
|
2645
|
+
upperNeedles = needleBounds.map(function (nb) {
|
|
2646
|
+
return nb.upper;
|
|
2647
|
+
});
|
|
2648
|
+
lowerNeedles = needleBounds.map(function (nb) {
|
|
2649
|
+
return nb.lower;
|
|
2650
|
+
});
|
|
2407
2651
|
direction = dir;
|
|
2408
|
-
nextKeySuffix =
|
|
2652
|
+
nextKeySuffix = dir === 'next' ? '' : suffix;
|
|
2409
2653
|
}
|
|
2410
|
-
initDirection(
|
|
2411
|
-
var c = new whereClause.Collection(whereClause, function () {
|
|
2654
|
+
initDirection('next');
|
|
2655
|
+
var c = new whereClause.Collection(whereClause, function () {
|
|
2656
|
+
return createRange(upperNeedles[0], lowerNeedles[needlesLen - 1] + suffix);
|
|
2657
|
+
});
|
|
2412
2658
|
c._ondirectionchange = function (direction) {
|
|
2413
2659
|
initDirection(direction);
|
|
2414
2660
|
};
|
|
@@ -2427,12 +2673,15 @@
|
|
|
2427
2673
|
var casing = nextCasing(key, lowerKey, upperNeedles[i], lowerNeedles[i], compare, direction);
|
|
2428
2674
|
if (casing === null && lowestPossibleCasing === null)
|
|
2429
2675
|
firstPossibleNeedle = i + 1;
|
|
2430
|
-
else if (lowestPossibleCasing === null ||
|
|
2676
|
+
else if (lowestPossibleCasing === null ||
|
|
2677
|
+
compare(lowestPossibleCasing, casing) > 0) {
|
|
2431
2678
|
lowestPossibleCasing = casing;
|
|
2432
2679
|
}
|
|
2433
2680
|
}
|
|
2434
2681
|
if (lowestPossibleCasing !== null) {
|
|
2435
|
-
advance(function () {
|
|
2682
|
+
advance(function () {
|
|
2683
|
+
cursor.continue(lowestPossibleCasing + nextKeySuffix);
|
|
2684
|
+
});
|
|
2436
2685
|
}
|
|
2437
2686
|
else {
|
|
2438
2687
|
advance(resolve);
|
|
@@ -2448,14 +2697,14 @@
|
|
|
2448
2697
|
lower: lower,
|
|
2449
2698
|
upper: upper,
|
|
2450
2699
|
lowerOpen: lowerOpen,
|
|
2451
|
-
upperOpen: upperOpen
|
|
2700
|
+
upperOpen: upperOpen,
|
|
2452
2701
|
};
|
|
2453
2702
|
}
|
|
2454
2703
|
function rangeEqual(value) {
|
|
2455
2704
|
return {
|
|
2456
2705
|
type: 1 ,
|
|
2457
2706
|
lower: value,
|
|
2458
|
-
upper: value
|
|
2707
|
+
upper: value,
|
|
2459
2708
|
};
|
|
2460
2709
|
}
|
|
2461
2710
|
|
|
@@ -2473,10 +2722,14 @@
|
|
|
2473
2722
|
includeLower = includeLower !== false;
|
|
2474
2723
|
includeUpper = includeUpper === true;
|
|
2475
2724
|
try {
|
|
2476
|
-
if (
|
|
2477
|
-
(this._cmp(lower, upper) === 0 &&
|
|
2725
|
+
if (this._cmp(lower, upper) > 0 ||
|
|
2726
|
+
(this._cmp(lower, upper) === 0 &&
|
|
2727
|
+
(includeLower || includeUpper) &&
|
|
2728
|
+
!(includeLower && includeUpper)))
|
|
2478
2729
|
return emptyCollection(this);
|
|
2479
|
-
return new this.Collection(this, function () {
|
|
2730
|
+
return new this.Collection(this, function () {
|
|
2731
|
+
return createRange(lower, upper, !includeLower, !includeUpper);
|
|
2732
|
+
});
|
|
2480
2733
|
}
|
|
2481
2734
|
catch (e) {
|
|
2482
2735
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
@@ -2495,12 +2748,16 @@
|
|
|
2495
2748
|
WhereClause.prototype.aboveOrEqual = function (value) {
|
|
2496
2749
|
if (value == null)
|
|
2497
2750
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
2498
|
-
return new this.Collection(this, function () {
|
|
2751
|
+
return new this.Collection(this, function () {
|
|
2752
|
+
return createRange(value, undefined, false);
|
|
2753
|
+
});
|
|
2499
2754
|
};
|
|
2500
2755
|
WhereClause.prototype.below = function (value) {
|
|
2501
2756
|
if (value == null)
|
|
2502
2757
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
2503
|
-
return new this.Collection(this, function () {
|
|
2758
|
+
return new this.Collection(this, function () {
|
|
2759
|
+
return createRange(undefined, value, false, true);
|
|
2760
|
+
});
|
|
2504
2761
|
};
|
|
2505
2762
|
WhereClause.prototype.belowOrEqual = function (value) {
|
|
2506
2763
|
if (value == null)
|
|
@@ -2513,18 +2770,18 @@
|
|
|
2513
2770
|
return this.between(str, str + maxString, true, true);
|
|
2514
2771
|
};
|
|
2515
2772
|
WhereClause.prototype.startsWithIgnoreCase = function (str) {
|
|
2516
|
-
if (str ===
|
|
2773
|
+
if (str === '')
|
|
2517
2774
|
return this.startsWith(str);
|
|
2518
2775
|
return addIgnoreCaseAlgorithm(this, function (x, a) { return x.indexOf(a[0]) === 0; }, [str], maxString);
|
|
2519
2776
|
};
|
|
2520
2777
|
WhereClause.prototype.equalsIgnoreCase = function (str) {
|
|
2521
|
-
return addIgnoreCaseAlgorithm(this, function (x, a) { return x === a[0]; }, [str],
|
|
2778
|
+
return addIgnoreCaseAlgorithm(this, function (x, a) { return x === a[0]; }, [str], '');
|
|
2522
2779
|
};
|
|
2523
2780
|
WhereClause.prototype.anyOfIgnoreCase = function () {
|
|
2524
2781
|
var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
2525
2782
|
if (set.length === 0)
|
|
2526
2783
|
return emptyCollection(this);
|
|
2527
|
-
return addIgnoreCaseAlgorithm(this, function (x, a) { return a.indexOf(x) !== -1; }, set,
|
|
2784
|
+
return addIgnoreCaseAlgorithm(this, function (x, a) { return a.indexOf(x) !== -1; }, set, '');
|
|
2528
2785
|
};
|
|
2529
2786
|
WhereClause.prototype.startsWithAnyOfIgnoreCase = function () {
|
|
2530
2787
|
var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
@@ -2544,11 +2801,11 @@
|
|
|
2544
2801
|
}
|
|
2545
2802
|
if (set.length === 0)
|
|
2546
2803
|
return emptyCollection(this);
|
|
2547
|
-
var c = new this.Collection(this, function () {
|
|
2804
|
+
var c = new this.Collection(this, function () {
|
|
2805
|
+
return createRange(set[0], set[set.length - 1]);
|
|
2806
|
+
});
|
|
2548
2807
|
c._ondirectionchange = function (direction) {
|
|
2549
|
-
compare =
|
|
2550
|
-
_this._ascending :
|
|
2551
|
-
_this._descending);
|
|
2808
|
+
compare = direction === 'next' ? _this._ascending : _this._descending;
|
|
2552
2809
|
set.sort(compare);
|
|
2553
2810
|
};
|
|
2554
2811
|
var i = 0;
|
|
@@ -2565,14 +2822,19 @@
|
|
|
2565
2822
|
return true;
|
|
2566
2823
|
}
|
|
2567
2824
|
else {
|
|
2568
|
-
advance(function () {
|
|
2825
|
+
advance(function () {
|
|
2826
|
+
cursor.continue(set[i]);
|
|
2827
|
+
});
|
|
2569
2828
|
return false;
|
|
2570
2829
|
}
|
|
2571
2830
|
});
|
|
2572
2831
|
return c;
|
|
2573
2832
|
};
|
|
2574
2833
|
WhereClause.prototype.notEqual = function (value) {
|
|
2575
|
-
return this.inAnyRange([
|
|
2834
|
+
return this.inAnyRange([
|
|
2835
|
+
[minKey, value],
|
|
2836
|
+
[value, this.db._maxKey],
|
|
2837
|
+
], { includeLowers: false, includeUppers: false });
|
|
2576
2838
|
};
|
|
2577
2839
|
WhereClause.prototype.noneOf = function () {
|
|
2578
2840
|
var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
@@ -2584,11 +2846,14 @@
|
|
|
2584
2846
|
catch (e) {
|
|
2585
2847
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
2586
2848
|
}
|
|
2587
|
-
var ranges = set.reduce(function (res, val) {
|
|
2588
|
-
res.concat([[res[res.length - 1][1], val]]) :
|
|
2589
|
-
|
|
2849
|
+
var ranges = set.reduce(function (res, val) {
|
|
2850
|
+
return res ? res.concat([[res[res.length - 1][1], val]]) : [[minKey, val]];
|
|
2851
|
+
}, null);
|
|
2590
2852
|
ranges.push([set[set.length - 1], this.db._maxKey]);
|
|
2591
|
-
return this.inAnyRange(ranges, {
|
|
2853
|
+
return this.inAnyRange(ranges, {
|
|
2854
|
+
includeLowers: false,
|
|
2855
|
+
includeUppers: false,
|
|
2856
|
+
});
|
|
2592
2857
|
};
|
|
2593
2858
|
WhereClause.prototype.inAnyRange = function (ranges, options) {
|
|
2594
2859
|
var _this = this;
|
|
@@ -2600,7 +2865,7 @@
|
|
|
2600
2865
|
range[1] !== undefined &&
|
|
2601
2866
|
ascending(range[0], range[1]) <= 0;
|
|
2602
2867
|
})) {
|
|
2603
|
-
return fail(this,
|
|
2868
|
+
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);
|
|
2604
2869
|
}
|
|
2605
2870
|
var includeLowers = !options || options.includeLowers !== false;
|
|
2606
2871
|
var includeUppers = options && options.includeUppers === true;
|
|
@@ -2619,7 +2884,9 @@
|
|
|
2619
2884
|
return ranges;
|
|
2620
2885
|
}
|
|
2621
2886
|
var sortDirection = ascending;
|
|
2622
|
-
function rangeSorter(a, b) {
|
|
2887
|
+
function rangeSorter(a, b) {
|
|
2888
|
+
return sortDirection(a[0], b[0]);
|
|
2889
|
+
}
|
|
2623
2890
|
var set;
|
|
2624
2891
|
try {
|
|
2625
2892
|
set = ranges.reduce(addRange, []);
|
|
@@ -2629,19 +2896,21 @@
|
|
|
2629
2896
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
2630
2897
|
}
|
|
2631
2898
|
var rangePos = 0;
|
|
2632
|
-
var keyIsBeyondCurrentEntry = includeUppers
|
|
2633
|
-
function (key) { return ascending(key, set[rangePos][1]) > 0; }
|
|
2634
|
-
function (key) { return ascending(key, set[rangePos][1]) >= 0; };
|
|
2635
|
-
var keyIsBeforeCurrentEntry = includeLowers
|
|
2636
|
-
function (key) { return descending(key, set[rangePos][0]) > 0; }
|
|
2637
|
-
function (key) { return descending(key, set[rangePos][0]) >= 0; };
|
|
2899
|
+
var keyIsBeyondCurrentEntry = includeUppers
|
|
2900
|
+
? function (key) { return ascending(key, set[rangePos][1]) > 0; }
|
|
2901
|
+
: function (key) { return ascending(key, set[rangePos][1]) >= 0; };
|
|
2902
|
+
var keyIsBeforeCurrentEntry = includeLowers
|
|
2903
|
+
? function (key) { return descending(key, set[rangePos][0]) > 0; }
|
|
2904
|
+
: function (key) { return descending(key, set[rangePos][0]) >= 0; };
|
|
2638
2905
|
function keyWithinCurrentRange(key) {
|
|
2639
2906
|
return !keyIsBeyondCurrentEntry(key) && !keyIsBeforeCurrentEntry(key);
|
|
2640
2907
|
}
|
|
2641
2908
|
var checkKey = keyIsBeyondCurrentEntry;
|
|
2642
|
-
var c = new this.Collection(this, function () {
|
|
2909
|
+
var c = new this.Collection(this, function () {
|
|
2910
|
+
return createRange(set[0][0], set[set.length - 1][1], !includeLowers, !includeUppers);
|
|
2911
|
+
});
|
|
2643
2912
|
c._ondirectionchange = function (direction) {
|
|
2644
|
-
if (direction ===
|
|
2913
|
+
if (direction === 'next') {
|
|
2645
2914
|
checkKey = keyIsBeyondCurrentEntry;
|
|
2646
2915
|
sortDirection = ascending;
|
|
2647
2916
|
}
|
|
@@ -2663,7 +2932,8 @@
|
|
|
2663
2932
|
if (keyWithinCurrentRange(key)) {
|
|
2664
2933
|
return true;
|
|
2665
2934
|
}
|
|
2666
|
-
else if (_this._cmp(key, set[rangePos][1]) === 0 ||
|
|
2935
|
+
else if (_this._cmp(key, set[rangePos][1]) === 0 ||
|
|
2936
|
+
_this._cmp(key, set[rangePos][0]) === 0) {
|
|
2667
2937
|
return false;
|
|
2668
2938
|
}
|
|
2669
2939
|
else {
|
|
@@ -2681,7 +2951,7 @@
|
|
|
2681
2951
|
WhereClause.prototype.startsWithAnyOf = function () {
|
|
2682
2952
|
var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
2683
2953
|
if (!set.every(function (s) { return typeof s === 'string'; })) {
|
|
2684
|
-
return fail(this,
|
|
2954
|
+
return fail(this, 'startsWithAnyOf() only works with strings');
|
|
2685
2955
|
}
|
|
2686
2956
|
if (set.length === 0)
|
|
2687
2957
|
return emptyCollection(this);
|
|
@@ -2695,13 +2965,13 @@
|
|
|
2695
2965
|
this.db = db;
|
|
2696
2966
|
this._ctx = {
|
|
2697
2967
|
table: table,
|
|
2698
|
-
index: index ===
|
|
2699
|
-
or: orCollection
|
|
2968
|
+
index: index === ':id' ? null : index,
|
|
2969
|
+
or: orCollection,
|
|
2700
2970
|
};
|
|
2701
2971
|
this._cmp = this._ascending = cmp;
|
|
2702
2972
|
this._descending = function (a, b) { return cmp(b, a); };
|
|
2703
|
-
this._max = function (a, b) { return cmp(a, b) > 0 ? a : b; };
|
|
2704
|
-
this._min = function (a, b) { return cmp(a, b) < 0 ? a : b; };
|
|
2973
|
+
this._max = function (a, b) { return (cmp(a, b) > 0 ? a : b); };
|
|
2974
|
+
this._min = function (a, b) { return (cmp(a, b) < 0 ? a : b); };
|
|
2705
2975
|
this._IDBKeyRange = db._deps.IDBKeyRange;
|
|
2706
2976
|
if (!this._IDBKeyRange)
|
|
2707
2977
|
throw new exceptions.MissingAPI();
|
|
@@ -2763,9 +3033,9 @@
|
|
|
2763
3033
|
assert(!this.idbtrans);
|
|
2764
3034
|
if (!idbtrans && !idbdb) {
|
|
2765
3035
|
switch (dbOpenError && dbOpenError.name) {
|
|
2766
|
-
case
|
|
3036
|
+
case 'DatabaseClosedError':
|
|
2767
3037
|
throw new exceptions.DatabaseClosed(dbOpenError);
|
|
2768
|
-
case
|
|
3038
|
+
case 'MissingAPIError':
|
|
2769
3039
|
throw new exceptions.MissingAPI(dbOpenError.message, dbOpenError);
|
|
2770
3040
|
default:
|
|
2771
3041
|
throw new exceptions.OpenFailed(dbOpenError);
|
|
@@ -2774,10 +3044,13 @@
|
|
|
2774
3044
|
if (!this.active)
|
|
2775
3045
|
throw new exceptions.TransactionInactive();
|
|
2776
3046
|
assert(this._completion._state === null);
|
|
2777
|
-
idbtrans = this.idbtrans =
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
3047
|
+
idbtrans = this.idbtrans =
|
|
3048
|
+
idbtrans ||
|
|
3049
|
+
(this.db.core
|
|
3050
|
+
? this.db.core.transaction(this.storeNames, this.mode, { durability: this.chromeTransactionDurability })
|
|
3051
|
+
: idbdb.transaction(this.storeNames, this.mode, {
|
|
3052
|
+
durability: this.chromeTransactionDurability,
|
|
3053
|
+
}));
|
|
2781
3054
|
idbtrans.onerror = wrap(function (ev) {
|
|
2782
3055
|
preventDefault(ev);
|
|
2783
3056
|
_this._reject(idbtrans.error);
|
|
@@ -2786,13 +3059,13 @@
|
|
|
2786
3059
|
preventDefault(ev);
|
|
2787
3060
|
_this.active && _this._reject(new exceptions.Abort(idbtrans.error));
|
|
2788
3061
|
_this.active = false;
|
|
2789
|
-
_this.on(
|
|
3062
|
+
_this.on('abort').fire(ev);
|
|
2790
3063
|
});
|
|
2791
3064
|
idbtrans.oncomplete = wrap(function () {
|
|
2792
3065
|
_this.active = false;
|
|
2793
3066
|
_this._resolve();
|
|
2794
3067
|
if ('mutatedParts' in idbtrans) {
|
|
2795
|
-
globalEvents.storagemutated.fire(idbtrans[
|
|
3068
|
+
globalEvents.storagemutated.fire(idbtrans['mutatedParts']);
|
|
2796
3069
|
}
|
|
2797
3070
|
});
|
|
2798
3071
|
return this;
|
|
@@ -2800,14 +3073,17 @@
|
|
|
2800
3073
|
Transaction.prototype._promise = function (mode, fn, bWriteLock) {
|
|
2801
3074
|
var _this = this;
|
|
2802
3075
|
if (mode === 'readwrite' && this.mode !== 'readwrite')
|
|
2803
|
-
return rejection(new exceptions.ReadOnly(
|
|
3076
|
+
return rejection(new exceptions.ReadOnly('Transaction is readonly'));
|
|
2804
3077
|
if (!this.active)
|
|
2805
3078
|
return rejection(new exceptions.TransactionInactive());
|
|
2806
3079
|
if (this._locked()) {
|
|
2807
3080
|
return new DexiePromise(function (resolve, reject) {
|
|
2808
|
-
_this._blockedFuncs.push([
|
|
3081
|
+
_this._blockedFuncs.push([
|
|
3082
|
+
function () {
|
|
2809
3083
|
_this._promise(mode, fn, bWriteLock).then(resolve, reject);
|
|
2810
|
-
},
|
|
3084
|
+
},
|
|
3085
|
+
PSD,
|
|
3086
|
+
]);
|
|
2811
3087
|
});
|
|
2812
3088
|
}
|
|
2813
3089
|
else if (bWriteLock) {
|
|
@@ -2849,14 +3125,16 @@
|
|
|
2849
3125
|
(function spin() {
|
|
2850
3126
|
++root._spinCount;
|
|
2851
3127
|
while (root._waitingQueue.length)
|
|
2852
|
-
|
|
3128
|
+
root._waitingQueue.shift()();
|
|
2853
3129
|
if (root._waitingFor)
|
|
2854
3130
|
store.get(-Infinity).onsuccess = spin;
|
|
2855
|
-
}()
|
|
3131
|
+
})();
|
|
2856
3132
|
}
|
|
2857
3133
|
var currentWaitPromise = root._waitingFor;
|
|
2858
3134
|
return new DexiePromise(function (resolve, reject) {
|
|
2859
|
-
promise
|
|
3135
|
+
promise
|
|
3136
|
+
.then(function (res) { return root._waitingQueue.push(wrap(resolve.bind(null, res))); }, function (err) { return root._waitingQueue.push(wrap(reject.bind(null, err))); })
|
|
3137
|
+
.finally(function () {
|
|
2860
3138
|
if (root._waitingFor === currentWaitPromise) {
|
|
2861
3139
|
root._waitingFor = null;
|
|
2862
3140
|
}
|
|
@@ -2872,12 +3150,12 @@
|
|
|
2872
3150
|
}
|
|
2873
3151
|
};
|
|
2874
3152
|
Transaction.prototype.table = function (tableName) {
|
|
2875
|
-
var memoizedTables =
|
|
3153
|
+
var memoizedTables = this._memoizedTables || (this._memoizedTables = {});
|
|
2876
3154
|
if (hasOwn(memoizedTables, tableName))
|
|
2877
3155
|
return memoizedTables[tableName];
|
|
2878
3156
|
var tableSchema = this.schema[tableName];
|
|
2879
3157
|
if (!tableSchema) {
|
|
2880
|
-
throw new exceptions.NotFound(
|
|
3158
|
+
throw new exceptions.NotFound('Table ' + tableName + ' not part of transaction');
|
|
2881
3159
|
}
|
|
2882
3160
|
var transactionBoundTable = new this.db.Table(tableName, tableSchema, this);
|
|
2883
3161
|
transactionBoundTable.core = this.db.core.table(tableName);
|
|
@@ -2903,7 +3181,7 @@
|
|
|
2903
3181
|
this.schema = dbschema;
|
|
2904
3182
|
this.chromeTransactionDurability = chromeTransactionDurability;
|
|
2905
3183
|
this.idbtrans = null;
|
|
2906
|
-
this.on = Events(this,
|
|
3184
|
+
this.on = Events(this, 'complete', 'error', 'abort');
|
|
2907
3185
|
this.parent = parent || null;
|
|
2908
3186
|
this.active = true;
|
|
2909
3187
|
this._reculock = 0;
|
|
@@ -2924,9 +3202,9 @@
|
|
|
2924
3202
|
var wasActive = _this.active;
|
|
2925
3203
|
_this.active = false;
|
|
2926
3204
|
_this.on.error.fire(e);
|
|
2927
|
-
_this.parent
|
|
2928
|
-
_this.parent._reject(e)
|
|
2929
|
-
wasActive && _this.idbtrans && _this.idbtrans.abort();
|
|
3205
|
+
_this.parent
|
|
3206
|
+
? _this.parent._reject(e)
|
|
3207
|
+
: wasActive && _this.idbtrans && _this.idbtrans.abort();
|
|
2930
3208
|
return rejection(e);
|
|
2931
3209
|
});
|
|
2932
3210
|
});
|
|
@@ -2940,14 +3218,19 @@
|
|
|
2940
3218
|
multi: multi,
|
|
2941
3219
|
auto: auto,
|
|
2942
3220
|
compound: compound,
|
|
2943
|
-
src: (unique && !isPrimKey ? '&' : '') +
|
|
2944
|
-
|
|
3221
|
+
src: (unique && !isPrimKey ? '&' : '') +
|
|
3222
|
+
(multi ? '*' : '') +
|
|
3223
|
+
(auto ? '++' : '') +
|
|
3224
|
+
nameFromKeyPath(keyPath),
|
|
3225
|
+
type: type,
|
|
2945
3226
|
};
|
|
2946
3227
|
}
|
|
2947
3228
|
function nameFromKeyPath(keyPath) {
|
|
2948
|
-
return typeof keyPath === 'string'
|
|
2949
|
-
keyPath
|
|
2950
|
-
|
|
3229
|
+
return typeof keyPath === 'string'
|
|
3230
|
+
? keyPath
|
|
3231
|
+
: keyPath
|
|
3232
|
+
? '[' + [].join.call(keyPath, '+') + ']'
|
|
3233
|
+
: '';
|
|
2951
3234
|
}
|
|
2952
3235
|
|
|
2953
3236
|
function createTableSchema(name, primKey, indexes) {
|
|
@@ -3001,22 +3284,22 @@
|
|
|
3001
3284
|
}
|
|
3002
3285
|
var _id_counter = 0;
|
|
3003
3286
|
function getKeyPathAlias(keyPath) {
|
|
3004
|
-
return keyPath == null
|
|
3005
|
-
|
|
3006
|
-
typeof keyPath === 'string'
|
|
3007
|
-
keyPath
|
|
3008
|
-
"[".concat(keyPath.join('+'), "]");
|
|
3287
|
+
return keyPath == null
|
|
3288
|
+
? ':id'
|
|
3289
|
+
: typeof keyPath === 'string'
|
|
3290
|
+
? keyPath
|
|
3291
|
+
: "[".concat(keyPath.join('+'), "]");
|
|
3009
3292
|
}
|
|
3010
3293
|
function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
3011
3294
|
function extractSchema(db, trans) {
|
|
3012
3295
|
var tables = arrayify(db.objectStoreNames);
|
|
3013
|
-
var tempStore = tables.length > 0
|
|
3014
|
-
? trans.objectStore(tables[0])
|
|
3015
|
-
: {};
|
|
3296
|
+
var tempStore = tables.length > 0 ? trans.objectStore(tables[0]) : {};
|
|
3016
3297
|
return {
|
|
3017
3298
|
schema: {
|
|
3018
3299
|
name: db.name,
|
|
3019
|
-
tables: tables
|
|
3300
|
+
tables: tables
|
|
3301
|
+
.map(function (table) { return trans.objectStore(table); })
|
|
3302
|
+
.map(function (store) {
|
|
3020
3303
|
var keyPath = store.keyPath, autoIncrement = store.autoIncrement;
|
|
3021
3304
|
var compound = isArray(keyPath);
|
|
3022
3305
|
var outbound = keyPath == null;
|
|
@@ -3031,9 +3314,10 @@
|
|
|
3031
3314
|
keyPath: keyPath,
|
|
3032
3315
|
autoIncrement: autoIncrement,
|
|
3033
3316
|
unique: true,
|
|
3034
|
-
extractKey: getKeyExtractor(keyPath)
|
|
3317
|
+
extractKey: getKeyExtractor(keyPath),
|
|
3035
3318
|
},
|
|
3036
|
-
indexes: arrayify(store.indexNames)
|
|
3319
|
+
indexes: arrayify(store.indexNames)
|
|
3320
|
+
.map(function (indexName) { return store.index(indexName); })
|
|
3037
3321
|
.map(function (index) {
|
|
3038
3322
|
var name = index.name, unique = index.unique, multiEntry = index.multiEntry, keyPath = index.keyPath;
|
|
3039
3323
|
var compound = isArray(keyPath);
|
|
@@ -3043,40 +3327,44 @@
|
|
|
3043
3327
|
keyPath: keyPath,
|
|
3044
3328
|
unique: unique,
|
|
3045
3329
|
multiEntry: multiEntry,
|
|
3046
|
-
extractKey: getKeyExtractor(keyPath)
|
|
3330
|
+
extractKey: getKeyExtractor(keyPath),
|
|
3047
3331
|
};
|
|
3048
3332
|
indexByKeyPath[getKeyPathAlias(keyPath)] = result;
|
|
3049
3333
|
return result;
|
|
3050
3334
|
}),
|
|
3051
|
-
getIndexByKeyPath: function (keyPath) {
|
|
3335
|
+
getIndexByKeyPath: function (keyPath) {
|
|
3336
|
+
return indexByKeyPath[getKeyPathAlias(keyPath)];
|
|
3337
|
+
},
|
|
3052
3338
|
};
|
|
3053
|
-
indexByKeyPath[
|
|
3339
|
+
indexByKeyPath[':id'] = result.primaryKey;
|
|
3054
3340
|
if (keyPath != null) {
|
|
3055
3341
|
indexByKeyPath[getKeyPathAlias(keyPath)] = result.primaryKey;
|
|
3056
3342
|
}
|
|
3057
3343
|
return result;
|
|
3058
|
-
})
|
|
3344
|
+
}),
|
|
3059
3345
|
},
|
|
3060
|
-
hasGetAll: tables.length > 0 &&
|
|
3061
|
-
|
|
3346
|
+
hasGetAll: tables.length > 0 &&
|
|
3347
|
+
'getAll' in tempStore &&
|
|
3348
|
+
!(typeof navigator !== 'undefined' &&
|
|
3349
|
+
/Safari/.test(navigator.userAgent) &&
|
|
3062
3350
|
!/(Chrome\/|Edge\/)/.test(navigator.userAgent) &&
|
|
3063
3351
|
[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604),
|
|
3064
|
-
hasIdb3Features: 'getAllRecords' in tempStore
|
|
3352
|
+
hasIdb3Features: 'getAllRecords' in tempStore,
|
|
3065
3353
|
};
|
|
3066
3354
|
}
|
|
3067
3355
|
function makeIDBKeyRange(range) {
|
|
3068
3356
|
if (range.type === 3 )
|
|
3069
3357
|
return null;
|
|
3070
3358
|
if (range.type === 4 )
|
|
3071
|
-
throw new Error(
|
|
3359
|
+
throw new Error('Cannot convert never type to IDBKeyRange');
|
|
3072
3360
|
var lower = range.lower, upper = range.upper, lowerOpen = range.lowerOpen, upperOpen = range.upperOpen;
|
|
3073
|
-
var idbRange = lower === undefined
|
|
3074
|
-
upper === undefined
|
|
3075
|
-
null
|
|
3076
|
-
IdbKeyRange.upperBound(upper, !!upperOpen)
|
|
3077
|
-
upper === undefined
|
|
3078
|
-
IdbKeyRange.lowerBound(lower, !!lowerOpen)
|
|
3079
|
-
IdbKeyRange.bound(lower, upper, !!lowerOpen, !!upperOpen);
|
|
3361
|
+
var idbRange = lower === undefined
|
|
3362
|
+
? upper === undefined
|
|
3363
|
+
? null
|
|
3364
|
+
: IdbKeyRange.upperBound(upper, !!upperOpen)
|
|
3365
|
+
: upper === undefined
|
|
3366
|
+
? IdbKeyRange.lowerBound(lower, !!lowerOpen)
|
|
3367
|
+
: IdbKeyRange.bound(lower, upper, !!lowerOpen, !!upperOpen);
|
|
3080
3368
|
return idbRange;
|
|
3081
3369
|
}
|
|
3082
3370
|
function createDbCoreTable(tableSchema) {
|
|
@@ -3087,15 +3375,20 @@
|
|
|
3087
3375
|
resolve = wrap(resolve);
|
|
3088
3376
|
var store = trans.objectStore(tableName);
|
|
3089
3377
|
var outbound = store.keyPath == null;
|
|
3090
|
-
var isAddOrPut = type ===
|
|
3378
|
+
var isAddOrPut = type === 'put' || type === 'add';
|
|
3091
3379
|
if (!isAddOrPut && type !== 'delete' && type !== 'deleteRange')
|
|
3092
|
-
throw new Error(
|
|
3380
|
+
throw new Error('Invalid operation type: ' + type);
|
|
3093
3381
|
var length = (keys || values || { length: 1 }).length;
|
|
3094
3382
|
if (keys && values && keys.length !== values.length) {
|
|
3095
|
-
throw new Error(
|
|
3383
|
+
throw new Error('Given keys array must have same length as given values array.');
|
|
3096
3384
|
}
|
|
3097
3385
|
if (length === 0)
|
|
3098
|
-
return resolve({
|
|
3386
|
+
return resolve({
|
|
3387
|
+
numFailures: 0,
|
|
3388
|
+
failures: {},
|
|
3389
|
+
results: [],
|
|
3390
|
+
lastResult: undefined,
|
|
3391
|
+
});
|
|
3099
3392
|
var req;
|
|
3100
3393
|
var reqs = [];
|
|
3101
3394
|
var failures = [];
|
|
@@ -3106,29 +3399,34 @@
|
|
|
3106
3399
|
};
|
|
3107
3400
|
if (type === 'deleteRange') {
|
|
3108
3401
|
if (range.type === 4 )
|
|
3109
|
-
return resolve({
|
|
3402
|
+
return resolve({
|
|
3403
|
+
numFailures: numFailures,
|
|
3404
|
+
failures: failures,
|
|
3405
|
+
results: [],
|
|
3406
|
+
lastResult: undefined,
|
|
3407
|
+
});
|
|
3110
3408
|
if (range.type === 3 )
|
|
3111
|
-
reqs.push(req = store.clear());
|
|
3409
|
+
reqs.push((req = store.clear()));
|
|
3112
3410
|
else
|
|
3113
|
-
reqs.push(req = store.delete(makeIDBKeyRange(range)));
|
|
3411
|
+
reqs.push((req = store.delete(makeIDBKeyRange(range))));
|
|
3114
3412
|
}
|
|
3115
3413
|
else {
|
|
3116
|
-
var _a = isAddOrPut
|
|
3117
|
-
outbound
|
|
3118
|
-
[values, keys]
|
|
3119
|
-
[values, null]
|
|
3120
|
-
[keys, null], args1 = _a[0], args2 = _a[1];
|
|
3414
|
+
var _a = isAddOrPut
|
|
3415
|
+
? outbound
|
|
3416
|
+
? [values, keys]
|
|
3417
|
+
: [values, null]
|
|
3418
|
+
: [keys, null], args1 = _a[0], args2 = _a[1];
|
|
3121
3419
|
if (isAddOrPut) {
|
|
3122
3420
|
for (var i = 0; i < length; ++i) {
|
|
3123
|
-
reqs.push(req = (args2 && args2[i] !== undefined
|
|
3124
|
-
store[type](args1[i], args2[i])
|
|
3125
|
-
store[type](args1[i])));
|
|
3421
|
+
reqs.push((req = (args2 && args2[i] !== undefined
|
|
3422
|
+
? store[type](args1[i], args2[i])
|
|
3423
|
+
: store[type](args1[i]))));
|
|
3126
3424
|
req.onerror = errorHandler;
|
|
3127
3425
|
}
|
|
3128
3426
|
}
|
|
3129
3427
|
else {
|
|
3130
3428
|
for (var i = 0; i < length; ++i) {
|
|
3131
|
-
reqs.push(req = store[type](args1[i]));
|
|
3429
|
+
reqs.push((req = store[type](args1[i])));
|
|
3132
3430
|
req.onerror = errorHandler;
|
|
3133
3431
|
}
|
|
3134
3432
|
}
|
|
@@ -3139,8 +3437,8 @@
|
|
|
3139
3437
|
resolve({
|
|
3140
3438
|
numFailures: numFailures,
|
|
3141
3439
|
failures: failures,
|
|
3142
|
-
results: type ===
|
|
3143
|
-
lastResult: lastResult
|
|
3440
|
+
results: type === 'delete' ? keys : reqs.map(function (req) { return req.result; }),
|
|
3441
|
+
lastResult: lastResult,
|
|
3144
3442
|
});
|
|
3145
3443
|
};
|
|
3146
3444
|
req.onerror = function (event) {
|
|
@@ -3156,19 +3454,17 @@
|
|
|
3156
3454
|
resolve = wrap(resolve);
|
|
3157
3455
|
var index = query.index, range = query.range;
|
|
3158
3456
|
var store = trans.objectStore(tableName);
|
|
3159
|
-
var source = index.isPrimaryKey ?
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
source.openCursor(makeIDBKeyRange(range), direction) :
|
|
3171
|
-
source.openKeyCursor(makeIDBKeyRange(range), direction);
|
|
3457
|
+
var source = index.isPrimaryKey ? store : store.index(index.name);
|
|
3458
|
+
var direction = reverse
|
|
3459
|
+
? unique
|
|
3460
|
+
? 'prevunique'
|
|
3461
|
+
: 'prev'
|
|
3462
|
+
: unique
|
|
3463
|
+
? 'nextunique'
|
|
3464
|
+
: 'next';
|
|
3465
|
+
var req = values || !('openKeyCursor' in source)
|
|
3466
|
+
? source.openCursor(makeIDBKeyRange(range), direction)
|
|
3467
|
+
: source.openKeyCursor(makeIDBKeyRange(range), direction);
|
|
3172
3468
|
req.onerror = eventRejectHandler(reject);
|
|
3173
3469
|
req.onsuccess = wrap(function (ev) {
|
|
3174
3470
|
var cursor = req.result;
|
|
@@ -3183,15 +3479,25 @@
|
|
|
3183
3479
|
if (_cursorContinuePrimaryKey)
|
|
3184
3480
|
_cursorContinuePrimaryKey = _cursorContinuePrimaryKey.bind(cursor);
|
|
3185
3481
|
var _cursorAdvance = cursor.advance.bind(cursor);
|
|
3186
|
-
var doThrowCursorIsNotStarted = function () {
|
|
3187
|
-
|
|
3482
|
+
var doThrowCursorIsNotStarted = function () {
|
|
3483
|
+
throw new Error('Cursor not started');
|
|
3484
|
+
};
|
|
3485
|
+
var doThrowCursorIsStopped = function () {
|
|
3486
|
+
throw new Error('Cursor not stopped');
|
|
3487
|
+
};
|
|
3188
3488
|
cursor.trans = trans;
|
|
3189
|
-
cursor.stop =
|
|
3489
|
+
cursor.stop =
|
|
3490
|
+
cursor.continue =
|
|
3491
|
+
cursor.continuePrimaryKey =
|
|
3492
|
+
cursor.advance =
|
|
3493
|
+
doThrowCursorIsNotStarted;
|
|
3190
3494
|
cursor.fail = wrap(reject);
|
|
3191
3495
|
cursor.next = function () {
|
|
3192
3496
|
var _this = this;
|
|
3193
3497
|
var gotOne = 1;
|
|
3194
|
-
return this.start(function () {
|
|
3498
|
+
return this.start(function () {
|
|
3499
|
+
return gotOne-- ? _this.continue() : _this.stop();
|
|
3500
|
+
}).then(function () { return _this; });
|
|
3195
3501
|
};
|
|
3196
3502
|
cursor.start = function (callback) {
|
|
3197
3503
|
var iterationPromise = new Promise(function (resolveIteration, rejectIteration) {
|
|
@@ -3199,7 +3505,11 @@
|
|
|
3199
3505
|
req.onerror = eventRejectHandler(rejectIteration);
|
|
3200
3506
|
cursor.fail = rejectIteration;
|
|
3201
3507
|
cursor.stop = function (value) {
|
|
3202
|
-
cursor.stop =
|
|
3508
|
+
cursor.stop =
|
|
3509
|
+
cursor.continue =
|
|
3510
|
+
cursor.continuePrimaryKey =
|
|
3511
|
+
cursor.advance =
|
|
3512
|
+
doThrowCursorIsStopped;
|
|
3203
3513
|
resolveIteration(value);
|
|
3204
3514
|
};
|
|
3205
3515
|
});
|
|
@@ -3214,7 +3524,9 @@
|
|
|
3214
3524
|
}
|
|
3215
3525
|
else {
|
|
3216
3526
|
cursor.done = true;
|
|
3217
|
-
cursor.start = function () {
|
|
3527
|
+
cursor.start = function () {
|
|
3528
|
+
throw new Error('Cursor behind last entry');
|
|
3529
|
+
};
|
|
3218
3530
|
cursor.stop();
|
|
3219
3531
|
}
|
|
3220
3532
|
};
|
|
@@ -3250,26 +3562,28 @@
|
|
|
3250
3562
|
var options = {
|
|
3251
3563
|
query: idbKeyRange,
|
|
3252
3564
|
count: nonInfinitLimit,
|
|
3253
|
-
direction: direction
|
|
3565
|
+
direction: direction,
|
|
3254
3566
|
};
|
|
3255
|
-
var req = values
|
|
3256
|
-
source.getAll(options)
|
|
3257
|
-
source.getAllKeys(options);
|
|
3567
|
+
var req = values
|
|
3568
|
+
? source.getAll(options)
|
|
3569
|
+
: source.getAllKeys(options);
|
|
3258
3570
|
req.onsuccess = function (event) { return resolve({ result: event.target.result }); };
|
|
3259
3571
|
req.onerror = eventRejectHandler(reject);
|
|
3260
3572
|
}
|
|
3261
3573
|
else if (hasGetAll && direction === 'next') {
|
|
3262
|
-
var req = values
|
|
3263
|
-
source.getAll(idbKeyRange, nonInfinitLimit)
|
|
3264
|
-
source.getAllKeys(idbKeyRange, nonInfinitLimit);
|
|
3265
|
-
req.onsuccess = function (event) {
|
|
3574
|
+
var req = values
|
|
3575
|
+
? source.getAll(idbKeyRange, nonInfinitLimit)
|
|
3576
|
+
: source.getAllKeys(idbKeyRange, nonInfinitLimit);
|
|
3577
|
+
req.onsuccess = function (event) {
|
|
3578
|
+
return resolve({ result: event.target.result });
|
|
3579
|
+
};
|
|
3266
3580
|
req.onerror = eventRejectHandler(reject);
|
|
3267
3581
|
}
|
|
3268
3582
|
else {
|
|
3269
3583
|
var count_1 = 0;
|
|
3270
|
-
var req_1 = values || !('openKeyCursor' in source)
|
|
3271
|
-
source.openCursor(idbKeyRange, direction)
|
|
3272
|
-
source.openKeyCursor(idbKeyRange, direction);
|
|
3584
|
+
var req_1 = values || !('openKeyCursor' in source)
|
|
3585
|
+
? source.openCursor(idbKeyRange, direction)
|
|
3586
|
+
: source.openKeyCursor(idbKeyRange, direction);
|
|
3273
3587
|
var result_1 = [];
|
|
3274
3588
|
req_1.onsuccess = function () {
|
|
3275
3589
|
var cursor = req_1.result;
|
|
@@ -3341,18 +3655,22 @@
|
|
|
3341
3655
|
var source = index.isPrimaryKey ? store : store.index(index.name);
|
|
3342
3656
|
var idbKeyRange = makeIDBKeyRange(range);
|
|
3343
3657
|
var req = idbKeyRange ? source.count(idbKeyRange) : source.count();
|
|
3344
|
-
req.onsuccess = wrap(function (ev) {
|
|
3658
|
+
req.onsuccess = wrap(function (ev) {
|
|
3659
|
+
return resolve(ev.target.result);
|
|
3660
|
+
});
|
|
3345
3661
|
req.onerror = eventRejectHandler(reject);
|
|
3346
3662
|
});
|
|
3347
|
-
}
|
|
3663
|
+
},
|
|
3348
3664
|
};
|
|
3349
3665
|
}
|
|
3350
3666
|
var _a = extractSchema(db, tmpTrans), schema = _a.schema, hasGetAll = _a.hasGetAll, hasIdb3Features = _a.hasIdb3Features;
|
|
3351
|
-
var tables = schema.tables.map(function (tableSchema) {
|
|
3667
|
+
var tables = schema.tables.map(function (tableSchema) {
|
|
3668
|
+
return createDbCoreTable(tableSchema);
|
|
3669
|
+
});
|
|
3352
3670
|
var tableMap = {};
|
|
3353
|
-
tables.forEach(function (table) { return tableMap[table.name] = table; });
|
|
3671
|
+
tables.forEach(function (table) { return (tableMap[table.name] = table); });
|
|
3354
3672
|
return {
|
|
3355
|
-
stack:
|
|
3673
|
+
stack: 'dbcore',
|
|
3356
3674
|
transaction: db.transaction.bind(db),
|
|
3357
3675
|
table: function (name) {
|
|
3358
3676
|
var result = tableMap[name];
|
|
@@ -3362,7 +3680,7 @@
|
|
|
3362
3680
|
},
|
|
3363
3681
|
MIN_KEY: -Infinity,
|
|
3364
3682
|
MAX_KEY: getMaxKey(IdbKeyRange),
|
|
3365
|
-
schema: schema
|
|
3683
|
+
schema: schema,
|
|
3366
3684
|
};
|
|
3367
3685
|
}
|
|
3368
3686
|
|
|
@@ -3376,7 +3694,7 @@
|
|
|
3376
3694
|
var IDBKeyRange = _a.IDBKeyRange; _a.indexedDB;
|
|
3377
3695
|
var dbcore = createMiddlewareStack(createDBCore(idbdb, IDBKeyRange, tmpTrans), middlewares.dbcore);
|
|
3378
3696
|
return {
|
|
3379
|
-
dbcore: dbcore
|
|
3697
|
+
dbcore: dbcore,
|
|
3380
3698
|
};
|
|
3381
3699
|
}
|
|
3382
3700
|
function generateMiddlewareStacks(db, tmpTrans) {
|
|
@@ -3399,13 +3717,20 @@
|
|
|
3399
3717
|
var schema = dbschema[tableName];
|
|
3400
3718
|
objs.forEach(function (obj) {
|
|
3401
3719
|
var propDesc = getPropertyDescriptor(obj, tableName);
|
|
3402
|
-
if (!propDesc || (
|
|
3720
|
+
if (!propDesc || ('value' in propDesc && propDesc.value === undefined)) {
|
|
3403
3721
|
if (obj === db.Transaction.prototype || obj instanceof db.Transaction) {
|
|
3404
3722
|
setProp(obj, tableName, {
|
|
3405
|
-
get: function () {
|
|
3723
|
+
get: function () {
|
|
3724
|
+
return this.table(tableName);
|
|
3725
|
+
},
|
|
3406
3726
|
set: function (value) {
|
|
3407
|
-
defineProperty(this, tableName, {
|
|
3408
|
-
|
|
3727
|
+
defineProperty(this, tableName, {
|
|
3728
|
+
value: value,
|
|
3729
|
+
writable: true,
|
|
3730
|
+
configurable: true,
|
|
3731
|
+
enumerable: true,
|
|
3732
|
+
});
|
|
3733
|
+
},
|
|
3409
3734
|
});
|
|
3410
3735
|
}
|
|
3411
3736
|
else {
|
|
@@ -3428,8 +3753,9 @@
|
|
|
3428
3753
|
}
|
|
3429
3754
|
function runUpgraders(db, oldVersion, idbUpgradeTrans, reject) {
|
|
3430
3755
|
var globalSchema = db._dbSchema;
|
|
3431
|
-
if (idbUpgradeTrans.objectStoreNames.contains('$meta') &&
|
|
3432
|
-
globalSchema.$meta
|
|
3756
|
+
if (idbUpgradeTrans.objectStoreNames.contains('$meta') &&
|
|
3757
|
+
!globalSchema.$meta) {
|
|
3758
|
+
globalSchema.$meta = createTableSchema('$meta', parseIndexSyntax('')[0], []);
|
|
3433
3759
|
db._storeNames.push('$meta');
|
|
3434
3760
|
}
|
|
3435
3761
|
var trans = db._createTransaction('readwrite', db._storeNames, globalSchema);
|
|
@@ -3450,15 +3776,20 @@
|
|
|
3450
3776
|
else {
|
|
3451
3777
|
generateMiddlewareStacks(db, idbUpgradeTrans);
|
|
3452
3778
|
return getExistingVersion(db, trans, oldVersion)
|
|
3453
|
-
.then(function (oldVersion) {
|
|
3779
|
+
.then(function (oldVersion) {
|
|
3780
|
+
return updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans);
|
|
3781
|
+
})
|
|
3454
3782
|
.catch(rejectTransaction);
|
|
3455
3783
|
}
|
|
3456
3784
|
});
|
|
3457
3785
|
}
|
|
3458
3786
|
function patchCurrentVersion(db, idbUpgradeTrans) {
|
|
3459
3787
|
createMissingTables(db._dbSchema, idbUpgradeTrans);
|
|
3460
|
-
if (idbUpgradeTrans.db.version % 10 === 0 &&
|
|
3461
|
-
idbUpgradeTrans.
|
|
3788
|
+
if (idbUpgradeTrans.db.version % 10 === 0 &&
|
|
3789
|
+
!idbUpgradeTrans.objectStoreNames.contains('$meta')) {
|
|
3790
|
+
idbUpgradeTrans.db
|
|
3791
|
+
.createObjectStore('$meta')
|
|
3792
|
+
.add(Math.ceil(idbUpgradeTrans.db.version / 10 - 1), 'version');
|
|
3462
3793
|
}
|
|
3463
3794
|
var globalSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
|
|
3464
3795
|
adjustToExistingIndexNames(db, db._dbSchema, idbUpgradeTrans);
|
|
@@ -3484,7 +3815,10 @@
|
|
|
3484
3815
|
}
|
|
3485
3816
|
function getExistingVersion(db, trans, oldVersion) {
|
|
3486
3817
|
if (trans.storeNames.includes('$meta')) {
|
|
3487
|
-
return trans
|
|
3818
|
+
return trans
|
|
3819
|
+
.table('$meta')
|
|
3820
|
+
.get('version')
|
|
3821
|
+
.then(function (metaVersion) {
|
|
3488
3822
|
return metaVersion != null ? metaVersion : oldVersion;
|
|
3489
3823
|
});
|
|
3490
3824
|
}
|
|
@@ -3495,7 +3829,7 @@
|
|
|
3495
3829
|
function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
|
|
3496
3830
|
var queue = [];
|
|
3497
3831
|
var versions = db._versions;
|
|
3498
|
-
var globalSchema = db._dbSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
|
|
3832
|
+
var globalSchema = (db._dbSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans));
|
|
3499
3833
|
var versToRun = versions.filter(function (v) { return v._cfg.version >= oldVersion; });
|
|
3500
3834
|
if (versToRun.length === 0) {
|
|
3501
3835
|
return DexiePromise.resolve();
|
|
@@ -3513,7 +3847,7 @@
|
|
|
3513
3847
|
});
|
|
3514
3848
|
diff.change.forEach(function (change) {
|
|
3515
3849
|
if (change.recreate) {
|
|
3516
|
-
throw new exceptions.Upgrade(
|
|
3850
|
+
throw new exceptions.Upgrade('Not yet support for changing primary key');
|
|
3517
3851
|
}
|
|
3518
3852
|
else {
|
|
3519
3853
|
var store_1 = idbUpgradeTrans.objectStore(change.name);
|
|
@@ -3550,8 +3884,9 @@
|
|
|
3550
3884
|
}
|
|
3551
3885
|
}
|
|
3552
3886
|
});
|
|
3553
|
-
return
|
|
3554
|
-
DexiePromise.resolve(returnValue_1)
|
|
3887
|
+
return returnValue_1 && typeof returnValue_1.then === 'function'
|
|
3888
|
+
? DexiePromise.resolve(returnValue_1)
|
|
3889
|
+
: promiseFollowed.then(function () { return returnValue_1; });
|
|
3555
3890
|
}
|
|
3556
3891
|
});
|
|
3557
3892
|
queue.push(function (idbtrans) {
|
|
@@ -3575,8 +3910,9 @@
|
|
|
3575
3910
|
});
|
|
3576
3911
|
});
|
|
3577
3912
|
function runQueue() {
|
|
3578
|
-
return queue.length
|
|
3579
|
-
DexiePromise.resolve()
|
|
3913
|
+
return queue.length
|
|
3914
|
+
? DexiePromise.resolve(queue.shift()(trans.idbtrans)).then(runQueue)
|
|
3915
|
+
: DexiePromise.resolve();
|
|
3580
3916
|
}
|
|
3581
3917
|
return runQueue().then(function () {
|
|
3582
3918
|
createMissingTables(globalSchema, idbUpgradeTrans);
|
|
@@ -3586,7 +3922,7 @@
|
|
|
3586
3922
|
var diff = {
|
|
3587
3923
|
del: [],
|
|
3588
3924
|
add: [],
|
|
3589
|
-
change: []
|
|
3925
|
+
change: [],
|
|
3590
3926
|
};
|
|
3591
3927
|
var table;
|
|
3592
3928
|
for (table in oldSchema) {
|
|
@@ -3605,11 +3941,12 @@
|
|
|
3605
3941
|
recreate: false,
|
|
3606
3942
|
del: [],
|
|
3607
3943
|
add: [],
|
|
3608
|
-
change: []
|
|
3944
|
+
change: [],
|
|
3609
3945
|
};
|
|
3610
|
-
if (
|
|
3611
|
-
'' + (oldDef.primKey.keyPath || '')
|
|
3612
|
-
(
|
|
3946
|
+
if (
|
|
3947
|
+
'' + (oldDef.primKey.keyPath || '') !==
|
|
3948
|
+
'' + (newDef.primKey.keyPath || '') ||
|
|
3949
|
+
oldDef.primKey.auto !== newDef.primKey.auto) {
|
|
3613
3950
|
change.recreate = true;
|
|
3614
3951
|
diff.change.push(change);
|
|
3615
3952
|
}
|
|
@@ -3628,7 +3965,9 @@
|
|
|
3628
3965
|
else if (oldIdx.src !== newIdx.src)
|
|
3629
3966
|
change.change.push(newIdx);
|
|
3630
3967
|
}
|
|
3631
|
-
if (change.del.length > 0 ||
|
|
3968
|
+
if (change.del.length > 0 ||
|
|
3969
|
+
change.add.length > 0 ||
|
|
3970
|
+
change.change.length > 0) {
|
|
3632
3971
|
diff.change.push(change);
|
|
3633
3972
|
}
|
|
3634
3973
|
}
|
|
@@ -3637,9 +3976,9 @@
|
|
|
3637
3976
|
return diff;
|
|
3638
3977
|
}
|
|
3639
3978
|
function createTable(idbtrans, tableName, primKey, indexes) {
|
|
3640
|
-
var store = idbtrans.db.createObjectStore(tableName, primKey.keyPath
|
|
3641
|
-
{ keyPath: primKey.keyPath, autoIncrement: primKey.auto }
|
|
3642
|
-
{ autoIncrement: primKey.auto });
|
|
3979
|
+
var store = idbtrans.db.createObjectStore(tableName, primKey.keyPath
|
|
3980
|
+
? { keyPath: primKey.keyPath, autoIncrement: primKey.auto }
|
|
3981
|
+
: { autoIncrement: primKey.auto });
|
|
3643
3982
|
indexes.forEach(function (idx) { return addIndex(store, idx); });
|
|
3644
3983
|
return store;
|
|
3645
3984
|
}
|
|
@@ -3653,12 +3992,17 @@
|
|
|
3653
3992
|
});
|
|
3654
3993
|
}
|
|
3655
3994
|
function deleteRemovedTables(newSchema, idbtrans) {
|
|
3656
|
-
[].slice
|
|
3995
|
+
[].slice
|
|
3996
|
+
.call(idbtrans.db.objectStoreNames)
|
|
3997
|
+
.forEach(function (storeName) {
|
|
3657
3998
|
return newSchema[storeName] == null && idbtrans.db.deleteObjectStore(storeName);
|
|
3658
3999
|
});
|
|
3659
4000
|
}
|
|
3660
4001
|
function addIndex(store, idx) {
|
|
3661
|
-
store.createIndex(idx.name, idx.keyPath, {
|
|
4002
|
+
store.createIndex(idx.name, idx.keyPath, {
|
|
4003
|
+
unique: idx.unique,
|
|
4004
|
+
multiEntry: idx.multi,
|
|
4005
|
+
});
|
|
3662
4006
|
}
|
|
3663
4007
|
function buildGlobalSchema(db, idbdb, tmpTrans) {
|
|
3664
4008
|
var globalSchema = {};
|
|
@@ -3666,12 +4010,12 @@
|
|
|
3666
4010
|
dbStoreNames.forEach(function (storeName) {
|
|
3667
4011
|
var store = tmpTrans.objectStore(storeName);
|
|
3668
4012
|
var keyPath = store.keyPath;
|
|
3669
|
-
var primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath ||
|
|
4013
|
+
var primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath || '', true, false, !!store.autoIncrement, keyPath && typeof keyPath !== 'string', true);
|
|
3670
4014
|
var indexes = [];
|
|
3671
4015
|
for (var j = 0; j < store.indexNames.length; ++j) {
|
|
3672
4016
|
var idbindex = store.index(store.indexNames[j]);
|
|
3673
4017
|
keyPath = idbindex.keyPath;
|
|
3674
|
-
var index = createIndexSpec(idbindex.name, keyPath, !!idbindex.unique, !!idbindex.multiEntry, false, keyPath && typeof keyPath !==
|
|
4018
|
+
var index = createIndexSpec(idbindex.name, keyPath, !!idbindex.unique, !!idbindex.multiEntry, false, keyPath && typeof keyPath !== 'string', false);
|
|
3675
4019
|
indexes.push(index);
|
|
3676
4020
|
}
|
|
3677
4021
|
globalSchema[storeName] = createTableSchema(storeName, primKey, indexes);
|
|
@@ -3680,14 +4024,15 @@
|
|
|
3680
4024
|
}
|
|
3681
4025
|
function readGlobalSchema(db, idbdb, tmpTrans) {
|
|
3682
4026
|
db.verno = idbdb.version / 10;
|
|
3683
|
-
var globalSchema = db._dbSchema = buildGlobalSchema(db, idbdb, tmpTrans);
|
|
4027
|
+
var globalSchema = (db._dbSchema = buildGlobalSchema(db, idbdb, tmpTrans));
|
|
3684
4028
|
db._storeNames = slice(idbdb.objectStoreNames, 0);
|
|
3685
4029
|
setApiOnPlace(db, [db._allTables], keys(globalSchema), globalSchema);
|
|
3686
4030
|
}
|
|
3687
4031
|
function verifyInstalledSchema(db, tmpTrans) {
|
|
3688
4032
|
var installedSchema = buildGlobalSchema(db, db.idbdb, tmpTrans);
|
|
3689
4033
|
var diff = getSchemaDiff(installedSchema, db._dbSchema);
|
|
3690
|
-
return !(diff.add.length ||
|
|
4034
|
+
return !(diff.add.length ||
|
|
4035
|
+
diff.change.some(function (ch) { return ch.add.length || ch.change.length; }));
|
|
3691
4036
|
}
|
|
3692
4037
|
function adjustToExistingIndexNames(db, schema, idbtrans) {
|
|
3693
4038
|
var storeNames = idbtrans.db.objectStoreNames;
|
|
@@ -3698,7 +4043,9 @@
|
|
|
3698
4043
|
for (var j = 0; j < store.indexNames.length; ++j) {
|
|
3699
4044
|
var indexName = store.indexNames[j];
|
|
3700
4045
|
var keyPath = store.index(indexName).keyPath;
|
|
3701
|
-
var dexieName = typeof keyPath === 'string'
|
|
4046
|
+
var dexieName = typeof keyPath === 'string'
|
|
4047
|
+
? keyPath
|
|
4048
|
+
: '[' + slice(keyPath).join('+') + ']';
|
|
3702
4049
|
if (schema[storeName]) {
|
|
3703
4050
|
var indexSpec = schema[storeName].idxByName[dexieName];
|
|
3704
4051
|
if (indexSpec) {
|
|
@@ -3709,9 +4056,11 @@
|
|
|
3709
4056
|
}
|
|
3710
4057
|
}
|
|
3711
4058
|
}
|
|
3712
|
-
if (typeof navigator !== 'undefined' &&
|
|
4059
|
+
if (typeof navigator !== 'undefined' &&
|
|
4060
|
+
/Safari/.test(navigator.userAgent) &&
|
|
3713
4061
|
!/(Chrome\/|Edge\/)/.test(navigator.userAgent) &&
|
|
3714
|
-
_global.WorkerGlobalScope &&
|
|
4062
|
+
_global.WorkerGlobalScope &&
|
|
4063
|
+
_global instanceof _global.WorkerGlobalScope &&
|
|
3715
4064
|
[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604) {
|
|
3716
4065
|
db._hasGetAll = false;
|
|
3717
4066
|
}
|
|
@@ -3722,8 +4071,10 @@
|
|
|
3722
4071
|
var typeSplit = index.split(':');
|
|
3723
4072
|
var type = (_a = typeSplit[1]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
3724
4073
|
index = typeSplit[0].trim();
|
|
3725
|
-
var name = index.replace(/([&*]|\+\+)/g,
|
|
3726
|
-
var keyPath = /^\[/.test(name)
|
|
4074
|
+
var name = index.replace(/([&*]|\+\+)/g, '');
|
|
4075
|
+
var keyPath = /^\[/.test(name)
|
|
4076
|
+
? name.match(/^\[(.*)\]$/)[1].split('+')
|
|
4077
|
+
: name;
|
|
3727
4078
|
return createIndexSpec(name, keyPath || null, /\&/.test(index), /\*/.test(index), /\+\+/.test(index), isArray(keyPath), indexNum === 0, type);
|
|
3728
4079
|
});
|
|
3729
4080
|
}
|
|
@@ -3794,14 +4145,15 @@
|
|
|
3794
4145
|
storesSource: null,
|
|
3795
4146
|
dbschema: {},
|
|
3796
4147
|
tables: {},
|
|
3797
|
-
contentUpgrade: null
|
|
4148
|
+
contentUpgrade: null,
|
|
3798
4149
|
};
|
|
3799
4150
|
});
|
|
3800
4151
|
}
|
|
3801
4152
|
|
|
3802
4153
|
var connections = createConnectionsManager();
|
|
3803
4154
|
function createConnectionsManager() {
|
|
3804
|
-
if (typeof FinalizationRegistry !== 'undefined' &&
|
|
4155
|
+
if (typeof FinalizationRegistry !== 'undefined' &&
|
|
4156
|
+
typeof WeakRef !== 'undefined') {
|
|
3805
4157
|
var _refs_1 = new Set();
|
|
3806
4158
|
var _registry_1 = new FinalizationRegistry(function (ref) {
|
|
3807
4159
|
_refs_1.delete(ref);
|
|
@@ -3857,19 +4209,19 @@
|
|
|
3857
4209
|
}
|
|
3858
4210
|
|
|
3859
4211
|
function getDbNamesTable(indexedDB, IDBKeyRange) {
|
|
3860
|
-
var dbNamesDB = indexedDB[
|
|
4212
|
+
var dbNamesDB = indexedDB['_dbNamesDB'];
|
|
3861
4213
|
if (!dbNamesDB) {
|
|
3862
|
-
dbNamesDB = indexedDB[
|
|
4214
|
+
dbNamesDB = indexedDB['_dbNamesDB'] = new Dexie$1(DBNAMES_DB, {
|
|
3863
4215
|
addons: [],
|
|
3864
4216
|
indexedDB: indexedDB,
|
|
3865
4217
|
IDBKeyRange: IDBKeyRange,
|
|
3866
4218
|
});
|
|
3867
|
-
dbNamesDB.version(1).stores({ dbnames:
|
|
4219
|
+
dbNamesDB.version(1).stores({ dbnames: 'name' });
|
|
3868
4220
|
}
|
|
3869
|
-
return dbNamesDB.table(
|
|
4221
|
+
return dbNamesDB.table('dbnames');
|
|
3870
4222
|
}
|
|
3871
4223
|
function hasDatabasesNative(indexedDB) {
|
|
3872
|
-
return indexedDB && typeof indexedDB.databases ===
|
|
4224
|
+
return indexedDB && typeof indexedDB.databases === 'function';
|
|
3873
4225
|
}
|
|
3874
4226
|
function getDatabaseNames(_a) {
|
|
3875
4227
|
var indexedDB = _a.indexedDB, IDBKeyRange = _a.IDBKeyRange;
|
|
@@ -3917,15 +4269,17 @@
|
|
|
3917
4269
|
|
|
3918
4270
|
var _a;
|
|
3919
4271
|
function isEmptyRange(node) {
|
|
3920
|
-
return !(
|
|
4272
|
+
return !('from' in node);
|
|
3921
4273
|
}
|
|
3922
4274
|
var RangeSet = function (fromOrTree, to) {
|
|
3923
4275
|
if (this) {
|
|
3924
|
-
extend(this, arguments.length
|
|
4276
|
+
extend(this, arguments.length
|
|
4277
|
+
? { d: 1, from: fromOrTree, to: arguments.length > 1 ? to : fromOrTree }
|
|
4278
|
+
: { d: 0 });
|
|
3925
4279
|
}
|
|
3926
4280
|
else {
|
|
3927
4281
|
var rv = new RangeSet();
|
|
3928
|
-
if (fromOrTree &&
|
|
4282
|
+
if (fromOrTree && 'd' in fromOrTree) {
|
|
3929
4283
|
extend(rv, fromOrTree);
|
|
3930
4284
|
}
|
|
3931
4285
|
return rv;
|
|
@@ -4025,7 +4379,9 @@
|
|
|
4025
4379
|
return false;
|
|
4026
4380
|
}
|
|
4027
4381
|
function getRangeSetIterator(node) {
|
|
4028
|
-
var state = isEmptyRange(node)
|
|
4382
|
+
var state = isEmptyRange(node)
|
|
4383
|
+
? null
|
|
4384
|
+
: { s: 0, n: node };
|
|
4029
4385
|
return {
|
|
4030
4386
|
next: function (key) {
|
|
4031
4387
|
var keyProvided = arguments.length > 0;
|
|
@@ -4062,9 +4418,9 @@
|
|
|
4062
4418
|
function rebalance(target) {
|
|
4063
4419
|
var _a, _b;
|
|
4064
4420
|
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);
|
|
4065
|
-
var r = diff > 1 ?
|
|
4421
|
+
var r = diff > 1 ? 'r' : diff < -1 ? 'l' : '';
|
|
4066
4422
|
if (r) {
|
|
4067
|
-
var l = r ===
|
|
4423
|
+
var l = r === 'r' ? 'l' : 'r';
|
|
4068
4424
|
var rootClone = __assign({}, target);
|
|
4069
4425
|
var oldRootRight = target[r];
|
|
4070
4426
|
target.from = oldRootRight.from;
|
|
@@ -4092,7 +4448,9 @@
|
|
|
4092
4448
|
}
|
|
4093
4449
|
|
|
4094
4450
|
function obsSetsOverlap(os1, os2) {
|
|
4095
|
-
return os1.all ||
|
|
4451
|
+
return (os1.all ||
|
|
4452
|
+
os2.all ||
|
|
4453
|
+
Object.keys(os1).some(function (key) { return os2[key] && rangesOverlap(os2[key], os1[key]); }));
|
|
4096
4454
|
}
|
|
4097
4455
|
|
|
4098
4456
|
var cache = {};
|
|
@@ -4162,9 +4520,9 @@
|
|
|
4162
4520
|
var state = db._state;
|
|
4163
4521
|
var indexedDB = db._deps.indexedDB;
|
|
4164
4522
|
if (state.isBeingOpened || db.idbdb)
|
|
4165
|
-
return state.dbReadyPromise.then(function () {
|
|
4166
|
-
rejection(state.dbOpenError) :
|
|
4167
|
-
|
|
4523
|
+
return state.dbReadyPromise.then(function () {
|
|
4524
|
+
return state.dbOpenError ? rejection(state.dbOpenError) : db;
|
|
4525
|
+
});
|
|
4168
4526
|
state.isBeingOpened = true;
|
|
4169
4527
|
state.dbOpenError = null;
|
|
4170
4528
|
state.openComplete = false;
|
|
@@ -4177,97 +4535,102 @@
|
|
|
4177
4535
|
}
|
|
4178
4536
|
var resolveDbReady = state.dbReadyResolve,
|
|
4179
4537
|
upgradeTransaction = null, wasCreated = false;
|
|
4180
|
-
var tryOpenDB = function () {
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
else {
|
|
4204
|
-
upgradeTransaction.onerror = eventRejectHandler(reject);
|
|
4205
|
-
var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion;
|
|
4206
|
-
wasCreated = oldVer < 1;
|
|
4207
|
-
db.idbdb = req.result;
|
|
4208
|
-
if (schemaPatchMode) {
|
|
4209
|
-
patchCurrentVersion(db, upgradeTransaction);
|
|
4538
|
+
var tryOpenDB = function () {
|
|
4539
|
+
return new DexiePromise(function (resolve, reject) {
|
|
4540
|
+
throwIfCancelled();
|
|
4541
|
+
if (!indexedDB)
|
|
4542
|
+
throw new exceptions.MissingAPI();
|
|
4543
|
+
var dbName = db.name;
|
|
4544
|
+
var req = state.autoSchema || !nativeVerToOpen
|
|
4545
|
+
? indexedDB.open(dbName)
|
|
4546
|
+
: indexedDB.open(dbName, nativeVerToOpen);
|
|
4547
|
+
if (!req)
|
|
4548
|
+
throw new exceptions.MissingAPI();
|
|
4549
|
+
req.onerror = eventRejectHandler(reject);
|
|
4550
|
+
req.onblocked = wrap(db._fireOnBlocked);
|
|
4551
|
+
req.onupgradeneeded = wrap(function (e) {
|
|
4552
|
+
upgradeTransaction = req.transaction;
|
|
4553
|
+
if (state.autoSchema && !db._options.allowEmptyDB) {
|
|
4554
|
+
req.onerror = preventDefault;
|
|
4555
|
+
upgradeTransaction.abort();
|
|
4556
|
+
req.result.close();
|
|
4557
|
+
var delreq = indexedDB.deleteDatabase(dbName);
|
|
4558
|
+
delreq.onsuccess = delreq.onerror = wrap(function () {
|
|
4559
|
+
reject(new exceptions.NoSuchDatabase("Database ".concat(dbName, " doesnt exist")));
|
|
4560
|
+
});
|
|
4210
4561
|
}
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
if (objectStoreNames.length > 0)
|
|
4219
|
-
try {
|
|
4220
|
-
var tmpTrans = idbdb.transaction(safariMultiStoreFix(objectStoreNames), 'readonly');
|
|
4221
|
-
if (state.autoSchema)
|
|
4222
|
-
readGlobalSchema(db, idbdb, tmpTrans);
|
|
4223
|
-
else {
|
|
4224
|
-
adjustToExistingIndexNames(db, db._dbSchema, tmpTrans);
|
|
4225
|
-
if (!verifyInstalledSchema(db, tmpTrans) && !schemaPatchMode) {
|
|
4226
|
-
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.");
|
|
4227
|
-
idbdb.close();
|
|
4228
|
-
nativeVerToOpen = idbdb.version + 1;
|
|
4229
|
-
schemaPatchMode = true;
|
|
4230
|
-
return resolve(tryOpenDB());
|
|
4231
|
-
}
|
|
4562
|
+
else {
|
|
4563
|
+
upgradeTransaction.onerror = eventRejectHandler(reject);
|
|
4564
|
+
var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion;
|
|
4565
|
+
wasCreated = oldVer < 1;
|
|
4566
|
+
db.idbdb = req.result;
|
|
4567
|
+
if (schemaPatchMode) {
|
|
4568
|
+
patchCurrentVersion(db, upgradeTransaction);
|
|
4232
4569
|
}
|
|
4233
|
-
|
|
4234
|
-
}
|
|
4235
|
-
catch (e) {
|
|
4236
|
-
}
|
|
4237
|
-
connections.add(db);
|
|
4238
|
-
idbdb.onversionchange = wrap(function (ev) {
|
|
4239
|
-
state.vcFired = true;
|
|
4240
|
-
db.on("versionchange").fire(ev);
|
|
4241
|
-
});
|
|
4242
|
-
idbdb.onclose = wrap(function () {
|
|
4243
|
-
db.close({ disableAutoOpen: false });
|
|
4244
|
-
});
|
|
4245
|
-
if (wasCreated)
|
|
4246
|
-
_onDatabaseCreated(db._deps, dbName);
|
|
4247
|
-
resolve();
|
|
4248
|
-
}, reject);
|
|
4249
|
-
}).catch(function (err) {
|
|
4250
|
-
switch (err === null || err === void 0 ? void 0 : err.name) {
|
|
4251
|
-
case "UnknownError":
|
|
4252
|
-
if (state.PR1398_maxLoop > 0) {
|
|
4253
|
-
state.PR1398_maxLoop--;
|
|
4254
|
-
console.warn('Dexie: Workaround for Chrome UnknownError on open()');
|
|
4255
|
-
return tryOpenDB();
|
|
4256
|
-
}
|
|
4257
|
-
break;
|
|
4258
|
-
case "VersionError":
|
|
4259
|
-
if (nativeVerToOpen > 0) {
|
|
4260
|
-
nativeVerToOpen = 0;
|
|
4261
|
-
return tryOpenDB();
|
|
4570
|
+
runUpgraders(db, oldVer / 10, upgradeTransaction, reject);
|
|
4262
4571
|
}
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4572
|
+
}, reject);
|
|
4573
|
+
req.onsuccess = wrap(function () {
|
|
4574
|
+
upgradeTransaction = null;
|
|
4575
|
+
var idbdb = (db.idbdb = req.result);
|
|
4576
|
+
var objectStoreNames = slice(idbdb.objectStoreNames);
|
|
4577
|
+
if (objectStoreNames.length > 0)
|
|
4578
|
+
try {
|
|
4579
|
+
var tmpTrans = idbdb.transaction(safariMultiStoreFix(objectStoreNames), 'readonly');
|
|
4580
|
+
if (state.autoSchema)
|
|
4581
|
+
readGlobalSchema(db, idbdb, tmpTrans);
|
|
4582
|
+
else {
|
|
4583
|
+
adjustToExistingIndexNames(db, db._dbSchema, tmpTrans);
|
|
4584
|
+
if (!verifyInstalledSchema(db, tmpTrans) && !schemaPatchMode) {
|
|
4585
|
+
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.");
|
|
4586
|
+
idbdb.close();
|
|
4587
|
+
nativeVerToOpen = idbdb.version + 1;
|
|
4588
|
+
schemaPatchMode = true;
|
|
4589
|
+
return resolve(tryOpenDB());
|
|
4590
|
+
}
|
|
4591
|
+
}
|
|
4592
|
+
generateMiddlewareStacks(db, tmpTrans);
|
|
4593
|
+
}
|
|
4594
|
+
catch (e) {
|
|
4595
|
+
}
|
|
4596
|
+
connections.add(db);
|
|
4597
|
+
idbdb.onversionchange = wrap(function (ev) {
|
|
4598
|
+
state.vcFired = true;
|
|
4599
|
+
db.on('versionchange').fire(ev);
|
|
4600
|
+
});
|
|
4601
|
+
idbdb.onclose = wrap(function () {
|
|
4602
|
+
db.close({ disableAutoOpen: false });
|
|
4603
|
+
});
|
|
4604
|
+
if (wasCreated)
|
|
4605
|
+
_onDatabaseCreated(db._deps, dbName);
|
|
4606
|
+
resolve();
|
|
4607
|
+
}, reject);
|
|
4608
|
+
}).catch(function (err) {
|
|
4609
|
+
switch (err === null || err === void 0 ? void 0 : err.name) {
|
|
4610
|
+
case 'UnknownError':
|
|
4611
|
+
if (state.PR1398_maxLoop > 0) {
|
|
4612
|
+
state.PR1398_maxLoop--;
|
|
4613
|
+
console.warn('Dexie: Workaround for Chrome UnknownError on open()');
|
|
4614
|
+
return tryOpenDB();
|
|
4615
|
+
}
|
|
4616
|
+
break;
|
|
4617
|
+
case 'VersionError':
|
|
4618
|
+
if (nativeVerToOpen > 0) {
|
|
4619
|
+
nativeVerToOpen = 0;
|
|
4620
|
+
return tryOpenDB();
|
|
4621
|
+
}
|
|
4622
|
+
break;
|
|
4623
|
+
}
|
|
4624
|
+
return DexiePromise.reject(err);
|
|
4625
|
+
});
|
|
4626
|
+
};
|
|
4267
4627
|
return DexiePromise.race([
|
|
4268
4628
|
openCanceller,
|
|
4269
|
-
(typeof navigator === 'undefined'
|
|
4270
|
-
|
|
4629
|
+
(typeof navigator === 'undefined'
|
|
4630
|
+
? DexiePromise.resolve()
|
|
4631
|
+
: idbReady()).then(tryOpenDB),
|
|
4632
|
+
])
|
|
4633
|
+
.then(function () {
|
|
4271
4634
|
throwIfCancelled();
|
|
4272
4635
|
state.onReadyBeingFired = [];
|
|
4273
4636
|
return DexiePromise.resolve(vip(function () { return db.on.ready.fire(db.vip); })).then(function fireRemainders() {
|
|
@@ -4277,12 +4640,14 @@
|
|
|
4277
4640
|
return DexiePromise.resolve(vip(function () { return remainders_1(db.vip); })).then(fireRemainders);
|
|
4278
4641
|
}
|
|
4279
4642
|
});
|
|
4280
|
-
})
|
|
4643
|
+
})
|
|
4644
|
+
.finally(function () {
|
|
4281
4645
|
if (state.openCanceller === openCanceller) {
|
|
4282
4646
|
state.onReadyBeingFired = null;
|
|
4283
4647
|
state.isBeingOpened = false;
|
|
4284
4648
|
}
|
|
4285
|
-
})
|
|
4649
|
+
})
|
|
4650
|
+
.catch(function (err) {
|
|
4286
4651
|
state.dbOpenError = err;
|
|
4287
4652
|
try {
|
|
4288
4653
|
upgradeTransaction && upgradeTransaction.abort();
|
|
@@ -4292,16 +4657,19 @@
|
|
|
4292
4657
|
db._close();
|
|
4293
4658
|
}
|
|
4294
4659
|
return rejection(err);
|
|
4295
|
-
})
|
|
4660
|
+
})
|
|
4661
|
+
.finally(function () {
|
|
4296
4662
|
state.openComplete = true;
|
|
4297
4663
|
resolveDbReady();
|
|
4298
|
-
})
|
|
4664
|
+
})
|
|
4665
|
+
.then(function () {
|
|
4299
4666
|
if (wasCreated) {
|
|
4300
4667
|
var everything_1 = {};
|
|
4301
4668
|
db.tables.forEach(function (table) {
|
|
4302
4669
|
table.schema.indexes.forEach(function (idx) {
|
|
4303
4670
|
if (idx.name)
|
|
4304
|
-
everything_1["idb://".concat(db.name, "/").concat(table.name, "/").concat(idx.name)] =
|
|
4671
|
+
everything_1["idb://".concat(db.name, "/").concat(table.name, "/").concat(idx.name)] =
|
|
4672
|
+
new RangeSet(-Infinity, [[[]]]);
|
|
4305
4673
|
});
|
|
4306
4674
|
everything_1["idb://".concat(db.name, "/").concat(table.name, "/")] = everything_1["idb://".concat(db.name, "/").concat(table.name, "/:dels")] = new RangeSet(-Infinity, [[[]]]);
|
|
4307
4675
|
});
|
|
@@ -4317,10 +4685,13 @@
|
|
|
4317
4685
|
function step(getNext) {
|
|
4318
4686
|
return function (val) {
|
|
4319
4687
|
var next = getNext(val), value = next.value;
|
|
4320
|
-
return next.done
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
value
|
|
4688
|
+
return next.done
|
|
4689
|
+
? value
|
|
4690
|
+
: !value || typeof value.then !== 'function'
|
|
4691
|
+
? isArray(value)
|
|
4692
|
+
? Promise.all(value).then(onSuccess, onError)
|
|
4693
|
+
: onSuccess(value)
|
|
4694
|
+
: value.then(onSuccess, onError);
|
|
4324
4695
|
};
|
|
4325
4696
|
}
|
|
4326
4697
|
return step(callNext)();
|
|
@@ -4329,7 +4700,7 @@
|
|
|
4329
4700
|
function extractTransactionArgs(mode, _tableArgs_, scopeFunc) {
|
|
4330
4701
|
var i = arguments.length;
|
|
4331
4702
|
if (i < 2)
|
|
4332
|
-
throw new exceptions.InvalidArgument(
|
|
4703
|
+
throw new exceptions.InvalidArgument('Too few arguments');
|
|
4333
4704
|
var args = new Array(i - 1);
|
|
4334
4705
|
while (--i)
|
|
4335
4706
|
args[i - 1] = arguments[i];
|
|
@@ -4344,7 +4715,7 @@
|
|
|
4344
4715
|
trans.explicit = true;
|
|
4345
4716
|
var zoneProps = {
|
|
4346
4717
|
trans: trans,
|
|
4347
|
-
transless: transless
|
|
4718
|
+
transless: transless,
|
|
4348
4719
|
};
|
|
4349
4720
|
if (parentTransaction) {
|
|
4350
4721
|
trans.idbtrans = parentTransaction.idbtrans;
|
|
@@ -4356,10 +4727,16 @@
|
|
|
4356
4727
|
db._state.PR1398_maxLoop = 3;
|
|
4357
4728
|
}
|
|
4358
4729
|
catch (ex) {
|
|
4359
|
-
if (ex.name === errnames.InvalidState &&
|
|
4730
|
+
if (ex.name === errnames.InvalidState &&
|
|
4731
|
+
db.isOpen() &&
|
|
4732
|
+
--db._state.PR1398_maxLoop > 0) {
|
|
4360
4733
|
console.warn('Dexie: Need to reopen db');
|
|
4361
4734
|
db.close({ disableAutoOpen: false });
|
|
4362
|
-
return db
|
|
4735
|
+
return db
|
|
4736
|
+
.open()
|
|
4737
|
+
.then(function () {
|
|
4738
|
+
return enterTransactionScope(db, mode, storeNames, null, scopeFunc);
|
|
4739
|
+
});
|
|
4363
4740
|
}
|
|
4364
4741
|
return rejection(ex);
|
|
4365
4742
|
}
|
|
@@ -4376,20 +4753,27 @@
|
|
|
4376
4753
|
var decrementor = decrementExpectedAwaits.bind(null, null);
|
|
4377
4754
|
returnValue.then(decrementor, decrementor);
|
|
4378
4755
|
}
|
|
4379
|
-
else if (typeof returnValue.next === 'function' &&
|
|
4756
|
+
else if (typeof returnValue.next === 'function' &&
|
|
4757
|
+
typeof returnValue.throw === 'function') {
|
|
4380
4758
|
returnValue = awaitIterator(returnValue);
|
|
4381
4759
|
}
|
|
4382
4760
|
}
|
|
4383
4761
|
}, zoneProps);
|
|
4384
|
-
return (returnValue && typeof returnValue.then === 'function'
|
|
4385
|
-
|
|
4386
|
-
x
|
|
4387
|
-
|
|
4388
|
-
|
|
4762
|
+
return (returnValue && typeof returnValue.then === 'function'
|
|
4763
|
+
?
|
|
4764
|
+
DexiePromise.resolve(returnValue).then(function (x) {
|
|
4765
|
+
return trans.active
|
|
4766
|
+
? x
|
|
4767
|
+
: rejection(new exceptions.PrematureCommit('Transaction committed too early. See http://bit.ly/2kdckMn'));
|
|
4768
|
+
})
|
|
4769
|
+
:
|
|
4770
|
+
promiseFollowed.then(function () { return returnValue; }))
|
|
4771
|
+
.then(function (x) {
|
|
4389
4772
|
if (parentTransaction)
|
|
4390
4773
|
trans._resolve();
|
|
4391
4774
|
return trans._completion.then(function () { return x; });
|
|
4392
|
-
})
|
|
4775
|
+
})
|
|
4776
|
+
.catch(function (e) {
|
|
4393
4777
|
trans._reject(e);
|
|
4394
4778
|
return rejection(e);
|
|
4395
4779
|
});
|
|
@@ -4410,8 +4794,13 @@
|
|
|
4410
4794
|
var allVirtualIndexes = [];
|
|
4411
4795
|
function addVirtualIndexes(keyPath, keyTail, lowLevelIndex) {
|
|
4412
4796
|
var keyPathAlias = getKeyPathAlias(keyPath);
|
|
4413
|
-
var indexList = (indexLookup[keyPathAlias] =
|
|
4414
|
-
|
|
4797
|
+
var indexList = (indexLookup[keyPathAlias] =
|
|
4798
|
+
indexLookup[keyPathAlias] || []);
|
|
4799
|
+
var keyLength = keyPath == null
|
|
4800
|
+
? 0
|
|
4801
|
+
: typeof keyPath === 'string'
|
|
4802
|
+
? 1
|
|
4803
|
+
: keyPath.length;
|
|
4415
4804
|
var isVirtual = keyTail > 0;
|
|
4416
4805
|
var virtualIndex = __assign(__assign({}, lowLevelIndex), { name: isVirtual
|
|
4417
4806
|
? "".concat(keyPathAlias, "(virtual-from:").concat(lowLevelIndex.name, ")")
|
|
@@ -4421,16 +4810,16 @@
|
|
|
4421
4810
|
allVirtualIndexes.push(virtualIndex);
|
|
4422
4811
|
}
|
|
4423
4812
|
if (keyLength > 1) {
|
|
4424
|
-
var virtualKeyPath = keyLength === 2
|
|
4425
|
-
keyPath[0]
|
|
4426
|
-
keyPath.slice(0, keyLength - 1);
|
|
4813
|
+
var virtualKeyPath = keyLength === 2
|
|
4814
|
+
? keyPath[0]
|
|
4815
|
+
: keyPath.slice(0, keyLength - 1);
|
|
4427
4816
|
addVirtualIndexes(virtualKeyPath, keyTail + 1, lowLevelIndex);
|
|
4428
4817
|
}
|
|
4429
4818
|
indexList.sort(function (a, b) { return a.keyTail - b.keyTail; });
|
|
4430
4819
|
return virtualIndex;
|
|
4431
4820
|
}
|
|
4432
4821
|
var primaryKey = addVirtualIndexes(schema.primaryKey.keyPath, 0, schema.primaryKey);
|
|
4433
|
-
indexLookup[
|
|
4822
|
+
indexLookup[':id'] = [primaryKey];
|
|
4434
4823
|
for (var _i = 0, _a = schema.indexes; _i < _a.length; _i++) {
|
|
4435
4824
|
var index = _a[_i];
|
|
4436
4825
|
addVirtualIndexes(index.keyPath, 0, index);
|
|
@@ -4441,80 +4830,82 @@
|
|
|
4441
4830
|
}
|
|
4442
4831
|
function translateRange(range, keyTail) {
|
|
4443
4832
|
return {
|
|
4444
|
-
type: range.type === 1
|
|
4445
|
-
2
|
|
4446
|
-
range.type,
|
|
4833
|
+
type: range.type === 1
|
|
4834
|
+
? 2
|
|
4835
|
+
: range.type,
|
|
4447
4836
|
lower: pad(range.lower, range.lowerOpen ? down.MAX_KEY : down.MIN_KEY, keyTail),
|
|
4448
4837
|
lowerOpen: true,
|
|
4449
4838
|
upper: pad(range.upper, range.upperOpen ? down.MIN_KEY : down.MAX_KEY, keyTail),
|
|
4450
|
-
upperOpen: true
|
|
4839
|
+
upperOpen: true,
|
|
4451
4840
|
};
|
|
4452
4841
|
}
|
|
4453
4842
|
function translateRequest(req) {
|
|
4454
4843
|
var index = req.query.index;
|
|
4455
|
-
return index.isVirtual
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4844
|
+
return index.isVirtual
|
|
4845
|
+
? __assign(__assign({}, req), { query: {
|
|
4846
|
+
index: index.lowLevelIndex,
|
|
4847
|
+
range: translateRange(req.query.range, index.keyTail),
|
|
4848
|
+
} }) : req;
|
|
4459
4849
|
}
|
|
4460
4850
|
var result = __assign(__assign({}, table), { schema: __assign(__assign({}, schema), { primaryKey: primaryKey, indexes: allVirtualIndexes, getIndexByKeyPath: findBestIndex }), count: function (req) {
|
|
4461
4851
|
return table.count(translateRequest(req));
|
|
4462
4852
|
}, query: function (req) {
|
|
4463
4853
|
return table.query(translateRequest(req));
|
|
4464
4854
|
}, openCursor: function (req) {
|
|
4465
|
-
var _a = req.query
|
|
4855
|
+
var _a = req.query
|
|
4856
|
+
.index, keyTail = _a.keyTail, isVirtual = _a.isVirtual, keyLength = _a.keyLength;
|
|
4466
4857
|
if (!isVirtual)
|
|
4467
4858
|
return table.openCursor(req);
|
|
4468
4859
|
function createVirtualCursor(cursor) {
|
|
4469
4860
|
function _continue(key) {
|
|
4470
|
-
key != null
|
|
4471
|
-
cursor.continue(pad(key, req.reverse ? down.MAX_KEY : down.MIN_KEY, keyTail))
|
|
4472
|
-
req.unique
|
|
4473
|
-
cursor.continue(cursor.key
|
|
4474
|
-
.
|
|
4475
|
-
? down.MIN_KEY
|
|
4476
|
-
|
|
4477
|
-
cursor.continue();
|
|
4861
|
+
key != null
|
|
4862
|
+
? cursor.continue(pad(key, req.reverse ? down.MAX_KEY : down.MIN_KEY, keyTail))
|
|
4863
|
+
: req.unique
|
|
4864
|
+
? cursor.continue(cursor.key
|
|
4865
|
+
.slice(0, keyLength)
|
|
4866
|
+
.concat(req.reverse ? down.MIN_KEY : down.MAX_KEY, keyTail))
|
|
4867
|
+
: cursor.continue();
|
|
4478
4868
|
}
|
|
4479
4869
|
var virtualCursor = Object.create(cursor, {
|
|
4480
4870
|
continue: { value: _continue },
|
|
4481
4871
|
continuePrimaryKey: {
|
|
4482
4872
|
value: function (key, primaryKey) {
|
|
4483
4873
|
cursor.continuePrimaryKey(pad(key, down.MAX_KEY, keyTail), primaryKey);
|
|
4484
|
-
}
|
|
4874
|
+
},
|
|
4485
4875
|
},
|
|
4486
4876
|
primaryKey: {
|
|
4487
4877
|
get: function () {
|
|
4488
4878
|
return cursor.primaryKey;
|
|
4489
|
-
}
|
|
4879
|
+
},
|
|
4490
4880
|
},
|
|
4491
4881
|
key: {
|
|
4492
4882
|
get: function () {
|
|
4493
4883
|
var key = cursor.key;
|
|
4494
|
-
return keyLength === 1
|
|
4495
|
-
key[0]
|
|
4496
|
-
key.slice(0, keyLength);
|
|
4497
|
-
}
|
|
4884
|
+
return keyLength === 1
|
|
4885
|
+
? key[0]
|
|
4886
|
+
: key.slice(0, keyLength);
|
|
4887
|
+
},
|
|
4498
4888
|
},
|
|
4499
4889
|
value: {
|
|
4500
4890
|
get: function () {
|
|
4501
4891
|
return cursor.value;
|
|
4502
|
-
}
|
|
4503
|
-
}
|
|
4892
|
+
},
|
|
4893
|
+
},
|
|
4504
4894
|
});
|
|
4505
4895
|
return virtualCursor;
|
|
4506
4896
|
}
|
|
4507
|
-
return table
|
|
4897
|
+
return table
|
|
4898
|
+
.openCursor(translateRequest(req))
|
|
4508
4899
|
.then(function (cursor) { return cursor && createVirtualCursor(cursor); });
|
|
4509
4900
|
} });
|
|
4510
4901
|
return result;
|
|
4511
4902
|
} });
|
|
4512
4903
|
}
|
|
4513
4904
|
var virtualIndexMiddleware = {
|
|
4514
|
-
stack:
|
|
4515
|
-
name:
|
|
4905
|
+
stack: 'dbcore',
|
|
4906
|
+
name: 'VirtualIndexMiddleware',
|
|
4516
4907
|
level: 1,
|
|
4517
|
-
create: createVirtualIndexMiddleware
|
|
4908
|
+
create: createVirtualIndexMiddleware,
|
|
4518
4909
|
};
|
|
4519
4910
|
|
|
4520
4911
|
function getObjectDiff(a, b, rv, prfx) {
|
|
@@ -4558,127 +4949,155 @@
|
|
|
4558
4949
|
}
|
|
4559
4950
|
|
|
4560
4951
|
var hooksMiddleware = {
|
|
4561
|
-
stack:
|
|
4562
|
-
name:
|
|
4952
|
+
stack: 'dbcore',
|
|
4953
|
+
name: 'HooksMiddleware',
|
|
4563
4954
|
level: 2,
|
|
4564
|
-
create: function (downCore) {
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
var _a = dxTrans.table(tableName).hook, deleting = _a.deleting, creating = _a.creating, updating = _a.updating;
|
|
4570
|
-
switch (req.type) {
|
|
4571
|
-
case 'add':
|
|
4572
|
-
if (creating.fire === nop)
|
|
4573
|
-
break;
|
|
4574
|
-
return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
|
|
4575
|
-
case 'put':
|
|
4576
|
-
if (creating.fire === nop && updating.fire === nop)
|
|
4577
|
-
break;
|
|
4578
|
-
return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
|
|
4579
|
-
case 'delete':
|
|
4580
|
-
if (deleting.fire === nop)
|
|
4581
|
-
break;
|
|
4582
|
-
return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
|
|
4583
|
-
case 'deleteRange':
|
|
4584
|
-
if (deleting.fire === nop)
|
|
4585
|
-
break;
|
|
4586
|
-
return dxTrans._promise('readwrite', function () { return deleteRange(req); }, true);
|
|
4587
|
-
}
|
|
4588
|
-
return downTable.mutate(req);
|
|
4589
|
-
function addPutOrDelete(req) {
|
|
4955
|
+
create: function (downCore) {
|
|
4956
|
+
return (__assign(__assign({}, downCore), { table: function (tableName) {
|
|
4957
|
+
var downTable = downCore.table(tableName);
|
|
4958
|
+
var primaryKey = downTable.schema.primaryKey;
|
|
4959
|
+
var tableMiddleware = __assign(__assign({}, downTable), { mutate: function (req) {
|
|
4590
4960
|
var dxTrans = PSD.trans;
|
|
4591
|
-
var
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4961
|
+
var _a = dxTrans.table(tableName).hook, deleting = _a.deleting, creating = _a.creating, updating = _a.updating;
|
|
4962
|
+
switch (req.type) {
|
|
4963
|
+
case 'add':
|
|
4964
|
+
if (creating.fire === nop)
|
|
4965
|
+
break;
|
|
4966
|
+
return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
|
|
4967
|
+
case 'put':
|
|
4968
|
+
if (creating.fire === nop && updating.fire === nop)
|
|
4969
|
+
break;
|
|
4970
|
+
return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
|
|
4971
|
+
case 'delete':
|
|
4972
|
+
if (deleting.fire === nop)
|
|
4973
|
+
break;
|
|
4974
|
+
return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
|
|
4975
|
+
case 'deleteRange':
|
|
4976
|
+
if (deleting.fire === nop)
|
|
4977
|
+
break;
|
|
4978
|
+
return dxTrans._promise('readwrite', function () { return deleteRange(req); }, true);
|
|
4979
|
+
}
|
|
4980
|
+
return downTable.mutate(req);
|
|
4981
|
+
function addPutOrDelete(req) {
|
|
4982
|
+
var dxTrans = PSD.trans;
|
|
4983
|
+
var keys = req.keys || getEffectiveKeys(primaryKey, req);
|
|
4984
|
+
if (!keys)
|
|
4985
|
+
throw new Error('Keys missing');
|
|
4986
|
+
req =
|
|
4987
|
+
req.type === 'add' || req.type === 'put'
|
|
4988
|
+
? __assign(__assign({}, req), { keys: keys }) : __assign({}, req);
|
|
4989
|
+
if (req.type !== 'delete')
|
|
4990
|
+
req.values = __spreadArray([], req.values, true);
|
|
4991
|
+
if (req.keys)
|
|
4992
|
+
req.keys = __spreadArray([], req.keys, true);
|
|
4993
|
+
return getExistingValues(downTable, req, keys).then(function (existingValues) {
|
|
4994
|
+
var contexts = keys.map(function (key, i) {
|
|
4995
|
+
var existingValue = existingValues[i];
|
|
4996
|
+
var ctx = { onerror: null, onsuccess: null };
|
|
4997
|
+
if (req.type === 'delete') {
|
|
4998
|
+
deleting.fire.call(ctx, key, existingValue, dxTrans);
|
|
4614
4999
|
}
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
requestedValue_1[keyPath] = additionalChanges_1[keyPath];
|
|
5000
|
+
else if (req.type === 'add' ||
|
|
5001
|
+
existingValue === undefined) {
|
|
5002
|
+
var generatedPrimaryKey = creating.fire.call(ctx, key, req.values[i], dxTrans);
|
|
5003
|
+
if (key == null && generatedPrimaryKey != null) {
|
|
5004
|
+
key = generatedPrimaryKey;
|
|
5005
|
+
req.keys[i] = key;
|
|
5006
|
+
if (!primaryKey.outbound) {
|
|
5007
|
+
setByKeyPath(req.values[i], primaryKey.keyPath, key);
|
|
4624
5008
|
}
|
|
4625
|
-
|
|
4626
|
-
setByKeyPath(requestedValue_1, keyPath, additionalChanges_1[keyPath]);
|
|
4627
|
-
}
|
|
4628
|
-
});
|
|
5009
|
+
}
|
|
4629
5010
|
}
|
|
4630
|
-
|
|
4631
|
-
|
|
5011
|
+
else {
|
|
5012
|
+
var objectDiff = getObjectDiff(existingValue, req.values[i]);
|
|
5013
|
+
var additionalChanges_1 = updating.fire.call(ctx, objectDiff, key, existingValue, dxTrans);
|
|
5014
|
+
if (additionalChanges_1) {
|
|
5015
|
+
var requestedValue_1 = req.values[i];
|
|
5016
|
+
Object.keys(additionalChanges_1).forEach(function (keyPath) {
|
|
5017
|
+
if (hasOwn(requestedValue_1, keyPath)) {
|
|
5018
|
+
requestedValue_1[keyPath] =
|
|
5019
|
+
additionalChanges_1[keyPath];
|
|
5020
|
+
}
|
|
5021
|
+
else {
|
|
5022
|
+
setByKeyPath(requestedValue_1, keyPath, additionalChanges_1[keyPath]);
|
|
5023
|
+
}
|
|
5024
|
+
});
|
|
5025
|
+
}
|
|
5026
|
+
}
|
|
5027
|
+
return ctx;
|
|
5028
|
+
});
|
|
5029
|
+
return downTable
|
|
5030
|
+
.mutate(req)
|
|
5031
|
+
.then(function (_a) {
|
|
5032
|
+
var failures = _a.failures, results = _a.results, numFailures = _a.numFailures, lastResult = _a.lastResult;
|
|
5033
|
+
for (var i = 0; i < keys.length; ++i) {
|
|
5034
|
+
var primKey = results ? results[i] : keys[i];
|
|
5035
|
+
var ctx = contexts[i];
|
|
5036
|
+
if (primKey == null) {
|
|
5037
|
+
ctx.onerror && ctx.onerror(failures[i]);
|
|
5038
|
+
}
|
|
5039
|
+
else {
|
|
5040
|
+
ctx.onsuccess &&
|
|
5041
|
+
ctx.onsuccess(req.type === 'put' && existingValues[i]
|
|
5042
|
+
? req.values[i]
|
|
5043
|
+
: primKey
|
|
5044
|
+
);
|
|
5045
|
+
}
|
|
5046
|
+
}
|
|
5047
|
+
return { failures: failures, results: results, numFailures: numFailures, lastResult: lastResult };
|
|
5048
|
+
})
|
|
5049
|
+
.catch(function (error) {
|
|
5050
|
+
contexts.forEach(function (ctx) { return ctx.onerror && ctx.onerror(error); });
|
|
5051
|
+
return Promise.reject(error);
|
|
5052
|
+
});
|
|
4632
5053
|
});
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
5054
|
+
}
|
|
5055
|
+
function deleteRange(req) {
|
|
5056
|
+
return deleteNextChunk(req.trans, req.range, 10000);
|
|
5057
|
+
}
|
|
5058
|
+
function deleteNextChunk(trans, range, limit) {
|
|
5059
|
+
return downTable
|
|
5060
|
+
.query({
|
|
5061
|
+
trans: trans,
|
|
5062
|
+
values: false,
|
|
5063
|
+
query: { index: primaryKey, range: range },
|
|
5064
|
+
limit: limit,
|
|
5065
|
+
})
|
|
5066
|
+
.then(function (_a) {
|
|
5067
|
+
var result = _a.result;
|
|
5068
|
+
return addPutOrDelete({
|
|
5069
|
+
type: 'delete',
|
|
5070
|
+
keys: result,
|
|
5071
|
+
trans: trans,
|
|
5072
|
+
}).then(function (res) {
|
|
5073
|
+
if (res.numFailures > 0)
|
|
5074
|
+
return Promise.reject(res.failures[0]);
|
|
5075
|
+
if (result.length < limit) {
|
|
5076
|
+
return {
|
|
5077
|
+
failures: [],
|
|
5078
|
+
numFailures: 0,
|
|
5079
|
+
lastResult: undefined,
|
|
5080
|
+
};
|
|
4640
5081
|
}
|
|
4641
5082
|
else {
|
|
4642
|
-
|
|
4643
|
-
req.values[i] :
|
|
4644
|
-
primKey
|
|
4645
|
-
);
|
|
5083
|
+
return deleteNextChunk(trans, __assign(__assign({}, range), { lower: result[result.length - 1], lowerOpen: true }), limit);
|
|
4646
5084
|
}
|
|
4647
|
-
}
|
|
4648
|
-
return { failures: failures, results: results, numFailures: numFailures, lastResult: lastResult };
|
|
4649
|
-
}).catch(function (error) {
|
|
4650
|
-
contexts.forEach(function (ctx) { return ctx.onerror && ctx.onerror(error); });
|
|
4651
|
-
return Promise.reject(error);
|
|
4652
|
-
});
|
|
4653
|
-
});
|
|
4654
|
-
}
|
|
4655
|
-
function deleteRange(req) {
|
|
4656
|
-
return deleteNextChunk(req.trans, req.range, 10000);
|
|
4657
|
-
}
|
|
4658
|
-
function deleteNextChunk(trans, range, limit) {
|
|
4659
|
-
return downTable.query({ trans: trans, values: false, query: { index: primaryKey, range: range }, limit: limit })
|
|
4660
|
-
.then(function (_a) {
|
|
4661
|
-
var result = _a.result;
|
|
4662
|
-
return addPutOrDelete({ type: 'delete', keys: result, trans: trans }).then(function (res) {
|
|
4663
|
-
if (res.numFailures > 0)
|
|
4664
|
-
return Promise.reject(res.failures[0]);
|
|
4665
|
-
if (result.length < limit) {
|
|
4666
|
-
return { failures: [], numFailures: 0, lastResult: undefined };
|
|
4667
|
-
}
|
|
4668
|
-
else {
|
|
4669
|
-
return deleteNextChunk(trans, __assign(__assign({}, range), { lower: result[result.length - 1], lowerOpen: true }), limit);
|
|
4670
|
-
}
|
|
5085
|
+
});
|
|
4671
5086
|
});
|
|
4672
|
-
}
|
|
4673
|
-
}
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
5087
|
+
}
|
|
5088
|
+
} });
|
|
5089
|
+
return tableMiddleware;
|
|
5090
|
+
} }));
|
|
5091
|
+
},
|
|
4677
5092
|
};
|
|
4678
5093
|
function getExistingValues(table, req, effectiveKeys) {
|
|
4679
|
-
return req.type ===
|
|
5094
|
+
return req.type === 'add'
|
|
4680
5095
|
? Promise.resolve([])
|
|
4681
|
-
: table.getMany({
|
|
5096
|
+
: table.getMany({
|
|
5097
|
+
trans: req.trans,
|
|
5098
|
+
keys: effectiveKeys,
|
|
5099
|
+
cache: 'immutable',
|
|
5100
|
+
});
|
|
4682
5101
|
}
|
|
4683
5102
|
|
|
4684
5103
|
function getFromTransactionCache(keys, cache, clone) {
|
|
@@ -4701,7 +5120,7 @@
|
|
|
4701
5120
|
}
|
|
4702
5121
|
}
|
|
4703
5122
|
var cacheExistingValuesMiddleware = {
|
|
4704
|
-
stack:
|
|
5123
|
+
stack: 'dbcore',
|
|
4705
5124
|
level: -1,
|
|
4706
5125
|
create: function (core) {
|
|
4707
5126
|
return {
|
|
@@ -4711,20 +5130,20 @@
|
|
|
4711
5130
|
if (!req.cache) {
|
|
4712
5131
|
return table.getMany(req);
|
|
4713
5132
|
}
|
|
4714
|
-
var cachedResult = getFromTransactionCache(req.keys, req.trans[
|
|
5133
|
+
var cachedResult = getFromTransactionCache(req.keys, req.trans['_cache'], req.cache === 'clone');
|
|
4715
5134
|
if (cachedResult) {
|
|
4716
5135
|
return DexiePromise.resolve(cachedResult);
|
|
4717
5136
|
}
|
|
4718
5137
|
return table.getMany(req).then(function (res) {
|
|
4719
|
-
req.trans[
|
|
5138
|
+
req.trans['_cache'] = {
|
|
4720
5139
|
keys: req.keys,
|
|
4721
|
-
values: req.cache ===
|
|
5140
|
+
values: req.cache === 'clone' ? deepClone(res) : res,
|
|
4722
5141
|
};
|
|
4723
5142
|
return res;
|
|
4724
5143
|
});
|
|
4725
5144
|
}, mutate: function (req) {
|
|
4726
|
-
if (req.type !==
|
|
4727
|
-
req.trans[
|
|
5145
|
+
if (req.type !== 'add')
|
|
5146
|
+
req.trans['_cache'] = null;
|
|
4728
5147
|
return table.mutate(req);
|
|
4729
5148
|
} });
|
|
4730
5149
|
},
|
|
@@ -4756,9 +5175,9 @@
|
|
|
4756
5175
|
}
|
|
4757
5176
|
|
|
4758
5177
|
var observabilityMiddleware = {
|
|
4759
|
-
stack:
|
|
5178
|
+
stack: 'dbcore',
|
|
4760
5179
|
level: 0,
|
|
4761
|
-
name:
|
|
5180
|
+
name: 'Observability',
|
|
4762
5181
|
create: function (core) {
|
|
4763
5182
|
var dbName = core.schema.name;
|
|
4764
5183
|
var FULL_RANGE = new RangeSet(core.MIN_KEY, core.MAX_KEY);
|
|
@@ -4772,7 +5191,11 @@
|
|
|
4772
5191
|
var schema = table.schema;
|
|
4773
5192
|
var primaryKey = schema.primaryKey, indexes = schema.indexes;
|
|
4774
5193
|
var extractKey = primaryKey.extractKey, outbound = primaryKey.outbound;
|
|
4775
|
-
var indexesWithAutoIncPK = primaryKey.autoIncrement &&
|
|
5194
|
+
var indexesWithAutoIncPK = primaryKey.autoIncrement &&
|
|
5195
|
+
indexes.filter(function (index) {
|
|
5196
|
+
return index.compound &&
|
|
5197
|
+
index.keyPath.includes(primaryKey.keyPath);
|
|
5198
|
+
});
|
|
4776
5199
|
var tableClone = __assign(__assign({}, table), { mutate: function (req) {
|
|
4777
5200
|
var _a, _b;
|
|
4778
5201
|
var trans = req.trans;
|
|
@@ -4782,20 +5205,25 @@
|
|
|
4782
5205
|
return (mutatedParts[part] ||
|
|
4783
5206
|
(mutatedParts[part] = new RangeSet()));
|
|
4784
5207
|
};
|
|
4785
|
-
var pkRangeSet = getRangeSet(
|
|
4786
|
-
var delsRangeSet = getRangeSet(
|
|
5208
|
+
var pkRangeSet = getRangeSet('');
|
|
5209
|
+
var delsRangeSet = getRangeSet(':dels');
|
|
4787
5210
|
var type = req.type;
|
|
4788
|
-
var _c = req.type ===
|
|
5211
|
+
var _c = req.type === 'deleteRange'
|
|
4789
5212
|
? [req.range]
|
|
4790
|
-
: req.type ===
|
|
5213
|
+
: req.type === 'delete'
|
|
4791
5214
|
? [req.keys]
|
|
4792
5215
|
: req.values.length < 50
|
|
4793
|
-
? [
|
|
5216
|
+
? [
|
|
5217
|
+
getEffectiveKeys(primaryKey, req).filter(function (id) { return id; }),
|
|
5218
|
+
req.values,
|
|
5219
|
+
]
|
|
4794
5220
|
: [], keys = _c[0], newObjs = _c[1];
|
|
4795
|
-
var oldCache = req.trans[
|
|
5221
|
+
var oldCache = req.trans['_cache'];
|
|
4796
5222
|
if (isArray(keys)) {
|
|
4797
5223
|
pkRangeSet.addKeys(keys);
|
|
4798
|
-
var oldObjs = type === 'delete' || keys.length === newObjs.length
|
|
5224
|
+
var oldObjs = type === 'delete' || keys.length === newObjs.length
|
|
5225
|
+
? getFromTransactionCache(keys, oldCache)
|
|
5226
|
+
: null;
|
|
4799
5227
|
if (!oldObjs) {
|
|
4800
5228
|
delsRangeSet.addKeys(keys);
|
|
4801
5229
|
}
|
|
@@ -4806,7 +5234,7 @@
|
|
|
4806
5234
|
else if (keys) {
|
|
4807
5235
|
var range = {
|
|
4808
5236
|
from: (_a = keys.lower) !== null && _a !== void 0 ? _a : core.MIN_KEY,
|
|
4809
|
-
to: (_b = keys.upper) !== null && _b !== void 0 ? _b : core.MAX_KEY
|
|
5237
|
+
to: (_b = keys.upper) !== null && _b !== void 0 ? _b : core.MAX_KEY,
|
|
4810
5238
|
};
|
|
4811
5239
|
delsRangeSet.add(range);
|
|
4812
5240
|
pkRangeSet.add(range);
|
|
@@ -4814,7 +5242,9 @@
|
|
|
4814
5242
|
else {
|
|
4815
5243
|
pkRangeSet.add(FULL_RANGE);
|
|
4816
5244
|
delsRangeSet.add(FULL_RANGE);
|
|
4817
|
-
schema.indexes.forEach(function (idx) {
|
|
5245
|
+
schema.indexes.forEach(function (idx) {
|
|
5246
|
+
return getRangeSet(idx.name).add(FULL_RANGE);
|
|
5247
|
+
});
|
|
4818
5248
|
}
|
|
4819
5249
|
return table.mutate(req).then(function (res) {
|
|
4820
5250
|
if (keys && (req.type === 'add' || req.type === 'put')) {
|
|
@@ -4853,9 +5283,10 @@
|
|
|
4853
5283
|
tableClone[method] = function (req) {
|
|
4854
5284
|
var subscr = PSD.subscr;
|
|
4855
5285
|
var isLiveQuery = !!subscr;
|
|
4856
|
-
var cachable = isCachableContext(PSD, table) &&
|
|
5286
|
+
var cachable = isCachableContext(PSD, table) &&
|
|
5287
|
+
isCachableRequest(method, req);
|
|
4857
5288
|
var obsSet = cachable
|
|
4858
|
-
? req.obsSet = {}
|
|
5289
|
+
? (req.obsSet = {})
|
|
4859
5290
|
: subscr;
|
|
4860
5291
|
if (isLiveQuery) {
|
|
4861
5292
|
var getRangeSet = function (indexName) {
|
|
@@ -4863,26 +5294,28 @@
|
|
|
4863
5294
|
return (obsSet[part] ||
|
|
4864
5295
|
(obsSet[part] = new RangeSet()));
|
|
4865
5296
|
};
|
|
4866
|
-
var pkRangeSet_1 = getRangeSet(
|
|
4867
|
-
var delsRangeSet_1 = getRangeSet(
|
|
5297
|
+
var pkRangeSet_1 = getRangeSet('');
|
|
5298
|
+
var delsRangeSet_1 = getRangeSet(':dels');
|
|
4868
5299
|
var _a = readSubscribers[method](req), queriedIndex = _a[0], queriedRanges = _a[1];
|
|
4869
|
-
if (method === 'query' &&
|
|
5300
|
+
if (method === 'query' &&
|
|
5301
|
+
queriedIndex.isPrimaryKey &&
|
|
5302
|
+
!req.values) {
|
|
4870
5303
|
delsRangeSet_1.add(queriedRanges);
|
|
4871
5304
|
}
|
|
4872
5305
|
else {
|
|
4873
|
-
getRangeSet(queriedIndex.name ||
|
|
5306
|
+
getRangeSet(queriedIndex.name || '').add(queriedRanges);
|
|
4874
5307
|
}
|
|
4875
5308
|
if (!queriedIndex.isPrimaryKey) {
|
|
4876
|
-
if (method ===
|
|
5309
|
+
if (method === 'count') {
|
|
4877
5310
|
delsRangeSet_1.add(FULL_RANGE);
|
|
4878
5311
|
}
|
|
4879
5312
|
else {
|
|
4880
|
-
var keysPromise_1 = method ===
|
|
5313
|
+
var keysPromise_1 = method === 'query' &&
|
|
4881
5314
|
outbound &&
|
|
4882
5315
|
req.values &&
|
|
4883
5316
|
table.query(__assign(__assign({}, req), { values: false }));
|
|
4884
5317
|
return table[method].apply(this, arguments).then(function (res) {
|
|
4885
|
-
if (method ===
|
|
5318
|
+
if (method === 'query') {
|
|
4886
5319
|
if (outbound && req.values) {
|
|
4887
5320
|
return keysPromise_1.then(function (_a) {
|
|
4888
5321
|
var resultingKeys = _a.result;
|
|
@@ -4900,9 +5333,10 @@
|
|
|
4900
5333
|
delsRangeSet_1.addKeys(pKeys);
|
|
4901
5334
|
}
|
|
4902
5335
|
}
|
|
4903
|
-
else if (method ===
|
|
5336
|
+
else if (method === 'openCursor') {
|
|
4904
5337
|
var cursor_1 = res;
|
|
4905
|
-
var wantValues_1 = req
|
|
5338
|
+
var wantValues_1 = req
|
|
5339
|
+
.values;
|
|
4906
5340
|
return (cursor_1 &&
|
|
4907
5341
|
Object.create(cursor_1, {
|
|
4908
5342
|
key: {
|
|
@@ -4920,7 +5354,8 @@
|
|
|
4920
5354
|
},
|
|
4921
5355
|
value: {
|
|
4922
5356
|
get: function () {
|
|
4923
|
-
wantValues_1 &&
|
|
5357
|
+
wantValues_1 &&
|
|
5358
|
+
pkRangeSet_1.addKey(cursor_1.primaryKey);
|
|
4924
5359
|
return cursor_1.value;
|
|
4925
5360
|
},
|
|
4926
5361
|
},
|
|
@@ -4940,13 +5375,17 @@
|
|
|
4940
5375
|
};
|
|
4941
5376
|
function trackAffectedIndexes(getRangeSet, schema, oldObjs, newObjs) {
|
|
4942
5377
|
function addAffectedIndex(ix) {
|
|
4943
|
-
var rangeSet = getRangeSet(ix.name ||
|
|
5378
|
+
var rangeSet = getRangeSet(ix.name || '');
|
|
4944
5379
|
function extractKey(obj) {
|
|
4945
5380
|
return obj != null ? ix.extractKey(obj) : null;
|
|
4946
5381
|
}
|
|
4947
|
-
var addKeyOrKeys = function (key) {
|
|
4948
|
-
|
|
4949
|
-
|
|
5382
|
+
var addKeyOrKeys = function (key) {
|
|
5383
|
+
return ix.multiEntry && isArray(key)
|
|
5384
|
+
?
|
|
5385
|
+
key.forEach(function (key) { return rangeSet.addKey(key); })
|
|
5386
|
+
:
|
|
5387
|
+
rangeSet.addKey(key);
|
|
5388
|
+
};
|
|
4950
5389
|
(oldObjs || newObjs).forEach(function (_, i) {
|
|
4951
5390
|
var oldKey = oldObjs && extractKey(oldObjs[i]);
|
|
4952
5391
|
var newKey = newObjs && extractKey(newObjs[i]);
|
|
@@ -5160,7 +5599,8 @@
|
|
|
5160
5599
|
var _a;
|
|
5161
5600
|
return entry.req.limit === req.limit &&
|
|
5162
5601
|
entry.req.values === req.values &&
|
|
5163
|
-
((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') ===
|
|
5602
|
+
((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') ===
|
|
5603
|
+
reqDirection_1 &&
|
|
5164
5604
|
areRangesEqual(entry.req.query.range, req.query.range);
|
|
5165
5605
|
});
|
|
5166
5606
|
if (equalEntry)
|
|
@@ -5174,7 +5614,8 @@
|
|
|
5174
5614
|
var _a;
|
|
5175
5615
|
var limit = 'limit' in entry.req ? entry.req.limit : Infinity;
|
|
5176
5616
|
return (limit >= req.limit &&
|
|
5177
|
-
((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') ===
|
|
5617
|
+
((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') ===
|
|
5618
|
+
reqDirection_1 &&
|
|
5178
5619
|
(req.values ? entry.req.values : true) &&
|
|
5179
5620
|
isSuperRange(entry.req.query.range, req.query.range));
|
|
5180
5621
|
});
|
|
@@ -5189,7 +5630,7 @@
|
|
|
5189
5630
|
|
|
5190
5631
|
function subscribeToCacheEntry(cacheEntry, container, requery, signal) {
|
|
5191
5632
|
cacheEntry.subscribers.add(requery);
|
|
5192
|
-
signal.addEventListener(
|
|
5633
|
+
signal.addEventListener('abort', function () {
|
|
5193
5634
|
cacheEntry.subscribers.delete(requery);
|
|
5194
5635
|
if (cacheEntry.subscribers.size === 0) {
|
|
5195
5636
|
enqueForDeletion(cacheEntry, container);
|
|
@@ -5225,14 +5666,18 @@
|
|
|
5225
5666
|
if (tblCache) {
|
|
5226
5667
|
var table = core.table(storeName);
|
|
5227
5668
|
var ops = tblCache.optimisticOps.filter(function (op) { return op.trans === idbtrans; });
|
|
5228
|
-
if (idbtrans._explicit &&
|
|
5669
|
+
if (idbtrans._explicit &&
|
|
5670
|
+
wasCommitted &&
|
|
5671
|
+
idbtrans.mutatedParts) {
|
|
5229
5672
|
for (var _a = 0, _b = Object.values(tblCache.queries.query); _a < _b.length; _a++) {
|
|
5230
5673
|
var entries = _b[_a];
|
|
5231
5674
|
for (var _c = 0, _d = entries.slice(); _c < _d.length; _c++) {
|
|
5232
5675
|
var entry = _d[_c];
|
|
5233
5676
|
if (obsSetsOverlap(entry.obsSet, idbtrans.mutatedParts)) {
|
|
5234
5677
|
delArrayItem(entries, entry);
|
|
5235
|
-
entry.subscribers.forEach(function (requery) {
|
|
5678
|
+
entry.subscribers.forEach(function (requery) {
|
|
5679
|
+
return affectedSubscribers_1.add(requery);
|
|
5680
|
+
});
|
|
5236
5681
|
}
|
|
5237
5682
|
}
|
|
5238
5683
|
}
|
|
@@ -5251,18 +5696,24 @@
|
|
|
5251
5696
|
var modRes = applyOptimisticOps(entry.res, entry.req, ops, table, entry, freezeResults);
|
|
5252
5697
|
if (entry.dirty) {
|
|
5253
5698
|
delArrayItem(entries, entry);
|
|
5254
|
-
entry.subscribers.forEach(function (requery) {
|
|
5699
|
+
entry.subscribers.forEach(function (requery) {
|
|
5700
|
+
return affectedSubscribers_1.add(requery);
|
|
5701
|
+
});
|
|
5255
5702
|
}
|
|
5256
5703
|
else if (modRes !== entry.res) {
|
|
5257
5704
|
entry.res = modRes;
|
|
5258
|
-
entry.promise = DexiePromise.resolve({
|
|
5705
|
+
entry.promise = DexiePromise.resolve({
|
|
5706
|
+
result: modRes,
|
|
5707
|
+
});
|
|
5259
5708
|
}
|
|
5260
5709
|
}
|
|
5261
5710
|
else {
|
|
5262
5711
|
if (entry.dirty) {
|
|
5263
5712
|
delArrayItem(entries, entry);
|
|
5264
5713
|
}
|
|
5265
|
-
entry.subscribers.forEach(function (requery) {
|
|
5714
|
+
entry.subscribers.forEach(function (requery) {
|
|
5715
|
+
return affectedSubscribers_1.add(requery);
|
|
5716
|
+
});
|
|
5266
5717
|
}
|
|
5267
5718
|
}
|
|
5268
5719
|
}
|
|
@@ -5300,7 +5751,9 @@
|
|
|
5300
5751
|
if (!tblCache)
|
|
5301
5752
|
return downTable.mutate(req);
|
|
5302
5753
|
var promise = downTable.mutate(req);
|
|
5303
|
-
if ((req.type === 'add' || req.type === 'put') &&
|
|
5754
|
+
if ((req.type === 'add' || req.type === 'put') &&
|
|
5755
|
+
(req.values.length >= 50 ||
|
|
5756
|
+
getEffectiveKeys(primKey, req).some(function (key) { return key == null; }))) {
|
|
5304
5757
|
promise.then(function (res) {
|
|
5305
5758
|
var reqWithResolvedKeys = __assign(__assign({}, req), { values: req.values.map(function (value, i) {
|
|
5306
5759
|
var _a;
|
|
@@ -5314,7 +5767,10 @@
|
|
|
5314
5767
|
}) });
|
|
5315
5768
|
var adjustedReq = adjustOptimisticFromFailures(tblCache, reqWithResolvedKeys, res);
|
|
5316
5769
|
tblCache.optimisticOps.push(adjustedReq);
|
|
5317
|
-
queueMicrotask(function () {
|
|
5770
|
+
queueMicrotask(function () {
|
|
5771
|
+
return req.mutatedParts &&
|
|
5772
|
+
signalSubscribersLazily(req.mutatedParts);
|
|
5773
|
+
});
|
|
5318
5774
|
});
|
|
5319
5775
|
}
|
|
5320
5776
|
else {
|
|
@@ -5338,16 +5794,20 @@
|
|
|
5338
5794
|
return promise;
|
|
5339
5795
|
}, query: function (req) {
|
|
5340
5796
|
var _a;
|
|
5341
|
-
if (!isCachableContext(PSD, downTable) ||
|
|
5797
|
+
if (!isCachableContext(PSD, downTable) ||
|
|
5798
|
+
!isCachableRequest('query', req))
|
|
5342
5799
|
return downTable.query(req);
|
|
5343
|
-
var freezeResults = ((_a = PSD.trans) === null || _a === void 0 ? void 0 : _a.db._options.cache) ===
|
|
5800
|
+
var freezeResults = ((_a = PSD.trans) === null || _a === void 0 ? void 0 : _a.db._options.cache) ===
|
|
5801
|
+
'immutable';
|
|
5344
5802
|
var _b = PSD, requery = _b.requery, signal = _b.signal;
|
|
5345
5803
|
var _c = findCompatibleQuery(dbName, tableName, 'query', req), cacheEntry = _c[0], exactMatch = _c[1], tblCache = _c[2], container = _c[3];
|
|
5346
5804
|
if (cacheEntry && exactMatch) {
|
|
5347
5805
|
cacheEntry.obsSet = req.obsSet;
|
|
5348
5806
|
}
|
|
5349
5807
|
else {
|
|
5350
|
-
var promise = downTable
|
|
5808
|
+
var promise = downTable
|
|
5809
|
+
.query(req)
|
|
5810
|
+
.then(function (res) {
|
|
5351
5811
|
var result = res.result;
|
|
5352
5812
|
if (cacheEntry)
|
|
5353
5813
|
cacheEntry.res = result;
|
|
@@ -5361,7 +5821,8 @@
|
|
|
5361
5821
|
res.result = deepClone(result);
|
|
5362
5822
|
}
|
|
5363
5823
|
return res;
|
|
5364
|
-
})
|
|
5824
|
+
})
|
|
5825
|
+
.catch(function (error) {
|
|
5365
5826
|
if (container && cacheEntry)
|
|
5366
5827
|
delArrayItem(container, cacheEntry);
|
|
5367
5828
|
return Promise.reject(error);
|
|
@@ -5387,7 +5848,7 @@
|
|
|
5387
5848
|
},
|
|
5388
5849
|
objs: new Map(),
|
|
5389
5850
|
optimisticOps: [],
|
|
5390
|
-
unsignaledParts: {}
|
|
5851
|
+
unsignaledParts: {},
|
|
5391
5852
|
};
|
|
5392
5853
|
}
|
|
5393
5854
|
tblCache.queries.query[req.query.index.name || ''] = container;
|
|
@@ -5412,7 +5873,7 @@
|
|
|
5412
5873
|
if (prop === 'db')
|
|
5413
5874
|
return vipDb;
|
|
5414
5875
|
return Reflect.get(target, prop, receiver);
|
|
5415
|
-
}
|
|
5876
|
+
},
|
|
5416
5877
|
});
|
|
5417
5878
|
}
|
|
5418
5879
|
|
|
@@ -5427,7 +5888,7 @@
|
|
|
5427
5888
|
indexedDB: deps.indexedDB, IDBKeyRange: deps.IDBKeyRange, cache: 'cloned', maxConnections: DEFAULT_MAX_CONNECTIONS }, options);
|
|
5428
5889
|
this._deps = {
|
|
5429
5890
|
indexedDB: options.indexedDB,
|
|
5430
|
-
IDBKeyRange: options.IDBKeyRange
|
|
5891
|
+
IDBKeyRange: options.IDBKeyRange,
|
|
5431
5892
|
};
|
|
5432
5893
|
var addons = options.addons;
|
|
5433
5894
|
this._dbSchema = {};
|
|
@@ -5457,7 +5918,9 @@
|
|
|
5457
5918
|
});
|
|
5458
5919
|
this._state = state;
|
|
5459
5920
|
this.name = name;
|
|
5460
|
-
this.on = Events(this,
|
|
5921
|
+
this.on = Events(this, 'populate', 'blocked', 'versionchange', 'close', {
|
|
5922
|
+
ready: [promisableChain, nop],
|
|
5923
|
+
});
|
|
5461
5924
|
this.once = function (event, callback) {
|
|
5462
5925
|
var fn = function () {
|
|
5463
5926
|
var args = [];
|
|
@@ -5501,26 +5964,29 @@
|
|
|
5501
5964
|
this.Transaction = createTransactionConstructor(this);
|
|
5502
5965
|
this.Version = createVersionConstructor(this);
|
|
5503
5966
|
this.WhereClause = createWhereClauseConstructor(this);
|
|
5504
|
-
this.on(
|
|
5967
|
+
this.on('versionchange', function (ev) {
|
|
5505
5968
|
if (ev.newVersion > 0)
|
|
5506
5969
|
console.warn("Another connection wants to upgrade database '".concat(_this.name, "'. Closing db now to resume the upgrade."));
|
|
5507
5970
|
else
|
|
5508
5971
|
console.warn("Another connection wants to delete database '".concat(_this.name, "'. Closing db now to resume the delete request."));
|
|
5509
5972
|
_this.close({ disableAutoOpen: false });
|
|
5510
5973
|
});
|
|
5511
|
-
this.on(
|
|
5974
|
+
this.on('blocked', function (ev) {
|
|
5512
5975
|
if (!ev.newVersion || ev.newVersion < ev.oldVersion)
|
|
5513
5976
|
console.warn("Dexie.delete('".concat(_this.name, "') was blocked"));
|
|
5514
5977
|
else
|
|
5515
5978
|
console.warn("Upgrade '".concat(_this.name, "' blocked by other connection holding version ").concat(ev.oldVersion / 10));
|
|
5516
5979
|
});
|
|
5517
5980
|
this._maxKey = getMaxKey(options.IDBKeyRange);
|
|
5518
|
-
this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) {
|
|
5981
|
+
this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) {
|
|
5982
|
+
return new _this.Transaction(mode, storeNames, dbschema, _this._options.chromeTransactionDurability, parentTransaction);
|
|
5983
|
+
};
|
|
5519
5984
|
this._fireOnBlocked = function (ev) {
|
|
5520
|
-
_this.on(
|
|
5521
|
-
connections
|
|
5985
|
+
_this.on('blocked').fire(ev);
|
|
5986
|
+
connections
|
|
5987
|
+
.toArray()
|
|
5522
5988
|
.filter(function (c) { return c.name === _this.name && c !== _this && !c._state.vcFired; })
|
|
5523
|
-
.map(function (c) { return c.on(
|
|
5989
|
+
.map(function (c) { return c.on('versionchange').fire(ev); });
|
|
5524
5990
|
};
|
|
5525
5991
|
this.use(cacheExistingValuesMiddleware);
|
|
5526
5992
|
this.use(cacheMiddleware);
|
|
@@ -5544,7 +6010,7 @@
|
|
|
5544
6010
|
return vipify(tx, vipDB);
|
|
5545
6011
|
};
|
|
5546
6012
|
return rv;
|
|
5547
|
-
}
|
|
6013
|
+
},
|
|
5548
6014
|
});
|
|
5549
6015
|
this.vip = vipDB;
|
|
5550
6016
|
addons.forEach(function (addon) { return addon(_this); });
|
|
@@ -5554,7 +6020,7 @@
|
|
|
5554
6020
|
throw new exceptions.Type("Given version is not a positive number");
|
|
5555
6021
|
versionNumber = Math.round(versionNumber * 10) / 10;
|
|
5556
6022
|
if (this.idbdb || this._state.isBeingOpened)
|
|
5557
|
-
throw new exceptions.Schema(
|
|
6023
|
+
throw new exceptions.Schema('Cannot add version when database is open');
|
|
5558
6024
|
this.verno = Math.max(this.verno, versionNumber);
|
|
5559
6025
|
var versions = this._versions;
|
|
5560
6026
|
var versionInstance = versions.filter(function (v) { return v._cfg.version === versionNumber; })[0];
|
|
@@ -5569,26 +6035,34 @@
|
|
|
5569
6035
|
};
|
|
5570
6036
|
Dexie.prototype._whenReady = function (fn) {
|
|
5571
6037
|
var _this = this;
|
|
5572
|
-
return
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
reject(new exceptions.DatabaseClosed());
|
|
5579
|
-
return;
|
|
6038
|
+
return this.idbdb &&
|
|
6039
|
+
(this._state.openComplete || PSD.letThrough || this._vip)
|
|
6040
|
+
? fn()
|
|
6041
|
+
: new DexiePromise(function (resolve, reject) {
|
|
6042
|
+
if (_this._state.openComplete) {
|
|
6043
|
+
return reject(new exceptions.DatabaseClosed(_this._state.dbOpenError));
|
|
5580
6044
|
}
|
|
5581
|
-
_this.
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
6045
|
+
if (!_this._state.isBeingOpened) {
|
|
6046
|
+
if (!_this._state.autoOpen) {
|
|
6047
|
+
reject(new exceptions.DatabaseClosed());
|
|
6048
|
+
return;
|
|
6049
|
+
}
|
|
6050
|
+
_this.open().catch(nop);
|
|
6051
|
+
}
|
|
6052
|
+
_this._state.dbReadyPromise.then(resolve, reject);
|
|
6053
|
+
}).then(fn);
|
|
5585
6054
|
};
|
|
5586
6055
|
Dexie.prototype.use = function (_a) {
|
|
5587
6056
|
var stack = _a.stack, create = _a.create, level = _a.level, name = _a.name;
|
|
5588
6057
|
if (name)
|
|
5589
6058
|
this.unuse({ stack: stack, name: name });
|
|
5590
6059
|
var middlewares = this._middlewares[stack] || (this._middlewares[stack] = []);
|
|
5591
|
-
middlewares.push({
|
|
6060
|
+
middlewares.push({
|
|
6061
|
+
stack: stack,
|
|
6062
|
+
create: create,
|
|
6063
|
+
level: level == null ? 10 : level,
|
|
6064
|
+
name: name,
|
|
6065
|
+
});
|
|
5592
6066
|
middlewares.sort(function (a, b) { return a.level - b.level; });
|
|
5593
6067
|
return this;
|
|
5594
6068
|
};
|
|
@@ -5596,9 +6070,11 @@
|
|
|
5596
6070
|
var stack = _a.stack, name = _a.name, create = _a.create;
|
|
5597
6071
|
if (stack && this._middlewares[stack]) {
|
|
5598
6072
|
this._middlewares[stack] = this._middlewares[stack].filter(function (mw) {
|
|
5599
|
-
return create
|
|
5600
|
-
|
|
5601
|
-
|
|
6073
|
+
return create
|
|
6074
|
+
? mw.create !== create
|
|
6075
|
+
: name
|
|
6076
|
+
? mw.name !== name
|
|
6077
|
+
: false;
|
|
5602
6078
|
});
|
|
5603
6079
|
}
|
|
5604
6080
|
return this;
|
|
@@ -5641,8 +6117,7 @@
|
|
|
5641
6117
|
}
|
|
5642
6118
|
else {
|
|
5643
6119
|
this._close();
|
|
5644
|
-
state.autoOpen = this._options.autoOpen ||
|
|
5645
|
-
state.isBeingOpened;
|
|
6120
|
+
state.autoOpen = this._options.autoOpen || state.isBeingOpened;
|
|
5646
6121
|
state.openComplete = false;
|
|
5647
6122
|
state.dbOpenError = null;
|
|
5648
6123
|
}
|
|
@@ -5664,7 +6139,7 @@
|
|
|
5664
6139
|
req.onblocked = _this._fireOnBlocked;
|
|
5665
6140
|
};
|
|
5666
6141
|
if (hasInvalidArguments)
|
|
5667
|
-
throw new exceptions.InvalidArgument(
|
|
6142
|
+
throw new exceptions.InvalidArgument('Invalid closeOptions argument to db.delete()');
|
|
5668
6143
|
if (state.isBeingOpened) {
|
|
5669
6144
|
state.dbReadyPromise.then(doDelete);
|
|
5670
6145
|
}
|
|
@@ -5681,7 +6156,7 @@
|
|
|
5681
6156
|
};
|
|
5682
6157
|
Dexie.prototype.hasBeenClosed = function () {
|
|
5683
6158
|
var dbOpenError = this._state.dbOpenError;
|
|
5684
|
-
return dbOpenError &&
|
|
6159
|
+
return dbOpenError && dbOpenError.name === 'DatabaseClosed';
|
|
5685
6160
|
};
|
|
5686
6161
|
Dexie.prototype.hasFailed = function () {
|
|
5687
6162
|
return this._state.dbOpenError !== null;
|
|
@@ -5704,7 +6179,9 @@
|
|
|
5704
6179
|
Dexie.prototype._transaction = function (mode, tables, scopeFunc) {
|
|
5705
6180
|
var _this = this;
|
|
5706
6181
|
var parentTransaction = PSD.trans;
|
|
5707
|
-
if (!parentTransaction ||
|
|
6182
|
+
if (!parentTransaction ||
|
|
6183
|
+
parentTransaction.db !== this ||
|
|
6184
|
+
mode.indexOf('!') !== -1)
|
|
5708
6185
|
parentTransaction = null;
|
|
5709
6186
|
var onlyIfCompatible = mode.indexOf('?') !== -1;
|
|
5710
6187
|
mode = mode.replace('!', '').replace('?', '');
|
|
@@ -5713,51 +6190,56 @@
|
|
|
5713
6190
|
storeNames = tables.map(function (table) {
|
|
5714
6191
|
var storeName = table instanceof _this.Table ? table.name : table;
|
|
5715
6192
|
if (typeof storeName !== 'string')
|
|
5716
|
-
throw new TypeError(
|
|
6193
|
+
throw new TypeError('Invalid table argument to Dexie.transaction(). Only Table or String are allowed');
|
|
5717
6194
|
return storeName;
|
|
5718
6195
|
});
|
|
5719
|
-
if (mode ==
|
|
6196
|
+
if (mode == 'r' || mode === READONLY)
|
|
5720
6197
|
idbMode = READONLY;
|
|
5721
|
-
else if (mode ==
|
|
6198
|
+
else if (mode == 'rw' || mode == READWRITE)
|
|
5722
6199
|
idbMode = READWRITE;
|
|
5723
6200
|
else
|
|
5724
|
-
throw new exceptions.InvalidArgument(
|
|
6201
|
+
throw new exceptions.InvalidArgument('Invalid transaction mode: ' + mode);
|
|
5725
6202
|
if (parentTransaction) {
|
|
5726
6203
|
if (parentTransaction.mode === READONLY && idbMode === READWRITE) {
|
|
5727
6204
|
if (onlyIfCompatible) {
|
|
5728
6205
|
parentTransaction = null;
|
|
5729
6206
|
}
|
|
5730
6207
|
else
|
|
5731
|
-
throw new exceptions.SubTransaction(
|
|
6208
|
+
throw new exceptions.SubTransaction('Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY');
|
|
5732
6209
|
}
|
|
5733
6210
|
if (parentTransaction) {
|
|
5734
6211
|
storeNames.forEach(function (storeName) {
|
|
5735
|
-
if (parentTransaction &&
|
|
6212
|
+
if (parentTransaction &&
|
|
6213
|
+
parentTransaction.storeNames.indexOf(storeName) === -1) {
|
|
5736
6214
|
if (onlyIfCompatible) {
|
|
5737
6215
|
parentTransaction = null;
|
|
5738
6216
|
}
|
|
5739
6217
|
else
|
|
5740
|
-
throw new exceptions.SubTransaction(
|
|
5741
|
-
" not included in parent transaction.");
|
|
6218
|
+
throw new exceptions.SubTransaction('Table ' + storeName + ' not included in parent transaction.');
|
|
5742
6219
|
}
|
|
5743
6220
|
});
|
|
5744
6221
|
}
|
|
5745
|
-
if (onlyIfCompatible &&
|
|
6222
|
+
if (onlyIfCompatible &&
|
|
6223
|
+
parentTransaction &&
|
|
6224
|
+
!parentTransaction.active) {
|
|
5746
6225
|
parentTransaction = null;
|
|
5747
6226
|
}
|
|
5748
6227
|
}
|
|
5749
6228
|
}
|
|
5750
6229
|
catch (e) {
|
|
5751
|
-
return parentTransaction
|
|
5752
|
-
parentTransaction._promise(null, function (_, reject) {
|
|
5753
|
-
|
|
6230
|
+
return parentTransaction
|
|
6231
|
+
? parentTransaction._promise(null, function (_, reject) {
|
|
6232
|
+
reject(e);
|
|
6233
|
+
})
|
|
6234
|
+
: rejection(e);
|
|
5754
6235
|
}
|
|
5755
6236
|
var enterTransaction = enterTransactionScope.bind(null, this, idbMode, storeNames, parentTransaction, scopeFunc);
|
|
5756
|
-
return
|
|
5757
|
-
parentTransaction._promise(idbMode, enterTransaction,
|
|
5758
|
-
PSD.trans
|
|
5759
|
-
|
|
5760
|
-
|
|
6237
|
+
return parentTransaction
|
|
6238
|
+
? parentTransaction._promise(idbMode, enterTransaction, 'lock')
|
|
6239
|
+
: PSD.trans
|
|
6240
|
+
?
|
|
6241
|
+
usePSD(PSD.transless, function () { return _this._whenReady(enterTransaction); })
|
|
6242
|
+
: this._whenReady(enterTransaction);
|
|
5761
6243
|
};
|
|
5762
6244
|
Dexie.prototype.table = function (tableName) {
|
|
5763
6245
|
if (!hasOwn(this._allTables, tableName)) {
|
|
@@ -5768,15 +6250,15 @@
|
|
|
5768
6250
|
return Dexie;
|
|
5769
6251
|
}());
|
|
5770
6252
|
|
|
5771
|
-
var symbolObservable = typeof Symbol !==
|
|
6253
|
+
var symbolObservable = typeof Symbol !== 'undefined' && 'observable' in Symbol
|
|
5772
6254
|
? Symbol.observable
|
|
5773
|
-
:
|
|
6255
|
+
: '@@observable';
|
|
5774
6256
|
var Observable = (function () {
|
|
5775
6257
|
function Observable(subscribe) {
|
|
5776
6258
|
this._subscribe = subscribe;
|
|
5777
6259
|
}
|
|
5778
6260
|
Observable.prototype.subscribe = function (x, error, complete) {
|
|
5779
|
-
return this._subscribe(!x || typeof x ===
|
|
6261
|
+
return this._subscribe(!x || typeof x === 'function' ? { next: x, error: error, complete: complete } : x);
|
|
5780
6262
|
};
|
|
5781
6263
|
Observable.prototype[symbolObservable] = function () {
|
|
5782
6264
|
return this;
|
|
@@ -5787,8 +6269,11 @@
|
|
|
5787
6269
|
var domDeps;
|
|
5788
6270
|
try {
|
|
5789
6271
|
domDeps = {
|
|
5790
|
-
indexedDB: _global.indexedDB ||
|
|
5791
|
-
|
|
6272
|
+
indexedDB: _global.indexedDB ||
|
|
6273
|
+
_global.mozIndexedDB ||
|
|
6274
|
+
_global.webkitIndexedDB ||
|
|
6275
|
+
_global.msIndexedDB,
|
|
6276
|
+
IDBKeyRange: _global.IDBKeyRange || _global.webkitIDBKeyRange,
|
|
5792
6277
|
};
|
|
5793
6278
|
}
|
|
5794
6279
|
catch (e) {
|
|
@@ -5862,22 +6347,32 @@
|
|
|
5862
6347
|
signal: abortController.signal,
|
|
5863
6348
|
requery: doQuery,
|
|
5864
6349
|
querier: querier,
|
|
5865
|
-
trans: null
|
|
6350
|
+
trans: null,
|
|
5866
6351
|
};
|
|
5867
6352
|
var ret = execute(ctx);
|
|
6353
|
+
if (!startedListening) {
|
|
6354
|
+
globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, mutationListener);
|
|
6355
|
+
startedListening = true;
|
|
6356
|
+
}
|
|
5868
6357
|
Promise.resolve(ret).then(function (result) {
|
|
5869
6358
|
hasValue = true;
|
|
5870
6359
|
currentValue = result;
|
|
5871
6360
|
if (closed || ctx.signal.aborted) {
|
|
5872
6361
|
return;
|
|
5873
6362
|
}
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
6363
|
+
if (shouldNotify()) {
|
|
6364
|
+
doQuery();
|
|
6365
|
+
}
|
|
6366
|
+
else {
|
|
6367
|
+
currentObs = subscr;
|
|
6368
|
+
if (shouldNotify()) {
|
|
6369
|
+
doQuery();
|
|
6370
|
+
}
|
|
6371
|
+
else {
|
|
6372
|
+
accumMuts = {};
|
|
6373
|
+
execInGlobalContext(function () { return !closed && observer.next && observer.next(result); });
|
|
6374
|
+
}
|
|
5879
6375
|
}
|
|
5880
|
-
execInGlobalContext(function () { return !closed && observer.next && observer.next(result); });
|
|
5881
6376
|
}, function (err) {
|
|
5882
6377
|
hasValue = false;
|
|
5883
6378
|
if (!['DatabaseClosedError', 'AbortError'].includes(err === null || err === void 0 ? void 0 : err.name)) {
|
|
@@ -5905,10 +6400,13 @@
|
|
|
5905
6400
|
return db.delete();
|
|
5906
6401
|
},
|
|
5907
6402
|
exists: function (name) {
|
|
5908
|
-
return new Dexie(name, { addons: [] })
|
|
6403
|
+
return new Dexie(name, { addons: [] })
|
|
6404
|
+
.open()
|
|
6405
|
+
.then(function (db) {
|
|
5909
6406
|
db.close();
|
|
5910
6407
|
return true;
|
|
5911
|
-
})
|
|
6408
|
+
})
|
|
6409
|
+
.catch('NoSuchDatabaseError', function () { return false; });
|
|
5912
6410
|
},
|
|
5913
6411
|
getDatabaseNames: function (cb) {
|
|
5914
6412
|
try {
|
|
@@ -5924,9 +6422,9 @@
|
|
|
5924
6422
|
}
|
|
5925
6423
|
return Class;
|
|
5926
6424
|
}, ignoreTransaction: function (scopeFunc) {
|
|
5927
|
-
return PSD.trans
|
|
5928
|
-
usePSD(PSD.transless, scopeFunc)
|
|
5929
|
-
scopeFunc();
|
|
6425
|
+
return PSD.trans
|
|
6426
|
+
? usePSD(PSD.transless || globalPSD, scopeFunc)
|
|
6427
|
+
: scopeFunc();
|
|
5930
6428
|
}, vip: vip, async: function (generatorFn) {
|
|
5931
6429
|
return function () {
|
|
5932
6430
|
try {
|
|
@@ -5951,22 +6449,19 @@
|
|
|
5951
6449
|
}
|
|
5952
6450
|
},
|
|
5953
6451
|
currentTransaction: {
|
|
5954
|
-
get: function () { return PSD.trans || null; }
|
|
6452
|
+
get: function () { return PSD.trans || null; },
|
|
5955
6453
|
}, waitFor: function (promiseOrFunction, optionalTimeout) {
|
|
5956
|
-
var promise = DexiePromise.resolve(typeof promiseOrFunction === 'function'
|
|
5957
|
-
Dexie.ignoreTransaction(promiseOrFunction)
|
|
5958
|
-
promiseOrFunction)
|
|
5959
|
-
|
|
5960
|
-
return PSD.trans ?
|
|
5961
|
-
PSD.trans.waitFor(promise) :
|
|
5962
|
-
promise;
|
|
6454
|
+
var promise = DexiePromise.resolve(typeof promiseOrFunction === 'function'
|
|
6455
|
+
? Dexie.ignoreTransaction(promiseOrFunction)
|
|
6456
|
+
: promiseOrFunction).timeout(optionalTimeout || 60000);
|
|
6457
|
+
return PSD.trans ? PSD.trans.waitFor(promise) : promise;
|
|
5963
6458
|
},
|
|
5964
6459
|
Promise: DexiePromise,
|
|
5965
6460
|
debug: {
|
|
5966
6461
|
get: function () { return debug; },
|
|
5967
6462
|
set: function (value) {
|
|
5968
6463
|
setDebug(value);
|
|
5969
|
-
}
|
|
6464
|
+
},
|
|
5970
6465
|
},
|
|
5971
6466
|
derive: derive, extend: extend, props: props, override: override,
|
|
5972
6467
|
Events: Events, on: globalEvents, liveQuery: liveQuery, extendObservabilitySet: extendObservabilitySet,
|
|
@@ -5974,21 +6469,22 @@
|
|
|
5974
6469
|
minKey: minKey,
|
|
5975
6470
|
addons: [],
|
|
5976
6471
|
connections: {
|
|
5977
|
-
get: connections.toArray
|
|
6472
|
+
get: connections.toArray,
|
|
5978
6473
|
},
|
|
5979
6474
|
errnames: errnames,
|
|
5980
6475
|
dependencies: domDeps, cache: cache,
|
|
5981
6476
|
semVer: DEXIE_VERSION, version: DEXIE_VERSION.split('.')
|
|
5982
6477
|
.map(function (n) { return parseInt(n); })
|
|
5983
|
-
.reduce(function (p, c, i) { return p +
|
|
6478
|
+
.reduce(function (p, c, i) { return p + c / Math.pow(10, i * 2); }) }));
|
|
5984
6479
|
Dexie.maxKey = getMaxKey(Dexie.dependencies.IDBKeyRange);
|
|
5985
6480
|
|
|
5986
|
-
if (typeof dispatchEvent !== 'undefined' &&
|
|
6481
|
+
if (typeof dispatchEvent !== 'undefined' &&
|
|
6482
|
+
typeof addEventListener !== 'undefined') {
|
|
5987
6483
|
globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, function (updatedParts) {
|
|
5988
6484
|
if (!propagatingLocally) {
|
|
5989
6485
|
var event_1;
|
|
5990
6486
|
event_1 = new CustomEvent(STORAGE_MUTATED_DOM_EVENT_NAME, {
|
|
5991
|
-
detail: updatedParts
|
|
6487
|
+
detail: updatedParts,
|
|
5992
6488
|
});
|
|
5993
6489
|
propagatingLocally = true;
|
|
5994
6490
|
dispatchEvent(event_1);
|