feathers-utils 6.0.0 → 7.0.1
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 -4
- package/dist/index.cjs +81 -99
- package/dist/index.d.cts +35 -33
- package/dist/index.d.mts +35 -33
- package/dist/index.d.ts +35 -33
- package/dist/index.mjs +81 -99
- package/package.json +29 -32
- package/src/.DS_Store +0 -0
- package/src/filters/array.ts +11 -13
- package/src/filters/index.ts +2 -2
- package/src/filters/object.ts +11 -11
- package/src/hooks/.DS_Store +0 -0
- package/src/hooks/checkMulti.ts +98 -82
- package/src/hooks/createRelated.ts +41 -41
- package/src/hooks/forEach.ts +32 -32
- package/src/hooks/from-client-for-server/common.ts +1 -1
- package/src/hooks/from-client-for-server/index.ts +2 -2
- package/src/hooks/from-client-for-server/paramsForServer.ts +32 -32
- package/src/hooks/from-client-for-server/paramsFromClient.ts +25 -25
- package/src/hooks/index.ts +9 -9
- package/src/hooks/onDelete.ts +54 -55
- package/src/hooks/parseFields.ts +13 -13
- package/src/hooks/removeRelated.ts +22 -20
- package/src/hooks/runPerItem.ts +17 -18
- package/src/hooks/setData.ts +295 -264
- package/src/index.ts +6 -6
- package/src/mixins/debounce-mixin/DebouncedStore.ts +29 -29
- package/src/mixins/debounce-mixin/debounceMixin.ts +17 -17
- package/src/mixins/debounce-mixin/index.ts +3 -3
- package/src/mixins/debounce-mixin/types.ts +9 -9
- package/src/mixins/debounce-mixin/utils.ts +3 -3
- package/src/mixins/index.ts +1 -1
- package/src/types.ts +3 -5
- package/src/typesInternal.ts +14 -14
- package/src/utility-types/index.ts +48 -48
- package/src/utils/_utils.internal.ts +5 -5
- package/src/utils/defineHooks.ts +8 -8
- package/src/utils/deflattenQuery.ts +31 -31
- package/src/utils/filterQuery.ts +58 -58
- package/src/utils/flattenQuery.ts +54 -54
- package/src/utils/getItemsIsArray.ts +148 -149
- package/src/utils/getPaginate.ts +31 -31
- package/src/utils/index.ts +17 -17
- package/src/utils/isMulti.ts +48 -40
- package/src/utils/isPaginated.ts +30 -30
- package/src/utils/markHookForSkip.ts +177 -178
- package/src/utils/mergeQuery/index.ts +3 -3
- package/src/utils/mergeQuery/mergeArrays.ts +67 -67
- package/src/utils/mergeQuery/mergeQuery.ts +211 -211
- package/src/utils/mergeQuery/types.ts +12 -12
- package/src/utils/mergeQuery/utils.ts +224 -224
- package/src/utils/optimizeBatchPatch.ts +42 -42
- package/src/utils/pushSet.ts +57 -57
- package/src/utils/setQueryKeySafely.ts +68 -68
- package/src/utils/setResultEmpty.ts +125 -123
- package/src/utils/shouldSkip.ts +72 -72
- package/src/utils/toJSON.ts +4 -4
- package/src/utils/validateQueryProperty.ts +10 -10
- package/src/hooks/makeSequelizeQuery.ts_ +0 -90
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { HookContext } from
|
|
2
|
-
import { isMulti } from
|
|
3
|
-
import { isPaginated } from
|
|
1
|
+
import type { HookContext } from '@feathersjs/feathers'
|
|
2
|
+
import { isMulti } from './isMulti.js'
|
|
3
|
+
import { isPaginated } from './isPaginated.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* util to set `context.result` to an empty array or object, depending on the hook type
|
|
@@ -9,31 +9,31 @@ export const setResultEmpty = <H extends HookContext = HookContext>(
|
|
|
9
9
|
context: H,
|
|
10
10
|
) => {
|
|
11
11
|
if (context.result) {
|
|
12
|
-
return context
|
|
12
|
+
return context
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
const multi = isMulti(context)
|
|
15
|
+
const multi = isMulti(context)
|
|
16
16
|
|
|
17
17
|
if (multi) {
|
|
18
|
-
if (context.method ===
|
|
18
|
+
if (context.method === 'find' && isPaginated(context)) {
|
|
19
19
|
context.result = {
|
|
20
20
|
total: 0,
|
|
21
21
|
skip: 0,
|
|
22
22
|
limit: 0,
|
|
23
23
|
data: [],
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
25
|
} else {
|
|
26
|
-
context.result = []
|
|
26
|
+
context.result = []
|
|
27
27
|
}
|
|
28
28
|
} else {
|
|
29
|
-
context.result = null
|
|
29
|
+
context.result = null
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
return context
|
|
33
|
-
}
|
|
32
|
+
return context
|
|
33
|
+
}
|
|
34
34
|
|
|
35
35
|
if (import.meta.vitest) {
|
|
36
|
-
const { it, assert } = import.meta.vitest
|
|
36
|
+
const { it, assert } = import.meta.vitest
|
|
37
37
|
|
|
38
38
|
const paginatedService = {
|
|
39
39
|
options: {
|
|
@@ -42,252 +42,254 @@ if (import.meta.vitest) {
|
|
|
42
42
|
max: 50,
|
|
43
43
|
},
|
|
44
44
|
},
|
|
45
|
-
}
|
|
45
|
+
}
|
|
46
46
|
|
|
47
47
|
const nonPaginatedService = {
|
|
48
48
|
options: {
|
|
49
49
|
paginate: false,
|
|
50
50
|
},
|
|
51
|
-
}
|
|
51
|
+
}
|
|
52
52
|
|
|
53
|
-
const paramsEmpty = {}
|
|
54
|
-
const paramsPaginateFalse = { paginate: false }
|
|
55
|
-
const paramsPaginate = { paginate: { default: 10, max: 50 } }
|
|
53
|
+
const paramsEmpty = {}
|
|
54
|
+
const paramsPaginateFalse = { paginate: false }
|
|
55
|
+
const paramsPaginate = { paginate: { default: 10, max: 50 } }
|
|
56
56
|
const paramsAdapterPaginate = {
|
|
57
57
|
adapter: { paginate: { default: 10, max: 50 } },
|
|
58
|
-
}
|
|
58
|
+
}
|
|
59
59
|
|
|
60
|
-
it(
|
|
61
|
-
[
|
|
62
|
-
|
|
63
|
-
[
|
|
64
|
-
[
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
it('does not overwrite result', function () {
|
|
61
|
+
;['find', 'get', 'create', 'update', 'patch', 'remove'].forEach(
|
|
62
|
+
(method) => {
|
|
63
|
+
;['before', 'after'].forEach((type) => {
|
|
64
|
+
;[paginatedService, nonPaginatedService].forEach((service) => {
|
|
65
|
+
;[paramsPaginateFalse, paramsAdapterPaginate].forEach((params) => {
|
|
66
|
+
const context = setResultEmpty({
|
|
67
|
+
method,
|
|
68
|
+
type,
|
|
69
|
+
service,
|
|
70
|
+
params,
|
|
71
|
+
result: 123,
|
|
72
|
+
} as any as HookContext)
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
assert.deepStrictEqual(
|
|
75
|
+
context.result,
|
|
76
|
+
123,
|
|
77
|
+
`result is not changed. '${type}:${method}': '${service}' - '${params}'`,
|
|
78
|
+
)
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
},
|
|
83
|
+
)
|
|
84
|
+
})
|
|
83
85
|
|
|
84
|
-
describe(
|
|
85
|
-
it(
|
|
86
|
+
describe('find', function () {
|
|
87
|
+
it('sets paginated result', function () {
|
|
86
88
|
const combos = [
|
|
87
89
|
{ service: paginatedService, params: paramsEmpty },
|
|
88
90
|
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
89
91
|
{ service: nonPaginatedService, params: paramsPaginate },
|
|
90
92
|
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
91
|
-
]
|
|
93
|
+
]
|
|
92
94
|
|
|
93
95
|
combos.forEach(({ service, params }, i) => {
|
|
94
96
|
const { result } = setResultEmpty({
|
|
95
97
|
service,
|
|
96
98
|
params,
|
|
97
|
-
method:
|
|
98
|
-
} as any as HookContext)
|
|
99
|
+
method: 'find',
|
|
100
|
+
} as any as HookContext)
|
|
99
101
|
assert.deepStrictEqual(
|
|
100
102
|
result,
|
|
101
103
|
{ total: 0, skip: 0, limit: 0, data: [] },
|
|
102
104
|
`'${i}': result is paginated empty`,
|
|
103
|
-
)
|
|
104
|
-
})
|
|
105
|
-
})
|
|
105
|
+
)
|
|
106
|
+
})
|
|
107
|
+
})
|
|
106
108
|
|
|
107
|
-
it(
|
|
109
|
+
it('sets empty array', function () {
|
|
108
110
|
const combos = [
|
|
109
111
|
{ service: paginatedService, params: paramsPaginateFalse },
|
|
110
112
|
{ service: nonPaginatedService, params: paramsEmpty },
|
|
111
|
-
]
|
|
113
|
+
]
|
|
112
114
|
|
|
113
115
|
combos.forEach(({ service, params }, i) => {
|
|
114
116
|
const { result } = setResultEmpty({
|
|
115
117
|
service,
|
|
116
118
|
params,
|
|
117
|
-
method:
|
|
118
|
-
} as any as HookContext)
|
|
119
|
-
assert.deepStrictEqual(result, [], `'${i}': result is empty array`)
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
})
|
|
119
|
+
method: 'find',
|
|
120
|
+
} as any as HookContext)
|
|
121
|
+
assert.deepStrictEqual(result, [], `'${i}': result is empty array`)
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
})
|
|
123
125
|
|
|
124
|
-
describe(
|
|
125
|
-
it(
|
|
126
|
+
describe('get', function () {
|
|
127
|
+
it('sets result to null', function () {
|
|
126
128
|
const combos = [
|
|
127
129
|
{ service: paginatedService, params: paramsEmpty },
|
|
128
130
|
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
129
131
|
{ service: paginatedService, params: paramsPaginateFalse },
|
|
130
132
|
{ service: nonPaginatedService, params: paramsPaginate },
|
|
131
133
|
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
132
|
-
]
|
|
134
|
+
]
|
|
133
135
|
|
|
134
136
|
combos.forEach(({ service, params }, i) => {
|
|
135
137
|
const { result } = setResultEmpty({
|
|
136
138
|
service,
|
|
137
139
|
params,
|
|
138
|
-
method:
|
|
139
|
-
} as any as HookContext)
|
|
140
|
-
assert.deepStrictEqual(result, null, `'${i}': result is null`)
|
|
141
|
-
})
|
|
142
|
-
})
|
|
143
|
-
})
|
|
140
|
+
method: 'get',
|
|
141
|
+
} as any as HookContext)
|
|
142
|
+
assert.deepStrictEqual(result, null, `'${i}': result is null`)
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
})
|
|
144
146
|
|
|
145
|
-
describe(
|
|
146
|
-
it(
|
|
147
|
+
describe('create', function () {
|
|
148
|
+
it('sets result to null for single data', function () {
|
|
147
149
|
const combos = [
|
|
148
150
|
{ service: paginatedService, params: paramsEmpty },
|
|
149
151
|
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
150
152
|
{ service: paginatedService, params: paramsPaginateFalse },
|
|
151
153
|
{ service: nonPaginatedService, params: paramsPaginate },
|
|
152
154
|
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
153
|
-
]
|
|
155
|
+
]
|
|
154
156
|
|
|
155
157
|
combos.forEach(({ service, params }, i) => {
|
|
156
158
|
const { result } = setResultEmpty({
|
|
157
159
|
service,
|
|
158
160
|
params,
|
|
159
|
-
method:
|
|
161
|
+
method: 'create',
|
|
160
162
|
data: { id: 1 },
|
|
161
|
-
} as any as HookContext)
|
|
162
|
-
assert.deepStrictEqual(result, null, `'${i}': result is null`)
|
|
163
|
-
})
|
|
164
|
-
})
|
|
163
|
+
} as any as HookContext)
|
|
164
|
+
assert.deepStrictEqual(result, null, `'${i}': result is null`)
|
|
165
|
+
})
|
|
166
|
+
})
|
|
165
167
|
|
|
166
|
-
it(
|
|
168
|
+
it('sets result to empty array for array data', function () {
|
|
167
169
|
const combos = [
|
|
168
170
|
{ service: paginatedService, params: paramsEmpty },
|
|
169
171
|
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
170
172
|
{ service: paginatedService, params: paramsPaginateFalse },
|
|
171
173
|
{ service: nonPaginatedService, params: paramsPaginate },
|
|
172
174
|
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
173
|
-
]
|
|
175
|
+
]
|
|
174
176
|
|
|
175
177
|
combos.forEach(({ service, params }, i) => {
|
|
176
178
|
const { result } = setResultEmpty({
|
|
177
179
|
service,
|
|
178
180
|
params,
|
|
179
|
-
method:
|
|
181
|
+
method: 'create',
|
|
180
182
|
data: [{ id: 1 }],
|
|
181
|
-
type:
|
|
182
|
-
} as any as HookContext)
|
|
183
|
-
assert.deepStrictEqual(result, [], `'${i}': result is empty array`)
|
|
184
|
-
})
|
|
185
|
-
})
|
|
186
|
-
})
|
|
183
|
+
type: 'before',
|
|
184
|
+
} as any as HookContext)
|
|
185
|
+
assert.deepStrictEqual(result, [], `'${i}': result is empty array`)
|
|
186
|
+
})
|
|
187
|
+
})
|
|
188
|
+
})
|
|
187
189
|
|
|
188
|
-
describe(
|
|
189
|
-
it(
|
|
190
|
+
describe('update', function () {
|
|
191
|
+
it('sets result to null', function () {
|
|
190
192
|
const combos = [
|
|
191
193
|
{ service: paginatedService, params: paramsEmpty },
|
|
192
194
|
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
193
195
|
{ service: paginatedService, params: paramsPaginateFalse },
|
|
194
196
|
{ service: nonPaginatedService, params: paramsPaginate },
|
|
195
197
|
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
196
|
-
]
|
|
198
|
+
]
|
|
197
199
|
|
|
198
200
|
combos.forEach(({ service, params }, i) => {
|
|
199
201
|
const { result } = setResultEmpty({
|
|
200
202
|
service,
|
|
201
203
|
params,
|
|
202
|
-
method:
|
|
204
|
+
method: 'update',
|
|
203
205
|
id: 1,
|
|
204
|
-
} as any as HookContext)
|
|
205
|
-
assert.deepStrictEqual(result, null, `'${i}': result is null`)
|
|
206
|
-
})
|
|
207
|
-
})
|
|
208
|
-
})
|
|
206
|
+
} as any as HookContext)
|
|
207
|
+
assert.deepStrictEqual(result, null, `'${i}': result is null`)
|
|
208
|
+
})
|
|
209
|
+
})
|
|
210
|
+
})
|
|
209
211
|
|
|
210
|
-
describe(
|
|
211
|
-
it(
|
|
212
|
+
describe('patch', function () {
|
|
213
|
+
it('sets result to null for id: 1', function () {
|
|
212
214
|
const combos = [
|
|
213
215
|
{ service: paginatedService, params: paramsEmpty },
|
|
214
216
|
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
215
217
|
{ service: paginatedService, params: paramsPaginateFalse },
|
|
216
218
|
{ service: nonPaginatedService, params: paramsPaginate },
|
|
217
219
|
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
218
|
-
]
|
|
220
|
+
]
|
|
219
221
|
|
|
220
222
|
combos.forEach(({ service, params }, i) => {
|
|
221
223
|
const { result } = setResultEmpty({
|
|
222
224
|
service,
|
|
223
225
|
params,
|
|
224
|
-
method:
|
|
226
|
+
method: 'patch',
|
|
225
227
|
id: 1,
|
|
226
|
-
} as any as HookContext)
|
|
227
|
-
assert.deepStrictEqual(result, null, `'${i}': result is null`)
|
|
228
|
-
})
|
|
229
|
-
})
|
|
228
|
+
} as any as HookContext)
|
|
229
|
+
assert.deepStrictEqual(result, null, `'${i}': result is null`)
|
|
230
|
+
})
|
|
231
|
+
})
|
|
230
232
|
|
|
231
|
-
it(
|
|
233
|
+
it('sets result to empty array for id: null', function () {
|
|
232
234
|
const combos = [
|
|
233
235
|
{ service: paginatedService, params: paramsEmpty },
|
|
234
236
|
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
235
237
|
{ service: paginatedService, params: paramsPaginateFalse },
|
|
236
238
|
{ service: nonPaginatedService, params: paramsPaginate },
|
|
237
239
|
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
238
|
-
]
|
|
240
|
+
]
|
|
239
241
|
|
|
240
242
|
combos.forEach(({ service, params }, i) => {
|
|
241
243
|
const { result } = setResultEmpty({
|
|
242
244
|
service,
|
|
243
245
|
params,
|
|
244
|
-
method:
|
|
246
|
+
method: 'patch',
|
|
245
247
|
id: null,
|
|
246
|
-
} as any as HookContext)
|
|
247
|
-
assert.deepStrictEqual(result, [], `'${i}': result is empty array`)
|
|
248
|
-
})
|
|
249
|
-
})
|
|
250
|
-
})
|
|
248
|
+
} as any as HookContext)
|
|
249
|
+
assert.deepStrictEqual(result, [], `'${i}': result is empty array`)
|
|
250
|
+
})
|
|
251
|
+
})
|
|
252
|
+
})
|
|
251
253
|
|
|
252
|
-
describe(
|
|
253
|
-
it(
|
|
254
|
+
describe('remove', function () {
|
|
255
|
+
it('sets result to null for id: 1', function () {
|
|
254
256
|
const combos = [
|
|
255
257
|
{ service: paginatedService, params: paramsEmpty },
|
|
256
258
|
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
257
259
|
{ service: paginatedService, params: paramsPaginateFalse },
|
|
258
260
|
{ service: nonPaginatedService, params: paramsPaginate },
|
|
259
261
|
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
260
|
-
]
|
|
262
|
+
]
|
|
261
263
|
|
|
262
264
|
combos.forEach(({ service, params }, i) => {
|
|
263
265
|
const { result } = setResultEmpty({
|
|
264
266
|
service,
|
|
265
267
|
params,
|
|
266
|
-
method:
|
|
268
|
+
method: 'remove',
|
|
267
269
|
id: 1,
|
|
268
|
-
} as any as HookContext)
|
|
269
|
-
assert.deepStrictEqual(result, null, `'${i}': result is null`)
|
|
270
|
-
})
|
|
271
|
-
})
|
|
270
|
+
} as any as HookContext)
|
|
271
|
+
assert.deepStrictEqual(result, null, `'${i}': result is null`)
|
|
272
|
+
})
|
|
273
|
+
})
|
|
272
274
|
|
|
273
|
-
it(
|
|
275
|
+
it('sets result to empty array for id: null', function () {
|
|
274
276
|
const combos = [
|
|
275
277
|
{ service: paginatedService, params: paramsEmpty },
|
|
276
278
|
{ service: paginatedService, params: paramsAdapterPaginate },
|
|
277
279
|
{ service: paginatedService, params: paramsPaginateFalse },
|
|
278
280
|
{ service: nonPaginatedService, params: paramsPaginate },
|
|
279
281
|
{ service: nonPaginatedService, params: paramsAdapterPaginate },
|
|
280
|
-
]
|
|
282
|
+
]
|
|
281
283
|
|
|
282
284
|
combos.forEach(({ service, params }, i) => {
|
|
283
285
|
const { result } = setResultEmpty({
|
|
284
286
|
service,
|
|
285
287
|
params,
|
|
286
|
-
method:
|
|
288
|
+
method: 'remove',
|
|
287
289
|
id: null,
|
|
288
|
-
} as any as HookContext)
|
|
289
|
-
assert.deepStrictEqual(result, [], `'${i}': result is empty array`)
|
|
290
|
-
})
|
|
291
|
-
})
|
|
292
|
-
})
|
|
290
|
+
} as any as HookContext)
|
|
291
|
+
assert.deepStrictEqual(result, [], `'${i}': result is empty array`)
|
|
292
|
+
})
|
|
293
|
+
})
|
|
294
|
+
})
|
|
293
295
|
}
|
package/src/utils/shouldSkip.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Kudos to @DaddyWarbucks! This is a cheeky copy of his awesome library: 'feathers-fletching'.
|
|
2
2
|
// Definitely check it out! https://daddywarbucks.github.io/feathers-fletching/overview.html
|
|
3
3
|
|
|
4
|
-
import { GeneralError } from
|
|
4
|
+
import { GeneralError } from '@feathersjs/errors'
|
|
5
5
|
|
|
6
|
-
import type { HookContext } from
|
|
6
|
+
import type { HookContext } from '@feathersjs/feathers'
|
|
7
7
|
|
|
8
8
|
export type ShouldSkipOptions = {
|
|
9
|
-
notSkippable?: boolean
|
|
10
|
-
}
|
|
9
|
+
notSkippable?: boolean
|
|
10
|
+
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* util to detect if a hook should be skipped
|
|
@@ -18,144 +18,144 @@ export const shouldSkip = <H extends HookContext = HookContext>(
|
|
|
18
18
|
options?: ShouldSkipOptions,
|
|
19
19
|
): boolean => {
|
|
20
20
|
if (!context.params || !context.params.skipHooks || options?.notSkippable) {
|
|
21
|
-
return false
|
|
21
|
+
return false
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const { skipHooks } = context.params
|
|
24
|
+
const { skipHooks } = context.params
|
|
25
25
|
if (!Array.isArray(skipHooks)) {
|
|
26
|
-
throw new GeneralError(
|
|
26
|
+
throw new GeneralError('The `skipHooks` param must be an Array of Strings')
|
|
27
27
|
}
|
|
28
|
-
const { type } = context
|
|
28
|
+
const { type } = context
|
|
29
29
|
if (skipHooks.includes(hookName)) {
|
|
30
|
-
return true
|
|
31
|
-
} else if (skipHooks.includes(
|
|
32
|
-
return true
|
|
30
|
+
return true
|
|
31
|
+
} else if (skipHooks.includes('all')) {
|
|
32
|
+
return true
|
|
33
33
|
} else if (skipHooks.includes(type)) {
|
|
34
|
-
return true
|
|
34
|
+
return true
|
|
35
35
|
} else if (skipHooks.includes(`${type}:${hookName}`)) {
|
|
36
|
-
return true
|
|
36
|
+
return true
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
return false
|
|
40
|
-
}
|
|
39
|
+
return false
|
|
40
|
+
}
|
|
41
41
|
|
|
42
42
|
if (import.meta.vitest) {
|
|
43
|
-
const { it, assert } = import.meta.vitest
|
|
43
|
+
const { it, assert } = import.meta.vitest
|
|
44
44
|
|
|
45
|
-
it(
|
|
46
|
-
[
|
|
47
|
-
[
|
|
45
|
+
it('returns false if skipHooks not defined', function () {
|
|
46
|
+
;['before', 'after'].forEach((type) => {
|
|
47
|
+
;['find', 'get', 'create', 'update', 'patch', 'remove'].forEach(
|
|
48
48
|
(method) => {
|
|
49
|
-
const context = { type, method } as HookContext
|
|
49
|
+
const context = { type, method } as HookContext
|
|
50
50
|
assert.strictEqual(
|
|
51
|
-
shouldSkip(
|
|
51
|
+
shouldSkip('all', context),
|
|
52
52
|
false,
|
|
53
53
|
`'${type}:${method}': returns false`,
|
|
54
|
-
)
|
|
54
|
+
)
|
|
55
55
|
},
|
|
56
|
-
)
|
|
57
|
-
})
|
|
58
|
-
})
|
|
56
|
+
)
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
59
|
|
|
60
60
|
it("returns true for skipHooks: ['all']", function () {
|
|
61
|
-
[
|
|
62
|
-
[
|
|
61
|
+
;['before', 'after', 'error'].forEach((type) => {
|
|
62
|
+
;['find', 'get', 'create', 'update', 'patch', 'remove'].forEach(
|
|
63
63
|
(method) => {
|
|
64
64
|
const context = {
|
|
65
65
|
type,
|
|
66
66
|
method,
|
|
67
|
-
params: { skipHooks: [
|
|
68
|
-
} as HookContext
|
|
67
|
+
params: { skipHooks: ['all'] },
|
|
68
|
+
} as HookContext
|
|
69
69
|
assert.strictEqual(
|
|
70
|
-
shouldSkip(
|
|
70
|
+
shouldSkip('test', context),
|
|
71
71
|
true,
|
|
72
72
|
`'${type}:${method}': returns true`,
|
|
73
|
-
)
|
|
73
|
+
)
|
|
74
74
|
},
|
|
75
|
-
)
|
|
76
|
-
})
|
|
77
|
-
})
|
|
75
|
+
)
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
78
|
|
|
79
|
-
it(
|
|
80
|
-
[
|
|
81
|
-
[
|
|
79
|
+
it('returns true for skipHooks: [`type`]', function () {
|
|
80
|
+
;['before', 'after', 'error'].forEach((type) => {
|
|
81
|
+
;['find', 'get', 'create', 'update', 'patch', 'remove'].forEach(
|
|
82
82
|
(method) => {
|
|
83
83
|
const context = {
|
|
84
84
|
type,
|
|
85
85
|
method,
|
|
86
86
|
params: { skipHooks: [type] },
|
|
87
|
-
} as HookContext
|
|
87
|
+
} as HookContext
|
|
88
88
|
assert.strictEqual(
|
|
89
|
-
shouldSkip(
|
|
89
|
+
shouldSkip('test', context),
|
|
90
90
|
true,
|
|
91
91
|
`'${type}:${method}': returns true`,
|
|
92
|
-
)
|
|
92
|
+
)
|
|
93
93
|
},
|
|
94
|
-
)
|
|
95
|
-
})
|
|
96
|
-
})
|
|
94
|
+
)
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
97
|
|
|
98
98
|
it("returns true for skipHooks: ['`type`:test']", function () {
|
|
99
|
-
[
|
|
100
|
-
[
|
|
99
|
+
;['before', 'after', 'error'].forEach((type) => {
|
|
100
|
+
;['find', 'get', 'create', 'update', 'patch', 'remove'].forEach(
|
|
101
101
|
(method) => {
|
|
102
102
|
const context = {
|
|
103
103
|
type,
|
|
104
104
|
method,
|
|
105
105
|
params: { skipHooks: [`${type}:test`] },
|
|
106
|
-
} as HookContext
|
|
106
|
+
} as HookContext
|
|
107
107
|
assert.strictEqual(
|
|
108
|
-
shouldSkip(
|
|
108
|
+
shouldSkip('test', context),
|
|
109
109
|
true,
|
|
110
110
|
`'${type}:${method}': returns true`,
|
|
111
|
-
)
|
|
111
|
+
)
|
|
112
112
|
},
|
|
113
|
-
)
|
|
114
|
-
})
|
|
115
|
-
})
|
|
113
|
+
)
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
116
|
|
|
117
117
|
it("returns true for skipHooks: ['test']", function () {
|
|
118
|
-
[
|
|
119
|
-
[
|
|
118
|
+
;['before', 'after', 'error'].forEach((type) => {
|
|
119
|
+
;['find', 'get', 'create', 'update', 'patch', 'remove'].forEach(
|
|
120
120
|
(method) => {
|
|
121
121
|
const context = {
|
|
122
122
|
type,
|
|
123
123
|
method,
|
|
124
|
-
params: { skipHooks: [
|
|
125
|
-
} as HookContext
|
|
124
|
+
params: { skipHooks: ['test'] },
|
|
125
|
+
} as HookContext
|
|
126
126
|
assert.strictEqual(
|
|
127
|
-
shouldSkip(
|
|
127
|
+
shouldSkip('test', context),
|
|
128
128
|
true,
|
|
129
129
|
`'${type}:${method}': returns true`,
|
|
130
|
-
)
|
|
130
|
+
)
|
|
131
131
|
},
|
|
132
|
-
)
|
|
133
|
-
})
|
|
134
|
-
})
|
|
132
|
+
)
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
135
|
|
|
136
|
-
it(
|
|
137
|
-
const types = [
|
|
136
|
+
it('returns false for skipHooks other than test', function () {
|
|
137
|
+
const types = ['before', 'after', 'error']
|
|
138
138
|
types.forEach((type) => {
|
|
139
|
-
[
|
|
139
|
+
;['find', 'get', 'create', 'update', 'patch', 'remove'].forEach(
|
|
140
140
|
(method) => {
|
|
141
|
-
const remainingTypes = types.filter((x) => x !== type)
|
|
141
|
+
const remainingTypes = types.filter((x) => x !== type)
|
|
142
142
|
const skipHooks = [
|
|
143
|
-
|
|
143
|
+
'test2',
|
|
144
144
|
`${type}:test2`,
|
|
145
145
|
...remainingTypes.map((t) => `${t}:test1`),
|
|
146
|
-
]
|
|
146
|
+
]
|
|
147
147
|
const context = {
|
|
148
148
|
type,
|
|
149
149
|
method,
|
|
150
150
|
params: { skipHooks },
|
|
151
|
-
} as HookContext
|
|
151
|
+
} as HookContext
|
|
152
152
|
assert.strictEqual(
|
|
153
|
-
shouldSkip(
|
|
153
|
+
shouldSkip('test1', context),
|
|
154
154
|
false,
|
|
155
155
|
`'${type}:${method}': returns true`,
|
|
156
|
-
)
|
|
156
|
+
)
|
|
157
157
|
},
|
|
158
|
-
)
|
|
159
|
-
})
|
|
160
|
-
})
|
|
158
|
+
)
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
161
|
}
|
package/src/utils/toJSON.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { HookContext } from
|
|
1
|
+
import type { HookContext } from '@feathersjs/feathers'
|
|
2
2
|
|
|
3
3
|
export const toJSON = (context: HookContext) => {
|
|
4
4
|
if (context.toJSON) {
|
|
5
|
-
return context.toJSON()
|
|
5
|
+
return context.toJSON()
|
|
6
6
|
}
|
|
7
|
-
return context
|
|
8
|
-
}
|
|
7
|
+
return context
|
|
8
|
+
}
|