@payloadcms/db-mongodb 3.0.0-canary.926cbeb → 3.0.0-canary.a0b06af
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/count.js +1 -1
- package/dist/count.js.map +1 -1
- package/dist/create.js +1 -1
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.js +1 -1
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.js +1 -1
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.js +1 -1
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.js +1 -1
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.js +1 -1
- 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/findGlobal.js +1 -1
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.js +1 -1
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.js +1 -1
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.js +1 -1
- package/dist/findVersions.js.map +1 -1
- package/dist/queryDrafts.js +1 -1
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +1 -0
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
- package/dist/transactions/rollbackTransaction.js +13 -7
- package/dist/transactions/rollbackTransaction.js.map +1 -1
- package/dist/updateGlobal.js +1 -1
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.js +1 -1
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.js +1 -1
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.js +1 -1
- package/dist/updateVersion.js.map +1 -1
- package/dist/withSession.d.ts +3 -2
- package/dist/withSession.d.ts.map +1 -1
- package/dist/withSession.js +6 -2
- package/dist/withSession.js.map +1 -1
- package/package.json +4 -4
package/dist/count.js
CHANGED
@@ -2,7 +2,7 @@ import { flattenWhereToOperators } from 'payload';
|
|
2
2
|
import { withSession } from './withSession.js';
|
3
3
|
export const count = async function count({ collection, locale, req = {}, where }) {
|
4
4
|
const Model = this.collections[collection];
|
5
|
-
const options = withSession(this, req
|
5
|
+
const options = await withSession(this, req);
|
6
6
|
let hasNearConstraint = false;
|
7
7
|
if (where) {
|
8
8
|
const constraints = flattenWhereToOperators(where);
|
package/dist/count.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { Count, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const count: Count = async function count(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n const options: QueryOptions = withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { Count, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const count: Count = async function count(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n const options: QueryOptions = await withSession(this, req)\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 query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n options.hint = {\n _id: 1,\n }\n }\n\n const result = await Model.countDocuments(query, options)\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","withSession","count","collection","locale","req","where","Model","collections","options","hasNearConstraint","constraints","some","prop","Object","keys","key","query","buildQuery","payload","useEstimatedCount","length","disableIndexHints","hint","_id","result","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,QAAe,eAAeA,MAEzC,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEzD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAwB,MAAMR,YAAY,IAAI,EAAEI;IAEtD,IAAIK,oBAAoB;IAExB,IAAIJ,OAAO;QACT,MAAMK,cAAcX,wBAAwBM;QAC5CI,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMV,MAAMW,UAAU,CAAC;QACnCd;QACAe,SAAS,IAAI,CAACA,OAAO;QACrBb;IACF;IAEA,4HAA4H;IAC5H,MAAMc,oBAAoBV,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBN,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5Bb,QAAQc,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,MAAMC,SAAS,MAAMlB,MAAMmB,cAAc,CAACT,OAAOR;IAEjD,OAAO;QACLkB,WAAWF;IACb;AACF,EAAC"}
|
package/dist/create.js
CHANGED
@@ -2,7 +2,7 @@ import { handleError } from './utilities/handleError.js';
|
|
2
2
|
import { withSession } from './withSession.js';
|
3
3
|
export const create = async function create({ collection, data, req = {} }) {
|
4
4
|
const Model = this.collections[collection];
|
5
|
-
const options = withSession(this, req
|
5
|
+
const options = await withSession(this, req);
|
6
6
|
let doc;
|
7
7
|
try {
|
8
8
|
[doc] = await Model.create([
|
package/dist/create.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { Create, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { handleError } from './utilities/handleError.js'\nimport { withSession } from './withSession.js'\n\nexport const create: Create = async function create(\n this: MongooseAdapter,\n { collection, data, req = {} as PayloadRequest },\n) {\n const Model = this.collections[collection]\n const options = withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { Create, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { handleError } from './utilities/handleError.js'\nimport { withSession } from './withSession.js'\n\nexport const create: Create = async function create(\n this: MongooseAdapter,\n { collection, data, req = {} as PayloadRequest },\n) {\n const Model = this.collections[collection]\n const options = await withSession(this, req)\n let doc\n try {\n ;[doc] = await Model.create([data], options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n // doc.toJSON does not do stuff like converting ObjectIds to string, or date strings to date objects. That's why we use JSON.parse/stringify here\n const result: Document = JSON.parse(JSON.stringify(doc))\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n\n return result\n}\n"],"names":["handleError","withSession","create","collection","data","req","Model","collections","options","doc","error","result","JSON","parse","stringify","verificationToken","_verificationToken","id","_id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,6BAA4B;AACxD,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,SAAiB,eAAeA,OAE3C,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAAmB,EAAE;IAEhD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAU,MAAMP,YAAY,IAAI,EAAEI;IACxC,IAAII;IACJ,IAAI;QACD,CAACA,IAAI,GAAG,MAAMH,MAAMJ,MAAM,CAAC;YAACE;SAAK,EAAEI;IACtC,EAAE,OAAOE,OAAO;QACdV,YAAY;YAAEG;YAAYO;YAAOL;QAAI;IACvC;IAEA,iJAAiJ;IACjJ,MAAMM,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IACnD,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOM,EAAE,GAAGN,OAAOO,GAAG;IACtB,IAAIH,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IAEA,OAAOJ;AACT,EAAC"}
|
package/dist/createGlobal.js
CHANGED
@@ -6,7 +6,7 @@ export const createGlobal = async function createGlobal({ slug, data, req = {} }
|
|
6
6
|
globalType: slug,
|
7
7
|
...data
|
8
8
|
};
|
9
|
-
const options = withSession(this, req
|
9
|
+
const options = await withSession(this, req);
|
10
10
|
let [result] = await Model.create([
|
11
11
|
global
|
12
12
|
], options);
|
package/dist/createGlobal.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/createGlobal.ts"],"sourcesContent":["import type { CreateGlobal, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const createGlobal: CreateGlobal = async function createGlobal(\n this: MongooseAdapter,\n { slug, data, req = {} as PayloadRequest },\n) {\n const Model = this.globals\n const global = {\n globalType: slug,\n ...data,\n }\n const options = withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/createGlobal.ts"],"sourcesContent":["import type { CreateGlobal, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const createGlobal: CreateGlobal = async function createGlobal(\n this: MongooseAdapter,\n { slug, data, req = {} as PayloadRequest },\n) {\n const Model = this.globals\n const global = {\n globalType: slug,\n ...data,\n }\n const options = await withSession(this, req)\n\n let [result] = (await Model.create([global], options)) as any\n\n result = JSON.parse(JSON.stringify(result))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["sanitizeInternalFields","withSession","createGlobal","slug","data","req","Model","globals","global","globalType","options","result","create","JSON","parse","stringify","id","_id"],"mappings":"AAIA,OAAOA,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAAmB,EAAE;IAE1C,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,SAAS;QACbC,YAAYN;QACZ,GAAGC,IAAI;IACT;IACA,MAAMM,UAAU,MAAMT,YAAY,IAAI,EAAEI;IAExC,IAAI,CAACM,OAAO,GAAI,MAAML,MAAMM,MAAM,CAAC;QAACJ;KAAO,EAAEE;IAE7CC,SAASE,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACJ;IAEnC,uBAAuB;IACvBA,OAAOK,EAAE,GAAGL,OAAOM,GAAG;IACtBN,SAASX,uBAAuBW;IAEhC,OAAOA;AACT,EAAC"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { withSession } from './withSession.js';
|
2
2
|
export const createGlobalVersion = async function createGlobalVersion({ autosave, createdAt, globalSlug, parent, req = {}, updatedAt, versionData }) {
|
3
3
|
const VersionModel = this.versions[globalSlug];
|
4
|
-
const options = withSession(this, req
|
4
|
+
const options = await withSession(this, req);
|
5
5
|
const [doc] = await VersionModel.create([
|
6
6
|
{
|
7
7
|
autosave,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import type { CreateGlobalVersion, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const createGlobalVersion: CreateGlobalVersion = async function createGlobalVersion(\n this: MongooseAdapter,\n { autosave, createdAt, globalSlug, parent, req = {} as PayloadRequest, updatedAt, versionData },\n) {\n const VersionModel = this.versions[globalSlug]\n const options = withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import type { CreateGlobalVersion, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const createGlobalVersion: CreateGlobalVersion = async function createGlobalVersion(\n this: MongooseAdapter,\n { autosave, createdAt, globalSlug, parent, req = {} as PayloadRequest, updatedAt, versionData },\n) {\n const VersionModel = this.versions[globalSlug]\n const options = await withSession(this, req)\n\n const [doc] = await VersionModel.create(\n [\n {\n autosave,\n createdAt,\n latest: true,\n parent,\n updatedAt,\n version: versionData,\n },\n ],\n options,\n req,\n )\n\n await VersionModel.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n {\n parent: {\n $eq: parent,\n },\n },\n {\n latest: {\n $eq: true,\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n const result: Document = JSON.parse(JSON.stringify(doc))\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["withSession","createGlobalVersion","autosave","createdAt","globalSlug","parent","req","updatedAt","versionData","VersionModel","versions","options","doc","create","latest","version","updateMany","$and","_id","$ne","$eq","$unset","result","JSON","parse","stringify","verificationToken","_verificationToken","id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,SAAS,EAAEC,WAAW,EAAE;IAE/F,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,WAAW;IAC9C,MAAMO,UAAU,MAAMX,YAAY,IAAI,EAAEM;IAExC,MAAM,CAACM,IAAI,GAAG,MAAMH,aAAaI,MAAM,CACrC;QACE;YACEX;YACAC;YACAW,QAAQ;YACRT;YACAE;YACAQ,SAASP;QACX;KACD,EACDG,SACAL;IAGF,MAAMG,aAAaO,UAAU,CAC3B;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKP,IAAIM,GAAG;gBACd;YACF;YACA;gBACEb,QAAQ;oBACNe,KAAKf;gBACP;YACF;YACA;gBACES,QAAQ;oBACNM,KAAK;gBACP;YACF;SACD;IACH,GACA;QAAEC,QAAQ;YAAEP,QAAQ;QAAE;IAAE,GACxBH;IAGF,MAAMW,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACb;IACnD,MAAMc,oBAAoBd,IAAIe,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOM,EAAE,GAAGN,OAAOJ,GAAG;IACtB,IAAIQ,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
|
package/dist/createVersion.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { withSession } from './withSession.js';
|
2
2
|
export const createVersion = async function createVersion({ autosave, collectionSlug, createdAt, parent, req = {}, updatedAt, versionData }) {
|
3
3
|
const VersionModel = this.versions[collectionSlug];
|
4
|
-
const options = withSession(this, req
|
4
|
+
const options = await withSession(this, req);
|
5
5
|
const [doc] = await VersionModel.create([
|
6
6
|
{
|
7
7
|
autosave,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import type { CreateVersion, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const createVersion: CreateVersion = async function createVersion(\n this: MongooseAdapter,\n {\n autosave,\n collectionSlug,\n createdAt,\n parent,\n req = {} as PayloadRequest,\n updatedAt,\n versionData,\n },\n) {\n const VersionModel = this.versions[collectionSlug]\n const options = withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import type { CreateVersion, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const createVersion: CreateVersion = async function createVersion(\n this: MongooseAdapter,\n {\n autosave,\n collectionSlug,\n createdAt,\n parent,\n req = {} as PayloadRequest,\n updatedAt,\n versionData,\n },\n) {\n const VersionModel = this.versions[collectionSlug]\n const options = await withSession(this, req)\n\n const [doc] = await VersionModel.create(\n [\n {\n autosave,\n createdAt,\n latest: true,\n parent,\n updatedAt,\n version: versionData,\n },\n ],\n options,\n req,\n )\n\n await VersionModel.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n {\n parent: {\n $eq: parent,\n },\n },\n {\n latest: {\n $eq: true,\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n const result: Document = JSON.parse(JSON.stringify(doc))\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["withSession","createVersion","autosave","collectionSlug","createdAt","parent","req","updatedAt","versionData","VersionModel","versions","options","doc","create","latest","version","updateMany","$and","_id","$ne","$eq","$unset","result","JSON","parse","stringify","verificationToken","_verificationToken","id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,MAAM,CAAC,CAAmB,EAC1BC,SAAS,EACTC,WAAW,EACZ;IAED,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACP,eAAe;IAClD,MAAMQ,UAAU,MAAMX,YAAY,IAAI,EAAEM;IAExC,MAAM,CAACM,IAAI,GAAG,MAAMH,aAAaI,MAAM,CACrC;QACE;YACEX;YACAE;YACAU,QAAQ;YACRT;YACAE;YACAQ,SAASP;QACX;KACD,EACDG,SACAL;IAGF,MAAMG,aAAaO,UAAU,CAC3B;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKP,IAAIM,GAAG;gBACd;YACF;YACA;gBACEb,QAAQ;oBACNe,KAAKf;gBACP;YACF;YACA;gBACES,QAAQ;oBACNM,KAAK;gBACP;YACF;SACD;IACH,GACA;QAAEC,QAAQ;YAAEP,QAAQ;QAAE;IAAE,GACxBH;IAGF,MAAMW,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACb;IACnD,MAAMc,oBAAoBd,IAAIe,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOM,EAAE,GAAGN,OAAOJ,GAAG;IACtB,IAAIQ,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
|
package/dist/deleteMany.js
CHANGED
@@ -2,7 +2,7 @@ import { withSession } from './withSession.js';
|
|
2
2
|
export const deleteMany = async function deleteMany({ collection, req = {}, where }) {
|
3
3
|
const Model = this.collections[collection];
|
4
4
|
const options = {
|
5
|
-
...withSession(this, req
|
5
|
+
...await withSession(this, req),
|
6
6
|
lean: true
|
7
7
|
};
|
8
8
|
const query = await Model.buildQuery({
|
package/dist/deleteMany.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n const options = {\n ...withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await Model.buildQuery({\n payload: this.payload,\n where,\n })\n\n await Model.deleteMany(query, options)\n}\n"],"names":["withSession","deleteMany","collection","req","where","Model","collections","options","lean","query","buildQuery","payload"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEjD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAU;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEG,IAAI;QAChCK,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMC,MAAMJ,UAAU,CAACQ,OAAOF;AAChC,EAAC"}
|
package/dist/deleteOne.js
CHANGED
@@ -2,7 +2,7 @@ import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
|
|
2
2
|
import { withSession } from './withSession.js';
|
3
3
|
export const deleteOne = async function deleteOne({ collection, req = {}, where }) {
|
4
4
|
const Model = this.collections[collection];
|
5
|
-
const options = withSession(this, req
|
5
|
+
const options = await withSession(this, req);
|
6
6
|
const query = await Model.buildQuery({
|
7
7
|
payload: this.payload,
|
8
8
|
where
|
package/dist/deleteOne.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { collection, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n const options = withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { collection, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n const options = await withSession(this, req)\n\n const query = await Model.buildQuery({\n payload: this.payload,\n where,\n })\n\n const doc = await Model.findOneAndDelete(query, options).lean()\n\n let result: Document = JSON.parse(JSON.stringify(doc))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["sanitizeInternalFields","withSession","deleteOne","collection","req","where","Model","collections","options","query","buildQuery","payload","doc","findOneAndDelete","lean","result","JSON","parse","stringify","id","_id"],"mappings":"AAIA,OAAOA,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEjD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAU,MAAMP,YAAY,IAAI,EAAEG;IAExC,MAAMK,QAAQ,MAAMH,MAAMI,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBN;IACF;IAEA,MAAMO,MAAM,MAAMN,MAAMO,gBAAgB,CAACJ,OAAOD,SAASM,IAAI;IAE7D,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEjD,uBAAuB;IACvBG,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASf,uBAAuBe;IAEhC,OAAOA;AACT,EAAC"}
|
package/dist/deleteVersions.js
CHANGED
@@ -2,7 +2,7 @@ import { withSession } from './withSession.js';
|
|
2
2
|
export const deleteVersions = async function deleteVersions({ collection, locale, req = {}, where }) {
|
3
3
|
const VersionsModel = this.versions[collection];
|
4
4
|
const options = {
|
5
|
-
...withSession(this, req
|
5
|
+
...await withSession(this, req),
|
6
6
|
lean: true
|
7
7
|
};
|
8
8
|
const query = await VersionsModel.buildQuery({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequest, where },\n) {\n const VersionsModel = this.versions[collection]\n const options = {\n ...withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequest, where },\n) {\n const VersionsModel = this.versions[collection]\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await VersionsModel.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n await VersionsModel.deleteMany(query, options)\n}\n"],"names":["withSession","deleteVersions","collection","locale","req","where","VersionsModel","versions","options","lean","query","buildQuery","payload","deleteMany"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,iBAAiC,eAAeA,eAE3D,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEzD,MAAMC,gBAAgB,IAAI,CAACC,QAAQ,CAACL,WAAW;IAC/C,MAAMM,UAAU;QACd,GAAI,MAAMR,YAAY,IAAI,EAAEI,IAAI;QAChCK,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMJ,cAAcK,UAAU,CAAC;QAC3CR;QACAS,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMC,cAAcO,UAAU,CAACH,OAAOF;AACxC,EAAC"}
|
package/dist/find.js
CHANGED
@@ -5,7 +5,7 @@ import { withSession } from './withSession.js';
|
|
5
5
|
export const find = async function find({ collection, limit, locale, page, pagination, req = {}, sort: sortArg, where }) {
|
6
6
|
const Model = this.collections[collection];
|
7
7
|
const collectionConfig = this.payload.collections[collection].config;
|
8
|
-
const options = withSession(this, req
|
8
|
+
const options = await withSession(this, req);
|
9
9
|
let hasNearConstraint = false;
|
10
10
|
if (where) {
|
11
11
|
const constraints = flattenWhereToOperators(where);
|
package/dist/find.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Find, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const find: Find = async function find(\n this: MongooseAdapter,\n { collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Find, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const find: Find = async function find(\n this: MongooseAdapter,\n { collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\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 let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n // eslint-disable-next-line no-param-reassign\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","find","collection","limit","locale","page","pagination","req","sort","sortArg","where","Model","collections","collectionConfig","payload","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,OAAa,eAAeA,KAEvC,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAMC,OAAO,EAAEC,KAAK,EAAE;IAEjG,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACV,WAAW;IAC1C,MAAMW,mBAAmB,IAAI,CAACC,OAAO,CAACF,WAAW,CAACV,WAAW,CAACa,MAAM;IACpE,MAAMC,UAAU,MAAMhB,YAAY,IAAI,EAAEO;IAExC,IAAIU,oBAAoB;IAExB,IAAIP,OAAO;QACT,MAAMQ,cAAcrB,wBAAwBa;QAC5CO,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAIf;IACJ,IAAI,CAACS,mBAAmB;QACtBT,OAAOV,eAAe;YACpBiB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;YAC3BS,QAAQX,iBAAiBW,MAAM;YAC/BpB;YACAI,MAAMC,WAAWI,iBAAiBY,WAAW;YAC7CC,YAAY;QACd;IACF;IAEA,MAAMC,QAAQ,MAAMhB,MAAMiB,UAAU,CAAC;QACnCxB;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBJ;IACF;IAEA,4HAA4H;IAC5H,MAAMmB,oBAAoBZ,qBAAqB,CAACU,SAASN,OAAOC,IAAI,CAACK,OAAOG,MAAM,KAAK;IACvF,MAAMC,oBAAqC;QACzCC,cAAcf;QACdgB,MAAM;QACNC,YAAY;QACZlB;QACAX;QACAC;QACAE;QACAqB;IACF;IAEA,IAAI,CAACA,qBAAqBR,OAAOC,IAAI,CAACK,OAAOG,MAAM,KAAK,KAAK,IAAI,CAACK,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BJ,kBAAkBK,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpB3B,MAAM4B,cAAc,CAACZ,OAAO;gBAC1B,GAAGX,OAAO;gBACVwB,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAItC,SAAS,GAAG;QACd4B,kBAAkB5B,KAAK,GAAGA;QAC1B,qEAAqE;QACrE4B,kBAAkBf,OAAO,CAACb,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACf4B,kBAAkBzB,UAAU,GAAG;QACjC;IACF;IAEA,MAAMoC,SAAS,MAAM/B,MAAMgC,QAAQ,CAAChB,OAAOI;IAC3C,MAAMa,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACd,6CAA6C;YAC7CA,IAAIC,EAAE,GAAGD,IAAIR,GAAG;YAChB,OAAO1C,uBAAuBkD;QAChC;IACF;AACF,EAAC"}
|
package/dist/findGlobal.js
CHANGED
@@ -4,7 +4,7 @@ import { withSession } from './withSession.js';
|
|
4
4
|
export const findGlobal = async function findGlobal({ slug, locale, req = {}, where }) {
|
5
5
|
const Model = this.globals;
|
6
6
|
const options = {
|
7
|
-
...withSession(this, req
|
7
|
+
...await withSession(this, req),
|
8
8
|
lean: true
|
9
9
|
};
|
10
10
|
const query = await Model.buildQuery({
|
package/dist/findGlobal.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal, PayloadRequest } from 'payload'\n\nimport { combineQueries } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: MongooseAdapter,\n { slug, locale, req = {} as PayloadRequest, where },\n) {\n const Model = this.globals\n const options = {\n ...withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal, PayloadRequest } from 'payload'\n\nimport { combineQueries } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: MongooseAdapter,\n { slug, locale, req = {} as PayloadRequest, where },\n) {\n const Model = this.globals\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await Model.buildQuery({\n globalSlug: slug,\n locale,\n payload: this.payload,\n where: combineQueries({ globalType: { equals: slug } }, where),\n })\n\n let doc = (await Model.findOne(query, {}, options)) as any\n\n if (!doc) {\n return null\n }\n if (doc._id) {\n doc.id = doc._id\n delete doc._id\n }\n\n doc = JSON.parse(JSON.stringify(doc))\n doc = sanitizeInternalFields(doc)\n\n return doc\n}\n"],"names":["combineQueries","sanitizeInternalFields","withSession","findGlobal","slug","locale","req","where","Model","globals","options","lean","query","buildQuery","globalSlug","payload","globalType","equals","doc","findOne","_id","id","JSON","parse","stringify"],"mappings":"AAEA,SAASA,cAAc,QAAQ,UAAS;AAIxC,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEnD,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAU;QACd,GAAI,MAAMR,YAAY,IAAI,EAAEI,IAAI;QAChCK,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCC,YAAYV;QACZC;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBR,OAAOP,eAAe;YAAEgB,YAAY;gBAAEC,QAAQb;YAAK;QAAE,GAAGG;IAC1D;IAEA,IAAIW,MAAO,MAAMV,MAAMW,OAAO,CAACP,OAAO,CAAC,GAAGF;IAE1C,IAAI,CAACQ,KAAK;QACR,OAAO;IACT;IACA,IAAIA,IAAIE,GAAG,EAAE;QACXF,IAAIG,EAAE,GAAGH,IAAIE,GAAG;QAChB,OAAOF,IAAIE,GAAG;IAChB;IAEAF,MAAMI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAChCA,MAAMjB,uBAAuBiB;IAE7B,OAAOA;AACT,EAAC"}
|
@@ -6,7 +6,7 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
|
|
6
6
|
const Model = this.versions[global];
|
7
7
|
const versionFields = buildVersionGlobalFields(this.payload.globals.config.find(({ slug })=>slug === global));
|
8
8
|
const options = {
|
9
|
-
...withSession(this, req
|
9
|
+
...await withSession(this, req),
|
10
10
|
limit,
|
11
11
|
skip
|
12
12
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindGlobalVersions, PayloadRequest } from 'payload'\n\nimport { buildVersionGlobalFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: MongooseAdapter,\n {\n global,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[global]\n const versionFields = buildVersionGlobalFields(\n this.payload.globals.config.find(({ slug }) => slug === global),\n )\n const options = {\n ...withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindGlobalVersions, PayloadRequest } from 'payload'\n\nimport { buildVersionGlobalFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: MongooseAdapter,\n {\n global,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[global]\n const versionFields = buildVersionGlobalFields(\n this.payload.globals.config.find(({ slug }) => slug === global),\n )\n const options = {\n ...(await withSession(this, req)),\n limit,\n skip,\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 let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: versionFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n globalSlug: global,\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n offset: skip,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n // eslint-disable-next-line no-param-reassign\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["buildVersionGlobalFields","flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","findGlobalVersions","global","limit","locale","page","pagination","req","skip","sort","sortArg","where","Model","versions","versionFields","payload","globals","config","find","slug","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","buildQuery","globalSlug","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","offset","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,wBAAwB,EAAEC,uBAAuB,QAAQ,UAAS;AAI3E,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EACEC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACX,OAAO;IACnC,MAAMY,gBAAgBlB,yBACpB,IAAI,CAACmB,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASjB;IAE1D,MAAMkB,UAAU;QACd,GAAI,MAAMpB,YAAY,IAAI,EAAEO,IAAI;QAChCJ;QACAK;IACF;IAEA,IAAIa,oBAAoB;IAExB,IAAIV,OAAO;QACT,MAAMW,cAAczB,wBAAwBc;QAC5CU,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAIlB;IACJ,IAAI,CAACY,mBAAmB;QACtBZ,OAAOX,eAAe;YACpBmB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;YAC3BW,QAAQd;YACRV;YACAK,MAAMC,WAAW;YACjBmB,YAAY;QACd;IACF;IAEA,MAAMC,QAAQ,MAAMlB,MAAMmB,UAAU,CAAC;QACnCC,YAAY9B;QACZE;QACAW,SAAS,IAAI,CAACA,OAAO;QACrBJ;IACF;IAEA,4HAA4H;IAC5H,MAAMsB,oBAAoBZ,qBAAqB,CAACS,SAASL,OAAOC,IAAI,CAACI,OAAOI,MAAM,KAAK;IACvF,MAAMC,oBAAqC;QACzCC,cAAcf;QACdgB,MAAM;QACNC,YAAY;QACZC,QAAQ/B;QACRY;QACAf;QACAC;QACAG;QACAwB;IACF;IAEA,IAAI,CAACA,qBAAqBR,OAAOC,IAAI,CAACI,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACM,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BL,kBAAkBM,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpB/B,MAAMgC,cAAc,CAACd,OAAO;gBAC1B,GAAGV,OAAO;gBACVyB,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAI3C,SAAS,GAAG;QACdgC,kBAAkBhC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEgC,kBAAkBf,OAAO,CAACjB,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACfgC,kBAAkB7B,UAAU,GAAG;QACjC;IACF;IAEA,MAAMyC,SAAS,MAAMnC,MAAMoC,QAAQ,CAAClB,OAAOK;IAC3C,MAAMc,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACd,6CAA6C;YAC7CA,IAAIC,EAAE,GAAGD,IAAIR,GAAG;YAChB,OAAO/C,uBAAuBuD;QAChC;IACF;AACF,EAAC"}
|
package/dist/findOne.js
CHANGED
@@ -3,7 +3,7 @@ import { withSession } from './withSession.js';
|
|
3
3
|
export const findOne = async function findOne({ collection, locale, req = {}, where }) {
|
4
4
|
const Model = this.collections[collection];
|
5
5
|
const options = {
|
6
|
-
...withSession(this, req
|
6
|
+
...await withSession(this, req),
|
7
7
|
lean: true
|
8
8
|
};
|
9
9
|
const query = await Model.buildQuery({
|
package/dist/findOne.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { MongooseQueryOptions } from 'mongoose'\nimport type { Document, FindOne, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findOne: FindOne = async function findOne(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n const options: MongooseQueryOptions = {\n ...withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { MongooseQueryOptions } from 'mongoose'\nimport type { Document, FindOne, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findOne: FindOne = async function findOne(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n const options: MongooseQueryOptions = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n const doc = await Model.findOne(query, {}, options)\n\n if (!doc) {\n return null\n }\n\n let result: Document = JSON.parse(JSON.stringify(doc))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["sanitizeInternalFields","withSession","findOne","collection","locale","req","where","Model","collections","options","lean","query","buildQuery","payload","doc","result","JSON","parse","stringify","id","_id"],"mappings":"AAKA,OAAOA,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,UAAmB,eAAeA,QAE7C,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEzD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAgC;QACpC,GAAI,MAAMR,YAAY,IAAI,EAAEI,IAAI;QAChCK,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCR;QACAS,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMQ,MAAM,MAAMP,MAAML,OAAO,CAACS,OAAO,CAAC,GAAGF;IAE3C,IAAI,CAACK,KAAK;QACR,OAAO;IACT;IAEA,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACJ;IAEjD,uBAAuB;IACvBC,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASf,uBAAuBe;IAEhC,OAAOA;AACT,EAAC"}
|
package/dist/findVersions.js
CHANGED
@@ -6,7 +6,7 @@ export const findVersions = async function findVersions({ collection, limit, loc
|
|
6
6
|
const Model = this.versions[collection];
|
7
7
|
const collectionConfig = this.payload.collections[collection].config;
|
8
8
|
const options = {
|
9
|
-
...withSession(this, req
|
9
|
+
...await withSession(this, req),
|
10
10
|
limit,
|
11
11
|
skip
|
12
12
|
};
|
package/dist/findVersions.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindVersions, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: MongooseAdapter,\n {\n collection,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = {\n ...withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindVersions, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: MongooseAdapter,\n {\n collection,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = {\n ...(await withSession(this, req)),\n limit,\n skip,\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 let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n // eslint-disable-next-line no-param-reassign\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","findVersions","collection","limit","locale","page","pagination","req","skip","sort","sortArg","where","Model","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EACEC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACX,WAAW;IACvC,MAAMY,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACd,WAAW,CAACe,MAAM;IACpE,MAAMC,UAAU;QACd,GAAI,MAAMlB,YAAY,IAAI,EAAEO,IAAI;QAChCJ;QACAK;IACF;IAEA,IAAIW,oBAAoB;IAExB,IAAIR,OAAO;QACT,MAAMS,cAAcvB,wBAAwBc;QAC5CQ,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAIhB;IACJ,IAAI,CAACU,mBAAmB;QACtBV,OAAOX,eAAe;YACpBmB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;YAC3BS,QAAQZ,iBAAiBY,MAAM;YAC/BtB;YACAK,MAAMC,WAAW;YACjBiB,YAAY;QACd;IACF;IAEA,MAAMC,QAAQ,MAAMhB,MAAMiB,UAAU,CAAC;QACnCzB;QACAW,SAAS,IAAI,CAACA,OAAO;QACrBJ;IACF;IAEA,4HAA4H;IAC5H,MAAMmB,oBAAoBX,qBAAqB,CAACS,SAASL,OAAOC,IAAI,CAACI,OAAOG,MAAM,KAAK;IACvF,MAAMC,oBAAqC;QACzCC,cAAcd;QACde,MAAM;QACNC,YAAY;QACZhC;QACAe;QACAb;QACAC;QACAG;QACAqB;IACF;IAEA,IAAI,CAACA,qBAAqBP,OAAOC,IAAI,CAACI,OAAOG,MAAM,KAAK,KAAK,IAAI,CAACK,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BJ,kBAAkBK,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpB3B,MAAM4B,cAAc,CAACZ,OAAO;gBAC1B,GAAGV,OAAO;gBACVuB,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAIvC,SAAS,GAAG;QACd6B,kBAAkB7B,KAAK,GAAGA;QAC1B,qEAAqE;QACrE6B,kBAAkBd,OAAO,CAACf,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACf6B,kBAAkB1B,UAAU,GAAG;QACjC;IACF;IAEA,MAAMqC,SAAS,MAAM/B,MAAMgC,QAAQ,CAAChB,OAAOI;IAC3C,MAAMa,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACd,6CAA6C;YAC7CA,IAAIC,EAAE,GAAGD,IAAIR,GAAG;YAChB,OAAO3C,uBAAuBmD;QAChC;IACF;AACF,EAAC"}
|
package/dist/queryDrafts.js
CHANGED
@@ -5,7 +5,7 @@ import { withSession } from './withSession.js';
|
|
5
5
|
export const queryDrafts = async function queryDrafts({ collection, limit, locale, page, pagination, req = {}, sort: sortArg, where }) {
|
6
6
|
const VersionModel = this.versions[collection];
|
7
7
|
const collectionConfig = this.payload.collections[collection].config;
|
8
|
-
const options = withSession(this, req
|
8
|
+
const options = await withSession(this, req);
|
9
9
|
let hasNearConstraint;
|
10
10
|
let sort;
|
11
11
|
if (where) {
|
package/dist/queryDrafts.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { PayloadRequest, QueryDrafts } from 'payload'\n\nimport { combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n { collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { PayloadRequest, QueryDrafts } from 'payload'\n\nimport { combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n { collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const versionQuery = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: combinedWhere,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n VersionModel.countDocuments(versionQuery, {\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n }\n\n const result = await VersionModel.paginate(versionQuery, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n // eslint-disable-next-line no-param-reassign\n doc = {\n _id: doc.parent,\n id: doc.parent,\n ...doc.version,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["combineQueries","flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","queryDrafts","collection","limit","locale","page","pagination","req","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version","createdAt","updatedAt"],"mappings":"AAGA,SAASA,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAIjE,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAMC,OAAO,EAAEC,KAAK,EAAE;IAEjG,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACV,WAAW;IAC9C,MAAMW,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACb,WAAW,CAACc,MAAM;IACpE,MAAMC,UAAU,MAAMjB,YAAY,IAAI,EAAEO;IAExC,IAAIW;IACJ,IAAIV;IAEJ,IAAIE,OAAO;QACT,MAAMS,cAActB,wBAAwBa;QAC5CQ,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAI,CAACN,mBAAmB;QACtBV,OAAOV,eAAe;YACpBkB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;YAC3BS,QAAQZ,iBAAiBY,MAAM;YAC/BrB;YACAI,MAAMC,WAAWI,iBAAiBa,WAAW;YAC7CC,YAAY;QACd;IACF;IAEA,MAAMC,gBAAgBhC,eAAe;QAAEiC,QAAQ;YAAEC,QAAQ;QAAK;IAAE,GAAGpB;IAEnE,MAAMqB,eAAe,MAAMpB,aAAaqB,UAAU,CAAC;QACjD5B;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBJ,OAAOkB;IACT;IAEA,4HAA4H;IAC5H,MAAMK,oBACJf,qBAAqB,CAACa,gBAAgBT,OAAOC,IAAI,CAACQ,cAAcG,MAAM,KAAK;IAC7E,MAAMC,oBAAqC;QACzCC,cAAclB;QACdmB,MAAM;QACNC,YAAY;QACZrB;QACAZ;QACAC;QACAE;QACAyB;IACF;IAEA,IACE,CAACA,qBACDX,OAAOC,IAAI,CAACQ,cAAcG,MAAM,KAAK,KACrC,IAAI,CAACK,iBAAiB,KAAK,MAC3B;QACA,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BJ,kBAAkBK,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpB/B,aAAagC,cAAc,CAACZ,cAAc;gBACxCa,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAI1C,QAAQ,GAAG;QACbgC,kBAAkBhC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEgC,kBAAkBlB,OAAO,CAACd,KAAK,GAAGA;IACpC;IAEA,MAAM2C,SAAS,MAAMnC,aAAaoC,QAAQ,CAAChB,cAAcI;IACzD,MAAMa,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACd,6CAA6C;YAC7CA,MAAM;gBACJR,KAAKQ,IAAIC,MAAM;gBACfC,IAAIF,IAAIC,MAAM;gBACd,GAAGD,IAAIG,OAAO;gBACdC,WAAWJ,IAAII,SAAS;gBACxBC,WAAWL,IAAIK,SAAS;YAC1B;YAEA,OAAO3D,uBAAuBsD;QAChC;IACF;AACF,EAAC"}
|
@@ -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;AAEhD,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;AAEhD,eAAO,MAAM,iBAAiB,EAAE,iBAc/B,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { CommitTransaction } from 'payload'\n\nexport const commitTransaction: CommitTransaction = async function commitTransaction(id) {\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 (error) {\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","sessions","inTransaction","endSession","error"],"mappings":"AAEA,OAAO,MAAMA,oBAAuC,eAAeA,kBAAkBC,EAAE;IACrF,IAAI,CAAC,IAAI,CAACC,QAAQ,
|
1
|
+
{"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { CommitTransaction } from 'payload'\n\nexport const commitTransaction: CommitTransaction = async function commitTransaction(id) {\n if (id instanceof Promise) return\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 (error) {\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","error"],"mappings":"AAEA,OAAO,MAAMA,oBAAuC,eAAeA,kBAAkBC,EAAE;IACrF,IAAIA,cAAcC,SAAS;IAE3B,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,OAAO;IACd,gHAAgH;IAClH;IACA,OAAO,IAAI,CAACH,QAAQ,CAACF,GAAG;AAC1B,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;AAElD,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;AAElD,eAAO,MAAM,mBAAmB,EAAE,mBAgCjC,CAAA"}
|
@@ -1,23 +1,29 @@
|
|
1
|
-
export const rollbackTransaction = async function rollbackTransaction(
|
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
8
|
// if multiple operations are using the same transaction, the first will flow through and delete the session.
|
3
9
|
// subsequent calls should be ignored.
|
4
|
-
if (!this.sessions[
|
10
|
+
if (!this.sessions[transactionID]) {
|
5
11
|
return;
|
6
12
|
}
|
7
13
|
// when session exists but is not inTransaction something unexpected is happening to the session
|
8
|
-
if (!this.sessions[
|
14
|
+
if (!this.sessions[transactionID].inTransaction()) {
|
9
15
|
this.payload.logger.warn('rollbackTransaction called when no transaction exists');
|
10
|
-
delete this.sessions[
|
16
|
+
delete this.sessions[transactionID];
|
11
17
|
return;
|
12
18
|
}
|
13
19
|
// the first call for rollback should be aborted and deleted causing any other operations with the same transaction to fail
|
14
20
|
try {
|
15
|
-
await this.sessions[
|
16
|
-
await this.sessions[
|
21
|
+
await this.sessions[transactionID].abortTransaction();
|
22
|
+
await this.sessions[transactionID].endSession();
|
17
23
|
} catch (error) {
|
18
24
|
// ignore the error as it is likely a race condition from multiple errors
|
19
25
|
}
|
20
|
-
delete this.sessions[
|
26
|
+
delete this.sessions[transactionID];
|
21
27
|
};
|
22
28
|
|
23
29
|
//# sourceMappingURL=rollbackTransaction.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/transactions/rollbackTransaction.ts"],"sourcesContent":["import type { RollbackTransaction } from 'payload'\n\nexport const rollbackTransaction: RollbackTransaction = async function rollbackTransaction(\n
|
1
|
+
{"version":3,"sources":["../../src/transactions/rollbackTransaction.ts"],"sourcesContent":["import type { RollbackTransaction } from 'payload'\n\nexport const rollbackTransaction: RollbackTransaction = async function rollbackTransaction(\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":"AAEA,OAAO,MAAMA,sBAA2C,eAAeA,oBACrEC,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,CAACG,aAAa,IAAI;QACjD,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,CAACO,gBAAgB;QACnD,MAAM,IAAI,CAACL,QAAQ,CAACF,cAAc,CAACQ,UAAU;IAC/C,EAAE,OAAOC,OAAO;IACd,yEAAyE;IAC3E;IACA,OAAO,IAAI,CAACP,QAAQ,CAACF,cAAc;AACrC,EAAC"}
|
package/dist/updateGlobal.js
CHANGED
@@ -3,7 +3,7 @@ import { withSession } from './withSession.js';
|
|
3
3
|
export const updateGlobal = async function updateGlobal({ slug, data, req = {} }) {
|
4
4
|
const Model = this.globals;
|
5
5
|
const options = {
|
6
|
-
...withSession(this, req
|
6
|
+
...await withSession(this, req),
|
7
7
|
lean: true,
|
8
8
|
new: true
|
9
9
|
};
|
package/dist/updateGlobal.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { PayloadRequest, UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, req = {} as PayloadRequest },\n) {\n const Model = this.globals\n const options = {\n ...withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { PayloadRequest, UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, req = {} as PayloadRequest },\n) {\n const Model = this.globals\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n let result\n result = await Model.findOneAndUpdate({ globalType: slug }, data, options)\n\n result = JSON.parse(JSON.stringify(result))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["sanitizeInternalFields","withSession","updateGlobal","slug","data","req","Model","globals","options","lean","new","result","findOneAndUpdate","globalType","JSON","parse","stringify","id","_id"],"mappings":"AAIA,OAAOA,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAAmB,EAAE;IAE1C,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAU;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEI,IAAI;QAChCI,MAAM;QACNC,KAAK;IACP;IAEA,IAAIC;IACJA,SAAS,MAAML,MAAMM,gBAAgB,CAAC;QAAEC,YAAYV;IAAK,GAAGC,MAAMI;IAElEG,SAASG,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEnC,uBAAuB;IACvBA,OAAOM,EAAE,GAAGN,OAAOO,GAAG;IACtBP,SAASX,uBAAuBW;IAEhC,OAAOA;AACT,EAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { PayloadRequest, TypeWithID, UpdateGlobalVersionArgs } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global,\n locale,\n req = {} as PayloadRequest,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[global]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { PayloadRequest, TypeWithID, UpdateGlobalVersionArgs } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global,\n locale,\n req = {} as PayloadRequest,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[global]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, versionData, options)\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["withSession","updateGlobalVersion","id","global","locale","req","versionData","where","VersionModel","versions","whereToUse","equals","options","lean","new","query","buildQuery","payload","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,MAAM,EACNC,MAAM,EACNC,MAAM,CAAC,CAAmB,EAC1BC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,OAAO;IAC1C,MAAMO,aAAaH,SAAS;QAAEL,IAAI;YAAES,QAAQT;QAAG;IAAE;IACjD,MAAMU,UAAU;QACd,GAAI,MAAMZ,YAAY,IAAI,EAAEK,IAAI;QAChCQ,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMP,aAAaQ,UAAU,CAAC;QAC1CZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBV,OAAOG;IACT;IAEA,MAAMQ,MAAM,MAAMV,aAAaW,gBAAgB,CAACJ,OAAOT,aAAaM;IAEpE,MAAMQ,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOlB,EAAE,GAAGkB,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT"}
|
package/dist/updateOne.js
CHANGED
@@ -9,7 +9,7 @@ export const updateOne = async function updateOne({ id, collection, data, locale
|
|
9
9
|
} : whereArg;
|
10
10
|
const Model = this.collections[collection];
|
11
11
|
const options = {
|
12
|
-
...withSession(this, req
|
12
|
+
...await withSession(this, req),
|
13
13
|
lean: true,
|
14
14
|
new: true
|
15
15
|
};
|
package/dist/updateOne.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { PayloadRequest, UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { handleError } from './utilities/handleError.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n { id, collection, data, locale, req = {} as PayloadRequest, where: whereArg },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const options = {\n ...withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { PayloadRequest, UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { handleError } from './utilities/handleError.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n { id, collection, data, locale, req = {} as PayloadRequest, where: whereArg },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n let result\n\n try {\n result = await Model.findOneAndUpdate(query, data, options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n result = JSON.parse(JSON.stringify(result))\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["handleError","sanitizeInternalFields","withSession","updateOne","id","collection","data","locale","req","where","whereArg","equals","Model","collections","options","lean","new","query","buildQuery","payload","result","findOneAndUpdate","error","JSON","parse","stringify","_id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,6BAA4B;AACxD,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,OAAOC,QAAQ,EAAE;IAE7E,MAAMD,QAAQL,KAAK;QAAEA,IAAI;YAAEO,QAAQP;QAAG;IAAE,IAAIM;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACR,WAAW;IAC1C,MAAMS,UAAU;QACd,GAAI,MAAMZ,YAAY,IAAI,EAAEM,IAAI;QAChCO,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAML,MAAMM,UAAU,CAAC;QACnCX;QACAY,SAAS,IAAI,CAACA,OAAO;QACrBV;IACF;IAEA,IAAIW;IAEJ,IAAI;QACFA,SAAS,MAAMR,MAAMS,gBAAgB,CAACJ,OAAOX,MAAMQ;IACrD,EAAE,OAAOQ,OAAO;QACdtB,YAAY;YAAEK;YAAYiB;YAAOd;QAAI;IACvC;IAEAY,SAASG,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IACnCA,OAAOhB,EAAE,GAAGgB,OAAOM,GAAG;IACtBN,SAASnB,uBAAuBmB;IAEhC,OAAOA;AACT,EAAC"}
|
package/dist/updateVersion.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { PayloadRequest, UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n { id, collection, locale, req = {} as PayloadRequest, versionData, where },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...withSession(this, req
|
1
|
+
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { PayloadRequest, UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n { id, collection, locale, req = {} as PayloadRequest, versionData, where },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, versionData, options)\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["withSession","updateVersion","id","collection","locale","req","versionData","where","VersionModel","versions","whereToUse","equals","options","lean","new","query","buildQuery","payload","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,WAAW,EAAEC,KAAK,EAAE;IAE1E,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,WAAW;IAC9C,MAAMO,aAAaH,SAAS;QAAEL,IAAI;YAAES,QAAQT;QAAG;IAAE;IACjD,MAAMU,UAAU;QACd,GAAI,MAAMZ,YAAY,IAAI,EAAEK,IAAI;QAChCQ,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMP,aAAaQ,UAAU,CAAC;QAC1CZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBV,OAAOG;IACT;IAEA,MAAMQ,MAAM,MAAMV,aAAaW,gBAAgB,CAACJ,OAAOT,aAAaM;IAEpE,MAAMQ,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOlB,EAAE,GAAGkB,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
|
package/dist/withSession.d.ts
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
import type { ClientSession } from 'mongoose';
|
2
|
+
import type { PayloadRequest } from 'payload';
|
2
3
|
import type { MongooseAdapter } from './index.js';
|
3
4
|
/**
|
4
5
|
* returns the session belonging to the transaction of the req.session if exists
|
5
6
|
* @returns ClientSession
|
6
7
|
*/
|
7
|
-
export declare function withSession(db: MongooseAdapter,
|
8
|
+
export declare function withSession(db: MongooseAdapter, req: PayloadRequest): Promise<{
|
8
9
|
session: ClientSession;
|
9
|
-
} | object
|
10
|
+
} | object>;
|
10
11
|
//# sourceMappingURL=withSession.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"withSession.d.ts","sourceRoot":"","sources":["../src/withSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;;GAGG;AACH,
|
1
|
+
{"version":3,"file":"withSession.d.ts","sourceRoot":"","sources":["../src/withSession.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,YAAY,CAAA;AAEjD;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,EAAE,EAAE,eAAe,EACnB,GAAG,EAAE,cAAc,GAClB,OAAO,CAAC;IAAE,OAAO,EAAE,aAAa,CAAA;CAAE,GAAG,MAAM,CAAC,CAQ9C"}
|
package/dist/withSession.js
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
/**
|
2
2
|
* returns the session belonging to the transaction of the req.session if exists
|
3
3
|
* @returns ClientSession
|
4
|
-
*/ export function withSession(db,
|
5
|
-
|
4
|
+
*/ export async function withSession(db, req) {
|
5
|
+
let transactionID = req.transactionID;
|
6
|
+
if (transactionID instanceof Promise) {
|
7
|
+
transactionID = await req.transactionID;
|
8
|
+
}
|
9
|
+
if (req) return db.sessions[transactionID] ? {
|
6
10
|
session: db.sessions[transactionID]
|
7
11
|
} : {};
|
8
12
|
}
|
package/dist/withSession.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/withSession.ts"],"sourcesContent":["import type { ClientSession } from 'mongoose'\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 function withSession(\n db: MongooseAdapter,\n
|
1
|
+
{"version":3,"sources":["../src/withSession.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 withSession(\n db: MongooseAdapter,\n req: PayloadRequest,\n): Promise<{ session: ClientSession } | object> {\n let transactionID = req.transactionID\n\n if (transactionID instanceof Promise) {\n transactionID = await req.transactionID\n }\n\n if (req) return db.sessions[transactionID] ? { session: db.sessions[transactionID] } : {}\n}\n"],"names":["withSession","db","req","transactionID","Promise","sessions","session"],"mappings":"AAKA;;;CAGC,GACD,OAAO,eAAeA,YACpBC,EAAmB,EACnBC,GAAmB;IAEnB,IAAIC,gBAAgBD,IAAIC,aAAa;IAErC,IAAIA,yBAAyBC,SAAS;QACpCD,gBAAgB,MAAMD,IAAIC,aAAa;IACzC;IAEA,IAAID,KAAK,OAAOD,GAAGI,QAAQ,CAACF,cAAc,GAAG;QAAEG,SAASL,GAAGI,QAAQ,CAACF,cAAc;IAAC,IAAI,CAAC;AAC1F"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@payloadcms/db-mongodb",
|
3
|
-
"version": "3.0.0-canary.
|
3
|
+
"version": "3.0.0-canary.a0b06af",
|
4
4
|
"description": "The officially supported MongoDB database adapter for Payload",
|
5
5
|
"homepage": "https://payloadcms.com",
|
6
6
|
"repository": {
|
@@ -38,11 +38,11 @@
|
|
38
38
|
"@types/mongoose-aggregate-paginate-v2": "1.0.9",
|
39
39
|
"mongodb": "4.17.1",
|
40
40
|
"mongodb-memory-server": "^9",
|
41
|
-
"@payloadcms/eslint-config": "
|
42
|
-
"payload": "3.0.0-canary.
|
41
|
+
"@payloadcms/eslint-config": "3.0.0-beta.59",
|
42
|
+
"payload": "3.0.0-canary.a0b06af"
|
43
43
|
},
|
44
44
|
"peerDependencies": {
|
45
|
-
"payload": "3.0.0-canary.
|
45
|
+
"payload": "3.0.0-canary.a0b06af"
|
46
46
|
},
|
47
47
|
"scripts": {
|
48
48
|
"build": "pnpm build:types && pnpm build:swc",
|