Skip to content

Commit

Permalink
allow js processor to be async
Browse files Browse the repository at this point in the history
  • Loading branch information
wighawag committed Apr 13, 2024
1 parent 7e6291c commit 98d3831
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 14 deletions.
7 changes: 7 additions & 0 deletions examples/basic/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# basic

## 0.0.4

### Patch Changes

- Updated dependencies
- [email protected]

## 0.0.3

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "basic",
"private": true,
"version": "0.0.3",
"version": "0.0.4",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -10,7 +10,7 @@
},
"dependencies": {
"ethereum-indexer-browser": "workspace:^0.7.0",
"ethereum-indexer-js-processor": "workspace:^0.6.16",
"ethereum-indexer-js-processor": "workspace:^0.7.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
7 changes: 7 additions & 0 deletions examples/event-processor-bleeps/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# event-processor-bleeps

## 0.0.57

### Patch Changes

- Updated dependencies
- [email protected]

## 0.0.56

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/event-processor-bleeps/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "event-processor-bleeps",
"private": true,
"version": "0.0.56",
"version": "0.0.57",
"description": "",
"type": "module",
"main": "dist/index.cjs",
Expand Down
7 changes: 7 additions & 0 deletions examples/event-processor-conquest-eth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# event-processor-conquest-eth

## 0.0.57

### Patch Changes

- Updated dependencies
- [email protected]

## 0.0.56

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/event-processor-conquest-eth/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "event-processor-conquest-eth",
"private": true,
"version": "0.0.56",
"version": "0.0.57",
"description": "",
"type": "module",
"main": "dist/index.cjs",
Expand Down
7 changes: 7 additions & 0 deletions examples/event-processor-conquest-fplay/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# event-processor-conquest-fplay

## 0.0.57

### Patch Changes

- Updated dependencies
- [email protected]

## 0.0.56

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/event-processor-conquest-fplay/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "event-processor-conquest-fplay",
"private": true,
"version": "0.0.56",
"version": "0.0.57",
"description": "",
"type": "module",
"main": "dist/index.cjs",
Expand Down
7 changes: 7 additions & 0 deletions examples/event-processor-nfts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# event-processor-nfts

## 0.0.57

### Patch Changes

- Updated dependencies
- [email protected]

## 0.0.56

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/event-processor-nfts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "event-processor-nfts",
"private": true,
"version": "0.0.56",
"version": "0.0.57",
"description": "",
"type": "module",
"main": "dist/index.cjs",
Expand Down
10 changes: 10 additions & 0 deletions examples/mud/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# web-demo

## 0.1.69

### Patch Changes

- Updated dependencies
- [email protected]
- [email protected]
- [email protected]
- [email protected]

## 0.1.68

### 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.68",
"version": "0.1.69",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
8 changes: 8 additions & 0 deletions examples/web-demo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# web-demo

## 0.1.69

### Patch Changes

- [email protected]
- [email protected]
- [email protected]

## 0.1.68

### 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.68",
"version": "0.1.69",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
6 changes: 6 additions & 0 deletions packages/ethereum-indexer-js-processor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ethereum-indexer-js-processor

## 0.7.0

### Minor Changes

- allow js processor to be async

## 0.6.30

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ethereum-indexer-js-processor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ethereum-indexer-js-processor",
"version": "0.6.30",
"version": "0.7.0",
"description": "",
"keywords": [],
"author": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type SingleEventJSONProcessor<
version?: string;
createInitialState(): ProcessResultType;
configure(config: ProcessorConfig): void;
processEvent(json: ProcessResultType, event: LogEvent<ABI>): void;
processEvent(json: ProcessResultType, event: LogEvent<ABI>): void | Promise<void>;
};

export class JSObjectEventProcessor<ABI extends Abi, ProcessResultType extends JSObject, ProcessorConfig = undefined>
Expand Down Expand Up @@ -181,7 +181,7 @@ export class JSObjectEventProcessor<ABI extends Abi, ProcessResultType extends J
}
} else {
if (willNotChange) {
this.singleEventProcessor.processEvent(this._json.state, event);
await this.singleEventProcessor.processEvent(this._json.state, event);
} else {
if (!lastBlockHash || event.blockHash != lastBlockHash) {
if (draft as any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type EventFunctions<ABI extends Abi, ProcessResultType extends JSObject,
json: ProcessResultType,
event: LogEvent<ABI> & {args: InputValues<ExtractAbiEvent<ABI, Property>>},
config: ProcessorConfig
) => void;
) => Promise<void> | void;
};

export type MergedEventFunctions<
Expand Down
4 changes: 2 additions & 2 deletions packages/ethereum-indexer-js-processor/src/processor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type JSProcessor<
> = EventFunctions<ABI, ProcessResultType, ProcessorConfig> & {
version?: string;
construct(): ProcessResultType;
handleUnparsedEvent?(json: ProcessResultType, event: LogEventWithParsingFailure): Promise<void>;
handleUnparsedEvent?(json: ProcessResultType, event: LogEventWithParsingFailure): void | Promise<void>;
};

class SingleJSONEventProcessorWrapper<ABI extends Abi, ProcessResultType extends JSObject, ProcessorConfig> {
Expand All @@ -31,7 +31,7 @@ class SingleJSONEventProcessorWrapper<ABI extends Abi, ProcessResultType extends
this.config = config;
}

processEvent(json: ProcessResultType, event: LogEvent<ABI>) {
processEvent(json: ProcessResultType, event: LogEvent<ABI>): Promise<void> | void {
if ('decodeError' in event) {
if (this.obj.handleUnparsedEvent) {
return this.obj.handleUnparsedEvent(json, event);
Expand Down

0 comments on commit 98d3831

Please sign in to comment.