feathers-utils 5.1.0 → 6.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.
- package/README.md +3 -2
- package/dist/index.cjs +117 -32
- package/dist/index.d.cts +13 -8
- package/dist/index.d.mts +13 -8
- package/dist/index.d.ts +13 -8
- package/dist/index.mjs +115 -29
- package/package.json +18 -20
- package/src/filters/object.ts +2 -2
- package/src/hooks/checkMulti.ts +151 -0
- package/src/hooks/setData.ts +509 -0
- package/src/mixins/debounce-mixin/DebouncedStore.ts +1 -9
- package/src/mixins/debounce-mixin/debounceMixin.ts +2 -1
- package/src/mixins/debounce-mixin/utils.ts +10 -0
- package/src/types.ts +1 -0
- package/src/typesInternal.ts +2 -0
- package/src/utils/_utils.internal.ts +16 -0
- package/src/utils/deflattenQuery.ts +109 -0
- package/src/utils/filterQuery.ts +112 -40
- package/src/utils/flattenQuery.ts +198 -0
- package/src/utils/getItemsIsArray.ts +279 -0
- package/src/utils/getPaginate.ts +74 -1
- package/src/utils/index.ts +2 -0
- package/src/utils/isMulti.ts +51 -0
- package/src/utils/isPaginated.ts +72 -0
- package/src/utils/markHookForSkip.ts +411 -0
- package/src/utils/mergeQuery/mergeArrays.ts +68 -0
- package/src/utils/mergeQuery/mergeQuery.ts +464 -3
- package/src/utils/mergeQuery/types.ts +0 -1
- package/src/utils/mergeQuery/utils.ts +93 -5
- package/src/utils/optimizeBatchPatch.ts +54 -22
- package/src/utils/pushSet.ts +67 -1
- package/src/utils/setQueryKeySafely.ts +169 -4
- package/src/utils/setResultEmpty.ts +260 -0
- package/src/utils/shouldSkip.ts +121 -0
- package/src/utils/validateQueryProperty.ts +3 -6
- package/src/utils/internal.utils.ts +0 -9
package/src/utils/shouldSkip.ts
CHANGED
|
@@ -38,3 +38,124 @@ export const shouldSkip = <H extends HookContext = HookContext>(
|
|
|
38
38
|
|
|
39
39
|
return false;
|
|
40
40
|
};
|
|
41
|
+
|
|
42
|
+
if (import.meta.vitest) {
|
|
43
|
+
const { it, assert } = import.meta.vitest;
|
|
44
|
+
|
|
45
|
+
it("returns false if skipHooks not defined", function () {
|
|
46
|
+
["before", "after"].forEach((type) => {
|
|
47
|
+
["find", "get", "create", "update", "patch", "remove"].forEach(
|
|
48
|
+
(method) => {
|
|
49
|
+
const context = { type, method } as HookContext;
|
|
50
|
+
assert.strictEqual(
|
|
51
|
+
shouldSkip("all", context),
|
|
52
|
+
false,
|
|
53
|
+
`'${type}:${method}': returns false`,
|
|
54
|
+
);
|
|
55
|
+
},
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("returns true for skipHooks: ['all']", function () {
|
|
61
|
+
["before", "after", "error"].forEach((type) => {
|
|
62
|
+
["find", "get", "create", "update", "patch", "remove"].forEach(
|
|
63
|
+
(method) => {
|
|
64
|
+
const context = {
|
|
65
|
+
type,
|
|
66
|
+
method,
|
|
67
|
+
params: { skipHooks: ["all"] },
|
|
68
|
+
} as HookContext;
|
|
69
|
+
assert.strictEqual(
|
|
70
|
+
shouldSkip("test", context),
|
|
71
|
+
true,
|
|
72
|
+
`'${type}:${method}': returns true`,
|
|
73
|
+
);
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("returns true for skipHooks: [`type`]", function () {
|
|
80
|
+
["before", "after", "error"].forEach((type) => {
|
|
81
|
+
["find", "get", "create", "update", "patch", "remove"].forEach(
|
|
82
|
+
(method) => {
|
|
83
|
+
const context = {
|
|
84
|
+
type,
|
|
85
|
+
method,
|
|
86
|
+
params: { skipHooks: [type] },
|
|
87
|
+
} as HookContext;
|
|
88
|
+
assert.strictEqual(
|
|
89
|
+
shouldSkip("test", context),
|
|
90
|
+
true,
|
|
91
|
+
`'${type}:${method}': returns true`,
|
|
92
|
+
);
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("returns true for skipHooks: ['`type`:test']", function () {
|
|
99
|
+
["before", "after", "error"].forEach((type) => {
|
|
100
|
+
["find", "get", "create", "update", "patch", "remove"].forEach(
|
|
101
|
+
(method) => {
|
|
102
|
+
const context = {
|
|
103
|
+
type,
|
|
104
|
+
method,
|
|
105
|
+
params: { skipHooks: [`${type}:test`] },
|
|
106
|
+
} as HookContext;
|
|
107
|
+
assert.strictEqual(
|
|
108
|
+
shouldSkip("test", context),
|
|
109
|
+
true,
|
|
110
|
+
`'${type}:${method}': returns true`,
|
|
111
|
+
);
|
|
112
|
+
},
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("returns true for skipHooks: ['test']", function () {
|
|
118
|
+
["before", "after", "error"].forEach((type) => {
|
|
119
|
+
["find", "get", "create", "update", "patch", "remove"].forEach(
|
|
120
|
+
(method) => {
|
|
121
|
+
const context = {
|
|
122
|
+
type,
|
|
123
|
+
method,
|
|
124
|
+
params: { skipHooks: ["test"] },
|
|
125
|
+
} as HookContext;
|
|
126
|
+
assert.strictEqual(
|
|
127
|
+
shouldSkip("test", context),
|
|
128
|
+
true,
|
|
129
|
+
`'${type}:${method}': returns true`,
|
|
130
|
+
);
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("returns false for skipHooks other than test", function () {
|
|
137
|
+
const types = ["before", "after", "error"];
|
|
138
|
+
types.forEach((type) => {
|
|
139
|
+
["find", "get", "create", "update", "patch", "remove"].forEach(
|
|
140
|
+
(method) => {
|
|
141
|
+
const remainingTypes = types.filter((x) => x !== type);
|
|
142
|
+
const skipHooks = [
|
|
143
|
+
"test2",
|
|
144
|
+
`${type}:test2`,
|
|
145
|
+
...remainingTypes.map((t) => `${t}:test1`),
|
|
146
|
+
];
|
|
147
|
+
const context = {
|
|
148
|
+
type,
|
|
149
|
+
method,
|
|
150
|
+
params: { skipHooks },
|
|
151
|
+
} as HookContext;
|
|
152
|
+
assert.strictEqual(
|
|
153
|
+
shouldSkip("test1", context),
|
|
154
|
+
false,
|
|
155
|
+
`'${type}:${method}': returns true`,
|
|
156
|
+
);
|
|
157
|
+
},
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { _ } from "@feathersjs/commons";
|
|
2
1
|
import { BadRequest } from "@feathersjs/errors";
|
|
3
2
|
import type { Query } from "@feathersjs/feathers";
|
|
4
|
-
|
|
5
|
-
const isPlainObject = (value: any) =>
|
|
6
|
-
_.isObject(value) && value.constructor === {}.constructor;
|
|
3
|
+
import { isObject } from "./_utils.internal";
|
|
7
4
|
|
|
8
5
|
/**
|
|
9
6
|
* util to validate a query for operators
|
|
@@ -12,7 +9,7 @@ export const validateQueryProperty = (
|
|
|
12
9
|
query: any,
|
|
13
10
|
operators: string[] = [],
|
|
14
11
|
): Query => {
|
|
15
|
-
if (!
|
|
12
|
+
if (!isObject(query)) {
|
|
16
13
|
return query;
|
|
17
14
|
}
|
|
18
15
|
|
|
@@ -23,7 +20,7 @@ export const validateQueryProperty = (
|
|
|
23
20
|
|
|
24
21
|
const value = query[key];
|
|
25
22
|
|
|
26
|
-
if (
|
|
23
|
+
if (isObject(value)) {
|
|
27
24
|
query[key] = validateQueryProperty(value, operators);
|
|
28
25
|
}
|
|
29
26
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export const hasOwnProperty = (
|
|
2
|
-
obj: Record<string, unknown>,
|
|
3
|
-
...keys: string[]
|
|
4
|
-
): boolean => {
|
|
5
|
-
return keys.some((x) => Object.prototype.hasOwnProperty.call(obj, x));
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const isPlainObject = (value) =>
|
|
9
|
-
value && [undefined, Object].includes(value.constructor);
|