We can make it cleaner, by declaring the model as a variable.
import{ Teasim, t }from"teasim";// Maybe in a different file eg. models.tsconst SignDTO = t.Object({ username: t.String(), password: t.String(),});const app =newTeasim().post("/sign-in",({ body })=> body,{ body: SignDTO, response: SignDTO,});
This is a good approach to keeping the code clean by creating a separation of concerns.
As the complexity of the app increases, you may find yourself reusing multiple models with various controllers.
You can make it a bit cleaner by creating a "reference model".
Registering the models with setModel allows you to name a model and reference them directly in schema with auto-completion.
import{ Teasim, t }from"teasim";const app =newTeasim().model({ sign: t.Object({ username: t.String(), password: t.String(),}),}).post("/sign-in",({ body })=> body,{// with auto-completion for existing model name body:"sign", response:"sign",});
Now when we need to quickly access the model's group, we can separate a setModel into a plugin which when registered will provide a set of models.
// auth.model.tsimport{ Teasim, t }from"teasim";exportconst authModel =newTeasim().model({ sign: t.Object({ username: t.String(), password: t.String(),}),});// index.tsimport{ Teasim }from"teasim";import{ authModel }from"./auth.model.ts";const app =newTeasim().use(authModel).post("/sign-in",({ body })=> body,{// with auto-completion for existing model name body:"sign", response:"sign",});
This can prevent naming duplication at some level, but in the end, it's best to let the naming convention decision up to your team's agreement is the best option.
Teasim provides an opinionated option for you to decide to prevent decision fatigue.