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.
- package/README.md +209 -208
- package/api/api.js +5 -0
- package/api/getModels/handler.js +5 -0
- package/api/getModels/out.js +3 -0
- package/api/getNewAPI/handler.js +53 -0
- package/api/getNewAPI/in.js +7 -0
- package/api/getNewAPI/out.js +3 -0
- package/api/getORM/handler.js +5 -0
- package/api/getORM/out.js +3 -0
- package/api/getSchemas/handler.js +5 -0
- package/api/getSchemas/out.js +3 -0
- package/api/getService/handler.js +8 -0
- package/api/getService/in.js +6 -0
- package/api/getService/out.js +3 -0
- package/api/getServices/handler.js +5 -0
- package/api/getServices/out.js +3 -0
- package/api/getSyncedHandler/handler.js +40 -0
- package/api/getSyncedHandler/in.js +3 -0
- package/api/getSyncedHandler/out.js +3 -0
- package/api/postModel/handler.js +8 -0
- package/api/postModel/in.js +6 -0
- package/api/postModule/handler.js +31 -0
- package/api/postModule/in.js +7 -0
- package/api/postORM/handler.js +7 -0
- package/api/postORM/in.js +5 -0
- package/api/postRawModule/handler.js +9 -0
- package/api/postRawModule/in.js +9 -0
- package/api/postRoute/handler.js +9 -0
- package/api/postRoute/in.js +7 -0
- package/api/postSchema/handler.js +8 -0
- package/api/postSchema/in.js +6 -0
- package/api/services.js +15 -0
- package/{src/autotest/getMethodTest/index.js → autotest/getMethodTest/handler.js} +14 -12
- package/autotest/getMethodTest/in.js +3 -0
- package/autotest/getMethodTest/out.js +3 -0
- package/{src/autotest → autotest}/getTestServerResponse/index.js +14 -14
- package/autotest/services.js +1 -0
- package/control/get/handler.js +8 -0
- package/control/get/in.js +6 -0
- package/control/get/out.js +3 -0
- package/control/services.js +1 -0
- package/database/post/handler.js +24 -0
- package/database/post/in.js +12 -0
- package/database/postConnection/handler.js +27 -0
- package/database/postConnection/in.js +5 -0
- package/database/postConnection/out.js +3 -0
- package/database/services.js +1 -0
- package/environment/getDBEnvVars/handler.js +6 -0
- package/environment/getDBEnvVars/in.js +3 -0
- package/environment/getDBEnvVars/out.js +3 -0
- package/environment/getENVEnvVars/handler.js +7 -0
- package/environment/getENVEnvVars/in.js +3 -0
- package/environment/getENVEnvVars/out.js +3 -0
- package/environment/postEnvFile/handler.js +20 -0
- package/environment/postEnvFile/in.js +6 -0
- package/{src/environment → environment}/postTestEnvironment/index.js +6 -6
- package/environment/services.js +5 -0
- package/{src/error → error}/index.js +4 -4
- package/{src/error → error}/postCompiletime/index.js +13 -13
- package/{src/error → error}/postRuntime/index.js +7 -7
- package/health/post/handler.js +14 -0
- package/health/services.js +1 -0
- package/index.js +23 -15
- package/{src/log → log}/index.js +5 -5
- package/{src/log → log}/post/index.js +3 -3
- package/{src/log → log}/postError/index.js +3 -3
- package/{src/log → log}/postQA/index.js +3 -3
- package/model/getSynced/handler.js +28 -0
- package/model/post/handler.js +17 -0
- package/model/post/in.js +6 -0
- package/model/services.js +1 -0
- package/modules.js +19 -0
- package/package.json +33 -32
- package/{src/server → server}/getNodejsServerHandler/index.js +70 -68
- package/server/getServerFactory/handler.js +17 -0
- package/server/getServerFactory/in.js +8 -0
- package/server/getServerFactory/out.js +3 -0
- package/server/services.js +1 -0
- package/service/getParsedCode/handler.js +22 -0
- package/service/getParsedCode/in.js +6 -0
- package/service/getParsedCode/out.js +6 -0
- package/service/getParsedEvent/handler.js +12 -0
- package/service/getParsedEvent/in.js +5 -0
- package/service/getParsedEvent/out.js +6 -0
- package/{src/method/getResponseCode/index.js → service/getResponseCode/handler.js} +11 -9
- package/service/getResponseCode/in.js +3 -0
- package/service/getResponseCode/out.js +3 -0
- package/service/getRouteCode/handler.js +15 -0
- package/service/getRouteCode/in.js +6 -0
- package/service/getRouteCode/out.js +3 -0
- package/service/getType/handler.js +11 -0
- package/service/getType/in.js +5 -0
- package/service/getType/out.js +3 -0
- package/{src/method → service}/postResponse/index.js +13 -13
- package/service/postRoute/handler.js +82 -0
- package/service/postRoute/in.js +6 -0
- package/service/services.js +9 -0
- package/validation/getParsedAsync/handler.js +38 -0
- package/validation/getParsedAsync/in.js +9 -0
- package/validation/getParsedAsync/out.js +6 -0
- package/validation/services.js +1 -0
- package/yarn-error.log +4104 -0
- package/zdb/components.js +1 -0
- package/zdb/getAssertExists/handler.js +16 -0
- package/zdb/getAssertExists/in.js +6 -0
- package/zdb/getAssertExists/out.js +3 -0
- package/zdb/getAssertNotExists/handler.js +16 -0
- package/zdb/getAssertNotExists/in.js +6 -0
- package/zdb/getAssertNotExists/out.js +3 -0
- package/zdb/getAssertSafeInt/handler.js +15 -0
- package/zdb/getAssertSafeInt/in.js +6 -0
- package/zdb/getAssertSafeInt/out.js +3 -0
- package/src/api/get/index.js +0 -19
- package/src/api/getNewAPI/index.js +0 -14
- package/src/api/getSyncedHandler/index.js +0 -24
- package/src/api/index.js +0 -4
- package/src/api/postService/index.js +0 -34
- package/src/autotest/getMethodTest/back.index.js +0 -29
- package/src/autotest/index.js +0 -3
- package/src/control/get/index.js +0 -3
- package/src/control/index.js +0 -3
- package/src/database/index.js +0 -4
- package/src/database/post/index.js +0 -28
- package/src/database/postConnection/index.js +0 -25
- package/src/environment/getDBEnvVars/index.js +0 -4
- package/src/environment/getENVEnvVars/index.js +0 -4
- package/src/environment/index.js +0 -4
- package/src/environment/postEnvFile/index.js +0 -13
- package/src/event/getParsedEvent/index.js +0 -9
- package/src/event/index.js +0 -3
- package/src/health/index.js +0 -3
- package/src/health/post/index.js +0 -10
- package/src/method/getParsedCode/index.js +0 -13
- package/src/method/getRouteCode/index.js +0 -12
- package/src/method/getType/index.js +0 -9
- package/src/method/index.js +0 -7
- package/src/method/post/index.js +0 -56
- package/src/middleware/index.js +0 -4
- package/src/middleware/postCors/index.js +0 -20
- package/src/middleware/postError/index.js +0 -10
- package/src/model/getSynced/index.js +0 -22
- package/src/model/index.js +0 -4
- package/src/model/post/index.js +0 -11
- package/src/path/getProjectRoot/index.js +0 -14
- package/src/path/index.js +0 -3
- package/src/server/getServerFactory/index.js +0 -14
- package/src/server/index.js +0 -3
- package/src/validation/dbValidation.js +0 -33
- package/src/validation/get/index.js +0 -16
- package/src/validation/getOptionalObject/index.js +0 -8
- package/src/validation/index.js +0 -8
- package/src/validation/postError/index.js +0 -29
- /package/{src/middleware/postCors → api}/corsHeaders.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default ['getAssertExists', 'getAssertNotExists', 'getAssertSafeInt'];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from '@minimonolith/lib';
|
|
2
|
+
|
|
3
|
+
export default ({ body }) => {
|
|
4
|
+
const model = body.model;
|
|
5
|
+
const field = body.field;
|
|
6
|
+
|
|
7
|
+
return async (value, ctx) => {
|
|
8
|
+
const valueCount = await model.count({ where: { [field]: value } });
|
|
9
|
+
if (valueCount == 0) {
|
|
10
|
+
ctx.addIssue({
|
|
11
|
+
code: z.ZodIssueCode.custom,
|
|
12
|
+
message: field.toUpperCase()+'_DOES_NOT_EXIST'
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from '@minimonolith/lib';
|
|
2
|
+
|
|
3
|
+
export default ({ body }) => {
|
|
4
|
+
const model = body.model;
|
|
5
|
+
const field = body.field;
|
|
6
|
+
|
|
7
|
+
return async (value, ctx) => {
|
|
8
|
+
const valueCount = await model.count({ where: { [field]: value } });
|
|
9
|
+
if (valueCount > 0) {
|
|
10
|
+
ctx.addIssue({
|
|
11
|
+
code: z.ZodIssueCode.custom,
|
|
12
|
+
message: field.toUpperCase()+'_ALREADY_EXISTS',
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from '@minimonolith/lib';
|
|
2
|
+
|
|
3
|
+
export default ({ body }) => {
|
|
4
|
+
const field = body.field;
|
|
5
|
+
|
|
6
|
+
return (rawValue, ctx) => {
|
|
7
|
+
const parsedValue = parseInt(rawValue, 10);
|
|
8
|
+
if (isNaN(parsedValue) || parsedValue.toString() !== rawValue) {
|
|
9
|
+
ctx.addIssue({
|
|
10
|
+
code: z.ZodIssueCode.custom,
|
|
11
|
+
message: field.toUpperCase()+'_NOT_A_SAFE_INT',
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/api/get/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import getLambdaAPI from 'lambda-api';
|
|
2
|
-
|
|
3
|
-
import LOG_SERVICE from '../../log/index.js';
|
|
4
|
-
import HEALTH_SERVICE from '../../health/index.js';
|
|
5
|
-
import DATABASE_SERVICE from '../../database/index.js';
|
|
6
|
-
import MIDDLEWARE_SERVICE from '../../middleware/index.js';
|
|
7
|
-
|
|
8
|
-
import postService from '../postService/index.js';
|
|
9
|
-
import getSyncedHandler from '../getSyncedHandler/index.js';
|
|
10
|
-
|
|
11
|
-
const API = getLambdaAPI();
|
|
12
|
-
API.postCORSMiddleware = MIDDLEWARE_SERVICE.postCors;
|
|
13
|
-
API.postHealthService = HEALTH_SERVICE.post;
|
|
14
|
-
API.postService = postService;
|
|
15
|
-
API.postDatabaseService = DATABASE_SERVICE.post;
|
|
16
|
-
API.postErrorMiddleware = MIDDLEWARE_SERVICE.postError;
|
|
17
|
-
API.getSyncedHandler = getSyncedHandler;
|
|
18
|
-
|
|
19
|
-
export default () => API;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import getAPI from '../get/index.js';
|
|
2
|
-
|
|
3
|
-
export default ({ DEV_ENV='FALSE', PROD_ENV='TRUE', TEST_ENV='FALSE' } = {}) => {
|
|
4
|
-
getAPI().SERVICES = {};
|
|
5
|
-
getAPI().VALIDATORS = {};
|
|
6
|
-
getAPI().SCHEMAS = {};
|
|
7
|
-
getAPI().MODELS = {};
|
|
8
|
-
getAPI().ORM = undefined;
|
|
9
|
-
getAPI().DEV_ENV = DEV_ENV;
|
|
10
|
-
getAPI().PROD_ENV = PROD_ENV;
|
|
11
|
-
getAPI().TEST_ENV = TEST_ENV;
|
|
12
|
-
getAPI().postCORSMiddleware();
|
|
13
|
-
return getAPI();
|
|
14
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import MODEL_SERVICE from '../../model/index.js';
|
|
2
|
-
import LOG_SERVICE from '../../log/index.js';
|
|
3
|
-
|
|
4
|
-
import getAPI from '../get/index.js';
|
|
5
|
-
|
|
6
|
-
const META_SERVICE='API', META_METHOD='GET_SYNCED_HANDLER', META_ROUTE=META_SERVICE+'_'+META_METHOD;
|
|
7
|
-
|
|
8
|
-
export default async () => {
|
|
9
|
-
getAPI().postErrorMiddleware();
|
|
10
|
-
if (getAPI().ORM) await MODEL_SERVICE.getSynced();
|
|
11
|
-
//else LOG_SERVICE.post({ META_ROUTE, INFO: 'NO_DATABASE_SERVICE_POSTED' });
|
|
12
|
-
|
|
13
|
-
LOG_SERVICE.post({ META_ROUTE, INFO: 'LISTENING' });
|
|
14
|
-
|
|
15
|
-
return async (event, context) => {
|
|
16
|
-
LOG_SERVICE.post({
|
|
17
|
-
ROUTE_CODE: 'LAMBDA_EVENT',
|
|
18
|
-
PATH: event.requestContext?.http?.path,
|
|
19
|
-
METHOD: event.requestContext?.http?.method,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
return await getAPI().run(event, context);
|
|
23
|
-
};
|
|
24
|
-
};
|
package/src/api/index.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import url from 'url'
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
import PATH_SERVICE from '../../path/index.js';
|
|
6
|
-
import MODEL_SERVICE from '../../model/index.js';
|
|
7
|
-
import LOG_SERVICE from '../../log/index.js';
|
|
8
|
-
import METHOD_SERVICE from '../../method/index.js';
|
|
9
|
-
import VALIDATION_SERVICE from '../../validation/index.js';
|
|
10
|
-
import ERROR_SERVICE from '../../error/index.js';
|
|
11
|
-
|
|
12
|
-
import getAPI from '../get/index.js';
|
|
13
|
-
|
|
14
|
-
const META_SERVICE_NAME = 'API', META_METHOD_NAME = 'POST_SERVICE';
|
|
15
|
-
|
|
16
|
-
export default async (SERVICE_NAME, SRC_FOLDER='', MODULES_FOLDER='node_modules' + path.sep) => {
|
|
17
|
-
|
|
18
|
-
LOG_SERVICE.post(META_SERVICE_NAME, META_METHOD_NAME, SERVICE_NAME);
|
|
19
|
-
getAPI().SERVICES[SERVICE_NAME] = {}; getAPI().VALIDATORS[SERVICE_NAME] = {};
|
|
20
|
-
try {
|
|
21
|
-
|
|
22
|
-
const projectRootPath = PATH_SERVICE.getProjectRoot(import.meta.url, MODULES_FOLDER) + path.sep;
|
|
23
|
-
const projectRelativeServicePath = path.join('.', SRC_FOLDER, SERVICE_NAME) + path.sep;
|
|
24
|
-
const SERVICE_URL = new URL(projectRelativeServicePath, projectRootPath);
|
|
25
|
-
await MODEL_SERVICE.post(SERVICE_NAME, SERVICE_URL);
|
|
26
|
-
|
|
27
|
-
const SERVICE_MODULE = await import(`${SERVICE_URL}index.js`);
|
|
28
|
-
LOG_SERVICE.post('METHODS_TO_BE_POSTED', SERVICE_MODULE.default);
|
|
29
|
-
for (const METHOD_CODE of SERVICE_MODULE.default) await METHOD_SERVICE.post(SERVICE_NAME, SERVICE_URL, METHOD_CODE);
|
|
30
|
-
|
|
31
|
-
} catch (META_METHOD_ERROR) {
|
|
32
|
-
ERROR_SERVICE.postCompiletime({ META_SERVICE_NAME, META_METHOD_NAME, META_METHOD_ERROR });
|
|
33
|
-
}
|
|
34
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import url from 'url';
|
|
2
|
-
import fetch from 'cross-fetch';
|
|
3
|
-
|
|
4
|
-
import getTestServerResponse from '../getTestServerResponse/index.js';
|
|
5
|
-
|
|
6
|
-
export default (serverHandler, expectedCode) => async params => {
|
|
7
|
-
const URL = new url.URL(params.path, 'http://localhost/');
|
|
8
|
-
|
|
9
|
-
const request = {
|
|
10
|
-
method: params.method,
|
|
11
|
-
url: URL.pathname + URL.search,
|
|
12
|
-
headers: {
|
|
13
|
-
...params.headers,
|
|
14
|
-
'Content-Type': 'application/json',
|
|
15
|
-
},
|
|
16
|
-
on(eventName, callback) {
|
|
17
|
-
if (eventName === 'data' && params.body) {
|
|
18
|
-
callback(Buffer.from(JSON.stringify(params.body)));
|
|
19
|
-
}
|
|
20
|
-
if (eventName === 'end') { callback(); }
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const response = getTestServerResponse();
|
|
25
|
-
serverHandler(request, response);
|
|
26
|
-
|
|
27
|
-
const result = await response.asyncResult();
|
|
28
|
-
expect(result.statusCode).toBe(expectedCode);
|
|
29
|
-
}
|
package/src/autotest/index.js
DELETED
package/src/control/get/index.js
DELETED
package/src/control/index.js
DELETED
package/src/database/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import Sequelize from 'sequelize';
|
|
2
|
-
//import SequelizeDynamo from 'dynamo-sequelize';
|
|
3
|
-
|
|
4
|
-
import API_SERVICE from '../../api/index.js';
|
|
5
|
-
import LOG_SERVICE from '../../log/index.js';
|
|
6
|
-
import ERROR_SERVICE from '../../error/index.js';
|
|
7
|
-
|
|
8
|
-
import postConnection from '../postConnection/index.js'
|
|
9
|
-
|
|
10
|
-
const META_SERVICE='DATABASE', META_METHOD='POST', META_ROUTE=META_SERVICE+'_'+META_METHOD;
|
|
11
|
-
|
|
12
|
-
export default async ({ DB_DIALECT='sqlite', DB_HOST=undefined, DB_PORT=undefined, DB_DB=undefined,
|
|
13
|
-
DB_USER=undefined, DB_PASS=undefined, DB_STORAGE=':memory:'} = {}) => {
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
const SEQUELIZE_OPTIONS = { dialect: DB_DIALECT, host: DB_HOST,
|
|
17
|
-
port: DB_PORT, storage: DB_STORAGE, logging: false };
|
|
18
|
-
|
|
19
|
-
LOG_SERVICE.postQA({ META_ROUTE, DB_VARS: {
|
|
20
|
-
DB_DIALECT, DB_HOST, DB_PORT, DB_DB, DB_USER, DB_PASS, DB_STORAGE }});
|
|
21
|
-
|
|
22
|
-
API_SERVICE.get().ORM = new Sequelize(DB_DB, DB_USER, DB_PASS, SEQUELIZE_OPTIONS);
|
|
23
|
-
await postConnection(API_SERVICE.get().ORM);
|
|
24
|
-
|
|
25
|
-
} catch (META_METHOD_ERROR) {
|
|
26
|
-
ERROR_SERVICE.postCompiletime({ META_ROUTE, META_METHOD_ERROR });
|
|
27
|
-
}
|
|
28
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import LOG_SERVICE from '../../log/index.js';
|
|
2
|
-
|
|
3
|
-
const META_SERVICE_NAME='DATABASE', META_METHOD_NAME='POST_CONNECTION';
|
|
4
|
-
|
|
5
|
-
export default async ORM => {
|
|
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({ META_SERVICE_NAME, META_METHOD_NAME, AUTH_INTENT: connectionRetries });
|
|
12
|
-
await ORM.authenticate();
|
|
13
|
-
break;
|
|
14
|
-
|
|
15
|
-
} catch (META_METHOD_ERROR) {
|
|
16
|
-
await new Promise(resolve => setTimeout(resolve, waitTime));
|
|
17
|
-
|
|
18
|
-
connectionRetries += 1;
|
|
19
|
-
const jitter = Math.random() * 0.3 + 0.7;
|
|
20
|
-
waitTime = Math.min(2 * waitTime * jitter, INITIAL_WAIT * Math.pow(2, MAX_RETRIES));
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return connectionRetries;
|
|
25
|
-
};
|
package/src/environment/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import url from 'url';
|
|
3
|
-
import dotenv from 'dotenv';
|
|
4
|
-
|
|
5
|
-
import LOG_SERVICE from '../../log/index.js';
|
|
6
|
-
import PATH_SERVICE from '../../path/index.js';
|
|
7
|
-
|
|
8
|
-
export default (ENV_FILE, MODULE_FOLDER) => {
|
|
9
|
-
const projectRootFileUrl = PATH_SERVICE.getProjectRoot(import.meta.url, MODULE_FOLDER);
|
|
10
|
-
const projectRootPath = url.fileURLToPath(projectRootFileUrl+'/');
|
|
11
|
-
const envFilePath = path.resolve(projectRootPath, ENV_FILE)
|
|
12
|
-
dotenv.config({ path: envFilePath });
|
|
13
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export default event => {
|
|
2
|
-
const { body, params, query, requestContext } = event;
|
|
3
|
-
const claims = requestContext.authorizer?.jwt?.claims
|
|
4
|
-
|
|
5
|
-
const tempUnifiedBody = { ...body, ...params, ...query };
|
|
6
|
-
const unifiedBody = Object.keys(tempUnifiedBody).length > 0 ? tempUnifiedBody : undefined;
|
|
7
|
-
|
|
8
|
-
return { body: unifiedBody, claims };
|
|
9
|
-
}
|
package/src/event/index.js
DELETED
package/src/health/index.js
DELETED
package/src/health/post/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import API_SERVICE from '../../api/index.js';
|
|
2
|
-
import LOG_SERVICE from '../../log/index.js';
|
|
3
|
-
|
|
4
|
-
export default () => {
|
|
5
|
-
API_SERVICE.get().get('/', async (req, res) => {
|
|
6
|
-
const SERVICE_RESPONSE = "API_RUNNING";
|
|
7
|
-
LOG_SERVICE.post({ SERVICE_RESPONSE });
|
|
8
|
-
return { SERVICE_RESPONSE: "API_RUNNING" };
|
|
9
|
-
});
|
|
10
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export default (SERVICE_NAME, METHOD_CODE) => {
|
|
2
|
-
const methodPathParts = METHOD_CODE.split(":");
|
|
3
|
-
const pathParams = methodPathParts.slice(1).map(param => `:${param}`);
|
|
4
|
-
const rawMethodName = methodPathParts[0];
|
|
5
|
-
const METHOD_NAME = rawMethodName[0] === '!' ? rawMethodName.substring(1) : rawMethodName;
|
|
6
|
-
|
|
7
|
-
const relativeMethodRoute = `${rawMethodName}${pathParams.length > 0 ? '/' : ''}${pathParams.join("/")}`;
|
|
8
|
-
const METHOD_ROUTE = relativeMethodRoute[0]==='!' ?
|
|
9
|
-
`/${relativeMethodRoute.substring(1)}/${SERVICE_NAME}` :
|
|
10
|
-
`/${SERVICE_NAME}/${relativeMethodRoute}`;
|
|
11
|
-
|
|
12
|
-
return { METHOD_NAME, METHOD_ROUTE };
|
|
13
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const getUpperSnakeCase = str => {
|
|
2
|
-
return str
|
|
3
|
-
.replace(/([a-z])([A-Z])/g, '$1_$2')
|
|
4
|
-
.replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')
|
|
5
|
-
.toUpperCase();
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default (SERVICE_NAME, METHOD_NAME) => {
|
|
9
|
-
const snakeServiceName = getUpperSnakeCase(SERVICE_NAME);
|
|
10
|
-
const snakeMethodName = getUpperSnakeCase(METHOD_NAME);
|
|
11
|
-
return snakeServiceName + '_' + snakeMethodName;
|
|
12
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
const methodsAvailable = ['post', 'get', 'patch', 'put', 'delete'];
|
|
2
|
-
|
|
3
|
-
export default METHOD_NAME => {
|
|
4
|
-
const methodMatched = METHOD_NAME.match(/^[a-z]*/);
|
|
5
|
-
if (!methodMatched || !methodsAvailable.includes(methodMatched[0]))
|
|
6
|
-
throw new Error('UNKNOWN_METHOD_TYPE: ' + METHOD_NAME);
|
|
7
|
-
|
|
8
|
-
return methodMatched[0];
|
|
9
|
-
}
|
package/src/method/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import post from './post/index.js';
|
|
2
|
-
import getParsedCode from './getParsedCode/index.js';
|
|
3
|
-
import getType from './getType/index.js';
|
|
4
|
-
import getRouteCode from './getRouteCode/index.js';
|
|
5
|
-
import postResponse from './postResponse/index.js';
|
|
6
|
-
|
|
7
|
-
export default { post, getParsedCode, getType, getRouteCode, postResponse };
|
package/src/method/post/index.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import API_SERVICE from '../../api/index.js';
|
|
2
|
-
import LOG_SERVICE from '../../log/index.js';
|
|
3
|
-
import CONTROL_SERVICE from '../../control/index.js';
|
|
4
|
-
import EVENT_SERVICE from '../../event/index.js';
|
|
5
|
-
import VALIDATION_SERVICE from '../../validation/index.js';
|
|
6
|
-
import ERROR_SERVICE from '../../error/index.js';
|
|
7
|
-
|
|
8
|
-
import getParsedCode from '../getParsedCode/index.js';
|
|
9
|
-
import getRouteCode from '../getRouteCode/index.js';
|
|
10
|
-
import getType from '../getType/index.js';
|
|
11
|
-
import postResponse from '../postResponse/index.js';
|
|
12
|
-
|
|
13
|
-
const META_SERVICE_NAME='METHOD', META_METHOD_NAME='POST';
|
|
14
|
-
|
|
15
|
-
export default async (SERVICE_NAME, SERVICE_URL, METHOD_CODE) => {
|
|
16
|
-
const { METHOD_NAME, METHOD_ROUTE } = getParsedCode(SERVICE_NAME, METHOD_CODE);
|
|
17
|
-
const ROUTE_CODE = getRouteCode(SERVICE_NAME, METHOD_NAME);
|
|
18
|
-
LOG_SERVICE.post(' FOUND_METHOD', METHOD_NAME);
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
|
|
22
|
-
const METHOD = {
|
|
23
|
-
CONTROLLER: await CONTROL_SERVICE.get(METHOD_NAME, SERVICE_URL),
|
|
24
|
-
VALIDATOR: await VALIDATION_SERVICE.get(METHOD_NAME, SERVICE_URL),
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// Register service within API
|
|
28
|
-
API_SERVICE.get().SERVICES[SERVICE_NAME][METHOD_NAME] = async (body, claims=undefined) => {
|
|
29
|
-
const { MODELS, SERVICES } = API_SERVICE.get();
|
|
30
|
-
return await METHOD.CONTROLLER({ MODELS, SERVICES, ROUTE_CODE, body, claims });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Register service within API
|
|
34
|
-
API_SERVICE.get().VALIDATORS[SERVICE_NAME][METHOD_NAME] = (body, claims=undefined) => {
|
|
35
|
-
const { MODELS, SERVICES, VALIDATORS } = API_SERVICE.get();
|
|
36
|
-
return METHOD.VALIDATOR({ MODELS, SERVICES, VALIDATORS, body, claims });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const METHOD_TYPE = getType(METHOD_NAME);
|
|
40
|
-
|
|
41
|
-
// Register route forn lAMBDA API
|
|
42
|
-
LOG_SERVICE.post('POSTING_ROUTE', METHOD_ROUTE);
|
|
43
|
-
API_SERVICE.get()[METHOD_TYPE](METHOD_ROUTE, async (event, res) => {
|
|
44
|
-
const { body, claims } = EVENT_SERVICE.getParsedEvent(event);
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
if (await VALIDATION_SERVICE.postError(res, ROUTE_CODE, METHOD.VALIDATOR, body, claims)) return;
|
|
48
|
-
await postResponse(res, ROUTE_CODE, METHOD.CONTROLLER, METHOD_TYPE, body, claims);
|
|
49
|
-
}
|
|
50
|
-
catch (METHOD_ERROR) { ERROR_SERVICE.postRuntime(res, ROUTE_CODE, METHOD_ERROR); }
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
} catch (META_METHOD_ERROR) {
|
|
54
|
-
ERROR_SERVICE.postCompiletime({ META_SERVICE_NAME, META_METHOD_NAME, ROUTE_CODE, META_METHOD_ERROR });
|
|
55
|
-
}
|
|
56
|
-
};
|
package/src/middleware/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import API_SERVICE from '../../api/index.js';
|
|
2
|
-
import LOG_SERVICE from '../../log/index.js';
|
|
3
|
-
|
|
4
|
-
import CORS_HEADERS from './corsHeaders.js';
|
|
5
|
-
|
|
6
|
-
export default () => {
|
|
7
|
-
|
|
8
|
-
API_SERVICE.get().use((req, res, next) => {
|
|
9
|
-
if (req.headers['x-trigger-error']) {
|
|
10
|
-
LOG_SERVICE.post({ ROUTE_CODE: 'LAMBDA_API', MESSAGE: 'X_TRIGGER_ERROR_HEADER' });
|
|
11
|
-
throw new Error('X_TRIGGER_ERROR_HEADER');
|
|
12
|
-
}
|
|
13
|
-
res.cors(); next();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
API_SERVICE.get().options('/*', (req, res) => {
|
|
17
|
-
for (let k in CORS_HEADERS) { res.header(k, CORS_HEADERS[k]); }
|
|
18
|
-
res.status(200).send({})
|
|
19
|
-
});
|
|
20
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import API_SERVICE from '../../api/index.js';
|
|
2
|
-
import LOG_SERVICE from '../../log/index.js';
|
|
3
|
-
|
|
4
|
-
export default () => {
|
|
5
|
-
API_SERVICE.get().use((err, req, res, next) => {
|
|
6
|
-
LOG_SERVICE.postError({ ROUTE_CODE: 'LAMBDA_API', ERROR: err });
|
|
7
|
-
res.cors(); //next();
|
|
8
|
-
res.status(500).send({ ROUTE_CODE: 'LAMBDA_API', ERROR: err.message });
|
|
9
|
-
});
|
|
10
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { DataTypes } from 'sequelize';
|
|
2
|
-
|
|
3
|
-
import API_SERVICE from '../../api/index.js';
|
|
4
|
-
import LOG_SERVICE from '../../log/index.js';
|
|
5
|
-
|
|
6
|
-
const META_SERVICE='MODEL', META_METHOD='GET_SYNCED', META_ROUTE=META_SERVICE+'_'+META_METHOD;
|
|
7
|
-
|
|
8
|
-
export default async () => {
|
|
9
|
-
for (const SERVICE_NAME of Object.keys(API_SERVICE.get().SCHEMAS)) {
|
|
10
|
-
LOG_SERVICE.post({ META_ROUTE, LOADING: SERVICE_NAME });
|
|
11
|
-
API_SERVICE.get().MODELS[SERVICE_NAME] = API_SERVICE.get().SCHEMAS[SERVICE_NAME](API_SERVICE.get().ORM, DataTypes);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
for (const [SERVICE_NAME, MODEL] of Object.entries(API_SERVICE.get().MODELS)) {
|
|
15
|
-
LOG_SERVICE.post({ META_ROUTE, ASSOCIATING: SERVICE_NAME });
|
|
16
|
-
MODEL.associate(API_SERVICE.get().MODELS);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
LOG_SERVICE.post({ META_ROUTE, SYNCING_ORM: 'WAITING_ORM_SYNCING' });
|
|
20
|
-
await API_SERVICE.get().ORM.sync({ alter: process.env.MM_API_DEV_ENV==='TRUE' ? true : false });
|
|
21
|
-
LOG_SERVICE.post({ META_ROUTE, SYNCING_ORM: 'DONE_ORM_SYNCING' });
|
|
22
|
-
};
|
package/src/model/index.js
DELETED
package/src/model/post/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import url from 'url';
|
|
3
|
-
|
|
4
|
-
import API_SERVICE from '../../api/index.js';
|
|
5
|
-
import LOG_SERVICE from '../../log/index.js';
|
|
6
|
-
|
|
7
|
-
export default async (SERVICE_NAME, SERVICE_URL) => {
|
|
8
|
-
if (!fs.existsSync(url.fileURLToPath(`${SERVICE_URL}model.js`))) return;
|
|
9
|
-
LOG_SERVICE.post(' FOUND_MODEL')
|
|
10
|
-
API_SERVICE.get().SCHEMAS[SERVICE_NAME] = (await import(`${SERVICE_URL}model.js`)).default(SERVICE_NAME);
|
|
11
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import url from 'url';
|
|
3
|
-
|
|
4
|
-
// Function to find the project root from any nested directory inside node_modules/
|
|
5
|
-
export default (currentFileUrl, MODULE_FOLDER) => {
|
|
6
|
-
const currentPath = path.dirname(url.fileURLToPath(currentFileUrl));
|
|
7
|
-
const nodeModulesIndex = currentPath.indexOf(MODULE_FOLDER);
|
|
8
|
-
if (nodeModulesIndex === -1) {
|
|
9
|
-
throw new Error(MODULE_FOLDER+' not found in the path '+currentPath);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const nodeModulesPath = currentPath.substring(0, nodeModulesIndex);
|
|
13
|
-
return url.pathToFileURL(nodeModulesPath);
|
|
14
|
-
}
|
package/src/path/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import http from 'http';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
import getNodejsServerHandler from '../getNodejsServerHandler/index.js';
|
|
5
|
-
|
|
6
|
-
export default async (ENV_FILE='.env', MODULE_FOLDER='node_modules'+path.sep) => {
|
|
7
|
-
(await import('../../environment/postEnvFile/index.js')).default(ENV_FILE, MODULE_FOLDER);
|
|
8
|
-
|
|
9
|
-
return (lambdaHandler) => {
|
|
10
|
-
const serverHandler = getNodejsServerHandler(lambdaHandler);
|
|
11
|
-
const server = http.createServer(serverHandler);
|
|
12
|
-
return server;
|
|
13
|
-
}
|
|
14
|
-
}
|
package/src/server/index.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
exists: (model, field) => async (value, ctx) => {
|
|
5
|
-
const valueCount = await model.count({ where: { [field]: value } });
|
|
6
|
-
if (valueCount == 0) {
|
|
7
|
-
ctx.addIssue({
|
|
8
|
-
code: z.ZodIssueCode.custom,
|
|
9
|
-
message: field.toUpperCase()+'_DOES_NOT_EXIST'
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
notExists: (model, field) => async (value, ctx) => {
|
|
15
|
-
const valueCount = await model.count({ where: { [field]: value } });
|
|
16
|
-
if (valueCount > 0) {
|
|
17
|
-
ctx.addIssue({
|
|
18
|
-
code: z.ZodIssueCode.custom,
|
|
19
|
-
message: field.toUpperCase()+'_ALREADY_EXISTS',
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
isSafeInt: field => (rawValue, ctx) => {
|
|
25
|
-
const parsedValue = parseInt(rawValue, 10);
|
|
26
|
-
if (isNaN(parsedValue) || parsedValue.toString() !== rawValue) {
|
|
27
|
-
ctx.addIssue({
|
|
28
|
-
code: z.ZodIssueCode.custom,
|
|
29
|
-
message: field.toUpperCase()+'_NOT_A_SAFE_INT',
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import url from 'url';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
|
|
5
|
-
import LOG_SERVICE from '../../log/index.js';
|
|
6
|
-
|
|
7
|
-
export default async (METHOD_NAME, SERVICE_URL) => {
|
|
8
|
-
const VALIDATION_URL = new URL(`${METHOD_NAME}/valid.js`, SERVICE_URL);
|
|
9
|
-
|
|
10
|
-
if (!fs.existsSync(url.fileURLToPath(VALIDATION_URL)))
|
|
11
|
-
//return EVENT_CONTEXT => z.undefined();
|
|
12
|
-
return undefined;;
|
|
13
|
-
|
|
14
|
-
LOG_SERVICE.post(' FOUND_VALIDATOR');
|
|
15
|
-
return (await import(VALIDATION_URL)).default;
|
|
16
|
-
};
|