@comet/api-generator 9.0.0-canary-20260113132154 → 9.0.0-canary-20260119123708

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.
@@ -11,6 +11,7 @@ export declare function buildOptions(metadata: EntityMetadata<any>, generatorOpt
11
11
  hasSlugProp: boolean;
12
12
  hasPositionProp: boolean;
13
13
  positionGroupProps: import("@mikro-orm/core").EntityProperty<any, any>[];
14
+ hasDeletedAtProp: boolean;
14
15
  scopeProp: import("@mikro-orm/core").EntityProperty<any, any> | undefined;
15
16
  skipScopeCheck: boolean;
16
17
  argsClassName: string;
@@ -101,6 +101,7 @@ function buildOptions(metadata, generatorOptions) {
101
101
  const scopeProp = metadata.props.find((prop) => prop.name == "scope");
102
102
  if (scopeProp && !scopeProp.targetMeta)
103
103
  throw new Error("Scope prop has no targetMeta");
104
+ const hasDeletedAtProp = metadata.props.some((prop) => prop.name == "deletedAt");
104
105
  const hasPositionProp = metadata.props.some((prop) => prop.name == "position");
105
106
  const positionGroupPropNames = hasPositionProp
106
107
  ? ((_b = (_a = generatorOptions.position) === null || _a === void 0 ? void 0 : _a.groupByFields) !== null && _b !== void 0 ? _b : [
@@ -125,6 +126,7 @@ function buildOptions(metadata, generatorOptions) {
125
126
  hasSlugProp,
126
127
  hasPositionProp,
127
128
  positionGroupProps,
129
+ hasDeletedAtProp,
128
130
  scopeProp,
129
131
  skipScopeCheck,
130
132
  argsClassName,
@@ -719,7 +719,7 @@ function generateRelationsFieldResolver({ generatorOptions, metadata }) {
719
719
  }
720
720
  function generateResolver({ generatorOptions, metadata }) {
721
721
  const { classNameSingular, fileNameSingular, instanceNameSingular, classNamePlural, fileNamePlural, instanceNamePlural } = (0, build_name_variants_1.buildNameVariants)(metadata);
722
- const { scopeProp, skipScopeCheck, argsClassName, argsFileName, hasSlugProp, hasSearchArg, hasSortArg, hasFilterArg, hasPositionProp, positionGroupProps, dedicatedResolverArgProps, } = (0, build_options_1.buildOptions)(metadata, generatorOptions);
722
+ const { scopeProp, skipScopeCheck, argsClassName, argsFileName, hasSlugProp, hasSearchArg, hasSortArg, hasFilterArg, hasPositionProp, positionGroupProps, hasDeletedAtProp, dedicatedResolverArgProps, } = (0, build_options_1.buildOptions)(metadata, generatorOptions);
723
723
  const relationManyToOneProps = metadata.props.filter((prop) => prop.kind === "m:1");
724
724
  const relationOneToManyProps = metadata.props.filter((prop) => prop.kind === "1:m");
725
725
  const relationManyToManyProps = metadata.props.filter((prop) => prop.kind === "m:n");
@@ -973,7 +973,8 @@ function generateResolver({ generatorOptions, metadata }) {
973
973
  @AffectedEntity(${metadata.className})
974
974
  async delete${metadata.className}(${generateIdArg("id", metadata)}): Promise<boolean> {
975
975
  const ${instanceNameSingular} = await this.entityManager.findOneOrFail(${metadata.className}, id);
976
- this.entityManager.remove(${instanceNameSingular});${hasPositionProp
976
+ ${hasDeletedAtProp ? `${instanceNameSingular}.assign({ deletedAt: new Date() });` : `this.entityManager.remove(${instanceNameSingular});`}
977
+ ${hasPositionProp
977
978
  ? `await this.${instanceNamePlural}Service.decrementPositions(${positionGroupProps.length
978
979
  ? `{ ${positionGroupProps
979
980
  .map((prop) => `${prop.name}: ${instanceNameSingular}.${prop.name}${[postgresql_1.ReferenceKind.MANY_TO_ONE, postgresql_1.ReferenceKind.ONE_TO_ONE].includes(prop.kind)
@@ -75,6 +75,18 @@ function generateCrudInput(generatorOptions_1, metadata_1) {
75
75
  { name: "PartialType", importPath: "@comet/cms-api" },
76
76
  { name: "BlockInputInterface", importPath: "@comet/cms-api" },
77
77
  { name: "isBlockInputInterface", importPath: "@comet/cms-api" },
78
+ { name: "IsString", importPath: "class-validator" },
79
+ { name: "IsNotEmpty", importPath: "class-validator" },
80
+ { name: "ValidateNested", importPath: "class-validator" },
81
+ { name: "IsNumber", importPath: "class-validator" },
82
+ { name: "IsBoolean", importPath: "class-validator" },
83
+ { name: "IsDate", importPath: "class-validator" },
84
+ { name: "IsDateString", importPath: "class-validator" },
85
+ { name: "IsOptional", importPath: "class-validator" },
86
+ { name: "IsEnum", importPath: "class-validator" },
87
+ { name: "IsUUID", importPath: "class-validator" },
88
+ { name: "IsArray", importPath: "class-validator" },
89
+ { name: "IsInt", importPath: "class-validator" },
78
90
  ];
79
91
  for (const prop of props) {
80
92
  let type = prop.type;
@@ -223,6 +235,7 @@ function generateCrudInput(generatorOptions_1, metadata_1) {
223
235
  }
224
236
  else {
225
237
  console.warn(`${prop.name}: Unsupported referenced type`);
238
+ continue;
226
239
  }
227
240
  }
228
241
  else if (prop.kind == "1:m") {
@@ -466,7 +479,6 @@ function generateCrudInput(generatorOptions_1, metadata_1) {
466
479
  const className = (_m = options.className) !== null && _m !== void 0 ? _m : `${metadata.className}Input`;
467
480
  const inputOut = `import { Field, InputType, ID, Int } from "@nestjs/graphql";
468
481
  import { Transform, Type } from "class-transformer";
469
- import { IsString, IsNotEmpty, ValidateNested, IsNumber, IsBoolean, IsDate, IsDateString, IsOptional, IsEnum, IsUUID, IsArray, IsInt } from "class-validator";
470
482
  import { GraphQLJSONObject, GraphQLLocalDate } from "graphql-scalars";
471
483
  ${(0, generate_imports_code_1.generateImportsCode)(imports)}
472
484
 
@@ -14,12 +14,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.generateFiles = void 0;
16
16
  const node_console_1 = __importDefault(require("node:console"));
17
+ const node_fs_1 = require("node:fs");
17
18
  const cms_api_1 = require("@comet/cms-api");
18
19
  const cli_1 = require("@mikro-orm/cli");
19
20
  const lazy_metadata_storage_1 = require("@nestjs/graphql/dist/schema-builder/storages/lazy-metadata.storage");
21
+ const child_process_1 = require("child_process");
22
+ const util_1 = require("util");
20
23
  const generate_crud_1 = require("./generateCrud/generate-crud");
21
24
  const generate_crud_single_1 = require("./generateCrudSingle/generate-crud-single");
22
25
  const write_generated_files_1 = require("./utils/write-generated-files");
26
+ const exec = (0, util_1.promisify)(child_process_1.exec);
23
27
  /**
24
28
  * Generate mode for the generator.
25
29
  *
@@ -41,6 +45,7 @@ file) => __awaiter(void 0, void 0, void 0, function* () {
41
45
  node_console_1.default.warn(e);
42
46
  }
43
47
  if (orm != null) {
48
+ const writtenFiles = [];
44
49
  const entities = orm.em.getMetadata().getAll();
45
50
  lazy_metadata_storage_1.LazyMetadataStorage.load();
46
51
  for (const name in entities) {
@@ -56,6 +61,7 @@ file) => __awaiter(void 0, void 0, void 0, function* () {
56
61
  node_console_1.default.log(`🚀 start generateCrud for Entity ${entity.path}`);
57
62
  const files = yield (0, generate_crud_1.generateCrud)(generatorOptions, entity);
58
63
  yield (0, write_generated_files_1.writeGeneratedFiles)(files, { targetDirectory: generatorOptions.targetDirectory });
64
+ writtenFiles.push(...files.map((f) => (0, node_fs_1.realpathSync)(`${generatorOptions.targetDirectory}/${f.name}`)));
59
65
  }
60
66
  }
61
67
  {
@@ -64,10 +70,15 @@ file) => __awaiter(void 0, void 0, void 0, function* () {
64
70
  node_console_1.default.log(`🚀 start generateCrudSingle for Entity ${entity.path}`);
65
71
  const files = yield (0, generate_crud_single_1.generateCrudSingle)(generatorOptions, entity);
66
72
  yield (0, write_generated_files_1.writeGeneratedFiles)(files, { targetDirectory: generatorOptions.targetDirectory });
73
+ writtenFiles.push(...files.map((f) => (0, node_fs_1.realpathSync)(`${generatorOptions.targetDirectory}/${f.name}`)));
67
74
  }
68
75
  }
69
76
  }
70
77
  }
78
+ if (writtenFiles.length > 0) {
79
+ node_console_1.default.log("Formatting generated files...");
80
+ yield exec(`./node_modules/.bin/prettier --write ${writtenFiles.join(" ")}`);
81
+ }
71
82
  }
72
83
  });
73
84
  exports.generateFiles = generateFiles;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comet/api-generator",
3
- "version": "9.0.0-canary-20260113132154",
3
+ "version": "9.0.0-canary-20260119123708",
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-20260113132154"
28
+ "@comet/cms-api": "9.0.0-canary-20260119123708"
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.2.0",
34
+ "@nestjs/graphql": "^13.2.3",
35
35
  "@types/jest": "^29.5.14",
36
36
  "@types/node": "^24.9.1",
37
37
  "@types/pluralize": "^0.0.33",
38
38
  "class-validator": "^0.14.3",
39
39
  "eslint": "^9.30.1",
40
40
  "jest": "^29.7.0",
41
- "npm-run-all2": "^8.0.0",
41
+ "npm-run-all2": "^8.0.4",
42
42
  "prettier": "^3.6.2",
43
43
  "reflect-metadata": "^0.2.2",
44
44
  "rimraf": "^6.1.2",
45
- "ts-jest": "^29.4.0",
45
+ "ts-jest": "^29.4.6",
46
46
  "uuid": "^11.1.0",
47
- "@comet/eslint-config": "9.0.0-canary-20260113132154"
47
+ "@comet/eslint-config": "9.0.0-canary-20260119123708"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@mikro-orm/cli": "^6.0.0",
@@ -67,7 +67,7 @@
67
67
  "lint": "run-p lint:prettier lint:eslint lint:tsc",
68
68
  "lint:ci": "pnpm run lint",
69
69
  "lint:eslint": "eslint --max-warnings 0 src/ **/*.json --no-warn-ignored",
70
- "lint:prettier": "pnpm exec prettier --check './**/*.{js,json,md,yml,yaml}'",
70
+ "lint:prettier": "pnpm exec prettier --check '*.{ts,js,json,md,yml,yaml}'",
71
71
  "lint:tsc": "tsc --noEmit",
72
72
  "test": "NODE_OPTIONS=--experimental-vm-modules pnpm exec jest",
73
73
  "test:updateSnapshot": "NODE_OPTIONS=--experimental-vm-modules jest --updateSnapshot",