single-source-of-truth
v0.6.3
Published
<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>
Readme
pnpm add truth@npm:single-source-of-truth arktype// src/shapes.ts
import { field, model, relation } from 'arktype';
export const User = model({
id: field('string').id_(),
name: field('string | null'),
posts: () => relation(() => Post.array()),
});
export type User = typeof User.infer;
// ^? { id: string, name: string | null }
export const Post = model({
id: field('string').id_(),
authorId: field('string'),
title: field('string'),
author: () => relation(() => User).reference('authorId', 'id'),
});
export type Post = typeof Post.infer;
// ^? { id: string, authorId: string, title: string }// truth.config.ts
import { defineConfig } from 'truth/config';
export default defineConfig(({ registry, arktype, prisma }) => {
await arktype.import(registry, './src/shapes.ts');
await prisma.export(registry, './prisma/generated.prisma');
});truthmodel User {
id String @id
name String?
posts Post[]
}
model Post {
id String @id
authorId String
title String
author User @relation(fields: [authorId], references: [id])
}