Comparing version 1.8.0-rc.1 to 1.8.0-rc.2
@@ -1,2 +0,1 @@ | ||
import * as http from 'http'; | ||
import { QueryObject } from 'ufo'; | ||
@@ -19,37 +18,2 @@ import { IncomingMessage, ServerResponse, OutgoingMessage } from 'node:http'; | ||
declare class H3Headers implements Headers { | ||
_headers: Record<string, string>; | ||
constructor(init?: HeadersInit); | ||
[Symbol.iterator](): IterableIterator<[string, string]>; | ||
entries(): IterableIterator<[string, string]>; | ||
keys(): IterableIterator<string>; | ||
values(): IterableIterator<string>; | ||
append(name: string, value: string): void; | ||
delete(name: string): void; | ||
get(name: string): string | null; | ||
has(name: string): boolean; | ||
set(name: string, value: string): void; | ||
forEach(callbackfn: (value: string, key: string, parent: Headers) => void): void; | ||
} | ||
declare class H3Response implements Response { | ||
readonly headers: H3Headers; | ||
readonly status: number; | ||
readonly statusText: string; | ||
readonly redirected: boolean; | ||
readonly ok: boolean; | ||
readonly url: string; | ||
_body: string | ArrayBuffer | Uint8Array; | ||
readonly body: ReadableStream<Uint8Array> | null; | ||
readonly type: ResponseType; | ||
readonly bodyUsed = false; | ||
constructor(body?: BodyInit | EventHandlerResponse | null, init?: ResponseInit); | ||
clone(): H3Response; | ||
arrayBuffer(): Promise<ArrayBuffer>; | ||
blob(): Promise<Blob>; | ||
formData(): Promise<FormData>; | ||
json<T = any>(): Promise<T>; | ||
text(): Promise<string>; | ||
} | ||
interface NodeEventContext { | ||
@@ -78,3 +42,3 @@ req: IncomingMessage & { | ||
get handled(): boolean; | ||
get method(): HTTPMethod | undefined; | ||
get method(): HTTPMethod; | ||
get headers(): Headers; | ||
@@ -90,3 +54,3 @@ /** @deprecated Please use `event.node.req` instead. **/ | ||
get request(): Request; | ||
respondWith(r: H3Response | PromiseLike<H3Response>): void; | ||
respondWith(response: Response | PromiseLike<Response>): Promise<void>; | ||
} | ||
@@ -108,2 +72,45 @@ declare function isEvent(input: any): input is H3Event; | ||
/** | ||
* @deprecated Please use native web Headers | ||
* https://developer.mozilla.org/en-US/docs/Web/API/Headers | ||
*/ | ||
declare class H3Headers implements Headers { | ||
_headers: Record<string, string>; | ||
constructor(init?: HeadersInit); | ||
[Symbol.iterator](): IterableIterator<[string, string]>; | ||
entries(): IterableIterator<[string, string]>; | ||
keys(): IterableIterator<string>; | ||
values(): IterableIterator<string>; | ||
append(name: string, value: string): void; | ||
delete(name: string): void; | ||
get(name: string): string | null; | ||
has(name: string): boolean; | ||
set(name: string, value: string): void; | ||
forEach(callbackfn: (value: string, key: string, parent: Headers) => void): void; | ||
} | ||
/** | ||
* @deprecated Please use native web Response | ||
* https://developer.mozilla.org/en-US/docs/Web/API/Response | ||
*/ | ||
declare class H3Response implements Response { | ||
readonly headers: H3Headers; | ||
readonly status: number; | ||
readonly statusText: string; | ||
readonly redirected: boolean; | ||
readonly ok: boolean; | ||
readonly url: string; | ||
_body: string | ArrayBuffer | Uint8Array; | ||
readonly body: ReadableStream<Uint8Array> | null; | ||
readonly type: ResponseType; | ||
readonly bodyUsed = false; | ||
constructor(body?: BodyInit | EventHandlerResponse | null, init?: ResponseInit); | ||
clone(): H3Response; | ||
arrayBuffer(): Promise<ArrayBuffer>; | ||
blob(): Promise<Blob>; | ||
formData(): Promise<FormData>; | ||
json<T = any>(): Promise<T>; | ||
text(): Promise<string>; | ||
} | ||
type SessionDataT = Record<string, any>; | ||
@@ -169,35 +176,2 @@ type SessionData<T extends SessionDataT = SessionDataT> = T; | ||
interface Layer { | ||
route: string; | ||
match?: Matcher; | ||
handler: EventHandler; | ||
} | ||
type Stack = Layer[]; | ||
interface InputLayer { | ||
route?: string; | ||
match?: Matcher; | ||
handler: EventHandler; | ||
lazy?: boolean; | ||
} | ||
type InputStack = InputLayer[]; | ||
type Matcher = (url: string, event?: H3Event) => boolean; | ||
interface AppUse { | ||
(route: string | string[], handler: EventHandler | EventHandler[], options?: Partial<InputLayer>): App; | ||
(handler: EventHandler | EventHandler[], options?: Partial<InputLayer>): App; | ||
(options: InputLayer): App; | ||
} | ||
interface AppOptions { | ||
debug?: boolean; | ||
onError?: (error: Error, event: H3Event) => any; | ||
} | ||
interface App { | ||
stack: Stack; | ||
handler: EventHandler; | ||
options: AppOptions; | ||
use: AppUse; | ||
} | ||
declare function createApp(options?: AppOptions): App; | ||
declare function use(app: App, arg1: string | EventHandler | InputLayer | InputLayer[], arg2?: Partial<InputLayer> | EventHandler | EventHandler[], arg3?: Partial<InputLayer>): App; | ||
declare function createAppEventHandler(stack: Stack, options: AppOptions): EventHandler<EventHandlerRequest, Promise<void | http.ServerResponse<http.IncomingMessage>>>; | ||
/** | ||
@@ -222,2 +196,6 @@ * H3 Runtime Error | ||
data?: any; | ||
cause?: unknown; | ||
constructor(message: string, opts?: { | ||
cause?: unknown; | ||
}); | ||
toJSON(): Pick<H3Error, "data" | "statusCode" | "statusMessage" | "message">; | ||
@@ -254,2 +232,42 @@ } | ||
interface Layer { | ||
route: string; | ||
match?: Matcher; | ||
handler: EventHandler; | ||
} | ||
type Stack = Layer[]; | ||
interface InputLayer { | ||
route?: string; | ||
match?: Matcher; | ||
handler: EventHandler; | ||
lazy?: boolean; | ||
} | ||
type InputStack = InputLayer[]; | ||
type Matcher = (url: string, event?: H3Event) => boolean; | ||
interface AppUse { | ||
(route: string | string[], handler: EventHandler | EventHandler[], options?: Partial<InputLayer>): App; | ||
(handler: EventHandler | EventHandler[], options?: Partial<InputLayer>): App; | ||
(options: InputLayer): App; | ||
} | ||
interface AppOptions { | ||
debug?: boolean; | ||
onError?: (error: H3Error, event: H3Event) => any; | ||
onRequest?: (event: H3Event) => void | Promise<void>; | ||
onBeforeResponse?: (event: H3Event, response: { | ||
body?: unknown; | ||
}) => void | Promise<void>; | ||
onAfterResponse?: (event: H3Event, response?: { | ||
body?: unknown; | ||
}) => void | Promise<void>; | ||
} | ||
interface App { | ||
stack: Stack; | ||
handler: EventHandler; | ||
options: AppOptions; | ||
use: AppUse; | ||
} | ||
declare function createApp(options?: AppOptions): App; | ||
declare function use(app: App, arg1: string | EventHandler | InputLayer | InputLayer[], arg2?: Partial<InputLayer> | EventHandler | EventHandler[], arg3?: Partial<InputLayer>): App; | ||
declare function createAppEventHandler(stack: Stack, options: AppOptions): EventHandler<EventHandlerRequest, Promise<void>>; | ||
declare function useBase(base: string, handler: EventHandler): EventHandler; | ||
@@ -321,3 +339,48 @@ | ||
interface H3CorsOptions { | ||
origin?: "*" | "null" | (string | RegExp)[] | ((origin: string) => boolean); | ||
methods?: "*" | HTTPMethod[]; | ||
allowHeaders?: "*" | string[]; | ||
exposeHeaders?: "*" | string[]; | ||
credentials?: boolean; | ||
maxAge?: string | false; | ||
preflight?: { | ||
statusCode?: number; | ||
}; | ||
} | ||
declare function handleCors(event: H3Event, options: H3CorsOptions): boolean; | ||
declare function getQuery<T, Event extends H3Event = H3Event, _T = Exclude<InferEventInput<"query", Event, T>, undefined>>(event: Event): _T; | ||
declare function getValidatedQuery<T, Event extends H3Event = H3Event, _T = InferEventInput<"query", Event, T>>(event: Event, validate: ValidateFunction<_T>): Promise<_T>; | ||
declare function getRouterParams(event: H3Event): NonNullable<H3Event["context"]["params"]>; | ||
declare function getRouterParam(event: H3Event, name: string): string | undefined; | ||
/** | ||
* @deprecated Directly use `event.method` instead. | ||
*/ | ||
declare function getMethod(event: H3Event, defaultMethod?: HTTPMethod): HTTPMethod; | ||
declare function isMethod(event: H3Event, expected: HTTPMethod | HTTPMethod[], allowHead?: boolean): boolean; | ||
declare function assertMethod(event: H3Event, expected: HTTPMethod | HTTPMethod[], allowHead?: boolean): void; | ||
declare function getRequestHeaders(event: H3Event): RequestHeaders; | ||
declare const getHeaders: typeof getRequestHeaders; | ||
declare function getRequestHeader(event: H3Event, name: string): RequestHeaders[string]; | ||
declare const getHeader: typeof getRequestHeader; | ||
declare function getRequestHost(event: H3Event, opts?: { | ||
xForwardedHost?: boolean; | ||
}): string; | ||
declare function getRequestProtocol(event: H3Event, opts?: { | ||
xForwardedProto?: boolean; | ||
}): "https" | "http"; | ||
declare function getRequestPath(event: H3Event): string; | ||
declare function getRequestURL(event: H3Event, opts?: { | ||
xForwardedHost?: boolean; | ||
xForwardedProto?: boolean; | ||
}): URL; | ||
declare function isPreflightRequest(event: H3Event): boolean; | ||
declare function isCorsOriginAllowed(origin: ReturnType<typeof getRequestHeaders>["origin"], options: H3CorsOptions): boolean; | ||
declare function appendCorsPreflightHeaders(event: H3Event, options: H3CorsOptions): void; | ||
declare function appendCorsHeaders(event: H3Event, options: H3CorsOptions): void; | ||
/** | ||
* Parse the request to get HTTP Cookie header string and returning an object of all cookie name-value pairs. | ||
@@ -371,3 +434,3 @@ * @param event {H3Event} H3 event or req passed by h3 handler | ||
*/ | ||
declare function splitCookiesString(cookiesString: string): string[]; | ||
declare function splitCookiesString(cookiesString: string | string[]): string[]; | ||
@@ -398,25 +461,2 @@ type Duplex = "half" | "full"; | ||
declare function getQuery<T, Event extends H3Event = H3Event, _T = Exclude<InferEventInput<"query", Event, T>, undefined>>(event: Event): _T; | ||
declare function getValidatedQuery<T, Event extends H3Event = H3Event, _T = InferEventInput<"query", Event, T>>(event: Event, validate: ValidateFunction<_T>): Promise<_T>; | ||
declare function getRouterParams(event: H3Event): NonNullable<H3Event["context"]["params"]>; | ||
declare function getRouterParam(event: H3Event, name: string): string | undefined; | ||
declare function getMethod(event: H3Event, defaultMethod?: HTTPMethod): HTTPMethod; | ||
declare function isMethod(event: H3Event, expected: HTTPMethod | HTTPMethod[], allowHead?: boolean): boolean; | ||
declare function assertMethod(event: H3Event, expected: HTTPMethod | HTTPMethod[], allowHead?: boolean): void; | ||
declare function getRequestHeaders(event: H3Event): RequestHeaders; | ||
declare const getHeaders: typeof getRequestHeaders; | ||
declare function getRequestHeader(event: H3Event, name: string): RequestHeaders[string]; | ||
declare const getHeader: typeof getRequestHeader; | ||
declare function getRequestHost(event: H3Event, opts?: { | ||
xForwardedHost?: boolean; | ||
}): string; | ||
declare function getRequestProtocol(event: H3Event, opts?: { | ||
xForwardedProto?: boolean; | ||
}): "https" | "http"; | ||
declare function getRequestPath(event: H3Event): string; | ||
declare function getRequestURL(event: H3Event, opts?: { | ||
xForwardedHost?: boolean; | ||
xForwardedProto?: boolean; | ||
}): URL; | ||
declare function send(event: H3Event, data?: any, type?: string): Promise<void>; | ||
@@ -457,26 +497,45 @@ /** | ||
declare function writeEarlyHints(event: H3Event, hints: string | string[] | Record<string, string | string[]>, cb?: () => void): void; | ||
declare function sendWebResponse(event: H3Event, response: Response): http.ServerResponse<http.IncomingMessage> | Promise<void>; | ||
declare function sendWebResponse(event: H3Event, response: Response): void | Promise<void>; | ||
interface H3CorsOptions { | ||
origin?: "*" | "null" | (string | RegExp)[] | ((origin: string) => boolean); | ||
methods?: "*" | HTTPMethod[]; | ||
allowHeaders?: "*" | string[]; | ||
exposeHeaders?: "*" | string[]; | ||
credentials?: boolean; | ||
maxAge?: string | false; | ||
preflight?: { | ||
statusCode?: number; | ||
}; | ||
} | ||
declare function handleCors(event: H3Event, options: H3CorsOptions): boolean; | ||
declare function isPreflightRequest(event: H3Event): boolean; | ||
declare function isCorsOriginAllowed(origin: ReturnType<typeof getRequestHeaders>["origin"], options: H3CorsOptions): boolean; | ||
declare function appendCorsPreflightHeaders(event: H3Event, options: H3CorsOptions): void; | ||
declare function appendCorsHeaders(event: H3Event, options: H3CorsOptions): void; | ||
declare function sanitizeStatusMessage(statusMessage?: string): string; | ||
declare function sanitizeStatusCode(statusCode: string | number, defaultStatusCode?: number): number; | ||
interface StaticAssetMeta { | ||
type?: string; | ||
etag?: string; | ||
mtime?: number | string | Date; | ||
path?: string; | ||
size?: number; | ||
encoding?: string; | ||
} | ||
interface ServeStaticOptions { | ||
/** | ||
* This function should resolve asset meta | ||
*/ | ||
getMeta: (id: string) => StaticAssetMeta | undefined | Promise<StaticAssetMeta | undefined>; | ||
/** | ||
* This function should resolve asset content | ||
*/ | ||
getContents: (id: string) => unknown | Promise<unknown>; | ||
/** | ||
* Map of supported encodings (compressions) and their file extensions. | ||
* | ||
* Each extension will be appended to the asset path to find the compressed version of the asset. | ||
* | ||
* @example { gzip: ".gz", br: ".br" } | ||
*/ | ||
encodings?: Record<string, string>; | ||
/** | ||
* Default index file to serve when the path is a directory | ||
* | ||
* @default ["/index.html"] | ||
*/ | ||
indexNames?: string[]; | ||
/** | ||
* When set to true, the function will not throw 404 error when the asset meta is not found or meta validation failed | ||
*/ | ||
fallthrough?: boolean; | ||
} | ||
declare function serveStatic(event: H3Event, options: ServeStaticOptions): Promise<void | false>; | ||
type RouterMethod = Lowercase<HTTPMethod>; | ||
@@ -497,2 +556,24 @@ type RouterUse = (path: string, handler: EventHandler, method?: RouterMethod | RouterMethod[]) => Router; | ||
export { AddRouteShortcuts, App, AppOptions, AppUse, CacheConditions, CreateRouterOptions, Duplex, DynamicEventHandler, Encoding, EventHandler, EventHandlerRequest, EventHandlerResponse, H3CorsOptions, H3Error, H3Event, H3EventContext, H3Headers, H3Response, HTTPMethod, InferEventInput, InputLayer, InputStack, Layer, LazyEventHandler, MIMES, Matcher, MultiPartData, NodeEventContext, NodeListener, NodeMiddleware, NodePromisifiedHandler, ProxyOptions, RequestHeaders, Router, RouterMethod, RouterUse, Session, SessionConfig, SessionData, Stack, ValidateFunction, ValidateResult, 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, setCookie, setHeader, setHeaders, setResponseHeader, setResponseHeaders, setResponseStatus, splitCookiesString, toEventHandler, toNodeListener, unsealSession, updateSession, use, useBase, useSession, writeEarlyHints }; | ||
type WebHandler = (request: Request, context?: Record<string, unknown>) => Promise<Response>; | ||
/** @experimental */ | ||
declare function toWebHandler(app: App): WebHandler; | ||
interface PlainRequest { | ||
_eventOverrides?: Partial<H3Event>; | ||
context?: Record<string, unknown>; | ||
method: string; | ||
path: string; | ||
headers: HeadersInit; | ||
body?: null | BodyInit; | ||
} | ||
interface PlainResponse { | ||
status: number; | ||
statusText: string; | ||
headers: [string, string][]; | ||
body?: unknown; | ||
} | ||
type PlainHandler = (request: PlainRequest) => Promise<PlainResponse>; | ||
/** @experimental */ | ||
declare function toPlainHandler(app: App): PlainHandler; | ||
export { AddRouteShortcuts, App, AppOptions, AppUse, CacheConditions, CreateRouterOptions, Duplex, DynamicEventHandler, Encoding, EventHandler, 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 }; |
{ | ||
"name": "h3", | ||
"version": "1.8.0-rc.1", | ||
"version": "1.8.0-rc.2", | ||
"description": "Tiny JavaScript Server", | ||
@@ -41,3 +41,4 @@ "repository": "unjs/h3", | ||
"ufo": "^1.1.2", | ||
"uncrypto": "^0.1.3" | ||
"uncrypto": "^0.1.3", | ||
"unenv": "^1.6.1" | ||
}, | ||
@@ -44,0 +45,0 @@ "devDependencies": { |
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
155077
4549
8
+ Addedunenv@^1.6.1
+ Addedconsola@3.2.3(transitive)
+ Addedmime@3.0.0(transitive)
+ Addednode-fetch-native@1.6.4(transitive)
+ Addedpathe@1.1.2(transitive)
+ Addedunenv@1.10.0(transitive)