@opra/core 0.33.13 → 1.0.0-alpha.10
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/cjs/augmentation/18n.augmentation.js +18 -5
- package/cjs/augmentation/http-controller.augmentation.js +25 -0
- package/cjs/constants.js +5 -0
- package/cjs/execution-context.js +24 -12
- package/cjs/{services → helpers}/logger.js +1 -2
- package/cjs/{services/api-service.js → helpers/service-base.js} +8 -8
- package/cjs/http/express-adapter.js +153 -0
- package/cjs/http/http-adapter.js +27 -0
- package/cjs/http/http-context.js +119 -0
- package/cjs/http/impl/asset-cache.js +21 -0
- package/cjs/http/impl/http-handler.js +584 -0
- package/cjs/http/{http-server-request.js → impl/http-incoming.host.js} +24 -49
- package/cjs/http/{http-server-response.js → impl/http-outgoing.host.js} +9 -28
- package/cjs/http/{helpers/multipart-helper.js → impl/multipart-reader.js} +23 -27
- package/cjs/http/impl/{http-incoming-message.host.js → node-incoming-message.host.js} +18 -57
- package/cjs/http/impl/{http-outgoing-message.host.js → node-outgoing-message.host.js} +11 -14
- package/cjs/http/interfaces/http-incoming.interface.js +25 -0
- package/cjs/http/interfaces/http-outgoing.interface.js +22 -0
- package/cjs/http/interfaces/node-incoming-message.interface.js +64 -0
- package/cjs/http/interfaces/node-outgoing-message.interface.js +15 -0
- package/cjs/http/utils/body-reader.js +217 -0
- package/cjs/http/{helpers → utils}/common.js +2 -1
- package/cjs/http/{helpers → utils}/convert-to-raw-headers.js +1 -2
- package/cjs/http/{helpers → utils}/match-known-fields.js +11 -9
- package/cjs/http/utils/wrap-exception.js +34 -0
- package/cjs/index.js +26 -26
- package/cjs/platform-adapter.js +21 -0
- package/cjs/type-guards.js +23 -0
- package/esm/augmentation/18n.augmentation.js +20 -7
- package/esm/augmentation/http-controller.augmentation.js +23 -0
- package/esm/constants.js +2 -0
- package/esm/execution-context.js +24 -13
- package/esm/{services → helpers}/logger.js +1 -2
- package/esm/{services/api-service.js → helpers/service-base.js} +6 -6
- package/esm/http/express-adapter.js +148 -0
- package/esm/http/http-adapter.js +23 -0
- package/esm/http/http-context.js +114 -0
- package/esm/http/impl/asset-cache.js +17 -0
- package/esm/http/impl/http-handler.js +579 -0
- package/esm/http/{http-server-request.js → impl/http-incoming.host.js} +20 -46
- package/esm/http/{http-server-response.js → impl/http-outgoing.host.js} +7 -27
- package/esm/http/{helpers/multipart-helper.js → impl/multipart-reader.js} +21 -25
- package/esm/http/impl/{http-incoming-message.host.js → node-incoming-message.host.js} +16 -55
- package/esm/http/impl/{http-outgoing-message.host.js → node-outgoing-message.host.js} +9 -12
- package/esm/http/interfaces/http-incoming.interface.js +22 -0
- package/esm/http/interfaces/http-outgoing.interface.js +19 -0
- package/esm/http/interfaces/node-incoming-message.interface.js +61 -0
- package/esm/http/interfaces/node-outgoing-message.interface.js +12 -0
- package/esm/http/utils/body-reader.js +212 -0
- package/esm/http/{helpers → utils}/common.js +2 -1
- package/esm/http/{helpers → utils}/convert-to-headers.js +1 -1
- package/esm/http/{helpers → utils}/convert-to-raw-headers.js +2 -3
- package/esm/http/{helpers → utils}/match-known-fields.js +11 -9
- package/esm/http/utils/wrap-exception.js +30 -0
- package/esm/index.js +26 -27
- package/esm/platform-adapter.js +19 -1
- package/esm/type-guards.js +16 -0
- package/package.json +31 -13
- package/types/augmentation/18n.augmentation.d.ts +31 -1
- package/types/augmentation/http-controller.augmentation.d.ts +21 -0
- package/types/constants.d.ts +2 -0
- package/types/execution-context.d.ts +22 -26
- package/types/helpers/service-base.d.ts +10 -0
- package/types/http/express-adapter.d.ts +13 -0
- package/types/http/http-adapter.d.ts +27 -0
- package/types/http/http-context.d.ts +44 -0
- package/types/http/impl/asset-cache.d.ts +5 -0
- package/types/http/impl/http-handler.d.ts +73 -0
- package/types/http/impl/http-incoming.host.d.ts +23 -0
- package/types/http/impl/http-outgoing.host.d.ts +17 -0
- package/types/http/{helpers/multipart-helper.d.ts → impl/multipart-reader.d.ts} +8 -6
- package/types/http/impl/{http-incoming-message.host.d.ts → node-incoming-message.host.d.ts} +10 -23
- package/types/http/impl/{http-outgoing-message.host.d.ts → node-outgoing-message.host.d.ts} +11 -27
- package/types/http/{http-server-request.d.ts → interfaces/http-incoming.interface.d.ts} +28 -17
- package/types/http/{http-server-response.d.ts → interfaces/http-outgoing.interface.d.ts} +17 -10
- package/types/http/interfaces/node-incoming-message.interface.d.ts +38 -0
- package/types/http/interfaces/node-outgoing-message.interface.d.ts +29 -0
- package/types/http/utils/body-reader.d.ts +41 -0
- package/types/http/utils/wrap-exception.d.ts +2 -0
- package/types/index.d.ts +25 -27
- package/types/platform-adapter.d.ts +20 -48
- package/types/type-guards.d.ts +8 -0
- package/cjs/augmentation/collection.augmentation.js +0 -2
- package/cjs/augmentation/container.augmentation.js +0 -2
- package/cjs/augmentation/resource.augmentation.js +0 -26
- package/cjs/augmentation/singleton.augmentation.js +0 -2
- package/cjs/augmentation/storage.augmentation.js +0 -2
- package/cjs/execution-context.host.js +0 -46
- package/cjs/http/adapters/express-adapter.host.js +0 -34
- package/cjs/http/adapters/express-adapter.js +0 -14
- package/cjs/http/adapters/node-http-adapter.host.js +0 -70
- package/cjs/http/adapters/node-http-adapter.js +0 -14
- package/cjs/http/helpers/json-body-loader.js +0 -29
- package/cjs/http/helpers/query-parsers.js +0 -16
- package/cjs/http/http-adapter-host.js +0 -715
- package/cjs/interfaces/interceptor.interface.js +0 -2
- package/cjs/interfaces/request-handler.interface.js +0 -2
- package/cjs/platform-adapter.host.js +0 -154
- package/cjs/request-context.js +0 -25
- package/cjs/request.host.js +0 -24
- package/cjs/request.js +0 -2
- package/cjs/response.host.js +0 -22
- package/cjs/response.js +0 -2
- package/esm/augmentation/collection.augmentation.js +0 -1
- package/esm/augmentation/container.augmentation.js +0 -1
- package/esm/augmentation/resource.augmentation.js +0 -24
- package/esm/augmentation/singleton.augmentation.js +0 -1
- package/esm/augmentation/storage.augmentation.js +0 -1
- package/esm/execution-context.host.js +0 -42
- package/esm/http/adapters/express-adapter.host.js +0 -30
- package/esm/http/adapters/express-adapter.js +0 -11
- package/esm/http/adapters/node-http-adapter.host.js +0 -65
- package/esm/http/adapters/node-http-adapter.js +0 -11
- package/esm/http/helpers/json-body-loader.js +0 -24
- package/esm/http/helpers/query-parsers.js +0 -12
- package/esm/http/http-adapter-host.js +0 -710
- package/esm/interfaces/interceptor.interface.js +0 -1
- package/esm/interfaces/request-handler.interface.js +0 -1
- package/esm/platform-adapter.host.js +0 -149
- package/esm/request-context.js +0 -22
- package/esm/request.host.js +0 -20
- package/esm/request.js +0 -1
- package/esm/response.host.js +0 -18
- package/esm/response.js +0 -1
- package/types/augmentation/collection.augmentation.d.ts +0 -146
- package/types/augmentation/container.augmentation.d.ts +0 -14
- package/types/augmentation/resource.augmentation.d.ts +0 -38
- package/types/augmentation/singleton.augmentation.d.ts +0 -83
- package/types/augmentation/storage.augmentation.d.ts +0 -50
- package/types/execution-context.host.d.ts +0 -25
- package/types/http/adapters/express-adapter.d.ts +0 -15
- package/types/http/adapters/express-adapter.host.d.ts +0 -12
- package/types/http/adapters/node-http-adapter.d.ts +0 -17
- package/types/http/adapters/node-http-adapter.host.d.ts +0 -19
- package/types/http/helpers/json-body-loader.d.ts +0 -5
- package/types/http/helpers/query-parsers.d.ts +0 -1
- package/types/http/http-adapter-host.d.ts +0 -34
- package/types/interfaces/interceptor.interface.d.ts +0 -2
- package/types/interfaces/request-handler.interface.d.ts +0 -4
- package/types/platform-adapter.host.d.ts +0 -43
- package/types/request-context.d.ts +0 -13
- package/types/request.d.ts +0 -14
- package/types/request.host.d.ts +0 -27
- package/types/response.d.ts +0 -22
- package/types/response.host.d.ts +0 -22
- package/types/services/api-service.d.ts +0 -10
- /package/cjs/http/{helpers → utils}/concat-readable.js +0 -0
- /package/cjs/http/{helpers → utils}/convert-to-headers.js +0 -0
- /package/esm/http/{helpers → utils}/concat-readable.js +0 -0
- /package/types/{services → helpers}/logger.d.ts +0 -0
- /package/types/http/{helpers → utils}/common.d.ts +0 -0
- /package/types/http/{helpers → utils}/concat-readable.d.ts +0 -0
- /package/types/http/{helpers → utils}/convert-to-headers.d.ts +0 -0
- /package/types/http/{helpers → utils}/convert-to-raw-headers.d.ts +0 -0
- /package/types/http/{helpers → utils}/match-known-fields.d.ts +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ApiDocument, HttpApi, OpraSchema } from '@opra/common';
|
|
2
|
+
import { kHandler } from '../constants.js';
|
|
3
|
+
import { PlatformAdapter } from '../platform-adapter.js';
|
|
4
|
+
import { HttpContext } from './http-context.js';
|
|
5
|
+
import { HttpHandler } from './impl/http-handler.js';
|
|
6
|
+
export declare namespace HttpAdapter {
|
|
7
|
+
/**
|
|
8
|
+
* @type Interceptor
|
|
9
|
+
*/
|
|
10
|
+
type Interceptor = (context: HttpContext, next: () => Promise<void>) => Promise<void>;
|
|
11
|
+
interface Options extends PlatformAdapter.Options {
|
|
12
|
+
basePath?: string;
|
|
13
|
+
interceptors?: HttpAdapter.Interceptor[];
|
|
14
|
+
onRequest?: (ctx: HttpContext) => void | Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @class HttpAdapter
|
|
20
|
+
*/
|
|
21
|
+
export declare abstract class HttpAdapter extends PlatformAdapter {
|
|
22
|
+
protected [kHandler]: HttpHandler;
|
|
23
|
+
readonly protocol: OpraSchema.Protocol;
|
|
24
|
+
interceptors: HttpAdapter.Interceptor[];
|
|
25
|
+
protected constructor(document: ApiDocument, options?: HttpAdapter.Options);
|
|
26
|
+
get api(): HttpApi;
|
|
27
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { HttpController, HttpMediaType, HttpOperation, OpraSchema } from '@opra/common';
|
|
2
|
+
import { ExecutionContext } from '../execution-context.js';
|
|
3
|
+
import type { HttpAdapter } from './http-adapter';
|
|
4
|
+
import { MultipartReader } from './impl/multipart-reader.js';
|
|
5
|
+
import type { HttpIncoming } from './interfaces/http-incoming.interface';
|
|
6
|
+
import type { HttpOutgoing } from './interfaces/http-outgoing.interface';
|
|
7
|
+
export declare namespace HttpContext {
|
|
8
|
+
interface Initiator extends Omit<ExecutionContext.Initiator, 'document' | 'protocol'> {
|
|
9
|
+
adapter: HttpAdapter;
|
|
10
|
+
request: HttpIncoming;
|
|
11
|
+
response: HttpOutgoing;
|
|
12
|
+
controller?: HttpController;
|
|
13
|
+
controllerInstance?: any;
|
|
14
|
+
operation?: HttpOperation;
|
|
15
|
+
operationHandler?: Function;
|
|
16
|
+
cookies?: Record<string, any>;
|
|
17
|
+
headers?: Record<string, any>;
|
|
18
|
+
pathParams?: Record<string, any>;
|
|
19
|
+
queryParams?: Record<string, any>;
|
|
20
|
+
mediaType?: HttpMediaType;
|
|
21
|
+
body?: any;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export declare class HttpContext extends ExecutionContext {
|
|
25
|
+
protected _body?: any;
|
|
26
|
+
protected _multipartReader?: MultipartReader;
|
|
27
|
+
readonly protocol: OpraSchema.Protocol;
|
|
28
|
+
readonly adapter: HttpAdapter;
|
|
29
|
+
readonly controller: HttpController;
|
|
30
|
+
readonly controllerInstance?: any;
|
|
31
|
+
readonly operation: HttpOperation;
|
|
32
|
+
readonly operationHandler?: Function;
|
|
33
|
+
readonly request: HttpIncoming;
|
|
34
|
+
readonly response: HttpOutgoing;
|
|
35
|
+
readonly mediaType?: HttpMediaType;
|
|
36
|
+
readonly cookies: Record<string, any>;
|
|
37
|
+
readonly headers: Record<string, any>;
|
|
38
|
+
readonly pathParams: Record<string, any>;
|
|
39
|
+
readonly queryParams: Record<string, any>;
|
|
40
|
+
constructor(init: HttpContext.Initiator);
|
|
41
|
+
get isMultipart(): boolean;
|
|
42
|
+
getMultipartReader(): Promise<MultipartReader>;
|
|
43
|
+
getBody<T>(): Promise<T>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { HttpOperationResponse } from '@opra/common';
|
|
2
|
+
import { kAssetCache } from '../../constants.js';
|
|
3
|
+
import type { HttpAdapter } from '../http-adapter.js';
|
|
4
|
+
import { HttpContext } from '../http-context.js';
|
|
5
|
+
import { HttpOutgoing } from '../interfaces/http-outgoing.interface.js';
|
|
6
|
+
import { AssetCache } from './asset-cache.js';
|
|
7
|
+
/**
|
|
8
|
+
* @namespace
|
|
9
|
+
*/
|
|
10
|
+
export declare namespace HttpHandler {
|
|
11
|
+
/**
|
|
12
|
+
* @interface ResponseArgs
|
|
13
|
+
*/
|
|
14
|
+
interface ResponseArgs {
|
|
15
|
+
statusCode: number;
|
|
16
|
+
contentType?: string;
|
|
17
|
+
operationResponse?: HttpOperationResponse;
|
|
18
|
+
body?: any;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @class HttpHandler
|
|
23
|
+
*/
|
|
24
|
+
export declare class HttpHandler {
|
|
25
|
+
readonly adapter: HttpAdapter;
|
|
26
|
+
protected [kAssetCache]: AssetCache;
|
|
27
|
+
constructor(adapter: HttpAdapter);
|
|
28
|
+
/**
|
|
29
|
+
* Main http request handler
|
|
30
|
+
* @param context
|
|
31
|
+
* @protected
|
|
32
|
+
*/
|
|
33
|
+
handleRequest(context: HttpContext): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param context
|
|
37
|
+
*/
|
|
38
|
+
parseRequest(context: HttpContext): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param context
|
|
42
|
+
* @protected
|
|
43
|
+
*/
|
|
44
|
+
protected _parseParameters(context: HttpContext): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param context
|
|
48
|
+
* @protected
|
|
49
|
+
*/
|
|
50
|
+
protected _parseContentType(context: HttpContext): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param context
|
|
54
|
+
* @protected
|
|
55
|
+
*/
|
|
56
|
+
protected _executeRequest(context: HttpContext): Promise<any>;
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @param context
|
|
60
|
+
* @param responseValue
|
|
61
|
+
* @protected
|
|
62
|
+
*/
|
|
63
|
+
protected _sendResponse(context: HttpContext, responseValue: any): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
*
|
|
66
|
+
* @param context
|
|
67
|
+
* @param body
|
|
68
|
+
* @protected
|
|
69
|
+
*/
|
|
70
|
+
protected _determineResponseArgs(context: HttpContext, body: any): HttpHandler.ResponseArgs;
|
|
71
|
+
sendDocumentSchema(context: HttpContext): Promise<void>;
|
|
72
|
+
sendErrorResponse(response: HttpOutgoing, errors: any[]): Promise<void>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import parseRange from 'range-parser';
|
|
3
|
+
import type { HttpIncoming } from '../interfaces/http-incoming.interface';
|
|
4
|
+
import { BodyReader } from '../utils/body-reader.js';
|
|
5
|
+
export interface HttpIncomingHost extends HttpIncoming {
|
|
6
|
+
}
|
|
7
|
+
export declare class HttpIncomingHost implements HttpIncoming {
|
|
8
|
+
body?: any;
|
|
9
|
+
get protocol(): string;
|
|
10
|
+
get secure(): boolean;
|
|
11
|
+
get hostname(): string | undefined;
|
|
12
|
+
get fresh(): boolean;
|
|
13
|
+
get xhr(): boolean;
|
|
14
|
+
header(name: string): any;
|
|
15
|
+
get(name: string): any;
|
|
16
|
+
accepts(...types: any): any;
|
|
17
|
+
acceptsCharsets(...charsets: any): any;
|
|
18
|
+
acceptsEncodings(...encoding: any): any;
|
|
19
|
+
acceptsLanguages(...lang: any): any;
|
|
20
|
+
is(type: string | string[], ...otherTypes: string[]): string | false | null;
|
|
21
|
+
range(size: number, options: any): parseRange.Ranges | parseRange.Result | undefined;
|
|
22
|
+
readBody(options: BodyReader.Options): Promise<string | Buffer | undefined>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CookieOptions, HttpOutgoing } from '../interfaces/http-outgoing.interface';
|
|
2
|
+
export interface HttpOutgoingHost extends HttpOutgoing {
|
|
3
|
+
}
|
|
4
|
+
export declare class HttpOutgoingHost {
|
|
5
|
+
attachment(filename?: string): this;
|
|
6
|
+
contentType(type: any): this;
|
|
7
|
+
setHeader(field: string | Record<string, any>, val?: any): this;
|
|
8
|
+
clearCookie(name: string, options: CookieOptions): this;
|
|
9
|
+
cookie(name: string, value: any, options?: CookieOptions): this;
|
|
10
|
+
status(code: number): this;
|
|
11
|
+
sendStatus(statusCode: number): this;
|
|
12
|
+
links(links: Record<string, string>): this;
|
|
13
|
+
location(url: string): this;
|
|
14
|
+
redirect(arg0: string | number, arg1?: string): void;
|
|
15
|
+
send(body: any): this;
|
|
16
|
+
vary(field: string): this;
|
|
17
|
+
}
|
|
@@ -2,25 +2,27 @@
|
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import formidable from 'formidable';
|
|
4
4
|
import type IncomingForm from 'formidable/Formidable.js';
|
|
5
|
-
import {
|
|
5
|
+
import type { NodeIncomingMessage } from '../interfaces/node-incoming-message.interface.js';
|
|
6
6
|
export type MultipartFile = formidable.File;
|
|
7
7
|
export type MultipartItem = {
|
|
8
|
-
|
|
8
|
+
fieldName: string;
|
|
9
|
+
type: 'field' | 'file';
|
|
9
10
|
value?: string;
|
|
10
11
|
file?: MultipartFile;
|
|
11
12
|
};
|
|
12
|
-
export declare class
|
|
13
|
+
export declare class MultipartReader extends EventEmitter {
|
|
14
|
+
protected _incoming: NodeIncomingMessage;
|
|
15
|
+
protected _started: boolean;
|
|
13
16
|
protected _cancelled: boolean;
|
|
14
17
|
protected _form: IncomingForm;
|
|
15
18
|
protected _items: MultipartItem[];
|
|
16
19
|
protected _stack: MultipartItem[];
|
|
17
|
-
|
|
20
|
+
constructor(incoming: NodeIncomingMessage, options?: formidable.Options);
|
|
18
21
|
get items(): MultipartItem[];
|
|
19
22
|
getNext(): Promise<MultipartItem | undefined>;
|
|
20
23
|
getAll(): Promise<MultipartItem[]>;
|
|
21
24
|
cancel(): void;
|
|
22
25
|
resume(): void;
|
|
23
26
|
pause(): void;
|
|
24
|
-
|
|
25
|
-
static create(incoming: HttpIncomingMessage, options?: formidable.Options): Promise<MultipartIterator>;
|
|
27
|
+
deleteTempFiles(): Promise<PromiseSettledResult<any>[]>;
|
|
26
28
|
}
|
|
@@ -2,39 +2,26 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
/// <reference types="node" />
|
|
5
|
-
import http, { IncomingHttpHeaders } from 'http';
|
|
6
|
-
import { Duplex, Readable } from 'stream';
|
|
7
5
|
import { HTTPParserJS } from '@browsery/http-parser';
|
|
6
|
+
import { IncomingHttpHeaders } from 'http';
|
|
7
|
+
import { Duplex, Readable } from 'stream';
|
|
8
|
+
import type { NodeIncomingMessage } from '../interfaces/node-incoming-message.interface';
|
|
8
9
|
export declare const CRLF: Buffer;
|
|
9
10
|
export declare const kHeaders: unique symbol;
|
|
10
11
|
export declare const kHeadersDistinct: unique symbol;
|
|
11
12
|
export declare const kTrailers: unique symbol;
|
|
12
13
|
export declare const kTrailersDistinct: unique symbol;
|
|
13
|
-
export
|
|
14
|
-
}
|
|
15
|
-
export declare namespace HttpIncomingMessageHost {
|
|
16
|
-
interface Initiator {
|
|
17
|
-
httpVersionMajor?: number;
|
|
18
|
-
httpVersionMinor?: number;
|
|
19
|
-
method?: string;
|
|
20
|
-
url?: string;
|
|
21
|
-
headers?: Record<string, any> | string[];
|
|
22
|
-
trailers?: Record<string, any> | string[];
|
|
23
|
-
body?: any;
|
|
24
|
-
ip?: string;
|
|
25
|
-
ips?: string[];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
14
|
+
export declare const kHttpParser: unique symbol;
|
|
28
15
|
/**
|
|
29
16
|
*
|
|
30
|
-
* @class
|
|
17
|
+
* @class NodeIncomingMessageHost
|
|
31
18
|
*/
|
|
32
|
-
export declare class
|
|
19
|
+
export declare class NodeIncomingMessageHost extends Duplex implements NodeIncomingMessage {
|
|
33
20
|
protected [kHeaders]?: IncomingHttpHeaders;
|
|
34
21
|
protected [kHeadersDistinct]?: NodeJS.Dict<string[]>;
|
|
35
22
|
protected [kTrailers]?: NodeJS.Dict<string>;
|
|
36
23
|
protected [kTrailersDistinct]?: NodeJS.Dict<string[]>;
|
|
37
|
-
protected
|
|
24
|
+
protected [kHttpParser]: HTTPParserJS | undefined;
|
|
38
25
|
protected _readStream?: Readable;
|
|
39
26
|
httpVersionMajor: number;
|
|
40
27
|
httpVersionMinor: number;
|
|
@@ -42,12 +29,14 @@ export declare class HttpIncomingMessageHost extends Duplex implements HttpIncom
|
|
|
42
29
|
url: string;
|
|
43
30
|
rawHeaders: string[];
|
|
44
31
|
rawTrailers: string[];
|
|
32
|
+
params?: Record<string, any>;
|
|
33
|
+
cookies?: Record<string, any>;
|
|
45
34
|
body?: Buffer;
|
|
46
35
|
complete: boolean;
|
|
47
36
|
ip?: string;
|
|
48
37
|
ips?: string[];
|
|
49
38
|
joinDuplicateHeaders: boolean;
|
|
50
|
-
constructor(init?:
|
|
39
|
+
constructor(init?: NodeIncomingMessage.Initiator);
|
|
51
40
|
get httpVersion(): string;
|
|
52
41
|
get headers(): IncomingHttpHeaders;
|
|
53
42
|
set headers(headers: IncomingHttpHeaders);
|
|
@@ -57,6 +46,4 @@ export declare class HttpIncomingMessageHost extends Duplex implements HttpIncom
|
|
|
57
46
|
get trailersDistinct(): NodeJS.Dict<string[]>;
|
|
58
47
|
_read(size: number): void;
|
|
59
48
|
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
60
|
-
static from(iterable: string | Iterable<any> | AsyncIterable<any> | HttpIncomingMessageHost.Initiator): HttpIncomingMessageHost;
|
|
61
|
-
static fromAsync(iterable: string | Iterable<any> | AsyncIterable<any> | HttpIncomingMessageHost.Initiator): Promise<HttpIncomingMessageHost>;
|
|
62
49
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
-
import
|
|
5
|
-
import { Duplex
|
|
6
|
-
import type {
|
|
4
|
+
import { OutgoingHttpHeaders } from 'http';
|
|
5
|
+
import { Duplex } from 'stream';
|
|
6
|
+
import type { NodeIncomingMessage } from '../interfaces/node-incoming-message.interface';
|
|
7
|
+
import type { NodeOutgoingMessage } from '../interfaces/node-outgoing-message.interface';
|
|
7
8
|
export declare const kOutHeaders: unique symbol;
|
|
8
9
|
export declare const kOutTrailers: unique symbol;
|
|
9
10
|
declare global {
|
|
@@ -12,57 +13,40 @@ declare global {
|
|
|
12
13
|
entries(): IterableIterator<[string, any]>;
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
|
-
export interface HttpOutgoingMessage extends Pick<http.ServerResponse, 'addTrailers' | 'getHeader' | 'getHeaders' | 'getHeaderNames' | 'removeHeader' | 'hasHeader' | 'headersSent' | 'statusCode' | 'statusMessage' | 'sendDate'>, Writable {
|
|
16
|
-
req?: HttpIncomingMessage;
|
|
17
|
-
appendHeader(name: string, value: string | readonly string[]): this;
|
|
18
|
-
setHeader(name: string, value: number | string | readonly string[]): this;
|
|
19
|
-
}
|
|
20
|
-
export declare namespace HttpOutgoingMessageHost {
|
|
21
|
-
interface Initiator {
|
|
22
|
-
req?: HttpIncomingMessage;
|
|
23
|
-
statusCode?: number;
|
|
24
|
-
statusMessage?: string;
|
|
25
|
-
headers?: OutgoingHttpHeaders | Headers | Map<string, any> | string[];
|
|
26
|
-
chunkedEncoding?: boolean;
|
|
27
|
-
sendDate?: boolean;
|
|
28
|
-
strictContentLength?: boolean;
|
|
29
|
-
body?: string | Iterable<any> | AsyncIterable<any> | Object;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
16
|
/**
|
|
33
17
|
*
|
|
34
|
-
* @class
|
|
18
|
+
* @class NodeOutgoingMessageHost
|
|
35
19
|
*/
|
|
36
|
-
export declare class
|
|
20
|
+
export declare class NodeOutgoingMessageHost extends Duplex implements NodeOutgoingMessage {
|
|
37
21
|
protected [kOutHeaders]: Record<string, any>;
|
|
38
22
|
protected [kOutTrailers]: Record<string, any>;
|
|
39
23
|
protected _headersSent: boolean;
|
|
40
24
|
protected _httpVersionMajor?: number;
|
|
41
25
|
protected _httpVersionMinor?: number;
|
|
42
26
|
finished: boolean;
|
|
43
|
-
req
|
|
27
|
+
req: NodeIncomingMessage;
|
|
44
28
|
statusCode: number;
|
|
45
29
|
statusMessage: string;
|
|
46
30
|
chunkedEncoding: boolean;
|
|
47
31
|
sendDate: boolean;
|
|
48
32
|
strictContentLength: boolean;
|
|
49
33
|
body?: any;
|
|
50
|
-
constructor(init?:
|
|
34
|
+
constructor(init?: NodeOutgoingMessage.Initiator);
|
|
51
35
|
get httpVersionMajor(): number | undefined;
|
|
52
36
|
get httpVersionMinor(): number | undefined;
|
|
53
37
|
get headersSent(): boolean;
|
|
54
38
|
appendHeader(name: string, value: number | string | readonly string[]): this;
|
|
55
39
|
addTrailers(headers: OutgoingHttpHeaders | [string, string][] | readonly [string, string][]): void;
|
|
56
|
-
|
|
40
|
+
flushHeaders(): void;
|
|
41
|
+
setHeader(name: string, value: number | string | readonly string[]): this;
|
|
57
42
|
setHeaders(headers: Headers | Map<string, any> | Record<string, any>): this;
|
|
58
43
|
getHeader(name: string): any;
|
|
59
44
|
getHeaderNames(): string[];
|
|
60
|
-
getRawHeaderNames():
|
|
45
|
+
getRawHeaderNames(): string[];
|
|
61
46
|
getHeaders(): OutgoingHttpHeaders;
|
|
62
47
|
hasHeader(name: string): boolean;
|
|
63
48
|
removeHeader(name: string): void;
|
|
64
49
|
end(cb?: () => void): this;
|
|
65
50
|
end(chunk: any, cb?: () => void): this;
|
|
66
51
|
end(chunk: any, encoding: BufferEncoding, cb?: () => void): this;
|
|
67
|
-
static from(init: HttpOutgoingMessageHost.Initiator): HttpOutgoingMessageHost;
|
|
68
52
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { Options as RangeParserOptions, Ranges as RangeParserRanges, Result as RangeParserResult } from 'range-parser';
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export interface
|
|
9
|
-
res:
|
|
3
|
+
import { BodyReader } from '../utils/body-reader.js';
|
|
4
|
+
import type { HttpOutgoing } from './http-outgoing.interface';
|
|
5
|
+
import { NodeIncomingMessage } from './node-incoming-message.interface.js';
|
|
6
|
+
/**
|
|
7
|
+
* @interface HttpIncoming
|
|
8
|
+
*/
|
|
9
|
+
export interface HttpIncoming extends NodeIncomingMessage {
|
|
10
|
+
res: HttpOutgoing;
|
|
10
11
|
baseUrl: string;
|
|
11
12
|
originalUrl: string;
|
|
12
|
-
parsedUrl: OpraURL;
|
|
13
|
-
searchParams: URLSearchParams;
|
|
14
|
-
body?: any;
|
|
15
13
|
/**
|
|
16
14
|
* Return the protocol string "http" or "https"
|
|
17
15
|
* When the "X-Forwarded-Proto" header field will be trusted
|
|
@@ -38,6 +36,10 @@ export interface HttpServerRequest extends HttpIncomingMessage {
|
|
|
38
36
|
* req.protocol === 'https'
|
|
39
37
|
*/
|
|
40
38
|
secure: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Used for signed cookies
|
|
41
|
+
*/
|
|
42
|
+
secret?: string;
|
|
41
43
|
/**
|
|
42
44
|
* Parse the "Host" header field to a hostname.
|
|
43
45
|
*
|
|
@@ -52,15 +54,13 @@ export interface HttpServerRequest extends HttpIncomingMessage {
|
|
|
52
54
|
*/
|
|
53
55
|
fresh: boolean;
|
|
54
56
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
+
* Path parameter values
|
|
57
58
|
*/
|
|
58
|
-
|
|
59
|
+
params: Record<string, any>;
|
|
59
60
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
61
|
+
* Cookie parameter values
|
|
62
62
|
*/
|
|
63
|
-
|
|
63
|
+
cookies?: Record<string, any>;
|
|
64
64
|
/**
|
|
65
65
|
* Return request header.
|
|
66
66
|
*
|
|
@@ -179,4 +179,15 @@ export interface HttpServerRequest extends HttpIncomingMessage {
|
|
|
179
179
|
* Parse Range header field, capping to the given `size`.
|
|
180
180
|
*/
|
|
181
181
|
range(size: number, options?: RangeParserOptions): RangeParserRanges | RangeParserResult | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* Receives the body
|
|
184
|
+
* @param options
|
|
185
|
+
*/
|
|
186
|
+
readBody(options: BodyReader.Options): Promise<string | Buffer | undefined>;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* @namespace HttpIncoming
|
|
190
|
+
*/
|
|
191
|
+
export declare namespace HttpIncoming {
|
|
192
|
+
function from(instance: HttpIncoming | NodeIncomingMessage.Initiator | string | Iterable<any> | AsyncIterable<any>): HttpIncoming;
|
|
182
193
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { StrictOmit } from 'ts-gems';
|
|
2
|
+
import type { HttpIncoming } from './http-incoming.interface';
|
|
3
|
+
import { NodeOutgoingMessage } from './node-outgoing-message.interface.js';
|
|
4
|
+
export interface HttpOutgoing extends StrictOmit<NodeOutgoingMessage, 'req' | 'appendHeader' | 'setHeader'> {
|
|
5
|
+
req: HttpIncoming;
|
|
6
|
+
readonly finished?: boolean;
|
|
7
|
+
appendHeader(name: string, value: string | readonly string[]): this;
|
|
8
|
+
setHeader(name: string, value: number | string | readonly string[]): this;
|
|
8
9
|
/**
|
|
9
10
|
* Set _Content-Disposition_ header to _attachment_ with optional `filename`.
|
|
10
11
|
*/
|
|
11
|
-
attachment(
|
|
12
|
+
attachment(filename?: string): this;
|
|
12
13
|
/** Clear cookie `name`. */
|
|
13
14
|
clearCookie(name: string, options?: CookieOptions): this;
|
|
14
15
|
/**
|
|
@@ -111,7 +112,7 @@ export interface HttpServerResponse extends HttpOutgoingMessage {
|
|
|
111
112
|
* response to the standard description from node's http.STATUS_CODES
|
|
112
113
|
* or the statusCode number if no description.
|
|
113
114
|
*/
|
|
114
|
-
sendStatus(statusCode: number):
|
|
115
|
+
sendStatus(statusCode: number): this;
|
|
115
116
|
/**
|
|
116
117
|
* Send a response.
|
|
117
118
|
*
|
|
@@ -132,6 +133,12 @@ export interface CookieOptions {
|
|
|
132
133
|
path?: string;
|
|
133
134
|
domain?: string;
|
|
134
135
|
secure?: boolean;
|
|
135
|
-
encode?: (
|
|
136
|
+
encode?: (val: string) => string;
|
|
136
137
|
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
137
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* @namespace HttpIncoming
|
|
141
|
+
*/
|
|
142
|
+
export declare namespace HttpOutgoing {
|
|
143
|
+
function from(instance: HttpOutgoing | NodeOutgoingMessage.Initiator): HttpOutgoing;
|
|
144
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import http from 'http';
|
|
4
|
+
import { Readable } from 'stream';
|
|
5
|
+
/**
|
|
6
|
+
* @interface NodeIncomingMessage
|
|
7
|
+
*/
|
|
8
|
+
export interface NodeIncomingMessage extends Readable, Pick<http.IncomingMessage, 'httpVersion' | 'httpVersionMajor' | 'httpVersionMinor' | 'complete' | 'headers' | 'trailers' | 'rawHeaders' | 'rawTrailers' | 'method' | 'url'> {
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @namespace NodeIncomingMessage
|
|
13
|
+
*/
|
|
14
|
+
export declare namespace NodeIncomingMessage {
|
|
15
|
+
interface Initiator {
|
|
16
|
+
httpVersionMajor?: number;
|
|
17
|
+
httpVersionMinor?: number;
|
|
18
|
+
method?: string;
|
|
19
|
+
url?: string;
|
|
20
|
+
headers?: Record<string, any> | string[];
|
|
21
|
+
trailers?: Record<string, any> | string[];
|
|
22
|
+
params?: Record<string, any>;
|
|
23
|
+
cookies?: Record<string, any>;
|
|
24
|
+
body?: any;
|
|
25
|
+
ip?: string;
|
|
26
|
+
ips?: string[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new NodeIncomingMessage from given argument
|
|
30
|
+
* @param iterable
|
|
31
|
+
*/
|
|
32
|
+
function from(iterable: string | Iterable<any> | AsyncIterable<any> | Initiator): NodeIncomingMessage;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new NodeIncomingMessage from given argument
|
|
35
|
+
* @param iterable
|
|
36
|
+
*/
|
|
37
|
+
function fromAsync(iterable: string | Iterable<any> | AsyncIterable<any> | Initiator): Promise<NodeIncomingMessage>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import http, { OutgoingHttpHeaders } from 'http';
|
|
4
|
+
import { Writable } from 'stream';
|
|
5
|
+
import { NodeIncomingMessage } from './node-incoming-message.interface.js';
|
|
6
|
+
export interface NodeOutgoingMessage extends Writable, Pick<http.ServerResponse, 'addTrailers' | 'getHeader' | 'getHeaders' | 'getHeaderNames' | 'flushHeaders' | 'removeHeader' | 'hasHeader' | 'headersSent' | 'statusCode' | 'statusMessage' | 'sendDate'> {
|
|
7
|
+
req: NodeIncomingMessage;
|
|
8
|
+
getRawHeaderNames(): string[];
|
|
9
|
+
appendHeader(name: string, value: string | readonly string[]): this;
|
|
10
|
+
setHeader(name: string, value: number | string | readonly string[]): this;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @namespace NodeOutgoingMessage
|
|
15
|
+
*/
|
|
16
|
+
export declare namespace NodeOutgoingMessage {
|
|
17
|
+
interface Initiator {
|
|
18
|
+
req: NodeIncomingMessage;
|
|
19
|
+
statusCode?: number;
|
|
20
|
+
statusMessage?: string;
|
|
21
|
+
headers?: OutgoingHttpHeaders | Headers | Map<string, any> | string[];
|
|
22
|
+
chunkedEncoding?: boolean;
|
|
23
|
+
sendDate?: boolean;
|
|
24
|
+
strictContentLength?: boolean;
|
|
25
|
+
body?: string | Iterable<any> | AsyncIterable<any> | Object;
|
|
26
|
+
parsedUrl?: URL;
|
|
27
|
+
}
|
|
28
|
+
function from(init: Initiator): NodeOutgoingMessage;
|
|
29
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import nodeStream from 'node:stream';
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
import type { HttpIncoming } from '../interfaces/http-incoming.interface.js';
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @namespace BodyReader
|
|
10
|
+
*/
|
|
11
|
+
export declare namespace BodyReader {
|
|
12
|
+
interface Options {
|
|
13
|
+
limit?: number | string;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
type Callback = (...args: any[]) => any;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @class BodyReader
|
|
20
|
+
*/
|
|
21
|
+
export declare class BodyReader extends EventEmitter {
|
|
22
|
+
readonly req: HttpIncoming;
|
|
23
|
+
limit?: number;
|
|
24
|
+
protected _stream: nodeStream.Readable;
|
|
25
|
+
protected _buffer?: string | Buffer[];
|
|
26
|
+
protected _completed?: boolean | undefined;
|
|
27
|
+
protected _receivedSize: number;
|
|
28
|
+
protected cleanup: Callback;
|
|
29
|
+
protected onAborted: Callback;
|
|
30
|
+
protected onData: Callback;
|
|
31
|
+
protected onEnd: Callback;
|
|
32
|
+
constructor(req: HttpIncoming, options?: BodyReader.Options);
|
|
33
|
+
read(): Promise<string | Buffer | undefined>;
|
|
34
|
+
protected _onEnd(error: any): void;
|
|
35
|
+
protected _cleanup(): void;
|
|
36
|
+
protected _onAborted(): void;
|
|
37
|
+
protected _onData(chunk: Buffer | string): void;
|
|
38
|
+
static read(req: HttpIncoming, options?: BodyReader.Options): Promise<string | Buffer | undefined>;
|
|
39
|
+
protected static encoderPipeline(req: HttpIncoming): nodeStream.Readable;
|
|
40
|
+
}
|
|
41
|
+
export {};
|