feathers-utils 1.6.1 → 2.0.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/esm/hooks/checkMulti.d.ts +2 -0
  2. package/dist/esm/hooks/checkMulti.js +18 -0
  3. package/dist/esm/hooks/runPerItem.d.ts +4 -0
  4. package/dist/esm/hooks/runPerItem.js +26 -0
  5. package/dist/esm/hooks/setData.d.ts +4 -0
  6. package/dist/esm/hooks/setData.js +34 -0
  7. package/dist/esm/index.d.ts +30 -0
  8. package/dist/esm/index.js +30 -0
  9. package/dist/esm/mixins/debounce-mixin/DebouncedStore.d.ts +15 -0
  10. package/dist/esm/mixins/debounce-mixin/DebouncedStore.js +46 -0
  11. package/dist/esm/mixins/debounce-mixin/index.d.ts +8 -0
  12. package/dist/esm/mixins/debounce-mixin/index.js +20 -0
  13. package/dist/esm/types.d.ts +60 -0
  14. package/dist/esm/types.js +2 -0
  15. package/dist/esm/utils/filterQuery.d.ts +3 -0
  16. package/dist/esm/utils/filterQuery.js +28 -0
  17. package/dist/esm/utils/getPaginate.d.ts +7 -0
  18. package/dist/esm/utils/getPaginate.js +14 -0
  19. package/dist/esm/utils/isMulti.d.ts +2 -0
  20. package/dist/esm/utils/isMulti.js +17 -0
  21. package/dist/esm/utils/isPaginated.d.ts +2 -0
  22. package/dist/esm/utils/isPaginated.js +8 -0
  23. package/dist/esm/utils/markHookForSkip.d.ts +3 -0
  24. package/dist/esm/utils/markHookForSkip.js +14 -0
  25. package/dist/esm/utils/mergeQuery/index.d.ts +3 -0
  26. package/dist/esm/utils/mergeQuery/index.js +327 -0
  27. package/dist/esm/utils/mergeQuery/mergeArrays.d.ts +2 -0
  28. package/dist/esm/utils/mergeQuery/mergeArrays.js +37 -0
  29. package/dist/esm/utils/pushSet.d.ts +2 -0
  30. package/dist/esm/utils/pushSet.js +19 -0
  31. package/dist/esm/utils/setResultEmpty.d.ts +2 -0
  32. package/dist/esm/utils/setResultEmpty.js +25 -0
  33. package/dist/esm/utils/shouldSkip.d.ts +2 -0
  34. package/dist/esm/utils/shouldSkip.js +29 -0
  35. package/dist/hooks/checkMulti.js +2 -2
  36. package/dist/hooks/runPerItem.d.ts +2 -1
  37. package/dist/hooks/runPerItem.js +3 -2
  38. package/dist/hooks/setData.js +7 -6
  39. package/dist/index.d.ts +6 -3
  40. package/dist/index.js +7 -3
  41. package/dist/mixins/debounce-mixin/DebouncedStore.d.ts +2 -2
  42. package/dist/mixins/debounce-mixin/DebouncedStore.js +2 -2
  43. package/dist/mixins/debounce-mixin/index.d.ts +4 -1
  44. package/dist/mixins/debounce-mixin/index.js +1 -1
  45. package/dist/types.d.ts +3 -2
  46. package/dist/utils/filterQuery.js +2 -2
  47. package/dist/utils/getPaginate.d.ts +7 -0
  48. package/dist/utils/getPaginate.js +15 -0
  49. package/dist/utils/isMulti.js +2 -3
  50. package/dist/utils/isPaginated.d.ts +2 -0
  51. package/dist/utils/isPaginated.js +12 -0
  52. package/dist/utils/markHookForSkip.js +1 -1
  53. package/dist/utils/mergeQuery/index.js +38 -38
  54. package/dist/utils/pushSet.js +3 -3
  55. package/dist/utils/setResultEmpty.d.ts +2 -0
  56. package/dist/utils/setResultEmpty.js +29 -0
  57. package/package.json +19 -13
  58. package/src/hooks/runPerItem.ts +4 -1
  59. package/src/hooks/setData.ts +1 -0
  60. package/src/index.ts +6 -3
  61. package/src/mixins/debounce-mixin/DebouncedStore.ts +1 -1
  62. package/src/mixins/debounce-mixin/index.ts +7 -3
  63. package/src/types.ts +4 -3
  64. package/src/utils/filterQuery.ts +2 -2
  65. package/src/utils/getPaginate.ts +26 -0
  66. package/src/utils/isMulti.ts +2 -3
  67. package/src/utils/isPaginated.ts +12 -0
  68. package/src/utils/setResultEmpty.ts +28 -0
  69. package/tsconfig-esm.json +9 -0
  70. package/.github/workflows/node.js.yml +0 -45
  71. package/.vscode/launch.json +0 -28
  72. package/.vscode/settings.json +0 -14
  73. package/dist/utils/addHook.d.ts +0 -3
  74. package/dist/utils/addHook.js +0 -40
  75. package/src/utils/addHook.ts +0 -49
  76. package/test/hooks/checkMulti.test.ts +0 -121
  77. package/test/hooks/setData.test.ts +0 -333
  78. package/test/mixins/debounce-mixin.test.ts +0 -174
  79. package/test/utils/addHook.test.ts +0 -307
  80. package/test/utils/isMulti.test.ts +0 -53
  81. package/test/utils/markHookForSkip.test.ts +0 -292
  82. package/test/utils/mergeQuery.test.ts +0 -407
  83. package/test/utils/pushSet.test.ts +0 -66
  84. package/test/utils/shouldSkip.test.ts +0 -67
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { Application, Service } from "@feathersjs/feathers";
1
+ import type { Application } from "@feathersjs/feathers";
2
+ import type { AdapterService } from "@feathersjs/adapter-commons";
2
3
  export declare type Path = Array<string | number>;
3
4
  export declare type HookType = "before" | "after" | "error";
4
5
  export declare type ServiceMethodName = "find" | "get" | "create" | "update" | "patch" | "remove";
@@ -43,7 +44,7 @@ export interface MergeQueryOptions<T> extends FilterQueryOptions<T> {
43
44
  };
44
45
  }
45
46
  export interface FilterQueryOptions<T> {
46
- service?: Service<T>;
47
+ service?: AdapterService<T>;
47
48
  operators?: string[];
48
49
  filters?: string[];
49
50
  }
@@ -25,9 +25,9 @@ function filterQuery(query, options) {
25
25
  return service.filterQuery({ query }, optionsForFilterQuery);
26
26
  }
27
27
  else {
28
- return adapter_commons_1.filterQuery(query, optionsForFilterQuery);
28
+ return (0, adapter_commons_1.filterQuery)(query, optionsForFilterQuery);
29
29
  }
30
30
  }
31
- return adapter_commons_1.filterQuery(query, options);
31
+ return (0, adapter_commons_1.filterQuery)(query, options);
32
32
  }
33
33
  exports.filterQuery = filterQuery;
@@ -0,0 +1,7 @@
1
+ import { HookContext } from "@feathersjs/feathers";
2
+ interface PaginationOptions {
3
+ default: number;
4
+ max: number;
5
+ }
6
+ export declare const getPaginate: (context: HookContext) => PaginationOptions | undefined;
7
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPaginate = void 0;
4
+ const getPaginate = (context) => {
5
+ if (Object.prototype.hasOwnProperty.call(context.params, "paginate")) {
6
+ return context.params.paginate || undefined;
7
+ }
8
+ if (context.params.paginate === false) {
9
+ return undefined;
10
+ }
11
+ let options = context.service.options || {};
12
+ options = Object.assign(Object.assign({}, options), context.params.adapter);
13
+ return options.paginate || undefined;
14
+ };
15
+ exports.getPaginate = getPaginate;
@@ -6,15 +6,14 @@ const isMulti = (context) => {
6
6
  if (method === "find") {
7
7
  return true;
8
8
  }
9
- else if (["patch", "remove"].includes(context.method)) {
9
+ else if (["patch", "remove"].includes(method)) {
10
10
  return context.id == null;
11
11
  }
12
12
  else if (method === "create") {
13
13
  const items = context.type === "before" ? context.data : context.result;
14
- items && context.method === "find" ? items.data || items : items;
15
14
  return Array.isArray(items);
16
15
  }
17
- else if (method === "get" || method === "update") {
16
+ else if (["get", "update"].includes(method)) {
18
17
  return false;
19
18
  }
20
19
  return false;
@@ -0,0 +1,2 @@
1
+ import { HookContext } from "@feathersjs/feathers";
2
+ export declare const isPaginated: (context: HookContext) => boolean;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPaginated = void 0;
4
+ const getPaginate_1 = require("./getPaginate");
5
+ const isPaginated = (context) => {
6
+ if (context.params.paginate === false) {
7
+ return false;
8
+ }
9
+ const paginate = (0, getPaginate_1.getPaginate)(context);
10
+ return !!paginate;
11
+ };
12
+ exports.isPaginated = isPaginated;
@@ -10,7 +10,7 @@ function markHookForSkip(hookName, type, context) {
10
10
  const combinedName = (t === "all")
11
11
  ? hookName
12
12
  : `${type}:${hookName}`;
13
- pushSet_1.pushSet(params, ["skipHooks"], combinedName, { unique: true });
13
+ (0, pushSet_1.pushSet)(params, ["skipHooks"], combinedName, { unique: true });
14
14
  });
15
15
  context.params = params;
16
16
  return context;
@@ -18,14 +18,14 @@ const hasOwnProperty = (obj, key) => {
18
18
  return Object.prototype.hasOwnProperty.call(obj, key);
19
19
  };
20
20
  function handleArray(target, source, key, options) {
21
- const targetVal = get_1.default(target, key);
22
- const sourceVal = get_1.default(source, key);
21
+ const targetVal = (0, get_1.default)(target, key);
22
+ const sourceVal = (0, get_1.default)(source, key);
23
23
  if (!sourceVal && !targetVal) {
24
24
  return;
25
25
  }
26
- const handle = get_1.default(options, ["handle", ...key], options.defaultHandle);
27
- const arr = mergeArrays_1.mergeArrays(targetVal, sourceVal, handle, key, options.actionOnEmptyIntersect);
28
- set_1.default(target, key, arr);
26
+ const handle = (0, get_1.default)(options, ["handle", ...key], options.defaultHandle);
27
+ const arr = (0, mergeArrays_1.mergeArrays)(targetVal, sourceVal, handle, key, options.actionOnEmptyIntersect);
28
+ (0, set_1.default)(target, key, arr);
29
29
  }
30
30
  function handleCircular(target, source, prependKey, options) {
31
31
  if (target === null || target === void 0 ? void 0 : target.$or) {
@@ -52,11 +52,11 @@ function handleCircular(target, source, prependKey, options) {
52
52
  delete source.$and;
53
53
  }
54
54
  }
55
- if (!has_1.default(source, prependKey)) {
55
+ if (!(0, has_1.default)(source, prependKey)) {
56
56
  return;
57
57
  }
58
- if (!has_1.default(target, prependKey)) {
59
- set_1.default(target, prependKey, get_1.default(source, prependKey));
58
+ if (!(0, has_1.default)(target, prependKey)) {
59
+ (0, set_1.default)(target, prependKey, (0, get_1.default)(source, prependKey));
60
60
  return;
61
61
  }
62
62
  const { defaultHandle, actionOnEmptyIntersect } = options;
@@ -64,22 +64,22 @@ function handleCircular(target, source, prependKey, options) {
64
64
  return;
65
65
  }
66
66
  const getTargetVal = () => {
67
- return (prependKey.length > 0) ? get_1.default(target, prependKey) : target;
67
+ return (prependKey.length > 0) ? (0, get_1.default)(target, prependKey) : target;
68
68
  };
69
69
  const getSourceVal = () => {
70
- return (prependKey.length > 0) ? get_1.default(source, prependKey) : source;
70
+ return (prependKey.length > 0) ? (0, get_1.default)(source, prependKey) : source;
71
71
  };
72
72
  const targetVal = getTargetVal();
73
73
  const sourceVal = getSourceVal();
74
- if (isEqual_1.default(targetVal, sourceVal)) {
74
+ if ((0, isEqual_1.default)(targetVal, sourceVal)) {
75
75
  return;
76
76
  }
77
77
  if (defaultHandle === "source") {
78
- set_1.default(target, prependKey, sourceVal);
78
+ (0, set_1.default)(target, prependKey, sourceVal);
79
79
  return;
80
80
  }
81
81
  if (targetVal === null || sourceVal === null) {
82
- set_1.default(target, prependKey, sourceVal);
82
+ (0, set_1.default)(target, prependKey, sourceVal);
83
83
  return;
84
84
  }
85
85
  const typeOfTargetVal = typeof targetVal;
@@ -87,7 +87,7 @@ function handleCircular(target, source, prependKey, options) {
87
87
  if (defaultHandle === "intersect") {
88
88
  actionOnEmptyIntersect(target, source, prependKey);
89
89
  }
90
- set_1.default(target, prependKey, sourceVal);
90
+ (0, set_1.default)(target, prependKey, sourceVal);
91
91
  return;
92
92
  }
93
93
  const typeOfSourceVal = typeof sourceVal;
@@ -96,7 +96,7 @@ function handleCircular(target, source, prependKey, options) {
96
96
  if (isTargetSimple || isSourceSimple) {
97
97
  if (isTargetSimple && isSourceSimple) {
98
98
  if (defaultHandle === "combine") {
99
- set_1.default(target, prependKey, { $in: [...new Set([targetVal, sourceVal])] });
99
+ (0, set_1.default)(target, prependKey, { $in: [...new Set([targetVal, sourceVal])] });
100
100
  return;
101
101
  }
102
102
  else if (defaultHandle === "intersect") {
@@ -110,20 +110,20 @@ function handleCircular(target, source, prependKey, options) {
110
110
  const targetHasIn = hasOwnProperty(targetVal, "$in");
111
111
  const $in = (targetHasIn) ? targetVal["$in"] : sourceVal["$in"];
112
112
  const otherVal = (isTargetSimple) ? targetVal : sourceVal;
113
- if ($in.length === 1 && isEqual_1.default($in[0], otherVal)) {
114
- set_1.default(target, prependKey, otherVal);
113
+ if ($in.length === 1 && (0, isEqual_1.default)($in[0], otherVal)) {
114
+ (0, set_1.default)(target, prependKey, otherVal);
115
115
  return;
116
116
  }
117
117
  else if (defaultHandle === "combine") {
118
- if (!$in.some((x) => isEqual_1.default(x, otherVal))) {
118
+ if (!$in.some((x) => (0, isEqual_1.default)(x, otherVal))) {
119
119
  $in.push(otherVal);
120
120
  }
121
- set_1.default(target, `${prependKey}.$in`, $in);
121
+ (0, set_1.default)(target, `${prependKey}.$in`, $in);
122
122
  return;
123
123
  }
124
124
  else if (defaultHandle === "intersect") {
125
- if ($in.some((x) => isEqual_1.default(x, otherVal))) {
126
- set_1.default(target, prependKey, otherVal);
125
+ if ($in.some((x) => (0, isEqual_1.default)(x, otherVal))) {
126
+ (0, set_1.default)(target, prependKey, otherVal);
127
127
  }
128
128
  else {
129
129
  actionOnEmptyIntersect(target, source, prependKey);
@@ -139,7 +139,7 @@ function handleCircular(target, source, prependKey, options) {
139
139
  const key = prependKey[prependKey.length - 1];
140
140
  if (key === "$or") {
141
141
  if (defaultHandle === "combine") {
142
- const newVals = sourceVal.filter((x) => !targetVal.some((y) => isEqual_1.default(x, y)));
142
+ const newVals = sourceVal.filter((x) => !targetVal.some((y) => (0, isEqual_1.default)(x, y)));
143
143
  targetVal.push(...newVals);
144
144
  }
145
145
  else if (defaultHandle === "intersect") {
@@ -176,7 +176,7 @@ function handleCircular(target, source, prependKey, options) {
176
176
  return;
177
177
  }
178
178
  else if (defaultHandle === "intersect") {
179
- const newVals = sourceVal.filter((x) => !targetVal.some((y) => isEqual_1.default(x, y)));
179
+ const newVals = sourceVal.filter((x) => !targetVal.some((y) => (0, isEqual_1.default)(x, y)));
180
180
  targetVal.push(...newVals);
181
181
  return;
182
182
  }
@@ -185,29 +185,29 @@ function handleCircular(target, source, prependKey, options) {
185
185
  if (defaultHandle === "combine") {
186
186
  let $in = targetVal.concat(sourceVal);
187
187
  $in = [...new Set($in)];
188
- set_1.default(target, prependKey, $in);
188
+ (0, set_1.default)(target, prependKey, $in);
189
189
  return;
190
190
  }
191
191
  else if (defaultHandle === "intersect") {
192
- const $in = targetVal.filter((x) => sourceVal.some((y) => isEqual_1.default(x, y)));
192
+ const $in = targetVal.filter((x) => sourceVal.some((y) => (0, isEqual_1.default)(x, y)));
193
193
  if ($in.length === 0) {
194
194
  actionOnEmptyIntersect(target, source, prependKey);
195
195
  }
196
196
  else if ($in.length === 1) {
197
- set_1.default(target, prependKey.slice(0, -1), $in[0]);
197
+ (0, set_1.default)(target, prependKey.slice(0, -1), $in[0]);
198
198
  return;
199
199
  }
200
200
  else {
201
- set_1.default(target, prependKey, $in);
201
+ (0, set_1.default)(target, prependKey, $in);
202
202
  }
203
203
  }
204
204
  return;
205
205
  }
206
- set_1.default(target, prependKey, sourceVal);
206
+ (0, set_1.default)(target, prependKey, sourceVal);
207
207
  return;
208
208
  }
209
209
  if (typeOfTargetVal !== "object" || typeOfSourceVal !== "object") {
210
- set_1.default(target, prependKey, sourceVal);
210
+ (0, set_1.default)(target, prependKey, sourceVal);
211
211
  return;
212
212
  }
213
213
  // both are objects
@@ -235,7 +235,7 @@ function makeDefaultOptions(options) {
235
235
  }
236
236
  function mergeQuery(target, source, options) {
237
237
  const fullOptions = makeDefaultOptions(options);
238
- const { filters: targetFilters, query: targetQuery } = filterQuery_1.filterQuery(target, {
238
+ const { filters: targetFilters, query: targetQuery } = (0, filterQuery_1.filterQuery)(target, {
239
239
  operators: fullOptions.operators,
240
240
  service: fullOptions.service
241
241
  });
@@ -244,7 +244,7 @@ function mergeQuery(target, source, options) {
244
244
  }
245
245
  let {
246
246
  // eslint-disable-next-line prefer-const
247
- filters: sourceFilters, query: sourceQuery } = filterQuery_1.filterQuery(source, {
247
+ filters: sourceFilters, query: sourceQuery } = (0, filterQuery_1.filterQuery)(source, {
248
248
  operators: fullOptions.operators,
249
249
  service: fullOptions.service
250
250
  });
@@ -265,13 +265,13 @@ function mergeQuery(target, source, options) {
265
265
  handleArray(targetFilters, sourceFilters, ["$select"], fullOptions);
266
266
  // remaining filters
267
267
  delete sourceFilters["$select"];
268
- merge_1.default(targetFilters, sourceFilters);
268
+ (0, merge_1.default)(targetFilters, sourceFilters);
269
269
  //#endregion
270
270
  //#region '$or' / '$and'
271
271
  if ((options === null || options === void 0 ? void 0 : options.useLogicalConjunction) &&
272
272
  (options.defaultHandle === "combine" ||
273
273
  options.defaultHandle === "intersect") &&
274
- !isEmpty_1.default(targetQuery)) {
274
+ !(0, isEmpty_1.default)(targetQuery)) {
275
275
  const logicalOp = (options.defaultHandle === "combine")
276
276
  ? "$or"
277
277
  : "$and";
@@ -301,13 +301,13 @@ function getParentProp(target, path) {
301
301
  return target;
302
302
  }
303
303
  const pathOneUp = path.slice(0, -1);
304
- return get_1.default(target, pathOneUp);
304
+ return (0, get_1.default)(target, pathOneUp);
305
305
  }
306
306
  function cleanOr(target) {
307
307
  if (!target || !Array.isArray(target) || target.length <= 0) {
308
308
  return target;
309
309
  }
310
- if (target.some(x => isEmpty_1.default(x))) {
310
+ if (target.some(x => (0, isEmpty_1.default)(x))) {
311
311
  return undefined;
312
312
  }
313
313
  else {
@@ -318,11 +318,11 @@ function cleanAnd(target) {
318
318
  if (!target || !Array.isArray(target) || target.length <= 0) {
319
319
  return target;
320
320
  }
321
- if (target.every(x => isEmpty_1.default(x))) {
321
+ if (target.every(x => (0, isEmpty_1.default)(x))) {
322
322
  return undefined;
323
323
  }
324
324
  else {
325
- target = target.filter(x => !isEmpty_1.default(x));
325
+ target = target.filter(x => !(0, isEmpty_1.default)(x));
326
326
  return arrayWithoutDuplicates(target);
327
327
  }
328
328
  }
@@ -330,5 +330,5 @@ function arrayWithoutDuplicates(target) {
330
330
  if (!target || !Array.isArray(target)) {
331
331
  return target;
332
332
  }
333
- return uniqWith_1.default(target, isEqual_1.default);
333
+ return (0, uniqWith_1.default)(target, isEqual_1.default);
334
334
  }
@@ -9,14 +9,14 @@ const get_1 = __importDefault(require("lodash/get"));
9
9
  const set_1 = __importDefault(require("lodash/set"));
10
10
  const pushSet = (obj, path, val, options) => {
11
11
  options = options || {};
12
- let arr = get_1.default(obj, path);
12
+ let arr = (0, get_1.default)(obj, path);
13
13
  if (!arr || !Array.isArray(arr)) {
14
14
  arr = [val];
15
- set_1.default(obj, path, arr);
15
+ (0, set_1.default)(obj, path, arr);
16
16
  return arr;
17
17
  }
18
18
  else {
19
- if (options.unique && arr.some(x => isEqual_1.default(x, val))) {
19
+ if (options.unique && arr.some(x => (0, isEqual_1.default)(x, val))) {
20
20
  return arr;
21
21
  }
22
22
  arr.push(val);
@@ -0,0 +1,2 @@
1
+ import { HookContext } from "@feathersjs/feathers";
2
+ export declare const setResultEmpty: (context: HookContext) => HookContext;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setResultEmpty = void 0;
4
+ const __1 = require("..");
5
+ const isPaginated_1 = require("./isPaginated");
6
+ const setResultEmpty = (context) => {
7
+ if (context.result) {
8
+ return context;
9
+ }
10
+ const multi = (0, __1.isMulti)(context);
11
+ if (multi) {
12
+ if (context.method === "find" && (0, isPaginated_1.isPaginated)(context)) {
13
+ context.result = {
14
+ total: 0,
15
+ skip: 0,
16
+ limit: 0,
17
+ data: []
18
+ };
19
+ }
20
+ else {
21
+ context.result = [];
22
+ }
23
+ }
24
+ else {
25
+ context.result = null;
26
+ }
27
+ return context;
28
+ };
29
+ exports.setResultEmpty = setResultEmpty;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feathers-utils",
3
- "version": "1.6.1",
3
+ "version": "2.0.0-0",
4
4
  "description": "Some utils for projects using '@feathersjs/feathers'",
5
5
  "author": "fratzinger",
6
6
  "repository": {
@@ -10,28 +10,33 @@
10
10
  "homepage": "https://github.com/fratzinger/feathers-utils",
11
11
  "license": "MIT",
12
12
  "main": "dist/",
13
+ "module": "dist/esm/index.js",
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/esm/index.js",
17
+ "require": "./dist/index.js"
18
+ }
19
+ },
13
20
  "types": "dist/",
14
21
  "directories": {
15
22
  "dist": "dist"
16
23
  },
17
24
  "scripts": {
18
- "preversion": "npm run lint && npm run test && npm run compile",
19
- "publish": "git push origin --tags && git push origin",
20
- "compile": "shx rm -rf lib/ && tsc",
21
- "release:pre": "npm version prerelease && npm publish --tag pre",
22
- "release:patch": "npm version patch && npm publish",
23
- "release:minor": "npm version minor && npm publish",
24
- "release:major": "npm version major && npm publish",
25
+ "build": "shx rm -rf dist/ && npm run tsc",
26
+ "tsc": "tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
27
+ "version": "npm run build",
28
+ "release": "np",
25
29
  "test": "cross-env NODE_ENV=test TS_NODE_PROJECT='tsconfig.test.json' mocha --require ts-node/register 'test/**/*.test.ts' --timeout 5000",
26
30
  "coverage": "nyc npm run test",
27
31
  "lint": "eslint . --ext .js,.jsx,.ts,.tsx"
28
32
  },
29
33
  "dependencies": {
30
- "@feathersjs/adapter-commons": "^4.5.11",
31
- "@feathersjs/errors": "^4.5.11",
32
- "@feathersjs/feathers": "^4.5.11",
33
- "feathers-hooks-common": "^5.0.5",
34
- "lodash": "^4.17.21"
34
+ "@feathersjs/adapter-commons": "5.0.0-pre.15",
35
+ "@feathersjs/errors": "5.0.0-pre.15",
36
+ "@feathersjs/feathers": "5.0.0-pre.15",
37
+ "feathers-hooks-common": "^5.0.6",
38
+ "lodash": "^4.17.21",
39
+ "type-fest": "^2.5.4"
35
40
  },
36
41
  "devDependencies": {
37
42
  "@istanbuljs/nyc-config-typescript": "^1.0.1",
@@ -45,6 +50,7 @@
45
50
  "eslint-plugin-security": "^1.4.0",
46
51
  "feathers-memory": "^4.1.0",
47
52
  "mocha": "^8.3.2",
53
+ "np": "^7.5.0",
48
54
  "nyc": "^15.1.0",
49
55
  "shx": "^0.3.3",
50
56
  "ts-node": "^9.1.1",
@@ -4,6 +4,7 @@ import { shouldSkip } from "../utils/shouldSkip";
4
4
 
5
5
  import type { HookRunPerItemOptions } from "../types";
6
6
  import type { HookContext } from "@feathersjs/feathers";
7
+ import type { Promisable } from "type-fest";
7
8
 
8
9
  const makeOptions = (
9
10
  options: HookRunPerItemOptions
@@ -15,12 +16,14 @@ const makeOptions = (
15
16
  };
16
17
 
17
18
  export const runPerItem = (
18
- actionPerItem: (item: unknown, context: HookContext) => Promise<unknown>,
19
+ actionPerItem: (item: any, context: HookContext) => Promisable<any>,
19
20
  options: HookRunPerItemOptions
20
21
  ): ((context: HookContext) => Promise<HookContext>) => {
21
22
  options = makeOptions(options);
22
23
  return async (context: HookContext): Promise<HookContext> => {
23
24
  if (shouldSkip("runForItems", context)) { return context; }
25
+
26
+ //@ts-expect-error type error because feathers-hooks-common is feathers@4
24
27
  let items = getItems(context);
25
28
  items = (Array.isArray(items)) ? items : [items];
26
29
 
@@ -26,6 +26,7 @@ export function setData(
26
26
  const options: Required<HookSetDataOptions> = Object.assign({}, defaultOptions, _options);
27
27
  return (context: HookContext): HookContext => {
28
28
 
29
+ //@ts-expect-error type error because feathers-hooks-common is feathers@4
29
30
  let items = getItems(context);
30
31
  items = (Array.isArray(items)) ? items : [items];
31
32
 
package/src/index.ts CHANGED
@@ -13,7 +13,7 @@ export { checkMulti };
13
13
  export { setData };
14
14
  export { runPerItem };
15
15
 
16
- import { debounceMixin, DebouncedStore } from "./mixins/debounce-mixin";
16
+ import { debounceMixin, DebouncedService, DebouncedStore } from "./mixins/debounce-mixin";
17
17
 
18
18
  export const mixins = {
19
19
  debounceMixin,
@@ -21,17 +21,20 @@ export const mixins = {
21
21
  };
22
22
 
23
23
  export { debounceMixin };
24
+ export { DebouncedService };
24
25
  export { DebouncedStore };
25
26
 
26
- export { addHook } from "./utils/addHook";
27
+ export { getPaginate } from "./utils/getPaginate";
27
28
  export { isMulti } from "./utils/isMulti";
29
+ export { isPaginated } from "./utils/isPaginated";
28
30
  export { mergeQuery } from "./utils/mergeQuery/index";
29
31
  export { mergeArrays } from "./utils/mergeQuery/mergeArrays";
30
32
  export { pushSet } from "./utils/pushSet";
33
+ export { setResultEmpty } from "./utils/setResultEmpty";
31
34
 
32
35
  export { markHookForSkip } from "./utils/markHookForSkip";
33
36
  export { shouldSkip } from "./utils/shouldSkip";
34
37
 
35
38
  export { filterQuery } from "./utils/filterQuery";
36
39
 
37
- export * from "./types";
40
+ export * from "./types";
@@ -3,7 +3,7 @@ import _debounce from "lodash/debounce";
3
3
  import type { DebouncedFunc } from "lodash";
4
4
  import type { Application, Id } from "@feathersjs/feathers";
5
5
 
6
- import {
6
+ import type {
7
7
  DebouncedFunctionApp,
8
8
  DebouncedStoreOptions
9
9
  } from "../../types";
@@ -3,18 +3,22 @@ import {
3
3
  makeDefaultOptions
4
4
  } from "./DebouncedStore";
5
5
 
6
- import type { Application } from "@feathersjs/feathers";
6
+ import type { Application, FeathersService } from "@feathersjs/feathers";
7
7
 
8
8
  import type {
9
9
  InitDebounceMixinOptions,
10
10
  DebouncedStoreOptions,
11
11
  } from "../../types";
12
12
 
13
+ export type DebouncedService = FeathersService & {
14
+ debouncedStore?: DebouncedStore;
15
+ };
16
+
13
17
  export function debounceMixin(options?: Partial<InitDebounceMixinOptions>): ((app: Application) => void) {
14
18
  return (app: Application): void => {
15
19
  options = options || {};
16
20
  const defaultOptions = Object.assign(makeDefaultOptions(), options?.default);
17
- app.mixins.push((service, path) => {
21
+ app.mixins.push((service: DebouncedService, path) => {
18
22
  // if path is on blacklist, don't add debouncedStore to service
19
23
  if (options?.blacklist && options.blacklist.includes(path)) return;
20
24
  // if service already has registered something on `debouncedStore`
@@ -29,4 +33,4 @@ export function debounceMixin(options?: Partial<InitDebounceMixinOptions>): ((ap
29
33
  };
30
34
  }
31
35
 
32
- export { DebouncedStore };
36
+ export { DebouncedStore };
package/src/types.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { Application, Service } from "@feathersjs/feathers";
1
+ import type { Application } from "@feathersjs/feathers";
2
+ import type { AdapterService } from "@feathersjs/adapter-commons";
2
3
 
3
4
  export type Path = Array<string|number>;
4
5
  export type HookType = "before" | "after" | "error";
@@ -69,7 +70,7 @@ export interface MergeQueryOptions<T> extends FilterQueryOptions<T> {
69
70
  }
70
71
 
71
72
  export interface FilterQueryOptions<T> {
72
- service?: Service<T>
73
+ service?: AdapterService<T>
73
74
  operators?: string[],
74
75
  filters?: string[],
75
76
  }
@@ -86,4 +87,4 @@ export interface FilterQueryResult {
86
87
  [key: string]: unknown
87
88
  }
88
89
 
89
- //#endregion
90
+ //#endregion
@@ -25,10 +25,10 @@ export function filterQuery<T>(query: Query, options?: FilterQueryOptions<T>): F
25
25
  if (operators) { optionsForFilterQuery.operators = operators; }
26
26
  if (filters) { optionsForFilterQuery.filters = filters; }
27
27
  if (typeof service?.filterQuery === "function") {
28
- return service.filterQuery({ query }, optionsForFilterQuery);
28
+ return service.filterQuery({ query }, optionsForFilterQuery) as FilterQueryResult;
29
29
  } else {
30
30
  return plainFilterQuery(query, optionsForFilterQuery) as FilterQueryResult;
31
31
  }
32
32
  }
33
33
  return plainFilterQuery(query, options) as FilterQueryResult;
34
- }
34
+ }
@@ -0,0 +1,26 @@
1
+ import { HookContext } from "@feathersjs/feathers";
2
+
3
+ // TODO: seems like this does no longer exist in feathers
4
+ interface PaginationOptions {
5
+ default: number;
6
+ max: number;
7
+ }
8
+
9
+
10
+ export const getPaginate = (
11
+ context: HookContext
12
+ ): PaginationOptions | undefined => {
13
+ if (Object.prototype.hasOwnProperty.call(context.params, "paginate")) {
14
+ return context.params.paginate as PaginationOptions || undefined;
15
+ }
16
+
17
+ if (context.params.paginate === false) { return undefined; }
18
+ let options = context.service.options || {};
19
+
20
+ options = {
21
+ ...options,
22
+ ...context.params.adapter
23
+ };
24
+
25
+ return options.paginate || undefined;
26
+ };
@@ -4,13 +4,12 @@ export const isMulti = (context: HookContext): boolean => {
4
4
  const { method } = context;
5
5
  if (method === "find") {
6
6
  return true;
7
- } else if (["patch", "remove"].includes(context.method)) {
7
+ } else if (["patch", "remove"].includes(method)) {
8
8
  return context.id == null;
9
9
  } else if (method === "create") {
10
10
  const items = context.type === "before" ? context.data : context.result;
11
- items && context.method === "find" ? items.data || items : items;
12
11
  return Array.isArray(items);
13
- } else if (method === "get" || method === "update") {
12
+ } else if (["get", "update"].includes(method)) {
14
13
  return false;
15
14
  }
16
15
  return false;
@@ -0,0 +1,12 @@
1
+ import { HookContext } from "@feathersjs/feathers";
2
+ import { getPaginate } from "./getPaginate";
3
+
4
+ export const isPaginated = (
5
+ context: HookContext
6
+ ): boolean => {
7
+ if (context.params.paginate === false) { return false; }
8
+
9
+ const paginate = getPaginate(context);
10
+
11
+ return !!paginate;
12
+ };