@adaptivestone/framework 5.0.0-beta.11 → 5.0.0-beta.12

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 (271) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENCE +1 -1
  3. package/cliCommand.ts +10 -0
  4. package/dist/Cli.d.ts +7 -0
  5. package/dist/Cli.js +19 -0
  6. package/dist/Cli.js.map +1 -0
  7. package/dist/cluster.d.ts +1 -0
  8. package/dist/cluster.js +18 -0
  9. package/dist/cluster.js.map +1 -0
  10. package/dist/commands/CreateUser.d.ts +32 -0
  11. package/dist/commands/CreateUser.js +81 -0
  12. package/dist/commands/CreateUser.js.map +1 -0
  13. package/dist/commands/Documentation.d.ts +5 -0
  14. package/dist/commands/Documentation.js +15 -0
  15. package/dist/commands/Documentation.js.map +1 -0
  16. package/dist/commands/DropIndex.d.ts +16 -0
  17. package/dist/commands/DropIndex.js +30 -0
  18. package/dist/commands/DropIndex.js.map +1 -0
  19. package/dist/commands/GenerateRandomBytes.d.ts +7 -0
  20. package/dist/commands/GenerateRandomBytes.js +18 -0
  21. package/dist/commands/GenerateRandomBytes.js.map +1 -0
  22. package/dist/commands/GetOpenApiJson.d.ts +17 -0
  23. package/dist/commands/GetOpenApiJson.js +272 -0
  24. package/dist/commands/GetOpenApiJson.js.map +1 -0
  25. package/dist/commands/SyncIndexes.d.ts +6 -0
  26. package/dist/commands/SyncIndexes.js +32 -0
  27. package/dist/commands/SyncIndexes.js.map +1 -0
  28. package/dist/commands/migration/Create.d.ts +18 -0
  29. package/dist/commands/migration/Create.js +57 -0
  30. package/dist/commands/migration/Create.js.map +1 -0
  31. package/dist/commands/migration/Migrate.d.ts +6 -0
  32. package/dist/commands/migration/Migrate.js +46 -0
  33. package/dist/commands/migration/Migrate.js.map +1 -0
  34. package/dist/config/auth.d.ts +6 -0
  35. package/dist/config/auth.js +7 -0
  36. package/dist/config/auth.js.map +1 -0
  37. package/dist/config/http.d.ts +8 -0
  38. package/dist/config/http.js +10 -0
  39. package/dist/config/http.js.map +1 -0
  40. package/dist/config/i18n.d.ts +10 -0
  41. package/dist/config/i18n.js +13 -0
  42. package/dist/config/i18n.js.map +1 -0
  43. package/dist/config/ipDetector.d.ts +5 -0
  44. package/dist/config/ipDetector.js +15 -0
  45. package/dist/config/ipDetector.js.map +1 -0
  46. package/dist/config/log.d.ts +22 -0
  47. package/dist/config/log.js +23 -0
  48. package/dist/config/log.js.map +1 -0
  49. package/dist/config/mongo.d.ts +4 -0
  50. package/dist/config/mongo.js +4 -0
  51. package/dist/config/mongo.js.map +1 -0
  52. package/dist/config/rateLimiter.d.ts +15 -0
  53. package/dist/config/rateLimiter.js +17 -0
  54. package/dist/config/rateLimiter.js.map +1 -0
  55. package/dist/config/redis.d.ts +5 -0
  56. package/dist/config/redis.js +5 -0
  57. package/dist/config/redis.js.map +1 -0
  58. package/dist/config/validate.d.ts +4 -0
  59. package/dist/config/validate.js +4 -0
  60. package/dist/config/validate.js.map +1 -0
  61. package/dist/controllers/Auth.d.ts +74 -0
  62. package/dist/controllers/Auth.js +181 -0
  63. package/dist/controllers/Auth.js.map +1 -0
  64. package/dist/controllers/Home.d.ts +15 -0
  65. package/dist/controllers/Home.js +24 -0
  66. package/dist/controllers/Home.js.map +1 -0
  67. package/dist/controllers/index.d.ts +16 -0
  68. package/dist/controllers/index.js +59 -0
  69. package/dist/controllers/index.js.map +1 -0
  70. package/dist/folderConfig.d.ts +34 -0
  71. package/dist/folderConfig.js +15 -0
  72. package/dist/folderConfig.js.map +1 -0
  73. package/dist/helpers/files.d.ts +16 -0
  74. package/dist/helpers/files.js +73 -0
  75. package/dist/helpers/files.js.map +1 -0
  76. package/dist/helpers/logger.d.ts +4 -0
  77. package/dist/helpers/logger.js +28 -0
  78. package/dist/helpers/logger.js.map +1 -0
  79. package/dist/helpers/redis/clearNamespace.d.ts +3 -0
  80. package/dist/helpers/redis/clearNamespace.js +15 -0
  81. package/dist/helpers/redis/clearNamespace.js.map +1 -0
  82. package/dist/helpers/yup.d.ts +13 -0
  83. package/{helpers → dist/helpers}/yup.js +8 -9
  84. package/dist/helpers/yup.js.map +1 -0
  85. package/dist/index.d.ts +1 -0
  86. package/dist/index.js +7 -0
  87. package/dist/index.js.map +1 -0
  88. package/dist/models/Lock.d.ts +62 -0
  89. package/dist/models/Lock.js +94 -0
  90. package/dist/models/Lock.js.map +1 -0
  91. package/dist/models/Migration.d.ts +11 -0
  92. package/dist/models/Migration.js +14 -0
  93. package/dist/models/Migration.js.map +1 -0
  94. package/dist/models/Sequence.d.ts +16 -0
  95. package/dist/models/Sequence.js +16 -0
  96. package/dist/models/Sequence.js.map +1 -0
  97. package/dist/models/User.d.ts +101 -0
  98. package/dist/models/User.js +230 -0
  99. package/dist/models/User.js.map +1 -0
  100. package/dist/modules/AbstractCommand.d.ts +30 -0
  101. package/dist/modules/AbstractCommand.js +44 -0
  102. package/dist/modules/AbstractCommand.js.map +1 -0
  103. package/dist/modules/AbstractConnector.d.ts +5 -0
  104. package/dist/modules/AbstractConnector.js +8 -0
  105. package/dist/modules/AbstractConnector.js.map +1 -0
  106. package/dist/modules/AbstractController.d.ts +90 -0
  107. package/dist/modules/AbstractController.js +324 -0
  108. package/dist/modules/AbstractController.js.map +1 -0
  109. package/dist/modules/AbstractModel.d.ts +32 -0
  110. package/dist/modules/AbstractModel.js +73 -0
  111. package/dist/modules/AbstractModel.js.map +1 -0
  112. package/dist/modules/Base.d.ts +29 -0
  113. package/dist/modules/Base.js +54 -0
  114. package/dist/modules/Base.js.map +1 -0
  115. package/dist/modules/BaseCli.d.ts +25 -0
  116. package/dist/modules/BaseCli.js +138 -0
  117. package/dist/modules/BaseCli.js.map +1 -0
  118. package/dist/server.d.ts +110 -0
  119. package/dist/server.js +372 -0
  120. package/dist/server.js.map +1 -0
  121. package/dist/services/cache/Cache.d.ts +31 -0
  122. package/dist/services/cache/Cache.js +115 -0
  123. package/dist/services/cache/Cache.js.map +1 -0
  124. package/dist/services/documentation/DocumentationGenerator.d.ts +11 -0
  125. package/dist/services/documentation/DocumentationGenerator.js +134 -0
  126. package/dist/services/documentation/DocumentationGenerator.js.map +1 -0
  127. package/dist/services/http/HttpServer.d.ts +35 -0
  128. package/dist/services/http/HttpServer.js +71 -0
  129. package/dist/services/http/HttpServer.js.map +1 -0
  130. package/dist/services/http/middleware/AbstractMiddleware.d.ts +25 -0
  131. package/dist/services/http/middleware/AbstractMiddleware.js +43 -0
  132. package/dist/services/http/middleware/AbstractMiddleware.js.map +1 -0
  133. package/dist/services/http/middleware/Auth.d.ts +9 -0
  134. package/dist/services/http/middleware/Auth.js +18 -0
  135. package/dist/services/http/middleware/Auth.js.map +1 -0
  136. package/dist/services/http/middleware/Cors.d.ts +10 -0
  137. package/dist/services/http/middleware/Cors.js +36 -0
  138. package/dist/services/http/middleware/Cors.js.map +1 -0
  139. package/dist/services/http/middleware/GetUserByToken.d.ts +19 -0
  140. package/dist/services/http/middleware/GetUserByToken.js +40 -0
  141. package/dist/services/http/middleware/GetUserByToken.js.map +1 -0
  142. package/dist/services/http/middleware/I18n.d.ts +26 -0
  143. package/dist/services/http/middleware/I18n.js +97 -0
  144. package/dist/services/http/middleware/I18n.js.map +1 -0
  145. package/dist/services/http/middleware/IpDetector.d.ts +12 -0
  146. package/dist/services/http/middleware/IpDetector.js +51 -0
  147. package/dist/services/http/middleware/IpDetector.js.map +1 -0
  148. package/dist/services/http/middleware/Pagination.d.ts +27 -0
  149. package/dist/services/http/middleware/Pagination.js +47 -0
  150. package/dist/services/http/middleware/Pagination.js.map +1 -0
  151. package/dist/services/http/middleware/PrepareAppInfo.d.ts +8 -0
  152. package/dist/services/http/middleware/PrepareAppInfo.js +17 -0
  153. package/dist/services/http/middleware/PrepareAppInfo.js.map +1 -0
  154. package/dist/services/http/middleware/RateLimiter.d.ts +18 -0
  155. package/dist/services/http/middleware/RateLimiter.js +106 -0
  156. package/dist/services/http/middleware/RateLimiter.js.map +1 -0
  157. package/dist/services/http/middleware/RequestLogger.d.ts +8 -0
  158. package/dist/services/http/middleware/RequestLogger.js +18 -0
  159. package/dist/services/http/middleware/RequestLogger.js.map +1 -0
  160. package/dist/services/http/middleware/RequestParser.d.ts +8 -0
  161. package/dist/services/http/middleware/RequestParser.js +35 -0
  162. package/dist/services/http/middleware/RequestParser.js.map +1 -0
  163. package/dist/services/http/middleware/Role.d.ts +9 -0
  164. package/dist/services/http/middleware/Role.js +24 -0
  165. package/dist/services/http/middleware/Role.js.map +1 -0
  166. package/dist/services/validate/ValidateService.d.ts +31 -0
  167. package/dist/services/validate/ValidateService.js +96 -0
  168. package/dist/services/validate/ValidateService.js.map +1 -0
  169. package/dist/services/validate/drivers/AbstractValidator.d.ts +14 -0
  170. package/dist/services/validate/drivers/AbstractValidator.js +32 -0
  171. package/dist/services/validate/drivers/AbstractValidator.js.map +1 -0
  172. package/dist/services/validate/drivers/CustomValidator.d.ts +14 -0
  173. package/dist/services/validate/drivers/CustomValidator.js +48 -0
  174. package/dist/services/validate/drivers/CustomValidator.js.map +1 -0
  175. package/dist/services/validate/drivers/YupValidator.d.ts +13 -0
  176. package/dist/services/validate/drivers/YupValidator.js +86 -0
  177. package/dist/services/validate/drivers/YupValidator.js.map +1 -0
  178. package/dist/tests/globalSetupVitest.d.ts +2 -0
  179. package/dist/tests/globalSetupVitest.js +29 -0
  180. package/dist/tests/globalSetupVitest.js.map +1 -0
  181. package/dist/tests/setupVitest.d.ts +1 -0
  182. package/dist/tests/setupVitest.js +99 -0
  183. package/dist/tests/setupVitest.js.map +1 -0
  184. package/package.json +19 -10
  185. package/Cli.js +0 -21
  186. package/cluster.js +0 -25
  187. package/commands/.gitkeep +0 -0
  188. package/commands/CreateUser.js +0 -106
  189. package/commands/Documentation.js +0 -17
  190. package/commands/DropIndex.js +0 -38
  191. package/commands/GenerateRandomBytes.js +0 -21
  192. package/commands/GetOpenApiJson.js +0 -336
  193. package/commands/SyncIndexes.js +0 -40
  194. package/commands/migration/Create.js +0 -72
  195. package/commands/migration/Migrate.js +0 -56
  196. package/config/auth.js +0 -9
  197. package/config/http.js +0 -9
  198. package/config/i18n.js +0 -12
  199. package/config/ipDetector.js +0 -14
  200. package/config/log.js +0 -22
  201. package/config/mongo.js +0 -3
  202. package/config/rateLimiter.js +0 -16
  203. package/config/redis.js +0 -4
  204. package/config/validate.js +0 -3
  205. package/controllers/Auth.js +0 -201
  206. package/controllers/Home.js +0 -28
  207. package/controllers/index.js +0 -66
  208. package/eslint.config.js +0 -68
  209. package/folderConfig.js +0 -13
  210. package/helpers/files.js +0 -76
  211. package/helpers/logger.js +0 -16
  212. package/helpers/redis/clearNamespace.js +0 -14
  213. package/index.js +0 -8
  214. package/jsconfig.json +0 -9
  215. package/locales/en/translation.json +0 -27
  216. package/locales/ru/translation.json +0 -27
  217. package/migrations/.gitkeep +0 -0
  218. package/models/Lock.js +0 -107
  219. package/models/Migration.js +0 -15
  220. package/models/Sequence.js +0 -22
  221. package/models/User.js +0 -280
  222. package/modules/AbstractCommand.d.ts +0 -50
  223. package/modules/AbstractCommand.js +0 -52
  224. package/modules/AbstractConnector.js +0 -9
  225. package/modules/AbstractController.d.ts +0 -55
  226. package/modules/AbstractController.js +0 -400
  227. package/modules/AbstractModel.d.ts +0 -48
  228. package/modules/AbstractModel.js +0 -92
  229. package/modules/Base.d.ts +0 -37
  230. package/modules/Base.js +0 -64
  231. package/modules/BaseCli.js +0 -162
  232. package/server.d.ts +0 -100
  233. package/server.js +0 -439
  234. package/services/cache/Cache.d.ts +0 -35
  235. package/services/cache/Cache.js +0 -124
  236. package/services/documentation/DocumentationGenerator.js +0 -169
  237. package/services/http/HttpServer.js +0 -89
  238. package/services/http/middleware/AbstractMiddleware.js +0 -51
  239. package/services/http/middleware/Auth.js +0 -20
  240. package/services/http/middleware/Cors.js +0 -46
  241. package/services/http/middleware/GetUserByToken.js +0 -47
  242. package/services/http/middleware/I18n.js +0 -117
  243. package/services/http/middleware/IpDetector.js +0 -59
  244. package/services/http/middleware/Pagination.js +0 -57
  245. package/services/http/middleware/PrepareAppInfo.js +0 -18
  246. package/services/http/middleware/RateLimiter.js +0 -134
  247. package/services/http/middleware/RequestLogger.js +0 -22
  248. package/services/http/middleware/RequestParser.js +0 -40
  249. package/services/http/middleware/Role.js +0 -29
  250. package/services/messaging/email/resources/.gitkeep +0 -1
  251. package/services/messaging/email/templates/.gitkeep +0 -0
  252. package/services/messaging/email/templates/recovery/html.pug +0 -8
  253. package/services/messaging/email/templates/recovery/subject.pug +0 -2
  254. package/services/messaging/email/templates/recovery/text.pug +0 -3
  255. package/services/messaging/email/templates/verification/html.pug +0 -10
  256. package/services/messaging/email/templates/verification/subject.pug +0 -1
  257. package/services/messaging/email/templates/verification/text.pug +0 -1
  258. package/services/validate/ValidateService.js +0 -157
  259. package/services/validate/drivers/AbstractValidator.js +0 -37
  260. package/services/validate/drivers/CustomValidator.js +0 -51
  261. package/services/validate/drivers/YupValidator.js +0 -103
  262. package/tests/globalSetupVitest.js +0 -35
  263. package/tests/setup.js +0 -120
  264. package/tests/setupVitest.js +0 -111
  265. package/types/Expand.d.ts +0 -11
  266. package/types/ICommandArguments.d.ts +0 -41
  267. package/types/TFoldersConfig.d.ts +0 -20
  268. package/views/404.pug +0 -3
  269. package/views/home.pug +0 -3
  270. package/views/layouts/base.pug +0 -39
  271. package/vitest.config.js +0 -17
@@ -1,106 +0,0 @@
1
- import AbstractCommand from '../modules/AbstractCommand.js';
2
-
3
- // Example: node src/cli createuser --email=somemail@gmail.com --password=somePassword --roles=user,admin,someOtherRoles
4
- class CreateUser extends AbstractCommand {
5
- static get description() {
6
- return 'Create user in a database';
7
- }
8
-
9
- /**
10
- * You able to add command arguments for parsing there.
11
- * @returns {import("../types/ICommandArguments.js").ICommandArguments}
12
- */
13
- static get commandArguments() {
14
- return {
15
- id: {
16
- type: 'string',
17
- description: 'User id to find user',
18
- },
19
- email: {
20
- type: 'string',
21
- description: 'User id to find/create user',
22
- },
23
- password: {
24
- type: 'string',
25
- description: 'New password for user',
26
- },
27
- roles: {
28
- type: 'string',
29
- description:
30
- 'User roles comma separated string (--roles=user,admin,someOtherRoles)',
31
- },
32
- update: {
33
- type: 'boolean',
34
- default: false,
35
- description: 'Update user if it exists',
36
- },
37
- };
38
- }
39
-
40
- async run() {
41
- const User = this.app.getModel('User');
42
- const { id, email, password, roles, update } = this.args;
43
-
44
- if (!email && !id) {
45
- this.logger.error('Input validation failded');
46
- this.logger.error('Please add "email" or "id" variables');
47
- return false;
48
- }
49
-
50
- let user;
51
-
52
- if (id) {
53
- user = await User.findOne({ _id: id });
54
- } else if (email) {
55
- user = await User.findOne({ email });
56
- }
57
-
58
- if (user && !update) {
59
- this.logger.error(
60
- 'We are found a user in database. But "update" option is not providing. Exitin',
61
- );
62
- return false;
63
- }
64
-
65
- if (!user && !password) {
66
- this.logger.error(
67
- 'For a new user we alway asking for a password. Please provide it and rerun command',
68
- );
69
- return false;
70
- }
71
-
72
- if (!user && !email) {
73
- this.logger.error(
74
- 'For a new user we alway asking for a email. Please provide it and rerun command',
75
- );
76
- return false;
77
- }
78
-
79
- if (!user) {
80
- user = new User();
81
- }
82
-
83
- if (password) {
84
- user.password = password;
85
- }
86
- if (email) {
87
- user.email = email;
88
- }
89
-
90
- if (roles) {
91
- user.roles = roles.split(',');
92
- }
93
-
94
- await user.save();
95
-
96
- await user.generateToken();
97
-
98
- this.logger.info(
99
- `User was created/updated ${JSON.stringify(user, null, 4)}`,
100
- );
101
-
102
- return user;
103
- }
104
- }
105
-
106
- export default CreateUser;
@@ -1,17 +0,0 @@
1
- import AbstractCommand from '../modules/AbstractCommand.js';
2
- import ControllerManager from '../controllers/index.js';
3
-
4
- class Documentation extends AbstractCommand {
5
- static get description() {
6
- return 'Generate documentation (internal)';
7
- }
8
-
9
- async run() {
10
- const CM = new ControllerManager(this.app);
11
- this.app.documentation = [];
12
- await CM.initControllers();
13
- return this.app.documentation;
14
- }
15
- }
16
-
17
- export default Documentation;
@@ -1,38 +0,0 @@
1
- import AbstractCommand from '../modules/AbstractCommand.js';
2
-
3
- class DropIndex extends AbstractCommand {
4
- static get description() {
5
- return 'Drop indexes of model';
6
- }
7
-
8
- /**
9
- * You able to add command arguments for parsing there.
10
- * @returns {import("../types/ICommandArguments.js").ICommandArguments}
11
- */
12
- static get commandArguments() {
13
- return {
14
- model: {
15
- type: 'string',
16
- description: 'Model name',
17
- required: true,
18
- },
19
- };
20
- }
21
-
22
- async run() {
23
- const Model = this.app.getModel(this.args.model);
24
-
25
- if (!Model) {
26
- this.logger.error('Not able to find model');
27
- return false;
28
- }
29
-
30
- await Model.collection.dropIndexes();
31
-
32
- this.logger.info('Success');
33
-
34
- return true;
35
- }
36
- }
37
-
38
- export default DropIndex;
@@ -1,21 +0,0 @@
1
- import { randomBytes } from 'node:crypto';
2
- import AbstractCommand from '../modules/AbstractCommand.js';
3
-
4
- class GenerateRandomBytes extends AbstractCommand {
5
- static get description() {
6
- return 'Generate random bytes ising randomBytes from node:crypto';
7
- }
8
-
9
- static isShouldInitModels = false;
10
-
11
- async run() {
12
- const sizes = [16, 32, 64, 128, 256];
13
- for (const size of sizes) {
14
- const bytes = randomBytes(size).toString('hex');
15
- this.logger.info(`${size} bytes: ${bytes}`);
16
- }
17
- return true;
18
- }
19
- }
20
-
21
- export default GenerateRandomBytes;
@@ -1,336 +0,0 @@
1
- import { promises as fs } from 'node:fs';
2
- import AbstractCommand from '../modules/AbstractCommand.js';
3
-
4
- /**
5
- * Command for generate documentation json file openApi
6
- */
7
- class GetOpenApiJson extends AbstractCommand {
8
- static get description() {
9
- return 'Generate documentation (openApi) ';
10
- }
11
- /**
12
- * You able to add command arguments for parsing there.
13
- * @returns {import("../types/ICommandArguments.js").ICommandArguments}
14
- */
15
- static get commandArguments() {
16
- return {
17
- output: {
18
- type: 'string',
19
- description: 'Output file path',
20
- },
21
- };
22
- }
23
-
24
- async run() {
25
- const { myDomain } = this.app.getConfig('http');
26
- let jsonFile = process.env.npm_package_json;
27
- if (!jsonFile) {
28
- jsonFile = `${process.env.PWD}/package.json`;
29
- }
30
-
31
- try {
32
- jsonFile = JSON.parse(await fs.readFile(jsonFile, 'utf8'));
33
- } catch {
34
- this.logger.error(
35
- 'No npm package detected. Please start this command via NPM as it depends on package.json',
36
- );
37
- }
38
-
39
- if (!jsonFile) {
40
- jsonFile = {
41
- name: 'UNDETECTD PROJECT',
42
- description: 'UNDETECTD PROJECT DECCRIPTION',
43
- version: '0.0.0-undetrcted',
44
- author: {
45
- email: 'none@example.com',
46
- },
47
- };
48
- }
49
-
50
- if (!jsonFile.author) {
51
- jsonFile.author = 'none@example.com';
52
- }
53
-
54
- const openApi = {
55
- openapi: '3.0.0',
56
- info: {
57
- title: jsonFile.name,
58
- description: jsonFile.description,
59
- contact: {
60
- email: jsonFile.author.email,
61
- },
62
- version: jsonFile.version,
63
- },
64
- servers: [
65
- {
66
- url: 'http://localhost:3300',
67
- description: 'Localhost',
68
- },
69
- {
70
- url: myDomain,
71
- description: 'Domain from config',
72
- },
73
- ],
74
- };
75
-
76
- const baseDocumentation = await this.app.runCliCommand('documentation');
77
-
78
- if (!baseDocumentation) {
79
- throw new Error('Problems with basic documenation generation');
80
- }
81
-
82
- openApi.components = {};
83
- openApi.components.securitySchemes = {};
84
-
85
- openApi.tags = [];
86
-
87
- for (const controller of baseDocumentation) {
88
- const controllerName = controller.contollerName.split('/')[0];
89
- if (!openApi.tags.find((tag) => tag.name === controllerName)) {
90
- openApi.tags.push({
91
- name: controllerName,
92
- description: '',
93
- });
94
- }
95
- }
96
-
97
- openApi.paths = {};
98
-
99
- const permissionWithRoutes = {};
100
- for (const controller of baseDocumentation) {
101
- for (const route of controller.routesInfo) {
102
- const routeInfo = route[Object.keys(route)?.[0]];
103
- const middlewares = [
104
- ...routeInfo.controllerMiddlewares,
105
- ...routeInfo.routeMiddlewares,
106
- ];
107
-
108
- const securitySchemaNames = [];
109
-
110
- permissionWithRoutes[Object.keys(route)?.[0]] = [];
111
-
112
- if (middlewares?.length) {
113
- for (const middleware of middlewares) {
114
- if (middleware?.authParams?.length) {
115
- for (const authParam of middleware.authParams) {
116
- const { permissions, ...mainFields } = authParam;
117
- const fullName = authParam.name;
118
- if (permissions) {
119
- permissionWithRoutes[Object.keys(route)?.[0]].push(
120
- permissions,
121
- );
122
- }
123
-
124
- if (!openApi.components.securitySchemes[fullName]) {
125
- openApi.components.securitySchemes[fullName] = mainFields;
126
- }
127
-
128
- securitySchemaNames.push({
129
- [fullName]: [],
130
- });
131
- }
132
- }
133
- }
134
- }
135
-
136
- let routeName = Object.keys(route)[0];
137
- if (routeName === '/') {
138
- continue;
139
- }
140
-
141
- if (routeName.slice(-1) === '/') {
142
- routeName = routeName.substring(0, routeName.length - 1);
143
- }
144
-
145
- const partsRoute = routeName.split('/');
146
-
147
- const newRoute = [];
148
- const routeParameters = [];
149
- for (const routeDetail of partsRoute) {
150
- let routeCopy = routeDetail;
151
-
152
- if (routeDetail.startsWith(':')) {
153
- const routeChange = routeCopy.split('');
154
- routeChange[0] = '{';
155
- routeChange.push('}');
156
- routeCopy = routeChange.join('');
157
- routeParameters.push(routeCopy.replace(/^.|.$/g, ''));
158
- }
159
-
160
- newRoute.push(routeCopy);
161
- }
162
-
163
- routeName = newRoute.join('/');
164
-
165
- if (!openApi.paths[routeName]) {
166
- openApi.paths[routeName] = {};
167
- }
168
-
169
- const routeDescription =
170
- route[Object.keys(route)[0]]?.description || 'empty description';
171
- const permissions =
172
- permissionWithRoutes[Object.keys(route)[0]][
173
- permissionWithRoutes[Object.keys(route)[0]].length - 1
174
- ];
175
- const routeDescriptionWithPermissions = `${
176
- permissions || ''
177
- } ${routeDescription}`;
178
- const methodName = route[Object.keys(route)[0]].method.toLowerCase();
179
- const routeTitle = route[Object.keys(route)[0]].name;
180
-
181
- const routeFields = route[Object.keys(route)[0]].fields;
182
- const routeQueryFields = route[Object.keys(route)[0]].queryFields;
183
-
184
- if (!openApi.paths[routeName][methodName]) {
185
- openApi.paths[routeName][methodName] = {};
186
- }
187
-
188
- openApi.paths[routeName][methodName].tags = [];
189
-
190
- openApi.paths[routeName][methodName].tags.push(
191
- controller.contollerName.split('/')[0],
192
- );
193
-
194
- openApi.paths[routeName][methodName].summary = routeTitle;
195
- openApi.paths[routeName][methodName].description =
196
- routeDescriptionWithPermissions;
197
- openApi.paths[routeName][methodName].parameters = [];
198
- openApi.paths[routeName][methodName].security = securitySchemaNames;
199
-
200
- openApi.paths[routeName][methodName].responses = {
201
- 200: {
202
- description: 'Successfully',
203
- },
204
- 201: {
205
- description: 'The resource was created successfully',
206
- },
207
- 400: {
208
- description: 'There is a syntax error in the request',
209
- },
210
- 401: {
211
- description:
212
- 'Authentication is required to access the requested resource',
213
- },
214
- 404: {
215
- description:
216
- 'The server accepted the request, but did not find the corresponding resource at the specified URI',
217
- },
218
- };
219
-
220
- for (const queryField of routeQueryFields) {
221
- openApi.paths[routeName][methodName].parameters.push({
222
- name: queryField.name,
223
- in: 'query',
224
- required: queryField?.required,
225
- schema: {
226
- type: queryField.type,
227
- },
228
- });
229
- }
230
-
231
- for (const routeField of routeParameters) {
232
- openApi.paths[routeName][methodName].parameters.push({
233
- name: routeField,
234
- in: 'path',
235
- required: true,
236
- schema: {
237
- type: 'string',
238
- },
239
- });
240
- }
241
-
242
- if (routeFields.length) {
243
- const groupBodyFields = {};
244
- const requiredFields = [];
245
- let isMultipartFormaData = false;
246
- for (const field of routeFields) {
247
- if (field.required) {
248
- requiredFields.push(field.name);
249
- }
250
-
251
- switch (field.type) {
252
- case 'object':
253
- groupBodyFields[field.name] = {
254
- properties: {},
255
- };
256
-
257
- for (const objField of field.fields) {
258
- groupBodyFields[field.name].properties[objField.name] = {
259
- // fields file has mixed type but openApi doesnt have this type
260
- type: objField.type === 'mixed' ? 'string' : objField.type,
261
- };
262
- }
263
-
264
- break;
265
-
266
- case 'array':
267
- groupBodyFields[field.name] = {
268
- items: {
269
- type: field.innerType,
270
- },
271
- };
272
- break;
273
-
274
- case 'lazy':
275
- groupBodyFields[field.name] = {
276
- oneOf: [
277
- {
278
- type: 'object',
279
- },
280
- {
281
- type: 'string',
282
- },
283
- ],
284
- };
285
- break;
286
-
287
- case 'file':
288
- groupBodyFields[field.name] = {
289
- type: 'string',
290
- format: 'binary',
291
- };
292
- isMultipartFormaData = true;
293
- break;
294
- default:
295
- groupBodyFields[field.name] = {
296
- type: field.type,
297
- };
298
- }
299
- }
300
-
301
- const contentType = isMultipartFormaData
302
- ? 'multipart/form-data'
303
- : 'application/json';
304
-
305
- openApi.paths[routeName][methodName].requestBody = {
306
- content: {
307
- [contentType]: {
308
- schema: {
309
- type: 'object',
310
- properties: groupBodyFields,
311
- },
312
- },
313
- },
314
- };
315
-
316
- if (requiredFields.length) {
317
- openApi.paths[routeName][methodName].requestBody.content[
318
- contentType
319
- ].schema.required = requiredFields;
320
- }
321
- }
322
- }
323
- }
324
-
325
- const result = JSON.stringify(openApi);
326
-
327
- if (this.args.output) {
328
- await fs.writeFile(this.args.output, result);
329
- this.logger.info(`Output to: ${this.args.output}`);
330
- }
331
-
332
- return result;
333
- }
334
- }
335
-
336
- export default GetOpenApiJson;
@@ -1,40 +0,0 @@
1
- import path from 'node:path';
2
- import * as url from 'node:url';
3
- import AbstractCommand from '../modules/AbstractCommand.js';
4
-
5
- class SyncIndexes extends AbstractCommand {
6
- async run() {
7
- const dirname = url.fileURLToPath(new URL('.', import.meta.url));
8
- const files = await this.getFilesPathWithInheritance(
9
- path.join(dirname, '/../models'),
10
- this.app.foldersConfig.models,
11
- );
12
- let models = [];
13
-
14
- for (const file of files) {
15
- models.push(path.basename(file.file, path.extname(file.file)));
16
- }
17
- models = models.sort();
18
- this.logger.info(`Total found ${models.length} models`);
19
-
20
- for (const modelName of models) {
21
- const Model = this.app.getModel(modelName);
22
- // eslint-disable-next-line no-await-in-loop
23
- const removedIndexes = await Model.syncIndexes(); // await in loop not a bug. Lets do one by one
24
- if (removedIndexes.length) {
25
- this.logger.info(
26
- `Model - ${modelName} removed indexes: ${removedIndexes}`,
27
- );
28
- } else {
29
- this.logger.info(`Model - ${modelName} NO removed indexes`);
30
- }
31
- }
32
- return true;
33
- }
34
-
35
- static get description() {
36
- return 'Synchronize indexes defined in models with a real one indexed on the database. Command will remove all indexes from the database that do not exist on model OR have different parameters. Then it will create a new indexes ';
37
- }
38
- }
39
-
40
- export default SyncIndexes;
@@ -1,72 +0,0 @@
1
- import path from 'node:path';
2
- import { promises as fs } from 'node:fs';
3
- import AbstractCommand from '../../modules/AbstractCommand.js';
4
-
5
- class CreateMigration extends AbstractCommand {
6
- static get description() {
7
- return 'Create new migration';
8
- }
9
-
10
- /**
11
- * You able to add command arguments for parsing there.
12
- * @returns {import("../../types/ICommandArguments.js").ICommandArguments}
13
- */
14
- static get commandArguments() {
15
- return {
16
- name: {
17
- type: 'string',
18
- description: 'Migration name',
19
- required: true,
20
- },
21
- };
22
- }
23
-
24
- async run() {
25
- if (this.args.name.match(/^\d/)) {
26
- this.logger.error('Command cant start from nubmer');
27
- return false;
28
- }
29
- const fileName = `${Date.now()}_${CreateMigration.camelSentence(
30
- this.args.name,
31
- )}.js`;
32
-
33
- const fileContent = CreateMigration.getTemplate(
34
- CreateMigration.camelSentence(this.args.name),
35
- );
36
-
37
- await fs.writeFile(
38
- path.join(this.app.foldersConfig.migrations, fileName),
39
- fileContent,
40
- );
41
- this.logger.info(`Migration created ${fileName}`);
42
- return true;
43
- }
44
-
45
- static camelSentence(str) {
46
- return ` ${str}`
47
- .toLowerCase()
48
- .replace(/[^a-zA-Z0-9]+(.)/g, (match, chr) => chr.toUpperCase());
49
- }
50
-
51
- static getTemplate(name) {
52
- return `/* eslint-disable class-methods-use-this */
53
-
54
- import Base from '@adaptivestone/framework/modules/Base.js';
55
-
56
- class ${name} extends Base {
57
- async up() {
58
- // put here your mirgation up logic
59
- // const YourModel = this.app.getModel('ModelName');
60
- }
61
-
62
- async down() {
63
- // put here your mirgation down logic
64
- }
65
- }
66
-
67
- export default ${name};
68
- `;
69
- }
70
- }
71
-
72
- export default CreateMigration;
@@ -1,56 +0,0 @@
1
- import * as url from 'node:url';
2
- import path from 'node:path';
3
- import AbstractCommand from '../../modules/AbstractCommand.js';
4
-
5
- class Migrate extends AbstractCommand {
6
- static get description() {
7
- return 'Run all pending migrations';
8
- }
9
-
10
- async run() {
11
- const dirname = url.fileURLToPath(new URL('.', import.meta.url));
12
-
13
- const files = await this.getFilesPathWithInheritance(
14
- path.join(dirname, '/../../migrations'),
15
- this.app.foldersConfig.migrations,
16
- );
17
- files.sort(
18
- (a, b) => Number(a.file.split('_')[0]) - Number(b.file.split('_')[0]),
19
- );
20
- const MigrationModel = this.app.getModel('Migration');
21
- const lastMigration = await MigrationModel.findOne({})
22
- .sort({ createdAt: -1 })
23
- .exec();
24
-
25
- let migrations = files;
26
-
27
- if (lastMigration) {
28
- const lastMigrationTime = Number(
29
- lastMigration.migrationFile.split('_')[0],
30
- );
31
- migrations = files.filter(
32
- (val) => Number(val.file.split('_')[0]) > lastMigrationTime,
33
- );
34
- }
35
-
36
- for (const migration of migrations) {
37
- this.logger.info(`=== Start migration ${migration.file} ===`);
38
- // eslint-disable-next-line no-await-in-loop
39
- const { default: MigrationCommand } = await import(migration.path);
40
- const migrationCommand = new MigrationCommand(this.app);
41
- // eslint-disable-next-line no-await-in-loop
42
- await migrationCommand.up();
43
- // eslint-disable-next-line no-await-in-loop
44
- await MigrationModel.create({
45
- migrationFile: migration.file,
46
- });
47
- }
48
-
49
- this.logger.info(
50
- `=== Migration Finished. Migrated ${migrations.length} files ===`,
51
- );
52
- return true;
53
- }
54
- }
55
-
56
- export default Migrate;
package/config/auth.js DELETED
@@ -1,9 +0,0 @@
1
- export default {
2
- hashRounds: 64,
3
- saltSecret:
4
- process.env.AUTH_SALT ||
5
- console.error(
6
- 'AUTH_SALT is not defined. You can "npm run cli generateRandomBytes" and use it',
7
- ),
8
- isAuthWithVefificationFlow: true,
9
- };