api-core-lib 12.12.104 → 12.12.106

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.
Files changed (2) hide show
  1. package/dist/cli.cjs +28 -11
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -75,13 +75,30 @@ var import_dotenv = __toESM(require("dotenv"), 1);
75
75
  var import_swagger_parser = __toESM(require("@apidevtools/swagger-parser"), 1);
76
76
  var import_openapi_types = __toESM(require_dist(), 1);
77
77
  var import_inquirer = __toESM(require("inquirer"), 1);
78
+
79
+ // src/generator/utils/index.ts
80
+ var getActionName = (opId) => {
81
+ const cleanOpId = opId.replace(/_v\d+$/, "");
82
+ const parts = cleanOpId.split("_");
83
+ if (parts.length > 1) {
84
+ const actionPart = parts.slice(1).join("_");
85
+ return toCamelCase(actionPart);
86
+ }
87
+ return toCamelCase(cleanOpId);
88
+ };
89
+ var toCamelCase = (str) => {
90
+ const s = toPascalCase(str);
91
+ return s.charAt(0).toLowerCase() + s.slice(1);
92
+ };
93
+ var toPascalCase = (str) => str.replace(/[^a-zA-Z0-9_]/g, " ").replace(/(?:^\w|[A-Z]|\b\w)/g, (w) => w.toUpperCase()).replace(/\s+/g, "");
94
+
95
+ // src/generator/v1.ts
78
96
  var DEBUG_MODE = process.env.DEBUG === "true";
79
97
  var debugLog = (title, data) => DEBUG_MODE && console.log(import_chalk.default.yellow(`
80
98
  [DEBUG: ${title}]`), import_util.default.inspect(data, { depth: 5, colors: true }));
81
- var toCamelCase = (str) => str.replace(/[-_\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : "").replace(/^(.)/, (c) => c.toLowerCase());
82
- var toPascalCase = (str) => str.replace(/(?:^|[-_\s])(\w)/g, (_, c) => c.toUpperCase());
83
- var sanitizeForModuleName = (name) => toPascalCase(name.replace(/api/gi, "").replace(/[^a-zA-Z0-9\s-]/g, ""));
84
- var getActionName = (operationId) => toCamelCase(operationId.split("_").pop() || operationId);
99
+ var toCamelCase2 = (str) => str.replace(/[-_\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : "").replace(/^(.)/, (c) => c.toLowerCase());
100
+ var toPascalCase2 = (str) => str.replace(/(?:^|[-_\s])(\w)/g, (_, c) => c.toUpperCase());
101
+ var sanitizeForModuleName = (name) => toPascalCase2(name.replace(/api/gi, "").replace(/[^a-zA-Z0-9\s-]/g, ""));
85
102
  function findCommonPath(paths) {
86
103
  if (!paths || paths.length === 0) return "/";
87
104
  const sortedPaths = paths.sort();
@@ -150,7 +167,7 @@ function _propToMock(prop) {
150
167
  case "string":
151
168
  if (prop.format === "email") return "test@example.com";
152
169
  if (prop.format === "uuid") return "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11";
153
- return `Mock ${toPascalCase(prop.name)}`;
170
+ return `Mock ${toPascalCase2(prop.name)}`;
154
171
  case "integer":
155
172
  case "number":
156
173
  return 1;
@@ -176,18 +193,18 @@ function parseSchema(name, schema, allEnums) {
176
193
  const propSchema = schema.properties[propName];
177
194
  let itemSchema, generatedEnumName;
178
195
  if (propSchema.type === "array" && propSchema.items) {
179
- const itemTypeName = `${toPascalCase(name)}${toPascalCase(propName)}Item`;
196
+ const itemTypeName = `${toPascalCase2(name)}${toPascalCase2(propName)}Item`;
180
197
  itemSchema = parseSchema(itemTypeName, propSchema.items, allEnums).properties[0];
181
198
  }
182
199
  if (propSchema.enum) {
183
- const enumName = `${toPascalCase(name)}${toPascalCase(propName)}Enum`;
200
+ const enumName = `${toPascalCase2(name)}${toPascalCase2(propName)}Enum`;
184
201
  enums[propName] = propSchema.enum;
185
202
  if (!allEnums.has(enumName)) {
186
203
  allEnums.set(enumName, { name: enumName, values: propSchema.enum });
187
204
  }
188
205
  generatedEnumName = enumName;
189
206
  }
190
- properties.push({ name: propName, type: propSchema.type || "object", isRequired: (schema.required || []).includes(propName), isNullable: propSchema.nullable || false, description: propSchema.description, example: propSchema.example, enum: propSchema.enum, enumName: generatedEnumName, format: propSchema.format, items: itemSchema, properties: propSchema.properties ? parseSchema(`${name}${toPascalCase(propName)}`, propSchema, allEnums).properties : void 0, minLength: propSchema.minLength, maxLength: propSchema.maxLength, pattern: propSchema.pattern, minimum: propSchema.minimum, maximum: propSchema.maximum, minItems: propSchema.minItems, maxItems: propSchema.maxItems });
207
+ properties.push({ name: propName, type: propSchema.type || "object", isRequired: (schema.required || []).includes(propName), isNullable: propSchema.nullable || false, description: propSchema.description, example: propSchema.example, enum: propSchema.enum, enumName: generatedEnumName, format: propSchema.format, items: itemSchema, properties: propSchema.properties ? parseSchema(`${name}${toPascalCase2(propName)}`, propSchema, allEnums).properties : void 0, minLength: propSchema.minLength, maxLength: propSchema.maxLength, pattern: propSchema.pattern, minimum: propSchema.minimum, maximum: propSchema.maximum, minItems: propSchema.minItems, maxItems: propSchema.maxItems });
191
208
  }
192
209
  }
193
210
  return { name, description: schema.description, properties, enums };
@@ -204,7 +221,7 @@ function parseSpecToModules(spec) {
204
221
  }
205
222
  if (schema.type === "object" || schema.properties || schema.allOf || !schema.type) {
206
223
  if (!schema.properties && !schema.allOf) return "Record<string, any>";
207
- const typeName = toPascalCase(baseName.replace(/_v\d+(Request|Response)$/, "$1"));
224
+ const typeName = toPascalCase2(baseName.replace(/_v\d+(Request|Response)$/, "$1"));
208
225
  if (!allSchemas.has(typeName)) allSchemas.set(typeName, parseSchema(typeName, schema, allEnums));
209
226
  return typeName;
210
227
  }
@@ -236,7 +253,7 @@ function parseSpecToModules(spec) {
236
253
  if (cleanType && !BUILT_IN_TYPES.has(cleanType)) {
237
254
  currentModule.schemas.add(cleanType);
238
255
  const schemaDef = allSchemas.get(cleanType);
239
- if (schemaDef) Object.keys(schemaDef.enums).forEach((propName) => currentModule.enums.add(`${toPascalCase(cleanType)}${toPascalCase(propName)}Enum`));
256
+ if (schemaDef) Object.keys(schemaDef.enums).forEach((propName) => currentModule.enums.add(`${toPascalCase2(cleanType)}${toPascalCase2(propName)}Enum`));
240
257
  }
241
258
  });
242
259
  currentModule.actions[getActionName(endpoint.operationId)] = { name: getActionName(endpoint.operationId), method: method.toUpperCase(), path: apiPath, description: endpoint.summary || "", hasQuery: (endpoint.parameters || []).some((p) => p.in === "query"), autoFetch: method.toUpperCase() === "GET" && !apiPath.includes("{"), requiresAuth: !!endpoint.security && endpoint.security.length > 0, inputType, outputType, pathParams: (apiPath.match(/{(\w+)}/g) || []).map((p) => p.slice(1, -1)) };
@@ -383,7 +400,7 @@ import type { ${schemasToImport.join(", ")} } from './types';
383
400
  import_fs.default.writeFileSync(indexFilePath, initialIndexContent);
384
401
  console.log(import_chalk.default.gray(` \u2713 index.ts (Initial Entry Point)`));
385
402
  const moduleBaseName = module2.moduleName.replace(/Api$/, "");
386
- const camelCaseModuleName = toCamelCase(moduleBaseName);
403
+ const camelCaseModuleName = toCamelCase2(moduleBaseName);
387
404
  let endpointsContent = `// Auto-generated file. Do not edit.
388
405
 
389
406
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-core-lib",
3
- "version": "12.12.104",
3
+ "version": "12.12.106",
4
4
  "description": "A flexible and powerful API client library for modern web applications.",
5
5
  "type": "module",
6
6
  "exports": {