@opra/common 0.18.4 → 0.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.js +1225 -910
- package/cjs/document/api-document.js +55 -38
- package/cjs/document/data-type/api-field.js +5 -5
- package/cjs/document/data-type/builtin/any.type.js +3 -5
- package/cjs/document/data-type/builtin/base64.type.js +5 -28
- package/cjs/document/data-type/builtin/bigint.type.js +7 -25
- package/cjs/document/data-type/builtin/boolean.type.js +5 -18
- package/cjs/document/data-type/builtin/date.type.js +13 -9
- package/cjs/document/data-type/builtin/index.js +3 -1
- package/cjs/document/data-type/builtin/integer.type.js +5 -18
- package/cjs/document/data-type/builtin/number.type.js +5 -23
- package/cjs/document/data-type/builtin/object.type.js +4 -9
- package/cjs/document/data-type/builtin/string.type.js +5 -14
- package/cjs/document/data-type/builtin/time.type.js +11 -23
- package/cjs/document/data-type/builtin/timestamp.type.js +8 -20
- package/cjs/document/data-type/builtin/uuid.type.js +15 -0
- package/cjs/document/data-type/complex-type.js +151 -92
- package/cjs/document/data-type/data-type.js +32 -31
- package/cjs/document/data-type/enum-type.js +49 -43
- package/cjs/document/data-type/mapped-type.js +115 -70
- package/cjs/document/data-type/simple-type.js +46 -45
- package/cjs/document/data-type/union-type.js +69 -36
- package/cjs/document/factory/create-document.js +5 -3
- package/cjs/document/factory/factory.js +23 -20
- package/cjs/document/factory/import-type-class.js +13 -4
- package/cjs/document/resource/collection.js +55 -59
- package/cjs/document/resource/resource.js +10 -21
- package/cjs/document/resource/singleton.js +36 -39
- package/cjs/exception/common-errors/validation.error.js +11 -0
- package/cjs/exception/index.js +2 -1
- package/cjs/exception/{enums/issue-severity.enum.js → issue-severity.enum.js} +1 -1
- package/cjs/exception/opra-exception.js +2 -2
- package/cjs/filter/antlr/OpraFilterLexer.js +1 -1
- package/cjs/filter/antlr/OpraFilterParser.js +1 -1
- package/cjs/filter/errors.js +5 -0
- package/cjs/http/enums/http-headers-codes.enum.js +1 -1
- package/cjs/http/enums/http-status-codes.enum.js +1 -1
- package/cjs/http/http-request-message.js +1 -1
- package/cjs/http/http-response-message.js +1 -1
- package/cjs/schema/data-type/complex-type.interface.js +1 -1
- package/cjs/schema/data-type/enum-type.interface.js +1 -1
- package/cjs/schema/data-type/mapped-type.interface.js +1 -1
- package/cjs/schema/data-type/simple-type.interface.js +1 -1
- package/cjs/schema/data-type/union-type.interface.js +1 -1
- package/cjs/schema/index.js +3 -41
- package/cjs/schema/opra-schema.ns.js +18 -0
- package/cjs/schema/resource/collection.interface.js +1 -1
- package/cjs/schema/resource/container.interface.js +1 -1
- package/cjs/schema/resource/singleton.interface.js +1 -1
- package/esm/document/api-document.js +55 -38
- package/esm/document/data-type/api-field.js +5 -5
- package/esm/document/data-type/builtin/any.type.js +2 -4
- package/esm/document/data-type/builtin/base64.type.js +4 -27
- package/esm/document/data-type/builtin/bigint.type.js +6 -24
- package/esm/document/data-type/builtin/boolean.type.js +4 -17
- package/esm/document/data-type/builtin/date.type.js +12 -8
- package/esm/document/data-type/builtin/index.js +3 -1
- package/esm/document/data-type/builtin/integer.type.js +4 -17
- package/esm/document/data-type/builtin/number.type.js +4 -22
- package/esm/document/data-type/builtin/object.type.js +3 -8
- package/esm/document/data-type/builtin/string.type.js +4 -13
- package/esm/document/data-type/builtin/time.type.js +10 -22
- package/esm/document/data-type/builtin/timestamp.type.js +7 -19
- package/esm/document/data-type/builtin/uuid.type.js +12 -0
- package/esm/document/data-type/complex-type.js +151 -92
- package/esm/document/data-type/data-type.js +31 -31
- package/esm/document/data-type/enum-type.js +49 -43
- package/esm/document/data-type/mapped-type.js +114 -70
- package/esm/document/data-type/simple-type.js +45 -44
- package/esm/document/data-type/union-type.js +68 -36
- package/esm/document/factory/create-document.js +6 -4
- package/esm/document/factory/factory.js +23 -20
- package/esm/document/factory/import-type-class.js +13 -4
- package/esm/document/resource/collection.js +55 -59
- package/esm/document/resource/resource.js +9 -21
- package/esm/document/resource/singleton.js +36 -39
- package/esm/exception/common-errors/validation.error.js +7 -0
- package/esm/exception/index.js +2 -1
- package/esm/exception/opra-exception.js +2 -2
- package/esm/filter/antlr/OpraFilterLexer.js +2 -1
- package/esm/filter/antlr/OpraFilterParser.js +2 -1
- package/esm/filter/errors.js +5 -0
- package/esm/schema/index.js +2 -41
- package/esm/schema/opra-schema.ns.js +15 -0
- package/package.json +5 -3
- package/types/document/api-document.d.ts +3 -2
- package/types/document/data-type/builtin/base64.type.d.ts +0 -4
- package/types/document/data-type/builtin/bigint.type.d.ts +1 -5
- package/types/document/data-type/builtin/boolean.type.d.ts +0 -3
- package/types/document/data-type/builtin/date.type.d.ts +1 -3
- package/types/document/data-type/builtin/index.d.ts +3 -1
- package/types/document/data-type/builtin/integer.type.d.ts +1 -5
- package/types/document/data-type/builtin/number.type.d.ts +0 -4
- package/types/document/data-type/builtin/object.type.d.ts +0 -1
- package/types/document/data-type/builtin/string.type.d.ts +0 -3
- package/types/document/data-type/builtin/time.type.d.ts +1 -6
- package/types/document/data-type/builtin/timestamp.type.d.ts +0 -3
- package/types/document/data-type/builtin/uuid.type.d.ts +2 -0
- package/types/document/data-type/complex-type.d.ts +29 -16
- package/types/document/data-type/data-type.d.ts +19 -15
- package/types/document/data-type/enum-type.d.ts +15 -5
- package/types/document/data-type/mapped-type.d.ts +27 -5
- package/types/document/data-type/simple-type.d.ts +26 -12
- package/types/document/data-type/union-type.d.ts +20 -5
- package/types/document/factory/factory.d.ts +3 -2
- package/types/document/resource/collection.d.ts +11 -9
- package/types/document/resource/resource.d.ts +3 -9
- package/types/document/resource/singleton.d.ts +7 -5
- package/types/exception/common-errors/validation.error.d.ts +4 -0
- package/types/exception/error-issue.d.ts +1 -1
- package/types/exception/index.d.ts +2 -1
- package/types/exception/opra-exception.d.ts +4 -2
- package/types/filter/errors.d.ts +3 -0
- package/types/schema/data-type/enum-type.interface.d.ts +5 -5
- package/types/schema/data-type/simple-type.interface.d.ts +5 -11
- package/types/schema/index.d.ts +2 -51
- package/types/schema/opra-schema.ns.d.ts +15 -0
- package/cjs/document/data-type/builtin/guid.type.js +0 -35
- package/esm/document/data-type/builtin/guid.type.js +0 -32
- package/types/document/data-type/builtin/guid.type.d.ts +0 -7
- /package/esm/exception/{enums/issue-severity.enum.js → issue-severity.enum.js} +0 -0
- /package/types/exception/{enums/issue-severity.enum.d.ts → issue-severity.enum.d.ts} +0 -0
|
@@ -6,9 +6,9 @@ const index_js_2 = require("../helpers/index.js");
|
|
|
6
6
|
const index_js_3 = require("../schema/index.js");
|
|
7
7
|
const constants_js_1 = require("./constants.js");
|
|
8
8
|
const complex_type_js_1 = require("./data-type/complex-type.js");
|
|
9
|
-
const simple_type_js_1 = require("./data-type/simple-type.js");
|
|
10
9
|
class ApiDocument {
|
|
11
10
|
constructor() {
|
|
11
|
+
this._designCtorMap = new Map();
|
|
12
12
|
this._typeCache = new index_js_2.ResponsiveMap();
|
|
13
13
|
this._typesCacheByCtor = new Map();
|
|
14
14
|
this.references = new index_js_2.ResponsiveMap();
|
|
@@ -18,59 +18,81 @@ class ApiDocument {
|
|
|
18
18
|
version: '',
|
|
19
19
|
title: ''
|
|
20
20
|
};
|
|
21
|
+
const BigIntConstructor = Object.getPrototypeOf(BigInt(0)).constructor;
|
|
22
|
+
const BufferConstructor = Object.getPrototypeOf(Buffer.from([]));
|
|
23
|
+
this._designCtorMap.set(String, 'string');
|
|
24
|
+
this._designCtorMap.set(Number, 'number');
|
|
25
|
+
this._designCtorMap.set(Boolean, 'boolean');
|
|
26
|
+
this._designCtorMap.set(Object, 'any');
|
|
27
|
+
this._designCtorMap.set(Date, 'timestamp');
|
|
28
|
+
this._designCtorMap.set(BigIntConstructor, 'bigint');
|
|
29
|
+
this._designCtorMap.set(ArrayBuffer, 'base64');
|
|
30
|
+
this._designCtorMap.set(SharedArrayBuffer, 'base64');
|
|
31
|
+
this._designCtorMap.set(BufferConstructor, 'base64');
|
|
21
32
|
}
|
|
22
|
-
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
getDataType(arg0, silent) {
|
|
23
37
|
let dataType;
|
|
24
|
-
|
|
25
|
-
nameOrCtor = 'any';
|
|
26
|
-
const nameOrCtorName = typeof nameOrCtor === 'function' ? nameOrCtor.name : nameOrCtor;
|
|
38
|
+
const name = typeof arg0 === 'function' ? arg0.name : arg0;
|
|
27
39
|
// Try to get instance from cache
|
|
28
|
-
const t = typeof
|
|
29
|
-
? this._typeCache.get(
|
|
30
|
-
: this._typesCacheByCtor.get(
|
|
40
|
+
const t = typeof arg0 === 'string'
|
|
41
|
+
? this._typeCache.get(arg0)
|
|
42
|
+
: this._typesCacheByCtor.get(arg0);
|
|
31
43
|
if (t)
|
|
32
44
|
return t;
|
|
45
|
+
// If cached as null, it means "not found"
|
|
33
46
|
if (t === null) {
|
|
34
47
|
if (silent)
|
|
35
48
|
return;
|
|
36
|
-
throw new
|
|
49
|
+
throw new Error(`Data type "${name}" does not exists`);
|
|
37
50
|
}
|
|
38
|
-
|
|
39
|
-
|
|
51
|
+
// Convert design ctor to type name (String -> 'string')
|
|
52
|
+
if (typeof arg0 === 'function') {
|
|
53
|
+
const x = this._designCtorMap.get(arg0);
|
|
54
|
+
if (x)
|
|
55
|
+
arg0 = x;
|
|
56
|
+
}
|
|
57
|
+
if (typeof arg0 === 'string') {
|
|
58
|
+
const m = constants_js_1.NAMESPACE_PATTERN.exec(arg0);
|
|
40
59
|
if (!m)
|
|
41
|
-
throw new
|
|
60
|
+
throw new TypeError(`Invalid data type name "${name}"`);
|
|
42
61
|
// If given string has namespace pattern (ns:type_name)
|
|
43
62
|
if (m[2]) {
|
|
44
63
|
const ref = this.references.get(m[1]);
|
|
45
64
|
if (!ref) {
|
|
46
65
|
if (silent)
|
|
47
66
|
return;
|
|
48
|
-
throw new
|
|
67
|
+
throw new Error(`No referenced document found for given namespace "${m[1]}"`);
|
|
49
68
|
}
|
|
50
|
-
dataType = ref.getDataType(m[2]);
|
|
51
|
-
this._typeCache.set(nameOrCtor, dataType);
|
|
69
|
+
dataType = ref.getDataType(m[2], silent);
|
|
52
70
|
}
|
|
53
71
|
else {
|
|
54
|
-
const name = m[1];
|
|
55
72
|
// Get instance from own types
|
|
56
|
-
dataType = this.types.get(
|
|
73
|
+
dataType = this.types.get(arg0);
|
|
57
74
|
// if not found, search in references (from last to first)
|
|
58
75
|
if (!dataType) {
|
|
59
76
|
const references = Array.from(this.references.values()).reverse();
|
|
60
77
|
for (const ref of references) {
|
|
61
|
-
dataType = ref.getDataType(name);
|
|
78
|
+
dataType = ref.getDataType(name, true);
|
|
62
79
|
if (dataType)
|
|
63
80
|
break;
|
|
64
81
|
}
|
|
65
82
|
}
|
|
66
|
-
if (dataType)
|
|
67
|
-
this._typeCache.set(dataType.name || name, dataType);
|
|
68
83
|
}
|
|
84
|
+
if (dataType) {
|
|
85
|
+
this._typeCache.set(arg0, dataType);
|
|
86
|
+
return dataType;
|
|
87
|
+
}
|
|
88
|
+
if (!silent)
|
|
89
|
+
throw new index_js_1.NotFoundError(`Data type "${arg0}" does not exists`);
|
|
90
|
+
return;
|
|
69
91
|
}
|
|
70
|
-
|
|
92
|
+
if (typeof arg0 === 'function') {
|
|
71
93
|
const types = Array.from(this.types.values()).reverse();
|
|
72
94
|
for (const dt of types) {
|
|
73
|
-
if (
|
|
95
|
+
if (dt instanceof complex_type_js_1.ComplexType && dt.isTypeOf(arg0)) {
|
|
74
96
|
dataType = dt;
|
|
75
97
|
break;
|
|
76
98
|
}
|
|
@@ -79,27 +101,22 @@ class ApiDocument {
|
|
|
79
101
|
if (!dataType) {
|
|
80
102
|
const references = Array.from(this.references.values()).reverse();
|
|
81
103
|
for (const ref of references) {
|
|
82
|
-
dataType = ref.getDataType(
|
|
104
|
+
dataType = ref.getDataType(arg0, true);
|
|
83
105
|
if (dataType)
|
|
84
106
|
break;
|
|
85
107
|
}
|
|
86
108
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
if (typeof nameOrCtor === 'string')
|
|
96
|
-
this._typeCache.set(nameOrCtor, null);
|
|
97
|
-
else
|
|
98
|
-
this._typesCacheByCtor.set(nameOrCtor, null);
|
|
99
|
-
}
|
|
100
|
-
if (silent)
|
|
109
|
+
if (dataType)
|
|
110
|
+
this._typesCacheByCtor.set(arg0, dataType);
|
|
111
|
+
if (dataType)
|
|
112
|
+
return dataType;
|
|
113
|
+
if (!silent)
|
|
114
|
+
throw new index_js_1.NotFoundError(`No data type mapping found for class "${name}"`);
|
|
101
115
|
return;
|
|
102
|
-
|
|
116
|
+
}
|
|
117
|
+
/* istanbul ignore next */
|
|
118
|
+
if (!silent)
|
|
119
|
+
throw new TypeError('Invalid argument');
|
|
103
120
|
}
|
|
104
121
|
getComplexType(nameOrCtor, silent) {
|
|
105
122
|
if (nameOrCtor === Object)
|
|
@@ -19,14 +19,15 @@ exports.ApiField = function (...args) {
|
|
|
19
19
|
metadata.kind = index_js_2.OpraSchema.ComplexType.Kind;
|
|
20
20
|
metadata.fields = metadata.fields || {};
|
|
21
21
|
const designType = Reflect.getMetadata('design:type', target, propertyKey);
|
|
22
|
-
const isArray = designType === Array;
|
|
23
22
|
const elemMeta = metadata.fields[propertyKey] = {
|
|
24
23
|
...options,
|
|
25
24
|
enum: undefined,
|
|
26
|
-
designType
|
|
25
|
+
designType
|
|
27
26
|
};
|
|
28
|
-
if (designType === Array)
|
|
27
|
+
if (designType === Array) {
|
|
29
28
|
elemMeta.isArray = true;
|
|
29
|
+
delete elemMeta.designType;
|
|
30
|
+
}
|
|
30
31
|
if (options?.enum) {
|
|
31
32
|
elemMeta.type = undefined;
|
|
32
33
|
if (Array.isArray(options.enum)) {
|
|
@@ -69,7 +70,7 @@ exports.ApiField = function (...args) {
|
|
|
69
70
|
};
|
|
70
71
|
const proto = {
|
|
71
72
|
exportSchema() {
|
|
72
|
-
|
|
73
|
+
return {
|
|
73
74
|
type: this.type.name ? this.type.name : this.type.exportSchema(),
|
|
74
75
|
description: this.description,
|
|
75
76
|
isArray: this.isArray,
|
|
@@ -77,7 +78,6 @@ const proto = {
|
|
|
77
78
|
fixed: this.fixed,
|
|
78
79
|
required: this.required
|
|
79
80
|
};
|
|
80
|
-
return out;
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
Object.assign(exports.ApiField.prototype, proto);
|
|
@@ -3,12 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AnyType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const simple_type_js_1 = require("../simple-type.js");
|
|
6
|
-
let AnyType = class AnyType {
|
|
6
|
+
let AnyType = exports.AnyType = class AnyType {
|
|
7
7
|
};
|
|
8
|
-
AnyType = tslib_1.__decorate([
|
|
8
|
+
exports.AnyType = AnyType = tslib_1.__decorate([
|
|
9
9
|
(0, simple_type_js_1.SimpleType)({
|
|
10
|
-
description: '
|
|
11
|
-
ctor: Object
|
|
10
|
+
description: 'Represents any value'
|
|
12
11
|
})
|
|
13
12
|
], AnyType);
|
|
14
|
-
exports.AnyType = AnyType;
|
|
@@ -2,37 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Base64Type = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const valgen_1 = require("valgen");
|
|
5
6
|
const simple_type_js_1 = require("../simple-type.js");
|
|
6
|
-
|
|
7
|
-
let Base64Type = class Base64Type {
|
|
8
|
-
decode(v) {
|
|
9
|
-
if (v == null)
|
|
10
|
-
return v;
|
|
11
|
-
if (typeof v === 'string')
|
|
12
|
-
this.validate(v);
|
|
13
|
-
return Buffer.from(v, 'base64').buffer.slice(0);
|
|
14
|
-
}
|
|
15
|
-
encode(v) {
|
|
16
|
-
if (v == null)
|
|
17
|
-
return v;
|
|
18
|
-
if (Buffer.isBuffer(v))
|
|
19
|
-
return v.toString('base64');
|
|
20
|
-
return Buffer.from(v).toString('base64');
|
|
21
|
-
}
|
|
22
|
-
coerce(v) {
|
|
23
|
-
if (v instanceof ArrayBuffer)
|
|
24
|
-
return v;
|
|
25
|
-
return this.decode(v);
|
|
26
|
-
}
|
|
27
|
-
validate(v) {
|
|
28
|
-
if (!(typeof v === 'string' && BASE64_PATTERN.test(v)))
|
|
29
|
-
throw new TypeError(`Invalid base64 value "${String(v).substring(0, 10)}..."`);
|
|
30
|
-
}
|
|
7
|
+
let Base64Type = exports.Base64Type = class Base64Type {
|
|
31
8
|
};
|
|
32
|
-
Base64Type = tslib_1.__decorate([
|
|
9
|
+
exports.Base64Type = Base64Type = tslib_1.__decorate([
|
|
33
10
|
(0, simple_type_js_1.SimpleType)({
|
|
34
11
|
description: 'A stream of bytes, base64 encoded',
|
|
35
|
-
|
|
12
|
+
decoder: (0, valgen_1.isBase64)(),
|
|
13
|
+
encoder: (0, valgen_1.isBase64)(),
|
|
36
14
|
})
|
|
37
15
|
], Base64Type);
|
|
38
|
-
exports.Base64Type = Base64Type;
|
|
@@ -1,33 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.BigintType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const valgen_1 = require("valgen");
|
|
5
6
|
const simple_type_js_1 = require("../simple-type.js");
|
|
6
|
-
|
|
7
|
-
let BigIntType = class BigIntType {
|
|
8
|
-
decode(v) {
|
|
9
|
-
if (v == null)
|
|
10
|
-
return v;
|
|
11
|
-
return typeof v === 'bigint' ? v : BigInt(v);
|
|
12
|
-
}
|
|
13
|
-
encode(v) {
|
|
14
|
-
if (v == null)
|
|
15
|
-
return v;
|
|
16
|
-
return typeof v === 'bigint' ? String(v) : undefined;
|
|
17
|
-
}
|
|
18
|
-
coerce(v) {
|
|
19
|
-
return this.decode(v);
|
|
20
|
-
}
|
|
21
|
-
validate(v) {
|
|
22
|
-
if (!((typeof v === 'number' && !isNaN(v)) || typeof v === 'bigint'))
|
|
23
|
-
throw new TypeError(`Invalid number value "${v}"`);
|
|
24
|
-
}
|
|
7
|
+
let BigintType = exports.BigintType = class BigintType {
|
|
25
8
|
};
|
|
26
|
-
|
|
9
|
+
exports.BigintType = BigintType = tslib_1.__decorate([
|
|
27
10
|
(0, simple_type_js_1.SimpleType)({
|
|
28
|
-
name: 'bigint',
|
|
29
11
|
description: 'BigInt number',
|
|
30
|
-
|
|
12
|
+
decoder: (0, valgen_1.isBigint)(),
|
|
13
|
+
encoder: (0, valgen_1.pipe)((0, valgen_1.isBigint)(), (0, valgen_1.isString)())
|
|
31
14
|
})
|
|
32
|
-
],
|
|
33
|
-
exports.BigIntType = BigIntType;
|
|
15
|
+
], BigintType);
|
|
@@ -2,27 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BooleanType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const valgen_1 = require("valgen");
|
|
6
6
|
const simple_type_js_1 = require("../simple-type.js");
|
|
7
|
-
let BooleanType = class BooleanType {
|
|
8
|
-
decode(v) {
|
|
9
|
-
if (v == null)
|
|
10
|
-
return v;
|
|
11
|
-
return (0, putil_varhelpers_1.toBoolean)(v);
|
|
12
|
-
}
|
|
13
|
-
encode(v) {
|
|
14
|
-
if (v == null)
|
|
15
|
-
return v;
|
|
16
|
-
return (0, putil_varhelpers_1.toBoolean)(v);
|
|
17
|
-
}
|
|
18
|
-
coerce(v) {
|
|
19
|
-
return this.decode(v);
|
|
20
|
-
}
|
|
7
|
+
let BooleanType = exports.BooleanType = class BooleanType {
|
|
21
8
|
};
|
|
22
|
-
BooleanType = tslib_1.__decorate([
|
|
9
|
+
exports.BooleanType = BooleanType = tslib_1.__decorate([
|
|
23
10
|
(0, simple_type_js_1.SimpleType)({
|
|
24
11
|
description: 'Simple true/false value',
|
|
25
|
-
|
|
12
|
+
decoder: (0, valgen_1.isBoolean)(),
|
|
13
|
+
encoder: (0, valgen_1.isBoolean)()
|
|
26
14
|
})
|
|
27
15
|
], BooleanType);
|
|
28
|
-
exports.BooleanType = BooleanType;
|
|
@@ -2,17 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DateType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const valgen_1 = require("valgen");
|
|
5
6
|
const simple_type_js_1 = require("../simple-type.js");
|
|
6
|
-
|
|
7
|
-
let DateType = class DateType extends timestamp_type_js_1.TimestampType {
|
|
8
|
-
constructor() {
|
|
9
|
-
super(...arguments);
|
|
10
|
-
this.format = 'YYYY-MM-DD';
|
|
11
|
-
}
|
|
7
|
+
let DateType = exports.DateType = class DateType {
|
|
12
8
|
};
|
|
13
|
-
DateType = tslib_1.__decorate([
|
|
9
|
+
exports.DateType = DateType = tslib_1.__decorate([
|
|
14
10
|
(0, simple_type_js_1.SimpleType)({
|
|
15
|
-
description: '
|
|
11
|
+
description: 'Date only string, for example, 2021-04-18',
|
|
12
|
+
decoder: (0, valgen_1.isDate)({
|
|
13
|
+
format: ['YYYY-MM-DD', 'YYYY',
|
|
14
|
+
'YYYY-MM-DDTHH:mm:ss',
|
|
15
|
+
'YYYY-MM-DDTHH:mm',
|
|
16
|
+
'YYYY-MM-DD HH:mm:ss',
|
|
17
|
+
'YYYY-MM-DD HH:mm'
|
|
18
|
+
]
|
|
19
|
+
}),
|
|
20
|
+
encoder: (0, valgen_1.isDateString)({ format: 'YYYY-MM-DD' })
|
|
16
21
|
})
|
|
17
22
|
], DateType);
|
|
18
|
-
exports.DateType = DateType;
|
|
@@ -6,8 +6,10 @@ tslib_1.__exportStar(require("./base64.type.js"), exports);
|
|
|
6
6
|
tslib_1.__exportStar(require("./bigint.type.js"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./boolean.type.js"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./date.type.js"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./
|
|
9
|
+
tslib_1.__exportStar(require("./uuid.type.js"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./integer.type.js"), exports);
|
|
11
11
|
tslib_1.__exportStar(require("./number.type.js"), exports);
|
|
12
12
|
tslib_1.__exportStar(require("./object.type.js"), exports);
|
|
13
13
|
tslib_1.__exportStar(require("./string.type.js"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./time.type.js"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./timestamp.type.js"), exports);
|
|
@@ -2,27 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IntegerType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const valgen_1 = require("valgen");
|
|
6
6
|
const simple_type_js_1 = require("../simple-type.js");
|
|
7
|
-
|
|
8
|
-
let IntegerType = class IntegerType extends number_type_js_1.NumberType {
|
|
9
|
-
decode(v) {
|
|
10
|
-
if (v == null)
|
|
11
|
-
return v;
|
|
12
|
-
return (0, putil_varhelpers_1.toInt)(super.decode(v));
|
|
13
|
-
}
|
|
14
|
-
encode(v) {
|
|
15
|
-
if (v == null)
|
|
16
|
-
return v;
|
|
17
|
-
return (0, putil_varhelpers_1.toInt)(super.encode(v));
|
|
18
|
-
}
|
|
19
|
-
coerce(v) {
|
|
20
|
-
return this.decode(v);
|
|
21
|
-
}
|
|
7
|
+
let IntegerType = exports.IntegerType = class IntegerType {
|
|
22
8
|
};
|
|
23
|
-
IntegerType = tslib_1.__decorate([
|
|
9
|
+
exports.IntegerType = IntegerType = tslib_1.__decorate([
|
|
24
10
|
(0, simple_type_js_1.SimpleType)({
|
|
25
11
|
description: 'An integer number',
|
|
12
|
+
decoder: (0, valgen_1.isInteger)(),
|
|
13
|
+
encoder: (0, valgen_1.isInteger)()
|
|
26
14
|
})
|
|
27
15
|
], IntegerType);
|
|
28
|
-
exports.IntegerType = IntegerType;
|
|
@@ -2,32 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NumberType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const valgen_1 = require("valgen");
|
|
6
6
|
const simple_type_js_1 = require("../simple-type.js");
|
|
7
|
-
let NumberType = class NumberType {
|
|
8
|
-
decode(v) {
|
|
9
|
-
if (v == null)
|
|
10
|
-
return v;
|
|
11
|
-
const x = (0, putil_varhelpers_1.toNumber)(v);
|
|
12
|
-
if (x)
|
|
13
|
-
this.validate(x);
|
|
14
|
-
return x;
|
|
15
|
-
}
|
|
16
|
-
encode(v) {
|
|
17
|
-
return this.decode(v);
|
|
18
|
-
}
|
|
19
|
-
coerce(v) {
|
|
20
|
-
return this.decode(v);
|
|
21
|
-
}
|
|
22
|
-
validate(v) {
|
|
23
|
-
if (typeof v !== 'number' || isNaN(v))
|
|
24
|
-
throw new TypeError(`Invalid number value "${v}"`);
|
|
25
|
-
}
|
|
7
|
+
let NumberType = exports.NumberType = class NumberType {
|
|
26
8
|
};
|
|
27
|
-
NumberType = tslib_1.__decorate([
|
|
9
|
+
exports.NumberType = NumberType = tslib_1.__decorate([
|
|
28
10
|
(0, simple_type_js_1.SimpleType)({
|
|
29
11
|
description: 'Both Integer as well as Floating-Point numbers',
|
|
30
|
-
|
|
12
|
+
decoder: (0, valgen_1.isNumber)(),
|
|
13
|
+
encoder: (0, valgen_1.isNumber)()
|
|
31
14
|
})
|
|
32
15
|
], NumberType);
|
|
33
|
-
exports.NumberType = NumberType;
|
|
@@ -3,18 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ObjectType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const complex_type_js_1 = require("../complex-type.js");
|
|
6
|
-
let ObjectType = class ObjectType {
|
|
7
|
-
coerce(v) {
|
|
8
|
-
if (v == null)
|
|
9
|
-
return v;
|
|
10
|
-
return typeof v === 'object' ? v : {};
|
|
11
|
-
}
|
|
6
|
+
let ObjectType = exports.ObjectType = class ObjectType {
|
|
12
7
|
};
|
|
13
|
-
ObjectType = tslib_1.__decorate([
|
|
8
|
+
exports.ObjectType = ObjectType = tslib_1.__decorate([
|
|
14
9
|
(0, complex_type_js_1.ComplexType)({
|
|
15
10
|
name: 'object',
|
|
16
11
|
description: 'A non modelled object',
|
|
17
|
-
additionalFields: true
|
|
12
|
+
additionalFields: true,
|
|
13
|
+
ctor: Object
|
|
18
14
|
})
|
|
19
15
|
], ObjectType);
|
|
20
|
-
exports.ObjectType = ObjectType;
|
|
@@ -2,23 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StringType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const valgen_1 = require("valgen");
|
|
6
6
|
const simple_type_js_1 = require("../simple-type.js");
|
|
7
|
-
let StringType = class StringType {
|
|
8
|
-
decode(v) {
|
|
9
|
-
return (0, putil_varhelpers_1.toString)(v);
|
|
10
|
-
}
|
|
11
|
-
encode(v) {
|
|
12
|
-
return (0, putil_varhelpers_1.toString)(v);
|
|
13
|
-
}
|
|
14
|
-
coerce(v) {
|
|
15
|
-
return this.decode(v);
|
|
16
|
-
}
|
|
7
|
+
let StringType = exports.StringType = class StringType {
|
|
17
8
|
};
|
|
18
|
-
StringType = tslib_1.__decorate([
|
|
9
|
+
exports.StringType = StringType = tslib_1.__decorate([
|
|
19
10
|
(0, simple_type_js_1.SimpleType)({
|
|
20
11
|
description: 'A sequence of characters',
|
|
21
|
-
|
|
12
|
+
decoder: (0, valgen_1.isString)(),
|
|
13
|
+
encoder: (0, valgen_1.isString)(),
|
|
22
14
|
})
|
|
23
15
|
], StringType);
|
|
24
|
-
exports.StringType = StringType;
|
|
@@ -2,31 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TimeType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const valgen_1 = require("valgen");
|
|
5
6
|
const simple_type_js_1 = require("../simple-type.js");
|
|
6
|
-
|
|
7
|
-
const TIME_PATTERN = /^([01][0-9]|2[0-3]):?([0-5][0-9]):?([0-5][0-9])?(?:\.(\d+))?$/;
|
|
8
|
-
let TimeType = class TimeType extends string_type_js_1.StringType {
|
|
9
|
-
decode(v) {
|
|
10
|
-
if (v == null)
|
|
11
|
-
return v;
|
|
12
|
-
this.validate(v);
|
|
13
|
-
return v;
|
|
14
|
-
}
|
|
15
|
-
encode(v) {
|
|
16
|
-
return this.decode(v);
|
|
17
|
-
}
|
|
18
|
-
coerce(v) {
|
|
19
|
-
return this.decode(v);
|
|
20
|
-
}
|
|
21
|
-
validate(v) {
|
|
22
|
-
// noinspection SuspiciousTypeOfGuard
|
|
23
|
-
if (typeof v === 'string' && !TIME_PATTERN.test(v))
|
|
24
|
-
throw new TypeError(`Invalid Time value "${v}"`);
|
|
25
|
-
}
|
|
7
|
+
let TimeType = exports.TimeType = class TimeType {
|
|
26
8
|
};
|
|
27
|
-
TimeType = tslib_1.__decorate([
|
|
9
|
+
exports.TimeType = TimeType = tslib_1.__decorate([
|
|
28
10
|
(0, simple_type_js_1.SimpleType)({
|
|
29
|
-
description: 'Time
|
|
11
|
+
description: 'Time string in 24h format, for example, 18:23:00',
|
|
12
|
+
decoder: (0, valgen_1.isDateString)({
|
|
13
|
+
format: ['HH:mm:ss', 'HH:mm'],
|
|
14
|
+
onFail: () => '{{label}} is not a valid time'
|
|
15
|
+
}),
|
|
16
|
+
encoder: (0, valgen_1.isDateString)({ format: ['HH:mm:ss', 'HH:mm'],
|
|
17
|
+
onFail: () => '{{label}} is not a valid time'
|
|
18
|
+
})
|
|
30
19
|
})
|
|
31
20
|
], TimeType);
|
|
32
|
-
exports.TimeType = TimeType;
|
|
@@ -2,28 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TimestampType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const valgen_1 = require("valgen");
|
|
6
6
|
const simple_type_js_1 = require("../simple-type.js");
|
|
7
|
-
let TimestampType = class TimestampType {
|
|
8
|
-
constructor() {
|
|
9
|
-
this.format = 'YYYY-MM-DDTHH:mm:ss';
|
|
10
|
-
}
|
|
11
|
-
decode(v) {
|
|
12
|
-
return (0, dayjs_1.default)(v).toDate();
|
|
13
|
-
}
|
|
14
|
-
encode(v) {
|
|
15
|
-
if (!v)
|
|
16
|
-
return undefined;
|
|
17
|
-
const d = (0, dayjs_1.default)(v);
|
|
18
|
-
if (!d.isValid())
|
|
19
|
-
throw new TypeError(`Invalid date value ${v}`);
|
|
20
|
-
return (0, dayjs_1.default)(v).format(this.format);
|
|
21
|
-
}
|
|
7
|
+
let TimestampType = exports.TimestampType = class TimestampType {
|
|
22
8
|
};
|
|
23
|
-
TimestampType = tslib_1.__decorate([
|
|
9
|
+
exports.TimestampType = TimestampType = tslib_1.__decorate([
|
|
24
10
|
(0, simple_type_js_1.SimpleType)({
|
|
25
|
-
description: '
|
|
26
|
-
|
|
11
|
+
description: 'Timestamp, for example, 2021-04-18T09:12:53',
|
|
12
|
+
decoder: (0, valgen_1.isDate)({
|
|
13
|
+
format: ['YYYY-MM-DDTHH:mm:ss', 'YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD', 'YYYY']
|
|
14
|
+
}),
|
|
15
|
+
encoder: (0, valgen_1.isDateString)({ format: 'YYYY-MM-DDTHH:mm:ss' })
|
|
27
16
|
})
|
|
28
17
|
], TimestampType);
|
|
29
|
-
exports.TimestampType = TimestampType;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UuidType = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const valgen_1 = require("valgen");
|
|
6
|
+
const simple_type_js_1 = require("../simple-type.js");
|
|
7
|
+
let UuidType = exports.UuidType = class UuidType {
|
|
8
|
+
};
|
|
9
|
+
exports.UuidType = UuidType = tslib_1.__decorate([
|
|
10
|
+
(0, simple_type_js_1.SimpleType)({
|
|
11
|
+
description: 'A Universal Unique Identifier (UUID) value',
|
|
12
|
+
decoder: (0, valgen_1.isUUID)(),
|
|
13
|
+
encoder: (0, valgen_1.isUUID)()
|
|
14
|
+
})
|
|
15
|
+
], UuidType);
|