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
2 changes: 2 additions & 0 deletions packages/runtime/src/client/crud/operations/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export type CrudOperation =
| 'aggregate'
| 'groupBy';

export type AllCrudOperation = CrudOperation | 'findUniqueOrThrow' | 'findFirstOrThrow';

export type FromRelationContext<Schema extends SchemaDef> = {
model: GetModels<Schema>;
field: string;
Expand Down
10 changes: 5 additions & 5 deletions packages/runtime/src/client/crud/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class InputValidator<Schema extends SchemaDef> {
return this.validate<FindArgs<Schema, GetModels<Schema>, true>, Parameters<typeof this.makeFindSchema>[1]>(
model,
'find',
{ unique, collection: true },
{ unique },
(model, options) => this.makeFindSchema(model, options),
args,
);
Expand Down Expand Up @@ -196,7 +196,7 @@ export class InputValidator<Schema extends SchemaDef> {

// #region Find

private makeFindSchema(model: string, options: { unique: boolean; collection: boolean }) {
private makeFindSchema(model: string, options: { unique: boolean }) {
const fields: Record<string, z.ZodSchema> = {};
const where = this.makeWhereSchema(model, options.unique);
if (options.unique) {
Expand All @@ -208,13 +208,13 @@ export class InputValidator<Schema extends SchemaDef> {
fields['select'] = this.makeSelectSchema(model).optional();
fields['include'] = this.makeIncludeSchema(model).optional();
fields['omit'] = this.makeOmitSchema(model).optional();
fields['distinct'] = this.makeDistinctSchema(model).optional();
fields['cursor'] = this.makeCursorSchema(model).optional();

if (options.collection) {
if (!options.unique) {
fields['skip'] = this.makeSkipSchema().optional();
fields['take'] = this.makeTakeSchema().optional();
fields['orderBy'] = this.orArray(this.makeOrderBySchema(model, true, false), true).optional();
fields['cursor'] = this.makeCursorSchema(model).optional();
fields['distinct'] = this.makeDistinctSchema(model).optional();
}

let result: ZodType = z.strictObject(fields);
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/src/client/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { OperationNode, QueryResult, RootOperationNode, UnknownRow } from '
import type { ClientContract, ToKysely } from '.';
import type { GetModels, SchemaDef } from '../schema';
import type { MaybePromise } from '../utils/type-utils';
import type { CrudOperation } from './crud/operations/base';
import type { AllCrudOperation } from './crud/operations/base';

/**
* ZenStack runtime plugin.
Expand Down Expand Up @@ -61,7 +61,7 @@ type OnQueryHookContext<Schema extends SchemaDef> = {
/**
* The operation that is being performed.
*/
operation: CrudOperation;
operation: AllCrudOperation;

/**
* The query arguments.
Expand Down