@mbc-cqrs-serverless/cli 0.1.49-beta.0 → 0.1.51-beta.0

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 (109) hide show
  1. package/README.md +94 -63
  2. package/dist/actions/generate.action.js +44 -0
  3. package/dist/actions/new.action.get-package-version.spec.js +29 -0
  4. package/dist/actions/new.action.is-latest-version.spec.js +36 -0
  5. package/dist/actions/new.action.js +12 -6
  6. package/dist/actions/new.action.spec.js +84 -0
  7. package/dist/actions/new.action.update-env-local.spec.js +35 -0
  8. package/dist/actions/new.action.use-package-version.spec.js +46 -0
  9. package/dist/actions/ui.action.js +7 -5
  10. package/dist/commands/command.input.js +2 -0
  11. package/dist/commands/generate.command.js +24 -0
  12. package/dist/commands/index.js +2 -0
  13. package/dist/index.js +13 -2
  14. package/dist/runners/abstract.runner.js +44 -0
  15. package/dist/runners/schematic.runner.js +21 -0
  16. package/dist/schematics/collection.json +34 -0
  17. package/dist/schematics/index.js +17 -0
  18. package/dist/schematics/lib/controller/controller.factory.js +40 -0
  19. package/dist/schematics/lib/controller/controller.factory.spec.js +79 -0
  20. package/dist/schematics/lib/controller/files/__name@dasherize__.controller.ts +11 -0
  21. package/dist/schematics/lib/controller/schema.json +18 -0
  22. package/dist/schematics/lib/controller/units/__name@dasherize__.controller.__specFileSuffix__.ts +19 -0
  23. package/dist/schematics/lib/dto/dto.factory.js +32 -0
  24. package/dist/schematics/lib/dto/dto.factory.spec.js +128 -0
  25. package/dist/schematics/lib/dto/files/dto/__name@dasherize__-attributes.dto.ts +6 -0
  26. package/dist/schematics/lib/dto/files/dto/__name@dasherize__-command.dto.ts +16 -0
  27. package/dist/schematics/lib/dto/files/dto/__name@dasherize__-create.dto.ts +18 -0
  28. package/dist/schematics/lib/dto/files/dto/__name@dasherize__-search.dto.ts +2 -0
  29. package/dist/schematics/lib/dto/files/dto/__name@dasherize__-update.dto.ts +34 -0
  30. package/dist/schematics/lib/dto/schema.json +18 -0
  31. package/dist/schematics/lib/entity/entity.factory.js +30 -0
  32. package/dist/schematics/lib/entity/entity.factory.spec.js +86 -0
  33. package/dist/schematics/lib/entity/files/entity/__name@dasherize__-command.entity.ts +12 -0
  34. package/dist/schematics/lib/entity/files/entity/__name@dasherize__-data-list.entity.ts +12 -0
  35. package/dist/schematics/lib/entity/files/entity/__name@dasherize__-data.entity.ts +12 -0
  36. package/dist/schematics/lib/entity/schema.json +18 -0
  37. package/dist/schematics/lib/module/files/async/__name@dasherize__.controller.ts +74 -0
  38. package/dist/schematics/lib/module/files/async/__name@dasherize__.module.ts +19 -0
  39. package/dist/schematics/lib/module/files/async/__name@dasherize__.service.ts +164 -0
  40. package/dist/schematics/lib/module/files/async/dto/__name@dasherize__-attributes.dto.ts +6 -0
  41. package/dist/schematics/lib/module/files/async/dto/__name@dasherize__-command.dto.ts +16 -0
  42. package/dist/schematics/lib/module/files/async/dto/__name@dasherize__-create.dto.ts +18 -0
  43. package/dist/schematics/lib/module/files/async/dto/__name@dasherize__-search.dto.ts +2 -0
  44. package/dist/schematics/lib/module/files/async/dto/__name@dasherize__-update.dto.ts +34 -0
  45. package/dist/schematics/lib/module/files/async/entity/__name@dasherize__-command.entity.ts +12 -0
  46. package/dist/schematics/lib/module/files/async/entity/__name@dasherize__-data-list.entity.ts +12 -0
  47. package/dist/schematics/lib/module/files/async/entity/__name@dasherize__-data.entity.ts +12 -0
  48. package/dist/schematics/lib/module/files/async/handler/__name@dasherize__-rds.handler.ts +62 -0
  49. package/dist/schematics/lib/module/files/sync/__name@dasherize__.controller.ts +74 -0
  50. package/dist/schematics/lib/module/files/sync/__name@dasherize__.module.ts +19 -0
  51. package/dist/schematics/lib/module/files/sync/__name@dasherize__.service.ts +164 -0
  52. package/dist/schematics/lib/module/files/sync/dto/__name@dasherize__-attributes.dto.ts +6 -0
  53. package/dist/schematics/lib/module/files/sync/dto/__name@dasherize__-command.dto.ts +16 -0
  54. package/dist/schematics/lib/module/files/sync/dto/__name@dasherize__-create.dto.ts +18 -0
  55. package/dist/schematics/lib/module/files/sync/dto/__name@dasherize__-search.dto.ts +2 -0
  56. package/dist/schematics/lib/module/files/sync/dto/__name@dasherize__-update.dto.ts +34 -0
  57. package/dist/schematics/lib/module/files/sync/entity/__name@dasherize__-command.entity.ts +12 -0
  58. package/dist/schematics/lib/module/files/sync/entity/__name@dasherize__-data-list.entity.ts +12 -0
  59. package/dist/schematics/lib/module/files/sync/entity/__name@dasherize__-data.entity.ts +12 -0
  60. package/dist/schematics/lib/module/files/sync/handler/__name@dasherize__-rds.handler.ts +62 -0
  61. package/dist/schematics/lib/module/module.factory.js +204 -0
  62. package/dist/schematics/lib/module/module.factory.spec.js +188 -0
  63. package/dist/schematics/lib/module/schema.json +28 -0
  64. package/dist/schematics/lib/module/units/__name@dasherize__.controller.__specFileSuffix__.ts +19 -0
  65. package/dist/schematics/lib/module/units/__name@dasherize__.service.__specFileSuffix__.ts +19 -0
  66. package/dist/schematics/lib/service/files/__name@dasherize__.service.ts +12 -0
  67. package/dist/schematics/lib/service/schema.json +18 -0
  68. package/dist/schematics/lib/service/service.factory.js +40 -0
  69. package/dist/schematics/lib/service/service.factory.spec.js +81 -0
  70. package/dist/schematics/lib/service/units/__name@dasherize__.service.__specFileSuffix__.ts +19 -0
  71. package/dist/schematics/schematic.colection.js +60 -0
  72. package/dist/schematics/schematic.option.js +44 -0
  73. package/dist/schematics/utils/check-files-exist.js +13 -0
  74. package/dist/schematics/utils/index.js +17 -0
  75. package/dist/ui/index.js +18 -0
  76. package/dist/ui/logger.js +54 -0
  77. package/dist/ui/message.js +6 -0
  78. package/dist/utils/formatting.js +18 -0
  79. package/dist/utils/index.js +18 -0
  80. package/dist/utils/local-binaries.js +20 -0
  81. package/package.json +14 -5
  82. package/templates/.env.local +1 -1
  83. package/templates/README.md +1 -1
  84. package/templates/infra/README.md +6 -1
  85. package/templates/infra/libs/infra-stack.ts +1 -1
  86. package/templates/infra-local/docker-compose.yml +1 -1
  87. package/templates/infra-local/serverless.yml +19 -21
  88. package/templates/infra-local/swagger.json +396 -0
  89. package/templates/package.json +1 -0
  90. package/templates/prisma/dynamodbs/cqrs.json +1 -1
  91. package/templates/prisma/schema.prisma +4 -7
  92. package/templates/src/helpers/id.ts +12 -0
  93. package/templates/src/helpers/index.ts +1 -0
  94. package/templates/src/main.module.ts +2 -2
  95. package/templates/src/{master/dto/master-attributes.dto.ts → sample/dto/sample-attributes.dto.ts} +2 -2
  96. package/templates/src/{master/dto/master-command.dto.ts → sample/dto/sample-command.dto.ts} +4 -4
  97. package/templates/src/sample/entity/sample-command.entity.ts +13 -0
  98. package/templates/src/sample/entity/sample-data-list.entity.ts +13 -0
  99. package/templates/src/sample/entity/sample-data.entity.ts +13 -0
  100. package/templates/src/{master/handler/master-rds.handler.ts → sample/handler/sample-rds.handler.ts} +5 -7
  101. package/templates/src/{master/master.controller.ts → sample/sample.controller.ts} +22 -22
  102. package/templates/src/sample/sample.module.ts +19 -0
  103. package/templates/src/{master/master.service.ts → sample/sample.service.ts} +12 -12
  104. package/templates/test/api.http +25 -0
  105. package/templates/tsconfig.json +1 -1
  106. package/templates/src/master/entity/master-command.entity.ts +0 -13
  107. package/templates/src/master/entity/master-data-list.entity.ts +0 -13
  108. package/templates/src/master/entity/master-data.entity.ts +0 -13
  109. package/templates/src/master/master.module.ts +0 -19
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractRunner = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const ui_1 = require("../ui");
6
+ /* eslint-disable no-console */
7
+ class AbstractRunner {
8
+ constructor(binary, args = []) {
9
+ this.binary = binary;
10
+ this.args = args;
11
+ }
12
+ async run(command, collect = false, cwd = process.cwd()) {
13
+ const args = [command];
14
+ const options = {
15
+ cwd,
16
+ stdio: collect ? 'pipe' : 'inherit',
17
+ shell: true,
18
+ };
19
+ return new Promise((resolve, reject) => {
20
+ const child = (0, child_process_1.spawn)(`${this.binary}`, [...this.args, ...args], options);
21
+ if (collect) {
22
+ child.stdout.on('data', (data) => resolve(data.toString().replace(/\r\n|\n/, '')));
23
+ }
24
+ child.on('close', (code) => {
25
+ if (code === 0) {
26
+ resolve(null);
27
+ }
28
+ else {
29
+ console.error(ui_1.MESSAGES.RUNNER_EXECUTION_ERROR(`${this.binary} ${command}`));
30
+ reject();
31
+ }
32
+ });
33
+ });
34
+ }
35
+ /**
36
+ * @param command
37
+ * @returns The entire command that will be ran when calling `run(command)`.
38
+ */
39
+ rawFullCommand(command) {
40
+ const commandArgs = [...this.args, command];
41
+ return `${this.binary} ${commandArgs.join(' ')}`;
42
+ }
43
+ }
44
+ exports.AbstractRunner = AbstractRunner;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchematicRunner = void 0;
4
+ const abstract_runner_1 = require("./abstract.runner");
5
+ class SchematicRunner extends abstract_runner_1.AbstractRunner {
6
+ constructor() {
7
+ super(`node`, [`"${SchematicRunner.findClosestSchematicsBinary()}"`]);
8
+ }
9
+ static getModulePaths() {
10
+ return module.paths;
11
+ }
12
+ static findClosestSchematicsBinary() {
13
+ try {
14
+ return require.resolve('@angular-devkit/schematics-cli/bin/schematics.js', { paths: this.getModulePaths() });
15
+ }
16
+ catch {
17
+ throw new Error("'schematics' binary path could not be found!");
18
+ }
19
+ }
20
+ }
21
+ exports.SchematicRunner = SchematicRunner;
@@ -0,0 +1,34 @@
1
+ {
2
+ "$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json",
3
+ "schematics": {
4
+ "module": {
5
+ "factory": "./lib/module/module.factory#main",
6
+ "description": "Create a mbc-cqrs-serverless module.",
7
+ "schema": "./lib/module/schema.json",
8
+ "aliases": ["mo"]
9
+ },
10
+ "controller": {
11
+ "factory": "./lib/controller/controller.factory#main",
12
+ "description": "Create a mbc-cqrs-serverless controller.",
13
+ "schema": "./lib/controller/schema.json",
14
+ "aliases": ["co"]
15
+ },
16
+ "service": {
17
+ "factory": "./lib/service/service.factory#main",
18
+ "description": "Create a mbc-cqrs-serverless service.",
19
+ "schema": "./lib/service/schema.json",
20
+ "aliases": ["se"]
21
+ },
22
+ "entity": {
23
+ "factory": "./lib/entity/entity.factory#main",
24
+ "description": "Create a mbc-cqrs-serverless entity.",
25
+ "schema": "./lib/entity/schema.json",
26
+ "aliases": ["en"]
27
+ },
28
+ "dto": {
29
+ "factory": "./lib/dto/dto.factory#main",
30
+ "description": "Create a mbc-cqrs-serverless dto.",
31
+ "schema": "./lib/dto/schema.json"
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./schematic.option"), exports);
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.main = main;
4
+ const core_1 = require("@angular-devkit/core");
5
+ const schematics_1 = require("@angular-devkit/schematics");
6
+ function createController(options) {
7
+ return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [
8
+ (0, schematics_1.template)({
9
+ ...core_1.strings,
10
+ ...options,
11
+ }),
12
+ (0, schematics_1.move)((0, core_1.normalize)(`/src/${core_1.strings.dasherize(options.name)}`)),
13
+ ]));
14
+ }
15
+ function createUnitTest(options) {
16
+ return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./units'), [
17
+ (0, schematics_1.template)({
18
+ ...core_1.strings,
19
+ ...options,
20
+ specFileSuffix: 'spec',
21
+ }),
22
+ (0, schematics_1.move)((0, core_1.normalize)(`/test/unit/${core_1.strings.dasherize(options.name)}`)),
23
+ ]));
24
+ }
25
+ function main(options) {
26
+ return (tree, _context) => {
27
+ const filePath = (0, core_1.normalize)(`/src/${core_1.strings.dasherize(options.name)}/${core_1.strings.dasherize(options.name)}.controller.ts`);
28
+ const unitPath = (0, core_1.normalize)(`/test/unit/${core_1.strings.dasherize(options.name)}/${core_1.strings.dasherize(options.name)}.controller.spec.ts`);
29
+ const isFileExists = tree.exists(filePath);
30
+ const isUnitExists = tree.exists(unitPath);
31
+ if (isFileExists || isUnitExists) {
32
+ if (isFileExists)
33
+ _context.logger.info(`Controller file already exists at: ${filePath}`);
34
+ if (isUnitExists)
35
+ _context.logger.info(`Unit test file already exists at: ${unitPath}`);
36
+ return;
37
+ }
38
+ return (0, schematics_1.chain)([createController(options), createUnitTest(options)]);
39
+ };
40
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const testing_1 = require("@angular-devkit/schematics/testing");
37
+ const path = __importStar(require("path"));
38
+ describe('Controller Factory', () => {
39
+ const runner = new testing_1.SchematicTestRunner('.', path.join(__dirname, '../../collection.json'));
40
+ it('should generate correct template', async () => {
41
+ const options = {
42
+ name: 'foo',
43
+ };
44
+ const tree = await runner.runSchematic('controller', options);
45
+ const files = tree.files;
46
+ expect(files.find((filename) => filename === '/src/foo/foo.controller.ts')).toBeDefined();
47
+ expect(files.find((filename) => filename === '/test/unit/foo/foo.controller.spec.ts')).toBeDefined();
48
+ expect(tree.readContent('/src/foo/foo.controller.ts')).toEqual("import { Controller, Logger } from '@nestjs/common';\n" +
49
+ "import { ApiTags } from '@nestjs/swagger'\n" +
50
+ '\n' +
51
+ "@ApiTags('foo')\n" +
52
+ "@Controller('api/foo')\n" +
53
+ 'export class FooController {\n' +
54
+ ' private readonly logger = new Logger(FooController.name)\n' +
55
+ '\n' +
56
+ ' constructor() {}\n' +
57
+ '\n' +
58
+ '}\n');
59
+ expect(tree.readContent('/test/unit/foo/foo.controller.spec.ts')).toEqual("import { createMock } from '@golevelup/ts-jest'\n" +
60
+ "import { Test, TestingModule } from '@nestjs/testing'\n" +
61
+ "import { FooController } from 'src/foo/foo.controller'\n" +
62
+ '\n' +
63
+ "describe('FooController', () => {\n" +
64
+ ' let controller: FooController\n' +
65
+ '\n' +
66
+ ' beforeEach(async () => {\n' +
67
+ ' const module: TestingModule = await Test.createTestingModule({\n' +
68
+ ' controllers: [FooController],\n' +
69
+ ' }).useMocker(createMock).compile()\n' +
70
+ '\n' +
71
+ ' controller = module.get<FooController>(FooController)\n' +
72
+ ' })\n' +
73
+ '\n' +
74
+ " it('should be defined', () => {\n" +
75
+ ' expect(controller).toBeDefined()\n' +
76
+ ' })\n' +
77
+ '})\n');
78
+ });
79
+ });
@@ -0,0 +1,11 @@
1
+ import { Controller, Logger } from '@nestjs/common';
2
+ import { ApiTags } from '@nestjs/swagger'
3
+
4
+ @ApiTags('<%= dasherize(name) %>')
5
+ @Controller('api/<%= dasherize(name) %>')
6
+ export class <%= classify(name) %>Controller {
7
+ private readonly logger = new Logger(<%= classify(name) %>Controller.name)
8
+
9
+ constructor() {}
10
+
11
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "SchematicsMbcController",
4
+ "title": "Nest Controller Options Schema",
5
+ "type": "object",
6
+ "properties": {
7
+ "name": {
8
+ "type": "string",
9
+ "description": "The name of the controller.",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "What name would you like to use for the controller?"
15
+ }
16
+ },
17
+ "required": ["name"]
18
+ }
@@ -0,0 +1,19 @@
1
+ import { createMock } from '@golevelup/ts-jest'
2
+ import { Test, TestingModule } from '@nestjs/testing'
3
+ import { <%= classify(name) %>Controller } from 'src/<%= dasherize(name) %>/<%= dasherize(name) %>.controller'
4
+
5
+ describe('<%= classify(name) %>Controller', () => {
6
+ let controller: <%= classify(name) %>Controller
7
+
8
+ beforeEach(async () => {
9
+ const module: TestingModule = await Test.createTestingModule({
10
+ controllers: [<%= classify(name) %>Controller],
11
+ }).useMocker(createMock).compile()
12
+
13
+ controller = module.get<<%= classify(name) %>Controller>(<%= classify(name) %>Controller)
14
+ })
15
+
16
+ it('should be defined', () => {
17
+ expect(controller).toBeDefined()
18
+ })
19
+ })
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.main = main;
4
+ const core_1 = require("@angular-devkit/core");
5
+ const schematics_1 = require("@angular-devkit/schematics");
6
+ const utils_1 = require("../../utils");
7
+ function createEntity(options) {
8
+ return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [
9
+ (0, schematics_1.template)({
10
+ ...core_1.strings,
11
+ ...options,
12
+ }),
13
+ (0, schematics_1.move)((0, core_1.normalize)(`/src/${core_1.strings.dasherize(options.name)}`)),
14
+ ]));
15
+ }
16
+ function main(options) {
17
+ return (tree, _context) => {
18
+ const basePath = `/src/${core_1.strings.dasherize(options.name)}/dto`;
19
+ const filePaths = [
20
+ `${basePath}/${core_1.strings.dasherize(options.name)}-attributes.dto.ts`,
21
+ `${basePath}/${core_1.strings.dasherize(options.name)}-command.dto.ts`,
22
+ `${basePath}/${core_1.strings.dasherize(options.name)}-create.dto.ts`,
23
+ `${basePath}/${core_1.strings.dasherize(options.name)}-search.dto.ts`,
24
+ `${basePath}/${core_1.strings.dasherize(options.name)}-update.dto.ts`,
25
+ ];
26
+ if ((0, utils_1.checkFilesExist)(tree, filePaths)) {
27
+ _context.logger.info('One or more files already exist.');
28
+ return;
29
+ }
30
+ return (0, schematics_1.chain)([createEntity(options)]);
31
+ };
32
+ }
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const testing_1 = require("@angular-devkit/schematics/testing");
37
+ const path = __importStar(require("path"));
38
+ describe('Dto Factory', () => {
39
+ const runner = new testing_1.SchematicTestRunner('.', path.join(__dirname, '../../collection.json'));
40
+ it('should generate correct template', async () => {
41
+ const options = {
42
+ name: 'foo',
43
+ };
44
+ const tree = await runner.runSchematic('dto', options);
45
+ const files = tree.files;
46
+ expect(files.find((filename) => filename === '/src/foo/dto/foo-attributes.dto.ts')).toBeDefined();
47
+ expect(files.find((filename) => filename === '/src/foo/dto/foo-command.dto.ts')).toBeDefined();
48
+ expect(files.find((filename) => filename === '/src/foo/dto/foo-create.dto.ts')).toBeDefined();
49
+ expect(files.find((filename) => filename === '/src/foo/dto/foo-search.dto.ts')).toBeDefined();
50
+ expect(files.find((filename) => filename === '/src/foo/dto/foo-update.dto.ts')).toBeDefined();
51
+ expect(tree.readContent('/src/foo/dto/foo-attributes.dto.ts')).toEqual("import { IsObject } from 'class-validator'\n" +
52
+ '\n' +
53
+ 'export class FooAttributes {\n' +
54
+ ' @IsObject()\n' +
55
+ ' value: object\n' +
56
+ '}\n');
57
+ expect(tree.readContent('/src/foo/dto/foo-command.dto.ts')).toEqual("import { CommandDto } from '@mbc-cqrs-serverless/core'\n" +
58
+ "import { Type } from 'class-transformer'\n" +
59
+ "import { ValidateNested } from 'class-validator'\n" +
60
+ '\n' +
61
+ "import { FooAttributes } from './foo-attributes.dto'\n" +
62
+ '\n' +
63
+ 'export class FooCommandDto extends CommandDto {\n' +
64
+ ' @Type(() => FooAttributes)\n' +
65
+ ' @ValidateNested()\n' +
66
+ ' attributes: FooAttributes\n' +
67
+ '\n' +
68
+ ' constructor(partial: Partial<FooCommandDto>) {\n' +
69
+ ' super()\n' +
70
+ ' Object.assign(this, partial)\n' +
71
+ ' }\n' +
72
+ '}\n');
73
+ expect(tree.readContent('/src/foo/dto/foo-create.dto.ts')).toEqual("import { Type } from 'class-transformer'\n" +
74
+ "import { IsOptional, IsString, ValidateNested } from 'class-validator'\n" +
75
+ '\n' +
76
+ "import { FooAttributes } from './foo-attributes.dto'\n" +
77
+ '\n' +
78
+ 'export class FooCreateDto {\n' +
79
+ ' @IsString()\n' +
80
+ ' name: string\n' +
81
+ '\n' +
82
+ ' @Type(() => FooAttributes)\n' +
83
+ ' @ValidateNested()\n' +
84
+ ' @IsOptional()\n' +
85
+ ' attributes?: FooAttributes\n' +
86
+ '\n' +
87
+ ' constructor(partial: Partial<FooCreateDto>) {\n' +
88
+ ' Object.assign(this, partial)\n' +
89
+ ' }\n' +
90
+ '}\n');
91
+ expect(tree.readContent('/src/foo/dto/foo-search.dto.ts')).toEqual("import { SearchDto } from '@mbc-cqrs-serverless/core'\n" +
92
+ 'export class FooSearchDto extends SearchDto {}\n');
93
+ expect(tree.readContent('/src/foo/dto/foo-update.dto.ts')).toEqual("import { PartialType } from '@nestjs/swagger'\n" +
94
+ "import { Transform, Type } from 'class-transformer'\n" +
95
+ 'import {\n' +
96
+ ' IsBoolean,\n' +
97
+ ' IsOptional,\n' +
98
+ ' IsString,\n' +
99
+ ' ValidateNested,\n' +
100
+ "} from 'class-validator'\n" +
101
+ '\n' +
102
+ "import { FooAttributes } from './foo-attributes.dto'\n" +
103
+ '\n' +
104
+ 'export class FooUpdateAttributes extends PartialType(FooAttributes) {}\n' +
105
+ '\n' +
106
+ 'export class FooUpdateDto {\n' +
107
+ ' @IsString()\n' +
108
+ ' @IsOptional()\n' +
109
+ ' name?: string\n' +
110
+ '\n' +
111
+ ' @IsBoolean()\n' +
112
+ ' @Transform(({ value }) =>\n' +
113
+ " value === 'true' ? true : value === 'false' ? false : value,\n" +
114
+ ' )\n' +
115
+ ' @IsOptional()\n' +
116
+ ' isDeleted?: boolean\n' +
117
+ '\n' +
118
+ ' @Type(() => FooUpdateAttributes)\n' +
119
+ ' @ValidateNested()\n' +
120
+ ' @IsOptional()\n' +
121
+ ' attributes?: FooUpdateAttributes\n' +
122
+ '\n' +
123
+ ' constructor(partial: Partial<FooUpdateDto>) {\n' +
124
+ ' Object.assign(this, partial)\n' +
125
+ ' }\n' +
126
+ '}\n');
127
+ });
128
+ });
@@ -0,0 +1,6 @@
1
+ import { IsObject } from 'class-validator'
2
+
3
+ export class <%= classify(name) %>Attributes {
4
+ @IsObject()
5
+ value: object
6
+ }
@@ -0,0 +1,16 @@
1
+ import { CommandDto } from '@mbc-cqrs-serverless/core'
2
+ import { Type } from 'class-transformer'
3
+ import { ValidateNested } from 'class-validator'
4
+
5
+ import { <%= classify(name) %>Attributes } from './<%= dasherize(name) %>-attributes.dto'
6
+
7
+ export class <%= classify(name) %>CommandDto extends CommandDto {
8
+ @Type(() => <%= classify(name) %>Attributes)
9
+ @ValidateNested()
10
+ attributes: <%= classify(name) %>Attributes
11
+
12
+ constructor(partial: Partial<<%= classify(name) %>CommandDto>) {
13
+ super()
14
+ Object.assign(this, partial)
15
+ }
16
+ }
@@ -0,0 +1,18 @@
1
+ import { Type } from 'class-transformer'
2
+ import { IsOptional, IsString, ValidateNested } from 'class-validator'
3
+
4
+ import { <%= classify(name) %>Attributes } from './<%= dasherize(name) %>-attributes.dto'
5
+
6
+ export class <%= classify(name) %>CreateDto {
7
+ @IsString()
8
+ name: string
9
+
10
+ @Type(() => <%= classify(name) %>Attributes)
11
+ @ValidateNested()
12
+ @IsOptional()
13
+ attributes?: <%= classify(name) %>Attributes
14
+
15
+ constructor(partial: Partial<<%= classify(name) %>CreateDto>) {
16
+ Object.assign(this, partial)
17
+ }
18
+ }
@@ -0,0 +1,2 @@
1
+ import { SearchDto } from '@mbc-cqrs-serverless/core'
2
+ export class <%= classify(name) %>SearchDto extends SearchDto {}
@@ -0,0 +1,34 @@
1
+ import { PartialType } from '@nestjs/swagger'
2
+ import { Transform, Type } from 'class-transformer'
3
+ import {
4
+ IsBoolean,
5
+ IsOptional,
6
+ IsString,
7
+ ValidateNested,
8
+ } from 'class-validator'
9
+
10
+ import { <%= classify(name) %>Attributes } from './<%= dasherize(name) %>-attributes.dto'
11
+
12
+ export class <%= classify(name) %>UpdateAttributes extends PartialType(<%= classify(name) %>Attributes) {}
13
+
14
+ export class <%= classify(name) %>UpdateDto {
15
+ @IsString()
16
+ @IsOptional()
17
+ name?: string
18
+
19
+ @IsBoolean()
20
+ @Transform(({ value }) =>
21
+ value === 'true' ? true : value === 'false' ? false : value,
22
+ )
23
+ @IsOptional()
24
+ isDeleted?: boolean
25
+
26
+ @Type(() => <%= classify(name) %>UpdateAttributes)
27
+ @ValidateNested()
28
+ @IsOptional()
29
+ attributes?: <%= classify(name) %>UpdateAttributes
30
+
31
+ constructor(partial: Partial<<%= classify(name) %>UpdateDto>) {
32
+ Object.assign(this, partial)
33
+ }
34
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "SchematicsMbcEntity",
4
+ "title": "Mbc-cqrs-serverless Entity Options Schema",
5
+ "type": "object",
6
+ "properties": {
7
+ "name": {
8
+ "type": "string",
9
+ "description": "The name of the entity.",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "What name would you like to use for the entity?"
15
+ }
16
+ },
17
+ "required": ["name"]
18
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.main = main;
4
+ const core_1 = require("@angular-devkit/core");
5
+ const schematics_1 = require("@angular-devkit/schematics");
6
+ const utils_1 = require("../../utils");
7
+ function createEntity(options) {
8
+ return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [
9
+ (0, schematics_1.template)({
10
+ ...core_1.strings,
11
+ ...options,
12
+ }),
13
+ (0, schematics_1.move)((0, core_1.normalize)(`/src/${core_1.strings.dasherize(options.name)}`)),
14
+ ]));
15
+ }
16
+ function main(options) {
17
+ return (tree, _context) => {
18
+ const basePath = `/src/${core_1.strings.dasherize(options.name)}/entity`;
19
+ const filePaths = [
20
+ `${basePath}/${core_1.strings.dasherize(options.name)}-command.entity.ts`,
21
+ `${basePath}/${core_1.strings.dasherize(options.name)}-data-list.entity.ts`,
22
+ `${basePath}/${core_1.strings.dasherize(options.name)}-data.entity.ts`,
23
+ ];
24
+ if ((0, utils_1.checkFilesExist)(tree, filePaths)) {
25
+ _context.logger.info('One or more files already exist.');
26
+ return;
27
+ }
28
+ return (0, schematics_1.chain)([createEntity(options)]);
29
+ };
30
+ }