@zimic/http 1.1.2-canary.6 → 1.1.3-canary.0

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/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../package.json","../src/utils/time.ts","../src/cli/cli.ts","../src/cli/index.ts"],"names":["yargs","hideBin","generate_default","color","logger"],"mappings":";;;;;;;;;;;;;;AAcE,IAAA,OAAA,GAAW,gBAAA;;;ACZb,eAAsB,iBAA6B,QAAA,EAA6C;AAC9F,EAAA,MAAM,uBAAA,GAA0B,YAAY,GAAA,EAAI;AAEhD,EAAA,MAAM,MAAA,GAAS,MAAM,QAAA,EAAS;AAE9B,EAAA,MAAM,qBAAA,GAAwB,YAAY,GAAA,EAAI;AAC9C,EAAA,MAAM,4BAA4B,qBAAA,GAAwB,uBAAA;AAE1D,EAAA,OAAO;AAAA,IACL,SAAA,EAAW,uBAAA;AAAA,IACX,WAAA,EAAa,yBAAA;AAAA,IACb,OAAA,EAAS,qBAAA;AAAA,IACT;AAAA,GACF;AACF;AAEO,SAAS,kBAAkB,yBAAA,EAAmC;AACnE,EAAA,IAAI,4BAA4B,GAAA,EAAM;AACpC,IAAA,OAAO,CAAA,EAAG,yBAAA,CAA0B,OAAA,CAAQ,CAAC,CAAC,CAAA,EAAA,CAAA;AAAA,GAChD,MAAO;AACL,IAAA,OAAO,CAAA,EAAA,CAAI,yBAAA,GAA4B,GAAA,EAAM,OAAA,CAAQ,CAAC,CAAC,CAAA,CAAA,CAAA;AAAA;AAE3D;;;ACdA,eAAe,MAAA,GAAS;AACtB,EAAA,MAAMA,uBAAMC,eAAA,CAAQ,OAAA,CAAQ,IAAI,CAAC,EAC9B,UAAA,CAAW,YAAY,CAAA,CACvB,OAAA,CAAQ,OAAO,CAAA,CACf,cAAA,CAAe,KAAK,CAAA,CACpB,QAAO,CAEP,OAAA;AAAA,IAAQ,SAAA;AAAA,IAAW,qCAAA;AAAA,IAA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;AAAA,OACR,CAAA;AAAA,MACL,OAAO,YAAA,KAAiB;AACtB,QAAA,MAAM,gBAAA,GAAmB,MAAM,gBAAA,CAAiB,YAAY;AAC1D,UAAA,MAAME,iCAAA,CAAyB;AAAA,YAC7B,OAAO,YAAA,CAAa,KAAA;AAAA,YACpB,QAAQ,YAAA,CAAa,MAAA;AAAA,YACrB,aAAa,YAAA,CAAa,WAAA;AAAA,YAC1B,iBAAiB,YAAA,CAAa,QAAA;AAAA,YAC9B,OAAO,YAAA,CAAa,KAAA;AAAA,YACpB,SAAS,YAAA,CAAa,MAAA;AAAA,YACtB,YAAY,YAAA,CAAa;AAAA,WAC1B,CAAA;AAAA,SACF,CAAA;AAED,QAAA,MAAM,iBAAiB,YAAA,CAAa,MAAA;AAEpC,QAAA,MAAM,cAAA,GACJ,GAAGC,sBAAA,CAAM,KAAA,CAAMA,uBAAM,IAAA,CAAK,QAAG,CAAC,CAAC,CAAA,WAAA,EAC5B,cAAA,GAAiBA,uBAAM,KAAA,CAAM,cAAc,IAAI,CAAA,GAAA,EAAMA,sBAAA,CAAM,OAAO,QAAQ,CAAC,CAAA,CAAE,CAAA,CAAA,EAAIA,sBAAA,CAAM,GAAA;AAAA,UACxF,CAAA,CAAA,EAAI,iBAAA,CAAkB,gBAAA,CAAiB,WAAW,CAAC,CAAA,CAAA;AAAA,SACpD,CAAA,CAAA;AAEH,QAAA,MAAM,qBAAqB,cAAA,KAAmB,MAAA;AAC9C,QAAAC,uBAAA,CAAO,kBAAA,GAAqB,MAAA,GAAS,MAAM,CAAA,CAAE,cAAc,CAAA;AAAA;AAC7D;AACF,IAGD,KAAA,EAAM;AACX;AAEA,IAAO,WAAA,GAAQ,MAAA;;;AC9Gf,KAAK,WAAA,EAAO","file":"cli.js","sourcesContent":["{\n \"name\": \"@zimic/http\",\n \"description\": \"Next-gen 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\": \"1.1.2-canary.6\",\n \"homepage\": \"https://zimic.dev/docs/http\",\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 \"funding\": {\n \"type\": \"github\",\n \"url\": \"https://github.com/sponsors/zimicjs\"\n },\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\",\n \"provenance\": true\n },\n \"engines\": {\n \"node\": \">=20.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 \"sideEffects\": false,\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 --enable-source-maps ./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:prepare\": \"playwright install chromium\"\n },\n \"dependencies\": {\n \"openapi-typescript\": \"7.9.1\",\n \"picocolors\": \"^1.1.1\",\n \"yargs\": \"18.0.0\"\n },\n \"devDependencies\": {\n \"@types/js-yaml\": \"^4.0.9\",\n \"@types/node\": \"^24.5.2\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.2.4\",\n \"@vitest/coverage-istanbul\": \"^3.2.4\",\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\": \"^10.0.0\",\n \"eslint\": \"^9.36.0\",\n \"execa\": \"9.6.0\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.55.1\",\n \"prettier\": \"^3.6.2\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.20.6\",\n \"typescript\": \"^5.9.2\",\n \"vitest\": \"^3.2.4\"\n },\n \"peerDependencies\": {\n \"typescript\": \">=5.0.0\"\n },\n \"peerDependenciesMeta\": {\n \"typescript\": {\n \"optional\": true\n }\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 { logger } from '@/utils/logging';\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 filtering which endpoints to include. Filters must follow the format `<method> ' +\n '<path>`, where:',\n '- `<method>`: one HTTP method, a list of HTTP methods separated by commas, or `*` to match any HTTP ' +\n 'method;',\n '- `<path>`: a literal path or a glob. `*` matches zero or more characters in a segment (except `/`), ' +\n 'while `**` matches zero or more characters across segments (may include `/`). For example, ' +\n '`GET /users` matches a single method and path, while `* /users` matches any method to the `/users` ' +\n 'path; `GET /users*` matches any `GET` request whose path starts with `/users`, and `GET /users/**/*` ' +\n 'matches any `GET` request to any sub-path of `/users`.',\n\n 'Negative filters can be created by prefixing the expression with `!`. For example, `!GET /users` will ' +\n 'exclude paths matching `GET /users`.',\n ].join('\\n'),\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 logger[hasWrittenToStdout ? 'warn' : 'info'](successMessage);\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","hideBin","generate_default","color","logger"],"mappings":";;;;;;;;;;;;;;AAcE,IAAA,OAAA,GAAW,gBAAA;;;ACZb,eAAsB,iBAA6B,QAAA,EAA6C;AAC9F,EAAA,MAAM,uBAAA,GAA0B,YAAY,GAAA,EAAI;AAEhD,EAAA,MAAM,MAAA,GAAS,MAAM,QAAA,EAAS;AAE9B,EAAA,MAAM,qBAAA,GAAwB,YAAY,GAAA,EAAI;AAC9C,EAAA,MAAM,4BAA4B,qBAAA,GAAwB,uBAAA;AAE1D,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A,CAAK,QAAG,CAAC,CAAC,CAAA,WAAA,EAC5B,cAAA,GAAiBA,uBAAM,KAAA,CAAM,cAAc,IAAI,CAAA,GAAA,EAAMA,sBAAA,CAAM,OAAO,QAAQ,CAAC,CAAA,CAAE,CAAA,CAAA,EAAIA,sBAAA,CAAM,GAAA;AAAA,UACxF,CAAA,CAAA,EAAI,iBAAA,CAAkB,gBAAA,CAAiB,WAAW,CAAC,CAAA,CAAA;AAAA,SACpD,CAAA,CAAA;AAEH,QAAA,MAAM,qBAAqB,cAAA,KAAmB,MAAA;AAC9C,QAAAC,uBAAA,CAAO,kBAAA,GAAqB,MAAA,GAAS,MAAM,CAAA,CAAE,cAAc,CAAA;AAAA;AAC7D;AACF,IAGD,KAAA,EAAM;AACX;AAEA,IAAO,WAAA,GAAQ,MAAA;;;AC9Gf,KAAK,WAAA,EAAO","file":"cli.js","sourcesContent":["{\n \"name\": \"@zimic/http\",\n \"description\": \"Next-gen 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\": \"1.1.3-canary.0\",\n \"homepage\": \"https://zimic.dev/docs/http\",\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 \"funding\": {\n \"type\": \"github\",\n \"url\": \"https://github.com/sponsors/zimicjs\"\n },\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\",\n \"provenance\": true\n },\n \"engines\": {\n \"node\": \">=20.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 \"sideEffects\": false,\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 --enable-source-maps ./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 -v FORCE_COLOR=1 -- 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:prepare\": \"playwright install chromium\"\n },\n \"dependencies\": {\n \"openapi-typescript\": \"7.9.1\",\n \"picocolors\": \"^1.1.1\",\n \"yargs\": \"18.0.0\"\n },\n \"devDependencies\": {\n \"@types/js-yaml\": \"^4.0.9\",\n \"@types/node\": \"^24.5.2\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.2.4\",\n \"@vitest/coverage-istanbul\": \"^3.2.4\",\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\": \"^10.0.0\",\n \"eslint\": \"^9.36.0\",\n \"execa\": \"9.6.0\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.55.1\",\n \"prettier\": \"^3.6.2\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.20.6\",\n \"typescript\": \"^5.9.2\",\n \"vitest\": \"^3.2.4\"\n },\n \"peerDependencies\": {\n \"typescript\": \">=5.0.0\"\n },\n \"peerDependenciesMeta\": {\n \"typescript\": {\n \"optional\": true\n }\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 { logger } from '@/utils/logging';\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 filtering which endpoints to include. Filters must follow the format `<method> ' +\n '<path>`, where:',\n '- `<method>`: one HTTP method, a list of HTTP methods separated by commas, or `*` to match any HTTP ' +\n 'method;',\n '- `<path>`: a literal path or a glob. `*` matches zero or more characters in a segment (except `/`), ' +\n 'while `**` matches zero or more characters across segments (may include `/`). For example, ' +\n '`GET /users` matches a single method and path, while `* /users` matches any method to the `/users` ' +\n 'path; `GET /users*` matches any `GET` request whose path starts with `/users`, and `GET /users/**/*` ' +\n 'matches any `GET` request to any sub-path of `/users`.',\n\n 'Negative filters can be created by prefixing the expression with `!`. For example, `!GET /users` will ' +\n 'exclude paths matching `GET /users`.',\n ].join('\\n'),\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 logger[hasWrittenToStdout ? 'warn' : 'info'](successMessage);\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/cli.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { logger, generate_default } from './chunk-ZPOGWLJW.mjs';
2
+ import { logger, generate_default } from './chunk-CGLPJU2K.mjs';
3
3
  import color from 'picocolors';
4
4
  import yargs from 'yargs';
5
5
  import { hideBin } from 'yargs/helpers';
6
6
 
7
7
  // package.json
8
- var version = "1.1.2-canary.6";
8
+ var version = "1.1.3-canary.0";
9
9
 
10
10
  // src/utils/time.ts
11
11
  async function usingElapsedTime(callback) {
package/dist/cli.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../package.json","../src/utils/time.ts","../src/cli/cli.ts","../src/cli/index.ts"],"names":["yargs"],"mappings":";;;;;;;AAcE,IAAA,OAAA,GAAW,gBAAA;;;ACZb,eAAsB,iBAA6B,QAAA,EAA6C;AAC9F,EAAA,MAAM,uBAAA,GAA0B,YAAY,GAAA,EAAI;AAEhD,EAAA,MAAM,MAAA,GAAS,MAAM,QAAA,EAAS;AAE9B,EAAA,MAAM,qBAAA,GAAwB,YAAY,GAAA,EAAI;AAC9C,EAAA,MAAM,4BAA4B,qBAAA,GAAwB,uBAAA;AAE1D,EAAA,OAAO;AAAA,IACL,SAAA,EAAW,uBAAA;AAAA,IACX,WAAA,EAAa,yBAAA;AAAA,IACb,OAAA,EAAS,qBAAA;AAAA,IACT;AAAA,GACF;AACF;AAEO,SAAS,kBAAkB,yBAAA,EAAmC;AACnE,EAAA,IAAI,4BAA4B,GAAA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,CAAA,EAAI,iBAAA,CAAkB,gBAAA,CAAiB,WAAW,CAAC,CAAA,CAAA;AAAA,SACpD,CAAA,CAAA;AAEH,QAAA,MAAM,qBAAqB,cAAA,KAAmB,MAAA;AAC9C,QAAA,MAAA,CAAO,kBAAA,GAAqB,MAAA,GAAS,MAAM,CAAA,CAAE,cAAc,CAAA;AAAA;AAC7D;AACF,IAGD,KAAA,EAAM;AACX;AAEA,IAAO,WAAA,GAAQ,MAAA;;;AC9Gf,KAAK,WAAA,EAAO","file":"cli.mjs","sourcesContent":["{\n \"name\": \"@zimic/http\",\n \"description\": \"Next-gen 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\": \"1.1.2-canary.6\",\n \"homepage\": \"https://zimic.dev/docs/http\",\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 \"funding\": {\n \"type\": \"github\",\n \"url\": \"https://github.com/sponsors/zimicjs\"\n },\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\",\n \"provenance\": true\n },\n \"engines\": {\n \"node\": \">=20.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 \"sideEffects\": false,\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 --enable-source-maps ./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:prepare\": \"playwright install chromium\"\n },\n \"dependencies\": {\n \"openapi-typescript\": \"7.9.1\",\n \"picocolors\": \"^1.1.1\",\n \"yargs\": \"18.0.0\"\n },\n \"devDependencies\": {\n \"@types/js-yaml\": \"^4.0.9\",\n \"@types/node\": \"^24.5.2\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.2.4\",\n \"@vitest/coverage-istanbul\": \"^3.2.4\",\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\": \"^10.0.0\",\n \"eslint\": \"^9.36.0\",\n \"execa\": \"9.6.0\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.55.1\",\n \"prettier\": \"^3.6.2\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.20.6\",\n \"typescript\": \"^5.9.2\",\n \"vitest\": \"^3.2.4\"\n },\n \"peerDependencies\": {\n \"typescript\": \">=5.0.0\"\n },\n \"peerDependenciesMeta\": {\n \"typescript\": {\n \"optional\": true\n }\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 { logger } from '@/utils/logging';\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 filtering which endpoints to include. Filters must follow the format `<method> ' +\n '<path>`, where:',\n '- `<method>`: one HTTP method, a list of HTTP methods separated by commas, or `*` to match any HTTP ' +\n 'method;',\n '- `<path>`: a literal path or a glob. `*` matches zero or more characters in a segment (except `/`), ' +\n 'while `**` matches zero or more characters across segments (may include `/`). For example, ' +\n '`GET /users` matches a single method and path, while `* /users` matches any method to the `/users` ' +\n 'path; `GET /users*` matches any `GET` request whose path starts with `/users`, and `GET /users/**/*` ' +\n 'matches any `GET` request to any sub-path of `/users`.',\n\n 'Negative filters can be created by prefixing the expression with `!`. For example, `!GET /users` will ' +\n 'exclude paths matching `GET /users`.',\n ].join('\\n'),\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 logger[hasWrittenToStdout ? 'warn' : 'info'](successMessage);\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,IAAA,OAAA,GAAW,gBAAA;;;ACZb,eAAsB,iBAA6B,QAAA,EAA6C;AAC9F,EAAA,MAAM,uBAAA,GAA0B,YAAY,GAAA,EAAI;AAEhD,EAAA,MAAM,MAAA,GAAS,MAAM,QAAA,EAAS;AAE9B,EAAA,MAAM,qBAAA,GAAwB,YAAY,GAAA,EAAI;AAC9C,EAAA,MAAM,4BAA4B,qBAAA,GAAwB,uBAAA;AAE1D,EAAA,OAAO;AAAA,IACL,SAAA,EAAW,uBAAA;AAAA,IACX,WAAA,EAAa,yBAAA;AAAA,IACb,OAAA,EAAS,qBAAA;AAAA,IACT;AAAA,GACF;AACF;AAEO,SAAS,kBAAkB,yBAAA,EAAmC;AACnE,EAAA,IAAI,4BAA4B,GAAA,EAAM;AACpC,IAAA,OAAO,CAAA,EAAG,yBAAA,CAA0B,OAAA,CAAQ,CAAC,CAAC,CAAA,EAAA,CAAA;AAAA,GAChD,MAAO;AACL,IAAA,OAAO,CAAA,EAAA,CAAI,yBAAA,GAA4B,GAAA,EAAM,OAAA,CAAQ,CAAC,CAAC,CAAA,CAAA,CAAA;AAAA;AAE3D;;;ACdA,eAAe,MAAA,GAAS;AACtB,EAAA,MAAM,MAAM,OAAA,CAAQ,OAAA,CAAQ,IAAI,CAAC,EAC9B,UAAA,CAAW,YAAY,CAAA,CACvB,OAAA,CAAQ,OAAO,CAAA,CACf,cAAA,CAAe,KAAK,CAAA,CACpB,QAAO,CAEP,OAAA;AAAA,IAAQ,SAAA;AAAA,IAAW,qCAAA;AAAA,IAAuC,CAACA,MAAAA,KAC1DA,MAAAA,CAAM,aAAA,EAAc,CAAE,OAAA;AAAA,MACpB,iBAAA;AAAA,MACA,wCAAA;AAAA,MAC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AC1D,UAAA,MAAM,gBAAA,CAAyB;AAAA,YAC7B,OAAO,YAAA,CAAa,KAAA;AAAA,YACpB,QAAQ,YAAA,CAAa,MAAA;AAAA,YACrB,aAAa,YAAA,CAAa,WAAA;AAAA,YAC1B,iBAAiB,YAAA,CAAa,QAAA;AAAA,YAC9B,OAAO,YAAA,CAAa,KAAA;AAAA,YACpB,SAAS,YAAA,CAAa,MAAA;AAAA,YACtB,YAAY,YAAA,CAAa;AAAA,WAC1B,CAAA;AAAA,SACF,CAAA;AAED,QAAA,MAAM,iBAAiB,YAAA,CAAa,MAAA;AAEpC,QAAA,MAAM,cAAA,GACJ,GAAG,KAAA,CAAM,KAAA,CAAM,MAAM,IAAA,CAAK,QAAG,CAAC,CAAC,CAAA,WAAA,EAC5B,cAAA,GAAiB,MAAM,KAAA,CAAM,cAAc,IAAI,CAAA,GAAA,EAAM,KAAA,CAAM,OAAO,QAAQ,CAAC,CAAA,CAAE,CAAA,CAAA,EAAI,KAAA,CAAM,GAAA;AAAA,UACxF,CAAA,CAAA,EAAI,iBAAA,CAAkB,gBAAA,CAAiB,WAAW,CAAC,CAAA,CAAA;AAAA,SACpD,CAAA,CAAA;AAEH,QAAA,MAAM,qBAAqB,cAAA,KAAmB,MAAA;AAC9C,QAAA,MAAA,CAAO,kBAAA,GAAqB,MAAA,GAAS,MAAM,CAAA,CAAE,cAAc,CAAA;AAAA;AAC7D;AACF,IAGD,KAAA,EAAM;AACX;AAEA,IAAO,WAAA,GAAQ,MAAA;;;AC9Gf,KAAK,WAAA,EAAO","file":"cli.mjs","sourcesContent":["{\n \"name\": \"@zimic/http\",\n \"description\": \"Next-gen 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\": \"1.1.3-canary.0\",\n \"homepage\": \"https://zimic.dev/docs/http\",\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 \"funding\": {\n \"type\": \"github\",\n \"url\": \"https://github.com/sponsors/zimicjs\"\n },\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\",\n \"provenance\": true\n },\n \"engines\": {\n \"node\": \">=20.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 \"sideEffects\": false,\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 --enable-source-maps ./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 -v FORCE_COLOR=1 -- 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:prepare\": \"playwright install chromium\"\n },\n \"dependencies\": {\n \"openapi-typescript\": \"7.9.1\",\n \"picocolors\": \"^1.1.1\",\n \"yargs\": \"18.0.0\"\n },\n \"devDependencies\": {\n \"@types/js-yaml\": \"^4.0.9\",\n \"@types/node\": \"^24.5.2\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.2.4\",\n \"@vitest/coverage-istanbul\": \"^3.2.4\",\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\": \"^10.0.0\",\n \"eslint\": \"^9.36.0\",\n \"execa\": \"9.6.0\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.55.1\",\n \"prettier\": \"^3.6.2\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.20.6\",\n \"typescript\": \"^5.9.2\",\n \"vitest\": \"^3.2.4\"\n },\n \"peerDependencies\": {\n \"typescript\": \">=5.0.0\"\n },\n \"peerDependenciesMeta\": {\n \"typescript\": {\n \"optional\": true\n }\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 { logger } from '@/utils/logging';\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 filtering which endpoints to include. Filters must follow the format `<method> ' +\n '<path>`, where:',\n '- `<method>`: one HTTP method, a list of HTTP methods separated by commas, or `*` to match any HTTP ' +\n 'method;',\n '- `<path>`: a literal path or a glob. `*` matches zero or more characters in a segment (except `/`), ' +\n 'while `**` matches zero or more characters across segments (may include `/`). For example, ' +\n '`GET /users` matches a single method and path, while `* /users` matches any method to the `/users` ' +\n 'path; `GET /users*` matches any `GET` request whose path starts with `/users`, and `GET /users/**/*` ' +\n 'matches any `GET` request to any sub-path of `/users`.',\n\n 'Negative filters can be created by prefixing the expression with `!`. For example, `!GET /users` will ' +\n 'exclude paths matching `GET /users`.',\n ].join('\\n'),\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 logger[hasWrittenToStdout ? 'warn' : 'info'](successMessage);\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.js CHANGED
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var chunkOFNBRVSF_js = require('./chunk-OFNBRVSF.js');
3
+ var chunkB2CEMX5F_js = require('./chunk-B2CEMX5F.js');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "generateTypesFromOpenAPI", {
8
8
  enumerable: true,
9
- get: function () { return chunkOFNBRVSF_js.generate_default; }
9
+ get: function () { return chunkB2CEMX5F_js.generate_default; }
10
10
  });
11
11
  //# sourceMappingURL=typegen.js.map
12
12
  //# sourceMappingURL=typegen.js.map
package/dist/typegen.mjs CHANGED
@@ -1,3 +1,3 @@
1
- export { generate_default as generateTypesFromOpenAPI } from './chunk-ZPOGWLJW.mjs';
1
+ export { generate_default as generateTypesFromOpenAPI } from './chunk-CGLPJU2K.mjs';
2
2
  //# sourceMappingURL=typegen.mjs.map
3
3
  //# sourceMappingURL=typegen.mjs.map
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "api",
13
13
  "static"
14
14
  ],
15
- "version": "1.1.2-canary.6",
15
+ "version": "1.1.3-canary.0",
16
16
  "homepage": "https://zimic.dev/docs/http",
17
17
  "repository": {
18
18
  "type": "git",
@@ -92,10 +92,10 @@
92
92
  "typescript": "^5.9.2",
93
93
  "vitest": "^3.2.4",
94
94
  "@zimic/eslint-config-node": "0.0.0",
95
- "@zimic/interceptor": "1.1.2-canary.5",
95
+ "@zimic/interceptor": "1.1.2",
96
96
  "@zimic/tsconfig": "0.0.0",
97
- "@zimic/lint-staged-config": "0.0.0",
98
- "@zimic/utils": "0.0.0"
97
+ "@zimic/utils": "0.0.0",
98
+ "@zimic/lint-staged-config": "0.0.0"
99
99
  },
100
100
  "peerDependencies": {
101
101
  "typescript": ">=5.0.0"
@@ -114,7 +114,7 @@
114
114
  "style": "prettier --log-level warn --ignore-unknown --no-error-on-unmatched-pattern --cache",
115
115
  "style:check": "pnpm style --check",
116
116
  "style:format": "pnpm style --write",
117
- "test": "dotenv -v NODE_ENV=test -- vitest",
117
+ "test": "dotenv -v NODE_ENV=test -v FORCE_COLOR=1 -- vitest",
118
118
  "test:turbo": "dotenv -v CI=true -- pnpm run test run --coverage",
119
119
  "types:check": "tsc --noEmit",
120
120
  "typegen:fixtures": "tsx ./scripts/typegen/generateFixtureTypes.ts",
@@ -1,5 +1,4 @@
1
1
  import isDefined from '@zimic/utils/data/isDefined';
2
- import filesystem from 'fs/promises';
3
2
  import path from 'path';
4
3
  import ts from 'typescript';
5
4
 
@@ -15,8 +14,9 @@ import { createImportDeclarations } from './transform/imports';
15
14
  import {
16
15
  convertTypesToString,
17
16
  importTypesFromOpenAPI,
18
- prepareTypeOutputToSave,
19
- writeTypeOutputToStandardOutput,
17
+ formatTypegenResultToOutput,
18
+ writeTypegenResultToStandardOutput,
19
+ writeTypegenResultToFile,
20
20
  } from './transform/io';
21
21
  import { isOperationsDeclaration, normalizeOperations, removeUnreferencedOperations } from './transform/operations';
22
22
  import { isPathsDeclaration, normalizePaths } from './transform/paths';
@@ -97,7 +97,7 @@ async function generateTypesFromOpenAPI({
97
97
  filters: filtersFromArguments = [],
98
98
  filterFile,
99
99
  }: OpenAPITypegenOptions) {
100
- const filtersFromFile = filterFile ? await readPathFiltersFromFile(filterFile) : [];
100
+ const filtersFromFile = filterFile ? await readPathFiltersFromFile(path.resolve(filterFile)) : [];
101
101
  const filters = ignoreEmptyFilters([...filtersFromFile, ...filtersFromArguments]);
102
102
 
103
103
  const rawNodes = await importTypesFromOpenAPI(inputFilePathOrURL);
@@ -110,14 +110,15 @@ async function generateTypesFromOpenAPI({
110
110
  nodes.unshift(declaration);
111
111
  }
112
112
 
113
- const typeOutput = await convertTypesToString(nodes, { includeComments });
114
- const formattedOutput = prepareTypeOutputToSave(typeOutput);
113
+ const typegenResult = await convertTypesToString(nodes, { includeComments });
114
+ const formattedTypegenResult = formatTypegenResultToOutput(typegenResult);
115
115
 
116
- const shouldWriteToStdout = outputFilePath === undefined;
117
- if (shouldWriteToStdout) {
118
- await writeTypeOutputToStandardOutput(formattedOutput);
116
+ const shouldWriteToStandardOutput = outputFilePath === undefined;
117
+
118
+ if (shouldWriteToStandardOutput) {
119
+ await writeTypegenResultToStandardOutput(formattedTypegenResult);
119
120
  } else {
120
- await filesystem.writeFile(path.resolve(outputFilePath), formattedOutput);
121
+ await writeTypegenResultToFile(path.resolve(outputFilePath), formattedTypegenResult);
121
122
  }
122
123
  }
123
124
 
@@ -1,10 +1,10 @@
1
1
  import isNonEmpty from '@zimic/utils/data/isNonEmpty';
2
2
  import createWildcardRegexFromPath from '@zimic/utils/url/createWildcardRegexFromPath';
3
- import filesystem from 'fs/promises';
4
- import path from 'path';
3
+ import fs from 'fs';
5
4
  import color from 'picocolors';
6
5
 
7
6
  import { HTTP_METHODS } from '@/types/schema';
7
+ import { ensurePathExists } from '@/utils/files';
8
8
  import { logger } from '@/utils/logging';
9
9
 
10
10
  import { TypePathFilter, TypePathFilters } from './context';
@@ -51,7 +51,11 @@ export function groupParsedFiltersByMatch(parsedFilters: (TypePathFilter | undef
51
51
  }
52
52
 
53
53
  export async function readPathFiltersFromFile(filePath: string) {
54
- const fileContent = await filesystem.readFile(path.resolve(filePath), 'utf-8');
54
+ await ensurePathExists(filePath, {
55
+ errorMessage: `Could not read filter file: ${color.yellow(filePath)}`,
56
+ });
57
+
58
+ const fileContent = await fs.promises.readFile(filePath, 'utf-8');
55
59
  const fileContentWithoutComments = fileContent.replace(/#.*$/gm, '');
56
60
 
57
61
  const filters = fileContentWithoutComments.split('\n');
@@ -1,4 +1,5 @@
1
1
  import createCachedDynamicImport from '@zimic/utils/import/createCachedDynamicImport';
2
+ import fs from 'fs';
2
3
  import type { SchemaObject } from 'openapi-typescript';
3
4
  import path from 'path';
4
5
  import ts from 'typescript';
@@ -56,29 +57,34 @@ export async function importTypesFromOpenAPI(filePathOrURL: string) {
56
57
  export async function convertTypesToString(nodes: ts.Node[], options: { includeComments: boolean }) {
57
58
  const { astToString: convertTypeASTToString } = await importOpenapiTypeScript();
58
59
 
59
- const typeOutput = convertTypeASTToString(nodes, {
60
+ const typegenResult = convertTypeASTToString(nodes, {
60
61
  formatOptions: { removeComments: !options.includeComments },
61
62
  });
62
63
 
63
- return typeOutput;
64
+ return typegenResult;
64
65
  }
65
66
 
66
- export function prepareTypeOutputToSave(output: string) {
67
- const formattedOutput = output
67
+ export function formatTypegenResultToOutput(typegenResult: string) {
68
+ const formattedResult = typegenResult
68
69
  .replace(/^export (\w+)/gm, '\nexport $1')
69
70
  .replace(/^( {4})+/gm, (match) => match.replace(/ {4}/g, ' '));
70
71
 
71
- const formattedOutputWithPrefix = [
72
+ return [
72
73
  '// Auto-generated by @zimic/http.',
73
74
  '// NOTE: Do not manually edit this file. Changes will be overridden.\n',
74
- formattedOutput,
75
+ formattedResult,
75
76
  ].join('\n');
76
-
77
- return formattedOutputWithPrefix;
78
77
  }
79
78
 
80
- export async function writeTypeOutputToStandardOutput(formattedOutput: string) {
79
+ export async function writeTypegenResultToStandardOutput(typegenResult: string) {
81
80
  await new Promise((resolve) => {
82
- process.stdout.write(formattedOutput, 'utf-8', resolve);
81
+ process.stdout.write(typegenResult, 'utf-8', resolve);
83
82
  });
84
83
  }
84
+
85
+ export async function writeTypegenResultToFile(outputFilePath: string, formattedResult: string) {
86
+ const outputDirectory = path.dirname(outputFilePath);
87
+ await fs.promises.mkdir(outputDirectory, { recursive: true });
88
+
89
+ await fs.promises.writeFile(outputFilePath, formattedResult);
90
+ }
@@ -1,4 +1,6 @@
1
1
  import createCachedDynamicImport from '@zimic/utils/import/createCachedDynamicImport';
2
+ import fs from 'fs';
3
+ import path from 'path';
2
4
 
3
5
  export const importFile = createCachedDynamicImport(
4
6
  /* istanbul ignore next -- @preserve
@@ -6,3 +8,27 @@ export const importFile = createCachedDynamicImport(
6
8
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
7
9
  async () => globalThis.File ?? (await import('buffer')).File,
8
10
  );
11
+
12
+ export function replaceFileExtension(filePath: string, newExtension: string) {
13
+ const parsedFilePath = path.parse(filePath);
14
+ return path.join(parsedFilePath.dir, `${parsedFilePath.name}.${newExtension}`);
15
+ }
16
+
17
+ export async function pathExists(path: string) {
18
+ try {
19
+ await fs.promises.access(path, fs.constants.R_OK);
20
+ return true;
21
+ } catch {
22
+ return false;
23
+ }
24
+ }
25
+
26
+ export async function ensurePathExists(path: string, options: { errorMessage: string }) {
27
+ try {
28
+ await fs.promises.access(path, fs.constants.R_OK);
29
+ } catch (accessError) {
30
+ const error = new Error(options.errorMessage);
31
+ error.cause = accessError;
32
+ throw error;
33
+ }
34
+ }