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