Skip to content

fix: @id always optional for default values #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ yarn add -D prisma-typebox-generator
```prisma
generator typebox {
provider = "prisma-typebox-generator"
// Optionally exclude relations from the generated types
includeRelations = false // default: true
// Optionally prefix all types with a string
prefix = "tbx_" // default: ""
}
```

Expand Down
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prisma-typebox-generator",
"version": "2.0.2",
"name": "jsbrain-prisma-typebox-generator",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please dont change this unless you want to fork it and create different distribution

"version": "2.0.6",
"main": "dist/index.js",
"license": "MIT",
"files": [
Expand All @@ -20,44 +20,44 @@
"typebox",
"typebox-generator"
],
"homepage": "https://github.com/adeyahya/prisma-typebox-generator",
"homepage": "https://github.com/jsbrain/prisma-typebox-generator",
"repository": {
"url": "https://github.com/adeyahya/prisma-typebox-generator.git"
"url": "https://github.com/jsbrain/prisma-typebox-generator.git"
},
"bugs": {
"email": "[email protected]",
"url": "https://github.com/adeyahya/prisma-typebox-generator/issues"
"url": "https://github.com/jsbrain/prisma-typebox-generator/issues"
},
"dependencies": {
"@prisma/generator-helper": "^2.20.1",
"@prisma/sdk": "^2.20.1",
"@prisma/generator-helper": "^4.5.0",
"@prisma/sdk": "^4.0.0",
"core-js": "3.10.0",
"prettier": "^2.3.0"
"prettier": "^2.7.1"
},
"devDependencies": {
"@babel/cli": "^7.13.14",
"@babel/core": "^7.13.14",
"@babel/preset-env": "^7.13.12",
"@babel/preset-typescript": "^7.13.0",
"@prisma/client": "^2.20.1",
"@prisma/client": "^4.5.0",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/commit-analyzer": "^8.0.1",
"@semantic-release/git": "^9.0.0",
"@semantic-release/github": "^7.2.0",
"@semantic-release/npm": "^7.1.0",
"@semantic-release/release-notes-generator": "^9.0.2",
"@sinclair/typebox": "^0.16.7",
"@sinclair/typebox": "^0.25.2",
"@types/jest": "26.0.22",
"@types/node": "^14.14.37",
"ajv": "^8.0.5",
"ajv-formats": "^2.0.2",
"ajv": "^8.11.0",
"ajv-formats": "^2.1.1",
"babel-jest": "^26.6.3",
"jest": "26.6.3",
"prisma": "^2.20.1",
"prisma": "^4.5.0",
"semantic-release": "^17.4.2",
"ts-jest": "^26.5.4",
"ts-node": "^9.1.1",
"typescript": "^4.2.3"
"typescript": "^4.8.4"
},
"scripts": {
"generate": "prisma generate",
Expand Down
5 changes: 4 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ generator client {
}

generator docs {
provider = "node ./dist/index.js"
provider = "node ./dist/index.js"
includeRelations = false
prefix = "tbx_"
}

datasource db {
Expand All @@ -28,6 +30,7 @@ model User {
}

model Post {
// id String @id @default(cuid())
id Int @id @default(autoincrement())
user User? @relation(fields: [userId], references: [id])
userId Int?
Expand Down
22 changes: 3 additions & 19 deletions prisma/typebox/Post.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
import { Type, Static } from "@sinclair/typebox";
import { Role } from "./Role";
import { tbx_Role } from "./Role";

export const Post = Type.Object({
export const tbx_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()),
});

export type PostType = Static<typeof Post>;
export type tbx_PostType = Static<typeof tbx_Post>;
22 changes: 3 additions & 19 deletions prisma/typebox/PostInput.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
import { Type, Static } from "@sinclair/typebox";
import { Role } from "./Role";
import { tbx_Role } from "./Role";

export const PostInput = Type.Object({
export const tbx_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()),
});

export type PostInputType = Static<typeof PostInput>;
export type tbx_PostInputType = Static<typeof tbx_PostInput>;
6 changes: 3 additions & 3 deletions prisma/typebox/Role.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Type, Static } from "@sinclair/typebox";

export const RoleConst = {
export const tbx_RoleConst = {
USER: Type.Literal("USER"),
ADMIN: Type.Literal("ADMIN"),
};

export const Role = Type.KeyOf(Type.Object(RoleConst));
export const tbx_Role = Type.KeyOf(Type.Object(tbx_RoleConst));

export type RoleType = Static<typeof Role>;
export type tbx_RoleType = Static<typeof tbx_Role>;
14 changes: 4 additions & 10 deletions prisma/typebox/User.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import { Type, Static } from "@sinclair/typebox";
import { Role } from "./Role";
import { tbx_Role } from "./Role";

export const User = Type.Object({
export const tbx_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()),
})
),
role: Type.Optional(tbx_Role),
keywords: Type.Array(Type.String()),
biography: Type.String(),
decimal: Type.Number(),
biginteger: Type.Integer(),
});

export type UserType = Static<typeof User>;
export type tbx_UserType = Static<typeof tbx_User>;
14 changes: 4 additions & 10 deletions prisma/typebox/UserInput.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import { Type, Static } from "@sinclair/typebox";
import { Role } from "./Role";
import { tbx_Role } from "./Role";

export const UserInput = Type.Object({
export const tbx_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()),
})
),
role: Type.Optional(tbx_Role),
keywords: Type.Array(Type.String()),
biography: Type.String(),
decimal: Type.Number(),
biginteger: Type.Integer(),
});

export type UserInputType = Static<typeof UserInput>;
export type tbx_UserInputType = Static<typeof tbx_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 './Post';
export * from './UserInput';
export * from './PostInput';
export * from './Role';
Loading