ponder 0.9.3 → 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.
@@ -0,0 +1,625 @@
1
+ import { onchain, OnchainTable, PrimaryKeyBuilder } from './drizzle/onchain.js';
2
+ import { AbiEvent, AbiFunction } from 'abitype';
3
+ import { Hex, Hash, Address, AccessList, TransactionType, Abi, Transport, Chain, LogTopic } from 'viem';
4
+ import { P as Prettify, a as PonderTypeError } from './utils-ceNucOJb.js';
5
+ import { Table, InferSelectModel, InferInsertModel, GetColumnData, Column as Column$1 } from 'drizzle-orm';
6
+ import { NodePgDatabase } from 'drizzle-orm/node-postgres';
7
+ import { TableConfig, PgTableExtraConfig } from 'drizzle-orm/pg-core';
8
+ import { PgliteDatabase } from 'drizzle-orm/pglite';
9
+
10
+ /**
11
+ * A confirmed Ethereum block.
12
+ *
13
+ * @link https://docs.soliditylang.org/en/v0.8.20/introduction-to-smart-contracts.html#blocks
14
+ */
15
+ type Block = {
16
+ /** Base fee per gas */
17
+ baseFeePerGas: bigint | null;
18
+ /** Difficulty for this block */
19
+ difficulty: bigint;
20
+ /** "Extra data" field of this block */
21
+ extraData: Hex;
22
+ /** Maximum gas allowed in this block */
23
+ gasLimit: bigint;
24
+ /** Total used gas by all transactions in this block */
25
+ gasUsed: bigint;
26
+ /** Block hash */
27
+ hash: Hash;
28
+ /** Logs bloom filter */
29
+ logsBloom: Hex;
30
+ /** Address that received this block’s mining rewards */
31
+ miner: Address;
32
+ /** Unique identifier for the block. */
33
+ mixHash: Hash | null;
34
+ /** Proof-of-work hash */
35
+ nonce: Hex | null;
36
+ /** Block number */
37
+ number: bigint;
38
+ /** Parent block hash */
39
+ parentHash: Hash;
40
+ /** Root of the this block’s receipts trie */
41
+ receiptsRoot: Hex;
42
+ /** SHA3 of the uncles data in this block */
43
+ sha3Uncles: Hash | null;
44
+ /** Size of this block in bytes */
45
+ size: bigint;
46
+ /** Root of this block’s final state trie */
47
+ stateRoot: Hash;
48
+ /** Unix timestamp of when this block was collated */
49
+ timestamp: bigint;
50
+ /** Total difficulty of the chain until this block */
51
+ totalDifficulty: bigint | null;
52
+ /** Root of this block’s transaction trie */
53
+ transactionsRoot: Hash;
54
+ };
55
+ /**
56
+ * A confirmed Ethereum transaction. Contains `legacy`, `EIP-1559`, or `EIP-2930` fee values depending on the transaction `type`.
57
+ *
58
+ * @link https://docs.soliditylang.org/en/v0.8.20/introduction-to-smart-contracts.html#transactions
59
+ */
60
+ type Transaction = Prettify<{
61
+ /** Transaction sender */
62
+ from: Address;
63
+ /** Gas provided for transaction execution */
64
+ gas: bigint;
65
+ /** Hash of this transaction */
66
+ hash: Hash;
67
+ /** Contract code or a hashed method call */
68
+ input: Hex;
69
+ /** Unique number identifying this transaction */
70
+ nonce: number;
71
+ /** ECDSA signature r */
72
+ r: Hex | null;
73
+ /** ECDSA signature s */
74
+ s: Hex | null;
75
+ /** Transaction recipient or `null` if deploying a contract */
76
+ to: Address | null;
77
+ /** Index of this transaction in the block */
78
+ transactionIndex: number;
79
+ /** ECDSA recovery ID */
80
+ v: bigint | null;
81
+ /** Value in wei sent with this transaction */
82
+ value: bigint;
83
+ } & ({
84
+ /** Transaction type. */
85
+ type: "legacy";
86
+ accessList?: never;
87
+ /** Base fee per gas. Only present in legacy and EIP-2930 transactions. */
88
+ gasPrice: bigint;
89
+ maxFeePerGas?: never;
90
+ maxPriorityFeePerGas?: never;
91
+ } | {
92
+ /** Transaction type. */
93
+ type: "eip2930";
94
+ /** List of addresses and storage keys the transaction will access. */
95
+ accessList: AccessList;
96
+ /** Base fee per gas. Only present in legacy and EIP-2930 transactions. */
97
+ gasPrice: bigint;
98
+ maxFeePerGas?: never;
99
+ maxPriorityFeePerGas?: never;
100
+ } | {
101
+ /** Transaction type. */
102
+ type: "eip1559";
103
+ accessList?: never;
104
+ gasPrice?: never;
105
+ /** Total fee per gas in wei (gasPrice/baseFeePerGas + maxPriorityFeePerGas). Only present in EIP-1559 transactions. */
106
+ maxFeePerGas: bigint;
107
+ /** Max priority fee per gas (in wei). Only present in EIP-1559 transactions. */
108
+ maxPriorityFeePerGas: bigint;
109
+ } | {
110
+ /** Transaction type. */
111
+ type: "deposit";
112
+ accessList?: never;
113
+ gasPrice?: never;
114
+ /** Total fee per gas in wei (gasPrice/baseFeePerGas + maxPriorityFeePerGas). Only present in EIP-1559 transactions. */
115
+ maxFeePerGas?: bigint;
116
+ /** Max priority fee per gas (in wei). Only present in EIP-1559 transactions. */
117
+ maxPriorityFeePerGas?: bigint;
118
+ } | {
119
+ /** Transaction type. */
120
+ type: Hex;
121
+ gasPrice?: never;
122
+ accessList?: never;
123
+ maxFeePerGas?: never;
124
+ maxPriorityFeePerGas?: never;
125
+ })>;
126
+ /**
127
+ * A confirmed Ethereum log.
128
+ *
129
+ * @link https://docs.soliditylang.org/en/v0.8.20/abi-spec.html#events
130
+ */
131
+ type Log = {
132
+ /** Globally unique identifier for this log (`${blockHash}-${logIndex}`) */
133
+ id: string;
134
+ /** The address from which this log originated */
135
+ address: Address;
136
+ /** Contains the non-indexed arguments of the log */
137
+ data: Hex;
138
+ /** Index of this log within its block */
139
+ logIndex: number;
140
+ /** `true` if this log has been removed in a chain reorganization */
141
+ removed: boolean;
142
+ /** List of order-dependent topics */
143
+ topics: [Hex, ...Hex[]] | [];
144
+ };
145
+ /** A confirmed Ethereum transaction receipt. */
146
+ type TransactionReceipt = {
147
+ /** Address of new contract or `null` if no contract was created */
148
+ contractAddress: Address | null;
149
+ /** Gas used by this and all preceding transactions in this block */
150
+ cumulativeGasUsed: bigint;
151
+ /** Pre-London, it is equal to the transaction's gasPrice. Post-London, it is equal to the actual gas price paid for inclusion. */
152
+ effectiveGasPrice: bigint;
153
+ /** Transaction sender */
154
+ from: Address;
155
+ /** Gas used by this transaction */
156
+ gasUsed: bigint;
157
+ /** Logs bloom filter */
158
+ logsBloom: Hex;
159
+ /** `success` if this transaction was successful or `reverted` if it failed */
160
+ status: "success" | "reverted";
161
+ /** Transaction recipient or `null` if deploying a contract */
162
+ to: Address | null;
163
+ /** Transaction type */
164
+ type: TransactionType;
165
+ };
166
+ type Trace = {
167
+ /** Globally unique identifier for this trace (`${transactionHash}-${tracePosition}`) */
168
+ id: string;
169
+ /** The type of the call. */
170
+ type: "CALL" | "CALLCODE" | "DELEGATECALL" | "STATICCALL" | "CREATE" | "CREATE2" | "SELFDESTRUCT";
171
+ /** The address of that initiated the call. */
172
+ from: Address;
173
+ /** The address of the contract that was called. */
174
+ to: Address | null;
175
+ /** How much gas was left before the call. */
176
+ gas: bigint;
177
+ /** How much gas was used by the call. */
178
+ gasUsed: bigint;
179
+ /** Calldata input. */
180
+ input: Hex;
181
+ /** Output of the call, if any. */
182
+ output?: Hex;
183
+ /** Error message, if any. */
184
+ error?: string;
185
+ /** Why this call reverted, if it reverted. */
186
+ revertReason?: string;
187
+ /** Value transferred. */
188
+ value: bigint | null;
189
+ /** Index of this trace in the transaction. */
190
+ traceIndex: number;
191
+ /** Number of subcalls. */
192
+ subcalls: number;
193
+ };
194
+ /** A native token transfer. */
195
+ type Transfer = {
196
+ /** The address that sent the transfer */
197
+ from: Address;
198
+ /** The address that received the transfer */
199
+ to: Address;
200
+ /** The amount of tokens transferred */
201
+ value: bigint;
202
+ };
203
+
204
+ type SqlStatements = {
205
+ tables: {
206
+ sql: string[];
207
+ json: JsonCreateTableStatement[];
208
+ };
209
+ enums: {
210
+ sql: string[];
211
+ json: JsonCreateEnumStatement[];
212
+ };
213
+ indexes: {
214
+ sql: string[];
215
+ json: JsonPgCreateIndexStatement[];
216
+ };
217
+ };
218
+ type Index = any;
219
+ type Column = any;
220
+ interface JsonCreateTableStatement {
221
+ type: "create_table";
222
+ tableName: string;
223
+ schema: string;
224
+ columns: Column[];
225
+ compositePKs: string[];
226
+ compositePkName?: string;
227
+ uniqueConstraints?: string[];
228
+ checkConstraints?: string[];
229
+ }
230
+ interface JsonCreateEnumStatement {
231
+ type: "create_type_enum";
232
+ name: string;
233
+ schema: string;
234
+ values: string[];
235
+ }
236
+ interface JsonPgCreateIndexStatement {
237
+ type: "create_index_pg";
238
+ tableName: string;
239
+ data: Index;
240
+ schema: string;
241
+ }
242
+
243
+ /**
244
+ * Fix issue with Array.isArray not checking readonly arrays
245
+ * {@link https://github.com/microsoft/TypeScript/issues/17002}
246
+ */
247
+ declare global {
248
+ interface ArrayConstructor {
249
+ isArray(arg: ReadonlyArray<any> | any): arg is ReadonlyArray<any>;
250
+ }
251
+ }
252
+ type AbiEventMeta = {
253
+ safeName: string;
254
+ signature: string;
255
+ selector: Hex;
256
+ item: AbiEvent;
257
+ };
258
+ type AbiFunctionMeta = {
259
+ safeName: string;
260
+ signature: string;
261
+ selector: Hex;
262
+ item: AbiFunction;
263
+ };
264
+ type AbiEvents = {
265
+ bySafeName: {
266
+ [key: string]: AbiEventMeta | undefined;
267
+ };
268
+ bySelector: {
269
+ [key: Hex]: AbiEventMeta | undefined;
270
+ };
271
+ };
272
+ type AbiFunctions = {
273
+ bySafeName: {
274
+ [key: string]: AbiFunctionMeta | undefined;
275
+ };
276
+ bySelector: {
277
+ [key: Hex]: AbiFunctionMeta | undefined;
278
+ };
279
+ };
280
+
281
+ /** Indexing functions for event callbacks */
282
+ type IndexingFunctions = {
283
+ [eventName: string]: (...args: any) => any;
284
+ };
285
+ /** Filter that matches addresses. */
286
+ type Factory = LogFactory;
287
+ type FilterAddress<factory extends Factory | undefined = Factory | undefined> = factory extends Factory ? factory : Address | Address[] | undefined;
288
+ type LogFilter<factory extends Factory | undefined = Factory | undefined> = {
289
+ type: "log";
290
+ chainId: number;
291
+ address: FilterAddress<factory>;
292
+ topic0: LogTopic;
293
+ topic1: LogTopic;
294
+ topic2: LogTopic;
295
+ topic3: LogTopic;
296
+ fromBlock: number | undefined;
297
+ toBlock: number | undefined;
298
+ include: (`block.${keyof Block}` | `transaction.${keyof Transaction}` | `transactionReceipt.${keyof TransactionReceipt}` | `log.${keyof Log}`)[] | undefined;
299
+ };
300
+ type BlockFilter = {
301
+ type: "block";
302
+ chainId: number;
303
+ interval: number;
304
+ offset: number;
305
+ fromBlock: number | undefined;
306
+ toBlock: number | undefined;
307
+ include: `block.${keyof Block}`[] | undefined;
308
+ };
309
+ type TransferFilter<fromFactory extends Factory | undefined = Factory | undefined, toFactory extends Factory | undefined = Factory | undefined> = {
310
+ type: "transfer";
311
+ chainId: number;
312
+ fromAddress: FilterAddress<fromFactory>;
313
+ toAddress: FilterAddress<toFactory>;
314
+ includeReverted: boolean;
315
+ fromBlock: number | undefined;
316
+ toBlock: number | undefined;
317
+ include: (`block.${keyof Block}` | `transaction.${keyof Transaction}` | `transactionReceipt.${keyof TransactionReceipt}` | `trace.${keyof Trace}`)[] | undefined;
318
+ };
319
+ type TransactionFilter<fromFactory extends Factory | undefined = Factory | undefined, toFactory extends Factory | undefined = Factory | undefined> = {
320
+ type: "transaction";
321
+ chainId: number;
322
+ fromAddress: FilterAddress<fromFactory>;
323
+ toAddress: FilterAddress<toFactory>;
324
+ includeReverted: boolean;
325
+ fromBlock: number | undefined;
326
+ toBlock: number | undefined;
327
+ include: (`block.${keyof Block}` | `transaction.${keyof Transaction}` | `transactionReceipt.${keyof TransactionReceipt}`)[] | undefined;
328
+ };
329
+ type TraceFilter<fromFactory extends Factory | undefined = Factory | undefined, toFactory extends Factory | undefined = Factory | undefined> = {
330
+ type: "trace";
331
+ chainId: number;
332
+ fromAddress: FilterAddress<fromFactory>;
333
+ toAddress: FilterAddress<toFactory>;
334
+ functionSelector: Hex | Hex[] | undefined;
335
+ callType: Trace["type"] | undefined;
336
+ includeReverted: boolean;
337
+ fromBlock: number | undefined;
338
+ toBlock: number | undefined;
339
+ include: (`block.${keyof Block}` | `transaction.${keyof Transaction}` | `transactionReceipt.${keyof TransactionReceipt}` | `trace.${keyof Trace}`)[] | undefined;
340
+ };
341
+ type LogFactory = {
342
+ type: "log";
343
+ chainId: number;
344
+ address: Address | Address[];
345
+ eventSelector: Hex;
346
+ childAddressLocation: "topic1" | "topic2" | "topic3" | `offset${number}`;
347
+ };
348
+ type FragmentAddressId = Address | `${Address}_${Factory["eventSelector"]}_${Factory["childAddressLocation"]}` | null;
349
+ type FragmentTopic = Hex | null;
350
+ /** Minimum slice of a {@link Filter} */
351
+ type FragmentId =
352
+ /** block_{chainId}_{interval}_{offset} */
353
+ `block_${number}_${number}_${number}`
354
+ /** transaction_{chainId}_{fromAddress}_{toAddress} */
355
+ | `transaction_${number}_${FragmentAddressId}_${FragmentAddressId}`
356
+ /** trace_{chainId}_{fromAddress}_{toAddress}_{functionSelector}_{includeReceipts} */
357
+ | `trace_${number}_${FragmentAddressId}_${FragmentAddressId}_${Hex | null}_${0 | 1}`
358
+ /** log_{chainId}_{address}_{topic0}_{topic1}_{topic2}_{topic3}_{includeReceipts} */
359
+ | `log_${number}_${FragmentAddressId}_${FragmentTopic}_${FragmentTopic}_${FragmentTopic}_${FragmentTopic}_${0 | 1}`
360
+ /** transfer_{chainId}_{fromAddress}_{toAddress}_{includeReceipts} */
361
+ | `transfer_${number}_${FragmentAddressId}_${FragmentAddressId}_${0 | 1}`;
362
+ /** Event source that matches {@link Event}s containing an underlying filter and metadata. */
363
+ type Source = ContractSource | AccountSource | BlockSource;
364
+ type ContractSource<filter extends "log" | "trace" = "log" | "trace", factory extends Factory | undefined = Factory | undefined, fromFactory extends Factory | undefined = Factory | undefined, toFactory extends Factory | undefined = Factory | undefined> = {
365
+ filter: filter extends "log" ? LogFilter<factory> : TraceFilter<fromFactory, toFactory>;
366
+ } & ContractMetadata;
367
+ type AccountSource<filter extends "transaction" | "transfer" = "transaction" | "transfer", fromFactory extends Factory | undefined = Factory | undefined, toFactory extends Factory | undefined = Factory | undefined> = {
368
+ filter: filter extends "transaction" ? TransactionFilter<fromFactory, toFactory> : TransferFilter<fromFactory, toFactory>;
369
+ } & AccountMetadata;
370
+ type BlockSource = {
371
+ filter: BlockFilter;
372
+ } & BlockMetadata;
373
+ type ContractMetadata = {
374
+ type: "contract";
375
+ abi: Abi;
376
+ abiEvents: AbiEvents;
377
+ abiFunctions: AbiFunctions;
378
+ name: string;
379
+ network: Network;
380
+ };
381
+ type AccountMetadata = {
382
+ type: "account";
383
+ name: string;
384
+ network: Network;
385
+ };
386
+ type BlockMetadata = {
387
+ type: "block";
388
+ name: string;
389
+ network: Network;
390
+ };
391
+ type Network = {
392
+ name: string;
393
+ chainId: number;
394
+ transport: ReturnType<Transport>;
395
+ chain: Chain;
396
+ pollingInterval: number;
397
+ maxRequestsPerSecond: number;
398
+ finalityBlockCount: number;
399
+ disableCache: boolean;
400
+ };
401
+ /** User-defined tables, enums, and indexes. */
402
+ type Schema = {
403
+ [name: string]: unknown;
404
+ };
405
+ type SchemaBuild = {
406
+ schema: Schema;
407
+ /** SQL statements to create the schema */
408
+ statements: SqlStatements;
409
+ };
410
+ type IndexingBuild = {
411
+ /** Ten character hex string identifier. */
412
+ buildId: string;
413
+ /** Sources to index. */
414
+ sources: Source[];
415
+ /** Networks to index. */
416
+ networks: Network[];
417
+ /** Event callbacks for all `sources`. */
418
+ indexingFunctions: IndexingFunctions;
419
+ };
420
+
421
+ type Drizzle<TSchema extends Schema = {
422
+ [name: string]: never;
423
+ }> = NodePgDatabase<TSchema> | PgliteDatabase<TSchema>;
424
+ type ReadonlyDrizzle<TSchema extends Schema = {
425
+ [name: string]: never;
426
+ }> = Omit<Drizzle<TSchema>, "insert" | "update" | "delete" | "transaction" | "refreshMaterializedView" | "_">;
427
+ type Db<schema extends Schema> = {
428
+ /**
429
+ * Find a row
430
+ *
431
+ * - Docs: https://ponder.sh/docs/indexing/write-to-the-database#find
432
+ *
433
+ * @example
434
+ * ```ts twoslash
435
+ * const result = await db.find(table, { id: 10 });
436
+ * ```
437
+ *
438
+ * @param table - The table to select from.
439
+ * @param key - The primary key.
440
+ * @returns The row if it exists or undefined if it doesn't.
441
+ */
442
+ find: Find;
443
+ /**
444
+ * Create new rows
445
+ *
446
+ * - Docs: https://ponder.sh/docs/indexing/write-to-the-database#insert
447
+ *
448
+ * @example
449
+ * ```ts twoslash
450
+ * await db.insert(table).values({ id: 10, name: "joe" });
451
+ * ```
452
+ *
453
+ * @example
454
+ * ```ts twoslash
455
+ * await db.insert(table).values([
456
+ * { id: 10, name: "joe" },
457
+ * { id: 3, name: "rob" }
458
+ * ]);
459
+ * ```
460
+ *
461
+ * @example
462
+ * ```ts twoslash
463
+ * await db.insert(table).values({ id: 10, name: "joe" }).onConflictDoNothing();
464
+ * ```
465
+ *
466
+ * @example
467
+ * ```ts twoslash
468
+ * await db
469
+ * .insert(table)
470
+ * .values({ id: 10, name: "joe" })
471
+ * .onConflictDoUpdate((row) => ({ age: row.age + 3 }));
472
+ * ```
473
+ *
474
+ * @param table - The table to insert into.
475
+ */
476
+ insert: Insert;
477
+ /**
478
+ * Update a row
479
+ *
480
+ * - Docs: https://ponder.sh/docs/indexing/write-to-the-database#update
481
+ *
482
+ * @example
483
+ * ```ts twoslash
484
+ * await db
485
+ * .update(table, { id: 10 })
486
+ * .set({ age: 19 });
487
+ * ```
488
+ *
489
+ * @example
490
+ * ```ts twoslash
491
+ * await db
492
+ * .update(table, { id: 10 })
493
+ * .set((row) => ({ age: row.age + 3 }));
494
+ * ```
495
+ *
496
+ * @param table - The table to select from.
497
+ * @param key - The primary key.
498
+ */
499
+ update: Update;
500
+ /**
501
+ * Delete a row
502
+ *
503
+ * - Docs: https://ponder.sh/docs/indexing/write-to-the-database#delete
504
+ *
505
+ * @example
506
+ * ```ts twoslash
507
+ * const deleted = await db.delete(table, { id: 10 });
508
+ * ```
509
+ *
510
+ * @param table - The table to select from.
511
+ * @param key - The primary key.
512
+ * @returns `true` if the row existed.
513
+ */
514
+ delete: Delete;
515
+ /**
516
+ * Access the raw drizzle object
517
+ *
518
+ * - Docs: https://ponder.sh/docs/indexing/write-to-the-database#raw-sql
519
+ */
520
+ sql: Prettify<Omit<Drizzle<schema>, "refreshMaterializedView" | "_">>;
521
+ };
522
+ type InferPrimaryKey<table extends Table, columns extends Record<string, Column$1> = table["_"]["columns"], columnNames extends keyof columns & string = keyof columns & string> = columnNames extends columnNames ? columns[columnNames]["_"]["isPrimaryKey"] extends true ? columnNames : never : never;
523
+ type Key<table extends Table, compositePrimaryKey extends keyof table["_"]["columns"] = InferCompositePrimaryKey<table>, primaryKey extends keyof table["_"]["columns"] = [
524
+ compositePrimaryKey
525
+ ] extends [never] ? InferPrimaryKey<table> : compositePrimaryKey> = {
526
+ [columnName in primaryKey]: GetColumnData<table["_"]["columns"][columnName]>;
527
+ };
528
+ type InferCompositePrimaryKey<table extends OnchainTable<TableConfig & {
529
+ extra: PgTableExtraConfig | undefined;
530
+ }>, extra extends PgTableExtraConfig | undefined = table["_"]["config"]["extra"], builders = extra[keyof extra]> = builders extends builders ? builders extends PrimaryKeyBuilder ? builders["columnNames"] : never : never;
531
+ type Find = <table extends Table>(table: table extends {
532
+ [onchain]: true;
533
+ } ? table : PonderTypeError<`db.find() can only be used with onchain tables, and '${table["_"]["name"]}' is an offchain table.`>, key: Key<table>) => Promise<InferSelectModel<table> | null>;
534
+ type Insert = <table extends Table, insertModel = InferInsertModel<table>, selectModel = InferSelectModel<table>, updateModel = Prettify<Omit<insertModel, keyof Key<table>>>, updateFn = (row: selectModel) => Partial<updateModel>>(table: table extends {
535
+ [onchain]: true;
536
+ } ? table : PonderTypeError<`Indexing functions can only write to onchain tables, and '${table["_"]["name"]}' is an offchain table.`>) => {
537
+ /**
538
+ * Create new rows
539
+ *
540
+ * - Docs: https://ponder.sh/docs/indexing/write-to-the-database#insert
541
+ *
542
+ * @example
543
+ * ```ts twoslash
544
+ * await db.insert(table).values({ id: 10, name: "joe" });
545
+ * ```
546
+ *
547
+ * @example
548
+ * ```ts twoslash
549
+ * await db.insert(table).values([
550
+ * { id: 10, name: "joe" },
551
+ * { id: 3, name: "rob" }
552
+ * ]);
553
+ * ```
554
+ * @param table - The table to insert into.
555
+ */
556
+ values: <values extends insertModel | insertModel[]>(values: values) => Promise<values extends unknown[] ? selectModel[] : selectModel> & {
557
+ /**
558
+ * Create new rows, cancelling the insert if there is a conflict
559
+ *
560
+ * - Docs: https://ponder.sh/docs/indexing/write-to-the-database#upsert--conflict-resolution
561
+ * @example
562
+ * ```ts twoslash
563
+ * await db.insert(table).values({ id: 10, name: "joe" }).onConflictDoNothing();
564
+ * ```
565
+ * @param table - The table to insert into.
566
+ */
567
+ onConflictDoNothing: () => Promise<values extends unknown[] ? (selectModel | null)[] : selectModel | null>;
568
+ /**
569
+ * Create new rows, updating the row if there is a conflict
570
+ *
571
+ * - Docs: https://ponder.sh/docs/indexing/write-to-the-database#upsert--conflict-resolution
572
+ *
573
+ * @example
574
+ * ```ts twoslash
575
+ * await db
576
+ * .insert(table)
577
+ * .values({ id: 10, name: "joe" })
578
+ * .onConflictDoUpdate({ age: 24 });
579
+ * ```
580
+ *
581
+ * @example
582
+ * ```ts twoslash
583
+ * await db
584
+ * .insert(table)
585
+ * .values({ id: 10, name: "joe" })
586
+ * .onConflictDoUpdate((row) => ({ age: row.age + 3 }));
587
+ * ```
588
+ *
589
+ * @param table - The table to insert into.
590
+ */
591
+ onConflictDoUpdate: (values: Partial<updateModel> | updateFn) => Promise<values extends unknown[] ? selectModel[] : selectModel>;
592
+ };
593
+ };
594
+ type Update = <table extends Table, insertModel = InferInsertModel<table>, selectModel = InferSelectModel<table>, insertValues = Prettify<Omit<insertModel, keyof Key<table>>>, updateFn = (row: selectModel) => Partial<insertModel>>(table: table extends {
595
+ [onchain]: true;
596
+ } ? table : PonderTypeError<`Indexing functions can only write to onchain tables, and '${table["_"]["name"]}' is an offchain table.`>, key: Key<table>) => {
597
+ /**
598
+ * Update a row
599
+ *
600
+ * - Docs: https://ponder.sh/docs/indexing/write-to-the-database#update
601
+ *
602
+ * @example
603
+ * ```ts twoslash
604
+ * await db
605
+ * .update(table, { id: 10 })
606
+ * .set({ age: 19 });
607
+ * ```
608
+ *
609
+ * @example
610
+ * ```ts twoslash
611
+ * await db
612
+ * .update(table, { id: 10 })
613
+ * .set((row) => ({ age: row.age + 3 }));
614
+ * ```
615
+ *
616
+ * @param table - The table to select from.
617
+ * @param key - The primary key.
618
+ */
619
+ set: (values: Partial<insertValues> | updateFn) => Promise<selectModel>;
620
+ };
621
+ type Delete = <table extends Table>(table: table extends {
622
+ [onchain]: true;
623
+ } ? table : PonderTypeError<`Indexing functions can only write to onchain tables, and '${table["_"]["name"]}' is an offchain table.`>, key: Key<table>) => Promise<boolean>;
624
+
625
+ export type { Block as B, Db as D, FragmentId as F, IndexingBuild as I, Log as L, ReadonlyDrizzle as R, Schema as S, TransactionReceipt as T, Transaction as a, Transfer as b, Trace as c, Drizzle as d, SchemaBuild as e };