@comet/api-generator 9.0.0-canary-20251013121422 → 9.0.0-canary-20251113142723
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.
|
@@ -59,11 +59,17 @@ function generateFilterDto({ generatorOptions, metadata }) {
|
|
|
59
59
|
const { classNameSingular } = (0, build_name_variants_1.buildNameVariants)(metadata);
|
|
60
60
|
const { crudFilterProps } = (0, build_options_1.buildOptions)(metadata, generatorOptions);
|
|
61
61
|
const imports = [];
|
|
62
|
+
imports.push({ name: "IsOptional", importPath: "class-validator" });
|
|
63
|
+
imports.push({ name: "ValidateNested", importPath: "class-validator" });
|
|
64
|
+
imports.push({ name: "Type", importPath: "class-transformer" });
|
|
65
|
+
imports.push({ name: "Field", importPath: "@nestjs/graphql" });
|
|
66
|
+
imports.push({ name: "InputType", importPath: "@nestjs/graphql" });
|
|
62
67
|
let enumFiltersOut = "";
|
|
63
68
|
const generatedEnumNames = new Set();
|
|
64
69
|
const generatedEnumsNames = new Set();
|
|
65
70
|
crudFilterProps.map((prop) => {
|
|
66
71
|
if (prop.type == "EnumArrayType") {
|
|
72
|
+
imports.push({ name: "createEnumsFilter", importPath: "@comet/cms-api" });
|
|
67
73
|
const enumName = (0, ts_morph_helper_1.findEnumName)(prop.name, metadata);
|
|
68
74
|
const importPath = (0, ts_morph_helper_1.findEnumImportPath)(enumName, `${generatorOptions.targetDirectory}/dto`, metadata);
|
|
69
75
|
if (!generatedEnumNames.has(enumName)) {
|
|
@@ -75,6 +81,7 @@ function generateFilterDto({ generatorOptions, metadata }) {
|
|
|
75
81
|
}
|
|
76
82
|
}
|
|
77
83
|
else if (prop.enum) {
|
|
84
|
+
imports.push({ name: "createEnumFilter", importPath: "@comet/cms-api" });
|
|
78
85
|
const enumName = (0, ts_morph_helper_1.findEnumName)(prop.name, metadata);
|
|
79
86
|
const importPath = (0, ts_morph_helper_1.findEnumImportPath)(enumName, `${generatorOptions.targetDirectory}/dto`, metadata);
|
|
80
87
|
if (!generatedEnumsNames.has(enumName)) {
|
|
@@ -86,12 +93,7 @@ function generateFilterDto({ generatorOptions, metadata }) {
|
|
|
86
93
|
}
|
|
87
94
|
}
|
|
88
95
|
});
|
|
89
|
-
const filterOut = `
|
|
90
|
-
import { Field, InputType } from "@nestjs/graphql";
|
|
91
|
-
import { Type } from "class-transformer";
|
|
92
|
-
import { IsNumber, IsOptional, IsString, ValidateNested } from "class-validator";
|
|
93
|
-
${(0, generate_imports_code_1.generateImportsCode)(imports)}
|
|
94
|
-
|
|
96
|
+
const filterOut = `
|
|
95
97
|
${enumFiltersOut}
|
|
96
98
|
|
|
97
99
|
@InputType()
|
|
@@ -117,6 +119,7 @@ function generateFilterDto({ generatorOptions, metadata }) {
|
|
|
117
119
|
`;
|
|
118
120
|
}
|
|
119
121
|
else if (prop.type === "string" || prop.type === "text") {
|
|
122
|
+
imports.push({ name: "StringFilter", importPath: "@comet/cms-api" });
|
|
120
123
|
return `@Field(() => StringFilter, { nullable: true })
|
|
121
124
|
@ValidateNested()
|
|
122
125
|
@IsOptional()
|
|
@@ -125,6 +128,7 @@ function generateFilterDto({ generatorOptions, metadata }) {
|
|
|
125
128
|
`;
|
|
126
129
|
}
|
|
127
130
|
else if (prop.type === "DecimalType" || prop.type == "number" || constants_1.integerTypes.includes(prop.type)) {
|
|
131
|
+
imports.push({ name: "NumberFilter", importPath: "@comet/cms-api" });
|
|
128
132
|
return `@Field(() => NumberFilter, { nullable: true })
|
|
129
133
|
@ValidateNested()
|
|
130
134
|
@IsOptional()
|
|
@@ -133,6 +137,7 @@ function generateFilterDto({ generatorOptions, metadata }) {
|
|
|
133
137
|
`;
|
|
134
138
|
}
|
|
135
139
|
else if (prop.type === "boolean" || prop.type === "BooleanType") {
|
|
140
|
+
imports.push({ name: "BooleanFilter", importPath: "@comet/cms-api" });
|
|
136
141
|
return `@Field(() => BooleanFilter, { nullable: true })
|
|
137
142
|
@ValidateNested()
|
|
138
143
|
@IsOptional()
|
|
@@ -142,6 +147,7 @@ function generateFilterDto({ generatorOptions, metadata }) {
|
|
|
142
147
|
}
|
|
143
148
|
else if (prop.type === "DateType") {
|
|
144
149
|
// ISO Date without time
|
|
150
|
+
imports.push({ name: "DateFilter", importPath: "@comet/cms-api" });
|
|
145
151
|
return `@Field(() => DateFilter, { nullable: true })
|
|
146
152
|
@ValidateNested()
|
|
147
153
|
@IsOptional()
|
|
@@ -151,6 +157,7 @@ function generateFilterDto({ generatorOptions, metadata }) {
|
|
|
151
157
|
}
|
|
152
158
|
else if (prop.type === "Date") {
|
|
153
159
|
// DateTime
|
|
160
|
+
imports.push({ name: "DateTimeFilter", importPath: "@comet/cms-api" });
|
|
154
161
|
return `@Field(() => DateTimeFilter, { nullable: true })
|
|
155
162
|
@ValidateNested()
|
|
156
163
|
@IsOptional()
|
|
@@ -159,6 +166,7 @@ function generateFilterDto({ generatorOptions, metadata }) {
|
|
|
159
166
|
`;
|
|
160
167
|
}
|
|
161
168
|
else if (prop.kind === "m:1") {
|
|
169
|
+
imports.push({ name: "ManyToOneFilter", importPath: "@comet/cms-api" });
|
|
162
170
|
return `@Field(() => ManyToOneFilter, { nullable: true })
|
|
163
171
|
@ValidateNested()
|
|
164
172
|
@IsOptional()
|
|
@@ -167,6 +175,7 @@ function generateFilterDto({ generatorOptions, metadata }) {
|
|
|
167
175
|
`;
|
|
168
176
|
}
|
|
169
177
|
else if (prop.kind === "1:m") {
|
|
178
|
+
imports.push({ name: "OneToManyFilter", importPath: "@comet/cms-api" });
|
|
170
179
|
return `@Field(() => OneToManyFilter, { nullable: true })
|
|
171
180
|
@ValidateNested()
|
|
172
181
|
@IsOptional()
|
|
@@ -175,6 +184,7 @@ function generateFilterDto({ generatorOptions, metadata }) {
|
|
|
175
184
|
`;
|
|
176
185
|
}
|
|
177
186
|
else if (prop.kind === "m:n") {
|
|
187
|
+
imports.push({ name: "ManyToManyFilter", importPath: "@comet/cms-api" });
|
|
178
188
|
return `@Field(() => ManyToManyFilter, { nullable: true })
|
|
179
189
|
@ValidateNested()
|
|
180
190
|
@IsOptional()
|
|
@@ -183,6 +193,7 @@ function generateFilterDto({ generatorOptions, metadata }) {
|
|
|
183
193
|
`;
|
|
184
194
|
}
|
|
185
195
|
else if (prop.type == "uuid") {
|
|
196
|
+
imports.push({ name: "IdFilter", importPath: "@comet/cms-api" });
|
|
186
197
|
return `@Field(() => IdFilter, { nullable: true })
|
|
187
198
|
@ValidateNested()
|
|
188
199
|
@IsOptional()
|
|
@@ -210,7 +221,7 @@ function generateFilterDto({ generatorOptions, metadata }) {
|
|
|
210
221
|
or?: ${classNameSingular}Filter[];
|
|
211
222
|
}
|
|
212
223
|
`;
|
|
213
|
-
return filterOut;
|
|
224
|
+
return (0, generate_imports_code_1.generateImportsCode)(imports) + filterOut;
|
|
214
225
|
}
|
|
215
226
|
function generateSortDto({ generatorOptions, metadata }) {
|
|
216
227
|
const { classNameSingular } = (0, build_name_variants_1.buildNameVariants)(metadata);
|
|
@@ -415,6 +426,14 @@ function generateService({ generatorOptions, metadata }) {
|
|
|
415
426
|
return serviceOut;
|
|
416
427
|
}
|
|
417
428
|
function generateEntityImport(targetMetadata, relativeTo) {
|
|
429
|
+
const libMatch = targetMetadata.path.match(/(packages\/api|@comet)\/cms-api\/lib\/(.*)/);
|
|
430
|
+
if (libMatch) {
|
|
431
|
+
// Import from cms-api package
|
|
432
|
+
return {
|
|
433
|
+
name: targetMetadata.className,
|
|
434
|
+
importPath: "@comet/cms-api",
|
|
435
|
+
};
|
|
436
|
+
}
|
|
418
437
|
return {
|
|
419
438
|
name: targetMetadata.className,
|
|
420
439
|
importPath: path.relative(relativeTo, targetMetadata.path).replace(/\.ts$/, ""),
|
|
@@ -906,8 +925,8 @@ function generateResolver({ generatorOptions, metadata }) {
|
|
|
906
925
|
: ``}`)
|
|
907
926
|
.join(",")} }`
|
|
908
927
|
: ``});
|
|
909
|
-
if (input.position > lastPosition
|
|
910
|
-
input.position = lastPosition
|
|
928
|
+
if (input.position > lastPosition) {
|
|
929
|
+
input.position = lastPosition;
|
|
911
930
|
}
|
|
912
931
|
if (${instanceNameSingular}.position < input.position) {
|
|
913
932
|
await this.${instanceNamePlural}Service.decrementPositions(${positionGroupProps.length
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comet/api-generator",
|
|
3
|
-
"version": "9.0.0-canary-
|
|
3
|
+
"version": "9.0.0-canary-20251113142723",
|
|
4
4
|
"description": "Comet API Generator CLI tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"directory": "packages/api/api-generator",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"license": "BSD-2-Clause",
|
|
11
11
|
"type": "commonjs",
|
|
12
|
-
"main": "lib/
|
|
13
|
-
"typings": "lib/
|
|
12
|
+
"main": "lib/apiGenerator.js",
|
|
13
|
+
"typings": "lib/apiGenerator.d.ts",
|
|
14
14
|
"bin": {
|
|
15
15
|
"comet-api-generator": "bin/api-generator.js"
|
|
16
16
|
},
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"pluralize": "^8.0.0",
|
|
25
25
|
"ts-morph": "^25.0.1",
|
|
26
26
|
"ts-node": "^10.9.2",
|
|
27
|
-
"
|
|
27
|
+
"typescript": "5.8.3",
|
|
28
|
+
"@comet/cms-api": "9.0.0-canary-20251113142723"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@mikro-orm/cli": "^6.4.16",
|
|
@@ -32,7 +33,7 @@
|
|
|
32
33
|
"@mikro-orm/postgresql": "^6.4.16",
|
|
33
34
|
"@nestjs/graphql": "^13.1.0",
|
|
34
35
|
"@types/jest": "^29.5.14",
|
|
35
|
-
"@types/node": "^
|
|
36
|
+
"@types/node": "^24.9.1",
|
|
36
37
|
"@types/pluralize": "^0.0.33",
|
|
37
38
|
"class-validator": "^0.14.2",
|
|
38
39
|
"eslint": "^9.30.1",
|
|
@@ -42,12 +43,13 @@
|
|
|
42
43
|
"reflect-metadata": "^0.2.2",
|
|
43
44
|
"rimraf": "^6.0.1",
|
|
44
45
|
"ts-jest": "^29.4.0",
|
|
45
|
-
"typescript": "5.8.3",
|
|
46
46
|
"uuid": "^11.1.0",
|
|
47
|
-
"@comet/eslint-config": "9.0.0-canary-
|
|
47
|
+
"@comet/eslint-config": "9.0.0-canary-20251113142723"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@mikro-orm/cli": "^6.0.0",
|
|
51
|
+
"@mikro-orm/core": "^6.0.0",
|
|
52
|
+
"@mikro-orm/postgresql": "^6.0.0",
|
|
51
53
|
"@nestjs/graphql": "^13.0.0",
|
|
52
54
|
"class-validator": "^0.14.0"
|
|
53
55
|
},
|
|
@@ -59,14 +61,14 @@
|
|
|
59
61
|
"registry": "https://registry.npmjs.org"
|
|
60
62
|
},
|
|
61
63
|
"scripts": {
|
|
62
|
-
"build": "
|
|
64
|
+
"build": "pnpm run clean && tsc -p tsconfig.build.json",
|
|
63
65
|
"clean": "rimraf lib",
|
|
64
66
|
"dev": "tsc --watch --preserveWatchOutput -p tsconfig.build.json",
|
|
65
67
|
"lint": "run-p lint:prettier lint:eslint lint:tsc",
|
|
66
68
|
"lint:eslint": "eslint --max-warnings 0 src/ **/*.json --no-warn-ignored",
|
|
67
|
-
"lint:prettier": "
|
|
69
|
+
"lint:prettier": "pnpm exec prettier --check './**/*.{js,json,md,yml,yaml}'",
|
|
68
70
|
"lint:tsc": "tsc --noEmit",
|
|
69
|
-
"test": "NODE_OPTIONS=--experimental-vm-modules
|
|
71
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules pnpm exec jest",
|
|
70
72
|
"test:updateSnapshot": "NODE_OPTIONS=--experimental-vm-modules jest --updateSnapshot",
|
|
71
73
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
72
74
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type Permission } from "@comet/cms-api";
|
|
2
|
-
import { type SourceFile } from "ts-morph";
|
|
3
|
-
import { type GeneratedFile } from "./write-generated-files";
|
|
4
|
-
export declare function formatSource(sourceCode: string): Promise<string>;
|
|
5
|
-
export declare function formatGeneratedFiles(files: GeneratedFile[]): Promise<GeneratedFile[]>;
|
|
6
|
-
export declare function parseSource(source: string): SourceFile;
|
|
7
|
-
export declare const testPermission: Permission;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.testPermission = void 0;
|
|
46
|
-
exports.formatSource = formatSource;
|
|
47
|
-
exports.formatGeneratedFiles = formatGeneratedFiles;
|
|
48
|
-
exports.parseSource = parseSource;
|
|
49
|
-
const process = __importStar(require("node:process"));
|
|
50
|
-
const prettier_1 = require("prettier");
|
|
51
|
-
const ts_morph_1 = require("ts-morph");
|
|
52
|
-
let options;
|
|
53
|
-
function formatSource(sourceCode) {
|
|
54
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
if (!options)
|
|
56
|
-
options = yield (0, prettier_1.resolveConfig)(process.cwd());
|
|
57
|
-
return (0, prettier_1.format)(sourceCode, Object.assign(Object.assign({}, options), { filepath: "test.ts" }));
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
function formatGeneratedFiles(files) {
|
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
return Promise.all(files.map((file) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
return Object.assign(Object.assign({}, file), { content: yield formatSource(file.content) });
|
|
64
|
-
})));
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
function parseSource(source) {
|
|
68
|
-
const project = new ts_morph_1.Project({
|
|
69
|
-
tsConfigFilePath: "./tsconfig.json",
|
|
70
|
-
skipAddingFilesFromTsConfig: true,
|
|
71
|
-
});
|
|
72
|
-
return project.createSourceFile("test.ts", source);
|
|
73
|
-
}
|
|
74
|
-
exports.testPermission = "crud";
|