@quilla-be-kit/http 0.14.0 → 0.14.1
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/README.md +26 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -349,7 +349,32 @@ Two things to keep in mind:
|
|
|
349
349
|
- **Schema shape is the truth.** Helpers that reshape input change the output type. For example, `tenantScopedListQuery` nests `page` / `pageSize` / `sort` under `pagination`, so read `query.pagination.pageSize`, not `query.pageSize`. The compiler now flags the wrong one.
|
|
350
350
|
- **The validator must return the schema's output.** The derived type is a claim about the schema; a custom `RequestValidator.validate` that returns a different shape than the schema infers makes the type lie.
|
|
351
351
|
|
|
352
|
-
|
|
352
|
+
#### Routes without validation
|
|
353
|
+
|
|
354
|
+
A route without `@ValidateRequest` keeps taking a plain `HttpRequest`; nothing about it changes. `getValidatedInput` is not part of `HttpRequest`, so calling it on such a route is a compile error rather than a runtime throw. A handler typed as plain `HttpRequest` under `@ValidateRequest` still compiles, but cannot read the validated input.
|
|
355
|
+
|
|
356
|
+
```ts
|
|
357
|
+
@Get('/:id')
|
|
358
|
+
async show(req: HttpRequest): Promise<HttpResponse> {
|
|
359
|
+
const id = req.getParams().id; // full request access, no validation involved
|
|
360
|
+
}
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
`ValidatedRequest<S>` is `HttpRequest` plus the typed accessor, so a validated handler keeps every other request method (`getBody`, `getHeader`, `getExecutionContext`, ...).
|
|
364
|
+
|
|
365
|
+
#### Migrating from `getValidatedInput<T>()`
|
|
366
|
+
|
|
367
|
+
Earlier versions exposed `getValidatedInput<T>()` on every `HttpRequest`. For each handler that calls it:
|
|
368
|
+
|
|
369
|
+
1. Change the parameter from `req: HttpRequest` to `req: ValidatedRequest<typeof Schema>`, using the schema passed to `@ValidateRequest`.
|
|
370
|
+
2. Call `req.getValidatedInput()` without a type argument and delete the hand-written `T`.
|
|
371
|
+
3. Fix any compile errors: they mark places where the hand-written type disagreed with the schema.
|
|
372
|
+
|
|
373
|
+
Hand-rolled `HttpRequest` fakes in tests must drop `getValidatedInput`.
|
|
374
|
+
|
|
375
|
+
#### Custom decorators
|
|
376
|
+
|
|
377
|
+
Custom method decorators that wrap handlers must be generic over the request type, as `@AuthorizeScope` is, or TypeScript will reject handlers typed `ValidatedRequest`:
|
|
353
378
|
|
|
354
379
|
```ts
|
|
355
380
|
function Audit() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quilla-be-kit/http",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "Framework-agnostic HTTP layer: decorators (@Controller/@Get/@Post/.../@AuthorizeScope/@ValidateRequest), framework-agnostic router, WebServer interface, and a Hono adapter sub-path.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Max Martinez",
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@quilla-be-kit/errors": "^0.3.0",
|
|
59
59
|
"@quilla-be-kit/execution-context": "^0.3.1",
|
|
60
|
-
"@quilla-be-kit/
|
|
61
|
-
"@quilla-be-kit/
|
|
60
|
+
"@quilla-be-kit/runtime": "^0.2.2",
|
|
61
|
+
"@quilla-be-kit/observability": "^0.3.1"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
64
|
"hono": "4.x.x",
|