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
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Id, Params } from "@feathersjs/feathers";
|
|
2
2
|
import { deepEqual } from "fast-equals";
|
|
3
|
+
import type { KeyOf } from "../typesInternal";
|
|
3
4
|
|
|
4
|
-
export type OptimizeBatchPatchOptions = {
|
|
5
|
-
id
|
|
5
|
+
export type OptimizeBatchPatchOptions<IdKey extends string> = {
|
|
6
|
+
/** the key of the id property */
|
|
7
|
+
id?: IdKey;
|
|
6
8
|
};
|
|
7
9
|
|
|
8
10
|
export type OptimizeBatchPatchResultItem<
|
|
@@ -11,18 +13,26 @@ export type OptimizeBatchPatchResultItem<
|
|
|
11
13
|
> = [Id, T, P | undefined];
|
|
12
14
|
|
|
13
15
|
export function optimizeBatchPatch<
|
|
14
|
-
T extends Record<string,
|
|
16
|
+
T extends Record<string, any>,
|
|
17
|
+
IdKey extends KeyOf<T>,
|
|
15
18
|
P extends Params,
|
|
19
|
+
R extends Omit<T, IdKey> = Omit<T, IdKey>,
|
|
16
20
|
>(
|
|
17
|
-
items:
|
|
18
|
-
options?: OptimizeBatchPatchOptions
|
|
19
|
-
): OptimizeBatchPatchResultItem<
|
|
20
|
-
const map: { ids: Id[]; data:
|
|
21
|
+
items: T[],
|
|
22
|
+
options?: OptimizeBatchPatchOptions<IdKey>,
|
|
23
|
+
): OptimizeBatchPatchResultItem<R, P>[] {
|
|
24
|
+
const map: { ids: Id[]; data: R }[] = [];
|
|
21
25
|
|
|
22
|
-
const
|
|
26
|
+
const idKey = options?.id ?? "id";
|
|
23
27
|
|
|
24
|
-
for (const
|
|
25
|
-
const
|
|
28
|
+
for (const _data of items) {
|
|
29
|
+
const data = _data as unknown as R;
|
|
30
|
+
const id = _data[idKey];
|
|
31
|
+
delete data[idKey as any];
|
|
32
|
+
|
|
33
|
+
const index = map.findIndex((item) => {
|
|
34
|
+
return deepEqual(item.data, data);
|
|
35
|
+
});
|
|
26
36
|
|
|
27
37
|
if (index === -1) {
|
|
28
38
|
map.push({ ids: [id], data });
|
|
@@ -33,34 +43,56 @@ export function optimizeBatchPatch<
|
|
|
33
43
|
|
|
34
44
|
return map.map(({ ids, data }) => {
|
|
35
45
|
return ids.length === 1
|
|
36
|
-
? ([ids[0], data, undefined] as OptimizeBatchPatchResultItem<
|
|
46
|
+
? ([ids[0], data, undefined] as OptimizeBatchPatchResultItem<R, P>)
|
|
37
47
|
: ([
|
|
38
48
|
null,
|
|
39
49
|
data,
|
|
40
50
|
{
|
|
41
51
|
query: {
|
|
42
|
-
[
|
|
52
|
+
[idKey]: { $in: ids },
|
|
43
53
|
},
|
|
44
54
|
},
|
|
45
|
-
] as OptimizeBatchPatchResultItem<
|
|
55
|
+
] as OptimizeBatchPatchResultItem<R, P>);
|
|
46
56
|
});
|
|
47
57
|
}
|
|
48
58
|
|
|
49
59
|
if (import.meta.vitest) {
|
|
50
60
|
const { it, expect } = import.meta.vitest;
|
|
51
61
|
it("optimizeBatchPatch", () => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
expect(
|
|
63
|
+
optimizeBatchPatch(
|
|
64
|
+
[
|
|
65
|
+
{ id: "1", name: "John" },
|
|
66
|
+
{ id: "2", name: "Jane" },
|
|
67
|
+
{ id: "3", name: "John" },
|
|
68
|
+
{ id: "4", name: "Jane" },
|
|
69
|
+
{ id: 5, name: "Jack" },
|
|
70
|
+
],
|
|
71
|
+
{ id: "id" },
|
|
72
|
+
),
|
|
73
|
+
).toEqual([
|
|
61
74
|
[null, { name: "John" }, { query: { id: { $in: ["1", "3"] } } }],
|
|
62
75
|
[null, { name: "Jane" }, { query: { id: { $in: ["2", "4"] } } }],
|
|
63
76
|
[5, { name: "Jack" }, undefined],
|
|
64
77
|
]);
|
|
65
78
|
});
|
|
79
|
+
|
|
80
|
+
it("optimizeBatchPatch with _id", () => {
|
|
81
|
+
expect(
|
|
82
|
+
optimizeBatchPatch(
|
|
83
|
+
[
|
|
84
|
+
{ _id: "1", name: "John" },
|
|
85
|
+
{ _id: "2", name: "Jane" },
|
|
86
|
+
{ _id: "3", name: "John" },
|
|
87
|
+
{ _id: "4", name: "Jane" },
|
|
88
|
+
{ _id: 5, name: "Jack" },
|
|
89
|
+
],
|
|
90
|
+
{ id: "_id" },
|
|
91
|
+
),
|
|
92
|
+
).toEqual([
|
|
93
|
+
[null, { name: "John" }, { query: { _id: { $in: ["1", "3"] } } }],
|
|
94
|
+
[null, { name: "Jane" }, { query: { _id: { $in: ["2", "4"] } } }],
|
|
95
|
+
[5, { name: "Jack" }, undefined],
|
|
96
|
+
]);
|
|
97
|
+
});
|
|
66
98
|
}
|
package/src/utils/pushSet.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import _isEqual from "
|
|
1
|
+
import { deepEqual as _isEqual } from "fast-equals";
|
|
2
2
|
import _get from "lodash/get.js";
|
|
3
3
|
import _set from "lodash/set.js";
|
|
4
4
|
import type { Path } from "../typesInternal";
|
|
@@ -30,3 +30,69 @@ export const pushSet = (
|
|
|
30
30
|
return arr;
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
|
+
|
|
34
|
+
if (import.meta.vitest) {
|
|
35
|
+
const { describe, it, assert } = import.meta.vitest;
|
|
36
|
+
|
|
37
|
+
it("pushes to existing array", function () {
|
|
38
|
+
const obj = {
|
|
39
|
+
arr: [1],
|
|
40
|
+
};
|
|
41
|
+
pushSet(obj, ["arr"], 2);
|
|
42
|
+
assert.deepStrictEqual(obj, { arr: [1, 2] });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("sets array for not existing", function () {
|
|
46
|
+
const obj = {};
|
|
47
|
+
pushSet(obj, ["arr"], 2);
|
|
48
|
+
assert.deepStrictEqual(obj, { arr: [2] });
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("adds existing element", function () {
|
|
52
|
+
const obj = {
|
|
53
|
+
arr: [1],
|
|
54
|
+
};
|
|
55
|
+
pushSet(obj, ["arr"], 1);
|
|
56
|
+
assert.deepStrictEqual(obj, { arr: [1, 1] });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("skips existing element", function () {
|
|
60
|
+
const obj = {
|
|
61
|
+
arr: [1],
|
|
62
|
+
};
|
|
63
|
+
pushSet(obj, ["arr"], 1, { unique: true });
|
|
64
|
+
assert.deepStrictEqual(obj, { arr: [1] });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe("deep dot notation", function () {
|
|
68
|
+
it("deep: pushes to existing array", function () {
|
|
69
|
+
const obj = {
|
|
70
|
+
nested: { deep: [{ arr: [1] }] },
|
|
71
|
+
};
|
|
72
|
+
pushSet(obj, ["nested", "deep", 0, "arr"], 2);
|
|
73
|
+
assert.deepStrictEqual(obj, { nested: { deep: [{ arr: [1, 2] }] } });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("deep: sets array for not existing", function () {
|
|
77
|
+
const obj = {};
|
|
78
|
+
pushSet(obj, ["nested", "deep", 0, "arr"], 2);
|
|
79
|
+
assert.deepStrictEqual(obj, { nested: { deep: [{ arr: [2] }] } });
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("deep: adds existing element", function () {
|
|
83
|
+
const obj = {
|
|
84
|
+
nested: { deep: [{ arr: [1] }] },
|
|
85
|
+
};
|
|
86
|
+
pushSet(obj, ["nested", "deep", 0, "arr"], 1);
|
|
87
|
+
assert.deepStrictEqual(obj, { nested: { deep: [{ arr: [1, 1] }] } });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("deep: skips existing element", function () {
|
|
91
|
+
const obj = {
|
|
92
|
+
nested: { deep: [{ arr: [1] }] },
|
|
93
|
+
};
|
|
94
|
+
pushSet(obj, ["nested", "deep", 0, "arr"], 1, { unique: true });
|
|
95
|
+
assert.deepStrictEqual(obj, { nested: { deep: [{ arr: [1] }] } });
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { isPlainObject } from "./internal
|
|
1
|
+
import { isPlainObject } from "./_utils.internal";
|
|
2
2
|
import type { Params } from "@feathersjs/feathers";
|
|
3
3
|
|
|
4
4
|
export type SetQueryKeySafelyOptions = {
|
|
5
5
|
mutate?: boolean;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
export const setQueryKeySafely =
|
|
9
|
-
params:
|
|
8
|
+
export const setQueryKeySafely = (
|
|
9
|
+
params: Params,
|
|
10
10
|
key: string,
|
|
11
11
|
value: any,
|
|
12
12
|
operator = "$eq",
|
|
13
13
|
options?: SetQueryKeySafelyOptions,
|
|
14
|
-
):
|
|
14
|
+
): Params => {
|
|
15
15
|
const { mutate = false } = options || {};
|
|
16
16
|
|
|
17
17
|
// TODO: mutate params
|
|
@@ -54,3 +54,168 @@ export const setQueryKeySafely = <P extends Params = Params>(
|
|
|
54
54
|
|
|
55
55
|
return params;
|
|
56
56
|
};
|
|
57
|
+
|
|
58
|
+
if (import.meta.vitest) {
|
|
59
|
+
const { it, assert } = import.meta.vitest;
|
|
60
|
+
|
|
61
|
+
it("does not mutate by default", function () {
|
|
62
|
+
const params: Params = {
|
|
63
|
+
query: {
|
|
64
|
+
test: true,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const result = setQueryKeySafely(params, "test", false);
|
|
69
|
+
assert.deepStrictEqual(params, {
|
|
70
|
+
query: {
|
|
71
|
+
test: true,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
assert.deepStrictEqual(result, {
|
|
76
|
+
query: {
|
|
77
|
+
test: true,
|
|
78
|
+
$and: [{ test: false }],
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("does not mutate explicitely", function () {
|
|
84
|
+
const params: Params = {
|
|
85
|
+
query: {
|
|
86
|
+
test: true,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const result = setQueryKeySafely(params, "test", false, "$eq", {
|
|
91
|
+
mutate: false,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
assert.deepStrictEqual(params, {
|
|
95
|
+
query: {
|
|
96
|
+
test: true,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
assert.deepStrictEqual(result, {
|
|
101
|
+
query: {
|
|
102
|
+
test: true,
|
|
103
|
+
$and: [{ test: false }],
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("does mutate explicitely", function () {
|
|
109
|
+
const params: Params = {
|
|
110
|
+
query: {
|
|
111
|
+
test: true,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const result = setQueryKeySafely(params, "test", false, "$eq", {
|
|
116
|
+
mutate: true,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
assert.equal(params, result);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("adds a $eq filter for non existent key", function () {
|
|
123
|
+
const params: Params = {
|
|
124
|
+
query: {},
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const result = setQueryKeySafely(params, "test", true);
|
|
128
|
+
assert.deepStrictEqual(result, {
|
|
129
|
+
query: {
|
|
130
|
+
test: true,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("adds a $ne filter for non existent key", function () {
|
|
136
|
+
const params = {
|
|
137
|
+
query: {},
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const result = setQueryKeySafely(params, "test", true, "$ne");
|
|
141
|
+
assert.deepStrictEqual(result, {
|
|
142
|
+
query: {
|
|
143
|
+
test: {
|
|
144
|
+
$ne: true,
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("adds a $eq filter for existing key", function () {
|
|
151
|
+
const params: Params = {
|
|
152
|
+
query: {
|
|
153
|
+
test: true,
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const result = setQueryKeySafely(params, "test", false);
|
|
158
|
+
assert.deepStrictEqual(result, {
|
|
159
|
+
query: {
|
|
160
|
+
test: true,
|
|
161
|
+
$and: [{ test: false }],
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("adds a $in filter for existing key with value", function () {
|
|
167
|
+
const params: Params = {
|
|
168
|
+
query: {
|
|
169
|
+
test: true,
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const result = setQueryKeySafely(params, "test", [true], "$in");
|
|
174
|
+
assert.deepStrictEqual(result, {
|
|
175
|
+
query: {
|
|
176
|
+
test: true,
|
|
177
|
+
$and: [{ test: { $in: [true] } }],
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("adds a $in filter for existing key with object", function () {
|
|
183
|
+
const params: Params = {
|
|
184
|
+
query: {
|
|
185
|
+
test: {
|
|
186
|
+
$eq: true,
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const result = setQueryKeySafely(params, "test", [true], "$in");
|
|
192
|
+
assert.deepStrictEqual(result, {
|
|
193
|
+
query: {
|
|
194
|
+
test: {
|
|
195
|
+
$eq: true,
|
|
196
|
+
$in: [true],
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("adds a $in filter for existing $in", function () {
|
|
203
|
+
const params: Params = {
|
|
204
|
+
query: {
|
|
205
|
+
test: {
|
|
206
|
+
$in: [true],
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const result = setQueryKeySafely(params, "test", [false], "$in");
|
|
212
|
+
assert.deepStrictEqual(result, {
|
|
213
|
+
query: {
|
|
214
|
+
test: {
|
|
215
|
+
$in: [true],
|
|
216
|
+
},
|
|
217
|
+
$and: [{ test: { $in: [false] } }],
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
}
|
|
@@ -31,3 +31,263 @@ export const setResultEmpty = <H extends HookContext = HookContext>(
|
|
|
31
31
|
|
|
32
32
|
return context;
|
|
33
33
|
};
|
|
34
|
+
|
|
35
|
+
if (import.meta.vitest) {
|
|
36
|
+
const { it, assert } = import.meta.vitest;
|
|
37
|
+
|
|
38
|
+
const paginatedService = {
|
|
39
|
+
options: {
|
|
40
|
+
paginate: {
|
|
41
|
+
default: 10,
|
|
42
|
+
max: 50,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const nonPaginatedService = {
|
|
48
|
+
options: {
|
|
49
|
+
paginate: false,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const paramsEmpty = {};
|
|
54
|
+
const paramsPaginateFalse = { paginate: false };
|
|
55
|
+
const paramsPaginate = { paginate: { default: 10, max: 50 } };
|
|
56
|
+
const paramsAdapterPaginate = {
|
|
57
|
+
adapter: { paginate: { default: 10, max: 50 } },
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
it("does not overwrite result", function () {
|
|
61
|
+
["find", "get", "create", "update", "patch", "remove"].forEach((method) => {
|
|
62
|
+
["before", "after"].forEach((type) => {
|
|
63
|
+
[paginatedService, nonPaginatedService].forEach((service) => {
|
|
64
|
+
[paramsPaginateFalse, paramsAdapterPaginate].forEach((params) => {
|
|
65
|
+
const context = setResultEmpty({
|
|
66
|
+
method,
|
|
67
|
+
type,
|
|
68
|
+
service,
|
|
69
|
+
params,
|
|
70
|
+
result: 123,
|
|
71
|
+
} as any as HookContext);
|
|
72
|
+
|
|
73
|
+
assert.deepStrictEqual(
|
|
74
|
+
context.result,
|
|
75
|
+
123,
|
|
76
|
+
`result is not changed. '${type}:${method}': '${service}' - '${params}'`,
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("find", function () {
|
|
85
|
+
it("sets paginated result", function () {
|
|
86
|
+
const combos = [
|
|
87
|
+
{ service: paginatedService, params: paramsEmpty },
|
|
88
|
+
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
89
|
+
{ service: nonPaginatedService, params: paramsPaginate },
|
|
90
|
+
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
combos.forEach(({ service, params }, i) => {
|
|
94
|
+
const { result } = setResultEmpty({
|
|
95
|
+
service,
|
|
96
|
+
params,
|
|
97
|
+
method: "find",
|
|
98
|
+
} as any as HookContext);
|
|
99
|
+
assert.deepStrictEqual(
|
|
100
|
+
result,
|
|
101
|
+
{ total: 0, skip: 0, limit: 0, data: [] },
|
|
102
|
+
`'${i}': result is paginated empty`,
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("sets empty array", function () {
|
|
108
|
+
const combos = [
|
|
109
|
+
{ service: paginatedService, params: paramsPaginateFalse },
|
|
110
|
+
{ service: nonPaginatedService, params: paramsEmpty },
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
combos.forEach(({ service, params }, i) => {
|
|
114
|
+
const { result } = setResultEmpty({
|
|
115
|
+
service,
|
|
116
|
+
params,
|
|
117
|
+
method: "find",
|
|
118
|
+
} as any as HookContext);
|
|
119
|
+
assert.deepStrictEqual(result, [], `'${i}': result is empty array`);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe("get", function () {
|
|
125
|
+
it("sets result to null", function () {
|
|
126
|
+
const combos = [
|
|
127
|
+
{ service: paginatedService, params: paramsEmpty },
|
|
128
|
+
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
129
|
+
{ service: paginatedService, params: paramsPaginateFalse },
|
|
130
|
+
{ service: nonPaginatedService, params: paramsPaginate },
|
|
131
|
+
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
combos.forEach(({ service, params }, i) => {
|
|
135
|
+
const { result } = setResultEmpty({
|
|
136
|
+
service,
|
|
137
|
+
params,
|
|
138
|
+
method: "get",
|
|
139
|
+
} as any as HookContext);
|
|
140
|
+
assert.deepStrictEqual(result, null, `'${i}': result is null`);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("create", function () {
|
|
146
|
+
it("sets result to null for single data", function () {
|
|
147
|
+
const combos = [
|
|
148
|
+
{ service: paginatedService, params: paramsEmpty },
|
|
149
|
+
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
150
|
+
{ service: paginatedService, params: paramsPaginateFalse },
|
|
151
|
+
{ service: nonPaginatedService, params: paramsPaginate },
|
|
152
|
+
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
153
|
+
];
|
|
154
|
+
|
|
155
|
+
combos.forEach(({ service, params }, i) => {
|
|
156
|
+
const { result } = setResultEmpty({
|
|
157
|
+
service,
|
|
158
|
+
params,
|
|
159
|
+
method: "create",
|
|
160
|
+
data: { id: 1 },
|
|
161
|
+
} as any as HookContext);
|
|
162
|
+
assert.deepStrictEqual(result, null, `'${i}': result is null`);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("sets result to empty array for array data", function () {
|
|
167
|
+
const combos = [
|
|
168
|
+
{ service: paginatedService, params: paramsEmpty },
|
|
169
|
+
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
170
|
+
{ service: paginatedService, params: paramsPaginateFalse },
|
|
171
|
+
{ service: nonPaginatedService, params: paramsPaginate },
|
|
172
|
+
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
173
|
+
];
|
|
174
|
+
|
|
175
|
+
combos.forEach(({ service, params }, i) => {
|
|
176
|
+
const { result } = setResultEmpty({
|
|
177
|
+
service,
|
|
178
|
+
params,
|
|
179
|
+
method: "create",
|
|
180
|
+
data: [{ id: 1 }],
|
|
181
|
+
type: "before",
|
|
182
|
+
} as any as HookContext);
|
|
183
|
+
assert.deepStrictEqual(result, [], `'${i}': result is empty array`);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe("update", function () {
|
|
189
|
+
it("sets result to null", function () {
|
|
190
|
+
const combos = [
|
|
191
|
+
{ service: paginatedService, params: paramsEmpty },
|
|
192
|
+
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
193
|
+
{ service: paginatedService, params: paramsPaginateFalse },
|
|
194
|
+
{ service: nonPaginatedService, params: paramsPaginate },
|
|
195
|
+
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
196
|
+
];
|
|
197
|
+
|
|
198
|
+
combos.forEach(({ service, params }, i) => {
|
|
199
|
+
const { result } = setResultEmpty({
|
|
200
|
+
service,
|
|
201
|
+
params,
|
|
202
|
+
method: "update",
|
|
203
|
+
id: 1,
|
|
204
|
+
} as any as HookContext);
|
|
205
|
+
assert.deepStrictEqual(result, null, `'${i}': result is null`);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
describe("patch", function () {
|
|
211
|
+
it("sets result to null for id: 1", function () {
|
|
212
|
+
const combos = [
|
|
213
|
+
{ service: paginatedService, params: paramsEmpty },
|
|
214
|
+
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
215
|
+
{ service: paginatedService, params: paramsPaginateFalse },
|
|
216
|
+
{ service: nonPaginatedService, params: paramsPaginate },
|
|
217
|
+
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
218
|
+
];
|
|
219
|
+
|
|
220
|
+
combos.forEach(({ service, params }, i) => {
|
|
221
|
+
const { result } = setResultEmpty({
|
|
222
|
+
service,
|
|
223
|
+
params,
|
|
224
|
+
method: "patch",
|
|
225
|
+
id: 1,
|
|
226
|
+
} as any as HookContext);
|
|
227
|
+
assert.deepStrictEqual(result, null, `'${i}': result is null`);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("sets result to empty array for id: null", function () {
|
|
232
|
+
const combos = [
|
|
233
|
+
{ service: paginatedService, params: paramsEmpty },
|
|
234
|
+
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
235
|
+
{ service: paginatedService, params: paramsPaginateFalse },
|
|
236
|
+
{ service: nonPaginatedService, params: paramsPaginate },
|
|
237
|
+
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
238
|
+
];
|
|
239
|
+
|
|
240
|
+
combos.forEach(({ service, params }, i) => {
|
|
241
|
+
const { result } = setResultEmpty({
|
|
242
|
+
service,
|
|
243
|
+
params,
|
|
244
|
+
method: "patch",
|
|
245
|
+
id: null,
|
|
246
|
+
} as any as HookContext);
|
|
247
|
+
assert.deepStrictEqual(result, [], `'${i}': result is empty array`);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
describe("remove", function () {
|
|
253
|
+
it("sets result to null for id: 1", function () {
|
|
254
|
+
const combos = [
|
|
255
|
+
{ service: paginatedService, params: paramsEmpty },
|
|
256
|
+
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
257
|
+
{ service: paginatedService, params: paramsPaginateFalse },
|
|
258
|
+
{ service: nonPaginatedService, params: paramsPaginate },
|
|
259
|
+
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
260
|
+
];
|
|
261
|
+
|
|
262
|
+
combos.forEach(({ service, params }, i) => {
|
|
263
|
+
const { result } = setResultEmpty({
|
|
264
|
+
service,
|
|
265
|
+
params,
|
|
266
|
+
method: "remove",
|
|
267
|
+
id: 1,
|
|
268
|
+
} as any as HookContext);
|
|
269
|
+
assert.deepStrictEqual(result, null, `'${i}': result is null`);
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("sets result to empty array for id: null", function () {
|
|
274
|
+
const combos = [
|
|
275
|
+
{ service: paginatedService, params: paramsEmpty },
|
|
276
|
+
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
277
|
+
{ service: paginatedService, params: paramsPaginateFalse },
|
|
278
|
+
{ service: nonPaginatedService, params: paramsPaginate },
|
|
279
|
+
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
280
|
+
];
|
|
281
|
+
|
|
282
|
+
combos.forEach(({ service, params }, i) => {
|
|
283
|
+
const { result } = setResultEmpty({
|
|
284
|
+
service,
|
|
285
|
+
params,
|
|
286
|
+
method: "remove",
|
|
287
|
+
id: null,
|
|
288
|
+
} as any as HookContext);
|
|
289
|
+
assert.deepStrictEqual(result, [], `'${i}': result is empty array`);
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
}
|