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

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.10, Wed Mar 29 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;
@@ -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 Extract<T, P> = P extends keyof T ? T[P] : void;
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
- changeSpecs?: {
468
- [keyPath: string]: any;
469
- }[]; // changeSpec per key.
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 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> {
587
+ export interface Table<T = any, TKey = any, TInsertType = T> {
594
588
  db: Dexie;
595
589
  name: string;
596
590
  schema: TableSchema;
597
- hook: TableHooks<T, IDType<T, TKeyPropNameOrKeyType>>;
591
+ hook: TableHooks<T, TKey>;
598
592
  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>;
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, IDType<T, TKeyPropNameOrKeyType>>;
601
+ where(index: string | string[]): WhereClause<T, TKey>;
608
602
  where(equalityCriterias: {
609
603
  [key: string]: any;
610
- }): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
611
- filter(fn: (obj: T) => boolean): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
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, IDType<T, TKeyPropNameOrKeyType>>;
615
- limit(n: number): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
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: IDType<T, TKeyPropNameOrKeyType>;
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, IDType<T, TKeyPropNameOrKeyType>>;
623
- orderBy(index: string | string[]): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
624
- reverse(): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
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: 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: {
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: InsertType<T, TOpt, TKeyPropNameOrKeyType>, key?: IDType<T, TKeyPropNameOrKeyType>): PromiseExtended<IDType<T, TKeyPropNameOrKeyType>>;
632
- delete(key: IDType<T, TKeyPropNameOrKeyType>): PromiseExtended<void>;
625
+ put(item: TInsertType, key?: TKey): PromiseExtended<TKey>;
626
+ delete(key: TKey): PromiseExtended<void>;
633
627
  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: {
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 ? IDType<T, TKeyPropNameOrKeyType>[] : IDType<T, TKeyPropNameOrKeyType>>;
638
- bulkAdd<B extends boolean>(items: readonly InsertType<T, TOpt, TKeyPropNameOrKeyType>[], options: {
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 ? IDType<T, TKeyPropNameOrKeyType>[] : IDType<T, TKeyPropNameOrKeyType>>;
641
- bulkAdd(items: readonly InsertType<T, TOpt, TKeyPropNameOrKeyType>[], keys?: IndexableTypeArrayReadonly, options?: {
634
+ }): PromiseExtended<B extends true ? TKey[] : TKey>;
635
+ bulkAdd(items: readonly TInsertType[], keys?: IndexableTypeArrayReadonly, options?: {
642
636
  allKeys: boolean;
643
- }): PromiseExtended<IDType<T, TKeyPropNameOrKeyType>>;
644
- bulkPut<B extends boolean>(items: readonly InsertType<T, TOpt, TKeyPropNameOrKeyType>[], keys: IndexableTypeArrayReadonly, options: {
637
+ }): PromiseExtended<TKey>;
638
+ bulkPut<B extends boolean>(items: readonly TInsertType[], keys: IndexableTypeArrayReadonly, options: {
645
639
  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: {
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 ? IDType<T, TKeyPropNameOrKeyType>[] : IDType<T, TKeyPropNameOrKeyType>>;
650
- bulkPut(items: readonly InsertType<T, TOpt, TKeyPropNameOrKeyType>[], keys?: IndexableTypeArrayReadonly, options?: {
643
+ }): PromiseExtended<B extends true ? TKey[] : TKey>;
644
+ bulkPut(items: readonly TInsertType[], keys?: IndexableTypeArrayReadonly, options?: {
651
645
  allKeys: boolean;
652
- }): PromiseExtended<IDType<T, TKeyPropNameOrKeyType>>;
653
- bulkDelete(keys: IDType<T, TKeyPropNameOrKeyType>[]): PromiseExtended<void>;
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: {
@@ -969,10 +967,16 @@ declare global {
969
967
  readonly observable: symbol;
970
968
  }
971
969
  }
970
+ export interface Subscribable<T> {
971
+ subscribe(observer: Partial<Observer<T>>): Unsubscribable;
972
+ }
973
+ export interface Unsubscribable {
974
+ unsubscribe(): void;
975
+ }
972
976
  export interface Observable<T = any> {
973
- subscribe(onNext?: ((value: T) => void) | null, onError?: ((error: any) => void) | null, onComplete?: (() => void) | null): Subscription;
974
- subscribe(observer?: Observer<T> | null): Subscription;
975
- [Symbol.observable]: () => Observable<T>;
977
+ subscribe(observerOrNext?: Observer<T> | ((value: T) => void)): Subscription;
978
+ subscribe(next?: ((value: T) => void) | null, error?: ((error: any) => void) | null, complete?: (() => void) | null): Subscription;
979
+ [Symbol.observable]: () => Subscribable<T>;
976
980
  }
977
981
  export interface Subscription {
978
982
  unsubscribe(): void;
@@ -1039,6 +1043,27 @@ export class Entity<TDexieSubClass extends Dexie = Dexie> {
1039
1043
  protected readonly db: TDexieSubClass;
1040
1044
  table(): TableProp<TDexieSubClass>;
1041
1045
  }
1046
+ export type IsStrictlyAny<T> = (T extends never ? true : false) extends false ? false : true;
1047
+ /** Extract the union of literal method names in T
1048
+ */
1049
+ export type MethodProps<T> = {
1050
+ [P in keyof T]: IsStrictlyAny<T[P]> extends true ? never // Plain property of type any (not method)
1051
+ : T[P] extends (...args: any[]) => any ? P // a function (method)
1052
+ : never;
1053
+ }[keyof T];
1054
+ /** Default insert type of T is a subset of T where:
1055
+ * * given optional props (such as an auto-generated primary key) are made optional
1056
+ * * methods are omitted
1057
+ */
1058
+ export type InsertType<T, OptionalProps extends keyof T> = Omit<T, OptionalProps | MethodProps<T>> & {
1059
+ [P in OptionalProps]?: T[P];
1060
+ };
1061
+ /** IDType extract the actual type of the primary key:
1062
+ * * If TKey is a literal type that names a property of T, extract the type using T[TKey]
1063
+ * * Else, use TKey as is.
1064
+ */
1065
+ export type IDType<T, TKeyPropNameOrKeyType> = IsStrictlyAny<T> extends true ? TKeyPropNameOrKeyType : TKeyPropNameOrKeyType extends string ? TKeyPropNameOrKeyType extends keyof T ? T[TKeyPropNameOrKeyType] : TKeyPropNameOrKeyType : TKeyPropNameOrKeyType;
1066
+ export type EntityTable<T, TKeyPropName extends keyof T = never, TInsertType = InsertType<T, TKeyPropName>> = Table<T, IDType<T, TKeyPropName>, TInsertType>;
1042
1067
  export declare var Dexie: DexieConstructor;
1043
1068
  export interface _Table<T, TKey> extends Table<T, TKey> {
1044
1069
  }