-
Notifications
You must be signed in to change notification settings - Fork 10
feat: filter pubs using jsonata #1421
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
Open
tefkah
wants to merge
10
commits into
main
Choose a base branch
from
tfk/jsonquery
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5020bb8
feat: jsonata query filter
tefkah 7d97b86
feat: add relation and search filtering
tefkah abf7615
feat: replace automation resolver with pub query
tefkah d7c4409
fix: last query problems
tefkah c5d843d
Merge branch 'main' into tfk/jsonquery
tefkah c844593
fix: types
tefkah afc873a
fix: lint
tefkah 8e335ef
fix: make slightly less redundant
tefkah fad3186
fix: clean up a bit
tefkah cdce099
fix: lint
tefkah 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,194 @@ | ||
| # JSONata Query Syntax | ||
|
|
||
| Query language for filtering pubs. Based on JSONata with restrictions. | ||
|
|
||
| ## Paths | ||
|
|
||
| ### Pub field values | ||
|
|
||
| ``` | ||
| $.pub.values.title | ||
| $.pub.values.externalId | ||
| ``` | ||
|
|
||
| ### Builtin fields | ||
|
|
||
| ``` | ||
| $.pub.id | ||
| $.pub.createdAt | ||
| $.pub.updatedAt | ||
| $.pub.pubTypeId | ||
| $.pub.title | ||
| $.pub.stageId | ||
| ``` | ||
|
|
||
| ### Pub type | ||
|
|
||
| ``` | ||
| $.pub.pubType.name | ||
| $.pub.pubType.id | ||
| ``` | ||
|
|
||
| ## Comparison operators | ||
|
|
||
| ### Equality | ||
|
|
||
| ``` | ||
| $.pub.values.title = "Test" | ||
| $.pub.values.count != 0 | ||
| ``` | ||
|
|
||
| ### Numeric comparison | ||
|
|
||
| ``` | ||
| $.pub.values.count > 10 | ||
| $.pub.values.count >= 10 | ||
| $.pub.values.count < 100 | ||
| $.pub.values.count <= 100 | ||
| ``` | ||
|
|
||
| ### In array | ||
|
|
||
| ``` | ||
| $.pub.values.status in ["draft", "published"] | ||
| ``` | ||
|
|
||
| ## Logical operators | ||
|
|
||
| ### And | ||
|
|
||
| ``` | ||
| $.pub.values.status = "published" and $.pub.values.count > 0 | ||
| ``` | ||
|
|
||
| ### Or | ||
|
|
||
| ``` | ||
| $.pub.values.status = "draft" or $.pub.values.status = "pending" | ||
| ``` | ||
|
|
||
| ### Not | ||
|
|
||
| ``` | ||
| $not($.pub.values.archived = true) | ||
| ``` | ||
|
|
||
| ## String functions | ||
|
|
||
| ### Contains | ||
|
|
||
| ``` | ||
| $contains($.pub.values.title, "chapter") | ||
| ``` | ||
|
|
||
| ### Starts with | ||
|
|
||
| ``` | ||
| $startsWith($.pub.values.title, "Introduction") | ||
| ``` | ||
|
|
||
| ### Ends with | ||
|
|
||
| ``` | ||
| $endsWith($.pub.values.filename, ".pdf") | ||
| ``` | ||
|
|
||
| ## Case-insensitive matching | ||
|
|
||
| Wrap the path in `$lowercase()` or `$uppercase()`. | ||
|
|
||
| ### Case-insensitive contains | ||
|
|
||
| ``` | ||
| $contains($lowercase($.pub.values.title), "snap") | ||
| ``` | ||
|
|
||
| ### Case-insensitive equality | ||
|
|
||
| ``` | ||
| $lowercase($.pub.values.status) = "draft" | ||
| ``` | ||
|
|
||
| ## Existence check | ||
|
|
||
| ``` | ||
| $exists($.pub.values.optionalField) | ||
| ``` | ||
|
|
||
| ## Full-text search | ||
|
|
||
| Searches across all pub values using PostgreSQL full-text search. | ||
|
|
||
| ``` | ||
| $search("climate change") | ||
| ``` | ||
|
|
||
| ## Relations | ||
|
|
||
| ### Outgoing relations | ||
|
|
||
| Find pubs that have outgoing relations via a field. | ||
|
|
||
| ``` | ||
| $.pub.out.contributors | ||
| ``` | ||
|
|
||
| ### Outgoing relations with filter | ||
|
|
||
| Filter by the relation value. | ||
|
|
||
| ``` | ||
| $.pub.out.contributors[$.value = "Editor"] | ||
| ``` | ||
|
|
||
| Filter by the related pub's field. | ||
|
|
||
| ``` | ||
| $.pub.out.contributors[$.relatedPub.values.institution = "MIT"] | ||
| ``` | ||
|
|
||
| Filter by the related pub's type. | ||
|
|
||
| ``` | ||
| $.pub.out.contributors[$.relatedPub.pubType.name = "Author"] | ||
| ``` | ||
|
|
||
| Combined filters. | ||
|
|
||
| ``` | ||
| $.pub.out.contributors[$.value = "Editor" and $contains($.relatedPub.values.name, "Smith")] | ||
| ``` | ||
|
|
||
| ### Incoming relations | ||
|
|
||
| Find pubs that are referenced by other pubs via a field. | ||
|
|
||
| ``` | ||
| $.pub.in.chapters | ||
| ``` | ||
|
|
||
| Filter by the source pub. | ||
|
|
||
| ``` | ||
| $.pub.in.chapters[$.relatedPub.values.title = "The Big Book"] | ||
| ``` | ||
|
|
||
| ## Interpolation (resolver only) | ||
|
|
||
| At the moment only used when configuring automations. | ||
|
|
||
| Use `{{ }}` to interpolate values from the context when using as a resolver. | ||
|
|
||
| ``` | ||
| $.pub.values.externalId = {{ $.json.body.articleId }} | ||
| ``` | ||
|
|
||
| The expression inside `{{ }}` is evaluated against the automation context before the query runs. | ||
|
|
||
| ## Limits | ||
|
|
||
| Maximum relation depth: 3 levels. | ||
|
|
||
| ## Unsupported | ||
|
|
||
| Variable assignment, lambda functions, recursive descent, and other advanced JSONata features are not supported. |
This file contains hidden or 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,20 @@ | ||
| import type { ParsedCondition } from "./parser" | ||
|
|
||
| import { parseJsonataQuery } from "./parser" | ||
|
|
||
| export interface CompiledQuery { | ||
| condition: ParsedCondition | ||
| originalExpression: string | ||
| } | ||
|
|
||
| /** | ||
| * compiles a jsonata expression into a query that can be used for | ||
| * both sql generation and in-memory filtering | ||
| */ | ||
| export function compileJsonataQuery(expression: string): CompiledQuery { | ||
| const parsed = parseJsonataQuery(expression) | ||
| return { | ||
| condition: parsed.condition, | ||
| originalExpression: expression, | ||
| } | ||
| } |
This file contains hidden or 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,31 @@ | ||
| export class JsonataQueryError extends Error { | ||
| constructor( | ||
| message: string, | ||
| public readonly expression?: string | ||
| ) { | ||
| super(message) | ||
| this.name = "JsonataQueryError" | ||
| } | ||
| } | ||
|
|
||
| export class UnsupportedExpressionError extends JsonataQueryError { | ||
| constructor( | ||
| message: string, | ||
| public readonly nodeType?: string, | ||
| expression?: string | ||
| ) { | ||
| super(message, expression) | ||
| this.name = "UnsupportedExpressionError" | ||
| } | ||
| } | ||
|
|
||
| export class InvalidPathError extends JsonataQueryError { | ||
| constructor( | ||
| message: string, | ||
| public readonly path?: string, | ||
| expression?: string | ||
| ) { | ||
| super(message, expression) | ||
| this.name = "InvalidPathError" | ||
| } | ||
| } |
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 new imports are not in alphabetical order. The Textarea import should come after Select and before TokenProvider, and the Tooltip imports should follow the established ordering pattern in this file.