@bagelink/sdk 1.4.184 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +23 -2
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +23 -2
- package/package.json +1 -1
- package/src/index.ts +3 -1
- package/src/openAPITools/functionGenerator.ts +53 -6
package/dist/index.cjs
CHANGED
|
@@ -385,6 +385,17 @@ function generateFunctionParameters(params, isFileUpload = false) {
|
|
|
385
385
|
config: queryParams.length ? { params: queryParams.join(", ") } : void 0
|
|
386
386
|
};
|
|
387
387
|
}
|
|
388
|
+
function parseParameter(paramStr) {
|
|
389
|
+
const trimmed = paramStr.trim();
|
|
390
|
+
const isOptional = trimmed.includes("?:");
|
|
391
|
+
const nameMatch = trimmed.match(/^([a-z_$][\w$]*)/i);
|
|
392
|
+
const name = nameMatch ? nameMatch[1] : "";
|
|
393
|
+
const typeMatch = trimmed.match(/:\s*([^=]+)/);
|
|
394
|
+
const type = typeMatch ? typeMatch[1].trim() : "any";
|
|
395
|
+
const defaultMatch = trimmed.match(/=(.+)$/);
|
|
396
|
+
const defaultValue = defaultMatch ? defaultMatch[1].trim() : void 0;
|
|
397
|
+
return { name, type, defaultValue, isOptional };
|
|
398
|
+
}
|
|
388
399
|
function combineAllParams(parameters, requestBodyParam) {
|
|
389
400
|
let allParamsArray = [];
|
|
390
401
|
if (parameters.params) {
|
|
@@ -393,7 +404,15 @@ function combineAllParams(parameters, requestBodyParam) {
|
|
|
393
404
|
if (requestBodyParam) {
|
|
394
405
|
allParamsArray.push(requestBodyParam.trim());
|
|
395
406
|
}
|
|
396
|
-
|
|
407
|
+
if (allParamsArray.length === 0) {
|
|
408
|
+
return "";
|
|
409
|
+
}
|
|
410
|
+
const parsedParams = allParamsArray.filter(Boolean).map(parseParameter);
|
|
411
|
+
const destructuredNames = parsedParams.map((p) => p.defaultValue ? `${p.name} = ${p.defaultValue}` : p.name).join(", ");
|
|
412
|
+
const typeDefinition = parsedParams.map((p) => {
|
|
413
|
+
return `${p.name}?: ${p.type}`;
|
|
414
|
+
}).join(", ");
|
|
415
|
+
return `{ ${destructuredNames} }: { ${typeDefinition} } = {}`;
|
|
397
416
|
}
|
|
398
417
|
function generateAxiosFunction(method, formattedPath, allParams, responseTypeStr, parameters, requestBodyPayload) {
|
|
399
418
|
if (allParams === "undefined") allParams = "";
|
|
@@ -795,10 +814,12 @@ class BagelAuth {
|
|
|
795
814
|
class Bagel {
|
|
796
815
|
host;
|
|
797
816
|
fileBaseUrl;
|
|
817
|
+
fileVersion;
|
|
798
818
|
onError;
|
|
799
|
-
constructor({ host, fileBaseUrl, onError }) {
|
|
819
|
+
constructor({ host, fileBaseUrl, fileVersion, onError }) {
|
|
800
820
|
this.host = host?.replace(/\/$/, "");
|
|
801
821
|
this.fileBaseUrl = fileBaseUrl?.replace(/\/$/, "");
|
|
822
|
+
this.fileVersion = fileVersion || "files";
|
|
802
823
|
if (!this.host) {
|
|
803
824
|
return this;
|
|
804
825
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -425,8 +425,9 @@ declare class BagelAuth {
|
|
|
425
425
|
declare class Bagel {
|
|
426
426
|
host?: string;
|
|
427
427
|
fileBaseUrl?: string;
|
|
428
|
+
fileVersion: string;
|
|
428
429
|
onError?: (err: any) => void;
|
|
429
|
-
constructor({ host, fileBaseUrl, onError }: {
|
|
430
|
+
constructor({ host, fileBaseUrl, fileVersion, onError }: {
|
|
430
431
|
[key: string]: any;
|
|
431
432
|
});
|
|
432
433
|
read_table: Tables | undefined;
|
package/dist/index.d.mts
CHANGED
|
@@ -425,8 +425,9 @@ declare class BagelAuth {
|
|
|
425
425
|
declare class Bagel {
|
|
426
426
|
host?: string;
|
|
427
427
|
fileBaseUrl?: string;
|
|
428
|
+
fileVersion: string;
|
|
428
429
|
onError?: (err: any) => void;
|
|
429
|
-
constructor({ host, fileBaseUrl, onError }: {
|
|
430
|
+
constructor({ host, fileBaseUrl, fileVersion, onError }: {
|
|
430
431
|
[key: string]: any;
|
|
431
432
|
});
|
|
432
433
|
read_table: Tables | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -425,8 +425,9 @@ declare class BagelAuth {
|
|
|
425
425
|
declare class Bagel {
|
|
426
426
|
host?: string;
|
|
427
427
|
fileBaseUrl?: string;
|
|
428
|
+
fileVersion: string;
|
|
428
429
|
onError?: (err: any) => void;
|
|
429
|
-
constructor({ host, fileBaseUrl, onError }: {
|
|
430
|
+
constructor({ host, fileBaseUrl, fileVersion, onError }: {
|
|
430
431
|
[key: string]: any;
|
|
431
432
|
});
|
|
432
433
|
read_table: Tables | undefined;
|
package/dist/index.mjs
CHANGED
|
@@ -379,6 +379,17 @@ function generateFunctionParameters(params, isFileUpload = false) {
|
|
|
379
379
|
config: queryParams.length ? { params: queryParams.join(", ") } : void 0
|
|
380
380
|
};
|
|
381
381
|
}
|
|
382
|
+
function parseParameter(paramStr) {
|
|
383
|
+
const trimmed = paramStr.trim();
|
|
384
|
+
const isOptional = trimmed.includes("?:");
|
|
385
|
+
const nameMatch = trimmed.match(/^([a-z_$][\w$]*)/i);
|
|
386
|
+
const name = nameMatch ? nameMatch[1] : "";
|
|
387
|
+
const typeMatch = trimmed.match(/:\s*([^=]+)/);
|
|
388
|
+
const type = typeMatch ? typeMatch[1].trim() : "any";
|
|
389
|
+
const defaultMatch = trimmed.match(/=(.+)$/);
|
|
390
|
+
const defaultValue = defaultMatch ? defaultMatch[1].trim() : void 0;
|
|
391
|
+
return { name, type, defaultValue, isOptional };
|
|
392
|
+
}
|
|
382
393
|
function combineAllParams(parameters, requestBodyParam) {
|
|
383
394
|
let allParamsArray = [];
|
|
384
395
|
if (parameters.params) {
|
|
@@ -387,7 +398,15 @@ function combineAllParams(parameters, requestBodyParam) {
|
|
|
387
398
|
if (requestBodyParam) {
|
|
388
399
|
allParamsArray.push(requestBodyParam.trim());
|
|
389
400
|
}
|
|
390
|
-
|
|
401
|
+
if (allParamsArray.length === 0) {
|
|
402
|
+
return "";
|
|
403
|
+
}
|
|
404
|
+
const parsedParams = allParamsArray.filter(Boolean).map(parseParameter);
|
|
405
|
+
const destructuredNames = parsedParams.map((p) => p.defaultValue ? `${p.name} = ${p.defaultValue}` : p.name).join(", ");
|
|
406
|
+
const typeDefinition = parsedParams.map((p) => {
|
|
407
|
+
return `${p.name}?: ${p.type}`;
|
|
408
|
+
}).join(", ");
|
|
409
|
+
return `{ ${destructuredNames} }: { ${typeDefinition} } = {}`;
|
|
391
410
|
}
|
|
392
411
|
function generateAxiosFunction(method, formattedPath, allParams, responseTypeStr, parameters, requestBodyPayload) {
|
|
393
412
|
if (allParams === "undefined") allParams = "";
|
|
@@ -789,10 +808,12 @@ class BagelAuth {
|
|
|
789
808
|
class Bagel {
|
|
790
809
|
host;
|
|
791
810
|
fileBaseUrl;
|
|
811
|
+
fileVersion;
|
|
792
812
|
onError;
|
|
793
|
-
constructor({ host, fileBaseUrl, onError }) {
|
|
813
|
+
constructor({ host, fileBaseUrl, fileVersion, onError }) {
|
|
794
814
|
this.host = host?.replace(/\/$/, "");
|
|
795
815
|
this.fileBaseUrl = fileBaseUrl?.replace(/\/$/, "");
|
|
816
|
+
this.fileVersion = fileVersion || "files";
|
|
796
817
|
if (!this.host) {
|
|
797
818
|
return this;
|
|
798
819
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -188,12 +188,14 @@ class BagelAuth {
|
|
|
188
188
|
export class Bagel {
|
|
189
189
|
host?: string
|
|
190
190
|
fileBaseUrl?: string
|
|
191
|
+
fileVersion: string
|
|
191
192
|
|
|
192
193
|
onError?: (err: any) => void
|
|
193
194
|
|
|
194
|
-
constructor({ host, fileBaseUrl, onError }: { [key: string]: any }) {
|
|
195
|
+
constructor({ host, fileBaseUrl, fileVersion, onError }: { [key: string]: any }) {
|
|
195
196
|
this.host = host?.replace(/\/$/, '')
|
|
196
197
|
this.fileBaseUrl = fileBaseUrl?.replace(/\/$/, '')
|
|
198
|
+
this.fileVersion = fileVersion || 'files' // Default to 'files_v2'
|
|
197
199
|
if (!this.host) {
|
|
198
200
|
return this
|
|
199
201
|
}
|
|
@@ -266,10 +266,41 @@ function generateFunctionParameters(
|
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
/**
|
|
269
|
-
*
|
|
269
|
+
* Parses a parameter string into name, type, and default value
|
|
270
|
+
* @param paramStr - The parameter string to parse
|
|
271
|
+
* @returns Object containing parsed parameter information
|
|
272
|
+
*/
|
|
273
|
+
function parseParameter(paramStr: string): {
|
|
274
|
+
name: string
|
|
275
|
+
type: string
|
|
276
|
+
defaultValue?: string
|
|
277
|
+
isOptional: boolean
|
|
278
|
+
} {
|
|
279
|
+
const trimmed = paramStr.trim()
|
|
280
|
+
|
|
281
|
+
// Check if parameter is optional (has ?)
|
|
282
|
+
const isOptional = trimmed.includes('?:')
|
|
283
|
+
|
|
284
|
+
// Extract parameter name
|
|
285
|
+
const nameMatch = trimmed.match(/^([a-z_$][\w$]*)/i)
|
|
286
|
+
const name = nameMatch ? nameMatch[1] : ''
|
|
287
|
+
|
|
288
|
+
// Extract type (between : and = or end of string)
|
|
289
|
+
const typeMatch = trimmed.match(/:\s*([^=]+)/)
|
|
290
|
+
const type = typeMatch ? typeMatch[1].trim() : 'any'
|
|
291
|
+
|
|
292
|
+
// Extract default value if exists
|
|
293
|
+
const defaultMatch = trimmed.match(/=(.+)$/)
|
|
294
|
+
const defaultValue = defaultMatch ? defaultMatch[1].trim() : undefined
|
|
295
|
+
|
|
296
|
+
return { name, type, defaultValue, isOptional }
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Combines and formats all parameters into a single object destructuring parameter
|
|
270
301
|
* @param parameters - The parameters object
|
|
271
302
|
* @param requestBodyParam - The request body parameter
|
|
272
|
-
* @returns A formatted parameter string
|
|
303
|
+
* @returns A formatted parameter string with object destructuring
|
|
273
304
|
*/
|
|
274
305
|
function combineAllParams(
|
|
275
306
|
parameters: { params?: string },
|
|
@@ -285,11 +316,27 @@ function combineAllParams(
|
|
|
285
316
|
allParamsArray.push(requestBodyParam.trim())
|
|
286
317
|
}
|
|
287
318
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
319
|
+
if (allParamsArray.length === 0) {
|
|
320
|
+
return ''
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Parse all parameters
|
|
324
|
+
const parsedParams = allParamsArray.filter(Boolean).map(parseParameter)
|
|
325
|
+
|
|
326
|
+
// Build destructuring pattern with default values
|
|
327
|
+
const destructuredNames = parsedParams
|
|
328
|
+
.map(p => p.defaultValue ? `${p.name} = ${p.defaultValue}` : p.name)
|
|
292
329
|
.join(', ')
|
|
330
|
+
|
|
331
|
+
// Build type definition - all parameters should be optional in the type
|
|
332
|
+
const typeDefinition = parsedParams
|
|
333
|
+
.map((p) => {
|
|
334
|
+
// Remove default value from type, make all optional
|
|
335
|
+
return `${p.name}?: ${p.type}`
|
|
336
|
+
})
|
|
337
|
+
.join(', ')
|
|
338
|
+
|
|
339
|
+
return `{ ${destructuredNames} }: { ${typeDefinition} } = {}`
|
|
293
340
|
}
|
|
294
341
|
|
|
295
342
|
/**
|