Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@dans98/prismabox
Advanced tools
Generate versatile typebox schemes from your prisma schema.
Currently does not support mongoDB composite types
Install it in your project,
npm i -D prismabox
pnpm i -D prismabox
bun add -D prismabox
then add
generator prismabox {
provider = "prismabox"
// you can optionally specify the output location. Defaults to ./prismabox
output = "./myCoolPrismaboxDirectory"
// 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
typeboxImportVariableName = "t"
// 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
typeboxImportDependencyName = "elysia"
// by default the generated schemes do not allow additional properties. You can allow them by setting this to true
additionalProperties = true
// optionally enable the data model generation. See the data model section below for more info
inputModel = true
}
to your prisma.schema
. You can modify the settings to your liking, please see the respective comments for info on what the option does.
There are additional config options available which are mostly irrelevant to the average user. Please see config.ts for all available options.
Prismabox offers annotations to adjust the output of models and fields.
Annotation | Example | Description |
---|---|---|
@prismabox.hide | - | Hides the field or model from the output |
@prismabox.hidden | - | Alias for @prismabox.hide |
@prismabox.input.hide | - | Hides the field or model from the output only in the input model |
@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! |
For a more detailed list of available annotations, please see annotations.ts
A schema using annotations could look like this:
/// The post model
model Post {
id Int @id @default(autoincrement())
/// @prismabox.hidden
createdAt DateTime @default(now())
title String @unique
User User? @relation(fields: [userId], references: [id])
/// @prismabox.options{max: 10}
/// this is the user id
userId Int?
}
/// @prismabox.hidden
enum Account {
PASSKEY
PASSWORD
}
Please note that you cannot use multiple annotations in one line! Each needs to be in its own!
The generator will output schema objects based on the models:
// the plain object without any relations
export const PostPlain = ...
// only the relations of a model
export const PostRelations = ...
// a composite model of the two, providing the full type
export const Post = ...
To simplify the validation of input data, prismabox is able to generate schemes specifically for input data.
These 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.
If you want to see the specifics on how the model behaves, see here and here.
userId
or userid
will work)createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@prismabox.input.hide
) are respected.If 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.
FAQs
Typebox generator for prisma schema
The npm package @dans98/prismabox receives a total of 0 weekly downloads. As such, @dans98/prismabox popularity was classified as not popular.
We found that @dans98/prismabox 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.