@tinyhttp/app
Advanced tools
Comparing version 0.1.48 to 0.2.0
@@ -1,176 +0,5 @@ | ||
/// <reference types="node" /> | ||
import { IncomingMessage, ServerResponse } from "http"; | ||
import { ParsedUrlQuery } from "querystring"; | ||
import parseRange from "range-parser"; | ||
import { Ranges, Options } from "range-parser"; | ||
import * as cookie from "@tinyhttp/cookie"; | ||
declare const json: (_req: Request, res: Response) => (body: any, ...args: any[]) => Response; | ||
declare const send: (req: Request, res: Response) => (body: any) => Response; | ||
declare const status: (_req: Request, res: Response) => (status: number) => Response; | ||
declare const setCookie: (req: Request, res: Response) => (name: string, value: string | Record<string, unknown>, options?: cookie.SerializeOptions & Partial<{ | ||
signed: boolean; | ||
}>) => Response; | ||
declare const clearCookie: (req: Request, res: Response) => (name: string, options?: cookie.SerializeOptions) => Response; | ||
declare const setHeader: (_req: Request, res: Response) => (field: string | Record<string, string | number | string[]>, val: string | any[]) => Response; | ||
declare const setLocationHeader: (req: Request, res: Response) => (url: string) => Response; | ||
declare const getResponseHeader: (_req: Request, res: Response) => (field: string) => string | number | string[]; | ||
declare const setLinksHeader: (_req: Request, res: Response) => (links: { | ||
[key: string]: string; | ||
}) => Response; | ||
declare const sendStatus: (_req: Request, res: Response) => (statusCode: number) => Response; | ||
interface Response extends ServerResponse { | ||
header(field: string | Record<string, unknown>, val: string | any[]): Response; | ||
set(field: string | Record<string, unknown>, val: string | any[]): Response; | ||
get(field: string): string | number | string[]; | ||
send(body: unknown): Response; | ||
json(body: unknown): Response; | ||
status(status: number): Response; | ||
sendStatus(statusCode: number): Response; | ||
cookie(name: string, value: string | Record<string, unknown>, options?: cookie.SerializeOptions & Partial<{ | ||
signed: boolean; | ||
}>): Response; | ||
clearCookie(name: string, options?: cookie.SerializeOptions): Response; | ||
location(url: string): Response; | ||
links(links: { | ||
[key: string]: string; | ||
}): Response; | ||
} | ||
type NextFunction = (err?: any) => void; | ||
type SyncHandler = (req: Request, res: Response, next?: NextFunction) => void; | ||
type AsyncHandler = (req: Request, res: Response, next?: NextFunction) => Promise<void>; | ||
type Handler = AsyncHandler | SyncHandler; | ||
type ErrorHandler = (err: any, req: Request, res: Response) => void; | ||
type Method = "GET" | "POST" | "PUT" | "PATCH" | "HEAD" | "OPTIONS" | "DELETE" | string; | ||
type MiddlewareType = "mw" | "route"; | ||
interface Middleware { | ||
method?: Method; | ||
handler: Handler; | ||
path?: string; | ||
type: MiddlewareType; | ||
} | ||
declare class Router { | ||
middleware: Middleware[]; | ||
get(path: string | Handler, handler?: Handler, ...handlers: Handler[]): this; | ||
post(path: string | Handler, handler?: Handler, ...handlers: Handler[]): this; | ||
put(path: string | Handler, handler?: Handler, ...handlers: Handler[]): this; | ||
patch(path: string | Handler, handler?: Handler, ...handlers: Handler[]): this; | ||
head(path: string | Handler, handler?: Handler, ...handlers: Handler[]): this; | ||
delete(path: string | Handler, handler?: Handler, ...handlers: Handler[]): this; | ||
options(path: string | Handler, handler?: Handler, ...handlers: Handler[]): this; | ||
all(path: string | Handler, handler?: Handler, ...handlers: Handler[]): this; | ||
use(path: string | Handler, handler?: Handler, ...handlers: Handler[]): this; | ||
} | ||
declare const getQueryParams: (url?: string) => ParsedUrlQuery; | ||
type URLParams = { | ||
[key: string]: string; | ||
}; | ||
declare const getURLParams: (reqUrl?: string, url?: string) => URLParams; | ||
declare const getRouteFromApp: (app: App, handler: Handler) => Middleware; | ||
declare const getProtocol: (req: Request) => Protocol; | ||
declare const getRequestHeader: (req: Request) => (header: string) => string | string[]; | ||
declare const setRequestHeader: (req: Request) => (field: string, value: string) => string; | ||
declare const getRangeFromHeader: (req: Request) => (size: number, options?: Options) => parseRange.Ranges | -1 | -2; | ||
declare const checkIfXMLHttpRequest: (req: Request) => boolean; | ||
declare const getHostname: (req: Request) => string | undefined; | ||
declare const getIP: (req: Request) => string; // export const getRequestIs = (types: string | string[], ...args: string[]) => (req: Request) => { | ||
// let arr = types | ||
// if (!Array.isArray(types)) { | ||
// arr = new Array(args.length) | ||
// for (let i = 0; i < arr.length; i++) { | ||
// arr[i] = args[i] | ||
// } | ||
// } | ||
// } | ||
/* export const getFreshOrStale = (req: Request, res: Response) => { | ||
const method = req.method | ||
const status = res.statusCode | ||
// GET or HEAD for weak freshness validation only | ||
if (method !== 'GET' && method !== 'HEAD') return false | ||
// 2xx or 304 as per rfc2616 14.26 | ||
if ((status >= 200 && status < 300) || 304 === status) { | ||
const resHeaders = { | ||
etag: res.get('ETag'), | ||
'last-modified': res.get('Last-Modified'), | ||
} | ||
return fresh(req.headers, resHeaders) | ||
} | ||
return false | ||
} */ | ||
// export const getRequestIs = (types: string | string[], ...args: string[]) => (req: Request) => { | ||
// let arr = types | ||
// if (!Array.isArray(types)) { | ||
// arr = new Array(args.length) | ||
// for (let i = 0; i < arr.length; i++) { | ||
// arr[i] = args[i] | ||
// } | ||
// } | ||
// } | ||
/* export const getFreshOrStale = (req: Request, res: Response) => { | ||
const method = req.method | ||
const status = res.statusCode | ||
// GET or HEAD for weak freshness validation only | ||
if (method !== 'GET' && method !== 'HEAD') return false | ||
// 2xx or 304 as per rfc2616 14.26 | ||
if ((status >= 200 && status < 300) || 304 === status) { | ||
const resHeaders = { | ||
etag: res.get('ETag'), | ||
'last-modified': res.get('Last-Modified'), | ||
} | ||
return fresh(req.headers, resHeaders) | ||
} | ||
return false | ||
} */ | ||
declare const getAccepts: (req: Request) => (...types: string[]) => string | false | string[]; | ||
type Connection = IncomingMessage["socket"] & { | ||
encrypted: boolean; | ||
}; | ||
type Protocol = "http" | "https" | string; | ||
interface Request extends IncomingMessage { | ||
query: ParsedUrlQuery; | ||
params: URLParams; | ||
connection: Connection; | ||
route?: Middleware | undefined; | ||
protocol: Protocol; | ||
secure: boolean; | ||
xhr: boolean; | ||
hostname: string | undefined; | ||
get: (header: string) => string | string[] | undefined; | ||
set: (field: string, value: string) => string; | ||
range: (size: number, options?: any) => -1 | -2 | Ranges | undefined; | ||
accepts: (...types: string[]) => string | false | string[]; | ||
cookies?: any; | ||
signedCookies?: any; | ||
secret?: string | string[]; | ||
/* fresh: boolean | ||
stale: boolean | ||
*/ | ||
body?: any; | ||
} | ||
declare const applyHandler: (h: Handler) => Handler; | ||
type AppSettings = Partial<{ | ||
networkExtensions: boolean; | ||
}>; | ||
declare class App extends Router { | ||
middleware: Middleware[]; | ||
locals: Record<string, string>; | ||
noMatchHandler: Handler; | ||
onError: ErrorHandler; | ||
settings: AppSettings; | ||
constructor(options?: Partial<{ | ||
noMatchHandler: Handler; | ||
onError: ErrorHandler; | ||
settings: AppSettings; | ||
}>); | ||
handler(mw: Middleware[], req: Request, res: Response): Promise<void>; | ||
listen(port?: number, cb?: () => void, host?: string, backlog?: number): import("http").Server; | ||
} | ||
declare const extendMiddleware: ({ networkExtensions }: AppSettings) => (req: Request, res: Response) => void; | ||
export { applyHandler, AppSettings, App, getQueryParams, URLParams, getURLParams, getRouteFromApp, getProtocol, getRequestHeader, setRequestHeader, getRangeFromHeader, checkIfXMLHttpRequest, getHostname, getIP, getAccepts, Connection, Protocol, Request, json, send, status, setCookie, clearCookie, setHeader, setLocationHeader, getResponseHeader, setLinksHeader, sendStatus, Response, NextFunction, SyncHandler, AsyncHandler, Handler, ErrorHandler, Middleware, Router, extendMiddleware }; | ||
export * from './app'; | ||
export * from './request'; | ||
export * from './response'; | ||
export * from './router'; | ||
export * from './extend'; |
@@ -424,2 +424,3 @@ import { STATUS_CODES, METHODS, createServer } from 'http'; | ||
}); | ||
req.hostname = getHostname(req); | ||
} | ||
@@ -435,3 +436,2 @@ req.query = getQueryParams(req.url); | ||
req.xhr = checkIfXMLHttpRequest(req); | ||
req.hostname = getHostname(req); | ||
/* | ||
@@ -438,0 +438,0 @@ Response extensions |
{ | ||
"name": "@tinyhttp/app", | ||
"version": "0.1.48", | ||
"version": "0.2.0", | ||
"description": "tinyhttp core", | ||
@@ -39,5 +39,5 @@ "type": "module", | ||
"dependencies": { | ||
"@tinyhttp/cookie": "0.0.13", | ||
"@tinyhttp/cookie-signature": "0.0.10", | ||
"@tinyhttp/etag": "0.1.26", | ||
"@tinyhttp/cookie": "0.1.0", | ||
"@tinyhttp/cookie-signature": "0.1.0", | ||
"@tinyhttp/etag": "0.2.0", | ||
"es-accepts": "^0.0.11", | ||
@@ -52,4 +52,10 @@ "es-content-type": "^0.0.4", | ||
"@types/proxy-addr": "^2.0.0", | ||
"@types/range-parser": "^1.2.3" | ||
"@types/range-parser": "^1.2.3", | ||
"rollup": "^2.21.0", | ||
"rollup-plugin-typescript2": "^0.27.1", | ||
"typescript": "^3.9.6" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c" | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
46950
16
2
5
1213
+ Added@tinyhttp/cookie@0.1.0(transitive)
+ Added@tinyhttp/cookie-signature@0.1.0(transitive)
+ Added@tinyhttp/etag@0.2.0(transitive)
- Removed@tinyhttp/cookie@0.0.13(transitive)
- Removed@tinyhttp/cookie-signature@0.0.10(transitive)
- Removed@tinyhttp/etag@0.1.26(transitive)
Updated@tinyhttp/cookie@0.1.0
Updated@tinyhttp/etag@0.2.0