@opra/core 0.22.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 -133
- 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} +4 -4
- 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 -132
- 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} +4 -4
- 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 +3 -2
- 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
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export class Logger {
|
|
2
|
+
constructor(options = {}) {
|
|
3
|
+
this._instance = options.instance ||
|
|
4
|
+
(!(process.env.NODE_ENV || '').includes('test') ? globalThis.console : {});
|
|
5
|
+
}
|
|
6
|
+
info(message, ...optionalParams) {
|
|
7
|
+
(this._instance.info || this._instance.log)?.(message, ...optionalParams);
|
|
8
|
+
}
|
|
9
|
+
error(message, ...optionalParams) {
|
|
10
|
+
if (this._instance.error) {
|
|
11
|
+
this._instance.error(message, ...optionalParams);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
this.info(message, ...optionalParams);
|
|
15
|
+
}
|
|
16
|
+
fatal(message, ...optionalParams) {
|
|
17
|
+
if (this._instance.fatal) {
|
|
18
|
+
this._instance.fatal(message, ...optionalParams);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
this.error(message, ...optionalParams);
|
|
22
|
+
}
|
|
23
|
+
warn(message, ...optionalParams) {
|
|
24
|
+
this._instance.warn?.(message, ...optionalParams);
|
|
25
|
+
}
|
|
26
|
+
debug(message, ...optionalParams) {
|
|
27
|
+
this._instance.debug?.(message, ...optionalParams);
|
|
28
|
+
}
|
|
29
|
+
verbose(message, ...optionalParams) {
|
|
30
|
+
this._instance.verbose?.(message, ...optionalParams);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/index.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import './augmentation/resource.augmentation.js';
|
|
3
|
+
import './augmentation/collection.augmentation.js';
|
|
4
|
+
import './augmentation/singleton.augmentation.js';
|
|
5
|
+
import './augmentation/storage.augmentation.js';
|
|
3
6
|
export * from './types.js';
|
|
4
|
-
export * from './adapter/
|
|
7
|
+
export * from './adapter/execution-context.js';
|
|
8
|
+
export * from './adapter/operation-context.js';
|
|
9
|
+
export * from './adapter/platform-adapter.js';
|
|
10
|
+
export * from './adapter/request.js';
|
|
11
|
+
export * from './adapter/response.js';
|
|
5
12
|
export * from './adapter/http/express-adapter.js';
|
|
6
13
|
export * from './adapter/http/http-adapter.js';
|
|
7
|
-
export * from './adapter/http/impl/http-
|
|
8
|
-
export * from './adapter/http/impl/http-
|
|
9
|
-
export * from './adapter/http/
|
|
10
|
-
export * from './adapter/http/
|
|
11
|
-
export * from './adapter/interfaces/request-context.interface.js';
|
|
14
|
+
export * from './adapter/http/impl/http-incoming-message.host.js';
|
|
15
|
+
export * from './adapter/http/impl/http-outgoing-message.host.js';
|
|
16
|
+
export * from './adapter/http/http-server-request.js';
|
|
17
|
+
export * from './adapter/http/http-server-response.js';
|
|
12
18
|
export * from './adapter/interfaces/logger.interface.js';
|
|
13
|
-
export * from './adapter/interfaces/request.interface.js';
|
|
14
|
-
export * from './adapter/
|
|
15
|
-
export * from './
|
|
19
|
+
export * from './adapter/interfaces/request-handler.interface.js';
|
|
20
|
+
export * from './adapter/services/logger.js';
|
|
21
|
+
export * from './adapter/http/helpers/multipart-helper.js';
|
package/i18n/en/error.json
CHANGED
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
"UNPROCESSABLE_ENTITY": "Unprocessable entity",
|
|
11
11
|
"RESOURCE_NOT_FOUND": "Resource not found: '{{resource}}'",
|
|
12
12
|
"RESOURCE_CONFLICT": "There is already an other {{resource}} resource with same field values ({{fields}})",
|
|
13
|
-
"RESOLVER_FORBIDDEN": "The resource endpoint does not accept '{{operation}}' operations",
|
|
14
|
-
"
|
|
13
|
+
"RESOLVER_FORBIDDEN": "The {{resource}} endpoint does not accept '{{operation}}' operations",
|
|
14
|
+
"UNKNOWN_FIELD": "Unknown field '{{field}}'",
|
|
15
|
+
"UNACCEPTED_SORT_FIELD": "Field '{{field}}' is not available for sort operation",
|
|
16
|
+
"UNACCEPTED_FILTER_FIELD": "Field '{{field}}' is not available for filter operation",
|
|
17
|
+
"UNACCEPTED_FILTER_OPERATION": "'{{operation}}' for field '{{field}}' is not available for filter operation"
|
|
15
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Opra schema package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"clean:cover": "rimraf ../../coverage/core"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@opra/common": "^0.
|
|
30
|
+
"@opra/common": "^0.23.0",
|
|
31
31
|
"accepts": "^1.3.8",
|
|
32
32
|
"content-disposition": "^0.5.4",
|
|
33
33
|
"content-type": "^1.0.5",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"mime-types": "^2.1.35",
|
|
40
40
|
"power-tasks": "^1.7.0",
|
|
41
41
|
"putil-varhelpers": "^1.6.5",
|
|
42
|
+
"putil-isplainobject": "^1.1.5",
|
|
42
43
|
"range-parser": "^1.2.1",
|
|
43
44
|
"strict-typed-events": "^2.3.1",
|
|
44
45
|
"type-is": "^1.6.18",
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { HttpServerRequest } from './http/http-server-request';
|
|
2
|
+
import type { HttpServerResponse } from './http/http-server-response';
|
|
3
|
+
import type { Protocol } from './platform-adapter';
|
|
4
|
+
export declare namespace ExecutionContext {
|
|
5
|
+
type OnFinishArgs = {
|
|
6
|
+
context: ExecutionContext;
|
|
7
|
+
failed: boolean;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface ExecutionContext {
|
|
11
|
+
readonly protocol: Protocol;
|
|
12
|
+
readonly platform: string;
|
|
13
|
+
errors: Error[];
|
|
14
|
+
executionScope: Record<string | number | symbol, any>;
|
|
15
|
+
switchToHttp(): HttpMessageContext;
|
|
16
|
+
switchToWs(): WsMessageContext;
|
|
17
|
+
switchToRpc(): RpcMessageContext;
|
|
18
|
+
on(event: 'finish', fn: (args: ExecutionContext.OnFinishArgs) => void | Promise<void>): any;
|
|
19
|
+
}
|
|
20
|
+
export interface HttpMessageContext {
|
|
21
|
+
readonly platform: string;
|
|
22
|
+
readonly incoming: HttpServerRequest;
|
|
23
|
+
readonly outgoing: HttpServerResponse;
|
|
24
|
+
switchToContext(): ExecutionContext;
|
|
25
|
+
}
|
|
26
|
+
export interface WsMessageContext {
|
|
27
|
+
switchToContext(): ExecutionContext;
|
|
28
|
+
}
|
|
29
|
+
export interface RpcMessageContext {
|
|
30
|
+
switchToContext(): ExecutionContext;
|
|
31
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
2
|
+
import type { ApiDocument } from '@opra/common';
|
|
3
|
+
import type { HttpServerResponse } from './/http/http-server-response.js';
|
|
4
|
+
import type { ExecutionContext, HttpMessageContext, RpcMessageContext, WsMessageContext } from './execution-context.js';
|
|
5
|
+
import type { HttpServerRequest } from './http/http-server-request.js';
|
|
6
|
+
import { Protocol } from './platform-adapter.js';
|
|
7
|
+
export declare class ExecutionContextHost extends AsyncEventEmitter implements ExecutionContext {
|
|
8
|
+
readonly api: ApiDocument;
|
|
9
|
+
readonly platform: string;
|
|
10
|
+
readonly protocol: Protocol;
|
|
11
|
+
readonly http?: HttpMessageContext;
|
|
12
|
+
readonly ws?: WsMessageContext;
|
|
13
|
+
readonly rpc?: RpcMessageContext;
|
|
14
|
+
errors: Error[];
|
|
15
|
+
executionScope: Record<string | number | symbol, any>;
|
|
16
|
+
constructor(api: ApiDocument, platform: string, protocol: {
|
|
17
|
+
http?: {
|
|
18
|
+
incoming: HttpServerRequest;
|
|
19
|
+
outgoing: HttpServerResponse;
|
|
20
|
+
};
|
|
21
|
+
ws?: WsMessageContext;
|
|
22
|
+
rpc?: RpcMessageContext;
|
|
23
|
+
});
|
|
24
|
+
switchToHttp(): HttpMessageContext;
|
|
25
|
+
switchToWs(): WsMessageContext;
|
|
26
|
+
switchToRpc(): RpcMessageContext;
|
|
27
|
+
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { Application } from 'express';
|
|
2
|
-
import { ApiDocument } from '@opra/common';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import type { ApiDocument } from '@opra/common';
|
|
3
|
+
import type { PlatformAdapter } from '../platform-adapter.js';
|
|
4
|
+
import type { HttpAdapter } from './http-adapter.js';
|
|
5
|
+
export interface ExpressAdapter extends PlatformAdapter {
|
|
6
|
+
readonly app: Application;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @namespace
|
|
10
|
+
*/
|
|
11
|
+
export declare namespace ExpressAdapter {
|
|
12
|
+
interface Options extends HttpAdapter.Options {
|
|
13
|
+
}
|
|
14
|
+
function create(app: Application, api: ApiDocument, options?: ExpressAdapter.Options): Promise<ExpressAdapter>;
|
|
11
15
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Application } from 'express';
|
|
2
|
+
import { ApiDocument } from '@opra/common';
|
|
3
|
+
import type { ExpressAdapter } from './express-adapter';
|
|
4
|
+
import { HttpAdapterBase } from './http-adapter-base.js';
|
|
5
|
+
export declare class ExpressAdapterHost extends HttpAdapterBase implements ExpressAdapter {
|
|
6
|
+
_platform: string;
|
|
7
|
+
_options: ExpressAdapter.Options;
|
|
8
|
+
_app: Application;
|
|
9
|
+
constructor(app: Application, api: ApiDocument, options?: ExpressAdapter.Options);
|
|
10
|
+
get app(): Application;
|
|
11
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import formidable from 'formidable';
|
|
4
|
+
import type IncomingForm from 'formidable/Formidable.js';
|
|
5
|
+
import { HttpIncomingMessage } from '../impl/http-incoming-message.host.js';
|
|
6
|
+
export type MultipartFile = formidable.File;
|
|
7
|
+
export type MultipartItem = {
|
|
8
|
+
field: string;
|
|
9
|
+
value?: string;
|
|
10
|
+
file?: MultipartFile;
|
|
11
|
+
};
|
|
12
|
+
export declare class MultipartIterator extends EventEmitter {
|
|
13
|
+
protected _cancelled: boolean;
|
|
14
|
+
protected _form: IncomingForm;
|
|
15
|
+
protected _items: MultipartItem[];
|
|
16
|
+
protected _stack: MultipartItem[];
|
|
17
|
+
constructor(incoming: HttpIncomingMessage, options?: formidable.Options);
|
|
18
|
+
get items(): MultipartItem[];
|
|
19
|
+
getNext(): Promise<MultipartItem | undefined>;
|
|
20
|
+
getAll(): Promise<MultipartItem[]>;
|
|
21
|
+
cancel(): void;
|
|
22
|
+
resume(): void;
|
|
23
|
+
pause(): void;
|
|
24
|
+
deleteFiles(): Promise<PromiseSettledResult<any>[]>;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseArrayParam(v?: string | null): string[] | undefined;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ExecutionContext } from '../execution-context.js';
|
|
2
|
+
import { RequestHandler } from '../interfaces/request-handler.interface.js';
|
|
3
|
+
import type { Protocol } from '../platform-adapter';
|
|
4
|
+
import { PlatformAdapterHost } from '../platform-adapter.host.js';
|
|
5
|
+
import { HttpServerRequest } from './http-server-request.js';
|
|
6
|
+
import { HttpServerResponse } from './http-server-response.js';
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @class HttpAdapterBase
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class HttpAdapterBase extends PlatformAdapterHost {
|
|
12
|
+
_protocol: Protocol;
|
|
13
|
+
_requestHandlers: RequestHandler[];
|
|
14
|
+
/**
|
|
15
|
+
* Main http request handler
|
|
16
|
+
* @param incoming
|
|
17
|
+
* @param outgoing
|
|
18
|
+
* @protected
|
|
19
|
+
*/
|
|
20
|
+
protected handleIncoming(incoming: HttpServerRequest, outgoing: HttpServerResponse): Promise<void>;
|
|
21
|
+
processRequest(context: ExecutionContext): Promise<void>;
|
|
22
|
+
protected handleError(context: ExecutionContext): Promise<void>;
|
|
23
|
+
}
|
|
@@ -1,33 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @namespace OpraHttpAdapter
|
|
10
|
-
*/
|
|
11
|
-
export declare namespace OpraHttpAdapter {
|
|
12
|
-
type Options = OpraAdapter.Options & {
|
|
13
|
-
prefix?: string;
|
|
14
|
-
};
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import http from 'http';
|
|
3
|
+
import type { ApiDocument, OpraURLPath } from '@opra/common';
|
|
4
|
+
import type { PlatformAdapter } from '../platform-adapter';
|
|
5
|
+
export interface HttpAdapter extends PlatformAdapter {
|
|
6
|
+
readonly basePath: OpraURLPath;
|
|
7
|
+
readonly server: http.Server;
|
|
15
8
|
}
|
|
16
9
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @class OpraHttpAdapter
|
|
10
|
+
* @namespace HttpAdapter
|
|
19
11
|
*/
|
|
20
|
-
export declare
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* @param outgoing
|
|
26
|
-
* @protected
|
|
27
|
-
*/
|
|
28
|
-
protected handler(incoming: HttpServerRequest, outgoing: HttpServerResponse): Promise<void>;
|
|
29
|
-
protected createRequestTask(request: Request, outgoing: HttpServerResponse): Task;
|
|
30
|
-
protected executeRequest(context: RequestContext): Promise<void>;
|
|
31
|
-
protected handleError(incoming: HttpServerRequest, outgoing: HttpServerResponse, errors: any[]): Promise<void>;
|
|
32
|
-
protected log(logType: keyof ILogger, incoming: HttpServerRequest, message: string, ...optionalParams: any[]): void;
|
|
12
|
+
export declare namespace HttpAdapter {
|
|
13
|
+
type Options = PlatformAdapter.Options & {
|
|
14
|
+
basePath?: string;
|
|
15
|
+
};
|
|
16
|
+
function create(api: ApiDocument, options?: Options): Promise<HttpAdapter>;
|
|
33
17
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import http from 'http';
|
|
3
|
+
import { ApiDocument, OpraURLPath } from '@opra/common';
|
|
4
|
+
import type { HttpAdapter } from './http-adapter';
|
|
5
|
+
import { HttpAdapterBase } from './http-adapter-base.js';
|
|
6
|
+
/**
|
|
7
|
+
* @class HttpAdapterHost
|
|
8
|
+
*/
|
|
9
|
+
export declare class HttpAdapterHost extends HttpAdapterBase implements HttpAdapter {
|
|
10
|
+
_basePath: OpraURLPath;
|
|
11
|
+
_options: HttpAdapter.Options;
|
|
12
|
+
_server: http.Server;
|
|
13
|
+
constructor(api: ApiDocument, options?: HttpAdapter.Options);
|
|
14
|
+
get basePath(): OpraURLPath;
|
|
15
|
+
get server(): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
16
|
+
protected _serverListener(incomingMessage: http.IncomingMessage, serverResponse: http.ServerResponse): void;
|
|
17
|
+
close(): Promise<void>;
|
|
18
|
+
}
|
|
@@ -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
|
+
}
|