Skip to content

Commit be3c4f4

Browse files
committed
refactor(pinia-orm): useRepo was having the wrong types for repositories
1 parent 81153f5 commit be3c4f4

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

packages/pinia-orm/src/composables/useRepo.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { Repository } from '../repository/Repository'
44
import { Database } from '../database/Database'
55
import type { Constructor } from '../types'
66

7+
export function useRepo<R extends Repository>(
8+
repository: R,
9+
pinia?: Pinia,
10+
): R
11+
712
export 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-
1717
export 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
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { WeakCache } from '../cache/WeakCache'
2-
import type { FilledInstallOptions } from './Store'
2+
import type { InstallOptions } from './Store'
33

44
export 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 }

packages/pinia-orm/src/store/Store.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,14 @@ export interface CacheConfigOptions {
1515
}
1616

1717
export 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 () => {}

packages/pinia-orm/tests/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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))

0 commit comments

Comments
 (0)