Skip to content

Commit

Permalink
option to log all requests
Browse files Browse the repository at this point in the history
  • Loading branch information
wighawag committed Nov 25, 2023
1 parent 51e38ee commit a78393b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 5 deletions.
7 changes: 7 additions & 0 deletions examples/mud/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# web-demo

## 0.1.44

### Patch Changes

- Updated dependencies
- ethereum-indexer-browser@0.6.16

## 0.1.43

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/mud/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mud-demo",
"private": true,
"version": "0.1.43",
"version": "0.1.44",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
7 changes: 7 additions & 0 deletions examples/web-demo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# web-demo

## 0.1.44

### Patch Changes

- Updated dependencies
- ethereum-indexer-browser@0.6.16

## 0.1.43

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/web-demo/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "web-demo",
"private": true,
"version": "0.1.43",
"version": "0.1.44",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
6 changes: 6 additions & 0 deletions packages/ethereum-indexer-browser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ethereum-indexer-browser

## 0.6.16

### Patch Changes

- option to log all requests

## 0.6.15

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ethereum-indexer-browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ethereum-indexer-browser",
"version": "0.6.15",
"version": "0.6.16",
"publishConfig": {
"access": "public"
},
Expand Down
10 changes: 8 additions & 2 deletions packages/ethereum-indexer-browser/src/IndexerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function createIndexerState<ABI extends Abi, ProcessResultType, Processor
processor: EventProcessorWithInitialState<ABI, ProcessResultType, ProcessorConfig>,
options?: {
trackNumRequests?: boolean;
logRequests?: boolean;
keepState?: KeepState<ABI, ProcessResultType, unknown, ProcessorConfig>;
keepStream?: ExistingStream<ABI>;
}
Expand Down Expand Up @@ -104,12 +105,17 @@ export function createIndexerState<ABI extends Abi, ProcessResultType, Processor
const config = {...{}, keepStream: options?.keepStream, ...(indexerSetup.config || {})};
const source = indexerSetup.source;

const provider = options?.trackNumRequests
const provider = options?.trackNumRequests || options?.logRequests
? new Proxy(indexerSetup.provider, {
get(target, p, receiver) {
if (p === 'request') {
return (args: {method: string; params?: readonly unknown[]}) => {
setSyncing({numRequests: ($syncing.numRequests || 0) + 1});
if (options.trackNumRequests) {
setSyncing({numRequests: ($syncing.numRequests || 0) + 1});
}
if (options.logRequests) {
console.log(JSON.stringify(args));
}
return target[p](args as any);
};
}
Expand Down

0 comments on commit a78393b

Please sign in to comment.