@payloadcms/db-mongodb 3.65.0-canary.7 → 3.65.0-canary.8

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.
@@ -1 +1 @@
1
- {"version":3,"file":"commitTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/commitTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAIhD,eAAO,MAAM,iBAAiB,EAAE,iBAmB/B,CAAA"}
1
+ {"version":3,"file":"commitTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/commitTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAIhD,eAAO,MAAM,iBAAiB,EAAE,iBA4B/B,CAAA"}
@@ -1,17 +1,23 @@
1
- export const commitTransaction = async function commitTransaction(id) {
2
- if (id instanceof Promise) {
1
+ export const commitTransaction = async function commitTransaction(incomingID = '') {
2
+ const transactionID = incomingID instanceof Promise ? await incomingID : incomingID;
3
+ if (!this.sessions[transactionID]) {
3
4
  return;
4
5
  }
5
- if (!this.sessions[id]?.inTransaction()) {
6
+ if (!this.sessions[transactionID]?.inTransaction()) {
7
+ // Clean up the orphaned session reference
8
+ delete this.sessions[transactionID];
6
9
  return;
7
10
  }
8
- await this.sessions[id].commitTransaction();
11
+ const session = this.sessions[transactionID];
12
+ // Delete from registry FIRST to prevent race conditions
13
+ // This ensures other operations can't retrieve this session while we're ending it
14
+ delete this.sessions[transactionID];
15
+ await session.commitTransaction();
9
16
  try {
10
- await this.sessions[id].endSession();
17
+ await session.endSession();
11
18
  } catch (_) {
12
19
  // ending sessions is only best effort and won't impact anything if it fails since the transaction was committed
13
20
  }
14
- delete this.sessions[id];
15
21
  };
16
22
 
17
23
  //# sourceMappingURL=commitTransaction.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { CommitTransaction } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const commitTransaction: CommitTransaction = async function commitTransaction(\n this: MongooseAdapter,\n id,\n) {\n if (id instanceof Promise) {\n return\n }\n\n if (!this.sessions[id]?.inTransaction()) {\n return\n }\n\n await this.sessions[id].commitTransaction()\n try {\n await this.sessions[id].endSession()\n } catch (_) {\n // ending sessions is only best effort and won't impact anything if it fails since the transaction was committed\n }\n delete this.sessions[id]\n}\n"],"names":["commitTransaction","id","Promise","sessions","inTransaction","endSession","_"],"mappings":"AAIA,OAAO,MAAMA,oBAAuC,eAAeA,kBAEjEC,EAAE;IAEF,IAAIA,cAAcC,SAAS;QACzB;IACF;IAEA,IAAI,CAAC,IAAI,CAACC,QAAQ,CAACF,GAAG,EAAEG,iBAAiB;QACvC;IACF;IAEA,MAAM,IAAI,CAACD,QAAQ,CAACF,GAAG,CAACD,iBAAiB;IACzC,IAAI;QACF,MAAM,IAAI,CAACG,QAAQ,CAACF,GAAG,CAACI,UAAU;IACpC,EAAE,OAAOC,GAAG;IACV,gHAAgH;IAClH;IACA,OAAO,IAAI,CAACH,QAAQ,CAACF,GAAG;AAC1B,EAAC"}
1
+ {"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { CommitTransaction } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const commitTransaction: CommitTransaction = async function commitTransaction(\n this: MongooseAdapter,\n incomingID = '',\n) {\n const transactionID = incomingID instanceof Promise ? await incomingID : incomingID\n\n if (!this.sessions[transactionID]) {\n return\n }\n\n if (!this.sessions[transactionID]?.inTransaction()) {\n // Clean up the orphaned session reference\n delete this.sessions[transactionID]\n return\n }\n\n const session = this.sessions[transactionID]\n\n // Delete from registry FIRST to prevent race conditions\n // This ensures other operations can't retrieve this session while we're ending it\n delete this.sessions[transactionID]\n\n await session.commitTransaction()\n try {\n await session.endSession()\n } catch (_) {\n // ending sessions is only best effort and won't impact anything if it fails since the transaction was committed\n }\n}\n"],"names":["commitTransaction","incomingID","transactionID","Promise","sessions","inTransaction","session","endSession","_"],"mappings":"AAIA,OAAO,MAAMA,oBAAuC,eAAeA,kBAEjEC,aAAa,EAAE;IAEf,MAAMC,gBAAgBD,sBAAsBE,UAAU,MAAMF,aAAaA;IAEzE,IAAI,CAAC,IAAI,CAACG,QAAQ,CAACF,cAAc,EAAE;QACjC;IACF;IAEA,IAAI,CAAC,IAAI,CAACE,QAAQ,CAACF,cAAc,EAAEG,iBAAiB;QAClD,0CAA0C;QAC1C,OAAO,IAAI,CAACD,QAAQ,CAACF,cAAc;QACnC;IACF;IAEA,MAAMI,UAAU,IAAI,CAACF,QAAQ,CAACF,cAAc;IAE5C,wDAAwD;IACxD,kFAAkF;IAClF,OAAO,IAAI,CAACE,QAAQ,CAACF,cAAc;IAEnC,MAAMI,QAAQN,iBAAiB;IAC/B,IAAI;QACF,MAAMM,QAAQC,UAAU;IAC1B,EAAE,OAAOC,GAAG;IACV,gHAAgH;IAClH;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"rollbackTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/rollbackTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAIlD,eAAO,MAAM,mBAAmB,EAAE,mBAiCjC,CAAA"}
1
+ {"version":3,"file":"rollbackTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/rollbackTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAIlD,eAAO,MAAM,mBAAmB,EAAE,mBAgCjC,CAAA"}
@@ -1,10 +1,5 @@
1
1
  export const rollbackTransaction = async function rollbackTransaction(incomingID = '') {
2
- let transactionID;
3
- if (incomingID instanceof Promise) {
4
- transactionID = await incomingID;
5
- } else {
6
- transactionID = incomingID;
7
- }
2
+ const transactionID = incomingID instanceof Promise ? await incomingID : incomingID;
8
3
  // if multiple operations are using the same transaction, the first will flow through and delete the session.
9
4
  // subsequent calls should be ignored.
10
5
  if (!this.sessions[transactionID]) {
@@ -16,14 +11,17 @@ export const rollbackTransaction = async function rollbackTransaction(incomingID
16
11
  delete this.sessions[transactionID];
17
12
  return;
18
13
  }
14
+ const session = this.sessions[transactionID];
15
+ // Delete from registry FIRST to prevent race conditions
16
+ // This ensures other operations can't retrieve this session while we're aborting it
17
+ delete this.sessions[transactionID];
19
18
  // the first call for rollback should be aborted and deleted causing any other operations with the same transaction to fail
20
19
  try {
21
- await this.sessions[transactionID]?.abortTransaction();
22
- await this.sessions[transactionID]?.endSession();
23
- } catch (error) {
20
+ await session.abortTransaction();
21
+ await session.endSession();
22
+ } catch (_error) {
24
23
  // ignore the error as it is likely a race condition from multiple errors
25
24
  }
26
- delete this.sessions[transactionID];
27
25
  };
28
26
 
29
27
  //# sourceMappingURL=rollbackTransaction.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/transactions/rollbackTransaction.ts"],"sourcesContent":["import type { RollbackTransaction } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const rollbackTransaction: RollbackTransaction = async function rollbackTransaction(\n this: MongooseAdapter,\n incomingID = '',\n) {\n let transactionID: number | string\n\n if (incomingID instanceof Promise) {\n transactionID = await incomingID\n } else {\n transactionID = incomingID\n }\n\n // if multiple operations are using the same transaction, the first will flow through and delete the session.\n // subsequent calls should be ignored.\n if (!this.sessions[transactionID]) {\n return\n }\n\n // when session exists but is not inTransaction something unexpected is happening to the session\n if (!this.sessions[transactionID]?.inTransaction()) {\n this.payload.logger.warn('rollbackTransaction called when no transaction exists')\n delete this.sessions[transactionID]\n return\n }\n\n // the first call for rollback should be aborted and deleted causing any other operations with the same transaction to fail\n try {\n await this.sessions[transactionID]?.abortTransaction()\n await this.sessions[transactionID]?.endSession()\n } catch (error) {\n // ignore the error as it is likely a race condition from multiple errors\n }\n delete this.sessions[transactionID]\n}\n"],"names":["rollbackTransaction","incomingID","transactionID","Promise","sessions","inTransaction","payload","logger","warn","abortTransaction","endSession","error"],"mappings":"AAIA,OAAO,MAAMA,sBAA2C,eAAeA,oBAErEC,aAAa,EAAE;IAEf,IAAIC;IAEJ,IAAID,sBAAsBE,SAAS;QACjCD,gBAAgB,MAAMD;IACxB,OAAO;QACLC,gBAAgBD;IAClB;IAEA,6GAA6G;IAC7G,sCAAsC;IACtC,IAAI,CAAC,IAAI,CAACG,QAAQ,CAACF,cAAc,EAAE;QACjC;IACF;IAEA,gGAAgG;IAChG,IAAI,CAAC,IAAI,CAACE,QAAQ,CAACF,cAAc,EAAEG,iBAAiB;QAClD,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;QACzB,OAAO,IAAI,CAACJ,QAAQ,CAACF,cAAc;QACnC;IACF;IAEA,2HAA2H;IAC3H,IAAI;QACF,MAAM,IAAI,CAACE,QAAQ,CAACF,cAAc,EAAEO;QACpC,MAAM,IAAI,CAACL,QAAQ,CAACF,cAAc,EAAEQ;IACtC,EAAE,OAAOC,OAAO;IACd,yEAAyE;IAC3E;IACA,OAAO,IAAI,CAACP,QAAQ,CAACF,cAAc;AACrC,EAAC"}
1
+ {"version":3,"sources":["../../src/transactions/rollbackTransaction.ts"],"sourcesContent":["import type { RollbackTransaction } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const rollbackTransaction: RollbackTransaction = async function rollbackTransaction(\n this: MongooseAdapter,\n incomingID = '',\n) {\n const transactionID = incomingID instanceof Promise ? await incomingID : incomingID\n\n // if multiple operations are using the same transaction, the first will flow through and delete the session.\n // subsequent calls should be ignored.\n if (!this.sessions[transactionID]) {\n return\n }\n\n // when session exists but is not inTransaction something unexpected is happening to the session\n if (!this.sessions[transactionID]?.inTransaction()) {\n this.payload.logger.warn('rollbackTransaction called when no transaction exists')\n delete this.sessions[transactionID]\n return\n }\n\n const session = this.sessions[transactionID]\n\n // Delete from registry FIRST to prevent race conditions\n // This ensures other operations can't retrieve this session while we're aborting it\n delete this.sessions[transactionID]\n\n // the first call for rollback should be aborted and deleted causing any other operations with the same transaction to fail\n try {\n await session.abortTransaction()\n await session.endSession()\n } catch (_error) {\n // ignore the error as it is likely a race condition from multiple errors\n }\n}\n"],"names":["rollbackTransaction","incomingID","transactionID","Promise","sessions","inTransaction","payload","logger","warn","session","abortTransaction","endSession","_error"],"mappings":"AAIA,OAAO,MAAMA,sBAA2C,eAAeA,oBAErEC,aAAa,EAAE;IAEf,MAAMC,gBAAgBD,sBAAsBE,UAAU,MAAMF,aAAaA;IAEzE,6GAA6G;IAC7G,sCAAsC;IACtC,IAAI,CAAC,IAAI,CAACG,QAAQ,CAACF,cAAc,EAAE;QACjC;IACF;IAEA,gGAAgG;IAChG,IAAI,CAAC,IAAI,CAACE,QAAQ,CAACF,cAAc,EAAEG,iBAAiB;QAClD,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;QACzB,OAAO,IAAI,CAACJ,QAAQ,CAACF,cAAc;QACnC;IACF;IAEA,MAAMO,UAAU,IAAI,CAACL,QAAQ,CAACF,cAAc;IAE5C,wDAAwD;IACxD,oFAAoF;IACpF,OAAO,IAAI,CAACE,QAAQ,CAACF,cAAc;IAEnC,2HAA2H;IAC3H,IAAI;QACF,MAAMO,QAAQC,gBAAgB;QAC9B,MAAMD,QAAQE,UAAU;IAC1B,EAAE,OAAOC,QAAQ;IACf,yEAAyE;IAC3E;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getSession.d.ts","sourceRoot":"","sources":["../../src/utilities/getSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,EAAE,EAAE,eAAe,EACnB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAC5B,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAcpC"}
1
+ {"version":3,"file":"getSession.d.ts","sourceRoot":"","sources":["../../src/utilities/getSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,EAAE,EAAE,eAAe,EACnB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAC5B,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA6BpC"}
@@ -10,7 +10,20 @@
10
10
  transactionID = await req.transactionID;
11
11
  }
12
12
  if (transactionID) {
13
- return db.sessions[transactionID];
13
+ const session = db.sessions[transactionID];
14
+ // Defensive check for race conditions where:
15
+ // 1. Session was retrieved from db.sessions
16
+ // 2. Another operation committed/rolled back and ended the session
17
+ // 3. This operation tries to use the now-ended session
18
+ // Note: This shouldn't normally happen as sessions are deleted from db.sessions
19
+ // after commit/rollback, but can occur due to async timing where we hold
20
+ // a reference to a session object that gets ended before we use it.
21
+ if (session && !session.inTransaction()) {
22
+ // Clean up the orphaned session reference
23
+ delete db.sessions[transactionID];
24
+ return undefined;
25
+ }
26
+ return session;
14
27
  }
15
28
  }
16
29
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/getSession.ts"],"sourcesContent":["import type { ClientSession } from 'mongoose'\nimport type { PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\n/**\n * returns the session belonging to the transaction of the req.session if exists\n * @returns ClientSession\n */\nexport async function getSession(\n db: MongooseAdapter,\n req?: Partial<PayloadRequest>,\n): Promise<ClientSession | undefined> {\n if (!req) {\n return\n }\n\n let transactionID = req.transactionID\n\n if (transactionID instanceof Promise) {\n transactionID = await req.transactionID\n }\n\n if (transactionID) {\n return db.sessions[transactionID]\n }\n}\n"],"names":["getSession","db","req","transactionID","Promise","sessions"],"mappings":"AAKA;;;CAGC,GACD,OAAO,eAAeA,WACpBC,EAAmB,EACnBC,GAA6B;IAE7B,IAAI,CAACA,KAAK;QACR;IACF;IAEA,IAAIC,gBAAgBD,IAAIC,aAAa;IAErC,IAAIA,yBAAyBC,SAAS;QACpCD,gBAAgB,MAAMD,IAAIC,aAAa;IACzC;IAEA,IAAIA,eAAe;QACjB,OAAOF,GAAGI,QAAQ,CAACF,cAAc;IACnC;AACF"}
1
+ {"version":3,"sources":["../../src/utilities/getSession.ts"],"sourcesContent":["import type { ClientSession } from 'mongoose'\nimport type { PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\n/**\n * returns the session belonging to the transaction of the req.session if exists\n * @returns ClientSession\n */\nexport async function getSession(\n db: MongooseAdapter,\n req?: Partial<PayloadRequest>,\n): Promise<ClientSession | undefined> {\n if (!req) {\n return\n }\n\n let transactionID = req.transactionID\n\n if (transactionID instanceof Promise) {\n transactionID = await req.transactionID\n }\n\n if (transactionID) {\n const session = db.sessions[transactionID]\n\n // Defensive check for race conditions where:\n // 1. Session was retrieved from db.sessions\n // 2. Another operation committed/rolled back and ended the session\n // 3. This operation tries to use the now-ended session\n // Note: This shouldn't normally happen as sessions are deleted from db.sessions\n // after commit/rollback, but can occur due to async timing where we hold\n // a reference to a session object that gets ended before we use it.\n if (session && !session.inTransaction()) {\n // Clean up the orphaned session reference\n delete db.sessions[transactionID]\n return undefined\n }\n\n return session\n }\n}\n"],"names":["getSession","db","req","transactionID","Promise","session","sessions","inTransaction","undefined"],"mappings":"AAKA;;;CAGC,GACD,OAAO,eAAeA,WACpBC,EAAmB,EACnBC,GAA6B;IAE7B,IAAI,CAACA,KAAK;QACR;IACF;IAEA,IAAIC,gBAAgBD,IAAIC,aAAa;IAErC,IAAIA,yBAAyBC,SAAS;QACpCD,gBAAgB,MAAMD,IAAIC,aAAa;IACzC;IAEA,IAAIA,eAAe;QACjB,MAAME,UAAUJ,GAAGK,QAAQ,CAACH,cAAc;QAE1C,6CAA6C;QAC7C,4CAA4C;QAC5C,mEAAmE;QACnE,uDAAuD;QACvD,gFAAgF;QAChF,yEAAyE;QACzE,oEAAoE;QACpE,IAAIE,WAAW,CAACA,QAAQE,aAAa,IAAI;YACvC,0CAA0C;YAC1C,OAAON,GAAGK,QAAQ,CAACH,cAAc;YACjC,OAAOK;QACT;QAEA,OAAOH;IACT;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/db-mongodb",
3
- "version": "3.65.0-canary.7",
3
+ "version": "3.65.0-canary.8",
4
4
  "description": "The officially supported MongoDB database adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -55,10 +55,10 @@
55
55
  "mongodb": "6.16.0",
56
56
  "mongodb-memory-server": "10.1.4",
57
57
  "@payloadcms/eslint-config": "3.28.0",
58
- "payload": "3.65.0-canary.7"
58
+ "payload": "3.65.0-canary.8"
59
59
  },
60
60
  "peerDependencies": {
61
- "payload": "3.65.0-canary.7"
61
+ "payload": "3.65.0-canary.8"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "pnpm build:types && pnpm build:swc",