dexie 3.0.0-rc.5 → 3.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/dist/dexie.d.ts +44 -49
- package/dist/dexie.js +59 -50
- 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 +59 -50
- package/dist/dexie.mjs.map +1 -1
- package/package.json +7 -7
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 3.0.
|
|
7
|
+
* Version 3.0.1, Thu May 07 2020
|
|
8
8
|
*
|
|
9
9
|
* http://dexie.org
|
|
10
10
|
*
|
|
@@ -215,18 +215,17 @@ export interface TableHooks<T=any,TKey=IndexableType> extends DexieEventSet {
|
|
|
215
215
|
updating: DexieEvent;
|
|
216
216
|
deleting: DexieEvent;
|
|
217
217
|
}
|
|
218
|
-
export
|
|
219
|
-
export const enum RangeType {
|
|
218
|
+
export const enum DBCoreRangeType {
|
|
220
219
|
Equal = 1,
|
|
221
220
|
Range = 2,
|
|
222
221
|
Any = 3,
|
|
223
222
|
Never = 4
|
|
224
223
|
}
|
|
225
|
-
export interface
|
|
226
|
-
readonly type:
|
|
227
|
-
readonly lower:
|
|
224
|
+
export interface DBCoreKeyRange {
|
|
225
|
+
readonly type: DBCoreRangeType;
|
|
226
|
+
readonly lower: any;
|
|
228
227
|
readonly lowerOpen?: boolean;
|
|
229
|
-
readonly upper:
|
|
228
|
+
readonly upper: any;
|
|
230
229
|
readonly upperOpen?: boolean;
|
|
231
230
|
//includes (key: Key) : boolean; Despite IDBKeyRange api - it's no good to have this as a method. Benefit from using a more functional approach.
|
|
232
231
|
}
|
|
@@ -235,83 +234,82 @@ export interface DBCoreTransaction {
|
|
|
235
234
|
}
|
|
236
235
|
export interface DBCoreTransactionRequest {
|
|
237
236
|
tables: string[];
|
|
238
|
-
mode:
|
|
237
|
+
mode: 'readonly' | 'readwrite';
|
|
239
238
|
}
|
|
240
|
-
export type
|
|
241
|
-
export
|
|
242
|
-
export interface MutateResponse {
|
|
239
|
+
export type DBCoreMutateRequest = DBCoreAddRequest | DBCorePutRequest | DBCoreDeleteRequest | DBCoreDeleteRangeRequest;
|
|
240
|
+
export interface DBCoreMutateResponse {
|
|
243
241
|
numFailures: number,
|
|
244
242
|
failures: {[operationNumber: number]: Error};
|
|
245
|
-
lastResult:
|
|
246
|
-
results?:
|
|
243
|
+
lastResult: any;
|
|
244
|
+
results?: any[]; // Present on AddRequest and PutRequest if request.wantResults is truthy.
|
|
247
245
|
}
|
|
248
|
-
export interface
|
|
246
|
+
export interface DBCoreAddRequest {
|
|
249
247
|
type: 'add';
|
|
250
248
|
trans: DBCoreTransaction;
|
|
251
249
|
values: any[];
|
|
252
|
-
keys?:
|
|
250
|
+
keys?: any[];
|
|
253
251
|
wantResults?: boolean;
|
|
254
252
|
}
|
|
255
|
-
export interface
|
|
253
|
+
export interface DBCorePutRequest {
|
|
256
254
|
type: 'put';
|
|
257
255
|
trans: DBCoreTransaction;
|
|
258
256
|
values: any[];
|
|
259
|
-
keys?:
|
|
257
|
+
keys?: any[];
|
|
260
258
|
wantResults?: boolean;
|
|
261
259
|
}
|
|
262
|
-
export interface
|
|
260
|
+
export interface DBCoreDeleteRequest {
|
|
263
261
|
type: 'delete';
|
|
264
262
|
trans: DBCoreTransaction;
|
|
265
|
-
keys:
|
|
263
|
+
keys: any[];
|
|
266
264
|
}
|
|
267
|
-
export interface
|
|
265
|
+
export interface DBCoreDeleteRangeRequest {
|
|
268
266
|
type: 'deleteRange';
|
|
269
267
|
trans: DBCoreTransaction;
|
|
270
|
-
range:
|
|
268
|
+
range: DBCoreKeyRange;
|
|
271
269
|
}
|
|
272
270
|
export interface DBCoreGetManyRequest {
|
|
273
271
|
trans: DBCoreTransaction;
|
|
274
|
-
keys:
|
|
272
|
+
keys: any[];
|
|
275
273
|
}
|
|
276
274
|
export interface DBCoreGetRequest {
|
|
277
275
|
trans: DBCoreTransaction;
|
|
278
|
-
key:
|
|
276
|
+
key: any;
|
|
279
277
|
}
|
|
280
278
|
export interface DBCoreQuery {
|
|
281
279
|
index: DBCoreIndex;//keyPath: null | string | string[]; // null represents primary key. string a property, string[] several properties.
|
|
282
|
-
range:
|
|
280
|
+
range: DBCoreKeyRange;
|
|
283
281
|
}
|
|
284
|
-
export interface DBCoreQueryRequest
|
|
282
|
+
export interface DBCoreQueryRequest {
|
|
285
283
|
trans: DBCoreTransaction;
|
|
286
284
|
values?: boolean;
|
|
287
285
|
limit?: number;
|
|
288
|
-
query:
|
|
286
|
+
query: DBCoreQuery;
|
|
289
287
|
}
|
|
290
288
|
export interface DBCoreQueryResponse {
|
|
291
289
|
result: any[];
|
|
292
290
|
}
|
|
293
|
-
export interface DBCoreOpenCursorRequest
|
|
291
|
+
export interface DBCoreOpenCursorRequest {
|
|
294
292
|
trans: DBCoreTransaction;
|
|
295
293
|
values?: boolean;
|
|
296
294
|
unique?: boolean;
|
|
297
295
|
reverse?: boolean;
|
|
298
|
-
query:
|
|
296
|
+
query: DBCoreQuery;
|
|
299
297
|
}
|
|
300
|
-
export interface DBCoreCountRequest
|
|
298
|
+
export interface DBCoreCountRequest {
|
|
301
299
|
trans: DBCoreTransaction;
|
|
302
|
-
query:
|
|
300
|
+
query: DBCoreQuery;
|
|
303
301
|
}
|
|
304
|
-
export interface DBCoreCursor
|
|
302
|
+
export interface DBCoreCursor {
|
|
305
303
|
readonly trans: DBCoreTransaction;
|
|
306
|
-
readonly key:
|
|
307
|
-
readonly primaryKey:
|
|
304
|
+
readonly key: any;
|
|
305
|
+
readonly primaryKey: any;
|
|
308
306
|
readonly value?: any;
|
|
309
307
|
readonly done?: boolean;
|
|
310
308
|
continue(key?: any): void;
|
|
311
|
-
continuePrimaryKey(key:
|
|
309
|
+
continuePrimaryKey(key: any, primaryKey: any): void;
|
|
312
310
|
advance(count: number): void;
|
|
313
|
-
start(onNext: ()=>void): Promise<
|
|
314
|
-
stop(value?:
|
|
311
|
+
start(onNext: ()=>void): Promise<any>
|
|
312
|
+
stop(value?: any | Promise<any>): void;
|
|
315
313
|
next(): Promise<DBCoreCursor>;
|
|
316
314
|
fail(error: Error): void;
|
|
317
315
|
}
|
|
@@ -343,33 +341,30 @@ export interface DBCoreIndex {
|
|
|
343
341
|
/** Whether index is multiEntry. */
|
|
344
342
|
readonly multiEntry?: boolean;
|
|
345
343
|
/** Extract (using keyPath) a key from given value (object) */
|
|
346
|
-
readonly extractKey: (value: any) =>
|
|
344
|
+
readonly extractKey: (value: any) => any;
|
|
347
345
|
}
|
|
348
|
-
export interface DBCore
|
|
346
|
+
export interface DBCore {
|
|
349
347
|
stack: "dbcore";
|
|
350
348
|
// Transaction and Object Store
|
|
351
349
|
transaction(req: DBCoreTransactionRequest): DBCoreTransaction;
|
|
352
350
|
|
|
353
351
|
// Utility methods
|
|
354
352
|
cmp(a: any, b: any) : number;
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
//readonly schema: DBCoreSchema;
|
|
358
|
-
readonly MIN_KEY: Key;
|
|
359
|
-
readonly MAX_KEY: Key;
|
|
353
|
+
readonly MIN_KEY: any;
|
|
354
|
+
readonly MAX_KEY: any;
|
|
360
355
|
readonly schema: DBCoreSchema;
|
|
361
|
-
table(name: string): DBCoreTable
|
|
356
|
+
table(name: string): DBCoreTable;
|
|
362
357
|
}
|
|
363
|
-
export interface DBCoreTable
|
|
358
|
+
export interface DBCoreTable {
|
|
364
359
|
readonly name: string;
|
|
365
360
|
readonly schema: DBCoreTableSchema;
|
|
366
361
|
|
|
367
|
-
mutate(req:
|
|
362
|
+
mutate(req: DBCoreMutateRequest): Promise<DBCoreMutateResponse>;
|
|
368
363
|
get(req: DBCoreGetRequest): Promise<any>;
|
|
369
364
|
getMany(req: DBCoreGetManyRequest): Promise<any[]>;
|
|
370
|
-
query(req: DBCoreQueryRequest
|
|
371
|
-
openCursor(req: DBCoreOpenCursorRequest
|
|
372
|
-
count(req: DBCoreCountRequest
|
|
365
|
+
query(req: DBCoreQueryRequest): Promise<DBCoreQueryResponse>;
|
|
366
|
+
openCursor(req: DBCoreOpenCursorRequest): Promise<DBCoreCursor | null>;
|
|
367
|
+
count(req: DBCoreCountRequest): Promise<number>;
|
|
373
368
|
}
|
|
374
369
|
export interface Table<T=any, TKey=IndexableType> {
|
|
375
370
|
db: Database;
|
package/dist/dexie.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* By David Fahlander, david.fahlander@gmail.com
|
|
6
6
|
*
|
|
7
|
-
* Version 3.0.
|
|
7
|
+
* Version 3.0.1, Thu May 07 2020
|
|
8
8
|
*
|
|
9
9
|
* http://dexie.org
|
|
10
10
|
*
|
|
@@ -805,31 +805,6 @@ props(DexiePromise, {
|
|
|
805
805
|
values.map(function (value) { return DexiePromise.resolve(value).then(resolve, reject); });
|
|
806
806
|
});
|
|
807
807
|
},
|
|
808
|
-
allSettled: function () {
|
|
809
|
-
var possiblePromises = getArrayOf.apply(null, arguments).map(onPossibleParallellAsync);
|
|
810
|
-
return new DexiePromise(function (resolve) {
|
|
811
|
-
if (possiblePromises.length === 0)
|
|
812
|
-
resolve([]);
|
|
813
|
-
var remaining = possiblePromises.length;
|
|
814
|
-
var results = new Array(remaining);
|
|
815
|
-
possiblePromises.forEach(function (p, i) { return DexiePromise.resolve(p).then(function (value) { return results[i] = { status: "fulfilled", value: value }; }, function (reason) { return results[i] = { status: "rejected", reason: reason }; })
|
|
816
|
-
.then(function () { return --remaining || resolve(results); }); });
|
|
817
|
-
});
|
|
818
|
-
},
|
|
819
|
-
any: function () {
|
|
820
|
-
var possiblePromises = getArrayOf.apply(null, arguments).map(onPossibleParallellAsync);
|
|
821
|
-
return new DexiePromise(function (resolve, reject) {
|
|
822
|
-
if (possiblePromises.length === 0)
|
|
823
|
-
reject(new AggregateError([]));
|
|
824
|
-
var remaining = possiblePromises.length;
|
|
825
|
-
var failures = new Array(remaining);
|
|
826
|
-
possiblePromises.forEach(function (p, i) { return DexiePromise.resolve(p).then(function (value) { return resolve(value); }, function (failure) {
|
|
827
|
-
failures[i] = failure;
|
|
828
|
-
if (!--remaining)
|
|
829
|
-
reject(new AggregateError(failures));
|
|
830
|
-
}); });
|
|
831
|
-
});
|
|
832
|
-
},
|
|
833
808
|
PSD: {
|
|
834
809
|
get: function () { return PSD; },
|
|
835
810
|
set: function (value) { return PSD = value; }
|
|
@@ -861,6 +836,35 @@ props(DexiePromise, {
|
|
|
861
836
|
});
|
|
862
837
|
}
|
|
863
838
|
});
|
|
839
|
+
if (NativePromise) {
|
|
840
|
+
if (NativePromise.allSettled)
|
|
841
|
+
setProp(DexiePromise, "allSettled", function () {
|
|
842
|
+
var possiblePromises = getArrayOf.apply(null, arguments).map(onPossibleParallellAsync);
|
|
843
|
+
return new DexiePromise(function (resolve) {
|
|
844
|
+
if (possiblePromises.length === 0)
|
|
845
|
+
resolve([]);
|
|
846
|
+
var remaining = possiblePromises.length;
|
|
847
|
+
var results = new Array(remaining);
|
|
848
|
+
possiblePromises.forEach(function (p, i) { return DexiePromise.resolve(p).then(function (value) { return results[i] = { status: "fulfilled", value: value }; }, function (reason) { return results[i] = { status: "rejected", reason: reason }; })
|
|
849
|
+
.then(function () { return --remaining || resolve(results); }); });
|
|
850
|
+
});
|
|
851
|
+
});
|
|
852
|
+
if (NativePromise.any && typeof AggregateError !== 'undefined')
|
|
853
|
+
setProp(DexiePromise, "any", function () {
|
|
854
|
+
var possiblePromises = getArrayOf.apply(null, arguments).map(onPossibleParallellAsync);
|
|
855
|
+
return new DexiePromise(function (resolve, reject) {
|
|
856
|
+
if (possiblePromises.length === 0)
|
|
857
|
+
reject(new AggregateError([]));
|
|
858
|
+
var remaining = possiblePromises.length;
|
|
859
|
+
var failures = new Array(remaining);
|
|
860
|
+
possiblePromises.forEach(function (p, i) { return DexiePromise.resolve(p).then(function (value) { return resolve(value); }, function (failure) {
|
|
861
|
+
failures[i] = failure;
|
|
862
|
+
if (!--remaining)
|
|
863
|
+
reject(new AggregateError(failures));
|
|
864
|
+
}); });
|
|
865
|
+
});
|
|
866
|
+
});
|
|
867
|
+
}
|
|
864
868
|
function executePromiseTask(promise, fn) {
|
|
865
869
|
try {
|
|
866
870
|
fn(function (value) {
|
|
@@ -1184,8 +1188,10 @@ function switchToZone(targetZone, bEnteringZone) {
|
|
|
1184
1188
|
GlobalPromise_1.race = targetEnv.race;
|
|
1185
1189
|
GlobalPromise_1.resolve = targetEnv.resolve;
|
|
1186
1190
|
GlobalPromise_1.reject = targetEnv.reject;
|
|
1187
|
-
|
|
1188
|
-
|
|
1191
|
+
if (targetEnv.allSettled)
|
|
1192
|
+
GlobalPromise_1.allSettled = targetEnv.allSettled;
|
|
1193
|
+
if (targetEnv.any)
|
|
1194
|
+
GlobalPromise_1.any = targetEnv.any;
|
|
1189
1195
|
}
|
|
1190
1196
|
}
|
|
1191
1197
|
}
|
|
@@ -1299,7 +1305,7 @@ function tempTransaction(db, mode, storeNames, fn) {
|
|
|
1299
1305
|
}
|
|
1300
1306
|
}
|
|
1301
1307
|
|
|
1302
|
-
var DEXIE_VERSION = '3.0.
|
|
1308
|
+
var DEXIE_VERSION = '3.0.1';
|
|
1303
1309
|
var maxString = String.fromCharCode(65535);
|
|
1304
1310
|
var minKey = -Infinity;
|
|
1305
1311
|
var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
|
|
@@ -2757,7 +2763,7 @@ function createTransactionConstructor(db) {
|
|
|
2757
2763
|
});
|
|
2758
2764
|
}
|
|
2759
2765
|
|
|
2760
|
-
function createIndexSpec(name, keyPath, unique, multi, auto, compound) {
|
|
2766
|
+
function createIndexSpec(name, keyPath, unique, multi, auto, compound, isPrimKey) {
|
|
2761
2767
|
return {
|
|
2762
2768
|
name: name,
|
|
2763
2769
|
keyPath: keyPath,
|
|
@@ -2765,7 +2771,7 @@ function createIndexSpec(name, keyPath, unique, multi, auto, compound) {
|
|
|
2765
2771
|
multi: multi,
|
|
2766
2772
|
auto: auto,
|
|
2767
2773
|
compound: compound,
|
|
2768
|
-
src: (unique ? '&' : '') + (multi ? '*' : '') + (auto ? "++" : "") + nameFromKeyPath(keyPath)
|
|
2774
|
+
src: (unique && !isPrimKey ? '&' : '') + (multi ? '*' : '') + (auto ? "++" : "") + nameFromKeyPath(keyPath)
|
|
2769
2775
|
};
|
|
2770
2776
|
}
|
|
2771
2777
|
function nameFromKeyPath(keyPath) {
|
|
@@ -3220,7 +3226,12 @@ function setApiOnPlace(db, objs, tableNames, dbschema) {
|
|
|
3220
3226
|
objs.forEach(function (obj) {
|
|
3221
3227
|
if (!(tableName in obj)) {
|
|
3222
3228
|
if (obj === db.Transaction.prototype || obj instanceof db.Transaction) {
|
|
3223
|
-
setProp(obj, tableName, {
|
|
3229
|
+
setProp(obj, tableName, {
|
|
3230
|
+
get: function () { return this.table(tableName); },
|
|
3231
|
+
set: function (value) {
|
|
3232
|
+
defineProperty(this, tableName, { value: value, writable: true, configurable: true, enumerable: true });
|
|
3233
|
+
}
|
|
3234
|
+
});
|
|
3224
3235
|
}
|
|
3225
3236
|
else {
|
|
3226
3237
|
obj[tableName] = new db.Table(tableName, schema);
|
|
@@ -3421,17 +3432,15 @@ function addIndex(store, idx) {
|
|
|
3421
3432
|
function buildGlobalSchema(db, idbdb, tmpTrans) {
|
|
3422
3433
|
var globalSchema = {};
|
|
3423
3434
|
var dbStoreNames = slice(idbdb.objectStoreNames, 0);
|
|
3424
|
-
if (dbStoreNames.length === 0)
|
|
3425
|
-
return;
|
|
3426
3435
|
dbStoreNames.forEach(function (storeName) {
|
|
3427
3436
|
var store = tmpTrans.objectStore(storeName);
|
|
3428
3437
|
var keyPath = store.keyPath;
|
|
3429
|
-
var primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath || "", false, false, !!store.autoIncrement, keyPath && typeof keyPath !== "string");
|
|
3438
|
+
var primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath || "", false, false, !!store.autoIncrement, keyPath && typeof keyPath !== "string", true);
|
|
3430
3439
|
var indexes = [];
|
|
3431
3440
|
for (var j = 0; j < store.indexNames.length; ++j) {
|
|
3432
3441
|
var idbindex = store.index(store.indexNames[j]);
|
|
3433
3442
|
keyPath = idbindex.keyPath;
|
|
3434
|
-
var index = createIndexSpec(idbindex.name, keyPath, !!idbindex.unique, !!idbindex.multiEntry, false, keyPath && typeof keyPath !== "string");
|
|
3443
|
+
var index = createIndexSpec(idbindex.name, keyPath, !!idbindex.unique, !!idbindex.multiEntry, false, keyPath && typeof keyPath !== "string", false);
|
|
3435
3444
|
indexes.push(index);
|
|
3436
3445
|
}
|
|
3437
3446
|
globalSchema[storeName] = createTableSchema(storeName, primKey, indexes);
|
|
@@ -3471,15 +3480,13 @@ function adjustToExistingIndexNames(db, schema, idbtrans) {
|
|
|
3471
3480
|
db._hasGetAll = false;
|
|
3472
3481
|
}
|
|
3473
3482
|
}
|
|
3474
|
-
function parseIndexSyntax(
|
|
3475
|
-
|
|
3476
|
-
indexes.split(',').forEach(function (index) {
|
|
3483
|
+
function parseIndexSyntax(primKeyAndIndexes) {
|
|
3484
|
+
return primKeyAndIndexes.split(',').map(function (index, indexNum) {
|
|
3477
3485
|
index = index.trim();
|
|
3478
3486
|
var name = index.replace(/([&*]|\+\+)/g, "");
|
|
3479
3487
|
var keyPath = /^\[/.test(name) ? name.match(/^\[(.*)\]$/)[1].split('+') : name;
|
|
3480
|
-
|
|
3488
|
+
return createIndexSpec(name, keyPath || null, /\&/.test(index), /\*/.test(index), /\+\+/.test(index), isArray(keyPath), indexNum === 0);
|
|
3481
3489
|
});
|
|
3482
|
-
return rv;
|
|
3483
3490
|
}
|
|
3484
3491
|
|
|
3485
3492
|
var Version = (function () {
|
|
@@ -3543,26 +3550,28 @@ function createVersionConstructor(db) {
|
|
|
3543
3550
|
|
|
3544
3551
|
var databaseEnumerator;
|
|
3545
3552
|
function DatabaseEnumerator(indexedDB) {
|
|
3546
|
-
var
|
|
3553
|
+
var hasDatabasesNative = indexedDB && typeof indexedDB.databases === 'function';
|
|
3547
3554
|
var dbNamesTable;
|
|
3548
|
-
if (!
|
|
3555
|
+
if (!hasDatabasesNative) {
|
|
3549
3556
|
var db = new Dexie(DBNAMES_DB, { addons: [] });
|
|
3550
3557
|
db.version(1).stores({ dbnames: 'name' });
|
|
3551
3558
|
dbNamesTable = db.table('dbnames');
|
|
3552
3559
|
}
|
|
3553
3560
|
return {
|
|
3554
3561
|
getDatabaseNames: function () {
|
|
3555
|
-
return
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3562
|
+
return hasDatabasesNative
|
|
3563
|
+
?
|
|
3564
|
+
DexiePromise.resolve(indexedDB.databases()).then(function (infos) { return infos
|
|
3565
|
+
.map(function (info) { return info.name; })
|
|
3566
|
+
.filter(function (name) { return name !== DBNAMES_DB; }); })
|
|
3567
|
+
:
|
|
3568
|
+
dbNamesTable.toCollection().primaryKeys();
|
|
3560
3569
|
},
|
|
3561
3570
|
add: function (name) {
|
|
3562
|
-
return !
|
|
3571
|
+
return !hasDatabasesNative && name !== DBNAMES_DB && dbNamesTable.put({ name: name }).catch(nop);
|
|
3563
3572
|
},
|
|
3564
3573
|
remove: function (name) {
|
|
3565
|
-
return !
|
|
3574
|
+
return !hasDatabasesNative && name !== DBNAMES_DB && dbNamesTable.delete(name).catch(nop);
|
|
3566
3575
|
}
|
|
3567
3576
|
};
|
|
3568
3577
|
}
|