@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
@@ -17,5 +17,11 @@ class AssetCache {
17
17
  }
18
18
  cache[name] = asset;
19
19
  }
20
+ delete(obj, name) {
21
+ const cache = this._items.get(obj);
22
+ if (!cache)
23
+ return;
24
+ delete cache[name];
25
+ }
20
26
  }
21
27
  exports.AssetCache = AssetCache;
@@ -1,29 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ExecutionContext = void 0;
4
- const strict_typed_events_1 = require("strict-typed-events");
4
+ const node_events_async_1 = require("node-events-async");
5
5
  /**
6
6
  * @class ExecutionContext
7
7
  */
8
- class ExecutionContext extends strict_typed_events_1.AsyncEventEmitter {
8
+ class ExecutionContext extends node_events_async_1.AsyncEventEmitter {
9
9
  constructor(init) {
10
10
  super();
11
+ this.shared = new Map();
11
12
  this.errors = [];
12
13
  this.document = init.document;
13
14
  this.protocol = init.protocol;
14
15
  this.platform = init.platform;
15
16
  }
16
- addListener(event, listener) {
17
- return super.addListener(event, listener);
18
- }
19
- removeListener(event, listener) {
20
- return super.removeListener(event, listener);
21
- }
22
- on(event, listener) {
23
- return super.on(event, listener);
24
- }
25
- off(event, listener) {
26
- return super.off(event, listener);
27
- }
28
17
  }
29
18
  exports.ExecutionContext = ExecutionContext;
package/cjs/index.js CHANGED
@@ -1,33 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.classes = void 0;
4
3
  const tslib_1 = require("tslib");
5
4
  require("reflect-metadata");
6
5
  require("./augmentation/18n.augmentation.js");
7
- require("./augmentation/http-controller.augmentation.js");
8
- const HttpIncomingHost_ = tslib_1.__importStar(require("./http/impl/http-incoming.host.js"));
9
- const HttpOutgoingHost_ = tslib_1.__importStar(require("./http/impl/http-outgoing.host.js"));
10
- const NodeIncomingMessageHost_ = tslib_1.__importStar(require("./http/impl/node-incoming-message.host.js"));
11
- const NodeOutgoingMessageHost_ = tslib_1.__importStar(require("./http/impl/node-outgoing-message.host.js"));
6
+ tslib_1.__exportStar(require("./asset-cache.js"), exports);
7
+ tslib_1.__exportStar(require("./constants.js"), exports);
12
8
  tslib_1.__exportStar(require("./execution-context.js"), exports);
13
- tslib_1.__exportStar(require("./helpers/service-base.js"), exports);
14
- tslib_1.__exportStar(require("./http/express-adapter.js"), exports);
15
- tslib_1.__exportStar(require("./http/http-adapter.js"), exports);
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);
19
- tslib_1.__exportStar(require("./http/interfaces/http-incoming.interface.js"), exports);
20
- tslib_1.__exportStar(require("./http/interfaces/http-outgoing.interface.js"), exports);
21
- tslib_1.__exportStar(require("./http/interfaces/node-incoming-message.interface.js"), exports);
22
- tslib_1.__exportStar(require("./http/interfaces/node-outgoing-message.interface.js"), exports);
23
- tslib_1.__exportStar(require("./http/utils/wrap-exception.js"), exports);
24
9
  tslib_1.__exportStar(require("./interfaces/logger.interface.js"), exports);
25
10
  tslib_1.__exportStar(require("./platform-adapter.js"), exports);
26
- tslib_1.__exportStar(require("./type-guards.js"), exports);
27
- var classes;
28
- (function (classes) {
29
- classes.HttpIncomingHost = HttpIncomingHost_.HttpIncomingHost;
30
- classes.HttpOutgoingHost = HttpOutgoingHost_.HttpOutgoingHost;
31
- classes.NodeIncomingMessageHost = NodeIncomingMessageHost_.NodeIncomingMessageHost;
32
- classes.NodeOutgoingMessageHost = NodeOutgoingMessageHost_.NodeOutgoingMessageHost;
33
- })(classes || (exports.classes = classes = {}));
11
+ tslib_1.__exportStar(require("./service-base.js"), exports);
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PlatformAdapter = void 0;
4
4
  require("./augmentation/18n.augmentation.js");
5
5
  const common_1 = require("@opra/common");
6
- const strict_typed_events_1 = require("strict-typed-events");
6
+ const node_events_async_1 = require("node-events-async");
7
+ const asset_cache_js_1 = require("./asset-cache.js");
7
8
  const constants_js_1 = require("./constants.js");
8
- const asset_cache_js_1 = require("./http/impl/asset-cache.js");
9
9
  /**
10
10
  * @class PlatformAdapter
11
11
  */
12
- class PlatformAdapter extends strict_typed_events_1.AsyncEventEmitter {
12
+ class PlatformAdapter extends node_events_async_1.AsyncEventEmitter {
13
13
  constructor(document, options) {
14
14
  super();
15
15
  this[constants_js_1.kAssetCache] = new asset_cache_js_1.AssetCache();
@@ -3,17 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ServiceBase = void 0;
4
4
  class ServiceBase {
5
5
  get context() {
6
- if (!this._context)
7
- throw new Error(`No context assigned for ${Object.getPrototypeOf(this).constructor.name}`);
6
+ this._assertContext();
8
7
  return this._context;
9
8
  }
10
9
  for(context, overwriteProperties, overwriteContext) {
11
- // Create new context instance
10
+ if (context instanceof ServiceBase)
11
+ context = context.context;
12
+ /** Create new context instance */
12
13
  const ctx = {};
13
14
  Object.setPrototypeOf(ctx, context);
14
15
  if (overwriteContext)
15
16
  Object.assign(ctx, overwriteContext);
16
- // Create new service instance
17
+ /** Create new service instance */
17
18
  const instance = { _context: ctx };
18
19
  Object.setPrototypeOf(instance, this);
19
20
  if (overwriteProperties)
@@ -22,6 +23,10 @@ class ServiceBase {
22
23
  this[ServiceBase.extendSymbol](instance);
23
24
  return instance;
24
25
  }
26
+ _assertContext() {
27
+ if (!this._context)
28
+ throw new Error(`No context assigned for ${Object.getPrototypeOf(this).constructor.name}`);
29
+ }
25
30
  }
26
31
  exports.ServiceBase = ServiceBase;
27
32
  (function (ServiceBase) {
@@ -14,4 +14,10 @@ export class AssetCache {
14
14
  }
15
15
  cache[name] = asset;
16
16
  }
17
+ delete(obj, name) {
18
+ const cache = this._items.get(obj);
19
+ if (!cache)
20
+ return;
21
+ delete cache[name];
22
+ }
17
23
  }
@@ -1,25 +1,14 @@
1
- import { AsyncEventEmitter } from 'strict-typed-events';
1
+ import { AsyncEventEmitter } from 'node-events-async';
2
2
  /**
3
3
  * @class ExecutionContext
4
4
  */
5
5
  export class ExecutionContext extends AsyncEventEmitter {
6
6
  constructor(init) {
7
7
  super();
8
+ this.shared = new Map();
8
9
  this.errors = [];
9
10
  this.document = init.document;
10
11
  this.protocol = init.protocol;
11
12
  this.platform = init.platform;
12
13
  }
13
- addListener(event, listener) {
14
- return super.addListener(event, listener);
15
- }
16
- removeListener(event, listener) {
17
- return super.removeListener(event, listener);
18
- }
19
- on(event, listener) {
20
- return super.on(event, listener);
21
- }
22
- off(event, listener) {
23
- return super.off(event, listener);
24
- }
25
14
  }
package/esm/index.js CHANGED
@@ -1,29 +1,8 @@
1
1
  import 'reflect-metadata';
2
2
  import './augmentation/18n.augmentation.js';
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';
3
+ export * from './asset-cache.js';
4
+ export * from './constants.js';
8
5
  export * from './execution-context.js';
9
- export * from './helpers/service-base.js';
10
- export * from './http/express-adapter.js';
11
- export * from './http/http-adapter.js';
12
- export * from './http/http-context.js';
13
- export * from './http/http-handler.js';
14
- export * from './http/impl/multipart-reader.js';
15
- export * from './http/interfaces/http-incoming.interface.js';
16
- export * from './http/interfaces/http-outgoing.interface.js';
17
- export * from './http/interfaces/node-incoming-message.interface.js';
18
- export * from './http/interfaces/node-outgoing-message.interface.js';
19
- export * from './http/utils/wrap-exception.js';
20
6
  export * from './interfaces/logger.interface.js';
21
7
  export * from './platform-adapter.js';
22
- export * from './type-guards.js';
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 = {}));
8
+ export * from './service-base.js';
@@ -1,8 +1,8 @@
1
1
  import './augmentation/18n.augmentation.js';
2
2
  import { I18n } from '@opra/common';
3
- import { AsyncEventEmitter } from 'strict-typed-events';
3
+ import { AsyncEventEmitter } from 'node-events-async';
4
+ import { AssetCache } from './asset-cache.js';
4
5
  import { kAssetCache } from './constants.js';
5
- import { AssetCache } from './http/impl/asset-cache.js';
6
6
  /**
7
7
  * @class PlatformAdapter
8
8
  */
@@ -1,16 +1,17 @@
1
1
  export class ServiceBase {
2
2
  get context() {
3
- if (!this._context)
4
- throw new Error(`No context assigned for ${Object.getPrototypeOf(this).constructor.name}`);
3
+ this._assertContext();
5
4
  return this._context;
6
5
  }
7
6
  for(context, overwriteProperties, overwriteContext) {
8
- // Create new context instance
7
+ if (context instanceof ServiceBase)
8
+ context = context.context;
9
+ /** Create new context instance */
9
10
  const ctx = {};
10
11
  Object.setPrototypeOf(ctx, context);
11
12
  if (overwriteContext)
12
13
  Object.assign(ctx, overwriteContext);
13
- // Create new service instance
14
+ /** Create new service instance */
14
15
  const instance = { _context: ctx };
15
16
  Object.setPrototypeOf(instance, this);
16
17
  if (overwriteProperties)
@@ -19,6 +20,10 @@ export class ServiceBase {
19
20
  this[ServiceBase.extendSymbol](instance);
20
21
  return instance;
21
22
  }
23
+ _assertContext() {
24
+ if (!this._context)
25
+ throw new Error(`No context assigned for ${Object.getPrototypeOf(this).constructor.name}`);
26
+ }
22
27
  }
23
28
  (function (ServiceBase) {
24
29
  ServiceBase.extendSymbol = Symbol('extend');
package/package.json CHANGED
@@ -1,44 +1,14 @@
1
1
  {
2
2
  "name": "@opra/core",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.4",
4
4
  "description": "Opra schema package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
- "@browsery/antlr4": "^4.13.3-r1",
9
- "@browsery/http-parser": "^0.5.9-r1",
10
- "@browsery/type-is": "^1.6.18-r5",
11
- "@opra/common": "^1.0.0-beta.2",
12
- "accepts": "^1.3.8",
13
- "base64-stream": "^1.0.0",
14
- "busboy": "^1.6.0",
15
- "bytes": "^3.1.2",
16
- "content-disposition": "^0.5.4",
17
- "content-type": "^1.0.5",
18
- "cookie": "^0.6.0",
19
- "cookie-signature": "^1.2.1",
20
- "cppzst": "^2.0.12",
21
- "encodeurl": "^2.0.0",
22
- "fast-tokenizer": "^1.7.0",
23
- "fresh": "^0.5.2",
24
- "iconv-lite": "^0.6.3",
25
- "mime-types": "^2.1.35",
26
- "power-tasks": "^1.11.0",
27
- "putil-isplainobject": "^1.1.5",
28
- "putil-merge": "^3.13.0",
29
- "putil-varhelpers": "^1.6.5",
30
- "range-parser": "^1.2.1",
31
- "raw-body": "^3.0.0",
8
+ "@opra/common": "^1.0.0-beta.4",
9
+ "node-events-async": "^1.0.0",
32
10
  "reflect-metadata": "^0.2.2",
33
- "strict-typed-events": "^2.8.0",
34
- "super-fast-md5": "^1.0.3",
35
- "tslib": "^2.7.0",
36
- "valgen": "^5.9.0",
37
- "vary": "^1.1.2"
38
- },
39
- "optionalDependencies": {
40
- "express": "^4.x.x || ^5.x.x",
41
- "fastify": "^4.x.x"
11
+ "tslib": "^2.7.0"
42
12
  },
43
13
  "type": "module",
44
14
  "exports": {
@@ -79,10 +49,6 @@
79
49
  "opra",
80
50
  "rest",
81
51
  "api",
82
- "openapi",
83
- "http",
84
- "web",
85
- "swagger",
86
- "raml"
52
+ "core"
87
53
  ]
88
54
  }
@@ -2,4 +2,5 @@ export declare class AssetCache {
2
2
  protected _items: WeakMap<any, Record<string, any>>;
3
3
  get<T>(obj: any, name: string): T | undefined;
4
4
  set(obj: any, name: string, asset: any): void;
5
+ delete(obj: any, name: string): void;
5
6
  }
@@ -1,27 +1,23 @@
1
1
  import { ApiDocument, OpraHttpError, OpraSchema } from '@opra/common';
2
- import { AsyncEventEmitter } from 'strict-typed-events';
2
+ import { AsyncEventEmitter } from 'node-events-async';
3
3
  /**
4
4
  * @namespace ExecutionContext
5
5
  */
6
6
  export declare namespace ExecutionContext {
7
7
  interface Initiator {
8
8
  document: ApiDocument;
9
- protocol: OpraSchema.Protocol;
9
+ protocol: OpraSchema.Transport;
10
10
  platform: string;
11
11
  }
12
- type OnFinishListener = (error: Error | undefined, context: ExecutionContext) => void | Promise<void>;
13
12
  }
14
13
  /**
15
14
  * @class ExecutionContext
16
15
  */
17
16
  export declare abstract class ExecutionContext extends AsyncEventEmitter {
17
+ readonly shared: Map<any, any>;
18
18
  readonly document: ApiDocument;
19
- readonly protocol: OpraSchema.Protocol;
19
+ readonly protocol: OpraSchema.Transport;
20
20
  readonly platform: string;
21
21
  errors: OpraHttpError[];
22
22
  protected constructor(init: ExecutionContext.Initiator);
23
- addListener(event: 'finish', listener: ExecutionContext.OnFinishListener): this;
24
- removeListener(event: 'finish', listener: ExecutionContext.OnFinishListener): this;
25
- on(event: 'finish', listener: ExecutionContext.OnFinishListener): this;
26
- off(event: 'finish', listener: ExecutionContext.OnFinishListener): this;
27
23
  }
package/types/index.d.cts CHANGED
@@ -1,28 +1,8 @@
1
1
  import 'reflect-metadata';
2
2
  import './augmentation/18n.augmentation.js';
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';
3
+ export * from './asset-cache.js';
4
+ export * from './constants.js';
8
5
  export * from './execution-context.js';
9
- export * from './helpers/service-base.js';
10
- export * from './http/express-adapter.js';
11
- export * from './http/http-adapter.js';
12
- export * from './http/http-context.js';
13
- export * from './http/http-handler.js';
14
- export * from './http/impl/multipart-reader.js';
15
- export * from './http/interfaces/http-incoming.interface.js';
16
- export * from './http/interfaces/http-outgoing.interface.js';
17
- export * from './http/interfaces/node-incoming-message.interface.js';
18
- export * from './http/interfaces/node-outgoing-message.interface.js';
19
- export * from './http/utils/wrap-exception.js';
20
6
  export * from './interfaces/logger.interface.js';
21
7
  export * from './platform-adapter.js';
22
- export * from './type-guards.js';
23
- export declare namespace classes {
24
- export import HttpIncomingHost = HttpIncomingHost_.HttpIncomingHost;
25
- export import HttpOutgoingHost = HttpOutgoingHost_.HttpOutgoingHost;
26
- export import NodeIncomingMessageHost = NodeIncomingMessageHost_.NodeIncomingMessageHost;
27
- export import NodeOutgoingMessageHost = NodeOutgoingMessageHost_.NodeOutgoingMessageHost;
28
- }
8
+ export * from './service-base.js';
package/types/index.d.ts CHANGED
@@ -1,28 +1,8 @@
1
1
  import 'reflect-metadata';
2
2
  import './augmentation/18n.augmentation.js';
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';
3
+ export * from './asset-cache.js';
4
+ export * from './constants.js';
8
5
  export * from './execution-context.js';
9
- export * from './helpers/service-base.js';
10
- export * from './http/express-adapter.js';
11
- export * from './http/http-adapter.js';
12
- export * from './http/http-context.js';
13
- export * from './http/http-handler.js';
14
- export * from './http/impl/multipart-reader.js';
15
- export * from './http/interfaces/http-incoming.interface.js';
16
- export * from './http/interfaces/http-outgoing.interface.js';
17
- export * from './http/interfaces/node-incoming-message.interface.js';
18
- export * from './http/interfaces/node-outgoing-message.interface.js';
19
- export * from './http/utils/wrap-exception.js';
20
6
  export * from './interfaces/logger.interface.js';
21
7
  export * from './platform-adapter.js';
22
- export * from './type-guards.js';
23
- export declare namespace classes {
24
- export import HttpIncomingHost = HttpIncomingHost_.HttpIncomingHost;
25
- export import HttpOutgoingHost = HttpOutgoingHost_.HttpOutgoingHost;
26
- export import NodeIncomingMessageHost = NodeIncomingMessageHost_.NodeIncomingMessageHost;
27
- export import NodeOutgoingMessageHost = NodeOutgoingMessageHost_.NodeOutgoingMessageHost;
28
- }
8
+ export * from './service-base.js';
@@ -1,8 +1,8 @@
1
1
  export interface ILogger {
2
+ error(message: any, ...optionalParams: any[]): void;
2
3
  log?(message: any, ...optionalParams: any[]): void;
3
4
  info?(message: any, ...optionalParams: any[]): void;
4
5
  warn?(message: any, ...optionalParams: any[]): void;
5
- error?(message: any, ...optionalParams: any[]): void;
6
6
  fatal?(message: any, ...optionalParams: any[]): void;
7
7
  debug?(message: any, ...optionalParams: any[]): void;
8
8
  verbose?(message: any, ...optionalParams: any[]): void;
@@ -1,8 +1,8 @@
1
1
  import './augmentation/18n.augmentation.js';
2
2
  import { ApiDocument, I18n, OpraSchema } from '@opra/common';
3
- import { AsyncEventEmitter } from 'strict-typed-events';
3
+ import { AsyncEventEmitter } from 'node-events-async';
4
+ import { AssetCache } from './asset-cache.js';
4
5
  import { kAssetCache } from './constants.js';
5
- import { AssetCache } from './http/impl/asset-cache.js';
6
6
  /**
7
7
  * @namespace PlatformAdapter
8
8
  */
@@ -17,7 +17,7 @@ export declare namespace PlatformAdapter {
17
17
  export declare abstract class PlatformAdapter extends AsyncEventEmitter {
18
18
  protected [kAssetCache]: AssetCache;
19
19
  readonly document: ApiDocument;
20
- abstract readonly protocol: OpraSchema.Protocol;
20
+ abstract readonly protocol: OpraSchema.Transport;
21
21
  i18n: I18n;
22
22
  protected constructor(document: ApiDocument, options?: PlatformAdapter.Options);
23
23
  abstract close(): Promise<void>;
@@ -0,0 +1,11 @@
1
+ import type { Nullish } from 'ts-gems';
2
+ import type { ExecutionContext } from './execution-context.js';
3
+ export declare abstract class ServiceBase {
4
+ protected _context: ExecutionContext;
5
+ get context(): ExecutionContext;
6
+ for<C extends ExecutionContext, P extends Partial<this>>(context: C | ServiceBase, overwriteProperties?: Nullish<P>, overwriteContext?: Partial<C>): this & Required<P>;
7
+ protected _assertContext(): void;
8
+ }
9
+ export declare namespace ServiceBase {
10
+ const extendSymbol: unique symbol;
11
+ }
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const common_1 = require("@opra/common");
4
- // @ts-ignore
5
- const oldInitialize = common_1.HttpController.prototype._initialize;
6
- // @ts-ignore
7
- common_1.HttpController.prototype._initialize = function (initArgs) {
8
- oldInitialize?.call(this, initArgs);
9
- this.onInit = initArgs.onInit;
10
- this.onShutdown = initArgs.onShutdown;
11
- };
12
- common_1.HttpController.OnInit = function () {
13
- return (target, propertyKey) => {
14
- const sourceMetadata = (Reflect.getOwnMetadata(common_1.HTTP_CONTROLLER_METADATA, target.constructor) || {});
15
- sourceMetadata.onInit = target[propertyKey];
16
- Reflect.defineMetadata(common_1.HTTP_CONTROLLER_METADATA, target.constructor, sourceMetadata);
17
- };
18
- };
19
- common_1.HttpController.OnShutdown = function () {
20
- return (target, propertyKey) => {
21
- const sourceMetadata = (Reflect.getOwnMetadata(common_1.HTTP_CONTROLLER_METADATA, target.constructor) || {});
22
- sourceMetadata.onShutdown = target[propertyKey];
23
- Reflect.defineMetadata(common_1.HTTP_CONTROLLER_METADATA, target.constructor, sourceMetadata);
24
- };
25
- };
@@ -1,155 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExpressAdapter = void 0;
4
- const tslib_1 = require("tslib");
5
- const nodePath = tslib_1.__importStar(require("node:path"));
6
- const common_1 = require("@opra/common");
7
- const express_1 = require("express");
8
- const http_adapter_js_1 = require("./http-adapter.js");
9
- const http_context_js_1 = require("./http-context.js");
10
- const http_incoming_interface_js_1 = require("./interfaces/http-incoming.interface.js");
11
- const http_outgoing_interface_js_1 = require("./interfaces/http-outgoing.interface.js");
12
- const wrap_exception_js_1 = require("./utils/wrap-exception.js");
13
- class ExpressAdapter extends http_adapter_js_1.HttpAdapter {
14
- constructor(app, document, options) {
15
- super(document, options);
16
- this._controllerInstances = new Map();
17
- this.app = app;
18
- if (!(this.document.api instanceof common_1.HttpApi))
19
- throw new TypeError('document.api must be instance of HttpApi');
20
- for (const c of this.api.controllers.values())
21
- this._createControllers(c);
22
- this._initRouter(options?.basePath);
23
- }
24
- get platform() {
25
- return 'express';
26
- }
27
- async close() {
28
- const processResource = async (resource) => {
29
- if (resource.controllers.size) {
30
- const subResources = Array.from(resource.controllers.values());
31
- subResources.reverse();
32
- for (const subResource of subResources) {
33
- await processResource(subResource);
34
- }
35
- }
36
- if (resource.onShutdown) {
37
- const instance = this._controllerInstances.get(resource) || resource.instance;
38
- if (instance) {
39
- try {
40
- await resource.onShutdown.call(instance, resource);
41
- }
42
- catch (e) {
43
- if (this.listenerCount('error'))
44
- this.emit('error', (0, wrap_exception_js_1.wrapException)(e));
45
- }
46
- }
47
- }
48
- };
49
- for (const c of this.api.controllers.values())
50
- await processResource(c);
51
- this._controllerInstances.clear();
52
- }
53
- getControllerInstance(controllerPath) {
54
- const controller = this.api.findController(controllerPath);
55
- return controller && this._controllerInstances.get(controller);
56
- }
57
- _initRouter(basePath) {
58
- const router = (0, express_1.Router)();
59
- if (basePath) {
60
- if (!basePath.startsWith('/'))
61
- basePath = '/' + basePath;
62
- if (basePath)
63
- this.app.use(basePath, router);
64
- }
65
- else
66
- this.app.use(router);
67
- const createContext = async (_req, _res, args) => {
68
- const request = http_incoming_interface_js_1.HttpIncoming.from(_req);
69
- const response = http_outgoing_interface_js_1.HttpOutgoing.from(_res);
70
- const ctx = new http_context_js_1.HttpContext({
71
- adapter: this,
72
- platform: this.platform,
73
- request,
74
- response,
75
- controller: args?.controller,
76
- controllerInstance: args?.controllerInstance,
77
- operation: args?.operation,
78
- operationHandler: args?.operationHandler,
79
- });
80
- await this.emitAsync('createContext', ctx);
81
- return ctx;
82
- };
83
- /** Add an endpoint that returns document schema */
84
- router.get('/\\$schema', (_req, _res, next) => {
85
- createContext(_req, _res)
86
- .then(ctx => this.handler.sendDocumentSchema(ctx).catch(next))
87
- .catch(next);
88
- });
89
- /** Add operation endpoints */
90
- if (this.api.controllers.size) {
91
- const processResource = (controller, currentPath) => {
92
- currentPath = nodePath.join(currentPath, controller.path);
93
- for (const operation of controller.operations.values()) {
94
- const routePath = currentPath + (operation.path || '');
95
- const controllerInstance = this._controllerInstances.get(controller);
96
- const operationHandler = controllerInstance[operation.name];
97
- if (!operationHandler)
98
- continue;
99
- /** Define router callback */
100
- router[operation.method.toLowerCase()](routePath, (_req, _res, _next) => {
101
- createContext(_req, _res, {
102
- controller,
103
- controllerInstance,
104
- operation,
105
- operationHandler,
106
- })
107
- .then(ctx => this.handler.handleRequest(ctx))
108
- .then(() => {
109
- if (!_res.headersSent)
110
- _next();
111
- })
112
- .catch((e) => this.emit('error', e));
113
- });
114
- }
115
- if (controller.controllers.size) {
116
- for (const child of controller.controllers.values())
117
- processResource(child, currentPath);
118
- }
119
- };
120
- for (const c of this.api.controllers.values())
121
- processResource(c, '/');
122
- }
123
- /** Add an endpoint that returns 404 error at last */
124
- router.use('*', (_req, _res, next) => {
125
- createContext(_req, _res)
126
- .then(ctx => {
127
- ctx.errors.push(new common_1.NotFoundError({
128
- message: `No endpoint found at [${_req.method}]${_req.baseUrl}`,
129
- details: {
130
- path: _req.baseUrl,
131
- method: _req.method,
132
- },
133
- }));
134
- this.handler.sendResponse(ctx).catch(next);
135
- })
136
- .catch(next);
137
- });
138
- }
139
- _createControllers(controller) {
140
- let instance = controller.instance;
141
- if (!instance && controller.ctor)
142
- instance = new controller.ctor();
143
- if (instance) {
144
- if (typeof instance.onInit === 'function')
145
- instance.onInit.call(instance, this);
146
- this._controllerInstances.set(controller, instance);
147
- // Initialize sub resources
148
- for (const r of controller.controllers.values()) {
149
- this._createControllers(r);
150
- }
151
- }
152
- return instance;
153
- }
154
- }
155
- exports.ExpressAdapter = ExpressAdapter;