univo 0.2.10 → 0.2.12
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 -3
- package/dist/index.d.mts +2 -189
- package/dist/index.d.ts +2 -189
- package/dist/index.mjs +47 -28
- package/dist/realtime.d.mts +1 -1
- package/dist/realtime.d.ts +1 -1
- package/dist/realtime.mjs +2 -2
- package/dist/rpc.d.mts +4 -9
- package/dist/rpc.d.ts +4 -9
- package/dist/shared/univo.Bb9Aplq9.mjs +221 -0
- package/dist/shared/univo.Cj4s4jNq.d.mts +219 -0
- package/dist/shared/univo.Cj4s4jNq.d.ts +219 -0
- package/dist/shared/{univo.DfCC9G2B.mjs → univo.DicQZf-2.mjs} +5 -5
- package/dist/transport.d.mts +5 -4
- package/dist/transport.d.ts +5 -4
- package/dist/transport.mjs +4 -185
- package/package.json +1 -3
- package/dist/shared/univo.C0flyVee.mjs +0 -21
package/dist/cli.mjs
CHANGED
|
@@ -4,9 +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 { http } from './
|
|
8
|
-
import { c as createLogger, v as version, f as name } from './shared/univo.
|
|
9
|
-
import './shared/univo.C0flyVee.mjs';
|
|
7
|
+
import { h as http } from './shared/univo.Bb9Aplq9.mjs';
|
|
8
|
+
import { c as createLogger, v as version, f as name } from './shared/univo.DicQZf-2.mjs';
|
|
10
9
|
|
|
11
10
|
const log = createLogger({ quiet: false });
|
|
12
11
|
const dev = defineCommand({
|
package/dist/index.d.mts
CHANGED
|
@@ -1,189 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Block -----------------------------------------------------------------------------------------------------------------------------------
|
|
5
|
-
*/
|
|
6
|
-
type Block = {
|
|
7
|
-
eth_chainId: `0x${string}`;
|
|
8
|
-
eth_getBlockByNumber: {
|
|
9
|
-
hash: `0x${string}`;
|
|
10
|
-
number: `0x${string}`;
|
|
11
|
-
parentHash: `0x${string}`;
|
|
12
|
-
};
|
|
13
|
-
eth_getBlockReceipts: Array<{
|
|
14
|
-
blockHash: `0x${string}`;
|
|
15
|
-
logs: Array<{
|
|
16
|
-
address: `0x${string}`;
|
|
17
|
-
topics: `0x${string}`[];
|
|
18
|
-
}>;
|
|
19
|
-
}>;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Filters -----------------------------------------------------------------------------------------------------------------------------------
|
|
23
|
-
*/
|
|
24
|
-
type Filter = {
|
|
25
|
-
/** Index blocks with this chain id */
|
|
26
|
-
chain: number;
|
|
27
|
-
/** Index blocks from this start block (inclusive) */
|
|
28
|
-
fromBlock: number;
|
|
29
|
-
/** Index blocks until this stop block (inclusive) */
|
|
30
|
-
toBlock?: number;
|
|
31
|
-
/** Index blocks where this event topic was emitted */
|
|
32
|
-
event?: `0x${string}`;
|
|
33
|
-
/** Index blocks that involve this address */
|
|
34
|
-
address?: `0x${string}`;
|
|
35
|
-
};
|
|
36
|
-
declare function matchFilter(block: Block, filter: Filter): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Events -----------------------------------------------------------------------------------------------------------------------------------
|
|
39
|
-
*/
|
|
40
|
-
type Event<TBlock, TEvent> = {
|
|
41
|
-
/**
|
|
42
|
-
* A human-readable identifier for the event.
|
|
43
|
-
*/
|
|
44
|
-
id: string;
|
|
45
|
-
/**
|
|
46
|
-
* Filters let you define what specific blocks you want this event to index.
|
|
47
|
-
*
|
|
48
|
-
* Blockchains are massive datasets and most of the time we are only ever interested in small portions of it.
|
|
49
|
-
* Sometimes that can be specific events like ERC20 transfers and other times it could be all events emitted
|
|
50
|
-
* by a specific contract. Filters provide a simple way for an event to define exactly which blocks we want
|
|
51
|
-
* to index.
|
|
52
|
-
*
|
|
53
|
-
* Filters reduce costs and improve backfill performance by ensuring we only index the blocks we need and
|
|
54
|
-
* ignore the blocks that don't have the data we are interested in.
|
|
55
|
-
*
|
|
56
|
-
* By default your event will not index any blocks, you must opt-in to indexing by providing atleast one filter.
|
|
57
|
-
*
|
|
58
|
-
* Each property in the filter operates like an AND statement. For example, if you specifiy an `address` and
|
|
59
|
-
* an `event` it implies that you only want to index blocks where the specific `address` emitted the specific
|
|
60
|
-
* `event` topic provided.
|
|
61
|
-
*
|
|
62
|
-
* However, when multiple filters are defined for a given event those filters operate like an OR statement. For
|
|
63
|
-
* example, if we define a second filter looking for a different `address` and `event` our event will now index
|
|
64
|
-
* any block that matches either the first filter or the second filter.
|
|
65
|
-
*
|
|
66
|
-
* Note that filters are a rudimentary method to dramatically reduce the number of blocks your application needs
|
|
67
|
-
* to index. Any advanced filtering should be performed in the event `handler` itself.
|
|
68
|
-
*/
|
|
69
|
-
filters: Filter[];
|
|
70
|
-
/**
|
|
71
|
-
* Synchronously transforms a raw block into a list of events.
|
|
72
|
-
*
|
|
73
|
-
* When a block matches any of filters defined by your event it will be passed to this function to be synchronously
|
|
74
|
-
* transformed into a list of structured events.
|
|
75
|
-
*
|
|
76
|
-
* The shape of the input `block` is determined by the return value of `getBlock` function provided to your `indexer`.
|
|
77
|
-
*
|
|
78
|
-
* The returned output value should be an array containg any valid JavaScript values. Each event that you return from
|
|
79
|
-
* your handler should not depend on any information outside of the input block data. It should directly map a given
|
|
80
|
-
* input (the raw block) to a given output (structured events). This ensures that handler remains idempotent and that
|
|
81
|
-
* repeated calls with the same input block produce the same output events.
|
|
82
|
-
*/
|
|
83
|
-
handler: (block: TBlock) => TEvent[];
|
|
84
|
-
/**
|
|
85
|
-
* Storage adapter to persist events in your off-chain storage.
|
|
86
|
-
*/
|
|
87
|
-
storage: {
|
|
88
|
-
/**
|
|
89
|
-
* Upserts a batch of events into your storage system.
|
|
90
|
-
*
|
|
91
|
-
* After a block is transformed into a list of structured events by your `handler` function, that batch
|
|
92
|
-
* is passed to this `upsert` function so they can be upserted into your storage system.
|
|
93
|
-
*
|
|
94
|
-
* This function must be idempotent. Functionally, this means that if the same batch of events is upserted
|
|
95
|
-
* multiple times it only produces a single set of events in your storage system.
|
|
96
|
-
*/
|
|
97
|
-
upsert: (events: TEvent[]) => Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Deletes a batch of events from your storage system.
|
|
100
|
-
*
|
|
101
|
-
* When your indexer encounters a chain reorganisation, this `delete` function will be invoked with the
|
|
102
|
-
* same batch of events created by that reorganised block. This ensures that any events that were previously
|
|
103
|
-
* upserted into your storage system that are no longer part of the canonical chain are safely removed.
|
|
104
|
-
*/
|
|
105
|
-
delete?: (events: TEvent[]) => Promise<void>;
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Indexer -----------------------------------------------------------------------------------------------------------------------------------
|
|
110
|
-
*/
|
|
111
|
-
type Head = {
|
|
112
|
-
hash: `0x${string}`;
|
|
113
|
-
chain: `0x${string}`;
|
|
114
|
-
number: `0x${string}`;
|
|
115
|
-
parentHash: `0x${string}`;
|
|
116
|
-
};
|
|
117
|
-
type Metadata = {
|
|
118
|
-
version: string;
|
|
119
|
-
language: string;
|
|
120
|
-
};
|
|
121
|
-
type Result = {
|
|
122
|
-
status: string;
|
|
123
|
-
event_id: string;
|
|
124
|
-
chain: `0x${string}`;
|
|
125
|
-
block_hash: `0x${string}`;
|
|
126
|
-
block_number: `0x${string}`;
|
|
127
|
-
created_at: number;
|
|
128
|
-
};
|
|
129
|
-
type IndexerOptions<TBlock> = {
|
|
130
|
-
/**
|
|
131
|
-
* Silences all logs including errors.
|
|
132
|
-
*
|
|
133
|
-
* Logs are emitted based on the environment LOG_LEVEL. Set `quiet: true` to surpress all logs.
|
|
134
|
-
* Available log options are `DEBUG`, `INFO`, `WARN`, and `ERROR`.
|
|
135
|
-
*/
|
|
136
|
-
quiet?: boolean;
|
|
137
|
-
/**
|
|
138
|
-
* Request signing key
|
|
139
|
-
*
|
|
140
|
-
* Facilitates secure communication with a trusted source like the univo dashboard.
|
|
141
|
-
*/
|
|
142
|
-
signingKey: string;
|
|
143
|
-
/**
|
|
144
|
-
* Storage interface for durably persisting indexer metadata.
|
|
145
|
-
*
|
|
146
|
-
* This uses the unified key-value storage API from unstorage. Install the `unstorage` dependency
|
|
147
|
-
* and provide the return value of your `createStorage()` call. Check out the documentation for
|
|
148
|
-
* a full list of [supported storage drivers](https://unstorage.unjs.io/drivers).
|
|
149
|
-
*
|
|
150
|
-
* Functionally, storing metadata is fundamental to ensure the correct operation of your indexer. It
|
|
151
|
-
* ensures that you indexer recovers from downtime and ensures that all blocks are processed correctly during
|
|
152
|
-
* chain reorganisations.
|
|
153
|
-
*/
|
|
154
|
-
metadataStorage: Storage;
|
|
155
|
-
/**
|
|
156
|
-
* Loads raw block data in realtime from a trusted set of RPC sources.
|
|
157
|
-
*
|
|
158
|
-
* Note that historical backfills do not use this function to load block data.
|
|
159
|
-
*
|
|
160
|
-
* The response from this function determines the input data to your `handler` functions in each event.
|
|
161
|
-
* Generally, the shape is a list of RPC methods with their corresponding value from an RPC node. This
|
|
162
|
-
* generic format allows you support the full range of RPC data available to you from your node. This
|
|
163
|
-
* flexibility is important in cases where some methods are supported on specific chains only.
|
|
164
|
-
*
|
|
165
|
-
* Note that there is a minimum set of RPC methods expected on the response notably `eth_chainId`,
|
|
166
|
-
* `eth_getBlockByNumber` and `eth_getBlockReceipts`. These are expected so that we can safely match
|
|
167
|
-
* each block processed against your event filters.
|
|
168
|
-
*
|
|
169
|
-
* Note that we provide only the block number to look up block data. During a chain reorganisation, this
|
|
170
|
-
* makes it possible for different RPC calls to return data for different block hashes. We manually verify
|
|
171
|
-
* that all methods return the expected block hash. However, for any custom methods you add you must manually
|
|
172
|
-
* verify the block hash is consistent with the other known methods.
|
|
173
|
-
*/
|
|
174
|
-
getBlock: (block: {
|
|
175
|
-
chain: `0x${string}`;
|
|
176
|
-
number: string;
|
|
177
|
-
}) => Promise<TBlock | null>;
|
|
178
|
-
};
|
|
179
|
-
type Indexer<TBlock> = {
|
|
180
|
-
fetch: (req: Request) => Promise<Response>;
|
|
181
|
-
event: <TEvent>(event: Event<TBlock, TEvent>) => Event<TBlock, TEvent>;
|
|
182
|
-
};
|
|
183
|
-
declare function indexer<TBlock extends Block>(opts: IndexerOptions<TBlock>): {
|
|
184
|
-
fetch: (req: Request) => Promise<Response>;
|
|
185
|
-
event: <TEvent>(event: Event<TBlock, TEvent>) => Event<TBlock, TEvent>;
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
export { indexer, matchFilter };
|
|
189
|
-
export type { Block, Event, Filter, Head, Indexer, Metadata, Result };
|
|
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.Cj4s4jNq.mjs';
|
|
2
|
+
import 'unstorage';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,189 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Block -----------------------------------------------------------------------------------------------------------------------------------
|
|
5
|
-
*/
|
|
6
|
-
type Block = {
|
|
7
|
-
eth_chainId: `0x${string}`;
|
|
8
|
-
eth_getBlockByNumber: {
|
|
9
|
-
hash: `0x${string}`;
|
|
10
|
-
number: `0x${string}`;
|
|
11
|
-
parentHash: `0x${string}`;
|
|
12
|
-
};
|
|
13
|
-
eth_getBlockReceipts: Array<{
|
|
14
|
-
blockHash: `0x${string}`;
|
|
15
|
-
logs: Array<{
|
|
16
|
-
address: `0x${string}`;
|
|
17
|
-
topics: `0x${string}`[];
|
|
18
|
-
}>;
|
|
19
|
-
}>;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Filters -----------------------------------------------------------------------------------------------------------------------------------
|
|
23
|
-
*/
|
|
24
|
-
type Filter = {
|
|
25
|
-
/** Index blocks with this chain id */
|
|
26
|
-
chain: number;
|
|
27
|
-
/** Index blocks from this start block (inclusive) */
|
|
28
|
-
fromBlock: number;
|
|
29
|
-
/** Index blocks until this stop block (inclusive) */
|
|
30
|
-
toBlock?: number;
|
|
31
|
-
/** Index blocks where this event topic was emitted */
|
|
32
|
-
event?: `0x${string}`;
|
|
33
|
-
/** Index blocks that involve this address */
|
|
34
|
-
address?: `0x${string}`;
|
|
35
|
-
};
|
|
36
|
-
declare function matchFilter(block: Block, filter: Filter): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Events -----------------------------------------------------------------------------------------------------------------------------------
|
|
39
|
-
*/
|
|
40
|
-
type Event<TBlock, TEvent> = {
|
|
41
|
-
/**
|
|
42
|
-
* A human-readable identifier for the event.
|
|
43
|
-
*/
|
|
44
|
-
id: string;
|
|
45
|
-
/**
|
|
46
|
-
* Filters let you define what specific blocks you want this event to index.
|
|
47
|
-
*
|
|
48
|
-
* Blockchains are massive datasets and most of the time we are only ever interested in small portions of it.
|
|
49
|
-
* Sometimes that can be specific events like ERC20 transfers and other times it could be all events emitted
|
|
50
|
-
* by a specific contract. Filters provide a simple way for an event to define exactly which blocks we want
|
|
51
|
-
* to index.
|
|
52
|
-
*
|
|
53
|
-
* Filters reduce costs and improve backfill performance by ensuring we only index the blocks we need and
|
|
54
|
-
* ignore the blocks that don't have the data we are interested in.
|
|
55
|
-
*
|
|
56
|
-
* By default your event will not index any blocks, you must opt-in to indexing by providing atleast one filter.
|
|
57
|
-
*
|
|
58
|
-
* Each property in the filter operates like an AND statement. For example, if you specifiy an `address` and
|
|
59
|
-
* an `event` it implies that you only want to index blocks where the specific `address` emitted the specific
|
|
60
|
-
* `event` topic provided.
|
|
61
|
-
*
|
|
62
|
-
* However, when multiple filters are defined for a given event those filters operate like an OR statement. For
|
|
63
|
-
* example, if we define a second filter looking for a different `address` and `event` our event will now index
|
|
64
|
-
* any block that matches either the first filter or the second filter.
|
|
65
|
-
*
|
|
66
|
-
* Note that filters are a rudimentary method to dramatically reduce the number of blocks your application needs
|
|
67
|
-
* to index. Any advanced filtering should be performed in the event `handler` itself.
|
|
68
|
-
*/
|
|
69
|
-
filters: Filter[];
|
|
70
|
-
/**
|
|
71
|
-
* Synchronously transforms a raw block into a list of events.
|
|
72
|
-
*
|
|
73
|
-
* When a block matches any of filters defined by your event it will be passed to this function to be synchronously
|
|
74
|
-
* transformed into a list of structured events.
|
|
75
|
-
*
|
|
76
|
-
* The shape of the input `block` is determined by the return value of `getBlock` function provided to your `indexer`.
|
|
77
|
-
*
|
|
78
|
-
* The returned output value should be an array containg any valid JavaScript values. Each event that you return from
|
|
79
|
-
* your handler should not depend on any information outside of the input block data. It should directly map a given
|
|
80
|
-
* input (the raw block) to a given output (structured events). This ensures that handler remains idempotent and that
|
|
81
|
-
* repeated calls with the same input block produce the same output events.
|
|
82
|
-
*/
|
|
83
|
-
handler: (block: TBlock) => TEvent[];
|
|
84
|
-
/**
|
|
85
|
-
* Storage adapter to persist events in your off-chain storage.
|
|
86
|
-
*/
|
|
87
|
-
storage: {
|
|
88
|
-
/**
|
|
89
|
-
* Upserts a batch of events into your storage system.
|
|
90
|
-
*
|
|
91
|
-
* After a block is transformed into a list of structured events by your `handler` function, that batch
|
|
92
|
-
* is passed to this `upsert` function so they can be upserted into your storage system.
|
|
93
|
-
*
|
|
94
|
-
* This function must be idempotent. Functionally, this means that if the same batch of events is upserted
|
|
95
|
-
* multiple times it only produces a single set of events in your storage system.
|
|
96
|
-
*/
|
|
97
|
-
upsert: (events: TEvent[]) => Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Deletes a batch of events from your storage system.
|
|
100
|
-
*
|
|
101
|
-
* When your indexer encounters a chain reorganisation, this `delete` function will be invoked with the
|
|
102
|
-
* same batch of events created by that reorganised block. This ensures that any events that were previously
|
|
103
|
-
* upserted into your storage system that are no longer part of the canonical chain are safely removed.
|
|
104
|
-
*/
|
|
105
|
-
delete?: (events: TEvent[]) => Promise<void>;
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Indexer -----------------------------------------------------------------------------------------------------------------------------------
|
|
110
|
-
*/
|
|
111
|
-
type Head = {
|
|
112
|
-
hash: `0x${string}`;
|
|
113
|
-
chain: `0x${string}`;
|
|
114
|
-
number: `0x${string}`;
|
|
115
|
-
parentHash: `0x${string}`;
|
|
116
|
-
};
|
|
117
|
-
type Metadata = {
|
|
118
|
-
version: string;
|
|
119
|
-
language: string;
|
|
120
|
-
};
|
|
121
|
-
type Result = {
|
|
122
|
-
status: string;
|
|
123
|
-
event_id: string;
|
|
124
|
-
chain: `0x${string}`;
|
|
125
|
-
block_hash: `0x${string}`;
|
|
126
|
-
block_number: `0x${string}`;
|
|
127
|
-
created_at: number;
|
|
128
|
-
};
|
|
129
|
-
type IndexerOptions<TBlock> = {
|
|
130
|
-
/**
|
|
131
|
-
* Silences all logs including errors.
|
|
132
|
-
*
|
|
133
|
-
* Logs are emitted based on the environment LOG_LEVEL. Set `quiet: true` to surpress all logs.
|
|
134
|
-
* Available log options are `DEBUG`, `INFO`, `WARN`, and `ERROR`.
|
|
135
|
-
*/
|
|
136
|
-
quiet?: boolean;
|
|
137
|
-
/**
|
|
138
|
-
* Request signing key
|
|
139
|
-
*
|
|
140
|
-
* Facilitates secure communication with a trusted source like the univo dashboard.
|
|
141
|
-
*/
|
|
142
|
-
signingKey: string;
|
|
143
|
-
/**
|
|
144
|
-
* Storage interface for durably persisting indexer metadata.
|
|
145
|
-
*
|
|
146
|
-
* This uses the unified key-value storage API from unstorage. Install the `unstorage` dependency
|
|
147
|
-
* and provide the return value of your `createStorage()` call. Check out the documentation for
|
|
148
|
-
* a full list of [supported storage drivers](https://unstorage.unjs.io/drivers).
|
|
149
|
-
*
|
|
150
|
-
* Functionally, storing metadata is fundamental to ensure the correct operation of your indexer. It
|
|
151
|
-
* ensures that you indexer recovers from downtime and ensures that all blocks are processed correctly during
|
|
152
|
-
* chain reorganisations.
|
|
153
|
-
*/
|
|
154
|
-
metadataStorage: Storage;
|
|
155
|
-
/**
|
|
156
|
-
* Loads raw block data in realtime from a trusted set of RPC sources.
|
|
157
|
-
*
|
|
158
|
-
* Note that historical backfills do not use this function to load block data.
|
|
159
|
-
*
|
|
160
|
-
* The response from this function determines the input data to your `handler` functions in each event.
|
|
161
|
-
* Generally, the shape is a list of RPC methods with their corresponding value from an RPC node. This
|
|
162
|
-
* generic format allows you support the full range of RPC data available to you from your node. This
|
|
163
|
-
* flexibility is important in cases where some methods are supported on specific chains only.
|
|
164
|
-
*
|
|
165
|
-
* Note that there is a minimum set of RPC methods expected on the response notably `eth_chainId`,
|
|
166
|
-
* `eth_getBlockByNumber` and `eth_getBlockReceipts`. These are expected so that we can safely match
|
|
167
|
-
* each block processed against your event filters.
|
|
168
|
-
*
|
|
169
|
-
* Note that we provide only the block number to look up block data. During a chain reorganisation, this
|
|
170
|
-
* makes it possible for different RPC calls to return data for different block hashes. We manually verify
|
|
171
|
-
* that all methods return the expected block hash. However, for any custom methods you add you must manually
|
|
172
|
-
* verify the block hash is consistent with the other known methods.
|
|
173
|
-
*/
|
|
174
|
-
getBlock: (block: {
|
|
175
|
-
chain: `0x${string}`;
|
|
176
|
-
number: string;
|
|
177
|
-
}) => Promise<TBlock | null>;
|
|
178
|
-
};
|
|
179
|
-
type Indexer<TBlock> = {
|
|
180
|
-
fetch: (req: Request) => Promise<Response>;
|
|
181
|
-
event: <TEvent>(event: Event<TBlock, TEvent>) => Event<TBlock, TEvent>;
|
|
182
|
-
};
|
|
183
|
-
declare function indexer<TBlock extends Block>(opts: IndexerOptions<TBlock>): {
|
|
184
|
-
fetch: (req: Request) => Promise<Response>;
|
|
185
|
-
event: <TEvent>(event: Event<TBlock, TEvent>) => Event<TBlock, TEvent>;
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
export { indexer, matchFilter };
|
|
189
|
-
export type { Block, Event, Filter, Head, Indexer, Metadata, Result };
|
|
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.Cj4s4jNq.js';
|
|
2
|
+
import 'unstorage';
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { c as
|
|
1
|
+
import { c as createException, a as catchException, l as local, g as getException } from './shared/univo.Bb9Aplq9.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.DicQZf-2.mjs';
|
|
3
|
+
import 'ws';
|
|
4
|
+
import 'partysocket';
|
|
3
5
|
|
|
4
6
|
function matchFilter(block, filter) {
|
|
5
7
|
if (!chainValid(block, filter)) return false;
|
|
@@ -556,10 +558,20 @@ function indexer(opts) {
|
|
|
556
558
|
return { failures: failures_array };
|
|
557
559
|
};
|
|
558
560
|
const private_writeEventsAndGetKeys = async (params) => {
|
|
559
|
-
if (all_events.length === 0)
|
|
560
|
-
|
|
561
|
+
if (all_events.length === 0) {
|
|
562
|
+
return { results: [], keys: [] };
|
|
563
|
+
}
|
|
564
|
+
if (params.events.length === 0) {
|
|
565
|
+
return { results: [], keys: [] };
|
|
566
|
+
}
|
|
561
567
|
const relevant_events = all_events.filter((event2) => params.events.includes(event2.id));
|
|
562
|
-
if (relevant_events.length === 0)
|
|
568
|
+
if (relevant_events.length === 0) {
|
|
569
|
+
return { results: [], keys: [] };
|
|
570
|
+
}
|
|
571
|
+
const block = await getBlock(params.head);
|
|
572
|
+
if (block === null) {
|
|
573
|
+
throw new Error(GetBlockError);
|
|
574
|
+
}
|
|
563
575
|
const keys = /* @__PURE__ */ new Set();
|
|
564
576
|
const results = {};
|
|
565
577
|
function createProxyHandler(path) {
|
|
@@ -581,7 +593,7 @@ function indexer(opts) {
|
|
|
581
593
|
}
|
|
582
594
|
};
|
|
583
595
|
}
|
|
584
|
-
const proxy = new Proxy(
|
|
596
|
+
const proxy = new Proxy(block, createProxyHandler(""));
|
|
585
597
|
await Promise.all(
|
|
586
598
|
relevant_events.map(async (event2) => {
|
|
587
599
|
if (!event2.filters.some((filter) => matchFilter(proxy, filter))) {
|
|
@@ -653,26 +665,19 @@ function indexer(opts) {
|
|
|
653
665
|
return { results: results_array, keys: filtered_keys };
|
|
654
666
|
};
|
|
655
667
|
const rpc = {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
668
|
+
request: {
|
|
669
|
+
public_getFinalizedHeight,
|
|
670
|
+
public_writeFinalizedHeads,
|
|
671
|
+
public_writeUnfinalizedHeads,
|
|
672
|
+
public_deleteReorganisedHead,
|
|
673
|
+
private_getEvents,
|
|
674
|
+
private_getMetadata,
|
|
675
|
+
private_writeEvents,
|
|
676
|
+
private_writeEventsAndGetKeys
|
|
677
|
+
},
|
|
678
|
+
subscribe: {}
|
|
664
679
|
};
|
|
665
|
-
const
|
|
666
|
-
if (!/^[A-Za-z0-9_-]+$/.test(event2.id)) {
|
|
667
|
-
throw new Error(`Invalid event id \`${event2.id}\`. Only characters A-Z, a-z, 0-9, underscores, and hyphens are permitted.`);
|
|
668
|
-
}
|
|
669
|
-
all_events.push(event2);
|
|
670
|
-
const group = events_grouped_by_storage_map.get(event2.storage) ?? [];
|
|
671
|
-
group.push(event2);
|
|
672
|
-
events_grouped_by_storage_map.set(event2.storage, group);
|
|
673
|
-
return event2;
|
|
674
|
-
};
|
|
675
|
-
const UnknownMethodError = createException("The requested method does not exist");
|
|
680
|
+
const transport = local(rpc);
|
|
676
681
|
const handler = async (req) => {
|
|
677
682
|
let body_buffer;
|
|
678
683
|
try {
|
|
@@ -733,8 +738,7 @@ function indexer(opts) {
|
|
|
733
738
|
}
|
|
734
739
|
}
|
|
735
740
|
try {
|
|
736
|
-
|
|
737
|
-
const result = await rpc[json.method](...json.params);
|
|
741
|
+
const result = await transport.request({ method: json.method, params: json.params });
|
|
738
742
|
return Response.json({ jsonrpc: "2.0", id: json.id, result });
|
|
739
743
|
} catch (error) {
|
|
740
744
|
const message = getException(error);
|
|
@@ -756,7 +760,22 @@ function indexer(opts) {
|
|
|
756
760
|
);
|
|
757
761
|
}
|
|
758
762
|
};
|
|
759
|
-
|
|
763
|
+
const event = (event2) => {
|
|
764
|
+
if (!/^[A-Za-z0-9_-]+$/.test(event2.id)) {
|
|
765
|
+
throw new Error(`Invalid event id \`${event2.id}\`. Only characters A-Z, a-z, 0-9, underscores, and hyphens are permitted.`);
|
|
766
|
+
}
|
|
767
|
+
all_events.push(event2);
|
|
768
|
+
const group = events_grouped_by_storage_map.get(event2.storage) ?? [];
|
|
769
|
+
group.push(event2);
|
|
770
|
+
events_grouped_by_storage_map.set(event2.storage, group);
|
|
771
|
+
return event2;
|
|
772
|
+
};
|
|
773
|
+
const indexer2 = {
|
|
774
|
+
...rpc,
|
|
775
|
+
event,
|
|
776
|
+
fetch: handler
|
|
777
|
+
};
|
|
778
|
+
return indexer2;
|
|
760
779
|
}
|
|
761
780
|
|
|
762
781
|
export { indexer, matchFilter };
|
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, b as iife, h as hexToNumber, e as numberToHex, m as mutex, r as retry, i as isHexEqual } from './shared/univo.
|
|
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.DicQZf-2.mjs';
|
|
2
2
|
|
|
3
3
|
const MAX_LENGTH = 1e4;
|
|
4
4
|
function defineBlockchain(opts) {
|
|
@@ -102,7 +102,7 @@ function realtime(opts) {
|
|
|
102
102
|
pending.push(head);
|
|
103
103
|
const heads = pending.map((head2) => ({ chain, ...head2 }));
|
|
104
104
|
await opts.indexer.request({ method: "public_writeUnfinalizedHeads", params: [heads] });
|
|
105
|
-
log.debug(`Delivered ${heads.length} unfinalized
|
|
105
|
+
log.debug(`Delivered ${heads.length} unfinalized head(s)`);
|
|
106
106
|
pending = pending.filter((head2) => {
|
|
107
107
|
return !heads.some((_head) => {
|
|
108
108
|
return isHexEqual(head2.hash, _head.hash);
|
package/dist/rpc.d.mts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import { Head, Metadata, Filter, Block, Result } from './
|
|
1
|
+
import { H as Head, M as Metadata, F as Flatten, a as Filter, B as Block, R as Result } from './shared/univo.Cj4s4jNq.mjs';
|
|
2
2
|
import 'unstorage';
|
|
3
3
|
|
|
4
|
-
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;
|
|
5
|
-
type Flatten<T> = {
|
|
6
|
-
[K in keyof T as CamelToSnake<Extract<K, string>>]: T[K];
|
|
7
|
-
};
|
|
8
|
-
|
|
9
4
|
type Rpc = {
|
|
10
5
|
/**
|
|
11
6
|
* All available methods that can be requested
|
|
@@ -92,12 +87,12 @@ type IndexerRpc = {
|
|
|
92
87
|
failures: Result[];
|
|
93
88
|
}>;
|
|
94
89
|
/**
|
|
95
|
-
* Accepts a
|
|
96
|
-
* @returns A list of
|
|
90
|
+
* Accepts a block head and writes events to storage
|
|
91
|
+
* @returns A list of results and block keys that were accessed as those events were written to storage
|
|
97
92
|
*/
|
|
98
93
|
private_writeEventsAndGetKeys: (params: {
|
|
99
94
|
events: string[];
|
|
100
|
-
|
|
95
|
+
head: Head;
|
|
101
96
|
}) => Promise<{
|
|
102
97
|
results: Result[];
|
|
103
98
|
keys: string[];
|
package/dist/rpc.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import { Head, Metadata, Filter, Block, Result } from './
|
|
1
|
+
import { H as Head, M as Metadata, F as Flatten, a as Filter, B as Block, R as Result } from './shared/univo.Cj4s4jNq.js';
|
|
2
2
|
import 'unstorage';
|
|
3
3
|
|
|
4
|
-
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;
|
|
5
|
-
type Flatten<T> = {
|
|
6
|
-
[K in keyof T as CamelToSnake<Extract<K, string>>]: T[K];
|
|
7
|
-
};
|
|
8
|
-
|
|
9
4
|
type Rpc = {
|
|
10
5
|
/**
|
|
11
6
|
* All available methods that can be requested
|
|
@@ -92,12 +87,12 @@ type IndexerRpc = {
|
|
|
92
87
|
failures: Result[];
|
|
93
88
|
}>;
|
|
94
89
|
/**
|
|
95
|
-
* Accepts a
|
|
96
|
-
* @returns A list of
|
|
90
|
+
* Accepts a block head and writes events to storage
|
|
91
|
+
* @returns A list of results and block keys that were accessed as those events were written to storage
|
|
97
92
|
*/
|
|
98
93
|
private_writeEventsAndGetKeys: (params: {
|
|
99
94
|
events: string[];
|
|
100
|
-
|
|
95
|
+
head: Head;
|
|
101
96
|
}) => Promise<{
|
|
102
97
|
results: Result[];
|
|
103
98
|
keys: string[];
|