feathers-utils 10.0.0-rc.9 → 10.0.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 (238) hide show
  1. package/dist/guards.mjs +1 -1
  2. package/dist/guards.mjs.map +1 -1
  3. package/dist/{hook-context-D16ztLk5.d.mts → hook-context-aHkq1h0N.d.mts} +3 -2
  4. package/dist/{traverse.hook-C2VIvQrn.mjs → hooks-CzxNpt2c.mjs} +181 -110
  5. package/dist/hooks-CzxNpt2c.mjs.map +1 -0
  6. package/dist/hooks.d.mts +84 -24
  7. package/dist/hooks.mjs +5 -9
  8. package/dist/{zip-data-result.util-Bjinzz8t.d.mts → index-CNrzxmWo.d.mts} +55 -8
  9. package/dist/index.d.mts +9 -10
  10. package/dist/index.mjs +8 -12
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/{infer-service-methods-DRcpjEXa.d.mts → infer-service-methods-D7zRVQeJ.d.mts} +2 -2
  13. package/dist/{internal.utils-C8LH1H55.mjs → internal.utils-BWQ25nOd.mjs} +2 -5
  14. package/dist/internal.utils-BWQ25nOd.mjs.map +1 -0
  15. package/dist/{mutate-result.util-BBqz9sPw.d.mts → mutate-result.util-BIeYlqqT.d.mts} +2 -2
  16. package/dist/{mutate-result.util-C8ZumXWd.mjs → mutate-result.util-CCBWix-G.mjs} +3 -7
  17. package/dist/{mutate-result.util-C8ZumXWd.mjs.map → mutate-result.util-CCBWix-G.mjs.map} +1 -1
  18. package/dist/{throw-if.hook-CiuUMtny.mjs → predicates-C2SeOKGd.mjs} +80 -84
  19. package/dist/predicates-C2SeOKGd.mjs.map +1 -0
  20. package/dist/predicates.d.mts +18 -42
  21. package/dist/predicates.mjs +2 -4
  22. package/dist/{resolve-B-y8cmo6.mjs → resolve-B81gQqXW.mjs} +4 -8
  23. package/dist/resolve-B81gQqXW.mjs.map +1 -0
  24. package/dist/{resolve-CsbBZQE9.d.mts → resolve-CA7-EaTw.d.mts} +7 -7
  25. package/dist/resolvers.d.mts +2 -2
  26. package/dist/resolvers.mjs +2 -12
  27. package/dist/resolvers.mjs.map +1 -1
  28. package/dist/{transform-result.hook-CTPT14PS.d.mts → transform-result.hook-C8-4Lezj.d.mts} +8 -5
  29. package/dist/{transform-result.hook-BZ55kPq7.mjs → transform-result.hook-DifNj7zf.mjs} +14 -16
  30. package/dist/transform-result.hook-DifNj7zf.mjs.map +1 -0
  31. package/dist/transformers.d.mts +3 -3
  32. package/dist/transformers.mjs +4 -11
  33. package/dist/transformers.mjs.map +1 -1
  34. package/dist/{unless.hook-s-Efoy7S.d.mts → unless.hook-CVD7SrZh.d.mts} +10 -7
  35. package/dist/{zip-data-result.util-CVD17gWe.mjs → utils-ByzrJKGQ.mjs} +25 -42
  36. package/dist/utils-ByzrJKGQ.mjs.map +1 -0
  37. package/dist/utils.d.mts +3 -5
  38. package/dist/utils.mjs +4 -6
  39. package/package.json +42 -30
  40. package/src/hooks/cache/cache.hook.ts +9 -7
  41. package/src/hooks/check-multi/check-multi.hook.ts +15 -14
  42. package/src/hooks/check-required/check-required.hook.ts +11 -7
  43. package/src/hooks/create-related/create-related.hook.ts +7 -3
  44. package/src/hooks/debug/debug.hook.ts +1 -1
  45. package/src/hooks/disable-pagination/disable-pagination.hook.ts +12 -5
  46. package/src/hooks/disallow/disallow.hook.ts +8 -3
  47. package/src/hooks/iff/iff.hook.ts +5 -5
  48. package/src/hooks/iff-else/iff-else.hook.ts +20 -9
  49. package/src/hooks/index.ts +1 -0
  50. package/src/hooks/on-delete/on-delete.hook.ts +7 -3
  51. package/src/hooks/params-for-server/params-for-server.hook.ts +12 -5
  52. package/src/hooks/params-from-client/params-from-client.hook.ts +11 -6
  53. package/src/hooks/rate-limit/rate-limit.hook.ts +58 -0
  54. package/src/hooks/set-data/set-data.hook.ts +10 -7
  55. package/src/hooks/set-field/set-field.hook.ts +16 -12
  56. package/src/hooks/set-result/set-result.hook.ts +9 -3
  57. package/src/hooks/set-slug/set-slug.hook.ts +8 -6
  58. package/src/hooks/skippable/skippable.hook.ts +16 -12
  59. package/src/hooks/soft-delete/soft-delete.hook.ts +5 -6
  60. package/src/hooks/stashable/stashable.hook.ts +14 -14
  61. package/src/hooks/throw-if/throw-if.hook.ts +2 -2
  62. package/src/hooks/transform-data/transform-data.hook.ts +4 -6
  63. package/src/hooks/transform-query/transform-query.hook.ts +6 -5
  64. package/src/hooks/transform-result/transform-result.hook.ts +8 -11
  65. package/src/hooks/traverse/traverse.hook.ts +11 -10
  66. package/src/internal.utils.ts +1 -0
  67. package/src/predicates/and/and.predicate.ts +57 -0
  68. package/src/predicates/index.ts +2 -2
  69. package/src/predicates/is-context/is-context.predicate.ts +20 -27
  70. package/src/predicates/or/or.predicate.ts +60 -0
  71. package/src/resolvers/resolve/resolve.ts +4 -2
  72. package/src/resolvers/resolve-data/resolve-data.ts +3 -3
  73. package/src/resolvers/resolve-query/resolve-query.ts +6 -1
  74. package/src/resolvers/resolve-result/resolve-result.ts +6 -3
  75. package/src/utils/check-context/check-context.util.ts +89 -8
  76. package/dist/internal.utils-C8LH1H55.mjs.map +0 -1
  77. package/dist/resolve-B-y8cmo6.mjs.map +0 -1
  78. package/dist/throw-if.hook-CiuUMtny.mjs.map +0 -1
  79. package/dist/transform-result.hook-BZ55kPq7.mjs.map +0 -1
  80. package/dist/traverse.hook-C2VIvQrn.mjs.map +0 -1
  81. package/dist/zip-data-result.util-CVD17gWe.mjs.map +0 -1
  82. package/src/.DS_Store +0 -0
  83. package/src/guards/has-query/has-query.guard.md +0 -6
  84. package/src/hooks/.DS_Store +0 -0
  85. package/src/hooks/cache/cache.hook.md +0 -227
  86. package/src/hooks/cache/cache.hook.test.ts +0 -944
  87. package/src/hooks/check-multi/check-multi.hook.md +0 -10
  88. package/src/hooks/check-multi/check-multi.hook.test.ts +0 -173
  89. package/src/hooks/check-required/check-required.hook.md +0 -8
  90. package/src/hooks/check-required/check-required.hook.test.ts +0 -41
  91. package/src/hooks/create-related/create-related.hook.md +0 -8
  92. package/src/hooks/create-related/create-related.hook.test.ts +0 -405
  93. package/src/hooks/debug/debug.hook.md +0 -8
  94. package/src/hooks/debug/debug.hook.test.ts +0 -25
  95. package/src/hooks/disable-pagination/disable-pagination.hook.md +0 -8
  96. package/src/hooks/disable-pagination/disable-pagination.hook.test.ts +0 -61
  97. package/src/hooks/disallow/disallow.hook.md +0 -9
  98. package/src/hooks/disallow/disallow.hook.test.ts +0 -159
  99. package/src/hooks/iff/iff.hook.md +0 -19
  100. package/src/hooks/iff/iff.hook.test.ts +0 -469
  101. package/src/hooks/iff-else/iff-else.hook.md +0 -19
  102. package/src/hooks/iff-else/iff-else.hook.test.ts +0 -219
  103. package/src/hooks/on-delete/on-delete.hook.md +0 -32
  104. package/src/hooks/on-delete/on-delete.hook.test.ts +0 -918
  105. package/src/hooks/params-for-server/params-for-server.hook.md +0 -10
  106. package/src/hooks/params-for-server/params-for-server.hook.test.ts +0 -68
  107. package/src/hooks/params-from-client/params-from-client.hook.md +0 -10
  108. package/src/hooks/params-from-client/params-from-client.hook.test.ts +0 -54
  109. package/src/hooks/prevent-changes/prevent-changes.hook.md +0 -8
  110. package/src/hooks/prevent-changes/prevent-changes.hook.test.ts +0 -206
  111. package/src/hooks/set-data/set-data.hook.md +0 -8
  112. package/src/hooks/set-data/set-data.hook.test.ts +0 -390
  113. package/src/hooks/set-field/set-field.hook.md +0 -8
  114. package/src/hooks/set-field/set-field.hook.test.ts +0 -94
  115. package/src/hooks/set-result/set-result.hook.md +0 -8
  116. package/src/hooks/set-result/set-result.hook.test.ts +0 -417
  117. package/src/hooks/set-slug/set-slug.hook.md +0 -8
  118. package/src/hooks/set-slug/set-slug.hook.test.ts +0 -57
  119. package/src/hooks/skippable/skippable.hook.md +0 -20
  120. package/src/hooks/skippable/skippable.hook.test.ts +0 -124
  121. package/src/hooks/soft-delete/soft-delete.hook.md +0 -8
  122. package/src/hooks/soft-delete/soft-delete.hook.test.ts +0 -213
  123. package/src/hooks/stashable/stashable.hook.md +0 -8
  124. package/src/hooks/stashable/stashable.hook.test.ts +0 -255
  125. package/src/hooks/throw-if/throw-if.hook.md +0 -9
  126. package/src/hooks/throw-if/throw-if.hook.test.ts +0 -27
  127. package/src/hooks/throw-if-is-multi/throw-if-is-multi.hook.md +0 -10
  128. package/src/hooks/throw-if-is-multi/throw-if-is-multi.hook.test.ts +0 -148
  129. package/src/hooks/throw-if-is-provider/throw-if-is-provider.hook.md +0 -10
  130. package/src/hooks/throw-if-is-provider/throw-if-is-provider.hook.test.ts +0 -39
  131. package/src/hooks/transform-data/transform-data.hook.md +0 -49
  132. package/src/hooks/transform-data/transform-data.hook.test-d.ts +0 -104
  133. package/src/hooks/transform-data/transform-data.hook.test.ts +0 -115
  134. package/src/hooks/transform-query/transform-query.hook.md +0 -19
  135. package/src/hooks/transform-query/transform-query.hook.test.ts +0 -30
  136. package/src/hooks/transform-result/transform-result.hook.md +0 -41
  137. package/src/hooks/transform-result/transform-result.hook.test-d.ts +0 -104
  138. package/src/hooks/transform-result/transform-result.hook.test.ts +0 -248
  139. package/src/hooks/traverse/traverse.hook.md +0 -8
  140. package/src/hooks/traverse/traverse.hook.test.ts +0 -128
  141. package/src/hooks/unless/unless.hook.md +0 -13
  142. package/src/hooks/unless/unless.hook.test.ts +0 -450
  143. package/src/predicates/.DS_Store +0 -0
  144. package/src/predicates/every/every.predicate.md +0 -9
  145. package/src/predicates/every/every.predicate.test.ts +0 -186
  146. package/src/predicates/every/every.predicate.ts +0 -66
  147. package/src/predicates/is-context/is-context.predicate.md +0 -4
  148. package/src/predicates/is-context/is-context.predicate.test.ts +0 -64
  149. package/src/predicates/is-multi/is-multi.predicate.md +0 -4
  150. package/src/predicates/is-multi/is-multi.predicate.test.ts +0 -57
  151. package/src/predicates/is-paginated/is-paginated.predicate.md +0 -6
  152. package/src/predicates/is-paginated/is-paginated.predicate.test.ts +0 -72
  153. package/src/predicates/is-provider/is-provider.predicate.md +0 -4
  154. package/src/predicates/is-provider/is-provider.predicate.test.ts +0 -138
  155. package/src/predicates/not/not.predicate.md +0 -9
  156. package/src/predicates/not/not.predicate.test.ts +0 -124
  157. package/src/predicates/should-skip/should-skip.predicate.md +0 -7
  158. package/src/predicates/should-skip/should-skip.predicate.test.ts +0 -121
  159. package/src/predicates/some/some.predicate.md +0 -9
  160. package/src/predicates/some/some.predicate.test.ts +0 -66
  161. package/src/predicates/some/some.predicate.ts +0 -69
  162. package/src/resolvers/from-predicate/from-predicate.md +0 -27
  163. package/src/resolvers/from-predicate/from-predicate.test-d.ts +0 -33
  164. package/src/resolvers/from-predicate/from-predicate.test.ts +0 -52
  165. package/src/resolvers/helpers/defaults/defaults.md +0 -9
  166. package/src/resolvers/helpers/helpers.test-d.ts +0 -96
  167. package/src/resolvers/helpers/helpers.test.ts +0 -117
  168. package/src/resolvers/helpers/lowercase/lowercase.md +0 -9
  169. package/src/resolvers/helpers/omit/omit.md +0 -9
  170. package/src/resolvers/helpers/set-now/set-now.md +0 -9
  171. package/src/resolvers/helpers/trim/trim.md +0 -9
  172. package/src/resolvers/resolve/resolve.md +0 -19
  173. package/src/resolvers/resolve/resolve.test-d.ts +0 -63
  174. package/src/resolvers/resolve/resolve.test.ts +0 -130
  175. package/src/resolvers/resolve-data/resolve-data.md +0 -17
  176. package/src/resolvers/resolve-data/resolve-data.test-d.ts +0 -73
  177. package/src/resolvers/resolve-data/resolve-data.test.ts +0 -420
  178. package/src/resolvers/resolve-query/resolve-query.md +0 -17
  179. package/src/resolvers/resolve-query/resolve-query.test-d.ts +0 -50
  180. package/src/resolvers/resolve-query/resolve-query.test.ts +0 -230
  181. package/src/resolvers/resolve-result/resolve-result.md +0 -17
  182. package/src/resolvers/resolve-result/resolve-result.test-d.ts +0 -64
  183. package/src/resolvers/resolve-result/resolve-result.test.ts +0 -369
  184. package/src/transformers/defaults/defaults.transformer.md +0 -4
  185. package/src/transformers/defaults/defaults.transformer.test-d.ts +0 -79
  186. package/src/transformers/defaults/defaults.transformer.test.ts +0 -58
  187. package/src/transformers/lowercase/lowercase.transformer.md +0 -4
  188. package/src/transformers/lowercase/lowercase.transformer.test.ts +0 -40
  189. package/src/transformers/omit/omit.transformer.md +0 -4
  190. package/src/transformers/omit/omit.transformer.test.ts +0 -29
  191. package/src/transformers/parse-date/parse-date.transformer.md +0 -4
  192. package/src/transformers/parse-date/parse-date.transformer.test.ts +0 -41
  193. package/src/transformers/pick/pick.transformer.md +0 -4
  194. package/src/transformers/pick/pick.transformer.test.ts +0 -27
  195. package/src/transformers/set-now/set-now.transformer.md +0 -4
  196. package/src/transformers/set-now/set-now.transformer.test.ts +0 -28
  197. package/src/transformers/trim/trim.transformer.md +0 -4
  198. package/src/transformers/trim/trim.transformer.test.ts +0 -40
  199. package/src/utils/.DS_Store +0 -0
  200. package/src/utils/add-skip/add-skip.util.md +0 -6
  201. package/src/utils/add-skip/add-skip.util.test.ts +0 -29
  202. package/src/utils/add-to-query/add-to-query.util.md +0 -4
  203. package/src/utils/add-to-query/add-to-query.util.test.ts +0 -72
  204. package/src/utils/check-context/check-context.util.md +0 -4
  205. package/src/utils/check-context/check-context.util.test.ts +0 -107
  206. package/src/utils/chunk-find/chunk-find.util.md +0 -6
  207. package/src/utils/chunk-find/chunk-find.util.test.ts +0 -118
  208. package/src/utils/combine/combine.util.md +0 -8
  209. package/src/utils/combine/combine.util.test.ts +0 -158
  210. package/src/utils/context-to-json/context-to-json.util.md +0 -4
  211. package/src/utils/define-hooks/define-hooks.util.md +0 -27
  212. package/src/utils/define-hooks/define-hooks.util.test.ts +0 -27
  213. package/src/utils/get-data-is-array/get-data-is-array.util.md +0 -4
  214. package/src/utils/get-data-is-array/get-data-is-array.util.test.ts +0 -63
  215. package/src/utils/get-exposed-methods/get-exposed-methods.util.md +0 -4
  216. package/src/utils/get-exposed-methods/get-exposed-methods.util.test.ts +0 -47
  217. package/src/utils/get-paginate/get-paginate.util.md +0 -4
  218. package/src/utils/get-paginate/get-paginate.util.test.ts +0 -73
  219. package/src/utils/get-result-is-array/get-result-is-array.util.md +0 -4
  220. package/src/utils/get-result-is-array/get-result-is-array.util.test.ts +0 -187
  221. package/src/utils/iterate-find/iterate-find.util.md +0 -6
  222. package/src/utils/iterate-find/iterate-find.util.test.ts +0 -122
  223. package/src/utils/mutate-data/mutate-data.util.md +0 -8
  224. package/src/utils/mutate-result/mutate-result.util.md +0 -8
  225. package/src/utils/mutate-result/mutate-result.util.test.ts +0 -175
  226. package/src/utils/patch-batch/patch-batch.util.md +0 -4
  227. package/src/utils/patch-batch/patch-batch.util.test.ts +0 -41
  228. package/src/utils/skip-result/skip-result.util.md +0 -4
  229. package/src/utils/skip-result/skip-result.util.test.ts +0 -262
  230. package/src/utils/sort-query-properties/sort-query-properties.util.md +0 -4
  231. package/src/utils/sort-query-properties/sort-query-properties.util.test.ts +0 -93
  232. package/src/utils/to-paginated/to-paginated.util.md +0 -4
  233. package/src/utils/to-paginated/to-paginated.util.test.ts +0 -27
  234. package/src/utils/transform-params/transform-params.util.md +0 -4
  235. package/src/utils/walk-query/walk-query.util.md +0 -4
  236. package/src/utils/walk-query/walk-query.util.test.ts +0 -141
  237. package/src/utils/zip-data-result/zip-data-result.util.md +0 -4
  238. package/src/utils/zip-data-result/zip-data-result.util.test.ts +0 -180
package/dist/guards.mjs CHANGED
@@ -25,7 +25,7 @@
25
25
  function hasQuery(params) {
26
26
  return !!params.query;
27
27
  }
28
-
29
28
  //#endregion
30
29
  export { hasQuery };
30
+
31
31
  //# sourceMappingURL=guards.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"guards.mjs","names":[],"sources":["../src/guards/has-query/has-query.guard.ts"],"sourcesContent":["import type { Params } from '@feathersjs/feathers'\nimport type { RequiredQuery } from '../../utility-types/required-query.js'\n\n/**\n * Type guard to check if the `query` property of `Params` is present and non-nullable.\n *\n * @param params - The `Params` object to check.\n * @returns `true` if `params.query` is present and non-nullable, otherwise `false`.\n *\n * @see https://utils.feathersjs.com/guards/has-query.html\n *\n * @example\n * ```ts\n * import { hasQuery } from 'feathers-utils/guards'\n *\n * function example(params: Params) {\n * // `params.query` is optional and can be undefined at this point\n * if (!hasQuery(params)) {\n * return;\n * }\n *\n * // TypeScript now knows that params.query is present and non-nullable\n * // You can safely access params.query here without additional checks\n * }\n * ```\n */\nexport function hasQuery<P extends Params>(\n params: P,\n): params is RequiredQuery<P> {\n return !!params.query\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,SACd,QAC4B;AAC5B,QAAO,CAAC,CAAC,OAAO"}
1
+ {"version":3,"file":"guards.mjs","names":[],"sources":["../src/guards/has-query/has-query.guard.ts"],"sourcesContent":["import type { Params } from '@feathersjs/feathers'\nimport type { RequiredQuery } from '../../utility-types/required-query.js'\n\n/**\n * Type guard to check if the `query` property of `Params` is present and non-nullable.\n *\n * @param params - The `Params` object to check.\n * @returns `true` if `params.query` is present and non-nullable, otherwise `false`.\n *\n * @see https://utils.feathersjs.com/guards/has-query.html\n *\n * @example\n * ```ts\n * import { hasQuery } from 'feathers-utils/guards'\n *\n * function example(params: Params) {\n * // `params.query` is optional and can be undefined at this point\n * if (!hasQuery(params)) {\n * return;\n * }\n *\n * // TypeScript now knows that params.query is present and non-nullable\n * // You can safely access params.query here without additional checks\n * }\n * ```\n */\nexport function hasQuery<P extends Params>(\n params: P,\n): params is RequiredQuery<P> {\n return !!params.query\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,SACd,QAC4B;CAC5B,OAAO,CAAC,CAAC,OAAO"}
@@ -2,6 +2,7 @@ import { HookContext, NextFunction, Paginated, Params } from "@feathersjs/feathe
2
2
 
3
3
  //#region src/internal.utils.d.ts
4
4
  type MaybeArray<T> = T | readonly T[];
5
+ type UnpackMaybeArray<T> = T extends readonly (infer E)[] ? E : T;
5
6
  type Promisable<T> = T | Promise<T>;
6
7
  type KeyOf<T> = Extract<keyof T, string>;
7
8
  type UnwrapArray<T> = T extends Array<infer U> ? U : T;
@@ -46,5 +47,5 @@ type UnwrapPaginatedOrArray<T> = T extends Paginated<infer D> ? D : T extends an
46
47
  type ResultSingleHookContext<H extends HookContext> = UnwrapPaginatedOrArray<NonNullable<H['result']>>;
47
48
  type DataSingleHookContext<H extends HookContext> = UnwrapArray<NonNullable<H['data']>>;
48
49
  //#endregion
49
- export { Promisable as A, hookTypes as C, KeyOfOrDotNotation as D, KeyOf as E, MaybeArray as O, TransportName as S, AnyFallback as T, PredicateItemWithContext as _, ContextFunction as a, TransformerFn as b, DefaultsInput as c, HookFunction as d, HookType$1 as f, PredicateFn as g, PredicateContextSync as h, UnwrapPaginatedOrArray as i, UnwrapArray as j, NeverFallback as k, DispatchOption as l, PredicateContextAsync as m, ResultSingleHookContext as n, ContextFunctionAsync as o, MethodName as p, UnwrapPaginated as r, ContextFunctionSync as s, DataSingleHookContext as t, FieldKey as u, StringFieldKey as v, methodNames as w, TransformerInputFn as x, TransformParamsFn as y };
50
- //# sourceMappingURL=hook-context-D16ztLk5.d.mts.map
50
+ export { Promisable as A, hookTypes as C, KeyOfOrDotNotation as D, KeyOf as E, UnwrapArray as M, MaybeArray as O, TransportName as S, AnyFallback as T, PredicateItemWithContext as _, ContextFunction as a, TransformerFn as b, DefaultsInput as c, HookFunction as d, HookType$1 as f, PredicateFn as g, PredicateContextSync as h, UnwrapPaginatedOrArray as i, UnpackMaybeArray as j, NeverFallback as k, DispatchOption as l, PredicateContextAsync as m, ResultSingleHookContext as n, ContextFunctionAsync as o, MethodName as p, UnwrapPaginated as r, ContextFunctionSync as s, DataSingleHookContext as t, FieldKey as u, StringFieldKey as v, methodNames as w, TransformerInputFn as x, TransformParamsFn as y };
51
+ //# sourceMappingURL=hook-context-aHkq1h0N.d.mts.map
@@ -1,18 +1,18 @@
1
- import { f as isMulti, l as isProvider, m as every, t as throwIf } from "./throw-if.hook-CiuUMtny.mjs";
2
- import { d as checkContext, f as addToQuery, h as sortQueryProperties, r as transformParams, u as contextToJson } from "./zip-data-result.util-CVD17gWe.mjs";
3
- import { a as traverse$1, i as isPromise, r as toArray, t as early } from "./internal.utils-C8LH1H55.mjs";
4
- import { i as getDataIsArray, r as getResultIsArray } from "./mutate-result.util-C8ZumXWd.mjs";
5
- import { r as transformData } from "./transform-result.hook-BZ55kPq7.mjs";
1
+ import { g as every, p as isMulti, t as throwIf, u as isProvider } from "./predicates-C2SeOKGd.mjs";
2
+ import { d as checkContext, f as addToQuery, h as sortQueryProperties, r as transformParams, u as contextToJson } from "./utils-ByzrJKGQ.mjs";
3
+ import { a as traverse$1, i as isPromise, r as toArray, t as early } from "./internal.utils-BWQ25nOd.mjs";
4
+ import { i as getDataIsArray, r as getResultIsArray } from "./mutate-result.util-CCBWix-G.mjs";
5
+ import { r as transformData } from "./transform-result.hook-DifNj7zf.mjs";
6
+ import "./resolve-B81gQqXW.mjs";
6
7
  import isObject from "lodash/isObject.js";
7
8
  import { copy } from "fast-copy";
8
- import { BadRequest, Forbidden, MethodNotAllowed } from "@feathersjs/errors";
9
+ import { BadRequest, Forbidden, MethodNotAllowed, TooManyRequests } from "@feathersjs/errors";
9
10
  import _get from "lodash/get.js";
10
11
  import _has from "lodash/has.js";
11
12
  import _omit from "lodash/omit.js";
12
13
  import _set from "lodash/set.js";
13
14
  import _setWith from "lodash/setWith.js";
14
15
  import _clone from "lodash/clone.js";
15
-
16
16
  //#region src/hooks/cache/cache-utils.ts
17
17
  const stableStringify = (obj) => {
18
18
  if (obj.query) obj = {
@@ -28,7 +28,6 @@ const stableStringify = (obj) => {
28
28
  return value;
29
29
  });
30
30
  };
31
-
32
31
  //#endregion
33
32
  //#region src/hooks/cache/cache.hook.ts
34
33
  /**
@@ -69,12 +68,10 @@ const cacheBefore = async (context, cacheMap) => {
69
68
  const value = await cacheMap.get(context);
70
69
  if (value) context.result = value;
71
70
  }
72
- return context;
73
71
  };
74
72
  const cacheAfter = async (context, cacheMap) => {
75
73
  if (context.method === "get" || context.method === "find") await cacheMap.set(context);
76
74
  else await cacheMap.clear(context);
77
- return context;
78
75
  };
79
76
  var ContextCacheMap = class {
80
77
  map;
@@ -175,7 +172,6 @@ var ContextCacheMap = class {
175
172
  return context;
176
173
  }
177
174
  };
178
-
179
175
  //#endregion
180
176
  //#region src/hooks/check-multi/check-multi.hook.ts
181
177
  /**
@@ -195,15 +191,16 @@ var ContextCacheMap = class {
195
191
  * @see https://utils.feathersjs.com/hooks/check-multi.html
196
192
  */
197
193
  function checkMulti(options) {
198
- return (context, next) => {
194
+ function hook(context, next) {
199
195
  const { service, method } = context;
200
- if (!service.allowsMulti || !isMulti(context) || method === "find") return context;
201
- if (!service.allowsMulti(method)) throw options?.error ? options.error(context) : new MethodNotAllowed(`Can not ${method} multiple entries`);
202
- if (next) return next();
203
- return context;
204
- };
196
+ if (!service.allowsMulti || !isMulti(context) || method === "find" || service.allowsMulti(method)) {
197
+ if (next) return next();
198
+ return;
199
+ }
200
+ throw options?.error ? options.error(context) : new MethodNotAllowed(`Can not ${method} multiple entries`);
201
+ }
202
+ return hook;
205
203
  }
206
-
207
204
  //#endregion
208
205
  //#region src/hooks/check-required/check-required.hook.ts
209
206
  /**
@@ -224,12 +221,16 @@ function checkMulti(options) {
224
221
  */
225
222
  function checkRequired(fieldNames) {
226
223
  const fieldNamesArray = toArray(fieldNames);
227
- return (context, next) => {
228
- checkContext(context, ["before", "around"], [
229
- "create",
230
- "update",
231
- "patch"
232
- ], "checkRequired");
224
+ function hook(context, next) {
225
+ checkContext(context, {
226
+ type: ["before", "around"],
227
+ method: [
228
+ "create",
229
+ "update",
230
+ "patch"
231
+ ],
232
+ label: "checkRequired"
233
+ });
233
234
  const { data } = getDataIsArray(context);
234
235
  for (let i = 0; i < data.length; i++) {
235
236
  const item = data[i];
@@ -241,9 +242,9 @@ function checkRequired(fieldNames) {
241
242
  }
242
243
  }
243
244
  if (next) return next();
244
- };
245
+ }
246
+ return hook;
245
247
  }
246
-
247
248
  //#endregion
248
249
  //#region src/hooks/create-related/create-related.hook.ts
249
250
  /**
@@ -266,20 +267,23 @@ function checkRequired(fieldNames) {
266
267
  */
267
268
  function createRelated(options) {
268
269
  return async (context, next) => {
269
- checkContext(context, ["after", "around"], ["create"], "createRelated");
270
+ checkContext(context, {
271
+ type: ["after", "around"],
272
+ method: ["create"],
273
+ label: "createRelated"
274
+ });
270
275
  if (next) await next();
271
276
  const { result } = getResultIsArray(context);
272
277
  const entries = Array.isArray(options) ? options : [options];
273
278
  await Promise.all(entries.map(async (entry) => {
274
279
  const { data, service, multi } = entry;
275
280
  const dataToCreate = (await Promise.all(result.map(async (item) => data(item, context)))).flat().filter((x) => !!x);
276
- if (!dataToCreate || dataToCreate.length <= 0) return context;
281
+ if (!dataToCreate || dataToCreate.length <= 0) return;
277
282
  if (multi || dataToCreate.length === 1) await context.app.service(service).create(dataToCreate.length === 1 ? dataToCreate[0] : dataToCreate);
278
283
  else await Promise.all(dataToCreate.map(async (item) => context.app.service(service).create(item)));
279
284
  }));
280
285
  };
281
286
  }
282
-
283
287
  //#endregion
284
288
  //#region src/hooks/debug/debug.hook.ts
285
289
  /**
@@ -315,7 +319,6 @@ const debug = (msg, ...fieldNames) => async (context, next) => {
315
319
  });
316
320
  if (context.error) console.log("error", context.error);
317
321
  };
318
-
319
322
  //#endregion
320
323
  //#region src/hooks/disable-pagination/disable-pagination.hook.ts
321
324
  /**
@@ -335,17 +338,22 @@ const debug = (msg, ...fieldNames) => async (context, next) => {
335
338
  *
336
339
  * @see https://utils.feathersjs.com/hooks/disable-pagination.html
337
340
  */
338
- const disablePagination = () => (context, next) => {
339
- checkContext(context, ["before", "around"], ["find"], "disablePagination");
340
- const $limit = context.params?.query?.$limit;
341
- if ($limit === "-1" || $limit === -1) {
342
- context.params.paginate = false;
343
- delete context.params.query.$limit;
341
+ const disablePagination = () => {
342
+ function hook(context, next) {
343
+ checkContext(context, {
344
+ type: ["before", "around"],
345
+ method: ["find"],
346
+ label: "disablePagination"
347
+ });
348
+ const $limit = context.params?.query?.$limit;
349
+ if ($limit === "-1" || $limit === -1) {
350
+ context.params.paginate = false;
351
+ delete context.params.query.$limit;
352
+ }
353
+ if (next) return next();
344
354
  }
345
- if (next) return next();
346
- return context;
355
+ return hook;
347
356
  };
348
-
349
357
  //#endregion
350
358
  //#region src/hooks/disallow/disallow.hook.ts
351
359
  /**
@@ -369,19 +377,23 @@ const disablePagination = () => (context, next) => {
369
377
  */
370
378
  const disallow = (transports) => {
371
379
  const transportsArr = toArray(transports);
372
- return (context, next) => {
380
+ function hook(context, next) {
373
381
  if (!transports) throw new MethodNotAllowed("Method not allowed");
374
- if (isProvider(...transportsArr)(context)) throw new MethodNotAllowed(`Provider '${context.params.provider}' can not call '${context.method}'. (disallow)`);
375
- if (next) return next().then(() => context);
376
- };
382
+ if (isProvider(...transportsArr)(context)) throw new MethodNotAllowed(`Provider '${context.params.provider}' can not call '${context.method}' on '${context.path}'. (disallow)`);
383
+ if (next) return next();
384
+ }
385
+ return hook;
377
386
  };
378
-
379
387
  //#endregion
380
388
  //#region src/hooks/on-delete/on-delete.hook.ts
381
389
  const onDelete = (options) => {
382
390
  const optionsMulti = Array.isArray(options) ? options : [options];
383
391
  return async (context, next) => {
384
- checkContext(context, ["after", "around"], "remove", "onDelete");
392
+ checkContext(context, {
393
+ type: ["after", "around"],
394
+ method: "remove",
395
+ label: "onDelete"
396
+ });
385
397
  if (next) await next();
386
398
  const { result } = getResultIsArray(context);
387
399
  if (!result.length) return;
@@ -389,7 +401,7 @@ const onDelete = (options) => {
389
401
  optionsMulti.forEach(async ({ keyHere, keyThere, onDelete, service, blocking, query }) => {
390
402
  let ids = result.map((x) => x[keyHere]).filter((x) => !!x);
391
403
  ids = [...new Set(ids)];
392
- if (!ids || ids.length <= 0) return context;
404
+ if (!ids || ids.length <= 0) return;
393
405
  const params = {
394
406
  query: {
395
407
  ...query,
@@ -408,11 +420,9 @@ const onDelete = (options) => {
408
420
  if (promises.length) await Promise.all(promises);
409
421
  };
410
422
  };
411
-
412
423
  //#endregion
413
424
  //#region src/hooks/params-for-server/params-for-from-shared.ts
414
425
  const FROM_CLIENT_FOR_SERVER_DEFAULT_KEY = "_$client";
415
-
416
426
  //#endregion
417
427
  //#region src/hooks/params-for-server/params-for-server.hook.ts
418
428
  /**
@@ -435,7 +445,7 @@ const FROM_CLIENT_FOR_SERVER_DEFAULT_KEY = "_$client";
435
445
  const paramsForServer = (whitelist, options) => {
436
446
  const whitelistArr = toArray(whitelist);
437
447
  const { keyToHide = FROM_CLIENT_FOR_SERVER_DEFAULT_KEY } = options || {};
438
- return (context, next) => {
448
+ function hook(context, next) {
439
449
  let clonedParams;
440
450
  Object.keys(context.params).forEach((key) => {
441
451
  if (key === "query") return;
@@ -451,10 +461,9 @@ const paramsForServer = (whitelist, options) => {
451
461
  });
452
462
  if (clonedParams) context.params = clonedParams;
453
463
  if (next) return next();
454
- return context;
455
- };
464
+ }
465
+ return hook;
456
466
  };
457
-
458
467
  //#endregion
459
468
  //#region src/hooks/params-from-client/params-from-client.hook.ts
460
469
  /**
@@ -477,8 +486,11 @@ const paramsForServer = (whitelist, options) => {
477
486
  const paramsFromClient = (whitelist, options) => {
478
487
  const whitelistArr = toArray(whitelist);
479
488
  const { keyToHide = FROM_CLIENT_FOR_SERVER_DEFAULT_KEY } = options || {};
480
- return (context, next) => {
481
- if (!context.params?.query?.[keyToHide] || typeof context.params.query[keyToHide] !== "object") return context;
489
+ function hook(context, next) {
490
+ if (!context.params?.query?.[keyToHide] || typeof context.params.query[keyToHide] !== "object") {
491
+ if (next) return next();
492
+ return;
493
+ }
482
494
  const params = {
483
495
  ...context.params,
484
496
  query: {
@@ -496,10 +508,9 @@ const paramsFromClient = (whitelist, options) => {
496
508
  if (Object.keys(client).length === 0) delete params.query[keyToHide];
497
509
  context.params = params;
498
510
  if (next) return next();
499
- return context;
500
- };
511
+ }
512
+ return hook;
501
513
  };
502
-
503
514
  //#endregion
504
515
  //#region src/hooks/prevent-changes/prevent-changes.hook.ts
505
516
  /**
@@ -531,7 +542,47 @@ const preventChanges = (fieldNames, options) => {
531
542
  return item;
532
543
  });
533
544
  };
534
-
545
+ //#endregion
546
+ //#region src/hooks/rate-limit/rate-limit.hook.ts
547
+ /**
548
+ * Rate limits service method calls using `rate-limiter-flexible`.
549
+ * You provide a pre-configured `RateLimiterAbstract` instance
550
+ * (Memory, Redis, Mongo, etc.) and the hook consumes points per request.
551
+ *
552
+ * @example
553
+ * ```ts
554
+ * import { rateLimit } from 'feathers-utils/hooks'
555
+ * import { RateLimiterMemory } from 'rate-limiter-flexible'
556
+ *
557
+ * const rateLimiter = new RateLimiterMemory({ points: 10, duration: 1 })
558
+ *
559
+ * app.service('users').hooks({
560
+ * before: { find: [rateLimit(rateLimiter)] }
561
+ * })
562
+ * ```
563
+ *
564
+ * @see https://utils.feathersjs.com/hooks/rate-limit.html
565
+ */
566
+ const rateLimit = (rateLimiter, options) => {
567
+ const key = options?.key ?? ((context) => context.path);
568
+ const points = options?.points ?? (() => 1);
569
+ return async (context, next) => {
570
+ checkContext(context, {
571
+ type: ["before", "around"],
572
+ label: "rateLimit"
573
+ });
574
+ const resolvedKey = await key(context);
575
+ const resolvedPoints = await points(context);
576
+ try {
577
+ const res = await rateLimiter.consume(resolvedKey, resolvedPoints);
578
+ context.params.rateLimit = res;
579
+ } catch (res) {
580
+ context.params.rateLimit = res;
581
+ throw new TooManyRequests("Too many requests", { rateLimitRes: res });
582
+ }
583
+ if (next) await next();
584
+ };
585
+ };
535
586
  //#endregion
536
587
  //#region src/hooks/set-data/set-data.hook.ts
537
588
  /**
@@ -552,12 +603,18 @@ const preventChanges = (fieldNames, options) => {
552
603
  */
553
604
  function setData(from, to, options) {
554
605
  const { allowUndefined = false, overwrite = true } = options ?? {};
555
- return (context, next) => {
606
+ function hook(context, next) {
556
607
  const { data } = getDataIsArray(context);
557
608
  const contextJson = contextToJson(context);
558
609
  if (!_has(contextJson, from)) {
559
- if (!context.params?.provider || allowUndefined === true) return context;
560
- if (!overwrite && data.every((item) => _has(item, to))) return context;
610
+ if (!context.params?.provider || allowUndefined === true) {
611
+ if (next) return next();
612
+ return;
613
+ }
614
+ if (!overwrite && data.every((item) => _has(item, to))) {
615
+ if (next) return next();
616
+ return;
617
+ }
561
618
  throw options?.error ? options.error(context, from) : new Forbidden(`Expected field ${from.toString()} not available`);
562
619
  }
563
620
  const val = _get(contextJson, from);
@@ -567,10 +624,9 @@ function setData(from, to, options) {
567
624
  _set(item, to, val);
568
625
  }
569
626
  if (next) return next();
570
- return context;
571
- };
627
+ }
628
+ return hook;
572
629
  }
573
-
574
630
  //#endregion
575
631
  //#region src/hooks/set-field/set-field.hook.ts
576
632
  /**
@@ -589,19 +645,26 @@ function setData(from, to, options) {
589
645
  *
590
646
  * @see https://utils.feathersjs.com/hooks/set-field.html
591
647
  */
592
- const setField = ({ as, from, allowUndefined = false, error }) => (context, next) => {
593
- const { params } = context;
594
- checkContext(context, ["before", "around"], null, "setField");
595
- const value = _get(context, from);
596
- if (value === void 0) {
597
- if (!params.provider || allowUndefined) return context;
598
- throw error ? error(context, from) : new Forbidden(`Expected field ${as} not available`);
648
+ const setField = ({ as, from, allowUndefined = false, error }) => {
649
+ function hook(context, next) {
650
+ const { params } = context;
651
+ checkContext(context, {
652
+ type: ["before", "around"],
653
+ label: "setField"
654
+ });
655
+ const value = _get(context, from);
656
+ if (value === void 0) {
657
+ if (!params.provider || allowUndefined) {
658
+ if (next) return next();
659
+ return;
660
+ }
661
+ throw error ? error(context, from) : new Forbidden(`Expected field ${as} not available`);
662
+ }
663
+ _setWith(context, as, value, _clone);
664
+ if (next) return next();
599
665
  }
600
- context = _setWith(context, as, value, _clone);
601
- if (next) return next();
602
- return context;
666
+ return hook;
603
667
  };
604
-
605
668
  //#endregion
606
669
  //#region src/hooks/set-result/set-result.hook.ts
607
670
  /**
@@ -645,12 +708,14 @@ function setResult(from, to, options) {
645
708
  }
646
709
  return forResultOrDispatch(context, !!options?.dispatch);
647
710
  };
648
- return (context, next) => {
649
- if (next) next().then(() => fn(context));
650
- return fn(context);
651
- };
711
+ function hook(context, next) {
712
+ if (next) return next().then(() => {
713
+ fn(context);
714
+ });
715
+ fn(context);
716
+ }
717
+ return hook;
652
718
  }
653
-
654
719
  //#endregion
655
720
  //#region src/hooks/set-slug/set-slug.hook.ts
656
721
  /**
@@ -670,17 +735,16 @@ function setResult(from, to, options) {
670
735
  * @see https://utils.feathersjs.com/hooks/set-slug.html
671
736
  */
672
737
  const setSlug = (slug, fieldName) => {
673
- if (typeof fieldName !== "string") fieldName = `query.${slug}`;
674
- return (context, next) => {
738
+ const targetField = typeof fieldName === "string" ? fieldName : `query.${slug}`;
739
+ function hook(context, next) {
675
740
  if (context.params && context.params.provider === "rest") {
676
741
  const value = context.params.route[slug];
677
- if (typeof value === "string" && value[0] !== ":") _set(context.params, fieldName, value);
742
+ if (typeof value === "string" && value[0] !== ":") _set(context.params, targetField, value);
678
743
  }
679
744
  if (next) return next();
680
- return context;
681
- };
745
+ }
746
+ return hook;
682
747
  };
683
-
684
748
  //#endregion
685
749
  //#region src/hooks/soft-delete/soft-delete.hook.ts
686
750
  /**
@@ -704,9 +768,15 @@ const setSlug = (slug, fieldName) => {
704
768
  const softDelete = (options) => {
705
769
  if (!options?.deletedQuery || !options?.removeData) throw new Error("You must provide `deletedQuery` and `removeData` options to the softDelete hook.");
706
770
  return async (context, next) => {
707
- checkContext(context, ["before", "around"], null, "softDelete");
771
+ checkContext(context, {
772
+ type: ["before", "around"],
773
+ label: "softDelete"
774
+ });
708
775
  const { disableSoftDeleteKey = "disableSoftDelete" } = options;
709
- if (context.params[disableSoftDeleteKey]) return early(context, next);
776
+ if (context.params[disableSoftDeleteKey]) {
777
+ await early(context, next);
778
+ return;
779
+ }
710
780
  const { deletedQuery, removeData } = options;
711
781
  let deleteQuery = getValue(deletedQuery, context);
712
782
  if (isPromise(deleteQuery)) deleteQuery = await deleteQuery;
@@ -722,15 +792,13 @@ const softDelete = (options) => {
722
792
  const method = options.usePatchWithHooks ? "patch" : "_patch";
723
793
  context.result = await context.service[method](context.id, data, params);
724
794
  }
725
- if (next) return await next();
726
- return context;
795
+ if (next) await next();
727
796
  };
728
797
  };
729
798
  const getValue = (value, ...args) => {
730
799
  if (typeof value === "function") return value(...args);
731
800
  return value;
732
801
  };
733
-
734
802
  //#endregion
735
803
  //#region src/hooks/stashable/stashable.hook.ts
736
804
  const defaultStashFunc = (context) => {
@@ -765,23 +833,26 @@ const defaultStashFunc = (context) => {
765
833
  function stashable(options) {
766
834
  const propName = options?.propName ?? "stashed";
767
835
  const stashFunc = options?.stashFunc ?? defaultStashFunc;
768
- return ((context, next) => {
836
+ function hook(context, next) {
769
837
  if (context.params._stashable) {
770
838
  if (next) return next();
771
- return context;
839
+ return;
772
840
  }
773
- checkContext(context, ["before", "around"], [
774
- "update",
775
- "patch",
776
- "remove"
777
- ], "stashable");
841
+ checkContext(context, {
842
+ type: ["before", "around"],
843
+ method: [
844
+ "update",
845
+ "patch",
846
+ "remove"
847
+ ],
848
+ label: "stashable"
849
+ });
778
850
  const promise = stashFunc(context).catch(() => void 0);
779
851
  context.params[propName] = () => promise;
780
852
  if (next) return next();
781
- return context;
782
- });
853
+ }
854
+ return hook;
783
855
  }
784
-
785
856
  //#endregion
786
857
  //#region src/hooks/throw-if-is-multi/throw-if-is-multi.hook.ts
787
858
  const defaultError$1 = (context) => new BadRequest(`Cannot perform multi operation on method '${context.method}'`);
@@ -802,7 +873,6 @@ const defaultError$1 = (context) => new BadRequest(`Cannot perform multi operati
802
873
  * @see https://utils.feathersjs.com/hooks/throw-if-is-multi.html
803
874
  */
804
875
  const throwIfIsMulti = (options) => throwIf(every(every(isMulti, (context) => context.method !== "find"), options?.filter), { error: options?.error ?? defaultError$1 });
805
-
806
876
  //#endregion
807
877
  //#region src/hooks/throw-if-is-provider/throw-if-is-provider.hook.ts
808
878
  const defaultError = (context) => new MethodNotAllowed(`Provider '${context.params.provider}' can not call '${context.method}'.`);
@@ -825,7 +895,6 @@ const defaultError = (context) => new MethodNotAllowed(`Provider '${context.para
825
895
  const throwIfIsProvider = (transports, options) => {
826
896
  return throwIf(every(isProvider(...toArray(transports)), options?.filter), { error: options?.error ?? defaultError });
827
897
  };
828
-
829
898
  //#endregion
830
899
  //#region src/hooks/traverse/traverse.hook.ts
831
900
  /**
@@ -846,12 +915,14 @@ const throwIfIsProvider = (transports, options) => {
846
915
  *
847
916
  * @see https://utils.feathersjs.com/hooks/traverse.html
848
917
  */
849
- const traverse = ({ transformer, getObject }) => (context, next) => {
850
- traverse$1(getObject(context), transformer);
851
- if (next) return next();
852
- return context;
918
+ const traverse = ({ transformer, getObject }) => {
919
+ function hook(context, next) {
920
+ traverse$1(getObject(context), transformer);
921
+ if (next) return next();
922
+ }
923
+ return hook;
853
924
  };
854
-
855
925
  //#endregion
856
- export { createRelated as _, softDelete as a, cache as b, setField as c, paramsFromClient as d, paramsForServer as f, debug as g, disablePagination as h, stashable as i, setData as l, disallow as m, throwIfIsProvider as n, setSlug as o, onDelete as p, throwIfIsMulti as r, setResult as s, traverse as t, preventChanges as u, checkRequired as v, checkMulti as y };
857
- //# sourceMappingURL=traverse.hook-C2VIvQrn.mjs.map
926
+ export { debug as _, softDelete as a, checkMulti as b, setField as c, preventChanges as d, paramsFromClient as f, disablePagination as g, disallow as h, stashable as i, setData as l, onDelete as m, throwIfIsProvider as n, setSlug as o, paramsForServer as p, throwIfIsMulti as r, setResult as s, traverse as t, rateLimit as u, createRelated as v, cache as x, checkRequired as y };
927
+
928
+ //# sourceMappingURL=hooks-CzxNpt2c.mjs.map