@libreflare/worker-runtime 0.6.0 → 0.7.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/README.md +120 -22
- package/dist/rule-evaluator/accept-encoding.d.ts +2 -1
- package/dist/rule-evaluator/accept-encoding.d.ts.map +1 -1
- package/dist/rule-evaluator/accept-encoding.js +27 -29
- package/dist/rule-evaluator/accept-encoding.js.map +1 -1
- package/dist/rule-evaluator/access-values.d.ts +23 -3
- package/dist/rule-evaluator/access-values.d.ts.map +1 -1
- package/dist/rule-evaluator/access-values.js +34 -14
- package/dist/rule-evaluator/access-values.js.map +1 -1
- package/dist/rule-evaluator/analysis.d.ts +3 -7
- package/dist/rule-evaluator/analysis.d.ts.map +1 -1
- package/dist/rule-evaluator/analysis.js +13 -39
- package/dist/rule-evaluator/analysis.js.map +1 -1
- package/dist/rule-evaluator/ast.d.ts +23 -3
- package/dist/rule-evaluator/ast.d.ts.map +1 -1
- package/dist/rule-evaluator/ast.js +5 -0
- package/dist/rule-evaluator/ast.js.map +1 -1
- package/dist/rule-evaluator/comparison.d.ts +16 -0
- package/dist/rule-evaluator/comparison.d.ts.map +1 -0
- package/dist/rule-evaluator/comparison.js +43 -0
- package/dist/rule-evaluator/comparison.js.map +1 -0
- package/dist/rule-evaluator/constants.d.ts +7 -3
- package/dist/rule-evaluator/constants.d.ts.map +1 -1
- package/dist/rule-evaluator/constants.js +7 -1
- 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 +6 -0
- package/dist/rule-evaluator/custom-lists.d.ts.map +1 -1
- package/dist/rule-evaluator/custom-lists.js +21 -1
- package/dist/rule-evaluator/custom-lists.js.map +1 -1
- package/dist/rule-evaluator/diagnostics.d.ts +10 -7
- package/dist/rule-evaluator/diagnostics.d.ts.map +1 -1
- package/dist/rule-evaluator/diagnostics.js +24 -1
- package/dist/rule-evaluator/diagnostics.js.map +1 -1
- package/dist/rule-evaluator/evaluator.d.ts +10 -3
- package/dist/rule-evaluator/evaluator.d.ts.map +1 -1
- package/dist/rule-evaluator/evaluator.js +85 -78
- package/dist/rule-evaluator/evaluator.js.map +1 -1
- package/dist/rule-evaluator/explain.d.ts +11 -2
- package/dist/rule-evaluator/explain.d.ts.map +1 -1
- package/dist/rule-evaluator/explain.js +217 -121
- package/dist/rule-evaluator/explain.js.map +1 -1
- package/dist/rule-evaluator/field-descriptions.generated.d.ts +113 -0
- package/dist/rule-evaluator/field-descriptions.generated.d.ts.map +1 -1
- package/dist/rule-evaluator/field-descriptions.generated.js +260 -0
- package/dist/rule-evaluator/field-descriptions.generated.js.map +1 -1
- package/dist/rule-evaluator/fields.d.ts +12 -2
- package/dist/rule-evaluator/fields.d.ts.map +1 -1
- package/dist/rule-evaluator/fields.js +172 -29
- package/dist/rule-evaluator/fields.js.map +1 -1
- package/dist/rule-evaluator/function-descriptions.generated.d.ts +13 -0
- package/dist/rule-evaluator/function-descriptions.generated.d.ts.map +1 -1
- package/dist/rule-evaluator/function-descriptions.generated.js +24 -0
- package/dist/rule-evaluator/function-descriptions.generated.js.map +1 -1
- package/dist/rule-evaluator/function-signature-validation.d.ts +1 -1
- package/dist/rule-evaluator/function-signature-validation.d.ts.map +1 -1
- package/dist/rule-evaluator/function-signature-validation.js +56 -5
- package/dist/rule-evaluator/function-signature-validation.js.map +1 -1
- package/dist/rule-evaluator/functions.d.ts +18 -5
- package/dist/rule-evaluator/functions.d.ts.map +1 -1
- package/dist/rule-evaluator/functions.js +257 -150
- package/dist/rule-evaluator/functions.js.map +1 -1
- package/dist/rule-evaluator/minifier.d.ts +2 -6
- package/dist/rule-evaluator/minifier.d.ts.map +1 -1
- package/dist/rule-evaluator/minifier.js +9 -9
- package/dist/rule-evaluator/minifier.js.map +1 -1
- package/dist/rule-evaluator/normalizer.d.ts +2 -6
- package/dist/rule-evaluator/normalizer.d.ts.map +1 -1
- package/dist/rule-evaluator/normalizer.js +8 -8
- package/dist/rule-evaluator/normalizer.js.map +1 -1
- package/dist/rule-evaluator/operators.d.ts +21 -2
- package/dist/rule-evaluator/operators.d.ts.map +1 -1
- package/dist/rule-evaluator/operators.js +162 -104
- package/dist/rule-evaluator/operators.js.map +1 -1
- package/dist/rule-evaluator/outcome.d.ts +63 -0
- package/dist/rule-evaluator/outcome.d.ts.map +1 -0
- package/dist/rule-evaluator/outcome.js +78 -0
- package/dist/rule-evaluator/outcome.js.map +1 -0
- package/dist/rule-evaluator/parser.d.ts +7 -1
- package/dist/rule-evaluator/parser.d.ts.map +1 -1
- package/dist/rule-evaluator/parser.js +55 -25
- package/dist/rule-evaluator/parser.js.map +1 -1
- package/dist/rule-evaluator/quantifier.d.ts +2 -2
- package/dist/rule-evaluator/quantifier.d.ts.map +1 -1
- package/dist/rule-evaluator/rule-language-types.d.ts +5 -3
- package/dist/rule-evaluator/rule-language-types.d.ts.map +1 -1
- package/dist/rule-evaluator/rule-language-types.js +46 -17
- package/dist/rule-evaluator/rule-language-types.js.map +1 -1
- package/dist/rule-evaluator/tokenizer.d.ts.map +1 -1
- package/dist/rule-evaluator/tokenizer.js +25 -0
- package/dist/rule-evaluator/tokenizer.js.map +1 -1
- package/dist/rule-evaluator/validation.d.ts +8 -9
- package/dist/rule-evaluator/validation.d.ts.map +1 -1
- package/dist/rule-evaluator/validation.js +185 -64
- package/dist/rule-evaluator/validation.js.map +1 -1
- package/dist/rule-evaluator/values.d.ts +26 -0
- package/dist/rule-evaluator/values.d.ts.map +1 -0
- package/dist/rule-evaluator/values.js +55 -0
- package/dist/rule-evaluator/values.js.map +1 -0
- package/dist/rule-evaluator.d.ts +3 -3
- package/dist/rule-evaluator.d.ts.map +1 -1
- package/dist/rule-evaluator.js +1 -1
- package/dist/rule-evaluator.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,35 +1,23 @@
|
|
|
1
1
|
# @libreflare/worker-runtime
|
|
2
2
|
|
|
3
|
-
Shared runtime utilities for Libreflare-managed Cloudflare Workers
|
|
3
|
+
Shared runtime utilities for Libreflare-managed Cloudflare Workers: request
|
|
4
|
+
handling and logging for managed Workers, and the Cloudflare Rules expression
|
|
5
|
+
tooling behind them.
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
The package root exports everything. The `./rule-evaluator`,
|
|
8
|
+
`./runtime-config`, and `./log-handler` entry points export each part on its
|
|
9
|
+
own.
|
|
10
|
+
|
|
11
|
+
## Request Handling
|
|
6
12
|
|
|
7
13
|
- `handleRequest`: batched logging request handler for managed logging Workers.
|
|
8
14
|
- `handleLibreflareRequest`: generated-config route/logging request handler. Pass `runtimeConfig` from a generated JSON import, or rely on the legacy `LIBREFLARE_CONFIG` env binding. For route-only v2 config, pass `apiURL`, `getSourceKey`, `apiAuthHeaders`, and related options to keep logging owned by the Worker repository.
|
|
9
|
-
- `evaluateExpression`: Cloudflare Rules expression evaluator for Worker-side diagnostics. Unresolved Cloudflare list references are inferred as matches by default and can be disabled via options.
|
|
10
|
-
- `analyzeRuleExpression`: versioned, JSON-safe Cloudflare Rules AST, symbol metadata, and optional block-comment metadata for dashboard inference.
|
|
11
|
-
- `foldRuleExpressionAst`: bottom-up public AST reducer for custom dashboard inference.
|
|
12
|
-
- `getRuleExpressionFieldDescriptions`: field descriptions filtered by the same preset and field availability override shape used by rule expression validation.
|
|
13
|
-
- `RULE_EXPRESSION_COUNTRY_CODES`: generated ISO 3166-1 alpha-2 country codes plus Cloudflare's `T1` and `XX` special values, used by field metadata and semantic validation.
|
|
14
|
-
- `getRuleExpressionFunctionDescriptions`: function reference metadata for dashboard editors, including signatures, return types, parameter roles, and evaluator support notes.
|
|
15
|
-
- `minifyRuleExpression`: syntax-aware minifier for Cloudflare Rules expressions before Rewrite Rule deployment. It uses C-like operators, removes precedence-redundant grouping, and preserves string literal spelling. Syntax-invalid source is returned unchanged with diagnostics.
|
|
16
|
-
- `normalizeRuleExpression`: syntax-aware readable formatter that preserves operator notation, grouping, and string literal spelling while canonicalizing grammar whitespace.
|
|
17
|
-
- `validateRuleExpressionSyntax`: syntax, length, and field availability validation for Cloudflare URL Rewrite Rule filter expressions by default. Pass an explicit config object for minification, length enforcement, preset, field availability, deprecated-field notices, and list-reference policy. With minification enabled it validates the minified expression against Cloudflare's 4096-character rule limit by default; when minification is disabled, the result omits `minifiedExpression` and `minifiedLength`.
|
|
18
|
-
- `validateLoggingSourceKeyRuleExpressionSyntax`: runtime-only source-key rule validation using the pre-origin field context, without Custom List references or deployment length enforcement.
|
|
19
15
|
- `parseLibreflareRuntimeConfig`: validates an object or JSON string against the runtime configuration contract.
|
|
20
16
|
|
|
21
17
|
Version 2 runtime config accepts `routes: []` for a managed Worker that does not
|
|
22
18
|
currently serve any Libreflare route. Such a config has no matching request
|
|
23
19
|
path until a route is added.
|
|
24
20
|
|
|
25
|
-
Rule expression validation, analysis, normalization, and minification expose structured
|
|
26
|
-
`diagnostics` with stable `id`, explicit `severity`, and interpolation `params`
|
|
27
|
-
for localization. The diagnostic `message` is an optional, deprecated
|
|
28
|
-
compatibility field. The legacy `errors` and `warnings` string arrays on
|
|
29
|
-
validation results, and `warnings` on analysis, normalization, and minification results, are also
|
|
30
|
-
deprecated compatibility fields; new integrations should derive user-visible
|
|
31
|
-
messages from diagnostic IDs and params.
|
|
32
|
-
|
|
33
21
|
`handleRequest` calls that provide a custom `originFetcher` without
|
|
34
22
|
`stripWorkerRoutePrefix` are deprecated. When `stripWorkerRoutePrefix` is
|
|
35
23
|
configured, origin fetching and rule evaluation both use the stripped origin
|
|
@@ -40,6 +28,109 @@ config to add `request.client_hostname` to log events. The runtime performs a
|
|
|
40
28
|
bounded reverse DNS lookup for the `cf-connecting-ip` header during the existing
|
|
41
29
|
background logging work and caches resolved hostnames per Worker isolate.
|
|
42
30
|
|
|
31
|
+
## Rule Expressions
|
|
32
|
+
|
|
33
|
+
Evaluation:
|
|
34
|
+
|
|
35
|
+
- `evaluateExpression`: Cloudflare Rules expression evaluator for Worker-side diagnostics. See [Rule Expression Evaluation](#rule-expression-evaluation).
|
|
36
|
+
|
|
37
|
+
Analysis:
|
|
38
|
+
|
|
39
|
+
- `analyzeRuleExpression`: versioned, JSON-safe Cloudflare Rules AST, symbol metadata, and optional block-comment metadata for dashboard inference.
|
|
40
|
+
- `foldRuleExpressionAst`: bottom-up public AST reducer for custom dashboard inference.
|
|
41
|
+
|
|
42
|
+
Validation:
|
|
43
|
+
|
|
44
|
+
- `validateRuleExpressionSyntax`: syntax, length, and field availability validation for Cloudflare URL Rewrite Rule filter expressions by default. Pass an explicit config object for minification, length enforcement, preset, field availability, deprecated-field notices, and list-reference policy. With minification enabled it validates the minified expression against Cloudflare's 4096-character rule limit by default; when minification is disabled, the result omits `minifiedExpression` and `minifiedLength`.
|
|
45
|
+
- `validateLoggingSourceKeyRuleExpressionSyntax`: runtime-only source-key rule validation using the pre-origin field context, without Custom List references or deployment length enforcement.
|
|
46
|
+
|
|
47
|
+
Formatting:
|
|
48
|
+
|
|
49
|
+
- `normalizeRuleExpression`: syntax-aware readable formatter that preserves operator notation, grouping, and string literal spelling while canonicalizing grammar whitespace.
|
|
50
|
+
- `minifyRuleExpression`: syntax-aware minifier for Cloudflare Rules expressions before Rewrite Rule deployment. It uses C-like operators, removes precedence-redundant grouping, and preserves string literal spelling. Syntax-invalid source is returned unchanged with diagnostics.
|
|
51
|
+
|
|
52
|
+
Reference metadata for dashboard editors:
|
|
53
|
+
|
|
54
|
+
- `getRuleExpressionFieldDescriptions`: field descriptions filtered by the same preset and field availability override shape used by rule expression validation.
|
|
55
|
+
- `getRuleExpressionFunctionDescriptions`: function reference metadata, including signatures, return types, parameter roles, and evaluator support notes.
|
|
56
|
+
- `RULE_EXPRESSION_COUNTRY_CODES`: generated ISO 3166-1 alpha-2 country codes plus Cloudflare's `T1` and `XX` special values, used by field metadata and semantic validation.
|
|
57
|
+
|
|
58
|
+
### Diagnostics
|
|
59
|
+
|
|
60
|
+
Rule expression validation, analysis, normalization, and minification expose structured
|
|
61
|
+
`diagnostics` with stable `id`, explicit `severity`, and interpolation `params`
|
|
62
|
+
for localization. Each result always includes the diagnostics array. Validation
|
|
63
|
+
and analysis diagnostics identify their source expression, while normalization
|
|
64
|
+
and minification diagnostics apply directly to their single input expression.
|
|
65
|
+
Integrations derive user-visible messages from diagnostic IDs and params.
|
|
66
|
+
|
|
67
|
+
## Rule Expression Evaluation
|
|
68
|
+
|
|
69
|
+
### Valid Expressions Only
|
|
70
|
+
|
|
71
|
+
`evaluateExpression` and `explainExpressionMatch` evaluate only expressions
|
|
72
|
+
Cloudflare accepts. An expression with a syntax error, a type mismatch such as
|
|
73
|
+
a Number compared with a String, an invalid function call such as `coalesce()`
|
|
74
|
+
with one argument, or a field on the right of an operator other than `eq`,
|
|
75
|
+
`ne`, `lt`, `le`, `gt` or `ge` is not evaluated and does not match, even if
|
|
76
|
+
another branch would match. The warnings list the validation errors. Field
|
|
77
|
+
availability is not part of this check, but unknown fields are.
|
|
78
|
+
|
|
79
|
+
### Comparisons and Missing Values
|
|
80
|
+
|
|
81
|
+
The right side of `eq`, `ne`, `lt`, `le`, `gt`, and `ge` can be a field,
|
|
82
|
+
indexed value, or function result, as in
|
|
83
|
+
`http.request.uri.path ne raw.http.request.uri.path`, and `coalesce()` provides
|
|
84
|
+
a fallback for missing values. `evaluateExpression` applies Cloudflare's
|
|
85
|
+
missing-value (nil) comparison results to absent map keys, out-of-bounds
|
|
86
|
+
indexes, and nil function results. For example, both sides being missing makes
|
|
87
|
+
`eq` true, and one missing side makes `ne` true.
|
|
88
|
+
|
|
89
|
+
Equality and ordering comparisons use each operand's declared type. Values are
|
|
90
|
+
converted to that type before comparing, so a numeric `request.cf` value that
|
|
91
|
+
arrives as text still compares as a number. Strings are ordered by code point,
|
|
92
|
+
which matches Cloudflare's byte order, and IP addresses are compared as
|
|
93
|
+
addresses rather than as text. A value that cannot be converted to its
|
|
94
|
+
declared type, such as a non-numeric `request.cf` value for a Number field,
|
|
95
|
+
makes the comparison unknown.
|
|
96
|
+
|
|
97
|
+
### Literals and Inline Lists
|
|
98
|
+
|
|
99
|
+
As in Cloudflare, inline list elements keep the type they are written as:
|
|
100
|
+
quoted elements are Strings that match exactly, so `{"10.0.0.0/8"}` is not a
|
|
101
|
+
CIDR, and unquoted elements are Integers, IP addresses, CIDRs, or ranges.
|
|
102
|
+
Inline lists only work with `in`.
|
|
103
|
+
|
|
104
|
+
There are no Boolean literals: `true` is accepted only as the entire
|
|
105
|
+
expression, which matches every request, and a non-Boolean field such as
|
|
106
|
+
`http.host` cannot be used as a condition on its own. Cloudflare's unquoted hex
|
|
107
|
+
byte literals, such as `65:78:61`, are not supported; write those values as
|
|
108
|
+
quoted strings.
|
|
109
|
+
|
|
110
|
+
### Maps
|
|
111
|
+
|
|
112
|
+
The request header, cookie, and query argument maps are values too: functions
|
|
113
|
+
such as `coalesce()` and `has_key()` accept them, and `["key"]` and `[*]` work
|
|
114
|
+
on a function's map result as on the field itself, so
|
|
115
|
+
`coalesce(http.request.uri.args, http.request.cookies)["x"][0]` reads the query
|
|
116
|
+
argument. A map is never nil, so `coalesce()` returns its first map argument.
|
|
117
|
+
|
|
118
|
+
### Unknown Values and List Inference
|
|
119
|
+
|
|
120
|
+
Values the evaluator cannot resolve are unknown rather than nil. These include
|
|
121
|
+
`raw.*` request fields in Worker context, request metadata missing from the
|
|
122
|
+
request, such as `request.cf` properties or the `cf-connecting-ip` header behind
|
|
123
|
+
`ip.src`, and results of functions it cannot reproduce, such as `sha256()` and
|
|
124
|
+
`is_jwt_valid()`. An unknown value makes the functions and comparisons that use
|
|
125
|
+
it unknown. It also makes `not`, `and`, `or` and `xor` unknown, unless another
|
|
126
|
+
operand settles the result. An unknown result does not match, and the
|
|
127
|
+
evaluation warnings name the values involved.
|
|
128
|
+
|
|
129
|
+
Unresolved Cloudflare list references are the exception: they count as
|
|
130
|
+
inferred matches whenever assuming the list results alone can make the
|
|
131
|
+
expression match. Set `inferListMatches: false` to report such expressions as
|
|
132
|
+
not matched instead.
|
|
133
|
+
|
|
43
134
|
## Development
|
|
44
135
|
|
|
45
136
|
```powershell
|
|
@@ -55,11 +146,18 @@ npm pack --dry-run
|
|
|
55
146
|
|
|
56
147
|
The package emits publishable files to `dist/`. Publishing is configured for restricted scoped package access.
|
|
57
148
|
|
|
149
|
+
Rule parser/evaluator refactor notes are tracked in
|
|
150
|
+
[`docs/rule-evaluator-refactor.md`](docs/rule-evaluator-refactor.md).
|
|
151
|
+
|
|
152
|
+
### Diagnosing Rule Misses
|
|
153
|
+
|
|
58
154
|
To diagnose why an expression does not match a captured request log:
|
|
59
155
|
|
|
60
156
|
```powershell
|
|
61
157
|
npm run explain:rule -- --sample <log-json-path> --expr 'http.host eq "example.com"'
|
|
62
158
|
```
|
|
63
159
|
|
|
64
|
-
|
|
65
|
-
|
|
160
|
+
The tool reports with `explainExpressionMatch`. In its results, `actual` and
|
|
161
|
+
`expected` hold only observed values, so `null` is a Cloudflare missing value
|
|
162
|
+
and `[]` an empty collection. An operand the evaluator cannot resolve is
|
|
163
|
+
omitted and named in `unavailable`.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ComparisonNode, type FuncNode } from './ast.js';
|
|
2
2
|
import type { ResolverCtx } from './fields.js';
|
|
3
|
-
|
|
3
|
+
import type { Outcome } from './outcome.js';
|
|
4
|
+
export declare function warnIfAcceptEncodingZstdSensitive(node: ComparisonNode | FuncNode, ctx: ResolverCtx, currentResult: boolean, evaluateWithCtx: (testCtx: ResolverCtx) => Outcome): void;
|
|
4
5
|
//# sourceMappingURL=accept-encoding.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accept-encoding.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/accept-encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,cAAc,EAAkB,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC3F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"accept-encoding.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/accept-encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,cAAc,EAAkB,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC3F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AA4D5C,wBAAgB,iCAAiC,CAChD,IAAI,EAAE,cAAc,GAAG,QAAQ,EAC/B,GAAG,EAAE,WAAW,EAChB,aAAa,EAAE,OAAO,EACtB,eAAe,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,GAChD,IAAI,CAiBN"}
|
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
import { pushWarning } from './ast.js';
|
|
2
|
-
|
|
2
|
+
/** Reads the Accept-Encoding header directly, or reads the whole headers map, such as with [*] or has_key(). */
|
|
3
3
|
function isAcceptEncodingFieldNode(node) {
|
|
4
|
-
|
|
5
|
-
return node.name === 'http.request.headers' && mapKey?.key.toLowerCase() === 'accept-encoding';
|
|
6
|
-
}
|
|
7
|
-
function funcUsesAcceptEncoding(node) {
|
|
8
|
-
const arg0 = node.args[0];
|
|
9
|
-
if (!arg0 || typeof arg0 !== 'object' || !('kind' in arg0))
|
|
4
|
+
if (node.name !== 'http.request.headers')
|
|
10
5
|
return false;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
const mapKey = node.accessPath[0];
|
|
7
|
+
return mapKey?.kind !== 'MapKeyAccess' || mapKey.key.toLowerCase() === 'accept-encoding';
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Whether an expression reads the Accept-Encoding header anywhere, including
|
|
11
|
+
* in later function arguments, such as coalesce() fallbacks, and in nested
|
|
12
|
+
* any()/all() predicates.
|
|
13
|
+
*/
|
|
14
|
+
function usesAcceptEncoding(node) {
|
|
15
|
+
switch (node?.kind) {
|
|
16
|
+
case 'Field':
|
|
17
|
+
return isAcceptEncodingFieldNode(node);
|
|
18
|
+
case 'Func':
|
|
19
|
+
return node.args.some(usesAcceptEncoding);
|
|
20
|
+
case 'Comparison':
|
|
21
|
+
return usesAcceptEncoding(node.left) || usesAcceptEncoding(node.right);
|
|
22
|
+
case 'Not':
|
|
23
|
+
return usesAcceptEncoding(node.operand);
|
|
24
|
+
case 'And':
|
|
25
|
+
case 'Or':
|
|
26
|
+
case 'Xor':
|
|
27
|
+
return node.operands.some(usesAcceptEncoding);
|
|
28
|
+
default:
|
|
29
|
+
return false;
|
|
16
30
|
}
|
|
17
|
-
return false;
|
|
18
31
|
}
|
|
19
32
|
function parseAcceptEncodingTokens(value) {
|
|
20
33
|
if (!value)
|
|
@@ -46,22 +59,7 @@ export function warnIfAcceptEncodingZstdSensitive(node, ctx, currentResult, eval
|
|
|
46
59
|
if (parseAcceptEncodingTokens(responseContentEncoding).some(token => token === 'zstd')) {
|
|
47
60
|
return;
|
|
48
61
|
}
|
|
49
|
-
|
|
50
|
-
? (node.left.kind === 'Func' ? funcUsesAcceptEncoding(node.left) : isAcceptEncodingFieldNode(node.left))
|
|
51
|
-
: (() => {
|
|
52
|
-
if (node.name !== 'any' && node.name !== 'all')
|
|
53
|
-
return false;
|
|
54
|
-
const fieldArg = extractQuantifierPredicate(node)?.source;
|
|
55
|
-
if (!fieldArg)
|
|
56
|
-
return false;
|
|
57
|
-
if (fieldArg.kind === 'Func')
|
|
58
|
-
return funcUsesAcceptEncoding(fieldArg);
|
|
59
|
-
if (fieldArg.kind === 'Field') {
|
|
60
|
-
return isAcceptEncodingFieldNode(fieldArg);
|
|
61
|
-
}
|
|
62
|
-
return false;
|
|
63
|
-
})();
|
|
64
|
-
if (!usesAcceptEncoding)
|
|
62
|
+
if (!usesAcceptEncoding(node))
|
|
65
63
|
return;
|
|
66
64
|
const toggledAcceptEncoding = toggleZstdInAcceptEncoding(ctx.cf.clientAcceptEncoding ?? ctx.request.headers.get('accept-encoding') ?? '');
|
|
67
65
|
const toggledCtx = withAcceptEncodingOverride(ctx, toggledAcceptEncoding);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accept-encoding.js","sourceRoot":"","sources":["../../src/rule-evaluator/accept-encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAsD,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"accept-encoding.js","sourceRoot":"","sources":["../../src/rule-evaluator/accept-encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAsD,MAAM,UAAU,CAAC;AAI3F,gHAAgH;AAChH,SAAS,yBAAyB,CAAC,IAAe;IACjD,IAAI,IAAI,CAAC,IAAI,KAAK,sBAAsB;QAAE,OAAO,KAAK,CAAC;IACvD,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAClC,OAAO,MAAM,EAAE,IAAI,KAAK,cAAc,IAAI,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,iBAAiB,CAAC;AAC1F,CAAC;AAED;;;;GAIG;AACH,SAAS,kBAAkB,CAAC,IAA0C;IACrE,QAAQ,IAAI,EAAE,IAAI,EAAE,CAAC;QACpB,KAAK,OAAO;YACX,OAAO,yBAAyB,CAAC,IAAI,CAAC,CAAC;QACxC,KAAK,MAAM;YACV,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAC3C,KAAK,YAAY;YAChB,OAAO,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxE,KAAK,KAAK;YACT,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzC,KAAK,KAAK,CAAC;QACX,KAAK,IAAI,CAAC;QACV,KAAK,KAAK;YACT,OAAO,IAAI,CAAC,QAAQ,CAAC,IAA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AAM,uBAAuB,GAAG,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC;IACpF,IAAI,yBAAyB,CAAC,uBAAuB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC,EAAE,CAAC;QACxF,OAAO;IACR,CAAC;IAED,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC;QAAE,OAAO;IAEtC,MAAM,qBAAqB,GAAG,0BAA0B,CAAC,GAAG,CAAC,EAAE,CAAC,oBAAoB,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1I,MAAM,UAAU,GAAG,0BAA0B,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC;IAC1E,MAAM,aAAa,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC;IAClD,IAAI,aAAa,KAAK,aAAa,EAAE,CAAC;QACrC,WAAW,CACV,GAAG,CAAC,QAAQ,EACZ,qHAAqH,IAAI,CAAC,GAAG,qDAAqD,CAClL,CAAC;IACH,CAAC;AACF,CAAC"}
|
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
import type { AccessNode, CfValue } from './ast.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* A map field's value while evaluating, such as http.request.headers. Maps
|
|
4
|
+
* only reach functions that accept them, such as has_key() and coalesce(),
|
|
5
|
+
* and postfix access; validation keeps them out of comparisons.
|
|
6
|
+
*/
|
|
7
|
+
export declare class RuleMapValue {
|
|
8
|
+
private readonly lookup;
|
|
9
|
+
private readonly keys;
|
|
10
|
+
constructor(lookup: (key: string) => CfValue, keys: () => readonly string[]);
|
|
11
|
+
/** The values for a key, or null when the map has no such key. */
|
|
12
|
+
get(key: string): CfValue;
|
|
13
|
+
/** Every key's values, which `[*]` iterates. */
|
|
14
|
+
values(): CfValue[];
|
|
15
|
+
}
|
|
16
|
+
/** A value while evaluating: a rule-language value, or a map. */
|
|
17
|
+
export type RuntimeValue = CfValue | RuleMapValue;
|
|
18
|
+
/**
|
|
19
|
+
* Applies postfix map and array access while preserving Cloudflare's
|
|
20
|
+
* vectorized `[*]` state. Once expanded, later access segments are mapped over
|
|
21
|
+
* every active element instead of indexing the outer result array, and, as in
|
|
22
|
+
* Wirefilter, an element without the accessed index is skipped. Without `[*]`,
|
|
23
|
+
* a missing index is nil. On a map, `["key"]` reads one key's values and `[*]`
|
|
24
|
+
* iterates every key's values.
|
|
6
25
|
*/
|
|
7
26
|
export declare function applyValueAccessPath(value: CfValue, accessPath: readonly AccessNode[]): CfValue;
|
|
27
|
+
export declare function applyValueAccessPath(value: RuntimeValue, accessPath: readonly AccessNode[]): RuntimeValue;
|
|
8
28
|
//# sourceMappingURL=access-values.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-values.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/access-values.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEpD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,UAAU,EAAE,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"access-values.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/access-values.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEpD;;;;GAIG;AACH,qBAAa,YAAY;IAEvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBADJ,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,EAChC,IAAI,EAAE,MAAM,SAAS,MAAM,EAAE;IAG/C,kEAAkE;IAClE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIzB,gDAAgD;IAChD,MAAM,IAAI,OAAO,EAAE;CAGnB;AAED,iEAAiE;AACjE,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,YAAY,CAAC;AAElD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,UAAU,EAAE,GAAG,OAAO,CAAC;AACjG,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,UAAU,EAAE,GAAG,YAAY,CAAC"}
|
|
@@ -1,27 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* A map field's value while evaluating, such as http.request.headers. Maps
|
|
3
|
+
* only reach functions that accept them, such as has_key() and coalesce(),
|
|
4
|
+
* and postfix access; validation keeps them out of comparisons.
|
|
5
5
|
*/
|
|
6
|
+
export class RuleMapValue {
|
|
7
|
+
lookup;
|
|
8
|
+
keys;
|
|
9
|
+
constructor(lookup, keys) {
|
|
10
|
+
this.lookup = lookup;
|
|
11
|
+
this.keys = keys;
|
|
12
|
+
}
|
|
13
|
+
/** The values for a key, or null when the map has no such key. */
|
|
14
|
+
get(key) {
|
|
15
|
+
return this.lookup(key);
|
|
16
|
+
}
|
|
17
|
+
/** Every key's values, which `[*]` iterates. */
|
|
18
|
+
values() {
|
|
19
|
+
return this.keys().map(key => this.lookup(key) ?? []);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
6
22
|
export function applyValueAccessPath(value, accessPath) {
|
|
7
23
|
let current = value;
|
|
8
24
|
let expanded = false;
|
|
9
25
|
for (const access of accessPath) {
|
|
26
|
+
if (current instanceof RuleMapValue) {
|
|
27
|
+
if (access.kind === 'MapKeyAccess') {
|
|
28
|
+
current = current.get(access.key);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (access.kind === 'ArrayIndexAccess')
|
|
32
|
+
return null;
|
|
33
|
+
current = current.values();
|
|
34
|
+
expanded = true;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
10
37
|
if (access.kind === 'MapKeyAccess')
|
|
11
38
|
return null;
|
|
12
39
|
if (access.kind === 'ArrayWildcardAccess') {
|
|
13
40
|
if (!Array.isArray(current))
|
|
14
41
|
return null;
|
|
15
|
-
if (expanded)
|
|
16
|
-
|
|
17
|
-
for (const item of current) {
|
|
18
|
-
if (Array.isArray(item))
|
|
19
|
-
next.push(...item);
|
|
20
|
-
else
|
|
21
|
-
next.push(null);
|
|
22
|
-
}
|
|
23
|
-
current = next;
|
|
24
|
-
}
|
|
42
|
+
if (expanded)
|
|
43
|
+
current = current.flatMap(item => Array.isArray(item) ? item : []);
|
|
25
44
|
expanded = true;
|
|
26
45
|
continue;
|
|
27
46
|
}
|
|
@@ -33,7 +52,8 @@ export function applyValueAccessPath(value, accessPath) {
|
|
|
33
52
|
}
|
|
34
53
|
if (!Array.isArray(current))
|
|
35
54
|
return null;
|
|
36
|
-
|
|
55
|
+
const { index } = access;
|
|
56
|
+
current = current.flatMap(item => Array.isArray(item) && index < item.length ? [item[index]] : []);
|
|
37
57
|
}
|
|
38
58
|
return current;
|
|
39
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-values.js","sourceRoot":"","sources":["../../src/rule-evaluator/access-values.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,
|
|
1
|
+
{"version":3,"file":"access-values.js","sourceRoot":"","sources":["../../src/rule-evaluator/access-values.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAEN;IACA;IAFlB,YACkB,MAAgC,EAChC,IAA6B;QAD7B,WAAM,GAAN,MAAM,CAA0B;QAChC,SAAI,GAAJ,IAAI,CAAyB;IAC5C,CAAC;IAEJ,kEAAkE;IAClE,GAAG,CAAC,GAAW;Q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I,CAAC,QAAQ,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;gBAAE,OAAO,IAAI,CAAC;YACzC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;YACxC,SAAS;QACV,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;YAAE,OAAO,IAAI,CAAC;QACzC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;QACzB,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACpG,CAAC;IAED,OAAO,OAAO,CAAC;AAChB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type RuleExpressionFieldValueDomain } from './field-value-domains.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type RuleExpressionDiagnostic } from './diagnostics.js';
|
|
3
3
|
export interface RuleExpressionSourceSpan {
|
|
4
4
|
pos: number | null;
|
|
5
5
|
length: number;
|
|
@@ -7,7 +7,7 @@ export interface RuleExpressionSourceSpan {
|
|
|
7
7
|
export type RuleExpressionAnalyzedValueType = 'Array' | 'Boolean' | 'IP address' | 'List' | 'Map' | 'Number' | 'Set' | 'String' | 'Unknown' | string;
|
|
8
8
|
export type RuleExpressionComparisonOperator = 'eq' | 'ne' | 'lt' | 'le' | 'gt' | 'ge' | 'contains' | 'matches' | 'wildcard' | 'strict_wildcard' | 'in';
|
|
9
9
|
export type RuleExpressionPublicAstNode = RuleExpressionLogicalAstNode | RuleExpressionNotAstNode | RuleExpressionComparisonAstNode | RuleExpressionQuantifierAstNode | RuleExpressionFunctionCallAstNode | RuleExpressionFieldAstNode | RuleExpressionLiteralAstNode | RuleExpressionSetAstNode | RuleExpressionListAstNode;
|
|
10
|
-
export type RuleExpressionPublicValueAstNode = RuleExpressionFunctionCallAstNode | RuleExpressionFieldAstNode | RuleExpressionLiteralAstNode | RuleExpressionSetAstNode | RuleExpressionListAstNode;
|
|
10
|
+
export type RuleExpressionPublicValueAstNode = RuleExpressionFunctionCallAstNode | RuleExpressionQuantifierAstNode | RuleExpressionFieldAstNode | RuleExpressionLiteralAstNode | RuleExpressionSetAstNode | RuleExpressionListAstNode;
|
|
11
11
|
interface RuleExpressionPublicAstBase {
|
|
12
12
|
raw: string;
|
|
13
13
|
span: RuleExpressionSourceSpan;
|
|
@@ -151,7 +151,7 @@ export interface RuleExpressionRequirements {
|
|
|
151
151
|
}[];
|
|
152
152
|
}
|
|
153
153
|
export interface RuleExpressionAnalysis {
|
|
154
|
-
version:
|
|
154
|
+
version: 4;
|
|
155
155
|
expression: string;
|
|
156
156
|
ast: RuleExpressionPublicAstNode;
|
|
157
157
|
symbols: RuleExpressionSymbols;
|
|
@@ -159,10 +159,6 @@ export interface RuleExpressionAnalysis {
|
|
|
159
159
|
requirements: RuleExpressionRequirements;
|
|
160
160
|
/** Structured rule expression diagnostics with stable IDs for localization. */
|
|
161
161
|
diagnostics: RuleExpressionDiagnostic[];
|
|
162
|
-
/**
|
|
163
|
-
* @deprecated Use `diagnostics` instead.
|
|
164
|
-
*/
|
|
165
|
-
warnings: string[];
|
|
166
162
|
}
|
|
167
163
|
export interface RuleExpressionAnalysisOptions {
|
|
168
164
|
comments?: 'block';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analysis.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/analysis.ts"],"names":[],"mappings":"AAQA,OAAO,EAEN,KAAK,8BAA8B,EACnC,MAAM,0BAA0B,CAAC;AAuBlC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"analysis.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/analysis.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C;IAC3D,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,mBAAmB,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACxD;AAED,MAAM,WAAW,sBAAsB;IACtC,OAAO,EAAE,CAAC,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,2BAA2B,CAAC;IACjC,OAAO,EAAE,qBAAqB,CAAC;IAC/B,QAAQ,EAAE,qBAAqB,EAAE,CAAC;IAClC,YAAY,EAAE,0BAA0B,CAAC;IACzC,+EAA+E;IAC/E,WAAW,EAAE,wBAAwB,EAAE,CAAC;CACxC;AAED,MAAM,WAAW,6BAA6B;IAC7C,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AAoBD;;;GAGG;AACH,wBAAgB,qBAAqB,CACpC,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,6BAAkC,GACzC,sBAAsB,CAmBxB"}
|
|
@@ -6,6 +6,7 @@ import { getUnreliableRuleExpressionFunctionReason } from './functions.js';
|
|
|
6
6
|
import { parseExpression } from './parse-cache.js';
|
|
7
7
|
import { extractQuantifierPredicate } from './quantifier.js';
|
|
8
8
|
import { formatRuleExpressionDataType, inferRuleExpressionArgument, isArrayMappedFunctionNode, } from './rule-language-types.js';
|
|
9
|
+
import { ruleExpressionDiagnostic, } from './diagnostics.js';
|
|
9
10
|
const FIELD_DESCRIPTIONS = RULE_EXPRESSION_FIELD_DESCRIPTIONS;
|
|
10
11
|
const FUNCTION_DESCRIPTIONS = RULE_EXPRESSION_FUNCTION_DESCRIPTIONS;
|
|
11
12
|
/**
|
|
@@ -23,14 +24,13 @@ export function analyzeRuleExpression(expression, options = {}) {
|
|
|
23
24
|
};
|
|
24
25
|
const analyzedAst = analyzeExprNode(ast, state);
|
|
25
26
|
return {
|
|
26
|
-
version:
|
|
27
|
+
version: 4,
|
|
27
28
|
expression,
|
|
28
29
|
ast: analyzedAst,
|
|
29
30
|
symbols: state.symbols,
|
|
30
31
|
comments: analyzeComments(comments),
|
|
31
32
|
requirements: requirementsFromSymbols(state.symbols),
|
|
32
|
-
diagnostics:
|
|
33
|
-
warnings,
|
|
33
|
+
diagnostics: parseDiagnostics.map(diagnostic => ruleExpressionDiagnostic(diagnostic, 'expression')),
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
function analyzeComments(comments) {
|
|
@@ -192,7 +192,8 @@ function analyzeValueNode(node, state) {
|
|
|
192
192
|
case 'Field':
|
|
193
193
|
return analyzeFieldLikeNode(node, state);
|
|
194
194
|
case 'Func':
|
|
195
|
-
|
|
195
|
+
// Nested any()/all() keep their predicate, as at the top level.
|
|
196
|
+
return analyzeFuncNode(node, state);
|
|
196
197
|
case 'StringLiteral':
|
|
197
198
|
case 'NumberLiteral':
|
|
198
199
|
case 'IpLiteral':
|
|
@@ -296,8 +297,8 @@ function analyzeLiteralNode(node, state) {
|
|
|
296
297
|
function analyzeSetNode(node, state) {
|
|
297
298
|
return {
|
|
298
299
|
kind: 'Set',
|
|
299
|
-
values: node.
|
|
300
|
-
elementType: setElementType(node
|
|
300
|
+
values: node.elements.map(element => element.value),
|
|
301
|
+
elementType: setElementType(node),
|
|
301
302
|
raw: state.source.slice(node.pos ?? 0, (node.pos ?? 0) + (node.length ?? 0)),
|
|
302
303
|
span: nodeSpan(node, state.source),
|
|
303
304
|
valueType: 'Set',
|
|
@@ -335,19 +336,15 @@ function fieldRuntimeAvailability(name) {
|
|
|
335
336
|
return 'unavailable';
|
|
336
337
|
return 'unknown';
|
|
337
338
|
}
|
|
338
|
-
function setElementType(
|
|
339
|
-
|
|
339
|
+
function setElementType(node) {
|
|
340
|
+
const types = new Set(node.elements.map(element => element.type));
|
|
341
|
+
if (types.size !== 1)
|
|
340
342
|
return 'Unknown';
|
|
341
|
-
if (
|
|
343
|
+
if (types.has('integer'))
|
|
342
344
|
return 'Number';
|
|
343
|
-
if (
|
|
345
|
+
if (types.has('ip'))
|
|
344
346
|
return 'IP address';
|
|
345
|
-
|
|
346
|
-
return 'String';
|
|
347
|
-
return 'Unknown';
|
|
348
|
-
}
|
|
349
|
-
function valueLooksLikeIp(value) {
|
|
350
|
-
return value.includes(':') || /^\d+\.\d+\.\d+\.\d+(?:\/\d+)?(?:\.\.\d+\.\d+\.\d+\.\d+)?$/.test(value);
|
|
347
|
+
return 'String';
|
|
351
348
|
}
|
|
352
349
|
function ipLiteralValueType(node) {
|
|
353
350
|
return node.value.includes('/') ? 'IP range' : 'IP address';
|
|
@@ -374,29 +371,6 @@ function mergeSpans(left, right, source, raw) {
|
|
|
374
371
|
const end = Math.max(left.pos + left.length, right.pos + right.length);
|
|
375
372
|
return { pos: start, length: Math.max(end - start, 0) };
|
|
376
373
|
}
|
|
377
|
-
function diagnosticsFromWarnings(warnings, details) {
|
|
378
|
-
const detailedMessages = new Set(details.map(detail => detail.message));
|
|
379
|
-
return [
|
|
380
|
-
...details.map(detail => ({
|
|
381
|
-
...(detail.id ? { id: detail.id } : {}),
|
|
382
|
-
...(detail.params ? { params: detail.params } : {}),
|
|
383
|
-
severity: detail.severity,
|
|
384
|
-
message: detail.message,
|
|
385
|
-
pos: detail.pos ?? null,
|
|
386
|
-
length: detail.length,
|
|
387
|
-
source: 'expression',
|
|
388
|
-
})),
|
|
389
|
-
...warnings
|
|
390
|
-
.filter(message => !detailedMessages.has(message))
|
|
391
|
-
.map(message => ({
|
|
392
|
-
severity: 'warning',
|
|
393
|
-
message,
|
|
394
|
-
pos: null,
|
|
395
|
-
length: 0,
|
|
396
|
-
source: 'expression',
|
|
397
|
-
})),
|
|
398
|
-
];
|
|
399
|
-
}
|
|
400
374
|
function requirementsFromSymbols(symbols) {
|
|
401
375
|
return {
|
|
402
376
|
fields: unique(symbols.fields.map(field => field.name)),
|