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
package/src/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './hooks/index.js'
|
|
2
|
+
export * from './mixins/index.js'
|
|
3
3
|
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
4
|
+
export * from './utils/index.js'
|
|
5
|
+
export * from './filters/index.js'
|
|
6
6
|
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
7
|
+
export * from './types.js'
|
|
8
|
+
export * from './utility-types/index.js'
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import _debounce from
|
|
1
|
+
import _debounce from 'lodash/debounce.js'
|
|
2
2
|
|
|
3
|
-
import type { DebouncedFunc } from
|
|
4
|
-
import type { Application, Id } from
|
|
5
|
-
import type { DebouncedFunctionApp, DebouncedStoreOptions } from
|
|
6
|
-
import { makeDefaultOptions } from
|
|
3
|
+
import type { DebouncedFunc } from 'lodash'
|
|
4
|
+
import type { Application, Id } from '@feathersjs/feathers'
|
|
5
|
+
import type { DebouncedFunctionApp, DebouncedStoreOptions } from './types.js'
|
|
6
|
+
import { makeDefaultOptions } from './utils.js'
|
|
7
7
|
|
|
8
8
|
export type DebouncedService<T = any> = T & {
|
|
9
|
-
debouncedStore: DebouncedStore
|
|
10
|
-
}
|
|
9
|
+
debouncedStore: DebouncedStore
|
|
10
|
+
}
|
|
11
11
|
|
|
12
12
|
export class DebouncedStore {
|
|
13
|
-
private _app: Application
|
|
14
|
-
private _options: DebouncedStoreOptions
|
|
15
|
-
private _isRunningById: Record<string, unknown
|
|
13
|
+
private _app: Application
|
|
14
|
+
private _options: DebouncedStoreOptions
|
|
15
|
+
private _isRunningById: Record<string, unknown>
|
|
16
16
|
_queueById: Record<
|
|
17
17
|
string,
|
|
18
18
|
DebouncedFunc<
|
|
19
19
|
(id: Id, action: DebouncedFunctionApp) => void | Promise<void>
|
|
20
20
|
>
|
|
21
|
-
|
|
21
|
+
>
|
|
22
22
|
//_waitingById: Record<string, WaitingObject>;
|
|
23
|
-
add
|
|
23
|
+
add
|
|
24
24
|
constructor(app: Application, options?: Partial<DebouncedStoreOptions>) {
|
|
25
|
-
this._app = app
|
|
26
|
-
this._options = Object.assign(makeDefaultOptions(), options)
|
|
27
|
-
this._queueById = {}
|
|
28
|
-
this._isRunningById = {}
|
|
25
|
+
this._app = app
|
|
26
|
+
this._options = Object.assign(makeDefaultOptions(), options)
|
|
27
|
+
this._queueById = {}
|
|
28
|
+
this._isRunningById = {}
|
|
29
29
|
//this._waitingById = {};
|
|
30
30
|
|
|
31
31
|
this.add = this.debounceById(this.unbounced, this._options.wait, {
|
|
32
32
|
leading: this._options.leading,
|
|
33
33
|
maxWait: this._options.maxWait,
|
|
34
34
|
trailing: this._options.trailing,
|
|
35
|
-
})
|
|
35
|
+
})
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
private async unbounced(id: Id, action: DebouncedFunctionApp): Promise<void> {
|
|
39
39
|
if (this._queueById[id] === undefined) {
|
|
40
|
-
return
|
|
40
|
+
return
|
|
41
41
|
}
|
|
42
|
-
delete this._queueById[id]
|
|
43
|
-
this._isRunningById[id] = true
|
|
44
|
-
await action(this._app)
|
|
45
|
-
delete this._isRunningById[id]
|
|
42
|
+
delete this._queueById[id]
|
|
43
|
+
this._isRunningById[id] = true
|
|
44
|
+
await action(this._app)
|
|
45
|
+
delete this._isRunningById[id]
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
private debounceById(
|
|
@@ -51,22 +51,22 @@ export class DebouncedStore {
|
|
|
51
51
|
options?: Partial<DebouncedStoreOptions>,
|
|
52
52
|
) {
|
|
53
53
|
return (id: Id, action: (app?: Application) => void | Promise<void>) => {
|
|
54
|
-
if (typeof this._queueById[id] ===
|
|
55
|
-
return this._queueById[id](id, action)
|
|
54
|
+
if (typeof this._queueById[id] === 'function') {
|
|
55
|
+
return this._queueById[id](id, action)
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
this._queueById[id] = _debounce(
|
|
59
59
|
(id, action) => {
|
|
60
|
-
this.unbounced(id, action)
|
|
60
|
+
this.unbounced(id, action)
|
|
61
61
|
},
|
|
62
62
|
wait,
|
|
63
63
|
{ ...options, leading: false },
|
|
64
|
-
)
|
|
65
|
-
return this._queueById[id](id, action)
|
|
66
|
-
}
|
|
64
|
+
) // leading required for return promise
|
|
65
|
+
return this._queueById[id](id, action)
|
|
66
|
+
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
cancel(id: Id): void {
|
|
70
|
-
delete this._queueById[id]
|
|
70
|
+
delete this._queueById[id]
|
|
71
71
|
}
|
|
72
72
|
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import type { Application } from
|
|
2
|
-
import { DebouncedStore } from
|
|
3
|
-
import type {
|
|
4
|
-
|
|
1
|
+
import type { Application } from '@feathersjs/feathers'
|
|
2
|
+
import { DebouncedStore } from './DebouncedStore.js'
|
|
3
|
+
import type {
|
|
4
|
+
DebouncedStoreOptions,
|
|
5
|
+
InitDebounceMixinOptions,
|
|
6
|
+
} from './types.js'
|
|
7
|
+
import { makeDefaultOptions } from './utils.js'
|
|
5
8
|
|
|
6
9
|
export function debounceMixin(
|
|
7
10
|
options?: Partial<InitDebounceMixinOptions>,
|
|
8
11
|
): (app: Application) => void {
|
|
9
12
|
return (app: Application): void => {
|
|
10
|
-
options = options || {}
|
|
11
|
-
const defaultOptions = Object.assign(
|
|
12
|
-
makeDefaultOptions(),
|
|
13
|
-
options?.default,
|
|
14
|
-
);
|
|
13
|
+
options = options || {}
|
|
14
|
+
const defaultOptions = Object.assign(makeDefaultOptions(), options?.default)
|
|
15
15
|
|
|
16
|
-
app.mixins.push((service: any, path) => {
|
|
16
|
+
app.mixins.push((service: any, path: string) => {
|
|
17
17
|
// if path is on blacklist, don't add debouncedStore to service
|
|
18
|
-
if (options?.blacklist && options.blacklist.includes(path)) return
|
|
18
|
+
if (options?.blacklist && options.blacklist.includes(path)) return
|
|
19
19
|
// if service already has registered something on `debouncedStore`
|
|
20
20
|
if (service.debouncedStore) {
|
|
21
21
|
console.warn(
|
|
22
22
|
`[feathers-utils] service: '${path}' already has a property 'debouncedStore'. Mixin will skip creating a new debouncedStore`,
|
|
23
|
-
)
|
|
24
|
-
return
|
|
23
|
+
)
|
|
24
|
+
return
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
const serviceOptions = Object.assign({}, defaultOptions, options?.[path])
|
|
27
|
+
const serviceOptions = Object.assign({}, defaultOptions, options?.[path])
|
|
28
28
|
service.debouncedStore = new DebouncedStore(
|
|
29
29
|
app,
|
|
30
30
|
serviceOptions as DebouncedStoreOptions,
|
|
31
|
-
)
|
|
32
|
-
})
|
|
33
|
-
}
|
|
31
|
+
)
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
34
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from './types.js'
|
|
2
|
+
export * from './DebouncedStore.js'
|
|
3
|
+
export * from './debounceMixin.js'
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { Application } from
|
|
1
|
+
import type { Application } from '@feathersjs/feathers'
|
|
2
2
|
|
|
3
3
|
export interface InitDebounceMixinOptions {
|
|
4
|
-
default: Partial<DebouncedStoreOptions
|
|
5
|
-
blacklist: string[]
|
|
6
|
-
[key: string]: unknown
|
|
4
|
+
default: Partial<DebouncedStoreOptions>
|
|
5
|
+
blacklist: string[]
|
|
6
|
+
[key: string]: unknown
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export type DebouncedFunctionApp = (app?: Application) => void | Promise<void
|
|
9
|
+
export type DebouncedFunctionApp = (app?: Application) => void | Promise<void>
|
|
10
10
|
|
|
11
11
|
export interface DebouncedStoreOptions {
|
|
12
|
-
leading: boolean
|
|
13
|
-
maxWait: number | undefined
|
|
14
|
-
trailing: boolean
|
|
15
|
-
wait: number
|
|
12
|
+
leading: boolean
|
|
13
|
+
maxWait: number | undefined
|
|
14
|
+
trailing: boolean
|
|
15
|
+
wait: number
|
|
16
16
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DebouncedStoreOptions } from
|
|
1
|
+
import type { DebouncedStoreOptions } from './types.js'
|
|
2
2
|
|
|
3
3
|
export const makeDefaultOptions = (): DebouncedStoreOptions => {
|
|
4
4
|
return {
|
|
@@ -6,5 +6,5 @@ export const makeDefaultOptions = (): DebouncedStoreOptions => {
|
|
|
6
6
|
maxWait: undefined,
|
|
7
7
|
trailing: true,
|
|
8
8
|
wait: 100,
|
|
9
|
-
}
|
|
10
|
-
}
|
|
9
|
+
}
|
|
10
|
+
}
|
package/src/mixins/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './debounce-mixin/index.js'
|
package/src/types.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import type { HookContext } from
|
|
1
|
+
import type { HookContext } from '@feathersjs/feathers'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
export type Predicate<T = any> = (item: T) => boolean;
|
|
3
|
+
export type Predicate<T = any> = (item: T) => boolean
|
|
5
4
|
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
5
|
export type PredicateWithContext<T = any> = (
|
|
8
6
|
item: T,
|
|
9
7
|
context: HookContext,
|
|
10
|
-
) => boolean
|
|
8
|
+
) => boolean
|
package/src/typesInternal.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
// here are types that are not meant to be exported!
|
|
2
2
|
// just for internal use of this package
|
|
3
3
|
|
|
4
|
-
import type { HookContext } from
|
|
4
|
+
import type { HookContext } from '@feathersjs/feathers'
|
|
5
5
|
|
|
6
|
-
export type MaybeArray<T> = T | T[]
|
|
7
|
-
export type Promisable<T> = T | Promise<T
|
|
8
|
-
export type Path = Array<string | number
|
|
6
|
+
export type MaybeArray<T> = T | T[]
|
|
7
|
+
export type Promisable<T> = T | Promise<T>
|
|
8
|
+
export type Path = Array<string | number>
|
|
9
9
|
|
|
10
|
-
export type HookType =
|
|
10
|
+
export type HookType = 'before' | 'after' | 'error'
|
|
11
11
|
export type ServiceMethodName =
|
|
12
|
-
|
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
|
|
|
17
|
-
|
|
|
12
|
+
| 'find'
|
|
13
|
+
| 'get'
|
|
14
|
+
| 'create'
|
|
15
|
+
| 'update'
|
|
16
|
+
| 'patch'
|
|
17
|
+
| 'remove'
|
|
18
18
|
|
|
19
19
|
export type ReturnSyncHook<H extends HookContext = HookContext> = (
|
|
20
20
|
context: H,
|
|
21
|
-
) => H
|
|
21
|
+
) => H
|
|
22
22
|
export type ReturnAsyncHook<H extends HookContext = HookContext> = (
|
|
23
23
|
context: H,
|
|
24
|
-
) => Promise<H
|
|
24
|
+
) => Promise<H>
|
|
25
25
|
|
|
26
|
-
export type KeyOf<T> = Extract<keyof T, string
|
|
26
|
+
export type KeyOf<T> = Extract<keyof T, string>
|
|
@@ -1,162 +1,162 @@
|
|
|
1
|
-
import type { Application, Id } from
|
|
1
|
+
import type { Application, Id } from '@feathersjs/feathers'
|
|
2
2
|
|
|
3
|
-
type Single<T> = T extends Array<infer U> ? U : T
|
|
4
|
-
type AsArray<T> = T extends any[] ? T : [T]
|
|
3
|
+
type Single<T> = T extends Array<infer U> ? U : T
|
|
4
|
+
type AsArray<T> = T extends any[] ? T : [T]
|
|
5
5
|
|
|
6
6
|
export type InferCreateData<S> = S extends {
|
|
7
|
-
create: (data: infer D, params: any) => any
|
|
7
|
+
create: (data: infer D, params: any) => any
|
|
8
8
|
}
|
|
9
9
|
? D
|
|
10
|
-
: never
|
|
10
|
+
: never
|
|
11
11
|
|
|
12
|
-
export type InferCreateDataSingle<S> = Single<InferCreateData<S
|
|
12
|
+
export type InferCreateDataSingle<S> = Single<InferCreateData<S>>
|
|
13
13
|
|
|
14
14
|
export type InferUpdateData<S> = S extends {
|
|
15
|
-
update: (id: any, data: infer D, params: any) => any
|
|
15
|
+
update: (id: any, data: infer D, params: any) => any
|
|
16
16
|
}
|
|
17
17
|
? D
|
|
18
|
-
: never
|
|
18
|
+
: never
|
|
19
19
|
|
|
20
20
|
export type InferPatchData<S> = S extends {
|
|
21
|
-
patch: (id: any, data: infer D, params: any) => any
|
|
21
|
+
patch: (id: any, data: infer D, params: any) => any
|
|
22
22
|
}
|
|
23
23
|
? D
|
|
24
|
-
: never
|
|
24
|
+
: never
|
|
25
25
|
|
|
26
26
|
export type InferGetResult<S> = S extends {
|
|
27
|
-
get: (id: any, params: any) => infer R
|
|
27
|
+
get: (id: any, params: any) => infer R
|
|
28
28
|
}
|
|
29
29
|
? Awaited<R>
|
|
30
|
-
: never
|
|
30
|
+
: never
|
|
31
31
|
|
|
32
32
|
export type InferFindResult<S> = S extends {
|
|
33
|
-
find: (params: any) => infer R
|
|
33
|
+
find: (params: any) => infer R
|
|
34
34
|
}
|
|
35
35
|
? Awaited<R>
|
|
36
|
-
: never
|
|
36
|
+
: never
|
|
37
37
|
|
|
38
38
|
export type InferCreateResult<S, D = unknown> = S extends {
|
|
39
|
-
create: (data: any, params: any) => infer R
|
|
39
|
+
create: (data: any, params: any) => infer R
|
|
40
40
|
}
|
|
41
41
|
? D extends any[]
|
|
42
42
|
? AsArray<Awaited<R>>
|
|
43
43
|
: D extends InferCreateDataSingle<S>
|
|
44
44
|
? Single<Awaited<R>>
|
|
45
45
|
: Awaited<R>
|
|
46
|
-
: never
|
|
46
|
+
: never
|
|
47
47
|
|
|
48
|
-
export type InferCreateResultSingle<S> = Single<InferCreateResult<S
|
|
48
|
+
export type InferCreateResultSingle<S> = Single<InferCreateResult<S>>
|
|
49
49
|
|
|
50
50
|
export type InferUpdateResult<S> = S extends {
|
|
51
|
-
update: (id: any, data: any, params: any) => infer R
|
|
51
|
+
update: (id: any, data: any, params: any) => infer R
|
|
52
52
|
}
|
|
53
53
|
? Awaited<R>
|
|
54
|
-
: never
|
|
54
|
+
: never
|
|
55
55
|
|
|
56
56
|
export type InferPatchResult<S, IdOrNullable = any> = S extends {
|
|
57
|
-
patch: (id: Id, data: any, params: any) => infer R
|
|
57
|
+
patch: (id: Id, data: any, params: any) => infer R
|
|
58
58
|
}
|
|
59
59
|
? IdOrNullable extends Id
|
|
60
60
|
? Single<Awaited<R>>
|
|
61
61
|
: IdOrNullable extends null
|
|
62
62
|
? AsArray<Awaited<R>>
|
|
63
63
|
: Awaited<R>
|
|
64
|
-
: never
|
|
64
|
+
: never
|
|
65
65
|
|
|
66
66
|
export type InferRemoveResult<S, IdOrNullable = any> = S extends {
|
|
67
|
-
remove: (id: IdOrNullable, params: any) => infer R
|
|
67
|
+
remove: (id: IdOrNullable, params: any) => infer R
|
|
68
68
|
}
|
|
69
69
|
? IdOrNullable extends Id
|
|
70
70
|
? Single<Awaited<R>>
|
|
71
71
|
: IdOrNullable extends null
|
|
72
72
|
? AsArray<Awaited<R>>
|
|
73
73
|
: Awaited<R>
|
|
74
|
-
: never
|
|
74
|
+
: never
|
|
75
75
|
|
|
76
76
|
export type GetService<
|
|
77
77
|
App extends Application,
|
|
78
78
|
Path extends string,
|
|
79
|
-
> = App[
|
|
79
|
+
> = App['services'][Path]
|
|
80
80
|
|
|
81
81
|
export type InferGetResultFromPath<
|
|
82
82
|
App extends Application,
|
|
83
83
|
Path extends string,
|
|
84
|
-
> = InferGetResult<GetService<App, Path
|
|
84
|
+
> = InferGetResult<GetService<App, Path>>
|
|
85
85
|
export type InferFindResultFromPath<
|
|
86
86
|
App extends Application,
|
|
87
87
|
Path extends string,
|
|
88
|
-
> = InferFindResult<GetService<App, Path
|
|
88
|
+
> = InferFindResult<GetService<App, Path>>
|
|
89
89
|
|
|
90
90
|
export type InferCreateDataFromPath<
|
|
91
91
|
App extends Application,
|
|
92
92
|
Path extends string,
|
|
93
|
-
> = InferCreateData<GetService<App, Path
|
|
93
|
+
> = InferCreateData<GetService<App, Path>>
|
|
94
94
|
export type InferCreateDataSingleFromPath<
|
|
95
95
|
App extends Application,
|
|
96
96
|
Path extends string,
|
|
97
|
-
> = InferCreateDataSingle<GetService<App, Path
|
|
97
|
+
> = InferCreateDataSingle<GetService<App, Path>>
|
|
98
98
|
|
|
99
99
|
export type InferCreateResultFromPath<
|
|
100
100
|
App extends Application,
|
|
101
101
|
Path extends string,
|
|
102
102
|
D = unknown,
|
|
103
|
-
> = InferCreateResult<GetService<App, Path>, D
|
|
103
|
+
> = InferCreateResult<GetService<App, Path>, D>
|
|
104
104
|
export type InferCreateResultSingleFromPath<
|
|
105
105
|
App extends Application,
|
|
106
106
|
Path extends string,
|
|
107
|
-
> = InferCreateResultSingle<GetService<App, Path
|
|
107
|
+
> = InferCreateResultSingle<GetService<App, Path>>
|
|
108
108
|
|
|
109
109
|
export type InferUpdateDataFromPath<
|
|
110
110
|
App extends Application,
|
|
111
111
|
Path extends string,
|
|
112
|
-
> = InferUpdateData<GetService<App, Path
|
|
112
|
+
> = InferUpdateData<GetService<App, Path>>
|
|
113
113
|
export type InferPatchDataFromPath<
|
|
114
114
|
App extends Application,
|
|
115
115
|
Path extends string,
|
|
116
|
-
> = InferPatchData<GetService<App, Path
|
|
116
|
+
> = InferPatchData<GetService<App, Path>>
|
|
117
117
|
|
|
118
118
|
export type InferUpdateResultFromPath<
|
|
119
119
|
App extends Application,
|
|
120
120
|
Path extends string,
|
|
121
|
-
> = InferUpdateResult<GetService<App, Path
|
|
121
|
+
> = InferUpdateResult<GetService<App, Path>>
|
|
122
122
|
export type InferPatchResultFromPath<
|
|
123
123
|
App extends Application,
|
|
124
124
|
Path extends string,
|
|
125
125
|
IdOrNullable = any,
|
|
126
|
-
> = InferPatchResult<GetService<App, Path>, IdOrNullable
|
|
126
|
+
> = InferPatchResult<GetService<App, Path>, IdOrNullable>
|
|
127
127
|
|
|
128
128
|
export type InferRemoveResultFromPath<
|
|
129
129
|
App extends Application,
|
|
130
130
|
Path extends string,
|
|
131
131
|
IdOrNullable = any,
|
|
132
|
-
> = InferRemoveResult<GetService<App, Path>, IdOrNullable
|
|
132
|
+
> = InferRemoveResult<GetService<App, Path>, IdOrNullable>
|
|
133
133
|
|
|
134
134
|
export type InferDataFromPath<
|
|
135
135
|
App extends Application,
|
|
136
136
|
Path extends string,
|
|
137
|
-
Method extends
|
|
138
|
-
> = Method extends
|
|
137
|
+
Method extends 'create' | 'update' | 'patch',
|
|
138
|
+
> = Method extends 'create'
|
|
139
139
|
? InferCreateDataFromPath<App, Path>
|
|
140
|
-
: Method extends
|
|
140
|
+
: Method extends 'update'
|
|
141
141
|
? InferUpdateDataFromPath<App, Path>
|
|
142
|
-
: Method extends
|
|
142
|
+
: Method extends 'patch'
|
|
143
143
|
? InferPatchDataFromPath<App, Path>
|
|
144
|
-
: never
|
|
144
|
+
: never
|
|
145
145
|
|
|
146
146
|
export type InferResultFromPath<
|
|
147
147
|
App extends Application,
|
|
148
148
|
Path extends string,
|
|
149
|
-
Method extends
|
|
150
|
-
> = Method extends
|
|
149
|
+
Method extends 'get' | 'find' | 'create' | 'update' | 'patch' | 'remove',
|
|
150
|
+
> = Method extends 'get'
|
|
151
151
|
? InferGetResultFromPath<App, Path>
|
|
152
|
-
: Method extends
|
|
152
|
+
: Method extends 'find'
|
|
153
153
|
? InferFindResultFromPath<App, Path>
|
|
154
|
-
: Method extends
|
|
154
|
+
: Method extends 'create'
|
|
155
155
|
? InferCreateResultFromPath<App, Path>
|
|
156
|
-
: Method extends
|
|
156
|
+
: Method extends 'update'
|
|
157
157
|
? InferUpdateResultFromPath<App, Path>
|
|
158
|
-
: Method extends
|
|
158
|
+
: Method extends 'patch'
|
|
159
159
|
? InferPatchResultFromPath<App, Path>
|
|
160
|
-
: Method extends
|
|
160
|
+
: Method extends 'remove'
|
|
161
161
|
? InferRemoveResultFromPath<App, Path>
|
|
162
|
-
: never
|
|
162
|
+
: never
|
|
@@ -2,15 +2,15 @@ export const hasOwnProperty = (
|
|
|
2
2
|
obj: Record<string, unknown>,
|
|
3
3
|
...keys: string[]
|
|
4
4
|
): boolean => {
|
|
5
|
-
return keys.some((x) => Object.prototype.hasOwnProperty.call(obj, x))
|
|
6
|
-
}
|
|
5
|
+
return keys.some((x) => Object.prototype.hasOwnProperty.call(obj, x))
|
|
6
|
+
}
|
|
7
7
|
|
|
8
8
|
export const isObject = (item: unknown): boolean =>
|
|
9
|
-
!!item && typeof item ===
|
|
9
|
+
!!item && typeof item === 'object' && !Array.isArray(item)
|
|
10
10
|
|
|
11
11
|
export const isPlainObject = (value: unknown): boolean =>
|
|
12
|
-
isObject(value) && value.constructor === {}.constructor
|
|
12
|
+
isObject(value) && value.constructor === {}.constructor
|
|
13
13
|
|
|
14
14
|
export const isEmpty = (obj: unknown): boolean =>
|
|
15
15
|
[Object, Array].includes((obj || {}).constructor as any) &&
|
|
16
|
-
!Object.keys(obj || {}).length
|
|
16
|
+
!Object.keys(obj || {}).length
|
package/src/utils/defineHooks.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { Application, HookOptions } from
|
|
1
|
+
import type { Application, HookOptions } from '@feathersjs/feathers'
|
|
2
2
|
|
|
3
3
|
export function defineHooks<
|
|
4
4
|
A extends Application = Application,
|
|
5
5
|
S = {
|
|
6
|
-
find: any
|
|
7
|
-
get: any
|
|
8
|
-
create: any
|
|
9
|
-
update: any
|
|
10
|
-
patch: any
|
|
11
|
-
remove: any
|
|
6
|
+
find: any
|
|
7
|
+
get: any
|
|
8
|
+
create: any
|
|
9
|
+
update: any
|
|
10
|
+
patch: any
|
|
11
|
+
remove: any
|
|
12
12
|
},
|
|
13
13
|
Options = HookOptions<A, S>,
|
|
14
14
|
>(hooks: Options): Options {
|
|
15
|
-
return hooks
|
|
15
|
+
return hooks
|
|
16
16
|
}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import type { Query } from
|
|
2
|
-
import _set from
|
|
3
|
-
import { isObject } from
|
|
1
|
+
import type { Query } from '@feathersjs/feathers'
|
|
2
|
+
import _set from 'lodash/set.js'
|
|
3
|
+
import { isObject } from './_utils.internal.js'
|
|
4
4
|
|
|
5
5
|
export function deflattenQuery(query: Query) {
|
|
6
|
-
const result: Query = {}
|
|
6
|
+
const result: Query = {}
|
|
7
7
|
|
|
8
8
|
Object.keys(query).forEach((key) => {
|
|
9
|
-
const value = query[key]
|
|
9
|
+
const value = query[key]
|
|
10
10
|
|
|
11
11
|
if (Array.isArray(value)) {
|
|
12
|
-
_set(result, key, value.map(deflattenQuery))
|
|
13
|
-
return
|
|
12
|
+
_set(result, key, value.map(deflattenQuery))
|
|
13
|
+
return
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
if (isObject(value)) {
|
|
17
|
-
_set(result, key, deflattenQuery(value))
|
|
18
|
-
return
|
|
17
|
+
_set(result, key, deflattenQuery(value))
|
|
18
|
+
return
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
_set(result, key, query[key])
|
|
22
|
-
})
|
|
21
|
+
_set(result, key, query[key])
|
|
22
|
+
})
|
|
23
23
|
|
|
24
|
-
return result
|
|
24
|
+
return result
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
if (import.meta.vitest) {
|
|
28
|
-
const { describe, it, expect } = import.meta.vitest
|
|
28
|
+
const { describe, it, expect } = import.meta.vitest
|
|
29
29
|
|
|
30
|
-
describe(
|
|
31
|
-
it(
|
|
30
|
+
describe('deflattenQuery', () => {
|
|
31
|
+
it('should deflatten a query', () => {
|
|
32
32
|
expect(
|
|
33
33
|
deflattenQuery({
|
|
34
34
|
a: 1,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
'b.c': 1,
|
|
36
|
+
'b.d': 1,
|
|
37
|
+
'e.f.g': 1,
|
|
38
38
|
}),
|
|
39
39
|
).toEqual({
|
|
40
40
|
a: 1,
|
|
@@ -47,14 +47,14 @@ if (import.meta.vitest) {
|
|
|
47
47
|
g: 1,
|
|
48
48
|
},
|
|
49
49
|
},
|
|
50
|
-
})
|
|
51
|
-
})
|
|
52
|
-
})
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
53
|
|
|
54
|
-
it(
|
|
54
|
+
it('should handle operators', () => {
|
|
55
55
|
expect(
|
|
56
56
|
deflattenQuery({
|
|
57
|
-
|
|
57
|
+
'a.b': 1,
|
|
58
58
|
c: {
|
|
59
59
|
$gt: 1,
|
|
60
60
|
$lte: 1,
|
|
@@ -68,21 +68,21 @@ if (import.meta.vitest) {
|
|
|
68
68
|
$gt: 1,
|
|
69
69
|
$lte: 1,
|
|
70
70
|
},
|
|
71
|
-
})
|
|
72
|
-
})
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
73
|
|
|
74
|
-
it(
|
|
74
|
+
it('should handle $or / $and', () => {
|
|
75
75
|
expect(
|
|
76
76
|
deflattenQuery({
|
|
77
|
-
|
|
77
|
+
'a.b': 1,
|
|
78
78
|
$and: [
|
|
79
79
|
{
|
|
80
|
-
|
|
80
|
+
'c.d': 1,
|
|
81
81
|
},
|
|
82
82
|
],
|
|
83
83
|
$or: [
|
|
84
84
|
{
|
|
85
|
-
|
|
85
|
+
'e.f': 1,
|
|
86
86
|
},
|
|
87
87
|
],
|
|
88
88
|
}),
|
|
@@ -104,6 +104,6 @@ if (import.meta.vitest) {
|
|
|
104
104
|
},
|
|
105
105
|
},
|
|
106
106
|
],
|
|
107
|
-
})
|
|
108
|
-
})
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
109
|
}
|