Skip to content

Commit

Permalink
cli: isolate modules
Browse files Browse the repository at this point in the history
  • Loading branch information
fracek committed Jul 29, 2024
1 parent 3d2625c commit f374a44
Show file tree
Hide file tree
Showing 34 changed files with 234 additions and 246 deletions.
2 changes: 1 addition & 1 deletion examples/cli/apibara.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig } from "@apibara/cli";
import { defineConfig } from "apibara/config";
import { defaultSink } from "@apibara/indexer";

export default defineConfig({
Expand Down
30 changes: 30 additions & 0 deletions examples/cli/indexers/simple.indexer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { EvmStream } from "@apibara/evm";
import { defineIndexer } from "@apibara/indexer";
import { encodeEventTopics, parseAbi } from "viem";

const abi = parseAbi([
"event Transfer(address indexed from, address indexed to, uint256 value)",
]);

export default defineIndexer(EvmStream)({
streamUrl: "https://sepolia.ethereum.a5a.ch",
finality: "accepted",
startingCursor: {
orderKey: 5_000_000n,
},
filter: {
logs: [
{
strict: true,
topics: encodeEventTopics({
abi,
eventName: "Transfer",
args: { from: null, to: null },
}) as `0x${string}`[],
},
],
},
async transform({ block: { header } }) {
return [header];
},
})
34 changes: 34 additions & 0 deletions examples/cli/indexers/with-config.indexer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { EvmStream } from "@apibara/evm";
import { defineIndexer } from "@apibara/indexer";
import { encodeEventTopics, parseAbi } from "viem";

const abi = parseAbi([
"event Transfer(address indexed from, address indexed to, uint256 value)",
]);

// TODO: `runtimeConfig` type should come from the generated types file
export default function indexer(runtimeConfig: unknown) {
console.log("runtimeConfig", runtimeConfig);
return defineIndexer(EvmStream)({
streamUrl: "https://sepolia.ethereum.a5a.ch",
finality: "accepted",
startingCursor: {
orderKey: 5_000_000n,
},
filter: {
logs: [
{
strict: true,
topics: encodeEventTopics({
abi,
eventName: "Transfer",
args: { from: null, to: null },
}) as `0x${string}`[],
},
],
},
async transform({ block: { header } }) {
return [header];
},
})
}
8 changes: 3 additions & 5 deletions examples/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"version": "1.0.0",
"private": true,
"scripts": {
"cli:build": "jiti ./src/main.ts build --dir ./src",
"cli:prepare": "jiti ./src/main.ts prepare --dir ./src",
"cli:start": "jiti ./dist/main.mjs",
"build": "apibara build",
"typecheck": "tsc --noEmit",
"lint": "biome check .",
"lint:fix": "pnpm lint --write",
Expand All @@ -15,13 +13,13 @@
"@apibara/evm": "workspace:*",
"@apibara/indexer": "workspace:*",
"@apibara/protocol": "workspace:*",
"@apibara/cli": "workspace:*",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/exporter-trace-otlp-proto": "^0.52.0",
"@opentelemetry/resources": "^1.25.0",
"@opentelemetry/sdk-node": "^0.52.0",
"@opentelemetry/sdk-trace-base": "^1.25.0",
"@opentelemetry/semantic-conventions": "^1.25.0",
"apibara": "workspace:*",
"better-sqlite3": "^11.1.2",
"citty": "^0.1.6",
"consola": "^3.2.3",
Expand All @@ -33,4 +31,4 @@
"@types/node": "^20.12.12",
"jiti": "^1.21.0"
}
}
}
93 changes: 0 additions & 93 deletions examples/cli/src/indexer.ts

This file was deleted.

9 changes: 0 additions & 9 deletions examples/cli/src/indexers/demo.indexer.ts

This file was deleted.

6 changes: 0 additions & 6 deletions examples/cli/src/indexers/test.indexer.ts

This file was deleted.

43 changes: 0 additions & 43 deletions examples/cli/src/instrumentation.ts

This file was deleted.

4 changes: 0 additions & 4 deletions examples/cli/src/main.ts

This file was deleted.

12 changes: 8 additions & 4 deletions examples/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
"outDir": "dist",
"declarationDir": "dist",
"noEmit": false,
"rootDir": "src",
"types": ["node"]
"rootDir": ".",
"types": [
"node"
]
},
"include": ["src/"]
}
"include": [
"indexers/"
]
}
37 changes: 37 additions & 0 deletions packages/cli/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { defineBuildConfig } from "unbuild";
import { fileURLToPath } from "node:url";
import { resolve } from "pathe";

const modules = [
"cli",
"config",
"core",
"rollup",
"types",
];

const srcDir = fileURLToPath(new URL("src", import.meta.url));

export default defineBuildConfig({
entries: [
{ input: "./src/cli/index.ts" },
{ input: "./src/config/index.ts" },
{ input: "./src/core/index.ts" },
{ input: "./src/rollup/index.ts" },
],
clean: true,
outDir: "./dist",
declaration: true,
alias: {
...Object.fromEntries(
modules.map((module) => [
`apibara/${module}`,
resolve(srcDir, `${module}/index.ts`),
])
),
},
externals: [
...modules.map((module) => `apibara/${module}`),
],
});

47 changes: 31 additions & 16 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
{
"name": "@apibara/cli",
"name": "apibara",
"version": "2.0.0",
"type": "module",
"source": "./src/index.ts",
"main": "./src/index.ts",
"source": "./src/core/index.ts",
"main": "./dist/core/index.mjs",
"exports": {
".": "./src/index.ts"
},
"publishConfig": {
"files": ["dist", "src", "README.md"],
"main": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"default": "./dist/index.mjs"
}
".": {
"types": "./dist/core/index.d.ts",
"import": "./dist/core/index.mjs"
},
"./cli": {
"types": "./dist/cli/index.d.ts",
"import": "./dist/cli/index.mjs"
},
"./config": {
"types": "./dist/config/index.d.ts",
"import": "./dist/config/index.mjs"
},
"./core": {
"types": "./dist/core/index.d.ts",
"import": "./dist/core/index.mjs"
},
"./rollup": {
"types": "./dist/rollup/index.d.ts",
"import": "./dist/rollup/index.mjs"
}
},
"bin": {
"apibara": "./dist/cli/index.mjs"
},
"files": [
"dist",
"src",
"README.md"
],
"scripts": {
"build": "unbuild",
"lint": "biome check .",
Expand Down Expand Up @@ -52,4 +67,4 @@
"tslib": "^2.6.3",
"untyped": "^1.4.2"
}
}
}
Loading

0 comments on commit f374a44

Please sign in to comment.