Skip to content

Commit

Permalink
Merge branch 'main' into kjs/sync-store
Browse files Browse the repository at this point in the history
  • Loading branch information
kyscott18 committed Feb 27, 2025
2 parents 894d622 + 7d5e650 commit cafde16
Show file tree
Hide file tree
Showing 21 changed files with 302 additions and 152 deletions.
1 change: 1 addition & 0 deletions docs/pages/docs/api-reference/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export default createConfig({
connectionString: "postgresql://user:password@localhost:5432/dbname",
poolConfig: {
max: 100,
ssl: true,
},
},
// ... more config
Expand Down
6 changes: 6 additions & 0 deletions packages/client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @ponder/client

## 0.9.24

## 0.9.23

## 0.9.22

## 0.9.21

## 0.9.20
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ponder/client",
"version": "0.9.21",
"version": "0.9.24",
"description": "",
"license": "MIT",
"type": "module",
Expand Down
20 changes: 20 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# ponder

## 0.9.24

### Patch Changes

- [#1447](https://github.com/ponder-sh/ponder/pull/1447) [`2c6f2aaa743483169f3913ae3757e70eda38f073`](https://github.com/ponder-sh/ponder/commit/2c6f2aaa743483169f3913ae3757e70eda38f073) Thanks [@typedarray](https://github.com/typedarray)! - Added support for `ssl` options in Postgres pool configuration.

## 0.9.23

### Patch Changes

- [#1552](https://github.com/ponder-sh/ponder/pull/1552) [`b0618efd5b07feb851463327b4517fdfb31c2384`](https://github.com/ponder-sh/ponder/commit/b0618efd5b07feb851463327b4517fdfb31c2384) Thanks [@normanzb](https://github.com/normanzb)! - Fixed an issue where libraries that subclass `Hono` (like `@hono/zod-openapi`) were not supported by API functions.

- [#1560](https://github.com/ponder-sh/ponder/pull/1560) [`818d20eef48a247b513d7eadfa7c04be74f36477`](https://github.com/ponder-sh/ponder/commit/818d20eef48a247b513d7eadfa7c04be74f36477) Thanks [@typedarray](https://github.com/typedarray)! - Fixed a bug introduced in `0.9.20` where the `ponder` entrypoint included Node.js-only imports like `"node:path"`, breaking some workflows that use `@ponder/client` in browser environments.

## 0.9.22

### Patch Changes

- [#1557](https://github.com/ponder-sh/ponder/pull/1557) [`3b92c7312889398986e82da543b5872ef15a27f5`](https://github.com/ponder-sh/ponder/commit/3b92c7312889398986e82da543b5872ef15a27f5) Thanks [@kyscott18](https://github.com/kyscott18)! - Fixed a regression introduced in v0.9.20 that caused an error when using raw sql queries.

## 0.9.21

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ponder",
"version": "0.9.21",
"version": "0.9.24",
"description": "An open-source framework for crypto application backends",
"license": "MIT",
"type": "module",
Expand Down
9 changes: 4 additions & 5 deletions packages/core/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { getNextAvailablePort } from "@/utils/port.js";
import type { Result } from "@/utils/result.js";
import { serialize } from "@/utils/serialize.js";
import { glob } from "glob";
import type { Hono } from "hono";
import { Hono } from "hono";
import { createServer } from "vite";
import { ViteNodeRunner } from "vite-node/client";
import { ViteNodeServer } from "vite-node/server";
Expand Down Expand Up @@ -276,7 +276,7 @@ export const createBuild = async ({

if (!fs.existsSync(common.options.apiFile)) {
const error = new BuildError(
`API function file not found. Create a file at ${common.options.apiFile}. Read more: https://ponder-docs-git-v09-ponder-sh.vercel.app/docs/query/api-functions`,
`API function file not found. Create a file at ${common.options.apiFile}. Read more: https://ponder.sh/docs/query/api-functions`,
);
error.stack = undefined;
common.logger.error({
Expand Down Expand Up @@ -310,10 +310,9 @@ export const createBuild = async ({

const app = executeResult.exports.default;

// TODO: Consider a stricter validation here.
if (app?.constructor?.name !== "Hono") {
if (!(app instanceof Hono || app?.constructor?.name === "Hono")) {
const error = new BuildError(
"API function file does not export a Hono instance as the default export. Read more: https://ponder-docs-git-v09-ponder-sh.vercel.app/docs/query/api-functions",
"API function file does not export a Hono instance as the default export. Read more: https://ponder.sh/docs/query/api-functions",
);
error.stack = undefined;
common.logger.error({
Expand Down
18 changes: 16 additions & 2 deletions packages/core/src/build/pre.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,32 @@ test("buildPre() database with postgres uses pool config", async () => {
database: {
kind: "postgres",
connectionString: "postgres://username@localhost:5432/database",
poolConfig: { max: 100 },
poolConfig: {
max: 100,
ssl: {
ca: "ca",
cert: "cert",
key: "key",
},
// @ts-expect-error
unsupported: "unsupported",
},
},
networks: { mainnet: { chainId: 1, transport: http() } },
contracts: { a: { network: "mainnet", abi: [] } },
});

const { databaseConfig } = buildPre({ config, options });
expect(databaseConfig).toMatchObject({
expect(databaseConfig).toStrictEqual({
kind: "postgres",
poolConfig: {
connectionString: "postgres://username@localhost:5432/database",
max: 100,
ssl: {
ca: "ca",
cert: "cert",
key: "key",
},
},
});
});
5 changes: 3 additions & 2 deletions packages/core/src/build/pre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ export function buildPre({
});

const poolConfig = {
max: config.database.poolConfig?.max ?? 30,
connectionString,
max: config.database.poolConfig?.max ?? 30,
ssl: config.database.poolConfig?.ssl ?? false,
};

databaseConfig = { kind: "postgres", poolConfig };
Expand Down Expand Up @@ -96,7 +97,7 @@ export function buildPre({
msg: `Using Postgres database ${getDatabaseName(connectionString)} (${source})`,
});

const poolConfig = { max: 30, connectionString };
const poolConfig = { connectionString, max: 30 };

databaseConfig = { kind: "postgres", poolConfig };
} else {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ConnectionOptions } from "node:tls";
import type { Prettify } from "@/types/utils.js";
import type { Abi } from "abitype";
import type { Narrow, Transport } from "viem";
Expand Down Expand Up @@ -58,6 +59,8 @@ type DatabaseConfig =
poolConfig?: {
/** Maximum number of clients in the pool. Default: `30`. */
max?: number;
/** Enable SSL, or provide a custom SSL configuration. Default: `undefined`. */
ssl?: boolean | Prettify<ConnectionOptions>;
};
};

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/graphql/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Database } from "@/database/index.js";
import type { OnchainTable } from "@/drizzle/onchain.js";
import { normalizeColumn } from "@/indexing-store/cache.js";
import { normalizeColumn } from "@/indexing-store/utils.js";
import type { Schema } from "@/internal/types.js";
import type { Drizzle, ReadonlyDrizzle } from "@/types/db.js";
import { never } from "@/utils/never.js";
Expand Down
45 changes: 45 additions & 0 deletions packages/core/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { readFileSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { build } from "vite";
import { expect, test } from "vitest";

let __dirname = fileURLToPath(new URL(".", import.meta.url));
__dirname = path.resolve(__dirname, "..");

const packageJson = JSON.parse(
readFileSync(path.resolve(__dirname, "./package.json"), "utf-8"),
);
const dependencies = Object.keys(packageJson.dependencies).filter(
(dep) => !["@ponder/client", "@ponder/utils"].includes(dep),
);

test("should bundle the entry file for the browser without throwing", async () => {
await expect(
build({
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
"@ponder/client": path.resolve(__dirname, "../client/src"),
"@ponder/utils": path.resolve(__dirname, "../utils/src"),
},
},
// Mock build settings
logLevel: "error",
build: {
lib: {
entry: path.resolve(__dirname, "./src/index.ts"),
name: "ponder",
formats: ["es"],
},
// Speed up the build
write: false,
minify: false,
reportCompressedSize: false,
sourcemap: false,
// Exclude all dependencies
rollupOptions: { external: dependencies },
},
}),
).resolves.toBeDefined();
});
19 changes: 18 additions & 1 deletion packages/core/src/indexing-store/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,24 @@ test("flush() update", async (context) => {

await indexingCache.flush({ client });

const result = await indexingStore.find(schema.account, {
let result = await indexingStore.find(schema.account, {
address: zeroAddress,
});

expect(result).toStrictEqual({
address: zeroAddress,
balance: 12n,
});

// flush again to make sure temp tables are cleaned up

await indexingStore.update(schema.account, { address: zeroAddress }).set({
balance: 12n,
});

await indexingCache.flush({ client });

result = await indexingStore.find(schema.account, {
address: zeroAddress,
});

Expand Down
Loading

0 comments on commit cafde16

Please sign in to comment.