@zimic/http 0.2.1 → 0.3.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 +0 -1
- package/dist/{chunk-2P56ILG3.js → chunk-3I6NFZLD.js} +92 -17
- package/dist/chunk-3I6NFZLD.js.map +1 -0
- package/dist/{chunk-5GJI2ESI.mjs → chunk-OHIMUBLQ.mjs} +92 -17
- package/dist/chunk-OHIMUBLQ.mjs.map +1 -0
- package/dist/cli.js +8 -8
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +4 -4
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.ts +43 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/typegen.js +2 -2
- package/dist/typegen.mjs +1 -1
- package/package.json +11 -11
- package/src/cli/cli.ts +3 -3
- package/src/typegen/openapi/transform/filters.ts +2 -4
- package/src/typegen/openapi/transform/methods.ts +2 -3
- package/src/types/requests.ts +2 -2
- package/src/types/schema.ts +62 -58
- package/src/utils/logging.ts +6 -0
- package/dist/chunk-2P56ILG3.js.map +0 -1
- package/dist/chunk-5GJI2ESI.mjs.map +0 -1
- package/src/utils/console.ts +0 -7
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":["__name","yargs","hideBin","generate_default","color","logWithPrefix"],"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,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,CAAC,CAC5B,WAAA,EAAA,cAAA,GAAiBA,uBAAM,KAAM,CAAA,cAAc,IAAI,CAAM,GAAA,EAAAA,sBAAA,CAAM,OAAO,QAAQ,CAAC,CAAE,CAAA,CAAA,CAAA,EAAIA,sBAAM,CAAA,GAAA;AAAA,UACxF,CAAI,CAAA,EAAA,iBAAA,CAAkB,gBAAiB,CAAA,WAAW,CAAC,CAAA,CAAA;AAAA,SACpD,CAAA,CAAA;AAEH,QAAA,MAAM,qBAAqB,cAAmB,KAAA,MAAA;AAC9C,QAAAC,8BAAA,CAAc,gBAAgB,EAAE,MAAA,EAAQ,kBAAqB,GAAA,MAAA,GAAS,OAAO,CAAA;AAAA;AAC/E;AACF,IAGD,KAAM,EAAA;AACX;AA/FeL,uBAAA,CAAA,MAAA,EAAA,QAAA,CAAA;AAiGf,IAAO,WAAQ,GAAA,MAAA;;;ACxGf,KAAK,WAAO,EAAA","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\": \"0.2.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 \"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 ./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.11\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.0.9\",\n \"@vitest/coverage-istanbul\": \"^3.0.9\",\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.23.0\",\n \"execa\": \"9.5.2\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.51.1\",\n \"prettier\": \"^3.5.3\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.19.3\",\n \"typescript\": \"^5.8.2\",\n \"vitest\": \"^3.0.9\"\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"]}
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/utils/time.ts","../src/cli/cli.ts","../src/cli/index.ts"],"names":["__name","yargs","hideBin","generate_default","color","logger"],"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;AAdsBA,uBAAA,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;AANgBA,uBAAA,CAAA,iBAAA,EAAA,mBAAA,CAAA;;;ACRhB,eAAe,MAAS,GAAA;AACtB,EAAA,MAAMC,uBAAMC,eAAQ,CAAA,OAAA,CAAQ,IAAI,CAAC,EAC9B,UAAW,CAAA,YAAY,CACvB,CAAA,OAAA,CAAQ,OAAO,CACf,CAAA,cAAA,CAAe,KAAK,CAAA,CACpB,QAEA,CAAA,OAAA;AAAA,IAAQ,SAAA;AAAA,IAAW,qCAAA;AAAA,I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AAiB,YAAY;AAC1D,UAAA,MAAME,iCAAyB,CAAA;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,QAAM,MAAA,cAAA,GACJ,GAAGC,sBAAM,CAAA,KAAA,CAAMA,uBAAM,IAAK,CAAA,QAAG,CAAC,CAAC,CAC5B,WAAA,EAAA,cAAA,GAAiBA,uBAAM,KAAM,CAAA,cAAc,IAAI,CAAM,GAAA,EAAAA,sBAAA,CAAM,OAAO,QAAQ,CAAC,CAAE,CAAA,CAAA,CAAA,EAAIA,sBAAM,CAAA,GAAA;AAAA,UACxF,CAAI,CAAA,EAAA,iBAAA,CAAkB,gBAAiB,CAAA,WAAW,CAAC,CAAA,CAAA;AAAA,SACpD,CAAA,CAAA;AAEH,QAAA,MAAM,qBAAqB,cAAmB,KAAA,MAAA;AAC9C,QAAAC,uBAAA,CAAO,kBAAqB,GAAA,MAAA,GAAS,MAAM,CAAA,CAAE,cAAc,CAAA;AAAA;AAC7D;AACF,IAGD,KAAM,EAAA;AACX;AA/FeL,uBAAA,CAAA,MAAA,EAAA,QAAA,CAAA;AAiGf,IAAO,WAAQ,GAAA,MAAA;;;ACxGf,KAAK,WAAO,EAAA","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\": \"0.3.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 \"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: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.14.0\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.1.1\",\n \"@vitest/coverage-istanbul\": \"^3.1.1\",\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.24.0\",\n \"execa\": \"9.5.2\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.51.1\",\n \"prettier\": \"^3.5.3\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.19.3\",\n \"typescript\": \"^5.8.3\",\n \"vitest\": \"^3.1.1\"\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 { 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 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 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 { __name, generate_default,
|
|
2
|
+
import { __name, generate_default, logger } from './chunk-OHIMUBLQ.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 = "0.
|
|
8
|
+
var version = "0.3.0-canary.1";
|
|
9
9
|
|
|
10
10
|
// src/utils/time.ts
|
|
11
11
|
async function usingElapsedTime(callback) {
|
|
@@ -34,7 +34,7 @@ __name(formatElapsedTime, "formatElapsedTime");
|
|
|
34
34
|
async function runCLI() {
|
|
35
35
|
await yargs(hideBin(process.argv)).scriptName("zimic-http").version(version).showHelpOnFail(false).strict().command(
|
|
36
36
|
"typegen",
|
|
37
|
-
"Generate types from schema sources",
|
|
37
|
+
"Generate types from schema sources.",
|
|
38
38
|
(yargs2) => yargs2.demandCommand().command(
|
|
39
39
|
"openapi <input>",
|
|
40
40
|
"Generate types from an OpenAPI schema.",
|
|
@@ -88,7 +88,7 @@ async function runCLI() {
|
|
|
88
88
|
`(${formatElapsedTime(executionSummary.elapsedTime)})`
|
|
89
89
|
)}`;
|
|
90
90
|
const hasWrittenToStdout = outputFilePath === void 0;
|
|
91
|
-
|
|
91
|
+
logger[hasWrittenToStdout ? "warn" : "info"](successMessage);
|
|
92
92
|
}
|
|
93
93
|
)
|
|
94
94
|
).parse();
|
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,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,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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ourcesContent":["{\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\": \"0.2.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 \"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 ./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.11\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.0.9\",\n \"@vitest/coverage-istanbul\": \"^3.0.9\",\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.23.0\",\n \"execa\": \"9.5.2\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.51.1\",\n \"prettier\": \"^3.5.3\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.19.3\",\n \"typescript\": \"^5.8.2\",\n \"vitest\": \"^3.0.9\"\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"]}
|
|
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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,KAAM,CAAA,GAAA;AAAA,UACxF,CAAI,CAAA,EAAA,iBAAA,CAAkB,gBAAiB,CAAA,WAAW,CAAC,CAAA,CAAA;AAAA,SACpD,CAAA,CAAA;AAEH,QAAA,MAAM,qBAAqB,cAAmB,KAAA,MAAA;AAC9C,QAAA,MAAA,CAAO,kBAAqB,GAAA,MAAA,GAAS,MAAM,CAAA,CAAE,cAAc,CAAA;AAAA;AAC7D;AACF,IAGD,KAAM,EAAA;AACX;AA/Fe,MAAA,CAAA,MAAA,EAAA,QAAA,CAAA;AAiGf,IAAO,WAAQ,GAAA,MAAA;;;ACxGf,KAAK,WAAO,EAAA","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\": \"0.3.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 \"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: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.14.0\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.1.1\",\n \"@vitest/coverage-istanbul\": \"^3.1.1\",\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.24.0\",\n \"execa\": \"9.5.2\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.51.1\",\n \"prettier\": \"^3.5.3\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.19.3\",\n \"typescript\": \"^5.8.3\",\n \"vitest\": \"^3.1.1\"\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 { 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 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 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/index.d.ts
CHANGED
|
@@ -649,9 +649,12 @@ interface HttpRequestSchema {
|
|
|
649
649
|
searchParams?: HttpSearchParamsSchema.Loose;
|
|
650
650
|
body?: HttpBody.Loose;
|
|
651
651
|
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
652
|
+
declare namespace HttpRequestSchema {
|
|
653
|
+
/** Convert an HTTP request schema to be strictly typed. */
|
|
654
|
+
type AsStrict<Schema> = {
|
|
655
|
+
[Key in keyof Schema]: Key extends 'headers' ? HttpHeadersSerialized<Schema[Key]> : Key extends 'searchParams' ? HttpSearchParamsSerialized<Schema[Key]> : Key extends 'body' ? HttpBody.AsStrict<Schema[Key]> : Schema[Key];
|
|
656
|
+
};
|
|
657
|
+
}
|
|
655
658
|
/**
|
|
656
659
|
* A schema representing the structure of an HTTP response.
|
|
657
660
|
*
|
|
@@ -666,8 +669,9 @@ declare namespace HttpResponseSchema {
|
|
|
666
669
|
interface NoBody extends Omit<HttpResponseSchema, 'body'> {
|
|
667
670
|
body?: null;
|
|
668
671
|
}
|
|
672
|
+
/** Convert an HTTP response schema to be strictly typed. */
|
|
673
|
+
type AsStrict<Schema> = HttpRequestSchema.AsStrict<Schema>;
|
|
669
674
|
}
|
|
670
|
-
type ConvertToStrictHttpResponseSchema<Schema> = ConvertToStrictHttpRequestSchema<Schema>;
|
|
671
675
|
/**
|
|
672
676
|
* The status codes used in HTTP responses, as defined by
|
|
673
677
|
* {@link https://httpwg.org/specs/rfc9110.html#overview.of.status.codes RFC-9110}.
|
|
@@ -678,6 +682,7 @@ type ConvertToStrictHttpResponseSchema<Schema> = ConvertToStrictHttpRequestSchem
|
|
|
678
682
|
* - `HttpStatusCode.ClientError`: {@link https://developer.mozilla.org/docs/Web/HTTP/Status#client_error_responses `4XX`}
|
|
679
683
|
* - `HttpStatusCode.ServerError`: {@link https://developer.mozilla.org/docs/Web/HTTP/Status#server_error_responses `5XX`}
|
|
680
684
|
*/
|
|
685
|
+
type HttpStatusCode = HttpStatusCode.Information | HttpStatusCode.Success | HttpStatusCode.Redirection | HttpStatusCode.ClientError | HttpStatusCode.ServerError;
|
|
681
686
|
declare namespace HttpStatusCode {
|
|
682
687
|
/**
|
|
683
688
|
* An HTTP status code in the `1XX` range, representing an informational response.
|
|
@@ -710,33 +715,26 @@ declare namespace HttpStatusCode {
|
|
|
710
715
|
*/
|
|
711
716
|
type ServerError = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
|
|
712
717
|
}
|
|
713
|
-
|
|
718
|
+
/**
|
|
719
|
+
* A schema representing the structure of HTTP responses by status code.
|
|
720
|
+
*
|
|
721
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
722
|
+
*/
|
|
723
|
+
type HttpResponseSchemaByStatusCode = HttpResponseSchemaByStatusCode.AsStrict<HttpResponseSchemaByStatusCode.Loose>;
|
|
714
724
|
declare namespace HttpResponseSchemaByStatusCode {
|
|
715
725
|
/** A loose version of HTTP responses by status code. JSON values are not strictly typed. */
|
|
716
726
|
type Loose = {
|
|
717
727
|
[StatusCode in HttpStatusCode]?: HttpResponseSchema;
|
|
718
728
|
};
|
|
719
|
-
/**
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
*/
|
|
723
|
-
type ConvertToStrict<Schema extends Loose> = {
|
|
724
|
-
[StatusCode in keyof Schema]: StatusCode extends 204 ? HttpResponseSchema.NoBody : Schema[StatusCode];
|
|
729
|
+
/** Converts an HTTP response schema by status code to be strictly typed. */
|
|
730
|
+
type AsStrict<Schema> = {
|
|
731
|
+
[StatusCode in keyof Schema]: StatusCode extends 204 ? HttpResponseSchema.NoBody : HttpResponseSchema.AsStrict<Schema[StatusCode]>;
|
|
725
732
|
};
|
|
726
733
|
/** A schema representing the structure of HTTP responses by status code with no body. */
|
|
727
734
|
type NoBody = {
|
|
728
735
|
[StatusCode in HttpStatusCode]?: HttpResponseSchema.NoBody;
|
|
729
736
|
};
|
|
730
737
|
}
|
|
731
|
-
/**
|
|
732
|
-
* A schema representing the structure of HTTP responses by status code.
|
|
733
|
-
*
|
|
734
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
735
|
-
*/
|
|
736
|
-
type HttpResponseSchemaByStatusCode = HttpResponseSchemaByStatusCode.ConvertToStrict<HttpResponseSchemaByStatusCode.Loose>;
|
|
737
|
-
type ConvertToStrictHttpResponseSchemaByStatusCode<Schema> = {
|
|
738
|
-
[Key in keyof Schema]: ConvertToStrictHttpResponseSchema<Schema[Key]>;
|
|
739
|
-
};
|
|
740
738
|
/**
|
|
741
739
|
* Extracts the status codes used in a response schema by status code.
|
|
742
740
|
*
|
|
@@ -766,10 +764,11 @@ declare namespace HttpMethodSchema {
|
|
|
766
764
|
interface NoBody extends Omit<NoRequestBody, 'response'> {
|
|
767
765
|
response?: HttpResponseSchemaByStatusCode.NoBody;
|
|
768
766
|
}
|
|
767
|
+
/** Converts an HTTP method schema to be strictly typed. */
|
|
768
|
+
type AsStrict<Schema> = {
|
|
769
|
+
[Key in keyof Schema]: Key extends 'request' ? HttpRequestSchema.AsStrict<Schema[Key]> : Key extends 'response' ? HttpResponseSchemaByStatusCode.AsStrict<Schema[Key]> : Schema[Key];
|
|
770
|
+
};
|
|
769
771
|
}
|
|
770
|
-
type ConvertToStrictMethod<Schema> = {
|
|
771
|
-
[Key in keyof Schema]: Key extends 'request' ? ConvertToStrictHttpRequestSchema<Schema[Key]> : Key extends 'response' ? ConvertToStrictHttpResponseSchemaByStatusCode<Schema[Key]> : Schema[Key];
|
|
772
|
-
};
|
|
773
772
|
/**
|
|
774
773
|
* A schema representing the structure of HTTP request and response by method.
|
|
775
774
|
*
|
|
@@ -784,15 +783,15 @@ interface HttpMethodsSchema {
|
|
|
784
783
|
HEAD?: HttpMethodSchema.NoBody;
|
|
785
784
|
OPTIONS?: HttpMethodSchema.NoRequestBody;
|
|
786
785
|
}
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
786
|
+
declare namespace HttpMethodsSchema {
|
|
787
|
+
/** Converts an HTTP methods schema to be strictly typed. */
|
|
788
|
+
type AsStrict<Schema> = {
|
|
789
|
+
[Method in keyof Schema]: HttpMethodSchema.AsStrict<Schema[Method]>;
|
|
790
|
+
};
|
|
791
|
+
}
|
|
790
792
|
interface BaseHttpSchema {
|
|
791
793
|
[path: string]: HttpMethodsSchema;
|
|
792
794
|
}
|
|
793
|
-
type ConvertToStrictHttpSchema<Schema extends HttpSchema> = {
|
|
794
|
-
[Path in keyof Schema]: ConvertToStrictHttpMethodsSchema<Schema[Path]>;
|
|
795
|
-
};
|
|
796
795
|
/**
|
|
797
796
|
* Declares an HTTP service schema.
|
|
798
797
|
*
|
|
@@ -828,8 +827,12 @@ type ConvertToStrictHttpSchema<Schema extends HttpSchema> = {
|
|
|
828
827
|
*
|
|
829
828
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
830
829
|
*/
|
|
831
|
-
type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> =
|
|
830
|
+
type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> = HttpSchema.AsStrict<Schema>;
|
|
832
831
|
declare namespace HttpSchema {
|
|
832
|
+
/** Converts an HTTP service schema to be strictly typed. */
|
|
833
|
+
type AsStrict<Schema extends BaseHttpSchema> = {
|
|
834
|
+
[Path in keyof Schema]: HttpMethodsSchema.AsStrict<Schema[Path]>;
|
|
835
|
+
};
|
|
833
836
|
/**
|
|
834
837
|
* Declares an HTTP service methods schema.
|
|
835
838
|
*
|
|
@@ -848,7 +851,7 @@ declare namespace HttpSchema {
|
|
|
848
851
|
* '/users': UserMethods;
|
|
849
852
|
* }>;
|
|
850
853
|
*/
|
|
851
|
-
type Methods<Schema extends HttpMethodsSchema> =
|
|
854
|
+
type Methods<Schema extends HttpMethodsSchema> = HttpMethodsSchema.AsStrict<Schema>;
|
|
852
855
|
/**
|
|
853
856
|
* Declares an HTTP service method schema.
|
|
854
857
|
*
|
|
@@ -867,7 +870,7 @@ declare namespace HttpSchema {
|
|
|
867
870
|
* };
|
|
868
871
|
* }>;
|
|
869
872
|
*/
|
|
870
|
-
type Method<Schema extends HttpMethodSchema> =
|
|
873
|
+
type Method<Schema extends HttpMethodSchema> = HttpMethodSchema.AsStrict<Schema>;
|
|
871
874
|
/**
|
|
872
875
|
* Declares an HTTP service request schema.
|
|
873
876
|
*
|
|
@@ -890,7 +893,7 @@ declare namespace HttpSchema {
|
|
|
890
893
|
* };
|
|
891
894
|
* }>;
|
|
892
895
|
*/
|
|
893
|
-
type Request<Schema extends HttpRequestSchema> =
|
|
896
|
+
type Request<Schema extends HttpRequestSchema> = HttpRequestSchema.AsStrict<Schema>;
|
|
894
897
|
/**
|
|
895
898
|
* Declares an HTTP service response schema by status code.
|
|
896
899
|
*
|
|
@@ -910,7 +913,7 @@ declare namespace HttpSchema {
|
|
|
910
913
|
* };
|
|
911
914
|
* }>;
|
|
912
915
|
*/
|
|
913
|
-
type ResponseByStatusCode<Schema extends HttpResponseSchemaByStatusCode> =
|
|
916
|
+
type ResponseByStatusCode<Schema extends HttpResponseSchemaByStatusCode> = HttpResponseSchemaByStatusCode.AsStrict<Schema>;
|
|
914
917
|
/**
|
|
915
918
|
* Declares an HTTP service response schema.
|
|
916
919
|
*
|
|
@@ -931,7 +934,7 @@ declare namespace HttpSchema {
|
|
|
931
934
|
* };
|
|
932
935
|
* }>;
|
|
933
936
|
*/
|
|
934
|
-
type Response<Schema extends HttpResponseSchema> =
|
|
937
|
+
type Response<Schema extends HttpResponseSchema> = HttpResponseSchema.AsStrict<Schema>;
|
|
935
938
|
/**
|
|
936
939
|
* Declares an HTTP body schema. JSON values are serialized to their strict form using
|
|
937
940
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic#jsonserialized `JSONSerialized`} if necessary.
|
|
@@ -951,7 +954,7 @@ declare namespace HttpSchema {
|
|
|
951
954
|
* };
|
|
952
955
|
* }>;
|
|
953
956
|
*/
|
|
954
|
-
type Body<Schema extends HttpBody.Loose> = HttpBody.
|
|
957
|
+
type Body<Schema extends HttpBody.Loose> = HttpBody.AsStrict<Schema>;
|
|
955
958
|
/**
|
|
956
959
|
* Declares an HTTP headers schema. Headers are serialized to their strict form using
|
|
957
960
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpheadersserialized `HttpHeadersSerialized`} if
|
|
@@ -1239,15 +1242,15 @@ type RecursiveMergeHttpResponsesByStatusCode<Schemas extends HttpResponseSchemaB
|
|
|
1239
1242
|
* };
|
|
1240
1243
|
* }>;
|
|
1241
1244
|
*/
|
|
1242
|
-
type MergeHttpResponsesByStatusCode<Schemas extends HttpResponseSchemaByStatusCode.Loose[], PastSchemas extends HttpResponseSchemaByStatusCode.Loose[] = []> = HttpResponseSchemaByStatusCode.
|
|
1245
|
+
type MergeHttpResponsesByStatusCode<Schemas extends HttpResponseSchemaByStatusCode.Loose[], PastSchemas extends HttpResponseSchemaByStatusCode.Loose[] = []> = HttpResponseSchemaByStatusCode.AsStrict<RecursiveMergeHttpResponsesByStatusCode<Schemas, PastSchemas>>;
|
|
1243
1246
|
|
|
1244
1247
|
/** The body type for HTTP requests and responses. */
|
|
1245
1248
|
type HttpBody = JSONValue | HttpFormData<any> | HttpSearchParams<any> | Blob | ArrayBuffer;
|
|
1246
1249
|
declare namespace HttpBody {
|
|
1247
1250
|
/** A loose version of the HTTP body type. JSON values are not strictly typed. */
|
|
1248
1251
|
type Loose = ReplaceBy<HttpBody, JSONValue, JSONValue.Loose>;
|
|
1249
|
-
/** Convert
|
|
1250
|
-
type
|
|
1252
|
+
/** Convert an HTTP body to be strictly typed. JSON values are serialized to their strict form. */
|
|
1253
|
+
type AsStrict<Type> = Type extends Exclude<HttpBody, JSONValue> ? Type : JSONSerialized<Type>;
|
|
1251
1254
|
}
|
|
1252
1255
|
/**
|
|
1253
1256
|
* An HTTP headers object with a strictly-typed schema. Fully compatible with the built-in
|
|
@@ -1294,4 +1297,4 @@ type HttpRequestBodySchema<MethodSchema extends HttpMethodSchema> = ReplaceBy<Re
|
|
|
1294
1297
|
type HttpResponseHeadersSchema<MethodSchema extends HttpMethodSchema, StatusCode extends HttpStatusCode> = Default<DefaultNoExclude<Default<Default<MethodSchema['response']>[StatusCode]>['headers']>>;
|
|
1295
1298
|
type HttpResponseBodySchema<MethodSchema extends HttpMethodSchema, StatusCode extends HttpStatusCode> = ReplaceBy<ReplaceBy<IfNever<DefaultNoExclude<Default<Default<MethodSchema['response']>[StatusCode]>['body']>, null>, undefined, null>, ArrayBuffer, Blob>;
|
|
1296
1299
|
|
|
1297
|
-
export { type AllowAnyStringInPathParams, HTTP_METHODS, HTTP_METHODS_WITH_REQUEST_BODY, HTTP_METHODS_WITH_RESPONSE_BODY, HttpBody, HttpFormData, HttpFormDataSchema, HttpFormDataSchemaName, type HttpFormDataSerialized, HttpHeaders, type HttpHeadersInit, HttpHeadersSchema, type HttpHeadersSchemaName, type HttpHeadersSchemaTuple, type HttpHeadersSerialized, type HttpMethod, HttpMethodSchema, type HttpMethodWithRequestBody, type HttpMethodWithResponseBody,
|
|
1300
|
+
export { type AllowAnyStringInPathParams, HTTP_METHODS, HTTP_METHODS_WITH_REQUEST_BODY, HTTP_METHODS_WITH_RESPONSE_BODY, HttpBody, HttpFormData, HttpFormDataSchema, HttpFormDataSchemaName, type HttpFormDataSerialized, HttpHeaders, type HttpHeadersInit, HttpHeadersSchema, type HttpHeadersSchemaName, type HttpHeadersSchemaTuple, type HttpHeadersSerialized, type HttpMethod, HttpMethodSchema, type HttpMethodWithRequestBody, type HttpMethodWithResponseBody, HttpMethodsSchema, HttpPathParamsSchema, type HttpPathParamsSerialized, type HttpRequest, type HttpRequestBodySchema, type HttpRequestHeadersSchema, HttpRequestSchema, type HttpRequestSearchParamsSchema, type HttpResponse, type HttpResponseBodySchema, type HttpResponseHeadersSchema, HttpResponseSchema, HttpResponseSchemaByStatusCode, type HttpResponseSchemaStatusCode, HttpSchema, type HttpSchemaMethod, HttpSchemaPath, HttpSearchParams, type HttpSearchParamsInit, HttpSearchParamsSchema, HttpSearchParamsSchemaName, type HttpSearchParamsSchemaTuple, type HttpSearchParamsSerialized, HttpStatusCode, type InferPathParams, type JSONSerialized, JSONValue, type LiteralHttpSchemaPathFromNonLiteral, type MergeHttpResponsesByStatusCode, type StrictFormData, type StrictHeaders, type StrictURLSearchParams };
|