@comet/api-generator 8.8.0-canary-20251127150256 → 8.8.0-canary-20251127150553
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.
|
@@ -55,10 +55,14 @@ function buildSortProps(metadata) {
|
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
const crudSortProps = directSortProps(metadata);
|
|
58
|
-
// add nested from relations, one level deep
|
|
59
58
|
metadata.props.forEach((prop) => {
|
|
60
59
|
if ((0, cms_api_1.hasCrudFieldFeature)(metadata.class, prop.name, "sort")) {
|
|
61
|
-
if (
|
|
60
|
+
if (prop.primary) {
|
|
61
|
+
// primary only on root level
|
|
62
|
+
crudSortProps.push(prop.name);
|
|
63
|
+
}
|
|
64
|
+
else if ((prop.kind == "1:1" || prop.kind == "m:1") && prop.targetMeta) {
|
|
65
|
+
// add nested from relations, one level deep
|
|
62
66
|
crudSortProps.push(...directSortProps(prop.targetMeta).map((nestedProp) => `${prop.name}.${nestedProp}`));
|
|
63
67
|
return true;
|
|
64
68
|
}
|
|
@@ -268,12 +268,20 @@ 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
273
|
const { scopeProp, argsClassName, hasSearchArg, hasSortArg, hasFilterArg, dedicatedResolverArgProps, hasPositionProp } = (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
|
+
}
|
|
277
285
|
const argsOut = `import { ArgsType, Field, IntersectionType, registerEnumType, ID } from "@nestjs/graphql";
|
|
278
286
|
import { Type } from "class-transformer";
|
|
279
287
|
import { IsOptional, IsString, ValidateNested, IsEnum, IsUUID } from "class-validator";
|
|
@@ -331,11 +339,10 @@ function generateArgsDto({ generatorOptions, metadata }) {
|
|
|
331
339
|
|
|
332
340
|
${hasSortArg
|
|
333
341
|
? `
|
|
334
|
-
@Field(() => [${classNameSingular}Sort], {
|
|
342
|
+
@Field(() => [${classNameSingular}Sort], { defaultValue: [{ field: ${classNameSingular}SortField.${defaultSortField}, direction: SortDirection.ASC }] })
|
|
335
343
|
@ValidateNested({ each: true })
|
|
336
344
|
@Type(() => ${classNameSingular}Sort)
|
|
337
|
-
${
|
|
338
|
-
sort${!hasPositionProp ? `?` : ""}: ${classNameSingular}Sort[];
|
|
345
|
+
sort: ${classNameSingular}Sort[];
|
|
339
346
|
`
|
|
340
347
|
: ""}
|
|
341
348
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comet/api-generator",
|
|
3
|
-
"version": "8.8.0-canary-
|
|
3
|
+
"version": "8.8.0-canary-20251127150553",
|
|
4
4
|
"description": "Comet API Generator CLI tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"directory": "packages/api/api-generator",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"ts-morph": "^25.0.1",
|
|
26
26
|
"ts-node": "^10.9.2",
|
|
27
27
|
"typescript": "5.9.3",
|
|
28
|
-
"@comet/cms-api": "8.8.0-canary-
|
|
28
|
+
"@comet/cms-api": "8.8.0-canary-20251127150553"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@mikro-orm/cli": "^6.4.16",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"rimraf": "^6.0.1",
|
|
45
45
|
"ts-jest": "^29.4.0",
|
|
46
46
|
"uuid": "^11.1.0",
|
|
47
|
-
"@comet/eslint-config": "8.8.0-canary-
|
|
47
|
+
"@comet/eslint-config": "8.8.0-canary-20251127150553"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@mikro-orm/cli": "^6.0.0",
|