@opra/core 0.33.13 → 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/cjs/augmentation/18n.augmentation.js +17 -4
- package/cjs/augmentation/http-controller.augmentation.js +25 -0
- package/cjs/constants.js +5 -0
- package/cjs/execution-context.js +25 -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 +164 -0
- package/cjs/http/http-adapter.js +27 -0
- package/cjs/http/http-context.js +116 -0
- package/cjs/http/impl/asset-cache.js +21 -0
- package/cjs/http/impl/http-handler.js +575 -0
- package/cjs/http/{http-server-request.js → impl/http-incoming.host.js} +21 -46
- package/cjs/http/{http-server-response.js → impl/http-outgoing.host.js} +7 -26
- package/cjs/http/{helpers/multipart-helper.js → impl/multipart-reader.js} +24 -22
- package/cjs/http/impl/{http-incoming-message.host.js → node-incoming-message.host.js} +13 -54
- 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 +63 -0
- package/cjs/http/interfaces/node-outgoing-message.interface.js +15 -0
- package/cjs/http/utils/body-reader.js +215 -0
- 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 +25 -25
- 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 +25 -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 +159 -0
- package/esm/http/http-adapter.js +23 -0
- package/esm/http/http-context.js +111 -0
- package/esm/http/impl/asset-cache.js +17 -0
- package/esm/http/impl/http-handler.js +570 -0
- package/esm/http/{http-server-request.js → impl/http-incoming.host.js} +17 -43
- package/esm/http/{http-server-response.js → impl/http-outgoing.host.js} +6 -26
- package/esm/http/{helpers/multipart-helper.js → impl/multipart-reader.js} +22 -20
- package/esm/http/impl/{http-incoming-message.host.js → node-incoming-message.host.js} +11 -52
- 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 +60 -0
- package/esm/http/interfaces/node-outgoing-message.interface.js +12 -0
- package/esm/http/utils/body-reader.js +210 -0
- 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 +25 -26
- package/esm/platform-adapter.js +19 -1
- package/esm/type-guards.js +16 -0
- package/package.json +22 -10
- package/types/augmentation/18n.augmentation.d.ts +32 -2
- package/types/augmentation/http-controller.augmentation.d.ts +21 -0
- package/types/constants.d.ts +2 -0
- package/types/execution-context.d.ts +24 -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} +9 -22
- 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 +24 -26
- 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/i18n/i18n/en/error.json +0 -21
- 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}/common.js +0 -0
- /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}/common.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
|
@@ -2,39 +2,26 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
/// <reference types="node" />
|
|
5
|
-
import
|
|
5
|
+
import { IncomingHttpHeaders } from 'http';
|
|
6
6
|
import { Duplex, Readable } from 'stream';
|
|
7
7
|
import { HTTPParserJS } from '@browsery/http-parser';
|
|
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 { EventEmitter } from 'events';
|
|
5
|
+
import nodeStream from 'node:stream';
|
|
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 {};
|
package/types/index.d.ts
CHANGED
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import 'reflect-metadata';
|
|
2
2
|
import './augmentation/18n.augmentation.js';
|
|
3
|
-
import './augmentation/
|
|
4
|
-
import './
|
|
5
|
-
import './
|
|
6
|
-
import './
|
|
7
|
-
import './
|
|
3
|
+
import './augmentation/http-controller.augmentation.js';
|
|
4
|
+
import * as HttpIncomingHost_ from './http/impl/http-incoming.host.js';
|
|
5
|
+
import * as HttpOutgoingHost_ from './http/impl/http-outgoing.host.js';
|
|
6
|
+
import * as NodeIncomingMessageHost_ from './http/impl/node-incoming-message.host.js';
|
|
7
|
+
import * as NodeOutgoingMessageHost_ from './http/impl/node-outgoing-message.host.js';
|
|
8
8
|
export * from './execution-context.js';
|
|
9
|
-
export * from './execution-context.host.js';
|
|
10
9
|
export * from './platform-adapter.js';
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
16
|
-
export * from './
|
|
17
|
-
export * from './http/
|
|
18
|
-
export * from './http/
|
|
19
|
-
export * from './http/
|
|
20
|
-
export * from './http/
|
|
21
|
-
export * from './http/impl/
|
|
22
|
-
export * from './http/
|
|
23
|
-
export * from './http/http-server-request.js';
|
|
24
|
-
export * from './http/http-server-response.js';
|
|
25
|
-
export * from './http/helpers/multipart-helper.js';
|
|
26
|
-
export * from './interfaces/interceptor.interface.js';
|
|
10
|
+
export * from './type-guards.js';
|
|
11
|
+
export * from './helpers/logger.js';
|
|
12
|
+
export * from './helpers/service-base.js';
|
|
13
|
+
export * from './http/express-adapter.js';
|
|
14
|
+
export * from './http/http-adapter.js';
|
|
15
|
+
export * from './http/http-context.js';
|
|
16
|
+
export * from './http/interfaces/http-incoming.interface.js';
|
|
17
|
+
export * from './http/interfaces/http-outgoing.interface.js';
|
|
18
|
+
export * from './http/interfaces/node-incoming-message.interface.js';
|
|
19
|
+
export * from './http/interfaces/node-outgoing-message.interface.js';
|
|
20
|
+
export * from './http/impl/multipart-reader.js';
|
|
21
|
+
export * from './http/utils/wrap-exception.js';
|
|
27
22
|
export * from './interfaces/logger.interface.js';
|
|
28
|
-
export
|
|
29
|
-
export
|
|
30
|
-
export
|
|
23
|
+
export declare namespace classes {
|
|
24
|
+
export import HttpIncomingHost = HttpIncomingHost_.HttpIncomingHost;
|
|
25
|
+
export import HttpOutgoingHost = HttpOutgoingHost_.HttpOutgoingHost;
|
|
26
|
+
export import NodeIncomingMessageHost = NodeIncomingMessageHost_.NodeIncomingMessageHost;
|
|
27
|
+
export import NodeOutgoingMessageHost = NodeOutgoingMessageHost_.NodeOutgoingMessageHost;
|
|
28
|
+
}
|
|
@@ -1,56 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
readonly api: ApiDocument;
|
|
9
|
-
readonly protocol: Protocol;
|
|
10
|
-
readonly platform: string;
|
|
11
|
-
readonly serviceName: string;
|
|
12
|
-
/**
|
|
13
|
-
* Calls shutDown hook for all resources
|
|
14
|
-
*/
|
|
15
|
-
close(): Promise<void>;
|
|
16
|
-
}
|
|
1
|
+
import './augmentation/18n.augmentation.js';
|
|
2
|
+
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
3
|
+
import { ApiDocument, I18n, OpraSchema } from '@opra/common';
|
|
4
|
+
import { kAssetCache } from './constants.js';
|
|
5
|
+
import { Logger } from './helpers/logger.js';
|
|
6
|
+
import { AssetCache } from './http/impl/asset-cache.js';
|
|
7
|
+
import type { ILogger } from './interfaces/logger.interface';
|
|
17
8
|
/**
|
|
18
9
|
* @namespace PlatformAdapter
|
|
19
10
|
*/
|
|
20
11
|
export declare namespace PlatformAdapter {
|
|
21
12
|
interface Options {
|
|
22
|
-
i18n?: I18n
|
|
13
|
+
i18n?: I18n;
|
|
23
14
|
logger?: ILogger;
|
|
24
|
-
interceptors?: Interceptor[];
|
|
25
|
-
on?: {
|
|
26
|
-
request?: (ctx: RequestContext) => void | Promise<void>;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
interface I18nOptions {
|
|
30
|
-
/**
|
|
31
|
-
* Language to use
|
|
32
|
-
* @default undefined
|
|
33
|
-
*/
|
|
34
|
-
lng?: string;
|
|
35
|
-
/**
|
|
36
|
-
* Language to use if translations in user language are not available.
|
|
37
|
-
* @default 'dev'
|
|
38
|
-
*/
|
|
39
|
-
fallbackLng?: false | FallbackLng;
|
|
40
|
-
/**
|
|
41
|
-
* Default namespace used if not passed to translation function
|
|
42
|
-
* @default 'translation'
|
|
43
|
-
*/
|
|
44
|
-
defaultNS?: string;
|
|
45
|
-
/**
|
|
46
|
-
* Resources to initialize with
|
|
47
|
-
* @default undefined
|
|
48
|
-
*/
|
|
49
|
-
resources?: LanguageResource;
|
|
50
|
-
/**
|
|
51
|
-
* Resource directories to initialize with (if not using loading or not appending using addResourceBundle)
|
|
52
|
-
* @default undefined
|
|
53
|
-
*/
|
|
54
|
-
resourceDirs?: string[];
|
|
55
15
|
}
|
|
56
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* @class PlatformAdapter
|
|
19
|
+
*/
|
|
20
|
+
export declare abstract class PlatformAdapter extends AsyncEventEmitter {
|
|
21
|
+
protected [kAssetCache]: AssetCache;
|
|
22
|
+
readonly document: ApiDocument;
|
|
23
|
+
abstract readonly protocol: OpraSchema.Protocol;
|
|
24
|
+
logger: Logger;
|
|
25
|
+
i18n: I18n;
|
|
26
|
+
protected constructor(document: ApiDocument, options?: PlatformAdapter.Options);
|
|
27
|
+
abstract close(): Promise<void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HttpIncoming } from './http/interfaces/http-incoming.interface.js';
|
|
2
|
+
import type { HttpOutgoing } from './http/interfaces/http-outgoing.interface.js';
|
|
3
|
+
import type { NodeIncomingMessage } from './http/interfaces/node-incoming-message.interface.js';
|
|
4
|
+
import type { NodeOutgoingMessage } from './http/interfaces/node-outgoing-message.interface.js';
|
|
5
|
+
export declare function isNodeIncomingMessage(v: any): v is NodeIncomingMessage;
|
|
6
|
+
export declare function isHttpIncoming(v: any): v is HttpIncoming;
|
|
7
|
+
export declare function isNodeOutgoingMessage(v: any): v is NodeOutgoingMessage;
|
|
8
|
+
export declare function isHttpOutgoing(v: any): v is HttpOutgoing;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const common_1 = require("@opra/common");
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
const oldConstruct = common_1.Resource.prototype._construct;
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
common_1.Resource.prototype._construct = function (init) {
|
|
8
|
-
oldConstruct.call(this, init);
|
|
9
|
-
const _this = this;
|
|
10
|
-
_this.onInit = init.onInit;
|
|
11
|
-
_this.onShutdown = init.onShutdown;
|
|
12
|
-
};
|
|
13
|
-
common_1.Collection.OnInit = common_1.Singleton.OnInit = function () {
|
|
14
|
-
return (target, propertyKey) => {
|
|
15
|
-
const sourceMetadata = (Reflect.getOwnMetadata(common_1.RESOURCE_METADATA, target.constructor) || {});
|
|
16
|
-
sourceMetadata.onInit = target[propertyKey];
|
|
17
|
-
Reflect.defineMetadata(common_1.RESOURCE_METADATA, target.constructor, sourceMetadata);
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
common_1.Collection.OnShutdown = common_1.Singleton.OnShutdown = function () {
|
|
21
|
-
return (target, propertyKey) => {
|
|
22
|
-
const sourceMetadata = (Reflect.getOwnMetadata(common_1.RESOURCE_METADATA, target.constructor) || {});
|
|
23
|
-
sourceMetadata.onShutdown = target[propertyKey];
|
|
24
|
-
Reflect.defineMetadata(common_1.RESOURCE_METADATA, target.constructor, sourceMetadata);
|
|
25
|
-
};
|
|
26
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExecutionContextHost = void 0;
|
|
4
|
-
const strict_typed_events_1 = require("strict-typed-events");
|
|
5
|
-
class ExecutionContextHost extends strict_typed_events_1.AsyncEventEmitter {
|
|
6
|
-
constructor(api, platform, protocol) {
|
|
7
|
-
super();
|
|
8
|
-
this.api = api;
|
|
9
|
-
this.platform = platform;
|
|
10
|
-
this.ws = protocol.ws;
|
|
11
|
-
this.rpc = protocol.rpc;
|
|
12
|
-
if (protocol.http) {
|
|
13
|
-
this.protocol = 'http';
|
|
14
|
-
this.http = {
|
|
15
|
-
platform,
|
|
16
|
-
incoming: protocol.http.incoming,
|
|
17
|
-
outgoing: protocol.http.outgoing,
|
|
18
|
-
switchToContext: () => this
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
else if (protocol.ws) {
|
|
22
|
-
this.protocol = 'ws';
|
|
23
|
-
this.ws = protocol.ws;
|
|
24
|
-
}
|
|
25
|
-
else if (protocol.rpc) {
|
|
26
|
-
this.protocol = 'rpc';
|
|
27
|
-
this.rpc = protocol.rpc;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
switchToHttp() {
|
|
31
|
-
if (this.http)
|
|
32
|
-
return this.http;
|
|
33
|
-
throw new TypeError('Not executing in an "Http" context');
|
|
34
|
-
}
|
|
35
|
-
switchToWs() {
|
|
36
|
-
if (this.ws)
|
|
37
|
-
return this.ws;
|
|
38
|
-
throw new TypeError('Not executing in an "WebSocket" context');
|
|
39
|
-
}
|
|
40
|
-
switchToRpc() {
|
|
41
|
-
if (this.rpc)
|
|
42
|
-
return this.rpc;
|
|
43
|
-
throw new TypeError('Not executing in an "RPC" context');
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.ExecutionContextHost = ExecutionContextHost;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExpressAdapterHost = void 0;
|
|
4
|
-
const common_1 = require("@opra/common");
|
|
5
|
-
const http_adapter_host_js_1 = require("../http-adapter-host.js");
|
|
6
|
-
const http_server_request_js_1 = require("../http-server-request.js");
|
|
7
|
-
const http_server_response_js_1 = require("../http-server-response.js");
|
|
8
|
-
class ExpressAdapterHost extends http_adapter_host_js_1.HttpAdapterHost {
|
|
9
|
-
constructor(app) {
|
|
10
|
-
super();
|
|
11
|
-
this._platform = 'express';
|
|
12
|
-
this._app = app;
|
|
13
|
-
}
|
|
14
|
-
get app() {
|
|
15
|
-
return this._app;
|
|
16
|
-
}
|
|
17
|
-
async init(api, options) {
|
|
18
|
-
await super.init(api, options);
|
|
19
|
-
this._api = api;
|
|
20
|
-
const basePath = new common_1.OpraURLPath(options?.basePath);
|
|
21
|
-
this._app.use(basePath.toString(), (_req, _res) => {
|
|
22
|
-
const req = http_server_request_js_1.HttpServerRequest.from(_req);
|
|
23
|
-
const res = http_server_response_js_1.HttpServerResponse.from(_res);
|
|
24
|
-
this.handleHttp(req, res)
|
|
25
|
-
.catch((e) => this._logger.fatal(e));
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
static async create(app, api, options) {
|
|
29
|
-
const adapter = new ExpressAdapterHost(app);
|
|
30
|
-
await adapter.init(api, options);
|
|
31
|
-
return adapter;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.ExpressAdapterHost = ExpressAdapterHost;
|