univo 0.4.0 → 0.4.1

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.mlthZw0m.mjs';
8
+ import { c as createLogger, v as version, f as name } from './shared/univo.DD1x3F1G.mjs';
9
9
 
10
10
  const log = createLogger({ quiet: false });
11
11
  const dev = defineCommand({
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, c as Indexer, M as Metadata, e as Result, b as defineAction, a as defineEvent, d as defineIndexer } from './shared/univo.DYd1g40o.mjs';
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.BcZ0twA5.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, c as Indexer, M as Metadata, e as Result, b as defineAction, a as defineEvent, d as defineIndexer } from './shared/univo.CEA4vY0E.js';
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.CNIJRI7c.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, formatTransaction, serializeTransaction, numberToBytes, isHex, concatBytes } from 'viem';
2
2
  import { local } from './transport.mjs';
3
- import { c as createLogger, r as retry, v as version, n as normalizeHex, d as decompress, i as isHexEqual, a as compress, b as iife, e as decoder } from './shared/univo.mlthZw0m.mjs';
3
+ import { c as createLogger, r as retry, v as version, n as normalizeHex, d as decompress, i as isHexEqual, a as compress, b as iife, e as decoder } from './shared/univo.DD1x3F1G.mjs';
4
4
  import { AdapterError } from './metadata/adapters.mjs';
5
5
  import { c as createException, a as catchException } from './shared/univo.C0flyVee.mjs';
6
6
  import 'ws';
@@ -52,7 +52,7 @@ function defineAction(action) {
52
52
  return action;
53
53
  }
54
54
  function defineIndexer(opts) {
55
- const log = createLogger({ quiet: opts.quiet ?? false, prefix: "[indexer]" });
55
+ const log = createLogger({ quiet: opts.quiet, prefix: "[indexer]" });
56
56
  const allEvents = [...opts.events];
57
57
  const eventsGroupedByStorageMap = /* @__PURE__ */ new Map();
58
58
  for (const event of allEvents) {
@@ -74,6 +74,43 @@ function defineIndexer(opts) {
74
74
  }
75
75
  actionIds.add(action.id);
76
76
  }
77
+ const public_getMetadata = async () => {
78
+ return {
79
+ chains: Array.from(
80
+ new Set(
81
+ allEvents.flatMap((event) => {
82
+ return event.filters.flatMap((filter) => {
83
+ return numberToHex(filter.chain);
84
+ });
85
+ })
86
+ )
87
+ )
88
+ };
89
+ };
90
+ const public_getFinalizedHeight = async (chain) => {
91
+ const manifest = await getOrInitManifest(chain);
92
+ return manifest.finalized_block_height;
93
+ };
94
+ async function getOrInitManifest(chain) {
95
+ const path = `manifest/v1/${normalizeHex(chain)}`;
96
+ const manifestRes = await opts.metadataStorage.adapter.get(path);
97
+ let manifest;
98
+ if (manifestRes === null) {
99
+ const block = await getBlockFromChain({ chain, number: "finalized" });
100
+ const chainFinalizedHeight = hexToNumber(block.eth_getBlockByNumber.number);
101
+ const newManifest = {
102
+ finalized_block_height: chainFinalizedHeight,
103
+ finalized_block_hash: block.eth_getBlockByNumber.hash,
104
+ next_finalized_height: chainFinalizedHeight,
105
+ updated_at: Date.now()
106
+ };
107
+ await opts.metadataStorage.adapter.put(path, JSON.stringify(newManifest), { ifNoneMatch: "*" });
108
+ manifest = newManifest;
109
+ } else {
110
+ manifest = JSON.parse(decoder.decode(manifestRes.body));
111
+ }
112
+ return manifest;
113
+ }
77
114
  async function getBlockFromChain(head) {
78
115
  return await retry(() => retry_getBlockFromChain(head), 2);
79
116
  }
@@ -334,30 +371,6 @@ function defineIndexer(opts) {
334
371
  throw new Error("Block returned inconsistent gas used");
335
372
  }
336
373
  }
337
- const public_getFinalizedHeight = async (chain) => {
338
- const manifest = await getOrInitManifest(chain);
339
- return manifest.finalized_block_height;
340
- };
341
- async function getOrInitManifest(chain) {
342
- const path = `manifest/v1/${normalizeHex(chain)}`;
343
- const manifestRes = await opts.metadataStorage.adapter.get(path);
344
- let manifest;
345
- if (manifestRes === null) {
346
- const block = await getBlockFromChain({ chain, number: "finalized" });
347
- const chainFinalizedHeight = hexToNumber(block.eth_getBlockByNumber.number);
348
- const newManifest = {
349
- finalized_block_height: chainFinalizedHeight,
350
- finalized_block_hash: block.eth_getBlockByNumber.hash,
351
- next_finalized_height: chainFinalizedHeight,
352
- updated_at: Date.now()
353
- };
354
- await opts.metadataStorage.adapter.put(path, JSON.stringify(newManifest), { ifNoneMatch: "*" });
355
- manifest = newManifest;
356
- } else {
357
- manifest = JSON.parse(decoder.decode(manifestRes.body));
358
- }
359
- return manifest;
360
- }
361
374
  const public_writeUnfinalizedHead = async (head) => {
362
375
  log.debug("Received unfinalized head...");
363
376
  const blocksStart = Date.now();
@@ -909,23 +922,21 @@ function defineIndexer(opts) {
909
922
  const private_getMetadata = async () => {
910
923
  return {
911
924
  version,
912
- language: "javascript"
925
+ language: "javascript",
926
+ events: allEvents.map((event) => {
927
+ const filters = event.filters.map((filter) => {
928
+ return {
929
+ chain: filter.chain,
930
+ event: filter.event,
931
+ address: filter.address,
932
+ to_block: filter.toBlock,
933
+ from_block: filter.fromBlock
934
+ };
935
+ });
936
+ return { id: event.id, filters };
937
+ })
913
938
  };
914
939
  };
915
- const private_getEvents = async () => {
916
- return allEvents.map((event) => {
917
- const filters = event.filters.map((filter) => {
918
- return {
919
- chain: filter.chain,
920
- event: filter.event,
921
- address: filter.address,
922
- to_block: filter.toBlock,
923
- from_block: filter.fromBlock
924
- };
925
- });
926
- return { id: event.id, filters };
927
- });
928
- };
929
940
  const ignored = [
930
941
  "toJSON",
931
942
  "toString",
@@ -1177,12 +1188,12 @@ function defineIndexer(opts) {
1177
1188
  const rpc = {
1178
1189
  request: {
1179
1190
  public_finalize,
1191
+ public_getMetadata,
1180
1192
  public_getFinalizedHeight,
1181
1193
  public_writeFinalizedHead,
1182
1194
  public_writeFinalizedHeight,
1183
1195
  public_writeUnfinalizedHead,
1184
1196
  public_deleteReorganisedHead,
1185
- private_getEvents,
1186
1197
  private_getMetadata,
1187
1198
  private_writeEvents,
1188
1199
  private_writeEventsAndGetKeys
package/dist/proxy.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { T as Transport, I as IndexerRpc } from './shared/univo.DYd1g40o.mjs';
1
+ import { T as Transport, I as IndexerRpc } from './shared/univo.BcZ0twA5.mjs';
2
2
  import 'viem';
3
3
  import './metadata.mjs';
4
4
  import './metadata/adapters.mjs';
package/dist/proxy.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { T as Transport, I as IndexerRpc } from './shared/univo.CEA4vY0E.js';
1
+ import { T as Transport, I as IndexerRpc } from './shared/univo.CNIJRI7c.js';
2
2
  import 'viem';
3
3
  import './metadata.js';
4
4
  import './metadata/adapters.js';
package/dist/proxy.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { g as getException } from './shared/univo.C0flyVee.mjs';
2
- import { c as createLogger, d as decompress, e as decoder } from './shared/univo.mlthZw0m.mjs';
2
+ import { c as createLogger, d as decompress, e as decoder } from './shared/univo.DD1x3F1G.mjs';
3
3
 
4
4
  function http(opts) {
5
- const log = createLogger({ quiet: opts.quiet ?? false, prefix: "[proxy]" });
5
+ const log = createLogger({ quiet: opts.quiet, prefix: "[proxy]" });
6
6
  return async function proxy(req) {
7
7
  let body_buffer;
8
8
  try {
@@ -1,4 +1,4 @@
1
- import { T as Transport, R as Rpc, I as IndexerRpc } from './shared/univo.DYd1g40o.mjs';
1
+ import { T as Transport, R as Rpc, I as IndexerRpc } from './shared/univo.BcZ0twA5.mjs';
2
2
  import 'viem';
3
3
  import './metadata.mjs';
4
4
  import './metadata/adapters.mjs';
@@ -14,9 +14,9 @@ type RealtimeOptions = {
14
14
  /**
15
15
  * Connection to a blockchain node.
16
16
  *
17
- * Must use the `wss` transport protocol from `univo/transport`.
17
+ * Must use the `wss` or `browser` transport protocol from `univo/transport`.
18
18
  */
19
- node: Transport<Rpc, "wss">;
19
+ node: Transport<Rpc, "wss" | "browser">;
20
20
  /**
21
21
  * Connection to a univo indexer.
22
22
  *
@@ -25,6 +25,6 @@ type RealtimeOptions = {
25
25
  */
26
26
  indexer: Transport<IndexerRpc, "http" | "local">;
27
27
  };
28
- declare function realtime(opts: RealtimeOptions): void;
28
+ declare function realtime(realtime: RealtimeOptions): void;
29
29
 
30
30
  export { realtime };
@@ -1,4 +1,4 @@
1
- import { T as Transport, R as Rpc, I as IndexerRpc } from './shared/univo.CEA4vY0E.js';
1
+ import { T as Transport, R as Rpc, I as IndexerRpc } from './shared/univo.CNIJRI7c.js';
2
2
  import 'viem';
3
3
  import './metadata.js';
4
4
  import './metadata/adapters.js';
@@ -14,9 +14,9 @@ type RealtimeOptions = {
14
14
  /**
15
15
  * Connection to a blockchain node.
16
16
  *
17
- * Must use the `wss` transport protocol from `univo/transport`.
17
+ * Must use the `wss` or `browser` transport protocol from `univo/transport`.
18
18
  */
19
- node: Transport<Rpc, "wss">;
19
+ node: Transport<Rpc, "wss" | "browser">;
20
20
  /**
21
21
  * Connection to a univo indexer.
22
22
  *
@@ -25,6 +25,6 @@ type RealtimeOptions = {
25
25
  */
26
26
  indexer: Transport<IndexerRpc, "http" | "local">;
27
27
  };
28
- declare function realtime(opts: RealtimeOptions): void;
28
+ declare function realtime(realtime: RealtimeOptions): void;
29
29
 
30
30
  export { realtime };