feathers-utils 2.0.0-9 → 2.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 (150) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -1
  3. package/dist/index.cjs +918 -0
  4. package/dist/index.d.ts +255 -5
  5. package/dist/index.mjs +892 -0
  6. package/package.json +34 -38
  7. package/src/filters/object.ts +1 -1
  8. package/src/hooks/forEach.ts +47 -0
  9. package/src/hooks/index.ts +3 -0
  10. package/src/hooks/makeSequelizeQuery.ts_ +4 -4
  11. package/src/hooks/parseFields.ts +27 -0
  12. package/src/index.ts +1 -0
  13. package/src/typesInternal.ts +7 -0
  14. package/src/utility-types/index.ts +116 -0
  15. package/src/utils/getItemsIsArray.ts +27 -11
  16. package/dist/esm/filters/array.d.ts +0 -2
  17. package/dist/esm/filters/array.js +0 -17
  18. package/dist/esm/filters/index.d.ts +0 -2
  19. package/dist/esm/filters/index.js +0 -2
  20. package/dist/esm/filters/object.d.ts +0 -2
  21. package/dist/esm/filters/object.js +0 -15
  22. package/dist/esm/hooks/checkMulti.d.ts +0 -5
  23. package/dist/esm/hooks/checkMulti.js +0 -20
  24. package/dist/esm/hooks/createRelated.d.ts +0 -12
  25. package/dist/esm/hooks/createRelated.js +0 -31
  26. package/dist/esm/hooks/index.d.ts +0 -6
  27. package/dist/esm/hooks/index.js +0 -6
  28. package/dist/esm/hooks/onDelete.d.ts +0 -12
  29. package/dist/esm/hooks/onDelete.js +0 -47
  30. package/dist/esm/hooks/removeRelated.d.ts +0 -11
  31. package/dist/esm/hooks/removeRelated.js +0 -37
  32. package/dist/esm/hooks/runPerItem.d.ts +0 -10
  33. package/dist/esm/hooks/runPerItem.js +0 -29
  34. package/dist/esm/hooks/setData.d.ts +0 -11
  35. package/dist/esm/hooks/setData.js +0 -46
  36. package/dist/esm/index.d.ts +0 -5
  37. package/dist/esm/index.js +0 -5
  38. package/dist/esm/mixins/debounce-mixin/DebouncedStore.d.ts +0 -18
  39. package/dist/esm/mixins/debounce-mixin/DebouncedStore.js +0 -46
  40. package/dist/esm/mixins/debounce-mixin/debounceMixin.d.ts +0 -3
  41. package/dist/esm/mixins/debounce-mixin/debounceMixin.js +0 -19
  42. package/dist/esm/mixins/debounce-mixin/index.d.ts +0 -3
  43. package/dist/esm/mixins/debounce-mixin/index.js +0 -3
  44. package/dist/esm/mixins/debounce-mixin/types.d.ts +0 -13
  45. package/dist/esm/mixins/debounce-mixin/types.js +0 -1
  46. package/dist/esm/mixins/index.d.ts +0 -1
  47. package/dist/esm/mixins/index.js +0 -1
  48. package/dist/esm/types.d.ts +0 -3
  49. package/dist/esm/types.js +0 -1
  50. package/dist/esm/typesInternal.d.ts +0 -3
  51. package/dist/esm/typesInternal.js +0 -3
  52. package/dist/esm/utils/filterQuery.d.ts +0 -8
  53. package/dist/esm/utils/filterQuery.js +0 -30
  54. package/dist/esm/utils/getItemsIsArray.d.ts +0 -10
  55. package/dist/esm/utils/getItemsIsArray.js +0 -16
  56. package/dist/esm/utils/getPaginate.d.ts +0 -9
  57. package/dist/esm/utils/getPaginate.js +0 -20
  58. package/dist/esm/utils/index.d.ts +0 -11
  59. package/dist/esm/utils/index.js +0 -11
  60. package/dist/esm/utils/isMulti.d.ts +0 -11
  61. package/dist/esm/utils/isMulti.js +0 -26
  62. package/dist/esm/utils/isPaginated.d.ts +0 -5
  63. package/dist/esm/utils/isPaginated.js +0 -11
  64. package/dist/esm/utils/markHookForSkip.d.ts +0 -7
  65. package/dist/esm/utils/markHookForSkip.js +0 -18
  66. package/dist/esm/utils/mergeQuery/index.d.ts +0 -3
  67. package/dist/esm/utils/mergeQuery/index.js +0 -3
  68. package/dist/esm/utils/mergeQuery/mergeArrays.d.ts +0 -3
  69. package/dist/esm/utils/mergeQuery/mergeArrays.js +0 -37
  70. package/dist/esm/utils/mergeQuery/mergeQuery.d.ts +0 -3
  71. package/dist/esm/utils/mergeQuery/mergeQuery.js +0 -70
  72. package/dist/esm/utils/mergeQuery/types.d.ts +0 -13
  73. package/dist/esm/utils/mergeQuery/types.js +0 -1
  74. package/dist/esm/utils/mergeQuery/utils.d.ts +0 -11
  75. package/dist/esm/utils/mergeQuery/utils.js +0 -272
  76. package/dist/esm/utils/pushSet.d.ts +0 -8
  77. package/dist/esm/utils/pushSet.js +0 -22
  78. package/dist/esm/utils/setResultEmpty.d.ts +0 -5
  79. package/dist/esm/utils/setResultEmpty.js +0 -28
  80. package/dist/esm/utils/shouldSkip.d.ts +0 -8
  81. package/dist/esm/utils/shouldSkip.js +0 -29
  82. package/dist/esm/utils/validateQueryProperty.d.ts +0 -5
  83. package/dist/esm/utils/validateQueryProperty.js +0 -23
  84. package/dist/filters/array.d.ts +0 -2
  85. package/dist/filters/array.js +0 -21
  86. package/dist/filters/index.d.ts +0 -2
  87. package/dist/filters/index.js +0 -18
  88. package/dist/filters/object.d.ts +0 -2
  89. package/dist/filters/object.js +0 -22
  90. package/dist/hooks/checkMulti.d.ts +0 -5
  91. package/dist/hooks/checkMulti.js +0 -24
  92. package/dist/hooks/createRelated.d.ts +0 -12
  93. package/dist/hooks/createRelated.js +0 -44
  94. package/dist/hooks/index.d.ts +0 -6
  95. package/dist/hooks/index.js +0 -22
  96. package/dist/hooks/onDelete.d.ts +0 -12
  97. package/dist/hooks/onDelete.js +0 -60
  98. package/dist/hooks/removeRelated.d.ts +0 -11
  99. package/dist/hooks/removeRelated.js +0 -50
  100. package/dist/hooks/runPerItem.d.ts +0 -10
  101. package/dist/hooks/runPerItem.js +0 -42
  102. package/dist/hooks/setData.d.ts +0 -11
  103. package/dist/hooks/setData.js +0 -54
  104. package/dist/index.js +0 -21
  105. package/dist/mixins/debounce-mixin/DebouncedStore.d.ts +0 -18
  106. package/dist/mixins/debounce-mixin/DebouncedStore.js +0 -65
  107. package/dist/mixins/debounce-mixin/debounceMixin.d.ts +0 -3
  108. package/dist/mixins/debounce-mixin/debounceMixin.js +0 -23
  109. package/dist/mixins/debounce-mixin/index.d.ts +0 -3
  110. package/dist/mixins/debounce-mixin/index.js +0 -19
  111. package/dist/mixins/debounce-mixin/types.d.ts +0 -13
  112. package/dist/mixins/debounce-mixin/types.js +0 -2
  113. package/dist/mixins/index.d.ts +0 -1
  114. package/dist/mixins/index.js +0 -17
  115. package/dist/types.d.ts +0 -3
  116. package/dist/types.js +0 -2
  117. package/dist/typesInternal.d.ts +0 -3
  118. package/dist/typesInternal.js +0 -4
  119. package/dist/utils/filterQuery.d.ts +0 -8
  120. package/dist/utils/filterQuery.js +0 -46
  121. package/dist/utils/getItemsIsArray.d.ts +0 -10
  122. package/dist/utils/getItemsIsArray.js +0 -20
  123. package/dist/utils/getPaginate.d.ts +0 -9
  124. package/dist/utils/getPaginate.js +0 -22
  125. package/dist/utils/index.d.ts +0 -11
  126. package/dist/utils/index.js +0 -27
  127. package/dist/utils/isMulti.d.ts +0 -11
  128. package/dist/utils/isMulti.js +0 -30
  129. package/dist/utils/isPaginated.d.ts +0 -5
  130. package/dist/utils/isPaginated.js +0 -15
  131. package/dist/utils/markHookForSkip.d.ts +0 -7
  132. package/dist/utils/markHookForSkip.js +0 -22
  133. package/dist/utils/mergeQuery/index.d.ts +0 -3
  134. package/dist/utils/mergeQuery/index.js +0 -19
  135. package/dist/utils/mergeQuery/mergeArrays.d.ts +0 -3
  136. package/dist/utils/mergeQuery/mergeArrays.js +0 -41
  137. package/dist/utils/mergeQuery/mergeQuery.d.ts +0 -3
  138. package/dist/utils/mergeQuery/mergeQuery.js +0 -77
  139. package/dist/utils/mergeQuery/types.d.ts +0 -13
  140. package/dist/utils/mergeQuery/types.js +0 -2
  141. package/dist/utils/mergeQuery/utils.d.ts +0 -11
  142. package/dist/utils/mergeQuery/utils.js +0 -287
  143. package/dist/utils/pushSet.d.ts +0 -8
  144. package/dist/utils/pushSet.js +0 -29
  145. package/dist/utils/setResultEmpty.d.ts +0 -5
  146. package/dist/utils/setResultEmpty.js +0 -32
  147. package/dist/utils/shouldSkip.d.ts +0 -8
  148. package/dist/utils/shouldSkip.js +0 -33
  149. package/dist/utils/validateQueryProperty.d.ts +0 -5
  150. package/dist/utils/validateQueryProperty.js +0 -25
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isMulti = void 0;
4
- /**
5
- * util to check if a hook is a multi hook:
6
- * - find: true
7
- * - get: false
8
- * - create: `context.data` is an array
9
- * - update: false
10
- * - patch: `context.id == null`
11
- * - remove: `context.id == null`
12
- */
13
- const isMulti = (context) => {
14
- const { method } = context;
15
- if (method === "find") {
16
- return true;
17
- }
18
- else if (["patch", "remove"].includes(method)) {
19
- return context.id == null;
20
- }
21
- else if (method === "create") {
22
- const items = context.type === "before" ? context.data : context.result;
23
- return Array.isArray(items);
24
- }
25
- else if (["get", "update"].includes(method)) {
26
- return false;
27
- }
28
- return false;
29
- };
30
- exports.isMulti = isMulti;
@@ -1,5 +0,0 @@
1
- import type { HookContext } from "@feathersjs/feathers";
2
- /**
3
- * util to check if a hook is a paginated hook using `getPaginate`
4
- */
5
- export declare const isPaginated: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(context: H) => boolean;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isPaginated = void 0;
4
- const getPaginate_1 = require("./getPaginate");
5
- /**
6
- * util to check if a hook is a paginated hook using `getPaginate`
7
- */
8
- const isPaginated = (context) => {
9
- if (context.params.paginate === false || context.method !== "find") {
10
- return false;
11
- }
12
- const paginate = (0, getPaginate_1.getPaginate)(context);
13
- return !!paginate;
14
- };
15
- exports.isPaginated = isPaginated;
@@ -1,7 +0,0 @@
1
- import type { HookContext } from "@feathersjs/feathers";
2
- import type { HookType } from "feathers-hooks-common";
3
- import type { MaybeArray } from "../typesInternal";
4
- /**
5
- * util to mark a hook for skip, has to be used with `shouldSkip`
6
- */
7
- export declare function markHookForSkip<H extends HookContext = HookContext>(hookName: string, type: "all" | MaybeArray<HookType>, context?: H): H | undefined;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.markHookForSkip = void 0;
4
- const pushSet_1 = require("./pushSet");
5
- /**
6
- * util to mark a hook for skip, has to be used with `shouldSkip`
7
- */
8
- function markHookForSkip(hookName, type, context) {
9
- // @ts-expect-error context is not of type 'H'
10
- context = context || {};
11
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
12
- const params = context.params || {};
13
- const types = Array.isArray(type) ? type : [type];
14
- types.forEach((t) => {
15
- const combinedName = t === "all" ? hookName : `${type}:${hookName}`;
16
- (0, pushSet_1.pushSet)(params, ["skipHooks"], combinedName, { unique: true });
17
- });
18
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
19
- context.params = params;
20
- return context;
21
- }
22
- exports.markHookForSkip = markHookForSkip;
@@ -1,3 +0,0 @@
1
- export * from "./mergeArrays";
2
- export * from "./mergeQuery";
3
- export * from "./types";
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./mergeArrays"), exports);
18
- __exportStar(require("./mergeQuery"), exports);
19
- __exportStar(require("./types"), exports);
@@ -1,3 +0,0 @@
1
- import type { Path } from "../../typesInternal";
2
- import type { Handle, ActionOnEmptyIntersect } from "./types";
3
- export declare function mergeArrays<T>(targetArr: T[], sourceArr: T[], handle: Handle, prependKey?: Path, actionOnEmptyIntersect?: ActionOnEmptyIntersect): T[] | undefined;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeArrays = void 0;
4
- function mergeArrays(targetArr, sourceArr, handle, prependKey, actionOnEmptyIntersect) {
5
- if (!sourceArr && !targetArr) {
6
- return;
7
- }
8
- if (handle === "target") {
9
- return targetArr;
10
- }
11
- else if (handle === "source") {
12
- return sourceArr;
13
- }
14
- else if (handle === "combine") {
15
- if (!sourceArr || !Array.isArray(sourceArr)) {
16
- return targetArr;
17
- }
18
- if (!targetArr || !Array.isArray(targetArr)) {
19
- return sourceArr;
20
- }
21
- const arr = targetArr.concat(sourceArr);
22
- return [...new Set(arr)];
23
- }
24
- else if (handle === "intersect" || handle === "intersectOrFull") {
25
- const targetIsArray = !targetArr || !Array.isArray(targetArr);
26
- const sourceIsArray = !sourceArr || !Array.isArray(sourceArr);
27
- if ((targetIsArray || sourceIsArray) && handle === "intersect") {
28
- if (actionOnEmptyIntersect) {
29
- actionOnEmptyIntersect(targetArr, sourceArr, prependKey || []);
30
- }
31
- return;
32
- }
33
- if (handle === "intersectOrFull") {
34
- const val = !targetIsArray ? targetArr : sourceArr;
35
- return val;
36
- }
37
- return targetArr.filter((val) => sourceArr.includes(val));
38
- }
39
- return undefined;
40
- }
41
- exports.mergeArrays = mergeArrays;
@@ -1,3 +0,0 @@
1
- import type { Query } from "@feathersjs/feathers";
2
- import type { MergeQueryOptions } from "./types";
3
- export declare function mergeQuery<T>(target: Query, source: Query, options?: Partial<MergeQueryOptions<T>>): Query;
@@ -1,77 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.mergeQuery = void 0;
7
- const merge_js_1 = __importDefault(require("lodash/merge.js"));
8
- const isEmpty_js_1 = __importDefault(require("lodash/isEmpty.js"));
9
- const utils_1 = require("./utils");
10
- const filterQuery_1 = require("../filterQuery");
11
- function mergeQuery(target, source, options) {
12
- const fullOptions = (0, utils_1.makeDefaultOptions)(options);
13
- const { filters: targetFilters, query: targetQuery } = (0, filterQuery_1.filterQuery)(target, {
14
- operators: fullOptions.operators,
15
- filters: fullOptions.filters,
16
- service: fullOptions.service,
17
- });
18
- (0, utils_1.moveProperty)(targetFilters, targetQuery, "$or");
19
- (0, utils_1.moveProperty)(targetFilters, targetQuery, "$and");
20
- if (target.$limit) {
21
- targetFilters.$limit = target.$limit;
22
- }
23
- let {
24
- // eslint-disable-next-line prefer-const
25
- filters: sourceFilters, query: sourceQuery, } = (0, filterQuery_1.filterQuery)(source, {
26
- operators: fullOptions.operators,
27
- filters: fullOptions.filters,
28
- service: fullOptions.service,
29
- });
30
- (0, utils_1.moveProperty)(sourceFilters, sourceQuery, "$or");
31
- (0, utils_1.moveProperty)(sourceFilters, sourceQuery, "$and");
32
- if (source.$limit) {
33
- sourceFilters.$limit = source.$limit;
34
- }
35
- //#region filters
36
- if (target &&
37
- !Object.prototype.hasOwnProperty.call(target, "$limit") &&
38
- Object.prototype.hasOwnProperty.call(targetFilters, "$limit")) {
39
- delete targetFilters.$limit;
40
- }
41
- if (source &&
42
- !Object.prototype.hasOwnProperty.call(source, "$limit") &&
43
- Object.prototype.hasOwnProperty.call(sourceFilters, "$limit")) {
44
- delete sourceFilters.$limit;
45
- }
46
- (0, utils_1.handleArray)(targetFilters, sourceFilters, ["$select"], fullOptions);
47
- // remaining filters
48
- delete sourceFilters["$select"];
49
- (0, merge_js_1.default)(targetFilters, sourceFilters);
50
- //#endregion
51
- //#region '$or' / '$and'
52
- if ((options === null || options === void 0 ? void 0 : options.useLogicalConjunction) &&
53
- (options.defaultHandle === "combine" ||
54
- options.defaultHandle === "intersect") &&
55
- !(0, isEmpty_js_1.default)(targetQuery)) {
56
- const logicalOp = options.defaultHandle === "combine" ? "$or" : "$and";
57
- if (Object.prototype.hasOwnProperty.call(sourceQuery, logicalOp)) {
58
- // omit '$or'/'$and' and put all other props into '$or'/'$and'
59
- const andOr = sourceQuery[logicalOp];
60
- delete sourceQuery[logicalOp];
61
- andOr.push(sourceQuery);
62
- sourceQuery = { [logicalOp]: andOr };
63
- }
64
- else {
65
- sourceQuery = { [logicalOp]: [sourceQuery] };
66
- }
67
- }
68
- //#endregion
69
- const keys = Object.keys(sourceQuery);
70
- for (let i = 0, n = keys.length; i < n; i++) {
71
- const key = keys[i];
72
- (0, utils_1.handleCircular)(targetQuery, sourceQuery, [key], fullOptions);
73
- }
74
- const result = Object.assign({}, targetFilters, targetQuery);
75
- return result;
76
- }
77
- exports.mergeQuery = mergeQuery;
@@ -1,13 +0,0 @@
1
- import type { Path } from "../../typesInternal";
2
- import type { FilterQueryOptions } from "../filterQuery";
3
- export type Handle = "target" | "source" | "combine" | "intersect" | "intersectOrFull";
4
- export type FirstLast = "first" | "last";
5
- export type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
6
- export interface MergeQueryOptions<T> extends FilterQueryOptions<T> {
7
- defaultHandle: Handle;
8
- actionOnEmptyIntersect: ActionOnEmptyIntersect;
9
- useLogicalConjunction: boolean;
10
- handle?: {
11
- [key: string]: Handle;
12
- };
13
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +0,0 @@
1
- import type { Path } from "../../typesInternal";
2
- import type { MergeQueryOptions } from "./types";
3
- export declare const hasOwnProperty: (obj: Record<string, unknown>, key: string) => boolean;
4
- export declare function handleArray<T>(target: Record<string, unknown>, source: Record<string, unknown>, key: Path, options: MergeQueryOptions<T>): void;
5
- export declare function handleCircular<T>(target: Record<string, unknown>, source: Record<string, unknown>, prependKey: Path, options: MergeQueryOptions<T>): void;
6
- export declare function makeDefaultOptions<T>(options?: Partial<MergeQueryOptions<T>>): MergeQueryOptions<T>;
7
- export declare function moveProperty(source: Record<string, any>, target: Record<string, any>, key: string): void;
8
- export declare function getParentProp(target: Record<string, unknown>, path: Path): any;
9
- export declare function cleanOr(target: Record<string, unknown>[]): Record<string, unknown>[] | undefined;
10
- export declare function cleanAnd(target: Record<string, unknown>[]): Record<string, unknown>[] | undefined;
11
- export declare function arrayWithoutDuplicates<T>(target: T[]): T[];
@@ -1,287 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.arrayWithoutDuplicates = exports.cleanAnd = exports.cleanOr = exports.getParentProp = exports.moveProperty = exports.makeDefaultOptions = exports.handleCircular = exports.handleArray = exports.hasOwnProperty = void 0;
7
- const errors_1 = require("@feathersjs/errors");
8
- const get_js_1 = __importDefault(require("lodash/get.js"));
9
- const has_js_1 = __importDefault(require("lodash/has.js"));
10
- const isEmpty_js_1 = __importDefault(require("lodash/isEmpty.js"));
11
- const isEqual_js_1 = __importDefault(require("lodash/isEqual.js"));
12
- const set_js_1 = __importDefault(require("lodash/set.js"));
13
- const uniqWith_js_1 = __importDefault(require("lodash/uniqWith.js"));
14
- const mergeArrays_1 = require("./mergeArrays");
15
- const hasOwnProperty = (obj, key) => {
16
- return Object.prototype.hasOwnProperty.call(obj, key);
17
- };
18
- exports.hasOwnProperty = hasOwnProperty;
19
- function handleArray(target, source, key, options) {
20
- const targetVal = (0, get_js_1.default)(target, key);
21
- const sourceVal = (0, get_js_1.default)(source, key);
22
- if (!sourceVal && !targetVal) {
23
- return;
24
- }
25
- const handle = (0, get_js_1.default)(options, ["handle", ...key], options.defaultHandle);
26
- const arr = (0, mergeArrays_1.mergeArrays)(targetVal, sourceVal, handle, key, options.actionOnEmptyIntersect);
27
- (0, set_js_1.default)(target, key, arr);
28
- }
29
- exports.handleArray = handleArray;
30
- function handleCircular(target, source, prependKey, options) {
31
- if (target === null || target === void 0 ? void 0 : target.$or) {
32
- target.$or = cleanOr(target.$or);
33
- if (!target.$or) {
34
- delete target.$or;
35
- }
36
- }
37
- if (source === null || source === void 0 ? void 0 : source.$or) {
38
- source.$or = cleanOr(source.$or);
39
- if (!source.$or) {
40
- delete source.$or;
41
- }
42
- }
43
- if (target === null || target === void 0 ? void 0 : target.$and) {
44
- target.$and = cleanAnd(target.$and);
45
- if (!target.$and) {
46
- delete target.$and;
47
- }
48
- }
49
- if (source === null || source === void 0 ? void 0 : source.$and) {
50
- source.$and = cleanAnd(source.$and);
51
- if (!source.$and) {
52
- delete source.$and;
53
- }
54
- }
55
- if (!(0, has_js_1.default)(source, prependKey)) {
56
- return;
57
- }
58
- if (!(0, has_js_1.default)(target, prependKey)) {
59
- (0, set_js_1.default)(target, prependKey, (0, get_js_1.default)(source, prependKey));
60
- return;
61
- }
62
- const { defaultHandle, actionOnEmptyIntersect } = options;
63
- if (defaultHandle === "target") {
64
- return;
65
- }
66
- const getTargetVal = () => {
67
- return prependKey.length > 0 ? (0, get_js_1.default)(target, prependKey) : target;
68
- };
69
- const getSourceVal = () => {
70
- return prependKey.length > 0 ? (0, get_js_1.default)(source, prependKey) : source;
71
- };
72
- const targetVal = getTargetVal();
73
- const sourceVal = getSourceVal();
74
- if ((0, isEqual_js_1.default)(targetVal, sourceVal)) {
75
- return;
76
- }
77
- if (defaultHandle === "source") {
78
- (0, set_js_1.default)(target, prependKey, sourceVal);
79
- return;
80
- }
81
- if (targetVal === null || sourceVal === null) {
82
- (0, set_js_1.default)(target, prependKey, sourceVal);
83
- return;
84
- }
85
- const typeOfTargetVal = typeof targetVal;
86
- if (["boolean"].includes(typeOfTargetVal)) {
87
- if (defaultHandle === "intersect") {
88
- actionOnEmptyIntersect(target, source, prependKey);
89
- }
90
- (0, set_js_1.default)(target, prependKey, sourceVal);
91
- return;
92
- }
93
- const typeOfSourceVal = typeof sourceVal;
94
- const isTargetSimple = ["string", "number"].includes(typeOfTargetVal);
95
- const isSourceSimple = ["string", "number"].includes(typeOfSourceVal);
96
- if (isTargetSimple || isSourceSimple) {
97
- if (isTargetSimple && isSourceSimple) {
98
- if (defaultHandle === "combine") {
99
- (0, set_js_1.default)(target, prependKey, { $in: [...new Set([targetVal, sourceVal])] });
100
- return;
101
- }
102
- else if (defaultHandle === "intersect") {
103
- actionOnEmptyIntersect(target, source, prependKey);
104
- }
105
- else {
106
- throw new Error("should not reach here");
107
- }
108
- }
109
- else if ((0, exports.hasOwnProperty)(targetVal, "$in") ||
110
- (0, exports.hasOwnProperty)(sourceVal, "$in")) {
111
- const targetHasIn = (0, exports.hasOwnProperty)(targetVal, "$in");
112
- const $in = targetHasIn ? targetVal["$in"] : sourceVal["$in"];
113
- const otherVal = isTargetSimple ? targetVal : sourceVal;
114
- if ($in.length === 1 && (0, isEqual_js_1.default)($in[0], otherVal)) {
115
- (0, set_js_1.default)(target, prependKey, otherVal);
116
- return;
117
- }
118
- else if (defaultHandle === "combine") {
119
- if (!$in.some((x) => (0, isEqual_js_1.default)(x, otherVal))) {
120
- $in.push(otherVal);
121
- }
122
- (0, set_js_1.default)(target, `${prependKey}.$in`, $in);
123
- return;
124
- }
125
- else if (defaultHandle === "intersect") {
126
- if ($in.some((x) => (0, isEqual_js_1.default)(x, otherVal))) {
127
- (0, set_js_1.default)(target, prependKey, otherVal);
128
- }
129
- else {
130
- actionOnEmptyIntersect(target, source, prependKey);
131
- }
132
- return;
133
- }
134
- return;
135
- }
136
- }
137
- const isTargetArray = Array.isArray(targetVal);
138
- const isSourceArray = Array.isArray(sourceVal);
139
- if (isTargetArray && isSourceArray) {
140
- const key = prependKey[prependKey.length - 1];
141
- if (key === "$or") {
142
- if (defaultHandle === "combine") {
143
- const newVals = sourceVal.filter((x) => !targetVal.some((y) => (0, isEqual_js_1.default)(x, y)));
144
- targetVal.push(...newVals);
145
- }
146
- else if (defaultHandle === "intersect") {
147
- // combine into "$and"
148
- const targetParent = getParentProp(target, prependKey);
149
- const sourceParent = getParentProp(source, prependKey);
150
- targetParent.$and = targetParent.$and || [];
151
- targetParent.$and.push({ $or: targetVal }, { $or: sourceVal });
152
- targetParent.$and = cleanAnd(targetParent.$and);
153
- if (!targetParent.$and) {
154
- delete targetParent.$and;
155
- }
156
- delete targetParent.$or;
157
- delete sourceParent.$or;
158
- handleCircular(target, source, [...prependKey, "$and"], options);
159
- return;
160
- }
161
- return;
162
- }
163
- else if (key === "$and") {
164
- if (defaultHandle === "combine") {
165
- // combine into "$or"
166
- const targetParent = getParentProp(target, prependKey);
167
- const sourceParent = getParentProp(source, prependKey);
168
- targetParent.$or = targetParent.$or || [];
169
- targetParent.$or.push({ $and: targetVal }, { $and: sourceVal });
170
- targetParent.$or = cleanOr(targetParent.$or);
171
- if (!targetParent.$or) {
172
- delete targetParent.$or;
173
- }
174
- delete targetParent.$and;
175
- delete sourceParent.$and;
176
- handleCircular(target, source, [...prependKey, "$or"], options);
177
- return;
178
- }
179
- else if (defaultHandle === "intersect") {
180
- const newVals = sourceVal.filter((x) => !targetVal.some((y) => (0, isEqual_js_1.default)(x, y)));
181
- targetVal.push(...newVals);
182
- return;
183
- }
184
- }
185
- else if (key === "$in") {
186
- if (defaultHandle === "combine") {
187
- let $in = targetVal.concat(sourceVal);
188
- $in = [...new Set($in)];
189
- (0, set_js_1.default)(target, prependKey, $in);
190
- return;
191
- }
192
- else if (defaultHandle === "intersect") {
193
- const $in = targetVal.filter((x) => sourceVal.some((y) => (0, isEqual_js_1.default)(x, y)));
194
- if ($in.length === 0) {
195
- actionOnEmptyIntersect(target, source, prependKey);
196
- }
197
- else if ($in.length === 1) {
198
- (0, set_js_1.default)(target, prependKey.slice(0, -1), $in[0]);
199
- return;
200
- }
201
- else {
202
- (0, set_js_1.default)(target, prependKey, $in);
203
- }
204
- }
205
- return;
206
- }
207
- (0, set_js_1.default)(target, prependKey, sourceVal);
208
- return;
209
- }
210
- if (typeOfTargetVal !== "object" || typeOfSourceVal !== "object") {
211
- (0, set_js_1.default)(target, prependKey, sourceVal);
212
- return;
213
- }
214
- // both are objects
215
- const sourceKeys = Object.keys(sourceVal);
216
- for (let i = 0, n = sourceKeys.length; i < n; i++) {
217
- const key = sourceKeys[i];
218
- handleCircular(target, source, [...prependKey, key], options);
219
- }
220
- }
221
- exports.handleCircular = handleCircular;
222
- function makeDefaultOptions(options) {
223
- options = options || {};
224
- options.defaultHandle = options.defaultHandle || "combine";
225
- options.useLogicalConjunction = Object.prototype.hasOwnProperty.call(options, "useLogicalConjunction")
226
- ? options.useLogicalConjunction
227
- : false;
228
- options.actionOnEmptyIntersect =
229
- options.actionOnEmptyIntersect ||
230
- (() => {
231
- throw new errors_1.Forbidden("You're not allowed to make this request");
232
- });
233
- options.handle = options.handle || {};
234
- if (options.defaultHandle === "intersect") {
235
- options.handle.$select = options.handle.$select || "intersectOrFull";
236
- }
237
- return options;
238
- }
239
- exports.makeDefaultOptions = makeDefaultOptions;
240
- function moveProperty(source, target, key) {
241
- if (!Object.prototype.hasOwnProperty.call(source, key)) {
242
- return;
243
- }
244
- target[key] = source[key];
245
- delete source[key];
246
- }
247
- exports.moveProperty = moveProperty;
248
- function getParentProp(target, path) {
249
- if (path.length <= 1) {
250
- return target;
251
- }
252
- const pathOneUp = path.slice(0, -1);
253
- return (0, get_js_1.default)(target, pathOneUp);
254
- }
255
- exports.getParentProp = getParentProp;
256
- function cleanOr(target) {
257
- if (!target || !Array.isArray(target) || target.length <= 0) {
258
- return target;
259
- }
260
- if (target.some((x) => (0, isEmpty_js_1.default)(x))) {
261
- return undefined;
262
- }
263
- else {
264
- return arrayWithoutDuplicates(target);
265
- }
266
- }
267
- exports.cleanOr = cleanOr;
268
- function cleanAnd(target) {
269
- if (!target || !Array.isArray(target) || target.length <= 0) {
270
- return target;
271
- }
272
- if (target.every((x) => (0, isEmpty_js_1.default)(x))) {
273
- return undefined;
274
- }
275
- else {
276
- target = target.filter((x) => !(0, isEmpty_js_1.default)(x));
277
- return arrayWithoutDuplicates(target);
278
- }
279
- }
280
- exports.cleanAnd = cleanAnd;
281
- function arrayWithoutDuplicates(target) {
282
- if (!target || !Array.isArray(target)) {
283
- return target;
284
- }
285
- return (0, uniqWith_js_1.default)(target, isEqual_js_1.default);
286
- }
287
- exports.arrayWithoutDuplicates = arrayWithoutDuplicates;
@@ -1,8 +0,0 @@
1
- import type { Path } from "../typesInternal";
2
- export interface PushSetOptions {
3
- unique?: boolean;
4
- }
5
- /**
6
- * util to push a value to an array at a given path in an object
7
- */
8
- export declare const pushSet: (obj: Record<string, unknown>, path: string | Path, val: unknown, options?: PushSetOptions) => unknown[];
@@ -1,29 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.pushSet = void 0;
7
- const isEqual_js_1 = __importDefault(require("lodash/isEqual.js"));
8
- const get_js_1 = __importDefault(require("lodash/get.js"));
9
- const set_js_1 = __importDefault(require("lodash/set.js"));
10
- /**
11
- * util to push a value to an array at a given path in an object
12
- */
13
- const pushSet = (obj, path, val, options) => {
14
- options = options || {};
15
- let arr = (0, get_js_1.default)(obj, path);
16
- if (!arr || !Array.isArray(arr)) {
17
- arr = [val];
18
- (0, set_js_1.default)(obj, path, arr);
19
- return arr;
20
- }
21
- else {
22
- if (options.unique && arr.some((x) => (0, isEqual_js_1.default)(x, val))) {
23
- return arr;
24
- }
25
- arr.push(val);
26
- return arr;
27
- }
28
- };
29
- exports.pushSet = pushSet;
@@ -1,5 +0,0 @@
1
- import type { HookContext } from "@feathersjs/feathers";
2
- /**
3
- * util to set `context.result` to an empty array or object, depending on the hook type
4
- */
5
- export declare const setResultEmpty: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(context: H) => H;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setResultEmpty = void 0;
4
- const isMulti_1 = require("./isMulti");
5
- const isPaginated_1 = require("./isPaginated");
6
- /**
7
- * util to set `context.result` to an empty array or object, depending on the hook type
8
- */
9
- const setResultEmpty = (context) => {
10
- if (context.result) {
11
- return context;
12
- }
13
- const multi = (0, isMulti_1.isMulti)(context);
14
- if (multi) {
15
- if (context.method === "find" && (0, isPaginated_1.isPaginated)(context)) {
16
- context.result = {
17
- total: 0,
18
- skip: 0,
19
- limit: 0,
20
- data: [],
21
- };
22
- }
23
- else {
24
- context.result = [];
25
- }
26
- }
27
- else {
28
- context.result = null;
29
- }
30
- return context;
31
- };
32
- exports.setResultEmpty = setResultEmpty;
@@ -1,8 +0,0 @@
1
- import type { HookContext } from "@feathersjs/feathers";
2
- export type ShouldSkipOptions = {
3
- notSkippable?: boolean;
4
- };
5
- /**
6
- * util to detect if a hook should be skipped
7
- */
8
- export declare const shouldSkip: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>, O extends ShouldSkipOptions = ShouldSkipOptions>(hookName: string, context: H, options?: O | undefined) => boolean;