dexie 4.0.0-alpha.3 → 4.0.1-alpha.6

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/CONTRIBUTING.md CHANGED
@@ -4,7 +4,7 @@ HOW TO CONTRIBUTE
4
4
  We appreciate contributions in forms of:
5
5
 
6
6
  * issues
7
- * help answering questions in [issues](https://github.com/dfahlander/Dexie.js/issues) and on [stackoverflow](https://stackexchange.com/filters/233583/dexie-stackoverflow)
7
+ * help answering questions in [issues](https://github.com/dexie/Dexie.js/issues) and on [stackoverflow](https://stackexchange.com/filters/233583/dexie-stackoverflow)
8
8
  * fixing bugs via pull-requests
9
9
  * developing addons or other [derived work](https://dexie.org/docs/DerivedWork)
10
10
  * promoting Dexie.js
@@ -13,7 +13,9 @@ We appreciate contributions in forms of:
13
13
  Contribute while developing your own app
14
14
  ========================================
15
15
 
16
- Here is a little cheat-sheet for how to symlink your app's `node_modules/dexie` to a place where you can edit the source, version control your changes and create pull requests back to Dexie. Assuming you've already ran `npm install dexie --save` for the app your are developing.
16
+ Dexie uses pnpm package manager. Refer to [pnpm.io/installation](https://pnpm.io/installation) for how to install pnpm.
17
+
18
+ Here is a little cheat-sheet for how to symlink your app's `node_modules/dexie` to a place where you can edit the source, version control your changes and create pull requests back to Dexie. Assuming you've already ran `npm install dexie` for the app your are developing.
17
19
 
18
20
  1. Fork Dexie.js from the web gui on github
19
21
  2. Clone your fork locally by launching a shell/command window and cd to a neutral place (like `~repos/`, `c:\repos` or whatever)
@@ -22,39 +24,42 @@ Here is a little cheat-sheet for how to symlink your app's `node_modules/dexie`
22
24
  ```
23
25
  git clone https://github.com/YOUR-USERNAME/Dexie.js.git dexie
24
26
  cd dexie
25
- npm install
26
- npm run build
27
- npm link
27
+ pnpm install
28
+ pnpm run build
29
+ npm link # Or yarn link or pnpm link --global depending on what package manager you are using.
28
30
  ```
29
31
  3. cd to your app directory and write:
30
32
  ```
31
- npm link dexie
33
+ npm link dexie # Or yarn link dexie / pnpm link dexie depending on your package manager.
32
34
  ```
33
35
 
34
- Your app's `node_modules/dexie/` is now sym-linked to the Dexie.js clone on your hard drive so any change you do there will propagate to your app. Build dexie.js using `npm run build` or `npm run watch`. The latter will react on any source file change and rebuild the dist files.
36
+ Your app's `node_modules/dexie/` is now sym-linked to the Dexie.js clone on your hard drive so any change you do there will propagate to your app. Build dexie.js using `pnpm run build` or `pnpm run watch`. The latter will react on any source file change and rebuild the dist files.
35
37
 
36
38
  That's it. Now you're up and running to test and commit changes to files under dexie/src/* or dexie/test/* and the changes will instantly affect the app you are developing.
37
39
 
40
+ If you're on yarn or pnpm, do the same procedures using yarn link / pnpm link.
41
+
38
42
  Pull requests are more than welcome. Some advices are:
39
43
 
40
- * Run npm test before making a pull request.
44
+ * Run pnpm test before making a pull request.
41
45
  * If you find an issue, a unit test that reproduces it is lovely ;). If you don't know where to put it, put it in `test/tests-misc.js`. We use qunit. Just look at existing tests in `tests-misc.js` to see how they should be written. Tests are transpiled in the build script so you can use ES6 if you like.
42
46
 
43
47
  Build
44
48
  -----
45
49
  ```
46
- npm install
47
- npm run build
50
+ # To install pnpm, see https://pnpm.io/installation
51
+ pnpm install
52
+ pnpm run build
48
53
  ```
49
54
 
50
55
  Test
51
56
  ----
52
57
  ```
53
- npm test
58
+ pnpm test
54
59
  ```
55
60
 
56
61
  Watch
57
62
  -----
58
63
  ```
59
- npm run watch
64
+ pnpm run watch
60
65
  ```
package/README.md CHANGED
@@ -229,50 +229,25 @@ https://unpkg.com/dexie@latest/dist/dexie.d.ts
229
229
 
230
230
  Contributing
231
231
  ============
232
- Here is a little cheat-sheet for how to symlink your app's `node_modules/dexie` to a place where you can edit the source, version control your changes and create pull requests back to Dexie. Assuming you've already ran `npm install dexie --save` for the app your are developing.
233
-
234
- 1. Fork Dexie.js from the web gui on github
235
- 2. Clone your fork locally by launching a shell/command window and cd to a neutral place (like `~repos/`, `c:\repos` or whatever)
236
- 3. Run the following commands:
237
-
238
- ```
239
- git clone https://github.com/YOUR-USERNAME/Dexie.js.git dexie
240
- cd dexie
241
- npm install
242
- npm run build
243
- npm link
244
- ```
245
- 3. cd to your app directory and write:
246
- ```
247
- npm link dexie
248
- ```
249
-
250
- Your app's `node_modules/dexie/` is now sym-linked to the Dexie.js clone on your hard drive so any change you do there will propagate to your app. Build dexie.js using `npm run build` or `npm run watch`. The latter will react on any source file change and rebuild the dist files.
251
-
252
- That's it. Now you're up and running to test and commit changes to files under dexie/src/* or dexie/test/* and the changes will instantly affect the app you are developing.
253
-
254
- Pull requests are more than welcome. Some advices are:
255
-
256
- * Run npm test before making a pull request.
257
- * If you find an issue, a unit test that reproduces it is lovely ;). If you don't know where to put it, put it in `test/tests-misc.js`. We use qunit. Just look at existing tests in `tests-misc.js` to see how they should be written. Tests are transpiled in the build script so you can use ES6 if you like.
232
+ See [CONTRIBUTING.md](CONTRIBUTING.md)
258
233
 
259
234
  Build
260
235
  -----
261
236
  ```
262
- npm install
263
- npm run build
237
+ pnpm install
238
+ pnpm run build
264
239
  ```
265
240
 
266
241
  Test
267
242
  ----
268
243
  ```
269
- npm test
244
+ pnpm test
270
245
  ```
271
246
 
272
247
  Watch
273
248
  -----
274
249
  ```
275
- npm run watch
250
+ pnpm run watch
276
251
  ```
277
252
 
278
253
 
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.0-alpha.3, Wed Apr 27 2022
7
+ * Version 4.0.1-alpha.6, Tue Jan 17 2023
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -85,7 +85,7 @@ export interface DeletingHookContext<T, Key> {
85
85
  onerror?: (err: any) => void;
86
86
  }
87
87
  export interface TableHooks<T = any, TKey = IndexableType> extends DexieEventSet {
88
- (eventName: "creating", subscriber: (this: CreatingHookContext<T, TKey>, primKey: TKey, obj: T, transaction: Transaction) => any): void;
88
+ (eventName: "creating", subscriber: (this: CreatingHookContext<T, TKey>, primKey: TKey, obj: T, transaction: Transaction) => void | undefined | TKey): void;
89
89
  (eventName: "reading", subscriber: (obj: T) => T | any): void;
90
90
  (eventName: "updating", subscriber: (this: UpdatingHookContext<T, TKey>, modifications: Object, primKey: TKey, obj: T, transaction: Transaction) => any): void;
91
91
  (eventName: "deleting", subscriber: (this: DeletingHookContext<T, TKey>, primKey: TKey, obj: T, transaction: Transaction) => any): void;
@@ -388,6 +388,7 @@ export interface Collection<T = any, TKey = IndexableType> {
388
388
  key: IndexableType;
389
389
  primaryKey: TKey;
390
390
  }) => any): PromiseExtended<void>;
391
+ filter<S extends T>(filter: (x: T) => x is S): Collection<S, TKey>;
391
392
  filter(filter: (x: T) => boolean): Collection<T, TKey>;
392
393
  first(): PromiseExtended<T | undefined>;
393
394
  first<R>(thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
@@ -464,9 +465,12 @@ export interface DBCorePutRequest {
464
465
  changeSpec?: {
465
466
  [keyPath: string]: any;
466
467
  }; // Common changeSpec for each key
467
- changeSpecs?: {
468
- [keyPath: string]: any;
469
- }[]; // changeSpec per key.
468
+ updates?: {
469
+ keys: any[];
470
+ changeSpecs: {
471
+ [keyPath: string]: any;
472
+ }[]; // changeSpec per key.
473
+ };
470
474
  /** @deprecated Will always get results since 3.1.0-alpha.5 */
471
475
  wantResults?: boolean;
472
476
  }
@@ -581,76 +585,71 @@ export interface DBCoreTable {
581
585
  openCursor(req: DBCoreOpenCursorRequest): Promise<DBCoreCursor | null>;
582
586
  count(req: DBCoreCountRequest): Promise<number>;
583
587
  }
584
- export type MethodProps<T> = {
585
- [P in keyof T]: T[P] extends (...args: any[]) => any ? P : never;
586
- }[keyof T];
587
- export type InsertType<T, TOptionalProperties, TKeyPropNameOrKeyType> = string extends MethodProps<T> ? T : Omit<T, TOptionalProperties extends keyof T ? TKeyPropNameOrKeyType extends keyof T ? MethodProps<T> | TOptionalProperties | TKeyPropNameOrKeyType : MethodProps<T> | TOptionalProperties : MethodProps<T>> & (TOptionalProperties extends keyof T ? TKeyPropNameOrKeyType extends keyof T ? {
588
- [P in (TOptionalProperties | TKeyPropNameOrKeyType)]?: T[P];
589
- } : {
590
- [P in TOptionalProperties]?: T[P];
591
- } : {});
592
- export type IDType<T, TKey> = TKey extends keyof T ? T[TKey] : TKey;
593
- export interface Table<T = any, TKeyPropNameOrKeyType = IndexableType, TOpt = void> {
588
+ export interface Table<T = any, TKey = IndexableType, TInsertType = T> {
594
589
  db: Dexie;
595
590
  name: string;
596
591
  schema: TableSchema;
597
- hook: TableHooks<T, IDType<T, TKeyPropNameOrKeyType>>;
592
+ hook: TableHooks<T, TKey>;
598
593
  core: DBCoreTable;
599
- get(key: IDType<T, TKeyPropNameOrKeyType>): PromiseExtended<T | undefined>;
600
- get<R>(key: IDType<T, TKeyPropNameOrKeyType>, thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
594
+ get(key: TKey): PromiseExtended<T | undefined>;
595
+ get<R>(key: TKey, thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
601
596
  get(equalityCriterias: {
602
597
  [key: string]: any;
603
598
  }): PromiseExtended<T | undefined>;
604
599
  get<R>(equalityCriterias: {
605
600
  [key: string]: any;
606
601
  }, thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
607
- where(index: string | string[]): WhereClause<T, IDType<T, TKeyPropNameOrKeyType>>;
602
+ where(index: string | string[]): WhereClause<T, TKey>;
608
603
  where(equalityCriterias: {
609
604
  [key: string]: any;
610
- }): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
611
- filter(fn: (obj: T) => boolean): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
605
+ }): Collection<T, TKey>;
606
+ filter(fn: (obj: T) => boolean): Collection<T, TKey>;
612
607
  count(): PromiseExtended<number>;
613
608
  count<R>(thenShortcut: ThenShortcut<number, R>): PromiseExtended<R>;
614
- offset(n: number): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
615
- limit(n: number): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
609
+ offset(n: number): Collection<T, TKey>;
610
+ limit(n: number): Collection<T, TKey>;
616
611
  each(callback: (obj: T, cursor: {
617
612
  key: any;
618
- primaryKey: IDType<T, TKeyPropNameOrKeyType>;
613
+ primaryKey: TKey;
619
614
  }) => any): PromiseExtended<void>;
620
615
  toArray(): PromiseExtended<Array<T>>;
621
616
  toArray<R>(thenShortcut: ThenShortcut<T[], R>): PromiseExtended<R>;
622
- toCollection(): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
623
- orderBy(index: string | string[]): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
624
- reverse(): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
617
+ toCollection(): Collection<T, TKey>;
618
+ orderBy(index: string | string[]): Collection<T, TKey>;
619
+ reverse(): Collection<T, TKey>;
625
620
  mapToClass(constructor: Function): Function;
626
- add(item: InsertType<T, TOpt, TKeyPropNameOrKeyType>, key?: IDType<T, TKeyPropNameOrKeyType>): PromiseExtended<IDType<T, TKeyPropNameOrKeyType>>;
627
- update(key: IDType<T, TKeyPropNameOrKeyType> | T, changes: UpdateSpec<T> | ((obj: T, ctx: {
621
+ add(item: TInsertType, key?: TKey): PromiseExtended<TKey>;
622
+ update(key: TKey | T, changes: UpdateSpec<T> | ((obj: T, ctx: {
628
623
  value: any;
629
624
  primKey: IndexableType;
630
625
  }) => void | boolean)): PromiseExtended<number>;
631
- put(item: InsertType<T, TOpt, TKeyPropNameOrKeyType>, key?: IDType<T, TKeyPropNameOrKeyType>): PromiseExtended<IDType<T, TKeyPropNameOrKeyType>>;
632
- delete(key: IDType<T, TKeyPropNameOrKeyType>): PromiseExtended<void>;
626
+ put(item: TInsertType, key?: TKey): PromiseExtended<TKey>;
627
+ delete(key: TKey): PromiseExtended<void>;
633
628
  clear(): PromiseExtended<void>;
634
- bulkGet(keys: IDType<T, TKeyPropNameOrKeyType>[]): PromiseExtended<(T | undefined)[]>;
635
- bulkAdd<B extends boolean>(items: readonly InsertType<T, TOpt, TKeyPropNameOrKeyType>[], keys: IndexableTypeArrayReadonly, options: {
629
+ bulkGet(keys: TKey[]): PromiseExtended<(T | undefined)[]>;
630
+ bulkAdd<B extends boolean>(items: readonly TInsertType[], keys: IndexableTypeArrayReadonly, options: {
636
631
  allKeys: B;
637
- }): PromiseExtended<B extends true ? IDType<T, TKeyPropNameOrKeyType>[] : IDType<T, TKeyPropNameOrKeyType>>;
638
- bulkAdd<B extends boolean>(items: readonly InsertType<T, TOpt, TKeyPropNameOrKeyType>[], options: {
632
+ }): PromiseExtended<B extends true ? TKey[] : TKey>;
633
+ bulkAdd<B extends boolean>(items: readonly TInsertType[], options: {
639
634
  allKeys: B;
640
- }): PromiseExtended<B extends true ? IDType<T, TKeyPropNameOrKeyType>[] : IDType<T, TKeyPropNameOrKeyType>>;
641
- bulkAdd(items: readonly InsertType<T, TOpt, TKeyPropNameOrKeyType>[], keys?: IndexableTypeArrayReadonly, options?: {
635
+ }): PromiseExtended<B extends true ? TKey[] : TKey>;
636
+ bulkAdd(items: readonly TInsertType[], keys?: IndexableTypeArrayReadonly, options?: {
642
637
  allKeys: boolean;
643
- }): PromiseExtended<IDType<T, TKeyPropNameOrKeyType>>;
644
- bulkPut<B extends boolean>(items: readonly InsertType<T, TOpt, TKeyPropNameOrKeyType>[], keys: IndexableTypeArrayReadonly, options: {
638
+ }): PromiseExtended<TKey>;
639
+ bulkPut<B extends boolean>(items: readonly TInsertType[], keys: IndexableTypeArrayReadonly, options: {
645
640
  allKeys: B;
646
- }): PromiseExtended<B extends true ? IDType<T, TKeyPropNameOrKeyType>[] : IDType<T, TKeyPropNameOrKeyType>>;
647
- bulkPut<B extends boolean>(items: readonly InsertType<T, TOpt, TKeyPropNameOrKeyType>[], options: {
641
+ }): PromiseExtended<B extends true ? TKey[] : TKey>;
642
+ bulkPut<B extends boolean>(items: readonly TInsertType[], options: {
648
643
  allKeys: B;
649
- }): PromiseExtended<B extends true ? IDType<T, TKeyPropNameOrKeyType>[] : IDType<T, TKeyPropNameOrKeyType>>;
650
- bulkPut(items: readonly InsertType<T, TOpt, TKeyPropNameOrKeyType>[], keys?: IndexableTypeArrayReadonly, options?: {
644
+ }): PromiseExtended<B extends true ? TKey[] : TKey>;
645
+ bulkPut(items: readonly TInsertType[], keys?: IndexableTypeArrayReadonly, options?: {
651
646
  allKeys: boolean;
652
- }): PromiseExtended<IDType<T, TKeyPropNameOrKeyType>>;
653
- bulkDelete(keys: IDType<T, TKeyPropNameOrKeyType>[]): PromiseExtended<void>;
647
+ }): PromiseExtended<TKey>;
648
+ bulkUpdate(keysAndChanges: ReadonlyArray<{
649
+ key: TKey;
650
+ changes: UpdateSpec<T>;
651
+ }>): PromiseExtended<number>;
652
+ bulkDelete(keys: TKey[]): PromiseExtended<void>;
654
653
  }
655
654
  export interface Version {
656
655
  stores(schema: {
@@ -1039,6 +1038,27 @@ export class Entity<TDexieSubClass extends Dexie = Dexie> {
1039
1038
  protected readonly db: TDexieSubClass;
1040
1039
  table(): TableProp<TDexieSubClass>;
1041
1040
  }
1041
+ export type IsStrictlyAny<T> = (T extends never ? true : false) extends false ? false : true;
1042
+ /** Extract the union of literal method names in T
1043
+ */
1044
+ export type MethodProps<T> = {
1045
+ [P in keyof T]: IsStrictlyAny<T[P]> extends true ? never // Plain property of type any (not method)
1046
+ : T[P] extends (...args: any[]) => any ? P // a function (method)
1047
+ : never;
1048
+ }[keyof T];
1049
+ /** Default insert type of T is a subset of T where:
1050
+ * * given optional props (such as an auto-generated primary key) are made optional
1051
+ * * methods are omitted
1052
+ */
1053
+ export type InsertType<T, OptionalProps extends keyof T> = Omit<T, OptionalProps | MethodProps<T>> & {
1054
+ [P in OptionalProps]?: T[P];
1055
+ };
1056
+ /** IDType extract the actual type of the primary key:
1057
+ * * If TKey is a literal type that names a property of T, extract the type using T[TKey]
1058
+ * * Else, use TKey as is.
1059
+ */
1060
+ export type IDType<T, TKeyPropNameOrKeyType> = IsStrictlyAny<T> extends true ? TKeyPropNameOrKeyType : TKeyPropNameOrKeyType extends string ? TKeyPropNameOrKeyType extends keyof T ? T[TKeyPropNameOrKeyType] : TKeyPropNameOrKeyType : TKeyPropNameOrKeyType;
1061
+ export type EntityTable<T, TKeyPropName extends keyof T = never, TInsertType = InsertType<T, TKeyPropName>> = Table<T, IDType<T, TKeyPropName>, TInsertType>;
1042
1062
  export declare var Dexie: DexieConstructor;
1043
1063
  export interface _Table<T, TKey> extends Table<T, TKey> {
1044
1064
  }
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.0-alpha.3, Wed Apr 27 2022
7
+ * Version 4.0.1-alpha.6, Tue Jan 17 2023
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -232,7 +232,7 @@
232
232
  function flatten(a) {
233
233
  return concat.apply([], a);
234
234
  }
235
- var intrinsicTypeNames = "Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey"
235
+ var intrinsicTypeNames = "Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,FileSystemDirectoryHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey"
236
236
  .split(',').concat(flatten([8, 16, 32, 64].map(function (num) { return ["Int", "Uint", "Float"].map(function (t) { return t + num + "Array"; }); }))).filter(function (t) { return _global[t]; });
237
237
  var intrinsicTypes = intrinsicTypeNames.map(function (t) { return _global[t]; });
238
238
  arrayToObject(intrinsicTypeNames, function (x) { return [x, true]; });
@@ -425,7 +425,7 @@
425
425
  this.name = "BulkError";
426
426
  this.failures = Object.keys(failures).map(function (pos) { return failures[pos]; });
427
427
  this.failuresByPos = failures;
428
- this.message = getMultiErrorMessage(msg, failures);
428
+ this.message = getMultiErrorMessage(msg, this.failures);
429
429
  }
430
430
  derive(BulkError).from(DexieError);
431
431
  var errnames = errorList.reduce(function (obj, name) { return (obj[name] = name + "Error", obj); }, {});
@@ -1300,7 +1300,7 @@
1300
1300
  }
1301
1301
  }
1302
1302
 
1303
- var DEXIE_VERSION = '4.0.0-alpha.3';
1303
+ var DEXIE_VERSION = '4.0.1-alpha.6';
1304
1304
  var maxString = String.fromCharCode(65535);
1305
1305
  var minKey = -Infinity;
1306
1306
  var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
@@ -1346,6 +1346,82 @@
1346
1346
  throw exceptions.Type();
1347
1347
  }
1348
1348
 
1349
+ function cmp(a, b) {
1350
+ try {
1351
+ var ta = type(a);
1352
+ var tb = type(b);
1353
+ if (ta !== tb) {
1354
+ if (ta === 'Array')
1355
+ return 1;
1356
+ if (tb === 'Array')
1357
+ return -1;
1358
+ if (ta === 'binary')
1359
+ return 1;
1360
+ if (tb === 'binary')
1361
+ return -1;
1362
+ if (ta === 'string')
1363
+ return 1;
1364
+ if (tb === 'string')
1365
+ return -1;
1366
+ if (ta === 'Date')
1367
+ return 1;
1368
+ if (tb !== 'Date')
1369
+ return NaN;
1370
+ return -1;
1371
+ }
1372
+ switch (ta) {
1373
+ case 'number':
1374
+ case 'Date':
1375
+ case 'string':
1376
+ return a > b ? 1 : a < b ? -1 : 0;
1377
+ case 'binary': {
1378
+ return compareUint8Arrays(getUint8Array(a), getUint8Array(b));
1379
+ }
1380
+ case 'Array':
1381
+ return compareArrays(a, b);
1382
+ }
1383
+ }
1384
+ catch (_a) { }
1385
+ return NaN;
1386
+ }
1387
+ function compareArrays(a, b) {
1388
+ var al = a.length;
1389
+ var bl = b.length;
1390
+ var l = al < bl ? al : bl;
1391
+ for (var i = 0; i < l; ++i) {
1392
+ var res = cmp(a[i], b[i]);
1393
+ if (res !== 0)
1394
+ return res;
1395
+ }
1396
+ return al === bl ? 0 : al < bl ? -1 : 1;
1397
+ }
1398
+ function compareUint8Arrays(a, b) {
1399
+ var al = a.length;
1400
+ var bl = b.length;
1401
+ var l = al < bl ? al : bl;
1402
+ for (var i = 0; i < l; ++i) {
1403
+ if (a[i] !== b[i])
1404
+ return a[i] < b[i] ? -1 : 1;
1405
+ }
1406
+ return al === bl ? 0 : al < bl ? -1 : 1;
1407
+ }
1408
+ function type(x) {
1409
+ var t = typeof x;
1410
+ if (t !== 'object')
1411
+ return t;
1412
+ if (ArrayBuffer.isView(x))
1413
+ return 'binary';
1414
+ var tsTag = toStringTag(x);
1415
+ return tsTag === 'ArrayBuffer' ? 'binary' : tsTag;
1416
+ }
1417
+ function getUint8Array(a) {
1418
+ if (a instanceof Uint8Array)
1419
+ return a;
1420
+ if (ArrayBuffer.isView(a))
1421
+ return new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
1422
+ return new Uint8Array(a);
1423
+ }
1424
+
1349
1425
  var Table = (function () {
1350
1426
  function Table() {
1351
1427
  }
@@ -1404,12 +1480,7 @@
1404
1480
  var idxByName = this.schema.idxByName;
1405
1481
  var idb = this.db._deps.indexedDB;
1406
1482
  function equals(a, b) {
1407
- try {
1408
- return idb.cmp(a, b) === 0;
1409
- }
1410
- catch (e) {
1411
- return false;
1412
- }
1483
+ return idb.cmp(a, b) === 0;
1413
1484
  }
1414
1485
  var _a = keyPaths.reduce(function (_a, keyPath) {
1415
1486
  var prevIndex = _a[0], prevFilterFn = _a[1];
@@ -1640,6 +1711,67 @@
1640
1711
  });
1641
1712
  });
1642
1713
  };
1714
+ Table.prototype.bulkUpdate = function (keysAndChanges) {
1715
+ var _this = this;
1716
+ var coreTable = this.core;
1717
+ var keys = keysAndChanges.map(function (entry) { return entry.key; });
1718
+ var changeSpecs = keysAndChanges.map(function (entry) { return entry.changes; });
1719
+ var offsetMap = [];
1720
+ return this._trans('readwrite', function (trans) {
1721
+ return coreTable.getMany({ trans: trans, keys: keys, cache: 'clone' }).then(function (objs) {
1722
+ var resultKeys = [];
1723
+ var resultObjs = [];
1724
+ keysAndChanges.forEach(function (_a, idx) {
1725
+ var key = _a.key, changes = _a.changes;
1726
+ var obj = objs[idx];
1727
+ if (obj) {
1728
+ for (var _i = 0, _b = Object.keys(changes); _i < _b.length; _i++) {
1729
+ var keyPath = _b[_i];
1730
+ var value = changes[keyPath];
1731
+ if (keyPath === _this.schema.primKey.keyPath) {
1732
+ if (cmp(value, key) !== 0) {
1733
+ throw new exceptions.Constraint("Cannot update primary key in bulkUpdate()");
1734
+ }
1735
+ }
1736
+ else {
1737
+ setByKeyPath(obj, keyPath, value);
1738
+ }
1739
+ }
1740
+ offsetMap.push(idx);
1741
+ resultKeys.push(key);
1742
+ resultObjs.push(obj);
1743
+ }
1744
+ });
1745
+ var numEntries = resultKeys.length;
1746
+ return coreTable
1747
+ .mutate({
1748
+ trans: trans,
1749
+ type: 'put',
1750
+ keys: resultKeys,
1751
+ values: resultObjs,
1752
+ updates: {
1753
+ keys: keys,
1754
+ changeSpecs: changeSpecs
1755
+ }
1756
+ })
1757
+ .then(function (_a) {
1758
+ var numFailures = _a.numFailures, failures = _a.failures;
1759
+ if (numFailures === 0)
1760
+ return numEntries;
1761
+ for (var _i = 0, _b = Object.keys(failures); _i < _b.length; _i++) {
1762
+ var offset = _b[_i];
1763
+ var mappedOffset = offsetMap[Number(offset)];
1764
+ if (mappedOffset != null) {
1765
+ var failure = failures[offset];
1766
+ delete failures[offset];
1767
+ failures[mappedOffset] = failure;
1768
+ }
1769
+ }
1770
+ throw new BulkError("".concat(_this.name, ".bulkUpdate(): ").concat(numFailures, " of ").concat(numEntries, " operations failed"), failures);
1771
+ });
1772
+ });
1773
+ });
1774
+ };
1643
1775
  Table.prototype.bulkDelete = function (keys) {
1644
1776
  var _this = this;
1645
1777
  var numKeys = keys.length;
@@ -1818,82 +1950,6 @@
1818
1950
  });
1819
1951
  }
1820
1952
 
1821
- function cmp(a, b) {
1822
- try {
1823
- var ta = type(a);
1824
- var tb = type(b);
1825
- if (ta !== tb) {
1826
- if (ta === 'Array')
1827
- return 1;
1828
- if (tb === 'Array')
1829
- return -1;
1830
- if (ta === 'binary')
1831
- return 1;
1832
- if (tb === 'binary')
1833
- return -1;
1834
- if (ta === 'string')
1835
- return 1;
1836
- if (tb === 'string')
1837
- return -1;
1838
- if (ta === 'Date')
1839
- return 1;
1840
- if (tb !== 'Date')
1841
- return NaN;
1842
- return -1;
1843
- }
1844
- switch (ta) {
1845
- case 'number':
1846
- case 'Date':
1847
- case 'string':
1848
- return a > b ? 1 : a < b ? -1 : 0;
1849
- case 'binary': {
1850
- return compareUint8Arrays(getUint8Array(a), getUint8Array(b));
1851
- }
1852
- case 'Array':
1853
- return compareArrays(a, b);
1854
- }
1855
- }
1856
- catch (_a) { }
1857
- return NaN;
1858
- }
1859
- function compareArrays(a, b) {
1860
- var al = a.length;
1861
- var bl = b.length;
1862
- var l = al < bl ? al : bl;
1863
- for (var i = 0; i < l; ++i) {
1864
- var res = cmp(a[i], b[i]);
1865
- if (res !== 0)
1866
- return res;
1867
- }
1868
- return al === bl ? 0 : al < bl ? -1 : 1;
1869
- }
1870
- function compareUint8Arrays(a, b) {
1871
- var al = a.length;
1872
- var bl = b.length;
1873
- var l = al < bl ? al : bl;
1874
- for (var i = 0; i < l; ++i) {
1875
- if (a[i] !== b[i])
1876
- return a[i] < b[i] ? -1 : 1;
1877
- }
1878
- return al === bl ? 0 : al < bl ? -1 : 1;
1879
- }
1880
- function type(x) {
1881
- var t = typeof x;
1882
- if (t !== 'object')
1883
- return t;
1884
- if (ArrayBuffer.isView(x))
1885
- return 'binary';
1886
- var tsTag = toStringTag(x);
1887
- return tsTag === 'ArrayBuffer' ? 'binary' : tsTag;
1888
- }
1889
- function getUint8Array(a) {
1890
- if (a instanceof Uint8Array)
1891
- return a;
1892
- if (ArrayBuffer.isView(a))
1893
- return new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
1894
- return new Uint8Array(a);
1895
- }
1896
-
1897
1953
  var Collection = (function () {
1898
1954
  function Collection() {
1899
1955
  }
@@ -2683,14 +2739,13 @@
2683
2739
  index: index === ":id" ? null : index,
2684
2740
  or: orCollection
2685
2741
  };
2686
- var indexedDB = db._deps.indexedDB;
2687
- if (!indexedDB)
2688
- throw new exceptions.MissingAPI();
2689
- this._cmp = this._ascending = indexedDB.cmp.bind(indexedDB);
2690
- this._descending = function (a, b) { return indexedDB.cmp(b, a); };
2691
- this._max = function (a, b) { return indexedDB.cmp(a, b) > 0 ? a : b; };
2692
- this._min = function (a, b) { return indexedDB.cmp(a, b) < 0 ? a : b; };
2742
+ this._cmp = this._ascending = cmp;
2743
+ this._descending = function (a, b) { return cmp(b, a); };
2744
+ this._max = function (a, b) { return cmp(a, b) > 0 ? a : b; };
2745
+ this._min = function (a, b) { return cmp(a, b) < 0 ? a : b; };
2693
2746
  this._IDBKeyRange = db._deps.IDBKeyRange;
2747
+ if (!this._IDBKeyRange)
2748
+ throw new exceptions.MissingAPI();
2694
2749
  });
2695
2750
  }
2696
2751
 
@@ -5156,6 +5211,9 @@
5156
5211
 
5157
5212
  if (typeof BroadcastChannel !== 'undefined') {
5158
5213
  var bc_1 = new BroadcastChannel(STORAGE_MUTATED_DOM_EVENT_NAME);
5214
+ if (typeof bc_1.unref === 'function') {
5215
+ bc_1.unref();
5216
+ }
5159
5217
  globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, function (changedParts) {
5160
5218
  if (!propagatingLocally) {
5161
5219
  bc_1.postMessage(changedParts);