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