@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
|
@@ -51,18 +51,30 @@ class ApiDocument extends document_element_js_1.DocumentElement {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
get httpApi() {
|
|
54
|
+
if (this.api && this.api instanceof http_api_js_1.HttpApi)
|
|
55
|
+
return this.api;
|
|
56
|
+
}
|
|
57
|
+
get mqApi() {
|
|
58
|
+
if (this.api && this.api instanceof mq_api_js_1.MQApi)
|
|
59
|
+
return this.api;
|
|
60
|
+
}
|
|
61
|
+
get wsApi() {
|
|
62
|
+
if (this.api && this.api instanceof ws_api_js_1.WSApi)
|
|
63
|
+
return this.api;
|
|
64
|
+
}
|
|
65
|
+
getHttpApi() {
|
|
54
66
|
if (!(this.api && this.api instanceof http_api_js_1.HttpApi)) {
|
|
55
67
|
throw new TypeError('The document do not contains HttpApi instance');
|
|
56
68
|
}
|
|
57
69
|
return this.api;
|
|
58
70
|
}
|
|
59
|
-
|
|
71
|
+
getMqApi() {
|
|
60
72
|
if (!(this.api && this.api instanceof mq_api_js_1.MQApi)) {
|
|
61
73
|
throw new TypeError('The document do not contains MQApi instance');
|
|
62
74
|
}
|
|
63
75
|
return this.api;
|
|
64
76
|
}
|
|
65
|
-
|
|
77
|
+
getWsApi() {
|
|
66
78
|
if (!(this.api && this.api instanceof ws_api_js_1.WSApi)) {
|
|
67
79
|
throw new TypeError('The document do not contains WSApi instance');
|
|
68
80
|
}
|
|
@@ -64,6 +64,17 @@ class DocumentNode {
|
|
|
64
64
|
const ns = this.getDocument().getDataTypeNs(dataType);
|
|
65
65
|
return ns ? ns + ':' + dataType.name : dataType.name;
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns EnumType instance by name or Constructor.
|
|
69
|
+
* Returns undefined if not found
|
|
70
|
+
* Throws error if data type is not a UnionType
|
|
71
|
+
*/
|
|
72
|
+
getArrayType(nameOrCtor, scope) {
|
|
73
|
+
const t = this.getDataType(nameOrCtor, scope);
|
|
74
|
+
if (t.kind === index_js_1.OpraSchema.ArrayType.Kind)
|
|
75
|
+
return t;
|
|
76
|
+
throw new TypeError(`Data type "${t.name || t}" is not a MixinType`);
|
|
77
|
+
}
|
|
67
78
|
/**
|
|
68
79
|
* Returns ComplexType instance by name or Constructor.
|
|
69
80
|
* Returns undefined if not found
|
|
@@ -128,7 +139,7 @@ class DocumentNode {
|
|
|
128
139
|
const t = this.getDataType(nameOrCtor, scope);
|
|
129
140
|
if (t.kind === index_js_1.OpraSchema.UnionType.Kind)
|
|
130
141
|
return t;
|
|
131
|
-
throw new TypeError(`Data type "${t.name || t}" is not a
|
|
142
|
+
throw new TypeError(`Data type "${t.name || t}" is not a UnionType`);
|
|
132
143
|
}
|
|
133
144
|
}
|
|
134
145
|
exports.DocumentNode = DocumentNode;
|
|
@@ -1,10 +1,11 @@
|
|
|
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.WS_CONTROLLER_METADATA = exports.MQ_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_PARAM_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
6
|
exports.MQ_CONTROLLER_METADATA = Symbol('opra.mq-controller.metadata');
|
|
7
7
|
exports.WS_CONTROLLER_METADATA = Symbol('opra.ws-controller.metadata');
|
|
8
|
+
exports.WS_PARAM_METADATA = Symbol('opra.ws-param.metadata');
|
|
8
9
|
exports.RPC_CONTROLLER_METADATA = Symbol('opra.rpc-controller.metadata');
|
|
9
10
|
exports.DECODER = Symbol.for('opra.type.decoder');
|
|
10
11
|
exports.ENCODER = Symbol('opra.type.encoder');
|
|
@@ -48,12 +48,7 @@ exports.ApiField = function (...args) {
|
|
|
48
48
|
? initArgs.scopePattern
|
|
49
49
|
: [initArgs.scopePattern]
|
|
50
50
|
: undefined;
|
|
51
|
-
_this.
|
|
52
|
-
initArgs.convertToNative ??
|
|
53
|
-
(_this.type.kind === 'SimpleType' &&
|
|
54
|
-
initArgs.designType !== String &&
|
|
55
|
-
typeof initArgs.designType === 'function' &&
|
|
56
|
-
initArgs.designType !== Object);
|
|
51
|
+
_this.designType = initArgs.designType;
|
|
57
52
|
_this.override = initArgs.override;
|
|
58
53
|
};
|
|
59
54
|
/**
|
|
@@ -117,6 +112,12 @@ class ApiFieldClass extends document_element_js_1.DocumentElement {
|
|
|
117
112
|
examples: this.examples,
|
|
118
113
|
});
|
|
119
114
|
}
|
|
115
|
+
generateCodec(codec, options, properties) {
|
|
116
|
+
return this.type.generateCodec(codec, options, {
|
|
117
|
+
...properties,
|
|
118
|
+
designType: this.designType,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
120
121
|
}
|
|
121
122
|
exports.ApiField.prototype = ApiFieldClass.prototype;
|
|
122
123
|
Object.assign(exports.ApiField, api_field_decorator_js_1.ApiFieldDecoratorFactory);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArrayType = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const objects_1 = require("@jsopen/objects");
|
|
6
|
+
const ts_gems_1 = require("ts-gems");
|
|
7
|
+
const valgen_1 = require("valgen");
|
|
8
|
+
const index_js_1 = require("../../schema/index.js");
|
|
9
|
+
const constants_js_1 = require("../constants.js");
|
|
10
|
+
const data_type_js_1 = require("./data-type.js");
|
|
11
|
+
/**
|
|
12
|
+
* @class ArrayType
|
|
13
|
+
*/
|
|
14
|
+
exports.ArrayType = function (...args) {
|
|
15
|
+
// ArrayType factory
|
|
16
|
+
if (!this) {
|
|
17
|
+
return exports.ArrayType[constants_js_1.DECORATOR].apply(undefined, args);
|
|
18
|
+
}
|
|
19
|
+
// Constructor
|
|
20
|
+
const [owner, initArgs, context] = args;
|
|
21
|
+
data_type_js_1.DataType.call(this, owner, initArgs, context);
|
|
22
|
+
const _this = (0, ts_gems_1.asMutable)(this);
|
|
23
|
+
_this.kind = index_js_1.OpraSchema.ArrayType.Kind;
|
|
24
|
+
_this.type = initArgs.type;
|
|
25
|
+
_this.minOccurs = initArgs.minOccurs;
|
|
26
|
+
_this.maxOccurs = initArgs.maxOccurs;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @class ArrayType
|
|
31
|
+
*/
|
|
32
|
+
class ArrayTypeClass extends data_type_js_1.DataType {
|
|
33
|
+
toJSON(options) {
|
|
34
|
+
const superJson = super.toJSON(options);
|
|
35
|
+
const typeName = this.node.getDataTypeNameWithNs(this.type);
|
|
36
|
+
return (0, objects_1.omitUndefined)({
|
|
37
|
+
...superJson,
|
|
38
|
+
kind: this.kind,
|
|
39
|
+
type: typeName ? typeName : this.type.toJSON(options),
|
|
40
|
+
minOccurs: this.minOccurs,
|
|
41
|
+
maxOccurs: this.maxOccurs,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
generateCodec(codec, options, properties) {
|
|
45
|
+
let fn = this.type.generateCodec(codec, options, properties);
|
|
46
|
+
fn = valgen_1.vg.isArray(fn);
|
|
47
|
+
const fns = [];
|
|
48
|
+
if (this.minOccurs)
|
|
49
|
+
fns.push(valgen_1.vg.lengthMin(this.minOccurs));
|
|
50
|
+
if (this.maxOccurs)
|
|
51
|
+
fns.push(valgen_1.vg.lengthMax(this.maxOccurs));
|
|
52
|
+
if (fns.length > 0)
|
|
53
|
+
return valgen_1.vg.pipe([fn, ...fns], { returnIndex: 0 });
|
|
54
|
+
return fn;
|
|
55
|
+
}
|
|
56
|
+
extendsFrom() {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
_locateBase() {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.ArrayType.prototype = ArrayTypeClass.prototype;
|
|
64
|
+
exports.ArrayType[constants_js_1.DECORATOR] = ArrayTypeFactory;
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
function ArrayTypeFactory(clasRefs, options) {
|
|
69
|
+
class ArrayClass {
|
|
70
|
+
}
|
|
71
|
+
const metadata = {
|
|
72
|
+
...options,
|
|
73
|
+
kind: index_js_1.OpraSchema.ArrayType.Kind,
|
|
74
|
+
type: clasRefs,
|
|
75
|
+
};
|
|
76
|
+
Reflect.defineMetadata(constants_js_1.DATATYPE_METADATA, metadata, ArrayClass);
|
|
77
|
+
return ArrayClass;
|
|
78
|
+
}
|
|
@@ -6,6 +6,7 @@ const object_hash_1 = tslib_1.__importDefault(require("object-hash"));
|
|
|
6
6
|
const ts_gems_1 = require("ts-gems");
|
|
7
7
|
const valgen_1 = require("valgen");
|
|
8
8
|
const index_js_1 = require("../../helpers/index.js");
|
|
9
|
+
const array_type_js_1 = require("./array-type.js");
|
|
9
10
|
const data_type_js_1 = require("./data-type.js");
|
|
10
11
|
exports.FIELD_PATH_PATTERN = /^([+-])?([a-z$_][\w.]*)$/i;
|
|
11
12
|
/**
|
|
@@ -331,15 +332,13 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
|
|
|
331
332
|
return schema;
|
|
332
333
|
}
|
|
333
334
|
_generateFieldCodec(codec, field, context) {
|
|
334
|
-
let fn = field.
|
|
335
|
+
let fn = field.generateCodec(codec, {
|
|
335
336
|
...context,
|
|
336
337
|
level: context.level + 1,
|
|
337
|
-
}, {
|
|
338
|
-
convertToNative: field.convertToNative,
|
|
339
338
|
});
|
|
340
339
|
if (field.fixed)
|
|
341
340
|
fn = valgen_1.vg.isEqual(field.fixed);
|
|
342
|
-
if (field.isArray)
|
|
341
|
+
if (field.isArray && !(field.type instanceof array_type_js_1.ArrayType))
|
|
343
342
|
fn = valgen_1.vg.isArray(fn);
|
|
344
343
|
return fn;
|
|
345
344
|
}
|
|
@@ -12,8 +12,10 @@ let Base64Type = class Base64Type {
|
|
|
12
12
|
}
|
|
13
13
|
[constants_js_1.DECODER](properties) {
|
|
14
14
|
const fn = valgen_1.vg.isBase64({ coerce: true });
|
|
15
|
-
if (properties.
|
|
15
|
+
if (properties.designType === Buffer)
|
|
16
16
|
return valgen_1.vg.pipe([fn, toBuffer], { coerce: true });
|
|
17
|
+
if (properties.designType === Uint8Array)
|
|
18
|
+
return valgen_1.vg.pipe([fn, toUint8Array], { coerce: true });
|
|
17
19
|
return fn;
|
|
18
20
|
}
|
|
19
21
|
[constants_js_1.ENCODER]() {
|
|
@@ -35,6 +37,9 @@ exports.Base64Type = Base64Type = tslib_1.__decorate([
|
|
|
35
37
|
const toBuffer = (0, valgen_1.validator)((base64String) => {
|
|
36
38
|
return Buffer.from(base64String, 'base64');
|
|
37
39
|
});
|
|
40
|
+
const toUint8Array = (0, valgen_1.validator)((base64String) => {
|
|
41
|
+
return new Uint8Array(Buffer.from(base64String, 'base64'));
|
|
42
|
+
});
|
|
38
43
|
const fromBuffer = (0, valgen_1.validator)((input) => {
|
|
39
44
|
if (Buffer.isBuffer(input))
|
|
40
45
|
return input.toString('base64');
|
|
@@ -11,7 +11,7 @@ let FieldPathType = class FieldPathType {
|
|
|
11
11
|
if (attributes)
|
|
12
12
|
Object.assign(this, attributes);
|
|
13
13
|
}
|
|
14
|
-
[constants_js_1.DECODER](properties, element, scope) {
|
|
14
|
+
[constants_js_1.DECODER](properties, { element, scope, }) {
|
|
15
15
|
const dataType = properties.dataType
|
|
16
16
|
? element.node.getComplexType(properties.dataType)
|
|
17
17
|
: element.node.getComplexType('object');
|
|
@@ -19,8 +19,8 @@ let FieldPathType = class FieldPathType {
|
|
|
19
19
|
const decodeFieldPath = (0, valgen_1.validator)('decodeFieldPath', (input) => dataType.normalizeFieldPath(input, { allowSigns, scope }));
|
|
20
20
|
return valgen_1.vg.pipe([valgen_1.toString, decodeFieldPath]);
|
|
21
21
|
}
|
|
22
|
-
[constants_js_1.ENCODER](properties,
|
|
23
|
-
return this[constants_js_1.DECODER](properties,
|
|
22
|
+
[constants_js_1.ENCODER](properties, args) {
|
|
23
|
+
return this[constants_js_1.DECODER](properties, args);
|
|
24
24
|
}
|
|
25
25
|
toJSON(properties, element, options) {
|
|
26
26
|
const dataType = properties.dataType
|
|
@@ -13,7 +13,7 @@ let FilterType = class FilterType {
|
|
|
13
13
|
if (attributes)
|
|
14
14
|
Object.assign(this, attributes);
|
|
15
15
|
}
|
|
16
|
-
[constants_js_1.DECODER](properties, element) {
|
|
16
|
+
[constants_js_1.DECODER](properties, { element }) {
|
|
17
17
|
const dataType = properties.dataType
|
|
18
18
|
? element.node.getComplexType(properties.dataType)
|
|
19
19
|
: element.node.getComplexType('object');
|
|
@@ -74,7 +74,11 @@ class SimpleTypeClass extends data_type_js_1.DataType {
|
|
|
74
74
|
let t = this;
|
|
75
75
|
while (t) {
|
|
76
76
|
if (t._generateDecoder)
|
|
77
|
-
return t._generateDecoder(prop,
|
|
77
|
+
return t._generateDecoder(prop, {
|
|
78
|
+
dataType: this,
|
|
79
|
+
element: options?.documentElement || this.owner,
|
|
80
|
+
scope: options?.scope,
|
|
81
|
+
});
|
|
78
82
|
t = this.base;
|
|
79
83
|
}
|
|
80
84
|
return valgen_1.isAny;
|
|
@@ -82,7 +86,11 @@ class SimpleTypeClass extends data_type_js_1.DataType {
|
|
|
82
86
|
let t = this;
|
|
83
87
|
while (t) {
|
|
84
88
|
if (t._generateEncoder)
|
|
85
|
-
return t._generateEncoder(prop,
|
|
89
|
+
return t._generateEncoder(prop, {
|
|
90
|
+
dataType: this,
|
|
91
|
+
element: options?.documentElement || this.owner,
|
|
92
|
+
scope: options?.scope,
|
|
93
|
+
});
|
|
86
94
|
t = this.base;
|
|
87
95
|
}
|
|
88
96
|
return valgen_1.isAny;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HttpOperationDecoratorFactory = HttpOperationDecoratorFactory;
|
|
4
|
+
const objects_1 = require("@jsopen/objects");
|
|
4
5
|
const index_js_1 = require("../../enums/index.js");
|
|
5
6
|
const index_js_2 = require("../../schema/index.js");
|
|
6
7
|
const constants_js_1 = require("../constants.js");
|
|
@@ -34,6 +35,8 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
|
|
|
34
35
|
type: arg1,
|
|
35
36
|
}
|
|
36
37
|
: { ...arg1, name, location: 'cookie' };
|
|
38
|
+
if ((0, objects_1.isConstructor)(paramMeta.type))
|
|
39
|
+
paramMeta.designType = paramMeta.type;
|
|
37
40
|
if (meta.parameters) {
|
|
38
41
|
meta.parameters = meta.parameters.filter(p => !(p.location === 'cookie' && String(p.name) === String(name)));
|
|
39
42
|
}
|
|
@@ -55,6 +58,8 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
|
|
|
55
58
|
type: arg1,
|
|
56
59
|
}
|
|
57
60
|
: { ...arg1, name, location: 'header' };
|
|
61
|
+
if ((0, objects_1.isConstructor)(paramMeta.type))
|
|
62
|
+
paramMeta.designType = paramMeta.type;
|
|
58
63
|
if (meta.parameters) {
|
|
59
64
|
meta.parameters = meta.parameters.filter(p => !(p.location === 'header' && String(p.name) === String(name)));
|
|
60
65
|
}
|
|
@@ -76,6 +81,8 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
|
|
|
76
81
|
type: arg1,
|
|
77
82
|
}
|
|
78
83
|
: { ...arg1, name, location: 'query' };
|
|
84
|
+
if ((0, objects_1.isConstructor)(paramMeta.type))
|
|
85
|
+
paramMeta.designType = paramMeta.type;
|
|
79
86
|
if (meta.parameters) {
|
|
80
87
|
meta.parameters = meta.parameters.filter(p => !(p.location === 'query' && String(p.name) === String(name)));
|
|
81
88
|
}
|
|
@@ -97,6 +104,8 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
|
|
|
97
104
|
type: arg1,
|
|
98
105
|
}
|
|
99
106
|
: { ...arg1, name, location: 'path' };
|
|
107
|
+
if ((0, objects_1.isConstructor)(paramMeta.type))
|
|
108
|
+
paramMeta.designType = paramMeta.type;
|
|
100
109
|
if (meta.parameters) {
|
|
101
110
|
meta.parameters = meta.parameters.filter(p => !(p.location === 'path' && String(p.name) === String(name)));
|
|
102
111
|
}
|
|
@@ -122,6 +131,8 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
|
|
|
122
131
|
if (responseMeta.contentType === index_js_1.MimeTypes.opra_response_json) {
|
|
123
132
|
responseMeta.contentEncoding = responseMeta.contentEncoding || 'utf-8';
|
|
124
133
|
}
|
|
134
|
+
if ((0, objects_1.isConstructor)(responseMeta.type))
|
|
135
|
+
responseMeta.designType = responseMeta.type;
|
|
125
136
|
decoratorChain.push((meta) => {
|
|
126
137
|
meta.responses = meta.responses || [];
|
|
127
138
|
meta.responses.push(responseMeta);
|
|
@@ -133,6 +144,8 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
|
|
|
133
144
|
if (contentMeta.type) {
|
|
134
145
|
contentMeta.contentType = contentMeta.contentType || index_js_1.MimeTypes.json;
|
|
135
146
|
contentMeta.contentEncoding = contentMeta.contentEncoding || 'utf-8';
|
|
147
|
+
if ((0, objects_1.isConstructor)(contentMeta.type))
|
|
148
|
+
contentMeta.designType = contentMeta.type;
|
|
136
149
|
}
|
|
137
150
|
decoratorChain.push((operationMetadata) => {
|
|
138
151
|
operationMetadata.requestBody = operationMetadata.requestBody || {
|
|
@@ -5,7 +5,7 @@ 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 MQOperationDecoratorFactory(decoratorChain,
|
|
8
|
+
function MQOperationDecoratorFactory(decoratorChain, type, options) {
|
|
9
9
|
let inResponse = false;
|
|
10
10
|
/**
|
|
11
11
|
*
|
|
@@ -16,8 +16,8 @@ function MQOperationDecoratorFactory(decoratorChain, payloadType, options) {
|
|
|
16
16
|
const operationMetadata = {
|
|
17
17
|
kind: index_js_1.OpraSchema.MQOperation.Kind,
|
|
18
18
|
channel: propertyKey,
|
|
19
|
-
|
|
20
|
-
...(0, objects_1.omit)(options, ['kind', '
|
|
19
|
+
type,
|
|
20
|
+
...(0, objects_1.omit)(options, ['kind', 'type']),
|
|
21
21
|
};
|
|
22
22
|
const controllerMetadata = (Reflect.getOwnMetadata(constants_js_1.MQ_CONTROLLER_METADATA, target.constructor) || {});
|
|
23
23
|
controllerMetadata.operations = controllerMetadata.operations || {};
|
|
@@ -29,10 +29,10 @@ function MQOperationDecoratorFactory(decoratorChain, payloadType, options) {
|
|
|
29
29
|
/**
|
|
30
30
|
*
|
|
31
31
|
*/
|
|
32
|
-
decorator.UseType = (...
|
|
32
|
+
decorator.UseType = (...types) => {
|
|
33
33
|
decoratorChain.push((meta) => {
|
|
34
34
|
meta.types = meta.types || [];
|
|
35
|
-
meta.types.push(...
|
|
35
|
+
meta.types.push(...types);
|
|
36
36
|
});
|
|
37
37
|
return decorator;
|
|
38
38
|
};
|
|
@@ -47,6 +47,8 @@ function MQOperationDecoratorFactory(decoratorChain, payloadType, options) {
|
|
|
47
47
|
type: arg1,
|
|
48
48
|
}
|
|
49
49
|
: { ...arg1, name };
|
|
50
|
+
if ((0, objects_1.isConstructor)(headerMetadata.type))
|
|
51
|
+
headerMetadata.designType = headerMetadata.type;
|
|
50
52
|
const subMeta = inResponse ? meta.response : meta;
|
|
51
53
|
if (subMeta.headers) {
|
|
52
54
|
subMeta.headers = subMeta.headers.filter(p => String(p.name) !== String(name));
|
|
@@ -60,17 +62,19 @@ function MQOperationDecoratorFactory(decoratorChain, payloadType, options) {
|
|
|
60
62
|
/**
|
|
61
63
|
*
|
|
62
64
|
*/
|
|
63
|
-
decorator.Response = (
|
|
65
|
+
decorator.Response = (_type, _options) => {
|
|
64
66
|
decoratorChain.push((meta) => {
|
|
65
67
|
inResponse = true;
|
|
66
68
|
meta.response = {
|
|
67
69
|
..._options,
|
|
68
|
-
|
|
70
|
+
type: _type,
|
|
69
71
|
};
|
|
72
|
+
if ((0, objects_1.isConstructor)(_type))
|
|
73
|
+
meta.response.designType = _type;
|
|
70
74
|
});
|
|
71
75
|
return decorator;
|
|
72
76
|
};
|
|
73
|
-
augmentationRegistry.forEach(fn => fn(decorator, decoratorChain,
|
|
77
|
+
augmentationRegistry.forEach(fn => fn(decorator, decoratorChain, type, options));
|
|
74
78
|
return decorator;
|
|
75
79
|
}
|
|
76
80
|
MQOperationDecoratorFactory.augment = function (fn) {
|
|
@@ -16,10 +16,10 @@ function WSControllerDecoratorFactory(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.WS_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.WS_CONTROLLER_METADATA, target);
|
|
23
23
|
if (oldMetadata)
|
|
24
24
|
(0, objects_1.merge)(metadata, oldMetadata, { deep: true });
|
|
25
25
|
(0, objects_1.merge)(metadata, {
|
|
@@ -28,10 +28,10 @@ function WSControllerDecoratorFactory(options) {
|
|
|
28
28
|
name,
|
|
29
29
|
path: name,
|
|
30
30
|
}, { deep: true });
|
|
31
|
-
Reflect.defineMetadata(constants_js_1.
|
|
31
|
+
Reflect.defineMetadata(constants_js_1.WS_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.WS_CONTROLLER_METADATA, metadata, target);
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
37
37
|
*
|
|
@@ -5,7 +5,7 @@ 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 WSOperationDecoratorFactory(decoratorChain,
|
|
8
|
+
function WSOperationDecoratorFactory(decoratorChain, options) {
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
11
11
|
*/
|
|
@@ -14,16 +14,15 @@ function WSOperationDecoratorFactory(decoratorChain, payloadType, options) {
|
|
|
14
14
|
throw new TypeError(`Symbol properties can not be decorated`);
|
|
15
15
|
const operationMetadata = {
|
|
16
16
|
kind: index_js_1.OpraSchema.WSOperation.Kind,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
...(0, objects_1.omit)(options, ['kind', 'payloadType']),
|
|
17
|
+
event: propertyKey,
|
|
18
|
+
...(0, objects_1.omit)(options, ['kind']),
|
|
20
19
|
};
|
|
21
|
-
const controllerMetadata = (Reflect.getOwnMetadata(constants_js_1.
|
|
20
|
+
const controllerMetadata = (Reflect.getOwnMetadata(constants_js_1.WS_CONTROLLER_METADATA, target.constructor) || {});
|
|
22
21
|
controllerMetadata.operations = controllerMetadata.operations || {};
|
|
23
22
|
controllerMetadata.operations[propertyKey] = operationMetadata;
|
|
24
23
|
for (const fn of decoratorChain)
|
|
25
24
|
fn(operationMetadata, target, propertyKey);
|
|
26
|
-
Reflect.defineMetadata(constants_js_1.
|
|
25
|
+
Reflect.defineMetadata(constants_js_1.WS_CONTROLLER_METADATA, controllerMetadata, target.constructor);
|
|
27
26
|
});
|
|
28
27
|
/**
|
|
29
28
|
*
|
|
@@ -35,7 +34,7 @@ function WSOperationDecoratorFactory(decoratorChain, payloadType, options) {
|
|
|
35
34
|
});
|
|
36
35
|
return decorator;
|
|
37
36
|
};
|
|
38
|
-
augmentationRegistry.forEach(fn => fn(decorator, decoratorChain,
|
|
37
|
+
augmentationRegistry.forEach(fn => fn(decorator, decoratorChain, options));
|
|
39
38
|
return decorator;
|
|
40
39
|
}
|
|
41
40
|
WSOperationDecoratorFactory.augment = function (fn) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WsParam = WsParam;
|
|
4
|
+
const constants_js_1 = require("../constants.js");
|
|
5
|
+
function WsParam(type) {
|
|
6
|
+
return (target, propertyKey, parameterIndex) => {
|
|
7
|
+
if (typeof propertyKey !== 'string')
|
|
8
|
+
throw new TypeError(`Un-named properties can not be decorated`);
|
|
9
|
+
if (!type) {
|
|
10
|
+
const designTypes = Reflect.getMetadata('design:paramtypes', target, propertyKey);
|
|
11
|
+
type = designTypes[parameterIndex];
|
|
12
|
+
if (!type)
|
|
13
|
+
throw new TypeError(`Missing parameter type`);
|
|
14
|
+
}
|
|
15
|
+
let paramMetadata = Reflect.getOwnMetadata(constants_js_1.WS_PARAM_METADATA, target, propertyKey);
|
|
16
|
+
if (!paramMetadata) {
|
|
17
|
+
paramMetadata = [];
|
|
18
|
+
Reflect.defineMetadata(constants_js_1.WS_PARAM_METADATA, paramMetadata, target, propertyKey);
|
|
19
|
+
}
|
|
20
|
+
paramMetadata[parameterIndex] = type;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -13,6 +13,7 @@ const primitiveTypes = tslib_1.__importStar(require("../data-type/primitive-type
|
|
|
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
15
|
const mq_api_factory_js_1 = require("./mq-api.factory.js");
|
|
16
|
+
const ws_api_factory_js_1 = require("./ws-api.factory.js");
|
|
16
17
|
const OPRA_SPEC_URL = 'https://oprajs.com/spec/v' + index_js_2.OpraSchema.SpecVersion;
|
|
17
18
|
/**
|
|
18
19
|
* @class ApiDocumentFactory
|
|
@@ -131,6 +132,14 @@ class ApiDocumentFactory {
|
|
|
131
132
|
if (api)
|
|
132
133
|
document.api = api;
|
|
133
134
|
}
|
|
135
|
+
else if (init.api && init.api.transport === 'ws') {
|
|
136
|
+
const api = await ws_api_factory_js_1.WSApiFactory.createApi(context, {
|
|
137
|
+
...init.api,
|
|
138
|
+
owner: document,
|
|
139
|
+
});
|
|
140
|
+
if (api)
|
|
141
|
+
document.api = api;
|
|
142
|
+
}
|
|
134
143
|
else
|
|
135
144
|
context.addError(`Unknown service transport (${init.api.transport})`);
|
|
136
145
|
});
|
|
@@ -5,6 +5,7 @@ const index_js_1 = require("../../helpers/index.js");
|
|
|
5
5
|
const index_js_2 = require("../../schema/index.js");
|
|
6
6
|
const document_init_context_js_1 = require("../common/document-init-context.js");
|
|
7
7
|
const constants_js_1 = require("../constants.js");
|
|
8
|
+
const array_type_js_1 = require("../data-type/array-type.js");
|
|
8
9
|
const complex_type_js_1 = require("../data-type/complex-type.js");
|
|
9
10
|
const complex_type_base_js_1 = require("../data-type/complex-type-base.js");
|
|
10
11
|
const data_type_js_1 = require("../data-type/data-type.js");
|
|
@@ -251,6 +252,9 @@ class DataTypeFactory {
|
|
|
251
252
|
}
|
|
252
253
|
}
|
|
253
254
|
switch (out.kind) {
|
|
255
|
+
case index_js_2.OpraSchema.ArrayType.Kind:
|
|
256
|
+
await this._prepareArrayTypeArgs(context, owner, out, metadata);
|
|
257
|
+
break;
|
|
254
258
|
case index_js_2.OpraSchema.ComplexType.Kind:
|
|
255
259
|
out.ctor = ctor;
|
|
256
260
|
await this._prepareComplexTypeArgs(context, owner, out, metadata);
|
|
@@ -291,6 +295,15 @@ class DataTypeFactory {
|
|
|
291
295
|
initArgs.examples = metadata.examples;
|
|
292
296
|
initArgs.scopePattern = metadata.scopePattern;
|
|
293
297
|
}
|
|
298
|
+
static async _prepareArrayTypeArgs(context, owner, initArgs, metadata) {
|
|
299
|
+
await this._prepareDataTypeArgs(context, initArgs, metadata);
|
|
300
|
+
await context.enterAsync('.type', async () => {
|
|
301
|
+
const baseArgs = await this._importDataTypeArgs(context, owner, metadata.type);
|
|
302
|
+
if (!baseArgs)
|
|
303
|
+
return;
|
|
304
|
+
initArgs.type = preferName(baseArgs);
|
|
305
|
+
});
|
|
306
|
+
}
|
|
294
307
|
static async _prepareComplexTypeArgs(context, owner, initArgs, metadata) {
|
|
295
308
|
await this._prepareDataTypeArgs(context, initArgs, metadata);
|
|
296
309
|
initArgs.keyField = metadata.keyField;
|
|
@@ -471,6 +484,8 @@ class DataTypeFactory {
|
|
|
471
484
|
dataTypeMap.set(dataType.name, dataType);
|
|
472
485
|
}
|
|
473
486
|
switch (initArgs?.kind) {
|
|
487
|
+
case index_js_2.OpraSchema.ArrayType.Kind:
|
|
488
|
+
return this._createArrayType(context, owner, initArgs);
|
|
474
489
|
case index_js_2.OpraSchema.ComplexType.Kind:
|
|
475
490
|
return this._createComplexType(context, owner, initArgs);
|
|
476
491
|
case index_js_2.OpraSchema.EnumType.Kind:
|
|
@@ -489,6 +504,18 @@ class DataTypeFactory {
|
|
|
489
504
|
}
|
|
490
505
|
context.addError(`Unknown data type (${String(args)})`);
|
|
491
506
|
}
|
|
507
|
+
static _createArrayType(context, owner, args) {
|
|
508
|
+
const dataType = args._instance || {};
|
|
509
|
+
Object.setPrototypeOf(dataType, array_type_js_1.ArrayType.prototype);
|
|
510
|
+
const initArgs = (0, index_js_1.cloneObject)(args);
|
|
511
|
+
if (args.type) {
|
|
512
|
+
context.enter('.type', () => {
|
|
513
|
+
initArgs.type = this._createDataType(context, owner, args.type);
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
array_type_js_1.ArrayType.apply(dataType, [owner, initArgs]);
|
|
517
|
+
return dataType;
|
|
518
|
+
}
|
|
492
519
|
static _createComplexType(context, owner, args) {
|
|
493
520
|
const dataType = args._instance || {};
|
|
494
521
|
Object.setPrototypeOf(dataType, complex_type_js_1.ComplexType.prototype);
|
|
@@ -116,7 +116,7 @@ class MQApiFactory {
|
|
|
116
116
|
...operationMeta,
|
|
117
117
|
name: operationName,
|
|
118
118
|
types: undefined,
|
|
119
|
-
|
|
119
|
+
type: undefined,
|
|
120
120
|
keyType: undefined,
|
|
121
121
|
});
|
|
122
122
|
await this._initMQOperation(context, operation, operationMeta);
|
|
@@ -140,7 +140,7 @@ class MQApiFactory {
|
|
|
140
140
|
await data_type_factory_js_1.DataTypeFactory.addDataTypes(context, operation, metadata.types);
|
|
141
141
|
});
|
|
142
142
|
}
|
|
143
|
-
operation.
|
|
143
|
+
operation.type = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, operation, metadata.type);
|
|
144
144
|
if (metadata.keyType) {
|
|
145
145
|
operation.keyType = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, operation, metadata.keyType);
|
|
146
146
|
}
|
|
@@ -163,7 +163,7 @@ class MQApiFactory {
|
|
|
163
163
|
await context.enterAsync('.response', async () => {
|
|
164
164
|
const response = new mq_operation_response_js_1.MQOperationResponse(operation, {
|
|
165
165
|
...metadata.response,
|
|
166
|
-
|
|
166
|
+
type: undefined,
|
|
167
167
|
keyType: undefined,
|
|
168
168
|
});
|
|
169
169
|
await this._initMQOperationResponse(context, response, metadata.response);
|
|
@@ -179,7 +179,7 @@ class MQApiFactory {
|
|
|
179
179
|
* @protected
|
|
180
180
|
*/
|
|
181
181
|
static async _initMQOperationResponse(context, response, metadata) {
|
|
182
|
-
response.
|
|
182
|
+
response.type = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, response, metadata.type);
|
|
183
183
|
if (metadata.keyType) {
|
|
184
184
|
response.keyType = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, response, metadata.keyType);
|
|
185
185
|
}
|