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
4 changes: 2 additions & 2 deletions js/httpql/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const readFile = (path: string) => {
describe("httpql", () => {
describe("ast", () => {
const cases = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23,
];
for (const c of cases) {
it(`Case ${c}`, () => {
Expand Down
5 changes: 2 additions & 3 deletions js/httpql/src/parser/parser.terms.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// This file was generated by lezer-generator. You probably shouldn't edit it.
export const
BlockComment = 1,
export const BlockComment = 1,
LineComment = 2,
HTTPQL = 3,
Query = 4,
Expand Down Expand Up @@ -57,4 +56,4 @@ export const
GroupQuery = 55,
LogicalQuery = 56,
And = 57,
Or = 58
Or = 58;
43 changes: 30 additions & 13 deletions js/httpql/src/parser/parser.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/httpql/src/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { err, ok, Result } from "neverthrow";

import { type HTTPQLError, InvalidQuery } from "./errors.js";
import {
OperatorString,
type ClauseHeader,
type ClauseRequest,
type ClauseResponse,
Expand All @@ -13,6 +12,7 @@ import {
type ExprPreset,
type ExprSource,
type ExprString,
OperatorString,
type Query,
} from "./primitives.js";
import { isPresent } from "./utils.js";
Expand Down
2 changes: 1 addition & 1 deletion js/streamql/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@caido/streamql",
"version": "0.3.0",
"version": "0.3.1",
"description": "Parser for the StreamQL language",
"author": "Caido Labs Inc. <dev@caido.io>",
"repository": "https://github.com/caido/httpql",
Expand Down
25 changes: 25 additions & 0 deletions js/streamql/src/deserialize/clause.websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { ClauseWs } from "../primitives.js";
import { getChildString, isPresent } from "../utils.js";

import { deserializeDateExpr } from "./expr.date.js";
import { deserializeIntExpr } from "./expr.int.js";
import { deserializeStringExpr } from "./expr.string.js";

export const deserializeWsClause = (
Expand Down Expand Up @@ -40,6 +41,17 @@ export const deserializeWsClause = (
}
})();

const intField = (() => {
const child = getChildString(node, terms.WsIntFieldName, doc);

if (isPresent(child)) {
switch (child) {
case "len":
return "len";
}
}
})();

const stringFilter = (() => {
const child = node.getChild(terms.StringExpression);
if (isPresent(child)) return deserializeStringExpr(child, doc);
Expand All @@ -50,6 +62,11 @@ export const deserializeWsClause = (
if (isPresent(child)) return deserializeDateExpr(child, doc);
})();

const intFilter = (() => {
const child = node.getChild(terms.IntExpression);
if (isPresent(child)) return deserializeIntExpr(child, doc);
})();

if (isPresent(stringField) && isPresent(stringFilter)) {
return stringFilter.map((filter) => {
return {
Expand All @@ -66,5 +83,13 @@ export const deserializeWsClause = (
});
}

if (isPresent(intField) && isPresent(intFilter)) {
return intFilter.map((filter) => {
return {
[intField]: filter,
};
});
}

return err(new InvalidQuery());
};
23 changes: 23 additions & 0 deletions js/streamql/src/deserialize/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,29 @@ describe("deserialize", () => {
});
});

it("should parse StreamQL ws len expression", () => {
const query = "ws.len.gte:1212";

const filter = deserialize(query)._unsafeUnwrap();

expect(filter).to.deep.equal({
websocket: {
len: {
operator: OperatorInt.Gte,
value: 1212,
},
},
});
});

it("should fail given a quoted ws len value", () => {
const query = 'ws.len.lt:"12"';

const result = deserialize(query);

expect(result.isErr()).to.be.true;
});

it("should parse StreamQL AND expression", () => {
const query = 'stream.host.cont:"test.com" AND ws.direction.eq:"client"';

Expand Down
2 changes: 1 addition & 1 deletion js/streamql/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const readFile = (path: string) => {

describe("streamql", () => {
describe("ast", () => {
const cases = [1, 2, 3, 4];
const cases = [1, 2, 3, 4, 5];
for (const c of cases) {
it(`Case ${c}`, () => {
const input = readFile(`ast/${c}/input.streamql`);
Expand Down
1 change: 1 addition & 0 deletions js/streamql/src/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type ClauseWs = {
raw?: Maybe<ExprString>;
direction?: Maybe<ExprString>;
format?: Maybe<ExprString>;
len?: Maybe<ExprInt>;
};

export type ClauseStream = {
Expand Down
3 changes: 3 additions & 0 deletions js/streamql/src/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ const serializeClauseWs = (value: ClauseWs): Result<string, StreamQLError> => {
if (isPresent(value.format)) {
return serializeExprString(value.format).map((str) => `format.${str}`);
}
if (isPresent(value.len)) {
return serializeExprInt(value.len).map((str) => `len.${str}`);
}

return err(new InvalidQuery());
};
Expand Down
1 change: 1 addition & 0 deletions rust/streamql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mod tests {
#[case(2)]
#[case(3)]
#[case(4)]
#[case(5)]
fn test_ast(#[case] case: u32) {
let input =
std::fs::read_to_string(format!("../../tests/streamql/ast/{case}/input.streamql"))
Expand Down
1 change: 1 addition & 0 deletions tests/streamql/ast/5/input.streamql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ws.len.gte:1212 AND stream.port.lt:8080
1 change: 1 addition & 0 deletions tests/streamql/ast/5/output.ast
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(ws.len.gte:1212 and stream.port.lt:8080)
Loading