@opra/core 1.0.0-beta.1 → 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.
Files changed (85) hide show
  1. package/cjs/execution-context.js +2 -14
  2. package/cjs/index.js +3 -25
  3. package/cjs/platform-adapter.js +3 -3
  4. package/esm/execution-context.js +1 -13
  5. package/esm/index.js +3 -24
  6. package/esm/platform-adapter.js +2 -2
  7. package/package.json +5 -39
  8. package/types/execution-context.d.ts +3 -8
  9. package/types/index.d.cts +3 -23
  10. package/types/index.d.ts +3 -23
  11. package/types/interfaces/logger.interface.d.ts +1 -1
  12. package/types/platform-adapter.d.ts +3 -3
  13. package/types/service-base.d.ts +10 -0
  14. package/cjs/augmentation/http-controller.augmentation.js +0 -25
  15. package/cjs/http/express-adapter.js +0 -155
  16. package/cjs/http/http-adapter.js +0 -24
  17. package/cjs/http/http-context.js +0 -104
  18. package/cjs/http/http-handler.js +0 -609
  19. package/cjs/http/impl/http-incoming.host.js +0 -112
  20. package/cjs/http/impl/http-outgoing.host.js +0 -207
  21. package/cjs/http/impl/multipart-reader.js +0 -196
  22. package/cjs/http/impl/node-incoming-message.host.js +0 -109
  23. package/cjs/http/impl/node-outgoing-message.host.js +0 -195
  24. package/cjs/http/interfaces/http-incoming.interface.js +0 -25
  25. package/cjs/http/interfaces/http-outgoing.interface.js +0 -22
  26. package/cjs/http/interfaces/node-incoming-message.interface.js +0 -64
  27. package/cjs/http/interfaces/node-outgoing-message.interface.js +0 -15
  28. package/cjs/http/utils/body-reader.js +0 -216
  29. package/cjs/http/utils/common.js +0 -67
  30. package/cjs/http/utils/concat-readable.js +0 -19
  31. package/cjs/http/utils/convert-to-headers.js +0 -64
  32. package/cjs/http/utils/convert-to-raw-headers.js +0 -23
  33. package/cjs/http/utils/match-known-fields.js +0 -49
  34. package/cjs/http/utils/wrap-exception.js +0 -33
  35. package/cjs/type-guards.js +0 -22
  36. package/esm/augmentation/http-controller.augmentation.js +0 -23
  37. package/esm/http/express-adapter.js +0 -150
  38. package/esm/http/http-adapter.js +0 -20
  39. package/esm/http/http-context.js +0 -99
  40. package/esm/http/http-handler.js +0 -604
  41. package/esm/http/impl/http-incoming.host.js +0 -107
  42. package/esm/http/impl/http-outgoing.host.js +0 -202
  43. package/esm/http/impl/multipart-reader.js +0 -191
  44. package/esm/http/impl/node-incoming-message.host.js +0 -105
  45. package/esm/http/impl/node-outgoing-message.host.js +0 -191
  46. package/esm/http/interfaces/http-incoming.interface.js +0 -22
  47. package/esm/http/interfaces/http-outgoing.interface.js +0 -19
  48. package/esm/http/interfaces/node-incoming-message.interface.js +0 -61
  49. package/esm/http/interfaces/node-outgoing-message.interface.js +0 -12
  50. package/esm/http/utils/body-reader.js +0 -211
  51. package/esm/http/utils/common.js +0 -61
  52. package/esm/http/utils/concat-readable.js +0 -16
  53. package/esm/http/utils/convert-to-headers.js +0 -60
  54. package/esm/http/utils/convert-to-raw-headers.js +0 -20
  55. package/esm/http/utils/match-known-fields.js +0 -45
  56. package/esm/http/utils/wrap-exception.js +0 -30
  57. package/esm/type-guards.js +0 -16
  58. package/types/augmentation/http-controller.augmentation.d.ts +0 -20
  59. package/types/helpers/service-base.d.ts +0 -10
  60. package/types/http/express-adapter.d.ts +0 -13
  61. package/types/http/http-adapter.d.ts +0 -54
  62. package/types/http/http-context.d.ts +0 -44
  63. package/types/http/http-handler.d.ts +0 -75
  64. package/types/http/impl/http-incoming.host.d.ts +0 -22
  65. package/types/http/impl/http-outgoing.host.d.ts +0 -17
  66. package/types/http/impl/multipart-reader.d.ts +0 -46
  67. package/types/http/impl/node-incoming-message.host.d.ts +0 -45
  68. package/types/http/impl/node-outgoing-message.host.d.ts +0 -49
  69. package/types/http/interfaces/http-incoming.interface.d.ts +0 -192
  70. package/types/http/interfaces/http-outgoing.interface.d.ts +0 -144
  71. package/types/http/interfaces/node-incoming-message.interface.d.ts +0 -36
  72. package/types/http/interfaces/node-outgoing-message.interface.d.ts +0 -27
  73. package/types/http/utils/body-reader.d.ts +0 -38
  74. package/types/http/utils/common.d.ts +0 -17
  75. package/types/http/utils/concat-readable.d.ts +0 -2
  76. package/types/http/utils/convert-to-headers.d.ts +0 -2
  77. package/types/http/utils/convert-to-raw-headers.d.ts +0 -2
  78. package/types/http/utils/match-known-fields.d.ts +0 -6
  79. package/types/http/utils/wrap-exception.d.ts +0 -2
  80. package/types/type-guards.d.ts +0 -8
  81. /package/cjs/{http/impl/asset-cache.js → asset-cache.js} +0 -0
  82. /package/cjs/{helpers/service-base.js → service-base.js} +0 -0
  83. /package/esm/{http/impl/asset-cache.js → asset-cache.js} +0 -0
  84. /package/esm/{helpers/service-base.js → service-base.js} +0 -0
  85. /package/types/{http/impl/asset-cache.d.ts → asset-cache.d.ts} +0 -0
@@ -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;