@apibara/plugin-drizzle 2.0.0-beta.38 → 2.0.0-beta.40

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
@@ -4,6 +4,7 @@ const indexer = require('@apibara/indexer');
4
4
  const plugins = require('@apibara/indexer/plugins');
5
5
  const internal = require('@apibara/indexer/internal');
6
6
  const plugins$1 = require('@apibara/indexer/internal/plugins');
7
+ const protocol = require('@apibara/protocol');
7
8
  const drizzleOrm = require('drizzle-orm');
8
9
  const pgCore = require('drizzle-orm/pg-core');
9
10
 
@@ -41,7 +42,7 @@ const SCHEMA_VERSION_TABLE_NAME = "__indexer_schema_version";
41
42
  const checkpoints = pgCore.pgTable(CHECKPOINTS_TABLE_NAME, {
42
43
  id: pgCore.text("id").notNull().primaryKey(),
43
44
  orderKey: pgCore.integer("order_key").notNull(),
44
- uniqueKey: pgCore.text("unique_key").$type().notNull().default(void 0)
45
+ uniqueKey: pgCore.text("unique_key")
45
46
  });
46
47
  const filters = pgCore.pgTable(
47
48
  FILTERS_TABLE_NAME,
@@ -87,7 +88,7 @@ async function initializePersistentState(tx) {
87
88
  CREATE TABLE IF NOT EXISTS ${CHECKPOINTS_TABLE_NAME} (
88
89
  id TEXT PRIMARY KEY,
89
90
  order_key INTEGER NOT NULL,
90
- unique_key TEXT NOT NULL DEFAULT ''
91
+ unique_key TEXT
91
92
  );
92
93
  `);
93
94
  await tx.execute(`
@@ -163,10 +164,10 @@ async function getState(props) {
163
164
  const { tx, indexerId } = props;
164
165
  try {
165
166
  const checkpointRows = await tx.select().from(checkpoints).where(drizzleOrm.eq(checkpoints.id, indexerId));
166
- const cursor = checkpointRows[0] ? {
167
+ const cursor = checkpointRows[0] ? protocol.normalizeCursor({
167
168
  orderKey: BigInt(checkpointRows[0].orderKey),
168
169
  uniqueKey: checkpointRows[0].uniqueKey
169
- } : void 0;
170
+ }) : void 0;
170
171
  const filterRows = await tx.select().from(filters).where(drizzleOrm.and(drizzleOrm.eq(filters.id, indexerId), drizzleOrm.isNull(filters.toBlock)));
171
172
  const filter = filterRows[0] ? deserialize(filterRows[0].filter) : void 0;
172
173
  return { cursor, filter };
package/dist/index.mjs CHANGED
@@ -2,6 +2,7 @@ import { useIndexerContext } from '@apibara/indexer';
2
2
  import { defineIndexerPlugin } from '@apibara/indexer/plugins';
3
3
  import { generateIndexerId } from '@apibara/indexer/internal';
4
4
  import { useInternalContext } from '@apibara/indexer/internal/plugins';
5
+ import { normalizeCursor } from '@apibara/protocol';
5
6
  import { eq, and, isNull, gt, lt, sql } from 'drizzle-orm';
6
7
  import { pgTable, text, integer, primaryKey, serial, char, jsonb } from 'drizzle-orm/pg-core';
7
8
 
@@ -39,7 +40,7 @@ const SCHEMA_VERSION_TABLE_NAME = "__indexer_schema_version";
39
40
  const checkpoints = pgTable(CHECKPOINTS_TABLE_NAME, {
40
41
  id: text("id").notNull().primaryKey(),
41
42
  orderKey: integer("order_key").notNull(),
42
- uniqueKey: text("unique_key").$type().notNull().default(void 0)
43
+ uniqueKey: text("unique_key")
43
44
  });
44
45
  const filters = pgTable(
45
46
  FILTERS_TABLE_NAME,
@@ -85,7 +86,7 @@ async function initializePersistentState(tx) {
85
86
  CREATE TABLE IF NOT EXISTS ${CHECKPOINTS_TABLE_NAME} (
86
87
  id TEXT PRIMARY KEY,
87
88
  order_key INTEGER NOT NULL,
88
- unique_key TEXT NOT NULL DEFAULT ''
89
+ unique_key TEXT
89
90
  );
90
91
  `);
91
92
  await tx.execute(`
@@ -161,10 +162,10 @@ async function getState(props) {
161
162
  const { tx, indexerId } = props;
162
163
  try {
163
164
  const checkpointRows = await tx.select().from(checkpoints).where(eq(checkpoints.id, indexerId));
164
- const cursor = checkpointRows[0] ? {
165
+ const cursor = checkpointRows[0] ? normalizeCursor({
165
166
  orderKey: BigInt(checkpointRows[0].orderKey),
166
167
  uniqueKey: checkpointRows[0].uniqueKey
167
- } : void 0;
168
+ }) : void 0;
168
169
  const filterRows = await tx.select().from(filters).where(and(eq(filters.id, indexerId), isNull(filters.toBlock)));
169
170
  const filter = filterRows[0] ? deserialize(filterRows[0].filter) : void 0;
170
171
  return { cursor, filter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apibara/plugin-drizzle",
3
- "version": "2.0.0-beta.38",
3
+ "version": "2.0.0-beta.40",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -39,8 +39,8 @@
39
39
  "vitest": "^1.6.0"
40
40
  },
41
41
  "dependencies": {
42
- "@apibara/indexer": "2.0.0-beta.39",
43
- "@apibara/protocol": "2.0.0-beta.39",
42
+ "@apibara/indexer": "2.0.0-beta.40",
43
+ "@apibara/protocol": "2.0.0-beta.40",
44
44
  "postgres-range": "^1.1.4"
45
45
  }
46
46
  }
@@ -1,4 +1,4 @@
1
- import type { Cursor } from "@apibara/protocol";
1
+ import { type Cursor, normalizeCursor } from "@apibara/protocol";
2
2
  import { and, eq, gt, isNull, lt } from "drizzle-orm";
3
3
  import type {
4
4
  ExtractTablesWithRelations,
@@ -15,10 +15,7 @@ const SCHEMA_VERSION_TABLE_NAME = "__indexer_schema_version";
15
15
  export const checkpoints = pgTable(CHECKPOINTS_TABLE_NAME, {
16
16
  id: text("id").notNull().primaryKey(),
17
17
  orderKey: integer("order_key").notNull(),
18
- uniqueKey: text("unique_key")
19
- .$type<`0x${string}` | undefined>()
20
- .notNull()
21
- .default(undefined),
18
+ uniqueKey: text("unique_key"),
22
19
  });
23
20
 
24
21
  export const filters = pgTable(
@@ -87,7 +84,7 @@ export async function initializePersistentState<
87
84
  CREATE TABLE IF NOT EXISTS ${CHECKPOINTS_TABLE_NAME} (
88
85
  id TEXT PRIMARY KEY,
89
86
  order_key INTEGER NOT NULL,
90
- unique_key TEXT NOT NULL DEFAULT ''
87
+ unique_key TEXT
91
88
  );
92
89
  `);
93
90
 
@@ -212,10 +209,10 @@ export async function getState<
212
209
  .where(eq(checkpoints.id, indexerId));
213
210
 
214
211
  const cursor = checkpointRows[0]
215
- ? {
212
+ ? normalizeCursor({
216
213
  orderKey: BigInt(checkpointRows[0].orderKey),
217
214
  uniqueKey: checkpointRows[0].uniqueKey,
218
- }
215
+ })
219
216
  : undefined;
220
217
 
221
218
  const filterRows = await tx