feathers-utils 2.1.3 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -15,6 +15,18 @@ const feathersHooksCommon = require('feathers-hooks-common');
15
15
  const _debounce = require('lodash/debounce.js');
16
16
  const _isObject = require('lodash/isObject.js');
17
17
 
18
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
19
+
20
+ const _merge__default = /*#__PURE__*/_interopDefaultCompat(_merge);
21
+ const _isEmpty__default = /*#__PURE__*/_interopDefaultCompat(_isEmpty);
22
+ const _get__default = /*#__PURE__*/_interopDefaultCompat(_get);
23
+ const _has__default = /*#__PURE__*/_interopDefaultCompat(_has);
24
+ const _set__default = /*#__PURE__*/_interopDefaultCompat(_set);
25
+ const _uniqWith__default = /*#__PURE__*/_interopDefaultCompat(_uniqWith);
26
+ const _isEqual__default = /*#__PURE__*/_interopDefaultCompat(_isEqual);
27
+ const _debounce__default = /*#__PURE__*/_interopDefaultCompat(_debounce);
28
+ const _isObject__default = /*#__PURE__*/_interopDefaultCompat(_isObject);
29
+
18
30
  function mergeArrays(targetArr, sourceArr, handle, prependKey, actionOnEmptyIntersect) {
19
31
  if (!sourceArr && !targetArr) {
20
32
  return;
@@ -59,12 +71,12 @@ const hasOwnProperty = (obj, ...keys) => {
59
71
  };
60
72
 
61
73
  function handleArray(target, source, key, options) {
62
- const targetVal = _get(target, key);
63
- const sourceVal = _get(source, key);
74
+ const targetVal = _get__default(target, key);
75
+ const sourceVal = _get__default(source, key);
64
76
  if (!sourceVal && !targetVal) {
65
77
  return;
66
78
  }
67
- const handle = _get(
79
+ const handle = _get__default(
68
80
  options,
69
81
  ["handle", ...key],
70
82
  options.defaultHandle
@@ -76,7 +88,7 @@ function handleArray(target, source, key, options) {
76
88
  key,
77
89
  options.actionOnEmptyIntersect
78
90
  );
79
- _set(target, key, arr);
91
+ _set__default(target, key, arr);
80
92
  }
81
93
  function handleCircular(target, source, prependKey, options) {
82
94
  if (target?.$or) {
@@ -103,11 +115,11 @@ function handleCircular(target, source, prependKey, options) {
103
115
  delete source.$and;
104
116
  }
105
117
  }
106
- if (!_has(source, prependKey)) {
118
+ if (!_has__default(source, prependKey)) {
107
119
  return;
108
120
  }
109
- if (!_has(target, prependKey)) {
110
- _set(target, prependKey, _get(source, prependKey));
121
+ if (!_has__default(target, prependKey)) {
122
+ _set__default(target, prependKey, _get__default(source, prependKey));
111
123
  return;
112
124
  }
113
125
  const { defaultHandle, actionOnEmptyIntersect } = options;
@@ -115,10 +127,10 @@ function handleCircular(target, source, prependKey, options) {
115
127
  return;
116
128
  }
117
129
  const getTargetVal = () => {
118
- return prependKey.length > 0 ? _get(target, prependKey) : target;
130
+ return prependKey.length > 0 ? _get__default(target, prependKey) : target;
119
131
  };
120
132
  const getSourceVal = () => {
121
- return prependKey.length > 0 ? _get(source, prependKey) : source;
133
+ return prependKey.length > 0 ? _get__default(source, prependKey) : source;
122
134
  };
123
135
  const targetVal = getTargetVal();
124
136
  const sourceVal = getSourceVal();
@@ -126,11 +138,11 @@ function handleCircular(target, source, prependKey, options) {
126
138
  return;
127
139
  }
128
140
  if (defaultHandle === "source") {
129
- _set(target, prependKey, sourceVal);
141
+ _set__default(target, prependKey, sourceVal);
130
142
  return;
131
143
  }
132
144
  if (targetVal === null || sourceVal === null) {
133
- _set(target, prependKey, sourceVal);
145
+ _set__default(target, prependKey, sourceVal);
134
146
  return;
135
147
  }
136
148
  const typeOfTargetVal = typeof targetVal;
@@ -138,7 +150,7 @@ function handleCircular(target, source, prependKey, options) {
138
150
  if (defaultHandle === "intersect") {
139
151
  actionOnEmptyIntersect(target, source, prependKey);
140
152
  }
141
- _set(target, prependKey, sourceVal);
153
+ _set__default(target, prependKey, sourceVal);
142
154
  return;
143
155
  }
144
156
  const typeOfSourceVal = typeof sourceVal;
@@ -147,7 +159,7 @@ function handleCircular(target, source, prependKey, options) {
147
159
  if (isTargetSimple || isSourceSimple) {
148
160
  if (isTargetSimple && isSourceSimple) {
149
161
  if (defaultHandle === "combine") {
150
- _set(target, prependKey, { $in: [.../* @__PURE__ */ new Set([targetVal, sourceVal])] });
162
+ _set__default(target, prependKey, { $in: [.../* @__PURE__ */ new Set([targetVal, sourceVal])] });
151
163
  return;
152
164
  } else if (defaultHandle === "intersect") {
153
165
  actionOnEmptyIntersect(target, source, prependKey);
@@ -159,17 +171,17 @@ function handleCircular(target, source, prependKey, options) {
159
171
  const $in = targetHasIn ? targetVal["$in"] : sourceVal["$in"];
160
172
  const otherVal = isTargetSimple ? targetVal : sourceVal;
161
173
  if ($in.length === 1 && fastEquals.deepEqual($in[0], otherVal)) {
162
- _set(target, prependKey, otherVal);
174
+ _set__default(target, prependKey, otherVal);
163
175
  return;
164
176
  } else if (defaultHandle === "combine") {
165
177
  if (!$in.some((x) => fastEquals.deepEqual(x, otherVal))) {
166
178
  $in.push(otherVal);
167
179
  }
168
- _set(target, `${prependKey}.$in`, $in);
180
+ _set__default(target, `${prependKey}.$in`, $in);
169
181
  return;
170
182
  } else if (defaultHandle === "intersect") {
171
183
  if ($in.some((x) => fastEquals.deepEqual(x, otherVal))) {
172
- _set(target, prependKey, otherVal);
184
+ _set__default(target, prependKey, otherVal);
173
185
  } else {
174
186
  actionOnEmptyIntersect(target, source, prependKey);
175
187
  }
@@ -228,7 +240,7 @@ function handleCircular(target, source, prependKey, options) {
228
240
  if (defaultHandle === "combine") {
229
241
  let $in = targetVal.concat(sourceVal);
230
242
  $in = [...new Set($in)];
231
- _set(target, prependKey, $in);
243
+ _set__default(target, prependKey, $in);
232
244
  return;
233
245
  } else if (defaultHandle === "intersect") {
234
246
  const $in = targetVal.filter(
@@ -237,19 +249,19 @@ function handleCircular(target, source, prependKey, options) {
237
249
  if ($in.length === 0) {
238
250
  actionOnEmptyIntersect(target, source, prependKey);
239
251
  } else if ($in.length === 1) {
240
- _set(target, prependKey.slice(0, -1), $in[0]);
252
+ _set__default(target, prependKey.slice(0, -1), $in[0]);
241
253
  return;
242
254
  } else {
243
- _set(target, prependKey, $in);
255
+ _set__default(target, prependKey, $in);
244
256
  }
245
257
  }
246
258
  return;
247
259
  }
248
- _set(target, prependKey, sourceVal);
260
+ _set__default(target, prependKey, sourceVal);
249
261
  return;
250
262
  }
251
263
  if (typeOfTargetVal !== "object" || typeOfSourceVal !== "object") {
252
- _set(target, prependKey, sourceVal);
264
+ _set__default(target, prependKey, sourceVal);
253
265
  return;
254
266
  }
255
267
  const sourceKeys = Object.keys(sourceVal);
@@ -285,13 +297,13 @@ function getParentProp(target, path) {
285
297
  return target;
286
298
  }
287
299
  const pathOneUp = path.slice(0, -1);
288
- return _get(target, pathOneUp);
300
+ return _get__default(target, pathOneUp);
289
301
  }
290
302
  function cleanOr(target) {
291
303
  if (!target || !Array.isArray(target) || target.length <= 0) {
292
304
  return target;
293
305
  }
294
- if (target.some((x) => _isEmpty(x))) {
306
+ if (target.some((x) => _isEmpty__default(x))) {
295
307
  return void 0;
296
308
  } else {
297
309
  return arrayWithoutDuplicates(target);
@@ -301,10 +313,10 @@ function cleanAnd(target) {
301
313
  if (!target || !Array.isArray(target) || target.length <= 0) {
302
314
  return target;
303
315
  }
304
- if (target.every((x) => _isEmpty(x))) {
316
+ if (target.every((x) => _isEmpty__default(x))) {
305
317
  return void 0;
306
318
  } else {
307
- target = target.filter((x) => !_isEmpty(x));
319
+ target = target.filter((x) => !_isEmpty__default(x));
308
320
  return arrayWithoutDuplicates(target);
309
321
  }
310
322
  }
@@ -312,7 +324,7 @@ function arrayWithoutDuplicates(target) {
312
324
  if (!target || !Array.isArray(target)) {
313
325
  return target;
314
326
  }
315
- return _uniqWith(target, fastEquals.deepEqual);
327
+ return _uniqWith__default(target, fastEquals.deepEqual);
316
328
  }
317
329
  function isQueryMoreExplicitThanQuery(target, source) {
318
330
  if (!target || !source) {
@@ -404,7 +416,7 @@ function mergeQuery(target, source, _options) {
404
416
  }
405
417
  handleArray(targetFilters, sourceFilters, ["$select"], options);
406
418
  delete sourceFilters["$select"];
407
- _merge(targetFilters, sourceFilters);
419
+ _merge__default(targetFilters, sourceFilters);
408
420
  const subsetQuery = isQueryMoreExplicitThanQuery(targetQuery, sourceQuery);
409
421
  if (options.defaultHandle === "intersect" && !!subsetQuery && !hasOwnProperty(targetQuery, "$or", "$and") && !hasOwnProperty(sourceQuery, "$or", "$and")) {
410
422
  return {
@@ -419,7 +431,7 @@ function mergeQuery(target, source, _options) {
419
431
  ...sourceQuery
420
432
  };
421
433
  }
422
- if (options.useLogicalConjunction && (options.defaultHandle === "combine" || options.defaultHandle === "intersect") && !_isEmpty(targetQuery)) {
434
+ if (options.useLogicalConjunction && (options.defaultHandle === "combine" || options.defaultHandle === "intersect") && !_isEmpty__default(targetQuery)) {
423
435
  const logicalOp = options.defaultHandle === "combine" ? "$or" : "$and";
424
436
  if (hasOwnProperty(sourceQuery, logicalOp)) {
425
437
  const andOr = sourceQuery[logicalOp];
@@ -501,13 +513,13 @@ const isPaginated = (context) => {
501
513
 
502
514
  const pushSet = (obj, path, val, options) => {
503
515
  options = options || {};
504
- let arr = _get(obj, path);
516
+ let arr = _get__default(obj, path);
505
517
  if (!arr || !Array.isArray(arr)) {
506
518
  arr = [val];
507
- _set(obj, path, arr);
519
+ _set__default(obj, path, arr);
508
520
  return arr;
509
521
  } else {
510
- if (options.unique && arr.some((x) => _isEqual(x, val))) {
522
+ if (options.unique && arr.some((x) => _isEqual__default(x, val))) {
511
523
  return arr;
512
524
  }
513
525
  arr.push(val);
@@ -802,16 +814,16 @@ function setData(from, to, _options) {
802
814
  return context;
803
815
  }
804
816
  const { items } = getItemsIsArray(context);
805
- if (!_has(context, from)) {
817
+ if (!_has__default(context, from)) {
806
818
  if (!context.params?.provider || options.allowUndefined === true) {
807
819
  return context;
808
820
  }
809
- if (!options.overwrite && items.every((item) => _has(item, to))) {
821
+ if (!options.overwrite && items.every((item) => _has__default(item, to))) {
810
822
  return context;
811
823
  }
812
824
  throw new errors.Forbidden(`Expected field ${from.toString()} not available`);
813
825
  }
814
- const val = _get(context, from);
826
+ const val = _get__default(context, from);
815
827
  items.forEach((item) => {
816
828
  let overwrite;
817
829
  if (typeof options.overwrite === "function") {
@@ -819,10 +831,10 @@ function setData(from, to, _options) {
819
831
  } else {
820
832
  overwrite = options.overwrite;
821
833
  }
822
- if (!overwrite && _has(item, to)) {
834
+ if (!overwrite && _has__default(item, to)) {
823
835
  return;
824
836
  }
825
- _set(item, to, val);
837
+ _set__default(item, to, val);
826
838
  });
827
839
  return context;
828
840
  };
@@ -862,7 +874,7 @@ class DebouncedStore {
862
874
  if (typeof this._queueById[id] === "function") {
863
875
  return this._queueById[id](id, action);
864
876
  }
865
- this._queueById[id] = _debounce(
877
+ this._queueById[id] = _debounce__default(
866
878
  (id2, action2) => {
867
879
  this.unbounced(id2, action2);
868
880
  },
@@ -922,7 +934,7 @@ const filterArray = (...keys) => {
922
934
  };
923
935
 
924
936
  const filterQueryObject = (key) => (obj, { operators }) => {
925
- if (obj && !_isObject(obj)) {
937
+ if (obj && !_isObject__default(obj)) {
926
938
  throw new Error(
927
939
  `Invalid query parameter: '${key}'. It has to be an object`
928
940
  );
package/dist/index.d.ts CHANGED
@@ -115,7 +115,7 @@ declare class DebouncedStore {
115
115
  private _options;
116
116
  private _isRunningById;
117
117
  _queueById: Record<string, DebouncedFunc<(id: Id, action: DebouncedFunctionApp) => void | Promise<void>>>;
118
- add: (id: Id, action: (app?: Application) => void | Promise<void>) => void | Promise<void> | undefined;
118
+ add: any;
119
119
  constructor(app: Application, options?: Partial<DebouncedStoreOptions>);
120
120
  private unbounced;
121
121
  private debounceById;
@@ -181,7 +181,7 @@ declare const isPaginated: <H extends HookContext<_feathersjs_feathers.Applicati
181
181
  /**
182
182
  * util to mark a hook for skip, has to be used with `shouldSkip`
183
183
  */
184
- declare function markHookForSkip<H extends HookContext = HookContext>(hookName: string, type: "all" | MaybeArray<HookType>, context?: H): H | undefined;
184
+ declare function markHookForSkip<H extends HookContext = HookContext>(hookName: string, type: "all" | MaybeArray<HookType>, context?: H): H;
185
185
 
186
186
  interface PushSetOptions {
187
187
  unique?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feathers-utils",
3
- "version": "2.1.3",
3
+ "version": "3.0.1",
4
4
  "description": "Some utils for projects using '@feathersjs/feathers'",
5
5
  "author": "fratzinger",
6
6
  "repository": {
@@ -12,14 +12,15 @@
12
12
  },
13
13
  "homepage": "https://github.com/fratzinger/feathers-utils",
14
14
  "license": "MIT",
15
- "type": "module",
16
15
  "exports": {
17
16
  ".": {
17
+ "types": "./dist/index.d.ts",
18
18
  "import": "./dist/index.mjs",
19
19
  "require": "./dist/index.cjs"
20
20
  }
21
21
  },
22
22
  "main": "./dist/index.cjs",
23
+ "module": "./dist/index.mjs",
23
24
  "types": "./dist/index.d.ts",
24
25
  "files": [
25
26
  "CHANGELOG.md",
@@ -39,36 +40,39 @@
39
40
  "lint": "eslint . --ext .js,.jsx,.ts,.tsx"
40
41
  },
41
42
  "dependencies": {
42
- "@feathersjs/adapter-commons": "5.0.1",
43
- "@feathersjs/commons": "^5.0.1",
44
- "@feathersjs/errors": "5.0.1",
45
- "@feathersjs/feathers": "5.0.1",
43
+ "@feathersjs/adapter-commons": "^5.0.5",
44
+ "@feathersjs/commons": "^5.0.5",
45
+ "@feathersjs/errors": "^5.0.5",
46
46
  "fast-equals": "^5.0.1",
47
- "feathers-hooks-common": "^7.0.1",
47
+ "feathers-hooks-common": "^7.0.3",
48
48
  "lodash": "^4.17.21"
49
49
  },
50
50
  "devDependencies": {
51
- "@feathersjs/memory": "^5.0.1",
51
+ "@feathersjs/feathers": "^5.0.5",
52
+ "@feathersjs/memory": "^5.0.5",
52
53
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
53
- "@types/lodash": "^4.14.191",
54
+ "@types/lodash": "^4.14.195",
54
55
  "@types/mocha": "^10.0.1",
55
- "@types/node": "^18.15.9",
56
- "@typescript-eslint/eslint-plugin": "^5.56.0",
57
- "@typescript-eslint/parser": "^5.56.0",
58
- "@vitest/coverage-c8": "^0.29.7",
56
+ "@types/node": "^20.2.5",
57
+ "@typescript-eslint/eslint-plugin": "^5.59.8",
58
+ "@typescript-eslint/parser": "^5.59.8",
59
+ "@vitest/coverage-c8": "^0.31.4",
59
60
  "cross-env": "^7.0.3",
60
- "eslint": "^8.36.0",
61
+ "eslint": "^8.41.0",
61
62
  "eslint-config-prettier": "^8.8.0",
62
- "eslint-import-resolver-typescript": "^3.5.3",
63
+ "eslint-import-resolver-typescript": "^3.5.5",
63
64
  "eslint-plugin-import": "^2.27.5",
64
65
  "eslint-plugin-prettier": "^4.2.1",
65
66
  "eslint-plugin-security": "^1.7.1",
66
- "np": "^7.6.4",
67
+ "np": "^8.0.2",
67
68
  "nyc": "^15.1.0",
68
- "prettier": "^2.8.7",
69
+ "prettier": "^2.8.8",
69
70
  "shx": "^0.3.4",
70
- "typescript": "^5.0.2",
71
- "unbuild": "^1.1.2",
72
- "vitest": "^0.29.7"
71
+ "typescript": "^5.1.3",
72
+ "unbuild": "^1.2.1",
73
+ "vitest": "^0.31.4"
74
+ },
75
+ "peerDependencies": {
76
+ "@feathersjs/feathers": "^5.0.0"
73
77
  }
74
78
  }