@opra/common 1.19.4 → 1.19.7

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 (109) hide show
  1. package/browser/index.cjs +5 -5
  2. package/browser/index.mjs +5 -5
  3. package/cjs/document/api-document.js +11 -4
  4. package/cjs/document/constants.js +3 -1
  5. package/cjs/document/data-type/enum-type.js +4 -0
  6. package/cjs/document/decorators/{rpc-controller.decorator.js → mq-controller.decorator.js} +8 -8
  7. package/cjs/document/decorators/{rpc-operation.decorator.js → mq-operation.decorator.js} +6 -6
  8. package/cjs/document/decorators/ws-controller.decorator.js +51 -0
  9. package/cjs/document/decorators/ws-operation.decorator.js +43 -0
  10. package/cjs/document/factory/api-document.factory.js +3 -3
  11. package/cjs/document/factory/{rpc-api.factory.js → mq-api.factory.js} +28 -28
  12. package/cjs/document/factory/ws-api.factory.js +123 -0
  13. package/cjs/document/index.js +15 -8
  14. package/cjs/document/{rpc/rpc-api.js → mq/mq-api.js} +5 -5
  15. package/cjs/document/{rpc/rpc-controller.js → mq/mq-controller.js} +14 -14
  16. package/cjs/document/{rpc/rpc-header.js → mq/mq-header.js} +5 -5
  17. package/cjs/document/{rpc/rpc-operation-response.js → mq/mq-operation-response.js} +4 -4
  18. package/cjs/document/{rpc/rpc-operation.js → mq/mq-operation.js} +10 -10
  19. package/cjs/document/ws/ws-api.js +52 -0
  20. package/cjs/document/ws/ws-controller.js +78 -0
  21. package/cjs/document/ws/ws-operation.js +62 -0
  22. package/cjs/filter/antlr/OpraFilterLexer.js +361 -211
  23. package/cjs/filter/antlr/OpraFilterParser.js +174 -92
  24. package/cjs/schema/http/http-api.interface.js +2 -0
  25. package/cjs/schema/mq/mq-api.interface.js +2 -0
  26. package/cjs/schema/mq/mq-controller.interface.js +11 -0
  27. package/cjs/schema/mq/mq-header.interface.js +2 -0
  28. package/cjs/schema/mq/mq-operation.interface.js +7 -0
  29. package/cjs/schema/opra-schema.js +9 -3
  30. package/cjs/schema/ws/ws-api.interface.js +2 -0
  31. package/cjs/schema/ws/ws-controller.interface.js +11 -0
  32. package/cjs/schema/ws/ws-operation.interface.js +7 -0
  33. package/esm/document/api-document.js +11 -4
  34. package/esm/document/constants.js +2 -0
  35. package/esm/document/data-type/enum-type.js +4 -0
  36. package/esm/document/decorators/{rpc-controller.decorator.js → mq-controller.decorator.js} +8 -8
  37. package/esm/document/decorators/{rpc-operation.decorator.js → mq-operation.decorator.js} +6 -6
  38. package/esm/document/decorators/ws-controller.decorator.js +48 -0
  39. package/esm/document/decorators/ws-operation.decorator.js +40 -0
  40. package/esm/document/factory/api-document.factory.js +3 -3
  41. package/esm/document/factory/{rpc-api.factory.js → mq-api.factory.js} +27 -27
  42. package/esm/document/factory/ws-api.factory.js +119 -0
  43. package/esm/document/index.js +15 -8
  44. package/esm/document/{rpc/rpc-api.js → mq/mq-api.js} +3 -3
  45. package/esm/document/{rpc/rpc-controller.js → mq/mq-controller.js} +13 -13
  46. package/esm/document/{rpc/rpc-header.js → mq/mq-header.js} +4 -4
  47. package/esm/document/{rpc/rpc-operation-response.js → mq/mq-operation-response.js} +2 -2
  48. package/esm/document/{rpc/rpc-operation.js → mq/mq-operation.js} +9 -9
  49. package/esm/document/ws/ws-api.js +48 -0
  50. package/esm/document/ws/ws-controller.js +75 -0
  51. package/esm/document/ws/ws-operation.js +59 -0
  52. package/esm/filter/antlr/OpraFilterLexer.js +362 -212
  53. package/esm/filter/antlr/OpraFilterListener.js +1 -1
  54. package/esm/filter/antlr/OpraFilterParser.js +174 -92
  55. package/esm/schema/http/http-api.interface.js +1 -0
  56. package/esm/schema/mq/mq-api.interface.js +1 -0
  57. package/esm/schema/mq/mq-controller.interface.js +8 -0
  58. package/esm/schema/mq/mq-header.interface.js +1 -0
  59. package/esm/schema/mq/mq-operation.interface.js +4 -0
  60. package/esm/schema/opra-schema.js +9 -3
  61. package/esm/schema/ws/ws-api.interface.js +1 -0
  62. package/esm/schema/ws/ws-controller.interface.js +8 -0
  63. package/esm/schema/ws/ws-operation.interface.js +4 -0
  64. package/package.json +6 -6
  65. package/types/document/api-document.d.ts +5 -3
  66. package/types/document/constants.d.ts +2 -0
  67. package/types/document/decorators/mq-controller.decorator.d.ts +20 -0
  68. package/types/document/decorators/mq-operation.decorator.d.ts +32 -0
  69. package/types/document/decorators/ws-controller.decorator.d.ts +20 -0
  70. package/types/document/decorators/ws-operation.decorator.d.ts +24 -0
  71. package/types/document/factory/api-document.factory.d.ts +3 -2
  72. package/types/document/factory/mq-api.factory.d.ts +40 -0
  73. package/types/document/factory/ws-api.factory.d.ts +31 -0
  74. package/types/document/index.d.ts +20 -11
  75. package/types/document/mq/mq-api.d.ts +27 -0
  76. package/types/document/mq/mq-controller.d.ts +83 -0
  77. package/types/document/{rpc/rpc-header.d.ts → mq/mq-header.d.ts} +15 -15
  78. package/types/document/{rpc/rpc-operation-response.d.ts → mq/mq-operation-response.d.ts} +13 -13
  79. package/types/document/{rpc/rpc-operation.d.ts → mq/mq-operation.d.ts} +27 -27
  80. package/types/document/ws/ws-api.d.ts +26 -0
  81. package/types/document/ws/ws-controller.d.ts +79 -0
  82. package/types/document/ws/ws-operation.d.ts +70 -0
  83. package/types/filter/antlr/OpraFilterLexer.d.ts +1 -1
  84. package/types/filter/antlr/OpraFilterListener.d.ts +28 -28
  85. package/types/filter/antlr/OpraFilterVisitor.d.ts +27 -27
  86. package/types/schema/api-document.interface.d.ts +4 -46
  87. package/types/schema/api.interface.d.ts +13 -0
  88. package/types/schema/http/http-api.interface.d.ts +12 -0
  89. package/types/schema/mq/mq-api.interface.d.ts +15 -0
  90. package/types/schema/mq/mq-controller.interface.d.ts +22 -0
  91. package/types/schema/{rpc/rpc-header.interface.d.ts → mq/mq-header.interface.d.ts} +2 -2
  92. package/types/schema/{rpc/rpc-operation.interface.d.ts → mq/mq-operation.interface.d.ts} +11 -11
  93. package/types/schema/opra-schema.d.ts +9 -3
  94. package/types/schema/types.d.ts +11 -0
  95. package/types/schema/ws/ws-api.interface.d.ts +11 -0
  96. package/types/schema/ws/ws-controller.interface.d.ts +20 -0
  97. package/types/schema/ws/ws-operation.interface.d.ts +15 -0
  98. package/cjs/schema/rpc/rpc-controller.interface.js +0 -11
  99. package/cjs/schema/rpc/rpc-operation.interface.js +0 -7
  100. package/esm/schema/rpc/rpc-controller.interface.js +0 -8
  101. package/esm/schema/rpc/rpc-operation.interface.js +0 -4
  102. package/types/document/decorators/rpc-controller.decorator.d.ts +0 -20
  103. package/types/document/decorators/rpc-operation.decorator.d.ts +0 -32
  104. package/types/document/factory/rpc-api.factory.d.ts +0 -40
  105. package/types/document/rpc/rpc-api.d.ts +0 -27
  106. package/types/document/rpc/rpc-controller.d.ts +0 -83
  107. package/types/schema/rpc/rpc-controller.interface.d.ts +0 -22
  108. /package/cjs/schema/{rpc/rpc-header.interface.js → api.interface.js} +0 -0
  109. /package/esm/schema/{rpc/rpc-header.interface.js → api.interface.js} +0 -0
@@ -8,7 +8,7 @@ import * as extendedTypes from '../data-type/extended-types/index.js';
8
8
  import * as primitiveTypes from '../data-type/primitive-types/index.js';
9
9
  import { DataTypeFactory } from './data-type.factory.js';
10
10
  import { HttpApiFactory } from './http-api.factory.js';
11
- import { RpcApiFactory } from './rpc-api.factory.js';
11
+ import { MQApiFactory } from './mq-api.factory.js';
12
12
  const OPRA_SPEC_URL = 'https://oprajs.com/spec/v' + OpraSchema.SpecVersion;
13
13
  /**
14
14
  * @class ApiDocumentFactory
@@ -119,8 +119,8 @@ export class ApiDocumentFactory {
119
119
  if (api)
120
120
  document.api = api;
121
121
  }
122
- else if (init.api && init.api.transport === 'rpc') {
123
- const api = await RpcApiFactory.createApi(context, {
122
+ else if (init.api && init.api.transport === 'mq') {
123
+ const api = await MQApiFactory.createApi(context, {
124
124
  ...init.api,
125
125
  owner: document,
126
126
  });
@@ -1,23 +1,23 @@
1
1
  import { isConstructor } from '@jsopen/objects';
2
2
  import { resolveThunk } from '../../helpers/index.js';
3
- import { RPC_CONTROLLER_METADATA } from '../constants.js';
4
- import { RpcApi } from '../rpc/rpc-api.js';
5
- import { RpcController } from '../rpc/rpc-controller.js';
6
- import { RpcHeader } from '../rpc/rpc-header.js';
7
- import { RpcOperation } from '../rpc/rpc-operation.js';
8
- import { RpcOperationResponse } from '../rpc/rpc-operation-response.js';
3
+ import { MQ_CONTROLLER_METADATA } from '../constants.js';
4
+ import { MQApi } from '../mq/mq-api.js';
5
+ import { MQController } from '../mq/mq-controller.js';
6
+ import { MQHeader } from '../mq/mq-header.js';
7
+ import { MQOperation } from '../mq/mq-operation.js';
8
+ import { MQOperationResponse } from '../mq/mq-operation-response.js';
9
9
  import { DataTypeFactory } from './data-type.factory.js';
10
10
  /**
11
- * @class RpcApiFactory
11
+ * @class MQApiFactory
12
12
  */
13
- export class RpcApiFactory {
13
+ export class MQApiFactory {
14
14
  /**
15
- * Generates RpcApi
15
+ * Generates MQApi
16
16
  * @param context
17
17
  * @param init
18
18
  */
19
19
  static async createApi(context, init) {
20
- const api = new RpcApi(init);
20
+ const api = new MQApi(init);
21
21
  if (init.controllers) {
22
22
  await context.enterAsync('.controllers', async () => {
23
23
  if (Array.isArray(init.controllers)) {
@@ -48,15 +48,15 @@ export class RpcApiFactory {
48
48
  let instance;
49
49
  // If thunk is a class
50
50
  if (typeof thunk === 'function') {
51
- metadata = Reflect.getMetadata(RPC_CONTROLLER_METADATA, thunk);
51
+ metadata = Reflect.getMetadata(MQ_CONTROLLER_METADATA, thunk);
52
52
  if (!metadata)
53
- return context.addError(`Class "${thunk.name}" doesn't have a valid RpcController metadata`);
53
+ return context.addError(`Class "${thunk.name}" doesn't have a valid MQController metadata`);
54
54
  ctor = thunk;
55
55
  }
56
56
  else {
57
- // If thunk is an instance of a class decorated with RpcController()
57
+ // If thunk is an instance of a class decorated with MQController()
58
58
  ctor = Object.getPrototypeOf(thunk).constructor;
59
- metadata = Reflect.getMetadata(RPC_CONTROLLER_METADATA, ctor);
59
+ metadata = Reflect.getMetadata(MQ_CONTROLLER_METADATA, ctor);
60
60
  if (metadata)
61
61
  instance = thunk;
62
62
  else {
@@ -69,11 +69,11 @@ export class RpcApiFactory {
69
69
  }
70
70
  }
71
71
  if (!metadata)
72
- return context.addError(`Class "${ctor.name}" is not decorated with RpcController()`);
72
+ return context.addError(`Class "${ctor.name}" is not decorated with MQController()`);
73
73
  name = name || metadata.name;
74
74
  if (!name)
75
75
  throw new TypeError(`Controller name required`);
76
- const controller = new RpcController(parent, {
76
+ const controller = new MQController(parent, {
77
77
  ...metadata,
78
78
  name,
79
79
  instance,
@@ -99,7 +99,7 @@ export class RpcApiFactory {
99
99
  if (!prmArgs.type)
100
100
  prmArgs.type = controller.node.getDataType('any');
101
101
  });
102
- const prm = new RpcHeader(controller, prmArgs);
102
+ const prm = new MQHeader(controller, prmArgs);
103
103
  controller.headers.push(prm);
104
104
  });
105
105
  }
@@ -109,14 +109,14 @@ export class RpcApiFactory {
109
109
  await context.enterAsync('.operations', async () => {
110
110
  for (const [operationName, operationMeta] of Object.entries(metadata.operations)) {
111
111
  await context.enterAsync(`[${operationName}]`, async () => {
112
- const operation = new RpcOperation(controller, {
112
+ const operation = new MQOperation(controller, {
113
113
  ...operationMeta,
114
114
  name: operationName,
115
115
  types: undefined,
116
116
  payloadType: undefined,
117
117
  keyType: undefined,
118
118
  });
119
- await this._initRpcOperation(context, operation, operationMeta);
119
+ await this._initMQOperation(context, operation, operationMeta);
120
120
  controller.operations.set(operation.name, operation);
121
121
  });
122
122
  }
@@ -125,13 +125,13 @@ export class RpcApiFactory {
125
125
  return controller;
126
126
  }
127
127
  /**
128
- * Initializes RpcOperation
128
+ * Initializes MQOperation
129
129
  * @param context
130
130
  * @param operation
131
131
  * @param metadata
132
132
  * @protected
133
133
  */
134
- static async _initRpcOperation(context, operation, metadata) {
134
+ static async _initMQOperation(context, operation, metadata) {
135
135
  if (metadata.types) {
136
136
  await context.enterAsync('.types', async () => {
137
137
  await DataTypeFactory.addDataTypes(context, operation, metadata.types);
@@ -150,7 +150,7 @@ export class RpcApiFactory {
150
150
  await context.enterAsync('.type', async () => {
151
151
  prmArgs.type = await DataTypeFactory.resolveDataType(context, operation, v.type);
152
152
  });
153
- const prm = new RpcHeader(operation, prmArgs);
153
+ const prm = new MQHeader(operation, prmArgs);
154
154
  operation.headers.push(prm);
155
155
  });
156
156
  }
@@ -158,24 +158,24 @@ export class RpcApiFactory {
158
158
  }
159
159
  if (metadata.response) {
160
160
  await context.enterAsync('.response', async () => {
161
- const response = new RpcOperationResponse(operation, {
161
+ const response = new MQOperationResponse(operation, {
162
162
  ...metadata.response,
163
163
  payloadType: undefined,
164
164
  keyType: undefined,
165
165
  });
166
- await this._initRpcOperationResponse(context, response, metadata.response);
166
+ await this._initMQOperationResponse(context, response, metadata.response);
167
167
  operation.response = response;
168
168
  });
169
169
  }
170
170
  }
171
171
  /**
172
- * Initializes RpcOperationResponse
172
+ * Initializes MQOperationResponse
173
173
  * @param context
174
174
  * @param response
175
175
  * @param metadata
176
176
  * @protected
177
177
  */
178
- static async _initRpcOperationResponse(context, response, metadata) {
178
+ static async _initMQOperationResponse(context, response, metadata) {
179
179
  response.payloadType = await DataTypeFactory.resolveDataType(context, response, metadata.payloadType);
180
180
  if (metadata.keyType) {
181
181
  response.keyType = await DataTypeFactory.resolveDataType(context, response, metadata.keyType);
@@ -189,7 +189,7 @@ export class RpcApiFactory {
189
189
  await context.enterAsync('.type', async () => {
190
190
  prmArgs.type = await DataTypeFactory.resolveDataType(context, response, v.type);
191
191
  });
192
- const prm = new RpcHeader(response, prmArgs);
192
+ const prm = new MQHeader(response, prmArgs);
193
193
  response.headers.push(prm);
194
194
  });
195
195
  }
@@ -0,0 +1,119 @@
1
+ import { isConstructor } from '@jsopen/objects';
2
+ import { resolveThunk } from '../../helpers/index.js';
3
+ import { WS_CONTROLLER_METADATA } from '../constants.js';
4
+ import { WSApi } from '../ws/ws-api.js';
5
+ import { WSController } from '../ws/ws-controller.js';
6
+ import { WSOperation } from '../ws/ws-operation.js';
7
+ import { DataTypeFactory } from './data-type.factory.js';
8
+ /**
9
+ * @class WSApiFactory
10
+ */
11
+ export class WSApiFactory {
12
+ /**
13
+ * Generates MQApi
14
+ * @param context
15
+ * @param init
16
+ */
17
+ static async createApi(context, init) {
18
+ const api = new WSApi(init);
19
+ if (init.controllers) {
20
+ await context.enterAsync('.controllers', async () => {
21
+ if (Array.isArray(init.controllers)) {
22
+ for (const c of init.controllers) {
23
+ const controller = await this._createController(context, api, c);
24
+ if (controller)
25
+ api.controllers.set(controller.name, controller);
26
+ }
27
+ }
28
+ else {
29
+ for (const [k, v] of Object.entries(init.controllers)) {
30
+ const controller = await this._createController(context, api, v, k);
31
+ if (controller)
32
+ api.controllers.set(controller.name, controller);
33
+ }
34
+ }
35
+ });
36
+ }
37
+ return api;
38
+ }
39
+ static async _createController(context, parent, thunk, name) {
40
+ if (typeof thunk === 'function' && !isConstructor(thunk)) {
41
+ thunk = thunk();
42
+ }
43
+ thunk = await resolveThunk(thunk);
44
+ let ctor;
45
+ let metadata;
46
+ let instance;
47
+ // If thunk is a class
48
+ if (typeof thunk === 'function') {
49
+ metadata = Reflect.getMetadata(WS_CONTROLLER_METADATA, thunk);
50
+ if (!metadata)
51
+ return context.addError(`Class "${thunk.name}" doesn't have a valid WSController metadata`);
52
+ ctor = thunk;
53
+ }
54
+ else {
55
+ // If thunk is an instance of a class decorated with WSController()
56
+ ctor = Object.getPrototypeOf(thunk).constructor;
57
+ metadata = Reflect.getMetadata(WS_CONTROLLER_METADATA, ctor);
58
+ if (metadata)
59
+ instance = thunk;
60
+ else {
61
+ // If thunk is a DecoratorMetadata or InitArguments
62
+ metadata = thunk;
63
+ if (thunk.instance === 'object') {
64
+ instance = thunk.instance;
65
+ ctor = Object.getPrototypeOf(instance).constructor;
66
+ }
67
+ }
68
+ }
69
+ if (!metadata)
70
+ return context.addError(`Class "${ctor.name}" is not decorated with WSController()`);
71
+ name = name || metadata.name;
72
+ if (!name)
73
+ throw new TypeError(`Controller name required`);
74
+ const controller = new WSController(parent, {
75
+ ...metadata,
76
+ name,
77
+ instance,
78
+ ctor,
79
+ });
80
+ if (metadata.types) {
81
+ await context.enterAsync('.types', async () => {
82
+ await DataTypeFactory.addDataTypes(context, controller, metadata.types);
83
+ });
84
+ }
85
+ if (metadata.operations) {
86
+ await context.enterAsync('.operations', async () => {
87
+ for (const [operationName, operationMeta] of Object.entries(metadata.operations)) {
88
+ await context.enterAsync(`[${operationName}]`, async () => {
89
+ const operation = new WSOperation(controller, {
90
+ ...operationMeta,
91
+ name: operationName,
92
+ types: undefined,
93
+ payloadType: undefined,
94
+ keyType: undefined,
95
+ });
96
+ await this._initWSOperation(context, operation, operationMeta);
97
+ controller.operations.set(operation.name, operation);
98
+ });
99
+ }
100
+ });
101
+ }
102
+ return controller;
103
+ }
104
+ /**
105
+ * Initializes WSOperation
106
+ * @param context
107
+ * @param operation
108
+ * @param metadata
109
+ * @protected
110
+ */
111
+ static async _initWSOperation(context, operation, metadata) {
112
+ if (metadata.types) {
113
+ await context.enterAsync('.types', async () => {
114
+ await DataTypeFactory.addDataTypes(context, operation, metadata.types);
115
+ });
116
+ }
117
+ operation.payloadType = await DataTypeFactory.resolveDataType(context, operation, metadata.payloadType);
118
+ }
119
+ }
@@ -8,8 +8,10 @@ import './decorators/http-operation-entity-get.decorator.js';
8
8
  import './decorators/http-operation-entity-replace.decorator.js';
9
9
  import './decorators/http-operation-entity-update.decorator.js';
10
10
  import './decorators/http-operation-entity-update-many.decorator.js';
11
- import * as RpcControllerDecorator_ from './decorators/rpc-controller.decorator.js';
12
- import * as RpcOperationDecorator_ from './decorators/rpc-operation.decorator.js';
11
+ import * as MQControllerDecorator_ from './decorators/mq-controller.decorator.js';
12
+ import * as MQOperationDecorator_ from './decorators/mq-operation.decorator.js';
13
+ import * as WSControllerDecorator_ from './decorators/ws-controller.decorator.js';
14
+ import * as WSOperationDecorator_ from './decorators/ws-operation.decorator.js';
13
15
  import * as DataTypeFactory_ from './factory/data-type.factory.js';
14
16
  import * as HttpApiFactory_ from './factory/http-api.factory.js';
15
17
  export * from './api-document.js';
@@ -44,14 +46,19 @@ export * from './http/http-operation-response.js';
44
46
  export * from './http/http-parameter.js';
45
47
  export * from './http/http-request-body.js';
46
48
  export * from './http/http-status-range.js';
47
- export * from './rpc/rpc-api.js';
48
- export * from './rpc/rpc-controller.js';
49
- export * from './rpc/rpc-header.js';
50
- export * from './rpc/rpc-operation.js';
49
+ export * from './mq/mq-api.js';
50
+ export * from './mq/mq-controller.js';
51
+ export * from './mq/mq-header.js';
52
+ export * from './mq/mq-operation.js';
53
+ export * from './ws/ws-api.js';
54
+ export * from './ws/ws-controller.js';
55
+ export * from './ws/ws-operation.js';
51
56
  export var classes;
52
57
  (function (classes) {
53
58
  classes.HttpApiFactory = HttpApiFactory_.HttpApiFactory;
54
59
  classes.DataTypeFactory = DataTypeFactory_.DataTypeFactory;
55
- classes.RpcOperationDecoratorFactory = RpcOperationDecorator_.RpcOperationDecoratorFactory;
56
- classes.RpcControllerDecoratorFactory = RpcControllerDecorator_.RpcControllerDecoratorFactory;
60
+ classes.MQOperationDecoratorFactory = MQOperationDecorator_.MQOperationDecoratorFactory;
61
+ classes.MQControllerDecoratorFactory = MQControllerDecorator_.MQControllerDecoratorFactory;
62
+ classes.WSOperationDecoratorFactory = WSOperationDecorator_.WSOperationDecoratorFactory;
63
+ classes.WSControllerDecoratorFactory = WSControllerDecorator_.WSControllerDecoratorFactory;
57
64
  })(classes || (classes = {}));
@@ -1,14 +1,14 @@
1
1
  import { ResponsiveMap } from '../../helpers/index.js';
2
2
  import { ApiBase } from '../common/api-base.js';
3
3
  /**
4
- * @class RpcApi
4
+ * @class MQApi
5
5
  */
6
- export class RpcApi extends ApiBase {
6
+ export class MQApi extends ApiBase {
7
7
  constructor(init) {
8
8
  super(init);
9
9
  // noinspection JSUnusedGlobalSymbols
10
10
  this._controllerReverseMap = new WeakMap();
11
- this.transport = 'rpc';
11
+ this.transport = 'mq';
12
12
  this.controllers = new ResponsiveMap();
13
13
  this.platform = init.platform;
14
14
  }
@@ -5,22 +5,22 @@ import { OpraSchema } from '../../schema/index.js';
5
5
  import { DataTypeMap } from '../common/data-type-map.js';
6
6
  import { DocumentElement } from '../common/document-element.js';
7
7
  import { CLASS_NAME_PATTERN, DECORATOR, kDataTypeMap } from '../constants.js';
8
- import { RpcControllerDecoratorFactory } from '../decorators/rpc-controller.decorator.js';
8
+ import { MQControllerDecoratorFactory } from '../decorators/mq-controller.decorator.js';
9
9
  import { colorFgMagenta, colorFgYellow, colorReset, nodeInspectCustom, } from '../utils/inspect.util.js';
10
10
  /**
11
- * RpcController
11
+ * MQController
12
12
  */
13
- export const RpcController = function (...args) {
13
+ export const MQController = function (...args) {
14
14
  // ClassDecorator
15
15
  if (!this)
16
- return RpcController[DECORATOR].apply(undefined, args);
16
+ return MQController[DECORATOR].apply(undefined, args);
17
17
  // Constructor
18
18
  const [owner, initArgs] = args;
19
19
  DocumentElement.call(this, owner);
20
20
  if (!CLASS_NAME_PATTERN.test(initArgs.name))
21
21
  throw new TypeError(`Invalid resource name (${initArgs.name})`);
22
22
  const _this = asMutable(this);
23
- _this.kind = OpraSchema.RpcController.Kind;
23
+ _this.kind = OpraSchema.MQController.Kind;
24
24
  _this.types = _this.node[kDataTypeMap] = new DataTypeMap();
25
25
  _this.operations = new ResponsiveMap();
26
26
  _this.headers = [];
@@ -33,9 +33,9 @@ export const RpcController = function (...args) {
33
33
  };
34
34
  /**
35
35
  *
36
- * @class RpcController
36
+ * @class MQController
37
37
  */
38
- class RpcControllerClass extends DocumentElement {
38
+ class MQControllerClass extends DocumentElement {
39
39
  findHeader(paramName, location) {
40
40
  const paramNameLower = paramName.toLowerCase();
41
41
  let prm;
@@ -48,7 +48,7 @@ class RpcControllerClass extends DocumentElement {
48
48
  if (prm.name instanceof RegExp && prm.name.test(paramName))
49
49
  return prm;
50
50
  }
51
- if (this.node.parent && this.node.parent.element instanceof RpcController) {
51
+ if (this.node.parent && this.node.parent.element instanceof MQController) {
52
52
  return this.node.parent.element.findHeader(paramName, location);
53
53
  }
54
54
  }
@@ -56,7 +56,7 @@ class RpcControllerClass extends DocumentElement {
56
56
  *
57
57
  */
58
58
  toString() {
59
- return `[RpcController ${this.name}]`;
59
+ return `[MQController ${this.name}]`;
60
60
  }
61
61
  /**
62
62
  *
@@ -90,9 +90,9 @@ class RpcControllerClass extends DocumentElement {
90
90
  *
91
91
  */
92
92
  [nodeInspectCustom]() {
93
- return `[${colorFgYellow}RpcController${colorFgMagenta + this.name + colorReset}]`;
93
+ return `[${colorFgYellow}MQController${colorFgMagenta + this.name + colorReset}]`;
94
94
  }
95
95
  }
96
- RpcController.prototype = RpcControllerClass.prototype;
97
- Object.assign(RpcController, RpcControllerDecoratorFactory);
98
- RpcController[DECORATOR] = RpcControllerDecoratorFactory;
96
+ MQController.prototype = MQControllerClass.prototype;
97
+ Object.assign(MQController, MQControllerDecoratorFactory);
98
+ MQController[DECORATOR] = MQControllerDecoratorFactory;
@@ -2,7 +2,7 @@ import { omitUndefined } from '@jsopen/objects';
2
2
  import { asMutable, } from 'ts-gems';
3
3
  import { Value } from '../common/value.js';
4
4
  import { parseRegExp } from '../utils/parse-regexp.util.js';
5
- export const RpcHeader = function (owner, initArgs) {
5
+ export const MQHeader = function (owner, initArgs) {
6
6
  if (!this)
7
7
  throw new TypeError('"this" should be passed to call class constructor');
8
8
  Value.call(this, owner, initArgs);
@@ -22,9 +22,9 @@ export const RpcHeader = function (owner, initArgs) {
22
22
  _this.required = initArgs.required;
23
23
  };
24
24
  /**
25
- * @class RpcHeader
25
+ * @class MQHeader
26
26
  */
27
- class RpcHeaderClass extends Value {
27
+ class MQHeaderClass extends Value {
28
28
  toJSON() {
29
29
  return omitUndefined({
30
30
  ...super.toJSON(),
@@ -34,4 +34,4 @@ class RpcHeaderClass extends Value {
34
34
  });
35
35
  }
36
36
  }
37
- RpcHeader.prototype = RpcHeaderClass.prototype;
37
+ MQHeader.prototype = MQHeaderClass.prototype;
@@ -2,9 +2,9 @@ import { omitUndefined } from '@jsopen/objects';
2
2
  import { DocumentElement } from '../common/document-element.js';
3
3
  import { DataType } from '../data-type/data-type.js';
4
4
  /**
5
- * @class RpcOperationResponse
5
+ * @class MQOperationResponse
6
6
  */
7
- export class RpcOperationResponse extends DocumentElement {
7
+ export class MQOperationResponse extends DocumentElement {
8
8
  constructor(owner, initArgs) {
9
9
  super(owner);
10
10
  this.headers = [];
@@ -5,16 +5,16 @@ import { DataTypeMap } from '../common/data-type-map.js';
5
5
  import { DocumentElement } from '../common/document-element.js';
6
6
  import { CLASS_NAME_PATTERN, DECORATOR, kDataTypeMap } from '../constants.js';
7
7
  import { DataType } from '../data-type/data-type.js';
8
- import { RpcOperationDecoratorFactory, } from '../decorators/rpc-operation.decorator.js';
8
+ import { MQOperationDecoratorFactory, } from '../decorators/mq-operation.decorator.js';
9
9
  /**
10
- * RpcOperation
10
+ * MQOperation
11
11
  */
12
- export const RpcOperation = function (...args) {
12
+ export const MQOperation = function (...args) {
13
13
  // Decorator
14
14
  if (!this) {
15
15
  const [payloadType, options] = args;
16
16
  const decoratorChain = [];
17
- return RpcOperation[DECORATOR].call(undefined, decoratorChain, payloadType, options);
17
+ return MQOperation[DECORATOR].call(undefined, decoratorChain, payloadType, options);
18
18
  }
19
19
  // Constructor
20
20
  const [resource, initArgs] = args;
@@ -41,9 +41,9 @@ export const RpcOperation = function (...args) {
41
41
  }
42
42
  };
43
43
  /**
44
- * @class RpcOperation
44
+ * @class MQOperation
45
45
  */
46
- class RpcOperationClass extends DocumentElement {
46
+ class MQOperationClass extends DocumentElement {
47
47
  findHeader(paramName) {
48
48
  const paramNameLower = paramName.toLowerCase();
49
49
  let prm;
@@ -59,7 +59,7 @@ class RpcOperationClass extends DocumentElement {
59
59
  }
60
60
  toJSON() {
61
61
  const out = omitUndefined({
62
- kind: OpraSchema.RpcOperation.Kind,
62
+ kind: OpraSchema.MQOperation.Kind,
63
63
  description: this.description,
64
64
  channel: this.channel,
65
65
  payloadType: this.payloadType.name
@@ -81,5 +81,5 @@ class RpcOperationClass extends DocumentElement {
81
81
  return out;
82
82
  }
83
83
  }
84
- RpcOperation.prototype = RpcOperationClass.prototype;
85
- RpcOperation[DECORATOR] = RpcOperationDecoratorFactory;
84
+ MQOperation.prototype = MQOperationClass.prototype;
85
+ MQOperation[DECORATOR] = MQOperationDecoratorFactory;
@@ -0,0 +1,48 @@
1
+ import { ResponsiveMap } from '../../helpers/index.js';
2
+ import { ApiBase } from '../common/api-base.js';
3
+ /**
4
+ * @class WSApi
5
+ */
6
+ export class WSApi extends ApiBase {
7
+ constructor(init) {
8
+ super(init);
9
+ // noinspection JSUnusedGlobalSymbols
10
+ this._controllerReverseMap = new WeakMap();
11
+ this.transport = 'ws';
12
+ this.controllers = new ResponsiveMap();
13
+ }
14
+ findController(arg0) {
15
+ if (typeof arg0 === 'function') {
16
+ /** Check for cached mapping */
17
+ const controller = this._controllerReverseMap.get(arg0);
18
+ if (controller != null)
19
+ return controller;
20
+ /** Lookup for ctor in all controllers */
21
+ for (const c of this.controllers.values()) {
22
+ if (c.ctor === arg0) {
23
+ this._controllerReverseMap.set(arg0, c);
24
+ return c;
25
+ }
26
+ }
27
+ this._controllerReverseMap.set(arg0, null);
28
+ return;
29
+ }
30
+ return this.controllers.get(arg0);
31
+ }
32
+ findOperation(arg0, operationName) {
33
+ const controller = this.findController(arg0);
34
+ return controller?.operations.get(operationName);
35
+ }
36
+ toJSON() {
37
+ const schema = super.toJSON();
38
+ const out = {
39
+ ...schema,
40
+ transport: this.transport,
41
+ controllers: {},
42
+ };
43
+ for (const v of this.controllers.values()) {
44
+ out.controllers[v.name] = v.toJSON();
45
+ }
46
+ return out;
47
+ }
48
+ }
@@ -0,0 +1,75 @@
1
+ import { omitUndefined } from '@jsopen/objects';
2
+ import { asMutable } from 'ts-gems';
3
+ import { ResponsiveMap } from '../../helpers/index.js';
4
+ import { OpraSchema } from '../../schema/index.js';
5
+ import { DataTypeMap } from '../common/data-type-map.js';
6
+ import { DocumentElement } from '../common/document-element.js';
7
+ import { CLASS_NAME_PATTERN, DECORATOR, kDataTypeMap } from '../constants.js';
8
+ import { WSControllerDecoratorFactory } from '../decorators/ws-controller.decorator.js';
9
+ import { colorFgMagenta, colorFgYellow, colorReset, nodeInspectCustom, } from '../utils/inspect.util.js';
10
+ /**
11
+ * WSController
12
+ */
13
+ export const WSController = function (...args) {
14
+ // ClassDecorator
15
+ if (!this)
16
+ return WSController[DECORATOR].apply(undefined, args);
17
+ // Constructor
18
+ const [owner, initArgs] = args;
19
+ DocumentElement.call(this, owner);
20
+ if (!CLASS_NAME_PATTERN.test(initArgs.name))
21
+ throw new TypeError(`Invalid resource name (${initArgs.name})`);
22
+ const _this = asMutable(this);
23
+ _this.kind = OpraSchema.WSController.Kind;
24
+ _this.types = _this.node[kDataTypeMap] = new DataTypeMap();
25
+ _this.operations = new ResponsiveMap();
26
+ _this.name = initArgs.name;
27
+ _this.description = initArgs.description;
28
+ _this.instance = initArgs.instance;
29
+ _this.ctor = initArgs.ctor;
30
+ _this._controllerReverseMap = new WeakMap();
31
+ _this._initialize?.(initArgs);
32
+ };
33
+ /**
34
+ *
35
+ * @class WSController
36
+ */
37
+ class WSControllerClass extends DocumentElement {
38
+ /**
39
+ *
40
+ */
41
+ toString() {
42
+ return `[WSController ${this.name}]`;
43
+ }
44
+ /**
45
+ *
46
+ */
47
+ toJSON() {
48
+ const out = omitUndefined({
49
+ kind: this.kind,
50
+ description: this.description,
51
+ });
52
+ if (this.operations.size) {
53
+ out.operations = {};
54
+ for (const v of this.operations.values()) {
55
+ out.operations[v.name] = v.toJSON();
56
+ }
57
+ }
58
+ if (this.types.size) {
59
+ out.types = {};
60
+ for (const v of this.types.values()) {
61
+ out.types[v.name] = v.toJSON();
62
+ }
63
+ }
64
+ return out;
65
+ }
66
+ /**
67
+ *
68
+ */
69
+ [nodeInspectCustom]() {
70
+ return `[${colorFgYellow}WSController${colorFgMagenta + this.name + colorReset}]`;
71
+ }
72
+ }
73
+ WSController.prototype = WSControllerClass.prototype;
74
+ Object.assign(WSController, WSControllerDecoratorFactory);
75
+ WSController[DECORATOR] = WSControllerDecoratorFactory;