@bagelink/sdk 0.0.1004 → 0.0.1008

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
@@ -21,8 +21,12 @@ function resolveReference(ref) {
21
21
  function schemaToType(schema) {
22
22
  if (!schema)
23
23
  return "any";
24
- if (schema.anyOf)
25
- return schema.anyOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" | ");
24
+ if (schema.anyOf) {
25
+ let _t = schema.anyOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" | ");
26
+ if (_t === "" || _t === "null")
27
+ _t = "any";
28
+ return _t;
29
+ }
26
30
  if (schema.allOf)
27
31
  return schema.allOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" & ");
28
32
  if (schema.$ref)
@@ -44,7 +48,10 @@ function schemaToType(schema) {
44
48
  return "undefined";
45
49
  case "null":
46
50
  return "null";
51
+ case void 0:
52
+ return "any";
47
53
  default:
54
+ console.log("Unknown type", schema.type);
48
55
  return "any";
49
56
  }
50
57
  }
@@ -200,8 +207,15 @@ function fileTemplate(tsString, typeForImport, baseURL) {
200
207
  const templateCode = `import ax from 'axios';
201
208
  import type { AxiosResponse } from 'axios';
202
209
  import type {${typeForImport.join(", ")}} from './types.d';
203
-
204
- export const axios = ax.create({baseURL:${baseURL}});
210
+
211
+ function paramsSerializer(params: { [key: string]: any }) {
212
+ return Object.entries(params)
213
+ .flatMap(([key, value]) => [value]
214
+ .flat()
215
+ .map(v => \`\${encodeURIComponent(key)}=\${encodeURIComponent(v)}\`))
216
+ .join('&')
217
+ }
218
+ export const axios = ax.create({baseURL:${baseURL}, paramsSerializer});
205
219
  ${tsString}`;
206
220
  const doubleQuoteRegex = /"([^"]+)":/g;
207
221
  return templateCode.replace(doubleQuoteRegex, "$1:");
package/dist/index.mjs CHANGED
@@ -15,8 +15,12 @@ function resolveReference(ref) {
15
15
  function schemaToType(schema) {
16
16
  if (!schema)
17
17
  return "any";
18
- if (schema.anyOf)
19
- return schema.anyOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" | ");
18
+ if (schema.anyOf) {
19
+ let _t = schema.anyOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" | ");
20
+ if (_t === "" || _t === "null")
21
+ _t = "any";
22
+ return _t;
23
+ }
20
24
  if (schema.allOf)
21
25
  return schema.allOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" & ");
22
26
  if (schema.$ref)
@@ -38,7 +42,10 @@ function schemaToType(schema) {
38
42
  return "undefined";
39
43
  case "null":
40
44
  return "null";
45
+ case void 0:
46
+ return "any";
41
47
  default:
48
+ console.log("Unknown type", schema.type);
42
49
  return "any";
43
50
  }
44
51
  }
@@ -194,8 +201,15 @@ function fileTemplate(tsString, typeForImport, baseURL) {
194
201
  const templateCode = `import ax from 'axios';
195
202
  import type { AxiosResponse } from 'axios';
196
203
  import type {${typeForImport.join(", ")}} from './types.d';
197
-
198
- export const axios = ax.create({baseURL:${baseURL}});
204
+
205
+ function paramsSerializer(params: { [key: string]: any }) {
206
+ return Object.entries(params)
207
+ .flatMap(([key, value]) => [value]
208
+ .flat()
209
+ .map(v => \`\${encodeURIComponent(key)}=\${encodeURIComponent(v)}\`))
210
+ .join('&')
211
+ }
212
+ export const axios = ax.create({baseURL:${baseURL}, paramsSerializer});
199
213
  ${tsString}`;
200
214
  const doubleQuoteRegex = /"([^"]+)":/g;
201
215
  return templateCode.replace(doubleQuoteRegex, "$1:");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/sdk",
3
3
  "type": "module",
4
- "version": "0.0.1004",
4
+ "version": "0.0.1008",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Neveh Allon",
@@ -178,8 +178,15 @@ function fileTemplate(tsString: string, typeForImport: string[], baseURL: string
178
178
  `import ax from 'axios';
179
179
  import type { AxiosResponse } from 'axios';
180
180
  import type {${typeForImport.join(', ')}} from './types.d';
181
-
182
- export const axios = ax.create({baseURL:${baseURL}});
181
+
182
+ function paramsSerializer(params: { [key: string]: any }) {
183
+ return Object.entries(params)
184
+ .flatMap(([key, value]) => [value]
185
+ .flat()
186
+ .map(v => \`\${encodeURIComponent(key)}=\${encodeURIComponent(v)}\`))
187
+ .join('&')
188
+ }
189
+ export const axios = ax.create({baseURL:${baseURL}, paramsSerializer});
183
190
  ${tsString}`
184
191
  )
185
192
  const doubleQuoteRegex = /"([^"]+)":/g
@@ -4,6 +4,7 @@ import { formatType, formatVarType } from './utils'
4
4
  export function generateTypes(schemas: SchemasObject): string {
5
5
  return Object.entries(schemas).map(([typeName, schema]) => {
6
6
  typeName = formatType(typeName)
7
+
7
8
  if (schema.enum) {
8
9
  return `export type ${typeName} = ${schema.enum.map((item: string) => `'${item}'`).join(' | ')};\n`
9
10
  }
@@ -11,6 +12,7 @@ export function generateTypes(schemas: SchemasObject): string {
11
12
 
12
13
  const properties = Object.entries(schema.properties).map(([key, value]) => {
13
14
  const varType = formatVarType(key, value)
15
+
14
16
  return `\t\t${varType}`
15
17
  }).join(';\n ')
16
18
 
@@ -17,7 +17,11 @@ function resolveReference(ref: string): string {
17
17
 
18
18
  export function schemaToType(schema?: SchemaObject): string {
19
19
  if (!schema) return 'any'
20
- if (schema.anyOf) return schema.anyOf.map(s => schemaToType(s)).filter(p => p !== 'any').join(' | ')
20
+ if (schema.anyOf) {
21
+ let _t = schema.anyOf.map(s => schemaToType(s)).filter(p => p !== 'any').join(' | ')
22
+ if (_t === '' || _t === 'null') _t = 'any'
23
+ return _t
24
+ }
21
25
  if (schema.allOf) return schema.allOf.map(s => schemaToType(s)).filter(p => p !== 'any').join(' & ')
22
26
  if (schema.$ref) return resolveReference(schema.$ref)
23
27
  switch (schema.type) {
@@ -37,7 +41,10 @@ export function schemaToType(schema?: SchemaObject): string {
37
41
  return 'undefined'
38
42
  case 'null':
39
43
  return 'null'
44
+ case undefined:
45
+ return 'any'
40
46
  default:
47
+ console.log('Unknown type', schema.type)
41
48
  return 'any'
42
49
  }
43
50
  }