File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Dexie , PromiseExtended } from '../../dist/dexie' ;
2+ import { DexieCollection } from './DexieCollection.mjs' ;
3+
4+ type TableProps < D extends Dexie > = {
5+ [ P in keyof D ] : D [ P ] extends { get ( key : any ) : PromiseExtended < any > , toArray : ( ) => PromiseExtended < any [ ] > } ? P : never ;
6+ } [ keyof D ] ;
7+
8+
9+ export type NextDexie < D extends Dexie > = {
10+ [ P in TableProps < D > ] : D [ P ] extends {
11+ get ( key : infer K ) : PromiseExtended < any > ;
12+ toArray : ( ) => PromiseExtended < Array < infer T > > ;
13+ }
14+ ? DexieCollection < T , K >
15+ : D [ P ] ;
16+ } & {
17+ readonly name : string ;
18+ readonly tables : DexieCollection < any , any > [ ] ;
19+ }
20+
21+ const wm = new WeakMap < Dexie , NextDexie < Dexie > > ( ) ;
22+
23+ export function NextDexie < D extends Dexie > ( db : D ) : NextDexie < D > {
24+ let nextDexie = wm . get ( db ) ;
25+ if ( nextDexie ) return nextDexie as NextDexie < D > ;
26+ nextDexie = {
27+ name : db . name ,
28+ tables : [ ] as DexieCollection < any , any > [ ] ,
29+ } as NextDexie < D > ;
30+ for ( const table of db . tables ) {
31+ nextDexie . tables . push ( new DexieCollection ( table ) ) ;
32+ }
33+ wm . set ( db , nextDexie ) ;
34+ return nextDexie as NextDexie < D > ;
35+ }
36+
Original file line number Diff line number Diff line change @@ -9,3 +9,5 @@ export { createMangoFilter } from './createMangoFilter.mjs';
99export { executeQuery , executeCount } from './executeMangoQuery.mjs' ;
1010export type { MangoExpression } from './MangoExpression.mjs' ;
1111export { toMapKey } from './toMapKey.mjs' ;
12+ export { NextDexie } from './NextDexie.mjs'
13+
You can’t perform that action at this time.
0 commit comments