quetch 0.26.0 → 0.27.1

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.
Files changed (130) hide show
  1. package/dist/constants/FILTER_ANY.d.ts +3 -0
  2. package/dist/constants/FILTER_ANY.js +2 -0
  3. package/dist/constants/FILTER_ANY.js.map +1 -0
  4. package/dist/constants/FILTER_NONE.d.ts +3 -0
  5. package/dist/constants/FILTER_NONE.js +2 -0
  6. package/dist/constants/FILTER_NONE.js.map +1 -0
  7. package/dist/constants.d.ts +2 -0
  8. package/dist/constants.js +2 -0
  9. package/dist/constants.js.map +1 -1
  10. package/dist/tools/filterChildren.d.ts +2 -2
  11. package/dist/tools/filterFromValue.d.ts +2 -2
  12. package/dist/tools/filterFromValue.js +14 -4
  13. package/dist/tools/filterFromValue.js.map +1 -1
  14. package/dist/tools/testFilter.js +5 -5
  15. package/dist/tools/testFilter.js.map +1 -1
  16. package/dist/types/FilterChildren.d.ts +2 -2
  17. package/dist/types/IntrinsicFilter.d.ts +7 -0
  18. package/dist/types/IntrinsicFilter.js +1 -0
  19. package/dist/types/IntrinsicFilter.js.map +1 -0
  20. package/dist/types/QuerySettings.d.ts +3 -5
  21. package/dist/types.d.ts +1 -0
  22. package/doc/README.md +3 -0
  23. package/doc/classes/RequestError.md +5 -5
  24. package/doc/functions/aggregate.md +1 -1
  25. package/doc/functions/branch.md +1 -1
  26. package/doc/functions/cache.md +1 -1
  27. package/doc/functions/combine.md +1 -1
  28. package/doc/functions/cork.md +1 -1
  29. package/doc/functions/defineCheckQuery.md +1 -1
  30. package/doc/functions/defineCustomFetch.md +1 -1
  31. package/doc/functions/defineGenericFetch.md +1 -1
  32. package/doc/functions/escapeRegex.md +1 -1
  33. package/doc/functions/fetchExternal.md +1 -1
  34. package/doc/functions/fetchLocal.md +1 -1
  35. package/doc/functions/fieldListFromFilter.md +1 -1
  36. package/doc/functions/filterChildren.md +3 -3
  37. package/doc/functions/filterFromValue.md +3 -3
  38. package/doc/functions/get.md +1 -1
  39. package/doc/functions/groupFilters.md +2 -2
  40. package/doc/functions/identity.md +1 -1
  41. package/doc/functions/isFilterGroup.md +1 -1
  42. package/doc/functions/log.md +1 -1
  43. package/doc/functions/normalizeOrder.md +1 -1
  44. package/doc/functions/queryItemList.md +1 -1
  45. package/doc/functions/retry.md +1 -1
  46. package/doc/functions/reverseOrder.md +1 -1
  47. package/doc/functions/sameField.md +1 -1
  48. package/doc/functions/sortItemList.md +1 -1
  49. package/doc/functions/splitPath.md +2 -2
  50. package/doc/functions/testFilter.md +1 -1
  51. package/doc/interfaces/CustomFetch.md +1 -1
  52. package/doc/type-aliases/AggregateFunction.md +1 -1
  53. package/doc/type-aliases/AggregateFunctionOperator.md +1 -1
  54. package/doc/type-aliases/CombineUnion.md +1 -1
  55. package/doc/type-aliases/Context.md +1 -1
  56. package/doc/type-aliases/CustomFieldAggregateMap.md +1 -1
  57. package/doc/type-aliases/CustomFieldMap.md +1 -1
  58. package/doc/type-aliases/Field.md +1 -1
  59. package/doc/type-aliases/FieldFiltered.md +1 -1
  60. package/doc/type-aliases/FieldFunction.md +1 -1
  61. package/doc/type-aliases/FieldFunctionCustom.md +1 -1
  62. package/doc/type-aliases/FieldFunctionFormatDate.md +1 -1
  63. package/doc/type-aliases/FieldFunctionReturn.md +1 -1
  64. package/doc/type-aliases/FieldKey.md +1 -1
  65. package/doc/type-aliases/FieldMap.md +1 -1
  66. package/doc/type-aliases/Filter.md +1 -1
  67. package/doc/type-aliases/FilterArray.md +1 -1
  68. package/doc/type-aliases/FilterBoolean.md +1 -1
  69. package/doc/type-aliases/FilterChildren.md +2 -2
  70. package/doc/type-aliases/FilterCustom.md +1 -1
  71. package/doc/type-aliases/FilterField.md +1 -1
  72. package/doc/type-aliases/FilterGroup.md +1 -1
  73. package/doc/type-aliases/FilterNumber.md +1 -1
  74. package/doc/type-aliases/FilterOperator.md +1 -1
  75. package/doc/type-aliases/FilterString.md +1 -1
  76. package/doc/type-aliases/FilterStringIntersect.md +1 -1
  77. package/doc/type-aliases/FilterStringMatch.md +1 -1
  78. package/doc/type-aliases/Get.md +1 -1
  79. package/doc/type-aliases/Group.md +1 -1
  80. package/doc/type-aliases/Handler.md +1 -1
  81. package/doc/type-aliases/Immutable.md +1 -1
  82. package/doc/type-aliases/Increment.md +1 -1
  83. package/doc/type-aliases/InjectCustomFields.md +1 -1
  84. package/doc/type-aliases/IntersectUnion.md +1 -1
  85. package/doc/type-aliases/IntrinsicFilter.md +19 -0
  86. package/doc/type-aliases/Item.md +1 -1
  87. package/doc/type-aliases/Join.md +1 -1
  88. package/doc/type-aliases/Key.md +1 -1
  89. package/doc/type-aliases/KeyFiltered.md +1 -1
  90. package/doc/type-aliases/KeyFromUnion.md +1 -1
  91. package/doc/type-aliases/Locale.md +1 -1
  92. package/doc/type-aliases/NextHandler.md +1 -1
  93. package/doc/type-aliases/Order.md +1 -1
  94. package/doc/type-aliases/OrderNormalized.md +1 -1
  95. package/doc/type-aliases/Parameters.md +1 -1
  96. package/doc/type-aliases/Path.md +1 -1
  97. package/doc/type-aliases/PathFiltered.md +1 -1
  98. package/doc/type-aliases/Primitive.md +1 -1
  99. package/doc/type-aliases/PrimitiveObject.md +1 -1
  100. package/doc/type-aliases/Query.md +1 -1
  101. package/doc/type-aliases/QueryAggregate.md +1 -1
  102. package/doc/type-aliases/QueryCreate.md +1 -1
  103. package/doc/type-aliases/QueryCreateMultiple.md +1 -1
  104. package/doc/type-aliases/QueryDelete.md +1 -1
  105. package/doc/type-aliases/QueryDeleteMultiple.md +1 -1
  106. package/doc/type-aliases/QueryMethod.md +1 -1
  107. package/doc/type-aliases/QueryRead.md +1 -1
  108. package/doc/type-aliases/QueryReadMultiple.md +1 -1
  109. package/doc/type-aliases/QuerySettings.md +4 -4
  110. package/doc/type-aliases/QueryUpdate.md +1 -1
  111. package/doc/type-aliases/QueryUpdateMultiple.md +1 -1
  112. package/doc/type-aliases/Result.md +1 -1
  113. package/doc/type-aliases/Store.md +1 -1
  114. package/doc/type-aliases/Value.md +1 -1
  115. package/doc/type-aliases/ValueMap.md +1 -1
  116. package/doc/variables/CACHE.md +1 -1
  117. package/doc/variables/FILTER_ANY.md +19 -0
  118. package/doc/variables/FILTER_NONE.md +19 -0
  119. package/doc/variables/SELF.md +1 -1
  120. package/lib/constants/FILTER_ANY.ts +1 -0
  121. package/lib/constants/FILTER_NONE.ts +1 -0
  122. package/lib/constants.ts +2 -0
  123. package/lib/tools/filterChildren.ts +2 -2
  124. package/lib/tools/filterFromValue.ts +19 -9
  125. package/lib/tools/testFilter.ts +13 -6
  126. package/lib/types/FilterChildren.ts +2 -2
  127. package/lib/types/IntrinsicFilter.ts +9 -0
  128. package/lib/types/QuerySettings.ts +3 -5
  129. package/lib/types.ts +1 -0
  130. package/package.json +1 -1
@@ -1,21 +1,31 @@
1
1
  import { EMPTY_ARRAY } from "unchangeable";
2
2
 
3
3
  import { SELF } from "../constants/SELF.js";
4
- import type { Filter } from "../types.js";
4
+ import type { IntrinsicFilter } from "../types.js";
5
5
 
6
6
  const { entries } = Object;
7
7
 
8
- export function filterFromValue<T>(value: T): Filter<T> {
9
- return {
10
- operator: "all",
11
- value: criteria(value),
12
- };
8
+ export function filterFromValue<T>(value: T): IntrinsicFilter<T> {
9
+ const criteriaValue = criteria(value);
10
+ switch (criteriaValue.length) {
11
+ case 0:
12
+ return {
13
+ operator: "any",
14
+ };
15
+ case 1:
16
+ return criteriaValue[0]!;
17
+ default:
18
+ return {
19
+ operator: "all",
20
+ value: criteria(value),
21
+ };
22
+ }
13
23
  }
14
24
 
15
25
  function criteria<T>(
16
26
  value: T,
17
27
  path: readonly string[] = EMPTY_ARRAY,
18
- ): readonly Filter<T>[] {
28
+ ): readonly IntrinsicFilter<T>[] {
19
29
  return entriesAndSelf(value).flatMap(([field, value]) => {
20
30
  switch (typeof value) {
21
31
  case "symbol":
@@ -36,7 +46,7 @@ function criteria<T>(
36
46
  field: path.length === 0 ? field : [...path, field],
37
47
  operator: "equal",
38
48
  value,
39
- } as Filter<T>,
49
+ } as IntrinsicFilter<T>,
40
50
  ];
41
51
  case "object": {
42
52
  if (value == null) {
@@ -45,7 +55,7 @@ function criteria<T>(
45
55
  field: path.length === 0 ? field : [...path, field],
46
56
  operator: "equal",
47
57
  value,
48
- } as Filter<T>,
58
+ } as IntrinsicFilter<T>,
49
59
  ];
50
60
  }
51
61
  return criteria<T>(value, [...path, field as string]);
@@ -38,7 +38,9 @@ export function testFilter<T>(
38
38
  }
39
39
  switch (filter.operator) {
40
40
  case "all":
41
- return filter.value.every((filter) => testFilter(filter, value));
41
+ return filter.value.every((filter) =>
42
+ testFilter(filter, value, settings),
43
+ );
42
44
  case "any": {
43
45
  const length = filter.value?.length ?? 0;
44
46
  const minimum = filter.minimum ?? (length > 0 ? 1 : 0);
@@ -47,10 +49,13 @@ export function testFilter<T>(
47
49
  return true;
48
50
  }
49
51
  if (minimum === 1 && maximum >= length) {
50
- return filter.value.some((filter) => testFilter(filter, value));
52
+ return filter.value.some((filter) =>
53
+ testFilter(filter, value, settings),
54
+ );
51
55
  }
52
56
  const matched = filter.value.reduce(
53
- (count, filter) => count + (testFilter(filter, value) ? 1 : 0),
57
+ (count, filter) =>
58
+ count + (testFilter(filter, value, settings) ? 1 : 0),
54
59
  0,
55
60
  );
56
61
  return matched >= minimum && matched <= maximum;
@@ -59,7 +64,9 @@ export function testFilter<T>(
59
64
  if (filter.value === undefined || filter.value.length === 0) {
60
65
  return false;
61
66
  }
62
- return filter.value.every((filter) => !testFilter(filter, value));
67
+ return filter.value.every(
68
+ (filter) => !testFilter(filter, value, settings),
69
+ );
63
70
  }
64
71
  case "exist":
65
72
  return get(value, filter.field as any) !== undefined;
@@ -127,7 +134,7 @@ export function testFilter<T>(
127
134
  const {
128
135
  pathField = "id" as FieldFiltered<T, string>,
129
136
  pathFieldSeparator,
130
- } = settings || (EMPTY_OBJECT as QuerySettings<T>);
137
+ } = settings || EMPTY_OBJECT;
131
138
  filter[CACHE] = filterChildren(
132
139
  filter.value as string,
133
140
  pathField,
@@ -137,7 +144,7 @@ export function testFilter<T>(
137
144
  }
138
145
  }
139
146
  }
140
- return negate(testFilter(filter[CACHE], value), not);
147
+ return negate(testFilter(filter[CACHE], value, settings), not);
141
148
  }
142
149
  case "custom": {
143
150
  return filter.value(value);
@@ -1,7 +1,7 @@
1
1
  import type { CACHE } from "../constants/CACHE.js";
2
2
 
3
3
  import type { Context } from "./Context";
4
- import type { Filter } from "./Filter";
4
+ import type { IntrinsicFilter } from "./IntrinsicFilter.js";
5
5
 
6
6
  /**
7
7
  * Matches the direct children of a specified `value` item.
@@ -11,5 +11,5 @@ export type FilterChildren<T> = {
11
11
  operator: "children" | "notChildren";
12
12
  value?: Context<T> | string;
13
13
  deep?: boolean;
14
- [CACHE]?: Filter<T>;
14
+ [CACHE]?: IntrinsicFilter<T>;
15
15
  };
@@ -0,0 +1,9 @@
1
+ import type { Filter } from "./Filter";
2
+
3
+ /**
4
+ * Filter that does not rely on query settings, and thus can be evaluated directly on the items.
5
+ */
6
+ export type IntrinsicFilter<T> = Exclude<
7
+ Filter<T>,
8
+ { operator: "children" | "notChildren" | "is" | "notIs" }
9
+ >;
@@ -1,6 +1,6 @@
1
1
  import type { FieldFiltered } from "./FieldFiltered";
2
- import type { Filter } from "./Filter";
3
2
  import type { FilterChildren } from "./FilterChildren";
3
+ import type { IntrinsicFilter } from "./IntrinsicFilter";
4
4
 
5
5
  /**
6
6
  * Settings to use when doing a query.
@@ -23,14 +23,12 @@ export type QuerySettings<T> = {
23
23
  */
24
24
  pathFieldSeparator?: string;
25
25
  /**
26
- * Returns a filter that captures the items expressed by the provided `FilterChildren`. The return filter cannot use filters of type `FilterChildren`.
26
+ * Returns a filter that captures the items expressed by the provided `FilterChildren`. The return filter cannot use filters of type `FilterChildren` or `FilterContext`.
27
27
  *
28
28
  * @param filter The provided `FilterChildren` to express.
29
29
  * @returns A filter that captures the items expressed by the provided `FilterChildren`.
30
30
  */
31
- transformFilterChildren?: (
32
- filter: FilterChildren<T>,
33
- ) => Exclude<Filter<T>, { operator: "children" | "notChildren" }>;
31
+ transformFilterChildren?: (filter: FilterChildren<T>) => IntrinsicFilter<T>;
34
32
  /**
35
33
  * Abort signal to abort the query.
36
34
  */
package/lib/types.ts CHANGED
@@ -33,6 +33,7 @@ export type { Immutable } from "./types/Immutable";
33
33
  export type { Increment } from "./types/Increment";
34
34
  export type { InjectCustomFields } from "./types/InjectCustomFields";
35
35
  export type { IntersectUnion } from "./types/IntersectUnion";
36
+ export type { IntrinsicFilter } from "./types/IntrinsicFilter";
36
37
  export type { Item } from "./types/Item";
37
38
  export type { Join } from "./types/Join";
38
39
  export type { Key } from "./types/Key";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quetch",
3
- "version": "0.26.0",
3
+ "version": "0.27.1",
4
4
  "type": "module",
5
5
  "main": "./dist/main.js",
6
6
  "exports": {