@atscript/moost-validator 0.2.4 → 0.2.6

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 CHANGED
@@ -83,8 +83,12 @@ 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 calls
87
- * `type.validator(opts).validate(value)` to perform synchronous validation.
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`, judging union branches with the same `opts`), then calls
89
+ * `type.validator(opts).validate(value)` on the normalized value, and hands the
90
+ * normalized value to the handler. Input without
91
+ * normalizers is passed on as it is (the same object).
88
92
  *
89
93
  * The pipe is registered at {@link TPipePriority.VALIDATE}, ensuring it fires
90
94
  * before any transformation pipes and long before business logic executes.
@@ -114,7 +118,9 @@ function coerceDate(value) {
114
118
  validator = type.validator(opts);
115
119
  validators.set(type, validator);
116
120
  }
117
- validator.validate(value);
121
+ const normalized = (0, _atscript_typescript_utils.normalizeForType)(type, value, opts);
122
+ validator.validate(normalized);
123
+ return normalized;
118
124
  }
119
125
  return value;
120
126
  }, moost.TPipePriority.VALIDATE);
@@ -155,12 +161,13 @@ function coerceDate(value) {
155
161
  }, moost.TInterceptorPriority.CATCH_ERROR);
156
162
  /**
157
163
  * Internal helper that performs the actual conversion: wraps a
158
- * `ValidatorError` into {@link HttpError} and passes it to Moost's `reply`.
164
+ * `ValidatorError` into {@link HttpError} — `{ message, statusCode, errors }`, the envelope
165
+ * `@atscript/moost-db` answers with too — and passes it to Moost's `reply`.
159
166
  */ function transformValidationError(error, reply) {
160
167
  if (error instanceof _atscript_typescript_utils.ValidatorError) reply(new _moostjs_event_http.HttpError(400, {
161
168
  message: error.message,
162
169
  statusCode: 400,
163
- _body: error.errors
170
+ errors: error.errors
164
171
  }));
165
172
  }
166
173
  /**
package/dist/index.d.ts CHANGED
@@ -63,8 +63,12 @@ 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 calls
67
- * `type.validator(opts).validate(value)` to perform synchronous validation.
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`, judging union branches with the same `opts`), then calls
69
+ * `type.validator(opts).validate(value)` on the normalized value, and hands the
70
+ * normalized value to the handler. Input without
71
+ * normalizers is passed on as it is (the same object).
68
72
  *
69
73
  * The pipe is registered at {@link TPipePriority.VALIDATE}, ensuring it fires
70
74
  * 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,12 @@ 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 calls
86
- * `type.validator(opts).validate(value)` to perform synchronous validation.
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`, judging union branches with the same `opts`), then calls
88
+ * `type.validator(opts).validate(value)` on the normalized value, and hands the
89
+ * normalized value to the handler. Input without
90
+ * normalizers is passed on as it is (the same object).
87
91
  *
88
92
  * The pipe is registered at {@link TPipePriority.VALIDATE}, ensuring it fires
89
93
  * before any transformation pipes and long before business logic executes.
@@ -113,7 +117,9 @@ function coerceDate(value) {
113
117
  validator = type.validator(opts);
114
118
  validators.set(type, validator);
115
119
  }
116
- validator.validate(value);
120
+ const normalized = normalizeForType(type, value, opts);
121
+ validator.validate(normalized);
122
+ return normalized;
117
123
  }
118
124
  return value;
119
125
  }, TPipePriority.VALIDATE);
@@ -154,12 +160,13 @@ function coerceDate(value) {
154
160
  }, TInterceptorPriority.CATCH_ERROR);
155
161
  /**
156
162
  * Internal helper that performs the actual conversion: wraps a
157
- * `ValidatorError` into {@link HttpError} and passes it to Moost's `reply`.
163
+ * `ValidatorError` into {@link HttpError} — `{ message, statusCode, errors }`, the envelope
164
+ * `@atscript/moost-db` answers with too — and passes it to Moost's `reply`.
158
165
  */ function transformValidationError(error, reply) {
159
166
  if (error instanceof ValidatorError) reply(new HttpError(400, {
160
167
  message: error.message,
161
168
  statusCode: 400,
162
- _body: error.errors
169
+ errors: error.errors
163
170
  }));
164
171
  }
165
172
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/moost-validator",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
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.2",
40
- "moost": "^0.7.2",
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.4",
47
- "@atscript/typescript": "^0.2.4"
46
+ "@atscript/typescript": "^0.2.6",
47
+ "@atscript/core": "^0.2.6"
48
48
  },
49
49
  "scripts": {
50
50
  "pub": "pnpm publish --access public",