-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathresult-base.ts
More file actions
69 lines (62 loc) · 1.55 KB
/
result-base.ts
File metadata and controls
69 lines (62 loc) · 1.55 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
import type {
ResultCode,
ResultCodeClientError,
ResultCodeServerError,
ResultCodes,
} from "./result-code";
/************************************************************
* Abstract results
*
* These are base interfaces that should be extended to
* create concrete result types.
************************************************************/
/**
* Abstract representation of any result.
*/
export interface AbstractResult<TResultCode extends ResultCode> {
/**
* The classification of the result.
*/
resultCode: TResultCode;
}
/**
* Abstract representation of a successful result.
*/
export interface AbstractResultOk<TDataType> extends AbstractResult<typeof ResultCodes.Ok> {
/**
* The data of the result.
*/
data: TDataType;
}
/**
* Abstract representation of an error result.
*/
export interface AbstractResultError<
TResultCode extends ResultCodeServerError | ResultCodeClientError,
TDataType = undefined,
> extends AbstractResult<TResultCode> {
/**
* A description of the error.
*/
errorMessage: string;
/**
* Identifies if it may be relevant to retry the operation.
*
* If `false`, retrying the operation is unlikely to be helpful.
*/
suggestRetry: boolean;
/**
* Optional data associated with the error.
*/
data?: TDataType;
}
/**
* Abstract representation of a loading result.
*/
export interface AbstractResultLoading<TDataType = undefined>
extends AbstractResult<typeof ResultCodes.Loading> {
/**
* Optional data associated with the loading operation.
*/
data?: TDataType;
}