minimonolith 0.21.2 → 0.22.1
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 +57 -32
- package/index.js +14 -5
- package/package.json +2 -1
- package/src/api/get/index.js +19 -0
- package/src/api/getNewAPI/index.js +13 -0
- package/src/api/getSyncedHandler/index.js +24 -0
- package/src/api/index.js +3 -3
- package/src/api/postService/index.js +32 -0
- package/src/autotest/getMethodTest/back.index.js +29 -0
- package/src/autotest/getMethodTest/index.js +12 -0
- package/src/autotest/getTestServerResponse/index.js +14 -0
- package/src/autotest/index.js +3 -0
- package/src/control/get/index.js +3 -0
- package/src/control/index.js +3 -0
- package/src/database/index.js +3 -3
- package/src/database/post/index.js +28 -0
- package/src/database/postConnection/index.js +25 -0
- package/src/environment/getDBEnvVars/index.js +4 -0
- package/src/environment/getENVEnvVars/index.js +4 -0
- package/src/environment/index.js +4 -0
- package/src/{development/loadEnvFile.js → environment/postEnvFile/index.js} +4 -5
- package/src/environment/postTestEnvironment/index.js +6 -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/health/index.js +2 -2
- package/src/health/post/index.js +10 -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/postQA/index.js +3 -0
- package/src/{service/parseMethodCode.js → method/getParsedCode/index.js} +1 -1
- package/src/method/getResponseCode/index.js +9 -0
- package/src/{service/getMethodRouteCode.js → method/getRouteCode/index.js} +2 -4
- package/src/{service/getMethodType.js → method/getType/index.js} +1 -3
- package/src/method/index.js +7 -0
- package/src/method/post/index.js +48 -0
- package/src/method/postResponse/index.js +13 -0
- package/src/middleware/index.js +4 -0
- package/src/middleware/postCors/index.js +21 -0
- package/src/middleware/postError/index.js +10 -0
- package/src/model/getSynced/index.js +22 -0
- package/src/model/index.js +3 -2
- package/src/model/post/index.js +11 -0
- package/src/path/{getProjectRoot.js → getProjectRoot/index.js} +1 -3
- package/src/path/index.js +2 -2
- package/src/{development/serverHandler.js → server/getNodejsServerHandler/index.js} +19 -22
- package/src/server/getServerFactory/index.js +13 -0
- package/src/server/index.js +3 -0
- package/src/{database/validation.js → validation/dbValidation.js} +1 -3
- package/src/validation/get/index.js +19 -0
- package/src/{zod/optionalZObject.js → validation/getOptionalObject/index.js} +1 -1
- package/src/validation/index.js +8 -0
- package/src/validation/postError/index.js +15 -0
- package/src/api/apiHandler.js +0 -13
- package/src/api/createAPI.js +0 -51
- package/src/crasher/crasher.js +0 -1
- package/src/crasher/index.js +0 -3
- package/src/database/databaseService.js +0 -49
- package/src/development/createDevEnvironment.js +0 -10
- package/src/development/createTestEnvironment.js +0 -9
- package/src/development/index.js +0 -4
- package/src/development/lambdaServer.js +0 -11
- package/src/health/healthService.js +0 -15
- package/src/logger/index.js +0 -3
- package/src/logger/logger.js +0 -5
- package/src/model/loadModels.js +0 -33
- package/src/service/index.js +0 -4
- package/src/service/methodHandler.js +0 -25
- package/src/service/registerMethod.js +0 -36
- package/src/service/registerService.js +0 -70
- package/src/zod/index.js +0 -5
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import url from 'url'
|
|
3
|
-
|
|
4
|
-
import { getProjectRoot } from '../path/index.js';
|
|
5
|
-
import { registerModel } from '../model/index.js';
|
|
6
|
-
import { logger } from '../logger/index.js';
|
|
7
|
-
import { crasher } from '../crasher/index.js';
|
|
8
|
-
import { methodHandler } from './methodHandler.js';
|
|
9
|
-
import { getMethodType } from './getMethodType.js';
|
|
10
|
-
import { getMethodRouteCode } from './getMethodRouteCode.js';
|
|
11
|
-
import { parseMethodCode } from './parseMethodCode.js';
|
|
12
|
-
import { registerMethod } from './registerMethod.js';
|
|
13
|
-
|
|
14
|
-
const ROUTE_CODE = 'REGISTER_SERVICE';
|
|
15
|
-
|
|
16
|
-
const registerService = async (API, SERVICE_NAME, SRC_FOLDER, MODULE_FOLDER) => {
|
|
17
|
-
try {
|
|
18
|
-
logger.log(ROUTE_CODE, SERVICE_NAME);
|
|
19
|
-
const PROJECT_ROOT_PATH = getProjectRoot(import.meta.url, MODULE_FOLDER)+'/';
|
|
20
|
-
const PROJECT_RELATIVE_SERVICE_PATH = './' + SRC_FOLDER + `${SERVICE_NAME}/`;
|
|
21
|
-
const SERVICE_URL = new URL(PROJECT_RELATIVE_SERVICE_PATH, PROJECT_ROOT_PATH);
|
|
22
|
-
|
|
23
|
-
const SERVICE_MODULE = await import(`${SERVICE_URL}index.js`);
|
|
24
|
-
if (fs.existsSync(url.fileURLToPath(`${SERVICE_URL}model.js`))) {
|
|
25
|
-
logger.log(' FOUND_MODEL');
|
|
26
|
-
registerModel(SERVICE_NAME, SERVICE_URL);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
logger.log('METHODS_TO_BE_REGISTERED', SERVICE_MODULE.default);
|
|
30
|
-
|
|
31
|
-
API.SERVICES[SERVICE_NAME] = {}; const SERVICE_METHODS = [];
|
|
32
|
-
for (const METHOD_CODE of SERVICE_MODULE.default) {
|
|
33
|
-
const { METHOD_NAME, METHOD_ROUTE } = parseMethodCode(SERVICE_NAME, METHOD_CODE);
|
|
34
|
-
logger.log('REGISTERING_ROUTE', METHOD_ROUTE);
|
|
35
|
-
|
|
36
|
-
const METHOD_ROUTE_CODE = getMethodRouteCode(SERVICE_NAME, METHOD_NAME);
|
|
37
|
-
|
|
38
|
-
SERVICE_METHODS[METHOD_CODE] = await registerMethod(SERVICE_NAME, SERVICE_URL,
|
|
39
|
-
METHOD_NAME, METHOD_ROUTE_CODE);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
API.SERVICES[SERVICE_NAME][METHOD_NAME] = async (body, claims=undefined) => {
|
|
43
|
-
const EVENT_CONTEXT = { MODELS: API.MODELS, SERVICES: API.SERVICES, ROUTE_CODE: METHOD_ROUTE_CODE };
|
|
44
|
-
return await SERVICE_METHODS[METHOD_CODE].handler({ ...EVENT_CONTEXT, body, claims });
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const methodType = getMethodType(METHOD_NAME);
|
|
48
|
-
API[methodType](METHOD_ROUTE, async (event, res) => {
|
|
49
|
-
const { body, params, query } = event;
|
|
50
|
-
const claims = event.requestContext.authorizer?.jwt?.claims
|
|
51
|
-
|
|
52
|
-
const parsedBody = body || Object.keys(params).length > 0 || Object.keys(query).length > 0 ?
|
|
53
|
-
{ ...body, ...params, ...query } : undefined;
|
|
54
|
-
|
|
55
|
-
const EVENT_CONTEXT = { MODELS: API.MODELS, SERVICES: API.SERVICES, ROUTE_CODE: METHOD_ROUTE_CODE };
|
|
56
|
-
await methodHandler(res, SERVICE_METHODS[METHOD_CODE], { ...EVENT_CONTEXT, body: parsedBody, claims });
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
} catch (REGISTER_SERVICE_ERROR) {
|
|
60
|
-
logger.error({
|
|
61
|
-
ROUTE_CODE,
|
|
62
|
-
SERVICE_NAME,
|
|
63
|
-
REGISTER_SERVICE_ERROR,
|
|
64
|
-
STACK_TRASE: REGISTER_SERVICE_ERROR.stack,
|
|
65
|
-
});
|
|
66
|
-
crasher(REGISTER_SERVICE_ERROR);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export { registerService };
|