@payloadcms/db-mongodb 3.84.0 → 3.85.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/deleteOne.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +10 -7
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +10 -7
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateJobs.d.ts.map +1 -1
- package/dist/updateJobs.js +11 -8
- package/dist/updateJobs.js.map +1 -1
- package/dist/updateMany.d.ts.map +1 -1
- package/dist/updateMany.js +11 -8
- package/dist/updateMany.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +10 -7
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +10 -7
- package/dist/updateVersion.js.map +1 -1
- package/package.json +6 -6
package/dist/deleteOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { DeleteOne } 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 deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { collection: collectionSlug, req, returning, select, where },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n where,\n })\n\n const options = {\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n } satisfies QueryOptions\n\n if (returning === false) {\n await Model.deleteOne(query, options)?.lean()\n return null\n }\n\n const doc = await Model.findOneAndDelete(query, options)?.lean()\n\n if (!doc) {\n return null\n }\n\n transform({\n adapter: this,\n data: doc,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildQuery","buildProjectionFromSelect","getCollection","getSession","transform","deleteOne","collection","collectionSlug","req","returning","select","where","collectionConfig","Model","adapter","query","fields","flattenedFields","options","projection","session","lean","doc","findOneAndDelete","data","operation"],"mappings":"AAKA,SAASA,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,YAAuB,eAAeA,UAEjD,EAAEC,YAAYC,cAAc,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAE7D,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGX,cAAc;QAAEY,SAAS,IAAI;QAAEP;IAAe;IAElF,MAAMQ,QAAQ,MAAMf,WAAW;QAC7Bc,SAAS,IAAI;QACbP;QACAS,QAAQJ,iBAAiBK,eAAe;QACxCN;IACF;IAEA,MAAMO,UAAU;QACdC,YAAYlB,0BAA0B;YACpCa,SAAS,IAAI;YACbE,QAAQJ,iBAAiBK,eAAe;YACxCP;QACF;QACAU,SAAS,MAAMjB,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAIC,cAAc,OAAO;QACvB,MAAMI,MAAMR,SAAS,CAACU,OAAOG,UAAUG;QACvC,OAAO;IACT;IAEA,MAAMC,MAAM,MAAMT,MAAMU,gBAAgB,CAACR,OAAOG,UAAUG;IAE1D,IAAI,CAACC,KAAK;QACR,OAAO;IACT;IAEAlB,UAAU;QACRU,SAAS,IAAI;QACbU,MAAMF;QACNN,QAAQJ,iBAAiBI,MAAM;QAC/BS,WAAW;IACb;IAEA,OAAOH;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAS3C,eAAO,MAAM,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAS3C,eAAO,MAAM,YAAY,EAAE,YAsC1B,CAAA"}
|
package/dist/updateGlobal.js
CHANGED
|
@@ -15,28 +15,31 @@ export const updateGlobal = async function updateGlobal({ slug: globalSlug, data
|
|
|
15
15
|
globalSlug,
|
|
16
16
|
operation: 'write'
|
|
17
17
|
});
|
|
18
|
-
const
|
|
18
|
+
const baseOptions = {
|
|
19
19
|
...optionsArgs,
|
|
20
|
+
session: await getSession(this, req),
|
|
21
|
+
// Timestamps are manually added by the write transform
|
|
22
|
+
timestamps: false
|
|
23
|
+
};
|
|
24
|
+
const findOptions = {
|
|
25
|
+
...baseOptions,
|
|
20
26
|
lean: true,
|
|
21
27
|
new: true,
|
|
22
28
|
projection: buildProjectionFromSelect({
|
|
23
29
|
adapter: this,
|
|
24
30
|
fields: globalConfig.flattenedFields,
|
|
25
31
|
select
|
|
26
|
-
})
|
|
27
|
-
session: await getSession(this, req),
|
|
28
|
-
// Timestamps are manually added by the write transform
|
|
29
|
-
timestamps: false
|
|
32
|
+
})
|
|
30
33
|
};
|
|
31
34
|
if (returning === false) {
|
|
32
35
|
await Model.updateOne({
|
|
33
36
|
globalType: globalSlug
|
|
34
|
-
}, data,
|
|
37
|
+
}, data, baseOptions);
|
|
35
38
|
return null;
|
|
36
39
|
}
|
|
37
40
|
const result = await Model.findOneAndUpdate({
|
|
38
41
|
globalType: globalSlug
|
|
39
|
-
}, data,
|
|
42
|
+
}, data, findOptions);
|
|
40
43
|
transform({
|
|
41
44
|
adapter: this,
|
|
42
45
|
data: result,
|
package/dist/updateGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug: globalSlug, data, options: optionsArgs = {}, req, returning, select },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug })\n\n const fields = globalConfig.fields\n\n transform({ adapter: this, data, fields, globalSlug, operation: 'write' })\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: globalConfig.flattenedFields,\n select,\n }),\n }\n\n if (returning === false) {\n await Model.updateOne({ globalType: globalSlug }, data, baseOptions)\n return null\n }\n\n const result: any = await Model.findOneAndUpdate({ globalType: globalSlug }, data, findOptions)\n\n transform({ adapter: this, data: result, fields, globalSlug, operation: 'read' })\n\n return result\n}\n"],"names":["buildProjectionFromSelect","getGlobal","getSession","transform","updateGlobal","slug","globalSlug","data","options","optionsArgs","req","returning","select","globalConfig","Model","adapter","fields","operation","baseOptions","session","timestamps","findOptions","lean","new","projection","flattenedFields","updateOne","globalType","result","findOneAndUpdate"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,MAAMC,UAAU,EAAEC,IAAI,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAE;IAE7E,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGb,UAAU;QAAEc,SAAS,IAAI;QAAET;IAAW;IAEtE,MAAMU,SAASH,aAAaG,MAAM;IAElCb,UAAU;QAAEY,SAAS,IAAI;QAAER;QAAMS;QAAQV;QAAYW,WAAW;IAAQ;IAExE,MAAMC,cAAc;QAClB,GAAGT,WAAW;QACdU,SAAS,MAAMjB,WAAW,IAAI,EAAEQ;QAChC,uDAAuD;QACvDU,YAAY;IACd;IAEA,MAAMC,cAA4B;QAChC,GAAGH,WAAW;QACdI,MAAM;QACNC,KAAK;QACLC,YAAYxB,0BAA0B;YACpCe,SAAS,IAAI;YACbC,QAAQH,aAAaY,eAAe;YACpCb;QACF;IACF;IAEA,IAAID,cAAc,OAAO;QACvB,MAAMG,MAAMY,SAAS,CAAC;YAAEC,YAAYrB;QAAW,GAAGC,MAAMW;QACxD,OAAO;IACT;IAEA,MAAMU,SAAc,MAAMd,MAAMe,gBAAgB,CAAC;QAAEF,YAAYrB;IAAW,GAAGC,MAAMc;IAEnFlB,UAAU;QAAEY,SAAS,IAAI;QAAER,MAAMqB;QAAQZ;QAAQV;QAAYW,WAAW;IAAO;IAE/E,OAAOW;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAIlE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAQjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EACzE,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,OAAO,EAAE,WAAgB,EACzB,GAAG,EACH,SAAS,EACT,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAIlE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAQjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EACzE,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,OAAO,EAAE,WAAgB,EACzB,GAAG,EACH,SAAS,EACT,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBAiD9B"}
|
|
@@ -29,24 +29,27 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, opti
|
|
|
29
29
|
fields,
|
|
30
30
|
operation: 'write'
|
|
31
31
|
});
|
|
32
|
-
const
|
|
32
|
+
const baseOptions = {
|
|
33
33
|
...optionsArgs,
|
|
34
|
+
session: await getSession(this, req),
|
|
35
|
+
// Timestamps are manually added by the write transform
|
|
36
|
+
timestamps: false
|
|
37
|
+
};
|
|
38
|
+
const findOptions = {
|
|
39
|
+
...baseOptions,
|
|
34
40
|
lean: true,
|
|
35
41
|
new: true,
|
|
36
42
|
projection: buildProjectionFromSelect({
|
|
37
43
|
adapter: this,
|
|
38
44
|
fields: flattenedFields,
|
|
39
45
|
select
|
|
40
|
-
})
|
|
41
|
-
session: await getSession(this, req),
|
|
42
|
-
// Timestamps are manually added by the write transform
|
|
43
|
-
timestamps: false
|
|
46
|
+
})
|
|
44
47
|
};
|
|
45
48
|
if (returning === false) {
|
|
46
|
-
await Model.updateOne(query, versionData,
|
|
49
|
+
await Model.updateOne(query, versionData, baseOptions);
|
|
47
50
|
return null;
|
|
48
51
|
}
|
|
49
|
-
const doc = await Model.findOneAndUpdate(query, versionData,
|
|
52
|
+
const doc = await Model.findOneAndUpdate(query, versionData, findOptions);
|
|
50
53
|
if (!doc) {
|
|
51
54
|
return null;
|
|
52
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { JsonObject, UpdateGlobalVersionArgs } from 'payload'\n\nimport { buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport async function updateGlobalVersion<T extends JsonObject = JsonObject>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n const whereToUse = where || { id: { equals: id } }\n\n const fields = buildVersionGlobalFields(this.payload.config, globalConfig)\n const flattenedFields = buildVersionGlobalFields(this.payload.config, globalConfig, 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 baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n }\n\n if (returning === false) {\n await Model.updateOne(query, versionData, baseOptions)\n return null\n }\n\n const doc = await Model.findOneAndUpdate(query, versionData, findOptions)\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":["buildVersionGlobalFields","buildQuery","buildProjectionFromSelect","getGlobal","getSession","transform","updateGlobalVersion","id","global","globalSlug","locale","options","optionsArgs","req","returning","select","versionData","where","globalConfig","Model","adapter","versions","whereToUse","equals","fields","payload","config","flattenedFields","query","data","operation","baseOptions","session","timestamps","findOptions","lean","new","projection","updateOne","doc","findOneAndUpdate"],"mappings":"AAGA,SAASA,wBAAwB,QAAQ,UAAS;AAIlD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,QAAQC,UAAU,EAClBC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGhB,UAAU;QAAEiB,SAAS,IAAI;QAAEX;QAAYY,UAAU;IAAK;IACtF,MAAMC,aAAaL,SAAS;QAAEV,IAAI;YAAEgB,QAAQhB;QAAG;IAAE;IAEjD,MAAMiB,SAASxB,yBAAyB,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAER;IAC7D,MAAMS,kBAAkB3B,yBAAyB,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAER,cAAc;IAEpF,MAAMU,QAAQ,MAAM3B,WAAW;QAC7BmB,SAAS,IAAI;QACbI,QAAQG;QACRjB;QACAO,OAAOK;IACT;IAEAjB,UAAU;QAAEe,SAAS,IAAI;QAAES,MAAMb;QAAaQ;QAAQM,WAAW;IAAQ;IAEzE,MAAMC,cAAc;QAClB,GAAGnB,WAAW;QACdoB,SAAS,MAAM5B,WAAW,IAAI,EAAES;QAChC,uDAAuD;QACvDoB,YAAY;IACd;IAEA,MAAMC,cAA4B;QAChC,GAAGH,WAAW;QACdI,MAAM;QACNC,KAAK;QACLC,YAAYnC,0BAA0B;YACpCkB,SAAS,IAAI;YACbI,QAAQG;YACRZ;QACF;IACF;IAEA,IAAID,cAAc,OAAO;QACvB,MAAMK,MAAMmB,SAAS,CAACV,OAAOZ,aAAae;QAC1C,OAAO;IACT;IAEA,MAAMQ,MAAM,MAAMpB,MAAMqB,gBAAgB,CAACZ,OAAOZ,aAAakB;IAE7D,IAAI,CAACK,KAAK;QACR,OAAO;IACT;IAEAlC,UAAU;QAAEe,SAAS,IAAI;QAAES,MAAMU;QAAKf;QAAQM,WAAW;IAAO;IAEhE,OAAOS;AACT"}
|
package/dist/updateJobs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateJobs.d.ts","sourceRoot":"","sources":["../src/updateJobs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAO,UAAU,EAAS,MAAM,SAAS,CAAA;AAWrD,eAAO,MAAM,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"updateJobs.d.ts","sourceRoot":"","sources":["../src/updateJobs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAO,UAAU,EAAS,MAAM,SAAS,CAAA;AAWrD,eAAO,MAAM,UAAU,EAAE,UAiIxB,CAAA"}
|
package/dist/updateJobs.js
CHANGED
|
@@ -62,18 +62,21 @@ export const updateJobs = async function updateMany({ id, data, limit, req, retu
|
|
|
62
62
|
updateOps.$set = updateData;
|
|
63
63
|
updateData = updateOps;
|
|
64
64
|
}
|
|
65
|
-
const
|
|
66
|
-
lean: true,
|
|
67
|
-
new: true,
|
|
65
|
+
const baseOptions = {
|
|
68
66
|
session: await getSession(this, req),
|
|
69
67
|
// Timestamps are manually added by the write transform
|
|
70
68
|
timestamps: false
|
|
71
69
|
};
|
|
70
|
+
const findOptions = {
|
|
71
|
+
...baseOptions,
|
|
72
|
+
lean: true,
|
|
73
|
+
new: true
|
|
74
|
+
};
|
|
72
75
|
let result = [];
|
|
73
76
|
try {
|
|
74
77
|
if (id) {
|
|
75
78
|
if (returning === false) {
|
|
76
|
-
await Model.updateOne(query, updateData,
|
|
79
|
+
await Model.updateOne(query, updateData, baseOptions);
|
|
77
80
|
transform({
|
|
78
81
|
adapter: this,
|
|
79
82
|
data,
|
|
@@ -82,7 +85,7 @@ export const updateJobs = async function updateMany({ id, data, limit, req, retu
|
|
|
82
85
|
});
|
|
83
86
|
return null;
|
|
84
87
|
} else {
|
|
85
|
-
const doc = await Model.findOneAndUpdate(query, updateData,
|
|
88
|
+
const doc = await Model.findOneAndUpdate(query, updateData, findOptions);
|
|
86
89
|
result = doc ? [
|
|
87
90
|
doc
|
|
88
91
|
] : [];
|
|
@@ -90,7 +93,7 @@ export const updateJobs = async function updateMany({ id, data, limit, req, retu
|
|
|
90
93
|
} else {
|
|
91
94
|
if (typeof limit === 'number' && limit > 0) {
|
|
92
95
|
const documentsToUpdate = await Model.find(query, {}, {
|
|
93
|
-
...
|
|
96
|
+
...findOptions,
|
|
94
97
|
limit,
|
|
95
98
|
projection: {
|
|
96
99
|
_id: 1
|
|
@@ -106,12 +109,12 @@ export const updateJobs = async function updateMany({ id, data, limit, req, retu
|
|
|
106
109
|
}
|
|
107
110
|
};
|
|
108
111
|
}
|
|
109
|
-
await Model.updateMany(query, updateData,
|
|
112
|
+
await Model.updateMany(query, updateData, baseOptions);
|
|
110
113
|
if (returning === false) {
|
|
111
114
|
return null;
|
|
112
115
|
}
|
|
113
116
|
result = await Model.find(query, {}, {
|
|
114
|
-
...
|
|
117
|
+
...findOptions,
|
|
115
118
|
sort
|
|
116
119
|
});
|
|
117
120
|
}
|
package/dist/updateJobs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\nimport type { Job, UpdateJobs, Where } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.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 updateJobs: UpdateJobs = async function updateMany(\n this: MongooseAdapter,\n { id, data, limit, req, returning, sort: sortArg, where: whereArg },\n) {\n if (\n !(data?.log as object[])?.length &&\n !(data.log && typeof data.log === 'object' && '$push' in data.log)\n ) {\n delete data.log\n }\n\n const where = id ? { id: { equals: id } } : (whereArg as Where)\n\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug: 'payload-jobs',\n })\n\n const sort: Record<string, unknown> | undefined = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n\n let query = await buildQuery({\n adapter: this,\n collectionSlug: collectionConfig.slug,\n fields: collectionConfig.flattenedFields,\n where,\n })\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: 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 = updateData\n updateData = updateOps\n }\n\n const baseOptions = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n new: true,\n }\n\n let result: Job[] = []\n\n try {\n if (id) {\n if (returning === false) {\n await Model.updateOne(query, updateData, baseOptions)\n transform({ adapter: this, data, fields: collectionConfig.fields, operation: 'read' })\n\n return null\n } else {\n const doc = await Model.findOneAndUpdate(query, updateData, findOptions)\n result = doc ? [doc] : []\n }\n } else {\n if (typeof limit === 'number' && limit > 0) {\n const documentsToUpdate = await Model.find(\n query,\n {},\n { ...findOptions, 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, updateData, baseOptions)\n\n if (returning === false) {\n return null\n }\n\n result = await Model.find(query, {}, { ...findOptions, sort })\n }\n } catch (error) {\n handleError({ collection: collectionConfig.slug, error, req })\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":["buildQuery","buildSortParam","getCollection","getSession","handleError","transform","updateJobs","updateMany","id","data","limit","req","returning","sort","sortArg","where","whereArg","log","length","equals","collectionConfig","Model","adapter","collectionSlug","config","payload","fields","flattenedFields","defaultSort","timestamps","query","slug","updateData","$inc","$push","$addToSet","$pull","operation","updateOps","Object","keys","$set","baseOptions","session","findOptions","lean","new","result","updateOne","doc","findOneAndUpdate","documentsTo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AAE,GAAGc,WAAW;oBAAElC;oBAAO2C,YAAY;wBAAEC,KAAK;oBAAE;oBAAGzC;gBAAK;gBAExD,IAAIsC,kBAAkBjC,MAAM,KAAK,GAAG;oBAClC,OAAO;gBACT;gBAEAY,QAAQ;oBAAEwB,KAAK;wBAAEC,KAAKJ,kBAAkBK,GAAG,CAAC,CAACP,MAAQA,IAAIK,GAAG;oBAAE;gBAAE;YAClE;YAEA,MAAMjC,MAAMd,UAAU,CAACuB,OAAOE,YAAYU;YAE1C,IAAI9B,cAAc,OAAO;gBACvB,OAAO;YACT;YAEAmC,SAAS,MAAM1B,MAAM+B,IAAI,CAACtB,OAAO,CAAC,GAAG;gBAAE,GAAGc,WAAW;gBAAE/B;YAAK;QAC9D;IACF,EAAE,OAAO4C,OAAO;QACdrD,YAAY;YAAEsD,YAAYtC,iBAAiBW,IAAI;YAAE0B;YAAO9C;QAAI;IAC9D;IAEAN,UAAU;QACRiB,SAAS,IAAI;QACbb,MAAMsC;QACNrB,QAAQN,iBAAiBM,MAAM;QAC/BW,WAAW;IACb;IAEA,OAAOU;AACT,EAAC"}
|
package/dist/updateMany.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../src/updateMany.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAYlE,eAAO,MAAM,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../src/updateMany.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAYlE,eAAO,MAAM,UAAU,EAAE,UAyIxB,CAAA"}
|
package/dist/updateMany.js
CHANGED
|
@@ -65,23 +65,26 @@ export const updateMany = async function updateMany({ collection: collectionSlug
|
|
|
65
65
|
updateOps.$set = data;
|
|
66
66
|
data = updateOps;
|
|
67
67
|
}
|
|
68
|
-
const
|
|
68
|
+
const baseOptions = {
|
|
69
69
|
...optionsArgs,
|
|
70
|
+
session: await getSession(this, req),
|
|
71
|
+
// Timestamps are manually added by the write transform
|
|
72
|
+
timestamps: false
|
|
73
|
+
};
|
|
74
|
+
const findOptions = {
|
|
75
|
+
...baseOptions,
|
|
70
76
|
lean: true,
|
|
71
77
|
new: true,
|
|
72
78
|
projection: buildProjectionFromSelect({
|
|
73
79
|
adapter: this,
|
|
74
80
|
fields: collectionConfig.flattenedFields,
|
|
75
81
|
select
|
|
76
|
-
})
|
|
77
|
-
session: await getSession(this, req),
|
|
78
|
-
// Timestamps are manually added by the write transform
|
|
79
|
-
timestamps: false
|
|
82
|
+
})
|
|
80
83
|
};
|
|
81
84
|
try {
|
|
82
85
|
if (typeof limit === 'number' && limit > 0) {
|
|
83
86
|
const documentsToUpdate = await Model.find(query, {}, {
|
|
84
|
-
...
|
|
87
|
+
...findOptions,
|
|
85
88
|
limit,
|
|
86
89
|
projection: {
|
|
87
90
|
_id: 1
|
|
@@ -97,7 +100,7 @@ export const updateMany = async function updateMany({ collection: collectionSlug
|
|
|
97
100
|
}
|
|
98
101
|
};
|
|
99
102
|
}
|
|
100
|
-
await Model.updateMany(query, data,
|
|
103
|
+
await Model.updateMany(query, data, baseOptions);
|
|
101
104
|
} catch (error) {
|
|
102
105
|
handleError({
|
|
103
106
|
collection: collectionSlug,
|
|
@@ -109,7 +112,7 @@ export const updateMany = async function updateMany({ collection: collectionSlug
|
|
|
109
112
|
return null;
|
|
110
113
|
}
|
|
111
114
|
const result = await Model.find(query, {}, {
|
|
112
|
-
...
|
|
115
|
+
...findOptions,
|
|
113
116
|
sort
|
|
114
117
|
});
|
|
115
118
|
transform({
|
package/dist/updateMany.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { QueryOptions, 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 baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n }\n\n try {\n if (typeof limit === 'number' && limit > 0) {\n const documentsToUpdate = await Model.find(\n query,\n {},\n { ...findOptions, 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, baseOptions)\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 ...findOptions,\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","baseOptions","session","findOptions","lean","new","projection","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,eAAe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,QAAQL,iBAAiBK,MAAM;QAC/BS,WAAW;IACb;IAEA,OAAOiB;AACT,EAAC"}
|
package/dist/updateOne.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAWxC,eAAO,MAAM,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAWxC,eAAO,MAAM,SAAS,EAAE,SAsGvB,CAAA"}
|
package/dist/updateOne.js
CHANGED
|
@@ -55,22 +55,25 @@ export const updateOne = async function updateOne({ id, collection: collectionSl
|
|
|
55
55
|
updateOps.$set = updateData;
|
|
56
56
|
updateData = updateOps;
|
|
57
57
|
}
|
|
58
|
-
const
|
|
58
|
+
const baseOptions = {
|
|
59
59
|
...optionsArgs,
|
|
60
|
+
session: await getSession(this, req),
|
|
61
|
+
// Timestamps are manually added by the write transform
|
|
62
|
+
timestamps: false
|
|
63
|
+
};
|
|
64
|
+
const findOptions = {
|
|
65
|
+
...baseOptions,
|
|
60
66
|
lean: true,
|
|
61
67
|
new: true,
|
|
62
68
|
projection: buildProjectionFromSelect({
|
|
63
69
|
adapter: this,
|
|
64
70
|
fields: collectionConfig.flattenedFields,
|
|
65
71
|
select
|
|
66
|
-
})
|
|
67
|
-
session: await getSession(this, req),
|
|
68
|
-
// Timestamps are manually added by the write transform
|
|
69
|
-
timestamps: false
|
|
72
|
+
})
|
|
70
73
|
};
|
|
71
74
|
try {
|
|
72
75
|
if (returning === false) {
|
|
73
|
-
await Model.updateOne(query, updateData,
|
|
76
|
+
await Model.updateOne(query, updateData, baseOptions);
|
|
74
77
|
transform({
|
|
75
78
|
adapter: this,
|
|
76
79
|
data,
|
|
@@ -79,7 +82,7 @@ export const updateOne = async function updateOne({ id, collection: collectionSl
|
|
|
79
82
|
});
|
|
80
83
|
return null;
|
|
81
84
|
} else {
|
|
82
|
-
result = await Model.findOneAndUpdate(query, updateData,
|
|
85
|
+
result = await Model.findOneAndUpdate(query, updateData, findOptions);
|
|
83
86
|
}
|
|
84
87
|
} catch (error) {
|
|
85
88
|
handleError({
|
package/dist/updateOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions, 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 baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n }\n\n try {\n if (returning === false) {\n await Model.updateOne(query, updateData, baseOptions)\n transform({ adapter: this, data, fields, operation: 'read' })\n return null\n } else {\n result = await Model.findOneAndUpdate(query, updateData, findOptions)\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","baseOptions","session","timestamps","findOptions","lean","new","projection","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,M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NC,KAAK;QACLC,YAAY3C,0BAA0B;YACpCoB,SAAS,IAAI;YACbE,QAAQJ,iBAAiBM,eAAe;YACxCT;QACF;IACF;IAEA,IAAI;QACF,IAAID,cAAc,OAAO;YACvB,MAAMK,MAAMd,SAAS,CAACkB,OAAOG,YAAYW;YACzCjC,UAAU;gBAAEgB,SAAS,IAAI;gBAAEX;gBAAMa;gBAAQS,WAAW;YAAO;YAC3D,OAAO;QACT,OAAO;YACLN,SAAS,MAAMN,MAAMyB,gBAAgB,CAACrB,OAAOG,YAAYc;QAC3D;IACF,EAAE,OAAOK,OAAO;QACd1C,YAAY;YAAEI,YAAYC;YAAgBqC;YAAOhC;QAAI;IACvD;IAEA,IAAI,CAACY,QAAQ;QACX,OAAO;IACT;IAEArB,UAAU;QAAEgB,SAAS,IAAI;QAAEX,MAAMgB;QAAQH;QAAQS,WAAW;IAAO;IAEnE,OAAON;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAU1E,eAAO,MAAM,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAU1E,eAAO,MAAM,aAAa,EAAE,aAkE3B,CAAA"}
|
package/dist/updateVersion.js
CHANGED
|
@@ -29,24 +29,27 @@ export const updateVersion = async function updateVersion({ id, collection: coll
|
|
|
29
29
|
fields,
|
|
30
30
|
operation: 'write'
|
|
31
31
|
});
|
|
32
|
-
const
|
|
32
|
+
const baseOptions = {
|
|
33
33
|
...optionsArgs,
|
|
34
|
+
session: await getSession(this, req),
|
|
35
|
+
// Timestamps are manually added by the write transform
|
|
36
|
+
timestamps: false
|
|
37
|
+
};
|
|
38
|
+
const findOptions = {
|
|
39
|
+
...baseOptions,
|
|
34
40
|
lean: true,
|
|
35
41
|
new: true,
|
|
36
42
|
projection: buildProjectionFromSelect({
|
|
37
43
|
adapter: this,
|
|
38
44
|
fields: flattenedFields,
|
|
39
45
|
select
|
|
40
|
-
})
|
|
41
|
-
session: await getSession(this, req),
|
|
42
|
-
// Timestamps are manually added by the write transform
|
|
43
|
-
timestamps: false
|
|
46
|
+
})
|
|
44
47
|
};
|
|
45
48
|
if (returning === false) {
|
|
46
|
-
await Model.updateOne(query, versionData,
|
|
49
|
+
await Model.updateOne(query, versionData, baseOptions);
|
|
47
50
|
return null;
|
|
48
51
|
}
|
|
49
|
-
const doc = await Model.findOneAndUpdate(query, versionData,
|
|
52
|
+
const doc = await Model.findOneAndUpdate(query, versionData, findOptions);
|
|
50
53
|
if (!doc) {
|
|
51
54
|
return null;
|
|
52
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { QueryOptions } 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 baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n }\n\n if (returning === false) {\n await Model.updateOne(query, versionData, baseOptions)\n return null\n }\n\n const doc = await Model.findOneAndUpdate(query, versionData, findOptions)\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","baseOptions","session","timestamps","findOptions","lean","new","projection","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,cAEzD,EACEC,EAAE,EACFC,YAAYC,cAAc,EAC1BC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,WAAW,EACXC,KAAK,EACN;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGhB,cAAc;QAChDiB,SAAS,IAAI;QACbX;QACAY,UAAU;IACZ;IAEA,MAAMC,aAAaL,SAAS;QAAEV,IAAI;YAAEgB,QAAQhB;QAAG;IAAE;IACjD,MAAMiB,SAASxB,6BAA6B,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAER;IAEjE,MAAMS,kBAAkB3B,6BAA6B,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAER,kBAAkB;IAE5F,MAAMU,QAAQ,MAAM3B,WAAW;QAC7BmB,SAAS,IAAI;QACbI,QAAQG;QACRjB;QACAO,OAAOK;IACT;IAEAjB,UAAU;QAAEe,SAAS,IAAI;QAAES,MAAMb;QAAaQ;QAAQM,WAAW;IAAQ;IAEzE,MAAMC,cAAc;QAClB,GAAGnB,WAAW;QACdoB,SAAS,MAAM5B,WAAW,IAAI,EAAES;QAChC,uDAAuD;QACvDoB,YAAY;IACd;IAEA,MAAMC,cAA4B;QAChC,GAAGH,WAAW;QACdI,MAAM;QACNC,KAAK;QACLC,YAAYnC,0BAA0B;YACpCkB,SAAS,IAAI;YACbI,QAAQG;YACRZ;QACF;IACF;IAEA,IAAID,cAAc,OAAO;QACvB,MAAMK,MAAMmB,SAAS,CAACV,OAAOZ,aAAae;QAC1C,OAAO;IACT;IAEA,MAAMQ,MAAM,MAAMpB,MAAMqB,gBAAgB,CAACZ,OAAOZ,aAAakB;IAE7D,IAAI,CAACK,KAAK;QACR,OAAO;IACT;IAEAlC,UAAU;QAAEe,SAAS,IAAI;QAAES,MAAMU;QAAKf;QAAQM,WAAW;IAAO;IAEhE,OAAOS;AACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/db-mongodb",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.85.0",
|
|
4
4
|
"description": "The officially supported MongoDB database adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -43,21 +43,21 @@
|
|
|
43
43
|
"predefinedMigrations"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"mongoose": "8.
|
|
46
|
+
"mongoose": "8.22.1",
|
|
47
47
|
"mongoose-paginate-v2": "1.9.4",
|
|
48
48
|
"prompts": "2.4.2",
|
|
49
|
-
"uuid": "
|
|
49
|
+
"uuid": "13.0.2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/mongoose-aggregate-paginate-v2": "1.0.12",
|
|
53
53
|
"@types/prompts": "^2.4.5",
|
|
54
|
-
"mongodb": "6.
|
|
54
|
+
"mongodb": "6.20.0",
|
|
55
55
|
"mongodb-memory-server": "10.1.4",
|
|
56
56
|
"@payloadcms/eslint-config": "3.28.0",
|
|
57
|
-
"payload": "3.
|
|
57
|
+
"payload": "3.85.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"payload": "3.
|
|
60
|
+
"payload": "3.85.0"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "pnpm build:types && pnpm build:swc",
|