dexie 4.0.7 → 4.0.9-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/dist/README.md ADDED
@@ -0,0 +1,46 @@
1
+ ## Can't find dexie.js?
2
+ Dexie's dist files are no longer checked in to github except temporarily when tagging
3
+ a release version (just so that bower will continue to work). The reason for this is because
4
+ checking in dist files bloats the commit history and makes it error prone to contribute to the
5
+ repo. To support bower though, we have to continue checking in dist files when releasing,
6
+ but that is now handled by the release.sh script, who also removes them directly afterwards.
7
+
8
+ If you still just want to download dexie.js to include in a test HTML page, go
9
+ to the following download site:
10
+
11
+ ### Download
12
+ [dexie.min.js](https://unpkg.com/dexie/dist/dexie.min.js)
13
+
14
+ [dexie.min.js.map](https://unpkg.com/dexie/dist/dexie.min.js.map)
15
+
16
+ ### Typings
17
+ [dexie.d.ts](https://unpkg.com/dexie/dist/dexie.d.ts)
18
+
19
+ ### Optional Stuff
20
+ [dexie.js (non-minified version)](https://unpkg.com/dexie/dist/dexie.js)
21
+
22
+ [dexie.js.map](https://unpkg.com/dexie/dist/dexie.js.map)
23
+
24
+ [dexie.min.js.gz (Minified and gzipped)](https://unpkg.com/dexie/dist/dexie.min.js.gz)
25
+
26
+ ## Install from NPM
27
+ ```
28
+ npm install dexie
29
+ ```
30
+
31
+ ## How to build
32
+ 1. cd to dexie package
33
+ 2. npm install
34
+ 3. npm run build
35
+
36
+ ## Contributing to Dexie.js?
37
+
38
+ Watch:
39
+ ```
40
+ npm run watch
41
+ ```
42
+
43
+ Test:
44
+ ```
45
+ npm test
46
+ ```
package/dist/dexie.d.ts CHANGED
@@ -4,13 +4,13 @@
4
4
  *
5
5
  * By David Fahlander, david.fahlander@gmail.com
6
6
  *
7
- * Version 4.0.7, Sun May 26 2024
7
+ * Version 4.0.9-alpha.1, Fri Aug 23 2024
8
8
  *
9
9
  * https://dexie.org
10
10
  *
11
11
  * Apache License Version 2.0, January 2004, http://www.apache.org/licenses/
12
12
  */
13
- // Generated by dts-bundle-generator v5.9.0
13
+ // Generated by dts-bundle-generator v9.3.1
14
14
 
15
15
  export interface IndexSpec {
16
16
  name: string;
@@ -20,11 +20,16 @@ export interface IndexSpec {
20
20
  auto: boolean | undefined;
21
21
  compound: boolean | undefined;
22
22
  src: string;
23
+ type?: string | undefined;
23
24
  }
24
25
  export interface TableSchema {
25
26
  name: string;
26
27
  primKey: IndexSpec;
27
28
  indexes: IndexSpec[];
29
+ yProps?: {
30
+ prop: string;
31
+ updatesTable: string;
32
+ }[];
28
33
  mappedClass: Function;
29
34
  idxByName: {
30
35
  [name: string]: IndexSpec;
@@ -359,20 +364,133 @@ export interface PromiseExtended<T = any> extends Promise<T> {
359
364
  finally<U>(onFinally?: () => U | PromiseLike<U>): PromiseExtended<T>;
360
365
  timeout(ms: number, msg?: string): PromiseExtended<T>;
361
366
  }
367
+ export interface DucktypedY {
368
+ Doc: new (options?: {
369
+ guid?: string;
370
+ collectionid?: string;
371
+ gc?: boolean;
372
+ gcFilter?: any;
373
+ meta?: any;
374
+ autoLoad?: boolean;
375
+ shouldLoad?: boolean;
376
+ }) => DucktypedYDoc;
377
+ applyUpdate: Function;
378
+ applyUpdateV2: Function;
379
+ encodeStateAsUpdate: Function;
380
+ encodeStateAsUpdateV2: Function;
381
+ encodeStateVector: Function;
382
+ encodeStateVectorFromUpdate: Function;
383
+ encodeStateVectorFromUpdateV2: Function;
384
+ mergeUpdates: Function;
385
+ mergeUpdatesV2: Function;
386
+ diffUpdate: Function;
387
+ diffUpdateV2: Function;
388
+ transact: Function;
389
+ }
390
+ export interface DucktypedYObservable {
391
+ on(name: string, f: (...args: any[]) => any): void;
392
+ off(name: string, f: (...args: any[]) => any): void;
393
+ once(name: string, f: (...args: any[]) => any): void;
394
+ emit(name: string, args: any[]): void;
395
+ destroy(): void;
396
+ }
397
+ /** Dock-typed Y.Doc */
398
+ export interface DucktypedYDoc extends DucktypedYObservable {
399
+ guid?: any;
400
+ collectionid?: any;
401
+ collection?: any;
402
+ whenLoaded: PromiseLike<any>;
403
+ whenSynced: PromiseLike<any>;
404
+ isLoaded: any;
405
+ isSynced: any;
406
+ transact: any;
407
+ toJSON: () => any;
408
+ destroy: () => void;
409
+ meta?: any;
410
+ share: Map<any, any>;
411
+ }
412
+ export interface DexieYDocMeta {
413
+ db: Dexie;
414
+ parentTable: string;
415
+ parentId: any;
416
+ parentProp: string;
417
+ updatesTable: string;
418
+ }
419
+ /** Stored in the updates table with auto-incremented number as primary key
420
+ *
421
+ */
422
+ export interface YUpdateRow {
423
+ /** The primary key in the update-table
424
+ *
425
+ */
426
+ i: number;
427
+ /** The primary key of the row in related table holding the document property.
428
+ *
429
+ */
430
+ k: IndexableType;
431
+ /** The Y update
432
+ *
433
+ */
434
+ u: Uint8Array;
435
+ /** Optional flag
436
+ *
437
+ * 1 = LOCAL_CHANGE_MAYBE_UNSYNCED
438
+ *
439
+ */
440
+ f?: number;
441
+ }
442
+ /** Stored in update tables along with YUpdateRows but with a string representing the syncing enging, as primary key
443
+ * A syncing engine can create an YSyncer row with an unsentFrom value set to the a number representing primary key (i)
444
+ * of updates that has not been sent to server or peer yet. Dexie will spare all updates that occur after the least
445
+ * unsentFrom value in the updates table from being compressed and garbage collected into the main update.
446
+ */
447
+ export interface YSyncer {
448
+ i: string;
449
+ unsentFrom: number;
450
+ }
451
+ /** A stamp of the last compressed and garbage collected update in the update table.
452
+ * The garbage collection process will find out which documents have got new updates since the last compressed update
453
+ * and compress them into their corresponding main update.
454
+ *
455
+ * The id of this row is always 0 - which is a reserved id for this purpose.
456
+ */
457
+ export interface YLastCompressed {
458
+ i: 0;
459
+ lastCompressed: number;
460
+ lastRun?: Date;
461
+ }
462
+ export interface DexieYProvider<YDoc = any> {
463
+ readonly doc: YDoc;
464
+ awareness?: any;
465
+ whenLoaded: Promise<any>;
466
+ whenSynced: Promise<any>;
467
+ on: DexieEventSet & ((name: string, f: (...args: any[]) => any) => void);
468
+ off(name: string, f: (...args: any[]) => any): void;
469
+ destroy(): void;
470
+ readonly destroyed: boolean;
471
+ }
472
+ export interface YDocCache {
473
+ readonly size: number;
474
+ find: (table: string, primaryKey: any, ydocProp: string) => DucktypedYDoc | undefined;
475
+ add: (doc: DucktypedYDoc) => void;
476
+ delete: (doc: DucktypedYDoc) => void;
477
+ }
362
478
  export type KeyPaths<T> = {
363
- [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
479
+ [P in keyof T]: P extends string ? T[P] extends Array<infer K> ? K extends any[] // Array of arrays (issue #2026)
480
+ ? P | `${P}.${number}` | `${P}.${number}.${number}` : K extends object // only drill into the array element if it's an object
364
481
  ? P | `${P}.${number}` | `${P}.${number}.${KeyPaths<K>}` : P | `${P}.${number}` : T[P] extends (...args: any[]) => any // Method
482
+ ? never : T[P] extends DucktypedYDoc // Not valid in update spec or where clause (+ avoid circular reference)
365
483
  ? never : T[P] extends object ? P | `${P}.${KeyPaths<T[P]>}` : P : never;
366
484
  }[keyof T];
367
- 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;
485
+ 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] : any;
368
486
  export declare const PropModSymbol: unique symbol;
369
487
  export type PropModSpec = {
370
488
  replacePrefix?: [
371
489
  string,
372
490
  string
373
491
  ];
374
- add?: number | BigInt | Array<string | number>;
375
- remove?: number | BigInt | Array<string | number>;
492
+ add?: number | bigint | Array<string | number>;
493
+ remove?: number | bigint | Array<string | number>;
376
494
  };
377
495
  export class PropModification implements PropModSpec {
378
496
  [PropModSymbol]?: true;
@@ -380,8 +498,8 @@ export class PropModification implements PropModSpec {
380
498
  string,
381
499
  string
382
500
  ];
383
- add?: number | BigInt | Array<string | number>;
384
- remove?: number | BigInt | Array<string | number>;
501
+ add?: number | bigint | Array<string | number>;
502
+ remove?: number | bigint | Array<string | number>;
385
503
  execute<T>(value: T): T;
386
504
  constructor(spec: PropModSpec);
387
505
  }
@@ -444,13 +562,29 @@ export type IntervalTree = IntervalTreeNode | EmptyRange;
444
562
  export interface IntervalTreeNode {
445
563
  from: IndexableType; // lower bound
446
564
  to: IndexableType; // upper bound
447
- l: IntervalTreeNode | null; // left
448
- r: IntervalTreeNode | null; // right
565
+ l?: IntervalTreeNode | null; // left
566
+ r?: IntervalTreeNode | null; // right
449
567
  d: number; // depth
450
568
  }
451
569
  export interface EmptyRange {
452
570
  d: 0;
453
571
  }
572
+ export interface RangeSetPrototype {
573
+ add(rangeSet: IntervalTree | {
574
+ from: IndexableType;
575
+ to: IndexableType;
576
+ }): RangeSet;
577
+ addKey(key: IndexableType): RangeSet;
578
+ addKeys(keys: IndexableType[]): RangeSet;
579
+ hasKey(key: IndexableType): boolean;
580
+ [Symbol.iterator](): Iterator<IntervalTreeNode, undefined, IndexableType | undefined>;
581
+ }
582
+ export type RangeSet = RangeSetPrototype & IntervalTree;
583
+ export interface RangeSetConstructor {
584
+ (tree: IntervalTree): RangeSet;
585
+ new (): RangeSet;
586
+ new (from: IndexableType, to?: IndexableType): RangeSet;
587
+ }
454
588
  export interface DexieOnReadyEvent {
455
589
  subscribe(fn: (vipDb: Dexie) => any, bSticky: boolean): void;
456
590
  unsubscribe(fn: (vipDb: Dexie) => any): void;
@@ -471,17 +605,26 @@ export interface DexieCloseEvent {
471
605
  unsubscribe(fn: (event: Event) => any): void;
472
606
  fire(event: Event): any;
473
607
  }
474
- export interface DbEvents extends DexieEventSet {
475
- (eventName: "ready", subscriber: (vipDb: Dexie) => any, bSticky?: boolean): void;
608
+ export interface DexieYEvent {
609
+ subscribe(fn: (provider: DexieYProvider, Y: any) => void): void;
610
+ unsubscribe(fn: (provider: DexieYProvider, Y: any) => void): void;
611
+ fire(provider: DexieYProvider, Y: any): void;
612
+ }
613
+ export interface DbEventFns {
476
614
  (eventName: "populate", subscriber: (trans: Transaction) => any): void;
477
615
  (eventName: "blocked", subscriber: (event: IDBVersionChangeEvent) => any): void;
478
616
  (eventName: "versionchange", subscriber: (event: IDBVersionChangeEvent) => any): void;
479
617
  (eventName: "close", subscriber: (event: Event) => any): void;
618
+ (eventName: "y", subscriber: (provider: DexieYProvider, Y: any) => void): void;
619
+ }
620
+ export interface DbEvents extends DbEventFns, DexieEventSet {
621
+ (eventName: "ready", subscriber: (vipDb: Dexie) => any, bSticky?: boolean): void;
480
622
  ready: DexieOnReadyEvent;
481
623
  populate: DexiePopulateEvent;
482
624
  blocked: DexieEvent;
483
625
  versionchange: DexieVersionChangeEvent;
484
626
  close: DexieCloseEvent;
627
+ y: DexieYEvent;
485
628
  }
486
629
  /** Set of mutated parts of the database
487
630
  */
@@ -737,10 +880,11 @@ export interface Table<T = any, TKey = any, TInsertType = T> {
737
880
  reverse(): Collection<T, TKey, TInsertType>;
738
881
  mapToClass(constructor: Function): Function;
739
882
  add(item: TInsertType, key?: TKey): PromiseExtended<TKey>;
740
- update(key: TKey | T, changes: UpdateSpec<TInsertType> | ((obj: T, ctx: {
883
+ update(key: TKey | T, changes: ((obj: T, ctx: {
741
884
  value: any;
742
885
  primKey: IndexableType;
743
886
  }) => void | boolean)): PromiseExtended<number>;
887
+ update(key: TKey | T, changes: UpdateSpec<TInsertType>): PromiseExtended<number>;
744
888
  put(item: TInsertType, key?: TKey): PromiseExtended<TKey>;
745
889
  delete(key: TKey): PromiseExtended<void>;
746
890
  clear(): PromiseExtended<void>;
@@ -811,12 +955,14 @@ export interface Dexie {
811
955
  readonly _allTables: {
812
956
  [name: string]: Table<any, IndexableType>;
813
957
  };
958
+ readonly _options: DexieOptions;
814
959
  readonly core: DBCore;
815
960
  _createTransaction: (this: Dexie, mode: IDBTransactionMode, storeNames: ArrayLike<string>, dbschema: DbSchema, parentTransaction?: Transaction | null) => Transaction;
816
961
  readonly _novip: Dexie;
817
962
  _dbSchema: DbSchema;
818
963
  version(versionNumber: number): Version;
819
964
  on: DbEvents;
965
+ once: DbEventFns;
820
966
  open(): PromiseExtended<Dexie>;
821
967
  table<T = any, TKey = IndexableType, TInsertType = T>(tableName: string): Table<T, TKey, TInsertType>;
822
968
  transaction<U>(mode: TransactionMode, tables: readonly (string | Table)[], scope: (trans: TXWithTables<this>) => PromiseLike<U> | U): PromiseExtended<U>;
@@ -845,6 +991,7 @@ export interface Dexie {
845
991
  stack: keyof DexieStacks;
846
992
  name: string;
847
993
  }): this;
994
+ gc(): Promise<void>;
848
995
  // Make it possible to touch physical class constructors where they reside - as properties on db instance.
849
996
  // For example, checking if (x instanceof db.Table). Can't do (x instanceof Dexie.Table because it's just a virtual interface)
850
997
  Table: {
@@ -1003,6 +1150,7 @@ export interface DexieDOMDependencies {
1003
1150
  indexedDB: IDBFactory;
1004
1151
  IDBKeyRange: typeof IDBKeyRange;
1005
1152
  }
1153
+ // There typings are extracted from https://github.com/tc39/proposal-observable
1006
1154
  declare global {
1007
1155
  interface SymbolConstructor {
1008
1156
  readonly observable: symbol;
@@ -1081,6 +1229,7 @@ export interface DexieOptions {
1081
1229
  modifyChunkSize?: number;
1082
1230
  chromeTransactionDurability?: ChromeTransactionDurability;
1083
1231
  cache?: "immutable" | "cloned" | "disabled";
1232
+ Y?: DucktypedY; // Caller supplies Y from the following: import * as Y from 'yjs';
1084
1233
  }
1085
1234
  export interface DexieConstructor extends DexieExceptionClasses {
1086
1235
  new (databaseName: string, options?: DexieOptions): Dexie;
@@ -1127,16 +1276,24 @@ export class Entity<TDexieSubClass extends Dexie = Dexie> {
1127
1276
  export type IsStrictlyAny<T> = (T extends never ? true : false) extends false ? false : true;
1128
1277
  /** Extract the union of literal method names in T
1129
1278
  */
1130
- export type MethodProps<T> = {
1279
+ export type NonInsertProps<T> = {
1131
1280
  [P in keyof T]: IsStrictlyAny<T[P]> extends true ? never // Plain property of type any (not method)
1132
1281
  : T[P] extends (...args: any[]) => any ? P // a function (method)
1282
+ : T[P] extends {
1283
+ on: any;
1284
+ subdocs: any;
1285
+ gc: any;
1286
+ isSynced: any;
1287
+ isLoaded: any;
1288
+ shouldLoad: any;
1289
+ } ? P // an YDoc property - should be generated by dexie and not by user
1133
1290
  : never;
1134
1291
  }[keyof T];
1135
1292
  /** Default insert type of T is a subset of T where:
1136
1293
  * * given optional props (such as an auto-generated primary key) are made optional
1137
1294
  * * methods are omitted
1138
1295
  */
1139
- export type InsertType<T, OptionalProps extends keyof T> = Omit<T, OptionalProps | MethodProps<T>> & {
1296
+ export type InsertType<T, OptionalProps extends keyof T> = Omit<T, OptionalProps | NonInsertProps<T>> & {
1140
1297
  [P in OptionalProps]?: T[P];
1141
1298
  };
1142
1299
  /** IDType extract the actual type of the primary key:
@@ -1146,10 +1303,13 @@ export type InsertType<T, OptionalProps extends keyof T> = Omit<T, OptionalProps
1146
1303
  export type IDType<T, TKeyPropNameOrKeyType> = IsStrictlyAny<T> extends true ? TKeyPropNameOrKeyType : TKeyPropNameOrKeyType extends string ? TKeyPropNameOrKeyType extends keyof T ? T[TKeyPropNameOrKeyType] : TKeyPropNameOrKeyType : TKeyPropNameOrKeyType;
1147
1304
  export type EntityTable<T, TKeyPropName extends keyof T = never, TInsertType = InsertType<T, TKeyPropName>> = Table<T, IDType<T, TKeyPropName>, TInsertType>;
1148
1305
  export declare var Dexie: DexieConstructor;
1306
+ // Alias of Table and Collection in order to be able to refer them from module below...
1149
1307
  export interface _Table<T, TKey, TInsertType> extends Table<T, TKey, TInsertType> {
1150
1308
  }
1151
1309
  export interface _Collection<T, TKey> extends Collection<T, TKey> {
1152
1310
  }
1311
+ // Besides being the only exported value, let Dexie also be
1312
+ // a namespace for types...
1153
1313
  export declare module Dexie {
1154
1314
  // The "Dexie.Promise" type.
1155
1315
  type Promise<T = any> = PromiseExtended<T>; // Because many samples have been Dexie.Promise.
@@ -1163,12 +1323,20 @@ export declare module Dexie {
1163
1323
  export function liveQuery<T>(querier: () => T | Promise<T>): Observable<T>;
1164
1324
  export function mergeRanges(target: IntervalTree, newSet: IntervalTree): void;
1165
1325
  export function rangesOverlap(rangeSet1: IntervalTree, rangeSet2: IntervalTree): boolean;
1326
+ declare var RangeSet$1: RangeSetConstructor;
1166
1327
  export function cmp(a: any, b: any): number;
1167
1328
  export function replacePrefix(a: string, b: string): PropModification;
1168
1329
  export function add(num: number | bigint | any[]): PropModification;
1169
1330
  export function remove(num: number | bigint | any[]): PropModification;
1170
- /** Exporting 'Dexie' as the default export.
1171
- **/
1172
- export default Dexie;
1331
+ export declare var DexieYProvider: {
1332
+ (doc: DucktypedYDoc): DexieYProvider;
1333
+ new (doc: DucktypedYDoc): DexieYProvider;
1334
+ getDocCache: (db: Dexie) => YDocCache;
1335
+ };
1336
+
1337
+ export {
1338
+ Dexie as default,
1339
+ RangeSet$1 as RangeSet,
1340
+ };
1173
1341
 
1174
1342
  export {};