refactor(imports): use explicit type-only imports across codebase
- 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:
@@ -1,4 +1,4 @@
|
||||
import {
|
||||
import type {
|
||||
IContext,
|
||||
IHttpKernel,
|
||||
IHttpKernelConfig,
|
||||
@@ -7,14 +7,14 @@ import {
|
||||
IRouteDefinition,
|
||||
} from './Interfaces/mod.ts';
|
||||
import {
|
||||
DeepPartial,
|
||||
Handler,
|
||||
type DeepPartial,
|
||||
type Handler,
|
||||
HTTP_404_NOT_FOUND,
|
||||
HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
HttpStatusTextMap,
|
||||
isHandler,
|
||||
isMiddleware,
|
||||
Middleware,
|
||||
type Middleware,
|
||||
} from './Types/mod.ts';
|
||||
import { RouteBuilder } from './RouteBuilder.ts';
|
||||
import { createEmptyContext, normalizeError } from './Utils/mod.ts';
|
||||
|
@@ -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,
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { IContext } from '../Interfaces/mod.ts';
|
||||
import { HttpErrorHandler, validHttpErrorCodes } from '../Types/mod.ts';
|
||||
import type { IContext } from '../Interfaces/mod.ts';
|
||||
import type { HttpErrorHandler, validHttpErrorCodes } from '../Types/mod.ts';
|
||||
|
||||
/**
|
||||
* A mapping of HTTP status codes to their corresponding error handlers.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { IContext } from './IContext.ts';
|
||||
import { IRouteBuilder } from './IRouteBuilder.ts';
|
||||
import { IRouteDefinition } from './IRouteDefinition.ts';
|
||||
import type { IContext } from './IContext.ts';
|
||||
import type { IRouteBuilder } from './IRouteBuilder.ts';
|
||||
import type { IRouteDefinition } from './IRouteDefinition.ts';
|
||||
|
||||
/**
|
||||
* The `IHttpKernel` interface defines the public API for a type-safe, middleware-driven HTTP dispatching system.
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { ResponseDecorator } from '../Types/mod.ts';
|
||||
import { IContext } from './IContext.ts';
|
||||
import { IHttpErrorHandlers } from './IHttpErrorHandlers.ts';
|
||||
import { IRouteBuilderFactory } from './IRouteBuilder.ts';
|
||||
import type { ResponseDecorator } from '../Types/mod.ts';
|
||||
import type { IContext } from './IContext.ts';
|
||||
import type { IHttpErrorHandlers } from './IHttpErrorHandlers.ts';
|
||||
import type { IRouteBuilderFactory } from './IRouteBuilder.ts';
|
||||
|
||||
export interface IHttpKernelConfig<TContext extends IContext = IContext> {
|
||||
decorateResponse: ResponseDecorator<TContext>;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { Handler, HttpMethod, Middleware } from '../Types/mod.ts';
|
||||
import { IContext, IRouteMatcher } from './mod.ts';
|
||||
import type { Handler, HttpMethod, Middleware } from '../Types/mod.ts';
|
||||
import type { IContext, IRouteMatcher } from './mod.ts';
|
||||
|
||||
/**
|
||||
* Represents an internally registered route within the HttpKernel.
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { Handler, Middleware } from '../Types/mod.ts';
|
||||
import { IInternalRoute } from './IInternalRoute.ts';
|
||||
import { IRouteDefinition } from './IRouteDefinition.ts';
|
||||
import { IContext } from './mod.ts';
|
||||
import type { Handler, Middleware } from '../Types/mod.ts';
|
||||
import type { IInternalRoute } from './IInternalRoute.ts';
|
||||
import type { IRouteDefinition } from './IRouteDefinition.ts';
|
||||
import type { IContext } from './mod.ts';
|
||||
|
||||
export interface IRouteBuilderFactory<TContext extends IContext = IContext> {
|
||||
new (
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { HttpMethod, isHttpMethod } from '../Types/mod.ts';
|
||||
import { IRouteMatcher } from './IRouteMatcher.ts';
|
||||
import { type HttpMethod, isHttpMethod } from '../Types/mod.ts';
|
||||
import type { IRouteMatcher } from './IRouteMatcher.ts';
|
||||
|
||||
/**
|
||||
* Defines a static route using a path pattern with optional parameters.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { Params, Query } from '../Types/mod.ts';
|
||||
import type { Params, Query } from '../Types/mod.ts';
|
||||
|
||||
export interface IRouteMatch {
|
||||
params?: Params;
|
||||
|
@@ -1,6 +1,5 @@
|
||||
import { Params } from '../Types/mod.ts';
|
||||
import { IRouteDefinition } from './IRouteDefinition.ts';
|
||||
import { IRouteMatch } from './IRouteMatch.ts';
|
||||
import type { IRouteDefinition } from './IRouteDefinition.ts';
|
||||
import type { IRouteMatch } from './IRouteMatch.ts';
|
||||
|
||||
/**
|
||||
* Defines a route matcher function that evaluates whether a route applies to a given request.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { assertEquals } from 'https://deno.land/std@0.204.0/assert/mod.ts';
|
||||
import {
|
||||
IRouteDefinition,
|
||||
type IRouteDefinition,
|
||||
isDynamicRouteDefinition,
|
||||
isStaticRouteDefinition,
|
||||
} from '../IRouteDefinition.ts';
|
||||
|
@@ -1,6 +1,10 @@
|
||||
import { IRouteMatcherFactory } from './Interfaces/IRouteMatcher.ts';
|
||||
import { IContext, IRouteBuilder, IRouteDefinition } from './Interfaces/mod.ts';
|
||||
import { Handler, Middleware, RegisterRoute } from './Types/mod.ts';
|
||||
import type { IRouteMatcherFactory } from './Interfaces/IRouteMatcher.ts';
|
||||
import type {
|
||||
IContext,
|
||||
IRouteBuilder,
|
||||
IRouteDefinition,
|
||||
} from './Interfaces/mod.ts';
|
||||
import type { Handler, Middleware, RegisterRoute } from './Types/mod.ts';
|
||||
import { createRouteMatcher } from './Utils/createRouteMatcher.ts';
|
||||
|
||||
/**
|
||||
|
@@ -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.
|
||||
|
@@ -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
|
||||
|
@@ -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.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { IContext } from '../Interfaces/IContext.ts';
|
||||
import { IInternalRoute } from '../Interfaces/mod.ts';
|
||||
import type { IContext } from '../Interfaces/IContext.ts';
|
||||
import type { IInternalRoute } from '../Interfaces/mod.ts';
|
||||
|
||||
/**
|
||||
* A type alias for the internal route registration function used by the `HttpKernel`.
|
||||
|
@@ -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.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { assertEquals } from 'https://deno.land/std/assert/mod.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', () => {
|
||||
const request = new Request('http://localhost');
|
||||
|
@@ -3,7 +3,7 @@ import {
|
||||
assertEquals,
|
||||
assertStrictEquals,
|
||||
} 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';
|
||||
|
||||
// Dummy request
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { IContext } from '../Interfaces/mod.ts';
|
||||
import { Params, Query, State } from '../Types/mod.ts';
|
||||
import type { IContext } from '../Interfaces/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).
|
||||
|
@@ -1,12 +1,12 @@
|
||||
// createRouteMatcher.ts
|
||||
|
||||
import {
|
||||
IRouteDefinition,
|
||||
IRouteMatch,
|
||||
IRouteMatcher,
|
||||
type IRouteDefinition,
|
||||
type IRouteMatch,
|
||||
type IRouteMatcher,
|
||||
isDynamicRouteDefinition,
|
||||
} 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.
|
||||
|
@@ -22,11 +22,9 @@
|
||||
* ```
|
||||
*/
|
||||
export function normalizeError(unknownError: unknown): Error {
|
||||
return unknownError instanceof Error
|
||||
? unknownError
|
||||
: new Error(
|
||||
typeof unknownError === 'string'
|
||||
? unknownError
|
||||
: JSON.stringify(unknownError),
|
||||
);
|
||||
return unknownError instanceof Error ? unknownError : new Error(
|
||||
typeof unknownError === 'string'
|
||||
? unknownError
|
||||
: JSON.stringify(unknownError),
|
||||
);
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { assertEquals } from 'https://deno.land/std@0.204.0/assert/mod.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 () => {
|
||||
const kernel = new HttpKernel();
|
||||
|
@@ -4,9 +4,9 @@ import {
|
||||
assertNotEquals,
|
||||
assertThrows,
|
||||
} 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 { Handler, Middleware } from '../Types/mod.ts';
|
||||
import type { Handler, Middleware } from '../Types/mod.ts';
|
||||
|
||||
// Dummy objects
|
||||
// deno-lint-ignore require-await
|
||||
@@ -91,7 +91,7 @@ Deno.test('handle: works with no middleware', async () => {
|
||||
Deno.test('handle: uses custom matcher factory', () => {
|
||||
let called = false;
|
||||
|
||||
const factory = (def: IRouteDefinition) => {
|
||||
const factory = (_def: IRouteDefinition) => {
|
||||
called = true;
|
||||
return dummyMatcher;
|
||||
};
|
||||
|
Reference in New Issue
Block a user