{"_id":"@cakesoft/ts-to-zod","_rev":"2-f8424d8b56837c0bf25ff3d197f7ab57","name":"@cakesoft/ts-to-zod","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@cakesoft/ts-to-zod","version":"1.0.0","license":"MIT","_id":"@cakesoft/ts-to-zod@1.0.0","maintainers":[{"name":"cakesoft","email":"mail@cakesofttech.com"}],"bin":{"ts-to-zod":"bin/run"},"dist":{"shasum":"1bf192f040dc3d4f3a4382f53a9f8e0236f082f4","tarball":"https://registry.npmjs.org/@cakesoft/ts-to-zod/-/ts-to-zod-1.0.0.tgz","fileCount":66,"integrity":"sha512-XIuK7dLpNeMK8KXd0xHjQJkgQ3up3Duv6fj/bBtOaFBx41/rcECQpbrLZAfk2jaqmHn7v5xdZKTvP+Kof9Twag==","signatures":[{"sig":"MEYCIQDZbRtVlsJZNFWOS3btMXwaqrz+q3aZueWe5jSsD2uOFQIhANl1OKfC3sjVRZMWaxFcHYa4T82q1TrJOdPPFDe4FKRF","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":327024,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkF2KNACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqNxA/+NOYURp5ozHzvIPdDxGupwn2WxO6trycwUhOKptGW90DB3y6T\r\nPeKozvbiG2QGmpiPanQDZ2EJ2gO+/OMdOmGEWYUjvEZcjmlL4cYqkV4gTNqF\r\n43xEAJ574HFOJApr4jwfDcndqS2L6qn59w7PawR9SIimf8SL37XBwgoSpr9J\r\nQNYEi0ktJYZ2TMDRBduQniQVypkU6NFqHP+ElcDM1jY9Va04fwnEptKd5Xxm\r\nxl5JeiudH8644fKva5gtUvzQt2pWoQVRHm1RsiGfsUCdLFfrt60e5rBIHmsN\r\nApCbfFoIJT6m10PF9pj3IYiK0GNHrS4MXo7rhLou5Qcgj26g0Zal+cpb+Bzr\r\nxGNgYt3iuz7KoiO9tITgrRITJ72gWRWmei/E68zfVNU4RoVPl7x59l3GGleq\r\nZeDXRbC15jl2z/lmrDQMxA/Z9g/nUzNs/tV1015AYVZGu5dZCscaSSOpW4vy\r\nvZFGJvYOfOquW1nzQ3xxQSsW00LgfS5chpeWqrsDZ9Uh4PrAcv8InEpQnh/b\r\nhD0dy57tFjYbJu95xr/z2JBRzF8X/+vglUH5eJAubj5ltDLudexC85RReOvD\r\nfoGKrH+cusbtA8T6KHfNvUrAL2MAnNIqZoh0eqdM1+CrRfGgFk8a6fu+aqwx\r\nTXicD2tFz5iPg8j6P6I1BGM7D1BGLSAqcGs=\r\n=KRPD\r\n-----END PGP SIGNATURE-----\r\n"},"jest":{"testMatch":["**/*.test.ts"],"testEnvironment":"node"},"main":"lib/index.js","oclif":{"bin":"ts-to-zod"},"types":"lib/index.d.ts","gitHead":"ac911f3c3fa65cb2770c8feb7f1b729063d5c82e","scripts":{"test":"jest","build":"tsc -p tsconfig.package.json","format":"eslint **/*.{js,jsx,ts,tsx} --fix && prettier **/*.{js,jsx,ts,tsx,json} --write","gen:all":"./bin/run --all","prepare":"husky install","test:ci":"jest --ci --coverage && yarn gen:all && tsc --noEmit","gen:config":"./bin/run --config config","gen:example":"./bin/run --config example","prepublishOnly":"yarn test:ci && rimraf lib && yarn build"},"_npmUser":{"name":"cakesoft","email":"mail@cakesofttech.com"},"prettier":{"semi":true,"printWidth":80,"trailingComma":"es5"},"_npmVersion":"7.24.0","description":"Generate zod schemas from typescript types/interfaces","directories":{},"_nodeVersion":"16.10.0","dependencies":{"ora":"^5.4.0","zod":"^3.11.6","case":"^1.6.3","rxjs":"^7.4.0","async":"^3.2.0","slash":"^3.0.0","tslib":"^2.3.1","lodash":"^4.17.21","threads":"^1.7.0","tsutils":"^3.21.0","chokidar":"^3.5.1","fs-extra":"^9.1.0","inquirer":"^8.2.0","prettier":"2.2.1","lz-string":"^1.4.4","typescript":"^4.5.2","@oclif/config":"^1.17.1","@oclif/command":"^1.8.6","@typescript/vfs":"^1.3.5","@oclif/plugin-help":"^3.2.7"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^27.5.1","husky":"^5.2.0","eslint":"^7.22.0","rimraf":"^3.0.2","codecov":"^3.8.1","ts-node":"^10.9.1","babel-jest":"^27.5.1","@babel/core":"^7.17.5","@types/jest":"^26.0.20","@types/node":"^12.7.11","@types/async":"^3.2.6","pretty-quick":"^3.1.0","@types/lodash":"^4.14.168","auto-changelog":"^2.2.1","@types/fs-extra":"^9.0.9","@types/inquirer":"^8.1.3","@types/lz-string":"^1.3.34","@babel/preset-env":"^7.16.11","eslint-config-prettier":"^8.1.0","eslint-plugin-prettier":"^3.3.1","@babel/preset-typescript":"^7.16.7","@typescript-eslint/parser":"^4.17.0","@typescript-eslint/eslint-plugin":"^4.17.0"},"_npmOperationalInternal":{"tmp":"tmp/ts-to-zod_1.0.0_1679254157165_0.062148736998286935","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"@cakesoft/ts-to-zod","version":"1.0.1","license":"MIT","_id":"@cakesoft/ts-to-zod@1.0.1","maintainers":[{"name":"cakesoft","email":"mail@cakesofttech.com"}],"bin":{"ts-to-zod":"bin/run"},"dist":{"shasum":"ab0f10fafbcc282fc843f18b480028860ebf012d","tarball":"https://registry.npmjs.org/@cakesoft/ts-to-zod/-/ts-to-zod-1.0.1.tgz","fileCount":66,"integrity":"sha512-JjUfHas0kVx2Vn9ZnRc15TBOOAzkNNu4R8X6iPt3mTOVkWaysxQK8Pw+jeDMyW0VNlX5cisC7YV0pwmm0mDcKw==","signatures":[{"sig":"MEQCICel6Rg/XuEaa85UKFRIN81nwKoBP2UDJyTk0Sub+cZEAiAhS18JvzZmMZNTMbop9MJNnQ9FtByVMOzEwWYzYnFBjg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":327025,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkF2MeACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrvQQ//TvtRq+GezGZanQx94vwgGjtzGK+jhVPnxFT3azwafbgjRQrP\r\nKgaWWEUACImrBPX9V9FTcFnFC/hqsoJc/Qz7UUUgvXTmcMcmYVy/+uhNz6Gz\r\nS9FPVFb6/Qeouv9BP87s7WgVH5X9d7ow0iMT5yFv//ggsPCrYmm1Ae1ytxOY\r\nMkI80HYqsROKi7jJZRS2ePj+RikBdcB7AT9wMOHLjeXyasmbQh5J2EMLhG9U\r\nwnVsgZ6mFGArxvf+h3HJmFsw4+Va6hSFBZzmEI7r02Q15Ffp9rMB6ST0a6NI\r\nMgPyMPlm8+P2BphV12rDhb+KQ/em/yZCHRh9UqqtAhzYoGvRbJPibl/nGuWL\r\nInCUjnD1a9Mv8m5UdrOQl/f2LaJdVyX4NEUwXhla614tLH7lfwq+st+RylvP\r\nNr1Uz0iW7Y5kZclZeIGmDxRdeGfPz8BrbU7ec9QClhC1ZcENHXJBTbHzoni4\r\neD1NvWmq3VdMQfYH3FCJJHtfpDkbl4l+MQMzVKtyHuDp3tvderIFYCT+uwiy\r\nE67YvCYuK4HHFo4QrW7K5K6vpGL+BS2sR36rhLXNAHTDstVkMUNF2v/8ACc4\r\nzr9JsQxjD2M7S7IKKuoKZOgRCR02POjUpKCXkGOK27Ys34iuvuHxhIrqNVnw\r\nmfcABS8SPbPHVMa8jmMg8tmjf92+EsBCcuM=\r\n=oyTm\r\n-----END PGP SIGNATURE-----\r\n"},"jest":{"testMatch":["**/*.test.ts"],"testEnvironment":"node"},"main":"lib/index.js","oclif":{"bin":"ts-to-zod"},"types":"lib/index.d.ts","gitHead":"2d1a8bbbcfaae8a39ccc782557bee272649ff20c","scripts":{"test":"jest","build":"tsc -p tsconfig.package.json","format":"eslint **/*.{js,jsx,ts,tsx} --fix && prettier **/*.{js,jsx,ts,tsx,json} --write","gen:all":"./bin/run --all","prepare":"husky install","test:ci":"jest --ci --coverage && yarn gen:all && tsc --noEmit","gen:config":"./bin/run --config config","gen:example":"./bin/run --config example","prepublishOnly":"yarn test:ci && rimraf lib && yarn build"},"_npmUser":{"name":"cakesoft","email":"mail@cakesofttech.com"},"prettier":{"semi":true,"printWidth":80,"trailingComma":"es5"},"_npmVersion":"7.24.0","description":"Generate zod schemas from typescript types/interfaces","directories":{},"_nodeVersion":"16.10.0","dependencies":{"ora":"^5.4.0","zod":"^3.11.6","case":"^1.6.3","rxjs":"^7.4.0","async":"^3.2.0","slash":"^3.0.0","tslib":"^2.3.1","lodash":"^4.17.21","threads":"^1.7.0","tsutils":"^3.21.0","chokidar":"^3.5.1","fs-extra":"^9.1.0","inquirer":"^8.2.0","prettier":"2.2.1","lz-string":"^1.4.4","typescript":"^4.5.2","@oclif/config":"^1.17.1","@oclif/command":"^1.8.6","@typescript/vfs":"^1.3.5","@oclif/plugin-help":"^3.2.7"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^27.5.1","husky":"^5.2.0","eslint":"^7.22.0","rimraf":"^3.0.2","codecov":"^3.8.1","ts-node":"^10.9.1","babel-jest":"^27.5.1","@babel/core":"^7.17.5","@types/jest":"^26.0.20","@types/node":"^12.7.11","@types/async":"^3.2.6","pretty-quick":"^3.1.0","@types/lodash":"^4.14.168","auto-changelog":"^2.2.1","@types/fs-extra":"^9.0.9","@types/inquirer":"^8.1.3","@types/lz-string":"^1.3.34","@babel/preset-env":"^7.16.11","eslint-config-prettier":"^8.1.0","eslint-plugin-prettier":"^3.3.1","@babel/preset-typescript":"^7.16.7","@typescript-eslint/parser":"^4.17.0","@typescript-eslint/eslint-plugin":"^4.17.0"},"_npmOperationalInternal":{"tmp":"tmp/ts-to-zod_1.0.1_1679254301824_0.6886832721582132","host":"s3://npm-registry-packages"}}},"time":{"created":"2023-03-19T19:29:17.096Z","modified":"2024-12-17T20:47:40.161Z","1.0.0":"2023-03-19T19:29:17.333Z","1.0.1":"2023-03-19T19:31:42.030Z"},"license":"MIT","description":"Generate zod schemas from typescript types/interfaces","maintainers":[{"email":"mail@cakesofttech.com","name":"cakesoft-arpit"}],"readme":"<div align=\"center\">\n  <img src=\"ts-to-zod-logo.svg\" width=\"200px\" align=\"center\" />\n  <h1 align=\"center\">ts-to-zod</h1>\n</div>\n\nGenerate [Zod](https://github.com/colinhacks/zod) schemas (v3) from Typescript types/interfaces.\n\n[![Version](https://img.shields.io/npm/v/ts-to-zod.svg)](https://npmjs.org/package/ts-to-zod)\n[![Github CI](https://github.com/fabien0102/ts-to-zod/actions/workflows/tests.yaml/badge.svg)](https://github.com/fabien0102/ts-to-zod/actions/workflows/tests.yaml)\n[![codecov](https://codecov.io/gh/fabien0102/ts-to-zod/branch/main/graph/badge.svg?token=W5M8UIJ59C)](https://codecov.io/gh/fabien0102/ts-to-zod)\n[![License](https://img.shields.io/npm/l/ts-to-zod.svg)](https://github.com/fabien0102/ts-to-zod/blob/main/LICENSE)\n[![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)\n\n## Usage\n\n```sh\n$ yarn add --dev ts-to-zod\n$ yarn ts-to-zod src/iDontTrustThisApi.ts src/nowIcanValidateEverything.ts\n```\n\nThat's it, go to `src/nowIcanValidateEverything.ts` file, you should have all the exported `interface` and `type` as Zod schemas with the following name pattern: `${originalType}Schema`.\n\n## Embedded validation\n\nTo make sure the generated zod schemas are 100% compatible with your original types, this tool is internally comparing `z.infer<generatedSchema>` and your original type. If you are running on those validation, please open an issue 😀\n\nNotes:\n\n- Only exported types/interface are tested (so you can have some private types/interface and just exports the composed type)\n- Even if this is not recommended, you can skip this validation step with `--skipValidation`. (At your own risk!)\n\n## Validators\n\nThis tool supports some JSDoc tags inspired from openapi to generate zod validator.\n\nList of supported keywords:\n\n| JSDoc keyword                      | JSDoc Example     | Generated Zod validator      |\n| ---------------------------------- | ----------------- | ---------------------------- |\n| `@minimum {number}`                | `@minimum 42`     | `z.number().min(42)`         |\n| `@maximum {number}`                | `@maximum 42`     | `z.number().max(42)`         |\n| `@minLength {number}`              | `@minLength 42`   | `z.string().min(42)`         |\n| `@maxLength {number}`              | `@maxLength 42`   | `z.string().max(42)`         |\n| `@format {\"email\"\\|\"uuid\"\\|\"url\"}` | `@format email`   | `z.string().email()`         |\n| `@pattern {regex}`                 | `@pattern ^hello` | `z.string().regex(/^hello/)` |\n\nThose JSDoc tags can also be combined:\n\n```ts\n// source.ts\nexport interface HeroContact {\n  /**\n   * The email of the hero.\n   *\n   * @format email\n   */\n  email: string;\n\n  /**\n   * The name of the hero.\n   *\n   * @minLength 2\n   * @maxLength 50\n   */\n  name: string;\n\n  /**\n   * The phone number of the hero.\n   *\n   * @pattern ^([+]?d{1,2}[-s]?|)d{3}[-s]?d{3}[-s]?d{4}$\n   */\n  phoneNumber: string;\n\n  /**\n   * Does the hero has super power?\n   *\n   * @default true\n   */\n  hasSuperPower?: boolean;\n\n  /**\n   * The age of the hero\n   *\n   * @minimum 0\n   * @maximum 500\n   */\n  age: number;\n}\n\n// output.ts\nexport const heroContactSchema = z.object({\n  /**\n   * The email of the hero.\n   *\n   * @format email\n   */\n  email: z.string().email(),\n\n  /**\n   * The name of the hero.\n   *\n   * @minLength 2\n   * @maxLength 50\n   */\n  name: z.string().min(2).max(50),\n\n  /**\n   * The phone number of the hero.\n   *\n   * @pattern ^([+]?d{1,2}[-s]?|)d{3}[-s]?d{3}[-s]?d{4}$\n   */\n  phoneNumber: z.string().regex(/^([+]?d{1,2}[-s]?|)d{3}[-s]?d{3}[-s]?d{4}$/),\n\n  /**\n   * Does the hero has super power?\n   *\n   * @default true\n   */\n  hasSuperPower: z.boolean().default(true),\n\n  /**\n   * The age of the hero\n   *\n   * @minimum 0\n   * @maximum 500\n   */\n  age: z.number().min(0).max(500),\n});\n```\n\n## Advanced configuration\n\nIf you want to customized the schema name or restrict the exported schemas, you can do this by adding a `ts-to-zod.config.js` at the root of your project.\n\nJust run `yarn ts-to-zod --init` and you will have a ready to use configuration file (with a bit of typesafety).\n\nYou have two ways to restrict the scope of ts-to-zod:\n\n- `nameFilter` will filter by interface/type name\n- `jsDocTagFilter` will filter on jsDocTag\n\nExample:\n\n```ts\n// ts-to-zod.config.js\n/**\n * ts-to-zod configuration.\n *\n * @type {import(\"./src/config\").TsToZodConfig}\n */\nmodule.exports = [\n  {\n    name: \"example\",\n    input: \"example/heros.ts\",\n    output: \"example/heros.zod.ts\",\n    jsDocTagFilter: (tags) => tags.map(tag => tag.name).includes(\"toExtract\")) // <= rule here\n  },\n];\n\n// example/heros.ts\n/**\n * Will not be part of `example/heros.zod.ts`\n */\nexport interface Enemy {\n  name: string;\n  powers: string[];\n  inPrison: boolean;\n}\n\n/**\n * Will be part of `example/heros.zod.ts`\n * @toExtract\n */\nexport interface Superman {\n  name: \"superman\" | \"clark kent\" | \"kal-l\";\n  enemies: Record<string, Enemy>;\n  age: number;\n  underKryptonite?: boolean;\n}\n```\n\n/!\\ Please note: if your exported interface/type have a reference to a non-exported interface/type, ts-to-zod will not be able to generate anything (a circular dependency will be report due to the missing reference).\n\n## Limitation\n\nSince we are generating Zod schemas, we are limited by what Zod actually supports:\n\n- No type generics\n- No complex circular dependencies (you will be warn if you have some in your types)\n- No `Record<number, …>`\n- …\n\nTo resume, you can use all the primitive types and some the following typescript helpers:\n\n- `Record<string, …>`\n- `Pick<>`\n- `Omit<>`\n- `Partial<>`\n- `Required<>`\n- `Array<>`\n- `Promise<>`\n\nThis utils is design to work with one file only, and will reference types from the same file:\n\n```ts\n// source.ts\nexport type Id = string;\nexport interface Hero {\n  id: Id;\n  name: string;\n}\n\n// output.ts\nexport const idSchema = z.string();\nexport const heroSchema = z.object({\n  id: idSchema,\n  name: z.string(),\n});\n```\n\n## Programmatic API\n\nYou need more than one file? Want even more power? No problem, just use the tool as a library.\n\nHigh-level function:\n\n- `generate` take a `sourceText` and generate two file getters\n\nPlease have a look to `src/core/generate.test.ts` for more examples.\n\nLow-level functions:\n\n- `generateZodSchema` help you to generate `export const ${varName} = ${zodImportValue}.object(…)`\n- `generateZodInferredType` help you to generate `export type ${aliasName} = ${zodImportValue}.infer<typeof ${zodConstName}>`\n- `generateIntegrationTests` help you to generate a file comparing the original types & zod types\n\nTo learn more about thoses functions or their usages, `src/core/generate.ts` is a good starting point.\n\n## Local development\n\n```sh\n$ git clone\n$ cd ts-to-zod\n$ yarn\n$ ./bin/run\nUSAGE\n  $ ts-to-zod [input] [output]\n  ...\n```\n\nYou also have plenty of unit tests to play safely:\n\n```sh\n$ yarn test --watch\n```\n\nAnd a playground inside `example`, buildable with the following command:\n\n```sh\n$ yarn gen:example\n```\n\nLast note, if you are updating `src/config.ts`, you need to run `yarn gen:config` to have generate the schemas of the config (`src/config.zod.ts`) (Yes, we are using the tool to build itself #inception)\n\nHave fun!\n","readmeFilename":"README.md"}