@orval/axios 7.14.0 → 8.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +13 -47
- package/dist/index.js.map +1 -1
- package/package.json +10 -8
package/dist/index.js
CHANGED
|
@@ -1,29 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
//#region rolldown:runtime
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
-
get: ((k) => from[k]).bind(null, key),
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
-
value: mod,
|
|
21
|
-
enumerable: true
|
|
22
|
-
}) : target, mod));
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
let __orval_core = require("@orval/core");
|
|
26
|
-
__orval_core = __toESM(__orval_core);
|
|
1
|
+
import { generateFormDataAndUrlEncodedFunction, generateMutatorConfig, generateMutatorRequestOptions, generateOptions, generateVerbImports, isSyntheticDefaultImportsAllow, pascal, sanitize, toObjectString } from "@orval/core";
|
|
27
2
|
|
|
28
3
|
//#region src/index.ts
|
|
29
4
|
const AXIOS_DEPENDENCIES = [{
|
|
@@ -55,8 +30,8 @@ const generateAxiosImplementation = ({ headers, queryParams, operationName, resp
|
|
|
55
30
|
const isFormData = !override?.formData.disabled;
|
|
56
31
|
const isFormUrlEncoded = override?.formUrlEncoded !== false;
|
|
57
32
|
const isExactOptionalPropertyTypes = !!context.output.tsconfig?.compilerOptions?.exactOptionalPropertyTypes;
|
|
58
|
-
const isSyntheticDefaultImportsAllowed =
|
|
59
|
-
const bodyForm =
|
|
33
|
+
const isSyntheticDefaultImportsAllowed = isSyntheticDefaultImportsAllow(context.output.tsconfig);
|
|
34
|
+
const bodyForm = generateFormDataAndUrlEncodedFunction({
|
|
60
35
|
formData,
|
|
61
36
|
formUrlEncoded,
|
|
62
37
|
body,
|
|
@@ -64,7 +39,7 @@ const generateAxiosImplementation = ({ headers, queryParams, operationName, resp
|
|
|
64
39
|
isFormUrlEncoded
|
|
65
40
|
});
|
|
66
41
|
if (mutator) {
|
|
67
|
-
const mutatorConfig =
|
|
42
|
+
const mutatorConfig = generateMutatorConfig({
|
|
68
43
|
route,
|
|
69
44
|
body,
|
|
70
45
|
headers,
|
|
@@ -76,17 +51,16 @@ const generateAxiosImplementation = ({ headers, queryParams, operationName, resp
|
|
|
76
51
|
hasSignal: false,
|
|
77
52
|
isExactOptionalPropertyTypes
|
|
78
53
|
});
|
|
79
|
-
const requestOptions = isRequestOptions ?
|
|
80
|
-
returnTypesToWrite.set(operationName, (title) => `export type ${
|
|
81
|
-
const
|
|
82
|
-
return `const ${operationName} = (\n ${propsImplementation}\n ${isRequestOptions && mutator.hasSecondArg ? `options${context.output.optionsParamRequired ? "" : "?"}: SecondParameter<typeof ${mutator.name}<${response.definition.success || "unknown"}>>,` : ""}) => {${bodyForm}
|
|
54
|
+
const requestOptions = isRequestOptions ? generateMutatorRequestOptions(override?.requestOptions, mutator.hasSecondArg) : "";
|
|
55
|
+
returnTypesToWrite.set(operationName, (title) => `export type ${pascal(operationName)}Result = NonNullable<Awaited<ReturnType<${title ? `ReturnType<typeof ${title}>['${operationName}']` : `typeof ${operationName}`}>>>`);
|
|
56
|
+
return `const ${operationName} = (\n ${mutator.bodyTypeName && body.definition ? toObjectString(props, "implementation").replace(/* @__PURE__ */ new RegExp(`(\\w*):\\s?${body.definition}`), `$1: ${mutator.bodyTypeName}<${body.definition}>`) : toObjectString(props, "implementation")}\n ${isRequestOptions && mutator.hasSecondArg ? `options${context.output.optionsParamRequired ? "" : "?"}: SecondParameter<typeof ${mutator.name}<${response.definition.success || "unknown"}>>,` : ""}) => {${bodyForm}
|
|
83
57
|
return ${mutator.name}<${response.definition.success || "unknown"}>(
|
|
84
58
|
${mutatorConfig},
|
|
85
59
|
${requestOptions});
|
|
86
60
|
}
|
|
87
61
|
`;
|
|
88
62
|
}
|
|
89
|
-
const options =
|
|
63
|
+
const options = generateOptions({
|
|
90
64
|
route,
|
|
91
65
|
body,
|
|
92
66
|
headers,
|
|
@@ -101,15 +75,14 @@ const generateAxiosImplementation = ({ headers, queryParams, operationName, resp
|
|
|
101
75
|
isExactOptionalPropertyTypes,
|
|
102
76
|
hasSignal: false
|
|
103
77
|
});
|
|
104
|
-
returnTypesToWrite.set(operationName, () => `export type ${
|
|
105
|
-
return `const ${operationName} = <TData = AxiosResponse<${response.definition.success || "unknown"}>>(\n ${
|
|
78
|
+
returnTypesToWrite.set(operationName, () => `export type ${pascal(operationName)}Result = AxiosResponse<${response.definition.success || "unknown"}>`);
|
|
79
|
+
return `const ${operationName} = <TData = AxiosResponse<${response.definition.success || "unknown"}>>(\n ${toObjectString(props, "implementation")} ${isRequestOptions ? `options?: AxiosRequestConfig\n` : ""} ): Promise<TData> => {${bodyForm}
|
|
106
80
|
return axios${isSyntheticDefaultImportsAllowed ? "" : ".default"}.${verb}(${options});
|
|
107
81
|
}
|
|
108
82
|
`;
|
|
109
83
|
};
|
|
110
84
|
const generateAxiosTitle = (title) => {
|
|
111
|
-
|
|
112
|
-
return `get${(0, __orval_core.pascal)(sanTitle)}`;
|
|
85
|
+
return `get${pascal(sanitize(title))}`;
|
|
113
86
|
};
|
|
114
87
|
const generateAxiosHeader = ({ title, isRequestOptions, isMutator, noFunction }) => `
|
|
115
88
|
${isRequestOptions && isMutator ? `type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];\n\n` : ""}
|
|
@@ -127,7 +100,7 @@ const generateAxiosFooter = ({ operationNames, title, noFunction, hasMutator, ha
|
|
|
127
100
|
return footer;
|
|
128
101
|
};
|
|
129
102
|
const generateAxios = (verbOptions, options) => {
|
|
130
|
-
const imports =
|
|
103
|
+
const imports = generateVerbImports(verbOptions);
|
|
131
104
|
return {
|
|
132
105
|
implementation: generateAxiosImplementation(verbOptions, options),
|
|
133
106
|
imports
|
|
@@ -168,12 +141,5 @@ const builder = ({ type = "axios-functions" } = {}) => () => builders[type];
|
|
|
168
141
|
var src_default = builder;
|
|
169
142
|
|
|
170
143
|
//#endregion
|
|
171
|
-
|
|
172
|
-
exports.default = src_default;
|
|
173
|
-
exports.generateAxios = generateAxios;
|
|
174
|
-
exports.generateAxiosFooter = generateAxiosFooter;
|
|
175
|
-
exports.generateAxiosFunctions = generateAxiosFunctions;
|
|
176
|
-
exports.generateAxiosHeader = generateAxiosHeader;
|
|
177
|
-
exports.generateAxiosTitle = generateAxiosTitle;
|
|
178
|
-
exports.getAxiosDependencies = getAxiosDependencies;
|
|
144
|
+
export { builder, src_default as default, generateAxios, generateAxiosFooter, generateAxiosFunctions, generateAxiosHeader, generateAxiosTitle, getAxiosDependencies };
|
|
179
145
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["AXIOS_DEPENDENCIES: GeneratorDependency[]","PARAMS_SERIALIZER_DEPENDENCIES: GeneratorDependency[]","getAxiosDependencies: ClientDependenciesBuilder","generateAxiosTitle: ClientTitleBuilder","generateAxiosHeader: ClientHeaderBuilder","generateAxiosFooter: ClientFooterBuilder","generateAxiosFunctions: ClientBuilder","axiosClientBuilder: ClientGeneratorsBuilder","axiosFunctionsClientBuilder: ClientGeneratorsBuilder","builders: Record<'axios' | 'axios-functions', ClientGeneratorsBuilder>"],"sources":["../src/index.ts"],"sourcesContent":["import {\n ClientBuilder,\n ClientDependenciesBuilder,\n ClientFooterBuilder,\n ClientGeneratorsBuilder,\n ClientHeaderBuilder,\n ClientTitleBuilder,\n generateFormDataAndUrlEncodedFunction,\n generateMutatorConfig,\n generateMutatorRequestOptions,\n generateOptions,\n generateVerbImports,\n GeneratorDependency,\n GeneratorOptions,\n GeneratorVerbOptions,\n isSyntheticDefaultImportsAllow,\n pascal,\n sanitize,\n toObjectString,\n} from '@orval/core';\n\nconst AXIOS_DEPENDENCIES: GeneratorDependency[] = [\n {\n exports: [\n {\n name: 'axios',\n default: true,\n values: true,\n syntheticDefaultImport: true,\n },\n { name: 'AxiosRequestConfig' },\n { name: 'AxiosResponse' },\n ],\n dependency: 'axios',\n },\n];\n\nconst PARAMS_SERIALIZER_DEPENDENCIES: GeneratorDependency[] = [\n {\n exports: [\n {\n name: 'qs',\n default: true,\n values: true,\n syntheticDefaultImport: true,\n },\n ],\n dependency: 'qs',\n },\n];\n\nconst returnTypesToWrite = new Map<string, (title?: string) => string>();\n\nexport const getAxiosDependencies: ClientDependenciesBuilder = (\n hasGlobalMutator,\n hasParamsSerializerOptions: boolean,\n) => [\n ...(hasGlobalMutator ? [] : AXIOS_DEPENDENCIES),\n ...(hasParamsSerializerOptions ? PARAMS_SERIALIZER_DEPENDENCIES : []),\n];\n\nconst generateAxiosImplementation = (\n {\n headers,\n queryParams,\n operationName,\n response,\n mutator,\n body,\n props,\n verb,\n override,\n formData,\n formUrlEncoded,\n paramsSerializer,\n }: GeneratorVerbOptions,\n { route, context }: GeneratorOptions,\n) => {\n const isRequestOptions = override?.requestOptions !== false;\n const isFormData = !override?.formData.disabled;\n const isFormUrlEncoded = override?.formUrlEncoded !== false;\n const isExactOptionalPropertyTypes =\n !!context.output.tsconfig?.compilerOptions?.exactOptionalPropertyTypes;\n\n const isSyntheticDefaultImportsAllowed = isSyntheticDefaultImportsAllow(\n context.output.tsconfig,\n );\n\n const bodyForm = generateFormDataAndUrlEncodedFunction({\n formData,\n formUrlEncoded,\n body,\n isFormData,\n isFormUrlEncoded,\n });\n\n if (mutator) {\n const mutatorConfig = generateMutatorConfig({\n route,\n body,\n headers,\n queryParams,\n response,\n verb,\n isFormData,\n isFormUrlEncoded,\n hasSignal: false,\n isExactOptionalPropertyTypes,\n });\n\n const requestOptions = isRequestOptions\n ? generateMutatorRequestOptions(\n override?.requestOptions,\n mutator.hasSecondArg,\n )\n : '';\n\n returnTypesToWrite.set(\n operationName,\n (title?: string) =>\n `export type ${pascal(\n operationName,\n )}Result = NonNullable<Awaited<ReturnType<${\n title\n ? `ReturnType<typeof ${title}>['${operationName}']`\n : `typeof ${operationName}`\n }>>>`,\n );\n\n const propsImplementation =\n mutator.bodyTypeName && body.definition\n ? toObjectString(props, 'implementation').replace(\n new RegExp(`(\\\\w*):\\\\s?${body.definition}`),\n `$1: ${mutator.bodyTypeName}<${body.definition}>`,\n )\n : toObjectString(props, 'implementation');\n\n return `const ${operationName} = (\\n ${propsImplementation}\\n ${\n isRequestOptions && mutator.hasSecondArg\n ? `options${context.output.optionsParamRequired ? '' : '?'}: SecondParameter<typeof ${mutator.name}<${response.definition.success || 'unknown'}>>,`\n : ''\n }) => {${bodyForm}\n return ${mutator.name}<${response.definition.success || 'unknown'}>(\n ${mutatorConfig},\n ${requestOptions});\n }\n `;\n }\n\n const options = generateOptions({\n route,\n body,\n headers,\n queryParams,\n response,\n verb,\n requestOptions: override?.requestOptions,\n isFormData,\n isFormUrlEncoded,\n paramsSerializer,\n paramsSerializerOptions: override?.paramsSerializerOptions,\n isExactOptionalPropertyTypes,\n hasSignal: false,\n });\n\n returnTypesToWrite.set(\n operationName,\n () =>\n `export type ${pascal(operationName)}Result = AxiosResponse<${\n response.definition.success || 'unknown'\n }>`,\n );\n\n return `const ${operationName} = <TData = AxiosResponse<${\n response.definition.success || 'unknown'\n }>>(\\n ${toObjectString(props, 'implementation')} ${\n isRequestOptions ? `options?: AxiosRequestConfig\\n` : ''\n } ): Promise<TData> => {${bodyForm}\n return axios${\n isSyntheticDefaultImportsAllowed ? '' : '.default'\n }.${verb}(${options});\n }\n`;\n};\n\nexport const generateAxiosTitle: ClientTitleBuilder = (title) => {\n const sanTitle = sanitize(title);\n return `get${pascal(sanTitle)}`;\n};\n\nexport const generateAxiosHeader: ClientHeaderBuilder = ({\n title,\n isRequestOptions,\n isMutator,\n noFunction,\n}) => `\n${\n isRequestOptions && isMutator\n ? `type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];\\n\\n`\n : ''\n}\n ${noFunction ? '' : `export const ${title} = () => {\\n`}`;\n\nexport const generateAxiosFooter: ClientFooterBuilder = ({\n operationNames,\n title,\n noFunction,\n hasMutator,\n hasAwaitedType,\n}) => {\n let footer = '';\n\n if (!noFunction) {\n footer += `return {${operationNames.join(',')}}};\\n`;\n }\n\n if (hasMutator && !hasAwaitedType) {\n footer += `\\ntype AwaitedInput<T> = PromiseLike<T> | T;\\n\n type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;\n\\n`;\n }\n\n for (const operationName of operationNames) {\n if (returnTypesToWrite.has(operationName)) {\n const func = returnTypesToWrite.get(operationName)!;\n footer += func(noFunction ? undefined : title) + '\\n';\n }\n }\n\n return footer;\n};\n\nexport const generateAxios = (\n verbOptions: GeneratorVerbOptions,\n options: GeneratorOptions,\n) => {\n const imports = generateVerbImports(verbOptions);\n const implementation = generateAxiosImplementation(verbOptions, options);\n\n return { implementation, imports };\n};\n\nexport const generateAxiosFunctions: ClientBuilder = async (\n verbOptions,\n options,\n) => {\n const { implementation, imports } = generateAxios(verbOptions, options);\n\n return {\n implementation: 'export ' + implementation,\n imports,\n };\n};\n\nconst axiosClientBuilder: ClientGeneratorsBuilder = {\n client: generateAxios,\n header: generateAxiosHeader,\n dependencies: getAxiosDependencies,\n footer: generateAxiosFooter,\n title: generateAxiosTitle,\n};\n\nconst axiosFunctionsClientBuilder: ClientGeneratorsBuilder = {\n client: generateAxiosFunctions,\n header: (options) => generateAxiosHeader({ ...options, noFunction: true }),\n dependencies: getAxiosDependencies,\n footer: (options) => generateAxiosFooter({ ...options, noFunction: true }),\n title: generateAxiosTitle,\n};\n\nconst builders: Record<'axios' | 'axios-functions', ClientGeneratorsBuilder> = {\n axios: axiosClientBuilder,\n 'axios-functions': axiosFunctionsClientBuilder,\n};\n\nexport const builder =\n ({ type = 'axios-functions' }: { type?: 'axios' | 'axios-functions' } = {}) =>\n () =>\n builders[type];\n\nexport default builder;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAMA,qBAA4C,CAChD;CACE,SAAS;EACP;GACE,MAAM;GACN,SAAS;GACT,QAAQ;GACR,wBAAwB;GACzB;EACD,EAAE,MAAM,sBAAsB;EAC9B,EAAE,MAAM,iBAAiB;EAC1B;CACD,YAAY;CACb,CACF;AAED,MAAMC,iCAAwD,CAC5D;CACE,SAAS,CACP;EACE,MAAM;EACN,SAAS;EACT,QAAQ;EACR,wBAAwB;EACzB,CACF;CACD,YAAY;CACb,CACF;AAED,MAAM,qCAAqB,IAAI,KAAyC;AAExE,MAAaC,wBACX,kBACA,+BACG,CACH,GAAI,mBAAmB,EAAE,GAAG,oBAC5B,GAAI,6BAA6B,iCAAiC,EAAE,CACrE;AAED,MAAM,+BACJ,EACE,SACA,aACA,eACA,UACA,SACA,MACA,OACA,MACA,UACA,UACA,gBACA,oBAEF,EAAE,OAAO,cACN;CACH,MAAM,mBAAmB,UAAU,mBAAmB;CACtD,MAAM,aAAa,CAAC,UAAU,SAAS;CACvC,MAAM,mBAAmB,UAAU,mBAAmB;CACtD,MAAM,+BACJ,CAAC,CAAC,QAAQ,OAAO,UAAU,iBAAiB;CAE9C,MAAM,oFACJ,Q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eneratorDependency[]","getAxiosDependencies: ClientDependenciesBuilder","generateAxiosTitle: ClientTitleBuilder","generateAxiosHeader: ClientHeaderBuilder","generateAxiosFooter: ClientFooterBuilder","generateAxiosFunctions: ClientBuilder","axiosClientBuilder: ClientGeneratorsBuilder","axiosFunctionsClientBuilder: ClientGeneratorsBuilder","builders: Record<'axios' | 'axios-functions', ClientGeneratorsBuilder>"],"sources":["../src/index.ts"],"sourcesContent":["import {\n type ClientBuilder,\n type ClientDependenciesBuilder,\n type ClientFooterBuilder,\n type ClientGeneratorsBuilder,\n type ClientHeaderBuilder,\n type ClientTitleBuilder,\n generateFormDataAndUrlEncodedFunction,\n generateMutatorConfig,\n generateMutatorRequestOptions,\n generateOptions,\n generateVerbImports,\n type GeneratorDependency,\n type GeneratorOptions,\n type GeneratorVerbOptions,\n isSyntheticDefaultImportsAllow,\n pascal,\n sanitize,\n toObjectString,\n} from '@orval/core';\n\nconst AXIOS_DEPENDENCIES: GeneratorDependency[] = [\n {\n exports: [\n {\n name: 'axios',\n default: true,\n values: true,\n syntheticDefaultImport: true,\n },\n { name: 'AxiosRequestConfig' },\n { name: 'AxiosResponse' },\n ],\n dependency: 'axios',\n },\n];\n\nconst PARAMS_SERIALIZER_DEPENDENCIES: GeneratorDependency[] = [\n {\n exports: [\n {\n name: 'qs',\n default: true,\n values: true,\n syntheticDefaultImport: true,\n },\n ],\n dependency: 'qs',\n },\n];\n\nconst returnTypesToWrite = new Map<string, (title?: string) => string>();\n\nexport const getAxiosDependencies: ClientDependenciesBuilder = (\n hasGlobalMutator,\n hasParamsSerializerOptions: boolean,\n) => [\n ...(hasGlobalMutator ? [] : AXIOS_DEPENDENCIES),\n ...(hasParamsSerializerOptions ? PARAMS_SERIALIZER_DEPENDENCIES : []),\n];\n\nconst generateAxiosImplementation = (\n {\n headers,\n queryParams,\n operationName,\n response,\n mutator,\n body,\n props,\n verb,\n override,\n formData,\n formUrlEncoded,\n paramsSerializer,\n }: GeneratorVerbOptions,\n { route, context }: GeneratorOptions,\n) => {\n const isRequestOptions = override?.requestOptions !== false;\n const isFormData = !override?.formData.disabled;\n const isFormUrlEncoded = override?.formUrlEncoded !== false;\n const isExactOptionalPropertyTypes =\n !!context.output.tsconfig?.compilerOptions?.exactOptionalPropertyTypes;\n\n const isSyntheticDefaultImportsAllowed = isSyntheticDefaultImportsAllow(\n context.output.tsconfig,\n );\n\n const bodyForm = generateFormDataAndUrlEncodedFunction({\n formData,\n formUrlEncoded,\n body,\n isFormData,\n isFormUrlEncoded,\n });\n\n if (mutator) {\n const mutatorConfig = generateMutatorConfig({\n route,\n body,\n headers,\n queryParams,\n response,\n verb,\n isFormData,\n isFormUrlEncoded,\n hasSignal: false,\n isExactOptionalPropertyTypes,\n });\n\n const requestOptions = isRequestOptions\n ? generateMutatorRequestOptions(\n override?.requestOptions,\n mutator.hasSecondArg,\n )\n : '';\n\n returnTypesToWrite.set(\n operationName,\n (title?: string) =>\n `export type ${pascal(\n operationName,\n )}Result = NonNullable<Awaited<ReturnType<${\n title\n ? `ReturnType<typeof ${title}>['${operationName}']`\n : `typeof ${operationName}`\n }>>>`,\n );\n\n const propsImplementation =\n mutator.bodyTypeName && body.definition\n ? toObjectString(props, 'implementation').replace(\n new RegExp(`(\\\\w*):\\\\s?${body.definition}`),\n `$1: ${mutator.bodyTypeName}<${body.definition}>`,\n )\n : toObjectString(props, 'implementation');\n\n return `const ${operationName} = (\\n ${propsImplementation}\\n ${\n isRequestOptions && mutator.hasSecondArg\n ? `options${context.output.optionsParamRequired ? '' : '?'}: SecondParameter<typeof ${mutator.name}<${response.definition.success || 'unknown'}>>,`\n : ''\n }) => {${bodyForm}\n return ${mutator.name}<${response.definition.success || 'unknown'}>(\n ${mutatorConfig},\n ${requestOptions});\n }\n `;\n }\n\n const options = generateOptions({\n route,\n body,\n headers,\n queryParams,\n response,\n verb,\n requestOptions: override?.requestOptions,\n isFormData,\n isFormUrlEncoded,\n paramsSerializer,\n paramsSerializerOptions: override?.paramsSerializerOptions,\n isExactOptionalPropertyTypes,\n hasSignal: false,\n });\n\n returnTypesToWrite.set(\n operationName,\n () =>\n `export type ${pascal(operationName)}Result = AxiosResponse<${\n response.definition.success || 'unknown'\n }>`,\n );\n\n return `const ${operationName} = <TData = AxiosResponse<${\n response.definition.success || 'unknown'\n }>>(\\n ${toObjectString(props, 'implementation')} ${\n isRequestOptions ? `options?: AxiosRequestConfig\\n` : ''\n } ): Promise<TData> => {${bodyForm}\n return axios${\n isSyntheticDefaultImportsAllowed ? '' : '.default'\n }.${verb}(${options});\n }\n`;\n};\n\nexport const generateAxiosTitle: ClientTitleBuilder = (title) => {\n const sanTitle = sanitize(title);\n return `get${pascal(sanTitle)}`;\n};\n\nexport const generateAxiosHeader: ClientHeaderBuilder = ({\n title,\n isRequestOptions,\n isMutator,\n noFunction,\n}) => `\n${\n isRequestOptions && isMutator\n ? `type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];\\n\\n`\n : ''\n}\n ${noFunction ? '' : `export const ${title} = () => {\\n`}`;\n\nexport const generateAxiosFooter: ClientFooterBuilder = ({\n operationNames,\n title,\n noFunction,\n hasMutator,\n hasAwaitedType,\n}) => {\n let footer = '';\n\n if (!noFunction) {\n footer += `return {${operationNames.join(',')}}};\\n`;\n }\n\n if (hasMutator && !hasAwaitedType) {\n footer += `\\ntype AwaitedInput<T> = PromiseLike<T> | T;\\n\n type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;\n\\n`;\n }\n\n for (const operationName of operationNames) {\n if (returnTypesToWrite.has(operationName)) {\n const func = returnTypesToWrite.get(operationName)!;\n footer += func(noFunction ? undefined : title) + '\\n';\n }\n }\n\n return footer;\n};\n\nexport const generateAxios = (\n verbOptions: GeneratorVerbOptions,\n options: GeneratorOptions,\n) => {\n const imports = generateVerbImports(verbOptions);\n const implementation = generateAxiosImplementation(verbOptions, options);\n\n return { implementation, imports };\n};\n\nexport const generateAxiosFunctions: ClientBuilder = async (\n verbOptions,\n options,\n) => {\n const { implementation, imports } = generateAxios(verbOptions, options);\n\n return {\n implementation: 'export ' + implementation,\n imports,\n };\n};\n\nconst axiosClientBuilder: ClientGeneratorsBuilder = {\n client: generateAxios,\n header: generateAxiosHeader,\n dependencies: getAxiosDependencies,\n footer: generateAxiosFooter,\n title: generateAxiosTitle,\n};\n\nconst axiosFunctionsClientBuilder: ClientGeneratorsBuilder = {\n client: generateAxiosFunctions,\n header: (options) => generateAxiosHeader({ ...options, noFunction: true }),\n dependencies: getAxiosDependencies,\n footer: (options) => generateAxiosFooter({ ...options, noFunction: true }),\n title: generateAxiosTitle,\n};\n\nconst builders: Record<'axios' | 'axios-functions', ClientGeneratorsBuilder> = {\n axios: axiosClientBuilder,\n 'axios-functions': axiosFunctionsClientBuilder,\n};\n\nexport const builder =\n ({ type = 'axios-functions' }: { type?: 'axios' | 'axios-functions' } = {}) =>\n () =>\n builders[type];\n\nexport default builder;\n"],"mappings":";;;AAqBA,MAAMA,qBAA4C,CAChD;CACE,SAAS;EACP;GACE,MAAM;GACN,SAAS;GACT,QAAQ;GACR,wBAAwB;GACzB;EACD,EAAE,MAAM,sBAAsB;EAC9B,EAAE,MAAM,iBAAiB;EAC1B;CACD,YAAY;CACb,CACF;AAED,MAAMC,iCAAwD,CAC5D;CACE,SAAS,CACP;EACE,MAAM;EACN,SAAS;EACT,QAAQ;EACR,wBAAwB;EACzB,CACF;CACD,YAAY;CACb,CACF;AAED,MAAM,qCAAqB,IAAI,KAAyC;AAExE,MAAaC,wBACX,kBACA,+BACG,CACH,GAAI,mBAAmB,EAAE,GAAG,oBAC5B,GAAI,6BAA6B,iCAAiC,EAAE,CACrE;AAED,MAAM,+BACJ,EACE,SACA,aACA,eACA,UACA,SACA,MACA,OACA,MACA,UACA,UACA,gBACA,oBAEF,EAAE,OAAO,cACN;CACH,MAAM,mBAAmB,UAAU,mBAAmB;CACtD,MAAM,aAAa,CAAC,UAAU,SAAS;CACvC,MAAM,mBAAmB,UAAU,mBAAmB;CACtD,MAAM,+BACJ,CAA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.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orval/axios",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-rc.0",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"exports": {
|
|
6
|
-
"
|
|
7
|
+
"import": {
|
|
7
8
|
"types": "./dist/index.d.ts",
|
|
8
|
-
"
|
|
9
|
+
"import": "./dist/index.js"
|
|
9
10
|
}
|
|
10
11
|
},
|
|
11
12
|
"files": [
|
|
@@ -20,12 +21,13 @@
|
|
|
20
21
|
"nuke": "rimraf .turbo dist node_modules"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@orval/core": "
|
|
24
|
+
"@orval/core": "8.0.0-rc.0"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"eslint": "^9.
|
|
27
|
+
"eslint": "^9.38.0",
|
|
27
28
|
"rimraf": "^6.0.1",
|
|
28
|
-
"tsdown": "^0.15.
|
|
29
|
-
"typescript": "^5.9.
|
|
30
|
-
}
|
|
29
|
+
"tsdown": "^0.15.9",
|
|
30
|
+
"typescript": "^5.9.3"
|
|
31
|
+
},
|
|
32
|
+
"stableVersion": "7.15.0"
|
|
31
33
|
}
|