@opra/common 1.17.7 → 1.19.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/data-type/api-field.js +11 -5
- package/cjs/document/data-type/complex-type-base.js +2 -0
- package/cjs/document/data-type/extended-types/base64.type.js +16 -3
- package/cjs/document/data-type/extended-types/date-time-tz.type.js +71 -0
- package/cjs/document/data-type/extended-types/date-time.type.js +13 -9
- package/cjs/document/data-type/extended-types/date.type.js +14 -9
- package/cjs/document/data-type/extended-types/index.js +2 -2
- package/cjs/document/data-type/extended-types/partial-date.type.js +85 -0
- package/cjs/document/data-type/simple-type.js +4 -0
- package/cjs/document/decorators/api-field-decorator.js +1 -0
- package/cjs/document/factory/api-document.factory.js +5 -25
- package/cjs/document/factory/data-type.factory.js +1 -0
- package/cjs/filter/filter-rules.js +1 -1
- package/esm/document/data-type/api-field.js +11 -5
- package/esm/document/data-type/complex-type-base.js +2 -0
- package/esm/document/data-type/extended-types/base64.type.js +17 -4
- package/esm/document/data-type/extended-types/date-time-tz.type.js +68 -0
- package/esm/document/data-type/extended-types/date-time.type.js +13 -9
- package/esm/document/data-type/extended-types/date.type.js +14 -9
- package/esm/document/data-type/extended-types/index.js +2 -2
- package/esm/document/data-type/extended-types/partial-date.type.js +82 -0
- package/esm/document/data-type/simple-type.js +4 -0
- package/esm/document/decorators/api-field-decorator.js +1 -0
- package/esm/document/factory/api-document.factory.js +4 -25
- package/esm/document/factory/data-type.factory.js +1 -0
- package/esm/filter/filter-rules.js +1 -1
- package/package.json +3 -3
- package/types/document/data-type/api-field.d.ts +8 -0
- package/types/document/data-type/data-type.d.ts +1 -1
- package/types/document/data-type/extended-types/base64.type.d.ts +2 -1
- package/types/document/data-type/extended-types/{date-string.type.d.ts → date-time-tz.type.d.ts} +2 -2
- package/types/document/data-type/extended-types/date-time.type.d.ts +1 -0
- package/types/document/data-type/extended-types/date.type.d.ts +1 -0
- package/types/document/data-type/extended-types/index.d.ts +2 -2
- package/types/document/data-type/extended-types/{date-time-string.type.d.ts → partial-date.type.d.ts} +2 -2
- package/types/document/data-type/simple-type.d.ts +3 -1
- package/types/document/factory/data-type.factory.d.ts +1 -0
- package/cjs/document/data-type/extended-types/date-string.type.js +0 -52
- package/cjs/document/data-type/extended-types/date-time-string.type.js +0 -55
- package/esm/document/data-type/extended-types/date-string.type.js +0 -49
- package/esm/document/data-type/extended-types/date-time-string.type.js +0 -52
|
@@ -28,11 +28,6 @@ exports.ApiField = function (...args) {
|
|
|
28
28
|
throw new Error('Field origin should be one of ComplexType, MappedType or MixinType');
|
|
29
29
|
}
|
|
30
30
|
_this.origin = origin;
|
|
31
|
-
_this.scopePattern = initArgs.scopePattern
|
|
32
|
-
? Array.isArray(initArgs.scopePattern)
|
|
33
|
-
? initArgs.scopePattern
|
|
34
|
-
: [initArgs.scopePattern]
|
|
35
|
-
: undefined;
|
|
36
31
|
_this.type = initArgs.type || owner.node.getDataType('any');
|
|
37
32
|
_this.description = initArgs.description;
|
|
38
33
|
_this.isArray = initArgs.isArray;
|
|
@@ -48,6 +43,17 @@ exports.ApiField = function (...args) {
|
|
|
48
43
|
_this.writeonly = initArgs.writeonly;
|
|
49
44
|
_this.examples = initArgs.examples;
|
|
50
45
|
_this.override = initArgs.override;
|
|
46
|
+
_this.scopePattern = initArgs.scopePattern
|
|
47
|
+
? Array.isArray(initArgs.scopePattern)
|
|
48
|
+
? initArgs.scopePattern
|
|
49
|
+
: [initArgs.scopePattern]
|
|
50
|
+
: undefined;
|
|
51
|
+
_this.convertToNative =
|
|
52
|
+
initArgs.convertToNative ??
|
|
53
|
+
(_this.type.kind === 'SimpleType' &&
|
|
54
|
+
typeof initArgs.designType === 'function' &&
|
|
55
|
+
initArgs.designType !== Object);
|
|
56
|
+
_this.override = initArgs.override;
|
|
51
57
|
};
|
|
52
58
|
/**
|
|
53
59
|
* The ApiFieldClass represents a descriptive metadata structure for API fields,
|
|
@@ -334,6 +334,8 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
|
|
|
334
334
|
let fn = field.type.generateCodec(codec, {
|
|
335
335
|
...context,
|
|
336
336
|
level: context.level + 1,
|
|
337
|
+
}, {
|
|
338
|
+
convertToNative: field.convertToNative,
|
|
337
339
|
});
|
|
338
340
|
if (field.fixed)
|
|
339
341
|
fn = valgen_1.vg.isEqual(field.fixed);
|
|
@@ -10,11 +10,14 @@ let Base64Type = class Base64Type {
|
|
|
10
10
|
if (attributes)
|
|
11
11
|
Object.assign(this, attributes);
|
|
12
12
|
}
|
|
13
|
-
[constants_js_1.DECODER]() {
|
|
14
|
-
|
|
13
|
+
[constants_js_1.DECODER](properties) {
|
|
14
|
+
const fn = valgen_1.vg.isBase64({ coerce: true });
|
|
15
|
+
if (properties.convertToNative)
|
|
16
|
+
return valgen_1.vg.pipe([fn, toBuffer], { coerce: true });
|
|
17
|
+
return fn;
|
|
15
18
|
}
|
|
16
19
|
[constants_js_1.ENCODER]() {
|
|
17
|
-
return
|
|
20
|
+
return fromBuffer;
|
|
18
21
|
}
|
|
19
22
|
};
|
|
20
23
|
exports.Base64Type = Base64Type;
|
|
@@ -29,3 +32,13 @@ exports.Base64Type = Base64Type = tslib_1.__decorate([
|
|
|
29
32
|
}),
|
|
30
33
|
tslib_1.__metadata("design:paramtypes", [Object])
|
|
31
34
|
], Base64Type);
|
|
35
|
+
const toBuffer = (0, valgen_1.validator)((base64String) => {
|
|
36
|
+
return Buffer.from(base64String, 'base64');
|
|
37
|
+
});
|
|
38
|
+
const fromBuffer = (0, valgen_1.validator)((input) => {
|
|
39
|
+
if (Buffer.isBuffer(input))
|
|
40
|
+
return input.toString('base64');
|
|
41
|
+
else {
|
|
42
|
+
return (0, valgen_1.isBase64)(input);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DateTimeTypeTz = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const valgen_1 = require("valgen");
|
|
6
|
+
const constants_js_1 = require("../../constants.js");
|
|
7
|
+
const simple_type_js_1 = require("../simple-type.js");
|
|
8
|
+
const _isDateString = valgen_1.vg.isDateString({
|
|
9
|
+
precisionMin: 'tz',
|
|
10
|
+
coerce: true,
|
|
11
|
+
});
|
|
12
|
+
let DateTimeTypeTz = class DateTimeTypeTz {
|
|
13
|
+
constructor(attributes) {
|
|
14
|
+
if (attributes)
|
|
15
|
+
Object.assign(this, attributes);
|
|
16
|
+
}
|
|
17
|
+
[constants_js_1.DECODER](properties) {
|
|
18
|
+
const fn = valgen_1.vg.isDateString({
|
|
19
|
+
coerce: true,
|
|
20
|
+
precisionMin: 'tz',
|
|
21
|
+
});
|
|
22
|
+
const x = [];
|
|
23
|
+
if (properties.minValue != null) {
|
|
24
|
+
_isDateString(properties.minValue);
|
|
25
|
+
x.push(valgen_1.toString, valgen_1.vg.isGte(properties.minValue));
|
|
26
|
+
}
|
|
27
|
+
if (properties.maxValue != null) {
|
|
28
|
+
_isDateString(properties.maxValue);
|
|
29
|
+
x.push(valgen_1.toString, valgen_1.vg.isLte(properties.maxValue));
|
|
30
|
+
}
|
|
31
|
+
return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
|
|
32
|
+
}
|
|
33
|
+
[constants_js_1.ENCODER](properties) {
|
|
34
|
+
const x = [];
|
|
35
|
+
if (properties.minValue != null) {
|
|
36
|
+
(0, valgen_1.isDateString)(properties.minValue);
|
|
37
|
+
x.push(valgen_1.vg.isGte(properties.minValue));
|
|
38
|
+
}
|
|
39
|
+
if (properties.maxValue != null) {
|
|
40
|
+
(0, valgen_1.isDateString)(properties.maxValue);
|
|
41
|
+
x.push(valgen_1.vg.isLte(properties.maxValue));
|
|
42
|
+
}
|
|
43
|
+
return x.length > 0
|
|
44
|
+
? valgen_1.vg.pipe([_isDateString, ...x], { returnIndex: 0 })
|
|
45
|
+
: _isDateString;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
exports.DateTimeTypeTz = DateTimeTypeTz;
|
|
49
|
+
tslib_1.__decorate([
|
|
50
|
+
simple_type_js_1.SimpleType.Attribute({
|
|
51
|
+
description: 'Minimum value',
|
|
52
|
+
}),
|
|
53
|
+
tslib_1.__metadata("design:type", String)
|
|
54
|
+
], DateTimeTypeTz.prototype, "minValue", void 0);
|
|
55
|
+
tslib_1.__decorate([
|
|
56
|
+
simple_type_js_1.SimpleType.Attribute({
|
|
57
|
+
description: 'Maximum value',
|
|
58
|
+
}),
|
|
59
|
+
tslib_1.__metadata("design:type", String)
|
|
60
|
+
], DateTimeTypeTz.prototype, "maxValue", void 0);
|
|
61
|
+
exports.DateTimeTypeTz = DateTimeTypeTz = tslib_1.__decorate([
|
|
62
|
+
((0, simple_type_js_1.SimpleType)({
|
|
63
|
+
name: 'datetimetz',
|
|
64
|
+
description: 'A full datetime value with time zone information',
|
|
65
|
+
nameMappings: {
|
|
66
|
+
js: 'string',
|
|
67
|
+
json: 'string',
|
|
68
|
+
},
|
|
69
|
+
}).Example('2021-04-18T22:30:15+03:00')),
|
|
70
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
71
|
+
], DateTimeTypeTz);
|
|
@@ -5,30 +5,32 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const valgen_1 = require("valgen");
|
|
6
6
|
const constants_js_1 = require("../../constants.js");
|
|
7
7
|
const simple_type_js_1 = require("../simple-type.js");
|
|
8
|
+
const _isDateString = valgen_1.vg.isDateString({
|
|
9
|
+
precisionMin: 'day',
|
|
10
|
+
coerce: true,
|
|
11
|
+
trim: 'tz',
|
|
12
|
+
});
|
|
8
13
|
let DateTimeType = class DateTimeType {
|
|
9
14
|
constructor(attributes) {
|
|
10
15
|
if (attributes)
|
|
11
16
|
Object.assign(this, attributes);
|
|
12
17
|
}
|
|
13
18
|
[constants_js_1.DECODER](properties) {
|
|
14
|
-
const fn = valgen_1.vg.isDate({
|
|
19
|
+
const fn = valgen_1.vg.isDate({
|
|
20
|
+
coerce: properties?.convertToNative,
|
|
21
|
+
});
|
|
15
22
|
const x = [];
|
|
16
23
|
if (properties.minValue != null) {
|
|
17
|
-
(
|
|
24
|
+
_isDateString(properties.minValue);
|
|
18
25
|
x.push(valgen_1.toString, valgen_1.vg.isGte(properties.minValue));
|
|
19
26
|
}
|
|
20
27
|
if (properties.maxValue != null) {
|
|
21
|
-
(
|
|
28
|
+
_isDateString(properties.maxValue);
|
|
22
29
|
x.push(valgen_1.toString, valgen_1.vg.isLte(properties.maxValue));
|
|
23
30
|
}
|
|
24
31
|
return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
|
|
25
32
|
}
|
|
26
33
|
[constants_js_1.ENCODER](properties) {
|
|
27
|
-
const fn = valgen_1.vg.isDateString({
|
|
28
|
-
precision: 'time',
|
|
29
|
-
trim: 'time',
|
|
30
|
-
coerce: true,
|
|
31
|
-
});
|
|
32
34
|
const x = [];
|
|
33
35
|
if (properties.minValue != null) {
|
|
34
36
|
(0, valgen_1.isDateString)(properties.minValue);
|
|
@@ -38,7 +40,9 @@ let DateTimeType = class DateTimeType {
|
|
|
38
40
|
(0, valgen_1.isDateString)(properties.maxValue);
|
|
39
41
|
x.push(valgen_1.vg.isLte(properties.maxValue));
|
|
40
42
|
}
|
|
41
|
-
return x.length > 0
|
|
43
|
+
return x.length > 0
|
|
44
|
+
? valgen_1.vg.pipe([_isDateString, ...x], { returnIndex: 0 })
|
|
45
|
+
: _isDateString;
|
|
42
46
|
}
|
|
43
47
|
};
|
|
44
48
|
exports.DateTimeType = DateTimeType;
|
|
@@ -5,30 +5,33 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const valgen_1 = require("valgen");
|
|
6
6
|
const constants_js_1 = require("../../constants.js");
|
|
7
7
|
const simple_type_js_1 = require("../simple-type.js");
|
|
8
|
+
const _isDateString = valgen_1.vg.isDateString({
|
|
9
|
+
precisionMin: 'day',
|
|
10
|
+
trim: 'day',
|
|
11
|
+
coerce: true,
|
|
12
|
+
});
|
|
8
13
|
let DateType = class DateType {
|
|
9
14
|
constructor(attributes) {
|
|
10
15
|
if (attributes)
|
|
11
16
|
Object.assign(this, attributes);
|
|
12
17
|
}
|
|
13
18
|
[constants_js_1.DECODER](properties) {
|
|
14
|
-
const fn = valgen_1.vg.isDate({
|
|
19
|
+
const fn = valgen_1.vg.isDate({
|
|
20
|
+
trim: 'day',
|
|
21
|
+
coerce: properties?.convertToNative,
|
|
22
|
+
});
|
|
15
23
|
const x = [];
|
|
16
24
|
if (properties.minValue != null) {
|
|
17
|
-
(
|
|
25
|
+
_isDateString(properties.minValue);
|
|
18
26
|
x.push(valgen_1.toString, valgen_1.vg.isGte(properties.minValue));
|
|
19
27
|
}
|
|
20
28
|
if (properties.maxValue != null) {
|
|
21
|
-
(
|
|
29
|
+
_isDateString(properties.maxValue);
|
|
22
30
|
x.push(valgen_1.toString, valgen_1.vg.isLte(properties.maxValue));
|
|
23
31
|
}
|
|
24
32
|
return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
|
|
25
33
|
}
|
|
26
34
|
[constants_js_1.ENCODER](properties) {
|
|
27
|
-
const fn = valgen_1.vg.isDateString({
|
|
28
|
-
precision: 'date',
|
|
29
|
-
trim: 'date',
|
|
30
|
-
coerce: true,
|
|
31
|
-
});
|
|
32
35
|
const x = [];
|
|
33
36
|
if (properties.minValue != null) {
|
|
34
37
|
(0, valgen_1.isDateString)(properties.minValue);
|
|
@@ -38,7 +41,9 @@ let DateType = class DateType {
|
|
|
38
41
|
(0, valgen_1.isDateString)(properties.maxValue);
|
|
39
42
|
x.push(valgen_1.vg.isLte(properties.maxValue));
|
|
40
43
|
}
|
|
41
|
-
return x.length > 0
|
|
44
|
+
return x.length > 0
|
|
45
|
+
? valgen_1.vg.pipe([_isDateString, ...x], { returnIndex: 0 })
|
|
46
|
+
: _isDateString;
|
|
42
47
|
}
|
|
43
48
|
};
|
|
44
49
|
exports.DateType = DateType;
|
|
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./base64.type.js"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./date.type.js"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./date-string.type.js"), exports);
|
|
7
6
|
tslib_1.__exportStar(require("./date-time.type.js"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./date-time-
|
|
7
|
+
tslib_1.__exportStar(require("./date-time-tz.type.js"), exports);
|
|
9
8
|
tslib_1.__exportStar(require("./email.type.js"), exports);
|
|
10
9
|
tslib_1.__exportStar(require("./field-path.type.js"), exports);
|
|
11
10
|
tslib_1.__exportStar(require("./filter.type.js"), exports);
|
|
12
11
|
tslib_1.__exportStar(require("./object-id.type.js"), exports);
|
|
13
12
|
tslib_1.__exportStar(require("./operation-result.type.js"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./partial-date.type.js"), exports);
|
|
14
14
|
tslib_1.__exportStar(require("./time.type.js"), exports);
|
|
15
15
|
tslib_1.__exportStar(require("./url.type.js"), exports);
|
|
16
16
|
tslib_1.__exportStar(require("./uuid.type.js"), exports);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PartialDateType = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const valgen_1 = require("valgen");
|
|
6
|
+
const constants_js_1 = require("../../constants.js");
|
|
7
|
+
const simple_type_js_1 = require("../simple-type.js");
|
|
8
|
+
let PartialDateType = class PartialDateType {
|
|
9
|
+
constructor(attributes) {
|
|
10
|
+
if (attributes)
|
|
11
|
+
Object.assign(this, attributes);
|
|
12
|
+
}
|
|
13
|
+
[constants_js_1.DECODER](properties) {
|
|
14
|
+
const fn = toPartialDate;
|
|
15
|
+
const x = [];
|
|
16
|
+
if (properties.minValue != null) {
|
|
17
|
+
(0, valgen_1.isDateString)(properties.minValue);
|
|
18
|
+
x.push(valgen_1.toString, valgen_1.vg.isGte(properties.minValue));
|
|
19
|
+
}
|
|
20
|
+
if (properties.maxValue != null) {
|
|
21
|
+
(0, valgen_1.isDateString)(properties.maxValue);
|
|
22
|
+
x.push(valgen_1.toString, valgen_1.vg.isLte(properties.maxValue));
|
|
23
|
+
}
|
|
24
|
+
return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
|
|
25
|
+
}
|
|
26
|
+
[constants_js_1.ENCODER](properties) {
|
|
27
|
+
const fn = toPartialDate;
|
|
28
|
+
const x = [];
|
|
29
|
+
if (properties.minValue != null) {
|
|
30
|
+
(0, valgen_1.isDateString)(properties.minValue);
|
|
31
|
+
x.push(valgen_1.vg.isGte(properties.minValue));
|
|
32
|
+
}
|
|
33
|
+
if (properties.maxValue != null) {
|
|
34
|
+
(0, valgen_1.isDateString)(properties.maxValue);
|
|
35
|
+
x.push(valgen_1.vg.isLte(properties.maxValue));
|
|
36
|
+
}
|
|
37
|
+
return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.PartialDateType = PartialDateType;
|
|
41
|
+
tslib_1.__decorate([
|
|
42
|
+
simple_type_js_1.SimpleType.Attribute({
|
|
43
|
+
description: 'Minimum value',
|
|
44
|
+
}),
|
|
45
|
+
tslib_1.__metadata("design:type", String)
|
|
46
|
+
], PartialDateType.prototype, "minValue", void 0);
|
|
47
|
+
tslib_1.__decorate([
|
|
48
|
+
simple_type_js_1.SimpleType.Attribute({
|
|
49
|
+
description: 'Maximum value',
|
|
50
|
+
}),
|
|
51
|
+
tslib_1.__metadata("design:type", String)
|
|
52
|
+
], PartialDateType.prototype, "maxValue", void 0);
|
|
53
|
+
exports.PartialDateType = PartialDateType = tslib_1.__decorate([
|
|
54
|
+
((0, simple_type_js_1.SimpleType)({
|
|
55
|
+
name: 'partialdate',
|
|
56
|
+
description: 'Specifies a point in time using a 24-hour clock notation.\rFormat: YYYY-[MM-[DD-[T?HH:[MM:[SS[.S[S[S[S]]]]]]]]][+/-ZZ:ZZ].',
|
|
57
|
+
nameMappings: {
|
|
58
|
+
js: 'string',
|
|
59
|
+
json: 'string',
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
.Example('2021-04-18T22:30:15:22+03:00')
|
|
63
|
+
.Example('2021-04-18 22:30')
|
|
64
|
+
.Example('2021-04-18')
|
|
65
|
+
.Example('2021')),
|
|
66
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
67
|
+
], PartialDateType);
|
|
68
|
+
const _isDateString = valgen_1.vg.isDateString({
|
|
69
|
+
precisionMin: 'year',
|
|
70
|
+
});
|
|
71
|
+
const toPartialDate = (0, valgen_1.validator)((input) => {
|
|
72
|
+
if (input instanceof Date) {
|
|
73
|
+
let s = _isDateString(input, { coerce: true });
|
|
74
|
+
if (s.endsWith('Z'))
|
|
75
|
+
s = s.substring(0, s.length - 1);
|
|
76
|
+
if (s.endsWith('.000'))
|
|
77
|
+
s = s.substring(0, s.length - 4);
|
|
78
|
+
if (s.endsWith(':00'))
|
|
79
|
+
s = s.substring(0, s.length - 3);
|
|
80
|
+
if (s.endsWith('00:00'))
|
|
81
|
+
s = s.substring(0, s.length - 6);
|
|
82
|
+
return s;
|
|
83
|
+
}
|
|
84
|
+
return _isDateString(input, { coerce: false });
|
|
85
|
+
});
|
|
@@ -52,6 +52,10 @@ exports.SimpleType = function (...args) {
|
|
|
52
52
|
* @class SimpleType
|
|
53
53
|
*/
|
|
54
54
|
class SimpleTypeClass extends data_type_js_1.DataType {
|
|
55
|
+
extend(properties) {
|
|
56
|
+
Object.setPrototypeOf(properties, this);
|
|
57
|
+
return properties;
|
|
58
|
+
}
|
|
55
59
|
extendsFrom(baseType) {
|
|
56
60
|
if (!(baseType instanceof data_type_js_1.DataType))
|
|
57
61
|
baseType = this.node.getDataType(baseType);
|
|
@@ -19,6 +19,7 @@ function ApiFieldDecoratorFactory(options) {
|
|
|
19
19
|
const designType = Reflect.getMetadata('design:type', target, propertyKey);
|
|
20
20
|
const elemMeta = (metadata.fields[propertyKey] = {
|
|
21
21
|
...options,
|
|
22
|
+
designType,
|
|
22
23
|
});
|
|
23
24
|
if (designType === Array) {
|
|
24
25
|
elemMeta.isArray = true;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ApiDocumentFactory = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const index_js_1 = require("../../helpers/index.js");
|
|
5
6
|
const index_js_2 = require("../../schema/index.js");
|
|
6
7
|
const api_document_js_1 = require("../api-document.js");
|
|
7
8
|
const document_init_context_js_1 = require("../common/document-init-context.js");
|
|
8
9
|
const opra_document_error_js_1 = require("../common/opra-document-error.js");
|
|
9
10
|
const constants_js_1 = require("../constants.js");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
11
|
+
const extendedTypes = tslib_1.__importStar(require("../data-type/extended-types/index.js"));
|
|
12
|
+
const primitiveTypes = tslib_1.__importStar(require("../data-type/primitive-types/index.js"));
|
|
12
13
|
const data_type_factory_js_1 = require("./data-type.factory.js");
|
|
13
14
|
const http_api_factory_js_1 = require("./http-api.factory.js");
|
|
14
15
|
const rpc_api_factory_js_1 = require("./rpc-api.factory.js");
|
|
@@ -157,29 +158,8 @@ class ApiDocumentFactory {
|
|
|
157
158
|
},
|
|
158
159
|
},
|
|
159
160
|
types: [
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
index_js_4.BigintType,
|
|
163
|
-
index_js_4.BooleanType,
|
|
164
|
-
index_js_4.IntegerType,
|
|
165
|
-
index_js_4.NullType,
|
|
166
|
-
index_js_4.NumberType,
|
|
167
|
-
index_js_4.ObjectType,
|
|
168
|
-
index_js_4.StringType,
|
|
169
|
-
// Extended types
|
|
170
|
-
index_js_3.Base64Type,
|
|
171
|
-
index_js_3.DateType,
|
|
172
|
-
index_js_3.DateStringType,
|
|
173
|
-
index_js_3.DateTimeType,
|
|
174
|
-
index_js_3.DateTimeStringType,
|
|
175
|
-
index_js_3.EmailType,
|
|
176
|
-
index_js_3.FieldPathType,
|
|
177
|
-
index_js_3.FilterType,
|
|
178
|
-
index_js_3.ObjectIdType,
|
|
179
|
-
index_js_3.OperationResult,
|
|
180
|
-
index_js_3.TimeType,
|
|
181
|
-
index_js_3.UrlType,
|
|
182
|
-
index_js_3.UuidType,
|
|
161
|
+
...Object.values(primitiveTypes),
|
|
162
|
+
...Object.values(extendedTypes),
|
|
183
163
|
],
|
|
184
164
|
};
|
|
185
165
|
const document = new api_document_js_1.ApiDocument();
|
|
@@ -25,11 +25,6 @@ export const ApiField = function (...args) {
|
|
|
25
25
|
throw new Error('Field origin should be one of ComplexType, MappedType or MixinType');
|
|
26
26
|
}
|
|
27
27
|
_this.origin = origin;
|
|
28
|
-
_this.scopePattern = initArgs.scopePattern
|
|
29
|
-
? Array.isArray(initArgs.scopePattern)
|
|
30
|
-
? initArgs.scopePattern
|
|
31
|
-
: [initArgs.scopePattern]
|
|
32
|
-
: undefined;
|
|
33
28
|
_this.type = initArgs.type || owner.node.getDataType('any');
|
|
34
29
|
_this.description = initArgs.description;
|
|
35
30
|
_this.isArray = initArgs.isArray;
|
|
@@ -45,6 +40,17 @@ export const ApiField = function (...args) {
|
|
|
45
40
|
_this.writeonly = initArgs.writeonly;
|
|
46
41
|
_this.examples = initArgs.examples;
|
|
47
42
|
_this.override = initArgs.override;
|
|
43
|
+
_this.scopePattern = initArgs.scopePattern
|
|
44
|
+
? Array.isArray(initArgs.scopePattern)
|
|
45
|
+
? initArgs.scopePattern
|
|
46
|
+
: [initArgs.scopePattern]
|
|
47
|
+
: undefined;
|
|
48
|
+
_this.convertToNative =
|
|
49
|
+
initArgs.convertToNative ??
|
|
50
|
+
(_this.type.kind === 'SimpleType' &&
|
|
51
|
+
typeof initArgs.designType === 'function' &&
|
|
52
|
+
initArgs.designType !== Object);
|
|
53
|
+
_this.override = initArgs.override;
|
|
48
54
|
};
|
|
49
55
|
/**
|
|
50
56
|
* The ApiFieldClass represents a descriptive metadata structure for API fields,
|
|
@@ -330,6 +330,8 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
330
330
|
let fn = field.type.generateCodec(codec, {
|
|
331
331
|
...context,
|
|
332
332
|
level: context.level + 1,
|
|
333
|
+
}, {
|
|
334
|
+
convertToNative: field.convertToNative,
|
|
333
335
|
});
|
|
334
336
|
if (field.fixed)
|
|
335
337
|
fn = vg.isEqual(field.fixed);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { vg } from 'valgen';
|
|
2
|
+
import { isBase64, validator, vg } from 'valgen';
|
|
3
3
|
import { DECODER, ENCODER } from '../../constants.js';
|
|
4
4
|
import { SimpleType } from '../simple-type.js';
|
|
5
5
|
let Base64Type = class Base64Type {
|
|
@@ -7,11 +7,14 @@ let Base64Type = class Base64Type {
|
|
|
7
7
|
if (attributes)
|
|
8
8
|
Object.assign(this, attributes);
|
|
9
9
|
}
|
|
10
|
-
[DECODER]() {
|
|
11
|
-
|
|
10
|
+
[DECODER](properties) {
|
|
11
|
+
const fn = vg.isBase64({ coerce: true });
|
|
12
|
+
if (properties.convertToNative)
|
|
13
|
+
return vg.pipe([fn, toBuffer], { coerce: true });
|
|
14
|
+
return fn;
|
|
12
15
|
}
|
|
13
16
|
[ENCODER]() {
|
|
14
|
-
return
|
|
17
|
+
return fromBuffer;
|
|
15
18
|
}
|
|
16
19
|
};
|
|
17
20
|
Base64Type = __decorate([
|
|
@@ -26,3 +29,13 @@ Base64Type = __decorate([
|
|
|
26
29
|
__metadata("design:paramtypes", [Object])
|
|
27
30
|
], Base64Type);
|
|
28
31
|
export { Base64Type };
|
|
32
|
+
const toBuffer = validator((base64String) => {
|
|
33
|
+
return Buffer.from(base64String, 'base64');
|
|
34
|
+
});
|
|
35
|
+
const fromBuffer = validator((input) => {
|
|
36
|
+
if (Buffer.isBuffer(input))
|
|
37
|
+
return input.toString('base64');
|
|
38
|
+
else {
|
|
39
|
+
return isBase64(input);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { isDateString, toString, vg } from 'valgen';
|
|
3
|
+
import { DECODER, ENCODER } from '../../constants.js';
|
|
4
|
+
import { SimpleType } from '../simple-type.js';
|
|
5
|
+
const _isDateString = vg.isDateString({
|
|
6
|
+
precisionMin: 'tz',
|
|
7
|
+
coerce: true,
|
|
8
|
+
});
|
|
9
|
+
let DateTimeTypeTz = class DateTimeTypeTz {
|
|
10
|
+
constructor(attributes) {
|
|
11
|
+
if (attributes)
|
|
12
|
+
Object.assign(this, attributes);
|
|
13
|
+
}
|
|
14
|
+
[DECODER](properties) {
|
|
15
|
+
const fn = vg.isDateString({
|
|
16
|
+
coerce: true,
|
|
17
|
+
precisionMin: 'tz',
|
|
18
|
+
});
|
|
19
|
+
const x = [];
|
|
20
|
+
if (properties.minValue != null) {
|
|
21
|
+
_isDateString(properties.minValue);
|
|
22
|
+
x.push(toString, vg.isGte(properties.minValue));
|
|
23
|
+
}
|
|
24
|
+
if (properties.maxValue != null) {
|
|
25
|
+
_isDateString(properties.maxValue);
|
|
26
|
+
x.push(toString, vg.isLte(properties.maxValue));
|
|
27
|
+
}
|
|
28
|
+
return x.length > 0 ? vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
|
|
29
|
+
}
|
|
30
|
+
[ENCODER](properties) {
|
|
31
|
+
const x = [];
|
|
32
|
+
if (properties.minValue != null) {
|
|
33
|
+
isDateString(properties.minValue);
|
|
34
|
+
x.push(vg.isGte(properties.minValue));
|
|
35
|
+
}
|
|
36
|
+
if (properties.maxValue != null) {
|
|
37
|
+
isDateString(properties.maxValue);
|
|
38
|
+
x.push(vg.isLte(properties.maxValue));
|
|
39
|
+
}
|
|
40
|
+
return x.length > 0
|
|
41
|
+
? vg.pipe([_isDateString, ...x], { returnIndex: 0 })
|
|
42
|
+
: _isDateString;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
__decorate([
|
|
46
|
+
SimpleType.Attribute({
|
|
47
|
+
description: 'Minimum value',
|
|
48
|
+
}),
|
|
49
|
+
__metadata("design:type", String)
|
|
50
|
+
], DateTimeTypeTz.prototype, "minValue", void 0);
|
|
51
|
+
__decorate([
|
|
52
|
+
SimpleType.Attribute({
|
|
53
|
+
description: 'Maximum value',
|
|
54
|
+
}),
|
|
55
|
+
__metadata("design:type", String)
|
|
56
|
+
], DateTimeTypeTz.prototype, "maxValue", void 0);
|
|
57
|
+
DateTimeTypeTz = __decorate([
|
|
58
|
+
(SimpleType({
|
|
59
|
+
name: 'datetimetz',
|
|
60
|
+
description: 'A full datetime value with time zone information',
|
|
61
|
+
nameMappings: {
|
|
62
|
+
js: 'string',
|
|
63
|
+
json: 'string',
|
|
64
|
+
},
|
|
65
|
+
}).Example('2021-04-18T22:30:15+03:00')),
|
|
66
|
+
__metadata("design:paramtypes", [Object])
|
|
67
|
+
], DateTimeTypeTz);
|
|
68
|
+
export { DateTimeTypeTz };
|
|
@@ -2,30 +2,32 @@ import { __decorate, __metadata } from "tslib";
|
|
|
2
2
|
import { isDateString, toString, vg } from 'valgen';
|
|
3
3
|
import { DECODER, ENCODER } from '../../constants.js';
|
|
4
4
|
import { SimpleType } from '../simple-type.js';
|
|
5
|
+
const _isDateString = vg.isDateString({
|
|
6
|
+
precisionMin: 'day',
|
|
7
|
+
coerce: true,
|
|
8
|
+
trim: 'tz',
|
|
9
|
+
});
|
|
5
10
|
let DateTimeType = class DateTimeType {
|
|
6
11
|
constructor(attributes) {
|
|
7
12
|
if (attributes)
|
|
8
13
|
Object.assign(this, attributes);
|
|
9
14
|
}
|
|
10
15
|
[DECODER](properties) {
|
|
11
|
-
const fn = vg.isDate({
|
|
16
|
+
const fn = vg.isDate({
|
|
17
|
+
coerce: properties?.convertToNative,
|
|
18
|
+
});
|
|
12
19
|
const x = [];
|
|
13
20
|
if (properties.minValue != null) {
|
|
14
|
-
|
|
21
|
+
_isDateString(properties.minValue);
|
|
15
22
|
x.push(toString, vg.isGte(properties.minValue));
|
|
16
23
|
}
|
|
17
24
|
if (properties.maxValue != null) {
|
|
18
|
-
|
|
25
|
+
_isDateString(properties.maxValue);
|
|
19
26
|
x.push(toString, vg.isLte(properties.maxValue));
|
|
20
27
|
}
|
|
21
28
|
return x.length > 0 ? vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
|
|
22
29
|
}
|
|
23
30
|
[ENCODER](properties) {
|
|
24
|
-
const fn = vg.isDateString({
|
|
25
|
-
precision: 'time',
|
|
26
|
-
trim: 'time',
|
|
27
|
-
coerce: true,
|
|
28
|
-
});
|
|
29
31
|
const x = [];
|
|
30
32
|
if (properties.minValue != null) {
|
|
31
33
|
isDateString(properties.minValue);
|
|
@@ -35,7 +37,9 @@ let DateTimeType = class DateTimeType {
|
|
|
35
37
|
isDateString(properties.maxValue);
|
|
36
38
|
x.push(vg.isLte(properties.maxValue));
|
|
37
39
|
}
|
|
38
|
-
return x.length > 0
|
|
40
|
+
return x.length > 0
|
|
41
|
+
? vg.pipe([_isDateString, ...x], { returnIndex: 0 })
|
|
42
|
+
: _isDateString;
|
|
39
43
|
}
|
|
40
44
|
};
|
|
41
45
|
__decorate([
|