dexie 4.1.0-alpha.7 → 4.1.0-beta.43

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/dexie.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * By David Fahlander, david.fahlander@gmail.com
6
6
  *
7
- * Version 4.1.0-alpha.7, Tue Oct 15 2024
7
+ * Version 4.1.0-beta.43, Fri Feb 07 2025
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -364,6 +364,112 @@ export interface PromiseExtended<T = any> extends Promise<T> {
364
364
  finally<U>(onFinally?: () => U | PromiseLike<U>): PromiseExtended<T>;
365
365
  timeout(ms: number, msg?: string): PromiseExtended<T>;
366
366
  }
367
+ export type KeyPathIgnoreObject = ArrayBuffer | ArrayBufferView | RegExp | Blob | FileList | FileSystemFileHandle | FileSystemDirectoryHandle | DataView | ImageBitmap | ImageData | Map<any, any> | Set<any> | CryptoKey | Promise<any> | ReadableStream<any> | ReadableStreamDefaultReader<any> | ReadableStreamDefaultController<any> | {
368
+ whenLoaded: Promise<any>;
369
+ }; // Y.Doc
370
+ export type KeyPaths<T, MAXDEPTH = "II", CURRDEPTH extends string = ""> = {
371
+ [P in keyof T]: P extends string ? CURRDEPTH extends MAXDEPTH ? P : T[P] extends Array<infer K> ? K extends any[] // Array of arrays (issue #2026)
372
+ ? P | `${P}.${number}` | `${P}.${number}.${number}` : K extends object // only drill into the array element if it's an object
373
+ ? P | `${P}.${number}` | `${P}.${number}.${KeyPaths<Required<K>>}` : P | `${P}.${number}` : T[P] extends (...args: any[]) => any // Method
374
+ ? never : T[P] extends KeyPathIgnoreObject // Not valid in update spec or where clause (+ avoid circular reference)
375
+ ? P : T[P] extends object ? P | `${P}.${KeyPaths<Required<T[P]>, MAXDEPTH, `${CURRDEPTH}I`>}` : P : never;
376
+ }[keyof T];
377
+ export type KeyPathValue<T, PATH> = PATH extends `${infer R}.${infer S}` ? R extends keyof T ? KeyPathValue<Required<T[R]>, S> : T extends any[] ? PATH extends `${number}.${infer S}` ? KeyPathValue<Required<T[number]>, S> : void : void : PATH extends `${number}` ? T extends any[] ? T[number] : void : PATH extends keyof T ? T[PATH] : any;
378
+ export type PropModSpec = {
379
+ replacePrefix?: [
380
+ string,
381
+ string
382
+ ];
383
+ add?: number | bigint | Array<string | number>;
384
+ remove?: number | bigint | Array<string | number>;
385
+ };
386
+ export class PropModification {
387
+ ["@@propmod"]: PropModSpec;
388
+ constructor(spec: PropModSpec);
389
+ execute<T>(value: T): T;
390
+ }
391
+ export type UpdateSpec<T> = {
392
+ [KP in KeyPaths<Required<T>>]?: KeyPathValue<Required<T>, KP> | PropModification;
393
+ };
394
+ export interface Collection<T = any, TKey = IndexableType, TInsertType = T> {
395
+ db: Dexie;
396
+ and(filter: (x: T) => boolean): Collection<T, TKey, TInsertType>;
397
+ clone(props?: Object): Collection<T, TKey, TInsertType>;
398
+ count(): PromiseExtended<number>;
399
+ count<R>(thenShortcut: ThenShortcut<number, R>): PromiseExtended<R>;
400
+ distinct(): Collection<T, TKey, TInsertType>;
401
+ each(callback: (obj: T, cursor: {
402
+ key: IndexableType;
403
+ primaryKey: TKey;
404
+ }) => any): PromiseExtended<void>;
405
+ eachKey(callback: (key: IndexableType, cursor: {
406
+ key: IndexableType;
407
+ primaryKey: TKey;
408
+ }) => any): PromiseExtended<void>;
409
+ eachPrimaryKey(callback: (key: TKey, cursor: {
410
+ key: IndexableType;
411
+ primaryKey: TKey;
412
+ }) => any): PromiseExtended<void>;
413
+ eachUniqueKey(callback: (key: IndexableType, cursor: {
414
+ key: IndexableType;
415
+ primaryKey: TKey;
416
+ }) => any): PromiseExtended<void>;
417
+ filter<S extends T>(filter: (x: T) => x is S): Collection<S, TKey>;
418
+ filter(filter: (x: T) => boolean): Collection<T, TKey, TInsertType>;
419
+ first(): PromiseExtended<T | undefined>;
420
+ first<R>(thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
421
+ keys(): PromiseExtended<IndexableTypeArray>;
422
+ keys<R>(thenShortcut: ThenShortcut<IndexableTypeArray, R>): PromiseExtended<R>;
423
+ primaryKeys(): PromiseExtended<TKey[]>;
424
+ primaryKeys<R>(thenShortcut: ThenShortcut<TKey[], R>): PromiseExtended<R>;
425
+ last(): PromiseExtended<T | undefined>;
426
+ last<R>(thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
427
+ limit(n: number): Collection<T, TKey, TInsertType>;
428
+ offset(n: number): Collection<T, TKey, TInsertType>;
429
+ or(indexOrPrimayKey: string): WhereClause<T, TKey, TInsertType>;
430
+ raw(): Collection<T, TKey, TInsertType>;
431
+ reverse(): Collection<T, TKey, TInsertType>;
432
+ sortBy(keyPath: string): PromiseExtended<T[]>;
433
+ sortBy<R>(keyPath: string, thenShortcut: ThenShortcut<T[], R>): PromiseExtended<R>;
434
+ toArray(): PromiseExtended<Array<T>>;
435
+ toArray<R>(thenShortcut: ThenShortcut<T[], R>): PromiseExtended<R>;
436
+ uniqueKeys(): PromiseExtended<IndexableTypeArray>;
437
+ uniqueKeys<R>(thenShortcut: ThenShortcut<IndexableTypeArray, R>): PromiseExtended<R>;
438
+ until(filter: (value: T) => boolean, includeStopEntry?: boolean): Collection<T, TKey, TInsertType>;
439
+ // Mutating methods
440
+ delete(): PromiseExtended<number>;
441
+ modify(changeCallback: (obj: T, ctx: {
442
+ value: TInsertType;
443
+ }) => void | boolean): PromiseExtended<number>;
444
+ modify(changes: UpdateSpec<TInsertType>): PromiseExtended<number>;
445
+ }
446
+ export type IntervalTree = IntervalTreeNode | EmptyRange;
447
+ export interface IntervalTreeNode {
448
+ from: IndexableType; // lower bound
449
+ to: IndexableType; // upper bound
450
+ l?: IntervalTreeNode | null; // left
451
+ r?: IntervalTreeNode | null; // right
452
+ d: number; // depth
453
+ }
454
+ export interface EmptyRange {
455
+ d: 0;
456
+ }
457
+ export interface RangeSetPrototype {
458
+ add(rangeSet: IntervalTree | {
459
+ from: IndexableType;
460
+ to: IndexableType;
461
+ }): RangeSet;
462
+ addKey(key: IndexableType): RangeSet;
463
+ addKeys(keys: IndexableType[]): RangeSet;
464
+ hasKey(key: IndexableType): boolean;
465
+ [Symbol.iterator](): Iterator<IntervalTreeNode, undefined, IndexableType | undefined>;
466
+ }
467
+ export type RangeSet = RangeSetPrototype & IntervalTree;
468
+ export interface RangeSetConstructor {
469
+ (tree: IntervalTree): RangeSet;
470
+ new (): RangeSet;
471
+ new (from: IndexableType, to?: IndexableType): RangeSet;
472
+ }
367
473
  // There typings are extracted from https://github.com/tc39/proposal-observable
368
474
  declare global {
369
475
  interface SymbolConstructor {
@@ -518,6 +624,8 @@ declare class DexieYProvider<YDoc = any> {
518
624
  addCleanupHandler(cleanupHandler: Unsubscribable | (() => void)): void;
519
625
  destroy(): void;
520
626
  readonly destroyed: boolean;
627
+ static on: DexieEventSet & ((name: string, f: (...args: any[]) => any) => void);
628
+ static getOrCreateDocument(db: Dexie, table: string, prop: string, id: any): YjsDoc;
521
629
  static load<YDoc extends YjsDoc>(doc: YDoc): DexieYProvider<YDoc>;
522
630
  static release<YDoc extends YjsDoc>(doc: YDoc, options?: ProviderReleaseOptions): void;
523
631
  static for<YDoc extends YjsDoc>(doc: YDoc): DexieYProvider<YDoc> | undefined;
@@ -530,116 +638,6 @@ export interface YDocCache {
530
638
  add: (doc: YjsDoc) => void;
531
639
  delete: (doc: YjsDoc) => void;
532
640
  }
533
- export type KeyPaths<T> = {
534
- [P in keyof T]: P extends string ? T[P] extends Array<infer K> ? K extends any[] // Array of arrays (issue #2026)
535
- ? P | `${P}.${number}` | `${P}.${number}.${number}` : K extends object // only drill into the array element if it's an object
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)
538
- ? never : T[P] extends object ? P | `${P}.${KeyPaths<T[P]>}` : P : never;
539
- }[keyof T];
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;
541
- export declare const PropModSymbol: unique symbol;
542
- export type PropModSpec = {
543
- replacePrefix?: [
544
- string,
545
- string
546
- ];
547
- add?: number | bigint | Array<string | number>;
548
- remove?: number | bigint | Array<string | number>;
549
- };
550
- export class PropModification implements PropModSpec {
551
- [PropModSymbol]?: true;
552
- replacePrefix?: [
553
- string,
554
- string
555
- ];
556
- add?: number | bigint | Array<string | number>;
557
- remove?: number | bigint | Array<string | number>;
558
- execute<T>(value: T): T;
559
- constructor(spec: PropModSpec);
560
- }
561
- export type UpdateSpec<T> = {
562
- [KP in KeyPaths<T>]?: KeyPathValue<T, KP> | PropModification;
563
- };
564
- export interface Collection<T = any, TKey = IndexableType, TInsertType = T> {
565
- db: Dexie;
566
- and(filter: (x: T) => boolean): Collection<T, TKey, TInsertType>;
567
- clone(props?: Object): Collection<T, TKey, TInsertType>;
568
- count(): PromiseExtended<number>;
569
- count<R>(thenShortcut: ThenShortcut<number, R>): PromiseExtended<R>;
570
- distinct(): Collection<T, TKey, TInsertType>;
571
- each(callback: (obj: T, cursor: {
572
- key: IndexableType;
573
- primaryKey: TKey;
574
- }) => any): PromiseExtended<void>;
575
- eachKey(callback: (key: IndexableType, cursor: {
576
- key: IndexableType;
577
- primaryKey: TKey;
578
- }) => any): PromiseExtended<void>;
579
- eachPrimaryKey(callback: (key: TKey, cursor: {
580
- key: IndexableType;
581
- primaryKey: TKey;
582
- }) => any): PromiseExtended<void>;
583
- eachUniqueKey(callback: (key: IndexableType, cursor: {
584
- key: IndexableType;
585
- primaryKey: TKey;
586
- }) => any): PromiseExtended<void>;
587
- filter<S extends T>(filter: (x: T) => x is S): Collection<S, TKey>;
588
- filter(filter: (x: T) => boolean): Collection<T, TKey, TInsertType>;
589
- first(): PromiseExtended<T | undefined>;
590
- first<R>(thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
591
- keys(): PromiseExtended<IndexableTypeArray>;
592
- keys<R>(thenShortcut: ThenShortcut<IndexableTypeArray, R>): PromiseExtended<R>;
593
- primaryKeys(): PromiseExtended<TKey[]>;
594
- primaryKeys<R>(thenShortcut: ThenShortcut<TKey[], R>): PromiseExtended<R>;
595
- last(): PromiseExtended<T | undefined>;
596
- last<R>(thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
597
- limit(n: number): Collection<T, TKey, TInsertType>;
598
- offset(n: number): Collection<T, TKey, TInsertType>;
599
- or(indexOrPrimayKey: string): WhereClause<T, TKey, TInsertType>;
600
- raw(): Collection<T, TKey, TInsertType>;
601
- reverse(): Collection<T, TKey, TInsertType>;
602
- sortBy(keyPath: string): PromiseExtended<T[]>;
603
- sortBy<R>(keyPath: string, thenShortcut: ThenShortcut<T[], R>): PromiseExtended<R>;
604
- toArray(): PromiseExtended<Array<T>>;
605
- toArray<R>(thenShortcut: ThenShortcut<T[], R>): PromiseExtended<R>;
606
- uniqueKeys(): PromiseExtended<IndexableTypeArray>;
607
- uniqueKeys<R>(thenShortcut: ThenShortcut<IndexableTypeArray, R>): PromiseExtended<R>;
608
- until(filter: (value: T) => boolean, includeStopEntry?: boolean): Collection<T, TKey, TInsertType>;
609
- // Mutating methods
610
- delete(): PromiseExtended<number>;
611
- modify(changeCallback: (obj: T, ctx: {
612
- value: TInsertType;
613
- }) => void | boolean): PromiseExtended<number>;
614
- modify(changes: UpdateSpec<TInsertType>): PromiseExtended<number>;
615
- }
616
- export type IntervalTree = IntervalTreeNode | EmptyRange;
617
- export interface IntervalTreeNode {
618
- from: IndexableType; // lower bound
619
- to: IndexableType; // upper bound
620
- l?: IntervalTreeNode | null; // left
621
- r?: IntervalTreeNode | null; // right
622
- d: number; // depth
623
- }
624
- export interface EmptyRange {
625
- d: 0;
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
- }
643
641
  export interface DexieOnReadyEvent {
644
642
  subscribe(fn: (vipDb: Dexie) => any, bSticky: boolean): void;
645
643
  unsubscribe(fn: (vipDb: Dexie) => any): void;
@@ -935,11 +933,10 @@ export interface Table<T = any, TKey = any, TInsertType = T> {
935
933
  reverse(): Collection<T, TKey, TInsertType>;
936
934
  mapToClass(constructor: Function): Function;
937
935
  add(item: TInsertType, key?: TKey): PromiseExtended<TKey>;
938
- update(key: TKey | T, changes: ((obj: T, ctx: {
936
+ update(key: TKey | T, changes: UpdateSpec<TInsertType> | ((obj: T, ctx: {
939
937
  value: any;
940
938
  primKey: IndexableType;
941
939
  }) => void | boolean)): PromiseExtended<number>;
942
- update(key: TKey | T, changes: UpdateSpec<TInsertType>): PromiseExtended<number>;
943
940
  put(item: TInsertType, key?: TKey): PromiseExtended<TKey>;
944
941
  delete(key: TKey): PromiseExtended<void>;
945
942
  clear(): PromiseExtended<void>;
@@ -989,7 +986,7 @@ export interface Middleware<TStack extends {
989
986
  export interface DexieStacks {
990
987
  dbcore: DBCore;
991
988
  }
992
- export type TableProp<DX extends Dexie> = {
989
+ export type TableProp<DX> = {
993
990
  [K in keyof DX]: DX[K] extends {
994
991
  schema: any;
995
992
  get: any;
@@ -1252,14 +1249,17 @@ export interface DexieOptions {
1252
1249
  upperBound: Function;
1253
1250
  };
1254
1251
  allowEmptyDB?: boolean;
1255
- modifyChunkSize?: number;
1252
+ modifyChunkSize?: number | {
1253
+ [key: string]: number;
1254
+ };
1256
1255
  chromeTransactionDurability?: ChromeTransactionDurability;
1257
1256
  cache?: "immutable" | "cloned" | "disabled";
1258
1257
  Y?: YjsLib; // Caller supplies Y from the following: import * as Y from 'yjs';
1258
+ gc?: boolean;
1259
1259
  }
1260
1260
  export interface DexieConstructor extends DexieExceptionClasses {
1261
1261
  new (databaseName: string, options?: DexieOptions): Dexie;
1262
- prototype: Dexie;
1262
+ prototype: any;
1263
1263
  addons: Array<(db: Dexie) => void>;
1264
1264
  version: number;
1265
1265
  semVer: string;
@@ -1333,9 +1333,11 @@ export interface ReleaseOptions {
1333
1333
  gracePeriod?: number;
1334
1334
  }
1335
1335
  declare class DexieYProvider$1<YDoc extends YjsDoc = any> implements DexieYProvider<YDoc> {
1336
- private refCount;
1336
+ refCount: number;
1337
1337
  private stopObserving;
1338
1338
  private cleanupHandlers;
1339
+ private graceTimer;
1340
+ private graceTimeout?;
1339
1341
  doc: YDoc;
1340
1342
  awareness?: any;
1341
1343
  whenLoaded: Promise<void>;
@@ -1343,8 +1345,11 @@ declare class DexieYProvider$1<YDoc extends YjsDoc = any> implements DexieYProvi
1343
1345
  on: DexieEventSet & ((name: string, f: (...args: any[]) => any) => void);
1344
1346
  off: (name: string, f: (...args: any[]) => any) => void;
1345
1347
  destroyed: boolean;
1348
+ static on: DexieEventSet & ((name: string, f: (...args: any[]) => any) => void);
1349
+ static getOrCreateDocument(db: Dexie, table: string, prop: string, id: any): YjsDoc;
1346
1350
  static load<YDoc extends YjsDoc>(doc: YDoc): DexieYProvider$1<YDoc>;
1347
1351
  static release<YDoc extends YjsDoc>(doc: YDoc, options?: ReleaseOptions): void;
1352
+ private _release;
1348
1353
  static for<YDoc extends YjsDoc>(doc: YDoc): DexieYProvider$1<YDoc> | undefined;
1349
1354
  static getDocCache: typeof getDocCache;
1350
1355
  static currentUpdateRow: YUpdateRow | null;