@opra/core 1.0.0-alpha.3 → 1.0.0-alpha.30

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.
Files changed (63) hide show
  1. package/cjs/augmentation/18n.augmentation.js +1 -1
  2. package/cjs/constants.js +1 -2
  3. package/cjs/execution-context.js +1 -1
  4. package/cjs/http/express-adapter.js +25 -34
  5. package/cjs/http/http-adapter.js +2 -5
  6. package/cjs/http/http-context.js +20 -32
  7. package/cjs/http/{impl/http-handler.js → http-handler.js} +249 -213
  8. package/cjs/http/impl/http-incoming.host.js +3 -3
  9. package/cjs/http/impl/http-outgoing.host.js +2 -2
  10. package/cjs/http/impl/multipart-reader.js +141 -50
  11. package/cjs/http/impl/node-incoming-message.host.js +5 -3
  12. package/cjs/http/interfaces/node-incoming-message.interface.js +3 -2
  13. package/cjs/http/utils/body-reader.js +6 -5
  14. package/cjs/http/utils/common.js +6 -5
  15. package/cjs/http/utils/concat-readable.js +1 -2
  16. package/cjs/http/utils/convert-to-headers.js +2 -3
  17. package/cjs/http/utils/convert-to-raw-headers.js +1 -2
  18. package/cjs/http/utils/match-known-fields.js +2 -2
  19. package/cjs/http/utils/wrap-exception.js +1 -2
  20. package/cjs/index.js +4 -4
  21. package/cjs/platform-adapter.js +1 -4
  22. package/cjs/type-guards.js +4 -5
  23. package/esm/augmentation/18n.augmentation.js +1 -1
  24. package/esm/constants.js +0 -1
  25. package/esm/execution-context.js +1 -1
  26. package/esm/http/express-adapter.js +25 -34
  27. package/esm/http/http-adapter.js +2 -5
  28. package/esm/http/http-context.js +21 -33
  29. package/esm/http/{impl/http-handler.js → http-handler.js} +243 -207
  30. package/esm/http/impl/http-incoming.host.js +3 -3
  31. package/esm/http/impl/http-outgoing.host.js +2 -2
  32. package/esm/http/impl/multipart-reader.js +142 -51
  33. package/esm/http/impl/node-incoming-message.host.js +5 -3
  34. package/esm/http/interfaces/node-incoming-message.interface.js +3 -2
  35. package/esm/http/utils/body-reader.js +6 -5
  36. package/esm/http/utils/common.js +2 -1
  37. package/esm/index.js +4 -4
  38. package/esm/platform-adapter.js +1 -4
  39. package/package.json +21 -14
  40. package/types/augmentation/18n.augmentation.d.ts +1 -1
  41. package/types/constants.d.ts +0 -1
  42. package/types/execution-context.d.ts +2 -3
  43. package/types/http/express-adapter.d.ts +1 -1
  44. package/types/http/http-adapter.d.ts +35 -8
  45. package/types/http/http-context.d.ts +4 -4
  46. package/types/http/{impl/http-handler.d.ts → http-handler.d.ts} +11 -9
  47. package/types/http/impl/http-incoming.host.d.ts +1 -2
  48. package/types/http/impl/http-outgoing.host.d.ts +1 -1
  49. package/types/http/impl/multipart-reader.d.ts +38 -20
  50. package/types/http/impl/node-incoming-message.host.d.ts +2 -6
  51. package/types/http/impl/node-outgoing-message.host.d.ts +4 -7
  52. package/types/http/interfaces/http-incoming.interface.d.ts +1 -2
  53. package/types/http/interfaces/http-outgoing.interface.d.ts +1 -1
  54. package/types/http/interfaces/node-incoming-message.interface.d.ts +0 -2
  55. package/types/http/interfaces/node-outgoing-message.interface.d.ts +0 -2
  56. package/types/http/utils/body-reader.d.ts +2 -5
  57. package/types/http/utils/concat-readable.d.ts +0 -1
  58. package/types/http/utils/convert-to-raw-headers.d.ts +0 -1
  59. package/types/index.d.ts +4 -4
  60. package/types/platform-adapter.d.ts +1 -5
  61. package/cjs/helpers/logger.js +0 -35
  62. package/esm/helpers/logger.js +0 -31
  63. package/types/helpers/logger.d.ts +0 -14
@@ -6,10 +6,10 @@ const tslib_1 = require("tslib");
6
6
  Some parts of this file contains codes from open source express library
7
7
  https://github.com/expressjs
8
8
  */
9
+ const type_is_1 = tslib_1.__importDefault(require("@browsery/type-is"));
9
10
  const accepts_1 = tslib_1.__importDefault(require("accepts"));
10
11
  const fresh_1 = tslib_1.__importDefault(require("fresh"));
11
12
  const range_parser_1 = tslib_1.__importDefault(require("range-parser"));
12
- const type_is_1 = tslib_1.__importDefault(require("@browsery/type-is"));
13
13
  const body_reader_js_1 = require("../utils/body-reader.js");
14
14
  class HttpIncomingHost {
15
15
  get protocol() {
@@ -41,11 +41,11 @@ class HttpIncomingHost {
41
41
  get fresh() {
42
42
  const method = this.method;
43
43
  // GET or HEAD for weak freshness validation only
44
- if ('GET' !== method && 'HEAD' !== method)
44
+ if (method !== 'GET' && method !== 'HEAD')
45
45
  return false;
46
46
  const status = this.res?.statusCode;
47
47
  // 2xx or 304 as per rfc2616 14.26
48
- if ((status >= 200 && status < 300) || 304 === status) {
48
+ if ((status >= 200 && status < 300) || status === 304) {
49
49
  return (0, fresh_1.default)(this.headers, {
50
50
  etag: this.res.getHeader('ETag'),
51
51
  'last-modified': this.res.getHeader('Last-Modified'),
@@ -6,6 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.HttpOutgoingHost = void 0;
8
8
  const tslib_1 = require("tslib");
9
+ const common_1 = require("@opra/common");
9
10
  const content_disposition_1 = tslib_1.__importDefault(require("content-disposition"));
10
11
  const content_type_1 = tslib_1.__importDefault(require("content-type"));
11
12
  const cookie_1 = tslib_1.__importDefault(require("cookie"));
@@ -15,7 +16,6 @@ const mime_types_1 = tslib_1.__importDefault(require("mime-types"));
15
16
  const path_1 = tslib_1.__importDefault(require("path"));
16
17
  const putil_varhelpers_1 = require("putil-varhelpers");
17
18
  const vary_1 = tslib_1.__importDefault(require("vary"));
18
- const common_1 = require("@opra/common");
19
19
  const charsetRegExp = /;\s*charset\s*=/;
20
20
  class HttpOutgoingHost {
21
21
  attachment(filename) {
@@ -164,7 +164,7 @@ class HttpOutgoingHost {
164
164
  if (req?.fresh)
165
165
  this.statusCode = 304;
166
166
  // strip irrelevant headers
167
- if (204 === this.statusCode || 304 === this.statusCode) {
167
+ if (this.statusCode === 204 || this.statusCode === 304) {
168
168
  this.removeHeader('Content-Type');
169
169
  this.removeHeader('Content-Length');
170
170
  this.removeHeader('Transfer-Encoding');
@@ -2,60 +2,158 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MultipartReader = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const node_crypto_1 = require("node:crypto");
6
+ const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
7
+ const node_os_1 = tslib_1.__importDefault(require("node:os"));
8
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
9
+ const type_is_1 = tslib_1.__importDefault(require("@browsery/type-is"));
10
+ const common_1 = require("@opra/common");
11
+ const busboy_1 = tslib_1.__importDefault(require("busboy"));
5
12
  const events_1 = require("events");
6
- const formidable_1 = tslib_1.__importDefault(require("formidable"));
7
13
  const promises_1 = tslib_1.__importDefault(require("fs/promises"));
14
+ const valgen_1 = require("valgen");
8
15
  class MultipartReader extends events_1.EventEmitter {
9
- constructor(incoming, options) {
16
+ constructor(context, options, mediaType) {
10
17
  super();
18
+ this.context = context;
19
+ this.mediaType = mediaType;
11
20
  this._started = false;
21
+ this._finished = false;
12
22
  this._cancelled = false;
13
23
  this._items = [];
14
24
  this._stack = [];
15
25
  this.setMaxListeners(1000);
16
- this._incoming = incoming;
17
- const form = (this._form = (0, formidable_1.default)({
18
- ...options,
19
- filter: (part) => {
20
- return !this._cancelled && (!options?.filter || options.filter(part));
21
- },
22
- }));
23
- form.once('error', () => {
26
+ this.tempDirectory = options?.tempDirectory || node_os_1.default.tmpdir();
27
+ const { request } = context;
28
+ const form = (0, busboy_1.default)({ headers: request.headers });
29
+ this._form = form;
30
+ form.once('error', (e) => {
24
31
  this._cancelled = true;
32
+ this._finished = true;
25
33
  if (this.listenerCount('error') > 0)
26
- this.emit('error');
34
+ this.emit('error', e);
27
35
  });
28
- form.on('field', (fieldName, value) => {
29
- const item = { fieldName, type: 'field', value };
36
+ form.on('close', () => {
37
+ this._finished = true;
38
+ });
39
+ form.on('field', (field, value, info) => {
40
+ const item = {
41
+ kind: 'field',
42
+ field,
43
+ value,
44
+ mimeType: info.mimeType,
45
+ encoding: info.encoding,
46
+ };
30
47
  this._items.push(item);
31
48
  this._stack.push(item);
32
49
  this.emit('field', item);
33
50
  this.emit('item', item);
34
51
  });
35
- form.on('file', (fieldName, file) => {
36
- const item = { fieldName, type: 'file', file };
37
- this._items.push(item);
38
- this._stack.push(item);
39
- this.emit('file', item);
40
- this.emit('item', item);
52
+ form.on('file', (field, file, info) => {
53
+ const saveTo = node_path_1.default.join(this.tempDirectory, `opra-${generateFileName()}`);
54
+ file.pipe(node_fs_1.default.createWriteStream(saveTo));
55
+ file.once('end', () => {
56
+ const item = {
57
+ kind: 'file',
58
+ field,
59
+ storedPath: saveTo,
60
+ filename: info.filename,
61
+ mimeType: info.mimeType,
62
+ encoding: info.encoding,
63
+ };
64
+ this._items.push(item);
65
+ this._stack.push(item);
66
+ this.emit('file', item);
67
+ this.emit('item', item);
68
+ });
41
69
  });
42
70
  }
43
71
  get items() {
44
72
  return this._items;
45
73
  }
46
- getNext() {
47
- if (!this._form.ended)
74
+ async getNext() {
75
+ let item = this._stack.shift();
76
+ if (!item && !this._finished) {
48
77
  this.resume();
49
- return new Promise((resolve, reject) => {
50
- if (this._stack.length)
51
- return resolve(this._stack.shift());
52
- if (this._form.ended)
53
- return resolve(undefined);
54
- this.once('item', () => resolve(this._stack.shift()));
55
- this.once('error', e => reject(e));
56
- });
78
+ item = await new Promise((resolve, reject) => {
79
+ let resolved = false;
80
+ if (this._stack.length)
81
+ return resolve(this._stack.shift());
82
+ if (this._form.ended)
83
+ return resolve(undefined);
84
+ this._form.once('close', () => {
85
+ if (resolved)
86
+ return;
87
+ resolved = true;
88
+ resolve(this._stack.shift());
89
+ });
90
+ this.once('item', () => {
91
+ this.pause();
92
+ if (resolved)
93
+ return;
94
+ resolved = true;
95
+ resolve(this._stack.shift());
96
+ });
97
+ this.once('error', e => reject(e));
98
+ });
99
+ }
100
+ if (item && this.mediaType) {
101
+ const field = this.mediaType.findMultipartField(item.field);
102
+ if (!field)
103
+ throw new common_1.BadRequestError(`Unknown multipart field (${item.field})`);
104
+ if (item.kind === 'field') {
105
+ const decode = field.generateCodec('decode', { ignoreReadonlyFields: true, projection: '*' });
106
+ item.value = decode(item.value, {
107
+ onFail: issue => `Multipart field (${item.field}) validation failed: ` + issue.message,
108
+ });
109
+ }
110
+ else if (item.kind === 'file') {
111
+ if (field.contentType) {
112
+ const arr = Array.isArray(field.contentType) ? field.contentType : [field.contentType];
113
+ if (!(item.mimeType && arr.find(ct => type_is_1.default.is(item.mimeType, [ct])))) {
114
+ throw new common_1.BadRequestError(`Multipart field (${item.field}) do not accept this content type`);
115
+ }
116
+ }
117
+ }
118
+ }
119
+ /** if all items received we check for required items */
120
+ if (this._finished && this.mediaType && this.mediaType.multipartFields?.length > 0) {
121
+ const fieldsLeft = new Set(this.mediaType.multipartFields);
122
+ for (const x of this._items) {
123
+ const field = this.mediaType.findMultipartField(x.field);
124
+ if (field)
125
+ fieldsLeft.delete(field);
126
+ }
127
+ let issues;
128
+ for (const field of fieldsLeft) {
129
+ if (!field.required)
130
+ continue;
131
+ try {
132
+ (0, valgen_1.isNotNullish)(null, { onFail: () => `Multi part field "${String(field.fieldName)}" is required` });
133
+ }
134
+ catch (e) {
135
+ if (!issues) {
136
+ issues = e.issues;
137
+ this.context.errors.push(e);
138
+ }
139
+ else
140
+ issues.push(...e.issues);
141
+ }
142
+ }
143
+ if (this.context.errors.length)
144
+ throw this.context.errors[0];
145
+ }
146
+ return item;
147
+ }
148
+ async getAll() {
149
+ const items = [...this._items];
150
+ let item;
151
+ while (!this._cancelled && (item = await this.getNext())) {
152
+ items.push(item);
153
+ }
154
+ return items;
57
155
  }
58
- getAll() {
156
+ getAll_() {
59
157
  if (this._form.ended)
60
158
  return Promise.resolve([...this._items]);
61
159
  this.resume();
@@ -72,34 +170,27 @@ class MultipartReader extends events_1.EventEmitter {
72
170
  this.resume();
73
171
  }
74
172
  resume() {
75
- if (!this._started)
76
- this._form.parse(this._incoming, () => void 0);
77
- if (this._form.req)
78
- this._form.resume();
173
+ if (!this._started) {
174
+ this._started = true;
175
+ this.context.request.pipe(this._form);
176
+ }
177
+ this.context.request.resume();
79
178
  }
80
179
  pause() {
81
- if (this._form.req)
82
- this._form.pause();
180
+ this.context.request.pause();
83
181
  }
84
- async deleteTempFiles() {
182
+ async purge() {
85
183
  const promises = [];
86
184
  this._items.forEach(item => {
87
- if (!item.file)
185
+ if (item.kind !== 'file')
88
186
  return;
89
- const file = item.file;
90
- promises.push(new Promise(resolve => {
91
- if (file._writeStream.closed)
92
- return resolve();
93
- file._writeStream.once('close', resolve);
94
- })
95
- .then(() => {
96
- return promises_1.default.unlink(file.filepath);
97
- })
98
- .then(() => {
99
- return 0;
100
- }));
187
+ promises.push(promises_1.default.unlink(item.storedPath));
101
188
  });
102
189
  return Promise.allSettled(promises);
103
190
  }
104
191
  }
105
192
  exports.MultipartReader = MultipartReader;
193
+ function generateFileName() {
194
+ const buf = Buffer.alloc(10);
195
+ return new Date().toISOString().substring(0, 10).replace(/-/g, '') + (0, node_crypto_1.randomFillSync)(buf).toString('hex');
196
+ }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NodeIncomingMessageHost = exports.kHttpParser = exports.kTrailersDistinct = exports.kTrailers = exports.kHeadersDistinct = exports.kHeaders = exports.CRLF = void 0;
4
- const stream_1 = require("stream");
5
4
  const common_1 = require("@opra/common");
5
+ const stream_1 = require("stream");
6
6
  const convert_to_headers_js_1 = require("../utils/convert-to-headers.js");
7
7
  const convert_to_raw_headers_js_1 = require("../utils/convert-to-raw-headers.js");
8
8
  exports.CRLF = Buffer.from('\r\n');
@@ -36,10 +36,12 @@ class NodeIncomingMessageHost extends stream_1.Duplex {
36
36
  else
37
37
  this.body = Buffer.from(JSON.stringify(init.body), 'utf-8');
38
38
  }
39
- if (init.headers)
39
+ if (init.headers) {
40
40
  this.rawHeaders = Array.isArray(init.headers) ? init.headers : (0, convert_to_raw_headers_js_1.convertToRawHeaders)(init.headers);
41
- if (init.trailers)
41
+ }
42
+ if (init.trailers) {
42
43
  this.rawTrailers = Array.isArray(init.trailers) ? init.trailers : (0, convert_to_raw_headers_js_1.convertToRawHeaders)(init.trailers);
44
+ }
43
45
  this.ip = init.ip || '';
44
46
  this.ips = init.ips || (this.ip ? [this.ip] : []);
45
47
  if (this.body && !this.headers['content-length'])
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NodeIncomingMessage = void 0;
4
- const stream_1 = require("stream");
5
4
  const http_parser_1 = require("@browsery/http-parser");
6
5
  const common_1 = require("@opra/common");
6
+ const stream_1 = require("stream");
7
7
  const node_incoming_message_host_js_1 = require("../impl/node-incoming-message.host.js");
8
8
  const concat_readable_js_1 = require("../utils/concat-readable.js");
9
9
  /**
@@ -17,8 +17,9 @@ var NodeIncomingMessage;
17
17
  * @param iterable
18
18
  */
19
19
  function from(iterable) {
20
- if (typeof iterable === 'object' && !((0, common_1.isIterable)(iterable) || (0, common_1.isAsyncIterable)(iterable)))
20
+ if (typeof iterable === 'object' && !((0, common_1.isIterable)(iterable) || (0, common_1.isAsyncIterable)(iterable))) {
21
21
  return new node_incoming_message_host_js_1.NodeIncomingMessageHost(iterable);
22
+ }
22
23
  const msg = new node_incoming_message_host_js_1.NodeIncomingMessageHost();
23
24
  const parser = (msg[node_incoming_message_host_js_1.kHttpParser] = new http_parser_1.HTTPParser(http_parser_1.HTTPParser.REQUEST));
24
25
  let bodyChunks;
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BodyReader = void 0;
4
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");
5
7
  const base64_stream_1 = require("base64-stream");
6
8
  const bytes_1 = tslib_1.__importDefault(require("bytes"));
7
9
  const content_type_1 = require("content-type");
@@ -9,8 +11,6 @@ const events_1 = require("events");
9
11
  const iconv_lite_1 = tslib_1.__importDefault(require("iconv-lite"));
10
12
  const stream_1 = require("stream");
11
13
  const zlib = tslib_1.__importStar(require("zlib"));
12
- const type_is_1 = tslib_1.__importDefault(require("@browsery/type-is"));
13
- const common_1 = require("@opra/common");
14
14
  /**
15
15
  *
16
16
  * @class BodyReader
@@ -33,11 +33,12 @@ class BodyReader extends events_1.EventEmitter {
33
33
  }
34
34
  async read() {
35
35
  /* istanbul ignore next */
36
- if (this._completed)
36
+ if (this._completed) {
37
37
  throw new common_1.InternalServerError({
38
38
  message: 'Stream already read',
39
39
  code: 'STREAM_ALREADY_READ',
40
40
  });
41
+ }
41
42
  if (!this.req.readable) {
42
43
  throw new common_1.InternalServerError({
43
44
  message: 'Stream is not readable',
@@ -61,8 +62,9 @@ class BodyReader extends events_1.EventEmitter {
61
62
  * http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.3
62
63
  */
63
64
  const contentLength = parseInt(this.req.headers['content-length'] || '0', 10);
64
- if (this.req.headers['transfer-encoding'] === undefined && !(contentLength && !isNaN(contentLength)))
65
+ if (this.req.headers['transfer-encoding'] === undefined && !(contentLength && !isNaN(contentLength))) {
65
66
  return this.onEnd();
67
+ }
66
68
  // check the length and limit options.
67
69
  // note: we intentionally leave the stream paused,
68
70
  // so users should handle the stream themselves.
@@ -147,7 +149,6 @@ class BodyReader extends events_1.EventEmitter {
147
149
  message: 'request aborted',
148
150
  code: 'ECONNABORTED',
149
151
  details: {
150
- length,
151
152
  received: this._receivedSize,
152
153
  },
153
154
  }));
@@ -4,7 +4,10 @@
4
4
  https://github.com/nodejs/
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.validateString = exports.validateHeaderValue = exports.validateHeaderName = exports.hideStackFrames = exports.checkIsHttpToken = void 0;
7
+ exports.validateHeaderValue = exports.validateHeaderName = void 0;
8
+ exports.checkIsHttpToken = checkIsHttpToken;
9
+ exports.hideStackFrames = hideStackFrames;
10
+ exports.validateString = validateString;
8
11
  const tokenRegExp = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/;
9
12
  const nodeInternalPrefix = '__node_internal_';
10
13
  /**
@@ -17,7 +20,6 @@ const nodeInternalPrefix = '__node_internal_';
17
20
  function checkIsHttpToken(val) {
18
21
  return typeof val === 'string' && tokenRegExp.exec(val) !== null;
19
22
  }
20
- exports.checkIsHttpToken = checkIsHttpToken;
21
23
  const headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
22
24
  /**
23
25
  * True if val contains an invalid field-vchar
@@ -44,7 +46,6 @@ function hideStackFrames(fn) {
44
46
  Object.defineProperty(fn, 'name', { __proto__: null, value: hidden });
45
47
  return fn;
46
48
  }
47
- exports.hideStackFrames = hideStackFrames;
48
49
  exports.validateHeaderName = hideStackFrames((name, label) => {
49
50
  // noinspection SuspiciousTypeOfGuard
50
51
  if (typeof name !== 'string' || !name || !checkIsHttpToken(name)) {
@@ -60,7 +61,7 @@ exports.validateHeaderValue = hideStackFrames((name, value) => {
60
61
  }
61
62
  });
62
63
  function validateString(value, name) {
63
- if (typeof value !== 'string')
64
+ if (typeof value !== 'string') {
64
65
  throw new TypeError(`Invalid ${name ? name + ' ' : ''}argument. Value must be a string`);
66
+ }
65
67
  }
66
- exports.validateString = validateString;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.concatReadable = void 0;
3
+ exports.concatReadable = concatReadable;
4
4
  const stream_1 = require("stream");
5
5
  function concatReadable(...streams) {
6
6
  const out = new stream_1.PassThrough();
@@ -17,4 +17,3 @@ function concatReadable(...streams) {
17
17
  pipeNext();
18
18
  return out;
19
19
  }
20
- exports.concatReadable = concatReadable;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertToHeadersDistinct = exports.convertToHeaders = void 0;
3
+ exports.convertToHeaders = convertToHeaders;
4
+ exports.convertToHeadersDistinct = convertToHeadersDistinct;
4
5
  const match_known_fields_js_1 = require("./match-known-fields.js");
5
6
  function convertToHeaders(src, dst, joinDuplicateHeaders) {
6
7
  for (let n = 0; n < src.length; n += 2) {
@@ -8,7 +9,6 @@ function convertToHeaders(src, dst, joinDuplicateHeaders) {
8
9
  }
9
10
  return dst;
10
11
  }
11
- exports.convertToHeaders = convertToHeaders;
12
12
  function convertToHeadersDistinct(src, dst) {
13
13
  const count = src.length % 2;
14
14
  for (let n = 0; n < count; n += 2) {
@@ -16,7 +16,6 @@ function convertToHeadersDistinct(src, dst) {
16
16
  }
17
17
  return dst;
18
18
  }
19
- exports.convertToHeadersDistinct = convertToHeadersDistinct;
20
19
  function addHeaderLine(field, value, dest, joinDuplicateHeaders) {
21
20
  if (value == null)
22
21
  return;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertToRawHeaders = void 0;
3
+ exports.convertToRawHeaders = convertToRawHeaders;
4
4
  const match_known_fields_js_1 = require("./match-known-fields.js");
5
5
  function convertToRawHeaders(src) {
6
6
  return Object.entries(src).reduce((a, [field, v]) => {
@@ -21,4 +21,3 @@ function convertToRawHeaders(src) {
21
21
  return a;
22
22
  }, []);
23
23
  }
24
- exports.convertToRawHeaders = convertToRawHeaders;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.matchKnownFields = exports.ARRAY_FIELD = exports.SEMICOLON_DELIMITED_FIELD = exports.COMMA_DELIMITED_FIELD = exports.NO_DUPLICATES_FIELD = void 0;
3
+ exports.ARRAY_FIELD = exports.SEMICOLON_DELIMITED_FIELD = exports.COMMA_DELIMITED_FIELD = exports.NO_DUPLICATES_FIELD = void 0;
4
+ exports.matchKnownFields = matchKnownFields;
4
5
  const common_1 = require("@opra/common");
5
6
  exports.NO_DUPLICATES_FIELD = 0;
6
7
  exports.COMMA_DELIMITED_FIELD = 1;
@@ -46,4 +47,3 @@ function matchKnownFields(field) {
46
47
  const x = KNOWN_FIELDS[field.toLowerCase()];
47
48
  return x ? x : [field, exports.COMMA_DELIMITED_FIELD];
48
49
  }
49
- exports.matchKnownFields = matchKnownFields;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapException = void 0;
3
+ exports.wrapException = wrapException;
4
4
  const common_1 = require("@opra/common");
5
5
  function wrapException(error) {
6
6
  if (error instanceof common_1.OpraHttpError)
@@ -31,4 +31,3 @@ function wrapException(error) {
31
31
  return new common_1.InternalServerError(error);
32
32
  }
33
33
  }
34
- exports.wrapException = wrapException;
package/cjs/index.js CHANGED
@@ -10,20 +10,20 @@ const HttpOutgoingHost_ = tslib_1.__importStar(require("./http/impl/http-outgoin
10
10
  const NodeIncomingMessageHost_ = tslib_1.__importStar(require("./http/impl/node-incoming-message.host.js"));
11
11
  const NodeOutgoingMessageHost_ = tslib_1.__importStar(require("./http/impl/node-outgoing-message.host.js"));
12
12
  tslib_1.__exportStar(require("./execution-context.js"), exports);
13
- tslib_1.__exportStar(require("./platform-adapter.js"), exports);
14
- tslib_1.__exportStar(require("./type-guards.js"), exports);
15
- tslib_1.__exportStar(require("./helpers/logger.js"), exports);
16
13
  tslib_1.__exportStar(require("./helpers/service-base.js"), exports);
17
14
  tslib_1.__exportStar(require("./http/express-adapter.js"), exports);
18
15
  tslib_1.__exportStar(require("./http/http-adapter.js"), exports);
19
16
  tslib_1.__exportStar(require("./http/http-context.js"), exports);
17
+ tslib_1.__exportStar(require("./http/http-handler.js"), exports);
18
+ tslib_1.__exportStar(require("./http/impl/multipart-reader.js"), exports);
20
19
  tslib_1.__exportStar(require("./http/interfaces/http-incoming.interface.js"), exports);
21
20
  tslib_1.__exportStar(require("./http/interfaces/http-outgoing.interface.js"), exports);
22
21
  tslib_1.__exportStar(require("./http/interfaces/node-incoming-message.interface.js"), exports);
23
22
  tslib_1.__exportStar(require("./http/interfaces/node-outgoing-message.interface.js"), exports);
24
- tslib_1.__exportStar(require("./http/impl/multipart-reader.js"), exports);
25
23
  tslib_1.__exportStar(require("./http/utils/wrap-exception.js"), exports);
26
24
  tslib_1.__exportStar(require("./interfaces/logger.interface.js"), exports);
25
+ tslib_1.__exportStar(require("./platform-adapter.js"), exports);
26
+ tslib_1.__exportStar(require("./type-guards.js"), exports);
27
27
  var classes;
28
28
  (function (classes) {
29
29
  classes.HttpIncomingHost = HttpIncomingHost_.HttpIncomingHost;
@@ -2,10 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PlatformAdapter = void 0;
4
4
  require("./augmentation/18n.augmentation.js");
5
- const strict_typed_events_1 = require("strict-typed-events");
6
5
  const common_1 = require("@opra/common");
6
+ const strict_typed_events_1 = require("strict-typed-events");
7
7
  const constants_js_1 = require("./constants.js");
8
- const logger_js_1 = require("./helpers/logger.js");
9
8
  const asset_cache_js_1 = require("./http/impl/asset-cache.js");
10
9
  /**
11
10
  * @class PlatformAdapter
@@ -15,8 +14,6 @@ class PlatformAdapter extends strict_typed_events_1.AsyncEventEmitter {
15
14
  super();
16
15
  this[constants_js_1.kAssetCache] = new asset_cache_js_1.AssetCache();
17
16
  this.document = document;
18
- this.logger =
19
- options?.logger && options.logger instanceof logger_js_1.Logger ? options.logger : new logger_js_1.Logger({ instance: options?.logger });
20
17
  this.i18n = options?.i18n || common_1.I18n.defaultInstance;
21
18
  }
22
19
  }
@@ -1,23 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isHttpOutgoing = exports.isNodeOutgoingMessage = exports.isHttpIncoming = exports.isNodeIncomingMessage = void 0;
3
+ exports.isNodeIncomingMessage = isNodeIncomingMessage;
4
+ exports.isHttpIncoming = isHttpIncoming;
5
+ exports.isNodeOutgoingMessage = isNodeOutgoingMessage;
6
+ exports.isHttpOutgoing = isHttpOutgoing;
4
7
  const common_1 = require("@opra/common");
5
8
  function isNodeIncomingMessage(v) {
6
9
  return v && typeof v.method === 'string' && Array.isArray(v.rawHeaders) && (0, common_1.isReadable)(v);
7
10
  }
8
- exports.isNodeIncomingMessage = isNodeIncomingMessage;
9
11
  function isHttpIncoming(v) {
10
12
  return (isNodeIncomingMessage(v) &&
11
13
  typeof v.header === 'function' &&
12
14
  typeof v.acceptsLanguages === 'function' &&
13
15
  typeof v.readBody === 'function');
14
16
  }
15
- exports.isHttpIncoming = isHttpIncoming;
16
17
  function isNodeOutgoingMessage(v) {
17
18
  return v && typeof v.getHeaders === 'function' && (0, common_1.isStream)(v);
18
19
  }
19
- exports.isNodeOutgoingMessage = isNodeOutgoingMessage;
20
20
  function isHttpOutgoing(v) {
21
21
  return isNodeOutgoingMessage(v) && typeof v.clearCookie === 'function' && typeof v.cookie === 'function';
22
22
  }
23
- exports.isHttpOutgoing = isHttpOutgoing;
@@ -1,6 +1,6 @@
1
+ import { getStackFileName, I18n as I18n_ } from '@opra/common';
1
2
  import fs from 'fs';
2
3
  import path from 'path';
3
- import { getStackFileName, I18n as I18n_ } from '@opra/common';
4
4
  I18n_.load = async function (options) {
5
5
  const opts = {
6
6
  ...options,
package/esm/constants.js CHANGED
@@ -1,2 +1 @@
1
- export const kHandler = Symbol.for('kHandler');
2
1
  export const kAssetCache = Symbol.for('kAssetCache');
@@ -5,10 +5,10 @@ import { AsyncEventEmitter } from 'strict-typed-events';
5
5
  export class ExecutionContext extends AsyncEventEmitter {
6
6
  constructor(init) {
7
7
  super();
8
+ this.errors = [];
8
9
  this.document = init.document;
9
10
  this.protocol = init.protocol;
10
11
  this.platform = init.platform;
11
- this.platformArgs = init.platformArgs;
12
12
  }
13
13
  addListener(event, listener) {
14
14
  return super.addListener(event, listener);