🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

prisma-json-types-generator

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prisma-json-types-generator

Changes JsonValues to your custom typescript type

2.0.0
Source
npm
Version published
Weekly downloads
139K
10.6%
Maintainers
1
Weekly downloads
 
Created
Source

Issues Stars License Downloads Bundlephobia Packagephobia

⚒️ Prisma Json Types Generator

A generator that changes the Prisma Client output to strongly type Json fields



// schema.prisma

generator client {
  provider      = "prisma-client-js"
}

/// >>> ALWAYS PUT AFTER THE PRISMA CLIENT GENERATOR <<<
generator test {
  provider = "prisma-json-types-generator"
  // namespace = "PrismaJson"
  // clientOutput = ".prisma/client" // (./ -> relative to schema, or an importable path to require() it)
}

model Test {
  /// [NormalType]
  field Json

  /// [OptionalType]
  field2 Json

  /// [ArrayType]
  field3 Json
}
// index.ts

declare global {
  namespace PrismaJson {
    type NormalType = boolean;

    type OptionalType = { a: number } | null;

    type ArrayType = { a: number }[];

    // you can use classes, interfaces, types, etc.
  }
}
// myFile.ts

import { Test } from '@prisma/client';

const test: Test = {
  // Intellisense works!
};

How it works

It works by using the typescript compiler api to interpret all emitted type declarations and changes their field type in the original file.

⚠️ It just changes the declaration files of your generated client, no runtime code is affected!

Some types are still json!

There's some complex json types like JsonFilter and JsonWithAggregatesFilter that still aren't supported. Feel free to make a PR!

https://github.com/arthurfiorette/prisma-json-types-generator/blob/9b2ceea0a8372629d224287a5590dbce1f0ca6dd/src/handler/module.ts#L92-L98

Limitations

Keywords

prisma

FAQs

Package last updated on 21 Jan 2023

Did you know?

Socket

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.

Install

Related posts