@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
|
@@ -28,6 +28,8 @@ export class NumberLiteral extends Literal {
|
|
|
28
28
|
throw new FilterValidationError(`Invalid number literal ${value}`);
|
|
29
29
|
}
|
|
30
30
|
toString() {
|
|
31
|
-
return typeof this.value === 'bigint'
|
|
31
|
+
return typeof this.value === 'bigint'
|
|
32
|
+
? ('' + this.value).replace(/n$/, '')
|
|
33
|
+
: '' + this.value;
|
|
32
34
|
}
|
|
33
35
|
}
|
|
@@ -45,7 +45,9 @@ export class FilterRules {
|
|
|
45
45
|
const rule = this._rules.get(ast.left.value);
|
|
46
46
|
if (!rule) {
|
|
47
47
|
throw new OpraException({
|
|
48
|
-
message: translate('error:UNACCEPTED_FILTER_FIELD', {
|
|
48
|
+
message: translate('error:UNACCEPTED_FILTER_FIELD', {
|
|
49
|
+
field: ast.left.value,
|
|
50
|
+
}),
|
|
49
51
|
code: 'UNACCEPTED_FILTER_FIELD',
|
|
50
52
|
details: {
|
|
51
53
|
field: ast.left.value,
|
|
@@ -55,7 +57,9 @@ export class FilterRules {
|
|
|
55
57
|
// Check if filtering endpoint accepted for given field
|
|
56
58
|
if (rule.operators && !rule.operators.includes(ast.op)) {
|
|
57
59
|
throw new OpraException({
|
|
58
|
-
message: translate('error:UNACCEPTED_FILTER_OPERATION', {
|
|
60
|
+
message: translate('error:UNACCEPTED_FILTER_OPERATION', {
|
|
61
|
+
field: ast.left.value,
|
|
62
|
+
}),
|
|
59
63
|
code: 'UNACCEPTED_FILTER_OPERATION',
|
|
60
64
|
details: {
|
|
61
65
|
field: ast.left.value,
|
|
@@ -105,11 +109,16 @@ export class FilterRules {
|
|
|
105
109
|
/** If calling for right side of comparison */
|
|
106
110
|
if (ast === comp.right || stack[compIdx + 1] === comp.right) {
|
|
107
111
|
/** Check if comparison expression left side is a field */
|
|
108
|
-
if (comp &&
|
|
112
|
+
if (comp &&
|
|
113
|
+
comp.left instanceof QualifiedIdentifier &&
|
|
114
|
+
comp.left.field) {
|
|
109
115
|
if (ast.value == null && !comp.left.field.required)
|
|
110
116
|
return ast.value;
|
|
111
117
|
let decoder;
|
|
112
|
-
if (comp.op === 'like' ||
|
|
118
|
+
if (comp.op === 'like' ||
|
|
119
|
+
comp.op === '!like' ||
|
|
120
|
+
comp.op === 'ilike' ||
|
|
121
|
+
comp.op === '!ilike') {
|
|
113
122
|
decoder = isString;
|
|
114
123
|
}
|
|
115
124
|
else
|
|
@@ -42,7 +42,8 @@ export class FilterTreeVisitor extends ParseTreeVisitor {
|
|
|
42
42
|
const items = [];
|
|
43
43
|
const wrapChildren = (arr, op) => {
|
|
44
44
|
for (const c of arr) {
|
|
45
|
-
if (c instanceof LogicalExpressionContext &&
|
|
45
|
+
if (c instanceof LogicalExpressionContext &&
|
|
46
|
+
c.logicalOperator().getText() === op) {
|
|
46
47
|
wrapChildren(c.expression_list(), c.logicalOperator().getText());
|
|
47
48
|
continue;
|
|
48
49
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ErrorListener } from '@browsery/antlr4';
|
|
1
|
+
import { ErrorListener, } from '@browsery/antlr4';
|
|
2
2
|
import { FilterParseError } from './errors.js';
|
|
3
3
|
export class OpraErrorListener extends ErrorListener {
|
|
4
4
|
constructor(errors) {
|
|
@@ -6,6 +6,12 @@ export class OpraErrorListener extends ErrorListener {
|
|
|
6
6
|
this.errors = errors;
|
|
7
7
|
}
|
|
8
8
|
syntaxError(recognizer, offendingSymbol, line, column, msg, e) {
|
|
9
|
-
this.errors.push(new FilterParseError(msg, {
|
|
9
|
+
this.errors.push(new FilterParseError(msg, {
|
|
10
|
+
recognizer,
|
|
11
|
+
offendingSymbol,
|
|
12
|
+
line,
|
|
13
|
+
column,
|
|
14
|
+
e,
|
|
15
|
+
}));
|
|
10
16
|
}
|
|
11
17
|
}
|
package/esm/filter/parse.js
CHANGED
|
@@ -21,7 +21,9 @@ export function parse(text, visitor) {
|
|
|
21
21
|
const errMsgs = [];
|
|
22
22
|
for (const err of errors) {
|
|
23
23
|
errMsgs.push(err.message +
|
|
24
|
-
(text.includes('\n')
|
|
24
|
+
(text.includes('\n')
|
|
25
|
+
? ' at line: ' + err.line + ' column: ' + err.column
|
|
26
|
+
: ' at column: ' + err.column));
|
|
25
27
|
}
|
|
26
28
|
const e = new SyntaxError(errMsgs.join('\n'));
|
|
27
29
|
e.errors = errors;
|
package/esm/filter/utils.js
CHANGED
|
@@ -11,7 +11,9 @@ export function quoteFilterString(s) {
|
|
|
11
11
|
return "'" + escapeString(s).replace(quotesRegEx, "\\'") + "'";
|
|
12
12
|
}
|
|
13
13
|
export function unquoteFilterString(s) {
|
|
14
|
-
if (s &&
|
|
14
|
+
if (s &&
|
|
15
|
+
(s.startsWith("'") || s.startsWith('"')) &&
|
|
16
|
+
s.endsWith(s.charAt(0))) {
|
|
15
17
|
return unescapeString(s.substring(1, s.length - 1));
|
|
16
18
|
}
|
|
17
19
|
/* istanbul ignore next */
|
|
@@ -14,7 +14,9 @@ export function getStackFileName(position = 1) {
|
|
|
14
14
|
if (stack !== null && typeof stack === 'object') {
|
|
15
15
|
// stack[0] holds this file
|
|
16
16
|
// stack[1] holds where this function was called
|
|
17
|
-
const s = stack[position]
|
|
17
|
+
const s = stack[position]
|
|
18
|
+
? stack[position].getFileName()
|
|
19
|
+
: undefined;
|
|
18
20
|
const m = s ? PATH_PATTERN.exec(s) : undefined;
|
|
19
21
|
return m ? m[1] : '';
|
|
20
22
|
}
|
|
@@ -35,7 +37,9 @@ export function getErrorStack(position = 1) {
|
|
|
35
37
|
if (stack !== null && typeof stack === 'object') {
|
|
36
38
|
// stack[0] holds this file
|
|
37
39
|
// stack[1] holds where this function was called
|
|
38
|
-
const s = stack[position]
|
|
40
|
+
const s = stack[position]
|
|
41
|
+
? stack[position].getFileName()
|
|
42
|
+
: undefined;
|
|
39
43
|
const m = s ? PATH_PATTERN.exec(s) : undefined;
|
|
40
44
|
return m ? m[1] : '';
|
|
41
45
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export function mergePrototype(targetProto, baseProto, filter) {
|
|
2
2
|
for (const k of Object.getOwnPropertyNames(baseProto)) {
|
|
3
|
-
if (k === 'constructor' ||
|
|
3
|
+
if (k === 'constructor' ||
|
|
4
|
+
k === '__proto__' ||
|
|
5
|
+
k === 'toJSON' ||
|
|
6
|
+
k === 'toString' ||
|
|
7
|
+
(filter && !filter(k))) {
|
|
4
8
|
continue;
|
|
5
9
|
}
|
|
6
10
|
Object.defineProperty(targetProto, k, Object.getOwnPropertyDescriptor(baseProto, k) || Object.create(null));
|
|
@@ -14,7 +18,8 @@ isPropertyInherited = (key) => true) {
|
|
|
14
18
|
const tempInstance = new clazz();
|
|
15
19
|
const propertyNames = Object.getOwnPropertyNames(tempInstance);
|
|
16
20
|
propertyNames
|
|
17
|
-
.filter(propertyName => typeof tempInstance[propertyName] !== 'undefined' &&
|
|
21
|
+
.filter(propertyName => typeof tempInstance[propertyName] !== 'undefined' &&
|
|
22
|
+
typeof target[propertyName] === 'undefined')
|
|
18
23
|
.filter(propertyName => isPropertyInherited(propertyName))
|
|
19
24
|
.forEach(propertyName => {
|
|
20
25
|
target[propertyName] = tempInstance[propertyName];
|
|
@@ -7,7 +7,9 @@ export function cloneObject(obj, jsonOnly) {
|
|
|
7
7
|
ignoreUndefined: true,
|
|
8
8
|
filter(key, source) {
|
|
9
9
|
const v = source[key];
|
|
10
|
-
return !jsonOnly ||
|
|
10
|
+
return (!jsonOnly ||
|
|
11
|
+
(typeof v !== 'function' &&
|
|
12
|
+
(typeof v !== 'object' || isPlainObject(v) || Array.isArray(v))));
|
|
11
13
|
},
|
|
12
14
|
});
|
|
13
15
|
}
|
|
@@ -46,14 +46,16 @@ export function parse(input, target) {
|
|
|
46
46
|
if (!m)
|
|
47
47
|
throw new TypeError(`Invalid field path (${input})`);
|
|
48
48
|
const fieldName = m[2];
|
|
49
|
-
const treeItem = (target[fieldName] =
|
|
49
|
+
const treeItem = (target[fieldName] =
|
|
50
|
+
target[fieldName] || new FieldsProjection.Item());
|
|
50
51
|
if (m[1])
|
|
51
52
|
treeItem.sign = m[1];
|
|
52
53
|
if (i === fields.length - 1) {
|
|
53
54
|
delete treeItem.projection;
|
|
54
55
|
}
|
|
55
56
|
else {
|
|
56
|
-
target = treeItem.projection =
|
|
57
|
+
target = treeItem.projection =
|
|
58
|
+
treeItem.projection || new FieldsProjection();
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
}
|
|
@@ -2,7 +2,9 @@ export function isStream(x) {
|
|
|
2
2
|
return x !== null && typeof x === 'object' && typeof x.pipe === 'function';
|
|
3
3
|
}
|
|
4
4
|
export function isReadable(x) {
|
|
5
|
-
return isStream(x) &&
|
|
5
|
+
return (isStream(x) &&
|
|
6
|
+
typeof x._read === 'function' &&
|
|
7
|
+
typeof x._readableState === 'object');
|
|
6
8
|
}
|
|
7
9
|
export function isWritable(x) {
|
|
8
10
|
return isStream(x) && typeof x._write === 'function';
|
|
@@ -28,5 +30,8 @@ export function isFormData(x) {
|
|
|
28
30
|
typeof x.getAll === 'function');
|
|
29
31
|
}
|
|
30
32
|
export function isURL(x) {
|
|
31
|
-
return x !== null &&
|
|
33
|
+
return (x !== null &&
|
|
34
|
+
typeof x == 'object' &&
|
|
35
|
+
typeof x.host === 'string' &&
|
|
36
|
+
typeof x.href === 'string');
|
|
32
37
|
}
|
package/esm/i18n/i18n.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import i18next from '@browsery/i18next';
|
|
2
2
|
import { splitString, tokenize } from 'fast-tokenizer';
|
|
3
3
|
import { unescapeString } from './string-utils.js';
|
|
4
|
-
|
|
4
|
+
// eslint-disable-next-line import-x/no-named-as-default-member
|
|
5
|
+
export const BaseI18n = Object.getPrototypeOf(i18next.createInstance())
|
|
6
|
+
.constructor;
|
|
5
7
|
export class I18n extends BaseI18n {
|
|
6
8
|
async init(arg0, arg1) {
|
|
7
9
|
const options = typeof arg0 === 'object' ? arg0 : {};
|
|
@@ -62,12 +64,20 @@ export class I18n extends BaseI18n {
|
|
|
62
64
|
})) {
|
|
63
65
|
if (token.startsWith('$t(') && token.endsWith(')')) {
|
|
64
66
|
token = token.substring(3, token.length - 1);
|
|
65
|
-
const a = splitString(token, {
|
|
67
|
+
const a = splitString(token, {
|
|
68
|
+
delimiters: '?',
|
|
69
|
+
quotes: true,
|
|
70
|
+
brackets: { '{': '}' },
|
|
71
|
+
});
|
|
66
72
|
const fallback = unescapeString(token.substring((a[0] || '').length + 1));
|
|
67
73
|
token = a[0] || '';
|
|
68
74
|
const keys = [];
|
|
69
75
|
let opts = null;
|
|
70
|
-
for (const token2 of tokenize(token, {
|
|
76
|
+
for (const token2 of tokenize(token, {
|
|
77
|
+
delimiters: ',',
|
|
78
|
+
quotes: true,
|
|
79
|
+
brackets: { '{': '}' },
|
|
80
|
+
})) {
|
|
71
81
|
if (token2.startsWith('{')) {
|
|
72
82
|
opts = JSON.parse(token2);
|
|
73
83
|
continue;
|
package/esm/i18n/translate.js
CHANGED
|
@@ -6,6 +6,8 @@ export function translate(key, arg0, arg1) {
|
|
|
6
6
|
return ('$t(' +
|
|
7
7
|
key +
|
|
8
8
|
(options ? ',' + JSON.stringify(options) : '') +
|
|
9
|
-
(fallback
|
|
9
|
+
(fallback
|
|
10
|
+
? '?' + escapeString(fallback).replace(bracketRegEx, '\\$1')
|
|
11
|
+
: '') +
|
|
10
12
|
')');
|
|
11
13
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
if (!Array.prototype.findLast) {
|
|
2
|
-
// eslint-disable-next-line no-extend-native
|
|
3
2
|
Array.prototype.findLast = function (predicate, thisArg) {
|
|
4
3
|
const i = this.findLastIndex(predicate, thisArg);
|
|
5
4
|
return i >= 0 ? this[i] : undefined;
|
|
6
5
|
};
|
|
7
|
-
// eslint-disable-next-line no-extend-native
|
|
8
6
|
Array.prototype.findLastIndex = function (predicate, thisArg) {
|
|
9
7
|
if (this == null) {
|
|
10
8
|
throw new TypeError('this is null or not defined');
|