@swaggerexpert/arazzo-criterion 1.0.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/LICENSE +202 -0
- package/NOTICE +20 -0
- package/README.md +406 -0
- package/SECURITY.md +15 -0
- package/cjs/apg-lite.cjs +1223 -0
- package/cjs/errors/ArazzoCriterionError.cjs +46 -0
- package/cjs/errors/ArazzoCriterionEvaluateError.cjs +10 -0
- package/cjs/errors/ArazzoCriterionParseError.cjs +10 -0
- package/cjs/evaluate/index.cjs +139 -0
- package/cjs/grammar.cjs +1111 -0
- package/cjs/index.cjs +83 -0
- package/cjs/parse/callbacks/cst.cjs +30 -0
- package/cjs/parse/index.cjs +42 -0
- package/cjs/parse/trace/Expectations.cjs +12 -0
- package/cjs/parse/trace/Trace.cjs +37 -0
- package/cjs/parse/translators/ASTTranslator/index.cjs +17 -0
- package/cjs/parse/translators/ASTTranslator/transformers.cjs +203 -0
- package/cjs/parse/translators/CSTTranslator.cjs +49 -0
- package/cjs/parse/translators/XMLTranslator.cjs +14 -0
- package/cjs/test/index.cjs +20 -0
- package/es/errors/ArazzoCriterionError.mjs +40 -0
- package/es/errors/ArazzoCriterionEvaluateError.mjs +3 -0
- package/es/errors/ArazzoCriterionParseError.mjs +3 -0
- package/es/evaluate/index.mjs +132 -0
- package/es/grammar.mjs +1105 -0
- package/es/index.mjs +11 -0
- package/es/parse/callbacks/cst.mjs +24 -0
- package/es/parse/index.mjs +35 -0
- package/es/parse/trace/Expectations.mjs +6 -0
- package/es/parse/trace/Trace.mjs +30 -0
- package/es/parse/translators/ASTTranslator/index.mjs +9 -0
- package/es/parse/translators/ASTTranslator/transformers.mjs +195 -0
- package/es/parse/translators/CSTTranslator.mjs +42 -0
- package/es/parse/translators/XMLTranslator.mjs +7 -0
- package/es/test/index.mjs +13 -0
- package/package.json +95 -0
- package/types/index.d.ts +283 -0
package/cjs/index.cjs
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ASTTranslator", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _index4.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ArazzoCriterionError", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _ArazzoCriterionError.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "ArazzoCriterionEvaluateError", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _ArazzoCriterionEvaluateError.default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "ArazzoCriterionParseError", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _ArazzoCriterionParseError.default;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "CSTTranslator", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _CSTTranslator.default;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "Grammar", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _grammar.default;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "Trace", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _Trace.default;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "XMLTranslator", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _XMLTranslator.default;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "evaluate", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _index3.default;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "parse", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _index.default;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "test", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _index2.default;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
var _grammar = _interopRequireDefault(require("./grammar.cjs"));
|
|
73
|
+
var _index = _interopRequireDefault(require("./parse/index.cjs"));
|
|
74
|
+
var _index2 = _interopRequireDefault(require("./test/index.cjs"));
|
|
75
|
+
var _index3 = _interopRequireDefault(require("./evaluate/index.cjs"));
|
|
76
|
+
var _CSTTranslator = _interopRequireDefault(require("./parse/translators/CSTTranslator.cjs"));
|
|
77
|
+
var _index4 = _interopRequireDefault(require("./parse/translators/ASTTranslator/index.cjs"));
|
|
78
|
+
var _XMLTranslator = _interopRequireDefault(require("./parse/translators/XMLTranslator.cjs"));
|
|
79
|
+
var _Trace = _interopRequireDefault(require("./parse/trace/Trace.cjs"));
|
|
80
|
+
var _ArazzoCriterionError = _interopRequireDefault(require("./errors/ArazzoCriterionError.cjs"));
|
|
81
|
+
var _ArazzoCriterionParseError = _interopRequireDefault(require("./errors/ArazzoCriterionParseError.cjs"));
|
|
82
|
+
var _ArazzoCriterionEvaluateError = _interopRequireDefault(require("./errors/ArazzoCriterionEvaluateError.cjs"));
|
|
83
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _apgLite = require("../../apg-lite.cjs");
|
|
8
|
+
const cst = nodeType => {
|
|
9
|
+
return (state, chars, phraseIndex, phraseLength, data) => {
|
|
10
|
+
if (state === _apgLite.identifiers.SEM_PRE) {
|
|
11
|
+
const node = {
|
|
12
|
+
type: nodeType,
|
|
13
|
+
text: _apgLite.utilities.charsToString(chars, phraseIndex, phraseLength),
|
|
14
|
+
start: phraseIndex,
|
|
15
|
+
length: phraseLength,
|
|
16
|
+
children: []
|
|
17
|
+
};
|
|
18
|
+
if (data.stack.length > 0) {
|
|
19
|
+
data.stack[data.stack.length - 1].children.push(node);
|
|
20
|
+
} else {
|
|
21
|
+
data.root = node;
|
|
22
|
+
}
|
|
23
|
+
data.stack.push(node);
|
|
24
|
+
}
|
|
25
|
+
if (state === _apgLite.identifiers.SEM_POST) {
|
|
26
|
+
data.stack.pop();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
var _default = exports.default = cst;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _apgLite = require("../apg-lite.cjs");
|
|
8
|
+
var _grammar = _interopRequireDefault(require("../grammar.cjs"));
|
|
9
|
+
var _index = _interopRequireDefault(require("./translators/ASTTranslator/index.cjs"));
|
|
10
|
+
var _Trace = _interopRequireDefault(require("./trace/Trace.cjs"));
|
|
11
|
+
var _ArazzoCriterionParseError = _interopRequireDefault(require("../errors/ArazzoCriterionParseError.cjs"));
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
const grammar = new _grammar.default();
|
|
14
|
+
const parse = (condition, {
|
|
15
|
+
startRule = 'condition',
|
|
16
|
+
stats = false,
|
|
17
|
+
trace = false,
|
|
18
|
+
translator = new _index.default()
|
|
19
|
+
} = {}) => {
|
|
20
|
+
if (typeof condition !== 'string') {
|
|
21
|
+
throw new TypeError('Criterion condition must be a string');
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const parser = new _apgLite.Parser();
|
|
25
|
+
if (translator) parser.ast = translator;
|
|
26
|
+
if (stats) parser.stats = new _apgLite.Stats();
|
|
27
|
+
if (trace) parser.trace = new _Trace.default();
|
|
28
|
+
const result = parser.parse(grammar, startRule, condition);
|
|
29
|
+
return {
|
|
30
|
+
result,
|
|
31
|
+
tree: result.success && translator ? parser.ast.getTree() : undefined,
|
|
32
|
+
stats: parser.stats,
|
|
33
|
+
trace: parser.trace
|
|
34
|
+
};
|
|
35
|
+
} catch (error) {
|
|
36
|
+
throw new _ArazzoCriterionParseError.default('Unexpected error during Arazzo Criterion parsing', {
|
|
37
|
+
cause: error,
|
|
38
|
+
condition
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var _default = exports.default = parse;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
class Expectations extends Array {
|
|
8
|
+
toString() {
|
|
9
|
+
return this.map(c => `"${String(c)}"`).join(', ');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
var _default = exports.default = Expectations;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _apgLite = require("../../apg-lite.cjs");
|
|
8
|
+
var _Expectations = _interopRequireDefault(require("./Expectations.cjs"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
class Trace extends _apgLite.Trace {
|
|
11
|
+
inferExpectations() {
|
|
12
|
+
const lines = this.displayTrace().split('\n');
|
|
13
|
+
const expectations = new Set();
|
|
14
|
+
let lastMatchedIndex = -1;
|
|
15
|
+
for (let i = 0; i < lines.length; i++) {
|
|
16
|
+
const line = lines[i];
|
|
17
|
+
|
|
18
|
+
// capture the max match line (first one that ends in a single character match)
|
|
19
|
+
if (line.includes('M|')) {
|
|
20
|
+
const textMatch = line.match(/]'(.*)'$/);
|
|
21
|
+
if (textMatch && textMatch[1]) {
|
|
22
|
+
lastMatchedIndex = i;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// collect terminal failures after the deepest successful match
|
|
27
|
+
if (i > lastMatchedIndex) {
|
|
28
|
+
const terminalFailMatch = line.match(/N\|\[TLS\(([^)]+)\)]/);
|
|
29
|
+
if (terminalFailMatch) {
|
|
30
|
+
expectations.add(terminalFailMatch[1]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return new _Expectations.default(...expectations);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
var _default = exports.default = Trace;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _CSTTranslator = _interopRequireDefault(require("../CSTTranslator.cjs"));
|
|
8
|
+
var _transformers = _interopRequireWildcard(require("./transformers.cjs"));
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
class ASTTranslator extends _CSTTranslator.default {
|
|
12
|
+
getTree() {
|
|
13
|
+
const cst = super.getTree();
|
|
14
|
+
return (0, _transformers.transformCSTtoAST)(cst, _transformers.default);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
var _default = exports.default = ASTTranslator;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.transformCSTtoAST = exports.default = void 0;
|
|
7
|
+
var _arazzoRuntimeExpression = require("@swaggerexpert/arazzo-runtime-expression");
|
|
8
|
+
var _index = _interopRequireDefault(require("../../index.cjs"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
const transformCSTtoAST = (node, transformerMap) => {
|
|
11
|
+
const transformer = transformerMap[node.type];
|
|
12
|
+
if (!transformer) {
|
|
13
|
+
throw new Error(`No transformer for CST node type: ${node.type}`);
|
|
14
|
+
}
|
|
15
|
+
return transformer(node);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// A basic-expr is not a registered CST rule, so its alternatives
|
|
19
|
+
// (paren-expr / comparison-expr / test-expr) and the literal alternatives
|
|
20
|
+
// (number / string / boolean / null) surface directly as children.
|
|
21
|
+
exports.transformCSTtoAST = transformCSTtoAST;
|
|
22
|
+
const OPERAND_TYPES = new Set(['paren-expr', 'comparison-expr', 'test-expr', 'runtime-expression-operand', 'number', 'string', 'boolean', 'null']);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Split an operand token at the boundary between its runtime-expression base and the
|
|
26
|
+
* trailing criterion navigation, returning both as text. The base is the longest
|
|
27
|
+
* leading substring that parses as a runtime expression.
|
|
28
|
+
*
|
|
29
|
+
* The grammar cannot find this boundary itself - a runtime expression and the
|
|
30
|
+
* criterion accessors both use "." - so it is resolved here by delegating to
|
|
31
|
+
* @swaggerexpert/arazzo-runtime-expression.
|
|
32
|
+
*/
|
|
33
|
+
const splitAtRuntimeExpression = operand => {
|
|
34
|
+
const full = (0, _arazzoRuntimeExpression.parse)(operand);
|
|
35
|
+
if (full.result.success) {
|
|
36
|
+
return {
|
|
37
|
+
expressionText: operand,
|
|
38
|
+
navigationText: ''
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// A failing parse reports how far it matched; walk down from there to the
|
|
43
|
+
// longest prefix that parses cleanly (robust against stopping mid-rule).
|
|
44
|
+
for (let n = full.result.maxMatched; n > 0; n -= 1) {
|
|
45
|
+
if ((0, _arazzoRuntimeExpression.parse)(operand.slice(0, n)).result.success) {
|
|
46
|
+
return {
|
|
47
|
+
expressionText: operand.slice(0, n),
|
|
48
|
+
navigationText: operand.slice(n)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
throw new Error(`Operand is not a valid runtime expression: "${operand}"`);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Parse a criterion navigation remainder (e.g. ".data[0].id") into a MemberAccess /
|
|
57
|
+
* IndexAccess path by parsing it against the grammar's `runtime-expression-navigation`
|
|
58
|
+
* rule (a secondary entry point); the ASTTranslator produces the path array directly.
|
|
59
|
+
* Throws if the remainder is not a valid accessor sequence.
|
|
60
|
+
*/
|
|
61
|
+
const parseNavigation = navigationText => {
|
|
62
|
+
const {
|
|
63
|
+
result,
|
|
64
|
+
tree
|
|
65
|
+
} = (0, _index.default)(navigationText, {
|
|
66
|
+
startRule: 'runtime-expression-navigation'
|
|
67
|
+
});
|
|
68
|
+
if (!result.success) {
|
|
69
|
+
throw new Error(`Invalid criterion navigation: "${navigationText}"`);
|
|
70
|
+
}
|
|
71
|
+
return tree;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Parse an operand token into its runtime-expression base and criterion navigation,
|
|
76
|
+
* both already parsed. `navigation` is an empty array when there are no accessors.
|
|
77
|
+
*/
|
|
78
|
+
const parseOperand = operand => {
|
|
79
|
+
const {
|
|
80
|
+
expressionText,
|
|
81
|
+
navigationText
|
|
82
|
+
} = splitAtRuntimeExpression(operand);
|
|
83
|
+
const runtimeExpression = {
|
|
84
|
+
type: 'RuntimeExpression',
|
|
85
|
+
text: expressionText,
|
|
86
|
+
expression: (0, _arazzoRuntimeExpression.parse)(expressionText).tree
|
|
87
|
+
};
|
|
88
|
+
const navigation = navigationText === '' ? [] : parseNavigation(navigationText);
|
|
89
|
+
return {
|
|
90
|
+
runtimeExpression,
|
|
91
|
+
navigation
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
const foldLeftAssociative = (operands, operator) => operands.reduce((left, right) => ({
|
|
95
|
+
type: 'LogicalExpression',
|
|
96
|
+
operator,
|
|
97
|
+
left,
|
|
98
|
+
right
|
|
99
|
+
}));
|
|
100
|
+
const transformers = {
|
|
101
|
+
['condition'](node) {
|
|
102
|
+
const child = node.children.find(c => c.type === 'logical-or-expr');
|
|
103
|
+
return transformCSTtoAST(child, transformers);
|
|
104
|
+
},
|
|
105
|
+
['logical-or-expr'](node) {
|
|
106
|
+
const operands = node.children.filter(c => c.type === 'logical-and-expr').map(c => transformCSTtoAST(c, transformers));
|
|
107
|
+
return operands.length === 1 ? operands[0] : foldLeftAssociative(operands, '||');
|
|
108
|
+
},
|
|
109
|
+
['logical-and-expr'](node) {
|
|
110
|
+
const operands = node.children.filter(c => OPERAND_TYPES.has(c.type)).map(c => transformCSTtoAST(c, transformers));
|
|
111
|
+
return operands.length === 1 ? operands[0] : foldLeftAssociative(operands, '&&');
|
|
112
|
+
},
|
|
113
|
+
['paren-expr'](node) {
|
|
114
|
+
const inner = node.children.find(c => c.type === 'logical-or-expr');
|
|
115
|
+
const argument = transformCSTtoAST(inner, transformers);
|
|
116
|
+
const negated = node.children.some(c => c.type === 'logical-not-op');
|
|
117
|
+
return negated ? {
|
|
118
|
+
type: 'UnaryExpression',
|
|
119
|
+
operator: '!',
|
|
120
|
+
argument
|
|
121
|
+
} : argument;
|
|
122
|
+
},
|
|
123
|
+
['test-expr'](node) {
|
|
124
|
+
const operandNode = node.children.find(c => OPERAND_TYPES.has(c.type));
|
|
125
|
+
const argument = transformCSTtoAST(operandNode, transformers);
|
|
126
|
+
const negated = node.children.some(c => c.type === 'logical-not-op');
|
|
127
|
+
return negated ? {
|
|
128
|
+
type: 'UnaryExpression',
|
|
129
|
+
operator: '!',
|
|
130
|
+
argument
|
|
131
|
+
} : argument;
|
|
132
|
+
},
|
|
133
|
+
['comparison-expr'](node) {
|
|
134
|
+
const operands = node.children.filter(c => OPERAND_TYPES.has(c.type));
|
|
135
|
+
const opNode = node.children.find(c => c.type === 'comparison-op');
|
|
136
|
+
return {
|
|
137
|
+
type: 'BinaryExpression',
|
|
138
|
+
operator: opNode.text,
|
|
139
|
+
left: transformCSTtoAST(operands[0], transformers),
|
|
140
|
+
right: transformCSTtoAST(operands[1], transformers)
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
['runtime-expression-operand'](node) {
|
|
144
|
+
const {
|
|
145
|
+
runtimeExpression,
|
|
146
|
+
navigation
|
|
147
|
+
} = parseOperand(node.text);
|
|
148
|
+
if (navigation.length === 0) return runtimeExpression;
|
|
149
|
+
return {
|
|
150
|
+
type: 'RuntimeExpressionNavigation',
|
|
151
|
+
expression: runtimeExpression,
|
|
152
|
+
navigation
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
['runtime-expression-navigation'](node) {
|
|
156
|
+
return node.children.filter(c => c.type === 'member-access' || c.type === 'index-access').map(c => transformCSTtoAST(c, transformers));
|
|
157
|
+
},
|
|
158
|
+
['member-access'](node) {
|
|
159
|
+
const nameNode = node.children.find(c => c.type === 'member-name');
|
|
160
|
+
return {
|
|
161
|
+
type: 'MemberAccess',
|
|
162
|
+
name: nameNode.text
|
|
163
|
+
};
|
|
164
|
+
},
|
|
165
|
+
['index-access'](node) {
|
|
166
|
+
const indexNode = node.children.find(c => c.type === 'index');
|
|
167
|
+
return {
|
|
168
|
+
type: 'IndexAccess',
|
|
169
|
+
value: Number(indexNode.text)
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
['number'](node) {
|
|
173
|
+
return {
|
|
174
|
+
type: 'Literal',
|
|
175
|
+
valueType: 'number',
|
|
176
|
+
value: Number(node.text)
|
|
177
|
+
};
|
|
178
|
+
},
|
|
179
|
+
['string'](node) {
|
|
180
|
+
// strip surrounding single quotes, then collapse doubled '' into a single '
|
|
181
|
+
const inner = node.text.slice(1, -1).replace(/''/g, "'");
|
|
182
|
+
return {
|
|
183
|
+
type: 'Literal',
|
|
184
|
+
valueType: 'string',
|
|
185
|
+
value: inner
|
|
186
|
+
};
|
|
187
|
+
},
|
|
188
|
+
['boolean'](node) {
|
|
189
|
+
return {
|
|
190
|
+
type: 'Literal',
|
|
191
|
+
valueType: 'boolean',
|
|
192
|
+
value: node.text === 'true'
|
|
193
|
+
};
|
|
194
|
+
},
|
|
195
|
+
['null'](node) {
|
|
196
|
+
return {
|
|
197
|
+
type: 'Literal',
|
|
198
|
+
valueType: 'null',
|
|
199
|
+
value: null
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
var _default = exports.default = transformers;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _apgLite = require("../../apg-lite.cjs");
|
|
8
|
+
var _cst = _interopRequireDefault(require("../callbacks/cst.cjs"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
class CSTTranslator extends _apgLite.Ast {
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
|
|
14
|
+
// logical / comparison spine
|
|
15
|
+
this.callbacks['condition'] = (0, _cst.default)('condition');
|
|
16
|
+
this.callbacks['logical-or-expr'] = (0, _cst.default)('logical-or-expr');
|
|
17
|
+
this.callbacks['logical-and-expr'] = (0, _cst.default)('logical-and-expr');
|
|
18
|
+
this.callbacks['paren-expr'] = (0, _cst.default)('paren-expr');
|
|
19
|
+
this.callbacks['comparison-expr'] = (0, _cst.default)('comparison-expr');
|
|
20
|
+
this.callbacks['test-expr'] = (0, _cst.default)('test-expr');
|
|
21
|
+
this.callbacks['logical-not-op'] = (0, _cst.default)('logical-not-op');
|
|
22
|
+
this.callbacks['comparison-op'] = (0, _cst.default)('comparison-op');
|
|
23
|
+
|
|
24
|
+
// comparable operand (runtime expression + navigation), captured as one token
|
|
25
|
+
this.callbacks['runtime-expression-operand'] = (0, _cst.default)('runtime-expression-operand');
|
|
26
|
+
|
|
27
|
+
// navigation (secondary entry point; parses the accessor remainder of an operand)
|
|
28
|
+
this.callbacks['runtime-expression-navigation'] = (0, _cst.default)('runtime-expression-navigation');
|
|
29
|
+
this.callbacks['member-access'] = (0, _cst.default)('member-access');
|
|
30
|
+
this.callbacks['index-access'] = (0, _cst.default)('index-access');
|
|
31
|
+
this.callbacks['member-name'] = (0, _cst.default)('member-name');
|
|
32
|
+
this.callbacks['index'] = (0, _cst.default)('index');
|
|
33
|
+
|
|
34
|
+
// literals
|
|
35
|
+
this.callbacks['number'] = (0, _cst.default)('number');
|
|
36
|
+
this.callbacks['string'] = (0, _cst.default)('string');
|
|
37
|
+
this.callbacks['boolean'] = (0, _cst.default)('boolean');
|
|
38
|
+
this.callbacks['null'] = (0, _cst.default)('null');
|
|
39
|
+
}
|
|
40
|
+
getTree() {
|
|
41
|
+
const data = {
|
|
42
|
+
stack: [],
|
|
43
|
+
root: null
|
|
44
|
+
};
|
|
45
|
+
this.translate(data);
|
|
46
|
+
return data.root;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
var _default = exports.default = CSTTranslator;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _CSTTranslator = _interopRequireDefault(require("./CSTTranslator.cjs"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
class XMLTranslator extends _CSTTranslator.default {
|
|
10
|
+
getTree() {
|
|
11
|
+
return this.toXml();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
var _default = exports.default = XMLTranslator;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _index = _interopRequireDefault(require("../parse/index.cjs"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
const test = condition => {
|
|
10
|
+
if (typeof condition !== 'string') return false;
|
|
11
|
+
try {
|
|
12
|
+
const {
|
|
13
|
+
result
|
|
14
|
+
} = (0, _index.default)(condition);
|
|
15
|
+
return result.success;
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var _default = exports.default = test;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
class ArazzoCriterionError extends Error {
|
|
2
|
+
constructor(message, options = undefined) {
|
|
3
|
+
super(message, options);
|
|
4
|
+
this.name = this.constructor.name;
|
|
5
|
+
if (typeof message === 'string') {
|
|
6
|
+
this.message = message;
|
|
7
|
+
}
|
|
8
|
+
if (typeof Error.captureStackTrace === 'function') {
|
|
9
|
+
Error.captureStackTrace(this, this.constructor);
|
|
10
|
+
} else {
|
|
11
|
+
this.stack = new Error(message).stack;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This needs to stay here until our minimum supported version of Node.js is >= 16.9.0.
|
|
16
|
+
* Node.js is >= 16.9.0 supports error causes natively.
|
|
17
|
+
*/
|
|
18
|
+
if (options != null && typeof options === 'object' && Object.hasOwn(options, 'cause') && !('cause' in this)) {
|
|
19
|
+
const {
|
|
20
|
+
cause
|
|
21
|
+
} = options;
|
|
22
|
+
this.cause = cause;
|
|
23
|
+
if (cause instanceof Error && 'stack' in cause) {
|
|
24
|
+
this.stack = `${this.stack}\nCAUSE: ${cause.stack}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Allows to assign arbitrary properties to the error object.
|
|
30
|
+
*/
|
|
31
|
+
if (options != null && typeof options === 'object') {
|
|
32
|
+
const {
|
|
33
|
+
cause,
|
|
34
|
+
...causelessOptions
|
|
35
|
+
} = options;
|
|
36
|
+
Object.assign(this, causelessOptions);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export default ArazzoCriterionError;
|