Comparing version 0.1.1 to 0.2.0
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { Http2SecureServer, Http2Server } from 'node:http2'; | ||
import { Request } from './request.js'; | ||
import { Response } from './response.js'; | ||
import { Router } from './router.js'; | ||
@@ -27,2 +29,2 @@ export declare const NEXT = "next"; | ||
} | ||
export { Router, }; | ||
export { Router, Request, Response, }; |
@@ -0,0 +0,0 @@ import { createSecureServer, createServer, } from 'node:http2'; |
@@ -0,0 +0,0 @@ import type { Request } from '../request.js'; |
@@ -0,0 +0,0 @@ import { randomUUID } from 'node:crypto'; |
@@ -0,0 +0,0 @@ export * from './form-data.js'; |
@@ -0,0 +0,0 @@ export * from './form-data.js'; |
@@ -0,0 +0,0 @@ import type { Request } from '../request.js'; |
@@ -0,0 +0,0 @@ export function deserializeJsonPayload(options) { |
@@ -0,0 +0,0 @@ /// <reference types="node" /> |
@@ -0,0 +0,0 @@ export function preparePlainTextPayload({ encoding = 'utf-8' } = {}) { |
@@ -0,0 +0,0 @@ import type { Request } from '../request.js'; |
@@ -0,0 +0,0 @@ import { createHash } from 'node:crypto'; |
import { Request } from '../request.js'; | ||
import { Response } from '../response.js'; | ||
export declare function prepareStreamPayload(): (req: Request, res: Response) => Promise<"next">; |
@@ -0,0 +0,0 @@ export function prepareStreamPayload() { |
@@ -0,0 +0,0 @@ import { Request } from '../request.js'; |
@@ -0,0 +0,0 @@ export function deserializeUrlencodedPayload( /* options?: DeserializeUrlencodedOptions */) { |
@@ -0,0 +0,0 @@ export declare function getRouteParams(path: PathString, pathPattern: PathMatcher): ParamsDictionary | false; |
@@ -0,0 +0,0 @@ import { URL } from 'node:url'; |
@@ -8,24 +8,27 @@ /// <reference types="node" /> | ||
import { SupportedHttpMethods } from './router.js'; | ||
declare global { | ||
namespace Fluvial { | ||
interface BaseRequest { | ||
readonly response: Response; | ||
readonly path: PathString; | ||
readonly method: SupportedHttpMethods; | ||
readonly headers: Readonly<IncomingHttpHeaders>; | ||
readonly payload: any; | ||
readonly rawRequest: Http2ServerRequest | IncomingMessage; | ||
readonly params: Readonly<ParamsDictionary>; | ||
readonly query: Readonly<QueryDictionary>; | ||
readonly hash: string; | ||
readonly httpVersion: '1.1' | '2.0'; | ||
} | ||
interface Http1Request extends BaseRequest { | ||
readonly rawRequest: IncomingMessage; | ||
readonly httpVersion: '1.1'; | ||
} | ||
interface Http2Request extends BaseRequest { | ||
readonly rawRequest: Http2ServerRequest; | ||
readonly httpVersion: '2.0'; | ||
} | ||
} | ||
} | ||
export declare function wrapRequest(rawRequest: Http2ServerRequest | IncomingMessage): Request; | ||
interface BaseRequest { | ||
readonly response: Response; | ||
readonly path: PathString; | ||
readonly method: SupportedHttpMethods; | ||
readonly headers: Readonly<IncomingHttpHeaders>; | ||
readonly payload: any; | ||
readonly rawRequest: Http2ServerRequest | IncomingMessage; | ||
readonly params: Readonly<ParamsDictionary>; | ||
readonly query: Readonly<QueryDictionary>; | ||
readonly hash: string; | ||
readonly httpVersion: '1.1' | '2.0'; | ||
} | ||
interface Http1Request extends BaseRequest { | ||
readonly rawRequest: IncomingMessage; | ||
readonly httpVersion: '1.1'; | ||
} | ||
interface Http2Request extends BaseRequest { | ||
readonly rawRequest: Http2ServerRequest; | ||
readonly httpVersion: '2.0'; | ||
} | ||
type Request = Http1Request | Http2Request; | ||
export type { Request, }; | ||
export type Request = Fluvial.Http1Request | Fluvial.Http2Request; |
@@ -0,0 +0,0 @@ import { constants } from 'node:http2'; |
@@ -9,40 +9,49 @@ /// <reference types="node" /> | ||
import { Request } from './request'; | ||
declare global { | ||
namespace Fluvial { | ||
interface BaseResponse { | ||
readonly request: Request; | ||
readonly rawResponse: Http2ServerResponse | ServerResponse; | ||
readonly headers: Record<string, string | string[]>; | ||
readonly httpVersion: '1.1' | '2.0'; | ||
/** getter for if a response has already been sent and the response is closed */ | ||
readonly responseSent: boolean; | ||
/** getter for the current status code */ | ||
status(): number; | ||
/** setter for a new status code */ | ||
status(statusCode: number): void; | ||
/** getter for the current eventSource value (default: false) */ | ||
asEventSource(): boolean; | ||
/** setter for the eventSource value */ | ||
asEventSource(bool: boolean): void; | ||
/** pass-thru for http2Stream.write */ | ||
write(data: string | Buffer): void; | ||
/** DEFAULT MODE ONLY: the simplest way to respond with or without data */ | ||
send(data?: any): void; | ||
/** ideal for object data to be consumed in a browser */ | ||
json(data: object): void; | ||
/** DEFAULT MODE ONLY: pass-thru for http2Stream.end */ | ||
end(data?: string | Buffer): void; | ||
/** EVENT STREAM MODE ONLY: when the response is set as an event stream, this sends the event; errors otherwise */ | ||
sendEvent(data?: object | string): void; | ||
/** ideal for needing to respond with files */ | ||
stream(stream: Readable): void; | ||
} | ||
interface __InternalResponse extends Fluvial.BaseResponse { | ||
_status: number; | ||
_eventSource: boolean; | ||
_eventSourceId: string; | ||
_send(data?: string): void; | ||
} | ||
interface Http1Response extends BaseResponse { | ||
readonly httpVersion: '1.1'; | ||
readonly rawResponse: ServerResponse; | ||
} | ||
interface Http2Response extends BaseResponse { | ||
readonly httpVersion: '2.0'; | ||
readonly rawResponse: Http2ServerResponse; | ||
} | ||
} | ||
} | ||
export declare function wrapResponse(rawResponse: Http2ServerResponse | ServerResponse): Response; | ||
interface BaseResponse { | ||
readonly request: Request; | ||
readonly rawResponse: Http2ServerResponse | ServerResponse; | ||
readonly headers: Record<string, string | string[]>; | ||
readonly httpVersion: '1.1' | '2.0'; | ||
/** getter for if a response has already been sent and the response is closed */ | ||
readonly responseSent: boolean; | ||
/** getter for the current status code */ | ||
status(): number; | ||
/** setter for a new status code */ | ||
status(statusCode: number): void; | ||
/** getter for the current eventSource value (default: false) */ | ||
asEventSource(): boolean; | ||
/** setter for the eventSource value */ | ||
asEventSource(bool: boolean): void; | ||
/** pass-thru for http2Stream.write */ | ||
write(data: string | Buffer): void; | ||
/** DEFAULT MODE ONLY: the simplest way to respond with or without data */ | ||
send(data?: any): void; | ||
/** ideal for object data to be consumed in a browser */ | ||
json(data: object): void; | ||
/** DEFAULT MODE ONLY: pass-thru for http2Stream.end */ | ||
end(data?: string | Buffer): void; | ||
/** EVENT STREAM MODE ONLY: when the response is set as an event stream, this sends the event; errors otherwise */ | ||
sendEvent(data?: object | string): void; | ||
/** ideal for needing to respond with files */ | ||
stream(stream: Readable): void; | ||
} | ||
interface Http1Response extends BaseResponse { | ||
readonly httpVersion: '1.1'; | ||
readonly rawResponse: ServerResponse; | ||
} | ||
interface Http2Response extends BaseResponse { | ||
readonly httpVersion: '2.0'; | ||
readonly rawResponse: Http2ServerResponse; | ||
} | ||
type Response = Http1Response | Http2Response; | ||
export type { Response, }; | ||
export type Response = Fluvial.Http1Response | Fluvial.Http2Response; |
@@ -0,0 +0,0 @@ import { randomUUID } from 'node:crypto'; |
import { type PathString, type PathMatcher } from './path-matching.js'; | ||
import type { Request } from './request.js'; | ||
import type { Response } from './response.js'; | ||
declare global { | ||
namespace Fluvial { | ||
/** @protected exported type; should not be imported outside of this package */ | ||
interface __InternalRouter extends Router { | ||
handleRequest(remainingPath: PathString, req: Request, res: Response, err?: unknown): Promise<void | 'next'>; | ||
__getMatchingRoute(state: __RouterState): Generator<__InternalRoute>; | ||
routes: __InternalRoute[]; | ||
__addRoute(method: HandlerHttpMethods | null, path: PathMatcher, ...handlers: (RequestHandler | ErrorHandler | Router)[]): __InternalRoute; | ||
} | ||
interface Router { | ||
component: 'router'; | ||
get(path: PathMatcher, ...handlers: RequestHandler[]): this; | ||
post(path: PathMatcher, ...handlers: RequestHandler[]): this; | ||
put(path: PathMatcher, ...handlers: RequestHandler[]): this; | ||
patch(path: PathMatcher, ...handlers: RequestHandler[]): this; | ||
delete(path: PathMatcher, ...handlers: RequestHandler[]): this; | ||
options(path: PathMatcher, ...handlers: RequestHandler[]): this; | ||
head(path: PathMatcher, ...handlers: RequestHandler[]): this; | ||
all(path: PathMatcher, ...handlers: RequestHandler[]): this; | ||
use(path: PathMatcher, ...handlers: (RequestHandler | Router)[]): this; | ||
use(...handlers: (RequestHandler | Router)[]): this; | ||
route(path: PathMatcher): Route; | ||
catch(path: PathMatcher, ...handlers: ErrorHandler[]): this; | ||
catch(...handlers: ErrorHandler[]): this; | ||
} | ||
/** @protected exported type; should not be imported outside of this package */ | ||
interface __InternalRoute extends Route { | ||
handleRequest(remainingPath: string, req: Request, res: Response, err?: unknown): Promise<void | 'next'>; | ||
__getMatchingHandlers(this: __InternalRoute, state: __RouteHandlerState): Generator<(RequestHandler | ErrorHandler | __InternalRouter)[]>; | ||
handlers: [method: HandlerHttpMethods, ...handlers: (RequestHandler | ErrorHandler | Router)[]][]; | ||
pathMatcher: PathMatcher; | ||
} | ||
type HandlerHttpMethods = SupportedHttpMethods | 'ALL' | 'ERROR'; | ||
interface __RouterState { | ||
error?: unknown; | ||
path: PathString; | ||
req: Request; | ||
end?: boolean; | ||
} | ||
interface __RouteHandlerState { | ||
error?: unknown; | ||
req: Request; | ||
end?: boolean; | ||
} | ||
interface Route { | ||
component: 'route'; | ||
get(...handlers: RequestHandler[]): this; | ||
post(...handlers: RequestHandler[]): this; | ||
put(...handlers: RequestHandler[]): this; | ||
patch(...handlers: RequestHandler[]): this; | ||
delete(...handlers: RequestHandler[]): this; | ||
options(...handlers: RequestHandler[]): this; | ||
head(...handlers: RequestHandler[]): this; | ||
all(...handlers: RequestHandler[]): this; | ||
catch(...handlers: ErrorHandler[]): this; | ||
} | ||
/** | ||
* A regular route handler or middleware function | ||
*/ | ||
interface RequestHandler { | ||
(req: Request, res: Response): void | 'next' | 'route' | Promise<void | 'next' | 'route'>; | ||
} | ||
/** | ||
* An error route handler or middleware function. Three parameters are required; any less and it's considered a regular route handler | ||
*/ | ||
interface ErrorHandler<ErrorType = unknown> { | ||
(err: ErrorType, req: Request, res: Response): void | 'next' | Promise<void | 'next'>; | ||
} | ||
} | ||
} | ||
export declare function Router(): Router; | ||
export declare const routerPrototype: { | ||
readonly component: string; | ||
get(this: __InternalRouter, path: PathMatcher, ...handlers: RequestHandler[]): Router; | ||
post(this: __InternalRouter, path: PathMatcher, ...handlers: RequestHandler[]): Router; | ||
put(this: __InternalRouter, path: PathMatcher, ...handlers: RequestHandler[]): Router; | ||
patch(this: __InternalRouter, path: PathMatcher, ...handlers: RequestHandler[]): Router; | ||
delete(this: __InternalRouter, path: PathMatcher, ...handlers: RequestHandler[]): Router; | ||
options(this: __InternalRouter, path: PathMatcher, ...handlers: RequestHandler[]): Router; | ||
head(this: __InternalRouter, path: PathMatcher, ...handlers: RequestHandler[]): Router; | ||
all(this: __InternalRouter, path: PathMatcher, ...handlers: RequestHandler[]): Router; | ||
route(this: __InternalRouter, path: PathMatcher): Route; | ||
use(this: __InternalRouter, pathOrHandler: PathMatcher | RequestHandler | Router, ...handlers: (RequestHandler | Router)[]): Router; | ||
get(this: __InternalRouter, path: PathMatcher, ...handlers: RequestHandler[]): Fluvial.Router; | ||
post(this: __InternalRouter, path: PathMatcher, ...handlers: RequestHandler[]): Fluvial.Router; | ||
put(this: __InternalRouter, path: PathMatcher, ...handlers: RequestHandler[]): Fluvial.Router; | ||
patch(this: __InternalRouter, path: PathMatcher, ...handlers: RequestHandler[]): Fluvial.Router; | ||
delete(this: __InternalRouter, path: PathMatcher, ...handlers: RequestHandler[]): Fluvial.Router; | ||
options(this: __InternalRouter, path: PathMatcher, ...handlers: RequestHandler[]): Fluvial.Router; | ||
head(this: __InternalRouter, path: PathMatcher, ...handlers: RequestHandler[]): Fluvial.Router; | ||
all(this: __InternalRouter, path: PathMatcher, ...handlers: RequestHandler[]): Fluvial.Router; | ||
route(this: __InternalRouter, path: PathMatcher): Fluvial.Route; | ||
use(this: __InternalRouter, pathOrHandler: PathMatcher | RequestHandler | Router, ...handlers: (RequestHandler | Router)[]): Fluvial.Router; | ||
catch(this: __InternalRouter, pathOrHandler: PathMatcher | ErrorHandler, ...handlers: ErrorHandler[]): void; | ||
@@ -23,71 +93,12 @@ /** | ||
__getMatchingRoute: (state: __RouterState) => Generator<__InternalRoute>; | ||
__addRoute(this: __InternalRouter, method: HandlerHttpMethods | null, path: PathMatcher, ...handlers: (RequestHandler | ErrorHandler | Router)[]): __InternalRoute; | ||
__addRoute(this: __InternalRouter, method: HandlerHttpMethods | null, path: PathMatcher, ...handlers: (RequestHandler | ErrorHandler | Router)[]): Fluvial.__InternalRoute; | ||
}; | ||
/** @protected exported type; should not be imported outside of this package */ | ||
export interface __InternalRouter extends Router { | ||
handleRequest(remainingPath: PathString, req: Request, res: Response, err?: unknown): Promise<void | 'next'>; | ||
__getMatchingRoute(state: __RouterState): Generator<__InternalRoute>; | ||
routes: __InternalRoute[]; | ||
__addRoute(method: HandlerHttpMethods | null, path: PathMatcher, ...handlers: (RequestHandler | ErrorHandler | Router)[]): __InternalRoute; | ||
} | ||
export interface Router { | ||
component: 'router'; | ||
get(path: PathMatcher, ...handlers: RequestHandler[]): this; | ||
post(path: PathMatcher, ...handlers: RequestHandler[]): this; | ||
put(path: PathMatcher, ...handlers: RequestHandler[]): this; | ||
patch(path: PathMatcher, ...handlers: RequestHandler[]): this; | ||
delete(path: PathMatcher, ...handlers: RequestHandler[]): this; | ||
options(path: PathMatcher, ...handlers: RequestHandler[]): this; | ||
head(path: PathMatcher, ...handlers: RequestHandler[]): this; | ||
all(path: PathMatcher, ...handlers: RequestHandler[]): this; | ||
use(path: PathMatcher, ...handlers: (RequestHandler | Router)[]): this; | ||
use(...handlers: (RequestHandler | Router)[]): this; | ||
route(path: PathMatcher): Route; | ||
catch(path: PathMatcher, ...handlers: ErrorHandler[]): this; | ||
catch(...handlers: ErrorHandler[]): this; | ||
} | ||
/** @protected exported type; should not be imported outside of this package */ | ||
export interface __InternalRoute extends Route { | ||
handleRequest(remainingPath: string, req: Request, res: Response, err?: unknown): Promise<void | 'next'>; | ||
__getMatchingHandlers(this: __InternalRoute, state: __RouteHandlerState): Generator<(RequestHandler | ErrorHandler | __InternalRouter)[]>; | ||
handlers: [method: HandlerHttpMethods, ...handlers: (RequestHandler | ErrorHandler | Router)[]][]; | ||
pathMatcher: PathMatcher; | ||
} | ||
type HandlerHttpMethods = SupportedHttpMethods | 'ALL' | 'ERROR'; | ||
interface __RouterState { | ||
error?: unknown; | ||
path: PathString; | ||
req: Request; | ||
end?: boolean; | ||
} | ||
interface __RouteHandlerState { | ||
error?: unknown; | ||
req: Request; | ||
end?: boolean; | ||
} | ||
interface Route { | ||
component: 'route'; | ||
get(...handlers: RequestHandler[]): this; | ||
post(...handlers: RequestHandler[]): this; | ||
put(...handlers: RequestHandler[]): this; | ||
patch(...handlers: RequestHandler[]): this; | ||
delete(...handlers: RequestHandler[]): this; | ||
options(...handlers: RequestHandler[]): this; | ||
head(...handlers: RequestHandler[]): this; | ||
all(...handlers: RequestHandler[]): this; | ||
catch(...handlers: ErrorHandler[]): this; | ||
} | ||
/** | ||
* A regular route handler or middleware function | ||
*/ | ||
interface RequestHandler { | ||
(req: Request, res: Response): void | 'next' | 'route' | Promise<void | 'next' | 'route'>; | ||
} | ||
/** | ||
* An error route handler or middleware function. Three parameters are required; any less and it's considered a regular route handler | ||
*/ | ||
interface ErrorHandler<ErrorType = unknown> { | ||
(err: ErrorType, req: Request, res: Response): void | 'next' | Promise<void | 'next'>; | ||
} | ||
export type __InternalRouter = Fluvial.__InternalRouter; | ||
export type __InternalRoute = Fluvial.__InternalRoute; | ||
export type Route = Fluvial.Route; | ||
export type Router = Fluvial.Router; | ||
export type RequestHandler = Fluvial.RequestHandler; | ||
export type ErrorHandler = Fluvial.ErrorHandler; | ||
type HandlerHttpMethods = Fluvial.HandlerHttpMethods; | ||
export type SupportedHttpMethods = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD'; | ||
export {}; |
@@ -0,0 +0,0 @@ import { getRouteParams, getQueryParams, } from './path-matching.js'; |
export declare function etagMatches(etag: string, matches: string): boolean; | ||
export declare function etagNoneMatches(etag: string, matches: string): boolean; |
@@ -0,0 +0,0 @@ export function etagMatches(etag, matches) { |
export declare function mimeTypeAccepted(targetType: string, accept: string): boolean; |
@@ -0,0 +0,0 @@ export function mimeTypeAccepted(targetType, accept) { |
export declare function areRegexesEquivalent(regex1: RegExp, regex2: RegExp): boolean; |
@@ -0,0 +0,0 @@ export function areRegexesEquivalent(regex1, regex2) { |
{ | ||
"name": "fluvial", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Fluvial: A light http/2 server framework, similar to Express", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
139420
48
1291
3