@opra/common 1.4.2 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/index.cjs +1 -1
- package/browser/index.mjs +1 -1
- package/cjs/document/api-document.js +3 -1
- package/cjs/document/common/api-base.js +2 -1
- package/cjs/document/common/data-type-map.js +14 -3
- package/cjs/document/common/value.js +3 -1
- package/cjs/document/data-type/api-field.js +3 -1
- package/cjs/document/data-type/complex-type-base.js +12 -4
- package/cjs/document/data-type/complex-type.js +6 -2
- package/cjs/document/data-type/enum-type.js +3 -1
- package/cjs/document/data-type/extended-types/date-time.type.js +5 -1
- package/cjs/document/data-type/extended-types/date.type.js +5 -1
- package/cjs/document/data-type/extended-types/field-path.type.js +3 -1
- package/cjs/document/data-type/extended-types/filter.type.js +3 -1
- package/cjs/document/data-type/mapped-type.js +15 -6
- package/cjs/document/data-type/mixin-type.js +3 -1
- package/cjs/document/data-type/primitive-types/bigint.type.js +3 -1
- package/cjs/document/data-type/primitive-types/integer.type.js +3 -1
- package/cjs/document/data-type/primitive-types/number.type.js +3 -1
- package/cjs/document/data-type/primitive-types/string.type.js +3 -1
- package/cjs/document/data-type/simple-type.js +7 -2
- package/cjs/document/data-type/utils/create-mapped-class.js +3 -1
- package/cjs/document/decorators/api-field-decorator.js +2 -1
- package/cjs/document/decorators/http-controller.decorator.js +7 -1
- package/cjs/document/decorators/http-operation-entity.decorator.js +20 -10
- package/cjs/document/decorators/http-operation.decorator.js +23 -10
- package/cjs/document/decorators/rpc-operation.decorator.js +1 -2
- package/cjs/document/decorators/simple-type.decorator.js +2 -1
- package/cjs/document/factory/api-document.factory.js +11 -3
- package/cjs/document/factory/data-type.factory.js +19 -7
- package/cjs/document/factory/http-api.factory.js +13 -4
- package/cjs/document/http/http-controller.js +2 -1
- package/cjs/document/http/http-media-type.js +15 -5
- package/cjs/document/http/http-operation-response.js +8 -3
- package/cjs/document/http/http-operation.js +3 -1
- package/cjs/document/http/http-status-range.js +3 -1
- package/cjs/document/rpc/rpc-operation-response.js +11 -3
- package/cjs/document/rpc/rpc-operation.js +11 -3
- package/cjs/document/utils/parse-regexp.util.js +2 -2
- package/cjs/exception/opra-exception.js +3 -1
- package/cjs/filter/antlr/OpraFilterLexer.js +190 -123
- package/cjs/filter/antlr/OpraFilterParser.js +53 -35
- package/cjs/filter/ast/expressions/arithmetic-expression.js +3 -1
- package/cjs/filter/ast/terms/number-literal.js +3 -1
- package/cjs/filter/filter-rules.js +13 -4
- package/cjs/filter/filter-tree-visitor.js +2 -1
- package/cjs/filter/opra-error-listener.js +7 -1
- package/cjs/filter/parse.js +3 -1
- package/cjs/filter/utils.js +3 -1
- package/cjs/helpers/get-stack-filename.js +6 -2
- package/cjs/helpers/mixin-utils.js +7 -2
- package/cjs/helpers/object-utils.js +3 -1
- package/cjs/helpers/parse-fields-projection.js +4 -2
- package/cjs/helpers/type-guards.js +7 -2
- package/cjs/i18n/i18n.js +13 -3
- package/cjs/i18n/translate.js +3 -1
- package/cjs/polifils/array-find-last.js +0 -2
- package/esm/document/api-document.js +4 -2
- package/esm/document/common/api-base.js +2 -1
- package/esm/document/common/data-type-map.js +14 -3
- package/esm/document/common/value.js +3 -1
- package/esm/document/data-type/api-field.js +3 -1
- package/esm/document/data-type/complex-type-base.js +13 -5
- package/esm/document/data-type/complex-type.js +6 -2
- package/esm/document/data-type/data-type.js +1 -1
- package/esm/document/data-type/enum-type.js +3 -1
- package/esm/document/data-type/extended-types/date-time.type.js +5 -1
- package/esm/document/data-type/extended-types/date.type.js +5 -1
- package/esm/document/data-type/extended-types/field-path.type.js +3 -1
- package/esm/document/data-type/extended-types/filter.type.js +3 -1
- package/esm/document/data-type/mapped-type.js +15 -6
- package/esm/document/data-type/mixin-type.js +4 -2
- package/esm/document/data-type/primitive-types/bigint.type.js +3 -1
- package/esm/document/data-type/primitive-types/integer.type.js +3 -1
- package/esm/document/data-type/primitive-types/number.type.js +3 -1
- package/esm/document/data-type/primitive-types/string.type.js +3 -1
- package/esm/document/data-type/simple-type.js +8 -3
- package/esm/document/data-type/utils/create-mapped-class.js +4 -2
- package/esm/document/decorators/api-field-decorator.js +2 -1
- package/esm/document/decorators/complex-type.decorator.js +1 -1
- package/esm/document/decorators/http-controller.decorator.js +7 -1
- package/esm/document/decorators/http-operation-entity.decorator.js +22 -12
- package/esm/document/decorators/http-operation.decorator.js +23 -10
- package/esm/document/decorators/rpc-operation.decorator.js +1 -2
- package/esm/document/decorators/simple-type.decorator.js +3 -2
- package/esm/document/factory/api-document.factory.js +11 -3
- package/esm/document/factory/data-type.factory.js +21 -9
- package/esm/document/factory/http-api.factory.js +13 -4
- package/esm/document/http/http-controller.js +3 -2
- package/esm/document/http/http-media-type.js +15 -5
- package/esm/document/http/http-operation-response.js +8 -3
- package/esm/document/http/http-operation.js +4 -2
- package/esm/document/http/http-parameter.js +1 -1
- package/esm/document/http/http-status-range.js +3 -1
- package/esm/document/rpc/rpc-controller.js +1 -1
- package/esm/document/rpc/rpc-header.js +1 -1
- package/esm/document/rpc/rpc-operation-response.js +11 -3
- package/esm/document/rpc/rpc-operation.js +12 -4
- package/esm/document/utils/parse-regexp.util.js +2 -2
- package/esm/exception/opra-exception.js +3 -1
- package/esm/filter/antlr/OpraFilterLexer.js +190 -123
- package/esm/filter/antlr/OpraFilterParser.js +53 -35
- package/esm/filter/ast/expressions/arithmetic-expression.js +3 -1
- package/esm/filter/ast/terms/number-literal.js +3 -1
- package/esm/filter/filter-rules.js +13 -4
- package/esm/filter/filter-tree-visitor.js +2 -1
- package/esm/filter/opra-error-listener.js +8 -2
- package/esm/filter/parse.js +3 -1
- package/esm/filter/utils.js +3 -1
- package/esm/helpers/get-stack-filename.js +6 -2
- package/esm/helpers/mixin-utils.js +7 -2
- package/esm/helpers/object-utils.js +3 -1
- package/esm/helpers/parse-fields-projection.js +4 -2
- package/esm/helpers/type-guards.js +7 -2
- package/esm/i18n/i18n.js +13 -3
- package/esm/i18n/translate.js +3 -1
- package/esm/polifils/array-find-last.js +0 -2
- package/package.json +1 -1
|
@@ -48,7 +48,9 @@ class FilterRules {
|
|
|
48
48
|
const rule = this._rules.get(ast.left.value);
|
|
49
49
|
if (!rule) {
|
|
50
50
|
throw new index_js_1.OpraException({
|
|
51
|
-
message: (0, index_js_3.translate)('error:UNACCEPTED_FILTER_FIELD', {
|
|
51
|
+
message: (0, index_js_3.translate)('error:UNACCEPTED_FILTER_FIELD', {
|
|
52
|
+
field: ast.left.value,
|
|
53
|
+
}),
|
|
52
54
|
code: 'UNACCEPTED_FILTER_FIELD',
|
|
53
55
|
details: {
|
|
54
56
|
field: ast.left.value,
|
|
@@ -58,7 +60,9 @@ class FilterRules {
|
|
|
58
60
|
// Check if filtering endpoint accepted for given field
|
|
59
61
|
if (rule.operators && !rule.operators.includes(ast.op)) {
|
|
60
62
|
throw new index_js_1.OpraException({
|
|
61
|
-
message: (0, index_js_3.translate)('error:UNACCEPTED_FILTER_OPERATION', {
|
|
63
|
+
message: (0, index_js_3.translate)('error:UNACCEPTED_FILTER_OPERATION', {
|
|
64
|
+
field: ast.left.value,
|
|
65
|
+
}),
|
|
62
66
|
code: 'UNACCEPTED_FILTER_OPERATION',
|
|
63
67
|
details: {
|
|
64
68
|
field: ast.left.value,
|
|
@@ -108,11 +112,16 @@ class FilterRules {
|
|
|
108
112
|
/** If calling for right side of comparison */
|
|
109
113
|
if (ast === comp.right || stack[compIdx + 1] === comp.right) {
|
|
110
114
|
/** Check if comparison expression left side is a field */
|
|
111
|
-
if (comp &&
|
|
115
|
+
if (comp &&
|
|
116
|
+
comp.left instanceof index_js_4.QualifiedIdentifier &&
|
|
117
|
+
comp.left.field) {
|
|
112
118
|
if (ast.value == null && !comp.left.field.required)
|
|
113
119
|
return ast.value;
|
|
114
120
|
let decoder;
|
|
115
|
-
if (comp.op === 'like' ||
|
|
121
|
+
if (comp.op === 'like' ||
|
|
122
|
+
comp.op === '!like' ||
|
|
123
|
+
comp.op === 'ilike' ||
|
|
124
|
+
comp.op === '!ilike') {
|
|
116
125
|
decoder = valgen_1.isString;
|
|
117
126
|
}
|
|
118
127
|
else
|
|
@@ -45,7 +45,8 @@ class FilterTreeVisitor extends antlr4_1.ParseTreeVisitor {
|
|
|
45
45
|
const items = [];
|
|
46
46
|
const wrapChildren = (arr, op) => {
|
|
47
47
|
for (const c of arr) {
|
|
48
|
-
if (c instanceof OpraFilterParser_js_1.LogicalExpressionContext &&
|
|
48
|
+
if (c instanceof OpraFilterParser_js_1.LogicalExpressionContext &&
|
|
49
|
+
c.logicalOperator().getText() === op) {
|
|
49
50
|
wrapChildren(c.expression_list(), c.logicalOperator().getText());
|
|
50
51
|
continue;
|
|
51
52
|
}
|
|
@@ -9,7 +9,13 @@ class OpraErrorListener extends antlr4_1.ErrorListener {
|
|
|
9
9
|
this.errors = errors;
|
|
10
10
|
}
|
|
11
11
|
syntaxError(recognizer, offendingSymbol, line, column, msg, e) {
|
|
12
|
-
this.errors.push(new errors_js_1.FilterParseError(msg, {
|
|
12
|
+
this.errors.push(new errors_js_1.FilterParseError(msg, {
|
|
13
|
+
recognizer,
|
|
14
|
+
offendingSymbol,
|
|
15
|
+
line,
|
|
16
|
+
column,
|
|
17
|
+
e,
|
|
18
|
+
}));
|
|
13
19
|
}
|
|
14
20
|
}
|
|
15
21
|
exports.OpraErrorListener = OpraErrorListener;
|
package/cjs/filter/parse.js
CHANGED
|
@@ -25,7 +25,9 @@ function parse(text, visitor) {
|
|
|
25
25
|
const errMsgs = [];
|
|
26
26
|
for (const err of errors) {
|
|
27
27
|
errMsgs.push(err.message +
|
|
28
|
-
(text.includes('\n')
|
|
28
|
+
(text.includes('\n')
|
|
29
|
+
? ' at line: ' + err.line + ' column: ' + err.column
|
|
30
|
+
: ' at column: ' + err.column));
|
|
29
31
|
}
|
|
30
32
|
const e = new errors_js_1.SyntaxError(errMsgs.join('\n'));
|
|
31
33
|
e.errors = errors;
|
package/cjs/filter/utils.js
CHANGED
|
@@ -15,7 +15,9 @@ function quoteFilterString(s) {
|
|
|
15
15
|
return "'" + escapeString(s).replace(quotesRegEx, "\\'") + "'";
|
|
16
16
|
}
|
|
17
17
|
function unquoteFilterString(s) {
|
|
18
|
-
if (s &&
|
|
18
|
+
if (s &&
|
|
19
|
+
(s.startsWith("'") || s.startsWith('"')) &&
|
|
20
|
+
s.endsWith(s.charAt(0))) {
|
|
19
21
|
return unescapeString(s.substring(1, s.length - 1));
|
|
20
22
|
}
|
|
21
23
|
/* istanbul ignore next */
|
|
@@ -18,7 +18,9 @@ function getStackFileName(position = 1) {
|
|
|
18
18
|
if (stack !== null && typeof stack === 'object') {
|
|
19
19
|
// stack[0] holds this file
|
|
20
20
|
// stack[1] holds where this function was called
|
|
21
|
-
const s = stack[position]
|
|
21
|
+
const s = stack[position]
|
|
22
|
+
? stack[position].getFileName()
|
|
23
|
+
: undefined;
|
|
22
24
|
const m = s ? PATH_PATTERN.exec(s) : undefined;
|
|
23
25
|
return m ? m[1] : '';
|
|
24
26
|
}
|
|
@@ -39,7 +41,9 @@ function getErrorStack(position = 1) {
|
|
|
39
41
|
if (stack !== null && typeof stack === 'object') {
|
|
40
42
|
// stack[0] holds this file
|
|
41
43
|
// stack[1] holds where this function was called
|
|
42
|
-
const s = stack[position]
|
|
44
|
+
const s = stack[position]
|
|
45
|
+
? stack[position].getFileName()
|
|
46
|
+
: undefined;
|
|
43
47
|
const m = s ? PATH_PATTERN.exec(s) : undefined;
|
|
44
48
|
return m ? m[1] : '';
|
|
45
49
|
}
|
|
@@ -4,7 +4,11 @@ exports.mergePrototype = mergePrototype;
|
|
|
4
4
|
exports.inheritPropertyInitializers = inheritPropertyInitializers;
|
|
5
5
|
function mergePrototype(targetProto, baseProto, filter) {
|
|
6
6
|
for (const k of Object.getOwnPropertyNames(baseProto)) {
|
|
7
|
-
if (k === 'constructor' ||
|
|
7
|
+
if (k === 'constructor' ||
|
|
8
|
+
k === '__proto__' ||
|
|
9
|
+
k === 'toJSON' ||
|
|
10
|
+
k === 'toString' ||
|
|
11
|
+
(filter && !filter(k))) {
|
|
8
12
|
continue;
|
|
9
13
|
}
|
|
10
14
|
Object.defineProperty(targetProto, k, Object.getOwnPropertyDescriptor(baseProto, k) || Object.create(null));
|
|
@@ -18,7 +22,8 @@ isPropertyInherited = (key) => true) {
|
|
|
18
22
|
const tempInstance = new clazz();
|
|
19
23
|
const propertyNames = Object.getOwnPropertyNames(tempInstance);
|
|
20
24
|
propertyNames
|
|
21
|
-
.filter(propertyName => typeof tempInstance[propertyName] !== 'undefined' &&
|
|
25
|
+
.filter(propertyName => typeof tempInstance[propertyName] !== 'undefined' &&
|
|
26
|
+
typeof target[propertyName] === 'undefined')
|
|
22
27
|
.filter(propertyName => isPropertyInherited(propertyName))
|
|
23
28
|
.forEach(propertyName => {
|
|
24
29
|
target[propertyName] = tempInstance[propertyName];
|
|
@@ -10,7 +10,9 @@ function cloneObject(obj, jsonOnly) {
|
|
|
10
10
|
ignoreUndefined: true,
|
|
11
11
|
filter(key, source) {
|
|
12
12
|
const v = source[key];
|
|
13
|
-
return !jsonOnly ||
|
|
13
|
+
return (!jsonOnly ||
|
|
14
|
+
(typeof v !== 'function' &&
|
|
15
|
+
(typeof v !== 'object' || (0, objects_1.isPlainObject)(v) || Array.isArray(v))));
|
|
14
16
|
},
|
|
15
17
|
});
|
|
16
18
|
}
|
|
@@ -52,14 +52,16 @@ function parse(input, target) {
|
|
|
52
52
|
if (!m)
|
|
53
53
|
throw new TypeError(`Invalid field path (${input})`);
|
|
54
54
|
const fieldName = m[2];
|
|
55
|
-
const treeItem = (target[fieldName] =
|
|
55
|
+
const treeItem = (target[fieldName] =
|
|
56
|
+
target[fieldName] || new FieldsProjection.Item());
|
|
56
57
|
if (m[1])
|
|
57
58
|
treeItem.sign = m[1];
|
|
58
59
|
if (i === fields.length - 1) {
|
|
59
60
|
delete treeItem.projection;
|
|
60
61
|
}
|
|
61
62
|
else {
|
|
62
|
-
target = treeItem.projection =
|
|
63
|
+
target = treeItem.projection =
|
|
64
|
+
treeItem.projection || new FieldsProjection();
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
}
|
|
@@ -11,7 +11,9 @@ function isStream(x) {
|
|
|
11
11
|
return x !== null && typeof x === 'object' && typeof x.pipe === 'function';
|
|
12
12
|
}
|
|
13
13
|
function isReadable(x) {
|
|
14
|
-
return isStream(x) &&
|
|
14
|
+
return (isStream(x) &&
|
|
15
|
+
typeof x._read === 'function' &&
|
|
16
|
+
typeof x._readableState === 'object');
|
|
15
17
|
}
|
|
16
18
|
function isWritable(x) {
|
|
17
19
|
return isStream(x) && typeof x._write === 'function';
|
|
@@ -37,5 +39,8 @@ function isFormData(x) {
|
|
|
37
39
|
typeof x.getAll === 'function');
|
|
38
40
|
}
|
|
39
41
|
function isURL(x) {
|
|
40
|
-
return x !== null &&
|
|
42
|
+
return (x !== null &&
|
|
43
|
+
typeof x == 'object' &&
|
|
44
|
+
typeof x.host === 'string' &&
|
|
45
|
+
typeof x.href === 'string');
|
|
41
46
|
}
|
package/cjs/i18n/i18n.js
CHANGED
|
@@ -5,7 +5,9 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const i18next_1 = tslib_1.__importDefault(require("@browsery/i18next"));
|
|
6
6
|
const fast_tokenizer_1 = require("fast-tokenizer");
|
|
7
7
|
const string_utils_js_1 = require("./string-utils.js");
|
|
8
|
-
|
|
8
|
+
// eslint-disable-next-line import-x/no-named-as-default-member
|
|
9
|
+
exports.BaseI18n = Object.getPrototypeOf(i18next_1.default.createInstance())
|
|
10
|
+
.constructor;
|
|
9
11
|
class I18n extends exports.BaseI18n {
|
|
10
12
|
async init(arg0, arg1) {
|
|
11
13
|
const options = typeof arg0 === 'object' ? arg0 : {};
|
|
@@ -66,12 +68,20 @@ class I18n extends exports.BaseI18n {
|
|
|
66
68
|
})) {
|
|
67
69
|
if (token.startsWith('$t(') && token.endsWith(')')) {
|
|
68
70
|
token = token.substring(3, token.length - 1);
|
|
69
|
-
const a = (0, fast_tokenizer_1.splitString)(token, {
|
|
71
|
+
const a = (0, fast_tokenizer_1.splitString)(token, {
|
|
72
|
+
delimiters: '?',
|
|
73
|
+
quotes: true,
|
|
74
|
+
brackets: { '{': '}' },
|
|
75
|
+
});
|
|
70
76
|
const fallback = (0, string_utils_js_1.unescapeString)(token.substring((a[0] || '').length + 1));
|
|
71
77
|
token = a[0] || '';
|
|
72
78
|
const keys = [];
|
|
73
79
|
let opts = null;
|
|
74
|
-
for (const token2 of (0, fast_tokenizer_1.tokenize)(token, {
|
|
80
|
+
for (const token2 of (0, fast_tokenizer_1.tokenize)(token, {
|
|
81
|
+
delimiters: ',',
|
|
82
|
+
quotes: true,
|
|
83
|
+
brackets: { '{': '}' },
|
|
84
|
+
})) {
|
|
75
85
|
if (token2.startsWith('{')) {
|
|
76
86
|
opts = JSON.parse(token2);
|
|
77
87
|
continue;
|
package/cjs/i18n/translate.js
CHANGED
|
@@ -9,6 +9,8 @@ function translate(key, arg0, arg1) {
|
|
|
9
9
|
return ('$t(' +
|
|
10
10
|
key +
|
|
11
11
|
(options ? ',' + JSON.stringify(options) : '') +
|
|
12
|
-
(fallback
|
|
12
|
+
(fallback
|
|
13
|
+
? '?' + (0, string_utils_js_1.escapeString)(fallback).replace(bracketRegEx, '\\$1')
|
|
14
|
+
: '') +
|
|
13
15
|
')');
|
|
14
16
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
if (!Array.prototype.findLast) {
|
|
4
|
-
// eslint-disable-next-line no-extend-native
|
|
5
4
|
Array.prototype.findLast = function (predicate, thisArg) {
|
|
6
5
|
const i = this.findLastIndex(predicate, thisArg);
|
|
7
6
|
return i >= 0 ? this[i] : undefined;
|
|
8
7
|
};
|
|
9
|
-
// eslint-disable-next-line no-extend-native
|
|
10
8
|
Array.prototype.findLastIndex = function (predicate, thisArg) {
|
|
11
9
|
if (this == null) {
|
|
12
10
|
throw new TypeError('this is null or not defined');
|
|
@@ -5,7 +5,7 @@ import { cloneObject, ResponsiveMap } from '../helpers/index.js';
|
|
|
5
5
|
import { OpraSchema } from '../schema/index.js';
|
|
6
6
|
import { DataTypeMap } from './common/data-type-map.js';
|
|
7
7
|
import { DocumentElement } from './common/document-element.js';
|
|
8
|
-
import { BUILTIN, kDataTypeMap, kTypeNSMap, NAMESPACE_PATTERN } from './constants.js';
|
|
8
|
+
import { BUILTIN, kDataTypeMap, kTypeNSMap, NAMESPACE_PATTERN, } from './constants.js';
|
|
9
9
|
import { DataType } from './data-type/data-type.js';
|
|
10
10
|
import { HttpApi } from './http/http-api.js';
|
|
11
11
|
import { RpcApi } from './rpc/rpc-api.js';
|
|
@@ -29,7 +29,9 @@ export class ApiDocument extends DocumentElement {
|
|
|
29
29
|
* @param nameOrCtor
|
|
30
30
|
*/
|
|
31
31
|
getDataTypeNs(nameOrCtor) {
|
|
32
|
-
const dt = nameOrCtor instanceof DataType
|
|
32
|
+
const dt = nameOrCtor instanceof DataType
|
|
33
|
+
? this._findDataType(nameOrCtor.name || '')
|
|
34
|
+
: this._findDataType(nameOrCtor);
|
|
33
35
|
if (dt)
|
|
34
36
|
return this[kTypeNSMap].get(dt);
|
|
35
37
|
}
|
|
@@ -15,8 +15,9 @@ export class ApiBase extends DocumentElement {
|
|
|
15
15
|
description: this.description,
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
+
async _initialize(init,
|
|
18
19
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
|
-
|
|
20
|
+
context) {
|
|
20
21
|
if (!CLASS_NAME_PATTERN.test(init.name))
|
|
21
22
|
throw new TypeError(`Invalid api name (${init.name})`);
|
|
22
23
|
this.name = init.name;
|
|
@@ -19,7 +19,9 @@ export class DataTypeMap {
|
|
|
19
19
|
this[kMap].forEach(callbackFn, thisArg);
|
|
20
20
|
}
|
|
21
21
|
get(nameOrCtor) {
|
|
22
|
-
let name = typeof nameOrCtor === 'string'
|
|
22
|
+
let name = typeof nameOrCtor === 'string'
|
|
23
|
+
? nameOrCtor
|
|
24
|
+
: this[kCtorMap].get(nameOrCtor);
|
|
23
25
|
if (!name && typeof nameOrCtor === 'function') {
|
|
24
26
|
const metadata = Reflect.getMetadata(DATATYPE_METADATA, nameOrCtor);
|
|
25
27
|
name = metadata?.name;
|
|
@@ -28,7 +30,14 @@ export class DataTypeMap {
|
|
|
28
30
|
const metadata = nameOrCtor[DATATYPE_METADATA];
|
|
29
31
|
name = metadata?.name;
|
|
30
32
|
}
|
|
31
|
-
|
|
33
|
+
if (!name)
|
|
34
|
+
return;
|
|
35
|
+
const out = this[kMap].get(name);
|
|
36
|
+
if (!out)
|
|
37
|
+
return;
|
|
38
|
+
if (typeof nameOrCtor === 'function' && out.kind === 'ComplexType')
|
|
39
|
+
return out.ctor === nameOrCtor ? out : undefined;
|
|
40
|
+
return out;
|
|
32
41
|
}
|
|
33
42
|
set(name, dataType) {
|
|
34
43
|
this[kMap].set(name, dataType);
|
|
@@ -40,7 +49,9 @@ export class DataTypeMap {
|
|
|
40
49
|
has(nameOrCtor) {
|
|
41
50
|
if (nameOrCtor instanceof DataType)
|
|
42
51
|
return !!nameOrCtor.name && this[kMap].has(nameOrCtor.name);
|
|
43
|
-
const name = typeof nameOrCtor === 'string'
|
|
52
|
+
const name = typeof nameOrCtor === 'string'
|
|
53
|
+
? nameOrCtor
|
|
54
|
+
: this[kCtorMap].get(nameOrCtor);
|
|
44
55
|
return name ? this[kMap].has(name) : false;
|
|
45
56
|
}
|
|
46
57
|
keys() {
|
|
@@ -18,7 +18,9 @@ export const Value = function (owner, initArgs) {
|
|
|
18
18
|
*/
|
|
19
19
|
class ValueClass extends DocumentElement {
|
|
20
20
|
toJSON() {
|
|
21
|
-
const typeName = this.type
|
|
21
|
+
const typeName = this.type
|
|
22
|
+
? this.node.getDataTypeNameWithNs(this.type)
|
|
23
|
+
: undefined;
|
|
22
24
|
return omitUndefined({
|
|
23
25
|
type: this.type ? (typeName ? typeName : this.type.toJSON()) : 'any',
|
|
24
26
|
description: this.description,
|
|
@@ -46,7 +46,9 @@ export const ApiField = function (...args) {
|
|
|
46
46
|
*/
|
|
47
47
|
class ApiFieldClass extends DocumentElement {
|
|
48
48
|
toJSON() {
|
|
49
|
-
const typeName = this.type
|
|
49
|
+
const typeName = this.type
|
|
50
|
+
? this.node.getDataTypeNameWithNs(this.type)
|
|
51
|
+
: undefined;
|
|
50
52
|
return omitUndefined({
|
|
51
53
|
type: typeName ? typeName : this.type?.toJSON(),
|
|
52
54
|
description: this.description,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { asMutable } from 'ts-gems';
|
|
2
2
|
import { validator, vg } from 'valgen';
|
|
3
|
-
import { parseFieldsProjection, ResponsiveMap } from '../../helpers/index.js';
|
|
3
|
+
import { parseFieldsProjection, ResponsiveMap, } from '../../helpers/index.js';
|
|
4
4
|
import { translate } from '../../i18n/index.js';
|
|
5
5
|
import { DataType } from './data-type.js';
|
|
6
6
|
export const FIELD_PATH_PATTERN = /^([+-])?([a-z$_][\w.]*)$/i;
|
|
@@ -83,7 +83,8 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
83
83
|
dataType = undefined;
|
|
84
84
|
continue;
|
|
85
85
|
}
|
|
86
|
-
if (dataType.additionalFields?.[0] === 'type' &&
|
|
86
|
+
if (dataType.additionalFields?.[0] === 'type' &&
|
|
87
|
+
dataType.additionalFields?.[1] instanceof DataType) {
|
|
87
88
|
item.additionalField = true;
|
|
88
89
|
item.dataType = dataType.additionalFields[1];
|
|
89
90
|
dataType = dataType.additionalFields[1];
|
|
@@ -113,7 +114,11 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
113
114
|
const projection = Array.isArray(options?.projection)
|
|
114
115
|
? parseFieldsProjection(options.projection)
|
|
115
116
|
: options?.projection;
|
|
116
|
-
const schema = this._generateSchema(codec, {
|
|
117
|
+
const schema = this._generateSchema(codec, {
|
|
118
|
+
...options,
|
|
119
|
+
projection,
|
|
120
|
+
currentPath: '',
|
|
121
|
+
});
|
|
117
122
|
let additionalFields;
|
|
118
123
|
if (this.additionalFields instanceof DataType) {
|
|
119
124
|
additionalFields = this.additionalFields.generateCodec(codec, options);
|
|
@@ -168,10 +173,13 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
168
173
|
const fn = this._generateFieldCodec(codec, field, {
|
|
169
174
|
...context,
|
|
170
175
|
partial: context.partial === 'deep' ? context.partial : undefined,
|
|
171
|
-
projection: typeof projection === 'object'
|
|
176
|
+
projection: typeof projection === 'object'
|
|
177
|
+
? projection[fieldName]?.projection || '*'
|
|
178
|
+
: projection,
|
|
172
179
|
currentPath: currentPath + (currentPath ? '.' : '') + fieldName,
|
|
173
180
|
});
|
|
174
|
-
schema[fieldName] =
|
|
181
|
+
schema[fieldName] =
|
|
182
|
+
context.partial || !field.required ? vg.optional(fn) : vg.required(fn);
|
|
175
183
|
}
|
|
176
184
|
if (context.allowPatchOperators) {
|
|
177
185
|
schema._$pull = vg.optional(vg.isAny());
|
|
@@ -69,7 +69,9 @@ class ComplexTypeClass extends ComplexTypeBase {
|
|
|
69
69
|
return !!this.base?.extendsFrom(baseType);
|
|
70
70
|
}
|
|
71
71
|
toJSON() {
|
|
72
|
-
const baseName = this.base
|
|
72
|
+
const baseName = this.base
|
|
73
|
+
? this.node.getDataTypeNameWithNs(this.base)
|
|
74
|
+
: undefined;
|
|
73
75
|
const out = omitUndefined({
|
|
74
76
|
...ComplexTypeBase.prototype.toJSON.call(this),
|
|
75
77
|
kind: this.kind,
|
|
@@ -78,7 +80,9 @@ class ComplexTypeClass extends ComplexTypeBase {
|
|
|
78
80
|
if (this.additionalFields) {
|
|
79
81
|
if (this.additionalFields instanceof DataType) {
|
|
80
82
|
const typeName = this.node.getDataTypeNameWithNs(this.additionalFields);
|
|
81
|
-
out.additionalFields = typeName
|
|
83
|
+
out.additionalFields = typeName
|
|
84
|
+
? typeName
|
|
85
|
+
: this.additionalFields.toJSON();
|
|
82
86
|
}
|
|
83
87
|
else
|
|
84
88
|
out.additionalFields = this.additionalFields;
|
|
@@ -2,7 +2,7 @@ import { omitUndefined } from '@jsopen/objects';
|
|
|
2
2
|
import { asMutable } from 'ts-gems';
|
|
3
3
|
import { DocumentElement } from '../common/document-element.js';
|
|
4
4
|
import { CLASS_NAME_PATTERN } from '../constants.js';
|
|
5
|
-
import { colorFgMagenta, colorFgYellow, colorReset, nodeInspectCustom } from '../utils/inspect.util.js';
|
|
5
|
+
import { colorFgMagenta, colorFgYellow, colorReset, nodeInspectCustom, } from '../utils/inspect.util.js';
|
|
6
6
|
/**
|
|
7
7
|
* DataType constructor
|
|
8
8
|
*/
|
|
@@ -49,7 +49,9 @@ class EnumTypeClass extends DataType {
|
|
|
49
49
|
return vg.isEnum(Object.keys(this.attributes));
|
|
50
50
|
}
|
|
51
51
|
toJSON() {
|
|
52
|
-
const baseName = this.base
|
|
52
|
+
const baseName = this.base
|
|
53
|
+
? this.node.getDataTypeNameWithNs(this.base)
|
|
54
|
+
: undefined;
|
|
53
55
|
return omitUndefined({
|
|
54
56
|
...DataType.prototype.toJSON.call(this),
|
|
55
57
|
base: this.base ? (baseName ? baseName : this.base.toJSON()) : undefined,
|
|
@@ -21,7 +21,11 @@ let DateTimeType = class DateTimeType {
|
|
|
21
21
|
return x.length > 0 ? vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
|
|
22
22
|
}
|
|
23
23
|
[ENCODER](properties) {
|
|
24
|
-
const fn = vg.isDateString({
|
|
24
|
+
const fn = vg.isDateString({
|
|
25
|
+
precision: 'time',
|
|
26
|
+
trim: 'time',
|
|
27
|
+
coerce: true,
|
|
28
|
+
});
|
|
25
29
|
const x = [];
|
|
26
30
|
if (properties.minValue) {
|
|
27
31
|
isDateString(properties.minValue);
|
|
@@ -21,7 +21,11 @@ let DateType = class DateType {
|
|
|
21
21
|
return x.length > 0 ? vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
|
|
22
22
|
}
|
|
23
23
|
[ENCODER](properties) {
|
|
24
|
-
const fn = vg.isDateString({
|
|
24
|
+
const fn = vg.isDateString({
|
|
25
|
+
precision: 'date',
|
|
26
|
+
trim: 'date',
|
|
27
|
+
coerce: true,
|
|
28
|
+
});
|
|
25
29
|
const x = [];
|
|
26
30
|
if (properties.minValue) {
|
|
27
31
|
isDateString(properties.minValue);
|
|
@@ -22,7 +22,9 @@ let FieldPathType = class FieldPathType {
|
|
|
22
22
|
const dataType = properties.dataType
|
|
23
23
|
? element.node.getComplexType(properties.dataType)
|
|
24
24
|
: element.node.getComplexType('object');
|
|
25
|
-
const typeName = dataType
|
|
25
|
+
const typeName = dataType
|
|
26
|
+
? element.node.getDataTypeNameWithNs(dataType)
|
|
27
|
+
: undefined;
|
|
26
28
|
return {
|
|
27
29
|
dataType: typeName ? typeName : dataType.toJSON(),
|
|
28
30
|
allowSigns: properties.allowSigns,
|
|
@@ -13,7 +13,9 @@ let FilterType = class FilterType {
|
|
|
13
13
|
const dataType = properties.dataType
|
|
14
14
|
? element.node.getComplexType(properties.dataType)
|
|
15
15
|
: element.node.getComplexType('object');
|
|
16
|
-
const rules = properties.rules
|
|
16
|
+
const rules = properties.rules
|
|
17
|
+
? new FilterRules(properties.rules)
|
|
18
|
+
: undefined;
|
|
17
19
|
return decodeFilter(dataType, rules);
|
|
18
20
|
}
|
|
19
21
|
[ENCODER]() {
|
|
@@ -40,16 +40,22 @@ export const MappedType = function (...args) {
|
|
|
40
40
|
}
|
|
41
41
|
/** Copy fields from base */
|
|
42
42
|
const isInheritedPredicate = getIsInheritedPredicateFn(_this.pick, _this.omit);
|
|
43
|
-
const partial = Array.isArray(_this.partial)
|
|
44
|
-
|
|
43
|
+
const partial = Array.isArray(_this.partial)
|
|
44
|
+
? _this.partial.map(x => x.toLowerCase())
|
|
45
|
+
: _this.partial;
|
|
46
|
+
const required = Array.isArray(_this.required)
|
|
47
|
+
? _this.required.map(x => x.toLowerCase())
|
|
48
|
+
: _this.required;
|
|
45
49
|
for (const [k, v] of _this.base.fields.entries()) {
|
|
46
50
|
if (!isInheritedPredicate(k))
|
|
47
51
|
continue;
|
|
48
52
|
const meta = { ...v };
|
|
49
|
-
if (partial === true ||
|
|
53
|
+
if (partial === true ||
|
|
54
|
+
(Array.isArray(partial) && partial.includes(v.name.toLowerCase()))) {
|
|
50
55
|
meta.required = false;
|
|
51
56
|
}
|
|
52
|
-
else if (required === true ||
|
|
57
|
+
else if (required === true ||
|
|
58
|
+
(Array.isArray(required) && required.includes(v.name.toLowerCase()))) {
|
|
53
59
|
meta.required = true;
|
|
54
60
|
}
|
|
55
61
|
const field = new ApiField(this, meta);
|
|
@@ -57,7 +63,8 @@ export const MappedType = function (...args) {
|
|
|
57
63
|
}
|
|
58
64
|
if (!_this.pick ||
|
|
59
65
|
_this.base.additionalFields === false ||
|
|
60
|
-
(Array.isArray(_this.base.additionalFields) &&
|
|
66
|
+
(Array.isArray(_this.base.additionalFields) &&
|
|
67
|
+
_this.base.additionalFields?.[0] === 'error')) {
|
|
61
68
|
_this.additionalFields = _this.base.additionalFields;
|
|
62
69
|
}
|
|
63
70
|
if (initArgs.base.keyField && isInheritedPredicate(initArgs.base.keyField))
|
|
@@ -79,7 +86,9 @@ class MappedTypeClass extends ComplexTypeBase {
|
|
|
79
86
|
return !!this.base?.extendsFrom(baseType);
|
|
80
87
|
}
|
|
81
88
|
toJSON() {
|
|
82
|
-
const baseName = this.base
|
|
89
|
+
const baseName = this.base
|
|
90
|
+
? this.node.getDataTypeNameWithNs(this.base)
|
|
91
|
+
: undefined;
|
|
83
92
|
return omitUndefined({
|
|
84
93
|
...ComplexTypeBase.prototype.toJSON.call(this),
|
|
85
94
|
base: baseName ? baseName : this.base.toJSON(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { omitUndefined } from '@jsopen/objects';
|
|
3
3
|
import { asMutable } from 'ts-gems';
|
|
4
|
-
import { inheritPropertyInitializers, mergePrototype } from '../../helpers/index.js';
|
|
4
|
+
import { inheritPropertyInitializers, mergePrototype, } from '../../helpers/index.js';
|
|
5
5
|
import { OpraSchema } from '../../schema/index.js';
|
|
6
6
|
import { DATATYPE_METADATA, DECORATOR } from '../constants.js';
|
|
7
7
|
import { ApiField } from './api-field.js';
|
|
@@ -73,7 +73,9 @@ MixinType[DECORATOR] = MixinTypeFactory;
|
|
|
73
73
|
function MixinTypeFactory(...args) {
|
|
74
74
|
// Filter undefined items
|
|
75
75
|
const clasRefs = args.filter(x => typeof x === 'function');
|
|
76
|
-
const options = typeof args[args.length - 1] === 'object'
|
|
76
|
+
const options = typeof args[args.length - 1] === 'object'
|
|
77
|
+
? args[args.length - 1]
|
|
78
|
+
: undefined;
|
|
77
79
|
if (!clasRefs.length)
|
|
78
80
|
throw new TypeError('No Class has been provided');
|
|
79
81
|
if (clasRefs.length === 1)
|
|
@@ -13,7 +13,9 @@ let BigintType = class BigintType extends NumberType {
|
|
|
13
13
|
x.push(vg.isGte(properties.minValue));
|
|
14
14
|
if (properties.maxValue)
|
|
15
15
|
x.push(vg.isLte(properties.maxValue));
|
|
16
|
-
return x.length > 0
|
|
16
|
+
return x.length > 0
|
|
17
|
+
? vg.pipe([toBigint, ...x], { returnIndex: 0 })
|
|
18
|
+
: toBigint;
|
|
17
19
|
}
|
|
18
20
|
[ENCODER](properties) {
|
|
19
21
|
return this[DECODER](properties);
|
|
@@ -13,7 +13,9 @@ let IntegerType = class IntegerType extends NumberType {
|
|
|
13
13
|
x.push(vg.isGte(properties.minValue));
|
|
14
14
|
if (properties.maxValue)
|
|
15
15
|
x.push(vg.isLte(properties.maxValue));
|
|
16
|
-
return x.length > 0
|
|
16
|
+
return x.length > 0
|
|
17
|
+
? vg.pipe([toInteger, ...x], { returnIndex: 0 })
|
|
18
|
+
: toInteger;
|
|
17
19
|
}
|
|
18
20
|
[ENCODER](properties) {
|
|
19
21
|
return this[DECODER](properties);
|
|
@@ -13,7 +13,9 @@ let NumberType = class NumberType {
|
|
|
13
13
|
x.push(vg.isGte(properties.minValue));
|
|
14
14
|
if (properties.maxValue)
|
|
15
15
|
x.push(vg.isLte(properties.maxValue));
|
|
16
|
-
return x.length > 0
|
|
16
|
+
return x.length > 0
|
|
17
|
+
? vg.pipe([toNumber, ...x], { returnIndex: 0 })
|
|
18
|
+
: toNumber;
|
|
17
19
|
}
|
|
18
20
|
[ENCODER](properties) {
|
|
19
21
|
return this[DECODER](properties);
|
|
@@ -21,7 +21,9 @@ let StringType = class StringType {
|
|
|
21
21
|
x.push(vg.lengthMin(properties.minLength));
|
|
22
22
|
if (properties.maxLength)
|
|
23
23
|
x.push(vg.lengthMax(properties.maxLength));
|
|
24
|
-
return x.length > 0
|
|
24
|
+
return x.length > 0
|
|
25
|
+
? vg.pipe([toString, ...x], { returnIndex: 0 })
|
|
26
|
+
: toString;
|
|
25
27
|
}
|
|
26
28
|
[ENCODER](properties) {
|
|
27
29
|
return this[DECODER](properties);
|
|
@@ -5,7 +5,7 @@ import { isAny } from 'valgen';
|
|
|
5
5
|
import { cloneObject } from '../../helpers/index.js';
|
|
6
6
|
import { OpraSchema } from '../../schema/index.js';
|
|
7
7
|
import { DECORATOR } from '../constants.js';
|
|
8
|
-
import { AttributeDecoratorFactory, SimpleTypeDecoratorFactory } from '../decorators/simple-type.decorator.js';
|
|
8
|
+
import { AttributeDecoratorFactory, SimpleTypeDecoratorFactory, } from '../decorators/simple-type.decorator.js';
|
|
9
9
|
import { DataType } from './data-type.js';
|
|
10
10
|
/**
|
|
11
11
|
* SimpleType constructor
|
|
@@ -28,7 +28,10 @@ export const SimpleType = function (...args) {
|
|
|
28
28
|
}
|
|
29
29
|
_this.properties = initArgs.properties;
|
|
30
30
|
_this.ownNameMappings = { ...initArgs.nameMappings };
|
|
31
|
-
_this.nameMappings = {
|
|
31
|
+
_this.nameMappings = {
|
|
32
|
+
..._this.base?.nameMappings,
|
|
33
|
+
...initArgs.nameMappings,
|
|
34
|
+
};
|
|
32
35
|
_this.ownAttributes = cloneObject(initArgs.attributes || {});
|
|
33
36
|
_this.attributes = _this.base ? cloneObject(_this.base.attributes) : {};
|
|
34
37
|
if (_this.ownAttributes) {
|
|
@@ -85,7 +88,9 @@ class SimpleTypeClass extends DataType {
|
|
|
85
88
|
}
|
|
86
89
|
else
|
|
87
90
|
properties = this.properties ? cloneObject(this.properties) : {};
|
|
88
|
-
const baseName = this.base
|
|
91
|
+
const baseName = this.base
|
|
92
|
+
? this.node.getDataTypeNameWithNs(this.base)
|
|
93
|
+
: undefined;
|
|
89
94
|
const out = omitUndefined({
|
|
90
95
|
...DataType.prototype.toJSON.apply(this),
|
|
91
96
|
base: this.base ? (baseName ? baseName : this.base.toJSON()) : undefined,
|