@carno.js/core 1.1.1 → 1.1.2
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/LICENSE +21 -21
- package/README.md +188 -188
- package/dist/Carno.js +46 -26
- package/dist/Carno.mjs +46 -26
- package/dist/bun/index.js +4 -4
- package/dist/bun/index.js.map +29 -29
- package/package.json +2 -2
- package/src/Carno.ts +718 -673
- package/src/DefaultRoutes.ts +34 -34
- package/src/cache/CacheDriver.ts +50 -50
- package/src/cache/CacheService.ts +139 -139
- package/src/cache/MemoryDriver.ts +104 -104
- package/src/cache/RedisDriver.ts +116 -116
- package/src/compiler/JITCompiler.ts +167 -167
- package/src/container/Container.ts +168 -168
- package/src/context/Context.ts +130 -130
- package/src/cors/CorsHandler.ts +145 -145
- package/src/decorators/Controller.ts +63 -63
- package/src/decorators/Inject.ts +16 -16
- package/src/decorators/Middleware.ts +22 -22
- package/src/decorators/Service.ts +18 -18
- package/src/decorators/methods.ts +58 -58
- package/src/decorators/params.ts +47 -47
- package/src/events/Lifecycle.ts +97 -97
- package/src/exceptions/HttpException.ts +99 -99
- package/src/index.ts +95 -95
- package/src/metadata.ts +46 -46
- package/src/middleware/CarnoMiddleware.ts +14 -14
- package/src/router/RadixRouter.ts +225 -225
- package/src/testing/TestHarness.ts +185 -185
- package/src/utils/Metadata.ts +43 -43
- package/src/utils/parseQuery.ts +161 -161
- package/src/validation/ValibotAdapter.ts +95 -95
- package/src/validation/ValidatorAdapter.ts +69 -69
- package/src/validation/ZodAdapter.ts +102 -102
- package/dist/Carno.d.js +0 -14
- package/dist/Carno.d.mjs +0 -1
- package/dist/DefaultRoutes.d.js +0 -13
- package/dist/DefaultRoutes.d.mjs +0 -0
- package/dist/cache/CacheDriver.d.js +0 -13
- package/dist/cache/CacheDriver.d.mjs +0 -0
- package/dist/cache/CacheService.d.js +0 -13
- package/dist/cache/CacheService.d.mjs +0 -0
- package/dist/cache/MemoryDriver.d.js +0 -13
- package/dist/cache/MemoryDriver.d.mjs +0 -0
- package/dist/cache/RedisDriver.d.js +0 -13
- package/dist/cache/RedisDriver.d.mjs +0 -0
- package/dist/compiler/JITCompiler.d.js +0 -13
- package/dist/compiler/JITCompiler.d.mjs +0 -0
- package/dist/container/Container.d.js +0 -13
- package/dist/container/Container.d.mjs +0 -0
- package/dist/context/Context.d.js +0 -13
- package/dist/context/Context.d.mjs +0 -0
- package/dist/cors/CorsHandler.d.js +0 -13
- package/dist/cors/CorsHandler.d.mjs +0 -0
- package/dist/decorators/Controller.d.js +0 -13
- package/dist/decorators/Controller.d.mjs +0 -0
- package/dist/decorators/Inject.d.js +0 -13
- package/dist/decorators/Inject.d.mjs +0 -0
- package/dist/decorators/Middleware.d.js +0 -13
- package/dist/decorators/Middleware.d.mjs +0 -0
- package/dist/decorators/Service.d.js +0 -13
- package/dist/decorators/Service.d.mjs +0 -0
- package/dist/decorators/methods.d.js +0 -13
- package/dist/decorators/methods.d.mjs +0 -0
- package/dist/decorators/params.d.js +0 -13
- package/dist/decorators/params.d.mjs +0 -0
- package/dist/events/Lifecycle.d.js +0 -13
- package/dist/events/Lifecycle.d.mjs +0 -0
- package/dist/exceptions/HttpException.d.js +0 -13
- package/dist/exceptions/HttpException.d.mjs +0 -0
- package/dist/index.d.js +0 -130
- package/dist/index.d.mjs +0 -78
- package/dist/metadata.d.js +0 -13
- package/dist/metadata.d.mjs +0 -0
- package/dist/middleware/CarnoMiddleware.d.js +0 -13
- package/dist/middleware/CarnoMiddleware.d.mjs +0 -0
- package/dist/router/RadixRouter.d.js +0 -13
- package/dist/router/RadixRouter.d.mjs +0 -0
- package/dist/testing/TestHarness.d.js +0 -13
- package/dist/testing/TestHarness.d.mjs +0 -0
- package/dist/utils/Metadata.d.js +0 -13
- package/dist/utils/Metadata.d.mjs +0 -0
- package/dist/utils/parseQuery.d.js +0 -13
- package/dist/utils/parseQuery.d.mjs +0 -0
- package/dist/validation/ValibotAdapter.d.js +0 -13
- package/dist/validation/ValibotAdapter.d.mjs +0 -0
- package/dist/validation/ValidatorAdapter.d.js +0 -13
- package/dist/validation/ValidatorAdapter.d.mjs +0 -0
- package/dist/validation/ZodAdapter.d.js +0 -13
- package/dist/validation/ZodAdapter.d.mjs +0 -0
- package/src/Carno.d.ts +0 -135
- package/src/DefaultRoutes.d.ts +0 -19
- package/src/cache/CacheDriver.d.ts +0 -43
- package/src/cache/CacheService.d.ts +0 -89
- package/src/cache/MemoryDriver.d.ts +0 -32
- package/src/cache/RedisDriver.d.ts +0 -34
- package/src/compiler/JITCompiler.d.ts +0 -36
- package/src/container/Container.d.ts +0 -38
- package/src/context/Context.d.ts +0 -36
- package/src/cors/CorsHandler.d.ts +0 -47
- package/src/decorators/Controller.d.ts +0 -13
- package/src/decorators/Inject.d.ts +0 -6
- package/src/decorators/Middleware.d.ts +0 -5
- package/src/decorators/Service.d.ts +0 -9
- package/src/decorators/methods.d.ts +0 -7
- package/src/decorators/params.d.ts +0 -13
- package/src/events/Lifecycle.d.ts +0 -54
- package/src/exceptions/HttpException.d.ts +0 -43
- package/src/index.d.ts +0 -42
- package/src/metadata.d.ts +0 -41
- package/src/middleware/CarnoMiddleware.d.ts +0 -12
- package/src/router/RadixRouter.d.ts +0 -19
- package/src/testing/TestHarness.d.ts +0 -71
- package/src/utils/Metadata.d.ts +0 -20
- package/src/utils/parseQuery.d.ts +0 -23
- package/src/validation/ValibotAdapter.d.ts +0 -30
- package/src/validation/ValidatorAdapter.d.ts +0 -54
- package/src/validation/ZodAdapter.d.ts +0 -35
package/src/context/Context.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Request Context for Turbo.
|
|
3
|
-
*
|
|
4
|
-
* Lazy initialization for maximum performance:
|
|
5
|
-
* - Query parsed only when accessed
|
|
6
|
-
* - Body parsed only when needed
|
|
7
|
-
* - Minimal allocations in hot path
|
|
8
|
-
*/
|
|
9
|
-
export declare class Context {
|
|
10
|
-
readonly req: Request;
|
|
11
|
-
params: Record<string, string>;
|
|
12
|
-
locals: Record<string, any>;
|
|
13
|
-
private _query;
|
|
14
|
-
private _body;
|
|
15
|
-
private _bodyParsed;
|
|
16
|
-
private _url;
|
|
17
|
-
private _status;
|
|
18
|
-
constructor(req: Request, params?: Record<string, string>);
|
|
19
|
-
get status(): number;
|
|
20
|
-
set status(value: number);
|
|
21
|
-
get url(): URL;
|
|
22
|
-
get query(): Record<string, string>;
|
|
23
|
-
get body(): any;
|
|
24
|
-
parseBody(): Promise<any>;
|
|
25
|
-
get method(): string;
|
|
26
|
-
get headers(): Headers;
|
|
27
|
-
get path(): string;
|
|
28
|
-
json(data: any, status?: number): Response;
|
|
29
|
-
text(data: string, status?: number): Response;
|
|
30
|
-
html(data: string, status?: number): Response;
|
|
31
|
-
redirect(url: string, status?: number): Response;
|
|
32
|
-
/**
|
|
33
|
-
* Creates a Context from a job (for queue processing).
|
|
34
|
-
*/
|
|
35
|
-
static createFromJob(job: any): Context;
|
|
36
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CORS Configuration types.
|
|
3
|
-
*/
|
|
4
|
-
export type CorsOrigin = string | string[] | RegExp | ((origin: string) => boolean);
|
|
5
|
-
export interface CorsConfig {
|
|
6
|
-
origins: CorsOrigin;
|
|
7
|
-
methods?: string[];
|
|
8
|
-
allowedHeaders?: string[];
|
|
9
|
-
exposedHeaders?: string[];
|
|
10
|
-
credentials?: boolean;
|
|
11
|
-
maxAge?: number;
|
|
12
|
-
}
|
|
13
|
-
export declare const DEFAULT_CORS_METHODS: string[];
|
|
14
|
-
export declare const DEFAULT_CORS_HEADERS: string[];
|
|
15
|
-
/**
|
|
16
|
-
* CORS Handler - Pre-computes headers at startup for maximum performance.
|
|
17
|
-
*/
|
|
18
|
-
export declare class CorsHandler {
|
|
19
|
-
private readonly cache;
|
|
20
|
-
private readonly methodsStr;
|
|
21
|
-
private readonly headersStr;
|
|
22
|
-
private readonly exposedStr;
|
|
23
|
-
private readonly maxAgeStr;
|
|
24
|
-
private readonly hasCredentials;
|
|
25
|
-
private readonly isWildcard;
|
|
26
|
-
private readonly matcher;
|
|
27
|
-
private readonly preflightResponse;
|
|
28
|
-
constructor(config: CorsConfig);
|
|
29
|
-
/**
|
|
30
|
-
* Handle preflight (OPTIONS) request.
|
|
31
|
-
*/
|
|
32
|
-
preflight(origin: string): Response;
|
|
33
|
-
/**
|
|
34
|
-
* Apply CORS headers to a response.
|
|
35
|
-
*/
|
|
36
|
-
apply(response: Response, origin: string): Response;
|
|
37
|
-
/**
|
|
38
|
-
* Check if origin is allowed.
|
|
39
|
-
*/
|
|
40
|
-
isAllowed(origin: string): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Get cached CORS headers for origin.
|
|
43
|
-
*/
|
|
44
|
-
private getHeaders;
|
|
45
|
-
private buildHeaders;
|
|
46
|
-
private buildMatcher;
|
|
47
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ControllerOptions } from '../metadata';
|
|
2
|
-
/**
|
|
3
|
-
* Marks a class as a controller with a base path.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* // Simple path
|
|
7
|
-
* @Controller('/users')
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* // With options
|
|
11
|
-
* @Controller({ path: '/users', children: [ProfileController] })
|
|
12
|
-
*/
|
|
13
|
-
export declare function Controller(pathOrOptions?: string | ControllerOptions): ClassDecorator;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Scope } from '../container/Container';
|
|
2
|
-
export interface ServiceOptions {
|
|
3
|
-
scope?: Scope;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Marks a class as an injectable service.
|
|
7
|
-
* Services are singleton by default.
|
|
8
|
-
*/
|
|
9
|
-
export declare function Service(options?: ServiceOptions): ClassDecorator;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const Get: (path?: string) => any;
|
|
2
|
-
export declare const Post: (path?: string) => any;
|
|
3
|
-
export declare const Put: (path?: string) => any;
|
|
4
|
-
export declare const Delete: (path?: string) => any;
|
|
5
|
-
export declare const Patch: (path?: string) => any;
|
|
6
|
-
export declare const Head: (path?: string) => any;
|
|
7
|
-
export declare const Options: (path?: string) => any;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type ParamType = 'param' | 'query' | 'body' | 'header' | 'req' | 'ctx' | 'locals';
|
|
2
|
-
export interface ParamMetadata {
|
|
3
|
-
type: ParamType;
|
|
4
|
-
key?: string;
|
|
5
|
-
index: number;
|
|
6
|
-
}
|
|
7
|
-
export declare function Param(key?: string): ParameterDecorator;
|
|
8
|
-
export declare function Query(key?: string): ParameterDecorator;
|
|
9
|
-
export declare function Body(key?: string): ParameterDecorator;
|
|
10
|
-
export declare function Header(key?: string): ParameterDecorator;
|
|
11
|
-
export declare function Req(): ParameterDecorator;
|
|
12
|
-
export declare function Ctx(): ParameterDecorator;
|
|
13
|
-
export declare function Locals(key?: string): ParameterDecorator;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lifecycle Event Types.
|
|
3
|
-
*/
|
|
4
|
-
export declare enum EventType {
|
|
5
|
-
/** Called when DI container initializes, before server starts */
|
|
6
|
-
INIT = "onInit",
|
|
7
|
-
/** Called right after application is fully bootstrapped */
|
|
8
|
-
BOOT = "onBoot",
|
|
9
|
-
/** Called when application receives SIGTERM/SIGINT */
|
|
10
|
-
SHUTDOWN = "onShutdown"
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Stored event handler info.
|
|
14
|
-
*/
|
|
15
|
-
export interface EventHandler {
|
|
16
|
-
target: any;
|
|
17
|
-
methodName: string;
|
|
18
|
-
priority: number;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Metadata key for storing events.
|
|
22
|
-
*/
|
|
23
|
-
export declare const EVENTS_META: unique symbol;
|
|
24
|
-
/**
|
|
25
|
-
* Register an event handler (called by decorators).
|
|
26
|
-
*/
|
|
27
|
-
export declare function registerEvent(type: EventType, target: any, methodName: string, priority?: number): void;
|
|
28
|
-
/**
|
|
29
|
-
* Get all handlers for an event type, sorted by priority (descending).
|
|
30
|
-
*/
|
|
31
|
-
export declare function getEventHandlers(type: EventType): EventHandler[];
|
|
32
|
-
/**
|
|
33
|
-
* Check if any handlers exist for an event type.
|
|
34
|
-
*/
|
|
35
|
-
export declare function hasEventHandlers(type: EventType): boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Clear all event handlers (for testing).
|
|
38
|
-
*/
|
|
39
|
-
export declare function clearEventRegistry(): void;
|
|
40
|
-
/**
|
|
41
|
-
* Called when DI container initializes, before the server starts.
|
|
42
|
-
* Use for database connections, cache warming, etc.
|
|
43
|
-
*/
|
|
44
|
-
export declare function OnApplicationInit(priority?: number): (target: any, propertyKey: string) => void;
|
|
45
|
-
/**
|
|
46
|
-
* Called right after the application is fully bootstrapped and server is ready.
|
|
47
|
-
* Use for logging, health checks, etc.
|
|
48
|
-
*/
|
|
49
|
-
export declare function OnApplicationBoot(priority?: number): (target: any, propertyKey: string) => void;
|
|
50
|
-
/**
|
|
51
|
-
* Called when application receives SIGTERM or SIGINT.
|
|
52
|
-
* Use for graceful cleanup, closing connections, etc.
|
|
53
|
-
*/
|
|
54
|
-
export declare function OnApplicationShutdown(priority?: number): (target: any, propertyKey: string) => void;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base HTTP Exception class.
|
|
3
|
-
* Throw this from handlers to return custom HTTP error responses.
|
|
4
|
-
*/
|
|
5
|
-
export declare class HttpException extends Error {
|
|
6
|
-
readonly statusCode: number;
|
|
7
|
-
readonly errors?: any[];
|
|
8
|
-
constructor(statusCode: number, message: string, errors?: any[]);
|
|
9
|
-
/**
|
|
10
|
-
* Convert exception to Response.
|
|
11
|
-
*/
|
|
12
|
-
toResponse(): Response;
|
|
13
|
-
}
|
|
14
|
-
export declare class BadRequestException extends HttpException {
|
|
15
|
-
constructor(message?: string, errors?: any[]);
|
|
16
|
-
}
|
|
17
|
-
export declare class UnauthorizedException extends HttpException {
|
|
18
|
-
constructor(message?: string);
|
|
19
|
-
}
|
|
20
|
-
export declare class ForbiddenException extends HttpException {
|
|
21
|
-
constructor(message?: string);
|
|
22
|
-
}
|
|
23
|
-
export declare class NotFoundException extends HttpException {
|
|
24
|
-
constructor(message?: string);
|
|
25
|
-
}
|
|
26
|
-
export declare class MethodNotAllowedException extends HttpException {
|
|
27
|
-
constructor(message?: string);
|
|
28
|
-
}
|
|
29
|
-
export declare class ConflictException extends HttpException {
|
|
30
|
-
constructor(message?: string);
|
|
31
|
-
}
|
|
32
|
-
export declare class UnprocessableEntityException extends HttpException {
|
|
33
|
-
constructor(message?: string, errors?: any[]);
|
|
34
|
-
}
|
|
35
|
-
export declare class TooManyRequestsException extends HttpException {
|
|
36
|
-
constructor(message?: string);
|
|
37
|
-
}
|
|
38
|
-
export declare class InternalServerErrorException extends HttpException {
|
|
39
|
-
constructor(message?: string);
|
|
40
|
-
}
|
|
41
|
-
export declare class ServiceUnavailableException extends HttpException {
|
|
42
|
-
constructor(message?: string);
|
|
43
|
-
}
|
package/src/index.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Carno - Ultra-Fast HTTP Framework
|
|
3
|
-
*
|
|
4
|
-
* Design principles:
|
|
5
|
-
* 1. ZERO abstraction at runtime - everything compiled at startup
|
|
6
|
-
* 2. Direct Bun.serve() with native routes
|
|
7
|
-
* 3. JIT compiled handlers with AOT async detection
|
|
8
|
-
* 4. No intermediate layers in hot path
|
|
9
|
-
* 5. Radix tree router for dynamic routes
|
|
10
|
-
*/
|
|
11
|
-
import 'reflect-metadata';
|
|
12
|
-
export { Carno } from './Carno';
|
|
13
|
-
export type { MiddlewareHandler, CarnoConfig } from './Carno';
|
|
14
|
-
export { Context } from './context/Context';
|
|
15
|
-
export { Controller } from './decorators/Controller';
|
|
16
|
-
export type { ControllerOptions } from './metadata';
|
|
17
|
-
export { Get, Post, Put, Delete, Patch, Head, Options } from './decorators/methods';
|
|
18
|
-
export { Param, Query, Body, Header, Req, Ctx, Locals } from './decorators/params';
|
|
19
|
-
export { Use, Use as Middleware } from './decorators/Middleware';
|
|
20
|
-
export type { CarnoMiddleware, CarnoClosure } from './middleware/CarnoMiddleware';
|
|
21
|
-
export { Service } from './decorators/Service';
|
|
22
|
-
export { Inject } from './decorators/Inject';
|
|
23
|
-
export { Container, Scope } from './container/Container';
|
|
24
|
-
export type { Token, ProviderConfig } from './container/Container';
|
|
25
|
-
export { RadixRouter } from './router/RadixRouter';
|
|
26
|
-
export type { RouteMatch } from './router/RadixRouter';
|
|
27
|
-
export { CorsHandler } from './cors/CorsHandler';
|
|
28
|
-
export type { CorsConfig, CorsOrigin } from './cors/CorsHandler';
|
|
29
|
-
export type { ValidatorAdapter, ValidationResult, ValidationError, ValidationConfig } from './validation/ValidatorAdapter';
|
|
30
|
-
export { Schema, getSchema, VALIDATION_SCHEMA } from './validation/ValidatorAdapter';
|
|
31
|
-
export { ZodAdapter, ValidationException } from './validation/ZodAdapter';
|
|
32
|
-
export { ValibotAdapter } from './validation/ValibotAdapter';
|
|
33
|
-
export { HttpException, BadRequestException, UnauthorizedException, ForbiddenException, NotFoundException, MethodNotAllowedException, ConflictException, UnprocessableEntityException, TooManyRequestsException, InternalServerErrorException, ServiceUnavailableException } from './exceptions/HttpException';
|
|
34
|
-
export { EventType, OnApplicationInit, OnApplicationBoot, OnApplicationShutdown } from './events/Lifecycle';
|
|
35
|
-
export { CacheService } from './cache/CacheService';
|
|
36
|
-
export { MemoryDriver } from './cache/MemoryDriver';
|
|
37
|
-
export { RedisDriver } from './cache/RedisDriver';
|
|
38
|
-
export type { RedisConfig } from './cache/RedisDriver';
|
|
39
|
-
export type { CacheDriver, CacheConfig } from './cache/CacheDriver';
|
|
40
|
-
export { createTestHarness, withTestApp } from './testing/TestHarness';
|
|
41
|
-
export type { TestHarness, TestOptions } from './testing/TestHarness';
|
|
42
|
-
export { Metadata, isObject, isString } from './utils/Metadata';
|
package/src/metadata.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Scope } from './container/Container';
|
|
2
|
-
/**
|
|
3
|
-
* Controller options for the @Controller decorator.
|
|
4
|
-
*/
|
|
5
|
-
export interface ControllerOptions {
|
|
6
|
-
path?: string;
|
|
7
|
-
scope?: Scope;
|
|
8
|
-
children?: any[];
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Controller metadata stored on controller classes.
|
|
12
|
-
*/
|
|
13
|
-
export interface ControllerMeta {
|
|
14
|
-
path: string;
|
|
15
|
-
scope?: Scope;
|
|
16
|
-
children?: any[];
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Route metadata stored on controllers.
|
|
20
|
-
*/
|
|
21
|
-
export interface RouteInfo {
|
|
22
|
-
method: 'get' | 'post' | 'put' | 'delete' | 'patch' | 'head' | 'options';
|
|
23
|
-
path: string;
|
|
24
|
-
handlerName: string;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Middleware metadata.
|
|
28
|
-
*/
|
|
29
|
-
export interface MiddlewareInfo {
|
|
30
|
-
handler: Function;
|
|
31
|
-
target?: string;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Metadata keys.
|
|
35
|
-
*/
|
|
36
|
-
export declare const CONTROLLER_META: unique symbol;
|
|
37
|
-
export declare const ROUTES_META: unique symbol;
|
|
38
|
-
export declare const PARAMS_META: unique symbol;
|
|
39
|
-
export declare const MIDDLEWARE_META: unique symbol;
|
|
40
|
-
export declare const SERVICE_META: unique symbol;
|
|
41
|
-
export declare const INJECT_META: unique symbol;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Context } from '../context/Context';
|
|
2
|
-
/**
|
|
3
|
-
* Closure function to call the next middleware in the chain.
|
|
4
|
-
*/
|
|
5
|
-
export type CarnoClosure = () => void | Promise<void>;
|
|
6
|
-
/**
|
|
7
|
-
* Interface for onion-style middleware.
|
|
8
|
-
* Middleware must call next() to continue the chain.
|
|
9
|
-
*/
|
|
10
|
-
export interface CarnoMiddleware {
|
|
11
|
-
handle(ctx: Context, next: CarnoClosure): void | Promise<void>;
|
|
12
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ultra-fast Radix Router for Turbo.
|
|
3
|
-
*
|
|
4
|
-
* Optimizations:
|
|
5
|
-
* - Char code comparisons (no string allocations)
|
|
6
|
-
* - Frozen empty params object
|
|
7
|
-
* - O(1) method lookup via char code index
|
|
8
|
-
* - Minimal allocations in hot path
|
|
9
|
-
*/
|
|
10
|
-
export interface RouteMatch<T> {
|
|
11
|
-
store: T;
|
|
12
|
-
params: Record<string, string>;
|
|
13
|
-
}
|
|
14
|
-
export declare class RadixRouter<T> {
|
|
15
|
-
private roots;
|
|
16
|
-
add(method: string, path: string, store: T): void;
|
|
17
|
-
find(method: string, path: string): RouteMatch<T> | null;
|
|
18
|
-
private matchPath;
|
|
19
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { Server } from 'bun';
|
|
2
|
-
import { Carno, type CarnoConfig } from '../Carno';
|
|
3
|
-
import { Container, type Token } from '../container/Container';
|
|
4
|
-
/**
|
|
5
|
-
* Test configuration options.
|
|
6
|
-
*/
|
|
7
|
-
export interface TestOptions {
|
|
8
|
-
config?: CarnoConfig;
|
|
9
|
-
listen?: boolean | number;
|
|
10
|
-
port?: number;
|
|
11
|
-
controllers?: (new (...args: any[]) => any)[];
|
|
12
|
-
services?: (Token | any)[];
|
|
13
|
-
plugins?: Carno[];
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Test harness - provides utilities for testing Carno applications.
|
|
17
|
-
*/
|
|
18
|
-
export interface TestHarness {
|
|
19
|
-
/** The Carno app instance */
|
|
20
|
-
app: Carno;
|
|
21
|
-
/** The internal DI container */
|
|
22
|
-
container: Container;
|
|
23
|
-
/** The HTTP server (if listening) */
|
|
24
|
-
server?: Server<any>;
|
|
25
|
-
/** The port the server is running on */
|
|
26
|
-
port?: number;
|
|
27
|
-
/** Resolve a service from the container */
|
|
28
|
-
resolve<T>(token: Token<T>): T;
|
|
29
|
-
/** Make an HTTP request to the app */
|
|
30
|
-
request(path: string, init?: RequestInit): Promise<Response>;
|
|
31
|
-
/** Make a GET request */
|
|
32
|
-
get(path: string, init?: Omit<RequestInit, 'method'>): Promise<Response>;
|
|
33
|
-
/** Make a POST request */
|
|
34
|
-
post(path: string, body?: any, init?: Omit<RequestInit, 'method' | 'body'>): Promise<Response>;
|
|
35
|
-
/** Make a PUT request */
|
|
36
|
-
put(path: string, body?: any, init?: Omit<RequestInit, 'method' | 'body'>): Promise<Response>;
|
|
37
|
-
/** Make a DELETE request */
|
|
38
|
-
delete(path: string, init?: Omit<RequestInit, 'method'>): Promise<Response>;
|
|
39
|
-
/** Close the test harness and cleanup */
|
|
40
|
-
close(): Promise<void>;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Create a test harness for Turbo applications.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```typescript
|
|
47
|
-
* const harness = await createTestHarness({
|
|
48
|
-
* controllers: [UserController],
|
|
49
|
-
* services: [UserService],
|
|
50
|
-
* listen: true
|
|
51
|
-
* });
|
|
52
|
-
*
|
|
53
|
-
* const response = await harness.get('/users');
|
|
54
|
-
* expect(response.status).toBe(200);
|
|
55
|
-
*
|
|
56
|
-
* await harness.close();
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
export declare function createTestHarness(options?: TestOptions): Promise<TestHarness>;
|
|
60
|
-
/**
|
|
61
|
-
* Run a test routine with automatic harness cleanup.
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```typescript
|
|
65
|
-
* await withTestApp(async (harness) => {
|
|
66
|
-
* const response = await harness.get('/health');
|
|
67
|
-
* expect(response.status).toBe(200);
|
|
68
|
-
* }, { controllers: [HealthController], listen: true });
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
export declare function withTestApp(routine: (harness: TestHarness) => Promise<void>, options?: TestOptions): Promise<void>;
|
package/src/utils/Metadata.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility class for handling metadata operations.
|
|
3
|
-
* Wraps Reflect.getMetadata and Reflect.defineMetadata.
|
|
4
|
-
*/
|
|
5
|
-
export declare class Metadata {
|
|
6
|
-
static get<T = any>(key: string | symbol, target: any): T | undefined;
|
|
7
|
-
static set(key: string | symbol, value: any, target: any): void;
|
|
8
|
-
static has(key: string | symbol, target: any): boolean;
|
|
9
|
-
static delete(key: string | symbol, target: any): boolean;
|
|
10
|
-
static keys(target: any): (string | symbol)[];
|
|
11
|
-
static getType(target: any, propertyKey: string | symbol): any;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Type guard for checking if value is an object.
|
|
15
|
-
*/
|
|
16
|
-
export declare function isObject(value: unknown): value is Record<string, any>;
|
|
17
|
-
/**
|
|
18
|
-
* Type guard for checking if value is a string.
|
|
19
|
-
*/
|
|
20
|
-
export declare function isString(value: unknown): value is string;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* High-performance query string parser.
|
|
3
|
-
*
|
|
4
|
-
* Based on Elysia's approach - uses manual string parsing with charCodeAt()
|
|
5
|
-
* instead of new URL() for significant performance gains.
|
|
6
|
-
*
|
|
7
|
-
* Benchmark: ~10x faster than new URL().searchParams
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Parse query string from a full URL.
|
|
11
|
-
* Extracts the query portion and parses key-value pairs.
|
|
12
|
-
*
|
|
13
|
-
* @param url Full URL string (e.g., "http://localhost/path?foo=bar&baz=123")
|
|
14
|
-
* @returns Record<string, string> - parsed query parameters
|
|
15
|
-
*/
|
|
16
|
-
export declare function parseQueryFromURL(url: string): Record<string, string>;
|
|
17
|
-
/**
|
|
18
|
-
* Parse query string directly.
|
|
19
|
-
*
|
|
20
|
-
* @param input Query string without leading '?' (e.g., "foo=bar&baz=123")
|
|
21
|
-
* @returns Record<string, string> - parsed query parameters
|
|
22
|
-
*/
|
|
23
|
-
export declare function parseQueryString(input: string): Record<string, string>;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { ValidatorAdapter, ValidationResult } from './ValidatorAdapter';
|
|
2
|
-
/**
|
|
3
|
-
* Valibot Adapter for Turbo validation.
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* ```typescript
|
|
7
|
-
* import * as v from 'valibot';
|
|
8
|
-
*
|
|
9
|
-
* @Schema(v.object({
|
|
10
|
-
* name: v.pipe(v.string(), v.minLength(1)),
|
|
11
|
-
* email: v.pipe(v.string(), v.email())
|
|
12
|
-
* }))
|
|
13
|
-
* class CreateUserDto {
|
|
14
|
-
* name: string;
|
|
15
|
-
* email: string;
|
|
16
|
-
* }
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export declare class ValibotAdapter implements ValidatorAdapter {
|
|
20
|
-
readonly name = "ValibotAdapter";
|
|
21
|
-
private schemaCache;
|
|
22
|
-
private valibot;
|
|
23
|
-
constructor();
|
|
24
|
-
private ensureValibot;
|
|
25
|
-
hasValidation(target: any): boolean;
|
|
26
|
-
validate<T>(target: any, value: unknown): ValidationResult<T>;
|
|
27
|
-
validateOrThrow<T>(target: any, value: unknown): T;
|
|
28
|
-
private getOrCacheSchema;
|
|
29
|
-
private formatErrors;
|
|
30
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validation result type.
|
|
3
|
-
*/
|
|
4
|
-
export interface ValidationResult<T = any> {
|
|
5
|
-
success: boolean;
|
|
6
|
-
data?: T;
|
|
7
|
-
errors?: ValidationError[];
|
|
8
|
-
}
|
|
9
|
-
export interface ValidationError {
|
|
10
|
-
path: string;
|
|
11
|
-
message: string;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Base interface for validation adapters.
|
|
15
|
-
* Adapters provide validation capabilities for different libraries.
|
|
16
|
-
*/
|
|
17
|
-
export interface ValidatorAdapter {
|
|
18
|
-
/**
|
|
19
|
-
* Validator name for debugging.
|
|
20
|
-
*/
|
|
21
|
-
readonly name: string;
|
|
22
|
-
/**
|
|
23
|
-
* Check if a target has validation schema.
|
|
24
|
-
*/
|
|
25
|
-
hasValidation(target: any): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Validate and transform a value.
|
|
28
|
-
* Returns result object instead of throwing for better performance.
|
|
29
|
-
*/
|
|
30
|
-
validate<T>(target: any, value: unknown): ValidationResult<T>;
|
|
31
|
-
/**
|
|
32
|
-
* Validate and transform, throwing on error.
|
|
33
|
-
* Used when you want to short-circuit on failure.
|
|
34
|
-
*/
|
|
35
|
-
validateOrThrow<T>(target: any, value: unknown): T;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Validation configuration for Turbo.
|
|
39
|
-
*/
|
|
40
|
-
export interface ValidationConfig {
|
|
41
|
-
adapter: ValidatorAdapter;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Symbol for storing validation schema on DTOs.
|
|
45
|
-
*/
|
|
46
|
-
export declare const VALIDATION_SCHEMA: unique symbol;
|
|
47
|
-
/**
|
|
48
|
-
* Decorator to attach a validation schema to a DTO class.
|
|
49
|
-
*/
|
|
50
|
-
export declare function Schema(schema: any): ClassDecorator;
|
|
51
|
-
/**
|
|
52
|
-
* Get the validation schema from a DTO class.
|
|
53
|
-
*/
|
|
54
|
-
export declare function getSchema(target: any): any | undefined;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { ValidatorAdapter, ValidationResult, ValidationError } from './ValidatorAdapter';
|
|
2
|
-
/**
|
|
3
|
-
* Zod Adapter - Default validation adapter for Turbo.
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* ```typescript
|
|
7
|
-
* import { z } from 'zod';
|
|
8
|
-
*
|
|
9
|
-
* @Schema(z.object({
|
|
10
|
-
* name: z.string().min(1),
|
|
11
|
-
* email: z.string().email()
|
|
12
|
-
* }))
|
|
13
|
-
* class CreateUserDto {
|
|
14
|
-
* name: string;
|
|
15
|
-
* email: string;
|
|
16
|
-
* }
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export declare class ZodAdapter implements ValidatorAdapter {
|
|
20
|
-
readonly name = "ZodAdapter";
|
|
21
|
-
private schemaCache;
|
|
22
|
-
hasValidation(target: any): boolean;
|
|
23
|
-
validate<T>(target: any, value: unknown): ValidationResult<T>;
|
|
24
|
-
validateOrThrow<T>(target: any, value: unknown): T;
|
|
25
|
-
private getOrCacheSchema;
|
|
26
|
-
private formatErrors;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Validation exception thrown when validation fails.
|
|
30
|
-
*/
|
|
31
|
-
export declare class ValidationException extends Error {
|
|
32
|
-
readonly errors: ValidationError[];
|
|
33
|
-
constructor(errors: ValidationError[]);
|
|
34
|
-
toResponse(): Response;
|
|
35
|
-
}
|