@comet/api-generator 8.0.0-canary-20250227115813

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.
Files changed (27) hide show
  1. package/LICENSE +24 -0
  2. package/bin/api-generator.js +5 -0
  3. package/lib/apiGenerator.d.ts +1 -0
  4. package/lib/apiGenerator.js +7 -0
  5. package/lib/commands/generate/generate-command.d.ts +2 -0
  6. package/lib/commands/generate/generate-command.js +45 -0
  7. package/lib/commands/generate/generateCrud/generate-crud.d.ts +24 -0
  8. package/lib/commands/generate/generateCrud/generate-crud.js +1212 -0
  9. package/lib/commands/generate/generateCrudInput/generate-crud-input.d.ts +11 -0
  10. package/lib/commands/generate/generateCrudInput/generate-crud-input.js +463 -0
  11. package/lib/commands/generate/generateCrudSingle/generate-crud-single.d.ts +4 -0
  12. package/lib/commands/generate/generateCrudSingle/generate-crud-single.js +153 -0
  13. package/lib/commands/generate/utils/build-name-variants.d.ts +10 -0
  14. package/lib/commands/generate/utils/build-name-variants.js +25 -0
  15. package/lib/commands/generate/utils/constants.d.ts +1 -0
  16. package/lib/commands/generate/utils/constants.js +4 -0
  17. package/lib/commands/generate/utils/generate-imports-code.d.ts +5 -0
  18. package/lib/commands/generate/utils/generate-imports-code.js +32 -0
  19. package/lib/commands/generate/utils/test-helper.d.ts +5 -0
  20. package/lib/commands/generate/utils/test-helper.js +72 -0
  21. package/lib/commands/generate/utils/ts-morph-helper.d.ts +10 -0
  22. package/lib/commands/generate/utils/ts-morph-helper.js +191 -0
  23. package/lib/commands/generate/utils/write-generated-file.d.ts +1 -0
  24. package/lib/commands/generate/utils/write-generated-file.js +69 -0
  25. package/lib/commands/generate/utils/write-generated-files.d.ts +8 -0
  26. package/lib/commands/generate/utils/write-generated-files.js +20 -0
  27. package/package.json +66 -0
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2023, Vivid Planet Software GmbH
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ require("ts-node").register({
3
+ require: ["tsconfig-paths/register"],
4
+ });
5
+ require("../lib/apiGenerator");
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const commander_1 = require("commander");
4
+ const generate_command_1 = require("./commands/generate/generate-command");
5
+ const program = new commander_1.Command();
6
+ program.addCommand(generate_command_1.generateCommand);
7
+ program.parse();
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const generateCommand: Command;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.generateCommand = void 0;
13
+ const cli_1 = require("@mikro-orm/cli");
14
+ const lazy_metadata_storage_1 = require("@nestjs/graphql/dist/schema-builder/storages/lazy-metadata.storage");
15
+ const commander_1 = require("commander");
16
+ const generate_crud_1 = require("./generateCrud/generate-crud");
17
+ const generate_crud_single_1 = require("./generateCrudSingle/generate-crud-single");
18
+ const write_generated_files_1 = require("./utils/write-generated-files");
19
+ exports.generateCommand = new commander_1.Command("generate").action((options) => __awaiter(void 0, void 0, void 0, function* () {
20
+ const orm = yield cli_1.CLIHelper.getORM(undefined, undefined, { dbName: "generator" });
21
+ const entities = orm.em.getMetadata().getAll();
22
+ lazy_metadata_storage_1.LazyMetadataStorage.load();
23
+ for (const name in entities) {
24
+ const entity = entities[name];
25
+ if (!entity.class) {
26
+ // Ignore e.g. relation entities that don't have a class
27
+ continue;
28
+ }
29
+ {
30
+ const generatorOptions = Reflect.getMetadata(`data:crudGeneratorOptions`, entity.class);
31
+ if (generatorOptions) {
32
+ const files = yield (0, generate_crud_1.generateCrud)(generatorOptions, entity);
33
+ yield (0, write_generated_files_1.writeGeneratedFiles)(files, { targetDirectory: generatorOptions.targetDirectory });
34
+ }
35
+ }
36
+ {
37
+ const generatorOptions = Reflect.getMetadata(`data:crudSingleGeneratorOptions`, entity.class);
38
+ if (generatorOptions) {
39
+ const files = yield (0, generate_crud_single_1.generateCrudSingle)(generatorOptions, entity);
40
+ yield (0, write_generated_files_1.writeGeneratedFiles)(files, { targetDirectory: generatorOptions.targetDirectory });
41
+ }
42
+ }
43
+ }
44
+ yield orm.close(true);
45
+ }));
@@ -0,0 +1,24 @@
1
+ import { type CrudGeneratorOptions } from "@comet/cms-api";
2
+ import { type EntityMetadata } from "@mikro-orm/postgresql";
3
+ import { type GeneratedFile } from "../utils/write-generated-files";
4
+ export declare function buildOptions(metadata: EntityMetadata<any>, generatorOptions: CrudGeneratorOptions): {
5
+ crudSearchPropNames: string[];
6
+ hasSearchArg: boolean;
7
+ crudFilterProps: import("@mikro-orm/postgresql").EntityProperty<any, any>[];
8
+ hasFilterArg: boolean;
9
+ crudSortProps: import("@mikro-orm/postgresql").EntityProperty<any, any>[];
10
+ hasSortArg: boolean;
11
+ hasSlugProp: boolean;
12
+ hasPositionProp: boolean;
13
+ positionGroupProps: import("@mikro-orm/postgresql").EntityProperty<any, any>[];
14
+ statusProp: import("@mikro-orm/postgresql").EntityProperty<any, any> | undefined;
15
+ statusActiveItems: (string | number)[] | undefined;
16
+ hasStatusFilter: boolean | undefined;
17
+ scopeProp: import("@mikro-orm/postgresql").EntityProperty<any, any> | undefined;
18
+ skipScopeCheck: boolean;
19
+ argsClassName: string;
20
+ argsFileName: string;
21
+ blockProps: import("@mikro-orm/postgresql").EntityProperty<any, any>[];
22
+ dedicatedResolverArgProps: import("@mikro-orm/postgresql").EntityProperty<any, any>[];
23
+ };
24
+ export declare function generateCrud(generatorOptionsParam: CrudGeneratorOptions, metadata: EntityMetadata<any>): Promise<GeneratedFile[]>;