@comet/api-generator 9.0.0-beta.5 → 9.0.0-beta.6
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.
|
@@ -600,6 +600,7 @@ ${options.mode == "update"
|
|
|
600
600
|
function generateNestedEntityResolver({ generatorOptions, metadata }) {
|
|
601
601
|
const { classNameSingular } = (0, build_name_variants_1.buildNameVariants)(metadata);
|
|
602
602
|
const { skipScopeCheck, targetDirectory } = (0, build_options_1.buildOptions)(metadata, generatorOptions);
|
|
603
|
+
const entityHasRequiredPermission = !!Reflect.getMetadata(cms_api_1.REQUIRED_PERMISSION_METADATA_KEY, metadata.class);
|
|
603
604
|
const imports = [];
|
|
604
605
|
const { imports: fieldImports, code, hasOutputRelations, needsBlocksTransformer, } = generateRelationsFieldResolver({ generatorOptions, metadata });
|
|
605
606
|
if (!hasOutputRelations) {
|
|
@@ -608,12 +609,12 @@ function generateNestedEntityResolver({ generatorOptions, metadata }) {
|
|
|
608
609
|
imports.push(...fieldImports);
|
|
609
610
|
imports.push(generateEntityImport(metadata, targetDirectory));
|
|
610
611
|
return `
|
|
611
|
-
import { RequiredPermission, RootBlockDataScalar, BlocksTransformerService } from "@comet/cms-api";
|
|
612
|
+
import { ${entityHasRequiredPermission ? "" : "RequiredPermission, "}RootBlockDataScalar, BlocksTransformerService } from "@comet/cms-api";
|
|
612
613
|
import { Args, ID, Info, Mutation, Query, Resolver, ResolveField, Parent } from "@nestjs/graphql";
|
|
613
614
|
${(0, generate_imports_code_1.generateImportsCode)(imports)}
|
|
614
615
|
|
|
615
616
|
@Resolver(() => ${metadata.className})
|
|
616
|
-
|
|
617
|
+
${entityHasRequiredPermission ? "" : `@RequiredPermission(${JSON.stringify(generatorOptions.requiredPermission)}${skipScopeCheck ? `, { skipScopeCheck: true }` : ""})`}
|
|
617
618
|
export class ${classNameSingular}Resolver {
|
|
618
619
|
${needsBlocksTransformer ? `constructor(protected readonly blocksTransformer: BlocksTransformerService) {}` : ""}
|
|
619
620
|
${code}
|
|
@@ -753,8 +754,11 @@ function generateResolver({ generatorOptions, metadata }) {
|
|
|
753
754
|
}
|
|
754
755
|
const payloadObjectTypes = (0, generate_payload_object_types_1.generatePayloadObjectTypes)({ hooksService, instanceNameSingular, entityName: metadata.className });
|
|
755
756
|
imports.push(...payloadObjectTypes.imports);
|
|
757
|
+
const entityHasRequiredPermission = !!Reflect.getMetadata(cms_api_1.REQUIRED_PERMISSION_METADATA_KEY, metadata.class);
|
|
756
758
|
imports.push({ name: "SortDirection", importPath: "@comet/cms-api" });
|
|
757
|
-
|
|
759
|
+
if (!entityHasRequiredPermission) {
|
|
760
|
+
imports.push({ name: "RequiredPermission", importPath: "@comet/cms-api" });
|
|
761
|
+
}
|
|
758
762
|
imports.push({ name: "AffectedEntity", importPath: "@comet/cms-api" });
|
|
759
763
|
imports.push({ name: "validateNotModified", importPath: "@comet/cms-api" });
|
|
760
764
|
imports.push({ name: "RootBlockDataScalar", importPath: "@comet/cms-api" });
|
|
@@ -773,7 +777,7 @@ function generateResolver({ generatorOptions, metadata }) {
|
|
|
773
777
|
${payloadObjectTypes.code}
|
|
774
778
|
|
|
775
779
|
@Resolver(() => ${metadata.className})
|
|
776
|
-
|
|
780
|
+
${entityHasRequiredPermission ? "" : `@RequiredPermission(${JSON.stringify(generatorOptions.requiredPermission)}${skipScopeCheck ? `, { skipScopeCheck: true }` : ""})`}
|
|
777
781
|
export class ${classNameSingular}Resolver {
|
|
778
782
|
constructor(
|
|
779
783
|
protected readonly entityManager: EntityManager,${hasPositionProp ? `protected readonly ${instanceNamePlural}Service: ${classNamePlural}Service,` : ``}
|
|
@@ -49,6 +49,7 @@ async function generateCrudSingle(generatorOptions, metadata) {
|
|
|
49
49
|
const { targetDirectory } = (0, build_options_1.buildOptions)(metadata, generatorOptions);
|
|
50
50
|
async function generateCrudResolver() {
|
|
51
51
|
const generatedFiles = [];
|
|
52
|
+
const entityHasRequiredPermission = !!Reflect.getMetadata(cms_api_1.REQUIRED_PERMISSION_METADATA_KEY, metadata.class);
|
|
52
53
|
const scopeProp = metadata.props.find((prop) => prop.name == "scope");
|
|
53
54
|
if (scopeProp && !scopeProp.targetMeta) {
|
|
54
55
|
throw new Error("Scope prop has no targetMeta");
|
|
@@ -68,7 +69,7 @@ async function generateCrudSingle(generatorOptions, metadata) {
|
|
|
68
69
|
generatedFiles.push({ name: `${fileNamePlural}.service.ts`, content: serviceOut, type: "service" });
|
|
69
70
|
const resolverOut = `import { FindOptions, EntityManager } from "@mikro-orm/postgresql";
|
|
70
71
|
import { Args, ID, Mutation, Query, Resolver } from "@nestjs/graphql";
|
|
71
|
-
import { RequiredPermission, SortDirection, validateNotModified } from "@comet/cms-api";
|
|
72
|
+
import { ${entityHasRequiredPermission ? "" : "RequiredPermission, "}SortDirection, validateNotModified } from "@comet/cms-api";
|
|
72
73
|
|
|
73
74
|
import { ${metadata.className} } from "${path.relative(targetDirectory, metadata.path).replace(/\.ts$/, "")}";
|
|
74
75
|
${scopeProp && scopeProp.targetMeta
|
|
@@ -78,7 +79,7 @@ async function generateCrudSingle(generatorOptions, metadata) {
|
|
|
78
79
|
import { ${classNameSingular}Input } from "./dto/${fileNameSingular}.input";
|
|
79
80
|
|
|
80
81
|
@Resolver(() => ${metadata.className})
|
|
81
|
-
|
|
82
|
+
${entityHasRequiredPermission ? "" : `@RequiredPermission(${JSON.stringify(generatorOptions.requiredPermission)}${!scopeProp ? `, { skipScopeCheck: true }` : ""})`}
|
|
82
83
|
export class ${classNameSingular}Resolver {
|
|
83
84
|
constructor(
|
|
84
85
|
protected readonly entityManager: EntityManager,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comet/api-generator",
|
|
3
|
-
"version": "9.0.0-beta.
|
|
3
|
+
"version": "9.0.0-beta.6",
|
|
4
4
|
"description": "Comet API Generator CLI tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"directory": "packages/api/api-generator",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"ts-morph": "^25.0.1",
|
|
27
27
|
"ts-node": "^10.9.2",
|
|
28
28
|
"typescript": "^5.9.3",
|
|
29
|
-
"@comet/cms-api": "9.0.0-beta.
|
|
29
|
+
"@comet/cms-api": "9.0.0-beta.6"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@mikro-orm/cli": "^6.6.14",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"rimraf": "^6.1.2",
|
|
44
44
|
"unplugin-swc": "^1.5.9",
|
|
45
45
|
"uuid": "^11.1.1",
|
|
46
|
-
"vitest": "^4.
|
|
47
|
-
"@comet/eslint-config": "9.0.0-beta.
|
|
46
|
+
"vitest": "^4.1.8",
|
|
47
|
+
"@comet/eslint-config": "9.0.0-beta.6"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@mikro-orm/cli": "^6.0.0",
|