@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.
- package/browser/index.cjs +5 -5
- package/browser/index.mjs +5 -5
- package/cjs/document/api-document.js +11 -4
- package/cjs/document/constants.js +3 -1
- package/cjs/document/data-type/enum-type.js +4 -0
- package/cjs/document/decorators/{rpc-controller.decorator.js → mq-controller.decorator.js} +8 -8
- package/cjs/document/decorators/{rpc-operation.decorator.js → mq-operation.decorator.js} +6 -6
- package/cjs/document/decorators/ws-controller.decorator.js +51 -0
- package/cjs/document/decorators/ws-operation.decorator.js +43 -0
- package/cjs/document/factory/api-document.factory.js +3 -3
- package/cjs/document/factory/{rpc-api.factory.js → mq-api.factory.js} +28 -28
- package/cjs/document/factory/ws-api.factory.js +123 -0
- package/cjs/document/index.js +15 -8
- package/cjs/document/{rpc/rpc-api.js → mq/mq-api.js} +5 -5
- package/cjs/document/{rpc/rpc-controller.js → mq/mq-controller.js} +14 -14
- package/cjs/document/{rpc/rpc-header.js → mq/mq-header.js} +5 -5
- package/cjs/document/{rpc/rpc-operation-response.js → mq/mq-operation-response.js} +4 -4
- package/cjs/document/{rpc/rpc-operation.js → mq/mq-operation.js} +10 -10
- package/cjs/document/ws/ws-api.js +52 -0
- package/cjs/document/ws/ws-controller.js +78 -0
- package/cjs/document/ws/ws-operation.js +62 -0
- package/cjs/filter/antlr/OpraFilterLexer.js +361 -211
- package/cjs/filter/antlr/OpraFilterParser.js +174 -92
- package/cjs/schema/http/http-api.interface.js +2 -0
- package/cjs/schema/mq/mq-api.interface.js +2 -0
- package/cjs/schema/mq/mq-controller.interface.js +11 -0
- package/cjs/schema/mq/mq-header.interface.js +2 -0
- package/cjs/schema/mq/mq-operation.interface.js +7 -0
- package/cjs/schema/opra-schema.js +9 -3
- package/cjs/schema/ws/ws-api.interface.js +2 -0
- package/cjs/schema/ws/ws-controller.interface.js +11 -0
- package/cjs/schema/ws/ws-operation.interface.js +7 -0
- package/esm/document/api-document.js +11 -4
- package/esm/document/constants.js +2 -0
- package/esm/document/data-type/enum-type.js +4 -0
- package/esm/document/decorators/{rpc-controller.decorator.js → mq-controller.decorator.js} +8 -8
- package/esm/document/decorators/{rpc-operation.decorator.js → mq-operation.decorator.js} +6 -6
- package/esm/document/decorators/ws-controller.decorator.js +48 -0
- package/esm/document/decorators/ws-operation.decorator.js +40 -0
- package/esm/document/factory/api-document.factory.js +3 -3
- package/esm/document/factory/{rpc-api.factory.js → mq-api.factory.js} +27 -27
- package/esm/document/factory/ws-api.factory.js +119 -0
- package/esm/document/index.js +15 -8
- package/esm/document/{rpc/rpc-api.js → mq/mq-api.js} +3 -3
- package/esm/document/{rpc/rpc-controller.js → mq/mq-controller.js} +13 -13
- package/esm/document/{rpc/rpc-header.js → mq/mq-header.js} +4 -4
- package/esm/document/{rpc/rpc-operation-response.js → mq/mq-operation-response.js} +2 -2
- package/esm/document/{rpc/rpc-operation.js → mq/mq-operation.js} +9 -9
- package/esm/document/ws/ws-api.js +48 -0
- package/esm/document/ws/ws-controller.js +75 -0
- package/esm/document/ws/ws-operation.js +59 -0
- package/esm/filter/antlr/OpraFilterLexer.js +362 -212
- package/esm/filter/antlr/OpraFilterListener.js +1 -1
- package/esm/filter/antlr/OpraFilterParser.js +174 -92
- package/esm/schema/http/http-api.interface.js +1 -0
- package/esm/schema/mq/mq-api.interface.js +1 -0
- package/esm/schema/mq/mq-controller.interface.js +8 -0
- package/esm/schema/mq/mq-header.interface.js +1 -0
- package/esm/schema/mq/mq-operation.interface.js +4 -0
- package/esm/schema/opra-schema.js +9 -3
- package/esm/schema/ws/ws-api.interface.js +1 -0
- package/esm/schema/ws/ws-controller.interface.js +8 -0
- package/esm/schema/ws/ws-operation.interface.js +4 -0
- package/package.json +6 -6
- package/types/document/api-document.d.ts +5 -3
- package/types/document/constants.d.ts +2 -0
- package/types/document/decorators/mq-controller.decorator.d.ts +20 -0
- package/types/document/decorators/mq-operation.decorator.d.ts +32 -0
- package/types/document/decorators/ws-controller.decorator.d.ts +20 -0
- package/types/document/decorators/ws-operation.decorator.d.ts +24 -0
- package/types/document/factory/api-document.factory.d.ts +3 -2
- package/types/document/factory/mq-api.factory.d.ts +40 -0
- package/types/document/factory/ws-api.factory.d.ts +31 -0
- package/types/document/index.d.ts +20 -11
- package/types/document/mq/mq-api.d.ts +27 -0
- package/types/document/mq/mq-controller.d.ts +83 -0
- package/types/document/{rpc/rpc-header.d.ts → mq/mq-header.d.ts} +15 -15
- package/types/document/{rpc/rpc-operation-response.d.ts → mq/mq-operation-response.d.ts} +13 -13
- package/types/document/{rpc/rpc-operation.d.ts → mq/mq-operation.d.ts} +27 -27
- package/types/document/ws/ws-api.d.ts +26 -0
- package/types/document/ws/ws-controller.d.ts +79 -0
- package/types/document/ws/ws-operation.d.ts +70 -0
- package/types/filter/antlr/OpraFilterLexer.d.ts +1 -1
- package/types/filter/antlr/OpraFilterListener.d.ts +28 -28
- package/types/filter/antlr/OpraFilterVisitor.d.ts +27 -27
- package/types/schema/api-document.interface.d.ts +4 -46
- package/types/schema/api.interface.d.ts +13 -0
- package/types/schema/http/http-api.interface.d.ts +12 -0
- package/types/schema/mq/mq-api.interface.d.ts +15 -0
- package/types/schema/mq/mq-controller.interface.d.ts +22 -0
- package/types/schema/{rpc/rpc-header.interface.d.ts → mq/mq-header.interface.d.ts} +2 -2
- package/types/schema/{rpc/rpc-operation.interface.d.ts → mq/mq-operation.interface.d.ts} +11 -11
- package/types/schema/opra-schema.d.ts +9 -3
- package/types/schema/types.d.ts +11 -0
- package/types/schema/ws/ws-api.interface.d.ts +11 -0
- package/types/schema/ws/ws-controller.interface.d.ts +20 -0
- package/types/schema/ws/ws-operation.interface.d.ts +15 -0
- package/cjs/schema/rpc/rpc-controller.interface.js +0 -11
- package/cjs/schema/rpc/rpc-operation.interface.js +0 -7
- package/esm/schema/rpc/rpc-controller.interface.js +0 -8
- package/esm/schema/rpc/rpc-operation.interface.js +0 -4
- package/types/document/decorators/rpc-controller.decorator.d.ts +0 -20
- package/types/document/decorators/rpc-operation.decorator.d.ts +0 -32
- package/types/document/factory/rpc-api.factory.d.ts +0 -40
- package/types/document/rpc/rpc-api.d.ts +0 -27
- package/types/document/rpc/rpc-controller.d.ts +0 -83
- package/types/schema/rpc/rpc-controller.interface.d.ts +0 -22
- /package/cjs/schema/{rpc/rpc-header.interface.js → api.interface.js} +0 -0
- /package/esm/schema/{rpc/rpc-header.interface.js → api.interface.js} +0 -0
|
@@ -11,7 +11,8 @@ const document_element_js_1 = require("./common/document-element.js");
|
|
|
11
11
|
const constants_js_1 = require("./constants.js");
|
|
12
12
|
const data_type_js_1 = require("./data-type/data-type.js");
|
|
13
13
|
const http_api_js_1 = require("./http/http-api.js");
|
|
14
|
-
const
|
|
14
|
+
const mq_api_js_1 = require("./mq/mq-api.js");
|
|
15
|
+
const ws_api_js_1 = require("./ws/ws-api.js");
|
|
15
16
|
/**
|
|
16
17
|
*
|
|
17
18
|
* @class ApiDocument
|
|
@@ -55,9 +56,15 @@ class ApiDocument extends document_element_js_1.DocumentElement {
|
|
|
55
56
|
}
|
|
56
57
|
return this.api;
|
|
57
58
|
}
|
|
58
|
-
get
|
|
59
|
-
if (!(this.api && this.api instanceof
|
|
60
|
-
throw new TypeError('The document do not contains
|
|
59
|
+
get mqApi() {
|
|
60
|
+
if (!(this.api && this.api instanceof mq_api_js_1.MQApi)) {
|
|
61
|
+
throw new TypeError('The document do not contains MQApi instance');
|
|
62
|
+
}
|
|
63
|
+
return this.api;
|
|
64
|
+
}
|
|
65
|
+
get wsApi() {
|
|
66
|
+
if (!(this.api && this.api instanceof ws_api_js_1.WSApi)) {
|
|
67
|
+
throw new TypeError('The document do not contains WSApi instance');
|
|
61
68
|
}
|
|
62
69
|
return this.api;
|
|
63
70
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.kTypeNSMap = exports.kCtorMap = exports.kDataTypeMap = exports.CLASS_NAME_PATTERN = exports.NAMESPACE_PATTERN = exports.BUILTIN = exports.DECORATOR = exports.ENCODER = exports.DECODER = exports.RPC_CONTROLLER_METADATA = exports.HTTP_CONTROLLER_METADATA = exports.DATATYPE_METADATA = void 0;
|
|
3
|
+
exports.kTypeNSMap = exports.kCtorMap = exports.kDataTypeMap = exports.CLASS_NAME_PATTERN = exports.NAMESPACE_PATTERN = exports.BUILTIN = exports.DECORATOR = exports.ENCODER = exports.DECODER = exports.RPC_CONTROLLER_METADATA = exports.WS_CONTROLLER_METADATA = exports.MQ_CONTROLLER_METADATA = exports.HTTP_CONTROLLER_METADATA = exports.DATATYPE_METADATA = void 0;
|
|
4
4
|
exports.DATATYPE_METADATA = Symbol.for('opra.type.metadata');
|
|
5
5
|
exports.HTTP_CONTROLLER_METADATA = Symbol('opra.http-controller.metadata');
|
|
6
|
+
exports.MQ_CONTROLLER_METADATA = Symbol('opra.mq-controller.metadata');
|
|
7
|
+
exports.WS_CONTROLLER_METADATA = Symbol('opra.ws-controller.metadata');
|
|
6
8
|
exports.RPC_CONTROLLER_METADATA = Symbol('opra.rpc-controller.metadata');
|
|
7
9
|
exports.DECODER = Symbol.for('opra.type.decoder');
|
|
8
10
|
exports.ENCODER = Symbol('opra.type.encoder');
|
|
@@ -90,6 +90,8 @@ function EnumTypeFactory(enumSource, ...args) {
|
|
|
90
90
|
}
|
|
91
91
|
attributes = {};
|
|
92
92
|
enumSource.forEach(k => {
|
|
93
|
+
if (!isNaN(Number(k)))
|
|
94
|
+
return;
|
|
93
95
|
const description = options?.meanings?.[k];
|
|
94
96
|
attributes[k] = (0, objects_1.omitUndefined)({ description });
|
|
95
97
|
});
|
|
@@ -101,6 +103,8 @@ function EnumTypeFactory(enumSource, ...args) {
|
|
|
101
103
|
out = { ...base, ...enumSource };
|
|
102
104
|
}
|
|
103
105
|
Object.keys(enumSource).forEach(k => {
|
|
106
|
+
if (!isNaN(Number(k)))
|
|
107
|
+
return;
|
|
104
108
|
const description = options?.meanings?.[k];
|
|
105
109
|
attributes[enumSource[k]] = (0, objects_1.omitUndefined)({ alias: k, description });
|
|
106
110
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MQControllerDecoratorFactory = MQControllerDecoratorFactory;
|
|
4
4
|
const objects_1 = require("@jsopen/objects");
|
|
5
5
|
const index_js_1 = require("../../schema/index.js");
|
|
6
6
|
const constants_js_1 = require("../constants.js");
|
|
7
7
|
const CLASS_NAME_PATTERN = /^(.*)(Controller)$/;
|
|
8
8
|
const augmentationRegistry = [];
|
|
9
|
-
function
|
|
9
|
+
function MQControllerDecoratorFactory(options) {
|
|
10
10
|
const decoratorChain = [];
|
|
11
11
|
/**
|
|
12
12
|
*
|
|
@@ -16,22 +16,22 @@ function RpcControllerDecoratorFactory(options) {
|
|
|
16
16
|
if (!name)
|
|
17
17
|
name = CLASS_NAME_PATTERN.exec(target.name)?.[1] || target.name;
|
|
18
18
|
const metadata = {};
|
|
19
|
-
const baseMetadata = Reflect.getOwnMetadata(constants_js_1.
|
|
19
|
+
const baseMetadata = Reflect.getOwnMetadata(constants_js_1.MQ_CONTROLLER_METADATA, Object.getPrototypeOf(target));
|
|
20
20
|
if (baseMetadata)
|
|
21
21
|
(0, objects_1.merge)(metadata, baseMetadata, { deep: true });
|
|
22
|
-
const oldMetadata = Reflect.getOwnMetadata(constants_js_1.
|
|
22
|
+
const oldMetadata = Reflect.getOwnMetadata(constants_js_1.MQ_CONTROLLER_METADATA, target);
|
|
23
23
|
if (oldMetadata)
|
|
24
24
|
(0, objects_1.merge)(metadata, oldMetadata, { deep: true });
|
|
25
25
|
(0, objects_1.merge)(metadata, {
|
|
26
26
|
...options,
|
|
27
|
-
kind: index_js_1.OpraSchema.
|
|
27
|
+
kind: index_js_1.OpraSchema.MQController.Kind,
|
|
28
28
|
name,
|
|
29
29
|
path: name,
|
|
30
30
|
}, { deep: true });
|
|
31
|
-
Reflect.defineMetadata(constants_js_1.
|
|
31
|
+
Reflect.defineMetadata(constants_js_1.MQ_CONTROLLER_METADATA, metadata, target);
|
|
32
32
|
for (const fn of decoratorChain)
|
|
33
33
|
fn(metadata, target);
|
|
34
|
-
Reflect.defineMetadata(constants_js_1.
|
|
34
|
+
Reflect.defineMetadata(constants_js_1.MQ_CONTROLLER_METADATA, metadata, target);
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
37
37
|
*
|
|
@@ -62,6 +62,6 @@ function RpcControllerDecoratorFactory(options) {
|
|
|
62
62
|
augmentationRegistry.forEach(fn => fn(decorator, decoratorChain, options));
|
|
63
63
|
return decorator;
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
MQControllerDecoratorFactory.augment = function (fn) {
|
|
66
66
|
augmentationRegistry.push(fn);
|
|
67
67
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MQOperationDecoratorFactory = MQOperationDecoratorFactory;
|
|
4
4
|
const objects_1 = require("@jsopen/objects");
|
|
5
5
|
const index_js_1 = require("../../schema/index.js");
|
|
6
6
|
const constants_js_1 = require("../constants.js");
|
|
7
7
|
const augmentationRegistry = [];
|
|
8
|
-
function
|
|
8
|
+
function MQOperationDecoratorFactory(decoratorChain, payloadType, options) {
|
|
9
9
|
let inResponse = false;
|
|
10
10
|
/**
|
|
11
11
|
*
|
|
@@ -14,17 +14,17 @@ function RpcOperationDecoratorFactory(decoratorChain, payloadType, options) {
|
|
|
14
14
|
if (typeof propertyKey !== 'string')
|
|
15
15
|
throw new TypeError(`Symbol properties can not be decorated`);
|
|
16
16
|
const operationMetadata = {
|
|
17
|
-
kind: index_js_1.OpraSchema.
|
|
17
|
+
kind: index_js_1.OpraSchema.MQOperation.Kind,
|
|
18
18
|
channel: propertyKey,
|
|
19
19
|
payloadType,
|
|
20
20
|
...(0, objects_1.omit)(options, ['kind', 'payloadType']),
|
|
21
21
|
};
|
|
22
|
-
const controllerMetadata = (Reflect.getOwnMetadata(constants_js_1.
|
|
22
|
+
const controllerMetadata = (Reflect.getOwnMetadata(constants_js_1.MQ_CONTROLLER_METADATA, target.constructor) || {});
|
|
23
23
|
controllerMetadata.operations = controllerMetadata.operations || {};
|
|
24
24
|
controllerMetadata.operations[propertyKey] = operationMetadata;
|
|
25
25
|
for (const fn of decoratorChain)
|
|
26
26
|
fn(operationMetadata, target, propertyKey);
|
|
27
|
-
Reflect.defineMetadata(constants_js_1.
|
|
27
|
+
Reflect.defineMetadata(constants_js_1.MQ_CONTROLLER_METADATA, controllerMetadata, target.constructor);
|
|
28
28
|
});
|
|
29
29
|
/**
|
|
30
30
|
*
|
|
@@ -73,6 +73,6 @@ function RpcOperationDecoratorFactory(decoratorChain, payloadType, options) {
|
|
|
73
73
|
augmentationRegistry.forEach(fn => fn(decorator, decoratorChain, payloadType, options));
|
|
74
74
|
return decorator;
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
MQOperationDecoratorFactory.augment = function (fn) {
|
|
77
77
|
augmentationRegistry.push(fn);
|
|
78
78
|
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WSControllerDecoratorFactory = WSControllerDecoratorFactory;
|
|
4
|
+
const objects_1 = require("@jsopen/objects");
|
|
5
|
+
const index_js_1 = require("../../schema/index.js");
|
|
6
|
+
const constants_js_1 = require("../constants.js");
|
|
7
|
+
const CLASS_NAME_PATTERN = /^(.*)(Controller)$/;
|
|
8
|
+
const augmentationRegistry = [];
|
|
9
|
+
function WSControllerDecoratorFactory(options) {
|
|
10
|
+
const decoratorChain = [];
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
const decorator = function (target) {
|
|
15
|
+
let name = options?.name;
|
|
16
|
+
if (!name)
|
|
17
|
+
name = CLASS_NAME_PATTERN.exec(target.name)?.[1] || target.name;
|
|
18
|
+
const metadata = {};
|
|
19
|
+
const baseMetadata = Reflect.getOwnMetadata(constants_js_1.MQ_CONTROLLER_METADATA, Object.getPrototypeOf(target));
|
|
20
|
+
if (baseMetadata)
|
|
21
|
+
(0, objects_1.merge)(metadata, baseMetadata, { deep: true });
|
|
22
|
+
const oldMetadata = Reflect.getOwnMetadata(constants_js_1.MQ_CONTROLLER_METADATA, target);
|
|
23
|
+
if (oldMetadata)
|
|
24
|
+
(0, objects_1.merge)(metadata, oldMetadata, { deep: true });
|
|
25
|
+
(0, objects_1.merge)(metadata, {
|
|
26
|
+
...options,
|
|
27
|
+
kind: index_js_1.OpraSchema.WSController.Kind,
|
|
28
|
+
name,
|
|
29
|
+
path: name,
|
|
30
|
+
}, { deep: true });
|
|
31
|
+
Reflect.defineMetadata(constants_js_1.MQ_CONTROLLER_METADATA, metadata, target);
|
|
32
|
+
for (const fn of decoratorChain)
|
|
33
|
+
fn(metadata, target);
|
|
34
|
+
Reflect.defineMetadata(constants_js_1.MQ_CONTROLLER_METADATA, metadata, target);
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
decorator.UseType = (...type) => {
|
|
40
|
+
decoratorChain.push((meta) => {
|
|
41
|
+
meta.types = meta.types || [];
|
|
42
|
+
meta.types.push(...type);
|
|
43
|
+
});
|
|
44
|
+
return decorator;
|
|
45
|
+
};
|
|
46
|
+
augmentationRegistry.forEach(fn => fn(decorator, decoratorChain, options));
|
|
47
|
+
return decorator;
|
|
48
|
+
}
|
|
49
|
+
WSControllerDecoratorFactory.augment = function (fn) {
|
|
50
|
+
augmentationRegistry.push(fn);
|
|
51
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WSOperationDecoratorFactory = WSOperationDecoratorFactory;
|
|
4
|
+
const objects_1 = require("@jsopen/objects");
|
|
5
|
+
const index_js_1 = require("../../schema/index.js");
|
|
6
|
+
const constants_js_1 = require("../constants.js");
|
|
7
|
+
const augmentationRegistry = [];
|
|
8
|
+
function WSOperationDecoratorFactory(decoratorChain, payloadType, options) {
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
const decorator = ((target, propertyKey) => {
|
|
13
|
+
if (typeof propertyKey !== 'string')
|
|
14
|
+
throw new TypeError(`Symbol properties can not be decorated`);
|
|
15
|
+
const operationMetadata = {
|
|
16
|
+
kind: index_js_1.OpraSchema.WSOperation.Kind,
|
|
17
|
+
channel: propertyKey,
|
|
18
|
+
payloadType,
|
|
19
|
+
...(0, objects_1.omit)(options, ['kind', 'payloadType']),
|
|
20
|
+
};
|
|
21
|
+
const controllerMetadata = (Reflect.getOwnMetadata(constants_js_1.MQ_CONTROLLER_METADATA, target.constructor) || {});
|
|
22
|
+
controllerMetadata.operations = controllerMetadata.operations || {};
|
|
23
|
+
controllerMetadata.operations[propertyKey] = operationMetadata;
|
|
24
|
+
for (const fn of decoratorChain)
|
|
25
|
+
fn(operationMetadata, target, propertyKey);
|
|
26
|
+
Reflect.defineMetadata(constants_js_1.MQ_CONTROLLER_METADATA, controllerMetadata, target.constructor);
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
decorator.UseType = (...type) => {
|
|
32
|
+
decoratorChain.push((meta) => {
|
|
33
|
+
meta.types = meta.types || [];
|
|
34
|
+
meta.types.push(...type);
|
|
35
|
+
});
|
|
36
|
+
return decorator;
|
|
37
|
+
};
|
|
38
|
+
augmentationRegistry.forEach(fn => fn(decorator, decoratorChain, payloadType, options));
|
|
39
|
+
return decorator;
|
|
40
|
+
}
|
|
41
|
+
WSOperationDecoratorFactory.augment = function (fn) {
|
|
42
|
+
augmentationRegistry.push(fn);
|
|
43
|
+
};
|
|
@@ -12,7 +12,7 @@ const extendedTypes = tslib_1.__importStar(require("../data-type/extended-types/
|
|
|
12
12
|
const primitiveTypes = tslib_1.__importStar(require("../data-type/primitive-types/index.js"));
|
|
13
13
|
const data_type_factory_js_1 = require("./data-type.factory.js");
|
|
14
14
|
const http_api_factory_js_1 = require("./http-api.factory.js");
|
|
15
|
-
const
|
|
15
|
+
const mq_api_factory_js_1 = require("./mq-api.factory.js");
|
|
16
16
|
const OPRA_SPEC_URL = 'https://oprajs.com/spec/v' + index_js_2.OpraSchema.SpecVersion;
|
|
17
17
|
/**
|
|
18
18
|
* @class ApiDocumentFactory
|
|
@@ -123,8 +123,8 @@ class ApiDocumentFactory {
|
|
|
123
123
|
if (api)
|
|
124
124
|
document.api = api;
|
|
125
125
|
}
|
|
126
|
-
else if (init.api && init.api.transport === '
|
|
127
|
-
const api = await
|
|
126
|
+
else if (init.api && init.api.transport === 'mq') {
|
|
127
|
+
const api = await mq_api_factory_js_1.MQApiFactory.createApi(context, {
|
|
128
128
|
...init.api,
|
|
129
129
|
owner: document,
|
|
130
130
|
});
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MQApiFactory = void 0;
|
|
4
4
|
const objects_1 = require("@jsopen/objects");
|
|
5
5
|
const index_js_1 = require("../../helpers/index.js");
|
|
6
6
|
const constants_js_1 = require("../constants.js");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
7
|
+
const mq_api_js_1 = require("../mq/mq-api.js");
|
|
8
|
+
const mq_controller_js_1 = require("../mq/mq-controller.js");
|
|
9
|
+
const mq_header_js_1 = require("../mq/mq-header.js");
|
|
10
|
+
const mq_operation_js_1 = require("../mq/mq-operation.js");
|
|
11
|
+
const mq_operation_response_js_1 = require("../mq/mq-operation-response.js");
|
|
12
12
|
const data_type_factory_js_1 = require("./data-type.factory.js");
|
|
13
13
|
/**
|
|
14
|
-
* @class
|
|
14
|
+
* @class MQApiFactory
|
|
15
15
|
*/
|
|
16
|
-
class
|
|
16
|
+
class MQApiFactory {
|
|
17
17
|
/**
|
|
18
|
-
* Generates
|
|
18
|
+
* Generates MQApi
|
|
19
19
|
* @param context
|
|
20
20
|
* @param init
|
|
21
21
|
*/
|
|
22
22
|
static async createApi(context, init) {
|
|
23
|
-
const api = new
|
|
23
|
+
const api = new mq_api_js_1.MQApi(init);
|
|
24
24
|
if (init.controllers) {
|
|
25
25
|
await context.enterAsync('.controllers', async () => {
|
|
26
26
|
if (Array.isArray(init.controllers)) {
|
|
@@ -51,15 +51,15 @@ class RpcApiFactory {
|
|
|
51
51
|
let instance;
|
|
52
52
|
// If thunk is a class
|
|
53
53
|
if (typeof thunk === 'function') {
|
|
54
|
-
metadata = Reflect.getMetadata(constants_js_1.
|
|
54
|
+
metadata = Reflect.getMetadata(constants_js_1.MQ_CONTROLLER_METADATA, thunk);
|
|
55
55
|
if (!metadata)
|
|
56
|
-
return context.addError(`Class "${thunk.name}" doesn't have a valid
|
|
56
|
+
return context.addError(`Class "${thunk.name}" doesn't have a valid MQController metadata`);
|
|
57
57
|
ctor = thunk;
|
|
58
58
|
}
|
|
59
59
|
else {
|
|
60
|
-
// If thunk is an instance of a class decorated with
|
|
60
|
+
// If thunk is an instance of a class decorated with MQController()
|
|
61
61
|
ctor = Object.getPrototypeOf(thunk).constructor;
|
|
62
|
-
metadata = Reflect.getMetadata(constants_js_1.
|
|
62
|
+
metadata = Reflect.getMetadata(constants_js_1.MQ_CONTROLLER_METADATA, ctor);
|
|
63
63
|
if (metadata)
|
|
64
64
|
instance = thunk;
|
|
65
65
|
else {
|
|
@@ -72,11 +72,11 @@ class RpcApiFactory {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
if (!metadata)
|
|
75
|
-
return context.addError(`Class "${ctor.name}" is not decorated with
|
|
75
|
+
return context.addError(`Class "${ctor.name}" is not decorated with MQController()`);
|
|
76
76
|
name = name || metadata.name;
|
|
77
77
|
if (!name)
|
|
78
78
|
throw new TypeError(`Controller name required`);
|
|
79
|
-
const controller = new
|
|
79
|
+
const controller = new mq_controller_js_1.MQController(parent, {
|
|
80
80
|
...metadata,
|
|
81
81
|
name,
|
|
82
82
|
instance,
|
|
@@ -102,7 +102,7 @@ class RpcApiFactory {
|
|
|
102
102
|
if (!prmArgs.type)
|
|
103
103
|
prmArgs.type = controller.node.getDataType('any');
|
|
104
104
|
});
|
|
105
|
-
const prm = new
|
|
105
|
+
const prm = new mq_header_js_1.MQHeader(controller, prmArgs);
|
|
106
106
|
controller.headers.push(prm);
|
|
107
107
|
});
|
|
108
108
|
}
|
|
@@ -112,14 +112,14 @@ class RpcApiFactory {
|
|
|
112
112
|
await context.enterAsync('.operations', async () => {
|
|
113
113
|
for (const [operationName, operationMeta] of Object.entries(metadata.operations)) {
|
|
114
114
|
await context.enterAsync(`[${operationName}]`, async () => {
|
|
115
|
-
const operation = new
|
|
115
|
+
const operation = new mq_operation_js_1.MQOperation(controller, {
|
|
116
116
|
...operationMeta,
|
|
117
117
|
name: operationName,
|
|
118
118
|
types: undefined,
|
|
119
119
|
payloadType: undefined,
|
|
120
120
|
keyType: undefined,
|
|
121
121
|
});
|
|
122
|
-
await this.
|
|
122
|
+
await this._initMQOperation(context, operation, operationMeta);
|
|
123
123
|
controller.operations.set(operation.name, operation);
|
|
124
124
|
});
|
|
125
125
|
}
|
|
@@ -128,13 +128,13 @@ class RpcApiFactory {
|
|
|
128
128
|
return controller;
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
131
|
-
* Initializes
|
|
131
|
+
* Initializes MQOperation
|
|
132
132
|
* @param context
|
|
133
133
|
* @param operation
|
|
134
134
|
* @param metadata
|
|
135
135
|
* @protected
|
|
136
136
|
*/
|
|
137
|
-
static async
|
|
137
|
+
static async _initMQOperation(context, operation, metadata) {
|
|
138
138
|
if (metadata.types) {
|
|
139
139
|
await context.enterAsync('.types', async () => {
|
|
140
140
|
await data_type_factory_js_1.DataTypeFactory.addDataTypes(context, operation, metadata.types);
|
|
@@ -153,7 +153,7 @@ class RpcApiFactory {
|
|
|
153
153
|
await context.enterAsync('.type', async () => {
|
|
154
154
|
prmArgs.type = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, operation, v.type);
|
|
155
155
|
});
|
|
156
|
-
const prm = new
|
|
156
|
+
const prm = new mq_header_js_1.MQHeader(operation, prmArgs);
|
|
157
157
|
operation.headers.push(prm);
|
|
158
158
|
});
|
|
159
159
|
}
|
|
@@ -161,24 +161,24 @@ class RpcApiFactory {
|
|
|
161
161
|
}
|
|
162
162
|
if (metadata.response) {
|
|
163
163
|
await context.enterAsync('.response', async () => {
|
|
164
|
-
const response = new
|
|
164
|
+
const response = new mq_operation_response_js_1.MQOperationResponse(operation, {
|
|
165
165
|
...metadata.response,
|
|
166
166
|
payloadType: undefined,
|
|
167
167
|
keyType: undefined,
|
|
168
168
|
});
|
|
169
|
-
await this.
|
|
169
|
+
await this._initMQOperationResponse(context, response, metadata.response);
|
|
170
170
|
operation.response = response;
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
175
|
-
* Initializes
|
|
175
|
+
* Initializes MQOperationResponse
|
|
176
176
|
* @param context
|
|
177
177
|
* @param response
|
|
178
178
|
* @param metadata
|
|
179
179
|
* @protected
|
|
180
180
|
*/
|
|
181
|
-
static async
|
|
181
|
+
static async _initMQOperationResponse(context, response, metadata) {
|
|
182
182
|
response.payloadType = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, response, metadata.payloadType);
|
|
183
183
|
if (metadata.keyType) {
|
|
184
184
|
response.keyType = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, response, metadata.keyType);
|
|
@@ -192,7 +192,7 @@ class RpcApiFactory {
|
|
|
192
192
|
await context.enterAsync('.type', async () => {
|
|
193
193
|
prmArgs.type = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, response, v.type);
|
|
194
194
|
});
|
|
195
|
-
const prm = new
|
|
195
|
+
const prm = new mq_header_js_1.MQHeader(response, prmArgs);
|
|
196
196
|
response.headers.push(prm);
|
|
197
197
|
});
|
|
198
198
|
}
|
|
@@ -200,4 +200,4 @@ class RpcApiFactory {
|
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
|
-
exports.
|
|
203
|
+
exports.MQApiFactory = MQApiFactory;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WSApiFactory = void 0;
|
|
4
|
+
const objects_1 = require("@jsopen/objects");
|
|
5
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
6
|
+
const constants_js_1 = require("../constants.js");
|
|
7
|
+
const ws_api_js_1 = require("../ws/ws-api.js");
|
|
8
|
+
const ws_controller_js_1 = require("../ws/ws-controller.js");
|
|
9
|
+
const ws_operation_js_1 = require("../ws/ws-operation.js");
|
|
10
|
+
const data_type_factory_js_1 = require("./data-type.factory.js");
|
|
11
|
+
/**
|
|
12
|
+
* @class WSApiFactory
|
|
13
|
+
*/
|
|
14
|
+
class WSApiFactory {
|
|
15
|
+
/**
|
|
16
|
+
* Generates MQApi
|
|
17
|
+
* @param context
|
|
18
|
+
* @param init
|
|
19
|
+
*/
|
|
20
|
+
static async createApi(context, init) {
|
|
21
|
+
const api = new ws_api_js_1.WSApi(init);
|
|
22
|
+
if (init.controllers) {
|
|
23
|
+
await context.enterAsync('.controllers', async () => {
|
|
24
|
+
if (Array.isArray(init.controllers)) {
|
|
25
|
+
for (const c of init.controllers) {
|
|
26
|
+
const controller = await this._createController(context, api, c);
|
|
27
|
+
if (controller)
|
|
28
|
+
api.controllers.set(controller.name, controller);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
for (const [k, v] of Object.entries(init.controllers)) {
|
|
33
|
+
const controller = await this._createController(context, api, v, k);
|
|
34
|
+
if (controller)
|
|
35
|
+
api.controllers.set(controller.name, controller);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return api;
|
|
41
|
+
}
|
|
42
|
+
static async _createController(context, parent, thunk, name) {
|
|
43
|
+
if (typeof thunk === 'function' && !(0, objects_1.isConstructor)(thunk)) {
|
|
44
|
+
thunk = thunk();
|
|
45
|
+
}
|
|
46
|
+
thunk = await (0, index_js_1.resolveThunk)(thunk);
|
|
47
|
+
let ctor;
|
|
48
|
+
let metadata;
|
|
49
|
+
let instance;
|
|
50
|
+
// If thunk is a class
|
|
51
|
+
if (typeof thunk === 'function') {
|
|
52
|
+
metadata = Reflect.getMetadata(constants_js_1.WS_CONTROLLER_METADATA, thunk);
|
|
53
|
+
if (!metadata)
|
|
54
|
+
return context.addError(`Class "${thunk.name}" doesn't have a valid WSController metadata`);
|
|
55
|
+
ctor = thunk;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// If thunk is an instance of a class decorated with WSController()
|
|
59
|
+
ctor = Object.getPrototypeOf(thunk).constructor;
|
|
60
|
+
metadata = Reflect.getMetadata(constants_js_1.WS_CONTROLLER_METADATA, ctor);
|
|
61
|
+
if (metadata)
|
|
62
|
+
instance = thunk;
|
|
63
|
+
else {
|
|
64
|
+
// If thunk is a DecoratorMetadata or InitArguments
|
|
65
|
+
metadata = thunk;
|
|
66
|
+
if (thunk.instance === 'object') {
|
|
67
|
+
instance = thunk.instance;
|
|
68
|
+
ctor = Object.getPrototypeOf(instance).constructor;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!metadata)
|
|
73
|
+
return context.addError(`Class "${ctor.name}" is not decorated with WSController()`);
|
|
74
|
+
name = name || metadata.name;
|
|
75
|
+
if (!name)
|
|
76
|
+
throw new TypeError(`Controller name required`);
|
|
77
|
+
const controller = new ws_controller_js_1.WSController(parent, {
|
|
78
|
+
...metadata,
|
|
79
|
+
name,
|
|
80
|
+
instance,
|
|
81
|
+
ctor,
|
|
82
|
+
});
|
|
83
|
+
if (metadata.types) {
|
|
84
|
+
await context.enterAsync('.types', async () => {
|
|
85
|
+
await data_type_factory_js_1.DataTypeFactory.addDataTypes(context, controller, metadata.types);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (metadata.operations) {
|
|
89
|
+
await context.enterAsync('.operations', async () => {
|
|
90
|
+
for (const [operationName, operationMeta] of Object.entries(metadata.operations)) {
|
|
91
|
+
await context.enterAsync(`[${operationName}]`, async () => {
|
|
92
|
+
const operation = new ws_operation_js_1.WSOperation(controller, {
|
|
93
|
+
...operationMeta,
|
|
94
|
+
name: operationName,
|
|
95
|
+
types: undefined,
|
|
96
|
+
payloadType: undefined,
|
|
97
|
+
keyType: undefined,
|
|
98
|
+
});
|
|
99
|
+
await this._initWSOperation(context, operation, operationMeta);
|
|
100
|
+
controller.operations.set(operation.name, operation);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return controller;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Initializes WSOperation
|
|
109
|
+
* @param context
|
|
110
|
+
* @param operation
|
|
111
|
+
* @param metadata
|
|
112
|
+
* @protected
|
|
113
|
+
*/
|
|
114
|
+
static async _initWSOperation(context, operation, metadata) {
|
|
115
|
+
if (metadata.types) {
|
|
116
|
+
await context.enterAsync('.types', async () => {
|
|
117
|
+
await data_type_factory_js_1.DataTypeFactory.addDataTypes(context, operation, metadata.types);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
operation.payloadType = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, operation, metadata.payloadType);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.WSApiFactory = WSApiFactory;
|
package/cjs/document/index.js
CHANGED
|
@@ -12,8 +12,10 @@ require("./decorators/http-operation-entity-get.decorator.js");
|
|
|
12
12
|
require("./decorators/http-operation-entity-replace.decorator.js");
|
|
13
13
|
require("./decorators/http-operation-entity-update.decorator.js");
|
|
14
14
|
require("./decorators/http-operation-entity-update-many.decorator.js");
|
|
15
|
-
const
|
|
16
|
-
const
|
|
15
|
+
const MQControllerDecorator_ = tslib_1.__importStar(require("./decorators/mq-controller.decorator.js"));
|
|
16
|
+
const MQOperationDecorator_ = tslib_1.__importStar(require("./decorators/mq-operation.decorator.js"));
|
|
17
|
+
const WSControllerDecorator_ = tslib_1.__importStar(require("./decorators/ws-controller.decorator.js"));
|
|
18
|
+
const WSOperationDecorator_ = tslib_1.__importStar(require("./decorators/ws-operation.decorator.js"));
|
|
17
19
|
const DataTypeFactory_ = tslib_1.__importStar(require("./factory/data-type.factory.js"));
|
|
18
20
|
const HttpApiFactory_ = tslib_1.__importStar(require("./factory/http-api.factory.js"));
|
|
19
21
|
tslib_1.__exportStar(require("./api-document.js"), exports);
|
|
@@ -48,14 +50,19 @@ tslib_1.__exportStar(require("./http/http-operation-response.js"), exports);
|
|
|
48
50
|
tslib_1.__exportStar(require("./http/http-parameter.js"), exports);
|
|
49
51
|
tslib_1.__exportStar(require("./http/http-request-body.js"), exports);
|
|
50
52
|
tslib_1.__exportStar(require("./http/http-status-range.js"), exports);
|
|
51
|
-
tslib_1.__exportStar(require("./
|
|
52
|
-
tslib_1.__exportStar(require("./
|
|
53
|
-
tslib_1.__exportStar(require("./
|
|
54
|
-
tslib_1.__exportStar(require("./
|
|
53
|
+
tslib_1.__exportStar(require("./mq/mq-api.js"), exports);
|
|
54
|
+
tslib_1.__exportStar(require("./mq/mq-controller.js"), exports);
|
|
55
|
+
tslib_1.__exportStar(require("./mq/mq-header.js"), exports);
|
|
56
|
+
tslib_1.__exportStar(require("./mq/mq-operation.js"), exports);
|
|
57
|
+
tslib_1.__exportStar(require("./ws/ws-api.js"), exports);
|
|
58
|
+
tslib_1.__exportStar(require("./ws/ws-controller.js"), exports);
|
|
59
|
+
tslib_1.__exportStar(require("./ws/ws-operation.js"), exports);
|
|
55
60
|
var classes;
|
|
56
61
|
(function (classes) {
|
|
57
62
|
classes.HttpApiFactory = HttpApiFactory_.HttpApiFactory;
|
|
58
63
|
classes.DataTypeFactory = DataTypeFactory_.DataTypeFactory;
|
|
59
|
-
classes.
|
|
60
|
-
classes.
|
|
64
|
+
classes.MQOperationDecoratorFactory = MQOperationDecorator_.MQOperationDecoratorFactory;
|
|
65
|
+
classes.MQControllerDecoratorFactory = MQControllerDecorator_.MQControllerDecoratorFactory;
|
|
66
|
+
classes.WSOperationDecoratorFactory = WSOperationDecorator_.WSOperationDecoratorFactory;
|
|
67
|
+
classes.WSControllerDecoratorFactory = WSControllerDecorator_.WSControllerDecoratorFactory;
|
|
61
68
|
})(classes || (exports.classes = classes = {}));
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MQApi = void 0;
|
|
4
4
|
const index_js_1 = require("../../helpers/index.js");
|
|
5
5
|
const api_base_js_1 = require("../common/api-base.js");
|
|
6
6
|
/**
|
|
7
|
-
* @class
|
|
7
|
+
* @class MQApi
|
|
8
8
|
*/
|
|
9
|
-
class
|
|
9
|
+
class MQApi extends api_base_js_1.ApiBase {
|
|
10
10
|
constructor(init) {
|
|
11
11
|
super(init);
|
|
12
12
|
// noinspection JSUnusedGlobalSymbols
|
|
13
13
|
this._controllerReverseMap = new WeakMap();
|
|
14
|
-
this.transport = '
|
|
14
|
+
this.transport = 'mq';
|
|
15
15
|
this.controllers = new index_js_1.ResponsiveMap();
|
|
16
16
|
this.platform = init.platform;
|
|
17
17
|
}
|
|
@@ -51,4 +51,4 @@ class RpcApi extends api_base_js_1.ApiBase {
|
|
|
51
51
|
return out;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
exports.
|
|
54
|
+
exports.MQApi = MQApi;
|