routup 0.14.2 → 1.0.0-alpha.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/README.md +9 -3
- package/dist/config/index.d.ts +2 -0
- package/dist/config/module.d.ts +8 -0
- package/dist/config/type.d.ts +34 -0
- package/dist/constants.d.ts +39 -0
- package/dist/handler/index.d.ts +0 -1
- package/dist/handler/utils.d.ts +1 -2
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/request/body.d.ts +5 -0
- package/dist/helpers/request/cache.d.ts +2 -0
- package/dist/helpers/request/cookie.d.ts +8 -0
- package/dist/helpers/request/env.d.ts +6 -0
- package/dist/helpers/request/header-accept-charset.d.ts +3 -0
- package/dist/helpers/request/header-accept-encoding.d.ts +4 -0
- package/dist/helpers/request/header-accept-language.d.ts +3 -0
- package/dist/helpers/request/header-accept.d.ts +3 -0
- package/dist/helpers/request/header-content-type.d.ts +2 -0
- package/dist/helpers/request/header.d.ts +5 -0
- package/dist/helpers/request/hostname.d.ts +7 -0
- package/dist/helpers/request/index.d.ts +18 -0
- package/dist/helpers/request/ip.d.ts +7 -0
- package/dist/helpers/request/mount-path.d.ts +3 -0
- package/dist/helpers/request/negotiator.d.ts +3 -0
- package/dist/helpers/request/params.d.ts +5 -0
- package/dist/helpers/request/path.d.ts +2 -0
- package/dist/helpers/request/protocol.d.ts +8 -0
- package/dist/helpers/request/query.d.ts +8 -0
- package/dist/helpers/response/cache.d.ts +7 -0
- package/dist/helpers/response/header-attachment.d.ts +2 -0
- package/dist/helpers/response/header-content-type.d.ts +2 -0
- package/dist/helpers/response/header.d.ts +5 -0
- package/dist/helpers/response/index.d.ts +12 -0
- package/dist/helpers/response/send-accepted.d.ts +2 -0
- package/dist/helpers/response/send-created.d.ts +2 -0
- package/dist/helpers/response/send-file.d.ts +9 -0
- package/dist/helpers/response/send-format.d.ts +6 -0
- package/dist/helpers/response/send-redirect.d.ts +2 -0
- package/dist/helpers/response/send-stream.d.ts +4 -0
- package/dist/helpers/response/send.d.ts +2 -0
- package/dist/helpers/response/utils.d.ts +3 -0
- package/dist/helpers/type.d.ts +3 -0
- package/dist/index.cjs +1085 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.mjs +991 -4
- package/dist/index.mjs.map +1 -1
- package/dist/layer/index.d.ts +0 -1
- package/dist/layer/module.d.ts +1 -3
- package/dist/layer/type.d.ts +0 -1
- package/dist/layer/utils.d.ts +0 -1
- package/dist/path/index.d.ts +0 -1
- package/dist/path/matcher.d.ts +0 -1
- package/dist/path/type.d.ts +0 -1
- package/dist/route/index.d.ts +0 -1
- package/dist/route/module.d.ts +2 -4
- package/dist/route/type.d.ts +0 -1
- package/dist/route/utils.d.ts +0 -1
- package/dist/router/index.d.ts +0 -1
- package/dist/router/module.d.ts +1 -3
- package/dist/router/type.d.ts +0 -1
- package/dist/type.d.ts +9 -1
- package/dist/utils/etag/index.d.ts +2 -0
- package/dist/utils/etag/module.d.ts +12 -0
- package/dist/utils/etag/type.d.ts +16 -0
- package/dist/utils/etag/utils.d.ts +2 -0
- package/dist/utils/index.d.ts +5 -1
- package/dist/utils/is-instance.d.ts +0 -1
- package/dist/utils/mime.d.ts +2 -0
- package/dist/utils/object.d.ts +1 -0
- package/dist/utils/path.d.ts +0 -1
- package/dist/utils/promise.d.ts +0 -1
- package/dist/utils/request.d.ts +1 -2
- package/dist/utils/trust-proxy/index.d.ts +2 -0
- package/dist/utils/trust-proxy/module.d.ts +2 -0
- package/dist/utils/trust-proxy/type.d.ts +2 -0
- package/dist/utils/url.d.ts +7 -0
- package/package.json +30 -13
- package/dist/handler/index.d.ts.map +0 -1
- package/dist/handler/utils.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/layer/index.d.ts.map +0 -1
- package/dist/layer/module.d.ts.map +0 -1
- package/dist/layer/type.d.ts.map +0 -1
- package/dist/layer/utils.d.ts.map +0 -1
- package/dist/path/index.d.ts.map +0 -1
- package/dist/path/matcher.d.ts.map +0 -1
- package/dist/path/type.d.ts.map +0 -1
- package/dist/route/index.d.ts.map +0 -1
- package/dist/route/module.d.ts.map +0 -1
- package/dist/route/type.d.ts.map +0 -1
- package/dist/route/utils.d.ts.map +0 -1
- package/dist/router/index.d.ts.map +0 -1
- package/dist/router/module.d.ts.map +0 -1
- package/dist/router/type.d.ts.map +0 -1
- package/dist/type.d.ts.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/is-instance.d.ts.map +0 -1
- package/dist/utils/path.d.ts.map +0 -1
- package/dist/utils/promise.d.ts.map +0 -1
- package/dist/utils/request.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](https://snyk.io/test/github/Tada5hi/routup)
|
|
7
7
|
[](https://conventionalcommits.org)
|
|
8
8
|
|
|
9
|
-
**Routup** is a lightweight and extendable http interface based routing framework.
|
|
9
|
+
**Routup** is a lightweight, minimalistic and extendable http interface based routing framework.
|
|
10
10
|
It uses node's vanilla request and response interfaces, which are injected into route handlers aka middlewares as function argument.
|
|
11
11
|
|
|
12
12
|
Helpers provide additional functionalities to transform and interact with the request and manipulate the response upstream.
|
|
@@ -18,6 +18,7 @@ Helpers provide additional functionalities to transform and interact with the re
|
|
|
18
18
|
- [Documentation](#documentation)
|
|
19
19
|
- [Usage](#usage)
|
|
20
20
|
- [Plugins](#plugins)
|
|
21
|
+
- [Contributing](#contributing)
|
|
21
22
|
- [License](#license)
|
|
22
23
|
|
|
23
24
|
## Installation
|
|
@@ -29,11 +30,11 @@ npm install routup --save
|
|
|
29
30
|
## Features
|
|
30
31
|
|
|
31
32
|
- 🚀 high performance routing
|
|
32
|
-
- 🧰 response & request helpers
|
|
33
|
+
- 🧰 response & request composables/helpers
|
|
33
34
|
- 💼 extendable & compact
|
|
34
35
|
- 🛫 named route parameters
|
|
35
36
|
- 📁 nestable routers
|
|
36
|
-
-
|
|
37
|
+
- 🤝️ define one or many (error-) middlewares
|
|
37
38
|
- ✨ promise support for route- & middleware-handlers
|
|
38
39
|
- 👕 TypeScript fully supported
|
|
39
40
|
- 🤏 Minimalistic to fit into any solution with minimum overhead
|
|
@@ -73,6 +74,11 @@ typically http framework functions, which are not integrated in the main package
|
|
|
73
74
|
| [rate-limit-redis](https://www.npmjs.com/package/@routup/rate-limit-redis) | Redis adapter for the rate-limit plugin. |
|
|
74
75
|
| [static](https://www.npmjs.com/package/@routup/static) | Serve static files from a directory. |
|
|
75
76
|
| [swagger](https://www.npmjs.com/package/@routup/swagger) | Serve generated docs from URL or based on a JSON file. |
|
|
77
|
+
## Contributing
|
|
78
|
+
|
|
79
|
+
Before starting to work on a pull request, it is important to review the guidelines for
|
|
80
|
+
[contributing](./CONTRIBUTING.md) and the [code of conduct](./CODE_OF_CONDUCT.md).
|
|
81
|
+
These guidelines will help to ensure that contributions are made effectively and are accepted.
|
|
76
82
|
|
|
77
83
|
## License
|
|
78
84
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FlattenObject } from 'continu';
|
|
2
|
+
import { Continu } from 'continu';
|
|
3
|
+
import type { Options, OptionsInput } from './type';
|
|
4
|
+
export declare function buildConfig(): Continu<Options, OptionsInput>;
|
|
5
|
+
export declare function useConfig(): Continu<Options, OptionsInput>;
|
|
6
|
+
export declare function setConfig(config: Continu<Options, OptionsInput>): void;
|
|
7
|
+
export declare function setConfigOption<K extends keyof FlattenObject<OptionsInput>>(key: K, value: FlattenObject<OptionsInput>[K]): Options;
|
|
8
|
+
export declare function getConfigOption(key: keyof FlattenObject<OptionsInput>): string | number | import("../utils").EtagFn | import("../utils").TrustProxyFn;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { EtagFn, EtagInput } from '../utils/etag/type';
|
|
2
|
+
import type { TrustProxyFn, TrustProxyInput } from '../utils/trust-proxy';
|
|
3
|
+
export type Options = {
|
|
4
|
+
/**
|
|
5
|
+
* default: production
|
|
6
|
+
*/
|
|
7
|
+
env: string;
|
|
8
|
+
/**
|
|
9
|
+
* default: () => true
|
|
10
|
+
*/
|
|
11
|
+
etag: EtagFn;
|
|
12
|
+
/**
|
|
13
|
+
* default: 2
|
|
14
|
+
*/
|
|
15
|
+
subdomainOffset: number;
|
|
16
|
+
/**
|
|
17
|
+
* default: () => false
|
|
18
|
+
*/
|
|
19
|
+
trustProxy: TrustProxyFn;
|
|
20
|
+
/**
|
|
21
|
+
* default: 0
|
|
22
|
+
*/
|
|
23
|
+
proxyIpMax: number;
|
|
24
|
+
};
|
|
25
|
+
export type OptionsInput = {
|
|
26
|
+
/**
|
|
27
|
+
* default: true
|
|
28
|
+
*/
|
|
29
|
+
etag?: EtagInput;
|
|
30
|
+
/**
|
|
31
|
+
* default: false
|
|
32
|
+
*/
|
|
33
|
+
trustProxy?: TrustProxyInput;
|
|
34
|
+
} & Partial<Omit<Options, 'etag' | 'trustProxy'>>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare enum Method {
|
|
2
|
+
GET = "get",
|
|
3
|
+
POST = "post",
|
|
4
|
+
PUT = "put",
|
|
5
|
+
PATCH = "patch",
|
|
6
|
+
DELETE = "delete",
|
|
7
|
+
OPTIONS = "options",
|
|
8
|
+
HEAD = "head"
|
|
9
|
+
}
|
|
10
|
+
export declare enum HeaderName {
|
|
11
|
+
ACCEPT = "accept",
|
|
12
|
+
ACCEPT_CHARSET = "accept-charset",
|
|
13
|
+
ACCEPT_ENCODING = "accept-encoding",
|
|
14
|
+
ACCEPT_LANGUAGE = "accept-language",
|
|
15
|
+
ACCEPT_RANGES = "accept-ranges",
|
|
16
|
+
ALLOW = "allow",
|
|
17
|
+
CACHE_CONTROL = "cache-control",
|
|
18
|
+
CONTENT_DISPOSITION = "content-disposition",
|
|
19
|
+
CONTENT_ENCODING = "content-encoding",
|
|
20
|
+
CONTENT_LENGTH = "content-length",
|
|
21
|
+
CONTENT_RANGE = "content-range",
|
|
22
|
+
CONTENT_TYPE = "content-type",
|
|
23
|
+
COOKIE = "cookie",
|
|
24
|
+
ETag = "etag",
|
|
25
|
+
HOST = "host",
|
|
26
|
+
IF_NONE_MATCH = "if-none-match",
|
|
27
|
+
LAST_MODIFIED = "last-modified",
|
|
28
|
+
LOCATION = "location",
|
|
29
|
+
RANGE = "range",
|
|
30
|
+
RATE_LIMIT_LIMIT = "ratelimit-limit",
|
|
31
|
+
RATE_LIMIT_REMAINING = "ratelimit-remaining",
|
|
32
|
+
RATE_LIMIT_RESET = "ratelimit-reset",
|
|
33
|
+
RETRY_AFTER = "retry-after",
|
|
34
|
+
SET_COOKIE = "set-cookie",
|
|
35
|
+
TRANSFER_ENCODING = "transfer-encoding",
|
|
36
|
+
X_FORWARDED_HOST = "x-forwarded-host",
|
|
37
|
+
X_FORWARDED_FOR = "x-forwarded-for",
|
|
38
|
+
X_FORWARDED_PROTO = "x-forwarded-proto"
|
|
39
|
+
}
|
package/dist/handler/index.d.ts
CHANGED
package/dist/handler/utils.d.ts
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Request } from '../../type';
|
|
2
|
+
export declare function useRequestBody(req: Request): Record<string, any>;
|
|
3
|
+
export declare function useRequestBody(req: Request, key: string): any | undefined;
|
|
4
|
+
export declare function setRequestBody(req: Request, key: string, value: unknown): void;
|
|
5
|
+
export declare function setRequestBody(req: Request, record: Record<string, any>, append?: boolean): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { IncomingMessage } from 'node:http';
|
|
3
|
+
import type { RequestFn } from '../type';
|
|
4
|
+
export declare function setRequestCookieFn(fn: RequestFn): void;
|
|
5
|
+
export declare function useRequestCookies(req: IncomingMessage): Record<string, string>;
|
|
6
|
+
export declare function hasRequestCookies(req: IncomingMessage): boolean;
|
|
7
|
+
export declare function useRequestCookie(req: IncomingMessage, name: string): string | undefined;
|
|
8
|
+
export declare function setRequestCookies(req: IncomingMessage, record: Record<string, any>, mergeIt?: boolean): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Request } from '../../type';
|
|
2
|
+
export declare function setRequestEnv(req: Request, key: string, value: unknown): void;
|
|
3
|
+
export declare function setRequestEnv(req: Request, record: Record<string, any>, append?: boolean): void;
|
|
4
|
+
export declare function useRequestEnv(req: Request): Record<string, any>;
|
|
5
|
+
export declare function useRequestEnv(req: Request, key: string): unknown | undefined;
|
|
6
|
+
export declare function unsetRequestEnv(req: Request, key: string): void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { IncomingMessage } from 'node:http';
|
|
3
|
+
export declare function getRequestAcceptableEncodings(req: IncomingMessage): string[];
|
|
4
|
+
export declare function getRequestAcceptableEncoding(req: IncomingMessage, input: string | string[]): string | undefined;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { IncomingHttpHeaders } from 'node:http';
|
|
3
|
+
import type { Request } from '../../type';
|
|
4
|
+
export declare function getRequestHeader<K extends keyof IncomingHttpHeaders>(req: Request, name: K): IncomingHttpHeaders[K];
|
|
5
|
+
export declare function setRequestHeader<K extends keyof IncomingHttpHeaders>(req: Request, name: K, value: IncomingHttpHeaders[K]): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Request } from '../../type';
|
|
2
|
+
import type { TrustProxyInput } from '../../utils';
|
|
3
|
+
type RequestHostNameOptions = {
|
|
4
|
+
trustProxy?: TrustProxyInput;
|
|
5
|
+
};
|
|
6
|
+
export declare function getRequestHostName(req: Request, options?: RequestHostNameOptions): string | undefined;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './body';
|
|
2
|
+
export * from './cache';
|
|
3
|
+
export * from './cookie';
|
|
4
|
+
export * from './env';
|
|
5
|
+
export * from './header';
|
|
6
|
+
export * from './header-accept';
|
|
7
|
+
export * from './header-accept-charset';
|
|
8
|
+
export * from './header-accept-encoding';
|
|
9
|
+
export * from './header-accept-language';
|
|
10
|
+
export * from './header-content-type';
|
|
11
|
+
export * from './hostname';
|
|
12
|
+
export * from './ip';
|
|
13
|
+
export * from './mount-path';
|
|
14
|
+
export * from './negotiator';
|
|
15
|
+
export * from './params';
|
|
16
|
+
export * from './path';
|
|
17
|
+
export * from './protocol';
|
|
18
|
+
export * from './query';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Request } from '../../type';
|
|
2
|
+
export declare function useRequestParams(req: Request): Record<string, any>;
|
|
3
|
+
export declare function useRequestParam(req: Request, key: string): any;
|
|
4
|
+
export declare function setRequestParams(req: Request, data: Record<string, any>): void;
|
|
5
|
+
export declare function setRequestParam(req: Request, key: string, value: any): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Request } from '../../type';
|
|
2
|
+
import type { TrustProxyInput } from '../../utils';
|
|
3
|
+
type RequestProtocolOptions = {
|
|
4
|
+
trustProxy?: TrustProxyInput;
|
|
5
|
+
default?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function getRequestProtocol(req: Request, options?: RequestProtocolOptions): string;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Request } from '../../type';
|
|
2
|
+
import type { RequestFn } from '../type';
|
|
3
|
+
export declare function setRequestQueryFn(fn: RequestFn): void;
|
|
4
|
+
export declare function useRequestQuery(req: Request): Record<string, any>;
|
|
5
|
+
export declare function useRequestQuery(req: Request, key: string): any;
|
|
6
|
+
export declare function hasRequestQuery(req: Request): boolean;
|
|
7
|
+
export declare function setRequestQuery(req: Request, key: string, value: unknown): void;
|
|
8
|
+
export declare function setRequestQuery(req: Request, record: Record<string, any>, append?: boolean): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Response } from '../../type';
|
|
2
|
+
export type ResponseCacheHeadersOptions = {
|
|
3
|
+
maxAge?: number;
|
|
4
|
+
modifiedTime?: string | Date;
|
|
5
|
+
cacheControls?: string[];
|
|
6
|
+
};
|
|
7
|
+
export declare function setResponseCacheHeaders(res: Response, options?: ResponseCacheHeadersOptions): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { OutgoingHttpHeader } from 'node:http';
|
|
3
|
+
import type { Response } from '../../type';
|
|
4
|
+
export declare function appendResponseHeader(res: Response, name: string, value: OutgoingHttpHeader): void;
|
|
5
|
+
export declare function appendResponseHeaderDirective(res: Response, name: string, value: OutgoingHttpHeader): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './cache';
|
|
2
|
+
export * from './header';
|
|
3
|
+
export * from './header-attachment';
|
|
4
|
+
export * from './header-content-type';
|
|
5
|
+
export * from './send';
|
|
6
|
+
export * from './send-accepted';
|
|
7
|
+
export * from './send-created';
|
|
8
|
+
export * from './send-file';
|
|
9
|
+
export * from './send-format';
|
|
10
|
+
export * from './send-redirect';
|
|
11
|
+
export * from './send-stream';
|
|
12
|
+
export * from './utils';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Stats } from 'node:fs';
|
|
3
|
+
import type { Response } from '../../type';
|
|
4
|
+
export type SendFileOptions = {
|
|
5
|
+
stats?: Stats;
|
|
6
|
+
filePath: string;
|
|
7
|
+
attachment?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare function sendFile(res: Response, filePath: string | SendFileOptions, fn?: CallableFunction): void;
|