feathers-utils 2.0.0-2 → 2.0.0-4
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/esm/filters/array.d.ts +1 -1
- package/dist/esm/filters/array.js +2 -2
- package/dist/esm/filters/object.d.ts +2 -0
- package/dist/esm/filters/object.js +8 -0
- package/dist/esm/hooks/checkMulti.d.ts +2 -2
- package/dist/esm/hooks/createRelated.d.ts +8 -2
- package/dist/esm/hooks/createRelated.js +2 -3
- package/dist/esm/hooks/onDelete.d.ts +8 -2
- package/dist/esm/hooks/onDelete.js +8 -7
- package/dist/esm/hooks/removeRelated.d.ts +7 -2
- package/dist/esm/hooks/removeRelated.js +8 -7
- package/dist/esm/hooks/runPerItem.d.ts +5 -2
- package/dist/esm/hooks/runPerItem.js +1 -1
- package/dist/esm/hooks/setData.d.ts +7 -2
- package/dist/esm/hooks/setData.js +3 -2
- package/dist/esm/index.d.ts +19 -34
- package/dist/esm/index.js +21 -33
- package/dist/esm/mixins/debounce-mixin/DebouncedStore.d.ts +5 -2
- package/dist/esm/mixins/debounce-mixin/DebouncedStore.js +2 -2
- package/dist/esm/mixins/debounce-mixin/debounceMixin.d.ts +3 -0
- package/dist/esm/mixins/debounce-mixin/debounceMixin.js +19 -0
- package/dist/esm/mixins/debounce-mixin/index.d.ts +3 -8
- package/dist/esm/mixins/debounce-mixin/index.js +3 -20
- package/dist/esm/mixins/debounce-mixin/types.d.ts +13 -0
- package/dist/esm/mixins/debounce-mixin/types.js +1 -0
- package/dist/esm/types.d.ts +1 -77
- package/dist/esm/types.js +0 -1
- package/dist/esm/typesInternal.d.ts +3 -0
- package/dist/esm/typesInternal.js +3 -0
- package/dist/esm/utils/filterQuery.d.ts +6 -1
- package/dist/esm/utils/filterQuery.js +5 -3
- package/dist/esm/utils/getItemsIsArray.d.ts +5 -2
- package/dist/esm/utils/getItemsIsArray.js +7 -12
- package/dist/esm/utils/getPaginate.d.ts +2 -6
- package/dist/esm/utils/getPaginate.js +1 -1
- package/dist/esm/utils/isMulti.d.ts +1 -1
- package/dist/esm/utils/isPaginated.d.ts +1 -1
- package/dist/esm/utils/markHookForSkip.d.ts +3 -2
- package/dist/esm/utils/markHookForSkip.js +6 -5
- package/dist/esm/utils/mergeQuery/index.d.ts +3 -3
- package/dist/esm/utils/mergeQuery/index.js +3 -338
- package/dist/esm/utils/mergeQuery/mergeArrays.d.ts +2 -1
- package/dist/esm/utils/mergeQuery/mergeArrays.js +2 -2
- package/dist/esm/utils/mergeQuery/mergeQuery.d.ts +3 -0
- package/dist/esm/utils/mergeQuery/mergeQuery.js +68 -0
- package/dist/esm/utils/mergeQuery/types.d.ts +13 -0
- package/dist/esm/utils/mergeQuery/types.js +1 -0
- package/dist/esm/utils/mergeQuery/utils.d.ts +11 -0
- package/dist/esm/utils/mergeQuery/utils.js +272 -0
- package/dist/esm/utils/pushSet.d.ts +4 -1
- package/dist/esm/utils/pushSet.js +1 -1
- package/dist/esm/utils/setResultEmpty.d.ts +1 -1
- package/dist/esm/utils/setResultEmpty.js +1 -1
- package/dist/esm/utils/shouldSkip.d.ts +1 -1
- package/dist/esm/utils/validateQueryProperty.js +1 -1
- package/dist/filters/array.d.ts +1 -1
- package/dist/filters/array.js +2 -2
- package/dist/filters/object.d.ts +2 -0
- package/dist/filters/object.js +15 -0
- package/dist/hooks/checkMulti.d.ts +2 -2
- package/dist/hooks/createRelated.d.ts +8 -2
- package/dist/hooks/createRelated.js +2 -3
- package/dist/hooks/onDelete.d.ts +8 -2
- package/dist/hooks/onDelete.js +8 -7
- package/dist/hooks/removeRelated.d.ts +7 -2
- package/dist/hooks/removeRelated.js +8 -7
- package/dist/hooks/runPerItem.d.ts +5 -2
- package/dist/hooks/runPerItem.js +1 -1
- package/dist/hooks/setData.d.ts +7 -2
- package/dist/hooks/setData.js +3 -2
- package/dist/index.d.ts +19 -34
- package/dist/index.js +23 -49
- package/dist/mixins/debounce-mixin/DebouncedStore.d.ts +5 -2
- package/dist/mixins/debounce-mixin/DebouncedStore.js +2 -2
- package/dist/mixins/debounce-mixin/debounceMixin.d.ts +3 -0
- package/dist/mixins/debounce-mixin/debounceMixin.js +23 -0
- package/dist/mixins/debounce-mixin/index.d.ts +3 -8
- package/dist/mixins/debounce-mixin/index.js +17 -22
- package/dist/mixins/debounce-mixin/types.d.ts +13 -0
- package/dist/mixins/debounce-mixin/types.js +2 -0
- package/dist/types.d.ts +1 -77
- package/dist/types.js +0 -1
- package/dist/typesInternal.d.ts +3 -0
- package/dist/typesInternal.js +4 -0
- package/dist/utils/filterQuery.d.ts +6 -1
- package/dist/utils/filterQuery.js +4 -2
- package/dist/utils/getItemsIsArray.d.ts +5 -2
- package/dist/utils/getItemsIsArray.js +7 -12
- package/dist/utils/getPaginate.d.ts +2 -6
- package/dist/utils/isMulti.d.ts +1 -1
- package/dist/utils/isPaginated.d.ts +1 -1
- package/dist/utils/markHookForSkip.d.ts +3 -2
- package/dist/utils/markHookForSkip.js +6 -5
- package/dist/utils/mergeQuery/index.d.ts +3 -3
- package/dist/utils/mergeQuery/index.js +16 -342
- package/dist/utils/mergeQuery/mergeArrays.d.ts +2 -1
- package/dist/utils/mergeQuery/mergeArrays.js +2 -2
- package/dist/utils/mergeQuery/mergeQuery.d.ts +3 -0
- package/dist/utils/mergeQuery/mergeQuery.js +75 -0
- package/dist/utils/mergeQuery/types.d.ts +13 -0
- package/dist/utils/mergeQuery/types.js +2 -0
- package/dist/utils/mergeQuery/utils.d.ts +11 -0
- package/dist/utils/mergeQuery/utils.js +287 -0
- package/dist/utils/pushSet.d.ts +4 -1
- package/dist/utils/pushSet.js +1 -1
- package/dist/utils/setResultEmpty.d.ts +1 -1
- package/dist/utils/setResultEmpty.js +1 -1
- package/dist/utils/shouldSkip.d.ts +1 -1
- package/package.json +5 -2
- package/src/filters/array.ts +13 -9
- package/src/filters/object.ts +15 -0
- package/src/hooks/checkMulti.ts +8 -6
- package/src/hooks/createRelated.ts +21 -12
- package/src/hooks/onDelete.ts +28 -13
- package/src/hooks/removeRelated.ts +28 -16
- package/src/hooks/runPerItem.ts +19 -10
- package/src/hooks/setData.ts +24 -15
- package/src/index.ts +21 -38
- package/src/mixins/debounce-mixin/DebouncedStore.ts +29 -24
- package/src/mixins/debounce-mixin/debounceMixin.ts +33 -0
- package/src/mixins/debounce-mixin/index.ts +3 -39
- package/src/mixins/debounce-mixin/types.ts +16 -0
- package/src/types.ts +6 -117
- package/src/typesInternal.ts +6 -0
- package/src/utils/filterQuery.ts +22 -10
- package/src/utils/getItemsIsArray.ts +15 -16
- package/src/utils/getPaginate.ts +11 -14
- package/src/utils/isMulti.ts +3 -3
- package/src/utils/isPaginated.ts +6 -4
- package/src/utils/markHookForSkip.ts +18 -16
- package/src/utils/mergeQuery/index.ts +3 -379
- package/src/utils/mergeQuery/mergeArrays.ts +25 -18
- package/src/utils/mergeQuery/mergeQuery.ts +102 -0
- package/src/utils/mergeQuery/types.ts +25 -0
- package/src/utils/mergeQuery/utils.ts +342 -0
- package/src/utils/pushSet.ts +14 -7
- package/src/utils/setResultEmpty.ts +8 -6
- package/src/utils/shouldSkip.ts +4 -4
- package/src/utils/validateQueryProperty.ts +8 -4
|
@@ -0,0 +1,272 @@
|
|
|
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,2 +1,5 @@
|
|
|
1
|
-
import type { Path
|
|
1
|
+
import type { Path } from "../typesInternal";
|
|
2
|
+
export interface PushSetOptions {
|
|
3
|
+
unique?: boolean;
|
|
4
|
+
}
|
|
2
5
|
export declare const pushSet: (obj: Record<string, unknown>, path: string | Path, val: unknown, options?: PushSetOptions) => unknown[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
export declare const setResultEmpty: (context:
|
|
2
|
+
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,2 +1,2 @@
|
|
|
1
1
|
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
export declare const shouldSkip: (hookName: string, context:
|
|
2
|
+
export declare const shouldSkip: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(hookName: string, context: H) => boolean;
|
package/dist/filters/array.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { FilterQueryOptions } from "@feathersjs/adapter-commons";
|
|
2
|
-
export declare const filterArray: () => (arr: any, { operators }: FilterQueryOptions) => any;
|
|
2
|
+
export declare const filterArray: (key: string) => (arr: any, { operators }: FilterQueryOptions) => any;
|
package/dist/filters/array.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.filterArray = void 0;
|
|
4
4
|
const validateQueryProperty_1 = require("../utils/validateQueryProperty");
|
|
5
|
-
const filterArray = () => (arr, { operators }) => {
|
|
5
|
+
const filterArray = (key) => (arr, { operators }) => {
|
|
6
6
|
if (arr && !Array.isArray(arr)) {
|
|
7
|
-
throw new Error(
|
|
7
|
+
throw new Error(`Invalid query parameter '${key}'. It has to be an array`);
|
|
8
8
|
}
|
|
9
9
|
if (Array.isArray(arr)) {
|
|
10
10
|
return arr.map((current) => (0, validateQueryProperty_1.validateQueryProperty)(current, operators));
|
|
@@ -0,0 +1,15 @@
|
|
|
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 filterObject = (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
|
+
exports.filterObject = filterObject;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function checkMulti():
|
|
1
|
+
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
+
export declare function checkMulti<H extends HookContext = HookContext>(): (context: H) => H;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
import type {
|
|
3
|
-
export
|
|
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
|
+
export declare function createRelated<S = Record<string, any>, H extends HookContext = HookContext>({ service, multi, data, createItemsInDataArraySeparately, }: CreateRelatedOptions<S>): (context: H) => Promise<H>;
|
|
@@ -12,15 +12,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.createRelated = void 0;
|
|
13
13
|
const feathers_hooks_common_1 = require("feathers-hooks-common");
|
|
14
14
|
const getItemsIsArray_1 = require("../utils/getItemsIsArray");
|
|
15
|
-
function createRelated({ service, multi = true, data, createItemsInDataArraySeparately = true }) {
|
|
15
|
+
function createRelated({ service, multi = true, data, createItemsInDataArraySeparately = true, }) {
|
|
16
16
|
if (!service || !data) {
|
|
17
17
|
throw "initialize hook 'createRelated' completely!";
|
|
18
18
|
}
|
|
19
19
|
return (context) => __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
// @ts-expect-error wait for feathers-hooks-common to update
|
|
21
20
|
(0, feathers_hooks_common_1.checkContext)(context, "after", undefined, "createRelated");
|
|
22
21
|
const { items } = (0, getItemsIsArray_1.getItemsIsArray)(context);
|
|
23
|
-
let dataToCreate = (yield Promise.all(items.map((item) => __awaiter(this, void 0, void 0, function* () { return data(item, context); })))).filter(x => !!x);
|
|
22
|
+
let dataToCreate = (yield Promise.all(items.map((item) => __awaiter(this, void 0, void 0, function* () { return data(item, context); })))).filter((x) => !!x);
|
|
24
23
|
if (createItemsInDataArraySeparately) {
|
|
25
24
|
dataToCreate = dataToCreate.flat();
|
|
26
25
|
}
|
package/dist/hooks/onDelete.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
|
|
3
|
-
export
|
|
2
|
+
export declare type OnDeleteAction = "cascade" | "set null";
|
|
3
|
+
export interface OnDeleteOptions {
|
|
4
|
+
keyThere: string;
|
|
5
|
+
keyHere: string;
|
|
6
|
+
onDelete: OnDeleteAction;
|
|
7
|
+
blocking?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function onDelete<S = Record<string, any>, H extends HookContext = HookContext>(service: keyof S, { keyThere, keyHere, onDelete, blocking, }: OnDeleteOptions): (context: H) => Promise<H>;
|
package/dist/hooks/onDelete.js
CHANGED
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.onDelete = void 0;
|
|
13
13
|
const feathers_hooks_common_1 = require("feathers-hooks-common");
|
|
14
14
|
const getItemsIsArray_1 = require("../utils/getItemsIsArray");
|
|
15
|
-
function onDelete(service, { keyThere, keyHere = "id", onDelete = "cascade", blocking = true }) {
|
|
15
|
+
function onDelete(service, { keyThere, keyHere = "id", onDelete = "cascade", blocking = true, }) {
|
|
16
16
|
if (!service || !keyThere) {
|
|
17
17
|
throw "initialize hook 'removeRelated' completely!";
|
|
18
18
|
}
|
|
@@ -20,10 +20,9 @@ function onDelete(service, { keyThere, keyHere = "id", onDelete = "cascade", blo
|
|
|
20
20
|
throw "onDelete must be 'cascade' or 'set null'";
|
|
21
21
|
}
|
|
22
22
|
return (context) => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
// @ts-expect-error wait for feathers-hooks-common to update
|
|
24
23
|
(0, feathers_hooks_common_1.checkContext)(context, "after", "remove", "onDelete");
|
|
25
24
|
const { items } = (0, getItemsIsArray_1.getItemsIsArray)(context);
|
|
26
|
-
let ids = items.map(x => x[keyHere]).filter(x => !!x);
|
|
25
|
+
let ids = items.map((x) => x[keyHere]).filter((x) => !!x);
|
|
27
26
|
ids = [...new Set(ids)];
|
|
28
27
|
if (!ids || ids.length <= 0) {
|
|
29
28
|
return context;
|
|
@@ -31,10 +30,10 @@ function onDelete(service, { keyThere, keyHere = "id", onDelete = "cascade", blo
|
|
|
31
30
|
const params = {
|
|
32
31
|
query: {
|
|
33
32
|
[keyThere]: {
|
|
34
|
-
$in: ids
|
|
35
|
-
}
|
|
33
|
+
$in: ids,
|
|
34
|
+
},
|
|
36
35
|
},
|
|
37
|
-
paginate: false
|
|
36
|
+
paginate: false,
|
|
38
37
|
};
|
|
39
38
|
let promise;
|
|
40
39
|
if (onDelete === "cascade") {
|
|
@@ -42,7 +41,9 @@ function onDelete(service, { keyThere, keyHere = "id", onDelete = "cascade", blo
|
|
|
42
41
|
}
|
|
43
42
|
else if (onDelete === "set null") {
|
|
44
43
|
const data = { [keyThere]: null };
|
|
45
|
-
promise = context.app
|
|
44
|
+
promise = context.app
|
|
45
|
+
.service(service)
|
|
46
|
+
.patch(null, data, params);
|
|
46
47
|
}
|
|
47
48
|
if (blocking) {
|
|
48
49
|
yield promise;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export interface RemoveRelatedOptions<S = Record<string, any>> {
|
|
3
|
+
service: keyof S;
|
|
4
|
+
keyThere: string;
|
|
5
|
+
keyHere: string;
|
|
6
|
+
blocking?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function removeRelated<S = Record<string, any>, H extends HookContext = HookContext>({ service, keyThere, keyHere, blocking, }: RemoveRelatedOptions<S>): (context: H) => Promise<H>;
|
|
@@ -12,27 +12,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.removeRelated = void 0;
|
|
13
13
|
const feathers_hooks_common_1 = require("feathers-hooks-common");
|
|
14
14
|
const getItemsIsArray_1 = require("../utils/getItemsIsArray");
|
|
15
|
-
function removeRelated({ service, keyThere, keyHere = "id", blocking = true }) {
|
|
15
|
+
function removeRelated({ service, keyThere, keyHere = "id", blocking = true, }) {
|
|
16
16
|
if (!service || !keyThere) {
|
|
17
17
|
throw "initialize hook 'removeRelated' completely!";
|
|
18
18
|
}
|
|
19
19
|
return (context) => __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
// @ts-expect-error wait for feathers-hooks-common to update
|
|
21
20
|
(0, feathers_hooks_common_1.checkContext)(context, "after", "remove", "removeRelated");
|
|
22
21
|
const { items } = (0, getItemsIsArray_1.getItemsIsArray)(context);
|
|
23
|
-
let ids = items.map(x => x[keyHere]).filter(x => !!x);
|
|
22
|
+
let ids = items.map((x) => x[keyHere]).filter((x) => !!x);
|
|
24
23
|
ids = [...new Set(ids)];
|
|
25
24
|
if (!ids || ids.length <= 0) {
|
|
26
25
|
return context;
|
|
27
26
|
}
|
|
28
27
|
// feathers does not accept `paginate: false` for remove, but some adapters need it to work properly
|
|
29
|
-
const promise = context.app
|
|
28
|
+
const promise = context.app
|
|
29
|
+
.service(service)
|
|
30
|
+
.remove(null, {
|
|
30
31
|
query: {
|
|
31
32
|
[keyThere]: {
|
|
32
|
-
$in: ids
|
|
33
|
-
}
|
|
33
|
+
$in: ids,
|
|
34
|
+
},
|
|
34
35
|
},
|
|
35
|
-
paginate: false
|
|
36
|
+
paginate: false,
|
|
36
37
|
});
|
|
37
38
|
if (blocking) {
|
|
38
39
|
yield promise;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import type { HookRunPerItemOptions, ReturnAsyncHook, Promisable } from "../types";
|
|
2
1
|
import type { HookContext } from "@feathersjs/feathers";
|
|
3
|
-
|
|
2
|
+
import type { Promisable } from "../typesInternal";
|
|
3
|
+
export interface HookRunPerItemOptions {
|
|
4
|
+
wait?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const runPerItem: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(actionPerItem: (item: any, context: H) => Promisable<any>, _options?: HookRunPerItemOptions) => (context: H) => Promise<H>;
|
package/dist/hooks/runPerItem.js
CHANGED
package/dist/hooks/setData.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import type { HookContext } from "@feathersjs/feathers";
|
|
1
2
|
import type { PropertyPath } from "lodash";
|
|
2
|
-
import type {
|
|
3
|
-
export
|
|
3
|
+
import type { PredicateWithContext } from "../types";
|
|
4
|
+
export interface HookSetDataOptions {
|
|
5
|
+
allowUndefined?: boolean;
|
|
6
|
+
overwrite?: boolean | PredicateWithContext;
|
|
7
|
+
}
|
|
8
|
+
export declare function setData<H extends HookContext = HookContext>(from: PropertyPath, to: PropertyPath, _options?: HookSetDataOptions): (context: H) => H;
|
package/dist/hooks/setData.js
CHANGED
|
@@ -11,7 +11,7 @@ const errors_1 = require("@feathersjs/errors");
|
|
|
11
11
|
const getItemsIsArray_1 = require("../utils/getItemsIsArray");
|
|
12
12
|
const defaultOptions = {
|
|
13
13
|
allowUndefined: false,
|
|
14
|
-
overwrite: true
|
|
14
|
+
overwrite: true,
|
|
15
15
|
};
|
|
16
16
|
function setData(from, to, _options) {
|
|
17
17
|
const options = Object.assign({}, defaultOptions, _options);
|
|
@@ -22,7 +22,8 @@ function setData(from, to, _options) {
|
|
|
22
22
|
if (!((_a = context.params) === null || _a === void 0 ? void 0 : _a.provider) || options.allowUndefined === true) {
|
|
23
23
|
return context;
|
|
24
24
|
}
|
|
25
|
-
if (!options.overwrite &&
|
|
25
|
+
if (!options.overwrite &&
|
|
26
|
+
items.every((item) => (0, has_js_1.default)(item, to))) {
|
|
26
27
|
return context;
|
|
27
28
|
}
|
|
28
29
|
throw new errors_1.Forbidden(`Expected field ${from.toString()} not available`);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,36 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export { debounceMixin };
|
|
20
|
-
export { DebouncedService };
|
|
21
|
-
export { DebouncedStore };
|
|
22
|
-
export { getPaginate } from "./utils/getPaginate";
|
|
23
|
-
export { isMulti } from "./utils/isMulti";
|
|
24
|
-
export { isPaginated } from "./utils/isPaginated";
|
|
25
|
-
export { mergeQuery } from "./utils/mergeQuery/index";
|
|
26
|
-
export { mergeArrays } from "./utils/mergeQuery/mergeArrays";
|
|
27
|
-
export { pushSet } from "./utils/pushSet";
|
|
28
|
-
export { setResultEmpty } from "./utils/setResultEmpty";
|
|
29
|
-
export { markHookForSkip } from "./utils/markHookForSkip";
|
|
30
|
-
export { filterQuery } from "./utils/filterQuery";
|
|
31
|
-
export { getItemsIsArray } from "./utils/getItemsIsArray";
|
|
32
|
-
export { onDelete } from "./hooks/onDelete";
|
|
33
|
-
export { shouldSkip } from "./utils/shouldSkip";
|
|
34
|
-
export { validateQueryProperty } from "./utils/validateQueryProperty";
|
|
1
|
+
export * from "./hooks/checkMulti";
|
|
2
|
+
export * from "./hooks/createRelated";
|
|
3
|
+
export * from "./hooks/onDelete";
|
|
4
|
+
export * from "./hooks/removeRelated";
|
|
5
|
+
export * from "./hooks/runPerItem";
|
|
6
|
+
export * from "./hooks/setData";
|
|
7
|
+
export * from "./mixins/debounce-mixin";
|
|
8
|
+
export * from "./utils/isMulti";
|
|
9
|
+
export * from "./utils/getPaginate";
|
|
10
|
+
export * from "./utils/isPaginated";
|
|
11
|
+
export * from "./utils/mergeQuery";
|
|
12
|
+
export * from "./utils/pushSet";
|
|
13
|
+
export * from "./utils/setResultEmpty";
|
|
14
|
+
export * from "./utils/filterQuery";
|
|
15
|
+
export * from "./utils/getItemsIsArray";
|
|
16
|
+
export * from "./utils/shouldSkip";
|
|
17
|
+
export * from "./utils/markHookForSkip";
|
|
18
|
+
export * from "./utils/validateQueryProperty";
|
|
35
19
|
export { filterArray } from "./filters/array";
|
|
20
|
+
export { filterObject } from "./filters/object";
|
|
36
21
|
export * from "./types";
|