@bagelink/sdk 1.15.409 → 1.15.417
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.cjs +11 -5
- package/dist/index.mjs +11 -5
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/src/openAPITools/functionGenerator.ts +11 -5
package/dist/index.cjs
CHANGED
|
@@ -695,7 +695,7 @@ function generateStreamFunction(method, path, formattedPath, allParams, requestB
|
|
|
695
695
|
}`;
|
|
696
696
|
}
|
|
697
697
|
}
|
|
698
|
-
function generateAxiosFunction(method, formattedPath, allParams, responseTypeStr, parameters, requestBodyPayload) {
|
|
698
|
+
function generateAxiosFunction(method, formattedPath, allParams, responseTypeStr, parameters, requestBodyPayload, isPrimitiveResponse) {
|
|
699
699
|
if (allParams === "undefined") {
|
|
700
700
|
allParams = "";
|
|
701
701
|
}
|
|
@@ -704,6 +704,7 @@ function generateAxiosFunction(method, formattedPath, allParams, responseTypeStr
|
|
|
704
704
|
"Promise<ApiResponse<$1>>"
|
|
705
705
|
);
|
|
706
706
|
let axiosFunction = `async (${allParams})${apiResponseType} => {`;
|
|
707
|
+
const returnExpression = isPrimitiveResponse ? "response.data" : "ApiResponse.create(response.data, response)";
|
|
707
708
|
const paramStr = parameters.config?.params ? `params: {${parameters.config.params}}` : "";
|
|
708
709
|
if (requestBodyPayload === "formData") {
|
|
709
710
|
if (allParams.includes("file: File")) {
|
|
@@ -715,20 +716,20 @@ function generateAxiosFunction(method, formattedPath, allParams, responseTypeStr
|
|
|
715
716
|
headers: { 'Content-Type': 'multipart/form-data' },
|
|
716
717
|
onUploadProgress: options?.onUploadProgress${paramStr ? `, ${paramStr}` : ""}
|
|
717
718
|
})
|
|
718
|
-
return
|
|
719
|
+
return ${returnExpression}`;
|
|
719
720
|
} else {
|
|
720
721
|
axiosFunction += `
|
|
721
722
|
const response = await axios.${method}(${formattedPath}, formData, {
|
|
722
723
|
headers: { 'Content-Type': 'multipart/form-data' }${paramStr ? `, ${paramStr}` : ""}
|
|
723
724
|
})
|
|
724
|
-
return
|
|
725
|
+
return ${returnExpression}`;
|
|
725
726
|
}
|
|
726
727
|
} else {
|
|
727
728
|
const configParams = paramStr ? `, { ${paramStr} }` : "";
|
|
728
729
|
const bodyVar = requestBodyPayload || "{}";
|
|
729
730
|
axiosFunction += `
|
|
730
731
|
const response = await axios.${method}(${formattedPath}${["get", "delete"].includes(method) ? configParams : `, ${bodyVar}${configParams}`})
|
|
731
|
-
return
|
|
732
|
+
return ${returnExpression}`;
|
|
732
733
|
}
|
|
733
734
|
axiosFunction += "}";
|
|
734
735
|
return axiosFunction;
|
|
@@ -788,6 +789,7 @@ function generateFunctionForOperation(method, path, operation) {
|
|
|
788
789
|
);
|
|
789
790
|
const allParams = isFileUpload ? "file: File, options?: UploadOptions & { dirPath?: string, tags?: string[] }" : combineAllParams(parameters, requestBodyParam);
|
|
790
791
|
const { type: responseType, isArray: isArrayResponse } = generateResponseType(operation.responses);
|
|
792
|
+
const isPrimitiveResponse = primitiveTypes.includes(responseType);
|
|
791
793
|
const responseTypeStr = responseType ? isArrayResponse ? `: Promise<ApiResponse<${responseType}>>` : `: Promise<${responseType}>` : "";
|
|
792
794
|
const functionComment = buildJSDocComment(operation, method, path);
|
|
793
795
|
if (isStream) {
|
|
@@ -819,7 +821,8 @@ function generateFunctionForOperation(method, path, operation) {
|
|
|
819
821
|
allParams,
|
|
820
822
|
responseTypeStr,
|
|
821
823
|
parameters,
|
|
822
|
-
requestBodyPayload
|
|
824
|
+
requestBodyPayload,
|
|
825
|
+
isPrimitiveResponse
|
|
823
826
|
);
|
|
824
827
|
}
|
|
825
828
|
function hasConflict(path, method) {
|
|
@@ -1608,6 +1611,9 @@ class ApiResponse extends Array {
|
|
|
1608
1611
|
* Factory method to handle both arrays and objects
|
|
1609
1612
|
*/
|
|
1610
1613
|
static create(data, response) {
|
|
1614
|
+
if (data === null || typeof data !== "object") {
|
|
1615
|
+
return data;
|
|
1616
|
+
}
|
|
1611
1617
|
if (!Array.isArray(data)) {
|
|
1612
1618
|
const obj = Object.assign(/* @__PURE__ */ Object.create(null), data);
|
|
1613
1619
|
obj.$raw = response;
|
package/dist/index.mjs
CHANGED
|
@@ -689,7 +689,7 @@ function generateStreamFunction(method, path, formattedPath, allParams, requestB
|
|
|
689
689
|
}`;
|
|
690
690
|
}
|
|
691
691
|
}
|
|
692
|
-
function generateAxiosFunction(method, formattedPath, allParams, responseTypeStr, parameters, requestBodyPayload) {
|
|
692
|
+
function generateAxiosFunction(method, formattedPath, allParams, responseTypeStr, parameters, requestBodyPayload, isPrimitiveResponse) {
|
|
693
693
|
if (allParams === "undefined") {
|
|
694
694
|
allParams = "";
|
|
695
695
|
}
|
|
@@ -698,6 +698,7 @@ function generateAxiosFunction(method, formattedPath, allParams, responseTypeStr
|
|
|
698
698
|
"Promise<ApiResponse<$1>>"
|
|
699
699
|
);
|
|
700
700
|
let axiosFunction = `async (${allParams})${apiResponseType} => {`;
|
|
701
|
+
const returnExpression = isPrimitiveResponse ? "response.data" : "ApiResponse.create(response.data, response)";
|
|
701
702
|
const paramStr = parameters.config?.params ? `params: {${parameters.config.params}}` : "";
|
|
702
703
|
if (requestBodyPayload === "formData") {
|
|
703
704
|
if (allParams.includes("file: File")) {
|
|
@@ -709,20 +710,20 @@ function generateAxiosFunction(method, formattedPath, allParams, responseTypeStr
|
|
|
709
710
|
headers: { 'Content-Type': 'multipart/form-data' },
|
|
710
711
|
onUploadProgress: options?.onUploadProgress${paramStr ? `, ${paramStr}` : ""}
|
|
711
712
|
})
|
|
712
|
-
return
|
|
713
|
+
return ${returnExpression}`;
|
|
713
714
|
} else {
|
|
714
715
|
axiosFunction += `
|
|
715
716
|
const response = await axios.${method}(${formattedPath}, formData, {
|
|
716
717
|
headers: { 'Content-Type': 'multipart/form-data' }${paramStr ? `, ${paramStr}` : ""}
|
|
717
718
|
})
|
|
718
|
-
return
|
|
719
|
+
return ${returnExpression}`;
|
|
719
720
|
}
|
|
720
721
|
} else {
|
|
721
722
|
const configParams = paramStr ? `, { ${paramStr} }` : "";
|
|
722
723
|
const bodyVar = requestBodyPayload || "{}";
|
|
723
724
|
axiosFunction += `
|
|
724
725
|
const response = await axios.${method}(${formattedPath}${["get", "delete"].includes(method) ? configParams : `, ${bodyVar}${configParams}`})
|
|
725
|
-
return
|
|
726
|
+
return ${returnExpression}`;
|
|
726
727
|
}
|
|
727
728
|
axiosFunction += "}";
|
|
728
729
|
return axiosFunction;
|
|
@@ -782,6 +783,7 @@ function generateFunctionForOperation(method, path, operation) {
|
|
|
782
783
|
);
|
|
783
784
|
const allParams = isFileUpload ? "file: File, options?: UploadOptions & { dirPath?: string, tags?: string[] }" : combineAllParams(parameters, requestBodyParam);
|
|
784
785
|
const { type: responseType, isArray: isArrayResponse } = generateResponseType(operation.responses);
|
|
786
|
+
const isPrimitiveResponse = primitiveTypes.includes(responseType);
|
|
785
787
|
const responseTypeStr = responseType ? isArrayResponse ? `: Promise<ApiResponse<${responseType}>>` : `: Promise<${responseType}>` : "";
|
|
786
788
|
const functionComment = buildJSDocComment(operation, method, path);
|
|
787
789
|
if (isStream) {
|
|
@@ -813,7 +815,8 @@ function generateFunctionForOperation(method, path, operation) {
|
|
|
813
815
|
allParams,
|
|
814
816
|
responseTypeStr,
|
|
815
817
|
parameters,
|
|
816
|
-
requestBodyPayload
|
|
818
|
+
requestBodyPayload,
|
|
819
|
+
isPrimitiveResponse
|
|
817
820
|
);
|
|
818
821
|
}
|
|
819
822
|
function hasConflict(path, method) {
|
|
@@ -1602,6 +1605,9 @@ class ApiResponse extends Array {
|
|
|
1602
1605
|
* Factory method to handle both arrays and objects
|
|
1603
1606
|
*/
|
|
1604
1607
|
static create(data, response) {
|
|
1608
|
+
if (data === null || typeof data !== "object") {
|
|
1609
|
+
return data;
|
|
1610
|
+
}
|
|
1605
1611
|
if (!Array.isArray(data)) {
|
|
1606
1612
|
const obj = Object.assign(/* @__PURE__ */ Object.create(null), data);
|
|
1607
1613
|
obj.$raw = response;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -107,6 +107,12 @@ export class ApiResponse<TData = any> extends Array<TData extends Array<infer U>
|
|
|
107
107
|
* Factory method to handle both arrays and objects
|
|
108
108
|
*/
|
|
109
109
|
static create<T>(data: T, response: AxiosResponse): any {
|
|
110
|
+
// Primitive payloads cannot carry response metadata. Return them as-is
|
|
111
|
+
// instead of boxing them into an object that loses the actual value.
|
|
112
|
+
if (data === null || typeof data !== 'object') {
|
|
113
|
+
return data
|
|
114
|
+
}
|
|
115
|
+
|
|
110
116
|
// For single objects, attach metadata directly
|
|
111
117
|
if (!Array.isArray(data)) {
|
|
112
118
|
const obj = Object.assign(Object.create(null), data) as any
|
|
@@ -548,7 +548,8 @@ function generateAxiosFunction(
|
|
|
548
548
|
allParams: string,
|
|
549
549
|
responseTypeStr: string,
|
|
550
550
|
parameters: { config?: { params?: string } },
|
|
551
|
-
requestBodyPayload: string
|
|
551
|
+
requestBodyPayload: string,
|
|
552
|
+
isPrimitiveResponse: boolean,
|
|
552
553
|
): string {
|
|
553
554
|
if (allParams === 'undefined') { allParams = '' }
|
|
554
555
|
|
|
@@ -559,6 +560,9 @@ function generateAxiosFunction(
|
|
|
559
560
|
)
|
|
560
561
|
|
|
561
562
|
let axiosFunction = `async (${allParams})${apiResponseType} => {`
|
|
563
|
+
const returnExpression = isPrimitiveResponse
|
|
564
|
+
? 'response.data'
|
|
565
|
+
: 'ApiResponse.create(response.data, response)'
|
|
562
566
|
const paramStr = parameters.config?.params
|
|
563
567
|
? `params: {${parameters.config.params}}`
|
|
564
568
|
: ''
|
|
@@ -574,14 +578,14 @@ function generateAxiosFunction(
|
|
|
574
578
|
headers: { 'Content-Type': 'multipart/form-data' },
|
|
575
579
|
onUploadProgress: options?.onUploadProgress${paramStr ? `, ${paramStr}` : ''}
|
|
576
580
|
})
|
|
577
|
-
return
|
|
581
|
+
return ${returnExpression}`
|
|
578
582
|
} else {
|
|
579
583
|
// Generic FormData handling
|
|
580
584
|
axiosFunction += `
|
|
581
585
|
const response = await axios.${method}(${formattedPath}, formData, {
|
|
582
586
|
headers: { 'Content-Type': 'multipart/form-data' }${paramStr ? `, ${paramStr}` : ''}
|
|
583
587
|
})
|
|
584
|
-
return
|
|
588
|
+
return ${returnExpression}`
|
|
585
589
|
}
|
|
586
590
|
} else {
|
|
587
591
|
const configParams = paramStr ? `, { ${paramStr} }` : ''
|
|
@@ -592,7 +596,7 @@ function generateAxiosFunction(
|
|
|
592
596
|
? configParams
|
|
593
597
|
: `, ${bodyVar}${configParams}`
|
|
594
598
|
})
|
|
595
|
-
return
|
|
599
|
+
return ${returnExpression}`
|
|
596
600
|
}
|
|
597
601
|
|
|
598
602
|
axiosFunction += '}'
|
|
@@ -693,6 +697,7 @@ function generateFunctionForOperation(
|
|
|
693
697
|
: combineAllParams(parameters, requestBodyParam)
|
|
694
698
|
|
|
695
699
|
const { type: responseType, isArray: isArrayResponse } = generateResponseType(operation.responses)
|
|
700
|
+
const isPrimitiveResponse = primitiveTypes.includes(responseType)
|
|
696
701
|
|
|
697
702
|
// For arrays: ApiResponse<T[]> (works as array, has metadata)
|
|
698
703
|
// For single objects: T (runtime adds metadata, but type is plain T for assignment)
|
|
@@ -745,7 +750,8 @@ function generateFunctionForOperation(
|
|
|
745
750
|
allParams,
|
|
746
751
|
responseTypeStr,
|
|
747
752
|
parameters,
|
|
748
|
-
requestBodyPayload
|
|
753
|
+
requestBodyPayload,
|
|
754
|
+
isPrimitiveResponse,
|
|
749
755
|
)
|
|
750
756
|
}
|
|
751
757
|
|