single-source-of-truth
Version:
Use Zod schemas to your generate Prisma schema
33 lines • 2.78 kB
TypeScript
import * as z from 'zod/v4';
import type { TruthModel } from './model.js';
import type { TruthShape } from './shape.js';
export interface TruthRelationDef<RelatedShape extends TruthShape = TruthShape> extends z.core.$ZodTypeDef {
type: 'custom';
name?: string;
references?: [field: string, relatedField: string][];
getter(): TruthModel<RelatedShape>;
}
export interface TruthRelationInternals<RelatedShape extends TruthShape = TruthShape> extends z.core.$ZodTypeInternals<TruthModel<RelatedShape>> {
def: TruthRelationDef<RelatedShape>;
}
export interface TruthRelation<RelatedShape extends TruthShape = TruthShape> extends z.ZodType<TruthModel<RelatedShape>> {
_zod: TruthRelationInternals<RelatedShape>;
def: TruthRelationDef<RelatedShape>;
unwrap(): TruthModel<RelatedShape>;
name(name: string): this;
reference(field: string, relatedField: keyof RelatedShape): this;
}
export declare const TruthRelation: z.core.$constructor<TruthRelation>;
export declare function relation<RelatedShape extends TruthShape>(getter: () => TruthModel<RelatedShape>): TruthRelation<RelatedShape>;
export declare namespace TruthRelationUtil {
type AnyRelation = TruthRelation | z.ZodNullable<TruthRelation> | z.ZodArray<TruthRelation>;
type AnyRelationAny = TruthRelation<any> | z.ZodNullable<TruthRelation<any>> | z.ZodArray<TruthRelation<any>>;
function isAnyRelation(value: unknown): value is AnyRelation;
type NormaliseRelation<Relation extends AnyRelation> = Relation extends TruthRelation<infer Shape> ? TruthModel<Shape> : Relation extends z.ZodNullable<TruthRelation<infer Shape>> ? TruthModel<Shape> : Relation extends z.ZodArray<TruthRelation<infer Shape>> ? TruthModel<Shape> : never;
function normaliseRelation<Relation extends AnyRelation>(relation: Relation): NormaliseRelation<Relation>;
type ExtractModelFromRelation<Relation extends AnyRelation> = Relation extends TruthRelation<infer Shape> ? TruthModel<Shape> : Relation extends z.ZodNullable<TruthRelation<infer Shape>> ? TruthModel<Shape> : Relation extends z.ZodArray<TruthRelation<infer Shape>> ? TruthModel<Shape> : never;
function extractModelFromRelation<Relation extends AnyRelation>(relation: Relation): ExtractModelFromRelation<Relation>;
type ApplyRelationWrapping<Template extends AnyRelation, Schema extends z.ZodType = TruthModel<ExtractModelFromRelation<Template>>> = Template extends z.ZodArray ? z.ZodArray<Schema> : Template extends z.ZodNullable ? z.ZodNullable<Schema> : Schema;
function applyRelationWrapping<Template extends AnyRelation, Schema extends z.ZodType = TruthModel<ExtractModelFromRelation<Template>>>(blueprint: Template, schema: Schema): ApplyRelationWrapping<Template, Schema>;
}
//# sourceMappingURL=relation.d.ts.map