@zimic/http 0.4.0-canary.1 → 0.4.0-canary.3
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 +1 -1
- 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 +85 -83
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/formData/HttpFormData.ts +34 -47
- package/src/formData/types.ts +36 -42
- package/src/headers/HttpHeaders.ts +32 -32
- package/src/pathParams/types.ts +29 -40
- package/src/searchParams/HttpSearchParams.ts +35 -35
- package/src/searchParams/types.ts +37 -43
- package/src/types/requests.ts +51 -5
package/README.md
CHANGED
|
@@ -144,7 +144,7 @@ Check our [getting started guide](https://github.com/zimicjs/zimic/wiki/getting
|
|
|
144
144
|
type UserListHeaders = Schema['/users']['GET']['request']['headers'];
|
|
145
145
|
|
|
146
146
|
const headers = new HttpHeaders<UserListHeaders>({
|
|
147
|
-
authorization: 'Bearer token',
|
|
147
|
+
authorization: 'Bearer my-token',
|
|
148
148
|
});
|
|
149
149
|
|
|
150
150
|
type UserListSearchParams = Schema['/users']['GET']['request']['searchParams'];
|
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 = "0.4.0-canary.
|
|
15
|
+
var version = "0.4.0-canary.3";
|
|
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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A,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.4.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.7.0\",\n \"picocolors\": \"^1.1.1\",\n \"yargs\": \"17.7.2\"\n },\n \"devDependencies\": {\n \"@types/js-yaml\": \"^4.0.9\",\n \"@types/node\": \"^22.15.3\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.1.2\",\n \"@vitest/coverage-istanbul\": \"^3.1.2\",\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.26.0\",\n \"execa\": \"9.5.2\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.52.0\",\n \"prettier\": \"^3.5.3\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.19.4\",\n \"typescript\": \"^5.8.3\",\n \"vitest\": \"^3.1.2\"\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"]}
|
|
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,CAA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;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.4.0-canary.3\",\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.7.0\",\n \"picocolors\": \"^1.1.1\",\n \"yargs\": \"17.7.2\"\n },\n \"devDependencies\": {\n \"@types/js-yaml\": \"^4.0.9\",\n \"@types/node\": \"^22.15.3\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.1.2\",\n \"@vitest/coverage-istanbul\": \"^3.1.2\",\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.26.0\",\n \"execa\": \"9.5.2\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.52.0\",\n \"prettier\": \"^3.5.3\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.19.4\",\n \"typescript\": \"^5.8.3\",\n \"vitest\": \"^3.1.2\"\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
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,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,G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A,cAAA,GACJ,GAAG,KAAM,CAAA,KAAA,CAAM,MAAM,IAAK,CAAA,QAAG,CAAC,CAAC,CAC5B,WAAA,EAAA,cAAA,GAAiB,MAAM,KAAM,CAAA,cAAc,IAAI,CAAM,GAAA,EAAA,KAAA,CAAM,OAAO,QAAQ,CAAC,CAAE,CAAA,CAAA,CAAA,EAAI,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.4.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.7.0\",\n \"picocolors\": \"^1.1.1\",\n \"yargs\": \"17.7.2\"\n },\n \"devDependencies\": {\n \"@types/js-yaml\": \"^4.0.9\",\n \"@types/node\": \"^22.15.3\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.1.2\",\n \"@vitest/coverage-istanbul\": \"^3.1.2\",\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.26.0\",\n \"execa\": \"9.5.2\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.52.0\",\n \"prettier\": \"^3.5.3\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.19.4\",\n \"typescript\": \"^5.8.3\",\n \"vitest\": \"^3.1.2\"\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"]}
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/utils/time.ts","../src/cli/cli.ts","../src/cli/index.ts"],"names":["yargs"],"mappings":";;;;;;;AAcE,IAAW,OAAA,GAAA,gBAAA;;;ACZb,eAAsB,iBAA6B,QAA6C,EAAA;AAC9F,EAAM,MAAA,uBAAA,GAA0B,YAAY,GAAI,EAAA;AAEhD,EAAM,MAAA,MAAA,GAAS,MAAM,QAAS,EAAA;AAE9B,EAAM,MAAA,qBAAA,GAAwB,YAAY,GAAI,EAAA;AAC9C,EAAA,MAAM,4BAA4B,qBAAwB,GAAA,uBAAA;AAE1D,EAAO,OAAA;AAAA,IACL,SAAW,EAAA,uBAAA;AAAA,IACX,WAAa,EAAA,yBAAA;AAAA,IACb,OAAS,EAAA,qBAAA;AAAA,IACT;AAAA,GACF;AACF;AAdsB,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA;AAgBf,SAAS,kBAAkB,yBAAmC,EAAA;AACnE,EAAA,IAAI,4BAA4B,GAAM,EAAA;AACpC,IAAA,OAAO,CAAG,EAAA,yBAAA,CAA0B,OAAQ,CAAA,CAAC,CAAC,CAAA,EAAA,CAAA;AAAA,GACzC,MAAA;AACL,IAAA,OAAO,CAAI,EAAA,CAAA,yBAAA,GAA4B,GAAM,EAAA,OAAA,CAAQ,CAAC,CAAC,CAAA,CAAA,CAAA;AAAA;AAE3D;AANgB,MAAA,CAAA,iBAAA,EAAA,mBAAA,CAAA;;;ACRhB,eAAe,MAAS,GAAA;AACtB,EAAA,MAAM,MAAM,OAAQ,CAAA,OAAA,CAAQ,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,IA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mB,MAAM,gBAAA,CAAiB,YAAY;AAC1D,UAAA,MAAM,gBAAyB,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,GAAG,KAAM,CAAA,KAAA,CAAM,MAAM,IAAK,CAAA,QAAG,CAAC,CAAC,CAC5B,WAAA,EAAA,cAAA,GAAiB,MAAM,KAAM,CAAA,cAAc,IAAI,CAAM,GAAA,EAAA,KAAA,CAAM,OAAO,QAAQ,CAAC,CAAE,CAAA,CAAA,CAAA,EAAI,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.4.0-canary.3\",\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.7.0\",\n \"picocolors\": \"^1.1.1\",\n \"yargs\": \"17.7.2\"\n },\n \"devDependencies\": {\n \"@types/js-yaml\": \"^4.0.9\",\n \"@types/node\": \"^22.15.3\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.1.2\",\n \"@vitest/coverage-istanbul\": \"^3.1.2\",\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.26.0\",\n \"execa\": \"9.5.2\",\n \"js-yaml\": \"^4.1.0\",\n \"playwright\": \"^1.52.0\",\n \"prettier\": \"^3.5.3\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.19.4\",\n \"typescript\": \"^5.8.3\",\n \"vitest\": \"^3.1.2\"\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
|
@@ -136,31 +136,29 @@ declare namespace HttpFormDataSchemaName {
|
|
|
136
136
|
* // "title" | "content"
|
|
137
137
|
*/
|
|
138
138
|
type HttpFormDataSchemaName<Schema extends HttpFormDataSchema> = IfNever<Schema, never, keyof Schema & string>;
|
|
139
|
-
type PrimitiveHttpFormDataSerialized<Type> = Type extends HttpFormDataSchema[string] ? Type : Type extends (infer ArrayItem)[] ? ArrayItem extends (infer _InternalArrayItem)[] ? never : PrimitiveHttpFormDataSerialized<ArrayItem>[] :
|
|
139
|
+
type PrimitiveHttpFormDataSerialized<Type> = [Type] extends [never] ? never : Type extends number ? `${number}` : Type extends boolean ? `${boolean}` : Type extends null ? 'null' : Type extends symbol ? never : Type extends HttpFormDataSchema[string] ? Type : Type extends (infer ArrayItem)[] ? ArrayItem extends (infer _InternalArrayItem)[] ? never : PrimitiveHttpFormDataSerialized<ArrayItem>[] : string;
|
|
140
140
|
/**
|
|
141
141
|
* Recursively converts a schema to its {@link https://developer.mozilla.org/docs/Web/API/FormData FormData}-serialized
|
|
142
|
-
* version. Numbers and
|
|
143
|
-
*
|
|
142
|
+
* version. Numbers, booleans, and null are converted to `${number}`, `${boolean}`, and 'null' respectively, and other
|
|
143
|
+
* values become strings.
|
|
144
144
|
*
|
|
145
145
|
* @example
|
|
146
146
|
* import { type HttpFormDataSerialized } from '@zimic/http';
|
|
147
147
|
*
|
|
148
148
|
* type Schema = HttpFormDataSerialized<{
|
|
149
|
-
* contentTitle: string
|
|
150
|
-
* contentSize: number;
|
|
149
|
+
* contentTitle: string;
|
|
150
|
+
* contentSize: number | null;
|
|
151
151
|
* content: Blob;
|
|
152
152
|
* full?: boolean;
|
|
153
|
-
* date: Date;
|
|
154
|
-
* method: () => void;
|
|
155
153
|
* }>;
|
|
156
154
|
* // {
|
|
157
|
-
* // contentTitle: string
|
|
158
|
-
* // contentSize? `${number}
|
|
155
|
+
* // contentTitle: string;
|
|
156
|
+
* // contentSize? `${number}` | 'null';
|
|
159
157
|
* // content: Blob;
|
|
160
158
|
* // full?: "false" | "true";
|
|
161
159
|
* // }
|
|
162
160
|
*/
|
|
163
|
-
type HttpFormDataSerialized<Type> = Type extends
|
|
161
|
+
type HttpFormDataSerialized<Type> = [Type] extends [never] ? never : Type extends HttpFormDataSchema ? Type : Type extends object ? {
|
|
164
162
|
[Key in keyof Type as IfNever<PrimitiveHttpFormDataSerialized<Type[Key]>, never, Key>]: PrimitiveHttpFormDataSerialized<Type[Key]>;
|
|
165
163
|
} : never;
|
|
166
164
|
|
|
@@ -190,13 +188,14 @@ type HttpFormDataSerialized<Type> = Type extends HttpFormDataSchema ? Type : Typ
|
|
|
190
188
|
*
|
|
191
189
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpformdata `HttpFormData` API reference}
|
|
192
190
|
*/
|
|
193
|
-
declare class HttpFormData<LooseSchema extends HttpFormDataSchema.Loose = HttpFormDataSchema.Loose
|
|
191
|
+
declare class HttpFormData<LooseSchema extends HttpFormDataSchema.Loose = HttpFormDataSchema.Loose> extends FormData {
|
|
192
|
+
readonly _schema: HttpFormDataSerialized<LooseSchema>;
|
|
194
193
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/set MDN Reference} */
|
|
195
|
-
set<Name extends HttpFormDataSchemaName<
|
|
196
|
-
set<Name extends HttpFormDataSchemaName<
|
|
194
|
+
set<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name, value: Exclude<ArrayItemIfArray<NonNullable<LooseSchema[Name]>>, Blob>): void;
|
|
195
|
+
set<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name, blob: Exclude<ArrayItemIfArray<NonNullable<LooseSchema[Name]>>, string>, fileName?: string): void;
|
|
197
196
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/append MDN Reference} */
|
|
198
|
-
append<Name extends HttpFormDataSchemaName<
|
|
199
|
-
append<Name extends HttpFormDataSchemaName<
|
|
197
|
+
append<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name, value: Exclude<ArrayItemIfArray<NonNullable<LooseSchema[Name]>>, Blob>): void;
|
|
198
|
+
append<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name, blob: Exclude<ArrayItemIfArray<NonNullable<LooseSchema[Name]>>, string>, fileName?: string): void;
|
|
200
199
|
/**
|
|
201
200
|
* Get the value of the entry associated to a key name.
|
|
202
201
|
*
|
|
@@ -206,7 +205,7 @@ declare class HttpFormData<LooseSchema extends HttpFormDataSchema.Loose = HttpFo
|
|
|
206
205
|
* @returns The value associated with the key name, or `null` if the key does not exist.
|
|
207
206
|
* @see {@link https://developer.mozilla.org/docs/Web/API/FormData/get MDN Reference}
|
|
208
207
|
*/
|
|
209
|
-
get<Name extends HttpFormDataSchemaName.NonArray<
|
|
208
|
+
get<Name extends HttpFormDataSchemaName.NonArray<this['_schema']>>(name: Name): ReplaceBy<ReplaceBy<ArrayItemIfArray<this['_schema'][Name]>, undefined, null>, Blob, File>;
|
|
210
209
|
/**
|
|
211
210
|
* Get all the values of the entry associated with a key name.
|
|
212
211
|
*
|
|
@@ -216,24 +215,24 @@ declare class HttpFormData<LooseSchema extends HttpFormDataSchema.Loose = HttpFo
|
|
|
216
215
|
* @returns An array of values associated with the key name, or an empty array if the key does not exist.
|
|
217
216
|
* @see {@link https://developer.mozilla.org/docs/Web/API/FormData/getAll MDN Reference}
|
|
218
217
|
*/
|
|
219
|
-
getAll<Name extends HttpFormDataSchemaName.Array<
|
|
218
|
+
getAll<Name extends HttpFormDataSchemaName.Array<this['_schema']>>(name: Name): ReplaceBy<ArrayItemIfArray<NonNullable<this['_schema'][Name]>>, Blob, File>[];
|
|
220
219
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/has MDN Reference} */
|
|
221
|
-
has<Name extends HttpFormDataSchemaName<
|
|
220
|
+
has<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name): boolean;
|
|
222
221
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/delete MDN Reference} */
|
|
223
|
-
delete<Name extends HttpFormDataSchemaName<
|
|
224
|
-
forEach<This extends HttpFormData<
|
|
222
|
+
delete<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name): void;
|
|
223
|
+
forEach<This extends HttpFormData<this['_schema']>>(callback: <Key extends HttpFormDataSchemaName<this['_schema']>>(value: ReplaceBy<ArrayItemIfArray<NonNullable<this['_schema'][Key]>>, Blob, File>, key: Key, parent: HttpFormData<this['_schema']>) => void, thisArg?: This): void;
|
|
225
224
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/keys MDN Reference} */
|
|
226
|
-
keys(): FormDataIterator<HttpFormDataSchemaName<
|
|
225
|
+
keys(): FormDataIterator<HttpFormDataSchemaName<this['_schema']>>;
|
|
227
226
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/values MDN Reference} */
|
|
228
|
-
values(): FormDataIterator<ReplaceBy<ArrayItemIfArray<NonNullable<
|
|
227
|
+
values(): FormDataIterator<ReplaceBy<ArrayItemIfArray<NonNullable<this['_schema'][HttpFormDataSchemaName<this['_schema']>]>>, Blob, File>>;
|
|
229
228
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/entries MDN Reference} */
|
|
230
229
|
entries(): FormDataIterator<[
|
|
231
|
-
HttpFormDataSchemaName<
|
|
232
|
-
ReplaceBy<ArrayItemIfArray<NonNullable<
|
|
230
|
+
HttpFormDataSchemaName<this['_schema']>,
|
|
231
|
+
ReplaceBy<ArrayItemIfArray<NonNullable<this['_schema'][HttpFormDataSchemaName<this['_schema']>]>>, Blob, File>
|
|
233
232
|
]>;
|
|
234
233
|
[Symbol.iterator](): FormDataIterator<[
|
|
235
|
-
HttpFormDataSchemaName<
|
|
236
|
-
ReplaceBy<ArrayItemIfArray<NonNullable<
|
|
234
|
+
HttpFormDataSchemaName<this['_schema']>,
|
|
235
|
+
ReplaceBy<ArrayItemIfArray<NonNullable<this['_schema'][HttpFormDataSchemaName<this['_schema']>]>>, Blob, File>
|
|
237
236
|
]>;
|
|
238
237
|
/**
|
|
239
238
|
* Checks if the data is equal to the other data. Equality is defined as having the same keys and values, regardless
|
|
@@ -277,7 +276,7 @@ declare class HttpFormData<LooseSchema extends HttpFormDataSchema.Loose = HttpFo
|
|
|
277
276
|
*
|
|
278
277
|
* @returns A plain object representation of this form data.
|
|
279
278
|
*/
|
|
280
|
-
toObject():
|
|
279
|
+
toObject(): this["_schema"];
|
|
281
280
|
}
|
|
282
281
|
|
|
283
282
|
interface HttpPathParamsSchema {
|
|
@@ -287,11 +286,10 @@ declare namespace HttpPathParamsSchema {
|
|
|
287
286
|
/** A schema for loose HTTP path parameters. Parameter values are not strictly typed. */
|
|
288
287
|
type Loose = Record<string, any>;
|
|
289
288
|
}
|
|
290
|
-
type PrimitiveHttpPathParamsSerialized<Type> = Type
|
|
289
|
+
type PrimitiveHttpPathParamsSerialized<Type> = [Type] extends [never] ? never : Type extends number ? `${number}` : Type extends boolean ? `${boolean}` : Type extends null ? 'null' : Type extends symbol ? never : Type extends HttpPathParamsSchema[string] ? Type : string;
|
|
291
290
|
/**
|
|
292
|
-
* Recursively converts a schema to its path parameters-serialized version. Numbers and
|
|
293
|
-
* `${number}
|
|
294
|
-
* functions and dates.
|
|
291
|
+
* Recursively converts a schema to its path parameters-serialized version. Numbers, booleans, and null are converted to
|
|
292
|
+
* `${number}`, `${boolean}`, and 'null' respectively, and other values become strings.
|
|
295
293
|
*
|
|
296
294
|
* @example
|
|
297
295
|
* import { type HttpPathParamsSerialized } from '@zimic/http';
|
|
@@ -300,16 +298,14 @@ type PrimitiveHttpPathParamsSerialized<Type> = Type extends HttpPathParamsSchema
|
|
|
300
298
|
* userId: string;
|
|
301
299
|
* notificationId: number | null;
|
|
302
300
|
* full?: boolean;
|
|
303
|
-
* from?: Date;
|
|
304
|
-
* method: () => void;
|
|
305
301
|
* }>;
|
|
306
302
|
* // {
|
|
307
303
|
* // userId: string;
|
|
308
|
-
* // notificationId: `${number}` |
|
|
304
|
+
* // notificationId: `${number}` | 'null';
|
|
309
305
|
* // full?: "false" | "true";
|
|
310
306
|
* // }
|
|
311
307
|
*/
|
|
312
|
-
type HttpPathParamsSerialized<Type> = Type extends
|
|
308
|
+
type HttpPathParamsSerialized<Type> = [Type] extends [never] ? never : Type extends HttpPathParamsSchema ? Type : Type extends object ? {
|
|
313
309
|
[Key in keyof Type as IfNever<PrimitiveHttpPathParamsSerialized<Type[Key]>, never, Key>]: PrimitiveHttpPathParamsSerialized<Type[Key]>;
|
|
314
310
|
} : never;
|
|
315
311
|
|
|
@@ -368,9 +364,6 @@ type HttpHeadersSerialized<Type> = HttpPathParamsSerialized<Type>;
|
|
|
368
364
|
* An extended HTTP headers object with a strictly-typed schema. Fully compatible with the built-in
|
|
369
365
|
* {@link https://developer.mozilla.org/docs/Web/API/Headers `Headers`} class.
|
|
370
366
|
*
|
|
371
|
-
* **IMPORTANT**: the input of `HttpHeaders` and all of its internal types must be declared inline or as a type aliases
|
|
372
|
-
* (`type`). They cannot be interfaces.
|
|
373
|
-
*
|
|
374
367
|
* @example
|
|
375
368
|
* import { HttpHeaders } from '@zimic/http';
|
|
376
369
|
*
|
|
@@ -387,33 +380,34 @@ type HttpHeadersSerialized<Type> = HttpPathParamsSerialized<Type>;
|
|
|
387
380
|
*
|
|
388
381
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpheaders `HttpHeaders` API reference}
|
|
389
382
|
*/
|
|
390
|
-
declare class HttpHeaders<LooseSchema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose
|
|
383
|
+
declare class HttpHeaders<LooseSchema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose> extends Headers {
|
|
384
|
+
readonly _schema: HttpHeadersSerialized<LooseSchema>;
|
|
391
385
|
constructor(init?: HttpHeadersInit<LooseSchema>);
|
|
392
386
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/set MDN Reference} */
|
|
393
|
-
set<Name extends HttpHeadersSchemaName<
|
|
387
|
+
set<Name extends HttpHeadersSchemaName<this['_schema']>>(name: Name, value: NonNullable<LooseSchema[Name]>): void;
|
|
394
388
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/append MDN Reference} */
|
|
395
|
-
append<Name extends HttpHeadersSchemaName<
|
|
389
|
+
append<Name extends HttpHeadersSchemaName<this['_schema']>>(name: Name, value: NonNullable<LooseSchema[Name]>): void;
|
|
396
390
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/get MDN Reference} */
|
|
397
|
-
get<Name extends HttpHeadersSchemaName<
|
|
391
|
+
get<Name extends HttpHeadersSchemaName<this['_schema']>>(name: Name): ReplaceBy<this['_schema'][Name], undefined, null>;
|
|
398
392
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/has MDN Reference} */
|
|
399
|
-
getSetCookie(): NonNullable<Default<
|
|
393
|
+
getSetCookie(): NonNullable<Default<this['_schema']['Set-Cookie'], string>>[];
|
|
400
394
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/has MDN Reference} */
|
|
401
|
-
has<Name extends HttpHeadersSchemaName<
|
|
395
|
+
has<Name extends HttpHeadersSchemaName<this['_schema']>>(name: Name): boolean;
|
|
402
396
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/delete MDN Reference} */
|
|
403
|
-
delete<Name extends HttpHeadersSchemaName<
|
|
404
|
-
forEach<This extends HttpHeaders<
|
|
397
|
+
delete<Name extends HttpHeadersSchemaName<this['_schema']>>(name: Name): void;
|
|
398
|
+
forEach<This extends HttpHeaders<this['_schema']>>(callback: <Key extends HttpHeadersSchemaName<this['_schema']>>(value: NonNullable<this['_schema'][Key]> & string, key: Key, parent: Headers) => void, thisArg?: This): void;
|
|
405
399
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/keys MDN Reference} */
|
|
406
|
-
keys(): HeadersIterator<HttpHeadersSchemaName<
|
|
400
|
+
keys(): HeadersIterator<HttpHeadersSchemaName<this['_schema']>>;
|
|
407
401
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/values MDN Reference} */
|
|
408
|
-
values(): HeadersIterator<NonNullable<
|
|
402
|
+
values(): HeadersIterator<NonNullable<this['_schema'][HttpHeadersSchemaName<this['_schema']>]> & string>;
|
|
409
403
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/entries MDN Reference} */
|
|
410
404
|
entries(): HeadersIterator<[
|
|
411
|
-
HttpHeadersSchemaName<
|
|
412
|
-
NonNullable<
|
|
405
|
+
HttpHeadersSchemaName<this['_schema']>,
|
|
406
|
+
NonNullable<this['_schema'][HttpHeadersSchemaName<this['_schema']>]> & string
|
|
413
407
|
]>;
|
|
414
408
|
[Symbol.iterator](): HeadersIterator<[
|
|
415
|
-
HttpHeadersSchemaName<
|
|
416
|
-
NonNullable<
|
|
409
|
+
HttpHeadersSchemaName<this['_schema']>,
|
|
410
|
+
NonNullable<this['_schema'][HttpHeadersSchemaName<this['_schema']>]> & string
|
|
417
411
|
]>;
|
|
418
412
|
/**
|
|
419
413
|
* Checks if this headers object is equal to another set of headers. Equality is defined as having the same keys and
|
|
@@ -445,7 +439,7 @@ declare class HttpHeaders<LooseSchema extends HttpHeadersSchema.Loose = HttpHead
|
|
|
445
439
|
*
|
|
446
440
|
* @returns A plain object representation of these headers.
|
|
447
441
|
*/
|
|
448
|
-
toObject():
|
|
442
|
+
toObject(): this['_schema'];
|
|
449
443
|
private splitHeaderValues;
|
|
450
444
|
}
|
|
451
445
|
|
|
@@ -502,30 +496,30 @@ declare namespace HttpSearchParamsSchemaName {
|
|
|
502
496
|
* // "page" | "perPage"
|
|
503
497
|
*/
|
|
504
498
|
type HttpSearchParamsSchemaName<Schema extends HttpSearchParamsSchema> = IfNever<Schema, never, keyof Schema & string>;
|
|
505
|
-
type PrimitiveHttpSearchParamsSerialized<Type> = Type extends
|
|
499
|
+
type PrimitiveHttpSearchParamsSerialized<Type> = [Type] extends [never] ? never : Type extends number ? `${number}` : Type extends boolean ? `${boolean}` : Type extends null ? 'null' : Type extends symbol ? never : Type extends HttpSearchParamsSchema[string] ? Type : Type extends (infer ArrayItem)[] ? ArrayItem extends (infer _InternalArrayItem)[] ? string : PrimitiveHttpSearchParamsSerialized<ArrayItem>[] : string;
|
|
506
500
|
/**
|
|
507
501
|
* Recursively converts a schema to its
|
|
508
|
-
* {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams URLSearchParams}-serialized version. Numbers
|
|
509
|
-
* booleans are converted to `${number}
|
|
510
|
-
*
|
|
502
|
+
* {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams URLSearchParams}-serialized version. Numbers,
|
|
503
|
+
* booleans, and null are converted to `${number}`, `${boolean}`, and 'null' respectively, and other values become
|
|
504
|
+
* strings.
|
|
511
505
|
*
|
|
512
506
|
* @example
|
|
513
507
|
* import { type HttpSearchParamsSerialized } from '@zimic/http';
|
|
514
508
|
*
|
|
515
509
|
* type Params = HttpSearchParamsSerialized<{
|
|
516
|
-
* query
|
|
510
|
+
* query?: string;
|
|
511
|
+
* order: 'asc' | 'desc' | null;
|
|
517
512
|
* page?: number;
|
|
518
513
|
* full?: boolean;
|
|
519
|
-
* date: Date;
|
|
520
|
-
* method: () => void;
|
|
521
514
|
* }>;
|
|
522
515
|
* // {
|
|
523
|
-
* // query
|
|
516
|
+
* // query?: string;
|
|
517
|
+
* // order: 'asc' | 'desc' | 'null';
|
|
524
518
|
* // page?: `${number}`;
|
|
525
519
|
* // full?: "false" | "true";
|
|
526
520
|
* // }
|
|
527
521
|
*/
|
|
528
|
-
type HttpSearchParamsSerialized<Type> = Type extends
|
|
522
|
+
type HttpSearchParamsSerialized<Type> = [Type] extends [never] ? never : Type extends HttpSearchParamsSchema ? Type : Type extends object ? {
|
|
529
523
|
[Key in keyof Type as IfNever<PrimitiveHttpSearchParamsSerialized<Type[Key]>, never, Key>]: PrimitiveHttpSearchParamsSerialized<Type[Key]>;
|
|
530
524
|
} : never;
|
|
531
525
|
|
|
@@ -533,9 +527,6 @@ type HttpSearchParamsSerialized<Type> = Type extends HttpSearchParamsSchema ? Ty
|
|
|
533
527
|
* An extended HTTP search params object with a strictly-typed schema. Fully compatible with the built-in
|
|
534
528
|
* {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams `URLSearchParams`} class.
|
|
535
529
|
*
|
|
536
|
-
* **IMPORTANT**: the input of `HttpSearchParams` and all of its internal types must be declared inline or as a type
|
|
537
|
-
* aliases (`type`). They cannot be interfaces.
|
|
538
|
-
*
|
|
539
530
|
* @example
|
|
540
531
|
* import { HttpSearchParams } from '@zimic/http';
|
|
541
532
|
*
|
|
@@ -555,13 +546,14 @@ type HttpSearchParamsSerialized<Type> = Type extends HttpSearchParamsSchema ? Ty
|
|
|
555
546
|
*
|
|
556
547
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpsearchparams `HttpSearchParams` API reference}
|
|
557
548
|
*/
|
|
558
|
-
declare class HttpSearchParams<LooseSchema extends HttpSearchParamsSchema.Loose = HttpSearchParamsSchema.Loose
|
|
549
|
+
declare class HttpSearchParams<LooseSchema extends HttpSearchParamsSchema.Loose = HttpSearchParamsSchema.Loose> extends URLSearchParams {
|
|
550
|
+
readonly _schema: HttpSearchParamsSerialized<LooseSchema>;
|
|
559
551
|
constructor(init?: HttpSearchParamsInit<LooseSchema>);
|
|
560
552
|
private populateInitArrayProperties;
|
|
561
553
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/set MDN Reference} */
|
|
562
|
-
set<Name extends HttpSearchParamsSchemaName<
|
|
554
|
+
set<Name extends HttpSearchParamsSchemaName<this['_schema']>>(name: Name, value: ArrayItemIfArray<NonNullable<LooseSchema[Name]>>): void;
|
|
563
555
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/append MDN Reference} */
|
|
564
|
-
append<Name extends HttpSearchParamsSchemaName<
|
|
556
|
+
append<Name extends HttpSearchParamsSchemaName<this['_schema']>>(name: Name, value: ArrayItemIfArray<NonNullable<LooseSchema[Name]>>): void;
|
|
565
557
|
/**
|
|
566
558
|
* Get the value of the entry associated to a key name.
|
|
567
559
|
*
|
|
@@ -571,7 +563,7 @@ declare class HttpSearchParams<LooseSchema extends HttpSearchParamsSchema.Loose
|
|
|
571
563
|
* @returns The value associated with the key name, or `null` if the key does not exist.
|
|
572
564
|
* @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/get MDN Reference}
|
|
573
565
|
*/
|
|
574
|
-
get<Name extends HttpSearchParamsSchemaName.NonArray<
|
|
566
|
+
get<Name extends HttpSearchParamsSchemaName.NonArray<this['_schema']>>(name: Name): ReplaceBy<ArrayItemIfArray<this['_schema'][Name]>, undefined, null>;
|
|
575
567
|
/**
|
|
576
568
|
* Get all the values of the entry associated with a key name.
|
|
577
569
|
*
|
|
@@ -581,24 +573,24 @@ declare class HttpSearchParams<LooseSchema extends HttpSearchParamsSchema.Loose
|
|
|
581
573
|
* @returns An array of values associated with the key name, or an empty array if the key does not exist.
|
|
582
574
|
* @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/getAll MDN Reference}
|
|
583
575
|
*/
|
|
584
|
-
getAll<Name extends HttpSearchParamsSchemaName.Array<
|
|
576
|
+
getAll<Name extends HttpSearchParamsSchemaName.Array<this['_schema']>>(name: Name): ArrayItemIfArray<NonNullable<this['_schema'][Name]>>[];
|
|
585
577
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/has MDN Reference} */
|
|
586
|
-
has<Name extends HttpSearchParamsSchemaName<
|
|
578
|
+
has<Name extends HttpSearchParamsSchemaName<this['_schema']>>(name: Name, value?: ArrayItemIfArray<NonNullable<LooseSchema[Name]>>): boolean;
|
|
587
579
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/delete MDN Reference} */
|
|
588
|
-
delete<Name extends HttpSearchParamsSchemaName<
|
|
589
|
-
forEach<This extends HttpSearchParams<
|
|
580
|
+
delete<Name extends HttpSearchParamsSchemaName<this['_schema']>>(name: Name, value?: ArrayItemIfArray<NonNullable<LooseSchema[Name]>>): void;
|
|
581
|
+
forEach<This extends HttpSearchParams<this['_schema']>>(callback: <Key extends HttpSearchParamsSchemaName<this['_schema']>>(value: ArrayItemIfArray<NonNullable<this['_schema'][Key]>>, key: Key, parent: HttpSearchParams<this['_schema']>) => void, thisArg?: This): void;
|
|
590
582
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/keys MDN Reference} */
|
|
591
|
-
keys(): URLSearchParamsIterator<HttpSearchParamsSchemaName<
|
|
583
|
+
keys(): URLSearchParamsIterator<HttpSearchParamsSchemaName<this['_schema']>>;
|
|
592
584
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/values MDN Reference} */
|
|
593
|
-
values(): URLSearchParamsIterator<ArrayItemIfArray<NonNullable<
|
|
585
|
+
values(): URLSearchParamsIterator<ArrayItemIfArray<NonNullable<this['_schema'][HttpSearchParamsSchemaName<this['_schema']>]>>>;
|
|
594
586
|
/** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/entries MDN Reference} */
|
|
595
587
|
entries(): URLSearchParamsIterator<[
|
|
596
|
-
HttpSearchParamsSchemaName<
|
|
597
|
-
ArrayItemIfArray<NonNullable<
|
|
588
|
+
HttpSearchParamsSchemaName<this['_schema']>,
|
|
589
|
+
ArrayItemIfArray<NonNullable<this['_schema'][HttpSearchParamsSchemaName<this['_schema']>]>>
|
|
598
590
|
]>;
|
|
599
591
|
[Symbol.iterator](): URLSearchParamsIterator<[
|
|
600
|
-
HttpSearchParamsSchemaName<
|
|
601
|
-
ArrayItemIfArray<NonNullable<
|
|
592
|
+
HttpSearchParamsSchemaName<this['_schema']>,
|
|
593
|
+
ArrayItemIfArray<NonNullable<this['_schema'][HttpSearchParamsSchemaName<this['_schema']>]>>
|
|
602
594
|
]>;
|
|
603
595
|
/**
|
|
604
596
|
* Checks if these search params are equal to another set of search parameters. Equality is defined as having the same
|
|
@@ -635,7 +627,7 @@ declare class HttpSearchParams<LooseSchema extends HttpSearchParamsSchema.Loose
|
|
|
635
627
|
*
|
|
636
628
|
* @returns A plain object representation of these search params.
|
|
637
629
|
*/
|
|
638
|
-
toObject():
|
|
630
|
+
toObject(): this["_schema"];
|
|
639
631
|
}
|
|
640
632
|
|
|
641
633
|
declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
|
|
@@ -1221,7 +1213,7 @@ interface HttpRequest<StrictBody extends HttpBody.Loose = HttpBody.Loose, Strict
|
|
|
1221
1213
|
* An HTTP response with a strictly-typed JSON body and status code. Fully compatible with the built-in
|
|
1222
1214
|
* {@link https://developer.mozilla.org/docs/Web/API/Response `Response`} class.
|
|
1223
1215
|
*/
|
|
1224
|
-
interface HttpResponse<StrictBody extends HttpBody.Loose = HttpBody.Loose,
|
|
1216
|
+
interface HttpResponse<StrictBody extends HttpBody.Loose = HttpBody.Loose, StrictHeadersSchema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose, StatusCode extends number = number> extends Response {
|
|
1225
1217
|
ok: StatusCode extends HttpStatusCode.Information | HttpStatusCode.Success | HttpStatusCode.Redirection ? true : false;
|
|
1226
1218
|
status: StatusCode;
|
|
1227
1219
|
headers: StrictHeaders<StrictHeadersSchema>;
|
|
@@ -1230,10 +1222,20 @@ interface HttpResponse<StrictBody extends HttpBody.Loose = HttpBody.Loose, Statu
|
|
|
1230
1222
|
formData: () => Promise<StrictBody extends HttpFormData<infer HttpFormDataSchema> ? StrictFormData<HttpFormDataSchema> : StrictBody extends HttpSearchParams<infer HttpSearchParamsSchema> ? StrictFormData<HttpSearchParamsSchema> : FormData>;
|
|
1231
1223
|
clone: () => this;
|
|
1232
1224
|
}
|
|
1233
|
-
type
|
|
1225
|
+
type HttpRequestHeadersSchemaFromBody<RequestSchema extends HttpRequestSchema, DefaultHeadersSchema> = 'body' extends keyof RequestSchema ? [RequestSchema['body']] extends [never] ? DefaultHeadersSchema : [Extract<RequestSchema['body'], BodyInit | HttpFormData | HttpSearchParams>] extends [never] ? 'headers' extends keyof RequestSchema ? [RequestSchema['headers']] extends [never] ? DefaultHeadersSchema : 'content-type' extends keyof Default<RequestSchema['headers']> ? DefaultHeadersSchema : {
|
|
1226
|
+
'content-type': 'application/json';
|
|
1227
|
+
} : {
|
|
1228
|
+
'content-type': 'application/json';
|
|
1229
|
+
} : DefaultHeadersSchema : DefaultHeadersSchema;
|
|
1230
|
+
type HttpRequestHeadersSchema<MethodSchema extends HttpMethodSchema> = 'headers' extends keyof MethodSchema['request'] ? [MethodSchema['request']['headers']] extends [never] ? HttpRequestHeadersSchemaFromBody<Default<MethodSchema['request']>, never> : (MethodSchema['request']['headers'] & HttpRequestHeadersSchemaFromBody<Default<MethodSchema['request']>, {}>) | Extract<MethodSchema['request']['headers'], undefined> : HttpRequestHeadersSchemaFromBody<Default<MethodSchema['request']>, never>;
|
|
1234
1231
|
type HttpRequestSearchParamsSchema<MethodSchema extends HttpMethodSchema> = 'searchParams' extends keyof MethodSchema['request'] ? Default<MethodSchema['request']>['searchParams'] : never;
|
|
1235
1232
|
type HttpRequestBodySchema<MethodSchema extends HttpMethodSchema> = ReplaceBy<ReplaceBy<IfNever<DefaultNoExclude<Default<MethodSchema['request']>['body']>, null>, undefined, null>, ArrayBuffer, Blob>;
|
|
1236
|
-
type
|
|
1233
|
+
type HttpResponseHeadersSchemaFromBody<ResponseSchema extends HttpResponseSchema, DefaultHeadersSchema> = 'body' extends keyof ResponseSchema ? [ResponseSchema['body']] extends [never] ? DefaultHeadersSchema : [Extract<ResponseSchema['body'], BodyInit | HttpSearchParams | HttpFormData>] extends [never] ? 'headers' extends keyof ResponseSchema ? [ResponseSchema['headers']] extends [never] ? DefaultHeadersSchema : 'content-type' extends keyof Default<ResponseSchema['headers']> ? DefaultHeadersSchema : {
|
|
1234
|
+
'content-type': 'application/json';
|
|
1235
|
+
} : {
|
|
1236
|
+
'content-type': 'application/json';
|
|
1237
|
+
} : DefaultHeadersSchema : DefaultHeadersSchema;
|
|
1238
|
+
type HttpResponseHeadersSchema<MethodSchema extends HttpMethodSchema, StatusCode extends HttpStatusCode> = 'headers' extends keyof Default<MethodSchema['response']>[StatusCode] ? [Default<MethodSchema['response']>[StatusCode]] extends [never] ? HttpResponseHeadersSchemaFromBody<Default<Default<MethodSchema['response']>[StatusCode]>, never> : (Default<Default<MethodSchema['response']>[StatusCode]>['headers'] & HttpResponseHeadersSchemaFromBody<Default<Default<MethodSchema['response']>[StatusCode]>, {}>) | Extract<Default<Default<MethodSchema['response']>[StatusCode]>['headers'], undefined> : HttpResponseHeadersSchemaFromBody<Default<Default<MethodSchema['response']>[StatusCode]>, never>;
|
|
1237
1239
|
type HttpResponseBodySchema<MethodSchema extends HttpMethodSchema, StatusCode extends HttpStatusCode> = ReplaceBy<ReplaceBy<IfNever<DefaultNoExclude<Default<Default<MethodSchema['response']>[StatusCode]>['body']>, null>, undefined, null>, ArrayBuffer, Blob>;
|
|
1238
1240
|
|
|
1239
1241
|
export { type AllowAnyStringInPathParams, HTTP_METHODS, HttpBody, HttpFormData, HttpFormDataSchema, HttpFormDataSchemaName, type HttpFormDataSerialized, HttpHeaders, type HttpHeadersInit, HttpHeadersSchema, type HttpHeadersSchemaName, type HttpHeadersSchemaTuple, type HttpHeadersSerialized, type HttpMethod, type HttpMethodSchema, type HttpMethodsSchema, HttpPathParamsSchema, type HttpPathParamsSerialized, type HttpRequest, type HttpRequestBodySchema, type HttpRequestHeadersSchema, type HttpRequestSchema, type HttpRequestSearchParamsSchema, type HttpResponse, type HttpResponseBodySchema, type HttpResponseHeadersSchema, type HttpResponseSchema, type 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 };
|
package/dist/index.js
CHANGED
|
@@ -69,6 +69,7 @@ var HttpFormData = class extends FormData {
|
|
|
69
69
|
static {
|
|
70
70
|
__name(this, "HttpFormData");
|
|
71
71
|
}
|
|
72
|
+
_schema;
|
|
72
73
|
set(name, blobOrValue, fileName) {
|
|
73
74
|
if (fileName === void 0) {
|
|
74
75
|
super.set(name, blobOrValue);
|
|
@@ -238,6 +239,7 @@ var HttpHeaders = class extends Headers {
|
|
|
238
239
|
static {
|
|
239
240
|
__name(this, "HttpHeaders");
|
|
240
241
|
}
|
|
242
|
+
_schema;
|
|
241
243
|
constructor(init) {
|
|
242
244
|
if (init instanceof Headers || Array.isArray(init) || !init) {
|
|
243
245
|
super(init);
|
|
@@ -378,6 +380,7 @@ var HttpSearchParams = class extends URLSearchParams {
|
|
|
378
380
|
static {
|
|
379
381
|
__name(this, "HttpSearchParams");
|
|
380
382
|
}
|
|
383
|
+
_schema;
|
|
381
384
|
constructor(init) {
|
|
382
385
|
if (init instanceof URLSearchParams || Array.isArray(init) || typeof init === "string" || !init) {
|
|
383
386
|
super(init);
|