@apibara/plugin-drizzle 2.1.0-beta.11 → 2.1.0-beta.13

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/index.cjs CHANGED
@@ -552,6 +552,7 @@ function drizzleStorage({
552
552
  let tableNames = [];
553
553
  let indexerId = "";
554
554
  const alwaysReindex = process.env["APIBARA_ALWAYS_REINDEX"] === "true";
555
+ let prevFinality;
555
556
  try {
556
557
  tableNames = Object.values(schema ?? db._.schema ?? {}).map(
557
558
  (table) => table.dbName
@@ -683,12 +684,15 @@ function drizzleStorage({
683
684
  indexer$1.hooks.hook("handler:middleware", async ({ use }) => {
684
685
  use(async (context, next) => {
685
686
  try {
686
- const { endCursor, finality } = context;
687
+ const { endCursor, finality, cursor } = context;
687
688
  if (!endCursor) {
688
689
  throw new DrizzleStorageError("End Cursor is undefined");
689
690
  }
690
691
  await withTransaction(db, async (tx) => {
691
692
  context[constants.DRIZZLE_PROPERTY] = { db: tx };
693
+ if (prevFinality === "pending") {
694
+ await invalidate(tx, cursor, idColumn, indexerId);
695
+ }
692
696
  if (finality !== "finalized") {
693
697
  await registerTriggers(
694
698
  tx,
@@ -700,13 +704,14 @@ function drizzleStorage({
700
704
  }
701
705
  await next();
702
706
  delete context[constants.DRIZZLE_PROPERTY];
703
- if (enablePersistence) {
707
+ if (enablePersistence && finality !== "pending") {
704
708
  await persistState({
705
709
  tx,
706
710
  endCursor,
707
711
  indexerId
708
712
  });
709
713
  }
714
+ prevFinality = finality;
710
715
  });
711
716
  if (finality !== "finalized") {
712
717
  await removeTriggers(db, tableNames, indexerId);
package/dist/index.mjs CHANGED
@@ -546,6 +546,7 @@ function drizzleStorage({
546
546
  let tableNames = [];
547
547
  let indexerId = "";
548
548
  const alwaysReindex = process.env["APIBARA_ALWAYS_REINDEX"] === "true";
549
+ let prevFinality;
549
550
  try {
550
551
  tableNames = Object.values(schema ?? db._.schema ?? {}).map(
551
552
  (table) => table.dbName
@@ -677,12 +678,15 @@ function drizzleStorage({
677
678
  indexer.hooks.hook("handler:middleware", async ({ use }) => {
678
679
  use(async (context, next) => {
679
680
  try {
680
- const { endCursor, finality } = context;
681
+ const { endCursor, finality, cursor } = context;
681
682
  if (!endCursor) {
682
683
  throw new DrizzleStorageError("End Cursor is undefined");
683
684
  }
684
685
  await withTransaction(db, async (tx) => {
685
686
  context[DRIZZLE_PROPERTY] = { db: tx };
687
+ if (prevFinality === "pending") {
688
+ await invalidate(tx, cursor, idColumn, indexerId);
689
+ }
686
690
  if (finality !== "finalized") {
687
691
  await registerTriggers(
688
692
  tx,
@@ -694,13 +698,14 @@ function drizzleStorage({
694
698
  }
695
699
  await next();
696
700
  delete context[DRIZZLE_PROPERTY];
697
- if (enablePersistence) {
701
+ if (enablePersistence && finality !== "pending") {
698
702
  await persistState({
699
703
  tx,
700
704
  endCursor,
701
705
  indexerId
702
706
  });
703
707
  }
708
+ prevFinality = finality;
704
709
  });
705
710
  if (finality !== "finalized") {
706
711
  await removeTriggers(db, tableNames, indexerId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apibara/plugin-drizzle",
3
- "version": "2.1.0-beta.11",
3
+ "version": "2.1.0-beta.13",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -45,8 +45,8 @@
45
45
  "vitest": "^1.6.0"
46
46
  },
47
47
  "dependencies": {
48
- "@apibara/indexer": "2.1.0-beta.11",
49
- "@apibara/protocol": "2.1.0-beta.11",
48
+ "@apibara/indexer": "2.1.0-beta.13",
49
+ "@apibara/protocol": "2.1.0-beta.13",
50
50
  "postgres-range": "^1.1.4"
51
51
  }
52
52
  }
package/src/index.ts CHANGED
@@ -128,6 +128,7 @@ export function drizzleStorage<
128
128
  let tableNames: string[] = [];
129
129
  let indexerId = "";
130
130
  const alwaysReindex = process.env["APIBARA_ALWAYS_REINDEX"] === "true";
131
+ let prevFinality: DataFinality | undefined;
131
132
 
132
133
  try {
133
134
  tableNames = Object.values((schema as TSchema) ?? db._.schema ?? {}).map(
@@ -299,7 +300,8 @@ export function drizzleStorage<
299
300
  indexer.hooks.hook("handler:middleware", async ({ use }) => {
300
301
  use(async (context, next) => {
301
302
  try {
302
- const { endCursor, finality } = context as {
303
+ const { endCursor, finality, cursor } = context as {
304
+ cursor: Cursor;
303
305
  endCursor: Cursor;
304
306
  finality: DataFinality;
305
307
  };
@@ -315,6 +317,11 @@ export function drizzleStorage<
315
317
  TSchema
316
318
  >;
317
319
 
320
+ if (prevFinality === "pending") {
321
+ // invalidate if previous block's finality was "pending"
322
+ await invalidate(tx, cursor, idColumn, indexerId);
323
+ }
324
+
318
325
  if (finality !== "finalized") {
319
326
  await registerTriggers(
320
327
  tx,
@@ -328,13 +335,15 @@ export function drizzleStorage<
328
335
  await next();
329
336
  delete context[DRIZZLE_PROPERTY];
330
337
 
331
- if (enablePersistence) {
338
+ if (enablePersistence && finality !== "pending") {
332
339
  await persistState({
333
340
  tx,
334
341
  endCursor,
335
342
  indexerId,
336
343
  });
337
344
  }
345
+
346
+ prevFinality = finality;
338
347
  });
339
348
 
340
349
  if (finality !== "finalized") {