minimonolith 0.24.1 → 0.25.4

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 (153) hide show
  1. package/README.md +209 -208
  2. package/api/api.js +5 -0
  3. package/api/getModels/handler.js +5 -0
  4. package/api/getModels/out.js +3 -0
  5. package/api/getNewAPI/handler.js +53 -0
  6. package/api/getNewAPI/in.js +7 -0
  7. package/api/getNewAPI/out.js +3 -0
  8. package/api/getORM/handler.js +5 -0
  9. package/api/getORM/out.js +3 -0
  10. package/api/getSchemas/handler.js +5 -0
  11. package/api/getSchemas/out.js +3 -0
  12. package/api/getService/handler.js +8 -0
  13. package/api/getService/in.js +6 -0
  14. package/api/getService/out.js +3 -0
  15. package/api/getServices/handler.js +5 -0
  16. package/api/getServices/out.js +3 -0
  17. package/api/getSyncedHandler/handler.js +40 -0
  18. package/api/getSyncedHandler/in.js +3 -0
  19. package/api/getSyncedHandler/out.js +3 -0
  20. package/api/postModel/handler.js +8 -0
  21. package/api/postModel/in.js +6 -0
  22. package/api/postModule/handler.js +31 -0
  23. package/api/postModule/in.js +7 -0
  24. package/api/postORM/handler.js +7 -0
  25. package/api/postORM/in.js +5 -0
  26. package/api/postRawModule/handler.js +9 -0
  27. package/api/postRawModule/in.js +9 -0
  28. package/api/postRoute/handler.js +9 -0
  29. package/api/postRoute/in.js +7 -0
  30. package/api/postSchema/handler.js +8 -0
  31. package/api/postSchema/in.js +6 -0
  32. package/api/services.js +15 -0
  33. package/{src/autotest/getMethodTest/index.js → autotest/getMethodTest/handler.js} +14 -12
  34. package/autotest/getMethodTest/in.js +3 -0
  35. package/autotest/getMethodTest/out.js +3 -0
  36. package/{src/autotest → autotest}/getTestServerResponse/index.js +14 -14
  37. package/autotest/services.js +1 -0
  38. package/control/get/handler.js +8 -0
  39. package/control/get/in.js +6 -0
  40. package/control/get/out.js +3 -0
  41. package/control/services.js +1 -0
  42. package/database/post/handler.js +24 -0
  43. package/database/post/in.js +12 -0
  44. package/database/postConnection/handler.js +27 -0
  45. package/database/postConnection/in.js +5 -0
  46. package/database/postConnection/out.js +3 -0
  47. package/database/services.js +1 -0
  48. package/environment/getDBEnvVars/handler.js +6 -0
  49. package/environment/getDBEnvVars/in.js +3 -0
  50. package/environment/getDBEnvVars/out.js +3 -0
  51. package/environment/getENVEnvVars/handler.js +7 -0
  52. package/environment/getENVEnvVars/in.js +3 -0
  53. package/environment/getENVEnvVars/out.js +3 -0
  54. package/environment/postEnvFile/handler.js +20 -0
  55. package/environment/postEnvFile/in.js +6 -0
  56. package/{src/environment → environment}/postTestEnvironment/index.js +6 -6
  57. package/environment/services.js +5 -0
  58. package/{src/error → error}/index.js +4 -4
  59. package/{src/error → error}/postCompiletime/index.js +13 -13
  60. package/{src/error → error}/postRuntime/index.js +7 -7
  61. package/health/post/handler.js +14 -0
  62. package/health/services.js +1 -0
  63. package/index.js +23 -15
  64. package/{src/log → log}/index.js +5 -5
  65. package/{src/log → log}/post/index.js +3 -3
  66. package/{src/log → log}/postError/index.js +3 -3
  67. package/{src/log → log}/postQA/index.js +3 -3
  68. package/model/getSynced/handler.js +28 -0
  69. package/model/post/handler.js +17 -0
  70. package/model/post/in.js +6 -0
  71. package/model/services.js +1 -0
  72. package/modules.js +19 -0
  73. package/package.json +33 -32
  74. package/{src/server → server}/getNodejsServerHandler/index.js +70 -68
  75. package/server/getServerFactory/handler.js +17 -0
  76. package/server/getServerFactory/in.js +8 -0
  77. package/server/getServerFactory/out.js +3 -0
  78. package/server/services.js +1 -0
  79. package/service/getParsedCode/handler.js +22 -0
  80. package/service/getParsedCode/in.js +6 -0
  81. package/service/getParsedCode/out.js +6 -0
  82. package/service/getParsedEvent/handler.js +12 -0
  83. package/service/getParsedEvent/in.js +5 -0
  84. package/service/getParsedEvent/out.js +6 -0
  85. package/{src/method/getResponseCode/index.js → service/getResponseCode/handler.js} +11 -9
  86. package/service/getResponseCode/in.js +3 -0
  87. package/service/getResponseCode/out.js +3 -0
  88. package/service/getRouteCode/handler.js +15 -0
  89. package/service/getRouteCode/in.js +6 -0
  90. package/service/getRouteCode/out.js +3 -0
  91. package/service/getType/handler.js +11 -0
  92. package/service/getType/in.js +5 -0
  93. package/service/getType/out.js +3 -0
  94. package/{src/method → service}/postResponse/index.js +13 -13
  95. package/service/postRoute/handler.js +82 -0
  96. package/service/postRoute/in.js +6 -0
  97. package/service/services.js +9 -0
  98. package/validation/getParsedAsync/handler.js +38 -0
  99. package/validation/getParsedAsync/in.js +9 -0
  100. package/validation/getParsedAsync/out.js +6 -0
  101. package/validation/services.js +1 -0
  102. package/yarn-error.log +4104 -0
  103. package/zdb/components.js +1 -0
  104. package/zdb/getAssertExists/handler.js +16 -0
  105. package/zdb/getAssertExists/in.js +6 -0
  106. package/zdb/getAssertExists/out.js +3 -0
  107. package/zdb/getAssertNotExists/handler.js +16 -0
  108. package/zdb/getAssertNotExists/in.js +6 -0
  109. package/zdb/getAssertNotExists/out.js +3 -0
  110. package/zdb/getAssertSafeInt/handler.js +15 -0
  111. package/zdb/getAssertSafeInt/in.js +6 -0
  112. package/zdb/getAssertSafeInt/out.js +3 -0
  113. package/src/api/get/index.js +0 -19
  114. package/src/api/getNewAPI/index.js +0 -14
  115. package/src/api/getSyncedHandler/index.js +0 -24
  116. package/src/api/index.js +0 -4
  117. package/src/api/postService/index.js +0 -34
  118. package/src/autotest/getMethodTest/back.index.js +0 -29
  119. package/src/autotest/index.js +0 -3
  120. package/src/control/get/index.js +0 -3
  121. package/src/control/index.js +0 -3
  122. package/src/database/index.js +0 -4
  123. package/src/database/post/index.js +0 -28
  124. package/src/database/postConnection/index.js +0 -25
  125. package/src/environment/getDBEnvVars/index.js +0 -4
  126. package/src/environment/getENVEnvVars/index.js +0 -4
  127. package/src/environment/index.js +0 -4
  128. package/src/environment/postEnvFile/index.js +0 -13
  129. package/src/event/getParsedEvent/index.js +0 -9
  130. package/src/event/index.js +0 -3
  131. package/src/health/index.js +0 -3
  132. package/src/health/post/index.js +0 -10
  133. package/src/method/getParsedCode/index.js +0 -13
  134. package/src/method/getRouteCode/index.js +0 -12
  135. package/src/method/getType/index.js +0 -9
  136. package/src/method/index.js +0 -7
  137. package/src/method/post/index.js +0 -56
  138. package/src/middleware/index.js +0 -4
  139. package/src/middleware/postCors/index.js +0 -20
  140. package/src/middleware/postError/index.js +0 -10
  141. package/src/model/getSynced/index.js +0 -22
  142. package/src/model/index.js +0 -4
  143. package/src/model/post/index.js +0 -11
  144. package/src/path/getProjectRoot/index.js +0 -14
  145. package/src/path/index.js +0 -3
  146. package/src/server/getServerFactory/index.js +0 -14
  147. package/src/server/index.js +0 -3
  148. package/src/validation/dbValidation.js +0 -33
  149. package/src/validation/get/index.js +0 -16
  150. package/src/validation/getOptionalObject/index.js +0 -8
  151. package/src/validation/index.js +0 -8
  152. package/src/validation/postError/index.js +0 -29
  153. /package/{src/middleware/postCors → api}/corsHeaders.js +0 -0
@@ -0,0 +1,31 @@
1
+ import fs from 'fs';
2
+ import url from 'url'
3
+ import path from 'path';
4
+
5
+ import { PATH_MODULE } from '@minimonolith/lib';
6
+
7
+ export default async ({ body, SERVICES }) => {
8
+ const moduleName = body.moduleName;
9
+ const srcFolder = body.srcFolder;
10
+ const modulesFolder = body.modulesFolder;
11
+
12
+ const projectRoot = PATH_MODULE.getProjectRoot(
13
+ import.meta.url, modulesFolder);
14
+ const projectRootPath = projectRoot + path.sep;
15
+ const projectRelativeServicePath = path.join('.',
16
+ srcFolder, moduleName) + path.sep;
17
+ //console.log('postmodule', srcFolder, projectRelativeServicePath);
18
+
19
+ await SERVICES.api.postRawModule.handler({
20
+ moduleName, srcFolder, modulesFolder });
21
+ const moduleURL = new URL(projectRelativeServicePath, projectRootPath);
22
+ //console.log('postmodule', moduleURL.href);
23
+ await SERVICES.model.post.handler({ moduleName, moduleURL });
24
+
25
+ const apiServices = await SERVICES.api.getServices.handler();
26
+ for (let serviceName in apiServices[moduleName]) {
27
+ const serviceCode = apiServices[moduleName][serviceName].code;
28
+ //console.log('POST_ROUTE', moduleName, serviceCode, apiServices);
29
+ await SERVICES.service.postRoute.handler({ moduleName, serviceCode });
30
+ }
31
+ };
@@ -0,0 +1,7 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => ({
4
+ moduleName: z.string(),
5
+ srcFolder: z.string().default(''),
6
+ modulesFolder: z.string().default('node_modules'),
7
+ });
@@ -0,0 +1,7 @@
1
+ import API from '../api.js';
2
+
3
+ export default async ({ body }) => {
4
+ const ORM = body.ORM;
5
+
6
+ API().ORM = ORM;
7
+ }
@@ -0,0 +1,5 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => ({
4
+ ORM: z.unknown(),
5
+ });
@@ -0,0 +1,9 @@
1
+ import API from '../api.js';
2
+
3
+ export default async ({ body }) => {
4
+ const moduleName = body.moduleName;
5
+ const srcFolder = body.srcFolder;
6
+ const modulesFolder = body.modulesFolder;
7
+
8
+ await API().LIB.postModule(moduleName, srcFolder, modulesFolder);
9
+ };
@@ -0,0 +1,9 @@
1
+ import path from 'path';
2
+
3
+ import { z } from '@minimonolith/lib';
4
+
5
+ export default () => ({
6
+ moduleName: z.string(),
7
+ srcFolder: z.string().default(''),
8
+ modulesFolder: z.string().default('node_modules' + path.sep),
9
+ });
@@ -0,0 +1,9 @@
1
+ import API from '../api.js';
2
+
3
+ export default ({ body }) => {
4
+ const method = body.method;
5
+ const route = body.route;
6
+ const handler = body.handler;
7
+
8
+ API().ROUTES[method](route, handler);
9
+ }
@@ -0,0 +1,7 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => ({
4
+ method: z.string(),
5
+ route: z.string(),
6
+ handler: z.function(),
7
+ })
@@ -0,0 +1,8 @@
1
+ import API from '../api.js';
2
+
3
+ export default async ({ body }) => {
4
+ const moduleName = body.moduleName;
5
+ const moduleSchema = body.moduleSchema;
6
+
7
+ API().SCHEMAS[moduleName] = moduleSchema;
8
+ }
@@ -0,0 +1,6 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => ({
4
+ moduleName: z.string(),
5
+ moduleSchema: z.unknown(),
6
+ });
@@ -0,0 +1,15 @@
1
+ export default [
2
+ 'getNewAPI',
3
+ 'getSyncedHandler',
4
+ 'postModule',
5
+ 'getService',
6
+ 'getServices',
7
+ 'getORM',
8
+ 'getModels',
9
+ 'getSchemas',
10
+ 'postRoute',
11
+ 'postRawModule',
12
+ 'postSchema',
13
+ 'postORM',
14
+ 'postModel',
15
+ ];
@@ -1,12 +1,14 @@
1
- export default async server => {
2
- const fetch = (await import('cross-fetch')).default;
3
-
4
- return async ({ path, method, expectedCode, headers, body }) => {
5
-
6
- const port = server.address().port
7
- const url = `http://localhost:${port}${path}`;
8
-
9
- const response = await fetch(url, { method, headers, body });
10
- expect(response.status).toBe(expectedCode);
11
- };
12
- };
1
+ export default async ({ body }) => {
2
+ const server = body;
3
+
4
+ const fetch = (await import('cross-fetch')).default;
5
+
6
+ return async ({ path, method, expectedCode, headers, body }) => {
7
+
8
+ const port = server.address().port
9
+ const url = `http://localhost:${port}${path}`;
10
+
11
+ const response = await fetch(url, { method, headers, body });
12
+ expect(response.status).toBe(expectedCode);
13
+ };
14
+ };
@@ -0,0 +1,3 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => z.unknown();
@@ -0,0 +1,3 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => z.function();
@@ -1,14 +1,14 @@
1
- import http from 'http';
2
-
3
- export default () => {
4
- let resolveAsyncResult;
5
- const asyncResultPromise = new Promise(resolve => { resolveAsyncResult = resolve; });
6
-
7
- const res = {
8
- statusCode: null,
9
- asyncResult: () => asyncResultPromise,
10
- end: body => { res.body = body; resolveAsyncResult(res); },
11
- };
12
-
13
- return res;
14
- };
1
+ import http from 'http';
2
+
3
+ export default () => {
4
+ let resolveAsyncResult;
5
+ const asyncResultPromise = new Promise(resolve => { resolveAsyncResult = resolve; });
6
+
7
+ const res = {
8
+ statusCode: null,
9
+ asyncResult: () => asyncResultPromise,
10
+ end: body => { res.body = body; resolveAsyncResult(res); },
11
+ };
12
+
13
+ return res;
14
+ };
@@ -0,0 +1 @@
1
+ export default ['getMethodTest'];
@@ -0,0 +1,8 @@
1
+ export default async ({ body }) => {
2
+ const SERVICE_NAME = body.SERVICE_NAME;
3
+ const MODULE_URL = body.MODULE_URL;
4
+
5
+ const handler = (await import(new URL(`${SERVICE_NAME}/index.js`,
6
+ MODULE_URL))).default;
7
+ return handler;
8
+ }
@@ -0,0 +1,6 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => ({
4
+ SERVICE_NAME: z.string(),
5
+ MODULE_URL: z.string(),
6
+ })
@@ -0,0 +1,3 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => z.unknown();
@@ -0,0 +1 @@
1
+ export default ['get'];
@@ -0,0 +1,24 @@
1
+ import Sequelize from 'sequelize';
2
+ //import SequelizeDynamo from 'dynamo-sequelize';
3
+
4
+ //import { LOG_SERVICE } from '@minimonolith/lib';
5
+
6
+ export default async ({ body, SERVICES, ROUTE }) => {
7
+ const dialect = body.dialect;
8
+ const host = body.host;
9
+ const port = body.port;
10
+ const user = body.user;
11
+ const pass = body.pass;
12
+ const db = body.db;
13
+ const storage = body.storage;
14
+
15
+ const SEQUELIZE_OPTIONS = { dialect, host, port, storage, logging: false };
16
+ console.log('SEQUELIZE_OPTIONS', SEQUELIZE_OPTIONS);
17
+
18
+ //LOG_SERVICE.postQA({ ROUTE, DB_VARS: {
19
+ // dialect, host, port, db, user, pass, storage }});
20
+
21
+ const ORM = new Sequelize(db, user, pass, SEQUELIZE_OPTIONS);
22
+ await SERVICES.api.postORM.handler({ ORM });
23
+ await SERVICES.database.postConnection.handler({ ORM });
24
+ };
@@ -0,0 +1,12 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default ({ MODELS }) => ({
4
+ dialect: z.enum(['sqlite', 'mysql', 'mariadb', 'postgres',
5
+ 'mssql', 'snowflake', 'oracle']).default('sqlite'),
6
+ host: z.string().optional(),
7
+ user: z.string().optional(),
8
+ pass: z.string().optional(),
9
+ port: z.number().optional(),
10
+ db: z.string().optional(),
11
+ storage: z.string().default(':memory:'),
12
+ });
@@ -0,0 +1,27 @@
1
+ //import { LOG_SERVICE } from '@minimonolith/lib';
2
+
3
+ export default async ({ body, ROUTE_CODE }) => {
4
+ const ORM = body.ORM;
5
+
6
+ const MAX_RETRIES = 5, INITIAL_WAIT = 100;
7
+ let connectionRetries = 0, waitTime = INITIAL_WAIT;
8
+
9
+ while (connectionRetries < MAX_RETRIES) {
10
+ try {
11
+ //LOG_SERVICE.post({ ROUTE_CODE, AUTH_INTENT: connectionRetries });
12
+ console.log({ ROUTE_CODE, AUTH_INTENT: connectionRetries });
13
+ await ORM.authenticate();
14
+ break;
15
+
16
+ } catch (META_METHOD_ERROR) {
17
+ await new Promise(resolve => setTimeout(resolve, waitTime));
18
+
19
+ connectionRetries += 1;
20
+ const jitter = Math.random() * 0.3 + 0.7;
21
+ waitTime = Math.min(2 * waitTime * jitter,
22
+ INITIAL_WAIT * Math.pow(2, MAX_RETRIES));
23
+ }
24
+ }
25
+
26
+ return connectionRetries;
27
+ };
@@ -0,0 +1,5 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default ({ MODELS }) => ({
4
+ ORM: z.unknown(),
5
+ });
@@ -0,0 +1,3 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default ({ MODELS }) => z.number();
@@ -0,0 +1 @@
1
+ export default ['post', 'postConnection'];
@@ -0,0 +1,6 @@
1
+ export default envVars => {
2
+ const DB_ENV_VARS = ['DB_DIALECT', 'DB_HOST', 'DB_PORT', 'DB_DB',
3
+ 'DB_USER', 'DB_PASS', 'DB_STORAGE'];
4
+ return Object.fromEntries(Object.entries(envVars).filter(
5
+ ([envVar]) => DB_ENV_VARS.includes(envVar)));
6
+ }
@@ -0,0 +1,3 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => z.array(z.string());
@@ -0,0 +1,3 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => z.unknown();
@@ -0,0 +1,7 @@
1
+ export default ({ body }) => {
2
+ const envVars = body.envVars;
3
+
4
+ const API_ENV_VARS = ['DEV_ENV', 'PROD_ENV', 'TEST_ENV'];
5
+ return Object.fromEntries(Object.entries(envVars).filter(
6
+ ([envVar]) => API_ENV_VARS.includes(envVar)));
7
+ }
@@ -0,0 +1,3 @@
1
+ export default () => ({
2
+ envVars: z.unknown(),
3
+ })
@@ -0,0 +1,3 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => z.unknown();
@@ -0,0 +1,20 @@
1
+ import path from 'path';
2
+ import url from 'url';
3
+ import dotenv from 'dotenv';
4
+
5
+ import { /*LOG_SERVICE,*/ PATH_MODULE } from '@minimonolith/lib';
6
+
7
+ export default async ({ body }) => {
8
+ const envFile = body.envFile;
9
+ const modulesFolder = body.modulesFolder;
10
+
11
+ const projectRootFileUrl = PATH_MODULE.getProjectRoot(
12
+ import.meta.url, modulesFolder);
13
+ console.log('meta url', import.meta.url);
14
+ console.log('modulesFolder', modulesFolder);
15
+ const projectRootPath = url.fileURLToPath(projectRootFileUrl + path.sep);
16
+ console.log('projectRootPath', projectRootPath);
17
+ const envFilePath = path.resolve(projectRootPath, envFile)
18
+ console.log('envFilePath', envFilePath);
19
+ dotenv.config({ path: envFilePath });
20
+ };
@@ -0,0 +1,6 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => ({
4
+ envFile: z.string(),
5
+ modulesFolder: z.string(),
6
+ })
@@ -1,6 +1,6 @@
1
- export default () => {
2
- process.env.DEV_ENV = 'TRUE';
3
- process.env.PROD_ENV = 'FALSE';
4
- process.env.DB_DIALECT = 'sqlite';
5
- process.env.DB_STORAGE = ':memory:';
6
- }
1
+ export default () => {
2
+ process.env.DEV_ENV = 'TRUE';
3
+ process.env.PROD_ENV = 'FALSE';
4
+ process.env.DB_DIALECT = 'sqlite';
5
+ process.env.DB_STORAGE = ':memory:';
6
+ }
@@ -0,0 +1,5 @@
1
+ export default [
2
+ //'getENVEnvVars',
3
+ //'getDBEnvVars',
4
+ 'postEnvFile'
5
+ ];
@@ -1,4 +1,4 @@
1
- import postCompiletime from './postCompiletime/index.js';
2
- import postRuntime from './postRuntime/index.js';
3
-
4
- export default { postCompiletime, postRuntime };
1
+ import postCompiletime from './postCompiletime/index.js';
2
+ import postRuntime from './postRuntime/index.js';
3
+
4
+ export default { postCompiletime, postRuntime };
@@ -1,13 +1,13 @@
1
- import API_SERVICE from '../../api/index.js';
2
- import LOG_SERVICE from '../../log/index.js';
3
-
4
- export default ({ META_SERVICE_NAME, META_METHOD_NAME, ROUTE_CODE, META_METHOD_ERROR }) => {
5
- LOG_SERVICE.postError({
6
- META_SERVICE_NAME,
7
- META_METHOD_NAME,
8
- ROUTE_CODE,
9
- META_METHOD_ERROR,
10
- STACK_TRACE: META_METHOD_ERROR?.stack,
11
- });
12
- if (API_SERVICE.get().DEV_ENV==='TRUE') throw META_METHOD_ERROR;
13
- };
1
+ import API_SERVICE from '../../api/index.js';
2
+ import LOG_SERVICE from '../../log/index.js';
3
+
4
+ export default ({ META_SERVICE_NAME, META_METHOD_NAME, ROUTE_CODE, META_METHOD_ERROR }) => {
5
+ LOG_SERVICE.postError({
6
+ META_SERVICE_NAME,
7
+ META_METHOD_NAME,
8
+ ROUTE_CODE,
9
+ META_METHOD_ERROR,
10
+ STACK_TRACE: META_METHOD_ERROR?.stack,
11
+ });
12
+ if (API_SERVICE.get().DEV_ENV==='TRUE') throw META_METHOD_ERROR;
13
+ };
@@ -1,7 +1,7 @@
1
- import LOG_SERVICE from '../../log/index.js';
2
-
3
- export default (res, ROUTE_CODE, METHOD_ERROR) => {
4
- const MESSAGE = { ROUTE_CODE, METHOD_ERROR: METHOD_ERROR.stack.toString() };
5
- LOG_SERVICE.postError(MESSAGE);
6
- res.status(500).json(MESSAGE);
7
- }
1
+ import LOG_SERVICE from '../../log/index.js';
2
+
3
+ export default (res, ROUTE_CODE, METHOD_ERROR) => {
4
+ const MESSAGE = { ROUTE_CODE, METHOD_ERROR: METHOD_ERROR.stack.toString() };
5
+ LOG_SERVICE.postError(MESSAGE);
6
+ res.status(500).json(MESSAGE);
7
+ }
@@ -0,0 +1,14 @@
1
+ //import { LOG_SERVICE } from '@minimonolith/lib';
2
+
3
+ export default async ({ SERVICES }) => {
4
+ const method = 'get';
5
+ const route = '/';
6
+ const handler = async (req, res) => {
7
+ const SERVICE_RESPONSE = "API_RUNNING";
8
+ //LOG_SERVICE.post({ SERVICE_RESPONSE });
9
+ console.log({ SERVICE_RESPONSE });
10
+ return { SERVICE_RESPONSE: "API_RUNNING" };
11
+ }
12
+
13
+ await SERVICES.api.postRoute.handler({ method, route, handler })
14
+ }
@@ -0,0 +1 @@
1
+ export default ['post'];
package/index.js CHANGED
@@ -1,15 +1,23 @@
1
- import API_SERVICE from './src/api/index.js';
2
- import SERVER_SERVICE from './src/server/index.js';
3
- import VALIDATION_SERVICE from './src/validation/index.js';
4
- import AUTOTEST_SERVICE from './src/autotest/index.js';
5
-
6
- const { getNewAPI } = API_SERVICE;
7
- const { getServerFactory } = SERVER_SERVICE;
8
- const { z, zdb } = VALIDATION_SERVICE;
9
- const { getMethodTest } = AUTOTEST_SERVICE;
10
-
11
- export {
12
- getServerFactory, getNewAPI,
13
- z, zdb,
14
- getMethodTest,
15
- };
1
+ import path from 'path';
2
+ import { getNewLib, z } from '@minimonolith/lib';
3
+
4
+ import modules from './modules.js';
5
+
6
+ //const LIB = await getNewLib({ DEBUG: 'TRUE' });
7
+ const LIB = await getNewLib();
8
+
9
+ await Promise.all(modules.map(module => LIB.postModule(
10
+ module,
11
+ //'minimonolith' + path.sep,
12
+ //path.join('@minimonolith', 'lib') + path.sep
13
+ )));
14
+
15
+
16
+ const { SERVICES, COMPONENTS } = LIB;
17
+ const zdb = COMPONENTS.zdb;
18
+ const database = SERVICES.database;
19
+ const getServerFactory = SERVICES.server.getServerFactory.handler;
20
+ const autotest = SERVICES.autotest;
21
+ const getNewAPI = SERVICES.api.getNewAPI.handler;
22
+
23
+ export { z, zdb, database, getServerFactory, autotest, getNewAPI };
@@ -1,5 +1,5 @@
1
- import post from './post/index.js';
2
- import postError from './postError/index.js';
3
- import postQA from './postQA/index.js';
4
-
5
- export default { post, postError, postQA };
1
+ import post from './post/index.js';
2
+ import postError from './postError/index.js';
3
+ import postQA from './postQA/index.js';
4
+
5
+ export default { post, postError, postQA };
@@ -1,3 +1,3 @@
1
- import API_SERVICE from '../../api/index.js';
2
-
3
- export default (...MESSAGE) => { console.log(...MESSAGE); };
1
+ import API_SERVICE from '../../api/index.js';
2
+
3
+ export default (...MESSAGE) => { console.log(...MESSAGE); };
@@ -1,3 +1,3 @@
1
- import API_SERVICE from '../../api/index.js';
2
-
3
- export default (...ERROR) => { console.error(...ERROR); };
1
+ import API_SERVICE from '../../api/index.js';
2
+
3
+ export default (...ERROR) => { console.error(...ERROR); };
@@ -1,3 +1,3 @@
1
- import API_SERVICE from '../../api/index.js';
2
-
3
- export default (...MESSAGE) => { if (API_SERVICE.get().PROD_ENV==='FALSE') { console.log(...MESSAGE); } };
1
+ import API_SERVICE from '../../api/index.js';
2
+
3
+ export default (...MESSAGE) => { if (API_SERVICE.get().PROD_ENV==='FALSE') { console.log(...MESSAGE); } };
@@ -0,0 +1,28 @@
1
+ import { DataTypes } from 'sequelize';
2
+
3
+ //import { LOG_SERVICE } from '@minimonolith/lib';
4
+
5
+ export default async ({ ROUTE_CODE, SERVICES }) => {
6
+ const SCHEMAS = await SERVICES.api.getSchemas.handler();
7
+ const ORM = await SERVICES.api.getORM.handler();
8
+
9
+ //for (const moduleName of SCHEMAS) {
10
+ for (const moduleName of Object.keys(SCHEMAS)) {
11
+ //LOG_SERVICE.post({ ROUTE_CODE, LOADING: moduleName });
12
+
13
+ const model = SCHEMAS[moduleName](ORM, DataTypes);
14
+ await SERVICES.api.postModel.handler({ moduleName, model });
15
+ }
16
+
17
+ const MODELS = await SERVICES.api.getModels.handler();
18
+
19
+ for (const [moduleName, MODEL] of Object.entries(MODELS)) {
20
+ //LOG_SERVICE.post({ ROUTE_CODE, ASSOCIATING: moduleName });
21
+ MODEL.associate(MODELS);
22
+ }
23
+
24
+ //LOG_SERVICE.post({ ROUTE_CODE, SYNCING_ORM: 'WAITING_ORM_SYNCING' });
25
+ await ORM.sync({ alter: process.env.DEV_ENV==='TRUE' ? true : false });
26
+
27
+ //LOG_SERVICE.post({ ROUTE_CODE, SYNCING_ORM: 'DONE_ORM_SYNCING' });
28
+ };
@@ -0,0 +1,17 @@
1
+ import fs from 'fs';
2
+ import url from 'url';
3
+
4
+ //import { LOG_SERVICE } from '@minimonolith/lib';
5
+
6
+ export default async ({ body, SERVICES }) => {
7
+ const moduleName = body.moduleName;
8
+ const moduleURL = body.moduleURL;
9
+
10
+ console.log('moduleURL', moduleURL);
11
+ if (!fs.existsSync(url.fileURLToPath(`${moduleURL}model.js`))) return;
12
+ //LOG_SERVICE.post({ messages: [' FOUND_MODEL'] })
13
+
14
+ const moduleSchema =
15
+ (await import(`${moduleURL}model.js`)).default(moduleName);
16
+ await SERVICES.api.postSchema.handler({ moduleName, moduleSchema });
17
+ };
@@ -0,0 +1,6 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => ({
4
+ moduleName: z.string(),
5
+ moduleURL: z.unknown(),
6
+ });
@@ -0,0 +1 @@
1
+ export default ['getSynced', 'post'];
package/modules.js ADDED
@@ -0,0 +1,19 @@
1
+ export default [
2
+ 'api',
3
+ 'server',
4
+ 'environment',
5
+ 'health',
6
+ 'database',
7
+ 'model',
8
+ 'service',
9
+ 'validation',
10
+ 'zdb',
11
+ 'autotest',
12
+
13
+ //'log',
14
+ /*
15
+ 'test',
16
+ 'path',
17
+ 'error',
18
+ */
19
+ ];