dexie 4.1.0-alpha.2 → 4.1.0-alpha.23

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.2, Fri Oct 04 2024
7
+ * Version 4.1.0-alpha.23, Wed Nov 27 2024
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -364,6 +364,119 @@ 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 declare const PropModSymbol: unique symbol;
379
+ export type PropModSpec = {
380
+ replacePrefix?: [
381
+ string,
382
+ string
383
+ ];
384
+ add?: number | bigint | Array<string | number>;
385
+ remove?: number | bigint | Array<string | number>;
386
+ };
387
+ export class PropModification implements PropModSpec {
388
+ [PropModSymbol]?: true;
389
+ replacePrefix?: [
390
+ string,
391
+ string
392
+ ];
393
+ add?: number | bigint | Array<string | number>;
394
+ remove?: number | bigint | Array<string | number>;
395
+ execute<T>(value: T): T;
396
+ constructor(spec: PropModSpec);
397
+ }
398
+ export type UpdateSpec<T> = {
399
+ [KP in KeyPaths<Required<T>>]?: KeyPathValue<Required<T>, KP> | PropModification;
400
+ };
401
+ export interface Collection<T = any, TKey = IndexableType, TInsertType = T> {
402
+ db: Dexie;
403
+ and(filter: (x: T) => boolean): Collection<T, TKey, TInsertType>;
404
+ clone(props?: Object): Collection<T, TKey, TInsertType>;
405
+ count(): PromiseExtended<number>;
406
+ count<R>(thenShortcut: ThenShortcut<number, R>): PromiseExtended<R>;
407
+ distinct(): Collection<T, TKey, TInsertType>;
408
+ each(callback: (obj: T, cursor: {
409
+ key: IndexableType;
410
+ primaryKey: TKey;
411
+ }) => any): PromiseExtended<void>;
412
+ eachKey(callback: (key: IndexableType, cursor: {
413
+ key: IndexableType;
414
+ primaryKey: TKey;
415
+ }) => any): PromiseExtended<void>;
416
+ eachPrimaryKey(callback: (key: TKey, cursor: {
417
+ key: IndexableType;
418
+ primaryKey: TKey;
419
+ }) => any): PromiseExtended<void>;
420
+ eachUniqueKey(callback: (key: IndexableType, cursor: {
421
+ key: IndexableType;
422
+ primaryKey: TKey;
423
+ }) => any): PromiseExtended<void>;
424
+ filter<S extends T>(filter: (x: T) => x is S): Collection<S, TKey>;
425
+ filter(filter: (x: T) => boolean): Collection<T, TKey, TInsertType>;
426
+ first(): PromiseExtended<T | undefined>;
427
+ first<R>(thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
428
+ keys(): PromiseExtended<IndexableTypeArray>;
429
+ keys<R>(thenShortcut: ThenShortcut<IndexableTypeArray, R>): PromiseExtended<R>;
430
+ primaryKeys(): PromiseExtended<TKey[]>;
431
+ primaryKeys<R>(thenShortcut: ThenShortcut<TKey[], R>): PromiseExtended<R>;
432
+ last(): PromiseExtended<T | undefined>;
433
+ last<R>(thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
434
+ limit(n: number): Collection<T, TKey, TInsertType>;
435
+ offset(n: number): Collection<T, TKey, TInsertType>;
436
+ or(indexOrPrimayKey: string): WhereClause<T, TKey, TInsertType>;
437
+ raw(): Collection<T, TKey, TInsertType>;
438
+ reverse(): Collection<T, TKey, TInsertType>;
439
+ sortBy(keyPath: string): PromiseExtended<T[]>;
440
+ sortBy<R>(keyPath: string, thenShortcut: ThenShortcut<T[], R>): PromiseExtended<R>;
441
+ toArray(): PromiseExtended<Array<T>>;
442
+ toArray<R>(thenShortcut: ThenShortcut<T[], R>): PromiseExtended<R>;
443
+ uniqueKeys(): PromiseExtended<IndexableTypeArray>;
444
+ uniqueKeys<R>(thenShortcut: ThenShortcut<IndexableTypeArray, R>): PromiseExtended<R>;
445
+ until(filter: (value: T) => boolean, includeStopEntry?: boolean): Collection<T, TKey, TInsertType>;
446
+ // Mutating methods
447
+ delete(): PromiseExtended<number>;
448
+ modify(changeCallback: (obj: T, ctx: {
449
+ value: TInsertType;
450
+ }) => void | boolean): PromiseExtended<number>;
451
+ modify(changes: UpdateSpec<TInsertType>): PromiseExtended<number>;
452
+ }
453
+ export type IntervalTree = IntervalTreeNode | EmptyRange;
454
+ export interface IntervalTreeNode {
455
+ from: IndexableType; // lower bound
456
+ to: IndexableType; // upper bound
457
+ l?: IntervalTreeNode | null; // left
458
+ r?: IntervalTreeNode | null; // right
459
+ d: number; // depth
460
+ }
461
+ export interface EmptyRange {
462
+ d: 0;
463
+ }
464
+ export interface RangeSetPrototype {
465
+ add(rangeSet: IntervalTree | {
466
+ from: IndexableType;
467
+ to: IndexableType;
468
+ }): RangeSet;
469
+ addKey(key: IndexableType): RangeSet;
470
+ addKeys(keys: IndexableType[]): RangeSet;
471
+ hasKey(key: IndexableType): boolean;
472
+ [Symbol.iterator](): Iterator<IntervalTreeNode, undefined, IndexableType | undefined>;
473
+ }
474
+ export type RangeSet = RangeSetPrototype & IntervalTree;
475
+ export interface RangeSetConstructor {
476
+ (tree: IntervalTree): RangeSet;
477
+ new (): RangeSet;
478
+ new (from: IndexableType, to?: IndexableType): RangeSet;
479
+ }
367
480
  // There typings are extracted from https://github.com/tc39/proposal-observable
368
481
  declare global {
369
482
  interface SymbolConstructor {
@@ -530,116 +643,6 @@ export interface YDocCache {
530
643
  add: (doc: YjsDoc) => void;
531
644
  delete: (doc: YjsDoc) => void;
532
645
  }
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
646
  export interface DexieOnReadyEvent {
644
647
  subscribe(fn: (vipDb: Dexie) => any, bSticky: boolean): void;
645
648
  unsubscribe(fn: (vipDb: Dexie) => any): void;
@@ -746,7 +749,7 @@ export interface DBCoreMutateResponse {
746
749
  [operationNumber: number]: Error;
747
750
  };
748
751
  lastResult: any;
749
- results?: any[]; // Present on AddRequest and PutRequest.
752
+ results?: any[]; // Always present on responses to AddRequest and PutRequest.
750
753
  }
751
754
  export interface DBCoreAddRequest {
752
755
  type: "add";
@@ -935,11 +938,10 @@ export interface Table<T = any, TKey = any, TInsertType = T> {
935
938
  reverse(): Collection<T, TKey, TInsertType>;
936
939
  mapToClass(constructor: Function): Function;
937
940
  add(item: TInsertType, key?: TKey): PromiseExtended<TKey>;
938
- update(key: TKey | T, changes: ((obj: T, ctx: {
941
+ update(key: TKey | T, changes: UpdateSpec<TInsertType> | ((obj: T, ctx: {
939
942
  value: any;
940
943
  primKey: IndexableType;
941
944
  }) => void | boolean)): PromiseExtended<number>;
942
- update(key: TKey | T, changes: UpdateSpec<TInsertType>): PromiseExtended<number>;
943
945
  put(item: TInsertType, key?: TKey): PromiseExtended<TKey>;
944
946
  delete(key: TKey): PromiseExtended<void>;
945
947
  clear(): PromiseExtended<void>;
@@ -989,7 +991,7 @@ export interface Middleware<TStack extends {
989
991
  export interface DexieStacks {
990
992
  dbcore: DBCore;
991
993
  }
992
- export type TableProp<DX extends Dexie> = {
994
+ export type TableProp<DX> = {
993
995
  [K in keyof DX]: DX[K] extends {
994
996
  schema: any;
995
997
  get: any;
@@ -1252,14 +1254,17 @@ export interface DexieOptions {
1252
1254
  upperBound: Function;
1253
1255
  };
1254
1256
  allowEmptyDB?: boolean;
1255
- modifyChunkSize?: number;
1257
+ modifyChunkSize?: number | {
1258
+ [key: string]: number;
1259
+ };
1256
1260
  chromeTransactionDurability?: ChromeTransactionDurability;
1257
1261
  cache?: "immutable" | "cloned" | "disabled";
1258
1262
  Y?: YjsLib; // Caller supplies Y from the following: import * as Y from 'yjs';
1263
+ gc?: boolean;
1259
1264
  }
1260
1265
  export interface DexieConstructor extends DexieExceptionClasses {
1261
1266
  new (databaseName: string, options?: DexieOptions): Dexie;
1262
- prototype: Dexie;
1267
+ prototype: any;
1263
1268
  addons: Array<(db: Dexie) => void>;
1264
1269
  version: number;
1265
1270
  semVer: string;