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,10 +1,10 @@
1
- import dayjs from 'dayjs';
2
-
3
- export const addSecond = (duration: number): Date => {
4
- return dayjs().add(duration, 'seconds').toDate();
5
- };
6
-
7
- export const isExpired = (date: Date): boolean => {
8
- const currentDate = dayjs();
9
- return dayjs(date).isBefore(currentDate);
10
- };
1
+ import dayjs from 'dayjs';
2
+
3
+ export const addSecond = (duration: number): Date => {
4
+ return dayjs().add(duration, 'seconds').toDate();
5
+ };
6
+
7
+ export const isExpired = (date: Date): boolean => {
8
+ const currentDate = dayjs();
9
+ return dayjs(date).isBefore(currentDate);
10
+ };
@@ -1,79 +1,79 @@
1
- import * as bcrypt from 'bcrypt';
2
- import {
3
- generateKey,
4
- generateDigitCode,
5
- generatePassword,
6
- } from './generator.util';
7
-
8
- describe('Utils', () => {
9
- describe('generateKey', () => {
10
- it('should generate a key of the specified length', () => {
11
- const keyLength = 10;
12
- const key = generateKey(keyLength);
13
- expect(key).toHaveLength(keyLength);
14
- });
15
-
16
- it('should generate a key with default length if not specified', () => {
17
- const defaultKeyLength = 36;
18
- const key = generateKey();
19
- expect(key).toHaveLength(defaultKeyLength);
20
- });
21
- });
22
-
23
- describe('generateDigitCode', () => {
24
- it('should generate a digit code of the specified length', () => {
25
- const codeLength = 6;
26
- const code = generateDigitCode(codeLength);
27
- expect(code).toHaveLength(codeLength);
28
- expect(Number(code)).toBeGreaterThanOrEqual(100000);
29
- expect(Number(code)).toBeLessThanOrEqual(999999);
30
- });
31
-
32
- it('should generate a digit code with default length if not specified', () => {
33
- const defaultCodeLength = 4;
34
- const code = generateDigitCode();
35
- expect(code).toHaveLength(defaultCodeLength);
36
- expect(Number(code)).toBeGreaterThanOrEqual(1000);
37
- expect(Number(code)).toBeLessThanOrEqual(9999);
38
- });
39
- });
40
-
41
- describe('Utility Functions', () => {
42
- test('generatePassword should return a hashed password with the specified salt rounds', async () => {
43
- // Arrange
44
- const password = 'password123';
45
- const saltRounds = 12;
46
-
47
- // Act
48
- const hashedPassword = await generatePassword(password, saltRounds);
49
-
50
- // Assert
51
- expect(typeof hashedPassword).toBe('string');
52
- expect(hashedPassword).not.toBe(password);
53
- expect(await bcrypt.compare(password, hashedPassword)).toBeTruthy();
54
- });
55
-
56
- test('generatePassword should use the default salt rounds when no value is provided', async () => {
57
- // Arrange
58
- const password = 'password123';
59
- const defaultSaltRounds = 10;
60
-
61
- // Act
62
- const hashedPassword = await generatePassword(password);
63
-
64
- // Assert
65
- expect(typeof hashedPassword).toBe('string');
66
- expect(hashedPassword).not.toBe(password);
67
- expect(await bcrypt.compare(password, hashedPassword)).toBeTruthy();
68
- expect(bcrypt.getRounds(hashedPassword)).toBe(defaultSaltRounds);
69
- });
70
-
71
- test('generatePassword should throw an error when an invalid password is provided', async () => {
72
- // Arrange
73
- const invalidPassword = '';
74
-
75
- // Act and Assert
76
- await expect(generatePassword(invalidPassword)).rejects.toThrow();
77
- });
78
- });
79
- });
1
+ import * as bcrypt from 'bcrypt';
2
+ import {
3
+ generateKey,
4
+ generateDigitCode,
5
+ generatePassword,
6
+ } from './generator.util';
7
+
8
+ describe('Utils', () => {
9
+ describe('generateKey', () => {
10
+ it('should generate a key of the specified length', () => {
11
+ const keyLength = 10;
12
+ const key = generateKey(keyLength);
13
+ expect(key).toHaveLength(keyLength);
14
+ });
15
+
16
+ it('should generate a key with default length if not specified', () => {
17
+ const defaultKeyLength = 36;
18
+ const key = generateKey();
19
+ expect(key).toHaveLength(defaultKeyLength);
20
+ });
21
+ });
22
+
23
+ describe('generateDigitCode', () => {
24
+ it('should generate a digit code of the specified length', () => {
25
+ const codeLength = 6;
26
+ const code = generateDigitCode(codeLength);
27
+ expect(code).toHaveLength(codeLength);
28
+ expect(Number(code)).toBeGreaterThanOrEqual(100000);
29
+ expect(Number(code)).toBeLessThanOrEqual(999999);
30
+ });
31
+
32
+ it('should generate a digit code with default length if not specified', () => {
33
+ const defaultCodeLength = 4;
34
+ const code = generateDigitCode();
35
+ expect(code).toHaveLength(defaultCodeLength);
36
+ expect(Number(code)).toBeGreaterThanOrEqual(1000);
37
+ expect(Number(code)).toBeLessThanOrEqual(9999);
38
+ });
39
+ });
40
+
41
+ describe('Utility Functions', () => {
42
+ test('generatePassword should return a hashed password with the specified salt rounds', async () => {
43
+ // Arrange
44
+ const password = 'password123';
45
+ const saltRounds = 12;
46
+
47
+ // Act
48
+ const hashedPassword = await generatePassword(password, saltRounds);
49
+
50
+ // Assert
51
+ expect(typeof hashedPassword).toBe('string');
52
+ expect(hashedPassword).not.toBe(password);
53
+ expect(await bcrypt.compare(password, hashedPassword)).toBeTruthy();
54
+ });
55
+
56
+ test('generatePassword should use the default salt rounds when no value is provided', async () => {
57
+ // Arrange
58
+ const password = 'password123';
59
+ const defaultSaltRounds = 10;
60
+
61
+ // Act
62
+ const hashedPassword = await generatePassword(password);
63
+
64
+ // Assert
65
+ expect(typeof hashedPassword).toBe('string');
66
+ expect(hashedPassword).not.toBe(password);
67
+ expect(await bcrypt.compare(password, hashedPassword)).toBeTruthy();
68
+ expect(bcrypt.getRounds(hashedPassword)).toBe(defaultSaltRounds);
69
+ });
70
+
71
+ test('generatePassword should throw an error when an invalid password is provided', async () => {
72
+ // Arrange
73
+ const invalidPassword = '';
74
+
75
+ // Act and Assert
76
+ await expect(generatePassword(invalidPassword)).rejects.toThrow();
77
+ });
78
+ });
79
+ });
@@ -1,34 +1,34 @@
1
- import * as bcrypt from 'bcrypt';
2
-
3
- export const generateKey = (length = 36) => {
4
- const chars =
5
- 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
6
- let result = '';
7
- for (let i = length; i > 0; i--) {
8
- result += chars[Math.floor(Math.random() * chars.length)];
9
- }
10
- return result;
11
- };
12
-
13
- export const generateDigitCode = (length = 4): string => {
14
- const startAt = 1 + '0'.repeat(length - 1);
15
- const endAt = 9 + '0'.repeat(length - 1);
16
- const generateCode = `${Math.floor(
17
- Number(startAt) + Math.random() * Number(endAt),
18
- )}`;
19
- return generateCode;
20
- };
21
-
22
- export const generatePassword = async (
23
- password: string,
24
- saltOrRounds = 10,
25
- ): Promise<string> => {
26
- return await bcrypt.hash(password, saltOrRounds);
27
- };
28
-
29
- export const comparePassword = (
30
- password: string,
31
- hashPassword: string,
32
- ): Promise<boolean> => {
33
- return bcrypt.compare(password, hashPassword);
34
- };
1
+ import * as bcrypt from 'bcrypt';
2
+
3
+ export const generateKey = (length = 36) => {
4
+ const chars =
5
+ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
6
+ let result = '';
7
+ for (let i = length; i > 0; i--) {
8
+ result += chars[Math.floor(Math.random() * chars.length)];
9
+ }
10
+ return result;
11
+ };
12
+
13
+ export const generateDigitCode = (length = 4): string => {
14
+ const startAt = 1 + '0'.repeat(length - 1);
15
+ const endAt = 9 + '0'.repeat(length - 1);
16
+ const generateCode = `${Math.floor(
17
+ Number(startAt) + Math.random() * Number(endAt),
18
+ )}`;
19
+ return generateCode;
20
+ };
21
+
22
+ export const generatePassword = async (
23
+ password: string,
24
+ saltOrRounds = 10,
25
+ ): Promise<string> => {
26
+ return await bcrypt.hash(password, saltOrRounds);
27
+ };
28
+
29
+ export const comparePassword = (
30
+ password: string,
31
+ hashPassword: string,
32
+ ): Promise<boolean> => {
33
+ return bcrypt.compare(password, hashPassword);
34
+ };
package/src/util/index.ts CHANGED
@@ -1,2 +1,3 @@
1
- export * from './date.util';
2
- export * from './generator.util';
1
+ export * from './date.util';
2
+ export * from './generator.util';
3
+ export * from './app.utils';
@@ -1,24 +1,24 @@
1
- import { Test, TestingModule } from '@nestjs/testing';
2
- import { INestApplication } from '@nestjs/common';
3
- import * as request from 'supertest';
4
- import { AppModule } from './../src/app.module';
5
-
6
- describe('AppController (e2e)', () => {
7
- let app: INestApplication;
8
-
9
- beforeEach(async () => {
10
- const moduleFixture: TestingModule = await Test.createTestingModule({
11
- imports: [AppModule],
12
- }).compile();
13
-
14
- app = moduleFixture.createNestApplication();
15
- await app.init();
16
- });
17
-
18
- it('/ (GET)', () => {
19
- return request(app.getHttpServer())
20
- .get('/')
21
- .expect(200)
22
- .expect('Hello World!');
23
- });
24
- });
1
+ import { Test, TestingModule } from '@nestjs/testing';
2
+ import { INestApplication } from '@nestjs/common';
3
+ import * as request from 'supertest';
4
+ import { AppModule } from './../src/app.module';
5
+
6
+ describe('AppController (e2e)', () => {
7
+ let app: INestApplication;
8
+
9
+ beforeEach(async () => {
10
+ const moduleFixture: TestingModule = await Test.createTestingModule({
11
+ imports: [AppModule],
12
+ }).compile();
13
+
14
+ app = moduleFixture.createNestApplication();
15
+ await app.init();
16
+ });
17
+
18
+ it('/ (GET)', () => {
19
+ return request(app.getHttpServer())
20
+ .get('/')
21
+ .expect(200)
22
+ .expect('Hello World!');
23
+ });
24
+ });
@@ -1,9 +1,9 @@
1
- {
2
- "moduleFileExtensions": ["js", "json", "ts"],
3
- "rootDir": ".",
4
- "testEnvironment": "node",
5
- "testRegex": ".e2e-spec.ts$",
6
- "transform": {
7
- "^.+\\.(t|j)s$": "ts-jest"
8
- }
9
- }
1
+ {
2
+ "moduleFileExtensions": ["js", "json", "ts"],
3
+ "rootDir": ".",
4
+ "testEnvironment": "node",
5
+ "testRegex": ".e2e-spec.ts$",
6
+ "transform": {
7
+ "^.+\\.(t|j)s$": "ts-jest"
8
+ }
9
+ }
@@ -1,4 +1,4 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
4
- }
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
4
+ }
package/tsconfig.json CHANGED
@@ -1,21 +1,21 @@
1
- {
2
- "compilerOptions": {
3
- "module": "commonjs",
4
- "declaration": true,
5
- "removeComments": true,
6
- "emitDecoratorMetadata": true,
7
- "experimentalDecorators": true,
8
- "allowSyntheticDefaultImports": true,
9
- "target": "es2017",
10
- "sourceMap": true,
11
- "outDir": "./dist",
12
- "baseUrl": "./",
13
- "incremental": true,
14
- "skipLibCheck": true,
15
- "strictNullChecks": false,
16
- "noImplicitAny": false,
17
- "strictBindCallApply": false,
18
- "forceConsistentCasingInFileNames": false,
19
- "noFallthroughCasesInSwitch": false
20
- }
21
- }
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "declaration": true,
5
+ "removeComments": true,
6
+ "emitDecoratorMetadata": true,
7
+ "experimentalDecorators": true,
8
+ "allowSyntheticDefaultImports": true,
9
+ "target": "es2017",
10
+ "sourceMap": true,
11
+ "outDir": "./dist",
12
+ "baseUrl": "./",
13
+ "incremental": true,
14
+ "skipLibCheck": true,
15
+ "strictNullChecks": false,
16
+ "noImplicitAny": false,
17
+ "strictBindCallApply": false,
18
+ "forceConsistentCasingInFileNames": false,
19
+ "noFallthroughCasesInSwitch": false
20
+ }
21
+ }