From 174a3527f4985d51841273a7b4dd83681d640f66 Mon Sep 17 00:00:00 2001 From: Jake Boone Date: Thu, 2 Jun 2022 10:55:30 -0700 Subject: [PATCH 1/2] Add JsonLogic export format; removed mongodb IC warning --- docs/api/export.mdx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/api/export.mdx b/docs/api/export.mdx index 16219b2f83..8cc2fa0e16 100644 --- a/docs/api/export.mdx +++ b/docs/api/export.mdx @@ -23,6 +23,7 @@ function formatQuery( - Parameterized SQL (with anonymous or named parameters) - MongoDB - Common Expression Language (CEL) +- JsonLogic For the next few sections, assume the `query` variable has been defined as: @@ -165,7 +166,7 @@ Output: :::info -For now, the MongoDB export format has two major shortcomings. For one, it does not support the inversion operator (setting `not: true` for a rule group), however rules _can_ be created using the `"!="` operator. Also, if the query uses [independent combinators](./querybuilder#independentcombinators), it will not be processed and `formatQuery(query, 'mongodb')` will always return the [fallback expression](#fallback-expression). +The MongoDB export format does not support the inversion operator (setting `not: true` for a rule group), however rules _can_ be created using the `"!="` operator. ::: @@ -183,6 +184,20 @@ Output: `firstName = "Steve" && lastName = "Vai"`; ``` +### JsonLogic + +The "jsonlogic" format produces an object that can be processed by the `jsonLogic.apply` function (see https://jsonlogic.com/). + +```ts +formatQuery(query, 'jsonlogic'); +``` + +Output: + +```json +{ "and": [{ "==": [{ "var": "firstName" }, "Steve"] }, { "==": [{ "var": "lastName" }, "Vai"] }] } +``` + ## Configuration An object can be passed as the second argument instead of a string to have more fine-grained control over the output. From 1d9b26c9141fec69711f8ee12f4ecadb56eabddf Mon Sep 17 00:00:00 2001 From: Jake Boone Date: Thu, 2 Jun 2022 16:12:48 -0700 Subject: [PATCH 2/2] Add SpEL export format --- docs/api/export.mdx | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/docs/api/export.mdx b/docs/api/export.mdx index 8cc2fa0e16..5becf1f820 100644 --- a/docs/api/export.mdx +++ b/docs/api/export.mdx @@ -23,6 +23,7 @@ function formatQuery( - Parameterized SQL (with anonymous or named parameters) - MongoDB - Common Expression Language (CEL) +- Spring Expression Language (SpEL) - JsonLogic For the next few sections, assume the `query` variable has been defined as: @@ -184,6 +185,20 @@ Output: `firstName = "Steve" && lastName = "Vai"`; ``` +### Spring Expression Language + +For Spring Expression Language (SpEL) output, use the "spel" format. + +```ts +formatQuery(query, 'spel'); +``` + +Output: + +```ts +`firstName == 'Steve' and lastName == 'Vai'`; +``` + ### JsonLogic The "jsonlogic" format produces an object that can be processed by the `jsonLogic.apply` function (see https://jsonlogic.com/). @@ -323,9 +338,17 @@ const p = formatQuery(query, { ### Fallback expression -The `fallbackExpression` is a string that will be part of the output when `formatQuery` can't quite figure out what to do for a particular rule or group. The intent is to maintain valid syntax while (hopefully) not detrimentally affecting the query criteria. - -By default, `fallbackExpression` is `"(1 = 1)"` for the "sql", "parameterized", and "parameterized_named" formats, `"1 == 1"` for the "cel" format, and `"{$and:[{$expr:true}]}"` for the "mongodb" format. +The `fallbackExpression` is a string that will be part of the output when `formatQuery` can't quite figure out what to do for a particular rule or group. The intent is to maintain valid syntax while (hopefully) not detrimentally affecting the query criteria. If not provided, the default fallback expression for the given format will be used (see table below). + +| Format | Default `fallbackExpression` | +| --------------------- | ---------------------------- | +| "sql" | `"(1 = 1)"` | +| "parameterized" | `"(1 = 1)"` | +| "parameterized_named" | `"(1 = 1)"` | +| "mongodb" | `"{$and:[{$expr:true}]}"` | +| "cel" | `"1 == 1"` | +| "spel" | `"1 == 1"` | +| "jsonlogic" | `false` | ### Value sources