@zimic/http 1.2.2-canary.1 → 1.3.0-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 +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +90 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/formData/HttpFormData.ts +39 -20
- package/src/headers/HttpHeaders.ts +31 -14
- package/src/searchParams/HttpSearchParams.ts +36 -17
package/dist/cli.js
CHANGED
|
@@ -12,7 +12,7 @@ var color__default = /*#__PURE__*/_interopDefault(color);
|
|
|
12
12
|
var yargs__default = /*#__PURE__*/_interopDefault(yargs);
|
|
13
13
|
|
|
14
14
|
// package.json
|
|
15
|
-
var version = "1.
|
|
15
|
+
var version = "1.3.0-canary.0";
|
|
16
16
|
|
|
17
17
|
// src/utils/time.ts
|
|
18
18
|
async function usingElapsedTime(callback) {
|
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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A,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.2.2-canary.1\",\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:setup-playwright\": \"playwright install chromium\",\n \"deps:setup\": \"pnpm deps:setup-playwright\"\n },\n \"dependencies\": {\n \"openapi-typescript\": \"7.10.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.7.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.37.0\",\n \"execa\": \"9.6.0\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.56.0\",\n \"prettier\": \"^3.6.2\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.20.6\",\n \"typescript\": \"^5.9.3\",\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,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,cAA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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.3.0-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:setup-playwright\": \"playwright install chromium\",\n \"deps:setup\": \"pnpm deps:setup-playwright\"\n },\n \"dependencies\": {\n \"openapi-typescript\": \"7.10.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.8.1\",\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.38.0\",\n \"execa\": \"9.6.0\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.56.1\",\n \"prettier\": \"^3.6.2\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.20.6\",\n \"typescript\": \"^5.9.3\",\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
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,M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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.2.2-canary.1\",\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:setup-playwright\": \"playwright install chromium\",\n \"deps:setup\": \"pnpm deps:setup-playwright\"\n },\n \"dependencies\": {\n \"openapi-typescript\": \"7.10.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.7.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.37.0\",\n \"execa\": \"9.6.0\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.56.0\",\n \"prettier\": \"^3.6.2\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.20.6\",\n \"typescript\": \"^5.9.3\",\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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C,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.3.0-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:setup-playwright\": \"playwright install chromium\",\n \"deps:setup\": \"pnpm deps:setup-playwright\"\n },\n \"dependencies\": {\n \"openapi-typescript\": \"7.10.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.8.1\",\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.38.0\",\n \"execa\": \"9.6.0\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.56.1\",\n \"prettier\": \"^3.6.2\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.20.6\",\n \"typescript\": \"^5.9.3\",\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/index.d.ts
CHANGED
|
@@ -198,6 +198,8 @@ declare class HttpFormData<LooseSchema extends HttpFormDataSchema.Loose = HttpFo
|
|
|
198
198
|
equals<OtherSchema extends LooseSchema>(otherData: HttpFormData<OtherSchema>): Promise<boolean>;
|
|
199
199
|
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdatacontains `formData.contains()` API reference} */
|
|
200
200
|
contains<OtherSchema extends LooseSchema>(otherData: HttpFormData<OtherSchema>): Promise<boolean>;
|
|
201
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdataassign `formData.assign()` API reference} */
|
|
202
|
+
assign<OtherSchema extends LooseSchema>(...otherDataArray: HttpFormData<OtherSchema>[]): void;
|
|
201
203
|
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdatatoobject `formData.toObject()` API reference} */
|
|
202
204
|
toObject(): this["_schema"];
|
|
203
205
|
}
|
|
@@ -318,6 +320,8 @@ declare class HttpHeaders<LooseSchema extends HttpHeadersSchema.Loose = HttpHead
|
|
|
318
320
|
equals<OtherSchema extends LooseSchema>(otherHeaders: HttpHeaders<OtherSchema>): boolean;
|
|
319
321
|
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headerscontains `headers.contains()` API reference} */
|
|
320
322
|
contains<OtherSchema extends LooseSchema>(otherHeaders: HttpHeaders<OtherSchema>): boolean;
|
|
323
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headersassign `headers.assign()` API reference} */
|
|
324
|
+
assign<OtherSchema extends LooseSchema>(...otherHeadersArray: HttpHeaders<OtherSchema>[]): void;
|
|
321
325
|
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headerstoobject `headers.toObject()` API reference} */
|
|
322
326
|
toObject(): this['_schema'];
|
|
323
327
|
private splitHeaderValues;
|
|
@@ -436,6 +440,8 @@ declare class HttpSearchParams<LooseSchema extends HttpSearchParamsSchema.Loose
|
|
|
436
440
|
equals<OtherSchema extends LooseSchema>(otherParams: HttpSearchParams<OtherSchema>): boolean;
|
|
437
441
|
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamscontains `searchParams.contains()` API reference} */
|
|
438
442
|
contains<OtherSchema extends LooseSchema>(otherParams: HttpSearchParams<OtherSchema>): boolean;
|
|
443
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamsassign `searchParams.assign()` API reference} */
|
|
444
|
+
assign<OtherSchema extends LooseSchema>(...otherParamsArray: HttpSearchParams<OtherSchema>[]): void;
|
|
439
445
|
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamstoobject `searchParams.toObject()` API reference} */
|
|
440
446
|
toObject(): this["_schema"];
|
|
441
447
|
}
|
package/dist/index.js
CHANGED
|
@@ -118,9 +118,8 @@ var HttpFormData = class extends FormData {
|
|
|
118
118
|
if (!await this.contains(otherData)) {
|
|
119
119
|
return false;
|
|
120
120
|
}
|
|
121
|
-
for (const
|
|
122
|
-
|
|
123
|
-
if (!otherHasKey) {
|
|
121
|
+
for (const fieldName of this.keys()) {
|
|
122
|
+
if (!super.has.call(otherData, fieldName)) {
|
|
124
123
|
return false;
|
|
125
124
|
}
|
|
126
125
|
}
|
|
@@ -128,38 +127,52 @@ var HttpFormData = class extends FormData {
|
|
|
128
127
|
}
|
|
129
128
|
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdatacontains `formData.contains()` API reference} */
|
|
130
129
|
async contains(otherData) {
|
|
131
|
-
for (const [
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
if (!
|
|
130
|
+
for (const [otherFieldName, otherFieldValue] of otherData.entries()) {
|
|
131
|
+
const fieldValues = super.getAll.call(this, otherFieldName);
|
|
132
|
+
const haveSameNumberOfFieldValues = fieldValues.length === super.getAll.call(otherData, otherFieldName).length;
|
|
133
|
+
if (!haveSameNumberOfFieldValues) {
|
|
135
134
|
return false;
|
|
136
135
|
}
|
|
137
|
-
let
|
|
138
|
-
for (const
|
|
139
|
-
if (
|
|
140
|
-
|
|
136
|
+
let fieldValueExists = false;
|
|
137
|
+
for (const fieldValue of fieldValues) {
|
|
138
|
+
if (fieldValue === otherFieldValue || fieldValue instanceof Blob && otherFieldValue instanceof Blob && await fileEquals_default(fieldValue, otherFieldValue)) {
|
|
139
|
+
fieldValueExists = true;
|
|
141
140
|
break;
|
|
142
141
|
}
|
|
143
142
|
}
|
|
144
|
-
if (!
|
|
143
|
+
if (!fieldValueExists) {
|
|
145
144
|
return false;
|
|
146
145
|
}
|
|
147
146
|
}
|
|
148
147
|
return true;
|
|
149
148
|
}
|
|
149
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdataassign `formData.assign()` API reference} */
|
|
150
|
+
assign(...otherDataArray) {
|
|
151
|
+
for (const otherData of otherDataArray) {
|
|
152
|
+
if (this === otherData) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
for (const fieldName of otherData.keys()) {
|
|
156
|
+
super.delete(fieldName);
|
|
157
|
+
}
|
|
158
|
+
for (const [fieldName, fieldValue] of otherData.entries()) {
|
|
159
|
+
super.append(fieldName, fieldValue);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
150
163
|
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdatatoobject `formData.toObject()` API reference} */
|
|
151
164
|
toObject() {
|
|
152
165
|
const object = {};
|
|
153
|
-
for (const [
|
|
154
|
-
if (
|
|
155
|
-
const
|
|
156
|
-
if (Array.isArray(
|
|
157
|
-
|
|
166
|
+
for (const [fieldName, fieldValue] of this.entries()) {
|
|
167
|
+
if (fieldName in object) {
|
|
168
|
+
const existingFieldValue = object[fieldName];
|
|
169
|
+
if (Array.isArray(existingFieldValue)) {
|
|
170
|
+
existingFieldValue.push(fieldValue);
|
|
158
171
|
} else {
|
|
159
|
-
object[
|
|
172
|
+
object[fieldName] = [existingFieldValue, fieldValue];
|
|
160
173
|
}
|
|
161
174
|
} else {
|
|
162
|
-
object[
|
|
175
|
+
object[fieldName] = fieldValue;
|
|
163
176
|
}
|
|
164
177
|
}
|
|
165
178
|
return object;
|
|
@@ -233,9 +246,8 @@ var HttpHeaders = class extends Headers {
|
|
|
233
246
|
if (!this.contains(otherHeaders)) {
|
|
234
247
|
return false;
|
|
235
248
|
}
|
|
236
|
-
for (const
|
|
237
|
-
|
|
238
|
-
if (!otherHasKey) {
|
|
249
|
+
for (const headerName of this.keys()) {
|
|
250
|
+
if (!super.has.call(otherHeaders, headerName)) {
|
|
239
251
|
return false;
|
|
240
252
|
}
|
|
241
253
|
}
|
|
@@ -243,30 +255,44 @@ var HttpHeaders = class extends Headers {
|
|
|
243
255
|
}
|
|
244
256
|
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headerscontains `headers.contains()` API reference} */
|
|
245
257
|
contains(otherHeaders) {
|
|
246
|
-
for (const [
|
|
247
|
-
const
|
|
248
|
-
if (
|
|
258
|
+
for (const [headerName, otherHeaderValue] of otherHeaders.entries()) {
|
|
259
|
+
const headerValue = super.get.call(this, headerName);
|
|
260
|
+
if (headerValue === null) {
|
|
249
261
|
return false;
|
|
250
262
|
}
|
|
251
|
-
const
|
|
252
|
-
const
|
|
253
|
-
const
|
|
254
|
-
if (!
|
|
263
|
+
const headerValueItems = this.splitHeaderValues(headerValue);
|
|
264
|
+
const otherHeaderValueItems = this.splitHeaderValues(otherHeaderValue);
|
|
265
|
+
const haveSameNumberOfHeaderValues = headerValueItems.length === otherHeaderValueItems.length;
|
|
266
|
+
if (!haveSameNumberOfHeaderValues) {
|
|
255
267
|
return false;
|
|
256
268
|
}
|
|
257
|
-
for (const otherValueItem of
|
|
258
|
-
if (!
|
|
269
|
+
for (const otherValueItem of otherHeaderValueItems) {
|
|
270
|
+
if (!headerValueItems.includes(otherValueItem)) {
|
|
259
271
|
return false;
|
|
260
272
|
}
|
|
261
273
|
}
|
|
262
274
|
}
|
|
263
275
|
return true;
|
|
264
276
|
}
|
|
277
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headersassign `headers.assign()` API reference} */
|
|
278
|
+
assign(...otherHeadersArray) {
|
|
279
|
+
for (const otherHeaders of otherHeadersArray) {
|
|
280
|
+
if (this === otherHeaders) {
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
for (const headerName of otherHeaders.keys()) {
|
|
284
|
+
super.delete(headerName);
|
|
285
|
+
}
|
|
286
|
+
for (const [headerName, headerValue] of otherHeaders.entries()) {
|
|
287
|
+
super.append(headerName, headerValue);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
265
291
|
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headerstoobject `headers.toObject()` API reference} */
|
|
266
292
|
toObject() {
|
|
267
293
|
const object = {};
|
|
268
|
-
for (const [
|
|
269
|
-
object[
|
|
294
|
+
for (const [headerName, headerValue] of this.entries()) {
|
|
295
|
+
object[headerName] = headerValue;
|
|
270
296
|
}
|
|
271
297
|
return object;
|
|
272
298
|
}
|
|
@@ -300,10 +326,10 @@ var HttpSearchParams = class extends URLSearchParams {
|
|
|
300
326
|
}
|
|
301
327
|
}
|
|
302
328
|
populateInitArrayProperties(init) {
|
|
303
|
-
for (const [
|
|
304
|
-
if (Array.isArray(
|
|
305
|
-
for (const
|
|
306
|
-
super.append(
|
|
329
|
+
for (const [paramName, paramValues] of Object.entries(init)) {
|
|
330
|
+
if (Array.isArray(paramValues)) {
|
|
331
|
+
for (const paramValue of paramValues) {
|
|
332
|
+
super.append(paramName, String(paramValue));
|
|
307
333
|
}
|
|
308
334
|
}
|
|
309
335
|
}
|
|
@@ -357,32 +383,46 @@ var HttpSearchParams = class extends URLSearchParams {
|
|
|
357
383
|
}
|
|
358
384
|
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamscontains `searchParams.contains()` API reference} */
|
|
359
385
|
contains(otherParams) {
|
|
360
|
-
for (const [
|
|
361
|
-
const
|
|
362
|
-
const
|
|
363
|
-
if (!
|
|
386
|
+
for (const [paramName, otherParamValue] of otherParams.entries()) {
|
|
387
|
+
const paramValues = super.getAll.call(this, paramName);
|
|
388
|
+
const haveSameNumberOfParamValues = paramValues.length === super.getAll.call(otherParams, paramName).length;
|
|
389
|
+
if (!haveSameNumberOfParamValues) {
|
|
364
390
|
return false;
|
|
365
391
|
}
|
|
366
|
-
const
|
|
367
|
-
if (!
|
|
392
|
+
const paramValueExists = paramValues.includes(otherParamValue);
|
|
393
|
+
if (!paramValueExists) {
|
|
368
394
|
return false;
|
|
369
395
|
}
|
|
370
396
|
}
|
|
371
397
|
return true;
|
|
372
398
|
}
|
|
399
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamsassign `searchParams.assign()` API reference} */
|
|
400
|
+
assign(...otherParamsArray) {
|
|
401
|
+
for (const otherParams of otherParamsArray) {
|
|
402
|
+
if (this === otherParams) {
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
for (const paramName of otherParams.keys()) {
|
|
406
|
+
super.delete(paramName);
|
|
407
|
+
}
|
|
408
|
+
for (const [paramName, paramValue] of otherParams.entries()) {
|
|
409
|
+
super.append(paramName, paramValue);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
373
413
|
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamstoobject `searchParams.toObject()` API reference} */
|
|
374
414
|
toObject() {
|
|
375
415
|
const object = {};
|
|
376
|
-
for (const [
|
|
377
|
-
if (
|
|
378
|
-
const
|
|
379
|
-
if (Array.isArray(
|
|
380
|
-
|
|
416
|
+
for (const [paramName, paramValue] of this.entries()) {
|
|
417
|
+
if (paramName in object) {
|
|
418
|
+
const existingParamValue = object[paramName];
|
|
419
|
+
if (Array.isArray(existingParamValue)) {
|
|
420
|
+
existingParamValue.push(paramValue);
|
|
381
421
|
} else {
|
|
382
|
-
object[
|
|
422
|
+
object[paramName] = [existingParamValue, paramValue];
|
|
383
423
|
}
|
|
384
424
|
} else {
|
|
385
|
-
object[
|
|
425
|
+
object[paramName] = paramValue;
|
|
386
426
|
}
|
|
387
427
|
}
|
|
388
428
|
return object;
|