@payloadcms/db-mongodb 3.65.0-internal.5b33fe0 → 3.65.0-internal.cebb1a8
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/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +12 -6
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
- package/dist/transactions/rollbackTransaction.js +8 -10
- package/dist/transactions/rollbackTransaction.js.map +1 -1
- package/dist/utilities/getSession.d.ts.map +1 -1
- package/dist/utilities/getSession.js +14 -1
- package/dist/utilities/getSession.js.map +1 -1
- package/package.json +3 -3
|
@@ -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,
|
|
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(
|
|
2
|
-
|
|
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[
|
|
6
|
+
if (!this.sessions[transactionID]?.inTransaction()) {
|
|
7
|
+
// Clean up the orphaned session reference
|
|
8
|
+
delete this.sessions[transactionID];
|
|
6
9
|
return;
|
|
7
10
|
}
|
|
8
|
-
|
|
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
|
|
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
|
|
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,
|
|
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
|
-
|
|
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
|
|
22
|
-
await
|
|
23
|
-
} catch (
|
|
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
|
|
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,
|
|
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
|
-
|
|
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
|
|
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-internal.
|
|
3
|
+
"version": "3.65.0-internal.cebb1a8",
|
|
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-internal.
|
|
58
|
+
"payload": "3.65.0-internal.cebb1a8"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"payload": "3.65.0-internal.
|
|
61
|
+
"payload": "3.65.0-internal.cebb1a8"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "pnpm build:types && pnpm build:swc",
|