@secondlayer/subgraphs 3.26.0 → 3.26.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.
- package/dist/src/index.js +29 -9
- package/dist/src/index.js.map +3 -3
- package/dist/src/runtime/block-processor.js +29 -9
- package/dist/src/runtime/block-processor.js.map +3 -3
- package/dist/src/runtime/catchup.js +29 -9
- package/dist/src/runtime/catchup.js.map +3 -3
- package/dist/src/runtime/context.d.ts +20 -0
- package/dist/src/runtime/context.js +29 -9
- package/dist/src/runtime/context.js.map +3 -3
- package/dist/src/runtime/processor.js +29 -9
- package/dist/src/runtime/processor.js.map +3 -3
- package/dist/src/runtime/reindex.js +29 -9
- package/dist/src/runtime/reindex.js.map +3 -3
- package/dist/src/runtime/reorg.js +29 -9
- package/dist/src/runtime/reorg.js.map +3 -3
- package/dist/src/runtime/runner.d.ts +20 -0
- package/dist/src/service.js +29 -9
- package/dist/src/service.js.map +3 -3
- package/dist/src/testing/index.js +29 -9
- package/dist/src/testing/index.js.map +3 -3
- package/package.json +1 -1
|
@@ -605,14 +605,10 @@ class SubgraphContext {
|
|
|
605
605
|
this.ops.length = 0;
|
|
606
606
|
const statements = this.buildStatements(opsToFlush);
|
|
607
607
|
if ("isTransaction" in this.db) {
|
|
608
|
-
|
|
609
|
-
await sql.raw(stmt).execute(this.db);
|
|
610
|
-
}
|
|
608
|
+
await this.execStatements(this.db, statements);
|
|
611
609
|
} else {
|
|
612
610
|
await this.db.transaction().execute(async (tx) => {
|
|
613
|
-
|
|
614
|
-
await sql.raw(stmt).execute(tx);
|
|
615
|
-
}
|
|
611
|
+
await this.execStatements(tx, statements);
|
|
616
612
|
});
|
|
617
613
|
}
|
|
618
614
|
const writes = opsToFlush.map((op, rowIndex) => {
|
|
@@ -631,6 +627,25 @@ class SubgraphContext {
|
|
|
631
627
|
});
|
|
632
628
|
return { count: opsToFlush.length, writes };
|
|
633
629
|
}
|
|
630
|
+
async execStatements(executor, statements) {
|
|
631
|
+
const affected = (r) => r.numAffectedRows ?? 0n;
|
|
632
|
+
for (const stmt of statements) {
|
|
633
|
+
if (typeof stmt === "string") {
|
|
634
|
+
await sql.raw(stmt).execute(executor);
|
|
635
|
+
continue;
|
|
636
|
+
}
|
|
637
|
+
const updated = await sql.raw(stmt.update).execute(executor);
|
|
638
|
+
if (affected(updated) > 0n)
|
|
639
|
+
continue;
|
|
640
|
+
const inserted = await sql.raw(stmt.insert).execute(executor);
|
|
641
|
+
if (affected(inserted) > 0n)
|
|
642
|
+
continue;
|
|
643
|
+
const retried = await sql.raw(stmt.update).execute(executor);
|
|
644
|
+
if (affected(retried) === 0n) {
|
|
645
|
+
throw new Error(`increment could not be applied to ${this.pgSchemaName}.${stmt.table} where ${stmt.keyPred}: row neither updated nor inserted`);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
634
649
|
prepareInsert(op) {
|
|
635
650
|
const upsertKeys = op.data._upsert_keys;
|
|
636
651
|
const data = { ...op.data };
|
|
@@ -710,7 +725,6 @@ class SubgraphContext {
|
|
|
710
725
|
for (const r of batch.rows.values()) {
|
|
711
726
|
const keyPred = batch.keyCols.map((k) => `"${k}" = ${escapeLiteral(r.keys[k])}`).join(" AND ");
|
|
712
727
|
const updSet = batch.deltaCols.map((c) => `"${c}" = COALESCE("${c}", 0) + (${String(r.deltas[c] ?? 0n)})`).join(", ");
|
|
713
|
-
statements.push(`UPDATE ${qualifiedTable} SET ${updSet} WHERE ${keyPred}`);
|
|
714
728
|
const insertVals = [
|
|
715
729
|
...batch.keyCols.map((k) => escapeLiteral(r.keys[k])),
|
|
716
730
|
...batch.deltaCols.map((c) => String(r.deltas[c] ?? 0n)),
|
|
@@ -718,7 +732,13 @@ class SubgraphContext {
|
|
|
718
732
|
escapeLiteral(r.meta.txId),
|
|
719
733
|
"NOW()"
|
|
720
734
|
];
|
|
721
|
-
statements.push(
|
|
735
|
+
statements.push({
|
|
736
|
+
kind: "increment",
|
|
737
|
+
table: batch.table,
|
|
738
|
+
keyPred,
|
|
739
|
+
update: `UPDATE ${qualifiedTable} SET ${updSet} WHERE ${keyPred}`,
|
|
740
|
+
insert: `INSERT INTO ${qualifiedTable} (${cols.map((c) => `"${c}"`).join(", ")}) ` + `SELECT ${insertVals.join(", ")} ` + `WHERE NOT EXISTS (SELECT 1 FROM ${qualifiedTable} WHERE ${keyPred})`
|
|
741
|
+
});
|
|
722
742
|
}
|
|
723
743
|
incBatch = null;
|
|
724
744
|
incBatchKey = "";
|
|
@@ -3421,5 +3441,5 @@ export {
|
|
|
3421
3441
|
handleSubgraphReorg
|
|
3422
3442
|
};
|
|
3423
3443
|
|
|
3424
|
-
//# debugId=
|
|
3444
|
+
//# debugId=9D5D02929028624564756E2164756E21
|
|
3425
3445
|
//# sourceMappingURL=reorg.js.map
|