Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions packages/clients/tanstack-query/src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,28 +344,28 @@ export function useModelQueries<Schema extends SchemaDef, Model extends GetModel
return useInternalMutation(schema, modelName, 'DELETE', 'deleteMany', options);
},

useCount: (options?: any) => {
return useInternalQuery(schema, modelName, 'count', undefined, options);
useCount: (args: any, options?: any) => {
return useInternalQuery(schema, modelName, 'count', args, options);
},

useSuspenseCount: (options?: any) => {
return useInternalSuspenseQuery(schema, modelName, 'count', undefined, options);
useSuspenseCount: (args: any, options?: any) => {
return useInternalSuspenseQuery(schema, modelName, 'count', args, options);
},

useAggregate: (options?: any) => {
return useInternalQuery(schema, modelName, 'aggregate', undefined, options);
useAggregate: (args: any, options?: any) => {
return useInternalQuery(schema, modelName, 'aggregate', args, options);
},

useSuspenseAggregate: (options?: any) => {
return useInternalSuspenseQuery(schema, modelName, 'aggregate', undefined, options);
useSuspenseAggregate: (args: any, options?: any) => {
return useInternalSuspenseQuery(schema, modelName, 'aggregate', args, options);
},

useGroupBy: (options?: any) => {
return useInternalQuery(schema, modelName, 'groupBy', undefined, options);
useGroupBy: (args: any, options?: any) => {
return useInternalQuery(schema, modelName, 'groupBy', args, options);
},

useSuspenseGroupBy: (options?: any) => {
return useInternalSuspenseQuery(schema, modelName, 'groupBy', undefined, options);
useSuspenseGroupBy: (args: any, options?: any) => {
return useInternalSuspenseQuery(schema, modelName, 'groupBy', args, options);
},
} as ModelQueryHooks<Schema, Model>;
}
Expand Down
12 changes: 6 additions & 6 deletions packages/clients/tanstack-query/src/svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,16 @@ export function useModelQueries<Schema extends SchemaDef, Model extends GetModel
return useInternalMutation(schema, modelName, 'DELETE', 'deleteMany', options);
},

useCount: (options?: any) => {
return useInternalQuery(schema, modelName, 'count', undefined, options);
useCount: (args: any, options?: any) => {
return useInternalQuery(schema, modelName, 'count', args, options);
},

useAggregate: (options?: any) => {
return useInternalQuery(schema, modelName, 'aggregate', undefined, options);
useAggregate: (args: any, options?: any) => {
return useInternalQuery(schema, modelName, 'aggregate', args, options);
},

useGroupBy: (options?: any) => {
return useInternalQuery(schema, modelName, 'groupBy', undefined, options);
useGroupBy: (args: any, options?: any) => {
return useInternalQuery(schema, modelName, 'groupBy', args, options);
},
} as ModelQueryHooks<Schema, Model>;
}
Expand Down
6 changes: 5 additions & 1 deletion packages/clients/tanstack-query/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ export const ORMWriteActions = [

export type ORMWriteActionType = (typeof ORMWriteActions)[number];

type HooksOperationsIneligibleForDelegateModels = OperationsIneligibleForDelegateModels extends any
? `use${Capitalize<OperationsIneligibleForDelegateModels>}`
: never;

export type TrimDelegateModelOperations<
Schema extends SchemaDef,
Model extends GetModels<Schema>,
T extends Record<string, unknown>,
> = IsDelegateModel<Schema, Model> extends true ? Omit<T, OperationsIneligibleForDelegateModels> : T;
> = IsDelegateModel<Schema, Model> extends true ? Omit<T, HooksOperationsIneligibleForDelegateModels> : T;
12 changes: 6 additions & 6 deletions packages/clients/tanstack-query/src/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,16 @@ export function useModelQueries<Schema extends SchemaDef, Model extends GetModel
return useInternalMutation(schema, modelName, 'DELETE', 'deleteMany', options);
},

useCount: (options?: any) => {
return useInternalQuery(schema, modelName, 'count', undefined, options);
useCount: (args: any, options?: any) => {
return useInternalQuery(schema, modelName, 'count', args, options);
},

useAggregate: (options?: any) => {
return useInternalQuery(schema, modelName, 'aggregate', undefined, options);
useAggregate: (args: any, options?: any) => {
return useInternalQuery(schema, modelName, 'aggregate', args, options);
},

useGroupBy: (options?: any) => {
return useInternalQuery(schema, modelName, 'groupBy', undefined, options);
useGroupBy: (args: any, options?: any) => {
return useInternalQuery(schema, modelName, 'groupBy', args, options);
},
} as ModelQueryHooks<Schema, Model>;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/clients/tanstack-query/test/react-typing-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,9 @@ client.user.useDeleteMany().mutate({ where: { email: '[email protected]' } });
function check(_value: unknown) {
// noop
}

// @ts-expect-error delegate model
client.foo.useCreate();

client.foo.useUpdate();
client.bar.useCreate();
40 changes: 40 additions & 0 deletions packages/clients/tanstack-query/test/schemas/basic/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,43 @@ export type CategorySelect = $SelectInput<$Schema, "Category">;
export type CategoryInclude = $IncludeInput<$Schema, "Category">;
export type CategoryOmit = $OmitInput<$Schema, "Category">;
export type CategoryGetPayload<Args extends $SelectIncludeOmit<$Schema, "Category", true>> = $SimplifiedModelResult<$Schema, "Category", Args>;
export type FooFindManyArgs = $FindManyArgs<$Schema, "Foo">;
export type FooFindUniqueArgs = $FindUniqueArgs<$Schema, "Foo">;
export type FooFindFirstArgs = $FindFirstArgs<$Schema, "Foo">;
export type FooCreateArgs = $CreateArgs<$Schema, "Foo">;
export type FooCreateManyArgs = $CreateManyArgs<$Schema, "Foo">;
export type FooCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Foo">;
export type FooUpdateArgs = $UpdateArgs<$Schema, "Foo">;
export type FooUpdateManyArgs = $UpdateManyArgs<$Schema, "Foo">;
export type FooUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Foo">;
export type FooUpsertArgs = $UpsertArgs<$Schema, "Foo">;
export type FooDeleteArgs = $DeleteArgs<$Schema, "Foo">;
export type FooDeleteManyArgs = $DeleteManyArgs<$Schema, "Foo">;
export type FooCountArgs = $CountArgs<$Schema, "Foo">;
export type FooAggregateArgs = $AggregateArgs<$Schema, "Foo">;
export type FooGroupByArgs = $GroupByArgs<$Schema, "Foo">;
export type FooWhereInput = $WhereInput<$Schema, "Foo">;
export type FooSelect = $SelectInput<$Schema, "Foo">;
export type FooInclude = $IncludeInput<$Schema, "Foo">;
export type FooOmit = $OmitInput<$Schema, "Foo">;
export type FooGetPayload<Args extends $SelectIncludeOmit<$Schema, "Foo", true>> = $SimplifiedModelResult<$Schema, "Foo", Args>;
export type BarFindManyArgs = $FindManyArgs<$Schema, "Bar">;
export type BarFindUniqueArgs = $FindUniqueArgs<$Schema, "Bar">;
export type BarFindFirstArgs = $FindFirstArgs<$Schema, "Bar">;
export type BarCreateArgs = $CreateArgs<$Schema, "Bar">;
export type BarCreateManyArgs = $CreateManyArgs<$Schema, "Bar">;
export type BarCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Bar">;
export type BarUpdateArgs = $UpdateArgs<$Schema, "Bar">;
export type BarUpdateManyArgs = $UpdateManyArgs<$Schema, "Bar">;
export type BarUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Bar">;
export type BarUpsertArgs = $UpsertArgs<$Schema, "Bar">;
export type BarDeleteArgs = $DeleteArgs<$Schema, "Bar">;
export type BarDeleteManyArgs = $DeleteManyArgs<$Schema, "Bar">;
export type BarCountArgs = $CountArgs<$Schema, "Bar">;
export type BarAggregateArgs = $AggregateArgs<$Schema, "Bar">;
export type BarGroupByArgs = $GroupByArgs<$Schema, "Bar">;
export type BarWhereInput = $WhereInput<$Schema, "Bar">;
export type BarSelect = $SelectInput<$Schema, "Bar">;
export type BarInclude = $IncludeInput<$Schema, "Bar">;
export type BarOmit = $OmitInput<$Schema, "Bar">;
export type BarGetPayload<Args extends $SelectIncludeOmit<$Schema, "Bar", true>> = $SimplifiedModelResult<$Schema, "Bar", Args>;
2 changes: 2 additions & 0 deletions packages/clients/tanstack-query/test/schemas/basic/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ import { type ModelResult as $ModelResult } from "@zenstackhq/orm";
export type User = $ModelResult<$Schema, "User">;
export type Post = $ModelResult<$Schema, "Post">;
export type Category = $ModelResult<$Schema, "Category">;
export type Foo = $ModelResult<$Schema, "Foo">;
export type Bar = $ModelResult<$Schema, "Bar">;
48 changes: 48 additions & 0 deletions packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,54 @@ export const schema = {
id: { type: "String" },
name: { type: "String" }
}
},
Foo: {
name: "Foo",
fields: {
id: {
name: "id",
type: "String",
id: true,
default: ExpressionUtils.call("cuid")
},
type: {
name: "type",
type: "String",
isDiscriminator: true
}
},
idFields: ["id"],
uniqueFields: {
id: { type: "String" }
},
isDelegate: true,
subModels: ["Bar"]
},
Bar: {
name: "Bar",
baseModel: "Foo",
fields: {
id: {
name: "id",
type: "String",
id: true,
default: ExpressionUtils.call("cuid")
},
type: {
name: "type",
type: "String",
originModel: "Foo",
isDiscriminator: true
},
title: {
name: "title",
type: "String"
}
},
idFields: ["id"],
uniqueFields: {
id: { type: "String" }
}
}
},
authType: "User",
Expand Down
12 changes: 11 additions & 1 deletion packages/clients/tanstack-query/test/schemas/basic/schema.zmodel
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ model Category {
id String @id @default(cuid())
name String @unique
posts Post[]
}
}

model Foo {
id String @id @default(cuid())
type String
@@delegate(type)
}

model Bar extends Foo {
title String
}
6 changes: 6 additions & 0 deletions packages/clients/tanstack-query/test/svelte-typing-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,9 @@ get(client.user.useDeleteMany()).mutate({ where: { email: '[email protected]' } }
function check(_value: unknown) {
// noop
}

// @ts-expect-error delegate model
client.foo.useCreate();

client.foo.useUpdate();
client.bar.useCreate();
6 changes: 6 additions & 0 deletions packages/clients/tanstack-query/test/vue-typing-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,9 @@ client.user.useDeleteMany().mutate({ where: { email: '[email protected]' } });
function check(_value: unknown) {
// noop
}

// @ts-expect-error delegate model
client.foo.useCreate();

client.foo.useUpdate();
client.bar.useCreate();