@open-rlb/nestjs-amqp 1.0.13 → 1.0.15

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 (81) hide show
  1. package/modules/broker/index.d.ts +2 -0
  2. package/modules/broker/index.js +2 -0
  3. package/modules/broker/index.js.map +1 -1
  4. package/modules/broker/services/broker.service.js +1 -1
  5. package/modules/broker/services/broker.service.js.map +1 -1
  6. package/package.json +14 -5
  7. package/schematics/collection.json +10 -0
  8. package/schematics/defaults.d.ts +14 -0
  9. package/schematics/defaults.js +18 -0
  10. package/schematics/defaults.js.map +1 -0
  11. package/schematics/defaults.ts +14 -0
  12. package/schematics/nest-add/index.d.ts +3 -0
  13. package/schematics/nest-add/index.js +315 -0
  14. package/schematics/nest-add/index.js.map +1 -0
  15. package/schematics/nest-add/index.ts +440 -0
  16. package/schematics/nest-add/init.schema.d.ts +15 -0
  17. package/schematics/nest-add/init.schema.js +3 -0
  18. package/schematics/nest-add/init.schema.js.map +1 -0
  19. package/schematics/nest-add/init.schema.ts +52 -0
  20. package/schematics/nest-add/schema.d.ts +5 -0
  21. package/schematics/nest-add/schema.js +3 -0
  22. package/schematics/nest-add/schema.js.map +1 -0
  23. package/schematics/nest-add/schema.json +20 -0
  24. package/schematics/nest-add/schema.ts +9 -0
  25. package/schematics/utils/dependencies.utils.d.ts +15 -0
  26. package/schematics/utils/dependencies.utils.js +43 -0
  27. package/schematics/utils/dependencies.utils.js.map +1 -0
  28. package/schematics/utils/dependencies.utils.ts +61 -0
  29. package/schematics/utils/formatting.d.ts +2 -0
  30. package/schematics/utils/formatting.js +23 -0
  31. package/schematics/utils/formatting.js.map +1 -0
  32. package/schematics/utils/formatting.spec.ts +45 -0
  33. package/schematics/utils/formatting.ts +31 -0
  34. package/schematics/utils/index.d.ts +9 -0
  35. package/schematics/utils/index.js +26 -0
  36. package/schematics/utils/index.js.map +1 -0
  37. package/schematics/utils/index.ts +9 -0
  38. package/schematics/utils/json-file.util.d.ts +15 -0
  39. package/schematics/utils/json-file.util.js +69 -0
  40. package/schematics/utils/json-file.util.js.map +1 -0
  41. package/schematics/utils/json-file.util.ts +100 -0
  42. package/schematics/utils/metadata.manager.d.ts +13 -0
  43. package/schematics/utils/metadata.manager.js +175 -0
  44. package/schematics/utils/metadata.manager.js.map +1 -0
  45. package/schematics/utils/metadata.manager.spec.ts +357 -0
  46. package/schematics/utils/metadata.manager.ts +241 -0
  47. package/schematics/utils/module-import.declarator.d.ts +10 -0
  48. package/schematics/utils/module-import.declarator.js +40 -0
  49. package/schematics/utils/module-import.declarator.js.map +1 -0
  50. package/schematics/utils/module-import.declarator.spec.ts +122 -0
  51. package/schematics/utils/module-import.declarator.ts +44 -0
  52. package/schematics/utils/module-metadata.declarator.d.ts +4 -0
  53. package/schematics/utils/module-metadata.declarator.js +13 -0
  54. package/schematics/utils/module-metadata.declarator.js.map +1 -0
  55. package/schematics/utils/module-metadata.declarator.spec.ts +404 -0
  56. package/schematics/utils/module-metadata.declarator.ts +14 -0
  57. package/schematics/utils/module.declarator.d.ts +23 -0
  58. package/schematics/utils/module.declarator.js +33 -0
  59. package/schematics/utils/module.declarator.js.map +1 -0
  60. package/schematics/utils/module.declarator.spec.ts +52 -0
  61. package/schematics/utils/module.declarator.ts +44 -0
  62. package/schematics/utils/module.finder.d.ts +13 -0
  63. package/schematics/utils/module.finder.js +25 -0
  64. package/schematics/utils/module.finder.js.map +1 -0
  65. package/schematics/utils/module.finder.spec.ts +59 -0
  66. package/schematics/utils/module.finder.ts +32 -0
  67. package/schematics/utils/name.parser.d.ts +12 -0
  68. package/schematics/utils/name.parser.js +18 -0
  69. package/schematics/utils/name.parser.js.map +1 -0
  70. package/schematics/utils/name.parser.spec.ts +50 -0
  71. package/schematics/utils/name.parser.ts +26 -0
  72. package/schematics/utils/path.solver.d.ts +4 -0
  73. package/schematics/utils/path.solver.js +15 -0
  74. package/schematics/utils/path.solver.js.map +1 -0
  75. package/schematics/utils/path.solver.spec.ts +11 -0
  76. package/schematics/utils/path.solver.ts +15 -0
  77. package/schematics/utils/source-root.helpers.d.ts +6 -0
  78. package/schematics/utils/source-root.helpers.js +25 -0
  79. package/schematics/utils/source-root.helpers.js.map +1 -0
  80. package/schematics/utils/source-root.helpers.ts +30 -0
  81. package/tsconfig.build.tsbuildinfo +1 -1
@@ -0,0 +1,122 @@
1
+ import { normalize } from '@angular-devkit/core';
2
+ import { ModuleImportDeclarator } from './module-import.declarator';
3
+ import { DeclarationOptions } from './module.declarator';
4
+
5
+ describe('Module Import Declarator', () => {
6
+ it('should add import to the buffered module content', () => {
7
+ const content: string =
8
+ "import { Module } from '@nestjs/common';\n" +
9
+ '\n' +
10
+ '@Module({})\n' +
11
+ 'export class FooModule {}\n';
12
+ const options: DeclarationOptions = {
13
+ metadata: 'imports',
14
+ type: 'module',
15
+ name: 'bar',
16
+ path: normalize('/src/foo/bar'),
17
+ module: normalize('/src/foo/foo.module.ts'),
18
+ symbol: 'BarModule',
19
+ };
20
+ const declarator = new ModuleImportDeclarator();
21
+ expect(declarator.declare(content, options)).toEqual(
22
+ "import { Module } from '@nestjs/common';\n" +
23
+ "import { BarModule } from './bar/bar.module';\n" +
24
+ '\n' +
25
+ '@Module({})\n' +
26
+ 'export class FooModule {}\n',
27
+ );
28
+ });
29
+
30
+ it('should manage no type', () => {
31
+ const content: string =
32
+ "import { Module } from '@nestjs/common';\n" +
33
+ '\n' +
34
+ '@Module({})\n' +
35
+ 'export class FooModule {}\n';
36
+ const options: DeclarationOptions = {
37
+ metadata: 'providers',
38
+ name: 'foo',
39
+ path: normalize('/src/foo'),
40
+ module: normalize('/src/foo/foo.ts'),
41
+ symbol: 'Foo',
42
+ };
43
+ const declarator = new ModuleImportDeclarator();
44
+ expect(declarator.declare(content, options)).toEqual(
45
+ "import { Module } from '@nestjs/common';\n" +
46
+ "import { Foo } from './foo';\n" +
47
+ '\n' +
48
+ '@Module({})\n' +
49
+ 'export class FooModule {}\n',
50
+ );
51
+ });
52
+
53
+ it('should not break existing multi-line imports', () => {
54
+ const content: string =
55
+ 'import {\n' +
56
+ ' Module,\n' +
57
+ ' Helper,\n' +
58
+ "} from '@nestjs/common';\n" +
59
+ '\n' +
60
+ '@Helper()\n' +
61
+ '@Module({})\n' +
62
+ 'export class FooModule {}\n';
63
+
64
+ const options: DeclarationOptions = {
65
+ metadata: 'imports',
66
+ type: 'module',
67
+ name: 'bar',
68
+ path: normalize('/src/foo/bar'),
69
+ module: normalize('/src/foo/foo.module.ts'),
70
+ symbol: 'BarModule',
71
+ };
72
+ const declarator = new ModuleImportDeclarator();
73
+ expect(declarator.declare(content, options)).toEqual(
74
+ 'import {\n' +
75
+ ' Module,\n' +
76
+ ' Helper,\n' +
77
+ "} from '@nestjs/common';\n" +
78
+ "import { BarModule } from './bar/bar.module';\n" +
79
+ '\n' +
80
+ '@Helper()\n' +
81
+ '@Module({})\n' +
82
+ 'export class FooModule {}\n',
83
+ );
84
+ });
85
+
86
+ it('should not break on match of "from" in another context', () => {
87
+ const content: string =
88
+ 'import {\n' +
89
+ ' Module,\n' +
90
+ ' Helper,\n' +
91
+ "} from '@nestjs/common';\n" +
92
+ '\n' +
93
+ '@Helper()\n' +
94
+ '@Module({})\n' +
95
+ 'const x = " from ";\n' +
96
+ 'console.error(" from ");\n' +
97
+ 'export class FooModule {}\n';
98
+
99
+ const options: DeclarationOptions = {
100
+ metadata: 'imports',
101
+ type: 'module',
102
+ name: 'bar',
103
+ path: normalize('/src/foo/bar'),
104
+ module: normalize('/src/foo/foo.module.ts'),
105
+ symbol: 'BarModule',
106
+ };
107
+ const declarator = new ModuleImportDeclarator();
108
+ expect(declarator.declare(content, options)).toEqual(
109
+ 'import {\n' +
110
+ ' Module,\n' +
111
+ ' Helper,\n' +
112
+ "} from '@nestjs/common';\n" +
113
+ "import { BarModule } from './bar/bar.module';\n" +
114
+ '\n' +
115
+ '@Helper()\n' +
116
+ '@Module({})\n' +
117
+ 'const x = " from ";\n' +
118
+ 'console.error(" from ");\n' +
119
+ 'export class FooModule {}\n',
120
+ );
121
+ });
122
+ });
@@ -0,0 +1,44 @@
1
+ import { normalize, Path } from '@angular-devkit/core';
2
+ import { DeclarationOptions } from './module.declarator';
3
+ import { PathSolver } from './path.solver';
4
+
5
+ export class ModuleImportDeclarator {
6
+ constructor(private solver: PathSolver = new PathSolver()) {}
7
+
8
+ public declare(content: string, options: DeclarationOptions): string {
9
+ const toInsert = this.buildLineToInsert(options);
10
+ const contentLines = content.split('\n');
11
+ const finalImportIndex = this.findImportsEndpoint(contentLines);
12
+ contentLines.splice(finalImportIndex + 1, 0, toInsert);
13
+ return contentLines.join('\n');
14
+ }
15
+
16
+ private findImportsEndpoint(contentLines: string[]): number {
17
+ const reversedContent = Array.from(contentLines).reverse();
18
+ const reverseImports = reversedContent.filter(line =>
19
+ line.match(/\} from ('|")/),
20
+ );
21
+ if (reverseImports.length <= 0) {
22
+ return 0;
23
+ }
24
+ return contentLines.indexOf(reverseImports[0]);
25
+ }
26
+
27
+ private buildLineToInsert(options: DeclarationOptions): string {
28
+ return `import { ${options.symbol} } from '${this.computeRelativePath(
29
+ options,
30
+ )}';`;
31
+ }
32
+
33
+ private computeRelativePath(options: DeclarationOptions): string {
34
+ let importModulePath: Path;
35
+ if (options.type !== undefined) {
36
+ importModulePath = normalize(
37
+ `/${options.path}/${options.name}.${options.type}`,
38
+ );
39
+ } else {
40
+ importModulePath = normalize(`/${options.path}/${options.name}`);
41
+ }
42
+ return this.solver.relative(options.module, importModulePath);
43
+ }
44
+ }
@@ -0,0 +1,4 @@
1
+ import { DeclarationOptions } from './module.declarator';
2
+ export declare class ModuleMetadataDeclarator {
3
+ declare(content: string, options: DeclarationOptions): string;
4
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModuleMetadataDeclarator = void 0;
4
+ const metadata_manager_1 = require("./metadata.manager");
5
+ class ModuleMetadataDeclarator {
6
+ declare(content, options) {
7
+ const manager = new metadata_manager_1.MetadataManager(content);
8
+ const inserted = manager.insert(options.metadata, options.symbol, options.staticOptions);
9
+ return inserted ?? content;
10
+ }
11
+ }
12
+ exports.ModuleMetadataDeclarator = ModuleMetadataDeclarator;
13
+ //# sourceMappingURL=module-metadata.declarator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-metadata.declarator.js","sourceRoot":"","sources":["../../../libs/rlb-nestjs-amqp/src/schematics/utils/module-metadata.declarator.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AAGrD,MAAa,wBAAwB;IAC5B,OAAO,CAAC,OAAe,EAAE,OAA2B;QACzD,MAAM,OAAO,GAAG,IAAI,kCAAe,CAAC,OAAO,CAAC,CAAC;QAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAC7B,OAAO,CAAC,QAAQ,EAChB,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,aAAa,CACtB,CAAC;QACF,OAAO,QAAQ,IAAI,OAAO,CAAC;IAC7B,CAAC;CACF;AAVD,4DAUC"}
@@ -0,0 +1,404 @@
1
+ import { normalize } from '@angular-devkit/core';
2
+ import { ModuleMetadataDeclarator } from './module-metadata.declarator';
3
+ import { DeclarationOptions } from './module.declarator';
4
+
5
+ describe('Module Metadata Declarator', () => {
6
+ let declarator: ModuleMetadataDeclarator;
7
+ beforeAll(() => (declarator = new ModuleMetadataDeclarator()));
8
+ it('should manage empty metadata', () => {
9
+ const content: string =
10
+ "import { Module } from '@nestjs/common';\n" +
11
+ '\n' +
12
+ '@Module({})\n' +
13
+ 'export class FooModule {}\n';
14
+ const options: DeclarationOptions = {
15
+ metadata: 'imports',
16
+ type: 'module',
17
+ name: 'bar',
18
+ path: normalize('/src/foo'),
19
+ module: normalize('/src/foo/foo.module.ts'),
20
+ symbol: 'BarModule',
21
+ };
22
+ expect(declarator.declare(content, options)).toEqual(
23
+ "import { Module } from '@nestjs/common';\n" +
24
+ '\n' +
25
+ '@Module({\n' +
26
+ ' imports: [BarModule]\n' +
27
+ '})\n' +
28
+ 'export class FooModule {}\n',
29
+ );
30
+ });
31
+ it('should manage empty metadata with dynamic expressions', () => {
32
+ const content: string =
33
+ "import { Module } from '@nestjs/common';\n" +
34
+ '\n' +
35
+ '@Module({})\n' +
36
+ 'export class FooModule {}\n';
37
+ const options: DeclarationOptions = {
38
+ metadata: 'imports',
39
+ type: 'module',
40
+ name: 'bar',
41
+ path: normalize('/src/foo'),
42
+ module: normalize('/src/foo/foo.module.ts'),
43
+ symbol: 'BarModule',
44
+ staticOptions: {
45
+ name: 'forRoot',
46
+ value: {
47
+ test: true,
48
+ prop: 1,
49
+ },
50
+ },
51
+ };
52
+ expect(declarator.declare(content, options)).toEqual(
53
+ "import { Module } from '@nestjs/common';\n" +
54
+ '\n' +
55
+ '@Module({\n' +
56
+ ' imports: [\n' +
57
+ ' BarModule.forRoot({\n' +
58
+ ' test: true,\n' +
59
+ ' prop: 1\n' +
60
+ ' })\n' +
61
+ ' ]\n' +
62
+ '})\n' +
63
+ 'export class FooModule {}\n',
64
+ );
65
+ });
66
+
67
+ it('should manage empty metadata array with dynamic expressions', () => {
68
+ const content: string =
69
+ "import { Module } from '@nestjs/common';\n" +
70
+ '\n' +
71
+ '@Module({\n' +
72
+ ' imports: []\n' +
73
+ '})\n' +
74
+ 'export class FooModule {}\n';
75
+ const options: DeclarationOptions = {
76
+ metadata: 'imports',
77
+ type: 'module',
78
+ name: 'bar',
79
+ path: normalize('/src/foo'),
80
+ module: normalize('/src/foo/foo.module.ts'),
81
+ symbol: 'BarModule',
82
+ staticOptions: {
83
+ name: 'forRoot',
84
+ value: {
85
+ test: 'true',
86
+ prop: 1,
87
+ },
88
+ },
89
+ };
90
+ expect(declarator.declare(content, options)).toEqual(
91
+ "import { Module } from '@nestjs/common';\n" +
92
+ '\n' +
93
+ '@Module({\n' +
94
+ ' imports: [\n' +
95
+ ' BarModule.forRoot({\n' +
96
+ " test: 'true',\n" +
97
+ ' prop: 1\n' +
98
+ ' })\n' +
99
+ ' ]\n' +
100
+ '})\n' +
101
+ 'export class FooModule {}\n',
102
+ );
103
+ });
104
+
105
+ it('should manage no metadata with dynamic expressions', () => {
106
+ const content: string =
107
+ "import { Module } from '@nestjs/common';\n" +
108
+ '\n' +
109
+ '@Module({\n' +
110
+ ' providers: []\n' +
111
+ '})\n' +
112
+ 'export class FooModule {}\n';
113
+ const options: DeclarationOptions = {
114
+ metadata: 'imports',
115
+ type: 'module',
116
+ name: 'bar',
117
+ path: normalize('/src/foo'),
118
+ module: normalize('/src/foo/foo.module.ts'),
119
+ symbol: 'BarModule',
120
+ staticOptions: {
121
+ name: 'forRoot',
122
+ value: {
123
+ test: true,
124
+ prop: 1,
125
+ },
126
+ },
127
+ };
128
+ expect(declarator.declare(content, options)).toEqual(
129
+ "import { Module } from '@nestjs/common';\n" +
130
+ '\n' +
131
+ '@Module({\n' +
132
+ ' providers: [],\n' +
133
+ ' imports: [\n' +
134
+ ' BarModule.forRoot({\n' +
135
+ ' test: true,\n' +
136
+ ' prop: 1\n' +
137
+ ' })\n' +
138
+ ' ]\n' +
139
+ '})\n' +
140
+ 'export class FooModule {}\n',
141
+ );
142
+ });
143
+
144
+ it('should manage existing metadata', () => {
145
+ const content =
146
+ "import { Module } from '@nestjs/common';\n" +
147
+ "import { BazModule } from './baz/baz.module';\n" +
148
+ '\n' +
149
+ '@Module({\n' +
150
+ ' imports: [\n' +
151
+ ' BazModule\n' +
152
+ ' ]\n' +
153
+ '})\n' +
154
+ 'export class FooModule {}\n';
155
+ const options: DeclarationOptions = {
156
+ metadata: 'imports',
157
+ type: 'module',
158
+ name: 'bar',
159
+ path: normalize('/src/foo'),
160
+ module: normalize('/src/foo/foo.module.ts'),
161
+ symbol: 'BarModule',
162
+ };
163
+ expect(declarator.declare(content, options)).toEqual(
164
+ "import { Module } from '@nestjs/common';\n" +
165
+ "import { BazModule } from './baz/baz.module';\n" +
166
+ '\n' +
167
+ '@Module({\n' +
168
+ ' imports: [\n' +
169
+ ' BazModule,\n' +
170
+ ' BarModule\n' +
171
+ ' ]\n' +
172
+ '})\n' +
173
+ 'export class FooModule {}\n',
174
+ );
175
+ });
176
+ it('should manage trailing comma', () => {
177
+ const content =
178
+ "import { Module } from '@nestjs/common';\n" +
179
+ "import { BazModule } from './baz/baz.module';\n" +
180
+ '\n' +
181
+ '@Module({\n' +
182
+ ' imports: [\n' +
183
+ ' BazModule,\n' +
184
+ ' ],\n' +
185
+ '})\n' +
186
+ 'export class FooModule {}\n';
187
+ const options: DeclarationOptions = {
188
+ metadata: 'imports',
189
+ type: 'module',
190
+ name: 'bar',
191
+ path: normalize('/src/foo'),
192
+ module: normalize('/src/foo/foo.module.ts'),
193
+ symbol: 'BarModule',
194
+ };
195
+ expect(declarator.declare(content, options)).toEqual(
196
+ "import { Module } from '@nestjs/common';\n" +
197
+ "import { BazModule } from './baz/baz.module';\n" +
198
+ '\n' +
199
+ '@Module({\n' +
200
+ ' imports: [\n' +
201
+ ' BazModule,\n' +
202
+ ' BarModule,\n' +
203
+ ' ],\n' +
204
+ '})\n' +
205
+ 'export class FooModule {}\n',
206
+ );
207
+ });
208
+
209
+ it('should manage dynamic expression', () => {
210
+ const content =
211
+ "import { Module } from '@nestjs/common';\n" +
212
+ "import { BazModule } from './baz/baz.module';\n" +
213
+ '\n' +
214
+ '@Module({\n' +
215
+ ' imports: [\n' +
216
+ ' BazModule,\n' +
217
+ ' ],\n' +
218
+ '})\n' +
219
+ 'export class FooModule {}\n';
220
+ const options: DeclarationOptions = {
221
+ metadata: 'imports',
222
+ type: 'module',
223
+ name: 'bar',
224
+ path: normalize('/src/foo'),
225
+ module: normalize('/src/foo/foo.module.ts'),
226
+ symbol: 'BarModule',
227
+ staticOptions: {
228
+ name: 'forRoot',
229
+ value: {
230
+ test: true,
231
+ prop: 1,
232
+ },
233
+ },
234
+ };
235
+ expect(declarator.declare(content, options)).toEqual(
236
+ "import { Module } from '@nestjs/common';\n" +
237
+ "import { BazModule } from './baz/baz.module';\n" +
238
+ '\n' +
239
+ '@Module({\n' +
240
+ ' imports: [\n' +
241
+ ' BazModule,\n' +
242
+ ' BarModule.forRoot({\n' +
243
+ ' test: true,\n' +
244
+ ' prop: 1\n' +
245
+ ' }),\n' +
246
+ ' ],\n' +
247
+ '})\n' +
248
+ 'export class FooModule {}\n',
249
+ );
250
+ });
251
+
252
+ it('should manage unformated metadata definition', () => {
253
+ const content =
254
+ "import { HelmetMiddleware } from '@nest-middlewares/helmet';\n" +
255
+ "import { MiddlewaresConsumer, Module, RequestMethod } from '@nestjs/common';\n" +
256
+ "import { ConfigModule } from './common/config/config.module';\n" +
257
+ "import { AuthMiddleware } from './middlewares/auth/auth-middleware';\n" +
258
+ "import { AuthService } from './middlewares/auth/auth.service';\n" +
259
+ "import { JwtStrategy } from './middlewares/auth/passport/jwt.strategy';\n" +
260
+ "import { PlayersModule } from './routes/players/players.module';\n" +
261
+ '\n' +
262
+ '@Module({\n' +
263
+ ' imports: [ConfigModule, PlayersModule,],\n' +
264
+ ' controllers: [],\n' +
265
+ ' components: [AuthService, Jwt3Strategy]\n' +
266
+ '})\n' +
267
+ 'export class AppModule {\n' +
268
+ ' public configure(consumer: MiddlewaresConsumer): void {\n' +
269
+ ' consumer\n' +
270
+ ' .apply(HelmetMiddleware)\n' +
271
+ " .forRoutes({ path: '*', method: RequestMethod.GET })\n" +
272
+ ' .apply(AuthMiddleware)\n' +
273
+ " .forRoutes({ path: '*', method: RequestMethod.GET });\n" +
274
+ ' }\n' +
275
+ '};\n';
276
+ const options: DeclarationOptions = {
277
+ metadata: 'imports',
278
+ type: 'module',
279
+ name: 'bar',
280
+ path: normalize('/src/foo'),
281
+ module: normalize('/src/foo/foo.module.ts'),
282
+ symbol: 'BarModule',
283
+ };
284
+ expect(declarator.declare(content, options)).toEqual(
285
+ "import { HelmetMiddleware } from '@nest-middlewares/helmet';\n" +
286
+ "import { MiddlewaresConsumer, Module, RequestMethod } from '@nestjs/common';\n" +
287
+ "import { ConfigModule } from './common/config/config.module';\n" +
288
+ "import { AuthMiddleware } from './middlewares/auth/auth-middleware';\n" +
289
+ "import { AuthService } from './middlewares/auth/auth.service';\n" +
290
+ "import { JwtStrategy } from './middlewares/auth/passport/jwt.strategy';\n" +
291
+ "import { PlayersModule } from './routes/players/players.module';\n" +
292
+ '\n' +
293
+ '@Module({\n' +
294
+ ' imports: [ConfigModule, PlayersModule, BarModule,],\n' +
295
+ ' controllers: [],\n' +
296
+ ' components: [AuthService, Jwt3Strategy]\n' +
297
+ '})\n' +
298
+ 'export class AppModule {\n' +
299
+ ' public configure(consumer: MiddlewaresConsumer): void {\n' +
300
+ ' consumer\n' +
301
+ ' .apply(HelmetMiddleware)\n' +
302
+ " .forRoutes({ path: '*', method: RequestMethod.GET })\n" +
303
+ ' .apply(AuthMiddleware)\n' +
304
+ " .forRoutes({ path: '*', method: RequestMethod.GET });\n" +
305
+ ' }\n' +
306
+ '};\n',
307
+ );
308
+ });
309
+ it('should manage module with forRoot() or forChild() call', () => {
310
+ const content: string =
311
+ "import { Module } from '@nestjs/common';\n" +
312
+ "import { FooModule } from './foo/foo.module';\n" +
313
+ '\n' +
314
+ '@Module({\n' +
315
+ ' imports: [\n' +
316
+ ' FooModule.forRoot()\n' +
317
+ ' ]\n' +
318
+ '})\n' +
319
+ 'export class FooModule {}\n';
320
+ const options: DeclarationOptions = {
321
+ metadata: 'imports',
322
+ type: 'module',
323
+ name: 'bar',
324
+ path: normalize('/src/foo'),
325
+ module: normalize('/src/foo/foo.module.ts'),
326
+ symbol: 'BarModule',
327
+ };
328
+ expect(declarator.declare(content, options)).toEqual(
329
+ "import { Module } from '@nestjs/common';\n" +
330
+ "import { FooModule } from './foo/foo.module';\n" +
331
+ '\n' +
332
+ '@Module({\n' +
333
+ ' imports: [\n' +
334
+ ' FooModule.forRoot(),\n' +
335
+ ' BarModule\n' +
336
+ ' ]\n' +
337
+ '})\n' +
338
+ 'export class FooModule {}\n',
339
+ );
340
+ });
341
+ it('should manage module with forRoot() or forChild() call with json configration inside', () => {
342
+ const content: string =
343
+ "import { Module } from '@nestjs/common';\n" +
344
+ "import { FooModule } from './foo/foo.module';\n" +
345
+ '\n' +
346
+ '@Module({\n' +
347
+ ' imports: [\n' +
348
+ ' FooModule.forRoot({ key: value })\n' +
349
+ ' ]\n' +
350
+ '})\n' +
351
+ 'export class FooModule {}\n';
352
+ const options: DeclarationOptions = {
353
+ metadata: 'imports',
354
+ type: 'module',
355
+ name: 'bar',
356
+ path: normalize('/src/foo'),
357
+ module: normalize('/src/foo/foo.module.ts'),
358
+ symbol: 'BarModule',
359
+ };
360
+ expect(declarator.declare(content, options)).toEqual(
361
+ "import { Module } from '@nestjs/common';\n" +
362
+ "import { FooModule } from './foo/foo.module';\n" +
363
+ '\n' +
364
+ '@Module({\n' +
365
+ ' imports: [\n' +
366
+ ' FooModule.forRoot({ key: value }),\n' +
367
+ ' BarModule\n' +
368
+ ' ]\n' +
369
+ '})\n' +
370
+ 'export class FooModule {}\n',
371
+ );
372
+ });
373
+ it('should manage comments', () => {
374
+ const content: string =
375
+ "import { Module } from '@nestjs/common';\n" +
376
+ '\n' +
377
+ '@Module({\n' +
378
+ ' imports: [\n' +
379
+ ' // FooModule.forRoot(),\n' +
380
+ ' /* FooModule.forRoot(), */\n' +
381
+ ' ]\n' +
382
+ '})\n' +
383
+ 'export class FooModule {}\n';
384
+ const options: DeclarationOptions = {
385
+ metadata: 'imports',
386
+ type: 'module',
387
+ name: 'bar',
388
+ path: normalize('/src/foo'),
389
+ module: normalize('/src/foo/foo.module.ts'),
390
+ symbol: 'BarModule',
391
+ };
392
+ expect(declarator.declare(content, options)).toEqual(
393
+ "import { Module } from '@nestjs/common';\n" +
394
+ '\n' +
395
+ '@Module({\n' +
396
+ ' imports: [\n' +
397
+ ' // FooModule.forRoot(),\n' +
398
+ ' /* FooModule.forRoot(), */\n' +
399
+ ' BarModule]\n' +
400
+ '})\n' +
401
+ 'export class FooModule {}\n',
402
+ );
403
+ });
404
+ });
@@ -0,0 +1,14 @@
1
+ import { MetadataManager } from './metadata.manager';
2
+ import { DeclarationOptions } from './module.declarator';
3
+
4
+ export class ModuleMetadataDeclarator {
5
+ public declare(content: string, options: DeclarationOptions): string {
6
+ const manager = new MetadataManager(content);
7
+ const inserted = manager.insert(
8
+ options.metadata,
9
+ options.symbol,
10
+ options.staticOptions,
11
+ );
12
+ return inserted ?? content;
13
+ }
14
+ }
@@ -0,0 +1,23 @@
1
+ import { Path } from '@angular-devkit/core';
2
+ import { ModuleImportDeclarator } from './module-import.declarator';
3
+ import { ModuleMetadataDeclarator } from './module-metadata.declarator';
4
+ export interface DeclarationOptions {
5
+ metadata: string;
6
+ type?: string;
7
+ name: string;
8
+ className?: string;
9
+ path: Path;
10
+ module: Path;
11
+ symbol?: string;
12
+ staticOptions?: {
13
+ name: string;
14
+ value: Record<string, any>;
15
+ };
16
+ }
17
+ export declare class ModuleDeclarator {
18
+ private imports;
19
+ private metadata;
20
+ constructor(imports?: ModuleImportDeclarator, metadata?: ModuleMetadataDeclarator);
21
+ declare(content: string, options: DeclarationOptions): string;
22
+ private computeSymbol;
23
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModuleDeclarator = void 0;
4
+ const strings_1 = require("@angular-devkit/core/src/utils/strings");
5
+ const module_import_declarator_1 = require("./module-import.declarator");
6
+ const module_metadata_declarator_1 = require("./module-metadata.declarator");
7
+ class ModuleDeclarator {
8
+ constructor(imports = new module_import_declarator_1.ModuleImportDeclarator(), metadata = new module_metadata_declarator_1.ModuleMetadataDeclarator()) {
9
+ this.imports = imports;
10
+ this.metadata = metadata;
11
+ }
12
+ declare(content, options) {
13
+ options = this.computeSymbol(options);
14
+ content = this.imports.declare(content, options);
15
+ content = this.metadata.declare(content, options);
16
+ return content;
17
+ }
18
+ computeSymbol(options) {
19
+ const target = Object.assign({}, options);
20
+ if (options.className) {
21
+ target.symbol = options.className;
22
+ }
23
+ else if (options.type !== undefined) {
24
+ target.symbol = (0, strings_1.classify)(options.name).concat((0, strings_1.capitalize)(options.type));
25
+ }
26
+ else {
27
+ target.symbol = (0, strings_1.classify)(options.name);
28
+ }
29
+ return target;
30
+ }
31
+ }
32
+ exports.ModuleDeclarator = ModuleDeclarator;
33
+ //# sourceMappingURL=module.declarator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.declarator.js","sourceRoot":"","sources":["../../../libs/rlb-nestjs-amqp/src/schematics/utils/module.declarator.ts"],"names":[],"mappings":";;;AACA,oEAA8E;AAC9E,yEAAoE;AACpE,6EAAwE;AAgBxE,MAAa,gBAAgB;IAC3B,YACU,UAAkC,IAAI,iDAAsB,EAAE,EAC9D,WAAqC,IAAI,qDAAwB,EAAE;QADnE,YAAO,GAAP,OAAO,CAAuD;QAC9D,aAAQ,GAAR,QAAQ,CAA2D;IAC1E,CAAC;IAEG,OAAO,CAAC,OAAe,EAAE,OAA2B;QACzD,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACtC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACjD,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAClD,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,aAAa,CAAC,OAA2B;QAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAC1C,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YACtB,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;QACpC,CAAC;aAAM,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YACtC,MAAM,CAAC,MAAM,GAAG,IAAA,kBAAQ,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAA,oBAAU,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1E,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,MAAM,GAAG,IAAA,kBAAQ,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAxBD,4CAwBC"}