@apso/cli 0.4.1 → 0.4.2

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.
@@ -14,7 +14,7 @@ export default class Scaffold extends BaseCommand {
14
14
  apiType: string;
15
15
  allEntities: Entity[];
16
16
  }): Promise<void>;
17
- setupRestFiles(dir: string, entity: Entity, relationshipMap: RelationshipMap, apiType: string): Promise<void>;
17
+ setupRestFiles(dir: string, entity: Entity, relationshipMap: RelationshipMap, apiType: string, allEntities: Entity[]): Promise<void>;
18
18
  setupGraphqlFiles(dir: string, entity: Entity, relationshipMap: RelationshipMap): Promise<void>;
19
19
  run(): Promise<void>;
20
20
  }
@@ -32,7 +32,7 @@ class Scaffold extends base_command_1.default {
32
32
  await this.setupGraphqlFiles(dir, entity, relationshipMap);
33
33
  break;
34
34
  case apsorc_parser_1.ApiType.Rest:
35
- await this.setupRestFiles(dir, entity, relationshipMap, apiType);
35
+ await this.setupRestFiles(dir, entity, relationshipMap, apiType, allEntities);
36
36
  break;
37
37
  default:
38
38
  break;
@@ -41,11 +41,11 @@ class Scaffold extends base_command_1.default {
41
41
  const entityBuildTime = perf_hooks_1.performance.now() - entityBuildStart;
42
42
  console.log(`[apso] Finished building entity '${entity.name}' in ${entityBuildTime.toFixed(2)} ms`);
43
43
  }
44
- async setupRestFiles(dir, entity, relationshipMap, apiType) {
44
+ async setupRestFiles(dir, entity, relationshipMap, apiType, allEntities) {
45
45
  const filePath = path.join(dir, entity.name);
46
46
  const entityRelationships = relationshipMap[entity.name] || [];
47
47
  const tDto = perf_hooks_1.performance.now();
48
- await (0, lib_1.createDto)(filePath, entity, entityRelationships, { apiType });
48
+ await (0, lib_1.createDto)(filePath, entity, entityRelationships, { apiType, allEntities });
49
49
  if (process.env.DEBUG) {
50
50
  console.log(`[timing] createDto for ${entity.name}: ${(perf_hooks_1.performance.now() - tDto).toFixed(2)}ms`);
51
51
  const used = process.memoryUsage();
package/dist/lib/dto.d.ts CHANGED
@@ -7,8 +7,10 @@ import { Entity } from "./types/entity";
7
7
  * @param relationships The relationships array from the parsed .apsorc.
8
8
  * @param options Optional configuration flags.
9
9
  * @param options.apiType The type of API being generated (default: "rest").
10
+ * @param options.allEntities Optional array of all entities, used to determine foreign key types.
10
11
  * @returns {Promise<void>} A promise that resolves when the DTO files are created.
11
12
  */
12
13
  export declare const createDto: (apiBaseDir: string, entity: Entity, relationships: any[], options?: {
13
14
  apiType?: string;
15
+ allEntities?: Entity[];
14
16
  }) => Promise<void>;
package/dist/lib/dto.js CHANGED
@@ -16,6 +16,7 @@ const casing_1 = require("./utils/casing");
16
16
  * @param relationships The relationships array from the parsed .apsorc.
17
17
  * @param options Optional configuration flags.
18
18
  * @param options.apiType The type of API being generated (default: "rest").
19
+ * @param options.allEntities Optional array of all entities, used to determine foreign key types.
19
20
  * @returns {Promise<void>} A promise that resolves when the DTO files are created.
20
21
  */
21
22
  const createDto = async (apiBaseDir, entity, relationships, // Relationship[]
@@ -32,22 +33,30 @@ options) => {
32
33
  // }
33
34
  // Add foreign key columns for ManyToOne relationships if not present
34
35
  relationshipsTemplate.forEach(rel => {
36
+ var _a;
35
37
  if (rel.type === 'ManyToOne') {
36
38
  const fkName = (0, casing_1.camelCase)(rel.referenceName || rel.name) + 'Id';
39
+ // Look up the referenced entity to determine the foreign key type
40
+ const referencedEntity = (_a = options === null || options === void 0 ? void 0 : options.allEntities) === null || _a === void 0 ? void 0 : _a.find(e => e.name === rel.name);
41
+ const referencedPrimaryKeyType = (referencedEntity === null || referencedEntity === void 0 ? void 0 : referencedEntity.primaryKeyType) || 'serial';
42
+ const fkDataType = referencedPrimaryKeyType === 'uuid' ? 'string' : 'number';
43
+ const fkType = referencedPrimaryKeyType === 'uuid' ? 'text' : 'integer';
37
44
  // if (process.env.DEBUG) {
38
45
  // console.log('[DTO DEBUG]', {
39
46
  // relType: rel.type,
40
47
  // relName: rel.name,
41
48
  // referenceName: rel.referenceName,
42
49
  // fkName,
50
+ // referencedPrimaryKeyType,
51
+ // fkDataType,
43
52
  // columns: columns.map(c => c.name)
44
53
  // });
45
54
  // }
46
55
  if (!columns.some(col => col.name === fkName)) {
47
56
  columns.push({
48
57
  name: fkName,
49
- dataType: 'number',
50
- type: 'integer',
58
+ dataType: fkDataType,
59
+ type: fkType,
51
60
  });
52
61
  }
53
62
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.4.1",
2
+ "version": "0.4.2",
3
3
  "commands": {
4
4
  "server:new": {
5
5
  "id": "server:new",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apso/cli",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Apso CLI",
5
5
  "author": "Apso by Mavric - @mavric",
6
6
  "bin": {