@0xsequence/indexer 1.9.24 → 1.9.26
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/0xsequence-indexer.cjs.dev.js +524 -53
- package/dist/0xsequence-indexer.cjs.prod.js +524 -53
- package/dist/0xsequence-indexer.esm.js +499 -54
- package/dist/declarations/src/indexer.gen.d.ts +219 -64
- package/package.json +1 -1
- package/src/indexer.gen.ts +986 -218
|
@@ -14,11 +14,11 @@ function _extends() {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/* eslint-disable */
|
|
17
|
-
// sequence-indexer v0.4.0
|
|
17
|
+
// sequence-indexer v0.4.0 d33d29bc84a4439a42a4e1533035bc80c4ea226e
|
|
18
18
|
// --
|
|
19
|
-
// Code generated by webrpc-gen@v0.
|
|
19
|
+
// Code generated by webrpc-gen@v0.18.6 with typescript generator. DO NOT EDIT.
|
|
20
20
|
//
|
|
21
|
-
// webrpc-gen -schema=indexer.ridl -target=typescript
|
|
21
|
+
// webrpc-gen -schema=indexer.ridl -target=typescript -client -out=./clients/indexer.gen.ts
|
|
22
22
|
|
|
23
23
|
// WebRPC description and code-gen version
|
|
24
24
|
const WebRPCVersion = 'v1';
|
|
@@ -27,7 +27,7 @@ const WebRPCVersion = 'v1';
|
|
|
27
27
|
const WebRPCSchemaVersion = 'v0.4.0';
|
|
28
28
|
|
|
29
29
|
// Schema hash generated from your RIDL schema
|
|
30
|
-
const WebRPCSchemaHash = '
|
|
30
|
+
const WebRPCSchemaHash = 'd33d29bc84a4439a42a4e1533035bc80c4ea226e';
|
|
31
31
|
|
|
32
32
|
//
|
|
33
33
|
// Types
|
|
@@ -95,63 +95,87 @@ class Indexer {
|
|
|
95
95
|
this.hostname = void 0;
|
|
96
96
|
this.fetch = void 0;
|
|
97
97
|
this.path = '/rpc/Indexer/';
|
|
98
|
-
this.ping = headers => {
|
|
99
|
-
return this.fetch(this.url('Ping'), createHTTPRequest({}, headers)).then(res => {
|
|
98
|
+
this.ping = (headers, signal) => {
|
|
99
|
+
return this.fetch(this.url('Ping'), createHTTPRequest({}, headers, signal)).then(res => {
|
|
100
100
|
return buildResponse(res).then(_data => {
|
|
101
101
|
return {
|
|
102
102
|
status: _data.status
|
|
103
103
|
};
|
|
104
104
|
});
|
|
105
|
+
}, error => {
|
|
106
|
+
throw WebrpcRequestFailedError.new({
|
|
107
|
+
cause: `fetch(): ${error.message || ''}`
|
|
108
|
+
});
|
|
105
109
|
});
|
|
106
110
|
};
|
|
107
|
-
this.version = headers => {
|
|
108
|
-
return this.fetch(this.url('Version'), createHTTPRequest({}, headers)).then(res => {
|
|
111
|
+
this.version = (headers, signal) => {
|
|
112
|
+
return this.fetch(this.url('Version'), createHTTPRequest({}, headers, signal)).then(res => {
|
|
109
113
|
return buildResponse(res).then(_data => {
|
|
110
114
|
return {
|
|
111
115
|
version: _data.version
|
|
112
116
|
};
|
|
113
117
|
});
|
|
118
|
+
}, error => {
|
|
119
|
+
throw WebrpcRequestFailedError.new({
|
|
120
|
+
cause: `fetch(): ${error.message || ''}`
|
|
121
|
+
});
|
|
114
122
|
});
|
|
115
123
|
};
|
|
116
|
-
this.runtimeStatus = headers => {
|
|
117
|
-
return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers)).then(res => {
|
|
124
|
+
this.runtimeStatus = (headers, signal) => {
|
|
125
|
+
return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers, signal)).then(res => {
|
|
118
126
|
return buildResponse(res).then(_data => {
|
|
119
127
|
return {
|
|
120
128
|
status: _data.status
|
|
121
129
|
};
|
|
122
130
|
});
|
|
131
|
+
}, error => {
|
|
132
|
+
throw WebrpcRequestFailedError.new({
|
|
133
|
+
cause: `fetch(): ${error.message || ''}`
|
|
134
|
+
});
|
|
123
135
|
});
|
|
124
136
|
};
|
|
125
|
-
this.getChainID = headers => {
|
|
126
|
-
return this.fetch(this.url('GetChainID'), createHTTPRequest({}, headers)).then(res => {
|
|
137
|
+
this.getChainID = (headers, signal) => {
|
|
138
|
+
return this.fetch(this.url('GetChainID'), createHTTPRequest({}, headers, signal)).then(res => {
|
|
127
139
|
return buildResponse(res).then(_data => {
|
|
128
140
|
return {
|
|
129
141
|
chainID: _data.chainID
|
|
130
142
|
};
|
|
131
143
|
});
|
|
144
|
+
}, error => {
|
|
145
|
+
throw WebrpcRequestFailedError.new({
|
|
146
|
+
cause: `fetch(): ${error.message || ''}`
|
|
147
|
+
});
|
|
132
148
|
});
|
|
133
149
|
};
|
|
134
|
-
this.getEtherBalance = (args, headers) => {
|
|
135
|
-
return this.fetch(this.url('GetEtherBalance'), createHTTPRequest(args, headers)).then(res => {
|
|
150
|
+
this.getEtherBalance = (args, headers, signal) => {
|
|
151
|
+
return this.fetch(this.url('GetEtherBalance'), createHTTPRequest(args, headers, signal)).then(res => {
|
|
136
152
|
return buildResponse(res).then(_data => {
|
|
137
153
|
return {
|
|
138
154
|
balance: _data.balance
|
|
139
155
|
};
|
|
140
156
|
});
|
|
157
|
+
}, error => {
|
|
158
|
+
throw WebrpcRequestFailedError.new({
|
|
159
|
+
cause: `fetch(): ${error.message || ''}`
|
|
160
|
+
});
|
|
141
161
|
});
|
|
142
162
|
};
|
|
143
|
-
this.getTokenBalances = (args, headers) => {
|
|
144
|
-
return this.fetch(this.url('GetTokenBalances'), createHTTPRequest(args, headers)).then(res => {
|
|
163
|
+
this.getTokenBalances = (args, headers, signal) => {
|
|
164
|
+
return this.fetch(this.url('GetTokenBalances'), createHTTPRequest(args, headers, signal)).then(res => {
|
|
145
165
|
return buildResponse(res).then(_data => {
|
|
146
166
|
return {
|
|
147
167
|
page: _data.page,
|
|
148
168
|
balances: _data.balances
|
|
149
169
|
};
|
|
150
170
|
});
|
|
171
|
+
}, error => {
|
|
172
|
+
throw WebrpcRequestFailedError.new({
|
|
173
|
+
cause: `fetch(): ${error.message || ''}`
|
|
174
|
+
});
|
|
151
175
|
});
|
|
152
176
|
};
|
|
153
|
-
this.getTokenSupplies = (args, headers) => {
|
|
154
|
-
return this.fetch(this.url('GetTokenSupplies'), createHTTPRequest(args, headers)).then(res => {
|
|
177
|
+
this.getTokenSupplies = (args, headers, signal) => {
|
|
178
|
+
return this.fetch(this.url('GetTokenSupplies'), createHTTPRequest(args, headers, signal)).then(res => {
|
|
155
179
|
return buildResponse(res).then(_data => {
|
|
156
180
|
return {
|
|
157
181
|
page: _data.page,
|
|
@@ -159,127 +183,199 @@ class Indexer {
|
|
|
159
183
|
tokenIDs: _data.tokenIDs
|
|
160
184
|
};
|
|
161
185
|
});
|
|
186
|
+
}, error => {
|
|
187
|
+
throw WebrpcRequestFailedError.new({
|
|
188
|
+
cause: `fetch(): ${error.message || ''}`
|
|
189
|
+
});
|
|
162
190
|
});
|
|
163
191
|
};
|
|
164
|
-
this.getTokenSuppliesMap = (args, headers) => {
|
|
165
|
-
return this.fetch(this.url('GetTokenSuppliesMap'), createHTTPRequest(args, headers)).then(res => {
|
|
192
|
+
this.getTokenSuppliesMap = (args, headers, signal) => {
|
|
193
|
+
return this.fetch(this.url('GetTokenSuppliesMap'), createHTTPRequest(args, headers, signal)).then(res => {
|
|
166
194
|
return buildResponse(res).then(_data => {
|
|
167
195
|
return {
|
|
168
196
|
supplies: _data.supplies
|
|
169
197
|
};
|
|
170
198
|
});
|
|
199
|
+
}, error => {
|
|
200
|
+
throw WebrpcRequestFailedError.new({
|
|
201
|
+
cause: `fetch(): ${error.message || ''}`
|
|
202
|
+
});
|
|
171
203
|
});
|
|
172
204
|
};
|
|
173
|
-
this.getBalanceUpdates = (args, headers) => {
|
|
174
|
-
return this.fetch(this.url('GetBalanceUpdates'), createHTTPRequest(args, headers)).then(res => {
|
|
205
|
+
this.getBalanceUpdates = (args, headers, signal) => {
|
|
206
|
+
return this.fetch(this.url('GetBalanceUpdates'), createHTTPRequest(args, headers, signal)).then(res => {
|
|
175
207
|
return buildResponse(res).then(_data => {
|
|
176
208
|
return {
|
|
177
209
|
page: _data.page,
|
|
178
210
|
balances: _data.balances
|
|
179
211
|
};
|
|
180
212
|
});
|
|
213
|
+
}, error => {
|
|
214
|
+
throw WebrpcRequestFailedError.new({
|
|
215
|
+
cause: `fetch(): ${error.message || ''}`
|
|
216
|
+
});
|
|
181
217
|
});
|
|
182
218
|
};
|
|
183
|
-
this.getTransactionHistory = (args, headers) => {
|
|
184
|
-
return this.fetch(this.url('GetTransactionHistory'), createHTTPRequest(args, headers)).then(res => {
|
|
219
|
+
this.getTransactionHistory = (args, headers, signal) => {
|
|
220
|
+
return this.fetch(this.url('GetTransactionHistory'), createHTTPRequest(args, headers, signal)).then(res => {
|
|
185
221
|
return buildResponse(res).then(_data => {
|
|
186
222
|
return {
|
|
187
223
|
page: _data.page,
|
|
188
224
|
transactions: _data.transactions
|
|
189
225
|
};
|
|
190
226
|
});
|
|
227
|
+
}, error => {
|
|
228
|
+
throw WebrpcRequestFailedError.new({
|
|
229
|
+
cause: `fetch(): ${error.message || ''}`
|
|
230
|
+
});
|
|
191
231
|
});
|
|
192
232
|
};
|
|
193
|
-
this.syncBalance = (args, headers) => {
|
|
194
|
-
return this.fetch(this.url('SyncBalance'), createHTTPRequest(args, headers)).then(res => {
|
|
233
|
+
this.syncBalance = (args, headers, signal) => {
|
|
234
|
+
return this.fetch(this.url('SyncBalance'), createHTTPRequest(args, headers, signal)).then(res => {
|
|
195
235
|
return buildResponse(res).then(_data => {
|
|
196
236
|
return {};
|
|
197
237
|
});
|
|
238
|
+
}, error => {
|
|
239
|
+
throw WebrpcRequestFailedError.new({
|
|
240
|
+
cause: `fetch(): ${error.message || ''}`
|
|
241
|
+
});
|
|
198
242
|
});
|
|
199
243
|
};
|
|
200
|
-
this.fetchTransactionReceipt = (args, headers) => {
|
|
201
|
-
return this.fetch(this.url('FetchTransactionReceipt'), createHTTPRequest(args, headers)).then(res => {
|
|
244
|
+
this.fetchTransactionReceipt = (args, headers, signal) => {
|
|
245
|
+
return this.fetch(this.url('FetchTransactionReceipt'), createHTTPRequest(args, headers, signal)).then(res => {
|
|
202
246
|
return buildResponse(res).then(_data => {
|
|
203
247
|
return {
|
|
204
248
|
receipt: _data.receipt
|
|
205
249
|
};
|
|
206
250
|
});
|
|
251
|
+
}, error => {
|
|
252
|
+
throw WebrpcRequestFailedError.new({
|
|
253
|
+
cause: `fetch(): ${error.message || ''}`
|
|
254
|
+
});
|
|
207
255
|
});
|
|
208
256
|
};
|
|
209
|
-
this.getOrderbookOrders = (args, headers) => {
|
|
210
|
-
return this.fetch(this.url('GetOrderbookOrders'), createHTTPRequest(args, headers)).then(res => {
|
|
257
|
+
this.getOrderbookOrders = (args, headers, signal) => {
|
|
258
|
+
return this.fetch(this.url('GetOrderbookOrders'), createHTTPRequest(args, headers, signal)).then(res => {
|
|
211
259
|
return buildResponse(res).then(_data => {
|
|
212
260
|
return {
|
|
213
261
|
page: _data.page,
|
|
214
262
|
orders: _data.orders
|
|
215
263
|
};
|
|
216
264
|
});
|
|
265
|
+
}, error => {
|
|
266
|
+
throw WebrpcRequestFailedError.new({
|
|
267
|
+
cause: `fetch(): ${error.message || ''}`
|
|
268
|
+
});
|
|
217
269
|
});
|
|
218
270
|
};
|
|
219
|
-
this.getTopOrders = (args, headers) => {
|
|
220
|
-
return this.fetch(this.url('GetTopOrders'), createHTTPRequest(args, headers)).then(res => {
|
|
271
|
+
this.getTopOrders = (args, headers, signal) => {
|
|
272
|
+
return this.fetch(this.url('GetTopOrders'), createHTTPRequest(args, headers, signal)).then(res => {
|
|
221
273
|
return buildResponse(res).then(_data => {
|
|
222
274
|
return {
|
|
223
275
|
orders: _data.orders
|
|
224
276
|
};
|
|
225
277
|
});
|
|
278
|
+
}, error => {
|
|
279
|
+
throw WebrpcRequestFailedError.new({
|
|
280
|
+
cause: `fetch(): ${error.message || ''}`
|
|
281
|
+
});
|
|
226
282
|
});
|
|
227
283
|
};
|
|
228
|
-
this.fetchTransactionReceiptWithFilter = (args, headers) => {
|
|
229
|
-
return this.fetch(this.url('FetchTransactionReceiptWithFilter'), createHTTPRequest(args, headers)).then(res => {
|
|
284
|
+
this.fetchTransactionReceiptWithFilter = (args, headers, signal) => {
|
|
285
|
+
return this.fetch(this.url('FetchTransactionReceiptWithFilter'), createHTTPRequest(args, headers, signal)).then(res => {
|
|
230
286
|
return buildResponse(res).then(_data => {
|
|
231
287
|
return {
|
|
232
288
|
receipt: _data.receipt
|
|
233
289
|
};
|
|
234
290
|
});
|
|
291
|
+
}, error => {
|
|
292
|
+
throw WebrpcRequestFailedError.new({
|
|
293
|
+
cause: `fetch(): ${error.message || ''}`
|
|
294
|
+
});
|
|
235
295
|
});
|
|
236
296
|
};
|
|
237
|
-
this.getAllWebhookListeners = (args, headers) => {
|
|
238
|
-
return this.fetch(this.url('GetAllWebhookListeners'), createHTTPRequest(args, headers)).then(res => {
|
|
297
|
+
this.getAllWebhookListeners = (args, headers, signal) => {
|
|
298
|
+
return this.fetch(this.url('GetAllWebhookListeners'), createHTTPRequest(args, headers, signal)).then(res => {
|
|
239
299
|
return buildResponse(res).then(_data => {
|
|
240
300
|
return {
|
|
241
301
|
listeners: _data.listeners
|
|
242
302
|
};
|
|
243
303
|
});
|
|
304
|
+
}, error => {
|
|
305
|
+
throw WebrpcRequestFailedError.new({
|
|
306
|
+
cause: `fetch(): ${error.message || ''}`
|
|
307
|
+
});
|
|
244
308
|
});
|
|
245
309
|
};
|
|
246
|
-
this.getWebhookListener = (args, headers) => {
|
|
247
|
-
return this.fetch(this.url('GetWebhookListener'), createHTTPRequest(args, headers)).then(res => {
|
|
310
|
+
this.getWebhookListener = (args, headers, signal) => {
|
|
311
|
+
return this.fetch(this.url('GetWebhookListener'), createHTTPRequest(args, headers, signal)).then(res => {
|
|
248
312
|
return buildResponse(res).then(_data => {
|
|
249
313
|
return {
|
|
250
314
|
listener: _data.listener
|
|
251
315
|
};
|
|
252
316
|
});
|
|
317
|
+
}, error => {
|
|
318
|
+
throw WebrpcRequestFailedError.new({
|
|
319
|
+
cause: `fetch(): ${error.message || ''}`
|
|
320
|
+
});
|
|
253
321
|
});
|
|
254
322
|
};
|
|
255
|
-
this.addWebhookListener = (args, headers) => {
|
|
256
|
-
return this.fetch(this.url('AddWebhookListener'), createHTTPRequest(args, headers)).then(res => {
|
|
323
|
+
this.addWebhookListener = (args, headers, signal) => {
|
|
324
|
+
return this.fetch(this.url('AddWebhookListener'), createHTTPRequest(args, headers, signal)).then(res => {
|
|
257
325
|
return buildResponse(res).then(_data => {
|
|
258
326
|
return {
|
|
259
327
|
status: _data.status,
|
|
260
328
|
listener: _data.listener
|
|
261
329
|
};
|
|
262
330
|
});
|
|
331
|
+
}, error => {
|
|
332
|
+
throw WebrpcRequestFailedError.new({
|
|
333
|
+
cause: `fetch(): ${error.message || ''}`
|
|
334
|
+
});
|
|
263
335
|
});
|
|
264
336
|
};
|
|
265
|
-
this.updateWebhookListener = (args, headers) => {
|
|
266
|
-
return this.fetch(this.url('UpdateWebhookListener'), createHTTPRequest(args, headers)).then(res => {
|
|
337
|
+
this.updateWebhookListener = (args, headers, signal) => {
|
|
338
|
+
return this.fetch(this.url('UpdateWebhookListener'), createHTTPRequest(args, headers, signal)).then(res => {
|
|
267
339
|
return buildResponse(res).then(_data => {
|
|
268
340
|
return {
|
|
269
341
|
status: _data.status
|
|
270
342
|
};
|
|
271
343
|
});
|
|
344
|
+
}, error => {
|
|
345
|
+
throw WebrpcRequestFailedError.new({
|
|
346
|
+
cause: `fetch(): ${error.message || ''}`
|
|
347
|
+
});
|
|
272
348
|
});
|
|
273
349
|
};
|
|
274
|
-
this.removeWebhookListener = (args, headers) => {
|
|
275
|
-
return this.fetch(this.url('RemoveWebhookListener'), createHTTPRequest(args, headers)).then(res => {
|
|
350
|
+
this.removeWebhookListener = (args, headers, signal) => {
|
|
351
|
+
return this.fetch(this.url('RemoveWebhookListener'), createHTTPRequest(args, headers, signal)).then(res => {
|
|
276
352
|
return buildResponse(res).then(_data => {
|
|
277
353
|
return {
|
|
278
354
|
status: _data.status
|
|
279
355
|
};
|
|
280
356
|
});
|
|
357
|
+
}, error => {
|
|
358
|
+
throw WebrpcRequestFailedError.new({
|
|
359
|
+
cause: `fetch(): ${error.message || ''}`
|
|
360
|
+
});
|
|
281
361
|
});
|
|
282
362
|
};
|
|
363
|
+
this.subscribeReceipts = (args, options) => {
|
|
364
|
+
const _fetch = () => this.fetch(this.url('SubscribeReceipts'), createHTTPRequest(args, options.headers, options.signal)).then(async function (res) {
|
|
365
|
+
await sseResponse(res, options, _fetch);
|
|
366
|
+
}, error => {
|
|
367
|
+
options.onError(error, _fetch);
|
|
368
|
+
});
|
|
369
|
+
return _fetch();
|
|
370
|
+
};
|
|
371
|
+
this.subscribeEvents = (args, options) => {
|
|
372
|
+
const _fetch = () => this.fetch(this.url('SubscribeEvents'), createHTTPRequest(args, options.headers, options.signal)).then(async function (res) {
|
|
373
|
+
await sseResponse(res, options, _fetch);
|
|
374
|
+
}, error => {
|
|
375
|
+
options.onError(error, _fetch);
|
|
376
|
+
});
|
|
377
|
+
return _fetch();
|
|
378
|
+
};
|
|
283
379
|
this.hostname = hostname;
|
|
284
380
|
this.fetch = (input, init) => fetch(input, init);
|
|
285
381
|
}
|
|
@@ -287,13 +383,128 @@ class Indexer {
|
|
|
287
383
|
return this.hostname + this.path + name;
|
|
288
384
|
}
|
|
289
385
|
}
|
|
290
|
-
const
|
|
386
|
+
const sseResponse = async (res, options, retryFetch) => {
|
|
387
|
+
const {
|
|
388
|
+
onMessage,
|
|
389
|
+
onOpen,
|
|
390
|
+
onClose,
|
|
391
|
+
onError
|
|
392
|
+
} = options;
|
|
393
|
+
if (!res.ok) {
|
|
394
|
+
try {
|
|
395
|
+
await buildResponse(res);
|
|
396
|
+
} catch (error) {
|
|
397
|
+
// @ts-ignore
|
|
398
|
+
onError(error, retryFetch);
|
|
399
|
+
}
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (!res.body) {
|
|
403
|
+
onError(WebrpcBadResponseError.new({
|
|
404
|
+
status: res.status,
|
|
405
|
+
cause: 'Invalid response, missing body'
|
|
406
|
+
}), retryFetch);
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
onOpen && onOpen();
|
|
410
|
+
const reader = res.body.getReader();
|
|
411
|
+
const decoder = new TextDecoder();
|
|
412
|
+
let buffer = '';
|
|
413
|
+
let lastReadTime = Date.now();
|
|
414
|
+
const timeout = (10 + 1) * 1000;
|
|
415
|
+
let intervalId;
|
|
416
|
+
try {
|
|
417
|
+
intervalId = setInterval(() => {
|
|
418
|
+
if (Date.now() - lastReadTime > timeout) {
|
|
419
|
+
throw WebrpcStreamLostError.new({
|
|
420
|
+
cause: 'Stream timed out'
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
}, timeout);
|
|
424
|
+
while (true) {
|
|
425
|
+
let value;
|
|
426
|
+
let done;
|
|
427
|
+
try {
|
|
428
|
+
;
|
|
429
|
+
({
|
|
430
|
+
value,
|
|
431
|
+
done
|
|
432
|
+
} = await reader.read());
|
|
433
|
+
lastReadTime = Date.now();
|
|
434
|
+
buffer += decoder.decode(value, {
|
|
435
|
+
stream: true
|
|
436
|
+
});
|
|
437
|
+
} catch (error) {
|
|
438
|
+
let message = '';
|
|
439
|
+
if (error instanceof Error) {
|
|
440
|
+
message = error.message;
|
|
441
|
+
}
|
|
442
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
443
|
+
onError(WebrpcRequestFailedError.new({
|
|
444
|
+
message: 'AbortError',
|
|
445
|
+
cause: `AbortError: ${message}`
|
|
446
|
+
}), () => {
|
|
447
|
+
throw new Error('Abort signal cannot be used to reconnect');
|
|
448
|
+
});
|
|
449
|
+
} else {
|
|
450
|
+
onError(WebrpcStreamLostError.new({
|
|
451
|
+
cause: `reader.read(): ${message}`
|
|
452
|
+
}), retryFetch);
|
|
453
|
+
}
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
let lines = buffer.split('\n');
|
|
457
|
+
for (let i = 0; i < lines.length - 1; i++) {
|
|
458
|
+
if (lines[i].length == 0) {
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
let data;
|
|
462
|
+
try {
|
|
463
|
+
data = JSON.parse(lines[i]);
|
|
464
|
+
if (data.hasOwnProperty('webrpcError')) {
|
|
465
|
+
const error = data.webrpcError;
|
|
466
|
+
const code = typeof error.code === 'number' ? error.code : 0;
|
|
467
|
+
onError((webrpcErrorByCode[code] || WebrpcError).new(error), retryFetch);
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
} catch (error) {
|
|
471
|
+
if (error instanceof Error && error.message === 'Abort signal cannot be used to reconnect') {
|
|
472
|
+
throw error;
|
|
473
|
+
}
|
|
474
|
+
onError(WebrpcBadResponseError.new({
|
|
475
|
+
status: res.status,
|
|
476
|
+
// @ts-ignore
|
|
477
|
+
cause: `JSON.parse(): ${error.message}`
|
|
478
|
+
}), retryFetch);
|
|
479
|
+
}
|
|
480
|
+
onMessage(data);
|
|
481
|
+
}
|
|
482
|
+
if (!done) {
|
|
483
|
+
buffer = lines[lines.length - 1];
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
onClose && onClose();
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
} catch (error) {
|
|
490
|
+
// @ts-ignore
|
|
491
|
+
if (error instanceof WebrpcStreamLostError) {
|
|
492
|
+
onError(error, retryFetch);
|
|
493
|
+
} else {
|
|
494
|
+
throw error;
|
|
495
|
+
}
|
|
496
|
+
} finally {
|
|
497
|
+
clearInterval(intervalId);
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
const createHTTPRequest = (body = {}, headers = {}, signal = null) => {
|
|
291
501
|
return {
|
|
292
502
|
method: 'POST',
|
|
293
503
|
headers: _extends({}, headers, {
|
|
294
504
|
'Content-Type': 'application/json'
|
|
295
505
|
}),
|
|
296
|
-
body: JSON.stringify(body || {})
|
|
506
|
+
body: JSON.stringify(body || {}),
|
|
507
|
+
signal
|
|
297
508
|
};
|
|
298
509
|
};
|
|
299
510
|
const buildResponse = res => {
|
|
@@ -301,20 +512,254 @@ const buildResponse = res => {
|
|
|
301
512
|
let data;
|
|
302
513
|
try {
|
|
303
514
|
data = JSON.parse(text);
|
|
304
|
-
} catch (
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
515
|
+
} catch (error) {
|
|
516
|
+
let message = '';
|
|
517
|
+
if (error instanceof Error) {
|
|
518
|
+
message = error.message;
|
|
519
|
+
}
|
|
520
|
+
throw WebrpcBadResponseError.new({
|
|
521
|
+
status: res.status,
|
|
522
|
+
cause: `JSON.parse(): ${message}: response text: ${text}`
|
|
523
|
+
});
|
|
310
524
|
}
|
|
311
525
|
if (!res.ok) {
|
|
312
|
-
|
|
526
|
+
const code = typeof data.code === 'number' ? data.code : 0;
|
|
527
|
+
throw (webrpcErrorByCode[code] || WebrpcError).new(data);
|
|
313
528
|
}
|
|
314
529
|
return data;
|
|
315
530
|
});
|
|
316
531
|
};
|
|
317
532
|
|
|
533
|
+
//
|
|
534
|
+
// Errors
|
|
535
|
+
//
|
|
536
|
+
|
|
537
|
+
class WebrpcError extends Error {
|
|
538
|
+
constructor(name, code, message, status, cause) {
|
|
539
|
+
super(message);
|
|
540
|
+
this.name = void 0;
|
|
541
|
+
this.code = void 0;
|
|
542
|
+
this.message = void 0;
|
|
543
|
+
this.status = void 0;
|
|
544
|
+
this.cause = void 0;
|
|
545
|
+
/** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */
|
|
546
|
+
this.msg = void 0;
|
|
547
|
+
this.name = name || 'WebrpcError';
|
|
548
|
+
this.code = typeof code === 'number' ? code : 0;
|
|
549
|
+
this.message = message || `endpoint error ${this.code}`;
|
|
550
|
+
this.msg = this.message;
|
|
551
|
+
this.status = typeof status === 'number' ? status : 0;
|
|
552
|
+
this.cause = cause;
|
|
553
|
+
Object.setPrototypeOf(this, WebrpcError.prototype);
|
|
554
|
+
}
|
|
555
|
+
static new(payload) {
|
|
556
|
+
return new this(payload.error, payload.code, payload.message || payload.msg, payload.status, payload.cause);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
// Webrpc errors
|
|
561
|
+
|
|
562
|
+
class WebrpcEndpointError extends WebrpcError {
|
|
563
|
+
constructor(name = 'WebrpcEndpoint', code = 0, message = 'endpoint error', status = 0, cause) {
|
|
564
|
+
super(name, code, message, status, cause);
|
|
565
|
+
Object.setPrototypeOf(this, WebrpcEndpointError.prototype);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
class WebrpcRequestFailedError extends WebrpcError {
|
|
569
|
+
constructor(name = 'WebrpcRequestFailed', code = -1, message = 'request failed', status = 0, cause) {
|
|
570
|
+
super(name, code, message, status, cause);
|
|
571
|
+
Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
class WebrpcBadRouteError extends WebrpcError {
|
|
575
|
+
constructor(name = 'WebrpcBadRoute', code = -2, message = 'bad route', status = 0, cause) {
|
|
576
|
+
super(name, code, message, status, cause);
|
|
577
|
+
Object.setPrototypeOf(this, WebrpcBadRouteError.prototype);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
class WebrpcBadMethodError extends WebrpcError {
|
|
581
|
+
constructor(name = 'WebrpcBadMethod', code = -3, message = 'bad method', status = 0, cause) {
|
|
582
|
+
super(name, code, message, status, cause);
|
|
583
|
+
Object.setPrototypeOf(this, WebrpcBadMethodError.prototype);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
class WebrpcBadRequestError extends WebrpcError {
|
|
587
|
+
constructor(name = 'WebrpcBadRequest', code = -4, message = 'bad request', status = 0, cause) {
|
|
588
|
+
super(name, code, message, status, cause);
|
|
589
|
+
Object.setPrototypeOf(this, WebrpcBadRequestError.prototype);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
class WebrpcBadResponseError extends WebrpcError {
|
|
593
|
+
constructor(name = 'WebrpcBadResponse', code = -5, message = 'bad response', status = 0, cause) {
|
|
594
|
+
super(name, code, message, status, cause);
|
|
595
|
+
Object.setPrototypeOf(this, WebrpcBadResponseError.prototype);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
class WebrpcServerPanicError extends WebrpcError {
|
|
599
|
+
constructor(name = 'WebrpcServerPanic', code = -6, message = 'server panic', status = 0, cause) {
|
|
600
|
+
super(name, code, message, status, cause);
|
|
601
|
+
Object.setPrototypeOf(this, WebrpcServerPanicError.prototype);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
class WebrpcInternalErrorError extends WebrpcError {
|
|
605
|
+
constructor(name = 'WebrpcInternalError', code = -7, message = 'internal error', status = 0, cause) {
|
|
606
|
+
super(name, code, message, status, cause);
|
|
607
|
+
Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
class WebrpcClientDisconnectedError extends WebrpcError {
|
|
611
|
+
constructor(name = 'WebrpcClientDisconnected', code = -8, message = 'client disconnected', status = 0, cause) {
|
|
612
|
+
super(name, code, message, status, cause);
|
|
613
|
+
Object.setPrototypeOf(this, WebrpcClientDisconnectedError.prototype);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
class WebrpcStreamLostError extends WebrpcError {
|
|
617
|
+
constructor(name = 'WebrpcStreamLost', code = -9, message = 'stream lost', status = 0, cause) {
|
|
618
|
+
super(name, code, message, status, cause);
|
|
619
|
+
Object.setPrototypeOf(this, WebrpcStreamLostError.prototype);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
class WebrpcStreamFinishedError extends WebrpcError {
|
|
623
|
+
constructor(name = 'WebrpcStreamFinished', code = -10, message = 'stream finished', status = 0, cause) {
|
|
624
|
+
super(name, code, message, status, cause);
|
|
625
|
+
Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// Schema errors
|
|
630
|
+
|
|
631
|
+
class UnauthorizedError extends WebrpcError {
|
|
632
|
+
constructor(name = 'Unauthorized', code = 1000, message = 'Unauthorized access', status = 0, cause) {
|
|
633
|
+
super(name, code, message, status, cause);
|
|
634
|
+
Object.setPrototypeOf(this, UnauthorizedError.prototype);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
class PermissionDeniedError extends WebrpcError {
|
|
638
|
+
constructor(name = 'PermissionDenied', code = 1001, message = 'Permission denied', status = 0, cause) {
|
|
639
|
+
super(name, code, message, status, cause);
|
|
640
|
+
Object.setPrototypeOf(this, PermissionDeniedError.prototype);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
class SessionExpiredError extends WebrpcError {
|
|
644
|
+
constructor(name = 'SessionExpired', code = 1002, message = 'Session expired', status = 0, cause) {
|
|
645
|
+
super(name, code, message, status, cause);
|
|
646
|
+
Object.setPrototypeOf(this, SessionExpiredError.prototype);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
class MethodNotFoundError extends WebrpcError {
|
|
650
|
+
constructor(name = 'MethodNotFound', code = 1003, message = 'Method not found', status = 0, cause) {
|
|
651
|
+
super(name, code, message, status, cause);
|
|
652
|
+
Object.setPrototypeOf(this, MethodNotFoundError.prototype);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
class RequestConflictError extends WebrpcError {
|
|
656
|
+
constructor(name = 'RequestConflict', code = 1004, message = 'Conflict with target resource', status = 0, cause) {
|
|
657
|
+
super(name, code, message, status, cause);
|
|
658
|
+
Object.setPrototypeOf(this, RequestConflictError.prototype);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
class AbortedError extends WebrpcError {
|
|
662
|
+
constructor(name = 'Aborted', code = 1005, message = 'Request aborted', status = 0, cause) {
|
|
663
|
+
super(name, code, message, status, cause);
|
|
664
|
+
Object.setPrototypeOf(this, AbortedError.prototype);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
class TimeoutError extends WebrpcError {
|
|
668
|
+
constructor(name = 'Timeout', code = 2000, message = 'Request timed out', status = 0, cause) {
|
|
669
|
+
super(name, code, message, status, cause);
|
|
670
|
+
Object.setPrototypeOf(this, TimeoutError.prototype);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
class InvalidArgumentError extends WebrpcError {
|
|
674
|
+
constructor(name = 'InvalidArgument', code = 2001, message = 'Invalid argument', status = 0, cause) {
|
|
675
|
+
super(name, code, message, status, cause);
|
|
676
|
+
Object.setPrototypeOf(this, InvalidArgumentError.prototype);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
class UnavailableError extends WebrpcError {
|
|
680
|
+
constructor(name = 'Unavailable', code = 2002, message = 'Unavailable resource', status = 0, cause) {
|
|
681
|
+
super(name, code, message, status, cause);
|
|
682
|
+
Object.setPrototypeOf(this, UnavailableError.prototype);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
class QueryFailedError extends WebrpcError {
|
|
686
|
+
constructor(name = 'QueryFailed', code = 2003, message = 'Query failed', status = 0, cause) {
|
|
687
|
+
super(name, code, message, status, cause);
|
|
688
|
+
Object.setPrototypeOf(this, QueryFailedError.prototype);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
class NotFoundError extends WebrpcError {
|
|
692
|
+
constructor(name = 'NotFound', code = 3000, message = 'Resource not found', status = 0, cause) {
|
|
693
|
+
super(name, code, message, status, cause);
|
|
694
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
class ProjectNotFoundError extends WebrpcError {
|
|
698
|
+
constructor(name = 'ProjectNotFound', code = 3002, message = 'Project not found', status = 0, cause) {
|
|
699
|
+
super(name, code, message, status, cause);
|
|
700
|
+
Object.setPrototypeOf(this, ProjectNotFoundError.prototype);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
class MetadataCallFailedError extends WebrpcError {
|
|
704
|
+
constructor(name = 'MetadataCallFailed', code = 3003, message = 'Metadata service call failed', status = 0, cause) {
|
|
705
|
+
super(name, code, message, status, cause);
|
|
706
|
+
Object.setPrototypeOf(this, MetadataCallFailedError.prototype);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
let errors = /*#__PURE__*/function (errors) {
|
|
710
|
+
errors["WebrpcEndpoint"] = "WebrpcEndpoint";
|
|
711
|
+
errors["WebrpcRequestFailed"] = "WebrpcRequestFailed";
|
|
712
|
+
errors["WebrpcBadRoute"] = "WebrpcBadRoute";
|
|
713
|
+
errors["WebrpcBadMethod"] = "WebrpcBadMethod";
|
|
714
|
+
errors["WebrpcBadRequest"] = "WebrpcBadRequest";
|
|
715
|
+
errors["WebrpcBadResponse"] = "WebrpcBadResponse";
|
|
716
|
+
errors["WebrpcServerPanic"] = "WebrpcServerPanic";
|
|
717
|
+
errors["WebrpcInternalError"] = "WebrpcInternalError";
|
|
718
|
+
errors["WebrpcClientDisconnected"] = "WebrpcClientDisconnected";
|
|
719
|
+
errors["WebrpcStreamLost"] = "WebrpcStreamLost";
|
|
720
|
+
errors["WebrpcStreamFinished"] = "WebrpcStreamFinished";
|
|
721
|
+
errors["Unauthorized"] = "Unauthorized";
|
|
722
|
+
errors["PermissionDenied"] = "PermissionDenied";
|
|
723
|
+
errors["SessionExpired"] = "SessionExpired";
|
|
724
|
+
errors["MethodNotFound"] = "MethodNotFound";
|
|
725
|
+
errors["RequestConflict"] = "RequestConflict";
|
|
726
|
+
errors["Aborted"] = "Aborted";
|
|
727
|
+
errors["Timeout"] = "Timeout";
|
|
728
|
+
errors["InvalidArgument"] = "InvalidArgument";
|
|
729
|
+
errors["Unavailable"] = "Unavailable";
|
|
730
|
+
errors["QueryFailed"] = "QueryFailed";
|
|
731
|
+
errors["NotFound"] = "NotFound";
|
|
732
|
+
errors["ProjectNotFound"] = "ProjectNotFound";
|
|
733
|
+
errors["MetadataCallFailed"] = "MetadataCallFailed";
|
|
734
|
+
return errors;
|
|
735
|
+
}({});
|
|
736
|
+
const webrpcErrorByCode = {
|
|
737
|
+
[0]: WebrpcEndpointError,
|
|
738
|
+
[-1]: WebrpcRequestFailedError,
|
|
739
|
+
[-2]: WebrpcBadRouteError,
|
|
740
|
+
[-3]: WebrpcBadMethodError,
|
|
741
|
+
[-4]: WebrpcBadRequestError,
|
|
742
|
+
[-5]: WebrpcBadResponseError,
|
|
743
|
+
[-6]: WebrpcServerPanicError,
|
|
744
|
+
[-7]: WebrpcInternalErrorError,
|
|
745
|
+
[-8]: WebrpcClientDisconnectedError,
|
|
746
|
+
[-9]: WebrpcStreamLostError,
|
|
747
|
+
[-10]: WebrpcStreamFinishedError,
|
|
748
|
+
[1000]: UnauthorizedError,
|
|
749
|
+
[1001]: PermissionDeniedError,
|
|
750
|
+
[1002]: SessionExpiredError,
|
|
751
|
+
[1003]: MethodNotFoundError,
|
|
752
|
+
[1004]: RequestConflictError,
|
|
753
|
+
[1005]: AbortedError,
|
|
754
|
+
[2000]: TimeoutError,
|
|
755
|
+
[2001]: InvalidArgumentError,
|
|
756
|
+
[2002]: UnavailableError,
|
|
757
|
+
[2003]: QueryFailedError,
|
|
758
|
+
[3000]: NotFoundError,
|
|
759
|
+
[3002]: ProjectNotFoundError,
|
|
760
|
+
[3003]: MetadataCallFailedError
|
|
761
|
+
};
|
|
762
|
+
|
|
318
763
|
const fetch = typeof global === 'object' ? global.fetch : window.fetch;
|
|
319
764
|
class SequenceIndexer extends Indexer {
|
|
320
765
|
constructor(hostname, projectAccessKey, jwtAuth) {
|
|
@@ -342,4 +787,4 @@ class SequenceIndexer extends Indexer {
|
|
|
342
787
|
}
|
|
343
788
|
}
|
|
344
789
|
|
|
345
|
-
export { ContractType, EventLogDataType, EventLogType, Indexer, OrderStatus, SequenceIndexer, SortOrder, TransactionStatus, TransactionType, TxnTransferType, WebRPCSchemaHash, WebRPCSchemaVersion, WebRPCVersion };
|
|
790
|
+
export { AbortedError, ContractType, EventLogDataType, EventLogType, Indexer, InvalidArgumentError, MetadataCallFailedError, MethodNotFoundError, NotFoundError, OrderStatus, PermissionDeniedError, ProjectNotFoundError, QueryFailedError, RequestConflictError, SequenceIndexer, SessionExpiredError, SortOrder, TimeoutError, TransactionStatus, TransactionType, TxnTransferType, UnauthorizedError, UnavailableError, WebRPCSchemaHash, WebRPCSchemaVersion, WebRPCVersion, WebrpcBadMethodError, WebrpcBadRequestError, WebrpcBadResponseError, WebrpcBadRouteError, WebrpcClientDisconnectedError, WebrpcEndpointError, WebrpcError, WebrpcInternalErrorError, WebrpcRequestFailedError, WebrpcServerPanicError, WebrpcStreamFinishedError, WebrpcStreamLostError, errors };
|