1
- export type DurablePromise = PendingPromise | ResolvedPromise | RejectedPromise | CanceledPromise | TimedoutPromise ;
2
-
3
- export type PendingPromise = {
4
- state : "PENDING" ;
5
- id : string ;
6
- timeout : number ;
7
- param : {
8
- headers : Record < string , string > | undefined ;
9
- data : string | undefined ;
10
- } ;
11
- value : {
12
- headers : undefined ;
13
- data : undefined ;
14
- } ;
15
- createdOn : number ;
16
- completedOn : undefined ;
17
- idempotencyKeyForCreate : string | undefined ;
18
- idempotencyKeyForComplete : undefined ;
19
- tags : Record < string , string > | undefined ;
20
- } ;
21
-
22
- export type ResolvedPromise = {
23
- state : "RESOLVED" ;
24
- id : string ;
25
- timeout : number ;
26
- param : {
27
- headers : Record < string , string > | undefined ;
28
- data : string | undefined ;
29
- } ;
30
- value : {
31
- headers : Record < string , string > | undefined ;
32
- data : string | undefined ;
33
- } ;
34
- createdOn : number ;
35
- completedOn : number ;
36
- idempotencyKeyForCreate : string | undefined ;
37
- idempotencyKeyForComplete : string | undefined ;
38
- tags : Record < string , string > | undefined ;
39
- } ;
40
-
41
- export type RejectedPromise = {
42
- state : "REJECTED" ;
1
+ export type DurablePromiseRecord = {
2
+ state : "PENDING" | "RESOLVED" | "REJECTED" | "REJECTED_CANCELED" | "REJECTED_TIMEDOUT" ;
43
3
id : string ;
44
4
timeout : number ;
45
5
param : {
@@ -51,53 +11,14 @@ export type RejectedPromise = {
51
11
data : string | undefined ;
52
12
} ;
53
13
createdOn : number ;
54
- completedOn : number ;
14
+ completedOn : number | undefined ;
55
15
idempotencyKeyForCreate : string | undefined ;
56
16
idempotencyKeyForComplete : string | undefined ;
57
17
tags : Record < string , string > | undefined ;
58
18
} ;
59
19
60
- export type CanceledPromise = {
61
- state : "REJECTED_CANCELED" ;
62
- id : string ;
63
- timeout : number ;
64
- param : {
65
- headers : Record < string , string > | undefined ;
66
- data : string | undefined ;
67
- } ;
68
- value : {
69
- headers : Record < string , string > | undefined ;
70
- data : string | undefined ;
71
- } ;
72
- createdOn : number ;
73
- completedOn : number ;
74
- idempotencyKeyForCreate : string | undefined ;
75
- idempotencyKeyForComplete : string | undefined ;
76
- tags : Record < string , string > | undefined ;
77
- } ;
78
-
79
- export type TimedoutPromise = {
80
- state : "REJECTED_TIMEDOUT" ;
81
- id : string ;
82
- timeout : number ;
83
- param : {
84
- headers : Record < string , string > | undefined ;
85
- data : string | undefined ;
86
- } ;
87
- value : {
88
- headers : undefined ;
89
- data : undefined ;
90
- } ;
91
- createdOn : number ;
92
- completedOn : number ;
93
- idempotencyKeyForCreate : string | undefined ;
94
- idempotencyKeyForComplete : undefined ;
95
- tags : Record < string , string > | undefined ;
96
- } ;
97
-
98
- // Type guards
99
-
100
- export function isDurablePromise ( p : unknown ) : p is DurablePromise {
20
+ // This is an unsound type guard, we should be more strict in what we call a DurablePromise
21
+ export function isDurablePromiseRecord ( p : unknown ) : p is DurablePromiseRecord {
101
22
return (
102
23
p !== null &&
103
24
typeof p === "object" &&
@@ -107,28 +28,26 @@ export function isDurablePromise(p: unknown): p is DurablePromise {
107
28
) ;
108
29
}
109
30
110
- export function isPendingPromise ( p : unknown ) : p is PendingPromise {
111
- return isDurablePromise ( p ) && p . state === "PENDING" ;
31
+ export function isPendingPromise ( p : DurablePromiseRecord ) : boolean {
32
+ return p . state === "PENDING" ;
112
33
}
113
34
114
- export function isResolvedPromise ( p : unknown ) : p is ResolvedPromise {
115
- return isDurablePromise ( p ) && p . state === "RESOLVED" ;
35
+ export function isResolvedPromise ( p : DurablePromiseRecord ) : boolean {
36
+ return p . state === "RESOLVED" ;
116
37
}
117
38
118
- export function isRejectedPromise ( p : unknown ) : p is RejectedPromise {
119
- return isDurablePromise ( p ) && p . state === "REJECTED" ;
39
+ export function isRejectedPromise ( p : DurablePromiseRecord ) : boolean {
40
+ return p . state === "REJECTED" ;
120
41
}
121
42
122
- export function isCanceledPromise ( p : unknown ) : p is CanceledPromise {
123
- return isDurablePromise ( p ) && p . state === "REJECTED_CANCELED" ;
43
+ export function isCanceledPromise ( p : DurablePromiseRecord ) : boolean {
44
+ return p . state === "REJECTED_CANCELED" ;
124
45
}
125
46
126
- export function isTimedoutPromise ( p : unknown ) : p is TimedoutPromise {
127
- return isDurablePromise ( p ) && p . state === "REJECTED_TIMEDOUT" ;
47
+ export function isTimedoutPromise ( p : DurablePromiseRecord ) : boolean {
48
+ return p . state === "REJECTED_TIMEDOUT" ;
128
49
}
129
50
130
- export function isCompletedPromise (
131
- p : unknown ,
132
- ) : p is ResolvedPromise | RejectedPromise | CanceledPromise | TimedoutPromise {
133
- return isDurablePromise ( p ) && [ "RESOLVED" , "REJECTED" , "REJECTED_CANCELED" , "REJECTED_TIMEDOUT" ] . includes ( p . state ) ;
51
+ export function isCompletedPromise ( p : DurablePromiseRecord ) : boolean {
52
+ return [ "RESOLVED" , "REJECTED" , "REJECTED_CANCELED" , "REJECTED_TIMEDOUT" ] . includes ( p . state ) ;
134
53
}
0 commit comments