@opra/core 0.13.0 → 0.15.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/adapter.js +88 -294
- package/cjs/adapter/http/express-adapter.js +27 -0
- package/cjs/adapter/http/http-adapter.js +466 -0
- package/cjs/adapter/http/http-request-context.host.js +28 -0
- package/cjs/adapter/http/http-request.host.js +14 -0
- package/cjs/adapter/http/http-response.host.js +14 -0
- package/cjs/adapter/internal/metadata.resource.js +27 -0
- package/cjs/adapter/request-context.host.js +30 -0
- package/cjs/adapter/request.host.js +19 -0
- package/cjs/adapter/response.host.js +20 -0
- package/cjs/augmentation/resource.augmentation.js +26 -0
- package/cjs/index.js +7 -8
- package/esm/adapter/adapter.d.ts +52 -28
- package/esm/adapter/adapter.js +88 -295
- package/esm/adapter/http/express-adapter.d.ts +11 -0
- package/esm/adapter/http/express-adapter.js +22 -0
- package/esm/adapter/http/http-adapter.d.ts +37 -0
- package/esm/adapter/http/http-adapter.js +462 -0
- package/esm/adapter/http/http-request-context.host.d.ts +16 -0
- package/esm/adapter/http/http-request-context.host.js +24 -0
- package/esm/adapter/http/http-request.host.d.ts +7 -0
- package/esm/adapter/http/http-request.host.js +10 -0
- package/esm/adapter/http/http-response.host.d.ts +7 -0
- package/esm/adapter/http/http-response.host.js +10 -0
- package/esm/{interfaces → adapter/interfaces}/logger.interface.d.ts +1 -0
- package/esm/adapter/interfaces/request-context.interface.d.ts +25 -0
- package/esm/adapter/interfaces/request.interface.d.ts +13 -0
- package/esm/adapter/interfaces/response.interface.d.ts +22 -0
- package/esm/adapter/internal/metadata.resource.d.ts +7 -0
- package/esm/adapter/internal/metadata.resource.js +24 -0
- package/esm/adapter/request-context.host.d.ts +19 -0
- package/esm/adapter/request-context.host.js +26 -0
- package/esm/adapter/request.host.d.ts +26 -0
- package/esm/adapter/request.host.js +15 -0
- package/esm/adapter/response.host.d.ts +20 -0
- package/esm/adapter/response.host.js +16 -0
- package/esm/augmentation/resource.augmentation.d.ts +33 -0
- package/esm/augmentation/resource.augmentation.js +24 -0
- package/esm/index.d.ts +7 -8
- package/esm/index.js +7 -8
- package/i18n/en/error.json +1 -1
- package/package.json +9 -7
- package/cjs/adapter/classes/execution-context.host.js +0 -16
- package/cjs/adapter/classes/express-request-wrapper.host.js +0 -36
- package/cjs/adapter/classes/express-response-wrapper.host.js +0 -55
- package/cjs/adapter/classes/http-execution-context.host.js +0 -28
- package/cjs/adapter/classes/metadata.resource.js +0 -22
- package/cjs/adapter/express-adapter.js +0 -26
- package/cjs/adapter/http-adapter.js +0 -443
- package/cjs/adapter/request-contexts/batch-request-context.js +0 -11
- package/cjs/adapter/request-contexts/request-context.js +0 -25
- package/cjs/adapter/request-contexts/single-request-context.js +0 -14
- package/cjs/interfaces/resource.interface.js +0 -2
- package/cjs/services/data-service.js +0 -9
- package/cjs/services/json-singleton-service.js +0 -96
- package/cjs/utils/create-i18n.js +0 -21
- package/cjs/utils/get-caller-file.util.js +0 -24
- package/esm/adapter/classes/execution-context.host.d.ts +0 -10
- package/esm/adapter/classes/execution-context.host.js +0 -12
- package/esm/adapter/classes/express-request-wrapper.host.d.ts +0 -19
- package/esm/adapter/classes/express-request-wrapper.host.js +0 -32
- package/esm/adapter/classes/express-response-wrapper.host.d.ts +0 -22
- package/esm/adapter/classes/express-response-wrapper.host.js +0 -51
- package/esm/adapter/classes/http-execution-context.host.d.ts +0 -13
- package/esm/adapter/classes/http-execution-context.host.js +0 -24
- package/esm/adapter/classes/metadata.resource.d.ts +0 -8
- package/esm/adapter/classes/metadata.resource.js +0 -19
- package/esm/adapter/express-adapter.d.ts +0 -11
- package/esm/adapter/express-adapter.js +0 -21
- package/esm/adapter/http-adapter.d.ts +0 -37
- package/esm/adapter/http-adapter.js +0 -439
- package/esm/adapter/request-contexts/batch-request-context.d.ts +0 -7
- package/esm/adapter/request-contexts/batch-request-context.js +0 -7
- package/esm/adapter/request-contexts/request-context.d.ts +0 -22
- package/esm/adapter/request-contexts/request-context.js +0 -21
- package/esm/adapter/request-contexts/single-request-context.d.ts +0 -10
- package/esm/adapter/request-contexts/single-request-context.js +0 -10
- package/esm/enums/issue-severity.enum.d.ts +0 -1
- package/esm/interfaces/execution-context.interface.d.ts +0 -47
- package/esm/interfaces/i18n-options.interface.d.ts +0 -28
- package/esm/interfaces/resource.interface.d.ts +0 -23
- package/esm/interfaces/resource.interface.js +0 -1
- package/esm/services/data-service.d.ts +0 -2
- package/esm/services/data-service.js +0 -5
- package/esm/services/json-singleton-service.d.ts +0 -39
- package/esm/services/json-singleton-service.js +0 -91
- package/esm/utils/create-i18n.d.ts +0 -3
- package/esm/utils/create-i18n.js +0 -16
- package/esm/utils/get-caller-file.util.d.ts +0 -1
- package/esm/utils/get-caller-file.util.js +0 -20
- /package/cjs/{interfaces → adapter/interfaces}/logger.interface.js +0 -0
- /package/cjs/{enums/issue-severity.enum.js → adapter/interfaces/request-context.interface.js} +0 -0
- /package/cjs/{interfaces/execution-context.interface.js → adapter/interfaces/request.interface.js} +0 -0
- /package/cjs/{interfaces/i18n-options.interface.js → adapter/interfaces/response.interface.js} +0 -0
- /package/esm/{interfaces → adapter/interfaces}/logger.interface.js +0 -0
- /package/esm/{enums/issue-severity.enum.js → adapter/interfaces/request-context.interface.js} +0 -0
- /package/esm/{interfaces/execution-context.interface.js → adapter/interfaces/request.interface.js} +0 -0
- /package/esm/{interfaces/i18n-options.interface.js → adapter/interfaces/response.interface.js} +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
2
|
+
export class RequestContextHost extends AsyncEventEmitter {
|
|
3
|
+
constructor(protocol, platform, api, _request, _response) {
|
|
4
|
+
super();
|
|
5
|
+
this.protocol = protocol;
|
|
6
|
+
this.platform = platform;
|
|
7
|
+
this.api = api;
|
|
8
|
+
this._request = _request;
|
|
9
|
+
this._response = _response;
|
|
10
|
+
}
|
|
11
|
+
get request() {
|
|
12
|
+
return this._request;
|
|
13
|
+
}
|
|
14
|
+
get response() {
|
|
15
|
+
return this._response;
|
|
16
|
+
}
|
|
17
|
+
switchToHttp() {
|
|
18
|
+
throw new TypeError('Not executing in an "Http" protocol');
|
|
19
|
+
}
|
|
20
|
+
switchToWs() {
|
|
21
|
+
throw new TypeError('Not executing in an "WebSocket" protocol');
|
|
22
|
+
}
|
|
23
|
+
switchToRpc() {
|
|
24
|
+
throw new TypeError('Not executing in an "RPC" protocol');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { HttpRequestMessage, Resource } from '@opra/common';
|
|
2
|
+
import { OpraSchema } from '@opra/common';
|
|
3
|
+
import type { Request } from './interfaces/request.interface.js';
|
|
4
|
+
export declare namespace RequestHost {
|
|
5
|
+
interface Initiator {
|
|
6
|
+
kind: string;
|
|
7
|
+
resource: Resource;
|
|
8
|
+
operation: string;
|
|
9
|
+
crud: 'create' | 'read' | 'update' | 'delete';
|
|
10
|
+
many: boolean;
|
|
11
|
+
args: any;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export declare abstract class RequestHost implements Request {
|
|
15
|
+
readonly kind: string;
|
|
16
|
+
readonly resource: Resource;
|
|
17
|
+
readonly resourceKind: OpraSchema.Resource.Kind;
|
|
18
|
+
readonly operation: string;
|
|
19
|
+
readonly crud: 'create' | 'read' | 'update' | 'delete';
|
|
20
|
+
readonly many: boolean;
|
|
21
|
+
readonly args: any;
|
|
22
|
+
protected constructor(init: RequestHost.Initiator);
|
|
23
|
+
switchToHttp(): HttpRequestMessage;
|
|
24
|
+
switchToWs(): never;
|
|
25
|
+
switchToRpc(): never;
|
|
26
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class RequestHost {
|
|
2
|
+
constructor(init) {
|
|
3
|
+
Object.assign(this, init);
|
|
4
|
+
this.resourceKind = this.resource.kind;
|
|
5
|
+
}
|
|
6
|
+
switchToHttp() {
|
|
7
|
+
throw new TypeError('Not executing in an "Http" protocol');
|
|
8
|
+
}
|
|
9
|
+
switchToWs() {
|
|
10
|
+
throw new TypeError('Not executing in an "WebSocket" protocol');
|
|
11
|
+
}
|
|
12
|
+
switchToRpc() {
|
|
13
|
+
throw new TypeError('Not executing in an "RPC" protocol');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HttpResponseMessage } from '@opra/common';
|
|
2
|
+
import { Response } from './interfaces/response.interface.js';
|
|
3
|
+
export declare namespace ResponseHost {
|
|
4
|
+
interface Initiator {
|
|
5
|
+
value?: any;
|
|
6
|
+
errors?: Error[];
|
|
7
|
+
continueOnError?: boolean;
|
|
8
|
+
count?: number;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export declare abstract class ResponseHost implements Response {
|
|
12
|
+
value?: any;
|
|
13
|
+
errors: Error[];
|
|
14
|
+
continueOnError?: boolean;
|
|
15
|
+
count?: number;
|
|
16
|
+
protected constructor(init: ResponseHost.Initiator);
|
|
17
|
+
switchToHttp(): HttpResponseMessage;
|
|
18
|
+
switchToWs(): never;
|
|
19
|
+
switchToRpc(): never;
|
|
20
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class ResponseHost {
|
|
2
|
+
constructor(init) {
|
|
3
|
+
if (init)
|
|
4
|
+
Object.assign(this, init);
|
|
5
|
+
this.errors = this.errors || [];
|
|
6
|
+
}
|
|
7
|
+
switchToHttp() {
|
|
8
|
+
throw new TypeError('Not executing in an "Http" protocol');
|
|
9
|
+
}
|
|
10
|
+
switchToWs() {
|
|
11
|
+
throw new TypeError('Not executing in an "WebSocket" protocol');
|
|
12
|
+
}
|
|
13
|
+
switchToRpc() {
|
|
14
|
+
throw new TypeError('Not executing in an "RPC" protocol');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
declare module "@opra/common" {
|
|
2
|
+
interface CollectionConstructor {
|
|
3
|
+
OnInit(): any;
|
|
4
|
+
OnShutdown(): any;
|
|
5
|
+
}
|
|
6
|
+
interface SingletonConstructor {
|
|
7
|
+
OnInit(): any;
|
|
8
|
+
OnShutdown(): any;
|
|
9
|
+
}
|
|
10
|
+
interface Resource {
|
|
11
|
+
onInit?: (resource: Resource) => void | Promise<void>;
|
|
12
|
+
onShutdown?: (resource: Resource) => void | Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
namespace Resource {
|
|
15
|
+
interface InitArguments {
|
|
16
|
+
onInit?: (resource: Resource) => void | Promise<void>;
|
|
17
|
+
onShutdown?: (resource: Resource) => void | Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
namespace Collection {
|
|
21
|
+
interface Metadata {
|
|
22
|
+
onInit?: (resource: Collection) => void | Promise<void>;
|
|
23
|
+
onShutdown?: (resource: Collection) => void | Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
namespace Singleton {
|
|
27
|
+
interface Metadata {
|
|
28
|
+
onInit?: (resource: Singleton) => void | Promise<void>;
|
|
29
|
+
onShutdown?: (resource: Singleton) => void | Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Collection, METADATA_KEY, Resource, Singleton } from "@opra/common";
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
const oldConstruct = Resource.prototype._construct;
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
Resource.prototype._construct = function (init) {
|
|
6
|
+
oldConstruct.call(this, init);
|
|
7
|
+
const _this = this;
|
|
8
|
+
_this.onInit = init.onInit;
|
|
9
|
+
_this.onShutdown = init.onShutdown;
|
|
10
|
+
};
|
|
11
|
+
Collection.OnInit = Singleton.OnInit = function () {
|
|
12
|
+
return (target, propertyKey) => {
|
|
13
|
+
const resourceMetadata = (Reflect.getOwnMetadata(METADATA_KEY, target.constructor) || {});
|
|
14
|
+
resourceMetadata.onInit = target[propertyKey];
|
|
15
|
+
Reflect.defineMetadata(METADATA_KEY, target.constructor, resourceMetadata);
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
Collection.OnShutdown = Singleton.OnShutdown = function () {
|
|
19
|
+
return (target, propertyKey) => {
|
|
20
|
+
const resourceMetadata = (Reflect.getOwnMetadata(METADATA_KEY, target.constructor) || {});
|
|
21
|
+
resourceMetadata.onShutdown = target[propertyKey];
|
|
22
|
+
Reflect.defineMetadata(METADATA_KEY, target.constructor, resourceMetadata);
|
|
23
|
+
};
|
|
24
|
+
};
|
package/esm/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
+
import './augmentation/resource.augmentation.js';
|
|
2
3
|
export * from './types.js';
|
|
3
|
-
export * from './interfaces/execution-context.interface.js';
|
|
4
|
-
export * from './interfaces/resource.interface.js';
|
|
5
|
-
export * from './interfaces/i18n-options.interface.js';
|
|
6
|
-
export * from './adapter/request-contexts/single-request-context.js';
|
|
7
4
|
export * from './adapter/adapter.js';
|
|
8
|
-
export * from './adapter/http-adapter.js';
|
|
9
|
-
export * from './adapter/
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
5
|
+
export * from './adapter/http/express-adapter.js';
|
|
6
|
+
export * from './adapter/http/http-adapter.js';
|
|
7
|
+
export * from './adapter/interfaces/request-context.interface.js';
|
|
8
|
+
export * from './adapter/interfaces/logger.interface.js';
|
|
9
|
+
export * from './adapter/interfaces/request.interface.js';
|
|
10
|
+
export * from './adapter/interfaces/response.interface.js';
|
package/esm/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
+
import './augmentation/resource.augmentation.js';
|
|
2
3
|
export * from './types.js';
|
|
3
|
-
export * from './interfaces/execution-context.interface.js';
|
|
4
|
-
export * from './interfaces/resource.interface.js';
|
|
5
|
-
export * from './interfaces/i18n-options.interface.js';
|
|
6
|
-
export * from './adapter/request-contexts/single-request-context.js';
|
|
7
4
|
export * from './adapter/adapter.js';
|
|
8
|
-
export * from './adapter/http-adapter.js';
|
|
9
|
-
export * from './adapter/
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
5
|
+
export * from './adapter/http/express-adapter.js';
|
|
6
|
+
export * from './adapter/http/http-adapter.js';
|
|
7
|
+
export * from './adapter/interfaces/request-context.interface.js';
|
|
8
|
+
export * from './adapter/interfaces/logger.interface.js';
|
|
9
|
+
export * from './adapter/interfaces/request.interface.js';
|
|
10
|
+
export * from './adapter/interfaces/response.interface.js';
|
package/i18n/en/error.json
CHANGED
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
"UNPROCESSABLE_ENTITY": "Unprocessable entity",
|
|
11
11
|
"RESOURCE_NOT_FOUND": "The resource '{{resource}}' could not be found",
|
|
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 '{{
|
|
13
|
+
"RESOLVER_FORBIDDEN": "The resource endpoint does not accept '{{operation}}' operations",
|
|
14
14
|
"UNACCEPTED_SORT_FIELD": "Field '{{field}}' is not available for sort operation"
|
|
15
15
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Opra schema package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,31 +19,33 @@
|
|
|
19
19
|
"_copy_pkg_files": "cp README.md package.json ../../LICENSE ../../build/core && cp ../../package.cjs.json ../../build/core/cjs/package.json",
|
|
20
20
|
"_copyi18n": "cp -R i18n ../../build/core/i18n",
|
|
21
21
|
"lint": "eslint . --max-warnings=0",
|
|
22
|
-
"test": "
|
|
23
|
-
"cover": "
|
|
22
|
+
"test": "jest",
|
|
23
|
+
"cover": "jest --collect-coverage",
|
|
24
24
|
"clean": "npm run clean:src && npm run clean:dist && npm run clean:cover",
|
|
25
25
|
"clean:src": "ts-cleanup -s src --all && ts-cleanup -s test --all",
|
|
26
26
|
"clean:dist": "rimraf ../../build/core",
|
|
27
27
|
"clean:cover": "rimraf ../../coverage/core"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@opra/common": "^0.
|
|
30
|
+
"@opra/common": "^0.15.0",
|
|
31
|
+
"content-type": "^1.0.5",
|
|
31
32
|
"lodash.isnil": "^4.0.0",
|
|
32
33
|
"lodash.omitby": "^4.6.0",
|
|
33
34
|
"power-tasks": "^1.6.4",
|
|
34
35
|
"putil-isplainobject": "^1.1.5",
|
|
35
|
-
"putil-merge": "^3.10.
|
|
36
|
+
"putil-merge": "^3.10.3",
|
|
36
37
|
"putil-varhelpers": "^1.6.5",
|
|
37
38
|
"strict-typed-events": "^2.3.1"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
|
-
"body-parser": "
|
|
41
|
+
"body-parser": "^1.20.2",
|
|
41
42
|
"express": "^4.x.x || ^5.x.x"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@faker-js/faker": "^7.6.0",
|
|
45
46
|
"@types/dicer": "^0.2.2",
|
|
46
|
-
"@types/express": "^4.17.
|
|
47
|
+
"@types/express": "^4.17.17",
|
|
48
|
+
"@types/content-type": "^1.1.5",
|
|
47
49
|
"cors": "^2.8.5",
|
|
48
50
|
"ts-gems": "^2.3.0"
|
|
49
51
|
},
|
|
@@ -1,16 +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() {
|
|
7
|
-
super();
|
|
8
|
-
}
|
|
9
|
-
switchToHttp() {
|
|
10
|
-
throw new Error(`This is not an http context`);
|
|
11
|
-
}
|
|
12
|
-
onFinish(fn) {
|
|
13
|
-
this.on('finish', fn);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.ExecutionContextHost = ExecutionContextHost;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExpressRequestWrapperHost = void 0;
|
|
4
|
-
class ExpressRequestWrapperHost {
|
|
5
|
-
constructor(instance) {
|
|
6
|
-
this.instance = instance;
|
|
7
|
-
}
|
|
8
|
-
getInstance() {
|
|
9
|
-
return this.instance;
|
|
10
|
-
}
|
|
11
|
-
getMethod() {
|
|
12
|
-
return this.instance.method;
|
|
13
|
-
}
|
|
14
|
-
getUrl() {
|
|
15
|
-
return this.instance.url;
|
|
16
|
-
}
|
|
17
|
-
getHeaderNames() {
|
|
18
|
-
return Object.keys(this.instance.headers);
|
|
19
|
-
}
|
|
20
|
-
getHeader(name) {
|
|
21
|
-
return this.instance.get(name);
|
|
22
|
-
}
|
|
23
|
-
getHeaders() {
|
|
24
|
-
return this.instance.headers;
|
|
25
|
-
}
|
|
26
|
-
getBody() {
|
|
27
|
-
return this.instance.body;
|
|
28
|
-
}
|
|
29
|
-
isCompleted() {
|
|
30
|
-
return this.instance.complete;
|
|
31
|
-
}
|
|
32
|
-
getStream() {
|
|
33
|
-
return this.instance;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.ExpressRequestWrapperHost = ExpressRequestWrapperHost;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExpressResponseWrapperHost = void 0;
|
|
4
|
-
class ExpressResponseWrapperHost {
|
|
5
|
-
constructor(instance) {
|
|
6
|
-
this.instance = instance;
|
|
7
|
-
}
|
|
8
|
-
getInstance() {
|
|
9
|
-
return this.instance;
|
|
10
|
-
}
|
|
11
|
-
getHeader(name) {
|
|
12
|
-
return this.instance.get(name);
|
|
13
|
-
}
|
|
14
|
-
getHeaders() {
|
|
15
|
-
return this.instance.getHeaders();
|
|
16
|
-
}
|
|
17
|
-
getHeaderNames() {
|
|
18
|
-
return this.instance.getHeaderNames();
|
|
19
|
-
}
|
|
20
|
-
hasHeader(name) {
|
|
21
|
-
return this.instance.hasHeader(name);
|
|
22
|
-
}
|
|
23
|
-
removeHeader(name) {
|
|
24
|
-
return this.instance.removeHeader(name);
|
|
25
|
-
}
|
|
26
|
-
setHeader(name, value) {
|
|
27
|
-
this.instance.setHeader(name, value);
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
getStatus() {
|
|
31
|
-
return this.instance.statusCode;
|
|
32
|
-
}
|
|
33
|
-
setStatus(value) {
|
|
34
|
-
// noinspection SuspiciousTypeOfGuard
|
|
35
|
-
this.instance.status(typeof value === 'number'
|
|
36
|
-
? value
|
|
37
|
-
: parseInt(value, 10) || 500);
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
getStream() {
|
|
41
|
-
return this.instance;
|
|
42
|
-
}
|
|
43
|
-
send(body) {
|
|
44
|
-
if (typeof body === 'string' || Buffer.isBuffer(body))
|
|
45
|
-
this.instance.send(body);
|
|
46
|
-
else
|
|
47
|
-
this.instance.json(body);
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
end() {
|
|
51
|
-
this.instance.end();
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.ExpressResponseWrapperHost = ExpressResponseWrapperHost;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpExecutionContextHost = void 0;
|
|
4
|
-
const execution_context_host_js_1 = require("./execution-context.host.js");
|
|
5
|
-
class HttpExecutionContextHost extends execution_context_host_js_1.ExecutionContextHost {
|
|
6
|
-
constructor(_platform, _request, _response) {
|
|
7
|
-
super();
|
|
8
|
-
this._platform = _platform;
|
|
9
|
-
this._request = _request;
|
|
10
|
-
this._response = _response;
|
|
11
|
-
}
|
|
12
|
-
getType() {
|
|
13
|
-
return 'http';
|
|
14
|
-
}
|
|
15
|
-
getPlatform() {
|
|
16
|
-
return this._platform;
|
|
17
|
-
}
|
|
18
|
-
getRequest() {
|
|
19
|
-
return this._request;
|
|
20
|
-
}
|
|
21
|
-
getResponse() {
|
|
22
|
-
return this._response;
|
|
23
|
-
}
|
|
24
|
-
switchToHttp() {
|
|
25
|
-
return this;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.HttpExecutionContextHost = HttpExecutionContextHost;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MetadataResource = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const common_1 = require("@opra/common");
|
|
6
|
-
const json_singleton_service_js_1 = require("../../services/json-singleton-service.js");
|
|
7
|
-
let MetadataResource = class MetadataResource {
|
|
8
|
-
init(resource) {
|
|
9
|
-
this.service = new json_singleton_service_js_1.JsonSingletonService(resource.dataType, {
|
|
10
|
-
data: resource.document.getMetadata(true)
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
get() {
|
|
14
|
-
return this.service.get();
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
MetadataResource = tslib_1.__decorate([
|
|
18
|
-
(0, common_1.OprSingletonResource)(Object, {
|
|
19
|
-
name: '$metadata'
|
|
20
|
-
})
|
|
21
|
-
], MetadataResource);
|
|
22
|
-
exports.MetadataResource = MetadataResource;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpraExpressAdapter = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const body_parser_1 = tslib_1.__importDefault(require("body-parser"));
|
|
6
|
-
const common_1 = require("@opra/common");
|
|
7
|
-
const express_request_wrapper_host_js_1 = require("./classes/express-request-wrapper.host.js");
|
|
8
|
-
const express_response_wrapper_host_js_1 = require("./classes/express-response-wrapper.host.js");
|
|
9
|
-
const http_execution_context_host_js_1 = require("./classes/http-execution-context.host.js");
|
|
10
|
-
const http_adapter_js_1 = require("./http-adapter.js");
|
|
11
|
-
class OpraExpressAdapter extends http_adapter_js_1.OpraHttpAdapter {
|
|
12
|
-
static async init(app, document, options) {
|
|
13
|
-
const adapter = new OpraExpressAdapter(document);
|
|
14
|
-
await adapter._init(options);
|
|
15
|
-
const prefix = '/' + (0, common_1.normalizePath)(options?.prefix, true);
|
|
16
|
-
app.use(prefix, body_parser_1.default.json());
|
|
17
|
-
app.use(prefix, (request, response, next) => {
|
|
18
|
-
(async () => {
|
|
19
|
-
const executionContext = new http_execution_context_host_js_1.HttpExecutionContextHost('express', new express_request_wrapper_host_js_1.ExpressRequestWrapperHost(request), new express_response_wrapper_host_js_1.ExpressResponseWrapperHost(response));
|
|
20
|
-
await adapter.handler(executionContext);
|
|
21
|
-
})().catch(e => next(e));
|
|
22
|
-
});
|
|
23
|
-
return adapter;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.OpraExpressAdapter = OpraExpressAdapter;
|