dexie 4.0.8 → 4.1.0-alpha.12

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.8, Wed Jul 10 2024
7
+ * Version 4.1.0-alpha.12, Wed Oct 16 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,10 +364,177 @@ 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
+ // There typings are extracted from https://github.com/tc39/proposal-observable
368
+ declare global {
369
+ interface SymbolConstructor {
370
+ readonly observable: symbol;
371
+ }
372
+ }
373
+ export interface Subscribable<T> {
374
+ subscribe(observer: Partial<Observer<T>>): Unsubscribable;
375
+ }
376
+ export interface Unsubscribable {
377
+ unsubscribe(): void;
378
+ }
379
+ export interface Observable<T = any> {
380
+ subscribe(observerOrNext?: Observer<T> | ((value: T) => void)): Subscription;
381
+ subscribe(next?: ((value: T) => void) | null, error?: ((error: any) => void) | null, complete?: (() => void) | null): Subscription;
382
+ getValue?(): T;
383
+ hasValue?(): boolean;
384
+ [Symbol.observable]: () => Subscribable<T>;
385
+ }
386
+ export interface Subscription {
387
+ unsubscribe(): void;
388
+ readonly closed: boolean;
389
+ }
390
+ export interface Observer<T = any> {
391
+ start?: (subscription: Subscription) => void;
392
+ next?: (value: T) => void;
393
+ error?: (error: any) => void;
394
+ complete?: () => void;
395
+ }
396
+ export interface YjsLib {
397
+ Doc: new (options?: {
398
+ guid?: string;
399
+ collectionid?: string;
400
+ gc?: boolean;
401
+ gcFilter?: any;
402
+ meta?: any;
403
+ autoLoad?: boolean;
404
+ shouldLoad?: boolean;
405
+ }) => YjsDoc;
406
+ applyUpdate: Function;
407
+ applyUpdateV2: Function;
408
+ encodeStateAsUpdate: Function;
409
+ encodeStateAsUpdateV2: Function;
410
+ encodeStateVector: Function;
411
+ encodeStateVectorFromUpdate: Function;
412
+ encodeStateVectorFromUpdateV2: Function;
413
+ mergeUpdates: Function;
414
+ mergeUpdatesV2: Function;
415
+ diffUpdate: Function;
416
+ diffUpdateV2: Function;
417
+ transact: Function;
418
+ }
419
+ export interface YjsObservable {
420
+ on(name: string, f: (...args: any[]) => any): void;
421
+ off(name: string, f: (...args: any[]) => any): void;
422
+ once(name: string, f: (...args: any[]) => any): void;
423
+ emit(name: string, args: any[]): void;
424
+ destroy(): void;
425
+ }
426
+ /** Duck-typed Y.Doc */
427
+ export interface YjsDoc extends YjsObservable {
428
+ guid?: any;
429
+ collectionid?: any;
430
+ collection?: any;
431
+ whenLoaded: PromiseLike<any>;
432
+ whenSynced: PromiseLike<any>;
433
+ isLoaded: any;
434
+ isSynced: any;
435
+ transact: any;
436
+ toJSON: () => any;
437
+ destroy: () => void;
438
+ meta?: any;
439
+ share: Map<any, any>;
440
+ }
441
+ /** Docktyped Awareness */
442
+ export interface YjsAwareness extends YjsObservable {
443
+ doc: YjsDoc;
444
+ destroy: () => void;
445
+ clientID: any;
446
+ states: any;
447
+ meta: any;
448
+ getLocalState: any;
449
+ setLocalState: any;
450
+ setLocalStateField: any;
451
+ getStates: any;
452
+ }
453
+ export interface DexieYDocMeta {
454
+ db: Dexie;
455
+ parentTable: string;
456
+ parentId: any;
457
+ parentProp: string;
458
+ updatesTable: string;
459
+ }
460
+ /** Stored in the updates table with auto-incremented number as primary key
461
+ *
462
+ */
463
+ export interface YUpdateRow {
464
+ /** The primary key in the update-table
465
+ *
466
+ */
467
+ i: number;
468
+ /** The primary key of the row in related table holding the document property.
469
+ *
470
+ */
471
+ k: IndexableType;
472
+ /** The Y update
473
+ *
474
+ */
475
+ u: Uint8Array;
476
+ /** Optional flag
477
+ *
478
+ * 1 = LOCAL_CHANGE_MAYBE_UNSYNCED
479
+ *
480
+ */
481
+ f?: number;
482
+ }
483
+ /** Stored in update tables along with YUpdateRows but with a string representing the syncing enging, as primary key
484
+ * A syncing engine can create an YSyncState row with an unsentFrom or receivedUntil value set to the a number representing primary key (i)
485
+ * of updates that has not been sent to server or peer yet. Dexie will compute the least value of unsentFrom and receivedUntil + 1 and
486
+ * spare all updates with an 'i' of that value or greater in the updates table from being compressed and garbage collected into the main update.
487
+ */
488
+ export interface YSyncState {
489
+ i: string;
490
+ unsentFrom?: number;
491
+ receivedUntil?: number;
492
+ }
493
+ /** A stamp of the last compressed and garbage collected update in the update table.
494
+ * The garbage collection process will find out which documents have got new updates since the last compressed update
495
+ * and compress them into their corresponding main update.
496
+ *
497
+ * The id of this row is always 0 - which is a reserved id for this purpose.
498
+ */
499
+ export interface YLastCompressed {
500
+ i: 0;
501
+ lastCompressed: number;
502
+ lastRun?: Date;
503
+ }
504
+ export interface ProviderReleaseOptions {
505
+ // Optional grace period to optimize for unload/reload scenarios when releasing a document
506
+ // and refcount reached zero - to avoid destroying the document immediately in case
507
+ // it's going to be reloaded soon.
508
+ // If not set, the document will be destroyed immediately when refcount reaches zero.
509
+ gracePeriod?: number;
510
+ }
511
+ declare class DexieYProvider<YDoc = any> {
512
+ readonly doc: YDoc;
513
+ awareness?: YjsAwareness;
514
+ whenLoaded: Promise<void>;
515
+ whenSynced: Promise<void>;
516
+ on: DexieEventSet & ((name: string, f: (...args: any[]) => any) => void);
517
+ off: (name: string, f: (...args: any[]) => any) => void;
518
+ addCleanupHandler(cleanupHandler: Unsubscribable | (() => void)): void;
519
+ destroy(): void;
520
+ readonly destroyed: boolean;
521
+ static load<YDoc extends YjsDoc>(doc: YDoc): DexieYProvider<YDoc>;
522
+ static release<YDoc extends YjsDoc>(doc: YDoc, options?: ProviderReleaseOptions): void;
523
+ static for<YDoc extends YjsDoc>(doc: YDoc): DexieYProvider<YDoc> | undefined;
524
+ static getDocCache: (db: Dexie) => YDocCache;
525
+ static currentUpdateRow: YUpdateRow | null;
526
+ }
527
+ export interface YDocCache {
528
+ readonly size: number;
529
+ find: (table: string, primaryKey: any, ydocProp: string) => YjsDoc | undefined;
530
+ add: (doc: YjsDoc) => void;
531
+ delete: (doc: YjsDoc) => void;
532
+ }
362
533
  export type KeyPaths<T> = {
363
534
  [P in keyof T]: P extends string ? T[P] extends Array<infer K> ? K extends any[] // Array of arrays (issue #2026)
364
535
  ? P | `${P}.${number}` | `${P}.${number}.${number}` : K extends object // only drill into the array element if it's an object
365
536
  ? P | `${P}.${number}` | `${P}.${number}.${KeyPaths<K>}` : P | `${P}.${number}` : T[P] extends (...args: any[]) => any // Method
537
+ ? never : T[P] extends YjsDoc // Not valid in update spec or where clause (+ avoid circular reference)
366
538
  ? never : T[P] extends object ? P | `${P}.${KeyPaths<T[P]>}` : P : never;
367
539
  }[keyof T];
368
540
  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;
@@ -452,6 +624,22 @@ export interface IntervalTreeNode {
452
624
  export interface EmptyRange {
453
625
  d: 0;
454
626
  }
627
+ export interface RangeSetPrototype {
628
+ add(rangeSet: IntervalTree | {
629
+ from: IndexableType;
630
+ to: IndexableType;
631
+ }): RangeSet;
632
+ addKey(key: IndexableType): RangeSet;
633
+ addKeys(keys: IndexableType[]): RangeSet;
634
+ hasKey(key: IndexableType): boolean;
635
+ [Symbol.iterator](): Iterator<IntervalTreeNode, undefined, IndexableType | undefined>;
636
+ }
637
+ export type RangeSet = RangeSetPrototype & IntervalTree;
638
+ export interface RangeSetConstructor {
639
+ (tree: IntervalTree): RangeSet;
640
+ new (): RangeSet;
641
+ new (from: IndexableType, to?: IndexableType): RangeSet;
642
+ }
455
643
  export interface DexieOnReadyEvent {
456
644
  subscribe(fn: (vipDb: Dexie) => any, bSticky: boolean): void;
457
645
  unsubscribe(fn: (vipDb: Dexie) => any): void;
@@ -472,17 +660,26 @@ export interface DexieCloseEvent {
472
660
  unsubscribe(fn: (event: Event) => any): void;
473
661
  fire(event: Event): any;
474
662
  }
475
- export interface DbEvents extends DexieEventSet {
476
- (eventName: "ready", subscriber: (vipDb: Dexie) => any, bSticky?: boolean): void;
663
+ export interface DexieYEvent {
664
+ subscribe(fn: (provider: DexieYProvider, Y: any) => void): void;
665
+ unsubscribe(fn: (provider: DexieYProvider, Y: any) => void): void;
666
+ fire(provider: DexieYProvider, Y: any): void;
667
+ }
668
+ export interface DbEventFns {
477
669
  (eventName: "populate", subscriber: (trans: Transaction) => any): void;
478
670
  (eventName: "blocked", subscriber: (event: IDBVersionChangeEvent) => any): void;
479
671
  (eventName: "versionchange", subscriber: (event: IDBVersionChangeEvent) => any): void;
480
672
  (eventName: "close", subscriber: (event: Event) => any): void;
673
+ (eventName: "y", subscriber: (provider: DexieYProvider, Y: any) => void): void;
674
+ }
675
+ export interface DbEvents extends DbEventFns, DexieEventSet {
676
+ (eventName: "ready", subscriber: (vipDb: Dexie) => any, bSticky?: boolean): void;
481
677
  ready: DexieOnReadyEvent;
482
678
  populate: DexiePopulateEvent;
483
679
  blocked: DexieEvent;
484
680
  versionchange: DexieVersionChangeEvent;
485
681
  close: DexieCloseEvent;
682
+ y: DexieYEvent;
486
683
  }
487
684
  /** Set of mutated parts of the database
488
685
  */
@@ -549,7 +746,7 @@ export interface DBCoreMutateResponse {
549
746
  [operationNumber: number]: Error;
550
747
  };
551
748
  lastResult: any;
552
- results?: any[]; // Present on AddRequest and PutRequest.
749
+ results?: any[]; // Always present on responses to AddRequest and PutRequest.
553
750
  }
554
751
  export interface DBCoreAddRequest {
555
752
  type: "add";
@@ -813,12 +1010,14 @@ export interface Dexie {
813
1010
  readonly _allTables: {
814
1011
  [name: string]: Table<any, IndexableType>;
815
1012
  };
1013
+ readonly _options: DexieOptions;
816
1014
  readonly core: DBCore;
817
1015
  _createTransaction: (this: Dexie, mode: IDBTransactionMode, storeNames: ArrayLike<string>, dbschema: DbSchema, parentTransaction?: Transaction | null) => Transaction;
818
1016
  readonly _novip: Dexie;
819
1017
  _dbSchema: DbSchema;
820
1018
  version(versionNumber: number): Version;
821
1019
  on: DbEvents;
1020
+ once: DbEventFns;
822
1021
  open(): PromiseExtended<Dexie>;
823
1022
  table<T = any, TKey = IndexableType, TInsertType = T>(tableName: string): Table<T, TKey, TInsertType>;
824
1023
  transaction<U>(mode: TransactionMode, tables: readonly (string | Table)[], scope: (trans: TXWithTables<this>) => PromiseLike<U> | U): PromiseExtended<U>;
@@ -847,6 +1046,7 @@ export interface Dexie {
847
1046
  stack: keyof DexieStacks;
848
1047
  name: string;
849
1048
  }): this;
1049
+ gc(): Promise<void>;
850
1050
  // Make it possible to touch physical class constructors where they reside - as properties on db instance.
851
1051
  // For example, checking if (x instanceof db.Table). Can't do (x instanceof Dexie.Table because it's just a virtual interface)
852
1052
  Table: {
@@ -1005,34 +1205,6 @@ export interface DexieDOMDependencies {
1005
1205
  indexedDB: IDBFactory;
1006
1206
  IDBKeyRange: typeof IDBKeyRange;
1007
1207
  }
1008
- declare global {
1009
- interface SymbolConstructor {
1010
- readonly observable: symbol;
1011
- }
1012
- }
1013
- export interface Subscribable<T> {
1014
- subscribe(observer: Partial<Observer<T>>): Unsubscribable;
1015
- }
1016
- export interface Unsubscribable {
1017
- unsubscribe(): void;
1018
- }
1019
- export interface Observable<T = any> {
1020
- subscribe(observerOrNext?: Observer<T> | ((value: T) => void)): Subscription;
1021
- subscribe(next?: ((value: T) => void) | null, error?: ((error: any) => void) | null, complete?: (() => void) | null): Subscription;
1022
- getValue?(): T;
1023
- hasValue?(): boolean;
1024
- [Symbol.observable]: () => Subscribable<T>;
1025
- }
1026
- export interface Subscription {
1027
- unsubscribe(): void;
1028
- readonly closed: boolean;
1029
- }
1030
- export interface Observer<T = any> {
1031
- start?: (subscription: Subscription) => void;
1032
- next?: (value: T) => void;
1033
- error?: (error: any) => void;
1034
- complete?: () => void;
1035
- }
1036
1208
  export type GlobalQueryCache = {
1037
1209
  // TODO: Change to parts: {[part: string]: TblQueryCache}
1038
1210
  // och unsignaledParts: ObservabilitySet;
@@ -1083,6 +1255,8 @@ export interface DexieOptions {
1083
1255
  modifyChunkSize?: number;
1084
1256
  chromeTransactionDurability?: ChromeTransactionDurability;
1085
1257
  cache?: "immutable" | "cloned" | "disabled";
1258
+ Y?: YjsLib; // Caller supplies Y from the following: import * as Y from 'yjs';
1259
+ gc?: boolean;
1086
1260
  }
1087
1261
  export interface DexieConstructor extends DexieExceptionClasses {
1088
1262
  new (databaseName: string, options?: DexieOptions): Dexie;
@@ -1129,16 +1303,24 @@ export class Entity<TDexieSubClass extends Dexie = Dexie> {
1129
1303
  export type IsStrictlyAny<T> = (T extends never ? true : false) extends false ? false : true;
1130
1304
  /** Extract the union of literal method names in T
1131
1305
  */
1132
- export type MethodProps<T> = {
1306
+ export type NonInsertProps<T> = {
1133
1307
  [P in keyof T]: IsStrictlyAny<T[P]> extends true ? never // Plain property of type any (not method)
1134
1308
  : T[P] extends (...args: any[]) => any ? P // a function (method)
1309
+ : T[P] extends {
1310
+ on: any;
1311
+ subdocs: any;
1312
+ gc: any;
1313
+ isSynced: any;
1314
+ isLoaded: any;
1315
+ shouldLoad: any;
1316
+ } ? P // an YDoc property - should be generated by dexie and not by user
1135
1317
  : never;
1136
1318
  }[keyof T];
1137
1319
  /** Default insert type of T is a subset of T where:
1138
1320
  * * given optional props (such as an auto-generated primary key) are made optional
1139
1321
  * * methods are omitted
1140
1322
  */
1141
- export type InsertType<T, OptionalProps extends keyof T> = Omit<T, OptionalProps | MethodProps<T>> & {
1323
+ export type InsertType<T, OptionalProps extends keyof T> = Omit<T, OptionalProps | NonInsertProps<T>> & {
1142
1324
  [P in OptionalProps]?: T[P];
1143
1325
  };
1144
1326
  /** IDType extract the actual type of the primary key:
@@ -1147,11 +1329,38 @@ export type InsertType<T, OptionalProps extends keyof T> = Omit<T, OptionalProps
1147
1329
  */
1148
1330
  export type IDType<T, TKeyPropNameOrKeyType> = IsStrictlyAny<T> extends true ? TKeyPropNameOrKeyType : TKeyPropNameOrKeyType extends string ? TKeyPropNameOrKeyType extends keyof T ? T[TKeyPropNameOrKeyType] : TKeyPropNameOrKeyType : TKeyPropNameOrKeyType;
1149
1331
  export type EntityTable<T, TKeyPropName extends keyof T = never, TInsertType = InsertType<T, TKeyPropName>> = Table<T, IDType<T, TKeyPropName>, TInsertType>;
1332
+ declare function getDocCache(db: Dexie): YDocCache;
1333
+ export interface ReleaseOptions {
1334
+ gracePeriod?: number;
1335
+ }
1336
+ declare class DexieYProvider$1<YDoc extends YjsDoc = any> implements DexieYProvider<YDoc> {
1337
+ private refCount;
1338
+ private stopObserving;
1339
+ private cleanupHandlers;
1340
+ doc: YDoc;
1341
+ awareness?: any;
1342
+ whenLoaded: Promise<void>;
1343
+ whenSynced: Promise<void>;
1344
+ on: DexieEventSet & ((name: string, f: (...args: any[]) => any) => void);
1345
+ off: (name: string, f: (...args: any[]) => any) => void;
1346
+ destroyed: boolean;
1347
+ static load<YDoc extends YjsDoc>(doc: YDoc): DexieYProvider$1<YDoc>;
1348
+ static release<YDoc extends YjsDoc>(doc: YDoc, options?: ReleaseOptions): void;
1349
+ static for<YDoc extends YjsDoc>(doc: YDoc): DexieYProvider$1<YDoc> | undefined;
1350
+ static getDocCache: typeof getDocCache;
1351
+ static currentUpdateRow: YUpdateRow | null;
1352
+ constructor(doc: YDoc);
1353
+ destroy(): void;
1354
+ addCleanupHandler(cleanupHandler: (() => void) | Unsubscribable): void;
1355
+ }
1150
1356
  export declare var Dexie: DexieConstructor;
1357
+ // Alias of Table and Collection in order to be able to refer them from module below...
1151
1358
  export interface _Table<T, TKey, TInsertType> extends Table<T, TKey, TInsertType> {
1152
1359
  }
1153
1360
  export interface _Collection<T, TKey> extends Collection<T, TKey> {
1154
1361
  }
1362
+ // Besides being the only exported value, let Dexie also be
1363
+ // a namespace for types...
1155
1364
  export declare module Dexie {
1156
1365
  // The "Dexie.Promise" type.
1157
1366
  type Promise<T = any> = PromiseExtended<T>; // Because many samples have been Dexie.Promise.
@@ -1165,12 +1374,16 @@ export declare module Dexie {
1165
1374
  export function liveQuery<T>(querier: () => T | Promise<T>): Observable<T>;
1166
1375
  export function mergeRanges(target: IntervalTree, newSet: IntervalTree): void;
1167
1376
  export function rangesOverlap(rangeSet1: IntervalTree, rangeSet2: IntervalTree): boolean;
1377
+ declare var RangeSet$1: RangeSetConstructor;
1168
1378
  export function cmp(a: any, b: any): number;
1169
1379
  export function replacePrefix(a: string, b: string): PropModification;
1170
1380
  export function add(num: number | bigint | any[]): PropModification;
1171
1381
  export function remove(num: number | bigint | any[]): PropModification;
1172
- /** Exporting 'Dexie' as the default export.
1173
- **/
1174
- export default Dexie;
1382
+
1383
+ export {
1384
+ Dexie as default,
1385
+ DexieYProvider$1 as DexieYProvider,
1386
+ RangeSet$1 as RangeSet,
1387
+ };
1175
1388
 
1176
1389
  export {};