dexie 4.1.0-alpha.8 → 4.1.0-beta.45

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,9 +1,31 @@
1
1
  # Dexie.js
2
2
 
3
- [![NPM Version][npm-image]][npm-url] ![Build Status](https://github.com/dexie/Dexie.js/actions/workflows/main.yml/badge.svg)
3
+ [![NPM Version][npm-image]][npm-url] ![Build Status](https://github.com/dexie/Dexie.js/actions/workflows/main.yml/badge.svg) [![Join our Discord](https://img.shields.io/discord/1328303736363421747?label=Discord&logo=discord&style=badge)](https://discord.gg/huhre7MHBF)
4
4
 
5
5
  Dexie.js is a wrapper library for indexedDB - the standard database in the browser. https://dexie.org.
6
6
 
7
+
8
+ ```
9
+ /$$ /$$ /$$ /$$ /$$
10
+ | $$ | $$ | $$ | $$ | $$
11
+ | $$ | $$ /$$$$$$ /$$$$$$$| $$ /$$ /$$$$$$ /$$$$$$ | $$$$$$$ /$$$$$$ /$$$$$$$
12
+ | $$$$$$$$ |____ $$ /$$_____/| $$ /$$/ |____ $$|_ $$_/ | $$__ $$ /$$__ $$| $$__ $$
13
+ | $$__ $$ /$$$$$$$| $$ | $$$$$$/ /$$$$$$$ | $$ | $$ \ $$| $$ \ $$| $$ \ $$
14
+ | $$ | $$ /$$__ $$| $$ | $$_ $$ /$$__ $$ | $$ /$$| $$ | $$| $$ | $$| $$ | $$
15
+ | $$ | $$| $$$$$$$| $$$$$$$| $$ \ $$| $$$$$$$ | $$$$/| $$ | $$| $$$$$$/| $$ | $$
16
+ |__/ |__/ \_______/ \_______/|__/ \__/ \_______/ \___/ |__/ |__/ \______/ |__/ |__/
17
+
18
+ 🌟 Welcome to Dexie Global Hackathon 25! 🌟
19
+ 📅 Date: February 14 --> April 13, 2025
20
+ 🕒 Start coding with Dexie Cloud and win prices!
21
+
22
+ For more information: dexie.org/hackathon
23
+
24
+ Good luck! 🚀
25
+
26
+ ```
27
+ [dexie.org/hackathon](https://dexie.org/hackathon/)
28
+
7
29
  #### Why Dexie.js?
8
30
 
9
31
  IndexedDB is the portable database for all browser engines. Dexie.js makes it fun and easy to work with.
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.8, Tue Oct 15 2024
7
+ * Version 4.1.0-beta.45, Mon Mar 31 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,7 +1249,9 @@ 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';
@@ -1260,7 +1259,7 @@ export interface DexieOptions {
1260
1259
  }
1261
1260
  export interface DexieConstructor extends DexieExceptionClasses {
1262
1261
  new (databaseName: string, options?: DexieOptions): Dexie;
1263
- prototype: Dexie;
1262
+ prototype: any;
1264
1263
  addons: Array<(db: Dexie) => void>;
1265
1264
  version: number;
1266
1265
  semVer: string;
@@ -1334,21 +1333,29 @@ export interface ReleaseOptions {
1334
1333
  gracePeriod?: number;
1335
1334
  }
1336
1335
  declare class DexieYProvider$1<YDoc extends YjsDoc = any> implements DexieYProvider<YDoc> {
1337
- private refCount;
1336
+ refCount: number;
1338
1337
  private stopObserving;
1339
1338
  private cleanupHandlers;
1339
+ private graceTimer;
1340
+ private graceTimeout;
1340
1341
  doc: YDoc;
1341
1342
  awareness?: any;
1342
- whenLoaded: Promise<void>;
1343
- whenSynced: Promise<void>;
1343
+ private _error?;
1344
+ private _whenLoaded;
1345
+ private _whenSynced;
1344
1346
  on: DexieEventSet & ((name: string, f: (...args: any[]) => any) => void);
1345
1347
  off: (name: string, f: (...args: any[]) => any) => void;
1346
1348
  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 on: DexieEventSet & ((name: string, f: (...args: any[]) => any) => void);
1350
+ static getOrCreateDocument(db: Dexie, table: string, prop: string, id: any): YjsDoc;
1351
+ static load<YDoc extends YjsDoc>(doc: YDoc, options?: ReleaseOptions): DexieYProvider$1<YDoc>;
1352
+ static release<YDoc extends YjsDoc>(doc: YDoc): void;
1353
+ private _release;
1349
1354
  static for<YDoc extends YjsDoc>(doc: YDoc): DexieYProvider$1<YDoc> | undefined;
1350
1355
  static getDocCache: typeof getDocCache;
1351
1356
  static currentUpdateRow: YUpdateRow | null;
1357
+ get whenLoaded(): Promise<void>;
1358
+ get whenSynced(): Promise<void>;
1352
1359
  constructor(doc: YDoc);
1353
1360
  destroy(): void;
1354
1361
  addCleanupHandler(cleanupHandler: (() => void) | Unsubscribable): void;