Skip to content

Commit

Permalink
v0.3.1 fixes startswith/endswith operators
Browse files Browse the repository at this point in the history
  • Loading branch information
kruschid committed Dec 28, 2024
1 parent 24b0283 commit 530a5cb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "refine-pocketbase",
"description": "PocketBase auth, data & live providers for Refine",
"version": "0.3.0",
"version": "0.3.1",
"author": "Denis Kruschinski <[email protected]>",
"source": "src/index.ts",
"module": "build/index.mjs",
Expand Down
8 changes: 4 additions & 4 deletions lib/src/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ const logicalOperators: Record<
nnull: ({ field, value }: TypedLogicalFilter<boolean>) =>
value === true ? `${field} != null` : `${field} = null`,
startswith: ({ field, value }: TypedLogicalFilter<string>) =>
`${field} = '${escape(value)}%'`,
`${field} ~ '${escape(value)}%'`,
nstartswith: ({ field, value }: TypedLogicalFilter<string>) =>
`${field} != '${escape(value)}%'`,
`${field} !~ '${escape(value)}%'`,
startswiths: undefined,
nstartswiths: undefined,
endswith: ({ field, value }: TypedLogicalFilter<string>) =>
`${field} = '%${escape(value)}'`,
`${field} ~ '%${escape(value)}'`,
nendswith: ({ field, value }: TypedLogicalFilter<string>) =>
`${field} != '%${escape(value)}'`,
`${field} !~ '%${escape(value)}'`,
endswiths: undefined,
nendswiths: undefined,
};
Expand Down
48 changes: 24 additions & 24 deletions lib/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ test("logical filters", (t) => {
["null", false, "(a != null)"],
["nnull", true, "(a != null)"],
["nnull", false, "(a = null)"],
["startswith", "a", "(a = 'a%')"],
["startswith", "%b", "(a = '\\%b%')"],
["nstartswith", "c", "(a != 'c%')"],
["nstartswith", "%d", "(a != '\\%d%')"],
["endswith", "e", "(a = '%e')"],
["endswith", "f%", "(a = '%f\\%')"],
["nendswith", "g", "(a != '%g')"],
["nendswith", "h%", "(a != '%h\\%')"],
["startswith", "a", "(a ~ 'a%')"],
["startswith", "%b", "(a ~ '\\%b%')"],
["nstartswith", "c", "(a !~ 'c%')"],
["nstartswith", "%d", "(a !~ '\\%d%')"],
["endswith", "e", "(a ~ '%e')"],
["endswith", "f%", "(a ~ '%f\\%')"],
["nendswith", "g", "(a !~ '%g')"],
["nendswith", "h%", "(a !~ '%h\\%')"],
]).forEach(([operator, value, output]) =>
t.equals(
transformFilter([
Expand Down Expand Up @@ -132,14 +132,14 @@ test("nested logical filters", (t) => {
["null", false, "((a != null) && (b = '4'))"],
["nnull", true, "((a != null) && (b = '4'))"],
["nnull", false, "((a = null) && (b = '4'))"],
["startswith", "a", "((a = 'a%') && (b = '4'))"],
["startswith", "%b", "((a = '\\%b%') && (b = '4'))"],
["nstartswith", "c", "((a != 'c%') && (b = '4'))"],
["nstartswith", "%d", "((a != '\\%d%') && (b = '4'))"],
["endswith", "e", "((a = '%e') && (b = '4'))"],
["endswith", "f%", "((a = '%f\\%') && (b = '4'))"],
["nendswith", "g", "((a != '%g') && (b = '4'))"],
["nendswith", "h%", "((a != '%h\\%') && (b = '4'))"],
["startswith", "a", "((a ~ 'a%') && (b = '4'))"],
["startswith", "%b", "((a ~ '\\%b%') && (b = '4'))"],
["nstartswith", "c", "((a !~ 'c%') && (b = '4'))"],
["nstartswith", "%d", "((a !~ '\\%d%') && (b = '4'))"],
["endswith", "e", "((a ~ '%e') && (b = '4'))"],
["endswith", "f%", "((a ~ '%f\\%') && (b = '4'))"],
["nendswith", "g", "((a !~ '%g') && (b = '4'))"],
["nendswith", "h%", "((a !~ '%h\\%') && (b = '4'))"],
]).forEach(([operator, value, output]) =>
t.equals(
transformFilter([
Expand Down Expand Up @@ -199,14 +199,14 @@ test("deeply nested logical filters", (t) => {
["null", false, "(((a != null) && (b = '4')) || (c > 1))"],
["nnull", true, "(((a != null) && (b = '4')) || (c > 1))"],
["nnull", false, "(((a = null) && (b = '4')) || (c > 1))"],
["startswith", "a", "(((a = 'a%') && (b = '4')) || (c > 1))"],
["startswith", "%b", "(((a = '\\%b%') && (b = '4')) || (c > 1))"],
["nstartswith", "c", "(((a != 'c%') && (b = '4')) || (c > 1))"],
["nstartswith", "%d", "(((a != '\\%d%') && (b = '4')) || (c > 1))"],
["endswith", "e", "(((a = '%e') && (b = '4')) || (c > 1))"],
["endswith", "f%", "(((a = '%f\\%') && (b = '4')) || (c > 1))"],
["nendswith", "g", "(((a != '%g') && (b = '4')) || (c > 1))"],
["nendswith", "h%", "(((a != '%h\\%') && (b = '4')) || (c > 1))"],
["startswith", "a", "(((a ~ 'a%') && (b = '4')) || (c > 1))"],
["startswith", "%b", "(((a ~ '\\%b%') && (b = '4')) || (c > 1))"],
["nstartswith", "c", "(((a !~ 'c%') && (b = '4')) || (c > 1))"],
["nstartswith", "%d", "(((a !~ '\\%d%') && (b = '4')) || (c > 1))"],
["endswith", "e", "(((a ~ '%e') && (b = '4')) || (c > 1))"],
["endswith", "f%", "(((a ~ '%f\\%') && (b = '4')) || (c > 1))"],
["nendswith", "g", "(((a !~ '%g') && (b = '4')) || (c > 1))"],
["nendswith", "h%", "(((a !~ '%h\\%') && (b = '4')) || (c > 1))"],
]).forEach(([operator, value, output]) =>
t.equals(
transformFilter([
Expand Down

0 comments on commit 530a5cb

Please sign in to comment.