refactor(imports): use explicit type-only imports across codebase
All checks were successful
Auto Changelog & Release / detect-version-change (push) Successful in 3s
Auto Changelog & Release / release (push) Has been skipped
Auto Changelog & Release / changelog-only (push) Successful in 6s

- Replace standard imports with type-only imports to improve clarity
  and align with TypeScript best practices.
- Ensure consistency across modules by modifying all relevant files.
This commit is contained in:
2025-05-27 13:18:31 +02:00
parent c28eb7f28d
commit b83aa330b3
24 changed files with 56 additions and 55 deletions

View File

@@ -1,4 +1,4 @@
import { import type {
IContext, IContext,
IHttpKernel, IHttpKernel,
IHttpKernelConfig, IHttpKernelConfig,
@@ -7,14 +7,14 @@ import {
IRouteDefinition, IRouteDefinition,
} from './Interfaces/mod.ts'; } from './Interfaces/mod.ts';
import { import {
DeepPartial, type DeepPartial,
Handler, type Handler,
HTTP_404_NOT_FOUND, HTTP_404_NOT_FOUND,
HTTP_500_INTERNAL_SERVER_ERROR, HTTP_500_INTERNAL_SERVER_ERROR,
HttpStatusTextMap, HttpStatusTextMap,
isHandler, isHandler,
isMiddleware, isMiddleware,
Middleware, type Middleware,
} from './Types/mod.ts'; } from './Types/mod.ts';
import { RouteBuilder } from './RouteBuilder.ts'; import { RouteBuilder } from './RouteBuilder.ts';
import { createEmptyContext, normalizeError } from './Utils/mod.ts'; import { createEmptyContext, normalizeError } from './Utils/mod.ts';

View File

@@ -1,4 +1,4 @@
import { Params, Query, State } from '../Types/mod.ts'; import type { Params, Query, State } from '../Types/mod.ts';
/** /**
* Represents the complete context for a single HTTP request, * Represents the complete context for a single HTTP request,

View File

@@ -1,5 +1,5 @@
import { IContext } from '../Interfaces/mod.ts'; import type { IContext } from '../Interfaces/mod.ts';
import { HttpErrorHandler, validHttpErrorCodes } from '../Types/mod.ts'; import type { HttpErrorHandler, validHttpErrorCodes } from '../Types/mod.ts';
/** /**
* A mapping of HTTP status codes to their corresponding error handlers. * A mapping of HTTP status codes to their corresponding error handlers.

View File

@@ -1,6 +1,6 @@
import { IContext } from './IContext.ts'; import type { IContext } from './IContext.ts';
import { IRouteBuilder } from './IRouteBuilder.ts'; import type { IRouteBuilder } from './IRouteBuilder.ts';
import { IRouteDefinition } from './IRouteDefinition.ts'; import type { IRouteDefinition } from './IRouteDefinition.ts';
/** /**
* The `IHttpKernel` interface defines the public API for a type-safe, middleware-driven HTTP dispatching system. * The `IHttpKernel` interface defines the public API for a type-safe, middleware-driven HTTP dispatching system.

View File

@@ -1,7 +1,7 @@
import { ResponseDecorator } from '../Types/mod.ts'; import type { ResponseDecorator } from '../Types/mod.ts';
import { IContext } from './IContext.ts'; import type { IContext } from './IContext.ts';
import { IHttpErrorHandlers } from './IHttpErrorHandlers.ts'; import type { IHttpErrorHandlers } from './IHttpErrorHandlers.ts';
import { IRouteBuilderFactory } from './IRouteBuilder.ts'; import type { IRouteBuilderFactory } from './IRouteBuilder.ts';
export interface IHttpKernelConfig<TContext extends IContext = IContext> { export interface IHttpKernelConfig<TContext extends IContext = IContext> {
decorateResponse: ResponseDecorator<TContext>; decorateResponse: ResponseDecorator<TContext>;

View File

@@ -1,5 +1,5 @@
import { Handler, HttpMethod, Middleware } from '../Types/mod.ts'; import type { Handler, HttpMethod, Middleware } from '../Types/mod.ts';
import { IContext, IRouteMatcher } from './mod.ts'; import type { IContext, IRouteMatcher } from './mod.ts';
/** /**
* Represents an internally registered route within the HttpKernel. * Represents an internally registered route within the HttpKernel.

View File

@@ -1,7 +1,7 @@
import { Handler, Middleware } from '../Types/mod.ts'; import type { Handler, Middleware } from '../Types/mod.ts';
import { IInternalRoute } from './IInternalRoute.ts'; import type { IInternalRoute } from './IInternalRoute.ts';
import { IRouteDefinition } from './IRouteDefinition.ts'; import type { IRouteDefinition } from './IRouteDefinition.ts';
import { IContext } from './mod.ts'; import type { IContext } from './mod.ts';
export interface IRouteBuilderFactory<TContext extends IContext = IContext> { export interface IRouteBuilderFactory<TContext extends IContext = IContext> {
new ( new (

View File

@@ -1,5 +1,5 @@
import { HttpMethod, isHttpMethod } from '../Types/mod.ts'; import { type HttpMethod, isHttpMethod } from '../Types/mod.ts';
import { IRouteMatcher } from './IRouteMatcher.ts'; import type { IRouteMatcher } from './IRouteMatcher.ts';
/** /**
* Defines a static route using a path pattern with optional parameters. * Defines a static route using a path pattern with optional parameters.

View File

@@ -1,4 +1,4 @@
import { Params, Query } from '../Types/mod.ts'; import type { Params, Query } from '../Types/mod.ts';
export interface IRouteMatch { export interface IRouteMatch {
params?: Params; params?: Params;

View File

@@ -1,6 +1,5 @@
import { Params } from '../Types/mod.ts'; import type { IRouteDefinition } from './IRouteDefinition.ts';
import { IRouteDefinition } from './IRouteDefinition.ts'; import type { IRouteMatch } from './IRouteMatch.ts';
import { IRouteMatch } from './IRouteMatch.ts';
/** /**
* Defines a route matcher function that evaluates whether a route applies to a given request. * Defines a route matcher function that evaluates whether a route applies to a given request.

View File

@@ -1,6 +1,6 @@
import { assertEquals } from 'https://deno.land/std@0.204.0/assert/mod.ts'; import { assertEquals } from 'https://deno.land/std@0.204.0/assert/mod.ts';
import { import {
IRouteDefinition, type IRouteDefinition,
isDynamicRouteDefinition, isDynamicRouteDefinition,
isStaticRouteDefinition, isStaticRouteDefinition,
} from '../IRouteDefinition.ts'; } from '../IRouteDefinition.ts';

View File

@@ -1,6 +1,10 @@
import { IRouteMatcherFactory } from './Interfaces/IRouteMatcher.ts'; import type { IRouteMatcherFactory } from './Interfaces/IRouteMatcher.ts';
import { IContext, IRouteBuilder, IRouteDefinition } from './Interfaces/mod.ts'; import type {
import { Handler, Middleware, RegisterRoute } from './Types/mod.ts'; IContext,
IRouteBuilder,
IRouteDefinition,
} from './Interfaces/mod.ts';
import type { Handler, Middleware, RegisterRoute } from './Types/mod.ts';
import { createRouteMatcher } from './Utils/createRouteMatcher.ts'; import { createRouteMatcher } from './Utils/createRouteMatcher.ts';
/** /**

View File

@@ -1,4 +1,4 @@
import { IContext } from '../Interfaces/mod.ts'; import type { IContext } from '../Interfaces/mod.ts';
/** /**
* Represents a final request handler responsible for producing an HTTP response. * Represents a final request handler responsible for producing an HTTP response.

View File

@@ -1,4 +1,4 @@
import { IContext } from '../Interfaces/mod.ts'; import type { IContext } from '../Interfaces/mod.ts';
/** /**
* Defines a handler function for errors that occur during the execution * Defines a handler function for errors that occur during the execution

View File

@@ -1,4 +1,4 @@
import { IContext } from '../Interfaces/IContext.ts'; import type { IContext } from '../Interfaces/IContext.ts';
/** /**
* Represents a middleware function in the HTTP request pipeline. * Represents a middleware function in the HTTP request pipeline.

View File

@@ -1,5 +1,5 @@
import { IContext } from '../Interfaces/IContext.ts'; import type { IContext } from '../Interfaces/IContext.ts';
import { IInternalRoute } from '../Interfaces/mod.ts'; import type { IInternalRoute } from '../Interfaces/mod.ts';
/** /**
* A type alias for the internal route registration function used by the `HttpKernel`. * A type alias for the internal route registration function used by the `HttpKernel`.

View File

@@ -1,4 +1,4 @@
import { IContext } from '../Interfaces/mod.ts'; import type { IContext } from '../Interfaces/mod.ts';
/** /**
* A function that modifies or enriches an outgoing HTTP response before it is returned to the client. * A function that modifies or enriches an outgoing HTTP response before it is returned to the client.

View File

@@ -1,6 +1,6 @@
import { assertEquals } from 'https://deno.land/std/assert/mod.ts'; import { assertEquals } from 'https://deno.land/std/assert/mod.ts';
import { createEmptyContext } from '../createEmptyContext.ts'; import { createEmptyContext } from '../createEmptyContext.ts';
import { IContext } from '../../Interfaces/mod.ts'; import type { IContext } from '../../Interfaces/mod.ts';
Deno.test('createEmptyContext: returns default-initialized context', () => { Deno.test('createEmptyContext: returns default-initialized context', () => {
const request = new Request('http://localhost'); const request = new Request('http://localhost');

View File

@@ -3,7 +3,7 @@ import {
assertEquals, assertEquals,
assertStrictEquals, assertStrictEquals,
} from 'https://deno.land/std/assert/mod.ts'; } from 'https://deno.land/std/assert/mod.ts';
import { IRouteDefinition } from '../../Interfaces/mod.ts'; import type { IRouteDefinition } from '../../Interfaces/mod.ts';
import { createRouteMatcher } from '../../mod.ts'; import { createRouteMatcher } from '../../mod.ts';
// Dummy request // Dummy request

View File

@@ -1,5 +1,5 @@
import { IContext } from '../Interfaces/mod.ts'; import type { IContext } from '../Interfaces/mod.ts';
import { Params, Query, State } from '../Types/mod.ts'; import type { Params, Query, State } from '../Types/mod.ts';
/** /**
* Creates an empty request context suitable for fallback handlers (e.g., 404 or 500 errors). * Creates an empty request context suitable for fallback handlers (e.g., 404 or 500 errors).

View File

@@ -1,12 +1,12 @@
// createRouteMatcher.ts // createRouteMatcher.ts
import { import {
IRouteDefinition, type IRouteDefinition,
IRouteMatch, type IRouteMatch,
IRouteMatcher, type IRouteMatcher,
isDynamicRouteDefinition, isDynamicRouteDefinition,
} from '../Interfaces/mod.ts'; } from '../Interfaces/mod.ts';
import { Params, Query } from '../Types/mod.ts'; import type { Params, Query } from '../Types/mod.ts';
/** /**
* Transforms a route definition into a matcher using Deno's URLPattern API. * Transforms a route definition into a matcher using Deno's URLPattern API.

View File

@@ -22,9 +22,7 @@
* ``` * ```
*/ */
export function normalizeError(unknownError: unknown): Error { export function normalizeError(unknownError: unknown): Error {
return unknownError instanceof Error return unknownError instanceof Error ? unknownError : new Error(
? unknownError
: new Error(
typeof unknownError === 'string' typeof unknownError === 'string'
? unknownError ? unknownError
: JSON.stringify(unknownError), : JSON.stringify(unknownError),

View File

@@ -1,6 +1,6 @@
import { assertEquals } from 'https://deno.land/std@0.204.0/assert/mod.ts'; import { assertEquals } from 'https://deno.land/std@0.204.0/assert/mod.ts';
import { HttpKernel } from '../HttpKernel.ts'; import { HttpKernel } from '../HttpKernel.ts';
import { IRouteDefinition } from '../Interfaces/mod.ts'; import type { IRouteDefinition } from '../Interfaces/mod.ts';
Deno.test('HttpKernel: matches static route and executes handler', async () => { Deno.test('HttpKernel: matches static route and executes handler', async () => {
const kernel = new HttpKernel(); const kernel = new HttpKernel();

View File

@@ -4,9 +4,9 @@ import {
assertNotEquals, assertNotEquals,
assertThrows, assertThrows,
} from 'https://deno.land/std@0.204.0/assert/mod.ts'; } from 'https://deno.land/std@0.204.0/assert/mod.ts';
import { IInternalRoute, IRouteDefinition } from '../Interfaces/mod.ts'; import type { IInternalRoute, IRouteDefinition } from '../Interfaces/mod.ts';
import { RouteBuilder } from '../mod.ts'; import { RouteBuilder } from '../mod.ts';
import { Handler, Middleware } from '../Types/mod.ts'; import type { Handler, Middleware } from '../Types/mod.ts';
// Dummy objects // Dummy objects
// deno-lint-ignore require-await // deno-lint-ignore require-await
@@ -91,7 +91,7 @@ Deno.test('handle: works with no middleware', async () => {
Deno.test('handle: uses custom matcher factory', () => { Deno.test('handle: uses custom matcher factory', () => {
let called = false; let called = false;
const factory = (def: IRouteDefinition) => { const factory = (_def: IRouteDefinition) => {
called = true; called = true;
return dummyMatcher; return dummyMatcher;
}; };