Skip to content

Commit

Permalink
fix: navigation from 0 (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias authored Oct 16, 2024
1 parent 3162329 commit 14ee3a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/shared/fix-query-parser/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ test(`Parse Navigation`, () => {
assert.deepEqual(parse_navigation('-[2]->').toString(), '-[2]->')
assert.deepEqual(parse_navigation('-[2:]->').toString(), '-[2:]->')
assert.deepEqual(parse_navigation('-[2:3]->'), new Navigation({ start: 2, until: 3 }))
assert.deepEqual(parse_navigation('-[0:3]->'), new Navigation({ start: 0, until: 3 }))
assert.deepEqual(
parse_navigation('-[2:3]delete->'),
new Navigation({
Expand Down Expand Up @@ -555,6 +556,7 @@ test('Parse existing queries', () => {
'is(aws_waf_web_acl) and logging_configuration==null',
'with_usage(7d, cpu_utilization_percent) is(instance,database) and /usage.cpu_utilization_percent.max < 10',
'/ancestors.account.reported.id="123456789012"',
'is(aws_iam_user) and name == matthias -->',
]

for (const query of queries) {
Expand Down
9 changes: 5 additions & 4 deletions src/shared/fix-query-parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ const keywordP = alt(tok(T.All), tok(T.Count), tok(T.With), tok(T.Any), tok(T.Em
const keywordS = apply(keywordP, (t) => t.text)
const literalP = alt(tok(T.Literal), keywordP)
const literalS = apply(literalP, (t) => t.text)
const lit_or_num = apply(alt(tok(T.Dot), tok(T.Literal), tok(T.Integer), tok(T.Float)), (t) => t.text)
const lit_combine = apply(alt(tok(T.Minus), tok(T.Colon)), (t) => t.text)
const lit_with_combine = apply(seq(opt(lit_combine), lit_or_num), ([cb, lit]) => (cb ? cb + lit : lit))
JsonElementP.setPattern(
alt(
apply(tok(T.True), () => true),
Expand All @@ -84,9 +87,7 @@ JsonElementP.setPattern(
numberP,
keywordS,
apply(tok(T.DoubleQuotedString), (t) => t.text.slice(1, -1)),
apply(times_n(alt(tok(T.Literal), tok(T.Minus), tok(T.Dot), tok(T.Colon), tok(T.Integer), tok(T.Float))), (ts) =>
ts.map((t) => t.text).join(''),
),
apply(times_n(lit_with_combine), (ts) => ts.join('')),
apply(seq(tok(T.LBracket), tok(T.RBracket)), () => []),
apply(seq(tok(T.LCurly), tok(T.RCurly)), () => ({})),
kmid(tok(T.LBracket), list_sc(JsonElementP, tok(T.Comma)), tok(T.RBracket)),
Expand Down Expand Up @@ -208,7 +209,7 @@ const edge_filter_p = kmid(tok(T.LCurly), EdgeTermP, tok(T.RCurly))
const edge_detail = apply(
seq(opt(edge_types_p), opt(range), opt(edge_filter_p), opt(edge_types_p)),
([et_before, range, edge_filter, et_after]) => {
const start: number = range ? range[0] || 1 : 1
const start: number = range ? (range[0] ?? 1) : 1
const until: number | undefined = range ? range[1] : 1
return new Navigation({ start, until, edge_types: et_before || et_after || [EdgeType.default], edge_filter })
},
Expand Down

0 comments on commit 14ee3a5

Please sign in to comment.