@uniqu/url 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/builder.cjs CHANGED
@@ -14,11 +14,11 @@ let _uniqu_core = require("@uniqu/core");
14
14
  if (filterStr && controlStr) return filterStr + "&" + controlStr;
15
15
  return filterStr || controlStr;
16
16
  }
17
- function serializeFilter(expr) {
17
+ function serializeFilter(expr, parentOp) {
18
18
  if ("$and" in expr && expr.$and !== void 0) {
19
19
  let result = "";
20
20
  for (const child of expr.$and) {
21
- const s = serializeFilter(child);
21
+ const s = serializeFilter(child, "$and");
22
22
  if (s) result = result ? result + "&" + s : s;
23
23
  }
24
24
  return result;
@@ -26,10 +26,10 @@ function serializeFilter(expr) {
26
26
  if ("$or" in expr && expr.$or !== void 0) {
27
27
  let result = "";
28
28
  for (const child of expr.$or) {
29
- const s = serializeFilter(child);
29
+ const s = serializeFilter(child, "$or");
30
30
  if (s) result = result ? result + "^" + s : s;
31
31
  }
32
- return result;
32
+ return parentOp === "$and" && result ? `(${result})` : result;
33
33
  }
34
34
  if ("$not" in expr && expr.$not !== void 0) {
35
35
  const inner = serializeFilter(expr.$not);
@@ -46,7 +46,7 @@ function serializeFilter(expr) {
46
46
  const part = serializeComparison(field, op, opValue);
47
47
  result = result ? result + "&" + part : part;
48
48
  }
49
- return result;
49
+ return parentOp === "$or" && result.includes("&") ? `(${result})` : result;
50
50
  }
51
51
  function serializeComparison(field, op, value) {
52
52
  switch (op) {
package/dist/builder.mjs CHANGED
@@ -13,11 +13,11 @@ import { isPrimitive } from "@uniqu/core";
13
13
  if (filterStr && controlStr) return filterStr + "&" + controlStr;
14
14
  return filterStr || controlStr;
15
15
  }
16
- function serializeFilter(expr) {
16
+ function serializeFilter(expr, parentOp) {
17
17
  if ("$and" in expr && expr.$and !== void 0) {
18
18
  let result = "";
19
19
  for (const child of expr.$and) {
20
- const s = serializeFilter(child);
20
+ const s = serializeFilter(child, "$and");
21
21
  if (s) result = result ? result + "&" + s : s;
22
22
  }
23
23
  return result;
@@ -25,10 +25,10 @@ function serializeFilter(expr) {
25
25
  if ("$or" in expr && expr.$or !== void 0) {
26
26
  let result = "";
27
27
  for (const child of expr.$or) {
28
- const s = serializeFilter(child);
28
+ const s = serializeFilter(child, "$or");
29
29
  if (s) result = result ? result + "^" + s : s;
30
30
  }
31
- return result;
31
+ return parentOp === "$and" && result ? `(${result})` : result;
32
32
  }
33
33
  if ("$not" in expr && expr.$not !== void 0) {
34
34
  const inner = serializeFilter(expr.$not);
@@ -45,7 +45,7 @@ function serializeFilter(expr) {
45
45
  const part = serializeComparison(field, op, opValue);
46
46
  result = result ? result + "&" + part : part;
47
47
  }
48
- return result;
48
+ return parentOp === "$or" && result.includes("&") ? `(${result})` : result;
49
49
  }
50
50
  function serializeComparison(field, op, value) {
51
51
  switch (op) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniqu/url",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "URL query string parser producing the Uniqu canonical query format",
5
5
  "license": "MIT",
6
6
  "author": "Artem Maltsev",
@@ -45,7 +45,7 @@
45
45
  "dist"
46
46
  ],
47
47
  "dependencies": {
48
- "@uniqu/core": "^0.1.4"
48
+ "@uniqu/core": "^0.1.5"
49
49
  },
50
50
  "scripts": {
51
51
  "pub": "pnpm publish --access public",