@bagelink/sdk 1.5.17 → 1.5.22

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.
@@ -3,25 +3,25 @@ import { isSchemaObject } from './types/utils'
3
3
  import { formatType, formatVarType, schemaToType } from './utils'
4
4
 
5
5
  export function generateTypes(schemas: ComponentsObject['schemas']): string {
6
- if (!schemas) return ''
6
+ if (!schemas) {return ''}
7
7
  const schemaEntries = Object.entries(schemas)
8
8
 
9
9
  return schemaEntries
10
10
  .map(([_typeName, schema]) => {
11
11
  const typeName = formatType(_typeName)
12
12
 
13
- if (!isSchemaObject(schema)) return ''
13
+ if (!isSchemaObject(schema)) {return ''}
14
14
 
15
15
  if (schema?.enum) {
16
16
  return `export type ${typeName} = ${schema.enum.map((item: string) => `'${item}'`).join(' | ')};\n`
17
17
  }
18
18
 
19
- if (schema?.type === 'array' && schema.items) {
19
+ if ('array' === schema?.type && schema.items) {
20
20
  return `export type ${typeName} = (${schemaToType(schema.items)})[];\n`
21
21
  }
22
22
  if (!schema.properties) {
23
23
  // Handle case where schema has additionalProperties: true
24
- if (schema.additionalProperties === true) {
24
+ if (true === schema.additionalProperties) {
25
25
  return `export type ${typeName} = { [key: string]: any };\n`
26
26
  }
27
27
  // #region Debug
@@ -33,7 +33,7 @@ export function generateTypes(schemas: ComponentsObject['schemas']): string {
33
33
  }
34
34
 
35
35
  // Handle empty properties with additionalProperties
36
- if (Object.keys(schema.properties).length === 0 && schema.additionalProperties === true) {
36
+ if (0 === Object.keys(schema.properties).length && true === schema.additionalProperties) {
37
37
  return `export type ${typeName} = { [key: string]: any };\n`
38
38
  }
39
39
 
@@ -46,7 +46,7 @@ export function generateTypes(schemas: ComponentsObject['schemas']): string {
46
46
  .join(';\n ')
47
47
 
48
48
  // Add index signature for additionalProperties if true
49
- const indexSignature = schema.additionalProperties === true ? '\n\t\t[key: string]: any;' : ''
49
+ const indexSignature = true === schema.additionalProperties ? '\n\t\t[key: string]: any;' : ''
50
50
 
51
51
  return `export type ${typeName} = {\n ${properties};${indexSignature}\n };\n`
52
52
  })
@@ -14,8 +14,8 @@ export function getPath(
14
14
  * @param obj The value to check.
15
15
  */
16
16
  export function isReferenceObject(obj: any): obj is ReferenceObject {
17
- if (!obj) return false
18
- return Object.prototype.hasOwnProperty.call(obj, '$ref')
17
+ if (!obj) {return false}
18
+ return Object.hasOwn(obj, '$ref')
19
19
  }
20
20
 
21
21
  /**
@@ -28,7 +28,7 @@ export function isReferenceObject(obj: any): obj is ReferenceObject {
28
28
  * @param schema The value to check.
29
29
  */
30
30
  export function isSchemaObject(schema: SchemaObject | ReferenceObject): schema is SchemaObject {
31
- return !Object.prototype.hasOwnProperty.call(schema, '$ref')
31
+ return ! Object.hasOwn(schema, '$ref')
32
32
  }
33
33
 
34
34
  export function dereference<T>(property: ReferenceObject | T) {
@@ -26,7 +26,7 @@ export function formatType(typeName: string): string {
26
26
 
27
27
  function resolveReference(ref: string): string {
28
28
  const t = ref.split('/').pop()
29
- if (!t) return 'any'
29
+ if (!t) {return 'any'}
30
30
  return formatType(t)
31
31
  }
32
32
 
@@ -53,9 +53,9 @@ function handleArrayItems(schema: SchemaObject): string {
53
53
  }
54
54
 
55
55
  export function schemaToType(schema?: SchemaObject | ReferenceObject): string {
56
- if (!schema) return 'any'
56
+ if (!schema) {return 'any'}
57
57
  if (isReferenceObject(schema)) {
58
- if (schema.$ref) return resolveReference(schema.$ref)
58
+ if (schema.$ref) {return resolveReference(schema.$ref)}
59
59
  }
60
60
  if (!isSchemaObject(schema)) {
61
61
  console.warn('Schema is not a SchemaObject:', schema)
@@ -65,15 +65,15 @@ export function schemaToType(schema?: SchemaObject | ReferenceObject): string {
65
65
  if (schema.anyOf) {
66
66
  let _t = schema.anyOf
67
67
  .map(s => schemaToType(s))
68
- .filter(p => p !== 'any')
68
+ .filter(p => 'any' !== p)
69
69
  .join(' | ')
70
- if (_t === '' || _t === 'null') _t = 'any'
70
+ if ('' === _t || 'null' === _t) {_t = 'any'}
71
71
  return _t
72
72
  }
73
73
  if (schema.allOf) {
74
74
  return schema.allOf
75
75
  .map(s => schemaToType(s))
76
- .filter(p => p !== 'any')
76
+ .filter(p => 'any' !== p)
77
77
  .join(' & ')
78
78
  }
79
79
  // TODO: handle Array.isArray(schema.type) case b4 switch
@@ -108,7 +108,7 @@ export function isOptional(schema?: SchemaObject) {
108
108
  export function cleanOptionals(str: string) {
109
109
  return str
110
110
  .split(' | ')
111
- .filter(t => t !== 'null' && t !== 'undefined')
111
+ .filter(t => 'null' !== t && 'undefined' !== t)
112
112
  .join(' | ')
113
113
  }
114
114
 
@@ -128,9 +128,9 @@ export function formatVarType({
128
128
 
129
129
  let defaultStr = ''
130
130
  if (defaultValue) {
131
- if (typeof defaultValue === 'string') {
131
+ if ('string' === typeof defaultValue) {
132
132
  defaultStr = ` = '${defaultValue}'`
133
- } else if (typeof defaultValue === 'object') {
133
+ } else if ('object' === typeof defaultValue) {
134
134
  defaultStr = ` = ${JSON.stringify(defaultValue)}`
135
135
  } else {
136
136
  defaultStr = ` = ${defaultValue}`
@@ -139,7 +139,7 @@ export function formatVarType({
139
139
 
140
140
  let optionalStr = (!required && isOptional(schema)) ? '?' : ''
141
141
 
142
- if (defaultStr) optionalStr = ''
142
+ if (defaultStr) {optionalStr = ''}
143
143
 
144
144
  return `${varName}${optionalStr}: ${type}${defaultStr}`
145
145
  }
@@ -263,7 +263,7 @@ const RESERVED_KEYWORDS = new Set([
263
263
  * @returns A safe variable name
264
264
  */
265
265
  export function sanitizeVarName(varName: string): string {
266
- if (!varName) return varName
266
+ if (!varName) {return varName}
267
267
 
268
268
  // If it's a reserved keyword, append underscore
269
269
  if (RESERVED_KEYWORDS.has(varName.toLowerCase())) {
package/src/utils.ts CHANGED
@@ -66,7 +66,7 @@ export function formatAPIErrorMessage(err: unknown): string {
66
66
  }
67
67
 
68
68
  // Handle other errors with detail
69
- if (data.detail && typeof data.detail === 'string') {
69
+ if (data.detail && 'string' === typeof data.detail) {
70
70
  return data.detail
71
71
  }
72
72