@opra/core 0.33.13 → 1.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/augmentation/18n.augmentation.js +17 -4
- package/cjs/augmentation/http-controller.augmentation.js +25 -0
- package/cjs/constants.js +5 -0
- package/cjs/execution-context.js +25 -12
- package/cjs/{services → helpers}/logger.js +1 -2
- package/cjs/{services/api-service.js → helpers/service-base.js} +8 -8
- package/cjs/http/express-adapter.js +164 -0
- package/cjs/http/http-adapter.js +27 -0
- package/cjs/http/http-context.js +116 -0
- package/cjs/http/impl/asset-cache.js +21 -0
- package/cjs/http/impl/http-handler.js +575 -0
- package/cjs/http/{http-server-request.js → impl/http-incoming.host.js} +21 -46
- package/cjs/http/{http-server-response.js → impl/http-outgoing.host.js} +7 -26
- package/cjs/http/{helpers/multipart-helper.js → impl/multipart-reader.js} +24 -22
- package/cjs/http/impl/{http-incoming-message.host.js → node-incoming-message.host.js} +13 -54
- package/cjs/http/impl/{http-outgoing-message.host.js → node-outgoing-message.host.js} +11 -14
- package/cjs/http/interfaces/http-incoming.interface.js +25 -0
- package/cjs/http/interfaces/http-outgoing.interface.js +22 -0
- package/cjs/http/interfaces/node-incoming-message.interface.js +63 -0
- package/cjs/http/interfaces/node-outgoing-message.interface.js +15 -0
- package/cjs/http/utils/body-reader.js +215 -0
- package/cjs/http/{helpers → utils}/convert-to-raw-headers.js +1 -2
- package/cjs/http/{helpers → utils}/match-known-fields.js +11 -9
- package/cjs/http/utils/wrap-exception.js +34 -0
- package/cjs/index.js +25 -25
- package/cjs/platform-adapter.js +21 -0
- package/cjs/type-guards.js +23 -0
- package/esm/augmentation/18n.augmentation.js +20 -7
- package/esm/augmentation/http-controller.augmentation.js +23 -0
- package/esm/constants.js +2 -0
- package/esm/execution-context.js +25 -13
- package/esm/{services → helpers}/logger.js +1 -2
- package/esm/{services/api-service.js → helpers/service-base.js} +6 -6
- package/esm/http/express-adapter.js +159 -0
- package/esm/http/http-adapter.js +23 -0
- package/esm/http/http-context.js +111 -0
- package/esm/http/impl/asset-cache.js +17 -0
- package/esm/http/impl/http-handler.js +570 -0
- package/esm/http/{http-server-request.js → impl/http-incoming.host.js} +17 -43
- package/esm/http/{http-server-response.js → impl/http-outgoing.host.js} +6 -26
- package/esm/http/{helpers/multipart-helper.js → impl/multipart-reader.js} +22 -20
- package/esm/http/impl/{http-incoming-message.host.js → node-incoming-message.host.js} +11 -52
- package/esm/http/impl/{http-outgoing-message.host.js → node-outgoing-message.host.js} +9 -12
- package/esm/http/interfaces/http-incoming.interface.js +22 -0
- package/esm/http/interfaces/http-outgoing.interface.js +19 -0
- package/esm/http/interfaces/node-incoming-message.interface.js +60 -0
- package/esm/http/interfaces/node-outgoing-message.interface.js +12 -0
- package/esm/http/utils/body-reader.js +210 -0
- package/esm/http/{helpers → utils}/convert-to-headers.js +1 -1
- package/esm/http/{helpers → utils}/convert-to-raw-headers.js +2 -3
- package/esm/http/{helpers → utils}/match-known-fields.js +11 -9
- package/esm/http/utils/wrap-exception.js +30 -0
- package/esm/index.js +25 -26
- package/esm/platform-adapter.js +19 -1
- package/esm/type-guards.js +16 -0
- package/package.json +22 -10
- package/types/augmentation/18n.augmentation.d.ts +32 -2
- package/types/augmentation/http-controller.augmentation.d.ts +21 -0
- package/types/constants.d.ts +2 -0
- package/types/execution-context.d.ts +24 -26
- package/types/helpers/service-base.d.ts +10 -0
- package/types/http/express-adapter.d.ts +13 -0
- package/types/http/http-adapter.d.ts +27 -0
- package/types/http/http-context.d.ts +44 -0
- package/types/http/impl/asset-cache.d.ts +5 -0
- package/types/http/impl/http-handler.d.ts +73 -0
- package/types/http/impl/http-incoming.host.d.ts +23 -0
- package/types/http/impl/http-outgoing.host.d.ts +17 -0
- package/types/http/{helpers/multipart-helper.d.ts → impl/multipart-reader.d.ts} +8 -6
- package/types/http/impl/{http-incoming-message.host.d.ts → node-incoming-message.host.d.ts} +9 -22
- package/types/http/impl/{http-outgoing-message.host.d.ts → node-outgoing-message.host.d.ts} +11 -27
- package/types/http/{http-server-request.d.ts → interfaces/http-incoming.interface.d.ts} +28 -17
- package/types/http/{http-server-response.d.ts → interfaces/http-outgoing.interface.d.ts} +17 -10
- package/types/http/interfaces/node-incoming-message.interface.d.ts +38 -0
- package/types/http/interfaces/node-outgoing-message.interface.d.ts +29 -0
- package/types/http/utils/body-reader.d.ts +41 -0
- package/types/http/utils/wrap-exception.d.ts +2 -0
- package/types/index.d.ts +24 -26
- package/types/platform-adapter.d.ts +20 -48
- package/types/type-guards.d.ts +8 -0
- package/cjs/augmentation/collection.augmentation.js +0 -2
- package/cjs/augmentation/container.augmentation.js +0 -2
- package/cjs/augmentation/resource.augmentation.js +0 -26
- package/cjs/augmentation/singleton.augmentation.js +0 -2
- package/cjs/augmentation/storage.augmentation.js +0 -2
- package/cjs/execution-context.host.js +0 -46
- package/cjs/http/adapters/express-adapter.host.js +0 -34
- package/cjs/http/adapters/express-adapter.js +0 -14
- package/cjs/http/adapters/node-http-adapter.host.js +0 -70
- package/cjs/http/adapters/node-http-adapter.js +0 -14
- package/cjs/http/helpers/json-body-loader.js +0 -29
- package/cjs/http/helpers/query-parsers.js +0 -16
- package/cjs/http/http-adapter-host.js +0 -715
- package/cjs/interfaces/interceptor.interface.js +0 -2
- package/cjs/interfaces/request-handler.interface.js +0 -2
- package/cjs/platform-adapter.host.js +0 -154
- package/cjs/request-context.js +0 -25
- package/cjs/request.host.js +0 -24
- package/cjs/request.js +0 -2
- package/cjs/response.host.js +0 -22
- package/cjs/response.js +0 -2
- package/esm/augmentation/collection.augmentation.js +0 -1
- package/esm/augmentation/container.augmentation.js +0 -1
- package/esm/augmentation/resource.augmentation.js +0 -24
- package/esm/augmentation/singleton.augmentation.js +0 -1
- package/esm/augmentation/storage.augmentation.js +0 -1
- package/esm/execution-context.host.js +0 -42
- package/esm/http/adapters/express-adapter.host.js +0 -30
- package/esm/http/adapters/express-adapter.js +0 -11
- package/esm/http/adapters/node-http-adapter.host.js +0 -65
- package/esm/http/adapters/node-http-adapter.js +0 -11
- package/esm/http/helpers/json-body-loader.js +0 -24
- package/esm/http/helpers/query-parsers.js +0 -12
- package/esm/http/http-adapter-host.js +0 -710
- package/esm/interfaces/interceptor.interface.js +0 -1
- package/esm/interfaces/request-handler.interface.js +0 -1
- package/esm/platform-adapter.host.js +0 -149
- package/esm/request-context.js +0 -22
- package/esm/request.host.js +0 -20
- package/esm/request.js +0 -1
- package/esm/response.host.js +0 -18
- package/esm/response.js +0 -1
- package/i18n/i18n/en/error.json +0 -21
- package/types/augmentation/collection.augmentation.d.ts +0 -146
- package/types/augmentation/container.augmentation.d.ts +0 -14
- package/types/augmentation/resource.augmentation.d.ts +0 -38
- package/types/augmentation/singleton.augmentation.d.ts +0 -83
- package/types/augmentation/storage.augmentation.d.ts +0 -50
- package/types/execution-context.host.d.ts +0 -25
- package/types/http/adapters/express-adapter.d.ts +0 -15
- package/types/http/adapters/express-adapter.host.d.ts +0 -12
- package/types/http/adapters/node-http-adapter.d.ts +0 -17
- package/types/http/adapters/node-http-adapter.host.d.ts +0 -19
- package/types/http/helpers/json-body-loader.d.ts +0 -5
- package/types/http/helpers/query-parsers.d.ts +0 -1
- package/types/http/http-adapter-host.d.ts +0 -34
- package/types/interfaces/interceptor.interface.d.ts +0 -2
- package/types/interfaces/request-handler.interface.d.ts +0 -4
- package/types/platform-adapter.host.d.ts +0 -43
- package/types/request-context.d.ts +0 -13
- package/types/request.d.ts +0 -14
- package/types/request.host.d.ts +0 -27
- package/types/response.d.ts +0 -22
- package/types/response.host.d.ts +0 -22
- package/types/services/api-service.d.ts +0 -10
- /package/cjs/http/{helpers → utils}/common.js +0 -0
- /package/cjs/http/{helpers → utils}/concat-readable.js +0 -0
- /package/cjs/http/{helpers → utils}/convert-to-headers.js +0 -0
- /package/esm/http/{helpers → utils}/common.js +0 -0
- /package/esm/http/{helpers → utils}/concat-readable.js +0 -0
- /package/types/{services → helpers}/logger.d.ts +0 -0
- /package/types/http/{helpers → utils}/common.d.ts +0 -0
- /package/types/http/{helpers → utils}/concat-readable.d.ts +0 -0
- /package/types/http/{helpers → utils}/convert-to-headers.d.ts +0 -0
- /package/types/http/{helpers → utils}/convert-to-raw-headers.d.ts +0 -0
- /package/types/http/{helpers → utils}/match-known-fields.d.ts +0 -0
|
@@ -3,9 +3,7 @@ export const NO_DUPLICATES_FIELD = 0;
|
|
|
3
3
|
export const COMMA_DELIMITED_FIELD = 1;
|
|
4
4
|
export const SEMICOLON_DELIMITED_FIELD = 2;
|
|
5
5
|
export const ARRAY_FIELD = 3;
|
|
6
|
-
const ARRAY_HEADERS = [
|
|
7
|
-
'set-cookie'
|
|
8
|
-
];
|
|
6
|
+
const ARRAY_HEADERS = ['set-cookie'];
|
|
9
7
|
const NO_DUPLICATES_HEADERS = [
|
|
10
8
|
'age',
|
|
11
9
|
'from',
|
|
@@ -27,13 +25,17 @@ const NO_DUPLICATES_HEADERS = [
|
|
|
27
25
|
'if-unmodified-since',
|
|
28
26
|
];
|
|
29
27
|
const SEMICOLON_DELIMITED_HEADERS = ['cookie'];
|
|
30
|
-
const KNOWN_FIELDS = Object.values(HttpHeaderCodes)
|
|
31
|
-
.reduce((o, k) => {
|
|
28
|
+
const KNOWN_FIELDS = Object.values(HttpHeaderCodes).reduce((o, k) => {
|
|
32
29
|
const n = k.toLowerCase();
|
|
33
|
-
o[n] = [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
o[n] = [
|
|
31
|
+
k,
|
|
32
|
+
NO_DUPLICATES_HEADERS.includes(n)
|
|
33
|
+
? NO_DUPLICATES_FIELD
|
|
34
|
+
: ARRAY_HEADERS.includes(n)
|
|
35
|
+
? ARRAY_FIELD
|
|
36
|
+
: SEMICOLON_DELIMITED_HEADERS.includes(n)
|
|
37
|
+
? SEMICOLON_DELIMITED_FIELD
|
|
38
|
+
: COMMA_DELIMITED_FIELD,
|
|
37
39
|
];
|
|
38
40
|
return o;
|
|
39
41
|
}, {});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BadRequestError, FailedDependencyError, ForbiddenError, InternalServerError, MethodNotAllowedError, NotAcceptableError, NotFoundError, OpraHttpError, UnauthorizedError, UnprocessableEntityError, } from '@opra/common';
|
|
2
|
+
export function wrapException(error) {
|
|
3
|
+
if (error instanceof OpraHttpError)
|
|
4
|
+
return error;
|
|
5
|
+
let status = 500;
|
|
6
|
+
if (typeof error.status === 'number')
|
|
7
|
+
status = error.status;
|
|
8
|
+
else if (typeof error.getStatus === 'function')
|
|
9
|
+
status = error.getStatus();
|
|
10
|
+
switch (status) {
|
|
11
|
+
case 400:
|
|
12
|
+
return new BadRequestError(error);
|
|
13
|
+
case 401:
|
|
14
|
+
return new UnauthorizedError(error);
|
|
15
|
+
case 403:
|
|
16
|
+
return new ForbiddenError(error);
|
|
17
|
+
case 404:
|
|
18
|
+
return new NotFoundError(error);
|
|
19
|
+
case 405:
|
|
20
|
+
return new MethodNotAllowedError(error);
|
|
21
|
+
case 406:
|
|
22
|
+
return new NotAcceptableError(error);
|
|
23
|
+
case 422:
|
|
24
|
+
return new UnprocessableEntityError(error);
|
|
25
|
+
case 424:
|
|
26
|
+
return new FailedDependencyError(error);
|
|
27
|
+
default:
|
|
28
|
+
return new InternalServerError(error);
|
|
29
|
+
}
|
|
30
|
+
}
|
package/esm/index.js
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import 'reflect-metadata';
|
|
2
2
|
import './augmentation/18n.augmentation.js';
|
|
3
|
-
import './augmentation/
|
|
4
|
-
import './
|
|
5
|
-
import './
|
|
6
|
-
import './
|
|
7
|
-
import './
|
|
3
|
+
import './augmentation/http-controller.augmentation.js';
|
|
4
|
+
import * as HttpIncomingHost_ from './http/impl/http-incoming.host.js';
|
|
5
|
+
import * as HttpOutgoingHost_ from './http/impl/http-outgoing.host.js';
|
|
6
|
+
import * as NodeIncomingMessageHost_ from './http/impl/node-incoming-message.host.js';
|
|
7
|
+
import * as NodeOutgoingMessageHost_ from './http/impl/node-outgoing-message.host.js';
|
|
8
8
|
export * from './execution-context.js';
|
|
9
|
-
export * from './execution-context.host.js';
|
|
10
9
|
export * from './platform-adapter.js';
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
16
|
-
export * from './
|
|
17
|
-
export * from './http/
|
|
18
|
-
export * from './http/
|
|
19
|
-
export * from './http/
|
|
20
|
-
export * from './http/
|
|
21
|
-
export * from './http/impl/
|
|
22
|
-
export * from './http/
|
|
23
|
-
export * from './http/http-server-request.js';
|
|
24
|
-
export * from './http/http-server-response.js';
|
|
25
|
-
export * from './http/helpers/multipart-helper.js';
|
|
26
|
-
export * from './interfaces/interceptor.interface.js';
|
|
10
|
+
export * from './type-guards.js';
|
|
11
|
+
export * from './helpers/logger.js';
|
|
12
|
+
export * from './helpers/service-base.js';
|
|
13
|
+
export * from './http/express-adapter.js';
|
|
14
|
+
export * from './http/http-adapter.js';
|
|
15
|
+
export * from './http/http-context.js';
|
|
16
|
+
export * from './http/interfaces/http-incoming.interface.js';
|
|
17
|
+
export * from './http/interfaces/http-outgoing.interface.js';
|
|
18
|
+
export * from './http/interfaces/node-incoming-message.interface.js';
|
|
19
|
+
export * from './http/interfaces/node-outgoing-message.interface.js';
|
|
20
|
+
export * from './http/impl/multipart-reader.js';
|
|
21
|
+
export * from './http/utils/wrap-exception.js';
|
|
27
22
|
export * from './interfaces/logger.interface.js';
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
export var classes;
|
|
24
|
+
(function (classes) {
|
|
25
|
+
classes.HttpIncomingHost = HttpIncomingHost_.HttpIncomingHost;
|
|
26
|
+
classes.HttpOutgoingHost = HttpOutgoingHost_.HttpOutgoingHost;
|
|
27
|
+
classes.NodeIncomingMessageHost = NodeIncomingMessageHost_.NodeIncomingMessageHost;
|
|
28
|
+
classes.NodeOutgoingMessageHost = NodeOutgoingMessageHost_.NodeOutgoingMessageHost;
|
|
29
|
+
})(classes || (classes = {}));
|
package/esm/platform-adapter.js
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import './augmentation/18n.augmentation.js';
|
|
2
|
+
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
3
|
+
import { I18n } from '@opra/common';
|
|
4
|
+
import { kAssetCache } from './constants.js';
|
|
5
|
+
import { Logger } from './helpers/logger.js';
|
|
6
|
+
import { AssetCache } from './http/impl/asset-cache.js';
|
|
7
|
+
/**
|
|
8
|
+
* @class PlatformAdapter
|
|
9
|
+
*/
|
|
10
|
+
export class PlatformAdapter extends AsyncEventEmitter {
|
|
11
|
+
constructor(document, options) {
|
|
12
|
+
super();
|
|
13
|
+
this[kAssetCache] = new AssetCache();
|
|
14
|
+
this.document = document;
|
|
15
|
+
this.logger =
|
|
16
|
+
options?.logger && options.logger instanceof Logger ? options.logger : new Logger({ instance: options?.logger });
|
|
17
|
+
this.i18n = options?.i18n || I18n.defaultInstance;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isReadable, isStream } from '@opra/common';
|
|
2
|
+
export function isNodeIncomingMessage(v) {
|
|
3
|
+
return v && typeof v.method === 'string' && Array.isArray(v.rawHeaders) && isReadable(v);
|
|
4
|
+
}
|
|
5
|
+
export function isHttpIncoming(v) {
|
|
6
|
+
return (isNodeIncomingMessage(v) &&
|
|
7
|
+
typeof v.header === 'function' &&
|
|
8
|
+
typeof v.acceptsLanguages === 'function' &&
|
|
9
|
+
typeof v.readBody === 'function');
|
|
10
|
+
}
|
|
11
|
+
export function isNodeOutgoingMessage(v) {
|
|
12
|
+
return v && typeof v.getHeaders === 'function' && isStream(v);
|
|
13
|
+
}
|
|
14
|
+
export function isHttpOutgoing(v) {
|
|
15
|
+
return isNodeOutgoingMessage(v) && typeof v.clearCookie === 'function' && typeof v.cookie === 'function';
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.2",
|
|
4
4
|
"description": "Opra schema package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,6 +19,8 @@
|
|
|
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
|
+
"check": "madge --circular src/**",
|
|
23
|
+
"format": "prettier . --write --log-level=warn",
|
|
22
24
|
"test": "jest",
|
|
23
25
|
"cover": "jest --collect-coverage",
|
|
24
26
|
"clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
|
|
@@ -28,15 +30,18 @@
|
|
|
28
30
|
"clean:cover": "rimraf ../../coverage/client"
|
|
29
31
|
},
|
|
30
32
|
"dependencies": {
|
|
31
|
-
"@browsery/type-is": "^
|
|
32
|
-
"@opra/common": "^0.
|
|
33
|
+
"@browsery/type-is": "^1.6.18-r2",
|
|
34
|
+
"@opra/common": "^1.0.0-alpha.2",
|
|
33
35
|
"@types/formidable": "^3.4.5",
|
|
34
36
|
"accepts": "^1.3.8",
|
|
37
|
+
"base64-stream": "^1.0.0",
|
|
38
|
+
"bytes": "^3.1.2",
|
|
35
39
|
"content-disposition": "^0.5.4",
|
|
36
40
|
"content-type": "^1.0.5",
|
|
37
41
|
"cookie": "^0.6.0",
|
|
38
42
|
"cookie-signature": "^1.2.1",
|
|
39
|
-
"
|
|
43
|
+
"cppzst": "^2.0.12",
|
|
44
|
+
"encodeurl": "^2.0.0",
|
|
40
45
|
"formidable": "^3.5.1",
|
|
41
46
|
"fresh": "^0.5.2",
|
|
42
47
|
"mime-types": "^2.1.35",
|
|
@@ -44,29 +49,36 @@
|
|
|
44
49
|
"putil-isplainobject": "^1.1.5",
|
|
45
50
|
"putil-varhelpers": "^1.6.5",
|
|
46
51
|
"range-parser": "^1.2.1",
|
|
52
|
+
"raw-body": "^2.5.2",
|
|
47
53
|
"strict-typed-events": "^2.3.3",
|
|
48
54
|
"vary": "^1.1.2"
|
|
49
55
|
},
|
|
50
|
-
"
|
|
51
|
-
"express": "^4.x.x || ^5.x.x"
|
|
56
|
+
"optionalDependencies": {
|
|
57
|
+
"express": "^4.x.x || ^5.x.x",
|
|
58
|
+
"fastify": "^4.x.x"
|
|
52
59
|
},
|
|
53
60
|
"devDependencies": {
|
|
54
|
-
"@faker-js/faker": "^8.4.
|
|
61
|
+
"@faker-js/faker": "^8.4.1",
|
|
55
62
|
"@types/accepts": "^1.3.7",
|
|
63
|
+
"@types/base64-stream": "^1.0.5",
|
|
64
|
+
"@types/bytes": "^3.1.4",
|
|
56
65
|
"@types/content-disposition": "^0.5.8",
|
|
57
66
|
"@types/content-type": "^1.1.8",
|
|
58
67
|
"@types/cookie": "^0.6.0",
|
|
68
|
+
"@types/cookie-parser": "^1.4.7",
|
|
59
69
|
"@types/cookie-signature": "^1.1.2",
|
|
60
70
|
"@types/encodeurl": "^1.0.2",
|
|
61
71
|
"@types/express": "^4.17.21",
|
|
62
72
|
"@types/fresh": "^0.5.2",
|
|
63
73
|
"@types/mime-types": "^2.1.4",
|
|
64
74
|
"@types/range-parser": "^1.2.7",
|
|
65
|
-
"@types/type-is": "^1.6.6",
|
|
66
75
|
"@types/vary": "^1.1.3",
|
|
76
|
+
"cookie-parser": "^1.4.6",
|
|
67
77
|
"crypto-browserify": "^3.12.0",
|
|
78
|
+
"express": "^4.19.2",
|
|
79
|
+
"fastify": "^4.27.0",
|
|
68
80
|
"path-browserify": "^1.0.1",
|
|
69
|
-
"ts-gems": "^3.
|
|
81
|
+
"ts-gems": "^3.4.0"
|
|
70
82
|
},
|
|
71
83
|
"type": "module",
|
|
72
84
|
"module": "./esm/index.js",
|
|
@@ -95,4 +107,4 @@
|
|
|
95
107
|
"swagger",
|
|
96
108
|
"raml"
|
|
97
109
|
]
|
|
98
|
-
}
|
|
110
|
+
}
|
|
@@ -1,7 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
import { FallbackLng, LanguageResource } from '@opra/common';
|
|
2
|
+
declare module '@opra/common' {
|
|
2
3
|
interface I18n {
|
|
3
4
|
loadResourceDir(dirnames: string | string[], deep?: boolean, overwrite?: boolean): Promise<void>;
|
|
4
5
|
loadResourceBundle(lang: string, ns: string, filePath: string, deep?: boolean, overwrite?: boolean): Promise<void>;
|
|
5
6
|
}
|
|
7
|
+
namespace I18n {
|
|
8
|
+
function load(): Promise<I18n>;
|
|
9
|
+
interface Options {
|
|
10
|
+
/**
|
|
11
|
+
* Language to use
|
|
12
|
+
* @default undefined
|
|
13
|
+
*/
|
|
14
|
+
lng?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Language to use if translations in user language are not available.
|
|
17
|
+
* @default 'dev'
|
|
18
|
+
*/
|
|
19
|
+
fallbackLng?: false | FallbackLng;
|
|
20
|
+
/**
|
|
21
|
+
* Default namespace used if not passed to translation function
|
|
22
|
+
* @default 'translation'
|
|
23
|
+
*/
|
|
24
|
+
defaultNS?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Resources to initialize with
|
|
27
|
+
* @default undefined
|
|
28
|
+
*/
|
|
29
|
+
resources?: LanguageResource;
|
|
30
|
+
/**
|
|
31
|
+
* Resource directories to initialize with (if not using loading or not appending using addResourceBundle)
|
|
32
|
+
* @default undefined
|
|
33
|
+
*/
|
|
34
|
+
resourceDirs?: string[];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
6
37
|
}
|
|
7
|
-
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { HttpContext } from '../http/http-context';
|
|
2
|
+
declare module '@opra/common' {
|
|
3
|
+
interface HttpControllerStatic {
|
|
4
|
+
OnInit(): PropertyDecorator;
|
|
5
|
+
OnShutdown(): PropertyDecorator;
|
|
6
|
+
}
|
|
7
|
+
interface HttpController {
|
|
8
|
+
onInit?: (resource: HttpController) => void;
|
|
9
|
+
onShutdown?: (resource: HttpController) => void | Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
namespace HttpController {
|
|
12
|
+
interface InitArguments {
|
|
13
|
+
onInit?: (resource: HttpController) => void;
|
|
14
|
+
onShutdown?: (resource: HttpController) => void | Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
namespace HttpOperation {
|
|
18
|
+
interface Context extends HttpContext {
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
readonly platform: string;
|
|
7
|
-
switchToHttp(): HttpMessageContext;
|
|
8
|
-
switchToWs(): WsMessageContext;
|
|
9
|
-
switchToRpc(): RpcMessageContext;
|
|
10
|
-
on(event: 'finish', fn: (args: ExecutionContext.OnFinishArgs) => void | Promise<void>): any;
|
|
11
|
-
}
|
|
1
|
+
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
2
|
+
import { ApiDocument, OpraSchema } from '@opra/common';
|
|
3
|
+
/**
|
|
4
|
+
* @namespace ExecutionContext
|
|
5
|
+
*/
|
|
12
6
|
export declare namespace ExecutionContext {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
interface Initiator {
|
|
8
|
+
document: ApiDocument;
|
|
9
|
+
protocol: OpraSchema.Protocol;
|
|
10
|
+
platform: string;
|
|
11
|
+
platformArgs: any;
|
|
12
|
+
}
|
|
13
|
+
type OnFinishListener = (error: Error | undefined, context: ExecutionContext) => void | Promise<void>;
|
|
18
14
|
}
|
|
19
|
-
|
|
15
|
+
/**
|
|
16
|
+
* @class ExecutionContext
|
|
17
|
+
*/
|
|
18
|
+
export declare abstract class ExecutionContext extends AsyncEventEmitter {
|
|
19
|
+
readonly document: ApiDocument;
|
|
20
|
+
readonly protocol: OpraSchema.Protocol;
|
|
20
21
|
readonly platform: string;
|
|
21
|
-
readonly
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
export interface RpcMessageContext {
|
|
29
|
-
switchToContext(): ExecutionContext;
|
|
22
|
+
readonly platformArgs: any;
|
|
23
|
+
protected constructor(init: ExecutionContext.Initiator);
|
|
24
|
+
addListener(event: 'finish', listener: ExecutionContext.OnFinishListener): this;
|
|
25
|
+
removeListener(event: 'finish', listener: ExecutionContext.OnFinishListener): this;
|
|
26
|
+
on(event: 'finish', listener: ExecutionContext.OnFinishListener): this;
|
|
27
|
+
off(event: 'finish', listener: ExecutionContext.OnFinishListener): this;
|
|
30
28
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Nullish } from 'ts-gems';
|
|
2
|
+
import type { HttpContext } from '../http/http-context';
|
|
3
|
+
export declare abstract class ServiceBase {
|
|
4
|
+
protected _context: HttpContext;
|
|
5
|
+
get context(): HttpContext;
|
|
6
|
+
for<C extends HttpContext, P extends Partial<this>>(context: C, overwriteProperties?: Nullish<P>, overwriteContext?: Partial<C>): this & Required<P>;
|
|
7
|
+
}
|
|
8
|
+
export declare namespace ServiceBase {
|
|
9
|
+
const extendSymbol: unique symbol;
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Application } from 'express';
|
|
2
|
+
import { ApiDocument, HttpController } from '@opra/common';
|
|
3
|
+
import { HttpAdapter } from './http-adapter.js';
|
|
4
|
+
export declare class ExpressAdapter extends HttpAdapter {
|
|
5
|
+
readonly app: Application;
|
|
6
|
+
protected _controllerInstances: Map<HttpController, any>;
|
|
7
|
+
constructor(app: Application, document: ApiDocument, options?: HttpAdapter.Options);
|
|
8
|
+
get platform(): string;
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
getControllerInstance<T>(controllerPath: string): T | undefined;
|
|
11
|
+
protected _initRouter(basePath?: string): void;
|
|
12
|
+
protected _createControllers(controller: HttpController): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ApiDocument, HttpApi, OpraSchema } from '@opra/common';
|
|
2
|
+
import { kHandler } from '../constants.js';
|
|
3
|
+
import { PlatformAdapter } from '../platform-adapter.js';
|
|
4
|
+
import { HttpContext } from './http-context.js';
|
|
5
|
+
import { HttpHandler } from './impl/http-handler.js';
|
|
6
|
+
export declare namespace HttpAdapter {
|
|
7
|
+
/**
|
|
8
|
+
* @type Interceptor
|
|
9
|
+
*/
|
|
10
|
+
type Interceptor = (context: HttpContext, next: () => Promise<void>) => Promise<void>;
|
|
11
|
+
interface Options extends PlatformAdapter.Options {
|
|
12
|
+
basePath?: string;
|
|
13
|
+
interceptors?: HttpAdapter.Interceptor[];
|
|
14
|
+
onRequest?: (ctx: HttpContext) => void | Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @class HttpAdapter
|
|
20
|
+
*/
|
|
21
|
+
export declare abstract class HttpAdapter extends PlatformAdapter {
|
|
22
|
+
protected [kHandler]: HttpHandler;
|
|
23
|
+
readonly protocol: OpraSchema.Protocol;
|
|
24
|
+
interceptors: HttpAdapter.Interceptor[];
|
|
25
|
+
protected constructor(document: ApiDocument, options?: HttpAdapter.Options);
|
|
26
|
+
get api(): HttpApi;
|
|
27
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { HttpController, HttpMediaType, HttpOperation, OpraSchema } from '@opra/common';
|
|
2
|
+
import { ExecutionContext } from '../execution-context.js';
|
|
3
|
+
import type { HttpAdapter } from './http-adapter';
|
|
4
|
+
import { MultipartReader } from './impl/multipart-reader.js';
|
|
5
|
+
import type { HttpIncoming } from './interfaces/http-incoming.interface';
|
|
6
|
+
import type { HttpOutgoing } from './interfaces/http-outgoing.interface';
|
|
7
|
+
export declare namespace HttpContext {
|
|
8
|
+
interface Initiator extends Omit<ExecutionContext.Initiator, 'document' | 'protocol'> {
|
|
9
|
+
adapter: HttpAdapter;
|
|
10
|
+
request: HttpIncoming;
|
|
11
|
+
response: HttpOutgoing;
|
|
12
|
+
controller?: HttpController;
|
|
13
|
+
controllerInstance?: any;
|
|
14
|
+
operation?: HttpOperation;
|
|
15
|
+
operationHandler?: Function;
|
|
16
|
+
cookies?: Record<string, any>;
|
|
17
|
+
headers?: Record<string, any>;
|
|
18
|
+
pathParams?: Record<string, any>;
|
|
19
|
+
queryParams?: Record<string, any>;
|
|
20
|
+
mediaType?: HttpMediaType;
|
|
21
|
+
body?: any;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export declare class HttpContext extends ExecutionContext {
|
|
25
|
+
protected _body?: any;
|
|
26
|
+
protected _multipartReader?: MultipartReader;
|
|
27
|
+
readonly protocol: OpraSchema.Protocol;
|
|
28
|
+
readonly adapter: HttpAdapter;
|
|
29
|
+
readonly controller: HttpController;
|
|
30
|
+
readonly controllerInstance?: any;
|
|
31
|
+
readonly operation: HttpOperation;
|
|
32
|
+
readonly operationHandler?: Function;
|
|
33
|
+
readonly request: HttpIncoming;
|
|
34
|
+
readonly response: HttpOutgoing;
|
|
35
|
+
readonly mediaType?: HttpMediaType;
|
|
36
|
+
readonly cookies: Record<string, any>;
|
|
37
|
+
readonly headers: Record<string, any>;
|
|
38
|
+
readonly pathParams: Record<string, any>;
|
|
39
|
+
readonly queryParams: Record<string, any>;
|
|
40
|
+
constructor(init: HttpContext.Initiator);
|
|
41
|
+
get isMultipart(): boolean;
|
|
42
|
+
getMultipartReader(): Promise<MultipartReader>;
|
|
43
|
+
getBody<T>(): Promise<T>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { HttpOperationResponse } from '@opra/common';
|
|
2
|
+
import { kAssetCache } from '../../constants.js';
|
|
3
|
+
import type { HttpAdapter } from '../http-adapter.js';
|
|
4
|
+
import { HttpContext } from '../http-context.js';
|
|
5
|
+
import { HttpOutgoing } from '../interfaces/http-outgoing.interface.js';
|
|
6
|
+
import { AssetCache } from './asset-cache.js';
|
|
7
|
+
/**
|
|
8
|
+
* @namespace
|
|
9
|
+
*/
|
|
10
|
+
export declare namespace HttpHandler {
|
|
11
|
+
/**
|
|
12
|
+
* @interface ResponseArgs
|
|
13
|
+
*/
|
|
14
|
+
interface ResponseArgs {
|
|
15
|
+
statusCode: number;
|
|
16
|
+
contentType?: string;
|
|
17
|
+
operationResponse?: HttpOperationResponse;
|
|
18
|
+
body?: any;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @class HttpHandler
|
|
23
|
+
*/
|
|
24
|
+
export declare class HttpHandler {
|
|
25
|
+
readonly adapter: HttpAdapter;
|
|
26
|
+
protected [kAssetCache]: AssetCache;
|
|
27
|
+
constructor(adapter: HttpAdapter);
|
|
28
|
+
/**
|
|
29
|
+
* Main http request handler
|
|
30
|
+
* @param context
|
|
31
|
+
* @protected
|
|
32
|
+
*/
|
|
33
|
+
handleRequest(context: HttpContext): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param context
|
|
37
|
+
*/
|
|
38
|
+
parseRequest(context: HttpContext): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param context
|
|
42
|
+
* @protected
|
|
43
|
+
*/
|
|
44
|
+
protected _parseParameters(context: HttpContext): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param context
|
|
48
|
+
* @protected
|
|
49
|
+
*/
|
|
50
|
+
protected _parseContentType(context: HttpContext): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param context
|
|
54
|
+
* @protected
|
|
55
|
+
*/
|
|
56
|
+
protected _executeRequest(context: HttpContext): Promise<any>;
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @param context
|
|
60
|
+
* @param responseValue
|
|
61
|
+
* @protected
|
|
62
|
+
*/
|
|
63
|
+
protected _sendResponse(context: HttpContext, responseValue: any): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
*
|
|
66
|
+
* @param context
|
|
67
|
+
* @param body
|
|
68
|
+
* @protected
|
|
69
|
+
*/
|
|
70
|
+
protected _determineResponseArgs(context: HttpContext, body: any): HttpHandler.ResponseArgs;
|
|
71
|
+
sendDocumentSchema(context: HttpContext): Promise<void>;
|
|
72
|
+
sendErrorResponse(response: HttpOutgoing, errors: any[]): Promise<void>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import parseRange from 'range-parser';
|
|
3
|
+
import type { HttpIncoming } from '../interfaces/http-incoming.interface';
|
|
4
|
+
import { BodyReader } from '../utils/body-reader.js';
|
|
5
|
+
export interface HttpIncomingHost extends HttpIncoming {
|
|
6
|
+
}
|
|
7
|
+
export declare class HttpIncomingHost implements HttpIncoming {
|
|
8
|
+
body?: any;
|
|
9
|
+
get protocol(): string;
|
|
10
|
+
get secure(): boolean;
|
|
11
|
+
get hostname(): string | undefined;
|
|
12
|
+
get fresh(): boolean;
|
|
13
|
+
get xhr(): boolean;
|
|
14
|
+
header(name: string): any;
|
|
15
|
+
get(name: string): any;
|
|
16
|
+
accepts(...types: any): any;
|
|
17
|
+
acceptsCharsets(...charsets: any): any;
|
|
18
|
+
acceptsEncodings(...encoding: any): any;
|
|
19
|
+
acceptsLanguages(...lang: any): any;
|
|
20
|
+
is(type: string | string[], ...otherTypes: string[]): string | false | null;
|
|
21
|
+
range(size: number, options: any): parseRange.Ranges | parseRange.Result | undefined;
|
|
22
|
+
readBody(options: BodyReader.Options): Promise<string | Buffer | undefined>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CookieOptions, HttpOutgoing } from '../interfaces/http-outgoing.interface';
|
|
2
|
+
export interface HttpOutgoingHost extends HttpOutgoing {
|
|
3
|
+
}
|
|
4
|
+
export declare class HttpOutgoingHost {
|
|
5
|
+
attachment(filename?: string): this;
|
|
6
|
+
contentType(type: any): this;
|
|
7
|
+
setHeader(field: string | Record<string, any>, val?: any): this;
|
|
8
|
+
clearCookie(name: string, options: CookieOptions): this;
|
|
9
|
+
cookie(name: string, value: any, options?: CookieOptions): this;
|
|
10
|
+
status(code: number): this;
|
|
11
|
+
sendStatus(statusCode: number): this;
|
|
12
|
+
links(links: Record<string, string>): this;
|
|
13
|
+
location(url: string): this;
|
|
14
|
+
redirect(arg0: string | number, arg1?: string): void;
|
|
15
|
+
send(body: any): this;
|
|
16
|
+
vary(field: string): this;
|
|
17
|
+
}
|
|
@@ -2,25 +2,27 @@
|
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import formidable from 'formidable';
|
|
4
4
|
import type IncomingForm from 'formidable/Formidable.js';
|
|
5
|
-
import {
|
|
5
|
+
import type { NodeIncomingMessage } from '../interfaces/node-incoming-message.interface.js';
|
|
6
6
|
export type MultipartFile = formidable.File;
|
|
7
7
|
export type MultipartItem = {
|
|
8
|
-
|
|
8
|
+
fieldName: string;
|
|
9
|
+
type: 'field' | 'file';
|
|
9
10
|
value?: string;
|
|
10
11
|
file?: MultipartFile;
|
|
11
12
|
};
|
|
12
|
-
export declare class
|
|
13
|
+
export declare class MultipartReader extends EventEmitter {
|
|
14
|
+
protected _incoming: NodeIncomingMessage;
|
|
15
|
+
protected _started: boolean;
|
|
13
16
|
protected _cancelled: boolean;
|
|
14
17
|
protected _form: IncomingForm;
|
|
15
18
|
protected _items: MultipartItem[];
|
|
16
19
|
protected _stack: MultipartItem[];
|
|
17
|
-
|
|
20
|
+
constructor(incoming: NodeIncomingMessage, options?: formidable.Options);
|
|
18
21
|
get items(): MultipartItem[];
|
|
19
22
|
getNext(): Promise<MultipartItem | undefined>;
|
|
20
23
|
getAll(): Promise<MultipartItem[]>;
|
|
21
24
|
cancel(): void;
|
|
22
25
|
resume(): void;
|
|
23
26
|
pause(): void;
|
|
24
|
-
|
|
25
|
-
static create(incoming: HttpIncomingMessage, options?: formidable.Options): Promise<MultipartIterator>;
|
|
27
|
+
deleteTempFiles(): Promise<PromiseSettledResult<any>[]>;
|
|
26
28
|
}
|