@opra/common 1.22.5 → 1.22.6
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 +5 -5
- package/document/common/data-type-map.js +5 -2
- package/document/data-type/extended-types/date-time.type.d.ts +3 -1
- package/document/data-type/extended-types/date-time.type.js +29 -16
- package/document/data-type/extended-types/date.type.js +2 -1
- package/document/data-type/extended-types/index.d.ts +0 -1
- package/document/data-type/extended-types/index.js +0 -1
- package/package.json +2 -2
- package/document/data-type/extended-types/partial-date.type.d.ts +0 -9
- package/document/data-type/extended-types/partial-date.type.js +0 -84
|
@@ -32,8 +32,11 @@ export class DataTypeMap {
|
|
|
32
32
|
const out = this[kMap].get(name);
|
|
33
33
|
if (!out)
|
|
34
34
|
return;
|
|
35
|
-
if (typeof nameOrCtor === 'function' &&
|
|
36
|
-
|
|
35
|
+
if (typeof nameOrCtor === 'function' &&
|
|
36
|
+
out.kind === 'ComplexType' &&
|
|
37
|
+
out.ctor !== nameOrCtor) {
|
|
38
|
+
throw new TypeError(`An other data type with same class (${nameOrCtor.name}) already exists.`);
|
|
39
|
+
}
|
|
37
40
|
return out;
|
|
38
41
|
}
|
|
39
42
|
set(name, dataType) {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Type } from 'ts-gems';
|
|
2
|
-
import { type Validator } from 'valgen';
|
|
2
|
+
import { type DatePrecision, type Validator } from 'valgen';
|
|
3
3
|
import { DECODER, ENCODER } from '../../constants.js';
|
|
4
4
|
export declare class DateTimeType {
|
|
5
5
|
designType?: Type;
|
|
6
6
|
constructor(attributes?: Partial<DateTimeType>);
|
|
7
|
+
precisionMin?: DatePrecision;
|
|
8
|
+
precisionMax?: DatePrecision;
|
|
7
9
|
protected [DECODER](properties: Partial<this>): Validator;
|
|
8
10
|
protected [ENCODER](properties: Partial<this>): Validator;
|
|
9
11
|
minValue?: string;
|
|
@@ -2,27 +2,26 @@ import { __decorate, __metadata } from "tslib";
|
|
|
2
2
|
import { 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
|
-
trim: 'tz',
|
|
8
|
-
coerce: true,
|
|
9
|
-
});
|
|
10
|
-
const _isDate = vg.isDate({
|
|
11
|
-
coerce: true,
|
|
12
|
-
});
|
|
13
5
|
let DateTimeType = class DateTimeType {
|
|
14
6
|
designType;
|
|
15
7
|
constructor(attributes) {
|
|
16
8
|
if (attributes)
|
|
17
9
|
Object.assign(this, attributes);
|
|
18
10
|
}
|
|
11
|
+
precisionMin;
|
|
12
|
+
precisionMax;
|
|
19
13
|
[DECODER](properties) {
|
|
20
14
|
let fn;
|
|
21
15
|
if (properties.designType === Date) {
|
|
22
|
-
fn =
|
|
16
|
+
fn = vg.isDate({ coerce: true });
|
|
23
17
|
}
|
|
24
18
|
else {
|
|
25
|
-
fn =
|
|
19
|
+
fn = vg.isDateString({
|
|
20
|
+
precisionMin: properties.precisionMin || 'day',
|
|
21
|
+
precisionMax: properties.precisionMax || 'ms',
|
|
22
|
+
trim: true,
|
|
23
|
+
coerce: true,
|
|
24
|
+
});
|
|
26
25
|
}
|
|
27
26
|
const x = [fn];
|
|
28
27
|
if (properties.minValue != null) {
|
|
@@ -34,7 +33,12 @@ let DateTimeType = class DateTimeType {
|
|
|
34
33
|
return x.length > 0 ? vg.pipe(x, { returnIndex: 0 }) : fn;
|
|
35
34
|
}
|
|
36
35
|
[ENCODER](properties) {
|
|
37
|
-
const fn =
|
|
36
|
+
const fn = vg.isDateString({
|
|
37
|
+
precisionMin: properties.precisionMin || 'day',
|
|
38
|
+
precisionMax: properties.precisionMax || 'ms',
|
|
39
|
+
trim: true,
|
|
40
|
+
coerce: true,
|
|
41
|
+
});
|
|
38
42
|
const x = [fn];
|
|
39
43
|
if (properties.minValue != null) {
|
|
40
44
|
x.push(vg.isGte(fn(properties.minValue)));
|
|
@@ -47,6 +51,18 @@ let DateTimeType = class DateTimeType {
|
|
|
47
51
|
minValue;
|
|
48
52
|
maxValue;
|
|
49
53
|
};
|
|
54
|
+
__decorate([
|
|
55
|
+
SimpleType.Attribute({
|
|
56
|
+
description: 'Determines the minimum precision, e.g. "year", "month", "hours", "minutes", "seconds" etc. Defaults to "day".',
|
|
57
|
+
}),
|
|
58
|
+
__metadata("design:type", String)
|
|
59
|
+
], DateTimeType.prototype, "precisionMin", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
SimpleType.Attribute({
|
|
62
|
+
description: 'Determines the minimum precision, e.g. "year", "month", "hours", "minutes", "seconds" etc. Defaults to "ms".',
|
|
63
|
+
}),
|
|
64
|
+
__metadata("design:type", String)
|
|
65
|
+
], DateTimeType.prototype, "precisionMax", void 0);
|
|
50
66
|
__decorate([
|
|
51
67
|
SimpleType.Attribute({
|
|
52
68
|
description: 'Minimum value',
|
|
@@ -60,17 +76,14 @@ __decorate([
|
|
|
60
76
|
__metadata("design:type", String)
|
|
61
77
|
], DateTimeType.prototype, "maxValue", void 0);
|
|
62
78
|
DateTimeType = __decorate([
|
|
63
|
-
|
|
79
|
+
SimpleType({
|
|
64
80
|
name: 'datetime',
|
|
65
81
|
description: 'A full datetime value',
|
|
66
82
|
nameMappings: {
|
|
67
83
|
js: 'string',
|
|
68
84
|
json: 'string',
|
|
69
85
|
},
|
|
70
|
-
})
|
|
71
|
-
.Example('2021-04-18T22:30:15')
|
|
72
|
-
.Example('2021-04-18 22:30:15')
|
|
73
|
-
.Example('2021-04-18 22:30')),
|
|
86
|
+
}),
|
|
74
87
|
__metadata("design:paramtypes", [Object])
|
|
75
88
|
], DateTimeType);
|
|
76
89
|
export { DateTimeType };
|
|
@@ -4,7 +4,8 @@ import { DECODER, ENCODER } from '../../constants.js';
|
|
|
4
4
|
import { SimpleType } from '../simple-type.js';
|
|
5
5
|
const _isDateString = vg.isDateString({
|
|
6
6
|
precisionMin: 'day',
|
|
7
|
-
|
|
7
|
+
precisionMax: 'day',
|
|
8
|
+
trim: true,
|
|
8
9
|
coerce: true,
|
|
9
10
|
});
|
|
10
11
|
const _isDate = vg.isDate({
|
|
@@ -7,7 +7,6 @@ export * from './field-path.type.js';
|
|
|
7
7
|
export * from './filter.type.js';
|
|
8
8
|
export * from './object-id.type.js';
|
|
9
9
|
export * from './operation-result.type.js';
|
|
10
|
-
export * from './partial-date.type.js';
|
|
11
10
|
export * from './time.type.js';
|
|
12
11
|
export * from './url.type.js';
|
|
13
12
|
export * from './uuid.type.js';
|
|
@@ -7,7 +7,6 @@ export * from './field-path.type.js';
|
|
|
7
7
|
export * from './filter.type.js';
|
|
8
8
|
export * from './object-id.type.js';
|
|
9
9
|
export * from './operation-result.type.js';
|
|
10
|
-
export * from './partial-date.type.js';
|
|
11
10
|
export * from './time.type.js';
|
|
12
11
|
export * from './url.type.js';
|
|
13
12
|
export * from './uuid.type.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/common",
|
|
3
|
-
"version": "1.22.
|
|
3
|
+
"version": "1.22.6",
|
|
4
4
|
"description": "Opra common package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"super-fast-md5": "^1.0.3",
|
|
20
20
|
"tslib": "^2.8.1",
|
|
21
21
|
"uid": "^2.0.2",
|
|
22
|
-
"valgen": "^5.
|
|
22
|
+
"valgen": "^5.19.3"
|
|
23
23
|
},
|
|
24
24
|
"type": "module",
|
|
25
25
|
"module": "./index.js",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type Validator } from 'valgen';
|
|
2
|
-
import { DECODER, ENCODER } from '../../constants.js';
|
|
3
|
-
export declare class PartialDateType {
|
|
4
|
-
constructor(attributes?: Partial<PartialDateType>);
|
|
5
|
-
protected [DECODER](properties: Partial<this>): Validator;
|
|
6
|
-
protected [ENCODER](properties: Partial<this>): Validator;
|
|
7
|
-
minValue?: string;
|
|
8
|
-
maxValue?: string;
|
|
9
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { isDateString, toString, validator, vg } from 'valgen';
|
|
3
|
-
import { DECODER, ENCODER } from '../../constants.js';
|
|
4
|
-
import { SimpleType } from '../simple-type.js';
|
|
5
|
-
let PartialDateType = class PartialDateType {
|
|
6
|
-
constructor(attributes) {
|
|
7
|
-
if (attributes)
|
|
8
|
-
Object.assign(this, attributes);
|
|
9
|
-
}
|
|
10
|
-
[DECODER](properties) {
|
|
11
|
-
const fn = toPartialDate;
|
|
12
|
-
const x = [];
|
|
13
|
-
if (properties.minValue != null) {
|
|
14
|
-
isDateString(properties.minValue);
|
|
15
|
-
x.push(toString, vg.isGte(properties.minValue));
|
|
16
|
-
}
|
|
17
|
-
if (properties.maxValue != null) {
|
|
18
|
-
isDateString(properties.maxValue);
|
|
19
|
-
x.push(toString, vg.isLte(properties.maxValue));
|
|
20
|
-
}
|
|
21
|
-
return x.length > 0 ? vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
|
|
22
|
-
}
|
|
23
|
-
[ENCODER](properties) {
|
|
24
|
-
const fn = toPartialDate;
|
|
25
|
-
const x = [];
|
|
26
|
-
if (properties.minValue != null) {
|
|
27
|
-
isDateString(properties.minValue);
|
|
28
|
-
x.push(vg.isGte(properties.minValue));
|
|
29
|
-
}
|
|
30
|
-
if (properties.maxValue != null) {
|
|
31
|
-
isDateString(properties.maxValue);
|
|
32
|
-
x.push(vg.isLte(properties.maxValue));
|
|
33
|
-
}
|
|
34
|
-
return x.length > 0 ? vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
|
|
35
|
-
}
|
|
36
|
-
minValue;
|
|
37
|
-
maxValue;
|
|
38
|
-
};
|
|
39
|
-
__decorate([
|
|
40
|
-
SimpleType.Attribute({
|
|
41
|
-
description: 'Minimum value',
|
|
42
|
-
}),
|
|
43
|
-
__metadata("design:type", String)
|
|
44
|
-
], PartialDateType.prototype, "minValue", void 0);
|
|
45
|
-
__decorate([
|
|
46
|
-
SimpleType.Attribute({
|
|
47
|
-
description: 'Maximum value',
|
|
48
|
-
}),
|
|
49
|
-
__metadata("design:type", String)
|
|
50
|
-
], PartialDateType.prototype, "maxValue", void 0);
|
|
51
|
-
PartialDateType = __decorate([
|
|
52
|
-
(SimpleType({
|
|
53
|
-
name: 'partialdate',
|
|
54
|
-
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].',
|
|
55
|
-
nameMappings: {
|
|
56
|
-
js: 'string',
|
|
57
|
-
json: 'string',
|
|
58
|
-
},
|
|
59
|
-
})
|
|
60
|
-
.Example('2021-04-18T22:30:15:22+03:00')
|
|
61
|
-
.Example('2021-04-18 22:30')
|
|
62
|
-
.Example('2021-04-18')
|
|
63
|
-
.Example('2021')),
|
|
64
|
-
__metadata("design:paramtypes", [Object])
|
|
65
|
-
], PartialDateType);
|
|
66
|
-
export { PartialDateType };
|
|
67
|
-
const _isDateString = vg.isDateString({
|
|
68
|
-
precisionMin: 'year',
|
|
69
|
-
});
|
|
70
|
-
const toPartialDate = validator((input) => {
|
|
71
|
-
if (input instanceof Date) {
|
|
72
|
-
let s = _isDateString(input, { coerce: true });
|
|
73
|
-
if (s.endsWith('Z'))
|
|
74
|
-
s = s.substring(0, s.length - 1);
|
|
75
|
-
if (s.endsWith('.000'))
|
|
76
|
-
s = s.substring(0, s.length - 4);
|
|
77
|
-
if (s.endsWith(':00'))
|
|
78
|
-
s = s.substring(0, s.length - 3);
|
|
79
|
-
if (s.endsWith('00:00'))
|
|
80
|
-
s = s.substring(0, s.length - 6);
|
|
81
|
-
return s;
|
|
82
|
-
}
|
|
83
|
-
return _isDateString(input, { coerce: false });
|
|
84
|
-
});
|