-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
85 lines (70 loc) · 2.32 KB
/
types.ts
File metadata and controls
85 lines (70 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import type { HookContext, NextFunction, Params } from '@feathersjs/feathers'
import type { Promisable } from './internal.utils.js'
export const hookTypes = ['around', 'before', 'after', 'error'] as const
export type HookType = (typeof hookTypes)[number]
export const methodNames = [
'find',
'get',
'create',
'update',
'patch',
'remove',
] as const
export type MethodName = (typeof methodNames)[number] | ({} & string) // allow custom methods
export type TransportName = 'socketio' | 'rest' | 'external' | 'server'
export type ContextFunctionSync<T, H extends HookContext = HookContext> = (
context: H,
) => T
export type ContextFunctionAsync<T, H extends HookContext = HookContext> = (
context: H,
) => Promise<T>
export type ContextFunction<T, H extends HookContext = HookContext> = (
context: H,
) => T | Promise<T>
export type PredicateContextSync<H extends HookContext = HookContext> = (
context: H,
) => boolean
export type PredicateContextAsync<H extends HookContext = HookContext> = (
context: H,
) => Promise<boolean>
export type PredicateFn<H extends HookContext = HookContext> = (
context: H,
) => boolean | Promise<boolean>
export type PredicateItemWithContext<T = any> = (
item: T,
context: HookContext,
) => boolean
export type TransformerFn<
T = Record<string, any>,
H extends HookContext = HookContext,
> = (
item: T,
options: { context: H; i: number },
) => Promisable<T | undefined | void>
export type TransformerInputFn<
T = Record<string, any>,
H extends HookContext = HookContext,
> = (item: T, options: { context: H; i: number }) => Promisable<any>
export type FieldKey<T> =
| (keyof T & string)
| `${Extract<keyof T, string>}.${string}`
export type StringFieldKey<T> =
| {
[K in keyof T & string]: T[K] extends string | null | undefined
? K
: never
}[keyof T & string]
| `${Extract<keyof T, string>}.${string}`
export type DefaultsInput<T extends Record<string, any>> = {
[K in keyof T & string]?: T[K] | (() => T[K])
} & {
[K in `${Extract<keyof T, string>}.${string}`]?: unknown
}
export declare type HookFunction<H extends HookContext = HookContext> = (
context: H,
next?: NextFunction,
) => Promise<H | void> | H | void
export type TransformParamsFn<P extends Params = Params> = (
params: P,
) => P | void
export type DispatchOption = boolean | 'both'