-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
data queries #965
Merged
data queries #965
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8f9aade
feat: ✨ add @elastic/micro-jq for JQ transformations
pelikhan efa1e47
jq support in defData
pelikhan f97cd3f
feat: 🆕 add jq query support for data filtering
pelikhan a19aba5
feat: ✨ add jq support to parsers for data filtering
pelikhan b84f88c
feat: ✨ add jq parser support for JSON transformation
pelikhan 46d41d6
feat: ✨ add detectPromptInjection support for defData
pelikhan 33788a1
feat: ✨ add support for multiple queries in jq function
pelikhan db59ddd
moving to groq
pelikhan 8fdde66
add cot
pelikhan 61aa64c
refactor: ♻️ update return type and comment in GROQEvaluate
pelikhan 7a868fe
feat: ✨ add support for root and params in GROQEvaluate
pelikhan 43ed7f3
feat: 🤖 add JSON schema inference and utilities
pelikhan 42658c5
docs: ✏️ add inference section for JSON schema generation
pelikhan 143af5d
refactor: ♻️ update return type for renderDefDataNode to Promise
pelikhan 0acea5b
refactor: ♻️ simplify cache control logic and formatting
pelikhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7091,6 +7091,30 @@ THIS SOFTWARE. | |
|
||
----------- | ||
|
||
The following npm package may be included in this product: | ||
|
||
- [email protected] | ||
|
||
This package contains the following license: | ||
|
||
ISC License | ||
|
||
Copyright (c) 2020, Stefan Terdell | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
|
||
----------- | ||
|
||
The following npm package may be included in this product: | ||
|
||
- [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { jq } from "./jq" | ||
import { describe, test } from "node:test" | ||
import assert from "node:assert/strict" | ||
|
||
describe("jq", () => { | ||
test("returns undefined when input is undefined", () => { | ||
const result = jq(undefined, ".") | ||
assert.strictEqual(result, undefined) | ||
}) | ||
|
||
test("applies JQ transformation to input data", () => { | ||
const input = { name: "John", age: 30 } | ||
const query = ".name" | ||
const result = jq(input, query) | ||
assert.strictEqual(result, "John") | ||
}) | ||
|
||
test("handles nested objects correctly", () => { | ||
const input = { person: { name: "John", age: 30 } } | ||
const query = ".person.name" | ||
const result = jq(input, query) | ||
assert.strictEqual(result, "John") | ||
}) | ||
|
||
test("returns null for non-existent keys", () => { | ||
const input = { name: "John", age: 30 } | ||
const query = ".address" | ||
const result = jq(input, query) | ||
assert.strictEqual(result, null) | ||
}) | ||
|
||
test("handles arrays correctly", () => { | ||
const input = { people: [{ name: "John" }, { name: "Jane" }] } | ||
const query = ".people[1].name" | ||
const result = jq(input, query) | ||
assert.strictEqual(result, "Jane") | ||
}) | ||
|
||
test("returns entire input when query is '.'", () => { | ||
const input = { name: "John", age: 30 } | ||
const query = "." | ||
const result = jq(input, query) | ||
assert.deepStrictEqual(result, input) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import _jq from "jqts" | ||
|
||
/** | ||
* Loads and applies JQ transformation to the input data | ||
* @param input | ||
*/ | ||
export function jq(input: any, query: string): any { | ||
if (input === undefined) return input | ||
|
||
const pattern = _jq.compile(query) | ||
const res = pattern.evaluate(input)[0] | ||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The link to the jq documentation is missing a closing parenthesis. It should be
https://jqlang.github.io/jq/
.