feathers-utils 3.1.3 → 4.1.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.
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as _feathersjs_feathers from '@feathersjs/feathers';
2
- import { HookContext, Application, Id, Query, Params } from '@feathersjs/feathers';
2
+ import { HookContext, Application, Id, HookOptions, Query, Params } from '@feathersjs/feathers';
3
3
  import { HookContext as HookContext$1, Application as Application$1 } from '@feathersjs/feathers/lib';
4
4
  import { PropertyPath, DebouncedFunc } from 'lodash';
5
- import { AdapterBase, FilterQueryOptions as FilterQueryOptions$1, PaginationOptions } from '@feathersjs/adapter-commons';
5
+ import { PaginationOptions, FilterQueryOptions } from '@feathersjs/adapter-commons';
6
6
  import { HookType } from 'feathers-hooks-common';
7
7
 
8
8
  /**
@@ -125,35 +125,29 @@ declare class DebouncedStore {
125
125
 
126
126
  declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): (app: Application$1) => void;
127
127
 
128
- interface FilterQueryOptions<T> {
129
- service?: AdapterBase<T>;
130
- operators?: FilterQueryOptions$1["operators"];
131
- filters?: FilterQueryOptions$1["filters"];
132
- }
133
- declare function filterQuery<T>(query: Query, _options?: FilterQueryOptions<T>): any;
134
-
135
- type Handle = "target" | "source" | "combine" | "intersect" | "intersectOrFull";
136
- type FirstLast = "first" | "last";
137
- type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
138
- interface MergeQueryOptions<T> extends FilterQueryOptions<T> {
139
- defaultHandle: Handle;
140
- actionOnEmptyIntersect: ActionOnEmptyIntersect;
141
- useLogicalConjunction: boolean;
142
- handle?: {
143
- [key: string]: Handle;
144
- };
145
- }
146
-
147
- declare function mergeArrays<T>(targetArr: T[] | undefined, sourceArr: T[] | undefined, handle: Handle, prependKey?: Path, actionOnEmptyIntersect?: ActionOnEmptyIntersect): T[] | undefined;
148
-
128
+ declare function defineHooks<A extends Application = Application, S = {
129
+ find: any;
130
+ get: any;
131
+ create: any;
132
+ update: any;
133
+ patch: any;
134
+ remove: any;
135
+ }, Options = HookOptions<A, S>>(hooks: Options): Options;
136
+
137
+ type FilterQueryResult<Q extends Query> = {
138
+ $select: Q["$select"] extends any ? Q["$select"] : never;
139
+ $limit: Q["$limit"] extends any ? Q["$limit"] : never;
140
+ $skip: Q["$skip"] extends any ? Q["$skip"] : never;
141
+ $sort: Q["$sort"] extends any ? Q["$sort"] : never;
142
+ query: Omit<Q, "$select" | "$limit" | "$skip" | "$sort">;
143
+ };
149
144
  /**
150
- * Merges two queries into one.
151
- * @param target Query to be merged into
152
- * @param source Query to be merged from
153
- * @param _options
154
- * @returns Query
145
+ * Extracts $select, $limit, $skip, $sort from a query and returns the rest as a query object.
146
+ *
147
+ * @param providedQuery
148
+ * @returns
155
149
  */
156
- declare function mergeQuery<T = any>(target: Query, source: Query, _options?: Partial<MergeQueryOptions<T>>): Query;
150
+ declare function filterQuery<Q extends Query>(providedQuery?: Q): FilterQueryResult<Q>;
157
151
 
158
152
  /**
159
153
  * util to get paginate options from context
@@ -184,6 +178,29 @@ declare const isPaginated: <H extends HookContext<_feathersjs_feathers.Applicati
184
178
  */
185
179
  declare function markHookForSkip<H extends HookContext = HookContext>(hookName: string, type: "all" | MaybeArray<HookType>, context?: H): H;
186
180
 
181
+ type Handle = "target" | "source" | "combine" | "intersect" | "intersectOrFull";
182
+ type FirstLast = "first" | "last";
183
+ type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
184
+ interface MergeQueryOptions {
185
+ defaultHandle: Handle;
186
+ actionOnEmptyIntersect: ActionOnEmptyIntersect;
187
+ useLogicalConjunction: boolean;
188
+ handle?: {
189
+ [key: string]: Handle;
190
+ };
191
+ }
192
+
193
+ declare function mergeArrays<T>(targetArr: T[] | undefined, sourceArr: T[] | undefined, handle: Handle, prependKey?: Path, actionOnEmptyIntersect?: ActionOnEmptyIntersect): T[] | undefined;
194
+
195
+ /**
196
+ * Merges two queries into one.
197
+ * @param target Query to be merged into
198
+ * @param source Query to be merged from
199
+ * @param _options
200
+ * @returns Query
201
+ */
202
+ declare function mergeQuery(target: Query, source: Query, _options?: Partial<MergeQueryOptions>): Query;
203
+
187
204
  interface PushSetOptions {
188
205
  unique?: boolean;
189
206
  }
@@ -192,6 +209,11 @@ interface PushSetOptions {
192
209
  */
193
210
  declare const pushSet: (obj: Record<string, unknown>, path: string | Path, val: unknown, options?: PushSetOptions) => unknown[];
194
211
 
212
+ type SetQueryKeySafelyOptions = {
213
+ mutate?: boolean;
214
+ };
215
+ declare const setQueryKeySafely: <P extends Params<_feathersjs_feathers.Query> = Params<_feathersjs_feathers.Query>>(params: P, key: string, value: any, operator?: string, options?: SetQueryKeySafelyOptions) => P;
216
+
195
217
  /**
196
218
  * util to set `context.result` to an empty array or object, depending on the hook type
197
219
  */
@@ -205,21 +227,16 @@ type ShouldSkipOptions = {
205
227
  */
206
228
  declare const shouldSkip: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>>(hookName: string, context: H, options?: ShouldSkipOptions) => boolean;
207
229
 
230
+ declare const toJSON: (context: HookContext) => HookContext<_feathersjs_feathers.Application<any, any>, any>;
231
+
208
232
  /**
209
233
  * util to validate a query for operators
210
234
  */
211
235
  declare const validateQueryProperty: (query: any, operators?: string[]) => Query;
212
236
 
213
- declare const toJSON: (context: HookContext) => HookContext<_feathersjs_feathers.Application<any, any>, any>;
214
-
215
- type SetQueryKeySafelyOptions = {
216
- mutate?: boolean;
217
- };
218
- declare const setQueryKeySafely: <P extends Params<_feathersjs_feathers.Query> = Params<_feathersjs_feathers.Query>>(params: P, key: string, value: any, operator?: string, options?: SetQueryKeySafelyOptions) => P;
219
-
220
- declare const filterArray: <T extends string[]>(...keys: T) => { [key in T[number]]: (value: any, options: FilterQueryOptions$1) => any; };
237
+ declare const filterArray: <T extends string[]>(...keys: T) => { [key in T[number]]: (value: any, options: FilterQueryOptions) => any; };
221
238
 
222
- declare const filterObject: <T extends string[]>(...keys: T) => { [key in T[number]]: (value: any, options: FilterQueryOptions$1) => any; };
239
+ declare const filterObject: <T extends string[]>(...keys: T) => { [key in T[number]]: (value: any, options: FilterQueryOptions) => any; };
223
240
 
224
241
  type Single<T> = T extends Array<infer U> ? U : T;
225
242
  type AsArray<T> = T extends any[] ? T : [T];
@@ -267,4 +284,4 @@ type InferRemoveResultFromPath<App extends Application, Path extends string, IdO
267
284
  type InferDataFromPath<App extends Application, Path extends string, Method extends "create" | "update" | "patch"> = Method extends "create" ? InferCreateDataFromPath<App, Path> : Method extends "update" ? InferUpdateDataFromPath<App, Path> : Method extends "patch" ? InferPatchDataFromPath<App, Path> : never;
268
285
  type InferResultFromPath<App extends Application, Path extends string, Method extends "get" | "find" | "create" | "update" | "patch" | "remove"> = Method extends "get" ? InferGetResultFromPath<App, Path> : Method extends "find" ? InferFindResultFromPath<App, Path> : Method extends "create" ? InferCreateResultFromPath<App, Path> : Method extends "update" ? InferUpdateResultFromPath<App, Path> : Method extends "patch" ? InferPatchResultFromPath<App, Path> : Method extends "remove" ? InferRemoveResultFromPath<App, Path> : never;
269
286
 
270
- export { type ActionOnEmptyIntersect, type CreateRelatedOptions, type DebouncedFunctionApp, type DebouncedService, DebouncedStore, type DebouncedStoreOptions, type FilterQueryOptions, type FirstLast, type GetItemsIsArrayFrom, type GetItemsIsArrayOptions, type GetItemsIsArrayResult, type GetService, type Handle, type HookForEachOptions, type HookRunPerItemOptions, type HookSetDataOptions, type InferCreateData, type InferCreateDataFromPath, type InferCreateDataSingle, type InferCreateDataSingleFromPath, type InferCreateResult, type InferCreateResultFromPath, type InferCreateResultSingle, type InferCreateResultSingleFromPath, type InferDataFromPath, type InferFindResult, type InferFindResultFromPath, type InferGetResult, type InferGetResultFromPath, type InferPatchData, type InferPatchDataFromPath, type InferPatchResult, type InferPatchResultFromPath, type InferRemoveResult, type InferRemoveResultFromPath, type InferResultFromPath, type InferUpdateData, type InferUpdateDataFromPath, type InferUpdateResult, type InferUpdateResultFromPath, type InitDebounceMixinOptions, type MergeQueryOptions, type OnDeleteAction, type OnDeleteOptions, type Predicate, type PredicateWithContext, type PushSetOptions, type RemoveRelatedOptions, type SetQueryKeySafelyOptions, type ShouldSkipOptions, checkMulti, createRelated, debounceMixin, filterArray, filterObject, filterQuery, forEach, getItemsIsArray, getPaginate, isMulti, isPaginated, makeDefaultOptions, markHookForSkip, mergeArrays, mergeQuery, onDelete, parseFields, pushSet, removeRelated, runPerItem, setData, setQueryKeySafely, setResultEmpty, shouldSkip, toJSON, validateQueryProperty };
287
+ export { type ActionOnEmptyIntersect, type CreateRelatedOptions, type DebouncedFunctionApp, type DebouncedService, DebouncedStore, type DebouncedStoreOptions, type FirstLast, type GetItemsIsArrayFrom, type GetItemsIsArrayOptions, type GetItemsIsArrayResult, type GetService, type Handle, type HookForEachOptions, type HookRunPerItemOptions, type HookSetDataOptions, type InferCreateData, type InferCreateDataFromPath, type InferCreateDataSingle, type InferCreateDataSingleFromPath, type InferCreateResult, type InferCreateResultFromPath, type InferCreateResultSingle, type InferCreateResultSingleFromPath, type InferDataFromPath, type InferFindResult, type InferFindResultFromPath, type InferGetResult, type InferGetResultFromPath, type InferPatchData, type InferPatchDataFromPath, type InferPatchResult, type InferPatchResultFromPath, type InferRemoveResult, type InferRemoveResultFromPath, type InferResultFromPath, type InferUpdateData, type InferUpdateDataFromPath, type InferUpdateResult, type InferUpdateResultFromPath, type InitDebounceMixinOptions, type MergeQueryOptions, type OnDeleteAction, type OnDeleteOptions, type Predicate, type PredicateWithContext, type PushSetOptions, type RemoveRelatedOptions, type SetQueryKeySafelyOptions, type ShouldSkipOptions, checkMulti, createRelated, debounceMixin, defineHooks, filterArray, filterObject, filterQuery, forEach, getItemsIsArray, getPaginate, isMulti, isPaginated, makeDefaultOptions, markHookForSkip, mergeArrays, mergeQuery, onDelete, parseFields, pushSet, removeRelated, runPerItem, setData, setQueryKeySafely, setResultEmpty, shouldSkip, toJSON, validateQueryProperty };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as _feathersjs_feathers from '@feathersjs/feathers';
2
- import { HookContext, Application, Id, Query, Params } from '@feathersjs/feathers';
2
+ import { HookContext, Application, Id, HookOptions, Query, Params } from '@feathersjs/feathers';
3
3
  import { HookContext as HookContext$1, Application as Application$1 } from '@feathersjs/feathers/lib';
4
4
  import { PropertyPath, DebouncedFunc } from 'lodash';
5
- import { AdapterBase, FilterQueryOptions as FilterQueryOptions$1, PaginationOptions } from '@feathersjs/adapter-commons';
5
+ import { PaginationOptions, FilterQueryOptions } from '@feathersjs/adapter-commons';
6
6
  import { HookType } from 'feathers-hooks-common';
7
7
 
8
8
  /**
@@ -125,35 +125,29 @@ declare class DebouncedStore {
125
125
 
126
126
  declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): (app: Application$1) => void;
127
127
 
128
- interface FilterQueryOptions<T> {
129
- service?: AdapterBase<T>;
130
- operators?: FilterQueryOptions$1["operators"];
131
- filters?: FilterQueryOptions$1["filters"];
132
- }
133
- declare function filterQuery<T>(query: Query, _options?: FilterQueryOptions<T>): any;
134
-
135
- type Handle = "target" | "source" | "combine" | "intersect" | "intersectOrFull";
136
- type FirstLast = "first" | "last";
137
- type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
138
- interface MergeQueryOptions<T> extends FilterQueryOptions<T> {
139
- defaultHandle: Handle;
140
- actionOnEmptyIntersect: ActionOnEmptyIntersect;
141
- useLogicalConjunction: boolean;
142
- handle?: {
143
- [key: string]: Handle;
144
- };
145
- }
146
-
147
- declare function mergeArrays<T>(targetArr: T[] | undefined, sourceArr: T[] | undefined, handle: Handle, prependKey?: Path, actionOnEmptyIntersect?: ActionOnEmptyIntersect): T[] | undefined;
148
-
128
+ declare function defineHooks<A extends Application = Application, S = {
129
+ find: any;
130
+ get: any;
131
+ create: any;
132
+ update: any;
133
+ patch: any;
134
+ remove: any;
135
+ }, Options = HookOptions<A, S>>(hooks: Options): Options;
136
+
137
+ type FilterQueryResult<Q extends Query> = {
138
+ $select: Q["$select"] extends any ? Q["$select"] : never;
139
+ $limit: Q["$limit"] extends any ? Q["$limit"] : never;
140
+ $skip: Q["$skip"] extends any ? Q["$skip"] : never;
141
+ $sort: Q["$sort"] extends any ? Q["$sort"] : never;
142
+ query: Omit<Q, "$select" | "$limit" | "$skip" | "$sort">;
143
+ };
149
144
  /**
150
- * Merges two queries into one.
151
- * @param target Query to be merged into
152
- * @param source Query to be merged from
153
- * @param _options
154
- * @returns Query
145
+ * Extracts $select, $limit, $skip, $sort from a query and returns the rest as a query object.
146
+ *
147
+ * @param providedQuery
148
+ * @returns
155
149
  */
156
- declare function mergeQuery<T = any>(target: Query, source: Query, _options?: Partial<MergeQueryOptions<T>>): Query;
150
+ declare function filterQuery<Q extends Query>(providedQuery?: Q): FilterQueryResult<Q>;
157
151
 
158
152
  /**
159
153
  * util to get paginate options from context
@@ -184,6 +178,29 @@ declare const isPaginated: <H extends HookContext<_feathersjs_feathers.Applicati
184
178
  */
185
179
  declare function markHookForSkip<H extends HookContext = HookContext>(hookName: string, type: "all" | MaybeArray<HookType>, context?: H): H;
186
180
 
181
+ type Handle = "target" | "source" | "combine" | "intersect" | "intersectOrFull";
182
+ type FirstLast = "first" | "last";
183
+ type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
184
+ interface MergeQueryOptions {
185
+ defaultHandle: Handle;
186
+ actionOnEmptyIntersect: ActionOnEmptyIntersect;
187
+ useLogicalConjunction: boolean;
188
+ handle?: {
189
+ [key: string]: Handle;
190
+ };
191
+ }
192
+
193
+ declare function mergeArrays<T>(targetArr: T[] | undefined, sourceArr: T[] | undefined, handle: Handle, prependKey?: Path, actionOnEmptyIntersect?: ActionOnEmptyIntersect): T[] | undefined;
194
+
195
+ /**
196
+ * Merges two queries into one.
197
+ * @param target Query to be merged into
198
+ * @param source Query to be merged from
199
+ * @param _options
200
+ * @returns Query
201
+ */
202
+ declare function mergeQuery(target: Query, source: Query, _options?: Partial<MergeQueryOptions>): Query;
203
+
187
204
  interface PushSetOptions {
188
205
  unique?: boolean;
189
206
  }
@@ -192,6 +209,11 @@ interface PushSetOptions {
192
209
  */
193
210
  declare const pushSet: (obj: Record<string, unknown>, path: string | Path, val: unknown, options?: PushSetOptions) => unknown[];
194
211
 
212
+ type SetQueryKeySafelyOptions = {
213
+ mutate?: boolean;
214
+ };
215
+ declare const setQueryKeySafely: <P extends Params<_feathersjs_feathers.Query> = Params<_feathersjs_feathers.Query>>(params: P, key: string, value: any, operator?: string, options?: SetQueryKeySafelyOptions) => P;
216
+
195
217
  /**
196
218
  * util to set `context.result` to an empty array or object, depending on the hook type
197
219
  */
@@ -205,21 +227,16 @@ type ShouldSkipOptions = {
205
227
  */
206
228
  declare const shouldSkip: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>>(hookName: string, context: H, options?: ShouldSkipOptions) => boolean;
207
229
 
230
+ declare const toJSON: (context: HookContext) => HookContext<_feathersjs_feathers.Application<any, any>, any>;
231
+
208
232
  /**
209
233
  * util to validate a query for operators
210
234
  */
211
235
  declare const validateQueryProperty: (query: any, operators?: string[]) => Query;
212
236
 
213
- declare const toJSON: (context: HookContext) => HookContext<_feathersjs_feathers.Application<any, any>, any>;
214
-
215
- type SetQueryKeySafelyOptions = {
216
- mutate?: boolean;
217
- };
218
- declare const setQueryKeySafely: <P extends Params<_feathersjs_feathers.Query> = Params<_feathersjs_feathers.Query>>(params: P, key: string, value: any, operator?: string, options?: SetQueryKeySafelyOptions) => P;
219
-
220
- declare const filterArray: <T extends string[]>(...keys: T) => { [key in T[number]]: (value: any, options: FilterQueryOptions$1) => any; };
237
+ declare const filterArray: <T extends string[]>(...keys: T) => { [key in T[number]]: (value: any, options: FilterQueryOptions) => any; };
221
238
 
222
- declare const filterObject: <T extends string[]>(...keys: T) => { [key in T[number]]: (value: any, options: FilterQueryOptions$1) => any; };
239
+ declare const filterObject: <T extends string[]>(...keys: T) => { [key in T[number]]: (value: any, options: FilterQueryOptions) => any; };
223
240
 
224
241
  type Single<T> = T extends Array<infer U> ? U : T;
225
242
  type AsArray<T> = T extends any[] ? T : [T];
@@ -267,4 +284,4 @@ type InferRemoveResultFromPath<App extends Application, Path extends string, IdO
267
284
  type InferDataFromPath<App extends Application, Path extends string, Method extends "create" | "update" | "patch"> = Method extends "create" ? InferCreateDataFromPath<App, Path> : Method extends "update" ? InferUpdateDataFromPath<App, Path> : Method extends "patch" ? InferPatchDataFromPath<App, Path> : never;
268
285
  type InferResultFromPath<App extends Application, Path extends string, Method extends "get" | "find" | "create" | "update" | "patch" | "remove"> = Method extends "get" ? InferGetResultFromPath<App, Path> : Method extends "find" ? InferFindResultFromPath<App, Path> : Method extends "create" ? InferCreateResultFromPath<App, Path> : Method extends "update" ? InferUpdateResultFromPath<App, Path> : Method extends "patch" ? InferPatchResultFromPath<App, Path> : Method extends "remove" ? InferRemoveResultFromPath<App, Path> : never;
269
286
 
270
- export { type ActionOnEmptyIntersect, type CreateRelatedOptions, type DebouncedFunctionApp, type DebouncedService, DebouncedStore, type DebouncedStoreOptions, type FilterQueryOptions, type FirstLast, type GetItemsIsArrayFrom, type GetItemsIsArrayOptions, type GetItemsIsArrayResult, type GetService, type Handle, type HookForEachOptions, type HookRunPerItemOptions, type HookSetDataOptions, type InferCreateData, type InferCreateDataFromPath, type InferCreateDataSingle, type InferCreateDataSingleFromPath, type InferCreateResult, type InferCreateResultFromPath, type InferCreateResultSingle, type InferCreateResultSingleFromPath, type InferDataFromPath, type InferFindResult, type InferFindResultFromPath, type InferGetResult, type InferGetResultFromPath, type InferPatchData, type InferPatchDataFromPath, type InferPatchResult, type InferPatchResultFromPath, type InferRemoveResult, type InferRemoveResultFromPath, type InferResultFromPath, type InferUpdateData, type InferUpdateDataFromPath, type InferUpdateResult, type InferUpdateResultFromPath, type InitDebounceMixinOptions, type MergeQueryOptions, type OnDeleteAction, type OnDeleteOptions, type Predicate, type PredicateWithContext, type PushSetOptions, type RemoveRelatedOptions, type SetQueryKeySafelyOptions, type ShouldSkipOptions, checkMulti, createRelated, debounceMixin, filterArray, filterObject, filterQuery, forEach, getItemsIsArray, getPaginate, isMulti, isPaginated, makeDefaultOptions, markHookForSkip, mergeArrays, mergeQuery, onDelete, parseFields, pushSet, removeRelated, runPerItem, setData, setQueryKeySafely, setResultEmpty, shouldSkip, toJSON, validateQueryProperty };
287
+ export { type ActionOnEmptyIntersect, type CreateRelatedOptions, type DebouncedFunctionApp, type DebouncedService, DebouncedStore, type DebouncedStoreOptions, type FirstLast, type GetItemsIsArrayFrom, type GetItemsIsArrayOptions, type GetItemsIsArrayResult, type GetService, type Handle, type HookForEachOptions, type HookRunPerItemOptions, type HookSetDataOptions, type InferCreateData, type InferCreateDataFromPath, type InferCreateDataSingle, type InferCreateDataSingleFromPath, type InferCreateResult, type InferCreateResultFromPath, type InferCreateResultSingle, type InferCreateResultSingleFromPath, type InferDataFromPath, type InferFindResult, type InferFindResultFromPath, type InferGetResult, type InferGetResultFromPath, type InferPatchData, type InferPatchDataFromPath, type InferPatchResult, type InferPatchResultFromPath, type InferRemoveResult, type InferRemoveResultFromPath, type InferResultFromPath, type InferUpdateData, type InferUpdateDataFromPath, type InferUpdateResult, type InferUpdateResultFromPath, type InitDebounceMixinOptions, type MergeQueryOptions, type OnDeleteAction, type OnDeleteOptions, type Predicate, type PredicateWithContext, type PushSetOptions, type RemoveRelatedOptions, type SetQueryKeySafelyOptions, type ShouldSkipOptions, checkMulti, createRelated, debounceMixin, defineHooks, filterArray, filterObject, filterQuery, forEach, getItemsIsArray, getPaginate, isMulti, isPaginated, makeDefaultOptions, markHookForSkip, mergeArrays, mergeQuery, onDelete, parseFields, pushSet, removeRelated, runPerItem, setData, setQueryKeySafely, setResultEmpty, shouldSkip, toJSON, validateQueryProperty };