@sumor/api-middleware
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "@sumor/api-middleware", | ||
"description": "API Middleware is a middleware for Node.JS. It can easily expose function to api, and validate parameters", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "repository": "sumor-cloud/api-middleware", |
@@ -5,2 +5,3 @@ # api-middleware | ||
[More Documentation](https://sumor.cloud/api-middleware) | ||
API Middleware is a middleware for Node.JS. | ||
@@ -24,3 +25,3 @@ It can easily expose function to api, and validate parameters | ||
Require Node.JS version 16.x or above | ||
Require Node.JS version 18.x or above | ||
@@ -42,3 +43,3 @@ ### require Node.JS ES module | ||
##### 1. Add a file named `plus.js` in your project folder `api` | ||
1. Add a file named `plus.js` in your project folder `api` | ||
@@ -53,3 +54,3 @@ ```js | ||
##### [Optional] 2. Add a file named `plus.json` in your project folder `api` | ||
2. [Optional] Add a file named `plus.json` in your project folder `api` | ||
@@ -73,3 +74,3 @@ ```json | ||
##### 3. Add the following code in your `index.js` file | ||
3. Add the following code in your `index.js` file | ||
@@ -88,3 +89,3 @@ ```javascript | ||
##### 4. run index.js | ||
4. run index.js | ||
@@ -95,2 +96,36 @@ ```bash | ||
### Parameter Rule | ||
You can reference below example to apply rules to parameters | ||
```json | ||
{ | ||
"name": "plus", | ||
"parameters": { | ||
"a": { | ||
"name": "parameter a", | ||
"type": "number", | ||
"length": 3, | ||
"rule": [ | ||
{ | ||
"code": "GREATER_THAN_0", | ||
"expression": "^[1-9][0-9]*$", | ||
"message": "must be greater than 0" | ||
} | ||
], | ||
"i18n": { | ||
"zh": { | ||
"GREATER_THAN_0": "必须大于0" | ||
} | ||
} | ||
}, | ||
"b": { | ||
"name": "parameter b", | ||
"type": "number" | ||
} | ||
} | ||
} | ||
``` | ||
For more usage, please reference [Validator](https://sumor.cloud/validator/) | ||
### context | ||
@@ -97,0 +132,0 @@ |
@@ -43,3 +43,5 @@ import { meta } from '@sumor/config' | ||
apiMeta[path].error = 'syntaxError' | ||
logger.code('API_LOAD_FAILED_SYNTAX_ERROR', { path: apiMeta[path].route }) | ||
logger.code('API_LOAD_FAILED_SYNTAX_ERROR', { | ||
path: apiMeta[path].route | ||
}) | ||
logger.error(programResult.error) | ||
@@ -54,3 +56,5 @@ } else { | ||
if (hasFile) { | ||
logger.code('API_LOAD_SUCCESS_WITH_FILE', { path: apiMeta[path].route }) | ||
logger.code('API_LOAD_SUCCESS_WITH_FILE', { | ||
path: apiMeta[path].route | ||
}) | ||
} else { | ||
@@ -61,3 +65,5 @@ logger.code('API_LOAD_SUCCESS', { path: apiMeta[path].route }) | ||
apiMeta[path].error = 'missingDefaultExport' | ||
logger.code('API_LOAD_FAILED_MISSING_DEFAULT', { path: apiMeta[path].route }) | ||
logger.code('API_LOAD_FAILED_MISSING_DEFAULT', { | ||
path: apiMeta[path].route | ||
}) | ||
} | ||
@@ -64,0 +70,0 @@ apiMeta[path].program = program |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
18481
428
141
0