
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
prisma-json-types-generator
Advanced tools
Using this package? Please consider donating to support my open source work ❤️
// schema.prisma
generator client {
provider = "prisma-client-js"
}
/// Always after the prisma-client-js generator
generator json {
provider = "prisma-json-types-generator"
// namespace = "PrismaJson"
// clientOutput = "<finds it automatically>"
// (./ -> relative to schema, or an importable path to require() it)
}
model Example {
/// [MyType]
normal Json
/// [MyType]
optional Json?
/// [MyType]
array Json[]
}
// index.ts
import type { Example } from '@prisma/client';
declare global {
namespace PrismaJson {
// you can use classes, interfaces, types, etc.
type MyType = boolean;
}
}
function myFunction(example: Example) {
// example.normal is now a boolean
// example.optional is now a boolean | null
// example.array is now a boolean[]
}
⚠️ It just changes the declaration files of your generated client, no runtime code is affected!
By using the Typescript Compiler API, this generator parses the generated client's types
AST and looks for Prisma.JsonValue
types (or related) and
replaces them with their corresponding type.
There are some complex json types like JsonFilter
and JsonWithAggregatesFilter
that,
if typed, would impact the usability of the client. So, they are still json.
This project should be a temporary workaround (and possible solution) to https://github.com/prisma/prisma/issues/3219.
Json types inside type
declarations won't work. (see
https://github.com/prisma/prisma/issues/13726)
FAQs
Changes JsonValues to your custom typescript type
The npm package prisma-json-types-generator receives a total of 127,505 weekly downloads. As such, prisma-json-types-generator popularity was classified as popular.
We found that prisma-json-types-generator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.