feathers-utils 1.5.11 → 1.6.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 (54) hide show
  1. package/.vscode/launch.json +26 -27
  2. package/dist/hooks/checkMulti.d.ts +1 -2
  3. package/dist/hooks/checkMulti.js +6 -8
  4. package/dist/hooks/runPerItem.d.ts +1 -2
  5. package/dist/hooks/runPerItem.js +4 -6
  6. package/dist/hooks/setData.d.ts +2 -2
  7. package/dist/hooks/setData.js +7 -3
  8. package/dist/index.d.ts +14 -20
  9. package/dist/index.js +30 -43
  10. package/dist/mixins/debounce-mixin/DebouncedStore.d.ts +2 -3
  11. package/dist/mixins/debounce-mixin/DebouncedStore.js +2 -2
  12. package/dist/mixins/debounce-mixin/index.d.ts +2 -2
  13. package/dist/mixins/debounce-mixin/index.js +6 -25
  14. package/dist/utils/addHook.d.ts +1 -2
  15. package/dist/utils/addHook.js +2 -1
  16. package/dist/utils/filterQuery.d.ts +1 -2
  17. package/dist/utils/filterQuery.js +2 -1
  18. package/dist/utils/isMulti.d.ts +1 -2
  19. package/dist/utils/isMulti.js +2 -1
  20. package/dist/utils/markHookForSkip.d.ts +1 -2
  21. package/dist/utils/markHookForSkip.js +4 -6
  22. package/dist/utils/mergeQuery/index.d.ts +1 -2
  23. package/dist/utils/mergeQuery/index.js +7 -6
  24. package/dist/utils/mergeQuery/mergeArrays.d.ts +1 -2
  25. package/dist/utils/mergeQuery/mergeArrays.js +2 -1
  26. package/dist/utils/pushSet.d.ts +1 -2
  27. package/dist/utils/pushSet.js +2 -1
  28. package/dist/utils/shouldSkip.d.ts +1 -2
  29. package/dist/utils/shouldSkip.js +2 -1
  30. package/package.json +1 -1
  31. package/src/hooks/checkMulti.ts +3 -5
  32. package/src/hooks/runPerItem.ts +3 -5
  33. package/src/hooks/setData.ts +13 -10
  34. package/src/index.ts +14 -23
  35. package/src/mixins/debounce-mixin/DebouncedStore.ts +3 -5
  36. package/src/mixins/debounce-mixin/index.ts +3 -2
  37. package/src/types.ts +1 -1
  38. package/src/utils/addHook.ts +2 -4
  39. package/src/utils/filterQuery.ts +2 -4
  40. package/src/utils/isMulti.ts +2 -4
  41. package/src/utils/markHookForSkip.ts +3 -5
  42. package/src/utils/mergeQuery/index.ts +4 -6
  43. package/src/utils/mergeQuery/mergeArrays.ts +2 -4
  44. package/src/utils/pushSet.ts +2 -4
  45. package/src/utils/shouldSkip.ts +2 -4
  46. package/test/hooks/checkMulti.test.ts +1 -1
  47. package/test/hooks/setData.test.ts +28 -1
  48. package/test/mixins/debounce-mixin.test.ts +1 -1
  49. package/test/utils/addHook.test.ts +1 -1
  50. package/test/utils/isMulti.test.ts +1 -1
  51. package/test/utils/markHookForSkip.test.ts +1 -2
  52. package/test/utils/mergeQuery.test.ts +1 -1
  53. package/test/utils/pushSet.test.ts +1 -1
  54. package/test/utils/shouldSkip.test.ts +1 -1
@@ -1,29 +1,28 @@
1
1
  {
2
- "version": "0.2.0",
3
- "configurations": [
4
- {
5
- "type": "node",
6
- "request": "launch",
7
- "name": "Mocha Tests",
8
- "program": "${workspaceFolder}/node_modules/mocha/bin/mocha",
9
- "args": [
10
- "--require",
11
- "ts-node/register",
12
- "--timeout",
13
- "999999",
14
- "--colors",
15
- "--recursive",
16
- ],
17
- "internalConsoleOptions": "openOnSessionStart",
18
- "env": {
19
- "NODE_ENV": "test",
20
- "TS_NODE_PROJECT": "tsconfig.test.json"
21
- },
22
- "outputCapture": "std",
23
- "skipFiles": [
24
- "<node_internals>/**"
25
- ]
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "type": "node",
6
+ "request": "launch",
7
+ "name": "Mocha Tests",
8
+ "program": "${workspaceFolder}/node_modules/mocha/bin/mocha",
9
+ "args": [
10
+ "--require",
11
+ "ts-node/register",
12
+ "--timeout",
13
+ "999999",
14
+ "--colors",
15
+ "--recursive",
16
+ ],
17
+ "internalConsoleOptions": "openOnSessionStart",
18
+ "env": {
19
+ "NODE_ENV": "test",
20
+ "TS_NODE_PROJECT": "tsconfig.test.json"
26
21
  },
27
- ]
28
- }
29
-
22
+ "outputCapture": "std",
23
+ "skipFiles": [
24
+ "<node_internals>/**"
25
+ ]
26
+ }
27
+ ]
28
+ }
@@ -1,3 +1,2 @@
1
1
  import type { HookContext } from "@feathersjs/feathers";
2
- declare function checkMulti(): ((context: HookContext) => HookContext);
3
- export default checkMulti;
2
+ export declare function checkMulti(): ((context: HookContext) => HookContext);
@@ -1,18 +1,16 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkMulti = void 0;
6
4
  const errors_1 = require("@feathersjs/errors");
7
- const shouldSkip_1 = __importDefault(require("../utils/shouldSkip"));
8
- const isMulti_1 = __importDefault(require("../utils/isMulti"));
5
+ const shouldSkip_1 = require("../utils/shouldSkip");
6
+ const isMulti_1 = require("../utils/isMulti");
9
7
  function checkMulti() {
10
8
  return (context) => {
11
- if (shouldSkip_1.default("checkMulti", context)) {
9
+ if (shouldSkip_1.shouldSkip("checkMulti", context)) {
12
10
  return context;
13
11
  }
14
12
  const { service, method } = context;
15
- if (!service.allowsMulti || !isMulti_1.default(context) || method === "find") {
13
+ if (!service.allowsMulti || !isMulti_1.isMulti(context) || method === "find") {
16
14
  return context;
17
15
  }
18
16
  if (!service.allowsMulti(method)) {
@@ -21,4 +19,4 @@ function checkMulti() {
21
19
  return context;
22
20
  };
23
21
  }
24
- exports.default = checkMulti;
22
+ exports.checkMulti = checkMulti;
@@ -1,4 +1,3 @@
1
1
  import type { HookRunPerItemOptions } from "../types";
2
2
  import type { HookContext } from "@feathersjs/feathers";
3
- declare const runPerItem: (actionPerItem: (item: unknown, context: HookContext) => Promise<unknown>, options: HookRunPerItemOptions) => (context: HookContext) => Promise<HookContext>;
4
- export default runPerItem;
3
+ export declare const runPerItem: (actionPerItem: (item: unknown, context: HookContext) => Promise<unknown>, options: HookRunPerItemOptions) => (context: HookContext) => Promise<HookContext>;
@@ -8,12 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.runPerItem = void 0;
15
13
  const feathers_hooks_common_1 = require("feathers-hooks-common");
16
- const shouldSkip_1 = __importDefault(require("../utils/shouldSkip"));
14
+ const shouldSkip_1 = require("../utils/shouldSkip");
17
15
  const makeOptions = (options) => {
18
16
  options = options || {};
19
17
  return Object.assign({
@@ -23,7 +21,7 @@ const makeOptions = (options) => {
23
21
  const runPerItem = (actionPerItem, options) => {
24
22
  options = makeOptions(options);
25
23
  return (context) => __awaiter(void 0, void 0, void 0, function* () {
26
- if (shouldSkip_1.default("runForItems", context)) {
24
+ if (shouldSkip_1.shouldSkip("runForItems", context)) {
27
25
  return context;
28
26
  }
29
27
  let items = feathers_hooks_common_1.getItems(context);
@@ -37,4 +35,4 @@ const runPerItem = (actionPerItem, options) => {
37
35
  return context;
38
36
  });
39
37
  };
40
- exports.default = runPerItem;
38
+ exports.runPerItem = runPerItem;
@@ -1,4 +1,4 @@
1
1
  import type { HookContext } from "@feathersjs/feathers";
2
2
  import type { HookSetDataOptions } from "../types";
3
- declare function setData(from: string[], to: string[], _options?: HookSetDataOptions): ((context: HookContext) => HookContext);
4
- export default setData;
3
+ import type { PropertyPath } from "lodash";
4
+ export declare function setData(from: PropertyPath, to: PropertyPath, _options?: HookSetDataOptions): ((context: HookContext) => HookContext);
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.setData = void 0;
6
7
  const get_1 = __importDefault(require("lodash/get"));
7
8
  const set_1 = __importDefault(require("lodash/set"));
8
9
  const has_1 = __importDefault(require("lodash/has"));
@@ -18,13 +19,16 @@ function setData(from, to, _options) {
18
19
  var _a;
19
20
  let items = feathers_hooks_common_1.getItems(context);
20
21
  items = (Array.isArray(items)) ? items : [items];
21
- const val = get_1.default(context, from);
22
- if (val === undefined) {
22
+ if (!has_1.default(context, from)) {
23
23
  if (!((_a = context.params) === null || _a === void 0 ? void 0 : _a.provider) || options.allowUndefined === true) {
24
24
  return context;
25
25
  }
26
+ if (!options.overwrite && items.every((item) => has_1.default(item, to))) {
27
+ return context;
28
+ }
26
29
  throw new errors_1.Forbidden(`Expected field ${from.toString()} not available`);
27
30
  }
31
+ const val = get_1.default(context, from);
28
32
  items.forEach((item) => {
29
33
  if (!options.overwrite && has_1.default(item, to)) {
30
34
  return;
@@ -34,4 +38,4 @@ function setData(from, to, _options) {
34
38
  return context;
35
39
  };
36
40
  }
37
- exports.default = setData;
41
+ exports.setData = setData;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import checkMulti from "./hooks/checkMulti";
2
- import setData from "./hooks/setData";
3
- import runPerItem from "./hooks/runPerItem";
1
+ import { checkMulti } from "./hooks/checkMulti";
2
+ import { setData } from "./hooks/setData";
3
+ import { runPerItem } from "./hooks/runPerItem";
4
4
  export declare const hooks: {
5
5
  checkMulti: typeof checkMulti;
6
6
  setData: typeof setData;
@@ -9,25 +9,19 @@ export declare const hooks: {
9
9
  export { checkMulti };
10
10
  export { setData };
11
11
  export { runPerItem };
12
- import debounceMixin, { DebouncedStore } from "./mixins/debounce-mixin";
12
+ import { debounceMixin, DebouncedStore } from "./mixins/debounce-mixin";
13
13
  export declare const mixins: {
14
14
  debounceMixin: typeof debounceMixin;
15
15
  DebouncedStore: typeof DebouncedStore;
16
16
  };
17
- import addHook from "./utils/addHook";
18
- import isMulti from "./utils/isMulti";
19
- import mergeQuery from "./utils/mergeQuery/index";
20
- import mergeArrays from "./utils/mergeQuery/mergeArrays";
21
- import pushSet from "./utils/pushSet";
22
- import markHookForSkip from "./utils/markHookForSkip";
23
- import shouldSkip from "./utils/shouldSkip";
24
- import filterQuery from "./utils/filterQuery";
25
- export { addHook };
26
- export { isMulti };
27
- export { mergeQuery };
28
- export { mergeArrays };
29
- export { pushSet };
30
- export { markHookForSkip };
31
- export { shouldSkip };
32
- export { filterQuery };
17
+ export { debounceMixin };
18
+ export { DebouncedStore };
19
+ export { addHook } from "./utils/addHook";
20
+ export { isMulti } from "./utils/isMulti";
21
+ export { mergeQuery } from "./utils/mergeQuery/index";
22
+ export { mergeArrays } from "./utils/mergeQuery/mergeArrays";
23
+ export { pushSet } from "./utils/pushSet";
24
+ export { markHookForSkip } from "./utils/markHookForSkip";
25
+ export { shouldSkip } from "./utils/shouldSkip";
26
+ export { filterQuery } from "./utils/filterQuery";
33
27
  export * from "./types";
package/dist/index.js CHANGED
@@ -6,57 +6,44 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
6
6
  if (k2 === undefined) k2 = k;
7
7
  o[k2] = m[k];
8
8
  }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
9
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
22
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
23
11
  };
24
- var __importDefault = (this && this.__importDefault) || function (mod) {
25
- return (mod && mod.__esModule) ? mod : { "default": mod };
26
- };
27
12
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.filterQuery = exports.shouldSkip = exports.markHookForSkip = exports.pushSet = exports.mergeArrays = exports.mergeQuery = exports.isMulti = exports.addHook = exports.mixins = exports.runPerItem = exports.setData = exports.checkMulti = exports.hooks = void 0;
13
+ exports.filterQuery = exports.shouldSkip = exports.markHookForSkip = exports.pushSet = exports.mergeArrays = exports.mergeQuery = exports.isMulti = exports.addHook = exports.DebouncedStore = exports.debounceMixin = exports.mixins = exports.runPerItem = exports.setData = exports.checkMulti = exports.hooks = void 0;
29
14
  // hooks
30
- const checkMulti_1 = __importDefault(require("./hooks/checkMulti"));
31
- exports.checkMulti = checkMulti_1.default;
32
- const setData_1 = __importDefault(require("./hooks/setData"));
33
- exports.setData = setData_1.default;
34
- const runPerItem_1 = __importDefault(require("./hooks/runPerItem"));
35
- exports.runPerItem = runPerItem_1.default;
15
+ const checkMulti_1 = require("./hooks/checkMulti");
16
+ Object.defineProperty(exports, "checkMulti", { enumerable: true, get: function () { return checkMulti_1.checkMulti; } });
17
+ const setData_1 = require("./hooks/setData");
18
+ Object.defineProperty(exports, "setData", { enumerable: true, get: function () { return setData_1.setData; } });
19
+ const runPerItem_1 = require("./hooks/runPerItem");
20
+ Object.defineProperty(exports, "runPerItem", { enumerable: true, get: function () { return runPerItem_1.runPerItem; } });
36
21
  exports.hooks = {
37
- checkMulti: checkMulti_1.default,
38
- setData: setData_1.default,
39
- runPerItem: runPerItem_1.default
22
+ checkMulti: checkMulti_1.checkMulti,
23
+ setData: setData_1.setData,
24
+ runPerItem: runPerItem_1.runPerItem
40
25
  };
41
- const debounce_mixin_1 = __importStar(require("./mixins/debounce-mixin"));
26
+ const debounce_mixin_1 = require("./mixins/debounce-mixin");
27
+ Object.defineProperty(exports, "debounceMixin", { enumerable: true, get: function () { return debounce_mixin_1.debounceMixin; } });
28
+ Object.defineProperty(exports, "DebouncedStore", { enumerable: true, get: function () { return debounce_mixin_1.DebouncedStore; } });
42
29
  exports.mixins = {
43
- debounceMixin: debounce_mixin_1.default,
30
+ debounceMixin: debounce_mixin_1.debounceMixin,
44
31
  DebouncedStore: debounce_mixin_1.DebouncedStore
45
32
  };
46
- const addHook_1 = __importDefault(require("./utils/addHook"));
47
- exports.addHook = addHook_1.default;
48
- const isMulti_1 = __importDefault(require("./utils/isMulti"));
49
- exports.isMulti = isMulti_1.default;
50
- const index_1 = __importDefault(require("./utils/mergeQuery/index"));
51
- exports.mergeQuery = index_1.default;
52
- const mergeArrays_1 = __importDefault(require("./utils/mergeQuery/mergeArrays"));
53
- exports.mergeArrays = mergeArrays_1.default;
54
- const pushSet_1 = __importDefault(require("./utils/pushSet"));
55
- exports.pushSet = pushSet_1.default;
56
- const markHookForSkip_1 = __importDefault(require("./utils/markHookForSkip"));
57
- exports.markHookForSkip = markHookForSkip_1.default;
58
- const shouldSkip_1 = __importDefault(require("./utils/shouldSkip"));
59
- exports.shouldSkip = shouldSkip_1.default;
60
- const filterQuery_1 = __importDefault(require("./utils/filterQuery"));
61
- exports.filterQuery = filterQuery_1.default;
33
+ var addHook_1 = require("./utils/addHook");
34
+ Object.defineProperty(exports, "addHook", { enumerable: true, get: function () { return addHook_1.addHook; } });
35
+ var isMulti_1 = require("./utils/isMulti");
36
+ Object.defineProperty(exports, "isMulti", { enumerable: true, get: function () { return isMulti_1.isMulti; } });
37
+ var index_1 = require("./utils/mergeQuery/index");
38
+ Object.defineProperty(exports, "mergeQuery", { enumerable: true, get: function () { return index_1.mergeQuery; } });
39
+ var mergeArrays_1 = require("./utils/mergeQuery/mergeArrays");
40
+ Object.defineProperty(exports, "mergeArrays", { enumerable: true, get: function () { return mergeArrays_1.mergeArrays; } });
41
+ var pushSet_1 = require("./utils/pushSet");
42
+ Object.defineProperty(exports, "pushSet", { enumerable: true, get: function () { return pushSet_1.pushSet; } });
43
+ var markHookForSkip_1 = require("./utils/markHookForSkip");
44
+ Object.defineProperty(exports, "markHookForSkip", { enumerable: true, get: function () { return markHookForSkip_1.markHookForSkip; } });
45
+ var shouldSkip_1 = require("./utils/shouldSkip");
46
+ Object.defineProperty(exports, "shouldSkip", { enumerable: true, get: function () { return shouldSkip_1.shouldSkip; } });
47
+ var filterQuery_1 = require("./utils/filterQuery");
48
+ Object.defineProperty(exports, "filterQuery", { enumerable: true, get: function () { return filterQuery_1.filterQuery; } });
62
49
  __exportStar(require("./types"), exports);
@@ -2,15 +2,14 @@ import type { DebouncedFunc } from "lodash";
2
2
  import type { Application, Id } from "@feathersjs/feathers";
3
3
  import { DebouncedFunctionApp, DebouncedStoreOptions } from "../../types";
4
4
  export declare const makeDefaultOptions: () => DebouncedStoreOptions;
5
- declare class DebouncedStore {
5
+ export declare class DebouncedStore {
6
6
  private _app;
7
7
  private _options;
8
8
  private _isRunningById;
9
9
  _queueById: Record<string, DebouncedFunc<((id: Id, action: DebouncedFunctionApp) => void | Promise<void>)>>;
10
10
  add: (id: Id, action: (app?: Application<{}> | undefined) => void | Promise<void>) => void | Promise<void> | undefined;
11
- constructor(app: Application, options: Partial<DebouncedStoreOptions>);
11
+ constructor(app: Application, options?: Partial<DebouncedStoreOptions>);
12
12
  private unbounced;
13
13
  private debounceById;
14
14
  cancel(id: Id): void;
15
15
  }
16
- export default DebouncedStore;
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.makeDefaultOptions = void 0;
15
+ exports.DebouncedStore = exports.makeDefaultOptions = void 0;
16
16
  const debounce_1 = __importDefault(require("lodash/debounce"));
17
17
  const makeDefaultOptions = () => {
18
18
  return {
@@ -62,4 +62,4 @@ class DebouncedStore {
62
62
  delete this._queueById[id];
63
63
  }
64
64
  }
65
- exports.default = DebouncedStore;
65
+ exports.DebouncedStore = DebouncedStore;
@@ -1,5 +1,5 @@
1
- import DebouncedStore from "./DebouncedStore";
1
+ import { DebouncedStore } from "./DebouncedStore";
2
2
  import type { Application } from "@feathersjs/feathers";
3
3
  import type { InitDebounceMixinOptions } from "../../types";
4
- export default function initDebounceMixin(options?: Partial<InitDebounceMixinOptions>): ((app: Application) => void);
4
+ export declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): ((app: Application) => void);
5
5
  export { DebouncedStore };
@@ -1,28 +1,9 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.DebouncedStore = void 0;
23
- const DebouncedStore_1 = __importStar(require("./DebouncedStore"));
24
- exports.DebouncedStore = DebouncedStore_1.default;
25
- function initDebounceMixin(options) {
3
+ exports.DebouncedStore = exports.debounceMixin = void 0;
4
+ const DebouncedStore_1 = require("./DebouncedStore");
5
+ Object.defineProperty(exports, "DebouncedStore", { enumerable: true, get: function () { return DebouncedStore_1.DebouncedStore; } });
6
+ function debounceMixin(options) {
26
7
  return (app) => {
27
8
  options = options || {};
28
9
  const defaultOptions = Object.assign(DebouncedStore_1.makeDefaultOptions(), options === null || options === void 0 ? void 0 : options.default);
@@ -36,8 +17,8 @@ function initDebounceMixin(options) {
36
17
  return;
37
18
  }
38
19
  const serviceOptions = Object.assign({}, defaultOptions, options === null || options === void 0 ? void 0 : options[path]);
39
- service.debouncedStore = new DebouncedStore_1.default(app, serviceOptions);
20
+ service.debouncedStore = new DebouncedStore_1.DebouncedStore(app, serviceOptions);
40
21
  });
41
22
  };
42
23
  }
43
- exports.default = initDebounceMixin;
24
+ exports.debounceMixin = debounceMixin;
@@ -1,4 +1,3 @@
1
1
  import type { Application } from "@feathersjs/feathers";
2
2
  import type { AddHookOptions } from "../types";
3
- declare const addHook: (app: Application, hook: unknown, options: AddHookOptions) => void;
4
- export default addHook;
3
+ export declare const addHook: (app: Application, hook: unknown, options: AddHookOptions) => void;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addHook = void 0;
3
4
  const defaultOptions = () => {
4
5
  return {
5
6
  whitelist: ["*"],
@@ -36,4 +37,4 @@ const addHook = (app, hook, options) => {
36
37
  });
37
38
  }
38
39
  };
39
- exports.default = addHook;
40
+ exports.addHook = addHook;
@@ -1,4 +1,3 @@
1
1
  import type { FilterQueryOptions, FilterQueryResult } from "../types";
2
2
  import type { Query } from "@feathersjs/feathers";
3
- declare function filterQuery<T>(query: Query, options?: FilterQueryOptions<T>): FilterQueryResult;
4
- export default filterQuery;
3
+ export declare function filterQuery<T>(query: Query, options?: FilterQueryOptions<T>): FilterQueryResult;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterQuery = void 0;
3
4
  const adapter_commons_1 = require("@feathersjs/adapter-commons");
4
5
  function filterQuery(query, options) {
5
6
  var _a, _b;
@@ -29,4 +30,4 @@ function filterQuery(query, options) {
29
30
  }
30
31
  return adapter_commons_1.filterQuery(query, options);
31
32
  }
32
- exports.default = filterQuery;
33
+ exports.filterQuery = filterQuery;
@@ -1,3 +1,2 @@
1
1
  import type { HookContext } from "@feathersjs/feathers";
2
- declare const isMulti: (context: HookContext) => boolean;
3
- export default isMulti;
2
+ export declare const isMulti: (context: HookContext) => boolean;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isMulti = void 0;
3
4
  const isMulti = (context) => {
4
5
  const { method } = context;
5
6
  if (method === "find") {
@@ -18,4 +19,4 @@ const isMulti = (context) => {
18
19
  }
19
20
  return false;
20
21
  };
21
- exports.default = isMulti;
22
+ exports.isMulti = isMulti;
@@ -1,4 +1,3 @@
1
1
  import type { HookContext } from "@feathersjs/feathers";
2
2
  import type { HookType } from "feathers-hooks-common/types";
3
- declare function markHookForSkip<T>(hookName: string, type: "all" | HookType | HookType[], context?: Partial<HookContext<T>>): Partial<HookContext<T>>;
4
- export default markHookForSkip;
3
+ export declare function markHookForSkip<T>(hookName: string, type: "all" | HookType | HookType[], context?: Partial<HookContext<T>>): Partial<HookContext<T>>;
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const pushSet_1 = __importDefault(require("./pushSet"));
3
+ exports.markHookForSkip = void 0;
4
+ const pushSet_1 = require("./pushSet");
7
5
  function markHookForSkip(hookName, type, context) {
8
6
  context = context || {};
9
7
  const params = context.params || {};
@@ -12,9 +10,9 @@ function markHookForSkip(hookName, type, context) {
12
10
  const combinedName = (t === "all")
13
11
  ? hookName
14
12
  : `${type}:${hookName}`;
15
- pushSet_1.default(params, ["skipHooks"], combinedName, { unique: true });
13
+ pushSet_1.pushSet(params, ["skipHooks"], combinedName, { unique: true });
16
14
  });
17
15
  context.params = params;
18
16
  return context;
19
17
  }
20
- exports.default = markHookForSkip;
18
+ exports.markHookForSkip = markHookForSkip;
@@ -1,4 +1,3 @@
1
1
  import type { Query } from "@feathersjs/feathers";
2
2
  import type { MergeQueryOptions } from "../../types";
3
- declare function mergeQuery<T>(target: Query, source: Query, options?: Partial<MergeQueryOptions<T>>): Query;
4
- export default mergeQuery;
3
+ export declare function mergeQuery<T>(target: Query, source: Query, options?: Partial<MergeQueryOptions<T>>): Query;
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.mergeQuery = void 0;
6
7
  const get_1 = __importDefault(require("lodash/get"));
7
8
  const has_1 = __importDefault(require("lodash/has"));
8
9
  const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
@@ -10,8 +11,8 @@ const isEqual_1 = __importDefault(require("lodash/isEqual"));
10
11
  const merge_1 = __importDefault(require("lodash/merge"));
11
12
  const set_1 = __importDefault(require("lodash/set"));
12
13
  const uniqWith_1 = __importDefault(require("lodash/uniqWith"));
13
- const mergeArrays_1 = __importDefault(require("./mergeArrays"));
14
- const filterQuery_1 = __importDefault(require("../filterQuery"));
14
+ const mergeArrays_1 = require("./mergeArrays");
15
+ const filterQuery_1 = require("../filterQuery");
15
16
  const errors_1 = require("@feathersjs/errors");
16
17
  const hasOwnProperty = (obj, key) => {
17
18
  return Object.prototype.hasOwnProperty.call(obj, key);
@@ -23,7 +24,7 @@ function handleArray(target, source, key, options) {
23
24
  return;
24
25
  }
25
26
  const handle = get_1.default(options, ["handle", ...key], options.defaultHandle);
26
- const arr = mergeArrays_1.default(targetVal, sourceVal, handle, key, options.actionOnEmptyIntersect);
27
+ const arr = mergeArrays_1.mergeArrays(targetVal, sourceVal, handle, key, options.actionOnEmptyIntersect);
27
28
  set_1.default(target, key, arr);
28
29
  }
29
30
  function handleCircular(target, source, prependKey, options) {
@@ -234,7 +235,7 @@ function makeDefaultOptions(options) {
234
235
  }
235
236
  function mergeQuery(target, source, options) {
236
237
  const fullOptions = makeDefaultOptions(options);
237
- const { filters: targetFilters, query: targetQuery } = filterQuery_1.default(target, {
238
+ const { filters: targetFilters, query: targetQuery } = filterQuery_1.filterQuery(target, {
238
239
  operators: fullOptions.operators,
239
240
  service: fullOptions.service
240
241
  });
@@ -243,7 +244,7 @@ function mergeQuery(target, source, options) {
243
244
  }
244
245
  let {
245
246
  // eslint-disable-next-line prefer-const
246
- filters: sourceFilters, query: sourceQuery } = filterQuery_1.default(source, {
247
+ filters: sourceFilters, query: sourceQuery } = filterQuery_1.filterQuery(source, {
247
248
  operators: fullOptions.operators,
248
249
  service: fullOptions.service
249
250
  });
@@ -294,6 +295,7 @@ function mergeQuery(target, source, options) {
294
295
  const result = Object.assign({}, targetFilters, targetQuery);
295
296
  return result;
296
297
  }
298
+ exports.mergeQuery = mergeQuery;
297
299
  function getParentProp(target, path) {
298
300
  if (path.length <= 1) {
299
301
  return target;
@@ -330,4 +332,3 @@ function arrayWithoutDuplicates(target) {
330
332
  }
331
333
  return uniqWith_1.default(target, isEqual_1.default);
332
334
  }
333
- exports.default = mergeQuery;
@@ -1,3 +1,2 @@
1
1
  import type { Handle, ActionOnEmptyIntersect, Path } from "../../types";
2
- declare function mergeArrays<T>(targetArr: T[], sourceArr: T[], handle: Handle, prependKey?: Path, actionOnEmptyIntersect?: ActionOnEmptyIntersect): T[] | undefined;
3
- export default mergeArrays;
2
+ export declare function mergeArrays<T>(targetArr: T[], sourceArr: T[], handle: Handle, prependKey?: Path, actionOnEmptyIntersect?: ActionOnEmptyIntersect): T[] | undefined;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeArrays = void 0;
3
4
  function mergeArrays(targetArr, sourceArr, handle, prependKey, actionOnEmptyIntersect) {
4
5
  if (!sourceArr && !targetArr) {
5
6
  return;
@@ -37,4 +38,4 @@ function mergeArrays(targetArr, sourceArr, handle, prependKey, actionOnEmptyInte
37
38
  }
38
39
  return undefined;
39
40
  }
40
- exports.default = mergeArrays;
41
+ exports.mergeArrays = mergeArrays;
@@ -1,3 +1,2 @@
1
1
  import type { Path, PushSetOptions } from "../types";
2
- declare const pushSet: (obj: Record<string, unknown>, path: string | Path, val: unknown, options?: PushSetOptions | undefined) => unknown[];
3
- export default pushSet;
2
+ export declare const pushSet: (obj: Record<string, unknown>, path: string | Path, val: unknown, options?: PushSetOptions | undefined) => unknown[];
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.pushSet = void 0;
6
7
  const isEqual_1 = __importDefault(require("lodash/isEqual"));
7
8
  const get_1 = __importDefault(require("lodash/get"));
8
9
  const set_1 = __importDefault(require("lodash/set"));
@@ -22,4 +23,4 @@ const pushSet = (obj, path, val, options) => {
22
23
  return arr;
23
24
  }
24
25
  };
25
- exports.default = pushSet;
26
+ exports.pushSet = pushSet;
@@ -1,3 +1,2 @@
1
1
  import type { HookContext } from "@feathersjs/feathers";
2
- declare const shouldSkip: (hookName: string, context: HookContext) => boolean;
3
- export default shouldSkip;
2
+ export declare const shouldSkip: (hookName: string, context: HookContext) => boolean;
@@ -2,6 +2,7 @@
2
2
  // Kudos to @DaddyWarbucks! This is a cheeky copy of his awesome library: 'feathers-fletching'.
3
3
  // Definitely check it out! https://daddywarbucks.github.io/feathers-fletching/overview.html
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.shouldSkip = void 0;
5
6
  const errors_1 = require("@feathersjs/errors");
6
7
  const shouldSkip = (hookName, context) => {
7
8
  if (!context.params || !context.params.skipHooks) {
@@ -29,4 +30,4 @@ const shouldSkip = (hookName, context) => {
29
30
  }
30
31
  return false;
31
32
  };
32
- exports.default = shouldSkip;
33
+ exports.shouldSkip = shouldSkip;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feathers-utils",
3
- "version": "1.5.11",
3
+ "version": "1.6.1",
4
4
  "description": "Some utils for projects using '@feathersjs/feathers'",
5
5
  "author": "fratzinger",
6
6
  "repository": {
@@ -1,10 +1,10 @@
1
1
  import { MethodNotAllowed } from "@feathersjs/errors";
2
- import shouldSkip from "../utils/shouldSkip";
3
- import isMulti from "../utils/isMulti";
2
+ import { shouldSkip } from "../utils/shouldSkip";
3
+ import { isMulti } from "../utils/isMulti";
4
4
 
5
5
  import type { HookContext } from "@feathersjs/feathers";
6
6
 
7
- function checkMulti(): ((context: HookContext) => HookContext) {
7
+ export function checkMulti(): ((context: HookContext) => HookContext) {
8
8
  return (context: HookContext): HookContext => {
9
9
  if (shouldSkip("checkMulti", context)) { return context; }
10
10
  const { service, method } = context;
@@ -17,5 +17,3 @@ function checkMulti(): ((context: HookContext) => HookContext) {
17
17
  return context;
18
18
  };
19
19
  }
20
-
21
- export default checkMulti;
@@ -1,6 +1,6 @@
1
1
  import { getItems } from "feathers-hooks-common";
2
2
 
3
- import shouldSkip from "../utils/shouldSkip";
3
+ import { shouldSkip } from "../utils/shouldSkip";
4
4
 
5
5
  import type { HookRunPerItemOptions } from "../types";
6
6
  import type { HookContext } from "@feathersjs/feathers";
@@ -14,7 +14,7 @@ const makeOptions = (
14
14
  }, options);
15
15
  };
16
16
 
17
- const runPerItem = (
17
+ export const runPerItem = (
18
18
  actionPerItem: (item: unknown, context: HookContext) => Promise<unknown>,
19
19
  options: HookRunPerItemOptions
20
20
  ): ((context: HookContext) => Promise<HookContext>) => {
@@ -34,6 +34,4 @@ const runPerItem = (
34
34
 
35
35
  return context;
36
36
  };
37
- };
38
-
39
- export default runPerItem;
37
+ };
@@ -11,15 +11,16 @@ import type { HookContext } from "@feathersjs/feathers";
11
11
  import type {
12
12
  HookSetDataOptions
13
13
  } from "../types";
14
+ import type { PropertyPath } from "lodash";
14
15
 
15
16
  const defaultOptions: Required<HookSetDataOptions> = {
16
17
  allowUndefined: false,
17
18
  overwrite: true
18
19
  };
19
20
 
20
- function setData(
21
- from: string[],
22
- to: string[],
21
+ export function setData(
22
+ from: PropertyPath,
23
+ to: PropertyPath,
23
24
  _options?: HookSetDataOptions
24
25
  ): ((context: HookContext) => HookContext) {
25
26
  const options: Required<HookSetDataOptions> = Object.assign({}, defaultOptions, _options);
@@ -28,24 +29,26 @@ function setData(
28
29
  let items = getItems(context);
29
30
  items = (Array.isArray(items)) ? items : [items];
30
31
 
31
- const val = _get(context, from);
32
-
33
- if (val === undefined) {
32
+ if (!_has(context, from)) {
34
33
  if (!context.params?.provider || options.allowUndefined === true) {
35
34
  return context;
36
35
  }
37
36
 
37
+ if (!options.overwrite && items.every((item: Record<string, unknown>) => _has(item, to))) {
38
+ return context;
39
+ }
40
+
38
41
  throw new Forbidden(`Expected field ${from.toString()} not available`);
39
42
  }
40
43
 
44
+ const val = _get(context, from);
45
+
41
46
  items.forEach((item: Record<string, unknown>) => {
42
47
  if (!options.overwrite && _has(item, to)) { return; }
43
-
48
+
44
49
  _set(item, to, val);
45
50
  });
46
51
 
47
52
  return context;
48
53
  };
49
- }
50
-
51
- export default setData;
54
+ }
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // hooks
2
- import checkMulti from "./hooks/checkMulti";
3
- import setData from "./hooks/setData";
4
- import runPerItem from "./hooks/runPerItem";
2
+ import { checkMulti } from "./hooks/checkMulti";
3
+ import { setData } from "./hooks/setData";
4
+ import { runPerItem } from "./hooks/runPerItem";
5
5
 
6
6
  export const hooks = {
7
7
  checkMulti,
@@ -13,34 +13,25 @@ export { checkMulti };
13
13
  export { setData };
14
14
  export { runPerItem };
15
15
 
16
- import debounceMixin, { DebouncedStore } from "./mixins/debounce-mixin";
16
+ import { debounceMixin, DebouncedStore } from "./mixins/debounce-mixin";
17
17
 
18
18
  export const mixins = {
19
19
  debounceMixin,
20
20
  DebouncedStore
21
21
  };
22
22
 
23
- import addHook from "./utils/addHook";
24
- import isMulti from "./utils/isMulti";
25
- import mergeQuery from "./utils/mergeQuery/index";
26
- import mergeArrays from "./utils/mergeQuery/mergeArrays";
27
- import pushSet from "./utils/pushSet";
23
+ export { debounceMixin };
24
+ export { DebouncedStore };
28
25
 
29
- import markHookForSkip from "./utils/markHookForSkip";
30
- import shouldSkip from "./utils/shouldSkip";
26
+ export { addHook } from "./utils/addHook";
27
+ export { isMulti } from "./utils/isMulti";
28
+ export { mergeQuery } from "./utils/mergeQuery/index";
29
+ export { mergeArrays } from "./utils/mergeQuery/mergeArrays";
30
+ export { pushSet } from "./utils/pushSet";
31
31
 
32
- import filterQuery from "./utils/filterQuery";
32
+ export { markHookForSkip } from "./utils/markHookForSkip";
33
+ export { shouldSkip } from "./utils/shouldSkip";
33
34
 
34
-
35
- export { addHook };
36
- export { isMulti };
37
- export { mergeQuery };
38
- export { mergeArrays };
39
- export { pushSet };
40
-
41
- export { markHookForSkip };
42
- export { shouldSkip };
43
-
44
- export { filterQuery };
35
+ export { filterQuery } from "./utils/filterQuery";
45
36
 
46
37
  export * from "./types";
@@ -17,14 +17,14 @@ export const makeDefaultOptions = (): DebouncedStoreOptions => {
17
17
  };
18
18
  };
19
19
 
20
- class DebouncedStore {
20
+ export class DebouncedStore {
21
21
  private _app: Application;
22
22
  private _options: DebouncedStoreOptions;
23
23
  private _isRunningById: Record<string, unknown>;
24
24
  _queueById: Record<string, DebouncedFunc<((id: Id, action: DebouncedFunctionApp) => void | Promise<void>)>>;
25
25
  //_waitingById: Record<string, WaitingObject>;
26
26
  add;
27
- constructor(app: Application, options: Partial<DebouncedStoreOptions>) {
27
+ constructor(app: Application, options?: Partial<DebouncedStoreOptions>) {
28
28
  this._app = app;
29
29
  this._options = Object.assign(makeDefaultOptions(), options);
30
30
  this._queueById = {};
@@ -72,6 +72,4 @@ class DebouncedStore {
72
72
  cancel(id: Id): void {
73
73
  delete this._queueById[id];
74
74
  }
75
- }
76
-
77
- export default DebouncedStore;
75
+ }
@@ -1,4 +1,5 @@
1
- import DebouncedStore, {
1
+ import {
2
+ DebouncedStore,
2
3
  makeDefaultOptions
3
4
  } from "./DebouncedStore";
4
5
 
@@ -9,7 +10,7 @@ import type {
9
10
  DebouncedStoreOptions,
10
11
  } from "../../types";
11
12
 
12
- export default function initDebounceMixin(options?: Partial<InitDebounceMixinOptions>): ((app: Application) => void) {
13
+ export function debounceMixin(options?: Partial<InitDebounceMixinOptions>): ((app: Application) => void) {
13
14
  return (app: Application): void => {
14
15
  options = options || {};
15
16
  const defaultOptions = Object.assign(makeDefaultOptions(), options?.default);
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Application, HookContext, Params, Service } from "@feathersjs/feathers";
1
+ import type { Application, Service } from "@feathersjs/feathers";
2
2
 
3
3
  export type Path = Array<string|number>;
4
4
  export type HookType = "before" | "after" | "error";
@@ -8,7 +8,7 @@ const defaultOptions = (): Partial<AddHookOptions> => {
8
8
  };
9
9
  };
10
10
 
11
- const addHook = (app: Application, hook: unknown, options: AddHookOptions): void => {
11
+ export const addHook = (app: Application, hook: unknown, options: AddHookOptions): void => {
12
12
  options = Object.assign(defaultOptions(), options);
13
13
 
14
14
  const {
@@ -46,6 +46,4 @@ const addHook = (app: Application, hook: unknown, options: AddHookOptions): void
46
46
  });
47
47
  });
48
48
  }
49
- };
50
-
51
- export default addHook;
49
+ };
@@ -10,7 +10,7 @@ import type {
10
10
 
11
11
  import type { Query } from "@feathersjs/feathers";
12
12
 
13
- function filterQuery<T>(query: Query, options?: FilterQueryOptions<T>): FilterQueryResult {
13
+ export function filterQuery<T>(query: Query, options?: FilterQueryOptions<T>): FilterQueryResult {
14
14
  query = query || {};
15
15
  options = options || {};
16
16
  if (options?.service) {
@@ -31,6 +31,4 @@ function filterQuery<T>(query: Query, options?: FilterQueryOptions<T>): FilterQu
31
31
  }
32
32
  }
33
33
  return plainFilterQuery(query, options) as FilterQueryResult;
34
- }
35
-
36
- export default filterQuery;
34
+ }
@@ -1,6 +1,6 @@
1
1
  import type { HookContext } from "@feathersjs/feathers";
2
2
 
3
- const isMulti = (context: HookContext): boolean => {
3
+ export const isMulti = (context: HookContext): boolean => {
4
4
  const { method } = context;
5
5
  if (method === "find") {
6
6
  return true;
@@ -14,6 +14,4 @@ const isMulti = (context: HookContext): boolean => {
14
14
  return false;
15
15
  }
16
16
  return false;
17
- };
18
-
19
- export default isMulti;
17
+ };
@@ -1,9 +1,9 @@
1
- import pushSet from "./pushSet";
1
+ import { pushSet } from "./pushSet";
2
2
 
3
3
  import type { HookContext } from "@feathersjs/feathers";
4
4
  import type { HookType } from "feathers-hooks-common/types";
5
5
 
6
- function markHookForSkip<T>(
6
+ export function markHookForSkip<T>(
7
7
  hookName: string,
8
8
  type: "all" | HookType | HookType[],
9
9
  context?: Partial<HookContext<T>>
@@ -21,6 +21,4 @@ function markHookForSkip<T>(
21
21
 
22
22
  context.params = params;
23
23
  return context;
24
- }
25
-
26
- export default markHookForSkip;
24
+ }
@@ -6,8 +6,8 @@ import _merge from "lodash/merge";
6
6
  import _set from "lodash/set";
7
7
  import _uniqWith from "lodash/uniqWith";
8
8
 
9
- import mergeArrays from "./mergeArrays";
10
- import filterQuery from "../filterQuery";
9
+ import { mergeArrays } from "./mergeArrays";
10
+ import { filterQuery } from "../filterQuery";
11
11
 
12
12
  import { Forbidden } from "@feathersjs/errors";
13
13
 
@@ -249,7 +249,7 @@ function makeDefaultOptions<T>(options?: Partial<MergeQueryOptions<T>>): MergeQu
249
249
  return options as MergeQueryOptions<T>;
250
250
  }
251
251
 
252
- function mergeQuery<T>(target: Query, source: Query, options?: Partial<MergeQueryOptions<T>>): Query {
252
+ export function mergeQuery<T>(target: Query, source: Query, options?: Partial<MergeQueryOptions<T>>): Query {
253
253
  const fullOptions = makeDefaultOptions(options);
254
254
  const {
255
255
  filters: targetFilters,
@@ -364,6 +364,4 @@ function cleanAnd(target: Record<string, unknown>[]): Record<string, unknown>[]
364
364
  function arrayWithoutDuplicates<T>(target: T[]): T[] {
365
365
  if (!target || !Array.isArray(target)) { return target; }
366
366
  return _uniqWith(target, _isEqual);
367
- }
368
-
369
- export default mergeQuery;
367
+ }
@@ -4,7 +4,7 @@ import type {
4
4
  Path
5
5
  } from "../../types";
6
6
 
7
- function mergeArrays<T> (
7
+ export function mergeArrays<T> (
8
8
  targetArr: T[],
9
9
  sourceArr: T[],
10
10
  handle: Handle,
@@ -40,6 +40,4 @@ function mergeArrays<T> (
40
40
  return targetArr.filter(val => sourceArr.includes(val));
41
41
  }
42
42
  return undefined;
43
- }
44
-
45
- export default mergeArrays;
43
+ }
@@ -7,7 +7,7 @@ import type {
7
7
  PushSetOptions
8
8
  } from "../types";
9
9
 
10
- const pushSet = (obj: Record<string, unknown>, path: string | Path, val: unknown, options?: PushSetOptions): unknown[] => {
10
+ export const pushSet = (obj: Record<string, unknown>, path: string | Path, val: unknown, options?: PushSetOptions): unknown[] => {
11
11
  options = options || {};
12
12
  let arr = _get(obj, path);
13
13
  if (!arr || !Array.isArray(arr)) {
@@ -19,6 +19,4 @@ const pushSet = (obj: Record<string, unknown>, path: string | Path, val: unknown
19
19
  arr.push(val);
20
20
  return arr;
21
21
  }
22
- };
23
-
24
- export default pushSet;
22
+ };
@@ -5,7 +5,7 @@ import { GeneralError } from "@feathersjs/errors";
5
5
 
6
6
  import type { HookContext } from "@feathersjs/feathers";
7
7
 
8
- const shouldSkip = (hookName: string, context: HookContext): boolean => {
8
+ export const shouldSkip = (hookName: string, context: HookContext): boolean => {
9
9
  if (!context.params || !context.params.skipHooks) {
10
10
  return false;
11
11
  }
@@ -38,6 +38,4 @@ const shouldSkip = (hookName: string, context: HookContext): boolean => {
38
38
  }
39
39
 
40
40
  return false;
41
- };
42
-
43
- export default shouldSkip;
41
+ };
@@ -1,5 +1,5 @@
1
1
  import assert from "assert";
2
- import checkMulti from "../../src/hooks/checkMulti";
2
+ import { checkMulti } from "../../src";
3
3
 
4
4
  describe("hook - checkMulti", function() {
5
5
  it("passes if 'allowsMulti' not defined", function() {
@@ -1,5 +1,5 @@
1
1
  import assert from "assert";
2
- import setData from "../../src/hooks/setData";
2
+ import { setData } from "../../src";
3
3
 
4
4
  describe("hook - setData", function() {
5
5
  it("sets userId for single item", function() {
@@ -190,6 +190,33 @@ describe("hook - setData", function() {
190
190
  });
191
191
  });
192
192
 
193
+ it("passes if 'external' is set and context.user.id is undefined but overwrite: false", function() {
194
+ const methodsByType = {
195
+ "before": ["create", "update", "patch", "remove"],
196
+ "after": ["find", "get", "create", "update", "patch", "remove"]
197
+ };
198
+ Object.keys(methodsByType).forEach(type => {
199
+ methodsByType[type].forEach(method => {
200
+ const context = {
201
+ method,
202
+ type,
203
+ params: {
204
+ provider: "socket.io"
205
+ }
206
+ };
207
+
208
+ const dataOrResult = (type === "before") ? "data" : "result";
209
+ context[dataOrResult] = { userId: 1 };
210
+
211
+ assert.doesNotThrow(
212
+ //@ts-ignore
213
+ () => setData("params.user.id", "userId", { overwrite: false })(context),
214
+ `'${type}/${method}': passes`
215
+ );
216
+ });
217
+ });
218
+ });
219
+
193
220
  describe("overwrite: false", function() {
194
221
  it("sets userId for single item", function() {
195
222
  const methodsByType = {
@@ -1,7 +1,7 @@
1
1
  import assert from "assert";
2
2
  import feathers from "@feathersjs/feathers";
3
3
  import createService from "feathers-memory";
4
- import makeMixin from "../../src/mixins/debounce-mixin";
4
+ import { debounceMixin as makeMixin } from "../../src";
5
5
  import { performance } from "perf_hooks";
6
6
 
7
7
  const mockApp = () => {
@@ -2,7 +2,7 @@ import assert from "assert";
2
2
  import feathers from "@feathersjs/feathers";
3
3
  import createService from "feathers-memory";
4
4
 
5
- import addHook from "../../src/utils/addHook";
5
+ import { addHook } from "../../src";
6
6
 
7
7
  import { HookType, ServiceMethodName } from "../../src/types";
8
8
 
@@ -1,5 +1,5 @@
1
1
  import assert from "assert";
2
- import isMulti from "../../src/utils/isMulti";
2
+ import { isMulti } from "../../src";
3
3
 
4
4
  describe("util - isMulti", function() {
5
5
  it("returns true", function() {
@@ -1,8 +1,7 @@
1
1
  import assert from "assert";
2
2
  import feathers from "@feathersjs/feathers";
3
3
  import { Service } from "feathers-memory";
4
- import shouldSkip from "../../src/utils/shouldSkip";
5
- import markHookForSkip from "../../src/utils/markHookForSkip";
4
+ import { shouldSkip, markHookForSkip } from "../../src";
6
5
 
7
6
  describe("util - markHookForSkip", function() {
8
7
  it("returns hook object", function() {
@@ -1,5 +1,5 @@
1
1
  import assert from"assert";
2
- import mergeQuery from "../../src/utils/mergeQuery";
2
+ import { mergeQuery } from "../../src";
3
3
  import feathers from "@feathersjs/feathers";
4
4
  import { Service } from "feathers-memory";
5
5
 
@@ -1,5 +1,5 @@
1
1
  import assert from "assert";
2
- import pushSet from "../../src/utils/pushSet";
2
+ import { pushSet } from "../../src";
3
3
 
4
4
  describe("util - pushSet", function() {
5
5
  it("pushes to existing array", function() {
@@ -1,5 +1,5 @@
1
1
  import assert from "assert";
2
- import shouldSkip from "../../src/utils/shouldSkip";
2
+ import { shouldSkip } from "../../src";
3
3
 
4
4
  describe("util - shouldSkip", function() {
5
5
  it("returns false if skipHooks not defined", function() {