Skip to content

Commit a9b5359

Browse files
v2
1 parent 81e6c0c commit a9b5359

File tree

11 files changed

+152
-285
lines changed

11 files changed

+152
-285
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ jobs:
1515
with:
1616
node-version: 22
1717
- run: npm install && npm run test
18+
env:
19+
IS_KEY: ${{ secrets.IS_KEY }}

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ Make a one-time query to get historical data:
1717
```typescript
1818
import { query } from "@indexsupply/indexsupply.js";
1919

20-
const { blockNumber, result } = await query({
20+
const { cursor, rows } = await query({
2121
apiKey: "face",
2222
chainId: 8453,
2323
query: 'select "from", "to", value from transfer limit 1',
24-
eventSignatures: ['Transfer(address indexed from, address indexed to, uint256 value)'],
24+
signatures: ['Transfer(address indexed from, address indexed to, uint256 value)'],
2525
formatRow: ([from, to, value]) => ({
2626
from: from as Address,
2727
to: to as Address,
2828
value: BigInt(value),
2929
}),
3030
})
3131

32-
console.log(`Block ${blockNumber}:`, result)
32+
console.log(`Block ${cursor}:`, rows)
3333
```
3434

3535
### Live Query
@@ -44,16 +44,16 @@ const q = queryLive({
4444
chainId: 8453,
4545
startBlock: async () => 1234567n,
4646
query: 'select "from", "to", value from transfer limit 1',
47-
eventSignatures: ['Transfer(address indexed from, address indexed to, uint256 value)'],
47+
signatures: ['Transfer(address indexed from, address indexed to, uint256 value)'],
4848
formatRow: ([from, to, value]) => ({
4949
from: from as Address,
5050
to: to as Address,
5151
value: BigInt(value),
5252
}),
5353
})
5454

55-
for await (const { blockNumber, result } of q) {
56-
console.log(`New data at block ${blockNumber}:`, result)
55+
for await (const { cursor, rows } of q) {
56+
console.log(`New data at block ${cursor}:`, rows)
5757
}
5858
```
5959

@@ -71,7 +71,7 @@ const liveQuery = queryLive({
7171
},
7272
...
7373
});
74-
for await (const { blockNumber, result } of liveQuery) {
74+
for await (const { cursor, rows } of liveQuery) {
7575
await pg.query("insert into my_table(block_num, ...) values (blockNumber, ...)");
7676
}
7777
```
@@ -90,12 +90,12 @@ See [this page](https://indexsupply.github.io/indexsupply.js/examples/index.html
9090
</head>
9191
<script type="module">
9292
import { query } from "https://static.indexsupply.net/indexsupply.js";
93-
const { blockNumber, result } = await query({
93+
const { cursor, rows } = await query({
9494
chainId: 8453n,
95-
eventSignatures: [],
95+
signatures: [],
9696
query: "select block_num from logs limit 1",
9797
});
98-
document.querySelector("body pre").textContent = JSON.stringify({ blockNumber, result });
98+
document.querySelector("body pre").textContent = JSON.stringify({ cursor, rows});
9999
</script>
100100
<body>
101101
<pre></pre>

examples/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { queryLive } from "https://static.indexsupply.net/indexsupply.js";
77
const query = await queryLive({
88
chainId: 8453n,
9-
eventSignatures: ["Transfer(address indexed from, address indexed to, uint value)"],
9+
signatures: ["Transfer(address indexed from, address indexed to, uint value)"],
1010
query: `select tx_hash, value from transfer limit 1`,
1111
});
1212
for await (const res of query) {

examples/live.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const query = queryLive({
2020
abortSignal: controller.signal,
2121
startBlock: async () => (latest + 1n),
2222
chainId: 8453n,
23-
eventSignatures: [
23+
signatures: [
2424
"Transfer(address indexed from, address indexed to, uint256 v)",
2525
],
2626
query: "select tx_hash, block_num from transfer limit 1",
@@ -32,8 +32,8 @@ const query = queryLive({
3232
},
3333
});
3434

35-
for await (const { result } of query) {
36-
result.forEach((row) => {
35+
for await (const { rows } of query) {
36+
rows.forEach((row) => {
3737
if (row.block > latest) {
3838
latest = row.block;
3939
}

examples/ox-seaport/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ setLogLevel(LogLevel.DEBUG);
66
const orderFulfilled = AbiEvent.from("event OrderFulfilled(bytes32 orderHash, address indexed offerer, address indexed zone, address recipient, (uint8, address, uint256, uint256)[] offer, (uint8, address, uint256, uint256, address)[] consideration)");
77

88
async function main() {
9-
const { blockNumber, result } = await query({
9+
const { cursor, rows } = await query({
1010
chainId: 1n,
1111
query: `
1212
select topics, data
@@ -24,7 +24,7 @@ async function main() {
2424
},
2525
});
2626

27-
result.forEach((order) => {
27+
rows.forEach((order) => {
2828
console.log({ offer: order.offer, consideration: order.consideration });
2929
})
3030
}

examples/save-to-postgres/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async function main() {
6363
return BigInt(res.rows[0].latest);
6464
},
6565
chainId: 8453n,
66-
eventSignatures: [
66+
signatures: [
6767
"Transfer(address indexed from, address indexed to, uint256 value)",
6868
],
6969
query: `select tx_hash, block_num, "from", "to", value from transfer order by block_num desc limit 1`,
@@ -77,8 +77,8 @@ async function main() {
7777
};
7878
},
7979
});
80-
for await (const { result } of query) {
81-
await Promise.all(result.map(async (row) => {
80+
for await (const { rows } of query) {
81+
await Promise.all(rows.map(async (row) => {
8282
await pg.client!.query(`
8383
insert into my_transfers(block_num, "from", "to", value)
8484
values ($1, $2, $3, $4)

examples/single.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { query } from "../src/index.ts";
1+
import { query, setLogLevel, LogLevel } from "../src/index.ts";
2+
setLogLevel(LogLevel.DEBUG);
23

3-
type Address = `0x${string}`;
4-
5-
const { blockNumber, result } = await query({
4+
let { cursor, rows } = await query({
65
chainId: 8453n,
7-
eventSignatures: [
6+
signatures: [
87
"Transfer(address indexed from, address indexed to, uint256 value)",
98
],
109
query:
1110
'select block_num, log_idx, "from", "to", "value" from transfer limit 5',
1211
});
1312

14-
console.log(`current block: ${blockNumber}`);
15-
result.forEach((r) => console.log(r.block_num));
13+
console.log({ cursor: cursor });
14+
rows.forEach((r) => console.log(r.block_num));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.0.15",
2+
"version": "2.0.0",
33
"name": "@indexsupply/indexsupply.js",
44
"keywords": [
55
"ethereum",

scripts/upload-browser-index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
22
import { readFile } from "node:fs/promises";
3+
import { execSync } from "node:child_process";
34

5+
const gitSha = execSync("git rev-parse --short HEAD").toString().trim();
46
const s3Client = new S3Client({ region: "us-west-2" });
57
await s3Client.send(
68
new PutObjectCommand({
79
Bucket: "static.indexsupply.net",
8-
Key: "indexsupply.js",
10+
Key: `indexsupply.js-${gitSha}`,
911
Body: await readFile("dist/index.js"),
1012
ContentType: "text/javascript",
1113
}),

0 commit comments

Comments
 (0)