dexie 4.0.1-alpha.8 → 4.0.1-beta.2

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
@@ -1,7 +1,7 @@
1
1
  Dexie.js
2
2
  ========
3
3
 
4
- [![NPM Version][npm-image]][npm-url] [![Build Status](https://travis-ci.com/dexie/Dexie.js.svg?branch=master)](https://travis-ci.com/dexie/Dexie.js)[![Tested with Browserstack](https://dexie.org/assets/images/tested-with-browserstack2.png)](https://www.browserstack.com)
4
+ [![NPM Version][npm-image]][npm-url] ![Build Status](https://github.com/dexie/Dexie.js/actions/workflows/main.yml/badge.svg)
5
5
 
6
6
  Dexie.js is a wrapper library for indexedDB - the standard database in the browser. https://dexie.org
7
7
 
@@ -0,0 +1 @@
1
+ [object Object]
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.1-alpha.8, Fri Feb 17 2023
7
+ * Version 4.0.1-beta.2, Wed Nov 29 2023
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -65,6 +65,7 @@ export interface Transaction {
65
65
  mode: IDBTransactionMode;
66
66
  //tables: { [type: string]: Table<any, any> }; Deprecated since 2.0. Obsolete from v3.0.
67
67
  storeNames: Array<string>;
68
+ explicit?: boolean;
68
69
  parent?: Transaction;
69
70
  on: TransactionEvents;
70
71
  abort(): void;
@@ -357,7 +358,8 @@ export interface PromiseExtended<T = any> extends Promise<T> {
357
358
  timeout(ms: number, msg?: string): PromiseExtended<T>;
358
359
  }
359
360
  export type KeyPaths<T> = {
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
+ [P in keyof T]: P extends string ? T[P] extends Array<infer K> ? K extends object // only drill into the array element if it's an object
362
+ ? P | `${P}.${number}` | `${P}.${number}.${KeyPaths<K>}` : P | `${P}.${number}` : T[P] extends (...args: any[]) => any // Method
361
363
  ? never : T[P] extends object ? P | `${P}.${KeyPaths<T[P]>}` : P : never;
362
364
  }[keyof T];
363
365
  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;
@@ -416,6 +418,88 @@ export interface Collection<T = any, TKey = IndexableType> {
416
418
  }) => void | boolean): PromiseExtended<number>;
417
419
  modify(changes: UpdateSpec<T>): PromiseExtended<number>;
418
420
  }
421
+ export type IntervalTree = IntervalTreeNode | EmptyRange;
422
+ export interface IntervalTreeNode {
423
+ from: IndexableType; // lower bound
424
+ to: IndexableType; // upper bound
425
+ l: IntervalTreeNode | null; // left
426
+ r: IntervalTreeNode | null; // right
427
+ d: number; // depth
428
+ }
429
+ export interface EmptyRange {
430
+ d: 0;
431
+ }
432
+ export interface DexieOnReadyEvent {
433
+ subscribe(fn: (vipDb: Dexie) => any, bSticky: boolean): void;
434
+ unsubscribe(fn: (vipDb: Dexie) => any): void;
435
+ fire(vipDb: Dexie): any;
436
+ }
437
+ export interface DexieVersionChangeEvent {
438
+ subscribe(fn: (event: IDBVersionChangeEvent) => any): void;
439
+ unsubscribe(fn: (event: IDBVersionChangeEvent) => any): void;
440
+ fire(event: IDBVersionChangeEvent): any;
441
+ }
442
+ export interface DexiePopulateEvent {
443
+ subscribe(fn: (trans: Transaction) => any): void;
444
+ unsubscribe(fn: (trans: Transaction) => any): void;
445
+ fire(trans: Transaction): any;
446
+ }
447
+ export interface DexieCloseEvent {
448
+ subscribe(fn: (event: Event) => any): void;
449
+ unsubscribe(fn: (event: Event) => any): void;
450
+ fire(event: Event): any;
451
+ }
452
+ export interface DbEvents extends DexieEventSet {
453
+ (eventName: "ready", subscriber: (vipDb: Dexie) => any, bSticky?: boolean): void;
454
+ (eventName: "populate", subscriber: (trans: Transaction) => any): void;
455
+ (eventName: "blocked", subscriber: (event: IDBVersionChangeEvent) => any): void;
456
+ (eventName: "versionchange", subscriber: (event: IDBVersionChangeEvent) => any): void;
457
+ (eventName: "close", subscriber: (event: Event) => any): void;
458
+ ready: DexieOnReadyEvent;
459
+ populate: DexiePopulateEvent;
460
+ blocked: DexieEvent;
461
+ versionchange: DexieVersionChangeEvent;
462
+ close: DexieCloseEvent;
463
+ }
464
+ /** Set of mutated parts of the database
465
+ */
466
+ export type ObservabilitySet = {
467
+ /** Database part having been mutated.
468
+ *
469
+ * This structure is produced in observability-middleware.ts
470
+ * and consumed in live-query.ts.
471
+ *
472
+ * Format of 'part':
473
+ *
474
+ * `idb://${dbName}/${tableName}/${indexName}`
475
+ *
476
+ * * dbName is the database name
477
+ * * tableName is the table name
478
+ * * indexName is any of:
479
+ * 1. An empty string - represents the primary keys of the affected objs
480
+ * 2. ":dels" - represents primary keys of deleted objects in the table
481
+ * 3. The keyPath of an index, such as "name", "age" or "address.city" -
482
+ * represents indexes that, if used in a query, might affect the
483
+ * result of that query.
484
+ *
485
+ * IntervalTree
486
+ * * See definition of IntervalTree type in rangeset.d.ts
487
+ * * See rangesOverlap() in rangeset.ts that can be used to compare two
488
+ * IntervalTrees and detect collissions.
489
+ * * See RangeSet class that can be used to create an IntervalTree and add
490
+ * ranges to it.
491
+ */
492
+ [part: string]: IntervalTree;
493
+ };
494
+ export interface DexieOnStorageMutatedEvent {
495
+ subscribe(fn: (parts: ObservabilitySet) => any): void;
496
+ unsubscribe(fn: (parts: ObservabilitySet) => any): void;
497
+ fire(parts: ObservabilitySet): any;
498
+ }
499
+ export interface GlobalDexieEvents extends DexieEventSet {
500
+ (eventName: "storagemutated", subscriber: (parts: ObservabilitySet) => any): void;
501
+ storagemutated: DexieOnStorageMutatedEvent;
502
+ }
419
503
  export const enum DBCoreRangeType {
420
504
  Equal = 1,
421
505
  Range = 2,
@@ -449,6 +533,7 @@ export interface DBCoreAddRequest {
449
533
  trans: DBCoreTransaction;
450
534
  values: readonly any[];
451
535
  keys?: any[];
536
+ mutatedParts?: ObservabilitySet;
452
537
  /** @deprecated Will always get results since 3.1.0-alpha.5 */
453
538
  wantResults?: boolean;
454
539
  }
@@ -457,6 +542,7 @@ export interface DBCorePutRequest {
457
542
  trans: DBCoreTransaction;
458
543
  values: readonly any[];
459
544
  keys?: any[];
545
+ mutatedParts?: ObservabilitySet;
460
546
  criteria?: {
461
547
  index: string | null;
462
548
  range: DBCoreKeyRange;
@@ -477,6 +563,7 @@ export interface DBCoreDeleteRequest {
477
563
  type: "delete";
478
564
  trans: DBCoreTransaction;
479
565
  keys: any[];
566
+ mutatedParts?: ObservabilitySet;
480
567
  criteria?: {
481
568
  index: string | null;
482
569
  range: DBCoreKeyRange;
@@ -486,15 +573,18 @@ export interface DBCoreDeleteRangeRequest {
486
573
  type: "deleteRange";
487
574
  trans: DBCoreTransaction;
488
575
  range: DBCoreKeyRange;
576
+ mutatedParts?: ObservabilitySet;
489
577
  }
490
578
  export interface DBCoreGetManyRequest {
491
579
  trans: DBCoreTransaction;
492
580
  keys: any[];
493
581
  cache?: "immutable" | "clone";
582
+ obsSet?: ObservabilitySet;
494
583
  }
495
584
  export interface DBCoreGetRequest {
496
585
  trans: DBCoreTransaction;
497
586
  key: any;
587
+ obsSet?: ObservabilitySet;
498
588
  }
499
589
  export interface DBCoreQuery {
500
590
  index: DBCoreIndex; //keyPath: null | string | string[]; // null represents primary key. string a property, string[] several properties.
@@ -505,6 +595,7 @@ export interface DBCoreQueryRequest {
505
595
  values?: boolean;
506
596
  limit?: number;
507
597
  query: DBCoreQuery;
598
+ obsSet?: ObservabilitySet;
508
599
  }
509
600
  export interface DBCoreQueryResponse {
510
601
  result: any[];
@@ -515,10 +606,12 @@ export interface DBCoreOpenCursorRequest {
515
606
  unique?: boolean;
516
607
  reverse?: boolean;
517
608
  query: DBCoreQuery;
609
+ obsSet?: ObservabilitySet;
518
610
  }
519
611
  export interface DBCoreCountRequest {
520
612
  trans: DBCoreTransaction;
521
613
  query: DBCoreQuery;
614
+ obsSet?: ObservabilitySet;
522
615
  }
523
616
  export interface DBCoreCursor {
524
617
  readonly trans: DBCoreTransaction;
@@ -563,6 +656,8 @@ export interface DBCoreIndex {
563
656
  readonly multiEntry?: boolean;
564
657
  /** Extract (using keyPath) a key from given value (object). Null for outbound primary keys */
565
658
  readonly extractKey: ((value: any) => any) | null;
659
+ /** If this index is a virtual index, lowLevelIndex represents the actual IndexedDB index behind it */
660
+ readonly lowLevelIndex?: DBCoreIndex;
566
661
  }
567
662
  export interface DBCore {
568
663
  stack: "dbcore";
@@ -584,7 +679,7 @@ export interface DBCoreTable {
584
679
  openCursor(req: DBCoreOpenCursorRequest): Promise<DBCoreCursor | null>;
585
680
  count(req: DBCoreCountRequest): Promise<number>;
586
681
  }
587
- export interface Table<T = any, TKey = IndexableType, TInsertType = T> {
682
+ export interface Table<T = any, TKey = any, TInsertType = T> {
588
683
  db: Dexie;
589
684
  name: string;
590
685
  schema: TableSchema;
@@ -656,88 +751,6 @@ export interface Version {
656
751
  }): Version;
657
752
  upgrade(fn: (trans: Transaction) => PromiseLike<any> | void): Version;
658
753
  }
659
- export type IntervalTree = IntervalTreeNode | EmptyRange;
660
- export interface IntervalTreeNode {
661
- from: IndexableType; // lower bound
662
- to: IndexableType; // upper bound
663
- l: IntervalTreeNode | null; // left
664
- r: IntervalTreeNode | null; // right
665
- d: number; // depth
666
- }
667
- export interface EmptyRange {
668
- d: 0;
669
- }
670
- export interface DexieOnReadyEvent {
671
- subscribe(fn: (vipDb: Dexie) => any, bSticky: boolean): void;
672
- unsubscribe(fn: (vipDb: Dexie) => any): void;
673
- fire(vipDb: Dexie): any;
674
- }
675
- export interface DexieVersionChangeEvent {
676
- subscribe(fn: (event: IDBVersionChangeEvent) => any): void;
677
- unsubscribe(fn: (event: IDBVersionChangeEvent) => any): void;
678
- fire(event: IDBVersionChangeEvent): any;
679
- }
680
- export interface DexiePopulateEvent {
681
- subscribe(fn: (trans: Transaction) => any): void;
682
- unsubscribe(fn: (trans: Transaction) => any): void;
683
- fire(trans: Transaction): any;
684
- }
685
- export interface DexieCloseEvent {
686
- subscribe(fn: (event: Event) => any): void;
687
- unsubscribe(fn: (event: Event) => any): void;
688
- fire(event: Event): any;
689
- }
690
- export interface DbEvents extends DexieEventSet {
691
- (eventName: "ready", subscriber: (vipDb: Dexie) => any, bSticky?: boolean): void;
692
- (eventName: "populate", subscriber: (trans: Transaction) => any): void;
693
- (eventName: "blocked", subscriber: (event: IDBVersionChangeEvent) => any): void;
694
- (eventName: "versionchange", subscriber: (event: IDBVersionChangeEvent) => any): void;
695
- (eventName: "close", subscriber: (event: Event) => any): void;
696
- ready: DexieOnReadyEvent;
697
- populate: DexiePopulateEvent;
698
- blocked: DexieEvent;
699
- versionchange: DexieVersionChangeEvent;
700
- close: DexieCloseEvent;
701
- }
702
- /** Set of mutated parts of the database
703
- */
704
- export type ObservabilitySet = {
705
- /** Database part having been mutated.
706
- *
707
- * This structure is produced in observability-middleware.ts
708
- * and consumed in live-query.ts.
709
- *
710
- * Format of 'part':
711
- *
712
- * `idb://${dbName}/${tableName}/${indexName}`
713
- *
714
- * * dbName is the database name
715
- * * tableName is the table name
716
- * * indexName is any of:
717
- * 1. An empty string - represents the primary keys of the affected objs
718
- * 2. ":dels" - represents primary keys of deleted objects in the table
719
- * 3. The keyPath of an index, such as "name", "age" or "address.city" -
720
- * represents indexes that, if used in a query, might affect the
721
- * result of that query.
722
- *
723
- * IntervalTree
724
- * * See definition of IntervalTree type in rangeset.d.ts
725
- * * See rangesOverlap() in rangeset.ts that can be used to compare two
726
- * IntervalTrees and detect collissions.
727
- * * See RangeSet class that can be used to create an IntervalTree and add
728
- * ranges to it.
729
- */
730
- [part: string]: IntervalTree;
731
- };
732
- export interface DexieOnStorageMutatedEvent {
733
- subscribe(fn: (parts: ObservabilitySet) => any): void;
734
- unsubscribe(fn: (parts: ObservabilitySet) => any): void;
735
- fire(parts: ObservabilitySet): any;
736
- }
737
- export interface GlobalDexieEvents extends DexieEventSet {
738
- (eventName: "storagemutated", subscriber: (parts: ObservabilitySet) => any): void;
739
- storagemutated: DexieOnStorageMutatedEvent;
740
- }
741
754
  export type TransactionMode = "readonly" | "readwrite" | "r" | "r!" | "r?" | "rw" | "rw!" | "rw?";
742
755
  export type DbSchema = {
743
756
  [tableName: string]: TableSchema;
@@ -788,7 +801,9 @@ export interface Dexie {
788
801
  transaction<U>(mode: TransactionMode, table: string | Table, table2: string | Table, table3: string | Table, scope: (trans: TXWithTables<this>) => PromiseLike<U> | U): PromiseExtended<U>;
789
802
  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>;
790
803
  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>;
791
- close(): void;
804
+ close(closeOptions?: {
805
+ disableAutoOpen: boolean;
806
+ }): void;
792
807
  delete(): PromiseExtended<void>;
793
808
  isOpen(): boolean;
794
809
  hasBeenClosed(): boolean;
@@ -967,10 +982,18 @@ declare global {
967
982
  readonly observable: symbol;
968
983
  }
969
984
  }
985
+ export interface Subscribable<T> {
986
+ subscribe(observer: Partial<Observer<T>>): Unsubscribable;
987
+ }
988
+ export interface Unsubscribable {
989
+ unsubscribe(): void;
990
+ }
970
991
  export interface Observable<T = any> {
971
- subscribe(onNext?: ((value: T) => void) | null, onError?: ((error: any) => void) | null, onComplete?: (() => void) | null): Subscription;
972
- subscribe(observer?: Observer<T> | null): Subscription;
973
- [Symbol.observable]: () => Observable<T>;
992
+ subscribe(observerOrNext?: Observer<T> | ((value: T) => void)): Subscription;
993
+ subscribe(next?: ((value: T) => void) | null, error?: ((error: any) => void) | null, complete?: (() => void) | null): Subscription;
994
+ getValue?(): T;
995
+ hasValue?(): boolean;
996
+ [Symbol.observable]: () => Subscribable<T>;
974
997
  }
975
998
  export interface Subscription {
976
999
  unsubscribe(): void;
@@ -982,6 +1005,41 @@ export interface Observer<T = any> {
982
1005
  error?: (error: any) => void;
983
1006
  complete?: () => void;
984
1007
  }
1008
+ export type GlobalQueryCache = {
1009
+ // TODO: Change to parts: {[part: string]: TblQueryCache}
1010
+ // och unsignaledParts: ObservabilitySet;
1011
+ [part: string]: TblQueryCache; // part is `idb://${dbName}/${tableName}`
1012
+ };
1013
+ export interface TblQueryCache {
1014
+ queries: {
1015
+ query: {
1016
+ [indexName: string]: CacheEntry[];
1017
+ };
1018
+ count: {
1019
+ [indexName: string]: CacheEntry[];
1020
+ };
1021
+ };
1022
+ objs: Map<string | number, object>;
1023
+ optimisticOps: DBCoreMutateRequest[];
1024
+ unsignaledParts: ObservabilitySet;
1025
+ signalTimer?: number;
1026
+ }
1027
+ export interface CacheEntryCommon {
1028
+ subscribers: Set<() => void>;
1029
+ obsSet: ObservabilitySet;
1030
+ //txObsSet: ObservabilitySet;
1031
+ promise: Promise<any>;
1032
+ dirty: boolean;
1033
+ }
1034
+ export type CacheEntry = CacheEntryCommon & ({
1035
+ type: "query";
1036
+ req: DBCoreQueryRequest;
1037
+ res?: readonly any[];
1038
+ } | {
1039
+ type: "count";
1040
+ req: DBCoreCountRequest;
1041
+ res?: number;
1042
+ });
985
1043
  export type ChromeTransactionDurability = "default" | "strict" | "relaxed";
986
1044
  export interface DexieOptions {
987
1045
  addons?: Array<(db: Dexie) => void>;
@@ -997,6 +1055,7 @@ export interface DexieOptions {
997
1055
  allowEmptyDB?: boolean;
998
1056
  modifyChunkSize?: number;
999
1057
  chromeTransactionDurability?: ChromeTransactionDurability;
1058
+ cache?: "immutable" | "cloned" | "disabled";
1000
1059
  }
1001
1060
  export interface DexieConstructor extends DexieExceptionClasses {
1002
1061
  new (databaseName: string, options?: DexieOptions): Dexie;
@@ -1025,6 +1084,8 @@ export interface DexieConstructor extends DexieExceptionClasses {
1025
1084
  delete(dbName: string): Promise<void>;
1026
1085
  dependencies: DexieDOMDependencies;
1027
1086
  default: Dexie; // Work-around for different build tools handling default imports differently.
1087
+ cache: GlobalQueryCache;
1088
+ debug: false | true | "dexie";
1028
1089
  Promise: PromiseExtendedConstructor;
1029
1090
  //TableSchema: {}; // Deprecate!
1030
1091
  //IndexSpec: {new():IndexSpec}; //? Deprecate