univo 0.2.14 → 0.2.15

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
@@ -4,8 +4,8 @@ import open from 'open';
4
4
  import { config } from 'dotenv';
5
5
  import { WebSocket } from 'partysocket';
6
6
  import { defineCommand, runMain } from 'citty';
7
- import { h as http } from './shared/univo.CzTm3CDN.mjs';
8
- import { c as createLogger, v as version, f as name } from './shared/univo.sqV2c2Yj.mjs';
7
+ import { h as http } from './shared/univo.O0SoVQWh.mjs';
8
+ import { c as createLogger, v as version, g as name } from './shared/univo.BgwFxZpJ.mjs';
9
9
 
10
10
  const log = createLogger({ quiet: false });
11
11
  const dev = defineCommand({
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export { B as Block, E as Event, a as Filter, H as Head, I as Indexer, M as Metadata, R as Result, i as indexer, m as matchFilter } from './shared/univo.DcmLb3Hn.mjs';
2
- import 'unstorage';
1
+ export { B as Block, E as Event, a as Filter, H as Head, I as Indexer, M as Metadata, R as Result, i as indexer, m as matchFilter } from './shared/univo.CjvLVVxo.mjs';
2
+ import '@storagesdk/core';
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { B as Block, E as Event, a as Filter, H as Head, I as Indexer, M as Metadata, R as Result, i as indexer, m as matchFilter } from './shared/univo.DcmLb3Hn.js';
2
- import 'unstorage';
1
+ export { B as Block, E as Event, a as Filter, H as Head, I as Indexer, M as Metadata, R as Result, i as indexer, m as matchFilter } from './shared/univo.CjvLVVxo.js';
2
+ import '@storagesdk/core';
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
- import { c as createException, a as catchException, l as local, g as getException } from './shared/univo.CzTm3CDN.mjs';
2
- import { c as createLogger, r as retry, v as version, h as hexToNumber, i as isHexEqual, d as decompress, a as decoder, n as normalizeHex } from './shared/univo.sqV2c2Yj.mjs';
1
+ import { StorageError } from '@storagesdk/core';
2
+ import { c as createException, a as catchException, l as local, g as getException } from './shared/univo.O0SoVQWh.mjs';
3
+ import { c as createLogger, r as retry, v as version, h as hexToNumber, i as isHexEqual, d as decompress, a as decoder, n as normalizeHex, b as compress } from './shared/univo.BgwFxZpJ.mjs';
3
4
  import 'ws';
4
5
  import 'partysocket';
5
6
 
@@ -48,48 +49,61 @@ function indexer(opts) {
48
49
  const events_grouped_by_storage_map = /* @__PURE__ */ new Map();
49
50
  const metadata = {
50
51
  blocks: {
51
- async list(head) {
52
- let prefix = `/blocks/v1/${normalizeHex(head.chain)}`;
53
- if (typeof head.number === "string") {
54
- prefix += `/${normalizeHex(head.number, 16)}`;
52
+ async getNextUnfinalizedBlock(chain) {
53
+ const prefix = `blocks/v1/${normalizeHex(chain)}`;
54
+ const keys = await opts.metadataStorage.list({ prefix, limit: 1 });
55
+ const [key] = keys.items;
56
+ if (key === void 0) {
57
+ return null;
55
58
  }
56
- const keys = await opts.metadataStorage.getKeys(prefix);
57
- return keys.map((key) => {
58
- const [__, ___, chain, number, hash] = key.split(":");
59
- return { chain, number, hash };
60
- });
59
+ const [_, __, ___, number, hash] = key.path.split("/");
60
+ return { chain, number, hash };
61
61
  },
62
- async get(head) {
63
- let prefix = `/blocks/v1/${head.chain.toLowerCase()}`;
64
- if (typeof head.number === "string") {
65
- prefix += `/${normalizeHex(head.number, 16)}`;
62
+ async getBlocksByNumber(chain, number) {
63
+ const prefix = `blocks/v1/${normalizeHex(chain)}/${normalizeHex(number, 16)}`;
64
+ const keys = await opts.metadataStorage.list({ prefix });
65
+ if (keys.items.length === 0) {
66
+ return [];
66
67
  }
67
- if (typeof head.hash === "string") {
68
- if (head.number === void 0) {
69
- throw new Error("Requested block by hash without specifying a block number");
70
- }
71
- prefix += `/${head.hash.toLowerCase()}`;
72
- const block = await opts.metadataStorage.getItem(prefix);
73
- if (block === null) {
74
- return [];
68
+ const blocks = await Promise.all(
69
+ keys.items.map(async (item) => {
70
+ const blob = await opts.metadataStorage.download(item.path, { as: "blob" });
71
+ const block = await decompress(blob);
72
+ const parsed = JSON.parse(block);
73
+ return parsed;
74
+ })
75
+ );
76
+ return blocks;
77
+ },
78
+ async getBlockByNumberAndHash(chain, number, hash) {
79
+ const prefix = `blocks/v1/${normalizeHex(chain)}/${normalizeHex(number, 16)}/${normalizeHex(hash)}`;
80
+ const blob = await opts.metadataStorage.download(prefix, { as: "blob" }).catch((error) => {
81
+ if (error instanceof StorageError) {
82
+ if (error.code === "NotFound") {
83
+ return null;
84
+ }
75
85
  }
76
- return [block];
86
+ throw error;
87
+ });
88
+ if (blob === null) {
89
+ return null;
77
90
  }
78
- const keys = await opts.metadataStorage.getKeys(prefix);
79
- const results = await opts.metadataStorage.getItems(keys);
80
- return results.map((result) => result.value);
91
+ const block = await decompress(blob);
92
+ const parsed = JSON.parse(block);
93
+ return parsed;
81
94
  },
82
95
  async upsert(blocks) {
83
96
  if (blocks.length === 0) {
84
97
  return;
85
98
  }
86
- await opts.metadataStorage.setItems(
87
- blocks.map((block) => {
99
+ await Promise.all(
100
+ blocks.map(async (block) => {
88
101
  const chain = normalizeHex(block.eth_chainId);
89
102
  const hash = normalizeHex(block.eth_getBlockByNumber.hash);
90
103
  const number = normalizeHex(block.eth_getBlockByNumber.number, 16);
91
- const key = `/blocks/v1/${chain}/${number}/${hash}`;
92
- return { key, value: block };
104
+ const prefix = `blocks/v1/${chain}/${number}/${hash}`;
105
+ const compressed = await compress(JSON.stringify(block));
106
+ await opts.metadataStorage.upload(prefix, compressed);
93
107
  })
94
108
  );
95
109
  },
@@ -102,7 +116,8 @@ function indexer(opts) {
102
116
  const chain = normalizeHex(block.eth_chainId);
103
117
  const hash = normalizeHex(block.eth_getBlockByNumber.hash);
104
118
  const number = normalizeHex(block.eth_getBlockByNumber.number, 16);
105
- await opts.metadataStorage.del(`/blocks/v1/${chain}/${number}/${hash}`);
119
+ const prefix = `blocks/v1/${chain}/${number}/${hash}`;
120
+ await opts.metadataStorage.delete(prefix);
106
121
  })
107
122
  );
108
123
  }
@@ -133,8 +148,8 @@ function indexer(opts) {
133
148
  }
134
149
  const GetBlockError = createException("Failed to load block from the provided `getBlock` function");
135
150
  const public_getFinalizedHeight = async (chain) => {
136
- const [[stored], finalizedBlock] = await Promise.all([
137
- metadata.blocks.list({ chain }),
151
+ const [stored, finalizedBlock] = await Promise.all([
152
+ metadata.blocks.getNextUnfinalizedBlock(chain),
138
153
  //
139
154
  getBlock({ chain, number: "finalized" })
140
155
  ]);
@@ -143,7 +158,7 @@ function indexer(opts) {
143
158
  throw new Error(GetBlockError);
144
159
  }
145
160
  const finalizedHeight = hexToNumber(finalizedBlock.eth_getBlockByNumber.number);
146
- if (stored === void 0) {
161
+ if (stored === null) {
147
162
  return finalizedHeight;
148
163
  }
149
164
  const indexerHeight = hexToNumber(stored.number) - 1;
@@ -231,11 +246,11 @@ function indexer(opts) {
231
246
  };
232
247
  const public_deleteReorganisedHead = async (head) => {
233
248
  log.debug(`Received reorganised head ${hexToNumber(head.number)}`);
234
- const [canonical_block, [stored_block]] = await Promise.all([
249
+ const [canonical_block, stored_block] = await Promise.all([
235
250
  getBlock({ chain: head.chain, number: head.number }),
236
- metadata.blocks.get({ chain: head.chain, number: head.number, hash: head.hash })
251
+ metadata.blocks.getBlockByNumberAndHash(head.chain, head.number, head.hash)
237
252
  ]);
238
- if (stored_block === void 0) {
253
+ if (stored_block === null) {
239
254
  return log.debug("Reorganised block never/already processed");
240
255
  }
241
256
  if (canonical_block === null) {
@@ -299,8 +314,8 @@ function indexer(opts) {
299
314
  }
300
315
  previousHead = head;
301
316
  }
302
- const [[unfinalizedMetadataBlock], finalizedBlock] = await Promise.all([
303
- metadata.blocks.list({ chain }),
317
+ const [unfinalizedMetadataBlock, finalizedBlock] = await Promise.all([
318
+ metadata.blocks.getNextUnfinalizedBlock(chain),
304
319
  //
305
320
  getBlock({ chain, number: "finalized" })
306
321
  ]);
@@ -314,7 +329,7 @@ function indexer(opts) {
314
329
  throw new Error("Received head greater than chain finalized height");
315
330
  }
316
331
  }
317
- if (unfinalizedMetadataBlock === void 0) {
332
+ if (unfinalizedMetadataBlock === null) {
318
333
  return log.debug("No heads to finalize, returning...");
319
334
  }
320
335
  const indexerHeight = hexToNumber(unfinalizedMetadataBlock.number) - 1;
@@ -333,7 +348,7 @@ function indexer(opts) {
333
348
  throw new Error("Client advanced too far. Heads received are greater than the indexer height");
334
349
  }
335
350
  for (const head of newHeads) {
336
- const processed = await metadata.blocks.get({ chain: head.chain, number: head.number });
351
+ const processed = await metadata.blocks.getBlocksByNumber(head.chain, head.number);
337
352
  if (processed.length === 0) {
338
353
  await writeFinalizedHead(head, null);
339
354
  continue;
@@ -1,7 +1,7 @@
1
1
  import { NodeRpc, IndexerRpc } from './rpc.mjs';
2
2
  import { Transport } from './transport.mjs';
3
- import './shared/univo.DcmLb3Hn.mjs';
4
- import 'unstorage';
3
+ import './shared/univo.CjvLVVxo.mjs';
4
+ import '@storagesdk/core';
5
5
 
6
6
  type RealtimeOptions = {
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  import { NodeRpc, IndexerRpc } from './rpc.js';
2
2
  import { Transport } from './transport.js';
3
- import './shared/univo.DcmLb3Hn.js';
4
- import 'unstorage';
3
+ import './shared/univo.CjvLVVxo.js';
4
+ import '@storagesdk/core';
5
5
 
6
6
  type RealtimeOptions = {
7
7
  /**
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.sqV2c2Yj.mjs';
1
+ import { c as createLogger, e as iife, h as hexToNumber, f as numberToHex, m as mutex, r as retry, i as isHexEqual } from './shared/univo.BgwFxZpJ.mjs';
2
2
 
3
3
  const MAX_LENGTH = 1e4;
4
4
  function defineBlockchain(opts) {
package/dist/rpc.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { H as Head, M as Metadata, F as Flatten, a as Filter, B as Block, R as Result } from './shared/univo.DcmLb3Hn.mjs';
2
- import 'unstorage';
1
+ import { H as Head, M as Metadata, F as Flatten, a as Filter, B as Block, R as Result } from './shared/univo.CjvLVVxo.mjs';
2
+ import '@storagesdk/core';
3
3
 
4
4
  type Rpc = {
5
5
  /**
package/dist/rpc.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { H as Head, M as Metadata, F as Flatten, a as Filter, B as Block, R as Result } from './shared/univo.DcmLb3Hn.js';
2
- import 'unstorage';
1
+ import { H as Head, M as Metadata, F as Flatten, a as Filter, B as Block, R as Result } from './shared/univo.CjvLVVxo.js';
2
+ import '@storagesdk/core';
3
3
 
4
4
  type Rpc = {
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  const name = "univo";
2
- const version = "0.2.14";
2
+ const version = "0.2.15";
3
3
 
4
4
  function createLogger(opts) {
5
5
  let prefix = `[${name}@${version}]`;
@@ -78,6 +78,10 @@ async function compress(input) {
78
78
  return new Response(compressed).arrayBuffer();
79
79
  }
80
80
  async function decompress(input) {
81
+ if (input instanceof Blob) {
82
+ const decompressed2 = input.stream().pipeThrough(new DecompressionStream("gzip"));
83
+ return new Response(decompressed2).text();
84
+ }
81
85
  const decompressed = new Blob([input]).stream().pipeThrough(new DecompressionStream("gzip"));
82
86
  return new Response(decompressed).text();
83
87
  }
@@ -89,4 +93,4 @@ const normalizeHex = (hex, length) => {
89
93
  return `0x${hex.slice(2).toLowerCase().padStart(length, "0")}`;
90
94
  };
91
95
 
92
- export { decoder as a, iife as b, createLogger as c, decompress as d, numberToHex as e, name as f, compress as g, hexToNumber as h, isHexEqual as i, raise as j, mutex as m, normalizeHex as n, retry as r, version as v };
96
+ export { decoder as a, compress as b, createLogger as c, decompress as d, iife as e, numberToHex as f, name as g, hexToNumber as h, isHexEqual as i, raise as j, mutex as m, normalizeHex as n, retry as r, version as v };
@@ -1,4 +1,4 @@
1
- import { Storage } from 'unstorage';
1
+ import { Storage } from '@storagesdk/core';
2
2
 
3
3
  type CamelToSnake<T extends string, P extends string = ""> = string extends T ? string : T extends `${infer C0}${infer R}` ? CamelToSnake<R, `${P}${C0 extends Lowercase<C0> ? "" : "_"}${Lowercase<C0>}`> : P;
4
4
  type Flatten<T> = {
@@ -1,4 +1,4 @@
1
- import { Storage } from 'unstorage';
1
+ import { Storage } from '@storagesdk/core';
2
2
 
3
3
  type CamelToSnake<T extends string, P extends string = ""> = string extends T ? string : T extends `${infer C0}${infer R}` ? CamelToSnake<R, `${P}${C0 extends Lowercase<C0> ? "" : "_"}${Lowercase<C0>}`> : P;
4
4
  type Flatten<T> = {
@@ -1,6 +1,6 @@
1
1
  import ws from 'ws';
2
2
  import { WebSocket } from 'partysocket';
3
- import { g as compress, j as raise, c as createLogger } from './univo.sqV2c2Yj.mjs';
3
+ import { b as compress, j as raise, c as createLogger } from './univo.BgwFxZpJ.mjs';
4
4
 
5
5
  function createException(message) {
6
6
  return `univo:${message}`;
@@ -1,6 +1,6 @@
1
1
  import { Rpc } from './rpc.mjs';
2
- import './shared/univo.DcmLb3Hn.mjs';
3
- import 'unstorage';
2
+ import './shared/univo.CjvLVVxo.mjs';
3
+ import '@storagesdk/core';
4
4
 
5
5
  type Protocol = "http" | "wss" | "local";
6
6
  type Transport<R extends Rpc, P extends Protocol = Protocol> = {
@@ -1,6 +1,6 @@
1
1
  import { Rpc } from './rpc.js';
2
- import './shared/univo.DcmLb3Hn.js';
3
- import 'unstorage';
2
+ import './shared/univo.CjvLVVxo.js';
3
+ import '@storagesdk/core';
4
4
 
5
5
  type Protocol = "http" | "wss" | "local";
6
6
  type Transport<R extends Rpc, P extends Protocol = Protocol> = {
@@ -1,4 +1,4 @@
1
1
  import 'ws';
2
2
  import 'partysocket';
3
- export { h as http, l as local, w as wss } from './shared/univo.CzTm3CDN.mjs';
4
- import './shared/univo.sqV2c2Yj.mjs';
3
+ export { h as http, l as local, w as wss } from './shared/univo.O0SoVQWh.mjs';
4
+ import './shared/univo.BgwFxZpJ.mjs';
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "univo",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "0.2.14",
5
+ "version": "0.2.15",
6
6
  "sideEffects": false,
7
7
  "module": "./dist/index.mjs",
8
8
  "types": "./dist/index.d.ts",
@@ -54,6 +54,7 @@
54
54
  "vitest": "^3.1.3"
55
55
  },
56
56
  "peerDependencies": {
57
- "unstorage": ">=1"
57
+ "@storagesdk/core": ">=0.4.2",
58
+ "@storagesdk/adapters": ">=0.6.0"
58
59
  }
59
60
  }