deno.land / x / domain_functions@v1.2.0 / src / types.ts

نووسراو ببینە
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
86
87
88
89
90
91
92
93
94
95
96
97
98
type ErrorWithMessage = { message: string}
type SuccessResult<T = void> = { success: true data: T errors: [] inputErrors: [] environmentErrors: []}type ErrorResult = { success: false errors: ErrorWithMessage[] inputErrors: SchemaError[] environmentErrors: SchemaError[]}type SchemaError = { path: string[] message: string}
type ErrorData = Omit<ErrorResult, 'success'>
type Result<T = void> = SuccessResult<T> | ErrorResult
type DomainFunction<Output = unknown> = { (input: unknown, environment?: unknown): Promise<Result<Output>>}
type UnpackResult<F extends DomainFunction> = Awaited<ReturnType<F>>type UnpackSuccess<F extends DomainFunction> = Extract< UnpackResult<F>, { success: true }>type UnpackData<F extends DomainFunction> = UnpackSuccess<F>['data']
type MergeObjs<Objs extends unknown[]> = Objs extends [ infer First, ...infer Rest,] ? First & MergeObjs<Rest> : {}
namespace List { type PopList<T extends unknown[]> = T extends [...infer R, unknown] ? R : T type PopItem<T extends unknown[]> = T extends [...unknown[], infer A] ? A : unknown type IntMapItem<L extends unknown[], M extends Mapper> = M & { Value: PopItem<L> Index: PopList<L>['length'] } type IntMapList< MapToType extends Mapper, ListItems extends unknown[], Collected extends unknown[] = [], > = ListItems['length'] extends 0 ? Collected : IntMapList< MapToType, PopList<ListItems>, [IntMapItem<ListItems, MapToType>['Return'], ...Collected] >
export type Mapper<I = unknown, O = unknown> = { Index: number Value: I Return: O } export type Map<M extends Mapper, L extends unknown[]> = IntMapList<M, L, []>}
interface ListToResultData extends List.Mapper<DomainFunction> { Return: UnpackData<this['Value']>}
type Last<T extends readonly unknown[]> = T extends [...infer _I, infer L] ? L : never
export type { DomainFunction, ErrorData, ErrorResult, ErrorWithMessage, Last, List, ListToResultData, MergeObjs, Result, SchemaError, SuccessResult, UnpackData, UnpackResult, UnpackSuccess,}
domain_functions

Version Info

Tagged at
a year ago