@adaptivestone/framework 5.0.0-alpha.9 → 5.0.0-beta.10

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 (78) hide show
  1. package/CHANGELOG.md +123 -1
  2. package/Cli.js +3 -4
  3. package/cluster.js +0 -2
  4. package/commands/CreateUser.js +35 -0
  5. package/commands/Documentation.js +4 -0
  6. package/commands/DropIndex.js +14 -5
  7. package/commands/GenerateRandomBytes.js +21 -0
  8. package/commands/GetOpenApiJson.js +17 -2
  9. package/commands/SyncIndexes.js +1 -0
  10. package/commands/migration/Create.js +21 -10
  11. package/commands/migration/Migrate.js +1 -0
  12. package/config/auth.js +4 -1
  13. package/config/ipDetector.js +14 -0
  14. package/controllers/Auth.js +22 -31
  15. package/controllers/Home.js +1 -1
  16. package/eslint.config.js +68 -0
  17. package/folderConfig.js +0 -1
  18. package/helpers/files.js +9 -12
  19. package/helpers/logger.js +0 -1
  20. package/helpers/yup.js +2 -4
  21. package/jsconfig.json +4 -4
  22. package/models/Lock.js +107 -0
  23. package/models/User.js +26 -3
  24. package/modules/AbstractCommand.js +26 -2
  25. package/modules/AbstractController.js +19 -26
  26. package/modules/AbstractModel.d.ts +48 -0
  27. package/modules/AbstractModel.js +37 -10
  28. package/modules/Base.d.ts +4 -4
  29. package/modules/Base.js +13 -2
  30. package/modules/BaseCli.js +99 -11
  31. package/package.json +28 -25
  32. package/server.d.ts +9 -7
  33. package/server.js +45 -11
  34. package/services/cache/Cache.d.ts +1 -1
  35. package/services/cache/Cache.js +9 -7
  36. package/services/http/HttpServer.js +11 -16
  37. package/services/http/middleware/AbstractMiddleware.js +3 -3
  38. package/services/http/middleware/GetUserByToken.js +3 -2
  39. package/services/http/middleware/I18n.js +22 -23
  40. package/services/http/middleware/IpDetector.js +59 -0
  41. package/services/http/middleware/Pagination.js +7 -6
  42. package/services/http/middleware/RateLimiter.js +10 -4
  43. package/services/http/middleware/RequestLogger.js +3 -3
  44. package/services/http/middleware/RequestParser.js +1 -1
  45. package/services/messaging/email/templates/.gitkeep +0 -0
  46. package/services/validate/ValidateService.js +5 -5
  47. package/services/validate/drivers/AbstractValidator.js +2 -2
  48. package/services/validate/drivers/CustomValidator.js +2 -2
  49. package/services/validate/drivers/YupValidator.js +3 -3
  50. package/tests/setup.js +8 -6
  51. package/tests/setupVitest.js +9 -7
  52. package/types/ICommandArguments.d.ts +41 -0
  53. package/types/TFoldersConfig.d.ts +7 -4
  54. package/vitest.config.js +4 -3
  55. package/.eslintrc.cjs +0 -41
  56. package/commands/Generate.js +0 -14
  57. package/config/mail.js +0 -29
  58. package/controllers/Auth.test.js +0 -451
  59. package/controllers/Home.test.js +0 -12
  60. package/models/Migration.test.js +0 -20
  61. package/models/Sequence.test.js +0 -43
  62. package/models/User.test.js +0 -143
  63. package/modules/Modules.test.js +0 -18
  64. package/services/cache/Cache.test.js +0 -81
  65. package/services/http/middleware/Auth.test.js +0 -57
  66. package/services/http/middleware/Cors.test.js +0 -147
  67. package/services/http/middleware/GetUserByToken.test.js +0 -108
  68. package/services/http/middleware/I18n.test.js +0 -96
  69. package/services/http/middleware/PrepareAppInfo.test.js +0 -26
  70. package/services/http/middleware/RateLimiter.test.js +0 -233
  71. package/services/http/middleware/RequestParser.test.js +0 -121
  72. package/services/http/middleware/Role.test.js +0 -93
  73. package/services/messaging/email/index.js +0 -217
  74. package/services/messaging/email/templates/emptyTemplate/html.pug +0 -9
  75. package/services/messaging/email/templates/emptyTemplate/subject.pug +0 -1
  76. package/services/messaging/email/templates/emptyTemplate/text.pug +0 -1
  77. package/services/messaging/index.js +0 -3
  78. package/services/validate/ValidateService.test.js +0 -107
@@ -1,107 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
-
3
- import yup from 'yup';
4
- import ValidateService from './ValidateService.js';
5
- import YupValidator from './drivers/YupValidator.js';
6
- import CustomValidator from './drivers/CustomValidator.js';
7
-
8
- describe('validate service', () => {
9
- describe('validateSchema funtion', () => {
10
- const data = {
11
- name: '1213123123',
12
- };
13
- const req = {};
14
-
15
- it('returns an empty object if no validator is provided', async () => {
16
- expect.assertions(1);
17
- const result = await new ValidateService(
18
- global.server.app,
19
- new YupValidator(
20
- global.server.app,
21
- yup.object().shape({ name: '123' }),
22
- ),
23
- ).validateSchema(req, undefined, data);
24
- expect(result).toStrictEqual({});
25
- });
26
-
27
- it('calls validateFields and castFields if validator is provided', async () => {
28
- expect.assertions(1);
29
- const validator = new YupValidator(
30
- global.server.app,
31
- yup.object().shape({ name: yup.string() }),
32
- );
33
- const result = await new ValidateService(
34
- global.server.app,
35
- {},
36
- ).validateSchema(req, validator, data);
37
- expect(result).toStrictEqual({
38
- name: '1213123123',
39
- });
40
- });
41
- });
42
-
43
- describe('isValidatorExists funtion', () => {
44
- it('returns false for non-object input', () => {
45
- expect.assertions(1);
46
- const validator = 'not an object';
47
- const result = ValidateService.isValidatorExists(validator);
48
- expect(result).toBeFalsy();
49
- });
50
-
51
- it('returns true if validator is an instance of one of the drivers', () => {
52
- expect.assertions(1);
53
- const validator = new ValidateService.drivers.YupValidator();
54
- const result = ValidateService.isValidatorExists(validator);
55
- expect(result).toBeTruthy();
56
- });
57
-
58
- it('returns false if validator is not an instance of any of the drivers', () => {
59
- expect.assertions(1);
60
- const validator = {};
61
- const result = ValidateService.isValidatorExists(validator);
62
- expect(result).toBeFalsy();
63
- });
64
- });
65
-
66
- describe('getDriverByValidatorBody', () => {
67
- it('should return the body if it is already a validator', () => {
68
- expect.assertions(1);
69
- const body = new YupValidator(
70
- global.server.app,
71
- yup.object().shape({ name: yup.string() }),
72
- );
73
-
74
- const validator = ValidateService.getDriverByValidatorBody(
75
- global.server.app,
76
- body,
77
- );
78
-
79
- expect(validator).toStrictEqual(body);
80
- });
81
-
82
- it('should return a YupValidator instance if the body is a Yup schema', () => {
83
- expect.assertions(1);
84
- const body = yup.object().shape({
85
- name: '1234',
86
- });
87
-
88
- const validator = ValidateService.getDriverByValidatorBody(
89
- global.server.app,
90
- body,
91
- );
92
-
93
- expect(validator).toBeInstanceOf(YupValidator);
94
- });
95
-
96
- it('should return CustomValidator if the body is neither a validator nor a Yup schema', () => {
97
- expect.assertions(1);
98
- const body = 'string';
99
- const validator = ValidateService.getDriverByValidatorBody(
100
- global.server.app,
101
- body,
102
- );
103
-
104
- expect(validator).toBeInstanceOf(CustomValidator);
105
- });
106
- });
107
- });