@libreflare/worker-runtime 0.8.3 → 0.9.1
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/README.md +230 -23
- package/dist/log-handler.d.ts.map +1 -1
- package/dist/log-handler.js +12 -6
- package/dist/log-handler.js.map +1 -1
- package/dist/rule-evaluator/access-values.d.ts +19 -6
- package/dist/rule-evaluator/access-values.d.ts.map +1 -1
- package/dist/rule-evaluator/access-values.js +33 -8
- package/dist/rule-evaluator/access-values.js.map +1 -1
- package/dist/rule-evaluator/analysis.d.ts +49 -17
- package/dist/rule-evaluator/analysis.d.ts.map +1 -1
- package/dist/rule-evaluator/analysis.js +39 -41
- package/dist/rule-evaluator/analysis.js.map +1 -1
- package/dist/rule-evaluator/ast.d.ts +31 -18
- package/dist/rule-evaluator/ast.d.ts.map +1 -1
- package/dist/rule-evaluator/ast.js +3 -4
- package/dist/rule-evaluator/ast.js.map +1 -1
- package/dist/rule-evaluator/constants.d.ts +1 -1
- package/dist/rule-evaluator/constants.d.ts.map +1 -1
- package/dist/rule-evaluator/constants.js +3 -0
- package/dist/rule-evaluator/constants.js.map +1 -1
- package/dist/rule-evaluator/country-codes.generated.js +1 -1
- package/dist/rule-evaluator/custom-lists.d.ts +0 -6
- package/dist/rule-evaluator/custom-lists.d.ts.map +1 -1
- package/dist/rule-evaluator/custom-lists.js +119 -91
- package/dist/rule-evaluator/custom-lists.js.map +1 -1
- package/dist/rule-evaluator/diagnostics.d.ts +1 -1
- package/dist/rule-evaluator/diagnostics.d.ts.map +1 -1
- package/dist/rule-evaluator/diagnostics.js +17 -0
- package/dist/rule-evaluator/diagnostics.js.map +1 -1
- package/dist/rule-evaluator/engine-observations.generated.d.ts +20 -0
- package/dist/rule-evaluator/engine-observations.generated.d.ts.map +1 -1
- package/dist/rule-evaluator/engine-observations.generated.js +5 -0
- package/dist/rule-evaluator/engine-observations.generated.js.map +1 -1
- package/dist/rule-evaluator/evaluator.d.ts +4 -2
- package/dist/rule-evaluator/evaluator.d.ts.map +1 -1
- package/dist/rule-evaluator/evaluator.js +5 -4
- package/dist/rule-evaluator/evaluator.js.map +1 -1
- package/dist/rule-evaluator/explain.d.ts +2 -1
- package/dist/rule-evaluator/explain.d.ts.map +1 -1
- package/dist/rule-evaluator/explain.js +49 -7
- package/dist/rule-evaluator/explain.js.map +1 -1
- package/dist/rule-evaluator/field-descriptions.generated.d.ts +13 -0
- package/dist/rule-evaluator/field-descriptions.generated.d.ts.map +1 -1
- package/dist/rule-evaluator/field-descriptions.generated.js +33 -0
- package/dist/rule-evaluator/field-descriptions.generated.js.map +1 -1
- package/dist/rule-evaluator/fields.d.ts +13 -1
- package/dist/rule-evaluator/fields.d.ts.map +1 -1
- package/dist/rule-evaluator/fields.js +71 -17
- package/dist/rule-evaluator/fields.js.map +1 -1
- package/dist/rule-evaluator/function-descriptions.d.ts +2 -0
- package/dist/rule-evaluator/function-descriptions.d.ts.map +1 -1
- package/dist/rule-evaluator/function-descriptions.generated.d.ts +66 -10
- package/dist/rule-evaluator/function-descriptions.generated.d.ts.map +1 -1
- package/dist/rule-evaluator/function-descriptions.generated.js +129 -11
- package/dist/rule-evaluator/function-descriptions.generated.js.map +1 -1
- package/dist/rule-evaluator/function-descriptions.js.map +1 -1
- package/dist/rule-evaluator/function-signature-validation.d.ts +2 -0
- package/dist/rule-evaluator/function-signature-validation.d.ts.map +1 -1
- package/dist/rule-evaluator/function-signature-validation.js +169 -19
- package/dist/rule-evaluator/function-signature-validation.js.map +1 -1
- package/dist/rule-evaluator/functions.d.ts +24 -1
- package/dist/rule-evaluator/functions.d.ts.map +1 -1
- package/dist/rule-evaluator/functions.js +423 -95
- package/dist/rule-evaluator/functions.js.map +1 -1
- package/dist/rule-evaluator/ip-literals.d.ts +56 -0
- package/dist/rule-evaluator/ip-literals.d.ts.map +1 -0
- package/dist/rule-evaluator/ip-literals.js +162 -0
- package/dist/rule-evaluator/ip-literals.js.map +1 -0
- package/dist/rule-evaluator/log-sample.d.ts.map +1 -1
- package/dist/rule-evaluator/log-sample.js +14 -2
- package/dist/rule-evaluator/log-sample.js.map +1 -1
- package/dist/rule-evaluator/match-chain.d.ts +2 -1
- package/dist/rule-evaluator/match-chain.d.ts.map +1 -1
- package/dist/rule-evaluator/match-chain.js +12 -17
- package/dist/rule-evaluator/match-chain.js.map +1 -1
- package/dist/rule-evaluator/minifier.d.ts +1 -1
- package/dist/rule-evaluator/minifier.d.ts.map +1 -1
- package/dist/rule-evaluator/minifier.js +15 -14
- package/dist/rule-evaluator/minifier.js.map +1 -1
- package/dist/rule-evaluator/normalizer.d.ts +1 -1
- package/dist/rule-evaluator/normalizer.d.ts.map +1 -1
- package/dist/rule-evaluator/normalizer.js +4 -5
- package/dist/rule-evaluator/normalizer.js.map +1 -1
- package/dist/rule-evaluator/operators.d.ts +4 -0
- package/dist/rule-evaluator/operators.d.ts.map +1 -1
- package/dist/rule-evaluator/operators.js +26 -98
- package/dist/rule-evaluator/operators.js.map +1 -1
- package/dist/rule-evaluator/outcome.d.ts +2 -0
- package/dist/rule-evaluator/outcome.d.ts.map +1 -1
- package/dist/rule-evaluator/outcome.js +0 -6
- package/dist/rule-evaluator/outcome.js.map +1 -1
- package/dist/rule-evaluator/parse-cache.d.ts +8 -3
- package/dist/rule-evaluator/parse-cache.d.ts.map +1 -1
- package/dist/rule-evaluator/parse-cache.js +9 -8
- package/dist/rule-evaluator/parse-cache.js.map +1 -1
- package/dist/rule-evaluator/parser.d.ts +155 -18
- package/dist/rule-evaluator/parser.d.ts.map +1 -1
- package/dist/rule-evaluator/parser.js +478 -81
- package/dist/rule-evaluator/parser.js.map +1 -1
- package/dist/rule-evaluator/quantifier.d.ts +96 -2
- package/dist/rule-evaluator/quantifier.d.ts.map +1 -1
- package/dist/rule-evaluator/quantifier.js +263 -22
- package/dist/rule-evaluator/quantifier.js.map +1 -1
- package/dist/rule-evaluator/query-args.d.ts +23 -0
- package/dist/rule-evaluator/query-args.d.ts.map +1 -0
- package/dist/rule-evaluator/query-args.js +46 -0
- package/dist/rule-evaluator/query-args.js.map +1 -0
- package/dist/rule-evaluator/rule-language-types.d.ts +28 -17
- package/dist/rule-evaluator/rule-language-types.d.ts.map +1 -1
- package/dist/rule-evaluator/rule-language-types.js +117 -42
- package/dist/rule-evaluator/rule-language-types.js.map +1 -1
- package/dist/rule-evaluator/string-literals.d.ts +20 -0
- package/dist/rule-evaluator/string-literals.d.ts.map +1 -0
- package/dist/rule-evaluator/string-literals.js +44 -0
- package/dist/rule-evaluator/string-literals.js.map +1 -0
- package/dist/rule-evaluator/tokenizer.d.ts +34 -5
- package/dist/rule-evaluator/tokenizer.d.ts.map +1 -1
- package/dist/rule-evaluator/tokenizer.js +320 -74
- package/dist/rule-evaluator/tokenizer.js.map +1 -1
- package/dist/rule-evaluator/transformation.d.ts +2 -2
- package/dist/rule-evaluator/transformation.d.ts.map +1 -1
- package/dist/rule-evaluator/transformation.js +4 -5
- package/dist/rule-evaluator/transformation.js.map +1 -1
- package/dist/rule-evaluator/validation.d.ts.map +1 -1
- package/dist/rule-evaluator/validation.js +261 -122
- package/dist/rule-evaluator/validation.js.map +1 -1
- package/dist/rule-evaluator.d.ts +3 -1
- package/dist/rule-evaluator.d.ts.map +1 -1
- package/dist/rule-evaluator.js +2 -0
- package/dist/rule-evaluator.js.map +1 -1
- package/dist/runtime-config.d.ts.map +1 -1
- package/dist/runtime-config.js +6 -4
- package/dist/runtime-config.js.map +1 -1
- package/dist/tools/explain-rule-miss.js +4 -6
- package/dist/tools/explain-rule-miss.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
import { isExpressionNode } from './ast.js';
|
|
1
|
+
import { isExpressionNode, unhandledNode, } from './ast.js';
|
|
2
|
+
import { alignedArrayGroup } from './fields.js';
|
|
3
|
+
import { conditionShape, inferFunctionInvocation, inferRuleExpressionArgument, isFieldNode, isFuncNode, } from './rule-language-types.js';
|
|
4
|
+
import { semanticRuleExpressionFingerprint } from './transformation.js';
|
|
2
5
|
/**
|
|
3
|
-
* Extracts the normalized comparison carried by an any()/all() node
|
|
6
|
+
* Extracts the normalized comparison carried by an any()/all() node; see
|
|
7
|
+
* QuantifierPredicateReading.
|
|
4
8
|
*/
|
|
5
9
|
export function extractQuantifierComparison(node) {
|
|
6
|
-
|
|
10
|
+
const reading = readQuantifierPredicate(node);
|
|
11
|
+
if (reading?.kind !== 'comparison')
|
|
7
12
|
return null;
|
|
8
|
-
const predicate =
|
|
9
|
-
|
|
10
|
-
return null;
|
|
11
|
-
const unwrapped = unwrapPredicate(predicate);
|
|
12
|
-
if (!unwrapped)
|
|
13
|
-
return null;
|
|
14
|
-
return {
|
|
15
|
-
predicate,
|
|
16
|
-
comparison: unwrapped.comparison,
|
|
17
|
-
source: unwrapped.comparison.left,
|
|
18
|
-
op: unwrapped.comparison.op,
|
|
19
|
-
negated: unwrapped.negated,
|
|
20
|
-
};
|
|
13
|
+
const { predicate, comparison, negated } = reading;
|
|
14
|
+
return { predicate, comparison, source: comparison.left, op: comparison.op, negated };
|
|
21
15
|
}
|
|
22
16
|
/**
|
|
23
17
|
* Extracts the complete normalized comparison predicate carried by an any()/all() node.
|
|
@@ -31,11 +25,258 @@ export function extractQuantifierPredicate(node) {
|
|
|
31
25
|
value: comparison.comparison.right,
|
|
32
26
|
};
|
|
33
27
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
// Parsed expressions are cached, so each predicate's reading and conditions, and each array's list and source,
|
|
29
|
+
// are found once.
|
|
30
|
+
const predicateReadingCache = new WeakMap();
|
|
31
|
+
const predicateConditionsCache = new WeakMap();
|
|
32
|
+
const pairedArrayListCache = new WeakMap();
|
|
33
|
+
const arraySourceCache = new WeakMap();
|
|
34
|
+
/** The conditions an any()/all() predicate combines, in source order. */
|
|
35
|
+
export function quantifierPredicateConditions(predicate) {
|
|
36
|
+
let conditions = predicateConditionsCache.get(predicate);
|
|
37
|
+
if (!conditions) {
|
|
38
|
+
const collected = [];
|
|
39
|
+
collectPredicateConditions(predicate, true, collected);
|
|
40
|
+
conditions = collected;
|
|
41
|
+
predicateConditionsCache.set(predicate, conditions);
|
|
42
|
+
}
|
|
43
|
+
return conditions;
|
|
44
|
+
}
|
|
45
|
+
// `needs` is the value a node has wherever the predicate holds, or null when that is not fixed.
|
|
46
|
+
function collectPredicateConditions(node, needs, conditions) {
|
|
47
|
+
switch (node.kind) {
|
|
48
|
+
case 'Not':
|
|
49
|
+
collectPredicateConditions(node.operand, needs === null ? null : !needs, conditions);
|
|
50
|
+
return;
|
|
51
|
+
case 'And':
|
|
52
|
+
for (const operand of node.operands)
|
|
53
|
+
collectPredicateConditions(operand, needs === true ? true : null, conditions);
|
|
54
|
+
return;
|
|
55
|
+
case 'Or':
|
|
56
|
+
for (const operand of node.operands)
|
|
57
|
+
collectPredicateConditions(operand, needs === false ? false : null, conditions);
|
|
58
|
+
return;
|
|
59
|
+
case 'Xor':
|
|
60
|
+
for (const operand of node.operands)
|
|
61
|
+
collectPredicateConditions(operand, null, conditions);
|
|
62
|
+
return;
|
|
63
|
+
case 'Comparison':
|
|
64
|
+
case 'BoolField':
|
|
65
|
+
case 'Func':
|
|
66
|
+
case 'Invalid':
|
|
67
|
+
conditions.push({ node, required: needs === true });
|
|
68
|
+
return;
|
|
69
|
+
default:
|
|
70
|
+
unhandledNode(node);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** How an any() or all() call reads its predicate, or null for a predicate of invalid syntax. */
|
|
74
|
+
export function readQuantifierPredicate(node) {
|
|
75
|
+
let reading = predicateReadingCache.get(node);
|
|
76
|
+
if (reading === undefined) {
|
|
77
|
+
reading = computePredicateReading(node);
|
|
78
|
+
predicateReadingCache.set(node, reading);
|
|
79
|
+
}
|
|
80
|
+
return reading;
|
|
81
|
+
}
|
|
82
|
+
function computePredicateReading(node) {
|
|
83
|
+
const predicate = node.args[0];
|
|
84
|
+
if ((node.name !== 'any' && node.name !== 'all') || !isExpressionNode(predicate))
|
|
85
|
+
return null;
|
|
86
|
+
if (predicate.kind === 'Func' && predicate.condition !== true)
|
|
87
|
+
return { kind: 'value', predicate };
|
|
88
|
+
let condition = predicate;
|
|
89
|
+
let negated = false;
|
|
90
|
+
while (condition.kind === 'Not') {
|
|
91
|
+
condition = condition.operand;
|
|
92
|
+
negated = !negated;
|
|
93
|
+
}
|
|
94
|
+
switch (condition.kind) {
|
|
95
|
+
case 'Comparison':
|
|
96
|
+
return { kind: 'comparison', predicate, comparison: condition, negated };
|
|
97
|
+
case 'And':
|
|
98
|
+
case 'Or':
|
|
99
|
+
case 'Xor':
|
|
100
|
+
case 'Func':
|
|
101
|
+
case 'BoolField':
|
|
102
|
+
return { kind: 'conditions', predicate };
|
|
103
|
+
default:
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Whether a comparison has a result for each element of an array, as one
|
|
109
|
+
* whose left side `[*]` expands has, or a single one. Null when its left side
|
|
110
|
+
* is invalid, or neither: an array or map it does not expand, or a value of
|
|
111
|
+
* a type not known, which has its own error.
|
|
112
|
+
*/
|
|
113
|
+
export function comparisonShape(node) {
|
|
114
|
+
const info = inferRuleExpressionArgument(node.left);
|
|
115
|
+
if (info.invalid)
|
|
116
|
+
return null;
|
|
117
|
+
if (info.expanded)
|
|
118
|
+
return 'array';
|
|
119
|
+
const { kind } = info.type;
|
|
120
|
+
return kind === 'array' || kind === 'map' || kind === 'set' || kind === 'unknown' ? null : 'scalar';
|
|
121
|
+
}
|
|
122
|
+
/** Whether a condition of a predicate is a comparison over each element of an array; see comparisonShape(). */
|
|
123
|
+
export function isArrayComparison(condition) {
|
|
124
|
+
return condition.kind === 'Comparison' && comparisonShape(condition) === 'array';
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Whether a call read as a condition has a result for each element: its
|
|
128
|
+
* value is an array of Booleans, as a Boolean function mapped over `[*]`
|
|
129
|
+
* gives, or a `[*]` after it expands one. Null when the call is invalid, or
|
|
130
|
+
* its value is neither that nor a Boolean, which has its own error.
|
|
131
|
+
*/
|
|
132
|
+
export function callShape(node) {
|
|
133
|
+
return conditionShape(inferRuleExpressionArgument(node));
|
|
134
|
+
}
|
|
135
|
+
/** Whether a condition of a predicate is a call with a result for each element; see callShape(). */
|
|
136
|
+
export function isArrayCall(condition) {
|
|
137
|
+
return condition.kind === 'Func' && callShape(condition) === 'array';
|
|
138
|
+
}
|
|
139
|
+
/** Whether a condition of a predicate has a result for each element of an array. */
|
|
140
|
+
export function isArrayCondition(condition) {
|
|
141
|
+
return isArrayComparison(condition) || isArrayCall(condition);
|
|
142
|
+
}
|
|
143
|
+
/** The array a condition has a result for each element of: a comparison's left side, or the call itself. */
|
|
144
|
+
export function conditionArray(condition) {
|
|
145
|
+
return condition.kind === 'Comparison' ? condition.left : condition;
|
|
146
|
+
}
|
|
147
|
+
/** The arrays of a predicate's conditions with a result for each element, in source order. */
|
|
148
|
+
export function predicateArrays(predicate) {
|
|
149
|
+
return quantifierPredicateConditions(predicate)
|
|
150
|
+
.map(({ node }) => node)
|
|
151
|
+
.filter(isArrayCondition)
|
|
152
|
+
.map(conditionArray);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Whether a predicate's conditions read more than one array, whose elements
|
|
156
|
+
* any() and all() pair by index. A call that maps over an array and gives
|
|
157
|
+
* each element a result reads that array, as `lower(names[*])` reads
|
|
158
|
+
* `names[*]`.
|
|
159
|
+
*/
|
|
160
|
+
export function readsSeveralArrays(predicate) {
|
|
161
|
+
return firstOtherArray(predicateArrays(predicate), arraySource) !== undefined;
|
|
162
|
+
}
|
|
163
|
+
/** The first array that comes from another list than the first's; see pairedArrayList(). */
|
|
164
|
+
export function unalignedArray(arrays) {
|
|
165
|
+
return firstOtherArray(arrays, pairedArrayList);
|
|
166
|
+
}
|
|
167
|
+
/** The first array whose key differs from the first array's. */
|
|
168
|
+
function firstOtherArray(arrays, key) {
|
|
169
|
+
let first;
|
|
170
|
+
for (const array of arrays) {
|
|
171
|
+
const value = key(array);
|
|
172
|
+
first ??= value;
|
|
173
|
+
if (value !== first)
|
|
174
|
+
return array;
|
|
175
|
+
}
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Functions that can map over an array and give every value they accept a
|
|
180
|
+
* result, never nil. coalesce() and concat() take the element first, which
|
|
181
|
+
* is never nil. An unknown element, a header value or a map key's values, is
|
|
182
|
+
* never nil either, so it keeps its place.
|
|
183
|
+
*/
|
|
184
|
+
const NEVER_NIL_FUNCTIONS = new Set([
|
|
185
|
+
'coalesce',
|
|
186
|
+
'concat',
|
|
187
|
+
'encode_base64',
|
|
188
|
+
'join',
|
|
189
|
+
'len',
|
|
190
|
+
'lower',
|
|
191
|
+
'regex_replace',
|
|
192
|
+
'remove_bytes',
|
|
193
|
+
'sha256',
|
|
194
|
+
'split',
|
|
195
|
+
'substring',
|
|
196
|
+
'to_string',
|
|
197
|
+
'trim',
|
|
198
|
+
'trim_end',
|
|
199
|
+
'trim_start',
|
|
200
|
+
'upper',
|
|
201
|
+
'url_decode',
|
|
202
|
+
'wildcard_replace',
|
|
203
|
+
]);
|
|
204
|
+
/**
|
|
205
|
+
* Functions that give nil when a later argument is nil, as has_value()'s
|
|
206
|
+
* value or the substring of starts_with() and ends_with() can be, and
|
|
207
|
+
* otherwise give every value they accept a result. Over an array, a nil later
|
|
208
|
+
* argument gives every element nil, unknown ones too, which leaves an empty
|
|
209
|
+
* array.
|
|
210
|
+
*/
|
|
211
|
+
const NIL_ARGUMENT_FUNCTIONS = new Set(['ends_with', 'has_value', 'starts_with']);
|
|
212
|
+
/**
|
|
213
|
+
* Whether a call that maps over an array gives each element a result, or
|
|
214
|
+
* none at all, so that the result keeps the array's places.
|
|
215
|
+
*/
|
|
216
|
+
export function keepsPlacesWhenMapped(name) {
|
|
217
|
+
return NEVER_NIL_FUNCTIONS.has(name) || NIL_ARGUMENT_FUNCTIONS.has(name);
|
|
218
|
+
}
|
|
219
|
+
/** Whether a call gives nil when a later argument is nil, for every element when it maps over an array. */
|
|
220
|
+
export function givesNilForNilArgument(name) {
|
|
221
|
+
return NIL_ARGUMENT_FUNCTIONS.has(name);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* The list an array a comparison reads comes from: arrays from one list line
|
|
225
|
+
* up by index, which any() and all() pair them by. A call that maps over an
|
|
226
|
+
* array and gives each element a result keeps that array's list; any other
|
|
227
|
+
* array is a list of its own.
|
|
228
|
+
*/
|
|
229
|
+
export function pairedArrayList(node) {
|
|
230
|
+
let list = pairedArrayListCache.get(node);
|
|
231
|
+
if (list === undefined) {
|
|
232
|
+
list = computePairedArrayList(node);
|
|
233
|
+
pairedArrayListCache.set(node, list);
|
|
234
|
+
}
|
|
235
|
+
return list;
|
|
236
|
+
}
|
|
237
|
+
function computePairedArrayList(node) {
|
|
238
|
+
const array = mappedArraySource(node);
|
|
239
|
+
if (isFieldNode(array) && readsWholeArray(array.accessPath)) {
|
|
240
|
+
const group = alignedArrayGroup(array.name);
|
|
241
|
+
if (group !== undefined)
|
|
242
|
+
return `group:${group}`;
|
|
243
|
+
}
|
|
244
|
+
return arraySource(node);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* The array an array reads under the calls that map over it and give each
|
|
248
|
+
* element a result, as a fingerprint, so that `lower(names[*])` and
|
|
249
|
+
* `names[*]` have the same one.
|
|
250
|
+
*/
|
|
251
|
+
function arraySource(node) {
|
|
252
|
+
let source = arraySourceCache.get(node);
|
|
253
|
+
if (source === undefined) {
|
|
254
|
+
source = semanticRuleExpressionFingerprint(mappedArraySource(node));
|
|
255
|
+
arraySourceCache.set(node, source);
|
|
256
|
+
}
|
|
257
|
+
return source;
|
|
258
|
+
}
|
|
259
|
+
/** The array under the calls that map over it and give each element a result, or the array itself. */
|
|
260
|
+
function mappedArraySource(node) {
|
|
261
|
+
const array = unwrapMappedCalls(node, keepsPlacesWhenMapped);
|
|
262
|
+
return isFieldNode(array) || isFuncNode(array) ? array : node;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* The value under the calls that map over it and that `unwraps` accepts by
|
|
266
|
+
* name; null when one of them reads its result other than whole, as
|
|
267
|
+
* `lower(...)[0]` or an access that failed to parse does.
|
|
268
|
+
*/
|
|
269
|
+
export function unwrapMappedCalls(node, unwraps) {
|
|
270
|
+
let value = node;
|
|
271
|
+
while (isFuncNode(value) && unwraps(value.name) && inferFunctionInvocation(value).mapping === 'mapped') {
|
|
272
|
+
if (!readsWholeArray(value.accessPath))
|
|
273
|
+
return null;
|
|
274
|
+
value = value.args[0];
|
|
275
|
+
}
|
|
276
|
+
return value;
|
|
277
|
+
}
|
|
278
|
+
/** Whether an access path reads a whole array: no access, or `[*]`. */
|
|
279
|
+
export function readsWholeArray(accessPath) {
|
|
280
|
+
return accessPath.length === 0 || (accessPath.length === 1 && accessPath[0].kind === 'ArrayWildcardAccess');
|
|
40
281
|
}
|
|
41
282
|
//# sourceMappingURL=quantifier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quantifier.js","sourceRoot":"","sources":["../../src/rule-evaluator/quantifier.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"quantifier.js","sourceRoot":"","sources":["../../src/rule-evaluator/quantifier.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAChB,aAAa,GAWb,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACN,cAAc,EACd,uBAAuB,EACvB,2BAA2B,EAC3B,WAAW,EACX,UAAU,GACV,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,iCAAiC,EAAE,MAAM,qBAAqB,CAAC;AAgBxE;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,IAAc;IACzD,MAAM,OAAO,GAAG,uBAAuB,C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AACf,CAAC;AAED,sGAAsG;AACtG,SAAS,iBAAiB,CAAC,IAA0B;IACpD,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;IAC7D,OAAO,WAAW,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAa,EAAE,OAAkC;IAClF,IAAI,KAAK,GAAG,IAAI,CAAC;IACjB,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,uBAAuB,CAAC,KAAK,CAAC,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QACxG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,UAAU,CAAC;YAAE,OAAO,IAAI,CAAC;QACpD,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,eAAe,CAAC,UAAiC;IAChE,OAAO,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,qBAAqB,CAAC,CAAC;AAC7G,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare's query fields read the query as the client sent it and decode
|
|
3
|
+
* nothing in it (test/fixtures/query-arg-probes.json). The query splits at
|
|
4
|
+
* each `&` and an argument at its first `=`. Empty arguments are skipped, and
|
|
5
|
+
* one without `=` has an empty value.
|
|
6
|
+
*/
|
|
7
|
+
export type QueryArg = [name: string, value: string];
|
|
8
|
+
/**
|
|
9
|
+
* The text from the first `?` to any `#`, which a lone `?` keeps. Workers
|
|
10
|
+
* keeps `request.url` as the client sent it, while `new URL()` percent-encodes
|
|
11
|
+
* `"`, `<`, `>` and `'` in a query, so query fields read this text.
|
|
12
|
+
*/
|
|
13
|
+
export declare function searchText(href: string): string;
|
|
14
|
+
/** A URL's text before its query, or before its fragment without a query. */
|
|
15
|
+
export declare function textBeforeSearch(href: string): string;
|
|
16
|
+
export declare function readQueryArgs(query: string): QueryArg[];
|
|
17
|
+
/**
|
|
18
|
+
* Cloudflare's remove_query_args(): removes the arguments whose names match
|
|
19
|
+
* exactly, and drops empty ones. The others keep their text and order, joined
|
|
20
|
+
* with `&`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function removeQueryArgs(query: string, names: ReadonlySet<string>): string;
|
|
23
|
+
//# sourceMappingURL=query-args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-args.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/query-args.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,EAAE,CAMvD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM,CAEjF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare's query fields read the query as the client sent it and decode
|
|
3
|
+
* nothing in it (test/fixtures/query-arg-probes.json). The query splits at
|
|
4
|
+
* each `&` and an argument at its first `=`. Empty arguments are skipped, and
|
|
5
|
+
* one without `=` has an empty value.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The text from the first `?` to any `#`, which a lone `?` keeps. Workers
|
|
9
|
+
* keeps `request.url` as the client sent it, while `new URL()` percent-encodes
|
|
10
|
+
* `"`, `<`, `>` and `'` in a query, so query fields read this text.
|
|
11
|
+
*/
|
|
12
|
+
export function searchText(href) {
|
|
13
|
+
const hash = href.indexOf('#');
|
|
14
|
+
const beforeHash = hash === -1 ? href : href.slice(0, hash);
|
|
15
|
+
const question = beforeHash.indexOf('?');
|
|
16
|
+
return question === -1 ? '' : beforeHash.slice(question);
|
|
17
|
+
}
|
|
18
|
+
/** A URL's text before its query, or before its fragment without a query. */
|
|
19
|
+
export function textBeforeSearch(href) {
|
|
20
|
+
const end = href.search(/[?#]/);
|
|
21
|
+
return end === -1 ? href : href.slice(0, end);
|
|
22
|
+
}
|
|
23
|
+
export function readQueryArgs(query) {
|
|
24
|
+
return queryArgTexts(query).map(arg => {
|
|
25
|
+
const name = queryArgName(arg);
|
|
26
|
+
// Past the `=`, which is past the end without one.
|
|
27
|
+
return [name, arg.slice(name.length + 1)];
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Cloudflare's remove_query_args(): removes the arguments whose names match
|
|
32
|
+
* exactly, and drops empty ones. The others keep their text and order, joined
|
|
33
|
+
* with `&`.
|
|
34
|
+
*/
|
|
35
|
+
export function removeQueryArgs(query, names) {
|
|
36
|
+
return queryArgTexts(query).filter(arg => !names.has(queryArgName(arg))).join('&');
|
|
37
|
+
}
|
|
38
|
+
/** The query's arguments as written, without the empty ones. */
|
|
39
|
+
function queryArgTexts(query) {
|
|
40
|
+
return query.split('&').filter(arg => arg);
|
|
41
|
+
}
|
|
42
|
+
function queryArgName(arg) {
|
|
43
|
+
const eq = arg.indexOf('=');
|
|
44
|
+
return eq === -1 ? arg : arg.slice(0, eq);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingUR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AAa,EAAE,KAA0B;IACxE,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACpF,CAAC;AAED,gEAAgE;AAChE,SAAS,aAAa,CAAC,KAAa;IACnC,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,YAAY,CAAC,GAAW;IAChC,MAAM,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AccessNode, type BoolLiteral, type FieldNode, type FuncNode, type IpLiteral, type LiteralNode, type NumberLiteral, type
|
|
1
|
+
import { type AccessNode, type BoolLiteral, type ExprNode, type FieldNode, type FuncNode, type IpLiteral, type LiteralNode, type NumberLiteral, type SetLiteral, type StringLiteral } from './ast.js';
|
|
2
2
|
import type { RuleExpressionFieldUsageKind } from './field-descriptions.js';
|
|
3
3
|
import type { RuleExpressionFunctionParameter } from './function-descriptions.js';
|
|
4
4
|
export type RuleExpressionScalarTypeName = 'String' | 'Bytes' | 'Integer' | 'Number' | 'Boolean' | 'IP address' | 'T' | string;
|
|
@@ -76,6 +76,10 @@ export interface RuleExpressionFunctionInvocationInfo {
|
|
|
76
76
|
* Infers the Cloudflare rule-language type and field usage shape for an AST node.
|
|
77
77
|
*/
|
|
78
78
|
export declare function inferRuleExpressionArgument(node: FuncNode['args'][number] | FieldNode | FuncNode | LiteralNode | undefined): RuleExpressionArgumentInfo;
|
|
79
|
+
/** Whether a value is a Boolean or an array of them, which `[*]` may expand; null for any other. */
|
|
80
|
+
export declare function conditionShape(info: RuleExpressionArgumentInfo): 'array' | 'scalar' | null;
|
|
81
|
+
/** Whether a function argument is a condition with a result for each element: an array of Booleans, which no call maps over. */
|
|
82
|
+
export declare function isArrayConditionArgument(arg: FuncNode['args'][number] | undefined): arg is ExprNode;
|
|
79
83
|
/**
|
|
80
84
|
* The type of a value as evaluation reads it. Only an expression without
|
|
81
85
|
* errors is evaluated, and none of its values is invalid.
|
|
@@ -125,22 +129,24 @@ export declare function isConcreteComparisonFamily(family: RuleExpressionCompari
|
|
|
125
129
|
* Returns the element/value type for array and map-like rule-language collections.
|
|
126
130
|
*/
|
|
127
131
|
export declare function collectionElementDataType(type: RuleExpressionDataType): RuleExpressionDataType | null;
|
|
132
|
+
/**
|
|
133
|
+
* The type of each element that `[*]` gives: an array's elements, or a map's
|
|
134
|
+
* values whole, so that `http.request.headers[*]` gives arrays, where
|
|
135
|
+
* collectionElementDataType() gives their elements. Null where `[*]` does not
|
|
136
|
+
* apply, or the type is not known.
|
|
137
|
+
*/
|
|
138
|
+
export declare function expandedElementDataType(type: RuleExpressionDataType): RuleExpressionDataType | null;
|
|
128
139
|
/**
|
|
129
140
|
* Returns whether a type is a rule-language collection with comparable elements.
|
|
130
141
|
*/
|
|
131
142
|
export declare function isCollectionDataType(type: RuleExpressionDataType): boolean;
|
|
132
143
|
/**
|
|
133
|
-
* Reads an integer literal as Cloudflare does: one
|
|
134
|
-
* octal, and any other, including a negative one, is
|
|
135
|
-
* text is not an integer, such as `1.5`, or not a
|
|
144
|
+
* Reads an integer literal as Cloudflare does: one after `0x` is hex, one
|
|
145
|
+
* with a leading `0` is octal, and any other, including a negative one, is
|
|
146
|
+
* decimal. Null means the text is not an integer, such as `1.5`, or not a
|
|
147
|
+
* valid one of its form, such as `08` or `0X10`.
|
|
136
148
|
*/
|
|
137
149
|
export declare function integerLiteralValue(literal: string): bigint | null;
|
|
138
|
-
/**
|
|
139
|
-
* Returns the type of an unquoted inline list element: an Integer or Integer
|
|
140
|
-
* range, or an IP address, CIDR, or range. Null means the element is neither,
|
|
141
|
-
* which Cloudflare rejects.
|
|
142
|
-
*/
|
|
143
|
-
export declare function unquotedSetElementType(value: string): Exclude<SetElementType, 'string'> | null;
|
|
144
150
|
/**
|
|
145
151
|
* Infers the union of scalar element types present in an inline set literal.
|
|
146
152
|
*/
|
|
@@ -160,14 +166,15 @@ export declare function isArrayExpandedNode(node: unknown): node is FieldNode |
|
|
|
160
166
|
*/
|
|
161
167
|
export declare function inferFunctionInvocation(node: FuncNode): RuleExpressionFunctionInvocationInfo;
|
|
162
168
|
/**
|
|
163
|
-
* Whether a comparison
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
+
* Whether a comparison can be a function's argument at an index, after the
|
|
170
|
+
* arguments before it; false where it takes none. Its value is a Boolean, or
|
|
171
|
+
* with `elementwise`, an array of them, as a comparison whose left side
|
|
172
|
+
* `[*]` expands has. Cloudflare fixes T from the first argument, as
|
|
173
|
+
* `coalesce()`'s first argument fixes the type of the others, and
|
|
174
|
+
* `has_value()`'s collection that of its value, so a comparison fills a later
|
|
175
|
+
* T parameter only when the first argument lets T have its type.
|
|
169
176
|
*/
|
|
170
|
-
export declare function acceptsComparisonArgument(name: string, index: number, before: readonly FuncNode['args'][number][]): boolean;
|
|
177
|
+
export declare function acceptsComparisonArgument(name: string, index: number, before: readonly FuncNode['args'][number][], elementwise?: boolean): boolean;
|
|
171
178
|
/** Whether a function's result can be a Boolean: one declared Boolean, or T. */
|
|
172
179
|
export declare function canReturnBoolean(name: string): boolean;
|
|
173
180
|
/**
|
|
@@ -187,10 +194,14 @@ export declare function isComparableValue(node: FieldNode | FuncNode): boolean;
|
|
|
187
194
|
export declare function singleValueType(node: FuncNode['args'][number]): RuleExpressionDataType | null;
|
|
188
195
|
/** Whether a type is the Boolean scalar. */
|
|
189
196
|
export declare function isBooleanType(type: RuleExpressionDataType): boolean;
|
|
197
|
+
/** Whether a type is an array of Booleans, the value of a condition with a result for each element. */
|
|
198
|
+
export declare function isBooleanArrayType(type: RuleExpressionDataType): boolean;
|
|
190
199
|
/** How many arguments a function takes at most. */
|
|
191
200
|
export declare function maximumArgumentCount(parameters: readonly RuleExpressionFunctionParameter[]): number;
|
|
192
201
|
/** The parameter an argument at an index fills: a variadic one fills every index from its own. */
|
|
193
202
|
export declare function parameterForArgument(parameters: readonly RuleExpressionFunctionParameter[], index: number): RuleExpressionFunctionParameter | undefined;
|
|
203
|
+
/** The type a function declares for its argument at an index; unknown past its parameters or for a function it does not know. */
|
|
204
|
+
export declare function parameterDataType(name: string, index: number): RuleExpressionDataType;
|
|
194
205
|
/**
|
|
195
206
|
* Narrows unknown AST values to rule-language field nodes.
|
|
196
207
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule-language-types.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/rule-language-types.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"rule-language-types.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/rule-language-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,KAAK,UAAU,EACf,KAAK,WAAW,EAEhB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,QAAQ,EAEb,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,aAAa,EAElB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,MAAM,UAAU,CAAC;AAGlB,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,KAAK,EAAqC,+BAA+B,EAAE,MAAM,4BAA4B,CAAC;AAErH,MAAM,MAAM,4BAA4B,GACrC,QAAQ,GACR,OAAO,GACP,SAAS,GACT,QAAQ,GACR,SAAS,GACT,YAAY,GACZ,GAAG,GACH,M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