@opra/common 1.0.0-alpha.3 → 1.0.0-alpha.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.js +181 -58
- package/cjs/document/data-type/api-field.js +4 -0
- package/cjs/document/data-type/complex-type-base.js +4 -0
- package/cjs/document/data-type/complex-type.js +2 -0
- package/cjs/document/data-type/enum-type.js +2 -0
- package/cjs/document/data-type/extended-types/base64.type.js +4 -0
- package/cjs/document/data-type/extended-types/date-string.type.js +4 -0
- package/cjs/document/data-type/extended-types/date-time-string.type.js +4 -0
- package/cjs/document/data-type/extended-types/date-time.type.js +4 -0
- package/cjs/document/data-type/extended-types/date.type.js +4 -0
- package/cjs/document/data-type/extended-types/email.type.js +4 -0
- package/cjs/document/data-type/extended-types/field-path.type.js +4 -0
- package/cjs/document/data-type/extended-types/filter.type.js +4 -0
- package/cjs/document/data-type/extended-types/object-id.type.js +4 -0
- package/cjs/document/data-type/extended-types/time.type.js +4 -0
- package/cjs/document/data-type/extended-types/url.type.js +4 -0
- package/cjs/document/data-type/extended-types/uuid.type.js +4 -0
- package/cjs/document/data-type/mapped-type.js +3 -0
- package/cjs/document/data-type/mixin-type.js +3 -0
- package/cjs/document/data-type/primitive-types/bigint.type.js +4 -0
- package/cjs/document/data-type/primitive-types/boolean.type.js +4 -0
- package/cjs/document/data-type/primitive-types/integer.type.js +4 -0
- package/cjs/document/data-type/primitive-types/null.type.js +4 -0
- package/cjs/document/data-type/primitive-types/number.type.js +4 -0
- package/cjs/document/data-type/primitive-types/string.type.js +4 -0
- package/cjs/document/data-type/simple-type.js +8 -1
- package/cjs/document/decorators/http-operation-entity.decorator.js +7 -7
- package/cjs/document/factory/data-type.factory.js +61 -38
- package/esm/document/data-type/api-field.js +4 -0
- package/esm/document/data-type/complex-type-base.js +4 -0
- package/esm/document/data-type/complex-type.js +2 -0
- package/esm/document/data-type/enum-type.js +2 -0
- package/esm/document/data-type/extended-types/base64.type.js +4 -0
- package/esm/document/data-type/extended-types/date-string.type.js +4 -0
- package/esm/document/data-type/extended-types/date-time-string.type.js +4 -0
- package/esm/document/data-type/extended-types/date-time.type.js +4 -0
- package/esm/document/data-type/extended-types/date.type.js +4 -0
- package/esm/document/data-type/extended-types/email.type.js +4 -0
- package/esm/document/data-type/extended-types/field-path.type.js +4 -0
- package/esm/document/data-type/extended-types/filter.type.js +4 -0
- package/esm/document/data-type/extended-types/object-id.type.js +4 -0
- package/esm/document/data-type/extended-types/time.type.js +4 -0
- package/esm/document/data-type/extended-types/url.type.js +4 -0
- package/esm/document/data-type/extended-types/uuid.type.js +4 -0
- package/esm/document/data-type/mapped-type.js +3 -0
- package/esm/document/data-type/mixin-type.js +3 -0
- package/esm/document/data-type/primitive-types/bigint.type.js +4 -0
- package/esm/document/data-type/primitive-types/boolean.type.js +4 -0
- package/esm/document/data-type/primitive-types/integer.type.js +4 -0
- package/esm/document/data-type/primitive-types/null.type.js +4 -0
- package/esm/document/data-type/primitive-types/number.type.js +4 -0
- package/esm/document/data-type/primitive-types/string.type.js +4 -0
- package/esm/document/data-type/simple-type.js +8 -1
- package/esm/document/decorators/http-operation-entity.decorator.js +7 -7
- package/esm/document/factory/data-type.factory.js +61 -38
- package/package.json +3 -3
- package/types/document/data-type/api-field.d.ts +2 -0
- package/types/document/data-type/complex-type.d.ts +1 -1
- package/types/document/data-type/data-type.d.ts +4 -2
- package/types/document/data-type/enum-type.d.ts +2 -2
- package/types/document/data-type/mapped-type.d.ts +2 -2
- package/types/document/data-type/mixin-type.d.ts +2 -2
- package/types/document/data-type/simple-type.d.ts +4 -2
- package/types/document/factory/data-type.factory.d.ts +5 -0
- package/types/schema/data-type/simple-type.interface.d.ts +4 -0
|
@@ -53,6 +53,10 @@ tslib_1.__decorate([
|
|
|
53
53
|
exports.DateType = DateType = tslib_1.__decorate([
|
|
54
54
|
(0, simple_type_js_1.SimpleType)({
|
|
55
55
|
description: 'A date without time',
|
|
56
|
+
nameMappings: {
|
|
57
|
+
js: 'Date',
|
|
58
|
+
json: 'string',
|
|
59
|
+
},
|
|
56
60
|
}).Example('2021-04-18', 'Full date value'),
|
|
57
61
|
tslib_1.__metadata("design:paramtypes", [Object])
|
|
58
62
|
], DateType);
|
|
@@ -85,6 +85,10 @@ tslib_1.__decorate([
|
|
|
85
85
|
exports.EmailType = EmailType = tslib_1.__decorate([
|
|
86
86
|
(0, simple_type_js_1.SimpleType)({
|
|
87
87
|
description: 'An email value',
|
|
88
|
+
nameMappings: {
|
|
89
|
+
js: 'string',
|
|
90
|
+
json: 'string',
|
|
91
|
+
},
|
|
88
92
|
}).Example('some.body@example.com'),
|
|
89
93
|
tslib_1.__metadata("design:paramtypes", [Object])
|
|
90
94
|
], EmailType);
|
|
@@ -52,6 +52,10 @@ tslib_1.__decorate([
|
|
|
52
52
|
exports.FieldPathType = FieldPathType = tslib_1.__decorate([
|
|
53
53
|
(0, simple_type_js_1.SimpleType)({
|
|
54
54
|
description: 'Field path',
|
|
55
|
+
nameMappings: {
|
|
56
|
+
js: 'string',
|
|
57
|
+
json: 'string',
|
|
58
|
+
},
|
|
55
59
|
}),
|
|
56
60
|
tslib_1.__metadata("design:paramtypes", [Object])
|
|
57
61
|
], FieldPathType);
|
|
@@ -49,6 +49,10 @@ tslib_1.__decorate([
|
|
|
49
49
|
exports.FilterType = FilterType = tslib_1.__decorate([
|
|
50
50
|
(0, simple_type_js_1.SimpleType)({
|
|
51
51
|
description: 'A query filter',
|
|
52
|
+
nameMappings: {
|
|
53
|
+
js: 'object',
|
|
54
|
+
json: 'string',
|
|
55
|
+
},
|
|
52
56
|
}),
|
|
53
57
|
tslib_1.__metadata("design:paramtypes", [Object])
|
|
54
58
|
], FilterType);
|
|
@@ -21,6 +21,10 @@ exports.ObjectIdType = ObjectIdType;
|
|
|
21
21
|
exports.ObjectIdType = ObjectIdType = tslib_1.__decorate([
|
|
22
22
|
(0, simple_type_js_1.SimpleType)({
|
|
23
23
|
description: 'A MongoDB ObjectID value',
|
|
24
|
+
nameMappings: {
|
|
25
|
+
js: 'object',
|
|
26
|
+
json: 'string',
|
|
27
|
+
},
|
|
24
28
|
}),
|
|
25
29
|
tslib_1.__metadata("design:paramtypes", [Object])
|
|
26
30
|
], ObjectIdType);
|
|
@@ -43,6 +43,10 @@ tslib_1.__decorate([
|
|
|
43
43
|
exports.TimeType = TimeType = tslib_1.__decorate([
|
|
44
44
|
(0, simple_type_js_1.SimpleType)({
|
|
45
45
|
description: 'Time string in 24h format',
|
|
46
|
+
nameMappings: {
|
|
47
|
+
js: 'string',
|
|
48
|
+
json: 'string',
|
|
49
|
+
},
|
|
46
50
|
})
|
|
47
51
|
.Example('18:23:00', 'Full time value')
|
|
48
52
|
.Example('18:23:00', 'Time value without seconds'),
|
|
@@ -21,6 +21,10 @@ exports.UrlType = UrlType;
|
|
|
21
21
|
exports.UrlType = UrlType = tslib_1.__decorate([
|
|
22
22
|
(0, simple_type_js_1.SimpleType)({
|
|
23
23
|
description: 'A Uniform Resource Identifier Reference (RFC 3986 icon) value',
|
|
24
|
+
nameMappings: {
|
|
25
|
+
js: 'string',
|
|
26
|
+
json: 'string',
|
|
27
|
+
},
|
|
24
28
|
}).Example('http://tempuri.org'),
|
|
25
29
|
tslib_1.__metadata("design:paramtypes", [Object])
|
|
26
30
|
], UrlType);
|
|
@@ -27,6 +27,10 @@ tslib_1.__decorate([
|
|
|
27
27
|
exports.UuidType = UuidType = tslib_1.__decorate([
|
|
28
28
|
(0, simple_type_js_1.SimpleType)({
|
|
29
29
|
description: 'A Universal Unique Identifier (UUID) value',
|
|
30
|
+
nameMappings: {
|
|
31
|
+
js: 'string',
|
|
32
|
+
json: 'string',
|
|
33
|
+
},
|
|
30
34
|
}),
|
|
31
35
|
tslib_1.__metadata("design:paramtypes", [Object])
|
|
32
36
|
], UuidType);
|
|
@@ -7,6 +7,7 @@ const index_js_1 = require("../../helpers/index.js");
|
|
|
7
7
|
const index_js_2 = require("../../schema/index.js");
|
|
8
8
|
const api_field_js_1 = require("./api-field.js");
|
|
9
9
|
const complex_type_base_js_1 = require("./complex-type-base.js");
|
|
10
|
+
const data_type_js_1 = require("./data-type.js");
|
|
10
11
|
const get_is_inherited_predicate_fn_js_1 = require("./utils/get-is-inherited-predicate-fn.js");
|
|
11
12
|
/**
|
|
12
13
|
* MappedType constructor
|
|
@@ -68,6 +69,8 @@ exports.MappedType = function (...args) {
|
|
|
68
69
|
*/
|
|
69
70
|
class MappedTypeClass extends complex_type_base_js_1.ComplexTypeBase {
|
|
70
71
|
extendsFrom(baseType) {
|
|
72
|
+
if (!(baseType instanceof data_type_js_1.DataType))
|
|
73
|
+
baseType = this.node.getDataType(baseType);
|
|
71
74
|
if (!(baseType instanceof complex_type_base_js_1.ComplexTypeBase))
|
|
72
75
|
return false;
|
|
73
76
|
if (baseType === this)
|
|
@@ -8,6 +8,7 @@ const index_js_2 = require("../../schema/index.js");
|
|
|
8
8
|
const constants_js_1 = require("../constants.js");
|
|
9
9
|
const api_field_js_1 = require("./api-field.js");
|
|
10
10
|
const complex_type_base_js_1 = require("./complex-type-base.js");
|
|
11
|
+
const data_type_js_1 = require("./data-type.js");
|
|
11
12
|
/**
|
|
12
13
|
* @class MixinType
|
|
13
14
|
*/
|
|
@@ -43,6 +44,8 @@ exports.MixinType = function (...args) {
|
|
|
43
44
|
*/
|
|
44
45
|
class MixinTypeClass extends complex_type_base_js_1.ComplexTypeBase {
|
|
45
46
|
extendsFrom(baseType) {
|
|
47
|
+
if (!(baseType instanceof data_type_js_1.DataType))
|
|
48
|
+
baseType = this.node.getDataType(baseType);
|
|
46
49
|
if (!(baseType instanceof complex_type_base_js_1.ComplexTypeBase))
|
|
47
50
|
return false;
|
|
48
51
|
if (baseType === this)
|
|
@@ -26,6 +26,10 @@ exports.BigintType = BigintType;
|
|
|
26
26
|
exports.BigintType = BigintType = tslib_1.__decorate([
|
|
27
27
|
(0, simple_type_js_1.SimpleType)({
|
|
28
28
|
description: 'BigInt number',
|
|
29
|
+
nameMappings: {
|
|
30
|
+
js: 'bigint',
|
|
31
|
+
json: 'string',
|
|
32
|
+
},
|
|
29
33
|
}),
|
|
30
34
|
tslib_1.__metadata("design:paramtypes", [Object])
|
|
31
35
|
], BigintType);
|
|
@@ -21,6 +21,10 @@ exports.BooleanType = BooleanType;
|
|
|
21
21
|
exports.BooleanType = BooleanType = tslib_1.__decorate([
|
|
22
22
|
(0, simple_type_js_1.SimpleType)({
|
|
23
23
|
description: 'Simple true/false value',
|
|
24
|
+
nameMappings: {
|
|
25
|
+
js: 'boolean',
|
|
26
|
+
json: 'boolean',
|
|
27
|
+
},
|
|
24
28
|
}),
|
|
25
29
|
tslib_1.__metadata("design:paramtypes", [Object])
|
|
26
30
|
], BooleanType);
|
|
@@ -26,6 +26,10 @@ exports.IntegerType = IntegerType;
|
|
|
26
26
|
exports.IntegerType = IntegerType = tslib_1.__decorate([
|
|
27
27
|
(0, simple_type_js_1.SimpleType)({
|
|
28
28
|
description: 'An integer number',
|
|
29
|
+
nameMappings: {
|
|
30
|
+
js: 'number',
|
|
31
|
+
json: 'number',
|
|
32
|
+
},
|
|
29
33
|
}),
|
|
30
34
|
tslib_1.__metadata("design:paramtypes", [Object])
|
|
31
35
|
], IntegerType);
|
|
@@ -21,6 +21,10 @@ exports.NullType = NullType;
|
|
|
21
21
|
exports.NullType = NullType = tslib_1.__decorate([
|
|
22
22
|
(0, simple_type_js_1.SimpleType)({
|
|
23
23
|
description: 'A Null value',
|
|
24
|
+
nameMappings: {
|
|
25
|
+
js: 'null',
|
|
26
|
+
json: 'null',
|
|
27
|
+
},
|
|
24
28
|
}),
|
|
25
29
|
tslib_1.__metadata("design:paramtypes", [Object])
|
|
26
30
|
], NullType);
|
|
@@ -38,6 +38,10 @@ tslib_1.__decorate([
|
|
|
38
38
|
exports.NumberType = NumberType = tslib_1.__decorate([
|
|
39
39
|
(0, simple_type_js_1.SimpleType)({
|
|
40
40
|
description: 'Both Integer as well as Floating-Point numbers',
|
|
41
|
+
nameMappings: {
|
|
42
|
+
js: 'number',
|
|
43
|
+
json: 'number',
|
|
44
|
+
},
|
|
41
45
|
}),
|
|
42
46
|
tslib_1.__metadata("design:paramtypes", [Object])
|
|
43
47
|
], NumberType);
|
|
@@ -58,6 +58,10 @@ tslib_1.__decorate([
|
|
|
58
58
|
exports.StringType = StringType = tslib_1.__decorate([
|
|
59
59
|
(0, simple_type_js_1.SimpleType)({
|
|
60
60
|
description: 'A sequence of characters',
|
|
61
|
+
nameMappings: {
|
|
62
|
+
js: 'string',
|
|
63
|
+
json: 'string',
|
|
64
|
+
},
|
|
61
65
|
}),
|
|
62
66
|
tslib_1.__metadata("design:paramtypes", [Object])
|
|
63
67
|
], StringType);
|
|
@@ -28,6 +28,8 @@ exports.SimpleType = function (...args) {
|
|
|
28
28
|
_this.base = initArgs.base;
|
|
29
29
|
}
|
|
30
30
|
_this.properties = initArgs.properties;
|
|
31
|
+
_this.ownNameMappings = { ...initArgs.nameMappings };
|
|
32
|
+
_this.nameMappings = { ..._this.base?.nameMappings, ...initArgs.nameMappings };
|
|
31
33
|
_this.ownAttributes = (0, index_js_1.cloneObject)(initArgs.attributes || {});
|
|
32
34
|
_this.attributes = _this.base ? (0, index_js_1.cloneObject)(_this.base.attributes) : {};
|
|
33
35
|
if (_this.ownAttributes) {
|
|
@@ -46,6 +48,8 @@ exports.SimpleType = function (...args) {
|
|
|
46
48
|
*/
|
|
47
49
|
class SimpleTypeClass extends data_type_js_1.DataType {
|
|
48
50
|
extendsFrom(baseType) {
|
|
51
|
+
if (!(baseType instanceof data_type_js_1.DataType))
|
|
52
|
+
baseType = this.node.getDataType(baseType);
|
|
49
53
|
if (!(baseType instanceof exports.SimpleType))
|
|
50
54
|
return false;
|
|
51
55
|
if (baseType === this)
|
|
@@ -90,12 +94,15 @@ class SimpleTypeClass extends data_type_js_1.DataType {
|
|
|
90
94
|
return o;
|
|
91
95
|
}, {});
|
|
92
96
|
const baseName = this.base ? this.node.getDataTypeNameWithNs(this.base) : undefined;
|
|
93
|
-
|
|
97
|
+
const out = (0, index_js_1.omitUndefined)({
|
|
94
98
|
...data_type_js_1.DataType.prototype.toJSON.apply(this),
|
|
95
99
|
base: this.base ? (baseName ? baseName : this.base.toJSON()) : undefined,
|
|
96
100
|
attributes: attributes && Object.keys(attributes).length ? attributes : undefined,
|
|
97
101
|
properties: Object.keys(properties).length ? properties : undefined,
|
|
98
102
|
});
|
|
103
|
+
if (Object.keys(this.ownNameMappings).length)
|
|
104
|
+
out.nameMappings = { ...this.ownNameMappings };
|
|
105
|
+
return out;
|
|
99
106
|
}
|
|
100
107
|
}
|
|
101
108
|
exports.SimpleType.prototype = SimpleTypeClass.prototype;
|
|
@@ -23,8 +23,8 @@ http_operation_js_1.HttpOperation.Entity.Create = function (arg0, arg1) {
|
|
|
23
23
|
/** Initialize the decorator and the chain */
|
|
24
24
|
const decoratorChain = [];
|
|
25
25
|
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
|
|
26
|
-
description: args.description,
|
|
27
26
|
method: 'POST',
|
|
27
|
+
...args,
|
|
28
28
|
composition: 'Entity.Create',
|
|
29
29
|
requestBody: {
|
|
30
30
|
immediateFetch: true,
|
|
@@ -74,8 +74,8 @@ http_operation_js_1.HttpOperation.Entity.Delete = function (arg0, arg1) {
|
|
|
74
74
|
/** Initialize the decorator and the chain */
|
|
75
75
|
const decoratorChain = [];
|
|
76
76
|
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
|
|
77
|
-
description: args.description,
|
|
78
77
|
method: 'DELETE',
|
|
78
|
+
...args,
|
|
79
79
|
composition: 'Entity.Delete',
|
|
80
80
|
}));
|
|
81
81
|
decorator
|
|
@@ -123,8 +123,8 @@ http_operation_js_1.HttpOperation.Entity.DeleteMany = function (arg0, arg1) {
|
|
|
123
123
|
const filterType = new index_js_3.FilterType({ dataType: args.type });
|
|
124
124
|
filterType.rules = {};
|
|
125
125
|
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
|
|
126
|
-
description: args.description,
|
|
127
126
|
method: 'DELETE',
|
|
127
|
+
...args,
|
|
128
128
|
composition: 'Entity.DeleteMany',
|
|
129
129
|
}));
|
|
130
130
|
decorator
|
|
@@ -171,8 +171,8 @@ http_operation_js_1.HttpOperation.Entity.FindMany = function (arg0, arg1) {
|
|
|
171
171
|
const filterType = new index_js_3.FilterType({ dataType: args.type });
|
|
172
172
|
filterType.rules = {};
|
|
173
173
|
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
|
|
174
|
-
description: args.description,
|
|
175
174
|
method: 'GET',
|
|
175
|
+
...args,
|
|
176
176
|
composition: 'Entity.FindMany',
|
|
177
177
|
}));
|
|
178
178
|
decorator
|
|
@@ -263,8 +263,8 @@ http_operation_js_1.HttpOperation.Entity.Get = function (arg0, arg1) {
|
|
|
263
263
|
/** Initialize the decorator and the chain */
|
|
264
264
|
const decoratorChain = [];
|
|
265
265
|
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
|
|
266
|
-
description: args.description,
|
|
267
266
|
method: 'GET',
|
|
267
|
+
...args,
|
|
268
268
|
composition: 'Entity.Get',
|
|
269
269
|
}));
|
|
270
270
|
decorator
|
|
@@ -326,8 +326,8 @@ http_operation_js_1.HttpOperation.Entity.UpdateMany = function (arg0, arg1) {
|
|
|
326
326
|
filterType.rules = {};
|
|
327
327
|
const filterRules = new filter_rules_js_1.FilterRules();
|
|
328
328
|
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
|
|
329
|
-
description: args.description,
|
|
330
329
|
method: 'PATCH',
|
|
330
|
+
...args,
|
|
331
331
|
composition: 'Entity.UpdateMany',
|
|
332
332
|
requestBody: {
|
|
333
333
|
immediateFetch: true,
|
|
@@ -381,8 +381,8 @@ http_operation_js_1.HttpOperation.Entity.Update = function (arg0, arg1) {
|
|
|
381
381
|
const filterType = new index_js_3.FilterType({ dataType: args.type });
|
|
382
382
|
filterType.rules = {};
|
|
383
383
|
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
|
|
384
|
-
description: args.description,
|
|
385
384
|
method: 'PATCH',
|
|
385
|
+
...args,
|
|
386
386
|
composition: 'Entity.Update',
|
|
387
387
|
requestBody: {
|
|
388
388
|
partial: 'deep',
|
|
@@ -7,6 +7,7 @@ const document_init_context_js_1 = require("../common/document-init-context.js")
|
|
|
7
7
|
const constants_js_1 = require("../constants.js");
|
|
8
8
|
const complex_type_js_1 = require("../data-type/complex-type.js");
|
|
9
9
|
const complex_type_base_js_1 = require("../data-type/complex-type-base.js");
|
|
10
|
+
const data_type_js_1 = require("../data-type/data-type.js");
|
|
10
11
|
const enum_type_js_1 = require("../data-type/enum-type.js");
|
|
11
12
|
const mapped_type_js_1 = require("../data-type/mapped-type.js");
|
|
12
13
|
const mixin_type_js_1 = require("../data-type/mixin-type.js");
|
|
@@ -133,7 +134,7 @@ class DataTypeFactory {
|
|
|
133
134
|
const { importQueue, initArgsMap } = context;
|
|
134
135
|
// Check if data type already exist (maybe a builtin type or already imported)
|
|
135
136
|
const dataType = owner.node.findDataType(thunk);
|
|
136
|
-
if (dataType)
|
|
137
|
+
if (dataType instanceof data_type_js_1.DataType)
|
|
137
138
|
return dataType.name;
|
|
138
139
|
let metadata;
|
|
139
140
|
let ctor;
|
|
@@ -212,11 +213,15 @@ class DataTypeFactory {
|
|
|
212
213
|
/** Mark "out" object as initializing. This will help us to detect circular dependencies */
|
|
213
214
|
out[initializingSymbol] = true;
|
|
214
215
|
try {
|
|
215
|
-
if (out.name
|
|
216
|
-
|
|
216
|
+
if (out.name) {
|
|
217
|
+
if (importQueue?.has(out.name)) {
|
|
218
|
+
initArgsMap?.set(metadata.name, out);
|
|
219
|
+
out._instance = { name: metadata.name };
|
|
220
|
+
out[constants_js_1.kDataTypeMap] = owner.node[constants_js_1.kDataTypeMap];
|
|
221
|
+
}
|
|
222
|
+
else
|
|
223
|
+
return context.addError(`Data Type (${out.name}) must be explicitly added to type list in the document scope`);
|
|
217
224
|
}
|
|
218
|
-
else if (out.name)
|
|
219
|
-
return context.addError(`Data Type (${out.name}) must be explicitly added to type list in the document scope`);
|
|
220
225
|
switch (out.kind) {
|
|
221
226
|
case index_js_2.OpraSchema.ComplexType.Kind:
|
|
222
227
|
out.ctor = ctor;
|
|
@@ -332,6 +337,7 @@ class DataTypeFactory {
|
|
|
332
337
|
initArgs.ctor = initArgs.ctor || baseArgs.ctor;
|
|
333
338
|
});
|
|
334
339
|
initArgs.properties = metadata.properties;
|
|
340
|
+
initArgs.nameMappings = metadata.nameMappings;
|
|
335
341
|
if (!initArgs.properties && initArgs.ctor)
|
|
336
342
|
initArgs.properties = new initArgs.ctor();
|
|
337
343
|
if (metadata.attributes)
|
|
@@ -384,27 +390,40 @@ class DataTypeFactory {
|
|
|
384
390
|
});
|
|
385
391
|
}
|
|
386
392
|
static _createDataType(context, owner, args) {
|
|
393
|
+
let dataType = owner.node.findDataType(typeof args === 'string' ? args : args.name || '');
|
|
394
|
+
if (dataType instanceof data_type_js_1.DataType)
|
|
395
|
+
return dataType;
|
|
387
396
|
const initArgs = typeof args === 'string' ? context.initArgsMap?.get(args) : args;
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
397
|
+
if (initArgs) {
|
|
398
|
+
const dataTypeMap = initArgs[constants_js_1.kDataTypeMap];
|
|
399
|
+
if (!dataTypeMap)
|
|
400
|
+
delete initArgs._instance;
|
|
401
|
+
dataType = initArgs._instance;
|
|
402
|
+
if (dataType?.name && dataTypeMap) {
|
|
403
|
+
dataTypeMap.set(dataType.name, dataType);
|
|
404
|
+
}
|
|
405
|
+
switch (initArgs?.kind) {
|
|
406
|
+
case index_js_2.OpraSchema.ComplexType.Kind:
|
|
407
|
+
return this._createComplexType(context, owner, initArgs);
|
|
408
|
+
case index_js_2.OpraSchema.EnumType.Kind:
|
|
409
|
+
return this._createEnumType(context, owner, initArgs);
|
|
410
|
+
case index_js_2.OpraSchema.MappedType.Kind:
|
|
411
|
+
return this._createMappedType(context, owner, initArgs);
|
|
412
|
+
case index_js_2.OpraSchema.MixinType.Kind:
|
|
413
|
+
return this._createMixinType(context, owner, initArgs);
|
|
414
|
+
case index_js_2.OpraSchema.SimpleType.Kind:
|
|
415
|
+
return this._createSimpleType(context, owner, initArgs);
|
|
416
|
+
}
|
|
399
417
|
}
|
|
400
418
|
context.addError(`Unknown data type (${String(args)})`);
|
|
401
419
|
}
|
|
402
420
|
static _createComplexType(context, owner, args) {
|
|
421
|
+
const dataType = args._instance || {};
|
|
422
|
+
Object.setPrototypeOf(dataType, complex_type_js_1.ComplexType.prototype);
|
|
403
423
|
const initArgs = (0, index_js_1.cloneObject)(args);
|
|
404
424
|
if (args.base) {
|
|
405
425
|
context.enter('.base', () => {
|
|
406
|
-
initArgs.base = (owner
|
|
407
|
-
this._createDataType(context, owner, args.base));
|
|
426
|
+
initArgs.base = this._createDataType(context, owner, args.base);
|
|
408
427
|
});
|
|
409
428
|
}
|
|
410
429
|
/** Set additionalFields */
|
|
@@ -413,14 +432,7 @@ class DataTypeFactory {
|
|
|
413
432
|
if (typeof args.additionalFields === 'boolean' || Array.isArray(args.additionalFields))
|
|
414
433
|
initArgs.additionalFields = args.additionalFields;
|
|
415
434
|
else {
|
|
416
|
-
|
|
417
|
-
initArgs.additionalFields =
|
|
418
|
-
owner.node.findDataType(args.additionalFields) ||
|
|
419
|
-
this._createDataType(context, owner, args.additionalFields);
|
|
420
|
-
}
|
|
421
|
-
else {
|
|
422
|
-
initArgs.additionalFields = this._createDataType(context, owner, args.additionalFields);
|
|
423
|
-
}
|
|
435
|
+
initArgs.additionalFields = this._createDataType(context, owner, args.additionalFields);
|
|
424
436
|
}
|
|
425
437
|
});
|
|
426
438
|
}
|
|
@@ -430,7 +442,7 @@ class DataTypeFactory {
|
|
|
430
442
|
context.enter('.fields', () => {
|
|
431
443
|
for (const [k, v] of Object.entries(args.fields)) {
|
|
432
444
|
context.enter(`[${k}]`, () => {
|
|
433
|
-
const type =
|
|
445
|
+
const type = this._createDataType(context, owner, v.type);
|
|
434
446
|
if (type)
|
|
435
447
|
initArgs.fields[k] = {
|
|
436
448
|
...v,
|
|
@@ -441,29 +453,37 @@ class DataTypeFactory {
|
|
|
441
453
|
}
|
|
442
454
|
});
|
|
443
455
|
}
|
|
444
|
-
|
|
456
|
+
complex_type_js_1.ComplexType.apply(dataType, [owner, initArgs]);
|
|
457
|
+
return dataType;
|
|
445
458
|
}
|
|
446
459
|
static _createEnumType(context, owner, args) {
|
|
460
|
+
const dataType = args._instance || {};
|
|
461
|
+
Object.setPrototypeOf(dataType, enum_type_js_1.EnumType.prototype);
|
|
447
462
|
const initArgs = (0, index_js_1.cloneObject)(args);
|
|
448
463
|
if (args.base) {
|
|
449
464
|
context.enter('.base', () => {
|
|
450
|
-
initArgs.base = (owner
|
|
451
|
-
this._createDataType(context, owner, args.base));
|
|
465
|
+
initArgs.base = this._createDataType(context, owner, args.base);
|
|
452
466
|
});
|
|
453
467
|
}
|
|
454
468
|
initArgs.attributes = args.attributes;
|
|
455
|
-
|
|
469
|
+
enum_type_js_1.EnumType.apply(dataType, [owner, initArgs]);
|
|
470
|
+
return dataType;
|
|
456
471
|
}
|
|
457
472
|
static _createMappedType(context, owner, args) {
|
|
473
|
+
const dataType = args._instance || {};
|
|
474
|
+
Object.setPrototypeOf(dataType, mapped_type_js_1.MappedType.prototype);
|
|
458
475
|
const initArgs = (0, index_js_1.cloneObject)(args);
|
|
459
476
|
if (args.base) {
|
|
460
477
|
context.enter('.base', () => {
|
|
461
|
-
initArgs.base =
|
|
478
|
+
initArgs.base = this._createDataType(context, owner, args.base);
|
|
462
479
|
});
|
|
463
480
|
}
|
|
464
|
-
|
|
481
|
+
mapped_type_js_1.MappedType.apply(dataType, [owner, initArgs]);
|
|
482
|
+
return dataType;
|
|
465
483
|
}
|
|
466
484
|
static _createMixinType(context, owner, args) {
|
|
485
|
+
const dataType = args._instance || {};
|
|
486
|
+
Object.setPrototypeOf(dataType, mixin_type_js_1.MixinType.prototype);
|
|
467
487
|
const initArgs = (0, index_js_1.cloneObject)(args);
|
|
468
488
|
if (args.types) {
|
|
469
489
|
context.enter('.types', () => {
|
|
@@ -471,7 +491,7 @@ class DataTypeFactory {
|
|
|
471
491
|
let i = 0;
|
|
472
492
|
for (const t of args.types) {
|
|
473
493
|
context.enter(`[${i++}]`, () => {
|
|
474
|
-
const base =
|
|
494
|
+
const base = this._createDataType(context, owner, t);
|
|
475
495
|
if (!(base instanceof complex_type_base_js_1.ComplexTypeBase))
|
|
476
496
|
throw new TypeError(`"${base?.kind}" can't be set as base for a "${initArgs.kind}"`);
|
|
477
497
|
initArgs.types.push(base);
|
|
@@ -479,17 +499,20 @@ class DataTypeFactory {
|
|
|
479
499
|
}
|
|
480
500
|
});
|
|
481
501
|
}
|
|
482
|
-
|
|
502
|
+
mixin_type_js_1.MixinType.apply(dataType, [owner, initArgs]);
|
|
503
|
+
return dataType;
|
|
483
504
|
}
|
|
484
505
|
static _createSimpleType(context, owner, args) {
|
|
506
|
+
const dataType = args._instance || {};
|
|
507
|
+
Object.setPrototypeOf(dataType, simple_type_js_1.SimpleType.prototype);
|
|
485
508
|
const initArgs = (0, index_js_1.cloneObject)(args);
|
|
486
509
|
if (args.base) {
|
|
487
510
|
context.enter('.base', () => {
|
|
488
|
-
initArgs.base = (owner
|
|
489
|
-
this._createDataType(context, owner, args.base));
|
|
511
|
+
initArgs.base = this._createDataType(context, owner, args.base);
|
|
490
512
|
});
|
|
491
513
|
}
|
|
492
|
-
|
|
514
|
+
simple_type_js_1.SimpleType.apply(dataType, [owner, initArgs]);
|
|
515
|
+
return dataType;
|
|
493
516
|
}
|
|
494
517
|
}
|
|
495
518
|
exports.DataTypeFactory = DataTypeFactory;
|
|
@@ -33,6 +33,8 @@ export const ApiField = function (...args) {
|
|
|
33
33
|
_this.exclusive = initArgs.exclusive;
|
|
34
34
|
_this.translatable = initArgs.translatable;
|
|
35
35
|
_this.deprecated = initArgs.deprecated;
|
|
36
|
+
_this.readonly = initArgs.readonly;
|
|
37
|
+
_this.writeonly = initArgs.writeonly;
|
|
36
38
|
_this.examples = initArgs.examples;
|
|
37
39
|
};
|
|
38
40
|
/**
|
|
@@ -52,6 +54,8 @@ class ApiFieldClass extends DocumentElement {
|
|
|
52
54
|
exclusive: this.exclusive,
|
|
53
55
|
translatable: this.translatable,
|
|
54
56
|
deprecated: this.deprecated,
|
|
57
|
+
readonly: this.readonly,
|
|
58
|
+
writeonly: this.writeonly,
|
|
55
59
|
examples: this.examples,
|
|
56
60
|
});
|
|
57
61
|
}
|
|
@@ -143,6 +143,10 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
143
143
|
// Process fields
|
|
144
144
|
let fieldName;
|
|
145
145
|
for (const field of this.fields.values()) {
|
|
146
|
+
if ((context.ignoreReadonlyFields && field.readonly) || (context.ignoreWriteonlyFields && field.writeonly)) {
|
|
147
|
+
schema[field.name] = vg.isUndefined({ coerce: true });
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
146
150
|
fieldName = field.name;
|
|
147
151
|
let p;
|
|
148
152
|
if (projection !== '*') {
|
|
@@ -57,6 +57,8 @@ export const ComplexType = function (...args) {
|
|
|
57
57
|
*/
|
|
58
58
|
class ComplexTypeClass extends ComplexTypeBase {
|
|
59
59
|
extendsFrom(baseType) {
|
|
60
|
+
if (!(baseType instanceof DataType))
|
|
61
|
+
baseType = this.node.getDataType(baseType);
|
|
60
62
|
if (!(baseType instanceof ComplexTypeBase))
|
|
61
63
|
return false;
|
|
62
64
|
if (baseType === this)
|
|
@@ -35,6 +35,8 @@ export const EnumType = function (...args) {
|
|
|
35
35
|
*/
|
|
36
36
|
class EnumTypeClass extends DataType {
|
|
37
37
|
extendsFrom(baseType) {
|
|
38
|
+
if (!(baseType instanceof DataType))
|
|
39
|
+
baseType = this.node.getDataType(baseType);
|
|
38
40
|
if (!(baseType instanceof EnumType))
|
|
39
41
|
return false;
|
|
40
42
|
if (baseType === this)
|
|
@@ -17,6 +17,10 @@ let Base64Type = class Base64Type {
|
|
|
17
17
|
Base64Type = __decorate([
|
|
18
18
|
SimpleType({
|
|
19
19
|
description: 'A stream of bytes, base64 encoded',
|
|
20
|
+
nameMappings: {
|
|
21
|
+
js: 'string',
|
|
22
|
+
json: 'string',
|
|
23
|
+
},
|
|
20
24
|
}),
|
|
21
25
|
__metadata("design:paramtypes", [Object])
|
|
22
26
|
], Base64Type);
|
|
@@ -35,6 +35,10 @@ __decorate([
|
|
|
35
35
|
DateStringType = __decorate([
|
|
36
36
|
SimpleType({
|
|
37
37
|
description: 'Date string value',
|
|
38
|
+
nameMappings: {
|
|
39
|
+
js: 'string',
|
|
40
|
+
json: 'string',
|
|
41
|
+
},
|
|
38
42
|
})
|
|
39
43
|
.Example('2021-04-18', 'Full date value')
|
|
40
44
|
.Example('2021-04', 'Date value without day')
|
|
@@ -35,6 +35,10 @@ __decorate([
|
|
|
35
35
|
DateTimeStringType = __decorate([
|
|
36
36
|
SimpleType({
|
|
37
37
|
description: 'DateTime string value',
|
|
38
|
+
nameMappings: {
|
|
39
|
+
js: 'string',
|
|
40
|
+
json: 'string',
|
|
41
|
+
},
|
|
38
42
|
})
|
|
39
43
|
.Example('2021-04-18T22:30:15+01:00', 'Full date-time value with timezone')
|
|
40
44
|
.Example('2021-04-18T22:30:15', 'Full date-time value without timezone')
|
|
@@ -49,6 +49,10 @@ __decorate([
|
|
|
49
49
|
DateType = __decorate([
|
|
50
50
|
SimpleType({
|
|
51
51
|
description: 'A date without time',
|
|
52
|
+
nameMappings: {
|
|
53
|
+
js: 'Date',
|
|
54
|
+
json: 'string',
|
|
55
|
+
},
|
|
52
56
|
}).Example('2021-04-18', 'Full date value'),
|
|
53
57
|
__metadata("design:paramtypes", [Object])
|
|
54
58
|
], DateType);
|