![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
prisma-class-dto-generator
Advanced tools
Generate Prisma DTOs with seamless class-validator and class-transformer integration for TypeScript applications.
A generator for Prisma ORM that creates fully-typed Data Transfer Objects (DTOs) based on decorators from class-validator
and class-transformer
. It also provides a custom @Entity
decorator for enhanced type support, enabling correct JSON schema generation. The resulting DTOs are ready for server-side TypeScript applications, and are well-suited for use with frameworks like routing-controllers
, routing-controllers-openapi
, and class-validator-jsonschema
.
Author: unbywyd
License: Free
App
will produce InputAppDTO
and OutputAppDTO
.@filterable
, @exclude input|output
, @listable
, and @orderable
let you control which fields appear in inputs, outputs, filters, and sorting.@OpenAPI({
summary: "Get incoming requests",
description: "Get incoming requests",
responses: getOpenAPIResponse(OutputRequestDTO, true)
})
@Entity(() => import('./ExtraAppDTO.model').then(m => m.ExtraAppDTO), true)
items: ExtraAppDTO[];
npm install prisma-class-dto-generator
Just add the generator to your schema.prisma
file:
generator class_validator {
provider = "node node_modules/prisma-class-dto-generator"
output = "../src/dto_sources"
configPath = "./"
}
Create a generator-config.json file next to your Prisma schema file (e.g. schema.prisma). This JSON file allows you to specify input/output configurations, excluded fields, included relations, extended models, list configurations, and more.
export type PrismaClassDTOGeneratorModelConfig = {
excludeFields?: string[];
excludeModelFields?: {
[modelName: string]: string[]
};
includeModelFields?: {
[modelName: string]: string[]
};
includeRelations?: boolean;
extendModels?: {
[modelName: string]: {
fields: Array<PrismaClassDTOGeneratorField>
}
}
};
export type PrismaClassDTOGeneratorListModelConfig = {
pagination?: true,
itemsModePrefix?: string,
filters?: Array<string | PrismaClassDTOGeneratorField>,
orderable?: boolean
};
export type PrismaClassDTOGeneratorConfig = {
input: PrismaClassDTOGeneratorModelConfig;
output: PrismaClassDTOGeneratorModelConfig;
excludeModels?: string[];
list?: { // Generate list DTOs
includeModels: true | {
[modelName: string]: PrismaClassDTOGeneratorListModelConfig
}
},
extra?: { // Additional models and enums
enums?: {
[enumName: string]: {
values: Array<string>
}
},
models: true | {
[modelName: string]: {
type: "input" | "output",
fields: Array<PrismaClassDTOGeneratorField>
}
}
}
};
Example generator-config.json:
{
"excludeModels": [],
"input": {
"excludeFields": ["id", "createdAt", "updatedAt"],
"includeRelations": true,
"includeModelFields": {
"App": ["name", "description", "test"]
}
},
"output": {
"excludeFields": [],
"includeRelations": true,
"excludeModelFields": {
"App": []
},
"includeModelFields": {},
"extendModels": {
"App": {
"fields": [
{
"name": "role",
"type": "ERole",
"isExtra": true,
"kind": "enum",
"isRequired": false
}
]
}
}
},
"list": {
"includeModels": {
"App": {
"pagination": true,
"orderable": true,
"itemsModePrefix": "Extra",
"filters": [
{
"name": "test_best",
"type": "String",
"isList": true
}
]
}
}
},
"extra": {
"enums": {
"ERole": {
"values": ["ADMIN", "USER"]
}
},
"models": {
"App": {
"fields": [
{ "name": "test", "type": "String", "isRequired": true },
{ "name": "description", "type": "String", "isRequired": true },
{ "name": "role", "type": "Role", "kind": "enum", "isRequired": true }
]
},
"Best": {
"fields": [
{ "name": "app", "type": "App", "relationName": "app", "isRequired": true },
{ "name": "paidAt", "type": "DateTime", "isRequired": true },
{ "name": "gena", "type": "Gena", "relationName": "gena", "isRequired": true }
]
}
}
}
}
Comment-Based Configuration within Prisma Schema:
model App {
id String @id @default(cuid())
name String @unique /// @filterable
description String? /// @exclude output
logoUrl String?
isActive Boolean @default(true)
apiKey String @unique @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt /// @filterable
email String @unique /// @filterable
password String /// @exclude input
isConfirmed Boolean @default(false)
test Test[]
/// @listable
/// @orderable
}
Utility functions like toDTO help you transform plain data to DTO instances with class-transformer:
import { plainToClass } from "class-transformer";
export function toDTO<T>(DtoClass: new (...args: any[]) => T, data: any): T {
return plainToClass(DtoClass, data, {
excludeExtraneousValues: true,
});
}
FAQs
Generate Prisma DTOs with seamless class-validator and class-transformer integration for TypeScript applications.
The npm package prisma-class-dto-generator receives a total of 37 weekly downloads. As such, prisma-class-dto-generator popularity was classified as not popular.
We found that prisma-class-dto-generator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.