minimonolith 0.26.4 → 0.26.5

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 CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  [![codecov](https://codecov.io/gh/DeepHackDev/minimonolith-api/branch/master/graph/badge.svg?token=ORFNKKJRSE)](https://codecov.io/gh/DeepHackDev/minimonolith-lib)
4
4
 
5
- `minimonolith` is a lightweight library designed to help you build serverless APIs using AWS Lambda, with a focus on simplicity and ease of use. The library provides a straightforward structure to organize your API's services, methods, validation, and models while handling common tasks like database connection and request validation.
5
+ `minimonolith` is a lightweight library designed to help you build serverless APIs using AWS Lambda, with a focus on simplicity and ease of use. The library provides a straightforward structure to organize your API's modules, methods, validation, and models while handling common tasks like database connection and request validation.
6
6
 
7
- In addition to its simplicity, `minimonolith` enables seamless inter-service communication within your API. This allows services to call one another's functionality without directly importing them, fostering a modular design. For example, you can call the get method of the todo service from the todoList service using SERVICES.todo.get({ id }). By registering services within the API, you can easily call their methods from other services, which not only promotes a clean architecture but also paves the way for future support of automated end-to-end testing.
7
+ In addition to its simplicity, `minimonolith` enables seamless inter-module communication within your API. This allows modules to call one another's functionality without directly importing them, fostering a modular design. For example, you can call the get method of the todo module from the todoList module using MODULES.todo.get({ id }). By registering modules within the API, you can easily call their methods from other modules, which not only promotes a clean architecture but also paves the way for future support of automated end-to-end testing.
8
8
 
9
9
  ## Example Project
10
10
 
@@ -16,12 +16,12 @@ Here's an example project using `minimonolith`:
16
16
  ├── .gitignore
17
17
  ├── .env
18
18
  ├── server.js // For local development
19
- ├── index.js // Root of the code in a deployed AWS Lambda
19
+ ├── index.js // Root of the code in a AWS Lambda
20
20
  └── todo
21
- ├── index.js // Service 'todo' exported method handlers are declared here
22
- ├── model.js // Optional: Sequelize model for service 'todo' is declared here
21
+ ├── index.js // Module 'todo' exported methods
22
+ ├── model.js // Optional: Sequelize model for module
23
23
  └── get
24
- └─── handler.js // Service 'todo' method 'get' handler
24
+ └─── handler.js // Module 'todo' method 'get' handler
25
25
  ```
26
26
 
27
27
  ### server.js
@@ -58,8 +58,8 @@ import todo from './todo/index.js';
58
58
 
59
59
  const API = await getNewAPI();
60
60
 
61
- await API.postService(todo.name, todo.service, todo.model);
62
- await API.postDatabaseService({
61
+ await API.postModule(todo.name, todo.module, todo.model);
62
+ await API.postDatabaseModule({
63
63
  DB_DIALECT: process.env.DB_DIALECT,
64
64
  DB_HOST: process.env.DB_HOST,
65
65
  DB_PORT: process.env.DB_PORT,
@@ -74,7 +74,7 @@ export const lambdaHandler = await API.getSyncedHandler();
74
74
 
75
75
  ### todo/index.js
76
76
 
77
- Here, we declare the method handlers for the `todo` service:
77
+ Here, we declare the method handlers for the `todo` module:
78
78
 
79
79
  ```js
80
80
  // todo/index.js
@@ -88,7 +88,7 @@ import model from './model.js';
88
88
 
89
89
  export default {
90
90
  name: 'todo',
91
- service: {
91
+ module: {
92
92
  'get': get,
93
93
  'post': post,
94
94
  'patch:id': patch,·
@@ -100,12 +100,12 @@ export default {
100
100
 
101
101
  ### todo/model.js
102
102
 
103
- In this file, we define a Sequelize model for the `todo` service:
103
+ In this file, we define a Sequelize model for the `todo` module:
104
104
 
105
105
  ```js
106
106
  // todo/model.js
107
- export default serviceName => (orm, types) => {
108
- const schema = orm.define(serviceName, {
107
+ export default moduleName => (orm, types) => {
108
+ const schema = orm.define(moduleName, {
109
109
  name: {
110
110
  type: types.STRING,
111
111
  allowNull: false
@@ -127,7 +127,7 @@ export default serviceName => (orm, types) => {
127
127
 
128
128
  ### todo/get/index.js
129
129
 
130
- This file contains the `get:id` method handler for the `todo` service. It retrieves a todo item by its ID:
130
+ This file contains the `get:id` method handler for the `todo` module. It retrieves a todo item by its ID:
131
131
 
132
132
  ```js
133
133
  // todo/get/index.js
@@ -158,7 +158,7 @@ export default async ({ body, MODELS }) => {
158
158
 
159
159
  ## Database Authentication
160
160
 
161
- To set up authentication for the database you need to pass necessary variables to postDatabaseService as at index.js above.
161
+ To set up authentication for the database you need to pass necessary variables to postDatabaseModule as at index.js above.
162
162
  Assuming using same env variable names as at index.js above
163
163
 
164
164
  For MySQL:
@@ -179,5 +179,5 @@ For SQLite in memory:
179
179
  ```makefile
180
180
  DB_DIALECT=sqlite
181
181
  DB_DB=<your_database_name>
182
- DB_STORAGE=:memory: # Need to also pass to API.postDatabaseService()
182
+ DB_STORAGE=:memory: # Need to also pass to API.postDatabaseModule()
183
183
  ```
package/index.js CHANGED
@@ -1,10 +1,10 @@
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';
1
+ import API_MODULE from './src/api/index.js';
2
+ import SERVER_MODULE from './src/server/index.js';
3
+ import AUTOTEST_MODULE from './src/autotest/index.js';
4
4
 
5
- const { getNewAPI } = API_SERVICE;
6
- const { getServerFactory } = SERVER_SERVICE;
7
- const { getMethodTest } = AUTOTEST_SERVICE;
5
+ const { getNewAPI } = API_MODULE;
6
+ const { getServerFactory } = SERVER_MODULE;
7
+ const { getMethodTest } = AUTOTEST_MODULE;
8
8
 
9
9
  export {
10
10
  getServerFactory,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "minimonolith",
3
3
  "type": "module",
4
- "version": "0.26.4",
4
+ "version": "0.26.5",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -1,17 +1,17 @@
1
1
  import getLambdaAPI from 'lambda-api';
2
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';
3
+ import LOG_MODULE from '../../log/index.js';
4
+ import DATABASE_MODULE from '../../database/index.js';
5
+ import MIDDLEWARE_MODULE from '../../middleware/index.js';
6
6
 
7
- import postService from '../postService/index.js';
7
+ import postModule from '../postModule/index.js';
8
8
  import getSyncedHandler from '../getSyncedHandler/index.js';
9
9
 
10
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;
11
+ API.postCORSMiddleware = MIDDLEWARE_MODULE.postCors;
12
+ API.postModule = postModule;
13
+ API.postDatabaseModule = DATABASE_MODULE.post;
14
+ API.postErrorMiddleware = MIDDLEWARE_MODULE.postError;
15
15
  API.getSyncedHandler = getSyncedHandler;
16
16
 
17
17
  export default () => API;
@@ -1,7 +1,7 @@
1
1
  import getAPI from '../get/index.js';
2
2
 
3
3
  export default ({ ERROR_LEVEL=0 } = {}) => {
4
- getAPI().SERVICES = {};
4
+ getAPI().MODULES = {};
5
5
  getAPI().SCHEMAS = {};
6
6
  getAPI().MODELS = {};
7
7
  getAPI().ORM = undefined;
@@ -1,18 +1,18 @@
1
- import MODEL_SERVICE from '../../model/index.js';
2
- import LOG_SERVICE from '../../log/index.js';
1
+ import MODEL_MODULE from '../../model/index.js';
2
+ import LOG_MODULE from '../../log/index.js';
3
3
 
4
4
  import getAPI from '../get/index.js';
5
5
 
6
- const META_SERVICE='API', META_METHOD='GET_SYNCED_HANDLER', META_ROUTE=META_SERVICE+'_'+META_METHOD;
6
+ const META_MODULE='API', META_METHOD='GET_SYNCED_HANDLER', META_ROUTE=META_MODULE+'_'+META_METHOD;
7
7
 
8
8
  export default async () => {
9
9
  getAPI().postErrorMiddleware();
10
- if (getAPI().ORM) await MODEL_SERVICE.getSynced();
10
+ if (getAPI().ORM) await MODEL_MODULE.getSynced();
11
11
 
12
- LOG_SERVICE.post({ META_ROUTE, INFO: 'LISTENING' });
12
+ LOG_MODULE.post({ META_ROUTE, INFO: 'LISTENING' });
13
13
 
14
14
  return async (event, context) => {
15
- LOG_SERVICE.post({
15
+ LOG_MODULE.post({
16
16
  ROUTE_CODE: 'LAMBDA_EVENT',
17
17
  PATH: event.requestContext?.http?.path,
18
18
  METHOD: event.requestContext?.http?.method,
@@ -0,0 +1,29 @@
1
+ import fs from 'fs';
2
+
3
+ import MODEL_MODULE from '../../model/index.js';
4
+ import LOG_MODULE from '../../log/index.js';
5
+ import METHOD_MODULE from '../../method/index.js';
6
+ import ERROR_MODULE from '../../error/index.js';
7
+
8
+ import getAPI from '../get/index.js';
9
+
10
+ const META_MODULE_NAME = 'API', META_METHOD_NAME = 'POST_MODULE';
11
+ const GREEN = '\x1b[32m', END = '\x1b[0m'
12
+
13
+ export default async ({ name, methods, model }) => {
14
+
15
+ LOG_MODULE.post(`${META_MODULE_NAME} ${META_METHOD_NAME} ${GREEN}${name}${END}`);
16
+
17
+ getAPI().MODULES[name] = {};
18
+ try {
19
+
20
+ await MODEL_MODULE.post(name, model);
21
+
22
+ for (const METHOD_KEY in methods) {
23
+ await METHOD_MODULE.post(name, METHOD_KEY, methods[METHOD_KEY]);
24
+ }
25
+
26
+ } catch (META_METHOD_ERROR) {
27
+ ERROR_MODULE.postCompiletime({ META_MODULE_NAME, META_METHOD_NAME, META_METHOD_ERROR });
28
+ }
29
+ };
@@ -1,13 +1,13 @@
1
1
  import Sequelize from 'sequelize';
2
2
  //import SequelizeDynamo from 'dynamo-sequelize';
3
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';
4
+ import API_MODULE from '../../api/index.js';
5
+ import LOG_MODULE from '../../log/index.js';
6
+ import ERROR_MODULE from '../../error/index.js';
7
7
 
8
8
  import postConnection from '../postConnection/index.js'
9
9
 
10
- const META_SERVICE='DATABASE', META_METHOD='POST', META_ROUTE=META_SERVICE+'_'+META_METHOD;
10
+ const META_MODULE='DATABASE', META_METHOD='POST', META_ROUTE=META_MODULE+'_'+META_METHOD;
11
11
 
12
12
  export default async ({ DB_DIALECT='sqlite', DB_HOST=undefined, DB_PORT=undefined, DB_DB=undefined,
13
13
  DB_USER=undefined, DB_PASS=undefined, DB_STORAGE=':memory:'} = {}) => {
@@ -27,12 +27,12 @@ export default async ({ DB_DIALECT='sqlite', DB_HOST=undefined, DB_PORT=undefine
27
27
  .filter(([key, val]) => val != null)
28
28
  );
29
29
 
30
- LOG_SERVICE.postINFO({ META_ROUTE, DB_VARS });
30
+ LOG_MODULE.postINFO({ META_ROUTE, DB_VARS });
31
31
 
32
- API_SERVICE.get().ORM = new Sequelize(DB_DB, DB_USER, DB_PASS, SEQUELIZE_OPTIONS);
33
- await postConnection(API_SERVICE.get().ORM);
32
+ API_MODULE.get().ORM = new Sequelize(DB_DB, DB_USER, DB_PASS, SEQUELIZE_OPTIONS);
33
+ await postConnection(API_MODULE.get().ORM);
34
34
 
35
35
  } catch (META_METHOD_ERROR) {
36
- ERROR_SERVICE.postCompiletime({ META_ROUTE, META_METHOD_ERROR });
36
+ ERROR_MODULE.postCompiletime({ META_ROUTE, META_METHOD_ERROR });
37
37
  }
38
38
  };
@@ -1,6 +1,6 @@
1
- import LOG_SERVICE from '../../log/index.js';
1
+ import LOG_MODULE from '../../log/index.js';
2
2
 
3
- const META_SERVICE_NAME='DATABASE', META_METHOD_NAME='POST_CONNECTION';
3
+ const META_MODULE_NAME='DATABASE', META_METHOD_NAME='POST_CONNECTION';
4
4
 
5
5
  export default async ORM => {
6
6
  const MAX_RETRIES = 5, INITIAL_WAIT = 100;
@@ -8,7 +8,7 @@ export default async ORM => {
8
8
 
9
9
  while (connectionRetries < MAX_RETRIES) {
10
10
  try {
11
- LOG_SERVICE.post({ META_SERVICE_NAME, META_METHOD_NAME, AUTH_INTENT: connectionRetries });
11
+ LOG_MODULE.post({ META_MODULE_NAME, META_METHOD_NAME, AUTH_INTENT: connectionRetries });
12
12
  await ORM.authenticate();
13
13
  break;
14
14
 
@@ -1,13 +1,13 @@
1
- import API_SERVICE from '../../api/index.js';
2
- import LOG_SERVICE from '../../log/index.js';
1
+ import API_MODULE from '../../api/index.js';
2
+ import LOG_MODULE from '../../log/index.js';
3
3
 
4
- export default ({ META_SERVICE_NAME, META_METHOD_NAME, ROUTE_CODE, META_METHOD_ERROR }) => {
5
- LOG_SERVICE.postERROR({
6
- META_SERVICE_NAME,
4
+ export default ({ META_MODULE_NAME, META_METHOD_NAME, ROUTE_CODE, META_METHOD_ERROR }) => {
5
+ LOG_MODULE.postERROR({
6
+ META_MODULE_NAME,
7
7
  META_METHOD_NAME,
8
8
  ROUTE_CODE,
9
9
  META_METHOD_ERROR,
10
10
  STACK_TRACE: META_METHOD_ERROR?.stack,
11
11
  });
12
- if (API_SERVICE.get().DEV_ENV==='TRUE') throw META_METHOD_ERROR;
12
+ if (API_MODULE.get().DEV_ENV==='TRUE') throw META_METHOD_ERROR;
13
13
  };
@@ -1,7 +1,7 @@
1
- import LOG_SERVICE from '../../log/index.js';
1
+ import LOG_MODULE from '../../log/index.js';
2
2
 
3
3
  export default (res, ROUTE_CODE, METHOD_ERROR) => {
4
4
  const MESSAGE = { ROUTE_CODE, METHOD_ERROR: METHOD_ERROR.stack.toString() };
5
- LOG_SERVICE.postERROR(MESSAGE);
5
+ LOG_MODULE.postERROR(MESSAGE);
6
6
  res.status(500).json(MESSAGE);
7
7
  }
@@ -1,3 +1,3 @@
1
- import API_SERVICE from '../../api/index.js';
1
+ import API_MODULE from '../../api/index.js';
2
2
 
3
3
  export default (...MESSAGE) => { console.log(...MESSAGE); };
@@ -1,3 +1,3 @@
1
- import API_SERVICE from '../../api/index.js';
1
+ import API_MODULE from '../../api/index.js';
2
2
 
3
3
  export default (...ERROR) => { console.error(...ERROR); };
@@ -1,3 +1,3 @@
1
- import API_SERVICE from '../../api/index.js';
1
+ import API_MODULE from '../../api/index.js';
2
2
 
3
- export default (...MESSAGE) => { if (API_SERVICE.get().ERROR_LEVEL===0) { console.log(...MESSAGE); } };
3
+ export default (...MESSAGE) => { if (API_MODULE.get().ERROR_LEVEL===0) { console.log(...MESSAGE); } };
@@ -1,4 +1,4 @@
1
- export default (SERVICE_NAME, METHOD_CODE) => {
1
+ export default (MODULE_NAME, METHOD_CODE) => {
2
2
  const methodPathParts = METHOD_CODE.split(":");
3
3
  const pathParams = methodPathParts.slice(1).map(param => `:${param}`);
4
4
  const rawMethodName = methodPathParts[0];
@@ -6,8 +6,8 @@ export default (SERVICE_NAME, METHOD_CODE) => {
6
6
 
7
7
  const relativeMethodRoute = `${rawMethodName}${pathParams.length > 0 ? '/' : ''}${pathParams.join("/")}`;
8
8
  const METHOD_ROUTE = relativeMethodRoute[0]==='!' ?
9
- `/${relativeMethodRoute.substring(1)}/${SERVICE_NAME}` :
10
- `/${SERVICE_NAME}/${relativeMethodRoute}`;
9
+ `/${relativeMethodRoute.substring(1)}/${MODULE_NAME}` :
10
+ `/${MODULE_NAME}/${relativeMethodRoute}`;
11
11
 
12
12
  return { METHOD_NAME, METHOD_ROUTE };
13
13
  };
@@ -5,8 +5,8 @@ const getUpperSnakeCase = str => {
5
5
  .toUpperCase();
6
6
  }
7
7
 
8
- export default (SERVICE_NAME, METHOD_NAME) => {
9
- const snakeServiceName = getUpperSnakeCase(SERVICE_NAME);
8
+ export default (MODULE_NAME, METHOD_NAME) => {
9
+ const snakeServiceName = getUpperSnakeCase(MODULE_NAME);
10
10
  const snakeMethodName = getUpperSnakeCase(METHOD_NAME);
11
11
  return snakeServiceName + '_' + snakeMethodName;
12
12
  };
@@ -1,44 +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';
1
+ import API_MODULE from '../../api/index.js';
2
+ import LOG_MODULE from '../../log/index.js';
3
+ import EVENT_MODULE from '../../event/index.js';
4
+ import ERROR_MODULE from '../../error/index.js';
5
5
 
6
6
  import getParsedCode from '../getParsedCode/index.js';
7
7
  import getRouteCode from '../getRouteCode/index.js';
8
8
  import getType from '../getType/index.js';
9
9
  import postResponse from '../postResponse/index.js';
10
10
 
11
- const META_SERVICE_NAME='METHOD', META_METHOD_NAME='POST';
11
+ const META_MODULE_NAME='METHOD', META_METHOD_NAME='POST';
12
12
  const CYAN = '\x1b[36m', YELLOW = '\x1b[33m', END = '\x1b[0m';
13
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}`);
14
+ export default async (MODULE_NAME, METHOD_KEY, METHOD) => {
15
+ const { METHOD_NAME, METHOD_ROUTE } = getParsedCode(MODULE_NAME, METHOD_KEY);
16
+ const ROUTE_CODE = getRouteCode(MODULE_NAME, METHOD_NAME);
17
+ //LOG_MODULE.post(` FOUND_METHOD: ${CYAN}${METHOD_NAME}${END}`);
18
18
 
19
19
  try {
20
20
 
21
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 });
22
+ API_MODULE.get().MODULES[MODULE_NAME][METHOD_NAME] = async (body, claims=undefined) => {
23
+ const { MODELS, MODULES } = API_MODULE.get();
24
+ return await METHOD({ MODELS, MODULES, ROUTE_CODE, body, claims });
25
25
  }
26
26
 
27
27
  const METHOD_TYPE = getType(METHOD_NAME);
28
28
 
29
29
  // Register route forn lAMBDA API
30
- LOG_SERVICE.post(` · ${YELLOW}${METHOD_ROUTE}${END}`);
30
+ LOG_MODULE.post(` · ${YELLOW}${METHOD_ROUTE}${END}`);
31
31
 
32
- API_SERVICE.get()[METHOD_TYPE](METHOD_ROUTE, async (event, res) => {
33
- const { body, claims } = EVENT_SERVICE.getParsedEvent(event);
32
+ API_MODULE.get()[METHOD_TYPE](METHOD_ROUTE, async (event, res) => {
33
+ const { body, claims } = EVENT_MODULE.getParsedEvent(event);
34
34
 
35
35
  try {
36
36
  await postResponse(res, ROUTE_CODE, METHOD, METHOD_TYPE, body, claims);
37
37
  }
38
- catch (METHOD_ERROR) { ERROR_SERVICE.postRuntime(res, ROUTE_CODE, METHOD_ERROR); }
38
+ catch (METHOD_ERROR) { ERROR_MODULE.postRuntime(res, ROUTE_CODE, METHOD_ERROR); }
39
39
  });
40
40
 
41
41
  } catch (META_METHOD_ERROR) {
42
- ERROR_SERVICE.postCompiletime({ META_SERVICE_NAME, META_METHOD_NAME, ROUTE_CODE, META_METHOD_ERROR });
42
+ ERROR_MODULE.postCompiletime({ META_MODULE_NAME, META_METHOD_NAME, ROUTE_CODE, META_METHOD_ERROR });
43
43
  }
44
44
  };
@@ -1,13 +1,13 @@
1
- import API_SERVICE from '../../api/index.js';
2
- import LOG_SERVICE from '../../log/index.js';
1
+ import API_MODULE from '../../api/index.js';
2
+ import LOG_MODULE from '../../log/index.js';
3
3
 
4
4
  import getResponseCode from '../getResponseCode/index.js';
5
5
 
6
6
  export default async (res, ROUTE_CODE, METHOD, METHOD_TYPE, body, claims) => {
7
7
 
8
- const { MODELS, SERVICES } = API_SERVICE.get();
8
+ const { MODELS, MODULES } = API_MODULE.get();
9
9
 
10
- const METHOD_RESPONSE = await METHOD({ MODELS, SERVICES, body, claims });
10
+ const METHOD_RESPONSE = await METHOD({ MODELS, MODULES, body, claims });
11
11
  const { status, body: responseBody, cookies, headers } = METHOD_RESPONSE;
12
12
 
13
13
  // status
@@ -23,7 +23,7 @@ export default async (res, ROUTE_CODE, METHOD, METHOD_TYPE, body, claims) => {
23
23
  //console.log('cookie', c.name);
24
24
  res.cookie(c.name, c.value, c.options || {}); });
25
25
 
26
- LOG_SERVICE.post({ ROUTE_CODE, METHOD_RESPONSE });
26
+ LOG_MODULE.post({ ROUTE_CODE, METHOD_RESPONSE });
27
27
 
28
28
  res.status(METHOD_RESPONSE_CODE).json(responseBody);
29
29
  };
@@ -1,19 +1,19 @@
1
- import API_SERVICE from '../../api/index.js';
2
- import LOG_SERVICE from '../../log/index.js';
1
+ import API_MODULE from '../../api/index.js';
2
+ import LOG_MODULE from '../../log/index.js';
3
3
 
4
4
  import CORS_HEADERS from './corsHeaders.js';
5
5
 
6
6
  export default () => {
7
7
 
8
- API_SERVICE.get().use((req, res, next) => {
8
+ API_MODULE.get().use((req, res, next) => {
9
9
  if (req.headers['x-trigger-error']) {
10
- LOG_SERVICE.post({ ROUTE_CODE: 'LAMBDA_API', MESSAGE: 'X_TRIGGER_ERROR_HEADER' });
10
+ LOG_MODULE.post({ ROUTE_CODE: 'LAMBDA_API', MESSAGE: 'X_TRIGGER_ERROR_HEADER' });
11
11
  throw new Error('X_TRIGGER_ERROR_HEADER');
12
12
  }
13
13
  res.cors(); next();
14
14
  });
15
15
 
16
- API_SERVICE.get().options('/*', (req, res) => {
16
+ API_MODULE.get().options('/*', (req, res) => {
17
17
  for (let k in CORS_HEADERS) { res.header(k, CORS_HEADERS[k]); }
18
18
  res.status(200).send({})
19
19
  });
@@ -1,9 +1,9 @@
1
- import API_SERVICE from '../../api/index.js';
2
- import LOG_SERVICE from '../../log/index.js';
1
+ import API_MODULE from '../../api/index.js';
2
+ import LOG_MODULE from '../../log/index.js';
3
3
 
4
4
  export default () => {
5
- API_SERVICE.get().use((err, req, res, next) => {
6
- LOG_SERVICE.postERROR({ ROUTE_CODE: 'LAMBDA_API', ERROR: err });
5
+ API_MODULE.get().use((err, req, res, next) => {
6
+ LOG_MODULE.postERROR({ ROUTE_CODE: 'LAMBDA_API', ERROR: err });
7
7
  res.cors(); //next();
8
8
  res.status(500).send({ ROUTE_CODE: 'LAMBDA_API', ERROR: err.message });
9
9
  });
@@ -1,23 +1,23 @@
1
1
  import { DataTypes } from 'sequelize';
2
2
 
3
- import API_SERVICE from '../../api/index.js';
4
- import LOG_SERVICE from '../../log/index.js';
3
+ import API_MODULE from '../../api/index.js';
4
+ import LOG_MODULE from '../../log/index.js';
5
5
 
6
- const META_SERVICE='MODEL', META_METHOD='GET_SYNCED', META_ROUTE=META_SERVICE+'_'+META_METHOD;
6
+ const META_MODULE='MODEL', META_METHOD='GET_SYNCED', META_ROUTE=META_MODULE+'_'+META_METHOD;
7
7
 
8
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);
9
+ for (const MODULE_NAME of Object.keys(API_MODULE.get().SCHEMAS)) {
10
+ LOG_MODULE.post({ META_ROUTE, LOADING: MODULE_NAME });
11
+ API_MODULE.get().MODELS[MODULE_NAME] = API_MODULE.get().SCHEMAS[MODULE_NAME](API_MODULE.get().ORM, DataTypes);
12
12
  }
13
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);
14
+ for (const [MODULE_NAME, MODEL] of Object.entries(API_MODULE.get().MODELS)) {
15
+ LOG_MODULE.post({ META_ROUTE, ASSOCIATING: MODULE_NAME });
16
+ MODEL.associate(API_MODULE.get().MODELS);
17
17
  }
18
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' });
19
+ LOG_MODULE.post({ META_ROUTE, SYNCING_ORM: 'WAITING_ORM_SYNCING' });
20
+ //await API_MODULE.get().ORM.sync({ alter: process.env.MM_API_DEV_ENV==='TRUE' ? true : false });
21
+ await API_MODULE.get().ORM.sync();
22
+ LOG_MODULE.post({ META_ROUTE, SYNCING_ORM: 'DONE_ORM_SYNCING' });
23
23
  };
@@ -1,16 +1,16 @@
1
1
  import fs from 'fs';
2
2
  import url from 'url';
3
3
 
4
- import API_SERVICE from '../../api/index.js';
5
- import LOG_SERVICE from '../../log/index.js';
4
+ import API_MODULE from '../../api/index.js';
5
+ import LOG_MODULE from '../../log/index.js';
6
6
  const CYAN = '\x1b[36m', YELLOW = '\x1b[33m', END = '\x1b[0m';
7
7
 
8
- export default async (SERVICE_NAME, MODEL) => {
8
+ export default async (MODULE_NAME, MODEL) => {
9
9
  if (!MODEL) {
10
- LOG_SERVICE.post(' MODEL_NOT_FOUND')
10
+ LOG_MODULE.post(' MODEL_NOT_FOUND')
11
11
  return;
12
12
  }
13
13
 
14
- LOG_SERVICE.post(` + MODEL: ${CYAN}${SERVICE_NAME}${END}`)
15
- API_SERVICE.get().SCHEMAS[SERVICE_NAME] = MODEL(SERVICE_NAME);
14
+ LOG_MODULE.post(` + MODEL: ${CYAN}${MODULE_NAME}${END}`)
15
+ API_MODULE.get().SCHEMAS[MODULE_NAME] = MODEL(MODULE_NAME);
16
16
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  import url from 'url';
4
4
 
5
- import LOG_SERVICE from '../../log/index.js';
5
+ import LOG_MODULE from '../../log/index.js';
6
6
 
7
7
  import CORS_HEADERS from '../../middleware/postCors/corsHeaders.js';
8
8
 
@@ -63,7 +63,7 @@ export default lambdaHandler => async (req, res) => {
63
63
  res.end(lambdaRes.body);
64
64
 
65
65
  } catch(SERVER_ERROR) {
66
- LOG_SERVICE.post({ SERVER_ERROR });
66
+ LOG_MODULE.post({ SERVER_ERROR });
67
67
  res.statusCode = 500;
68
68
  for (let k in CORS_HEADERS) res.setHeader(k, CORS_HEADERS[k]);
69
69
  res.end(JSON.stringify({ REQUEST_PARSING_ERROR: SERVER_ERROR.toString() }));
@@ -1,29 +0,0 @@
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
- };