wapi-client 0.15.5 → 0.16.0-beta.1
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/dist/api/base-client.browser.cjs +62 -41
- package/dist/api/base-client.browser.js +62 -41
- package/dist/api/base-client.cjs +62 -41
- package/dist/api/base-client.js +62 -41
- package/dist/api/http-client.browser.cjs +13 -13
- package/dist/api/http-client.browser.js +14 -14
- package/dist/api/http-client.cjs +13 -13
- package/dist/api/http-client.js +14 -14
- package/dist/api/ws-client.browser.cjs +2 -2
- package/dist/api/ws-client.browser.js +2 -2
- package/dist/api/ws-client.cjs +2 -2
- package/dist/api/ws-client.js +2 -2
- package/dist/client-options.schema.zod.browser.cjs +12 -17
- package/dist/client-options.schema.zod.browser.js +12 -17
- package/dist/client-options.schema.zod.cjs +15 -21
- package/dist/client-options.schema.zod.js +12 -17
- package/dist/client.browser.cjs +19 -5
- package/dist/client.browser.js +19 -5
- package/dist/client.cjs +19 -5
- package/dist/client.js +19 -5
- package/dist/lib/env.browser.cjs +1 -1
- package/dist/lib/env.browser.js +1 -1
- package/dist/lib/env.cjs +1 -1
- package/dist/lib/env.js +1 -1
- package/dist/lib/errors.browser.cjs +5 -0
- package/dist/lib/errors.browser.js +5 -0
- package/dist/lib/errors.cjs +5 -0
- package/dist/lib/errors.js +5 -0
- package/dist/lib/utils.browser.cjs +10 -4
- package/dist/lib/utils.browser.js +10 -4
- package/dist/lib/utils.cjs +11 -4
- package/dist/lib/utils.js +10 -4
- package/dist/txs/get-transfer-group/get-transfer-group.schema.zod.browser.cjs +8 -1
- package/dist/txs/get-transfer-group/get-transfer-group.schema.zod.browser.js +8 -1
- package/dist/txs/get-transfer-group/get-transfer-group.schema.zod.cjs +8 -1
- package/dist/txs/get-transfer-group/get-transfer-group.schema.zod.js +8 -1
- package/dist/types/wapi-client.d.ts +667 -52
- package/dist/wapi-client-web.iife.js +7 -7
- package/dist/wapi-client.browser.cjs +4 -6
- package/dist/wapi-client.browser.js +5 -10
- package/dist/wapi-client.cjs +4 -6
- package/dist/wapi-client.iife.js +7 -7
- package/dist/wapi-client.js +5 -10
- package/package.json +2 -2
|
@@ -91,6 +91,7 @@ var BaseClient = class {
|
|
|
91
91
|
__publicField(this, "_error", false);
|
|
92
92
|
__publicField(this, "_sending", /* @__PURE__ */ new Map());
|
|
93
93
|
__publicField(this, "sendingTimeout");
|
|
94
|
+
__publicField(this, "requestTimeout", 12e4);
|
|
94
95
|
this.type = connectionType;
|
|
95
96
|
this._connection = connection;
|
|
96
97
|
this.connectionType = connectionType;
|
|
@@ -132,18 +133,50 @@ var BaseClient = class {
|
|
|
132
133
|
// Will fire this in case we lose connection
|
|
133
134
|
// This is so we can terminate ongoing requests
|
|
134
135
|
_connectionLost() {
|
|
135
|
-
this._requests.forEach((
|
|
136
|
-
|
|
137
|
-
responseObject.stream.destroy(
|
|
138
|
-
new import_errors.StreamError("CONNECTION_LOST", { method: "connectionLost" })
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
this._requests.delete(key);
|
|
136
|
+
this._requests.forEach((requestInfo) => {
|
|
137
|
+
this._fireConnectionLost(requestInfo);
|
|
142
138
|
});
|
|
143
139
|
this.socId = void 0;
|
|
144
140
|
}
|
|
141
|
+
_completeRequest(request, error) {
|
|
142
|
+
const key = request.message.id;
|
|
143
|
+
if (key === null) {
|
|
144
|
+
throw new Error("JSONRPCMessage.id should not be null");
|
|
145
|
+
}
|
|
146
|
+
if (error) {
|
|
147
|
+
if ("error" in request) {
|
|
148
|
+
request.error(error);
|
|
149
|
+
} else if ("stream" in request) {
|
|
150
|
+
request.stream.destroy(error);
|
|
151
|
+
}
|
|
152
|
+
} else if (!request.stream.destroyed) {
|
|
153
|
+
request.stream.push(null);
|
|
154
|
+
}
|
|
155
|
+
clearTimeout(request.requestTimeout);
|
|
156
|
+
clearTimeout(request.sendingTimeout);
|
|
157
|
+
this._requests.delete(key);
|
|
158
|
+
this._sending.delete(key);
|
|
159
|
+
}
|
|
160
|
+
_fireConnectionLost(requestInfo) {
|
|
161
|
+
const error = new import_errors.StreamError("CONNECTION_LOST", {
|
|
162
|
+
method: "connectionLost"
|
|
163
|
+
});
|
|
164
|
+
return this._completeRequest(requestInfo, error);
|
|
165
|
+
}
|
|
166
|
+
_fireSendingTimeout(requestInfo) {
|
|
167
|
+
const error = new import_errors.ConfigError("SENDING_TIMEOUT", {
|
|
168
|
+
timeout: this.sendingTimeout
|
|
169
|
+
});
|
|
170
|
+
return this._completeRequest(requestInfo, error);
|
|
171
|
+
}
|
|
172
|
+
_fireRequestTimeout(requestInfo) {
|
|
173
|
+
const error = new import_errors.ConfigError("REQUEST_TIMEOUT", {
|
|
174
|
+
timeout: this.requestTimeout
|
|
175
|
+
});
|
|
176
|
+
return this._completeRequest(requestInfo, error);
|
|
177
|
+
}
|
|
145
178
|
_handleMessage(incoming) {
|
|
146
|
-
var _a, _b, _c
|
|
179
|
+
var _a, _b, _c;
|
|
147
180
|
if (this.hooks.message) {
|
|
148
181
|
this.hooks.message(incoming);
|
|
149
182
|
}
|
|
@@ -168,16 +201,16 @@ var BaseClient = class {
|
|
|
168
201
|
(0, import_debug.debugLog)("Unexpected JSONRPCResponse", incoming);
|
|
169
202
|
return;
|
|
170
203
|
}
|
|
171
|
-
if (responseMessage.result === import_jsonrpc_enums.JSONRPC.acknowledgement) {
|
|
172
|
-
clearTimeout((_a = this._sending.get(responseMessage.id)) == null ? void 0 : _a.timeout);
|
|
173
|
-
this._sending.delete(responseMessage.id);
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
204
|
const requestInfo = this._requests.get(responseMessage.id);
|
|
177
205
|
if (!requestInfo) {
|
|
178
206
|
(0, import_debug.debugLog)("No Request found for incoming", incoming);
|
|
179
207
|
return;
|
|
180
208
|
}
|
|
209
|
+
if (responseMessage.result === import_jsonrpc_enums.JSONRPC.acknowledgement) {
|
|
210
|
+
clearTimeout(requestInfo.requestTimeout);
|
|
211
|
+
delete requestInfo.requestTimeout;
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
181
214
|
if ("handle" in requestInfo) {
|
|
182
215
|
requestInfo.handle(responseMessage);
|
|
183
216
|
delete requestInfo.handle;
|
|
@@ -187,26 +220,21 @@ var BaseClient = class {
|
|
|
187
220
|
requestInfo.error(responseMessage.error);
|
|
188
221
|
}
|
|
189
222
|
const message = responseMessage;
|
|
190
|
-
if (((
|
|
223
|
+
if (((_a = message.result) == null ? void 0 : _a.type) === import_jsonrpc_enums.JSONRPC.streamPause && "pause" in requestInfo) {
|
|
191
224
|
requestInfo.pause();
|
|
192
225
|
return;
|
|
193
226
|
}
|
|
194
|
-
if (((
|
|
227
|
+
if (((_b = message.result) == null ? void 0 : _b.type) === import_jsonrpc_enums.JSONRPC.streamResume && "resume" in requestInfo) {
|
|
195
228
|
requestInfo.resume();
|
|
196
229
|
return;
|
|
197
230
|
}
|
|
198
231
|
const { stream, start } = requestInfo;
|
|
199
|
-
if (((
|
|
232
|
+
if (((_c = message.result) == null ? void 0 : _c.type) === import_jsonrpc_enums.JSONRPC.streamChunk) {
|
|
200
233
|
stream.push(message.result);
|
|
201
234
|
return;
|
|
202
235
|
}
|
|
203
236
|
stream.push(message);
|
|
204
|
-
|
|
205
|
-
stream.push(null);
|
|
206
|
-
}
|
|
207
|
-
if (message.id) {
|
|
208
|
-
this._requests.delete(message.id);
|
|
209
|
-
}
|
|
237
|
+
this._completeRequest(requestInfo);
|
|
210
238
|
if (this.connectionType === import_wapi_client.WapiClientType.ws) {
|
|
211
239
|
this._send({
|
|
212
240
|
jsonrpc: import_jsonrpc_enums.JSONRPC.version,
|
|
@@ -224,22 +252,6 @@ var BaseClient = class {
|
|
|
224
252
|
// const inputCopy = APIValidators[name](input);
|
|
225
253
|
// return this._sendRaw<Input, Output>(name, inputCopy as Input);
|
|
226
254
|
// }
|
|
227
|
-
_setSending(jsonRpcMessage, stream) {
|
|
228
|
-
if (jsonRpcMessage.id === null) {
|
|
229
|
-
throw new Error("JSONRPCMessage should not be null");
|
|
230
|
-
}
|
|
231
|
-
this._sending.set(jsonRpcMessage.id, __spreadValues({}, this.sendingTimeout && {
|
|
232
|
-
timeout: setTimeout(() => {
|
|
233
|
-
this._sending.delete(jsonRpcMessage.id);
|
|
234
|
-
stream.push({
|
|
235
|
-
error: new import_errors.ConfigError("SENDING_TIMEOUT", {
|
|
236
|
-
timeout: this.sendingTimeout
|
|
237
|
-
}).toJSON()
|
|
238
|
-
});
|
|
239
|
-
this._requests.delete(jsonRpcMessage.id);
|
|
240
|
-
}, this.sendingTimeout)
|
|
241
|
-
}));
|
|
242
|
-
}
|
|
243
255
|
_sendRaw(method, params) {
|
|
244
256
|
const jsonRpcMessage = {
|
|
245
257
|
jsonrpc: import_jsonrpc_enums.JSONRPC.version,
|
|
@@ -260,11 +272,20 @@ var BaseClient = class {
|
|
|
260
272
|
if (this._error) {
|
|
261
273
|
throw this._error;
|
|
262
274
|
}
|
|
263
|
-
|
|
275
|
+
const outboundRequest = __spreadValues(__spreadValues({
|
|
264
276
|
stream,
|
|
265
|
-
start: Date.now()
|
|
277
|
+
start: Date.now(),
|
|
278
|
+
message: jsonRpcMessage
|
|
279
|
+
}, this.sendingTimeout && {
|
|
280
|
+
sendingTimeout: setTimeout(() => {
|
|
281
|
+
this._fireSendingTimeout(outboundRequest);
|
|
282
|
+
}, this.sendingTimeout)
|
|
283
|
+
}), this.requestTimeout && {
|
|
284
|
+
requestTimeout: setTimeout(() => {
|
|
285
|
+
this._fireRequestTimeout(outboundRequest);
|
|
286
|
+
}, this.requestTimeout)
|
|
266
287
|
});
|
|
267
|
-
this.
|
|
288
|
+
this._requests.set(jsonRpcMessage.id, outboundRequest);
|
|
268
289
|
this._send(jsonRpcMessage);
|
|
269
290
|
}));
|
|
270
291
|
}
|
|
@@ -72,6 +72,7 @@ var BaseClient = class {
|
|
|
72
72
|
__publicField(this, "_error", false);
|
|
73
73
|
__publicField(this, "_sending", /* @__PURE__ */ new Map());
|
|
74
74
|
__publicField(this, "sendingTimeout");
|
|
75
|
+
__publicField(this, "requestTimeout", 12e4);
|
|
75
76
|
this.type = connectionType;
|
|
76
77
|
this._connection = connection;
|
|
77
78
|
this.connectionType = connectionType;
|
|
@@ -113,18 +114,50 @@ var BaseClient = class {
|
|
|
113
114
|
// Will fire this in case we lose connection
|
|
114
115
|
// This is so we can terminate ongoing requests
|
|
115
116
|
_connectionLost() {
|
|
116
|
-
this._requests.forEach((
|
|
117
|
-
|
|
118
|
-
responseObject.stream.destroy(
|
|
119
|
-
new StreamError("CONNECTION_LOST", { method: "connectionLost" })
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
this._requests.delete(key);
|
|
117
|
+
this._requests.forEach((requestInfo) => {
|
|
118
|
+
this._fireConnectionLost(requestInfo);
|
|
123
119
|
});
|
|
124
120
|
this.socId = void 0;
|
|
125
121
|
}
|
|
122
|
+
_completeRequest(request, error) {
|
|
123
|
+
const key = request.message.id;
|
|
124
|
+
if (key === null) {
|
|
125
|
+
throw new Error("JSONRPCMessage.id should not be null");
|
|
126
|
+
}
|
|
127
|
+
if (error) {
|
|
128
|
+
if ("error" in request) {
|
|
129
|
+
request.error(error);
|
|
130
|
+
} else if ("stream" in request) {
|
|
131
|
+
request.stream.destroy(error);
|
|
132
|
+
}
|
|
133
|
+
} else if (!request.stream.destroyed) {
|
|
134
|
+
request.stream.push(null);
|
|
135
|
+
}
|
|
136
|
+
clearTimeout(request.requestTimeout);
|
|
137
|
+
clearTimeout(request.sendingTimeout);
|
|
138
|
+
this._requests.delete(key);
|
|
139
|
+
this._sending.delete(key);
|
|
140
|
+
}
|
|
141
|
+
_fireConnectionLost(requestInfo) {
|
|
142
|
+
const error = new StreamError("CONNECTION_LOST", {
|
|
143
|
+
method: "connectionLost"
|
|
144
|
+
});
|
|
145
|
+
return this._completeRequest(requestInfo, error);
|
|
146
|
+
}
|
|
147
|
+
_fireSendingTimeout(requestInfo) {
|
|
148
|
+
const error = new ConfigError("SENDING_TIMEOUT", {
|
|
149
|
+
timeout: this.sendingTimeout
|
|
150
|
+
});
|
|
151
|
+
return this._completeRequest(requestInfo, error);
|
|
152
|
+
}
|
|
153
|
+
_fireRequestTimeout(requestInfo) {
|
|
154
|
+
const error = new ConfigError("REQUEST_TIMEOUT", {
|
|
155
|
+
timeout: this.requestTimeout
|
|
156
|
+
});
|
|
157
|
+
return this._completeRequest(requestInfo, error);
|
|
158
|
+
}
|
|
126
159
|
_handleMessage(incoming) {
|
|
127
|
-
var _a, _b, _c
|
|
160
|
+
var _a, _b, _c;
|
|
128
161
|
if (this.hooks.message) {
|
|
129
162
|
this.hooks.message(incoming);
|
|
130
163
|
}
|
|
@@ -149,16 +182,16 @@ var BaseClient = class {
|
|
|
149
182
|
debugLog("Unexpected JSONRPCResponse", incoming);
|
|
150
183
|
return;
|
|
151
184
|
}
|
|
152
|
-
if (responseMessage.result === JSONRPC.acknowledgement) {
|
|
153
|
-
clearTimeout((_a = this._sending.get(responseMessage.id)) == null ? void 0 : _a.timeout);
|
|
154
|
-
this._sending.delete(responseMessage.id);
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
185
|
const requestInfo = this._requests.get(responseMessage.id);
|
|
158
186
|
if (!requestInfo) {
|
|
159
187
|
debugLog("No Request found for incoming", incoming);
|
|
160
188
|
return;
|
|
161
189
|
}
|
|
190
|
+
if (responseMessage.result === JSONRPC.acknowledgement) {
|
|
191
|
+
clearTimeout(requestInfo.requestTimeout);
|
|
192
|
+
delete requestInfo.requestTimeout;
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
162
195
|
if ("handle" in requestInfo) {
|
|
163
196
|
requestInfo.handle(responseMessage);
|
|
164
197
|
delete requestInfo.handle;
|
|
@@ -168,26 +201,21 @@ var BaseClient = class {
|
|
|
168
201
|
requestInfo.error(responseMessage.error);
|
|
169
202
|
}
|
|
170
203
|
const message = responseMessage;
|
|
171
|
-
if (((
|
|
204
|
+
if (((_a = message.result) == null ? void 0 : _a.type) === JSONRPC.streamPause && "pause" in requestInfo) {
|
|
172
205
|
requestInfo.pause();
|
|
173
206
|
return;
|
|
174
207
|
}
|
|
175
|
-
if (((
|
|
208
|
+
if (((_b = message.result) == null ? void 0 : _b.type) === JSONRPC.streamResume && "resume" in requestInfo) {
|
|
176
209
|
requestInfo.resume();
|
|
177
210
|
return;
|
|
178
211
|
}
|
|
179
212
|
const { stream, start } = requestInfo;
|
|
180
|
-
if (((
|
|
213
|
+
if (((_c = message.result) == null ? void 0 : _c.type) === JSONRPC.streamChunk) {
|
|
181
214
|
stream.push(message.result);
|
|
182
215
|
return;
|
|
183
216
|
}
|
|
184
217
|
stream.push(message);
|
|
185
|
-
|
|
186
|
-
stream.push(null);
|
|
187
|
-
}
|
|
188
|
-
if (message.id) {
|
|
189
|
-
this._requests.delete(message.id);
|
|
190
|
-
}
|
|
218
|
+
this._completeRequest(requestInfo);
|
|
191
219
|
if (this.connectionType === WapiClientType.ws) {
|
|
192
220
|
this._send({
|
|
193
221
|
jsonrpc: JSONRPC.version,
|
|
@@ -205,22 +233,6 @@ var BaseClient = class {
|
|
|
205
233
|
// const inputCopy = APIValidators[name](input);
|
|
206
234
|
// return this._sendRaw<Input, Output>(name, inputCopy as Input);
|
|
207
235
|
// }
|
|
208
|
-
_setSending(jsonRpcMessage, stream) {
|
|
209
|
-
if (jsonRpcMessage.id === null) {
|
|
210
|
-
throw new Error("JSONRPCMessage should not be null");
|
|
211
|
-
}
|
|
212
|
-
this._sending.set(jsonRpcMessage.id, __spreadValues({}, this.sendingTimeout && {
|
|
213
|
-
timeout: setTimeout(() => {
|
|
214
|
-
this._sending.delete(jsonRpcMessage.id);
|
|
215
|
-
stream.push({
|
|
216
|
-
error: new ConfigError("SENDING_TIMEOUT", {
|
|
217
|
-
timeout: this.sendingTimeout
|
|
218
|
-
}).toJSON()
|
|
219
|
-
});
|
|
220
|
-
this._requests.delete(jsonRpcMessage.id);
|
|
221
|
-
}, this.sendingTimeout)
|
|
222
|
-
}));
|
|
223
|
-
}
|
|
224
236
|
_sendRaw(method, params) {
|
|
225
237
|
const jsonRpcMessage = {
|
|
226
238
|
jsonrpc: JSONRPC.version,
|
|
@@ -241,11 +253,20 @@ var BaseClient = class {
|
|
|
241
253
|
if (this._error) {
|
|
242
254
|
throw this._error;
|
|
243
255
|
}
|
|
244
|
-
|
|
256
|
+
const outboundRequest = __spreadValues(__spreadValues({
|
|
245
257
|
stream,
|
|
246
|
-
start: Date.now()
|
|
258
|
+
start: Date.now(),
|
|
259
|
+
message: jsonRpcMessage
|
|
260
|
+
}, this.sendingTimeout && {
|
|
261
|
+
sendingTimeout: setTimeout(() => {
|
|
262
|
+
this._fireSendingTimeout(outboundRequest);
|
|
263
|
+
}, this.sendingTimeout)
|
|
264
|
+
}), this.requestTimeout && {
|
|
265
|
+
requestTimeout: setTimeout(() => {
|
|
266
|
+
this._fireRequestTimeout(outboundRequest);
|
|
267
|
+
}, this.requestTimeout)
|
|
247
268
|
});
|
|
248
|
-
this.
|
|
269
|
+
this._requests.set(jsonRpcMessage.id, outboundRequest);
|
|
249
270
|
this._send(jsonRpcMessage);
|
|
250
271
|
}));
|
|
251
272
|
}
|
package/dist/api/base-client.cjs
CHANGED
|
@@ -91,6 +91,7 @@ var BaseClient = class {
|
|
|
91
91
|
__publicField(this, "_error", false);
|
|
92
92
|
__publicField(this, "_sending", /* @__PURE__ */ new Map());
|
|
93
93
|
__publicField(this, "sendingTimeout");
|
|
94
|
+
__publicField(this, "requestTimeout", 12e4);
|
|
94
95
|
this.type = connectionType;
|
|
95
96
|
this._connection = connection;
|
|
96
97
|
this.connectionType = connectionType;
|
|
@@ -132,18 +133,50 @@ var BaseClient = class {
|
|
|
132
133
|
// Will fire this in case we lose connection
|
|
133
134
|
// This is so we can terminate ongoing requests
|
|
134
135
|
_connectionLost() {
|
|
135
|
-
this._requests.forEach((
|
|
136
|
-
|
|
137
|
-
responseObject.stream.destroy(
|
|
138
|
-
new import_errors.StreamError("CONNECTION_LOST", { method: "connectionLost" })
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
this._requests.delete(key);
|
|
136
|
+
this._requests.forEach((requestInfo) => {
|
|
137
|
+
this._fireConnectionLost(requestInfo);
|
|
142
138
|
});
|
|
143
139
|
this.socId = void 0;
|
|
144
140
|
}
|
|
141
|
+
_completeRequest(request, error) {
|
|
142
|
+
const key = request.message.id;
|
|
143
|
+
if (key === null) {
|
|
144
|
+
throw new Error("JSONRPCMessage.id should not be null");
|
|
145
|
+
}
|
|
146
|
+
if (error) {
|
|
147
|
+
if ("error" in request) {
|
|
148
|
+
request.error(error);
|
|
149
|
+
} else if ("stream" in request) {
|
|
150
|
+
request.stream.destroy(error);
|
|
151
|
+
}
|
|
152
|
+
} else if (!request.stream.destroyed) {
|
|
153
|
+
request.stream.push(null);
|
|
154
|
+
}
|
|
155
|
+
clearTimeout(request.requestTimeout);
|
|
156
|
+
clearTimeout(request.sendingTimeout);
|
|
157
|
+
this._requests.delete(key);
|
|
158
|
+
this._sending.delete(key);
|
|
159
|
+
}
|
|
160
|
+
_fireConnectionLost(requestInfo) {
|
|
161
|
+
const error = new import_errors.StreamError("CONNECTION_LOST", {
|
|
162
|
+
method: "connectionLost"
|
|
163
|
+
});
|
|
164
|
+
return this._completeRequest(requestInfo, error);
|
|
165
|
+
}
|
|
166
|
+
_fireSendingTimeout(requestInfo) {
|
|
167
|
+
const error = new import_errors.ConfigError("SENDING_TIMEOUT", {
|
|
168
|
+
timeout: this.sendingTimeout
|
|
169
|
+
});
|
|
170
|
+
return this._completeRequest(requestInfo, error);
|
|
171
|
+
}
|
|
172
|
+
_fireRequestTimeout(requestInfo) {
|
|
173
|
+
const error = new import_errors.ConfigError("REQUEST_TIMEOUT", {
|
|
174
|
+
timeout: this.requestTimeout
|
|
175
|
+
});
|
|
176
|
+
return this._completeRequest(requestInfo, error);
|
|
177
|
+
}
|
|
145
178
|
_handleMessage(incoming) {
|
|
146
|
-
var _a, _b, _c
|
|
179
|
+
var _a, _b, _c;
|
|
147
180
|
if (this.hooks.message) {
|
|
148
181
|
this.hooks.message(incoming);
|
|
149
182
|
}
|
|
@@ -168,16 +201,16 @@ var BaseClient = class {
|
|
|
168
201
|
(0, import_debug.debugLog)("Unexpected JSONRPCResponse", incoming);
|
|
169
202
|
return;
|
|
170
203
|
}
|
|
171
|
-
if (responseMessage.result === import_jsonrpc_enums.JSONRPC.acknowledgement) {
|
|
172
|
-
clearTimeout((_a = this._sending.get(responseMessage.id)) == null ? void 0 : _a.timeout);
|
|
173
|
-
this._sending.delete(responseMessage.id);
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
204
|
const requestInfo = this._requests.get(responseMessage.id);
|
|
177
205
|
if (!requestInfo) {
|
|
178
206
|
(0, import_debug.debugLog)("No Request found for incoming", incoming);
|
|
179
207
|
return;
|
|
180
208
|
}
|
|
209
|
+
if (responseMessage.result === import_jsonrpc_enums.JSONRPC.acknowledgement) {
|
|
210
|
+
clearTimeout(requestInfo.requestTimeout);
|
|
211
|
+
delete requestInfo.requestTimeout;
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
181
214
|
if ("handle" in requestInfo) {
|
|
182
215
|
requestInfo.handle(responseMessage);
|
|
183
216
|
delete requestInfo.handle;
|
|
@@ -187,26 +220,21 @@ var BaseClient = class {
|
|
|
187
220
|
requestInfo.error(responseMessage.error);
|
|
188
221
|
}
|
|
189
222
|
const message = responseMessage;
|
|
190
|
-
if (((
|
|
223
|
+
if (((_a = message.result) == null ? void 0 : _a.type) === import_jsonrpc_enums.JSONRPC.streamPause && "pause" in requestInfo) {
|
|
191
224
|
requestInfo.pause();
|
|
192
225
|
return;
|
|
193
226
|
}
|
|
194
|
-
if (((
|
|
227
|
+
if (((_b = message.result) == null ? void 0 : _b.type) === import_jsonrpc_enums.JSONRPC.streamResume && "resume" in requestInfo) {
|
|
195
228
|
requestInfo.resume();
|
|
196
229
|
return;
|
|
197
230
|
}
|
|
198
231
|
const { stream, start } = requestInfo;
|
|
199
|
-
if (((
|
|
232
|
+
if (((_c = message.result) == null ? void 0 : _c.type) === import_jsonrpc_enums.JSONRPC.streamChunk) {
|
|
200
233
|
stream.push(message.result);
|
|
201
234
|
return;
|
|
202
235
|
}
|
|
203
236
|
stream.push(message);
|
|
204
|
-
|
|
205
|
-
stream.push(null);
|
|
206
|
-
}
|
|
207
|
-
if (message.id) {
|
|
208
|
-
this._requests.delete(message.id);
|
|
209
|
-
}
|
|
237
|
+
this._completeRequest(requestInfo);
|
|
210
238
|
if (this.connectionType === import_wapi_client.WapiClientType.ws) {
|
|
211
239
|
this._send({
|
|
212
240
|
jsonrpc: import_jsonrpc_enums.JSONRPC.version,
|
|
@@ -224,22 +252,6 @@ var BaseClient = class {
|
|
|
224
252
|
// const inputCopy = APIValidators[name](input);
|
|
225
253
|
// return this._sendRaw<Input, Output>(name, inputCopy as Input);
|
|
226
254
|
// }
|
|
227
|
-
_setSending(jsonRpcMessage, stream) {
|
|
228
|
-
if (jsonRpcMessage.id === null) {
|
|
229
|
-
throw new Error("JSONRPCMessage should not be null");
|
|
230
|
-
}
|
|
231
|
-
this._sending.set(jsonRpcMessage.id, __spreadValues({}, this.sendingTimeout && {
|
|
232
|
-
timeout: setTimeout(() => {
|
|
233
|
-
this._sending.delete(jsonRpcMessage.id);
|
|
234
|
-
stream.push({
|
|
235
|
-
error: new import_errors.ConfigError("SENDING_TIMEOUT", {
|
|
236
|
-
timeout: this.sendingTimeout
|
|
237
|
-
}).toJSON()
|
|
238
|
-
});
|
|
239
|
-
this._requests.delete(jsonRpcMessage.id);
|
|
240
|
-
}, this.sendingTimeout)
|
|
241
|
-
}));
|
|
242
|
-
}
|
|
243
255
|
_sendRaw(method, params) {
|
|
244
256
|
const jsonRpcMessage = {
|
|
245
257
|
jsonrpc: import_jsonrpc_enums.JSONRPC.version,
|
|
@@ -260,11 +272,20 @@ var BaseClient = class {
|
|
|
260
272
|
if (this._error) {
|
|
261
273
|
throw this._error;
|
|
262
274
|
}
|
|
263
|
-
|
|
275
|
+
const outboundRequest = __spreadValues(__spreadValues({
|
|
264
276
|
stream,
|
|
265
|
-
start: Date.now()
|
|
277
|
+
start: Date.now(),
|
|
278
|
+
message: jsonRpcMessage
|
|
279
|
+
}, this.sendingTimeout && {
|
|
280
|
+
sendingTimeout: setTimeout(() => {
|
|
281
|
+
this._fireSendingTimeout(outboundRequest);
|
|
282
|
+
}, this.sendingTimeout)
|
|
283
|
+
}), this.requestTimeout && {
|
|
284
|
+
requestTimeout: setTimeout(() => {
|
|
285
|
+
this._fireRequestTimeout(outboundRequest);
|
|
286
|
+
}, this.requestTimeout)
|
|
266
287
|
});
|
|
267
|
-
this.
|
|
288
|
+
this._requests.set(jsonRpcMessage.id, outboundRequest);
|
|
268
289
|
this._send(jsonRpcMessage);
|
|
269
290
|
}));
|
|
270
291
|
}
|
package/dist/api/base-client.js
CHANGED
|
@@ -72,6 +72,7 @@ var BaseClient = class {
|
|
|
72
72
|
__publicField(this, "_error", false);
|
|
73
73
|
__publicField(this, "_sending", /* @__PURE__ */ new Map());
|
|
74
74
|
__publicField(this, "sendingTimeout");
|
|
75
|
+
__publicField(this, "requestTimeout", 12e4);
|
|
75
76
|
this.type = connectionType;
|
|
76
77
|
this._connection = connection;
|
|
77
78
|
this.connectionType = connectionType;
|
|
@@ -113,18 +114,50 @@ var BaseClient = class {
|
|
|
113
114
|
// Will fire this in case we lose connection
|
|
114
115
|
// This is so we can terminate ongoing requests
|
|
115
116
|
_connectionLost() {
|
|
116
|
-
this._requests.forEach((
|
|
117
|
-
|
|
118
|
-
responseObject.stream.destroy(
|
|
119
|
-
new StreamError("CONNECTION_LOST", { method: "connectionLost" })
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
this._requests.delete(key);
|
|
117
|
+
this._requests.forEach((requestInfo) => {
|
|
118
|
+
this._fireConnectionLost(requestInfo);
|
|
123
119
|
});
|
|
124
120
|
this.socId = void 0;
|
|
125
121
|
}
|
|
122
|
+
_completeRequest(request, error) {
|
|
123
|
+
const key = request.message.id;
|
|
124
|
+
if (key === null) {
|
|
125
|
+
throw new Error("JSONRPCMessage.id should not be null");
|
|
126
|
+
}
|
|
127
|
+
if (error) {
|
|
128
|
+
if ("error" in request) {
|
|
129
|
+
request.error(error);
|
|
130
|
+
} else if ("stream" in request) {
|
|
131
|
+
request.stream.destroy(error);
|
|
132
|
+
}
|
|
133
|
+
} else if (!request.stream.destroyed) {
|
|
134
|
+
request.stream.push(null);
|
|
135
|
+
}
|
|
136
|
+
clearTimeout(request.requestTimeout);
|
|
137
|
+
clearTimeout(request.sendingTimeout);
|
|
138
|
+
this._requests.delete(key);
|
|
139
|
+
this._sending.delete(key);
|
|
140
|
+
}
|
|
141
|
+
_fireConnectionLost(requestInfo) {
|
|
142
|
+
const error = new StreamError("CONNECTION_LOST", {
|
|
143
|
+
method: "connectionLost"
|
|
144
|
+
});
|
|
145
|
+
return this._completeRequest(requestInfo, error);
|
|
146
|
+
}
|
|
147
|
+
_fireSendingTimeout(requestInfo) {
|
|
148
|
+
const error = new ConfigError("SENDING_TIMEOUT", {
|
|
149
|
+
timeout: this.sendingTimeout
|
|
150
|
+
});
|
|
151
|
+
return this._completeRequest(requestInfo, error);
|
|
152
|
+
}
|
|
153
|
+
_fireRequestTimeout(requestInfo) {
|
|
154
|
+
const error = new ConfigError("REQUEST_TIMEOUT", {
|
|
155
|
+
timeout: this.requestTimeout
|
|
156
|
+
});
|
|
157
|
+
return this._completeRequest(requestInfo, error);
|
|
158
|
+
}
|
|
126
159
|
_handleMessage(incoming) {
|
|
127
|
-
var _a, _b, _c
|
|
160
|
+
var _a, _b, _c;
|
|
128
161
|
if (this.hooks.message) {
|
|
129
162
|
this.hooks.message(incoming);
|
|
130
163
|
}
|
|
@@ -149,16 +182,16 @@ var BaseClient = class {
|
|
|
149
182
|
debugLog("Unexpected JSONRPCResponse", incoming);
|
|
150
183
|
return;
|
|
151
184
|
}
|
|
152
|
-
if (responseMessage.result === JSONRPC.acknowledgement) {
|
|
153
|
-
clearTimeout((_a = this._sending.get(responseMessage.id)) == null ? void 0 : _a.timeout);
|
|
154
|
-
this._sending.delete(responseMessage.id);
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
185
|
const requestInfo = this._requests.get(responseMessage.id);
|
|
158
186
|
if (!requestInfo) {
|
|
159
187
|
debugLog("No Request found for incoming", incoming);
|
|
160
188
|
return;
|
|
161
189
|
}
|
|
190
|
+
if (responseMessage.result === JSONRPC.acknowledgement) {
|
|
191
|
+
clearTimeout(requestInfo.requestTimeout);
|
|
192
|
+
delete requestInfo.requestTimeout;
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
162
195
|
if ("handle" in requestInfo) {
|
|
163
196
|
requestInfo.handle(responseMessage);
|
|
164
197
|
delete requestInfo.handle;
|
|
@@ -168,26 +201,21 @@ var BaseClient = class {
|
|
|
168
201
|
requestInfo.error(responseMessage.error);
|
|
169
202
|
}
|
|
170
203
|
const message = responseMessage;
|
|
171
|
-
if (((
|
|
204
|
+
if (((_a = message.result) == null ? void 0 : _a.type) === JSONRPC.streamPause && "pause" in requestInfo) {
|
|
172
205
|
requestInfo.pause();
|
|
173
206
|
return;
|
|
174
207
|
}
|
|
175
|
-
if (((
|
|
208
|
+
if (((_b = message.result) == null ? void 0 : _b.type) === JSONRPC.streamResume && "resume" in requestInfo) {
|
|
176
209
|
requestInfo.resume();
|
|
177
210
|
return;
|
|
178
211
|
}
|
|
179
212
|
const { stream, start } = requestInfo;
|
|
180
|
-
if (((
|
|
213
|
+
if (((_c = message.result) == null ? void 0 : _c.type) === JSONRPC.streamChunk) {
|
|
181
214
|
stream.push(message.result);
|
|
182
215
|
return;
|
|
183
216
|
}
|
|
184
217
|
stream.push(message);
|
|
185
|
-
|
|
186
|
-
stream.push(null);
|
|
187
|
-
}
|
|
188
|
-
if (message.id) {
|
|
189
|
-
this._requests.delete(message.id);
|
|
190
|
-
}
|
|
218
|
+
this._completeRequest(requestInfo);
|
|
191
219
|
if (this.connectionType === WapiClientType.ws) {
|
|
192
220
|
this._send({
|
|
193
221
|
jsonrpc: JSONRPC.version,
|
|
@@ -205,22 +233,6 @@ var BaseClient = class {
|
|
|
205
233
|
// const inputCopy = APIValidators[name](input);
|
|
206
234
|
// return this._sendRaw<Input, Output>(name, inputCopy as Input);
|
|
207
235
|
// }
|
|
208
|
-
_setSending(jsonRpcMessage, stream) {
|
|
209
|
-
if (jsonRpcMessage.id === null) {
|
|
210
|
-
throw new Error("JSONRPCMessage should not be null");
|
|
211
|
-
}
|
|
212
|
-
this._sending.set(jsonRpcMessage.id, __spreadValues({}, this.sendingTimeout && {
|
|
213
|
-
timeout: setTimeout(() => {
|
|
214
|
-
this._sending.delete(jsonRpcMessage.id);
|
|
215
|
-
stream.push({
|
|
216
|
-
error: new ConfigError("SENDING_TIMEOUT", {
|
|
217
|
-
timeout: this.sendingTimeout
|
|
218
|
-
}).toJSON()
|
|
219
|
-
});
|
|
220
|
-
this._requests.delete(jsonRpcMessage.id);
|
|
221
|
-
}, this.sendingTimeout)
|
|
222
|
-
}));
|
|
223
|
-
}
|
|
224
236
|
_sendRaw(method, params) {
|
|
225
237
|
const jsonRpcMessage = {
|
|
226
238
|
jsonrpc: JSONRPC.version,
|
|
@@ -241,11 +253,20 @@ var BaseClient = class {
|
|
|
241
253
|
if (this._error) {
|
|
242
254
|
throw this._error;
|
|
243
255
|
}
|
|
244
|
-
|
|
256
|
+
const outboundRequest = __spreadValues(__spreadValues({
|
|
245
257
|
stream,
|
|
246
|
-
start: Date.now()
|
|
258
|
+
start: Date.now(),
|
|
259
|
+
message: jsonRpcMessage
|
|
260
|
+
}, this.sendingTimeout && {
|
|
261
|
+
sendingTimeout: setTimeout(() => {
|
|
262
|
+
this._fireSendingTimeout(outboundRequest);
|
|
263
|
+
}, this.sendingTimeout)
|
|
264
|
+
}), this.requestTimeout && {
|
|
265
|
+
requestTimeout: setTimeout(() => {
|
|
266
|
+
this._fireRequestTimeout(outboundRequest);
|
|
267
|
+
}, this.requestTimeout)
|
|
247
268
|
});
|
|
248
|
-
this.
|
|
269
|
+
this._requests.set(jsonRpcMessage.id, outboundRequest);
|
|
249
270
|
this._send(jsonRpcMessage);
|
|
250
271
|
}));
|
|
251
272
|
}
|