dexie 4.0.1-beta.9 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SECURITY.md +1 -1
- package/dist/dexie.d.ts +23 -3
- package/dist/dexie.js +82 -56
- 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 +80 -57
- 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 +77 -57
- package/dist/modern/dexie.mjs.map +1 -1
- package/import-wrapper-prod.mjs +2 -2
- package/import-wrapper.mjs +2 -2
- package/package.json +1 -1
package/SECURITY.md
CHANGED
package/dist/dexie.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* By David Fahlander, david.fahlander@gmail.com
|
|
6
6
|
*
|
|
7
|
-
* Version 4.0.1
|
|
7
|
+
* Version 4.0.1, Tue Mar 26 2024
|
|
8
8
|
*
|
|
9
9
|
* https://dexie.org
|
|
10
10
|
*
|
|
@@ -363,8 +363,24 @@ export type KeyPaths<T> = {
|
|
|
363
363
|
? never : T[P] extends object ? P | `${P}.${KeyPaths<T[P]>}` : P : never;
|
|
364
364
|
}[keyof T];
|
|
365
365
|
export type KeyPathValue<T, PATH> = PATH extends `${infer R}.${infer S}` ? R extends keyof T ? KeyPathValue<T[R], S> : T extends any[] ? PATH extends `${number}.${infer S}` ? KeyPathValue<T[number], S> : void : void : PATH extends `${number}` ? T extends any[] ? T[number] : void : PATH extends keyof T ? T[PATH] : void;
|
|
366
|
+
export declare const PropModSymbol: unique symbol;
|
|
367
|
+
export type PropModSpec = {
|
|
368
|
+
replacePrefix?: [
|
|
369
|
+
string,
|
|
370
|
+
string
|
|
371
|
+
];
|
|
372
|
+
};
|
|
373
|
+
export class PropModification implements PropModSpec {
|
|
374
|
+
[PropModSymbol]?: true;
|
|
375
|
+
replacePrefix?: [
|
|
376
|
+
string,
|
|
377
|
+
string
|
|
378
|
+
];
|
|
379
|
+
execute<T>(value: T): T;
|
|
380
|
+
constructor(spec: PropModSpec);
|
|
381
|
+
}
|
|
366
382
|
export type UpdateSpec<T> = {
|
|
367
|
-
[KP in KeyPaths<T>]?: KeyPathValue<T, KP
|
|
383
|
+
[KP in KeyPaths<T>]?: KeyPathValue<T, KP> | PropModification;
|
|
368
384
|
};
|
|
369
385
|
export interface Collection<T = any, TKey = IndexableType, TInsertType = T> {
|
|
370
386
|
db: Dexie;
|
|
@@ -804,7 +820,9 @@ export interface Dexie {
|
|
|
804
820
|
close(closeOptions?: {
|
|
805
821
|
disableAutoOpen: boolean;
|
|
806
822
|
}): void;
|
|
807
|
-
delete(
|
|
823
|
+
delete(closeOptions?: {
|
|
824
|
+
disableAutoOpen: boolean;
|
|
825
|
+
}): PromiseExtended<void>;
|
|
808
826
|
isOpen(): boolean;
|
|
809
827
|
hasBeenClosed(): boolean;
|
|
810
828
|
hasFailed(): boolean;
|
|
@@ -1068,6 +1086,7 @@ export interface DexieConstructor extends DexieExceptionClasses {
|
|
|
1068
1086
|
getDatabaseNames<R>(thenShortcut: ThenShortcut<string[], R>): Promise<R>;
|
|
1069
1087
|
vip<U>(scopeFunction: () => U): U;
|
|
1070
1088
|
ignoreTransaction<U>(fn: () => U): U;
|
|
1089
|
+
disableBfCache?: boolean;
|
|
1071
1090
|
liveQuery<T>(fn: () => T | Promise<T>): Observable<T>;
|
|
1072
1091
|
extendObservabilitySet(target: ObservabilitySet, newSet: ObservabilitySet): ObservabilitySet;
|
|
1073
1092
|
override<F>(origFunc: F, overridedFactory: (fn: any) => any): F; // ?
|
|
@@ -1137,6 +1156,7 @@ export function liveQuery<T>(querier: () => T | Promise<T>): Observable<T>;
|
|
|
1137
1156
|
export function mergeRanges(target: IntervalTree, newSet: IntervalTree): void;
|
|
1138
1157
|
export function rangesOverlap(rangeSet1: IntervalTree, rangeSet2: IntervalTree): boolean;
|
|
1139
1158
|
export function cmp(a: any, b: any): number;
|
|
1159
|
+
export function replacePrefix(a: string, b: string): PropModification;
|
|
1140
1160
|
/** Exporting 'Dexie' as the default export.
|
|
1141
1161
|
**/
|
|
1142
1162
|
export default Dexie;
|
package/dist/dexie.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* By David Fahlander, david.fahlander@gmail.com
|
|
6
6
|
*
|
|
7
|
-
* Version 4.0.1
|
|
7
|
+
* Version 4.0.1, Tue Mar 26 2024
|
|
8
8
|
*
|
|
9
9
|
* https://dexie.org
|
|
10
10
|
*
|
|
@@ -156,7 +156,7 @@
|
|
|
156
156
|
var period = keyPath.indexOf('.');
|
|
157
157
|
if (period !== -1) {
|
|
158
158
|
var innerObj = obj[keyPath.substr(0, period)];
|
|
159
|
-
return innerObj
|
|
159
|
+
return innerObj == null ? undefined : getByKeyPath(innerObj, keyPath.substr(period + 1));
|
|
160
160
|
}
|
|
161
161
|
return undefined;
|
|
162
162
|
}
|
|
@@ -1129,7 +1129,7 @@
|
|
|
1129
1129
|
catch (ex) {
|
|
1130
1130
|
if (ex.name === errnames.InvalidState && db.isOpen() && --db._state.PR1398_maxLoop > 0) {
|
|
1131
1131
|
console.warn('Dexie: Need to reopen db');
|
|
1132
|
-
db.
|
|
1132
|
+
db.close({ disableAutoOpen: false });
|
|
1133
1133
|
return db.open().then(function () { return tempTransaction(db, mode, storeNames, fn); });
|
|
1134
1134
|
}
|
|
1135
1135
|
return rejection(ex);
|
|
@@ -1150,15 +1150,12 @@
|
|
|
1150
1150
|
}
|
|
1151
1151
|
}
|
|
1152
1152
|
|
|
1153
|
-
var DEXIE_VERSION = '4.0.1
|
|
1153
|
+
var DEXIE_VERSION = '4.0.1';
|
|
1154
1154
|
var maxString = String.fromCharCode(65535);
|
|
1155
1155
|
var minKey = -Infinity;
|
|
1156
1156
|
var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
|
|
1157
1157
|
var STRING_EXPECTED = "String expected.";
|
|
1158
1158
|
var connections = [];
|
|
1159
|
-
var isIEOrEdge = typeof navigator !== 'undefined' && /(MSIE|Trident|Edge)/.test(navigator.userAgent);
|
|
1160
|
-
var hasIEDeleteObjectStoreBug = isIEOrEdge;
|
|
1161
|
-
var hangsOnDeleteLargeKeyRange = isIEOrEdge;
|
|
1162
1159
|
var DBNAMES_DB = '__dbnames';
|
|
1163
1160
|
var READONLY = 'readonly';
|
|
1164
1161
|
var READWRITE = 'readwrite';
|
|
@@ -1806,6 +1803,22 @@
|
|
|
1806
1803
|
});
|
|
1807
1804
|
}
|
|
1808
1805
|
|
|
1806
|
+
var PropModSymbol = Symbol();
|
|
1807
|
+
var PropModification = (function () {
|
|
1808
|
+
function PropModification(spec) {
|
|
1809
|
+
Object.assign(this, spec);
|
|
1810
|
+
}
|
|
1811
|
+
PropModification.prototype.execute = function (value) {
|
|
1812
|
+
var _a;
|
|
1813
|
+
var prefixToReplace = (_a = this.replacePrefix) === null || _a === void 0 ? void 0 : _a[0];
|
|
1814
|
+
if (prefixToReplace && typeof value === 'string' && value.startsWith(prefixToReplace)) {
|
|
1815
|
+
return this.replacePrefix[1] + value.substring(prefixToReplace.length);
|
|
1816
|
+
}
|
|
1817
|
+
return value;
|
|
1818
|
+
};
|
|
1819
|
+
return PropModification;
|
|
1820
|
+
}());
|
|
1821
|
+
|
|
1809
1822
|
var Collection = (function () {
|
|
1810
1823
|
function Collection() {
|
|
1811
1824
|
}
|
|
@@ -2077,8 +2090,14 @@
|
|
|
2077
2090
|
modifyer = function (item) {
|
|
2078
2091
|
var anythingModified = false;
|
|
2079
2092
|
for (var i = 0; i < numKeys; ++i) {
|
|
2080
|
-
var keyPath = keyPaths[i]
|
|
2081
|
-
|
|
2093
|
+
var keyPath = keyPaths[i];
|
|
2094
|
+
var val = changes[keyPath];
|
|
2095
|
+
var origVal = getByKeyPath(item, keyPath);
|
|
2096
|
+
if (val instanceof PropModification) {
|
|
2097
|
+
setByKeyPath(item, keyPath, val.execute(origVal));
|
|
2098
|
+
anythingModified = true;
|
|
2099
|
+
}
|
|
2100
|
+
else if (origVal !== val) {
|
|
2082
2101
|
setByKeyPath(item, keyPath, val);
|
|
2083
2102
|
anythingModified = true;
|
|
2084
2103
|
}
|
|
@@ -2177,7 +2196,7 @@
|
|
|
2177
2196
|
Collection.prototype.delete = function () {
|
|
2178
2197
|
var ctx = this._ctx, range = ctx.range;
|
|
2179
2198
|
if (isPlainKeyRange(ctx) &&
|
|
2180
|
-
(
|
|
2199
|
+
(ctx.isPrimKey || range.type === 3 ))
|
|
2181
2200
|
{
|
|
2182
2201
|
return this._write(function (trans) {
|
|
2183
2202
|
var primaryKey = ctx.table.core.schema.primaryKey;
|
|
@@ -3367,7 +3386,6 @@
|
|
|
3367
3386
|
var queue = [];
|
|
3368
3387
|
var versions = db._versions;
|
|
3369
3388
|
var globalSchema = db._dbSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
|
|
3370
|
-
var anyContentUpgraderHasRun = false;
|
|
3371
3389
|
var versToRun = versions.filter(function (v) { return v._cfg.version >= oldVersion; });
|
|
3372
3390
|
if (versToRun.length === 0) {
|
|
3373
3391
|
return DexiePromise.resolve();
|
|
@@ -3401,7 +3419,6 @@
|
|
|
3401
3419
|
if (contentUpgrade && version._cfg.version > oldVersion) {
|
|
3402
3420
|
generateMiddlewareStacks(db, idbUpgradeTrans);
|
|
3403
3421
|
trans._memoizedTables = {};
|
|
3404
|
-
anyContentUpgraderHasRun = true;
|
|
3405
3422
|
var upgradeSchema_1 = shallowClone(newSchema);
|
|
3406
3423
|
diff.del.forEach(function (table) {
|
|
3407
3424
|
upgradeSchema_1[table] = oldSchema[table];
|
|
@@ -3428,10 +3445,8 @@
|
|
|
3428
3445
|
}
|
|
3429
3446
|
});
|
|
3430
3447
|
queue.push(function (idbtrans) {
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
deleteRemovedTables(newSchema, idbtrans);
|
|
3434
|
-
}
|
|
3448
|
+
var newSchema = version._cfg.dbschema;
|
|
3449
|
+
deleteRemovedTables(newSchema, idbtrans);
|
|
3435
3450
|
removeTablesApi(db, [db.Transaction.prototype]);
|
|
3436
3451
|
setApiOnPlace(db, [db.Transaction.prototype], db._storeNames, db._dbSchema);
|
|
3437
3452
|
trans.schema = db._dbSchema;
|
|
@@ -3484,8 +3499,7 @@
|
|
|
3484
3499
|
};
|
|
3485
3500
|
if ((
|
|
3486
3501
|
'' + (oldDef.primKey.keyPath || '')) !== ('' + (newDef.primKey.keyPath || '')) ||
|
|
3487
|
-
(oldDef.primKey.auto !== newDef.primKey.auto
|
|
3488
|
-
{
|
|
3502
|
+
(oldDef.primKey.auto !== newDef.primKey.auto)) {
|
|
3489
3503
|
change.recreate = true;
|
|
3490
3504
|
diff.change.push(change);
|
|
3491
3505
|
}
|
|
@@ -4159,7 +4173,7 @@
|
|
|
4159
4173
|
catch (ex) {
|
|
4160
4174
|
if (ex.name === errnames.InvalidState && db.isOpen() && --db._state.PR1398_maxLoop > 0) {
|
|
4161
4175
|
console.warn('Dexie: Need to reopen db');
|
|
4162
|
-
db.
|
|
4176
|
+
db.close({ disableAutoOpen: false });
|
|
4163
4177
|
return db.open().then(function () { return enterTransactionScope(db, mode, storeNames, null, scopeFunc); });
|
|
4164
4178
|
}
|
|
4165
4179
|
return rejection(ex);
|
|
@@ -5252,7 +5266,6 @@
|
|
|
5252
5266
|
else
|
|
5253
5267
|
console.warn("Another connection wants to delete database '".concat(_this.name, "'. Closing db now to resume the delete request."));
|
|
5254
5268
|
_this.close({ disableAutoOpen: false });
|
|
5255
|
-
_this._state.openComplete = false;
|
|
5256
5269
|
});
|
|
5257
5270
|
this.on("blocked", function (ev) {
|
|
5258
5271
|
if (!ev.newVersion || ev.newVersion < ev.oldVersion)
|
|
@@ -5366,34 +5379,42 @@
|
|
|
5366
5379
|
catch (e) { }
|
|
5367
5380
|
this.idbdb = null;
|
|
5368
5381
|
}
|
|
5369
|
-
state.
|
|
5370
|
-
state.
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
state.
|
|
5374
|
-
|
|
5382
|
+
if (!state.isBeingOpened) {
|
|
5383
|
+
state.dbReadyPromise = new DexiePromise(function (resolve) {
|
|
5384
|
+
state.dbReadyResolve = resolve;
|
|
5385
|
+
});
|
|
5386
|
+
state.openCanceller = new DexiePromise(function (_, reject) {
|
|
5387
|
+
state.cancelOpen = reject;
|
|
5388
|
+
});
|
|
5389
|
+
}
|
|
5375
5390
|
};
|
|
5376
5391
|
Dexie.prototype.close = function (_a) {
|
|
5377
5392
|
var _b = _a === void 0 ? { disableAutoOpen: true } : _a, disableAutoOpen = _b.disableAutoOpen;
|
|
5378
|
-
var wasOpen = this.isOpen();
|
|
5379
|
-
this._close();
|
|
5380
5393
|
var state = this._state;
|
|
5381
|
-
if (disableAutoOpen)
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5394
|
+
if (disableAutoOpen) {
|
|
5395
|
+
if (state.isBeingOpened) {
|
|
5396
|
+
state.cancelOpen(new exceptions.DatabaseClosed());
|
|
5397
|
+
}
|
|
5398
|
+
this._close();
|
|
5399
|
+
state.autoOpen = false;
|
|
5400
|
+
state.dbOpenError = new exceptions.DatabaseClosed();
|
|
5401
|
+
}
|
|
5402
|
+
else {
|
|
5403
|
+
this._close();
|
|
5404
|
+
state.autoOpen = this._options.autoOpen ||
|
|
5405
|
+
state.isBeingOpened;
|
|
5406
|
+
state.openComplete = false;
|
|
5407
|
+
state.dbOpenError = null;
|
|
5408
|
+
}
|
|
5389
5409
|
};
|
|
5390
|
-
Dexie.prototype.delete = function () {
|
|
5410
|
+
Dexie.prototype.delete = function (closeOptions) {
|
|
5391
5411
|
var _this = this;
|
|
5392
|
-
|
|
5412
|
+
if (closeOptions === void 0) { closeOptions = { disableAutoOpen: true }; }
|
|
5413
|
+
var hasInvalidArguments = arguments.length > 0 && typeof arguments[0] !== 'object';
|
|
5393
5414
|
var state = this._state;
|
|
5394
5415
|
return new DexiePromise(function (resolve, reject) {
|
|
5395
5416
|
var doDelete = function () {
|
|
5396
|
-
_this.close(
|
|
5417
|
+
_this.close(closeOptions);
|
|
5397
5418
|
var req = _this._deps.indexedDB.deleteDatabase(_this.name);
|
|
5398
5419
|
req.onsuccess = wrap(function () {
|
|
5399
5420
|
_onDatabaseDeleted(_this._deps, _this.name);
|
|
@@ -5402,8 +5423,8 @@
|
|
|
5402
5423
|
req.onerror = eventRejectHandler(reject);
|
|
5403
5424
|
req.onblocked = _this._fireOnBlocked;
|
|
5404
5425
|
};
|
|
5405
|
-
if (
|
|
5406
|
-
throw new exceptions.InvalidArgument("
|
|
5426
|
+
if (hasInvalidArguments)
|
|
5427
|
+
throw new exceptions.InvalidArgument("Invalid closeOptions argument to db.delete()");
|
|
5407
5428
|
if (state.isBeingOpened) {
|
|
5408
5429
|
state.dbReadyPromise.then(doDelete);
|
|
5409
5430
|
}
|
|
@@ -5724,15 +5745,9 @@
|
|
|
5724
5745
|
globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, function (updatedParts) {
|
|
5725
5746
|
if (!propagatingLocally) {
|
|
5726
5747
|
var event_1;
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
}
|
|
5731
|
-
else {
|
|
5732
|
-
event_1 = new CustomEvent(STORAGE_MUTATED_DOM_EVENT_NAME, {
|
|
5733
|
-
detail: updatedParts
|
|
5734
|
-
});
|
|
5735
|
-
}
|
|
5748
|
+
event_1 = new CustomEvent(STORAGE_MUTATED_DOM_EVENT_NAME, {
|
|
5749
|
+
detail: updatedParts
|
|
5750
|
+
});
|
|
5736
5751
|
propagatingLocally = true;
|
|
5737
5752
|
dispatchEvent(event_1);
|
|
5738
5753
|
propagatingLocally = false;
|
|
@@ -5778,22 +5793,30 @@
|
|
|
5778
5793
|
|
|
5779
5794
|
if (typeof addEventListener !== 'undefined') {
|
|
5780
5795
|
addEventListener('pagehide', function (event) {
|
|
5781
|
-
if (event.persisted) {
|
|
5796
|
+
if (!Dexie$1.disableBfCache && event.persisted) {
|
|
5797
|
+
if (debug)
|
|
5798
|
+
console.debug('Dexie: handling persisted pagehide');
|
|
5782
5799
|
bc === null || bc === void 0 ? void 0 : bc.close();
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5800
|
+
for (var _i = 0, connections_1 = connections; _i < connections_1.length; _i++) {
|
|
5801
|
+
var db = connections_1[_i];
|
|
5802
|
+
db.close({ disableAutoOpen: false });
|
|
5803
|
+
}
|
|
5787
5804
|
}
|
|
5788
5805
|
});
|
|
5789
5806
|
addEventListener('pageshow', function (event) {
|
|
5790
|
-
if (event.persisted) {
|
|
5807
|
+
if (!Dexie$1.disableBfCache && event.persisted) {
|
|
5808
|
+
if (debug)
|
|
5809
|
+
console.debug('Dexie: handling persisted pageshow');
|
|
5791
5810
|
createBC();
|
|
5792
5811
|
propagateLocally({ all: new RangeSet(-Infinity, [[]]) });
|
|
5793
5812
|
}
|
|
5794
5813
|
});
|
|
5795
5814
|
}
|
|
5796
5815
|
|
|
5816
|
+
function replacePrefix(a, b) {
|
|
5817
|
+
return new PropModification({ replacePrefix: [a, b] });
|
|
5818
|
+
}
|
|
5819
|
+
|
|
5797
5820
|
DexiePromise.rejectionMapper = mapError;
|
|
5798
5821
|
setDebug(debug);
|
|
5799
5822
|
|
|
@@ -5803,6 +5826,9 @@
|
|
|
5803
5826
|
liveQuery: liveQuery,
|
|
5804
5827
|
Entity: Entity,
|
|
5805
5828
|
cmp: cmp,
|
|
5829
|
+
PropModSymbol: PropModSymbol,
|
|
5830
|
+
PropModification: PropModification,
|
|
5831
|
+
replacePrefix: replacePrefix,
|
|
5806
5832
|
'default': Dexie$1,
|
|
5807
5833
|
RangeSet: RangeSet,
|
|
5808
5834
|
mergeRanges: mergeRanges,
|