File tree Expand file tree Collapse file tree 4 files changed +19
-20
lines changed
Expand file tree Collapse file tree 4 files changed +19
-20
lines changed Original file line number Diff line number Diff line change @@ -4,16 +4,16 @@ import { Repository } from '../repository/Repository'
44import { Database } from '../database/Database'
55import type { Constructor } from '../types'
66
7+ export function useRepo < R extends Repository > (
8+ repository : R ,
9+ pinia ?: Pinia ,
10+ ) : R
11+
712export function useRepo < M extends Model > (
813 model : Constructor < M > ,
914 pinia ?: Pinia ,
1015) : Repository < M >
1116
12- export function useRepo < R extends Repository > (
13- repository : Constructor < R > ,
14- pinia ?: Pinia ,
15- ) : R
16-
1717export function useRepo (
1818 ModelOrRepository : any ,
1919 pinia ?: Pinia
@@ -26,7 +26,11 @@ export function useRepo (
2626
2727 try {
2828 const typeModels = Object . values ( repository . getModel ( ) . $types ( ) )
29- if ( typeModels . length > 0 ) { typeModels . forEach ( typeModel => repository . database . register ( typeModel . newRawInstance ( ) ) ) } else { repository . database . register ( repository . getModel ( ) ) }
29+ if ( typeModels . length > 0 ) {
30+ typeModels . forEach ( typeModel => repository . database . register ( typeModel . newRawInstance ( ) ) )
31+ } else {
32+ repository . database . register ( repository . getModel ( ) )
33+ }
3034 } catch ( e ) { }
3135
3236 return repository
Original file line number Diff line number Diff line change 11import { WeakCache } from '../cache/WeakCache'
2- import type { FilledInstallOptions } from './Store'
2+ import type { InstallOptions } from './Store'
33
44export const CONFIG_DEFAULTS = {
55 model : {
66 withMeta : false ,
7- hidden : [ '_meta' , 'original' ] ,
8- visible : [ '*' ]
7+ hidden : [ '_meta' ] ,
8+ visible : [ '*' ] ,
99 } ,
1010 cache : {
1111 shared : true ,
1212 provider : WeakCache
13- }
13+ } ,
1414}
1515
16- export const config : FilledInstallOptions = { ...CONFIG_DEFAULTS }
16+ export const config : InstallOptions = { ...CONFIG_DEFAULTS }
Original file line number Diff line number Diff line change @@ -15,19 +15,14 @@ export interface CacheConfigOptions {
1515}
1616
1717export interface InstallOptions {
18- model ?: ModelConfigOptions
19- cache ?: CacheConfigOptions | boolean
20- }
21-
22- export interface FilledInstallOptions {
23- model : Required < ModelConfigOptions >
24- cache : Required < CacheConfigOptions | boolean >
18+ model : ModelConfigOptions
19+ cache : CacheConfigOptions | boolean
2520}
2621
2722/**
2823 * Install Pinia ORM to the store.
2924 */
30- export function createORM ( options ?: InstallOptions ) : PiniaPlugin {
25+ export function createORM ( options ?: Partial < InstallOptions > ) : PiniaPlugin {
3126 config . model = { ...CONFIG_DEFAULTS . model , ...options ?. model }
3227 config . cache = options ?. cache === false ? false : { ...CONFIG_DEFAULTS . cache , ...( options ?. cache !== true && options ?. cache ) }
3328 return ( ) => { }
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ interface Entities {
1515 [ name : string ] : Elements
1616}
1717
18- export function createPiniaORM ( options ?: InstallOptions ) {
18+ export function createPiniaORM ( options ?: Partial < InstallOptions > ) {
1919 const app = createApp ( { } )
2020 const pinia = createPinia ( )
2121 pinia . use ( createORM ( options ) )
You can’t perform that action at this time.
0 commit comments