New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

zod-prisma

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zod-prisma - npm Package Compare versions

Comparing version

to
0.2.0

13

dist/zod-prisma.cjs.development.js
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var path = _interopDefault(require('path'));
var generatorHelper = require('@prisma/generator-helper');

@@ -111,2 +114,5 @@ var tsMorph = require('ts-morph');

var models = options.dmmf.datamodel.models;
var prismaClient = options.otherGenerators.find(function (each) {
return each.provider.value === 'prisma-client-js';
});
var relationModel = options.generator.config.relationModel;

@@ -117,2 +123,4 @@ var indexSource = project.createSourceFile(outputPath + "/index.ts", {}, {

models.forEach(function (model) {
var _prismaClient$output;
indexSource.addExportDeclaration({

@@ -144,3 +152,3 @@ moduleSpecifier: "./" + model.name.toLowerCase()

kind: tsMorph.StructureKind.ImportDeclaration,
moduleSpecifier: '@prisma/client',
moduleSpecifier: prismaClient != null && (_prismaClient$output = prismaClient.output) != null && _prismaClient$output.value ? path.relative(outputPath, prismaClient.output.value) : '@prisma/client',
namedImports: [model.name].concat(enumFields.map(function (f) {

@@ -203,2 +211,3 @@ return f.type;

name: relatedModelName(model.name),
type: "z.ZodSchema<Complete" + model.name + ">",
initializer: function initializer(writer) {

@@ -210,3 +219,3 @@ writer.write("z.lazy(() => " + modelName(model.name) + ".extend(").inlineBlock(function () {

});
}).write(')).schema');
}).write('))');
}

@@ -213,0 +222,0 @@ }]

2

dist/zod-prisma.cjs.production.min.js

@@ -1,2 +0,2 @@

"use strict";var e=require("@prisma/generator-helper"),n=require("ts-morph"),t=require("typescript"),r=function(e){var n=[];if(e){var t=e.split("\n").filter((function(e){return!e.trimLeft().startsWith("@zod")}));t.length&&(n.push("/**"),t.forEach((function(e){return n.push(" * "+e)})),n.push(" */"))}return n},i=function(e,n){void 0===n&&(n=function(e){return e});var t="unknown()",r=[""];if("scalar"===e.kind)switch(e.type){case"String":t="z.string()";break;case"Int":t="z.number()",r.push("int()");break;case"DateTime":t="z.date()";break;case"Float":t="z.number()";break;case"Json":t="z.any()";break;case"Boolean":t="z.boolean()"}else"enum"===e.kind?t="z.nativeEnum("+e.type+")":"object"===e.kind&&(t=n(e.type));return e.isRequired||r.push("nullable()"),e.isList&&r.push("array()"),e.documentation&&r.push.apply(r,e.documentation.split("\n").filter((function(e){return e.trimLeft().startsWith("@zod")})).map((function(e){return e.trim().split("@zod.").slice(-1)[0]}))),""+t+r.join(".")},a=function(e,n,t){return void 0===t&&(t=!0),n.forEach((function(n){return e.write(n).conditionalNewLine(t)}))};e.generatorHandler({onManifest:function(){return{prettyName:"Zod Schemas",defaultOutput:"zod",version:"0.1.0"}},onGenerate:function(e){var o=new n.Project({skipAddingFilesFromTsConfig:!0}),c=e.generator.output.value,u=e.dmmf.datamodel.models,d=e.generator.config.relationModel,l=o.createSourceFile(c+"/index.ts",{},{overwrite:!0});return u.forEach((function(e){l.addExportDeclaration({moduleSpecifier:"./"+e.name.toLowerCase()});var u=function(e){return"default"===d?"_"+e+"Model":e+"Model"},s=function(e){return"default"===d?e+"Model":"Related"+e+"Model"},m=o.createSourceFile(c+"/"+e.name.toLowerCase()+".ts",{statements:[{kind:n.StructureKind.ImportDeclaration,namespaceImport:"z",moduleSpecifier:"zod"}]},{overwrite:!0}),f=e.fields.filter((function(e){return"enum"===e.kind}));m.addImportDeclaration({kind:n.StructureKind.ImportDeclaration,moduleSpecifier:"@prisma/client",namedImports:[e.name].concat(f.map((function(e){return e.type})))}),m.addStatements((function(n){return a(n,r(e.documentation))})),m.addVariableStatement({declarationKind:n.VariableDeclarationKind.Const,isExported:!0,declarations:[{name:u(e.name),initializer:function(n){n.write("z.object(").inlineBlock((function(){e.fields.filter((function(e){return"object"!==e.kind})).forEach((function(e){a(n,r(e.documentation)),n.write(e.name+": "+i(e)).write(",").newLine()}))})).write(")")}}]});var p=e.fields.filter((function(e){return"object"===e.kind}));!1!==d&&p.length>0&&(m.addImportDeclaration({kind:n.StructureKind.ImportDeclaration,moduleSpecifier:"./index",namedImports:Array.from(new Set(p.flatMap((function(e){return["Complete"+e.type,s(e.type)]}))))}),m.addInterface({name:"Complete"+e.name,isExported:!0,extends:function(n){return n.write(e.name)},properties:p.map((function(e){return{name:e.name,type:"Complete"+e.type+(e.isList?"[]":"")+(e.isRequired?"":" | null")}}))}),m.addStatements((function(n){return a(n,["","/**"," * "+s(e.name)+" contains all relations on your model in addition to the scalars"," *"," * NOTE: Lazy required in case of potential circular dependencies within schema"," */"])})),m.addVariableStatement({declarationKind:n.VariableDeclarationKind.Const,isExported:!0,declarations:[{name:s(e.name),initializer:function(n){n.write("z.lazy(() => "+u(e.name)+".extend(").inlineBlock((function(){p.forEach((function(e){a(n,r(e.documentation)),n.write(e.name+": "+i(e,s)).write(",").newLine()}))})).write(")).schema")}}]})),m.formatText({indentSize:2,convertTabsToSpaces:!0,semicolons:t.SemicolonPreference.Remove})})),o.save()}});
"use strict";var e,t=(e=require("path"))&&"object"==typeof e&&"default"in e?e.default:e,n=require("@prisma/generator-helper"),r=require("ts-morph"),i=require("typescript"),a=function(e){var t=[];if(e){var n=e.split("\n").filter((function(e){return!e.trimLeft().startsWith("@zod")}));n.length&&(t.push("/**"),n.forEach((function(e){return t.push(" * "+e)})),t.push(" */"))}return t},o=function(e,t){void 0===t&&(t=function(e){return e});var n="unknown()",r=[""];if("scalar"===e.kind)switch(e.type){case"String":n="z.string()";break;case"Int":n="z.number()",r.push("int()");break;case"DateTime":n="z.date()";break;case"Float":n="z.number()";break;case"Json":n="z.any()";break;case"Boolean":n="z.boolean()"}else"enum"===e.kind?n="z.nativeEnum("+e.type+")":"object"===e.kind&&(n=t(e.type));return e.isRequired||r.push("nullable()"),e.isList&&r.push("array()"),e.documentation&&r.push.apply(r,e.documentation.split("\n").filter((function(e){return e.trimLeft().startsWith("@zod")})).map((function(e){return e.trim().split("@zod.").slice(-1)[0]}))),""+n+r.join(".")},u=function(e,t,n){return void 0===n&&(n=!0),t.forEach((function(t){return e.write(t).conditionalNewLine(n)}))};n.generatorHandler({onManifest:function(){return{prettyName:"Zod Schemas",defaultOutput:"zod",version:"0.1.0"}},onGenerate:function(e){var n=new r.Project({skipAddingFilesFromTsConfig:!0}),c=e.generator.output.value,d=e.dmmf.datamodel.models,l=e.otherGenerators.find((function(e){return"prisma-client-js"===e.provider.value})),s=e.generator.config.relationModel,m=n.createSourceFile(c+"/index.ts",{},{overwrite:!0});return d.forEach((function(e){var d;m.addExportDeclaration({moduleSpecifier:"./"+e.name.toLowerCase()});var f=function(e){return"default"===s?"_"+e+"Model":e+"Model"},p=function(e){return"default"===s?e+"Model":"Related"+e+"Model"},h=n.createSourceFile(c+"/"+e.name.toLowerCase()+".ts",{statements:[{kind:r.StructureKind.ImportDeclaration,namespaceImport:"z",moduleSpecifier:"zod"}]},{overwrite:!0}),v=e.fields.filter((function(e){return"enum"===e.kind}));h.addImportDeclaration({kind:r.StructureKind.ImportDeclaration,moduleSpecifier:null!=l&&null!=(d=l.output)&&d.value?t.relative(c,l.output.value):"@prisma/client",namedImports:[e.name].concat(v.map((function(e){return e.type})))}),h.addStatements((function(t){return u(t,a(e.documentation))})),h.addVariableStatement({declarationKind:r.VariableDeclarationKind.Const,isExported:!0,declarations:[{name:f(e.name),initializer:function(t){t.write("z.object(").inlineBlock((function(){e.fields.filter((function(e){return"object"!==e.kind})).forEach((function(e){u(t,a(e.documentation)),t.write(e.name+": "+o(e)).write(",").newLine()}))})).write(")")}}]});var w=e.fields.filter((function(e){return"object"===e.kind}));!1!==s&&w.length>0&&(h.addImportDeclaration({kind:r.StructureKind.ImportDeclaration,moduleSpecifier:"./index",namedImports:Array.from(new Set(w.flatMap((function(e){return["Complete"+e.type,p(e.type)]}))))}),h.addInterface({name:"Complete"+e.name,isExported:!0,extends:function(t){return t.write(e.name)},properties:w.map((function(e){return{name:e.name,type:"Complete"+e.type+(e.isList?"[]":"")+(e.isRequired?"":" | null")}}))}),h.addStatements((function(t){return u(t,["","/**"," * "+p(e.name)+" contains all relations on your model in addition to the scalars"," *"," * NOTE: Lazy required in case of potential circular dependencies within schema"," */"])})),h.addVariableStatement({declarationKind:r.VariableDeclarationKind.Const,isExported:!0,declarations:[{name:p(e.name),type:"z.ZodSchema<Complete"+e.name+">",initializer:function(t){t.write("z.lazy(() => "+f(e.name)+".extend(").inlineBlock((function(){w.forEach((function(e){u(t,a(e.documentation)),t.write(e.name+": "+o(e,p)).write(",").newLine()}))})).write("))")}}]})),h.formatText({indentSize:2,convertTabsToSpaces:!0,semicolons:i.SemicolonPreference.Remove})})),n.save()}});
//# sourceMappingURL=zod-prisma.cjs.production.min.js.map

@@ -0,1 +1,2 @@

import path from 'path';
import { generatorHandler } from '@prisma/generator-helper';

@@ -109,2 +110,5 @@ import { Project, StructureKind, VariableDeclarationKind } from 'ts-morph';

var models = options.dmmf.datamodel.models;
var prismaClient = options.otherGenerators.find(function (each) {
return each.provider.value === 'prisma-client-js';
});
var relationModel = options.generator.config.relationModel;

@@ -115,2 +119,4 @@ var indexSource = project.createSourceFile(outputPath + "/index.ts", {}, {

models.forEach(function (model) {
var _prismaClient$output;
indexSource.addExportDeclaration({

@@ -142,3 +148,3 @@ moduleSpecifier: "./" + model.name.toLowerCase()

kind: StructureKind.ImportDeclaration,
moduleSpecifier: '@prisma/client',
moduleSpecifier: prismaClient != null && (_prismaClient$output = prismaClient.output) != null && _prismaClient$output.value ? path.relative(outputPath, prismaClient.output.value) : '@prisma/client',
namedImports: [model.name].concat(enumFields.map(function (f) {

@@ -201,2 +207,3 @@ return f.type;

name: relatedModelName(model.name),
type: "z.ZodSchema<Complete" + model.name + ">",
initializer: function initializer(writer) {

@@ -208,3 +215,3 @@ writer.write("z.lazy(() => " + modelName(model.name) + ".extend(").inlineBlock(function () {

});
}).write(')).schema');
}).write('))');
}

@@ -211,0 +218,0 @@ }]

{
"version": "0.1.2",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"bin": "bin/cli.js",
"files": [
"dist",
"src",
"bin"
],
"engines": {
"node": ">=14"
"version": "0.2.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"bin": {
"zod-prisma": "bin/cli.js"
},
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test",
"lint": "tsdx lint src test/*.test.ts test/**/*.test.ts",
"size": "size-limit",
"analyze": "size-limit --why"
},
"peerDependencies": {
"prisma": "^2.24.0",
"zod": "^3.0.0"
},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
}
},
"prettier": {
"printWidth": 80,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"tabWidth": 4,
"useTabs": true
},
"name": "zod-prisma",
"author": "Carter Grimmeisen",
"module": "dist/zod-prisma.esm.js",
"size-limit": [
{
"path": "dist/zod-prisma.cjs.production.min.js",
"limit": "10 KB"
},
{
"path": "dist/zod-prisma.esm.js",
"limit": "10 KB"
}
],
"resolutions": {
"eslint": "^7.17.0"
},
"devDependencies": {
"@size-limit/preset-small-lib": "^4.5.5",
"@types/fs-extra": "^9.0.11",
"@typescript-eslint/eslint-plugin": "^4.26.1-alpha.0",
"@typescript-eslint/parser": "^4.26.1-alpha.0",
"eslint": "^7.17.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-prettier": "^3.4.0",
"execa": "^5.1.0",
"fast-glob": "^3.2.5",
"fs-extra": "^10.0.0",
"husky": "^6.0.0",
"jest-mock-extended": "^1.0.15",
"prettier": "^2.3.0",
"prisma": "^2.24.1",
"size-limit": "^4.11.0",
"tsdx": "^0.14.1",
"tslib": "^2.2.0",
"typescript": "^4.2.4",
"zod": "^3.1.0"
},
"dependencies": {
"@prisma/generator-helper": "^2.24.0",
"ts-morph": "^11.0.0"
}
}
"files": [
"dist",
"src",
"bin"
],
"engines": {
"node": ">=14"
},
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test",
"lint": "tsdx lint src test/*.test.ts test/**/*.test.ts"
},
"peerDependencies": {
"prisma": "^3.3.0",
"zod": "^3.0.0"
},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
}
},
"prettier": {
"printWidth": 80,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"tabWidth": 4,
"useTabs": true
},
"name": "zod-prisma",
"author": "Carter Grimmeisen",
"module": "dist/zod-prisma.esm.js",
"resolutions": {
"eslint": "^7.17.0"
},
"devDependencies": {
"@types/fs-extra": "^9.0.11",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.17.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-prettier": "^4.0.0",
"execa": "^5.1.0",
"fast-glob": "^3.2.5",
"fs-extra": "^10.0.0",
"husky": "^7.0.4",
"jest-mock-extended": "^2.0.4",
"prettier": "^2.3.0",
"prisma": "^3.3.0",
"tsdx": "^0.14.1",
"tslib": "^2.2.0",
"typescript": "^4.4.4",
"zod": "^3.11.6"
},
"dependencies": {
"@prisma/generator-helper": "^3.3.0",
"ts-morph": "^12.1.0"
}
}

@@ -0,1 +1,2 @@

import path from 'path'
import { generatorHandler } from '@prisma/generator-helper'

@@ -28,2 +29,6 @@ import { Project, StructureKind, VariableDeclarationKind } from 'ts-morph'

const prismaClient = options.otherGenerators.find(
(each) => each.provider.value === 'prisma-client-js'
)
const { relationModel } = options.generator.config as unknown as Config

@@ -71,3 +76,5 @@

kind: StructureKind.ImportDeclaration,
moduleSpecifier: '@prisma/client',
moduleSpecifier: prismaClient?.output?.value
? path.relative(outputPath, prismaClient.output.value)
: '@prisma/client',
namedImports: [model.name, ...enumFields.map((f) => f.type)],

@@ -164,2 +171,3 @@ })

name: relatedModelName(model.name),
type: `z.ZodSchema<Complete${model.name}>`,
initializer(writer) {

@@ -192,3 +200,3 @@ writer

})
.write(')).schema')
.write('))')
},

@@ -195,0 +203,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet