feathers-utils 7.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 +28 -42
- package/dist/index.d.cts +27 -28
- package/dist/index.d.mts +27 -28
- package/dist/index.d.ts +27 -28
- package/dist/index.mjs +28 -42
- package/package.json +19 -22
- package/src/filters/array.ts +11 -13
- package/src/filters/index.ts +2 -2
- package/src/filters/object.ts +11 -11
- package/src/hooks/checkMulti.ts +98 -82
- package/src/hooks/createRelated.ts +22 -23
- 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 +32 -32
- package/src/hooks/parseFields.ts +13 -13
- package/src/hooks/removeRelated.ts +20 -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
package/src/utils/isMulti.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HookContext } from
|
|
1
|
+
import type { HookContext } from '@feathersjs/feathers'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* util to check if a hook is a multi hook:
|
|
@@ -12,67 +12,75 @@ import type { HookContext } from "@feathersjs/feathers";
|
|
|
12
12
|
export const isMulti = <H extends HookContext = HookContext>(
|
|
13
13
|
context: H,
|
|
14
14
|
): boolean => {
|
|
15
|
-
const { method } = context
|
|
16
|
-
if (method ===
|
|
17
|
-
return true
|
|
18
|
-
} else if ([
|
|
19
|
-
return context.id == null
|
|
20
|
-
} else if (method ===
|
|
21
|
-
const items = context.type ===
|
|
22
|
-
return Array.isArray(items)
|
|
23
|
-
} else if ([
|
|
24
|
-
return false
|
|
15
|
+
const { method } = context
|
|
16
|
+
if (method === 'find') {
|
|
17
|
+
return true
|
|
18
|
+
} else if (['patch', 'remove'].includes(method)) {
|
|
19
|
+
return context.id == null
|
|
20
|
+
} else if (method === 'create') {
|
|
21
|
+
const items = context.type === 'before' ? context.data : context.result
|
|
22
|
+
return Array.isArray(items)
|
|
23
|
+
} else if (['get', 'update'].includes(method)) {
|
|
24
|
+
return false
|
|
25
25
|
}
|
|
26
|
-
return false
|
|
27
|
-
}
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
28
|
|
|
29
29
|
if (import.meta.vitest) {
|
|
30
|
-
const { it, assert } = import.meta.vitest
|
|
30
|
+
const { it, assert } = import.meta.vitest
|
|
31
31
|
|
|
32
|
-
it(
|
|
32
|
+
it('returns true', function () {
|
|
33
33
|
const makeContext = (type: string, method: string) => {
|
|
34
34
|
const context = {
|
|
35
35
|
method,
|
|
36
36
|
type,
|
|
37
|
-
} as HookContext
|
|
38
|
-
if (method ===
|
|
39
|
-
type ===
|
|
37
|
+
} as HookContext
|
|
38
|
+
if (method === 'create') {
|
|
39
|
+
if (type === 'before') {
|
|
40
|
+
context.data = []
|
|
41
|
+
} else {
|
|
42
|
+
context.result = []
|
|
43
|
+
}
|
|
40
44
|
}
|
|
41
|
-
return context
|
|
42
|
-
}
|
|
43
|
-
[
|
|
44
|
-
[
|
|
45
|
-
const context = makeContext(type, method)
|
|
45
|
+
return context
|
|
46
|
+
}
|
|
47
|
+
;['before', 'after'].forEach((type) => {
|
|
48
|
+
;['find', 'create', 'patch', 'remove'].forEach((method) => {
|
|
49
|
+
const context = makeContext(type, method)
|
|
46
50
|
assert.strictEqual(
|
|
47
51
|
isMulti(context),
|
|
48
52
|
true,
|
|
49
53
|
`'${type}:${method}': returns true`,
|
|
50
|
-
)
|
|
51
|
-
})
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
+
)
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
})
|
|
54
58
|
|
|
55
|
-
it(
|
|
59
|
+
it('returns false', function () {
|
|
56
60
|
const makeContext = (type: string, method: string) => {
|
|
57
61
|
const context = {
|
|
58
62
|
method,
|
|
59
63
|
type,
|
|
60
64
|
id: 0,
|
|
61
|
-
} as HookContext
|
|
62
|
-
if (method ===
|
|
63
|
-
type ===
|
|
65
|
+
} as HookContext
|
|
66
|
+
if (method === 'create') {
|
|
67
|
+
if (type === 'before') {
|
|
68
|
+
context.data = {}
|
|
69
|
+
} else {
|
|
70
|
+
context.result = {}
|
|
71
|
+
}
|
|
64
72
|
}
|
|
65
|
-
return context
|
|
66
|
-
}
|
|
67
|
-
[
|
|
68
|
-
[
|
|
69
|
-
const context = makeContext(type, method)
|
|
73
|
+
return context
|
|
74
|
+
}
|
|
75
|
+
;['before', 'after'].forEach((type) => {
|
|
76
|
+
;['get', 'create', 'update', 'patch', 'remove'].forEach((method) => {
|
|
77
|
+
const context = makeContext(type, method)
|
|
70
78
|
assert.strictEqual(
|
|
71
79
|
isMulti(context),
|
|
72
80
|
false,
|
|
73
81
|
`'${type}:${method}': returns false`,
|
|
74
|
-
)
|
|
75
|
-
})
|
|
76
|
-
})
|
|
77
|
-
})
|
|
82
|
+
)
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
})
|
|
78
86
|
}
|
package/src/utils/isPaginated.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { HookContext } from
|
|
2
|
-
import { getPaginate } from
|
|
1
|
+
import type { HookContext } from '@feathersjs/feathers'
|
|
2
|
+
import { getPaginate } from './getPaginate.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* util to check if a hook is a paginated hook using `getPaginate`
|
|
@@ -7,83 +7,83 @@ import { getPaginate } from "./getPaginate";
|
|
|
7
7
|
export const isPaginated = <H extends HookContext = HookContext>(
|
|
8
8
|
context: H,
|
|
9
9
|
): boolean => {
|
|
10
|
-
if (context.params.paginate === false || context.method !==
|
|
11
|
-
return false
|
|
10
|
+
if (context.params.paginate === false || context.method !== 'find') {
|
|
11
|
+
return false
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const paginate = getPaginate(context)
|
|
14
|
+
const paginate = getPaginate(context)
|
|
15
15
|
|
|
16
|
-
return !!paginate
|
|
17
|
-
}
|
|
16
|
+
return !!paginate
|
|
17
|
+
}
|
|
18
18
|
|
|
19
19
|
if (import.meta.vitest) {
|
|
20
|
-
const { it, assert } = import.meta.vitest
|
|
20
|
+
const { it, assert } = import.meta.vitest
|
|
21
21
|
|
|
22
|
-
it(
|
|
22
|
+
it('returns true for service.options.paginate', function () {
|
|
23
23
|
const serviceOptions = {
|
|
24
24
|
paginate: {
|
|
25
25
|
default: 10,
|
|
26
26
|
max: 50,
|
|
27
27
|
},
|
|
28
|
-
}
|
|
28
|
+
}
|
|
29
29
|
|
|
30
30
|
const paginate = isPaginated({
|
|
31
31
|
params: {},
|
|
32
32
|
service: {
|
|
33
33
|
options: serviceOptions,
|
|
34
34
|
},
|
|
35
|
-
method:
|
|
36
|
-
} as HookContext)
|
|
35
|
+
method: 'find',
|
|
36
|
+
} as HookContext)
|
|
37
37
|
|
|
38
|
-
assert.deepStrictEqual(paginate, true)
|
|
39
|
-
})
|
|
38
|
+
assert.deepStrictEqual(paginate, true)
|
|
39
|
+
})
|
|
40
40
|
|
|
41
|
-
it(
|
|
41
|
+
it('returns false for params.paginate: false', function () {
|
|
42
42
|
const serviceOptions = {
|
|
43
43
|
paginate: {
|
|
44
44
|
default: 10,
|
|
45
45
|
max: 50,
|
|
46
46
|
},
|
|
47
|
-
}
|
|
47
|
+
}
|
|
48
48
|
|
|
49
49
|
const paginate = isPaginated({
|
|
50
50
|
params: { paginate: false },
|
|
51
51
|
service: {
|
|
52
52
|
options: serviceOptions,
|
|
53
53
|
},
|
|
54
|
-
} as HookContext)
|
|
54
|
+
} as HookContext)
|
|
55
55
|
|
|
56
|
-
assert.deepStrictEqual(paginate, false)
|
|
57
|
-
})
|
|
56
|
+
assert.deepStrictEqual(paginate, false)
|
|
57
|
+
})
|
|
58
58
|
|
|
59
|
-
it(
|
|
59
|
+
it('returns true for context.adapter.paginate', function () {
|
|
60
60
|
const serviceOptions = {
|
|
61
61
|
paginate: false,
|
|
62
|
-
}
|
|
62
|
+
}
|
|
63
63
|
|
|
64
64
|
const paginate = isPaginated({
|
|
65
65
|
params: { adapter: { paginate: { default: 20, max: 100 } } },
|
|
66
66
|
service: {
|
|
67
67
|
options: serviceOptions,
|
|
68
68
|
},
|
|
69
|
-
method:
|
|
70
|
-
} as HookContext)
|
|
69
|
+
method: 'find',
|
|
70
|
+
} as HookContext)
|
|
71
71
|
|
|
72
|
-
assert.deepStrictEqual(paginate, true)
|
|
73
|
-
})
|
|
72
|
+
assert.deepStrictEqual(paginate, true)
|
|
73
|
+
})
|
|
74
74
|
|
|
75
|
-
it(
|
|
75
|
+
it('returns false for no paginate', function () {
|
|
76
76
|
const serviceOptions = {
|
|
77
77
|
paginate: false,
|
|
78
|
-
}
|
|
78
|
+
}
|
|
79
79
|
|
|
80
80
|
const paginate = isPaginated({
|
|
81
81
|
params: {},
|
|
82
82
|
service: {
|
|
83
83
|
options: serviceOptions,
|
|
84
84
|
},
|
|
85
|
-
} as HookContext)
|
|
85
|
+
} as HookContext)
|
|
86
86
|
|
|
87
|
-
assert.deepStrictEqual(paginate, false)
|
|
88
|
-
})
|
|
87
|
+
assert.deepStrictEqual(paginate, false)
|
|
88
|
+
})
|
|
89
89
|
}
|