@bagelink/sdk 1.6.41 → 1.6.43

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
@@ -662,26 +662,27 @@ function generateTypes(schemas) {
662
662
  return `export type ${typeName} = ${schema.enum.map((item) => `'${item}'`).join(" | ")};
663
663
  `;
664
664
  }
665
- if ("array" === schema?.type && schema.items) {
665
+ if (schema?.type === "array" && schema.items) {
666
666
  return `export type ${typeName} = (${schemaToType(schema.items)})[];
667
667
  `;
668
668
  }
669
669
  if (!schema.properties) {
670
- if (true === schema.additionalProperties) {
670
+ if (schema.additionalProperties === true) {
671
671
  return `export type ${typeName} = { [key: string]: any };
672
672
  `;
673
673
  }
674
674
  return "";
675
675
  }
676
- if (0 === Object.keys(schema.properties).length && true === schema.additionalProperties) {
676
+ if (Object.keys(schema.properties).length === 0 && schema.additionalProperties === true) {
677
677
  return `export type ${typeName} = { [key: string]: any };
678
678
  `;
679
679
  }
680
680
  const properties = Object.entries(schema.properties).map(([key, value]) => {
681
- const varType = formatVarType({ varName: key, schema: value });
681
+ const quotedKey = /^[a-z_$][\w$]*$/i.test(key) ? key : `'${key}'`;
682
+ const varType = formatVarType({ varName: quotedKey, schema: value });
682
683
  return ` ${varType}`;
683
684
  }).join(";\n ");
684
- const indexSignature = true === schema.additionalProperties ? "\n [key: string]: any;" : "";
685
+ const indexSignature = schema.additionalProperties === true ? "\n [key: string]: any;" : "";
685
686
  return `export type ${typeName} = {
686
687
  ${properties};${indexSignature}
687
688
  };
package/dist/index.mjs CHANGED
@@ -656,26 +656,27 @@ function generateTypes(schemas) {
656
656
  return `export type ${typeName} = ${schema.enum.map((item) => `'${item}'`).join(" | ")};
657
657
  `;
658
658
  }
659
- if ("array" === schema?.type && schema.items) {
659
+ if (schema?.type === "array" && schema.items) {
660
660
  return `export type ${typeName} = (${schemaToType(schema.items)})[];
661
661
  `;
662
662
  }
663
663
  if (!schema.properties) {
664
- if (true === schema.additionalProperties) {
664
+ if (schema.additionalProperties === true) {
665
665
  return `export type ${typeName} = { [key: string]: any };
666
666
  `;
667
667
  }
668
668
  return "";
669
669
  }
670
- if (0 === Object.keys(schema.properties).length && true === schema.additionalProperties) {
670
+ if (Object.keys(schema.properties).length === 0 && schema.additionalProperties === true) {
671
671
  return `export type ${typeName} = { [key: string]: any };
672
672
  `;
673
673
  }
674
674
  const properties = Object.entries(schema.properties).map(([key, value]) => {
675
- const varType = formatVarType({ varName: key, schema: value });
675
+ const quotedKey = /^[a-z_$][\w$]*$/i.test(key) ? key : `'${key}'`;
676
+ const varType = formatVarType({ varName: quotedKey, schema: value });
676
677
  return ` ${varType}`;
677
678
  }).join(";\n ");
678
- const indexSignature = true === schema.additionalProperties ? "\n [key: string]: any;" : "";
679
+ const indexSignature = schema.additionalProperties === true ? "\n [key: string]: any;" : "";
679
680
  return `export type ${typeName} = {
680
681
  ${properties};${indexSignature}
681
682
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/sdk",
3
3
  "type": "module",
4
- "version": "1.6.41",
4
+ "version": "1.6.43",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
@@ -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 ('array' === schema?.type && schema.items) {
19
+ if (schema?.type === 'array' && 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 (true === schema.additionalProperties) {
24
+ if (schema.additionalProperties === true) {
25
25
  return `export type ${typeName} = { [key: string]: any };\n`
26
26
  }
27
27
  // #region Debug
@@ -33,20 +33,22 @@ export function generateTypes(schemas: ComponentsObject['schemas']): string {
33
33
  }
34
34
 
35
35
  // Handle empty properties with additionalProperties
36
- if (0 === Object.keys(schema.properties).length && true === schema.additionalProperties) {
36
+ if (Object.keys(schema.properties).length === 0 && schema.additionalProperties === true) {
37
37
  return `export type ${typeName} = { [key: string]: any };\n`
38
38
  }
39
39
 
40
40
  const properties = Object.entries(schema.properties)
41
41
  .map(([key, value]) => {
42
- const varType = formatVarType({ varName: key, schema: value })
42
+ // Wrap key in quotes if it contains hyphens or isn't a valid identifier
43
+ const quotedKey = /^[a-z_$][\w$]*$/i.test(key) ? key : `'${key}'`
44
+ const varType = formatVarType({ varName: quotedKey, schema: value })
43
45
 
44
46
  return `\t\t${varType}`
45
47
  })
46
48
  .join(';\n ')
47
49
 
48
50
  // Add index signature for additionalProperties if true
49
- const indexSignature = true === schema.additionalProperties ? '\n\t\t[key: string]: any;' : ''
51
+ const indexSignature = schema.additionalProperties === true ? '\n\t\t[key: string]: any;' : ''
50
52
 
51
53
  return `export type ${typeName} = {\n ${properties};${indexSignature}\n };\n`
52
54
  })