Closed gotjoshua closed 1 year ago
Possible to use typia
in tRPC
.
Have not tested elysia
, but it seems possible. Will you try it?
import { initTRPC } from "@trpc/server";
import { v4 } from "uuid";
import typia from "typia";
interface IBbsArticle {
id: string;
writer: IBbsArticle.IWriter;
title: string;
body: string;
created_at: string;
}
namespace IBbsArticle {
export interface IStore {
writer: IWriter;
title: string;
body: string;
/**
* @minLength 4
* @maxLength 16
* @pattern ^[a-zA-Z0-9]+$
*/
password: string;
}
export interface IWriter {
/**
* @format uuid
*/
external_service_id?: string;
/**
* @format email
*/
email: string;
}
}
const t = initTRPC.create();
export const appRouter = t.router({
store: t.procedure
.input(typia.createAssert<IBbsArticle.IStore>())
.output(typia.createAssert<IBbsArticle>())
.query(({ input }) => {
return {
id: v4(),
writer: input.writer,
title: input.title,
body: input.body,
created_at: new Date().toString(),
};
})
});
export type AppRouter = typeof appRouter;
input(typia.createAssert<IBbsArticle.IStore>())
Ahhhh using create assert... Nice, yeah I'll try that over the weekend! Thanks 🙏
Ah but after reviewing your code , i wonder if create assert parse may be more appropriate...
I just followed guide of tRPC. It delivers parsed object into the input function.
So i didn't try with pure trpc, because my goal is to use the trpc plugin for elysia... Which is optimized for bun, and i didn't manage to get the server running with typia involved. I could run the ttsc command but the run commands didn't work. Repo here
I expect this is because bun does not employee the transformer properly.
More investigation needed.
Will support through https://github.com/samchon/typia/issues/509
Feature Request
It would be great if typia could be considered ZodEsque By trpc and elysia
i would like to experiment with using typia instead of zod and typebox and curious if you plan to offer parse functions similar to zod.