minimonolith 0.25.24 → 0.26.3
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 +55 -81
- package/backtest/back.js +54 -0
- package/backtest/backtest.js +131 -0
- package/backtest/handler.js +23 -0
- package/backtest/handlerCompiletimeError.js +10 -0
- package/backtest/handlerCompiletimeError2.js +10 -0
- package/backtest/handlerRuntimeError.js +24 -0
- package/backtest/localDocker/Dockerfile +11 -0
- package/backtest/localDocker/docker-compose.yml +34 -0
- package/backtest/localDocker/run.sh +4 -0
- package/backtest/localDocker/shutdown.sh +2 -0
- package/backtest/localDocker/update.sh +2 -0
- package/backtest/server.js +7 -0
- package/backtest/todo/delete/index.js +7 -0
- package/backtest/todo/delete/valid.js +8 -0
- package/backtest/todo/get/index.js +3 -0
- package/backtest/todo/getAttributes/index.js +5 -0
- package/backtest/todo/getAttributes/valid.js +5 -0
- package/backtest/todo/getOne/index.js +3 -0
- package/backtest/todo/getOne/valid.js +8 -0
- package/backtest/todo/getOneAlias/index.js +3 -0
- package/backtest/todo/getOneAlias/valid.js +3 -0
- package/backtest/todo/index.js +1 -0
- package/backtest/todo/model.js +19 -0
- package/backtest/todo/patch/index.js +6 -0
- package/backtest/todo/patch/valid.js +12 -0
- package/backtest/todo/post/index.js +5 -0
- package/backtest/todo/post/valid.js +5 -0
- package/backtest/todo/postSeed/index.js +9 -0
- package/backtest/todo/postSeed/seed.js +4 -0
- package/backtest/todoCompiletimeError/got/index.js +1 -0
- package/backtest/todoCompiletimeError/index.js +1 -0
- package/backtest/todoList/delete/handler.js +7 -0
- package/backtest/todoList/delete/valid.js +5 -0
- package/backtest/todoList/get/handler.js +5 -0
- package/backtest/todoList/index.js +1 -0
- package/backtest/todoList/model.js +17 -0
- package/backtest/todoList/post/handler.js +9 -0
- package/backtest/todoList/post/valid.js +6 -0
- package/backtest/todoRuntimeError/get/index.js +1 -0
- package/index.js +13 -22
- package/package.json +7 -8
- package/src/api/get/index.js +17 -0
- package/src/api/getNewAPI/index.js +11 -0
- package/src/api/getSyncedHandler/index.js +23 -0
- package/src/api/index.js +4 -0
- package/src/api/postService/index.js +29 -0
- package/src/autotest/getMethodTest/back.index.js +29 -0
- package/{autotest/getMethodTest/handler.js → src/autotest/getMethodTest/index.js} +1 -3
- package/src/autotest/index.js +3 -0
- package/src/database/index.js +4 -0
- package/src/database/post/index.js +38 -0
- package/src/database/postConnection/index.js +25 -0
- package/src/error/index.js +4 -0
- package/src/error/postCompiletime/index.js +13 -0
- package/src/error/postRuntime/index.js +7 -0
- package/src/event/getParsedEvent/index.js +9 -0
- package/src/event/index.js +3 -0
- package/src/log/index.js +5 -0
- package/src/log/post/index.js +3 -0
- package/src/log/postERROR/index.js +3 -0
- package/src/log/postINFO/index.js +3 -0
- package/src/method/getParsedCode/index.js +13 -0
- package/{service/getResponseCode/handler.js → src/method/getResponseCode/index.js} +1 -3
- package/src/method/getRouteCode/index.js +12 -0
- package/src/method/getType/index.js +9 -0
- package/src/method/index.js +7 -0
- package/src/method/post/index.js +44 -0
- package/src/method/postResponse/index.js +29 -0
- package/src/middleware/index.js +4 -0
- package/src/middleware/postCors/index.js +20 -0
- package/src/middleware/postError/index.js +10 -0
- package/src/model/getSynced/index.js +23 -0
- package/src/model/index.js +4 -0
- package/src/model/post/index.js +16 -0
- package/{server → src/server}/getNodejsServerHandler/index.js +13 -7
- package/src/server/getServerFactory/index.js +12 -0
- package/src/server/index.js +3 -0
- package/api/api.js +0 -5
- package/api/getModels/handler.js +0 -5
- package/api/getModels/out.js +0 -3
- package/api/getNewAPI/handler.js +0 -46
- package/api/getNewAPI/in.js +0 -8
- package/api/getNewAPI/out.js +0 -3
- package/api/getORM/handler.js +0 -5
- package/api/getORM/out.js +0 -3
- package/api/getSchemas/handler.js +0 -5
- package/api/getSchemas/out.js +0 -3
- package/api/getService/handler.js +0 -8
- package/api/getService/in.js +0 -6
- package/api/getService/out.js +0 -3
- package/api/getServices/handler.js +0 -5
- package/api/getServices/out.js +0 -3
- package/api/getSyncedHandler/handler.js +0 -28
- package/api/getSyncedHandler/in.js +0 -3
- package/api/getSyncedHandler/out.js +0 -3
- package/api/postDebug/handler.js +0 -5
- package/api/postDebug/in.js +0 -3
- package/api/postError/handler.js +0 -5
- package/api/postError/in.js +0 -3
- package/api/postInfo/handler.js +0 -5
- package/api/postInfo/in.js +0 -3
- package/api/postModel/handler.js +0 -8
- package/api/postModel/in.js +0 -6
- package/api/postModule/handler.js +0 -31
- package/api/postModule/in.js +0 -7
- package/api/postORM/handler.js +0 -7
- package/api/postORM/in.js +0 -5
- package/api/postRawModule/handler.js +0 -9
- package/api/postRawModule/in.js +0 -9
- package/api/postRoute/handler.js +0 -9
- package/api/postRoute/in.js +0 -7
- package/api/postSchema/handler.js +0 -8
- package/api/postSchema/in.js +0 -6
- package/api/services.js +0 -18
- package/autotest/getMethodTest/in.js +0 -3
- package/autotest/getMethodTest/out.js +0 -3
- package/autotest/services.js +0 -1
- package/control/get/handler.js +0 -8
- package/control/get/in.js +0 -6
- package/control/get/out.js +0 -3
- package/database/post/handler.js +0 -24
- package/database/post/in.js +0 -12
- package/database/postConnection/handler.js +0 -25
- package/database/postConnection/in.js +0 -5
- package/database/postConnection/out.js +0 -3
- package/database/services.js +0 -1
- package/environment/getDBEnvVars/handler.js +0 -6
- package/environment/getDBEnvVars/in.js +0 -3
- package/environment/getDBEnvVars/out.js +0 -3
- package/environment/getENVEnvVars/handler.js +0 -7
- package/environment/getENVEnvVars/in.js +0 -3
- package/environment/getENVEnvVars/out.js +0 -3
- package/environment/postEnvFile/handler.js +0 -16
- package/environment/postEnvFile/in.js +0 -6
- package/environment/postTestEnvironment/index.js +0 -6
- package/environment/services.js +0 -5
- package/health/post/handler.js +0 -11
- package/health/services.js +0 -1
- package/model/getSynced/handler.js +0 -29
- package/model/post/handler.js +0 -14
- package/model/post/in.js +0 -6
- package/model/services.js +0 -1
- package/modules.js +0 -19
- package/server/getServerFactory/handler.js +0 -17
- package/server/getServerFactory/in.js +0 -8
- package/server/getServerFactory/out.js +0 -3
- package/server/services.js +0 -1
- package/service/getParsedCode/handler.js +0 -19
- package/service/getParsedCode/in.js +0 -6
- package/service/getParsedCode/out.js +0 -6
- package/service/getParsedEvent/handler.js +0 -12
- package/service/getParsedEvent/in.js +0 -5
- package/service/getParsedEvent/out.js +0 -6
- package/service/getResponseCode/in.js +0 -3
- package/service/getResponseCode/out.js +0 -3
- package/service/getRouteCode/handler.js +0 -15
- package/service/getRouteCode/in.js +0 -6
- package/service/getRouteCode/out.js +0 -3
- package/service/getType/handler.js +0 -11
- package/service/getType/in.js +0 -5
- package/service/getType/out.js +0 -3
- package/service/postRoute/handler.js +0 -105
- package/service/postRoute/in.js +0 -6
- package/service/services.js +0 -9
- package/setupTesting.js +0 -17
- package/validation/getParsedAsync/handler.js +0 -37
- package/validation/getParsedAsync/in.js +0 -9
- package/validation/getParsedAsync/out.js +0 -6
- package/validation/services.js +0 -1
- package/zdb/components.js +0 -1
- package/zdb/getAssertExists/handler.js +0 -16
- package/zdb/getAssertExists/in.js +0 -6
- package/zdb/getAssertExists/out.js +0 -3
- package/zdb/getAssertNotExists/handler.js +0 -16
- package/zdb/getAssertNotExists/in.js +0 -6
- package/zdb/getAssertNotExists/out.js +0 -3
- package/zdb/getAssertSafeInt/handler.js +0 -15
- package/zdb/getAssertSafeInt/in.js +0 -6
- package/zdb/getAssertSafeInt/out.js +0 -3
- /package/{control/services.js → backtest/todoRuntimeError/index.js} +0 -0
- /package/{autotest → src/autotest}/getTestServerResponse/index.js +0 -0
- /package/{api → src/middleware/postCors}/corsHeaders.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//export default async () => 'ERROR';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default ['got'];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const methods = ['get', 'post', 'delete'];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const modelSchema = serviceName => (orm, types) => {
|
|
2
|
+
const schema = orm.define(serviceName, {
|
|
3
|
+
name: {
|
|
4
|
+
type: types.STRING,
|
|
5
|
+
allowNull: false
|
|
6
|
+
},
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
schema.associate = MODELS => {
|
|
10
|
+
schema.hasMany(MODELS.todo, {
|
|
11
|
+
foreignKey: 'todoListId',
|
|
12
|
+
as: 'todoElements',
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return schema;
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default async () => { throw Error(); }
|
package/index.js
CHANGED
|
@@ -1,22 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const { SERVICES, COMPONENTS } = LIB;
|
|
16
|
-
const zdb = COMPONENTS.zdb;
|
|
17
|
-
const database = SERVICES.database;
|
|
18
|
-
const getServerFactory = SERVICES.server.getServerFactory.handler;
|
|
19
|
-
const autotest = SERVICES.autotest;
|
|
20
|
-
const getNewAPI = SERVICES.api.getNewAPI.handler;
|
|
21
|
-
|
|
22
|
-
export { z, zdb, database, getServerFactory, autotest, getNewAPI };
|
|
1
|
+
import API_SERVICE from './src/api/index.js';
|
|
2
|
+
import SERVER_SERVICE from './src/server/index.js';
|
|
3
|
+
import AUTOTEST_SERVICE from './src/autotest/index.js';
|
|
4
|
+
|
|
5
|
+
const { getNewAPI } = API_SERVICE;
|
|
6
|
+
const { getServerFactory } = SERVER_SERVICE;
|
|
7
|
+
const { getMethodTest } = AUTOTEST_SERVICE;
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
getServerFactory,
|
|
11
|
+
getNewAPI,
|
|
12
|
+
getMethodTest,
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "minimonolith",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.26.3",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
@@ -10,24 +10,23 @@
|
|
|
10
10
|
},
|
|
11
11
|
"keywords": [
|
|
12
12
|
"lambda-api",
|
|
13
|
-
"zod",
|
|
14
13
|
"sequelize"
|
|
15
14
|
],
|
|
16
15
|
"dependencies": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"sequelize": "^6.30.0",
|
|
20
|
-
"dotenv": "^16.0.3",
|
|
21
|
-
"zod": "^3.23.8"
|
|
16
|
+
"lambda-api": "^1.0.1",
|
|
17
|
+
"sequelize": "^6.30.0"
|
|
22
18
|
},
|
|
23
19
|
"devDependencies": {
|
|
24
20
|
"@aws-sdk/client-s3": "^3.304.0",
|
|
25
21
|
"@aws-sdk/s3-request-presigner": "^3.304.0",
|
|
22
|
+
"@jest/globals": "^30.2.0",
|
|
26
23
|
"cross-env": "^7.0.3",
|
|
27
24
|
"cross-fetch": "^3.1.5",
|
|
25
|
+
"dotenv": "^16.0.3",
|
|
28
26
|
"jest": "^29.5.0",
|
|
29
27
|
"mysql2": "^3.2.0",
|
|
30
28
|
"nodemon": "^2.0.22",
|
|
31
|
-
"sqlite3": "^5.1.6"
|
|
29
|
+
"sqlite3": "^5.1.6",
|
|
30
|
+
"zod": "^3.21.4"
|
|
32
31
|
}
|
|
33
32
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import getLambdaAPI from 'lambda-api';
|
|
2
|
+
|
|
3
|
+
import LOG_SERVICE from '../../log/index.js';
|
|
4
|
+
import DATABASE_SERVICE from '../../database/index.js';
|
|
5
|
+
import MIDDLEWARE_SERVICE from '../../middleware/index.js';
|
|
6
|
+
|
|
7
|
+
import postService from '../postService/index.js';
|
|
8
|
+
import getSyncedHandler from '../getSyncedHandler/index.js';
|
|
9
|
+
|
|
10
|
+
const API = getLambdaAPI();
|
|
11
|
+
API.postCORSMiddleware = MIDDLEWARE_SERVICE.postCors;
|
|
12
|
+
API.postService = postService;
|
|
13
|
+
API.postDatabaseService = DATABASE_SERVICE.post;
|
|
14
|
+
API.postErrorMiddleware = MIDDLEWARE_SERVICE.postError;
|
|
15
|
+
API.getSyncedHandler = getSyncedHandler;
|
|
16
|
+
|
|
17
|
+
export default () => API;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import getAPI from '../get/index.js';
|
|
2
|
+
|
|
3
|
+
export default ({ ERROR_LEVEL=0 } = {}) => {
|
|
4
|
+
getAPI().SERVICES = {};
|
|
5
|
+
getAPI().SCHEMAS = {};
|
|
6
|
+
getAPI().MODELS = {};
|
|
7
|
+
getAPI().ORM = undefined;
|
|
8
|
+
getAPI().ERROR_LEVEL = ERROR_LEVEL;
|
|
9
|
+
getAPI().postCORSMiddleware();
|
|
10
|
+
return getAPI();
|
|
11
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
|
|
12
|
+
LOG_SERVICE.post({ META_ROUTE, INFO: 'LISTENING' });
|
|
13
|
+
|
|
14
|
+
return async (event, context) => {
|
|
15
|
+
LOG_SERVICE.post({
|
|
16
|
+
ROUTE_CODE: 'LAMBDA_EVENT',
|
|
17
|
+
PATH: event.requestContext?.http?.path,
|
|
18
|
+
METHOD: event.requestContext?.http?.method,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return await getAPI().run(event, context);
|
|
22
|
+
};
|
|
23
|
+
};
|
package/src/api/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
|
|
3
|
+
import MODEL_SERVICE from '../../model/index.js';
|
|
4
|
+
import LOG_SERVICE from '../../log/index.js';
|
|
5
|
+
import METHOD_SERVICE from '../../method/index.js';
|
|
6
|
+
import ERROR_SERVICE from '../../error/index.js';
|
|
7
|
+
|
|
8
|
+
import getAPI from '../get/index.js';
|
|
9
|
+
|
|
10
|
+
const META_SERVICE_NAME = 'API', META_METHOD_NAME = 'POST_SERVICE';
|
|
11
|
+
const GREEN = '\x1b[32m', END = '\x1b[0m'
|
|
12
|
+
|
|
13
|
+
export default async (SERVICE_NAME, SERVICE, MODEL) => {
|
|
14
|
+
|
|
15
|
+
LOG_SERVICE.post(`${META_SERVICE_NAME} ${META_METHOD_NAME} ${GREEN}${SERVICE_NAME}${END}`);
|
|
16
|
+
|
|
17
|
+
getAPI().SERVICES[SERVICE_NAME] = {};
|
|
18
|
+
try {
|
|
19
|
+
|
|
20
|
+
await MODEL_SERVICE.post(SERVICE_NAME, MODEL);
|
|
21
|
+
|
|
22
|
+
for (const METHOD_KEY in SERVICE) {
|
|
23
|
+
await METHOD_SERVICE.post(SERVICE_NAME, METHOD_KEY, SERVICE[METHOD_KEY]);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
} catch (META_METHOD_ERROR) {
|
|
27
|
+
ERROR_SERVICE.postCompiletime({ META_SERVICE_NAME, META_METHOD_NAME, META_METHOD_ERROR });
|
|
28
|
+
}
|
|
29
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
if (DB_DIALECT!=='sqlite' && (!DB_HOST || !DB_PORT || !DB_DB || !DB_USER || !DB_PASS)) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
'One of these DB parameters not given: [DB_HOST, DB_PORT, DB_DB, DB_USER, DB_PASS]');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const SEQUELIZE_OPTIONS = { dialect: DB_DIALECT, host: DB_HOST,
|
|
22
|
+
port: DB_PORT, storage: DB_STORAGE, logging: false };
|
|
23
|
+
|
|
24
|
+
const DB_VARS = Object.fromEntries(
|
|
25
|
+
Object.entries({
|
|
26
|
+
DB_DIALECT, DB_HOST, DB_PORT, DB_DB, DB_USER, DB_PASS, DB_STORAGE })
|
|
27
|
+
.filter(([key, val]) => val != null)
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
LOG_SERVICE.postINFO({ META_ROUTE, DB_VARS });
|
|
31
|
+
|
|
32
|
+
API_SERVICE.get().ORM = new Sequelize(DB_DB, DB_USER, DB_PASS, SEQUELIZE_OPTIONS);
|
|
33
|
+
await postConnection(API_SERVICE.get().ORM);
|
|
34
|
+
|
|
35
|
+
} catch (META_METHOD_ERROR) {
|
|
36
|
+
ERROR_SERVICE.postCompiletime({ META_ROUTE, META_METHOD_ERROR });
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +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
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
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/log/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
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 };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import API_SERVICE from '../../api/index.js';
|
|
2
|
+
import LOG_SERVICE from '../../log/index.js';
|
|
3
|
+
import EVENT_SERVICE from '../../event/index.js';
|
|
4
|
+
import ERROR_SERVICE from '../../error/index.js';
|
|
5
|
+
|
|
6
|
+
import getParsedCode from '../getParsedCode/index.js';
|
|
7
|
+
import getRouteCode from '../getRouteCode/index.js';
|
|
8
|
+
import getType from '../getType/index.js';
|
|
9
|
+
import postResponse from '../postResponse/index.js';
|
|
10
|
+
|
|
11
|
+
const META_SERVICE_NAME='METHOD', META_METHOD_NAME='POST';
|
|
12
|
+
const CYAN = '\x1b[36m', YELLOW = '\x1b[33m', END = '\x1b[0m';
|
|
13
|
+
|
|
14
|
+
export default async (SERVICE_NAME, METHOD_KEY, METHOD) => {
|
|
15
|
+
const { METHOD_NAME, METHOD_ROUTE } = getParsedCode(SERVICE_NAME, METHOD_KEY);
|
|
16
|
+
const ROUTE_CODE = getRouteCode(SERVICE_NAME, METHOD_NAME);
|
|
17
|
+
//LOG_SERVICE.post(` FOUND_METHOD: ${CYAN}${METHOD_NAME}${END}`);
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
|
|
21
|
+
// Register service within API
|
|
22
|
+
API_SERVICE.get().SERVICES[SERVICE_NAME][METHOD_NAME] = async (body, claims=undefined) => {
|
|
23
|
+
const { MODELS, SERVICES } = API_SERVICE.get();
|
|
24
|
+
return await METHOD({ MODELS, SERVICES, ROUTE_CODE, body, claims });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const METHOD_TYPE = getType(METHOD_NAME);
|
|
28
|
+
|
|
29
|
+
// Register route forn lAMBDA API
|
|
30
|
+
LOG_SERVICE.post(` · ${YELLOW}${METHOD_ROUTE}${END}`);
|
|
31
|
+
|
|
32
|
+
API_SERVICE.get()[METHOD_TYPE](METHOD_ROUTE, async (event, res) => {
|
|
33
|
+
const { body, claims } = EVENT_SERVICE.getParsedEvent(event);
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
await postResponse(res, ROUTE_CODE, METHOD, METHOD_TYPE, body, claims);
|
|
37
|
+
}
|
|
38
|
+
catch (METHOD_ERROR) { ERROR_SERVICE.postRuntime(res, ROUTE_CODE, METHOD_ERROR); }
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
} catch (META_METHOD_ERROR) {
|
|
42
|
+
ERROR_SERVICE.postCompiletime({ META_SERVICE_NAME, META_METHOD_NAME, ROUTE_CODE, META_METHOD_ERROR });
|
|
43
|
+
}
|
|
44
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import API_SERVICE from '../../api/index.js';
|
|
2
|
+
import LOG_SERVICE from '../../log/index.js';
|
|
3
|
+
|
|
4
|
+
import getResponseCode from '../getResponseCode/index.js';
|
|
5
|
+
|
|
6
|
+
export default async (res, ROUTE_CODE, METHOD, METHOD_TYPE, body, claims) => {
|
|
7
|
+
|
|
8
|
+
const { MODELS, SERVICES } = API_SERVICE.get();
|
|
9
|
+
|
|
10
|
+
const METHOD_RESPONSE = await METHOD({ MODELS, SERVICES, body, claims });
|
|
11
|
+
const { status, body: responseBody, cookies, headers } = METHOD_RESPONSE;
|
|
12
|
+
|
|
13
|
+
// status
|
|
14
|
+
let METHOD_RESPONSE_CODE = status;
|
|
15
|
+
if (!status) METHOD_RESPONSE_CODE = getResponseCode(METHOD_TYPE);
|
|
16
|
+
|
|
17
|
+
// headers
|
|
18
|
+
if (headers) Object.entries(headers).forEach(([k, v]) => res.header(k, v));
|
|
19
|
+
|
|
20
|
+
// cookies
|
|
21
|
+
if (cookies && Array.isArray(cookies))
|
|
22
|
+
cookies.forEach(c => {
|
|
23
|
+
//console.log('cookie', c.name);
|
|
24
|
+
res.cookie(c.name, c.value, c.options || {}); });
|
|
25
|
+
|
|
26
|
+
LOG_SERVICE.post({ ROUTE_CODE, METHOD_RESPONSE });
|
|
27
|
+
|
|
28
|
+
res.status(METHOD_RESPONSE_CODE).json(responseBody);
|
|
29
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
await API_SERVICE.get().ORM.sync();
|
|
22
|
+
LOG_SERVICE.post({ META_ROUTE, SYNCING_ORM: 'DONE_ORM_SYNCING' });
|
|
23
|
+
};
|