@resonatehq/sdk 0.9.6 → 0.10.0
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 +84 -12
- package/dist/clock.d.ts.map +1 -0
- package/dist/clock.js +12 -0
- package/dist/clock.js.map +1 -0
- package/dist/codec.d.ts +11 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/codec.js +115 -0
- package/dist/codec.js.map +1 -0
- package/dist/computation.d.ts +40 -0
- package/dist/computation.d.ts.map +1 -0
- package/dist/computation.js +152 -0
- package/dist/computation.js.map +1 -0
- package/dist/{src/context.d.ts → context.d.ts} +65 -40
- package/dist/context.d.ts.map +1 -0
- package/dist/{src/context.js → context.js} +131 -153
- package/dist/context.js.map +1 -0
- package/dist/core.d.ts +45 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +140 -0
- package/dist/core.js.map +1 -0
- package/dist/coroutine.d.ts +37 -0
- package/dist/coroutine.d.ts.map +1 -0
- package/dist/coroutine.js +258 -0
- package/dist/coroutine.js.map +1 -0
- package/dist/{src/decorator.d.ts → decorator.d.ts} +8 -8
- package/dist/decorator.d.ts.map +1 -0
- package/dist/decorator.js +149 -0
- package/dist/decorator.js.map +1 -0
- package/dist/encryptor.d.ts +10 -0
- package/dist/encryptor.d.ts.map +1 -0
- package/dist/encryptor.js +9 -0
- package/dist/encryptor.js.map +1 -0
- package/dist/{src/exceptions.d.ts → exceptions.d.ts} +4 -1
- package/dist/exceptions.d.ts.map +1 -0
- package/dist/{src/exceptions.js → exceptions.js} +11 -11
- package/dist/exceptions.js.map +1 -0
- package/dist/{src/heartbeat.d.ts → heartbeat.d.ts} +5 -3
- package/dist/heartbeat.d.ts.map +1 -0
- package/dist/heartbeat.js +50 -0
- package/dist/heartbeat.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +33 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +54 -0
- package/dist/logger.js.map +1 -0
- package/dist/network/http.d.ts +82 -0
- package/dist/network/http.d.ts.map +1 -0
- package/dist/network/http.js +339 -0
- package/dist/network/http.js.map +1 -0
- package/dist/network/local.d.ts +179 -0
- package/dist/network/local.d.ts.map +1 -0
- package/dist/network/local.js +1232 -0
- package/dist/network/local.js.map +1 -0
- package/dist/network/network.d.ts +16 -0
- package/dist/network/network.d.ts.map +1 -0
- package/dist/network/network.js +2 -0
- package/dist/network/network.js.map +1 -0
- package/dist/network/types.d.ts +1279 -0
- package/dist/network/types.d.ts.map +1 -0
- package/dist/network/types.js +919 -0
- package/dist/network/types.js.map +1 -0
- package/dist/{src/options.d.ts → options.d.ts} +10 -4
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +32 -0
- package/dist/options.js.map +1 -0
- package/dist/promises.d.ts +41 -0
- package/dist/promises.d.ts.map +1 -0
- package/dist/promises.js +113 -0
- package/dist/promises.js.map +1 -0
- package/dist/{src/registry.d.ts → registry.d.ts} +1 -1
- package/dist/registry.d.ts.map +1 -0
- package/dist/{src/registry.js → registry.js} +6 -13
- package/dist/registry.js.map +1 -0
- package/dist/resonate.d.ts +168 -0
- package/dist/resonate.d.ts.map +1 -0
- package/dist/resonate.js +488 -0
- package/dist/resonate.js.map +1 -0
- package/dist/retries.d.ts.map +1 -0
- package/dist/{src/retries.js → retries.js} +4 -11
- package/dist/retries.js.map +1 -0
- package/dist/schedules.d.ts +22 -0
- package/dist/schedules.d.ts.map +1 -0
- package/dist/schedules.js +65 -0
- package/dist/schedules.js.map +1 -0
- package/dist/trace.d.ts +79 -0
- package/dist/trace.d.ts.map +1 -0
- package/dist/trace.js +224 -0
- package/dist/trace.js.map +1 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/{src/util.d.ts → util.d.ts} +10 -6
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +156 -0
- package/dist/util.js.map +1 -0
- package/package.json +18 -10
- package/dist/dev/network.d.ts +0 -34
- package/dist/dev/network.d.ts.map +0 -1
- package/dist/dev/network.js +0 -115
- package/dist/dev/network.js.map +0 -1
- package/dist/dev/server.d.ts +0 -89
- package/dist/dev/server.d.ts.map +0 -1
- package/dist/dev/server.js +0 -890
- package/dist/dev/server.js.map +0 -1
- package/dist/sim/example-1.d.ts +0 -2
- package/dist/sim/example-1.d.ts.map +0 -1
- package/dist/sim/example-1.js +0 -95
- package/dist/sim/example-1.js.map +0 -1
- package/dist/sim/example-2.d.ts +0 -2
- package/dist/sim/example-2.d.ts.map +0 -1
- package/dist/sim/example-2.js +0 -97
- package/dist/sim/example-2.js.map +0 -1
- package/dist/sim/example-3.d.ts +0 -2
- package/dist/sim/example-3.d.ts.map +0 -1
- package/dist/sim/example-3.js +0 -97
- package/dist/sim/example-3.js.map +0 -1
- package/dist/sim/main.d.ts +0 -14
- package/dist/sim/main.d.ts.map +0 -1
- package/dist/sim/main.js +0 -207
- package/dist/sim/main.js.map +0 -1
- package/dist/sim/src/server.d.ts +0 -15
- package/dist/sim/src/server.d.ts.map +0 -1
- package/dist/sim/src/server.js +0 -85
- package/dist/sim/src/server.js.map +0 -1
- package/dist/sim/src/simulator.d.ts +0 -65
- package/dist/sim/src/simulator.d.ts.map +0 -1
- package/dist/sim/src/simulator.js +0 -236
- package/dist/sim/src/simulator.js.map +0 -1
- package/dist/sim/src/worker.d.ts +0 -23
- package/dist/sim/src/worker.d.ts.map +0 -1
- package/dist/sim/src/worker.js +0 -217
- package/dist/sim/src/worker.js.map +0 -1
- package/dist/src/clock.d.ts.map +0 -1
- package/dist/src/clock.js +0 -17
- package/dist/src/clock.js.map +0 -1
- package/dist/src/computation.d.ts +0 -49
- package/dist/src/computation.d.ts.map +0 -1
- package/dist/src/computation.js +0 -314
- package/dist/src/computation.js.map +0 -1
- package/dist/src/context.d.ts.map +0 -1
- package/dist/src/context.js.map +0 -1
- package/dist/src/core.d.ts +0 -12
- package/dist/src/core.d.ts.map +0 -1
- package/dist/src/core.js +0 -28
- package/dist/src/core.js.map +0 -1
- package/dist/src/coroutine.d.ts +0 -42
- package/dist/src/coroutine.d.ts.map +0 -1
- package/dist/src/coroutine.js +0 -364
- package/dist/src/coroutine.js.map +0 -1
- package/dist/src/decorator.d.ts.map +0 -1
- package/dist/src/decorator.js +0 -220
- package/dist/src/decorator.js.map +0 -1
- package/dist/src/encoder.d.ts +0 -12
- package/dist/src/encoder.d.ts.map +0 -1
- package/dist/src/encoder.js +0 -101
- package/dist/src/encoder.js.map +0 -1
- package/dist/src/encryptor.d.ts +0 -10
- package/dist/src/encryptor.d.ts.map +0 -1
- package/dist/src/encryptor.js +0 -13
- package/dist/src/encryptor.js.map +0 -1
- package/dist/src/exceptions.d.ts.map +0 -1
- package/dist/src/exceptions.js.map +0 -1
- package/dist/src/handler.d.ts +0 -49
- package/dist/src/handler.d.ts.map +0 -1
- package/dist/src/handler.js +0 -316
- package/dist/src/handler.js.map +0 -1
- package/dist/src/heartbeat.d.ts.map +0 -1
- package/dist/src/heartbeat.js +0 -87
- package/dist/src/heartbeat.js.map +0 -1
- package/dist/src/index.d.ts +0 -15
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -61
- package/dist/src/index.js.map +0 -1
- package/dist/src/network/network.d.ts +0 -254
- package/dist/src/network/network.d.ts.map +0 -1
- package/dist/src/network/network.js +0 -4
- package/dist/src/network/network.js.map +0 -1
- package/dist/src/network/remote.d.ts +0 -85
- package/dist/src/network/remote.d.ts.map +0 -1
- package/dist/src/network/remote.js +0 -523
- package/dist/src/network/remote.js.map +0 -1
- package/dist/src/nursery.d.ts +0 -19
- package/dist/src/nursery.d.ts.map +0 -1
- package/dist/src/nursery.js +0 -102
- package/dist/src/nursery.js.map +0 -1
- package/dist/src/options.d.ts.map +0 -1
- package/dist/src/options.js +0 -70
- package/dist/src/options.js.map +0 -1
- package/dist/src/processor/processor.d.ts +0 -12
- package/dist/src/processor/processor.d.ts.map +0 -1
- package/dist/src/processor/processor.js +0 -43
- package/dist/src/processor/processor.js.map +0 -1
- package/dist/src/promises.d.ts +0 -54
- package/dist/src/promises.d.ts.map +0 -1
- package/dist/src/promises.js +0 -169
- package/dist/src/promises.js.map +0 -1
- package/dist/src/registry.d.ts.map +0 -1
- package/dist/src/registry.js.map +0 -1
- package/dist/src/resonate-inner.d.ts +0 -60
- package/dist/src/resonate-inner.d.ts.map +0 -1
- package/dist/src/resonate-inner.js +0 -97
- package/dist/src/resonate-inner.js.map +0 -1
- package/dist/src/resonate.d.ts +0 -341
- package/dist/src/resonate.d.ts.map +0 -1
- package/dist/src/resonate.js +0 -591
- package/dist/src/resonate.js.map +0 -1
- package/dist/src/retries.d.ts.map +0 -1
- package/dist/src/retries.js.map +0 -1
- package/dist/src/schedules.d.ts +0 -19
- package/dist/src/schedules.d.ts.map +0 -1
- package/dist/src/schedules.js +0 -85
- package/dist/src/schedules.js.map +0 -1
- package/dist/src/tasks.d.ts +0 -9
- package/dist/src/tasks.d.ts.map +0 -1
- package/dist/src/tasks.js +0 -61
- package/dist/src/tasks.js.map +0 -1
- package/dist/src/tracer.d.ts +0 -23
- package/dist/src/tracer.d.ts.map +0 -1
- package/dist/src/tracer.js +0 -25
- package/dist/src/tracer.js.map +0 -1
- package/dist/src/types.d.ts +0 -28
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -11
- package/dist/src/types.js.map +0 -1
- package/dist/src/util.d.ts.map +0 -1
- package/dist/src/util.js +0 -120
- package/dist/src/util.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- /package/dist/{src/clock.d.ts → clock.d.ts} +0 -0
- /package/dist/{src/retries.d.ts → retries.d.ts} +0 -0
|
@@ -0,0 +1,919 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// SHARED TYPES
|
|
3
|
+
// =============================================================================
|
|
4
|
+
// =============================================================================
|
|
5
|
+
// TYPE GUARDS
|
|
6
|
+
// =============================================================================
|
|
7
|
+
export function isSuccess(res) {
|
|
8
|
+
return res.head.status === 200;
|
|
9
|
+
}
|
|
10
|
+
export function isRedirect(res) {
|
|
11
|
+
return res.head.status === 300;
|
|
12
|
+
}
|
|
13
|
+
export function isBadRequest(res) {
|
|
14
|
+
return res.head.status === 400;
|
|
15
|
+
}
|
|
16
|
+
export function isUnauthorized(res) {
|
|
17
|
+
return res.head.status === 401;
|
|
18
|
+
}
|
|
19
|
+
export function isForbidden(res) {
|
|
20
|
+
return res.head.status === 403;
|
|
21
|
+
}
|
|
22
|
+
export function isNotFound(res) {
|
|
23
|
+
return res.head.status === 404;
|
|
24
|
+
}
|
|
25
|
+
export function isConflict(res) {
|
|
26
|
+
return res.head.status === 409;
|
|
27
|
+
}
|
|
28
|
+
export function isUnprocessable(res) {
|
|
29
|
+
return res.head.status === 422;
|
|
30
|
+
}
|
|
31
|
+
export function isRateLimited(res) {
|
|
32
|
+
return res.head.status === 429;
|
|
33
|
+
}
|
|
34
|
+
export function isError(res) {
|
|
35
|
+
return res.head.status === 500;
|
|
36
|
+
}
|
|
37
|
+
export function isNotImplemented(res) {
|
|
38
|
+
return res.head.status === 501;
|
|
39
|
+
}
|
|
40
|
+
// =============================================================================
|
|
41
|
+
// TYPE GUARDS - DEBUG TICK ACTION
|
|
42
|
+
// =============================================================================
|
|
43
|
+
export function isDebugTickAction(val) {
|
|
44
|
+
if (typeof val !== "object" || val === null)
|
|
45
|
+
return false;
|
|
46
|
+
const v = val;
|
|
47
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
48
|
+
return false;
|
|
49
|
+
const d = v.data;
|
|
50
|
+
if (v.kind === "promise.settle") {
|
|
51
|
+
return typeof d.id === "string" && (d.state === "rejected_timedout" || d.state === "resolved");
|
|
52
|
+
}
|
|
53
|
+
if (v.kind === "task.release" || v.kind === "task.retry") {
|
|
54
|
+
return typeof d.id === "string" && typeof d.version === "number";
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
// =============================================================================
|
|
59
|
+
// TYPE GUARDS - REQUESTS
|
|
60
|
+
// =============================================================================
|
|
61
|
+
function isRequestHead(val) {
|
|
62
|
+
if (typeof val !== "object" || val === null)
|
|
63
|
+
return false;
|
|
64
|
+
const v = val;
|
|
65
|
+
return (typeof v.corrId === "string" &&
|
|
66
|
+
typeof v.version === "string" &&
|
|
67
|
+
(v.auth === undefined || typeof v.auth === "string") &&
|
|
68
|
+
(v["resonate:debug_time"] === undefined || typeof v["resonate:debug_time"] === "number"));
|
|
69
|
+
}
|
|
70
|
+
export function isPromiseGetReq(val) {
|
|
71
|
+
if (typeof val !== "object" || val === null)
|
|
72
|
+
return false;
|
|
73
|
+
const v = val;
|
|
74
|
+
if (v.kind !== "promise.get" || !isRequestHead(v.head))
|
|
75
|
+
return false;
|
|
76
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
77
|
+
return false;
|
|
78
|
+
return typeof v.data.id === "string";
|
|
79
|
+
}
|
|
80
|
+
export function isPromiseCreateReq(val) {
|
|
81
|
+
if (typeof val !== "object" || val === null)
|
|
82
|
+
return false;
|
|
83
|
+
const v = val;
|
|
84
|
+
if (v.kind !== "promise.create" || !isRequestHead(v.head))
|
|
85
|
+
return false;
|
|
86
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
87
|
+
return false;
|
|
88
|
+
const d = v.data;
|
|
89
|
+
return (typeof d.id === "string" &&
|
|
90
|
+
typeof d.timeoutAt === "number" &&
|
|
91
|
+
isValue(d.param) &&
|
|
92
|
+
typeof d.tags === "object" &&
|
|
93
|
+
d.tags !== null);
|
|
94
|
+
}
|
|
95
|
+
export function isPromiseSettleReq(val) {
|
|
96
|
+
if (typeof val !== "object" || val === null)
|
|
97
|
+
return false;
|
|
98
|
+
const v = val;
|
|
99
|
+
if (v.kind !== "promise.settle" || !isRequestHead(v.head))
|
|
100
|
+
return false;
|
|
101
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
102
|
+
return false;
|
|
103
|
+
const d = v.data;
|
|
104
|
+
return (typeof d.id === "string" &&
|
|
105
|
+
(d.state === "resolved" || d.state === "rejected" || d.state === "rejected_canceled") &&
|
|
106
|
+
isValue(d.value));
|
|
107
|
+
}
|
|
108
|
+
export function isPromiseRegisterCallbackReq(val) {
|
|
109
|
+
if (typeof val !== "object" || val === null)
|
|
110
|
+
return false;
|
|
111
|
+
const v = val;
|
|
112
|
+
if (v.kind !== "promise.register_callback" || !isRequestHead(v.head))
|
|
113
|
+
return false;
|
|
114
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
115
|
+
return false;
|
|
116
|
+
const d = v.data;
|
|
117
|
+
return typeof d.awaited === "string" && typeof d.awaiter === "string";
|
|
118
|
+
}
|
|
119
|
+
export function isPromiseRegisterListenerReq(val) {
|
|
120
|
+
if (typeof val !== "object" || val === null)
|
|
121
|
+
return false;
|
|
122
|
+
const v = val;
|
|
123
|
+
if (v.kind !== "promise.register_listener" || !isRequestHead(v.head))
|
|
124
|
+
return false;
|
|
125
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
126
|
+
return false;
|
|
127
|
+
const d = v.data;
|
|
128
|
+
return typeof d.awaited === "string" && typeof d.address === "string";
|
|
129
|
+
}
|
|
130
|
+
export function isPromiseSearchReq(val) {
|
|
131
|
+
if (typeof val !== "object" || val === null)
|
|
132
|
+
return false;
|
|
133
|
+
const v = val;
|
|
134
|
+
if (v.kind !== "promise.search" || !isRequestHead(v.head))
|
|
135
|
+
return false;
|
|
136
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
137
|
+
return false;
|
|
138
|
+
const d = v.data;
|
|
139
|
+
return ((d.state === undefined ||
|
|
140
|
+
d.state === "pending" ||
|
|
141
|
+
d.state === "resolved" ||
|
|
142
|
+
d.state === "rejected" ||
|
|
143
|
+
d.state === "rejected_canceled" ||
|
|
144
|
+
d.state === "rejected_timedout") &&
|
|
145
|
+
(d.tags === undefined || (typeof d.tags === "object" && d.tags !== null)) &&
|
|
146
|
+
(d.limit === undefined || typeof d.limit === "number") &&
|
|
147
|
+
(d.cursor === undefined || typeof d.cursor === "string"));
|
|
148
|
+
}
|
|
149
|
+
export function isTaskGetReq(val) {
|
|
150
|
+
if (typeof val !== "object" || val === null)
|
|
151
|
+
return false;
|
|
152
|
+
const v = val;
|
|
153
|
+
if (v.kind !== "task.get" || !isRequestHead(v.head))
|
|
154
|
+
return false;
|
|
155
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
156
|
+
return false;
|
|
157
|
+
return typeof v.data.id === "string";
|
|
158
|
+
}
|
|
159
|
+
export function isTaskCreateReq(val) {
|
|
160
|
+
if (typeof val !== "object" || val === null)
|
|
161
|
+
return false;
|
|
162
|
+
const v = val;
|
|
163
|
+
if (v.kind !== "task.create" || !isRequestHead(v.head))
|
|
164
|
+
return false;
|
|
165
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
166
|
+
return false;
|
|
167
|
+
const d = v.data;
|
|
168
|
+
return typeof d.pid === "string" && typeof d.ttl === "number" && isPromiseCreateReq(d.action);
|
|
169
|
+
}
|
|
170
|
+
export function isTaskAcquireReq(val) {
|
|
171
|
+
if (typeof val !== "object" || val === null)
|
|
172
|
+
return false;
|
|
173
|
+
const v = val;
|
|
174
|
+
if (v.kind !== "task.acquire" || !isRequestHead(v.head))
|
|
175
|
+
return false;
|
|
176
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
177
|
+
return false;
|
|
178
|
+
const d = v.data;
|
|
179
|
+
return (typeof d.id === "string" && typeof d.version === "number" && typeof d.pid === "string" && typeof d.ttl === "number");
|
|
180
|
+
}
|
|
181
|
+
export function isTaskReleaseReq(val) {
|
|
182
|
+
if (typeof val !== "object" || val === null)
|
|
183
|
+
return false;
|
|
184
|
+
const v = val;
|
|
185
|
+
if (v.kind !== "task.release" || !isRequestHead(v.head))
|
|
186
|
+
return false;
|
|
187
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
188
|
+
return false;
|
|
189
|
+
const d = v.data;
|
|
190
|
+
return typeof d.id === "string" && typeof d.version === "number";
|
|
191
|
+
}
|
|
192
|
+
export function isTaskSuspendReq(val) {
|
|
193
|
+
if (typeof val !== "object" || val === null)
|
|
194
|
+
return false;
|
|
195
|
+
const v = val;
|
|
196
|
+
if (v.kind !== "task.suspend" || !isRequestHead(v.head))
|
|
197
|
+
return false;
|
|
198
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
199
|
+
return false;
|
|
200
|
+
const d = v.data;
|
|
201
|
+
return (typeof d.id === "string" &&
|
|
202
|
+
typeof d.version === "number" &&
|
|
203
|
+
Array.isArray(d.actions) &&
|
|
204
|
+
d.actions.every(isPromiseRegisterCallbackReq));
|
|
205
|
+
}
|
|
206
|
+
export function isTaskHaltReq(val) {
|
|
207
|
+
if (typeof val !== "object" || val === null)
|
|
208
|
+
return false;
|
|
209
|
+
const v = val;
|
|
210
|
+
if (v.kind !== "task.halt" || !isRequestHead(v.head))
|
|
211
|
+
return false;
|
|
212
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
213
|
+
return false;
|
|
214
|
+
return typeof v.data.id === "string";
|
|
215
|
+
}
|
|
216
|
+
export function isTaskContinueReq(val) {
|
|
217
|
+
if (typeof val !== "object" || val === null)
|
|
218
|
+
return false;
|
|
219
|
+
const v = val;
|
|
220
|
+
if (v.kind !== "task.continue" || !isRequestHead(v.head))
|
|
221
|
+
return false;
|
|
222
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
223
|
+
return false;
|
|
224
|
+
return typeof v.data.id === "string";
|
|
225
|
+
}
|
|
226
|
+
export function isTaskFulfillReq(val) {
|
|
227
|
+
if (typeof val !== "object" || val === null)
|
|
228
|
+
return false;
|
|
229
|
+
const v = val;
|
|
230
|
+
if (v.kind !== "task.fulfill" || !isRequestHead(v.head))
|
|
231
|
+
return false;
|
|
232
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
233
|
+
return false;
|
|
234
|
+
const d = v.data;
|
|
235
|
+
return typeof d.id === "string" && typeof d.version === "number" && isPromiseSettleReq(d.action);
|
|
236
|
+
}
|
|
237
|
+
export function isTaskFenceReq(val) {
|
|
238
|
+
if (typeof val !== "object" || val === null)
|
|
239
|
+
return false;
|
|
240
|
+
const v = val;
|
|
241
|
+
if (v.kind !== "task.fence" || !isRequestHead(v.head))
|
|
242
|
+
return false;
|
|
243
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
244
|
+
return false;
|
|
245
|
+
const d = v.data;
|
|
246
|
+
return (typeof d.id === "string" &&
|
|
247
|
+
typeof d.version === "number" &&
|
|
248
|
+
(isPromiseCreateReq(d.action) || isPromiseSettleReq(d.action)));
|
|
249
|
+
}
|
|
250
|
+
export function isTaskHeartbeatReq(val) {
|
|
251
|
+
if (typeof val !== "object" || val === null)
|
|
252
|
+
return false;
|
|
253
|
+
const v = val;
|
|
254
|
+
if (v.kind !== "task.heartbeat" || !isRequestHead(v.head))
|
|
255
|
+
return false;
|
|
256
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
257
|
+
return false;
|
|
258
|
+
const d = v.data;
|
|
259
|
+
return (typeof d.pid === "string" &&
|
|
260
|
+
Array.isArray(d.tasks) &&
|
|
261
|
+
d.tasks.every((t) => typeof t === "object" &&
|
|
262
|
+
t !== null &&
|
|
263
|
+
typeof t.id === "string" &&
|
|
264
|
+
typeof t.version === "number"));
|
|
265
|
+
}
|
|
266
|
+
export function isTaskSearchReq(val) {
|
|
267
|
+
if (typeof val !== "object" || val === null)
|
|
268
|
+
return false;
|
|
269
|
+
const v = val;
|
|
270
|
+
if (v.kind !== "task.search" || !isRequestHead(v.head))
|
|
271
|
+
return false;
|
|
272
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
273
|
+
return false;
|
|
274
|
+
const d = v.data;
|
|
275
|
+
return ((d.state === undefined ||
|
|
276
|
+
d.state === "pending" ||
|
|
277
|
+
d.state === "acquired" ||
|
|
278
|
+
d.state === "suspended" ||
|
|
279
|
+
d.state === "halted" ||
|
|
280
|
+
d.state === "fulfilled") &&
|
|
281
|
+
(d.limit === undefined || typeof d.limit === "number") &&
|
|
282
|
+
(d.cursor === undefined || typeof d.cursor === "string"));
|
|
283
|
+
}
|
|
284
|
+
export function isScheduleGetReq(val) {
|
|
285
|
+
if (typeof val !== "object" || val === null)
|
|
286
|
+
return false;
|
|
287
|
+
const v = val;
|
|
288
|
+
if (v.kind !== "schedule.get" || !isRequestHead(v.head))
|
|
289
|
+
return false;
|
|
290
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
291
|
+
return false;
|
|
292
|
+
return typeof v.data.id === "string";
|
|
293
|
+
}
|
|
294
|
+
export function isScheduleCreateReq(val) {
|
|
295
|
+
if (typeof val !== "object" || val === null)
|
|
296
|
+
return false;
|
|
297
|
+
const v = val;
|
|
298
|
+
if (v.kind !== "schedule.create" || !isRequestHead(v.head))
|
|
299
|
+
return false;
|
|
300
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
301
|
+
return false;
|
|
302
|
+
const d = v.data;
|
|
303
|
+
return (typeof d.id === "string" &&
|
|
304
|
+
typeof d.cron === "string" &&
|
|
305
|
+
typeof d.promiseId === "string" &&
|
|
306
|
+
typeof d.promiseTimeout === "number" &&
|
|
307
|
+
isValue(d.promiseParam) &&
|
|
308
|
+
typeof d.promiseTags === "object" &&
|
|
309
|
+
d.promiseTags !== null);
|
|
310
|
+
}
|
|
311
|
+
export function isScheduleDeleteReq(val) {
|
|
312
|
+
if (typeof val !== "object" || val === null)
|
|
313
|
+
return false;
|
|
314
|
+
const v = val;
|
|
315
|
+
if (v.kind !== "schedule.delete" || !isRequestHead(v.head))
|
|
316
|
+
return false;
|
|
317
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
318
|
+
return false;
|
|
319
|
+
return typeof v.data.id === "string";
|
|
320
|
+
}
|
|
321
|
+
export function isScheduleSearchReq(val) {
|
|
322
|
+
if (typeof val !== "object" || val === null)
|
|
323
|
+
return false;
|
|
324
|
+
const v = val;
|
|
325
|
+
if (v.kind !== "schedule.search" || !isRequestHead(v.head))
|
|
326
|
+
return false;
|
|
327
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
328
|
+
return false;
|
|
329
|
+
const d = v.data;
|
|
330
|
+
return ((d.tags === undefined || (typeof d.tags === "object" && d.tags !== null)) &&
|
|
331
|
+
(d.limit === undefined || typeof d.limit === "number") &&
|
|
332
|
+
(d.cursor === undefined || typeof d.cursor === "string"));
|
|
333
|
+
}
|
|
334
|
+
export function isDebugStartReq(val) {
|
|
335
|
+
if (typeof val !== "object" || val === null)
|
|
336
|
+
return false;
|
|
337
|
+
const v = val;
|
|
338
|
+
return v.kind === "debug.start" && isRequestHead(v.head) && typeof v.data === "object" && v.data !== null;
|
|
339
|
+
}
|
|
340
|
+
export function isDebugResetReq(val) {
|
|
341
|
+
if (typeof val !== "object" || val === null)
|
|
342
|
+
return false;
|
|
343
|
+
const v = val;
|
|
344
|
+
return v.kind === "debug.reset" && isRequestHead(v.head) && typeof v.data === "object" && v.data !== null;
|
|
345
|
+
}
|
|
346
|
+
export function isDebugTickReq(val) {
|
|
347
|
+
if (typeof val !== "object" || val === null)
|
|
348
|
+
return false;
|
|
349
|
+
const v = val;
|
|
350
|
+
if (v.kind !== "debug.tick" || !isRequestHead(v.head))
|
|
351
|
+
return false;
|
|
352
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
353
|
+
return false;
|
|
354
|
+
return typeof v.data.time === "number";
|
|
355
|
+
}
|
|
356
|
+
export function isDebugSnapReq(val) {
|
|
357
|
+
if (typeof val !== "object" || val === null)
|
|
358
|
+
return false;
|
|
359
|
+
const v = val;
|
|
360
|
+
return v.kind === "debug.snap" && isRequestHead(v.head) && typeof v.data === "object" && v.data !== null;
|
|
361
|
+
}
|
|
362
|
+
export function isDebugStopReq(val) {
|
|
363
|
+
if (typeof val !== "object" || val === null)
|
|
364
|
+
return false;
|
|
365
|
+
const v = val;
|
|
366
|
+
return v.kind === "debug.stop" && isRequestHead(v.head) && typeof v.data === "object" && v.data !== null;
|
|
367
|
+
}
|
|
368
|
+
export function isRequest(val) {
|
|
369
|
+
return (isPromiseGetReq(val) ||
|
|
370
|
+
isPromiseCreateReq(val) ||
|
|
371
|
+
isPromiseSettleReq(val) ||
|
|
372
|
+
isPromiseRegisterCallbackReq(val) ||
|
|
373
|
+
isPromiseRegisterListenerReq(val) ||
|
|
374
|
+
isPromiseSearchReq(val) ||
|
|
375
|
+
isTaskGetReq(val) ||
|
|
376
|
+
isTaskCreateReq(val) ||
|
|
377
|
+
isTaskAcquireReq(val) ||
|
|
378
|
+
isTaskReleaseReq(val) ||
|
|
379
|
+
isTaskSuspendReq(val) ||
|
|
380
|
+
isTaskHaltReq(val) ||
|
|
381
|
+
isTaskContinueReq(val) ||
|
|
382
|
+
isTaskFulfillReq(val) ||
|
|
383
|
+
isTaskFenceReq(val) ||
|
|
384
|
+
isTaskHeartbeatReq(val) ||
|
|
385
|
+
isTaskSearchReq(val) ||
|
|
386
|
+
isScheduleGetReq(val) ||
|
|
387
|
+
isScheduleCreateReq(val) ||
|
|
388
|
+
isScheduleDeleteReq(val) ||
|
|
389
|
+
isScheduleSearchReq(val) ||
|
|
390
|
+
isDebugStartReq(val) ||
|
|
391
|
+
isDebugResetReq(val) ||
|
|
392
|
+
isDebugTickReq(val) ||
|
|
393
|
+
isDebugSnapReq(val) ||
|
|
394
|
+
isDebugStopReq(val));
|
|
395
|
+
}
|
|
396
|
+
// =============================================================================
|
|
397
|
+
// TYPE GUARDS - RESPONSES
|
|
398
|
+
// =============================================================================
|
|
399
|
+
function isResponseHead(val) {
|
|
400
|
+
if (typeof val !== "object" || val === null)
|
|
401
|
+
return false;
|
|
402
|
+
const v = val;
|
|
403
|
+
return typeof v.corrId === "string" && typeof v.status === "number" && typeof v.version === "string";
|
|
404
|
+
}
|
|
405
|
+
export function isPromiseGetRes(val) {
|
|
406
|
+
if (typeof val !== "object" || val === null)
|
|
407
|
+
return false;
|
|
408
|
+
const v = val;
|
|
409
|
+
if (v.kind !== "promise.get" || !isResponseHead(v.head))
|
|
410
|
+
return false;
|
|
411
|
+
const { status } = v.head;
|
|
412
|
+
if (status === 200) {
|
|
413
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
414
|
+
return false;
|
|
415
|
+
return isPromiseRecord(v.data.promise);
|
|
416
|
+
}
|
|
417
|
+
return typeof v.data === "string";
|
|
418
|
+
}
|
|
419
|
+
export function isPromiseCreateRes(val) {
|
|
420
|
+
if (typeof val !== "object" || val === null)
|
|
421
|
+
return false;
|
|
422
|
+
const v = val;
|
|
423
|
+
if (v.kind !== "promise.create" || !isResponseHead(v.head))
|
|
424
|
+
return false;
|
|
425
|
+
const { status } = v.head;
|
|
426
|
+
if (status === 200) {
|
|
427
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
428
|
+
return false;
|
|
429
|
+
return isPromiseRecord(v.data.promise);
|
|
430
|
+
}
|
|
431
|
+
return typeof v.data === "string";
|
|
432
|
+
}
|
|
433
|
+
export function isPromiseSettleRes(val) {
|
|
434
|
+
if (typeof val !== "object" || val === null)
|
|
435
|
+
return false;
|
|
436
|
+
const v = val;
|
|
437
|
+
if (v.kind !== "promise.settle" || !isResponseHead(v.head))
|
|
438
|
+
return false;
|
|
439
|
+
const { status } = v.head;
|
|
440
|
+
if (status === 200) {
|
|
441
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
442
|
+
return false;
|
|
443
|
+
return isPromiseRecord(v.data.promise);
|
|
444
|
+
}
|
|
445
|
+
return typeof v.data === "string";
|
|
446
|
+
}
|
|
447
|
+
export function isPromiseRegisterCallbackRes(val) {
|
|
448
|
+
if (typeof val !== "object" || val === null)
|
|
449
|
+
return false;
|
|
450
|
+
const v = val;
|
|
451
|
+
if (v.kind !== "promise.register_callback" || !isResponseHead(v.head))
|
|
452
|
+
return false;
|
|
453
|
+
const { status } = v.head;
|
|
454
|
+
if (status === 200) {
|
|
455
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
456
|
+
return false;
|
|
457
|
+
return isPromiseRecord(v.data.promise);
|
|
458
|
+
}
|
|
459
|
+
return typeof v.data === "string";
|
|
460
|
+
}
|
|
461
|
+
export function isPromiseRegisterListenerRes(val) {
|
|
462
|
+
if (typeof val !== "object" || val === null)
|
|
463
|
+
return false;
|
|
464
|
+
const v = val;
|
|
465
|
+
if (v.kind !== "promise.register_listener" || !isResponseHead(v.head))
|
|
466
|
+
return false;
|
|
467
|
+
const { status } = v.head;
|
|
468
|
+
if (status === 200) {
|
|
469
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
470
|
+
return false;
|
|
471
|
+
return isPromiseRecord(v.data.promise);
|
|
472
|
+
}
|
|
473
|
+
return typeof v.data === "string";
|
|
474
|
+
}
|
|
475
|
+
export function isPromiseSearchRes(val) {
|
|
476
|
+
if (typeof val !== "object" || val === null)
|
|
477
|
+
return false;
|
|
478
|
+
const v = val;
|
|
479
|
+
if (v.kind !== "promise.search" || !isResponseHead(v.head))
|
|
480
|
+
return false;
|
|
481
|
+
const { status } = v.head;
|
|
482
|
+
if (status === 200) {
|
|
483
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
484
|
+
return false;
|
|
485
|
+
const d = v.data;
|
|
486
|
+
return (Array.isArray(d.promises) &&
|
|
487
|
+
d.promises.every(isPromiseRecord) &&
|
|
488
|
+
(d.cursor === undefined || typeof d.cursor === "string"));
|
|
489
|
+
}
|
|
490
|
+
return typeof v.data === "string";
|
|
491
|
+
}
|
|
492
|
+
export function isTaskGetRes(val) {
|
|
493
|
+
if (typeof val !== "object" || val === null)
|
|
494
|
+
return false;
|
|
495
|
+
const v = val;
|
|
496
|
+
if (v.kind !== "task.get" || !isResponseHead(v.head))
|
|
497
|
+
return false;
|
|
498
|
+
const { status } = v.head;
|
|
499
|
+
if (status === 200) {
|
|
500
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
501
|
+
return false;
|
|
502
|
+
return isTaskRecord(v.data.task);
|
|
503
|
+
}
|
|
504
|
+
return typeof v.data === "string";
|
|
505
|
+
}
|
|
506
|
+
export function isTaskCreateRes(val) {
|
|
507
|
+
if (typeof val !== "object" || val === null)
|
|
508
|
+
return false;
|
|
509
|
+
const v = val;
|
|
510
|
+
if (v.kind !== "task.create" || !isResponseHead(v.head))
|
|
511
|
+
return false;
|
|
512
|
+
const { status } = v.head;
|
|
513
|
+
if (status === 200) {
|
|
514
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
515
|
+
return false;
|
|
516
|
+
const d = v.data;
|
|
517
|
+
return ((d.task === undefined || isTaskRecord(d.task)) &&
|
|
518
|
+
isPromiseRecord(d.promise) &&
|
|
519
|
+
Array.isArray(d.preload) &&
|
|
520
|
+
d.preload.every(isPromiseRecord));
|
|
521
|
+
}
|
|
522
|
+
return typeof v.data === "string";
|
|
523
|
+
}
|
|
524
|
+
export function isTaskAcquireRes(val) {
|
|
525
|
+
if (typeof val !== "object" || val === null)
|
|
526
|
+
return false;
|
|
527
|
+
const v = val;
|
|
528
|
+
if (v.kind !== "task.acquire" || !isResponseHead(v.head))
|
|
529
|
+
return false;
|
|
530
|
+
const { status } = v.head;
|
|
531
|
+
if (status === 200) {
|
|
532
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
533
|
+
return false;
|
|
534
|
+
const d = v.data;
|
|
535
|
+
return isPromiseRecord(d.promise) && Array.isArray(d.preload) && d.preload.every(isPromiseRecord);
|
|
536
|
+
}
|
|
537
|
+
return typeof v.data === "string";
|
|
538
|
+
}
|
|
539
|
+
export function isTaskReleaseRes(val) {
|
|
540
|
+
if (typeof val !== "object" || val === null)
|
|
541
|
+
return false;
|
|
542
|
+
const v = val;
|
|
543
|
+
if (v.kind !== "task.release" || !isResponseHead(v.head))
|
|
544
|
+
return false;
|
|
545
|
+
const { status } = v.head;
|
|
546
|
+
if (status === 200)
|
|
547
|
+
return typeof v.data === "object" && v.data !== null;
|
|
548
|
+
return typeof v.data === "string";
|
|
549
|
+
}
|
|
550
|
+
export function isTaskSuspendRes(val) {
|
|
551
|
+
if (typeof val !== "object" || val === null)
|
|
552
|
+
return false;
|
|
553
|
+
const v = val;
|
|
554
|
+
if (v.kind !== "task.suspend" || !isResponseHead(v.head))
|
|
555
|
+
return false;
|
|
556
|
+
const { status } = v.head;
|
|
557
|
+
if (status === 200)
|
|
558
|
+
return typeof v.data === "object" && v.data !== null;
|
|
559
|
+
if (status === 300) {
|
|
560
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
561
|
+
return false;
|
|
562
|
+
const d = v.data;
|
|
563
|
+
return Array.isArray(d.preload) && d.preload.every(isPromiseRecord);
|
|
564
|
+
}
|
|
565
|
+
return typeof v.data === "string";
|
|
566
|
+
}
|
|
567
|
+
export function isTaskHaltRes(val) {
|
|
568
|
+
if (typeof val !== "object" || val === null)
|
|
569
|
+
return false;
|
|
570
|
+
const v = val;
|
|
571
|
+
if (v.kind !== "task.halt" || !isResponseHead(v.head))
|
|
572
|
+
return false;
|
|
573
|
+
const { status } = v.head;
|
|
574
|
+
if (status === 200)
|
|
575
|
+
return typeof v.data === "object" && v.data !== null;
|
|
576
|
+
return typeof v.data === "string";
|
|
577
|
+
}
|
|
578
|
+
export function isTaskContinueRes(val) {
|
|
579
|
+
if (typeof val !== "object" || val === null)
|
|
580
|
+
return false;
|
|
581
|
+
const v = val;
|
|
582
|
+
if (v.kind !== "task.continue" || !isResponseHead(v.head))
|
|
583
|
+
return false;
|
|
584
|
+
const { status } = v.head;
|
|
585
|
+
if (status === 200)
|
|
586
|
+
return typeof v.data === "object" && v.data !== null;
|
|
587
|
+
return typeof v.data === "string";
|
|
588
|
+
}
|
|
589
|
+
export function isTaskFulfillRes(val) {
|
|
590
|
+
if (typeof val !== "object" || val === null)
|
|
591
|
+
return false;
|
|
592
|
+
const v = val;
|
|
593
|
+
if (v.kind !== "task.fulfill" || !isResponseHead(v.head))
|
|
594
|
+
return false;
|
|
595
|
+
const { status } = v.head;
|
|
596
|
+
if (status === 200) {
|
|
597
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
598
|
+
return false;
|
|
599
|
+
return isPromiseRecord(v.data.promise);
|
|
600
|
+
}
|
|
601
|
+
return typeof v.data === "string";
|
|
602
|
+
}
|
|
603
|
+
export function isTaskFenceRes(val) {
|
|
604
|
+
if (typeof val !== "object" || val === null)
|
|
605
|
+
return false;
|
|
606
|
+
const v = val;
|
|
607
|
+
if (v.kind !== "task.fence" || !isResponseHead(v.head))
|
|
608
|
+
return false;
|
|
609
|
+
const { status } = v.head;
|
|
610
|
+
if (status === 200) {
|
|
611
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
612
|
+
return false;
|
|
613
|
+
const d = v.data;
|
|
614
|
+
return ((isPromiseCreateRes(d.action) || isPromiseSettleRes(d.action)) &&
|
|
615
|
+
Array.isArray(d.preload) &&
|
|
616
|
+
d.preload.every(isPromiseRecord));
|
|
617
|
+
}
|
|
618
|
+
return typeof v.data === "string";
|
|
619
|
+
}
|
|
620
|
+
export function isTaskHeartbeatRes(val) {
|
|
621
|
+
if (typeof val !== "object" || val === null)
|
|
622
|
+
return false;
|
|
623
|
+
const v = val;
|
|
624
|
+
if (v.kind !== "task.heartbeat" || !isResponseHead(v.head))
|
|
625
|
+
return false;
|
|
626
|
+
const { status } = v.head;
|
|
627
|
+
if (status === 200)
|
|
628
|
+
return typeof v.data === "object" && v.data !== null;
|
|
629
|
+
return typeof v.data === "string";
|
|
630
|
+
}
|
|
631
|
+
export function isTaskSearchRes(val) {
|
|
632
|
+
if (typeof val !== "object" || val === null)
|
|
633
|
+
return false;
|
|
634
|
+
const v = val;
|
|
635
|
+
if (v.kind !== "task.search" || !isResponseHead(v.head))
|
|
636
|
+
return false;
|
|
637
|
+
const { status } = v.head;
|
|
638
|
+
if (status === 200) {
|
|
639
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
640
|
+
return false;
|
|
641
|
+
const d = v.data;
|
|
642
|
+
return (Array.isArray(d.tasks) &&
|
|
643
|
+
d.tasks.every(isTaskRecord) &&
|
|
644
|
+
(d.cursor === undefined || typeof d.cursor === "string"));
|
|
645
|
+
}
|
|
646
|
+
return typeof v.data === "string";
|
|
647
|
+
}
|
|
648
|
+
export function isScheduleGetRes(val) {
|
|
649
|
+
if (typeof val !== "object" || val === null)
|
|
650
|
+
return false;
|
|
651
|
+
const v = val;
|
|
652
|
+
if (v.kind !== "schedule.get" || !isResponseHead(v.head))
|
|
653
|
+
return false;
|
|
654
|
+
const { status } = v.head;
|
|
655
|
+
if (status === 200) {
|
|
656
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
657
|
+
return false;
|
|
658
|
+
return isScheduleRecord(v.data.schedule);
|
|
659
|
+
}
|
|
660
|
+
return typeof v.data === "string";
|
|
661
|
+
}
|
|
662
|
+
export function isScheduleCreateRes(val) {
|
|
663
|
+
if (typeof val !== "object" || val === null)
|
|
664
|
+
return false;
|
|
665
|
+
const v = val;
|
|
666
|
+
if (v.kind !== "schedule.create" || !isResponseHead(v.head))
|
|
667
|
+
return false;
|
|
668
|
+
const { status } = v.head;
|
|
669
|
+
if (status === 200) {
|
|
670
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
671
|
+
return false;
|
|
672
|
+
return isScheduleRecord(v.data.schedule);
|
|
673
|
+
}
|
|
674
|
+
return typeof v.data === "string";
|
|
675
|
+
}
|
|
676
|
+
export function isScheduleDeleteRes(val) {
|
|
677
|
+
if (typeof val !== "object" || val === null)
|
|
678
|
+
return false;
|
|
679
|
+
const v = val;
|
|
680
|
+
if (v.kind !== "schedule.delete" || !isResponseHead(v.head))
|
|
681
|
+
return false;
|
|
682
|
+
const { status } = v.head;
|
|
683
|
+
if (status === 200)
|
|
684
|
+
return typeof v.data === "object" && v.data !== null;
|
|
685
|
+
return typeof v.data === "string";
|
|
686
|
+
}
|
|
687
|
+
export function isScheduleSearchRes(val) {
|
|
688
|
+
if (typeof val !== "object" || val === null)
|
|
689
|
+
return false;
|
|
690
|
+
const v = val;
|
|
691
|
+
if (v.kind !== "schedule.search" || !isResponseHead(v.head))
|
|
692
|
+
return false;
|
|
693
|
+
const { status } = v.head;
|
|
694
|
+
if (status === 200) {
|
|
695
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
696
|
+
return false;
|
|
697
|
+
const d = v.data;
|
|
698
|
+
return (Array.isArray(d.schedules) &&
|
|
699
|
+
d.schedules.every(isScheduleRecord) &&
|
|
700
|
+
(d.cursor === undefined || typeof d.cursor === "string"));
|
|
701
|
+
}
|
|
702
|
+
return typeof v.data === "string";
|
|
703
|
+
}
|
|
704
|
+
export function isDebugStartRes(val) {
|
|
705
|
+
if (typeof val !== "object" || val === null)
|
|
706
|
+
return false;
|
|
707
|
+
const v = val;
|
|
708
|
+
if (v.kind !== "debug.start" || !isResponseHead(v.head))
|
|
709
|
+
return false;
|
|
710
|
+
const { status } = v.head;
|
|
711
|
+
if (status === 200)
|
|
712
|
+
return typeof v.data === "object" && v.data !== null;
|
|
713
|
+
return typeof v.data === "string";
|
|
714
|
+
}
|
|
715
|
+
export function isDebugResetRes(val) {
|
|
716
|
+
if (typeof val !== "object" || val === null)
|
|
717
|
+
return false;
|
|
718
|
+
const v = val;
|
|
719
|
+
if (v.kind !== "debug.reset" || !isResponseHead(v.head))
|
|
720
|
+
return false;
|
|
721
|
+
const { status } = v.head;
|
|
722
|
+
if (status === 200)
|
|
723
|
+
return typeof v.data === "object" && v.data !== null;
|
|
724
|
+
return typeof v.data === "string";
|
|
725
|
+
}
|
|
726
|
+
export function isDebugTickRes(val) {
|
|
727
|
+
if (typeof val !== "object" || val === null)
|
|
728
|
+
return false;
|
|
729
|
+
const v = val;
|
|
730
|
+
if (v.kind !== "debug.tick" || !isResponseHead(v.head))
|
|
731
|
+
return false;
|
|
732
|
+
const { status } = v.head;
|
|
733
|
+
if (status === 200) {
|
|
734
|
+
return Array.isArray(v.data) && v.data.every(isDebugTickAction);
|
|
735
|
+
}
|
|
736
|
+
return typeof v.data === "string";
|
|
737
|
+
}
|
|
738
|
+
export function isDebugSnapRes(val) {
|
|
739
|
+
if (typeof val !== "object" || val === null)
|
|
740
|
+
return false;
|
|
741
|
+
const v = val;
|
|
742
|
+
if (v.kind !== "debug.snap" || !isResponseHead(v.head))
|
|
743
|
+
return false;
|
|
744
|
+
const { status } = v.head;
|
|
745
|
+
if (status === 200) {
|
|
746
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
747
|
+
return false;
|
|
748
|
+
const d = v.data;
|
|
749
|
+
return (Array.isArray(d.promises) &&
|
|
750
|
+
d.promises.every(isPromiseRecord) &&
|
|
751
|
+
Array.isArray(d.promiseTimeouts) &&
|
|
752
|
+
d.promiseTimeouts.every((t) => typeof t === "object" &&
|
|
753
|
+
t !== null &&
|
|
754
|
+
typeof t.id === "string" &&
|
|
755
|
+
typeof t.timeout === "number") &&
|
|
756
|
+
Array.isArray(d.callbacks) &&
|
|
757
|
+
d.callbacks.every((c) => typeof c === "object" &&
|
|
758
|
+
c !== null &&
|
|
759
|
+
typeof c.awaiter === "string" &&
|
|
760
|
+
typeof c.awaited === "string") &&
|
|
761
|
+
(d.listeners === undefined ||
|
|
762
|
+
(Array.isArray(d.listeners) &&
|
|
763
|
+
d.listeners.every((l) => typeof l === "object" &&
|
|
764
|
+
l !== null &&
|
|
765
|
+
typeof l.id === "string" &&
|
|
766
|
+
typeof l.address === "string"))) &&
|
|
767
|
+
Array.isArray(d.tasks) &&
|
|
768
|
+
d.tasks.every(isTaskRecord) &&
|
|
769
|
+
Array.isArray(d.taskTimeouts) &&
|
|
770
|
+
d.taskTimeouts.every((t) => typeof t === "object" &&
|
|
771
|
+
t !== null &&
|
|
772
|
+
typeof t.id === "string" &&
|
|
773
|
+
typeof t.type === "number" &&
|
|
774
|
+
typeof t.timeout === "number") &&
|
|
775
|
+
Array.isArray(d.messages) &&
|
|
776
|
+
d.messages.every((m) => typeof m === "object" &&
|
|
777
|
+
m !== null &&
|
|
778
|
+
typeof m.address === "string" &&
|
|
779
|
+
isMessage(m.message)));
|
|
780
|
+
}
|
|
781
|
+
return typeof v.data === "string";
|
|
782
|
+
}
|
|
783
|
+
export function isDebugStopRes(val) {
|
|
784
|
+
if (typeof val !== "object" || val === null)
|
|
785
|
+
return false;
|
|
786
|
+
const v = val;
|
|
787
|
+
if (v.kind !== "debug.stop" || !isResponseHead(v.head))
|
|
788
|
+
return false;
|
|
789
|
+
const { status } = v.head;
|
|
790
|
+
if (status === 200)
|
|
791
|
+
return typeof v.data === "object" && v.data !== null;
|
|
792
|
+
return typeof v.data === "string";
|
|
793
|
+
}
|
|
794
|
+
export function isResponse(val) {
|
|
795
|
+
return (isPromiseGetRes(val) ||
|
|
796
|
+
isPromiseCreateRes(val) ||
|
|
797
|
+
isPromiseSettleRes(val) ||
|
|
798
|
+
isPromiseRegisterCallbackRes(val) ||
|
|
799
|
+
isPromiseRegisterListenerRes(val) ||
|
|
800
|
+
isPromiseSearchRes(val) ||
|
|
801
|
+
isTaskGetRes(val) ||
|
|
802
|
+
isTaskCreateRes(val) ||
|
|
803
|
+
isTaskAcquireRes(val) ||
|
|
804
|
+
isTaskReleaseRes(val) ||
|
|
805
|
+
isTaskSuspendRes(val) ||
|
|
806
|
+
isTaskHaltRes(val) ||
|
|
807
|
+
isTaskContinueRes(val) ||
|
|
808
|
+
isTaskFulfillRes(val) ||
|
|
809
|
+
isTaskFenceRes(val) ||
|
|
810
|
+
isTaskHeartbeatRes(val) ||
|
|
811
|
+
isTaskSearchRes(val) ||
|
|
812
|
+
isScheduleGetRes(val) ||
|
|
813
|
+
isScheduleCreateRes(val) ||
|
|
814
|
+
isScheduleDeleteRes(val) ||
|
|
815
|
+
isScheduleSearchRes(val) ||
|
|
816
|
+
isDebugStartRes(val) ||
|
|
817
|
+
isDebugResetRes(val) ||
|
|
818
|
+
isDebugTickRes(val) ||
|
|
819
|
+
isDebugSnapRes(val) ||
|
|
820
|
+
isDebugStopRes(val));
|
|
821
|
+
}
|
|
822
|
+
// =============================================================================
|
|
823
|
+
// TYPE GUARDS - RECORDS
|
|
824
|
+
// =============================================================================
|
|
825
|
+
export function isValue(val) {
|
|
826
|
+
if (typeof val !== "object" || val === null)
|
|
827
|
+
return false;
|
|
828
|
+
const v = val;
|
|
829
|
+
if (v.headers !== undefined && (typeof v.headers !== "object" || v.headers === null))
|
|
830
|
+
return false;
|
|
831
|
+
if (v.data !== undefined && typeof v.data !== "string")
|
|
832
|
+
return false;
|
|
833
|
+
return true;
|
|
834
|
+
}
|
|
835
|
+
export function isPromiseRecord(val) {
|
|
836
|
+
if (typeof val !== "object" || val === null)
|
|
837
|
+
return false;
|
|
838
|
+
const v = val;
|
|
839
|
+
return (typeof v.id === "string" &&
|
|
840
|
+
(v.state === "pending" ||
|
|
841
|
+
v.state === "resolved" ||
|
|
842
|
+
v.state === "rejected" ||
|
|
843
|
+
v.state === "rejected_canceled" ||
|
|
844
|
+
v.state === "rejected_timedout") &&
|
|
845
|
+
isValue(v.param) &&
|
|
846
|
+
isValue(v.value) &&
|
|
847
|
+
typeof v.tags === "object" &&
|
|
848
|
+
v.tags !== null &&
|
|
849
|
+
typeof v.timeoutAt === "number" &&
|
|
850
|
+
typeof v.createdAt === "number" &&
|
|
851
|
+
(v.settledAt === undefined || typeof v.settledAt === "number"));
|
|
852
|
+
}
|
|
853
|
+
export function isTaskRecord(val) {
|
|
854
|
+
if (typeof val !== "object" || val === null)
|
|
855
|
+
return false;
|
|
856
|
+
const v = val;
|
|
857
|
+
return (typeof v.id === "string" &&
|
|
858
|
+
(v.state === "pending" ||
|
|
859
|
+
v.state === "acquired" ||
|
|
860
|
+
v.state === "suspended" ||
|
|
861
|
+
v.state === "halted" ||
|
|
862
|
+
v.state === "fulfilled") &&
|
|
863
|
+
typeof v.version === "number" &&
|
|
864
|
+
(v.ttl === undefined || typeof v.ttl === "number") &&
|
|
865
|
+
(v.pid === undefined || typeof v.pid === "string") &&
|
|
866
|
+
(Array.isArray(v.resumes) || typeof v.resumes === "number" || typeof v.resumes === "boolean"));
|
|
867
|
+
}
|
|
868
|
+
export function isScheduleRecord(val) {
|
|
869
|
+
if (typeof val !== "object" || val === null)
|
|
870
|
+
return false;
|
|
871
|
+
const v = val;
|
|
872
|
+
return (typeof v.id === "string" &&
|
|
873
|
+
typeof v.cron === "string" &&
|
|
874
|
+
typeof v.promiseId === "string" &&
|
|
875
|
+
typeof v.promiseTimeout === "number" &&
|
|
876
|
+
isValue(v.promiseParam) &&
|
|
877
|
+
typeof v.promiseTags === "object" &&
|
|
878
|
+
v.promiseTags !== null &&
|
|
879
|
+
typeof v.createdAt === "number" &&
|
|
880
|
+
typeof v.nextRunAt === "number" &&
|
|
881
|
+
(v.lastRunAt === undefined || typeof v.lastRunAt === "number"));
|
|
882
|
+
}
|
|
883
|
+
// =============================================================================
|
|
884
|
+
// TYPE GUARDS - MESSAGES
|
|
885
|
+
// =============================================================================
|
|
886
|
+
function isMessageHead(val) {
|
|
887
|
+
if (typeof val !== "object" || val === null)
|
|
888
|
+
return false;
|
|
889
|
+
const v = val;
|
|
890
|
+
return v.serverUrl === undefined || typeof v.serverUrl === "string";
|
|
891
|
+
}
|
|
892
|
+
export function isExecuteMsg(val) {
|
|
893
|
+
if (typeof val !== "object" || val === null)
|
|
894
|
+
return false;
|
|
895
|
+
const v = val;
|
|
896
|
+
if (v.kind !== "execute" || !isMessageHead(v.head))
|
|
897
|
+
return false;
|
|
898
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
899
|
+
return false;
|
|
900
|
+
const d = v.data;
|
|
901
|
+
if (typeof d.task !== "object" || d.task === null)
|
|
902
|
+
return false;
|
|
903
|
+
const task = d.task;
|
|
904
|
+
return typeof task.id === "string" && typeof task.version === "number";
|
|
905
|
+
}
|
|
906
|
+
export function isUnblockMsg(val) {
|
|
907
|
+
if (typeof val !== "object" || val === null)
|
|
908
|
+
return false;
|
|
909
|
+
const v = val;
|
|
910
|
+
if (v.kind !== "unblock" || !isMessageHead(v.head))
|
|
911
|
+
return false;
|
|
912
|
+
if (typeof v.data !== "object" || v.data === null)
|
|
913
|
+
return false;
|
|
914
|
+
return isPromiseRecord(v.data.promise);
|
|
915
|
+
}
|
|
916
|
+
export function isMessage(val) {
|
|
917
|
+
return isExecuteMsg(val) || isUnblockMsg(val);
|
|
918
|
+
}
|
|
919
|
+
//# sourceMappingURL=types.js.map
|