@apso/cli 0.8.6 → 0.10.1
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/README.md +221 -1653
- package/dist/commands/config.d.ts +13 -0
- package/dist/commands/config.js +114 -0
- package/dist/commands/deploy.d.ts +11 -0
- package/dist/commands/deploy.js +141 -0
- package/dist/commands/dev.d.ts +15 -0
- package/dist/commands/dev.js +95 -0
- package/dist/commands/generate.d.ts +12 -0
- package/dist/commands/generate.js +179 -0
- package/dist/commands/init.d.ts +16 -0
- package/dist/commands/init.js +313 -0
- package/dist/commands/link.d.ts +11 -0
- package/dist/commands/link.js +139 -0
- package/dist/commands/login.d.ts +22 -0
- package/dist/commands/login.js +345 -0
- package/dist/commands/logout.d.ts +9 -0
- package/dist/commands/logout.js +38 -0
- package/dist/commands/logs.d.ts +10 -0
- package/dist/commands/logs.js +64 -0
- package/dist/commands/mcp/serve.d.ts +11 -0
- package/dist/commands/mcp/serve.js +818 -0
- package/dist/commands/migrate.d.ts +11 -0
- package/dist/commands/migrate.js +137 -0
- package/dist/commands/open.d.ts +10 -0
- package/dist/commands/open.js +79 -0
- package/dist/commands/projects.d.ts +10 -0
- package/dist/commands/projects.js +106 -0
- package/dist/commands/schema/diff.d.ts +7 -0
- package/dist/commands/schema/diff.js +63 -0
- package/dist/commands/schema/pull.d.ts +9 -0
- package/dist/commands/schema/pull.js +81 -0
- package/dist/commands/schema/push.d.ts +9 -0
- package/dist/commands/schema/push.js +97 -0
- package/dist/commands/schema/validate.d.ts +9 -0
- package/dist/commands/schema/validate.js +90 -0
- package/dist/commands/server/new.d.ts +2 -19
- package/dist/commands/server/new.js +6 -192
- package/dist/commands/server/scaffold.d.ts +2 -25
- package/dist/commands/server/scaffold.js +6 -312
- package/dist/commands/status.d.ts +7 -0
- package/dist/commands/status.js +53 -0
- package/dist/commands/unlink.d.ts +9 -0
- package/dist/commands/unlink.js +47 -0
- package/dist/commands/whoami.d.ts +10 -0
- package/dist/commands/whoami.js +97 -0
- package/dist/lib/api/client.js +1 -1
- package/dist/lib/api/services.js +3 -3
- package/dist/lib/api/types.d.ts +9 -2
- package/dist/lib/apsorc-parser.d.ts +0 -19
- package/dist/lib/apsorc-parser.js +2 -73
- package/dist/lib/guards.d.ts +3 -20
- package/dist/lib/guards.js +1 -113
- package/dist/lib/index.d.ts +1 -9
- package/dist/lib/index.js +1 -18
- package/dist/lib/migrate/entity-generator.d.ts +14 -0
- package/dist/lib/migrate/entity-generator.js +7 -0
- package/dist/lib/migrate/sandbox.d.ts +42 -0
- package/dist/lib/migrate/sandbox.js +337 -0
- package/dist/lib/migrate/snapshot.d.ts +80 -0
- package/dist/lib/migrate/snapshot.js +100 -0
- package/dist/lib/templates/python/models/model-col-datetime.eta +1 -1
- package/dist/lib/templates/python/models/model-col-string.eta +1 -1
- package/dist/lib/templates/python/models/model-col-text.eta +1 -1
- package/dist/lib/templates/python/models/model-col-varchar.eta +1 -1
- package/dist/lib/utils/field.d.ts +12 -0
- package/dist/lib/utils/field.js +80 -1
- package/dist/lib/utils/schema-convert.d.ts +71 -0
- package/dist/lib/utils/schema-convert.js +169 -0
- package/dist/lib/utils/spinner.d.ts +19 -0
- package/dist/lib/utils/spinner.js +87 -0
- package/dist/lib/utils/template.d.ts +12 -0
- package/dist/lib/utils/template.js +49 -0
- package/npm-shrinkwrap.json +18118 -0
- package/oclif.manifest.json +547 -41
- package/package.json +26 -5
- package/dist/lib/controller.d.ts +0 -10
- package/dist/lib/controller.js +0 -99
- package/dist/lib/dto.d.ts +0 -16
- package/dist/lib/dto.js +0 -92
- package/dist/lib/entity.d.ts +0 -19
- package/dist/lib/entity.js +0 -56
- package/dist/lib/enums.d.ts +0 -6
- package/dist/lib/enums.js +0 -28
- package/dist/lib/gql-dto.d.ts +0 -3
- package/dist/lib/gql-dto.js +0 -39
- package/dist/lib/index-module.d.ts +0 -13
- package/dist/lib/index-module.js +0 -26
- package/dist/lib/module.d.ts +0 -13
- package/dist/lib/module.js +0 -42
- package/dist/lib/service.d.ts +0 -2
- package/dist/lib/service.js +0 -61
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apso/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Apso CLI",
|
|
5
5
|
"author": "Apso by Mavric - @mavric",
|
|
6
6
|
"bin": {
|
|
@@ -23,15 +23,20 @@
|
|
|
23
23
|
"/oclif.manifest.json"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"@electric-sql/pglite": "^0.2.17",
|
|
27
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
26
28
|
"@oclif/core": "^2",
|
|
27
29
|
"@oclif/plugin-help": "^5",
|
|
28
30
|
"@oclif/plugin-plugins": "^3",
|
|
29
31
|
"debug": "^4.3.4",
|
|
30
32
|
"eta": "^2.0.0",
|
|
31
33
|
"inquirer": "^8.2.7",
|
|
34
|
+
"ora": "^5.4.1",
|
|
32
35
|
"pluralize": "^8.0.0",
|
|
33
36
|
"rc": "^1.2.8",
|
|
34
|
-
"shelljs": "^0.8.5"
|
|
37
|
+
"shelljs": "^0.8.5",
|
|
38
|
+
"typeorm": "^0.3.20",
|
|
39
|
+
"typeorm-pglite": "^0.3.4"
|
|
35
40
|
},
|
|
36
41
|
"devDependencies": {
|
|
37
42
|
"@jest/globals": "^29.5.0",
|
|
@@ -71,8 +76,24 @@
|
|
|
71
76
|
],
|
|
72
77
|
"topicSeparator": " ",
|
|
73
78
|
"topics": {
|
|
74
|
-
"
|
|
75
|
-
"description": "
|
|
79
|
+
"server": {
|
|
80
|
+
"description": "Server commands (deprecated - use top-level commands)"
|
|
81
|
+
},
|
|
82
|
+
"schema": {
|
|
83
|
+
"description": "Manage service schema (validate, push, pull, diff)"
|
|
84
|
+
},
|
|
85
|
+
"mcp": {
|
|
86
|
+
"description": "MCP server for AI coding agents"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"update": {
|
|
90
|
+
"node": {
|
|
91
|
+
"version": "18.20.4",
|
|
92
|
+
"targets": [
|
|
93
|
+
"darwin-x64",
|
|
94
|
+
"darwin-arm64",
|
|
95
|
+
"linux-x64"
|
|
96
|
+
]
|
|
76
97
|
}
|
|
77
98
|
}
|
|
78
99
|
},
|
|
@@ -86,7 +107,7 @@
|
|
|
86
107
|
"pack": "oclif pack tarballs",
|
|
87
108
|
"posttest": "npm run lint",
|
|
88
109
|
"prepack": "npm run build && oclif manifest && oclif readme",
|
|
89
|
-
"test": "jest",
|
|
110
|
+
"test": "NODE_OPTIONS='--experimental-vm-modules' jest",
|
|
90
111
|
"test:watch": "jest --watch",
|
|
91
112
|
"test:cov": "jest --coverage",
|
|
92
113
|
"docs:generate": "typedoc src/lib/index.ts --out docs",
|
package/dist/lib/controller.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Entity, RelationshipMap } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Generates NestJS controller and spec files for a given entity.
|
|
4
|
-
*
|
|
5
|
-
* @param apiBaseDir The base directory for the generated API module (e.g., 'src/autogen/users').
|
|
6
|
-
* @param entity The entity definition object from the parsed .apsorc.
|
|
7
|
-
* @param relationshipMap The complete RelationshipMap generated from parsing all relationships.
|
|
8
|
-
* @returns {Promise<void>} A promise that resolves when the controller and spec files are created.
|
|
9
|
-
*/
|
|
10
|
-
export declare const createController: (apiBaseDir: string, entity: Entity, relationshipMap: RelationshipMap) => Promise<void>;
|
package/dist/lib/controller.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createController = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const Eta = tslib_1.__importStar(require("eta"));
|
|
6
|
-
const path = tslib_1.__importStar(require("path"));
|
|
7
|
-
const file_system_1 = require("./utils/file-system");
|
|
8
|
-
const relationships_1 = require("./utils/relationships");
|
|
9
|
-
const parse_1 = require("./utils/relationships/parse");
|
|
10
|
-
const pluralize_1 = tslib_1.__importDefault(require("pluralize"));
|
|
11
|
-
const perf_hooks_1 = require("perf_hooks");
|
|
12
|
-
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
13
|
-
const os_1 = tslib_1.__importDefault(require("os"));
|
|
14
|
-
const util_1 = require("util");
|
|
15
|
-
const unlinkAsync = (0, util_1.promisify)(fs_1.default.unlink);
|
|
16
|
-
/**
|
|
17
|
-
* Generates NestJS controller and spec files for a given entity.
|
|
18
|
-
*
|
|
19
|
-
* @param apiBaseDir The base directory for the generated API module (e.g., 'src/autogen/users').
|
|
20
|
-
* @param entity The entity definition object from the parsed .apsorc.
|
|
21
|
-
* @param relationshipMap The complete RelationshipMap generated from parsing all relationships.
|
|
22
|
-
* @returns {Promise<void>} A promise that resolves when the controller and spec files are created.
|
|
23
|
-
*/
|
|
24
|
-
const createController = async (apiBaseDir, entity, relationshipMap) => {
|
|
25
|
-
const { name: entityName } = entity;
|
|
26
|
-
const controllerFileName = path.join(apiBaseDir, `${entityName}.controller.ts`);
|
|
27
|
-
const specFileName = path.join(apiBaseDir, `${entityName}.controller.spec.ts`);
|
|
28
|
-
const startTotal = perf_hooks_1.performance.now();
|
|
29
|
-
const startRel = perf_hooks_1.performance.now();
|
|
30
|
-
const relationships = (0, relationships_1.getRelationshipForTemplate)(entityName, relationshipMap[entityName]);
|
|
31
|
-
const relTime = perf_hooks_1.performance.now() - startRel;
|
|
32
|
-
if (process.env.DEBUG) {
|
|
33
|
-
console.log(`[createController][${entityName}] getRelationshipForTemplate: ${relTime.toFixed(2)} ms`);
|
|
34
|
-
}
|
|
35
|
-
const startNested = perf_hooks_1.performance.now();
|
|
36
|
-
const tmpDir = os_1.default.tmpdir();
|
|
37
|
-
const nestedJoinsFile = path.join(tmpDir, `apso-nested-joins-${entityName}-${Date.now()}.eta`);
|
|
38
|
-
const nestedJoinsStream = fs_1.default.createWriteStream(nestedJoinsFile, {
|
|
39
|
-
encoding: "utf8",
|
|
40
|
-
});
|
|
41
|
-
let nestedCount = 0;
|
|
42
|
-
nestedCount = await (0, parse_1.streamNestedRelationships)(entityName, relationshipMap, nestedJoinsStream);
|
|
43
|
-
nestedJoinsStream.end();
|
|
44
|
-
await new Promise((resolve) => {
|
|
45
|
-
nestedJoinsStream.on("finish", resolve);
|
|
46
|
-
});
|
|
47
|
-
const nestedTime = perf_hooks_1.performance.now() - startNested;
|
|
48
|
-
if (process.env.DEBUG) {
|
|
49
|
-
console.log(`[createController][${entityName}] getNestedRelationships (streamed ${nestedCount} paths): ${nestedTime.toFixed(2)} ms`);
|
|
50
|
-
}
|
|
51
|
-
const svcName = `${entityName}Service`;
|
|
52
|
-
const ctrlName = `${entityName}Controller`;
|
|
53
|
-
const pluralEntityName = (0, pluralize_1.default)(entityName);
|
|
54
|
-
const primaryKeyType = entity.primaryKeyType || "serial"; // Default to 'serial' if not specified
|
|
55
|
-
const data = {
|
|
56
|
-
svcName,
|
|
57
|
-
ctrlName,
|
|
58
|
-
entityName,
|
|
59
|
-
pluralEntityName,
|
|
60
|
-
primaryKeyType,
|
|
61
|
-
associations: [...new Set(relationships)],
|
|
62
|
-
nestedJoinsFile,
|
|
63
|
-
};
|
|
64
|
-
const startRenderController = perf_hooks_1.performance.now();
|
|
65
|
-
const controllerContent = await Eta.renderFileAsync("./rest/controller-rest", (0, file_system_1.withGeneratedMeta)(data));
|
|
66
|
-
const renderControllerTime = perf_hooks_1.performance.now() - startRenderController;
|
|
67
|
-
if (process.env.DEBUG) {
|
|
68
|
-
console.log(`[createController][${entityName}] renderController: ${renderControllerTime.toFixed(2)} ms`);
|
|
69
|
-
}
|
|
70
|
-
const startWriteController = perf_hooks_1.performance.now();
|
|
71
|
-
await (0, file_system_1.createFile)(controllerFileName, controllerContent);
|
|
72
|
-
const writeControllerTime = perf_hooks_1.performance.now() - startWriteController;
|
|
73
|
-
if (process.env.DEBUG) {
|
|
74
|
-
console.log(`[createController][${entityName}] writeController: ${writeControllerTime.toFixed(2)} ms`);
|
|
75
|
-
}
|
|
76
|
-
const startRenderSpec = perf_hooks_1.performance.now();
|
|
77
|
-
const specContent = await Eta.renderFileAsync("./rest/controller-rest-spec", (0, file_system_1.withGeneratedMeta)(data));
|
|
78
|
-
const renderSpecTime = perf_hooks_1.performance.now() - startRenderSpec;
|
|
79
|
-
if (process.env.DEBUG) {
|
|
80
|
-
console.log(`[createController][${entityName}] renderSpec: ${renderSpecTime.toFixed(2)} ms`);
|
|
81
|
-
}
|
|
82
|
-
const startWriteSpec = perf_hooks_1.performance.now();
|
|
83
|
-
await (0, file_system_1.createFile)(specFileName, specContent);
|
|
84
|
-
const writeSpecTime = perf_hooks_1.performance.now() - startWriteSpec;
|
|
85
|
-
if (process.env.DEBUG) {
|
|
86
|
-
console.log(`[createController][${entityName}] writeSpec: ${writeSpecTime.toFixed(2)} ms`);
|
|
87
|
-
}
|
|
88
|
-
try {
|
|
89
|
-
await unlinkAsync(nestedJoinsFile);
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
console.warn(`[createController][${entityName}] Warning: Failed to delete temp file ${nestedJoinsFile}:`, error);
|
|
93
|
-
}
|
|
94
|
-
const totalTime = perf_hooks_1.performance.now() - startTotal;
|
|
95
|
-
if (process.env.DEBUG) {
|
|
96
|
-
console.log(`[createController][${entityName}] TOTAL: ${totalTime.toFixed(2)} ms`);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
exports.createController = createController;
|
package/dist/lib/dto.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Entity } from "./types/entity";
|
|
2
|
-
/**
|
|
3
|
-
* Generates Data Transfer Object (DTO) files (create and update) for a given entity.
|
|
4
|
-
*
|
|
5
|
-
* @param apiBaseDir The base directory for the generated API module (e.g., 'src/autogen/users').
|
|
6
|
-
* @param entity The entity definition object from the parsed .apsorc.
|
|
7
|
-
* @param relationships The relationships array from the parsed .apsorc.
|
|
8
|
-
* @param options Optional configuration flags.
|
|
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.
|
|
11
|
-
* @returns {Promise<void>} A promise that resolves when the DTO files are created.
|
|
12
|
-
*/
|
|
13
|
-
export declare const createDto: (apiBaseDir: string, entity: Entity, relationships: any[], options?: {
|
|
14
|
-
apiType?: string;
|
|
15
|
-
allEntities?: Entity[];
|
|
16
|
-
}) => Promise<void>;
|
package/dist/lib/dto.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createDto = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const Eta = tslib_1.__importStar(require("eta"));
|
|
6
|
-
const path = tslib_1.__importStar(require("path"));
|
|
7
|
-
const file_system_1 = require("./utils/file-system");
|
|
8
|
-
const field_1 = require("./utils/field");
|
|
9
|
-
const relationships_1 = require("./utils/relationships");
|
|
10
|
-
const casing_1 = require("./utils/casing");
|
|
11
|
-
/**
|
|
12
|
-
* Generates Data Transfer Object (DTO) files (create and update) for a given entity.
|
|
13
|
-
*
|
|
14
|
-
* @param apiBaseDir The base directory for the generated API module (e.g., 'src/autogen/users').
|
|
15
|
-
* @param entity The entity definition object from the parsed .apsorc.
|
|
16
|
-
* @param relationships The relationships array from the parsed .apsorc.
|
|
17
|
-
* @param options Optional configuration flags.
|
|
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.
|
|
20
|
-
* @returns {Promise<void>} A promise that resolves when the DTO files are created.
|
|
21
|
-
*/
|
|
22
|
-
const createDto = async (apiBaseDir, entity, relationships, // Relationship[]
|
|
23
|
-
options) => {
|
|
24
|
-
var _a;
|
|
25
|
-
const { name: entityName, fields = [] } = entity;
|
|
26
|
-
const dtoDir = path.join(apiBaseDir, "dtos");
|
|
27
|
-
const dtoFile = path.join(dtoDir, `${entityName}.dto.ts`);
|
|
28
|
-
const columns = (0, field_1.getFieldForTemplate)(fields, entityName);
|
|
29
|
-
const relationshipsTemplate = (0, relationships_1.getRelationshipForTemplate)(entityName, relationships);
|
|
30
|
-
// if (process.env.DEBUG) {
|
|
31
|
-
// console.log('[DTO DEBUG] Generating DTO for:', entityName);
|
|
32
|
-
// console.log('[DTO DEBUG] relationshipsTemplate:', relationshipsTemplate);
|
|
33
|
-
// }
|
|
34
|
-
// Add foreign key columns for ManyToOne relationships if not present
|
|
35
|
-
relationshipsTemplate.forEach((rel) => {
|
|
36
|
-
var _a;
|
|
37
|
-
if (rel.type === "ManyToOne") {
|
|
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";
|
|
44
|
-
// if (process.env.DEBUG) {
|
|
45
|
-
// console.log('[DTO DEBUG]', {
|
|
46
|
-
// relType: rel.type,
|
|
47
|
-
// relName: rel.name,
|
|
48
|
-
// referenceName: rel.referenceName,
|
|
49
|
-
// fkName,
|
|
50
|
-
// referencedPrimaryKeyType,
|
|
51
|
-
// fkDataType,
|
|
52
|
-
// columns: columns.map(c => c.name)
|
|
53
|
-
// });
|
|
54
|
-
// }
|
|
55
|
-
if (!columns.some((col) => col.name === fkName)) {
|
|
56
|
-
columns.push({
|
|
57
|
-
name: fkName,
|
|
58
|
-
dataType: fkDataType,
|
|
59
|
-
type: fkType,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
const primaryKeyColumns = columns.filter((column) => column.primary === true);
|
|
65
|
-
const addDefaultPKProperty = primaryKeyColumns.length === 0;
|
|
66
|
-
const createdAt = entity.created_at;
|
|
67
|
-
const updatedAt = entity.updated_at;
|
|
68
|
-
const primaryKeyType = entity.primaryKeyType || "serial"; // Default to 'serial' if not specified
|
|
69
|
-
// Filter columns: remove id, createdAt, updatedAt
|
|
70
|
-
const dtoColumns = columns.filter((col) => !["id", "createdAt", "updatedAt"].includes(col.name));
|
|
71
|
-
// Class names
|
|
72
|
-
const createDtoName = `Create${(0, casing_1.pascalCase)(entityName)}Dto`;
|
|
73
|
-
const updateDtoName = `Update${(0, casing_1.pascalCase)(entityName)}Dto`;
|
|
74
|
-
const data = {
|
|
75
|
-
entityName,
|
|
76
|
-
addDefaultPKProperty,
|
|
77
|
-
primaryKeyType,
|
|
78
|
-
createdAt,
|
|
79
|
-
updatedAt,
|
|
80
|
-
columns: dtoColumns,
|
|
81
|
-
associations: relationshipsTemplate,
|
|
82
|
-
createDtoName,
|
|
83
|
-
updateDtoName,
|
|
84
|
-
apiType: (_a = options === null || options === void 0 ? void 0 : options.apiType) !== null && _a !== void 0 ? _a : "rest",
|
|
85
|
-
importEnums: (0, field_1.typeExistsInEntity)(entity, "enum") !== -1,
|
|
86
|
-
};
|
|
87
|
-
// Render the unified template only once
|
|
88
|
-
const dtoContent = await Eta.renderFileAsync("./rest/dto-rest", (0, file_system_1.withGeneratedMeta)(data));
|
|
89
|
-
// Create only one DTO file
|
|
90
|
-
await (0, file_system_1.createFile)(dtoFile, dtoContent);
|
|
91
|
-
};
|
|
92
|
-
exports.createDto = createDto;
|
package/dist/lib/entity.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Entity, Relationship } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Generates a TypeORM entity file based on the entity definition and relationships.
|
|
4
|
-
*
|
|
5
|
-
* @param options Configuration options for entity generation
|
|
6
|
-
* @param options.apiBaseDir The base directory for the generated API module (e.g., 'src/autogen/users').
|
|
7
|
-
* @param options.entity The entity definition object from the parsed .apsorc.
|
|
8
|
-
* @param options.relationships An array of processed Relationship objects for this entity.
|
|
9
|
-
* @param options.apiType The type of API being generated (e.g., "rest", "graphql").
|
|
10
|
-
* @param options.allEntities Optional array of all entities, used to determine foreign key types.
|
|
11
|
-
* @returns {Promise<void>} A promise that resolves when the entity file is created.
|
|
12
|
-
*/
|
|
13
|
-
export declare const createEntity: (options: {
|
|
14
|
-
apiBaseDir: string;
|
|
15
|
-
entity: Entity;
|
|
16
|
-
relationships: Relationship[];
|
|
17
|
-
apiType: string;
|
|
18
|
-
allEntities?: Entity[];
|
|
19
|
-
}) => Promise<void>;
|
package/dist/lib/entity.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createEntity = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
6
|
-
const file_system_1 = require("./utils/file-system");
|
|
7
|
-
const field_1 = require("./utils/field");
|
|
8
|
-
const relationships_1 = require("./utils/relationships");
|
|
9
|
-
const casing_1 = require("./utils/casing");
|
|
10
|
-
const pluralize_1 = tslib_1.__importDefault(require("pluralize"));
|
|
11
|
-
const Eta = tslib_1.__importStar(require("eta"));
|
|
12
|
-
/**
|
|
13
|
-
* Generates a TypeORM entity file based on the entity definition and relationships.
|
|
14
|
-
*
|
|
15
|
-
* @param options Configuration options for entity generation
|
|
16
|
-
* @param options.apiBaseDir The base directory for the generated API module (e.g., 'src/autogen/users').
|
|
17
|
-
* @param options.entity The entity definition object from the parsed .apsorc.
|
|
18
|
-
* @param options.relationships An array of processed Relationship objects for this entity.
|
|
19
|
-
* @param options.apiType The type of API being generated (e.g., "rest", "graphql").
|
|
20
|
-
* @param options.allEntities Optional array of all entities, used to determine foreign key types.
|
|
21
|
-
* @returns {Promise<void>} A promise that resolves when the entity file is created.
|
|
22
|
-
*/
|
|
23
|
-
const createEntity = async (options) => {
|
|
24
|
-
const { apiBaseDir, entity, relationships: relationshipsNew, apiType, allEntities, } = options;
|
|
25
|
-
const { name, fields = [], indexes, uniques } = entity;
|
|
26
|
-
const File = path.join(apiBaseDir, `${name}.entity.ts`);
|
|
27
|
-
const columns = (0, field_1.getFieldForTemplate)(fields, name);
|
|
28
|
-
const createPrimaryKey = columns.filter((column) => column.primary === true).length === 0;
|
|
29
|
-
const createdAt = entity.created_at;
|
|
30
|
-
const updatedAt = entity.updated_at;
|
|
31
|
-
const primaryKeyType = entity.primaryKeyType || "serial"; // Default to 'serial' if not specified
|
|
32
|
-
const relationships = (0, relationships_1.getRelationshipForTemplate)(name, relationshipsNew, allEntities);
|
|
33
|
-
const entitiesToImport = (0, relationships_1.getRelationshipsForImport)(name, relationships);
|
|
34
|
-
const data = {
|
|
35
|
-
name,
|
|
36
|
-
indexes: indexes || [],
|
|
37
|
-
uniques: uniques || [],
|
|
38
|
-
createPrimaryKey,
|
|
39
|
-
primaryKeyType,
|
|
40
|
-
snakeCasedName: (0, casing_1.snakeCase)(name),
|
|
41
|
-
createdAt,
|
|
42
|
-
updatedAt,
|
|
43
|
-
pluralizedName: (0, casing_1.camelCase)((0, pluralize_1.default)(name)),
|
|
44
|
-
columns,
|
|
45
|
-
associations: [...new Set(relationships)],
|
|
46
|
-
entitiesToImport,
|
|
47
|
-
importEnums: (0, field_1.typeExistsInEntity)(entity, "enum") !== -1,
|
|
48
|
-
apiType,
|
|
49
|
-
};
|
|
50
|
-
const templatePath = apiType === "graphql"
|
|
51
|
-
? "./graphql/gql-entity-graphql"
|
|
52
|
-
: "./entities/entity";
|
|
53
|
-
const content = await Eta.renderFileAsync(templatePath, (0, file_system_1.withGeneratedMeta)(data));
|
|
54
|
-
await (0, file_system_1.createFile)(File, content);
|
|
55
|
-
};
|
|
56
|
-
exports.createEntity = createEntity;
|
package/dist/lib/enums.d.ts
DELETED
package/dist/lib/enums.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createEnums = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
6
|
-
const file_system_1 = require("./utils/file-system");
|
|
7
|
-
const field_1 = require("./utils/field");
|
|
8
|
-
const Eta = tslib_1.__importStar(require("eta"));
|
|
9
|
-
const createEnums = async (apiBaseDir, entities, apiType) => {
|
|
10
|
-
if (entities.length > 0) {
|
|
11
|
-
const outputFile = path.join(apiBaseDir, "enums.ts");
|
|
12
|
-
const allEnumsFields = entities
|
|
13
|
-
.flatMap((entity) => (entity.fields || []).map((field) => {
|
|
14
|
-
if (field.type === "enum") {
|
|
15
|
-
return { ...field, name: (0, field_1.fieldToEnumType)(field.name, entity.name) };
|
|
16
|
-
}
|
|
17
|
-
return null;
|
|
18
|
-
}))
|
|
19
|
-
.filter(Boolean);
|
|
20
|
-
if (allEnumsFields.length > 0) {
|
|
21
|
-
const content = await Eta.renderFileAsync(`./${apiType}/enums-${apiType}`, {
|
|
22
|
-
allEnumsFields,
|
|
23
|
-
});
|
|
24
|
-
await (0, file_system_1.createFile)(outputFile, content);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
exports.createEnums = createEnums;
|
package/dist/lib/gql-dto.d.ts
DELETED
package/dist/lib/gql-dto.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createGqlDTO = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
6
|
-
const pluralize_1 = tslib_1.__importDefault(require("pluralize"));
|
|
7
|
-
const Eta = tslib_1.__importStar(require("eta"));
|
|
8
|
-
const field_1 = require("./utils/field");
|
|
9
|
-
const relationships_1 = require("./utils/relationships");
|
|
10
|
-
const casing_1 = require("./utils/casing");
|
|
11
|
-
const file_system_1 = require("./utils/file-system");
|
|
12
|
-
const createGqlDTO = async (apiBaseDir, entity, relationshipsNew) => {
|
|
13
|
-
const { name, fields = [], indexes } = entity;
|
|
14
|
-
const Dir = path.join(apiBaseDir, "dtos");
|
|
15
|
-
const File = path.join(Dir, `${name}.dto.ts`);
|
|
16
|
-
const columns = (0, field_1.getFieldForTemplate)(fields, name);
|
|
17
|
-
const createPrimaryKey = columns.filter((column) => column.primary === true)
|
|
18
|
-
.length === 0;
|
|
19
|
-
const createdAt = entity.created_at;
|
|
20
|
-
const updatedAt = entity.updated_at;
|
|
21
|
-
const relationships = (0, relationships_1.getRelationshipForTemplate)(name, relationshipsNew);
|
|
22
|
-
const entitiesToImport = (0, relationships_1.getRelationshipsForImport)(name, relationships);
|
|
23
|
-
const data = {
|
|
24
|
-
name,
|
|
25
|
-
indexes: indexes || [],
|
|
26
|
-
createPrimaryKey,
|
|
27
|
-
snakeCasedName: (0, casing_1.snakeCase)(name),
|
|
28
|
-
createdAt,
|
|
29
|
-
updatedAt,
|
|
30
|
-
pluralizedName: (0, casing_1.camelCase)((0, pluralize_1.default)(name)),
|
|
31
|
-
columns,
|
|
32
|
-
associations: relationships,
|
|
33
|
-
entitiesToImport,
|
|
34
|
-
importEnums: (0, field_1.typeExistsInEntity)(entity, "enum") !== -1,
|
|
35
|
-
};
|
|
36
|
-
const contentEntity = await Eta.renderFileAsync("./graphql/gql-dto-graphql", data);
|
|
37
|
-
await (0, file_system_1.createFile)(File, contentEntity);
|
|
38
|
-
};
|
|
39
|
-
exports.createGqlDTO = createGqlDTO;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Entity } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Generates an index file (e.g., index.ts) that exports all generated entity modules.
|
|
4
|
-
*
|
|
5
|
-
* This file serves as a central point for importing and managing the generated modules
|
|
6
|
-
* within the application, tailored to the specified API type (REST or GraphQL).
|
|
7
|
-
*
|
|
8
|
-
* @param apiBaseDir The base directory where the generated API modules reside (e.g., 'src/autogen').
|
|
9
|
-
* @param entities An array of Entity definition objects, used to determine which modules to export.
|
|
10
|
-
* @param apiType The type of API being generated ('rest' or 'graphql'), which determines the template used.
|
|
11
|
-
* @returns {Promise<void>} A promise that resolves when the index file is created.
|
|
12
|
-
*/
|
|
13
|
-
export declare const createIndexAppModule: (apiBaseDir: string, entities: Entity[], apiType: string) => Promise<void>;
|
package/dist/lib/index-module.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createIndexAppModule = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const Eta = tslib_1.__importStar(require("eta"));
|
|
6
|
-
const file_system_1 = require("./utils/file-system");
|
|
7
|
-
const path = tslib_1.__importStar(require("path"));
|
|
8
|
-
/**
|
|
9
|
-
* Generates an index file (e.g., index.ts) that exports all generated entity modules.
|
|
10
|
-
*
|
|
11
|
-
* This file serves as a central point for importing and managing the generated modules
|
|
12
|
-
* within the application, tailored to the specified API type (REST or GraphQL).
|
|
13
|
-
*
|
|
14
|
-
* @param apiBaseDir The base directory where the generated API modules reside (e.g., 'src/autogen').
|
|
15
|
-
* @param entities An array of Entity definition objects, used to determine which modules to export.
|
|
16
|
-
* @param apiType The type of API being generated ('rest' or 'graphql'), which determines the template used.
|
|
17
|
-
* @returns {Promise<void>} A promise that resolves when the index file is created.
|
|
18
|
-
*/
|
|
19
|
-
const createIndexAppModule = async (apiBaseDir, entities, apiType) => {
|
|
20
|
-
const File = path.join(apiBaseDir, `index.ts`);
|
|
21
|
-
const content = await Eta.renderFileAsync(`./${apiType}/index-module-${apiType}`, {
|
|
22
|
-
entities,
|
|
23
|
-
});
|
|
24
|
-
await (0, file_system_1.createFile)(File, content);
|
|
25
|
-
};
|
|
26
|
-
exports.createIndexAppModule = createIndexAppModule;
|
package/dist/lib/module.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Entity } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Generates a NestJS module file for a given entity.
|
|
4
|
-
*
|
|
5
|
-
* @param apiBaseDir The base directory for the generated API module (e.g., 'src/autogen/users').
|
|
6
|
-
* @param entity The entity definition object from the parsed .apsorc.
|
|
7
|
-
* @param options Optional configuration flags.
|
|
8
|
-
* @param options.apiType The type of API being generated (default: "rest").
|
|
9
|
-
* @returns {Promise<void>} A promise that resolves when the module file is created.
|
|
10
|
-
*/
|
|
11
|
-
export declare const createModule: (apiBaseDir: string, entity: Entity, options?: {
|
|
12
|
-
apiType?: string;
|
|
13
|
-
}) => Promise<void>;
|
package/dist/lib/module.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createModule = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const Eta = tslib_1.__importStar(require("eta"));
|
|
6
|
-
const path = tslib_1.__importStar(require("path"));
|
|
7
|
-
const file_system_1 = require("./utils/file-system");
|
|
8
|
-
/**
|
|
9
|
-
* Generates a NestJS module file for a given entity.
|
|
10
|
-
*
|
|
11
|
-
* @param apiBaseDir The base directory for the generated API module (e.g., 'src/autogen/users').
|
|
12
|
-
* @param entity The entity definition object from the parsed .apsorc.
|
|
13
|
-
* @param options Optional configuration flags.
|
|
14
|
-
* @param options.apiType The type of API being generated (default: "rest").
|
|
15
|
-
* @returns {Promise<void>} A promise that resolves when the module file is created.
|
|
16
|
-
*/
|
|
17
|
-
const createModule = async (apiBaseDir, entity, options) => {
|
|
18
|
-
const { name: entityName } = entity;
|
|
19
|
-
const moduleFileName = path.join(apiBaseDir, `${entityName}.module.ts`);
|
|
20
|
-
// Names needed by the templates
|
|
21
|
-
const moduleName = `${entityName}Module`;
|
|
22
|
-
const svcName = `${entityName}Service`;
|
|
23
|
-
const ctrlName = `${entityName}Controller`; // Used by REST template
|
|
24
|
-
const resolverName = `${entityName}Resolver`; // Used by GQL template
|
|
25
|
-
// Data for the Eta templates
|
|
26
|
-
const data = {
|
|
27
|
-
moduleName,
|
|
28
|
-
svcName,
|
|
29
|
-
ctrlName,
|
|
30
|
-
resolverName,
|
|
31
|
-
entityName,
|
|
32
|
-
};
|
|
33
|
-
// Determine template based on API type
|
|
34
|
-
const templatePath = (options === null || options === void 0 ? void 0 : options.apiType) === "graphql"
|
|
35
|
-
? "./graphql/gql-module-graphql"
|
|
36
|
-
: "./rest/module-rest";
|
|
37
|
-
// Render the template
|
|
38
|
-
const content = await Eta.renderFileAsync(templatePath, data);
|
|
39
|
-
// Create the module file
|
|
40
|
-
await (0, file_system_1.createFile)(moduleFileName, content);
|
|
41
|
-
};
|
|
42
|
-
exports.createModule = createModule;
|
package/dist/lib/service.d.ts
DELETED
package/dist/lib/service.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createService = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const Eta = tslib_1.__importStar(require("eta"));
|
|
6
|
-
const file_system_1 = require("./utils/file-system");
|
|
7
|
-
const path = tslib_1.__importStar(require("path"));
|
|
8
|
-
/*
|
|
9
|
-
* Generates NestJS service and spec files for a given entity.
|
|
10
|
-
*
|
|
11
|
-
* @param apiBaseDir The base directory for the generated API module (e.g., 'src/autogen/users').
|
|
12
|
-
* @param entity The entity definition object from the parsed .apsorc.
|
|
13
|
-
* @returns {Promise<void>} A promise that resolves when the service and spec files are created.
|
|
14
|
-
*/
|
|
15
|
-
const createService = async (apiBaseDir, entity, relationshipMap // RelationshipMap, optional for backward compatibility
|
|
16
|
-
) => {
|
|
17
|
-
const { name: entityName } = entity;
|
|
18
|
-
const serviceFileName = path.join(apiBaseDir, `${entityName}.service.ts`);
|
|
19
|
-
const specFileName = path.join(apiBaseDir, `${entityName}.service.spec.ts`);
|
|
20
|
-
// Names needed by the templates
|
|
21
|
-
const svcName = `${entityName}Service`;
|
|
22
|
-
const repoName = `${entityName}Repository`; // Assuming convention
|
|
23
|
-
// --- NEW: Recursively collect all related entities for the test file ---
|
|
24
|
-
let allRelatedEntities = [entityName];
|
|
25
|
-
if (relationshipMap && relationshipMap[entityName]) {
|
|
26
|
-
// Use a Set to avoid duplicates
|
|
27
|
-
const visited = new Set();
|
|
28
|
-
const collect = (entity) => {
|
|
29
|
-
if (visited.has(entity))
|
|
30
|
-
return;
|
|
31
|
-
visited.add(entity);
|
|
32
|
-
allRelatedEntities.push(entity);
|
|
33
|
-
const rels = relationshipMap[entity] || [];
|
|
34
|
-
for (const rel of rels) {
|
|
35
|
-
if (!visited.has(rel.name)) {
|
|
36
|
-
collect(rel.name);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
allRelatedEntities = [];
|
|
41
|
-
collect(entityName);
|
|
42
|
-
// Remove self-duplicates using spread operator
|
|
43
|
-
allRelatedEntities = [...new Set(allRelatedEntities)];
|
|
44
|
-
}
|
|
45
|
-
// Data for the Eta templates
|
|
46
|
-
const data = {
|
|
47
|
-
svcName,
|
|
48
|
-
repoName,
|
|
49
|
-
entityName,
|
|
50
|
-
allRelatedEntities,
|
|
51
|
-
};
|
|
52
|
-
// Render service template
|
|
53
|
-
const serviceContent = await Eta.renderFileAsync("./rest/service-rest", (0, file_system_1.withGeneratedMeta)(data));
|
|
54
|
-
await (0, file_system_1.createFile)(serviceFileName, serviceContent);
|
|
55
|
-
Eta.templates.remove("./rest/service-rest");
|
|
56
|
-
// Render spec template
|
|
57
|
-
const specContent = await Eta.renderFileAsync("./rest/service-rest-spec", (0, file_system_1.withGeneratedMeta)(data));
|
|
58
|
-
await (0, file_system_1.createFile)(specFileName, specContent);
|
|
59
|
-
Eta.templates.remove("./rest/service-rest-spec");
|
|
60
|
-
};
|
|
61
|
-
exports.createService = createService;
|