univo 0.4.3 → 0.4.4
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/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +55 -44
- package/dist/proxy.d.mts +1 -1
- package/dist/proxy.d.ts +1 -1
- package/dist/proxy.mjs +1 -1
- package/dist/realtime.d.mts +1 -1
- package/dist/realtime.d.ts +1 -1
- package/dist/realtime.mjs +1 -1
- package/dist/rpc.d.mts +1 -1
- package/dist/rpc.d.ts +1 -1
- package/dist/shared/{univo.7S1OTdpc.d.ts → univo.BL1Gu6sU.d.ts} +2 -2
- package/dist/shared/{univo.Ckj3I8tQ.d.mts → univo.Cwz0D-bk.d.mts} +2 -2
- package/dist/shared/{univo.DEUuEEoe.mjs → univo.DAgQmcSe.mjs} +2 -2
- package/dist/transport.d.mts +1 -1
- package/dist/transport.d.ts +1 -1
- package/dist/transport.mjs +1 -1
- package/package.json +3 -10
- package/dist/cli.d.mts +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.mjs +0 -79
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as Action, B as Block, E as Event, F as Filter, H as Head, e as Indexer, f as PrivateMetadata, P as PublicMetadata, g as Result, c as defineAction, a as defineEvent, d as defineIndexer } from './shared/univo.
|
|
1
|
+
export { A as Action, B as Block, E as Event, F as Filter, H as Head, e as Indexer, f as PrivateMetadata, P as PublicMetadata, g as Result, c as defineAction, a as defineEvent, d as defineIndexer } from './shared/univo.Cwz0D-bk.mjs';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './metadata.mjs';
|
|
4
4
|
import './metadata/adapters.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as Action, B as Block, E as Event, F as Filter, H as Head, e as Indexer, f as PrivateMetadata, P as PublicMetadata, g as Result, c as defineAction, a as defineEvent, d as defineIndexer } from './shared/univo.
|
|
1
|
+
export { A as Action, B as Block, E as Event, F as Filter, H as Head, e as Indexer, f as PrivateMetadata, P as PublicMetadata, g as Result, c as defineAction, a as defineEvent, d as defineIndexer } from './shared/univo.BL1Gu6sU.js';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './metadata.js';
|
|
4
4
|
import './metadata/adapters.js';
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { hexToNumber, numberToHex, hexToBytes, keccak256, toRlp, hexToBigInt, numberToBytes, isHex, concatBytes, concatHex, formatTransaction, serializeTransaction } from 'viem';
|
|
2
2
|
import { local } from './transport.mjs';
|
|
3
|
-
import { c as createLogger, r as retry, v as version,
|
|
3
|
+
import { c as createLogger, r as retry, v as version, n as normalizeHex, d as decompress, b as isHexEqual, a as compress, i as iife, e as decoder } from './shared/univo.DAgQmcSe.mjs';
|
|
4
4
|
import { AdapterError } from './metadata/adapters.mjs';
|
|
5
5
|
import 'ws';
|
|
6
6
|
import 'partysocket';
|
|
@@ -1084,30 +1084,37 @@ function defineIndexer(opts) {
|
|
|
1084
1084
|
const IncompleteBlockError = createException("Received block with missing required property");
|
|
1085
1085
|
const private_writeEvents = async (params) => {
|
|
1086
1086
|
if (allEvents.length === 0) {
|
|
1087
|
-
return {
|
|
1087
|
+
return { results: [] };
|
|
1088
1088
|
}
|
|
1089
1089
|
const relevantEvents = allEvents.filter((event) => params.events.includes(event.id));
|
|
1090
1090
|
if (relevantEvents.length === 0) {
|
|
1091
|
-
return {
|
|
1091
|
+
return { results: [] };
|
|
1092
1092
|
}
|
|
1093
1093
|
if (params.events.length === 0) {
|
|
1094
|
-
return {
|
|
1094
|
+
return { results: [] };
|
|
1095
1095
|
}
|
|
1096
|
-
const
|
|
1096
|
+
const results = {};
|
|
1097
1097
|
let accessedUndefinedKey = false;
|
|
1098
1098
|
const proxiedBlocks = getWriteEventsProxy(params.blocks, () => {
|
|
1099
1099
|
accessedUndefinedKey = true;
|
|
1100
1100
|
throw new Error(IncompleteBlockError);
|
|
1101
1101
|
});
|
|
1102
|
-
const promises = eventsGroupedByStorageMap.entries().map(async ([storage,
|
|
1102
|
+
const promises = eventsGroupedByStorageMap.entries().map(async ([storage, groupedEvents]) => {
|
|
1103
|
+
const requestedEvents = groupedEvents.filter((event) => params.events.includes(event.id));
|
|
1103
1104
|
const batch = [];
|
|
1104
|
-
for (const event of
|
|
1105
|
-
if (!params.events.includes(event.id)) {
|
|
1106
|
-
continue;
|
|
1107
|
-
}
|
|
1105
|
+
for (const event of requestedEvents) {
|
|
1108
1106
|
for (const block of proxiedBlocks) {
|
|
1109
1107
|
try {
|
|
1110
1108
|
if (!event.filters.some((filter) => matchFilter(block, filter))) {
|
|
1109
|
+
results[event.id + block.eth_getBlockByNumber.number] ??= {
|
|
1110
|
+
status: "ignored",
|
|
1111
|
+
event_id: event.id,
|
|
1112
|
+
chain: block.eth_chainId,
|
|
1113
|
+
hash: block.eth_getBlockByNumber.hash,
|
|
1114
|
+
number: block.eth_getBlockByNumber.number,
|
|
1115
|
+
parent_hash: block.eth_getBlockByNumber.parentHash,
|
|
1116
|
+
created_at: Date.now()
|
|
1117
|
+
};
|
|
1111
1118
|
continue;
|
|
1112
1119
|
}
|
|
1113
1120
|
const events = event.handler(block);
|
|
@@ -1124,7 +1131,7 @@ function defineIndexer(opts) {
|
|
|
1124
1131
|
log.error(error.message);
|
|
1125
1132
|
}
|
|
1126
1133
|
}
|
|
1127
|
-
|
|
1134
|
+
results[event.id + block.eth_getBlockByNumber.number] ??= {
|
|
1128
1135
|
status,
|
|
1129
1136
|
event_id: event.id,
|
|
1130
1137
|
chain: block.eth_chainId,
|
|
@@ -1136,47 +1143,51 @@ function defineIndexer(opts) {
|
|
|
1136
1143
|
}
|
|
1137
1144
|
}
|
|
1138
1145
|
}
|
|
1139
|
-
if (batch.length
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
await retry(() => storage.upsert(batch), 2);
|
|
1145
|
-
if (accessedUndefinedKey) {
|
|
1146
|
-
throw new Error(IncompleteBlockError);
|
|
1147
|
-
}
|
|
1148
|
-
} catch (error) {
|
|
1149
|
-
const status = catchException(error, IncompleteBlockError) ? "incomplete_error" : "upsert_error";
|
|
1150
|
-
if (status === "upsert_error") {
|
|
1151
|
-
if (error instanceof Error) {
|
|
1152
|
-
log.error(error.message);
|
|
1146
|
+
if (batch.length > 0) {
|
|
1147
|
+
try {
|
|
1148
|
+
await retry(() => storage.upsert(batch), 2);
|
|
1149
|
+
if (accessedUndefinedKey) {
|
|
1150
|
+
throw new Error(IncompleteBlockError);
|
|
1153
1151
|
}
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
if (
|
|
1158
|
-
|
|
1152
|
+
} catch (error) {
|
|
1153
|
+
const status = catchException(error, IncompleteBlockError) ? "incomplete_error" : "upsert_error";
|
|
1154
|
+
if (status === "upsert_error") {
|
|
1155
|
+
if (error instanceof Error) {
|
|
1156
|
+
log.error(error.message);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
for (const event of requestedEvents) {
|
|
1160
|
+
for (const block of proxiedBlocks) {
|
|
1161
|
+
results[event.id + block.eth_getBlockByNumber.number] ??= {
|
|
1162
|
+
status,
|
|
1163
|
+
event_id: event.id,
|
|
1164
|
+
chain: block.eth_chainId,
|
|
1165
|
+
hash: block.eth_getBlockByNumber.hash,
|
|
1166
|
+
number: block.eth_getBlockByNumber.number,
|
|
1167
|
+
parent_hash: block.eth_getBlockByNumber.parentHash,
|
|
1168
|
+
created_at: Date.now()
|
|
1169
|
+
};
|
|
1159
1170
|
}
|
|
1160
|
-
failures[event.id + block.eth_getBlockByNumber.number] ??= {
|
|
1161
|
-
status,
|
|
1162
|
-
event_id: event.id,
|
|
1163
|
-
chain: block.eth_chainId,
|
|
1164
|
-
hash: block.eth_getBlockByNumber.hash,
|
|
1165
|
-
number: block.eth_getBlockByNumber.number,
|
|
1166
|
-
parent_hash: block.eth_getBlockByNumber.parentHash,
|
|
1167
|
-
created_at: Date.now()
|
|
1168
|
-
};
|
|
1169
1171
|
}
|
|
1170
1172
|
}
|
|
1171
1173
|
}
|
|
1172
|
-
const
|
|
1173
|
-
|
|
1174
|
-
|
|
1174
|
+
for (const event of requestedEvents) {
|
|
1175
|
+
for (const block of proxiedBlocks) {
|
|
1176
|
+
results[event.id + block.eth_getBlockByNumber.number] ??= {
|
|
1177
|
+
status: "ok",
|
|
1178
|
+
event_id: event.id,
|
|
1179
|
+
chain: block.eth_chainId,
|
|
1180
|
+
hash: block.eth_getBlockByNumber.hash,
|
|
1181
|
+
number: block.eth_getBlockByNumber.number,
|
|
1182
|
+
parent_hash: block.eth_getBlockByNumber.parentHash,
|
|
1183
|
+
created_at: Date.now()
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1175
1186
|
}
|
|
1176
1187
|
});
|
|
1177
1188
|
await Promise.all(promises);
|
|
1178
|
-
const
|
|
1179
|
-
return {
|
|
1189
|
+
const resultsArray = Object.values(results);
|
|
1190
|
+
return { results: resultsArray };
|
|
1180
1191
|
};
|
|
1181
1192
|
const private_writeEventsAndGetKeys = async (params) => {
|
|
1182
1193
|
if (allEvents.length === 0) {
|
package/dist/proxy.d.mts
CHANGED
package/dist/proxy.d.ts
CHANGED
package/dist/proxy.mjs
CHANGED
package/dist/realtime.d.mts
CHANGED
package/dist/realtime.d.ts
CHANGED
package/dist/realtime.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hexToNumber } from 'viem';
|
|
2
|
-
import { c as createLogger, i as iife, m as mutex, l as lifecycle, q as queue, r as retry,
|
|
2
|
+
import { c as createLogger, i as iife, m as mutex, l as lifecycle, q as queue, r as retry, b as isHexEqual } from './shared/univo.DAgQmcSe.mjs';
|
|
3
3
|
|
|
4
4
|
function defineBlockchain(opts) {
|
|
5
5
|
const log = createLogger({ quiet: opts.quiet });
|
package/dist/rpc.d.mts
CHANGED
package/dist/rpc.d.ts
CHANGED
|
@@ -51,13 +51,13 @@ type IndexerRpc = {
|
|
|
51
51
|
private_getMetadata: () => Promise<PrivateMetadata>;
|
|
52
52
|
/**
|
|
53
53
|
* Accepts a list of events and a batch of minified block data and writes to storage
|
|
54
|
-
* @returns A list of
|
|
54
|
+
* @returns A list of results indicating the status of each processed block
|
|
55
55
|
*/
|
|
56
56
|
private_writeEvents: (params: {
|
|
57
57
|
events: string[];
|
|
58
58
|
blocks: Block[];
|
|
59
59
|
}) => Promise<{
|
|
60
|
-
|
|
60
|
+
results: Result[];
|
|
61
61
|
}>;
|
|
62
62
|
/**
|
|
63
63
|
* Accepts a block head and writes events to storage
|
|
@@ -51,13 +51,13 @@ type IndexerRpc = {
|
|
|
51
51
|
private_getMetadata: () => Promise<PrivateMetadata>;
|
|
52
52
|
/**
|
|
53
53
|
* Accepts a list of events and a batch of minified block data and writes to storage
|
|
54
|
-
* @returns A list of
|
|
54
|
+
* @returns A list of results indicating the status of each processed block
|
|
55
55
|
*/
|
|
56
56
|
private_writeEvents: (params: {
|
|
57
57
|
events: string[];
|
|
58
58
|
blocks: Block[];
|
|
59
59
|
}) => Promise<{
|
|
60
|
-
|
|
60
|
+
results: Result[];
|
|
61
61
|
}>;
|
|
62
62
|
/**
|
|
63
63
|
* Accepts a block head and writes events to storage
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const name = "univo";
|
|
2
|
-
const version = "0.4.
|
|
2
|
+
const version = "0.4.4";
|
|
3
3
|
|
|
4
4
|
function createLogger(opts) {
|
|
5
5
|
const noop = (..._) => {
|
|
@@ -159,4 +159,4 @@ const normalizeHex = (hex, length) => {
|
|
|
159
159
|
return `0x${hex.slice(2).toLowerCase().padStart(length, "0")}`;
|
|
160
160
|
};
|
|
161
161
|
|
|
162
|
-
export {
|
|
162
|
+
export { compress as a, isHexEqual as b, createLogger as c, decompress as d, decoder as e, iife as i, lifecycle as l, mutex as m, normalizeHex as n, queue as q, retry as r, version as v };
|
package/dist/transport.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { T as Transport, b as browser, h as http, l as local, w as wss } from './shared/univo.
|
|
1
|
+
export { T as Transport, b as browser, h as http, l as local, w as wss } from './shared/univo.Cwz0D-bk.mjs';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './metadata.mjs';
|
|
4
4
|
import './metadata/adapters.mjs';
|
package/dist/transport.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { T as Transport, b as browser, h as http, l as local, w as wss } from './shared/univo.
|
|
1
|
+
export { T as Transport, b as browser, h as http, l as local, w as wss } from './shared/univo.BL1Gu6sU.js';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './metadata.js';
|
|
4
4
|
import './metadata/adapters.js';
|
package/dist/transport.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ws from 'ws';
|
|
2
2
|
import { WebSocket } from 'partysocket';
|
|
3
|
-
import {
|
|
3
|
+
import { c as createLogger, m as mutex, a as compress } from './shared/univo.DAgQmcSe.mjs';
|
|
4
4
|
|
|
5
5
|
const DEFAULT_TIMEOUT_MS = 60 * 1e3;
|
|
6
6
|
function local(rpc) {
|
package/package.json
CHANGED
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
"name": "univo",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.4.
|
|
5
|
+
"version": "0.4.4",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"bin": {
|
|
10
|
-
"univo": "dist/cli.mjs"
|
|
11
|
-
},
|
|
12
9
|
"exports": {
|
|
13
10
|
".": {
|
|
14
11
|
"types": "./dist/index.d.ts",
|
|
@@ -60,15 +57,11 @@
|
|
|
60
57
|
],
|
|
61
58
|
"scripts": {
|
|
62
59
|
"test": "vitest",
|
|
63
|
-
"build": "unbuild"
|
|
64
|
-
"univo": "NODE_ENV=production LOG_LEVEL=DEBUG jiti ./src/cli"
|
|
60
|
+
"build": "unbuild"
|
|
65
61
|
},
|
|
66
62
|
"dependencies": {
|
|
67
63
|
"aws4fetch": "1.0.20",
|
|
68
|
-
"citty": "^0.1.6",
|
|
69
|
-
"dotenv": "^17.2.2",
|
|
70
64
|
"fast-xml-parser": "5.11.1",
|
|
71
|
-
"open": "^10.2.0",
|
|
72
65
|
"partysocket": "^1.1.3",
|
|
73
66
|
"ws": "^8.18.1"
|
|
74
67
|
},
|
|
@@ -77,7 +70,7 @@
|
|
|
77
70
|
"@types/node": "^20.11.27",
|
|
78
71
|
"@types/ws": "^8.18.1",
|
|
79
72
|
"changelogen": "^0.6.1",
|
|
80
|
-
"
|
|
73
|
+
"dotenv": "^17.2.2",
|
|
81
74
|
"msw": "^2.10.2",
|
|
82
75
|
"typescript": "^5.8.2",
|
|
83
76
|
"unbuild": "^3.5.0",
|
package/dist/cli.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/dist/cli.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/dist/cli.mjs
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import ws from 'ws';
|
|
3
|
-
import open from 'open';
|
|
4
|
-
import { config } from 'dotenv';
|
|
5
|
-
import { WebSocket } from 'partysocket';
|
|
6
|
-
import { defineCommand, runMain } from 'citty';
|
|
7
|
-
import { http } from './transport.mjs';
|
|
8
|
-
import { c as createLogger, v as version, n as name } from './shared/univo.DEUuEEoe.mjs';
|
|
9
|
-
|
|
10
|
-
const log = createLogger({ quiet: false });
|
|
11
|
-
const dev = defineCommand({
|
|
12
|
-
args: {
|
|
13
|
-
url: {
|
|
14
|
-
required: true,
|
|
15
|
-
type: "positional",
|
|
16
|
-
description: "Endpoint url like http://localhost:3000"
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
async run(ctx) {
|
|
20
|
-
try {
|
|
21
|
-
if (!ctx.args.url.startsWith("http://")) {
|
|
22
|
-
throw new Error("`url` must start with http://");
|
|
23
|
-
}
|
|
24
|
-
config({ quiet: true });
|
|
25
|
-
const localSigningKey = process.env.UNIVO_SIGNING_KEY;
|
|
26
|
-
if (localSigningKey === void 0) {
|
|
27
|
-
throw new Error("Please provide a UNIVO_SIGNING_KEY environment variable");
|
|
28
|
-
}
|
|
29
|
-
const client = http(ctx.args.url, { signingKey: localSigningKey });
|
|
30
|
-
await client.request({ method: "private_getMetadata", params: [] }).catch(() => {
|
|
31
|
-
throw new Error(`Failed to connect to ${ctx.args.url}. Check that your server is running on the correct port.`);
|
|
32
|
-
});
|
|
33
|
-
const remoteSigningKey = crypto.randomUUID();
|
|
34
|
-
const url = `https://tunnel-univo.app/v1/${crypto.randomUUID()}`;
|
|
35
|
-
const endpoint = {
|
|
36
|
-
url,
|
|
37
|
-
signing_key: remoteSigningKey
|
|
38
|
-
};
|
|
39
|
-
const encoder = new TextEncoder();
|
|
40
|
-
const data = encoder.encode(JSON.stringify(endpoint));
|
|
41
|
-
const encoded = data.toBase64({ alphabet: "base64url", omitPadding: true });
|
|
42
|
-
await open(`https://univo.app/dev/${encoded}`);
|
|
43
|
-
const ws$1 = new WebSocket(url, [], { WebSocket: ws });
|
|
44
|
-
ws$1.binaryType = "arraybuffer";
|
|
45
|
-
ws$1.onerror = (event) => {
|
|
46
|
-
log.error(event.message);
|
|
47
|
-
};
|
|
48
|
-
ws$1.onopen = () => {
|
|
49
|
-
log.info(`Dev server started for ${ctx.args.url}`);
|
|
50
|
-
};
|
|
51
|
-
ws$1.onclose = () => {
|
|
52
|
-
log.info(`Dev server closed for ${ctx.args.url}`);
|
|
53
|
-
};
|
|
54
|
-
ws$1.onmessage = async (event) => {
|
|
55
|
-
try {
|
|
56
|
-
const json = JSON.parse(event.data);
|
|
57
|
-
log.debug(`Received request (${json.id}) for method '${json.method}'`);
|
|
58
|
-
const result = await client.request({ method: json.method, params: json.params });
|
|
59
|
-
ws$1.send(JSON.stringify({ jsonrpc: "2.0", id: json.id, result }));
|
|
60
|
-
} catch {
|
|
61
|
-
ws$1.send(JSON.stringify({ jsonrpc: "2.0", id: null, error: { code: 0, message: "Invalid request" } }));
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
} catch (error) {
|
|
65
|
-
if (error instanceof Error) {
|
|
66
|
-
return log.error(error.message);
|
|
67
|
-
}
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
const main = defineCommand({
|
|
73
|
-
subCommands: { dev },
|
|
74
|
-
meta: { name, version }
|
|
75
|
-
});
|
|
76
|
-
runMain(main).catch((error) => {
|
|
77
|
-
if (error instanceof Error) log.error(error.message);
|
|
78
|
-
process.exit(1);
|
|
79
|
-
});
|