@kominal/common-nestjs 0.0.23 → 0.0.25

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.
@@ -1 +1,2 @@
1
- export declare function bootstrap(module: any): Promise<void>;
1
+ export declare function findControllers(module: any): any[];
2
+ export declare function bootstrap(module: any, bodyParser?: boolean): Promise<void>;
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findControllers = findControllers;
3
4
  exports.bootstrap = bootstrap;
4
5
  const common_1 = require("@nestjs/common");
5
6
  const core_1 = require("@nestjs/core");
6
7
  const swagger_1 = require("@nestjs/swagger");
8
+ const testing_1 = require("@nestjs/testing");
7
9
  const fs_1 = require("fs");
8
10
  const process_1 = require("process");
9
11
  const exception_filter_1 = require("../helpers/exception-filter");
@@ -11,27 +13,39 @@ const logger_1 = require("../helpers/logger");
11
13
  process.on('uncaughtException', (exception) => {
12
14
  console.log(exception);
13
15
  });
14
- async function bootstrap(module) {
15
- const app = await core_1.NestFactory.create(module, {
16
- logger: new logger_1.CommonLogger(),
17
- cors: { origin: '*' },
18
- bodyParser: false,
19
- });
20
- app.useGlobalPipes(new common_1.ValidationPipe());
21
- app.useGlobalFilters(new exception_filter_1.CommonExceptionFilter());
22
- app.enableCors();
16
+ function getOpenAPIObject(app) {
23
17
  const config = new swagger_1.DocumentBuilder()
24
18
  .setTitle('Core')
25
19
  .addServer('/api/core', 'Current installation')
26
20
  .addBearerAuth()
27
21
  .build();
28
- const document = swagger_1.SwaggerModule.createDocument(app, config);
29
- swagger_1.SwaggerModule.setup('api', app, document);
22
+ return swagger_1.SwaggerModule.createDocument(app, config);
23
+ }
24
+ function findControllers(module) {
25
+ const reflector = new core_1.Reflector();
26
+ const controllers = reflector.get('controllers', module) || [];
27
+ const imports = reflector.get('imports', module) || [];
28
+ return [...imports.reduce((acc, mod) => [...acc, ...findControllers(mod)], []), ...controllers];
29
+ }
30
+ async function bootstrap(module, bodyParser = true) {
30
31
  if (process.env.GENERATE_SWAGGER) {
31
- (0, fs_1.writeFileSync)('swagger.json', JSON.stringify(document));
32
+ const moduleRef = await testing_1.Test.createTestingModule({ controllers: findControllers(module) })
33
+ .useMocker(() => ({}))
34
+ .compile();
35
+ const app = moduleRef.createNestApplication();
36
+ (0, fs_1.writeFileSync)('swagger.json', JSON.stringify(getOpenAPIObject(app), null, 2));
32
37
  (0, process_1.exit)(0);
33
38
  }
34
39
  else {
40
+ const app = await core_1.NestFactory.create(module, {
41
+ logger: new logger_1.CommonLogger(),
42
+ cors: { origin: '*' },
43
+ bodyParser,
44
+ });
45
+ app.useGlobalPipes(new common_1.ValidationPipe());
46
+ app.useGlobalFilters(new exception_filter_1.CommonExceptionFilter());
47
+ app.enableCors();
48
+ swagger_1.SwaggerModule.setup('api', app, getOpenAPIObject(app));
35
49
  await app.listen(3000);
36
50
  }
37
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/executables/bootstrap.ts"],"names":[],"mappings":";;AAYA,8BAyBC;AArCD,2CAAgD;AAChD,uCAA2C;AAC3C,6CAAiE;AACjE,2BAAmC;AACnC,qCAA+B;AAC/B,kEAAoE;AACpE,8CAAiD;AAEjD,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,SAAS,EAAE,EAAE;IAC5C,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AACzB,CAAC,CAAC,CAAC;AAEI,KAAK,UAAU,SAAS,CAAC,MAAW;IACzC,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,MAAM,EAAE;QAC3C,MAAM,EAAE,IAAI,qBAAY,EAAE;QAC1B,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE;QACrB,UAAU,EAAE,KAAK;KAClB,CAAC,CAAC;IACH,GAAG,CAAC,cAAc,CAAC,IAAI,uBAAc,EAAE,CAAC,CAAC;IACzC,GAAG,CA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AAI,qBAAY,EAAE;YAC1B,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE;YACrB,UAAU;SACX,CAAC,CAAC;QACH,GAAG,CAAC,cAAc,CAAC,IAAI,uBAAc,EAAE,CAAC,CAAC;QACzC,GAAG,CAAC,gBAAgB,CAAC,IAAI,wCAAqB,EAAE,CAAC,CAAC;QAClD,GAAG,CAAC,UAAU,EAAE,CAAC;QACjB,uBAAa,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC;QACvD,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kominal/common-nestjs",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -19,6 +19,7 @@
19
19
  "@nestjs/common": "^11.0.20",
20
20
  "@nestjs/mongoose": "^11.0.3",
21
21
  "@nestjs/swagger": "^11.1.4",
22
+ "@nestjs/testing": "^11.1.1",
22
23
  "body-parser": "^2.2.0",
23
24
  "class-transformer": "^0.5.1",
24
25
  "class-validator": "^0.14.1",