dexie 3.2.1-beta.1 → 4.0.0-alpha.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/README.md CHANGED
@@ -44,7 +44,38 @@ Dexie provides a neat database API with a well thought-through API design, robus
44
44
  </head>
45
45
  </html>
46
46
  ```
47
- Yes, it's that simple.
47
+ Yes, it's that simple.
48
+
49
+ An equivalent modern version (works in all modern browsers):
50
+
51
+ ```html
52
+ <!doctype html>
53
+ <html>
54
+ <head>
55
+ <script type="module">
56
+ import Dexie from "https://unpkg.com/dexie@latest/dist/modern/dexie.mjs";
57
+ //
58
+ // Declare Database
59
+ //
60
+ const db = new Dexie("FriendDatabase");
61
+ db.version(1).stores({
62
+ friends: "++id,name,age"
63
+ });
64
+
65
+ //
66
+ // Manipulate and Query Database
67
+ //
68
+ try {
69
+ await db.friends.add({name: "Josephine", age: 21});
70
+ const youngFriends = await db.friends.where("age").below(25).toArray();
71
+ alert (`My young friends: ${JSON.stringify(youngFriends)}`);
72
+ } catch (e) {
73
+ alert (`Error: ${e}`);
74
+ }
75
+ </script>
76
+ </head>
77
+ </html>
78
+ ```
48
79
 
49
80
  [Tutorial](https://dexie.org/docs/Tutorial)
50
81
 
@@ -110,40 +141,10 @@ update(key: Key, changes: { [keyPath: string]: any }): Promise;
110
141
  ```
111
142
  This is a mix of methods from [WhereClause](https://dexie.org/docs/WhereClause/WhereClause), [Table](https://dexie.org/docs/Table/Table) and [Collection](https://dexie.org/docs/Collection/Collection). Dive into the [API reference](https://dexie.org/docs/API-Reference) to see the details.
112
143
 
113
- #### Hello World (ES2016 / ES7)
114
- ```js
115
- import Dexie from 'dexie';
116
-
117
- //
118
- // Declare Database
119
- //
120
- const db = new Dexie("FriendDatabase");
121
- db.version(1).stores({ friends: "++id,name,age" });
122
-
123
- db.transaction('rw', db.friends, async() => {
124
-
125
- // Make sure we have something in DB:
126
- if ((await db.friends.where({name: 'Josephine'}).count()) === 0) {
127
- const id = await db.friends.add({name: "Josephine", age: 21});
128
- alert (`Addded friend with id ${id}`);
129
- }
130
-
131
- // Query:
132
- const youngFriends = await db.friends.where("age").below(25).toArray();
133
-
134
- // Show result:
135
- alert ("My young friends: " + JSON.stringify(youngFriends));
136
-
137
- }).catch(e => {
138
- alert(e.stack || e);
139
- });
140
-
141
- ```
142
-
143
144
  #### Hello World (Typescript)
144
145
 
145
146
  ```js
146
- import Dexie from 'dexie';
147
+ import Dexie, { Table } from 'dexie';
147
148
 
148
149
  interface Friend {
149
150
  id?: number;
@@ -155,14 +156,13 @@ interface Friend {
155
156
  // Declare Database
156
157
  //
157
158
  class FriendDatabase extends Dexie {
158
- public friends: Dexie.Table<Friend, number>; // id is number in this case
159
+ public friends!: Table<Friend, number>; // id is number in this case
159
160
 
160
161
  public constructor() {
161
162
  super("FriendDatabase");
162
163
  this.version(1).stores({
163
164
  friends: "++id,name,age"
164
165
  });
165
- this.friends = this.table("friends");
166
166
  }
167
167
  }
168
168
 
@@ -212,13 +212,21 @@ Download
212
212
  --------
213
213
  For those who don't like package managers, here's the download links:
214
214
 
215
- https://unpkg.com/dexie@latest/dist/dexie.js
215
+ ### Legacy:
216
+ https://unpkg.com/dexie@latest/dist/dexie.min.js
216
217
 
217
- https://unpkg.com/dexie@latest/dist/dexie.js.map
218
+ https://unpkg.com/dexie@latest/dist/dexie.min.js.map
218
219
 
220
+ ### Modern:
221
+ https://unpkg.com/dexie@latest/dist/modern/dexie.min.mjs
222
+
223
+ https://unpkg.com/dexie@latest/dist/modern/dexie.min.mjs.map
224
+
225
+ ### Typings:
219
226
  https://unpkg.com/dexie@latest/dist/dexie.d.ts
220
227
 
221
228
 
229
+
222
230
  Contributing
223
231
  ============
224
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.
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.2.1-beta.1, Fri Nov 19 2021
7
+ * Version 4.0.0-alpha.1, Sun Dec 19 2021
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -51,7 +51,78 @@ export interface DexieEventSet {
51
51
  ]);
52
52
  }): DexieEvent;
53
53
  }
54
- export type TransactionMode = "readonly" | "readwrite" | "r" | "r!" | "r?" | "rw" | "rw!" | "rw?";
54
+ export interface TransactionEvents extends DexieEventSet {
55
+ (eventName: "complete", subscriber: () => any): void;
56
+ (eventName: "abort", subscriber: () => any): void;
57
+ (eventName: "error", subscriber: (error: any) => any): void;
58
+ complete: DexieEvent;
59
+ abort: DexieEvent;
60
+ error: DexieEvent;
61
+ }
62
+ export interface Transaction {
63
+ db: Dexie;
64
+ active: boolean;
65
+ mode: IDBTransactionMode;
66
+ //tables: { [type: string]: Table<any, any> }; Deprecated since 2.0. Obsolete from v3.0.
67
+ storeNames: Array<string>;
68
+ parent?: Transaction;
69
+ on: TransactionEvents;
70
+ abort(): void;
71
+ table(tableName: string): Table<any, any>;
72
+ table<T>(tableName: string): Table<T, any>;
73
+ table<T, Key>(tableName: string): Table<T, Key>;
74
+ }
75
+ export interface CreatingHookContext<T, Key> {
76
+ onsuccess?: (primKey: Key) => void;
77
+ onerror?: (err: any) => void;
78
+ }
79
+ export interface UpdatingHookContext<T, Key> {
80
+ onsuccess?: (updatedObj: T) => void;
81
+ onerror?: (err: any) => void;
82
+ }
83
+ export interface DeletingHookContext<T, Key> {
84
+ onsuccess?: () => void;
85
+ onerror?: (err: any) => void;
86
+ }
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;
89
+ (eventName: "reading", subscriber: (obj: T) => T | any): void;
90
+ (eventName: "updating", subscriber: (this: UpdatingHookContext<T, TKey>, modifications: Object, primKey: TKey, obj: T, transaction: Transaction) => any): void;
91
+ (eventName: "deleting", subscriber: (this: DeletingHookContext<T, TKey>, primKey: TKey, obj: T, transaction: Transaction) => any): void;
92
+ creating: DexieEvent;
93
+ reading: DexieEvent;
94
+ updating: DexieEvent;
95
+ deleting: DexieEvent;
96
+ }
97
+ export type ThenShortcut<T, TResult> = (value: T) => TResult | PromiseLike<TResult>;
98
+ export interface WhereClause<T = any, TKey = IndexableType> {
99
+ above(key: any): Collection<T, TKey>;
100
+ aboveOrEqual(key: any): Collection<T, TKey>;
101
+ anyOf(keys: ReadonlyArray<IndexableType>): Collection<T, TKey>;
102
+ anyOf(...keys: Array<IndexableType>): Collection<T, TKey>;
103
+ anyOfIgnoreCase(keys: string[]): Collection<T, TKey>;
104
+ anyOfIgnoreCase(...keys: string[]): Collection<T, TKey>;
105
+ below(key: any): Collection<T, TKey>;
106
+ belowOrEqual(key: any): Collection<T, TKey>;
107
+ between(lower: any, upper: any, includeLower?: boolean, includeUpper?: boolean): Collection<T, TKey>;
108
+ equals(key: IndexableType): Collection<T, TKey>;
109
+ equalsIgnoreCase(key: string): Collection<T, TKey>;
110
+ inAnyRange(ranges: ReadonlyArray<{
111
+ 0: any;
112
+ 1: any;
113
+ }>, options?: {
114
+ includeLowers?: boolean;
115
+ includeUppers?: boolean;
116
+ }): Collection<T, TKey>;
117
+ startsWith(key: string): Collection<T, TKey>;
118
+ startsWithAnyOf(prefixes: string[]): Collection<T, TKey>;
119
+ startsWithAnyOf(...prefixes: string[]): Collection<T, TKey>;
120
+ startsWithIgnoreCase(key: string): Collection<T, TKey>;
121
+ startsWithAnyOfIgnoreCase(prefixes: string[]): Collection<T, TKey>;
122
+ startsWithAnyOfIgnoreCase(...prefixes: string[]): Collection<T, TKey>;
123
+ noneOf(keys: ReadonlyArray<IndexableType>): Collection<T, TKey>;
124
+ notEqual(key: IndexableType): Collection<T, TKey>;
125
+ }
55
126
  export interface PromiseExtendedConstructor extends PromiseConstructor {
56
127
  readonly prototype: PromiseExtended;
57
128
  new <T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): PromiseExtended<T>;
@@ -285,9 +356,17 @@ export interface PromiseExtended<T = any> extends Promise<T> {
285
356
  finally<U>(onFinally?: () => U | PromiseLike<U>): PromiseExtended<T>;
286
357
  timeout(ms: number, msg?: string): PromiseExtended<T>;
287
358
  }
288
- export type ThenShortcut<T, TResult> = (value: T) => TResult | PromiseLike<TResult>;
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
361
+ ? never : T[P] extends object ? P | `${P}.${KeyPaths<T[P]>}` : P : never;
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>;
365
+ export type UpdateSpec<T> = {
366
+ [KP in KeyPaths<T>]?: KeyPathValue<T, KP>;
367
+ };
289
368
  export interface Collection<T = any, TKey = IndexableType> {
290
- //db: Database;
369
+ db: Dexie;
291
370
  and(filter: (x: T) => boolean): Collection<T, TKey>;
292
371
  clone(props?: Object): Collection<T, TKey>;
293
372
  count(): PromiseExtended<number>;
@@ -335,91 +414,7 @@ export interface Collection<T = any, TKey = IndexableType> {
335
414
  modify(changeCallback: (obj: T, ctx: {
336
415
  value: T;
337
416
  }) => void | boolean): PromiseExtended<number>;
338
- modify(changes: {
339
- [keyPath: string]: any;
340
- }): PromiseExtended<number>;
341
- }
342
- export interface WhereClause<T = any, TKey = IndexableType> {
343
- above(key: any): Collection<T, TKey>;
344
- aboveOrEqual(key: any): Collection<T, TKey>;
345
- anyOf(keys: ReadonlyArray<IndexableType>): Collection<T, TKey>;
346
- anyOf(...keys: Array<IndexableType>): Collection<T, TKey>;
347
- anyOfIgnoreCase(keys: string[]): Collection<T, TKey>;
348
- anyOfIgnoreCase(...keys: string[]): Collection<T, TKey>;
349
- below(key: any): Collection<T, TKey>;
350
- belowOrEqual(key: any): Collection<T, TKey>;
351
- between(lower: any, upper: any, includeLower?: boolean, includeUpper?: boolean): Collection<T, TKey>;
352
- equals(key: IndexableType): Collection<T, TKey>;
353
- equalsIgnoreCase(key: string): Collection<T, TKey>;
354
- inAnyRange(ranges: ReadonlyArray<{
355
- 0: any;
356
- 1: any;
357
- }>, options?: {
358
- includeLowers?: boolean;
359
- includeUppers?: boolean;
360
- }): Collection<T, TKey>;
361
- startsWith(key: string): Collection<T, TKey>;
362
- startsWithAnyOf(prefixes: string[]): Collection<T, TKey>;
363
- startsWithAnyOf(...prefixes: string[]): Collection<T, TKey>;
364
- startsWithIgnoreCase(key: string): Collection<T, TKey>;
365
- startsWithAnyOfIgnoreCase(prefixes: string[]): Collection<T, TKey>;
366
- startsWithAnyOfIgnoreCase(...prefixes: string[]): Collection<T, TKey>;
367
- noneOf(keys: ReadonlyArray<IndexableType>): Collection<T, TKey>;
368
- notEqual(key: IndexableType): Collection<T, TKey>;
369
- }
370
- export interface Database {
371
- readonly name: string;
372
- readonly tables: Table[];
373
- table<T = any, TKey = any>(tableName: string): Table<T, TKey>;
374
- transaction<U>(mode: TransactionMode, table: Table, scope: () => PromiseLike<U> | U): PromiseExtended<U>;
375
- transaction<U>(mode: TransactionMode, table: Table, table2: Table, scope: () => PromiseLike<U> | U): PromiseExtended<U>;
376
- transaction<U>(mode: TransactionMode, table: Table, table2: Table, table3: Table, scope: () => PromiseLike<U> | U): PromiseExtended<U>;
377
- transaction<U>(mode: TransactionMode, table: Table, table2: Table, table3: Table, table4: Table, scope: () => PromiseLike<U> | U): PromiseExtended<U>;
378
- transaction<U>(mode: TransactionMode, table: Table, table2: Table, table3: Table, table4: Table, table5: Table, scope: () => PromiseLike<U> | U): PromiseExtended<U>;
379
- transaction<U>(mode: TransactionMode, tables: Table[], scope: () => PromiseLike<U> | U): PromiseExtended<U>;
380
- }
381
- export interface TransactionEvents extends DexieEventSet {
382
- (eventName: "complete", subscriber: () => any): void;
383
- (eventName: "abort", subscriber: () => any): void;
384
- (eventName: "error", subscriber: (error: any) => any): void;
385
- complete: DexieEvent;
386
- abort: DexieEvent;
387
- error: DexieEvent;
388
- }
389
- export interface Transaction {
390
- db: Database;
391
- active: boolean;
392
- mode: IDBTransactionMode;
393
- //tables: { [type: string]: Table<any, any> }; Deprecated since 2.0. Obsolete from v3.0.
394
- storeNames: Array<string>;
395
- parent?: Transaction;
396
- on: TransactionEvents;
397
- abort(): void;
398
- table(tableName: string): Table<any, any>;
399
- table<T>(tableName: string): Table<T, any>;
400
- table<T, Key>(tableName: string): Table<T, Key>;
401
- }
402
- export interface CreatingHookContext<T, Key> {
403
- onsuccess?: (primKey: Key) => void;
404
- onerror?: (err: any) => void;
405
- }
406
- export interface UpdatingHookContext<T, Key> {
407
- onsuccess?: (updatedObj: T) => void;
408
- onerror?: (err: any) => void;
409
- }
410
- export interface DeletingHookContext<T, Key> {
411
- onsuccess?: () => void;
412
- onerror?: (err: any) => void;
413
- }
414
- export interface TableHooks<T = any, TKey = IndexableType> extends DexieEventSet {
415
- (eventName: "creating", subscriber: (this: CreatingHookContext<T, TKey>, primKey: TKey, obj: T, transaction: Transaction) => any): void;
416
- (eventName: "reading", subscriber: (obj: T) => T | any): void;
417
- (eventName: "updating", subscriber: (this: UpdatingHookContext<T, TKey>, modifications: Object, primKey: TKey, obj: T, transaction: Transaction) => any): void;
418
- (eventName: "deleting", subscriber: (this: DeletingHookContext<T, TKey>, primKey: TKey, obj: T, transaction: Transaction) => any): void;
419
- creating: DexieEvent;
420
- reading: DexieEvent;
421
- updating: DexieEvent;
422
- deleting: DexieEvent;
417
+ modify(changes: UpdateSpec<T>): PromiseExtended<number>;
423
418
  }
424
419
  export const enum DBCoreRangeType {
425
420
  Equal = 1,
@@ -452,7 +447,7 @@ export interface DBCoreMutateResponse {
452
447
  export interface DBCoreAddRequest {
453
448
  type: "add";
454
449
  trans: DBCoreTransaction;
455
- values: any[];
450
+ values: readonly any[];
456
451
  keys?: any[];
457
452
  /** @deprecated Will always get results since 3.1.0-alpha.5 */
458
453
  wantResults?: boolean;
@@ -460,7 +455,7 @@ export interface DBCoreAddRequest {
460
455
  export interface DBCorePutRequest {
461
456
  type: "put";
462
457
  trans: DBCoreTransaction;
463
- values: any[];
458
+ values: readonly any[];
464
459
  keys?: any[];
465
460
  criteria?: {
466
461
  index: string | null;
@@ -586,66 +581,76 @@ export interface DBCoreTable {
586
581
  openCursor(req: DBCoreOpenCursorRequest): Promise<DBCoreCursor | null>;
587
582
  count(req: DBCoreCountRequest): Promise<number>;
588
583
  }
589
- export interface Table<T = any, TKey = IndexableType> {
590
- db: Database;
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> {
594
+ db: Dexie;
591
595
  name: string;
592
596
  schema: TableSchema;
593
- hook: TableHooks<T, TKey>;
597
+ hook: TableHooks<T, IDType<T, TKeyPropNameOrKeyType>>;
594
598
  core: DBCoreTable;
595
- get(key: TKey): PromiseExtended<T | undefined>;
596
- get<R>(key: TKey, thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
599
+ get(key: IDType<T, TKeyPropNameOrKeyType>): PromiseExtended<T | undefined>;
600
+ get<R>(key: IDType<T, TKeyPropNameOrKeyType>, thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
597
601
  get(equalityCriterias: {
598
602
  [key: string]: any;
599
603
  }): PromiseExtended<T | undefined>;
600
604
  get<R>(equalityCriterias: {
601
605
  [key: string]: any;
602
606
  }, thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
603
- where(index: string | string[]): WhereClause<T, TKey>;
607
+ where(index: string | string[]): WhereClause<T, IDType<T, TKeyPropNameOrKeyType>>;
604
608
  where(equalityCriterias: {
605
609
  [key: string]: any;
606
- }): Collection<T, TKey>;
607
- filter(fn: (obj: T) => boolean): Collection<T, TKey>;
610
+ }): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
611
+ filter(fn: (obj: T) => boolean): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
608
612
  count(): PromiseExtended<number>;
609
613
  count<R>(thenShortcut: ThenShortcut<number, R>): PromiseExtended<R>;
610
- offset(n: number): Collection<T, TKey>;
611
- limit(n: number): Collection<T, TKey>;
614
+ offset(n: number): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
615
+ limit(n: number): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
612
616
  each(callback: (obj: T, cursor: {
613
617
  key: any;
614
- primaryKey: TKey;
618
+ primaryKey: IDType<T, TKeyPropNameOrKeyType>;
615
619
  }) => any): PromiseExtended<void>;
616
620
  toArray(): PromiseExtended<Array<T>>;
617
621
  toArray<R>(thenShortcut: ThenShortcut<T[], R>): PromiseExtended<R>;
618
- toCollection(): Collection<T, TKey>;
619
- orderBy(index: string | string[]): Collection<T, TKey>;
620
- reverse(): Collection<T, TKey>;
622
+ toCollection(): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
623
+ orderBy(index: string | string[]): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
624
+ reverse(): Collection<T, IDType<T, TKeyPropNameOrKeyType>>;
621
625
  mapToClass(constructor: Function): Function;
622
- add(item: T, key?: TKey): PromiseExtended<TKey>;
623
- update(key: TKey | T, changes: {
624
- [keyPath: string]: any;
625
- }): PromiseExtended<number>;
626
- put(item: T, key?: TKey): PromiseExtended<TKey>;
627
- delete(key: TKey): PromiseExtended<void>;
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: {
628
+ value: any;
629
+ primKey: IndexableType;
630
+ }) => 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>;
628
633
  clear(): PromiseExtended<void>;
629
- bulkGet(keys: TKey[]): PromiseExtended<(T | undefined)[]>;
630
- bulkAdd<B extends boolean>(items: readonly T[], keys: IndexableTypeArrayReadonly, options: {
634
+ bulkGet(keys: IDType<T, TKeyPropNameOrKeyType>[]): PromiseExtended<(T | undefined)[]>;
635
+ bulkAdd<B extends boolean>(items: readonly InsertType<T, TOpt, TKeyPropNameOrKeyType>[], keys: IndexableTypeArrayReadonly, options: {
631
636
  allKeys: B;
632
- }): PromiseExtended<B extends true ? TKey[] : TKey>;
633
- bulkAdd<B extends boolean>(items: readonly T[], options: {
637
+ }): PromiseExtended<B extends true ? IDType<T, TKeyPropNameOrKeyType>[] : IDType<T, TKeyPropNameOrKeyType>>;
638
+ bulkAdd<B extends boolean>(items: readonly InsertType<T, TOpt, TKeyPropNameOrKeyType>[], options: {
634
639
  allKeys: B;
635
- }): PromiseExtended<B extends true ? TKey[] : TKey>;
636
- bulkAdd(items: readonly T[], keys?: IndexableTypeArrayReadonly, options?: {
640
+ }): PromiseExtended<B extends true ? IDType<T, TKeyPropNameOrKeyType>[] : IDType<T, TKeyPropNameOrKeyType>>;
641
+ bulkAdd(items: readonly InsertType<T, TOpt, TKeyPropNameOrKeyType>[], keys?: IndexableTypeArrayReadonly, options?: {
637
642
  allKeys: boolean;
638
- }): PromiseExtended<TKey>;
639
- bulkPut<B extends boolean>(items: readonly T[], keys: IndexableTypeArrayReadonly, options: {
643
+ }): PromiseExtended<IDType<T, TKeyPropNameOrKeyType>>;
644
+ bulkPut<B extends boolean>(items: readonly InsertType<T, TOpt, TKeyPropNameOrKeyType>[], keys: IndexableTypeArrayReadonly, options: {
640
645
  allKeys: B;
641
- }): PromiseExtended<B extends true ? TKey[] : TKey>;
642
- bulkPut<B extends boolean>(items: readonly T[], options: {
646
+ }): PromiseExtended<B extends true ? IDType<T, TKeyPropNameOrKeyType>[] : IDType<T, TKeyPropNameOrKeyType>>;
647
+ bulkPut<B extends boolean>(items: readonly InsertType<T, TOpt, TKeyPropNameOrKeyType>[], options: {
643
648
  allKeys: B;
644
- }): PromiseExtended<B extends true ? TKey[] : TKey>;
645
- bulkPut(items: readonly T[], keys?: IndexableTypeArrayReadonly, options?: {
649
+ }): PromiseExtended<B extends true ? IDType<T, TKeyPropNameOrKeyType>[] : IDType<T, TKeyPropNameOrKeyType>>;
650
+ bulkPut(items: readonly InsertType<T, TOpt, TKeyPropNameOrKeyType>[], keys?: IndexableTypeArrayReadonly, options?: {
646
651
  allKeys: boolean;
647
- }): PromiseExtended<TKey>;
648
- bulkDelete(keys: TKey[]): PromiseExtended<void>;
652
+ }): PromiseExtended<IDType<T, TKeyPropNameOrKeyType>>;
653
+ bulkDelete(keys: IDType<T, TKeyPropNameOrKeyType>[]): PromiseExtended<void>;
649
654
  }
650
655
  export interface Version {
651
656
  stores(schema: {
@@ -710,6 +715,7 @@ export interface GlobalDexieEvents extends DexieEventSet {
710
715
  (eventName: "storagemutated", subscriber: (parts: ObservabilitySet) => any): void;
711
716
  storagemutated: DexieOnStorageMutatedEvent;
712
717
  }
718
+ export type TransactionMode = "readonly" | "readwrite" | "r" | "r!" | "r?" | "rw" | "rw!" | "rw?";
713
719
  export type DbSchema = {
714
720
  [tableName: string]: TableSchema;
715
721
  };
@@ -724,7 +730,20 @@ export interface Middleware<TStack extends {
724
730
  export interface DexieStacks {
725
731
  dbcore: DBCore;
726
732
  }
727
- export interface Dexie extends Database {
733
+ export type TableProp<DX extends Dexie> = {
734
+ [K in keyof DX]: DX[K] extends {
735
+ schema: any;
736
+ get: any;
737
+ put: any;
738
+ add: any;
739
+ where: any;
740
+ } ? K : never;
741
+ }[keyof DX] & string;
742
+ export type TXWithTables<DX extends Dexie> = Dexie extends DX ? Transaction // If not subclassed, just expect a Transaction without table props
743
+ : Transaction & {
744
+ [P in TableProp<DX>]: DX[P];
745
+ };
746
+ export interface Dexie {
728
747
  readonly name: string;
729
748
  readonly tables: Table[];
730
749
  readonly verno: number;
@@ -734,23 +753,18 @@ export interface Dexie extends Database {
734
753
  };
735
754
  readonly core: DBCore;
736
755
  _createTransaction: (this: Dexie, mode: IDBTransactionMode, storeNames: ArrayLike<string>, dbschema: DbSchema, parentTransaction?: Transaction | null) => Transaction;
756
+ readonly _novip: Dexie;
737
757
  _dbSchema: DbSchema;
738
758
  version(versionNumber: number): Version;
739
759
  on: DbEvents;
740
760
  open(): PromiseExtended<Dexie>;
741
761
  table<T = any, TKey = IndexableType>(tableName: string): Table<T, TKey>;
742
- transaction<U>(mode: TransactionMode, table: Table, scope: (trans: Transaction) => PromiseLike<U> | U): PromiseExtended<U>;
743
- transaction<U>(mode: TransactionMode, table: string, scope: (trans: Transaction) => PromiseLike<U> | U): PromiseExtended<U>;
744
- transaction<U>(mode: TransactionMode, table: Table, table2: Table, scope: (trans: Transaction) => PromiseLike<U> | U): PromiseExtended<U>;
745
- transaction<U>(mode: TransactionMode, table: string, table2: string, scope: (trans: Transaction) => PromiseLike<U> | U): PromiseExtended<U>;
746
- transaction<U>(mode: TransactionMode, table: Table, table2: Table, table3: Table, scope: (trans: Transaction) => PromiseLike<U> | U): PromiseExtended<U>;
747
- transaction<U>(mode: TransactionMode, table: string, table2: string, table3: string, scope: (trans: Transaction) => PromiseLike<U> | U): PromiseExtended<U>;
748
- transaction<U>(mode: TransactionMode, table: Table, table2: Table, table3: Table, table4: Table, scope: (trans: Transaction) => PromiseLike<U> | U): PromiseExtended<U>;
749
- transaction<U>(mode: TransactionMode, table: string, table2: string, table3: string, table4: string, scope: (trans: Transaction) => PromiseLike<U> | U): PromiseExtended<U>;
750
- transaction<U>(mode: TransactionMode, table: Table, table2: Table, table3: Table, table4: Table, table5: Table, scope: (trans: Transaction) => PromiseLike<U> | U): PromiseExtended<U>;
751
- transaction<U>(mode: TransactionMode, table: string, table2: string, table3: string, table4: string, table5: string, scope: (trans: Transaction) => PromiseLike<U> | U): PromiseExtended<U>;
752
- transaction<U>(mode: TransactionMode, tables: Table[], scope: (trans: Transaction) => PromiseLike<U> | U): PromiseExtended<U>;
753
- transaction<U>(mode: TransactionMode, tables: string[], scope: (trans: Transaction) => PromiseLike<U> | U): PromiseExtended<U>;
762
+ transaction<U>(mode: TransactionMode, tables: readonly (string | Table)[], scope: (trans: TXWithTables<this>) => PromiseLike<U> | U): PromiseExtended<U>;
763
+ transaction<U>(mode: TransactionMode, table: string | Table, scope: (trans: TXWithTables<this>) => PromiseLike<U> | U): PromiseExtended<U>;
764
+ transaction<U>(mode: TransactionMode, table: string | Table, table2: string | Table, scope: (trans: TXWithTables<this>) => PromiseLike<U> | U): PromiseExtended<U>;
765
+ transaction<U>(mode: TransactionMode, table: string | Table, table2: string | Table, table3: string | Table, scope: (trans: TXWithTables<this>) => PromiseLike<U> | U): PromiseExtended<U>;
766
+ transaction<U>(mode: TransactionMode, table: string | Table, table2: string | Table, table3: string | Table, table4: string | Table, scope: (trans: TXWithTables<this>) => PromiseLike<U> | U): PromiseExtended<U>;
767
+ transaction<U>(mode: TransactionMode, table: string | Table, table2: string | Table, table3: string | Table, table5: string | Table, scope: (trans: TXWithTables<this>) => PromiseLike<U> | U): PromiseExtended<U>;
754
768
  close(): void;
755
769
  delete(): PromiseExtended<void>;
756
770
  isOpen(): boolean;
@@ -976,9 +990,9 @@ export interface DexieConstructor extends DexieExceptionClasses {
976
990
  liveQuery<T>(fn: () => T | Promise<T>): Observable<T>;
977
991
  extendObservabilitySet(target: ObservabilitySet, newSet: ObservabilitySet): ObservabilitySet;
978
992
  override<F>(origFunc: F, overridedFactory: (fn: any) => any): F; // ?
979
- getByKeyPath(obj: Object, keyPath: string): any;
980
- setByKeyPath(obj: Object, keyPath: string, value: any): void;
981
- delByKeyPath(obj: Object, keyPath: string): void;
993
+ getByKeyPath(obj: Object, keyPath: string | string[]): any;
994
+ setByKeyPath(obj: Object, keyPath: string | string[], value: any): void;
995
+ delByKeyPath(obj: Object, keyPath: string | string[]): void;
982
996
  shallowClone<T>(obj: T): T;
983
997
  deepClone<T>(obj: T): T;
984
998
  asap(fn: Function): void; //?
@@ -995,6 +1009,11 @@ export interface DexieConstructor extends DexieExceptionClasses {
995
1009
  on: GlobalDexieEvents;
996
1010
  errnames: DexieErrors;
997
1011
  }
1012
+ export class Entity<TDexieSubClass extends Dexie = Dexie> {
1013
+ protected constructor();
1014
+ protected readonly db: TDexieSubClass;
1015
+ table(): TableProp<TDexieSubClass>;
1016
+ }
998
1017
  export declare var Dexie: DexieConstructor;
999
1018
  export interface _Table<T, TKey> extends Table<T, TKey> {
1000
1019
  }
@@ -1013,6 +1032,7 @@ export declare module Dexie {
1013
1032
  export function liveQuery<T>(querier: () => T | Promise<T>): Observable<T>;
1014
1033
  export function mergeRanges(target: IntervalTree, newSet: IntervalTree): void;
1015
1034
  export function rangesOverlap(rangeSet1: IntervalTree, rangeSet2: IntervalTree): boolean;
1035
+ export function cmp(a: any, b: any): number;
1016
1036
  /** Exporting 'Dexie' as the default export.
1017
1037
  **/
1018
1038
  export default Dexie;