@zimic/http 0.1.2 → 0.2.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/{chunk-KDDZRZK6.js → chunk-2P56ILG3.js} +8 -26
- package/dist/chunk-2P56ILG3.js.map +1 -0
- package/dist/{chunk-C5GWXTO5.mjs → chunk-5GJI2ESI.mjs} +7 -25
- package/dist/chunk-5GJI2ESI.mjs.map +1 -0
- package/dist/cli.js +23 -30
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +19 -26
- package/dist/cli.mjs.map +1 -1
- package/dist/typegen.d.ts +3 -25
- package/dist/typegen.js +3 -3
- package/dist/typegen.mjs +1 -1
- package/package.json +5 -5
- package/src/cli/cli.ts +25 -9
- package/src/typegen/index.ts +1 -10
- package/src/typegen/openapi/generate.ts +2 -2
- package/src/typegen/openapi/transform/filters.ts +2 -2
- package/src/typegen/openapi/transform/methods.ts +2 -2
- package/src/utils/console.ts +2 -2
- package/dist/chunk-C5GWXTO5.mjs.map +0 -1
- package/dist/chunk-KDDZRZK6.js.map +0 -1
- package/src/cli/typegen/openapi.ts +0 -24
- package/src/typegen/namespace/TypegenNamespace.ts +0 -18
package/dist/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../src/utils/time.ts","../src/cli/typegen/openapi.ts","../src/cli/cli.ts","../src/cli/index.ts"],"names":["yargs"],"mappings":";;;;;;;AAcE,IAAW,OAAA,GAAA,OAAA;;;ACZb,eAAsB,iBAA6B,QAA6C,EAAA;AAC9F,EAAM,MAAA,uBAAA,GAA0B,YAAY,GAAI,EAAA;AAEhD,EAAM,MAAA,MAAA,GAAS,MAAM,QAAS,EAAA;AAE9B,EAAM,MAAA,qBAAA,GAAwB,YAAY,GAAI,EAAA;AAC9C,EAAA,MAAM,4BAA4B,qBAAwB,GAAA,uBAAA;AAE1D,EAAO,OAAA;AAAA,IACL,S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,WACE,EAAA,ulBAAA;AAAA,QAOF,KAAO,EAAA;AAAA,OACR,CACA,CAAA,MAAA,CAAO,aAAe,EAAA;AAAA,QACrB,IAAM,EAAA,QAAA;AAAA,QACN,WACE,EAAA,uPAAA;AAAA,QAGF,KAAO,EAAA;AAAA,OACR,CAAA;AAAA,MACL,OAAO,YAAiB,KAAA;AACtB,QAAA,MAAM,eAAyB,CAAA;AAAA,UAC7B,OAAO,YAAa,CAAA,KAAA;AAAA,UACpB,QAAQ,YAAa,CAAA,MAAA;AAAA,UACrB,aAAa,YAAa,CAAA,WAAA;AAAA,UAC1B,iBAAiB,YAAa,CAAA,QAAA;AAAA,UAC9B,OAAO,YAAa,CAAA,KAAA;AAAA,UACpB,SAAS,YAAa,CAAA,MAAA;AAAA,UACtB,YAAY,YAAa,CAAA;AAAA,SAC1B,CAAA;AAAA;AACH;AACF,IAGD,KAAM,EAAA;AACX;AAlFe,MAAA,CAAA,MAAA,EAAA,QAAA,CAAA;AAoFf,IAAO,WAAQ,GAAA,MAAA;;;ACxFf,KAAK,WAAO,EAAA","file":"cli.mjs","sourcesContent":["{\n \"name\": \"@zimic/http\",\n \"description\": \"TypeScript-first HTTP utilities\",\n \"keywords\": [\n \"zimic\",\n \"typescript\",\n \"types\",\n \"typegen\",\n \"validation\",\n \"inference\",\n \"http\",\n \"api\",\n \"static\"\n ],\n \"version\": \"0.1.2\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/zimicjs/zimic.git\",\n \"directory\": \"packages/zimic-http\"\n },\n \"author\": {\n \"name\": \"Diego Aquino\",\n \"url\": \"https://github.com/diego-aquino\"\n },\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\",\n \"provenance\": true\n },\n \"engines\": {\n \"node\": \">=18.0.0\"\n },\n \"license\": \"MIT\",\n \"files\": [\n \"package.json\",\n \"README.md\",\n \"LICENSE.md\",\n \"src\",\n \"!src/**/tests\",\n \"!src/**/__tests__\",\n \"!src/**/*.test.ts\",\n \"dist\",\n \"index.d.ts\",\n \"typegen.d.ts\"\n ],\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"index.d.ts\",\n \"bin\": {\n \"zimic-http\": \"./dist/cli.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./index.d.ts\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\",\n \"default\": \"./dist/index.js\"\n },\n \"./typegen\": {\n \"types\": \"./typegen.d.ts\",\n \"import\": \"./dist/typegen.mjs\",\n \"require\": \"./dist/typegen.js\",\n \"default\": \"./dist/typegen.js\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"scripts\": {\n \"dev\": \"tsup --watch\",\n \"cli\": \"node ./dist/cli.js\",\n \"build\": \"tsup\",\n \"lint\": \"eslint --cache --no-error-on-unmatched-pattern --no-warn-ignored --fix\",\n \"lint:turbo\": \"pnpm lint . --max-warnings 0\",\n \"style\": \"prettier --log-level warn --ignore-unknown --no-error-on-unmatched-pattern --cache\",\n \"style:check\": \"pnpm style --check\",\n \"style:format\": \"pnpm style --write\",\n \"test\": \"dotenv -v NODE_ENV=test -- vitest\",\n \"test:turbo\": \"dotenv -v CI=true -- pnpm run test run --coverage\",\n \"types:check\": \"tsc --noEmit\",\n \"typegen:fixtures\": \"tsx ./scripts/typegen/generateFixtureTypes.ts\",\n \"deps:init\": \"playwright install chromium\"\n },\n \"dependencies\": {\n \"chalk\": \"4.1.2\",\n \"openapi-typescript\": \"7.6.1\",\n \"yargs\": \"17.7.2\"\n },\n \"devDependencies\": {\n \"@types/js-yaml\": \"^4.0.9\",\n \"@types/node\": \"^22.13.10\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.0.8\",\n \"@vitest/coverage-istanbul\": \"^3.0.8\",\n \"@zimic/eslint-config-node\": \"workspace:*\",\n \"@zimic/interceptor\": \"workspace:*\",\n \"@zimic/lint-staged-config\": \"workspace:*\",\n \"@zimic/tsconfig\": \"workspace:*\",\n \"@zimic/utils\": \"workspace:*\",\n \"dotenv-cli\": \"^8.0.0\",\n \"eslint\": \"^9.22.0\",\n \"execa\": \"9.5.2\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.51.0\",\n \"prettier\": \"^3.5.3\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.19.3\",\n \"typescript\": \"^5.8.2\",\n \"vitest\": \"^3.0.8\"\n },\n \"peerDependencies\": {\n \"typescript\": \">=4.8.0\"\n }\n}\n","import { PossiblePromise } from '@zimic/utils/types';\n\nexport async function usingElapsedTime<ReturnType>(callback: () => PossiblePromise<ReturnType>) {\n const startTimeInMilliseconds = performance.now();\n\n const result = await callback();\n\n const endTimeInMilliseconds = performance.now();\n const elapsedTimeInMilliseconds = endTimeInMilliseconds - startTimeInMilliseconds;\n\n return {\n startTime: startTimeInMilliseconds,\n elapsedTime: elapsedTimeInMilliseconds,\n endTime: endTimeInMilliseconds,\n result,\n };\n}\n\nexport function formatElapsedTime(elapsedTimeInMilliseconds: number) {\n if (elapsedTimeInMilliseconds < 1000) {\n return `${elapsedTimeInMilliseconds.toFixed(0)}ms`;\n } else {\n return `${(elapsedTimeInMilliseconds / 1000).toFixed(2)}s`;\n }\n}\n","import chalk from 'chalk';\n\nimport { OpenAPITypegenOptions, typegen } from '@/typegen';\nimport { logWithPrefix } from '@/utils/console';\nimport { usingElapsedTime, formatElapsedTime } from '@/utils/time';\n\nasync function generateTypesFromOpenAPI(options: OpenAPITypegenOptions) {\n const executionSummary = await usingElapsedTime(async () => {\n await typegen.generateFromOpenAPI(options);\n });\n\n const outputFilePath = options.output;\n\n const successMessage =\n `${chalk.green.bold('✔')} Generated ` +\n `${outputFilePath ? chalk.green(outputFilePath) : `to ${chalk.yellow('stdout')}`} ${chalk.dim(\n `(${formatElapsedTime(executionSummary.elapsedTime)})`,\n )}`;\n\n const hasWrittenToStdout = outputFilePath === undefined;\n logWithPrefix(successMessage, { method: hasWrittenToStdout ? 'warn' : 'log' });\n}\n\nexport default generateTypesFromOpenAPI;\n","import yargs from 'yargs';\nimport { hideBin } from 'yargs/helpers';\n\nimport { version } from '@@/package.json';\n\nimport generateTypesFromOpenAPI from './typegen/openapi';\n\nasync function runCLI() {\n await yargs(hideBin(process.argv))\n .scriptName('zimic-http')\n .version(version)\n .showHelpOnFail(false)\n .strict()\n\n .command('typegen', 'Generate types from schema sources', (yargs) =>\n yargs.demandCommand().command(\n 'openapi <input>',\n 'Generate types from an OpenAPI schema.',\n (yargs) =>\n yargs\n .positional('input', {\n type: 'string',\n description:\n 'The path to a local OpenAPI schema file or an URL to fetch it. ' +\n 'Version 3 is supported as YAML or JSON.',\n demandOption: true,\n })\n .option('output', {\n type: 'string',\n description:\n 'The path to write the generated types to. If not provided, the types will be written to stdout.',\n alias: 'o',\n })\n .option('service-name', {\n type: 'string',\n description: 'The name of the service to use in the generated types.',\n alias: 's',\n demandOption: true,\n })\n .option('comments', {\n type: 'boolean',\n description: 'Whether to include comments in the generated types.',\n alias: 'c',\n default: true,\n })\n .option('prune', {\n type: 'boolean',\n description:\n 'Whether to remove unused operations and components from the generated types. This is useful for ' +\n 'reducing the size of the output file.',\n alias: 'p',\n default: true,\n })\n .option('filter', {\n type: 'string',\n array: true,\n description:\n 'One or more expressions to filter the types to generate. Filters must follow the format ' +\n '`<method> <path>`, where `<method>` is an HTTP method or `*`, and `<path>` is a literal path or a ' +\n 'glob. Filters are case-sensitive regarding paths. For example, `GET /users`, `* /users`, ' +\n '`GET /users/*`, and `GET /users/**/*` are valid filters. Negative filters can be created by ' +\n 'prefixing the expression with `!`. For example, `!GET /users` will exclude paths matching ' +\n '`GET /users`. If more than one positive filter is provided, they will be combined with OR, while ' +\n 'negative filters will be combined with AND.',\n alias: 'f',\n })\n .option('filter-file', {\n type: 'string',\n description:\n 'A path to a file containing filter expressions. One expression is expected per line and the format ' +\n 'is the same as used in a `--filter` option. Comments are prefixed with `#`. A filter file can be ' +\n 'used alongside additional `--filter` expressions.',\n alias: 'F',\n }),\n async (cliArguments) => {\n await generateTypesFromOpenAPI({\n input: cliArguments.input,\n output: cliArguments.output,\n serviceName: cliArguments.serviceName,\n includeComments: cliArguments.comments,\n prune: cliArguments.prune,\n filters: cliArguments.filter,\n filterFile: cliArguments.filterFile,\n });\n },\n ),\n )\n\n .parse();\n}\n\nexport default runCLI;\n","#!/usr/bin/env node\nimport runCLI from './cli';\n\nvoid runCLI();\n"]}
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/utils/time.ts","../src/cli/cli.ts","../src/cli/index.ts"],"names":["yargs"],"mappings":";;;;;;;AAcE,IAAW,OAAA,GAAA,gBAAA;;;ACZb,eAAsB,iBAA6B,QAA6C,EAAA;AAC9F,EAAM,MAAA,uBAAA,GAA0B,YAAY,GAAI,EAAA;AAEhD,EAAM,MAAA,MAAA,GAAS,MAAM,QAAS,EAAA;AAE9B,EAAM,MAAA,qBAAA,GAAwB,YAAY,GAAI,EAAA;AAC9C,EAAA,MAAM,4BAA4B,qBAAwB,GAAA,uBAAA;AAE1D,EAAO,OAAA;AAAA,IACL,SAAW,EAAA,uBAAA;AAAA,IACX,WAAa,EAAA,yBAAA;AAAA,IACb,OAAS,EAAA,qBAAA;AAAA,IACT;AAAA,GACF;AACF;AAdsB,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA;AAgBf,SAAS,kBAAkB,yBAAmC,EAAA;AACnE,EAAA,IAAI,4BAA4B,GAAM,EAAA;AACpC,IAAA,OAAO,CAAG,EAAA,yBAAA,CAA0B,OAAQ,CAAA,CAAC,CAAC,CAAA,EAAA,CAAA;AAAA,GACzC,MAAA;AACL,IAAA,OAAO,CAAI,EAAA,CAAA,yBAAA,GAA4B,GAAM,EAAA,OAAA,CAAQ,CAAC,CAAC,CAAA,CAAA,CAAA;AAAA;AAE3D;AANgB,MAAA,CAAA,iBAAA,EAAA,mBAAA,CAAA;;;ACRhB,eAAe,MAAS,GAAA;AACtB,EAAA,MAAM,MAAM,OAAQ,CAAA,OAAA,CAAQ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\"@zimic/http\",\n \"description\": \"TypeScript-first HTTP utilities\",\n \"keywords\": [\n \"zimic\",\n \"typescript\",\n \"types\",\n \"typegen\",\n \"validation\",\n \"inference\",\n \"http\",\n \"api\",\n \"static\"\n ],\n \"version\": \"0.2.0-canary.1\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/zimicjs/zimic.git\",\n \"directory\": \"packages/zimic-http\"\n },\n \"author\": {\n \"name\": \"Diego Aquino\",\n \"url\": \"https://github.com/diego-aquino\"\n },\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\",\n \"provenance\": true\n },\n \"engines\": {\n \"node\": \">=18.0.0\"\n },\n \"license\": \"MIT\",\n \"files\": [\n \"package.json\",\n \"README.md\",\n \"LICENSE.md\",\n \"src\",\n \"!src/**/tests\",\n \"!src/**/__tests__\",\n \"!src/**/*.test.ts\",\n \"dist\",\n \"index.d.ts\",\n \"typegen.d.ts\"\n ],\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"index.d.ts\",\n \"bin\": {\n \"zimic-http\": \"./dist/cli.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./index.d.ts\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\",\n \"default\": \"./dist/index.js\"\n },\n \"./typegen\": {\n \"types\": \"./typegen.d.ts\",\n \"import\": \"./dist/typegen.mjs\",\n \"require\": \"./dist/typegen.js\",\n \"default\": \"./dist/typegen.js\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"scripts\": {\n \"dev\": \"tsup --watch\",\n \"cli\": \"node ./dist/cli.js\",\n \"build\": \"tsup\",\n \"lint\": \"eslint --cache --no-error-on-unmatched-pattern --no-warn-ignored --fix\",\n \"lint:turbo\": \"pnpm lint . --max-warnings 0\",\n \"style\": \"prettier --log-level warn --ignore-unknown --no-error-on-unmatched-pattern --cache\",\n \"style:check\": \"pnpm style --check\",\n \"style:format\": \"pnpm style --write\",\n \"test\": \"dotenv -v NODE_ENV=test -- vitest\",\n \"test:turbo\": \"dotenv -v CI=true -- pnpm run test run --coverage\",\n \"types:check\": \"tsc --noEmit\",\n \"typegen:fixtures\": \"tsx ./scripts/typegen/generateFixtureTypes.ts\",\n \"deps:init\": \"playwright install chromium\"\n },\n \"dependencies\": {\n \"openapi-typescript\": \"7.6.1\",\n \"picocolors\": \"^1.1.1\",\n \"yargs\": \"17.7.2\"\n },\n \"devDependencies\": {\n \"@types/js-yaml\": \"^4.0.9\",\n \"@types/node\": \"^22.13.10\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.0.8\",\n \"@vitest/coverage-istanbul\": \"^3.0.8\",\n \"@zimic/eslint-config-node\": \"workspace:*\",\n \"@zimic/interceptor\": \"workspace:*\",\n \"@zimic/lint-staged-config\": \"workspace:*\",\n \"@zimic/tsconfig\": \"workspace:*\",\n \"@zimic/utils\": \"workspace:*\",\n \"dotenv-cli\": \"^8.0.0\",\n \"eslint\": \"^9.22.0\",\n \"execa\": \"9.5.2\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.51.0\",\n \"prettier\": \"^3.5.3\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.19.3\",\n \"typescript\": \"^5.8.2\",\n \"vitest\": \"^3.0.8\"\n },\n \"peerDependencies\": {\n \"typescript\": \">=4.8.0\"\n }\n}\n","import { PossiblePromise } from '@zimic/utils/types';\n\nexport async function usingElapsedTime<ReturnType>(callback: () => PossiblePromise<ReturnType>) {\n const startTimeInMilliseconds = performance.now();\n\n const result = await callback();\n\n const endTimeInMilliseconds = performance.now();\n const elapsedTimeInMilliseconds = endTimeInMilliseconds - startTimeInMilliseconds;\n\n return {\n startTime: startTimeInMilliseconds,\n elapsedTime: elapsedTimeInMilliseconds,\n endTime: endTimeInMilliseconds,\n result,\n };\n}\n\nexport function formatElapsedTime(elapsedTimeInMilliseconds: number) {\n if (elapsedTimeInMilliseconds < 1000) {\n return `${elapsedTimeInMilliseconds.toFixed(0)}ms`;\n } else {\n return `${(elapsedTimeInMilliseconds / 1000).toFixed(2)}s`;\n }\n}\n","import color from 'picocolors';\nimport yargs from 'yargs';\nimport { hideBin } from 'yargs/helpers';\n\nimport { version } from '@@/package.json';\n\nimport { generateTypesFromOpenAPI } from '@/typegen';\nimport { logWithPrefix } from '@/utils/console';\nimport { usingElapsedTime, formatElapsedTime } from '@/utils/time';\n\nasync function runCLI() {\n await yargs(hideBin(process.argv))\n .scriptName('zimic-http')\n .version(version)\n .showHelpOnFail(false)\n .strict()\n\n .command('typegen', 'Generate types from schema sources', (yargs) =>\n yargs.demandCommand().command(\n 'openapi <input>',\n 'Generate types from an OpenAPI schema.',\n (yargs) =>\n yargs\n .positional('input', {\n type: 'string',\n description:\n 'The path to a local OpenAPI schema file or an URL to fetch it. ' +\n 'Version 3 is supported as YAML or JSON.',\n demandOption: true,\n })\n .option('output', {\n type: 'string',\n description:\n 'The path to write the generated types to. If not provided, the types will be written to stdout.',\n alias: 'o',\n })\n .option('service-name', {\n type: 'string',\n description: 'The name of the service to use in the generated types.',\n alias: 's',\n demandOption: true,\n })\n .option('comments', {\n type: 'boolean',\n description: 'Whether to include comments in the generated types.',\n alias: 'c',\n default: true,\n })\n .option('prune', {\n type: 'boolean',\n description:\n 'Whether to remove unused operations and components from the generated types. This is useful for ' +\n 'reducing the size of the output file.',\n alias: 'p',\n default: true,\n })\n .option('filter', {\n type: 'string',\n array: true,\n description:\n 'One or more expressions to filter the types to generate. Filters must follow the format ' +\n '`<method> <path>`, where `<method>` is an HTTP method or `*`, and `<path>` is a literal path or a ' +\n 'glob. Filters are case-sensitive regarding paths. For example, `GET /users`, `* /users`, ' +\n '`GET /users/*`, and `GET /users/**/*` are valid filters. Negative filters can be created by ' +\n 'prefixing the expression with `!`. For example, `!GET /users` will exclude paths matching ' +\n '`GET /users`. If more than one positive filter is provided, they will be combined with OR, while ' +\n 'negative filters will be combined with AND.',\n alias: 'f',\n })\n .option('filter-file', {\n type: 'string',\n description:\n 'A path to a file containing filter expressions. One expression is expected per line and the format ' +\n 'is the same as used in a `--filter` option. Comments are prefixed with `#`. A filter file can be ' +\n 'used alongside additional `--filter` expressions.',\n alias: 'F',\n }),\n async (cliArguments) => {\n const executionSummary = await usingElapsedTime(async () => {\n await generateTypesFromOpenAPI({\n input: cliArguments.input,\n output: cliArguments.output,\n serviceName: cliArguments.serviceName,\n includeComments: cliArguments.comments,\n prune: cliArguments.prune,\n filters: cliArguments.filter,\n filterFile: cliArguments.filterFile,\n });\n });\n\n const outputFilePath = cliArguments.output;\n\n const successMessage =\n `${color.green(color.bold('✔'))} Generated ` +\n `${outputFilePath ? color.green(outputFilePath) : `to ${color.yellow('stdout')}`} ${color.dim(\n `(${formatElapsedTime(executionSummary.elapsedTime)})`,\n )}`;\n\n const hasWrittenToStdout = outputFilePath === undefined;\n logWithPrefix(successMessage, { method: hasWrittenToStdout ? 'warn' : 'log' });\n },\n ),\n )\n\n .parse();\n}\n\nexport default runCLI;\n","#!/usr/bin/env node\nimport runCLI from './cli';\n\nvoid runCLI();\n"]}
|
package/dist/typegen.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The options to use when generating types from an OpenAPI schema.
|
|
3
3
|
*
|
|
4
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐typegen#
|
|
4
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐typegen#generatetypesfromopenapioptions `generateTypesFromOpenAPI(options)` API reference}
|
|
5
5
|
*/
|
|
6
6
|
interface OpenAPITypegenOptions {
|
|
7
7
|
/**
|
|
@@ -57,30 +57,8 @@ interface OpenAPITypegenOptions {
|
|
|
57
57
|
* Generates TypeScript types from an OpenAPI schema.
|
|
58
58
|
*
|
|
59
59
|
* @param options The options to use when generating the types.
|
|
60
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐typegen#
|
|
60
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐typegen#generatetypesfromopenapioptions `generateTypesFromOpenAPI(options)` API reference}
|
|
61
61
|
*/
|
|
62
62
|
declare function generateTypesFromOpenAPI({ input: inputFilePathOrURL, output: outputFilePath, serviceName, includeComments, prune, filters: filtersFromArguments, filterFile, }: OpenAPITypegenOptions): Promise<void>;
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
* A namespace of type generation resources.
|
|
66
|
-
*
|
|
67
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐typegen `zimic/typegen` API reference}
|
|
68
|
-
*/
|
|
69
|
-
declare class TypegenNamespace {
|
|
70
|
-
/**
|
|
71
|
-
* Generates TypeScript types from an OpenAPI schema.
|
|
72
|
-
*
|
|
73
|
-
* @param options The options to use when generating the types.
|
|
74
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐typegen#typegengeneratefromopenapioptions `typegen.generateFromOpenAPI(options)` API reference}
|
|
75
|
-
*/
|
|
76
|
-
generateFromOpenAPI: typeof generateTypesFromOpenAPI;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* A namespace of type generation resources.
|
|
81
|
-
*
|
|
82
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐typegen `zimic-http typegen` API reference}
|
|
83
|
-
*/
|
|
84
|
-
declare const typegen: Readonly<TypegenNamespace>;
|
|
85
|
-
|
|
86
|
-
export { type OpenAPITypegenOptions, TypegenNamespace, typegen };
|
|
64
|
+
export { type OpenAPITypegenOptions, generateTypesFromOpenAPI };
|
package/dist/typegen.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunk2P56ILG3_js = require('./chunk-2P56ILG3.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
Object.defineProperty(exports, "
|
|
7
|
+
Object.defineProperty(exports, "generateTypesFromOpenAPI", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunk2P56ILG3_js.generate_default; }
|
|
10
10
|
});
|
|
11
11
|
//# sourceMappingURL=typegen.js.map
|
|
12
12
|
//# sourceMappingURL=typegen.js.map
|
package/dist/typegen.mjs
CHANGED
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"api",
|
|
13
13
|
"static"
|
|
14
14
|
],
|
|
15
|
-
"version": "0.1
|
|
15
|
+
"version": "0.2.0-canary.1",
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
18
|
"url": "https://github.com/zimicjs/zimic.git",
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
"./package.json": "./package.json"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"chalk": "4.1.2",
|
|
69
68
|
"openapi-typescript": "7.6.1",
|
|
69
|
+
"picocolors": "^1.1.1",
|
|
70
70
|
"yargs": "17.7.2"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
@@ -86,10 +86,10 @@
|
|
|
86
86
|
"typescript": "^5.8.2",
|
|
87
87
|
"vitest": "^3.0.8",
|
|
88
88
|
"@zimic/eslint-config-node": "0.0.0",
|
|
89
|
-
"@zimic/utils": "0.0.0",
|
|
90
|
-
"@zimic/interceptor": "0.15.0-canary.3",
|
|
91
89
|
"@zimic/lint-staged-config": "0.0.0",
|
|
92
|
-
"@zimic/tsconfig": "0.0.0"
|
|
90
|
+
"@zimic/tsconfig": "0.0.0",
|
|
91
|
+
"@zimic/utils": "0.0.0",
|
|
92
|
+
"@zimic/interceptor": "0.16.0-canary.9"
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
95
|
"typescript": ">=4.8.0"
|
package/src/cli/cli.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import color from 'picocolors';
|
|
1
2
|
import yargs from 'yargs';
|
|
2
3
|
import { hideBin } from 'yargs/helpers';
|
|
3
4
|
|
|
4
5
|
import { version } from '@@/package.json';
|
|
5
6
|
|
|
6
|
-
import generateTypesFromOpenAPI from '
|
|
7
|
+
import { generateTypesFromOpenAPI } from '@/typegen';
|
|
8
|
+
import { logWithPrefix } from '@/utils/console';
|
|
9
|
+
import { usingElapsedTime, formatElapsedTime } from '@/utils/time';
|
|
7
10
|
|
|
8
11
|
async function runCLI() {
|
|
9
12
|
await yargs(hideBin(process.argv))
|
|
@@ -73,15 +76,28 @@ async function runCLI() {
|
|
|
73
76
|
alias: 'F',
|
|
74
77
|
}),
|
|
75
78
|
async (cliArguments) => {
|
|
76
|
-
await
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
const executionSummary = await usingElapsedTime(async () => {
|
|
80
|
+
await generateTypesFromOpenAPI({
|
|
81
|
+
input: cliArguments.input,
|
|
82
|
+
output: cliArguments.output,
|
|
83
|
+
serviceName: cliArguments.serviceName,
|
|
84
|
+
includeComments: cliArguments.comments,
|
|
85
|
+
prune: cliArguments.prune,
|
|
86
|
+
filters: cliArguments.filter,
|
|
87
|
+
filterFile: cliArguments.filterFile,
|
|
88
|
+
});
|
|
84
89
|
});
|
|
90
|
+
|
|
91
|
+
const outputFilePath = cliArguments.output;
|
|
92
|
+
|
|
93
|
+
const successMessage =
|
|
94
|
+
`${color.green(color.bold('✔'))} Generated ` +
|
|
95
|
+
`${outputFilePath ? color.green(outputFilePath) : `to ${color.yellow('stdout')}`} ${color.dim(
|
|
96
|
+
`(${formatElapsedTime(executionSummary.elapsedTime)})`,
|
|
97
|
+
)}`;
|
|
98
|
+
|
|
99
|
+
const hasWrittenToStdout = outputFilePath === undefined;
|
|
100
|
+
logWithPrefix(successMessage, { method: hasWrittenToStdout ? 'warn' : 'log' });
|
|
85
101
|
},
|
|
86
102
|
),
|
|
87
103
|
)
|
package/src/typegen/index.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import TypegenNamespace from './namespace/TypegenNamespace';
|
|
2
|
-
|
|
3
1
|
export type { OpenAPITypegenOptions } from './openapi/generate';
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
* A namespace of type generation resources.
|
|
7
|
-
*
|
|
8
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐typegen `zimic-http typegen` API reference}
|
|
9
|
-
*/
|
|
10
|
-
export const typegen = Object.freeze(new TypegenNamespace());
|
|
11
|
-
|
|
12
|
-
export type { TypegenNamespace };
|
|
3
|
+
export { default as generateTypesFromOpenAPI } from './openapi/generate';
|
|
@@ -72,7 +72,7 @@ function normalizeRawNodes(rawNodes: ts.Node[], context: TypeTransformContext, o
|
|
|
72
72
|
/**
|
|
73
73
|
* The options to use when generating types from an OpenAPI schema.
|
|
74
74
|
*
|
|
75
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐typegen#
|
|
75
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐typegen#generatetypesfromopenapioptions `generateTypesFromOpenAPI(options)` API reference}
|
|
76
76
|
*/
|
|
77
77
|
export interface OpenAPITypegenOptions {
|
|
78
78
|
/**
|
|
@@ -129,7 +129,7 @@ export interface OpenAPITypegenOptions {
|
|
|
129
129
|
* Generates TypeScript types from an OpenAPI schema.
|
|
130
130
|
*
|
|
131
131
|
* @param options The options to use when generating the types.
|
|
132
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐typegen#
|
|
132
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐typegen#generatetypesfromopenapioptions `generateTypesFromOpenAPI(options)` API reference}
|
|
133
133
|
*/
|
|
134
134
|
async function generateTypesFromOpenAPI({
|
|
135
135
|
input: inputFilePathOrURL,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import isNonEmpty from '@zimic/utils/data/isNonEmpty';
|
|
2
2
|
import createRegExpFromWildcardPath from '@zimic/utils/url/createRegExpFromWildcardPath';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
3
|
import filesystem from 'fs/promises';
|
|
5
4
|
import path from 'path';
|
|
5
|
+
import color from 'picocolors';
|
|
6
6
|
|
|
7
7
|
import { HTTP_METHODS } from '@/types/schema';
|
|
8
8
|
import { logWithPrefix } from '@/utils/console';
|
|
@@ -26,7 +26,7 @@ export function parseRawFilter(rawFilter: string): ParsedTypePathFilter | undefi
|
|
|
26
26
|
|
|
27
27
|
const isValidFilter = !filteredMethodsOrWildcard || !filteredPath;
|
|
28
28
|
if (isValidFilter) {
|
|
29
|
-
logWithPrefix(`Warning: Filter could not be parsed and was ignored: ${
|
|
29
|
+
logWithPrefix(`Warning: Filter could not be parsed and was ignored: ${color.yellow(rawFilter)}`, {
|
|
30
30
|
method: 'warn',
|
|
31
31
|
});
|
|
32
32
|
return undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import isDefined from '@zimic/utils/data/isDefined';
|
|
2
2
|
import { Override } from '@zimic/utils/types';
|
|
3
|
-
import
|
|
3
|
+
import color from 'picocolors';
|
|
4
4
|
import ts from 'typescript';
|
|
5
5
|
|
|
6
6
|
import { HTTP_METHODS, HttpMethod } from '@/types/schema';
|
|
@@ -438,7 +438,7 @@ export function normalizeResponse(
|
|
|
438
438
|
|
|
439
439
|
if (!mappedType) {
|
|
440
440
|
logWithPrefix(
|
|
441
|
-
`Warning: Response has a non-standard status code: ${
|
|
441
|
+
`Warning: Response has a non-standard status code: ${color.yellow(response.name.text)}. ` +
|
|
442
442
|
"Consider replacing it with a number (e.g. '200'), a pattern ('1xx', '2xx', '3xx', '4xx', or '5xx'), " +
|
|
443
443
|
"or 'default'.",
|
|
444
444
|
{ method: 'warn' },
|
package/src/utils/console.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import color from 'picocolors';
|
|
2
2
|
|
|
3
3
|
export function logWithPrefix(message: string, options: { method: 'log' | 'warn' | 'error' }) {
|
|
4
4
|
const { method } = options;
|
|
5
5
|
|
|
6
|
-
console[method](
|
|
6
|
+
console[method](color.cyan('[@zimic/http]'), message);
|
|
7
7
|
}
|