dexie 4.0.0-alpha.4 → 4.0.1-alpha.7
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 +16 -11
- package/README.md +5 -30
- package/dist/dexie.d.ts +67 -48
- package/dist/dexie.js +147 -92
- 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 +147 -92
- 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 +142 -92
- package/dist/modern/dexie.mjs.map +1 -1
- package/package.json +14 -16
- package/pnpm-workspace.yaml +7 -0
package/CONTRIBUTING.md
CHANGED
|
@@ -13,7 +13,9 @@ We appreciate contributions in forms of:
|
|
|
13
13
|
Contribute while developing your own app
|
|
14
14
|
========================================
|
|
15
15
|
|
|
16
|
-
|
|
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
|
-
|
|
26
|
-
|
|
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 `
|
|
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
|
|
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
|
-
|
|
47
|
-
|
|
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
|
-
|
|
58
|
+
pnpm test
|
|
54
59
|
```
|
|
55
60
|
|
|
56
61
|
Watch
|
|
57
62
|
-----
|
|
58
63
|
```
|
|
59
|
-
|
|
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
|
-
|
|
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
|
-
|
|
263
|
-
|
|
237
|
+
pnpm install
|
|
238
|
+
pnpm run build
|
|
264
239
|
```
|
|
265
240
|
|
|
266
241
|
Test
|
|
267
242
|
----
|
|
268
243
|
```
|
|
269
|
-
|
|
244
|
+
pnpm test
|
|
270
245
|
```
|
|
271
246
|
|
|
272
247
|
Watch
|
|
273
248
|
-----
|
|
274
249
|
```
|
|
275
|
-
|
|
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.
|
|
7
|
+
* Version 4.0.1-alpha.7, Wed Jan 25 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) =>
|
|
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;
|
|
@@ -357,11 +357,10 @@ export interface PromiseExtended<T = any> extends Promise<T> {
|
|
|
357
357
|
timeout(ms: number, msg?: string): PromiseExtended<T>;
|
|
358
358
|
}
|
|
359
359
|
export type KeyPaths<T> = {
|
|
360
|
-
[P in keyof T]: P extends string ? T[P] extends any[] ? P : T[P] extends (...args: any[]) => any // Method
|
|
360
|
+
[P in keyof T]: P extends string ? T[P] extends any[] ? P | `${P}.${number}` | `${P}.${number}.${KeyPaths<T[P][number]>}` : T[P] extends (...args: any[]) => any // Method
|
|
361
361
|
? never : T[P] extends object ? P | `${P}.${KeyPaths<T[P]>}` : P : never;
|
|
362
362
|
}[keyof T];
|
|
363
|
-
export type
|
|
364
|
-
export type KeyPathValue<T, PATH> = PATH extends `${infer R}.${infer S}` ? R extends keyof T ? Extract<T[R], S> : void : Extract<T, PATH>;
|
|
363
|
+
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;
|
|
365
364
|
export type UpdateSpec<T> = {
|
|
366
365
|
[KP in KeyPaths<T>]?: KeyPathValue<T, KP>;
|
|
367
366
|
};
|
|
@@ -388,6 +387,7 @@ export interface Collection<T = any, TKey = IndexableType> {
|
|
|
388
387
|
key: IndexableType;
|
|
389
388
|
primaryKey: TKey;
|
|
390
389
|
}) => any): PromiseExtended<void>;
|
|
390
|
+
filter<S extends T>(filter: (x: T) => x is S): Collection<S, TKey>;
|
|
391
391
|
filter(filter: (x: T) => boolean): Collection<T, TKey>;
|
|
392
392
|
first(): PromiseExtended<T | undefined>;
|
|
393
393
|
first<R>(thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
|
|
@@ -464,9 +464,12 @@ export interface DBCorePutRequest {
|
|
|
464
464
|
changeSpec?: {
|
|
465
465
|
[keyPath: string]: any;
|
|
466
466
|
}; // Common changeSpec for each key
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
467
|
+
updates?: {
|
|
468
|
+
keys: any[];
|
|
469
|
+
changeSpecs: {
|
|
470
|
+
[keyPath: string]: any;
|
|
471
|
+
}[]; // changeSpec per key.
|
|
472
|
+
};
|
|
470
473
|
/** @deprecated Will always get results since 3.1.0-alpha.5 */
|
|
471
474
|
wantResults?: boolean;
|
|
472
475
|
}
|
|
@@ -581,76 +584,71 @@ export interface DBCoreTable {
|
|
|
581
584
|
openCursor(req: DBCoreOpenCursorRequest): Promise<DBCoreCursor | null>;
|
|
582
585
|
count(req: DBCoreCountRequest): Promise<number>;
|
|
583
586
|
}
|
|
584
|
-
export
|
|
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> {
|
|
587
|
+
export interface Table<T = any, TKey = IndexableType, TInsertType = T> {
|
|
594
588
|
db: Dexie;
|
|
595
589
|
name: string;
|
|
596
590
|
schema: TableSchema;
|
|
597
|
-
hook: TableHooks<T,
|
|
591
|
+
hook: TableHooks<T, TKey>;
|
|
598
592
|
core: DBCoreTable;
|
|
599
|
-
get(key:
|
|
600
|
-
get<R>(key:
|
|
593
|
+
get(key: TKey): PromiseExtended<T | undefined>;
|
|
594
|
+
get<R>(key: TKey, thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
|
|
601
595
|
get(equalityCriterias: {
|
|
602
596
|
[key: string]: any;
|
|
603
597
|
}): PromiseExtended<T | undefined>;
|
|
604
598
|
get<R>(equalityCriterias: {
|
|
605
599
|
[key: string]: any;
|
|
606
600
|
}, thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
|
|
607
|
-
where(index: string | string[]): WhereClause<T,
|
|
601
|
+
where(index: string | string[]): WhereClause<T, TKey>;
|
|
608
602
|
where(equalityCriterias: {
|
|
609
603
|
[key: string]: any;
|
|
610
|
-
}): Collection<T,
|
|
611
|
-
filter(fn: (obj: T) => boolean): Collection<T,
|
|
604
|
+
}): Collection<T, TKey>;
|
|
605
|
+
filter(fn: (obj: T) => boolean): Collection<T, TKey>;
|
|
612
606
|
count(): PromiseExtended<number>;
|
|
613
607
|
count<R>(thenShortcut: ThenShortcut<number, R>): PromiseExtended<R>;
|
|
614
|
-
offset(n: number): Collection<T,
|
|
615
|
-
limit(n: number): Collection<T,
|
|
608
|
+
offset(n: number): Collection<T, TKey>;
|
|
609
|
+
limit(n: number): Collection<T, TKey>;
|
|
616
610
|
each(callback: (obj: T, cursor: {
|
|
617
611
|
key: any;
|
|
618
|
-
primaryKey:
|
|
612
|
+
primaryKey: TKey;
|
|
619
613
|
}) => any): PromiseExtended<void>;
|
|
620
614
|
toArray(): PromiseExtended<Array<T>>;
|
|
621
615
|
toArray<R>(thenShortcut: ThenShortcut<T[], R>): PromiseExtended<R>;
|
|
622
|
-
toCollection(): Collection<T,
|
|
623
|
-
orderBy(index: string | string[]): Collection<T,
|
|
624
|
-
reverse(): Collection<T,
|
|
616
|
+
toCollection(): Collection<T, TKey>;
|
|
617
|
+
orderBy(index: string | string[]): Collection<T, TKey>;
|
|
618
|
+
reverse(): Collection<T, TKey>;
|
|
625
619
|
mapToClass(constructor: Function): Function;
|
|
626
|
-
add(item:
|
|
627
|
-
update(key:
|
|
620
|
+
add(item: TInsertType, key?: TKey): PromiseExtended<TKey>;
|
|
621
|
+
update(key: TKey | T, changes: UpdateSpec<T> | ((obj: T, ctx: {
|
|
628
622
|
value: any;
|
|
629
623
|
primKey: IndexableType;
|
|
630
624
|
}) => void | boolean)): PromiseExtended<number>;
|
|
631
|
-
put(item:
|
|
632
|
-
delete(key:
|
|
625
|
+
put(item: TInsertType, key?: TKey): PromiseExtended<TKey>;
|
|
626
|
+
delete(key: TKey): PromiseExtended<void>;
|
|
633
627
|
clear(): PromiseExtended<void>;
|
|
634
|
-
bulkGet(keys:
|
|
635
|
-
bulkAdd<B extends boolean>(items: readonly
|
|
628
|
+
bulkGet(keys: TKey[]): PromiseExtended<(T | undefined)[]>;
|
|
629
|
+
bulkAdd<B extends boolean>(items: readonly TInsertType[], keys: IndexableTypeArrayReadonly, options: {
|
|
636
630
|
allKeys: B;
|
|
637
|
-
}): PromiseExtended<B extends true ?
|
|
638
|
-
bulkAdd<B extends boolean>(items: readonly
|
|
631
|
+
}): PromiseExtended<B extends true ? TKey[] : TKey>;
|
|
632
|
+
bulkAdd<B extends boolean>(items: readonly TInsertType[], options: {
|
|
639
633
|
allKeys: B;
|
|
640
|
-
}): PromiseExtended<B extends true ?
|
|
641
|
-
bulkAdd(items: readonly
|
|
634
|
+
}): PromiseExtended<B extends true ? TKey[] : TKey>;
|
|
635
|
+
bulkAdd(items: readonly TInsertType[], keys?: IndexableTypeArrayReadonly, options?: {
|
|
642
636
|
allKeys: boolean;
|
|
643
|
-
}): PromiseExtended<
|
|
644
|
-
bulkPut<B extends boolean>(items: readonly
|
|
637
|
+
}): PromiseExtended<TKey>;
|
|
638
|
+
bulkPut<B extends boolean>(items: readonly TInsertType[], keys: IndexableTypeArrayReadonly, options: {
|
|
645
639
|
allKeys: B;
|
|
646
|
-
}): PromiseExtended<B extends true ?
|
|
647
|
-
bulkPut<B extends boolean>(items: readonly
|
|
640
|
+
}): PromiseExtended<B extends true ? TKey[] : TKey>;
|
|
641
|
+
bulkPut<B extends boolean>(items: readonly TInsertType[], options: {
|
|
648
642
|
allKeys: B;
|
|
649
|
-
}): PromiseExtended<B extends true ?
|
|
650
|
-
bulkPut(items: readonly
|
|
643
|
+
}): PromiseExtended<B extends true ? TKey[] : TKey>;
|
|
644
|
+
bulkPut(items: readonly TInsertType[], keys?: IndexableTypeArrayReadonly, options?: {
|
|
651
645
|
allKeys: boolean;
|
|
652
|
-
}): PromiseExtended<
|
|
653
|
-
|
|
646
|
+
}): PromiseExtended<TKey>;
|
|
647
|
+
bulkUpdate(keysAndChanges: ReadonlyArray<{
|
|
648
|
+
key: TKey;
|
|
649
|
+
changes: UpdateSpec<T>;
|
|
650
|
+
}>): PromiseExtended<number>;
|
|
651
|
+
bulkDelete(keys: TKey[]): PromiseExtended<void>;
|
|
654
652
|
}
|
|
655
653
|
export interface Version {
|
|
656
654
|
stores(schema: {
|
|
@@ -1039,6 +1037,27 @@ export class Entity<TDexieSubClass extends Dexie = Dexie> {
|
|
|
1039
1037
|
protected readonly db: TDexieSubClass;
|
|
1040
1038
|
table(): TableProp<TDexieSubClass>;
|
|
1041
1039
|
}
|
|
1040
|
+
export type IsStrictlyAny<T> = (T extends never ? true : false) extends false ? false : true;
|
|
1041
|
+
/** Extract the union of literal method names in T
|
|
1042
|
+
*/
|
|
1043
|
+
export type MethodProps<T> = {
|
|
1044
|
+
[P in keyof T]: IsStrictlyAny<T[P]> extends true ? never // Plain property of type any (not method)
|
|
1045
|
+
: T[P] extends (...args: any[]) => any ? P // a function (method)
|
|
1046
|
+
: never;
|
|
1047
|
+
}[keyof T];
|
|
1048
|
+
/** Default insert type of T is a subset of T where:
|
|
1049
|
+
* * given optional props (such as an auto-generated primary key) are made optional
|
|
1050
|
+
* * methods are omitted
|
|
1051
|
+
*/
|
|
1052
|
+
export type InsertType<T, OptionalProps extends keyof T> = Omit<T, OptionalProps | MethodProps<T>> & {
|
|
1053
|
+
[P in OptionalProps]?: T[P];
|
|
1054
|
+
};
|
|
1055
|
+
/** IDType extract the actual type of the primary key:
|
|
1056
|
+
* * If TKey is a literal type that names a property of T, extract the type using T[TKey]
|
|
1057
|
+
* * Else, use TKey as is.
|
|
1058
|
+
*/
|
|
1059
|
+
export type IDType<T, TKeyPropNameOrKeyType> = IsStrictlyAny<T> extends true ? TKeyPropNameOrKeyType : TKeyPropNameOrKeyType extends string ? TKeyPropNameOrKeyType extends keyof T ? T[TKeyPropNameOrKeyType] : TKeyPropNameOrKeyType : TKeyPropNameOrKeyType;
|
|
1060
|
+
export type EntityTable<T, TKeyPropName extends keyof T = never, TInsertType = InsertType<T, TKeyPropName>> = Table<T, IDType<T, TKeyPropName>, TInsertType>;
|
|
1042
1061
|
export declare var Dexie: DexieConstructor;
|
|
1043
1062
|
export interface _Table<T, TKey> extends Table<T, TKey> {
|
|
1044
1063
|
}
|
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.
|
|
7
|
+
* Version 4.0.1-alpha.7, Wed Jan 25 2023
|
|
8
8
|
*
|
|
9
9
|
* https://dexie.org
|
|
10
10
|
*
|
|
@@ -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.
|
|
1303
|
+
var DEXIE_VERSION = '4.0.1-alpha.7';
|
|
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
|
-
|
|
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
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
this.
|
|
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
|
|