Skip to content

Commit

Permalink
feat: documentation hints
Browse files Browse the repository at this point in the history
  • Loading branch information
TLDMain committed Apr 14, 2023
1 parent 0e2dde1 commit 2e383fe
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 227 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prisma-typebox-generator",
"version": "2.0.2",
"version": "3.0.0",
"main": "dist/index.js",
"license": "MIT",
"files": [
Expand Down
14 changes: 14 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ datasource db {
url = env("DATABASE_URL")
}

/// model description
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
Expand All @@ -21,14 +22,27 @@ model User {
successorId Int?
role Role @default(USER)
posts Post[]
/// @docs.opt minLength: 3
/// @docs.listopt maxItems: 10
keywords String[]
/// field description
biography Json
/// ignored description
/// @docs.opt description: "used description"
decimal Decimal
/// multiline
/// description
biginteger BigInt
/// @docs.opt minimum: 0
/// @docs.type Integer
unsigned Int
/// @docs.hide
hidden Int
}

model Post {
id Int @id @default(autoincrement())
/// @docs.hide
user User? @relation(fields: [userId], references: [id])
userId Int?
}
Expand Down
17 changes: 0 additions & 17 deletions prisma/typebox/Post.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
import { Type, Static } from "@sinclair/typebox";
import { Role } from "./Role";

export const Post = Type.Object({
id: Type.Number(),
user: Type.Optional(
Type.Object({
id: Type.Number(),
createdAt: Type.Optional(Type.String()),
email: Type.String(),
weight: Type.Optional(Type.Number()),
is18: Type.Optional(Type.Boolean()),
name: Type.Optional(Type.String()),
successorId: Type.Optional(Type.Number()),
role: Type.Optional(Role),
keywords: Type.Array(Type.String()),
biography: Type.String(),
decimal: Type.Number(),
biginteger: Type.Integer(),
})
),
userId: Type.Optional(Type.Number()),
});

Expand Down
17 changes: 0 additions & 17 deletions prisma/typebox/PostInput.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
import { Type, Static } from "@sinclair/typebox";
import { Role } from "./Role";

export const PostInput = Type.Object({
id: Type.Optional(Type.Number()),
user: Type.Optional(
Type.Object({
id: Type.Optional(Type.Number()),
createdAt: Type.Optional(Type.String()),
email: Type.String(),
weight: Type.Optional(Type.Number()),
is18: Type.Optional(Type.Boolean()),
name: Type.Optional(Type.String()),
successorId: Type.Optional(Type.Number()),
role: Type.Optional(Role),
keywords: Type.Array(Type.String()),
biography: Type.String(),
decimal: Type.Number(),
biginteger: Type.Integer(),
})
),
userId: Type.Optional(Type.Number()),
});

Expand Down
44 changes: 24 additions & 20 deletions prisma/typebox/User.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import { Type, Static } from "@sinclair/typebox";
import { Role } from "./Role";

export const User = Type.Object({
id: Type.Number(),
createdAt: Type.Optional(Type.String()),
email: Type.String(),
weight: Type.Optional(Type.Number()),
is18: Type.Optional(Type.Boolean()),
name: Type.Optional(Type.String()),
successorId: Type.Optional(Type.Number()),
role: Type.Optional(Role),
posts: Type.Array(
Type.Object({
id: Type.Number(),
userId: Type.Optional(Type.Number()),
})
),
keywords: Type.Array(Type.String()),
biography: Type.String(),
decimal: Type.Number(),
biginteger: Type.Integer(),
});
export const User = Type.Object(
{
id: Type.Number(),
createdAt: Type.Optional(Type.String()),
email: Type.String(),
weight: Type.Optional(Type.Number()),
is18: Type.Optional(Type.Boolean()),
name: Type.Optional(Type.String()),
successorId: Type.Optional(Type.Number()),
role: Type.Optional(Role),
posts: Type.Array(
Type.Object({
id: Type.Number(),
userId: Type.Optional(Type.Number()),
})
),
keywords: Type.Array(Type.String({ minLength: 3 }), { maxItems: 10 }),
biography: Type.String({ description: "field description" }),
decimal: Type.Number({ description: "used description" }),
biginteger: Type.Integer({ description: "multiline\ndescription" }),
unsigned: Type.Integer({ minimum: 0 }),
},
{ description: "model description" }
);

export type UserType = Static<typeof User>;
44 changes: 24 additions & 20 deletions prisma/typebox/UserInput.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import { Type, Static } from "@sinclair/typebox";
import { Role } from "./Role";

export const UserInput = Type.Object({
id: Type.Optional(Type.Number()),
createdAt: Type.Optional(Type.String()),
email: Type.String(),
weight: Type.Optional(Type.Number()),
is18: Type.Optional(Type.Boolean()),
name: Type.Optional(Type.String()),
successorId: Type.Optional(Type.Number()),
role: Type.Optional(Role),
posts: Type.Array(
Type.Object({
id: Type.Optional(Type.Number()),
userId: Type.Optional(Type.Number()),
})
),
keywords: Type.Array(Type.String()),
biography: Type.String(),
decimal: Type.Number(),
biginteger: Type.Integer(),
});
export const UserInput = Type.Object(
{
id: Type.Optional(Type.Number()),
createdAt: Type.Optional(Type.String()),
email: Type.String(),
weight: Type.Optional(Type.Number()),
is18: Type.Optional(Type.Boolean()),
name: Type.Optional(Type.String()),
successorId: Type.Optional(Type.Number()),
role: Type.Optional(Role),
posts: Type.Array(
Type.Object({
id: Type.Optional(Type.Number()),
userId: Type.Optional(Type.Number()),
})
),
keywords: Type.Array(Type.String({ minLength: 3 }), { maxItems: 10 }),
biography: Type.String({ description: "field description" }),
decimal: Type.Number({ description: "used description" }),
biginteger: Type.Integer({ description: "multiline\ndescription" }),
unsigned: Type.Integer({ minimum: 0 }),
},
{ description: "model description" }
);

export type UserInputType = Static<typeof UserInput>;
5 changes: 5 additions & 0 deletions prisma/typebox/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './User';
export * from './UserInput';
export * from './Post';
export * from './PostInput';
export * from './Role';
Loading

0 comments on commit 2e383fe

Please sign in to comment.