@payloadcms/db-mongodb 3.65.0-internal.ef335bd → 3.65.0
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/count.js +3 -3
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.js +3 -3
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.js +3 -3
- package/dist/countVersions.js.map +1 -1
- package/dist/create.js +5 -5
- package/dist/create.js.map +1 -1
- package/dist/createGlobalVersion.js +5 -5
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.js +5 -5
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.js +3 -3
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.js +6 -6
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.js +1 -1
- package/dist/deleteVersions.js.map +1 -1
- package/dist/find.js +1 -1
- package/dist/find.js.map +1 -1
- package/dist/findDistinct.js +1 -1
- package/dist/findDistinct.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +9 -9
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.js +6 -6
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.js +5 -5
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.js +6 -6
- package/dist/findVersions.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +4 -3
- package/dist/queryDrafts.js.map +1 -1
- 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/updateGlobal.js +7 -7
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +12 -12
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateJobs.js +7 -7
- package/dist/updateJobs.js.map +1 -1
- package/dist/updateMany.js +13 -13
- package/dist/updateMany.js.map +1 -1
- package/dist/updateOne.js +13 -13
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.js +12 -12
- package/dist/updateVersion.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
package/dist/updateMany.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { MongooseUpdateQueryOptions, UpdateQuery } from 'mongoose'\n\nimport { flattenWhereToOperators, type UpdateMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateMany: UpdateMany = async function updateMany(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n data,\n limit,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n sort: sortArg,\n where,\n },\n) {\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n let sort: Record<string, unknown> | undefined\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n
|
|
1
|
+
{"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { MongooseUpdateQueryOptions, UpdateQuery } from 'mongoose'\n\nimport { flattenWhereToOperators, type UpdateMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateMany: UpdateMany = async function updateMany(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n data,\n limit,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n sort: sortArg,\n where,\n },\n) {\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n let sort: Record<string, unknown> | undefined\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n let query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields: collectionConfig.fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = data\n data = updateOps\n }\n\n const options: MongooseUpdateQueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n try {\n if (typeof limit === 'number' && limit > 0) {\n const documentsToUpdate = await Model.find(\n query,\n {},\n { ...options, limit, projection: { _id: 1 }, sort },\n )\n if (documentsToUpdate.length === 0) {\n return null\n }\n\n query = { _id: { $in: documentsToUpdate.map((doc) => doc._id) } }\n }\n\n await Model.updateMany(query, data, options)\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n\n if (returning === false) {\n return null\n }\n\n const result = await Model.find(\n query,\n {},\n {\n ...options,\n sort,\n },\n )\n\n transform({\n adapter: this,\n data: result,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["flattenWhereToOperators","buildQuery","buildSortParam","buildProjectionFromSelect","getCollection","getSession","handleError","transform","updateMany","collection","collectionSlug","data","limit","locale","options","optionsArgs","req","returning","select","sort","sortArg","where","hasNearConstraint","constraints","some","prop","Object","keys","key","collectionConfig","Model","adapter","config","payload","fields","flattenedFields","defaultSort","timestamps","query","$inc","$push","$addToSet","$pull","operation","updateOps","length","$set","lean","new","projection","session","documentsToUpdate","find","_id","$in","map","doc","error","result"],"mappings":"AAEA,SAASA,uBAAuB,QAAyB,UAAS;AAIlE,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EACEC,YAAYC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T,EAAC"}
|
package/dist/updateOne.js
CHANGED
|
@@ -15,19 +15,6 @@ export const updateOne = async function updateOne({ id, collection: collectionSl
|
|
|
15
15
|
}
|
|
16
16
|
} : whereArg;
|
|
17
17
|
const fields = collectionConfig.fields;
|
|
18
|
-
const options = {
|
|
19
|
-
...optionsArgs,
|
|
20
|
-
lean: true,
|
|
21
|
-
new: true,
|
|
22
|
-
projection: buildProjectionFromSelect({
|
|
23
|
-
adapter: this,
|
|
24
|
-
fields: collectionConfig.flattenedFields,
|
|
25
|
-
select
|
|
26
|
-
}),
|
|
27
|
-
session: await getSession(this, req),
|
|
28
|
-
// Timestamps are manually added by the write transform
|
|
29
|
-
timestamps: false
|
|
30
|
-
};
|
|
31
18
|
const query = await buildQuery({
|
|
32
19
|
adapter: this,
|
|
33
20
|
collectionSlug,
|
|
@@ -68,6 +55,19 @@ export const updateOne = async function updateOne({ id, collection: collectionSl
|
|
|
68
55
|
updateOps.$set = updateData;
|
|
69
56
|
updateData = updateOps;
|
|
70
57
|
}
|
|
58
|
+
const options = {
|
|
59
|
+
...optionsArgs,
|
|
60
|
+
lean: true,
|
|
61
|
+
new: true,
|
|
62
|
+
projection: buildProjectionFromSelect({
|
|
63
|
+
adapter: this,
|
|
64
|
+
fields: collectionConfig.flattenedFields,
|
|
65
|
+
select
|
|
66
|
+
}),
|
|
67
|
+
session: await getSession(this, req),
|
|
68
|
+
// Timestamps are manually added by the write transform
|
|
69
|
+
timestamps: false
|
|
70
|
+
};
|
|
71
71
|
try {
|
|
72
72
|
if (returning === false) {
|
|
73
73
|
await Model.updateOne(query, updateData, options);
|
package/dist/updateOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { MongooseUpdateQueryOptions, UpdateQuery } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n collection: collectionSlug,\n data,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n where: whereArg = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n const where = id ? { id: { equals: id } } : whereArg\n const fields = collectionConfig.fields\n\n const
|
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { MongooseUpdateQueryOptions, UpdateQuery } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n collection: collectionSlug,\n data,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n where: whereArg = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n const where = id ? { id: { equals: id } } : whereArg\n const fields = collectionConfig.fields\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n let result\n\n let updateData: UpdateQuery<any> = data\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = updateData\n updateData = updateOps\n }\n\n const options: MongooseUpdateQueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n try {\n if (returning === false) {\n await Model.updateOne(query, updateData, options)\n transform({ adapter: this, data, fields, operation: 'read' })\n return null\n } else {\n result = await Model.findOneAndUpdate(query, updateData, options)\n }\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n\n if (!result) {\n return null\n }\n\n transform({ adapter: this, data: result, fields, operation: 'read' })\n\n return result\n}\n"],"names":["buildQuery","buildProjectionFromSelect","getCollection","getSession","handleError","transform","updateOne","id","collection","collectionSlug","data","locale","options","optionsArgs","req","returning","select","where","whereArg","collectionConfig","Model","adapter","equals","fields","query","flattenedFields","result","updateData","$inc","$push","$addToSet","$pull","operation","updateOps","Object","keys","length","$set","lean","new","projection","session","timestamps","findOneAndUpdate","error"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EACEC,EAAE,EACFC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,OAAOC,WAAW,CAAC,CAAC,E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D;QACvD4B,YAAY;IACd;IAEA,IAAI;QACF,IAAI3B,cAAc,OAAO;YACvB,MAAMK,MAAMd,SAAS,CAACkB,OAAOG,YAAYf;YACzCP,UAAU;gBAAEgB,SAAS,IAAI;gBAAEX;gBAAMa;gBAAQS,WAAW;YAAO;YAC3D,OAAO;QACT,OAAO;YACLN,SAAS,MAAMN,MAAMuB,gBAAgB,CAACnB,OAAOG,YAAYf;QAC3D;IACF,EAAE,OAAOgC,OAAO;QACdxC,YAAY;YAAEI,YAAYC;YAAgBmC;YAAO9B;QAAI;IACvD;IAEA,IAAI,CAACY,QAAQ;QACX,OAAO;IACT;IAEArB,UAAU;QAAEgB,SAAS,IAAI;QAAEX,MAAMgB;QAAQH;QAAQS,WAAW;IAAO;IAEnE,OAAON;AACT,EAAC"}
|
package/dist/updateVersion.js
CHANGED
|
@@ -17,6 +17,18 @@ export const updateVersion = async function updateVersion({ id, collection: coll
|
|
|
17
17
|
};
|
|
18
18
|
const fields = buildVersionCollectionFields(this.payload.config, collectionConfig);
|
|
19
19
|
const flattenedFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true);
|
|
20
|
+
const query = await buildQuery({
|
|
21
|
+
adapter: this,
|
|
22
|
+
fields: flattenedFields,
|
|
23
|
+
locale,
|
|
24
|
+
where: whereToUse
|
|
25
|
+
});
|
|
26
|
+
transform({
|
|
27
|
+
adapter: this,
|
|
28
|
+
data: versionData,
|
|
29
|
+
fields,
|
|
30
|
+
operation: 'write'
|
|
31
|
+
});
|
|
20
32
|
const options = {
|
|
21
33
|
...optionsArgs,
|
|
22
34
|
lean: true,
|
|
@@ -30,18 +42,6 @@ export const updateVersion = async function updateVersion({ id, collection: coll
|
|
|
30
42
|
// Timestamps are manually added by the write transform
|
|
31
43
|
timestamps: false
|
|
32
44
|
};
|
|
33
|
-
const query = await buildQuery({
|
|
34
|
-
adapter: this,
|
|
35
|
-
fields: flattenedFields,
|
|
36
|
-
locale,
|
|
37
|
-
where: whereToUse
|
|
38
|
-
});
|
|
39
|
-
transform({
|
|
40
|
-
adapter: this,
|
|
41
|
-
data: versionData,
|
|
42
|
-
fields,
|
|
43
|
-
operation: 'write'
|
|
44
|
-
});
|
|
45
45
|
if (returning === false) {
|
|
46
46
|
await Model.updateOne(query, versionData, options);
|
|
47
47
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { MongooseUpdateQueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n {\n id,\n collection: collectionSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n const flattenedFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const options: MongooseUpdateQueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n
|
|
1
|
+
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { MongooseUpdateQueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n {\n id,\n collection: collectionSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n const flattenedFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n transform({ adapter: this, data: versionData, fields, operation: 'write' })\n\n const options: MongooseUpdateQueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n if (returning === false) {\n await Model.updateOne(query, versionData, options)\n return null\n }\n\n const doc = await Model.findOneAndUpdate(query, versionData, options)\n\n if (!doc) {\n return null\n }\n\n transform({ adapter: this, data: doc, fields, operation: 'read' })\n\n return doc\n}\n"],"names":["buildVersionCollectionFields","buildQuery","buildProjectionFromSelect","getCollection","getSession","transform","updateVersion","id","collection","collectionSlug","locale","options","optionsArgs","req","returning","select","versionData","where","collectionConfig","Model","adapter","versions","whereToUse","equals","fields","payload","config","flattenedFields","query","data","operation","lean","new","projection","session","timestamps","updateOne","doc","findOneAndUpdate"],"mappings":"AAEA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,gBAA+B,eAAeA,cAEz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ilities/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
|
|
3
|
+
"version": "3.65.0",
|
|
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
|
|
58
|
+
"payload": "3.65.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"payload": "3.65.0
|
|
61
|
+
"payload": "3.65.0"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "pnpm build:types && pnpm build:swc",
|