@comet/api-generator 9.0.0-canary-20251202103135 → 9.0.0-canary-20251209140438
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.
|
@@ -37,6 +37,7 @@ function buildSortProps(metadata) {
|
|
|
37
37
|
return metadata.props
|
|
38
38
|
.filter((prop) => (0, cms_api_1.hasCrudFieldFeature)(metadata.class, prop.name, "sort") &&
|
|
39
39
|
!prop.name.startsWith("scope_") &&
|
|
40
|
+
!prop.primary &&
|
|
40
41
|
(!prop.embedded || (0, cms_api_1.hasCrudFieldFeature)(metadata.class, prop.embedded[0], "sort")) && // the whole embeddable has sort disabled
|
|
41
42
|
(prop.type === "string" ||
|
|
42
43
|
prop.type === "text" ||
|
|
@@ -55,10 +56,14 @@ function buildSortProps(metadata) {
|
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
const crudSortProps = directSortProps(metadata);
|
|
58
|
-
// add nested from relations, one level deep
|
|
59
59
|
metadata.props.forEach((prop) => {
|
|
60
60
|
if ((0, cms_api_1.hasCrudFieldFeature)(metadata.class, prop.name, "sort")) {
|
|
61
|
-
if (
|
|
61
|
+
if (prop.primary) {
|
|
62
|
+
// primary only on root level
|
|
63
|
+
crudSortProps.push(prop.name);
|
|
64
|
+
}
|
|
65
|
+
else if ((prop.kind == "1:1" || prop.kind == "m:1") && prop.targetMeta) {
|
|
66
|
+
// add nested from relations, one level deep
|
|
62
67
|
crudSortProps.push(...directSortProps(prop.targetMeta).map((nestedProp) => `${prop.name}.${nestedProp}`));
|
|
63
68
|
return true;
|
|
64
69
|
}
|
|
@@ -268,12 +268,22 @@ function generatePaginatedDto({ generatorOptions, metadata }) {
|
|
|
268
268
|
return paginatedOut;
|
|
269
269
|
}
|
|
270
270
|
function generateArgsDto({ generatorOptions, metadata }) {
|
|
271
|
+
var _a;
|
|
271
272
|
const { classNameSingular, fileNameSingular } = (0, build_name_variants_1.buildNameVariants)(metadata);
|
|
272
|
-
const { scopeProp, argsClassName, hasSearchArg, hasSortArg, hasFilterArg, dedicatedResolverArgProps, hasPositionProp } = (0, build_options_1.buildOptions)(metadata, generatorOptions);
|
|
273
|
+
const { scopeProp, argsClassName, hasSearchArg, hasSortArg, hasFilterArg, dedicatedResolverArgProps, hasPositionProp, crudSortProps } = (0, build_options_1.buildOptions)(metadata, generatorOptions);
|
|
273
274
|
const imports = [];
|
|
274
275
|
if (scopeProp && scopeProp.targetMeta) {
|
|
275
276
|
imports.push(generateEntityImport(scopeProp.targetMeta, `${generatorOptions.targetDirectory}/dto`));
|
|
276
277
|
}
|
|
278
|
+
let defaultSortField = ((_a = metadata.props.find((prop) => prop.primary)) === null || _a === void 0 ? void 0 : _a.name) || "id";
|
|
279
|
+
if (hasPositionProp) {
|
|
280
|
+
defaultSortField = "position";
|
|
281
|
+
}
|
|
282
|
+
else if (metadata.props.some((prop) => prop.name === "createdAt" && prop.type === "Date")) {
|
|
283
|
+
defaultSortField = "createdAt";
|
|
284
|
+
}
|
|
285
|
+
if (!crudSortProps.includes(defaultSortField))
|
|
286
|
+
defaultSortField = null;
|
|
277
287
|
const argsOut = `import { ArgsType, Field, IntersectionType, registerEnumType, ID } from "@nestjs/graphql";
|
|
278
288
|
import { Type } from "class-transformer";
|
|
279
289
|
import { IsOptional, IsString, ValidateNested, IsEnum, IsUUID } from "class-validator";
|
|
@@ -331,11 +341,11 @@ function generateArgsDto({ generatorOptions, metadata }) {
|
|
|
331
341
|
|
|
332
342
|
${hasSortArg
|
|
333
343
|
? `
|
|
334
|
-
@Field(() => [${classNameSingular}Sort], { ${
|
|
344
|
+
@Field(() => [${classNameSingular}Sort], { ${defaultSortField === null ? "nullable: true" : `defaultValue: [{ field: ${classNameSingular}SortField.${defaultSortField}, direction: SortDirection.ASC }]`} })
|
|
335
345
|
@ValidateNested({ each: true })
|
|
336
346
|
@Type(() => ${classNameSingular}Sort)
|
|
337
|
-
${
|
|
338
|
-
sort${
|
|
347
|
+
${defaultSortField === null ? "@IsOptional()" : ""}
|
|
348
|
+
sort${defaultSortField === null ? "?" : ""}: ${classNameSingular}Sort[];
|
|
339
349
|
`
|
|
340
350
|
: ""}
|
|
341
351
|
}
|
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-20251209140438",
|
|
4
4
|
"description": "Comet API Generator CLI tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"directory": "packages/api/api-generator",
|
|
@@ -25,26 +25,26 @@
|
|
|
25
25
|
"ts-morph": "^25.0.1",
|
|
26
26
|
"ts-node": "^10.9.2",
|
|
27
27
|
"typescript": "5.9.3",
|
|
28
|
-
"@comet/cms-api": "9.0.0-canary-
|
|
28
|
+
"@comet/cms-api": "9.0.0-canary-20251209140438"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@mikro-orm/cli": "^6.4.16",
|
|
32
32
|
"@mikro-orm/core": "^6.4.16",
|
|
33
33
|
"@mikro-orm/postgresql": "^6.4.16",
|
|
34
|
-
"@nestjs/graphql": "^13.
|
|
34
|
+
"@nestjs/graphql": "^13.2.0",
|
|
35
35
|
"@types/jest": "^29.5.14",
|
|
36
36
|
"@types/node": "^24.9.1",
|
|
37
37
|
"@types/pluralize": "^0.0.33",
|
|
38
|
-
"class-validator": "^0.14.
|
|
38
|
+
"class-validator": "^0.14.3",
|
|
39
39
|
"eslint": "^9.30.1",
|
|
40
40
|
"jest": "^29.7.0",
|
|
41
41
|
"npm-run-all2": "^8.0.0",
|
|
42
42
|
"prettier": "^3.6.2",
|
|
43
43
|
"reflect-metadata": "^0.2.2",
|
|
44
|
-
"rimraf": "^6.
|
|
44
|
+
"rimraf": "^6.1.2",
|
|
45
45
|
"ts-jest": "^29.4.0",
|
|
46
46
|
"uuid": "^11.1.0",
|
|
47
|
-
"@comet/eslint-config": "9.0.0-canary-
|
|
47
|
+
"@comet/eslint-config": "9.0.0-canary-20251209140438"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@mikro-orm/cli": "^6.0.0",
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"clean": "rimraf lib",
|
|
66
66
|
"dev": "tsc --watch --preserveWatchOutput -p tsconfig.build.json",
|
|
67
67
|
"lint": "run-p lint:prettier lint:eslint lint:tsc",
|
|
68
|
+
"lint:ci": "pnpm run lint",
|
|
68
69
|
"lint:eslint": "eslint --max-warnings 0 src/ **/*.json --no-warn-ignored",
|
|
69
70
|
"lint:prettier": "pnpm exec prettier --check './**/*.{js,json,md,yml,yaml}'",
|
|
70
71
|
"lint:tsc": "tsc --noEmit",
|