@bagelink/sdk 1.4.16 → 1.4.20
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 +21 -3
- 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 +21 -3
- package/package.json +1 -1
- package/src/openAPITools/openApiTypes.ts +2 -0
- package/src/openAPITools/typeGenerator.ts +1 -1
- package/src/openAPITools/utils.ts +32 -17
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,21 @@ function resolveReference(ref) {
|
|
|
21
21
|
if (!t) return "any";
|
|
22
22
|
return formatType(t);
|
|
23
23
|
}
|
|
24
|
+
function handleArrayItems(schema) {
|
|
25
|
+
const itemType = schemaToType(schema.items);
|
|
26
|
+
const needsParentheses = itemType.includes("|") || itemType.includes("&");
|
|
27
|
+
let res = needsParentheses ? `(${itemType})[]` : `${itemType}[]`;
|
|
28
|
+
if (itemType.includes("string | string")) {
|
|
29
|
+
res = res.replace("string | string", "string");
|
|
30
|
+
}
|
|
31
|
+
if (itemType.includes("string |")) {
|
|
32
|
+
return res.replace("string |", "(string & {}) |");
|
|
33
|
+
}
|
|
34
|
+
if (itemType.includes("| string")) {
|
|
35
|
+
return res.replace("| string", "| (string & {})");
|
|
36
|
+
}
|
|
37
|
+
return res;
|
|
38
|
+
}
|
|
24
39
|
function schemaToType(schema) {
|
|
25
40
|
if (!schema) return "any";
|
|
26
41
|
if (schema.anyOf) {
|
|
@@ -36,6 +51,9 @@ function schemaToType(schema) {
|
|
|
36
51
|
case "object":
|
|
37
52
|
return "{ [key: string]: any }";
|
|
38
53
|
case "string":
|
|
54
|
+
if (schema.const) {
|
|
55
|
+
return `'${schema.const}'`;
|
|
56
|
+
}
|
|
39
57
|
return "string";
|
|
40
58
|
case "integer":
|
|
41
59
|
return "number";
|
|
@@ -44,7 +62,7 @@ function schemaToType(schema) {
|
|
|
44
62
|
case "boolean":
|
|
45
63
|
return "boolean";
|
|
46
64
|
case "array":
|
|
47
|
-
return
|
|
65
|
+
return handleArrayItems(schema);
|
|
48
66
|
case "undefined":
|
|
49
67
|
return "undefined";
|
|
50
68
|
case "null":
|
|
@@ -53,7 +71,7 @@ function schemaToType(schema) {
|
|
|
53
71
|
return "any";
|
|
54
72
|
default:
|
|
55
73
|
console.log("Unknown type", schema.type);
|
|
56
|
-
return "
|
|
74
|
+
return "unknown";
|
|
57
75
|
}
|
|
58
76
|
}
|
|
59
77
|
function isOptional(schema) {
|
|
@@ -414,7 +432,7 @@ function generateTypes(schemas) {
|
|
|
414
432
|
`;
|
|
415
433
|
}
|
|
416
434
|
if (schema.type === "array" && schema.items) {
|
|
417
|
-
return `export type ${typeName} = ${schemaToType(schema.items)}[];
|
|
435
|
+
return `export type ${typeName} = (${schemaToType(schema.items)})[];
|
|
418
436
|
`;
|
|
419
437
|
}
|
|
420
438
|
if (!schema.properties) {
|
package/dist/index.d.cts
CHANGED
|
@@ -108,4 +108,5 @@ declare class Bagel {
|
|
|
108
108
|
uploadFile<T>(file: File, options?: UploadOptions): Promise<T>;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
export { Bagel,
|
|
111
|
+
export { Bagel, formatAPIErrorMessage, _default as openAPI };
|
|
112
|
+
export type { TableToTypeMapping, Tables, UploadOptions, User };
|
package/dist/index.d.mts
CHANGED
|
@@ -108,4 +108,5 @@ declare class Bagel {
|
|
|
108
108
|
uploadFile<T>(file: File, options?: UploadOptions): Promise<T>;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
export { Bagel,
|
|
111
|
+
export { Bagel, formatAPIErrorMessage, _default as openAPI };
|
|
112
|
+
export type { TableToTypeMapping, Tables, UploadOptions, User };
|
package/dist/index.d.ts
CHANGED
|
@@ -108,4 +108,5 @@ declare class Bagel {
|
|
|
108
108
|
uploadFile<T>(file: File, options?: UploadOptions): Promise<T>;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
export { Bagel,
|
|
111
|
+
export { Bagel, formatAPIErrorMessage, _default as openAPI };
|
|
112
|
+
export type { TableToTypeMapping, Tables, UploadOptions, User };
|
package/dist/index.mjs
CHANGED
|
@@ -15,6 +15,21 @@ function resolveReference(ref) {
|
|
|
15
15
|
if (!t) return "any";
|
|
16
16
|
return formatType(t);
|
|
17
17
|
}
|
|
18
|
+
function handleArrayItems(schema) {
|
|
19
|
+
const itemType = schemaToType(schema.items);
|
|
20
|
+
const needsParentheses = itemType.includes("|") || itemType.includes("&");
|
|
21
|
+
let res = needsParentheses ? `(${itemType})[]` : `${itemType}[]`;
|
|
22
|
+
if (itemType.includes("string | string")) {
|
|
23
|
+
res = res.replace("string | string", "string");
|
|
24
|
+
}
|
|
25
|
+
if (itemType.includes("string |")) {
|
|
26
|
+
return res.replace("string |", "(string & {}) |");
|
|
27
|
+
}
|
|
28
|
+
if (itemType.includes("| string")) {
|
|
29
|
+
return res.replace("| string", "| (string & {})");
|
|
30
|
+
}
|
|
31
|
+
return res;
|
|
32
|
+
}
|
|
18
33
|
function schemaToType(schema) {
|
|
19
34
|
if (!schema) return "any";
|
|
20
35
|
if (schema.anyOf) {
|
|
@@ -30,6 +45,9 @@ function schemaToType(schema) {
|
|
|
30
45
|
case "object":
|
|
31
46
|
return "{ [key: string]: any }";
|
|
32
47
|
case "string":
|
|
48
|
+
if (schema.const) {
|
|
49
|
+
return `'${schema.const}'`;
|
|
50
|
+
}
|
|
33
51
|
return "string";
|
|
34
52
|
case "integer":
|
|
35
53
|
return "number";
|
|
@@ -38,7 +56,7 @@ function schemaToType(schema) {
|
|
|
38
56
|
case "boolean":
|
|
39
57
|
return "boolean";
|
|
40
58
|
case "array":
|
|
41
|
-
return
|
|
59
|
+
return handleArrayItems(schema);
|
|
42
60
|
case "undefined":
|
|
43
61
|
return "undefined";
|
|
44
62
|
case "null":
|
|
@@ -47,7 +65,7 @@ function schemaToType(schema) {
|
|
|
47
65
|
return "any";
|
|
48
66
|
default:
|
|
49
67
|
console.log("Unknown type", schema.type);
|
|
50
|
-
return "
|
|
68
|
+
return "unknown";
|
|
51
69
|
}
|
|
52
70
|
}
|
|
53
71
|
function isOptional(schema) {
|
|
@@ -408,7 +426,7 @@ function generateTypes(schemas) {
|
|
|
408
426
|
`;
|
|
409
427
|
}
|
|
410
428
|
if (schema.type === "array" && schema.items) {
|
|
411
|
-
return `export type ${typeName} = ${schemaToType(schema.items)}[];
|
|
429
|
+
return `export type ${typeName} = (${schemaToType(schema.items)})[];
|
|
412
430
|
`;
|
|
413
431
|
}
|
|
414
432
|
if (!schema.properties) {
|
package/package.json
CHANGED
|
@@ -41,8 +41,10 @@ export interface ResponsesObject { [statusCode: string]: ResponseObject }
|
|
|
41
41
|
|
|
42
42
|
export interface SchemaObject {
|
|
43
43
|
type?: string
|
|
44
|
+
const?: string
|
|
44
45
|
format?: string
|
|
45
46
|
properties?: { [property: string]: SchemaObject }
|
|
47
|
+
prefixItems?: SchemaObject[]
|
|
46
48
|
items?: SchemaObject
|
|
47
49
|
$ref?: string
|
|
48
50
|
enum?: string[]
|
|
@@ -11,7 +11,7 @@ export function generateTypes(schemas: SchemasObject): string {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
if (schema.type === 'array' && schema.items) {
|
|
14
|
-
return `export type ${typeName} = ${schemaToType(schema.items)}[];\n`
|
|
14
|
+
return `export type ${typeName} = (${schemaToType(schema.items)})[];\n`
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// if (typeName === 'LocalizedJsonInt') {
|
|
@@ -29,6 +29,28 @@ function resolveReference(ref: string): string {
|
|
|
29
29
|
return formatType(t)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
function handleArrayItems(schema: SchemaObject): string {
|
|
33
|
+
// Handle array items that might be union types
|
|
34
|
+
const itemType = schemaToType(schema.items)
|
|
35
|
+
|
|
36
|
+
// Add parentheses around union types to ensure correct syntax
|
|
37
|
+
const needsParentheses = itemType.includes('|') || itemType.includes('&')
|
|
38
|
+
|
|
39
|
+
let res = needsParentheses ? `(${itemType})[]` : `${itemType}[]`
|
|
40
|
+
|
|
41
|
+
if (itemType.includes('string | string')) {
|
|
42
|
+
res = res.replace('string | string', 'string')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (itemType.includes('string |')) {
|
|
46
|
+
return res.replace('string |', '(string & {}) |')
|
|
47
|
+
}
|
|
48
|
+
if (itemType.includes('| string')) {
|
|
49
|
+
return res.replace('| string', '| (string & {})')
|
|
50
|
+
}
|
|
51
|
+
return res
|
|
52
|
+
}
|
|
53
|
+
|
|
32
54
|
export function schemaToType(schema?: SchemaObject): string {
|
|
33
55
|
if (!schema) return 'any'
|
|
34
56
|
if (schema.anyOf) {
|
|
@@ -47,27 +69,20 @@ export function schemaToType(schema?: SchemaObject): string {
|
|
|
47
69
|
}
|
|
48
70
|
if (schema.$ref) return resolveReference(schema.$ref)
|
|
49
71
|
switch (schema.type) {
|
|
50
|
-
case 'object':
|
|
51
|
-
return '{ [key: string]: any }'
|
|
72
|
+
case 'object': return '{ [key: string]: any }'
|
|
52
73
|
case 'string':
|
|
74
|
+
if (schema.const) { return `'${schema.const}'` }
|
|
53
75
|
return 'string'
|
|
54
|
-
case 'integer':
|
|
55
|
-
|
|
56
|
-
case '
|
|
57
|
-
|
|
58
|
-
case '
|
|
59
|
-
|
|
60
|
-
case '
|
|
61
|
-
return `${schemaToType(schema.items)}[]`
|
|
62
|
-
case 'undefined':
|
|
63
|
-
return 'undefined'
|
|
64
|
-
case 'null':
|
|
65
|
-
return 'null'
|
|
66
|
-
case undefined:
|
|
67
|
-
return 'any'
|
|
76
|
+
case 'integer': return 'number'
|
|
77
|
+
case 'number': return 'number'
|
|
78
|
+
case 'boolean': return 'boolean'
|
|
79
|
+
case 'array': return handleArrayItems(schema)
|
|
80
|
+
case 'undefined': return 'undefined'
|
|
81
|
+
case 'null': return 'null'
|
|
82
|
+
case undefined: return 'any'
|
|
68
83
|
default:
|
|
69
84
|
console.log('Unknown type', schema.type)
|
|
70
|
-
return '
|
|
85
|
+
return 'unknown'
|
|
71
86
|
}
|
|
72
87
|
}
|
|
73
88
|
|