@atscript/moost-validator 0.1.101 → 0.1.103
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/dist/index.cjs +16 -5
- package/dist/index.mjs +16 -5
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -103,11 +103,22 @@ function coerceDate(value) {
|
|
|
103
103
|
* const app = new Moost();
|
|
104
104
|
* app.applyGlobalPipes(validatorPipe());
|
|
105
105
|
* ```
|
|
106
|
-
*/ const validatorPipe = (opts) =>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
*/ const validatorPipe = (opts) => {
|
|
107
|
+
const validators = /* @__PURE__ */ new WeakMap();
|
|
108
|
+
return (0, moost.definePipeFn)((value, metas) => {
|
|
109
|
+
if (metas?.targetMeta?.optional && (value === void 0 || value === null)) return value;
|
|
110
|
+
const type = metas?.targetMeta?.type;
|
|
111
|
+
if ((0, _atscript_typescript_utils.isAnnotatedType)(type) && typeof type.validator === "function") {
|
|
112
|
+
let validator = validators.get(type);
|
|
113
|
+
if (!validator) {
|
|
114
|
+
validator = type.validator(opts);
|
|
115
|
+
validators.set(type, validator);
|
|
116
|
+
}
|
|
117
|
+
validator.validate(value);
|
|
118
|
+
}
|
|
119
|
+
return value;
|
|
120
|
+
}, moost.TPipePriority.VALIDATE);
|
|
121
|
+
};
|
|
111
122
|
/**
|
|
112
123
|
* Syntactic sugar decorator that applies {@link validatorPipe} to a handler or
|
|
113
124
|
* an entire controller class.
|
package/dist/index.mjs
CHANGED
|
@@ -102,11 +102,22 @@ function coerceDate(value) {
|
|
|
102
102
|
* const app = new Moost();
|
|
103
103
|
* app.applyGlobalPipes(validatorPipe());
|
|
104
104
|
* ```
|
|
105
|
-
*/ const validatorPipe = (opts) =>
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
*/ const validatorPipe = (opts) => {
|
|
106
|
+
const validators = /* @__PURE__ */ new WeakMap();
|
|
107
|
+
return definePipeFn((value, metas) => {
|
|
108
|
+
if (metas?.targetMeta?.optional && (value === void 0 || value === null)) return value;
|
|
109
|
+
const type = metas?.targetMeta?.type;
|
|
110
|
+
if (isAnnotatedType(type) && typeof type.validator === "function") {
|
|
111
|
+
let validator = validators.get(type);
|
|
112
|
+
if (!validator) {
|
|
113
|
+
validator = type.validator(opts);
|
|
114
|
+
validators.set(type, validator);
|
|
115
|
+
}
|
|
116
|
+
validator.validate(value);
|
|
117
|
+
}
|
|
118
|
+
return value;
|
|
119
|
+
}, TPipePriority.VALIDATE);
|
|
120
|
+
};
|
|
110
121
|
/**
|
|
111
122
|
* Syntactic sugar decorator that applies {@link validatorPipe} to a handler or
|
|
112
123
|
* an entire controller class.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/moost-validator",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.103",
|
|
4
4
|
"description": "Validator pipe and utils for Moost.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@moostjs/event-http": "^0.6.42",
|
|
45
45
|
"moost": "^0.6.42",
|
|
46
|
-
"@atscript/typescript": "^0.1.
|
|
47
|
-
"@atscript/core": "^0.1.
|
|
46
|
+
"@atscript/typescript": "^0.1.103",
|
|
47
|
+
"@atscript/core": "^0.1.103"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"pub": "pnpm publish --access public",
|