@opra/common 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/index.cjs +1 -1
- package/browser/index.mjs +1 -1
- package/cjs/document/api-document.js +3 -1
- package/cjs/document/common/api-base.js +2 -1
- package/cjs/document/common/data-type-map.js +14 -3
- package/cjs/document/common/value.js +3 -1
- package/cjs/document/data-type/api-field.js +3 -1
- package/cjs/document/data-type/complex-type-base.js +12 -4
- package/cjs/document/data-type/complex-type.js +6 -2
- package/cjs/document/data-type/enum-type.js +3 -1
- package/cjs/document/data-type/extended-types/date-time.type.js +5 -1
- package/cjs/document/data-type/extended-types/date.type.js +5 -1
- package/cjs/document/data-type/extended-types/field-path.type.js +3 -1
- package/cjs/document/data-type/extended-types/filter.type.js +3 -1
- package/cjs/document/data-type/mapped-type.js +15 -6
- package/cjs/document/data-type/mixin-type.js +3 -1
- package/cjs/document/data-type/primitive-types/bigint.type.js +3 -1
- package/cjs/document/data-type/primitive-types/integer.type.js +3 -1
- package/cjs/document/data-type/primitive-types/number.type.js +3 -1
- package/cjs/document/data-type/primitive-types/string.type.js +3 -1
- package/cjs/document/data-type/simple-type.js +7 -2
- package/cjs/document/data-type/utils/create-mapped-class.js +3 -1
- package/cjs/document/decorators/api-field-decorator.js +2 -1
- package/cjs/document/decorators/http-controller.decorator.js +7 -1
- package/cjs/document/decorators/http-operation-entity.decorator.js +20 -10
- package/cjs/document/decorators/http-operation.decorator.js +23 -10
- package/cjs/document/decorators/rpc-operation.decorator.js +1 -2
- package/cjs/document/decorators/simple-type.decorator.js +2 -1
- package/cjs/document/factory/api-document.factory.js +11 -3
- package/cjs/document/factory/data-type.factory.js +19 -7
- package/cjs/document/factory/http-api.factory.js +13 -4
- package/cjs/document/http/http-controller.js +2 -1
- package/cjs/document/http/http-media-type.js +15 -5
- package/cjs/document/http/http-operation-response.js +8 -3
- package/cjs/document/http/http-operation.js +3 -1
- package/cjs/document/http/http-status-range.js +3 -1
- package/cjs/document/rpc/rpc-operation-response.js +11 -3
- package/cjs/document/rpc/rpc-operation.js +11 -3
- package/cjs/document/utils/parse-regexp.util.js +2 -2
- package/cjs/exception/opra-exception.js +3 -1
- package/cjs/filter/antlr/OpraFilterLexer.js +190 -123
- package/cjs/filter/antlr/OpraFilterParser.js +53 -35
- package/cjs/filter/ast/expressions/arithmetic-expression.js +3 -1
- package/cjs/filter/ast/terms/number-literal.js +3 -1
- package/cjs/filter/filter-rules.js +13 -4
- package/cjs/filter/filter-tree-visitor.js +2 -1
- package/cjs/filter/opra-error-listener.js +7 -1
- package/cjs/filter/parse.js +3 -1
- package/cjs/filter/utils.js +3 -1
- package/cjs/helpers/get-stack-filename.js +6 -2
- package/cjs/helpers/mixin-utils.js +7 -2
- package/cjs/helpers/object-utils.js +3 -1
- package/cjs/helpers/parse-fields-projection.js +4 -2
- package/cjs/helpers/type-guards.js +7 -2
- package/cjs/i18n/i18n.js +13 -3
- package/cjs/i18n/translate.js +3 -1
- package/cjs/polifils/array-find-last.js +0 -2
- package/esm/document/api-document.js +4 -2
- package/esm/document/common/api-base.js +2 -1
- package/esm/document/common/data-type-map.js +14 -3
- package/esm/document/common/value.js +3 -1
- package/esm/document/data-type/api-field.js +3 -1
- package/esm/document/data-type/complex-type-base.js +13 -5
- package/esm/document/data-type/complex-type.js +6 -2
- package/esm/document/data-type/data-type.js +1 -1
- package/esm/document/data-type/enum-type.js +3 -1
- package/esm/document/data-type/extended-types/date-time.type.js +5 -1
- package/esm/document/data-type/extended-types/date.type.js +5 -1
- package/esm/document/data-type/extended-types/field-path.type.js +3 -1
- package/esm/document/data-type/extended-types/filter.type.js +3 -1
- package/esm/document/data-type/mapped-type.js +15 -6
- package/esm/document/data-type/mixin-type.js +4 -2
- package/esm/document/data-type/primitive-types/bigint.type.js +3 -1
- package/esm/document/data-type/primitive-types/integer.type.js +3 -1
- package/esm/document/data-type/primitive-types/number.type.js +3 -1
- package/esm/document/data-type/primitive-types/string.type.js +3 -1
- package/esm/document/data-type/simple-type.js +8 -3
- package/esm/document/data-type/utils/create-mapped-class.js +4 -2
- package/esm/document/decorators/api-field-decorator.js +2 -1
- package/esm/document/decorators/complex-type.decorator.js +1 -1
- package/esm/document/decorators/http-controller.decorator.js +7 -1
- package/esm/document/decorators/http-operation-entity.decorator.js +22 -12
- package/esm/document/decorators/http-operation.decorator.js +23 -10
- package/esm/document/decorators/rpc-operation.decorator.js +1 -2
- package/esm/document/decorators/simple-type.decorator.js +3 -2
- package/esm/document/factory/api-document.factory.js +11 -3
- package/esm/document/factory/data-type.factory.js +21 -9
- package/esm/document/factory/http-api.factory.js +13 -4
- package/esm/document/http/http-controller.js +3 -2
- package/esm/document/http/http-media-type.js +15 -5
- package/esm/document/http/http-operation-response.js +8 -3
- package/esm/document/http/http-operation.js +4 -2
- package/esm/document/http/http-parameter.js +1 -1
- package/esm/document/http/http-status-range.js +3 -1
- package/esm/document/rpc/rpc-controller.js +1 -1
- package/esm/document/rpc/rpc-header.js +1 -1
- package/esm/document/rpc/rpc-operation-response.js +11 -3
- package/esm/document/rpc/rpc-operation.js +12 -4
- package/esm/document/utils/parse-regexp.util.js +2 -2
- package/esm/exception/opra-exception.js +3 -1
- package/esm/filter/antlr/OpraFilterLexer.js +190 -123
- package/esm/filter/antlr/OpraFilterParser.js +53 -35
- package/esm/filter/ast/expressions/arithmetic-expression.js +3 -1
- package/esm/filter/ast/terms/number-literal.js +3 -1
- package/esm/filter/filter-rules.js +13 -4
- package/esm/filter/filter-tree-visitor.js +2 -1
- package/esm/filter/opra-error-listener.js +8 -2
- package/esm/filter/parse.js +3 -1
- package/esm/filter/utils.js +3 -1
- package/esm/helpers/get-stack-filename.js +6 -2
- package/esm/helpers/mixin-utils.js +7 -2
- package/esm/helpers/object-utils.js +3 -1
- package/esm/helpers/parse-fields-projection.js +4 -2
- package/esm/helpers/type-guards.js +7 -2
- package/esm/i18n/i18n.js +13 -3
- package/esm/i18n/translate.js +3 -1
- package/esm/polifils/array-find-last.js +0 -2
- package/package.json +1 -1
|
@@ -32,7 +32,9 @@ class ApiDocument extends document_element_js_1.DocumentElement {
|
|
|
32
32
|
* @param nameOrCtor
|
|
33
33
|
*/
|
|
34
34
|
getDataTypeNs(nameOrCtor) {
|
|
35
|
-
const dt = nameOrCtor instanceof data_type_js_1.DataType
|
|
35
|
+
const dt = nameOrCtor instanceof data_type_js_1.DataType
|
|
36
|
+
? this._findDataType(nameOrCtor.name || '')
|
|
37
|
+
: this._findDataType(nameOrCtor);
|
|
36
38
|
if (dt)
|
|
37
39
|
return this[constants_js_1.kTypeNSMap].get(dt);
|
|
38
40
|
}
|
|
@@ -18,8 +18,9 @@ class ApiBase extends document_element_js_1.DocumentElement {
|
|
|
18
18
|
description: this.description,
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
+
async _initialize(init,
|
|
21
22
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
22
|
-
|
|
23
|
+
context) {
|
|
23
24
|
if (!constants_js_1.CLASS_NAME_PATTERN.test(init.name))
|
|
24
25
|
throw new TypeError(`Invalid api name (${init.name})`);
|
|
25
26
|
this.name = init.name;
|
|
@@ -22,7 +22,9 @@ class DataTypeMap {
|
|
|
22
22
|
this[kMap].forEach(callbackFn, thisArg);
|
|
23
23
|
}
|
|
24
24
|
get(nameOrCtor) {
|
|
25
|
-
let name = typeof nameOrCtor === 'string'
|
|
25
|
+
let name = typeof nameOrCtor === 'string'
|
|
26
|
+
? nameOrCtor
|
|
27
|
+
: this[kCtorMap].get(nameOrCtor);
|
|
26
28
|
if (!name && typeof nameOrCtor === 'function') {
|
|
27
29
|
const metadata = Reflect.getMetadata(constants_js_1.DATATYPE_METADATA, nameOrCtor);
|
|
28
30
|
name = metadata?.name;
|
|
@@ -31,7 +33,14 @@ class DataTypeMap {
|
|
|
31
33
|
const metadata = nameOrCtor[constants_js_1.DATATYPE_METADATA];
|
|
32
34
|
name = metadata?.name;
|
|
33
35
|
}
|
|
34
|
-
|
|
36
|
+
if (!name)
|
|
37
|
+
return;
|
|
38
|
+
const out = this[kMap].get(name);
|
|
39
|
+
if (!out)
|
|
40
|
+
return;
|
|
41
|
+
if (typeof nameOrCtor === 'function' && out.kind === 'ComplexType')
|
|
42
|
+
return out.ctor === nameOrCtor ? out : undefined;
|
|
43
|
+
return out;
|
|
35
44
|
}
|
|
36
45
|
set(name, dataType) {
|
|
37
46
|
this[kMap].set(name, dataType);
|
|
@@ -43,7 +52,9 @@ class DataTypeMap {
|
|
|
43
52
|
has(nameOrCtor) {
|
|
44
53
|
if (nameOrCtor instanceof data_type_js_1.DataType)
|
|
45
54
|
return !!nameOrCtor.name && this[kMap].has(nameOrCtor.name);
|
|
46
|
-
const name = typeof nameOrCtor === 'string'
|
|
55
|
+
const name = typeof nameOrCtor === 'string'
|
|
56
|
+
? nameOrCtor
|
|
57
|
+
: this[kCtorMap].get(nameOrCtor);
|
|
47
58
|
return name ? this[kMap].has(name) : false;
|
|
48
59
|
}
|
|
49
60
|
keys() {
|
|
@@ -21,7 +21,9 @@ exports.Value = function (owner, initArgs) {
|
|
|
21
21
|
*/
|
|
22
22
|
class ValueClass extends document_element_js_1.DocumentElement {
|
|
23
23
|
toJSON() {
|
|
24
|
-
const typeName = this.type
|
|
24
|
+
const typeName = this.type
|
|
25
|
+
? this.node.getDataTypeNameWithNs(this.type)
|
|
26
|
+
: undefined;
|
|
25
27
|
return (0, objects_1.omitUndefined)({
|
|
26
28
|
type: this.type ? (typeName ? typeName : this.type.toJSON()) : 'any',
|
|
27
29
|
description: this.description,
|
|
@@ -49,7 +49,9 @@ exports.ApiField = function (...args) {
|
|
|
49
49
|
*/
|
|
50
50
|
class ApiFieldClass extends document_element_js_1.DocumentElement {
|
|
51
51
|
toJSON() {
|
|
52
|
-
const typeName = this.type
|
|
52
|
+
const typeName = this.type
|
|
53
|
+
? this.node.getDataTypeNameWithNs(this.type)
|
|
54
|
+
: undefined;
|
|
53
55
|
return (0, objects_1.omitUndefined)({
|
|
54
56
|
type: typeName ? typeName : this.type?.toJSON(),
|
|
55
57
|
description: this.description,
|
|
@@ -86,7 +86,8 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
|
|
|
86
86
|
dataType = undefined;
|
|
87
87
|
continue;
|
|
88
88
|
}
|
|
89
|
-
if (dataType.additionalFields?.[0] === 'type' &&
|
|
89
|
+
if (dataType.additionalFields?.[0] === 'type' &&
|
|
90
|
+
dataType.additionalFields?.[1] instanceof data_type_js_1.DataType) {
|
|
90
91
|
item.additionalField = true;
|
|
91
92
|
item.dataType = dataType.additionalFields[1];
|
|
92
93
|
dataType = dataType.additionalFields[1];
|
|
@@ -116,7 +117,11 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
|
|
|
116
117
|
const projection = Array.isArray(options?.projection)
|
|
117
118
|
? (0, index_js_1.parseFieldsProjection)(options.projection)
|
|
118
119
|
: options?.projection;
|
|
119
|
-
const schema = this._generateSchema(codec, {
|
|
120
|
+
const schema = this._generateSchema(codec, {
|
|
121
|
+
...options,
|
|
122
|
+
projection,
|
|
123
|
+
currentPath: '',
|
|
124
|
+
});
|
|
120
125
|
let additionalFields;
|
|
121
126
|
if (this.additionalFields instanceof data_type_js_1.DataType) {
|
|
122
127
|
additionalFields = this.additionalFields.generateCodec(codec, options);
|
|
@@ -171,10 +176,13 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
|
|
|
171
176
|
const fn = this._generateFieldCodec(codec, field, {
|
|
172
177
|
...context,
|
|
173
178
|
partial: context.partial === 'deep' ? context.partial : undefined,
|
|
174
|
-
projection: typeof projection === 'object'
|
|
179
|
+
projection: typeof projection === 'object'
|
|
180
|
+
? projection[fieldName]?.projection || '*'
|
|
181
|
+
: projection,
|
|
175
182
|
currentPath: currentPath + (currentPath ? '.' : '') + fieldName,
|
|
176
183
|
});
|
|
177
|
-
schema[fieldName] =
|
|
184
|
+
schema[fieldName] =
|
|
185
|
+
context.partial || !field.required ? valgen_1.vg.optional(fn) : valgen_1.vg.required(fn);
|
|
178
186
|
}
|
|
179
187
|
if (context.allowPatchOperators) {
|
|
180
188
|
schema._$pull = valgen_1.vg.optional(valgen_1.vg.isAny());
|
|
@@ -72,7 +72,9 @@ class ComplexTypeClass extends complex_type_base_js_1.ComplexTypeBase {
|
|
|
72
72
|
return !!this.base?.extendsFrom(baseType);
|
|
73
73
|
}
|
|
74
74
|
toJSON() {
|
|
75
|
-
const baseName = this.base
|
|
75
|
+
const baseName = this.base
|
|
76
|
+
? this.node.getDataTypeNameWithNs(this.base)
|
|
77
|
+
: undefined;
|
|
76
78
|
const out = (0, objects_1.omitUndefined)({
|
|
77
79
|
...complex_type_base_js_1.ComplexTypeBase.prototype.toJSON.call(this),
|
|
78
80
|
kind: this.kind,
|
|
@@ -81,7 +83,9 @@ class ComplexTypeClass extends complex_type_base_js_1.ComplexTypeBase {
|
|
|
81
83
|
if (this.additionalFields) {
|
|
82
84
|
if (this.additionalFields instanceof data_type_js_1.DataType) {
|
|
83
85
|
const typeName = this.node.getDataTypeNameWithNs(this.additionalFields);
|
|
84
|
-
out.additionalFields = typeName
|
|
86
|
+
out.additionalFields = typeName
|
|
87
|
+
? typeName
|
|
88
|
+
: this.additionalFields.toJSON();
|
|
85
89
|
}
|
|
86
90
|
else
|
|
87
91
|
out.additionalFields = this.additionalFields;
|
|
@@ -52,7 +52,9 @@ class EnumTypeClass extends data_type_js_1.DataType {
|
|
|
52
52
|
return valgen_1.vg.isEnum(Object.keys(this.attributes));
|
|
53
53
|
}
|
|
54
54
|
toJSON() {
|
|
55
|
-
const baseName = this.base
|
|
55
|
+
const baseName = this.base
|
|
56
|
+
? this.node.getDataTypeNameWithNs(this.base)
|
|
57
|
+
: undefined;
|
|
56
58
|
return (0, objects_1.omitUndefined)({
|
|
57
59
|
...data_type_js_1.DataType.prototype.toJSON.call(this),
|
|
58
60
|
base: this.base ? (baseName ? baseName : this.base.toJSON()) : undefined,
|
|
@@ -24,7 +24,11 @@ let DateTimeType = class DateTimeType {
|
|
|
24
24
|
return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
|
|
25
25
|
}
|
|
26
26
|
[constants_js_1.ENCODER](properties) {
|
|
27
|
-
const fn = valgen_1.vg.isDateString({
|
|
27
|
+
const fn = valgen_1.vg.isDateString({
|
|
28
|
+
precision: 'time',
|
|
29
|
+
trim: 'time',
|
|
30
|
+
coerce: true,
|
|
31
|
+
});
|
|
28
32
|
const x = [];
|
|
29
33
|
if (properties.minValue) {
|
|
30
34
|
(0, valgen_1.isDateString)(properties.minValue);
|
|
@@ -24,7 +24,11 @@ let DateType = class DateType {
|
|
|
24
24
|
return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
|
|
25
25
|
}
|
|
26
26
|
[constants_js_1.ENCODER](properties) {
|
|
27
|
-
const fn = valgen_1.vg.isDateString({
|
|
27
|
+
const fn = valgen_1.vg.isDateString({
|
|
28
|
+
precision: 'date',
|
|
29
|
+
trim: 'date',
|
|
30
|
+
coerce: true,
|
|
31
|
+
});
|
|
28
32
|
const x = [];
|
|
29
33
|
if (properties.minValue) {
|
|
30
34
|
(0, valgen_1.isDateString)(properties.minValue);
|
|
@@ -25,7 +25,9 @@ let FieldPathType = class FieldPathType {
|
|
|
25
25
|
const dataType = properties.dataType
|
|
26
26
|
? element.node.getComplexType(properties.dataType)
|
|
27
27
|
: element.node.getComplexType('object');
|
|
28
|
-
const typeName = dataType
|
|
28
|
+
const typeName = dataType
|
|
29
|
+
? element.node.getDataTypeNameWithNs(dataType)
|
|
30
|
+
: undefined;
|
|
29
31
|
return {
|
|
30
32
|
dataType: typeName ? typeName : dataType.toJSON(),
|
|
31
33
|
allowSigns: properties.allowSigns,
|
|
@@ -16,7 +16,9 @@ let FilterType = class FilterType {
|
|
|
16
16
|
const dataType = properties.dataType
|
|
17
17
|
? element.node.getComplexType(properties.dataType)
|
|
18
18
|
: element.node.getComplexType('object');
|
|
19
|
-
const rules = properties.rules
|
|
19
|
+
const rules = properties.rules
|
|
20
|
+
? new filter_rules_js_1.FilterRules(properties.rules)
|
|
21
|
+
: undefined;
|
|
20
22
|
return decodeFilter(dataType, rules);
|
|
21
23
|
}
|
|
22
24
|
[constants_js_1.ENCODER]() {
|
|
@@ -43,16 +43,22 @@ exports.MappedType = function (...args) {
|
|
|
43
43
|
}
|
|
44
44
|
/** Copy fields from base */
|
|
45
45
|
const isInheritedPredicate = (0, get_is_inherited_predicate_fn_js_1.getIsInheritedPredicateFn)(_this.pick, _this.omit);
|
|
46
|
-
const partial = Array.isArray(_this.partial)
|
|
47
|
-
|
|
46
|
+
const partial = Array.isArray(_this.partial)
|
|
47
|
+
? _this.partial.map(x => x.toLowerCase())
|
|
48
|
+
: _this.partial;
|
|
49
|
+
const required = Array.isArray(_this.required)
|
|
50
|
+
? _this.required.map(x => x.toLowerCase())
|
|
51
|
+
: _this.required;
|
|
48
52
|
for (const [k, v] of _this.base.fields.entries()) {
|
|
49
53
|
if (!isInheritedPredicate(k))
|
|
50
54
|
continue;
|
|
51
55
|
const meta = { ...v };
|
|
52
|
-
if (partial === true ||
|
|
56
|
+
if (partial === true ||
|
|
57
|
+
(Array.isArray(partial) && partial.includes(v.name.toLowerCase()))) {
|
|
53
58
|
meta.required = false;
|
|
54
59
|
}
|
|
55
|
-
else if (required === true ||
|
|
60
|
+
else if (required === true ||
|
|
61
|
+
(Array.isArray(required) && required.includes(v.name.toLowerCase()))) {
|
|
56
62
|
meta.required = true;
|
|
57
63
|
}
|
|
58
64
|
const field = new api_field_js_1.ApiField(this, meta);
|
|
@@ -60,7 +66,8 @@ exports.MappedType = function (...args) {
|
|
|
60
66
|
}
|
|
61
67
|
if (!_this.pick ||
|
|
62
68
|
_this.base.additionalFields === false ||
|
|
63
|
-
(Array.isArray(_this.base.additionalFields) &&
|
|
69
|
+
(Array.isArray(_this.base.additionalFields) &&
|
|
70
|
+
_this.base.additionalFields?.[0] === 'error')) {
|
|
64
71
|
_this.additionalFields = _this.base.additionalFields;
|
|
65
72
|
}
|
|
66
73
|
if (initArgs.base.keyField && isInheritedPredicate(initArgs.base.keyField))
|
|
@@ -82,7 +89,9 @@ class MappedTypeClass extends complex_type_base_js_1.ComplexTypeBase {
|
|
|
82
89
|
return !!this.base?.extendsFrom(baseType);
|
|
83
90
|
}
|
|
84
91
|
toJSON() {
|
|
85
|
-
const baseName = this.base
|
|
92
|
+
const baseName = this.base
|
|
93
|
+
? this.node.getDataTypeNameWithNs(this.base)
|
|
94
|
+
: undefined;
|
|
86
95
|
return (0, objects_1.omitUndefined)({
|
|
87
96
|
...complex_type_base_js_1.ComplexTypeBase.prototype.toJSON.call(this),
|
|
88
97
|
base: baseName ? baseName : this.base.toJSON(),
|
|
@@ -76,7 +76,9 @@ exports.MixinType[constants_js_1.DECORATOR] = MixinTypeFactory;
|
|
|
76
76
|
function MixinTypeFactory(...args) {
|
|
77
77
|
// Filter undefined items
|
|
78
78
|
const clasRefs = args.filter(x => typeof x === 'function');
|
|
79
|
-
const options = typeof args[args.length - 1] === 'object'
|
|
79
|
+
const options = typeof args[args.length - 1] === 'object'
|
|
80
|
+
? args[args.length - 1]
|
|
81
|
+
: undefined;
|
|
80
82
|
if (!clasRefs.length)
|
|
81
83
|
throw new TypeError('No Class has been provided');
|
|
82
84
|
if (clasRefs.length === 1)
|
|
@@ -16,7 +16,9 @@ let BigintType = class BigintType extends number_type_js_1.NumberType {
|
|
|
16
16
|
x.push(valgen_1.vg.isGte(properties.minValue));
|
|
17
17
|
if (properties.maxValue)
|
|
18
18
|
x.push(valgen_1.vg.isLte(properties.maxValue));
|
|
19
|
-
return x.length > 0
|
|
19
|
+
return x.length > 0
|
|
20
|
+
? valgen_1.vg.pipe([valgen_1.toBigint, ...x], { returnIndex: 0 })
|
|
21
|
+
: valgen_1.toBigint;
|
|
20
22
|
}
|
|
21
23
|
[constants_js_1.ENCODER](properties) {
|
|
22
24
|
return this[constants_js_1.DECODER](properties);
|
|
@@ -16,7 +16,9 @@ let IntegerType = class IntegerType extends number_type_js_1.NumberType {
|
|
|
16
16
|
x.push(valgen_1.vg.isGte(properties.minValue));
|
|
17
17
|
if (properties.maxValue)
|
|
18
18
|
x.push(valgen_1.vg.isLte(properties.maxValue));
|
|
19
|
-
return x.length > 0
|
|
19
|
+
return x.length > 0
|
|
20
|
+
? valgen_1.vg.pipe([valgen_1.toInteger, ...x], { returnIndex: 0 })
|
|
21
|
+
: valgen_1.toInteger;
|
|
20
22
|
}
|
|
21
23
|
[constants_js_1.ENCODER](properties) {
|
|
22
24
|
return this[constants_js_1.DECODER](properties);
|
|
@@ -16,7 +16,9 @@ let NumberType = class NumberType {
|
|
|
16
16
|
x.push(valgen_1.vg.isGte(properties.minValue));
|
|
17
17
|
if (properties.maxValue)
|
|
18
18
|
x.push(valgen_1.vg.isLte(properties.maxValue));
|
|
19
|
-
return x.length > 0
|
|
19
|
+
return x.length > 0
|
|
20
|
+
? valgen_1.vg.pipe([valgen_1.toNumber, ...x], { returnIndex: 0 })
|
|
21
|
+
: valgen_1.toNumber;
|
|
20
22
|
}
|
|
21
23
|
[constants_js_1.ENCODER](properties) {
|
|
22
24
|
return this[constants_js_1.DECODER](properties);
|
|
@@ -24,7 +24,9 @@ let StringType = class StringType {
|
|
|
24
24
|
x.push(valgen_1.vg.lengthMin(properties.minLength));
|
|
25
25
|
if (properties.maxLength)
|
|
26
26
|
x.push(valgen_1.vg.lengthMax(properties.maxLength));
|
|
27
|
-
return x.length > 0
|
|
27
|
+
return x.length > 0
|
|
28
|
+
? valgen_1.vg.pipe([valgen_1.toString, ...x], { returnIndex: 0 })
|
|
29
|
+
: valgen_1.toString;
|
|
28
30
|
}
|
|
29
31
|
[constants_js_1.ENCODER](properties) {
|
|
30
32
|
return this[constants_js_1.DECODER](properties);
|
|
@@ -31,7 +31,10 @@ exports.SimpleType = function (...args) {
|
|
|
31
31
|
}
|
|
32
32
|
_this.properties = initArgs.properties;
|
|
33
33
|
_this.ownNameMappings = { ...initArgs.nameMappings };
|
|
34
|
-
_this.nameMappings = {
|
|
34
|
+
_this.nameMappings = {
|
|
35
|
+
..._this.base?.nameMappings,
|
|
36
|
+
...initArgs.nameMappings,
|
|
37
|
+
};
|
|
35
38
|
_this.ownAttributes = (0, index_js_1.cloneObject)(initArgs.attributes || {});
|
|
36
39
|
_this.attributes = _this.base ? (0, index_js_1.cloneObject)(_this.base.attributes) : {};
|
|
37
40
|
if (_this.ownAttributes) {
|
|
@@ -88,7 +91,9 @@ class SimpleTypeClass extends data_type_js_1.DataType {
|
|
|
88
91
|
}
|
|
89
92
|
else
|
|
90
93
|
properties = this.properties ? (0, index_js_1.cloneObject)(this.properties) : {};
|
|
91
|
-
const baseName = this.base
|
|
94
|
+
const baseName = this.base
|
|
95
|
+
? this.node.getDataTypeNameWithNs(this.base)
|
|
96
|
+
: undefined;
|
|
92
97
|
const out = (0, objects_1.omitUndefined)({
|
|
93
98
|
...data_type_js_1.DataType.prototype.toJSON.apply(this),
|
|
94
99
|
base: this.base ? (baseName ? baseName : this.base.toJSON()) : undefined,
|
|
@@ -8,7 +8,9 @@ const mapped_type_js_1 = require("../mapped-type.js");
|
|
|
8
8
|
const get_is_inherited_predicate_fn_js_1 = require("./get-is-inherited-predicate-fn.js");
|
|
9
9
|
function createMappedClass(source, config, options) {
|
|
10
10
|
const isInheritedPredicate = (0, get_is_inherited_predicate_fn_js_1.getIsInheritedPredicateFn)(config.pick, config.omit);
|
|
11
|
-
const sourceName = typeof source === 'string'
|
|
11
|
+
const sourceName = typeof source === 'string'
|
|
12
|
+
? source.charAt(0).toUpperCase() + source.substring(1)
|
|
13
|
+
: source.name;
|
|
12
14
|
const className = options?.name || sourceName + 'Mapped';
|
|
13
15
|
const MappedClass = {
|
|
14
16
|
[className]: class {
|
|
@@ -7,7 +7,8 @@ function ApiFieldDecorator(options) {
|
|
|
7
7
|
return function (target, propertyKey) {
|
|
8
8
|
if (typeof propertyKey !== 'string')
|
|
9
9
|
throw new TypeError(`Symbol properties can't be used as a field`);
|
|
10
|
-
const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target.constructor) ||
|
|
10
|
+
const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target.constructor) ||
|
|
11
|
+
{};
|
|
11
12
|
metadata.kind = index_js_1.OpraSchema.ComplexType.Kind;
|
|
12
13
|
metadata.fields = metadata.fields || {};
|
|
13
14
|
const designType = Reflect.getMetadata('design:type', target, propertyKey);
|
|
@@ -25,7 +25,13 @@ function HttpControllerDecoratorFactory(options) {
|
|
|
25
25
|
kind: index_js_1.OpraSchema.HttpController.Kind,
|
|
26
26
|
name,
|
|
27
27
|
path: name,
|
|
28
|
-
...(0, objects_1.omit)(options, [
|
|
28
|
+
...(0, objects_1.omit)(options, [
|
|
29
|
+
'kind',
|
|
30
|
+
'name',
|
|
31
|
+
'instance',
|
|
32
|
+
'endpoints',
|
|
33
|
+
'key',
|
|
34
|
+
]),
|
|
29
35
|
}, { deep: true });
|
|
30
36
|
Reflect.defineMetadata(constants_js_1.HTTP_CONTROLLER_METADATA, metadata, target);
|
|
31
37
|
for (const fn of decoratorChain)
|
|
@@ -53,7 +53,8 @@ http_operation_js_1.HttpOperation.Entity.Create = function (arg0, arg1) {
|
|
|
53
53
|
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
54
54
|
});
|
|
55
55
|
decoratorChain.push((operationMeta) => {
|
|
56
|
-
const compositionOptions = (operationMeta.compositionOptions =
|
|
56
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
57
|
+
operationMeta.compositionOptions || {});
|
|
57
58
|
compositionOptions.type = getDataTypeName(args.type);
|
|
58
59
|
});
|
|
59
60
|
return decorator;
|
|
@@ -110,7 +111,8 @@ http_operation_js_1.HttpOperation.Entity.Delete = function (arg0, arg1) {
|
|
|
110
111
|
return decorator;
|
|
111
112
|
};
|
|
112
113
|
decoratorChain.push((operationMeta) => {
|
|
113
|
-
const compositionOptions = (operationMeta.compositionOptions =
|
|
114
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
115
|
+
operationMeta.compositionOptions || {});
|
|
114
116
|
compositionOptions.type = getDataTypeName(args.type);
|
|
115
117
|
});
|
|
116
118
|
return decorator;
|
|
@@ -149,7 +151,8 @@ http_operation_js_1.HttpOperation.Entity.DeleteMany = function (arg0, arg1) {
|
|
|
149
151
|
description: 'Determines filter fields',
|
|
150
152
|
});
|
|
151
153
|
decoratorChain.push((operationMeta) => {
|
|
152
|
-
const compositionOptions = (operationMeta.compositionOptions =
|
|
154
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
155
|
+
operationMeta.compositionOptions || {});
|
|
153
156
|
compositionOptions.type = getDataTypeName(args.type);
|
|
154
157
|
});
|
|
155
158
|
decorator.Filter = (field, operators, description) => {
|
|
@@ -228,7 +231,8 @@ http_operation_js_1.HttpOperation.Entity.FindMany = function (arg0, arg1) {
|
|
|
228
231
|
arraySeparator: ',',
|
|
229
232
|
});
|
|
230
233
|
decoratorChain.push((operationMeta) => {
|
|
231
|
-
const compositionOptions = (operationMeta.compositionOptions =
|
|
234
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
235
|
+
operationMeta.compositionOptions || {});
|
|
232
236
|
compositionOptions.type = getDataTypeName(args.type);
|
|
233
237
|
if (args.defaultLimit)
|
|
234
238
|
compositionOptions.defaultLimit = args.defaultLimit;
|
|
@@ -239,14 +243,16 @@ http_operation_js_1.HttpOperation.Entity.FindMany = function (arg0, arg1) {
|
|
|
239
243
|
});
|
|
240
244
|
decorator.DefaultSort = (...fields) => {
|
|
241
245
|
decoratorChain.push((operationMeta) => {
|
|
242
|
-
const compositionOptions = (operationMeta.compositionOptions =
|
|
246
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
247
|
+
operationMeta.compositionOptions || {});
|
|
243
248
|
compositionOptions.defaultSort = fields;
|
|
244
249
|
});
|
|
245
250
|
return decorator;
|
|
246
251
|
};
|
|
247
252
|
decorator.SortFields = (...fields) => {
|
|
248
253
|
decoratorChain.push((operationMeta) => {
|
|
249
|
-
const compositionOptions = (operationMeta.compositionOptions =
|
|
254
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
255
|
+
operationMeta.compositionOptions || {});
|
|
250
256
|
compositionOptions.sortFields = fields;
|
|
251
257
|
});
|
|
252
258
|
return decorator;
|
|
@@ -326,7 +332,8 @@ http_operation_js_1.HttpOperation.Entity.Get = function (arg0, arg1) {
|
|
|
326
332
|
return decorator;
|
|
327
333
|
};
|
|
328
334
|
decoratorChain.push((operationMeta) => {
|
|
329
|
-
const compositionOptions = (operationMeta.compositionOptions =
|
|
335
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
336
|
+
operationMeta.compositionOptions || {});
|
|
330
337
|
compositionOptions.type = getDataTypeName(args.type);
|
|
331
338
|
});
|
|
332
339
|
return decorator;
|
|
@@ -397,7 +404,8 @@ http_operation_js_1.HttpOperation.Entity.Replace = function (arg0, arg1) {
|
|
|
397
404
|
return decorator;
|
|
398
405
|
};
|
|
399
406
|
decoratorChain.push((operationMeta) => {
|
|
400
|
-
const compositionOptions = (operationMeta.compositionOptions =
|
|
407
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
408
|
+
operationMeta.compositionOptions || {});
|
|
401
409
|
compositionOptions.type = getDataTypeName(args.type);
|
|
402
410
|
});
|
|
403
411
|
return decorator;
|
|
@@ -444,7 +452,8 @@ http_operation_js_1.HttpOperation.Entity.UpdateMany = function (arg0, arg1) {
|
|
|
444
452
|
description: 'Determines filter fields',
|
|
445
453
|
});
|
|
446
454
|
decoratorChain.push((operationMeta) => {
|
|
447
|
-
const compositionOptions = (operationMeta.compositionOptions =
|
|
455
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
456
|
+
operationMeta.compositionOptions || {});
|
|
448
457
|
compositionOptions.type = getDataTypeName(args.type);
|
|
449
458
|
});
|
|
450
459
|
decorator.Filter = (field, operators, description) => {
|
|
@@ -537,7 +546,8 @@ http_operation_js_1.HttpOperation.Entity.Update = function (arg0, arg1) {
|
|
|
537
546
|
return decorator;
|
|
538
547
|
};
|
|
539
548
|
decoratorChain.push((operationMeta) => {
|
|
540
|
-
const compositionOptions = (operationMeta.compositionOptions =
|
|
549
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
550
|
+
operationMeta.compositionOptions || {});
|
|
541
551
|
compositionOptions.type = getDataTypeName(args.type);
|
|
542
552
|
});
|
|
543
553
|
decorator.Filter = (field, operators, description) => {
|
|
@@ -15,8 +15,7 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
|
|
|
15
15
|
...options,
|
|
16
16
|
kind: index_js_2.OpraSchema.HttpOperation.Kind,
|
|
17
17
|
};
|
|
18
|
-
const controllerMetadata = (Reflect.getOwnMetadata(constants_js_1.HTTP_CONTROLLER_METADATA, target.constructor) ||
|
|
19
|
-
{});
|
|
18
|
+
const controllerMetadata = (Reflect.getOwnMetadata(constants_js_1.HTTP_CONTROLLER_METADATA, target.constructor) || {});
|
|
20
19
|
controllerMetadata.operations = controllerMetadata.operations || {};
|
|
21
20
|
controllerMetadata.operations[propertyKey] = operationMetadata;
|
|
22
21
|
for (const fn of decoratorChain)
|
|
@@ -111,9 +110,13 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
|
|
|
111
110
|
*
|
|
112
111
|
*/
|
|
113
112
|
decorator.Response = (statusCode, responseOptions) => {
|
|
114
|
-
const responseMeta = {
|
|
113
|
+
const responseMeta = {
|
|
114
|
+
...responseOptions,
|
|
115
|
+
statusCode,
|
|
116
|
+
};
|
|
115
117
|
if (responseMeta.type) {
|
|
116
|
-
responseMeta.contentType =
|
|
118
|
+
responseMeta.contentType =
|
|
119
|
+
responseMeta.contentType || index_js_1.MimeTypes.opra_response_json;
|
|
117
120
|
responseMeta.contentEncoding = responseMeta.contentEncoding || 'utf-8';
|
|
118
121
|
}
|
|
119
122
|
if (responseMeta.contentType === index_js_1.MimeTypes.opra_response_json) {
|
|
@@ -132,8 +135,12 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
|
|
|
132
135
|
contentMeta.contentEncoding = contentMeta.contentEncoding || 'utf-8';
|
|
133
136
|
}
|
|
134
137
|
decoratorChain.push((operationMetadata) => {
|
|
135
|
-
operationMetadata.requestBody = operationMetadata.requestBody || {
|
|
136
|
-
|
|
138
|
+
operationMetadata.requestBody = operationMetadata.requestBody || {
|
|
139
|
+
required: true,
|
|
140
|
+
content: [],
|
|
141
|
+
};
|
|
142
|
+
operationMetadata.requestBody.content =
|
|
143
|
+
operationMetadata.requestBody.content || [];
|
|
137
144
|
operationMetadata.requestBody.content.push(contentMeta);
|
|
138
145
|
});
|
|
139
146
|
return decorator;
|
|
@@ -144,14 +151,19 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
|
|
|
144
151
|
contentType: contentOpts?.contentType || 'multipart/form-data',
|
|
145
152
|
};
|
|
146
153
|
decoratorChain.push((operationMetadata) => {
|
|
147
|
-
operationMetadata.requestBody = operationMetadata.requestBody || {
|
|
148
|
-
|
|
154
|
+
operationMetadata.requestBody = operationMetadata.requestBody || {
|
|
155
|
+
required: true,
|
|
156
|
+
content: [],
|
|
157
|
+
};
|
|
158
|
+
operationMetadata.requestBody.content =
|
|
159
|
+
operationMetadata.requestBody.content || [];
|
|
149
160
|
operationMetadata.requestBody.content.push(contentMetadata);
|
|
150
161
|
});
|
|
151
162
|
if (subInit) {
|
|
152
163
|
const configScope = {
|
|
153
164
|
Field(fieldName, opts) {
|
|
154
|
-
contentMetadata.multipartFields =
|
|
165
|
+
contentMetadata.multipartFields =
|
|
166
|
+
contentMetadata.multipartFields || [];
|
|
155
167
|
contentMetadata.multipartFields.push({
|
|
156
168
|
fieldName,
|
|
157
169
|
fieldType: 'field',
|
|
@@ -160,7 +172,8 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
|
|
|
160
172
|
return configScope;
|
|
161
173
|
},
|
|
162
174
|
File(fieldName, opts) {
|
|
163
|
-
contentMetadata.multipartFields =
|
|
175
|
+
contentMetadata.multipartFields =
|
|
176
|
+
contentMetadata.multipartFields || [];
|
|
164
177
|
contentMetadata.multipartFields.push({
|
|
165
178
|
fieldName,
|
|
166
179
|
fieldType: 'file',
|
|
@@ -19,8 +19,7 @@ function RpcOperationDecoratorFactory(decoratorChain, payloadType, options) {
|
|
|
19
19
|
payloadType,
|
|
20
20
|
...(0, objects_1.omit)(options, ['kind', 'payloadType']),
|
|
21
21
|
};
|
|
22
|
-
const controllerMetadata = (Reflect.getOwnMetadata(constants_js_1.RPC_CONTROLLER_METADATA, target.constructor) ||
|
|
23
|
-
{});
|
|
22
|
+
const controllerMetadata = (Reflect.getOwnMetadata(constants_js_1.RPC_CONTROLLER_METADATA, target.constructor) || {});
|
|
24
23
|
controllerMetadata.operations = controllerMetadata.operations || {};
|
|
25
24
|
controllerMetadata.operations[propertyKey] = operationMetadata;
|
|
26
25
|
for (const fn of decoratorChain)
|
|
@@ -45,7 +45,8 @@ function AttributeDecoratorFactory(options) {
|
|
|
45
45
|
return (target, propertyKey) => {
|
|
46
46
|
if (typeof propertyKey !== 'string')
|
|
47
47
|
throw new TypeError(`Symbol properties can't be decorated with Attribute`);
|
|
48
|
-
const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target.constructor) ||
|
|
48
|
+
const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target.constructor) ||
|
|
49
|
+
{};
|
|
49
50
|
const designType = Reflect.getMetadata('design:type', target, propertyKey);
|
|
50
51
|
let format = 'string';
|
|
51
52
|
if (designType === Boolean)
|
|
@@ -25,7 +25,9 @@ class ApiDocumentFactory {
|
|
|
25
25
|
*/
|
|
26
26
|
static async createDocument(schemaOrUrl, options) {
|
|
27
27
|
const factory = new ApiDocumentFactory();
|
|
28
|
-
const context = options instanceof document_init_context_js_1.DocumentInitContext
|
|
28
|
+
const context = options instanceof document_init_context_js_1.DocumentInitContext
|
|
29
|
+
? options
|
|
30
|
+
: new document_init_context_js_1.DocumentInitContext(options);
|
|
29
31
|
try {
|
|
30
32
|
const document = new api_document_js_1.ApiDocument();
|
|
31
33
|
await factory.initDocument(document, context, schemaOrUrl);
|
|
@@ -113,12 +115,18 @@ class ApiDocumentFactory {
|
|
|
113
115
|
if (init.api) {
|
|
114
116
|
await context.enterAsync(`.api`, async () => {
|
|
115
117
|
if (init.api && init.api.transport === 'http') {
|
|
116
|
-
const api = await http_api_factory_js_1.HttpApiFactory.createApi(context, {
|
|
118
|
+
const api = await http_api_factory_js_1.HttpApiFactory.createApi(context, {
|
|
119
|
+
...init.api,
|
|
120
|
+
owner: document,
|
|
121
|
+
});
|
|
117
122
|
if (api)
|
|
118
123
|
document.api = api;
|
|
119
124
|
}
|
|
120
125
|
else if (init.api && init.api.transport === 'rpc') {
|
|
121
|
-
const api = await rpc_api_factory_js_1.RpcApiFactory.createApi(context, {
|
|
126
|
+
const api = await rpc_api_factory_js_1.RpcApiFactory.createApi(context, {
|
|
127
|
+
...init.api,
|
|
128
|
+
owner: document,
|
|
129
|
+
});
|
|
122
130
|
if (api)
|
|
123
131
|
document.api = api;
|
|
124
132
|
}
|