@apibara/plugin-mongo 2.1.0-beta.14 → 2.1.0-beta.16

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
@@ -44,7 +44,9 @@ async function cleanupStorage(db, session, collections) {
44
44
  try {
45
45
  await db.collection(collection).deleteMany({}, { session });
46
46
  } catch (error) {
47
- throw new Error(`Failed to clean up collection ${collection}: ${error}`);
47
+ throw new Error(`Failed to clean up collection ${collection}`, {
48
+ cause: error
49
+ });
48
50
  }
49
51
  }
50
52
  }
@@ -57,22 +59,22 @@ class MongoStorageError extends Error {
57
59
  }
58
60
  async function withTransaction(client, cb) {
59
61
  return await client.withSession(async (session) => {
60
- return await session.withTransaction(async (session2) => {
61
- return await cb(session2);
62
- });
62
+ return await session.withTransaction(
63
+ async (session2) => {
64
+ return await cb(session2);
65
+ },
66
+ {
67
+ retryWrites: false
68
+ }
69
+ );
63
70
  });
64
71
  }
65
72
 
66
73
  const checkpointCollectionName = "checkpoints";
67
74
  const filterCollectionName = "filters";
68
75
  async function initializePersistentState(db, session) {
69
- const checkpoint = await db.createCollection(
70
- checkpointCollectionName,
71
- { session }
72
- );
73
- const filter = await db.createCollection(filterCollectionName, {
74
- session
75
- });
76
+ const checkpoint = db.collection(checkpointCollectionName);
77
+ const filter = db.collection(filterCollectionName);
76
78
  await checkpoint.createIndex({ id: 1 }, { session });
77
79
  await filter.createIndex({ id: 1, fromBlock: 1 }, { session });
78
80
  }
package/dist/index.mjs CHANGED
@@ -42,7 +42,9 @@ async function cleanupStorage(db, session, collections) {
42
42
  try {
43
43
  await db.collection(collection).deleteMany({}, { session });
44
44
  } catch (error) {
45
- throw new Error(`Failed to clean up collection ${collection}: ${error}`);
45
+ throw new Error(`Failed to clean up collection ${collection}`, {
46
+ cause: error
47
+ });
46
48
  }
47
49
  }
48
50
  }
@@ -55,22 +57,22 @@ class MongoStorageError extends Error {
55
57
  }
56
58
  async function withTransaction(client, cb) {
57
59
  return await client.withSession(async (session) => {
58
- return await session.withTransaction(async (session2) => {
59
- return await cb(session2);
60
- });
60
+ return await session.withTransaction(
61
+ async (session2) => {
62
+ return await cb(session2);
63
+ },
64
+ {
65
+ retryWrites: false
66
+ }
67
+ );
61
68
  });
62
69
  }
63
70
 
64
71
  const checkpointCollectionName = "checkpoints";
65
72
  const filterCollectionName = "filters";
66
73
  async function initializePersistentState(db, session) {
67
- const checkpoint = await db.createCollection(
68
- checkpointCollectionName,
69
- { session }
70
- );
71
- const filter = await db.createCollection(filterCollectionName, {
72
- session
73
- });
74
+ const checkpoint = db.collection(checkpointCollectionName);
75
+ const filter = db.collection(filterCollectionName);
74
76
  await checkpoint.createIndex({ id: 1 }, { session });
75
77
  await filter.createIndex({ id: 1, fromBlock: 1 }, { session });
76
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apibara/plugin-mongo",
3
- "version": "2.1.0-beta.14",
3
+ "version": "2.1.0-beta.16",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -35,7 +35,7 @@
35
35
  "mongodb": "^6.12.0"
36
36
  },
37
37
  "dependencies": {
38
- "@apibara/indexer": "2.1.0-beta.14",
39
- "@apibara/protocol": "2.1.0-beta.14"
38
+ "@apibara/indexer": "2.1.0-beta.16",
39
+ "@apibara/protocol": "2.1.0-beta.16"
40
40
  }
41
41
  }
package/src/mongo.ts CHANGED
@@ -60,7 +60,9 @@ export async function cleanupStorage(
60
60
  // Delete all documents in the collection
61
61
  await db.collection(collection).deleteMany({}, { session });
62
62
  } catch (error) {
63
- throw new Error(`Failed to clean up collection ${collection}: ${error}`);
63
+ throw new Error(`Failed to clean up collection ${collection}`, {
64
+ cause: error,
65
+ });
64
66
  }
65
67
  }
66
68
  }
@@ -22,13 +22,8 @@ export async function initializePersistentState(
22
22
  db: Db,
23
23
  session: ClientSession,
24
24
  ) {
25
- const checkpoint = await db.createCollection<CheckpointSchema>(
26
- checkpointCollectionName,
27
- { session },
28
- );
29
- const filter = await db.createCollection<FilterSchema>(filterCollectionName, {
30
- session,
31
- });
25
+ const checkpoint = db.collection<CheckpointSchema>(checkpointCollectionName);
26
+ const filter = db.collection<FilterSchema>(filterCollectionName);
32
27
 
33
28
  await checkpoint.createIndex({ id: 1 }, { session });
34
29
  await filter.createIndex({ id: 1, fromBlock: 1 }, { session });
package/src/utils.ts CHANGED
@@ -12,8 +12,13 @@ export async function withTransaction<T>(
12
12
  cb: (session: ClientSession) => Promise<T>,
13
13
  ) {
14
14
  return await client.withSession(async (session) => {
15
- return await session.withTransaction(async (session) => {
16
- return await cb(session);
17
- });
15
+ return await session.withTransaction(
16
+ async (session) => {
17
+ return await cb(session);
18
+ },
19
+ {
20
+ retryWrites: false,
21
+ },
22
+ );
18
23
  });
19
24
  }