wapi-client 0.18.0-beta.2 → 0.18.0-beta.5

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.
@@ -98,19 +98,6 @@ var BaseClient = class {
98
98
  _clearError() {
99
99
  this._error = false;
100
100
  }
101
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
102
- _send(input) {
103
- throw new Error("This method must be implemented by child class");
104
- }
105
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
106
- _reconnect(nrOfAttempts) {
107
- throw new Error("This method must be implemented by child class");
108
- }
109
- close() {
110
- return __async(this, null, function* () {
111
- throw new Error("This method must be implemented by child class");
112
- });
113
- }
114
101
  // Will fire this in case we lose connection
115
102
  // This is so we can terminate ongoing requests
116
103
  _connectionLost() {
@@ -175,9 +162,6 @@ var BaseClient = class {
175
162
  return;
176
163
  }
177
164
  const responseMessage = incoming;
178
- if (this.hooks.message) {
179
- this.hooks.message(responseMessage);
180
- }
181
165
  if (responseMessage.id === null) {
182
166
  debugLog("Unexpected JSONRPCResponse", incoming);
183
167
  return;
@@ -181,9 +181,13 @@ var WsClient = class extends BaseClient {
181
181
  const { data, type } = event;
182
182
  debugLog(`message(type:${type},data:$0)`, data);
183
183
  if (type === "message") {
184
- const obj = JSON.parse(data.toString());
185
- this._handleMessage(obj);
186
- this._heartbeat();
184
+ try {
185
+ const obj = JSON.parse(data.toString());
186
+ this._handleMessage(obj);
187
+ this._heartbeat();
188
+ } catch (e) {
189
+ debugLog(`Invalid JSON message(error:$1,type:${type})`, e);
190
+ }
187
191
  }
188
192
  };
189
193
  this._connection.onerror = (event) => {
package/dist/client.js CHANGED
@@ -14,6 +14,18 @@ var __spreadValues = (a, b) => {
14
14
  }
15
15
  return a;
16
16
  };
17
+ var __objRest = (source, exclude) => {
18
+ var target = {};
19
+ for (var prop in source)
20
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
21
+ target[prop] = source[prop];
22
+ if (source != null && __getOwnPropSymbols)
23
+ for (var prop of __getOwnPropSymbols(source)) {
24
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
25
+ target[prop] = source[prop];
26
+ }
27
+ return target;
28
+ };
17
29
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
18
30
  var __async = (__this, __arguments, generator) => {
19
31
  return new Promise((resolve, reject) => {
@@ -109,7 +121,7 @@ var Client = class {
109
121
  this.api = _apiClient;
110
122
  this.$connect = _apiClient.$connect;
111
123
  if (initialConf) {
112
- this.configure(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, initialConf.token && { token: initialConf.token }), initialConf.sendingTimeout && {
124
+ this.configure(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, initialConf.token !== void 0 && { token: initialConf.token }), initialConf.sendingTimeout && {
113
125
  sendingTimeout: initialConf.sendingTimeout
114
126
  }), initialConf.connectingTimeout && {
115
127
  connectingTimeout: initialConf.connectingTimeout
@@ -191,7 +203,7 @@ var Client = class {
191
203
  * @param {ClientConfig} newConf
192
204
  */
193
205
  configure(newConf) {
194
- if (newConf.token && typeof newConf.token !== "string" && typeof newConf.token !== "number") {
206
+ if (newConf.token !== void 0 && typeof newConf.token !== "string" && typeof newConf.token !== "number") {
195
207
  throw new ConfigError("CONFIG_INVALID", {
196
208
  field: "token",
197
209
  error: `Must be a string|number, '${newConf.token}' provided`
@@ -203,16 +215,15 @@ var Client = class {
203
215
  "reconnectingTimeout",
204
216
  "requestTimeout"
205
217
  ].forEach((t) => {
206
- if (newConf[t] && typeof newConf[t] !== "number") {
218
+ if (newConf[t] !== void 0 && typeof newConf[t] !== "number") {
207
219
  throw new ConfigError("CONFIG_INVALID", {
208
220
  field: t,
209
221
  error: `Must be a number, '${newConf[t]}' provided`
210
222
  });
211
223
  }
212
224
  });
213
- const hooks = newConf.hooks;
214
- delete newConf.hooks;
215
- this.config = __spreadValues(__spreadValues({}, this.config), newConf);
225
+ const _a = newConf, { hooks } = _a, restOfConf = __objRest(_a, ["hooks"]);
226
+ this.config = __spreadValues(__spreadValues({}, this.config), restOfConf);
216
227
  if ("sendingTimeout" in this.config) {
217
228
  this.api.sendingTimeout = this.config.sendingTimeout;
218
229
  }
@@ -11,7 +11,7 @@ import { transferFilterFullInputSchema } from "../../txs/find-transfer-many/find
11
11
  import { mergeFnOptions } from "../../lib/utils.js";
12
12
  var transferFilterFullInputSchemaRequired = transferFilterFullInputSchema.extend({
13
13
  token: findTransfersInputSchema.shape.token,
14
- wallet: findTransfersInputSchema.shape.token
14
+ wallet: findTransfersInputSchema.shape.wallet
15
15
  }).required();
16
16
  function findTransfers(options, input, fnOptions) {
17
17
  const { client } = options;
@@ -33,7 +33,7 @@ import {
33
33
  import { DbFilterMetadataSchema } from "../../db/consts.js";
34
34
  var findTransfersFnExtraOptionsSchema = z.object({
35
35
  return_running_balance: z.boolean().describe("return running balance for specified wallet under filter"),
36
- return_signed_amount: z.boolean().describe("return running balance for specified wallet under filter"),
36
+ return_signed_amount: z.boolean().describe("return signed amount for specified wallet under filter"),
37
37
  return_running_balance_for_wallet: allowedStringIntForForeign.describe(
38
38
  "foreign key for which wallet should running balance be returned for"
39
39
  ),
@@ -60,7 +60,13 @@ var StreamPromise = class {
60
60
  (_a = this.resolve) == null ? void 0 : _a.call(this, void 0);
61
61
  return;
62
62
  }
63
- this.makeRequest(this.streamObject).catch(this.reject);
63
+ this.makeRequest(this.streamObject).catch((err) => {
64
+ if (this.mode === "stream") {
65
+ this.outStreamObject.destroy(err);
66
+ } else if (this.reject) {
67
+ this.reject(err);
68
+ }
69
+ });
64
70
  const internalArr = [];
65
71
  if (this.mode === "stream") {
66
72
  this.streamObject.on(
@@ -69,6 +75,7 @@ var StreamPromise = class {
69
75
  debugLog("stream data", chunk);
70
76
  if (!chunk) {
71
77
  this.outStreamObject.push(chunk);
78
+ return;
72
79
  }
73
80
  if (chunk.error) {
74
81
  const error = getError(chunk.error);
package/dist/lib/utils.js CHANGED
@@ -87,25 +87,15 @@ var internalMap = {
87
87
  timeouts: {},
88
88
  values: {},
89
89
  set(key, value) {
90
- this.timeouts[key] = setTimeout(() => this.clear(key), 3e4);
90
+ var _a, _b;
91
+ this.timeouts[key] = (_b = (_a = setTimeout(() => this.clear(key), 3e4)) == null ? void 0 : _a.unref) == null ? void 0 : _b.call(_a);
91
92
  this.values[key] = value;
92
93
  },
93
94
  get(key) {
94
95
  return this.values[key];
95
96
  },
96
97
  getKey(object) {
97
- const copy = JSON.parse(JSON.stringify(object));
98
- let toHash = "";
99
- Object.keys(copy).sort().forEach((key) => {
100
- let value = "";
101
- if (copy[key] && typeof copy[key] === "object" && !Array.isArray(copy[key])) {
102
- value = this.getKey(copy[key]);
103
- } else {
104
- value = JSON.stringify(copy[key]);
105
- }
106
- toHash += key + ":" + value;
107
- });
108
- return toHash;
98
+ return JSON.stringify(object);
109
99
  },
110
100
  clear(key) {
111
101
  if (this.timeouts[key]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wapi-client",
3
- "version": "0.18.0-beta.2",
3
+ "version": "0.18.0-beta.5",
4
4
  "description": "Client library to to access WAPI ledgering services",
5
5
  "main": "dist/wapi-client.cjs",
6
6
  "module": "dist/wapi-client.js",