feathers-utils 2.0.0-8 → 2.0.0-9

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 (42) hide show
  1. package/dist/esm/hooks/onDelete.d.ts +1 -1
  2. package/dist/esm/hooks/runPerItem.d.ts +1 -2
  3. package/dist/esm/hooks/runPerItem.js +1 -2
  4. package/dist/esm/hooks/setData.d.ts +1 -1
  5. package/dist/esm/hooks/setData.js +1 -1
  6. package/dist/esm/mixins/debounce-mixin/DebouncedStore.d.ts +1 -1
  7. package/dist/esm/mixins/debounce-mixin/types.d.ts +1 -1
  8. package/dist/esm/types.d.ts +2 -2
  9. package/dist/esm/typesInternal.d.ts +3 -3
  10. package/dist/esm/utils/filterQuery.js +0 -2
  11. package/dist/esm/utils/getItemsIsArray.d.ts +3 -3
  12. package/dist/esm/utils/getItemsIsArray.js +2 -2
  13. package/dist/esm/utils/getPaginate.js +1 -1
  14. package/dist/esm/utils/isPaginated.js +1 -1
  15. package/dist/esm/utils/mergeQuery/types.d.ts +3 -3
  16. package/dist/esm/utils/shouldSkip.d.ts +1 -1
  17. package/dist/esm/utils/shouldSkip.js +5 -8
  18. package/dist/hooks/onDelete.d.ts +1 -1
  19. package/dist/hooks/runPerItem.d.ts +1 -2
  20. package/dist/hooks/runPerItem.js +1 -2
  21. package/dist/hooks/setData.d.ts +1 -1
  22. package/dist/hooks/setData.js +1 -1
  23. package/dist/mixins/debounce-mixin/DebouncedStore.d.ts +1 -1
  24. package/dist/mixins/debounce-mixin/types.d.ts +1 -1
  25. package/dist/types.d.ts +2 -2
  26. package/dist/typesInternal.d.ts +3 -3
  27. package/dist/utils/filterQuery.js +0 -2
  28. package/dist/utils/getItemsIsArray.d.ts +3 -3
  29. package/dist/utils/getItemsIsArray.js +2 -2
  30. package/dist/utils/getPaginate.js +2 -1
  31. package/dist/utils/isPaginated.js +1 -1
  32. package/dist/utils/mergeQuery/types.d.ts +3 -3
  33. package/dist/utils/shouldSkip.d.ts +1 -1
  34. package/dist/utils/shouldSkip.js +5 -8
  35. package/package.json +17 -17
  36. package/src/hooks/runPerItem.ts +1 -2
  37. package/src/hooks/setData.ts +1 -1
  38. package/src/utils/filterQuery.ts +0 -2
  39. package/src/utils/getItemsIsArray.ts +4 -4
  40. package/src/utils/getPaginate.ts +1 -1
  41. package/src/utils/isPaginated.ts +1 -1
  42. package/src/utils/shouldSkip.ts +5 -17
@@ -1,5 +1,5 @@
1
1
  import type { HookContext } from "@feathersjs/feathers";
2
- export declare type OnDeleteAction = "cascade" | "set null";
2
+ export type OnDeleteAction = "cascade" | "set null";
3
3
  export interface OnDeleteOptions {
4
4
  keyThere: string;
5
5
  keyHere: string;
@@ -5,7 +5,6 @@ export interface HookRunPerItemOptions {
5
5
  }
6
6
  /**
7
7
  * hook to run a hook for each item in the context
8
- * uses `context.data` in a before hook
9
- * uses `context.result` in an after hook
8
+ * uses `context.result` if it is existent. otherwise uses context.data
10
9
  */
11
10
  export declare const runPerItem: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(actionPerItem: (item: any, context: H) => Promisable<any>, _options?: HookRunPerItemOptions) => (context: H) => Promise<H>;
@@ -7,8 +7,7 @@ const makeOptions = (options) => {
7
7
  };
8
8
  /**
9
9
  * hook to run a hook for each item in the context
10
- * uses `context.data` in a before hook
11
- * uses `context.result` in an after hook
10
+ * uses `context.result` if it is existent. otherwise uses context.data
12
11
  */
13
12
  export const runPerItem = (
14
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -6,6 +6,6 @@ export interface HookSetDataOptions {
6
6
  overwrite?: boolean | PredicateWithContext;
7
7
  }
8
8
  /**
9
- * hook to set properties on `context.data` (before-hook) or `context.result` (after-hook)
9
+ * hook to set properties on `context.result` (if existent) or `context.data` (otherwise)
10
10
  */
11
11
  export declare function setData<H extends HookContext = HookContext>(from: PropertyPath, to: PropertyPath, _options?: HookSetDataOptions): (context: H) => H;
@@ -8,7 +8,7 @@ const defaultOptions = {
8
8
  overwrite: true,
9
9
  };
10
10
  /**
11
- * hook to set properties on `context.data` (before-hook) or `context.result` (after-hook)
11
+ * hook to set properties on `context.result` (if existent) or `context.data` (otherwise)
12
12
  */
13
13
  export function setData(from, to, _options) {
14
14
  const options = Object.assign({}, defaultOptions, _options);
@@ -2,7 +2,7 @@ import type { DebouncedFunc } from "lodash";
2
2
  import type { Application, Id } from "@feathersjs/feathers";
3
3
  import type { DebouncedFunctionApp, DebouncedStoreOptions } from "./types";
4
4
  export declare const makeDefaultOptions: () => DebouncedStoreOptions;
5
- export declare type DebouncedService<T = any> = T & {
5
+ export type DebouncedService<T = any> = T & {
6
6
  debouncedStore: DebouncedStore;
7
7
  };
8
8
  export declare class DebouncedStore {
@@ -4,7 +4,7 @@ export interface InitDebounceMixinOptions {
4
4
  blacklist: string[];
5
5
  [key: string]: unknown;
6
6
  }
7
- export declare type DebouncedFunctionApp = (app?: Application) => void | Promise<void>;
7
+ export type DebouncedFunctionApp = (app?: Application) => void | Promise<void>;
8
8
  export interface DebouncedStoreOptions {
9
9
  leading: boolean;
10
10
  maxWait: number | undefined;
@@ -1,3 +1,3 @@
1
1
  import type { HookContext } from "@feathersjs/feathers";
2
- export declare type Predicate<T = any> = (item: T) => boolean;
3
- export declare type PredicateWithContext<T = any> = (item: T, context: HookContext) => boolean;
2
+ export type Predicate<T = any> = (item: T) => boolean;
3
+ export type PredicateWithContext<T = any> = (item: T, context: HookContext) => boolean;
@@ -1,3 +1,3 @@
1
- export declare type MaybeArray<T> = T | T[];
2
- export declare type Promisable<T> = T | Promise<T>;
3
- export declare type Path = Array<string | number>;
1
+ export type MaybeArray<T> = T | T[];
2
+ export type Promisable<T> = T | Promise<T>;
3
+ export type Path = Array<string | number>;
@@ -19,9 +19,7 @@ export function filterQuery(query, _options) {
19
19
  }
20
20
  if (service &&
21
21
  "filterQuery" in service &&
22
- // @ts-expect-error service is of type 'never'
23
22
  typeof service.filterQuery === "function") {
24
- // @ts-expect-error service has no filterQuery method
25
23
  return service.filterQuery({ query }, optionsForFilterQuery);
26
24
  }
27
25
  else {
@@ -1,10 +1,10 @@
1
1
  import type { HookContext } from "@feathersjs/feathers";
2
- export interface GetItemsIsArrayOptions<T = any> {
2
+ export interface GetItemsIsArrayResult<T = any> {
3
3
  items: T[];
4
4
  isArray: boolean;
5
5
  }
6
6
  /**
7
7
  * util to get items from context, return it as an array, no matter if it is an array or not
8
- * in a before hook, it uses `context.data`. in an after hook, it uses `context.result`
8
+ * uses `context.result` if existent. uses `context.data` otherwise
9
9
  */
10
- export declare const getItemsIsArray: <T = any, H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(context: H) => GetItemsIsArrayOptions<T>;
10
+ export declare const getItemsIsArray: <T = any, H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(context: H) => GetItemsIsArrayResult<T>;
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * util to get items from context, return it as an array, no matter if it is an array or not
3
- * in a before hook, it uses `context.data`. in an after hook, it uses `context.result`
3
+ * uses `context.result` if existent. uses `context.data` otherwise
4
4
  */
5
5
  export const getItemsIsArray = (context) => {
6
- let itemOrItems = context.type === "before" ? context.data : context.result;
6
+ let itemOrItems = context.result !== undefined ? context.result : context.data;
7
7
  itemOrItems =
8
8
  itemOrItems && context.method === "find"
9
9
  ? itemOrItems.data || itemOrItems
@@ -11,7 +11,7 @@ export const getPaginate = (context) => {
11
11
  if (context.params.paginate === false) {
12
12
  return undefined;
13
13
  }
14
- let options = context.service.options || {};
14
+ let options = context.service?.options || {};
15
15
  options = {
16
16
  ...options,
17
17
  ...context.params.adapter,
@@ -3,7 +3,7 @@ import { getPaginate } from "./getPaginate";
3
3
  * util to check if a hook is a paginated hook using `getPaginate`
4
4
  */
5
5
  export const isPaginated = (context) => {
6
- if (context.params.paginate === false) {
6
+ if (context.params.paginate === false || context.method !== "find") {
7
7
  return false;
8
8
  }
9
9
  const paginate = getPaginate(context);
@@ -1,8 +1,8 @@
1
1
  import type { Path } from "../../typesInternal";
2
2
  import type { FilterQueryOptions } from "../filterQuery";
3
- export declare type Handle = "target" | "source" | "combine" | "intersect" | "intersectOrFull";
4
- export declare type FirstLast = "first" | "last";
5
- export declare type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
3
+ export type Handle = "target" | "source" | "combine" | "intersect" | "intersectOrFull";
4
+ export type FirstLast = "first" | "last";
5
+ export type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
6
6
  export interface MergeQueryOptions<T> extends FilterQueryOptions<T> {
7
7
  defaultHandle: Handle;
8
8
  actionOnEmptyIntersect: ActionOnEmptyIntersect;
@@ -1,5 +1,5 @@
1
1
  import type { HookContext } from "@feathersjs/feathers";
2
- export declare type ShouldSkipOptions = {
2
+ export type ShouldSkipOptions = {
3
3
  notSkippable?: boolean;
4
4
  };
5
5
  /**
@@ -16,17 +16,14 @@ export const shouldSkip = (hookName, context, options) => {
16
16
  if (skipHooks.includes(hookName)) {
17
17
  return true;
18
18
  }
19
- if (skipHooks.includes("all")) {
19
+ else if (skipHooks.includes("all")) {
20
20
  return true;
21
21
  }
22
- if (type === "before") {
23
- return (skipHooks.includes(`before:${hookName}`) || skipHooks.includes("before"));
24
- }
25
- if (type === "after") {
26
- return (skipHooks.includes(`after:${hookName}`) || skipHooks.includes("after"));
22
+ else if (skipHooks.includes(type)) {
23
+ return true;
27
24
  }
28
- if (type === "error") {
29
- return (skipHooks.includes(`error:${hookName}`) || skipHooks.includes("error"));
25
+ else if (skipHooks.includes(`${type}:${hookName}`)) {
26
+ return true;
30
27
  }
31
28
  return false;
32
29
  };
@@ -1,5 +1,5 @@
1
1
  import type { HookContext } from "@feathersjs/feathers";
2
- export declare type OnDeleteAction = "cascade" | "set null";
2
+ export type OnDeleteAction = "cascade" | "set null";
3
3
  export interface OnDeleteOptions {
4
4
  keyThere: string;
5
5
  keyHere: string;
@@ -5,7 +5,6 @@ export interface HookRunPerItemOptions {
5
5
  }
6
6
  /**
7
7
  * hook to run a hook for each item in the context
8
- * uses `context.data` in a before hook
9
- * uses `context.result` in an after hook
8
+ * uses `context.result` if it is existent. otherwise uses context.data
10
9
  */
11
10
  export declare const runPerItem: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(actionPerItem: (item: any, context: H) => Promisable<any>, _options?: HookRunPerItemOptions) => (context: H) => Promise<H>;
@@ -19,8 +19,7 @@ const makeOptions = (options) => {
19
19
  };
20
20
  /**
21
21
  * hook to run a hook for each item in the context
22
- * uses `context.data` in a before hook
23
- * uses `context.result` in an after hook
22
+ * uses `context.result` if it is existent. otherwise uses context.data
24
23
  */
25
24
  const runPerItem = (
26
25
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -6,6 +6,6 @@ export interface HookSetDataOptions {
6
6
  overwrite?: boolean | PredicateWithContext;
7
7
  }
8
8
  /**
9
- * hook to set properties on `context.data` (before-hook) or `context.result` (after-hook)
9
+ * hook to set properties on `context.result` (if existent) or `context.data` (otherwise)
10
10
  */
11
11
  export declare function setData<H extends HookContext = HookContext>(from: PropertyPath, to: PropertyPath, _options?: HookSetDataOptions): (context: H) => H;
@@ -14,7 +14,7 @@ const defaultOptions = {
14
14
  overwrite: true,
15
15
  };
16
16
  /**
17
- * hook to set properties on `context.data` (before-hook) or `context.result` (after-hook)
17
+ * hook to set properties on `context.result` (if existent) or `context.data` (otherwise)
18
18
  */
19
19
  function setData(from, to, _options) {
20
20
  const options = Object.assign({}, defaultOptions, _options);
@@ -2,7 +2,7 @@ import type { DebouncedFunc } from "lodash";
2
2
  import type { Application, Id } from "@feathersjs/feathers";
3
3
  import type { DebouncedFunctionApp, DebouncedStoreOptions } from "./types";
4
4
  export declare const makeDefaultOptions: () => DebouncedStoreOptions;
5
- export declare type DebouncedService<T = any> = T & {
5
+ export type DebouncedService<T = any> = T & {
6
6
  debouncedStore: DebouncedStore;
7
7
  };
8
8
  export declare class DebouncedStore {
@@ -4,7 +4,7 @@ export interface InitDebounceMixinOptions {
4
4
  blacklist: string[];
5
5
  [key: string]: unknown;
6
6
  }
7
- export declare type DebouncedFunctionApp = (app?: Application) => void | Promise<void>;
7
+ export type DebouncedFunctionApp = (app?: Application) => void | Promise<void>;
8
8
  export interface DebouncedStoreOptions {
9
9
  leading: boolean;
10
10
  maxWait: number | undefined;
package/dist/types.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { HookContext } from "@feathersjs/feathers";
2
- export declare type Predicate<T = any> = (item: T) => boolean;
3
- export declare type PredicateWithContext<T = any> = (item: T, context: HookContext) => boolean;
2
+ export type Predicate<T = any> = (item: T) => boolean;
3
+ export type PredicateWithContext<T = any> = (item: T, context: HookContext) => boolean;
@@ -1,3 +1,3 @@
1
- export declare type MaybeArray<T> = T | T[];
2
- export declare type Promisable<T> = T | Promise<T>;
3
- export declare type Path = Array<string | number>;
1
+ export type MaybeArray<T> = T | T[];
2
+ export type Promisable<T> = T | Promise<T>;
3
+ export type Path = Array<string | number>;
@@ -34,9 +34,7 @@ function filterQuery(query, _options) {
34
34
  }
35
35
  if (service &&
36
36
  "filterQuery" in service &&
37
- // @ts-expect-error service is of type 'never'
38
37
  typeof service.filterQuery === "function") {
39
- // @ts-expect-error service has no filterQuery method
40
38
  return service.filterQuery({ query }, optionsForFilterQuery);
41
39
  }
42
40
  else {
@@ -1,10 +1,10 @@
1
1
  import type { HookContext } from "@feathersjs/feathers";
2
- export interface GetItemsIsArrayOptions<T = any> {
2
+ export interface GetItemsIsArrayResult<T = any> {
3
3
  items: T[];
4
4
  isArray: boolean;
5
5
  }
6
6
  /**
7
7
  * util to get items from context, return it as an array, no matter if it is an array or not
8
- * in a before hook, it uses `context.data`. in an after hook, it uses `context.result`
8
+ * uses `context.result` if existent. uses `context.data` otherwise
9
9
  */
10
- export declare const getItemsIsArray: <T = any, H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(context: H) => GetItemsIsArrayOptions<T>;
10
+ export declare const getItemsIsArray: <T = any, H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(context: H) => GetItemsIsArrayResult<T>;
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getItemsIsArray = void 0;
4
4
  /**
5
5
  * util to get items from context, return it as an array, no matter if it is an array or not
6
- * in a before hook, it uses `context.data`. in an after hook, it uses `context.result`
6
+ * uses `context.result` if existent. uses `context.data` otherwise
7
7
  */
8
8
  const getItemsIsArray = (context) => {
9
- let itemOrItems = context.type === "before" ? context.data : context.result;
9
+ let itemOrItems = context.result !== undefined ? context.result : context.data;
10
10
  itemOrItems =
11
11
  itemOrItems && context.method === "find"
12
12
  ? itemOrItems.data || itemOrItems
@@ -8,13 +8,14 @@ exports.getPaginate = void 0;
8
8
  * 3. it uses `context.params.adapter` if it exists
9
9
  */
10
10
  const getPaginate = (context) => {
11
+ var _a;
11
12
  if (Object.prototype.hasOwnProperty.call(context.params, "paginate")) {
12
13
  return context.params.paginate || undefined;
13
14
  }
14
15
  if (context.params.paginate === false) {
15
16
  return undefined;
16
17
  }
17
- let options = context.service.options || {};
18
+ let options = ((_a = context.service) === null || _a === void 0 ? void 0 : _a.options) || {};
18
19
  options = Object.assign(Object.assign({}, options), context.params.adapter);
19
20
  return options.paginate || undefined;
20
21
  };
@@ -6,7 +6,7 @@ const getPaginate_1 = require("./getPaginate");
6
6
  * util to check if a hook is a paginated hook using `getPaginate`
7
7
  */
8
8
  const isPaginated = (context) => {
9
- if (context.params.paginate === false) {
9
+ if (context.params.paginate === false || context.method !== "find") {
10
10
  return false;
11
11
  }
12
12
  const paginate = (0, getPaginate_1.getPaginate)(context);
@@ -1,8 +1,8 @@
1
1
  import type { Path } from "../../typesInternal";
2
2
  import type { FilterQueryOptions } from "../filterQuery";
3
- export declare type Handle = "target" | "source" | "combine" | "intersect" | "intersectOrFull";
4
- export declare type FirstLast = "first" | "last";
5
- export declare type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
3
+ export type Handle = "target" | "source" | "combine" | "intersect" | "intersectOrFull";
4
+ export type FirstLast = "first" | "last";
5
+ export type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
6
6
  export interface MergeQueryOptions<T> extends FilterQueryOptions<T> {
7
7
  defaultHandle: Handle;
8
8
  actionOnEmptyIntersect: ActionOnEmptyIntersect;
@@ -1,5 +1,5 @@
1
1
  import type { HookContext } from "@feathersjs/feathers";
2
- export declare type ShouldSkipOptions = {
2
+ export type ShouldSkipOptions = {
3
3
  notSkippable?: boolean;
4
4
  };
5
5
  /**
@@ -19,17 +19,14 @@ const shouldSkip = (hookName, context, options) => {
19
19
  if (skipHooks.includes(hookName)) {
20
20
  return true;
21
21
  }
22
- if (skipHooks.includes("all")) {
22
+ else if (skipHooks.includes("all")) {
23
23
  return true;
24
24
  }
25
- if (type === "before") {
26
- return (skipHooks.includes(`before:${hookName}`) || skipHooks.includes("before"));
27
- }
28
- if (type === "after") {
29
- return (skipHooks.includes(`after:${hookName}`) || skipHooks.includes("after"));
25
+ else if (skipHooks.includes(type)) {
26
+ return true;
30
27
  }
31
- if (type === "error") {
32
- return (skipHooks.includes(`error:${hookName}`) || skipHooks.includes("error"));
28
+ else if (skipHooks.includes(`${type}:${hookName}`)) {
29
+ return true;
33
30
  }
34
31
  return false;
35
32
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feathers-utils",
3
- "version": "2.0.0-8",
3
+ "version": "2.0.0-9",
4
4
  "description": "Some utils for projects using '@feathersjs/feathers'",
5
5
  "author": "fratzinger",
6
6
  "repository": {
@@ -43,35 +43,35 @@
43
43
  "lint": "eslint . --ext .js,.jsx,.ts,.tsx"
44
44
  },
45
45
  "dependencies": {
46
- "@feathersjs/adapter-commons": "5.0.0-pre.29",
47
- "@feathersjs/errors": "5.0.0-pre.29",
48
- "@feathersjs/feathers": "5.0.0-pre.29",
49
- "feathers-hooks-common": "^7.0.0-pre.0",
46
+ "@feathersjs/adapter-commons": "5.0.0-pre.33",
47
+ "@feathersjs/errors": "5.0.0-pre.33",
48
+ "@feathersjs/feathers": "5.0.0-pre.33",
49
+ "feathers-hooks-common": "^7.0.0-pre.1",
50
50
  "lodash": "^4.17.21",
51
- "type-fest": "^2.19.0"
51
+ "type-fest": "^3.2.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@feathersjs/memory": "^5.0.0-pre.20",
54
+ "@feathersjs/memory": "^5.0.0-pre.33",
55
55
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
56
- "@types/lodash": "^4.14.185",
57
- "@types/mocha": "^9.1.1",
58
- "@types/node": "^18.7.18",
59
- "@typescript-eslint/eslint-plugin": "^5.37.0",
60
- "@typescript-eslint/parser": "^5.37.0",
56
+ "@types/lodash": "^4.14.189",
57
+ "@types/mocha": "^10.0.0",
58
+ "@types/node": "^18.11.9",
59
+ "@typescript-eslint/eslint-plugin": "^5.44.0",
60
+ "@typescript-eslint/parser": "^5.44.0",
61
61
  "cross-env": "^7.0.3",
62
- "eslint": "^8.23.1",
62
+ "eslint": "^8.28.0",
63
63
  "eslint-config-prettier": "^8.5.0",
64
- "eslint-import-resolver-typescript": "^3.5.1",
64
+ "eslint-import-resolver-typescript": "^3.5.2",
65
65
  "eslint-plugin-import": "^2.26.0",
66
66
  "eslint-plugin-prettier": "^4.2.1",
67
67
  "eslint-plugin-security": "^1.5.0",
68
68
  "feathers-memory": "^4.1.0",
69
- "mocha": "^10.0.0",
69
+ "mocha": "^10.1.0",
70
70
  "np": "^7.6.2",
71
71
  "nyc": "^15.1.0",
72
- "prettier": "^2.7.1",
72
+ "prettier": "^2.8.0",
73
73
  "shx": "^0.3.4",
74
74
  "ts-node": "^10.9.1",
75
- "typescript": "^4.8.3"
75
+ "typescript": "^4.9.3"
76
76
  }
77
77
  }
@@ -21,8 +21,7 @@ const makeOptions = (
21
21
 
22
22
  /**
23
23
  * hook to run a hook for each item in the context
24
- * uses `context.data` in a before hook
25
- * uses `context.result` in an after hook
24
+ * uses `context.result` if it is existent. otherwise uses context.data
26
25
  */
27
26
  export const runPerItem = <H extends HookContext = HookContext>(
28
27
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -20,7 +20,7 @@ const defaultOptions: Required<HookSetDataOptions> = {
20
20
  };
21
21
 
22
22
  /**
23
- * hook to set properties on `context.data` (before-hook) or `context.result` (after-hook)
23
+ * hook to set properties on `context.result` (if existent) or `context.data` (otherwise)
24
24
  */
25
25
  export function setData<H extends HookContext = HookContext>(
26
26
  from: PropertyPath,
@@ -34,10 +34,8 @@ export function filterQuery<T>(query: Query, _options?: FilterQueryOptions<T>) {
34
34
  if (
35
35
  service &&
36
36
  "filterQuery" in service &&
37
- // @ts-expect-error service is of type 'never'
38
37
  typeof service.filterQuery === "function"
39
38
  ) {
40
- // @ts-expect-error service has no filterQuery method
41
39
  return service.filterQuery({ query }, optionsForFilterQuery);
42
40
  } else {
43
41
  return plainFilterQuery(query, optionsForFilterQuery);
@@ -1,18 +1,18 @@
1
1
  import type { HookContext } from "@feathersjs/feathers";
2
2
 
3
- export interface GetItemsIsArrayOptions<T = any> {
3
+ export interface GetItemsIsArrayResult<T = any> {
4
4
  items: T[];
5
5
  isArray: boolean;
6
6
  }
7
7
 
8
8
  /**
9
9
  * util to get items from context, return it as an array, no matter if it is an array or not
10
- * in a before hook, it uses `context.data`. in an after hook, it uses `context.result`
10
+ * uses `context.result` if existent. uses `context.data` otherwise
11
11
  */
12
12
  export const getItemsIsArray = <T = any, H extends HookContext = HookContext>(
13
13
  context: H
14
- ): GetItemsIsArrayOptions<T> => {
15
- let itemOrItems = context.type === "before" ? context.data : context.result;
14
+ ): GetItemsIsArrayResult<T> => {
15
+ let itemOrItems = context.result !== undefined ? context.result : context.data;
16
16
  itemOrItems =
17
17
  itemOrItems && context.method === "find"
18
18
  ? itemOrItems.data || itemOrItems
@@ -17,7 +17,7 @@ export const getPaginate = <H extends HookContext = HookContext>(
17
17
  if (context.params.paginate === false) {
18
18
  return undefined;
19
19
  }
20
- let options = context.service.options || {};
20
+ let options = context.service?.options || {};
21
21
 
22
22
  options = {
23
23
  ...options,
@@ -7,7 +7,7 @@ import { getPaginate } from "./getPaginate";
7
7
  export const isPaginated = <H extends HookContext = HookContext>(
8
8
  context: H
9
9
  ): boolean => {
10
- if (context.params.paginate === false) {
10
+ if (context.params.paginate === false || context.method !== "find") {
11
11
  return false;
12
12
  }
13
13
 
@@ -31,24 +31,12 @@ export const shouldSkip = <
31
31
  const { type } = context;
32
32
  if (skipHooks.includes(hookName)) {
33
33
  return true;
34
- }
35
- if (skipHooks.includes("all")) {
34
+ } else if (skipHooks.includes("all")) {
35
+ return true;
36
+ } else if (skipHooks.includes(type)) {
37
+ return true;
38
+ } else if (skipHooks.includes(`${type}:${hookName}`)) {
36
39
  return true;
37
- }
38
- if (type === "before") {
39
- return (
40
- skipHooks.includes(`before:${hookName}`) || skipHooks.includes("before")
41
- );
42
- }
43
- if (type === "after") {
44
- return (
45
- skipHooks.includes(`after:${hookName}`) || skipHooks.includes("after")
46
- );
47
- }
48
- if (type === "error") {
49
- return (
50
- skipHooks.includes(`error:${hookName}`) || skipHooks.includes("error")
51
- );
52
40
  }
53
41
 
54
42
  return false;