ponder 0.9.2 → 0.9.4-debug.1

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 (58) hide show
  1. package/dist/bin/ponder.js +2470 -3762
  2. package/dist/bin/ponder.js.map +1 -1
  3. package/dist/chunk-6AOFLZJ4.js +1692 -0
  4. package/dist/chunk-6AOFLZJ4.js.map +1 -0
  5. package/dist/chunk-DZFRP3KH.js +70 -0
  6. package/dist/chunk-DZFRP3KH.js.map +1 -0
  7. package/dist/{chunk-IFTUFVCL.js → chunk-MJKRYIBO.js} +3 -73
  8. package/dist/chunk-MJKRYIBO.js.map +1 -0
  9. package/dist/db-in86nyw7.d.ts +625 -0
  10. package/dist/experimental_unsafe_stores.d.ts +375 -0
  11. package/dist/experimental_unsafe_stores.js +11 -0
  12. package/dist/experimental_unsafe_stores.js.map +1 -0
  13. package/dist/index.d.ts +17 -429
  14. package/dist/index.js +4 -2
  15. package/dist/index.js.map +1 -1
  16. package/package.json +5 -1
  17. package/src/bin/commands/codegen.ts +8 -10
  18. package/src/bin/commands/dev.ts +30 -42
  19. package/src/bin/commands/list.ts +9 -14
  20. package/src/bin/commands/serve.ts +26 -39
  21. package/src/bin/commands/start.ts +29 -42
  22. package/src/bin/utils/{shutdown.ts → exit.ts} +23 -37
  23. package/src/bin/utils/run.ts +275 -175
  24. package/src/bin/utils/runServer.ts +1 -5
  25. package/src/build/configAndIndexingFunctions.ts +547 -512
  26. package/src/build/index.ts +5 -8
  27. package/src/build/pre.ts +3 -0
  28. package/src/config/index.ts +9 -6
  29. package/src/database/index.ts +72 -72
  30. package/src/drizzle/kit/index.ts +3 -3
  31. package/src/experimental_unsafe_stores.ts +4 -0
  32. package/src/indexing/index.ts +0 -4
  33. package/src/indexing/service.ts +31 -93
  34. package/src/indexing-store/historical.ts +2 -4
  35. package/src/internal/common.ts +2 -0
  36. package/src/internal/errors.ts +9 -9
  37. package/src/internal/logger.ts +1 -1
  38. package/src/internal/metrics.ts +75 -103
  39. package/src/internal/shutdown.ts +25 -0
  40. package/src/internal/telemetry.ts +16 -18
  41. package/src/internal/types.ts +9 -1
  42. package/src/server/index.ts +3 -5
  43. package/src/sync/events.ts +4 -4
  44. package/src/sync/filter.ts +1 -0
  45. package/src/sync/index.ts +1046 -805
  46. package/src/sync-historical/index.ts +0 -37
  47. package/src/sync-realtime/index.ts +48 -48
  48. package/src/sync-store/encoding.ts +5 -5
  49. package/src/sync-store/index.ts +5 -23
  50. package/src/ui/index.ts +2 -11
  51. package/src/utils/checkpoint.ts +17 -3
  52. package/src/utils/chunk.ts +7 -0
  53. package/src/utils/generators.ts +66 -0
  54. package/src/utils/mutex.ts +34 -0
  55. package/src/utils/partition.ts +41 -0
  56. package/src/utils/requestQueue.ts +19 -10
  57. package/src/utils/zipper.ts +80 -0
  58. package/dist/chunk-IFTUFVCL.js.map +0 -1
@@ -0,0 +1,375 @@
1
+ import { D as Db, S as Schema, F as FragmentId, I as IndexingBuild, d as Drizzle, e as SchemaBuild } from './db-in86nyw7.js';
2
+ import { Hash, Hex, Address } from 'viem';
3
+ import { ColumnType, Kysely } from 'kysely';
4
+ import { PGlite } from '@electric-sql/pglite';
5
+ import { Pool, PoolClient } from 'pg';
6
+ import { P as Prettify } from './utils-ceNucOJb.js';
7
+ import { LevelWithSilent } from 'pino';
8
+ import prometheus from 'prom-client';
9
+ import './drizzle/onchain.js';
10
+ import 'drizzle-orm/pg-core';
11
+ import 'drizzle-orm';
12
+ import 'drizzle-orm/pg-core/columns/all';
13
+ import 'abitype';
14
+ import 'drizzle-orm/node-postgres';
15
+ import 'drizzle-orm/pglite';
16
+
17
+ type IndexingStore<policy extends "historical" | "realtime"> = policy extends "realtime" ? Db<Schema> : Db<Schema> & {
18
+ /** Persist the cache to the database. */
19
+ flush: () => Promise<void>;
20
+ /** Return `true` if the cache size in bytes is above the limit specified by `option.indexingCacheMaxBytes`. */
21
+ isCacheFull: () => boolean;
22
+ };
23
+
24
+ type LogMode = "pretty" | "json";
25
+ type LogLevel = Prettify<LevelWithSilent>;
26
+ type Logger = ReturnType<typeof createLogger>;
27
+ type Log = {
28
+ level: 60 | 50 | 40 | 30 | 20 | 10;
29
+ time: number;
30
+ service: string;
31
+ msg: string;
32
+ error?: Error;
33
+ };
34
+ declare function createLogger({ level, mode, }: {
35
+ level: LogLevel;
36
+ mode?: LogMode;
37
+ }): {
38
+ fatal(options: Omit<Log, "level" | "time">): void;
39
+ error(options: Omit<Log, "level" | "time">): void;
40
+ warn(options: Omit<Log, "level" | "time">): void;
41
+ info(options: Omit<Log, "level" | "time">): void;
42
+ debug(options: Omit<Log, "level" | "time">): void;
43
+ trace(options: Omit<Log, "level" | "time">): void;
44
+ flush: () => Promise<unknown>;
45
+ };
46
+
47
+ declare class MetricsService {
48
+ registry: prometheus.Registry;
49
+ start_timestamp: number;
50
+ rps: {
51
+ [network: string]: {
52
+ count: number;
53
+ timestamp: number;
54
+ }[];
55
+ };
56
+ ponder_historical_total_indexing_seconds: prometheus.Gauge<"network">;
57
+ ponder_historical_cached_indexing_seconds: prometheus.Gauge<"network">;
58
+ ponder_historical_completed_indexing_seconds: prometheus.Gauge<"network">;
59
+ ponder_indexing_timestamp: prometheus.Gauge<"network">;
60
+ ponder_indexing_has_error: prometheus.Gauge<"network">;
61
+ ponder_indexing_completed_events: prometheus.Gauge<"event">;
62
+ ponder_indexing_function_duration: prometheus.Histogram<"event">;
63
+ ponder_indexing_abi_decoding_duration: prometheus.Histogram;
64
+ ponder_sync_block: prometheus.Gauge<"network">;
65
+ ponder_sync_is_realtime: prometheus.Gauge<"network">;
66
+ ponder_sync_is_complete: prometheus.Gauge<"network">;
67
+ ponder_historical_duration: prometheus.Histogram<"network">;
68
+ ponder_historical_total_blocks: prometheus.Gauge<"network">;
69
+ ponder_historical_cached_blocks: prometheus.Gauge<"network">;
70
+ ponder_historical_completed_blocks: prometheus.Gauge<"network">;
71
+ ponder_realtime_reorg_total: prometheus.Counter<"network">;
72
+ ponder_realtime_latency: prometheus.Histogram<"network">;
73
+ ponder_database_method_duration: prometheus.Histogram<"service" | "method">;
74
+ ponder_database_method_error_total: prometheus.Counter<"service" | "method">;
75
+ ponder_http_server_port: prometheus.Gauge;
76
+ ponder_http_server_active_requests: prometheus.Gauge<"method" | "path">;
77
+ ponder_http_server_request_duration_ms: prometheus.Histogram<"method" | "path" | "status">;
78
+ ponder_http_server_request_size_bytes: prometheus.Histogram<"method" | "path" | "status">;
79
+ ponder_http_server_response_size_bytes: prometheus.Histogram<"method" | "path" | "status">;
80
+ ponder_rpc_request_duration: prometheus.Histogram<"network" | "method">;
81
+ ponder_rpc_request_lag: prometheus.Histogram<"network" | "method">;
82
+ ponder_postgres_query_total: prometheus.Counter<"pool">;
83
+ ponder_postgres_query_queue_size: prometheus.Gauge<"pool">;
84
+ ponder_postgres_pool_connections: prometheus.Gauge<"pool" | "kind">;
85
+ constructor();
86
+ /**
87
+ * Get string representation for all metrics.
88
+ * @returns Metrics encoded using Prometheus v0.0.4 format.
89
+ */
90
+ getMetrics(): Promise<string>;
91
+ resetIndexingMetrics(): void;
92
+ resetApiMetrics(): void;
93
+ }
94
+
95
+ type Options = {
96
+ command: "dev" | "start" | "serve" | "codegen" | "list";
97
+ configFile: string;
98
+ schemaFile: string;
99
+ apiDir: string;
100
+ apiFile: string;
101
+ rootDir: string;
102
+ indexingDir: string;
103
+ generatedDir: string;
104
+ ponderDir: string;
105
+ logDir: string;
106
+ port: number;
107
+ hostname?: string;
108
+ telemetryUrl: string;
109
+ telemetryDisabled: boolean;
110
+ telemetryConfigDir: string | undefined;
111
+ logLevel: LevelWithSilent;
112
+ logFormat: "json" | "pretty";
113
+ databaseHeartbeatInterval: number;
114
+ databaseHeartbeatTimeout: number;
115
+ databaseMaxQueryParameters: number;
116
+ factoryAddressCountThreshold: number;
117
+ indexingCacheMaxBytes: number;
118
+ indexingCacheFlushRatio: number;
119
+ syncEventsQuerySize: number;
120
+ syncHandoffStaleSeconds: number;
121
+ };
122
+
123
+ type Shutdown = {
124
+ add: (callback: () => unknown | Promise<unknown>) => void;
125
+ kill: () => Promise<void>;
126
+ isKilled: boolean;
127
+ abortController: AbortController;
128
+ };
129
+
130
+ type TelemetryEvent = {
131
+ name: "lifecycle:session_start";
132
+ properties: {
133
+ cli_command: string;
134
+ };
135
+ } | {
136
+ name: "lifecycle:session_end";
137
+ properties: {
138
+ duration_seconds: number;
139
+ };
140
+ } | {
141
+ name: "lifecycle:heartbeat_send";
142
+ properties: {
143
+ duration_seconds: number;
144
+ };
145
+ };
146
+ type Telemetry = ReturnType<typeof createTelemetry>;
147
+ declare function createTelemetry({ options, logger, shutdown, }: {
148
+ options: Options;
149
+ logger: Logger;
150
+ shutdown: Shutdown;
151
+ }): {
152
+ record: (_event: TelemetryEvent) => void;
153
+ flush: () => Promise<void>;
154
+ };
155
+
156
+ type Common = {
157
+ options: Options;
158
+ logger: Logger;
159
+ metrics: MetricsService;
160
+ telemetry: Telemetry;
161
+ shutdown: Shutdown;
162
+ };
163
+
164
+ type BlocksTable = {
165
+ hash: Hash;
166
+ chainId: number;
167
+ checkpoint: string;
168
+ number: ColumnType<string, string | bigint, string | bigint>;
169
+ timestamp: ColumnType<string, string | bigint, string | bigint>;
170
+ baseFeePerGas: ColumnType<string, string | bigint, string | bigint> | null;
171
+ difficulty: ColumnType<string, string | bigint, string | bigint>;
172
+ extraData: Hex;
173
+ gasLimit: ColumnType<string, string | bigint, string | bigint>;
174
+ gasUsed: ColumnType<string, string | bigint, string | bigint>;
175
+ logsBloom: Hex;
176
+ miner: Address;
177
+ mixHash: Hash | null;
178
+ nonce: Hex | null;
179
+ parentHash: Hash;
180
+ receiptsRoot: Hex;
181
+ sha3Uncles: Hash | null;
182
+ size: ColumnType<string, string | bigint, string | bigint>;
183
+ stateRoot: Hash;
184
+ totalDifficulty: ColumnType<string, string | bigint, string | bigint> | null;
185
+ transactionsRoot: Hash;
186
+ };
187
+ type LogsTable = {
188
+ id: string;
189
+ chainId: number;
190
+ checkpoint: string | null;
191
+ blockHash: Hash;
192
+ blockNumber: ColumnType<string, string | bigint, string | bigint>;
193
+ logIndex: number;
194
+ transactionHash: Hash;
195
+ transactionIndex: number;
196
+ address: Address;
197
+ topic0: Hex | null;
198
+ topic1: Hex | null;
199
+ topic2: Hex | null;
200
+ topic3: Hex | null;
201
+ data: Hex;
202
+ };
203
+ type TransactionsTable = {
204
+ hash: Hash;
205
+ chainId: number;
206
+ /** `checkpoint` will be null for transactions inserted before 0.8. This is to avoid a very slow migration. */
207
+ checkpoint: string | null;
208
+ blockHash: Hash;
209
+ blockNumber: ColumnType<string, string | bigint, string | bigint>;
210
+ from: Address;
211
+ gas: ColumnType<string, string | bigint, string | bigint>;
212
+ input: Hex;
213
+ nonce: number;
214
+ r: Hex | null;
215
+ s: Hex | null;
216
+ to: Address | null;
217
+ transactionIndex: number;
218
+ v: ColumnType<string, string | bigint, string | bigint> | null;
219
+ value: ColumnType<string, string | bigint, string | bigint>;
220
+ type: Hex;
221
+ gasPrice: ColumnType<string, string | bigint, string | bigint> | null;
222
+ maxFeePerGas: ColumnType<string, string | bigint, string | bigint> | null;
223
+ maxPriorityFeePerGas: ColumnType<string, string | bigint, string | bigint> | null;
224
+ accessList: string | null;
225
+ };
226
+ type TransactionReceiptsTable = {
227
+ transactionHash: Hash;
228
+ chainId: number;
229
+ blockHash: Hash;
230
+ blockNumber: ColumnType<string, string | bigint, string | bigint>;
231
+ contractAddress: Address | null;
232
+ cumulativeGasUsed: ColumnType<string, string | bigint, string | bigint>;
233
+ effectiveGasPrice: ColumnType<string, string | bigint, string | bigint>;
234
+ from: Address;
235
+ gasUsed: ColumnType<string, string | bigint, string | bigint>;
236
+ logsBloom: Hex;
237
+ status: Hex;
238
+ to: Address | null;
239
+ transactionIndex: number;
240
+ type: Hex;
241
+ };
242
+ type TracesTable = {
243
+ id: string;
244
+ chainId: number;
245
+ checkpoint: string;
246
+ type: string;
247
+ transactionHash: Hex;
248
+ blockHash: Hex;
249
+ blockNumber: ColumnType<string, string | bigint, string | bigint>;
250
+ from: Address;
251
+ to: Address | null;
252
+ gas: ColumnType<string, string | bigint, string | bigint>;
253
+ gasUsed: ColumnType<string, string | bigint, string | bigint>;
254
+ input: Hex;
255
+ functionSelector: Hex;
256
+ output: Hex | null;
257
+ error: string | null;
258
+ revertReason: string | null;
259
+ value: ColumnType<string | null, string | bigint | null, string | bigint | null>;
260
+ index: number;
261
+ subcalls: number;
262
+ isReverted: number;
263
+ };
264
+ type RpcRequestResultsTable = {
265
+ request: string;
266
+ request_hash: ColumnType<string, undefined>;
267
+ chain_id: number;
268
+ block_number: ColumnType<string | undefined, string | bigint | undefined, string | bigint | undefined>;
269
+ result: string;
270
+ };
271
+ type IntervalTable = {
272
+ fragment_id: FragmentId;
273
+ chain_id: number;
274
+ blocks: string;
275
+ };
276
+ type PonderSyncSchema = {
277
+ blocks: BlocksTable;
278
+ logs: LogsTable;
279
+ transactions: TransactionsTable;
280
+ transactionReceipts: TransactionReceiptsTable;
281
+ traces: TracesTable;
282
+ rpc_request_results: RpcRequestResultsTable;
283
+ intervals: IntervalTable;
284
+ };
285
+
286
+ type Database = {
287
+ driver: PostgresDriver | PGliteDriver;
288
+ qb: QueryBuilder;
289
+ wrap: <T>(options: {
290
+ method: string;
291
+ includeTraceLogs?: boolean;
292
+ }, fn: () => Promise<T>) => Promise<T>;
293
+ /** Migrate the `ponder_sync` schema. */
294
+ migrateSync(): Promise<void>;
295
+ /** Migrate the user schema. */
296
+ migrate({ buildId }: Pick<IndexingBuild, "buildId">): Promise<void>;
297
+ /** Determine the app checkpoint, possibly reverting unfinalized rows. */
298
+ recoverCheckpoint(): Promise<string>;
299
+ createIndexes(): Promise<void>;
300
+ createTriggers(): Promise<void>;
301
+ removeTriggers(): Promise<void>;
302
+ revert(args: {
303
+ checkpoint: string;
304
+ }): Promise<void>;
305
+ finalize(args: {
306
+ checkpoint: string;
307
+ }): Promise<void>;
308
+ complete(args: {
309
+ checkpoint: string;
310
+ }): Promise<void>;
311
+ };
312
+ type PonderApp = {
313
+ is_locked: 0 | 1;
314
+ is_dev: 0 | 1;
315
+ heartbeat_at: number;
316
+ build_id: string;
317
+ checkpoint: string;
318
+ table_names: string[];
319
+ version: string;
320
+ };
321
+ type PonderInternalSchema = {
322
+ _ponder_meta: {
323
+ key: "app";
324
+ value: PonderApp;
325
+ };
326
+ _ponder_status: {
327
+ network_name: string;
328
+ block_number: number | null;
329
+ block_timestamp: number | null;
330
+ ready: boolean;
331
+ };
332
+ } & {
333
+ [_: ReturnType<typeof getTableNames>[number]["sql"]]: unknown;
334
+ } & {
335
+ [_: ReturnType<typeof getTableNames>[number]["reorg"]]: unknown & {
336
+ operation_id: number;
337
+ operation: 0 | 1 | 2;
338
+ checkpoint: string;
339
+ };
340
+ };
341
+ type PGliteDriver = {
342
+ instance: PGlite;
343
+ };
344
+ type PostgresDriver = {
345
+ internal: Pool;
346
+ user: Pool;
347
+ sync: Pool;
348
+ readonly: Pool;
349
+ listen: PoolClient | undefined;
350
+ };
351
+ type QueryBuilder = {
352
+ /** For updating metadata and handling reorgs */
353
+ internal: Kysely<PonderInternalSchema>;
354
+ /** For indexing-store methods in user code */
355
+ user: Kysely<any>;
356
+ /** Used to interact with the sync-store */
357
+ sync: Kysely<PonderSyncSchema>;
358
+ drizzle: Drizzle<Schema>;
359
+ drizzleReadonly: Drizzle<Schema>;
360
+ };
361
+
362
+ declare const createHistoricalIndexingStore: ({ common, schemaBuild: { schema }, database, isDatabaseEmpty, }: {
363
+ common: Common;
364
+ schemaBuild: Pick<SchemaBuild, "schema">;
365
+ database: Database;
366
+ isDatabaseEmpty: boolean;
367
+ }) => IndexingStore<"historical">;
368
+
369
+ declare const createRealtimeIndexingStore: ({ schemaBuild: { schema }, database, }: {
370
+ common: Common;
371
+ schemaBuild: Pick<SchemaBuild, "schema">;
372
+ database: Database;
373
+ }) => IndexingStore<"realtime">;
374
+
375
+ export { createHistoricalIndexingStore, createRealtimeIndexingStore };
@@ -0,0 +1,11 @@
1
+ import {
2
+ createHistoricalIndexingStore,
3
+ createRealtimeIndexingStore
4
+ } from "./chunk-6AOFLZJ4.js";
5
+ import "./chunk-MJKRYIBO.js";
6
+ import "./chunk-K2TLRLX3.js";
7
+ export {
8
+ createHistoricalIndexingStore,
9
+ createRealtimeIndexingStore
10
+ };
11
+ //# sourceMappingURL=experimental_unsafe_stores.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}