mm-share-lib 0.0.4 → 0.0.5

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 (113) hide show
  1. package/.eslintrc.js +25 -25
  2. package/.prettierrc +3 -3
  3. package/README.md +73 -73
  4. package/dist/src/exception/bad-request-error.exception.d.ts +4 -0
  5. package/dist/src/exception/bad-request-error.exception.js +12 -0
  6. package/dist/src/exception/bad-request-error.exception.js.map +1 -0
  7. package/dist/src/exception/base.exception.d.ts +21 -0
  8. package/dist/src/exception/base.exception.js +16 -0
  9. package/dist/src/exception/base.exception.js.map +1 -0
  10. package/dist/src/exception/conflict-error.exception.d.ts +4 -0
  11. package/dist/src/exception/conflict-error.exception.js +12 -0
  12. package/dist/src/exception/conflict-error.exception.js.map +1 -0
  13. package/dist/src/exception/forbidden-error.exception.d.ts +4 -0
  14. package/dist/src/exception/forbidden-error.exception.js +12 -0
  15. package/dist/src/exception/forbidden-error.exception.js.map +1 -0
  16. package/dist/src/exception/index.d.ts +7 -0
  17. package/dist/src/exception/index.js +23 -0
  18. package/dist/src/exception/index.js.map +1 -1
  19. package/dist/src/exception/internal-server-error.exception.d.ts +4 -0
  20. package/dist/src/exception/internal-server-error.exception.js +12 -0
  21. package/dist/src/exception/internal-server-error.exception.js.map +1 -0
  22. package/dist/src/exception/not-found-error.exception.d.ts +4 -0
  23. package/dist/src/exception/not-found-error.exception.js +12 -0
  24. package/dist/src/exception/not-found-error.exception.js.map +1 -0
  25. package/dist/src/exception/unauthorized-error.exception.d.ts +4 -0
  26. package/dist/src/exception/unauthorized-error.exception.js +12 -0
  27. package/dist/src/exception/unauthorized-error.exception.js.map +1 -0
  28. package/dist/src/filter/http-exception.filter.d.ts +4 -0
  29. package/dist/src/filter/http-exception.filter.js +27 -0
  30. package/dist/src/filter/http-exception.filter.js.map +1 -0
  31. package/dist/src/filter/index.d.ts +1 -0
  32. package/dist/src/filter/index.js +18 -0
  33. package/dist/src/filter/index.js.map +1 -0
  34. package/dist/src/index.d.ts +2 -0
  35. package/dist/src/index.js +2 -0
  36. package/dist/src/index.js.map +1 -1
  37. package/dist/src/setup/index.d.ts +1 -0
  38. package/dist/src/setup/index.js +18 -0
  39. package/dist/src/setup/index.js.map +1 -0
  40. package/dist/src/setup/microservice.setup.d.ts +2 -0
  41. package/dist/src/setup/microservice.setup.js +25 -0
  42. package/dist/src/setup/microservice.setup.js.map +1 -0
  43. package/dist/src/setup/swagger.setup.d.ts +0 -0
  44. package/dist/src/setup/swagger.setup.js +1 -0
  45. package/dist/src/setup/swagger.setup.js.map +1 -0
  46. package/dist/src/util/app.utils.d.ts +4 -0
  47. package/dist/src/util/app.utils.js +21 -0
  48. package/dist/src/util/app.utils.js.map +1 -0
  49. package/dist/src/util/index.d.ts +1 -0
  50. package/dist/src/util/index.js +1 -0
  51. package/dist/src/util/index.js.map +1 -1
  52. package/dist/tsconfig.build.tsbuildinfo +1 -1
  53. package/index.ts +1 -1
  54. package/nest-cli.json +8 -8
  55. package/package.json +82 -81
  56. package/src/constant/entity-state.constant.ts +4 -4
  57. package/src/constant/index.ts +1 -1
  58. package/src/dto/base-filter.dto.ts +4 -4
  59. package/src/dto/index.ts +2 -2
  60. package/src/dto/pagination.dto.ts +4 -4
  61. package/src/exception/bad-request-error.exception.spec.ts +24 -0
  62. package/src/exception/bad-request-error.exception.ts +8 -0
  63. package/src/exception/base.exception.ts +36 -0
  64. package/src/exception/conflict-error.exception.spec.ts +23 -0
  65. package/src/exception/conflict-error.exception.ts +8 -0
  66. package/src/exception/forbidden-error.exception.spec.ts +23 -0
  67. package/src/exception/forbidden-error.exception.ts +8 -0
  68. package/src/exception/index.ts +7 -0
  69. package/src/exception/internal-server-error.exception.spec.ts +23 -0
  70. package/src/exception/internal-server-error.exception.ts +12 -0
  71. package/src/exception/not-found-error.exception.spec.ts +23 -0
  72. package/src/exception/not-found-error.exception.ts +8 -0
  73. package/src/exception/unauthorized-error.exception.spec.ts +23 -0
  74. package/src/exception/unauthorized-error.exception.ts +12 -0
  75. package/src/filter/http-exception.filter.ts +23 -0
  76. package/src/filter/index.ts +1 -0
  77. package/src/generic/entity/entity.generic.ts +34 -34
  78. package/src/generic/entity/index.ts +1 -1
  79. package/src/generic/index.ts +2 -2
  80. package/src/generic/service/index.ts +1 -1
  81. package/src/generic/service/service.generic.ts +112 -112
  82. package/src/index.ts +2 -0
  83. package/src/lib/index.ts +1 -1
  84. package/src/lib/search-engine/document/base.document.ts +2 -2
  85. package/src/lib/search-engine/index.ts +1 -1
  86. package/src/lib/search-engine/interface/index.ts +1 -1
  87. package/src/lib/search-engine/interface/search-document.interface.ts +5 -5
  88. package/src/lib/search-engine/interface/transform-service.interface.ts +10 -10
  89. package/src/lib/search-engine/typesense/index.ts +3 -3
  90. package/src/lib/search-engine/typesense/metadata/index.ts +1 -1
  91. package/src/lib/search-engine/typesense/metadata/schema.metadata.ts +13 -13
  92. package/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.ts +28 -28
  93. package/src/lib/search-engine/typesense/service/client.service.ts +258 -258
  94. package/src/lib/search-engine/typesense/typesense-module.interface.ts +36 -36
  95. package/src/lib/search-engine/typesense/typesense.constants.ts +1 -1
  96. package/src/lib/search-engine/typesense/typesense.module.test.ts +94 -94
  97. package/src/lib/search-engine/typesense/typesense.module.ts +76 -76
  98. package/src/lib/search-engine/typesense/typesense.providers.ts +42 -42
  99. package/src/response/index.ts +1 -1
  100. package/src/response/pagination.response.ts +37 -37
  101. package/src/setup/index.ts +1 -0
  102. package/src/setup/microservice.setup.ts +29 -0
  103. package/src/setup/swagger.setup.ts +0 -0
  104. package/src/util/app.utils.ts +18 -0
  105. package/src/util/date.util.spec.ts +49 -49
  106. package/src/util/date.util.ts +10 -10
  107. package/src/util/generator.util.spec.ts +79 -79
  108. package/src/util/generator.util.ts +34 -34
  109. package/src/util/index.ts +3 -2
  110. package/test/app.e2e-spec.ts +24 -24
  111. package/test/jest-e2e.json +9 -9
  112. package/tsconfig.build.json +4 -4
  113. package/tsconfig.json +21 -21
@@ -1,94 +1,94 @@
1
- /* eslint-disable max-classes-per-file */
2
-
3
- import { Module } from '@nestjs/common'
4
- import { Test } from '@nestjs/testing'
5
-
6
- import { TypesenseModuleOptions } from './typesense-module.interface'
7
- import { TYPESENSE_MODULE_OPTIONS } from './typesense.constants'
8
- import { TypesenseModule } from './typesense.module'
9
-
10
- describe('typesense', () => {
11
- describe('module', () => {
12
- let module
13
-
14
- afterEach(async () => {
15
- await module.close()
16
- })
17
-
18
- it(`register`, async () => {
19
- module = await Test.createTestingModule({
20
- imports: [
21
- TypesenseModule.register({
22
- apiKey: 'test',
23
- }),
24
- ],
25
- }).compile()
26
-
27
- expect(module.get(TYPESENSE_MODULE_OPTIONS)).toBeDefined()
28
- })
29
-
30
- it(`register async use factory`, async () => {
31
- module = await Test.createTestingModule({
32
- imports: [
33
- TypesenseModule.registerAsync({
34
- useFactory: () => ({
35
- apiKey: 'test',
36
- }),
37
- }),
38
- ],
39
- }).compile()
40
-
41
- expect(module.get(TYPESENSE_MODULE_OPTIONS)).toBeDefined()
42
- })
43
-
44
- it(`register async use class`, async () => {
45
- class TestTypesenseModuleOptions {
46
- createTypesenseOptions(): TypesenseModuleOptions {
47
- return {
48
- apiKey: 'test',
49
- }
50
- }
51
- }
52
-
53
- module = await Test.createTestingModule({
54
- imports: [
55
- TypesenseModule.registerAsync({
56
- useClass: TestTypesenseModuleOptions,
57
- }),
58
- ],
59
- }).compile()
60
-
61
- expect(module.get(TYPESENSE_MODULE_OPTIONS)).toBeDefined()
62
- })
63
-
64
- it(`register async use exists`, async () => {
65
- class TestTypesenseModuleOptions {
66
- createTypesenseOptions(): TypesenseModuleOptions {
67
- return {
68
- apiKey: 'test',
69
- }
70
- }
71
- }
72
-
73
- @Module({})
74
- class TestTypesenseModule {}
75
-
76
- module = await Test.createTestingModule({
77
- imports: [
78
- TypesenseModule.registerAsync({
79
- imports: [
80
- {
81
- module: TestTypesenseModule,
82
- providers: [TestTypesenseModuleOptions],
83
- exports: [TestTypesenseModuleOptions],
84
- },
85
- ],
86
- useExisting: TestTypesenseModuleOptions,
87
- }),
88
- ],
89
- }).compile()
90
-
91
- expect(module.get(TYPESENSE_MODULE_OPTIONS)).toBeDefined()
92
- })
93
- })
94
- })
1
+ /* eslint-disable max-classes-per-file */
2
+
3
+ import { Module } from '@nestjs/common'
4
+ import { Test } from '@nestjs/testing'
5
+
6
+ import { TypesenseModuleOptions } from './typesense-module.interface'
7
+ import { TYPESENSE_MODULE_OPTIONS } from './typesense.constants'
8
+ import { TypesenseModule } from './typesense.module'
9
+
10
+ describe('typesense', () => {
11
+ describe('module', () => {
12
+ let module
13
+
14
+ afterEach(async () => {
15
+ await module.close()
16
+ })
17
+
18
+ it(`register`, async () => {
19
+ module = await Test.createTestingModule({
20
+ imports: [
21
+ TypesenseModule.register({
22
+ apiKey: 'test',
23
+ }),
24
+ ],
25
+ }).compile()
26
+
27
+ expect(module.get(TYPESENSE_MODULE_OPTIONS)).toBeDefined()
28
+ })
29
+
30
+ it(`register async use factory`, async () => {
31
+ module = await Test.createTestingModule({
32
+ imports: [
33
+ TypesenseModule.registerAsync({
34
+ useFactory: () => ({
35
+ apiKey: 'test',
36
+ }),
37
+ }),
38
+ ],
39
+ }).compile()
40
+
41
+ expect(module.get(TYPESENSE_MODULE_OPTIONS)).toBeDefined()
42
+ })
43
+
44
+ it(`register async use class`, async () => {
45
+ class TestTypesenseModuleOptions {
46
+ createTypesenseOptions(): TypesenseModuleOptions {
47
+ return {
48
+ apiKey: 'test',
49
+ }
50
+ }
51
+ }
52
+
53
+ module = await Test.createTestingModule({
54
+ imports: [
55
+ TypesenseModule.registerAsync({
56
+ useClass: TestTypesenseModuleOptions,
57
+ }),
58
+ ],
59
+ }).compile()
60
+
61
+ expect(module.get(TYPESENSE_MODULE_OPTIONS)).toBeDefined()
62
+ })
63
+
64
+ it(`register async use exists`, async () => {
65
+ class TestTypesenseModuleOptions {
66
+ createTypesenseOptions(): TypesenseModuleOptions {
67
+ return {
68
+ apiKey: 'test',
69
+ }
70
+ }
71
+ }
72
+
73
+ @Module({})
74
+ class TestTypesenseModule {}
75
+
76
+ module = await Test.createTestingModule({
77
+ imports: [
78
+ TypesenseModule.registerAsync({
79
+ imports: [
80
+ {
81
+ module: TestTypesenseModule,
82
+ providers: [TestTypesenseModuleOptions],
83
+ exports: [TestTypesenseModuleOptions],
84
+ },
85
+ ],
86
+ useExisting: TestTypesenseModuleOptions,
87
+ }),
88
+ ],
89
+ }).compile()
90
+
91
+ expect(module.get(TYPESENSE_MODULE_OPTIONS)).toBeDefined()
92
+ })
93
+ })
94
+ })
@@ -1,76 +1,76 @@
1
- import { DynamicModule, Module, Provider } from '@nestjs/common';
2
- import { DiscoveryModule } from '@nestjs/core';
3
- import {
4
- TypesenseModuleAsyncOptions,
5
- TypesenseOptionsFactory,
6
- TypesenseModuleOptions,
7
- } from './typesense-module.interface';
8
- import { TYPESENSE_MODULE_OPTIONS } from './typesense.constants';
9
- import {
10
- createTypesenseExportsProvider,
11
- createTypesenseOptionsProvider,
12
- } from './typesense.providers';
13
-
14
- @Module({
15
- imports: [DiscoveryModule],
16
- })
17
- export class TypesenseModule {
18
- static register(options: TypesenseModuleOptions = {}): DynamicModule {
19
- const optionsProviders = createTypesenseOptionsProvider(options);
20
- const exportsProviders = createTypesenseExportsProvider();
21
-
22
- return {
23
- global: true,
24
- module: TypesenseModule,
25
- providers: [...optionsProviders, ...exportsProviders],
26
- exports: exportsProviders,
27
- };
28
- }
29
-
30
- static registerAsync(options: TypesenseModuleAsyncOptions): DynamicModule {
31
- const exportsProviders = createTypesenseExportsProvider();
32
-
33
- return {
34
- global: true,
35
- module: TypesenseModule,
36
- imports: options.imports || [],
37
- providers: [...this.createAsyncProviders(options), ...exportsProviders],
38
- exports: exportsProviders,
39
- };
40
- }
41
-
42
- private static createAsyncProviders(
43
- options: TypesenseModuleAsyncOptions,
44
- ): Provider[] {
45
- if (options.useExisting || options.useFactory) {
46
- return [this.createAsyncOptionsProvider(options)];
47
- }
48
-
49
- return [
50
- this.createAsyncOptionsProvider(options),
51
- {
52
- provide: options?.useClass,
53
- useClass: options?.useClass,
54
- },
55
- ];
56
- }
57
-
58
- private static createAsyncOptionsProvider(
59
- options: TypesenseModuleAsyncOptions,
60
- ): Provider {
61
- if (options.useFactory) {
62
- return {
63
- provide: TYPESENSE_MODULE_OPTIONS,
64
- useFactory: options.useFactory,
65
- inject: options.inject || [],
66
- };
67
- }
68
-
69
- return {
70
- provide: TYPESENSE_MODULE_OPTIONS,
71
- useFactory: (optionsFactory: TypesenseOptionsFactory) =>
72
- optionsFactory.createTypesenseOptions(),
73
- inject: [options?.useExisting || options?.useClass],
74
- };
75
- }
76
- }
1
+ import { DynamicModule, Module, Provider } from '@nestjs/common';
2
+ import { DiscoveryModule } from '@nestjs/core';
3
+ import {
4
+ TypesenseModuleAsyncOptions,
5
+ TypesenseOptionsFactory,
6
+ TypesenseModuleOptions,
7
+ } from './typesense-module.interface';
8
+ import { TYPESENSE_MODULE_OPTIONS } from './typesense.constants';
9
+ import {
10
+ createTypesenseExportsProvider,
11
+ createTypesenseOptionsProvider,
12
+ } from './typesense.providers';
13
+
14
+ @Module({
15
+ imports: [DiscoveryModule],
16
+ })
17
+ export class TypesenseModule {
18
+ static register(options: TypesenseModuleOptions = {}): DynamicModule {
19
+ const optionsProviders = createTypesenseOptionsProvider(options);
20
+ const exportsProviders = createTypesenseExportsProvider();
21
+
22
+ return {
23
+ global: true,
24
+ module: TypesenseModule,
25
+ providers: [...optionsProviders, ...exportsProviders],
26
+ exports: exportsProviders,
27
+ };
28
+ }
29
+
30
+ static registerAsync(options: TypesenseModuleAsyncOptions): DynamicModule {
31
+ const exportsProviders = createTypesenseExportsProvider();
32
+
33
+ return {
34
+ global: true,
35
+ module: TypesenseModule,
36
+ imports: options.imports || [],
37
+ providers: [...this.createAsyncProviders(options), ...exportsProviders],
38
+ exports: exportsProviders,
39
+ };
40
+ }
41
+
42
+ private static createAsyncProviders(
43
+ options: TypesenseModuleAsyncOptions,
44
+ ): Provider[] {
45
+ if (options.useExisting || options.useFactory) {
46
+ return [this.createAsyncOptionsProvider(options)];
47
+ }
48
+
49
+ return [
50
+ this.createAsyncOptionsProvider(options),
51
+ {
52
+ provide: options?.useClass,
53
+ useClass: options?.useClass,
54
+ },
55
+ ];
56
+ }
57
+
58
+ private static createAsyncOptionsProvider(
59
+ options: TypesenseModuleAsyncOptions,
60
+ ): Provider {
61
+ if (options.useFactory) {
62
+ return {
63
+ provide: TYPESENSE_MODULE_OPTIONS,
64
+ useFactory: options.useFactory,
65
+ inject: options.inject || [],
66
+ };
67
+ }
68
+
69
+ return {
70
+ provide: TYPESENSE_MODULE_OPTIONS,
71
+ useFactory: (optionsFactory: TypesenseOptionsFactory) =>
72
+ optionsFactory.createTypesenseOptions(),
73
+ inject: [options?.useExisting || options?.useClass],
74
+ };
75
+ }
76
+ }
@@ -1,42 +1,42 @@
1
- import { Provider } from '@nestjs/common';
2
- import { Client } from 'typesense';
3
- import { TypesenseMetadataRegistry } from './metadata';
4
- import { TypesenseModuleOptions } from './typesense-module.interface';
5
- import { TYPESENSE_MODULE_OPTIONS } from './typesense.constants';
6
-
7
- export const createTypesenseOptionsProvider = (
8
- options: TypesenseModuleOptions = {},
9
- ): Provider[] => [
10
- {
11
- provide: TYPESENSE_MODULE_OPTIONS,
12
- useValue: options,
13
- },
14
- ];
15
-
16
- export const createTypesenseExportsProvider = (): Provider[] => [
17
- TypesenseMetadataRegistry,
18
- {
19
- provide: Client,
20
- useFactory: (options: TypesenseModuleOptions) =>
21
- new Client({
22
- nodes: options.nodes || [
23
- {
24
- host:
25
- process.env.TYPESENSE_HOST ||
26
- process.env.NODE_ENV === 'production'
27
- ? 'ts.typesense.svc.cluster.local'
28
- : 'localhost',
29
- port: 8108,
30
- protocol: 'http',
31
- },
32
- ],
33
- numRetries: options.numRetries || 10,
34
- apiKey: options.apiKey || process.env.TYPESENSE_API_KEY,
35
- connectionTimeoutSeconds: options.connectionTimeoutSeconds || 10,
36
- retryIntervalSeconds: options.retryIntervalSeconds || 0.1,
37
- healthcheckIntervalSeconds: options.healthcheckIntervalSeconds || 2,
38
- logLevel: options.logLevel || 'info',
39
- }),
40
- inject: [TYPESENSE_MODULE_OPTIONS],
41
- },
42
- ];
1
+ import { Provider } from '@nestjs/common';
2
+ import { Client } from 'typesense';
3
+ import { TypesenseMetadataRegistry } from './metadata';
4
+ import { TypesenseModuleOptions } from './typesense-module.interface';
5
+ import { TYPESENSE_MODULE_OPTIONS } from './typesense.constants';
6
+
7
+ export const createTypesenseOptionsProvider = (
8
+ options: TypesenseModuleOptions = {},
9
+ ): Provider[] => [
10
+ {
11
+ provide: TYPESENSE_MODULE_OPTIONS,
12
+ useValue: options,
13
+ },
14
+ ];
15
+
16
+ export const createTypesenseExportsProvider = (): Provider[] => [
17
+ TypesenseMetadataRegistry,
18
+ {
19
+ provide: Client,
20
+ useFactory: (options: TypesenseModuleOptions) =>
21
+ new Client({
22
+ nodes: options.nodes || [
23
+ {
24
+ host:
25
+ process.env.TYPESENSE_HOST ||
26
+ process.env.NODE_ENV === 'production'
27
+ ? 'ts.typesense.svc.cluster.local'
28
+ : 'localhost',
29
+ port: 8108,
30
+ protocol: 'http',
31
+ },
32
+ ],
33
+ numRetries: options.numRetries || 10,
34
+ apiKey: options.apiKey || process.env.TYPESENSE_API_KEY,
35
+ connectionTimeoutSeconds: options.connectionTimeoutSeconds || 10,
36
+ retryIntervalSeconds: options.retryIntervalSeconds || 0.1,
37
+ healthcheckIntervalSeconds: options.healthcheckIntervalSeconds || 2,
38
+ logLevel: options.logLevel || 'info',
39
+ }),
40
+ inject: [TYPESENSE_MODULE_OPTIONS],
41
+ },
42
+ ];
@@ -1 +1 @@
1
- export * from './pagination.response';
1
+ export * from './pagination.response';
@@ -1,37 +1,37 @@
1
- export class PaginationResponse<T> {
2
- data: T[];
3
- total?: number;
4
- offset?: number;
5
- limit?: number;
6
- hasNext?: boolean;
7
-
8
- constructor(
9
- data: T[],
10
- total: number = data?.length || 0,
11
- limit?: number,
12
- offset?: number,
13
- ) {
14
- this.data = data;
15
- this.total = total;
16
- this.offset = offset;
17
- this.limit = limit;
18
- this.hasNext = this.offset + this.limit < this.total;
19
- }
20
-
21
- toJSON() {
22
- return {
23
- data: this.data,
24
- total: this.total,
25
- count: this.data.length,
26
- offset: this.offset,
27
- limit: this.limit,
28
- hasNext: this.hasNext,
29
- };
30
- }
31
-
32
- promise(): Promise<PaginationResponse<T>> {
33
- return new Promise((resolve, reject) => {
34
- resolve(this);
35
- });
36
- }
37
- }
1
+ export class PaginationResponse<T> {
2
+ data: T[];
3
+ total?: number;
4
+ offset?: number;
5
+ limit?: number;
6
+ hasNext?: boolean;
7
+
8
+ constructor(
9
+ data: T[],
10
+ total: number = data?.length || 0,
11
+ limit?: number,
12
+ offset?: number,
13
+ ) {
14
+ this.data = data;
15
+ this.total = total;
16
+ this.offset = offset;
17
+ this.limit = limit;
18
+ this.hasNext = this.offset + this.limit < this.total;
19
+ }
20
+
21
+ toJSON() {
22
+ return {
23
+ data: this.data,
24
+ total: this.total,
25
+ count: this.data.length,
26
+ offset: this.offset,
27
+ limit: this.limit,
28
+ hasNext: this.hasNext,
29
+ };
30
+ }
31
+
32
+ promise(): Promise<PaginationResponse<T>> {
33
+ return new Promise((resolve, reject) => {
34
+ resolve(this);
35
+ });
36
+ }
37
+ }
@@ -0,0 +1 @@
1
+ export * from './microservice.setup';
@@ -0,0 +1,29 @@
1
+ import type { INestApplication } from '@nestjs/common';
2
+ import { Logger } from '@nestjs/common';
3
+ import { Transport } from '@nestjs/microservices';
4
+
5
+ import { AppUtils } from '../util';
6
+
7
+ export async function microserviceSetup(
8
+ app: INestApplication,
9
+ serviceName: string,
10
+ ) {
11
+ AppUtils.killAppWithGrace(app);
12
+ const protoBasePath = process.cwd() + '/libs/proto-schema/src/proto';
13
+ const host = process.env['GRPC_HOST'];
14
+ const port = process.env['GRPC_PORT'];
15
+ const options = {
16
+ transport: Transport.GRPC,
17
+ options: {
18
+ url: `${host}:${port}`,
19
+ protoPath: `${protoBasePath}/${serviceName}.proto`,
20
+ package: `${serviceName}`,
21
+ },
22
+ };
23
+ app.connectMicroservice(options);
24
+ await app.startAllMicroservices();
25
+ Logger.log(
26
+ `GRPC ${serviceName} running on ${options.options.url}`,
27
+ 'Bootstrap',
28
+ );
29
+ }
File without changes
@@ -0,0 +1,18 @@
1
+ import type { INestApplication } from '@nestjs/common';
2
+
3
+ export class AppUtils {
4
+ public static killAppWithGrace = (app: INestApplication) => {
5
+ process.on('SIGINT', async () => {
6
+ setTimeout(() => process.exit(1), 5000);
7
+ await app.close();
8
+ process.exit(0);
9
+ });
10
+
11
+ // kill -15
12
+ process.on('SIGTERM', async () => {
13
+ setTimeout(() => process.exit(1), 5000);
14
+ await app.close();
15
+ process.exit(0);
16
+ });
17
+ };
18
+ }
@@ -1,49 +1,49 @@
1
- import dayjs from 'dayjs';
2
- import { addSecond, isExpired } from './date.util';
3
-
4
- describe('Utility Functions', () => {
5
- test('addSecond should return a Date object with the specified duration added', () => {
6
- // Arrange
7
- const duration = 10;
8
-
9
- // Act
10
- const result = addSecond(duration);
11
-
12
- // Assert
13
- const expectedDate = dayjs().add(duration, 'seconds').toDate();
14
- expect(result).toEqual(expectedDate);
15
- });
16
-
17
- test('isExpired should return true for a past date', () => {
18
- // Arrange
19
- const pastDate = dayjs().subtract(1, 'day').toDate();
20
-
21
- // Act
22
- const result = isExpired(pastDate);
23
-
24
- // Assert
25
- expect(result).toBe(true);
26
- });
27
-
28
- test('isExpired should return false for a future date', () => {
29
- // Arrange
30
- const futureDate = dayjs().add(1, 'day').toDate();
31
-
32
- // Act
33
- const result = isExpired(futureDate);
34
-
35
- // Assert
36
- expect(result).toBe(false);
37
- });
38
-
39
- test('isExpired should return false for the current date', () => {
40
- // Arrange
41
- const currentDate = dayjs().toDate();
42
-
43
- // Act
44
- const result = isExpired(currentDate);
45
-
46
- // Assert
47
- expect(result).toBe(false);
48
- });
49
- });
1
+ import dayjs from 'dayjs';
2
+ import { addSecond, isExpired } from './date.util';
3
+
4
+ describe('Utility Functions', () => {
5
+ test('addSecond should return a Date object with the specified duration added', () => {
6
+ // Arrange
7
+ const duration = 10;
8
+
9
+ // Act
10
+ const result = addSecond(duration);
11
+
12
+ // Assert
13
+ const expectedDate = dayjs().add(duration, 'seconds').toDate();
14
+ expect(result).toEqual(expectedDate);
15
+ });
16
+
17
+ test('isExpired should return true for a past date', () => {
18
+ // Arrange
19
+ const pastDate = dayjs().subtract(1, 'day').toDate();
20
+
21
+ // Act
22
+ const result = isExpired(pastDate);
23
+
24
+ // Assert
25
+ expect(result).toBe(true);
26
+ });
27
+
28
+ test('isExpired should return false for a future date', () => {
29
+ // Arrange
30
+ const futureDate = dayjs().add(1, 'day').toDate();
31
+
32
+ // Act
33
+ const result = isExpired(futureDate);
34
+
35
+ // Assert
36
+ expect(result).toBe(false);
37
+ });
38
+
39
+ test('isExpired should return false for the current date', () => {
40
+ // Arrange
41
+ const currentDate = dayjs().toDate();
42
+
43
+ // Act
44
+ const result = isExpired(currentDate);
45
+
46
+ // Assert
47
+ expect(result).toBe(false);
48
+ });
49
+ });