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 +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +57 -42
- package/dist/realtime.d.mts +2 -2
- package/dist/realtime.d.ts +2 -2
- package/dist/realtime.mjs +1 -1
- package/dist/rpc.d.mts +2 -2
- package/dist/rpc.d.ts +2 -2
- package/dist/shared/{univo.sqV2c2Yj.mjs → univo.BgwFxZpJ.mjs} +6 -2
- package/dist/shared/{univo.DcmLb3Hn.d.mts → univo.CjvLVVxo.d.mts} +1 -1
- package/dist/shared/{univo.DcmLb3Hn.d.ts → univo.CjvLVVxo.d.ts} +1 -1
- package/dist/shared/{univo.CzTm3CDN.mjs → univo.O0SoVQWh.mjs} +1 -1
- package/dist/transport.d.mts +2 -2
- package/dist/transport.d.ts +2 -2
- package/dist/transport.mjs +2 -2
- package/package.json +3 -2
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.
|
|
8
|
-
import { c as createLogger, v as version,
|
|
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.
|
|
2
|
-
import '
|
|
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.
|
|
2
|
-
import '
|
|
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 {
|
|
2
|
-
import { c as
|
|
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
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
|
57
|
-
return
|
|
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
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
86
|
+
throw error;
|
|
87
|
+
});
|
|
88
|
+
if (blob === null) {
|
|
89
|
+
return null;
|
|
77
90
|
}
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
return
|
|
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
|
|
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
|
|
92
|
-
|
|
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
|
-
|
|
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 [
|
|
137
|
-
metadata.blocks.
|
|
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 ===
|
|
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,
|
|
249
|
+
const [canonical_block, stored_block] = await Promise.all([
|
|
235
250
|
getBlock({ chain: head.chain, number: head.number }),
|
|
236
|
-
metadata.blocks.
|
|
251
|
+
metadata.blocks.getBlockByNumberAndHash(head.chain, head.number, head.hash)
|
|
237
252
|
]);
|
|
238
|
-
if (stored_block ===
|
|
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 [
|
|
303
|
-
metadata.blocks.
|
|
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 ===
|
|
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.
|
|
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;
|
package/dist/realtime.d.mts
CHANGED
package/dist/realtime.d.ts
CHANGED
package/dist/realtime.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as createLogger,
|
|
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.
|
|
2
|
-
import '
|
|
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.
|
|
2
|
-
import '
|
|
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.
|
|
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,
|
|
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 '
|
|
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 '
|
|
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 {
|
|
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}`;
|
package/dist/transport.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Rpc } from './rpc.mjs';
|
|
2
|
-
import './shared/univo.
|
|
3
|
-
import '
|
|
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> = {
|
package/dist/transport.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Rpc } from './rpc.js';
|
|
2
|
-
import './shared/univo.
|
|
3
|
-
import '
|
|
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> = {
|
package/dist/transport.mjs
CHANGED
|
@@ -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.
|
|
4
|
-
import './shared/univo.
|
|
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.
|
|
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
|
-
"
|
|
57
|
+
"@storagesdk/core": ">=0.4.2",
|
|
58
|
+
"@storagesdk/adapters": ">=0.6.0"
|
|
58
59
|
}
|
|
59
60
|
}
|