@opra/core 0.33.13 → 1.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/augmentation/18n.augmentation.js +18 -5
- package/cjs/augmentation/http-controller.augmentation.js +25 -0
- package/cjs/constants.js +5 -0
- package/cjs/execution-context.js +24 -12
- package/cjs/{services → helpers}/logger.js +1 -2
- package/cjs/{services/api-service.js → helpers/service-base.js} +8 -8
- package/cjs/http/express-adapter.js +153 -0
- package/cjs/http/http-adapter.js +27 -0
- package/cjs/http/http-context.js +119 -0
- package/cjs/http/impl/asset-cache.js +21 -0
- package/cjs/http/impl/http-handler.js +584 -0
- package/cjs/http/{http-server-request.js → impl/http-incoming.host.js} +24 -49
- package/cjs/http/{http-server-response.js → impl/http-outgoing.host.js} +9 -28
- package/cjs/http/{helpers/multipart-helper.js → impl/multipart-reader.js} +23 -27
- package/cjs/http/impl/{http-incoming-message.host.js → node-incoming-message.host.js} +18 -57
- package/cjs/http/impl/{http-outgoing-message.host.js → node-outgoing-message.host.js} +11 -14
- package/cjs/http/interfaces/http-incoming.interface.js +25 -0
- package/cjs/http/interfaces/http-outgoing.interface.js +22 -0
- package/cjs/http/interfaces/node-incoming-message.interface.js +64 -0
- package/cjs/http/interfaces/node-outgoing-message.interface.js +15 -0
- package/cjs/http/utils/body-reader.js +217 -0
- package/cjs/http/{helpers → utils}/common.js +2 -1
- package/cjs/http/{helpers → utils}/convert-to-raw-headers.js +1 -2
- package/cjs/http/{helpers → utils}/match-known-fields.js +11 -9
- package/cjs/http/utils/wrap-exception.js +34 -0
- package/cjs/index.js +26 -26
- package/cjs/platform-adapter.js +21 -0
- package/cjs/type-guards.js +23 -0
- package/esm/augmentation/18n.augmentation.js +20 -7
- package/esm/augmentation/http-controller.augmentation.js +23 -0
- package/esm/constants.js +2 -0
- package/esm/execution-context.js +24 -13
- package/esm/{services → helpers}/logger.js +1 -2
- package/esm/{services/api-service.js → helpers/service-base.js} +6 -6
- package/esm/http/express-adapter.js +148 -0
- package/esm/http/http-adapter.js +23 -0
- package/esm/http/http-context.js +114 -0
- package/esm/http/impl/asset-cache.js +17 -0
- package/esm/http/impl/http-handler.js +579 -0
- package/esm/http/{http-server-request.js → impl/http-incoming.host.js} +20 -46
- package/esm/http/{http-server-response.js → impl/http-outgoing.host.js} +7 -27
- package/esm/http/{helpers/multipart-helper.js → impl/multipart-reader.js} +21 -25
- package/esm/http/impl/{http-incoming-message.host.js → node-incoming-message.host.js} +16 -55
- package/esm/http/impl/{http-outgoing-message.host.js → node-outgoing-message.host.js} +9 -12
- package/esm/http/interfaces/http-incoming.interface.js +22 -0
- package/esm/http/interfaces/http-outgoing.interface.js +19 -0
- package/esm/http/interfaces/node-incoming-message.interface.js +61 -0
- package/esm/http/interfaces/node-outgoing-message.interface.js +12 -0
- package/esm/http/utils/body-reader.js +212 -0
- package/esm/http/{helpers → utils}/common.js +2 -1
- package/esm/http/{helpers → utils}/convert-to-headers.js +1 -1
- package/esm/http/{helpers → utils}/convert-to-raw-headers.js +2 -3
- package/esm/http/{helpers → utils}/match-known-fields.js +11 -9
- package/esm/http/utils/wrap-exception.js +30 -0
- package/esm/index.js +26 -27
- package/esm/platform-adapter.js +19 -1
- package/esm/type-guards.js +16 -0
- package/package.json +31 -13
- package/types/augmentation/18n.augmentation.d.ts +31 -1
- package/types/augmentation/http-controller.augmentation.d.ts +21 -0
- package/types/constants.d.ts +2 -0
- package/types/execution-context.d.ts +22 -26
- package/types/helpers/service-base.d.ts +10 -0
- package/types/http/express-adapter.d.ts +13 -0
- package/types/http/http-adapter.d.ts +27 -0
- package/types/http/http-context.d.ts +44 -0
- package/types/http/impl/asset-cache.d.ts +5 -0
- package/types/http/impl/http-handler.d.ts +73 -0
- package/types/http/impl/http-incoming.host.d.ts +23 -0
- package/types/http/impl/http-outgoing.host.d.ts +17 -0
- package/types/http/{helpers/multipart-helper.d.ts → impl/multipart-reader.d.ts} +8 -6
- package/types/http/impl/{http-incoming-message.host.d.ts → node-incoming-message.host.d.ts} +10 -23
- package/types/http/impl/{http-outgoing-message.host.d.ts → node-outgoing-message.host.d.ts} +11 -27
- package/types/http/{http-server-request.d.ts → interfaces/http-incoming.interface.d.ts} +28 -17
- package/types/http/{http-server-response.d.ts → interfaces/http-outgoing.interface.d.ts} +17 -10
- package/types/http/interfaces/node-incoming-message.interface.d.ts +38 -0
- package/types/http/interfaces/node-outgoing-message.interface.d.ts +29 -0
- package/types/http/utils/body-reader.d.ts +41 -0
- package/types/http/utils/wrap-exception.d.ts +2 -0
- package/types/index.d.ts +25 -27
- package/types/platform-adapter.d.ts +20 -48
- package/types/type-guards.d.ts +8 -0
- package/cjs/augmentation/collection.augmentation.js +0 -2
- package/cjs/augmentation/container.augmentation.js +0 -2
- package/cjs/augmentation/resource.augmentation.js +0 -26
- package/cjs/augmentation/singleton.augmentation.js +0 -2
- package/cjs/augmentation/storage.augmentation.js +0 -2
- package/cjs/execution-context.host.js +0 -46
- package/cjs/http/adapters/express-adapter.host.js +0 -34
- package/cjs/http/adapters/express-adapter.js +0 -14
- package/cjs/http/adapters/node-http-adapter.host.js +0 -70
- package/cjs/http/adapters/node-http-adapter.js +0 -14
- package/cjs/http/helpers/json-body-loader.js +0 -29
- package/cjs/http/helpers/query-parsers.js +0 -16
- package/cjs/http/http-adapter-host.js +0 -715
- package/cjs/interfaces/interceptor.interface.js +0 -2
- package/cjs/interfaces/request-handler.interface.js +0 -2
- package/cjs/platform-adapter.host.js +0 -154
- package/cjs/request-context.js +0 -25
- package/cjs/request.host.js +0 -24
- package/cjs/request.js +0 -2
- package/cjs/response.host.js +0 -22
- package/cjs/response.js +0 -2
- package/esm/augmentation/collection.augmentation.js +0 -1
- package/esm/augmentation/container.augmentation.js +0 -1
- package/esm/augmentation/resource.augmentation.js +0 -24
- package/esm/augmentation/singleton.augmentation.js +0 -1
- package/esm/augmentation/storage.augmentation.js +0 -1
- package/esm/execution-context.host.js +0 -42
- package/esm/http/adapters/express-adapter.host.js +0 -30
- package/esm/http/adapters/express-adapter.js +0 -11
- package/esm/http/adapters/node-http-adapter.host.js +0 -65
- package/esm/http/adapters/node-http-adapter.js +0 -11
- package/esm/http/helpers/json-body-loader.js +0 -24
- package/esm/http/helpers/query-parsers.js +0 -12
- package/esm/http/http-adapter-host.js +0 -710
- package/esm/interfaces/interceptor.interface.js +0 -1
- package/esm/interfaces/request-handler.interface.js +0 -1
- package/esm/platform-adapter.host.js +0 -149
- package/esm/request-context.js +0 -22
- package/esm/request.host.js +0 -20
- package/esm/request.js +0 -1
- package/esm/response.host.js +0 -18
- package/esm/response.js +0 -1
- package/types/augmentation/collection.augmentation.d.ts +0 -146
- package/types/augmentation/container.augmentation.d.ts +0 -14
- package/types/augmentation/resource.augmentation.d.ts +0 -38
- package/types/augmentation/singleton.augmentation.d.ts +0 -83
- package/types/augmentation/storage.augmentation.d.ts +0 -50
- package/types/execution-context.host.d.ts +0 -25
- package/types/http/adapters/express-adapter.d.ts +0 -15
- package/types/http/adapters/express-adapter.host.d.ts +0 -12
- package/types/http/adapters/node-http-adapter.d.ts +0 -17
- package/types/http/adapters/node-http-adapter.host.d.ts +0 -19
- package/types/http/helpers/json-body-loader.d.ts +0 -5
- package/types/http/helpers/query-parsers.d.ts +0 -1
- package/types/http/http-adapter-host.d.ts +0 -34
- package/types/interfaces/interceptor.interface.d.ts +0 -2
- package/types/interfaces/request-handler.interface.d.ts +0 -4
- package/types/platform-adapter.host.d.ts +0 -43
- package/types/request-context.d.ts +0 -13
- package/types/request.d.ts +0 -14
- package/types/request.host.d.ts +0 -27
- package/types/response.d.ts +0 -22
- package/types/response.host.d.ts +0 -22
- package/types/services/api-service.d.ts +0 -10
- /package/cjs/http/{helpers → utils}/concat-readable.js +0 -0
- /package/cjs/http/{helpers → utils}/convert-to-headers.js +0 -0
- /package/esm/http/{helpers → utils}/concat-readable.js +0 -0
- /package/types/{services → helpers}/logger.d.ts +0 -0
- /package/types/http/{helpers → utils}/common.d.ts +0 -0
- /package/types/http/{helpers → utils}/concat-readable.d.ts +0 -0
- /package/types/http/{helpers → utils}/convert-to-headers.d.ts +0 -0
- /package/types/http/{helpers → utils}/convert-to-raw-headers.d.ts +0 -0
- /package/types/http/{helpers → utils}/match-known-fields.d.ts +0 -0
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 './
|
|
10
|
-
export * from './
|
|
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/adapters/node-http-adapter.host.js';
|
|
21
|
-
export * from './http/impl/http-incoming-message.host.js';
|
|
22
|
-
export * from './http/impl/http-outgoing-message.host.js';
|
|
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';
|
|
9
|
+
export * from './helpers/logger.js';
|
|
10
|
+
export * from './helpers/service-base.js';
|
|
11
|
+
export * from './http/express-adapter.js';
|
|
12
|
+
export * from './http/http-adapter.js';
|
|
13
|
+
export * from './http/http-context.js';
|
|
14
|
+
export * from './http/impl/multipart-reader.js';
|
|
15
|
+
export * from './http/interfaces/http-incoming.interface.js';
|
|
16
|
+
export * from './http/interfaces/http-outgoing.interface.js';
|
|
17
|
+
export * from './http/interfaces/node-incoming-message.interface.js';
|
|
18
|
+
export * from './http/interfaces/node-outgoing-message.interface.js';
|
|
19
|
+
export * from './http/utils/wrap-exception.js';
|
|
27
20
|
export * from './interfaces/logger.interface.js';
|
|
28
|
-
export * from './
|
|
29
|
-
export * from './
|
|
30
|
-
export
|
|
21
|
+
export * from './platform-adapter.js';
|
|
22
|
+
export * from './type-guards.js';
|
|
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 { ApiDocument, I18n, OpraSchema } from '@opra/common';
|
|
3
|
+
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
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;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExpressAdapter = void 0;
|
|
4
|
-
const express_adapter_host_js_1 = require("./express-adapter.host.js");
|
|
5
|
-
/**
|
|
6
|
-
* @namespace
|
|
7
|
-
*/
|
|
8
|
-
var ExpressAdapter;
|
|
9
|
-
(function (ExpressAdapter) {
|
|
10
|
-
async function create(app, api, options) {
|
|
11
|
-
return express_adapter_host_js_1.ExpressAdapterHost.create(app, api, options);
|
|
12
|
-
}
|
|
13
|
-
ExpressAdapter.create = create;
|
|
14
|
-
})(ExpressAdapter || (exports.ExpressAdapter = ExpressAdapter = {}));
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NodeHttpAdapterHost = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const http_1 = tslib_1.__importDefault(require("http"));
|
|
6
|
-
const common_1 = require("@opra/common");
|
|
7
|
-
const http_adapter_host_js_1 = require("../http-adapter-host.js");
|
|
8
|
-
const http_server_request_js_1 = require("../http-server-request.js");
|
|
9
|
-
const http_server_response_js_1 = require("../http-server-response.js");
|
|
10
|
-
/**
|
|
11
|
-
* @class NodeHttpAdapterHost
|
|
12
|
-
*/
|
|
13
|
-
class NodeHttpAdapterHost extends http_adapter_host_js_1.HttpAdapterHost {
|
|
14
|
-
constructor() {
|
|
15
|
-
super(...arguments);
|
|
16
|
-
this._platform = 'http';
|
|
17
|
-
}
|
|
18
|
-
get basePath() {
|
|
19
|
-
return this._basePath;
|
|
20
|
-
}
|
|
21
|
-
get server() {
|
|
22
|
-
return this._server;
|
|
23
|
-
}
|
|
24
|
-
async close() {
|
|
25
|
-
await super.close();
|
|
26
|
-
if (this.server.listening)
|
|
27
|
-
await new Promise((resolve, reject) => {
|
|
28
|
-
this.server.close((err) => {
|
|
29
|
-
if (err)
|
|
30
|
-
return reject(err);
|
|
31
|
-
resolve();
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
async init(api, options) {
|
|
36
|
-
await super.init(api, options);
|
|
37
|
-
this._basePath = new common_1.OpraURLPath(options?.basePath);
|
|
38
|
-
this._server = http_1.default.createServer((incomingMessage, serverResponse) => this._serverListener(incomingMessage, serverResponse));
|
|
39
|
-
}
|
|
40
|
-
_serverListener(incomingMessage, serverResponse) {
|
|
41
|
-
const originalUrl = incomingMessage.url;
|
|
42
|
-
const parsedUrl = new common_1.OpraURL(originalUrl);
|
|
43
|
-
const relativePath = common_1.OpraURLPath.relative(parsedUrl.path, this.basePath);
|
|
44
|
-
if (!relativePath) {
|
|
45
|
-
serverResponse.statusCode = common_1.HttpStatusCode.NOT_FOUND;
|
|
46
|
-
serverResponse.statusMessage = common_1.HttpStatusMessages[common_1.HttpStatusCode.NOT_FOUND];
|
|
47
|
-
serverResponse.end();
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
parsedUrl.path = relativePath;
|
|
51
|
-
incomingMessage.originalUrl = originalUrl;
|
|
52
|
-
incomingMessage.baseUrl = this.basePath.toString();
|
|
53
|
-
incomingMessage.parsedUrl = parsedUrl;
|
|
54
|
-
Object.defineProperty(incomingMessage, 'searchParams', {
|
|
55
|
-
get() {
|
|
56
|
-
return incomingMessage.parsedUrl.searchParams;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
const req = http_server_request_js_1.HttpServerRequest.from(incomingMessage);
|
|
60
|
-
const res = http_server_response_js_1.HttpServerResponse.from(serverResponse);
|
|
61
|
-
this.handleHttp(req, res)
|
|
62
|
-
.catch((e) => this._logger.fatal(e));
|
|
63
|
-
}
|
|
64
|
-
static async create(api, options) {
|
|
65
|
-
const adapter = new NodeHttpAdapterHost();
|
|
66
|
-
await adapter.init(api, options);
|
|
67
|
-
return adapter;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.NodeHttpAdapterHost = NodeHttpAdapterHost;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NodeHttpAdapter = void 0;
|
|
4
|
-
const node_http_adapter_host_js_1 = require("./node-http-adapter.host.js");
|
|
5
|
-
/**
|
|
6
|
-
* @namespace NodeHttpAdapter
|
|
7
|
-
*/
|
|
8
|
-
var NodeHttpAdapter;
|
|
9
|
-
(function (NodeHttpAdapter) {
|
|
10
|
-
async function create(api, options) {
|
|
11
|
-
return node_http_adapter_host_js_1.NodeHttpAdapterHost.create(api, options);
|
|
12
|
-
}
|
|
13
|
-
NodeHttpAdapter.create = create;
|
|
14
|
-
})(NodeHttpAdapter || (exports.NodeHttpAdapter = NodeHttpAdapter = {}));
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.jsonBodyLoader = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const body_parser_1 = tslib_1.__importDefault(require("body-parser"));
|
|
6
|
-
const bodyLoaderCache = new WeakMap();
|
|
7
|
-
function jsonBodyLoader(options, cachePoint) {
|
|
8
|
-
let bodyLoader = cachePoint ? bodyLoaderCache.get(cachePoint) : undefined;
|
|
9
|
-
if (bodyLoader)
|
|
10
|
-
return bodyLoader;
|
|
11
|
-
const parser = body_parser_1.default.json({
|
|
12
|
-
...options,
|
|
13
|
-
type: 'json'
|
|
14
|
-
});
|
|
15
|
-
bodyLoader = (incoming) => {
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
const next = (error) => {
|
|
18
|
-
if (error)
|
|
19
|
-
return reject(error);
|
|
20
|
-
resolve(incoming.body);
|
|
21
|
-
};
|
|
22
|
-
parser(incoming, {}, next);
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
if (cachePoint)
|
|
26
|
-
bodyLoaderCache.set(cachePoint, bodyLoader);
|
|
27
|
-
return bodyLoader;
|
|
28
|
-
}
|
|
29
|
-
exports.jsonBodyLoader = jsonBodyLoader;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseArrayParam = void 0;
|
|
4
|
-
const fast_tokenizer_1 = require("fast-tokenizer");
|
|
5
|
-
function parseArrayParam(v) {
|
|
6
|
-
if (!v)
|
|
7
|
-
return;
|
|
8
|
-
return (0, fast_tokenizer_1.splitString)(v, {
|
|
9
|
-
delimiters: ',',
|
|
10
|
-
quotes: true,
|
|
11
|
-
brackets: true,
|
|
12
|
-
keepBrackets: true,
|
|
13
|
-
keepQuotes: true
|
|
14
|
-
}).map(x => x.trim());
|
|
15
|
-
}
|
|
16
|
-
exports.parseArrayParam = parseArrayParam;
|