Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: add ts path alias and rollup typescript plugin #126

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/cli/apibara.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import typescript from "@rollup/plugin-typescript";
import { defineConfig } from "apibara/config";

export default defineConfig({
Expand All @@ -11,7 +12,7 @@ export default defineConfig({
},
},
},
// rollupConfig: {
// plugins: [tsConfigPaths()],
// },
rollupConfig: {
plugins: [typescript()],
},
});
6 changes: 4 additions & 2 deletions examples/cli/indexers/1-evm.indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import { defineIndexer, useSink } from "@apibara/indexer";
import { drizzlePersistence } from "@apibara/indexer/plugins/drizzle-persistence";
import { useLogger } from "@apibara/indexer/plugins/logger";
import { drizzle as drizzleSink } from "@apibara/indexer/sinks/drizzle";

import type { ApibaraRuntimeConfig } from "apibara/types";
import type {
ExtractTablesWithRelations,
TablesRelationalConfig,
} from "drizzle-orm";
import type { PgDatabase, PgQueryResultHKT } from "drizzle-orm/pg-core";
import { encodeEventTopics, parseAbi } from "viem";
import { db } from "../lib/db";
import { ethereumUsdcTransfers } from "../lib/schema";

import { db } from "@/lib/db";
import { ethereumUsdcTransfers } from "@/lib/schema";

const abi = parseAbi([
"event Transfer(address indexed from, address indexed to, uint256 value)",
Expand Down
6 changes: 4 additions & 2 deletions examples/cli/indexers/2-starknet.indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import { drizzlePersistence } from "@apibara/indexer/plugins/drizzle-persistence
import { useLogger } from "@apibara/indexer/plugins/logger";
import { drizzle as drizzleSink } from "@apibara/indexer/sinks/drizzle";
import { StarknetStream } from "@apibara/starknet";

import type { ApibaraRuntimeConfig } from "apibara/types";
import type {
ExtractTablesWithRelations,
TablesRelationalConfig,
} from "drizzle-orm";
import type { PgDatabase, PgQueryResultHKT } from "drizzle-orm/pg-core";
import { hash } from "starknet";
import { db } from "../lib/db";
import { starknetUsdcTransfers } from "../lib/schema";

import { db } from "@/lib/db";
import { starknetUsdcTransfers } from "@/lib/schema";

// USDC Transfers on Starknet
export default function (runtimeConfig: ApibaraRuntimeConfig) {
Expand Down
1 change: 1 addition & 0 deletions examples/cli/indexers/3-starknet-factory.indexer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineIndexer } from "@apibara/indexer";
import { useLogger } from "@apibara/indexer/plugins/logger";
import { StarknetStream } from "@apibara/starknet";

import type { ApibaraRuntimeConfig } from "apibara/types";
import { hash } from "starknet";

Expand Down
1 change: 1 addition & 0 deletions examples/cli/lib/db.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type NodePgDatabase, drizzle } from "drizzle-orm/node-postgres";
import pg from "pg";

import * as schema from "./schema";

const connectionString = "postgres://postgres:postgres@localhost:5432/postgres";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using environment variables for database configuration

The connection string is hardcoded which could pose security risks and make deployment across different environments difficult.

Consider using environment variables:

-const connectionString = "postgres://postgres:postgres@localhost:5432/postgres";
+const connectionString = process.env.DATABASE_URL || "postgres://postgres:postgres@localhost:5432/postgres";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const connectionString = "postgres://postgres:postgres@localhost:5432/postgres";
const connectionString = process.env.DATABASE_URL || "postgres://postgres:postgres@localhost:5432/postgres";

Expand Down
1 change: 1 addition & 0 deletions examples/cli/lib/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { pgIndexerTable } from "@apibara/indexer/sinks/drizzle";

import { bigint, text } from "drizzle-orm/pg-core";

export const starknetUsdcTransfers = pgIndexerTable("starknet_usdc_transfers", {
Expand Down
3 changes: 2 additions & 1 deletion examples/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@rollup/plugin-typescript": "^11.1.6",
"@types/node": "^20.5.2",
"@types/pg": "^8.11.10",
"drizzle-kit": "^0.29.0",
"rollup-plugin-tsconfig-paths": "^1.5.2",
"typescript": "^5.6.2",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^1.6.0"
},
"dependencies": {
Expand Down
9 changes: 6 additions & 3 deletions examples/cli/test/ethereum.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { createVcr } from "@apibara/indexer/testing";

import { drizzle } from "drizzle-orm/pglite";
import { beforeAll, describe, expect, it } from "vitest";
import { createIndexer } from "../indexers/1-evm.indexer";
import { ethereumUsdcTransfers } from "../lib/schema";
import * as schema from "../lib/schema";

import { createIndexer } from "@/indexers/1-evm.indexer";
import { ethereumUsdcTransfers } from "@/lib/schema";
import * as schema from "@/lib/schema";

import { migratePglite } from "./helper";

const vcr = createVcr();
Expand Down
3 changes: 2 additions & 1 deletion examples/cli/test/helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { PgliteDatabase } from "drizzle-orm/pglite";
import { migrate } from "drizzle-orm/pglite/migrator";
import type * as schema from "../lib/schema";

import type * as schema from "@/lib/schema";

export async function migratePglite(database: PgliteDatabase<typeof schema>) {
return await migrate(database, { migrationsFolder: "./drizzle" });
Expand Down
9 changes: 6 additions & 3 deletions examples/cli/test/starknet.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { createVcr } from "@apibara/indexer/testing";

import { drizzle } from "drizzle-orm/pglite";
import { beforeAll, describe, expect, it } from "vitest";
import { createIndexer } from "../indexers/2-starknet.indexer";
import { starknetUsdcTransfers } from "../lib/schema";
import * as schema from "../lib/schema";

import { createIndexer } from "@/indexers/2-starknet.indexer";
import { starknetUsdcTransfers } from "@/lib/schema";
import * as schema from "@/lib/schema";

import { migratePglite } from "./helper";

const vcr = createVcr();
Expand Down
6 changes: 5 additions & 1 deletion examples/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
"skipLibCheck": true,
"types": ["node"],
"noEmit": true,
"strict": true
"strict": true,
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
}
},
"include": [".", "./.apibara/types"],
"exclude": ["node_modules"]
Expand Down
2 changes: 2 additions & 0 deletions examples/cli/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import tsconfigPaths from "vite-tsconfig-paths";
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
testTimeout: 10000,
},
plugins: [tsconfigPaths()],
});
68 changes: 44 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading