feathers-utils 7.0.0 → 7.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 (57) hide show
  1. package/README.md +3 -4
  2. package/dist/index.cjs +28 -42
  3. package/dist/index.d.cts +27 -28
  4. package/dist/index.d.mts +27 -28
  5. package/dist/index.d.ts +27 -28
  6. package/dist/index.mjs +28 -42
  7. package/package.json +19 -22
  8. package/src/filters/array.ts +11 -13
  9. package/src/filters/index.ts +2 -2
  10. package/src/filters/object.ts +11 -11
  11. package/src/hooks/checkMulti.ts +98 -82
  12. package/src/hooks/createRelated.ts +22 -23
  13. package/src/hooks/forEach.ts +32 -32
  14. package/src/hooks/from-client-for-server/common.ts +1 -1
  15. package/src/hooks/from-client-for-server/index.ts +2 -2
  16. package/src/hooks/from-client-for-server/paramsForServer.ts +32 -32
  17. package/src/hooks/from-client-for-server/paramsFromClient.ts +25 -25
  18. package/src/hooks/index.ts +9 -9
  19. package/src/hooks/onDelete.ts +32 -32
  20. package/src/hooks/parseFields.ts +13 -13
  21. package/src/hooks/removeRelated.ts +20 -20
  22. package/src/hooks/runPerItem.ts +17 -18
  23. package/src/hooks/setData.ts +295 -264
  24. package/src/index.ts +6 -6
  25. package/src/mixins/debounce-mixin/DebouncedStore.ts +29 -29
  26. package/src/mixins/debounce-mixin/debounceMixin.ts +17 -17
  27. package/src/mixins/debounce-mixin/index.ts +3 -3
  28. package/src/mixins/debounce-mixin/types.ts +9 -9
  29. package/src/mixins/debounce-mixin/utils.ts +3 -3
  30. package/src/mixins/index.ts +1 -1
  31. package/src/types.ts +3 -5
  32. package/src/typesInternal.ts +14 -14
  33. package/src/utility-types/index.ts +48 -48
  34. package/src/utils/_utils.internal.ts +5 -5
  35. package/src/utils/defineHooks.ts +8 -8
  36. package/src/utils/deflattenQuery.ts +31 -31
  37. package/src/utils/filterQuery.ts +58 -58
  38. package/src/utils/flattenQuery.ts +54 -54
  39. package/src/utils/getItemsIsArray.ts +148 -149
  40. package/src/utils/getPaginate.ts +31 -31
  41. package/src/utils/index.ts +17 -17
  42. package/src/utils/isMulti.ts +48 -40
  43. package/src/utils/isPaginated.ts +30 -30
  44. package/src/utils/markHookForSkip.ts +177 -178
  45. package/src/utils/mergeQuery/index.ts +3 -3
  46. package/src/utils/mergeQuery/mergeArrays.ts +67 -67
  47. package/src/utils/mergeQuery/mergeQuery.ts +211 -211
  48. package/src/utils/mergeQuery/types.ts +12 -12
  49. package/src/utils/mergeQuery/utils.ts +224 -224
  50. package/src/utils/optimizeBatchPatch.ts +42 -42
  51. package/src/utils/pushSet.ts +57 -57
  52. package/src/utils/setQueryKeySafely.ts +68 -68
  53. package/src/utils/setResultEmpty.ts +125 -123
  54. package/src/utils/shouldSkip.ts +72 -72
  55. package/src/utils/toJSON.ts +4 -4
  56. package/src/utils/validateQueryProperty.ts +10 -10
  57. package/src/hooks/makeSequelizeQuery.ts_ +0 -90
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import * as _feathersjs_feathers from '@feathersjs/feathers';
2
2
  import { HookContext, Application, Id, HookOptions, Query, Params } from '@feathersjs/feathers';
3
- import { HookContext as HookContext$1, Application as Application$1 } from '@feathersjs/feathers/lib';
4
3
  import { PropertyPath, DebouncedFunc } from 'lodash';
5
4
  import { PaginationOptions, FilterQueryOptions } from '@feathersjs/adapter-commons';
6
5
  import { HookType } from 'feathers-hooks-common';
@@ -13,7 +12,7 @@ declare function checkMulti<H extends HookContext = HookContext>(): (context: H)
13
12
  type MaybeArray<T> = T | T[];
14
13
  type Promisable<T> = T | Promise<T>;
15
14
  type Path = Array<string | number>;
16
- type ReturnAsyncHook<H extends HookContext$1 = HookContext$1> = (context: H) => Promise<H>;
15
+ type ReturnAsyncHook<H extends HookContext = HookContext> = (context: H) => Promise<H>;
17
16
  type KeyOf<T> = Extract<keyof T, string>;
18
17
 
19
18
  interface CreateRelatedOptions<S = Record<string, any>> {
@@ -27,7 +26,7 @@ interface CreateRelatedOptions<S = Record<string, any>> {
27
26
  */
28
27
  declare function createRelated<S = Record<string, any>, H extends HookContext = HookContext>(options: MaybeArray<CreateRelatedOptions<S>>): (context: H) => Promise<H>;
29
28
 
30
- type GetItemsIsArrayFrom = "data" | "result" | "automatic";
29
+ type GetItemsIsArrayFrom = 'data' | 'result' | 'automatic';
31
30
  type GetItemsIsArrayOptions = {
32
31
  from?: GetItemsIsArrayFrom;
33
32
  };
@@ -35,11 +34,11 @@ interface GetItemsIsArrayResult<T = any> {
35
34
  items: T[];
36
35
  isArray: boolean;
37
36
  }
38
- declare const getItemsIsArray: <T = any, H extends HookContext = HookContext<_feathersjs_feathers.Application<any, any>, any>>(context: H, options?: GetItemsIsArrayOptions) => GetItemsIsArrayResult<T>;
37
+ declare const getItemsIsArray: <T = any, H extends HookContext = HookContext>(context: H, options?: GetItemsIsArrayOptions) => GetItemsIsArrayResult<T>;
39
38
 
40
39
  type HookForEachOptions<T = any, H = HookContext, R = any> = {
41
- wait?: "sequential" | "parallel" | false;
42
- items?: GetItemsIsArrayOptions["from"];
40
+ wait?: 'sequential' | 'parallel' | false;
41
+ items?: GetItemsIsArrayOptions['from'];
43
42
  forAll?: (items: T[], context: H) => Promisable<R>;
44
43
  skip?: (context: H) => Promisable<boolean>;
45
44
  };
@@ -49,9 +48,9 @@ type ActionPerItem<T, H, R> = (item: T, options: {
49
48
  } & (undefined extends R ? {} : {
50
49
  fromAll: R;
51
50
  })) => Promisable<any>;
52
- declare const forEach: <H extends HookContext = HookContext<_feathersjs_feathers.Application<any, any>, any>, T = any, R = any>(actionPerItem: ActionPerItem<T, H, R>, options?: HookForEachOptions<T, H, R>) => ReturnAsyncHook<H>;
51
+ declare const forEach: <H extends HookContext = HookContext, T = any, R = any>(actionPerItem: ActionPerItem<T, H, R>, options?: HookForEachOptions<T, H, R>) => ReturnAsyncHook<H>;
53
52
 
54
- type OnDeleteAction = "cascade" | "set null";
53
+ type OnDeleteAction = 'cascade' | 'set null';
55
54
  interface OnDeleteOptions<Path extends string = string> {
56
55
  service: Path;
57
56
  keyThere: string;
@@ -92,7 +91,7 @@ interface HookRunPerItemOptions {
92
91
  * hook to run a hook for each item in the context
93
92
  * uses `context.result` if it is existent. otherwise uses context.data
94
93
  */
95
- declare const runPerItem: <H extends HookContext = HookContext<_feathersjs_feathers.Application<any, any>, any>, T = any>(actionPerItem: (item: T, context: H) => Promisable<any>, _options?: HookRunPerItemOptions) => (context: H) => Promise<H>;
94
+ declare const runPerItem: <H extends HookContext = HookContext, T = any>(actionPerItem: (item: T, context: H) => Promisable<any>, _options?: HookRunPerItemOptions) => (context: H) => Promise<H>;
96
95
 
97
96
  type Predicate<T = any> = (item: T) => boolean;
98
97
  type PredicateWithContext<T = any> = (item: T, context: HookContext) => boolean;
@@ -139,14 +138,14 @@ declare class DebouncedStore {
139
138
  private _options;
140
139
  private _isRunningById;
141
140
  _queueById: Record<string, DebouncedFunc<(id: Id, action: DebouncedFunctionApp) => void | Promise<void>>>;
142
- add: any;
141
+ add: (id: Id, action: (app?: Application) => void | Promise<void>) => void | Promise<void> | undefined;
143
142
  constructor(app: Application, options?: Partial<DebouncedStoreOptions>);
144
143
  private unbounced;
145
144
  private debounceById;
146
145
  cancel(id: Id): void;
147
146
  }
148
147
 
149
- declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): (app: Application$1) => void;
148
+ declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): (app: Application) => void;
150
149
 
151
150
  declare function defineHooks<A extends Application = Application, S = {
152
151
  find: any;
@@ -158,11 +157,11 @@ declare function defineHooks<A extends Application = Application, S = {
158
157
  }, Options = HookOptions<A, S>>(hooks: Options): Options;
159
158
 
160
159
  type FilterQueryResult<Q extends Query = Query> = {
161
- $select: Q["$select"] extends any ? Q["$select"] : never;
162
- $limit: Q["$limit"] extends any ? Q["$limit"] : never;
163
- $skip: Q["$skip"] extends any ? Q["$skip"] : never;
164
- $sort: Q["$sort"] extends any ? Q["$sort"] : never;
165
- query: Omit<Q, "$select" | "$limit" | "$skip" | "$sort">;
160
+ $select: Q['$select'] extends any ? Q['$select'] : never;
161
+ $limit: Q['$limit'] extends any ? Q['$limit'] : never;
162
+ $skip: Q['$skip'] extends any ? Q['$skip'] : never;
163
+ $sort: Q['$sort'] extends any ? Q['$sort'] : never;
164
+ query: Omit<Q, '$select' | '$limit' | '$skip' | '$sort'>;
166
165
  };
167
166
  /**
168
167
  * Extracts $select, $limit, $skip, $sort from a query and returns the rest as a query object.
@@ -179,7 +178,7 @@ declare function reassembleQuery(query: FilterQueryResult): Query;
179
178
  * 2. it uses `service.options.paginate` if it exists
180
179
  * 3. it uses `context.params.adapter` if it exists
181
180
  */
182
- declare const getPaginate: <H extends HookContext = HookContext<_feathersjs_feathers.Application<any, any>, any>>(context: H) => PaginationOptions | undefined;
181
+ declare const getPaginate: <H extends HookContext = HookContext>(context: H) => PaginationOptions | undefined;
183
182
 
184
183
  /**
185
184
  * util to check if a hook is a multi hook:
@@ -190,19 +189,19 @@ declare const getPaginate: <H extends HookContext = HookContext<_feathersjs_feat
190
189
  * - patch: `context.id == null`
191
190
  * - remove: `context.id == null`
192
191
  */
193
- declare const isMulti: <H extends HookContext = HookContext<_feathersjs_feathers.Application<any, any>, any>>(context: H) => boolean;
192
+ declare const isMulti: <H extends HookContext = HookContext>(context: H) => boolean;
194
193
 
195
194
  /**
196
195
  * util to check if a hook is a paginated hook using `getPaginate`
197
196
  */
198
- declare const isPaginated: <H extends HookContext = HookContext<_feathersjs_feathers.Application<any, any>, any>>(context: H) => boolean;
197
+ declare const isPaginated: <H extends HookContext = HookContext>(context: H) => boolean;
199
198
 
200
199
  /**
201
200
  * util to mark a hook for skip, has to be used with `shouldSkip`
202
201
  */
203
- declare function markHookForSkip<H extends HookContext = HookContext>(hookName: string, type: "all" | MaybeArray<HookType>, context?: H): H;
202
+ declare function markHookForSkip<H extends HookContext = HookContext>(hookName: string, type: 'all' | MaybeArray<HookType>, context?: H): H | undefined;
204
203
 
205
- type Handle = "target" | "source" | "combine" | "intersect" | "intersectOrFull";
204
+ type Handle = 'target' | 'source' | 'combine' | 'intersect' | 'intersectOrFull';
206
205
  type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
207
206
  interface MergeQueryOptions {
208
207
  defaultHandle: Handle;
@@ -240,7 +239,7 @@ declare const setQueryKeySafely: (params: Params, key: string, value: any, opera
240
239
  /**
241
240
  * util to set `context.result` to an empty array or object, depending on the hook type
242
241
  */
243
- declare const setResultEmpty: <H extends HookContext = HookContext<_feathersjs_feathers.Application<any, any>, any>>(context: H) => H;
242
+ declare const setResultEmpty: <H extends HookContext = HookContext>(context: H) => H;
244
243
 
245
244
  type ShouldSkipOptions = {
246
245
  notSkippable?: boolean;
@@ -248,7 +247,7 @@ type ShouldSkipOptions = {
248
247
  /**
249
248
  * util to detect if a hook should be skipped
250
249
  */
251
- declare const shouldSkip: <H extends HookContext = HookContext<_feathersjs_feathers.Application<any, any>, any>>(hookName: string, context: H, options?: ShouldSkipOptions) => boolean;
250
+ declare const shouldSkip: <H extends HookContext = HookContext>(hookName: string, context: H, options?: ShouldSkipOptions) => boolean;
252
251
 
253
252
  declare const toJSON: (context: HookContext) => HookContext<_feathersjs_feathers.Application<any, any>, any>;
254
253
 
@@ -261,10 +260,10 @@ type OptimizeBatchPatchOptions<IdKey extends string> = {
261
260
  /** the key of the id property */
262
261
  id?: IdKey;
263
262
  };
264
- type OptimizeBatchPatchResultItem<T = Record<string, unknown>, P = Params> = [Id, T, P | undefined];
263
+ type OptimizeBatchPatchResultItem<T = Record<string, unknown>, P = Params> = [Id | null, T, P | undefined];
265
264
  declare function optimizeBatchPatch<T extends Record<string, any>, IdKey extends KeyOf<T>, P extends Params, R extends Omit<T, IdKey> = Omit<T, IdKey>>(items: T[], options?: OptimizeBatchPatchOptions<IdKey>): OptimizeBatchPatchResultItem<R, P>[];
266
265
 
267
- declare function flattenQuery(q: Query): any;
266
+ declare function flattenQuery(q: Query): Query;
268
267
 
269
268
  declare function deflattenQuery(query: Query): Query;
270
269
 
@@ -303,7 +302,7 @@ type InferPatchResult<S, IdOrNullable = any> = S extends {
303
302
  type InferRemoveResult<S, IdOrNullable = any> = S extends {
304
303
  remove: (id: IdOrNullable, params: any) => infer R;
305
304
  } ? IdOrNullable extends Id ? Single<Awaited<R>> : IdOrNullable extends null ? AsArray<Awaited<R>> : Awaited<R> : never;
306
- type GetService<App extends Application, Path extends string> = App["services"][Path];
305
+ type GetService<App extends Application, Path extends string> = App['services'][Path];
307
306
  type InferGetResultFromPath<App extends Application, Path extends string> = InferGetResult<GetService<App, Path>>;
308
307
  type InferFindResultFromPath<App extends Application, Path extends string> = InferFindResult<GetService<App, Path>>;
309
308
  type InferCreateDataFromPath<App extends Application, Path extends string> = InferCreateData<GetService<App, Path>>;
@@ -315,7 +314,7 @@ type InferPatchDataFromPath<App extends Application, Path extends string> = Infe
315
314
  type InferUpdateResultFromPath<App extends Application, Path extends string> = InferUpdateResult<GetService<App, Path>>;
316
315
  type InferPatchResultFromPath<App extends Application, Path extends string, IdOrNullable = any> = InferPatchResult<GetService<App, Path>, IdOrNullable>;
317
316
  type InferRemoveResultFromPath<App extends Application, Path extends string, IdOrNullable = any> = InferRemoveResult<GetService<App, Path>, IdOrNullable>;
318
- 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;
319
- 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;
317
+ 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;
318
+ 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;
320
319
 
321
320
  export { type ActionOnEmptyIntersect, type CreateRelatedOptions, type DebouncedFunctionApp, type DebouncedService, DebouncedStore, type DebouncedStoreOptions, 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 OptimizeBatchPatchOptions, type OptimizeBatchPatchResultItem, type Predicate, type PredicateWithContext, type PushSetOptions, type RemoveRelatedOptions, type SetQueryKeySafelyOptions, type ShouldSkipOptions, checkMulti, createRelated, debounceMixin, defineHooks, defineParamsForServer, defineParamsFromClient, deflattenQuery, filterArray, filterObject, filterQuery, flattenQuery, forEach, getItemsIsArray, getPaginate, isMulti, isPaginated, markHookForSkip, mergeArrays, mergeQuery, onDelete, optimizeBatchPatch, paramsForServer, paramsFromClient, parseFields, pushSet, reassembleQuery, removeRelated, runPerItem, setData, setQueryKeySafely, setResultEmpty, shouldSkip, toJSON, validateQueryProperty };
package/dist/index.mjs CHANGED
@@ -13,7 +13,7 @@ function defineHooks(hooks) {
13
13
  }
14
14
 
15
15
  function filterQuery(providedQuery) {
16
- providedQuery ?? (providedQuery = {});
16
+ providedQuery ??= {};
17
17
  const { $select, $limit, $skip, $sort, ...query } = providedQuery;
18
18
  const result = { query };
19
19
  if ("$select" in providedQuery) {
@@ -381,12 +381,12 @@ function handleCircular(target, source, prependKey, options) {
381
381
  }
382
382
  }
383
383
  function makeDefaultOptions$1(options) {
384
- options ?? (options = {});
385
- options.defaultHandle ?? (options.defaultHandle = "combine");
386
- options.useLogicalConjunction ?? (options.useLogicalConjunction = false);
387
- options.actionOnEmptyIntersect ?? (options.actionOnEmptyIntersect = () => {
384
+ options ??= {};
385
+ options.defaultHandle ??= "combine";
386
+ options.useLogicalConjunction ??= false;
387
+ options.actionOnEmptyIntersect ??= () => {
388
388
  throw new Forbidden("You're not allowed to make this request");
389
- });
389
+ };
390
390
  options.handle = options.handle || {};
391
391
  if (options.defaultHandle === "intersect") {
392
392
  options.handle.$select = options.handle.$select || "intersectOrFull";
@@ -506,7 +506,6 @@ function mergeQuery(target, source, _options) {
506
506
  }
507
507
 
508
508
  const setQueryKeySafely = (params, key, value, operator = "$eq", options) => {
509
- var _a;
510
509
  const { mutate = false } = options || {};
511
510
  if (!mutate) {
512
511
  params = structuredClone(params);
@@ -527,7 +526,7 @@ const setQueryKeySafely = (params, key, value, operator = "$eq", options) => {
527
526
  if (isPlainObject(params.query[key]) && !(operator in params.query[key])) {
528
527
  params.query[key][operator] = value;
529
528
  } else {
530
- (_a = params.query).$and ?? (_a.$and = []);
529
+ params.query.$and ??= [];
531
530
  params.query.$and.push(
532
531
  operator === "$eq" ? { [key]: value } : {
533
532
  [key]: {
@@ -815,7 +814,7 @@ function onDelete(options) {
815
814
  const data = { [keyThere]: null };
816
815
  promise = context.app.service(service).patch(null, data, params);
817
816
  }
818
- if (blocking) {
817
+ if (blocking && promise) {
819
818
  promises.push(promise);
820
819
  }
821
820
  }
@@ -955,19 +954,18 @@ function defineParamsForServer(keyToHide) {
955
954
  return;
956
955
  }
957
956
  if (whitelist.includes(key)) {
958
- if (!clonedParams) {
959
- clonedParams = {
960
- ...context.params,
961
- query: {
962
- ...context.params.query
963
- }
964
- };
965
- }
966
- if (!clonedParams.query[keyToHide]) {
967
- clonedParams.query[keyToHide] = {};
957
+ const currentParams = clonedParams ?? {
958
+ ...context.params,
959
+ query: {
960
+ ...context.params.query
961
+ }
962
+ };
963
+ if (!currentParams.query[keyToHide]) {
964
+ currentParams.query[keyToHide] = {};
968
965
  }
969
- clonedParams.query[keyToHide][key] = clonedParams[key];
970
- delete clonedParams[key];
966
+ currentParams.query[keyToHide][key] = currentParams[key];
967
+ delete currentParams[key];
968
+ clonedParams = currentParams;
971
969
  }
972
970
  });
973
971
  if (clonedParams) {
@@ -1024,20 +1022,14 @@ const makeDefaultOptions = () => {
1024
1022
  };
1025
1023
  };
1026
1024
 
1027
- var __defProp = Object.defineProperty;
1028
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1029
- var __publicField = (obj, key, value) => {
1030
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1031
- return value;
1032
- };
1033
1025
  class DebouncedStore {
1026
+ _app;
1027
+ _options;
1028
+ _isRunningById;
1029
+ _queueById;
1030
+ //_waitingById: Record<string, WaitingObject>;
1031
+ add;
1034
1032
  constructor(app, options) {
1035
- __publicField(this, "_app");
1036
- __publicField(this, "_options");
1037
- __publicField(this, "_isRunningById");
1038
- __publicField(this, "_queueById");
1039
- //_waitingById: Record<string, WaitingObject>;
1040
- __publicField(this, "add");
1041
1033
  this._app = app;
1042
1034
  this._options = Object.assign(makeDefaultOptions(), options);
1043
1035
  this._queueById = {};
@@ -1080,13 +1072,9 @@ class DebouncedStore {
1080
1072
  function debounceMixin(options) {
1081
1073
  return (app) => {
1082
1074
  options = options || {};
1083
- const defaultOptions = Object.assign(
1084
- makeDefaultOptions(),
1085
- options?.default
1086
- );
1075
+ const defaultOptions = Object.assign(makeDefaultOptions(), options?.default);
1087
1076
  app.mixins.push((service, path) => {
1088
- if (options?.blacklist && options.blacklist.includes(path))
1089
- return;
1077
+ if (options?.blacklist && options.blacklist.includes(path)) return;
1090
1078
  if (service.debouncedStore) {
1091
1079
  console.warn(
1092
1080
  `[feathers-utils] service: '${path}' already has a property 'debouncedStore'. Mixin will skip creating a new debouncedStore`
@@ -1104,9 +1092,7 @@ function debounceMixin(options) {
1104
1092
 
1105
1093
  const filterQueryArray = (key) => (arr, { operators }) => {
1106
1094
  if (arr && !Array.isArray(arr)) {
1107
- throw new Error(
1108
- `Invalid query parameter '${key}'. It has to be an array`
1109
- );
1095
+ throw new Error(`Invalid query parameter '${key}'. It has to be an array`);
1110
1096
  }
1111
1097
  if (Array.isArray(arr)) {
1112
1098
  return arr.map((current) => validateQueryProperty(current, operators));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feathers-utils",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "Some utils for projects using '@feathersjs/feathers'",
5
5
  "author": "fratzinger",
6
6
  "repository": {
@@ -22,6 +22,7 @@
22
22
  "main": "./dist/index.cjs",
23
23
  "module": "./dist/index.mjs",
24
24
  "types": "./dist/index.d.ts",
25
+ "type": "module",
25
26
  "files": [
26
27
  "CHANGELOG.md",
27
28
  "LICENSE",
@@ -31,31 +32,27 @@
31
32
  "dist/**"
32
33
  ],
33
34
  "dependencies": {
34
- "@feathersjs/adapter-commons": "^5.0.31",
35
- "@feathersjs/errors": "^5.0.31",
36
- "@feathersjs/feathers": "^5.0.31",
37
- "fast-equals": "^5.0.1",
35
+ "@feathersjs/adapter-commons": "^5.0.33",
36
+ "@feathersjs/errors": "^5.0.33",
37
+ "@feathersjs/feathers": "^5.0.33",
38
+ "fast-equals": "^5.2.2",
38
39
  "feathers-hooks-common": "^8.2.1",
39
40
  "lodash": "^4.17.21"
40
41
  },
41
42
  "devDependencies": {
42
- "@feathersjs/memory": "^5.0.31",
43
- "@types/lodash": "^4.17.13",
44
- "@types/node": "^22.10.1",
45
- "@typescript-eslint/eslint-plugin": "^6.16.0",
46
- "@typescript-eslint/parser": "^6.16.0",
47
- "@vitest/coverage-v8": "^2.1.8",
48
- "eslint": "^8.56.0",
49
- "eslint-config-prettier": "^9.1.0",
50
- "eslint-import-resolver-typescript": "^3.7.0",
51
- "eslint-plugin-import": "^2.29.1",
52
- "eslint-plugin-prettier": "^5.1.2",
53
- "np": "^10.1.0",
54
- "prettier": "^3.4.1",
43
+ "@feathers-community/eslint-config": "^0.0.4",
44
+ "@feathersjs/memory": "^5.0.33",
45
+ "@tsconfig/node22": "^22.0.0",
46
+ "@types/lodash": "^4.17.16",
47
+ "@types/node": "^22.13.9",
48
+ "@vitest/coverage-v8": "^3.0.7",
49
+ "eslint": "^9.21.0",
50
+ "np": "^10.2.0",
51
+ "prettier": "^3.5.3",
55
52
  "shx": "^0.3.4",
56
- "typescript": "^5.7.2",
57
- "unbuild": "^2.0.0",
58
- "vitest": "^2.1.8"
53
+ "typescript": "^5.8.2",
54
+ "unbuild": "^3.5.0",
55
+ "vitest": "^3.0.7"
59
56
  },
60
57
  "peerDependencies": {
61
58
  "@feathersjs/feathers": "^5.0.0"
@@ -67,6 +64,6 @@
67
64
  "test": "vitest run",
68
65
  "vitest": "vitest",
69
66
  "coverage": "vitest run --coverage",
70
- "lint": "eslint . --ext .js,.jsx,.ts,.tsx"
67
+ "lint": "eslint"
71
68
  }
72
69
  }
@@ -1,30 +1,28 @@
1
- import type { FilterQueryOptions } from "@feathersjs/adapter-commons";
2
- import { validateQueryProperty } from "../utils/validateQueryProperty";
1
+ import type { FilterQueryOptions } from '@feathersjs/adapter-commons'
2
+ import { validateQueryProperty } from '../utils/validateQueryProperty.js'
3
3
 
4
4
  const filterQueryArray =
5
5
  (key: string) =>
6
6
  (arr: any, { operators }: FilterQueryOptions) => {
7
7
  if (arr && !Array.isArray(arr)) {
8
- throw new Error(
9
- `Invalid query parameter '${key}'. It has to be an array`,
10
- );
8
+ throw new Error(`Invalid query parameter '${key}'. It has to be an array`)
11
9
  }
12
10
 
13
11
  if (Array.isArray(arr)) {
14
- return arr.map((current) => validateQueryProperty(current, operators));
12
+ return arr.map((current) => validateQueryProperty(current, operators))
15
13
  }
16
14
 
17
- return arr;
18
- };
15
+ return arr
16
+ }
19
17
 
20
18
  export const filterArray = <T extends string[]>(...keys: T) => {
21
19
  const result: {
22
- [key in T[number]]: (value: any, options: FilterQueryOptions) => any;
23
- } = {} as any;
20
+ [key in T[number]]: (value: any, options: FilterQueryOptions) => any
21
+ } = {} as any
24
22
 
25
23
  for (const key of keys) {
26
- result[key as T[number]] = filterQueryArray(key);
24
+ result[key as T[number]] = filterQueryArray(key)
27
25
  }
28
26
 
29
- return result;
30
- };
27
+ return result
28
+ }
@@ -1,2 +1,2 @@
1
- export * from "./array";
2
- export * from "./object";
1
+ export * from './array.js'
2
+ export * from './object.js'
@@ -1,6 +1,6 @@
1
- import type { FilterQueryOptions } from "@feathersjs/adapter-commons";
2
- import { validateQueryProperty } from "../utils/validateQueryProperty";
3
- import { isObject } from "../utils/_utils.internal";
1
+ import type { FilterQueryOptions } from '@feathersjs/adapter-commons'
2
+ import { validateQueryProperty } from '../utils/validateQueryProperty.js'
3
+ import { isObject } from '../utils/_utils.internal.js'
4
4
 
5
5
  const filterQueryObject =
6
6
  (key: string) =>
@@ -8,20 +8,20 @@ const filterQueryObject =
8
8
  if (obj && !isObject(obj)) {
9
9
  throw new Error(
10
10
  `Invalid query parameter: '${key}'. It has to be an object`,
11
- );
11
+ )
12
12
  }
13
13
 
14
- return validateQueryProperty(obj, operators);
15
- };
14
+ return validateQueryProperty(obj, operators)
15
+ }
16
16
 
17
17
  export const filterObject = <T extends string[]>(...keys: T) => {
18
18
  const result: {
19
- [key in T[number]]: (value: any, options: FilterQueryOptions) => any;
20
- } = {} as any;
19
+ [key in T[number]]: (value: any, options: FilterQueryOptions) => any
20
+ } = {} as any
21
21
 
22
22
  for (const key of keys) {
23
- result[key as T[number]] = filterQueryObject(key);
23
+ result[key as T[number]] = filterQueryObject(key)
24
24
  }
25
25
 
26
- return result;
27
- };
26
+ return result
27
+ }