@opra/core 1.0.0-beta.2 → 1.0.0-beta.3
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/execution-context.js +2 -14
- package/cjs/index.js +3 -25
- package/cjs/platform-adapter.js +3 -3
- package/esm/execution-context.js +1 -13
- package/esm/index.js +3 -24
- package/esm/platform-adapter.js +2 -2
- package/package.json +5 -39
- package/types/execution-context.d.ts +3 -8
- package/types/index.d.cts +3 -23
- package/types/index.d.ts +3 -23
- package/types/interfaces/logger.interface.d.ts +1 -1
- package/types/platform-adapter.d.ts +3 -3
- package/types/service-base.d.ts +10 -0
- package/cjs/augmentation/http-controller.augmentation.js +0 -25
- package/cjs/http/express-adapter.js +0 -155
- package/cjs/http/http-adapter.js +0 -24
- package/cjs/http/http-context.js +0 -104
- package/cjs/http/http-handler.js +0 -609
- package/cjs/http/impl/http-incoming.host.js +0 -112
- package/cjs/http/impl/http-outgoing.host.js +0 -207
- package/cjs/http/impl/multipart-reader.js +0 -196
- package/cjs/http/impl/node-incoming-message.host.js +0 -109
- package/cjs/http/impl/node-outgoing-message.host.js +0 -195
- package/cjs/http/interfaces/http-incoming.interface.js +0 -25
- package/cjs/http/interfaces/http-outgoing.interface.js +0 -22
- package/cjs/http/interfaces/node-incoming-message.interface.js +0 -64
- package/cjs/http/interfaces/node-outgoing-message.interface.js +0 -15
- package/cjs/http/utils/body-reader.js +0 -216
- package/cjs/http/utils/common.js +0 -67
- package/cjs/http/utils/concat-readable.js +0 -19
- package/cjs/http/utils/convert-to-headers.js +0 -64
- package/cjs/http/utils/convert-to-raw-headers.js +0 -23
- package/cjs/http/utils/match-known-fields.js +0 -49
- package/cjs/http/utils/wrap-exception.js +0 -33
- package/cjs/type-guards.js +0 -22
- package/esm/augmentation/http-controller.augmentation.js +0 -23
- package/esm/http/express-adapter.js +0 -150
- package/esm/http/http-adapter.js +0 -20
- package/esm/http/http-context.js +0 -99
- package/esm/http/http-handler.js +0 -604
- package/esm/http/impl/http-incoming.host.js +0 -107
- package/esm/http/impl/http-outgoing.host.js +0 -202
- package/esm/http/impl/multipart-reader.js +0 -191
- package/esm/http/impl/node-incoming-message.host.js +0 -105
- package/esm/http/impl/node-outgoing-message.host.js +0 -191
- package/esm/http/interfaces/http-incoming.interface.js +0 -22
- package/esm/http/interfaces/http-outgoing.interface.js +0 -19
- package/esm/http/interfaces/node-incoming-message.interface.js +0 -61
- package/esm/http/interfaces/node-outgoing-message.interface.js +0 -12
- package/esm/http/utils/body-reader.js +0 -211
- package/esm/http/utils/common.js +0 -61
- package/esm/http/utils/concat-readable.js +0 -16
- package/esm/http/utils/convert-to-headers.js +0 -60
- package/esm/http/utils/convert-to-raw-headers.js +0 -20
- package/esm/http/utils/match-known-fields.js +0 -45
- package/esm/http/utils/wrap-exception.js +0 -30
- package/esm/type-guards.js +0 -16
- package/types/augmentation/http-controller.augmentation.d.ts +0 -20
- package/types/helpers/service-base.d.ts +0 -10
- package/types/http/express-adapter.d.ts +0 -13
- package/types/http/http-adapter.d.ts +0 -54
- package/types/http/http-context.d.ts +0 -44
- package/types/http/http-handler.d.ts +0 -75
- package/types/http/impl/http-incoming.host.d.ts +0 -22
- package/types/http/impl/http-outgoing.host.d.ts +0 -17
- package/types/http/impl/multipart-reader.d.ts +0 -46
- package/types/http/impl/node-incoming-message.host.d.ts +0 -45
- package/types/http/impl/node-outgoing-message.host.d.ts +0 -49
- package/types/http/interfaces/http-incoming.interface.d.ts +0 -192
- package/types/http/interfaces/http-outgoing.interface.d.ts +0 -144
- package/types/http/interfaces/node-incoming-message.interface.d.ts +0 -36
- package/types/http/interfaces/node-outgoing-message.interface.d.ts +0 -27
- package/types/http/utils/body-reader.d.ts +0 -38
- package/types/http/utils/common.d.ts +0 -17
- package/types/http/utils/concat-readable.d.ts +0 -2
- package/types/http/utils/convert-to-headers.d.ts +0 -2
- package/types/http/utils/convert-to-raw-headers.d.ts +0 -2
- package/types/http/utils/match-known-fields.d.ts +0 -6
- package/types/http/utils/wrap-exception.d.ts +0 -2
- package/types/type-guards.d.ts +0 -8
- /package/cjs/{http/impl/asset-cache.js → asset-cache.js} +0 -0
- /package/cjs/{helpers/service-base.js → service-base.js} +0 -0
- /package/esm/{http/impl/asset-cache.js → asset-cache.js} +0 -0
- /package/esm/{helpers/service-base.js → service-base.js} +0 -0
- /package/types/{http/impl/asset-cache.d.ts → asset-cache.d.ts} +0 -0
package/cjs/http/http-context.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpContext = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const type_is_1 = tslib_1.__importDefault(require("@browsery/type-is"));
|
|
6
|
-
const common_1 = require("@opra/common");
|
|
7
|
-
const valgen_1 = require("valgen");
|
|
8
|
-
const constants_js_1 = require("../constants.js");
|
|
9
|
-
const execution_context_js_1 = require("../execution-context.js");
|
|
10
|
-
const multipart_reader_js_1 = require("./impl/multipart-reader.js");
|
|
11
|
-
class HttpContext extends execution_context_js_1.ExecutionContext {
|
|
12
|
-
constructor(init) {
|
|
13
|
-
super({ ...init, document: init.adapter.document, protocol: 'http' });
|
|
14
|
-
this.adapter = init.adapter;
|
|
15
|
-
this.protocol = 'http';
|
|
16
|
-
if (init.controller)
|
|
17
|
-
this.controller = init.controller;
|
|
18
|
-
if (init.controllerInstance)
|
|
19
|
-
this.controllerInstance = init.controllerInstance;
|
|
20
|
-
if (init.operation)
|
|
21
|
-
this.operation = init.operation;
|
|
22
|
-
if (init.operationHandler)
|
|
23
|
-
this.operationHandler = init.operationHandler;
|
|
24
|
-
this.request = init.request;
|
|
25
|
-
this.response = init.response;
|
|
26
|
-
this.mediaType = init.mediaType;
|
|
27
|
-
this.cookies = init.cookies || {};
|
|
28
|
-
this.headers = init.headers || {};
|
|
29
|
-
this.pathParams = init.pathParams || {};
|
|
30
|
-
this.queryParams = init.queryParams || {};
|
|
31
|
-
this._body = init.body;
|
|
32
|
-
this.on('finish', () => {
|
|
33
|
-
if (this._multipartReader)
|
|
34
|
-
this._multipartReader.purge().catch(() => undefined);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
get isMultipart() {
|
|
38
|
-
return !!this.request.is('multipart');
|
|
39
|
-
}
|
|
40
|
-
async getMultipartReader() {
|
|
41
|
-
if (!this.isMultipart)
|
|
42
|
-
throw new common_1.InternalServerError('Request content is not a multipart content');
|
|
43
|
-
if (this._multipartReader)
|
|
44
|
-
return this._multipartReader;
|
|
45
|
-
const { mediaType } = this;
|
|
46
|
-
if (mediaType?.contentType) {
|
|
47
|
-
const arr = Array.isArray(mediaType.contentType) ? mediaType.contentType : [mediaType.contentType];
|
|
48
|
-
const contentType = arr.find(ct => type_is_1.default.is(ct, ['multipart']));
|
|
49
|
-
if (!contentType)
|
|
50
|
-
throw new common_1.NotAcceptableError('This endpoint does not accept multipart requests');
|
|
51
|
-
}
|
|
52
|
-
const reader = new multipart_reader_js_1.MultipartReader(this, {
|
|
53
|
-
limits: {
|
|
54
|
-
fields: mediaType?.maxFields,
|
|
55
|
-
fieldSize: mediaType?.maxFieldsSize,
|
|
56
|
-
files: mediaType?.maxFiles,
|
|
57
|
-
fileSize: mediaType?.maxFileSize,
|
|
58
|
-
},
|
|
59
|
-
}, mediaType);
|
|
60
|
-
this._multipartReader = reader;
|
|
61
|
-
return reader;
|
|
62
|
-
}
|
|
63
|
-
async getBody() {
|
|
64
|
-
if (this._body !== undefined)
|
|
65
|
-
return this._body;
|
|
66
|
-
const { request, operation, mediaType } = this;
|
|
67
|
-
if (this.isMultipart) {
|
|
68
|
-
const reader = await this.getMultipartReader();
|
|
69
|
-
/** Retrieve all fields */
|
|
70
|
-
const parts = await reader.getAll();
|
|
71
|
-
/** Filter fields according to configuration */
|
|
72
|
-
this._body = [...parts];
|
|
73
|
-
return this._body;
|
|
74
|
-
}
|
|
75
|
-
this._body = await this.request.readBody({ limit: operation?.requestBody?.maxContentSize });
|
|
76
|
-
if (this._body != null) {
|
|
77
|
-
// Convert Buffer to string if media is text
|
|
78
|
-
if (Buffer.isBuffer(this._body) && request.is(['json', 'xml', 'txt', 'text'])) {
|
|
79
|
-
this._body = this._body.toString('utf-8');
|
|
80
|
-
}
|
|
81
|
-
// Transform text to Object if media is JSON
|
|
82
|
-
if (typeof this._body === 'string' && request.is(['json']))
|
|
83
|
-
this._body = JSON.parse(this._body);
|
|
84
|
-
}
|
|
85
|
-
if (mediaType) {
|
|
86
|
-
// Decode/Validate the data object according to data model
|
|
87
|
-
if (this._body && mediaType.type) {
|
|
88
|
-
let decode = this.adapter[constants_js_1.kAssetCache].get(mediaType, 'decode');
|
|
89
|
-
if (!decode) {
|
|
90
|
-
decode =
|
|
91
|
-
mediaType.type?.generateCodec('decode', {
|
|
92
|
-
partial: operation?.requestBody?.partial,
|
|
93
|
-
projection: '*',
|
|
94
|
-
ignoreReadonlyFields: true,
|
|
95
|
-
}) || valgen_1.vg.isAny();
|
|
96
|
-
this.adapter[constants_js_1.kAssetCache].set(mediaType, 'decode', decode);
|
|
97
|
-
}
|
|
98
|
-
this._body = decode(this._body);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return this._body;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
exports.HttpContext = HttpContext;
|