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,272 +0,0 @@
1
- import { Forbidden } from "@feathersjs/errors";
2
- import _get from "lodash/get.js";
3
- import _has from "lodash/has.js";
4
- import _isEmpty from "lodash/isEmpty.js";
5
- import _isEqual from "lodash/isEqual.js";
6
- import _set from "lodash/set.js";
7
- import _uniqWith from "lodash/uniqWith.js";
8
- import { mergeArrays } from "./mergeArrays";
9
- export const hasOwnProperty = (obj, key) => {
10
- return Object.prototype.hasOwnProperty.call(obj, key);
11
- };
12
- export function handleArray(target, source, key, options) {
13
- const targetVal = _get(target, key);
14
- const sourceVal = _get(source, key);
15
- if (!sourceVal && !targetVal) {
16
- return;
17
- }
18
- const handle = _get(options, ["handle", ...key], options.defaultHandle);
19
- const arr = mergeArrays(targetVal, sourceVal, handle, key, options.actionOnEmptyIntersect);
20
- _set(target, key, arr);
21
- }
22
- export function handleCircular(target, source, prependKey, options) {
23
- if (target?.$or) {
24
- target.$or = cleanOr(target.$or);
25
- if (!target.$or) {
26
- delete target.$or;
27
- }
28
- }
29
- if (source?.$or) {
30
- source.$or = cleanOr(source.$or);
31
- if (!source.$or) {
32
- delete source.$or;
33
- }
34
- }
35
- if (target?.$and) {
36
- target.$and = cleanAnd(target.$and);
37
- if (!target.$and) {
38
- delete target.$and;
39
- }
40
- }
41
- if (source?.$and) {
42
- source.$and = cleanAnd(source.$and);
43
- if (!source.$and) {
44
- delete source.$and;
45
- }
46
- }
47
- if (!_has(source, prependKey)) {
48
- return;
49
- }
50
- if (!_has(target, prependKey)) {
51
- _set(target, prependKey, _get(source, prependKey));
52
- return;
53
- }
54
- const { defaultHandle, actionOnEmptyIntersect } = options;
55
- if (defaultHandle === "target") {
56
- return;
57
- }
58
- const getTargetVal = () => {
59
- return prependKey.length > 0 ? _get(target, prependKey) : target;
60
- };
61
- const getSourceVal = () => {
62
- return prependKey.length > 0 ? _get(source, prependKey) : source;
63
- };
64
- const targetVal = getTargetVal();
65
- const sourceVal = getSourceVal();
66
- if (_isEqual(targetVal, sourceVal)) {
67
- return;
68
- }
69
- if (defaultHandle === "source") {
70
- _set(target, prependKey, sourceVal);
71
- return;
72
- }
73
- if (targetVal === null || sourceVal === null) {
74
- _set(target, prependKey, sourceVal);
75
- return;
76
- }
77
- const typeOfTargetVal = typeof targetVal;
78
- if (["boolean"].includes(typeOfTargetVal)) {
79
- if (defaultHandle === "intersect") {
80
- actionOnEmptyIntersect(target, source, prependKey);
81
- }
82
- _set(target, prependKey, sourceVal);
83
- return;
84
- }
85
- const typeOfSourceVal = typeof sourceVal;
86
- const isTargetSimple = ["string", "number"].includes(typeOfTargetVal);
87
- const isSourceSimple = ["string", "number"].includes(typeOfSourceVal);
88
- if (isTargetSimple || isSourceSimple) {
89
- if (isTargetSimple && isSourceSimple) {
90
- if (defaultHandle === "combine") {
91
- _set(target, prependKey, { $in: [...new Set([targetVal, sourceVal])] });
92
- return;
93
- }
94
- else if (defaultHandle === "intersect") {
95
- actionOnEmptyIntersect(target, source, prependKey);
96
- }
97
- else {
98
- throw new Error("should not reach here");
99
- }
100
- }
101
- else if (hasOwnProperty(targetVal, "$in") ||
102
- hasOwnProperty(sourceVal, "$in")) {
103
- const targetHasIn = hasOwnProperty(targetVal, "$in");
104
- const $in = targetHasIn ? targetVal["$in"] : sourceVal["$in"];
105
- const otherVal = isTargetSimple ? targetVal : sourceVal;
106
- if ($in.length === 1 && _isEqual($in[0], otherVal)) {
107
- _set(target, prependKey, otherVal);
108
- return;
109
- }
110
- else if (defaultHandle === "combine") {
111
- if (!$in.some((x) => _isEqual(x, otherVal))) {
112
- $in.push(otherVal);
113
- }
114
- _set(target, `${prependKey}.$in`, $in);
115
- return;
116
- }
117
- else if (defaultHandle === "intersect") {
118
- if ($in.some((x) => _isEqual(x, otherVal))) {
119
- _set(target, prependKey, otherVal);
120
- }
121
- else {
122
- actionOnEmptyIntersect(target, source, prependKey);
123
- }
124
- return;
125
- }
126
- return;
127
- }
128
- }
129
- const isTargetArray = Array.isArray(targetVal);
130
- const isSourceArray = Array.isArray(sourceVal);
131
- if (isTargetArray && isSourceArray) {
132
- const key = prependKey[prependKey.length - 1];
133
- if (key === "$or") {
134
- if (defaultHandle === "combine") {
135
- const newVals = sourceVal.filter((x) => !targetVal.some((y) => _isEqual(x, y)));
136
- targetVal.push(...newVals);
137
- }
138
- else if (defaultHandle === "intersect") {
139
- // combine into "$and"
140
- const targetParent = getParentProp(target, prependKey);
141
- const sourceParent = getParentProp(source, prependKey);
142
- targetParent.$and = targetParent.$and || [];
143
- targetParent.$and.push({ $or: targetVal }, { $or: sourceVal });
144
- targetParent.$and = cleanAnd(targetParent.$and);
145
- if (!targetParent.$and) {
146
- delete targetParent.$and;
147
- }
148
- delete targetParent.$or;
149
- delete sourceParent.$or;
150
- handleCircular(target, source, [...prependKey, "$and"], options);
151
- return;
152
- }
153
- return;
154
- }
155
- else if (key === "$and") {
156
- if (defaultHandle === "combine") {
157
- // combine into "$or"
158
- const targetParent = getParentProp(target, prependKey);
159
- const sourceParent = getParentProp(source, prependKey);
160
- targetParent.$or = targetParent.$or || [];
161
- targetParent.$or.push({ $and: targetVal }, { $and: sourceVal });
162
- targetParent.$or = cleanOr(targetParent.$or);
163
- if (!targetParent.$or) {
164
- delete targetParent.$or;
165
- }
166
- delete targetParent.$and;
167
- delete sourceParent.$and;
168
- handleCircular(target, source, [...prependKey, "$or"], options);
169
- return;
170
- }
171
- else if (defaultHandle === "intersect") {
172
- const newVals = sourceVal.filter((x) => !targetVal.some((y) => _isEqual(x, y)));
173
- targetVal.push(...newVals);
174
- return;
175
- }
176
- }
177
- else if (key === "$in") {
178
- if (defaultHandle === "combine") {
179
- let $in = targetVal.concat(sourceVal);
180
- $in = [...new Set($in)];
181
- _set(target, prependKey, $in);
182
- return;
183
- }
184
- else if (defaultHandle === "intersect") {
185
- const $in = targetVal.filter((x) => sourceVal.some((y) => _isEqual(x, y)));
186
- if ($in.length === 0) {
187
- actionOnEmptyIntersect(target, source, prependKey);
188
- }
189
- else if ($in.length === 1) {
190
- _set(target, prependKey.slice(0, -1), $in[0]);
191
- return;
192
- }
193
- else {
194
- _set(target, prependKey, $in);
195
- }
196
- }
197
- return;
198
- }
199
- _set(target, prependKey, sourceVal);
200
- return;
201
- }
202
- if (typeOfTargetVal !== "object" || typeOfSourceVal !== "object") {
203
- _set(target, prependKey, sourceVal);
204
- return;
205
- }
206
- // both are objects
207
- const sourceKeys = Object.keys(sourceVal);
208
- for (let i = 0, n = sourceKeys.length; i < n; i++) {
209
- const key = sourceKeys[i];
210
- handleCircular(target, source, [...prependKey, key], options);
211
- }
212
- }
213
- export function makeDefaultOptions(options) {
214
- options = options || {};
215
- options.defaultHandle = options.defaultHandle || "combine";
216
- options.useLogicalConjunction = Object.prototype.hasOwnProperty.call(options, "useLogicalConjunction")
217
- ? options.useLogicalConjunction
218
- : false;
219
- options.actionOnEmptyIntersect =
220
- options.actionOnEmptyIntersect ||
221
- (() => {
222
- throw new Forbidden("You're not allowed to make this request");
223
- });
224
- options.handle = options.handle || {};
225
- if (options.defaultHandle === "intersect") {
226
- options.handle.$select = options.handle.$select || "intersectOrFull";
227
- }
228
- return options;
229
- }
230
- export function moveProperty(source, target, key) {
231
- if (!Object.prototype.hasOwnProperty.call(source, key)) {
232
- return;
233
- }
234
- target[key] = source[key];
235
- delete source[key];
236
- }
237
- export function getParentProp(target, path) {
238
- if (path.length <= 1) {
239
- return target;
240
- }
241
- const pathOneUp = path.slice(0, -1);
242
- return _get(target, pathOneUp);
243
- }
244
- export function cleanOr(target) {
245
- if (!target || !Array.isArray(target) || target.length <= 0) {
246
- return target;
247
- }
248
- if (target.some((x) => _isEmpty(x))) {
249
- return undefined;
250
- }
251
- else {
252
- return arrayWithoutDuplicates(target);
253
- }
254
- }
255
- export function cleanAnd(target) {
256
- if (!target || !Array.isArray(target) || target.length <= 0) {
257
- return target;
258
- }
259
- if (target.every((x) => _isEmpty(x))) {
260
- return undefined;
261
- }
262
- else {
263
- target = target.filter((x) => !_isEmpty(x));
264
- return arrayWithoutDuplicates(target);
265
- }
266
- }
267
- export function arrayWithoutDuplicates(target) {
268
- if (!target || !Array.isArray(target)) {
269
- return target;
270
- }
271
- return _uniqWith(target, _isEqual);
272
- }
@@ -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,22 +0,0 @@
1
- import _isEqual from "lodash/isEqual.js";
2
- import _get from "lodash/get.js";
3
- import _set from "lodash/set.js";
4
- /**
5
- * util to push a value to an array at a given path in an object
6
- */
7
- export const pushSet = (obj, path, val, options) => {
8
- options = options || {};
9
- let arr = _get(obj, path);
10
- if (!arr || !Array.isArray(arr)) {
11
- arr = [val];
12
- _set(obj, path, arr);
13
- return arr;
14
- }
15
- else {
16
- if (options.unique && arr.some((x) => _isEqual(x, val))) {
17
- return arr;
18
- }
19
- arr.push(val);
20
- return arr;
21
- }
22
- };
@@ -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,28 +0,0 @@
1
- import { isMulti } from "./isMulti";
2
- import { isPaginated } from "./isPaginated";
3
- /**
4
- * util to set `context.result` to an empty array or object, depending on the hook type
5
- */
6
- export const setResultEmpty = (context) => {
7
- if (context.result) {
8
- return context;
9
- }
10
- const multi = isMulti(context);
11
- if (multi) {
12
- if (context.method === "find" && 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
- };
@@ -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;
@@ -1,29 +0,0 @@
1
- // Kudos to @DaddyWarbucks! This is a cheeky copy of his awesome library: 'feathers-fletching'.
2
- // Definitely check it out! https://daddywarbucks.github.io/feathers-fletching/overview.html
3
- import { GeneralError } from "@feathersjs/errors";
4
- /**
5
- * util to detect if a hook should be skipped
6
- */
7
- export const shouldSkip = (hookName, context, options) => {
8
- if (!context.params || !context.params.skipHooks || options?.notSkippable) {
9
- return false;
10
- }
11
- const { skipHooks } = context.params;
12
- if (!Array.isArray(skipHooks)) {
13
- throw new GeneralError("The `skipHooks` param must be an Array of Strings");
14
- }
15
- const { type } = context;
16
- if (skipHooks.includes(hookName)) {
17
- return true;
18
- }
19
- else if (skipHooks.includes("all")) {
20
- return true;
21
- }
22
- else if (skipHooks.includes(type)) {
23
- return true;
24
- }
25
- else if (skipHooks.includes(`${type}:${hookName}`)) {
26
- return true;
27
- }
28
- return false;
29
- };
@@ -1,5 +0,0 @@
1
- import type { Query } from "@feathersjs/feathers";
2
- /**
3
- * util to validate a query for operators
4
- */
5
- export declare const validateQueryProperty: (query: any, operators?: string[]) => Query;
@@ -1,23 +0,0 @@
1
- import { _ } from "@feathersjs/commons";
2
- import { BadRequest } from "@feathersjs/errors";
3
- const isPlainObject = (value) => _.isObject(value) && value.constructor === {}.constructor;
4
- /**
5
- * util to validate a query for operators
6
- */
7
- export const validateQueryProperty = (query, operators = []) => {
8
- if (!isPlainObject(query)) {
9
- return query;
10
- }
11
- for (const key of Object.keys(query)) {
12
- if (key.startsWith("$") && !operators.includes(key)) {
13
- throw new BadRequest(`Invalid query parameter ${key}`, query);
14
- }
15
- const value = query[key];
16
- if (isPlainObject(value)) {
17
- query[key] = validateQueryProperty(value, operators);
18
- }
19
- }
20
- return {
21
- ...query,
22
- };
23
- };
@@ -1,2 +0,0 @@
1
- import type { FilterQueryOptions } from "@feathersjs/adapter-commons";
2
- export declare const filterArray: <T extends string[]>(...keys: T) => { [key in T[number]]: (value: any, options: FilterQueryOptions) => any; };
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.filterArray = void 0;
4
- const validateQueryProperty_1 = require("../utils/validateQueryProperty");
5
- const filterQueryArray = (key) => (arr, { operators }) => {
6
- if (arr && !Array.isArray(arr)) {
7
- throw new Error(`Invalid query parameter '${key}'. It has to be an array`);
8
- }
9
- if (Array.isArray(arr)) {
10
- return arr.map((current) => (0, validateQueryProperty_1.validateQueryProperty)(current, operators));
11
- }
12
- return arr;
13
- };
14
- const filterArray = (...keys) => {
15
- const result = {};
16
- for (const key of keys) {
17
- result[key] = filterQueryArray(key);
18
- }
19
- return result;
20
- };
21
- exports.filterArray = filterArray;
@@ -1,2 +0,0 @@
1
- export * from "./array";
2
- export * from "./object";
@@ -1,18 +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("./array"), exports);
18
- __exportStar(require("./object"), exports);
@@ -1,2 +0,0 @@
1
- import type { FilterQueryOptions } from "@feathersjs/adapter-commons";
2
- export declare const filterObject: <T extends string[]>(...keys: T) => { [key in T[number]]: (value: any, options: FilterQueryOptions) => any; };
@@ -1,22 +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.filterObject = void 0;
7
- const validateQueryProperty_1 = require("../utils/validateQueryProperty");
8
- const isObject_1 = __importDefault(require("lodash/isObject"));
9
- const filterQueryObject = (key) => (obj, { operators }) => {
10
- if (obj && !(0, isObject_1.default)(obj)) {
11
- throw new Error(`Invalid query parameter: '${key}'. It has to be an object`);
12
- }
13
- return (0, validateQueryProperty_1.validateQueryProperty)(obj, operators);
14
- };
15
- const filterObject = (...keys) => {
16
- const result = {};
17
- for (const key of keys) {
18
- result[key] = filterQueryObject(key);
19
- }
20
- return result;
21
- };
22
- exports.filterObject = filterObject;
@@ -1,5 +0,0 @@
1
- import type { HookContext } from "@feathersjs/feathers";
2
- /**
3
- * hook to check if context is multi patch/remove and if the service allows it
4
- */
5
- export declare function checkMulti<H extends HookContext = HookContext>(): (context: H) => H;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkMulti = void 0;
4
- const errors_1 = require("@feathersjs/errors");
5
- const utils_1 = require("../utils");
6
- /**
7
- * hook to check if context is multi patch/remove and if the service allows it
8
- */
9
- function checkMulti() {
10
- return (context) => {
11
- if ((0, utils_1.shouldSkip)("checkMulti", context)) {
12
- return context;
13
- }
14
- const { service, method } = context;
15
- if (!service.allowsMulti || !(0, utils_1.isMulti)(context) || method === "find") {
16
- return context;
17
- }
18
- if (!service.allowsMulti(method)) {
19
- throw new errors_1.MethodNotAllowed(`Can not ${method} multiple entries`);
20
- }
21
- return context;
22
- };
23
- }
24
- exports.checkMulti = checkMulti;
@@ -1,12 +0,0 @@
1
- import type { HookContext } from "@feathersjs/feathers";
2
- import type { Promisable } from "../typesInternal";
3
- export interface CreateRelatedOptions<S = Record<string, any>> {
4
- service: keyof S;
5
- multi?: boolean;
6
- data: (item: any, context: HookContext) => Promisable<Record<string, any>>;
7
- createItemsInDataArraySeparately?: boolean;
8
- }
9
- /**
10
- * hook to create related items
11
- */
12
- export declare function createRelated<S = Record<string, any>, H extends HookContext = HookContext>({ service, multi, data, createItemsInDataArraySeparately, }: CreateRelatedOptions<S>): (context: H) => Promise<H>;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.createRelated = void 0;
13
- const feathers_hooks_common_1 = require("feathers-hooks-common");
14
- const utils_1 = require("../utils");
15
- /**
16
- * hook to create related items
17
- */
18
- function createRelated({ service, multi = true, data, createItemsInDataArraySeparately = true, }) {
19
- if (!service || !data) {
20
- throw "initialize hook 'createRelated' completely!";
21
- }
22
- return (context) => __awaiter(this, void 0, void 0, function* () {
23
- if ((0, utils_1.shouldSkip)("createRelated", context)) {
24
- return context;
25
- }
26
- (0, feathers_hooks_common_1.checkContext)(context, "after", undefined, "createRelated");
27
- const { items } = (0, utils_1.getItemsIsArray)(context);
28
- let dataToCreate = (yield Promise.all(items.map((item) => __awaiter(this, void 0, void 0, function* () { return data(item, context); })))).filter((x) => !!x);
29
- if (createItemsInDataArraySeparately) {
30
- dataToCreate = dataToCreate.flat();
31
- }
32
- if (!dataToCreate || dataToCreate.length <= 0) {
33
- return context;
34
- }
35
- if (multi) {
36
- yield context.app.service(service).create(dataToCreate);
37
- }
38
- else {
39
- yield Promise.all(dataToCreate.map((item) => __awaiter(this, void 0, void 0, function* () { return context.app.service(service).create(item); })));
40
- }
41
- return context;
42
- });
43
- }
44
- exports.createRelated = createRelated;
@@ -1,6 +0,0 @@
1
- export * from "./checkMulti";
2
- export * from "./createRelated";
3
- export * from "./onDelete";
4
- export * from "./removeRelated";
5
- export * from "./runPerItem";
6
- export * from "./setData";
@@ -1,22 +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("./checkMulti"), exports);
18
- __exportStar(require("./createRelated"), exports);
19
- __exportStar(require("./onDelete"), exports);
20
- __exportStar(require("./removeRelated"), exports);
21
- __exportStar(require("./runPerItem"), exports);
22
- __exportStar(require("./setData"), exports);
@@ -1,12 +0,0 @@
1
- import type { HookContext } from "@feathersjs/feathers";
2
- export type OnDeleteAction = "cascade" | "set null";
3
- export interface OnDeleteOptions {
4
- keyThere: string;
5
- keyHere: string;
6
- onDelete: OnDeleteAction;
7
- blocking?: boolean;
8
- }
9
- /**
10
- * hook to manipulate related items on delete
11
- */
12
- export declare function onDelete<S = Record<string, any>, H extends HookContext = HookContext>(service: keyof S, { keyThere, keyHere, onDelete, blocking, }: OnDeleteOptions): (context: H) => Promise<H>;