@mbc-cqrs-serverless/cli 0.1.50-beta.0 → 0.1.52-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 (108) hide show
  1. package/dist/actions/generate.action.js +44 -0
  2. package/dist/actions/new.action.get-package-version.spec.js +29 -0
  3. package/dist/actions/new.action.is-latest-version.spec.js +36 -0
  4. package/dist/actions/new.action.js +12 -6
  5. package/dist/actions/new.action.spec.js +84 -0
  6. package/dist/actions/new.action.update-env-local.spec.js +35 -0
  7. package/dist/actions/new.action.use-package-version.spec.js +46 -0
  8. package/dist/actions/ui.action.js +7 -5
  9. package/dist/commands/command.input.js +2 -0
  10. package/dist/commands/generate.command.js +24 -0
  11. package/dist/commands/index.js +2 -0
  12. package/dist/index.js +13 -2
  13. package/dist/runners/abstract.runner.js +44 -0
  14. package/dist/runners/schematic.runner.js +21 -0
  15. package/dist/schematics/collection.json +34 -0
  16. package/dist/schematics/index.js +17 -0
  17. package/dist/schematics/lib/controller/controller.factory.js +40 -0
  18. package/dist/schematics/lib/controller/controller.factory.spec.js +79 -0
  19. package/dist/schematics/lib/controller/files/__name@dasherize__.controller.ts +11 -0
  20. package/dist/schematics/lib/controller/schema.json +18 -0
  21. package/dist/schematics/lib/controller/units/__name@dasherize__.controller.__specFileSuffix__.ts +19 -0
  22. package/dist/schematics/lib/dto/dto.factory.js +32 -0
  23. package/dist/schematics/lib/dto/dto.factory.spec.js +128 -0
  24. package/dist/schematics/lib/dto/files/dto/__name@dasherize__-attributes.dto.ts +6 -0
  25. package/dist/schematics/lib/dto/files/dto/__name@dasherize__-command.dto.ts +16 -0
  26. package/dist/schematics/lib/dto/files/dto/__name@dasherize__-create.dto.ts +18 -0
  27. package/dist/schematics/lib/dto/files/dto/__name@dasherize__-search.dto.ts +2 -0
  28. package/dist/schematics/lib/dto/files/dto/__name@dasherize__-update.dto.ts +34 -0
  29. package/dist/schematics/lib/dto/schema.json +18 -0
  30. package/dist/schematics/lib/entity/entity.factory.js +30 -0
  31. package/dist/schematics/lib/entity/entity.factory.spec.js +86 -0
  32. package/dist/schematics/lib/entity/files/entity/__name@dasherize__-command.entity.ts +12 -0
  33. package/dist/schematics/lib/entity/files/entity/__name@dasherize__-data-list.entity.ts +12 -0
  34. package/dist/schematics/lib/entity/files/entity/__name@dasherize__-data.entity.ts +12 -0
  35. package/dist/schematics/lib/entity/schema.json +18 -0
  36. package/dist/schematics/lib/module/files/async/__name@dasherize__.controller.ts +74 -0
  37. package/dist/schematics/lib/module/files/async/__name@dasherize__.module.ts +19 -0
  38. package/dist/schematics/lib/module/files/async/__name@dasherize__.service.ts +164 -0
  39. package/dist/schematics/lib/module/files/async/dto/__name@dasherize__-attributes.dto.ts +6 -0
  40. package/dist/schematics/lib/module/files/async/dto/__name@dasherize__-command.dto.ts +16 -0
  41. package/dist/schematics/lib/module/files/async/dto/__name@dasherize__-create.dto.ts +18 -0
  42. package/dist/schematics/lib/module/files/async/dto/__name@dasherize__-search.dto.ts +2 -0
  43. package/dist/schematics/lib/module/files/async/dto/__name@dasherize__-update.dto.ts +34 -0
  44. package/dist/schematics/lib/module/files/async/entity/__name@dasherize__-command.entity.ts +12 -0
  45. package/dist/schematics/lib/module/files/async/entity/__name@dasherize__-data-list.entity.ts +12 -0
  46. package/dist/schematics/lib/module/files/async/entity/__name@dasherize__-data.entity.ts +12 -0
  47. package/dist/schematics/lib/module/files/async/handler/__name@dasherize__-rds.handler.ts +62 -0
  48. package/dist/schematics/lib/module/files/sync/__name@dasherize__.controller.ts +74 -0
  49. package/dist/schematics/lib/module/files/sync/__name@dasherize__.module.ts +19 -0
  50. package/dist/schematics/lib/module/files/sync/__name@dasherize__.service.ts +164 -0
  51. package/dist/schematics/lib/module/files/sync/dto/__name@dasherize__-attributes.dto.ts +6 -0
  52. package/dist/schematics/lib/module/files/sync/dto/__name@dasherize__-command.dto.ts +16 -0
  53. package/dist/schematics/lib/module/files/sync/dto/__name@dasherize__-create.dto.ts +18 -0
  54. package/dist/schematics/lib/module/files/sync/dto/__name@dasherize__-search.dto.ts +2 -0
  55. package/dist/schematics/lib/module/files/sync/dto/__name@dasherize__-update.dto.ts +34 -0
  56. package/dist/schematics/lib/module/files/sync/entity/__name@dasherize__-command.entity.ts +12 -0
  57. package/dist/schematics/lib/module/files/sync/entity/__name@dasherize__-data-list.entity.ts +12 -0
  58. package/dist/schematics/lib/module/files/sync/entity/__name@dasherize__-data.entity.ts +12 -0
  59. package/dist/schematics/lib/module/files/sync/handler/__name@dasherize__-rds.handler.ts +62 -0
  60. package/dist/schematics/lib/module/module.factory.js +204 -0
  61. package/dist/schematics/lib/module/module.factory.spec.js +188 -0
  62. package/dist/schematics/lib/module/schema.json +28 -0
  63. package/dist/schematics/lib/module/units/__name@dasherize__.controller.__specFileSuffix__.ts +19 -0
  64. package/dist/schematics/lib/module/units/__name@dasherize__.service.__specFileSuffix__.ts +19 -0
  65. package/dist/schematics/lib/service/files/__name@dasherize__.service.ts +12 -0
  66. package/dist/schematics/lib/service/schema.json +18 -0
  67. package/dist/schematics/lib/service/service.factory.js +40 -0
  68. package/dist/schematics/lib/service/service.factory.spec.js +81 -0
  69. package/dist/schematics/lib/service/units/__name@dasherize__.service.__specFileSuffix__.ts +19 -0
  70. package/dist/schematics/schematic.colection.js +60 -0
  71. package/dist/schematics/schematic.option.js +44 -0
  72. package/dist/schematics/utils/check-files-exist.js +13 -0
  73. package/dist/schematics/utils/index.js +17 -0
  74. package/dist/ui/index.js +18 -0
  75. package/dist/ui/logger.js +54 -0
  76. package/dist/ui/message.js +6 -0
  77. package/dist/utils/formatting.js +18 -0
  78. package/dist/utils/index.js +18 -0
  79. package/dist/utils/local-binaries.js +20 -0
  80. package/package.json +13 -4
  81. package/templates/.env.local +1 -1
  82. package/templates/README.md +1 -1
  83. package/templates/infra/README.md +6 -1
  84. package/templates/infra/libs/infra-stack.ts +1 -1
  85. package/templates/infra-local/docker-compose.yml +1 -1
  86. package/templates/infra-local/serverless.yml +19 -21
  87. package/templates/infra-local/swagger.json +396 -0
  88. package/templates/package.json +1 -0
  89. package/templates/prisma/dynamodbs/cqrs.json +1 -1
  90. package/templates/prisma/schema.prisma +4 -7
  91. package/templates/src/helpers/id.ts +12 -0
  92. package/templates/src/helpers/index.ts +1 -0
  93. package/templates/src/main.module.ts +2 -2
  94. package/templates/src/{master/dto/master-attributes.dto.ts → sample/dto/sample-attributes.dto.ts} +2 -2
  95. package/templates/src/{master/dto/master-command.dto.ts → sample/dto/sample-command.dto.ts} +4 -4
  96. package/templates/src/sample/entity/sample-command.entity.ts +13 -0
  97. package/templates/src/sample/entity/sample-data-list.entity.ts +13 -0
  98. package/templates/src/sample/entity/sample-data.entity.ts +13 -0
  99. package/templates/src/{master/handler/master-rds.handler.ts → sample/handler/sample-rds.handler.ts} +5 -7
  100. package/templates/src/{master/master.controller.ts → sample/sample.controller.ts} +22 -22
  101. package/templates/src/sample/sample.module.ts +19 -0
  102. package/templates/src/{master/master.service.ts → sample/sample.service.ts} +12 -12
  103. package/templates/test/api.http +25 -0
  104. package/templates/tsconfig.json +1 -1
  105. package/templates/src/master/entity/master-command.entity.ts +0 -13
  106. package/templates/src/master/entity/master-data-list.entity.ts +0 -13
  107. package/templates/src/master/entity/master-data.entity.ts +0 -13
  108. package/templates/src/master/master.module.ts +0 -19
@@ -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
+ }
@@ -0,0 +1,86 @@
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('Entity 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('entity', options);
45
+ const files = tree.files;
46
+ expect(files.find((filename) => filename === '/src/foo/entity/foo-command.entity.ts')).toBeDefined();
47
+ expect(files.find((filename) => filename === '/src/foo/entity/foo-data-list.entity.ts')).toBeDefined();
48
+ expect(files.find((filename) => filename === '/src/foo/entity/foo-data.entity.ts')).toBeDefined();
49
+ expect(tree.readContent('/src/foo/entity/foo-command.entity.ts')).toEqual("import { CommandEntity } from '@mbc-cqrs-serverless/core'\n" +
50
+ '\n' +
51
+ "import { FooAttributes } from '../dto/foo-attributes.dto'\n" +
52
+ '\n' +
53
+ 'export class FooCommandEntity extends CommandEntity {\n' +
54
+ ' attributes: FooAttributes\n' +
55
+ '\n' +
56
+ ' constructor(partial: Partial<FooCommandEntity>) {\n' +
57
+ ' super()\n' +
58
+ ' Object.assign(this, partial)\n' +
59
+ ' }\n' +
60
+ '}\n');
61
+ expect(tree.readContent('/src/foo/entity/foo-data-list.entity.ts')).toEqual("import { DataListEntity } from '@mbc-cqrs-serverless/core'\n" +
62
+ '\n' +
63
+ "import { FooDataEntity } from './foo-data.entity'\n" +
64
+ '\n' +
65
+ 'export class FooDataListEntity extends DataListEntity {\n' +
66
+ ' items: FooDataEntity[]\n' +
67
+ '\n' +
68
+ ' constructor(partial: Partial<FooDataListEntity>) {\n' +
69
+ ' super(partial)\n' +
70
+ ' Object.assign(this, partial)\n' +
71
+ ' }\n' +
72
+ '}\n');
73
+ expect(tree.readContent('/src/foo/entity/foo-data.entity.ts')).toEqual("import { DataEntity } from '@mbc-cqrs-serverless/core'\n" +
74
+ '\n' +
75
+ "import { FooAttributes } from '../dto/foo-attributes.dto'\n" +
76
+ '\n' +
77
+ 'export class FooDataEntity extends DataEntity {\n' +
78
+ ' attributes: FooAttributes\n' +
79
+ '\n' +
80
+ ' constructor(partial: Partial<FooDataEntity>) {\n' +
81
+ ' super(partial)\n' +
82
+ ' Object.assign(this, partial)\n' +
83
+ ' }\n' +
84
+ '}\n');
85
+ });
86
+ });
@@ -0,0 +1,12 @@
1
+ import { CommandEntity } from '@mbc-cqrs-serverless/core'
2
+
3
+ import { <%= classify(name) %>Attributes } from '../dto/<%= dasherize(name) %>-attributes.dto'
4
+
5
+ export class <%= classify(name) %>CommandEntity extends CommandEntity {
6
+ attributes: <%= classify(name) %>Attributes
7
+
8
+ constructor(partial: Partial<<%= classify(name) %>CommandEntity>) {
9
+ super()
10
+ Object.assign(this, partial)
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ import { DataListEntity } from '@mbc-cqrs-serverless/core'
2
+
3
+ import { <%= classify(name) %>DataEntity } from './<%= dasherize(name) %>-data.entity'
4
+
5
+ export class <%= classify(name) %>DataListEntity extends DataListEntity {
6
+ items: <%= classify(name) %>DataEntity[]
7
+
8
+ constructor(partial: Partial<<%= classify(name) %>DataListEntity>) {
9
+ super(partial)
10
+ Object.assign(this, partial)
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ import { DataEntity } from '@mbc-cqrs-serverless/core'
2
+
3
+ import { <%= classify(name) %>Attributes } from '../dto/<%= dasherize(name) %>-attributes.dto'
4
+
5
+ export class <%= classify(name) %>DataEntity extends DataEntity {
6
+ attributes: <%= classify(name) %>Attributes
7
+
8
+ constructor(partial: Partial<<%= classify(name) %>DataEntity>) {
9
+ super(partial)
10
+ Object.assign(this, partial)
11
+ }
12
+ }
@@ -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,74 @@
1
+ import {
2
+ DetailDto,
3
+ getUserContext,
4
+ IInvoke,
5
+ INVOKE_CONTEXT,
6
+ SearchDto,
7
+ } from '@mbc-cqrs-serverless/core'
8
+ import {
9
+ Body,
10
+ Controller,
11
+ Delete,
12
+ Get,
13
+ Logger,
14
+ Param,
15
+ Patch,
16
+ Post,
17
+ Query,
18
+ } from '@nestjs/common'
19
+ import { ApiTags } from '@nestjs/swagger'
20
+
21
+ import { <%= classify(name) %>Service } from './<%= dasherize(name) %>.service'
22
+ import { <%= classify(name) %>CreateDto } from './dto/<%= dasherize(name) %>-create.dto'
23
+ import { <%= classify(name) %>UpdateDto } from './dto/<%= dasherize(name) %>-update.dto'
24
+ import { <%= classify(name) %>DataEntity } from './entity/<%= dasherize(name) %>-data.entity'
25
+
26
+ @Controller('api/<%= dasherize(name) %>')
27
+ @ApiTags('<%= dasherize(name) %>')
28
+ export class <%= classify(name) %>Controller {
29
+ private readonly logger = new Logger(<%= classify(name) %>Controller.name)
30
+
31
+ constructor(private readonly <%= camelize(name) %>Service: <%= classify(name) %>Service) {}
32
+
33
+ @Post('/')
34
+ async create(
35
+ @INVOKE_CONTEXT() invokeContext: IInvoke,
36
+ @Body() createDto: <%= classify(name) %>CreateDto,
37
+ ): Promise<<%= classify(name) %>DataEntity> {
38
+ this.logger.debug('createDto:', createDto)
39
+ return this.<%= camelize(name) %>Service.create(createDto, { invokeContext })
40
+ }
41
+
42
+ <% if (schema) { %>@Get('/')
43
+ async findAll(
44
+ @INVOKE_CONTEXT() invokeContext: IInvoke,
45
+ @Query() searchDto: SearchDto,
46
+ ) {
47
+ this.logger.debug('searchDto:', searchDto)
48
+ const { tenantCode } = getUserContext(invokeContext)
49
+ return await this.<%= camelize(name) %>Service.findAll(tenantCode, searchDto)
50
+ }<% } %>
51
+
52
+ @Get('/:pk/:sk')
53
+ async findOne(@Param() detailDto: DetailDto): Promise<<%= classify(name) %>DataEntity> {
54
+ return this.<%= camelize(name) %>Service.findOne(detailDto)
55
+ }
56
+
57
+ @Patch('/:pk/:sk')
58
+ async update(
59
+ @INVOKE_CONTEXT() invokeContext: IInvoke,
60
+ @Param() detailDto: DetailDto,
61
+ @Body() updateDto: <%= classify(name) %>UpdateDto,
62
+ ) {
63
+ this.logger.debug('updateDto:', updateDto)
64
+ return this.<%= camelize(name) %>Service.update(detailDto, updateDto, { invokeContext })
65
+ }
66
+
67
+ @Delete('/:pk/:sk')
68
+ async remove(
69
+ @INVOKE_CONTEXT() invokeContext: IInvoke,
70
+ @Param() detailDto: DetailDto,
71
+ ) {
72
+ return this.<%= camelize(name) %>Service.remove(detailDto, { invokeContext })
73
+ }
74
+ }