dexie 4.4.1 → 4.4.2-pr2297.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 +1410 -918
- 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 +1410 -918
- 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 +1252 -847
- 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-pr2297.2, Thu Apr 16 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) {
|
|
@@ -1090,8 +1168,16 @@ function execInGlobalContext(cb) {
|
|
|
1090
1168
|
}
|
|
1091
1169
|
var rejection = DexiePromise.reject;
|
|
1092
1170
|
|
|
1093
|
-
function
|
|
1094
|
-
|
|
1171
|
+
function isWebKitInjectKeyError(ex) {
|
|
1172
|
+
return ((ex === null || ex === void 0 ? void 0 : ex.name) === 'UnknownError' &&
|
|
1173
|
+
typeof (ex === null || ex === void 0 ? void 0 : ex.message) === 'string' &&
|
|
1174
|
+
ex.message.includes('inject key'));
|
|
1175
|
+
}
|
|
1176
|
+
var WEBKIT_INJECT_KEY_MAX_RETRIES = 7;
|
|
1177
|
+
var WEBKIT_INJECT_KEY_BASE_DELAY_MS = 100;
|
|
1178
|
+
function tempTransaction(db, mode, storeNames, fn, _webkitRetry) {
|
|
1179
|
+
if (_webkitRetry === void 0) { _webkitRetry = 0; }
|
|
1180
|
+
if (!db.idbdb || (!db._state.openComplete && !PSD.letThrough && !db._vip)) {
|
|
1095
1181
|
if (db._state.openComplete) {
|
|
1096
1182
|
return rejection(new exceptions.DatabaseClosed(db._state.dbOpenError));
|
|
1097
1183
|
}
|
|
@@ -1100,7 +1186,9 @@ function tempTransaction(db, mode, storeNames, fn) {
|
|
|
1100
1186
|
return rejection(new exceptions.DatabaseClosed());
|
|
1101
1187
|
db.open().catch(nop);
|
|
1102
1188
|
}
|
|
1103
|
-
return db._state.dbReadyPromise.then(function () {
|
|
1189
|
+
return db._state.dbReadyPromise.then(function () {
|
|
1190
|
+
return tempTransaction(db, mode, storeNames, fn);
|
|
1191
|
+
});
|
|
1104
1192
|
}
|
|
1105
1193
|
else {
|
|
1106
1194
|
var trans = db._createTransaction(mode, storeNames, db._dbSchema);
|
|
@@ -1109,45 +1197,66 @@ function tempTransaction(db, mode, storeNames, fn) {
|
|
|
1109
1197
|
db._state.PR1398_maxLoop = 3;
|
|
1110
1198
|
}
|
|
1111
1199
|
catch (ex) {
|
|
1112
|
-
if (ex.name === errnames.InvalidState &&
|
|
1200
|
+
if (ex.name === errnames.InvalidState &&
|
|
1201
|
+
db.isOpen() &&
|
|
1202
|
+
--db._state.PR1398_maxLoop > 0) {
|
|
1113
1203
|
console.warn('Dexie: Need to reopen db');
|
|
1114
1204
|
db.close({ disableAutoOpen: false });
|
|
1115
1205
|
return db.open().then(function () { return tempTransaction(db, mode, storeNames, fn); });
|
|
1116
1206
|
}
|
|
1117
1207
|
return rejection(ex);
|
|
1118
1208
|
}
|
|
1119
|
-
return trans
|
|
1209
|
+
return trans
|
|
1210
|
+
._promise(mode, function (resolve, reject) {
|
|
1120
1211
|
return newScope(function () {
|
|
1121
1212
|
PSD.trans = trans;
|
|
1122
1213
|
return fn(resolve, reject, trans);
|
|
1123
1214
|
});
|
|
1124
|
-
})
|
|
1215
|
+
})
|
|
1216
|
+
.then(function (result) {
|
|
1125
1217
|
if (mode === 'readwrite')
|
|
1126
1218
|
try {
|
|
1127
1219
|
trans.idbtrans.commit();
|
|
1128
1220
|
}
|
|
1129
1221
|
catch (_a) { }
|
|
1130
|
-
return mode === 'readonly'
|
|
1222
|
+
return mode === 'readonly'
|
|
1223
|
+
? result
|
|
1224
|
+
: trans._completion.then(function () { return result; });
|
|
1225
|
+
})
|
|
1226
|
+
.catch(function (ex) {
|
|
1227
|
+
if (isWebKitInjectKeyError(ex) &&
|
|
1228
|
+
_webkitRetry < WEBKIT_INJECT_KEY_MAX_RETRIES) {
|
|
1229
|
+
var delay_1 = WEBKIT_INJECT_KEY_BASE_DELAY_MS * Math.pow(1.5, _webkitRetry);
|
|
1230
|
+
if (_webkitRetry === 0) {
|
|
1231
|
+
console.warn('Dexie: WebKit "Cannot inject key" workaround — retrying transaction');
|
|
1232
|
+
}
|
|
1233
|
+
return new Promise(function (resolve) { return setTimeout(resolve, delay_1); }).then(function () {
|
|
1234
|
+
return tempTransaction(db, mode, storeNames, fn, _webkitRetry + 1);
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
return rejection(ex);
|
|
1131
1238
|
});
|
|
1132
1239
|
}
|
|
1133
1240
|
}
|
|
1134
1241
|
|
|
1135
|
-
var DEXIE_VERSION = '4.4.
|
|
1242
|
+
var DEXIE_VERSION = '4.4.2-pr2297.2';
|
|
1136
1243
|
var maxString = String.fromCharCode(65535);
|
|
1137
1244
|
var minKey = -Infinity;
|
|
1138
|
-
var INVALID_KEY_ARGUMENT =
|
|
1139
|
-
var STRING_EXPECTED =
|
|
1245
|
+
var INVALID_KEY_ARGUMENT = 'Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.';
|
|
1246
|
+
var STRING_EXPECTED = 'String expected.';
|
|
1140
1247
|
var DEFAULT_MAX_CONNECTIONS = 1000;
|
|
1141
1248
|
var DBNAMES_DB = '__dbnames';
|
|
1142
1249
|
var READONLY = 'readonly';
|
|
1143
1250
|
var READWRITE = 'readwrite';
|
|
1144
1251
|
|
|
1145
1252
|
function combine(filter1, filter2) {
|
|
1146
|
-
return filter1
|
|
1147
|
-
filter2
|
|
1148
|
-
function () {
|
|
1149
|
-
|
|
1150
|
-
|
|
1253
|
+
return filter1
|
|
1254
|
+
? filter2
|
|
1255
|
+
? function () {
|
|
1256
|
+
return (filter1.apply(this, arguments) && filter2.apply(this, arguments));
|
|
1257
|
+
}
|
|
1258
|
+
: filter1
|
|
1259
|
+
: filter2;
|
|
1151
1260
|
}
|
|
1152
1261
|
|
|
1153
1262
|
var AnyRange = {
|
|
@@ -1155,13 +1264,13 @@ var AnyRange = {
|
|
|
1155
1264
|
lower: -Infinity,
|
|
1156
1265
|
lowerOpen: false,
|
|
1157
1266
|
upper: [[]],
|
|
1158
|
-
upperOpen: false
|
|
1267
|
+
upperOpen: false,
|
|
1159
1268
|
};
|
|
1160
1269
|
|
|
1161
1270
|
function workaroundForUndefinedPrimKey(keyPath) {
|
|
1162
|
-
return typeof keyPath ===
|
|
1271
|
+
return typeof keyPath === 'string' && !/\./.test(keyPath)
|
|
1163
1272
|
? function (obj) {
|
|
1164
|
-
if (obj[keyPath] === undefined &&
|
|
1273
|
+
if (obj[keyPath] === undefined && keyPath in obj) {
|
|
1165
1274
|
obj = deepClone(obj);
|
|
1166
1275
|
delete obj[keyPath];
|
|
1167
1276
|
}
|
|
@@ -1266,11 +1375,11 @@ function builtInDeletionTrigger(table, keys, res) {
|
|
|
1266
1375
|
|
|
1267
1376
|
var PropModification = (function () {
|
|
1268
1377
|
function PropModification(spec) {
|
|
1269
|
-
this[
|
|
1378
|
+
this['@@propmod'] = spec;
|
|
1270
1379
|
}
|
|
1271
1380
|
PropModification.prototype.execute = function (value) {
|
|
1272
1381
|
var _a;
|
|
1273
|
-
var spec = this[
|
|
1382
|
+
var spec = this['@@propmod'];
|
|
1274
1383
|
if (spec.add !== undefined) {
|
|
1275
1384
|
var term = spec.add;
|
|
1276
1385
|
if (isArray(term)) {
|
|
@@ -1291,7 +1400,9 @@ var PropModification = (function () {
|
|
|
1291
1400
|
if (spec.remove !== undefined) {
|
|
1292
1401
|
var subtrahend_1 = spec.remove;
|
|
1293
1402
|
if (isArray(subtrahend_1)) {
|
|
1294
|
-
return isArray(value)
|
|
1403
|
+
return isArray(value)
|
|
1404
|
+
? value.filter(function (item) { return !subtrahend_1.includes(item); }).sort()
|
|
1405
|
+
: [];
|
|
1295
1406
|
}
|
|
1296
1407
|
if (typeof subtrahend_1 === 'number')
|
|
1297
1408
|
return Number(value) - subtrahend_1;
|
|
@@ -1306,7 +1417,9 @@ var PropModification = (function () {
|
|
|
1306
1417
|
throw new TypeError("Invalid subtrahend ".concat(subtrahend_1));
|
|
1307
1418
|
}
|
|
1308
1419
|
var prefixToReplace = (_a = spec.replacePrefix) === null || _a === void 0 ? void 0 : _a[0];
|
|
1309
|
-
if (prefixToReplace &&
|
|
1420
|
+
if (prefixToReplace &&
|
|
1421
|
+
typeof value === 'string' &&
|
|
1422
|
+
value.startsWith(prefixToReplace)) {
|
|
1310
1423
|
return spec.replacePrefix[1] + value.substring(prefixToReplace.length);
|
|
1311
1424
|
}
|
|
1312
1425
|
return value;
|
|
@@ -1340,19 +1453,24 @@ var Table = (function () {
|
|
|
1340
1453
|
Table.prototype._trans = function (mode, fn, writeLocked) {
|
|
1341
1454
|
var trans = this._tx || PSD.trans;
|
|
1342
1455
|
var tableName = this.name;
|
|
1343
|
-
var task = debug &&
|
|
1456
|
+
var task = debug &&
|
|
1457
|
+
typeof console !== 'undefined' &&
|
|
1458
|
+
console.createTask &&
|
|
1459
|
+
console.createTask("Dexie: ".concat(mode === 'readonly' ? 'read' : 'write', " ").concat(this.name));
|
|
1344
1460
|
function checkTableInTransaction(resolve, reject, trans) {
|
|
1345
1461
|
if (!trans.schema[tableName])
|
|
1346
|
-
throw new exceptions.NotFound(
|
|
1462
|
+
throw new exceptions.NotFound('Table ' + tableName + ' not part of transaction');
|
|
1347
1463
|
return fn(trans.idbtrans, trans);
|
|
1348
1464
|
}
|
|
1349
1465
|
var wasRootExec = beginMicroTickScope();
|
|
1350
1466
|
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
|
-
|
|
1467
|
+
var p = trans && trans.db._novip === this.db._novip
|
|
1468
|
+
? trans === PSD.trans
|
|
1469
|
+
? trans._promise(mode, checkTableInTransaction, writeLocked)
|
|
1470
|
+
: newScope(function () {
|
|
1471
|
+
return trans._promise(mode, checkTableInTransaction, writeLocked);
|
|
1472
|
+
}, { trans: trans, transless: PSD.transless || PSD })
|
|
1473
|
+
: tempTransaction(this.db, mode, [this.name], checkTableInTransaction);
|
|
1356
1474
|
if (task) {
|
|
1357
1475
|
p._consoleTask = task;
|
|
1358
1476
|
p = p.catch(function (err) {
|
|
@@ -1374,7 +1492,8 @@ var Table = (function () {
|
|
|
1374
1492
|
if (keyOrCrit == null)
|
|
1375
1493
|
return rejection(new exceptions.Type("Invalid argument to Table.get()"));
|
|
1376
1494
|
return this._trans('readonly', function (trans) {
|
|
1377
|
-
return _this.core
|
|
1495
|
+
return _this.core
|
|
1496
|
+
.get({ trans: trans, key: keyOrCrit })
|
|
1378
1497
|
.then(function (res) { return _this.hook.reading.fire(res); });
|
|
1379
1498
|
}).then(cb);
|
|
1380
1499
|
};
|
|
@@ -1385,10 +1504,10 @@ var Table = (function () {
|
|
|
1385
1504
|
return new this.db.WhereClause(this, "[".concat(indexOrCrit.join('+'), "]"));
|
|
1386
1505
|
var keyPaths = keys(indexOrCrit);
|
|
1387
1506
|
if (keyPaths.length === 1)
|
|
1388
|
-
return this
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1507
|
+
return this.where(keyPaths[0]).equals(indexOrCrit[keyPaths[0]]);
|
|
1508
|
+
var compoundIndex = this.schema.indexes
|
|
1509
|
+
.concat(this.schema.primKey)
|
|
1510
|
+
.filter(function (ix) {
|
|
1392
1511
|
if (ix.compound &&
|
|
1393
1512
|
keyPaths.every(function (keyPath) { return ix.keyPath.indexOf(keyPath) >= 0; })) {
|
|
1394
1513
|
for (var i = 0; i < keyPaths.length; ++i) {
|
|
@@ -1398,12 +1517,11 @@ var Table = (function () {
|
|
|
1398
1517
|
return true;
|
|
1399
1518
|
}
|
|
1400
1519
|
return false;
|
|
1401
|
-
})
|
|
1520
|
+
})
|
|
1521
|
+
.sort(function (a, b) { return a.keyPath.length - b.keyPath.length; })[0];
|
|
1402
1522
|
if (compoundIndex && this.db._maxKey !== maxString) {
|
|
1403
1523
|
var keyPathsInValidOrder = compoundIndex.keyPath.slice(0, keyPaths.length);
|
|
1404
|
-
return this
|
|
1405
|
-
.where(keyPathsInValidOrder)
|
|
1406
|
-
.equals(keyPathsInValidOrder.map(function (kp) { return indexOrCrit[kp]; }));
|
|
1524
|
+
return this.where(keyPathsInValidOrder).equals(keyPathsInValidOrder.map(function (kp) { return indexOrCrit[kp]; }));
|
|
1407
1525
|
}
|
|
1408
1526
|
if (!compoundIndex && debug)
|
|
1409
1527
|
console.warn("The query ".concat(JSON.stringify(indexOrCrit), " on ").concat(this.name, " would benefit from a ") +
|
|
@@ -1418,21 +1536,24 @@ var Table = (function () {
|
|
|
1418
1536
|
var value = indexOrCrit[keyPath];
|
|
1419
1537
|
return [
|
|
1420
1538
|
prevIndex || index,
|
|
1421
|
-
prevIndex || !index
|
|
1422
|
-
combine(prevFilterFn, index && index.multi
|
|
1423
|
-
function (x) {
|
|
1539
|
+
prevIndex || !index
|
|
1540
|
+
? combine(prevFilterFn, index && index.multi
|
|
1541
|
+
? function (x) {
|
|
1424
1542
|
var prop = getByKeyPath(x, keyPath);
|
|
1425
|
-
return isArray(prop) &&
|
|
1426
|
-
|
|
1427
|
-
|
|
1543
|
+
return (isArray(prop) &&
|
|
1544
|
+
prop.some(function (item) { return equals(value, item); }));
|
|
1545
|
+
}
|
|
1546
|
+
: function (x) { return equals(value, getByKeyPath(x, keyPath)); })
|
|
1547
|
+
: prevFilterFn,
|
|
1428
1548
|
];
|
|
1429
1549
|
}, [null, null]), idx = _a[0], filterFunction = _a[1];
|
|
1430
|
-
return idx
|
|
1431
|
-
this.where(idx.name)
|
|
1432
|
-
.
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
this.
|
|
1550
|
+
return idx
|
|
1551
|
+
? this.where(idx.name)
|
|
1552
|
+
.equals(indexOrCrit[idx.keyPath])
|
|
1553
|
+
.filter(filterFunction)
|
|
1554
|
+
: compoundIndex
|
|
1555
|
+
? this.filter(filterFunction)
|
|
1556
|
+
: this.where(keyPaths).equals('');
|
|
1436
1557
|
};
|
|
1437
1558
|
Table.prototype.filter = function (filterFunction) {
|
|
1438
1559
|
return this.toCollection().and(filterFunction);
|
|
@@ -1456,9 +1577,7 @@ var Table = (function () {
|
|
|
1456
1577
|
return new this.db.Collection(new this.db.WhereClause(this));
|
|
1457
1578
|
};
|
|
1458
1579
|
Table.prototype.orderBy = function (index) {
|
|
1459
|
-
return new this.db.Collection(new this.db.WhereClause(this, isArray(index) ?
|
|
1460
|
-
"[".concat(index.join('+'), "]") :
|
|
1461
|
-
index));
|
|
1580
|
+
return new this.db.Collection(new this.db.WhereClause(this, isArray(index) ? "[".concat(index.join('+'), "]") : index));
|
|
1462
1581
|
};
|
|
1463
1582
|
Table.prototype.reverse = function () {
|
|
1464
1583
|
return this.toCollection().reverse();
|
|
@@ -1473,17 +1592,23 @@ var Table = (function () {
|
|
|
1473
1592
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
1474
1593
|
}
|
|
1475
1594
|
Object.defineProperty(class_1.prototype, "db", {
|
|
1476
|
-
get: function () {
|
|
1595
|
+
get: function () {
|
|
1596
|
+
return db;
|
|
1597
|
+
},
|
|
1477
1598
|
enumerable: false,
|
|
1478
1599
|
configurable: true
|
|
1479
1600
|
});
|
|
1480
|
-
class_1.prototype.table = function () {
|
|
1601
|
+
class_1.prototype.table = function () {
|
|
1602
|
+
return tableName;
|
|
1603
|
+
};
|
|
1481
1604
|
return class_1;
|
|
1482
1605
|
}(constructor));
|
|
1483
1606
|
}
|
|
1484
1607
|
var inheritedProps = new Set();
|
|
1485
1608
|
for (var proto = constructor.prototype; proto; proto = getProto(proto)) {
|
|
1486
|
-
Object.getOwnPropertyNames(proto).forEach(function (propName) {
|
|
1609
|
+
Object.getOwnPropertyNames(proto).forEach(function (propName) {
|
|
1610
|
+
return inheritedProps.add(propName);
|
|
1611
|
+
});
|
|
1487
1612
|
}
|
|
1488
1613
|
var readHook = function (obj) {
|
|
1489
1614
|
if (!obj)
|
|
@@ -1501,7 +1626,7 @@ var Table = (function () {
|
|
|
1501
1626
|
this.hook.reading.unsubscribe(this.schema.readHook);
|
|
1502
1627
|
}
|
|
1503
1628
|
this.schema.readHook = readHook;
|
|
1504
|
-
this.hook(
|
|
1629
|
+
this.hook('reading', readHook);
|
|
1505
1630
|
return constructor;
|
|
1506
1631
|
};
|
|
1507
1632
|
Table.prototype.defineClass = function () {
|
|
@@ -1518,8 +1643,16 @@ var Table = (function () {
|
|
|
1518
1643
|
objToAdd = workaroundForUndefinedPrimKey(keyPath)(obj);
|
|
1519
1644
|
}
|
|
1520
1645
|
return this._trans('readwrite', function (trans) {
|
|
1521
|
-
return _this.core.mutate({
|
|
1522
|
-
|
|
1646
|
+
return _this.core.mutate({
|
|
1647
|
+
trans: trans,
|
|
1648
|
+
type: 'add',
|
|
1649
|
+
keys: key != null ? [key] : null,
|
|
1650
|
+
values: [objToAdd],
|
|
1651
|
+
});
|
|
1652
|
+
})
|
|
1653
|
+
.then(function (res) {
|
|
1654
|
+
return res.numFailures ? DexiePromise.reject(res.failures[0]) : res.lastResult;
|
|
1655
|
+
})
|
|
1523
1656
|
.then(function (lastResult) {
|
|
1524
1657
|
if (keyPath) {
|
|
1525
1658
|
try {
|
|
@@ -1539,14 +1672,18 @@ var Table = (function () {
|
|
|
1539
1672
|
applyUpdateSpec(obj, modifications);
|
|
1540
1673
|
if (keyPath)
|
|
1541
1674
|
setByKeyPath(obj, keyPath, key);
|
|
1542
|
-
return _this.core
|
|
1675
|
+
return _this.core
|
|
1676
|
+
.mutate({
|
|
1543
1677
|
trans: trans,
|
|
1544
1678
|
type: 'put',
|
|
1545
1679
|
values: [obj],
|
|
1546
1680
|
keys: [key],
|
|
1547
1681
|
upsert: true,
|
|
1548
|
-
updates: { keys: [key], changeSpecs: [modifications] }
|
|
1549
|
-
})
|
|
1682
|
+
updates: { keys: [key], changeSpecs: [modifications] },
|
|
1683
|
+
})
|
|
1684
|
+
.then(function (res) {
|
|
1685
|
+
return res.numFailures ? DexiePromise.reject(res.failures[0]) : !!existing;
|
|
1686
|
+
});
|
|
1550
1687
|
});
|
|
1551
1688
|
});
|
|
1552
1689
|
};
|
|
@@ -1554,11 +1691,11 @@ var Table = (function () {
|
|
|
1554
1691
|
if (typeof keyOrObject === 'object' && !isArray(keyOrObject)) {
|
|
1555
1692
|
var key = getByKeyPath(keyOrObject, this.schema.primKey.keyPath);
|
|
1556
1693
|
if (key === undefined)
|
|
1557
|
-
return rejection(new exceptions.InvalidArgument(
|
|
1558
|
-
return this.where(
|
|
1694
|
+
return rejection(new exceptions.InvalidArgument('Given object does not contain its primary key'));
|
|
1695
|
+
return this.where(':id').equals(key).modify(modifications);
|
|
1559
1696
|
}
|
|
1560
1697
|
else {
|
|
1561
|
-
return this.where(
|
|
1698
|
+
return this.where(':id').equals(keyOrObject).modify(modifications);
|
|
1562
1699
|
}
|
|
1563
1700
|
};
|
|
1564
1701
|
Table.prototype.put = function (obj, key) {
|
|
@@ -1568,8 +1705,17 @@ var Table = (function () {
|
|
|
1568
1705
|
if (keyPath && auto) {
|
|
1569
1706
|
objToAdd = workaroundForUndefinedPrimKey(keyPath)(obj);
|
|
1570
1707
|
}
|
|
1571
|
-
return this._trans('readwrite', function (trans) {
|
|
1572
|
-
|
|
1708
|
+
return this._trans('readwrite', function (trans) {
|
|
1709
|
+
return _this.core.mutate({
|
|
1710
|
+
trans: trans,
|
|
1711
|
+
type: 'put',
|
|
1712
|
+
values: [objToAdd],
|
|
1713
|
+
keys: key != null ? [key] : null,
|
|
1714
|
+
});
|
|
1715
|
+
})
|
|
1716
|
+
.then(function (res) {
|
|
1717
|
+
return res.numFailures ? DexiePromise.reject(res.failures[0]) : res.lastResult;
|
|
1718
|
+
})
|
|
1573
1719
|
.then(function (lastResult) {
|
|
1574
1720
|
if (keyPath) {
|
|
1575
1721
|
try {
|
|
@@ -1582,41 +1728,60 @@ var Table = (function () {
|
|
|
1582
1728
|
};
|
|
1583
1729
|
Table.prototype.delete = function (key) {
|
|
1584
1730
|
var _this = this;
|
|
1585
|
-
return this._trans('readwrite', function (trans) {
|
|
1586
|
-
|
|
1587
|
-
|
|
1731
|
+
return this._trans('readwrite', function (trans) {
|
|
1732
|
+
return _this.core
|
|
1733
|
+
.mutate({ trans: trans, type: 'delete', keys: [key] })
|
|
1734
|
+
.then(function (res) { return builtInDeletionTrigger(_this, [key], res); })
|
|
1735
|
+
.then(function (res) {
|
|
1736
|
+
return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined;
|
|
1737
|
+
});
|
|
1738
|
+
});
|
|
1588
1739
|
};
|
|
1589
1740
|
Table.prototype.clear = function () {
|
|
1590
1741
|
var _this = this;
|
|
1591
|
-
return this._trans('readwrite', function (trans) {
|
|
1592
|
-
|
|
1593
|
-
|
|
1742
|
+
return this._trans('readwrite', function (trans) {
|
|
1743
|
+
return _this.core
|
|
1744
|
+
.mutate({ trans: trans, type: 'deleteRange', range: AnyRange })
|
|
1745
|
+
.then(function (res) { return builtInDeletionTrigger(_this, null, res); });
|
|
1746
|
+
}).then(function (res) {
|
|
1747
|
+
return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined;
|
|
1748
|
+
});
|
|
1594
1749
|
};
|
|
1595
1750
|
Table.prototype.bulkGet = function (keys) {
|
|
1596
1751
|
var _this = this;
|
|
1597
1752
|
return this._trans('readonly', function (trans) {
|
|
1598
|
-
return _this.core
|
|
1753
|
+
return _this.core
|
|
1754
|
+
.getMany({
|
|
1599
1755
|
keys: keys,
|
|
1600
|
-
trans: trans
|
|
1601
|
-
})
|
|
1756
|
+
trans: trans,
|
|
1757
|
+
})
|
|
1758
|
+
.then(function (result) { return result.map(function (res) { return _this.hook.reading.fire(res); }); });
|
|
1602
1759
|
});
|
|
1603
1760
|
};
|
|
1604
1761
|
Table.prototype.bulkAdd = function (objects, keysOrOptions, options) {
|
|
1605
1762
|
var _this = this;
|
|
1606
1763
|
var keys = Array.isArray(keysOrOptions) ? keysOrOptions : undefined;
|
|
1607
|
-
options =
|
|
1764
|
+
options =
|
|
1765
|
+
options || (keys ? undefined : keysOrOptions);
|
|
1608
1766
|
var wantResults = options ? options.allKeys : undefined;
|
|
1609
1767
|
return this._trans('readwrite', function (trans) {
|
|
1610
1768
|
var _a = _this.schema.primKey, auto = _a.auto, keyPath = _a.keyPath;
|
|
1611
1769
|
if (keyPath && keys)
|
|
1612
|
-
throw new exceptions.InvalidArgument(
|
|
1770
|
+
throw new exceptions.InvalidArgument('bulkAdd(): keys argument invalid on tables with inbound keys');
|
|
1613
1771
|
if (keys && keys.length !== objects.length)
|
|
1614
|
-
throw new exceptions.InvalidArgument(
|
|
1772
|
+
throw new exceptions.InvalidArgument('Arguments objects and keys must have the same length');
|
|
1615
1773
|
var numObjects = objects.length;
|
|
1616
|
-
var objectsToAdd = keyPath && auto
|
|
1617
|
-
objects.map(workaroundForUndefinedPrimKey(keyPath))
|
|
1618
|
-
objects;
|
|
1619
|
-
return _this.core
|
|
1774
|
+
var objectsToAdd = keyPath && auto
|
|
1775
|
+
? objects.map(workaroundForUndefinedPrimKey(keyPath))
|
|
1776
|
+
: objects;
|
|
1777
|
+
return _this.core
|
|
1778
|
+
.mutate({
|
|
1779
|
+
trans: trans,
|
|
1780
|
+
type: 'add',
|
|
1781
|
+
keys: keys,
|
|
1782
|
+
values: objectsToAdd,
|
|
1783
|
+
wantResults: wantResults,
|
|
1784
|
+
})
|
|
1620
1785
|
.then(function (_a) {
|
|
1621
1786
|
var numFailures = _a.numFailures, results = _a.results, lastResult = _a.lastResult, failures = _a.failures;
|
|
1622
1787
|
var result = wantResults ? results : lastResult;
|
|
@@ -1629,19 +1794,27 @@ var Table = (function () {
|
|
|
1629
1794
|
Table.prototype.bulkPut = function (objects, keysOrOptions, options) {
|
|
1630
1795
|
var _this = this;
|
|
1631
1796
|
var keys = Array.isArray(keysOrOptions) ? keysOrOptions : undefined;
|
|
1632
|
-
options =
|
|
1797
|
+
options =
|
|
1798
|
+
options || (keys ? undefined : keysOrOptions);
|
|
1633
1799
|
var wantResults = options ? options.allKeys : undefined;
|
|
1634
1800
|
return this._trans('readwrite', function (trans) {
|
|
1635
1801
|
var _a = _this.schema.primKey, auto = _a.auto, keyPath = _a.keyPath;
|
|
1636
1802
|
if (keyPath && keys)
|
|
1637
|
-
throw new exceptions.InvalidArgument(
|
|
1803
|
+
throw new exceptions.InvalidArgument('bulkPut(): keys argument invalid on tables with inbound keys');
|
|
1638
1804
|
if (keys && keys.length !== objects.length)
|
|
1639
|
-
throw new exceptions.InvalidArgument(
|
|
1805
|
+
throw new exceptions.InvalidArgument('Arguments objects and keys must have the same length');
|
|
1640
1806
|
var numObjects = objects.length;
|
|
1641
|
-
var objectsToPut = keyPath && auto
|
|
1642
|
-
objects.map(workaroundForUndefinedPrimKey(keyPath))
|
|
1643
|
-
objects;
|
|
1644
|
-
return _this.core
|
|
1807
|
+
var objectsToPut = keyPath && auto
|
|
1808
|
+
? objects.map(workaroundForUndefinedPrimKey(keyPath))
|
|
1809
|
+
: objects;
|
|
1810
|
+
return _this.core
|
|
1811
|
+
.mutate({
|
|
1812
|
+
trans: trans,
|
|
1813
|
+
type: 'put',
|
|
1814
|
+
keys: keys,
|
|
1815
|
+
values: objectsToPut,
|
|
1816
|
+
wantResults: wantResults,
|
|
1817
|
+
})
|
|
1645
1818
|
.then(function (_a) {
|
|
1646
1819
|
var numFailures = _a.numFailures, results = _a.results, lastResult = _a.lastResult, failures = _a.failures;
|
|
1647
1820
|
var result = wantResults ? results : lastResult;
|
|
@@ -1691,8 +1864,8 @@ var Table = (function () {
|
|
|
1691
1864
|
values: resultObjs,
|
|
1692
1865
|
updates: {
|
|
1693
1866
|
keys: keys,
|
|
1694
|
-
changeSpecs: changeSpecs
|
|
1695
|
-
}
|
|
1867
|
+
changeSpecs: changeSpecs,
|
|
1868
|
+
},
|
|
1696
1869
|
})
|
|
1697
1870
|
.then(function (_a) {
|
|
1698
1871
|
var numFailures = _a.numFailures, failures = _a.failures;
|
|
@@ -1716,7 +1889,8 @@ var Table = (function () {
|
|
|
1716
1889
|
var _this = this;
|
|
1717
1890
|
var numKeys = keys.length;
|
|
1718
1891
|
return this._trans('readwrite', function (trans) {
|
|
1719
|
-
return _this.core
|
|
1892
|
+
return _this.core
|
|
1893
|
+
.mutate({ trans: trans, type: 'delete', keys: keys })
|
|
1720
1894
|
.then(function (res) { return builtInDeletionTrigger(_this, keys, res); });
|
|
1721
1895
|
}).then(function (_a) {
|
|
1722
1896
|
var numFailures = _a.numFailures, lastResult = _a.lastResult, failures = _a.failures;
|
|
@@ -1738,7 +1912,7 @@ function Events(ctx) {
|
|
|
1738
1912
|
evs[eventName].subscribe.apply(null, args);
|
|
1739
1913
|
return ctx;
|
|
1740
1914
|
}
|
|
1741
|
-
else if (typeof
|
|
1915
|
+
else if (typeof eventName === 'string') {
|
|
1742
1916
|
return evs[eventName];
|
|
1743
1917
|
}
|
|
1744
1918
|
};
|
|
@@ -1764,9 +1938,11 @@ function Events(ctx) {
|
|
|
1764
1938
|
}
|
|
1765
1939
|
},
|
|
1766
1940
|
unsubscribe: function (cb) {
|
|
1767
|
-
context.subscribers = context.subscribers.filter(function (fn) {
|
|
1941
|
+
context.subscribers = context.subscribers.filter(function (fn) {
|
|
1942
|
+
return fn !== cb;
|
|
1943
|
+
});
|
|
1768
1944
|
context.fire = context.subscribers.reduce(chainFunction, defaultFunction);
|
|
1769
|
-
}
|
|
1945
|
+
},
|
|
1770
1946
|
};
|
|
1771
1947
|
evs[eventName] = rv[eventName] = context;
|
|
1772
1948
|
return context;
|
|
@@ -1790,7 +1966,7 @@ function Events(ctx) {
|
|
|
1790
1966
|
});
|
|
1791
1967
|
}
|
|
1792
1968
|
else
|
|
1793
|
-
throw new exceptions.InvalidArgument(
|
|
1969
|
+
throw new exceptions.InvalidArgument('Invalid event config');
|
|
1794
1970
|
});
|
|
1795
1971
|
}
|
|
1796
1972
|
}
|
|
@@ -1806,18 +1982,20 @@ function createTableConstructor(db) {
|
|
|
1806
1982
|
this._tx = trans;
|
|
1807
1983
|
this.name = name;
|
|
1808
1984
|
this.schema = tableSchema;
|
|
1809
|
-
this.hook = db._allTables[name]
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1985
|
+
this.hook = db._allTables[name]
|
|
1986
|
+
? db._allTables[name].hook
|
|
1987
|
+
: Events(null, {
|
|
1988
|
+
creating: [hookCreatingChain, nop],
|
|
1989
|
+
reading: [pureFunctionChain, mirror],
|
|
1990
|
+
updating: [hookUpdatingChain, nop],
|
|
1991
|
+
deleting: [hookDeletingChain, nop],
|
|
1992
|
+
});
|
|
1815
1993
|
});
|
|
1816
1994
|
}
|
|
1817
1995
|
|
|
1818
1996
|
function isPlainKeyRange(ctx, ignoreLimitFilter) {
|
|
1819
|
-
return !(ctx.filter || ctx.algorithm || ctx.or) &&
|
|
1820
|
-
(ignoreLimitFilter ? ctx.justLimit : !ctx.replayFilter);
|
|
1997
|
+
return (!(ctx.filter || ctx.algorithm || ctx.or) &&
|
|
1998
|
+
(ignoreLimitFilter ? ctx.justLimit : !ctx.replayFilter));
|
|
1821
1999
|
}
|
|
1822
2000
|
function addFilter(ctx, fn) {
|
|
1823
2001
|
ctx.filter = combine(ctx.filter, fn);
|
|
@@ -1835,7 +2013,11 @@ function getIndexOrStore(ctx, coreSchema) {
|
|
|
1835
2013
|
return coreSchema.primaryKey;
|
|
1836
2014
|
var index = coreSchema.getIndexByKeyPath(ctx.index);
|
|
1837
2015
|
if (!index)
|
|
1838
|
-
throw new exceptions.Schema(
|
|
2016
|
+
throw new exceptions.Schema('KeyPath ' +
|
|
2017
|
+
ctx.index +
|
|
2018
|
+
' on object store ' +
|
|
2019
|
+
coreSchema.name +
|
|
2020
|
+
' is not indexed');
|
|
1839
2021
|
return index;
|
|
1840
2022
|
}
|
|
1841
2023
|
function openCursor(ctx, coreTable, trans) {
|
|
@@ -1847,19 +2029,22 @@ function openCursor(ctx, coreTable, trans) {
|
|
|
1847
2029
|
unique: !!ctx.unique,
|
|
1848
2030
|
query: {
|
|
1849
2031
|
index: index,
|
|
1850
|
-
range: ctx.range
|
|
1851
|
-
}
|
|
2032
|
+
range: ctx.range,
|
|
2033
|
+
},
|
|
1852
2034
|
});
|
|
1853
2035
|
}
|
|
1854
2036
|
function iter(ctx, fn, coreTrans, coreTable) {
|
|
1855
|
-
var filter = ctx.replayFilter
|
|
2037
|
+
var filter = ctx.replayFilter
|
|
2038
|
+
? combine(ctx.filter, ctx.replayFilter())
|
|
2039
|
+
: ctx.filter;
|
|
1856
2040
|
if (!ctx.or) {
|
|
1857
2041
|
return iterate(openCursor(ctx, coreTable, coreTrans), combine(ctx.algorithm, filter), fn, !ctx.keysOnly && ctx.valueMapper);
|
|
1858
2042
|
}
|
|
1859
2043
|
else {
|
|
1860
2044
|
var set_1 = {};
|
|
1861
2045
|
var union = function (item, cursor, advance) {
|
|
1862
|
-
if (!filter ||
|
|
2046
|
+
if (!filter ||
|
|
2047
|
+
filter(cursor, advance, function (result) { return cursor.stop(result); }, function (err) { return cursor.fail(err); })) {
|
|
1863
2048
|
var primaryKey = cursor.primaryKey;
|
|
1864
2049
|
var key = '' + primaryKey;
|
|
1865
2050
|
if (key === '[object ArrayBuffer]')
|
|
@@ -1872,7 +2057,7 @@ function iter(ctx, fn, coreTrans, coreTable) {
|
|
|
1872
2057
|
};
|
|
1873
2058
|
return Promise.all([
|
|
1874
2059
|
ctx.or._iterate(union, coreTrans),
|
|
1875
|
-
iterate(openCursor(ctx, coreTable, coreTrans), ctx.algorithm, union, !ctx.keysOnly && ctx.valueMapper)
|
|
2060
|
+
iterate(openCursor(ctx, coreTable, coreTrans), ctx.algorithm, union, !ctx.keysOnly && ctx.valueMapper),
|
|
1876
2061
|
]);
|
|
1877
2062
|
}
|
|
1878
2063
|
}
|
|
@@ -1883,8 +2068,15 @@ function iterate(cursorPromise, filter, fn, valueMapper) {
|
|
|
1883
2068
|
if (cursor) {
|
|
1884
2069
|
return cursor.start(function () {
|
|
1885
2070
|
var c = function () { return cursor.continue(); };
|
|
1886
|
-
if (!filter ||
|
|
1887
|
-
|
|
2071
|
+
if (!filter ||
|
|
2072
|
+
filter(cursor, function (advancer) { return (c = advancer); }, function (val) {
|
|
2073
|
+
cursor.stop(val);
|
|
2074
|
+
c = nop;
|
|
2075
|
+
}, function (e) {
|
|
2076
|
+
cursor.fail(e);
|
|
2077
|
+
c = nop;
|
|
2078
|
+
}))
|
|
2079
|
+
wrappedFn(cursor.value, cursor, function (advancer) { return (c = advancer); });
|
|
1888
2080
|
c();
|
|
1889
2081
|
});
|
|
1890
2082
|
}
|
|
@@ -1896,15 +2088,15 @@ var Collection = (function () {
|
|
|
1896
2088
|
}
|
|
1897
2089
|
Collection.prototype._read = function (fn, cb) {
|
|
1898
2090
|
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);
|
|
2091
|
+
return ctx.error
|
|
2092
|
+
? ctx.table._trans(null, rejection.bind(null, ctx.error))
|
|
2093
|
+
: ctx.table._trans('readonly', fn).then(cb);
|
|
1902
2094
|
};
|
|
1903
2095
|
Collection.prototype._write = function (fn) {
|
|
1904
2096
|
var ctx = this._ctx;
|
|
1905
|
-
return ctx.error
|
|
1906
|
-
ctx.table._trans(null, rejection.bind(null, ctx.error))
|
|
1907
|
-
ctx.table._trans('readwrite', fn,
|
|
2097
|
+
return ctx.error
|
|
2098
|
+
? ctx.table._trans(null, rejection.bind(null, ctx.error))
|
|
2099
|
+
: ctx.table._trans('readwrite', fn, 'locked');
|
|
1908
2100
|
};
|
|
1909
2101
|
Collection.prototype._addAlgorithm = function (fn) {
|
|
1910
2102
|
var ctx = this._ctx;
|
|
@@ -1934,18 +2126,22 @@ var Collection = (function () {
|
|
|
1934
2126
|
var ctx = _this._ctx;
|
|
1935
2127
|
var coreTable = ctx.table.core;
|
|
1936
2128
|
if (isPlainKeyRange(ctx, true)) {
|
|
1937
|
-
return coreTable
|
|
2129
|
+
return coreTable
|
|
2130
|
+
.count({
|
|
1938
2131
|
trans: trans,
|
|
1939
2132
|
query: {
|
|
1940
2133
|
index: getIndexOrStore(ctx, coreTable.schema),
|
|
1941
|
-
range: ctx.range
|
|
1942
|
-
}
|
|
1943
|
-
})
|
|
2134
|
+
range: ctx.range,
|
|
2135
|
+
},
|
|
2136
|
+
})
|
|
2137
|
+
.then(function (count) { return Math.min(count, ctx.limit); });
|
|
1944
2138
|
}
|
|
1945
2139
|
else {
|
|
1946
2140
|
var count = 0;
|
|
1947
|
-
return iter(ctx, function () {
|
|
1948
|
-
|
|
2141
|
+
return iter(ctx, function () {
|
|
2142
|
+
++count;
|
|
2143
|
+
return false;
|
|
2144
|
+
}, trans, coreTable).then(function () { return count; });
|
|
1949
2145
|
}
|
|
1950
2146
|
}).then(cb);
|
|
1951
2147
|
};
|
|
@@ -1956,13 +2152,13 @@ var Collection = (function () {
|
|
|
1956
2152
|
return getval(obj[parts[i]], i - 1);
|
|
1957
2153
|
return obj[lastPart];
|
|
1958
2154
|
}
|
|
1959
|
-
var order = this._ctx.dir ===
|
|
2155
|
+
var order = this._ctx.dir === 'next' ? 1 : -1;
|
|
1960
2156
|
function sorter(a, b) {
|
|
1961
2157
|
var aVal = getval(a, lastIndex), bVal = getval(b, lastIndex);
|
|
1962
2158
|
return cmp(aVal, bVal) * order;
|
|
1963
2159
|
}
|
|
1964
2160
|
return this.toArray(function (a) {
|
|
1965
|
-
return a.sort(sorter);
|
|
2161
|
+
return a.slice().sort(sorter);
|
|
1966
2162
|
}).then(cb);
|
|
1967
2163
|
};
|
|
1968
2164
|
Collection.prototype.toArray = function (cb) {
|
|
@@ -1972,16 +2168,18 @@ var Collection = (function () {
|
|
|
1972
2168
|
if (isPlainKeyRange(ctx, true) && ctx.limit > 0) {
|
|
1973
2169
|
var valueMapper_1 = ctx.valueMapper;
|
|
1974
2170
|
var index = getIndexOrStore(ctx, ctx.table.core.schema);
|
|
1975
|
-
return ctx.table.core
|
|
2171
|
+
return ctx.table.core
|
|
2172
|
+
.query({
|
|
1976
2173
|
trans: trans,
|
|
1977
2174
|
limit: ctx.limit,
|
|
1978
2175
|
values: true,
|
|
1979
2176
|
direction: ctx.dir === 'prev' ? 'prev' : undefined,
|
|
1980
2177
|
query: {
|
|
1981
2178
|
index: index,
|
|
1982
|
-
range: ctx.range
|
|
1983
|
-
}
|
|
1984
|
-
})
|
|
2179
|
+
range: ctx.range,
|
|
2180
|
+
},
|
|
2181
|
+
})
|
|
2182
|
+
.then(function (_a) {
|
|
1985
2183
|
var result = _a.result;
|
|
1986
2184
|
return valueMapper_1 ? result.map(valueMapper_1) : result;
|
|
1987
2185
|
});
|
|
@@ -2018,7 +2216,7 @@ var Collection = (function () {
|
|
|
2018
2216
|
else {
|
|
2019
2217
|
addReplayFilter(ctx, function () {
|
|
2020
2218
|
var offsetLeft = offset;
|
|
2021
|
-
return function () { return
|
|
2219
|
+
return function () { return --offsetLeft < 0; };
|
|
2022
2220
|
});
|
|
2023
2221
|
}
|
|
2024
2222
|
return this;
|
|
@@ -2048,7 +2246,11 @@ var Collection = (function () {
|
|
|
2048
2246
|
return this;
|
|
2049
2247
|
};
|
|
2050
2248
|
Collection.prototype.first = function (cb) {
|
|
2051
|
-
return this.limit(1)
|
|
2249
|
+
return this.limit(1)
|
|
2250
|
+
.toArray(function (a) {
|
|
2251
|
+
return a[0];
|
|
2252
|
+
})
|
|
2253
|
+
.then(cb);
|
|
2052
2254
|
};
|
|
2053
2255
|
Collection.prototype.last = function (cb) {
|
|
2054
2256
|
return this.reverse().first(cb);
|
|
@@ -2067,7 +2269,7 @@ var Collection = (function () {
|
|
|
2067
2269
|
return new this.db.WhereClause(this._ctx.table, indexName, this);
|
|
2068
2270
|
};
|
|
2069
2271
|
Collection.prototype.reverse = function () {
|
|
2070
|
-
this._ctx.dir =
|
|
2272
|
+
this._ctx.dir = this._ctx.dir === 'prev' ? 'next' : 'prev';
|
|
2071
2273
|
if (this._ondirectionchange)
|
|
2072
2274
|
this._ondirectionchange(this._ctx.dir);
|
|
2073
2275
|
return this;
|
|
@@ -2078,16 +2280,20 @@ var Collection = (function () {
|
|
|
2078
2280
|
Collection.prototype.eachKey = function (cb) {
|
|
2079
2281
|
var ctx = this._ctx;
|
|
2080
2282
|
ctx.keysOnly = !ctx.isMatch;
|
|
2081
|
-
return this.each(function (val, cursor) {
|
|
2283
|
+
return this.each(function (val, cursor) {
|
|
2284
|
+
cb(cursor.key, cursor);
|
|
2285
|
+
});
|
|
2082
2286
|
};
|
|
2083
2287
|
Collection.prototype.eachUniqueKey = function (cb) {
|
|
2084
|
-
this._ctx.unique =
|
|
2288
|
+
this._ctx.unique = 'unique';
|
|
2085
2289
|
return this.eachKey(cb);
|
|
2086
2290
|
};
|
|
2087
2291
|
Collection.prototype.eachPrimaryKey = function (cb) {
|
|
2088
2292
|
var ctx = this._ctx;
|
|
2089
2293
|
ctx.keysOnly = !ctx.isMatch;
|
|
2090
|
-
return this.each(function (val, cursor) {
|
|
2294
|
+
return this.each(function (val, cursor) {
|
|
2295
|
+
cb(cursor.primaryKey, cursor);
|
|
2296
|
+
});
|
|
2091
2297
|
};
|
|
2092
2298
|
Collection.prototype.keys = function (cb) {
|
|
2093
2299
|
var ctx = this._ctx;
|
|
@@ -2095,9 +2301,11 @@ var Collection = (function () {
|
|
|
2095
2301
|
var a = [];
|
|
2096
2302
|
return this.each(function (item, cursor) {
|
|
2097
2303
|
a.push(cursor.key);
|
|
2098
|
-
})
|
|
2304
|
+
})
|
|
2305
|
+
.then(function () {
|
|
2099
2306
|
return a;
|
|
2100
|
-
})
|
|
2307
|
+
})
|
|
2308
|
+
.then(cb);
|
|
2101
2309
|
};
|
|
2102
2310
|
Collection.prototype.primaryKeys = function (cb) {
|
|
2103
2311
|
var ctx = this._ctx;
|
|
@@ -2111,28 +2319,36 @@ var Collection = (function () {
|
|
|
2111
2319
|
direction: ctx.dir === 'prev' ? 'prev' : undefined,
|
|
2112
2320
|
query: {
|
|
2113
2321
|
index: index,
|
|
2114
|
-
range: ctx.range
|
|
2115
|
-
}
|
|
2322
|
+
range: ctx.range,
|
|
2323
|
+
},
|
|
2116
2324
|
});
|
|
2117
|
-
})
|
|
2325
|
+
})
|
|
2326
|
+
.then(function (_a) {
|
|
2118
2327
|
var result = _a.result;
|
|
2119
2328
|
return result;
|
|
2120
|
-
})
|
|
2329
|
+
})
|
|
2330
|
+
.then(cb);
|
|
2121
2331
|
}
|
|
2122
2332
|
ctx.keysOnly = !ctx.isMatch;
|
|
2123
2333
|
var a = [];
|
|
2124
2334
|
return this.each(function (item, cursor) {
|
|
2125
2335
|
a.push(cursor.primaryKey);
|
|
2126
|
-
})
|
|
2336
|
+
})
|
|
2337
|
+
.then(function () {
|
|
2127
2338
|
return a;
|
|
2128
|
-
})
|
|
2339
|
+
})
|
|
2340
|
+
.then(cb);
|
|
2129
2341
|
};
|
|
2130
2342
|
Collection.prototype.uniqueKeys = function (cb) {
|
|
2131
|
-
this._ctx.unique =
|
|
2343
|
+
this._ctx.unique = 'unique';
|
|
2132
2344
|
return this.keys(cb);
|
|
2133
2345
|
};
|
|
2134
2346
|
Collection.prototype.firstKey = function (cb) {
|
|
2135
|
-
return this.limit(1)
|
|
2347
|
+
return this.limit(1)
|
|
2348
|
+
.keys(function (a) {
|
|
2349
|
+
return a[0];
|
|
2350
|
+
})
|
|
2351
|
+
.then(cb);
|
|
2136
2352
|
};
|
|
2137
2353
|
Collection.prototype.lastKey = function (cb) {
|
|
2138
2354
|
return this.reverse().firstKey(cb);
|
|
@@ -2167,7 +2383,8 @@ var Collection = (function () {
|
|
|
2167
2383
|
var modifyChunkSize = _this.db._options.modifyChunkSize;
|
|
2168
2384
|
if (modifyChunkSize) {
|
|
2169
2385
|
if (typeof modifyChunkSize == 'object') {
|
|
2170
|
-
limit =
|
|
2386
|
+
limit =
|
|
2387
|
+
modifyChunkSize[coreTable.name] || modifyChunkSize['*'] || 200;
|
|
2171
2388
|
}
|
|
2172
2389
|
else {
|
|
2173
2390
|
limit = modifyChunkSize;
|
|
@@ -2185,21 +2402,25 @@ var Collection = (function () {
|
|
|
2185
2402
|
}
|
|
2186
2403
|
};
|
|
2187
2404
|
var isUnconditionalDelete = changes === deleteCallback;
|
|
2188
|
-
return _this.clone()
|
|
2405
|
+
return _this.clone()
|
|
2406
|
+
.primaryKeys()
|
|
2407
|
+
.then(function (keys) {
|
|
2189
2408
|
var criteria = isPlainKeyRange(ctx) &&
|
|
2190
2409
|
ctx.limit === Infinity &&
|
|
2191
2410
|
(typeof changes !== 'function' || isUnconditionalDelete) && {
|
|
2192
2411
|
index: ctx.index,
|
|
2193
|
-
range: ctx.range
|
|
2412
|
+
range: ctx.range,
|
|
2194
2413
|
};
|
|
2195
2414
|
var nextChunk = function (offset) {
|
|
2196
2415
|
var count = Math.min(limit, keys.length - offset);
|
|
2197
2416
|
var keysInChunk = keys.slice(offset, offset + count);
|
|
2198
|
-
return (isUnconditionalDelete
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2417
|
+
return (isUnconditionalDelete
|
|
2418
|
+
? Promise.resolve([])
|
|
2419
|
+
: coreTable.getMany({
|
|
2420
|
+
trans: trans,
|
|
2421
|
+
keys: keysInChunk,
|
|
2422
|
+
cache: 'immutable',
|
|
2423
|
+
})).then(function (values) {
|
|
2203
2424
|
var addValues = [];
|
|
2204
2425
|
var putValues = [];
|
|
2205
2426
|
var putKeys = outbound ? [] : null;
|
|
@@ -2209,13 +2430,14 @@ var Collection = (function () {
|
|
|
2209
2430
|
var origValue = values[i];
|
|
2210
2431
|
var ctx_1 = {
|
|
2211
2432
|
value: deepClone(origValue),
|
|
2212
|
-
primKey: keys[offset + i]
|
|
2433
|
+
primKey: keys[offset + i],
|
|
2213
2434
|
};
|
|
2214
2435
|
if (modifyer.call(ctx_1, ctx_1.value, ctx_1) !== false) {
|
|
2215
2436
|
if (ctx_1.value == null) {
|
|
2216
2437
|
deleteKeys.push(keys[offset + i]);
|
|
2217
2438
|
}
|
|
2218
|
-
else if (!outbound &&
|
|
2439
|
+
else if (!outbound &&
|
|
2440
|
+
cmp(extractKey(origValue), extractKey(ctx_1.value)) !== 0) {
|
|
2219
2441
|
deleteKeys.push(keys[offset + i]);
|
|
2220
2442
|
addValues.push(ctx_1.value);
|
|
2221
2443
|
}
|
|
@@ -2227,38 +2449,53 @@ var Collection = (function () {
|
|
|
2227
2449
|
}
|
|
2228
2450
|
}
|
|
2229
2451
|
return Promise.resolve(addValues.length > 0 &&
|
|
2230
|
-
coreTable
|
|
2452
|
+
coreTable
|
|
2453
|
+
.mutate({ trans: trans, type: 'add', values: addValues })
|
|
2231
2454
|
.then(function (res) {
|
|
2232
2455
|
for (var pos in res.failures) {
|
|
2233
2456
|
deleteKeys.splice(parseInt(pos), 1);
|
|
2234
2457
|
}
|
|
2235
2458
|
applyMutateResult(addValues.length, res);
|
|
2236
|
-
}))
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2459
|
+
}))
|
|
2460
|
+
.then(function () {
|
|
2461
|
+
return (putValues.length > 0 ||
|
|
2462
|
+
(criteria && typeof changes === 'object')) &&
|
|
2463
|
+
coreTable
|
|
2464
|
+
.mutate({
|
|
2465
|
+
trans: trans,
|
|
2466
|
+
type: 'put',
|
|
2467
|
+
keys: putKeys,
|
|
2468
|
+
values: putValues,
|
|
2469
|
+
criteria: criteria,
|
|
2470
|
+
changeSpec: typeof changes !== 'function' && changes,
|
|
2471
|
+
isAdditionalChunk: offset > 0,
|
|
2472
|
+
})
|
|
2473
|
+
.then(function (res) { return applyMutateResult(putValues.length, res); });
|
|
2474
|
+
})
|
|
2475
|
+
.then(function () {
|
|
2476
|
+
return (deleteKeys.length > 0 ||
|
|
2477
|
+
(criteria && isUnconditionalDelete)) &&
|
|
2478
|
+
coreTable
|
|
2479
|
+
.mutate({
|
|
2480
|
+
trans: trans,
|
|
2481
|
+
type: 'delete',
|
|
2482
|
+
keys: deleteKeys,
|
|
2483
|
+
criteria: criteria,
|
|
2484
|
+
isAdditionalChunk: offset > 0,
|
|
2485
|
+
})
|
|
2486
|
+
.then(function (res) {
|
|
2487
|
+
return builtInDeletionTrigger(ctx.table, deleteKeys, res);
|
|
2488
|
+
})
|
|
2489
|
+
.then(function (res) { return applyMutateResult(deleteKeys.length, res); });
|
|
2490
|
+
})
|
|
2491
|
+
.then(function () {
|
|
2492
|
+
return (keys.length > offset + count && nextChunk(offset + limit));
|
|
2256
2493
|
});
|
|
2257
2494
|
});
|
|
2258
2495
|
};
|
|
2259
2496
|
return nextChunk(0).then(function () {
|
|
2260
2497
|
if (totalFailures.length > 0)
|
|
2261
|
-
throw new ModifyError(
|
|
2498
|
+
throw new ModifyError('Error modifying one or more objects', totalFailures, successCount, failedKeys);
|
|
2262
2499
|
return keys.length;
|
|
2263
2500
|
});
|
|
2264
2501
|
});
|
|
@@ -2273,12 +2510,15 @@ var Collection = (function () {
|
|
|
2273
2510
|
return this._write(function (trans) {
|
|
2274
2511
|
var primaryKey = ctx.table.core.schema.primaryKey;
|
|
2275
2512
|
var coreRange = range;
|
|
2276
|
-
return ctx.table.core
|
|
2277
|
-
|
|
2513
|
+
return ctx.table.core
|
|
2514
|
+
.count({ trans: trans, query: { index: primaryKey, range: coreRange } })
|
|
2515
|
+
.then(function (count) {
|
|
2516
|
+
return ctx.table.core
|
|
2517
|
+
.mutate({ trans: trans, type: 'deleteRange', range: coreRange })
|
|
2278
2518
|
.then(function (_a) {
|
|
2279
2519
|
var failures = _a.failures, numFailures = _a.numFailures;
|
|
2280
2520
|
if (numFailures)
|
|
2281
|
-
throw new ModifyError(
|
|
2521
|
+
throw new ModifyError('Could not delete some values', Object.keys(failures).map(function (pos) { return failures[pos]; }), count - numFailures);
|
|
2282
2522
|
return count - numFailures;
|
|
2283
2523
|
});
|
|
2284
2524
|
});
|
|
@@ -2288,7 +2528,7 @@ var Collection = (function () {
|
|
|
2288
2528
|
};
|
|
2289
2529
|
return Collection;
|
|
2290
2530
|
}());
|
|
2291
|
-
var deleteCallback = function (value, ctx) { return ctx.value = null; };
|
|
2531
|
+
var deleteCallback = function (value, ctx) { return (ctx.value = null); };
|
|
2292
2532
|
|
|
2293
2533
|
function createCollectionConstructor(db) {
|
|
2294
2534
|
return makeClassConstructor(Collection.prototype, function Collection(whereClause, keyRangeGenerator) {
|
|
@@ -2307,11 +2547,13 @@ function createCollectionConstructor(db) {
|
|
|
2307
2547
|
this._ctx = {
|
|
2308
2548
|
table: table,
|
|
2309
2549
|
index: whereCtx.index,
|
|
2310
|
-
isPrimKey:
|
|
2550
|
+
isPrimKey: !whereCtx.index ||
|
|
2551
|
+
(table.schema.primKey.keyPath &&
|
|
2552
|
+
whereCtx.index === table.schema.primKey.name),
|
|
2311
2553
|
range: keyRange,
|
|
2312
2554
|
keysOnly: false,
|
|
2313
|
-
dir:
|
|
2314
|
-
unique:
|
|
2555
|
+
dir: 'next',
|
|
2556
|
+
unique: '',
|
|
2315
2557
|
algorithm: null,
|
|
2316
2558
|
filter: null,
|
|
2317
2559
|
replayFilter: null,
|
|
@@ -2321,7 +2563,7 @@ function createCollectionConstructor(db) {
|
|
|
2321
2563
|
limit: Infinity,
|
|
2322
2564
|
error: error,
|
|
2323
2565
|
or: whereCtx.or,
|
|
2324
|
-
valueMapper: readingHook !== mirror ? readingHook : null
|
|
2566
|
+
valueMapper: readingHook !== mirror ? readingHook : null,
|
|
2325
2567
|
};
|
|
2326
2568
|
});
|
|
2327
2569
|
}
|
|
@@ -2334,24 +2576,24 @@ function simpleCompareReverse(a, b) {
|
|
|
2334
2576
|
}
|
|
2335
2577
|
|
|
2336
2578
|
function fail(collectionOrWhereClause, err, T) {
|
|
2337
|
-
var collection = collectionOrWhereClause instanceof WhereClause
|
|
2338
|
-
new collectionOrWhereClause.Collection(collectionOrWhereClause)
|
|
2339
|
-
collectionOrWhereClause;
|
|
2579
|
+
var collection = collectionOrWhereClause instanceof WhereClause
|
|
2580
|
+
? new collectionOrWhereClause.Collection(collectionOrWhereClause)
|
|
2581
|
+
: collectionOrWhereClause;
|
|
2340
2582
|
collection._ctx.error = T ? new T(err) : new TypeError(err);
|
|
2341
2583
|
return collection;
|
|
2342
2584
|
}
|
|
2343
2585
|
function emptyCollection(whereClause) {
|
|
2344
|
-
return new whereClause.Collection(whereClause, function () { return rangeEqual(
|
|
2586
|
+
return new whereClause.Collection(whereClause, function () { return rangeEqual(''); }).limit(0);
|
|
2345
2587
|
}
|
|
2346
2588
|
function upperFactory(dir) {
|
|
2347
|
-
return dir ===
|
|
2348
|
-
function (s) { return s.toUpperCase(); }
|
|
2349
|
-
function (s) { return s.toLowerCase(); };
|
|
2589
|
+
return dir === 'next'
|
|
2590
|
+
? function (s) { return s.toUpperCase(); }
|
|
2591
|
+
: function (s) { return s.toLowerCase(); };
|
|
2350
2592
|
}
|
|
2351
2593
|
function lowerFactory(dir) {
|
|
2352
|
-
return dir ===
|
|
2353
|
-
function (s) { return s.toLowerCase(); }
|
|
2354
|
-
function (s) { return s.toUpperCase(); };
|
|
2594
|
+
return dir === 'next'
|
|
2595
|
+
? function (s) { return s.toLowerCase(); }
|
|
2596
|
+
: function (s) { return s.toUpperCase(); };
|
|
2355
2597
|
}
|
|
2356
2598
|
function nextCasing(key, lowerKey, upperNeedle, lowerNeedle, cmp, dir) {
|
|
2357
2599
|
var length = Math.min(key.length, lowerNeedle.length);
|
|
@@ -2370,11 +2612,13 @@ function nextCasing(key, lowerKey, upperNeedle, lowerNeedle, cmp, dir) {
|
|
|
2370
2612
|
if (cmp(key[i], lwrKeyChar) < 0)
|
|
2371
2613
|
llp = i;
|
|
2372
2614
|
}
|
|
2373
|
-
if (length < lowerNeedle.length && dir ===
|
|
2615
|
+
if (length < lowerNeedle.length && dir === 'next')
|
|
2374
2616
|
return key + upperNeedle.substr(key.length);
|
|
2375
|
-
if (length < key.length && dir ===
|
|
2617
|
+
if (length < key.length && dir === 'prev')
|
|
2376
2618
|
return key.substr(0, upperNeedle.length);
|
|
2377
|
-
return
|
|
2619
|
+
return llp < 0
|
|
2620
|
+
? null
|
|
2621
|
+
: key.substr(0, llp) + lowerNeedle[llp] + upperNeedle.substr(llp + 1);
|
|
2378
2622
|
}
|
|
2379
2623
|
function addIgnoreCaseAlgorithm(whereClause, match, needles, suffix) {
|
|
2380
2624
|
var upper, lower, compare, upperNeedles, lowerNeedles, direction, nextKeySuffix, needlesLen = needles.length;
|
|
@@ -2384,19 +2628,27 @@ function addIgnoreCaseAlgorithm(whereClause, match, needles, suffix) {
|
|
|
2384
2628
|
function initDirection(dir) {
|
|
2385
2629
|
upper = upperFactory(dir);
|
|
2386
2630
|
lower = lowerFactory(dir);
|
|
2387
|
-
compare =
|
|
2388
|
-
var needleBounds = needles
|
|
2631
|
+
compare = dir === 'next' ? simpleCompare : simpleCompareReverse;
|
|
2632
|
+
var needleBounds = needles
|
|
2633
|
+
.map(function (needle) {
|
|
2389
2634
|
return { lower: lower(needle), upper: upper(needle) };
|
|
2390
|
-
})
|
|
2635
|
+
})
|
|
2636
|
+
.sort(function (a, b) {
|
|
2391
2637
|
return compare(a.lower, b.lower);
|
|
2392
2638
|
});
|
|
2393
|
-
upperNeedles = needleBounds.map(function (nb) {
|
|
2394
|
-
|
|
2639
|
+
upperNeedles = needleBounds.map(function (nb) {
|
|
2640
|
+
return nb.upper;
|
|
2641
|
+
});
|
|
2642
|
+
lowerNeedles = needleBounds.map(function (nb) {
|
|
2643
|
+
return nb.lower;
|
|
2644
|
+
});
|
|
2395
2645
|
direction = dir;
|
|
2396
|
-
nextKeySuffix =
|
|
2646
|
+
nextKeySuffix = dir === 'next' ? '' : suffix;
|
|
2397
2647
|
}
|
|
2398
|
-
initDirection(
|
|
2399
|
-
var c = new whereClause.Collection(whereClause, function () {
|
|
2648
|
+
initDirection('next');
|
|
2649
|
+
var c = new whereClause.Collection(whereClause, function () {
|
|
2650
|
+
return createRange(upperNeedles[0], lowerNeedles[needlesLen - 1] + suffix);
|
|
2651
|
+
});
|
|
2400
2652
|
c._ondirectionchange = function (direction) {
|
|
2401
2653
|
initDirection(direction);
|
|
2402
2654
|
};
|
|
@@ -2415,12 +2667,15 @@ function addIgnoreCaseAlgorithm(whereClause, match, needles, suffix) {
|
|
|
2415
2667
|
var casing = nextCasing(key, lowerKey, upperNeedles[i], lowerNeedles[i], compare, direction);
|
|
2416
2668
|
if (casing === null && lowestPossibleCasing === null)
|
|
2417
2669
|
firstPossibleNeedle = i + 1;
|
|
2418
|
-
else if (lowestPossibleCasing === null ||
|
|
2670
|
+
else if (lowestPossibleCasing === null ||
|
|
2671
|
+
compare(lowestPossibleCasing, casing) > 0) {
|
|
2419
2672
|
lowestPossibleCasing = casing;
|
|
2420
2673
|
}
|
|
2421
2674
|
}
|
|
2422
2675
|
if (lowestPossibleCasing !== null) {
|
|
2423
|
-
advance(function () {
|
|
2676
|
+
advance(function () {
|
|
2677
|
+
cursor.continue(lowestPossibleCasing + nextKeySuffix);
|
|
2678
|
+
});
|
|
2424
2679
|
}
|
|
2425
2680
|
else {
|
|
2426
2681
|
advance(resolve);
|
|
@@ -2436,14 +2691,14 @@ function createRange(lower, upper, lowerOpen, upperOpen) {
|
|
|
2436
2691
|
lower: lower,
|
|
2437
2692
|
upper: upper,
|
|
2438
2693
|
lowerOpen: lowerOpen,
|
|
2439
|
-
upperOpen: upperOpen
|
|
2694
|
+
upperOpen: upperOpen,
|
|
2440
2695
|
};
|
|
2441
2696
|
}
|
|
2442
2697
|
function rangeEqual(value) {
|
|
2443
2698
|
return {
|
|
2444
2699
|
type: 1 ,
|
|
2445
2700
|
lower: value,
|
|
2446
|
-
upper: value
|
|
2701
|
+
upper: value,
|
|
2447
2702
|
};
|
|
2448
2703
|
}
|
|
2449
2704
|
|
|
@@ -2461,10 +2716,14 @@ var WhereClause = (function () {
|
|
|
2461
2716
|
includeLower = includeLower !== false;
|
|
2462
2717
|
includeUpper = includeUpper === true;
|
|
2463
2718
|
try {
|
|
2464
|
-
if (
|
|
2465
|
-
(this._cmp(lower, upper) === 0 &&
|
|
2719
|
+
if (this._cmp(lower, upper) > 0 ||
|
|
2720
|
+
(this._cmp(lower, upper) === 0 &&
|
|
2721
|
+
(includeLower || includeUpper) &&
|
|
2722
|
+
!(includeLower && includeUpper)))
|
|
2466
2723
|
return emptyCollection(this);
|
|
2467
|
-
return new this.Collection(this, function () {
|
|
2724
|
+
return new this.Collection(this, function () {
|
|
2725
|
+
return createRange(lower, upper, !includeLower, !includeUpper);
|
|
2726
|
+
});
|
|
2468
2727
|
}
|
|
2469
2728
|
catch (e) {
|
|
2470
2729
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
@@ -2483,12 +2742,16 @@ var WhereClause = (function () {
|
|
|
2483
2742
|
WhereClause.prototype.aboveOrEqual = function (value) {
|
|
2484
2743
|
if (value == null)
|
|
2485
2744
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
2486
|
-
return new this.Collection(this, function () {
|
|
2745
|
+
return new this.Collection(this, function () {
|
|
2746
|
+
return createRange(value, undefined, false);
|
|
2747
|
+
});
|
|
2487
2748
|
};
|
|
2488
2749
|
WhereClause.prototype.below = function (value) {
|
|
2489
2750
|
if (value == null)
|
|
2490
2751
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
2491
|
-
return new this.Collection(this, function () {
|
|
2752
|
+
return new this.Collection(this, function () {
|
|
2753
|
+
return createRange(undefined, value, false, true);
|
|
2754
|
+
});
|
|
2492
2755
|
};
|
|
2493
2756
|
WhereClause.prototype.belowOrEqual = function (value) {
|
|
2494
2757
|
if (value == null)
|
|
@@ -2501,18 +2764,18 @@ var WhereClause = (function () {
|
|
|
2501
2764
|
return this.between(str, str + maxString, true, true);
|
|
2502
2765
|
};
|
|
2503
2766
|
WhereClause.prototype.startsWithIgnoreCase = function (str) {
|
|
2504
|
-
if (str ===
|
|
2767
|
+
if (str === '')
|
|
2505
2768
|
return this.startsWith(str);
|
|
2506
2769
|
return addIgnoreCaseAlgorithm(this, function (x, a) { return x.indexOf(a[0]) === 0; }, [str], maxString);
|
|
2507
2770
|
};
|
|
2508
2771
|
WhereClause.prototype.equalsIgnoreCase = function (str) {
|
|
2509
|
-
return addIgnoreCaseAlgorithm(this, function (x, a) { return x === a[0]; }, [str],
|
|
2772
|
+
return addIgnoreCaseAlgorithm(this, function (x, a) { return x === a[0]; }, [str], '');
|
|
2510
2773
|
};
|
|
2511
2774
|
WhereClause.prototype.anyOfIgnoreCase = function () {
|
|
2512
2775
|
var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
2513
2776
|
if (set.length === 0)
|
|
2514
2777
|
return emptyCollection(this);
|
|
2515
|
-
return addIgnoreCaseAlgorithm(this, function (x, a) { return a.indexOf(x) !== -1; }, set,
|
|
2778
|
+
return addIgnoreCaseAlgorithm(this, function (x, a) { return a.indexOf(x) !== -1; }, set, '');
|
|
2516
2779
|
};
|
|
2517
2780
|
WhereClause.prototype.startsWithAnyOfIgnoreCase = function () {
|
|
2518
2781
|
var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
@@ -2532,11 +2795,11 @@ var WhereClause = (function () {
|
|
|
2532
2795
|
}
|
|
2533
2796
|
if (set.length === 0)
|
|
2534
2797
|
return emptyCollection(this);
|
|
2535
|
-
var c = new this.Collection(this, function () {
|
|
2798
|
+
var c = new this.Collection(this, function () {
|
|
2799
|
+
return createRange(set[0], set[set.length - 1]);
|
|
2800
|
+
});
|
|
2536
2801
|
c._ondirectionchange = function (direction) {
|
|
2537
|
-
compare =
|
|
2538
|
-
_this._ascending :
|
|
2539
|
-
_this._descending);
|
|
2802
|
+
compare = direction === 'next' ? _this._ascending : _this._descending;
|
|
2540
2803
|
set.sort(compare);
|
|
2541
2804
|
};
|
|
2542
2805
|
var i = 0;
|
|
@@ -2553,14 +2816,19 @@ var WhereClause = (function () {
|
|
|
2553
2816
|
return true;
|
|
2554
2817
|
}
|
|
2555
2818
|
else {
|
|
2556
|
-
advance(function () {
|
|
2819
|
+
advance(function () {
|
|
2820
|
+
cursor.continue(set[i]);
|
|
2821
|
+
});
|
|
2557
2822
|
return false;
|
|
2558
2823
|
}
|
|
2559
2824
|
});
|
|
2560
2825
|
return c;
|
|
2561
2826
|
};
|
|
2562
2827
|
WhereClause.prototype.notEqual = function (value) {
|
|
2563
|
-
return this.inAnyRange([
|
|
2828
|
+
return this.inAnyRange([
|
|
2829
|
+
[minKey, value],
|
|
2830
|
+
[value, this.db._maxKey],
|
|
2831
|
+
], { includeLowers: false, includeUppers: false });
|
|
2564
2832
|
};
|
|
2565
2833
|
WhereClause.prototype.noneOf = function () {
|
|
2566
2834
|
var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
@@ -2572,11 +2840,14 @@ var WhereClause = (function () {
|
|
|
2572
2840
|
catch (e) {
|
|
2573
2841
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
2574
2842
|
}
|
|
2575
|
-
var ranges = set.reduce(function (res, val) {
|
|
2576
|
-
res.concat([[res[res.length - 1][1], val]]) :
|
|
2577
|
-
|
|
2843
|
+
var ranges = set.reduce(function (res, val) {
|
|
2844
|
+
return res ? res.concat([[res[res.length - 1][1], val]]) : [[minKey, val]];
|
|
2845
|
+
}, null);
|
|
2578
2846
|
ranges.push([set[set.length - 1], this.db._maxKey]);
|
|
2579
|
-
return this.inAnyRange(ranges, {
|
|
2847
|
+
return this.inAnyRange(ranges, {
|
|
2848
|
+
includeLowers: false,
|
|
2849
|
+
includeUppers: false,
|
|
2850
|
+
});
|
|
2580
2851
|
};
|
|
2581
2852
|
WhereClause.prototype.inAnyRange = function (ranges, options) {
|
|
2582
2853
|
var _this = this;
|
|
@@ -2588,7 +2859,7 @@ var WhereClause = (function () {
|
|
|
2588
2859
|
range[1] !== undefined &&
|
|
2589
2860
|
ascending(range[0], range[1]) <= 0;
|
|
2590
2861
|
})) {
|
|
2591
|
-
return fail(this,
|
|
2862
|
+
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
2863
|
}
|
|
2593
2864
|
var includeLowers = !options || options.includeLowers !== false;
|
|
2594
2865
|
var includeUppers = options && options.includeUppers === true;
|
|
@@ -2607,7 +2878,9 @@ var WhereClause = (function () {
|
|
|
2607
2878
|
return ranges;
|
|
2608
2879
|
}
|
|
2609
2880
|
var sortDirection = ascending;
|
|
2610
|
-
function rangeSorter(a, b) {
|
|
2881
|
+
function rangeSorter(a, b) {
|
|
2882
|
+
return sortDirection(a[0], b[0]);
|
|
2883
|
+
}
|
|
2611
2884
|
var set;
|
|
2612
2885
|
try {
|
|
2613
2886
|
set = ranges.reduce(addRange, []);
|
|
@@ -2617,19 +2890,21 @@ var WhereClause = (function () {
|
|
|
2617
2890
|
return fail(this, INVALID_KEY_ARGUMENT);
|
|
2618
2891
|
}
|
|
2619
2892
|
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; };
|
|
2893
|
+
var keyIsBeyondCurrentEntry = includeUppers
|
|
2894
|
+
? function (key) { return ascending(key, set[rangePos][1]) > 0; }
|
|
2895
|
+
: function (key) { return ascending(key, set[rangePos][1]) >= 0; };
|
|
2896
|
+
var keyIsBeforeCurrentEntry = includeLowers
|
|
2897
|
+
? function (key) { return descending(key, set[rangePos][0]) > 0; }
|
|
2898
|
+
: function (key) { return descending(key, set[rangePos][0]) >= 0; };
|
|
2626
2899
|
function keyWithinCurrentRange(key) {
|
|
2627
2900
|
return !keyIsBeyondCurrentEntry(key) && !keyIsBeforeCurrentEntry(key);
|
|
2628
2901
|
}
|
|
2629
2902
|
var checkKey = keyIsBeyondCurrentEntry;
|
|
2630
|
-
var c = new this.Collection(this, function () {
|
|
2903
|
+
var c = new this.Collection(this, function () {
|
|
2904
|
+
return createRange(set[0][0], set[set.length - 1][1], !includeLowers, !includeUppers);
|
|
2905
|
+
});
|
|
2631
2906
|
c._ondirectionchange = function (direction) {
|
|
2632
|
-
if (direction ===
|
|
2907
|
+
if (direction === 'next') {
|
|
2633
2908
|
checkKey = keyIsBeyondCurrentEntry;
|
|
2634
2909
|
sortDirection = ascending;
|
|
2635
2910
|
}
|
|
@@ -2651,7 +2926,8 @@ var WhereClause = (function () {
|
|
|
2651
2926
|
if (keyWithinCurrentRange(key)) {
|
|
2652
2927
|
return true;
|
|
2653
2928
|
}
|
|
2654
|
-
else if (_this._cmp(key, set[rangePos][1]) === 0 ||
|
|
2929
|
+
else if (_this._cmp(key, set[rangePos][1]) === 0 ||
|
|
2930
|
+
_this._cmp(key, set[rangePos][0]) === 0) {
|
|
2655
2931
|
return false;
|
|
2656
2932
|
}
|
|
2657
2933
|
else {
|
|
@@ -2669,7 +2945,7 @@ var WhereClause = (function () {
|
|
|
2669
2945
|
WhereClause.prototype.startsWithAnyOf = function () {
|
|
2670
2946
|
var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
|
|
2671
2947
|
if (!set.every(function (s) { return typeof s === 'string'; })) {
|
|
2672
|
-
return fail(this,
|
|
2948
|
+
return fail(this, 'startsWithAnyOf() only works with strings');
|
|
2673
2949
|
}
|
|
2674
2950
|
if (set.length === 0)
|
|
2675
2951
|
return emptyCollection(this);
|
|
@@ -2683,13 +2959,13 @@ function createWhereClauseConstructor(db) {
|
|
|
2683
2959
|
this.db = db;
|
|
2684
2960
|
this._ctx = {
|
|
2685
2961
|
table: table,
|
|
2686
|
-
index: index ===
|
|
2687
|
-
or: orCollection
|
|
2962
|
+
index: index === ':id' ? null : index,
|
|
2963
|
+
or: orCollection,
|
|
2688
2964
|
};
|
|
2689
2965
|
this._cmp = this._ascending = cmp;
|
|
2690
2966
|
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; };
|
|
2967
|
+
this._max = function (a, b) { return (cmp(a, b) > 0 ? a : b); };
|
|
2968
|
+
this._min = function (a, b) { return (cmp(a, b) < 0 ? a : b); };
|
|
2693
2969
|
this._IDBKeyRange = db._deps.IDBKeyRange;
|
|
2694
2970
|
if (!this._IDBKeyRange)
|
|
2695
2971
|
throw new exceptions.MissingAPI();
|
|
@@ -2751,9 +3027,9 @@ var Transaction = (function () {
|
|
|
2751
3027
|
assert(!this.idbtrans);
|
|
2752
3028
|
if (!idbtrans && !idbdb) {
|
|
2753
3029
|
switch (dbOpenError && dbOpenError.name) {
|
|
2754
|
-
case
|
|
3030
|
+
case 'DatabaseClosedError':
|
|
2755
3031
|
throw new exceptions.DatabaseClosed(dbOpenError);
|
|
2756
|
-
case
|
|
3032
|
+
case 'MissingAPIError':
|
|
2757
3033
|
throw new exceptions.MissingAPI(dbOpenError.message, dbOpenError);
|
|
2758
3034
|
default:
|
|
2759
3035
|
throw new exceptions.OpenFailed(dbOpenError);
|
|
@@ -2762,10 +3038,13 @@ var Transaction = (function () {
|
|
|
2762
3038
|
if (!this.active)
|
|
2763
3039
|
throw new exceptions.TransactionInactive();
|
|
2764
3040
|
assert(this._completion._state === null);
|
|
2765
|
-
idbtrans = this.idbtrans =
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
3041
|
+
idbtrans = this.idbtrans =
|
|
3042
|
+
idbtrans ||
|
|
3043
|
+
(this.db.core
|
|
3044
|
+
? this.db.core.transaction(this.storeNames, this.mode, { durability: this.chromeTransactionDurability })
|
|
3045
|
+
: idbdb.transaction(this.storeNames, this.mode, {
|
|
3046
|
+
durability: this.chromeTransactionDurability,
|
|
3047
|
+
}));
|
|
2769
3048
|
idbtrans.onerror = wrap(function (ev) {
|
|
2770
3049
|
preventDefault(ev);
|
|
2771
3050
|
_this._reject(idbtrans.error);
|
|
@@ -2774,13 +3053,13 @@ var Transaction = (function () {
|
|
|
2774
3053
|
preventDefault(ev);
|
|
2775
3054
|
_this.active && _this._reject(new exceptions.Abort(idbtrans.error));
|
|
2776
3055
|
_this.active = false;
|
|
2777
|
-
_this.on(
|
|
3056
|
+
_this.on('abort').fire(ev);
|
|
2778
3057
|
});
|
|
2779
3058
|
idbtrans.oncomplete = wrap(function () {
|
|
2780
3059
|
_this.active = false;
|
|
2781
3060
|
_this._resolve();
|
|
2782
3061
|
if ('mutatedParts' in idbtrans) {
|
|
2783
|
-
globalEvents.storagemutated.fire(idbtrans[
|
|
3062
|
+
globalEvents.storagemutated.fire(idbtrans['mutatedParts']);
|
|
2784
3063
|
}
|
|
2785
3064
|
});
|
|
2786
3065
|
return this;
|
|
@@ -2788,14 +3067,17 @@ var Transaction = (function () {
|
|
|
2788
3067
|
Transaction.prototype._promise = function (mode, fn, bWriteLock) {
|
|
2789
3068
|
var _this = this;
|
|
2790
3069
|
if (mode === 'readwrite' && this.mode !== 'readwrite')
|
|
2791
|
-
return rejection(new exceptions.ReadOnly(
|
|
3070
|
+
return rejection(new exceptions.ReadOnly('Transaction is readonly'));
|
|
2792
3071
|
if (!this.active)
|
|
2793
3072
|
return rejection(new exceptions.TransactionInactive());
|
|
2794
3073
|
if (this._locked()) {
|
|
2795
3074
|
return new DexiePromise(function (resolve, reject) {
|
|
2796
|
-
_this._blockedFuncs.push([
|
|
3075
|
+
_this._blockedFuncs.push([
|
|
3076
|
+
function () {
|
|
2797
3077
|
_this._promise(mode, fn, bWriteLock).then(resolve, reject);
|
|
2798
|
-
},
|
|
3078
|
+
},
|
|
3079
|
+
PSD,
|
|
3080
|
+
]);
|
|
2799
3081
|
});
|
|
2800
3082
|
}
|
|
2801
3083
|
else if (bWriteLock) {
|
|
@@ -2837,14 +3119,16 @@ var Transaction = (function () {
|
|
|
2837
3119
|
(function spin() {
|
|
2838
3120
|
++root._spinCount;
|
|
2839
3121
|
while (root._waitingQueue.length)
|
|
2840
|
-
|
|
3122
|
+
root._waitingQueue.shift()();
|
|
2841
3123
|
if (root._waitingFor)
|
|
2842
3124
|
store.get(-Infinity).onsuccess = spin;
|
|
2843
|
-
}()
|
|
3125
|
+
})();
|
|
2844
3126
|
}
|
|
2845
3127
|
var currentWaitPromise = root._waitingFor;
|
|
2846
3128
|
return new DexiePromise(function (resolve, reject) {
|
|
2847
|
-
promise
|
|
3129
|
+
promise
|
|
3130
|
+
.then(function (res) { return root._waitingQueue.push(wrap(resolve.bind(null, res))); }, function (err) { return root._waitingQueue.push(wrap(reject.bind(null, err))); })
|
|
3131
|
+
.finally(function () {
|
|
2848
3132
|
if (root._waitingFor === currentWaitPromise) {
|
|
2849
3133
|
root._waitingFor = null;
|
|
2850
3134
|
}
|
|
@@ -2860,12 +3144,12 @@ var Transaction = (function () {
|
|
|
2860
3144
|
}
|
|
2861
3145
|
};
|
|
2862
3146
|
Transaction.prototype.table = function (tableName) {
|
|
2863
|
-
var memoizedTables =
|
|
3147
|
+
var memoizedTables = this._memoizedTables || (this._memoizedTables = {});
|
|
2864
3148
|
if (hasOwn(memoizedTables, tableName))
|
|
2865
3149
|
return memoizedTables[tableName];
|
|
2866
3150
|
var tableSchema = this.schema[tableName];
|
|
2867
3151
|
if (!tableSchema) {
|
|
2868
|
-
throw new exceptions.NotFound(
|
|
3152
|
+
throw new exceptions.NotFound('Table ' + tableName + ' not part of transaction');
|
|
2869
3153
|
}
|
|
2870
3154
|
var transactionBoundTable = new this.db.Table(tableName, tableSchema, this);
|
|
2871
3155
|
transactionBoundTable.core = this.db.core.table(tableName);
|
|
@@ -2891,7 +3175,7 @@ function createTransactionConstructor(db) {
|
|
|
2891
3175
|
this.schema = dbschema;
|
|
2892
3176
|
this.chromeTransactionDurability = chromeTransactionDurability;
|
|
2893
3177
|
this.idbtrans = null;
|
|
2894
|
-
this.on = Events(this,
|
|
3178
|
+
this.on = Events(this, 'complete', 'error', 'abort');
|
|
2895
3179
|
this.parent = parent || null;
|
|
2896
3180
|
this.active = true;
|
|
2897
3181
|
this._reculock = 0;
|
|
@@ -2912,9 +3196,9 @@ function createTransactionConstructor(db) {
|
|
|
2912
3196
|
var wasActive = _this.active;
|
|
2913
3197
|
_this.active = false;
|
|
2914
3198
|
_this.on.error.fire(e);
|
|
2915
|
-
_this.parent
|
|
2916
|
-
_this.parent._reject(e)
|
|
2917
|
-
wasActive && _this.idbtrans && _this.idbtrans.abort();
|
|
3199
|
+
_this.parent
|
|
3200
|
+
? _this.parent._reject(e)
|
|
3201
|
+
: wasActive && _this.idbtrans && _this.idbtrans.abort();
|
|
2918
3202
|
return rejection(e);
|
|
2919
3203
|
});
|
|
2920
3204
|
});
|
|
@@ -2928,14 +3212,19 @@ function createIndexSpec(name, keyPath, unique, multi, auto, compound, isPrimKey
|
|
|
2928
3212
|
multi: multi,
|
|
2929
3213
|
auto: auto,
|
|
2930
3214
|
compound: compound,
|
|
2931
|
-
src: (unique && !isPrimKey ? '&' : '') +
|
|
2932
|
-
|
|
3215
|
+
src: (unique && !isPrimKey ? '&' : '') +
|
|
3216
|
+
(multi ? '*' : '') +
|
|
3217
|
+
(auto ? '++' : '') +
|
|
3218
|
+
nameFromKeyPath(keyPath),
|
|
3219
|
+
type: type,
|
|
2933
3220
|
};
|
|
2934
3221
|
}
|
|
2935
3222
|
function nameFromKeyPath(keyPath) {
|
|
2936
|
-
return typeof keyPath === 'string'
|
|
2937
|
-
keyPath
|
|
2938
|
-
|
|
3223
|
+
return typeof keyPath === 'string'
|
|
3224
|
+
? keyPath
|
|
3225
|
+
: keyPath
|
|
3226
|
+
? '[' + [].join.call(keyPath, '+') + ']'
|
|
3227
|
+
: '';
|
|
2939
3228
|
}
|
|
2940
3229
|
|
|
2941
3230
|
function createTableSchema(name, primKey, indexes) {
|
|
@@ -2989,22 +3278,22 @@ function arrayify(arrayLike) {
|
|
|
2989
3278
|
}
|
|
2990
3279
|
var _id_counter = 0;
|
|
2991
3280
|
function getKeyPathAlias(keyPath) {
|
|
2992
|
-
return keyPath == null
|
|
2993
|
-
|
|
2994
|
-
typeof keyPath === 'string'
|
|
2995
|
-
keyPath
|
|
2996
|
-
"[".concat(keyPath.join('+'), "]");
|
|
3281
|
+
return keyPath == null
|
|
3282
|
+
? ':id'
|
|
3283
|
+
: typeof keyPath === 'string'
|
|
3284
|
+
? keyPath
|
|
3285
|
+
: "[".concat(keyPath.join('+'), "]");
|
|
2997
3286
|
}
|
|
2998
3287
|
function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
2999
3288
|
function extractSchema(db, trans) {
|
|
3000
3289
|
var tables = arrayify(db.objectStoreNames);
|
|
3001
|
-
var tempStore = tables.length > 0
|
|
3002
|
-
? trans.objectStore(tables[0])
|
|
3003
|
-
: {};
|
|
3290
|
+
var tempStore = tables.length > 0 ? trans.objectStore(tables[0]) : {};
|
|
3004
3291
|
return {
|
|
3005
3292
|
schema: {
|
|
3006
3293
|
name: db.name,
|
|
3007
|
-
tables: tables
|
|
3294
|
+
tables: tables
|
|
3295
|
+
.map(function (table) { return trans.objectStore(table); })
|
|
3296
|
+
.map(function (store) {
|
|
3008
3297
|
var keyPath = store.keyPath, autoIncrement = store.autoIncrement;
|
|
3009
3298
|
var compound = isArray(keyPath);
|
|
3010
3299
|
var outbound = keyPath == null;
|
|
@@ -3019,9 +3308,10 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3019
3308
|
keyPath: keyPath,
|
|
3020
3309
|
autoIncrement: autoIncrement,
|
|
3021
3310
|
unique: true,
|
|
3022
|
-
extractKey: getKeyExtractor(keyPath)
|
|
3311
|
+
extractKey: getKeyExtractor(keyPath),
|
|
3023
3312
|
},
|
|
3024
|
-
indexes: arrayify(store.indexNames)
|
|
3313
|
+
indexes: arrayify(store.indexNames)
|
|
3314
|
+
.map(function (indexName) { return store.index(indexName); })
|
|
3025
3315
|
.map(function (index) {
|
|
3026
3316
|
var name = index.name, unique = index.unique, multiEntry = index.multiEntry, keyPath = index.keyPath;
|
|
3027
3317
|
var compound = isArray(keyPath);
|
|
@@ -3031,40 +3321,44 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3031
3321
|
keyPath: keyPath,
|
|
3032
3322
|
unique: unique,
|
|
3033
3323
|
multiEntry: multiEntry,
|
|
3034
|
-
extractKey: getKeyExtractor(keyPath)
|
|
3324
|
+
extractKey: getKeyExtractor(keyPath),
|
|
3035
3325
|
};
|
|
3036
3326
|
indexByKeyPath[getKeyPathAlias(keyPath)] = result;
|
|
3037
3327
|
return result;
|
|
3038
3328
|
}),
|
|
3039
|
-
getIndexByKeyPath: function (keyPath) {
|
|
3329
|
+
getIndexByKeyPath: function (keyPath) {
|
|
3330
|
+
return indexByKeyPath[getKeyPathAlias(keyPath)];
|
|
3331
|
+
},
|
|
3040
3332
|
};
|
|
3041
|
-
indexByKeyPath[
|
|
3333
|
+
indexByKeyPath[':id'] = result.primaryKey;
|
|
3042
3334
|
if (keyPath != null) {
|
|
3043
3335
|
indexByKeyPath[getKeyPathAlias(keyPath)] = result.primaryKey;
|
|
3044
3336
|
}
|
|
3045
3337
|
return result;
|
|
3046
|
-
})
|
|
3338
|
+
}),
|
|
3047
3339
|
},
|
|
3048
|
-
hasGetAll: tables.length > 0 &&
|
|
3049
|
-
|
|
3340
|
+
hasGetAll: tables.length > 0 &&
|
|
3341
|
+
'getAll' in tempStore &&
|
|
3342
|
+
!(typeof navigator !== 'undefined' &&
|
|
3343
|
+
/Safari/.test(navigator.userAgent) &&
|
|
3050
3344
|
!/(Chrome\/|Edge\/)/.test(navigator.userAgent) &&
|
|
3051
3345
|
[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604),
|
|
3052
|
-
hasIdb3Features: 'getAllRecords' in tempStore
|
|
3346
|
+
hasIdb3Features: 'getAllRecords' in tempStore,
|
|
3053
3347
|
};
|
|
3054
3348
|
}
|
|
3055
3349
|
function makeIDBKeyRange(range) {
|
|
3056
3350
|
if (range.type === 3 )
|
|
3057
3351
|
return null;
|
|
3058
3352
|
if (range.type === 4 )
|
|
3059
|
-
throw new Error(
|
|
3353
|
+
throw new Error('Cannot convert never type to IDBKeyRange');
|
|
3060
3354
|
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);
|
|
3355
|
+
var idbRange = lower === undefined
|
|
3356
|
+
? upper === undefined
|
|
3357
|
+
? null
|
|
3358
|
+
: IdbKeyRange.upperBound(upper, !!upperOpen)
|
|
3359
|
+
: upper === undefined
|
|
3360
|
+
? IdbKeyRange.lowerBound(lower, !!lowerOpen)
|
|
3361
|
+
: IdbKeyRange.bound(lower, upper, !!lowerOpen, !!upperOpen);
|
|
3068
3362
|
return idbRange;
|
|
3069
3363
|
}
|
|
3070
3364
|
function createDbCoreTable(tableSchema) {
|
|
@@ -3075,15 +3369,20 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3075
3369
|
resolve = wrap(resolve);
|
|
3076
3370
|
var store = trans.objectStore(tableName);
|
|
3077
3371
|
var outbound = store.keyPath == null;
|
|
3078
|
-
var isAddOrPut = type ===
|
|
3372
|
+
var isAddOrPut = type === 'put' || type === 'add';
|
|
3079
3373
|
if (!isAddOrPut && type !== 'delete' && type !== 'deleteRange')
|
|
3080
|
-
throw new Error(
|
|
3374
|
+
throw new Error('Invalid operation type: ' + type);
|
|
3081
3375
|
var length = (keys || values || { length: 1 }).length;
|
|
3082
3376
|
if (keys && values && keys.length !== values.length) {
|
|
3083
|
-
throw new Error(
|
|
3377
|
+
throw new Error('Given keys array must have same length as given values array.');
|
|
3084
3378
|
}
|
|
3085
3379
|
if (length === 0)
|
|
3086
|
-
return resolve({
|
|
3380
|
+
return resolve({
|
|
3381
|
+
numFailures: 0,
|
|
3382
|
+
failures: {},
|
|
3383
|
+
results: [],
|
|
3384
|
+
lastResult: undefined,
|
|
3385
|
+
});
|
|
3087
3386
|
var req;
|
|
3088
3387
|
var reqs = [];
|
|
3089
3388
|
var failures = [];
|
|
@@ -3094,29 +3393,34 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3094
3393
|
};
|
|
3095
3394
|
if (type === 'deleteRange') {
|
|
3096
3395
|
if (range.type === 4 )
|
|
3097
|
-
return resolve({
|
|
3396
|
+
return resolve({
|
|
3397
|
+
numFailures: numFailures,
|
|
3398
|
+
failures: failures,
|
|
3399
|
+
results: [],
|
|
3400
|
+
lastResult: undefined,
|
|
3401
|
+
});
|
|
3098
3402
|
if (range.type === 3 )
|
|
3099
|
-
reqs.push(req = store.clear());
|
|
3403
|
+
reqs.push((req = store.clear()));
|
|
3100
3404
|
else
|
|
3101
|
-
reqs.push(req = store.delete(makeIDBKeyRange(range)));
|
|
3405
|
+
reqs.push((req = store.delete(makeIDBKeyRange(range))));
|
|
3102
3406
|
}
|
|
3103
3407
|
else {
|
|
3104
|
-
var _a = isAddOrPut
|
|
3105
|
-
outbound
|
|
3106
|
-
[values, keys]
|
|
3107
|
-
[values, null]
|
|
3108
|
-
[keys, null], args1 = _a[0], args2 = _a[1];
|
|
3408
|
+
var _a = isAddOrPut
|
|
3409
|
+
? outbound
|
|
3410
|
+
? [values, keys]
|
|
3411
|
+
: [values, null]
|
|
3412
|
+
: [keys, null], args1 = _a[0], args2 = _a[1];
|
|
3109
3413
|
if (isAddOrPut) {
|
|
3110
3414
|
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])));
|
|
3415
|
+
reqs.push((req = (args2 && args2[i] !== undefined
|
|
3416
|
+
? store[type](args1[i], args2[i])
|
|
3417
|
+
: store[type](args1[i]))));
|
|
3114
3418
|
req.onerror = errorHandler;
|
|
3115
3419
|
}
|
|
3116
3420
|
}
|
|
3117
3421
|
else {
|
|
3118
3422
|
for (var i = 0; i < length; ++i) {
|
|
3119
|
-
reqs.push(req = store[type](args1[i]));
|
|
3423
|
+
reqs.push((req = store[type](args1[i])));
|
|
3120
3424
|
req.onerror = errorHandler;
|
|
3121
3425
|
}
|
|
3122
3426
|
}
|
|
@@ -3127,8 +3431,8 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3127
3431
|
resolve({
|
|
3128
3432
|
numFailures: numFailures,
|
|
3129
3433
|
failures: failures,
|
|
3130
|
-
results: type ===
|
|
3131
|
-
lastResult: lastResult
|
|
3434
|
+
results: type === 'delete' ? keys : reqs.map(function (req) { return req.result; }),
|
|
3435
|
+
lastResult: lastResult,
|
|
3132
3436
|
});
|
|
3133
3437
|
};
|
|
3134
3438
|
req.onerror = function (event) {
|
|
@@ -3144,19 +3448,17 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3144
3448
|
resolve = wrap(resolve);
|
|
3145
3449
|
var index = query.index, range = query.range;
|
|
3146
3450
|
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);
|
|
3451
|
+
var source = index.isPrimaryKey ? store : store.index(index.name);
|
|
3452
|
+
var direction = reverse
|
|
3453
|
+
? unique
|
|
3454
|
+
? 'prevunique'
|
|
3455
|
+
: 'prev'
|
|
3456
|
+
: unique
|
|
3457
|
+
? 'nextunique'
|
|
3458
|
+
: 'next';
|
|
3459
|
+
var req = values || !('openKeyCursor' in source)
|
|
3460
|
+
? source.openCursor(makeIDBKeyRange(range), direction)
|
|
3461
|
+
: source.openKeyCursor(makeIDBKeyRange(range), direction);
|
|
3160
3462
|
req.onerror = eventRejectHandler(reject);
|
|
3161
3463
|
req.onsuccess = wrap(function (ev) {
|
|
3162
3464
|
var cursor = req.result;
|
|
@@ -3171,15 +3473,25 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3171
3473
|
if (_cursorContinuePrimaryKey)
|
|
3172
3474
|
_cursorContinuePrimaryKey = _cursorContinuePrimaryKey.bind(cursor);
|
|
3173
3475
|
var _cursorAdvance = cursor.advance.bind(cursor);
|
|
3174
|
-
var doThrowCursorIsNotStarted = function () {
|
|
3175
|
-
|
|
3476
|
+
var doThrowCursorIsNotStarted = function () {
|
|
3477
|
+
throw new Error('Cursor not started');
|
|
3478
|
+
};
|
|
3479
|
+
var doThrowCursorIsStopped = function () {
|
|
3480
|
+
throw new Error('Cursor not stopped');
|
|
3481
|
+
};
|
|
3176
3482
|
cursor.trans = trans;
|
|
3177
|
-
cursor.stop =
|
|
3483
|
+
cursor.stop =
|
|
3484
|
+
cursor.continue =
|
|
3485
|
+
cursor.continuePrimaryKey =
|
|
3486
|
+
cursor.advance =
|
|
3487
|
+
doThrowCursorIsNotStarted;
|
|
3178
3488
|
cursor.fail = wrap(reject);
|
|
3179
3489
|
cursor.next = function () {
|
|
3180
3490
|
var _this = this;
|
|
3181
3491
|
var gotOne = 1;
|
|
3182
|
-
return this.start(function () {
|
|
3492
|
+
return this.start(function () {
|
|
3493
|
+
return gotOne-- ? _this.continue() : _this.stop();
|
|
3494
|
+
}).then(function () { return _this; });
|
|
3183
3495
|
};
|
|
3184
3496
|
cursor.start = function (callback) {
|
|
3185
3497
|
var iterationPromise = new Promise(function (resolveIteration, rejectIteration) {
|
|
@@ -3187,7 +3499,11 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3187
3499
|
req.onerror = eventRejectHandler(rejectIteration);
|
|
3188
3500
|
cursor.fail = rejectIteration;
|
|
3189
3501
|
cursor.stop = function (value) {
|
|
3190
|
-
cursor.stop =
|
|
3502
|
+
cursor.stop =
|
|
3503
|
+
cursor.continue =
|
|
3504
|
+
cursor.continuePrimaryKey =
|
|
3505
|
+
cursor.advance =
|
|
3506
|
+
doThrowCursorIsStopped;
|
|
3191
3507
|
resolveIteration(value);
|
|
3192
3508
|
};
|
|
3193
3509
|
});
|
|
@@ -3202,7 +3518,9 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3202
3518
|
}
|
|
3203
3519
|
else {
|
|
3204
3520
|
cursor.done = true;
|
|
3205
|
-
cursor.start = function () {
|
|
3521
|
+
cursor.start = function () {
|
|
3522
|
+
throw new Error('Cursor behind last entry');
|
|
3523
|
+
};
|
|
3206
3524
|
cursor.stop();
|
|
3207
3525
|
}
|
|
3208
3526
|
};
|
|
@@ -3238,26 +3556,28 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3238
3556
|
var options = {
|
|
3239
3557
|
query: idbKeyRange,
|
|
3240
3558
|
count: nonInfinitLimit,
|
|
3241
|
-
direction: direction
|
|
3559
|
+
direction: direction,
|
|
3242
3560
|
};
|
|
3243
|
-
var req = values
|
|
3244
|
-
source.getAll(options)
|
|
3245
|
-
source.getAllKeys(options);
|
|
3561
|
+
var req = values
|
|
3562
|
+
? source.getAll(options)
|
|
3563
|
+
: source.getAllKeys(options);
|
|
3246
3564
|
req.onsuccess = function (event) { return resolve({ result: event.target.result }); };
|
|
3247
3565
|
req.onerror = eventRejectHandler(reject);
|
|
3248
3566
|
}
|
|
3249
3567
|
else if (hasGetAll && direction === 'next') {
|
|
3250
|
-
var req = values
|
|
3251
|
-
source.getAll(idbKeyRange, nonInfinitLimit)
|
|
3252
|
-
source.getAllKeys(idbKeyRange, nonInfinitLimit);
|
|
3253
|
-
req.onsuccess = function (event) {
|
|
3568
|
+
var req = values
|
|
3569
|
+
? source.getAll(idbKeyRange, nonInfinitLimit)
|
|
3570
|
+
: source.getAllKeys(idbKeyRange, nonInfinitLimit);
|
|
3571
|
+
req.onsuccess = function (event) {
|
|
3572
|
+
return resolve({ result: event.target.result });
|
|
3573
|
+
};
|
|
3254
3574
|
req.onerror = eventRejectHandler(reject);
|
|
3255
3575
|
}
|
|
3256
3576
|
else {
|
|
3257
3577
|
var count_1 = 0;
|
|
3258
|
-
var req_1 = values || !('openKeyCursor' in source)
|
|
3259
|
-
source.openCursor(idbKeyRange, direction)
|
|
3260
|
-
source.openKeyCursor(idbKeyRange, direction);
|
|
3578
|
+
var req_1 = values || !('openKeyCursor' in source)
|
|
3579
|
+
? source.openCursor(idbKeyRange, direction)
|
|
3580
|
+
: source.openKeyCursor(idbKeyRange, direction);
|
|
3261
3581
|
var result_1 = [];
|
|
3262
3582
|
req_1.onsuccess = function () {
|
|
3263
3583
|
var cursor = req_1.result;
|
|
@@ -3329,18 +3649,22 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3329
3649
|
var source = index.isPrimaryKey ? store : store.index(index.name);
|
|
3330
3650
|
var idbKeyRange = makeIDBKeyRange(range);
|
|
3331
3651
|
var req = idbKeyRange ? source.count(idbKeyRange) : source.count();
|
|
3332
|
-
req.onsuccess = wrap(function (ev) {
|
|
3652
|
+
req.onsuccess = wrap(function (ev) {
|
|
3653
|
+
return resolve(ev.target.result);
|
|
3654
|
+
});
|
|
3333
3655
|
req.onerror = eventRejectHandler(reject);
|
|
3334
3656
|
});
|
|
3335
|
-
}
|
|
3657
|
+
},
|
|
3336
3658
|
};
|
|
3337
3659
|
}
|
|
3338
3660
|
var _a = extractSchema(db, tmpTrans), schema = _a.schema, hasGetAll = _a.hasGetAll, hasIdb3Features = _a.hasIdb3Features;
|
|
3339
|
-
var tables = schema.tables.map(function (tableSchema) {
|
|
3661
|
+
var tables = schema.tables.map(function (tableSchema) {
|
|
3662
|
+
return createDbCoreTable(tableSchema);
|
|
3663
|
+
});
|
|
3340
3664
|
var tableMap = {};
|
|
3341
|
-
tables.forEach(function (table) { return tableMap[table.name] = table; });
|
|
3665
|
+
tables.forEach(function (table) { return (tableMap[table.name] = table); });
|
|
3342
3666
|
return {
|
|
3343
|
-
stack:
|
|
3667
|
+
stack: 'dbcore',
|
|
3344
3668
|
transaction: db.transaction.bind(db),
|
|
3345
3669
|
table: function (name) {
|
|
3346
3670
|
var result = tableMap[name];
|
|
@@ -3350,7 +3674,7 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
|
|
|
3350
3674
|
},
|
|
3351
3675
|
MIN_KEY: -Infinity,
|
|
3352
3676
|
MAX_KEY: getMaxKey(IdbKeyRange),
|
|
3353
|
-
schema: schema
|
|
3677
|
+
schema: schema,
|
|
3354
3678
|
};
|
|
3355
3679
|
}
|
|
3356
3680
|
|
|
@@ -3364,7 +3688,7 @@ function createMiddlewareStacks(middlewares, idbdb, _a, tmpTrans) {
|
|
|
3364
3688
|
var IDBKeyRange = _a.IDBKeyRange; _a.indexedDB;
|
|
3365
3689
|
var dbcore = createMiddlewareStack(createDBCore(idbdb, IDBKeyRange, tmpTrans), middlewares.dbcore);
|
|
3366
3690
|
return {
|
|
3367
|
-
dbcore: dbcore
|
|
3691
|
+
dbcore: dbcore,
|
|
3368
3692
|
};
|
|
3369
3693
|
}
|
|
3370
3694
|
function generateMiddlewareStacks(db, tmpTrans) {
|
|
@@ -3387,13 +3711,20 @@ function setApiOnPlace(db, objs, tableNames, dbschema) {
|
|
|
3387
3711
|
var schema = dbschema[tableName];
|
|
3388
3712
|
objs.forEach(function (obj) {
|
|
3389
3713
|
var propDesc = getPropertyDescriptor(obj, tableName);
|
|
3390
|
-
if (!propDesc || (
|
|
3714
|
+
if (!propDesc || ('value' in propDesc && propDesc.value === undefined)) {
|
|
3391
3715
|
if (obj === db.Transaction.prototype || obj instanceof db.Transaction) {
|
|
3392
3716
|
setProp(obj, tableName, {
|
|
3393
|
-
get: function () {
|
|
3717
|
+
get: function () {
|
|
3718
|
+
return this.table(tableName);
|
|
3719
|
+
},
|
|
3394
3720
|
set: function (value) {
|
|
3395
|
-
defineProperty(this, tableName, {
|
|
3396
|
-
|
|
3721
|
+
defineProperty(this, tableName, {
|
|
3722
|
+
value: value,
|
|
3723
|
+
writable: true,
|
|
3724
|
+
configurable: true,
|
|
3725
|
+
enumerable: true,
|
|
3726
|
+
});
|
|
3727
|
+
},
|
|
3397
3728
|
});
|
|
3398
3729
|
}
|
|
3399
3730
|
else {
|
|
@@ -3416,8 +3747,9 @@ function lowerVersionFirst(a, b) {
|
|
|
3416
3747
|
}
|
|
3417
3748
|
function runUpgraders(db, oldVersion, idbUpgradeTrans, reject) {
|
|
3418
3749
|
var globalSchema = db._dbSchema;
|
|
3419
|
-
if (idbUpgradeTrans.objectStoreNames.contains('$meta') &&
|
|
3420
|
-
globalSchema.$meta
|
|
3750
|
+
if (idbUpgradeTrans.objectStoreNames.contains('$meta') &&
|
|
3751
|
+
!globalSchema.$meta) {
|
|
3752
|
+
globalSchema.$meta = createTableSchema('$meta', parseIndexSyntax('')[0], []);
|
|
3421
3753
|
db._storeNames.push('$meta');
|
|
3422
3754
|
}
|
|
3423
3755
|
var trans = db._createTransaction('readwrite', db._storeNames, globalSchema);
|
|
@@ -3438,15 +3770,20 @@ function runUpgraders(db, oldVersion, idbUpgradeTrans, reject) {
|
|
|
3438
3770
|
else {
|
|
3439
3771
|
generateMiddlewareStacks(db, idbUpgradeTrans);
|
|
3440
3772
|
return getExistingVersion(db, trans, oldVersion)
|
|
3441
|
-
.then(function (oldVersion) {
|
|
3773
|
+
.then(function (oldVersion) {
|
|
3774
|
+
return updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans);
|
|
3775
|
+
})
|
|
3442
3776
|
.catch(rejectTransaction);
|
|
3443
3777
|
}
|
|
3444
3778
|
});
|
|
3445
3779
|
}
|
|
3446
3780
|
function patchCurrentVersion(db, idbUpgradeTrans) {
|
|
3447
3781
|
createMissingTables(db._dbSchema, idbUpgradeTrans);
|
|
3448
|
-
if (idbUpgradeTrans.db.version % 10 === 0 &&
|
|
3449
|
-
idbUpgradeTrans.
|
|
3782
|
+
if (idbUpgradeTrans.db.version % 10 === 0 &&
|
|
3783
|
+
!idbUpgradeTrans.objectStoreNames.contains('$meta')) {
|
|
3784
|
+
idbUpgradeTrans.db
|
|
3785
|
+
.createObjectStore('$meta')
|
|
3786
|
+
.add(Math.ceil(idbUpgradeTrans.db.version / 10 - 1), 'version');
|
|
3450
3787
|
}
|
|
3451
3788
|
var globalSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
|
|
3452
3789
|
adjustToExistingIndexNames(db, db._dbSchema, idbUpgradeTrans);
|
|
@@ -3472,7 +3809,10 @@ function patchCurrentVersion(db, idbUpgradeTrans) {
|
|
|
3472
3809
|
}
|
|
3473
3810
|
function getExistingVersion(db, trans, oldVersion) {
|
|
3474
3811
|
if (trans.storeNames.includes('$meta')) {
|
|
3475
|
-
return trans
|
|
3812
|
+
return trans
|
|
3813
|
+
.table('$meta')
|
|
3814
|
+
.get('version')
|
|
3815
|
+
.then(function (metaVersion) {
|
|
3476
3816
|
return metaVersion != null ? metaVersion : oldVersion;
|
|
3477
3817
|
});
|
|
3478
3818
|
}
|
|
@@ -3483,7 +3823,7 @@ function getExistingVersion(db, trans, oldVersion) {
|
|
|
3483
3823
|
function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
|
|
3484
3824
|
var queue = [];
|
|
3485
3825
|
var versions = db._versions;
|
|
3486
|
-
var globalSchema = db._dbSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
|
|
3826
|
+
var globalSchema = (db._dbSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans));
|
|
3487
3827
|
var versToRun = versions.filter(function (v) { return v._cfg.version >= oldVersion; });
|
|
3488
3828
|
if (versToRun.length === 0) {
|
|
3489
3829
|
return DexiePromise.resolve();
|
|
@@ -3501,7 +3841,7 @@ function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
|
|
|
3501
3841
|
});
|
|
3502
3842
|
diff.change.forEach(function (change) {
|
|
3503
3843
|
if (change.recreate) {
|
|
3504
|
-
throw new exceptions.Upgrade(
|
|
3844
|
+
throw new exceptions.Upgrade('Not yet support for changing primary key');
|
|
3505
3845
|
}
|
|
3506
3846
|
else {
|
|
3507
3847
|
var store_1 = idbUpgradeTrans.objectStore(change.name);
|
|
@@ -3538,8 +3878,9 @@ function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
|
|
|
3538
3878
|
}
|
|
3539
3879
|
}
|
|
3540
3880
|
});
|
|
3541
|
-
return
|
|
3542
|
-
DexiePromise.resolve(returnValue_1)
|
|
3881
|
+
return returnValue_1 && typeof returnValue_1.then === 'function'
|
|
3882
|
+
? DexiePromise.resolve(returnValue_1)
|
|
3883
|
+
: promiseFollowed.then(function () { return returnValue_1; });
|
|
3543
3884
|
}
|
|
3544
3885
|
});
|
|
3545
3886
|
queue.push(function (idbtrans) {
|
|
@@ -3563,8 +3904,9 @@ function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
|
|
|
3563
3904
|
});
|
|
3564
3905
|
});
|
|
3565
3906
|
function runQueue() {
|
|
3566
|
-
return queue.length
|
|
3567
|
-
DexiePromise.resolve()
|
|
3907
|
+
return queue.length
|
|
3908
|
+
? DexiePromise.resolve(queue.shift()(trans.idbtrans)).then(runQueue)
|
|
3909
|
+
: DexiePromise.resolve();
|
|
3568
3910
|
}
|
|
3569
3911
|
return runQueue().then(function () {
|
|
3570
3912
|
createMissingTables(globalSchema, idbUpgradeTrans);
|
|
@@ -3574,7 +3916,7 @@ function getSchemaDiff(oldSchema, newSchema) {
|
|
|
3574
3916
|
var diff = {
|
|
3575
3917
|
del: [],
|
|
3576
3918
|
add: [],
|
|
3577
|
-
change: []
|
|
3919
|
+
change: [],
|
|
3578
3920
|
};
|
|
3579
3921
|
var table;
|
|
3580
3922
|
for (table in oldSchema) {
|
|
@@ -3593,11 +3935,12 @@ function getSchemaDiff(oldSchema, newSchema) {
|
|
|
3593
3935
|
recreate: false,
|
|
3594
3936
|
del: [],
|
|
3595
3937
|
add: [],
|
|
3596
|
-
change: []
|
|
3938
|
+
change: [],
|
|
3597
3939
|
};
|
|
3598
|
-
if (
|
|
3599
|
-
'' + (oldDef.primKey.keyPath || '')
|
|
3600
|
-
(
|
|
3940
|
+
if (
|
|
3941
|
+
'' + (oldDef.primKey.keyPath || '') !==
|
|
3942
|
+
'' + (newDef.primKey.keyPath || '') ||
|
|
3943
|
+
oldDef.primKey.auto !== newDef.primKey.auto) {
|
|
3601
3944
|
change.recreate = true;
|
|
3602
3945
|
diff.change.push(change);
|
|
3603
3946
|
}
|
|
@@ -3616,7 +3959,9 @@ function getSchemaDiff(oldSchema, newSchema) {
|
|
|
3616
3959
|
else if (oldIdx.src !== newIdx.src)
|
|
3617
3960
|
change.change.push(newIdx);
|
|
3618
3961
|
}
|
|
3619
|
-
if (change.del.length > 0 ||
|
|
3962
|
+
if (change.del.length > 0 ||
|
|
3963
|
+
change.add.length > 0 ||
|
|
3964
|
+
change.change.length > 0) {
|
|
3620
3965
|
diff.change.push(change);
|
|
3621
3966
|
}
|
|
3622
3967
|
}
|
|
@@ -3625,9 +3970,9 @@ function getSchemaDiff(oldSchema, newSchema) {
|
|
|
3625
3970
|
return diff;
|
|
3626
3971
|
}
|
|
3627
3972
|
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 });
|
|
3973
|
+
var store = idbtrans.db.createObjectStore(tableName, primKey.keyPath
|
|
3974
|
+
? { keyPath: primKey.keyPath, autoIncrement: primKey.auto }
|
|
3975
|
+
: { autoIncrement: primKey.auto });
|
|
3631
3976
|
indexes.forEach(function (idx) { return addIndex(store, idx); });
|
|
3632
3977
|
return store;
|
|
3633
3978
|
}
|
|
@@ -3641,12 +3986,17 @@ function createMissingTables(newSchema, idbtrans) {
|
|
|
3641
3986
|
});
|
|
3642
3987
|
}
|
|
3643
3988
|
function deleteRemovedTables(newSchema, idbtrans) {
|
|
3644
|
-
[].slice
|
|
3989
|
+
[].slice
|
|
3990
|
+
.call(idbtrans.db.objectStoreNames)
|
|
3991
|
+
.forEach(function (storeName) {
|
|
3645
3992
|
return newSchema[storeName] == null && idbtrans.db.deleteObjectStore(storeName);
|
|
3646
3993
|
});
|
|
3647
3994
|
}
|
|
3648
3995
|
function addIndex(store, idx) {
|
|
3649
|
-
store.createIndex(idx.name, idx.keyPath, {
|
|
3996
|
+
store.createIndex(idx.name, idx.keyPath, {
|
|
3997
|
+
unique: idx.unique,
|
|
3998
|
+
multiEntry: idx.multi,
|
|
3999
|
+
});
|
|
3650
4000
|
}
|
|
3651
4001
|
function buildGlobalSchema(db, idbdb, tmpTrans) {
|
|
3652
4002
|
var globalSchema = {};
|
|
@@ -3654,12 +4004,12 @@ function buildGlobalSchema(db, idbdb, tmpTrans) {
|
|
|
3654
4004
|
dbStoreNames.forEach(function (storeName) {
|
|
3655
4005
|
var store = tmpTrans.objectStore(storeName);
|
|
3656
4006
|
var keyPath = store.keyPath;
|
|
3657
|
-
var primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath ||
|
|
4007
|
+
var primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath || '', true, false, !!store.autoIncrement, keyPath && typeof keyPath !== 'string', true);
|
|
3658
4008
|
var indexes = [];
|
|
3659
4009
|
for (var j = 0; j < store.indexNames.length; ++j) {
|
|
3660
4010
|
var idbindex = store.index(store.indexNames[j]);
|
|
3661
4011
|
keyPath = idbindex.keyPath;
|
|
3662
|
-
var index = createIndexSpec(idbindex.name, keyPath, !!idbindex.unique, !!idbindex.multiEntry, false, keyPath && typeof keyPath !==
|
|
4012
|
+
var index = createIndexSpec(idbindex.name, keyPath, !!idbindex.unique, !!idbindex.multiEntry, false, keyPath && typeof keyPath !== 'string', false);
|
|
3663
4013
|
indexes.push(index);
|
|
3664
4014
|
}
|
|
3665
4015
|
globalSchema[storeName] = createTableSchema(storeName, primKey, indexes);
|
|
@@ -3668,14 +4018,15 @@ function buildGlobalSchema(db, idbdb, tmpTrans) {
|
|
|
3668
4018
|
}
|
|
3669
4019
|
function readGlobalSchema(db, idbdb, tmpTrans) {
|
|
3670
4020
|
db.verno = idbdb.version / 10;
|
|
3671
|
-
var globalSchema = db._dbSchema = buildGlobalSchema(db, idbdb, tmpTrans);
|
|
4021
|
+
var globalSchema = (db._dbSchema = buildGlobalSchema(db, idbdb, tmpTrans));
|
|
3672
4022
|
db._storeNames = slice(idbdb.objectStoreNames, 0);
|
|
3673
4023
|
setApiOnPlace(db, [db._allTables], keys(globalSchema), globalSchema);
|
|
3674
4024
|
}
|
|
3675
4025
|
function verifyInstalledSchema(db, tmpTrans) {
|
|
3676
4026
|
var installedSchema = buildGlobalSchema(db, db.idbdb, tmpTrans);
|
|
3677
4027
|
var diff = getSchemaDiff(installedSchema, db._dbSchema);
|
|
3678
|
-
return !(diff.add.length ||
|
|
4028
|
+
return !(diff.add.length ||
|
|
4029
|
+
diff.change.some(function (ch) { return ch.add.length || ch.change.length; }));
|
|
3679
4030
|
}
|
|
3680
4031
|
function adjustToExistingIndexNames(db, schema, idbtrans) {
|
|
3681
4032
|
var storeNames = idbtrans.db.objectStoreNames;
|
|
@@ -3686,7 +4037,9 @@ function adjustToExistingIndexNames(db, schema, idbtrans) {
|
|
|
3686
4037
|
for (var j = 0; j < store.indexNames.length; ++j) {
|
|
3687
4038
|
var indexName = store.indexNames[j];
|
|
3688
4039
|
var keyPath = store.index(indexName).keyPath;
|
|
3689
|
-
var dexieName = typeof keyPath === 'string'
|
|
4040
|
+
var dexieName = typeof keyPath === 'string'
|
|
4041
|
+
? keyPath
|
|
4042
|
+
: '[' + slice(keyPath).join('+') + ']';
|
|
3690
4043
|
if (schema[storeName]) {
|
|
3691
4044
|
var indexSpec = schema[storeName].idxByName[dexieName];
|
|
3692
4045
|
if (indexSpec) {
|
|
@@ -3697,9 +4050,11 @@ function adjustToExistingIndexNames(db, schema, idbtrans) {
|
|
|
3697
4050
|
}
|
|
3698
4051
|
}
|
|
3699
4052
|
}
|
|
3700
|
-
if (typeof navigator !== 'undefined' &&
|
|
4053
|
+
if (typeof navigator !== 'undefined' &&
|
|
4054
|
+
/Safari/.test(navigator.userAgent) &&
|
|
3701
4055
|
!/(Chrome\/|Edge\/)/.test(navigator.userAgent) &&
|
|
3702
|
-
_global.WorkerGlobalScope &&
|
|
4056
|
+
_global.WorkerGlobalScope &&
|
|
4057
|
+
_global instanceof _global.WorkerGlobalScope &&
|
|
3703
4058
|
[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604) {
|
|
3704
4059
|
db._hasGetAll = false;
|
|
3705
4060
|
}
|
|
@@ -3710,8 +4065,10 @@ function parseIndexSyntax(primKeyAndIndexes) {
|
|
|
3710
4065
|
var typeSplit = index.split(':');
|
|
3711
4066
|
var type = (_a = typeSplit[1]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
3712
4067
|
index = typeSplit[0].trim();
|
|
3713
|
-
var name = index.replace(/([&*]|\+\+)/g,
|
|
3714
|
-
var keyPath = /^\[/.test(name)
|
|
4068
|
+
var name = index.replace(/([&*]|\+\+)/g, '');
|
|
4069
|
+
var keyPath = /^\[/.test(name)
|
|
4070
|
+
? name.match(/^\[(.*)\]$/)[1].split('+')
|
|
4071
|
+
: name;
|
|
3715
4072
|
return createIndexSpec(name, keyPath || null, /\&/.test(index), /\*/.test(index), /\+\+/.test(index), isArray(keyPath), indexNum === 0, type);
|
|
3716
4073
|
});
|
|
3717
4074
|
}
|
|
@@ -3782,14 +4139,15 @@ function createVersionConstructor(db) {
|
|
|
3782
4139
|
storesSource: null,
|
|
3783
4140
|
dbschema: {},
|
|
3784
4141
|
tables: {},
|
|
3785
|
-
contentUpgrade: null
|
|
4142
|
+
contentUpgrade: null,
|
|
3786
4143
|
};
|
|
3787
4144
|
});
|
|
3788
4145
|
}
|
|
3789
4146
|
|
|
3790
4147
|
var connections = createConnectionsManager();
|
|
3791
4148
|
function createConnectionsManager() {
|
|
3792
|
-
if (typeof FinalizationRegistry !== 'undefined' &&
|
|
4149
|
+
if (typeof FinalizationRegistry !== 'undefined' &&
|
|
4150
|
+
typeof WeakRef !== 'undefined') {
|
|
3793
4151
|
var _refs_1 = new Set();
|
|
3794
4152
|
var _registry_1 = new FinalizationRegistry(function (ref) {
|
|
3795
4153
|
_refs_1.delete(ref);
|
|
@@ -3845,19 +4203,19 @@ function createConnectionsManager() {
|
|
|
3845
4203
|
}
|
|
3846
4204
|
|
|
3847
4205
|
function getDbNamesTable(indexedDB, IDBKeyRange) {
|
|
3848
|
-
var dbNamesDB = indexedDB[
|
|
4206
|
+
var dbNamesDB = indexedDB['_dbNamesDB'];
|
|
3849
4207
|
if (!dbNamesDB) {
|
|
3850
|
-
dbNamesDB = indexedDB[
|
|
4208
|
+
dbNamesDB = indexedDB['_dbNamesDB'] = new Dexie$1(DBNAMES_DB, {
|
|
3851
4209
|
addons: [],
|
|
3852
4210
|
indexedDB: indexedDB,
|
|
3853
4211
|
IDBKeyRange: IDBKeyRange,
|
|
3854
4212
|
});
|
|
3855
|
-
dbNamesDB.version(1).stores({ dbnames:
|
|
4213
|
+
dbNamesDB.version(1).stores({ dbnames: 'name' });
|
|
3856
4214
|
}
|
|
3857
|
-
return dbNamesDB.table(
|
|
4215
|
+
return dbNamesDB.table('dbnames');
|
|
3858
4216
|
}
|
|
3859
4217
|
function hasDatabasesNative(indexedDB) {
|
|
3860
|
-
return indexedDB && typeof indexedDB.databases ===
|
|
4218
|
+
return indexedDB && typeof indexedDB.databases === 'function';
|
|
3861
4219
|
}
|
|
3862
4220
|
function getDatabaseNames(_a) {
|
|
3863
4221
|
var indexedDB = _a.indexedDB, IDBKeyRange = _a.IDBKeyRange;
|
|
@@ -3905,15 +4263,17 @@ function idbReady() {
|
|
|
3905
4263
|
|
|
3906
4264
|
var _a;
|
|
3907
4265
|
function isEmptyRange(node) {
|
|
3908
|
-
return !(
|
|
4266
|
+
return !('from' in node);
|
|
3909
4267
|
}
|
|
3910
4268
|
var RangeSet = function (fromOrTree, to) {
|
|
3911
4269
|
if (this) {
|
|
3912
|
-
extend(this, arguments.length
|
|
4270
|
+
extend(this, arguments.length
|
|
4271
|
+
? { d: 1, from: fromOrTree, to: arguments.length > 1 ? to : fromOrTree }
|
|
4272
|
+
: { d: 0 });
|
|
3913
4273
|
}
|
|
3914
4274
|
else {
|
|
3915
4275
|
var rv = new RangeSet();
|
|
3916
|
-
if (fromOrTree &&
|
|
4276
|
+
if (fromOrTree && 'd' in fromOrTree) {
|
|
3917
4277
|
extend(rv, fromOrTree);
|
|
3918
4278
|
}
|
|
3919
4279
|
return rv;
|
|
@@ -4013,7 +4373,9 @@ function rangesOverlap(rangeSet1, rangeSet2) {
|
|
|
4013
4373
|
return false;
|
|
4014
4374
|
}
|
|
4015
4375
|
function getRangeSetIterator(node) {
|
|
4016
|
-
var state = isEmptyRange(node)
|
|
4376
|
+
var state = isEmptyRange(node)
|
|
4377
|
+
? null
|
|
4378
|
+
: { s: 0, n: node };
|
|
4017
4379
|
return {
|
|
4018
4380
|
next: function (key) {
|
|
4019
4381
|
var keyProvided = arguments.length > 0;
|
|
@@ -4050,9 +4412,9 @@ function getRangeSetIterator(node) {
|
|
|
4050
4412
|
function rebalance(target) {
|
|
4051
4413
|
var _a, _b;
|
|
4052
4414
|
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 ?
|
|
4415
|
+
var r = diff > 1 ? 'r' : diff < -1 ? 'l' : '';
|
|
4054
4416
|
if (r) {
|
|
4055
|
-
var l = r ===
|
|
4417
|
+
var l = r === 'r' ? 'l' : 'r';
|
|
4056
4418
|
var rootClone = __assign({}, target);
|
|
4057
4419
|
var oldRootRight = target[r];
|
|
4058
4420
|
target.from = oldRootRight.from;
|
|
@@ -4080,7 +4442,9 @@ function extendObservabilitySet(target, newSet) {
|
|
|
4080
4442
|
}
|
|
4081
4443
|
|
|
4082
4444
|
function obsSetsOverlap(os1, os2) {
|
|
4083
|
-
return os1.all ||
|
|
4445
|
+
return (os1.all ||
|
|
4446
|
+
os2.all ||
|
|
4447
|
+
Object.keys(os1).some(function (key) { return os2[key] && rangesOverlap(os2[key], os1[key]); }));
|
|
4084
4448
|
}
|
|
4085
4449
|
|
|
4086
4450
|
var cache = {};
|
|
@@ -4150,9 +4514,9 @@ function dexieOpen(db) {
|
|
|
4150
4514
|
var state = db._state;
|
|
4151
4515
|
var indexedDB = db._deps.indexedDB;
|
|
4152
4516
|
if (state.isBeingOpened || db.idbdb)
|
|
4153
|
-
return state.dbReadyPromise.then(function () {
|
|
4154
|
-
rejection(state.dbOpenError) :
|
|
4155
|
-
|
|
4517
|
+
return state.dbReadyPromise.then(function () {
|
|
4518
|
+
return state.dbOpenError ? rejection(state.dbOpenError) : db;
|
|
4519
|
+
});
|
|
4156
4520
|
state.isBeingOpened = true;
|
|
4157
4521
|
state.dbOpenError = null;
|
|
4158
4522
|
state.openComplete = false;
|
|
@@ -4165,97 +4529,102 @@ function dexieOpen(db) {
|
|
|
4165
4529
|
}
|
|
4166
4530
|
var resolveDbReady = state.dbReadyResolve,
|
|
4167
4531
|
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);
|
|
4532
|
+
var tryOpenDB = function () {
|
|
4533
|
+
return new DexiePromise(function (resolve, reject) {
|
|
4534
|
+
throwIfCancelled();
|
|
4535
|
+
if (!indexedDB)
|
|
4536
|
+
throw new exceptions.MissingAPI();
|
|
4537
|
+
var dbName = db.name;
|
|
4538
|
+
var req = state.autoSchema || !nativeVerToOpen
|
|
4539
|
+
? indexedDB.open(dbName)
|
|
4540
|
+
: indexedDB.open(dbName, nativeVerToOpen);
|
|
4541
|
+
if (!req)
|
|
4542
|
+
throw new exceptions.MissingAPI();
|
|
4543
|
+
req.onerror = eventRejectHandler(reject);
|
|
4544
|
+
req.onblocked = wrap(db._fireOnBlocked);
|
|
4545
|
+
req.onupgradeneeded = wrap(function (e) {
|
|
4546
|
+
upgradeTransaction = req.transaction;
|
|
4547
|
+
if (state.autoSchema && !db._options.allowEmptyDB) {
|
|
4548
|
+
req.onerror = preventDefault;
|
|
4549
|
+
upgradeTransaction.abort();
|
|
4550
|
+
req.result.close();
|
|
4551
|
+
var delreq = indexedDB.deleteDatabase(dbName);
|
|
4552
|
+
delreq.onsuccess = delreq.onerror = wrap(function () {
|
|
4553
|
+
reject(new exceptions.NoSuchDatabase("Database ".concat(dbName, " doesnt exist")));
|
|
4554
|
+
});
|
|
4198
4555
|
}
|
|
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
|
-
}
|
|
4556
|
+
else {
|
|
4557
|
+
upgradeTransaction.onerror = eventRejectHandler(reject);
|
|
4558
|
+
var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion;
|
|
4559
|
+
wasCreated = oldVer < 1;
|
|
4560
|
+
db.idbdb = req.result;
|
|
4561
|
+
if (schemaPatchMode) {
|
|
4562
|
+
patchCurrentVersion(db, upgradeTransaction);
|
|
4220
4563
|
}
|
|
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();
|
|
4564
|
+
runUpgraders(db, oldVer / 10, upgradeTransaction, reject);
|
|
4250
4565
|
}
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4566
|
+
}, reject);
|
|
4567
|
+
req.onsuccess = wrap(function () {
|
|
4568
|
+
upgradeTransaction = null;
|
|
4569
|
+
var idbdb = (db.idbdb = req.result);
|
|
4570
|
+
var objectStoreNames = slice(idbdb.objectStoreNames);
|
|
4571
|
+
if (objectStoreNames.length > 0)
|
|
4572
|
+
try {
|
|
4573
|
+
var tmpTrans = idbdb.transaction(safariMultiStoreFix(objectStoreNames), 'readonly');
|
|
4574
|
+
if (state.autoSchema)
|
|
4575
|
+
readGlobalSchema(db, idbdb, tmpTrans);
|
|
4576
|
+
else {
|
|
4577
|
+
adjustToExistingIndexNames(db, db._dbSchema, tmpTrans);
|
|
4578
|
+
if (!verifyInstalledSchema(db, tmpTrans) && !schemaPatchMode) {
|
|
4579
|
+
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.");
|
|
4580
|
+
idbdb.close();
|
|
4581
|
+
nativeVerToOpen = idbdb.version + 1;
|
|
4582
|
+
schemaPatchMode = true;
|
|
4583
|
+
return resolve(tryOpenDB());
|
|
4584
|
+
}
|
|
4585
|
+
}
|
|
4586
|
+
generateMiddlewareStacks(db, tmpTrans);
|
|
4587
|
+
}
|
|
4588
|
+
catch (e) {
|
|
4589
|
+
}
|
|
4590
|
+
connections.add(db);
|
|
4591
|
+
idbdb.onversionchange = wrap(function (ev) {
|
|
4592
|
+
state.vcFired = true;
|
|
4593
|
+
db.on('versionchange').fire(ev);
|
|
4594
|
+
});
|
|
4595
|
+
idbdb.onclose = wrap(function () {
|
|
4596
|
+
db.close({ disableAutoOpen: false });
|
|
4597
|
+
});
|
|
4598
|
+
if (wasCreated)
|
|
4599
|
+
_onDatabaseCreated(db._deps, dbName);
|
|
4600
|
+
resolve();
|
|
4601
|
+
}, reject);
|
|
4602
|
+
}).catch(function (err) {
|
|
4603
|
+
switch (err === null || err === void 0 ? void 0 : err.name) {
|
|
4604
|
+
case 'UnknownError':
|
|
4605
|
+
if (state.PR1398_maxLoop > 0) {
|
|
4606
|
+
state.PR1398_maxLoop--;
|
|
4607
|
+
console.warn('Dexie: Workaround for Chrome UnknownError on open()');
|
|
4608
|
+
return tryOpenDB();
|
|
4609
|
+
}
|
|
4610
|
+
break;
|
|
4611
|
+
case 'VersionError':
|
|
4612
|
+
if (nativeVerToOpen > 0) {
|
|
4613
|
+
nativeVerToOpen = 0;
|
|
4614
|
+
return tryOpenDB();
|
|
4615
|
+
}
|
|
4616
|
+
break;
|
|
4617
|
+
}
|
|
4618
|
+
return DexiePromise.reject(err);
|
|
4619
|
+
});
|
|
4620
|
+
};
|
|
4255
4621
|
return DexiePromise.race([
|
|
4256
4622
|
openCanceller,
|
|
4257
|
-
(typeof navigator === 'undefined'
|
|
4258
|
-
|
|
4623
|
+
(typeof navigator === 'undefined'
|
|
4624
|
+
? DexiePromise.resolve()
|
|
4625
|
+
: idbReady()).then(tryOpenDB),
|
|
4626
|
+
])
|
|
4627
|
+
.then(function () {
|
|
4259
4628
|
throwIfCancelled();
|
|
4260
4629
|
state.onReadyBeingFired = [];
|
|
4261
4630
|
return DexiePromise.resolve(vip(function () { return db.on.ready.fire(db.vip); })).then(function fireRemainders() {
|
|
@@ -4265,12 +4634,14 @@ function dexieOpen(db) {
|
|
|
4265
4634
|
return DexiePromise.resolve(vip(function () { return remainders_1(db.vip); })).then(fireRemainders);
|
|
4266
4635
|
}
|
|
4267
4636
|
});
|
|
4268
|
-
})
|
|
4637
|
+
})
|
|
4638
|
+
.finally(function () {
|
|
4269
4639
|
if (state.openCanceller === openCanceller) {
|
|
4270
4640
|
state.onReadyBeingFired = null;
|
|
4271
4641
|
state.isBeingOpened = false;
|
|
4272
4642
|
}
|
|
4273
|
-
})
|
|
4643
|
+
})
|
|
4644
|
+
.catch(function (err) {
|
|
4274
4645
|
state.dbOpenError = err;
|
|
4275
4646
|
try {
|
|
4276
4647
|
upgradeTransaction && upgradeTransaction.abort();
|
|
@@ -4280,16 +4651,19 @@ function dexieOpen(db) {
|
|
|
4280
4651
|
db._close();
|
|
4281
4652
|
}
|
|
4282
4653
|
return rejection(err);
|
|
4283
|
-
})
|
|
4654
|
+
})
|
|
4655
|
+
.finally(function () {
|
|
4284
4656
|
state.openComplete = true;
|
|
4285
4657
|
resolveDbReady();
|
|
4286
|
-
})
|
|
4658
|
+
})
|
|
4659
|
+
.then(function () {
|
|
4287
4660
|
if (wasCreated) {
|
|
4288
4661
|
var everything_1 = {};
|
|
4289
4662
|
db.tables.forEach(function (table) {
|
|
4290
4663
|
table.schema.indexes.forEach(function (idx) {
|
|
4291
4664
|
if (idx.name)
|
|
4292
|
-
everything_1["idb://".concat(db.name, "/").concat(table.name, "/").concat(idx.name)] =
|
|
4665
|
+
everything_1["idb://".concat(db.name, "/").concat(table.name, "/").concat(idx.name)] =
|
|
4666
|
+
new RangeSet(-Infinity, [[[]]]);
|
|
4293
4667
|
});
|
|
4294
4668
|
everything_1["idb://".concat(db.name, "/").concat(table.name, "/")] = everything_1["idb://".concat(db.name, "/").concat(table.name, "/:dels")] = new RangeSet(-Infinity, [[[]]]);
|
|
4295
4669
|
});
|
|
@@ -4305,10 +4679,13 @@ function awaitIterator(iterator) {
|
|
|
4305
4679
|
function step(getNext) {
|
|
4306
4680
|
return function (val) {
|
|
4307
4681
|
var next = getNext(val), value = next.value;
|
|
4308
|
-
return next.done
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
value
|
|
4682
|
+
return next.done
|
|
4683
|
+
? value
|
|
4684
|
+
: !value || typeof value.then !== 'function'
|
|
4685
|
+
? isArray(value)
|
|
4686
|
+
? Promise.all(value).then(onSuccess, onError)
|
|
4687
|
+
: onSuccess(value)
|
|
4688
|
+
: value.then(onSuccess, onError);
|
|
4312
4689
|
};
|
|
4313
4690
|
}
|
|
4314
4691
|
return step(callNext)();
|
|
@@ -4317,7 +4694,7 @@ function awaitIterator(iterator) {
|
|
|
4317
4694
|
function extractTransactionArgs(mode, _tableArgs_, scopeFunc) {
|
|
4318
4695
|
var i = arguments.length;
|
|
4319
4696
|
if (i < 2)
|
|
4320
|
-
throw new exceptions.InvalidArgument(
|
|
4697
|
+
throw new exceptions.InvalidArgument('Too few arguments');
|
|
4321
4698
|
var args = new Array(i - 1);
|
|
4322
4699
|
while (--i)
|
|
4323
4700
|
args[i - 1] = arguments[i];
|
|
@@ -4332,7 +4709,7 @@ function enterTransactionScope(db, mode, storeNames, parentTransaction, scopeFun
|
|
|
4332
4709
|
trans.explicit = true;
|
|
4333
4710
|
var zoneProps = {
|
|
4334
4711
|
trans: trans,
|
|
4335
|
-
transless: transless
|
|
4712
|
+
transless: transless,
|
|
4336
4713
|
};
|
|
4337
4714
|
if (parentTransaction) {
|
|
4338
4715
|
trans.idbtrans = parentTransaction.idbtrans;
|
|
@@ -4344,10 +4721,16 @@ function enterTransactionScope(db, mode, storeNames, parentTransaction, scopeFun
|
|
|
4344
4721
|
db._state.PR1398_maxLoop = 3;
|
|
4345
4722
|
}
|
|
4346
4723
|
catch (ex) {
|
|
4347
|
-
if (ex.name === errnames.InvalidState &&
|
|
4724
|
+
if (ex.name === errnames.InvalidState &&
|
|
4725
|
+
db.isOpen() &&
|
|
4726
|
+
--db._state.PR1398_maxLoop > 0) {
|
|
4348
4727
|
console.warn('Dexie: Need to reopen db');
|
|
4349
4728
|
db.close({ disableAutoOpen: false });
|
|
4350
|
-
return db
|
|
4729
|
+
return db
|
|
4730
|
+
.open()
|
|
4731
|
+
.then(function () {
|
|
4732
|
+
return enterTransactionScope(db, mode, storeNames, null, scopeFunc);
|
|
4733
|
+
});
|
|
4351
4734
|
}
|
|
4352
4735
|
return rejection(ex);
|
|
4353
4736
|
}
|
|
@@ -4364,20 +4747,27 @@ function enterTransactionScope(db, mode, storeNames, parentTransaction, scopeFun
|
|
|
4364
4747
|
var decrementor = decrementExpectedAwaits.bind(null, null);
|
|
4365
4748
|
returnValue.then(decrementor, decrementor);
|
|
4366
4749
|
}
|
|
4367
|
-
else if (typeof returnValue.next === 'function' &&
|
|
4750
|
+
else if (typeof returnValue.next === 'function' &&
|
|
4751
|
+
typeof returnValue.throw === 'function') {
|
|
4368
4752
|
returnValue = awaitIterator(returnValue);
|
|
4369
4753
|
}
|
|
4370
4754
|
}
|
|
4371
4755
|
}, zoneProps);
|
|
4372
|
-
return (returnValue && typeof returnValue.then === 'function'
|
|
4373
|
-
|
|
4374
|
-
x
|
|
4375
|
-
|
|
4376
|
-
|
|
4756
|
+
return (returnValue && typeof returnValue.then === 'function'
|
|
4757
|
+
?
|
|
4758
|
+
DexiePromise.resolve(returnValue).then(function (x) {
|
|
4759
|
+
return trans.active
|
|
4760
|
+
? x
|
|
4761
|
+
: rejection(new exceptions.PrematureCommit('Transaction committed too early. See http://bit.ly/2kdckMn'));
|
|
4762
|
+
})
|
|
4763
|
+
:
|
|
4764
|
+
promiseFollowed.then(function () { return returnValue; }))
|
|
4765
|
+
.then(function (x) {
|
|
4377
4766
|
if (parentTransaction)
|
|
4378
4767
|
trans._resolve();
|
|
4379
4768
|
return trans._completion.then(function () { return x; });
|
|
4380
|
-
})
|
|
4769
|
+
})
|
|
4770
|
+
.catch(function (e) {
|
|
4381
4771
|
trans._reject(e);
|
|
4382
4772
|
return rejection(e);
|
|
4383
4773
|
});
|
|
@@ -4398,8 +4788,13 @@ function createVirtualIndexMiddleware(down) {
|
|
|
4398
4788
|
var allVirtualIndexes = [];
|
|
4399
4789
|
function addVirtualIndexes(keyPath, keyTail, lowLevelIndex) {
|
|
4400
4790
|
var keyPathAlias = getKeyPathAlias(keyPath);
|
|
4401
|
-
var indexList = (indexLookup[keyPathAlias] =
|
|
4402
|
-
|
|
4791
|
+
var indexList = (indexLookup[keyPathAlias] =
|
|
4792
|
+
indexLookup[keyPathAlias] || []);
|
|
4793
|
+
var keyLength = keyPath == null
|
|
4794
|
+
? 0
|
|
4795
|
+
: typeof keyPath === 'string'
|
|
4796
|
+
? 1
|
|
4797
|
+
: keyPath.length;
|
|
4403
4798
|
var isVirtual = keyTail > 0;
|
|
4404
4799
|
var virtualIndex = __assign(__assign({}, lowLevelIndex), { name: isVirtual
|
|
4405
4800
|
? "".concat(keyPathAlias, "(virtual-from:").concat(lowLevelIndex.name, ")")
|
|
@@ -4409,16 +4804,16 @@ function createVirtualIndexMiddleware(down) {
|
|
|
4409
4804
|
allVirtualIndexes.push(virtualIndex);
|
|
4410
4805
|
}
|
|
4411
4806
|
if (keyLength > 1) {
|
|
4412
|
-
var virtualKeyPath = keyLength === 2
|
|
4413
|
-
keyPath[0]
|
|
4414
|
-
keyPath.slice(0, keyLength - 1);
|
|
4807
|
+
var virtualKeyPath = keyLength === 2
|
|
4808
|
+
? keyPath[0]
|
|
4809
|
+
: keyPath.slice(0, keyLength - 1);
|
|
4415
4810
|
addVirtualIndexes(virtualKeyPath, keyTail + 1, lowLevelIndex);
|
|
4416
4811
|
}
|
|
4417
4812
|
indexList.sort(function (a, b) { return a.keyTail - b.keyTail; });
|
|
4418
4813
|
return virtualIndex;
|
|
4419
4814
|
}
|
|
4420
4815
|
var primaryKey = addVirtualIndexes(schema.primaryKey.keyPath, 0, schema.primaryKey);
|
|
4421
|
-
indexLookup[
|
|
4816
|
+
indexLookup[':id'] = [primaryKey];
|
|
4422
4817
|
for (var _i = 0, _a = schema.indexes; _i < _a.length; _i++) {
|
|
4423
4818
|
var index = _a[_i];
|
|
4424
4819
|
addVirtualIndexes(index.keyPath, 0, index);
|
|
@@ -4429,80 +4824,82 @@ function createVirtualIndexMiddleware(down) {
|
|
|
4429
4824
|
}
|
|
4430
4825
|
function translateRange(range, keyTail) {
|
|
4431
4826
|
return {
|
|
4432
|
-
type: range.type === 1
|
|
4433
|
-
2
|
|
4434
|
-
range.type,
|
|
4827
|
+
type: range.type === 1
|
|
4828
|
+
? 2
|
|
4829
|
+
: range.type,
|
|
4435
4830
|
lower: pad(range.lower, range.lowerOpen ? down.MAX_KEY : down.MIN_KEY, keyTail),
|
|
4436
4831
|
lowerOpen: true,
|
|
4437
4832
|
upper: pad(range.upper, range.upperOpen ? down.MIN_KEY : down.MAX_KEY, keyTail),
|
|
4438
|
-
upperOpen: true
|
|
4833
|
+
upperOpen: true,
|
|
4439
4834
|
};
|
|
4440
4835
|
}
|
|
4441
4836
|
function translateRequest(req) {
|
|
4442
4837
|
var index = req.query.index;
|
|
4443
|
-
return index.isVirtual
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4838
|
+
return index.isVirtual
|
|
4839
|
+
? __assign(__assign({}, req), { query: {
|
|
4840
|
+
index: index.lowLevelIndex,
|
|
4841
|
+
range: translateRange(req.query.range, index.keyTail),
|
|
4842
|
+
} }) : req;
|
|
4447
4843
|
}
|
|
4448
4844
|
var result = __assign(__assign({}, table), { schema: __assign(__assign({}, schema), { primaryKey: primaryKey, indexes: allVirtualIndexes, getIndexByKeyPath: findBestIndex }), count: function (req) {
|
|
4449
4845
|
return table.count(translateRequest(req));
|
|
4450
4846
|
}, query: function (req) {
|
|
4451
4847
|
return table.query(translateRequest(req));
|
|
4452
4848
|
}, openCursor: function (req) {
|
|
4453
|
-
var _a = req.query
|
|
4849
|
+
var _a = req.query
|
|
4850
|
+
.index, keyTail = _a.keyTail, isVirtual = _a.isVirtual, keyLength = _a.keyLength;
|
|
4454
4851
|
if (!isVirtual)
|
|
4455
4852
|
return table.openCursor(req);
|
|
4456
4853
|
function createVirtualCursor(cursor) {
|
|
4457
4854
|
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();
|
|
4855
|
+
key != null
|
|
4856
|
+
? cursor.continue(pad(key, req.reverse ? down.MAX_KEY : down.MIN_KEY, keyTail))
|
|
4857
|
+
: req.unique
|
|
4858
|
+
? cursor.continue(cursor.key
|
|
4859
|
+
.slice(0, keyLength)
|
|
4860
|
+
.concat(req.reverse ? down.MIN_KEY : down.MAX_KEY, keyTail))
|
|
4861
|
+
: cursor.continue();
|
|
4466
4862
|
}
|
|
4467
4863
|
var virtualCursor = Object.create(cursor, {
|
|
4468
4864
|
continue: { value: _continue },
|
|
4469
4865
|
continuePrimaryKey: {
|
|
4470
4866
|
value: function (key, primaryKey) {
|
|
4471
4867
|
cursor.continuePrimaryKey(pad(key, down.MAX_KEY, keyTail), primaryKey);
|
|
4472
|
-
}
|
|
4868
|
+
},
|
|
4473
4869
|
},
|
|
4474
4870
|
primaryKey: {
|
|
4475
4871
|
get: function () {
|
|
4476
4872
|
return cursor.primaryKey;
|
|
4477
|
-
}
|
|
4873
|
+
},
|
|
4478
4874
|
},
|
|
4479
4875
|
key: {
|
|
4480
4876
|
get: function () {
|
|
4481
4877
|
var key = cursor.key;
|
|
4482
|
-
return keyLength === 1
|
|
4483
|
-
key[0]
|
|
4484
|
-
key.slice(0, keyLength);
|
|
4485
|
-
}
|
|
4878
|
+
return keyLength === 1
|
|
4879
|
+
? key[0]
|
|
4880
|
+
: key.slice(0, keyLength);
|
|
4881
|
+
},
|
|
4486
4882
|
},
|
|
4487
4883
|
value: {
|
|
4488
4884
|
get: function () {
|
|
4489
4885
|
return cursor.value;
|
|
4490
|
-
}
|
|
4491
|
-
}
|
|
4886
|
+
},
|
|
4887
|
+
},
|
|
4492
4888
|
});
|
|
4493
4889
|
return virtualCursor;
|
|
4494
4890
|
}
|
|
4495
|
-
return table
|
|
4891
|
+
return table
|
|
4892
|
+
.openCursor(translateRequest(req))
|
|
4496
4893
|
.then(function (cursor) { return cursor && createVirtualCursor(cursor); });
|
|
4497
4894
|
} });
|
|
4498
4895
|
return result;
|
|
4499
4896
|
} });
|
|
4500
4897
|
}
|
|
4501
4898
|
var virtualIndexMiddleware = {
|
|
4502
|
-
stack:
|
|
4503
|
-
name:
|
|
4899
|
+
stack: 'dbcore',
|
|
4900
|
+
name: 'VirtualIndexMiddleware',
|
|
4504
4901
|
level: 1,
|
|
4505
|
-
create: createVirtualIndexMiddleware
|
|
4902
|
+
create: createVirtualIndexMiddleware,
|
|
4506
4903
|
};
|
|
4507
4904
|
|
|
4508
4905
|
function getObjectDiff(a, b, rv, prfx) {
|
|
@@ -4546,127 +4943,155 @@ function getEffectiveKeys(primaryKey, req) {
|
|
|
4546
4943
|
}
|
|
4547
4944
|
|
|
4548
4945
|
var hooksMiddleware = {
|
|
4549
|
-
stack:
|
|
4550
|
-
name:
|
|
4946
|
+
stack: 'dbcore',
|
|
4947
|
+
name: 'HooksMiddleware',
|
|
4551
4948
|
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) {
|
|
4949
|
+
create: function (downCore) {
|
|
4950
|
+
return (__assign(__assign({}, downCore), { table: function (tableName) {
|
|
4951
|
+
var downTable = downCore.table(tableName);
|
|
4952
|
+
var primaryKey = downTable.schema.primaryKey;
|
|
4953
|
+
var tableMiddleware = __assign(__assign({}, downTable), { mutate: function (req) {
|
|
4578
4954
|
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
|
-
|
|
4955
|
+
var _a = dxTrans.table(tableName).hook, deleting = _a.deleting, creating = _a.creating, updating = _a.updating;
|
|
4956
|
+
switch (req.type) {
|
|
4957
|
+
case 'add':
|
|
4958
|
+
if (creating.fire === nop)
|
|
4959
|
+
break;
|
|
4960
|
+
return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
|
|
4961
|
+
case 'put':
|
|
4962
|
+
if (creating.fire === nop && updating.fire === nop)
|
|
4963
|
+
break;
|
|
4964
|
+
return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
|
|
4965
|
+
case 'delete':
|
|
4966
|
+
if (deleting.fire === nop)
|
|
4967
|
+
break;
|
|
4968
|
+
return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
|
|
4969
|
+
case 'deleteRange':
|
|
4970
|
+
if (deleting.fire === nop)
|
|
4971
|
+
break;
|
|
4972
|
+
return dxTrans._promise('readwrite', function () { return deleteRange(req); }, true);
|
|
4973
|
+
}
|
|
4974
|
+
return downTable.mutate(req);
|
|
4975
|
+
function addPutOrDelete(req) {
|
|
4976
|
+
var dxTrans = PSD.trans;
|
|
4977
|
+
var keys = req.keys || getEffectiveKeys(primaryKey, req);
|
|
4978
|
+
if (!keys)
|
|
4979
|
+
throw new Error('Keys missing');
|
|
4980
|
+
req =
|
|
4981
|
+
req.type === 'add' || req.type === 'put'
|
|
4982
|
+
? __assign(__assign({}, req), { keys: keys }) : __assign({}, req);
|
|
4983
|
+
if (req.type !== 'delete')
|
|
4984
|
+
req.values = __spreadArray([], req.values, true);
|
|
4985
|
+
if (req.keys)
|
|
4986
|
+
req.keys = __spreadArray([], req.keys, true);
|
|
4987
|
+
return getExistingValues(downTable, req, keys).then(function (existingValues) {
|
|
4988
|
+
var contexts = keys.map(function (key, i) {
|
|
4989
|
+
var existingValue = existingValues[i];
|
|
4990
|
+
var ctx = { onerror: null, onsuccess: null };
|
|
4991
|
+
if (req.type === 'delete') {
|
|
4992
|
+
deleting.fire.call(ctx, key, existingValue, dxTrans);
|
|
4602
4993
|
}
|
|
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]);
|
|
4994
|
+
else if (req.type === 'add' ||
|
|
4995
|
+
existingValue === undefined) {
|
|
4996
|
+
var generatedPrimaryKey = creating.fire.call(ctx, key, req.values[i], dxTrans);
|
|
4997
|
+
if (key == null && generatedPrimaryKey != null) {
|
|
4998
|
+
key = generatedPrimaryKey;
|
|
4999
|
+
req.keys[i] = key;
|
|
5000
|
+
if (!primaryKey.outbound) {
|
|
5001
|
+
setByKeyPath(req.values[i], primaryKey.keyPath, key);
|
|
4615
5002
|
}
|
|
4616
|
-
}
|
|
5003
|
+
}
|
|
4617
5004
|
}
|
|
4618
|
-
|
|
4619
|
-
|
|
5005
|
+
else {
|
|
5006
|
+
var objectDiff = getObjectDiff(existingValue, req.values[i]);
|
|
5007
|
+
var additionalChanges_1 = updating.fire.call(ctx, objectDiff, key, existingValue, dxTrans);
|
|
5008
|
+
if (additionalChanges_1) {
|
|
5009
|
+
var requestedValue_1 = req.values[i];
|
|
5010
|
+
Object.keys(additionalChanges_1).forEach(function (keyPath) {
|
|
5011
|
+
if (hasOwn(requestedValue_1, keyPath)) {
|
|
5012
|
+
requestedValue_1[keyPath] =
|
|
5013
|
+
additionalChanges_1[keyPath];
|
|
5014
|
+
}
|
|
5015
|
+
else {
|
|
5016
|
+
setByKeyPath(requestedValue_1, keyPath, additionalChanges_1[keyPath]);
|
|
5017
|
+
}
|
|
5018
|
+
});
|
|
5019
|
+
}
|
|
5020
|
+
}
|
|
5021
|
+
return ctx;
|
|
5022
|
+
});
|
|
5023
|
+
return downTable
|
|
5024
|
+
.mutate(req)
|
|
5025
|
+
.then(function (_a) {
|
|
5026
|
+
var failures = _a.failures, results = _a.results, numFailures = _a.numFailures, lastResult = _a.lastResult;
|
|
5027
|
+
for (var i = 0; i < keys.length; ++i) {
|
|
5028
|
+
var primKey = results ? results[i] : keys[i];
|
|
5029
|
+
var ctx = contexts[i];
|
|
5030
|
+
if (primKey == null) {
|
|
5031
|
+
ctx.onerror && ctx.onerror(failures[i]);
|
|
5032
|
+
}
|
|
5033
|
+
else {
|
|
5034
|
+
ctx.onsuccess &&
|
|
5035
|
+
ctx.onsuccess(req.type === 'put' && existingValues[i]
|
|
5036
|
+
? req.values[i]
|
|
5037
|
+
: primKey
|
|
5038
|
+
);
|
|
5039
|
+
}
|
|
5040
|
+
}
|
|
5041
|
+
return { failures: failures, results: results, numFailures: numFailures, lastResult: lastResult };
|
|
5042
|
+
})
|
|
5043
|
+
.catch(function (error) {
|
|
5044
|
+
contexts.forEach(function (ctx) { return ctx.onerror && ctx.onerror(error); });
|
|
5045
|
+
return Promise.reject(error);
|
|
5046
|
+
});
|
|
4620
5047
|
});
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
5048
|
+
}
|
|
5049
|
+
function deleteRange(req) {
|
|
5050
|
+
return deleteNextChunk(req.trans, req.range, 10000);
|
|
5051
|
+
}
|
|
5052
|
+
function deleteNextChunk(trans, range, limit) {
|
|
5053
|
+
return downTable
|
|
5054
|
+
.query({
|
|
5055
|
+
trans: trans,
|
|
5056
|
+
values: false,
|
|
5057
|
+
query: { index: primaryKey, range: range },
|
|
5058
|
+
limit: limit,
|
|
5059
|
+
})
|
|
5060
|
+
.then(function (_a) {
|
|
5061
|
+
var result = _a.result;
|
|
5062
|
+
return addPutOrDelete({
|
|
5063
|
+
type: 'delete',
|
|
5064
|
+
keys: result,
|
|
5065
|
+
trans: trans,
|
|
5066
|
+
}).then(function (res) {
|
|
5067
|
+
if (res.numFailures > 0)
|
|
5068
|
+
return Promise.reject(res.failures[0]);
|
|
5069
|
+
if (result.length < limit) {
|
|
5070
|
+
return {
|
|
5071
|
+
failures: [],
|
|
5072
|
+
numFailures: 0,
|
|
5073
|
+
lastResult: undefined,
|
|
5074
|
+
};
|
|
4628
5075
|
}
|
|
4629
5076
|
else {
|
|
4630
|
-
|
|
4631
|
-
req.values[i] :
|
|
4632
|
-
primKey
|
|
4633
|
-
);
|
|
5077
|
+
return deleteNextChunk(trans, __assign(__assign({}, range), { lower: result[result.length - 1], lowerOpen: true }), limit);
|
|
4634
5078
|
}
|
|
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
|
-
}
|
|
5079
|
+
});
|
|
4659
5080
|
});
|
|
4660
|
-
}
|
|
4661
|
-
}
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
5081
|
+
}
|
|
5082
|
+
} });
|
|
5083
|
+
return tableMiddleware;
|
|
5084
|
+
} }));
|
|
5085
|
+
},
|
|
4665
5086
|
};
|
|
4666
5087
|
function getExistingValues(table, req, effectiveKeys) {
|
|
4667
|
-
return req.type ===
|
|
5088
|
+
return req.type === 'add'
|
|
4668
5089
|
? Promise.resolve([])
|
|
4669
|
-
: table.getMany({
|
|
5090
|
+
: table.getMany({
|
|
5091
|
+
trans: req.trans,
|
|
5092
|
+
keys: effectiveKeys,
|
|
5093
|
+
cache: 'immutable',
|
|
5094
|
+
});
|
|
4670
5095
|
}
|
|
4671
5096
|
|
|
4672
5097
|
function getFromTransactionCache(keys, cache, clone) {
|
|
@@ -4689,7 +5114,7 @@ function getFromTransactionCache(keys, cache, clone) {
|
|
|
4689
5114
|
}
|
|
4690
5115
|
}
|
|
4691
5116
|
var cacheExistingValuesMiddleware = {
|
|
4692
|
-
stack:
|
|
5117
|
+
stack: 'dbcore',
|
|
4693
5118
|
level: -1,
|
|
4694
5119
|
create: function (core) {
|
|
4695
5120
|
return {
|
|
@@ -4699,20 +5124,20 @@ var cacheExistingValuesMiddleware = {
|
|
|
4699
5124
|
if (!req.cache) {
|
|
4700
5125
|
return table.getMany(req);
|
|
4701
5126
|
}
|
|
4702
|
-
var cachedResult = getFromTransactionCache(req.keys, req.trans[
|
|
5127
|
+
var cachedResult = getFromTransactionCache(req.keys, req.trans['_cache'], req.cache === 'clone');
|
|
4703
5128
|
if (cachedResult) {
|
|
4704
5129
|
return DexiePromise.resolve(cachedResult);
|
|
4705
5130
|
}
|
|
4706
5131
|
return table.getMany(req).then(function (res) {
|
|
4707
|
-
req.trans[
|
|
5132
|
+
req.trans['_cache'] = {
|
|
4708
5133
|
keys: req.keys,
|
|
4709
|
-
values: req.cache ===
|
|
5134
|
+
values: req.cache === 'clone' ? deepClone(res) : res,
|
|
4710
5135
|
};
|
|
4711
5136
|
return res;
|
|
4712
5137
|
});
|
|
4713
5138
|
}, mutate: function (req) {
|
|
4714
|
-
if (req.type !==
|
|
4715
|
-
req.trans[
|
|
5139
|
+
if (req.type !== 'add')
|
|
5140
|
+
req.trans['_cache'] = null;
|
|
4716
5141
|
return table.mutate(req);
|
|
4717
5142
|
} });
|
|
4718
5143
|
},
|
|
@@ -4744,9 +5169,9 @@ function isCachableRequest(type, req) {
|
|
|
4744
5169
|
}
|
|
4745
5170
|
|
|
4746
5171
|
var observabilityMiddleware = {
|
|
4747
|
-
stack:
|
|
5172
|
+
stack: 'dbcore',
|
|
4748
5173
|
level: 0,
|
|
4749
|
-
name:
|
|
5174
|
+
name: 'Observability',
|
|
4750
5175
|
create: function (core) {
|
|
4751
5176
|
var dbName = core.schema.name;
|
|
4752
5177
|
var FULL_RANGE = new RangeSet(core.MIN_KEY, core.MAX_KEY);
|
|
@@ -4760,7 +5185,11 @@ var observabilityMiddleware = {
|
|
|
4760
5185
|
var schema = table.schema;
|
|
4761
5186
|
var primaryKey = schema.primaryKey, indexes = schema.indexes;
|
|
4762
5187
|
var extractKey = primaryKey.extractKey, outbound = primaryKey.outbound;
|
|
4763
|
-
var indexesWithAutoIncPK = primaryKey.autoIncrement &&
|
|
5188
|
+
var indexesWithAutoIncPK = primaryKey.autoIncrement &&
|
|
5189
|
+
indexes.filter(function (index) {
|
|
5190
|
+
return index.compound &&
|
|
5191
|
+
index.keyPath.includes(primaryKey.keyPath);
|
|
5192
|
+
});
|
|
4764
5193
|
var tableClone = __assign(__assign({}, table), { mutate: function (req) {
|
|
4765
5194
|
var _a, _b;
|
|
4766
5195
|
var trans = req.trans;
|
|
@@ -4770,20 +5199,25 @@ var observabilityMiddleware = {
|
|
|
4770
5199
|
return (mutatedParts[part] ||
|
|
4771
5200
|
(mutatedParts[part] = new RangeSet()));
|
|
4772
5201
|
};
|
|
4773
|
-
var pkRangeSet = getRangeSet(
|
|
4774
|
-
var delsRangeSet = getRangeSet(
|
|
5202
|
+
var pkRangeSet = getRangeSet('');
|
|
5203
|
+
var delsRangeSet = getRangeSet(':dels');
|
|
4775
5204
|
var type = req.type;
|
|
4776
|
-
var _c = req.type ===
|
|
5205
|
+
var _c = req.type === 'deleteRange'
|
|
4777
5206
|
? [req.range]
|
|
4778
|
-
: req.type ===
|
|
5207
|
+
: req.type === 'delete'
|
|
4779
5208
|
? [req.keys]
|
|
4780
5209
|
: req.values.length < 50
|
|
4781
|
-
? [
|
|
5210
|
+
? [
|
|
5211
|
+
getEffectiveKeys(primaryKey, req).filter(function (id) { return id; }),
|
|
5212
|
+
req.values,
|
|
5213
|
+
]
|
|
4782
5214
|
: [], keys = _c[0], newObjs = _c[1];
|
|
4783
|
-
var oldCache = req.trans[
|
|
5215
|
+
var oldCache = req.trans['_cache'];
|
|
4784
5216
|
if (isArray(keys)) {
|
|
4785
5217
|
pkRangeSet.addKeys(keys);
|
|
4786
|
-
var oldObjs = type === 'delete' || keys.length === newObjs.length
|
|
5218
|
+
var oldObjs = type === 'delete' || keys.length === newObjs.length
|
|
5219
|
+
? getFromTransactionCache(keys, oldCache)
|
|
5220
|
+
: null;
|
|
4787
5221
|
if (!oldObjs) {
|
|
4788
5222
|
delsRangeSet.addKeys(keys);
|
|
4789
5223
|
}
|
|
@@ -4794,7 +5228,7 @@ var observabilityMiddleware = {
|
|
|
4794
5228
|
else if (keys) {
|
|
4795
5229
|
var range = {
|
|
4796
5230
|
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
|
|
5231
|
+
to: (_b = keys.upper) !== null && _b !== void 0 ? _b : core.MAX_KEY,
|
|
4798
5232
|
};
|
|
4799
5233
|
delsRangeSet.add(range);
|
|
4800
5234
|
pkRangeSet.add(range);
|
|
@@ -4802,7 +5236,9 @@ var observabilityMiddleware = {
|
|
|
4802
5236
|
else {
|
|
4803
5237
|
pkRangeSet.add(FULL_RANGE);
|
|
4804
5238
|
delsRangeSet.add(FULL_RANGE);
|
|
4805
|
-
schema.indexes.forEach(function (idx) {
|
|
5239
|
+
schema.indexes.forEach(function (idx) {
|
|
5240
|
+
return getRangeSet(idx.name).add(FULL_RANGE);
|
|
5241
|
+
});
|
|
4806
5242
|
}
|
|
4807
5243
|
return table.mutate(req).then(function (res) {
|
|
4808
5244
|
if (keys && (req.type === 'add' || req.type === 'put')) {
|
|
@@ -4841,9 +5277,10 @@ var observabilityMiddleware = {
|
|
|
4841
5277
|
tableClone[method] = function (req) {
|
|
4842
5278
|
var subscr = PSD.subscr;
|
|
4843
5279
|
var isLiveQuery = !!subscr;
|
|
4844
|
-
var cachable = isCachableContext(PSD, table) &&
|
|
5280
|
+
var cachable = isCachableContext(PSD, table) &&
|
|
5281
|
+
isCachableRequest(method, req);
|
|
4845
5282
|
var obsSet = cachable
|
|
4846
|
-
? req.obsSet = {}
|
|
5283
|
+
? (req.obsSet = {})
|
|
4847
5284
|
: subscr;
|
|
4848
5285
|
if (isLiveQuery) {
|
|
4849
5286
|
var getRangeSet = function (indexName) {
|
|
@@ -4851,26 +5288,28 @@ var observabilityMiddleware = {
|
|
|
4851
5288
|
return (obsSet[part] ||
|
|
4852
5289
|
(obsSet[part] = new RangeSet()));
|
|
4853
5290
|
};
|
|
4854
|
-
var pkRangeSet_1 = getRangeSet(
|
|
4855
|
-
var delsRangeSet_1 = getRangeSet(
|
|
5291
|
+
var pkRangeSet_1 = getRangeSet('');
|
|
5292
|
+
var delsRangeSet_1 = getRangeSet(':dels');
|
|
4856
5293
|
var _a = readSubscribers[method](req), queriedIndex = _a[0], queriedRanges = _a[1];
|
|
4857
|
-
if (method === 'query' &&
|
|
5294
|
+
if (method === 'query' &&
|
|
5295
|
+
queriedIndex.isPrimaryKey &&
|
|
5296
|
+
!req.values) {
|
|
4858
5297
|
delsRangeSet_1.add(queriedRanges);
|
|
4859
5298
|
}
|
|
4860
5299
|
else {
|
|
4861
|
-
getRangeSet(queriedIndex.name ||
|
|
5300
|
+
getRangeSet(queriedIndex.name || '').add(queriedRanges);
|
|
4862
5301
|
}
|
|
4863
5302
|
if (!queriedIndex.isPrimaryKey) {
|
|
4864
|
-
if (method ===
|
|
5303
|
+
if (method === 'count') {
|
|
4865
5304
|
delsRangeSet_1.add(FULL_RANGE);
|
|
4866
5305
|
}
|
|
4867
5306
|
else {
|
|
4868
|
-
var keysPromise_1 = method ===
|
|
5307
|
+
var keysPromise_1 = method === 'query' &&
|
|
4869
5308
|
outbound &&
|
|
4870
5309
|
req.values &&
|
|
4871
5310
|
table.query(__assign(__assign({}, req), { values: false }));
|
|
4872
5311
|
return table[method].apply(this, arguments).then(function (res) {
|
|
4873
|
-
if (method ===
|
|
5312
|
+
if (method === 'query') {
|
|
4874
5313
|
if (outbound && req.values) {
|
|
4875
5314
|
return keysPromise_1.then(function (_a) {
|
|
4876
5315
|
var resultingKeys = _a.result;
|
|
@@ -4888,9 +5327,10 @@ var observabilityMiddleware = {
|
|
|
4888
5327
|
delsRangeSet_1.addKeys(pKeys);
|
|
4889
5328
|
}
|
|
4890
5329
|
}
|
|
4891
|
-
else if (method ===
|
|
5330
|
+
else if (method === 'openCursor') {
|
|
4892
5331
|
var cursor_1 = res;
|
|
4893
|
-
var wantValues_1 = req
|
|
5332
|
+
var wantValues_1 = req
|
|
5333
|
+
.values;
|
|
4894
5334
|
return (cursor_1 &&
|
|
4895
5335
|
Object.create(cursor_1, {
|
|
4896
5336
|
key: {
|
|
@@ -4908,7 +5348,8 @@ var observabilityMiddleware = {
|
|
|
4908
5348
|
},
|
|
4909
5349
|
value: {
|
|
4910
5350
|
get: function () {
|
|
4911
|
-
wantValues_1 &&
|
|
5351
|
+
wantValues_1 &&
|
|
5352
|
+
pkRangeSet_1.addKey(cursor_1.primaryKey);
|
|
4912
5353
|
return cursor_1.value;
|
|
4913
5354
|
},
|
|
4914
5355
|
},
|
|
@@ -4928,13 +5369,17 @@ var observabilityMiddleware = {
|
|
|
4928
5369
|
};
|
|
4929
5370
|
function trackAffectedIndexes(getRangeSet, schema, oldObjs, newObjs) {
|
|
4930
5371
|
function addAffectedIndex(ix) {
|
|
4931
|
-
var rangeSet = getRangeSet(ix.name ||
|
|
5372
|
+
var rangeSet = getRangeSet(ix.name || '');
|
|
4932
5373
|
function extractKey(obj) {
|
|
4933
5374
|
return obj != null ? ix.extractKey(obj) : null;
|
|
4934
5375
|
}
|
|
4935
|
-
var addKeyOrKeys = function (key) {
|
|
4936
|
-
|
|
4937
|
-
|
|
5376
|
+
var addKeyOrKeys = function (key) {
|
|
5377
|
+
return ix.multiEntry && isArray(key)
|
|
5378
|
+
?
|
|
5379
|
+
key.forEach(function (key) { return rangeSet.addKey(key); })
|
|
5380
|
+
:
|
|
5381
|
+
rangeSet.addKey(key);
|
|
5382
|
+
};
|
|
4938
5383
|
(oldObjs || newObjs).forEach(function (_, i) {
|
|
4939
5384
|
var oldKey = oldObjs && extractKey(oldObjs[i]);
|
|
4940
5385
|
var newKey = newObjs && extractKey(newObjs[i]);
|
|
@@ -5148,7 +5593,8 @@ function findCompatibleQuery(dbName, tableName, type, req) {
|
|
|
5148
5593
|
var _a;
|
|
5149
5594
|
return entry.req.limit === req.limit &&
|
|
5150
5595
|
entry.req.values === req.values &&
|
|
5151
|
-
((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') ===
|
|
5596
|
+
((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') ===
|
|
5597
|
+
reqDirection_1 &&
|
|
5152
5598
|
areRangesEqual(entry.req.query.range, req.query.range);
|
|
5153
5599
|
});
|
|
5154
5600
|
if (equalEntry)
|
|
@@ -5162,7 +5608,8 @@ function findCompatibleQuery(dbName, tableName, type, req) {
|
|
|
5162
5608
|
var _a;
|
|
5163
5609
|
var limit = 'limit' in entry.req ? entry.req.limit : Infinity;
|
|
5164
5610
|
return (limit >= req.limit &&
|
|
5165
|
-
((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') ===
|
|
5611
|
+
((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') ===
|
|
5612
|
+
reqDirection_1 &&
|
|
5166
5613
|
(req.values ? entry.req.values : true) &&
|
|
5167
5614
|
isSuperRange(entry.req.query.range, req.query.range));
|
|
5168
5615
|
});
|
|
@@ -5177,7 +5624,7 @@ function findCompatibleQuery(dbName, tableName, type, req) {
|
|
|
5177
5624
|
|
|
5178
5625
|
function subscribeToCacheEntry(cacheEntry, container, requery, signal) {
|
|
5179
5626
|
cacheEntry.subscribers.add(requery);
|
|
5180
|
-
signal.addEventListener(
|
|
5627
|
+
signal.addEventListener('abort', function () {
|
|
5181
5628
|
cacheEntry.subscribers.delete(requery);
|
|
5182
5629
|
if (cacheEntry.subscribers.size === 0) {
|
|
5183
5630
|
enqueForDeletion(cacheEntry, container);
|
|
@@ -5213,14 +5660,18 @@ var cacheMiddleware = {
|
|
|
5213
5660
|
if (tblCache) {
|
|
5214
5661
|
var table = core.table(storeName);
|
|
5215
5662
|
var ops = tblCache.optimisticOps.filter(function (op) { return op.trans === idbtrans; });
|
|
5216
|
-
if (idbtrans._explicit &&
|
|
5663
|
+
if (idbtrans._explicit &&
|
|
5664
|
+
wasCommitted &&
|
|
5665
|
+
idbtrans.mutatedParts) {
|
|
5217
5666
|
for (var _a = 0, _b = Object.values(tblCache.queries.query); _a < _b.length; _a++) {
|
|
5218
5667
|
var entries = _b[_a];
|
|
5219
5668
|
for (var _c = 0, _d = entries.slice(); _c < _d.length; _c++) {
|
|
5220
5669
|
var entry = _d[_c];
|
|
5221
5670
|
if (obsSetsOverlap(entry.obsSet, idbtrans.mutatedParts)) {
|
|
5222
5671
|
delArrayItem(entries, entry);
|
|
5223
|
-
entry.subscribers.forEach(function (requery) {
|
|
5672
|
+
entry.subscribers.forEach(function (requery) {
|
|
5673
|
+
return affectedSubscribers_1.add(requery);
|
|
5674
|
+
});
|
|
5224
5675
|
}
|
|
5225
5676
|
}
|
|
5226
5677
|
}
|
|
@@ -5239,18 +5690,24 @@ var cacheMiddleware = {
|
|
|
5239
5690
|
var modRes = applyOptimisticOps(entry.res, entry.req, ops, table, entry, freezeResults);
|
|
5240
5691
|
if (entry.dirty) {
|
|
5241
5692
|
delArrayItem(entries, entry);
|
|
5242
|
-
entry.subscribers.forEach(function (requery) {
|
|
5693
|
+
entry.subscribers.forEach(function (requery) {
|
|
5694
|
+
return affectedSubscribers_1.add(requery);
|
|
5695
|
+
});
|
|
5243
5696
|
}
|
|
5244
5697
|
else if (modRes !== entry.res) {
|
|
5245
5698
|
entry.res = modRes;
|
|
5246
|
-
entry.promise = DexiePromise.resolve({
|
|
5699
|
+
entry.promise = DexiePromise.resolve({
|
|
5700
|
+
result: modRes,
|
|
5701
|
+
});
|
|
5247
5702
|
}
|
|
5248
5703
|
}
|
|
5249
5704
|
else {
|
|
5250
5705
|
if (entry.dirty) {
|
|
5251
5706
|
delArrayItem(entries, entry);
|
|
5252
5707
|
}
|
|
5253
|
-
entry.subscribers.forEach(function (requery) {
|
|
5708
|
+
entry.subscribers.forEach(function (requery) {
|
|
5709
|
+
return affectedSubscribers_1.add(requery);
|
|
5710
|
+
});
|
|
5254
5711
|
}
|
|
5255
5712
|
}
|
|
5256
5713
|
}
|
|
@@ -5288,7 +5745,9 @@ var cacheMiddleware = {
|
|
|
5288
5745
|
if (!tblCache)
|
|
5289
5746
|
return downTable.mutate(req);
|
|
5290
5747
|
var promise = downTable.mutate(req);
|
|
5291
|
-
if ((req.type === 'add' || req.type === 'put') &&
|
|
5748
|
+
if ((req.type === 'add' || req.type === 'put') &&
|
|
5749
|
+
(req.values.length >= 50 ||
|
|
5750
|
+
getEffectiveKeys(primKey, req).some(function (key) { return key == null; }))) {
|
|
5292
5751
|
promise.then(function (res) {
|
|
5293
5752
|
var reqWithResolvedKeys = __assign(__assign({}, req), { values: req.values.map(function (value, i) {
|
|
5294
5753
|
var _a;
|
|
@@ -5302,7 +5761,10 @@ var cacheMiddleware = {
|
|
|
5302
5761
|
}) });
|
|
5303
5762
|
var adjustedReq = adjustOptimisticFromFailures(tblCache, reqWithResolvedKeys, res);
|
|
5304
5763
|
tblCache.optimisticOps.push(adjustedReq);
|
|
5305
|
-
queueMicrotask(function () {
|
|
5764
|
+
queueMicrotask(function () {
|
|
5765
|
+
return req.mutatedParts &&
|
|
5766
|
+
signalSubscribersLazily(req.mutatedParts);
|
|
5767
|
+
});
|
|
5306
5768
|
});
|
|
5307
5769
|
}
|
|
5308
5770
|
else {
|
|
@@ -5326,16 +5788,20 @@ var cacheMiddleware = {
|
|
|
5326
5788
|
return promise;
|
|
5327
5789
|
}, query: function (req) {
|
|
5328
5790
|
var _a;
|
|
5329
|
-
if (!isCachableContext(PSD, downTable) ||
|
|
5791
|
+
if (!isCachableContext(PSD, downTable) ||
|
|
5792
|
+
!isCachableRequest('query', req))
|
|
5330
5793
|
return downTable.query(req);
|
|
5331
|
-
var freezeResults = ((_a = PSD.trans) === null || _a === void 0 ? void 0 : _a.db._options.cache) ===
|
|
5794
|
+
var freezeResults = ((_a = PSD.trans) === null || _a === void 0 ? void 0 : _a.db._options.cache) ===
|
|
5795
|
+
'immutable';
|
|
5332
5796
|
var _b = PSD, requery = _b.requery, signal = _b.signal;
|
|
5333
5797
|
var _c = findCompatibleQuery(dbName, tableName, 'query', req), cacheEntry = _c[0], exactMatch = _c[1], tblCache = _c[2], container = _c[3];
|
|
5334
5798
|
if (cacheEntry && exactMatch) {
|
|
5335
5799
|
cacheEntry.obsSet = req.obsSet;
|
|
5336
5800
|
}
|
|
5337
5801
|
else {
|
|
5338
|
-
var promise = downTable
|
|
5802
|
+
var promise = downTable
|
|
5803
|
+
.query(req)
|
|
5804
|
+
.then(function (res) {
|
|
5339
5805
|
var result = res.result;
|
|
5340
5806
|
if (cacheEntry)
|
|
5341
5807
|
cacheEntry.res = result;
|
|
@@ -5349,7 +5815,8 @@ var cacheMiddleware = {
|
|
|
5349
5815
|
res.result = deepClone(result);
|
|
5350
5816
|
}
|
|
5351
5817
|
return res;
|
|
5352
|
-
})
|
|
5818
|
+
})
|
|
5819
|
+
.catch(function (error) {
|
|
5353
5820
|
if (container && cacheEntry)
|
|
5354
5821
|
delArrayItem(container, cacheEntry);
|
|
5355
5822
|
return Promise.reject(error);
|
|
@@ -5375,7 +5842,7 @@ var cacheMiddleware = {
|
|
|
5375
5842
|
},
|
|
5376
5843
|
objs: new Map(),
|
|
5377
5844
|
optimisticOps: [],
|
|
5378
|
-
unsignaledParts: {}
|
|
5845
|
+
unsignaledParts: {},
|
|
5379
5846
|
};
|
|
5380
5847
|
}
|
|
5381
5848
|
tblCache.queries.query[req.query.index.name || ''] = container;
|
|
@@ -5400,7 +5867,7 @@ function vipify(target, vipDb) {
|
|
|
5400
5867
|
if (prop === 'db')
|
|
5401
5868
|
return vipDb;
|
|
5402
5869
|
return Reflect.get(target, prop, receiver);
|
|
5403
|
-
}
|
|
5870
|
+
},
|
|
5404
5871
|
});
|
|
5405
5872
|
}
|
|
5406
5873
|
|
|
@@ -5415,7 +5882,7 @@ var Dexie$1 = (function () {
|
|
|
5415
5882
|
indexedDB: deps.indexedDB, IDBKeyRange: deps.IDBKeyRange, cache: 'cloned', maxConnections: DEFAULT_MAX_CONNECTIONS }, options);
|
|
5416
5883
|
this._deps = {
|
|
5417
5884
|
indexedDB: options.indexedDB,
|
|
5418
|
-
IDBKeyRange: options.IDBKeyRange
|
|
5885
|
+
IDBKeyRange: options.IDBKeyRange,
|
|
5419
5886
|
};
|
|
5420
5887
|
var addons = options.addons;
|
|
5421
5888
|
this._dbSchema = {};
|
|
@@ -5445,7 +5912,9 @@ var Dexie$1 = (function () {
|
|
|
5445
5912
|
});
|
|
5446
5913
|
this._state = state;
|
|
5447
5914
|
this.name = name;
|
|
5448
|
-
this.on = Events(this,
|
|
5915
|
+
this.on = Events(this, 'populate', 'blocked', 'versionchange', 'close', {
|
|
5916
|
+
ready: [promisableChain, nop],
|
|
5917
|
+
});
|
|
5449
5918
|
this.once = function (event, callback) {
|
|
5450
5919
|
var fn = function () {
|
|
5451
5920
|
var args = [];
|
|
@@ -5489,26 +5958,29 @@ var Dexie$1 = (function () {
|
|
|
5489
5958
|
this.Transaction = createTransactionConstructor(this);
|
|
5490
5959
|
this.Version = createVersionConstructor(this);
|
|
5491
5960
|
this.WhereClause = createWhereClauseConstructor(this);
|
|
5492
|
-
this.on(
|
|
5961
|
+
this.on('versionchange', function (ev) {
|
|
5493
5962
|
if (ev.newVersion > 0)
|
|
5494
5963
|
console.warn("Another connection wants to upgrade database '".concat(_this.name, "'. Closing db now to resume the upgrade."));
|
|
5495
5964
|
else
|
|
5496
5965
|
console.warn("Another connection wants to delete database '".concat(_this.name, "'. Closing db now to resume the delete request."));
|
|
5497
5966
|
_this.close({ disableAutoOpen: false });
|
|
5498
5967
|
});
|
|
5499
|
-
this.on(
|
|
5968
|
+
this.on('blocked', function (ev) {
|
|
5500
5969
|
if (!ev.newVersion || ev.newVersion < ev.oldVersion)
|
|
5501
5970
|
console.warn("Dexie.delete('".concat(_this.name, "') was blocked"));
|
|
5502
5971
|
else
|
|
5503
5972
|
console.warn("Upgrade '".concat(_this.name, "' blocked by other connection holding version ").concat(ev.oldVersion / 10));
|
|
5504
5973
|
});
|
|
5505
5974
|
this._maxKey = getMaxKey(options.IDBKeyRange);
|
|
5506
|
-
this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) {
|
|
5975
|
+
this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) {
|
|
5976
|
+
return new _this.Transaction(mode, storeNames, dbschema, _this._options.chromeTransactionDurability, parentTransaction);
|
|
5977
|
+
};
|
|
5507
5978
|
this._fireOnBlocked = function (ev) {
|
|
5508
|
-
_this.on(
|
|
5509
|
-
connections
|
|
5979
|
+
_this.on('blocked').fire(ev);
|
|
5980
|
+
connections
|
|
5981
|
+
.toArray()
|
|
5510
5982
|
.filter(function (c) { return c.name === _this.name && c !== _this && !c._state.vcFired; })
|
|
5511
|
-
.map(function (c) { return c.on(
|
|
5983
|
+
.map(function (c) { return c.on('versionchange').fire(ev); });
|
|
5512
5984
|
};
|
|
5513
5985
|
this.use(cacheExistingValuesMiddleware);
|
|
5514
5986
|
this.use(cacheMiddleware);
|
|
@@ -5532,7 +6004,7 @@ var Dexie$1 = (function () {
|
|
|
5532
6004
|
return vipify(tx, vipDB);
|
|
5533
6005
|
};
|
|
5534
6006
|
return rv;
|
|
5535
|
-
}
|
|
6007
|
+
},
|
|
5536
6008
|
});
|
|
5537
6009
|
this.vip = vipDB;
|
|
5538
6010
|
addons.forEach(function (addon) { return addon(_this); });
|
|
@@ -5542,7 +6014,7 @@ var Dexie$1 = (function () {
|
|
|
5542
6014
|
throw new exceptions.Type("Given version is not a positive number");
|
|
5543
6015
|
versionNumber = Math.round(versionNumber * 10) / 10;
|
|
5544
6016
|
if (this.idbdb || this._state.isBeingOpened)
|
|
5545
|
-
throw new exceptions.Schema(
|
|
6017
|
+
throw new exceptions.Schema('Cannot add version when database is open');
|
|
5546
6018
|
this.verno = Math.max(this.verno, versionNumber);
|
|
5547
6019
|
var versions = this._versions;
|
|
5548
6020
|
var versionInstance = versions.filter(function (v) { return v._cfg.version === versionNumber; })[0];
|
|
@@ -5557,26 +6029,34 @@ var Dexie$1 = (function () {
|
|
|
5557
6029
|
};
|
|
5558
6030
|
Dexie.prototype._whenReady = function (fn) {
|
|
5559
6031
|
var _this = this;
|
|
5560
|
-
return
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
reject(new exceptions.DatabaseClosed());
|
|
5567
|
-
return;
|
|
6032
|
+
return this.idbdb &&
|
|
6033
|
+
(this._state.openComplete || PSD.letThrough || this._vip)
|
|
6034
|
+
? fn()
|
|
6035
|
+
: new DexiePromise(function (resolve, reject) {
|
|
6036
|
+
if (_this._state.openComplete) {
|
|
6037
|
+
return reject(new exceptions.DatabaseClosed(_this._state.dbOpenError));
|
|
5568
6038
|
}
|
|
5569
|
-
_this.
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
|
|
6039
|
+
if (!_this._state.isBeingOpened) {
|
|
6040
|
+
if (!_this._state.autoOpen) {
|
|
6041
|
+
reject(new exceptions.DatabaseClosed());
|
|
6042
|
+
return;
|
|
6043
|
+
}
|
|
6044
|
+
_this.open().catch(nop);
|
|
6045
|
+
}
|
|
6046
|
+
_this._state.dbReadyPromise.then(resolve, reject);
|
|
6047
|
+
}).then(fn);
|
|
5573
6048
|
};
|
|
5574
6049
|
Dexie.prototype.use = function (_a) {
|
|
5575
6050
|
var stack = _a.stack, create = _a.create, level = _a.level, name = _a.name;
|
|
5576
6051
|
if (name)
|
|
5577
6052
|
this.unuse({ stack: stack, name: name });
|
|
5578
6053
|
var middlewares = this._middlewares[stack] || (this._middlewares[stack] = []);
|
|
5579
|
-
middlewares.push({
|
|
6054
|
+
middlewares.push({
|
|
6055
|
+
stack: stack,
|
|
6056
|
+
create: create,
|
|
6057
|
+
level: level == null ? 10 : level,
|
|
6058
|
+
name: name,
|
|
6059
|
+
});
|
|
5580
6060
|
middlewares.sort(function (a, b) { return a.level - b.level; });
|
|
5581
6061
|
return this;
|
|
5582
6062
|
};
|
|
@@ -5584,9 +6064,11 @@ var Dexie$1 = (function () {
|
|
|
5584
6064
|
var stack = _a.stack, name = _a.name, create = _a.create;
|
|
5585
6065
|
if (stack && this._middlewares[stack]) {
|
|
5586
6066
|
this._middlewares[stack] = this._middlewares[stack].filter(function (mw) {
|
|
5587
|
-
return create
|
|
5588
|
-
|
|
5589
|
-
|
|
6067
|
+
return create
|
|
6068
|
+
? mw.create !== create
|
|
6069
|
+
: name
|
|
6070
|
+
? mw.name !== name
|
|
6071
|
+
: false;
|
|
5590
6072
|
});
|
|
5591
6073
|
}
|
|
5592
6074
|
return this;
|
|
@@ -5629,8 +6111,7 @@ var Dexie$1 = (function () {
|
|
|
5629
6111
|
}
|
|
5630
6112
|
else {
|
|
5631
6113
|
this._close();
|
|
5632
|
-
state.autoOpen = this._options.autoOpen ||
|
|
5633
|
-
state.isBeingOpened;
|
|
6114
|
+
state.autoOpen = this._options.autoOpen || state.isBeingOpened;
|
|
5634
6115
|
state.openComplete = false;
|
|
5635
6116
|
state.dbOpenError = null;
|
|
5636
6117
|
}
|
|
@@ -5652,7 +6133,7 @@ var Dexie$1 = (function () {
|
|
|
5652
6133
|
req.onblocked = _this._fireOnBlocked;
|
|
5653
6134
|
};
|
|
5654
6135
|
if (hasInvalidArguments)
|
|
5655
|
-
throw new exceptions.InvalidArgument(
|
|
6136
|
+
throw new exceptions.InvalidArgument('Invalid closeOptions argument to db.delete()');
|
|
5656
6137
|
if (state.isBeingOpened) {
|
|
5657
6138
|
state.dbReadyPromise.then(doDelete);
|
|
5658
6139
|
}
|
|
@@ -5669,7 +6150,7 @@ var Dexie$1 = (function () {
|
|
|
5669
6150
|
};
|
|
5670
6151
|
Dexie.prototype.hasBeenClosed = function () {
|
|
5671
6152
|
var dbOpenError = this._state.dbOpenError;
|
|
5672
|
-
return dbOpenError &&
|
|
6153
|
+
return dbOpenError && dbOpenError.name === 'DatabaseClosed';
|
|
5673
6154
|
};
|
|
5674
6155
|
Dexie.prototype.hasFailed = function () {
|
|
5675
6156
|
return this._state.dbOpenError !== null;
|
|
@@ -5692,7 +6173,9 @@ var Dexie$1 = (function () {
|
|
|
5692
6173
|
Dexie.prototype._transaction = function (mode, tables, scopeFunc) {
|
|
5693
6174
|
var _this = this;
|
|
5694
6175
|
var parentTransaction = PSD.trans;
|
|
5695
|
-
if (!parentTransaction ||
|
|
6176
|
+
if (!parentTransaction ||
|
|
6177
|
+
parentTransaction.db !== this ||
|
|
6178
|
+
mode.indexOf('!') !== -1)
|
|
5696
6179
|
parentTransaction = null;
|
|
5697
6180
|
var onlyIfCompatible = mode.indexOf('?') !== -1;
|
|
5698
6181
|
mode = mode.replace('!', '').replace('?', '');
|
|
@@ -5701,51 +6184,56 @@ var Dexie$1 = (function () {
|
|
|
5701
6184
|
storeNames = tables.map(function (table) {
|
|
5702
6185
|
var storeName = table instanceof _this.Table ? table.name : table;
|
|
5703
6186
|
if (typeof storeName !== 'string')
|
|
5704
|
-
throw new TypeError(
|
|
6187
|
+
throw new TypeError('Invalid table argument to Dexie.transaction(). Only Table or String are allowed');
|
|
5705
6188
|
return storeName;
|
|
5706
6189
|
});
|
|
5707
|
-
if (mode ==
|
|
6190
|
+
if (mode == 'r' || mode === READONLY)
|
|
5708
6191
|
idbMode = READONLY;
|
|
5709
|
-
else if (mode ==
|
|
6192
|
+
else if (mode == 'rw' || mode == READWRITE)
|
|
5710
6193
|
idbMode = READWRITE;
|
|
5711
6194
|
else
|
|
5712
|
-
throw new exceptions.InvalidArgument(
|
|
6195
|
+
throw new exceptions.InvalidArgument('Invalid transaction mode: ' + mode);
|
|
5713
6196
|
if (parentTransaction) {
|
|
5714
6197
|
if (parentTransaction.mode === READONLY && idbMode === READWRITE) {
|
|
5715
6198
|
if (onlyIfCompatible) {
|
|
5716
6199
|
parentTransaction = null;
|
|
5717
6200
|
}
|
|
5718
6201
|
else
|
|
5719
|
-
throw new exceptions.SubTransaction(
|
|
6202
|
+
throw new exceptions.SubTransaction('Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY');
|
|
5720
6203
|
}
|
|
5721
6204
|
if (parentTransaction) {
|
|
5722
6205
|
storeNames.forEach(function (storeName) {
|
|
5723
|
-
if (parentTransaction &&
|
|
6206
|
+
if (parentTransaction &&
|
|
6207
|
+
parentTransaction.storeNames.indexOf(storeName) === -1) {
|
|
5724
6208
|
if (onlyIfCompatible) {
|
|
5725
6209
|
parentTransaction = null;
|
|
5726
6210
|
}
|
|
5727
6211
|
else
|
|
5728
|
-
throw new exceptions.SubTransaction(
|
|
5729
|
-
" not included in parent transaction.");
|
|
6212
|
+
throw new exceptions.SubTransaction('Table ' + storeName + ' not included in parent transaction.');
|
|
5730
6213
|
}
|
|
5731
6214
|
});
|
|
5732
6215
|
}
|
|
5733
|
-
if (onlyIfCompatible &&
|
|
6216
|
+
if (onlyIfCompatible &&
|
|
6217
|
+
parentTransaction &&
|
|
6218
|
+
!parentTransaction.active) {
|
|
5734
6219
|
parentTransaction = null;
|
|
5735
6220
|
}
|
|
5736
6221
|
}
|
|
5737
6222
|
}
|
|
5738
6223
|
catch (e) {
|
|
5739
|
-
return parentTransaction
|
|
5740
|
-
parentTransaction._promise(null, function (_, reject) {
|
|
5741
|
-
|
|
6224
|
+
return parentTransaction
|
|
6225
|
+
? parentTransaction._promise(null, function (_, reject) {
|
|
6226
|
+
reject(e);
|
|
6227
|
+
})
|
|
6228
|
+
: rejection(e);
|
|
5742
6229
|
}
|
|
5743
6230
|
var enterTransaction = enterTransactionScope.bind(null, this, idbMode, storeNames, parentTransaction, scopeFunc);
|
|
5744
|
-
return
|
|
5745
|
-
parentTransaction._promise(idbMode, enterTransaction,
|
|
5746
|
-
PSD.trans
|
|
5747
|
-
|
|
5748
|
-
|
|
6231
|
+
return parentTransaction
|
|
6232
|
+
? parentTransaction._promise(idbMode, enterTransaction, 'lock')
|
|
6233
|
+
: PSD.trans
|
|
6234
|
+
?
|
|
6235
|
+
usePSD(PSD.transless, function () { return _this._whenReady(enterTransaction); })
|
|
6236
|
+
: this._whenReady(enterTransaction);
|
|
5749
6237
|
};
|
|
5750
6238
|
Dexie.prototype.table = function (tableName) {
|
|
5751
6239
|
if (!hasOwn(this._allTables, tableName)) {
|
|
@@ -5756,15 +6244,15 @@ var Dexie$1 = (function () {
|
|
|
5756
6244
|
return Dexie;
|
|
5757
6245
|
}());
|
|
5758
6246
|
|
|
5759
|
-
var symbolObservable = typeof Symbol !==
|
|
6247
|
+
var symbolObservable = typeof Symbol !== 'undefined' && 'observable' in Symbol
|
|
5760
6248
|
? Symbol.observable
|
|
5761
|
-
:
|
|
6249
|
+
: '@@observable';
|
|
5762
6250
|
var Observable = (function () {
|
|
5763
6251
|
function Observable(subscribe) {
|
|
5764
6252
|
this._subscribe = subscribe;
|
|
5765
6253
|
}
|
|
5766
6254
|
Observable.prototype.subscribe = function (x, error, complete) {
|
|
5767
|
-
return this._subscribe(!x || typeof x ===
|
|
6255
|
+
return this._subscribe(!x || typeof x === 'function' ? { next: x, error: error, complete: complete } : x);
|
|
5768
6256
|
};
|
|
5769
6257
|
Observable.prototype[symbolObservable] = function () {
|
|
5770
6258
|
return this;
|
|
@@ -5775,8 +6263,11 @@ var Observable = (function () {
|
|
|
5775
6263
|
var domDeps;
|
|
5776
6264
|
try {
|
|
5777
6265
|
domDeps = {
|
|
5778
|
-
indexedDB: _global.indexedDB ||
|
|
5779
|
-
|
|
6266
|
+
indexedDB: _global.indexedDB ||
|
|
6267
|
+
_global.mozIndexedDB ||
|
|
6268
|
+
_global.webkitIndexedDB ||
|
|
6269
|
+
_global.msIndexedDB,
|
|
6270
|
+
IDBKeyRange: _global.IDBKeyRange || _global.webkitIDBKeyRange,
|
|
5780
6271
|
};
|
|
5781
6272
|
}
|
|
5782
6273
|
catch (e) {
|
|
@@ -5903,10 +6394,13 @@ props(Dexie, __assign(__assign({}, fullNameExceptions), {
|
|
|
5903
6394
|
return db.delete();
|
|
5904
6395
|
},
|
|
5905
6396
|
exists: function (name) {
|
|
5906
|
-
return new Dexie(name, { addons: [] })
|
|
6397
|
+
return new Dexie(name, { addons: [] })
|
|
6398
|
+
.open()
|
|
6399
|
+
.then(function (db) {
|
|
5907
6400
|
db.close();
|
|
5908
6401
|
return true;
|
|
5909
|
-
})
|
|
6402
|
+
})
|
|
6403
|
+
.catch('NoSuchDatabaseError', function () { return false; });
|
|
5910
6404
|
},
|
|
5911
6405
|
getDatabaseNames: function (cb) {
|
|
5912
6406
|
try {
|
|
@@ -5922,9 +6416,9 @@ props(Dexie, __assign(__assign({}, fullNameExceptions), {
|
|
|
5922
6416
|
}
|
|
5923
6417
|
return Class;
|
|
5924
6418
|
}, ignoreTransaction: function (scopeFunc) {
|
|
5925
|
-
return PSD.trans
|
|
5926
|
-
usePSD(PSD.transless, scopeFunc)
|
|
5927
|
-
scopeFunc();
|
|
6419
|
+
return PSD.trans
|
|
6420
|
+
? usePSD(PSD.transless || globalPSD, scopeFunc)
|
|
6421
|
+
: scopeFunc();
|
|
5928
6422
|
}, vip: vip, async: function (generatorFn) {
|
|
5929
6423
|
return function () {
|
|
5930
6424
|
try {
|
|
@@ -5949,22 +6443,19 @@ props(Dexie, __assign(__assign({}, fullNameExceptions), {
|
|
|
5949
6443
|
}
|
|
5950
6444
|
},
|
|
5951
6445
|
currentTransaction: {
|
|
5952
|
-
get: function () { return PSD.trans || null; }
|
|
6446
|
+
get: function () { return PSD.trans || null; },
|
|
5953
6447
|
}, 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;
|
|
6448
|
+
var promise = DexiePromise.resolve(typeof promiseOrFunction === 'function'
|
|
6449
|
+
? Dexie.ignoreTransaction(promiseOrFunction)
|
|
6450
|
+
: promiseOrFunction).timeout(optionalTimeout || 60000);
|
|
6451
|
+
return PSD.trans ? PSD.trans.waitFor(promise) : promise;
|
|
5961
6452
|
},
|
|
5962
6453
|
Promise: DexiePromise,
|
|
5963
6454
|
debug: {
|
|
5964
6455
|
get: function () { return debug; },
|
|
5965
6456
|
set: function (value) {
|
|
5966
6457
|
setDebug(value);
|
|
5967
|
-
}
|
|
6458
|
+
},
|
|
5968
6459
|
},
|
|
5969
6460
|
derive: derive, extend: extend, props: props, override: override,
|
|
5970
6461
|
Events: Events, on: globalEvents, liveQuery: liveQuery, extendObservabilitySet: extendObservabilitySet,
|
|
@@ -5972,21 +6463,22 @@ props(Dexie, __assign(__assign({}, fullNameExceptions), {
|
|
|
5972
6463
|
minKey: minKey,
|
|
5973
6464
|
addons: [],
|
|
5974
6465
|
connections: {
|
|
5975
|
-
get: connections.toArray
|
|
6466
|
+
get: connections.toArray,
|
|
5976
6467
|
},
|
|
5977
6468
|
errnames: errnames,
|
|
5978
6469
|
dependencies: domDeps, cache: cache,
|
|
5979
6470
|
semVer: DEXIE_VERSION, version: DEXIE_VERSION.split('.')
|
|
5980
6471
|
.map(function (n) { return parseInt(n); })
|
|
5981
|
-
.reduce(function (p, c, i) { return p +
|
|
6472
|
+
.reduce(function (p, c, i) { return p + c / Math.pow(10, i * 2); }) }));
|
|
5982
6473
|
Dexie.maxKey = getMaxKey(Dexie.dependencies.IDBKeyRange);
|
|
5983
6474
|
|
|
5984
|
-
if (typeof dispatchEvent !== 'undefined' &&
|
|
6475
|
+
if (typeof dispatchEvent !== 'undefined' &&
|
|
6476
|
+
typeof addEventListener !== 'undefined') {
|
|
5985
6477
|
globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, function (updatedParts) {
|
|
5986
6478
|
if (!propagatingLocally) {
|
|
5987
6479
|
var event_1;
|
|
5988
6480
|
event_1 = new CustomEvent(STORAGE_MUTATED_DOM_EVENT_NAME, {
|
|
5989
|
-
detail: updatedParts
|
|
6481
|
+
detail: updatedParts,
|
|
5990
6482
|
});
|
|
5991
6483
|
propagatingLocally = true;
|
|
5992
6484
|
dispatchEvent(event_1);
|