univo 0.2.9 → 0.2.10

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/cli.mjs CHANGED
@@ -5,7 +5,7 @@ import { config } from 'dotenv';
5
5
  import { WebSocket } from 'partysocket';
6
6
  import { defineCommand, runMain } from 'citty';
7
7
  import { http } from './transport.mjs';
8
- import { c as createLogger, v as version, f as name } from './shared/univo.RhVE6xw6.mjs';
8
+ import { c as createLogger, v as version, f as name } from './shared/univo.DfCC9G2B.mjs';
9
9
  import './shared/univo.C0flyVee.mjs';
10
10
 
11
11
  const log = createLogger({ quiet: false });
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { c as createLogger, d as decompress, a as decoder, h as hexToNumber, i as isHexEqual, r as retry, v as version, n as normalizeHex } from './shared/univo.RhVE6xw6.mjs';
1
+ import { c as createLogger, d as decompress, a as decoder, h as hexToNumber, i as isHexEqual, r as retry, v as version, n as normalizeHex } from './shared/univo.DfCC9G2B.mjs';
2
2
  import { c as createException, g as getException, a as catchException } from './shared/univo.C0flyVee.mjs';
3
3
 
4
4
  function matchFilter(block, filter) {
@@ -309,7 +309,7 @@ function indexer(opts) {
309
309
  const finalizedHeight = hexToNumber(finalizedBlock.eth_getBlockByNumber.number);
310
310
  for (const head of heads) {
311
311
  if (hexToNumber(head.number) > finalizedHeight) {
312
- throw new Error("Received invalid finalized heads");
312
+ throw new Error("Received head greater than chain finalized height");
313
313
  }
314
314
  }
315
315
  if (unfinalizedMetadataBlock === void 0) {
@@ -328,7 +328,7 @@ function indexer(opts) {
328
328
  return log.debug("No new heads received, returning...");
329
329
  }
330
330
  if (hexToNumber(firstNewHead.number) !== indexerHeight + 1) {
331
- throw new Error("Client advanced too far. Heads received are greater is than the indexer height");
331
+ throw new Error("Client advanced too far. Heads received are greater than the indexer height");
332
332
  }
333
333
  for (const head of newHeads) {
334
334
  const processed = await metadata.blocks.get({ chain: head.chain, number: head.number });
@@ -355,7 +355,7 @@ function indexer(opts) {
355
355
  block = await getBlock({ chain: head.chain, number: head.number, hash: head.hash });
356
356
  }
357
357
  if (block === null) {
358
- throw new Error("Received invalid finalized heads");
358
+ throw new Error("Received unknown head that wasn't canonical");
359
359
  }
360
360
  const promises = events_grouped_by_storage_map.entries().map(async ([storage, grouped_events]) => {
361
361
  const batch = [];
package/dist/realtime.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { c as createLogger, b as iife, h as hexToNumber, e as numberToHex, m as mutex, r as retry, i as isHexEqual } from './shared/univo.RhVE6xw6.mjs';
1
+ import { c as createLogger, b as iife, h as hexToNumber, e as numberToHex, m as mutex, r as retry, i as isHexEqual } from './shared/univo.DfCC9G2B.mjs';
2
2
 
3
3
  const MAX_LENGTH = 1e4;
4
4
  function defineBlockchain(opts) {
@@ -160,6 +160,7 @@ function realtime(opts) {
160
160
  let indexerHeight = initialIndexerHeight;
161
161
  const poll = async () => {
162
162
  try {
163
+ log.debug("Polling for finalized height...");
163
164
  const finalizedBlock = await opts.node.request({
164
165
  method: "eth_getBlockByNumber",
165
166
  params: ["finalized", false]
@@ -1,5 +1,5 @@
1
1
  const name = "univo";
2
- const version = "0.2.9";
2
+ const version = "0.2.10";
3
3
 
4
4
  function createLogger(opts) {
5
5
  let prefix = `[${name}@${version}]`;
@@ -2,8 +2,8 @@ import { Rpc } from './rpc.mjs';
2
2
  import './index.mjs';
3
3
  import 'unstorage';
4
4
 
5
- type Protcol = "http" | "wss";
6
- type Transport<R extends Rpc, P extends Protcol = Protcol> = {
5
+ type Protocol = "http" | "wss";
6
+ type Transport<R extends Rpc, P extends Protocol = Protocol> = {
7
7
  /**
8
8
  * The underlying transport protocol.
9
9
  */
@@ -2,8 +2,8 @@ import { Rpc } from './rpc.js';
2
2
  import './index.js';
3
3
  import 'unstorage';
4
4
 
5
- type Protcol = "http" | "wss";
6
- type Transport<R extends Rpc, P extends Protcol = Protcol> = {
5
+ type Protocol = "http" | "wss";
6
+ type Transport<R extends Rpc, P extends Protocol = Protocol> = {
7
7
  /**
8
8
  * The underlying transport protocol.
9
9
  */
@@ -1,7 +1,7 @@
1
1
  import ws from 'ws';
2
2
  import { WebSocket } from 'partysocket';
3
3
  import { c as createException } from './shared/univo.C0flyVee.mjs';
4
- import { g as compress, j as raise, c as createLogger } from './shared/univo.RhVE6xw6.mjs';
4
+ import { g as compress, j as raise, c as createLogger } from './shared/univo.DfCC9G2B.mjs';
5
5
 
6
6
  function createSocket(url, opts) {
7
7
  const socket = new WebSocket(url, [], { WebSocket: ws });
@@ -26,7 +26,9 @@ function wss(url, opts = {}) {
26
26
  logger.error(new Error("Socket error", { cause }));
27
27
  },
28
28
  async onOpen() {
29
- if (subscriptions.size === 0) return;
29
+ if (subscriptions.size === 0) {
30
+ return;
31
+ }
30
32
  const params2 = [];
31
33
  for (const [id2, subscription] of subscriptions) {
32
34
  params2.push(subscription.param);
@@ -74,13 +76,24 @@ function wss(url, opts = {}) {
74
76
  }
75
77
  });
76
78
  const request = async (opts2) => {
77
- return await new Promise((resolve) => {
79
+ return await new Promise((resolve, reject) => {
78
80
  const body = Object.assign({ id: id++ }, opts2);
81
+ const timeout = setTimeout(() => {
82
+ requests.delete(body.id);
83
+ reject(new Error("wss request timed out after 30 seconds"));
84
+ }, 30 * 1e3);
79
85
  requests.set(body.id, (data) => {
86
+ clearTimeout(timeout);
80
87
  requests.delete(body.id);
81
88
  resolve(data);
82
89
  });
83
- socket.send(JSON.stringify(body));
90
+ try {
91
+ socket.send(JSON.stringify(body));
92
+ } catch (cause) {
93
+ clearTimeout(timeout);
94
+ requests.delete(body.id);
95
+ reject(new Error(ClientConnectionError, { cause }));
96
+ }
84
97
  });
85
98
  };
86
99
  const subscribe = async (param, handler) => {
@@ -148,7 +161,7 @@ function http(url, opts = {}) {
148
161
  headers.set("Content-Encoding", "gzip");
149
162
  headers.set("Authorization", `Bearer ${opts.signingKey}`);
150
163
  }
151
- const res = await fetch(url, { headers, body, method: "POST" }).catch((cause) => {
164
+ const res = await fetch(url, { headers, body, method: "POST", signal: AbortSignal.timeout(30 * 1e3) }).catch((cause) => {
152
165
  throw new Error(ClientConnectionError, { cause });
153
166
  });
154
167
  const json = await res.json().catch((cause) => {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "univo",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "0.2.9",
5
+ "version": "0.2.10",
6
6
  "sideEffects": false,
7
7
  "module": "./dist/index.mjs",
8
8
  "types": "./dist/index.d.ts",