feathers-utils 10.2.0 → 10.3.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 (41) hide show
  1. package/dist/{hooks-tfw03iVM.mjs → hooks-DpFQfcFa.mjs} +65 -65
  2. package/dist/{hooks-tfw03iVM.mjs.map → hooks-DpFQfcFa.mjs.map} +1 -1
  3. package/dist/hooks.d.mts +48 -48
  4. package/dist/hooks.mjs +4 -4
  5. package/dist/{index-CKAzIogj.d.mts → index-C6MN6wag.d.mts} +162 -105
  6. package/dist/index.d.mts +2 -2
  7. package/dist/index.mjs +7 -7
  8. package/dist/{internal.utils-BMzV_-xp.mjs → internal.utils-BBB-b6Ud.mjs} +16 -2
  9. package/dist/internal.utils-BBB-b6Ud.mjs.map +1 -0
  10. package/dist/{mutate-result.util-Dqzepn1M.mjs → mutate-result.util-C0nY6L7i.mjs} +2 -2
  11. package/dist/{mutate-result.util-Dqzepn1M.mjs.map → mutate-result.util-C0nY6L7i.mjs.map} +1 -1
  12. package/dist/{predicates-puYa4nkf.mjs → predicates-NOnUyMic.mjs} +53 -53
  13. package/dist/{predicates-puYa4nkf.mjs.map → predicates-NOnUyMic.mjs.map} +1 -1
  14. package/dist/predicates.d.mts +18 -18
  15. package/dist/predicates.mjs +1 -1
  16. package/dist/{resolve-B9hRleHY.mjs → resolve-BflgIVD8.mjs} +2 -2
  17. package/dist/{resolve-B9hRleHY.mjs.map → resolve-BflgIVD8.mjs.map} +1 -1
  18. package/dist/resolvers.mjs +1 -1
  19. package/dist/{transform-result.hook-B65pTRJO.mjs → transform-result.hook-V2QYN2K0.mjs} +2 -2
  20. package/dist/{transform-result.hook-B65pTRJO.mjs.map → transform-result.hook-V2QYN2K0.mjs.map} +1 -1
  21. package/dist/transformers.mjs +3 -3
  22. package/dist/{utils-BAIcSl7u.mjs → utils-DByCpAsf.mjs} +386 -209
  23. package/dist/utils-DByCpAsf.mjs.map +1 -0
  24. package/dist/utils.d.mts +2 -2
  25. package/dist/utils.mjs +4 -4
  26. package/package.json +1 -1
  27. package/src/common/index.ts +1 -0
  28. package/src/common/is-empty-object.ts +38 -0
  29. package/src/hooks/index.ts +1 -1
  30. package/src/predicates/index.ts +3 -3
  31. package/src/utils/add-to-query/add-to-query.util.ts +19 -1
  32. package/src/utils/index.ts +5 -4
  33. package/src/utils/merge-query/dedupe-branches.ts +42 -0
  34. package/src/utils/merge-query/extract-query-filters.ts +80 -0
  35. package/src/utils/merge-query/has-conflict.ts +39 -0
  36. package/src/utils/merge-query/logical-branches.ts +39 -0
  37. package/src/utils/merge-query/merge-query-bodies.ts +136 -0
  38. package/src/utils/merge-query/merge-query.util.ts +102 -0
  39. package/src/utils/merge-query/merge-select.ts +64 -0
  40. package/dist/internal.utils-BMzV_-xp.mjs.map +0 -1
  41. package/dist/utils-BAIcSl7u.mjs.map +0 -1
@@ -0,0 +1,136 @@
1
+ import type { MergeQueryMode } from './merge-query.util.js'
2
+ import { isEmptyObject } from '../../common/is-empty-object.js'
3
+ import { logicalBranches } from './logical-branches.js'
4
+ import { dedupeBranches } from './dedupe-branches.js'
5
+ import { hasConflict } from './has-conflict.js'
6
+
7
+ type QueryRecord = Record<string, any>
8
+
9
+ /**
10
+ * Merges two query bodies (filters already removed) according to the mode.
11
+ * Internal helper for {@link mergeQuery}.
12
+ *
13
+ * - `target` / `source`: precedence merge (that side wins on conflict).
14
+ * - `combine`: the two bodies always become branches of a single `$or`.
15
+ * - `intersect`: non-conflicting bodies merge flat; on conflict they become
16
+ * branches of a single `$and`.
17
+ *
18
+ * Logical-only bodies (`{ $or: [...] }` for combine, `{ $and: [...] }` for
19
+ * intersect) are flattened into the result and their branches de-duplicated.
20
+ */
21
+ export function mergeQueryBodies(
22
+ target: QueryRecord,
23
+ source: QueryRecord,
24
+ mode: MergeQueryMode,
25
+ ): QueryRecord {
26
+ if (mode === 'target') {
27
+ return { ...source, ...target }
28
+ }
29
+ if (mode === 'source') {
30
+ return { ...target, ...source }
31
+ }
32
+
33
+ if (isEmptyObject(target)) {
34
+ return { ...source }
35
+ }
36
+ if (isEmptyObject(source)) {
37
+ return { ...target }
38
+ }
39
+
40
+ const op = mode === 'combine' ? '$or' : '$and'
41
+
42
+ const targetBranches = logicalBranches(target, op)
43
+ const sourceBranches = logicalBranches(source, op)
44
+
45
+ // For intersect (AND) the top level is itself an implicit AND, so two
46
+ // conflict-free bodies can be merged flat. For combine (OR) there is no flat
47
+ // representation — combine always produces an `$or`.
48
+ if (
49
+ op === '$and' &&
50
+ !targetBranches &&
51
+ !sourceBranches &&
52
+ !hasConflict(target, source)
53
+ ) {
54
+ return { ...target, ...source }
55
+ }
56
+
57
+ const branches = dedupeBranches([
58
+ ...(targetBranches ?? [target]),
59
+ ...(sourceBranches ?? [source]),
60
+ ])
61
+
62
+ if (branches.length === 0) {
63
+ return {}
64
+ }
65
+ if (branches.length === 1) {
66
+ return { ...branches[0] }
67
+ }
68
+ return { [op]: branches }
69
+ }
70
+
71
+ if (import.meta.vitest) {
72
+ const { describe, it, expect } = import.meta.vitest
73
+
74
+ describe('mergeQueryBodies', () => {
75
+ it('target / source precedence', () => {
76
+ expect(mergeQueryBodies({ id: 1 }, { id: 2, a: 3 }, 'target')).toEqual({
77
+ id: 1,
78
+ a: 3,
79
+ })
80
+ expect(mergeQueryBodies({ id: 1 }, { id: 2, a: 3 }, 'source')).toEqual({
81
+ id: 2,
82
+ a: 3,
83
+ })
84
+ })
85
+
86
+ it('returns the other side when one is empty', () => {
87
+ expect(mergeQueryBodies({}, { id: 1 }, 'combine')).toEqual({ id: 1 })
88
+ expect(mergeQueryBodies({ id: 1 }, {}, 'intersect')).toEqual({ id: 1 })
89
+ })
90
+
91
+ it('combine always produces an $or, even for disjoint keys', () => {
92
+ expect(mergeQueryBodies({ a: 1 }, { b: 2 }, 'combine')).toEqual({
93
+ $or: [{ a: 1 }, { b: 2 }],
94
+ })
95
+ })
96
+
97
+ it('combine flattens and dedupes $or branches', () => {
98
+ expect(
99
+ mergeQueryBodies(
100
+ { $or: [{ id: 1 }, { id: 2 }] },
101
+ { $or: [{ id: 2 }, { id: 3 }] },
102
+ 'combine',
103
+ ),
104
+ ).toEqual({ $or: [{ id: 1 }, { id: 2 }, { id: 3 }] })
105
+ })
106
+
107
+ it('combine collapses to a single body', () => {
108
+ expect(mergeQueryBodies({ id: 1 }, { id: 1 }, 'combine')).toEqual({
109
+ id: 1,
110
+ })
111
+ })
112
+
113
+ it('intersect merges disjoint keys flat', () => {
114
+ expect(mergeQueryBodies({ id: 1 }, { userId: 2 }, 'intersect')).toEqual({
115
+ id: 1,
116
+ userId: 2,
117
+ })
118
+ })
119
+
120
+ it('intersect wraps conflicts in $and', () => {
121
+ expect(mergeQueryBodies({ id: 1 }, { id: 2 }, 'intersect')).toEqual({
122
+ $and: [{ id: 1 }, { id: 2 }],
123
+ })
124
+ })
125
+
126
+ it('intersect flattens $and branches', () => {
127
+ expect(
128
+ mergeQueryBodies(
129
+ { $and: [{ id: 1 }, { id: 2 }] },
130
+ { $and: [{ id: 3 }] },
131
+ 'intersect',
132
+ ),
133
+ ).toEqual({ $and: [{ id: 1 }, { id: 2 }, { id: 3 }] })
134
+ })
135
+ })
136
+ }
@@ -0,0 +1,102 @@
1
+ import type { Query } from '@feathersjs/feathers'
2
+ import { extractQueryFilters } from './extract-query-filters.js'
3
+ import { mergeQueryBodies } from './merge-query-bodies.js'
4
+ import { mergeSelect } from './merge-select.js'
5
+
6
+ export type MergeQueryMode = 'target' | 'source' | 'combine' | 'intersect'
7
+
8
+ export interface MergeQueryOptions {
9
+ /**
10
+ * How to merge query properties that both queries constrain.
11
+ *
12
+ * - `combine` (default): broaden — the two queries always become branches of an `$or`.
13
+ * - `intersect`: narrow — non-conflicting properties merge flat, conflicts become an `$and`.
14
+ * - `target`: keep the target's value on conflict.
15
+ * - `source`: keep the source's value on conflict.
16
+ */
17
+ mode?: MergeQueryMode
18
+ }
19
+
20
+ /**
21
+ * Properties are combined with a logical operator rather than merged at the value
22
+ * level, so the result is always a valid query: `combine` always wraps the two
23
+ * queries in `$or` (broaden — OR has no flat form), while `intersect` merges
24
+ * non-conflicting properties flat and wraps conflicts in `$and` (narrow). The
25
+ * special filters `$select`, `$limit`, `$skip` and `$sort` are merged separately.
26
+ * Inputs are never mutated.
27
+ *
28
+ * This is well suited to merging a client-provided query with a server-side
29
+ * restriction inside a hook.
30
+ *
31
+ * @param target Query to be merged into
32
+ * @param source Query to be merged from
33
+ * @param options
34
+ * @returns the merged query
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { mergeQuery } from 'feathers-utils/utils'
39
+ *
40
+ * // combine (default): the two queries always become an $or
41
+ * mergeQuery({ id: 1 }, { id: 2 })
42
+ * // => { $or: [{ id: 1 }, { id: 2 }] }
43
+ *
44
+ * mergeQuery({ status: 'active' }, { authorId: 5 })
45
+ * // => { $or: [{ status: 'active' }, { authorId: 5 }] }
46
+ * ```
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * // intersect: non-conflicting properties merge flat, conflicts become an $and
51
+ * mergeQuery({ status: 'active' }, { authorId: 5 }, { mode: 'intersect' })
52
+ * // => { status: 'active', authorId: 5 }
53
+ *
54
+ * mergeQuery({ id: 1 }, { id: 2 }, { mode: 'intersect' })
55
+ * // => { $and: [{ id: 1 }, { id: 2 }] }
56
+ * ```
57
+ *
58
+ * @see https://utils.feathersjs.com/utils/merge-query.html
59
+ */
60
+ export function mergeQuery(
61
+ target: Query,
62
+ source: Query,
63
+ options?: MergeQueryOptions,
64
+ ): Query {
65
+ const mode = options?.mode ?? 'combine'
66
+
67
+ const targetFilters = extractQueryFilters(target)
68
+ const sourceFilters = extractQueryFilters(source)
69
+
70
+ const result: Query = mergeQueryBodies(
71
+ targetFilters.query,
72
+ sourceFilters.query,
73
+ mode,
74
+ )
75
+
76
+ const $select = mergeSelect(
77
+ targetFilters.$select,
78
+ sourceFilters.$select,
79
+ mode,
80
+ )
81
+ if ($select !== undefined) {
82
+ result.$select = $select
83
+ }
84
+
85
+ if ('$limit' in sourceFilters) {
86
+ result.$limit = sourceFilters.$limit
87
+ } else if ('$limit' in targetFilters) {
88
+ result.$limit = targetFilters.$limit
89
+ }
90
+
91
+ if ('$skip' in sourceFilters) {
92
+ result.$skip = sourceFilters.$skip
93
+ } else if ('$skip' in targetFilters) {
94
+ result.$skip = targetFilters.$skip
95
+ }
96
+
97
+ if ('$sort' in targetFilters || '$sort' in sourceFilters) {
98
+ result.$sort = { ...targetFilters.$sort, ...sourceFilters.$sort }
99
+ }
100
+
101
+ return result
102
+ }
@@ -0,0 +1,64 @@
1
+ import type { MergeQueryMode } from './merge-query.util.js'
2
+
3
+ /**
4
+ * Merges two `$select` filters according to the mode: `combine` → union,
5
+ * `intersect` → intersection, `target`/`source` → that side. When only one side
6
+ * provides a `$select`, that one is used. Internal helper for {@link mergeQuery}.
7
+ */
8
+ export function mergeSelect(
9
+ target: any,
10
+ source: any,
11
+ mode: MergeQueryMode,
12
+ ): any {
13
+ if (target === undefined) {
14
+ return source
15
+ }
16
+ if (source === undefined) {
17
+ return target
18
+ }
19
+ if (mode === 'target') {
20
+ return target
21
+ }
22
+ if (mode === 'source') {
23
+ return source
24
+ }
25
+ const targetArr = Array.isArray(target) ? target : [target]
26
+ const sourceArr = Array.isArray(source) ? source : [source]
27
+ if (mode === 'combine') {
28
+ return [...new Set([...targetArr, ...sourceArr])]
29
+ }
30
+ // intersect
31
+ return targetArr.filter((value) => sourceArr.includes(value))
32
+ }
33
+
34
+ if (import.meta.vitest) {
35
+ const { describe, it, expect } = import.meta.vitest
36
+
37
+ describe('mergeSelect', () => {
38
+ it('returns the defined side when one is missing', () => {
39
+ expect(mergeSelect(undefined, ['a'], 'combine')).toEqual(['a'])
40
+ expect(mergeSelect(['a'], undefined, 'combine')).toEqual(['a'])
41
+ })
42
+
43
+ it('unions on combine', () => {
44
+ expect(mergeSelect(['a', 'b'], ['b', 'c'], 'combine')).toEqual([
45
+ 'a',
46
+ 'b',
47
+ 'c',
48
+ ])
49
+ })
50
+
51
+ it('intersects on intersect', () => {
52
+ expect(mergeSelect(['a', 'b'], ['b', 'c'], 'intersect')).toEqual(['b'])
53
+ })
54
+
55
+ it('can produce an empty intersection', () => {
56
+ expect(mergeSelect(['a'], ['b'], 'intersect')).toEqual([])
57
+ })
58
+
59
+ it('picks the requested side on target / source', () => {
60
+ expect(mergeSelect(['a'], ['b'], 'target')).toEqual(['a'])
61
+ expect(mergeSelect(['a'], ['b'], 'source')).toEqual(['b'])
62
+ })
63
+ })
64
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"internal.utils-BMzV_-xp.mjs","names":[],"sources":["../src/common/traverse.ts","../src/common/index.ts","../src/internal.utils.ts"],"sourcesContent":["import _traverse from 'neotraverse'\n\n/**\n * Recursively traverses items (or an array of items) and applies a converter function\n * to every node using `neotraverse`. Modifications happen in place.\n *\n * @example\n * ```ts\n * traverse(items, function () { if (this.key === 'secret') this.remove() })\n * ```\n */\nexport function traverse<T extends Record<string, any>>(\n items: T | T[],\n converter: (item: T) => void,\n) {\n ;(Array.isArray(items) ? items : [items]).forEach((item) => {\n _traverse(item).forEach(converter) // replacement is in place\n })\n}\n","/**\n * Type guard that checks if a value is a `Promise` instance.\n *\n * @example\n * ```ts\n * const result = maybeSyncFn()\n * if (isPromise(result)) {\n * await result\n * }\n * ```\n */\nexport function isPromise(p: any): p is Promise<any> {\n return p instanceof Promise\n}\n\nexport { traverse } from './traverse.js'\nexport { clone } from './clone.js'\n","import type { HookContext } from '@feathersjs/feathers'\n\nexport const hasOwnProperty = (\n obj: Record<string, unknown>,\n ...keys: string[]\n): boolean => {\n return keys.some((x) => Object.prototype.hasOwnProperty.call(obj, x))\n}\n\nexport type MaybeArray<T> = T | readonly T[]\nexport type UnpackMaybeArray<T> = T extends readonly (infer E)[] ? E : T\n/**\n * Normalizes a value or array into an array. The returned array MUST be treated\n * as read-only — when the input is already an array it is returned as-is (no copy)\n * to avoid a per-call allocation on hook hot paths.\n */\nexport const toArray = <T>(value: T | readonly T[]): T[] =>\n Array.isArray(value) ? (value as T[]) : [value as T]\n\nexport type Promisable<T> = T | Promise<T>\nexport type KeyOf<T> = Extract<keyof T, string>\n\nexport type UnwrapArray<T> = T extends Array<infer U> ? U : T\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false\n\nexport type AnyFallback<T, Fallback> = IsAny<T> extends true ? Fallback : T\n\nexport type NeverFallback<Never, Fallback> = [Never] extends [never]\n ? Fallback\n : Never\n\nexport type KeyOfOrDotNotation<D> = KeyOf<D> | `${KeyOf<D>}.${string}`\n\n/**+\n * Can be used to early return a hook.\n *\n * If it's an around hook, it will call `next` if provided.\n */\nexport const early = <H extends HookContext>(\n context: H,\n next?: (context: H) => Promisable<void>,\n): Promisable<void> => {\n if (next) {\n return next(context)\n }\n return\n}\n"],"mappings":";;;;;;;;;;;AAWA,SAAgB,SACd,OACA,WACA;CACC,CAAC,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK,EAAA,CAAG,SAAS,SAAS;EAC1D,UAAU,IAAI,CAAC,CAAC,QAAQ,SAAS;CACnC,CAAC;AACH;;;;;;;;;;;;;;ACPA,SAAgB,UAAU,GAA2B;CACnD,OAAO,aAAa;AACtB;;;ACXA,MAAa,kBACX,KACA,GAAG,SACS;CACZ,OAAO,KAAK,MAAM,MAAM,OAAO,UAAU,eAAe,KAAK,KAAK,CAAC,CAAC;AACtE;;;;;;AASA,MAAa,WAAc,UACzB,MAAM,QAAQ,KAAK,IAAK,QAAgB,CAAC,KAAU;;;;;;AAsBrD,MAAa,SACX,SACA,SACqB;CACrB,IAAI,MACF,OAAO,KAAK,OAAO;AAGvB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils-BAIcSl7u.mjs","names":["deepEqual"],"sources":["../src/utils/sort-query-properties/sort-query-properties.util.ts","../src/utils/add-skip/add-skip.util.ts","../src/utils/chunk-find/chunk-find.util.ts","../src/utils/add-to-query/add-to-query.util.ts","../src/utils/check-context/check-context.util.ts","../src/utils/context-to-json/context-to-json.util.ts","../src/utils/define-hooks/define-hooks.util.ts","../src/feathers-cjs-fix.ts","../src/utils/get-exposed-methods/get-exposed-methods.util.ts","../src/utils/iterate-find/iterate-find.util.ts","../src/utils/patch-batch/patch-batch.util.ts","../src/utils/skip-result/skip-result.util.ts","../src/utils/to-paginated/to-paginated.util.ts","../src/utils/transform-params/transform-params.util.ts","../src/utils/wait-for-service-event/wait-for-service-event.util.ts","../src/utils/walk-query/walk-query.util.ts","../src/utils/query-has-property/query-has-property.util.ts","../src/utils/query-defaults/query-defaults.util.ts","../src/utils/zip-data-result/zip-data-result.util.ts"],"sourcesContent":["import type { Query } from '@feathersjs/feathers'\n\nconst arrayOperators = new Set(['$or', '$and', '$nor', '$not', '$in', '$nin'])\n\nconst isPlainObjectLike = (value: unknown): value is Record<string, any> =>\n value !== null && typeof value === 'object'\n\n/**\n * Recursively normalizes a Feathers query object for order-independent comparison.\n * Sorts object keys and sorts arrays within `$or`, `$and`, `$nor`, `$not`, `$in`,\n * and `$nin` operators so that different orderings produce the same result.\n *\n * This is useful for generating stable cache keys where\n * `{ $or: [{ a: 1 }, { b: 2 }] }` and `{ $or: [{ b: 2 }, { a: 1 }] }`\n * should be treated as equivalent.\n *\n * @example\n * ```ts\n * import { sortQueryProperties } from 'feathers-utils/utils'\n *\n * const normalized = sortQueryProperties({\n * $or: [{ name: 'Jane' }, { name: 'John' }],\n * age: { $in: [30, 25] },\n * })\n * // => { $or: [{ name: 'John' }, { name: 'Jane' }], age: { $in: [25, 30] } }\n * // (sorted by stable stringify comparison)\n * ```\n *\n * @see https://utils.feathersjs.com/utils/sort-query-properties.html\n */\nexport const sortQueryProperties = <Q extends Query>(query: Q): Q => {\n return normalize(query) as Q\n}\n\nconst normalize = (value: any): any => {\n if (Array.isArray(value)) {\n return value.map(normalize)\n }\n\n if (!isPlainObjectLike(value)) {\n return value\n }\n\n const sorted: Record<string, any> = {}\n\n for (const key of Object.keys(value).sort()) {\n const val = value[key]\n\n if (arrayOperators.has(key) && Array.isArray(val)) {\n // Schwartzian transform: serialize each normalized element once, sort by\n // that key, then unwrap. Avoids the O(n log n) repeated JSON.stringify of\n // the previous comparator (which also returned 1 for equal elements).\n sorted[key] = val\n .map((el) => {\n const normalized = normalize(el)\n return { k: JSON.stringify(normalized), v: normalized }\n })\n .sort((a, b) => (a.k < b.k ? -1 : a.k > b.k ? 1 : 0))\n .map((entry) => entry.v)\n } else {\n sorted[key] = normalize(val)\n }\n }\n\n return sorted\n}\n","import type { HookContext, HookType } from '@feathersjs/feathers'\nimport type { MaybeArray } from '../../internal.utils.js'\n\nexport type SkipHookName =\n | 'all'\n | HookType\n | `${HookType}:${string}`\n | (string & {})\n\n/**\n * Adds hook names to `context.params.skipHooks` so that `skippable`-wrapped hooks\n * will be bypassed for the current service call. Accepts a single name or an array.\n * Duplicates are automatically removed.\n *\n * @example\n * ```ts\n * import { addSkip } from 'feathers-utils/utils'\n *\n * // Inside a hook or custom code:\n * addSkip(context, 'myHook')\n * addSkip(context, ['hookA', 'hookB'])\n * ```\n *\n * @see https://utils.feathersjs.com/utils/add-skip.html\n */\nexport const addSkip = <H extends HookContext>(\n context: H,\n hooks: MaybeArray<SkipHookName>,\n) => {\n const names = Array.isArray(hooks) ? hooks : [hooks]\n\n if (context.params.skipHooks === undefined) {\n context.params = {\n ...context.params,\n skipHooks: [...names],\n }\n } else {\n if (!Array.isArray(context.params.skipHooks)) {\n throw new Error('Invalid skipHooks parameter')\n }\n\n context.params = {\n ...context.params,\n skipHooks: [...new Set([...context.params.skipHooks, ...names])],\n }\n }\n}\n","import type { Application, Params } from '@feathersjs/feathers'\nimport type { KeyOf } from '../../internal.utils.js'\nimport type {\n InferFindParams,\n InferFindResultSingle,\n} from '../../utility-types/infer-service-methods.js'\n\ntype PaginateOption = { default?: number; max?: number }\n\ntype ChunkFindOptions<P extends Params = Params> = {\n params?: P & { paginate?: PaginateOption }\n}\n\n/**\n * Use `for await` to iterate over chunks (pages) of results from a `find` method.\n *\n * This function is useful for processing large datasets in batches without loading everything into memory at once.\n * It uses pagination to fetch results in chunks, yielding each page's data array.\n *\n * @example\n * ```ts\n * import { chunkFind } from 'feathers-utils/utils'\n *\n * const app = feathers()\n *\n * // Assuming 'users' service has many records\n * for await (const users of chunkFind(app, 'users', {\n * params: { query: { active: true }, // Custom query parameters\n * } })) {\n * console.log(users) // Process each chunk of user records\n * }\n * ```\n *\n * @see https://utils.feathersjs.com/utils/chunk-find.html\n */\nexport async function* chunkFind<\n Services,\n Path extends KeyOf<Services>,\n Service extends Services[Path] = Services[Path],\n P extends Params = InferFindParams<Service>,\n Item = InferFindResultSingle<Service>,\n>(\n app: Application<Services>,\n servicePath: Path,\n options?: ChunkFindOptions<P>,\n): AsyncGenerator<Item[], void, unknown> {\n const service = app.service(servicePath)\n\n if (!service || !('find' in service)) {\n throw new Error(`Service '${servicePath}' does not have a 'find' method.`)\n }\n\n const params = {\n ...options?.params,\n query: {\n ...(options?.params?.query ?? {}),\n $limit: options?.params?.query?.$limit ?? 10,\n $skip: options?.params?.query?.$skip ?? 0,\n },\n paginate: {\n default: options?.params?.paginate?.default ?? 10,\n max: options?.params?.paginate?.max ?? 100,\n },\n }\n\n let result\n\n do {\n result = await (service as any).find(params)\n\n // Guard against an infinite loop: an empty page never advances $skip, so\n // `total > $skip` could stay true forever (e.g. $limit:0, or a stale total\n // when items are concurrently removed / filtered out by hooks).\n if (!result.data.length) {\n break\n }\n\n yield result.data\n\n params.query.$skip = (params.query.$skip ?? 0) + result.data.length\n } while (result.total > params.query.$skip)\n}\n","import type { Query } from '@feathersjs/feathers'\nimport { dequal as deepEqual } from 'dequal'\n\n/**\n * Safely merges properties into a Feathers query object. If a property already exists\n * with a different value, it wraps both in a `$and` array to preserve both conditions.\n * If the exact same key-value pair already exists, no changes are made.\n *\n * @example\n * ```ts\n * import { addToQuery } from 'feathers-utils/utils'\n *\n * const query = { status: 'active' }\n * addToQuery(query, { role: 'admin' })\n * // => { status: 'active', role: 'admin' }\n * ```\n *\n * @see https://utils.feathersjs.com/utils/add-to-query.html\n */\nexport function addToQuery<Q extends Query>(targetQuery: Q, query: Q): Q {\n targetQuery ??= {} as Q\n\n if (Object.keys(query).length === 0) {\n return targetQuery\n }\n\n const entries = Object.entries(query) as [keyof Q, any][]\n\n if (entries.every(([property]) => !(property in targetQuery))) {\n // if none of the properties exist, merge them directly\n return {\n ...targetQuery,\n ...query,\n }\n }\n\n function isAlreadyInQuery(targetQuery: Q, entries: [keyof Q, any][]) {\n return entries.every(\n ([property, value]) =>\n property in targetQuery && deepEqual(targetQuery[property], value),\n )\n }\n\n if (isAlreadyInQuery(targetQuery, entries)) {\n // if all properties already exist with the exact same value, do nothing\n return targetQuery\n }\n\n if (!targetQuery.$and) {\n return {\n ...targetQuery,\n $and: [{ ...query }],\n }\n }\n\n // check if the exact same value already exists in $and\n if (targetQuery.$and.some((q: any) => isAlreadyInQuery(q, entries))) {\n return targetQuery\n }\n\n return {\n ...targetQuery,\n $and: [...targetQuery.$and, { ...query }],\n }\n}\n","import type { HookContext } from '@feathersjs/feathers'\nimport type { HookType, MethodName } from '../../types.js'\nimport {\n isContext,\n type IsContextOptions,\n} from '../../predicates/is-context/is-context.predicate.js'\nimport type { UnpackMaybeArray } from '../../internal.utils.js'\n\ntype NarrowedContext<H extends HookContext, O> = H &\n (O extends { path: infer P }\n ? [P] extends [undefined | null]\n ? unknown\n : { path: UnpackMaybeArray<P> }\n : unknown) &\n (O extends { type: infer T }\n ? [T] extends [undefined | null]\n ? unknown\n : { type: UnpackMaybeArray<T> }\n : unknown) &\n (O extends { method: infer M }\n ? [M] extends [undefined | null]\n ? unknown\n : { method: UnpackMaybeArray<M> }\n : unknown)\n\nexport type CheckContextOptions<H extends HookContext = HookContext> =\n IsContextOptions<H> & {\n label?: string\n }\n\n/**\n * Validates that the hook context matches the expected type(s) and method(s).\n * Throws an error if the context is invalid, preventing hooks from running in\n * unsupported configurations. Typically used internally by other hooks.\n * Also narrows the context type based on the passed options.\n *\n * @example\n * ```ts\n * import { checkContext } from 'feathers-utils/utils'\n *\n * const myHook = (context) => {\n * checkContext(context, ['before', 'around'], ['create', 'patch'], 'myHook')\n * // or with options object:\n * checkContext(context, { type: ['before', 'around'], method: ['create', 'patch'], label: 'myHook' })\n * // context.type is now 'before' | 'around', context.method is now 'create' | 'patch'\n * }\n * ```\n *\n * @see https://utils.feathersjs.com/utils/check-context.html\n */\nexport function checkContext<\n H extends HookContext,\n const O extends CheckContextOptions<NoInfer<H>>,\n>(context: H, options: O): asserts context is NarrowedContext<H, O>\nexport function checkContext<\n H extends HookContext,\n const T extends HookType | HookType[] | null | undefined = undefined,\n const M extends MethodName | MethodName[] | null | undefined = undefined,\n>(\n context: H,\n type?: T,\n methods?: M,\n label?: string,\n): asserts context is NarrowedContext<H, { type: T; method: M }>\nexport function checkContext<H extends HookContext = HookContext>(\n context: H,\n typeOrOptions?:\n | HookType\n | HookType[]\n | CheckContextOptions<NoInfer<H>>\n | null,\n methods?: MethodName | MethodName[] | null,\n label = 'anonymous',\n): void {\n let options: IsContextOptions\n let hookLabel: string\n\n if (\n typeOrOptions != null &&\n typeof typeOrOptions === 'object' &&\n !Array.isArray(typeOrOptions)\n ) {\n const { label: optLabel, ...rest } = typeOrOptions\n options = rest\n hookLabel = optLabel ?? 'anonymous'\n } else {\n options = {\n method: methods ?? undefined,\n type: typeOrOptions ?? undefined,\n }\n hookLabel = label\n }\n\n if (!isContext(options)(context)) {\n const details: string[] = []\n\n if (options.type != null) {\n details.push(\n `type: expected '${Array.isArray(options.type) ? options.type.join(\"' | '\") : options.type}' but got '${context.type}'`,\n )\n }\n if (options.method != null) {\n details.push(\n `method: expected '${Array.isArray(options.method) ? options.method.join(\"' | '\") : options.method}' but got '${context.method}'`,\n )\n }\n if (options.path != null) {\n details.push(\n `path: expected '${Array.isArray(options.path) ? options.path.join(\"' | '\") : options.path}' but got '${context.path}'`,\n )\n }\n\n throw new Error(\n `The '${hookLabel}' hook has invalid context (${details.join(', ')}).`,\n )\n }\n}\n","import type { HookContext } from '@feathersjs/feathers'\n\n/**\n * Converts a FeathersJS HookContext to a plain JSON object by calling `toJSON()` if available.\n * This is important when using lodash `get`/`has` on the context, since the HookContext\n * class uses getters that may not be enumerable.\n *\n * @example\n * ```ts\n * import { contextToJson } from 'feathers-utils/utils'\n *\n * const json = contextToJson(context)\n * console.log(json)\n * ```\n *\n * @see https://utils.feathersjs.com/utils/context-to-json.html\n */\nexport const contextToJson = (context: HookContext) => {\n if (context.toJSON) {\n return context.toJSON()\n }\n return context\n}\n","import type { Application, HookOptions } from '@feathersjs/feathers'\n\n/**\n * TypeScript helper that provides full type inference and autocompletion when defining\n * service hooks. It is an identity function that simply returns its input,\n * but enables your IDE to infer the correct hook context types.\n *\n * @example\n * ```ts\n * import { defineHooks } from 'feathers-utils/utils'\n *\n * export const userHooks = defineHooks({\n * before: { create: [validateUser()] },\n * after: { all: [sanitizeResult()] }\n * })\n * ```\n *\n * @see https://utils.feathersjs.com/utils/define-hooks.html\n */\nexport function defineHooks<\n A extends Application = Application,\n S = {\n find: any\n get: any\n create: any\n update: any\n patch: any\n remove: any\n },\n Options = HookOptions<A, S>,\n>(hooks: Options): Options {\n return hooks\n}\n","// src/feathers.ts\nimport * as feathers from '@feathersjs/feathers'\n\n// Type-safe re-export of only what you need\nexport const SERVICE = (feathers as any).SERVICE || feathers.default?.SERVICE\n","import type { Service } from '@feathersjs/feathers'\nimport { SERVICE } from '../../feathers-cjs-fix.js'\n\n/**\n * Returns the list of method names that are publicly exposed by a Feathers service.\n * Reads the internal `[SERVICE].methods` property set during service registration.\n * Throws if the service does not have any exposed methods configured.\n *\n * @example\n * ```ts\n * import { getExposedMethods } from 'feathers-utils/utils'\n *\n * const methods = getExposedMethods(app.service('users'))\n * // => ['find', 'get', 'create', 'patch', 'remove']\n * ```\n *\n * @see https://utils.feathersjs.com/utils/get-exposed-methods.html\n */\nexport function getExposedMethods(service: Service) {\n const result = (service as any)[SERVICE].methods\n\n if (!result || !Array.isArray(result)) {\n throw new Error(`Service does not have exposed methods`)\n }\n\n return result\n}\n","import type { Application, Params } from '@feathersjs/feathers'\nimport type { KeyOf } from '../../internal.utils.js'\nimport type {\n InferFindParams,\n InferFindResultSingle,\n} from '../../utility-types/infer-service-methods.js'\n\ntype PaginateOption = { default?: number; max?: number }\n\ntype IterateFindOptions<P extends Params = Params> = {\n params?: P & { paginate?: PaginateOption }\n}\n\n/**\n * Use `for await` to iterate over the results of a `find` method.\n *\n * This function is useful for iterating over large datasets without loading everything into memory at once.\n * It uses pagination to fetch results in chunks, allowing you to process each item as it is retrieved.\n *\n * @example\n * ```ts\n * import { iterateFind } from 'feathers-utils/utils'\n *\n * const app = feathers()\n *\n * // Assuming 'users' service has many records\n * for await (const user of iterateFind(app, 'users', {\n * params: { query: { active: true }, // Custom query parameters\n * } })) {\n * console.log(user) // Process each user record\n * }\n * ```\n *\n * @see https://utils.feathersjs.com/utils/iterate-find.html\n */\nexport async function* iterateFind<\n Services,\n Path extends KeyOf<Services>,\n Service extends Services[Path] = Services[Path],\n P extends Params = InferFindParams<Service>,\n Item = InferFindResultSingle<Service>,\n>(\n app: Application<Services>,\n servicePath: Path,\n options?: IterateFindOptions<P>,\n): AsyncGenerator<Item, void, unknown> {\n const service = app.service(servicePath)\n\n if (!service || !('find' in service)) {\n throw new Error(`Service '${servicePath}' does not have a 'find' method.`)\n }\n\n const params = {\n ...options?.params,\n query: {\n ...(options?.params?.query ?? {}),\n $limit: options?.params?.query?.$limit,\n $skip: options?.params?.query?.$skip ?? 0,\n },\n paginate: {\n default: options?.params?.paginate?.default ?? 10,\n max: options?.params?.paginate?.max ?? 100,\n },\n }\n\n let result\n\n do {\n result = await (service as any).find(params)\n\n // Guard against an infinite loop: an empty page never advances $skip, so\n // `total > $skip` could stay true forever (e.g. $limit:0, or a stale total\n // when items are concurrently removed / filtered out by hooks).\n if (!result.data.length) {\n break\n }\n\n for (const item of result.data) {\n yield item\n }\n\n params.query.$skip = (params.query.$skip ?? 0) + result.data.length\n } while (result.total > params.query.$skip)\n}\n","import type { Id, Params } from '@feathersjs/feathers'\nimport type { KeyOf } from '../../internal.utils.js'\n\n/**\n * Deterministic, key-order-independent serialization used to group items with\n * equal patch data in O(1) per item.\n */\nconst stableKey = (value: any): string =>\n JSON.stringify(value, (_key, val) =>\n val && typeof val === 'object' && !Array.isArray(val)\n ? Object.keys(val)\n .sort()\n .reduce<Record<string, any>>((acc, k) => {\n acc[k] = val[k]\n return acc\n }, {})\n : val,\n )\n\nexport type PatchBatchOptions<IdKey extends string> = {\n /** the key of the id property */\n id?: IdKey\n}\n\nexport type PatchBatchResultItem<T = Record<string, unknown>, P = Params> = [\n Id | null,\n T,\n P | undefined,\n]\n\n/**\n * Batch patching utility that takes an array of items to be changed and returns an array of arguments to be called with the `patch` method.\n *\n * This utility is useful when you need to patch multiple items with varying data in as few requests as possible.\n *\n * @example\n * ```ts\n * const items = [\n * { id: 1, value: 10 },\n * { id: 2, value: 10 },\n * { id: 3, value: 20 },\n * ];\n *\n * const batched = patchBatch(items, { id: 'id' });\n * // batched will be:\n * // [\n * // [null, { value: 10 }, { query: { id: { $in: [1, 2] } } }],\n * // [3, { value: 20 }, undefined],\n * // ]\n *\n * await Promise.all(batched.map(args => service.patch(...args)));\n * ```\n *\n * @see https://utils.feathersjs.com/utils/patch-batch.html\n */\nexport function patchBatch<\n T extends Record<string, any>,\n IdKey extends KeyOf<T>,\n P extends Params,\n R extends Omit<T, IdKey> = Omit<T, IdKey>,\n>(\n items: T[],\n options?: PatchBatchOptions<IdKey>,\n): PatchBatchResultItem<R, P>[] {\n const idKey = options?.id ?? 'id'\n\n // group items with identical (id-stripped) data in O(n) via a Map keyed by a\n // stable serialization, instead of an O(n^2) findIndex + deepEqual scan.\n const groups = new Map<string, { ids: Id[]; data: R }>()\n\n for (const item of items) {\n const source = item as Record<string, any>\n const id = source[idKey] as Id\n // shallow copy then drop the id key, so the caller's input is never mutated.\n const data = { ...source }\n delete data[idKey as any]\n\n const key = stableKey(data)\n const existing = groups.get(key)\n\n if (existing) {\n existing.ids.push(id)\n } else {\n groups.set(key, { ids: [id], data: data as unknown as R })\n }\n }\n\n return [...groups.values()].map(({ ids, data }) => {\n return ids.length === 1\n ? ([ids[0], data, undefined] as PatchBatchResultItem<R, P>)\n : ([\n null,\n data,\n {\n query: {\n [idKey]: { $in: ids },\n },\n },\n ] as PatchBatchResultItem<R, P>)\n })\n}\n","import type { HookContext } from '@feathersjs/feathers'\nimport { isMulti, isPaginated } from '../../predicates/index.js'\n\n/**\n * Sets `context.result` to an appropriate empty value based on the hook method.\n * Returns an empty paginated object for paginated `find`, an empty array for multi\n * operations, or `null` for single-item operations. Does nothing if a result already exists.\n *\n * @example\n * ```ts\n * import { skipResult } from 'feathers-utils/utils'\n *\n * // In a before hook to skip the actual database call:\n * skipResult(context)\n * ```\n *\n * @see https://utils.feathersjs.com/utils/skip-result.html\n */\nexport const skipResult = <H extends HookContext = HookContext>(context: H) => {\n if (context.result) {\n return context\n }\n\n const multi = isMulti(context)\n\n if (multi) {\n if (context.method === 'find' && isPaginated(context)) {\n context.result = {\n total: 0,\n skip: 0,\n limit: 0,\n data: [],\n }\n } else {\n context.result = []\n }\n } else {\n context.result = null\n }\n\n return context\n}\n","import type { Paginated } from '@feathersjs/feathers'\n\n/**\n * Ensures a result is in Feathers paginated format (`{ total, limit, skip, data }`).\n * If the input is already paginated, it is returned as-is. If it is a plain array,\n * it is wrapped in a paginated object with `total` and `limit` set to the array length.\n *\n * @example\n * ```ts\n * import { toPaginated } from 'feathers-utils/utils'\n *\n * const paginated = toPaginated([{ id: 1 }, { id: 2 }])\n * // => { total: 2, limit: 2, skip: 0, data: [{ id: 1 }, { id: 2 }] }\n * ```\n *\n * @see https://utils.feathersjs.com/utils/to-paginated.html\n */\nexport function toPaginated<R>(result: R[] | Paginated<R>): Paginated<R> {\n if (Array.isArray(result)) {\n return {\n total: result.length,\n limit: result.length,\n skip: 0,\n data: result,\n }\n }\n return result\n}\n","import type { Params } from '@feathersjs/feathers'\nimport type { TransformParamsFn } from '../../types.js'\n\n/**\n * Safely applies a `transformParams` function to a params object.\n * If no function is provided, the original params are returned unchanged.\n * The function receives a shallow copy of params, so the original is not mutated.\n *\n * @example\n * ```ts\n * import { transformParams } from 'feathers-utils/utils'\n *\n * const params = transformParams(context.params, (p) => { delete p.provider; return p })\n * ```\n *\n * @see https://utils.feathersjs.com/utils/transform-params.html\n */\nexport const transformParams = <P extends Params = Params>(\n params: P,\n fn: TransformParamsFn<P> | undefined,\n): P => {\n if (!fn) {\n return params\n }\n\n const result = fn({ ...params })\n\n return result ?? params\n}\n","import type { Application, HookContext } from '@feathersjs/feathers'\nimport type { KeyOf, NeverFallback } from '../../internal.utils.js'\nimport type { InferFindResultSingle } from '../../utility-types/infer-service-methods.js'\n\n/**\n * The standard Feathers service events, plus any custom event name a service\n * might emit.\n */\nexport type ServiceEventName =\n | 'created'\n | 'updated'\n | 'patched'\n | 'removed'\n | (string & {})\n\nexport type WaitForServiceEventOptions<Result = unknown> = {\n /**\n * Reject after this many milliseconds. Pass `false` to wait indefinitely.\n *\n * @default 5000\n */\n timeout?: number | false\n /**\n * Only resolve for events whose data passes this predicate. Receives the\n * emitted record and the `HookContext` (the second argument Feathers emits).\n */\n filter?: (data: Result, context: HookContext) => boolean\n /**\n * Abort waiting via an `AbortSignal`. The promise rejects with the signal's\n * `reason` (or a generic abort error) and all listeners are detached.\n */\n signal?: AbortSignal\n}\n\n/**\n * Service-agnostic defaults that can be bound once when currying with the app.\n * `filter` is intentionally omitted because it depends on the per-service\n * record type.\n */\nexport type WaitForServiceEventDefaults = Pick<\n WaitForServiceEventOptions,\n 'timeout' | 'signal'\n>\n\nexport type WaitForServiceEventResult<Event extends string, Result> = [\n /** The emitted record. */\n data: Result,\n meta: {\n /** The event that fired (one of the requested events). */\n event: Event\n /** The `HookContext` Feathers emitted alongside the record. */\n context: HookContext\n },\n]\n\n/**\n * Wait for a service event to fire and resolve with the emitted record. Useful\n * in tests to await the result of an asynchronous service event, a bit like\n * `promisify` for Feathers events.\n *\n * Curried: bind the `app` (and optional defaults) once, then call the returned\n * function per service/event. Resolves with a `[data, { event, context }]`\n * tuple: `data` is typed as the service's record type, and `event` is the union\n * of the requested events.\n *\n * Feathers emits events as `emit(event, record, context)` and fires one event\n * per record, so each resolution carries a single record and its `HookContext`.\n *\n * @example\n * ```ts\n * import { waitForServiceEvent } from 'feathers-utils/utils'\n *\n * const app = feathers()\n * const waitForEvent = waitForServiceEvent(app)\n *\n * // Wait for the next `users` record to be created.\n * const [user] = await waitForEvent('users', 'created')\n *\n * // Wait for a specific record, with a custom timeout and filter.\n * const [data, { event }] = await waitForEvent(\n * 'users',\n * ['created', 'patched'],\n * { filter: (user) => user.email === 'jane@example.com', timeout: 1000 },\n * )\n * ```\n *\n * @see https://utils.feathersjs.com/utils/wait-for-service-event.html\n */\nexport function waitForServiceEvent<Services>(\n app: Application<Services>,\n defaultOptions?: WaitForServiceEventDefaults,\n) {\n return function waitForEvent<\n Path extends KeyOf<Services>,\n const Event extends ServiceEventName,\n Service extends Services[Path] = Services[Path],\n Result = NeverFallback<InferFindResultSingle<Service>, unknown>,\n >(\n servicePath: Path,\n eventOrEvents: Event | Event[],\n options?: WaitForServiceEventOptions<Result>,\n ): Promise<WaitForServiceEventResult<Event, Result>> {\n const events = (\n Array.isArray(eventOrEvents) ? eventOrEvents : [eventOrEvents]\n ) as Event[]\n\n const timeout = options?.timeout ?? defaultOptions?.timeout ?? 5000\n const filter = options?.filter\n const signal = options?.signal ?? defaultOptions?.signal\n\n const service = app.service(servicePath)\n\n return new Promise<WaitForServiceEventResult<Event, Result>>(\n (resolve, reject) => {\n let timer: ReturnType<typeof setTimeout> | undefined\n\n // [event, listener] pairs so we know which event fired (Node's\n // EventEmitter does not pass the event name to the listener) and can\n // detach each listener precisely on cleanup.\n const listeners = events.map((event) => {\n const listener = (data: Result, context: HookContext) => {\n if (filter && !filter(data, context)) {\n return\n }\n cleanup()\n resolve([data, { event, context }])\n }\n return [event, listener] as const\n })\n\n const abortError = () =>\n signal?.reason ??\n new Error(\n `Aborted waiting for event \"${events.join(', ')}\" on service \"${String(servicePath)}\"`,\n )\n\n const onAbort = () => {\n cleanup()\n reject(abortError())\n }\n\n function cleanup() {\n if (timer) {\n clearTimeout(timer)\n timer = undefined\n }\n for (const [event, listener] of listeners) {\n ;(service as any).off(event, listener)\n }\n signal?.removeEventListener('abort', onAbort)\n }\n\n if (signal?.aborted) {\n reject(abortError())\n return\n }\n\n if (timeout !== false) {\n timer = setTimeout(() => {\n cleanup()\n reject(\n new Error(\n `Timeout waiting for event \"${events.join(', ')}\" on service \"${String(servicePath)}\"`,\n ),\n )\n }, timeout)\n }\n\n signal?.addEventListener('abort', onAbort, { once: true })\n\n for (const [event, listener] of listeners) {\n ;(service as any).on(event, listener)\n }\n },\n )\n }\n}\n","import type { Query } from '@feathersjs/feathers'\n\ntype WalkQueryOptionsInit = {\n property?: string\n operator?: string | undefined\n value?: any\n path: (string | number)[]\n}\n\nexport type WalkQueryOptions = {\n property: string\n operator: string | undefined\n value: any\n path: (string | number)[]\n /**\n * Stops the traversal. Any replacement value returned from the current walker\n * call is still applied, but no further properties are visited.\n */\n stop: () => void\n}\n\nexport type WalkQueryCallback = (options: WalkQueryOptions) => any\n\ntype WalkQueryState = { stopped: boolean }\n\nconst _walkQueryUtil = <Q extends Query>(\n query: Q,\n walker: WalkQueryCallback,\n state: WalkQueryState,\n options?: WalkQueryOptionsInit | WalkQueryOptions,\n): Q => {\n const stop = () => {\n state.stopped = true\n }\n\n let cloned = false\n const clonedSecond: Record<string, boolean> = {}\n function set(key: string, value: any, secondKey?: string | number) {\n if (!cloned) {\n query = { ...query }\n cloned = true\n }\n\n if (secondKey !== undefined) {\n if (!clonedSecond[key]) {\n ;(query as any)[key] = { ...query[key] }\n clonedSecond[key] = true\n }\n query[key][secondKey] = value\n return\n }\n\n ;(query as any)[key] = value\n }\n\n for (const key in query) {\n if (state.stopped) {\n break\n }\n\n if (\n (key === '$or' || key === '$and' || key === '$nor') &&\n Array.isArray(query[key])\n ) {\n let array = query[key]\n\n let copiedArray = false\n\n for (let i = 0, n = array.length; i < n; i++) {\n if (state.stopped) {\n break\n }\n\n const nestedQuery = array[i]\n const transformed = _walkQueryUtil(nestedQuery, walker, state, {\n ...options,\n path: [...(options?.path || []), key, i],\n })\n\n if (transformed !== nestedQuery) {\n if (!copiedArray) {\n array = [...array] as any\n copiedArray = true\n }\n\n array[i] = transformed\n }\n }\n\n if (copiedArray) {\n set(key, array)\n }\n } else if (\n typeof query[key] === 'object' &&\n query[key] !== null &&\n !Array.isArray(query[key])\n ) {\n let hasOperator = false\n for (const operator in query[key]) {\n if (state.stopped) {\n break\n }\n\n if (operator.startsWith('$')) {\n hasOperator = true\n const value = walker({\n operator,\n path: [...(options?.path ?? []), key],\n property: key,\n value: query[key][operator],\n stop,\n })\n\n if (value !== undefined && value !== query[key][operator]) {\n set(key, value, operator)\n }\n }\n }\n\n if (!hasOperator) {\n const value = walker({\n operator: undefined,\n path: [...(options?.path ?? []), key],\n property: key,\n value: query[key],\n stop,\n })\n\n if (value !== undefined && value !== query[key]) {\n set(key, value)\n }\n }\n } else {\n const value = walker({\n operator: undefined,\n path: [...(options?.path ?? []), key],\n property: key,\n value: query[key],\n stop,\n })\n\n if (value !== undefined && value !== query[key]) {\n set(key, value)\n }\n }\n }\n\n return query\n}\n\n/**\n * Walks every property of a Feathers query (including nested `$and`/`$or`/`$nor` arrays)\n * and calls the `walker` function for each one. The walker receives the property name, operator,\n * value, path, and a `stop` function, and can return a replacement value. Calling `stop()` halts\n * the traversal early. Returns a new query only if changes were made.\n *\n * @example\n * ```ts\n * import { walkQuery } from 'feathers-utils/utils'\n *\n * const query = walkQuery({ age: { $gt: '18' } }, ({ value, operator }) => {\n * if (operator === '$gt') return Number(value)\n * })\n * // => { age: { $gt: 18 } }\n * ```\n *\n * @example\n * ```ts\n * // stop early once a property is found\n * let found = false\n * walkQuery(query, ({ property, stop }) => {\n * if (property === 'isTemplate') {\n * found = true\n * stop()\n * }\n * })\n * ```\n *\n * @see https://utils.feathersjs.com/utils/walk-query.html\n */\nexport const walkQuery = <Q extends Query>(\n query: Q,\n walker: WalkQueryCallback,\n): Q => {\n return _walkQueryUtil(query, walker, { stopped: false })\n}\n","import type { Query } from '@feathersjs/feathers'\nimport { toArray, type MaybeArray } from '../../internal.utils.js'\nimport { walkQuery } from '../walk-query/walk-query.util.js'\n\n/**\n * Checks whether a Feathers query contains one or more properties — including\n * properties nested inside `$and`/`$or`/`$nor` arrays. Returns `true` as soon as\n * any of the given property names is found. The query is not mutated.\n *\n * @example\n * ```ts\n * import { queryHasProperty } from 'feathers-utils/utils'\n *\n * queryHasProperty({ isTemplate: true }, 'isTemplate') // true\n * queryHasProperty({ $or: [{ isTemplate: true }] }, 'isTemplate') // true\n * queryHasProperty({ age: { $gt: 18 } }, ['isTemplate', 'status']) // false\n * ```\n *\n * @see https://utils.feathersjs.com/utils/query-has-property.html\n */\nexport const queryHasProperty = (\n query: Query,\n property: MaybeArray<string>,\n): boolean => {\n const properties = new Set(toArray(property))\n\n let found = false\n walkQuery(query, ({ property: key, stop }) => {\n if (properties.has(key)) {\n found = true\n stop()\n }\n // returning undefined leaves the value untouched → no mutation\n })\n\n return found\n}\n","import type { Query } from '@feathersjs/feathers'\nimport { addToQuery } from '../add-to-query/add-to-query.util.js'\nimport { queryHasProperty } from '../query-has-property/query-has-property.util.js'\n\n/**\n * Adds default properties to a Feathers query — but only for fields the query does\n * not already constrain. Presence is checked with {@link queryHasProperty}, so a field\n * referenced anywhere (including nested in `$and`/`$or`/`$nor`) is left untouched and\n * the caller keeps control over it. The query is treated as the `data` equivalent of\n * the `defaults` transformer. Each default is applied independently (per-field).\n *\n * @example\n * ```ts\n * import { queryDefaults } from 'feathers-utils/utils'\n *\n * queryDefaults({ status: 'active' }, { isTemplate: false })\n * // => { status: 'active', isTemplate: false }\n *\n * queryDefaults({ $or: [{ isTemplate: true }] }, { isTemplate: false })\n * // => { $or: [{ isTemplate: true }] } (untouched — already referenced)\n * ```\n *\n * @see https://utils.feathersjs.com/utils/query-defaults.html\n */\nexport const queryDefaults = (\n query: Query | undefined,\n defaults: Query,\n): Query => {\n const source: Query = query ?? {}\n\n const toAdd: Query = {}\n for (const key in defaults) {\n if (!queryHasProperty(source, key)) {\n toAdd[key] = defaults[key]\n }\n }\n\n return addToQuery(source, toAdd)\n}\n","import type { HookContext } from '@feathersjs/feathers'\nimport { getDataIsArray } from '../get-data-is-array/get-data-is-array.util.js'\nimport { getResultIsArray } from '../get-result-is-array/get-result-is-array.util.js'\nimport { checkContext } from '../check-context/check-context.util.js'\nimport type {\n DataSingleHookContext,\n ResultSingleHookContext,\n} from '../../utility-types/hook-context.js'\n\nexport type ZipDataResultOptions = {\n onMismatch?: (context: HookContext) => void\n}\n\nexport type ZipDataResultItem<D, R> = {\n data: D | undefined\n result: R | undefined\n}\n\n/**\n * Pairs each item in `context.data` with its corresponding item in `context.result` by index.\n * Handles both single-item and array data, normalizing them into an array of `{ data, result }` pairs.\n * Only works in `after`/`around` hooks for `create`, `update`, and `patch` methods.\n *\n * @example\n * ```ts\n * import { zipDataResult } from 'feathers-utils/utils'\n *\n * const pairs = zipDataResult(context)\n * pairs.forEach(({ data, result }) => { /* process each pair *\\/ })\n * ```\n *\n * @see https://utils.feathersjs.com/utils/zip-data-result.html\n */\nexport function zipDataResult<\n H extends HookContext,\n D extends DataSingleHookContext<H> = DataSingleHookContext<H>,\n R extends ResultSingleHookContext<H> = ResultSingleHookContext<H>,\n>(context: H, options?: ZipDataResultOptions): ZipDataResultItem<D, R>[] {\n checkContext(context, ['after', 'around'], ['create', 'update', 'patch'])\n\n const input = getDataIsArray(context)\n const output = getResultIsArray(context)\n\n if (\n input.isArray &&\n output.isArray &&\n input.data.length !== output.result.length\n ) {\n options?.onMismatch?.(context)\n }\n\n const result: ZipDataResultItem<D, R>[] = []\n\n const length = Math.max(input.data.length, output.result.length)\n\n for (let i = 0; i < length; i++) {\n const dataItem = input.isArray ? input.data.at(i) : input.data[0]\n const resultItem = output.result.at(i)\n\n result.push({\n data: dataItem,\n result: resultItem,\n })\n }\n\n return result\n}\n"],"mappings":";;;;;;AAEA,MAAM,iBAAiB,IAAI,IAAI;CAAC;CAAO;CAAQ;CAAQ;CAAQ;CAAO;AAAM,CAAC;AAE7E,MAAM,qBAAqB,UACzB,UAAU,QAAQ,OAAO,UAAU;;;;;;;;;;;;;;;;;;;;;;;;AAyBrC,MAAa,uBAAwC,UAAgB;CACnE,OAAO,UAAU,KAAK;AACxB;AAEA,MAAM,aAAa,UAAoB;CACrC,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,IAAI,SAAS;CAG5B,IAAI,CAAC,kBAAkB,KAAK,GAC1B,OAAO;CAGT,MAAM,SAA8B,CAAC;CAErC,KAAK,MAAM,OAAO,OAAO,KAAK,KAAK,CAAC,CAAC,KAAK,GAAG;EAC3C,MAAM,MAAM,MAAM;EAElB,IAAI,eAAe,IAAI,GAAG,KAAK,MAAM,QAAQ,GAAG,GAI9C,OAAO,OAAO,IACX,KAAK,OAAO;GACX,MAAM,aAAa,UAAU,EAAE;GAC/B,OAAO;IAAE,GAAG,KAAK,UAAU,UAAU;IAAG,GAAG;GAAW;EACxD,CAAC,CAAC,CACD,MAAM,GAAG,MAAO,EAAE,IAAI,EAAE,IAAI,KAAK,EAAE,IAAI,EAAE,IAAI,IAAI,CAAE,CAAC,CACpD,KAAK,UAAU,MAAM,CAAC;OAEzB,OAAO,OAAO,UAAU,GAAG;CAE/B;CAEA,OAAO;AACT;;;;;;;;;;;;;;;;;;;ACxCA,MAAa,WACX,SACA,UACG;CACH,MAAM,QAAQ,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK;CAEnD,IAAI,QAAQ,OAAO,cAAc,KAAA,GAC/B,QAAQ,SAAS;EACf,GAAG,QAAQ;EACX,WAAW,CAAC,GAAG,KAAK;CACtB;MACK;EACL,IAAI,CAAC,MAA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