api-core-lib 12.0.81 → 12.0.83

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 +44 -6
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -212,6 +212,21 @@ function parseSpecToModules(spec) {
212
212
  const allSchemas = /* @__PURE__ */ new Map();
213
213
  const allEnums = /* @__PURE__ */ new Map();
214
214
  const modulePaths = /* @__PURE__ */ new Map();
215
+ const BUILT_IN_TYPES = /* @__PURE__ */ new Set([
216
+ "string",
217
+ "number",
218
+ "boolean",
219
+ "void",
220
+ "undefined",
221
+ "unknown",
222
+ "any",
223
+ "Date",
224
+ "Promise",
225
+ "QueryOptions",
226
+ "Record<string, any>",
227
+ "Record<string, unknown>"
228
+ // <-- Add our fallback type here
229
+ ]);
215
230
  const registerSchema = (schema, baseName) => {
216
231
  if (!schema) return "Record<string, any>";
217
232
  if (schema.type === "array" && schema.items) {
@@ -224,6 +239,9 @@ function parseSpecToModules(spec) {
224
239
  return `${primitiveType}[]`;
225
240
  }
226
241
  if (schema.type === "object" || schema.properties || schema.allOf || !schema.type) {
242
+ if (!schema.properties && !schema.allOf) {
243
+ return "Record<string, any>";
244
+ }
227
245
  const typeName = toPascalCase(baseName.replace(/_v\d+(Request|Response)$/, "$1"));
228
246
  if (!allSchemas.has(typeName)) {
229
247
  allSchemas.set(typeName, parseSchema(typeName, schema, allEnums));
@@ -252,11 +270,14 @@ function parseSpecToModules(spec) {
252
270
  const outputType = successKey === "204" ? "void" : registerSchema(successRes?.content?.["application/json"]?.schema, `${endpoint.operationId}Response`);
253
271
  const reqBody = endpoint.requestBody;
254
272
  let inputType = "undefined";
255
- if (reqBody?.content?.["application/json"]?.schema) inputType = registerSchema(reqBody.content["application/json"].schema, `${endpoint.operationId}Request`);
256
- else if ((endpoint.parameters || []).some((p) => p.in === "query")) inputType = "QueryOptions";
273
+ if (reqBody?.content?.["application/json"]?.schema) {
274
+ inputType = registerSchema(reqBody.content["application/json"].schema, `${endpoint.operationId}Request`);
275
+ } else if ((endpoint.parameters || []).some((p) => p.in === "query")) {
276
+ inputType = "QueryOptions";
277
+ }
257
278
  [inputType, outputType].forEach((t) => {
258
279
  const cleanType = t.replace("[]", "");
259
- if (cleanType && !["unknown", "undefined", "void", "any", "QueryOptions", "Promise"].includes(cleanType)) {
280
+ if (cleanType && !BUILT_IN_TYPES.has(cleanType)) {
260
281
  currentModule.schemas.add(cleanType);
261
282
  const schemaDef = allSchemas.get(cleanType);
262
283
  if (schemaDef) Object.keys(schemaDef.enums).forEach((propName) => currentModule.enums.add(`${toPascalCase(cleanType)}${toPascalCase(propName)}Enum`));
@@ -278,7 +299,22 @@ async function generateModuleFiles(module2, allSchemas, allEnums, outputDir) {
278
299
  if (!import_fs.default.existsSync(moduleOutputPath)) import_fs.default.mkdirSync(moduleOutputPath, { recursive: true });
279
300
  console.log(import_chalk.default.cyan(`
280
301
  Generating module: ${import_chalk.default.bold(module2.moduleName)}`));
281
- const schemasToImport = [...module2.schemas].sort();
302
+ const BUILT_IN_TYPES = /* @__PURE__ */ new Set([
303
+ "string",
304
+ "number",
305
+ "boolean",
306
+ "void",
307
+ "undefined",
308
+ "unknown",
309
+ "any",
310
+ "Date",
311
+ "Promise",
312
+ "QueryOptions",
313
+ "Record<string, any>",
314
+ "Record<string, unknown>"
315
+ ]);
316
+ const allCustomSchemaNames = [...module2.schemas].sort();
317
+ const schemasToImport = allCustomSchemaNames.filter((name) => !BUILT_IN_TYPES.has(name));
282
318
  const enumsToImport = [...module2.enums].sort();
283
319
  const indexContent = [`// This file is auto-generated. Do not edit directly.
284
320
 
@@ -287,8 +323,10 @@ export * from './config';`];
287
323
 
288
324
  import type { ApiModuleConfig, ActionConfigModule } from 'api-core-lib';
289
325
  `;
290
- if (schemasToImport.length > 0) configContent += `import type { ${schemasToImport.join(", ")} } from './types';
326
+ if (schemasToImport.length > 0) {
327
+ configContent += `import type { ${schemasToImport.join(", ")} } from './types';
291
328
  `;
329
+ }
292
330
  const actionsType = Object.values(module2.actions).map((a) => ` ${a.name}: ActionConfigModule<${a.inputType}, ${a.outputType}>;`).join("\n");
293
331
  const actionsValue = Object.values(module2.actions).map((a) => {
294
332
  const { inputType, outputType, name, ...c } = a;
@@ -306,7 +344,7 @@ ${actionsValue}
306
344
  `;
307
345
  import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, "config.ts"), configContent.trim());
308
346
  console.log(import_chalk.default.gray(` \u2713 config.ts`));
309
- if (schemasToImport.length > 0) {
347
+ if (allCustomSchemaNames.length > 0) {
310
348
  if (enumsToImport.length > 0) {
311
349
  let enumsContent = `// This file is auto-generated. Do not edit directly.
312
350
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-core-lib",
3
- "version": "12.0.81",
3
+ "version": "12.0.83",
4
4
  "description": "A flexible and powerful API client library for modern web applications.",
5
5
  "type": "module",
6
6
  "exports": {