@tari-project/ootle-indexer 0.11.1 → 0.13.0

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.
Files changed (2) hide show
  1. package/dist/index.js +74 -61
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -22,7 +22,8 @@ function f(e5) {
22
22
  function p(e5, t3) {
23
23
  return typeof t3 == "bigint" ? t3.toString() : t3;
24
24
  }
25
- function m(e5, t3) {
25
+ var m = 1024 * 1024, h = 1024 * 1024;
26
+ function g(e5, t3) {
26
27
  let n2 = new AbortController();
27
28
  return t3.signal && (t3.signal.aborted ? n2.abort() : t3.signal.addEventListener("abort", () => n2.abort(), { once: true })), (async () => {
28
29
  let r2 = await fetch(e5, {
@@ -35,54 +36,66 @@ function m(e5, t3) {
35
36
  throw new d(r2.status, r2.statusText, e6);
36
37
  }
37
38
  if (!r2.body) throw Error("Response body is not readable");
38
- let i2 = r2.body.getReader(), a2 = new TextDecoder(), o2 = "", s2 = "", c2 = [], l2, u2, f2 = () => {
39
- if (c2.length === 0) {
40
- s2 = "", l2 = void 0, u2 = void 0;
39
+ let i2 = r2.body.getReader(), a2 = new TextDecoder(), o2 = /\r\n|\r|\n/g, s2 = [], c2 = 0, l2 = false, u2 = "", f2 = [], p2 = 0, g2, _2, v2 = () => {
40
+ if (f2.length === 0) {
41
+ u2 = "", g2 = void 0, _2 = void 0;
41
42
  return;
42
43
  }
43
44
  let e6 = {
44
- event: s2 || "message",
45
- data: c2.join("\n"),
46
- id: l2,
47
- retry: u2
45
+ event: u2 || "message",
46
+ data: f2.join("\n"),
47
+ id: g2,
48
+ retry: _2
48
49
  };
49
- t3.onEvent(e6), s2 = "", c2 = [], l2 = void 0, u2 = void 0;
50
- }, p2 = (e6) => {
50
+ t3.onEvent(e6), u2 = "", f2 = [], p2 = 0, g2 = void 0, _2 = void 0;
51
+ }, y2 = (e6) => {
52
+ if (e6.length > m) throw Error(`SSE line exceeds the maximum length of ${m}`);
51
53
  if (e6 === "") {
52
- f2();
54
+ v2();
53
55
  return;
54
56
  }
55
57
  if (e6.startsWith(":")) return;
56
58
  let t4 = e6.indexOf(":"), n3, r3;
57
59
  switch (t4 === -1 ? (n3 = e6, r3 = "") : (n3 = e6.slice(0, t4), r3 = e6.slice(t4 + 1), r3.startsWith(" ") && (r3 = r3.slice(1))), n3) {
58
60
  case "event":
59
- s2 = r3;
61
+ u2 = r3;
60
62
  break;
61
63
  case "data":
62
- c2.push(r3);
64
+ if (p2 += r3.length + (f2.length > 0 ? 1 : 0), p2 > h) throw Error(`SSE event data exceeds the maximum length of ${h}`);
65
+ f2.push(r3);
63
66
  break;
64
67
  case "id":
65
- l2 = r3;
68
+ g2 = r3;
66
69
  break;
67
70
  case "retry": {
68
71
  let e7 = parseInt(r3, 10);
69
- isNaN(e7) || (u2 = e7);
72
+ isNaN(e7) || (_2 = e7);
70
73
  break;
71
74
  }
72
75
  }
73
76
  };
74
77
  try {
75
78
  for (; ; ) {
76
- let { done: e6, value: t4 } = await i2.read();
77
- if (e6) break;
78
- o2 += a2.decode(t4, { stream: true });
79
- let n3 = /\r\n|\r|\n/, r3;
80
- for (; (r3 = n3.exec(o2)) !== null; ) {
81
- let e7 = o2.slice(0, r3.index);
82
- o2 = o2.slice(r3.index + r3[0].length), p2(e7);
79
+ let { done: e7, value: t4 } = await i2.read();
80
+ if (e7) break;
81
+ let n3 = a2.decode(t4, { stream: true });
82
+ l2 && n3.length > 0 && (n3.startsWith("\n") && (n3 = n3.slice(1)), l2 = false);
83
+ let r3 = 0;
84
+ o2.lastIndex = 0;
85
+ let u3;
86
+ for (; (u3 = o2.exec(n3)) !== null; ) {
87
+ s2.push(n3.slice(r3, u3.index));
88
+ let e8 = s2.join("");
89
+ s2 = [], c2 = 0, y2(e8), r3 = o2.lastIndex, l2 = u3[0] === "\r" && r3 === n3.length;
83
90
  }
91
+ if (r3 < n3.length && (s2.push(n3.slice(r3)), c2 += n3.length - r3, c2 > m)) throw Error(`SSE line exceeds the maximum length of ${m}`);
84
92
  }
85
- o2.length > 0 && (p2(o2), f2());
93
+ s2.push(a2.decode());
94
+ let e6 = s2.join("");
95
+ e6.length > 0 && (y2(e6), v2());
96
+ } catch (e6) {
97
+ throw await i2.cancel().catch(() => {
98
+ }), e6;
86
99
  } finally {
87
100
  i2.releaseLock();
88
101
  }
@@ -96,7 +109,7 @@ function m(e5, t3) {
96
109
  n2.abort();
97
110
  } };
98
111
  }
99
- var h = class e2 {
112
+ var _ = class e2 {
100
113
  constructor(e5) {
101
114
  __publicField(this, "url");
102
115
  this.url = e5;
@@ -144,7 +157,7 @@ var h = class e2 {
144
157
  let n3 = e6.toString();
145
158
  n3.length > 0 && (r2 += `?${n3}`);
146
159
  }
147
- return m(r2, n2);
160
+ return g(r2, n2);
148
161
  }
149
162
  async sendRequest(e5, t3, n2) {
150
163
  let r2 = new AbortController(), i2 = r2.signal, a2 = (n2 == null ? void 0 : n2.timeout_millis) ? setTimeout(() => {
@@ -172,7 +185,7 @@ var h = class e2 {
172
185
  if (l2.error) throw Error(`${l2.error.code}: ${l2.error.message}`);
173
186
  return l2;
174
187
  }
175
- }, g = /* @__PURE__ */ u({ FetchTransport: () => h }), _ = class e3 {
188
+ }, v = /* @__PURE__ */ u({ FetchTransport: () => _ }), y = class e3 {
176
189
  constructor(e5) {
177
190
  __publicField(this, "transport");
178
191
  this.transport = e5;
@@ -181,7 +194,7 @@ var h = class e2 {
181
194
  return new e3(t3);
182
195
  }
183
196
  static usingFetchTransport(t3) {
184
- return e3.new(h.new(t3));
197
+ return e3.new(_.new(t3));
185
198
  }
186
199
  getTransport() {
187
200
  return this.transport;
@@ -270,8 +283,8 @@ var h = class e2 {
270
283
  signal: t3.signal
271
284
  });
272
285
  }
273
- }, v = 1024 * 1024, y = 1024 * 1024;
274
- function b(e5) {
286
+ }, b = 1024 * 1024, x = 1024 * 1024;
287
+ function S(e5) {
275
288
  let t3 = [], n2 = e5.split(/\n\n|\r\n\r\n/), r2 = n2.pop() ?? "";
276
289
  for (let e6 of n2) {
277
290
  if (!e6.trim()) continue;
@@ -293,7 +306,7 @@ function b(e5) {
293
306
  remainder: r2
294
307
  };
295
308
  }
296
- var x = class {
309
+ var C = class {
297
310
  constructor(e5) {
298
311
  __publicField(this, "lineEnding", /\r\n|\r|\n/g);
299
312
  __publicField(this, "pending", []);
@@ -317,16 +330,16 @@ var x = class {
317
330
  let a2 = this.processLine(e5);
318
331
  a2 && n2.push(a2);
319
332
  }
320
- if (r2 < t3.length && (this.pending.push(t3.slice(r2)), this.pendingLength += t3.length - r2, this.pendingLength > 1048576)) throw new e(`SSE line exceeds the maximum length of ${v}`, { url: this.url });
333
+ if (r2 < t3.length && (this.pending.push(t3.slice(r2)), this.pendingLength += t3.length - r2, this.pendingLength > 1048576)) throw new e(`SSE line exceeds the maximum length of ${b}`, { url: this.url });
321
334
  return n2;
322
335
  }
323
336
  processLine(t3) {
324
- if (t3.length > 1048576) throw new e(`SSE line exceeds the maximum length of ${v}`, { url: this.url });
337
+ if (t3.length > 1048576) throw new e(`SSE line exceeds the maximum length of ${b}`, { url: this.url });
325
338
  if (t3 === "") return this.dispatch();
326
339
  if (t3.startsWith("event:")) this.type = t3.slice(6).trim();
327
340
  else if (t3.startsWith("data:")) {
328
341
  let n2 = t3.slice(5).trim();
329
- if (this.dataLength += n2.length + (this.dataLines.length > 0 ? 1 : 0), this.dataLength > 1048576) throw new e(`SSE event data exceeds the maximum length of ${y}`, { url: this.url });
342
+ if (this.dataLength += n2.length + (this.dataLines.length > 0 ? 1 : 0), this.dataLength > 1048576) throw new e(`SSE event data exceeds the maximum length of ${x}`, { url: this.url });
330
343
  this.dataLines.push(n2);
331
344
  }
332
345
  }
@@ -344,7 +357,7 @@ var x = class {
344
357
  };
345
358
  }
346
359
  };
347
- async function* S(t3, n2) {
360
+ async function* w(t3, n2) {
348
361
  for (; !n2.aborted; ) {
349
362
  let r2 = new AbortController(), i2 = () => r2.abort();
350
363
  n2.addEventListener("abort", i2, { once: true });
@@ -363,7 +376,7 @@ async function* S(t3, n2) {
363
376
  url: t3
364
377
  });
365
378
  }
366
- let a2 = i3.body.getReader(), o2 = new TextDecoder(), s2 = new x(t3);
379
+ let a2 = i3.body.getReader(), o2 = new TextDecoder(), s2 = new C(t3);
367
380
  try {
368
381
  for (; !n2.aborted; ) {
369
382
  let { done: e5, value: t4 } = await a2.read();
@@ -387,7 +400,7 @@ async function* S(t3, n2) {
387
400
  }
388
401
  }
389
402
  }
390
- var C = 500, w = 3e3, T = class {
403
+ var T = 500, E = 3e3, D = class {
391
404
  constructor(e5) {
392
405
  __publicField(this, "baseUrl");
393
406
  __publicField(this, "pending", /* @__PURE__ */ new Map());
@@ -406,7 +419,7 @@ var C = 500, w = 3e3, T = class {
406
419
  this.pending.clear();
407
420
  }
408
421
  watch(e5, t3, n2 = 32e3) {
409
- return this.start(), new E(e5, this, t3, n2);
422
+ return this.start(), new O(e5, this, t3, n2);
410
423
  }
411
424
  register(e5) {
412
425
  return new Promise((t3, n2) => {
@@ -421,7 +434,7 @@ var C = 500, w = 3e3, T = class {
421
434
  }
422
435
  async run(e5) {
423
436
  let t3 = `${this.baseUrl}/events`;
424
- for await (let n2 of S(t3, e5)) {
437
+ for await (let n2 of w(t3, e5)) {
425
438
  if (n2.type !== "TransactionFinalized") continue;
426
439
  let e6 = n2.data, t4 = this.pending.get(e6.transaction_id);
427
440
  if (!t4) continue;
@@ -437,7 +450,7 @@ var C = 500, w = 3e3, T = class {
437
450
  } else t4.resolve({ decision: "Indeterminate" });
438
451
  }
439
452
  }
440
- }, E = class {
453
+ }, O = class {
441
454
  constructor(e5, t3, n2, r2) {
442
455
  __publicField(this, "txId");
443
456
  __publicField(this, "watcher");
@@ -464,7 +477,7 @@ var C = 500, w = 3e3, T = class {
464
477
  r2,
465
478
  this.cancellation.promise
466
479
  ]);
467
- if (n2 !== null && clearTimeout(n2), i3 === "sse-timeout") return await Promise.race([this.restPollUntilFinal(Date.now() + w, o2.signal, w), a2]);
480
+ if (n2 !== null && clearTimeout(n2), i3 === "sse-timeout") return await Promise.race([this.restPollUntilFinal(Date.now() + E, o2.signal, E), a2]);
468
481
  if (i3.decision === "Indeterminate") return await Promise.race([this.restPollUntilFinal(t3, o2.signal, 0), a2]);
469
482
  if (i3.decision === "Commit") return { outcome: "Commit" };
470
483
  let s2 = await this.client.getTransactionResult(this.txId);
@@ -500,7 +513,7 @@ var C = 500, w = 3e3, T = class {
500
513
  if (e6) return e6.outcome === "Commit" ? { outcome: "Commit" } : this.throwFromReceipt(r3, e6.reason ?? "");
501
514
  }
502
515
  if (Date.now() >= e5) break;
503
- await this.delay(C, t3);
516
+ await this.delay(T, t3);
504
517
  } while (Date.now() < e5 && !t3.aborted);
505
518
  if (t3.aborted) throw new n(`Wait for transaction ${this.txId} was cancelled`);
506
519
  let s2 = this.timeoutMs + r2, c2 = r2 > 0 ? ` (incl. ${r2}ms grace)` : "";
@@ -531,11 +544,11 @@ var C = 500, w = 3e3, T = class {
531
544
  return this.client.getTransactionResult(this.txId);
532
545
  }
533
546
  };
534
- function D(e5) {
547
+ function k(e5) {
535
548
  let t3 = e5 instanceof Error ? e5.message : String(e5);
536
549
  return /not found/i.test(t3) || t3.includes("404");
537
550
  }
538
- var O = class t2 {
551
+ var A = class t2 {
539
552
  constructor(e5, t3, n2, r2) {
540
553
  __publicField(this, "client");
541
554
  __publicField(this, "_network");
@@ -545,14 +558,14 @@ var O = class t2 {
545
558
  this.client = e5, this._network = t3, this._url = n2, this.defaultTransactionTimeoutMs = r2;
546
559
  }
547
560
  static async connect(e5) {
548
- let n2 = _.usingFetchTransport(e5.url);
561
+ let n2 = y.usingFetchTransport(e5.url);
549
562
  return await n2.identityGet(), new t2(n2, e5.network, e5.url, e5.defaultTransactionTimeoutMs ?? 6e4);
550
563
  }
551
564
  getClient() {
552
565
  return this.client;
553
566
  }
554
567
  watchTransactionSSE(e5, t3) {
555
- return this._watcher || (this._watcher = new T(this._url), this._watcher.start()), this._watcher.watch(e5, this.client, t3 ?? this.defaultTransactionTimeoutMs);
568
+ return this._watcher || (this._watcher = new D(this._url), this._watcher.start()), this._watcher.watch(e5, this.client, t3 ?? this.defaultTransactionTimeoutMs);
556
569
  }
557
570
  stopWatcher() {
558
571
  var _a;
@@ -576,7 +589,7 @@ var O = class t2 {
576
589
  try {
577
590
  return await this.getSubstate(n2);
578
591
  } catch (e6) {
579
- if (D(e6)) return null;
592
+ if (k(e6)) return null;
580
593
  throw e6;
581
594
  }
582
595
  }
@@ -611,7 +624,7 @@ var O = class t2 {
611
624
  };
612
625
  } catch (n2) {
613
626
  let r2 = n2 instanceof Error ? n2.message : String(n2);
614
- throw D(n2) ? new e(`Failed to find input "${t4.substate_id}": ${r2}. Verify the substate id is correct (typo? wrong network?) or wait for the producing transaction to finalize.`, {
627
+ throw k(n2) ? new e(`Failed to find input "${t4.substate_id}": ${r2}. Verify the substate id is correct (typo? wrong network?) or wait for the producing transaction to finalize.`, {
615
628
  cause: n2,
616
629
  url: this._url
617
630
  }) : new e(`Failed to resolve input "${t4.substate_id}": ${r2}. Check the indexer URL points at the same network as the substate.`, {
@@ -624,7 +637,7 @@ var O = class t2 {
624
637
  async listRecentTransactions(e5) {
625
638
  return await this.client.listRecentTransactions(e5);
626
639
  }
627
- }, k = class e4 {
640
+ }, j = class e4 {
628
641
  constructor() {
629
642
  __publicField(this, "_network", t.LocalNet);
630
643
  __publicField(this, "_url", null);
@@ -648,10 +661,10 @@ var O = class t2 {
648
661
  network: this._network,
649
662
  defaultTransactionTimeoutMs: this._transactionTimeoutMs
650
663
  };
651
- return O.connect(e5);
664
+ return A.connect(e5);
652
665
  }
653
666
  };
654
- async function A(e5, t3) {
667
+ async function M(e5, t3) {
655
668
  return Promise.all(t3.map(async (t4) => {
656
669
  if (t4.type === "SpecificSubstate") {
657
670
  if (t4.version != null) return {
@@ -681,15 +694,15 @@ async function A(e5, t3) {
681
694
  }));
682
695
  }
683
696
  export {
684
- _ as IndexerClient,
685
- O as IndexerProvider,
686
- y as MAX_SSE_EVENT_DATA_LENGTH,
687
- v as MAX_SSE_LINE_LENGTH,
688
- E as PendingTransaction,
689
- k as ProviderBuilder,
690
- T as TransactionWatcher,
691
- S as openEventStream,
692
- b as parseSseChunk,
693
- A as resolveWantInputs,
694
- g as transports
697
+ y as IndexerClient,
698
+ A as IndexerProvider,
699
+ x as MAX_SSE_EVENT_DATA_LENGTH,
700
+ b as MAX_SSE_LINE_LENGTH,
701
+ O as PendingTransaction,
702
+ j as ProviderBuilder,
703
+ D as TransactionWatcher,
704
+ w as openEventStream,
705
+ S as parseSseChunk,
706
+ M as resolveWantInputs,
707
+ v as transports
695
708
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tari-project/ootle-indexer",
3
- "version": "0.11.1",
3
+ "version": "0.13.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/tari-project/ootle.ts.git",
@@ -25,9 +25,9 @@
25
25
  }
26
26
  },
27
27
  "dependencies": {
28
- "@tari-project/indexer-client": "^1.11.0",
29
- "@tari-project/ootle-ts-bindings": "^1.60.0",
30
- "@tari-project/ootle": "0.11.1"
28
+ "@tari-project/indexer-client": "^1.13.0",
29
+ "@tari-project/ootle-ts-bindings": "^1.62.0",
30
+ "@tari-project/ootle": "0.13.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^25.5.0",