{"_id":"@anglinb/ts-to-zod","_rev":"2-077eaacd8187103d168cab1f4e211735","name":"@anglinb/ts-to-zod","dist-tags":{"latest":"1.3.2"},"versions":{"1.3.1":{"name":"@anglinb/ts-to-zod","description":"Generate zod schemas from typescript types/interfaces","version":"1.3.1","homepage":"https://github.com/fabien0102/ts-to-zod","bugs":{"url":"https://github.com/fabien0102/ts-to-zod/issues"},"repository":{"type":"git","url":"git+https://github.com/fabien0102/ts-to-zod.git"},"keywords":["zod","typescript","generator","oclif"],"author":{"name":"Fabien Bernard @fabien0102"},"types":"lib/index.d.ts","main":"lib/index.js","bin":{"ts-to-zod":"bin/run"},"scripts":{"build":"tsc -p tsconfig.package.json","prepublishOnly":"yarn test:ci && rimraf lib && yarn build","format":"eslint **/*.{js,jsx,ts,tsx} --fix && prettier **/*.{js,jsx,ts,tsx,json} --write","test":"jest","test:ci":"jest --ci --coverage && yarn gen:all && tsc --noEmit","gen:all":"./bin/run --all","gen:example":"./bin/run --config example","gen:config":"./bin/run --config config","prepare":"husky install"},"license":"MIT","dependencies":{"@oclif/command":"^1.8.0","@oclif/config":"^1.17.0","@oclif/plugin-help":"^3.2.2","@typescript/vfs":"^1.3.4","async":"^3.2.0","case":"^1.6.3","chokidar":"^3.5.1","fs-extra":"^9.1.0","inquirer":"^8.0.0","lodash":"^4.17.21","lz-string":"^1.4.4","ora":"^5.4.0","prettier":"^2.2.1","rxjs":"^6.6.7","slash":"^3.0.0","threads":"^1.6.3","tslib":"^2.1.0","tsutils":"^3.21.0","typescript":"4.2.3","zod":"^3.1.0"},"devDependencies":{"@types/async":"^3.2.6","@types/fs-extra":"^9.0.9","@types/inquirer":"^7.3.1","@types/jest":"^26.0.20","@types/lodash":"^4.14.168","@types/lz-string":"^1.3.34","@types/node":"^12.7.11","@typescript-eslint/eslint-plugin":"^4.17.0","@typescript-eslint/parser":"^4.17.0","auto-changelog":"^2.2.1","codecov":"^3.8.1","eslint":"^7.22.0","eslint-config-prettier":"^8.1.0","eslint-plugin-prettier":"^3.3.1","husky":"^5.2.0","jest":"^26.6.3","pretty-quick":"^3.1.0","rimraf":"^3.0.2","ts-jest":"^26.5.3","ts-node":"^9.1.1"},"jest":{"preset":"ts-jest","testEnvironment":"node","testMatch":["**/*.test.ts"]},"prettier":{"printWidth":80,"semi":true,"trailingComma":"es5"},"oclif":{"bin":"ts-to-zod"},"gitHead":"5a5583ccedb81cbab1252ceee747d68d4fc22ba7","_id":"@anglinb/ts-to-zod@1.3.1","_nodeVersion":"14.17.3","_npmVersion":"6.14.13","dist":{"integrity":"sha512-fKeqtGnmbUfBY+ppkJ4czRsbNw+7/k7n3LkSQdhABoIdevGr2R8yPS0GG84P3FE3S0bNapX+9cDza/LV6IA+dg==","shasum":"ed6e46e869f518ca964bff45b42f7f664d2131f7","tarball":"https://registry.npmjs.org/@anglinb/ts-to-zod/-/ts-to-zod-1.3.1.tgz","fileCount":41,"unpackedSize":239012,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhAdy3CRA9TVsSAnZWagAAZ7IP/i427SSzi9FQ3ISuXk4b\nHg6kk8SYvVzdhTgPnRhvd0WarOP1tkj/XByRgtXDmPjbpghYFMdbqX4M4EWo\n6nHCCIvrP40v4M9QO1set/+Wz6MInSDLORcciDufFXyGYSiUbZ+h1QpV9rBe\nz/9lrvJcU1piEJ0e/dt6GXcYriswYQ/XrNl9NNBh+Z88vgODmAyk3T78VxLf\nYOut9QZGKcSsq6utBRGAcyhUxPQdUYiP/gxXVTjjGhSaBAe3iNfs8haSDeio\nVW+9Wd9SL0t7c3qEIn0Iwmi7iU7cd/b+YgfeC9Q+9SllMP4WYccB+ZDQQ51Y\nncBStWBFWGG5KhUd9RxpQoS3OFrlR3ykl/QMNMOmKBIbUFv036/guACN3GC+\nUivTCSTZ8Hg405CzwhgJQwYkjlO6pHz81f+1A2ZfeN+7EunmTinPHgdDV+Ip\nVEL+IK03dSGaT2sROfq3g0wDVYUNRk8RPumnhEM0Rkfy92I1HmEEOvXkjHRC\nEz5cE7TBMWZpjmRcQTnd6azGey/unKZWMEuBzcPShv58V4f05mBRRM3JKL1F\nLnLiCgPRo9dh8IurPJ5qrsx2ctAbpTviIZkD/UxO4+A+f8No9zxenrP56knk\nCjYw3zq57QvNujD8kenf/D1OmmVUdt4x8Ot0mikzEsugl5aSAl5TBwCIfO/N\nWRXZ\r\n=xb2V\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAc4REpxALLS/lvVhgwJvLBKf+gr/z+y0TMWTnHydfTlAiEA3n1bdW70AZ8GxgAp+lJS85VTXnVJHGRxME9CJaPHj7A="}]},"_npmUser":{"name":"anglinb","email":"brianranglin@gmail.com"},"directories":{},"maintainers":[{"name":"anglinb","email":"brianranglin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ts-to-zod_1.3.1_1627511991003_0.37899922095724525"},"_hasShrinkwrap":false},"1.3.2":{"name":"@anglinb/ts-to-zod","description":"Generate zod schemas from typescript types/interfaces","version":"1.3.2","homepage":"https://github.com/fabien0102/ts-to-zod","bugs":{"url":"https://github.com/fabien0102/ts-to-zod/issues"},"repository":{"type":"git","url":"git+https://github.com/fabien0102/ts-to-zod.git"},"keywords":["zod","typescript","generator","oclif"],"author":{"name":"Fabien Bernard @fabien0102"},"types":"lib/index.d.ts","main":"lib/index.js","bin":{"ts-to-zod":"bin/run"},"scripts":{"build":"tsc -p tsconfig.package.json","prepublishOnly":"yarn test:ci && rimraf lib && yarn build","format":"eslint **/*.{js,jsx,ts,tsx} --fix && prettier **/*.{js,jsx,ts,tsx,json} --write","test":"jest","test:ci":"jest --ci --coverage && yarn gen:all && tsc --noEmit","gen:all":"./bin/run --all","gen:example":"./bin/run --config example","gen:config":"./bin/run --config config","prepare":"husky install"},"license":"MIT","dependencies":{"@oclif/command":"^1.8.0","@oclif/config":"^1.17.0","@oclif/plugin-help":"^3.2.2","@typescript/vfs":"^1.3.4","async":"^3.2.0","case":"^1.6.3","chokidar":"^3.5.1","fs-extra":"^9.1.0","inquirer":"^8.0.0","lodash":"^4.17.21","lz-string":"^1.4.4","ora":"^5.4.0","prettier":"^2.2.1","rxjs":"^6.6.7","slash":"^3.0.0","threads":"^1.6.3","tslib":"^2.1.0","tsutils":"^3.21.0","typescript":"4.2.3","zod":"^3.1.0"},"devDependencies":{"@types/async":"^3.2.6","@types/fs-extra":"^9.0.9","@types/inquirer":"^7.3.1","@types/jest":"^26.0.20","@types/lodash":"^4.14.168","@types/lz-string":"^1.3.34","@types/node":"^12.7.11","@typescript-eslint/eslint-plugin":"^4.17.0","@typescript-eslint/parser":"^4.17.0","auto-changelog":"^2.2.1","codecov":"^3.8.1","eslint":"^7.22.0","eslint-config-prettier":"^8.1.0","eslint-plugin-prettier":"^3.3.1","husky":"^5.2.0","jest":"^26.6.3","pretty-quick":"^3.1.0","rimraf":"^3.0.2","ts-jest":"^26.5.3","ts-node":"^9.1.1"},"jest":{"preset":"ts-jest","testEnvironment":"node","testMatch":["**/*.test.ts"]},"prettier":{"printWidth":80,"semi":true,"trailingComma":"es5"},"oclif":{"bin":"ts-to-zod"},"gitHead":"490b4c40ffdc74322475c0e71925e1007dbe437e","_id":"@anglinb/ts-to-zod@1.3.2","_nodeVersion":"14.17.3","_npmVersion":"6.14.13","dist":{"integrity":"sha512-JZxA+nrSRzbI64V+8vHezT7CLzwmqYxvPy+XWSvgRx9imEXKsel8poF+/JLshNCDsVKv1g+G+SYNkfGNfbIq4A==","shasum":"f3667ca670490e89e6f1788a87014e56b736709f","tarball":"https://registry.npmjs.org/@anglinb/ts-to-zod/-/ts-to-zod-1.3.2.tgz","fileCount":41,"unpackedSize":239370,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhAfKNCRA9TVsSAnZWagAAs0AQAIl8tHU5cVMuS92Jygof\nymVbEo+1YI0tWWm4XUTSmbUhexQtm6JVxn4CBrTGKxOVAglE6N3pBfr646ZR\n16fepDBJ1XuvZ2U9y9/nfH2uvAHcryRu2EOJYqoh8b35hZtzgwvbtc7YL3Ox\niMwnyrxvi1Yi5F654gdXs0KYNL54hze33DCed7jay81EnrAkmvnw3kQ3fdtO\noG2BGlfhKGG8SVjzCbEeNkfT4YBImodonVGDKnOVjGGOicJZ/zEIX37bH+ex\n17zfUAPMyrV0giboU8HnkwbkJA4NfHoV+br5oywpMyMJwXJYIYRwQrEZ2Iwn\nvc1xF54OQLcPIZNPj4j+5+Pu942C/hLtF5RFI+9DG4uvTNUyIuJlJlFjkZ9j\n+b7X7oxb7HPau4MoKqgzfEUdd8331Q/DblrYZ1IeDCttzvqVdCN22/tvuvPC\nA5Mi7my4FlMmcD8ujPWwWyM/MlrI/ba5OMVVynA4ktd2HtFbypJv9K/RSIFe\nYovgR+mON2oBBc80IbRcq27V7w2ejB4I6MJHXfoLPbcVC9t7e5Q6oOwReCfC\nYO5olWv1i7BX9xxlnuznatzB1B1QQlgANtdev+9TmlmJQUL3DxkJDHsJeNHo\nnp8lOr5UuC6P4n9+Yltb0PWfWG7RhKr5OJZ5XM3/xWXeq6LJV2tlJn+gtGNw\nnF1C\r\n=jBmw\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCglIBer3L+mAqmg1TNnGoVxuBdJooYqKOpvltwBBjS+AIgd/yldAqUaPdHFl8LtP4XwBZ+yFkfQq9/WFxu1e0HA1A="}]},"_npmUser":{"name":"anglinb","email":"brianranglin@gmail.com"},"directories":{},"maintainers":[{"name":"anglinb","email":"brianranglin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ts-to-zod_1.3.2_1627517581680_0.16118506631370622"},"_hasShrinkwrap":false}},"time":{"created":"2021-07-28T22:39:50.925Z","1.3.1":"2021-07-28T22:39:51.156Z","modified":"2022-04-04T14:06:12.715Z","1.3.2":"2021-07-29T00:13:01.879Z"},"maintainers":[{"name":"anglinb","email":"brianranglin@gmail.com"}],"description":"Generate zod schemas from typescript types/interfaces","homepage":"https://github.com/fabien0102/ts-to-zod","keywords":["zod","typescript","generator","oclif"],"repository":{"type":"git","url":"git+https://github.com/fabien0102/ts-to-zod.git"},"author":{"name":"Fabien Bernard @fabien0102"},"bugs":{"url":"https://github.com/fabien0102/ts-to-zod/issues"},"license":"MIT","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\nNote: The generated zod schemas have `zod@next` as dependency.\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 recommanded, 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().min(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\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"}