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,208 +1,207 @@
|
|
|
1
|
-
import type { HookContext } from
|
|
1
|
+
import type { HookContext } from '@feathersjs/feathers'
|
|
2
2
|
|
|
3
|
-
export type GetItemsIsArrayFrom =
|
|
3
|
+
export type GetItemsIsArrayFrom = 'data' | 'result' | 'automatic'
|
|
4
4
|
|
|
5
5
|
export type GetItemsIsArrayOptions = {
|
|
6
|
-
from?: GetItemsIsArrayFrom
|
|
7
|
-
}
|
|
6
|
+
from?: GetItemsIsArrayFrom
|
|
7
|
+
}
|
|
8
8
|
|
|
9
9
|
export interface GetItemsIsArrayResult<T = any> {
|
|
10
|
-
items: T[]
|
|
11
|
-
isArray: boolean
|
|
10
|
+
items: T[]
|
|
11
|
+
isArray: boolean
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
14
|
export const getItemsIsArray = <T = any, H extends HookContext = HookContext>(
|
|
16
15
|
context: H,
|
|
17
16
|
options?: GetItemsIsArrayOptions,
|
|
18
17
|
): GetItemsIsArrayResult<T> => {
|
|
19
|
-
const { from =
|
|
18
|
+
const { from = 'automatic' } = options || {}
|
|
20
19
|
|
|
21
|
-
let itemOrItems
|
|
20
|
+
let itemOrItems
|
|
22
21
|
|
|
23
|
-
if (from ===
|
|
24
|
-
itemOrItems = context.type ===
|
|
25
|
-
} else if (from ===
|
|
26
|
-
itemOrItems = context.data
|
|
27
|
-
} else if (from ===
|
|
28
|
-
itemOrItems = context.result
|
|
22
|
+
if (from === 'automatic') {
|
|
23
|
+
itemOrItems = context.type === 'before' ? context.data : context.result
|
|
24
|
+
} else if (from === 'data') {
|
|
25
|
+
itemOrItems = context.data
|
|
26
|
+
} else if (from === 'result') {
|
|
27
|
+
itemOrItems = context.result
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
if ((from ===
|
|
30
|
+
if ((from === 'automatic' || from === 'result') && context.type === 'after') {
|
|
32
31
|
itemOrItems =
|
|
33
|
-
itemOrItems && context.method ===
|
|
32
|
+
itemOrItems && context.method === 'find'
|
|
34
33
|
? itemOrItems.data || itemOrItems
|
|
35
|
-
: itemOrItems
|
|
34
|
+
: itemOrItems
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
const isArray = Array.isArray(itemOrItems)
|
|
37
|
+
const isArray = Array.isArray(itemOrItems)
|
|
39
38
|
return {
|
|
40
39
|
items: isArray ? itemOrItems : itemOrItems != null ? [itemOrItems] : [],
|
|
41
40
|
isArray,
|
|
42
|
-
}
|
|
43
|
-
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
44
43
|
|
|
45
44
|
if (import.meta.vitest) {
|
|
46
|
-
const { describe, it, assert } = import.meta.vitest
|
|
45
|
+
const { describe, it, assert } = import.meta.vitest
|
|
47
46
|
|
|
48
|
-
const assertBefore = (context, items, isArray) => {
|
|
47
|
+
const assertBefore = (context: any, items: any, isArray: any) => {
|
|
49
48
|
const arrays: (GetItemsIsArrayFrom | undefined)[] = [
|
|
50
49
|
undefined,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
]
|
|
50
|
+
'data',
|
|
51
|
+
'automatic',
|
|
52
|
+
]
|
|
54
53
|
|
|
55
54
|
for (const from of arrays) {
|
|
56
55
|
const { items: items2, isArray: isArray2 } = getItemsIsArray(context, {
|
|
57
56
|
from,
|
|
58
|
-
})
|
|
59
|
-
assert.deepStrictEqual(items2, items, `from: ${from}`)
|
|
60
|
-
assert.deepStrictEqual(isArray2, isArray, `from: ${from}`)
|
|
57
|
+
})
|
|
58
|
+
assert.deepStrictEqual(items2, items, `from: ${from}`)
|
|
59
|
+
assert.deepStrictEqual(isArray2, isArray, `from: ${from}`)
|
|
61
60
|
}
|
|
62
|
-
}
|
|
61
|
+
}
|
|
63
62
|
|
|
64
|
-
const assertAfter = (context, items, isArray) => {
|
|
63
|
+
const assertAfter = (context: any, items: any, isArray: any) => {
|
|
65
64
|
const arrays: (GetItemsIsArrayFrom | undefined)[] = [
|
|
66
65
|
undefined,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
]
|
|
66
|
+
'result',
|
|
67
|
+
'automatic',
|
|
68
|
+
]
|
|
70
69
|
|
|
71
70
|
for (const from of arrays) {
|
|
72
71
|
const { items: items2, isArray: isArray2 } = getItemsIsArray(context, {
|
|
73
72
|
from,
|
|
74
|
-
})
|
|
75
|
-
assert.deepStrictEqual(items2, items, `from: ${from}`)
|
|
76
|
-
assert.deepStrictEqual(isArray2, isArray, `from: ${from}`)
|
|
73
|
+
})
|
|
74
|
+
assert.deepStrictEqual(items2, items, `from: ${from}`)
|
|
75
|
+
assert.deepStrictEqual(isArray2, isArray, `from: ${from}`)
|
|
77
76
|
}
|
|
78
|
-
}
|
|
77
|
+
}
|
|
79
78
|
|
|
80
|
-
describe(
|
|
81
|
-
it(
|
|
79
|
+
describe('before', function () {
|
|
80
|
+
it('find:before', async function () {
|
|
82
81
|
const context = {
|
|
83
|
-
type:
|
|
84
|
-
method:
|
|
82
|
+
type: 'before',
|
|
83
|
+
method: 'find',
|
|
85
84
|
params: {
|
|
86
85
|
query: {},
|
|
87
86
|
},
|
|
88
|
-
} as any as HookContext
|
|
87
|
+
} as any as HookContext
|
|
89
88
|
|
|
90
|
-
assertBefore(context, [], false)
|
|
91
|
-
})
|
|
89
|
+
assertBefore(context, [], false)
|
|
90
|
+
})
|
|
92
91
|
|
|
93
|
-
it(
|
|
92
|
+
it('get:before', async function () {
|
|
94
93
|
const context = {
|
|
95
|
-
type:
|
|
96
|
-
method:
|
|
94
|
+
type: 'before',
|
|
95
|
+
method: 'get',
|
|
97
96
|
id: 1,
|
|
98
97
|
params: {
|
|
99
98
|
query: {},
|
|
100
99
|
},
|
|
101
|
-
} as any as HookContext
|
|
100
|
+
} as any as HookContext
|
|
102
101
|
|
|
103
|
-
assertBefore(context, [], false)
|
|
104
|
-
})
|
|
102
|
+
assertBefore(context, [], false)
|
|
103
|
+
})
|
|
105
104
|
|
|
106
|
-
it(
|
|
105
|
+
it('create:before single', async function () {
|
|
107
106
|
const context = {
|
|
108
|
-
type:
|
|
109
|
-
method:
|
|
107
|
+
type: 'before',
|
|
108
|
+
method: 'create',
|
|
110
109
|
data: { test: true },
|
|
111
110
|
params: {
|
|
112
111
|
query: {},
|
|
113
112
|
},
|
|
114
|
-
} as any as HookContext
|
|
113
|
+
} as any as HookContext
|
|
115
114
|
|
|
116
|
-
assertBefore(context, [{ test: true }], false)
|
|
117
|
-
})
|
|
115
|
+
assertBefore(context, [{ test: true }], false)
|
|
116
|
+
})
|
|
118
117
|
|
|
119
|
-
it(
|
|
118
|
+
it('create:before multi', async function () {
|
|
120
119
|
const context = {
|
|
121
|
-
type:
|
|
122
|
-
method:
|
|
120
|
+
type: 'before',
|
|
121
|
+
method: 'create',
|
|
123
122
|
data: [{ test: true }, { test: true }],
|
|
124
123
|
params: {
|
|
125
124
|
query: {},
|
|
126
125
|
},
|
|
127
|
-
} as any as HookContext
|
|
126
|
+
} as any as HookContext
|
|
128
127
|
|
|
129
|
-
assertBefore(context, [{ test: true }, { test: true }], true)
|
|
130
|
-
})
|
|
128
|
+
assertBefore(context, [{ test: true }, { test: true }], true)
|
|
129
|
+
})
|
|
131
130
|
|
|
132
|
-
it(
|
|
131
|
+
it('update:before single', async function () {
|
|
133
132
|
const context = {
|
|
134
|
-
type:
|
|
135
|
-
method:
|
|
133
|
+
type: 'before',
|
|
134
|
+
method: 'update',
|
|
136
135
|
id: 1,
|
|
137
136
|
data: { test: true },
|
|
138
137
|
params: {
|
|
139
138
|
query: {},
|
|
140
139
|
},
|
|
141
|
-
} as any as HookContext
|
|
140
|
+
} as any as HookContext
|
|
142
141
|
|
|
143
|
-
assertBefore(context, [{ test: true }], false)
|
|
144
|
-
})
|
|
142
|
+
assertBefore(context, [{ test: true }], false)
|
|
143
|
+
})
|
|
145
144
|
|
|
146
|
-
it(
|
|
145
|
+
it('patch:before single', async function () {
|
|
147
146
|
const context = {
|
|
148
|
-
type:
|
|
149
|
-
method:
|
|
147
|
+
type: 'before',
|
|
148
|
+
method: 'patch',
|
|
150
149
|
id: 1,
|
|
151
150
|
data: { test: true },
|
|
152
151
|
params: {
|
|
153
152
|
query: {},
|
|
154
153
|
},
|
|
155
|
-
} as any as HookContext
|
|
154
|
+
} as any as HookContext
|
|
156
155
|
|
|
157
|
-
assertBefore(context, [{ test: true }], false)
|
|
158
|
-
})
|
|
156
|
+
assertBefore(context, [{ test: true }], false)
|
|
157
|
+
})
|
|
159
158
|
|
|
160
|
-
it(
|
|
159
|
+
it('patch:before multi', async function () {
|
|
161
160
|
const context = {
|
|
162
|
-
type:
|
|
163
|
-
method:
|
|
161
|
+
type: 'before',
|
|
162
|
+
method: 'patch',
|
|
164
163
|
id: null,
|
|
165
164
|
data: { test: true },
|
|
166
165
|
params: {
|
|
167
166
|
query: {},
|
|
168
167
|
},
|
|
169
|
-
} as any as HookContext
|
|
168
|
+
} as any as HookContext
|
|
170
169
|
|
|
171
|
-
assertBefore(context, [{ test: true }], false)
|
|
172
|
-
})
|
|
170
|
+
assertBefore(context, [{ test: true }], false)
|
|
171
|
+
})
|
|
173
172
|
|
|
174
|
-
it(
|
|
173
|
+
it('remove:before single', async function () {
|
|
175
174
|
const context = {
|
|
176
|
-
type:
|
|
177
|
-
method:
|
|
175
|
+
type: 'before',
|
|
176
|
+
method: 'remove',
|
|
178
177
|
id: 1,
|
|
179
178
|
params: {
|
|
180
179
|
query: {},
|
|
181
180
|
},
|
|
182
|
-
} as any as HookContext
|
|
181
|
+
} as any as HookContext
|
|
183
182
|
|
|
184
|
-
assertBefore(context, [], false)
|
|
185
|
-
})
|
|
183
|
+
assertBefore(context, [], false)
|
|
184
|
+
})
|
|
186
185
|
|
|
187
|
-
it(
|
|
186
|
+
it('remove:before multi', async function () {
|
|
188
187
|
const context = {
|
|
189
|
-
type:
|
|
190
|
-
method:
|
|
188
|
+
type: 'before',
|
|
189
|
+
method: 'remove',
|
|
191
190
|
id: null,
|
|
192
191
|
params: {
|
|
193
192
|
query: {},
|
|
194
193
|
},
|
|
195
|
-
} as any as HookContext
|
|
194
|
+
} as any as HookContext
|
|
196
195
|
|
|
197
|
-
assertBefore(context, [], false)
|
|
198
|
-
})
|
|
199
|
-
})
|
|
196
|
+
assertBefore(context, [], false)
|
|
197
|
+
})
|
|
198
|
+
})
|
|
200
199
|
|
|
201
|
-
describe(
|
|
202
|
-
it(
|
|
200
|
+
describe('after', function () {
|
|
201
|
+
it('find:after paginate:true', function () {
|
|
203
202
|
const context = {
|
|
204
|
-
type:
|
|
205
|
-
method:
|
|
203
|
+
type: 'after',
|
|
204
|
+
method: 'find',
|
|
206
205
|
result: {
|
|
207
206
|
total: 1,
|
|
208
207
|
skip: 0,
|
|
@@ -212,111 +211,111 @@ if (import.meta.vitest) {
|
|
|
212
211
|
params: {
|
|
213
212
|
query: {},
|
|
214
213
|
},
|
|
215
|
-
} as any as HookContext
|
|
214
|
+
} as any as HookContext
|
|
216
215
|
|
|
217
|
-
assertAfter(context, [{ test: true }], true)
|
|
218
|
-
})
|
|
216
|
+
assertAfter(context, [{ test: true }], true)
|
|
217
|
+
})
|
|
219
218
|
|
|
220
|
-
it(
|
|
219
|
+
it('find:after paginate:false', function () {
|
|
221
220
|
const context = {
|
|
222
|
-
type:
|
|
223
|
-
method:
|
|
221
|
+
type: 'after',
|
|
222
|
+
method: 'find',
|
|
224
223
|
result: [{ test: true }],
|
|
225
224
|
params: {
|
|
226
225
|
query: {},
|
|
227
226
|
},
|
|
228
|
-
} as any as HookContext
|
|
227
|
+
} as any as HookContext
|
|
229
228
|
|
|
230
|
-
assertAfter(context, [{ test: true }], true)
|
|
231
|
-
})
|
|
229
|
+
assertAfter(context, [{ test: true }], true)
|
|
230
|
+
})
|
|
232
231
|
|
|
233
|
-
it(
|
|
232
|
+
it('get:after', function () {
|
|
234
233
|
const context = {
|
|
235
|
-
type:
|
|
236
|
-
method:
|
|
234
|
+
type: 'after',
|
|
235
|
+
method: 'get',
|
|
237
236
|
id: 1,
|
|
238
237
|
result: { test: true },
|
|
239
238
|
params: {
|
|
240
239
|
query: {},
|
|
241
240
|
},
|
|
242
|
-
} as any as HookContext
|
|
241
|
+
} as any as HookContext
|
|
243
242
|
|
|
244
|
-
assertAfter(context, [{ test: true }], false)
|
|
245
|
-
})
|
|
243
|
+
assertAfter(context, [{ test: true }], false)
|
|
244
|
+
})
|
|
246
245
|
|
|
247
|
-
it(
|
|
246
|
+
it('update:after', function () {
|
|
248
247
|
const context = {
|
|
249
|
-
type:
|
|
250
|
-
method:
|
|
248
|
+
type: 'after',
|
|
249
|
+
method: 'update',
|
|
251
250
|
id: 1,
|
|
252
|
-
data: { test:
|
|
251
|
+
data: { test: 'yes' },
|
|
253
252
|
result: { test: true },
|
|
254
253
|
params: {
|
|
255
254
|
query: {},
|
|
256
255
|
},
|
|
257
|
-
} as any as HookContext
|
|
256
|
+
} as any as HookContext
|
|
258
257
|
|
|
259
|
-
assertAfter(context, [{ test: true }], false)
|
|
260
|
-
})
|
|
258
|
+
assertAfter(context, [{ test: true }], false)
|
|
259
|
+
})
|
|
261
260
|
|
|
262
|
-
it(
|
|
261
|
+
it('patch:after single', function () {
|
|
263
262
|
const context = {
|
|
264
|
-
type:
|
|
265
|
-
method:
|
|
263
|
+
type: 'after',
|
|
264
|
+
method: 'patch',
|
|
266
265
|
id: 1,
|
|
267
|
-
data: { test:
|
|
266
|
+
data: { test: 'yes' },
|
|
268
267
|
result: { test: true },
|
|
269
268
|
params: {
|
|
270
269
|
query: {},
|
|
271
270
|
},
|
|
272
|
-
} as any as HookContext
|
|
271
|
+
} as any as HookContext
|
|
273
272
|
|
|
274
|
-
assertAfter(context, [{ test: true }], false)
|
|
275
|
-
})
|
|
273
|
+
assertAfter(context, [{ test: true }], false)
|
|
274
|
+
})
|
|
276
275
|
|
|
277
|
-
it(
|
|
276
|
+
it('patch:after multi', function () {
|
|
278
277
|
const context = {
|
|
279
|
-
type:
|
|
280
|
-
method:
|
|
278
|
+
type: 'after',
|
|
279
|
+
method: 'patch',
|
|
281
280
|
id: null,
|
|
282
|
-
data: { test:
|
|
281
|
+
data: { test: 'yes' },
|
|
283
282
|
result: [{ test: true }, { test: true }],
|
|
284
283
|
params: {
|
|
285
284
|
query: {},
|
|
286
285
|
},
|
|
287
|
-
} as any as HookContext
|
|
286
|
+
} as any as HookContext
|
|
288
287
|
|
|
289
|
-
assertAfter(context, [{ test: true }, { test: true }], true)
|
|
290
|
-
})
|
|
288
|
+
assertAfter(context, [{ test: true }, { test: true }], true)
|
|
289
|
+
})
|
|
291
290
|
|
|
292
|
-
it(
|
|
291
|
+
it('remove:after single', function () {
|
|
293
292
|
const context = {
|
|
294
|
-
type:
|
|
295
|
-
method:
|
|
293
|
+
type: 'after',
|
|
294
|
+
method: 'remove',
|
|
296
295
|
id: 1,
|
|
297
|
-
data: { test:
|
|
296
|
+
data: { test: 'yes' },
|
|
298
297
|
result: { test: true },
|
|
299
298
|
params: {
|
|
300
299
|
query: {},
|
|
301
300
|
},
|
|
302
|
-
} as any as HookContext
|
|
301
|
+
} as any as HookContext
|
|
303
302
|
|
|
304
|
-
assertAfter(context, [{ test: true }], false)
|
|
305
|
-
})
|
|
303
|
+
assertAfter(context, [{ test: true }], false)
|
|
304
|
+
})
|
|
306
305
|
|
|
307
|
-
it(
|
|
306
|
+
it('remove:after multi', function () {
|
|
308
307
|
const context = {
|
|
309
|
-
type:
|
|
310
|
-
method:
|
|
308
|
+
type: 'after',
|
|
309
|
+
method: 'remove',
|
|
311
310
|
id: null,
|
|
312
|
-
data: { test:
|
|
311
|
+
data: { test: 'yes' },
|
|
313
312
|
result: [{ test: true }, { test: true }],
|
|
314
313
|
params: {
|
|
315
314
|
query: {},
|
|
316
315
|
},
|
|
317
|
-
} as any as HookContext
|
|
316
|
+
} as any as HookContext
|
|
318
317
|
|
|
319
|
-
assertAfter(context, [{ test: true }, { test: true }], true)
|
|
320
|
-
})
|
|
321
|
-
})
|
|
318
|
+
assertAfter(context, [{ test: true }, { test: true }], true)
|
|
319
|
+
})
|
|
320
|
+
})
|
|
322
321
|
}
|
package/src/utils/getPaginate.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { PaginationOptions } from
|
|
2
|
-
import type { HookContext } from
|
|
3
|
-
import { hasOwnProperty } from
|
|
1
|
+
import type { PaginationOptions } from '@feathersjs/adapter-commons'
|
|
2
|
+
import type { HookContext } from '@feathersjs/feathers'
|
|
3
|
+
import { hasOwnProperty } from './_utils.internal.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* util to get paginate options from context
|
|
@@ -11,92 +11,92 @@ import { hasOwnProperty } from "./_utils.internal";
|
|
|
11
11
|
export const getPaginate = <H extends HookContext = HookContext>(
|
|
12
12
|
context: H,
|
|
13
13
|
): PaginationOptions | undefined => {
|
|
14
|
-
if (hasOwnProperty(context.params,
|
|
15
|
-
return (context.params.paginate as PaginationOptions) || undefined
|
|
14
|
+
if (hasOwnProperty(context.params, 'paginate')) {
|
|
15
|
+
return (context.params.paginate as PaginationOptions) || undefined
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
if (context.params.paginate === false) {
|
|
19
|
-
return undefined
|
|
19
|
+
return undefined
|
|
20
20
|
}
|
|
21
|
-
let options = context.service?.options || {}
|
|
21
|
+
let options = context.service?.options || {}
|
|
22
22
|
|
|
23
23
|
options = {
|
|
24
24
|
...options,
|
|
25
25
|
...context.params.adapter,
|
|
26
|
-
}
|
|
26
|
+
}
|
|
27
27
|
|
|
28
|
-
return options.paginate || undefined
|
|
29
|
-
}
|
|
28
|
+
return options.paginate || undefined
|
|
29
|
+
}
|
|
30
30
|
|
|
31
31
|
if (import.meta.vitest) {
|
|
32
|
-
const { it, assert } = import.meta.vitest
|
|
32
|
+
const { it, assert } = import.meta.vitest
|
|
33
33
|
|
|
34
|
-
it(
|
|
34
|
+
it('returns service.options.paginate', function () {
|
|
35
35
|
const serviceOptions = {
|
|
36
36
|
paginate: {
|
|
37
37
|
default: 10,
|
|
38
38
|
max: 50,
|
|
39
39
|
},
|
|
40
|
-
}
|
|
40
|
+
}
|
|
41
41
|
|
|
42
42
|
const paginate = getPaginate({
|
|
43
43
|
params: {},
|
|
44
44
|
service: {
|
|
45
45
|
options: serviceOptions,
|
|
46
46
|
},
|
|
47
|
-
} as HookContext)
|
|
47
|
+
} as HookContext)
|
|
48
48
|
|
|
49
|
-
assert.deepStrictEqual(paginate, { default: 10, max: 50 })
|
|
50
|
-
})
|
|
49
|
+
assert.deepStrictEqual(paginate, { default: 10, max: 50 })
|
|
50
|
+
})
|
|
51
51
|
|
|
52
|
-
it(
|
|
52
|
+
it('returns undefined for params.paginate: false', function () {
|
|
53
53
|
const serviceOptions = {
|
|
54
54
|
paginate: {
|
|
55
55
|
default: 10,
|
|
56
56
|
max: 50,
|
|
57
57
|
},
|
|
58
|
-
}
|
|
58
|
+
}
|
|
59
59
|
|
|
60
60
|
const paginate = getPaginate({
|
|
61
61
|
params: { paginate: false },
|
|
62
62
|
service: {
|
|
63
63
|
options: serviceOptions,
|
|
64
64
|
},
|
|
65
|
-
} as HookContext)
|
|
65
|
+
} as HookContext)
|
|
66
66
|
|
|
67
|
-
assert.deepStrictEqual(paginate, undefined)
|
|
68
|
-
})
|
|
67
|
+
assert.deepStrictEqual(paginate, undefined)
|
|
68
|
+
})
|
|
69
69
|
|
|
70
|
-
it(
|
|
70
|
+
it('returns context.adapter.paginate over service.options.paginate', function () {
|
|
71
71
|
const serviceOptions = {
|
|
72
72
|
paginate: {
|
|
73
73
|
default: 10,
|
|
74
74
|
max: 50,
|
|
75
75
|
},
|
|
76
|
-
}
|
|
76
|
+
}
|
|
77
77
|
|
|
78
78
|
const paginate = getPaginate({
|
|
79
79
|
params: { adapter: { paginate: { default: 20, max: 100 } } },
|
|
80
80
|
service: {
|
|
81
81
|
options: serviceOptions,
|
|
82
82
|
},
|
|
83
|
-
} as HookContext)
|
|
83
|
+
} as HookContext)
|
|
84
84
|
|
|
85
|
-
assert.deepStrictEqual(paginate, { default: 20, max: 100 })
|
|
86
|
-
})
|
|
85
|
+
assert.deepStrictEqual(paginate, { default: 20, max: 100 })
|
|
86
|
+
})
|
|
87
87
|
|
|
88
|
-
it(
|
|
88
|
+
it('returns undefined for no paginate', function () {
|
|
89
89
|
const serviceOptions = {
|
|
90
90
|
paginate: false,
|
|
91
|
-
}
|
|
91
|
+
}
|
|
92
92
|
|
|
93
93
|
const paginate = getPaginate({
|
|
94
94
|
params: {},
|
|
95
95
|
service: {
|
|
96
96
|
options: serviceOptions,
|
|
97
97
|
},
|
|
98
|
-
} as HookContext)
|
|
98
|
+
} as HookContext)
|
|
99
99
|
|
|
100
|
-
assert.deepStrictEqual(paginate, undefined)
|
|
101
|
-
})
|
|
100
|
+
assert.deepStrictEqual(paginate, undefined)
|
|
101
|
+
})
|
|
102
102
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export * from
|
|
16
|
-
export * from
|
|
17
|
-
export * from
|
|
1
|
+
export * from './defineHooks.js'
|
|
2
|
+
export * from './filterQuery.js'
|
|
3
|
+
export * from './getItemsIsArray.js'
|
|
4
|
+
export * from './getPaginate.js'
|
|
5
|
+
export * from './isMulti.js'
|
|
6
|
+
export * from './isPaginated.js'
|
|
7
|
+
export * from './markHookForSkip.js'
|
|
8
|
+
export * from './mergeQuery/index.js'
|
|
9
|
+
export * from './pushSet.js'
|
|
10
|
+
export * from './setQueryKeySafely.js'
|
|
11
|
+
export * from './setResultEmpty.js'
|
|
12
|
+
export * from './shouldSkip.js'
|
|
13
|
+
export * from './toJSON.js'
|
|
14
|
+
export * from './validateQueryProperty.js'
|
|
15
|
+
export * from './optimizeBatchPatch.js'
|
|
16
|
+
export * from './flattenQuery.js'
|
|
17
|
+
export * from './deflattenQuery.js'
|