{"_id":"@dans98/prismabox","name":"@dans98/prismabox","dist-tags":{"latest":"2.3.0"},"versions":{"2.3.0":{"name":"@dans98/prismabox","version":"2.3.0","license":"MIT","description":"Typebox generator for prisma schema","author":{"name":"Ade Yahya Prasetyo, m1212e"},"keywords":["prisma2","prisma","prisma-generator","prisma-schema","code-generation","typebox","typebox-generator","prismabox"],"homepage":"https://github.com/m1212e/prismabox","repository":{"url":"git+https://github.com/m1212e/prismabox.git"},"dependencies":{"@prisma/generator-helper":"^5.17.0","@sinclair/typebox":"^0.32.35","prettier":"^3.3.3"},"devDependencies":{"@biomejs/biome":"^1.8.3","@prisma/client":"5.17.0","@types/bun":"latest","esbuild":"^0.23.0","prisma":"5.17.0","typescript":"^5.5.4"},"scripts":{"dev":"bun run build && bunx prisma generate","build":"bun run typecheck && bun build.ts","lint":"biome check --write .","typecheck":"tsc --noEmit"},"_id":"@dans98/prismabox@2.3.0","bugs":{"url":"https://github.com/m1212e/prismabox/issues"},"_integrity":"sha512-TvuFfDr0/Asqth933ADOB7rYGX6NayKKB/D0fsXB0Qt8Zu2KqDDrgzx0BNYJ4lwX2UI3NX5d7NN381+DbIQwZw==","_resolved":"C:\\Users\\me\\AppData\\Local\\Temp\\df5804a03a7465a178b6dc2107c8ee2a\\dans98-prismabox-2.3.0.tgz","_from":"file:dans98-prismabox-2.3.0.tgz","_nodeVersion":"22.5.1","_npmVersion":"10.8.2","dist":{"integrity":"sha512-TvuFfDr0/Asqth933ADOB7rYGX6NayKKB/D0fsXB0Qt8Zu2KqDDrgzx0BNYJ4lwX2UI3NX5d7NN381+DbIQwZw==","shasum":"2162d4003ad631805687cad2159f5cb99ced84c2","tarball":"https://registry.npmjs.org/@dans98/prismabox/-/prismabox-2.3.0.tgz","fileCount":33,"unpackedSize":80841,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGPMvelU4ypvOsAs4CQvbUKnx/cTjDMIolE+key0ERiXAiBCEty5DxvMTKIoOu/0koZJVQFIZPiM+nMuNjEIHUg1Yw=="}]},"_npmUser":{"name":"dans98","email":"me@danielshields.uk"},"directories":{},"maintainers":[{"name":"dans98","email":"me@danielshields.uk"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/prismabox_2.3.0_1722253930244_0.893463343363406"},"_hasShrinkwrap":false}},"time":{"created":"2024-07-29T11:52:10.149Z","2.3.0":"2024-07-29T11:52:10.424Z","modified":"2024-07-29T11:52:10.674Z"},"maintainers":[{"name":"dans98","email":"me@danielshields.uk"}],"description":"Typebox generator for prisma schema","homepage":"https://github.com/m1212e/prismabox","keywords":["prisma2","prisma","prisma-generator","prisma-schema","code-generation","typebox","typebox-generator","prismabox"],"repository":{"url":"git+https://github.com/m1212e/prismabox.git"},"author":{"name":"Ade Yahya Prasetyo, m1212e"},"bugs":{"url":"https://github.com/m1212e/prismabox/issues"},"license":"MIT","readme":"# prismabox\r\nGenerate versatile [typebox](https://github.com/sinclairzx81/typebox) schemes from your [prisma](https://github.com/prisma) schema.\r\n\r\n> Currently does not support [mongoDB composite types](https://www.prisma.io/docs/orm/prisma-schema/data-model/models#defining-composite-types)\r\n\r\nInstall it in your project,\r\n```bash\r\nnpm i -D prismabox\r\npnpm i -D prismabox\r\nbun add -D prismabox\r\n```\r\n\r\n then add\r\n```prisma\r\ngenerator prismabox {\r\n  provider = \"prismabox\"\r\n  // you can optionally specify the output location. Defaults to ./prismabox\r\n  output = \"./myCoolPrismaboxDirectory\"\r\n  // if you want, you can customize the imported variable name that is used for the schemes. Defaults to \"Type\" which is what the standard typebox package offers\r\n  typeboxImportVariableName = \"t\"\r\n  // you also can specify the dependency from which the above import should happen. This is useful if a package re-exports the typebox package and you would like to use that\r\n  typeboxImportDependencyName = \"elysia\"\r\n  // by default the generated schemes do not allow additional properties. You can allow them by setting this to true\r\n  additionalProperties = true\r\n  // optionally enable the data model generation. See the data model section below for more info\r\n  inputModel = true\r\n}\r\n```\r\nto your `prisma.schema`. You can modify the settings to your liking, please see the respective comments for info on what the option does.\r\n> There are additional config options available which are mostly irrelevant to the average user. Please see [config.ts](src/config.ts) for all available options.\r\n\r\n## Annotations\r\nPrismabox offers annotations to adjust the output of models and fields.\r\n\r\n| Annotation | Example | Description |\r\n---|---|---\r\n| @prismabox.hide | - | Hides the field or model from the output |\r\n| @prismabox.hidden | - | Alias for @prismabox.hide |\r\n| @prismabox.input.hide | - | Hides the field or model from the output only in the input model |\r\n| @prismabox.options | @prismabox.options{ min: 10, max: 20 } | Uses the provided options for the field or model in the generated schema. Be careful to use valid JS/TS syntax! |\r\n> For a more detailed list of available annotations, please see [annotations.ts](src/annotations/annotations.ts)\r\n\r\nA schema using annotations could look like this:\r\n```prisma\r\n/// The post model\r\nmodel Post {\r\n  id        Int      @id @default(autoincrement())\r\n  /// @prismabox.hidden\r\n  createdAt DateTime @default(now())\r\n  title     String   @unique\r\n\r\n  User   User? @relation(fields: [userId], references: [id])\r\n  /// @prismabox.options{max: 10}\r\n  /// this is the user id\r\n  userId Int?\r\n}\r\n\r\n/// @prismabox.hidden\r\nenum Account {\r\n  PASSKEY\r\n  PASSWORD\r\n}\r\n\r\n```\r\n> Please note that you cannot use multiple annotations in one line! Each needs to be in its own!\r\n## Generated Schemes\r\nThe generator will output schema objects based on the models:\r\n```ts\r\n// the plain object without any relations\r\nexport const PostPlain = ...\r\n\r\n// only the relations of a model\r\nexport const PostRelations = ...\r\n\r\n// a composite model of the two, providing the full type\r\nexport const Post = ...\r\n\r\n```\r\n\r\n### Input models\r\nTo simplify the validation of input data, prismabox is able to generate schemes specifically for input data.\r\nThese are called \"InputModels\" and need to be explicitly enabled in the generator settings (`inputModel = true`) because they expect some conventions/field naming patterns to work properly.\r\n> If you want to see the specifics on how the model behaves, see [here](src/generators/relations.ts) and [here](src/generators/plain.ts).\r\n\r\n1. Foreign Ids need to end in Id (case is ignored, e.g. `userId` or `userid` will work)\r\n2. createdAt will be detected and ignored if it follows exactly this pattern: `createdAt DateTime @default(now())`\r\n3. updatedAt will be detected and ignored if it follows exactly this pattern: `updatedAt DateTime @updatedAt`\r\n4. Hide annotations marked for imports (`@prismabox.input.hide`) are respected.\r\n\r\nIf enabled, the generator will additonally output more schemes for each model which can be used for creating/updating entities. The model will only allow editing fields of the entity itself. For relations, only connecting/disconnecting is allowed, but changing/creating related entities is not possible.\r\n","readmeFilename":"README.md"}