@eggjs/ajv-decorator 3.36.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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +21 -0
- package/dist/src/enum/TransformEnum.d.ts +45 -0
- package/dist/src/enum/TransformEnum.js +50 -0
- package/dist/src/error/AjvInvalidParamError.d.ts +12 -0
- package/dist/src/error/AjvInvalidParamError.js +14 -0
- package/dist/src/type/Ajv.d.ts +4 -0
- package/dist/src/type/Ajv.js +3 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-present Alibaba Group Holding Limited and other contributors.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@sinclair/typebox"), exports);
|
|
18
|
+
__exportStar(require("./src/enum/TransformEnum"), exports);
|
|
19
|
+
__exportStar(require("./src/error/AjvInvalidParamError"), exports);
|
|
20
|
+
__exportStar(require("./src/type/Ajv"), exports);
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsb0RBQWtDO0FBQ2xDLDJEQUF5QztBQUN6QyxtRUFBaUQ7QUFDakQsaURBQStCIn0=
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This keyword allows a string to be modified during validation.
|
|
3
|
+
* This keyword applies only to strings. If the data is not a string, the transform keyword is ignored.
|
|
4
|
+
* @see https://github.com/ajv-validator/ajv-keywords?tab=readme-ov-file#transform
|
|
5
|
+
*/
|
|
6
|
+
export declare enum TransformEnum {
|
|
7
|
+
/** remove whitespace from start and end */
|
|
8
|
+
trim = "trim",
|
|
9
|
+
/** remove whitespace from start */
|
|
10
|
+
trimStart = "trimStart",
|
|
11
|
+
/**
|
|
12
|
+
* @alias trimStart
|
|
13
|
+
*/
|
|
14
|
+
trimLeft = "trimLeft",
|
|
15
|
+
/** remove whitespace from end */
|
|
16
|
+
trimEnd = "trimEnd",
|
|
17
|
+
/**
|
|
18
|
+
* @alias trimEnd
|
|
19
|
+
*/
|
|
20
|
+
trimRight = "trimRight",
|
|
21
|
+
/** convert to lower case */
|
|
22
|
+
toLowerCase = "toLowerCase",
|
|
23
|
+
/** convert to upper case */
|
|
24
|
+
toUpperCase = "toUpperCase",
|
|
25
|
+
/**
|
|
26
|
+
* change string case to be equal to one of `enum` values in the schema
|
|
27
|
+
*
|
|
28
|
+
* **NOTE**: requires that all allowed values are unique when case insensitive
|
|
29
|
+
* ```ts
|
|
30
|
+
* const schema = {
|
|
31
|
+
* type: "array",
|
|
32
|
+
* items: {
|
|
33
|
+
* type: "string",
|
|
34
|
+
* transform: ["trim", Transform.toEnumCase],
|
|
35
|
+
* enum: ["pH"],
|
|
36
|
+
* },
|
|
37
|
+
* };
|
|
38
|
+
*
|
|
39
|
+
* const data = ["ph", " Ph", "PH", "pH "];
|
|
40
|
+
* ajv.validate(schema, data);
|
|
41
|
+
* console.log(data) // ['pH','pH','pH','pH'];
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
toEnumCase = "toEnumCase"
|
|
45
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransformEnum = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* This keyword allows a string to be modified during validation.
|
|
6
|
+
* This keyword applies only to strings. If the data is not a string, the transform keyword is ignored.
|
|
7
|
+
* @see https://github.com/ajv-validator/ajv-keywords?tab=readme-ov-file#transform
|
|
8
|
+
*/
|
|
9
|
+
var TransformEnum;
|
|
10
|
+
(function (TransformEnum) {
|
|
11
|
+
/** remove whitespace from start and end */
|
|
12
|
+
TransformEnum["trim"] = "trim";
|
|
13
|
+
/** remove whitespace from start */
|
|
14
|
+
TransformEnum["trimStart"] = "trimStart";
|
|
15
|
+
/**
|
|
16
|
+
* @alias trimStart
|
|
17
|
+
*/
|
|
18
|
+
TransformEnum["trimLeft"] = "trimLeft";
|
|
19
|
+
/** remove whitespace from end */
|
|
20
|
+
TransformEnum["trimEnd"] = "trimEnd";
|
|
21
|
+
/**
|
|
22
|
+
* @alias trimEnd
|
|
23
|
+
*/
|
|
24
|
+
TransformEnum["trimRight"] = "trimRight";
|
|
25
|
+
/** convert to lower case */
|
|
26
|
+
TransformEnum["toLowerCase"] = "toLowerCase";
|
|
27
|
+
/** convert to upper case */
|
|
28
|
+
TransformEnum["toUpperCase"] = "toUpperCase";
|
|
29
|
+
/**
|
|
30
|
+
* change string case to be equal to one of `enum` values in the schema
|
|
31
|
+
*
|
|
32
|
+
* **NOTE**: requires that all allowed values are unique when case insensitive
|
|
33
|
+
* ```ts
|
|
34
|
+
* const schema = {
|
|
35
|
+
* type: "array",
|
|
36
|
+
* items: {
|
|
37
|
+
* type: "string",
|
|
38
|
+
* transform: ["trim", Transform.toEnumCase],
|
|
39
|
+
* enum: ["pH"],
|
|
40
|
+
* },
|
|
41
|
+
* };
|
|
42
|
+
*
|
|
43
|
+
* const data = ["ph", " Ph", "PH", "pH "];
|
|
44
|
+
* ajv.validate(schema, data);
|
|
45
|
+
* console.log(data) // ['pH','pH','pH','pH'];
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
TransformEnum["toEnumCase"] = "toEnumCase";
|
|
49
|
+
})(TransformEnum || (exports.TransformEnum = TransformEnum = {}));
|
|
50
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiVHJhbnNmb3JtRW51bS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9lbnVtL1RyYW5zZm9ybUVudW0udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUE7Ozs7R0FJRztBQUNILElBQVksYUF1Q1g7QUF2Q0QsV0FBWSxhQUFhO0lBQ3ZCLDJDQUEyQztJQUMzQyw4QkFBYSxDQUFBO0lBQ2IsbUNBQW1DO0lBQ25DLHdDQUF1QixDQUFBO0lBQ3ZCOztPQUVHO0lBQ0gsc0NBQXFCLENBQUE7SUFDckIsaUNBQWlDO0lBQ2pDLG9DQUFtQixDQUFBO0lBQ25COztPQUVHO0lBQ0gsd0NBQXVCLENBQUE7SUFDdkIsNEJBQTRCO0lBQzVCLDRDQUEyQixDQUFBO0lBQzNCLDRCQUE0QjtJQUM1Qiw0Q0FBMkIsQ0FBQTtJQUMzQjs7Ozs7Ozs7Ozs7Ozs7Ozs7O09Ba0JHO0lBQ0gsMENBQXlCLENBQUE7QUFDM0IsQ0FBQyxFQXZDVyxhQUFhLDZCQUFiLGFBQWEsUUF1Q3hCIn0=
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ErrorObject } from 'ajv/dist/2019';
|
|
2
|
+
export interface AjvInvalidParamErrorOptions {
|
|
3
|
+
errorData: unknown;
|
|
4
|
+
currentSchema: string;
|
|
5
|
+
errors: ErrorObject[];
|
|
6
|
+
}
|
|
7
|
+
export declare class AjvInvalidParamError extends Error {
|
|
8
|
+
errorData: unknown;
|
|
9
|
+
currentSchema: string;
|
|
10
|
+
errors: ErrorObject[];
|
|
11
|
+
constructor(message: string, options: AjvInvalidParamErrorOptions);
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AjvInvalidParamError = void 0;
|
|
4
|
+
class AjvInvalidParamError extends Error {
|
|
5
|
+
constructor(message, options) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = this.constructor.name;
|
|
8
|
+
this.errorData = options.errorData;
|
|
9
|
+
this.currentSchema = options.currentSchema;
|
|
10
|
+
this.errors = options.errors;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.AjvInvalidParamError = AjvInvalidParamError;
|
|
14
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQWp2SW52YWxpZFBhcmFtRXJyb3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvZXJyb3IvQWp2SW52YWxpZFBhcmFtRXJyb3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBUUEsTUFBYSxvQkFBcUIsU0FBUSxLQUFLO0lBSzdDLFlBQVksT0FBZSxFQUFFLE9BQW9DO1FBQy9ELEtBQUssQ0FBQyxPQUFPLENBQUMsQ0FBQztRQUNmLElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxDQUFDLFdBQVcsQ0FBQyxJQUFJLENBQUM7UUFDbEMsSUFBSSxDQUFDLFNBQVMsR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDO1FBQ25DLElBQUksQ0FBQyxhQUFhLEdBQUcsT0FBTyxDQUFDLGFBQWEsQ0FBQztRQUMzQyxJQUFJLENBQUMsTUFBTSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUM7SUFDL0IsQ0FBQztDQUNGO0FBWkQsb0RBWUMifQ==
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQWp2LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3R5cGUvQWp2LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIifQ==
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eggjs/ajv-decorator",
|
|
3
|
+
"version": "3.36.0",
|
|
4
|
+
"description": "tegg ajv decorator",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"egg",
|
|
7
|
+
"typescript",
|
|
8
|
+
"decorator",
|
|
9
|
+
"tegg",
|
|
10
|
+
"ajv"
|
|
11
|
+
],
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist/**/*.js",
|
|
15
|
+
"dist/**/*.d.ts"
|
|
16
|
+
],
|
|
17
|
+
"typings": "dist/index.d.ts",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "cross-env NODE_ENV=test NODE_OPTIONS='--no-deprecation' mocha",
|
|
20
|
+
"clean": "tsc -b --clean",
|
|
21
|
+
"tsc": "npm run clean && tsc -p ./tsconfig.json",
|
|
22
|
+
"tsc:pub": "npm run clean && tsc -p ./tsconfig.pub.json",
|
|
23
|
+
"prepublishOnly": "npm run tsc:pub"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"homepage": "https://github.com/eggjs/tegg",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/eggjs/tegg/issues"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git@github.com:eggjs/tegg.git",
|
|
33
|
+
"directory": "core/ajv-decorator"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=16.0.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@sinclair/typebox": "^0.32.20",
|
|
40
|
+
"ajv": "^8.12.0"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/mocha": "^10.0.1",
|
|
47
|
+
"@types/node": "^20.2.4",
|
|
48
|
+
"cross-env": "^7.0.3",
|
|
49
|
+
"mocha": "^10.2.0",
|
|
50
|
+
"ts-node": "^10.9.1",
|
|
51
|
+
"typescript": "^5.0.4"
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "b550d59a21f7c9991310ca6b6fd16ee581a5e17d"
|
|
54
|
+
}
|