@opra/core 0.21.0 → 0.23.0
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/adapter/execution-context.host.js +48 -0
- package/cjs/adapter/http/express-adapter.host.js +24 -0
- package/cjs/adapter/http/express-adapter.js +12 -45
- package/cjs/adapter/http/helpers/concat-readable.js +20 -0
- package/cjs/adapter/http/helpers/multipart-helper.js +96 -0
- package/cjs/adapter/http/helpers/query-parsers.js +16 -0
- package/cjs/adapter/http/http-adapter-base.js +127 -0
- package/cjs/adapter/http/http-adapter.host.js +57 -0
- package/cjs/adapter/http/http-adapter.js +11 -129
- package/cjs/adapter/http/{impl/http-server-request.js → http-server-request.js} +11 -5
- package/cjs/adapter/http/{impl/http-server-response.js → http-server-response.js} +22 -22
- package/cjs/adapter/http/impl/http-incoming-message.host.js +148 -0
- package/cjs/adapter/http/impl/{http-outgoing-message-host.js → http-outgoing-message.host.js} +26 -38
- package/cjs/adapter/http/request-handlers/entity-request-handler.js +378 -0
- package/cjs/adapter/http/request-handlers/request-handler-base.js +27 -0
- package/cjs/adapter/http/request-handlers/storage-request-handler.js +134 -0
- package/cjs/adapter/operation-context.js +16 -0
- package/cjs/adapter/platform-adapter.host.js +107 -0
- package/cjs/adapter/request.host.js +1 -2
- package/cjs/adapter/request.js +2 -0
- package/cjs/adapter/response.js +2 -0
- package/cjs/adapter/services/logger.js +36 -0
- package/cjs/augmentation/collection.augmentation.js +2 -0
- package/cjs/augmentation/singleton.augmentation.js +2 -0
- package/cjs/augmentation/storage.augmentation.js +2 -0
- package/cjs/index.js +15 -9
- package/esm/adapter/execution-context.host.js +44 -0
- package/esm/adapter/http/express-adapter.host.js +20 -0
- package/esm/adapter/http/express-adapter.js +11 -20
- package/esm/adapter/http/helpers/concat-readable.js +16 -0
- package/esm/adapter/http/helpers/multipart-helper.js +91 -0
- package/esm/adapter/http/helpers/query-parsers.js +12 -0
- package/esm/adapter/http/http-adapter-base.js +123 -0
- package/esm/adapter/http/http-adapter.host.js +52 -0
- package/esm/adapter/http/http-adapter.js +11 -128
- package/esm/adapter/http/{impl/http-server-request.js → http-server-request.js} +12 -6
- package/esm/adapter/http/{impl/http-server-response.js → http-server-response.js} +22 -22
- package/esm/adapter/http/impl/http-incoming-message.host.js +144 -0
- package/esm/adapter/http/impl/{http-outgoing-message-host.js → http-outgoing-message.host.js} +25 -36
- package/esm/adapter/http/request-handlers/entity-request-handler.js +373 -0
- package/esm/adapter/http/request-handlers/request-handler-base.js +23 -0
- package/esm/adapter/http/request-handlers/storage-request-handler.js +129 -0
- package/esm/adapter/operation-context.js +13 -0
- package/esm/adapter/platform-adapter.host.js +102 -0
- package/esm/adapter/request.host.js +1 -2
- package/esm/adapter/request.js +1 -0
- package/esm/adapter/response.js +1 -0
- package/esm/adapter/services/logger.js +32 -0
- package/esm/augmentation/collection.augmentation.js +1 -0
- package/esm/augmentation/singleton.augmentation.js +1 -0
- package/esm/augmentation/storage.augmentation.js +1 -0
- package/esm/index.js +15 -9
- package/i18n/en/error.json +5 -2
- package/package.json +8 -7
- package/types/adapter/execution-context.d.ts +31 -0
- package/types/adapter/execution-context.host.d.ts +27 -0
- package/types/adapter/http/express-adapter.d.ts +12 -8
- package/types/adapter/http/express-adapter.host.d.ts +11 -0
- package/types/adapter/http/helpers/concat-readable.d.ts +3 -0
- package/types/adapter/http/helpers/multipart-helper.d.ts +25 -0
- package/types/adapter/http/helpers/query-parsers.d.ts +1 -0
- package/types/adapter/http/http-adapter-base.d.ts +23 -0
- package/types/adapter/http/http-adapter.d.ts +13 -29
- package/types/adapter/http/http-adapter.host.d.ts +18 -0
- package/types/adapter/http/{impl/http-server-request.d.ts → http-server-request.d.ts} +7 -6
- package/types/adapter/http/{impl/http-server-response.d.ts → http-server-response.d.ts} +2 -2
- package/types/adapter/http/impl/{http-incoming-message-host.d.ts → http-incoming-message.host.d.ts} +16 -12
- package/types/adapter/http/impl/{http-outgoing-message-host.d.ts → http-outgoing-message.host.d.ts} +12 -16
- package/types/adapter/http/request-handlers/entity-request-handler.d.ts +24 -0
- package/types/adapter/http/request-handlers/request-handler-base.d.ts +15 -0
- package/types/adapter/http/request-handlers/storage-request-handler.d.ts +23 -0
- package/types/adapter/interfaces/logger.interface.d.ts +7 -6
- package/types/adapter/interfaces/request-handler.interface.d.ts +4 -0
- package/types/adapter/operation-context.d.ts +11 -0
- package/types/adapter/{adapter.d.ts → platform-adapter.d.ts} +18 -28
- package/types/adapter/platform-adapter.host.d.ts +31 -0
- package/types/adapter/request.d.ts +11 -0
- package/types/adapter/request.host.d.ts +12 -21
- package/types/adapter/{interfaces/response.interface.d.ts → response.d.ts} +2 -2
- package/types/adapter/response.host.d.ts +2 -2
- package/types/adapter/services/logger.d.ts +14 -0
- package/types/augmentation/collection.augmentation.d.ts +112 -0
- package/types/augmentation/singleton.augmentation.d.ts +64 -0
- package/types/augmentation/storage.augmentation.d.ts +39 -0
- package/types/index.d.ts +15 -9
- package/cjs/adapter/adapter.js +0 -118
- package/cjs/adapter/http/impl/http-incoming-message-host.js +0 -127
- package/cjs/adapter/http/request-parsers/parse-collection-request.js +0 -165
- package/cjs/adapter/http/request-parsers/parse-request.js +0 -24
- package/cjs/adapter/http/request-parsers/parse-singleton-request.js +0 -96
- package/cjs/adapter/internal/metadata.resource.js +0 -26
- package/cjs/adapter/request-context.host.js +0 -44
- package/cjs/shared/collection-resource-base.js +0 -20
- package/esm/adapter/adapter.js +0 -113
- package/esm/adapter/http/impl/http-incoming-message-host.js +0 -122
- package/esm/adapter/http/request-parsers/parse-collection-request.js +0 -161
- package/esm/adapter/http/request-parsers/parse-request.js +0 -20
- package/esm/adapter/http/request-parsers/parse-singleton-request.js +0 -92
- package/esm/adapter/internal/metadata.resource.js +0 -23
- package/esm/adapter/request-context.host.js +0 -40
- package/esm/shared/collection-resource-base.js +0 -16
- package/types/adapter/http/request-parsers/parse-collection-request.d.ts +0 -4
- package/types/adapter/http/request-parsers/parse-request.d.ts +0 -4
- package/types/adapter/http/request-parsers/parse-singleton-request.d.ts +0 -4
- package/types/adapter/interfaces/request-context.interface.d.ts +0 -31
- package/types/adapter/interfaces/request.interface.d.ts +0 -15
- package/types/adapter/internal/metadata.resource.d.ts +0 -7
- package/types/adapter/request-context.host.d.ts +0 -22
- package/types/shared/collection-resource-base.d.ts +0 -11
- /package/cjs/adapter/{interfaces/request-context.interface.js → execution-context.js} +0 -0
- /package/cjs/adapter/http/{request-parsers/batch-request-parser.js → request-handlers/parse-batch-request.js} +0 -0
- /package/cjs/adapter/interfaces/{request.interface.js → request-handler.interface.js} +0 -0
- /package/cjs/adapter/{interfaces/response.interface.js → platform-adapter.js} +0 -0
- /package/esm/adapter/{interfaces/request-context.interface.js → execution-context.js} +0 -0
- /package/esm/adapter/http/{request-parsers/batch-request-parser.js → request-handlers/parse-batch-request.js} +0 -0
- /package/esm/adapter/interfaces/{request.interface.js → request-handler.interface.js} +0 -0
- /package/esm/adapter/{interfaces/response.interface.js → platform-adapter.js} +0 -0
- /package/types/adapter/http/{request-parsers/batch-request-parser.d.ts → request-handlers/parse-batch-request.d.ts} +0 -0
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
1
|
import { Options as RangeParserOptions, Ranges as RangeParserRanges, Result as RangeParserResult } from 'range-parser';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
2
|
+
import { OpraURL } from '@opra/common';
|
|
3
|
+
import type { HttpServerResponse } from './http-server-response';
|
|
4
|
+
import { HttpIncomingMessage, HttpIncomingMessageHost } from './impl/http-incoming-message.host.js';
|
|
7
5
|
export declare namespace HttpServerRequest {
|
|
8
|
-
function
|
|
6
|
+
function from(instance: HttpIncomingMessage | HttpIncomingMessageHost.Initiator | string | Iterable<any> | AsyncIterable<any>): HttpServerRequest;
|
|
9
7
|
}
|
|
10
8
|
export interface HttpServerRequest extends HttpIncomingMessage {
|
|
11
9
|
res: HttpServerResponse;
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
originalUrl: string;
|
|
12
|
+
parsedUrl: OpraURL;
|
|
12
13
|
body?: any;
|
|
13
14
|
/**
|
|
14
15
|
* Return the protocol string "http" or "https"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { HttpOutgoingMessage, HttpOutgoingMessageHost } from './http-outgoing-message-host.js';
|
|
2
1
|
import type { HttpServerRequest } from './http-server-request.js';
|
|
2
|
+
import { HttpOutgoingMessage, HttpOutgoingMessageHost } from './impl/http-outgoing-message.host.js';
|
|
3
3
|
export declare namespace HttpServerResponse {
|
|
4
|
-
function
|
|
4
|
+
function from(instance?: HttpOutgoingMessage | HttpOutgoingMessageHost.Initiator): HttpServerResponse;
|
|
5
5
|
}
|
|
6
6
|
export interface HttpServerResponse extends HttpOutgoingMessage {
|
|
7
7
|
req?: HttpServerRequest;
|
package/types/adapter/http/impl/{http-incoming-message-host.d.ts → http-incoming-message.host.d.ts}
RENAMED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
/// <reference types="node" />
|
|
5
5
|
import http, { IncomingHttpHeaders } from 'http';
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
6
|
+
import { Duplex, Readable } from 'stream';
|
|
7
|
+
import { HTTPParserJS } from '@browsery/http-parser';
|
|
8
8
|
export declare const CRLF: Buffer;
|
|
9
9
|
export declare const kHeaders: unique symbol;
|
|
10
10
|
export declare const kHeadersDistinct: unique symbol;
|
|
11
11
|
export declare const kTrailers: unique symbol;
|
|
12
12
|
export declare const kTrailersDistinct: unique symbol;
|
|
13
|
-
export interface HttpIncomingMessage extends Pick<http.IncomingMessage, 'httpVersion' | 'httpVersionMajor' | 'httpVersionMinor' | 'complete' | 'headers' | 'trailers' | 'rawHeaders' | 'rawTrailers' | 'method' | 'url'>,
|
|
13
|
+
export interface HttpIncomingMessage extends Pick<http.IncomingMessage, 'httpVersion' | 'httpVersionMajor' | 'httpVersionMinor' | 'complete' | 'headers' | 'trailers' | 'rawHeaders' | 'rawTrailers' | 'method' | 'url'>, Readable {
|
|
14
14
|
}
|
|
15
15
|
export declare namespace HttpIncomingMessageHost {
|
|
16
16
|
interface Initiator {
|
|
@@ -25,25 +25,29 @@ export declare namespace HttpIncomingMessageHost {
|
|
|
25
25
|
ips?: string[];
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
export interface HttpIncomingMessageHost extends stream.Readable {
|
|
29
|
-
}
|
|
30
28
|
/**
|
|
31
29
|
*
|
|
32
30
|
* @class HttpIncomingMessageHost
|
|
33
31
|
*/
|
|
34
|
-
export declare class HttpIncomingMessageHost implements HttpIncomingMessage {
|
|
32
|
+
export declare class HttpIncomingMessageHost extends Duplex implements HttpIncomingMessage {
|
|
33
|
+
protected [kHeaders]?: IncomingHttpHeaders;
|
|
34
|
+
protected [kHeadersDistinct]?: NodeJS.Dict<string[]>;
|
|
35
|
+
protected [kTrailers]?: NodeJS.Dict<string>;
|
|
36
|
+
protected [kTrailersDistinct]?: NodeJS.Dict<string[]>;
|
|
37
|
+
protected _httpParser: HTTPParserJS | undefined;
|
|
38
|
+
protected _readStream?: Readable;
|
|
35
39
|
httpVersionMajor: number;
|
|
36
40
|
httpVersionMinor: number;
|
|
37
41
|
method: string;
|
|
38
42
|
url: string;
|
|
39
43
|
rawHeaders: string[];
|
|
40
44
|
rawTrailers: string[];
|
|
41
|
-
body?:
|
|
45
|
+
body?: Buffer;
|
|
42
46
|
complete: boolean;
|
|
43
47
|
ip?: string;
|
|
44
48
|
ips?: string[];
|
|
45
49
|
joinDuplicateHeaders: boolean;
|
|
46
|
-
constructor();
|
|
50
|
+
constructor(init?: HttpIncomingMessageHost.Initiator);
|
|
47
51
|
get httpVersion(): string;
|
|
48
52
|
get headers(): IncomingHttpHeaders;
|
|
49
53
|
set headers(headers: IncomingHttpHeaders);
|
|
@@ -51,8 +55,8 @@ export declare class HttpIncomingMessageHost implements HttpIncomingMessage {
|
|
|
51
55
|
get trailers(): NodeJS.Dict<string>;
|
|
52
56
|
set trailers(trailers: NodeJS.Dict<string>);
|
|
53
57
|
get trailersDistinct(): NodeJS.Dict<string[]>;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
static
|
|
58
|
+
_read(size: number): void;
|
|
59
|
+
_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>;
|
|
58
62
|
}
|
package/types/adapter/http/impl/{http-outgoing-message-host.d.ts → http-outgoing-message.host.d.ts}
RENAMED
|
@@ -2,18 +2,17 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
import http, { OutgoingHttpHeaders } from 'http';
|
|
5
|
-
import
|
|
6
|
-
import type { HttpIncomingMessage } from './http-incoming-message
|
|
5
|
+
import { Duplex, Writable } from 'stream';
|
|
6
|
+
import type { HttpIncomingMessage } from './http-incoming-message.host';
|
|
7
7
|
export declare const kOutHeaders: unique symbol;
|
|
8
8
|
export declare const kOutTrailers: unique symbol;
|
|
9
|
-
export declare const kErrored: unique symbol;
|
|
10
9
|
declare global {
|
|
11
10
|
interface Headers {
|
|
12
11
|
keys(): IterableIterator<string>;
|
|
13
12
|
entries(): IterableIterator<[string, any]>;
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
|
-
export interface HttpOutgoingMessage extends Pick<http.ServerResponse, 'addTrailers' | 'getHeader' | 'getHeaders' | 'getHeaderNames' | 'removeHeader' | 'hasHeader' | 'headersSent' | 'statusCode' | 'statusMessage' | 'sendDate'>,
|
|
15
|
+
export interface HttpOutgoingMessage extends Pick<http.ServerResponse, 'addTrailers' | 'getHeader' | 'getHeaders' | 'getHeaderNames' | 'removeHeader' | 'hasHeader' | 'headersSent' | 'statusCode' | 'statusMessage' | 'sendDate'>, Writable {
|
|
17
16
|
req?: HttpIncomingMessage;
|
|
18
17
|
appendHeader(name: string, value: string | readonly string[]): this;
|
|
19
18
|
setHeader(name: string, value: number | string | readonly string[]): this;
|
|
@@ -27,21 +26,19 @@ export declare namespace HttpOutgoingMessageHost {
|
|
|
27
26
|
chunkedEncoding?: boolean;
|
|
28
27
|
sendDate?: boolean;
|
|
29
28
|
strictContentLength?: boolean;
|
|
30
|
-
body?: any;
|
|
29
|
+
body?: string | Iterable<any> | AsyncIterable<any> | Object;
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
|
-
export interface HttpOutgoingMessageHost extends stream.Writable {
|
|
34
|
-
}
|
|
35
32
|
/**
|
|
36
33
|
*
|
|
37
34
|
* @class HttpOutgoingMessageHost
|
|
38
35
|
*/
|
|
39
|
-
export declare class HttpOutgoingMessageHost {
|
|
40
|
-
protected _headersSent: boolean;
|
|
41
|
-
protected _closed: boolean;
|
|
42
|
-
protected [kErrored]: Error | null;
|
|
36
|
+
export declare class HttpOutgoingMessageHost extends Duplex implements HttpOutgoingMessage {
|
|
43
37
|
protected [kOutHeaders]: Record<string, any>;
|
|
44
38
|
protected [kOutTrailers]: Record<string, any>;
|
|
39
|
+
protected _headersSent: boolean;
|
|
40
|
+
protected _httpVersionMajor?: number;
|
|
41
|
+
protected _httpVersionMinor?: number;
|
|
45
42
|
finished: boolean;
|
|
46
43
|
req?: HttpIncomingMessage;
|
|
47
44
|
statusCode: number;
|
|
@@ -50,10 +47,10 @@ export declare class HttpOutgoingMessageHost {
|
|
|
50
47
|
sendDate: boolean;
|
|
51
48
|
strictContentLength: boolean;
|
|
52
49
|
body?: any;
|
|
53
|
-
constructor();
|
|
50
|
+
constructor(init?: HttpOutgoingMessageHost.Initiator);
|
|
51
|
+
get httpVersionMajor(): number | undefined;
|
|
52
|
+
get httpVersionMinor(): number | undefined;
|
|
54
53
|
get headersSent(): boolean;
|
|
55
|
-
get closed(): boolean;
|
|
56
|
-
get errored(): Error | null;
|
|
57
54
|
appendHeader(name: string, value: number | string | readonly string[]): this;
|
|
58
55
|
addTrailers(headers: OutgoingHttpHeaders | [string, string][] | readonly [string, string][]): void;
|
|
59
56
|
setHeader(name: any, value: any): this;
|
|
@@ -67,6 +64,5 @@ export declare class HttpOutgoingMessageHost {
|
|
|
67
64
|
end(cb?: () => void): this;
|
|
68
65
|
end(chunk: any, cb?: () => void): this;
|
|
69
66
|
end(chunk: any, encoding: BufferEncoding, cb?: () => void): this;
|
|
70
|
-
|
|
71
|
-
static create(init?: HttpOutgoingMessageHost.Initiator): HttpOutgoingMessageHost;
|
|
67
|
+
static from(init: HttpOutgoingMessageHost.Initiator): HttpOutgoingMessageHost;
|
|
72
68
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Collection, OpraSchema, Singleton } from '@opra/common';
|
|
2
|
+
import { ExecutionContext } from '../../execution-context.js';
|
|
3
|
+
import { OperationContext } from '../../operation-context.js';
|
|
4
|
+
import { Request } from '../../request.js';
|
|
5
|
+
import type { HttpAdapterBase } from '../http-adapter-base.js';
|
|
6
|
+
import { HttpServerRequest } from '../http-server-request.js';
|
|
7
|
+
import { RequestHandlerBase } from './request-handler-base.js';
|
|
8
|
+
type BodyLoaderFunction = (incoming: HttpServerRequest) => Promise<any>;
|
|
9
|
+
/**
|
|
10
|
+
* @class EntityRequestHandler
|
|
11
|
+
*/
|
|
12
|
+
export declare class EntityRequestHandler extends RequestHandlerBase {
|
|
13
|
+
readonly adapter: HttpAdapterBase;
|
|
14
|
+
readonly bodyLoaders: WeakMap<Object, BodyLoaderFunction>;
|
|
15
|
+
constructor(adapter: HttpAdapterBase);
|
|
16
|
+
processRequest(executionContext: ExecutionContext): Promise<void>;
|
|
17
|
+
parseRequest(incoming: HttpServerRequest): Promise<Request | undefined>;
|
|
18
|
+
executeOperation(context: OperationContext): Promise<void>;
|
|
19
|
+
sendResponse(context: OperationContext): Promise<void>;
|
|
20
|
+
parseCollectionRequest(resource: Collection, incoming: HttpServerRequest): Promise<Request>;
|
|
21
|
+
parseSingletonRequest(resource: Singleton, incoming: HttpServerRequest): Promise<Request>;
|
|
22
|
+
getBodyLoader(operation: OpraSchema.Collection.CreateOperation | OpraSchema.Collection.UpdateOperation | OpraSchema.Collection.UpdateManyOperation): BodyLoaderFunction;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { OpraSchema, Resource } from '@opra/common';
|
|
2
|
+
import type { ExecutionContext } from '../../execution-context';
|
|
3
|
+
import type { RequestHandler } from '../../interfaces/request-handler.interface';
|
|
4
|
+
import type { HttpAdapterBase } from '../http-adapter-base';
|
|
5
|
+
/**
|
|
6
|
+
* @class RequestHandlerBase
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class RequestHandlerBase implements RequestHandler {
|
|
9
|
+
readonly adapter: HttpAdapterBase;
|
|
10
|
+
protected constructor(adapter: HttpAdapterBase);
|
|
11
|
+
abstract processRequest(executionContext: ExecutionContext): Promise<void>;
|
|
12
|
+
assertOperation<T extends OpraSchema.Operation = OpraSchema.Operation>(resource: Resource, operation: string): Promise<T & {
|
|
13
|
+
controller: any;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ExecutionContext } from '../../execution-context';
|
|
2
|
+
import { OperationContext } from '../../operation-context.js';
|
|
3
|
+
import { Request } from '../../request.js';
|
|
4
|
+
import type { HttpAdapterBase } from '../http-adapter-base.js';
|
|
5
|
+
import { HttpServerRequest } from '../http-server-request.js';
|
|
6
|
+
import { RequestHandlerBase } from './request-handler-base.js';
|
|
7
|
+
export declare namespace StorageRequestHandler {
|
|
8
|
+
interface Options {
|
|
9
|
+
uploadDir?: string;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* @class StorageRequestHandler
|
|
14
|
+
*/
|
|
15
|
+
export declare class StorageRequestHandler extends RequestHandlerBase {
|
|
16
|
+
readonly adapter: HttpAdapterBase;
|
|
17
|
+
_uploadDir: string;
|
|
18
|
+
constructor(adapter: HttpAdapterBase, options?: StorageRequestHandler.Options);
|
|
19
|
+
processRequest(executionContext: ExecutionContext): Promise<void>;
|
|
20
|
+
parseRequest(executionContext: ExecutionContext, incoming: HttpServerRequest): Promise<Request | undefined>;
|
|
21
|
+
executeOperation(context: OperationContext): Promise<void>;
|
|
22
|
+
sendResponse(context: OperationContext): Promise<void>;
|
|
23
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export interface ILogger {
|
|
2
|
-
log(message: any, ...optionalParams: any[]):
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
log?(message: any, ...optionalParams: any[]): void;
|
|
3
|
+
info?(message: any, ...optionalParams: any[]): void;
|
|
4
|
+
warn?(message: any, ...optionalParams: any[]): void;
|
|
5
|
+
error?(message: any, ...optionalParams: any[]): void;
|
|
6
|
+
fatal?(message: any, ...optionalParams: any[]): void;
|
|
7
|
+
debug?(message: any, ...optionalParams: any[]): void;
|
|
8
|
+
verbose?(message: any, ...optionalParams: any[]): void;
|
|
8
9
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ExecutionContext } from './execution-context';
|
|
2
|
+
import type { Request } from './request';
|
|
3
|
+
import type { Response } from './response';
|
|
4
|
+
export interface OperationContext<TRequest extends Request = Request, TResponse extends Response = Response> extends ExecutionContext {
|
|
5
|
+
request: TRequest;
|
|
6
|
+
response: TResponse;
|
|
7
|
+
requestScope: Record<string | number | symbol, any>;
|
|
8
|
+
}
|
|
9
|
+
export declare namespace OperationContext {
|
|
10
|
+
function from<TRequest extends Request = Request, TResponse extends Response = Response>(executionContext: ExecutionContext, request: TRequest, response: TResponse): OperationContext;
|
|
11
|
+
}
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ApiDocument, FallbackLng, I18n, LanguageResource } from '@opra/common';
|
|
1
|
+
import { FallbackLng, I18n, LanguageResource } from '@opra/common';
|
|
3
2
|
import { ILogger } from './interfaces/logger.interface.js';
|
|
4
|
-
import {
|
|
3
|
+
import { RequestHandler } from './interfaces/request-handler.interface.js';
|
|
4
|
+
import { OperationContext } from './operation-context.js';
|
|
5
|
+
export type Protocol = 'http' | 'ws' | 'rpc';
|
|
6
|
+
export interface PlatformAdapter extends RequestHandler {
|
|
7
|
+
readonly protocol: Protocol;
|
|
8
|
+
readonly platform: string;
|
|
9
|
+
readonly serviceName: string;
|
|
10
|
+
/**
|
|
11
|
+
* Calls shutDown hook for all resources
|
|
12
|
+
*/
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
}
|
|
5
15
|
/**
|
|
6
|
-
* @namespace
|
|
16
|
+
* @namespace PlatformAdapter
|
|
7
17
|
*/
|
|
8
|
-
export declare namespace
|
|
18
|
+
export declare namespace PlatformAdapter {
|
|
9
19
|
interface Options {
|
|
10
20
|
i18n?: I18n | I18nOptions | (() => Promise<I18n>);
|
|
11
21
|
logger?: ILogger;
|
|
12
|
-
|
|
22
|
+
on?: {
|
|
23
|
+
request?: (ctx: OperationContext) => void | Promise<void>;
|
|
24
|
+
};
|
|
13
25
|
}
|
|
14
26
|
interface I18nOptions {
|
|
15
27
|
/**
|
|
@@ -39,25 +51,3 @@ export declare namespace OpraAdapter {
|
|
|
39
51
|
resourceDirs?: string[];
|
|
40
52
|
}
|
|
41
53
|
}
|
|
42
|
-
/**
|
|
43
|
-
* @class OpraAdapter
|
|
44
|
-
*/
|
|
45
|
-
export declare abstract class OpraAdapter extends AsyncEventEmitter {
|
|
46
|
-
readonly api: ApiDocument;
|
|
47
|
-
protected _apiRoot: ApiDocument;
|
|
48
|
-
i18n: I18n;
|
|
49
|
-
logger?: ILogger;
|
|
50
|
-
protected constructor(api: ApiDocument);
|
|
51
|
-
/**
|
|
52
|
-
* Initializes the adapter
|
|
53
|
-
* @param options
|
|
54
|
-
* @protected
|
|
55
|
-
*/
|
|
56
|
-
protected init(options?: OpraAdapter.Options): Promise<void>;
|
|
57
|
-
/**
|
|
58
|
-
* Calls shutDown hook for all resources
|
|
59
|
-
*/
|
|
60
|
-
close(): Promise<void>;
|
|
61
|
-
protected executeRequest(context: RequestContext): Promise<void>;
|
|
62
|
-
protected _createI18n(options?: OpraAdapter.I18nOptions): Promise<I18n>;
|
|
63
|
-
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
2
|
+
import { ApiDocument, I18n, Resource } from '@opra/common';
|
|
3
|
+
import { ExecutionContext } from './execution-context.js';
|
|
4
|
+
import type { PlatformAdapter, Protocol } from './platform-adapter';
|
|
5
|
+
import { Logger } from './services/logger.js';
|
|
6
|
+
/**
|
|
7
|
+
* @class PlatformAdapterHost
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class PlatformAdapterHost extends AsyncEventEmitter implements PlatformAdapter {
|
|
10
|
+
readonly api: ApiDocument;
|
|
11
|
+
_controllers: WeakMap<Resource, any>;
|
|
12
|
+
_protocol: Protocol;
|
|
13
|
+
_platform: string;
|
|
14
|
+
_initialized: boolean;
|
|
15
|
+
_serviceName: string;
|
|
16
|
+
_options: PlatformAdapter.Options;
|
|
17
|
+
_i18n: I18n;
|
|
18
|
+
_logger: Logger;
|
|
19
|
+
protected constructor(api: ApiDocument, options?: PlatformAdapter.Options);
|
|
20
|
+
get platform(): string;
|
|
21
|
+
get protocol(): Protocol;
|
|
22
|
+
get serviceName(): string;
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Initializes the adapter
|
|
26
|
+
*/
|
|
27
|
+
init(): Promise<void>;
|
|
28
|
+
getController(resource: Resource | string): Promise<any>;
|
|
29
|
+
protected _createI18n(options?: PlatformAdapter.I18nOptions): Promise<I18n>;
|
|
30
|
+
abstract processRequest(executionContext: ExecutionContext): Promise<void>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Resource } from '@opra/common';
|
|
2
|
+
import { HttpServerRequest } from './http/http-server-request.js';
|
|
3
|
+
export interface Request {
|
|
4
|
+
resource: Resource;
|
|
5
|
+
operation: string;
|
|
6
|
+
contentId?: string;
|
|
7
|
+
params?: Record<string, any>;
|
|
8
|
+
switchToHttp(): HttpServerRequest;
|
|
9
|
+
switchToWs(): never;
|
|
10
|
+
switchToRpc(): never;
|
|
11
|
+
}
|
|
@@ -1,29 +1,20 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import type { Request } from './interfaces/request.interface.js';
|
|
1
|
+
import type { StrictOmit } from 'ts-gems';
|
|
2
|
+
import type { HttpServerRequest } from './http/http-server-request.js';
|
|
3
|
+
import type { Request } from './request';
|
|
5
4
|
export declare namespace RequestHost {
|
|
6
|
-
interface Initiator {
|
|
7
|
-
|
|
8
|
-
kind: string;
|
|
9
|
-
resource: Resource;
|
|
10
|
-
operation: string;
|
|
11
|
-
crud: 'create' | 'read' | 'update' | 'delete';
|
|
12
|
-
many: boolean;
|
|
13
|
-
args: any;
|
|
5
|
+
interface Initiator extends StrictOmit<Request, 'switchToHttp' | 'switchToWs' | 'switchToRpc'> {
|
|
6
|
+
controller: any;
|
|
14
7
|
http?: HttpServerRequest;
|
|
8
|
+
[key: string]: any;
|
|
15
9
|
}
|
|
16
10
|
}
|
|
11
|
+
export interface RequestHost extends Request {
|
|
12
|
+
}
|
|
17
13
|
export declare class RequestHost implements Request {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
readonly operation: string;
|
|
23
|
-
readonly crud: 'create' | 'read' | 'update' | 'delete';
|
|
24
|
-
readonly many: boolean;
|
|
25
|
-
readonly args: any;
|
|
26
|
-
readonly http?: HttpServerRequest;
|
|
14
|
+
controller: any;
|
|
15
|
+
http?: HttpServerRequest;
|
|
16
|
+
key?: any;
|
|
17
|
+
params: Record<string, any>;
|
|
27
18
|
constructor(init: RequestHost.Initiator);
|
|
28
19
|
switchToHttp(): HttpServerRequest;
|
|
29
20
|
switchToWs(): never;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HttpServerResponse } from '
|
|
1
|
+
import type { HttpServerResponse } from './http/http-server-response';
|
|
2
2
|
export interface Response {
|
|
3
3
|
/**
|
|
4
4
|
* Result value
|
|
@@ -7,7 +7,7 @@ export interface Response {
|
|
|
7
7
|
/**
|
|
8
8
|
* List of errors
|
|
9
9
|
*/
|
|
10
|
-
errors:
|
|
10
|
+
errors: any[];
|
|
11
11
|
/**
|
|
12
12
|
*
|
|
13
13
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HttpServerResponse } from './http/
|
|
2
|
-
import { Response } from './
|
|
1
|
+
import type { HttpServerResponse } from './http/http-server-response';
|
|
2
|
+
import type { Response } from './response';
|
|
3
3
|
export declare namespace ResponseHost {
|
|
4
4
|
interface Initiator {
|
|
5
5
|
value?: any;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ILogger } from '../interfaces/logger.interface.js';
|
|
2
|
+
export interface LoggerOptions {
|
|
3
|
+
instance?: ILogger;
|
|
4
|
+
}
|
|
5
|
+
export declare class Logger implements ILogger {
|
|
6
|
+
protected _instance: ILogger;
|
|
7
|
+
constructor(options?: LoggerOptions);
|
|
8
|
+
info(message: any, ...optionalParams: any[]): void;
|
|
9
|
+
error(message: any, ...optionalParams: any[]): void;
|
|
10
|
+
fatal(message: any, ...optionalParams: any[]): void;
|
|
11
|
+
warn(message: any, ...optionalParams: any[]): void;
|
|
12
|
+
debug(message: any, ...optionalParams: any[]): void;
|
|
13
|
+
verbose(message: any, ...optionalParams: any[]): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { PartialOutput } from '@opra/common';
|
|
2
|
+
import type { OperationContext } from '../adapter/operation-context.js';
|
|
3
|
+
import type { Request as _Request } from '../adapter/request.js';
|
|
4
|
+
declare module "@opra/common" {
|
|
5
|
+
namespace Collection {
|
|
6
|
+
namespace Create {
|
|
7
|
+
interface Request extends _Request {
|
|
8
|
+
operation: 'create';
|
|
9
|
+
data: any;
|
|
10
|
+
params: {
|
|
11
|
+
pick?: string[];
|
|
12
|
+
omit?: string[];
|
|
13
|
+
include?: string[];
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
interface Context extends OperationContext {
|
|
17
|
+
request: Request;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
namespace Delete {
|
|
21
|
+
interface Request extends _Request {
|
|
22
|
+
operation: 'delete';
|
|
23
|
+
key: any;
|
|
24
|
+
}
|
|
25
|
+
interface Context extends OperationContext {
|
|
26
|
+
request: Request;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
namespace DeleteMany {
|
|
30
|
+
interface Request extends _Request {
|
|
31
|
+
operation: 'deleteMany';
|
|
32
|
+
params: {
|
|
33
|
+
filter?: any;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
interface Context extends OperationContext {
|
|
37
|
+
request: Request;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
namespace FindMany {
|
|
41
|
+
interface Request extends _Request {
|
|
42
|
+
operation: 'findMany';
|
|
43
|
+
params: {
|
|
44
|
+
filter?: any;
|
|
45
|
+
pick?: string[];
|
|
46
|
+
omit?: string[];
|
|
47
|
+
include?: string[];
|
|
48
|
+
sort?: string[];
|
|
49
|
+
limit?: number;
|
|
50
|
+
skip?: number;
|
|
51
|
+
distinct?: boolean;
|
|
52
|
+
count?: boolean;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
interface Context extends OperationContext {
|
|
56
|
+
request: Request;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
namespace Get {
|
|
60
|
+
interface Request extends _Request {
|
|
61
|
+
operation: 'get';
|
|
62
|
+
key: any;
|
|
63
|
+
params: {
|
|
64
|
+
pick?: string[];
|
|
65
|
+
omit?: string[];
|
|
66
|
+
include?: string[];
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
interface Context extends OperationContext {
|
|
70
|
+
request: Request;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
namespace Update {
|
|
74
|
+
interface Request extends _Request {
|
|
75
|
+
operation: 'update';
|
|
76
|
+
key: any;
|
|
77
|
+
data: any;
|
|
78
|
+
params: {
|
|
79
|
+
pick?: string[];
|
|
80
|
+
omit?: string[];
|
|
81
|
+
include?: string[];
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
interface Context extends OperationContext {
|
|
85
|
+
request: Request;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
namespace UpdateMany {
|
|
89
|
+
interface Request extends _Request {
|
|
90
|
+
operation: 'updateMany';
|
|
91
|
+
data: any;
|
|
92
|
+
params: {
|
|
93
|
+
filter?: any;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
interface Context extends OperationContext {
|
|
97
|
+
request: Request;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
interface CollectionResource<T> {
|
|
102
|
+
create?(context: Collection.Create.Context): Promise<PartialOutput<T>>;
|
|
103
|
+
delete?(context: Collection.Delete.Context): Promise<number> | undefined;
|
|
104
|
+
deleteMany?(context: Collection.DeleteMany.Context): Promise<number> | undefined;
|
|
105
|
+
findMany?(context: Collection.FindMany.Context): Promise<PartialOutput<T>[] | undefined>;
|
|
106
|
+
get?(context: Collection.Get.Context): Promise<PartialOutput<T> | undefined>;
|
|
107
|
+
update?(context: Collection.Update.Context): Promise<PartialOutput<T> | undefined>;
|
|
108
|
+
updateMany?(context: Collection.UpdateMany.Context): Promise<number> | undefined;
|
|
109
|
+
onInit?(): Promise<void>;
|
|
110
|
+
onShutdown?(): Promise<void>;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { PartialOutput } from '@opra/common';
|
|
2
|
+
import type { OperationContext } from '../adapter/operation-context.js';
|
|
3
|
+
import type { Request as _Request } from '../adapter/request.js';
|
|
4
|
+
declare module "@opra/common" {
|
|
5
|
+
namespace Singleton {
|
|
6
|
+
namespace Create {
|
|
7
|
+
interface Request extends _Request {
|
|
8
|
+
operation: 'create';
|
|
9
|
+
data: any;
|
|
10
|
+
params: {
|
|
11
|
+
pick?: string[];
|
|
12
|
+
omit?: string[];
|
|
13
|
+
include?: string[];
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
interface Context extends OperationContext {
|
|
17
|
+
request: Request;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
namespace Delete {
|
|
21
|
+
interface Request extends _Request {
|
|
22
|
+
operation: 'delete';
|
|
23
|
+
}
|
|
24
|
+
interface Context extends OperationContext {
|
|
25
|
+
request: Request;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
namespace Get {
|
|
29
|
+
interface Request extends _Request {
|
|
30
|
+
operation: 'get';
|
|
31
|
+
params: {
|
|
32
|
+
pick?: string[];
|
|
33
|
+
omit?: string[];
|
|
34
|
+
include?: string[];
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
interface Context extends OperationContext {
|
|
38
|
+
request: Request;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
namespace Update {
|
|
42
|
+
interface Request extends _Request {
|
|
43
|
+
operation: 'update';
|
|
44
|
+
data: any;
|
|
45
|
+
params: {
|
|
46
|
+
pick?: string[];
|
|
47
|
+
omit?: string[];
|
|
48
|
+
include?: string[];
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
interface Context extends OperationContext {
|
|
52
|
+
request: Request;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
interface SingletonResource<T> {
|
|
57
|
+
create?(context: Singleton.Create.Context): Promise<PartialOutput<T>>;
|
|
58
|
+
delete?(context: Singleton.Delete.Context): Promise<number> | undefined;
|
|
59
|
+
get?(context: Singleton.Get.Context): Promise<PartialOutput<T> | undefined>;
|
|
60
|
+
update?(context: Singleton.Update.Context): Promise<PartialOutput<T> | undefined>;
|
|
61
|
+
onInit?(): Promise<void>;
|
|
62
|
+
onShutdown?(): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
}
|