bponder 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/esm/build/bunNativeBuild.js +65 -2
  3. package/dist/esm/build/bunNativeBuild.js.map +1 -1
  4. package/dist/esm/client/index.js +2 -1
  5. package/dist/esm/client/index.js.map +1 -1
  6. package/dist/esm/database/actions.js +7 -9
  7. package/dist/esm/database/actions.js.map +1 -1
  8. package/dist/esm/database/executeResult.js +22 -0
  9. package/dist/esm/database/executeResult.js.map +1 -0
  10. package/dist/esm/graphql/index.js +2 -3
  11. package/dist/esm/graphql/index.js.map +1 -1
  12. package/dist/esm/indexing-store/index.js +7 -4
  13. package/dist/esm/indexing-store/index.js.map +1 -1
  14. package/dist/esm/server/bunV1Api.js +2 -11
  15. package/dist/esm/server/bunV1Api.js.map +1 -1
  16. package/dist/esm/server/bunV1Readonly.js +2 -11
  17. package/dist/esm/server/bunV1Readonly.js.map +1 -1
  18. package/dist/types/build/bunNativeBuild.d.ts.map +1 -1
  19. package/dist/types/client/index.d.ts.map +1 -1
  20. package/dist/types/database/actions.d.ts.map +1 -1
  21. package/dist/types/database/executeResult.d.ts +11 -0
  22. package/dist/types/database/executeResult.d.ts.map +1 -0
  23. package/dist/types/graphql/index.d.ts.map +1 -1
  24. package/dist/types/indexing-store/index.d.ts.map +1 -1
  25. package/dist/types/server/bunV1Api.d.ts.map +1 -1
  26. package/dist/types/server/bunV1Readonly.d.ts.map +1 -1
  27. package/package.json +4 -4
  28. package/src/build/bunNativeBuild.ts +84 -3
  29. package/src/client/index.ts +2 -1
  30. package/src/database/actions.ts +14 -9
  31. package/src/database/executeResult.ts +27 -0
  32. package/src/graphql/index.ts +7 -6
  33. package/src/indexing-store/index.ts +9 -4
  34. package/src/server/bunV1Api.ts +3 -12
  35. package/src/server/bunV1Readonly.ts +3 -12
@@ -34,6 +34,7 @@ import type {
34
34
  SchemaBuild,
35
35
  } from "@/internal/types.js";
36
36
  import { decodeCheckpoint, MAX_CHECKPOINT_STRING } from "@/utils/checkpoint.js";
37
+ import { normalizeExecuteRows } from "./executeResult.js";
37
38
  import {
38
39
  getPonderCheckpointTable,
39
40
  PONDER_CHECKPOINT_TABLE_NAME,
@@ -404,8 +405,7 @@ WITH reverted1 AS (
404
405
  ), ${getRevertSql({ table })};`),
405
406
  );
406
407
 
407
- // @ts-expect-error
408
- counts.push(result.rows[0]!.count);
408
+ counts.push(normalizeExecuteRows<{ count: number }>(result)[0]!.count);
409
409
  }
410
410
 
411
411
  return counts;
@@ -447,7 +447,9 @@ AND checkpoint > '${checkpoint}'`,
447
447
  .join(" UNION ALL ")}) AS all_mins;`),
448
448
  )
449
449
  .then((result) => {
450
- return result.rows[0]?.operation_id as string | null;
450
+ return normalizeExecuteRows<{ operation_id: string | null }>(
451
+ result,
452
+ )[0]?.operation_id as string | null;
451
453
  });
452
454
 
453
455
  for (const table of tables) {
@@ -473,8 +475,7 @@ WITH reverted1 AS (
473
475
  ), ${getRevertSql({ table })};`),
474
476
  );
475
477
 
476
- // @ts-expect-error
477
- counts.push(result.rows[0]!.count);
478
+ counts.push(normalizeExecuteRows<{ count: number }>(result)[0]!.count);
478
479
  }
479
480
 
480
481
  return counts;
@@ -524,8 +525,7 @@ WITH reverted1 AS (
524
525
  ), ${getRevertSql({ table })};`),
525
526
  );
526
527
 
527
- // @ts-expect-error
528
- counts.push(result.rows[0]!.count);
528
+ counts.push(normalizeExecuteRows<{ count: number }>(result)[0]!.count);
529
529
  }
530
530
 
531
531
  return counts;
@@ -642,7 +642,9 @@ WHERE checkpoint > (
642
642
  .join(" UNION ALL ")}) AS all_mins;`),
643
643
  )
644
644
  .then((result) => {
645
- return result.rows[0]?.operation_id as string | null;
645
+ return normalizeExecuteRows<{ operation_id: string | null }>(
646
+ result,
647
+ )[0]?.operation_id as string | null;
646
648
  });
647
649
 
648
650
  const result = await tx.wrap((tx) =>
@@ -667,7 +669,10 @@ WHERE checkpoint > (
667
669
  GROUP BY SUBSTRING(checkpoint, 11, 16)::numeric;`),
668
670
  );
669
671
 
670
- for (const { chain_id, safe_checkpoint } of result.rows) {
672
+ for (const { chain_id, safe_checkpoint } of normalizeExecuteRows<{
673
+ chain_id: number;
674
+ safe_checkpoint: string;
675
+ }>(result)) {
671
676
  await tx.wrap((tx) =>
672
677
  tx
673
678
  .update(PONDER_CHECKPOINT)
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Normalize drizzle `execute()` / prepared-query results across drivers.
3
+ *
4
+ * - `drizzle-orm/bun-sql` returns a row array (`client.unsafe(...)`)
5
+ * - `drizzle-orm/node-postgres` and PGlite return `{ rows: [...] }`
6
+ *
7
+ * Call sites that assume `result.rows` (pg shape) crash under Bun.SQL with
8
+ * `TypeError: undefined is not an object (evaluating 'result.rows[0]')`.
9
+ */
10
+ export const normalizeExecuteRows = <
11
+ T extends Record<string, unknown> = Record<string, unknown>,
12
+ >(
13
+ result: unknown,
14
+ ): T[] => {
15
+ if (Array.isArray(result)) {
16
+ return result as T[];
17
+ }
18
+ if (
19
+ result !== null &&
20
+ typeof result === "object" &&
21
+ "rows" in result &&
22
+ Array.isArray((result as { rows: unknown }).rows)
23
+ ) {
24
+ return (result as { rows: T[] }).rows;
25
+ }
26
+ return [];
27
+ };
@@ -67,6 +67,7 @@ import {
67
67
  type SelectionNode,
68
68
  } from "graphql";
69
69
  import superjson from "superjson";
70
+ import { normalizeExecuteRows } from "@/database/executeResult.js";
70
71
  import type { QB } from "@/database/queryBuilder.js";
71
72
  import { getPrimaryKeyColumns } from "@/drizzle/index.js";
72
73
  import type { OnchainTable } from "@/drizzle/onchain.js";
@@ -632,16 +633,16 @@ export function buildGraphQLSchema({
632
633
  type: GraphQLMeta,
633
634
  resolve: async (_source, _args, context) => {
634
635
  // Note: This is done to avoid non-browser compatible dependencies
635
- const checkpoints = (await context.qb.raw
636
- .execute(
637
- "SELECT chain_name, chain_id, latest_checkpoint, safe_checkpoint from _ponder_checkpoint",
638
- )
639
- .then((res) => res.rows)) as {
636
+ const checkpoints = normalizeExecuteRows<{
640
637
  chain_name: string;
641
638
  chain_id: string;
642
639
  latest_checkpoint: string;
643
640
  safe_checkpoint: string;
644
- }[];
641
+ }>(
642
+ await context.qb.raw.execute(
643
+ "SELECT chain_name, chain_id, latest_checkpoint, safe_checkpoint from _ponder_checkpoint",
644
+ ),
645
+ );
645
646
 
646
647
  const status: Status = {};
647
648
  for (const {
@@ -10,6 +10,7 @@ import {
10
10
  } from "drizzle-orm";
11
11
  import { getTableConfig } from "drizzle-orm/pg-core";
12
12
  import { drizzle } from "drizzle-orm/pg-proxy";
13
+ import { normalizeExecuteRows } from "@/database/executeResult.js";
13
14
  import type { QB } from "@/database/queryBuilder.js";
14
15
  import { getPrimaryKeyColumns } from "@/drizzle/index.js";
15
16
  import { onchain } from "@/drizzle/onchain.js";
@@ -644,15 +645,19 @@ export const createIndexingStore = ({
644
645
  .execute(),
645
646
  );
646
647
 
648
+ const rows = normalizeExecuteRows(result);
649
+
647
650
  if (method === "all") {
648
651
  return {
649
- // @ts-expect-error
650
- ...result,
651
- // @ts-expect-error
652
- rows: result.rows.map((row) => Object.values(row)),
652
+ rows: rows.map((row) => Object.values(row)),
653
653
  };
654
654
  }
655
655
 
656
+ // bun-sql returns a bare row array; drizzle's pg-proxy expects { rows }.
657
+ if (Array.isArray(result)) {
658
+ return { rows };
659
+ }
660
+
656
661
  return result;
657
662
  });
658
663
  } catch (error) {
@@ -1,3 +1,4 @@
1
+ import { normalizeExecuteRows } from "@/database/executeResult.js";
1
2
  import type { BunSqlDatabase } from "../database/bunSql.js";
2
3
  import type { BunFetchHandler } from "./bunServe.js";
3
4
 
@@ -48,18 +49,8 @@ export const isReadonlySelectSql = (sql: string): boolean => {
48
49
  );
49
50
  };
50
51
 
51
- const toRows = (result: unknown): Record<string, unknown>[] => {
52
- if (Array.isArray(result)) return result as Record<string, unknown>[];
53
- if (
54
- result !== null &&
55
- typeof result === "object" &&
56
- "rows" in result &&
57
- Array.isArray((result as { rows: unknown }).rows)
58
- ) {
59
- return (result as { rows: Record<string, unknown>[] }).rows;
60
- }
61
- return [];
62
- };
52
+ const toRows = (result: unknown): Record<string, unknown>[] =>
53
+ normalizeExecuteRows(result);
63
54
 
64
55
  const jsonError = (message: string, status: number) =>
65
56
  Response.json({ error: message }, { status });
@@ -1,4 +1,5 @@
1
1
  import { sql } from "drizzle-orm";
2
+ import { normalizeExecuteRows } from "@/database/executeResult.js";
2
3
  import { getPonderCheckpointTable } from "@/database/index.js";
3
4
  import type { QB } from "@/database/queryBuilder.js";
4
5
  import { decodeCheckpoint } from "@/utils/checkpoint.js";
@@ -8,18 +9,8 @@ import {
8
9
  isReadonlySelectSql,
9
10
  } from "./bunV1Api.js";
10
11
 
11
- const toRows = (result: unknown): Record<string, unknown>[] => {
12
- if (Array.isArray(result)) return result as Record<string, unknown>[];
13
- if (
14
- result !== null &&
15
- typeof result === "object" &&
16
- "rows" in result &&
17
- Array.isArray((result as { rows: unknown }).rows)
18
- ) {
19
- return (result as { rows: Record<string, unknown>[] }).rows;
20
- }
21
- return [];
22
- };
12
+ const toRows = (result: unknown): Record<string, unknown>[] =>
13
+ normalizeExecuteRows(result);
23
14
 
24
15
  const toBunV1Status = (
25
16
  checkpoints: {