UNPKG

single-source-of-truth

Version:

<div align='center'> <h1><strong>single-source-of-truth</strong></h1> <i>Use ArkType schemas to generate your Prisma schema</i><br> <code>pnpm add truth@npm:single-source-of-truth arktype</code> </div>

87 lines (86 loc) 3.13 kB
import { t as Standard } from "../standard-Db3GoMRB.js"; import { Type, type } from "arktype"; import { ArrayType } from "arktype/internal/variants/array.ts"; //#region src/arktype/schemas/enum.d.ts type Schema$2<values extends string[]> = Type<values[number]>; type Enum<values extends string[] = any> = Schema$2<values> & { truth: { kind: 'enum'; name: string | null; values: values; }; toTruth(this: Enum): Standard.Enum; }; declare function enum_<const values extends `${Uppercase<string>}${string}`[]>(values: values): Enum<values>; declare namespace enum_ { function is(thing: any): thing is Enum; } //#endregion //#region src/arktype/schemas/field.d.ts type Schema$1<type$1 extends string> = type.instantiate<type$1>; type Field<type$1 extends string = any> = Schema$1<type$1> & { truth: { kind: 'field'; name: string | null; id?: true; unique?: true; updatedAt?: true; }; id_(this: Field<type$1>): Field<type$1>; unique(this: Field<type$1>): Field<type$1>; updatedAt(this: Field<type$1>): Field<type$1>; }; declare function field<const type$1 extends string>(type: type.validate<type$1>): Field<type$1>; declare namespace field { function is(thing: any): thing is Field; } //#endregion //#region src/arktype/schemas/relation.d.ts type ModelLike = Model | { __shape: Shape; }; type Relation<getter extends () => ModelLike = any> = getter & { truth: { kind: 'relation'; name?: string; references?: [string, string][]; }; name(this: Relation<getter>, name: string): Relation<getter>; reference(this: Relation<getter>, ownKey: string, foreignKey: string): Relation<getter>; }; declare function relation<getter extends () => ModelLike>(getter: getter): Relation<getter>; declare namespace relation { function is(thing: any): thing is Relation; } //#endregion //#region src/arktype/schemas/model.d.ts type Shape = Record<string, Field | Enum | (() => Relation)>; type Schema<shape extends Shape> = { array(): ArrayType<type.infer<Pick<shape, fieldKeys<shape>>>[]> & { readonly __shape: shape; }; or(def: 'null'): type.instantiate<Pick<shape, fieldKeys<shape>> | 'null'> & { readonly __shape: shape; }; } & type.instantiate<Pick<shape, fieldKeys<shape>>>; type Model<shape extends Shape = any> = Schema<shape> & { truth: { kind: 'model'; name: string | null; shape: shape; id: (keyof shape)[]; unique?: (keyof shape)[][]; }; id_(this: Model<shape>, fields: (keyof shape)[]): Model<shape>; unique(this: Model<shape>, fields: (keyof shape)[]): Model<shape>; toTruth(this: Model): Standard.Model; }; declare function model<shape extends Shape>(shape: type.validate<shape>): Model<shape>; declare namespace model { function is(thing: any): thing is Model; } type fieldKeys<shape> = keyof { [key in keyof shape as shape[key] extends Field ? key : never]: true }; declare function fieldKeys<shape extends Shape>(shape: shape): Extract<keyof shape, string>[]; //#endregion export { type Enum, type Field, type Model, type Relation, enum_ as enum, enum_, field, model, relation }; //# sourceMappingURL=index.d.ts.map