quetch 0.18.0 → 0.18.2

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.
@@ -30,19 +30,4 @@ function criteria(context, path = EMPTY_ARRAY) {
30
30
  }
31
31
  });
32
32
  }
33
- /*
34
-
35
- {
36
- filter: {
37
- field: "a"
38
- }
39
- }
40
-
41
- {
42
- operator: "equal",
43
- field: ["filter", "field"],
44
- value: "a"
45
- }
46
-
47
- */
48
33
  //# sourceMappingURL=filterFromContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"filterFromContext.js","sourceRoot":"","sources":["../../lib/tools/filterFromContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAI3C,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;AAE3B,MAAM,UAAU,iBAAiB,CAC/B,OAAmB;IAEnB,OAAO;QACL,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAgB;KACxC,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CACf,OAAe,EACf,OAA0B,WAAW;IAErC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE;QACjD,QAAQ,OAAO,KAAK,EAAE,CAAC;YACrB,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ,CAAC;YACd,KAAK,WAAW;gBACd,OAAO;oBACL;wBACE,KAAK,EAAE,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC;wBACnD,QAAQ,EAAE,OAAO;wBACjB,KAAK;qBACN;iBACF,CAAC;YACJ,KAAK,QAAQ;gBACX,OAAO,QAAQ,C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7 +2,11 @@ import type { Any } from "./Any";
2
2
  import type { FieldFiltered } from "./FieldFiltered";
3
3
  import type { Value } from "./Value";
4
4
  /**
5
- * Checks if a given array field matches a given array value according to a given operator.
5
+ * Checks if a given array field matches a given array value according to a given operator:
6
+ *
7
+ * - `equal` matches the exact content of the array.
8
+ * - `include` requires every value to be present in the array.
9
+ * - `intersect` requires at least one item of the value to be present in the array.
6
10
  */
7
11
  export type FilterArray<T extends object, P = Any> = {
8
12
  operator: "equal" | "include" | "intersect";
@@ -1,4 +1,4 @@
1
1
  import type { Increment } from "./Increment";
2
- export type Path<T, D = 0> = D extends 4 ? never : T extends Array<infer P> ? readonly [number] | readonly [number, ...Path<P, Increment<D>>] : T extends object ? {
2
+ export type Path<T, D = 0> = D extends 2 ? never : T extends Array<infer P> ? readonly [number] | readonly [number, ...Path<P, Increment<D>>] : T extends object ? {
3
3
  [K in keyof T]-?: [K] | [K, ...Path<T[K], Increment<D>>];
4
4
  }[keyof T] : never;
@@ -9,7 +9,7 @@ export function filterFromContext<T extends object>(
9
9
  ): Filter<T> {
10
10
  return {
11
11
  operator: "all",
12
- value: criteria(context) as Filter<T>[],
12
+ value: criteria(context),
13
13
  };
14
14
  }
15
15
 
@@ -30,7 +30,7 @@ function criteria<T extends object>(
30
30
  field: path.length === 0 ? field : [...path, field],
31
31
  operator: "equal",
32
32
  value,
33
- },
33
+ } as Filter<T>,
34
34
  ];
35
35
  case "object":
36
36
  return criteria(value, [...path, field]);
@@ -40,19 +40,3 @@ function criteria<T extends object>(
40
40
  }
41
41
  });
42
42
  }
43
-
44
- /*
45
-
46
- {
47
- filter: {
48
- field: "a"
49
- }
50
- }
51
-
52
- {
53
- operator: "equal",
54
- field: ["filter", "field"],
55
- value: "a"
56
- }
57
-
58
- */
@@ -3,6 +3,7 @@ import { expect, test } from "vitest";
3
3
  import { SymbolCache } from "../constants.js";
4
4
  import type { FilterChildren } from "../types.js";
5
5
 
6
+ import { filterFromContext } from "./filterFromContext.js";
6
7
  import { testFilter } from "./testFilter.js";
7
8
 
8
9
  test("tests filter lists", () => {
@@ -266,6 +267,15 @@ test("tests filter on array values", () => {
266
267
  ).toBe(false);
267
268
  });
268
269
 
270
+ test("tests filter with paths", () => {
271
+ const context = { value: { filter: { field: "label" } } };
272
+ expect(
273
+ testFilter(filterFromContext(context), {
274
+ value: { filter: { field: "label" } },
275
+ }),
276
+ ).toBe(true);
277
+ });
278
+
269
279
  test("tests filter with children predicates", () => {
270
280
  expect(testFilter({ operator: "children", value: "a" }, { id: "a/b" })).toBe(
271
281
  true,
@@ -3,7 +3,11 @@ import type { FieldFiltered } from "./FieldFiltered";
3
3
  import type { Value } from "./Value";
4
4
 
5
5
  /**
6
- * Checks if a given array field matches a given array value according to a given operator.
6
+ * Checks if a given array field matches a given array value according to a given operator:
7
+ *
8
+ * - `equal` matches the exact content of the array.
9
+ * - `include` requires every value to be present in the array.
10
+ * - `intersect` requires at least one item of the value to be present in the array.
7
11
  */
8
12
  export type FilterArray<T extends object, P = Any> = {
9
13
  operator: "equal" | "include" | "intersect";
@@ -8,6 +8,7 @@ import type { Value } from "./Value";
8
8
  export type FilterString<T extends object> = {
9
9
  operator:
10
10
  | "equal"
11
+ // FIXME: Redundant with `"not"` operator
11
12
  | "notEqual"
12
13
  | "startWith"
13
14
  | "endWith"
package/lib/types/Path.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Increment } from "./Increment";
2
2
 
3
- export type Path<T, D = 0> = D extends 4
3
+ export type Path<T, D = 0> = D extends 2
4
4
  ? never
5
5
  : T extends Array<infer P>
6
6
  ? readonly [number] | readonly [number, ...Path<P, Increment<D>>]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quetch",
3
- "version": "0.18.0",
3
+ "version": "0.18.2",
4
4
  "type": "module",
5
5
  "main": "./dist/main.js",
6
6
  "exports": {
@@ -38,7 +38,7 @@
38
38
  "format:fix": "prettier --write './**/*.{css,scss,md,mdx,json,tsx,ts,jsx,js}'",
39
39
  "lint": "npm run lint:ts",
40
40
  "lint:fix": "npm run lint:ts:fix",
41
- "lint:ts": "eslint .",
41
+ "lint:ts": "eslint . && tsc --project tsconfig.package.json --noEmit",
42
42
  "lint:ts:fix": "eslint --fix .",
43
43
  "release:init": "npm publish --access=public",
44
44
  "release:patch": "npm version patch && git push origin --follow-tags && npm publish",
@@ -79,6 +79,6 @@
79
79
  },
80
80
  "dependencies": {
81
81
  "futurise": "^1.7.1",
82
- "unchangeable": "^1.7.2"
82
+ "unchangeable": "^1.7.3"
83
83
  }
84
84
  }