@bagelink/sdk 0.0.421 → 0.0.427
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
CHANGED
|
@@ -6,9 +6,17 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
6
6
|
|
|
7
7
|
const axios__default = /*#__PURE__*/_interopDefaultCompat(axios$1);
|
|
8
8
|
|
|
9
|
+
const toCamelCase = (str) => str?.replace(/[-._\s]+(.)?/g, (_, c) => c?.toUpperCase() || "").replace(/^./, (str2) => str2.toLowerCase()) || str;
|
|
10
|
+
const toPascalCase = (str) => str?.replace(/[-_\s]+(.)?/g, (_, c) => c?.toUpperCase() || "").replace(/^./, (str2) => str2.toUpperCase()) || str;
|
|
11
|
+
function formatType(typeName) {
|
|
12
|
+
typeName = typeName.replace(/-/g, "").replace(/(post|put)$/gi, "").replace(/^body_/gi, "");
|
|
13
|
+
return toPascalCase(typeName);
|
|
14
|
+
}
|
|
9
15
|
const resolveReference = (ref) => {
|
|
10
|
-
const t = ref.split("/").pop()
|
|
11
|
-
|
|
16
|
+
const t = ref.split("/").pop();
|
|
17
|
+
if (!t)
|
|
18
|
+
return "any";
|
|
19
|
+
return formatType(t);
|
|
12
20
|
};
|
|
13
21
|
const schemaToType = (schema) => {
|
|
14
22
|
if (!schema)
|
|
@@ -38,8 +46,6 @@ const schemaToType = (schema) => {
|
|
|
38
46
|
return "any";
|
|
39
47
|
}
|
|
40
48
|
};
|
|
41
|
-
const toCamelCase = (str) => str?.replace(/[-_\s]+(.)?/g, (_, c) => c?.toUpperCase() || "").replace(/^./, (str2) => str2.toLowerCase()) || str;
|
|
42
|
-
const toPascalCase = (str) => str?.replace(/[-_\s]+(.)?/g, (_, c) => c?.toUpperCase() || "").replace(/^./, (str2) => str2.toUpperCase()) || str;
|
|
43
49
|
const isOptional = (schema) => {
|
|
44
50
|
const type = schemaToType(schema);
|
|
45
51
|
return type?.split(/\s+\|\s+/).includes("null");
|
|
@@ -61,6 +67,7 @@ function cleanPath(path) {
|
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
const generateTypes = (schemas) => Object.entries(schemas).map(([typeName, schema]) => {
|
|
70
|
+
typeName = formatType(typeName);
|
|
64
71
|
if (schema?.enum) {
|
|
65
72
|
return `export type ${typeName} = ${schema.enum.map((item) => `'${item}'`).join(" | ")};
|
|
66
73
|
`;
|
|
@@ -88,6 +95,7 @@ function collectTypeForImportStatement(typeName) {
|
|
|
88
95
|
}
|
|
89
96
|
const primitiveTypes = ["string", "number", "boolean", "null", "void", "any", "Record<string, any>"];
|
|
90
97
|
const isPrimitive = primitiveTypes.includes(typeName);
|
|
98
|
+
typeName = formatType(typeName);
|
|
91
99
|
if (!typeName || isPrimitive)
|
|
92
100
|
return;
|
|
93
101
|
if (!allTypes.includes(typeName))
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import axios$1 from 'axios';
|
|
2
2
|
|
|
3
|
+
const toCamelCase = (str) => str?.replace(/[-._\s]+(.)?/g, (_, c) => c?.toUpperCase() || "").replace(/^./, (str2) => str2.toLowerCase()) || str;
|
|
4
|
+
const toPascalCase = (str) => str?.replace(/[-_\s]+(.)?/g, (_, c) => c?.toUpperCase() || "").replace(/^./, (str2) => str2.toUpperCase()) || str;
|
|
5
|
+
function formatType(typeName) {
|
|
6
|
+
typeName = typeName.replace(/-/g, "").replace(/(post|put)$/gi, "").replace(/^body_/gi, "");
|
|
7
|
+
return toPascalCase(typeName);
|
|
8
|
+
}
|
|
3
9
|
const resolveReference = (ref) => {
|
|
4
|
-
const t = ref.split("/").pop()
|
|
5
|
-
|
|
10
|
+
const t = ref.split("/").pop();
|
|
11
|
+
if (!t)
|
|
12
|
+
return "any";
|
|
13
|
+
return formatType(t);
|
|
6
14
|
};
|
|
7
15
|
const schemaToType = (schema) => {
|
|
8
16
|
if (!schema)
|
|
@@ -32,8 +40,6 @@ const schemaToType = (schema) => {
|
|
|
32
40
|
return "any";
|
|
33
41
|
}
|
|
34
42
|
};
|
|
35
|
-
const toCamelCase = (str) => str?.replace(/[-_\s]+(.)?/g, (_, c) => c?.toUpperCase() || "").replace(/^./, (str2) => str2.toLowerCase()) || str;
|
|
36
|
-
const toPascalCase = (str) => str?.replace(/[-_\s]+(.)?/g, (_, c) => c?.toUpperCase() || "").replace(/^./, (str2) => str2.toUpperCase()) || str;
|
|
37
43
|
const isOptional = (schema) => {
|
|
38
44
|
const type = schemaToType(schema);
|
|
39
45
|
return type?.split(/\s+\|\s+/).includes("null");
|
|
@@ -55,6 +61,7 @@ function cleanPath(path) {
|
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
const generateTypes = (schemas) => Object.entries(schemas).map(([typeName, schema]) => {
|
|
64
|
+
typeName = formatType(typeName);
|
|
58
65
|
if (schema?.enum) {
|
|
59
66
|
return `export type ${typeName} = ${schema.enum.map((item) => `'${item}'`).join(" | ")};
|
|
60
67
|
`;
|
|
@@ -82,6 +89,7 @@ function collectTypeForImportStatement(typeName) {
|
|
|
82
89
|
}
|
|
83
90
|
const primitiveTypes = ["string", "number", "boolean", "null", "void", "any", "Record<string, any>"];
|
|
84
91
|
const isPrimitive = primitiveTypes.includes(typeName);
|
|
92
|
+
typeName = formatType(typeName);
|
|
85
93
|
if (!typeName || isPrimitive)
|
|
86
94
|
return;
|
|
87
95
|
if (!allTypes.includes(typeName))
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
} from './openApiTypes';
|
|
4
4
|
import {
|
|
5
5
|
cleanPath,
|
|
6
|
+
formatType,
|
|
6
7
|
formatVarType, schemaToType, toCamelCase, toPascalCase,
|
|
7
8
|
} from './utils';
|
|
8
9
|
|
|
@@ -11,15 +12,14 @@ const allTypes: string[] = [];
|
|
|
11
12
|
function collectTypeForImportStatement(typeName: string) {
|
|
12
13
|
typeName = typeName.trim().replace('[]', '');
|
|
13
14
|
if (typeName.includes('|')) {
|
|
14
|
-
typeName
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
(singleType) => collectTypeForImportStatement(singleType),
|
|
18
|
-
);
|
|
15
|
+
typeName.split('|').forEach(
|
|
16
|
+
(singleType) => collectTypeForImportStatement(singleType),
|
|
17
|
+
);
|
|
19
18
|
return;
|
|
20
19
|
}
|
|
21
20
|
const primitiveTypes = ['string', 'number', 'boolean', 'null', 'void', 'any', 'Record<string, any>'];
|
|
22
21
|
const isPrimitive = primitiveTypes.includes(typeName);
|
|
22
|
+
typeName = formatType(typeName);
|
|
23
23
|
if (!typeName || isPrimitive) return;
|
|
24
24
|
if (!allTypes.includes(typeName)) allTypes.push(typeName);
|
|
25
25
|
}
|
|
@@ -205,7 +205,6 @@ function handlePathSegment(
|
|
|
205
205
|
}
|
|
206
206
|
obj[functionName] = createFunctionPlaceholder(path, method, operation[method]);
|
|
207
207
|
}
|
|
208
|
-
|
|
209
208
|
return { ...obj, ...existingObj };
|
|
210
209
|
}
|
|
211
210
|
|
|
@@ -225,7 +224,7 @@ export function generateFunctions(paths: PathsObject, baseURL: string) {
|
|
|
225
224
|
allPathsClean.filter((p) => p === cleanPath(path)).length === 1
|
|
226
225
|
) {
|
|
227
226
|
const method: string = methods[0];
|
|
228
|
-
const opp:any = { ...operation }[method];
|
|
227
|
+
const opp: any = { ...operation }[method];
|
|
229
228
|
acc[objFuncKey] = createFunctionPlaceholder(path, methods[0], opp);
|
|
230
229
|
} else if (
|
|
231
230
|
index === array.length - 1
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { formatVarType } from './utils';
|
|
1
|
+
import { formatType, formatVarType } from './utils';
|
|
2
2
|
import type { SchemasObject } from './openApiTypes';
|
|
3
3
|
|
|
4
4
|
export const generateTypes = (schemas: SchemasObject): string => Object.entries(schemas).map(([typeName, schema]) => {
|
|
5
|
+
typeName = formatType(typeName);
|
|
5
6
|
if (schema?.enum) {
|
|
6
7
|
return `export type ${typeName} = ${schema.enum.map((item: string) => `'${item}'`).join(' | ')};\n`;
|
|
7
8
|
}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import type { SchemaObject } from './openApiTypes';
|
|
2
2
|
|
|
3
|
+
export const toCamelCase = (str?: string) => str?.replace(/[-._\s]+(.)?/g, (_, c) => c?.toUpperCase() || '').replace(/^./, (str) => str.toLowerCase()) || str;
|
|
4
|
+
export const toPascalCase = (str?: string) => str?.replace(/[-_\s]+(.)?/g, (_, c) => c?.toUpperCase() || '').replace(/^./, (str) => str.toUpperCase()) || str;
|
|
5
|
+
|
|
6
|
+
export function formatType(typeName: string): string {
|
|
7
|
+
typeName = typeName.replace(/-/g, '').replace(/(post|put)$/gi, '').replace(/^body_/gi, '');
|
|
8
|
+
return toPascalCase(typeName)!;
|
|
9
|
+
}
|
|
10
|
+
|
|
3
11
|
const resolveReference = (ref: string): string => {
|
|
4
|
-
const t = ref.split('/').pop()
|
|
5
|
-
return
|
|
12
|
+
const t = ref.split('/').pop();
|
|
13
|
+
if (!t) return 'any';
|
|
14
|
+
return formatType(t);
|
|
6
15
|
};
|
|
7
16
|
|
|
8
17
|
export const schemaToType = (schema?: SchemaObject): string => {
|
|
@@ -30,9 +39,6 @@ export const schemaToType = (schema?: SchemaObject): string => {
|
|
|
30
39
|
}
|
|
31
40
|
};
|
|
32
41
|
|
|
33
|
-
export const toCamelCase = (str?: string) => str?.replace(/[-_\s]+(.)?/g, (_, c) => c?.toUpperCase() || '').replace(/^./, (str) => str.toLowerCase()) || str;
|
|
34
|
-
export const toPascalCase = (str?: string) => str?.replace(/[-_\s]+(.)?/g, (_, c) => c?.toUpperCase() || '').replace(/^./, (str) => str.toUpperCase()) || str;
|
|
35
|
-
|
|
36
42
|
export const isOptional = (schema: SchemaObject) => {
|
|
37
43
|
/// / !schema?.required?.includes(schema.title || '')
|
|
38
44
|
const type = schemaToType(schema);
|