Skip to content

Commit

Permalink
Merge pull request #416 from 0xOlias/kjs/esm
Browse files Browse the repository at this point in the history
Move to ESM
  • Loading branch information
kyscott18 authored Nov 10, 2023
2 parents cf6340f + 2bce055 commit 49fa33c
Show file tree
Hide file tree
Showing 108 changed files with 646 additions and 679 deletions.
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
"simple-import-sort/exports": "error",
"import/first": "error",
"import/newline-after-import": "error",
"@typescript-eslint/consistent-type-imports": [
"error",
{
"prefer": "type-imports",
"disallowTypeAnnotations": false
}
],
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
Expand Down
5 changes: 3 additions & 2 deletions docs/pages/api/telemetry/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Analytics, TrackParams } from "@segment/analytics-node";
import { NextApiRequest, NextApiResponse } from "next";
import type { TrackParams } from "@segment/analytics-node";
import { Analytics } from "@segment/analytics-node";
import type { NextApiRequest, NextApiResponse } from "next";

if (!process.env.SEGMENT_WRITE_KEY) {
throw new Error('Missing required environment variable "SEGMENT_WRITE_KEY".');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"lint-staged": "^13.2.3",
"prettier": "^2.8.8",
"simple-git-hooks": "^2.9.0",
"typescript": "^5.1.3"
"typescript": "^5.2.2"
},
"lint-staged": {
"*.ts": [
Expand Down
15 changes: 8 additions & 7 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.95",
"description": "An open-source framework for crypto application backends",
"license": "MIT",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/0xOlias/ponder",
Expand All @@ -17,11 +18,11 @@
"bin": {
"ponder": "./dist/bin/ponder.js"
},
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"typings": "./dist/index.d.ts",
"exports": {
"default": "./dist/index.js",
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"scripts": {
Expand All @@ -38,7 +39,7 @@
"async-mutex": "^0.4.0",
"better-sqlite3": "^8.7.0",
"cac": "^6.7.14",
"conf": "^10.2.0",
"conf": "^12.0.0",
"cors": "^2.8.5",
"data-uri-to-buffer": "3.0.1",
"detect-package-manager": "^2.0.1",
Expand All @@ -53,8 +54,8 @@
"ink": "^3.2.0",
"kysely": "^0.24.2",
"p-limit": "3",
"p-queue": "^6.6.2",
"pg": "^8.9.0",
"p-queue": "^7.4.1",
"pg": "^8.11.3",
"picocolors": "^1.0.0",
"pino": "^8.14.1",
"prom-client": "^14.2.0",
Expand All @@ -71,7 +72,7 @@
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/glob": "^8.0.0",
"@types/node": "^18.7.8",
"@types/node": "^20.9.0",
"@types/pg": "^8.6.6",
"@types/react": "^18.0.25",
"@types/retry": "^0.12.2",
Expand All @@ -81,7 +82,7 @@
"rimraf": "^5.0.1",
"supertest": "^6.3.3",
"tsc-alias": "^1.8.2",
"typescript": "^5.1.3",
"typescript": "^5.2.2",
"vitest": "^0.34.6"
}
}
49 changes: 25 additions & 24 deletions packages/core/src/Ponder.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import path from "node:path";
import process from "node:process";

import { BuildService } from "@/build/service";
import { CodegenService } from "@/codegen/service";
import { buildDatabase } from "@/config/database";
import { type Network, buildNetwork } from "@/config/networks";
import { type Options } from "@/config/options";
import { UserErrorService } from "@/errors/service";
import { IndexingService } from "@/indexing/service";
import { PostgresIndexingStore } from "@/indexing-store/postgres/store";
import { SqliteIndexingStore } from "@/indexing-store/sqlite/store";
import { type IndexingStore } from "@/indexing-store/store";
import { LoggerService } from "@/logs/service";
import { MetricsService } from "@/metrics/service";
import { ServerService } from "@/server/service";
import { SyncGateway } from "@/sync-gateway/service";
import { HistoricalSyncService } from "@/sync-historical/service";
import { RealtimeSyncService } from "@/sync-realtime/service";
import { PostgresSyncStore } from "@/sync-store/postgres/store";
import { SqliteSyncStore } from "@/sync-store/sqlite/store";
import { type SyncStore } from "@/sync-store/store";
import { TelemetryService } from "@/telemetry/service";
import { UiService } from "@/ui/service";

import { hydrateIndexingFunctions } from "./build/functions";
import { buildSources, Source } from "./config/sources";
import { BuildService } from "@/build/service.js";
import { CodegenService } from "@/codegen/service.js";
import { buildDatabase } from "@/config/database.js";
import { type Network, buildNetwork } from "@/config/networks.js";
import { type Options } from "@/config/options.js";
import { UserErrorService } from "@/errors/service.js";
import { IndexingService } from "@/indexing/service.js";
import { PostgresIndexingStore } from "@/indexing-store/postgres/store.js";
import { SqliteIndexingStore } from "@/indexing-store/sqlite/store.js";
import { type IndexingStore } from "@/indexing-store/store.js";
import { LoggerService } from "@/logs/service.js";
import { MetricsService } from "@/metrics/service.js";
import { ServerService } from "@/server/service.js";
import { SyncGateway } from "@/sync-gateway/service.js";
import { HistoricalSyncService } from "@/sync-historical/service.js";
import { RealtimeSyncService } from "@/sync-realtime/service.js";
import { PostgresSyncStore } from "@/sync-store/postgres/store.js";
import { SqliteSyncStore } from "@/sync-store/sqlite/store.js";
import { type SyncStore } from "@/sync-store/store.js";
import { TelemetryService } from "@/telemetry/service.js";
import { UiService } from "@/ui/service.js";

import { hydrateIndexingFunctions } from "./build/functions.js";
import type { Source } from "./config/sources.js";
import { buildSources } from "./config/sources.js";

export type Common = {
options: Options;
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/_test/art-gobblers/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { rmSync } from "node:fs";
import request from "supertest";
import { type TestContext, afterEach, beforeEach, expect, test } from "vitest";

import { setupIndexingStore, setupSyncStore } from "@/_test/setup";
import { buildOptions } from "@/config/options";
import { Ponder } from "@/Ponder";
import { setupIndexingStore, setupSyncStore } from "@/_test/setup.js";
import { buildOptions } from "@/config/options.js";
import { Ponder } from "@/Ponder.js";

beforeEach((context) => setupSyncStore(context));
beforeEach((context) => setupIndexingStore(context));
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/_test/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
parseAbiItem,
} from "viem";

import { getEvents } from "@/config/abi";
import { buildFactoryCriteria } from "@/config/factories";
import { getEvents } from "@/config/abi.js";
import { buildFactoryCriteria } from "@/config/factories.js";

export const FORK_BLOCK_NUMBER = 16380000n;

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/_test/ens/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { rmSync } from "node:fs";
import request from "supertest";
import { type TestContext, afterEach, beforeEach, expect, test } from "vitest";

import { setupIndexingStore, setupSyncStore } from "@/_test/setup";
import { buildOptions } from "@/config/options";
import { Ponder } from "@/Ponder";
import { setupIndexingStore, setupSyncStore } from "@/_test/setup.js";
import { buildOptions } from "@/config/options.js";
import { Ponder } from "@/Ponder.js";

beforeEach((context) => setupSyncStore(context));
beforeEach((context) => setupIndexingStore(context));
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/_test/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { startProxy } from "@viem/anvil";
import dotenv from "dotenv";
import { Pool } from "pg";

import { FORK_BLOCK_NUMBER } from "./constants";
import { FORK_BLOCK_NUMBER } from "./constants.js";

export default async function () {
dotenv.config({ path: ".env.local" });
Expand Down
30 changes: 15 additions & 15 deletions packages/core/src/_test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import SqliteDatabase from "better-sqlite3";
import { Pool } from "pg";
import { type TestContext, beforeEach } from "vitest";

import { patchSqliteDatabase } from "@/config/database";
import { buildOptions } from "@/config/options";
import { UserErrorService } from "@/errors/service";
import { PostgresIndexingStore } from "@/indexing-store/postgres/store";
import { SqliteIndexingStore } from "@/indexing-store/sqlite/store";
import type { IndexingStore } from "@/indexing-store/store";
import { LoggerService } from "@/logs/service";
import { MetricsService } from "@/metrics/service";
import type { Common } from "@/Ponder";
import { PostgresSyncStore } from "@/sync-store/postgres/store";
import { SqliteSyncStore } from "@/sync-store/sqlite/store";
import type { SyncStore } from "@/sync-store/store";
import { TelemetryService } from "@/telemetry/service";
import { patchSqliteDatabase } from "@/config/database.js";
import { buildOptions } from "@/config/options.js";
import { UserErrorService } from "@/errors/service.js";
import { PostgresIndexingStore } from "@/indexing-store/postgres/store.js";
import { SqliteIndexingStore } from "@/indexing-store/sqlite/store.js";
import type { IndexingStore } from "@/indexing-store/store.js";
import { LoggerService } from "@/logs/service.js";
import { MetricsService } from "@/metrics/service.js";
import type { Common } from "@/Ponder.js";
import { PostgresSyncStore } from "@/sync-store/postgres/store.js";
import { SqliteSyncStore } from "@/sync-store/sqlite/store.js";
import type { SyncStore } from "@/sync-store/store.js";
import { TelemetryService } from "@/telemetry/service.js";

import { FORK_BLOCK_NUMBER, vitalik } from "./constants";
import { poolId, testClient } from "./utils";
import { FORK_BLOCK_NUMBER, vitalik } from "./constants.js";
import { poolId, testClient } from "./utils.js";

/**
* Inject an isolated sync store into the test context.
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/bin/ponder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import { cac } from "cac";
import dotenv from "dotenv";

import { buildOptions } from "@/config/options";
import { Ponder } from "@/Ponder";
import { buildOptions } from "@/config/options.js";
import { Ponder } from "@/Ponder.js";

// NOTE: This is a workaround for tsconfig `rootDir` nonsense.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import packageJson from "../../package.json";
import packageJson from "../../package.json" assert { type: "json" };

dotenv.config({ path: ".env.local" });

Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/build/functions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Hex } from "viem";

import type { LogEventMetadata } from "@/config/abi";
import { Source } from "@/config/sources";
import type { Block } from "@/types/block";
import type { Log } from "@/types/log";
import type { Transaction } from "@/types/transaction";
import type { LogEventMetadata } from "@/config/abi.js";
import type { Source } from "@/config/sources.js";
import type { Block } from "@/types/block.js";
import type { Log } from "@/types/log.js";
import type { Transaction } from "@/types/transaction.js";

export interface LogEvent {
name: string;
Expand Down
15 changes: 8 additions & 7 deletions packages/core/src/build/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import type { ViteNodeRunner } from "vite-node/client";
// @ts-ignore
import type { ViteNodeServer } from "vite-node/server";

import type { Config } from "@/config/config";
import type { Common } from "@/Ponder";
import type { Schema } from "@/schema/types";
import { buildGqlSchema } from "@/server/graphql/schema";

import type { RawIndexingFunctions } from "./functions";
import { parseViteNodeError, ViteNodeError } from "./stacktrace";
import type { Config } from "@/config/config.js";
import type { Common } from "@/Ponder.js";
import type { Schema } from "@/schema/types.js";
import { buildGqlSchema } from "@/server/graphql/schema.js";

import type { RawIndexingFunctions } from "./functions.js";
import type { ViteNodeError } from "./stacktrace.js";
import { parseViteNodeError } from "./stacktrace.js";

type BuildServiceEvents = {
newConfig: { config: Config };
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/codegen/service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Emittery from "emittery";
import { GraphQLSchema, printSchema } from "graphql";
import type { GraphQLSchema } from "graphql";
import { printSchema } from "graphql";
import { writeFileSync } from "node:fs";
import path from "node:path";

import type { Common } from "@/Ponder";
import { ensureDirExists } from "@/utils/exists";
import type { Common } from "@/Ponder.js";
import { ensureDirExists } from "@/utils/exists.js";

export class CodegenService extends Emittery {
private common: Common;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/config/abi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type Abi, type AbiEvent, formatAbiItem } from "abitype";
import { type Hex, getEventSelector } from "viem";

import { getDuplicateElements } from "@/utils/duplicates";
import { getDuplicateElements } from "@/utils/duplicates.js";

export type LogEventMetadata = {
// Event name (if no overloads) or full event signature (if name is overloaded).
Expand Down
9 changes: 5 additions & 4 deletions packages/core/src/config/config.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { http, ParseAbi, ParseAbiItem } from "viem";
import type { ParseAbi, ParseAbiItem } from "viem";
import { http } from "viem";
import { assertType, test } from "vitest";

import {
import type {
Config,
createConfig,
FilterAbiEvents,
RecoverAbiEvent,
SafeEventNames,
} from "./config";
} from "./config.js";
import { createConfig } from "./config.js";

export const abiSimple = [
{
Expand Down
22 changes: 11 additions & 11 deletions packages/core/src/config/database.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Sqlite from "better-sqlite3";
import path from "node:path";
import pg, { Client, DatabaseError, Pool } from "pg";
import pg from "pg";

import type { Config } from "@/config/config";
import { PostgresError } from "@/errors/postgres";
import { SqliteError } from "@/errors/sqlite";
import type { Common } from "@/Ponder";
import { ensureDirExists } from "@/utils/exists";
import type { Config } from "@/config/config.js";
import { PostgresError } from "@/errors/postgres.js";
import { SqliteError } from "@/errors/sqlite.js";
import type { Common } from "@/Ponder.js";
import { ensureDirExists } from "@/utils/exists.js";

export interface SqliteDb {
kind: "sqlite";
Expand All @@ -15,7 +15,7 @@ export interface SqliteDb {

export interface PostgresDb {
kind: "postgres";
pool: Pool;
pool: pg.Pool;
}

export type Database = SqliteDb | PostgresDb;
Expand All @@ -26,18 +26,18 @@ pg.types.setTypeParser(1700, BigInt);

// Monkeypatch Pool.query to get more informative stack traces. I have no idea why this works.
// https://stackoverflow.com/a/70601114
const originalClientQuery = Client.prototype.query;
const originalClientQuery = pg.Client.prototype.query;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Client.prototype.query = async function query(
pg.Client.prototype.query = async function query(
...args: [queryText: string, values: any[], callback: () => void]
) {
try {
return await originalClientQuery.apply(this, args);
} catch (error) {
const [statement, parameters] = args;

if (error instanceof DatabaseError) {
if (error instanceof pg.DatabaseError) {
const parameters_ = parameters ?? [];
throw new PostgresError({
statement,
Expand Down Expand Up @@ -132,7 +132,7 @@ export const buildDatabase = ({

return { kind: "sqlite", db };
} else {
const pool = new Pool({
const pool = new pg.Pool({
connectionString: resolvedDatabaseConfig.connectionString,
});

Expand Down
Loading

1 comment on commit 49fa33c

@vercel
Copy link

@vercel vercel bot commented on 49fa33c Nov 10, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.