feathers-utils 1.9.2 → 1.9.5

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.
@@ -1,3 +1,3 @@
1
1
  import type { HookRunPerItemOptions, ReturnAsyncHook, Promisable } from "../types";
2
2
  import type { HookContext } from "@feathersjs/feathers";
3
- export declare const runPerItem: (actionPerItem: (item: any, context: HookContext) => Promisable<any>, options: HookRunPerItemOptions) => ReturnAsyncHook;
3
+ export declare const runPerItem: (actionPerItem: (item: any, context: HookContext) => Promisable<any>, _options?: HookRunPerItemOptions | undefined) => ReturnAsyncHook;
@@ -8,8 +8,8 @@ const makeOptions = (options) => {
8
8
  };
9
9
  export const runPerItem = (
10
10
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
- actionPerItem, options) => {
12
- options = makeOptions(options);
11
+ actionPerItem, _options) => {
12
+ const options = makeOptions(_options);
13
13
  return async (context) => {
14
14
  if (shouldSkip("runForItems", context)) {
15
15
  return context;
@@ -4,7 +4,7 @@ import { runPerItem } from "./hooks/runPerItem";
4
4
  export declare const hooks: {
5
5
  checkMulti: typeof checkMulti;
6
6
  setData: typeof setData;
7
- runPerItem: (actionPerItem: (item: any, context: import("@feathersjs/feathers").HookContext<any, import("@feathersjs/feathers").Service<any>>) => any, options: import("./types").HookRunPerItemOptions) => import("./types").ReturnAsyncHook;
7
+ runPerItem: (actionPerItem: (item: any, context: import("@feathersjs/feathers").HookContext<any, import("@feathersjs/feathers").Service<any>>) => any, _options?: import("./types").HookRunPerItemOptions | undefined) => import("./types").ReturnAsyncHook;
8
8
  };
9
9
  export { checkMulti };
10
10
  export { setData };
@@ -1,10 +1,18 @@
1
1
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
2
  export const getItemsIsArray = (context) => {
3
- let itemOrItems = context.type === "before" ? context.data : context.result;
4
- itemOrItems = itemOrItems && context.method === "find" ? (itemOrItems.data || itemOrItems) : itemOrItems;
3
+ let itemOrItems = context.type === "before"
4
+ ? context.data
5
+ : context.result;
6
+ itemOrItems = itemOrItems && context.method === "find"
7
+ ? (itemOrItems.data || itemOrItems)
8
+ : itemOrItems;
5
9
  const isArray = Array.isArray(itemOrItems);
6
10
  return {
7
- items: (isArray) ? itemOrItems : [itemOrItems],
11
+ items: (isArray)
12
+ ? itemOrItems
13
+ : (itemOrItems != null)
14
+ ? [itemOrItems]
15
+ : [],
8
16
  isArray
9
17
  };
10
18
  };
@@ -1,3 +1,3 @@
1
1
  import type { HookRunPerItemOptions, ReturnAsyncHook, Promisable } from "../types";
2
2
  import type { HookContext } from "@feathersjs/feathers";
3
- export declare const runPerItem: (actionPerItem: (item: any, context: HookContext) => Promisable<any>, options: HookRunPerItemOptions) => ReturnAsyncHook;
3
+ export declare const runPerItem: (actionPerItem: (item: any, context: HookContext) => Promisable<any>, _options?: HookRunPerItemOptions | undefined) => ReturnAsyncHook;
@@ -20,8 +20,8 @@ const makeOptions = (options) => {
20
20
  };
21
21
  const runPerItem = (
22
22
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- actionPerItem, options) => {
24
- options = makeOptions(options);
23
+ actionPerItem, _options) => {
24
+ const options = makeOptions(_options);
25
25
  return (context) => __awaiter(void 0, void 0, void 0, function* () {
26
26
  if ((0, shouldSkip_1.shouldSkip)("runForItems", context)) {
27
27
  return context;
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { runPerItem } from "./hooks/runPerItem";
4
4
  export declare const hooks: {
5
5
  checkMulti: typeof checkMulti;
6
6
  setData: typeof setData;
7
- runPerItem: (actionPerItem: (item: any, context: import("@feathersjs/feathers").HookContext<any, import("@feathersjs/feathers").Service<any>>) => any, options: import("./types").HookRunPerItemOptions) => import("./types").ReturnAsyncHook;
7
+ runPerItem: (actionPerItem: (item: any, context: import("@feathersjs/feathers").HookContext<any, import("@feathersjs/feathers").Service<any>>) => any, _options?: import("./types").HookRunPerItemOptions | undefined) => import("./types").ReturnAsyncHook;
8
8
  };
9
9
  export { checkMulti };
10
10
  export { setData };
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -3,11 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getItemsIsArray = void 0;
4
4
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
5
  const getItemsIsArray = (context) => {
6
- let itemOrItems = context.type === "before" ? context.data : context.result;
7
- itemOrItems = itemOrItems && context.method === "find" ? (itemOrItems.data || itemOrItems) : itemOrItems;
6
+ let itemOrItems = context.type === "before"
7
+ ? context.data
8
+ : context.result;
9
+ itemOrItems = itemOrItems && context.method === "find"
10
+ ? (itemOrItems.data || itemOrItems)
11
+ : itemOrItems;
8
12
  const isArray = Array.isArray(itemOrItems);
9
13
  return {
10
- items: (isArray) ? itemOrItems : [itemOrItems],
14
+ items: (isArray)
15
+ ? itemOrItems
16
+ : (itemOrItems != null)
17
+ ? [itemOrItems]
18
+ : [],
11
19
  isArray
12
20
  };
13
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feathers-utils",
3
- "version": "1.9.2",
3
+ "version": "1.9.5",
4
4
  "description": "Some utils for projects using '@feathersjs/feathers'",
5
5
  "author": "fratzinger",
6
6
  "repository": {
@@ -46,22 +46,22 @@
46
46
  },
47
47
  "devDependencies": {
48
48
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
49
- "@types/lodash": "^4.14.178",
49
+ "@types/lodash": "^4.14.179",
50
50
  "@types/mocha": "^9.1.0",
51
- "@types/node": "^17.0.14",
52
- "@typescript-eslint/eslint-plugin": "^5.10.2",
53
- "@typescript-eslint/parser": "^5.10.2",
51
+ "@types/node": "^17.0.21",
52
+ "@typescript-eslint/eslint-plugin": "^5.13.0",
53
+ "@typescript-eslint/parser": "^5.13.0",
54
54
  "cross-env": "^7.0.3",
55
- "eslint": "^8.8.0",
55
+ "eslint": "^8.10.0",
56
56
  "eslint-import-resolver-typescript": "^2.5.0",
57
57
  "eslint-plugin-import": "^2.25.4",
58
58
  "eslint-plugin-security": "^1.4.0",
59
59
  "feathers-memory": "^4.1.0",
60
- "mocha": "^9.2.0",
60
+ "mocha": "^9.2.1",
61
61
  "np": "^7.6.0",
62
62
  "nyc": "^15.1.0",
63
63
  "shx": "^0.3.4",
64
- "ts-node": "^10.4.0",
65
- "typescript": "^4.5.5"
64
+ "ts-node": "^10.5.0",
65
+ "typescript": "^4.6.2"
66
66
  }
67
67
  }
@@ -5,7 +5,7 @@ import type { HookContext } from "@feathersjs/feathers";
5
5
  import { getItemsIsArray } from "../utils/getItemsIsArray";
6
6
 
7
7
  const makeOptions = (
8
- options: HookRunPerItemOptions
8
+ options?: HookRunPerItemOptions
9
9
  ): Required<HookRunPerItemOptions> => {
10
10
  options = options || {};
11
11
  return Object.assign({
@@ -16,9 +16,9 @@ const makeOptions = (
16
16
  export const runPerItem = (
17
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
18
  actionPerItem: (item: any, context: HookContext) => Promisable<any>,
19
- options: HookRunPerItemOptions
19
+ _options?: HookRunPerItemOptions
20
20
  ): ReturnAsyncHook => {
21
- options = makeOptions(options);
21
+ const options = makeOptions(_options);
22
22
  return async (context: HookContext): Promise<HookContext> => {
23
23
  if (shouldSkip("runForItems", context)) { return context; }
24
24
  const { items } = getItemsIsArray(context);
@@ -5,11 +5,19 @@ import type { GetItemsIsArrayOptions } from "..";
5
5
  export const getItemsIsArray = <T = any>(
6
6
  context: HookContext
7
7
  ): GetItemsIsArrayOptions<T> => {
8
- let itemOrItems = context.type === "before" ? context.data : context.result;
9
- itemOrItems = itemOrItems && context.method === "find" ? (itemOrItems.data || itemOrItems) : itemOrItems;
8
+ let itemOrItems = context.type === "before"
9
+ ? context.data
10
+ : context.result;
11
+ itemOrItems = itemOrItems && context.method === "find"
12
+ ? (itemOrItems.data || itemOrItems)
13
+ : itemOrItems;
10
14
  const isArray = Array.isArray(itemOrItems);
11
15
  return {
12
- items: (isArray) ? itemOrItems : [itemOrItems],
16
+ items: (isArray)
17
+ ? itemOrItems
18
+ : (itemOrItems != null)
19
+ ? [itemOrItems]
20
+ : [],
13
21
  isArray
14
22
  };
15
23
  };