UNPKG

json-api-nestjs

Version:
26 lines (25 loc) 1.77 kB
import { QueryField } from '../../../../utils/nestjs-shared'; import { z, ZodObject } from 'zod'; import { ObjectLiteral } from '../../../../types'; import { AllFieldWithType, ArrayPropsForEntity, RelationTree, ResultGetField } from '../../types'; import { ZodFieldsQuery } from './fields'; import { ZodFilterQuery } from './filter'; import { ZodSortQuery } from './sort'; import { ZodIncludeQuery } from './include'; import { ZodPageInputQuery } from '../zod-share'; type Shape<E extends ObjectLiteral> = { [QueryField.fields]: ZodFieldsQuery<E>; [QueryField.filter]: ZodFilterQuery<E>; [QueryField.include]: ZodIncludeQuery<E>; [QueryField.sort]: ZodSortQuery<E>; [QueryField.page]: ZodPageInputQuery; }; declare function getZodResultSchema<E extends ObjectLiteral>(shape: Shape<E>): ZodObject<Shape<E>, 'strict'>; export declare function zodQuery<E extends ObjectLiteral>(entityFieldsStructure: ResultGetField<E>, entityRelationStructure: RelationTree<E>, propsArray: ArrayPropsForEntity<E>, propsType: AllFieldWithType<E>): ZodResultSchema<E>; export type ZodResultSchema<E extends ObjectLiteral> = ReturnType<typeof getZodResultSchema<E>>; export type ZodQuery<E extends ObjectLiteral> = ReturnType<typeof zodQuery<E>>; export type Query<E extends ObjectLiteral> = z.infer<ZodQuery<E>>; declare function zodQueryOne<E extends ObjectLiteral>(entityFieldsStructure: ResultGetField<E>, entityRelationStructure: RelationTree<E>, propsArray: ArrayPropsForEntity<E>, propsType: AllFieldWithType<E>): ZodObject<Pick<Shape<E>, QueryField.fields | QueryField.include>, 'strict'>; export type ZodQueryOne<E extends ObjectLiteral> = ReturnType<typeof zodQueryOne<E>>; export type QueryOne<E extends ObjectLiteral> = z.infer<ZodQueryOne<E>>; export {};