feathers-utils 1.6.1 → 1.8.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/dist/esm/hooks/checkMulti.d.ts +2 -0
- package/dist/esm/hooks/checkMulti.js +18 -0
- package/dist/esm/hooks/runPerItem.d.ts +4 -0
- package/dist/esm/hooks/runPerItem.js +27 -0
- package/dist/esm/hooks/setData.d.ts +4 -0
- package/dist/esm/hooks/setData.js +40 -0
- package/dist/esm/index.d.ts +30 -0
- package/dist/esm/index.js +31 -0
- package/dist/esm/mixins/debounce-mixin/DebouncedStore.d.ts +15 -0
- package/dist/esm/mixins/debounce-mixin/DebouncedStore.js +46 -0
- package/dist/esm/mixins/debounce-mixin/index.d.ts +5 -0
- package/dist/esm/mixins/debounce-mixin/index.js +20 -0
- package/dist/esm/types.d.ts +61 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/utils/addHook.d.ts +3 -0
- package/dist/esm/utils/addHook.js +36 -0
- package/dist/esm/utils/filterQuery.d.ts +3 -0
- package/dist/esm/utils/filterQuery.js +28 -0
- package/dist/esm/utils/getPaginate.d.ts +2 -0
- package/dist/esm/utils/getPaginate.js +14 -0
- package/dist/esm/utils/isMulti.d.ts +2 -0
- package/dist/esm/utils/isMulti.js +17 -0
- package/dist/esm/utils/isPaginated.d.ts +2 -0
- package/dist/esm/utils/isPaginated.js +8 -0
- package/dist/esm/utils/markHookForSkip.d.ts +3 -0
- package/dist/esm/utils/markHookForSkip.js +14 -0
- package/dist/esm/utils/mergeQuery/index.d.ts +3 -0
- package/dist/esm/utils/mergeQuery/index.js +327 -0
- package/dist/esm/utils/mergeQuery/mergeArrays.d.ts +2 -0
- package/dist/esm/utils/mergeQuery/mergeArrays.js +37 -0
- package/dist/esm/utils/pushSet.d.ts +2 -0
- package/dist/esm/utils/pushSet.js +19 -0
- package/dist/esm/utils/setResultEmpty.d.ts +2 -0
- package/dist/esm/utils/setResultEmpty.js +25 -0
- package/dist/esm/utils/shouldSkip.d.ts +2 -0
- package/dist/esm/utils/shouldSkip.js +29 -0
- package/dist/hooks/checkMulti.js +2 -2
- package/dist/hooks/runPerItem.d.ts +2 -1
- package/dist/hooks/runPerItem.js +5 -3
- package/dist/hooks/setData.js +13 -6
- package/dist/index.d.ts +4 -1
- package/dist/index.js +7 -1
- package/dist/mixins/debounce-mixin/DebouncedStore.d.ts +1 -1
- package/dist/mixins/debounce-mixin/DebouncedStore.js +2 -2
- package/dist/mixins/debounce-mixin/index.js +1 -1
- package/dist/types.d.ts +4 -2
- package/dist/utils/filterQuery.js +2 -2
- package/dist/utils/getPaginate.d.ts +2 -0
- package/dist/utils/getPaginate.js +15 -0
- package/dist/utils/isMulti.js +2 -3
- package/dist/utils/isPaginated.d.ts +2 -0
- package/dist/utils/isPaginated.js +12 -0
- package/dist/utils/markHookForSkip.js +1 -1
- package/dist/utils/mergeQuery/index.js +38 -38
- package/dist/utils/pushSet.js +3 -3
- package/dist/utils/setResultEmpty.d.ts +2 -0
- package/dist/utils/setResultEmpty.js +29 -0
- package/package.json +40 -24
- package/src/hooks/runPerItem.ts +3 -1
- package/src/hooks/setData.ts +8 -1
- package/src/index.ts +3 -0
- package/src/mixins/debounce-mixin/DebouncedStore.ts +49 -49
- package/src/types.ts +7 -2
- package/src/utils/getPaginate.ts +18 -0
- package/src/utils/isMulti.ts +2 -3
- package/src/utils/isPaginated.ts +12 -0
- package/src/utils/setResultEmpty.ts +28 -0
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -44
- package/.github/workflows/node.js.yml +0 -45
- package/.gitlab-ci.yml +0 -11
- package/.mocharc.js +0 -11
- package/.nycrc.json +0 -22
- package/.vscode/launch.json +0 -28
- package/.vscode/settings.json +0 -14
- package/index.js +0 -9
- package/test/hooks/checkMulti.test.ts +0 -121
- package/test/hooks/setData.test.ts +0 -333
- package/test/mixins/debounce-mixin.test.ts +0 -174
- package/test/utils/addHook.test.ts +0 -307
- package/test/utils/isMulti.test.ts +0 -53
- package/test/utils/markHookForSkip.test.ts +0 -292
- package/test/utils/mergeQuery.test.ts +0 -407
- package/test/utils/pushSet.test.ts +0 -66
- package/test/utils/shouldSkip.test.ts +0 -67
- package/tsconfig.json +0 -16
- package/tsconfig.test.json +0 -13
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
import assert from "assert";
|
|
2
|
-
import feathers from "@feathersjs/feathers";
|
|
3
|
-
import createService from "feathers-memory";
|
|
4
|
-
|
|
5
|
-
import { addHook } from "../../src";
|
|
6
|
-
|
|
7
|
-
import { HookType, ServiceMethodName } from "../../src/types";
|
|
8
|
-
|
|
9
|
-
const mockApp = (withHooks?: boolean) => {
|
|
10
|
-
const app = feathers();
|
|
11
|
-
app.use("users", createService());
|
|
12
|
-
app.use("tasks", createService());
|
|
13
|
-
app.use("authentication", createService());
|
|
14
|
-
const usersService = app.service("users");
|
|
15
|
-
const tasksService = app.service("tasks");
|
|
16
|
-
const authenticationService = app.service("authentication");
|
|
17
|
-
usersService.path = "users";
|
|
18
|
-
tasksService.path = "tasks";
|
|
19
|
-
authenticationService.path = "authentication";
|
|
20
|
-
if (withHooks) {
|
|
21
|
-
[usersService, tasksService, authenticationService].forEach(service => {
|
|
22
|
-
service.hooks({
|
|
23
|
-
before: {
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
25
|
-
all: [() => {}]
|
|
26
|
-
},
|
|
27
|
-
after: {
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
29
|
-
all: [() => {}]
|
|
30
|
-
},
|
|
31
|
-
error: {
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
33
|
-
all: [() => {}]
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
} else {
|
|
38
|
-
[usersService, tasksService, authenticationService].forEach(service => {
|
|
39
|
-
service.hooks({
|
|
40
|
-
before: { all: [] },
|
|
41
|
-
after: { all: [] },
|
|
42
|
-
error: { all: [] }
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
app,
|
|
48
|
-
usersService,
|
|
49
|
-
tasksService,
|
|
50
|
-
authenticationService
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
describe("util - addHook", function() {
|
|
55
|
-
it("adds all hooks", function() {
|
|
56
|
-
const {
|
|
57
|
-
app,
|
|
58
|
-
usersService,
|
|
59
|
-
tasksService,
|
|
60
|
-
authenticationService
|
|
61
|
-
} = mockApp();
|
|
62
|
-
|
|
63
|
-
const types = ["before", "after", "error"] as HookType[];
|
|
64
|
-
const methods = ["find", "get", "create", "update", "patch", "remove"] as ServiceMethodName[];
|
|
65
|
-
|
|
66
|
-
addHook(app, "addHook", {
|
|
67
|
-
types,
|
|
68
|
-
methods,
|
|
69
|
-
orderByType: {
|
|
70
|
-
before: "first",
|
|
71
|
-
after: "first",
|
|
72
|
-
error: "first"
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
[usersService, tasksService, authenticationService].forEach(service => {
|
|
77
|
-
types.forEach(type => {
|
|
78
|
-
methods.forEach(method => {
|
|
79
|
-
const hooks = service.__hooks[type][method];
|
|
80
|
-
assert.strictEqual(hooks.length, 1, `'${service.path}/${type}:${method}': has 1 hook`);
|
|
81
|
-
assert.strictEqual(hooks[0], "addHook", `'${service.path}/${type}:${method}': hook is 'addHook'`);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("adds hooks to specific type", function() {
|
|
88
|
-
const types = ["before", "after", "error"] as HookType[];
|
|
89
|
-
const methods = ["find", "get", "create", "update", "patch", "remove"] as ServiceMethodName[];
|
|
90
|
-
|
|
91
|
-
types.forEach(type => {
|
|
92
|
-
const {
|
|
93
|
-
app,
|
|
94
|
-
usersService,
|
|
95
|
-
tasksService,
|
|
96
|
-
authenticationService
|
|
97
|
-
} = mockApp();
|
|
98
|
-
|
|
99
|
-
addHook(app, "addHook", {
|
|
100
|
-
types: [type],
|
|
101
|
-
methods,
|
|
102
|
-
orderByType: {
|
|
103
|
-
before: "first",
|
|
104
|
-
after: "first",
|
|
105
|
-
error: "first"
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
const remainingTypes = types.filter(x => x !== type);
|
|
110
|
-
|
|
111
|
-
[usersService, tasksService, authenticationService].forEach(service => {
|
|
112
|
-
methods.forEach(method => {
|
|
113
|
-
const hooks = service.__hooks[type][method];
|
|
114
|
-
assert.strictEqual(hooks.length, 1, `'${service.path}/${type}:${method}': has 1 hook`);
|
|
115
|
-
assert.strictEqual(hooks[0], "addHook", `'${service.path}/${type}:${method}': hook is 'addHook'`);
|
|
116
|
-
remainingTypes.forEach(type => {
|
|
117
|
-
const hooks = service.__hooks[type][method];
|
|
118
|
-
assert.strictEqual(hooks.length, 0, `'${service.path}/${type}:${method}': has zero hooks`);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it("adds hooks to specific type and method", function() {
|
|
126
|
-
const types = ["before", "after", "error"] as HookType[];
|
|
127
|
-
const methods = ["find", "get", "create", "update", "patch", "remove"] as ServiceMethodName[];
|
|
128
|
-
|
|
129
|
-
const method = "find";
|
|
130
|
-
|
|
131
|
-
types.forEach(type => {
|
|
132
|
-
const {
|
|
133
|
-
app,
|
|
134
|
-
usersService,
|
|
135
|
-
tasksService,
|
|
136
|
-
authenticationService
|
|
137
|
-
} = mockApp();
|
|
138
|
-
|
|
139
|
-
addHook(app, "addHook", {
|
|
140
|
-
types: [type],
|
|
141
|
-
methods: [method],
|
|
142
|
-
orderByType: {
|
|
143
|
-
before: "first",
|
|
144
|
-
after: "first",
|
|
145
|
-
error: "first"
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
const remainingTypes = types.filter(x => x !== type);
|
|
150
|
-
const remainingMethods = methods.filter(x => x != method);
|
|
151
|
-
|
|
152
|
-
[usersService, tasksService, authenticationService].forEach(service => {
|
|
153
|
-
const hooks = service.__hooks[type][method];
|
|
154
|
-
assert.strictEqual(hooks.length, 1, `'${service.path}/${type}:${method}': has 1 hook`);
|
|
155
|
-
assert.strictEqual(hooks[0], "addHook", `'${service.path}/${type}:${method}': hook is 'addHook'`);
|
|
156
|
-
remainingTypes.forEach(type => {
|
|
157
|
-
remainingMethods.forEach(method => {
|
|
158
|
-
const hooks = service.__hooks[type][method];
|
|
159
|
-
assert.strictEqual(hooks.length, 0, `'${service.path}/${type}:${method}': has zero hooks`);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it("appends all hooks with 'last'", function() {
|
|
167
|
-
const {
|
|
168
|
-
app,
|
|
169
|
-
usersService,
|
|
170
|
-
tasksService,
|
|
171
|
-
authenticationService
|
|
172
|
-
} = mockApp(true);
|
|
173
|
-
|
|
174
|
-
const types = ["before", "after", "error"] as HookType[];
|
|
175
|
-
const methods = ["find", "get", "create", "update", "patch", "remove"] as ServiceMethodName[];
|
|
176
|
-
|
|
177
|
-
addHook(app, "addHook", {
|
|
178
|
-
types,
|
|
179
|
-
methods,
|
|
180
|
-
orderByType: {
|
|
181
|
-
before: "last",
|
|
182
|
-
after: "last",
|
|
183
|
-
error: "last"
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
[usersService, tasksService, authenticationService].forEach(service => {
|
|
188
|
-
types.forEach(type => {
|
|
189
|
-
methods.forEach(method => {
|
|
190
|
-
const hooks = service.__hooks[type][method];
|
|
191
|
-
assert.strictEqual(hooks.length, 2, `'${service.path}/${type}:${method}': has 2 hooks`);
|
|
192
|
-
assert.strictEqual(hooks[1], "addHook", `'${service.path}/${type}:${method}': last hook is 'addHook'`);
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it("prepends all hooks with 'first'", function() {
|
|
199
|
-
const {
|
|
200
|
-
app,
|
|
201
|
-
usersService,
|
|
202
|
-
tasksService,
|
|
203
|
-
authenticationService
|
|
204
|
-
} = mockApp(true);
|
|
205
|
-
|
|
206
|
-
const types = ["before", "after", "error"] as HookType[];
|
|
207
|
-
const methods = ["find", "get", "create", "update", "patch", "remove"] as ServiceMethodName[];
|
|
208
|
-
|
|
209
|
-
addHook(app, "addHook", {
|
|
210
|
-
types,
|
|
211
|
-
methods,
|
|
212
|
-
orderByType: {
|
|
213
|
-
before: "first",
|
|
214
|
-
after: "first",
|
|
215
|
-
error: "first"
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
[usersService, tasksService, authenticationService].forEach(service => {
|
|
220
|
-
types.forEach(type => {
|
|
221
|
-
methods.forEach(method => {
|
|
222
|
-
const hooks = service.__hooks[type][method];
|
|
223
|
-
assert.strictEqual(hooks.length, 2, `'${service.path}/${type}:${method}' has 2 hooks`);
|
|
224
|
-
assert.strictEqual(hooks[0], "addHook", `'${service.path}/${type}:${method}': first hook is 'addHook'`);
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it("ignores blacklisted", function() {
|
|
231
|
-
const {
|
|
232
|
-
app,
|
|
233
|
-
usersService,
|
|
234
|
-
tasksService,
|
|
235
|
-
authenticationService
|
|
236
|
-
} = mockApp();
|
|
237
|
-
|
|
238
|
-
const types = ["before", "after", "error"] as HookType[];
|
|
239
|
-
const methods = ["find", "get", "create", "update", "patch", "remove"] as ServiceMethodName[];
|
|
240
|
-
|
|
241
|
-
const blacklist = ["authentication"];
|
|
242
|
-
|
|
243
|
-
addHook(app, "addHook", {
|
|
244
|
-
types,
|
|
245
|
-
methods,
|
|
246
|
-
orderByType: {
|
|
247
|
-
before: "first",
|
|
248
|
-
after: "first",
|
|
249
|
-
error: "first"
|
|
250
|
-
},
|
|
251
|
-
blacklist: ["authentication"]
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
[usersService, tasksService, authenticationService].forEach(service => {
|
|
255
|
-
types.forEach(type => {
|
|
256
|
-
methods.forEach(method => {
|
|
257
|
-
const hooks = service.__hooks[type][method];
|
|
258
|
-
if (blacklist.includes(service.path)) {
|
|
259
|
-
assert.strictEqual(hooks.length, 0, `'${service.path}/${type}:${method}' has zero hooks`);
|
|
260
|
-
} else {
|
|
261
|
-
assert.strictEqual(hooks.length, 1, `'${service.path}/${type}:${method}' has 1 hook`);
|
|
262
|
-
assert.strictEqual(hooks[0], "addHook", "hook is 'addHook'");
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it("only sets whitelist", function() {
|
|
270
|
-
const {
|
|
271
|
-
app,
|
|
272
|
-
usersService,
|
|
273
|
-
tasksService,
|
|
274
|
-
authenticationService
|
|
275
|
-
} = mockApp();
|
|
276
|
-
|
|
277
|
-
const types = ["before", "after", "error"] as HookType[];
|
|
278
|
-
const methods = ["find", "get", "create", "update", "patch", "remove"] as ServiceMethodName[];
|
|
279
|
-
|
|
280
|
-
const whitelist = ["users"];
|
|
281
|
-
|
|
282
|
-
addHook(app, "addHook", {
|
|
283
|
-
types,
|
|
284
|
-
methods,
|
|
285
|
-
orderByType: {
|
|
286
|
-
before: "first",
|
|
287
|
-
after: "first",
|
|
288
|
-
error: "first"
|
|
289
|
-
},
|
|
290
|
-
whitelist
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
[usersService, tasksService, authenticationService].forEach(service => {
|
|
294
|
-
types.forEach(type => {
|
|
295
|
-
methods.forEach(method => {
|
|
296
|
-
const hooks = service.__hooks[type][method];
|
|
297
|
-
if (whitelist.includes(service.path)) {
|
|
298
|
-
assert.strictEqual(hooks.length, 1, `'${service.path}/${type}:${method}' has 1 hook`);
|
|
299
|
-
assert.strictEqual(hooks[0], "addHook", "hook is 'addHook'");
|
|
300
|
-
} else {
|
|
301
|
-
assert.strictEqual(hooks.length, 0, `'${service.path}/${type}:${method}' has zero hooks`);
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
});
|
|
307
|
-
});
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import assert from "assert";
|
|
2
|
-
import { isMulti } from "../../src";
|
|
3
|
-
|
|
4
|
-
describe("util - isMulti", function() {
|
|
5
|
-
it("returns true", function() {
|
|
6
|
-
const makeContext = (type: string, method: string) => {
|
|
7
|
-
const context = {
|
|
8
|
-
method,
|
|
9
|
-
type,
|
|
10
|
-
};
|
|
11
|
-
if (method === "create") {
|
|
12
|
-
(type === "before")
|
|
13
|
-
//@ts-ignore
|
|
14
|
-
? context.data = []
|
|
15
|
-
//@ts-ignore
|
|
16
|
-
: context.result = [];
|
|
17
|
-
}
|
|
18
|
-
return context;
|
|
19
|
-
};
|
|
20
|
-
["before", "after"].forEach(type => {
|
|
21
|
-
["find", "create", "patch", "remove"].forEach(method => {
|
|
22
|
-
const context = makeContext(type, method);
|
|
23
|
-
//@ts-ignore
|
|
24
|
-
assert.strictEqual(isMulti(context), true, `'${type}:${method}': returns true`);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("returns false", function() {
|
|
30
|
-
const makeContext = (type: string, method: string) => {
|
|
31
|
-
const context = {
|
|
32
|
-
method,
|
|
33
|
-
type,
|
|
34
|
-
id: 0
|
|
35
|
-
};
|
|
36
|
-
if (method === "create") {
|
|
37
|
-
(type === "before")
|
|
38
|
-
//@ts-ignore
|
|
39
|
-
? context.data = {}
|
|
40
|
-
//@ts-ignore
|
|
41
|
-
: context.result = {};
|
|
42
|
-
}
|
|
43
|
-
return context;
|
|
44
|
-
};
|
|
45
|
-
["before", "after"].forEach(type => {
|
|
46
|
-
["get", "create", "update", "patch", "remove"].forEach(method => {
|
|
47
|
-
const context = makeContext(type, method);
|
|
48
|
-
//@ts-ignore
|
|
49
|
-
assert.strictEqual(isMulti(context), false, `'${type}:${method}': returns false`);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
});
|
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
import assert from "assert";
|
|
2
|
-
import feathers from "@feathersjs/feathers";
|
|
3
|
-
import { Service } from "feathers-memory";
|
|
4
|
-
import { shouldSkip, markHookForSkip } from "../../src";
|
|
5
|
-
|
|
6
|
-
describe("util - markHookForSkip", function() {
|
|
7
|
-
it("returns hook object", function() {
|
|
8
|
-
const context = markHookForSkip("test", "all", {});
|
|
9
|
-
assert.ok(context, "returned context");
|
|
10
|
-
assert.ok(context.params.skipHooks, "has skipHooks");
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it("returns hook object for undefined context", function() {
|
|
14
|
-
const context = markHookForSkip("test", "all");
|
|
15
|
-
assert.ok(context, "returned context");
|
|
16
|
-
assert.ok(context.params.skipHooks, "has skipHooks");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("skips explicitly before hook", async function() {
|
|
20
|
-
const app = feathers();
|
|
21
|
-
app.use("service", new Service());
|
|
22
|
-
const service = app.service("service");
|
|
23
|
-
const ranInto = {};
|
|
24
|
-
service.hooks({
|
|
25
|
-
before: {
|
|
26
|
-
all: [
|
|
27
|
-
context => {
|
|
28
|
-
markHookForSkip("test", "before", context);
|
|
29
|
-
}
|
|
30
|
-
],
|
|
31
|
-
find: [
|
|
32
|
-
context => {
|
|
33
|
-
if (shouldSkip("test", context)) { return context; }
|
|
34
|
-
ranInto["find"] = true;
|
|
35
|
-
},
|
|
36
|
-
context => { context.result = null; }
|
|
37
|
-
],
|
|
38
|
-
get: [
|
|
39
|
-
context => {
|
|
40
|
-
if (shouldSkip("test", context)) { return context; }
|
|
41
|
-
ranInto["get"] = true;
|
|
42
|
-
},
|
|
43
|
-
context => { context.result = null; }
|
|
44
|
-
],
|
|
45
|
-
create: [
|
|
46
|
-
context => {
|
|
47
|
-
if (shouldSkip("test", context)) { return context; }
|
|
48
|
-
ranInto["create"] = true;
|
|
49
|
-
},
|
|
50
|
-
context => { context.result = null; }
|
|
51
|
-
],
|
|
52
|
-
update: [
|
|
53
|
-
context => {
|
|
54
|
-
if (shouldSkip("test", context)) { return context; }
|
|
55
|
-
ranInto["update"] = true;
|
|
56
|
-
},
|
|
57
|
-
context => { context.result = null; }
|
|
58
|
-
],
|
|
59
|
-
patch: [
|
|
60
|
-
context => {
|
|
61
|
-
if (shouldSkip("test", context)) { return context; }
|
|
62
|
-
ranInto["patch"] = true;
|
|
63
|
-
},
|
|
64
|
-
context => { context.result = null; }
|
|
65
|
-
],
|
|
66
|
-
remove: [
|
|
67
|
-
context => {
|
|
68
|
-
if (shouldSkip("test", context)) { return context; }
|
|
69
|
-
ranInto["remove"] = true;
|
|
70
|
-
},
|
|
71
|
-
context => { context.result = null; }
|
|
72
|
-
]
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
const methods = {
|
|
76
|
-
find: [],
|
|
77
|
-
get: [1],
|
|
78
|
-
create: [{}],
|
|
79
|
-
update: [1, {}],
|
|
80
|
-
patch: [1, {}],
|
|
81
|
-
remove: [1]
|
|
82
|
-
};
|
|
83
|
-
const promises = Object.keys(methods).map(async method => {
|
|
84
|
-
await service[method](...methods[method]);
|
|
85
|
-
assert.ok(!Object.prototype.hasOwnProperty.call(ranInto, method), `'${method}': did not run into hook`);
|
|
86
|
-
return true;
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const results = await Promise.all(promises);
|
|
90
|
-
assert.ok(results.every(x => x === true), "all ok");
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("skips explicitly after hook", async function() {
|
|
94
|
-
const app = feathers();
|
|
95
|
-
app.use("service", new Service());
|
|
96
|
-
const service = app.service("service");
|
|
97
|
-
const ranInto = {};
|
|
98
|
-
service.hooks({
|
|
99
|
-
before: {
|
|
100
|
-
all: [
|
|
101
|
-
context => {
|
|
102
|
-
markHookForSkip("test", "after", context);
|
|
103
|
-
},
|
|
104
|
-
context => {
|
|
105
|
-
context.result = null;
|
|
106
|
-
return context;
|
|
107
|
-
}
|
|
108
|
-
]
|
|
109
|
-
},
|
|
110
|
-
after: {
|
|
111
|
-
find: [
|
|
112
|
-
context => {
|
|
113
|
-
if (shouldSkip("test", context)) { return context; }
|
|
114
|
-
ranInto["find"] = true;
|
|
115
|
-
},
|
|
116
|
-
context => { context.result = null; }
|
|
117
|
-
],
|
|
118
|
-
get: [
|
|
119
|
-
context => {
|
|
120
|
-
if (shouldSkip("test", context)) { return context; }
|
|
121
|
-
ranInto["get"] = true;
|
|
122
|
-
},
|
|
123
|
-
context => { context.result = null; }
|
|
124
|
-
],
|
|
125
|
-
create: [
|
|
126
|
-
context => {
|
|
127
|
-
if (shouldSkip("test", context)) { return context; }
|
|
128
|
-
ranInto["create"] = true;
|
|
129
|
-
},
|
|
130
|
-
context => { context.result = null; }
|
|
131
|
-
],
|
|
132
|
-
update: [
|
|
133
|
-
context => {
|
|
134
|
-
if (shouldSkip("test", context)) { return context; }
|
|
135
|
-
ranInto["update"] = true;
|
|
136
|
-
},
|
|
137
|
-
context => { context.result = null; }
|
|
138
|
-
],
|
|
139
|
-
patch: [
|
|
140
|
-
context => {
|
|
141
|
-
if (shouldSkip("test", context)) { return context; }
|
|
142
|
-
ranInto["patch"] = true;
|
|
143
|
-
},
|
|
144
|
-
context => { context.result = null; }
|
|
145
|
-
],
|
|
146
|
-
remove: [
|
|
147
|
-
context => {
|
|
148
|
-
if (shouldSkip("test", context)) { return context; }
|
|
149
|
-
ranInto["remove"] = true;
|
|
150
|
-
},
|
|
151
|
-
context => { context.result = null; }
|
|
152
|
-
]
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
const methods = {
|
|
156
|
-
find: [],
|
|
157
|
-
get: [1],
|
|
158
|
-
create: [{}],
|
|
159
|
-
update: [1, {}],
|
|
160
|
-
patch: [1, {}],
|
|
161
|
-
remove: [1]
|
|
162
|
-
};
|
|
163
|
-
const promises = Object.keys(methods).map(async method => {
|
|
164
|
-
await service[method](...methods[method]);
|
|
165
|
-
assert.ok(!Object.prototype.hasOwnProperty.call(ranInto, method), `'${method}': did not run into hook`);
|
|
166
|
-
return true;
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
const results = await Promise.all(promises);
|
|
170
|
-
assert.ok(results.every(x => x === true), "all ok");
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("skips all hooks", async function() {
|
|
174
|
-
const app = feathers();
|
|
175
|
-
app.use("service", new Service());
|
|
176
|
-
const service = app.service("service");
|
|
177
|
-
const ranIntoBefore = {};
|
|
178
|
-
const ranIntoAfter = {};
|
|
179
|
-
service.hooks({
|
|
180
|
-
before: {
|
|
181
|
-
all: [
|
|
182
|
-
context => {
|
|
183
|
-
markHookForSkip("test", "all", context);
|
|
184
|
-
}
|
|
185
|
-
],
|
|
186
|
-
find: [
|
|
187
|
-
context => {
|
|
188
|
-
if (shouldSkip("test", context)) { return context; }
|
|
189
|
-
ranIntoBefore["find"] = true;
|
|
190
|
-
},
|
|
191
|
-
context => { context.result = null; }
|
|
192
|
-
],
|
|
193
|
-
get: [
|
|
194
|
-
context => {
|
|
195
|
-
if (shouldSkip("test", context)) { return context; }
|
|
196
|
-
ranIntoBefore["get"] = true;
|
|
197
|
-
},
|
|
198
|
-
context => { context.result = null; }
|
|
199
|
-
],
|
|
200
|
-
create: [
|
|
201
|
-
context => {
|
|
202
|
-
if (shouldSkip("test", context)) { return context; }
|
|
203
|
-
ranIntoBefore["create"] = true;
|
|
204
|
-
},
|
|
205
|
-
context => { context.result = null; }
|
|
206
|
-
],
|
|
207
|
-
update: [
|
|
208
|
-
context => {
|
|
209
|
-
if (shouldSkip("test", context)) { return context; }
|
|
210
|
-
ranIntoBefore["update"] = true;
|
|
211
|
-
},
|
|
212
|
-
context => { context.result = null; }
|
|
213
|
-
],
|
|
214
|
-
patch: [
|
|
215
|
-
context => {
|
|
216
|
-
if (shouldSkip("test", context)) { return context; }
|
|
217
|
-
ranIntoBefore["patch"] = true;
|
|
218
|
-
},
|
|
219
|
-
context => { context.result = null; }
|
|
220
|
-
],
|
|
221
|
-
remove: [
|
|
222
|
-
context => {
|
|
223
|
-
if (shouldSkip("test", context)) { return context; }
|
|
224
|
-
ranIntoBefore["remove"] = true;
|
|
225
|
-
},
|
|
226
|
-
context => { context.result = null; }
|
|
227
|
-
]
|
|
228
|
-
},
|
|
229
|
-
after: {
|
|
230
|
-
find: [
|
|
231
|
-
context => {
|
|
232
|
-
if (shouldSkip("test", context)) { return context; }
|
|
233
|
-
ranIntoAfter["find"] = true;
|
|
234
|
-
},
|
|
235
|
-
context => { context.result = null; }
|
|
236
|
-
],
|
|
237
|
-
get: [
|
|
238
|
-
context => {
|
|
239
|
-
if (shouldSkip("test", context)) { return context; }
|
|
240
|
-
ranIntoAfter["get"] = true;
|
|
241
|
-
},
|
|
242
|
-
context => { context.result = null; }
|
|
243
|
-
],
|
|
244
|
-
create: [
|
|
245
|
-
context => {
|
|
246
|
-
if (shouldSkip("test", context)) { return context; }
|
|
247
|
-
ranIntoAfter["create"] = true;
|
|
248
|
-
},
|
|
249
|
-
context => { context.result = null; }
|
|
250
|
-
],
|
|
251
|
-
update: [
|
|
252
|
-
context => {
|
|
253
|
-
if (shouldSkip("test", context)) { return context; }
|
|
254
|
-
ranIntoAfter["update"] = true;
|
|
255
|
-
},
|
|
256
|
-
context => { context.result = null; }
|
|
257
|
-
],
|
|
258
|
-
patch: [
|
|
259
|
-
context => {
|
|
260
|
-
if (shouldSkip("test", context)) { return context; }
|
|
261
|
-
ranIntoAfter["patch"] = true;
|
|
262
|
-
},
|
|
263
|
-
context => { context.result = null; }
|
|
264
|
-
],
|
|
265
|
-
remove: [
|
|
266
|
-
context => {
|
|
267
|
-
if (shouldSkip("test", context)) { return context; }
|
|
268
|
-
ranIntoAfter["remove"] = true;
|
|
269
|
-
},
|
|
270
|
-
context => { context.result = null; }
|
|
271
|
-
]
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
const methods = {
|
|
275
|
-
find: [],
|
|
276
|
-
get: [1],
|
|
277
|
-
create: [{}],
|
|
278
|
-
update: [1, {}],
|
|
279
|
-
patch: [1, {}],
|
|
280
|
-
remove: [1]
|
|
281
|
-
};
|
|
282
|
-
const promises = Object.keys(methods).map(async method => {
|
|
283
|
-
await service[method](...methods[method]);
|
|
284
|
-
assert.ok(!Object.prototype.hasOwnProperty.call(ranIntoBefore, method), `'${method}': did not run into before hook`);
|
|
285
|
-
assert.ok(!Object.prototype.hasOwnProperty.call(ranIntoAfter, method), `'${method}': did not run into after hook`);
|
|
286
|
-
return true;
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
const results = await Promise.all(promises);
|
|
290
|
-
assert.ok(results.every(x => x === true), "all ok");
|
|
291
|
-
});
|
|
292
|
-
});
|