minimonolith 0.25.24 → 0.26.2

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 (183) hide show
  1. package/README.md +55 -80
  2. package/backtest/back.js +54 -0
  3. package/backtest/backtest.js +131 -0
  4. package/backtest/handler.js +23 -0
  5. package/backtest/handlerCompiletimeError.js +10 -0
  6. package/backtest/handlerCompiletimeError2.js +10 -0
  7. package/backtest/handlerRuntimeError.js +24 -0
  8. package/backtest/localDocker/Dockerfile +11 -0
  9. package/backtest/localDocker/docker-compose.yml +34 -0
  10. package/backtest/localDocker/run.sh +4 -0
  11. package/backtest/localDocker/shutdown.sh +2 -0
  12. package/backtest/localDocker/update.sh +2 -0
  13. package/backtest/server.js +7 -0
  14. package/backtest/todo/delete/index.js +7 -0
  15. package/backtest/todo/delete/valid.js +8 -0
  16. package/backtest/todo/get/index.js +3 -0
  17. package/backtest/todo/getAttributes/index.js +5 -0
  18. package/backtest/todo/getAttributes/valid.js +5 -0
  19. package/backtest/todo/getOne/index.js +3 -0
  20. package/backtest/todo/getOne/valid.js +8 -0
  21. package/backtest/todo/getOneAlias/index.js +3 -0
  22. package/backtest/todo/getOneAlias/valid.js +3 -0
  23. package/backtest/todo/index.js +1 -0
  24. package/backtest/todo/model.js +19 -0
  25. package/backtest/todo/patch/index.js +6 -0
  26. package/backtest/todo/patch/valid.js +12 -0
  27. package/backtest/todo/post/index.js +5 -0
  28. package/backtest/todo/post/valid.js +5 -0
  29. package/backtest/todo/postSeed/index.js +9 -0
  30. package/backtest/todo/postSeed/seed.js +4 -0
  31. package/backtest/todoCompiletimeError/got/index.js +1 -0
  32. package/backtest/todoCompiletimeError/index.js +1 -0
  33. package/backtest/todoList/delete/handler.js +7 -0
  34. package/backtest/todoList/delete/valid.js +5 -0
  35. package/backtest/todoList/get/handler.js +5 -0
  36. package/backtest/todoList/index.js +1 -0
  37. package/backtest/todoList/model.js +17 -0
  38. package/backtest/todoList/post/handler.js +9 -0
  39. package/backtest/todoList/post/valid.js +6 -0
  40. package/backtest/todoRuntimeError/get/index.js +1 -0
  41. package/index.js +13 -22
  42. package/package.json +7 -8
  43. package/src/api/get/index.js +17 -0
  44. package/src/api/getNewAPI/index.js +11 -0
  45. package/src/api/getSyncedHandler/index.js +23 -0
  46. package/src/api/index.js +4 -0
  47. package/src/api/postService/index.js +29 -0
  48. package/src/autotest/getMethodTest/back.index.js +29 -0
  49. package/{autotest/getMethodTest/handler.js → src/autotest/getMethodTest/index.js} +1 -3
  50. package/src/autotest/index.js +3 -0
  51. package/src/database/index.js +4 -0
  52. package/src/database/post/index.js +38 -0
  53. package/src/database/postConnection/index.js +25 -0
  54. package/src/error/index.js +4 -0
  55. package/src/error/postCompiletime/index.js +13 -0
  56. package/src/error/postRuntime/index.js +7 -0
  57. package/src/event/getParsedEvent/index.js +9 -0
  58. package/src/event/index.js +3 -0
  59. package/src/log/index.js +5 -0
  60. package/src/log/post/index.js +3 -0
  61. package/src/log/postERROR/index.js +3 -0
  62. package/src/log/postINFO/index.js +3 -0
  63. package/src/method/getParsedCode/index.js +13 -0
  64. package/{service/getResponseCode/handler.js → src/method/getResponseCode/index.js} +1 -3
  65. package/src/method/getRouteCode/index.js +12 -0
  66. package/src/method/getType/index.js +9 -0
  67. package/src/method/index.js +7 -0
  68. package/src/method/post/index.js +44 -0
  69. package/src/method/postResponse/index.js +29 -0
  70. package/src/middleware/index.js +4 -0
  71. package/src/middleware/postCors/index.js +20 -0
  72. package/src/middleware/postError/index.js +10 -0
  73. package/src/model/getSynced/index.js +23 -0
  74. package/src/model/index.js +4 -0
  75. package/src/model/post/index.js +16 -0
  76. package/{server → src/server}/getNodejsServerHandler/index.js +13 -7
  77. package/src/server/getServerFactory/index.js +12 -0
  78. package/src/server/index.js +3 -0
  79. package/api/api.js +0 -5
  80. package/api/getModels/handler.js +0 -5
  81. package/api/getModels/out.js +0 -3
  82. package/api/getNewAPI/handler.js +0 -46
  83. package/api/getNewAPI/in.js +0 -8
  84. package/api/getNewAPI/out.js +0 -3
  85. package/api/getORM/handler.js +0 -5
  86. package/api/getORM/out.js +0 -3
  87. package/api/getSchemas/handler.js +0 -5
  88. package/api/getSchemas/out.js +0 -3
  89. package/api/getService/handler.js +0 -8
  90. package/api/getService/in.js +0 -6
  91. package/api/getService/out.js +0 -3
  92. package/api/getServices/handler.js +0 -5
  93. package/api/getServices/out.js +0 -3
  94. package/api/getSyncedHandler/handler.js +0 -28
  95. package/api/getSyncedHandler/in.js +0 -3
  96. package/api/getSyncedHandler/out.js +0 -3
  97. package/api/postDebug/handler.js +0 -5
  98. package/api/postDebug/in.js +0 -3
  99. package/api/postError/handler.js +0 -5
  100. package/api/postError/in.js +0 -3
  101. package/api/postInfo/handler.js +0 -5
  102. package/api/postInfo/in.js +0 -3
  103. package/api/postModel/handler.js +0 -8
  104. package/api/postModel/in.js +0 -6
  105. package/api/postModule/handler.js +0 -31
  106. package/api/postModule/in.js +0 -7
  107. package/api/postORM/handler.js +0 -7
  108. package/api/postORM/in.js +0 -5
  109. package/api/postRawModule/handler.js +0 -9
  110. package/api/postRawModule/in.js +0 -9
  111. package/api/postRoute/handler.js +0 -9
  112. package/api/postRoute/in.js +0 -7
  113. package/api/postSchema/handler.js +0 -8
  114. package/api/postSchema/in.js +0 -6
  115. package/api/services.js +0 -18
  116. package/autotest/getMethodTest/in.js +0 -3
  117. package/autotest/getMethodTest/out.js +0 -3
  118. package/autotest/services.js +0 -1
  119. package/control/get/handler.js +0 -8
  120. package/control/get/in.js +0 -6
  121. package/control/get/out.js +0 -3
  122. package/database/post/handler.js +0 -24
  123. package/database/post/in.js +0 -12
  124. package/database/postConnection/handler.js +0 -25
  125. package/database/postConnection/in.js +0 -5
  126. package/database/postConnection/out.js +0 -3
  127. package/database/services.js +0 -1
  128. package/environment/getDBEnvVars/handler.js +0 -6
  129. package/environment/getDBEnvVars/in.js +0 -3
  130. package/environment/getDBEnvVars/out.js +0 -3
  131. package/environment/getENVEnvVars/handler.js +0 -7
  132. package/environment/getENVEnvVars/in.js +0 -3
  133. package/environment/getENVEnvVars/out.js +0 -3
  134. package/environment/postEnvFile/handler.js +0 -16
  135. package/environment/postEnvFile/in.js +0 -6
  136. package/environment/postTestEnvironment/index.js +0 -6
  137. package/environment/services.js +0 -5
  138. package/health/post/handler.js +0 -11
  139. package/health/services.js +0 -1
  140. package/model/getSynced/handler.js +0 -29
  141. package/model/post/handler.js +0 -14
  142. package/model/post/in.js +0 -6
  143. package/model/services.js +0 -1
  144. package/modules.js +0 -19
  145. package/server/getServerFactory/handler.js +0 -17
  146. package/server/getServerFactory/in.js +0 -8
  147. package/server/getServerFactory/out.js +0 -3
  148. package/server/services.js +0 -1
  149. package/service/getParsedCode/handler.js +0 -19
  150. package/service/getParsedCode/in.js +0 -6
  151. package/service/getParsedCode/out.js +0 -6
  152. package/service/getParsedEvent/handler.js +0 -12
  153. package/service/getParsedEvent/in.js +0 -5
  154. package/service/getParsedEvent/out.js +0 -6
  155. package/service/getResponseCode/in.js +0 -3
  156. package/service/getResponseCode/out.js +0 -3
  157. package/service/getRouteCode/handler.js +0 -15
  158. package/service/getRouteCode/in.js +0 -6
  159. package/service/getRouteCode/out.js +0 -3
  160. package/service/getType/handler.js +0 -11
  161. package/service/getType/in.js +0 -5
  162. package/service/getType/out.js +0 -3
  163. package/service/postRoute/handler.js +0 -105
  164. package/service/postRoute/in.js +0 -6
  165. package/service/services.js +0 -9
  166. package/setupTesting.js +0 -17
  167. package/validation/getParsedAsync/handler.js +0 -37
  168. package/validation/getParsedAsync/in.js +0 -9
  169. package/validation/getParsedAsync/out.js +0 -6
  170. package/validation/services.js +0 -1
  171. package/zdb/components.js +0 -1
  172. package/zdb/getAssertExists/handler.js +0 -16
  173. package/zdb/getAssertExists/in.js +0 -6
  174. package/zdb/getAssertExists/out.js +0 -3
  175. package/zdb/getAssertNotExists/handler.js +0 -16
  176. package/zdb/getAssertNotExists/in.js +0 -6
  177. package/zdb/getAssertNotExists/out.js +0 -3
  178. package/zdb/getAssertSafeInt/handler.js +0 -15
  179. package/zdb/getAssertSafeInt/in.js +0 -6
  180. package/zdb/getAssertSafeInt/out.js +0 -3
  181. /package/{control/services.js → backtest/todoRuntimeError/index.js} +0 -0
  182. /package/{autotest → src/autotest}/getTestServerResponse/index.js +0 -0
  183. /package/{api → src/middleware/postCors}/corsHeaders.js +0 -0
@@ -1,6 +0,0 @@
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,5 +0,0 @@
1
- export default [
2
- //'getENVEnvVars',
3
- //'getDBEnvVars',
4
- 'postEnvFile'
5
- ];
@@ -1,11 +0,0 @@
1
- export default async ({ SERVICES }) => {
2
- const method = 'get';
3
- const route = '/';
4
- const handler = async (req, res) => {
5
- const SERVICE_RESPONSE = "API_RUNNING";
6
- await SERVICES.api.postInfo.handler({ SERVICE_RESPONSE });
7
- return { SERVICE_RESPONSE: "API_RUNNING" };
8
- }
9
-
10
- await SERVICES.api.postRoute.handler({ method, route, handler })
11
- }
@@ -1 +0,0 @@
1
- export default ['post'];
@@ -1,29 +0,0 @@
1
- import { DataTypes } from 'sequelize';
2
-
3
- export default async ({ ROUTE_CODE, SERVICES }) => {
4
- const SCHEMAS = await SERVICES.api.getSchemas.handler();
5
- const ORM = await SERVICES.api.getORM.handler();
6
-
7
- for (const moduleName of Object.keys(SCHEMAS)) {
8
- await SERVICES.api.postInfo.handler({
9
- ROUTE_CODE, LOADING: moduleName });
10
-
11
- const model = SCHEMAS[moduleName](ORM, DataTypes);
12
- await SERVICES.api.postModel.handler({ moduleName, model });
13
- }
14
-
15
- const MODELS = await SERVICES.api.getModels.handler();
16
-
17
- for (const [moduleName, MODEL] of Object.entries(MODELS)) {
18
- await SERVICES.api.postInfo.handler({
19
- ROUTE_CODE, ASSOCIATING: moduleName });
20
- MODEL.associate(MODELS);
21
- }
22
-
23
- await SERVICES.api.postInfo.handler({
24
- ROUTE_CODE, SYNCING_ORM: 'WAITING_ORM_SYNCING' });
25
- await ORM.sync({ alter: process.env.DEV_ENV==='TRUE' ? true : false });
26
-
27
- await SERVICES.api.postInfo.handler({
28
- ROUTE_CODE, SYNCING_ORM: 'DONE_ORM_SYNCING' });
29
- };
@@ -1,14 +0,0 @@
1
- import fs from 'fs';
2
- import url from 'url';
3
-
4
- export default async ({ body, SERVICES }) => {
5
- const moduleName = body.moduleName;
6
- const moduleURL = body.moduleURL;
7
-
8
- if (!fs.existsSync(url.fileURLToPath(`${moduleURL}model.js`))) return;
9
- await SERVICES.api.postInfo.handler(` FOUND_MODEL ${moduleName}`)
10
-
11
- const moduleSchema =
12
- (await import(`${moduleURL}model.js`)).default(moduleName);
13
- await SERVICES.api.postSchema.handler({ moduleName, moduleSchema });
14
- };
package/model/post/in.js DELETED
@@ -1,6 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => ({
4
- moduleName: z.string(),
5
- moduleURL: z.unknown(),
6
- });
package/model/services.js DELETED
@@ -1 +0,0 @@
1
- export default ['getSynced', 'post'];
package/modules.js DELETED
@@ -1,19 +0,0 @@
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
- ];
@@ -1,17 +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 ({ body, SERVICES }) => {
7
- const envFile = body.envFile;
8
- const modulesFolder = body.modulesFolder;
9
-
10
- await SERVICES.environment.postEnvFile.handler({ envFile, modulesFolder });
11
-
12
- return (lambdaHandler) => {
13
- const serverHandler = getNodejsServerHandler(lambdaHandler);
14
- const server = http.createServer(serverHandler);
15
- return server;
16
- }
17
- }
@@ -1,8 +0,0 @@
1
- import path from 'path';
2
-
3
- import { z } from '@minimonolith/lib';
4
-
5
- export default () => ({
6
- envFile: z.string().default('.env'),
7
- modulesFolder: z.string().default('node_modules'+path.sep),
8
- });
@@ -1,3 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => z.function();
@@ -1 +0,0 @@
1
- export default ['getServerFactory'];
@@ -1,19 +0,0 @@
1
- export default ({ body }) => {
2
- const moduleName = body.moduleName;
3
- const serviceCode = body.serviceCode;
4
-
5
- const servicePathParts = serviceCode.split(":");
6
- const pathParams = servicePathParts.slice(1).map(param => `:${param}`);
7
- const rawServiceName = servicePathParts[0];
8
- const serviceName = rawServiceName[0] === '!' ?
9
- rawServiceName.substring(1) : rawServiceName;
10
-
11
- const relativeServiceRoute = `${rawServiceName}`+
12
- `${pathParams.length > 0 ? '/' : ''}${pathParams.join("/")}`;
13
-
14
- const serviceRoute = relativeServiceRoute[0]==='!' ?
15
- `/${relativeServiceRoute.substring(1)}/${moduleName}` :
16
- `/${moduleName}/${relativeServiceRoute}`;
17
-
18
- return { serviceName, serviceRoute };
19
- };
@@ -1,6 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => ({
4
- moduleName: z.string(),
5
- serviceCode: z.string(),
6
- });
@@ -1,6 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => ({
4
- serviceName: z.string(),
5
- serviceRoute: z.string(),
6
- });
@@ -1,12 +0,0 @@
1
- export default ({ body }) => {
2
- const event = body.event;
3
-
4
- const { params, query, requestContext } = event;
5
- const claims = requestContext.authorizer?.jwt?.claims
6
-
7
- const tempUnifiedBody = { ...event.body, ...params, ...query };
8
- const unifiedBody = Object.keys(tempUnifiedBody).length > 0 ?
9
- tempUnifiedBody : undefined;
10
-
11
- return { body: unifiedBody, claims };
12
- }
@@ -1,5 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => ({
4
- event: z.unknown(),
5
- });
@@ -1,6 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => ({
4
- body: z.unknown(),
5
- claims: z.unknown(),
6
- });
@@ -1,3 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => z.enum(['get','post','patch','put','delete']);
@@ -1,3 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => z.number();
@@ -1,15 +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 ({ body }) => {
9
- const moduleName = body.moduleName;
10
- const serviceName = body.serviceName;
11
-
12
- const snakeModuleName = getUpperSnakeCase(moduleName);
13
- const snakeServiceName = getUpperSnakeCase(serviceName);
14
- return snakeModuleName + '_' + snakeServiceName;
15
- };
@@ -1,6 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => ({
4
- moduleName: z.string(),
5
- serviceName: z.string(),
6
- });
@@ -1,3 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => z.string();
@@ -1,11 +0,0 @@
1
- const methodsAvailable = ['post', 'get', 'patch', 'put', 'delete'];
2
-
3
- export default ({ body }) => {
4
- const serviceName = body.serviceName;
5
-
6
- const methodMatched = serviceName.match(/^[a-z]*/);
7
- if (!methodMatched || !methodsAvailable.includes(methodMatched[0]))
8
- throw new Error('UNKNOWN_METHOD_TYPE: ' + serviceName);
9
-
10
- return methodMatched[0];
11
- }
@@ -1,5 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => ({
4
- serviceName: z.string(),
5
- });
@@ -1,3 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => z.string();
@@ -1,105 +0,0 @@
1
- export default async ({ body, ROUTE_CODE, SERVICES }) => {
2
- const moduleName = body.moduleName;
3
- const serviceCode = body.serviceCode;
4
-
5
- const { serviceName, serviceRoute } = await SERVICES.service
6
- .getParsedCode.handler({ moduleName, serviceCode });
7
-
8
- const service =
9
- await SERVICES.api.getService.handler({ moduleName, serviceName });
10
-
11
- const ADDITIONAL_KEYS = { MODELS: await SERVICES.api.getModels.handler() };
12
-
13
- const handler = async (event, res) => {
14
- const { body: inBody, claims } =
15
- await SERVICES.service.getParsedEvent.handler({ event });
16
-
17
- let parsedInBody = inBody;
18
-
19
- try {
20
- const validationIn = await SERVICES.validation
21
- .getParsedAsync.handler({ ROUTE_CODE: ROUTE_CODE+'_IN',
22
- VALIDATOR: service.in, input: inBody });
23
-
24
- if (validationIn?.error) {
25
- await SERVICES.api.postInfo.handler({
26
- VALIDATION_ERROR: validationIn.error });
27
- res.status(400).json(validationIn.error);
28
- return;
29
- }
30
-
31
- if (validationIn) parsedInBody = validationIn.parsedBody;
32
- } catch (SERVICE_ERROR) {
33
- const serviceRouteCode =
34
- await SERVICES.service.getRouteCode.handler({
35
- moduleName, serviceName });
36
-
37
- await SERVICES.api.postError.handler({
38
- STAGE: 'VALIDATION_IN',
39
- [serviceRouteCode]: SERVICE_ERROR });
40
-
41
- res.status(500).json({
42
- [serviceRouteCode]: SERVICE_ERROR.toString() });
43
- return;
44
- }
45
-
46
- let outBody = undefined;
47
- try {
48
- outBody = await service
49
- .rawHandler(parsedInBody, claims);
50
-
51
- } catch (SERVICE_ERROR) {
52
- if (!service.error) {
53
- const serviceRouteCode =
54
- await SERVICES.service.getRouteCode.handler({
55
- moduleName, serviceName });
56
-
57
- await SERVICES.api.postError.handler({
58
- STAGE: 'HANDLER',
59
- [serviceRouteCode]: SERVICE_ERROR });
60
-
61
- res.status(500).json({
62
- [serviceRouteCode]: SERVICE_ERROR.toString() });
63
- return;
64
- }
65
-
66
- outBody = await service.error(parsedInBody, claims);
67
- }
68
-
69
- let parsedOutBody = outBody;
70
-
71
- try {
72
- const validationOut = await SERVICES.validation
73
- .getParsedAsync.handler({ ROUTE_CODE: ROUTE_CODE+'_OUT',
74
- VALIDATOR: service.out, input: outBody });
75
-
76
- if (validationOut?.error) {
77
- await SERVICES.api.postInfo.handler({
78
- VALIDATION_ERROR: validationOut.error });
79
- res.status(400).json(validationOut.error);
80
- return;
81
- }
82
-
83
- if (validationOut) parsedOutBody = validationOut.parsedBody;
84
- } catch (SERVICE_ERROR) {
85
- const serviceRouteCode =
86
- await SERVICES.service.getRouteCode.handler({
87
- moduleName, serviceName });
88
-
89
- await SERVICES.api.postError.handler({
90
- STAGE: 'VALIDATION_OUT',
91
- [serviceRouteCode]: SERVICE_ERROR });
92
-
93
- res.status(500).json({
94
- [serviceRouteCode]: SERVICE_ERROR.toString() });
95
- return;
96
- }
97
-
98
- const serviceResponseCode =
99
- await SERVICES.service.getResponseCode.handler(service.type);
100
- return res.status(serviceResponseCode).json(parsedOutBody);
101
- };
102
-
103
- await SERVICES.api.postRoute.handler({
104
- method: service.type, route: serviceRoute, handler });
105
- };
@@ -1,6 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => ({
4
- moduleName: z.string(),
5
- serviceCode: z.string(),
6
- });
@@ -1,9 +0,0 @@
1
- export default [
2
- 'postRoute',
3
- 'getParsedCode',
4
- //'getType',
5
- 'getRouteCode',
6
- //'postResponse',
7
- 'getParsedEvent',
8
- 'getResponseCode',
9
- ];
package/setupTesting.js DELETED
@@ -1,17 +0,0 @@
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({ LOG_LEVEL: 1 });
7
-
8
- await Promise.all(modules.map(module => LIB.postModule(module)));
9
-
10
- const { SERVICES, COMPONENTS } = LIB;
11
- const zdb = COMPONENTS.zdb;
12
- const database = SERVICES.database;
13
- const getServerFactory = SERVICES.server.getServerFactory.handler;
14
- const autotest = SERVICES.autotest;
15
- const getNewAPI = SERVICES.api.getNewAPI.handler;
16
-
17
- export { z, zdb, database, getServerFactory, autotest, getNewAPI };
@@ -1,37 +0,0 @@
1
- import { VALIDATION_MODULE } from '@minimonolith/lib';
2
-
3
- export default async ({ body, SERVICES }) => {
4
- const ROUTE_CODE = body.ROUTE_CODE;
5
- const VALIDATOR = body.VALIDATOR;
6
- const input = body.input;
7
- const ADDITIONAL_KEYS = body.ADDITIONAL_KEYS;
8
-
9
- const apiServices = await SERVICES.api.getServices.handler();
10
-
11
- //const EVENT_CONTEXT = { SERVICES: apiServices, body: input };
12
- const EVENT_CONTEXT = input;
13
-
14
- if (!VALIDATOR && input) {
15
- const MESSAGE = { ROUTE_CODE, VALIDATION_ERROR: 'BODY_NOT_ALLOWED' };
16
- await SERVICES.api.postInfo.handler(MESSAGE);
17
- return { error: MESSAGE };
18
- }
19
-
20
- if (!VALIDATOR) return undefined;
21
-
22
- const zodobject = await VALIDATION_MODULE.getZodObject(ROUTE_CODE,
23
- VALIDATOR(EVENT_CONTEXT));
24
-
25
- const VALIDATION_RESULT = await VALIDATION_MODULE.getZodObject(ROUTE_CODE,
26
- VALIDATOR(EVENT_CONTEXT)).safeParseAsync(input);
27
- const VALIDATION_ERROR = VALIDATION_RESULT.error?.format();
28
-
29
- if (VALIDATION_ERROR) {
30
- const MESSAGE = { ROUTE_CODE,
31
- VALIDATION_ERROR: JSON.stringify(VALIDATION_ERROR) };
32
- //await SERVICES.api.postInfo.handler(MESSAGE);
33
- return { error: MESSAGE };
34
- }
35
-
36
- return { parsedBody: VALIDATION_RESULT.data };
37
- }
@@ -1,9 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => ({
4
- ROUTE_CODE: z.string(),
5
- VALIDATOR: z.unknown(),
6
- input: z.unknown(),
7
- //ADDITIONAL_KEYS: z.object(),
8
- ADDITIONAL_KEYS: z.unknown(),
9
- });
@@ -1,6 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => ({
4
- error: z.unknown().optional(),
5
- parsedBody: z.unknown().optional(),
6
- });
@@ -1 +0,0 @@
1
- export default ['getParsedAsync'];
package/zdb/components.js DELETED
@@ -1 +0,0 @@
1
- export default ['getAssertExists', 'getAssertNotExists', 'getAssertSafeInt'];
@@ -1,16 +0,0 @@
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
- }
@@ -1,6 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => ({
4
- model: z.unknown(),
5
- field: z.string(),
6
- });
@@ -1,3 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => z.function();
@@ -1,16 +0,0 @@
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
- }
@@ -1,6 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => ({
4
- model: z.unknown(),
5
- field: z.string(),
6
- });
@@ -1,3 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => z.function();
@@ -1,15 +0,0 @@
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
- }
@@ -1,6 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => ({
4
- model: z.unknown(),
5
- field: z.string(),
6
- });
@@ -1,3 +0,0 @@
1
- import { z } from '@minimonolith/lib';
2
-
3
- export default () => z.function();
File without changes