UNPKG

@chubbyts/chubbyts-api

Version:

[![CI](https://github.com/chubbyts/chubbyts-api/workflows/CI/badge.svg?branch=master)](https://github.com/chubbyts/chubbyts-api/actions?query=workflow%3ACI) [![Coverage Status](https://coveralls.io/repos/github/chubbyts/chubbyts-api/badge.svg?branch=maste

81 lines (80 loc) 5.21 kB
import type { ServerRequest } from '@chubbyts/chubbyts-http-types/dist/message'; import { z } from 'zod'; export declare const stringSchema: z.ZodString; export declare const numberSchema: z.ZodCoercedNumber<unknown>; export declare const dateSchema: z.ZodCoercedDate<unknown>; export declare const sortSchema: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"asc">, z.ZodLiteral<"desc">]>>; export type SortSchema = typeof sortSchema; type AnyNumberSchema = z.ZodNumber | z.ZodDefault<z.ZodNumber> | z.ZodCoercedNumber | z.ZodDefault<z.ZodCoercedNumber>; type AnyDateSchema = z.ZodDate | z.ZodDefault<z.ZodDate> | z.ZodCoercedDate | z.ZodDefault<z.ZodCoercedDate>; declare const embeddedSchema: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>; export type EmbeddedSchema = typeof embeddedSchema; declare const linkSchema: z.ZodIntersection<z.ZodObject<{ href: z.ZodString; name: z.ZodOptional<z.ZodString>; templated: z.ZodOptional<z.ZodBoolean>; }, z.core.$strip>, z.ZodRecord<z.ZodString, z.ZodUnknown>>; type LinkSchema = typeof linkSchema; export type Link = z.infer<LinkSchema>; declare const linksSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodIntersection<z.ZodObject<{ href: z.ZodString; name: z.ZodOptional<z.ZodString>; templated: z.ZodOptional<z.ZodBoolean>; }, z.core.$strip>, z.ZodRecord<z.ZodString, z.ZodUnknown>>, z.ZodArray<z.ZodIntersection<z.ZodObject<{ href: z.ZodString; name: z.ZodOptional<z.ZodString>; templated: z.ZodOptional<z.ZodBoolean>; }, z.core.$strip>, z.ZodRecord<z.ZodString, z.ZodUnknown>>>]>>>; type LinksSchema = typeof linksSchema; export type InputModelSchema = z.ZodObject<z.ZodRawShape>; export type InputModel<IMS extends InputModelSchema> = z.infer<IMS>; export type InputModelListSchema = z.ZodObject<{ offset: AnyNumberSchema; limit: AnyNumberSchema; filters: z.ZodObject | z.ZodDefault<z.ZodObject>; sort: z.ZodObject<{ [key: string]: SortSchema; }> | z.ZodDefault<z.ZodObject<{ [key: string]: SortSchema | z.ZodDefault<SortSchema>; }>>; }>; export type InputModelList<IMLS extends InputModelListSchema> = z.infer<IMLS>; export type ModelSchema<IMS extends InputModelSchema> = IMS & z.ZodObject<{ id: z.ZodString; createdAt: AnyDateSchema; updatedAt: z.ZodOptional<AnyDateSchema>; }>; export type Model<IMS extends InputModelSchema> = z.infer<ModelSchema<IMS>>; export declare const createModelSchema: <IMS extends InputModelSchema>(inputModelSchema: IMS) => ModelSchema<IMS>; export type ModelListSchema<IMS extends InputModelSchema, IMLS extends InputModelListSchema> = IMLS & z.ZodObject<{ count: AnyNumberSchema; items: z.ZodArray<ModelSchema<IMS>>; }>; export type ModelList<IMS extends InputModelSchema, IMLS extends InputModelListSchema> = z.infer<ModelListSchema<IMS, IMLS>>; export declare const createModelListSchema: <IMS extends InputModelSchema, IMLS extends InputModelListSchema>(inputModelSchema: IMS, inputModelListSchema: IMLS) => ModelListSchema<IMS, IMLS>; export type EnrichedModelSchema<IMS extends InputModelSchema, EMS extends EmbeddedSchema = EmbeddedSchema> = IMS & z.ZodObject<{ id: z.ZodString; createdAt: AnyDateSchema; updatedAt: z.ZodOptional<AnyDateSchema>; _embedded: EMS; _links: LinksSchema; }>; export type EnrichedModel<IMS extends InputModelSchema, EMS extends EmbeddedSchema = EmbeddedSchema> = z.infer<EnrichedModelSchema<IMS, EMS>>; export declare const createEnrichedModelSchema: <IMS extends InputModelSchema, EMS extends EmbeddedSchema = EmbeddedSchema>(inputModelSchema: IMS, embeddedModelSchema?: EMS) => EnrichedModelSchema<IMS, EMS>; export type EnrichedModelListSchema<IMS extends InputModelSchema, IMLS extends InputModelListSchema, EMS extends EmbeddedSchema = EmbeddedSchema, EMLS extends EmbeddedSchema = EmbeddedSchema> = IMLS & z.ZodObject<{ count: AnyNumberSchema; items: z.ZodArray<EnrichedModelSchema<IMS, EMS>>; _embedded: EMLS; _links: LinksSchema; }>; export type EnrichedModelList<IMS extends InputModelSchema, IMLS extends InputModelListSchema, EMS extends EmbeddedSchema = EmbeddedSchema, EMLS extends EmbeddedSchema = EmbeddedSchema> = z.infer<EnrichedModelListSchema<IMS, IMLS, EMS, EMLS>>; export declare const createEnrichedModelListSchema: <IMS extends InputModelSchema, IMLS extends InputModelListSchema, EMS extends EmbeddedSchema = EmbeddedSchema, EMLS extends EmbeddedSchema = EmbeddedSchema>(inputModelSchema: IMS, inputModelListSchema: IMLS, embeddedModelSchema?: EMS, embeddedModelListSchema?: EMLS) => EnrichedModelListSchema<IMS, IMLS, EMS, EMLS>; export type EnrichModel<IMS extends InputModelSchema, EMS extends EmbeddedSchema = EmbeddedSchema> = (model: Model<IMS>, context: { request: ServerRequest; [key: string]: unknown; }) => Promise<EnrichedModel<IMS, EMS>>; export type EnrichModelList<IMS extends InputModelSchema, IMLS extends InputModelListSchema, EMS extends EmbeddedSchema = EmbeddedSchema, EMLS extends EmbeddedSchema = EmbeddedSchema> = (list: ModelList<IMS, IMLS>, context: { request: ServerRequest; [key: string]: unknown; }) => Promise<EnrichedModelList<IMS, IMLS, EMS, EMLS>>; export {};