@opra/core 1.0.0-beta.2 → 1.0.0-beta.4

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/{http/impl/asset-cache.js → asset-cache.js} +6 -0
  2. package/cjs/execution-context.js +3 -14
  3. package/cjs/index.js +3 -25
  4. package/cjs/platform-adapter.js +3 -3
  5. package/cjs/{helpers/service-base.js → service-base.js} +9 -4
  6. package/esm/{http/impl/asset-cache.js → asset-cache.js} +6 -0
  7. package/esm/execution-context.js +2 -13
  8. package/esm/index.js +3 -24
  9. package/esm/platform-adapter.js +2 -2
  10. package/esm/{helpers/service-base.js → service-base.js} +9 -4
  11. package/package.json +5 -39
  12. package/types/{http/impl/asset-cache.d.ts → asset-cache.d.ts} +1 -0
  13. package/types/execution-context.d.ts +4 -8
  14. package/types/index.d.cts +3 -23
  15. package/types/index.d.ts +3 -23
  16. package/types/interfaces/logger.interface.d.ts +1 -1
  17. package/types/platform-adapter.d.ts +3 -3
  18. package/types/service-base.d.ts +11 -0
  19. package/cjs/augmentation/http-controller.augmentation.js +0 -25
  20. package/cjs/http/express-adapter.js +0 -155
  21. package/cjs/http/http-adapter.js +0 -24
  22. package/cjs/http/http-context.js +0 -104
  23. package/cjs/http/http-handler.js +0 -609
  24. package/cjs/http/impl/http-incoming.host.js +0 -112
  25. package/cjs/http/impl/http-outgoing.host.js +0 -207
  26. package/cjs/http/impl/multipart-reader.js +0 -196
  27. package/cjs/http/impl/node-incoming-message.host.js +0 -109
  28. package/cjs/http/impl/node-outgoing-message.host.js +0 -195
  29. package/cjs/http/interfaces/http-incoming.interface.js +0 -25
  30. package/cjs/http/interfaces/http-outgoing.interface.js +0 -22
  31. package/cjs/http/interfaces/node-incoming-message.interface.js +0 -64
  32. package/cjs/http/interfaces/node-outgoing-message.interface.js +0 -15
  33. package/cjs/http/utils/body-reader.js +0 -216
  34. package/cjs/http/utils/common.js +0 -67
  35. package/cjs/http/utils/concat-readable.js +0 -19
  36. package/cjs/http/utils/convert-to-headers.js +0 -64
  37. package/cjs/http/utils/convert-to-raw-headers.js +0 -23
  38. package/cjs/http/utils/match-known-fields.js +0 -49
  39. package/cjs/http/utils/wrap-exception.js +0 -33
  40. package/cjs/type-guards.js +0 -22
  41. package/esm/augmentation/http-controller.augmentation.js +0 -23
  42. package/esm/http/express-adapter.js +0 -150
  43. package/esm/http/http-adapter.js +0 -20
  44. package/esm/http/http-context.js +0 -99
  45. package/esm/http/http-handler.js +0 -604
  46. package/esm/http/impl/http-incoming.host.js +0 -107
  47. package/esm/http/impl/http-outgoing.host.js +0 -202
  48. package/esm/http/impl/multipart-reader.js +0 -191
  49. package/esm/http/impl/node-incoming-message.host.js +0 -105
  50. package/esm/http/impl/node-outgoing-message.host.js +0 -191
  51. package/esm/http/interfaces/http-incoming.interface.js +0 -22
  52. package/esm/http/interfaces/http-outgoing.interface.js +0 -19
  53. package/esm/http/interfaces/node-incoming-message.interface.js +0 -61
  54. package/esm/http/interfaces/node-outgoing-message.interface.js +0 -12
  55. package/esm/http/utils/body-reader.js +0 -211
  56. package/esm/http/utils/common.js +0 -61
  57. package/esm/http/utils/concat-readable.js +0 -16
  58. package/esm/http/utils/convert-to-headers.js +0 -60
  59. package/esm/http/utils/convert-to-raw-headers.js +0 -20
  60. package/esm/http/utils/match-known-fields.js +0 -45
  61. package/esm/http/utils/wrap-exception.js +0 -30
  62. package/esm/type-guards.js +0 -16
  63. package/types/augmentation/http-controller.augmentation.d.ts +0 -20
  64. package/types/helpers/service-base.d.ts +0 -10
  65. package/types/http/express-adapter.d.ts +0 -13
  66. package/types/http/http-adapter.d.ts +0 -54
  67. package/types/http/http-context.d.ts +0 -44
  68. package/types/http/http-handler.d.ts +0 -75
  69. package/types/http/impl/http-incoming.host.d.ts +0 -22
  70. package/types/http/impl/http-outgoing.host.d.ts +0 -17
  71. package/types/http/impl/multipart-reader.d.ts +0 -46
  72. package/types/http/impl/node-incoming-message.host.d.ts +0 -45
  73. package/types/http/impl/node-outgoing-message.host.d.ts +0 -49
  74. package/types/http/interfaces/http-incoming.interface.d.ts +0 -192
  75. package/types/http/interfaces/http-outgoing.interface.d.ts +0 -144
  76. package/types/http/interfaces/node-incoming-message.interface.d.ts +0 -36
  77. package/types/http/interfaces/node-outgoing-message.interface.d.ts +0 -27
  78. package/types/http/utils/body-reader.d.ts +0 -38
  79. package/types/http/utils/common.d.ts +0 -17
  80. package/types/http/utils/concat-readable.d.ts +0 -2
  81. package/types/http/utils/convert-to-headers.d.ts +0 -2
  82. package/types/http/utils/convert-to-raw-headers.d.ts +0 -2
  83. package/types/http/utils/match-known-fields.d.ts +0 -6
  84. package/types/http/utils/wrap-exception.d.ts +0 -2
  85. package/types/type-guards.d.ts +0 -8
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpAdapter = void 0;
4
- const common_1 = require("@opra/common");
5
- const platform_adapter_js_1 = require("../platform-adapter.js");
6
- const http_handler_js_1 = require("./http-handler.js");
7
- /**
8
- *
9
- * @class HttpAdapter
10
- */
11
- class HttpAdapter extends platform_adapter_js_1.PlatformAdapter {
12
- constructor(document, options) {
13
- super(document, options);
14
- this.protocol = 'http';
15
- if (!(document.api instanceof common_1.HttpApi))
16
- throw new TypeError(`The document does not expose an HTTP Api`);
17
- this.handler = new http_handler_js_1.HttpHandler(this);
18
- this.interceptors = [...(options?.interceptors || [])];
19
- }
20
- get api() {
21
- return this.document.api;
22
- }
23
- }
24
- exports.HttpAdapter = HttpAdapter;
@@ -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;