Comparing version 1.8.0-rc.3 to 1.8.0
@@ -24,21 +24,24 @@ import { QueryObject } from 'ufo'; | ||
} | ||
interface WebEventContext { | ||
request?: Request; | ||
url?: URL; | ||
} | ||
declare class H3Event<_RequestT extends EventHandlerRequest = EventHandlerRequest> implements Pick<FetchEvent, "respondWith"> { | ||
"__is_event__": boolean; | ||
node: NodeEventContext; | ||
web?: WebEventContext; | ||
context: H3EventContext; | ||
_request: Request | undefined; | ||
_method: HTTPMethod | undefined; | ||
_headers: Headers | undefined; | ||
_path: string | undefined; | ||
_url: URL | undefined; | ||
_body: BodyInit | undefined; | ||
_method?: HTTPMethod; | ||
_path?: string; | ||
_headers?: Headers; | ||
_requestBody?: BodyInit; | ||
_handled: boolean; | ||
constructor(req: IncomingMessage, res: ServerResponse); | ||
get _originalPath(): string; | ||
get _hasBody(): boolean; | ||
get method(): HTTPMethod; | ||
get path(): string; | ||
get url(): URL; | ||
get headers(): Headers; | ||
get handled(): boolean; | ||
get method(): HTTPMethod; | ||
get headers(): Headers; | ||
respondWith(response: Response | PromiseLike<Response>): Promise<void>; | ||
toString(): string; | ||
toJSON(): string; | ||
/** @deprecated Please use `event.node.req` instead. **/ | ||
@@ -50,8 +53,2 @@ get req(): IncomingMessage & { | ||
get res(): ServerResponse<IncomingMessage>; | ||
get body(): BodyInit | undefined; | ||
/** @experimental */ | ||
get request(): Request; | ||
respondWith(response: Response | PromiseLike<Response>): Promise<void>; | ||
toString(): string; | ||
toJSON(): string; | ||
} | ||
@@ -64,2 +61,4 @@ declare function isEvent(input: any): input is H3Event; | ||
declare const eventHandler: typeof defineEventHandler; | ||
declare function defineRequestMiddleware<Request extends EventHandlerRequest = EventHandlerRequest>(fn: _RequestMiddleware<Request>): _RequestMiddleware<Request>; | ||
declare function defineResponseMiddleware<Request extends EventHandlerRequest = EventHandlerRequest>(fn: _ResponseMiddleware<Request>): _ResponseMiddleware<Request>; | ||
declare function isEventHandler(input: any): input is EventHandler; | ||
@@ -153,2 +152,21 @@ declare function toEventHandler(input: any, _?: any, _route?: string): EventHandler; | ||
type RouterMethod = Lowercase<HTTPMethod>; | ||
type RouterUse = (path: string, handler: EventHandler, method?: RouterMethod | RouterMethod[]) => Router; | ||
type AddRouteShortcuts = Record<RouterMethod, RouterUse>; | ||
interface Router extends AddRouteShortcuts { | ||
add: RouterUse; | ||
use: RouterUse; | ||
handler: EventHandler; | ||
} | ||
interface RouteNode { | ||
handlers: Partial<Record<RouterMethod | "all", EventHandler>>; | ||
path: string; | ||
} | ||
interface CreateRouterOptions { | ||
/** @deprecated Please use `preemptive` instead. **/ | ||
preemtive?: boolean; | ||
preemptive?: boolean; | ||
} | ||
declare function createRouter(opts?: CreateRouterOptions): Router; | ||
type ValidateResult<T> = T | true | false | void; | ||
@@ -161,3 +179,10 @@ type ValidateFunction<T> = (data: unknown) => ValidateResult<T> | Promise<ValidateResult<T>>; | ||
params?: Record<string, string>; | ||
/** | ||
* Matched router Node | ||
* | ||
* @experimental The object structure may change in non-major version. | ||
*/ | ||
matchedRoute?: RouteNode; | ||
sessions?: Record<string, Session>; | ||
clientAddress?: string; | ||
} | ||
@@ -174,8 +199,10 @@ type EventHandlerResponse<T = any> = T | Promise<T>; | ||
} | ||
type _RequestMiddleware<Request extends EventHandlerRequest = EventHandlerRequest> = (event: H3Event<Request>) => void | Promise<void>; | ||
type _ResponseMiddleware<Request extends EventHandlerRequest = EventHandlerRequest, Response extends EventHandlerResponse = EventHandlerResponse> = (event: H3Event<Request>, response: { | ||
body?: Awaited<Response>; | ||
}) => void | Promise<void>; | ||
type EventHandlerObject<Request extends EventHandlerRequest = EventHandlerRequest, Response extends EventHandlerResponse = EventHandlerResponse> = { | ||
onRequest?: _RequestMiddleware<Request> | _RequestMiddleware<Request>[]; | ||
onBeforeResponse?: _ResponseMiddleware<Request, Response> | _ResponseMiddleware<Request, Response>[]; | ||
handler: EventHandler<Request, Response>; | ||
before?: ((event: H3Event<Request>) => void | Promise<void>)[]; | ||
after?: ((event: H3Event<Request>, response: { | ||
body?: Response; | ||
}) => void | Promise<void>)[]; | ||
}; | ||
@@ -328,2 +355,3 @@ type LazyEventHandler = () => EventHandler | Promise<EventHandler>; | ||
declare function readFormData(event: H3Event): Promise<FormData>; | ||
declare function getRequestWebStream(event: H3Event): undefined | ReadableStream; | ||
@@ -382,2 +410,3 @@ interface CacheConditions { | ||
}): "https" | "http"; | ||
/** @deprecated Use `event.path` instead */ | ||
declare function getRequestPath(event: H3Event): string; | ||
@@ -388,2 +417,11 @@ declare function getRequestURL(event: H3Event, opts?: { | ||
}): URL; | ||
declare function toWebRequest(event: H3Event): Request; | ||
declare function getRequestIP(event: H3Event, opts?: { | ||
/** | ||
* Use the X-Forwarded-For HTTP header set by proxies. | ||
* | ||
* Note: Make sure that this header can be trusted (your application running behind a CDN or reverse proxy) before enabling. | ||
*/ | ||
xForwardedFor?: boolean; | ||
}): string | undefined; | ||
@@ -508,3 +546,3 @@ declare function isPreflightRequest(event: H3Event): boolean; | ||
declare function sanitizeStatusMessage(statusMessage?: string): string; | ||
declare function sanitizeStatusCode(statusCode: string | number, defaultStatusCode?: number): number; | ||
declare function sanitizeStatusCode(statusCode?: string | number, defaultStatusCode?: number): number; | ||
@@ -549,20 +587,8 @@ interface StaticAssetMeta { | ||
type RouterMethod = Lowercase<HTTPMethod>; | ||
type RouterUse = (path: string, handler: EventHandler, method?: RouterMethod | RouterMethod[]) => Router; | ||
type AddRouteShortcuts = Record<RouterMethod, RouterUse>; | ||
interface Router extends AddRouteShortcuts { | ||
add: RouterUse; | ||
use: RouterUse; | ||
handler: EventHandler; | ||
} | ||
interface CreateRouterOptions { | ||
/** @deprecated Please use `preemptive` instead. **/ | ||
preemtive?: boolean; | ||
preemptive?: boolean; | ||
} | ||
declare function createRouter(opts?: CreateRouterOptions): Router; | ||
/** @experimental */ | ||
type WebHandler = (request: Request, context?: Record<string, unknown>) => Promise<Response>; | ||
/** @experimental */ | ||
declare function toWebHandler(app: App): WebHandler; | ||
/** @experimental */ | ||
declare function fromWebHandler(handler: WebHandler): EventHandler<EventHandlerRequest, Promise<Response>>; | ||
@@ -586,3 +612,5 @@ interface PlainRequest { | ||
declare function toPlainHandler(app: App): PlainHandler; | ||
/** @experimental */ | ||
declare function fromPlainHandler(handler: PlainHandler): EventHandler<EventHandlerRequest, Promise<unknown>>; | ||
export { AddRouteShortcuts, App, AppOptions, AppUse, CacheConditions, CreateRouterOptions, Duplex, DynamicEventHandler, Encoding, EventHandler, EventHandlerObject, EventHandlerRequest, EventHandlerResponse, H3CorsOptions, H3Error, H3Event, H3EventContext, H3Headers, H3Response, HTTPMethod, InferEventInput, InputLayer, InputStack, Layer, LazyEventHandler, MIMES, Matcher, MultiPartData, NodeEventContext, NodeListener, NodeMiddleware, NodePromisifiedHandler, PlainHandler, PlainRequest, PlainResponse, ProxyOptions, RequestHeaders, Router, RouterMethod, RouterUse, ServeStaticOptions, Session, SessionConfig, SessionData, Stack, StaticAssetMeta, ValidateFunction, ValidateResult, WebHandler, appendCorsHeaders, appendCorsPreflightHeaders, appendHeader, appendHeaders, appendResponseHeader, appendResponseHeaders, assertMethod, callNodeListener, clearResponseHeaders, clearSession, createApp, createAppEventHandler, createError, createEvent, createRouter, defaultContentType, defineEventHandler, defineLazyEventHandler, defineNodeListener, defineNodeMiddleware, deleteCookie, dynamicEventHandler, eventHandler, fetchWithEvent, fromNodeMiddleware, getCookie, getHeader, getHeaders, getMethod, getProxyRequestHeaders, getQuery, getRequestHeader, getRequestHeaders, getRequestHost, getRequestPath, getRequestProtocol, getRequestURL, getResponseHeader, getResponseHeaders, getResponseStatus, getResponseStatusText, getRouterParam, getRouterParams, getSession, getValidatedQuery, handleCacheHeaders, handleCors, isCorsOriginAllowed, isError, isEvent, isEventHandler, isMethod, isPreflightRequest, isStream, isWebResponse, lazyEventHandler, parseCookies, promisifyNodeListener, proxyRequest, readBody, readFormData, readMultipartFormData, readRawBody, readValidatedBody, removeResponseHeader, sanitizeStatusCode, sanitizeStatusMessage, sealSession, send, sendError, sendNoContent, sendProxy, sendRedirect, sendStream, sendWebResponse, serveStatic, setCookie, setHeader, setHeaders, setResponseHeader, setResponseHeaders, setResponseStatus, splitCookiesString, toEventHandler, toNodeListener, toPlainHandler, toWebHandler, unsealSession, updateSession, use, useBase, useSession, writeEarlyHints }; | ||
export { AddRouteShortcuts, App, AppOptions, AppUse, CacheConditions, CreateRouterOptions, Duplex, DynamicEventHandler, Encoding, EventHandler, EventHandlerObject, EventHandlerRequest, EventHandlerResponse, H3CorsOptions, H3Error, H3Event, H3EventContext, H3Headers, H3Response, HTTPMethod, InferEventInput, InputLayer, InputStack, Layer, LazyEventHandler, MIMES, Matcher, MultiPartData, NodeEventContext, NodeListener, NodeMiddleware, NodePromisifiedHandler, PlainHandler, PlainRequest, PlainResponse, ProxyOptions, RequestHeaders, RouteNode, Router, RouterMethod, RouterUse, ServeStaticOptions, Session, SessionConfig, SessionData, Stack, StaticAssetMeta, ValidateFunction, ValidateResult, WebEventContext, WebHandler, _RequestMiddleware, _ResponseMiddleware, appendCorsHeaders, appendCorsPreflightHeaders, appendHeader, appendHeaders, appendResponseHeader, appendResponseHeaders, assertMethod, callNodeListener, clearResponseHeaders, clearSession, createApp, createAppEventHandler, createError, createEvent, createRouter, defaultContentType, defineEventHandler, defineLazyEventHandler, defineNodeListener, defineNodeMiddleware, defineRequestMiddleware, defineResponseMiddleware, deleteCookie, dynamicEventHandler, eventHandler, fetchWithEvent, fromNodeMiddleware, fromPlainHandler, fromWebHandler, getCookie, getHeader, getHeaders, getMethod, getProxyRequestHeaders, getQuery, getRequestHeader, getRequestHeaders, getRequestHost, getRequestIP, getRequestPath, getRequestProtocol, getRequestURL, getRequestWebStream, getResponseHeader, getResponseHeaders, getResponseStatus, getResponseStatusText, getRouterParam, getRouterParams, getSession, getValidatedQuery, handleCacheHeaders, handleCors, isCorsOriginAllowed, isError, isEvent, isEventHandler, isMethod, isPreflightRequest, isStream, isWebResponse, lazyEventHandler, parseCookies, promisifyNodeListener, proxyRequest, readBody, readFormData, readMultipartFormData, readRawBody, readValidatedBody, removeResponseHeader, sanitizeStatusCode, sanitizeStatusMessage, sealSession, send, sendError, sendNoContent, sendProxy, sendRedirect, sendStream, sendWebResponse, serveStatic, setCookie, setHeader, setHeaders, setResponseHeader, setResponseHeaders, setResponseStatus, splitCookiesString, toEventHandler, toNodeListener, toPlainHandler, toWebHandler, toWebRequest, unsealSession, updateSession, use, useBase, useSession, writeEarlyHints }; |
{ | ||
"name": "h3", | ||
"version": "1.8.0-rc.3", | ||
"description": "Tiny JavaScript Server", | ||
"version": "1.8.0", | ||
"description": "Minimal H(TTP) framework built for high performance and portability.", | ||
"repository": "unjs/h3", | ||
@@ -22,14 +22,2 @@ "license": "MIT", | ||
], | ||
"scripts": { | ||
"build": "unbuild", | ||
"dev": "vitest", | ||
"lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src test playground", | ||
"lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src test playground -w", | ||
"play": "listhen -w ./playground/app.ts", | ||
"profile": "0x -o -D .profile -P 'autocannon -c 100 -p 10 -d 40 http://localhost:$PORT' ./playground/server.cjs", | ||
"release": "pnpm test && pnpm build && changelogen --release && pnpm publish && git push --follow-tags", | ||
"release-rc": "pnpm test && pnpm build && changelogen --release --prerelease rc --push --publish --publishTag rc", | ||
"test": "pnpm lint && vitest --run typecheck && vitest --run --coverage", | ||
"test:types": "vitest typecheck" | ||
}, | ||
"dependencies": { | ||
@@ -43,3 +31,3 @@ "cookie-es": "^1.0.0", | ||
"uncrypto": "^0.1.3", | ||
"unenv": "^1.6.1" | ||
"unenv": "^1.7.1" | ||
}, | ||
@@ -49,9 +37,9 @@ "devDependencies": { | ||
"@types/express": "^4.17.17", | ||
"@types/node": "^20.4.6", | ||
"@types/node": "^20.5.0", | ||
"@types/supertest": "^2.0.12", | ||
"@vitest/coverage-v8": "^0.34.1", | ||
"autocannon": "^7.11.0", | ||
"autocannon": "^7.12.0", | ||
"changelogen": "^0.5.4", | ||
"connect": "^3.7.0", | ||
"eslint": "^8.46.0", | ||
"eslint": "^8.47.0", | ||
"eslint-config-unjs": "^0.2.1", | ||
@@ -61,5 +49,5 @@ "express": "^4.18.2", | ||
"jiti": "^1.19.1", | ||
"listhen": "^1.2.2", | ||
"listhen": "^1.3.0", | ||
"node-fetch-native": "^1.2.0", | ||
"prettier": "^3.0.0", | ||
"prettier": "^3.0.1", | ||
"react": "^18.2.0", | ||
@@ -71,5 +59,17 @@ "react-dom": "^18.2.0", | ||
"vitest": "^0.34.1", | ||
"zod": "^3.21.4" | ||
"zod": "^3.22.0" | ||
}, | ||
"packageManager": "pnpm@8.6.9" | ||
"packageManager": "pnpm@8.6.12", | ||
"scripts": { | ||
"build": "unbuild", | ||
"dev": "vitest", | ||
"lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src test playground", | ||
"lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src test playground -w", | ||
"play": "listhen -w ./playground/app.ts", | ||
"profile": "0x -o -D .profile -P 'autocannon -c 100 -p 10 -d 40 http://localhost:$PORT' ./playground/server.cjs", | ||
"release": "pnpm test && pnpm build && changelogen --release && pnpm publish && git push --follow-tags", | ||
"release-rc": "pnpm test && pnpm build && changelogen --release --prerelease rc --push --publish --publishTag rc", | ||
"test": "pnpm lint && vitest --run typecheck && vitest --run --coverage", | ||
"test:types": "vitest typecheck" | ||
} | ||
} |
@@ -89,3 +89,3 @@ # H3 | ||
"/", | ||
eventHandler(() => "Hello world!") | ||
eventHandler(() => "Hello world!"), | ||
); | ||
@@ -105,3 +105,3 @@ | ||
"/", | ||
eventHandler(() => "Hello world!") | ||
eventHandler(() => "Hello world!"), | ||
); | ||
@@ -126,7 +126,7 @@ | ||
"/", | ||
eventHandler(() => "Hello World!") | ||
eventHandler(() => "Hello World!"), | ||
) | ||
.get( | ||
"/hello/:name", | ||
eventHandler((event) => `Hello ${event.context.params.name}!`) | ||
eventHandler((event) => `Hello ${event.context.params.name}!`), | ||
); | ||
@@ -149,3 +149,3 @@ | ||
"/api", | ||
eventHandler((event) => ({ url: event.node.req.url })) | ||
eventHandler((event) => ({ url: event.node.req.url })), | ||
); | ||
@@ -157,3 +157,3 @@ | ||
eventHandler(() => "Is odd!"), | ||
{ match: (url) => url.substr(1) % 2 } | ||
{ match: (url) => url.substr(1) % 2 }, | ||
); | ||
@@ -168,7 +168,7 @@ | ||
"/1", | ||
eventHandler(() => "<h1>Hello world!</h1>") | ||
eventHandler(() => "<h1>Hello world!</h1>"), | ||
) | ||
.use( | ||
"/2", | ||
eventHandler(() => "<h1>Goodbye!</h1>") | ||
eventHandler(() => "<h1>Goodbye!</h1>"), | ||
); | ||
@@ -190,4 +190,4 @@ | ||
}, | ||
}) | ||
) | ||
}), | ||
), | ||
); | ||
@@ -200,3 +200,3 @@ | ||
next(); | ||
}) | ||
}), | ||
); | ||
@@ -235,2 +235,3 @@ | ||
- `getRequestPath(event)` | ||
- `getRequestIP(event, { xForwardedFor: boolean })` | ||
@@ -323,3 +324,3 @@ #### Response | ||
- `useValidateParams(event, schema)` | ||
## License | ||
@@ -326,0 +327,0 @@ |
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
226530
7
6933
1
334
Updatedunenv@^1.7.1