Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ui/packages/shared/parser/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ test('Partial Parsing ProfileName and rest', () => {
});
});

test('QueryParseBareMatchers', () => {
const input = '{namespace=~"environment-afc16806", pod=~".*"}';
expect(() => Query.parse(input)).not.toThrow();
const q = Query.parse(input);
expect(q.profileName()).toBe('');
expect(q.matchersString()).toBe('namespace=~"environment-afc16806", pod=~".*"');
});

test('Parse Multiline query', () => {
expect(
Query.parse(`memory:alloc_objects:count:space:bytes:delta{
Expand Down
8 changes: 6 additions & 2 deletions ui/packages/shared/parser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
}
}

function findMatcherLabelName(stateStack: any): string {

Check warning on line 51 in ui/packages/shared/parser/src/index.ts

View workflow job for this annotation

GitHub Actions / UI Test and Lint

Unexpected any. Specify a different type
let currentState = stateStack.find((e: any) => e.rule.name === 'matcher');

Check warning on line 52 in ui/packages/shared/parser/src/index.ts

View workflow job for this annotation

GitHub Actions / UI Test and Lint

Unexpected any. Specify a different type

if (currentState === undefined) {
return '';
Expand Down Expand Up @@ -176,7 +176,7 @@
this.inputMatcherString = inputMatcherString;
}

static fromAst(ast: any): Query {

Check warning on line 179 in ui/packages/shared/parser/src/index.ts

View workflow job for this annotation

GitHub Actions / UI Test and Lint

Unexpected any. Specify a different type
if (ast === undefined || ast == null) {
return new Query(new ProfileType('', '', '', '', '', false), [], '');
}
Expand All @@ -185,7 +185,11 @@
(e: any) =>
new Matcher(e.key.value, matcherTypeFromString(e.matcherType.value), e.value.value)
);
return new Query(ProfileType.fromString(ast.profileName.value), matchers, '');
const profileType =
ast.profileName?.value !== undefined
? ProfileType.fromString(ast.profileName.value)
: new ProfileType('', '', '', '', '', false);
return new Query(profileType, matchers, '');
}

static parse(input: string): Query {
Expand Down Expand Up @@ -219,7 +223,7 @@
(s: any) =>
s.data !== undefined && Object.prototype.hasOwnProperty.call(s.data, 'profileName')
).data;
const rest = input.slice(column.lexerState.col - 2);
const rest = column.lexerState !== undefined ? input.slice(column.lexerState.col - 2) : input;
return new Query(
ProfileType.fromString(data.profileName),
[],
Expand Down
Loading