minimonolith 0.15.5 → 0.16.0

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/index.js CHANGED
@@ -1,10 +1,9 @@
1
- import { z } from 'zod';
2
-
1
+ import { z } from './src/zod/index.js';
3
2
  import { createAPI } from './src/api/index.js';
4
3
  import { DB_VALIDATION } from './src/database/index.js';
5
4
 
6
- const devEnvironment = async () => {
7
- return await import('./src/local/index.js');
5
+ const createDevEnvironment = async () => {
6
+ return await import('./src/development/index.js');
8
7
  }
9
8
 
10
- export { devEnvironment, createAPI, z, DB_VALIDATION };
9
+ export { createDevEnvironment, createAPI, z, DB_VALIDATION };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "minimonolith",
3
3
  "type": "module",
4
- "version": "0.15.5",
4
+ "version": "0.16.0",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import url from 'url';
3
3
  import path from 'path';
4
- import { z } from 'zod';
4
+ import { z, optionalZObject } from '../zod/index.js';
5
5
 
6
6
  const registerMethod = async (SERVICE_NAME, SERVICE_URL, METHOD_NAME, METHOD_ROUTE_CODE) => {
7
7
 
@@ -19,7 +19,7 @@ const registerMethod = async (SERVICE_NAME, SERVICE_URL, METHOD_NAME, METHOD_ROU
19
19
  console.log(' FOUND_VALIDATOR');
20
20
 
21
21
  const VALIDATOR_BODY = (await import(VALIDATOR_URL)).default;
22
- method.VALIDATOR = MODELS => z.object(VALIDATOR_BODY(MODELS)).strict();
22
+ method.VALIDATOR = MODELS => optionalZObject(VALIDATOR_BODY(MODELS));
23
23
  }
24
24
 
25
25
  return method;
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+
3
+ import optionalZObject from './optionalZObject.js';
4
+
5
+ export { z, optionalZObject };
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+
3
+ export default zElements => {
4
+ const zObject = z.object(zElements).strict();
5
+ if (!Object.values(zElements).every(zElement => zElement.isOptional())) return zObject;
6
+
7
+ return z.custom(inputBody => inputBody===undefined ? true : zObject.parse(inputBody));
8
+ }
@@ -1,41 +0,0 @@
1
- import fs from 'fs';
2
- import url from 'url';
3
- import path from 'path';
4
- import { z } from 'zod';
5
-
6
- import { parseMethodPathCode } from './parseMethodPathCode.js';
7
- import { getMethodRouteCode } from './getMethodRouteCode.js';
8
-
9
- const registerMethods = methodPathCodes => async (SERVICE_NAME, SERVICE_URL) => {
10
- let ROUTE_CODE = 'REGISTER_METHODS';
11
-
12
- try {
13
- const methods = await methodPathCodes.reduce(async (prevMethods, METHOD_PATH_CODE) => {
14
- const methods = await prevMethods;
15
- const { METHOD_NAME } = parseMethodPathCode(METHOD_PATH_CODE);
16
- ROUTE_CODE = 'REGISTER_METHODS_' + getMethodRouteCode(SERVICE_NAME, METHOD_NAME);
17
- console.log(' FOUND_METHOD', METHOD_NAME);
18
-
19
- methods[METHOD_PATH_CODE] = { VALIDATOR: (MODELS, ROUTE_CODE) => z.undefined() };
20
- methods[METHOD_PATH_CODE].handler =
21
- (await import(new URL(`${METHOD_NAME}/index.js`, SERVICE_URL))).default;
22
-
23
- const VALIDATOR_URL = new URL(`${METHOD_NAME}/valid.js`, SERVICE_URL);
24
- if (fs.existsSync(url.fileURLToPath(VALIDATOR_URL))) {
25
- console.log(' FOUND_VALIDATOR');
26
- const VALIDATOR_BODY = (await import(VALIDATOR_URL)).default;
27
- methods[METHOD_PATH_CODE].VALIDATOR = (MODELS, ROUTE_CODE) =>
28
- z.object(VALIDATOR_BODY(MODELS, ROUTE_CODE)).strict();
29
- }
30
-
31
- return methods;
32
- }, Promise.resolve({}));
33
-
34
- return methods;
35
- } catch (REGISTER_METHOD_ERROR) {
36
- console.error({ ROUTE_CODE, REGISTER_METHOD_ERROR,
37
- STACK_TRASE: REGISTER_METHOD_ERROR.stack });
38
- }
39
- };
40
-
41
- export { registerMethods };
File without changes
File without changes
File without changes
File without changes