@opra/common 1.19.7 → 1.20.0
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 +14 -2
- package/cjs/document/common/document-node.js +12 -1
- package/cjs/document/constants.js +2 -1
- package/cjs/document/data-type/api-field.js +7 -6
- package/cjs/document/data-type/array-type.js +78 -0
- package/cjs/document/data-type/complex-type-base.js +3 -4
- package/cjs/document/data-type/extended-types/base64.type.js +6 -1
- package/cjs/document/data-type/extended-types/date-time.type.js +1 -1
- package/cjs/document/data-type/extended-types/date.type.js +1 -1
- package/cjs/document/data-type/extended-types/field-path.type.js +3 -3
- package/cjs/document/data-type/extended-types/filter.type.js +1 -1
- package/cjs/document/data-type/simple-type.js +10 -2
- package/cjs/document/decorators/http-operation.decorator.js +13 -0
- package/cjs/document/decorators/mq-operation.decorator.js +12 -8
- package/cjs/document/decorators/ws-controller.decorator.js +4 -4
- package/cjs/document/decorators/ws-operation.decorator.js +6 -7
- package/cjs/document/decorators/ws-param.decorator.js +22 -0
- package/cjs/document/factory/api-document.factory.js +9 -0
- package/cjs/document/factory/data-type.factory.js +27 -0
- package/cjs/document/factory/mq-api.factory.js +4 -4
- package/cjs/document/factory/ws-api.factory.js +26 -4
- package/cjs/document/http/http-media-type.js +13 -4
- package/cjs/document/http/http-parameter.js +8 -0
- package/cjs/document/index.js +2 -0
- package/cjs/document/mq/mq-header.js +8 -0
- package/cjs/document/mq/mq-operation-response.js +9 -9
- package/cjs/document/mq/mq-operation.js +23 -10
- package/cjs/document/ws/ws-operation.js +22 -20
- package/cjs/filter/filter-rules.js +2 -2
- package/cjs/schema/data-type/array-type.interface.js +7 -0
- package/cjs/schema/opra-schema.js +1 -0
- package/cjs/schema/type-guards.js +7 -1
- package/esm/document/api-document.js +14 -2
- package/esm/document/common/document-node.js +12 -1
- package/esm/document/constants.js +1 -0
- package/esm/document/data-type/api-field.js +7 -6
- package/esm/document/data-type/array-type.js +75 -0
- package/esm/document/data-type/complex-type-base.js +3 -4
- package/esm/document/data-type/extended-types/base64.type.js +6 -1
- package/esm/document/data-type/extended-types/date-time.type.js +1 -1
- package/esm/document/data-type/extended-types/date.type.js +1 -1
- package/esm/document/data-type/extended-types/field-path.type.js +3 -3
- package/esm/document/data-type/extended-types/filter.type.js +1 -1
- package/esm/document/data-type/simple-type.js +10 -2
- package/esm/document/decorators/http-operation.decorator.js +13 -0
- package/esm/document/decorators/mq-operation.decorator.js +13 -9
- package/esm/document/decorators/ws-controller.decorator.js +5 -5
- package/esm/document/decorators/ws-operation.decorator.js +7 -8
- package/esm/document/decorators/ws-param.decorator.js +19 -0
- package/esm/document/factory/api-document.factory.js +9 -0
- package/esm/document/factory/data-type.factory.js +27 -0
- package/esm/document/factory/mq-api.factory.js +4 -4
- package/esm/document/factory/ws-api.factory.js +27 -5
- package/esm/document/http/http-media-type.js +13 -4
- package/esm/document/http/http-parameter.js +8 -0
- package/esm/document/index.js +2 -0
- package/esm/document/mq/mq-header.js +8 -0
- package/esm/document/mq/mq-operation-response.js +9 -9
- package/esm/document/mq/mq-operation.js +23 -10
- package/esm/document/ws/ws-operation.js +22 -20
- package/esm/filter/filter-rules.js +2 -2
- package/esm/schema/data-type/array-type.interface.js +4 -0
- package/esm/schema/opra-schema.js +1 -0
- package/esm/schema/type-guards.js +6 -1
- package/package.json +1 -1
- package/types/document/api-document.d.ts +6 -3
- package/types/document/common/document-node.d.ts +7 -0
- package/types/document/constants.d.ts +1 -0
- package/types/document/data-type/api-field.d.ts +6 -9
- package/types/document/data-type/array-type.d.ts +76 -0
- package/types/document/data-type/extended-types/base64.type.d.ts +2 -1
- package/types/document/data-type/extended-types/date-time.type.d.ts +2 -1
- package/types/document/data-type/extended-types/date.type.d.ts +2 -1
- package/types/document/data-type/extended-types/field-path.type.d.ts +5 -2
- package/types/document/data-type/extended-types/filter.type.d.ts +3 -1
- package/types/document/data-type/simple-type.d.ts +6 -2
- package/types/document/decorators/mq-operation.decorator.d.ts +5 -5
- package/types/document/decorators/ws-controller.decorator.d.ts +0 -2
- package/types/document/decorators/ws-operation.decorator.d.ts +5 -5
- package/types/document/decorators/ws-param.decorator.d.ts +2 -0
- package/types/document/factory/data-type.factory.d.ts +12 -2
- package/types/document/http/http-media-type.d.ts +3 -1
- package/types/document/http/http-parameter.d.ts +5 -1
- package/types/document/index.d.ts +2 -0
- package/types/document/mq/mq-header.d.ts +5 -1
- package/types/document/mq/mq-operation-response.d.ts +8 -4
- package/types/document/mq/mq-operation.d.ts +13 -6
- package/types/document/ws/ws-controller.d.ts +0 -1
- package/types/document/ws/ws-operation.d.ts +14 -14
- package/types/schema/data-type/array-type.interface.d.ts +16 -0
- package/types/schema/data-type/data-type.interface.d.ts +3 -2
- package/types/schema/data-type/field.interface.d.ts +1 -0
- package/types/schema/http/http-media-type.interface.d.ts +1 -0
- package/types/schema/mq/mq-operation.interface.d.ts +2 -2
- package/types/schema/opra-schema.d.ts +1 -0
- package/types/schema/type-guards.d.ts +2 -0
- package/types/schema/value.interface.d.ts +1 -0
- package/types/schema/ws/ws-operation.interface.d.ts +3 -2
|
@@ -87,17 +87,26 @@ class WSApiFactory {
|
|
|
87
87
|
}
|
|
88
88
|
if (metadata.operations) {
|
|
89
89
|
await context.enterAsync('.operations', async () => {
|
|
90
|
-
for (const [operationName,
|
|
90
|
+
for (const [operationName, _operationMeta] of Object.entries(metadata.operations)) {
|
|
91
91
|
await context.enterAsync(`[${operationName}]`, async () => {
|
|
92
|
+
const argumentsMetadata = Reflect.getMetadata(constants_js_1.WS_PARAM_METADATA, ctor.prototype, operationName);
|
|
93
|
+
let operationMeta = _operationMeta;
|
|
94
|
+
if (argumentsMetadata) {
|
|
95
|
+
operationMeta = {
|
|
96
|
+
...operationMeta,
|
|
97
|
+
arguments: argumentsMetadata,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
92
100
|
const operation = new ws_operation_js_1.WSOperation(controller, {
|
|
93
101
|
...operationMeta,
|
|
94
102
|
name: operationName,
|
|
95
103
|
types: undefined,
|
|
96
|
-
|
|
104
|
+
type: undefined,
|
|
97
105
|
keyType: undefined,
|
|
106
|
+
arguments: undefined,
|
|
98
107
|
});
|
|
99
108
|
await this._initWSOperation(context, operation, operationMeta);
|
|
100
|
-
controller.operations.set(
|
|
109
|
+
controller.operations.set(operationName, operation);
|
|
101
110
|
});
|
|
102
111
|
}
|
|
103
112
|
});
|
|
@@ -117,7 +126,20 @@ class WSApiFactory {
|
|
|
117
126
|
await data_type_factory_js_1.DataTypeFactory.addDataTypes(context, operation, metadata.types);
|
|
118
127
|
});
|
|
119
128
|
}
|
|
120
|
-
|
|
129
|
+
if (metadata.arguments?.length) {
|
|
130
|
+
await context.enterAsync('.arguments', async () => {
|
|
131
|
+
operation.arguments = [];
|
|
132
|
+
for (const x of metadata.arguments) {
|
|
133
|
+
const t = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, operation, x);
|
|
134
|
+
operation.arguments?.push(t);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (metadata.response) {
|
|
139
|
+
await context.enterAsync('.response', async () => {
|
|
140
|
+
operation.response = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, operation, metadata.response);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
121
143
|
}
|
|
122
144
|
}
|
|
123
145
|
exports.WSApiFactory = WSApiFactory;
|
|
@@ -7,6 +7,7 @@ const objects_1 = require("@jsopen/objects");
|
|
|
7
7
|
const ts_gems_1 = require("ts-gems");
|
|
8
8
|
const valgen_1 = require("valgen");
|
|
9
9
|
const document_element_js_1 = require("../common/document-element.js");
|
|
10
|
+
const array_type_js_1 = require("../data-type/array-type.js");
|
|
10
11
|
const data_type_js_1 = require("../data-type/data-type.js");
|
|
11
12
|
exports.HttpMediaType = function (owner, initArgs) {
|
|
12
13
|
if (!this)
|
|
@@ -36,6 +37,7 @@ exports.HttpMediaType = function (owner, initArgs) {
|
|
|
36
37
|
: _this.owner.node.getDataType(initArgs.type);
|
|
37
38
|
}
|
|
38
39
|
_this.isArray = initArgs.isArray;
|
|
40
|
+
_this.designType = initArgs.designType;
|
|
39
41
|
};
|
|
40
42
|
/**
|
|
41
43
|
* @class HttpMediaType
|
|
@@ -75,21 +77,28 @@ class HttpMediaTypeClass extends document_element_js_1.DocumentElement {
|
|
|
75
77
|
}
|
|
76
78
|
return out;
|
|
77
79
|
}
|
|
78
|
-
generateCodec(codec, options) {
|
|
80
|
+
generateCodec(codec, options, properties) {
|
|
79
81
|
let fn;
|
|
80
82
|
if (this.type) {
|
|
81
|
-
fn = this.type.generateCodec(codec, options
|
|
83
|
+
fn = this.type.generateCodec(codec, options, {
|
|
84
|
+
designType: this.designType,
|
|
85
|
+
});
|
|
82
86
|
}
|
|
83
87
|
else if (this.contentType) {
|
|
84
88
|
const arr = Array.isArray(this.contentType)
|
|
85
89
|
? this.contentType
|
|
86
90
|
: [this.contentType];
|
|
87
91
|
if (arr.find(ct => type_is_1.default.is(ct, ['json']))) {
|
|
88
|
-
fn = this.node.findDataType('object').generateCodec(codec
|
|
92
|
+
fn = this.node.findDataType('object').generateCodec(codec, options, {
|
|
93
|
+
...properties,
|
|
94
|
+
designType: this.designType,
|
|
95
|
+
});
|
|
89
96
|
}
|
|
90
97
|
}
|
|
91
98
|
fn = fn || valgen_1.isAny;
|
|
92
|
-
return this.isArray
|
|
99
|
+
return this.isArray && !(this.type instanceof array_type_js_1.ArrayType)
|
|
100
|
+
? valgen_1.vg.isArray(fn)
|
|
101
|
+
: fn;
|
|
93
102
|
}
|
|
94
103
|
}
|
|
95
104
|
exports.HttpMediaType.prototype = HttpMediaTypeClass.prototype;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.HttpParameter = void 0;
|
|
4
4
|
const objects_1 = require("@jsopen/objects");
|
|
5
5
|
const ts_gems_1 = require("ts-gems");
|
|
6
|
+
const valgen_1 = require("valgen");
|
|
6
7
|
const value_js_1 = require("../common/value.js");
|
|
7
8
|
const parse_regexp_util_js_1 = require("../utils/parse-regexp.util.js");
|
|
8
9
|
exports.HttpParameter = function (owner, initArgs) {
|
|
@@ -29,6 +30,7 @@ exports.HttpParameter = function (owner, initArgs) {
|
|
|
29
30
|
_this.arraySeparator = initArgs.arraySeparator;
|
|
30
31
|
_this.keyParam = initArgs.keyParam;
|
|
31
32
|
_this.parser = initArgs.parser;
|
|
33
|
+
_this.designType = initArgs.designType;
|
|
32
34
|
};
|
|
33
35
|
/**
|
|
34
36
|
* @class HttpParameter
|
|
@@ -45,5 +47,11 @@ class HttpParameterClass extends value_js_1.Value {
|
|
|
45
47
|
deprecated: this.deprecated,
|
|
46
48
|
});
|
|
47
49
|
}
|
|
50
|
+
generateCodec(codec, options, properties) {
|
|
51
|
+
return (this.type?.generateCodec(codec, options, {
|
|
52
|
+
...properties,
|
|
53
|
+
designType: this.designType,
|
|
54
|
+
}) || valgen_1.vg.isAny());
|
|
55
|
+
}
|
|
48
56
|
}
|
|
49
57
|
exports.HttpParameter.prototype = HttpParameterClass.prototype;
|
package/cjs/document/index.js
CHANGED
|
@@ -27,6 +27,7 @@ tslib_1.__exportStar(require("./common/document-node.js"), exports);
|
|
|
27
27
|
tslib_1.__exportStar(require("./common/opra-document-error.js"), exports);
|
|
28
28
|
tslib_1.__exportStar(require("./constants.js"), exports);
|
|
29
29
|
tslib_1.__exportStar(require("./data-type/api-field.js"), exports);
|
|
30
|
+
tslib_1.__exportStar(require("./data-type/array-type.js"), exports);
|
|
30
31
|
tslib_1.__exportStar(require("./data-type/complex-type.js"), exports);
|
|
31
32
|
tslib_1.__exportStar(require("./data-type/data-type.js"), exports);
|
|
32
33
|
tslib_1.__exportStar(require("./data-type/enum-type.js"), exports);
|
|
@@ -40,6 +41,7 @@ tslib_1.__exportStar(require("./data-type/primitive-types/index.js"), exports);
|
|
|
40
41
|
tslib_1.__exportStar(require("./data-type/required-type.js"), exports);
|
|
41
42
|
tslib_1.__exportStar(require("./data-type/simple-type.js"), exports);
|
|
42
43
|
tslib_1.__exportStar(require("./data-type/union-type.js"), exports);
|
|
44
|
+
tslib_1.__exportStar(require("./decorators/ws-param.decorator.js"), exports);
|
|
43
45
|
tslib_1.__exportStar(require("./factory/api-document.factory.js"), exports);
|
|
44
46
|
tslib_1.__exportStar(require("./http/http-api.js"), exports);
|
|
45
47
|
tslib_1.__exportStar(require("./http/http-controller.js"), exports);
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MQHeader = void 0;
|
|
4
4
|
const objects_1 = require("@jsopen/objects");
|
|
5
5
|
const ts_gems_1 = require("ts-gems");
|
|
6
|
+
const valgen_1 = require("valgen");
|
|
6
7
|
const value_js_1 = require("../common/value.js");
|
|
7
8
|
const parse_regexp_util_js_1 = require("../utils/parse-regexp.util.js");
|
|
8
9
|
exports.MQHeader = function (owner, initArgs) {
|
|
@@ -23,6 +24,7 @@ exports.MQHeader = function (owner, initArgs) {
|
|
|
23
24
|
}
|
|
24
25
|
_this.deprecated = initArgs.deprecated;
|
|
25
26
|
_this.required = initArgs.required;
|
|
27
|
+
_this.designType = initArgs.designType;
|
|
26
28
|
};
|
|
27
29
|
/**
|
|
28
30
|
* @class MQHeader
|
|
@@ -36,5 +38,11 @@ class MQHeaderClass extends value_js_1.Value {
|
|
|
36
38
|
deprecated: this.deprecated,
|
|
37
39
|
});
|
|
38
40
|
}
|
|
41
|
+
generateCodec(codec, options, properties) {
|
|
42
|
+
return (this.type?.generateCodec(codec, options, {
|
|
43
|
+
...properties,
|
|
44
|
+
designType: this.designType,
|
|
45
|
+
}) || valgen_1.vg.isAny());
|
|
46
|
+
}
|
|
39
47
|
}
|
|
40
48
|
exports.MQHeader.prototype = MQHeaderClass.prototype;
|
|
@@ -13,20 +13,22 @@ class MQOperationResponse extends document_element_js_1.DocumentElement {
|
|
|
13
13
|
this.headers = [];
|
|
14
14
|
this.channel = initArgs?.channel;
|
|
15
15
|
this.description = initArgs?.description;
|
|
16
|
-
if (initArgs?.
|
|
17
|
-
this.
|
|
18
|
-
initArgs?.
|
|
19
|
-
? initArgs.
|
|
20
|
-
: this.owner.node.getDataType(initArgs.
|
|
16
|
+
if (initArgs?.type) {
|
|
17
|
+
this.type =
|
|
18
|
+
initArgs?.type instanceof data_type_js_1.DataType
|
|
19
|
+
? initArgs.type
|
|
20
|
+
: this.owner.node.getDataType(initArgs.type);
|
|
21
21
|
}
|
|
22
22
|
else
|
|
23
|
-
this.
|
|
23
|
+
this.type = this.owner.node.getDataType('any');
|
|
24
24
|
if (initArgs?.keyType) {
|
|
25
25
|
this.keyType =
|
|
26
26
|
initArgs?.keyType instanceof data_type_js_1.DataType
|
|
27
27
|
? initArgs.keyType
|
|
28
28
|
: this.owner.node.getDataType(initArgs.keyType);
|
|
29
29
|
}
|
|
30
|
+
this.designType = initArgs?.designType;
|
|
31
|
+
this.keyDesignType = initArgs?.keyDesignType;
|
|
30
32
|
}
|
|
31
33
|
findHeader(paramName) {
|
|
32
34
|
const paramNameLower = paramName.toLowerCase();
|
|
@@ -45,9 +47,7 @@ class MQOperationResponse extends document_element_js_1.DocumentElement {
|
|
|
45
47
|
const out = (0, objects_1.omitUndefined)({
|
|
46
48
|
description: this.description,
|
|
47
49
|
channel: this.channel,
|
|
48
|
-
|
|
49
|
-
? this.payloadType.name
|
|
50
|
-
: this.payloadType.toJSON(),
|
|
50
|
+
type: this.type.name ? this.type.name : this.type.toJSON(),
|
|
51
51
|
keyType: this.keyType
|
|
52
52
|
? this.keyType.name
|
|
53
53
|
? this.keyType.name
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MQOperation = void 0;
|
|
4
4
|
const objects_1 = require("@jsopen/objects");
|
|
5
5
|
const ts_gems_1 = require("ts-gems");
|
|
6
|
+
const valgen_1 = require("valgen");
|
|
6
7
|
const index_js_1 = require("../../schema/index.js");
|
|
7
8
|
const data_type_map_js_1 = require("../common/data-type-map.js");
|
|
8
9
|
const document_element_js_1 = require("../common/document-element.js");
|
|
@@ -15,9 +16,9 @@ const mq_operation_decorator_js_1 = require("../decorators/mq-operation.decorato
|
|
|
15
16
|
exports.MQOperation = function (...args) {
|
|
16
17
|
// Decorator
|
|
17
18
|
if (!this) {
|
|
18
|
-
const [
|
|
19
|
+
const [type, options] = args;
|
|
19
20
|
const decoratorChain = [];
|
|
20
|
-
return exports.MQOperation[constants_js_1.DECORATOR].call(undefined, decoratorChain,
|
|
21
|
+
return exports.MQOperation[constants_js_1.DECORATOR].call(undefined, decoratorChain, type, options);
|
|
21
22
|
}
|
|
22
23
|
// Constructor
|
|
23
24
|
const [resource, initArgs] = args;
|
|
@@ -30,11 +31,11 @@ exports.MQOperation = function (...args) {
|
|
|
30
31
|
_this.name = initArgs.name;
|
|
31
32
|
_this.description = initArgs.description;
|
|
32
33
|
_this.channel = initArgs.channel;
|
|
33
|
-
if (initArgs?.
|
|
34
|
-
_this.
|
|
35
|
-
initArgs?.
|
|
36
|
-
? initArgs.
|
|
37
|
-
: _this.owner.node.getDataType(initArgs.
|
|
34
|
+
if (initArgs?.type) {
|
|
35
|
+
_this.type =
|
|
36
|
+
initArgs?.type instanceof data_type_js_1.DataType
|
|
37
|
+
? initArgs.type
|
|
38
|
+
: _this.owner.node.getDataType(initArgs.type);
|
|
38
39
|
}
|
|
39
40
|
if (initArgs?.keyType) {
|
|
40
41
|
_this.keyType =
|
|
@@ -42,6 +43,8 @@ exports.MQOperation = function (...args) {
|
|
|
42
43
|
? initArgs.keyType
|
|
43
44
|
: _this.owner.node.getDataType(initArgs.keyType);
|
|
44
45
|
}
|
|
46
|
+
_this.designType = initArgs.designType;
|
|
47
|
+
_this.keyDesignType = initArgs.keyDesignType;
|
|
45
48
|
};
|
|
46
49
|
/**
|
|
47
50
|
* @class MQOperation
|
|
@@ -65,9 +68,7 @@ class MQOperationClass extends document_element_js_1.DocumentElement {
|
|
|
65
68
|
kind: index_js_1.OpraSchema.MQOperation.Kind,
|
|
66
69
|
description: this.description,
|
|
67
70
|
channel: this.channel,
|
|
68
|
-
|
|
69
|
-
? this.payloadType.name
|
|
70
|
-
: this.payloadType.toJSON(),
|
|
71
|
+
type: this.type.name ? this.type.name : this.type.toJSON(),
|
|
71
72
|
keyType: this.keyType
|
|
72
73
|
? this.keyType.name
|
|
73
74
|
? this.keyType.name
|
|
@@ -83,6 +84,18 @@ class MQOperationClass extends document_element_js_1.DocumentElement {
|
|
|
83
84
|
}
|
|
84
85
|
return out;
|
|
85
86
|
}
|
|
87
|
+
generateCodec(codec, options, properties) {
|
|
88
|
+
return (this.type?.generateCodec(codec, options, {
|
|
89
|
+
...properties,
|
|
90
|
+
designType: this.designType,
|
|
91
|
+
}) || valgen_1.vg.isAny());
|
|
92
|
+
}
|
|
93
|
+
generateKeyCodec(codec, options, properties) {
|
|
94
|
+
return (this.keyType?.generateCodec(codec, options, {
|
|
95
|
+
...properties,
|
|
96
|
+
designType: this.keyDesignType,
|
|
97
|
+
}) || valgen_1.vg.isAny());
|
|
98
|
+
}
|
|
86
99
|
}
|
|
87
100
|
exports.MQOperation.prototype = MQOperationClass.prototype;
|
|
88
101
|
exports.MQOperation[constants_js_1.DECORATOR] = mq_operation_decorator_js_1.MQOperationDecoratorFactory;
|
|
@@ -9,15 +9,16 @@ const document_element_js_1 = require("../common/document-element.js");
|
|
|
9
9
|
const constants_js_1 = require("../constants.js");
|
|
10
10
|
const data_type_js_1 = require("../data-type/data-type.js");
|
|
11
11
|
const ws_operation_decorator_js_1 = require("../decorators/ws-operation.decorator.js");
|
|
12
|
+
const parse_regexp_util_js_1 = require("../utils/parse-regexp.util.js");
|
|
12
13
|
/**
|
|
13
14
|
* WSOperation
|
|
14
15
|
*/
|
|
15
16
|
exports.WSOperation = function (...args) {
|
|
16
17
|
// Decorator
|
|
17
18
|
if (!this) {
|
|
18
|
-
const [
|
|
19
|
+
const [type, options] = args;
|
|
19
20
|
const decoratorChain = [];
|
|
20
|
-
return exports.WSOperation[constants_js_1.DECORATOR].call(undefined, decoratorChain,
|
|
21
|
+
return exports.WSOperation[constants_js_1.DECORATOR].call(undefined, decoratorChain, type, options);
|
|
21
22
|
}
|
|
22
23
|
// Constructor
|
|
23
24
|
const [resource, initArgs] = args;
|
|
@@ -28,34 +29,35 @@ exports.WSOperation = function (...args) {
|
|
|
28
29
|
_this.types = _this.node[constants_js_1.kDataTypeMap] = new data_type_map_js_1.DataTypeMap();
|
|
29
30
|
_this.name = initArgs.name;
|
|
30
31
|
_this.description = initArgs.description;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
_this.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
: _this.owner.node.getDataType(initArgs.keyType);
|
|
32
|
+
if (initArgs.event)
|
|
33
|
+
this.event =
|
|
34
|
+
initArgs.event instanceof RegExp
|
|
35
|
+
? initArgs.event
|
|
36
|
+
: initArgs.event.startsWith('/')
|
|
37
|
+
? (0, parse_regexp_util_js_1.parseRegExp)(initArgs.event)
|
|
38
|
+
: initArgs.event;
|
|
39
|
+
else
|
|
40
|
+
_this.event = this.name;
|
|
41
|
+
if (initArgs?.arguments) {
|
|
42
|
+
_this.arguments = initArgs.arguments.map(arg => arg instanceof data_type_js_1.DataType ? arg : _this.owner.node.getDataType(arg));
|
|
43
43
|
}
|
|
44
|
+
if (initArgs?.response)
|
|
45
|
+
_this.response =
|
|
46
|
+
initArgs.response instanceof data_type_js_1.DataType
|
|
47
|
+
? initArgs.response
|
|
48
|
+
: _this.owner.node.getDataType(initArgs.response);
|
|
44
49
|
};
|
|
45
50
|
/**
|
|
46
51
|
* @class WSOperation
|
|
47
52
|
*/
|
|
48
53
|
class WSOperationClass extends document_element_js_1.DocumentElement {
|
|
49
54
|
toJSON() {
|
|
50
|
-
|
|
55
|
+
return (0, objects_1.omitUndefined)({
|
|
51
56
|
kind: index_js_1.OpraSchema.WSOperation.Kind,
|
|
52
57
|
description: this.description,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
? this.payloadType.name
|
|
56
|
-
: this.payloadType.toJSON(),
|
|
58
|
+
event: this.event,
|
|
59
|
+
arguments: this.arguments?.map(arg => arg.name ? arg.name : arg.toJSON()),
|
|
57
60
|
});
|
|
58
|
-
return out;
|
|
59
61
|
}
|
|
60
62
|
}
|
|
61
63
|
exports.WSOperation.prototype = WSOperationClass.prototype;
|
|
@@ -125,10 +125,10 @@ class FilterRules {
|
|
|
125
125
|
else
|
|
126
126
|
decoder = this._decoderCache.get(comp.left.field);
|
|
127
127
|
if (!decoder) {
|
|
128
|
-
decoder = comp.left.field.
|
|
128
|
+
decoder = comp.left.field.generateCodec('decode', {
|
|
129
129
|
scope,
|
|
130
130
|
projection: '*',
|
|
131
|
-
|
|
131
|
+
ignoreReadonlyFields: true,
|
|
132
132
|
coerce: true,
|
|
133
133
|
});
|
|
134
134
|
this._decoderCache.set(comp.left.field, decoder);
|
|
@@ -4,6 +4,7 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
tslib_1.__exportStar(require("./api.interface.js"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./api-document.interface.js"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./constants.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./data-type/array-type.interface.js"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./data-type/complex-type.interface.js"), exports);
|
|
8
9
|
tslib_1.__exportStar(require("./data-type/data-type.interface.js"), exports);
|
|
9
10
|
tslib_1.__exportStar(require("./data-type/enum-type.interface.js"), exports);
|
|
@@ -7,7 +7,9 @@ exports.isMixinType = isMixinType;
|
|
|
7
7
|
exports.isMappedType = isMappedType;
|
|
8
8
|
exports.isEnumType = isEnumType;
|
|
9
9
|
exports.isUnionType = isUnionType;
|
|
10
|
+
exports.isArrayType = isArrayType;
|
|
10
11
|
exports.isHttpController = isHttpController;
|
|
12
|
+
const array_type_interface_js_1 = require("./data-type/array-type.interface.js");
|
|
11
13
|
const complex_type_interface_js_1 = require("./data-type/complex-type.interface.js");
|
|
12
14
|
const enum_type_interface_js_1 = require("./data-type/enum-type.interface.js");
|
|
13
15
|
const mapped_type_interface_js_1 = require("./data-type/mapped-type.interface.js");
|
|
@@ -18,7 +20,8 @@ const http_controller_interface_js_1 = require("./http/http-controller.interface
|
|
|
18
20
|
function isDataType(obj) {
|
|
19
21
|
return (obj &&
|
|
20
22
|
typeof obj === 'object' &&
|
|
21
|
-
(obj.kind ===
|
|
23
|
+
(obj.kind === array_type_interface_js_1.ArrayType.Kind ||
|
|
24
|
+
obj.kind === complex_type_interface_js_1.ComplexType.Kind ||
|
|
22
25
|
obj.kind === enum_type_interface_js_1.EnumType.Kind ||
|
|
23
26
|
obj.kind === mapped_type_interface_js_1.MappedType.Kind ||
|
|
24
27
|
obj.kind === simple_type_interface_js_1.SimpleType.Kind ||
|
|
@@ -43,6 +46,9 @@ function isEnumType(obj) {
|
|
|
43
46
|
function isUnionType(obj) {
|
|
44
47
|
return obj && typeof obj === 'object' && obj.kind === union_type_interface_js_1.UnionType.Kind;
|
|
45
48
|
}
|
|
49
|
+
function isArrayType(obj) {
|
|
50
|
+
return obj && typeof obj === 'object' && obj.kind === array_type_interface_js_1.ArrayType.Kind;
|
|
51
|
+
}
|
|
46
52
|
function isHttpController(obj) {
|
|
47
53
|
return obj && typeof obj === 'object' && obj.kind === http_controller_interface_js_1.HttpController.Kind;
|
|
48
54
|
}
|
|
@@ -48,18 +48,30 @@ export class ApiDocument extends DocumentElement {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
get httpApi() {
|
|
51
|
+
if (this.api && this.api instanceof HttpApi)
|
|
52
|
+
return this.api;
|
|
53
|
+
}
|
|
54
|
+
get mqApi() {
|
|
55
|
+
if (this.api && this.api instanceof MQApi)
|
|
56
|
+
return this.api;
|
|
57
|
+
}
|
|
58
|
+
get wsApi() {
|
|
59
|
+
if (this.api && this.api instanceof WSApi)
|
|
60
|
+
return this.api;
|
|
61
|
+
}
|
|
62
|
+
getHttpApi() {
|
|
51
63
|
if (!(this.api && this.api instanceof HttpApi)) {
|
|
52
64
|
throw new TypeError('The document do not contains HttpApi instance');
|
|
53
65
|
}
|
|
54
66
|
return this.api;
|
|
55
67
|
}
|
|
56
|
-
|
|
68
|
+
getMqApi() {
|
|
57
69
|
if (!(this.api && this.api instanceof MQApi)) {
|
|
58
70
|
throw new TypeError('The document do not contains MQApi instance');
|
|
59
71
|
}
|
|
60
72
|
return this.api;
|
|
61
73
|
}
|
|
62
|
-
|
|
74
|
+
getWsApi() {
|
|
63
75
|
if (!(this.api && this.api instanceof WSApi)) {
|
|
64
76
|
throw new TypeError('The document do not contains WSApi instance');
|
|
65
77
|
}
|
|
@@ -61,6 +61,17 @@ export class DocumentNode {
|
|
|
61
61
|
const ns = this.getDocument().getDataTypeNs(dataType);
|
|
62
62
|
return ns ? ns + ':' + dataType.name : dataType.name;
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns EnumType instance by name or Constructor.
|
|
66
|
+
* Returns undefined if not found
|
|
67
|
+
* Throws error if data type is not a UnionType
|
|
68
|
+
*/
|
|
69
|
+
getArrayType(nameOrCtor, scope) {
|
|
70
|
+
const t = this.getDataType(nameOrCtor, scope);
|
|
71
|
+
if (t.kind === OpraSchema.ArrayType.Kind)
|
|
72
|
+
return t;
|
|
73
|
+
throw new TypeError(`Data type "${t.name || t}" is not a MixinType`);
|
|
74
|
+
}
|
|
64
75
|
/**
|
|
65
76
|
* Returns ComplexType instance by name or Constructor.
|
|
66
77
|
* Returns undefined if not found
|
|
@@ -125,6 +136,6 @@ export class DocumentNode {
|
|
|
125
136
|
const t = this.getDataType(nameOrCtor, scope);
|
|
126
137
|
if (t.kind === OpraSchema.UnionType.Kind)
|
|
127
138
|
return t;
|
|
128
|
-
throw new TypeError(`Data type "${t.name || t}" is not a
|
|
139
|
+
throw new TypeError(`Data type "${t.name || t}" is not a UnionType`);
|
|
129
140
|
}
|
|
130
141
|
}
|
|
@@ -2,6 +2,7 @@ export const DATATYPE_METADATA = Symbol.for('opra.type.metadata');
|
|
|
2
2
|
export const HTTP_CONTROLLER_METADATA = Symbol('opra.http-controller.metadata');
|
|
3
3
|
export const MQ_CONTROLLER_METADATA = Symbol('opra.mq-controller.metadata');
|
|
4
4
|
export const WS_CONTROLLER_METADATA = Symbol('opra.ws-controller.metadata');
|
|
5
|
+
export const WS_PARAM_METADATA = Symbol('opra.ws-param.metadata');
|
|
5
6
|
export const RPC_CONTROLLER_METADATA = Symbol('opra.rpc-controller.metadata');
|
|
6
7
|
export const DECODER = Symbol.for('opra.type.decoder');
|
|
7
8
|
export const ENCODER = Symbol('opra.type.encoder');
|
|
@@ -45,12 +45,7 @@ export const ApiField = function (...args) {
|
|
|
45
45
|
? initArgs.scopePattern
|
|
46
46
|
: [initArgs.scopePattern]
|
|
47
47
|
: undefined;
|
|
48
|
-
_this.
|
|
49
|
-
initArgs.convertToNative ??
|
|
50
|
-
(_this.type.kind === 'SimpleType' &&
|
|
51
|
-
initArgs.designType !== String &&
|
|
52
|
-
typeof initArgs.designType === 'function' &&
|
|
53
|
-
initArgs.designType !== Object);
|
|
48
|
+
_this.designType = initArgs.designType;
|
|
54
49
|
_this.override = initArgs.override;
|
|
55
50
|
};
|
|
56
51
|
/**
|
|
@@ -114,6 +109,12 @@ class ApiFieldClass extends DocumentElement {
|
|
|
114
109
|
examples: this.examples,
|
|
115
110
|
});
|
|
116
111
|
}
|
|
112
|
+
generateCodec(codec, options, properties) {
|
|
113
|
+
return this.type.generateCodec(codec, options, {
|
|
114
|
+
...properties,
|
|
115
|
+
designType: this.designType,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
117
118
|
}
|
|
118
119
|
ApiField.prototype = ApiFieldClass.prototype;
|
|
119
120
|
Object.assign(ApiField, ApiFieldDecoratorFactory);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { omitUndefined } from '@jsopen/objects';
|
|
3
|
+
import { asMutable } from 'ts-gems';
|
|
4
|
+
import { vg } from 'valgen';
|
|
5
|
+
import { OpraSchema } from '../../schema/index.js';
|
|
6
|
+
import { DATATYPE_METADATA, DECORATOR } from '../constants.js';
|
|
7
|
+
import { DataType } from './data-type.js';
|
|
8
|
+
/**
|
|
9
|
+
* @class ArrayType
|
|
10
|
+
*/
|
|
11
|
+
export const ArrayType = function (...args) {
|
|
12
|
+
// ArrayType factory
|
|
13
|
+
if (!this) {
|
|
14
|
+
return ArrayType[DECORATOR].apply(undefined, args);
|
|
15
|
+
}
|
|
16
|
+
// Constructor
|
|
17
|
+
const [owner, initArgs, context] = args;
|
|
18
|
+
DataType.call(this, owner, initArgs, context);
|
|
19
|
+
const _this = asMutable(this);
|
|
20
|
+
_this.kind = OpraSchema.ArrayType.Kind;
|
|
21
|
+
_this.type = initArgs.type;
|
|
22
|
+
_this.minOccurs = initArgs.minOccurs;
|
|
23
|
+
_this.maxOccurs = initArgs.maxOccurs;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @class ArrayType
|
|
28
|
+
*/
|
|
29
|
+
class ArrayTypeClass extends DataType {
|
|
30
|
+
toJSON(options) {
|
|
31
|
+
const superJson = super.toJSON(options);
|
|
32
|
+
const typeName = this.node.getDataTypeNameWithNs(this.type);
|
|
33
|
+
return omitUndefined({
|
|
34
|
+
...superJson,
|
|
35
|
+
kind: this.kind,
|
|
36
|
+
type: typeName ? typeName : this.type.toJSON(options),
|
|
37
|
+
minOccurs: this.minOccurs,
|
|
38
|
+
maxOccurs: this.maxOccurs,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
generateCodec(codec, options, properties) {
|
|
42
|
+
let fn = this.type.generateCodec(codec, options, properties);
|
|
43
|
+
fn = vg.isArray(fn);
|
|
44
|
+
const fns = [];
|
|
45
|
+
if (this.minOccurs)
|
|
46
|
+
fns.push(vg.lengthMin(this.minOccurs));
|
|
47
|
+
if (this.maxOccurs)
|
|
48
|
+
fns.push(vg.lengthMax(this.maxOccurs));
|
|
49
|
+
if (fns.length > 0)
|
|
50
|
+
return vg.pipe([fn, ...fns], { returnIndex: 0 });
|
|
51
|
+
return fn;
|
|
52
|
+
}
|
|
53
|
+
extendsFrom() {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
_locateBase() {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
ArrayType.prototype = ArrayTypeClass.prototype;
|
|
61
|
+
ArrayType[DECORATOR] = ArrayTypeFactory;
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
65
|
+
function ArrayTypeFactory(clasRefs, options) {
|
|
66
|
+
class ArrayClass {
|
|
67
|
+
}
|
|
68
|
+
const metadata = {
|
|
69
|
+
...options,
|
|
70
|
+
kind: OpraSchema.ArrayType.Kind,
|
|
71
|
+
type: clasRefs,
|
|
72
|
+
};
|
|
73
|
+
Reflect.defineMetadata(DATATYPE_METADATA, metadata, ArrayClass);
|
|
74
|
+
return ArrayClass;
|
|
75
|
+
}
|
|
@@ -2,6 +2,7 @@ import hashObject from 'object-hash';
|
|
|
2
2
|
import { asMutable } from 'ts-gems';
|
|
3
3
|
import { validator, vg } from 'valgen';
|
|
4
4
|
import { parseFieldsProjection, ResponsiveMap, } from '../../helpers/index.js';
|
|
5
|
+
import { ArrayType } from './array-type.js';
|
|
5
6
|
import { DataType } from './data-type.js';
|
|
6
7
|
export const FIELD_PATH_PATTERN = /^([+-])?([a-z$_][\w.]*)$/i;
|
|
7
8
|
/**
|
|
@@ -327,15 +328,13 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
327
328
|
return schema;
|
|
328
329
|
}
|
|
329
330
|
_generateFieldCodec(codec, field, context) {
|
|
330
|
-
let fn = field.
|
|
331
|
+
let fn = field.generateCodec(codec, {
|
|
331
332
|
...context,
|
|
332
333
|
level: context.level + 1,
|
|
333
|
-
}, {
|
|
334
|
-
convertToNative: field.convertToNative,
|
|
335
334
|
});
|
|
336
335
|
if (field.fixed)
|
|
337
336
|
fn = vg.isEqual(field.fixed);
|
|
338
|
-
if (field.isArray)
|
|
337
|
+
if (field.isArray && !(field.type instanceof ArrayType))
|
|
339
338
|
fn = vg.isArray(fn);
|
|
340
339
|
return fn;
|
|
341
340
|
}
|
|
@@ -9,8 +9,10 @@ let Base64Type = class Base64Type {
|
|
|
9
9
|
}
|
|
10
10
|
[DECODER](properties) {
|
|
11
11
|
const fn = vg.isBase64({ coerce: true });
|
|
12
|
-
if (properties.
|
|
12
|
+
if (properties.designType === Buffer)
|
|
13
13
|
return vg.pipe([fn, toBuffer], { coerce: true });
|
|
14
|
+
if (properties.designType === Uint8Array)
|
|
15
|
+
return vg.pipe([fn, toUint8Array], { coerce: true });
|
|
14
16
|
return fn;
|
|
15
17
|
}
|
|
16
18
|
[ENCODER]() {
|
|
@@ -32,6 +34,9 @@ export { Base64Type };
|
|
|
32
34
|
const toBuffer = validator((base64String) => {
|
|
33
35
|
return Buffer.from(base64String, 'base64');
|
|
34
36
|
});
|
|
37
|
+
const toUint8Array = validator((base64String) => {
|
|
38
|
+
return new Uint8Array(Buffer.from(base64String, 'base64'));
|
|
39
|
+
});
|
|
35
40
|
const fromBuffer = validator((input) => {
|
|
36
41
|
if (Buffer.isBuffer(input))
|
|
37
42
|
return input.toString('base64');
|