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.
Files changed (100) hide show
  1. package/README.md +9 -3
  2. package/dist/config/index.d.ts +2 -0
  3. package/dist/config/module.d.ts +8 -0
  4. package/dist/config/type.d.ts +34 -0
  5. package/dist/constants.d.ts +39 -0
  6. package/dist/handler/index.d.ts +0 -1
  7. package/dist/handler/utils.d.ts +1 -2
  8. package/dist/helpers/index.d.ts +3 -0
  9. package/dist/helpers/request/body.d.ts +5 -0
  10. package/dist/helpers/request/cache.d.ts +2 -0
  11. package/dist/helpers/request/cookie.d.ts +8 -0
  12. package/dist/helpers/request/env.d.ts +6 -0
  13. package/dist/helpers/request/header-accept-charset.d.ts +3 -0
  14. package/dist/helpers/request/header-accept-encoding.d.ts +4 -0
  15. package/dist/helpers/request/header-accept-language.d.ts +3 -0
  16. package/dist/helpers/request/header-accept.d.ts +3 -0
  17. package/dist/helpers/request/header-content-type.d.ts +2 -0
  18. package/dist/helpers/request/header.d.ts +5 -0
  19. package/dist/helpers/request/hostname.d.ts +7 -0
  20. package/dist/helpers/request/index.d.ts +18 -0
  21. package/dist/helpers/request/ip.d.ts +7 -0
  22. package/dist/helpers/request/mount-path.d.ts +3 -0
  23. package/dist/helpers/request/negotiator.d.ts +3 -0
  24. package/dist/helpers/request/params.d.ts +5 -0
  25. package/dist/helpers/request/path.d.ts +2 -0
  26. package/dist/helpers/request/protocol.d.ts +8 -0
  27. package/dist/helpers/request/query.d.ts +8 -0
  28. package/dist/helpers/response/cache.d.ts +7 -0
  29. package/dist/helpers/response/header-attachment.d.ts +2 -0
  30. package/dist/helpers/response/header-content-type.d.ts +2 -0
  31. package/dist/helpers/response/header.d.ts +5 -0
  32. package/dist/helpers/response/index.d.ts +12 -0
  33. package/dist/helpers/response/send-accepted.d.ts +2 -0
  34. package/dist/helpers/response/send-created.d.ts +2 -0
  35. package/dist/helpers/response/send-file.d.ts +9 -0
  36. package/dist/helpers/response/send-format.d.ts +6 -0
  37. package/dist/helpers/response/send-redirect.d.ts +2 -0
  38. package/dist/helpers/response/send-stream.d.ts +4 -0
  39. package/dist/helpers/response/send.d.ts +2 -0
  40. package/dist/helpers/response/utils.d.ts +3 -0
  41. package/dist/helpers/type.d.ts +3 -0
  42. package/dist/index.cjs +1085 -35
  43. package/dist/index.cjs.map +1 -1
  44. package/dist/index.d.ts +3 -2
  45. package/dist/index.mjs +991 -4
  46. package/dist/index.mjs.map +1 -1
  47. package/dist/layer/index.d.ts +0 -1
  48. package/dist/layer/module.d.ts +1 -3
  49. package/dist/layer/type.d.ts +0 -1
  50. package/dist/layer/utils.d.ts +0 -1
  51. package/dist/path/index.d.ts +0 -1
  52. package/dist/path/matcher.d.ts +0 -1
  53. package/dist/path/type.d.ts +0 -1
  54. package/dist/route/index.d.ts +0 -1
  55. package/dist/route/module.d.ts +2 -4
  56. package/dist/route/type.d.ts +0 -1
  57. package/dist/route/utils.d.ts +0 -1
  58. package/dist/router/index.d.ts +0 -1
  59. package/dist/router/module.d.ts +1 -3
  60. package/dist/router/type.d.ts +0 -1
  61. package/dist/type.d.ts +9 -1
  62. package/dist/utils/etag/index.d.ts +2 -0
  63. package/dist/utils/etag/module.d.ts +12 -0
  64. package/dist/utils/etag/type.d.ts +16 -0
  65. package/dist/utils/etag/utils.d.ts +2 -0
  66. package/dist/utils/index.d.ts +5 -1
  67. package/dist/utils/is-instance.d.ts +0 -1
  68. package/dist/utils/mime.d.ts +2 -0
  69. package/dist/utils/object.d.ts +1 -0
  70. package/dist/utils/path.d.ts +0 -1
  71. package/dist/utils/promise.d.ts +0 -1
  72. package/dist/utils/request.d.ts +1 -2
  73. package/dist/utils/trust-proxy/index.d.ts +2 -0
  74. package/dist/utils/trust-proxy/module.d.ts +2 -0
  75. package/dist/utils/trust-proxy/type.d.ts +2 -0
  76. package/dist/utils/url.d.ts +7 -0
  77. package/package.json +30 -13
  78. package/dist/handler/index.d.ts.map +0 -1
  79. package/dist/handler/utils.d.ts.map +0 -1
  80. package/dist/index.d.ts.map +0 -1
  81. package/dist/layer/index.d.ts.map +0 -1
  82. package/dist/layer/module.d.ts.map +0 -1
  83. package/dist/layer/type.d.ts.map +0 -1
  84. package/dist/layer/utils.d.ts.map +0 -1
  85. package/dist/path/index.d.ts.map +0 -1
  86. package/dist/path/matcher.d.ts.map +0 -1
  87. package/dist/path/type.d.ts.map +0 -1
  88. package/dist/route/index.d.ts.map +0 -1
  89. package/dist/route/module.d.ts.map +0 -1
  90. package/dist/route/type.d.ts.map +0 -1
  91. package/dist/route/utils.d.ts.map +0 -1
  92. package/dist/router/index.d.ts.map +0 -1
  93. package/dist/router/module.d.ts.map +0 -1
  94. package/dist/router/type.d.ts.map +0 -1
  95. package/dist/type.d.ts.map +0 -1
  96. package/dist/utils/index.d.ts.map +0 -1
  97. package/dist/utils/is-instance.d.ts.map +0 -1
  98. package/dist/utils/path.d.ts.map +0 -1
  99. package/dist/utils/promise.d.ts.map +0 -1
  100. package/dist/utils/request.d.ts.map +0 -1
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![Known Vulnerabilities](https://snyk.io/test/github/Tada5hi/routup/badge.svg)](https://snyk.io/test/github/Tada5hi/routup)
7
7
  [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](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/utilities
33
+ - 🧰 response & request composables/helpers
33
34
  - 💼 extendable & compact
34
35
  - 🛫 named route parameters
35
36
  - 📁 nestable routers
36
- - 😌 define one or many (error-) middlewares
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,2 @@
1
+ export * from './module';
2
+ export * from './type';
@@ -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
+ }
@@ -1,2 +1 @@
1
1
  export * from './utils';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,2 @@
1
- import type { Next, Response } from '@routup/core';
1
+ import type { Next, Response } from '../type';
2
2
  export declare function processHandlerExecutionOutput(res: Response, next: Next, output?: unknown): void;
3
- //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,3 @@
1
+ export * from './request';
2
+ export * from './response';
3
+ export * from './type';
@@ -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,2 @@
1
+ import type { Request } from '../../type';
2
+ export declare function isRequestCacheable(req: Request, modifiedTime: string | Date): boolean;
@@ -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,3 @@
1
+ import type { Request } from '../../type';
2
+ export declare function getRequestAcceptableCharsets(req: Request): string[];
3
+ export declare function getRequestAcceptableCharset(req: Request, input: string | string[]): string | undefined;
@@ -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,3 @@
1
+ import type { Request } from '../../type';
2
+ export declare function getRequestAcceptableLanguages(req: Request): string[];
3
+ export declare function getRequestAcceptableLanguage(req: Request, input?: string | string[]): string | undefined;
@@ -0,0 +1,3 @@
1
+ import type { Request } from '../../type';
2
+ export declare function getRequestAcceptableContentTypes(req: Request): string[];
3
+ export declare function getRequestAcceptableContentType(req: Request, input?: string | string[]): string | undefined;
@@ -0,0 +1,2 @@
1
+ import type { Request } from '../../type';
2
+ export declare function matchRequestContentType(req: Request, contentType: string): boolean;
@@ -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,7 @@
1
+ import type { Request } from '../../type';
2
+ import type { TrustProxyInput } from '../../utils';
3
+ type RequestIpOptions = {
4
+ trustProxy?: TrustProxyInput;
5
+ };
6
+ export declare function getRequestIP(req: Request, options?: RequestIpOptions): string;
7
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { Request } from '../../type';
2
+ export declare function useRequestMountPath(req: Request): string;
3
+ export declare function setRequestMountPath(req: Request, basePath: string): void;
@@ -0,0 +1,3 @@
1
+ import Negotiator from 'negotiator';
2
+ import type { Request } from '../../type';
3
+ export declare function useRequestNegotiator(req: Request): Negotiator;
@@ -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,2 @@
1
+ import type { Request } from '../../type';
2
+ export declare function useRequestPath(req: Request): string;
@@ -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,2 @@
1
+ import type { Response } from '../../type';
2
+ export declare function setResponseHeaderAttachment(res: Response, filename?: string): void;
@@ -0,0 +1,2 @@
1
+ import type { Response } from '../../type';
2
+ export declare function setResponseHeaderContentType(res: Response, input: string, ifNotExists?: boolean): 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,2 @@
1
+ import type { Response } from '../../type';
2
+ export declare function sendAccepted(res: Response, chunk?: any): void;
@@ -0,0 +1,2 @@
1
+ import type { Response } from '../../type';
2
+ export declare function sendCreated(res: Response, chunk?: any): void;
@@ -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;
@@ -0,0 +1,6 @@
1
+ import type { Response } from '../../type';
2
+ export type ResponseFormat = {
3
+ [key: string]: () => void;
4
+ default: () => void;
5
+ };
6
+ export declare function sendFormat(_res: Response, _format: ResponseFormat): void;
@@ -0,0 +1,2 @@
1
+ import type { Response } from '../../type';
2
+ export declare function sendRedirect(res: Response, location: string, statusCode?: number): void;
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ import type { Readable } from 'node:stream';
3
+ import type { Response } from '../../type';
4
+ export declare function sendStream(res: Response, stream: Readable, fn?: CallableFunction): void;
@@ -0,0 +1,2 @@
1
+ import type { Response } from '../../type';
2
+ export declare function send(res: Response, chunk?: any): void;
@@ -0,0 +1,3 @@
1
+ import type { Response } from '../../type';
2
+ export declare function setResponseContentTypeByFileName(res: Response, fileName: string): void;
3
+ export declare function onResponseFinished(res: Response, cb: (err?: Error) => void): void;
@@ -0,0 +1,3 @@
1
+ import type { Request, Response } from '../type';
2
+ export type RequestFn = (req: Request) => any;
3
+ export type ResponseFn = (res: Response) => any;