@orval/fetch 8.11.0 → 8.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +6 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GetterPropType, camel, generateBodyOptions, generateFormDataAndUrlEncodedFunction, generateVerbImports, isObject, pascal, resolveRef, stringify, toObjectString } from "@orval/core";
|
|
1
|
+
import { GetterPropType, camel, generateBodyOptions, generateFormDataAndUrlEncodedFunction, generateVerbImports, isObject, makeRouteSafe, pascal, resolveRef, stringify, toObjectString } from "@orval/core";
|
|
2
2
|
//#region src/index.ts
|
|
3
3
|
const WILDCARD_STATUS_CODE_REGEX = /^[1-5]XX$/i;
|
|
4
4
|
const resolveSchemaRef = (schema, context) => resolveRef(schema, context);
|
|
@@ -15,7 +15,9 @@ const FETCH_DEPENDENCIES = [{
|
|
|
15
15
|
dependency: "zod"
|
|
16
16
|
}];
|
|
17
17
|
const getFetchDependencies = () => FETCH_DEPENDENCIES;
|
|
18
|
-
const generateRequestFunction = ({ queryParams, headers, operationName, response, mutator, body, props, verb, fetchReviver, formData, formUrlEncoded, override, doc }, { route, context, pathRoute }) => {
|
|
18
|
+
const generateRequestFunction = ({ queryParams, headers, operationName, response, mutator, body, props, verb, fetchReviver, formData, formUrlEncoded, override, doc }, { route: _route, context, pathRoute }) => {
|
|
19
|
+
let route = _route;
|
|
20
|
+
if (context.output.urlEncodeParameters) route = makeRouteSafe(route);
|
|
19
21
|
const isRequestOptions = override.requestOptions !== false;
|
|
20
22
|
const isFormData = !override.formData.disabled;
|
|
21
23
|
const isFormUrlEncoded = override.formUrlEncoded !== false;
|
|
@@ -42,7 +44,7 @@ const generateRequestFunction = ({ queryParams, headers, operationName, response
|
|
|
42
44
|
|
|
43
45
|
if (Array.isArray(value) && explodeParameters.includes(key)) {
|
|
44
46
|
value.forEach((v) => {
|
|
45
|
-
normalizedParams.append(key, v === null ? 'null' : ${hasExplodedDateParams ? "v instanceof Date ? v.toISOString() : " : ""}v
|
|
47
|
+
normalizedParams.append(key, v === null ? 'null' : ${hasExplodedDateParams ? "v instanceof Date ? v.toISOString() : " : ""}String(v));
|
|
46
48
|
});
|
|
47
49
|
return;
|
|
48
50
|
}
|
|
@@ -53,7 +55,7 @@ const generateRequestFunction = ({ queryParams, headers, operationName, response
|
|
|
53
55
|
if (!parameter.schema) return false;
|
|
54
56
|
const { schema } = resolveSchemaRef(parameter.schema, context);
|
|
55
57
|
return schema.format === "date-time";
|
|
56
|
-
}) ? "value instanceof Date ? value.toISOString() : " : ""}value
|
|
58
|
+
}) ? "value instanceof Date ? value.toISOString() : " : ""}String(value))
|
|
57
59
|
}`;
|
|
58
60
|
const getUrlFnImplementation = `export const ${getUrlFnName} = (${getUrlFnProps}) => {
|
|
59
61
|
${queryParams ? ` const normalizedParams = new URLSearchParams();
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n camel,\n type ClientBuilder,\n type ClientGeneratorsBuilder,\n type ClientHeaderBuilder,\n generateBodyOptions,\n generateFormDataAndUrlEncodedFunction,\n generateVerbImports,\n type GeneratorDependency,\n type GeneratorOptions,\n type GeneratorVerbOptions,\n GetterPropType,\n isObject,\n type OpenApiParameterObject,\n type OpenApiReferenceObject,\n type OpenApiSchemaObject,\n pascal,\n resolveRef,\n stringify,\n toObjectString,\n} from '@orval/core';\n\nconst WILDCARD_STATUS_CODE_REGEX = /^[1-5]XX$/i;\nconst resolveSchemaRef = (\n schema: OpenApiSchemaObject | OpenApiReferenceObject,\n context: GeneratorOptions['context'],\n) =>\n resolveRef(schema, context) as {\n schema: OpenApiSchemaObject;\n };\n\nconst getStatusCodeType = (key: string): string => {\n if (WILDCARD_STATUS_CODE_REGEX.test(key)) {\n const prefix = key[0];\n return `HTTPStatusCode${prefix}xx`;\n }\n return key;\n};\n\nconst FETCH_DEPENDENCIES: GeneratorDependency[] = [\n {\n exports: [\n {\n name: 'z',\n alias: 'zod',\n values: true,\n },\n ],\n dependency: 'zod',\n },\n];\n\nexport const getFetchDependencies = () => FETCH_DEPENDENCIES;\n\nexport const generateRequestFunction = (\n {\n queryParams,\n headers,\n operationName,\n response,\n mutator,\n body,\n props,\n verb,\n fetchReviver,\n formData,\n formUrlEncoded,\n override,\n doc,\n }: GeneratorVerbOptions,\n { route, context, pathRoute }: GeneratorOptions,\n) => {\n const isRequestOptions = override.requestOptions !== false;\n const isFormData = !override.formData.disabled;\n const isFormUrlEncoded = override.formUrlEncoded !== false;\n\n const getUrlFnName = camel(`get-${operationName}-url`);\n const getUrlFnProps = toObjectString(\n props.filter(\n (prop) =>\n prop.type === GetterPropType.PARAM ||\n prop.type === GetterPropType.NAMED_PATH_PARAMS ||\n prop.type === GetterPropType.QUERY_PARAM,\n ),\n 'implementation',\n );\n\n const spec = context.spec.paths?.[pathRoute];\n const parameters = spec?.[verb]?.parameters ?? [];\n const parameterObjects = parameters.map((parameter) => {\n const { schema } = resolveRef(parameter, context);\n return schema as OpenApiParameterObject;\n });\n\n const explodeParameters = parameterObjects.filter((parameterObject) => {\n if (!parameterObject.schema) {\n return false;\n }\n\n const { schema: schemaObject } = resolveSchemaRef(\n parameterObject.schema,\n context,\n );\n\n const isArrayLike =\n schemaObject.type === 'array' ||\n (\n (schemaObject.oneOf as\n | (OpenApiSchemaObject | OpenApiReferenceObject)[]\n | undefined) ?? []\n ).some((s) => resolveSchemaRef(s, context).schema.type === 'array') ||\n (\n (schemaObject.anyOf as\n | (OpenApiSchemaObject | OpenApiReferenceObject)[]\n | undefined) ?? []\n ).some((s) => resolveSchemaRef(s, context).schema.type === 'array') ||\n (\n (schemaObject.allOf as\n | (OpenApiSchemaObject | OpenApiReferenceObject)[]\n | undefined) ?? []\n ).some((s) => resolveSchemaRef(s, context).schema.type === 'array');\n\n return (\n parameterObject.in === 'query' && isArrayLike && parameterObject.explode\n );\n });\n\n const explodeParametersNames = explodeParameters.map(\n (parameter) => parameter.name,\n );\n const hasExplodedDateParams =\n context.output.override.useDates &&\n explodeParameters.some((parameter) => {\n if (!parameter.schema) {\n return false;\n }\n\n const { schema } = resolveSchemaRef(parameter.schema, context);\n return schema.format === 'date-time';\n });\n\n const explodeArrayImplementation =\n explodeParameters.length > 0\n ? `const explodeParameters = ${JSON.stringify(explodeParametersNames)};\n\n if (Array.isArray(value) && explodeParameters.includes(key)) {\n value.forEach((v) => {\n normalizedParams.append(key, v === null ? 'null' : ${hasExplodedDateParams ? 'v instanceof Date ? v.toISOString() : ' : ''}v.toString());\n });\n return;\n }\n `\n : '';\n\n const isExplodeParametersOnly =\n explodeParameters.length === parameters.length;\n\n const hasDateParams =\n context.output.override.useDates &&\n parameterObjects.some((parameter) => {\n if (!parameter.schema) {\n return false;\n }\n\n const { schema } = resolveSchemaRef(parameter.schema, context);\n return schema.format === 'date-time';\n });\n\n const normalParamsImplementation = `if (value !== undefined) {\n normalizedParams.append(key, value === null ? 'null' : ${hasDateParams ? 'value instanceof Date ? value.toISOString() : ' : ''}value.toString())\n }`;\n\n const getUrlFnImplementation = `export const ${getUrlFnName} = (${getUrlFnProps}) => {\n${\n queryParams\n ? ` const normalizedParams = new URLSearchParams();\n\n Object.entries(params || {}).forEach(([key, value]) => {\n ${explodeArrayImplementation}\n ${isExplodeParametersOnly ? '' : normalParamsImplementation}\n });`\n : ''\n}\n\n ${queryParams ? `const stringifiedParams = normalizedParams.toString();` : ``}\n\n ${\n queryParams\n ? `return stringifiedParams.length > 0 ? \\`${route}?\\${stringifiedParams}\\` : \\`${route}\\``\n : `return \\`${route}\\``\n }\n}\\n`;\n\n const isContentTypeNdJson = (contentType: string) =>\n contentType === 'application/nd-json' ||\n contentType === 'application/x-ndjson';\n\n const isContentTypeJson = (contentType: string) =>\n contentType.toLowerCase().includes('json');\n\n const isNdJson = response.contentTypes.some((contentType) =>\n isContentTypeNdJson(contentType),\n );\n const isBlob = response.isBlob;\n\n const successContentTypes = response.types.success\n .map((t) => t.contentType)\n .filter(Boolean);\n const errorContentTypes = response.types.errors\n .map((t) => t.contentType)\n .filter(Boolean);\n\n // Resolve parsing strategy at generation time based on spec-declared content types.\n // Only emit a runtime Content-Type check when responses have mixed types.\n //\n // When `forceSuccessResponse` is false the same parse block handles both 2xx\n // and error status codes, so its strategy must cover error content types too\n // (otherwise e.g. 200 application/json + 429 text/plain still JSON.parses text).\n const parseTimeContentTypes = override.fetch.forceSuccessResponse\n ? successContentTypes\n : [...successContentTypes, ...errorContentTypes];\n const successHasJson = parseTimeContentTypes.some((ct) =>\n isContentTypeJson(ct),\n );\n const successHasNonJson = parseTimeContentTypes.some(\n (ct) => !isContentTypeJson(ct),\n );\n const hasMixedSuccessContentTypes = successHasJson && successHasNonJson;\n // No declared content types → fall back to JSON (preserve original behaviour)\n const successAlwaysJson =\n parseTimeContentTypes.length === 0 ||\n (successHasJson && !successHasNonJson);\n\n const errorHasJson = errorContentTypes.some((ct) => isContentTypeJson(ct));\n const errorHasNonJson = errorContentTypes.some(\n (ct) => !isContentTypeJson(ct),\n );\n const hasMixedErrorContentTypes = errorHasJson && errorHasNonJson;\n const errorAlwaysJson =\n errorContentTypes.length === 0 || (errorHasJson && !errorHasNonJson);\n const responseTypeName = fetchResponseTypeName(\n override.fetch.includeHttpResponseReturnType,\n isNdJson ? 'Response' : response.definition.success,\n operationName,\n );\n\n const responseType = response.definition.success;\n const isVoidResponse = responseType === 'void';\n\n const isPrimitiveType = [\n 'string',\n 'number',\n 'boolean',\n 'void',\n 'unknown',\n ].includes(responseType);\n const hasSchema = response.imports.some((imp) => imp.name === responseType);\n\n const isValidateResponse =\n override.fetch.runtimeValidation &&\n !isPrimitiveType &&\n hasSchema &&\n !isNdJson;\n\n const allResponses = [...response.types.success, ...response.types.errors];\n if (allResponses.length === 0) {\n allResponses.push({\n contentType: '',\n hasReadonlyProps: false,\n imports: [],\n isEnum: false,\n isRef: false,\n key: 'default',\n schemas: [],\n type: 'unknown',\n value: 'unknown',\n dependencies: [],\n });\n }\n const nonDefaultStatuses = allResponses\n .filter((r) => r.key !== 'default')\n .map((r) => getStatusCodeType(r.key));\n const uniqueNonDefaultStatuses = [...new Set(nonDefaultStatuses)];\n const responseDataTypes = allResponses\n .map((r) =>\n allResponses.filter((r2) => r2.key === r.key).length > 1\n ? { ...r, suffix: pascal(r.contentType) }\n : r,\n )\n .map((r) => {\n const name = `${responseTypeName}${pascal(r.key)}${'suffix' in r ? r.suffix : ''}`;\n const dataType = r.value || 'unknown';\n\n return {\n name,\n success: response.types.success.some((s) => s.key === r.key),\n value: `export type ${name} = {\n ${isContentTypeNdJson(r.contentType) ? `stream: TypedResponse<${dataType}>` : `data: ${dataType}`}\n status: ${\n r.key === 'default'\n ? uniqueNonDefaultStatuses.length > 0\n ? `Exclude<HTTPStatusCodes, ${uniqueNonDefaultStatuses.join(' | ')}>`\n : 'number'\n : getStatusCodeType(r.key)\n }\n}`,\n };\n });\n\n const successName = `${responseTypeName}Success`;\n const errorName = `${responseTypeName}Error`;\n const hasSuccess = responseDataTypes.some((r) => r.success);\n const hasError = responseDataTypes.some((r) => !r.success);\n\n const responseTypeImplementation = override.fetch\n .includeHttpResponseReturnType\n ? `${responseDataTypes.map((r) => r.value).join('\\n\\n')}\n\n${\n hasSuccess\n ? `export type ${successName} = (${responseDataTypes\n .filter((r) => r.success)\n .map((r) => r.name)\n .join(' | ')}) & {\n headers: Headers;\n}`\n : ''\n};\n${\n hasError\n ? `export type ${errorName} = (${responseDataTypes\n .filter((r) => !r.success)\n .map((r) => r.name)\n .join(' | ')}) & {\n headers: Headers;\n}`\n : ''\n};\n\n${override.fetch.forceSuccessResponse && hasSuccess ? '' : `export type ${responseTypeName} = (${hasError && hasSuccess ? `${successName} | ${errorName}` : hasSuccess ? successName : errorName})\\n\\n`}`\n : '';\n\n const getUrlFnProperties = props\n .filter(\n (prop) =>\n prop.type === GetterPropType.PARAM ||\n prop.type === GetterPropType.QUERY_PARAM ||\n prop.type === GetterPropType.NAMED_PATH_PARAMS,\n )\n .map((param) => {\n return param.type === GetterPropType.NAMED_PATH_PARAMS\n ? param.destructured\n : param.name;\n })\n .join(',');\n\n const useRuntimeFetcher = override.fetch.useRuntimeFetcher;\n const fetchFnParam =\n useRuntimeFetcher && isRequestOptions && !mutator\n ? ', fetchFn?: typeof globalThis.fetch'\n : '';\n const args = `${toObjectString(props, 'implementation')} ${isRequestOptions ? `options?: RequestInit` : ''}${fetchFnParam}`;\n const returnType =\n override.fetch.forceSuccessResponse && hasSuccess\n ? `Promise<${successName}>`\n : `Promise<${responseTypeName}>`;\n\n const fetchMethodOption = `method: '${verb.toUpperCase()}'`;\n const ignoreContentTypes = ['multipart/form-data'];\n const overrideHeaders =\n isObject(override.requestOptions) && override.requestOptions.headers\n ? Object.entries(override.requestOptions.headers).map(\n ([key, value]) => `'${key}': \\`${value}\\``,\n )\n : [];\n\n const headersToAdd: string[] = [\n ...(body.contentType && !ignoreContentTypes.includes(body.contentType)\n ? [`'Content-Type': '${body.contentType}'`]\n : []),\n ...(isNdJson && response.contentTypes.length === 1\n ? [\n `Accept: ${\n response.contentTypes[0] === 'application/x-ndjson'\n ? \"'application/x-ndjson'\"\n : \"'application/nd-json'\"\n }`,\n ]\n : []),\n ...overrideHeaders,\n ...(headers ? ['...headers'] : []),\n ];\n\n let globalFetchOptions;\n if (isObject(override.requestOptions)) {\n // If both requestOptions and fetchHeadersOptions will be adding a header, we must merge them to avoid multiple properties with the same name\n const shouldMergeFetchOptionHeaders =\n headersToAdd.length > 0 && 'headers' in override.requestOptions;\n const globalFetchOptionsObject = { ...override.requestOptions };\n if (shouldMergeFetchOptionHeaders && override.requestOptions.headers) {\n // Remove the headers from the object going into globalFetchOptions\n delete globalFetchOptionsObject.headers;\n // Add it to the dedicated headers object\n }\n globalFetchOptions = stringify(globalFetchOptionsObject)\n ?.slice(1, -1)\n .trim();\n } else {\n globalFetchOptions = '';\n }\n const fetchHeadersOption =\n headersToAdd.length > 0\n ? `headers: { ${headersToAdd.join(',')}, ...options?.headers }`\n : '';\n const requestBodyParams = generateBodyOptions(\n body,\n isFormData,\n isFormUrlEncoded,\n );\n const fetchBodyOption = requestBodyParams\n ? (isFormData && body.formData) ||\n (isFormUrlEncoded && body.formUrlEncoded) ||\n body.contentType === 'text/plain'\n ? `body: ${requestBodyParams}`\n : `body: JSON.stringify(${requestBodyParams})`\n : '';\n const fetchFnOptions = `${getUrlFnName}(${getUrlFnProperties}),\n {${globalFetchOptions ? '\\n' : ''} ${globalFetchOptions}\n ${isRequestOptions ? '...options,' : ''}\n ${fetchMethodOption}${fetchHeadersOption ? ',' : ''}\n ${fetchHeadersOption}${fetchBodyOption ? ',' : ''}\n ${fetchBodyOption}\n }\n`;\n const reviver = fetchReviver ? `, ${fetchReviver.name}` : '';\n const schemaValueRef =\n responseType === 'Error' ? 'ErrorSchema' : responseType;\n const fetchResponseType =\n override.fetch.forceSuccessResponse && hasSuccess\n ? successName\n : responseTypeName;\n\n // Error response fallback always uses {} — error data types vary (e.g. `Error`)\n // and {} satisfies them all without a type error, matching prior behaviour.\n // Use truthy `body` check before JSON.parse so empty string bodies fall back\n // instead of throwing (`JSON.parse('')` is invalid).\n const errorBodyExpression = hasMixedErrorContentTypes\n ? `errorBody ? (errorContentType.includes('json') ? JSON.parse(errorBody${reviver}) : errorBody) : {}`\n : errorAlwaysJson\n ? `errorBody ? JSON.parse(errorBody${reviver}) : {}`\n : `errorBody !== null ? errorBody : {}`;\n\n const throwOnErrorBodyExpression = hasMixedErrorContentTypes\n ? `body ? (errorContentType.includes('json') ? JSON.parse(body${reviver}) : body) : {}`\n : errorAlwaysJson\n ? `body ? JSON.parse(body${reviver}) : {}`\n : `body !== null ? body : ''`;\n\n const throwOnErrorDataExpression = isNdJson\n ? `body ? JSON.parse(body${reviver}) : {}`\n : isBlob\n ? errorBodyExpression\n : throwOnErrorBodyExpression;\n\n // In the forceSuccessResponse path, throwOnErrorImplementation is emitted AFTER\n // `contentType` and `body` are already declared in the outer scope, so we must\n // NOT redeclare them here.\n const throwOnErrorInnerDeclarations = isNdJson\n ? 'const body = [204, 205, 304].includes(stream.status) ? null : await stream.text();'\n : isBlob\n ? `const errorBody = [204, 205, 304].includes(res.status) ? null : await res.text();\n ${hasMixedErrorContentTypes ? `const errorContentType = (res.headers.get('content-type') ?? '').toLowerCase();` : ''}`\n : override.fetch.forceSuccessResponse\n ? hasMixedErrorContentTypes\n ? `const errorContentType = (res.headers.get('content-type') ?? '').toLowerCase();`\n : ''\n : hasMixedErrorContentTypes\n ? `const errorContentType = (res.headers.get('content-type') ?? '').toLowerCase();\n const body = [204, 205, 304].includes(res.status) ? null : await res.text();`\n : 'const body = [204, 205, 304].includes(res.status) ? null : await res.text();';\n\n const throwOnErrorImplementation = `if (!${isNdJson ? 'stream' : 'res'}.ok) {\n ${throwOnErrorInnerDeclarations}\n const err: globalThis.Error & {info?: ${hasError ? `${errorName}${override.fetch.includeHttpResponseReturnType ? \"['data']\" : ''}` : 'any'}, status?: number} = new globalThis.Error();\n const data ${hasError ? `: ${errorName}${override.fetch.includeHttpResponseReturnType ? `['data']` : ''}` : ''} = ${throwOnErrorDataExpression}\n err.info = data;\n err.status = ${isNdJson ? 'stream' : 'res'}.status;\n throw err;\n }`;\n const fetchFnCall =\n useRuntimeFetcher && isRequestOptions ? '(fetchFn ?? fetch)' : 'fetch';\n const blobFetchResponseImplementation = `const res = await ${fetchFnCall}(${fetchFnOptions})\n\n ${override.fetch.forceSuccessResponse ? throwOnErrorImplementation : ''}\n const body = [204, 205, 304].includes(res.status) ? null : await res.blob();\n const data: ${fetchResponseType}${override.fetch.includeHttpResponseReturnType ? `['data']` : ''} = body as ${fetchResponseType}${override.fetch.includeHttpResponseReturnType ? `['data']` : ''}\n ${\n override.fetch.includeHttpResponseReturnType\n ? `return { data, status: res.status, headers: res.headers } as ${fetchResponseType}`\n : 'return data'\n }\n`;\n const fetchResponseImplementation = isNdJson\n ? ` const stream = await ${fetchFnCall}(${fetchFnOptions});\n ${override.fetch.forceSuccessResponse ? throwOnErrorImplementation : ''}\n ${\n override.fetch.includeHttpResponseReturnType\n ? `return { status: stream.status, stream, headers: stream.headers } as ${fetchResponseType}`\n : `return stream`\n }\n `\n : isBlob\n ? blobFetchResponseImplementation\n : `const res = await ${fetchFnCall}(${fetchFnOptions})\n\n ${hasMixedSuccessContentTypes || (isValidateResponse && successAlwaysJson) ? `const contentType = (res.headers.get('content-type') ?? '').toLowerCase();` : ''}\n const body = [204, 205, 304].includes(res.status) ? null : await res.text();\n ${override.fetch.forceSuccessResponse ? throwOnErrorImplementation : ''}\n ${\n isValidateResponse\n ? hasMixedSuccessContentTypes\n ? `const parsedBody = body ? (contentType.includes('json') ? JSON.parse(body${reviver}) : body) : {}\n const data = contentType.includes('json') ? ${schemaValueRef}.parse(parsedBody) : parsedBody`\n : successAlwaysJson\n ? `const parsedBody = body ? (contentType.includes('json') ? JSON.parse(body${reviver}) : body) : {}\n const data = contentType.includes('json') ? ${schemaValueRef}.parse(parsedBody) : parsedBody`\n : `const parsedBody = body !== null ? body : ''\n const data = parsedBody`\n : hasMixedSuccessContentTypes\n ? `const data: ${fetchResponseType}${override.fetch.includeHttpResponseReturnType ? `['data']` : ''} = body ? (contentType.includes('json') ? JSON.parse(body${reviver}) : body) : ${isVoidResponse ? 'undefined' : '{}'}`\n : successAlwaysJson\n ? `const data: ${fetchResponseType}${override.fetch.includeHttpResponseReturnType ? `['data']` : ''} = body ? JSON.parse(body${reviver}) : ${isVoidResponse ? 'undefined' : '{}'}`\n : `const data: ${fetchResponseType}${override.fetch.includeHttpResponseReturnType ? `['data']` : ''} = body !== null ? body : ${isVoidResponse ? 'undefined' : \"''\"}`\n }\n ${\n override.fetch.includeHttpResponseReturnType\n ? `return { data, status: res.status, headers: res.headers } as ${fetchResponseType}`\n : 'return data'\n }\n`;\n let customFetchResponseImplementation = `return ${mutator?.name}<${fetchResponseType}>(${fetchFnOptions});`;\n\n const bodyForm = generateFormDataAndUrlEncodedFunction({\n formData,\n formUrlEncoded,\n body,\n isFormData,\n isFormUrlEncoded,\n });\n\n if (mutator?.isHook) {\n const hasDefaultName = !mutator.path.includes('#');\n const fetchExportName = hasDefaultName\n ? 'customFetcher'\n : mutator.path.split('#')[1];\n const formattedDeconstructor = hasDefaultName\n ? `customFetcher`\n : `{${fetchExportName}}`;\n customFetchResponseImplementation = `\n const ${formattedDeconstructor} = ${mutator.name}();\n return (${args}) => {\n ${bodyForm}\n return ${fetchExportName}(${fetchFnOptions});\n }\n `;\n }\n\n const fetchImplementationBody = mutator\n ? customFetchResponseImplementation\n : fetchResponseImplementation;\n\n let fetchImplementation = `export const ${operationName} = async (${args}): ${returnType} => {\n ${bodyForm ? ` ${bodyForm}` : ''}\n ${fetchImplementationBody}}\n `;\n if (mutator?.isHook) {\n fetchImplementation = `export const use${pascal(operationName)}Hook = (): (${args}) => ${returnType} => {\n ${fetchImplementationBody}}\n `;\n }\n\n return (\n responseTypeImplementation +\n `${getUrlFnImplementation}\\n` +\n `${doc}${fetchImplementation}\\n`\n );\n};\n\nexport const fetchResponseTypeName = (\n includeHttpResponseReturnType: boolean | undefined,\n definitionSuccessResponse: string,\n operationName: string,\n) => {\n return includeHttpResponseReturnType\n ? `${operationName}Response`\n : definitionSuccessResponse;\n};\n\nexport const generateClient: ClientBuilder = (verbOptions, options) => {\n const isZodOutput =\n typeof options.context.output.schemas === 'object' &&\n options.context.output.schemas.type === 'zod';\n const responseType = verbOptions.response.definition.success;\n const isPrimitiveResponse = [\n 'string',\n 'number',\n 'boolean',\n 'void',\n 'unknown',\n ].includes(responseType);\n const shouldUseRuntimeValidation =\n verbOptions.override.fetch.runtimeValidation && isZodOutput;\n\n const normalizedVerbOptions =\n shouldUseRuntimeValidation &&\n !isPrimitiveResponse &&\n verbOptions.response.imports.some((imp) => imp.name === responseType)\n ? {\n ...verbOptions,\n response: {\n ...verbOptions.response,\n imports: verbOptions.response.imports.map((imp) =>\n imp.name === responseType ? { ...imp, values: true } : imp,\n ),\n },\n }\n : verbOptions;\n\n const imports = generateVerbImports(normalizedVerbOptions);\n const functionImplementation = generateRequestFunction(\n normalizedVerbOptions,\n options,\n );\n\n return {\n implementation: `${functionImplementation}\\n`,\n imports,\n docComment: '',\n };\n};\n\nconst getHTTPStatusCodes = () => `\nexport type HTTPStatusCode1xx = 100 | 101 | 102 | 103;\nexport type HTTPStatusCode2xx = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207;\nexport type HTTPStatusCode3xx = 300 | 301 | 302 | 303 | 304 | 305 | 307 | 308;\nexport type HTTPStatusCode4xx = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 426 | 428 | 429 | 431 | 451;\nexport type HTTPStatusCode5xx = 500 | 501 | 502 | 503 | 504 | 505 | 507 | 511;\nexport type HTTPStatusCodes = HTTPStatusCode1xx | HTTPStatusCode2xx | HTTPStatusCode3xx | HTTPStatusCode4xx | HTTPStatusCode5xx;\n\n`;\n\nexport const generateFetchHeader: ClientHeaderBuilder = ({\n clientImplementation,\n}) => {\n const needsStatusCodeTypes = /HTTPStatusCode[1-5]xx|<HTTPStatusCodes,/.test(\n clientImplementation,\n );\n return needsStatusCodeTypes ? getHTTPStatusCodes() : '';\n};\n\nconst fetchClientBuilder: ClientGeneratorsBuilder = {\n client: generateClient,\n header: generateFetchHeader,\n dependencies: getFetchDependencies,\n};\n\nexport const builder = () => () => fetchClientBuilder;\n\nexport default builder;\n"],"mappings":";;AAsBA,MAAM,6BAA6B;AACnC,MAAM,oBACJ,QACA,YAEA,WAAW,QAAQ,QAAQ;AAI7B,MAAM,qBAAqB,QAAwB;AACjD,KAAI,2BAA2B,KAAK,IAAI,CAEtC,QAAO,iBADQ,I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;CACR,cAAc;CACf;AAED,MAAa,sBAAsB"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n camel,\n type ClientBuilder,\n type ClientGeneratorsBuilder,\n type ClientHeaderBuilder,\n generateBodyOptions,\n generateFormDataAndUrlEncodedFunction,\n generateVerbImports,\n type GeneratorDependency,\n type GeneratorOptions,\n type GeneratorVerbOptions,\n GetterPropType,\n isObject,\n makeRouteSafe,\n type OpenApiParameterObject,\n type OpenApiReferenceObject,\n type OpenApiSchemaObject,\n pascal,\n resolveRef,\n stringify,\n toObjectString,\n} from '@orval/core';\n\nconst WILDCARD_STATUS_CODE_REGEX = /^[1-5]XX$/i;\nconst resolveSchemaRef = (\n schema: OpenApiSchemaObject | OpenApiReferenceObject,\n context: GeneratorOptions['context'],\n) =>\n resolveRef(schema, context) as {\n schema: OpenApiSchemaObject;\n };\n\nconst getStatusCodeType = (key: string): string => {\n if (WILDCARD_STATUS_CODE_REGEX.test(key)) {\n const prefix = key[0];\n return `HTTPStatusCode${prefix}xx`;\n }\n return key;\n};\n\nconst FETCH_DEPENDENCIES: GeneratorDependency[] = [\n {\n exports: [\n {\n name: 'z',\n alias: 'zod',\n values: true,\n },\n ],\n dependency: 'zod',\n },\n];\n\nexport const getFetchDependencies = () => FETCH_DEPENDENCIES;\n\nexport const generateRequestFunction = (\n {\n queryParams,\n headers,\n operationName,\n response,\n mutator,\n body,\n props,\n verb,\n fetchReviver,\n formData,\n formUrlEncoded,\n override,\n doc,\n }: GeneratorVerbOptions,\n { route: _route, context, pathRoute }: GeneratorOptions,\n) => {\n let route = _route;\n\n if (context.output.urlEncodeParameters) {\n route = makeRouteSafe(route);\n }\n\n const isRequestOptions = override.requestOptions !== false;\n const isFormData = !override.formData.disabled;\n const isFormUrlEncoded = override.formUrlEncoded !== false;\n\n const getUrlFnName = camel(`get-${operationName}-url`);\n const getUrlFnProps = toObjectString(\n props.filter(\n (prop) =>\n prop.type === GetterPropType.PARAM ||\n prop.type === GetterPropType.NAMED_PATH_PARAMS ||\n prop.type === GetterPropType.QUERY_PARAM,\n ),\n 'implementation',\n );\n\n const spec = context.spec.paths?.[pathRoute];\n const parameters = spec?.[verb]?.parameters ?? [];\n const parameterObjects = parameters.map((parameter) => {\n const { schema } = resolveRef(parameter, context);\n return schema as OpenApiParameterObject;\n });\n\n const explodeParameters = parameterObjects.filter((parameterObject) => {\n if (!parameterObject.schema) {\n return false;\n }\n\n const { schema: schemaObject } = resolveSchemaRef(\n parameterObject.schema,\n context,\n );\n\n const isArrayLike =\n schemaObject.type === 'array' ||\n (\n (schemaObject.oneOf as\n | (OpenApiSchemaObject | OpenApiReferenceObject)[]\n | undefined) ?? []\n ).some((s) => resolveSchemaRef(s, context).schema.type === 'array') ||\n (\n (schemaObject.anyOf as\n | (OpenApiSchemaObject | OpenApiReferenceObject)[]\n | undefined) ?? []\n ).some((s) => resolveSchemaRef(s, context).schema.type === 'array') ||\n (\n (schemaObject.allOf as\n | (OpenApiSchemaObject | OpenApiReferenceObject)[]\n | undefined) ?? []\n ).some((s) => resolveSchemaRef(s, context).schema.type === 'array');\n\n return (\n parameterObject.in === 'query' && isArrayLike && parameterObject.explode\n );\n });\n\n const explodeParametersNames = explodeParameters.map(\n (parameter) => parameter.name,\n );\n const hasExplodedDateParams =\n context.output.override.useDates &&\n explodeParameters.some((parameter) => {\n if (!parameter.schema) {\n return false;\n }\n\n const { schema } = resolveSchemaRef(parameter.schema, context);\n return schema.format === 'date-time';\n });\n\n const explodeArrayImplementation =\n explodeParameters.length > 0\n ? `const explodeParameters = ${JSON.stringify(explodeParametersNames)};\n\n if (Array.isArray(value) && explodeParameters.includes(key)) {\n value.forEach((v) => {\n normalizedParams.append(key, v === null ? 'null' : ${hasExplodedDateParams ? 'v instanceof Date ? v.toISOString() : ' : ''}String(v));\n });\n return;\n }\n `\n : '';\n\n const isExplodeParametersOnly =\n explodeParameters.length === parameters.length;\n\n const hasDateParams =\n context.output.override.useDates &&\n parameterObjects.some((parameter) => {\n if (!parameter.schema) {\n return false;\n }\n\n const { schema } = resolveSchemaRef(parameter.schema, context);\n return schema.format === 'date-time';\n });\n\n const normalParamsImplementation = `if (value !== undefined) {\n normalizedParams.append(key, value === null ? 'null' : ${hasDateParams ? 'value instanceof Date ? value.toISOString() : ' : ''}String(value))\n }`;\n\n const getUrlFnImplementation = `export const ${getUrlFnName} = (${getUrlFnProps}) => {\n${\n queryParams\n ? ` const normalizedParams = new URLSearchParams();\n\n Object.entries(params || {}).forEach(([key, value]) => {\n ${explodeArrayImplementation}\n ${isExplodeParametersOnly ? '' : normalParamsImplementation}\n });`\n : ''\n}\n\n ${queryParams ? `const stringifiedParams = normalizedParams.toString();` : ``}\n\n ${\n queryParams\n ? `return stringifiedParams.length > 0 ? \\`${route}?\\${stringifiedParams}\\` : \\`${route}\\``\n : `return \\`${route}\\``\n }\n}\\n`;\n\n const isContentTypeNdJson = (contentType: string) =>\n contentType === 'application/nd-json' ||\n contentType === 'application/x-ndjson';\n\n const isContentTypeJson = (contentType: string) =>\n contentType.toLowerCase().includes('json');\n\n const isNdJson = response.contentTypes.some((contentType) =>\n isContentTypeNdJson(contentType),\n );\n const isBlob = response.isBlob;\n\n const successContentTypes = response.types.success\n .map((t) => t.contentType)\n .filter(Boolean);\n const errorContentTypes = response.types.errors\n .map((t) => t.contentType)\n .filter(Boolean);\n\n // Resolve parsing strategy at generation time based on spec-declared content types.\n // Only emit a runtime Content-Type check when responses have mixed types.\n //\n // When `forceSuccessResponse` is false the same parse block handles both 2xx\n // and error status codes, so its strategy must cover error content types too\n // (otherwise e.g. 200 application/json + 429 text/plain still JSON.parses text).\n const parseTimeContentTypes = override.fetch.forceSuccessResponse\n ? successContentTypes\n : [...successContentTypes, ...errorContentTypes];\n const successHasJson = parseTimeContentTypes.some((ct) =>\n isContentTypeJson(ct),\n );\n const successHasNonJson = parseTimeContentTypes.some(\n (ct) => !isContentTypeJson(ct),\n );\n const hasMixedSuccessContentTypes = successHasJson && successHasNonJson;\n // No declared content types → fall back to JSON (preserve original behaviour)\n const successAlwaysJson =\n parseTimeContentTypes.length === 0 ||\n (successHasJson && !successHasNonJson);\n\n const errorHasJson = errorContentTypes.some((ct) => isContentTypeJson(ct));\n const errorHasNonJson = errorContentTypes.some(\n (ct) => !isContentTypeJson(ct),\n );\n const hasMixedErrorContentTypes = errorHasJson && errorHasNonJson;\n const errorAlwaysJson =\n errorContentTypes.length === 0 || (errorHasJson && !errorHasNonJson);\n const responseTypeName = fetchResponseTypeName(\n override.fetch.includeHttpResponseReturnType,\n isNdJson ? 'Response' : response.definition.success,\n operationName,\n );\n\n const responseType = response.definition.success;\n const isVoidResponse = responseType === 'void';\n\n const isPrimitiveType = [\n 'string',\n 'number',\n 'boolean',\n 'void',\n 'unknown',\n ].includes(responseType);\n const hasSchema = response.imports.some((imp) => imp.name === responseType);\n\n const isValidateResponse =\n override.fetch.runtimeValidation &&\n !isPrimitiveType &&\n hasSchema &&\n !isNdJson;\n\n const allResponses = [...response.types.success, ...response.types.errors];\n if (allResponses.length === 0) {\n allResponses.push({\n contentType: '',\n hasReadonlyProps: false,\n imports: [],\n isEnum: false,\n isRef: false,\n key: 'default',\n schemas: [],\n type: 'unknown',\n value: 'unknown',\n dependencies: [],\n });\n }\n const nonDefaultStatuses = allResponses\n .filter((r) => r.key !== 'default')\n .map((r) => getStatusCodeType(r.key));\n const uniqueNonDefaultStatuses = [...new Set(nonDefaultStatuses)];\n const responseDataTypes = allResponses\n .map((r) =>\n allResponses.filter((r2) => r2.key === r.key).length > 1\n ? { ...r, suffix: pascal(r.contentType) }\n : r,\n )\n .map((r) => {\n const name = `${responseTypeName}${pascal(r.key)}${'suffix' in r ? r.suffix : ''}`;\n const dataType = r.value || 'unknown';\n\n return {\n name,\n success: response.types.success.some((s) => s.key === r.key),\n value: `export type ${name} = {\n ${isContentTypeNdJson(r.contentType) ? `stream: TypedResponse<${dataType}>` : `data: ${dataType}`}\n status: ${\n r.key === 'default'\n ? uniqueNonDefaultStatuses.length > 0\n ? `Exclude<HTTPStatusCodes, ${uniqueNonDefaultStatuses.join(' | ')}>`\n : 'number'\n : getStatusCodeType(r.key)\n }\n}`,\n };\n });\n\n const successName = `${responseTypeName}Success`;\n const errorName = `${responseTypeName}Error`;\n const hasSuccess = responseDataTypes.some((r) => r.success);\n const hasError = responseDataTypes.some((r) => !r.success);\n\n const responseTypeImplementation = override.fetch\n .includeHttpResponseReturnType\n ? `${responseDataTypes.map((r) => r.value).join('\\n\\n')}\n\n${\n hasSuccess\n ? `export type ${successName} = (${responseDataTypes\n .filter((r) => r.success)\n .map((r) => r.name)\n .join(' | ')}) & {\n headers: Headers;\n}`\n : ''\n};\n${\n hasError\n ? `export type ${errorName} = (${responseDataTypes\n .filter((r) => !r.success)\n .map((r) => r.name)\n .join(' | ')}) & {\n headers: Headers;\n}`\n : ''\n};\n\n${override.fetch.forceSuccessResponse && hasSuccess ? '' : `export type ${responseTypeName} = (${hasError && hasSuccess ? `${successName} | ${errorName}` : hasSuccess ? successName : errorName})\\n\\n`}`\n : '';\n\n const getUrlFnProperties = props\n .filter(\n (prop) =>\n prop.type === GetterPropType.PARAM ||\n prop.type === GetterPropType.QUERY_PARAM ||\n prop.type === GetterPropType.NAMED_PATH_PARAMS,\n )\n .map((param) => {\n return param.type === GetterPropType.NAMED_PATH_PARAMS\n ? param.destructured\n : param.name;\n })\n .join(',');\n\n const useRuntimeFetcher = override.fetch.useRuntimeFetcher;\n const fetchFnParam =\n useRuntimeFetcher && isRequestOptions && !mutator\n ? ', fetchFn?: typeof globalThis.fetch'\n : '';\n const args = `${toObjectString(props, 'implementation')} ${isRequestOptions ? `options?: RequestInit` : ''}${fetchFnParam}`;\n const returnType =\n override.fetch.forceSuccessResponse && hasSuccess\n ? `Promise<${successName}>`\n : `Promise<${responseTypeName}>`;\n\n const fetchMethodOption = `method: '${verb.toUpperCase()}'`;\n const ignoreContentTypes = ['multipart/form-data'];\n const overrideHeaders =\n isObject(override.requestOptions) && override.requestOptions.headers\n ? Object.entries(override.requestOptions.headers).map(\n ([key, value]) => `'${key}': \\`${value}\\``,\n )\n : [];\n\n const headersToAdd: string[] = [\n ...(body.contentType && !ignoreContentTypes.includes(body.contentType)\n ? [`'Content-Type': '${body.contentType}'`]\n : []),\n ...(isNdJson && response.contentTypes.length === 1\n ? [\n `Accept: ${\n response.contentTypes[0] === 'application/x-ndjson'\n ? \"'application/x-ndjson'\"\n : \"'application/nd-json'\"\n }`,\n ]\n : []),\n ...overrideHeaders,\n ...(headers ? ['...headers'] : []),\n ];\n\n let globalFetchOptions;\n if (isObject(override.requestOptions)) {\n // If both requestOptions and fetchHeadersOptions will be adding a header, we must merge them to avoid multiple properties with the same name\n const shouldMergeFetchOptionHeaders =\n headersToAdd.length > 0 && 'headers' in override.requestOptions;\n const globalFetchOptionsObject = { ...override.requestOptions };\n if (shouldMergeFetchOptionHeaders && override.requestOptions.headers) {\n // Remove the headers from the object going into globalFetchOptions\n delete globalFetchOptionsObject.headers;\n // Add it to the dedicated headers object\n }\n globalFetchOptions = stringify(globalFetchOptionsObject)\n ?.slice(1, -1)\n .trim();\n } else {\n globalFetchOptions = '';\n }\n const fetchHeadersOption =\n headersToAdd.length > 0\n ? `headers: { ${headersToAdd.join(',')}, ...options?.headers }`\n : '';\n const requestBodyParams = generateBodyOptions(\n body,\n isFormData,\n isFormUrlEncoded,\n );\n const fetchBodyOption = requestBodyParams\n ? (isFormData && body.formData) ||\n (isFormUrlEncoded && body.formUrlEncoded) ||\n body.contentType === 'text/plain'\n ? `body: ${requestBodyParams}`\n : `body: JSON.stringify(${requestBodyParams})`\n : '';\n const fetchFnOptions = `${getUrlFnName}(${getUrlFnProperties}),\n {${globalFetchOptions ? '\\n' : ''} ${globalFetchOptions}\n ${isRequestOptions ? '...options,' : ''}\n ${fetchMethodOption}${fetchHeadersOption ? ',' : ''}\n ${fetchHeadersOption}${fetchBodyOption ? ',' : ''}\n ${fetchBodyOption}\n }\n`;\n const reviver = fetchReviver ? `, ${fetchReviver.name}` : '';\n const schemaValueRef =\n responseType === 'Error' ? 'ErrorSchema' : responseType;\n const fetchResponseType =\n override.fetch.forceSuccessResponse && hasSuccess\n ? successName\n : responseTypeName;\n\n // Error response fallback always uses {} — error data types vary (e.g. `Error`)\n // and {} satisfies them all without a type error, matching prior behaviour.\n // Use truthy `body` check before JSON.parse so empty string bodies fall back\n // instead of throwing (`JSON.parse('')` is invalid).\n const errorBodyExpression = hasMixedErrorContentTypes\n ? `errorBody ? (errorContentType.includes('json') ? JSON.parse(errorBody${reviver}) : errorBody) : {}`\n : errorAlwaysJson\n ? `errorBody ? JSON.parse(errorBody${reviver}) : {}`\n : `errorBody !== null ? errorBody : {}`;\n\n const throwOnErrorBodyExpression = hasMixedErrorContentTypes\n ? `body ? (errorContentType.includes('json') ? JSON.parse(body${reviver}) : body) : {}`\n : errorAlwaysJson\n ? `body ? JSON.parse(body${reviver}) : {}`\n : `body !== null ? body : ''`;\n\n const throwOnErrorDataExpression = isNdJson\n ? `body ? JSON.parse(body${reviver}) : {}`\n : isBlob\n ? errorBodyExpression\n : throwOnErrorBodyExpression;\n\n // In the forceSuccessResponse path, throwOnErrorImplementation is emitted AFTER\n // `contentType` and `body` are already declared in the outer scope, so we must\n // NOT redeclare them here.\n const throwOnErrorInnerDeclarations = isNdJson\n ? 'const body = [204, 205, 304].includes(stream.status) ? null : await stream.text();'\n : isBlob\n ? `const errorBody = [204, 205, 304].includes(res.status) ? null : await res.text();\n ${hasMixedErrorContentTypes ? `const errorContentType = (res.headers.get('content-type') ?? '').toLowerCase();` : ''}`\n : override.fetch.forceSuccessResponse\n ? hasMixedErrorContentTypes\n ? `const errorContentType = (res.headers.get('content-type') ?? '').toLowerCase();`\n : ''\n : hasMixedErrorContentTypes\n ? `const errorContentType = (res.headers.get('content-type') ?? '').toLowerCase();\n const body = [204, 205, 304].includes(res.status) ? null : await res.text();`\n : 'const body = [204, 205, 304].includes(res.status) ? null : await res.text();';\n\n const throwOnErrorImplementation = `if (!${isNdJson ? 'stream' : 'res'}.ok) {\n ${throwOnErrorInnerDeclarations}\n const err: globalThis.Error & {info?: ${hasError ? `${errorName}${override.fetch.includeHttpResponseReturnType ? \"['data']\" : ''}` : 'any'}, status?: number} = new globalThis.Error();\n const data ${hasError ? `: ${errorName}${override.fetch.includeHttpResponseReturnType ? `['data']` : ''}` : ''} = ${throwOnErrorDataExpression}\n err.info = data;\n err.status = ${isNdJson ? 'stream' : 'res'}.status;\n throw err;\n }`;\n const fetchFnCall =\n useRuntimeFetcher && isRequestOptions ? '(fetchFn ?? fetch)' : 'fetch';\n const blobFetchResponseImplementation = `const res = await ${fetchFnCall}(${fetchFnOptions})\n\n ${override.fetch.forceSuccessResponse ? throwOnErrorImplementation : ''}\n const body = [204, 205, 304].includes(res.status) ? null : await res.blob();\n const data: ${fetchResponseType}${override.fetch.includeHttpResponseReturnType ? `['data']` : ''} = body as ${fetchResponseType}${override.fetch.includeHttpResponseReturnType ? `['data']` : ''}\n ${\n override.fetch.includeHttpResponseReturnType\n ? `return { data, status: res.status, headers: res.headers } as ${fetchResponseType}`\n : 'return data'\n }\n`;\n const fetchResponseImplementation = isNdJson\n ? ` const stream = await ${fetchFnCall}(${fetchFnOptions});\n ${override.fetch.forceSuccessResponse ? throwOnErrorImplementation : ''}\n ${\n override.fetch.includeHttpResponseReturnType\n ? `return { status: stream.status, stream, headers: stream.headers } as ${fetchResponseType}`\n : `return stream`\n }\n `\n : isBlob\n ? blobFetchResponseImplementation\n : `const res = await ${fetchFnCall}(${fetchFnOptions})\n\n ${hasMixedSuccessContentTypes || (isValidateResponse && successAlwaysJson) ? `const contentType = (res.headers.get('content-type') ?? '').toLowerCase();` : ''}\n const body = [204, 205, 304].includes(res.status) ? null : await res.text();\n ${override.fetch.forceSuccessResponse ? throwOnErrorImplementation : ''}\n ${\n isValidateResponse\n ? hasMixedSuccessContentTypes\n ? `const parsedBody = body ? (contentType.includes('json') ? JSON.parse(body${reviver}) : body) : {}\n const data = contentType.includes('json') ? ${schemaValueRef}.parse(parsedBody) : parsedBody`\n : successAlwaysJson\n ? `const parsedBody = body ? (contentType.includes('json') ? JSON.parse(body${reviver}) : body) : {}\n const data = contentType.includes('json') ? ${schemaValueRef}.parse(parsedBody) : parsedBody`\n : `const parsedBody = body !== null ? body : ''\n const data = parsedBody`\n : hasMixedSuccessContentTypes\n ? `const data: ${fetchResponseType}${override.fetch.includeHttpResponseReturnType ? `['data']` : ''} = body ? (contentType.includes('json') ? JSON.parse(body${reviver}) : body) : ${isVoidResponse ? 'undefined' : '{}'}`\n : successAlwaysJson\n ? `const data: ${fetchResponseType}${override.fetch.includeHttpResponseReturnType ? `['data']` : ''} = body ? JSON.parse(body${reviver}) : ${isVoidResponse ? 'undefined' : '{}'}`\n : `const data: ${fetchResponseType}${override.fetch.includeHttpResponseReturnType ? `['data']` : ''} = body !== null ? body : ${isVoidResponse ? 'undefined' : \"''\"}`\n }\n ${\n override.fetch.includeHttpResponseReturnType\n ? `return { data, status: res.status, headers: res.headers } as ${fetchResponseType}`\n : 'return data'\n }\n`;\n let customFetchResponseImplementation = `return ${mutator?.name}<${fetchResponseType}>(${fetchFnOptions});`;\n\n const bodyForm = generateFormDataAndUrlEncodedFunction({\n formData,\n formUrlEncoded,\n body,\n isFormData,\n isFormUrlEncoded,\n });\n\n if (mutator?.isHook) {\n const hasDefaultName = !mutator.path.includes('#');\n const fetchExportName = hasDefaultName\n ? 'customFetcher'\n : mutator.path.split('#')[1];\n const formattedDeconstructor = hasDefaultName\n ? `customFetcher`\n : `{${fetchExportName}}`;\n customFetchResponseImplementation = `\n const ${formattedDeconstructor} = ${mutator.name}();\n return (${args}) => {\n ${bodyForm}\n return ${fetchExportName}(${fetchFnOptions});\n }\n `;\n }\n\n const fetchImplementationBody = mutator\n ? customFetchResponseImplementation\n : fetchResponseImplementation;\n\n let fetchImplementation = `export const ${operationName} = async (${args}): ${returnType} => {\n ${bodyForm ? ` ${bodyForm}` : ''}\n ${fetchImplementationBody}}\n `;\n if (mutator?.isHook) {\n fetchImplementation = `export const use${pascal(operationName)}Hook = (): (${args}) => ${returnType} => {\n ${fetchImplementationBody}}\n `;\n }\n\n return (\n responseTypeImplementation +\n `${getUrlFnImplementation}\\n` +\n `${doc}${fetchImplementation}\\n`\n );\n};\n\nexport const fetchResponseTypeName = (\n includeHttpResponseReturnType: boolean | undefined,\n definitionSuccessResponse: string,\n operationName: string,\n) => {\n return includeHttpResponseReturnType\n ? `${operationName}Response`\n : definitionSuccessResponse;\n};\n\nexport const generateClient: ClientBuilder = (verbOptions, options) => {\n const isZodOutput =\n typeof options.context.output.schemas === 'object' &&\n options.context.output.schemas.type === 'zod';\n const responseType = verbOptions.response.definition.success;\n const isPrimitiveResponse = [\n 'string',\n 'number',\n 'boolean',\n 'void',\n 'unknown',\n ].includes(responseType);\n const shouldUseRuntimeValidation =\n verbOptions.override.fetch.runtimeValidation && isZodOutput;\n\n const normalizedVerbOptions =\n shouldUseRuntimeValidation &&\n !isPrimitiveResponse &&\n verbOptions.response.imports.some((imp) => imp.name === responseType)\n ? {\n ...verbOptions,\n response: {\n ...verbOptions.response,\n imports: verbOptions.response.imports.map((imp) =>\n imp.name === responseType ? { ...imp, values: true } : imp,\n ),\n },\n }\n : verbOptions;\n\n const imports = generateVerbImports(normalizedVerbOptions);\n const functionImplementation = generateRequestFunction(\n normalizedVerbOptions,\n options,\n );\n\n return {\n implementation: `${functionImplementation}\\n`,\n imports,\n docComment: '',\n };\n};\n\nconst getHTTPStatusCodes = () => `\nexport type HTTPStatusCode1xx = 100 | 101 | 102 | 103;\nexport type HTTPStatusCode2xx = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207;\nexport type HTTPStatusCode3xx = 300 | 301 | 302 | 303 | 304 | 305 | 307 | 308;\nexport type HTTPStatusCode4xx = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 426 | 428 | 429 | 431 | 451;\nexport type HTTPStatusCode5xx = 500 | 501 | 502 | 503 | 504 | 505 | 507 | 511;\nexport type HTTPStatusCodes = HTTPStatusCode1xx | HTTPStatusCode2xx | HTTPStatusCode3xx | HTTPStatusCode4xx | HTTPStatusCode5xx;\n\n`;\n\nexport const generateFetchHeader: ClientHeaderBuilder = ({\n clientImplementation,\n}) => {\n const needsStatusCodeTypes = /HTTPStatusCode[1-5]xx|<HTTPStatusCodes,/.test(\n clientImplementation,\n );\n return needsStatusCodeTypes ? getHTTPStatusCodes() : '';\n};\n\nconst fetchClientBuilder: ClientGeneratorsBuilder = {\n client: generateClient,\n header: generateFetchHeader,\n dependencies: getFetchDependencies,\n};\n\nexport const builder = () => () => fetchClientBuilder;\n\nexport default builder;\n"],"mappings":";;AAuBA,MAAM,6BAA6B;AACnC,MAAM,oBACJ,QACA,YAEA,WAAW,QAAQ,QAAQ;AAI7B,MAAM,qBAAqB,QAAwB;AACjD,KAAI,2BAA2B,KAAK,IAAI,CAEtC,QAAO,iBADQ,IAAI,GACY;AAEjC,QAAO;;AAGT,MAAM,qBAA4C,CAChD;CACE,SAAS,CACP;EACE,MAAM;EACN,OAAO;EACP,QAAQ;EACT,CACF;CACD,YAAY;CACb,CACF;AAED,MAAa,6BAA6B;AAE1C,MAAa,2BACX,EACE,aACA,SACA,eACA,UACA,SACA,MACA,OACA,MACA,cACA,UACA,gBACA,UACA,OAEF,EAAE,OAAO,QAAQ,SAAS,gBACvB;CACH,IAAI,QAAQ;AAEZ,KAAI,QAAQ,OAAO,oBACjB,SAAQ,cAAc,MAAM;CAG9B,MAAM,mBAAmB,SAAS,mBAAmB;CACrD,MAAM,aAAa,CAAC,SAAS,SAAS;CACtC,MAAM,mBAAmB,SAAS,mBAAmB;CAErD,MAAM,eAAe,MAAM,OAAO,cAAc,MAAM;CACtD,MAAM,gBAAgB,eACpB,MAAM,QACH,SACC,KAAK,SAAS,eAAe,SAC7B,KAAK,SAAS,eAAe,qB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AQ,QAAQ,OAAO,YAAY,YAC1C,QAAQ,QAAQ,OAAO,QAAQ,SAAS;CAC1C,MAAM,eAAe,YAAY,SAAS,WAAW;CACrD,MAAM,sBAAsB;EAC1B;EACA;EACA;EACA;EACA;EACD,CAAC,SAAS,aAAa;CAIxB,MAAM,wBAFJ,YAAY,SAAS,MAAM,qBAAqB,eAIhD,CAAC,uBACD,YAAY,SAAS,QAAQ,MAAM,QAAQ,IAAI,SAAS,aAAa,GACjE;EACE,GAAG;EACH,UAAU;GACR,GAAG,YAAY;GACf,SAAS,YAAY,SAAS,QAAQ,KAAK,QACzC,IAAI,SAAS,eAAe;IAAE,GAAG;IAAK,QAAQ;IAAM,GAAG,IACxD;GACF;EACF,GACD;CAEN,MAAM,UAAU,oBAAoB,sBAAsB;AAM1D,QAAO;EACL,gBAAgB,GANa,wBAC7B,uBACA,QACD,CAG2C;EAC1C;EACA,YAAY;EACb;;AAGH,MAAM,2BAA2B;;;;;;;;;AAUjC,MAAa,uBAA4C,EACvD,2BACI;AAIJ,QAH6B,0CAA0C,KACrE,qBACD,GAC6B,oBAAoB,GAAG;;AAGvD,MAAM,qBAA8C;CAClD,QAAQ;CACR,QAAQ;CACR,cAAc;CACf;AAED,MAAa,sBAAsB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orval/fetch",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.12.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"nuke": "rimraf .turbo dist node_modules"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@orval/core": "8.
|
|
38
|
+
"@orval/core": "8.12.1",
|
|
39
39
|
"@scalar/openapi-types": "0.8.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|