@tchain/tcabci-read-js-client 2.5.5 → 2.5.7
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/bytea.d.ts +4 -0
- package/client.d.ts +112 -0
- package/client.js +85 -68
- package/constants.d.ts +8 -0
- package/constants.js +2 -4
- package/errors.d.ts +24 -0
- package/errors.js +26 -8
- package/errors_test.js +1 -1
- package/eslint.config.js +45 -0
- package/message.d.ts +13 -0
- package/message.js +2 -5
- package/package.json +18 -13
- package/transaction.d.ts +84 -0
- package/transaction.js +1 -1
- package/util.d.ts +2 -0
- package/util.js +2 -2
- package/websocket.d.ts +24 -0
- package/websocket.js +6 -6
- package/websocketOptions.d.ts +50 -0
- package/websocketOptions.js +17 -14
- package/websocketOptions_test.js +6 -6
package/bytea.d.ts
ADDED
package/client.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { TXType } from './transaction'
|
|
2
|
+
|
|
3
|
+
declare class TCaBCIClient {
|
|
4
|
+
constructor(
|
|
5
|
+
readNodeAddresses: string[],
|
|
6
|
+
wsLibrary: WebSocket,
|
|
7
|
+
chainName: string,
|
|
8
|
+
chainVersion: string,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
SetDebug(debug: boolean): TCaBCIClient
|
|
12
|
+
Socket(): WebSocket
|
|
13
|
+
SetSuccessCallback(cb: (event: Event) => void): TCaBCIClient
|
|
14
|
+
SetErrorCallback(cb: (event: Event) => void): TCaBCIClient
|
|
15
|
+
SetCloseCallback(cb: (event: Event) => void): TCaBCIClient
|
|
16
|
+
SetListenCallback(cb: (event: Event) => void): TCaBCIClient
|
|
17
|
+
Start(): Awaited<TCaBCIClient>
|
|
18
|
+
Stop(): Awaited<TCaBCIClient>
|
|
19
|
+
Status(): {
|
|
20
|
+
chain_name: string
|
|
21
|
+
chain_version: string
|
|
22
|
+
connected: boolean
|
|
23
|
+
subscribed: boolean
|
|
24
|
+
}
|
|
25
|
+
Subscribe(
|
|
26
|
+
addresses: string[],
|
|
27
|
+
signedData: Record<string, string>,
|
|
28
|
+
txTypes?: TXType[],
|
|
29
|
+
): TCaBCIClient
|
|
30
|
+
Unsubscribe(): TCaBCIClient
|
|
31
|
+
LastBlock(
|
|
32
|
+
chainName?: null,
|
|
33
|
+
chainVersion?: null,
|
|
34
|
+
): { blocks: Record<string, any>; total_count: number }
|
|
35
|
+
Tx(id: string, signature: string): Promise<{ tx: Record<string, any> }>
|
|
36
|
+
TxSummary({
|
|
37
|
+
recipientAddrs,
|
|
38
|
+
senderAddrs,
|
|
39
|
+
signedData,
|
|
40
|
+
typ,
|
|
41
|
+
types,
|
|
42
|
+
chainName,
|
|
43
|
+
chainVersion,
|
|
44
|
+
}: Record<string, any>): Promise<{
|
|
45
|
+
chain_name: string
|
|
46
|
+
chain_version: string
|
|
47
|
+
first_block_height: number
|
|
48
|
+
first_transaction: Record<string, any>
|
|
49
|
+
last_block_height: number
|
|
50
|
+
last_transaction: Record<string, any>
|
|
51
|
+
total_count: number
|
|
52
|
+
}>
|
|
53
|
+
TxSearch({
|
|
54
|
+
heightOperator,
|
|
55
|
+
height,
|
|
56
|
+
maxHeight,
|
|
57
|
+
lastOrder,
|
|
58
|
+
recipientAddrs,
|
|
59
|
+
senderAddrs,
|
|
60
|
+
signedData,
|
|
61
|
+
hashes,
|
|
62
|
+
typ,
|
|
63
|
+
types,
|
|
64
|
+
limit,
|
|
65
|
+
offset,
|
|
66
|
+
orderField,
|
|
67
|
+
orderBy,
|
|
68
|
+
chainName,
|
|
69
|
+
chainVersion,
|
|
70
|
+
}): Promise<{ txs: Record<string, any>[]; total_count: number }>
|
|
71
|
+
BroadcastCommit({
|
|
72
|
+
id,
|
|
73
|
+
version,
|
|
74
|
+
type,
|
|
75
|
+
data,
|
|
76
|
+
sender_addr,
|
|
77
|
+
recipient_addr,
|
|
78
|
+
sign,
|
|
79
|
+
fee,
|
|
80
|
+
}): Promise<{ data: Record<string, any> }>
|
|
81
|
+
BroadcastSync({
|
|
82
|
+
id,
|
|
83
|
+
version,
|
|
84
|
+
type,
|
|
85
|
+
data,
|
|
86
|
+
sender_addr,
|
|
87
|
+
recipient_addr,
|
|
88
|
+
sign,
|
|
89
|
+
fee,
|
|
90
|
+
}): Promise<{ data: Record<string, any> }>
|
|
91
|
+
Broadcast({
|
|
92
|
+
id,
|
|
93
|
+
version,
|
|
94
|
+
type,
|
|
95
|
+
data,
|
|
96
|
+
sender_addr,
|
|
97
|
+
recipient_addr,
|
|
98
|
+
sign,
|
|
99
|
+
fee,
|
|
100
|
+
}): Promise<{ data: Record<string, any> }>
|
|
101
|
+
Bulk(
|
|
102
|
+
addresses: string[],
|
|
103
|
+
signedData: Record<string, any>,
|
|
104
|
+
maxHeight?: number,
|
|
105
|
+
chainName?: string,
|
|
106
|
+
chainVersion?: string,
|
|
107
|
+
): Promise<{ data: Record<string, any> }>
|
|
108
|
+
Disconnect(code?: number): Awaited<TCaBCIClient>
|
|
109
|
+
Reconnect(code?: number): Awaited<TCaBCIClient>
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export = TCaBCIClient
|
package/client.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
FetchError,
|
|
3
3
|
ALREADY_CONNECTED,
|
|
4
4
|
BLOCK_NOT_FOUND,
|
|
5
5
|
ERR_NETWORK,
|
|
6
|
-
FetchError,
|
|
7
6
|
INVALID_ARGUMENT_WITH_CS,
|
|
8
7
|
INVALID_ARGUMENTS,
|
|
9
8
|
NOT_CONNECTED,
|
|
@@ -12,12 +11,13 @@ import {
|
|
|
12
11
|
TRANSACTION_TYPE_NOT_VALID,
|
|
13
12
|
} from './errors.js'
|
|
14
13
|
import {
|
|
15
|
-
|
|
14
|
+
SUBSCRIBEMessage,
|
|
15
|
+
UNSUBSCRIBEMessage,
|
|
16
16
|
READ_NODE_ADDRESS,
|
|
17
17
|
READ_NODE_WS_ADDRESS,
|
|
18
18
|
} from './constants.js'
|
|
19
19
|
import Message from './message.js'
|
|
20
|
-
import { isJSON,
|
|
20
|
+
import { isJSON, fromJSON } from './util.js'
|
|
21
21
|
import { Options } from './websocketOptions.js'
|
|
22
22
|
import { TWebSocket } from './websocket.js'
|
|
23
23
|
import { TX_TYPE, TX_TYPE_LIST } from './transaction.js'
|
|
@@ -49,7 +49,7 @@ export default class TCaBCIClient {
|
|
|
49
49
|
_connected = false
|
|
50
50
|
_chainName = 'transferchain'
|
|
51
51
|
_chainVersion = 'v1'
|
|
52
|
-
_version = `v2.5.
|
|
52
|
+
_version = `v2.5.7`
|
|
53
53
|
/**
|
|
54
54
|
* @type {?successCallback}
|
|
55
55
|
*/
|
|
@@ -67,6 +67,11 @@ export default class TCaBCIClient {
|
|
|
67
67
|
*/
|
|
68
68
|
_listenCb = null
|
|
69
69
|
_wsLibrary = null
|
|
70
|
+
/**
|
|
71
|
+
* @type {Options}
|
|
72
|
+
* @private
|
|
73
|
+
*/
|
|
74
|
+
_options
|
|
70
75
|
/**
|
|
71
76
|
* @type {TWebSocket}
|
|
72
77
|
*/
|
|
@@ -90,34 +95,25 @@ export default class TCaBCIClient {
|
|
|
90
95
|
this._wsLibrary = wsLibrary
|
|
91
96
|
|
|
92
97
|
if (Array.isArray(readNodeAddresses) && readNodeAddresses.length === 2) {
|
|
93
|
-
this._readNodeAddress = readNodeAddresses[0]
|
|
94
|
-
this._readNodeWSAddress = readNodeAddresses[1]
|
|
95
|
-
|
|
96
98
|
if (!readNodeAddresses[0].startsWith('http'))
|
|
97
99
|
throw new Error(INVALID_ARGUMENTS)
|
|
98
100
|
if (!readNodeAddresses[1].startsWith('ws'))
|
|
99
101
|
throw new Error(INVALID_ARGUMENTS)
|
|
102
|
+
|
|
103
|
+
this._readNodeAddress = readNodeAddresses[0]
|
|
104
|
+
this._readNodeWSAddress = readNodeAddresses[1]
|
|
100
105
|
}
|
|
101
106
|
|
|
107
|
+
this._options = new Options(this._readNodeWSAddress)
|
|
108
|
+
this._options.setCustomWS(this._wsLibrary)
|
|
109
|
+
|
|
102
110
|
if (chainName) this._chainName = chainName
|
|
103
111
|
if (chainVersion) this._chainVersion = chainVersion
|
|
104
112
|
}
|
|
105
113
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
* @return {Promise<any>}
|
|
110
|
-
*/
|
|
111
|
-
httpClient(uri, req) {
|
|
112
|
-
req.cache = 'no-cache'
|
|
113
|
-
req.headers = {
|
|
114
|
-
Client: `tcabaci-read-js-client-${this._version}`,
|
|
115
|
-
}
|
|
116
|
-
req.priority = 'high'
|
|
117
|
-
|
|
118
|
-
return fetch(this._readNodeAddress + uri, req).then((response) =>
|
|
119
|
-
this.handleRestResponse(response),
|
|
120
|
-
)
|
|
114
|
+
SetDebug(debug) {
|
|
115
|
+
this._options.setDebug(debug)
|
|
116
|
+
return this
|
|
121
117
|
}
|
|
122
118
|
|
|
123
119
|
Socket() {
|
|
@@ -126,7 +122,7 @@ export default class TCaBCIClient {
|
|
|
126
122
|
|
|
127
123
|
/**
|
|
128
124
|
* @param {successCallback} cb
|
|
129
|
-
* @
|
|
125
|
+
* @return {TCaBCIClient}
|
|
130
126
|
*/
|
|
131
127
|
SetSuccessCallback(cb) {
|
|
132
128
|
this._successCb = cb
|
|
@@ -136,7 +132,7 @@ export default class TCaBCIClient {
|
|
|
136
132
|
|
|
137
133
|
/**
|
|
138
134
|
* @param {errorCallback} cb
|
|
139
|
-
* @
|
|
135
|
+
* @return {TCaBCIClient}
|
|
140
136
|
*/
|
|
141
137
|
SetErrorCallback(cb) {
|
|
142
138
|
this._errorCb = cb
|
|
@@ -146,7 +142,7 @@ export default class TCaBCIClient {
|
|
|
146
142
|
|
|
147
143
|
/**
|
|
148
144
|
* @param {closeCallback} cb
|
|
149
|
-
* @
|
|
145
|
+
* @return {TCaBCIClient}
|
|
150
146
|
*/
|
|
151
147
|
SetCloseCallback(cb) {
|
|
152
148
|
this._closeCb = cb
|
|
@@ -156,7 +152,7 @@ export default class TCaBCIClient {
|
|
|
156
152
|
|
|
157
153
|
/**
|
|
158
154
|
* @param {listenCallback} cb
|
|
159
|
-
* @
|
|
155
|
+
* @return {TCaBCIClient}
|
|
160
156
|
*/
|
|
161
157
|
SetListenCallback(cb) {
|
|
162
158
|
this._listenCb = cb
|
|
@@ -183,6 +179,15 @@ export default class TCaBCIClient {
|
|
|
183
179
|
return this
|
|
184
180
|
}
|
|
185
181
|
|
|
182
|
+
Status() {
|
|
183
|
+
return {
|
|
184
|
+
chain_name: this._chainName,
|
|
185
|
+
chain_version: this._chainVersion,
|
|
186
|
+
connected: this._connected,
|
|
187
|
+
subscribed: this._subscribed,
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
186
191
|
/**
|
|
187
192
|
* @param {Array<string>} addresses
|
|
188
193
|
* @param {Object} signedData
|
|
@@ -232,13 +237,7 @@ export default class TCaBCIClient {
|
|
|
232
237
|
sdata = this.getSubscribedSignedData()
|
|
233
238
|
}
|
|
234
239
|
|
|
235
|
-
const message = new Message(
|
|
236
|
-
true,
|
|
237
|
-
MESSAGE_TYPE.SUBSCRIBE,
|
|
238
|
-
addrs,
|
|
239
|
-
sdata,
|
|
240
|
-
txTypes,
|
|
241
|
-
)
|
|
240
|
+
const message = new Message(true, SUBSCRIBEMessage, addrs, sdata, txTypes)
|
|
242
241
|
|
|
243
242
|
this._ws.send(message.ToJSON())
|
|
244
243
|
this.setSubscribeAddresses(addrs, true)
|
|
@@ -248,6 +247,9 @@ export default class TCaBCIClient {
|
|
|
248
247
|
return this
|
|
249
248
|
}
|
|
250
249
|
|
|
250
|
+
/**
|
|
251
|
+
* @return {TCaBCIClient}
|
|
252
|
+
*/
|
|
251
253
|
Unsubscribe() {
|
|
252
254
|
if (!this.getSubscribed()) {
|
|
253
255
|
throw new Error(NOT_SUBSCRIBED)
|
|
@@ -255,22 +257,24 @@ export default class TCaBCIClient {
|
|
|
255
257
|
this._ws.send(
|
|
256
258
|
new Message(
|
|
257
259
|
true,
|
|
258
|
-
|
|
260
|
+
UNSUBSCRIBEMessage,
|
|
259
261
|
this.getSubscribeAddresses(),
|
|
260
262
|
).ToJSON(),
|
|
261
263
|
)
|
|
262
264
|
this.setSubscribed(false)
|
|
263
265
|
this.setSubscribeAddresses([])
|
|
264
266
|
this.setSubscribeSignedData({})
|
|
267
|
+
|
|
268
|
+
return this
|
|
265
269
|
}
|
|
266
270
|
|
|
267
271
|
/**
|
|
268
272
|
* @param {?string} chainName
|
|
269
273
|
* @param {?string} chainVersion
|
|
270
|
-
* @return {Promise<
|
|
274
|
+
* @return {Promise<{blocks: Object<string, *>, total_count: number}>}
|
|
271
275
|
*/
|
|
272
276
|
LastBlock(chainName = null, chainVersion = null) {
|
|
273
|
-
return this.
|
|
277
|
+
return this._httpClient(
|
|
274
278
|
`/v1/blocks?chain_name=${chainName ?? this._chainName}&chain_version=${chainVersion ?? this._chainVersion}&limit=1&offset=0`,
|
|
275
279
|
{
|
|
276
280
|
method: 'GET',
|
|
@@ -279,7 +283,7 @@ export default class TCaBCIClient {
|
|
|
279
283
|
.then((res) => {
|
|
280
284
|
return { blocks: res.data, total_count: res.total_count }
|
|
281
285
|
})
|
|
282
|
-
.catch((e) => this.
|
|
286
|
+
.catch((e) => this._handleRestError(e, new Error(BLOCK_NOT_FOUND)))
|
|
283
287
|
}
|
|
284
288
|
|
|
285
289
|
/**
|
|
@@ -292,14 +296,14 @@ export default class TCaBCIClient {
|
|
|
292
296
|
return Promise.reject(new Error(INVALID_ARGUMENTS))
|
|
293
297
|
}
|
|
294
298
|
|
|
295
|
-
return this.
|
|
299
|
+
return this._httpClient(`/v1/tx/${id}`, {
|
|
296
300
|
method: 'GET',
|
|
297
301
|
headers: { 'X-Signature': signature },
|
|
298
302
|
})
|
|
299
303
|
.then((res) => {
|
|
300
304
|
return { tx: res.data }
|
|
301
305
|
})
|
|
302
|
-
.catch((e) => this.
|
|
306
|
+
.catch((e) => this._handleRestError(e))
|
|
303
307
|
}
|
|
304
308
|
|
|
305
309
|
/**
|
|
@@ -325,7 +329,7 @@ export default class TCaBCIClient {
|
|
|
325
329
|
return Promise.reject(new Error(INVALID_ARGUMENTS))
|
|
326
330
|
}
|
|
327
331
|
|
|
328
|
-
return this.
|
|
332
|
+
return this._httpClient('/v1/tx_summary', {
|
|
329
333
|
method: 'POST',
|
|
330
334
|
body: JSON.stringify({
|
|
331
335
|
chain_name: chainName ?? this._chainName,
|
|
@@ -347,7 +351,7 @@ export default class TCaBCIClient {
|
|
|
347
351
|
total_count: res.total_count,
|
|
348
352
|
}
|
|
349
353
|
})
|
|
350
|
-
.catch((e) => this.
|
|
354
|
+
.catch((e) => this._handleRestError(e))
|
|
351
355
|
}
|
|
352
356
|
|
|
353
357
|
/**
|
|
@@ -387,7 +391,7 @@ export default class TCaBCIClient {
|
|
|
387
391
|
chainName = null,
|
|
388
392
|
chainVersion = null,
|
|
389
393
|
}) {
|
|
390
|
-
return this.
|
|
394
|
+
return this._httpClient('/v1/tx_search/p', {
|
|
391
395
|
method: 'POST',
|
|
392
396
|
body: JSON.stringify({
|
|
393
397
|
chain_name: chainName ?? this._chainName,
|
|
@@ -412,16 +416,7 @@ export default class TCaBCIClient {
|
|
|
412
416
|
total_count: res.total_count,
|
|
413
417
|
}
|
|
414
418
|
})
|
|
415
|
-
.catch((e) => this.
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
Status() {
|
|
419
|
-
return {
|
|
420
|
-
chain_name: this._chainName,
|
|
421
|
-
chain_version: this._chainVersion,
|
|
422
|
-
connected: this._connected,
|
|
423
|
-
subscribed: this._subscribed,
|
|
424
|
-
}
|
|
419
|
+
.catch((e) => this._handleRestError(e))
|
|
425
420
|
}
|
|
426
421
|
|
|
427
422
|
/**
|
|
@@ -544,7 +539,7 @@ export default class TCaBCIClient {
|
|
|
544
539
|
throw new Error(TRANSACTION_TYPE_NOT_VALID)
|
|
545
540
|
}
|
|
546
541
|
|
|
547
|
-
return this.
|
|
542
|
+
return this._httpClient(
|
|
548
543
|
commit ? '/v1/tx/commit' : sync ? '/v1/tx/sync' : '/v1/tx',
|
|
549
544
|
{
|
|
550
545
|
method: 'POST',
|
|
@@ -564,7 +559,7 @@ export default class TCaBCIClient {
|
|
|
564
559
|
return { data: res.data }
|
|
565
560
|
})
|
|
566
561
|
.catch((e) =>
|
|
567
|
-
this.
|
|
562
|
+
this._handleRestError(e, { 400: new Error(TRANSACTION_NOT_BROADCAST) }),
|
|
568
563
|
)
|
|
569
564
|
}
|
|
570
565
|
|
|
@@ -584,7 +579,7 @@ export default class TCaBCIClient {
|
|
|
584
579
|
chainName = null,
|
|
585
580
|
chainVersion = null,
|
|
586
581
|
) {
|
|
587
|
-
return this.
|
|
582
|
+
return this._httpClient('/v1/bulk_tx', {
|
|
588
583
|
method: 'POST',
|
|
589
584
|
body: JSON.stringify({
|
|
590
585
|
chain_name: chainName ?? this._chainName,
|
|
@@ -596,6 +591,10 @@ export default class TCaBCIClient {
|
|
|
596
591
|
})
|
|
597
592
|
}
|
|
598
593
|
|
|
594
|
+
/**
|
|
595
|
+
* @param {?number} code
|
|
596
|
+
* @return {Promise<TCaBCIClient>}
|
|
597
|
+
*/
|
|
599
598
|
async Disconnect(code = 1000) {
|
|
600
599
|
if (this.getConnected()) {
|
|
601
600
|
await this._ws.disconnect(code)
|
|
@@ -603,6 +602,8 @@ export default class TCaBCIClient {
|
|
|
603
602
|
this.setConnected(false)
|
|
604
603
|
this.setSubscribed(false)
|
|
605
604
|
}
|
|
605
|
+
|
|
606
|
+
return this
|
|
606
607
|
}
|
|
607
608
|
|
|
608
609
|
async Reconnect(code = 1000) {
|
|
@@ -639,10 +640,7 @@ export default class TCaBCIClient {
|
|
|
639
640
|
return Promise.reject(new Error(ALREADY_CONNECTED))
|
|
640
641
|
}
|
|
641
642
|
|
|
642
|
-
|
|
643
|
-
options.setCustomWS(this._wsLibrary)
|
|
644
|
-
|
|
645
|
-
this._ws = new TWebSocket(options)
|
|
643
|
+
this._ws = new TWebSocket(this._options)
|
|
646
644
|
|
|
647
645
|
this._ws.addErrorListener((e) => {
|
|
648
646
|
this.setConnected(false)
|
|
@@ -663,7 +661,7 @@ export default class TCaBCIClient {
|
|
|
663
661
|
}
|
|
664
662
|
|
|
665
663
|
this.callListenCallback(
|
|
666
|
-
!isJSON(message.data) ? message.data :
|
|
664
|
+
!isJSON(message.data) ? message.data : fromJSON(message.data),
|
|
667
665
|
)
|
|
668
666
|
})
|
|
669
667
|
|
|
@@ -728,25 +726,44 @@ export default class TCaBCIClient {
|
|
|
728
726
|
return this
|
|
729
727
|
}
|
|
730
728
|
|
|
729
|
+
/**
|
|
730
|
+
* @param {string} uri
|
|
731
|
+
* @param {RequestInit} req
|
|
732
|
+
* @return {Promise<any>}
|
|
733
|
+
*/
|
|
734
|
+
_httpClient(uri, req) {
|
|
735
|
+
req.cache = 'no-cache'
|
|
736
|
+
req.headers = {
|
|
737
|
+
Client: `tcabaci-read-js-client-${this._version}`,
|
|
738
|
+
}
|
|
739
|
+
req.priority = 'high'
|
|
740
|
+
|
|
741
|
+
return fetch(this._readNodeAddress + uri, req).then((response) =>
|
|
742
|
+
this._handleRestResponse(response),
|
|
743
|
+
)
|
|
744
|
+
}
|
|
745
|
+
|
|
731
746
|
/**
|
|
732
747
|
* @param {Response} response
|
|
733
748
|
* @return {Promise<*>}
|
|
734
749
|
*/
|
|
735
|
-
async
|
|
750
|
+
async _handleRestResponse(response) {
|
|
736
751
|
if (response.status >= 200 && response.status < 400) {
|
|
737
752
|
return response.json()
|
|
738
753
|
}
|
|
739
754
|
|
|
740
|
-
let data = await response.text()
|
|
741
|
-
|
|
742
755
|
try {
|
|
743
|
-
data = JSON.parse(
|
|
756
|
+
const data = JSON.parse(await response.text())
|
|
744
757
|
|
|
745
758
|
return Promise.reject(
|
|
746
|
-
new FetchError(data.message)
|
|
759
|
+
new FetchError(data.message)
|
|
760
|
+
.setStatus(response.status)
|
|
761
|
+
.setResponse(data),
|
|
747
762
|
)
|
|
748
763
|
} catch (e) {
|
|
749
|
-
return Promise.reject(
|
|
764
|
+
return Promise.reject(
|
|
765
|
+
new FetchError(response.statusText).setOriginError(e),
|
|
766
|
+
)
|
|
750
767
|
}
|
|
751
768
|
}
|
|
752
769
|
|
|
@@ -755,7 +772,7 @@ export default class TCaBCIClient {
|
|
|
755
772
|
* @param {?Object|Error} custom
|
|
756
773
|
* @throws Error
|
|
757
774
|
*/
|
|
758
|
-
|
|
775
|
+
_handleRestError(err, custom = null) {
|
|
759
776
|
const code = err.code
|
|
760
777
|
|
|
761
778
|
if (custom && typeof custom === 'object' && custom[code]) {
|
package/constants.d.ts
ADDED
package/constants.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
export const
|
|
2
|
-
|
|
3
|
-
UNSUBSCRIBE: 'unsubscribe',
|
|
4
|
-
},
|
|
1
|
+
export const SUBSCRIBEMessage = 'subscribe',
|
|
2
|
+
UNSUBSCRIBEMessage = 'unsubscribe',
|
|
5
3
|
CHARACTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
|
|
6
4
|
READ_NODE_ADDRESS = 'https://read-node-01.transferchain.io',
|
|
7
5
|
READ_NODE_WS_ADDRESS = 'wss://read-node-01.transferchain.io/ws'
|
package/errors.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare type ErrMessage = string
|
|
2
|
+
|
|
3
|
+
export declare const ALREADY_CONNECTED: ErrMessage,
|
|
4
|
+
NOT_CONNECTED: ErrMessage,
|
|
5
|
+
ERR_NETWORK: ErrMessage,
|
|
6
|
+
INVALID_ARGUMENTS: ErrMessage,
|
|
7
|
+
INVALID_ARGUMENT_WITH_CS: (val: string) => ErrMessage,
|
|
8
|
+
NOT_SUBSCRIBED: ErrMessage,
|
|
9
|
+
ALREADY_SUBSCRIBED: ErrMessage,
|
|
10
|
+
ADDRESSES_IS_EMPTY: ErrMessage,
|
|
11
|
+
BLOCK_NOT_FOUND: ErrMessage,
|
|
12
|
+
TRANSACTION_TYPE_NOT_VALID: ErrMessage,
|
|
13
|
+
TRANSACTION_NOT_BROADCAST: ErrMessage
|
|
14
|
+
|
|
15
|
+
export declare class FetchError extends Error {
|
|
16
|
+
code: number
|
|
17
|
+
response: Record<string, any>
|
|
18
|
+
originError?: Error
|
|
19
|
+
constructor(message: string)
|
|
20
|
+
setStatus(status: number): FetchError
|
|
21
|
+
setCode(code: number): FetchError
|
|
22
|
+
setResponse(data: Record<string, any>): FetchError
|
|
23
|
+
setOriginError(error: Error): FetchError
|
|
24
|
+
}
|
package/errors.js
CHANGED
|
@@ -13,8 +13,9 @@ export const ALREADY_CONNECTED = 'Already connected',
|
|
|
13
13
|
TRANSACTION_NOT_BROADCAST = 'Transaction can not be broadcast'
|
|
14
14
|
|
|
15
15
|
export class FetchError extends Error {
|
|
16
|
-
|
|
17
|
-
response
|
|
16
|
+
status = -1
|
|
17
|
+
response
|
|
18
|
+
originError
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* @param {string} message
|
|
@@ -24,18 +25,35 @@ export class FetchError extends Error {
|
|
|
24
25
|
this.name = 'FetchError'
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
/**
|
|
29
|
+
* @param {number} status
|
|
30
|
+
* @return {FetchError}
|
|
31
|
+
*/
|
|
32
|
+
setStatus(status) {
|
|
33
|
+
this.status = status
|
|
34
|
+
|
|
35
|
+
return this
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated use .setStatus/1
|
|
40
|
+
* @param {number} code
|
|
41
|
+
* @return {FetchError}
|
|
42
|
+
*/
|
|
27
43
|
setCode(code) {
|
|
28
|
-
this.
|
|
44
|
+
this.status = code
|
|
29
45
|
|
|
30
46
|
return this
|
|
31
47
|
}
|
|
32
48
|
|
|
33
49
|
setResponse(data) {
|
|
34
|
-
this.response =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
50
|
+
this.response = data
|
|
51
|
+
|
|
52
|
+
return this
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
setOriginError(error) {
|
|
56
|
+
this.originError = error
|
|
39
57
|
|
|
40
58
|
return this
|
|
41
59
|
}
|
package/errors_test.js
CHANGED
package/eslint.config.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import globals from 'globals'
|
|
2
|
+
import pluginJs from '@eslint/js'
|
|
3
|
+
import pluginPrettier from 'eslint-plugin-prettier/recommended'
|
|
4
|
+
|
|
5
|
+
export default [
|
|
6
|
+
{
|
|
7
|
+
languageOptions: {
|
|
8
|
+
globals: {
|
|
9
|
+
...globals.browser,
|
|
10
|
+
process: 'readonly',
|
|
11
|
+
global: 'readonly',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
pluginJs.configs.recommended,
|
|
16
|
+
{
|
|
17
|
+
ignores: ['.nyc*', 'node_modules/*', 'eslint*', '*_test.js'],
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
rules: {
|
|
21
|
+
'no-console': 'error',
|
|
22
|
+
'no-debugger': 'error',
|
|
23
|
+
'no-extra-boolean-cast': 'off',
|
|
24
|
+
'no-unused-vars': [
|
|
25
|
+
'error',
|
|
26
|
+
{
|
|
27
|
+
argsIgnorePattern: '^_',
|
|
28
|
+
varsIgnorePattern: '^_',
|
|
29
|
+
caughtErrorsIgnorePattern: '^_',
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
indent: [
|
|
33
|
+
'error',
|
|
34
|
+
2,
|
|
35
|
+
{
|
|
36
|
+
SwitchCase: 1,
|
|
37
|
+
MemberExpression: 1,
|
|
38
|
+
ImportDeclaration: 1,
|
|
39
|
+
// VariableDeclarator: { var: 2, let: 2, const: 3 },
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
pluginPrettier,
|
|
45
|
+
]
|
package/message.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MessageType } from './constants'
|
|
2
|
+
import { TXType } from './transaction'
|
|
3
|
+
|
|
4
|
+
export declare class Message {
|
|
5
|
+
constructor(
|
|
6
|
+
isWeb: boolean,
|
|
7
|
+
type: MessageType,
|
|
8
|
+
addrs: string[],
|
|
9
|
+
signedData?: Record<string, string>,
|
|
10
|
+
txTypes?: TXType[],
|
|
11
|
+
)
|
|
12
|
+
ToJSON(): string
|
|
13
|
+
}
|
package/message.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { INVALID_ARGUMENTS, INVALID_ARGUMENT_WITH_CS } from './errors.js'
|
|
2
|
-
import {
|
|
2
|
+
import { SUBSCRIBEMessage, UNSUBSCRIBEMessage } from './constants.js'
|
|
3
3
|
import { TX_TYPE_LIST } from './transaction.js'
|
|
4
4
|
|
|
5
5
|
export default class Message {
|
|
@@ -53,10 +53,7 @@ export default class Message {
|
|
|
53
53
|
throw new Error(INVALID_ARGUMENT_WITH_CS('signedData'))
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
if (
|
|
57
|
-
[MESSAGE_TYPE.SUBSCRIBE, MESSAGE_TYPE.UNSUBSCRIBE].indexOf(this._type) ===
|
|
58
|
-
-1
|
|
59
|
-
) {
|
|
56
|
+
if (![SUBSCRIBEMessage, UNSUBSCRIBEMessage].includes(this._type)) {
|
|
60
57
|
throw new Error(INVALID_ARGUMENTS)
|
|
61
58
|
}
|
|
62
59
|
|
package/package.json
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tchain/tcabci-read-js-client",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.7",
|
|
4
4
|
"description": "TransferChain Fastest Read Network WebSocket Client",
|
|
5
5
|
"main": "client.js",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "export NODE_ENV=test || SET \"NODE_ENV=test\" && mocha --require esm --timeout 5000",
|
|
9
|
-
"test:all": "export NODE_ENV=test || SET \"NODE_ENV=test\" && mocha --require esm --timeout 5000 '*_test.js'",
|
|
10
|
-
"test:coverage": "export NODE_ENV=test || SET \"NODE_ENV=test\" && nyc --reporter=text mocha --require esm --timeout 5000",
|
|
11
|
-
"format": "prettier --write \"**/*.{js,md,json}\" --ignore-path .gitignore"
|
|
12
|
-
},
|
|
13
7
|
"repository": {
|
|
14
8
|
"type": "git",
|
|
15
9
|
"url": "git+https://github.com/TransferChain/tcabci-read-js-client.git"
|
|
@@ -21,12 +15,16 @@
|
|
|
21
15
|
},
|
|
22
16
|
"homepage": "https://github.com/TransferChain/tcabci-read-js-client#readme",
|
|
23
17
|
"devDependencies": {
|
|
24
|
-
"@eslint/js": "^9.
|
|
25
|
-
"chai": "^
|
|
26
|
-
"
|
|
18
|
+
"@eslint/js": "^9.38.0",
|
|
19
|
+
"@types/chai": "^5.2.3",
|
|
20
|
+
"chai": "^6.2.0",
|
|
21
|
+
"eslint": "^9.38.0",
|
|
22
|
+
"eslint-config-prettier": "^10.1.8",
|
|
23
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
24
|
+
"esm": "^3.2.25",
|
|
27
25
|
"express": "^5.1.0",
|
|
28
|
-
"globals": "^16.
|
|
29
|
-
"mocha": "^11.7.
|
|
26
|
+
"globals": "^16.4.0",
|
|
27
|
+
"mocha": "^11.7.4",
|
|
30
28
|
"nyc": "^17.1.0",
|
|
31
29
|
"prettier": "^3.6.2",
|
|
32
30
|
"unit.js": "^2.1.1",
|
|
@@ -34,5 +32,12 @@
|
|
|
34
32
|
},
|
|
35
33
|
"dependencies": {
|
|
36
34
|
"reconnecting-websocket": "^4.4.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"format": "prettier --write \"**/*.{js,md,json}\" --ignore-path .gitignore",
|
|
38
|
+
"lint:fix": "eslint --fix",
|
|
39
|
+
"test": "export NODE_ENV=test || SET \"NODE_ENV=test\" && mocha --require esm --timeout 5000",
|
|
40
|
+
"test:all": "export NODE_ENV=test || SET \"NODE_ENV=test\" && mocha --require esm --timeout 5000 '*_test.js'",
|
|
41
|
+
"test:coverage": "export NODE_ENV=test || SET \"NODE_ENV=test\" && nyc --reporter=text mocha --require esm --timeout 5000"
|
|
37
42
|
}
|
|
38
|
-
}
|
|
43
|
+
}
|
package/transaction.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export declare type TXType = string;
|
|
2
|
+
|
|
3
|
+
export declare const TX_TYPE_MASTER: TXType,
|
|
4
|
+
TX_TYPE_ADDRESS: TXType,
|
|
5
|
+
TX_TYPE_ADDRESSES: TXType,
|
|
6
|
+
TX_TYPE_ACCOUNT: TXType,
|
|
7
|
+
TX_TYPE_ACCOUNT_INITIAL_TXS: TXType,
|
|
8
|
+
TX_TYPE_MESSAGE: TXType,
|
|
9
|
+
TX_TYPE_MESSAGE_SENT: TXType,
|
|
10
|
+
TX_TYPE_MESSAGE_THREAD_DELETE: TXType,
|
|
11
|
+
TX_TYPE_TRANSFER: TXType,
|
|
12
|
+
TX_TYPE_TRANSFER_CANCEL: TXType,
|
|
13
|
+
TX_TYPE_TRANSFER_SENT: TXType,
|
|
14
|
+
TX_TYPE_TRANSFER_RECEIVE_DELETE: TXType,
|
|
15
|
+
TX_TYPE_TRANSFER_INFO: TXType,
|
|
16
|
+
TX_TYPE_STORAGE: TXType,
|
|
17
|
+
TX_TYPE_STORAGE_DELETE: TXType,
|
|
18
|
+
TX_TYPE_BACKUP: TXType,
|
|
19
|
+
TX_TYPE_CONTACT: TXType,
|
|
20
|
+
TX_TYPE_FILE_VIRTUAL: TXType,
|
|
21
|
+
TX_TYPE_FILE_FS: TXType,
|
|
22
|
+
TX_TYPE_RFILE_VIRTUAL: TXType,
|
|
23
|
+
TX_TYPE_RFILE_FS: TXType,
|
|
24
|
+
TX_TYPE_DFILE_VIRTUAL: TXType,
|
|
25
|
+
TX_TYPE_DFILE_FS: TXType,
|
|
26
|
+
TX_TYPE_PFILE_VIRTUAL: TXType,
|
|
27
|
+
TX_TYPE_REQUEST: TXType,
|
|
28
|
+
TX_TYPE_REQUEST_IN: TXType,
|
|
29
|
+
TX_TYPE_REQUEST_UPLOAD: TXType,
|
|
30
|
+
TX_TYPE_REQUEST_CANCEL: TXType,
|
|
31
|
+
TX_TYPE_DATA_ROOM: TXType,
|
|
32
|
+
TX_TYPE_DATA_ROOMF: TXType,
|
|
33
|
+
TX_TYPE_DATA_ROOM_POLICY: TXType,
|
|
34
|
+
TX_TYPE_DATA_ROOM_DATA: TXType,
|
|
35
|
+
TX_TYPE_DATA_ROOM_DATA_DELETE: TXType,
|
|
36
|
+
TX_TYPE_DATA_ROOM_DATA_POLICY: TXType,
|
|
37
|
+
TX_TYPE_MULTI_DATA_ROOM: TXType,
|
|
38
|
+
TX_TYPE_MULTI_STORAGE: TXType,
|
|
39
|
+
TX_TYPE_MULTI_TRANSFER: TXType,
|
|
40
|
+
TX_TYPE_MULTI_TRANSFER_SENT: TXType,
|
|
41
|
+
TX_TYPE_MULTI_BACKUP: TXType,
|
|
42
|
+
TX_TYPE_MULTI_PASSWD: TXType,
|
|
43
|
+
TX_TYPE_PASSWD_DATA: TXType,
|
|
44
|
+
TX_TYPE_PASSWD_ROOM: TXType,
|
|
45
|
+
TX_TYPE_PASSWD_ROOMF: TXType,
|
|
46
|
+
TX_TYPE_PASSWD_ROOM_POLICY: TXType,
|
|
47
|
+
TX_TYPE_PASSWD_ROOM_DATA: TXType,
|
|
48
|
+
TX_TYPE_PASSWD_ROOM_DATA_DELETE: TXType,
|
|
49
|
+
TX_TYPE_PASSWD_ROOM_DATA_POLICY: TXType,
|
|
50
|
+
TX_TYPE_PASSWD_DATAV2: TXType,
|
|
51
|
+
TX_TYPE_PASSWD_DATAV2_POLICY: TXType,
|
|
52
|
+
TX_TYPE_COLLECTION: TXType,
|
|
53
|
+
TX_TYPE_COLLECTION_POLICY: TXType;
|
|
54
|
+
|
|
55
|
+
export declare const TX_TYPE: Record<string, TXType>,
|
|
56
|
+
TX_TYPE_LIST: TXType[];
|
|
57
|
+
|
|
58
|
+
export declare class Transaction {
|
|
59
|
+
constructor(
|
|
60
|
+
id: string,
|
|
61
|
+
height: number,
|
|
62
|
+
version: number,
|
|
63
|
+
typ: TXType,
|
|
64
|
+
sender_addr: string,
|
|
65
|
+
recipient_addr: string,
|
|
66
|
+
data: string,
|
|
67
|
+
sign: string,
|
|
68
|
+
fee: number,
|
|
69
|
+
hash: string,
|
|
70
|
+
inserted_at: Date,
|
|
71
|
+
)
|
|
72
|
+
get ID(): string;
|
|
73
|
+
get Height(): number;
|
|
74
|
+
get Version(): number;
|
|
75
|
+
get Typ(): TXType;
|
|
76
|
+
get SenderAddr(): string;
|
|
77
|
+
get RecipientAddr(): string;
|
|
78
|
+
get Data(): string;
|
|
79
|
+
get Sign(): string;
|
|
80
|
+
get Fee(): number;
|
|
81
|
+
get Hash(): string;
|
|
82
|
+
get InsertedAt(): Date;
|
|
83
|
+
ToJSON(): string;
|
|
84
|
+
}
|
package/transaction.js
CHANGED
package/util.d.ts
ADDED
package/util.js
CHANGED
package/websocket.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Options } from './websocketOptions'
|
|
2
|
+
|
|
3
|
+
export declare const MaxListenerSize: number
|
|
4
|
+
|
|
5
|
+
export declare class TWebSocket {
|
|
6
|
+
constructor(options: Options)
|
|
7
|
+
get ready(): boolean
|
|
8
|
+
get openListeners(): (() => void)[]
|
|
9
|
+
get messageListeners(): (() => void)[]
|
|
10
|
+
get errorListeners(): (() => void)[]
|
|
11
|
+
get closeListeners(): (() => void)[]
|
|
12
|
+
connect(force?: boolean): Awaited<TWebSocket>
|
|
13
|
+
reconnect(code: number): Awaited<TWebSocket>
|
|
14
|
+
disconnect(code: number): Awaited<TWebSocket>
|
|
15
|
+
send(message: (string|ArrayBufferLike|Blob|ArrayBufferView)): void
|
|
16
|
+
addOpenListener(callback: (event: Event) => void): TWebSocket
|
|
17
|
+
removeOpenListener(callback: (event: Event) => void): TWebSocket
|
|
18
|
+
addMessageListener(callback: (event: Event) => void): TWebSocket
|
|
19
|
+
removeMessageListener(callback: (event: Event) => void): TWebSocket
|
|
20
|
+
addErrorListener(callback: (event: Event) => void): TWebSocket
|
|
21
|
+
removeErrorListener(callback: (event: Event) => void): TWebSocket
|
|
22
|
+
addCloseListener(callback: (event: Event) => void): TWebSocket
|
|
23
|
+
removeCloseListener(callback: (event: Event) => void): TWebSocket
|
|
24
|
+
}
|
package/websocket.js
CHANGED
|
@@ -49,28 +49,28 @@ export class TWebSocket {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
|
-
* @return {Array<
|
|
52
|
+
* @return {Array<function>}
|
|
53
53
|
*/
|
|
54
54
|
get openListeners() {
|
|
55
55
|
return this._openCallbacks
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* @return {Array<
|
|
59
|
+
* @return {Array<function>}
|
|
60
60
|
*/
|
|
61
61
|
get messageListeners() {
|
|
62
62
|
return this._messageCallbacks
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
-
* @return {Array<
|
|
66
|
+
* @return {Array<function>}
|
|
67
67
|
*/
|
|
68
68
|
get errorListeners() {
|
|
69
69
|
return this._errorCallbacks
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
* @return {Array<
|
|
73
|
+
* @return {Array<function>}
|
|
74
74
|
*/
|
|
75
75
|
get closeListeners() {
|
|
76
76
|
return this._closeCallbacks
|
|
@@ -252,8 +252,8 @@ export class TWebSocket {
|
|
|
252
252
|
|
|
253
253
|
_make() {
|
|
254
254
|
this._client = new ReconnectingWebSocket(
|
|
255
|
-
this._options.url
|
|
256
|
-
this._options.protocols
|
|
255
|
+
this._options.url,
|
|
256
|
+
this._options.protocols,
|
|
257
257
|
this._options.make(),
|
|
258
258
|
)
|
|
259
259
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare type Timeout = number
|
|
2
|
+
export declare const DefaultTimeout: Timeout, LongTimeout: Timeout
|
|
3
|
+
|
|
4
|
+
export declare type Port = number
|
|
5
|
+
export declare const HTTPSPort: Port, HTTPPort: Port
|
|
6
|
+
|
|
7
|
+
export declare class Options {
|
|
8
|
+
constructor(
|
|
9
|
+
host: string,
|
|
10
|
+
timeout: Timeout,
|
|
11
|
+
secure: boolean,
|
|
12
|
+
port: Port,
|
|
13
|
+
longpoll: boolean,
|
|
14
|
+
)
|
|
15
|
+
check(): boolean
|
|
16
|
+
isLongPool(): boolean
|
|
17
|
+
setDebug(debug: boolean): Options
|
|
18
|
+
get debug(): boolean
|
|
19
|
+
setEndpoints(wsEndpoint: string, longpollEndpoint: string): Options
|
|
20
|
+
endpoints(): string[]
|
|
21
|
+
setMaxConnectionDelay(delay: number): Options
|
|
22
|
+
get maxConnectionDelay(): number
|
|
23
|
+
setMinReconnectionDelay(delay: number): Options
|
|
24
|
+
get minReconnectionDelay(): number
|
|
25
|
+
setReconnectionDelayGrowFactor(gw: number): Options
|
|
26
|
+
get reconnectionDelayGrowFactor(): number
|
|
27
|
+
setMinUptime(ut: number): Options
|
|
28
|
+
get minUptime(): number
|
|
29
|
+
setMaxRetries(retries: number): Options
|
|
30
|
+
get maxRetries(): number
|
|
31
|
+
setMaxEnqueuedMessages(em: number): Options
|
|
32
|
+
get maxEnqueuedMessages(): number
|
|
33
|
+
setProtocols(protocols: string[]): Options
|
|
34
|
+
get protocols(): string[]
|
|
35
|
+
setCustomWS(customWS: WebSocket): Options
|
|
36
|
+
get customWS(): WebSocket | undefined
|
|
37
|
+
get url(): string
|
|
38
|
+
make(): {
|
|
39
|
+
WebSocket?: any
|
|
40
|
+
maxReconnectionDelay: number
|
|
41
|
+
minReconnectionDelay: number
|
|
42
|
+
reconnectionDelayGrowFactor: number
|
|
43
|
+
minUptime: number
|
|
44
|
+
connectionTimeout: number
|
|
45
|
+
maxRetries: number
|
|
46
|
+
maxEnqueuedMessages: number
|
|
47
|
+
startClosed: boolean
|
|
48
|
+
debug: boolean
|
|
49
|
+
}
|
|
50
|
+
}
|
package/websocketOptions.js
CHANGED
|
@@ -13,7 +13,7 @@ export class Options {
|
|
|
13
13
|
_protocols = []
|
|
14
14
|
_customWS
|
|
15
15
|
_endpoints = ['ws', 'longpoll']
|
|
16
|
-
_version = `v2.5.
|
|
16
|
+
_version = `v2.5.7`
|
|
17
17
|
|
|
18
18
|
_maxConnectionDelay = 10000
|
|
19
19
|
_minReconnectionDelay = 1000 + Math.random() * 4000
|
|
@@ -54,8 +54,9 @@ export class Options {
|
|
|
54
54
|
if (this._timeout > LongTimeout)
|
|
55
55
|
throw new Error(`timeout less than LongTimeout`)
|
|
56
56
|
|
|
57
|
+
// eslint-disable-next-line
|
|
57
58
|
try {
|
|
58
|
-
new URL(this.url
|
|
59
|
+
new URL(this.url)
|
|
59
60
|
|
|
60
61
|
return true
|
|
61
62
|
} catch (e) {
|
|
@@ -66,7 +67,7 @@ export class Options {
|
|
|
66
67
|
/**
|
|
67
68
|
* @return {boolean}
|
|
68
69
|
*/
|
|
69
|
-
isLongPool() {
|
|
70
|
+
get isLongPool() {
|
|
70
71
|
// return this._longpoll
|
|
71
72
|
|
|
72
73
|
return false
|
|
@@ -85,7 +86,7 @@ export class Options {
|
|
|
85
86
|
/**
|
|
86
87
|
* @return {boolean}
|
|
87
88
|
*/
|
|
88
|
-
debug() {
|
|
89
|
+
get debug() {
|
|
89
90
|
return this._debug
|
|
90
91
|
}
|
|
91
92
|
|
|
@@ -99,12 +100,14 @@ export class Options {
|
|
|
99
100
|
throw new TypeError('invalid endpoints')
|
|
100
101
|
|
|
101
102
|
this._endpoints = [wsEndpoint, longpollEndpoint]
|
|
103
|
+
|
|
104
|
+
return this
|
|
102
105
|
}
|
|
103
106
|
|
|
104
107
|
/**
|
|
105
108
|
* @return {Array<string>}
|
|
106
109
|
*/
|
|
107
|
-
endpoints() {
|
|
110
|
+
get endpoints() {
|
|
108
111
|
return this._endpoints
|
|
109
112
|
}
|
|
110
113
|
|
|
@@ -121,7 +124,7 @@ export class Options {
|
|
|
121
124
|
/**
|
|
122
125
|
* @return {number}
|
|
123
126
|
*/
|
|
124
|
-
maxConnectionDelay() {
|
|
127
|
+
get maxConnectionDelay() {
|
|
125
128
|
return this._maxConnectionDelay
|
|
126
129
|
}
|
|
127
130
|
|
|
@@ -138,7 +141,7 @@ export class Options {
|
|
|
138
141
|
/**
|
|
139
142
|
* @return {number}
|
|
140
143
|
*/
|
|
141
|
-
minReconnectionDelay() {
|
|
144
|
+
get minReconnectionDelay() {
|
|
142
145
|
return this._minReconnectionDelay
|
|
143
146
|
}
|
|
144
147
|
|
|
@@ -155,7 +158,7 @@ export class Options {
|
|
|
155
158
|
/**
|
|
156
159
|
* @return {number}
|
|
157
160
|
*/
|
|
158
|
-
reconnectionDelayGrowFactor() {
|
|
161
|
+
get reconnectionDelayGrowFactor() {
|
|
159
162
|
return this._reconnectionDelayGrowFactor
|
|
160
163
|
}
|
|
161
164
|
|
|
@@ -172,7 +175,7 @@ export class Options {
|
|
|
172
175
|
/**
|
|
173
176
|
* @return {number}
|
|
174
177
|
*/
|
|
175
|
-
minUptime() {
|
|
178
|
+
get minUptime() {
|
|
176
179
|
return this._minUptime
|
|
177
180
|
}
|
|
178
181
|
|
|
@@ -189,7 +192,7 @@ export class Options {
|
|
|
189
192
|
/**
|
|
190
193
|
* @return {number}
|
|
191
194
|
*/
|
|
192
|
-
maxRetries() {
|
|
195
|
+
get maxRetries() {
|
|
193
196
|
return this._maxRetries
|
|
194
197
|
}
|
|
195
198
|
|
|
@@ -206,7 +209,7 @@ export class Options {
|
|
|
206
209
|
/**
|
|
207
210
|
* @return {number}
|
|
208
211
|
*/
|
|
209
|
-
maxEnqueuedMessages() {
|
|
212
|
+
get maxEnqueuedMessages() {
|
|
210
213
|
return this._maxEnqueuedMessages
|
|
211
214
|
}
|
|
212
215
|
|
|
@@ -226,7 +229,7 @@ export class Options {
|
|
|
226
229
|
/**
|
|
227
230
|
* @return {Array<string>}
|
|
228
231
|
*/
|
|
229
|
-
protocols() {
|
|
232
|
+
get protocols() {
|
|
230
233
|
return this._protocols
|
|
231
234
|
}
|
|
232
235
|
|
|
@@ -243,14 +246,14 @@ export class Options {
|
|
|
243
246
|
/**
|
|
244
247
|
* @return {any}
|
|
245
248
|
*/
|
|
246
|
-
customWS() {
|
|
249
|
+
get customWS() {
|
|
247
250
|
return this._customWS
|
|
248
251
|
}
|
|
249
252
|
|
|
250
253
|
/**
|
|
251
254
|
* @return {string}
|
|
252
255
|
*/
|
|
253
|
-
url() {
|
|
256
|
+
get url() {
|
|
254
257
|
if (this._host.length > 2 && this._host.slice(0, 2) === 'ws') {
|
|
255
258
|
return `${this._host}${![HTTPPort, HTTPSPort].includes(this._port) ? `:${this._port}` : ''}`
|
|
256
259
|
}
|
package/websocketOptions_test.js
CHANGED
|
@@ -44,7 +44,7 @@ describe('Options', () => {
|
|
|
44
44
|
it('isLongPoll/0', () => {
|
|
45
45
|
const options = new Options('localhost')
|
|
46
46
|
|
|
47
|
-
expect(options.isLongPool
|
|
47
|
+
expect(options.isLongPool).to.be.equal(false)
|
|
48
48
|
})
|
|
49
49
|
|
|
50
50
|
it('setEndpoints/2 with valid params', () => {
|
|
@@ -81,7 +81,7 @@ describe('Options', () => {
|
|
|
81
81
|
const options = new Options('localhost')
|
|
82
82
|
|
|
83
83
|
options.setProtocols(['wamp', 'soap'])
|
|
84
|
-
expect(options.protocols
|
|
84
|
+
expect(options.protocols).to.have.deep.members(['wamp', 'soap'])
|
|
85
85
|
})
|
|
86
86
|
|
|
87
87
|
it('setCustomWS/1 with valid params', () => {
|
|
@@ -94,25 +94,25 @@ describe('Options', () => {
|
|
|
94
94
|
const options = new Options('localhost')
|
|
95
95
|
|
|
96
96
|
options.setCustomWS(WebSocket)
|
|
97
|
-
expect(options.customWS
|
|
97
|
+
expect(options.customWS).to.be.eq(WebSocket)
|
|
98
98
|
})
|
|
99
99
|
|
|
100
100
|
it('url/0', () => {
|
|
101
101
|
const options = new Options('localhost.localdomain')
|
|
102
102
|
|
|
103
|
-
expect(options.url
|
|
103
|
+
expect(options.url).to.equal('wss://localhost.localdomain/ws')
|
|
104
104
|
})
|
|
105
105
|
|
|
106
106
|
it('url/0 with protocol', () => {
|
|
107
107
|
const options = new Options('ws://localhost.localdomain')
|
|
108
108
|
|
|
109
|
-
expect(options.url
|
|
109
|
+
expect(options.url).to.equal('ws://localhost.localdomain')
|
|
110
110
|
})
|
|
111
111
|
|
|
112
112
|
it('url/0 with protocol case two', () => {
|
|
113
113
|
const options = new Options('wss://localhost.localdomain/ws')
|
|
114
114
|
|
|
115
|
-
expect(options.url
|
|
115
|
+
expect(options.url).to.equal('wss://localhost.localdomain/ws')
|
|
116
116
|
})
|
|
117
117
|
|
|
118
118
|
it('make/0', () => {
|