BREAKING CHANGE: `parseQuery` utility removed; `IRouteMatcher` now includes query parsing; `RouteBuilder.middleware` and `handle` are now strictly typed per builder instance.
- Add `isHandler` and `isMiddleware` runtime type guards for validation in `HttpKernel`.
- Introduce `createEmptyContext` for constructing default context objects.
- Support custom HTTP error handlers (`404`, `500`) via `IHttpKernelConfig.httpErrorHandlers`.
- Default error handlers return meaningful HTTP status text (e.g., "Not Found").
- Replace legacy `parseQuery` logic with integrated query extraction via `createRouteMatcher`.
- Strongly type `RouteBuilder.middleware()` and `.handle()` methods without generic overrides.
- Simplify `HttpKernel.handle()` and `executePipeline()` through precise control flow and validation.
- Remove deprecated `registerRoute.ts` and `HttpKernelConfig.ts` in favor of colocated type exports.
- Add tests for integrated query parsing in `createRouteMatcher`.
- Improve error handling tests: middleware/handler validation, double `next()` call, thrown exceptions.
- Replace `assertRejects` with plain response code checks (via updated error handling).
- Removed `parseQuery.ts` and all related tests — query parsing is now built into route matching.
- `IRouteMatcher` signature changed to return `{ params, query }` instead of only `params`.
- `HttpKernelConfig` now uses `DeepPartial` and includes `httpErrorHandlers`.
- `RouteBuilder`'s generics are simplified for better DX and improved type safety.
This refactor improves clarity, test coverage, and runtime safety of the request lifecycle while reducing boilerplate and eliminating duplicated query handling logic.
Signed-off-by: Max P. <Mail@MPassarello.de>
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import {
|
|
assertEquals,
|
|
assertInstanceOf,
|
|
} from 'https://deno.land/std/assert/mod.ts';
|
|
import { normalizeError } from '../normalizeError.ts';
|
|
|
|
Deno.test('normalizeError: preserves Error instances', () => {
|
|
const original = new Error('original');
|
|
const result = normalizeError(original);
|
|
|
|
assertInstanceOf(result, Error);
|
|
assertEquals(result, original);
|
|
});
|
|
|
|
Deno.test('normalizeError: converts string to Error', () => {
|
|
const result = normalizeError('something went wrong');
|
|
|
|
assertInstanceOf(result, Error);
|
|
assertEquals(result.message, 'something went wrong');
|
|
});
|
|
|
|
Deno.test('normalizeError: converts number to Error', () => {
|
|
const result = normalizeError(404);
|
|
|
|
assertInstanceOf(result, Error);
|
|
assertEquals(result.message, '404');
|
|
});
|
|
|
|
Deno.test('normalizeError: converts plain object to Error', () => {
|
|
const input = { error: true, msg: 'Invalid' };
|
|
const result = normalizeError(input);
|
|
|
|
assertInstanceOf(result, Error);
|
|
assertEquals(result.message, JSON.stringify(input));
|
|
});
|