From d4d9c3a09bf5e7991c882143a28bf8dffb823019 Mon Sep 17 00:00:00 2001 From: Gregor Becker Date: Thu, 6 Jun 2024 08:46:32 +0200 Subject: [PATCH 1/4] fix(pinia-orm): `.find` returning type `any` when using `useRepo` --- packages/pinia-orm/src/types/repository.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/pinia-orm/src/types/repository.ts b/packages/pinia-orm/src/types/repository.ts index 59702ec7d..d68bfa498 100644 --- a/packages/pinia-orm/src/types/repository.ts +++ b/packages/pinia-orm/src/types/repository.ts @@ -31,6 +31,5 @@ declare module '../repository/Repository' { */ find (id: string | number): Item find (ids: (string | number)[]): Collection - find (ids: any): Item } } From ddb257e3ad87bca2213f8fe837c826993fdfa2c3 Mon Sep 17 00:00:00 2001 From: Gregor Becker Date: Mon, 17 Jun 2024 21:25:13 +0200 Subject: [PATCH 2/4] refactor(pinia-orm): returning type of `find` is still any --- .../pinia-orm/src/repository/Repository.ts | 32 +++++++++++++++++ packages/pinia-orm/src/types/repository.ts | 35 ------------------- playgrounds/nuxt3/app.vue | 3 ++ 3 files changed, 35 insertions(+), 35 deletions(-) delete mode 100644 packages/pinia-orm/src/types/repository.ts diff --git a/packages/pinia-orm/src/repository/Repository.ts b/packages/pinia-orm/src/repository/Repository.ts index 1b8537c62..e14766bcb 100644 --- a/packages/pinia-orm/src/repository/Repository.ts +++ b/packages/pinia-orm/src/repository/Repository.ts @@ -25,6 +25,38 @@ import type { WeakCache } from '../cache/WeakCache' import { config as globalConfig } from '../store/Config' import type { FilledInstallOptions } from '../store/Store' +export interface Repository { + /** + * Add a where clause where `field` value is in values. + */ + whereIn (field: string, values: any[] | Set): Query + /** + * Add a where clause where `field` value is in values or ... + */ + orWhereIn (field: string, values: any[] | Set): Query + /** + * Add a where clause where `field` value is not in values or ... + */ + orWhereNotIn (field: string, values: any[] | Set): Query + /** + * Add a where clause where `field` has not defined values + */ + whereNotIn (field: string, values: any[] | Set): Query + /** + * Add a where clause to get all results where `field` is null + */ + whereNull (field: string): Query + /** + * Add a where clause to get all results where `field` is not null + */ + whereNotNull (field: string): Query + /** + * Find the model with the given id. + */ + find (id: string | number): Item + find (ids: (string | number)[]): Collection +} + export class Repository { [index: string]: any /** diff --git a/packages/pinia-orm/src/types/repository.ts b/packages/pinia-orm/src/types/repository.ts deleted file mode 100644 index d68bfa498..000000000 --- a/packages/pinia-orm/src/types/repository.ts +++ /dev/null @@ -1,35 +0,0 @@ -import type { Collection, Item, Model, Query } from '../' - -declare module '../repository/Repository' { - interface Repository { - /** - * Add a where clause where `field` value is in values. - */ - whereIn (field: string, values: any[] | Set): Query - /** - * Add a where clause where `field` value is in values or ... - */ - orWhereIn (field: string, values: any[] | Set): Query - /** - * Add a where clause where `field` value is not in values or ... - */ - orWhereNotIn (field: string, values: any[] | Set): Query - /** - * Add a where clause where `field` has not defined values - */ - whereNotIn (field: string, values: any[] | Set): Query - /** - * Add a where clause to get all results where `field` is null - */ - whereNull (field: string): Query - /** - * Add a where clause to get all results where `field` is not null - */ - whereNotNull (field: string): Query - /** - * Find the model with the given id. - */ - find (id: string | number): Item - find (ids: (string | number)[]): Collection - } -} diff --git a/playgrounds/nuxt3/app.vue b/playgrounds/nuxt3/app.vue index c1de59d18..75e5736aa 100644 --- a/playgrounds/nuxt3/app.vue +++ b/playgrounds/nuxt3/app.vue @@ -5,6 +5,7 @@