quetch 0.30.0 → 0.31.0

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 (164) hide show
  1. package/dist/tools/comparatorFieldValues.d.ts +8 -0
  2. package/dist/tools/comparatorFieldValues.js +26 -0
  3. package/dist/tools/comparatorFieldValues.js.map +1 -0
  4. package/dist/tools/get.d.ts +4 -4
  5. package/dist/tools/get.js +6 -2
  6. package/dist/tools/get.js.map +1 -1
  7. package/dist/tools/querySettings.d.ts +8 -0
  8. package/dist/tools/querySettings.js +16 -0
  9. package/dist/tools/querySettings.js.map +1 -0
  10. package/dist/tools/sortItemList.d.ts +4 -4
  11. package/dist/tools/sortItemList.js +17 -24
  12. package/dist/tools/sortItemList.js.map +1 -1
  13. package/dist/tools/transformerFilterChildren.d.ts +2 -22
  14. package/dist/tools/transformerFilterChildren.js +1 -4
  15. package/dist/tools/transformerFilterChildren.js.map +1 -1
  16. package/dist/tools.d.ts +2 -0
  17. package/dist/tools.js +2 -0
  18. package/dist/tools.js.map +1 -1
  19. package/dist/types/CombineUnion.d.ts +1 -1
  20. package/dist/types/Decrement.d.ts +4 -0
  21. package/dist/types/Decrement.js +1 -0
  22. package/dist/types/Decrement.js.map +1 -0
  23. package/dist/types/DepthLimit.d.ts +1 -0
  24. package/dist/types/DepthLimit.js +1 -0
  25. package/dist/types/DepthLimit.js.map +1 -0
  26. package/dist/types/FieldKey.d.ts +2 -1
  27. package/dist/types/Get.d.ts +3 -1
  28. package/dist/types/KeyFiltered.d.ts +1 -1
  29. package/dist/types/NormalizedPathFieldSettings.d.ts +24 -0
  30. package/dist/types/NormalizedPathFieldSettings.js +1 -0
  31. package/dist/types/NormalizedPathFieldSettings.js.map +1 -0
  32. package/dist/types/Path.d.ts +4 -3
  33. package/dist/types/PathFiltered.d.ts +4 -3
  34. package/dist/types/QuerySettings.d.ts +12 -17
  35. package/dist/types.d.ts +3 -1
  36. package/doc/README.md +5 -1
  37. package/doc/classes/RequestError.md +5 -5
  38. package/doc/functions/aggregate.md +1 -1
  39. package/doc/functions/branch.md +1 -1
  40. package/doc/functions/cache.md +1 -1
  41. package/doc/functions/combine.md +1 -1
  42. package/doc/functions/comparatorFieldValues.md +33 -0
  43. package/doc/functions/cork.md +1 -1
  44. package/doc/functions/defineCheckQuery.md +1 -1
  45. package/doc/functions/defineCustomFetch.md +1 -1
  46. package/doc/functions/defineGenericFetch.md +1 -1
  47. package/doc/functions/escapeRegex.md +1 -1
  48. package/doc/functions/fetchExternal.md +1 -1
  49. package/doc/functions/fetchLocal.md +1 -1
  50. package/doc/functions/fieldListFromFilter.md +1 -1
  51. package/doc/functions/filterChildren.md +1 -1
  52. package/doc/functions/filterFromValue.md +1 -1
  53. package/doc/functions/get.md +2 -2
  54. package/doc/functions/groupFilters.md +1 -1
  55. package/doc/functions/identity.md +1 -1
  56. package/doc/functions/intrinsicFilter.md +1 -1
  57. package/doc/functions/isFilterGroup.md +1 -1
  58. package/doc/functions/log.md +1 -1
  59. package/doc/functions/normalizeOrder.md +1 -1
  60. package/doc/functions/queryItemList.md +1 -1
  61. package/doc/functions/querySettings.md +33 -0
  62. package/doc/functions/retry.md +1 -1
  63. package/doc/functions/reverseOrder.md +1 -1
  64. package/doc/functions/sameField.md +1 -1
  65. package/doc/functions/sortItemList.md +2 -2
  66. package/doc/functions/splitPath.md +2 -2
  67. package/doc/functions/testFilter.md +1 -1
  68. package/doc/functions/transformerFilterChildren.md +2 -2
  69. package/doc/interfaces/CustomFetch.md +1 -1
  70. package/doc/type-aliases/AggregateFunction.md +1 -1
  71. package/doc/type-aliases/AggregateFunctionOperator.md +1 -1
  72. package/doc/type-aliases/CombineUnion.md +2 -2
  73. package/doc/type-aliases/Context.md +1 -1
  74. package/doc/type-aliases/CustomFieldAggregateMap.md +1 -1
  75. package/doc/type-aliases/CustomFieldMap.md +1 -1
  76. package/doc/type-aliases/Decrement.md +17 -0
  77. package/doc/type-aliases/DepthLimit.md +13 -0
  78. package/doc/type-aliases/Field.md +1 -1
  79. package/doc/type-aliases/FieldFiltered.md +1 -1
  80. package/doc/type-aliases/FieldFunction.md +1 -1
  81. package/doc/type-aliases/FieldFunctionCustom.md +1 -1
  82. package/doc/type-aliases/FieldFunctionFormatDate.md +1 -1
  83. package/doc/type-aliases/FieldFunctionReturn.md +1 -1
  84. package/doc/type-aliases/FieldKey.md +2 -2
  85. package/doc/type-aliases/FieldMap.md +1 -1
  86. package/doc/type-aliases/Filter.md +1 -1
  87. package/doc/type-aliases/FilterArray.md +1 -1
  88. package/doc/type-aliases/FilterBoolean.md +1 -1
  89. package/doc/type-aliases/FilterChildren.md +1 -1
  90. package/doc/type-aliases/FilterCustom.md +1 -1
  91. package/doc/type-aliases/FilterField.md +1 -1
  92. package/doc/type-aliases/FilterGroup.md +1 -1
  93. package/doc/type-aliases/FilterNumber.md +1 -1
  94. package/doc/type-aliases/FilterOperator.md +1 -1
  95. package/doc/type-aliases/FilterString.md +1 -1
  96. package/doc/type-aliases/FilterStringIntersect.md +1 -1
  97. package/doc/type-aliases/FilterStringMatch.md +1 -1
  98. package/doc/type-aliases/Get.md +5 -3
  99. package/doc/type-aliases/Group.md +1 -1
  100. package/doc/type-aliases/Handler.md +1 -1
  101. package/doc/type-aliases/Immutable.md +1 -1
  102. package/doc/type-aliases/InjectCustomFields.md +1 -1
  103. package/doc/type-aliases/IntersectUnion.md +1 -1
  104. package/doc/type-aliases/IntrinsicFilter.md +1 -1
  105. package/doc/type-aliases/Item.md +1 -1
  106. package/doc/type-aliases/Join.md +1 -1
  107. package/doc/type-aliases/Key.md +1 -1
  108. package/doc/type-aliases/KeyFiltered.md +2 -2
  109. package/doc/type-aliases/KeyFromUnion.md +1 -1
  110. package/doc/type-aliases/Locale.md +1 -1
  111. package/doc/type-aliases/NextHandler.md +1 -1
  112. package/doc/type-aliases/NormalizedPathFieldSettings.md +57 -0
  113. package/doc/type-aliases/Order.md +1 -1
  114. package/doc/type-aliases/OrderNormalized.md +1 -1
  115. package/doc/type-aliases/Parameters.md +1 -1
  116. package/doc/type-aliases/Path.md +3 -3
  117. package/doc/type-aliases/PathFiltered.md +3 -3
  118. package/doc/type-aliases/Primitive.md +1 -1
  119. package/doc/type-aliases/PrimitiveObject.md +1 -1
  120. package/doc/type-aliases/Query.md +1 -1
  121. package/doc/type-aliases/QueryAggregate.md +1 -1
  122. package/doc/type-aliases/QueryCreate.md +1 -1
  123. package/doc/type-aliases/QueryCreateMultiple.md +1 -1
  124. package/doc/type-aliases/QueryDelete.md +1 -1
  125. package/doc/type-aliases/QueryDeleteMultiple.md +1 -1
  126. package/doc/type-aliases/QueryMethod.md +1 -1
  127. package/doc/type-aliases/QueryRead.md +1 -1
  128. package/doc/type-aliases/QueryReadMultiple.md +1 -1
  129. package/doc/type-aliases/QuerySettings.md +36 -30
  130. package/doc/type-aliases/QueryUpdate.md +1 -1
  131. package/doc/type-aliases/QueryUpdateMultiple.md +1 -1
  132. package/doc/type-aliases/Result.md +1 -1
  133. package/doc/type-aliases/Store.md +1 -1
  134. package/doc/type-aliases/Value.md +1 -1
  135. package/doc/type-aliases/ValueMap.md +1 -1
  136. package/doc/variables/CACHE.md +1 -1
  137. package/doc/variables/FILTER_ANY.md +1 -1
  138. package/doc/variables/FILTER_NONE.md +1 -1
  139. package/doc/variables/SELF.md +1 -1
  140. package/lib/tools/comparatorFieldValues.ts +46 -0
  141. package/lib/tools/get.ts +9 -4
  142. package/lib/tools/querySettings.ts +20 -0
  143. package/lib/tools/sortItemList.test.ts +31 -8
  144. package/lib/tools/sortItemList.ts +21 -41
  145. package/lib/tools/testFilter.test.ts +35 -12
  146. package/lib/tools/transformerFilterChildren.ts +3 -26
  147. package/lib/tools.ts +2 -0
  148. package/lib/types/CombineUnion.ts +12 -10
  149. package/lib/types/Decrement.ts +5 -0
  150. package/lib/types/DepthLimit.ts +1 -0
  151. package/lib/types/FieldKey.ts +6 -1
  152. package/lib/types/Get.ts +17 -9
  153. package/lib/types/KeyFiltered.ts +14 -10
  154. package/lib/types/NormalizedPathFieldSettings.ts +25 -0
  155. package/lib/types/Path.ts +18 -15
  156. package/lib/types/PathFiltered.ts +20 -17
  157. package/lib/types/QuerySettings.ts +16 -17
  158. package/lib/types.ts +3 -1
  159. package/package.json +2 -2
  160. package/dist/types/Increment.d.ts +0 -4
  161. package/dist/types/Increment.js +0 -1
  162. package/dist/types/Increment.js.map +0 -1
  163. package/doc/type-aliases/Increment.md +0 -17
  164. package/lib/types/Increment.ts +0 -5
@@ -0,0 +1,8 @@
1
+ import type { NormalizedPathFieldSettings, QuerySettings } from "../types";
2
+ /**
3
+ * Returns a function that transforms a `FilterChildren` into a `FilterStringMatch`.
4
+ *
5
+ * @param options - Options for the transformer.
6
+ * @returns A function that takes a `FilterChildren` and returns a `FilterStringMatch` that matches the paths of the children of the item specified in the `FilterChildren`.
7
+ */
8
+ export declare function comparatorFieldValues<T>({ pathField, pathFieldSeparator, pathFieldSeparatorEscape, }?: NormalizedPathFieldSettings<T>): QuerySettings<T>["compareFieldValues"];
@@ -0,0 +1,26 @@
1
+ import { EMPTY_OBJECT } from "unchangeable";
2
+ import { escapeRegex } from "./escapeRegex.js";
3
+ import { sameField } from "./sameField.js";
4
+ /**
5
+ * Returns a function that transforms a `FilterChildren` into a `FilterStringMatch`.
6
+ *
7
+ * @param options - Options for the transformer.
8
+ * @returns A function that takes a `FilterChildren` and returns a `FilterStringMatch` that matches the paths of the children of the item specified in the `FilterChildren`.
9
+ */
10
+ export function comparatorFieldValues({ pathField = "path", pathFieldSeparator = "/", pathFieldSeparatorEscape = "\\", } = EMPTY_OBJECT) {
11
+ const fieldSeparatorRegexp = new RegExp(!pathFieldSeparatorEscape
12
+ ? escapeRegex(pathFieldSeparator)
13
+ : `(?<!${escapeRegex(pathFieldSeparatorEscape)})${escapeRegex(pathFieldSeparator)}`, "g");
14
+ return (field, a, b) => {
15
+ if (!sameField(field, pathField)) {
16
+ return undefined;
17
+ }
18
+ const normalizedA = a.replaceAll?.(fieldSeparatorRegexp, "\x00");
19
+ const normalizedB = b.replaceAll?.(fieldSeparatorRegexp, "\x00");
20
+ if (normalizedA > normalizedB) {
21
+ return 1;
22
+ }
23
+ return -1;
24
+ };
25
+ }
26
+ //# sourceMappingURL=comparatorFieldValues.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comparatorFieldValues.js","sourceRoot":"","sources":["../../lib/tools/comparatorFieldValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQ5C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAI,EACvC,SAAS,GAAG,MAAkC,EAC9C,kBAAkB,GAAG,GAAG,EACxB,wBAAwB,GAAG,IAAI,MACG,YAAY;IAC9C,MAAM,oBAAoB,GAAG,IAAI,MAAM,CACrC,CAAC,wBAAwB;QACvB,CAAC,CAAC,WAAW,CAAC,kBAAkB,CAAC;QACjC,CAAC,CAAC,OAAO,WAAW,CAAC,wBAAwB,CAAC,IAAI,WAAW,CAAC,kBAAkB,CAAC,EAAE,EACrF,GAAG,CACJ,CAAC;IACF,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE;QACrB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,CAAC;YACjC,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,WAAW,GAAI,CAAY,CAAC,UAAU,EAAE,CAC5C,oBAAoB,EACpB,MAAM,CACP,CAAC;QACF,MAAM,WAAW,GAAI,CAAY,CAAC,UAAU,EAAE,CAC5C,oBAAoB,EACpB,MAAM,CACP,CAAC;QACF,IAAI,WAAW,GAAG,WAAW,EAAE,CAAC;YAC9B,OAAO,CAAC,CAAC;QACX,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;IACZ,CAAC,CAAC;AACJ,CAAC"}
@@ -1,12 +1,12 @@
1
- import type { Get, Path } from "../types";
1
+ import type { Field, Get } from "../types";
2
2
  /**
3
3
  * Gets the property value of the given `value` at the specified `path` (an array of object property names or array indexes).
4
4
  * If the `path` is undefined, returns the `value` itself.
5
5
  * If the `path` is a string, it is considered as a path with one item.
6
6
  * If the `path` leads to an unknown property, returns `undefined`.
7
7
  *
8
- * @param value The value from which to get the property value.
9
- * @param path The path leading to the property value or a property name or `undefined`.
8
+ * @param value - The value from which to get the property value.
9
+ * @param path - The path leading to the property value or a property name or `undefined`.
10
10
  * @returns The property value found at the given path, or `undefined` if it cannot be found.
11
11
  */
12
- export declare function get<const T, const P extends Path<T> | keyof T>(value: T, path?: P): Get<T, P>;
12
+ export declare function get<const T, const P extends Field<T>>(value: T, path?: P): Get<T, P>;
package/dist/tools/get.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import { SELF } from "../constants/SELF.js";
2
+ const { isArray } = Array;
2
3
  /**
3
4
  * Gets the property value of the given `value` at the specified `path` (an array of object property names or array indexes).
4
5
  * If the `path` is undefined, returns the `value` itself.
5
6
  * If the `path` is a string, it is considered as a path with one item.
6
7
  * If the `path` leads to an unknown property, returns `undefined`.
7
8
  *
8
- * @param value The value from which to get the property value.
9
- * @param path The path leading to the property value or a property name or `undefined`.
9
+ * @param value - The value from which to get the property value.
10
+ * @param path - The path leading to the property value or a property name or `undefined`.
10
11
  * @returns The property value found at the given path, or `undefined` if it cannot be found.
11
12
  */
12
13
  export function get(value, path) {
@@ -19,6 +20,9 @@ export function get(value, path) {
19
20
  case "symbol":
20
21
  return value?.[path];
21
22
  default: {
23
+ if (!isArray(path)) {
24
+ return value;
25
+ }
22
26
  switch (path.length) {
23
27
  case 0:
24
28
  return value;
@@ -1 +1 @@
1
- {"version":3,"file":"get.js","sourceRoot":"","sources":["../../lib/tools/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAG5C;;;;;;;;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IAAY,CAAC,CAAC,CAAQ,CACxB,EAAE,CAAE,IAAY,CAAC,CAAC,CAAQ,CAAC,CAAC;gBAC/B;oBACE,OAAO,IAAI,CAAC,MAAM,CAChB,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAE,KAAa,EAAE,CAAC,GAAG,CAAC,EACrC,KAAK,CACC,CAAC;YACb,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { NormalizedPathFieldSettings, QuerySettings } from "../types";
2
+ /**
3
+ * Returns query settings for path fields.
4
+ *
5
+ * @param settings - Settings for normalizing path fields.
6
+ * @returns Query settings for path fields.
7
+ */
8
+ export declare function querySettings<T>(settings?: NormalizedPathFieldSettings<T>): QuerySettings<T>;
@@ -0,0 +1,16 @@
1
+ import { EMPTY_OBJECT } from "unchangeable";
2
+ import { comparatorFieldValues } from "./comparatorFieldValues.js";
3
+ import { transformerFilterChildren } from "./transformerFilterChildren.js";
4
+ /**
5
+ * Returns query settings for path fields.
6
+ *
7
+ * @param settings - Settings for normalizing path fields.
8
+ * @returns Query settings for path fields.
9
+ */
10
+ export function querySettings(settings = EMPTY_OBJECT) {
11
+ return {
12
+ compareFieldValues: comparatorFieldValues(settings),
13
+ transformFilterChildren: transformerFilterChildren(settings),
14
+ };
15
+ }
16
+ //# sourceMappingURL=querySettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"querySettings.js","sourceRoot":"","sources":["../../lib/tools/querySettings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC3B,WAA2C,YAAY;IAEvD,OAAO;QACL,kBAAkB,EAAE,qBAAqB,CAAC,QAAQ,CAAC;QACnD,uBAAuB,EAAE,yBAAyB,CAAC,QAAQ,CAAC;KAC7D,CAAC;AACJ,CAAC"}
@@ -2,9 +2,9 @@ import type { Order, QuerySettings } from "../types";
2
2
  /**
3
3
  * Sorts provided `value` array according to the `orderList`.
4
4
  *
5
- * @param orderList The order to use for sorting.
6
- * @param value The array to sort.
7
- * @param settings Optional query settings.
5
+ * @param orderList - The order to use for sorting.
6
+ * @param value - The array to sort.
7
+ * @param settings - Optional query settings.
8
8
  * @returns A new sorted array.
9
9
  */
10
- export declare function sortItemList<T>(orderList: readonly Order<T>[] | undefined, value: readonly T[], settings?: QuerySettings<T>): readonly T[];
10
+ export declare function sortItemList<T>(orderList: NoInfer<readonly Order<T>[]> | undefined, value: readonly T[], settings?: QuerySettings<T>): readonly T[];
@@ -1,26 +1,20 @@
1
- import { escapeRegex } from "./escapeRegex.js";
1
+ import { EMPTY_OBJECT } from "unchangeable";
2
2
  import { get } from "./get.js";
3
3
  import { normalizeOrder } from "./normalizeOrder.js";
4
- import { sameField } from "./sameField.js";
5
4
  /**
6
5
  * Sorts provided `value` array according to the `orderList`.
7
6
  *
8
- * @param orderList The order to use for sorting.
9
- * @param value The array to sort.
10
- * @param settings Optional query settings.
7
+ * @param orderList - The order to use for sorting.
8
+ * @param value - The array to sort.
9
+ * @param settings - Optional query settings.
11
10
  * @returns A new sorted array.
12
11
  */
13
12
  export function sortItemList(orderList, value, settings) {
14
- const { pathField, pathFieldSeparator = "/", pathFieldSeparatorEscape, } = settings ?? {};
15
13
  if (orderList === undefined || orderList.length === 0) {
16
14
  return value;
17
15
  }
16
+ const { compareFieldValues } = settings ?? EMPTY_OBJECT;
18
17
  const normalizedOrder = orderList.map(normalizeOrder);
19
- const fieldSeparatorRegexp = pathField == null || pathFieldSeparator == null
20
- ? null
21
- : new RegExp(!pathFieldSeparatorEscape
22
- ? escapeRegex(pathFieldSeparator)
23
- : `(?<!${escapeRegex(pathFieldSeparatorEscape)})${escapeRegex(pathFieldSeparator)}`, "g");
24
18
  return value.toSorted((a, b) => {
25
19
  for (let index = 0; index < normalizedOrder.length; index++) {
26
20
  const { field, descending } = normalizedOrder[index];
@@ -29,24 +23,23 @@ export function sortItemList(orderList, value, settings) {
29
23
  if (valueA === valueB) {
30
24
  continue;
31
25
  }
32
- if (fieldSeparatorRegexp != null && sameField(field, pathField)) {
33
- if (valueA == null) {
34
- return valueB == null ? 0 : descending ? 1 : -1;
35
- }
36
- if (valueB == null) {
37
- return descending ? -1 : 1;
38
- }
39
- const normalizedA = valueA.replaceAll(fieldSeparatorRegexp, "\x00");
40
- const normalizedB = valueB.replaceAll(fieldSeparatorRegexp, "\x00");
41
- if (normalizedA > normalizedB) {
26
+ if (valueA == null) {
27
+ return valueB == null ? 0 : descending ? 1 : -1;
28
+ }
29
+ if (valueB == null) {
30
+ return descending ? -1 : 1;
31
+ }
32
+ const comparison = compareFieldValues?.(field, valueA, valueB);
33
+ if (comparison === undefined) {
34
+ if (valueA > valueB) {
42
35
  return descending ? -1 : 1;
43
36
  }
44
37
  return descending ? 1 : -1;
45
38
  }
46
- if (valueA > valueB) {
47
- return descending ? -1 : 1;
39
+ if (comparison === 0) {
40
+ continue;
48
41
  }
49
- return descending ? 1 : -1;
42
+ return descending ? -comparison : comparison;
50
43
  }
51
44
  return 0;
52
45
  });
@@ -1 +1 @@
1
- {"version":3,"file":"sortItemList.js","sourceRoot":"","sources":["../../lib/tools/sortItemList.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,SAA0C,EAC1C,KAAmB,EACnB,QAA2B;IAE3B,MAAM,EACJ,SAAS,EACT,kBAAkB,GAAG,GAAG,EACxB,wBAAwB,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CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7B,CAAC;YACD,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;gBACrB,SAAS;YACX,CAAC;YACD,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC;QAC/C,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,28 +1,8 @@
1
- import type { FieldFiltered, FilterChildren, FilterStringMatch } from "../types";
2
- export type TransformerFilterChildrenOptions<T> = {
3
- /**
4
- * Path to the field that contains the path value of an item, used for displaying items in a tree.
5
- *
6
- * @default "path"
7
- */
8
- pathField?: FieldFiltered<T, string>;
9
- /**
10
- * String used to escape the separator.
11
- *
12
- * @default "\\"
13
- */
14
- pathFieldSeparatorEscape?: string;
15
- /**
16
- * Maps path fields to a string used to separate the path nodes of a field value.
17
- *
18
- * @default "/"
19
- */
20
- pathFieldSeparator?: string;
21
- };
1
+ import type { FilterChildren, FilterStringMatch, NormalizedPathFieldSettings } from "../types";
22
2
  /**
23
3
  * Returns a function that transforms a `FilterChildren` into a `FilterStringMatch`.
24
4
  *
25
5
  * @param options - Options for the transformer.
26
6
  * @returns A function that takes a `FilterChildren` and returns a `FilterStringMatch` that matches the paths of the children of the item specified in the `FilterChildren`.
27
7
  */
28
- export declare function transformerFilterChildren<T>({ pathField, pathFieldSeparator, }?: TransformerFilterChildrenOptions<T>): (filter: FilterChildren<T>) => FilterStringMatch<T>;
8
+ export declare function transformerFilterChildren<T>({ pathField, pathFieldSeparator, }?: NormalizedPathFieldSettings<T>): (filter: FilterChildren<T>) => FilterStringMatch<T>;
@@ -10,10 +10,7 @@ import { get } from "./get.js";
10
10
  export function transformerFilterChildren({ pathField = "path", pathFieldSeparator = "/", } = EMPTY_OBJECT) {
11
11
  return (filter) => {
12
12
  const { value, minDepth = 1, maxDepth = Infinity } = filter;
13
- if (value === undefined) {
14
- throw new Error("FilterChildren must have a value");
15
- }
16
- const parentPath = get(value, pathField);
13
+ const parentPath = (get(value, pathField) ?? "");
17
14
  return filterChildren(parentPath, pathField, minDepth, maxDepth, pathFieldSeparator);
18
15
  };
19
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"transformerFilterChildren.js","sourceRoot":"","sources":["../../lib/tools/transformerFilterChildren.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQ5C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAuB/B;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAI,EAC3C,SAAS,GAAG,MAAkC,EAC9C,kBAAkB,GAAG,GAAG,MACe,YAAY;IACnD,OAAO,CAAC,MAAyB,EAAwB,EAAE;QACzD,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,QAAQ,EAAE,GAAG,MAAM,CAAC;QAC5D,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACtD,CAAC;QACD,MAAM,UAAU,GAAG,GAAG,CAAC,KAAK,EAAE,SAAgB,CAAW,CAAC;QAC1D,OAAO,cAAc,CACnB,UAAU,EACV,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,kBAAkB,CACnB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"transformerFilterChildren.js","sourceRoot":"","sources":["../../lib/tools/transformerFilterChildren.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAS5C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAI,EAC3C,SAAS,GAAG,MAAkC,EAC9C,kBAAkB,GAAG,GAAG,MACU,YAAY;IAC9C,OAAO,CAAC,MAAyB,EAAwB,EAAE;QACzD,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,QAAQ,EAAE,GAAG,MAAM,CAAC;QAC5D,MAAM,UAAU,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,SAAgB,CAAC,IAAI,EAAE,CAAW,CAAC;QAClE,OAAO,cAAc,CACnB,UAAU,EACV,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,kBAAkB,CACnB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
package/dist/tools.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { comparatorFieldValues } from "./tools/comparatorFieldValues.js";
1
2
  export { cork } from "./tools/cork.js";
2
3
  export { defineCheckQuery } from "./tools/defineCheckQuery.js";
3
4
  export { defineCustomFetch } from "./tools/defineCustomFetch.js";
@@ -12,6 +13,7 @@ export { intrinsicFilter } from "./tools/intrinsicFilter.js";
12
13
  export { isFilterGroup } from "./tools/isFilterGroup.js";
13
14
  export { normalizeOrder } from "./tools/normalizeOrder.js";
14
15
  export { queryItemList } from "./tools/queryItemList.js";
16
+ export { querySettings } from "./tools/querySettings.js";
15
17
  export { reverseOrder } from "./tools/reverseOrder.js";
16
18
  export { sameField } from "./tools/sameField.js";
17
19
  export { sortItemList } from "./tools/sortItemList.js";
package/dist/tools.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // File automatically generated by `vite-plugin-module-list`
2
+ export { comparatorFieldValues } from "./tools/comparatorFieldValues.js";
2
3
  export { cork } from "./tools/cork.js";
3
4
  export { defineCheckQuery } from "./tools/defineCheckQuery.js";
4
5
  export { defineCustomFetch } from "./tools/defineCustomFetch.js";
@@ -13,6 +14,7 @@ export { intrinsicFilter } from "./tools/intrinsicFilter.js";
13
14
  export { isFilterGroup } from "./tools/isFilterGroup.js";
14
15
  export { normalizeOrder } from "./tools/normalizeOrder.js";
15
16
  export { queryItemList } from "./tools/queryItemList.js";
17
+ export { querySettings } from "./tools/querySettings.js";
16
18
  export { reverseOrder } from "./tools/reverseOrder.js";
17
19
  export { sameField } from "./tools/sameField.js";
18
20
  export { sortItemList } from "./tools/sortItemList.js";
package/dist/tools.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"tools.js","sourceRoot":"","sources":["../lib/tools.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,E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MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { KeyFromUnion } from "./KeyFromUnion";
2
2
  import type { Primitive } from "./Primitive";
3
- export type CombineUnion<U> = [0] extends [1 & U] ? any : [U] extends [Function | readonly Function[]] ? undefined : [U] extends [Primitive] ? U : [U] extends readonly [Array<any>] ? U : {
3
+ export type CombineUnion<U> = [unknown] extends [U] ? unknown : [0] extends [1 & U] ? any : [U] extends [Function | readonly Function[]] ? undefined : [U] extends [Primitive] ? U : [U] extends readonly [Array<any>] ? U : {
4
4
  [K in KeyFromUnion<U>]: Continue<Combine<U, K>>;
5
5
  };
6
6
  type Combine<U, K extends string | number | symbol> = Exclude<Extract<U, {
@@ -0,0 +1,4 @@
1
+ type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
2
+ type NextDigit = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
3
+ export type Decrement<D> = D extends Digit ? NextDigit[D] : -1;
4
+ export {};
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=Decrement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Decrement.js","sourceRoot":"","sources":["../../lib/types/Decrement.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export type DepthLimit = 4;
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=DepthLimit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DepthLimit.js","sourceRoot":"","sources":["../../lib/types/DepthLimit.ts"],"names":[],"mappings":""}
@@ -1,3 +1,4 @@
1
1
  import type { SELF } from "../constants/SELF.ts";
2
+ import type { Key } from "./Key.ts";
2
3
  import type { Primitive } from "./Primitive";
3
- export type FieldKey<T> = T extends Primitive ? typeof SELF : keyof T;
4
+ export type FieldKey<T> = T extends Primitive ? typeof SELF : [unknown] extends [T] ? Key : keyof T;
@@ -1,5 +1,7 @@
1
+ import type { Decrement } from "./Decrement";
2
+ import type { DepthLimit } from "./DepthLimit";
1
3
  import type { Path } from "./Path";
2
4
  /**
3
5
  * Returns the type of the property at the specified `P` path.
4
6
  */
5
- export type Get<T, P> = [P] extends [readonly [infer K, ...infer R]] ? K extends keyof T ? R extends Path<T[K]> ? Get<T[K], R> : T[K] : never : [P] extends [keyof T] ? T[P] : T;
7
+ export type Get<T, P, D = DepthLimit> = [unknown] extends [T] ? unknown : [0] extends [1 & T] ? any : D extends -1 ? any : [P] extends [readonly [infer K, ...infer R]] ? K extends keyof T ? R extends Path<T[K]> ? Get<T[K], R, Decrement<D>> : T[K] : never : [P] extends [keyof T] ? T[P] : T;
@@ -4,7 +4,7 @@ type SymbolSelf = typeof SELF;
4
4
  /**
5
5
  * Returns union of keys whose mapped value extend the provided `P` type.
6
6
  */
7
- export type KeyFiltered<T, P> = [0] extends [1 & T] ? Key | SymbolSelf : T extends string | number | boolean | bigint | symbol ? T extends P ? SymbolSelf : never : T extends object ? keyof {
7
+ export type KeyFiltered<T, P> = [unknown] extends [T] ? Key | SymbolSelf : [0] extends [1 & T] ? Key | SymbolSelf : T extends string | number | boolean | bigint | symbol ? T extends P ? SymbolSelf : never : T extends object ? keyof {
8
8
  [K in keyof T as Extract<T[K], P> extends never ? never : K]-?: T[K];
9
9
  } : never;
10
10
  export {};
@@ -0,0 +1,24 @@
1
+ import type { FieldFiltered } from "./FieldFiltered";
2
+ /**
3
+ * Settings for fields that contain path values of items, used for displaying items in a tree.
4
+ */
5
+ export type NormalizedPathFieldSettings<T> = {
6
+ /**
7
+ * Path to the field that contains the path value of an item, used for displaying items in a tree.
8
+ *
9
+ * @default "path"
10
+ */
11
+ pathField?: FieldFiltered<T, string>;
12
+ /**
13
+ * String used to escape the separator.
14
+ *
15
+ * @default "\\"
16
+ */
17
+ pathFieldSeparatorEscape?: string;
18
+ /**
19
+ * Maps path fields to a string used to separate the path nodes of a field value.
20
+ *
21
+ * @default "/"
22
+ */
23
+ pathFieldSeparator?: string;
24
+ };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=NormalizedPathFieldSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NormalizedPathFieldSettings.js","sourceRoot":"","sources":["../../lib/types/NormalizedPathFieldSettings.ts"],"names":[],"mappings":""}
@@ -1,6 +1,7 @@
1
- import type { Increment } from "./Increment";
1
+ import type { Decrement } from "./Decrement";
2
+ import type { DepthLimit } from "./DepthLimit";
2
3
  import type { Key } from "./Key";
3
4
  import type { Primitive } from "./Primitive";
4
- export type Path<T, D = 7> = [0] extends [1 & T] ? readonly (Key | never)[] : D extends -1 ? never : T extends Primitive ? readonly never[] : T extends Array<infer P> ? readonly [number] | readonly [number, ...Path<P, Increment<D>>] : T extends object ? {
5
- [K in keyof T]: readonly [K] | readonly [K, ...Path<T[K], Increment<D>>];
5
+ export type Path<T, D = DepthLimit> = [unknown] extends [T] ? readonly (Key | never)[] : [0] extends [1 & T] ? readonly (Key | never)[] : D extends -1 ? never : T extends Primitive ? readonly never[] : T extends Array<infer P> ? readonly [number] | readonly [number, ...Path<P, Decrement<D>>] : T extends object ? {
6
+ [K in keyof T]: readonly [K] | readonly [K, ...Path<T[K], Decrement<D>>];
6
7
  }[keyof T] : never;
@@ -1,5 +1,6 @@
1
- import type { Increment } from "./Increment";
1
+ import type { Decrement } from "./Decrement";
2
+ import type { DepthLimit } from "./DepthLimit";
2
3
  import type { Key } from "./Key";
3
- export type PathFiltered<T, P, D = 7> = [0] extends [1 & T] ? readonly (Key | never)[] : D extends -1 ? never : T extends P ? readonly never[] : T extends ReadonlyArray<infer I> ? Extract<I, P> extends never ? readonly [number, ...PathFiltered<I, P, Increment<D>>] : readonly [number] : T extends object ? {
4
- [K in keyof T]: Extract<T[K], P> extends never ? readonly [K, ...PathFiltered<T[K], P, Increment<D>>] : readonly [K];
4
+ export type PathFiltered<T, P, D = DepthLimit> = [unknown] extends [T] ? readonly (Key | never)[] : [0] extends [1 & T] ? readonly (Key | never)[] : D extends -1 ? never : T extends P ? readonly never[] : T extends ReadonlyArray<infer I> ? Extract<I, P> extends never ? readonly [number, ...PathFiltered<I, P, Decrement<D>>] : readonly [number] : T extends object ? {
5
+ [K in keyof T]: Extract<T[K], P> extends never ? readonly [K, ...PathFiltered<T[K], P, Decrement<D>>] : readonly [K];
5
6
  }[keyof T] : never;
@@ -1,26 +1,10 @@
1
- import type { FieldFiltered } from "./FieldFiltered";
1
+ import type { Field } from "./Field";
2
2
  import type { FilterChildren } from "./FilterChildren";
3
3
  import type { IntrinsicFilter } from "./IntrinsicFilter";
4
4
  /**
5
5
  * Settings to use when doing a query.
6
6
  */
7
7
  export type QuerySettings<T> = {
8
- /**
9
- * Path to the field that contains the path value of an item, used for displaying items in a tree.
10
- */
11
- pathField?: FieldFiltered<T, string>;
12
- /**
13
- * String used to escape the separator.
14
- *
15
- * @default "\\"
16
- */
17
- pathFieldSeparatorEscape?: string;
18
- /**
19
- * Maps path fields to a string used to separate the path nodes of a field value.
20
- *
21
- * @default "/"
22
- */
23
- pathFieldSeparator?: string;
24
8
  /**
25
9
  * Returns a filter that captures the items expressed by the provided `FilterChildren`. The return filter cannot use filters of type `FilterChildren` or `FilterContext`.
26
10
  *
@@ -28,6 +12,17 @@ export type QuerySettings<T> = {
28
12
  * @returns A filter that captures the items expressed by the provided `FilterChildren`.
29
13
  */
30
14
  transformFilterChildren?: (filter: FilterChildren<T>) => IntrinsicFilter<T>;
15
+ /**
16
+ * Compares two values of a field for sorting purposes. If not provided, values are compared using the default comparison operators (`>`, `<`, `===`).
17
+ *
18
+ * This function is called only when both `a` and `b` are defined and different. If it returns `undefined`, the default comparison operators are used as a fallback.
19
+ *
20
+ * @param a - The first value to compare.
21
+ * @param b - The second value to compare.
22
+ * @param field - The field for which the values are compared.
23
+ * @returns `-1` if `a` should be sorted before `b`, `1` if `a` should be sorted after `b`, `0` if they are considered equal, or `undefined` to use the default comparison operators.
24
+ */
25
+ compareFieldValues?<T>(field: Field<T>, a: NonNullable<any>, b: NonNullable<any>): -1 | 0 | 1 | undefined;
31
26
  /**
32
27
  * Abort signal to abort the query.
33
28
  */
package/dist/types.d.ts CHANGED
@@ -5,6 +5,8 @@ export type { Context } from "./types/Context";
5
5
  export type { CustomFetch } from "./types/CustomFetch";
6
6
  export type { CustomFieldAggregateMap } from "./types/CustomFieldAggregateMap";
7
7
  export type { CustomFieldMap } from "./types/CustomFieldMap";
8
+ export type { Decrement } from "./types/Decrement";
9
+ export type { DepthLimit } from "./types/DepthLimit";
8
10
  export type { Field } from "./types/Field";
9
11
  export type { FieldFiltered } from "./types/FieldFiltered";
10
12
  export type { FieldFunction } from "./types/FieldFunction";
@@ -29,7 +31,6 @@ export type { Get } from "./types/Get";
29
31
  export type { Group } from "./types/Group";
30
32
  export type { Handler } from "./types/Handler";
31
33
  export type { Immutable } from "./types/Immutable";
32
- export type { Increment } from "./types/Increment";
33
34
  export type { InjectCustomFields } from "./types/InjectCustomFields";
34
35
  export type { IntersectUnion } from "./types/IntersectUnion";
35
36
  export type { IntrinsicFilter } from "./types/IntrinsicFilter";
@@ -40,6 +41,7 @@ export type { KeyFiltered } from "./types/KeyFiltered";
40
41
  export type { KeyFromUnion } from "./types/KeyFromUnion";
41
42
  export type { Locale } from "./types/Locale";
42
43
  export type { NextHandler } from "./types/NextHandler";
44
+ export type { NormalizedPathFieldSettings } from "./types/NormalizedPathFieldSettings";
43
45
  export type { Order } from "./types/Order";
44
46
  export type { OrderNormalized } from "./types/OrderNormalized";
45
47
  export type { Parameters } from "./types/Parameters";
package/doc/README.md CHANGED
@@ -20,6 +20,8 @@
20
20
  - [Context](type-aliases/Context.md)
21
21
  - [CustomFieldAggregateMap](type-aliases/CustomFieldAggregateMap.md)
22
22
  - [CustomFieldMap](type-aliases/CustomFieldMap.md)
23
+ - [Decrement](type-aliases/Decrement.md)
24
+ - [DepthLimit](type-aliases/DepthLimit.md)
23
25
  - [Field](type-aliases/Field.md)
24
26
  - [FieldFiltered](type-aliases/FieldFiltered.md)
25
27
  - [FieldFunction](type-aliases/FieldFunction.md)
@@ -44,7 +46,6 @@
44
46
  - [Group](type-aliases/Group.md)
45
47
  - [Handler](type-aliases/Handler.md)
46
48
  - [Immutable](type-aliases/Immutable.md)
47
- - [Increment](type-aliases/Increment.md)
48
49
  - [InjectCustomFields](type-aliases/InjectCustomFields.md)
49
50
  - [IntersectUnion](type-aliases/IntersectUnion.md)
50
51
  - [IntrinsicFilter](type-aliases/IntrinsicFilter.md)
@@ -55,6 +56,7 @@
55
56
  - [KeyFromUnion](type-aliases/KeyFromUnion.md)
56
57
  - [Locale](type-aliases/Locale.md)
57
58
  - [NextHandler](type-aliases/NextHandler.md)
59
+ - [NormalizedPathFieldSettings](type-aliases/NormalizedPathFieldSettings.md)
58
60
  - [Order](type-aliases/Order.md)
59
61
  - [OrderNormalized](type-aliases/OrderNormalized.md)
60
62
  - [Parameters](type-aliases/Parameters.md)
@@ -92,6 +94,7 @@
92
94
  - [branch](functions/branch.md)
93
95
  - [cache](functions/cache.md)
94
96
  - [combine](functions/combine.md)
97
+ - [comparatorFieldValues](functions/comparatorFieldValues.md)
95
98
  - [cork](functions/cork.md)
96
99
  - [defineCheckQuery](functions/defineCheckQuery.md)
97
100
  - [defineCustomFetch](functions/defineCustomFetch.md)
@@ -110,6 +113,7 @@
110
113
  - [log](functions/log.md)
111
114
  - [normalizeOrder](functions/normalizeOrder.md)
112
115
  - [queryItemList](functions/queryItemList.md)
116
+ - [querySettings](functions/querySettings.md)
113
117
  - [retry](functions/retry.md)
114
118
  - [reverseOrder](functions/reverseOrder.md)
115
119
  - [sameField](functions/sameField.md)
@@ -50,7 +50,7 @@ Error to be thrown in case there is an issue with the query call. Only instances
50
50
 
51
51
  #### Defined in
52
52
 
53
- [lib/errors/RequestError.ts:7](https://github.com/nevoland/quetch/blob/94f546831241bf41f83cf97787b7e923c8cf7824/lib/errors/RequestError.ts#L7)
53
+ [lib/errors/RequestError.ts:7](https://github.com/nevoland/quetch/blob/1cf615b166541d2a753e34c0a2dd4a9474026d7a/lib/errors/RequestError.ts#L7)
54
54
 
55
55
  ## Properties
56
56
 
@@ -60,7 +60,7 @@ Error to be thrown in case there is an issue with the query call. Only instances
60
60
 
61
61
  #### Defined in
62
62
 
63
- [lib/errors/RequestError.ts:10](https://github.com/nevoland/quetch/blob/94f546831241bf41f83cf97787b7e923c8cf7824/lib/errors/RequestError.ts#L10)
63
+ [lib/errors/RequestError.ts:10](https://github.com/nevoland/quetch/blob/1cf615b166541d2a753e34c0a2dd4a9474026d7a/lib/errors/RequestError.ts#L10)
64
64
 
65
65
  ***
66
66
 
@@ -70,7 +70,7 @@ Error to be thrown in case there is an issue with the query call. Only instances
70
70
 
71
71
  #### Defined in
72
72
 
73
- [lib/errors/RequestError.ts:11](https://github.com/nevoland/quetch/blob/94f546831241bf41f83cf97787b7e923c8cf7824/lib/errors/RequestError.ts#L11)
73
+ [lib/errors/RequestError.ts:11](https://github.com/nevoland/quetch/blob/1cf615b166541d2a753e34c0a2dd4a9474026d7a/lib/errors/RequestError.ts#L11)
74
74
 
75
75
  ***
76
76
 
@@ -80,7 +80,7 @@ Error to be thrown in case there is an issue with the query call. Only instances
80
80
 
81
81
  #### Defined in
82
82
 
83
- [lib/errors/RequestError.ts:12](https://github.com/nevoland/quetch/blob/94f546831241bf41f83cf97787b7e923c8cf7824/lib/errors/RequestError.ts#L12)
83
+ [lib/errors/RequestError.ts:12](https://github.com/nevoland/quetch/blob/1cf615b166541d2a753e34c0a2dd4a9474026d7a/lib/errors/RequestError.ts#L12)
84
84
 
85
85
  ***
86
86
 
@@ -90,4 +90,4 @@ Error to be thrown in case there is an issue with the query call. Only instances
90
90
 
91
91
  #### Defined in
92
92
 
93
- [lib/errors/RequestError.ts:9](https://github.com/nevoland/quetch/blob/94f546831241bf41f83cf97787b7e923c8cf7824/lib/errors/RequestError.ts#L9)
93
+ [lib/errors/RequestError.ts:9](https://github.com/nevoland/quetch/blob/1cf615b166541d2a753e34c0a2dd4a9474026d7a/lib/errors/RequestError.ts#L9)
@@ -58,4 +58,4 @@ If a query occurs twice, `mergeQuery(query, currentQuery)` is called and the out
58
58
 
59
59
  ## Defined in
60
60
 
61
- [lib/middlewares/aggregate.ts:17](https://github.com/nevoland/quetch/blob/94f546831241bf41f83cf97787b7e923c8cf7824/lib/middlewares/aggregate.ts#L17)
61
+ [lib/middlewares/aggregate.ts:17](https://github.com/nevoland/quetch/blob/1cf615b166541d2a753e34c0a2dd4a9474026d7a/lib/middlewares/aggregate.ts#L17)
@@ -49,4 +49,4 @@ const customFetch = combine(
49
49
 
50
50
  ## Defined in
51
51
 
52
- [lib/middlewares/branch.ts:21](https://github.com/nevoland/quetch/blob/94f546831241bf41f83cf97787b7e923c8cf7824/lib/middlewares/branch.ts#L21)
52
+ [lib/middlewares/branch.ts:21](https://github.com/nevoland/quetch/blob/1cf615b166541d2a753e34c0a2dd4a9474026d7a/lib/middlewares/branch.ts#L21)
@@ -68,4 +68,4 @@ Cache store.
68
68
 
69
69
  ## Defined in
70
70
 
71
- [lib/middlewares/cache.ts:8](https://github.com/nevoland/quetch/blob/94f546831241bf41f83cf97787b7e923c8cf7824/lib/middlewares/cache.ts#L8)
71
+ [lib/middlewares/cache.ts:8](https://github.com/nevoland/quetch/blob/1cf615b166541d2a753e34c0a2dd4a9474026d7a/lib/middlewares/cache.ts#L8)
@@ -116,4 +116,4 @@ Handler that combines all provided handlers.
116
116
 
117
117
  ## Defined in
118
118
 
119
- [lib/middlewares/combine.ts:801](https://github.com/nevoland/quetch/blob/94f546831241bf41f83cf97787b7e923c8cf7824/lib/middlewares/combine.ts#L801)
119
+ [lib/middlewares/combine.ts:801](https://github.com/nevoland/quetch/blob/1cf615b166541d2a753e34c0a2dd4a9474026d7a/lib/middlewares/combine.ts#L801)