@bagelink/sdk 1.12.61 → 1.12.67
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 +28 -5
- package/dist/index.mjs +28 -5
- package/package.json +1 -1
- package/src/openAPITools/functionGenerator.ts +44 -5
package/dist/index.cjs
CHANGED
|
@@ -606,7 +606,7 @@ function generateStreamTypeName(path) {
|
|
|
606
606
|
path.split("/").filter((p) => p && !/\{|\}/.test(p)).join("_")
|
|
607
607
|
)}StreamEvents`;
|
|
608
608
|
}
|
|
609
|
-
function generateStreamFunction(method, path, formattedPath, allParams, requestBodyPayload, eventTypes) {
|
|
609
|
+
function generateStreamFunction(method, path, formattedPath, allParams, requestBodyPayload, eventTypes, queryParams) {
|
|
610
610
|
if (allParams === "undefined") {
|
|
611
611
|
allParams = "";
|
|
612
612
|
}
|
|
@@ -649,6 +649,28 @@ function generateStreamFunction(method, path, formattedPath, allParams, requestB
|
|
|
649
649
|
}
|
|
650
650
|
}`;
|
|
651
651
|
} else {
|
|
652
|
+
let queryStringCode = "";
|
|
653
|
+
if (queryParams?.length) {
|
|
654
|
+
const paramEntries = queryParams.map((p) => {
|
|
655
|
+
const match = p.match(/^'([^']+)':\s*(.+)$/);
|
|
656
|
+
if (match) return { key: match[1], varName: match[2] };
|
|
657
|
+
return { key: p, varName: p };
|
|
658
|
+
});
|
|
659
|
+
const conditions = paramEntries.map(
|
|
660
|
+
({ key, varName }) => `if (${varName}) __qs.set('${key}', String(${varName}))`
|
|
661
|
+
).join("\n ");
|
|
662
|
+
queryStringCode = [
|
|
663
|
+
`const __qs = new URLSearchParams()`,
|
|
664
|
+
conditions,
|
|
665
|
+
`const __qsSuffix = __qs.size ? "?" + __qs.toString() : ""`
|
|
666
|
+
].join("\n ");
|
|
667
|
+
}
|
|
668
|
+
const regularParamStr = queryParams?.length ? `, { params: {${queryParams.join(", ")}} }` : "";
|
|
669
|
+
const urlLine = queryParams?.length ? `const url = \`\${${baseUrlRef}}${pathForUrl}\` + __qsSuffix` : `const url = \`\${${baseUrlRef}}${pathForUrl}\``;
|
|
670
|
+
const streamBody = queryParams?.length ? `
|
|
671
|
+
${queryStringCode}
|
|
672
|
+
${urlLine}` : `
|
|
673
|
+
${urlLine}`;
|
|
652
674
|
return `{
|
|
653
675
|
/**
|
|
654
676
|
* Stream SSE events from this endpoint (returns StreamController)${eventTypesComment}
|
|
@@ -661,15 +683,14 @@ function generateStreamFunction(method, path, formattedPath, allParams, requestB
|
|
|
661
683
|
* // Close stream when needed
|
|
662
684
|
* stream.close()
|
|
663
685
|
*/
|
|
664
|
-
stream: (${streamParams}): ${typeAnnotation} => {
|
|
665
|
-
const url = \`\${${baseUrlRef}}${pathForUrl}\`
|
|
686
|
+
stream: (${streamParams}): ${typeAnnotation} => {${streamBody}
|
|
666
687
|
return createSSEStream<${streamTypeName}>(url, options)
|
|
667
688
|
},
|
|
668
689
|
/**
|
|
669
690
|
* Regular GET request (non-streaming)
|
|
670
691
|
*/
|
|
671
692
|
get: async (${regularParams}): Promise<AxiosResponse<any>> => {
|
|
672
|
-
return axios.get(${formattedPath})
|
|
693
|
+
return axios.get(${formattedPath}${regularParamStr})
|
|
673
694
|
}
|
|
674
695
|
}`;
|
|
675
696
|
}
|
|
@@ -781,13 +802,15 @@ function generateFunctionForOperation(method, path, operation) {
|
|
|
781
802
|
streamEventSchemas[streamTypeName] = eventSchemas;
|
|
782
803
|
Object.values(eventSchemas).forEach((tsType) => collectTypeForImportStatement(tsType));
|
|
783
804
|
}
|
|
805
|
+
const queryParams = parameters.config?.params ? parameters.config.params.split(",").map((p) => p.trim()).filter(Boolean) : void 0;
|
|
784
806
|
return functionComment + generateStreamFunction(
|
|
785
807
|
method,
|
|
786
808
|
path,
|
|
787
809
|
formatPathWithParams(path),
|
|
788
810
|
allParams,
|
|
789
811
|
requestBodyPayload,
|
|
790
|
-
eventTypes
|
|
812
|
+
eventTypes,
|
|
813
|
+
queryParams
|
|
791
814
|
);
|
|
792
815
|
}
|
|
793
816
|
return functionComment + generateAxiosFunction(
|
package/dist/index.mjs
CHANGED
|
@@ -600,7 +600,7 @@ function generateStreamTypeName(path) {
|
|
|
600
600
|
path.split("/").filter((p) => p && !/\{|\}/.test(p)).join("_")
|
|
601
601
|
)}StreamEvents`;
|
|
602
602
|
}
|
|
603
|
-
function generateStreamFunction(method, path, formattedPath, allParams, requestBodyPayload, eventTypes) {
|
|
603
|
+
function generateStreamFunction(method, path, formattedPath, allParams, requestBodyPayload, eventTypes, queryParams) {
|
|
604
604
|
if (allParams === "undefined") {
|
|
605
605
|
allParams = "";
|
|
606
606
|
}
|
|
@@ -643,6 +643,28 @@ function generateStreamFunction(method, path, formattedPath, allParams, requestB
|
|
|
643
643
|
}
|
|
644
644
|
}`;
|
|
645
645
|
} else {
|
|
646
|
+
let queryStringCode = "";
|
|
647
|
+
if (queryParams?.length) {
|
|
648
|
+
const paramEntries = queryParams.map((p) => {
|
|
649
|
+
const match = p.match(/^'([^']+)':\s*(.+)$/);
|
|
650
|
+
if (match) return { key: match[1], varName: match[2] };
|
|
651
|
+
return { key: p, varName: p };
|
|
652
|
+
});
|
|
653
|
+
const conditions = paramEntries.map(
|
|
654
|
+
({ key, varName }) => `if (${varName}) __qs.set('${key}', String(${varName}))`
|
|
655
|
+
).join("\n ");
|
|
656
|
+
queryStringCode = [
|
|
657
|
+
`const __qs = new URLSearchParams()`,
|
|
658
|
+
conditions,
|
|
659
|
+
`const __qsSuffix = __qs.size ? "?" + __qs.toString() : ""`
|
|
660
|
+
].join("\n ");
|
|
661
|
+
}
|
|
662
|
+
const regularParamStr = queryParams?.length ? `, { params: {${queryParams.join(", ")}} }` : "";
|
|
663
|
+
const urlLine = queryParams?.length ? `const url = \`\${${baseUrlRef}}${pathForUrl}\` + __qsSuffix` : `const url = \`\${${baseUrlRef}}${pathForUrl}\``;
|
|
664
|
+
const streamBody = queryParams?.length ? `
|
|
665
|
+
${queryStringCode}
|
|
666
|
+
${urlLine}` : `
|
|
667
|
+
${urlLine}`;
|
|
646
668
|
return `{
|
|
647
669
|
/**
|
|
648
670
|
* Stream SSE events from this endpoint (returns StreamController)${eventTypesComment}
|
|
@@ -655,15 +677,14 @@ function generateStreamFunction(method, path, formattedPath, allParams, requestB
|
|
|
655
677
|
* // Close stream when needed
|
|
656
678
|
* stream.close()
|
|
657
679
|
*/
|
|
658
|
-
stream: (${streamParams}): ${typeAnnotation} => {
|
|
659
|
-
const url = \`\${${baseUrlRef}}${pathForUrl}\`
|
|
680
|
+
stream: (${streamParams}): ${typeAnnotation} => {${streamBody}
|
|
660
681
|
return createSSEStream<${streamTypeName}>(url, options)
|
|
661
682
|
},
|
|
662
683
|
/**
|
|
663
684
|
* Regular GET request (non-streaming)
|
|
664
685
|
*/
|
|
665
686
|
get: async (${regularParams}): Promise<AxiosResponse<any>> => {
|
|
666
|
-
return axios.get(${formattedPath})
|
|
687
|
+
return axios.get(${formattedPath}${regularParamStr})
|
|
667
688
|
}
|
|
668
689
|
}`;
|
|
669
690
|
}
|
|
@@ -775,13 +796,15 @@ function generateFunctionForOperation(method, path, operation) {
|
|
|
775
796
|
streamEventSchemas[streamTypeName] = eventSchemas;
|
|
776
797
|
Object.values(eventSchemas).forEach((tsType) => collectTypeForImportStatement(tsType));
|
|
777
798
|
}
|
|
799
|
+
const queryParams = parameters.config?.params ? parameters.config.params.split(",").map((p) => p.trim()).filter(Boolean) : void 0;
|
|
778
800
|
return functionComment + generateStreamFunction(
|
|
779
801
|
method,
|
|
780
802
|
path,
|
|
781
803
|
formatPathWithParams(path),
|
|
782
804
|
allParams,
|
|
783
805
|
requestBodyPayload,
|
|
784
|
-
eventTypes
|
|
806
|
+
eventTypes,
|
|
807
|
+
queryParams
|
|
785
808
|
);
|
|
786
809
|
}
|
|
787
810
|
return functionComment + generateAxiosFunction(
|
package/package.json
CHANGED
|
@@ -401,6 +401,7 @@ function generateStreamTypeName(path: string): string {
|
|
|
401
401
|
* @param allParams - The combined parameter string
|
|
402
402
|
* @param requestBodyPayload - The request body payload
|
|
403
403
|
* @param eventTypes - Array of SSE event types
|
|
404
|
+
* @param queryParams - Query/header parameter mappings (e.g. "'run_id': _runId")
|
|
404
405
|
* @returns A string with the SSE stream function
|
|
405
406
|
*/
|
|
406
407
|
function generateStreamFunction(
|
|
@@ -409,7 +410,8 @@ function generateStreamFunction(
|
|
|
409
410
|
formattedPath: string,
|
|
410
411
|
allParams: string,
|
|
411
412
|
requestBodyPayload: string,
|
|
412
|
-
eventTypes?: string[]
|
|
413
|
+
eventTypes?: string[],
|
|
414
|
+
queryParams?: string[]
|
|
413
415
|
): string {
|
|
414
416
|
if (allParams === 'undefined') { allParams = '' }
|
|
415
417
|
|
|
@@ -473,6 +475,38 @@ function generateStreamFunction(
|
|
|
473
475
|
}
|
|
474
476
|
}`
|
|
475
477
|
} else {
|
|
478
|
+
// Build query string construction for GET SSE streams
|
|
479
|
+
let queryStringCode = ''
|
|
480
|
+
if (queryParams?.length) {
|
|
481
|
+
// Generate URLSearchParams code to append query params to the SSE URL
|
|
482
|
+
// Query params use 'original_name': varName mapping format
|
|
483
|
+
const paramEntries = queryParams.map(p => {
|
|
484
|
+
const match = p.match(/^'([^']+)':\s*(.+)$/)
|
|
485
|
+
if (match) return { key: match[1], varName: match[2] }
|
|
486
|
+
// Simple case: param name is the same as var name
|
|
487
|
+
return { key: p, varName: p }
|
|
488
|
+
})
|
|
489
|
+
const conditions = paramEntries.map(({ key, varName }) =>
|
|
490
|
+
`if (${varName}) __qs.set('${key}', String(${varName}))`
|
|
491
|
+
).join('\n ')
|
|
492
|
+
queryStringCode = [
|
|
493
|
+
`const __qs = new URLSearchParams()`,
|
|
494
|
+
conditions,
|
|
495
|
+
`const __qsSuffix = __qs.size ? "?" + __qs.toString() : ""`,
|
|
496
|
+
].join('\n ')
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const regularParamStr = queryParams?.length ? `, { params: {${queryParams.join(', ')}} }` : ''
|
|
500
|
+
|
|
501
|
+
// For GET streams with query params, build URL with suffix; otherwise plain URL
|
|
502
|
+
const urlLine = queryParams?.length
|
|
503
|
+
? `const url = \`\${${baseUrlRef}}${pathForUrl}\` + __qsSuffix`
|
|
504
|
+
: `const url = \`\${${baseUrlRef}}${pathForUrl}\``
|
|
505
|
+
|
|
506
|
+
const streamBody = queryParams?.length
|
|
507
|
+
? `\n ${queryStringCode}\n ${urlLine}`
|
|
508
|
+
: `\n ${urlLine}`
|
|
509
|
+
|
|
476
510
|
return `{
|
|
477
511
|
/**
|
|
478
512
|
* Stream SSE events from this endpoint (returns StreamController)${eventTypesComment}
|
|
@@ -485,15 +519,14 @@ function generateStreamFunction(
|
|
|
485
519
|
* // Close stream when needed
|
|
486
520
|
* stream.close()
|
|
487
521
|
*/
|
|
488
|
-
stream: (${streamParams}): ${typeAnnotation} => {
|
|
489
|
-
const url = \`\${${baseUrlRef}}${pathForUrl}\`
|
|
522
|
+
stream: (${streamParams}): ${typeAnnotation} => {${streamBody}
|
|
490
523
|
return createSSEStream<${streamTypeName}>(url, options)
|
|
491
524
|
},
|
|
492
525
|
/**
|
|
493
526
|
* Regular GET request (non-streaming)
|
|
494
527
|
*/
|
|
495
528
|
get: async (${regularParams}): Promise<AxiosResponse<any>> => {
|
|
496
|
-
return axios.get(${formattedPath})
|
|
529
|
+
return axios.get(${formattedPath}${regularParamStr})
|
|
497
530
|
}
|
|
498
531
|
}`
|
|
499
532
|
}
|
|
@@ -690,13 +723,19 @@ function generateFunctionForOperation(
|
|
|
690
723
|
Object.values(eventSchemas).forEach(tsType => collectTypeForImportStatement(tsType))
|
|
691
724
|
}
|
|
692
725
|
|
|
726
|
+
// Extract query param mappings for GET SSE streams (e.g. "'run_id': _runId")
|
|
727
|
+
const queryParams = parameters.config?.params
|
|
728
|
+
? parameters.config.params.split(',').map(p => p.trim()).filter(Boolean)
|
|
729
|
+
: undefined
|
|
730
|
+
|
|
693
731
|
return functionComment + generateStreamFunction(
|
|
694
732
|
method,
|
|
695
733
|
path,
|
|
696
734
|
formatPathWithParams(path),
|
|
697
735
|
allParams,
|
|
698
736
|
requestBodyPayload,
|
|
699
|
-
eventTypes
|
|
737
|
+
eventTypes,
|
|
738
|
+
queryParams
|
|
700
739
|
)
|
|
701
740
|
}
|
|
702
741
|
|