@opra/common 1.4.3 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/index.cjs +5 -5
- package/browser/index.mjs +5 -5
- package/cjs/document/api-document.js +16 -9
- package/cjs/document/common/api-base.js +4 -2
- package/cjs/document/common/data-type-map.js +14 -3
- package/cjs/document/common/document-init-context.js +5 -0
- package/cjs/document/common/document-node.js +25 -29
- package/cjs/document/common/value.js +9 -3
- package/cjs/document/constants.js +1 -2
- package/cjs/document/data-type/api-field.js +19 -4
- package/cjs/document/data-type/complex-type-base.js +24 -7
- package/cjs/document/data-type/complex-type.js +17 -6
- package/cjs/document/data-type/data-type.js +16 -1
- package/cjs/document/data-type/enum-type.js +12 -3
- package/cjs/document/data-type/extended-types/base64.type.js +1 -0
- package/cjs/document/data-type/extended-types/date-string.type.js +1 -0
- package/cjs/document/data-type/extended-types/date-time-string.type.js +1 -0
- package/cjs/document/data-type/extended-types/date-time.type.js +6 -1
- package/cjs/document/data-type/extended-types/date.type.js +6 -1
- package/cjs/document/data-type/extended-types/email.type.js +1 -0
- package/cjs/document/data-type/extended-types/field-path.type.js +9 -3
- package/cjs/document/data-type/extended-types/filter.type.js +14 -5
- package/cjs/document/data-type/extended-types/object-id.type.js +1 -0
- package/cjs/document/data-type/extended-types/operation-result.type.js +1 -0
- package/cjs/document/data-type/extended-types/time.type.js +1 -0
- package/cjs/document/data-type/extended-types/url.type.js +1 -0
- package/cjs/document/data-type/extended-types/uuid.type.js +1 -0
- package/cjs/document/data-type/mapped-type.js +21 -9
- package/cjs/document/data-type/mixin-type.js +10 -5
- package/cjs/document/data-type/primitive-types/any.type.js +1 -0
- package/cjs/document/data-type/primitive-types/bigint.type.js +4 -1
- package/cjs/document/data-type/primitive-types/boolean.type.js +1 -0
- package/cjs/document/data-type/primitive-types/integer.type.js +4 -1
- package/cjs/document/data-type/primitive-types/null.type.js +1 -0
- package/cjs/document/data-type/primitive-types/number.type.js +4 -1
- package/cjs/document/data-type/primitive-types/string.type.js +4 -1
- package/cjs/document/data-type/simple-type.js +17 -5
- 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/complex-type.decorator.js +1 -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 +3 -2
- package/cjs/document/factory/api-document.factory.js +12 -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-api.js +2 -2
- package/cjs/document/http/http-controller.js +7 -6
- package/cjs/document/http/http-media-type.js +18 -8
- package/cjs/document/http/http-multipart-field.js +2 -2
- package/cjs/document/http/http-operation-response.js +11 -6
- package/cjs/document/http/http-operation.js +8 -6
- package/cjs/document/http/http-parameter.js +2 -2
- package/cjs/document/http/http-request-body.js +4 -2
- 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 +18 -8
- 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 +17 -10
- package/esm/document/common/api-base.js +4 -2
- package/esm/document/common/data-type-map.js +14 -3
- package/esm/document/common/document-init-context.js +5 -0
- package/esm/document/common/document-node.js +25 -29
- package/esm/document/common/value.js +9 -3
- package/esm/document/constants.js +0 -1
- package/esm/document/data-type/api-field.js +19 -4
- package/esm/document/data-type/complex-type-base.js +25 -8
- package/esm/document/data-type/complex-type.js +17 -6
- package/esm/document/data-type/data-type.js +17 -2
- package/esm/document/data-type/enum-type.js +12 -3
- package/esm/document/data-type/extended-types/base64.type.js +1 -0
- package/esm/document/data-type/extended-types/date-string.type.js +1 -0
- package/esm/document/data-type/extended-types/date-time-string.type.js +1 -0
- package/esm/document/data-type/extended-types/date-time.type.js +6 -1
- package/esm/document/data-type/extended-types/date.type.js +6 -1
- package/esm/document/data-type/extended-types/email.type.js +1 -0
- package/esm/document/data-type/extended-types/field-path.type.js +9 -3
- package/esm/document/data-type/extended-types/filter.type.js +14 -5
- package/esm/document/data-type/extended-types/object-id.type.js +1 -0
- package/esm/document/data-type/extended-types/operation-result.type.js +1 -0
- package/esm/document/data-type/extended-types/time.type.js +1 -0
- package/esm/document/data-type/extended-types/url.type.js +1 -0
- package/esm/document/data-type/extended-types/uuid.type.js +1 -0
- package/esm/document/data-type/mapped-type.js +21 -9
- package/esm/document/data-type/mixin-type.js +11 -6
- package/esm/document/data-type/primitive-types/any.type.js +1 -0
- package/esm/document/data-type/primitive-types/bigint.type.js +4 -1
- package/esm/document/data-type/primitive-types/boolean.type.js +1 -0
- package/esm/document/data-type/primitive-types/integer.type.js +4 -1
- package/esm/document/data-type/primitive-types/null.type.js +1 -0
- package/esm/document/data-type/primitive-types/number.type.js +4 -1
- package/esm/document/data-type/primitive-types/string.type.js +4 -1
- package/esm/document/data-type/simple-type.js +18 -6
- 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 +2 -2
- 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 +4 -3
- package/esm/document/factory/api-document.factory.js +12 -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-api.js +2 -2
- package/esm/document/http/http-controller.js +8 -7
- package/esm/document/http/http-media-type.js +18 -8
- package/esm/document/http/http-multipart-field.js +2 -2
- package/esm/document/http/http-operation-response.js +11 -6
- package/esm/document/http/http-operation.js +9 -7
- package/esm/document/http/http-parameter.js +3 -3
- package/esm/document/http/http-request-body.js +4 -2
- 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 +18 -8
- 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
- package/types/document/api-document.d.ts +8 -2
- package/types/document/common/api-base.d.ts +1 -1
- package/types/document/common/document-init-context.d.ts +2 -0
- package/types/document/common/document-node.d.ts +8 -14
- package/types/document/common/value.d.ts +2 -1
- package/types/document/constants.d.ts +0 -1
- package/types/document/data-type/api-field.d.ts +6 -11
- package/types/document/data-type/complex-type.d.ts +2 -1
- package/types/document/data-type/data-type.d.ts +7 -2
- package/types/document/data-type/enum-type.d.ts +2 -1
- package/types/document/data-type/extended-types/field-path.type.d.ts +2 -1
- package/types/document/data-type/extended-types/filter.type.d.ts +2 -1
- package/types/document/data-type/mapped-type.d.ts +2 -1
- package/types/document/data-type/mixin-type.d.ts +2 -1
- package/types/document/data-type/simple-type.d.ts +2 -1
- package/types/document/factory/api-document.factory.d.ts +2 -1
- package/types/document/http/http-api.d.ts +1 -1
- package/types/document/http/http-controller.d.ts +2 -1
- package/types/document/http/http-media-type.d.ts +2 -1
- package/types/document/http/http-multipart-field.d.ts +2 -1
- package/types/document/http/http-operation-response.d.ts +2 -1
- package/types/document/http/http-operation.d.ts +2 -1
- package/types/document/http/http-parameter.d.ts +2 -1
- package/types/document/http/http-request-body.d.ts +2 -1
- package/types/filter/filter-rules.d.ts +3 -3
|
@@ -32,11 +32,12 @@ class FilterRules {
|
|
|
32
32
|
operators,
|
|
33
33
|
}));
|
|
34
34
|
}
|
|
35
|
-
normalizeFilter(filter, currentType) {
|
|
35
|
+
normalizeFilter(filter, currentType, element) {
|
|
36
36
|
const ast = typeof filter === 'string' ? (0, parse_js_1.parse)(filter) : filter;
|
|
37
|
-
|
|
37
|
+
const doc = element?.node.getDocument();
|
|
38
|
+
return this.normalizeFilterAst(ast, [], currentType, doc?.scopes);
|
|
38
39
|
}
|
|
39
|
-
normalizeFilterAst(ast, stack, currentType) {
|
|
40
|
+
normalizeFilterAst(ast, stack, currentType, scopes) {
|
|
40
41
|
if (ast instanceof index_js_4.ComparisonExpression) {
|
|
41
42
|
stack.push(ast);
|
|
42
43
|
this.normalizeFilterAst(ast.left, stack, currentType);
|
|
@@ -48,7 +49,9 @@ class FilterRules {
|
|
|
48
49
|
const rule = this._rules.get(ast.left.value);
|
|
49
50
|
if (!rule) {
|
|
50
51
|
throw new index_js_1.OpraException({
|
|
51
|
-
message: (0, index_js_3.translate)('error:UNACCEPTED_FILTER_FIELD', {
|
|
52
|
+
message: (0, index_js_3.translate)('error:UNACCEPTED_FILTER_FIELD', {
|
|
53
|
+
field: ast.left.value,
|
|
54
|
+
}),
|
|
52
55
|
code: 'UNACCEPTED_FILTER_FIELD',
|
|
53
56
|
details: {
|
|
54
57
|
field: ast.left.value,
|
|
@@ -58,7 +61,9 @@ class FilterRules {
|
|
|
58
61
|
// Check if filtering endpoint accepted for given field
|
|
59
62
|
if (rule.operators && !rule.operators.includes(ast.op)) {
|
|
60
63
|
throw new index_js_1.OpraException({
|
|
61
|
-
message: (0, index_js_3.translate)('error:UNACCEPTED_FILTER_OPERATION', {
|
|
64
|
+
message: (0, index_js_3.translate)('error:UNACCEPTED_FILTER_OPERATION', {
|
|
65
|
+
field: ast.left.value,
|
|
66
|
+
}),
|
|
62
67
|
code: 'UNACCEPTED_FILTER_OPERATION',
|
|
63
68
|
details: {
|
|
64
69
|
field: ast.left.value,
|
|
@@ -108,20 +113,25 @@ class FilterRules {
|
|
|
108
113
|
/** If calling for right side of comparison */
|
|
109
114
|
if (ast === comp.right || stack[compIdx + 1] === comp.right) {
|
|
110
115
|
/** Check if comparison expression left side is a field */
|
|
111
|
-
if (comp &&
|
|
116
|
+
if (comp &&
|
|
117
|
+
comp.left instanceof index_js_4.QualifiedIdentifier &&
|
|
118
|
+
comp.left.field) {
|
|
112
119
|
if (ast.value == null && !comp.left.field.required)
|
|
113
120
|
return ast.value;
|
|
114
121
|
let decoder;
|
|
115
|
-
if (comp.op === 'like' ||
|
|
122
|
+
if (comp.op === 'like' ||
|
|
123
|
+
comp.op === '!like' ||
|
|
124
|
+
comp.op === 'ilike' ||
|
|
125
|
+
comp.op === '!ilike') {
|
|
116
126
|
decoder = valgen_1.isString;
|
|
117
127
|
}
|
|
118
128
|
else
|
|
119
129
|
decoder = this._decoderCache.get(comp.left.field);
|
|
120
130
|
if (!decoder) {
|
|
121
131
|
decoder = comp.left.field.type.generateCodec('decode', {
|
|
132
|
+
scope: scopes,
|
|
122
133
|
projection: '*',
|
|
123
134
|
ignoreWriteonlyFields: true,
|
|
124
|
-
ignoreHiddenFields: true,
|
|
125
135
|
coerce: true,
|
|
126
136
|
});
|
|
127
137
|
this._decoderCache.set(comp.left.field, decoder);
|
|
@@ -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
|
}
|
|
@@ -62,13 +64,14 @@ export class ApiDocument extends DocumentElement {
|
|
|
62
64
|
/**
|
|
63
65
|
* Export as Opra schema definition object
|
|
64
66
|
*/
|
|
65
|
-
export() {
|
|
67
|
+
export(options) {
|
|
66
68
|
const out = omitUndefined({
|
|
67
69
|
spec: OpraSchema.SpecVersion,
|
|
68
70
|
id: this.id,
|
|
69
71
|
url: this.url,
|
|
70
72
|
info: cloneObject(this.info, true),
|
|
71
73
|
});
|
|
74
|
+
options = options || { scopes: this.scopes };
|
|
72
75
|
if (this.references.size) {
|
|
73
76
|
let i = 0;
|
|
74
77
|
const references = {};
|
|
@@ -88,25 +91,29 @@ export class ApiDocument extends DocumentElement {
|
|
|
88
91
|
if (this.types.size) {
|
|
89
92
|
out.types = {};
|
|
90
93
|
for (const v of this.types.values()) {
|
|
91
|
-
|
|
94
|
+
if (!v.inScope(options.scopes))
|
|
95
|
+
continue;
|
|
96
|
+
out.types[v.name] = v.toJSON(options);
|
|
92
97
|
}
|
|
93
98
|
}
|
|
94
99
|
if (this.api)
|
|
95
|
-
out.api = this.api.toJSON();
|
|
100
|
+
out.api = this.api.toJSON(options);
|
|
96
101
|
return out;
|
|
97
102
|
}
|
|
98
103
|
invalidate() {
|
|
99
104
|
/** Generate id */
|
|
100
|
-
const x = this.export();
|
|
105
|
+
const x = this.export({});
|
|
101
106
|
delete x.id;
|
|
102
107
|
this.id = md5(JSON.stringify(x));
|
|
103
108
|
/** Clear [kTypeNSMap] */
|
|
104
109
|
this[kTypeNSMap] = new WeakMap();
|
|
105
110
|
}
|
|
106
|
-
_findDataType(nameOrCtor, visitedRefs) {
|
|
111
|
+
_findDataType(nameOrCtor, scope, visitedRefs) {
|
|
107
112
|
let result = this.types.get(nameOrCtor);
|
|
108
|
-
if (result
|
|
113
|
+
if (result && result.inScope(scope))
|
|
109
114
|
return result;
|
|
115
|
+
if (!this.references.size)
|
|
116
|
+
return;
|
|
110
117
|
// Lookup for references
|
|
111
118
|
if (typeof nameOrCtor === 'string') {
|
|
112
119
|
// If given string has namespace pattern (ns:type_name)
|
|
@@ -120,7 +127,7 @@ export class ApiDocument extends DocumentElement {
|
|
|
120
127
|
visitedRefs = visitedRefs || new WeakMap();
|
|
121
128
|
visitedRefs.set(this, true);
|
|
122
129
|
visitedRefs.set(ref, true);
|
|
123
|
-
return ref._findDataType(m[2], visitedRefs);
|
|
130
|
+
return ref._findDataType(m[2], scope, visitedRefs);
|
|
124
131
|
}
|
|
125
132
|
nameOrCtor = m[2];
|
|
126
133
|
}
|
|
@@ -142,7 +149,7 @@ export class ApiDocument extends DocumentElement {
|
|
|
142
149
|
for (const refNs of references) {
|
|
143
150
|
const ref = this.references.get(refNs);
|
|
144
151
|
visitedRefs.set(ref, true);
|
|
145
|
-
result = ref._findDataType(nameOrCtor, visitedRefs);
|
|
152
|
+
result = ref._findDataType(nameOrCtor, scope, visitedRefs);
|
|
146
153
|
if (result) {
|
|
147
154
|
this[kTypeNSMap].set(result, ref?.[BUILTIN] ? '' : refNs);
|
|
148
155
|
return result;
|
|
@@ -8,15 +8,17 @@ export class ApiBase extends DocumentElement {
|
|
|
8
8
|
this.name = init.name;
|
|
9
9
|
this.description = init.description;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
+
toJSON(options) {
|
|
12
13
|
return omitUndefined({
|
|
13
14
|
transport: this.transport,
|
|
14
15
|
name: this.name,
|
|
15
16
|
description: this.description,
|
|
16
17
|
});
|
|
17
18
|
}
|
|
19
|
+
async _initialize(init,
|
|
18
20
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
|
-
|
|
21
|
+
context) {
|
|
20
22
|
if (!CLASS_NAME_PATTERN.test(init.name))
|
|
21
23
|
throw new TypeError(`Invalid api name (${init.name})`);
|
|
22
24
|
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() {
|
|
@@ -6,6 +6,11 @@ export class DocumentInitContext {
|
|
|
6
6
|
this.showErrorDetails = true;
|
|
7
7
|
this.maxErrors = options?.maxErrors || 0;
|
|
8
8
|
this.error.message = '';
|
|
9
|
+
this.scopes = options?.scopes
|
|
10
|
+
? Array.isArray(options.scopes)
|
|
11
|
+
? options?.scopes
|
|
12
|
+
: [options?.scopes]
|
|
13
|
+
: undefined;
|
|
9
14
|
}
|
|
10
15
|
addError(error) {
|
|
11
16
|
if (!this.error.details.length) {
|
|
@@ -18,25 +18,24 @@ export class DocumentNode {
|
|
|
18
18
|
// istanbul ignore next
|
|
19
19
|
throw new Error('ApiDocument not found in document tree');
|
|
20
20
|
}
|
|
21
|
-
hasDataType(nameOrCtor) {
|
|
22
|
-
|
|
23
|
-
if (result)
|
|
24
|
-
return result;
|
|
25
|
-
return this.parent ? this.parent.hasDataType(nameOrCtor) : false;
|
|
21
|
+
hasDataType(nameOrCtor, scope) {
|
|
22
|
+
return !!this.findDataType(nameOrCtor, scope);
|
|
26
23
|
}
|
|
27
|
-
findDataType(nameOrCtor) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
findDataType(nameOrCtor, scope) {
|
|
25
|
+
scope = scope || this.getDocument().scopes;
|
|
26
|
+
const dt = this[kDataTypeMap]?.get(nameOrCtor);
|
|
27
|
+
if (dt && dt.inScope(scope))
|
|
28
|
+
return dt;
|
|
29
|
+
return this.parent
|
|
30
|
+
? this.parent.findDataType(nameOrCtor, scope)
|
|
31
|
+
: undefined;
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Returns DataType instance by name or Constructor. Returns undefined if not found
|
|
35
|
-
* @param nameOrCtor
|
|
36
35
|
*/
|
|
37
|
-
getDataType(nameOrCtor) {
|
|
36
|
+
getDataType(nameOrCtor, scope) {
|
|
38
37
|
const dt = this.findDataType(nameOrCtor);
|
|
39
|
-
if (dt)
|
|
38
|
+
if (dt && dt.inScope(scope))
|
|
40
39
|
return dt;
|
|
41
40
|
let name = '';
|
|
42
41
|
if (typeof nameOrCtor === 'function') {
|
|
@@ -53,7 +52,9 @@ export class DocumentNode {
|
|
|
53
52
|
else if (typeof nameOrCtor === 'function')
|
|
54
53
|
name = nameOrCtor.name;
|
|
55
54
|
}
|
|
56
|
-
|
|
55
|
+
if (dt)
|
|
56
|
+
throw new TypeError(`Data type${name ? ' (' + name + ')' : ''} is not in requested scope (${scope})`);
|
|
57
|
+
throw new TypeError(`Unknown data type${name ? ' (' + name + ')' : ''}`);
|
|
57
58
|
}
|
|
58
59
|
getDataTypeNameWithNs(dataType) {
|
|
59
60
|
if (!dataType.name)
|
|
@@ -65,10 +66,9 @@ export class DocumentNode {
|
|
|
65
66
|
* Returns ComplexType instance by name or Constructor.
|
|
66
67
|
* Returns undefined if not found
|
|
67
68
|
* Throws error if data type is not a ComplexType
|
|
68
|
-
* @param nameOrCtor
|
|
69
69
|
*/
|
|
70
|
-
getComplexType(nameOrCtor) {
|
|
71
|
-
const t = this.getDataType(nameOrCtor);
|
|
70
|
+
getComplexType(nameOrCtor, scope) {
|
|
71
|
+
const t = this.getDataType(nameOrCtor, scope);
|
|
72
72
|
if (t.kind === OpraSchema.ComplexType.Kind)
|
|
73
73
|
return t;
|
|
74
74
|
throw new TypeError(`Data type "${t.name}" is not a ComplexType`);
|
|
@@ -77,10 +77,9 @@ export class DocumentNode {
|
|
|
77
77
|
* Returns SimpleType instance by name or Constructor.
|
|
78
78
|
* Returns undefined if not found
|
|
79
79
|
* Throws error if data type is not a SimpleType
|
|
80
|
-
* @param nameOrCtor
|
|
81
80
|
*/
|
|
82
|
-
getSimpleType(nameOrCtor) {
|
|
83
|
-
const t = this.getDataType(nameOrCtor);
|
|
81
|
+
getSimpleType(nameOrCtor, scope) {
|
|
82
|
+
const t = this.getDataType(nameOrCtor, scope);
|
|
84
83
|
if (t.kind === OpraSchema.SimpleType.Kind)
|
|
85
84
|
return t;
|
|
86
85
|
throw new TypeError(`Data type "${t.name || t}" is not a SimpleType`);
|
|
@@ -89,10 +88,9 @@ export class DocumentNode {
|
|
|
89
88
|
* Returns EnumType instance by name or Constructor.
|
|
90
89
|
* Returns undefined if not found
|
|
91
90
|
* Throws error if data type is not a EnumType
|
|
92
|
-
* @param nameOrCtor
|
|
93
91
|
*/
|
|
94
|
-
getEnumType(nameOrCtor) {
|
|
95
|
-
const t = this.getDataType(nameOrCtor);
|
|
92
|
+
getEnumType(nameOrCtor, scope) {
|
|
93
|
+
const t = this.getDataType(nameOrCtor, scope);
|
|
96
94
|
if (t.kind === OpraSchema.EnumType.Kind)
|
|
97
95
|
return t;
|
|
98
96
|
throw new TypeError(`Data type "${t.name || t}" is not a EnumType`);
|
|
@@ -101,10 +99,9 @@ export class DocumentNode {
|
|
|
101
99
|
* Returns EnumType instance by name or Constructor.
|
|
102
100
|
* Returns undefined if not found
|
|
103
101
|
* Throws error if data type is not a MappedType
|
|
104
|
-
* @param nameOrCtor
|
|
105
102
|
*/
|
|
106
|
-
getMappedType(nameOrCtor) {
|
|
107
|
-
const t = this.getDataType(nameOrCtor);
|
|
103
|
+
getMappedType(nameOrCtor, scope) {
|
|
104
|
+
const t = this.getDataType(nameOrCtor, scope);
|
|
108
105
|
if (t.kind === OpraSchema.MappedType.Kind)
|
|
109
106
|
return t;
|
|
110
107
|
throw new TypeError(`Data type "${t.name || t}" is not a MappedType`);
|
|
@@ -113,10 +110,9 @@ export class DocumentNode {
|
|
|
113
110
|
* Returns EnumType instance by name or Constructor.
|
|
114
111
|
* Returns undefined if not found
|
|
115
112
|
* Throws error if data type is not a MixinType
|
|
116
|
-
* @param nameOrCtor
|
|
117
113
|
*/
|
|
118
|
-
getMixinType(nameOrCtor) {
|
|
119
|
-
const t = this.getDataType(nameOrCtor);
|
|
114
|
+
getMixinType(nameOrCtor, scope) {
|
|
115
|
+
const t = this.getDataType(nameOrCtor, scope);
|
|
120
116
|
if (t.kind === OpraSchema.MixinType.Kind)
|
|
121
117
|
return t;
|
|
122
118
|
throw new TypeError(`Data type "${t.name || t}" is not a MixinType`);
|
|
@@ -17,10 +17,16 @@ export const Value = function (owner, initArgs) {
|
|
|
17
17
|
* @class Value
|
|
18
18
|
*/
|
|
19
19
|
class ValueClass extends DocumentElement {
|
|
20
|
-
toJSON() {
|
|
21
|
-
const typeName = this.type
|
|
20
|
+
toJSON(options) {
|
|
21
|
+
const typeName = this.type
|
|
22
|
+
? this.node.getDataTypeNameWithNs(this.type)
|
|
23
|
+
: undefined;
|
|
22
24
|
return omitUndefined({
|
|
23
|
-
type: this.type
|
|
25
|
+
type: this.type
|
|
26
|
+
? typeName
|
|
27
|
+
? typeName
|
|
28
|
+
: this.type.toJSON(options)
|
|
29
|
+
: 'any',
|
|
24
30
|
description: this.description,
|
|
25
31
|
isArray: this.isArray,
|
|
26
32
|
examples: this.examples,
|
|
@@ -7,7 +7,6 @@ export const DECORATOR = Symbol.for('DECORATOR');
|
|
|
7
7
|
export const BUILTIN = Symbol.for('BUILTIN');
|
|
8
8
|
export const NAMESPACE_PATTERN = /([a-z$_]\w+):(.+)/i;
|
|
9
9
|
export const CLASS_NAME_PATTERN = /^[a-z][\w_]*$/i;
|
|
10
|
-
export const EXTRACT_TYPENAME_PATTERN = /^(.*)Type(\d*)$/;
|
|
11
10
|
export const kDataTypeMap = Symbol.for('kDataTypeMap');
|
|
12
11
|
export const kCtorMap = Symbol.for('kCtorMap');
|
|
13
12
|
export const kTypeNSMap = Symbol.for('kTypeNSMap');
|
|
@@ -25,6 +25,7 @@ export const ApiField = function (...args) {
|
|
|
25
25
|
throw new Error('Field origin should be one of ComplexType, MappedType or MixinType');
|
|
26
26
|
}
|
|
27
27
|
_this.origin = origin;
|
|
28
|
+
_this.scopes = initArgs.scopes;
|
|
28
29
|
_this.type = initArgs.type || owner.node.getDataType('any');
|
|
29
30
|
_this.description = initArgs.description;
|
|
30
31
|
_this.isArray = initArgs.isArray;
|
|
@@ -38,17 +39,31 @@ export const ApiField = function (...args) {
|
|
|
38
39
|
_this.readonly = initArgs.readonly;
|
|
39
40
|
_this.writeonly = initArgs.writeonly;
|
|
40
41
|
_this.examples = initArgs.examples;
|
|
41
|
-
_this.hidden = initArgs.hidden;
|
|
42
42
|
};
|
|
43
43
|
/**
|
|
44
44
|
*
|
|
45
45
|
* @class ApiField
|
|
46
46
|
*/
|
|
47
47
|
class ApiFieldClass extends DocumentElement {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
inScope(scopes) {
|
|
49
|
+
if (!this.scopes?.length || !scopes)
|
|
50
|
+
return true;
|
|
51
|
+
/** this.scope should match all required scopes */
|
|
52
|
+
scopes = Array.isArray(scopes) ? scopes : [scopes];
|
|
53
|
+
for (const scope of scopes) {
|
|
54
|
+
if (!this.scopes.some(s => {
|
|
55
|
+
return typeof s === 'string' ? scope === s : s.test(scope);
|
|
56
|
+
}))
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
toJSON(options) {
|
|
62
|
+
const typeName = this.type
|
|
63
|
+
? this.node.getDataTypeNameWithNs(this.type)
|
|
64
|
+
: undefined;
|
|
50
65
|
return omitUndefined({
|
|
51
|
-
type: typeName ? typeName : this.type?.toJSON(),
|
|
66
|
+
type: typeName ? typeName : this.type?.toJSON(options),
|
|
52
67
|
description: this.description,
|
|
53
68
|
isArray: this.isArray || undefined,
|
|
54
69
|
default: this.default,
|