dexie 4.0.9-alpha.1 → 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/dexie.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * By David Fahlander, david.fahlander@gmail.com
6
6
  *
7
- * Version 4.0.9-alpha.1, Fri Aug 23 2024
7
+ * Version 4.1.0-alpha.12, Wed Oct 16 2024
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -364,7 +364,36 @@ 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 interface DucktypedY {
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 {
368
397
  Doc: new (options?: {
369
398
  guid?: string;
370
399
  collectionid?: string;
@@ -373,7 +402,7 @@ export interface DucktypedY {
373
402
  meta?: any;
374
403
  autoLoad?: boolean;
375
404
  shouldLoad?: boolean;
376
- }) => DucktypedYDoc;
405
+ }) => YjsDoc;
377
406
  applyUpdate: Function;
378
407
  applyUpdateV2: Function;
379
408
  encodeStateAsUpdate: Function;
@@ -387,15 +416,15 @@ export interface DucktypedY {
387
416
  diffUpdateV2: Function;
388
417
  transact: Function;
389
418
  }
390
- export interface DucktypedYObservable {
419
+ export interface YjsObservable {
391
420
  on(name: string, f: (...args: any[]) => any): void;
392
421
  off(name: string, f: (...args: any[]) => any): void;
393
422
  once(name: string, f: (...args: any[]) => any): void;
394
423
  emit(name: string, args: any[]): void;
395
424
  destroy(): void;
396
425
  }
397
- /** Dock-typed Y.Doc */
398
- export interface DucktypedYDoc extends DucktypedYObservable {
426
+ /** Duck-typed Y.Doc */
427
+ export interface YjsDoc extends YjsObservable {
399
428
  guid?: any;
400
429
  collectionid?: any;
401
430
  collection?: any;
@@ -409,6 +438,18 @@ export interface DucktypedYDoc extends DucktypedYObservable {
409
438
  meta?: any;
410
439
  share: Map<any, any>;
411
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
+ }
412
453
  export interface DexieYDocMeta {
413
454
  db: Dexie;
414
455
  parentTable: string;
@@ -440,13 +481,14 @@ export interface YUpdateRow {
440
481
  f?: number;
441
482
  }
442
483
  /** 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.
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.
446
487
  */
447
- export interface YSyncer {
488
+ export interface YSyncState {
448
489
  i: string;
449
- unsentFrom: number;
490
+ unsentFrom?: number;
491
+ receivedUntil?: number;
450
492
  }
451
493
  /** A stamp of the last compressed and garbage collected update in the update table.
452
494
  * The garbage collection process will find out which documents have got new updates since the last compressed update
@@ -459,27 +501,40 @@ export interface YLastCompressed {
459
501
  lastCompressed: number;
460
502
  lastRun?: Date;
461
503
  }
462
- export interface DexieYProvider<YDoc = any> {
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> {
463
512
  readonly doc: YDoc;
464
- awareness?: any;
465
- whenLoaded: Promise<any>;
466
- whenSynced: Promise<any>;
513
+ awareness?: YjsAwareness;
514
+ whenLoaded: Promise<void>;
515
+ whenSynced: Promise<void>;
467
516
  on: DexieEventSet & ((name: string, f: (...args: any[]) => any) => void);
468
- off(name: string, f: (...args: any[]) => any): void;
517
+ off: (name: string, f: (...args: any[]) => any) => void;
518
+ addCleanupHandler(cleanupHandler: Unsubscribable | (() => void)): void;
469
519
  destroy(): void;
470
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;
471
526
  }
472
527
  export interface YDocCache {
473
528
  readonly size: number;
474
- find: (table: string, primaryKey: any, ydocProp: string) => DucktypedYDoc | undefined;
475
- add: (doc: DucktypedYDoc) => void;
476
- delete: (doc: DucktypedYDoc) => void;
529
+ find: (table: string, primaryKey: any, ydocProp: string) => YjsDoc | undefined;
530
+ add: (doc: YjsDoc) => void;
531
+ delete: (doc: YjsDoc) => void;
477
532
  }
478
533
  export type KeyPaths<T> = {
479
534
  [P in keyof T]: P extends string ? T[P] extends Array<infer K> ? K extends any[] // Array of arrays (issue #2026)
480
535
  ? P | `${P}.${number}` | `${P}.${number}.${number}` : K extends object // only drill into the array element if it's an object
481
536
  ? 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)
537
+ ? never : T[P] extends YjsDoc // Not valid in update spec or where clause (+ avoid circular reference)
483
538
  ? never : T[P] extends object ? P | `${P}.${KeyPaths<T[P]>}` : P : never;
484
539
  }[keyof T];
485
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;
@@ -691,7 +746,7 @@ export interface DBCoreMutateResponse {
691
746
  [operationNumber: number]: Error;
692
747
  };
693
748
  lastResult: any;
694
- results?: any[]; // Present on AddRequest and PutRequest.
749
+ results?: any[]; // Always present on responses to AddRequest and PutRequest.
695
750
  }
696
751
  export interface DBCoreAddRequest {
697
752
  type: "add";
@@ -1150,35 +1205,6 @@ export interface DexieDOMDependencies {
1150
1205
  indexedDB: IDBFactory;
1151
1206
  IDBKeyRange: typeof IDBKeyRange;
1152
1207
  }
1153
- // There typings are extracted from https://github.com/tc39/proposal-observable
1154
- declare global {
1155
- interface SymbolConstructor {
1156
- readonly observable: symbol;
1157
- }
1158
- }
1159
- export interface Subscribable<T> {
1160
- subscribe(observer: Partial<Observer<T>>): Unsubscribable;
1161
- }
1162
- export interface Unsubscribable {
1163
- unsubscribe(): void;
1164
- }
1165
- export interface Observable<T = any> {
1166
- subscribe(observerOrNext?: Observer<T> | ((value: T) => void)): Subscription;
1167
- subscribe(next?: ((value: T) => void) | null, error?: ((error: any) => void) | null, complete?: (() => void) | null): Subscription;
1168
- getValue?(): T;
1169
- hasValue?(): boolean;
1170
- [Symbol.observable]: () => Subscribable<T>;
1171
- }
1172
- export interface Subscription {
1173
- unsubscribe(): void;
1174
- readonly closed: boolean;
1175
- }
1176
- export interface Observer<T = any> {
1177
- start?: (subscription: Subscription) => void;
1178
- next?: (value: T) => void;
1179
- error?: (error: any) => void;
1180
- complete?: () => void;
1181
- }
1182
1208
  export type GlobalQueryCache = {
1183
1209
  // TODO: Change to parts: {[part: string]: TblQueryCache}
1184
1210
  // och unsignaledParts: ObservabilitySet;
@@ -1229,7 +1255,8 @@ export interface DexieOptions {
1229
1255
  modifyChunkSize?: number;
1230
1256
  chromeTransactionDurability?: ChromeTransactionDurability;
1231
1257
  cache?: "immutable" | "cloned" | "disabled";
1232
- Y?: DucktypedY; // Caller supplies Y from the following: import * as Y from 'yjs';
1258
+ Y?: YjsLib; // Caller supplies Y from the following: import * as Y from 'yjs';
1259
+ gc?: boolean;
1233
1260
  }
1234
1261
  export interface DexieConstructor extends DexieExceptionClasses {
1235
1262
  new (databaseName: string, options?: DexieOptions): Dexie;
@@ -1302,6 +1329,30 @@ export type InsertType<T, OptionalProps extends keyof T> = Omit<T, OptionalProps
1302
1329
  */
1303
1330
  export type IDType<T, TKeyPropNameOrKeyType> = IsStrictlyAny<T> extends true ? TKeyPropNameOrKeyType : TKeyPropNameOrKeyType extends string ? TKeyPropNameOrKeyType extends keyof T ? T[TKeyPropNameOrKeyType] : TKeyPropNameOrKeyType : TKeyPropNameOrKeyType;
1304
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
+ }
1305
1356
  export declare var Dexie: DexieConstructor;
1306
1357
  // Alias of Table and Collection in order to be able to refer them from module below...
1307
1358
  export interface _Table<T, TKey, TInsertType> extends Table<T, TKey, TInsertType> {
@@ -1328,14 +1379,10 @@ export function cmp(a: any, b: any): number;
1328
1379
  export function replacePrefix(a: string, b: string): PropModification;
1329
1380
  export function add(num: number | bigint | any[]): PropModification;
1330
1381
  export function remove(num: number | bigint | any[]): PropModification;
1331
- export declare var DexieYProvider: {
1332
- (doc: DucktypedYDoc): DexieYProvider;
1333
- new (doc: DucktypedYDoc): DexieYProvider;
1334
- getDocCache: (db: Dexie) => YDocCache;
1335
- };
1336
1382
 
1337
1383
  export {
1338
1384
  Dexie as default,
1385
+ DexieYProvider$1 as DexieYProvider,
1339
1386
  RangeSet$1 as RangeSet,
1340
1387
  };
1341
1388