@atscript/moost-validator 0.2.3 → 0.2.5
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 +11 -5
- package/dist/index.d.ts +5 -2
- package/dist/index.mjs +12 -6
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -83,8 +83,11 @@ function coerceDate(value) {
|
|
|
83
83
|
* handler parameters (body, params, query, etc.).
|
|
84
84
|
*
|
|
85
85
|
* The pipe inspects the runtime metadata supplied by Moost; when the target
|
|
86
|
-
* parameter type is an atscript‑annotated class or interface it
|
|
87
|
-
*
|
|
86
|
+
* parameter type is an atscript‑annotated class or interface it first applies the
|
|
87
|
+
* type's normalizers (`@normalize.trim` / `lowercase` / `uppercase`, see
|
|
88
|
+
* `normalizeForType`), then calls `type.validator(opts).validate(value)` on the
|
|
89
|
+
* normalized value, and hands the normalized value to the handler. Input without
|
|
90
|
+
* normalizers is passed on as it is (the same object).
|
|
88
91
|
*
|
|
89
92
|
* The pipe is registered at {@link TPipePriority.VALIDATE}, ensuring it fires
|
|
90
93
|
* before any transformation pipes and long before business logic executes.
|
|
@@ -114,7 +117,9 @@ function coerceDate(value) {
|
|
|
114
117
|
validator = type.validator(opts);
|
|
115
118
|
validators.set(type, validator);
|
|
116
119
|
}
|
|
117
|
-
|
|
120
|
+
const normalized = (0, _atscript_typescript_utils.normalizeForType)(type, value);
|
|
121
|
+
validator.validate(normalized);
|
|
122
|
+
return normalized;
|
|
118
123
|
}
|
|
119
124
|
return value;
|
|
120
125
|
}, moost.TPipePriority.VALIDATE);
|
|
@@ -155,12 +160,13 @@ function coerceDate(value) {
|
|
|
155
160
|
}, moost.TInterceptorPriority.CATCH_ERROR);
|
|
156
161
|
/**
|
|
157
162
|
* Internal helper that performs the actual conversion: wraps a
|
|
158
|
-
* `ValidatorError` into {@link HttpError}
|
|
163
|
+
* `ValidatorError` into {@link HttpError} — `{ message, statusCode, errors }`, the envelope
|
|
164
|
+
* `@atscript/moost-db` answers with too — and passes it to Moost's `reply`.
|
|
159
165
|
*/ function transformValidationError(error, reply) {
|
|
160
166
|
if (error instanceof _atscript_typescript_utils.ValidatorError) reply(new _moostjs_event_http.HttpError(400, {
|
|
161
167
|
message: error.message,
|
|
162
168
|
statusCode: 400,
|
|
163
|
-
|
|
169
|
+
errors: error.errors
|
|
164
170
|
}));
|
|
165
171
|
}
|
|
166
172
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -63,8 +63,11 @@ declare const UseCoercionPipe: (opts?: TCoercionOptions) => ClassDecorator & Met
|
|
|
63
63
|
* handler parameters (body, params, query, etc.).
|
|
64
64
|
*
|
|
65
65
|
* The pipe inspects the runtime metadata supplied by Moost; when the target
|
|
66
|
-
* parameter type is an atscript‑annotated class or interface it
|
|
67
|
-
*
|
|
66
|
+
* parameter type is an atscript‑annotated class or interface it first applies the
|
|
67
|
+
* type's normalizers (`@normalize.trim` / `lowercase` / `uppercase`, see
|
|
68
|
+
* `normalizeForType`), then calls `type.validator(opts).validate(value)` on the
|
|
69
|
+
* normalized value, and hands the normalized value to the handler. Input without
|
|
70
|
+
* normalizers is passed on as it is (the same object).
|
|
68
71
|
*
|
|
69
72
|
* The pipe is registered at {@link TPipePriority.VALIDATE}, ensuring it fires
|
|
70
73
|
* before any transformation pipes and long before business logic executes.
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ValidatorError, coerceForType, coerceScalar, isAnnotatedType } from "@atscript/typescript/utils";
|
|
1
|
+
import { ValidatorError, coerceForType, coerceScalar, isAnnotatedType, normalizeForType } from "@atscript/typescript/utils";
|
|
2
2
|
import { Intercept, Pipe, TInterceptorPriority, TPipePriority, defineInterceptor, definePipeFn } from "moost";
|
|
3
3
|
import { HttpError } from "@moostjs/event-http";
|
|
4
4
|
|
|
@@ -82,8 +82,11 @@ function coerceDate(value) {
|
|
|
82
82
|
* handler parameters (body, params, query, etc.).
|
|
83
83
|
*
|
|
84
84
|
* The pipe inspects the runtime metadata supplied by Moost; when the target
|
|
85
|
-
* parameter type is an atscript‑annotated class or interface it
|
|
86
|
-
*
|
|
85
|
+
* parameter type is an atscript‑annotated class or interface it first applies the
|
|
86
|
+
* type's normalizers (`@normalize.trim` / `lowercase` / `uppercase`, see
|
|
87
|
+
* `normalizeForType`), then calls `type.validator(opts).validate(value)` on the
|
|
88
|
+
* normalized value, and hands the normalized value to the handler. Input without
|
|
89
|
+
* normalizers is passed on as it is (the same object).
|
|
87
90
|
*
|
|
88
91
|
* The pipe is registered at {@link TPipePriority.VALIDATE}, ensuring it fires
|
|
89
92
|
* before any transformation pipes and long before business logic executes.
|
|
@@ -113,7 +116,9 @@ function coerceDate(value) {
|
|
|
113
116
|
validator = type.validator(opts);
|
|
114
117
|
validators.set(type, validator);
|
|
115
118
|
}
|
|
116
|
-
|
|
119
|
+
const normalized = normalizeForType(type, value);
|
|
120
|
+
validator.validate(normalized);
|
|
121
|
+
return normalized;
|
|
117
122
|
}
|
|
118
123
|
return value;
|
|
119
124
|
}, TPipePriority.VALIDATE);
|
|
@@ -154,12 +159,13 @@ function coerceDate(value) {
|
|
|
154
159
|
}, TInterceptorPriority.CATCH_ERROR);
|
|
155
160
|
/**
|
|
156
161
|
* Internal helper that performs the actual conversion: wraps a
|
|
157
|
-
* `ValidatorError` into {@link HttpError}
|
|
162
|
+
* `ValidatorError` into {@link HttpError} — `{ message, statusCode, errors }`, the envelope
|
|
163
|
+
* `@atscript/moost-db` answers with too — and passes it to Moost's `reply`.
|
|
158
164
|
*/ function transformValidationError(error, reply) {
|
|
159
165
|
if (error instanceof ValidatorError) reply(new HttpError(400, {
|
|
160
166
|
message: error.message,
|
|
161
167
|
statusCode: 400,
|
|
162
|
-
|
|
168
|
+
errors: error.errors
|
|
163
169
|
}));
|
|
164
170
|
}
|
|
165
171
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/moost-validator",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Validator pipe and utils for Moost.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -36,15 +36,15 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@moostjs/event-http": "^0.7.
|
|
40
|
-
"moost": "^0.7.
|
|
39
|
+
"@moostjs/event-http": "^0.7.3",
|
|
40
|
+
"moost": "^0.7.3",
|
|
41
41
|
"vitest": "4.1.12"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@moostjs/event-http": "^0.7.0",
|
|
45
45
|
"moost": "^0.7.0",
|
|
46
|
-
"@atscript/core": "^0.2.
|
|
47
|
-
"@atscript/typescript": "^0.2.
|
|
46
|
+
"@atscript/core": "^0.2.5",
|
|
47
|
+
"@atscript/typescript": "^0.2.5"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"pub": "pnpm publish --access public",
|