@payloadcms/db-mongodb 3.24.0 → 3.25.0-canary.6d6bbd2
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/create.js +15 -15
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +15 -14
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +26 -23
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +26 -31
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +8 -6
- package/dist/deleteOne.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +8 -9
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +10 -9
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +10 -10
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +8 -6
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.js +8 -9
- package/dist/findVersions.js.map +1 -1
- package/dist/models/buildSchema.js +2 -0
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +12 -7
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +16 -0
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queryDrafts.js +13 -13
- package/dist/queryDrafts.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +15 -15
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +13 -13
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +12 -9
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +13 -13
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/transform.d.ts +27 -0
- package/dist/utilities/transform.d.ts.map +1 -0
- package/dist/utilities/transform.js +224 -0
- package/dist/utilities/transform.js.map +1 -0
- package/dist/utilities/{sanitizeRelationshipIDs.spec.js → transform.spec.js} +11 -5
- package/dist/utilities/transform.spec.js.map +1 -0
- package/package.json +3 -3
- package/dist/utilities/sanitizeInternalFields.d.ts +0 -2
- package/dist/utilities/sanitizeInternalFields.d.ts.map +0 -1
- package/dist/utilities/sanitizeInternalFields.js +0 -20
- package/dist/utilities/sanitizeInternalFields.js.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +0 -10
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.js +0 -130
- package/dist/utilities/sanitizeRelationshipIDs.js.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +0 -1
package/dist/create.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { getSession } from './utilities/getSession.js';
|
|
2
2
|
import { handleError } from './utilities/handleError.js';
|
|
3
|
-
import {
|
|
3
|
+
import { transform } from './utilities/transform.js';
|
|
4
4
|
export const create = async function create({ collection, data, req }) {
|
|
5
5
|
const Model = this.collections[collection];
|
|
6
6
|
const options = {
|
|
7
7
|
session: await getSession(this, req)
|
|
8
8
|
};
|
|
9
9
|
let doc;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
transform({
|
|
11
|
+
adapter: this,
|
|
12
12
|
data,
|
|
13
|
-
fields: this.payload.collections[collection].config.fields
|
|
13
|
+
fields: this.payload.collections[collection].config.fields,
|
|
14
|
+
operation: 'write'
|
|
14
15
|
});
|
|
15
16
|
if (this.payload.collections[collection].customIDType) {
|
|
16
|
-
|
|
17
|
+
data._id = data.id;
|
|
17
18
|
}
|
|
18
19
|
try {
|
|
19
20
|
;
|
|
20
21
|
[doc] = await Model.create([
|
|
21
|
-
|
|
22
|
+
data
|
|
22
23
|
], options);
|
|
23
24
|
} catch (error) {
|
|
24
25
|
handleError({
|
|
@@ -27,15 +28,14 @@ export const create = async function create({ collection, data, req }) {
|
|
|
27
28
|
req
|
|
28
29
|
});
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return result;
|
|
31
|
+
doc = doc.toObject();
|
|
32
|
+
transform({
|
|
33
|
+
adapter: this,
|
|
34
|
+
data: doc,
|
|
35
|
+
fields: this.payload.collections[collection].config.fields,
|
|
36
|
+
operation: 'read'
|
|
37
|
+
});
|
|
38
|
+
return doc;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
//# sourceMappingURL=create.js.map
|
package/dist/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { CreateOptions } from 'mongoose'\nimport type { Create, Document } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { CreateOptions } from 'mongoose'\nimport type { Create, Document } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const create: Create = async function create(\n this: MongooseAdapter,\n { collection, data, req },\n) {\n const Model = this.collections[collection]\n const options: CreateOptions = {\n session: await getSession(this, req),\n }\n\n let doc\n\n transform({\n adapter: this,\n data,\n fields: this.payload.collections[collection].config.fields,\n operation: 'write',\n })\n\n if (this.payload.collections[collection].customIDType) {\n data._id = data.id\n }\n\n try {\n ;[doc] = await Model.create([data], options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields: this.payload.collections[collection].config.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["getSession","handleError","transform","create","collection","data","req","Model","collections","options","session","doc","adapter","fields","payload","config","operation","customIDType","_id","id","error","toObject"],"mappings":"AAKA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,SAAiB,eAAeA,OAE3C,EAAEC,UAAU,EAAEC,IAAI,EAAEC,GAAG,EAAE;IAEzB,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAyB;QAC7BC,SAAS,MAAMV,WAAW,IAAI,EAAEM;IAClC;IAEA,IAAIK;IAEJT,UAAU;QACRU,SAAS,IAAI;QACbP;QACAQ,QAAQ,IAAI,CAACC,OAAO,CAACN,WAAW,CAACJ,WAAW,CAACW,MAAM,CAACF,MAAM;QAC1DG,WAAW;IACb;IAEA,IAAI,IAAI,CAACF,OAAO,CAACN,WAAW,CAACJ,WAAW,CAACa,YAAY,EAAE;QACrDZ,KAAKa,GAAG,GAAGb,KAAKc,EAAE;IACpB;IAEA,IAAI;;QACD,CAACR,IAAI,GAAG,MAAMJ,MAAMJ,MAAM,CAAC;YAACE;SAAK,EAAEI;IACtC,EAAE,OAAOW,OAAO;QACdnB,YAAY;YAAEG;YAAYgB;YAAOd;QAAI;IACvC;IAEAK,MAAMA,IAAIU,QAAQ;IAElBnB,UAAU;QACRU,SAAS,IAAI;QACbP,MAAMM;QACNE,QAAQ,IAAI,CAACC,OAAO,CAACN,WAAW,CAACJ,WAAW,CAACW,MAAM,CAACF,MAAM;QAC1DG,WAAW;IACb;IAEA,OAAOL;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createGlobal.d.ts","sourceRoot":"","sources":["../src/createGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"createGlobal.d.ts","sourceRoot":"","sources":["../src/createGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAO3C,eAAO,MAAM,YAAY,EAAE,YA8B1B,CAAA"}
|
package/dist/createGlobal.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import { getSession } from './utilities/getSession.js';
|
|
2
|
-
import {
|
|
3
|
-
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
2
|
+
import { transform } from './utilities/transform.js';
|
|
4
3
|
export const createGlobal = async function createGlobal({ slug, data, req }) {
|
|
5
4
|
const Model = this.globals;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
data
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
fields: this.payload.config.globals.find((globalConfig)=>globalConfig.slug === slug).fields
|
|
5
|
+
transform({
|
|
6
|
+
adapter: this,
|
|
7
|
+
data,
|
|
8
|
+
fields: this.payload.config.globals.find((globalConfig)=>globalConfig.slug === slug).fields,
|
|
9
|
+
globalSlug: slug,
|
|
10
|
+
operation: 'write'
|
|
13
11
|
});
|
|
14
12
|
const options = {
|
|
15
13
|
session: await getSession(this, req)
|
|
16
14
|
};
|
|
17
15
|
let [result] = await Model.create([
|
|
18
|
-
|
|
16
|
+
data
|
|
19
17
|
], options);
|
|
20
|
-
result =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
result = result.toObject();
|
|
19
|
+
transform({
|
|
20
|
+
adapter: this,
|
|
21
|
+
data: result,
|
|
22
|
+
fields: this.payload.config.globals.find((globalConfig)=>globalConfig.slug === slug).fields,
|
|
23
|
+
operation: 'read'
|
|
24
|
+
});
|
|
24
25
|
return result;
|
|
25
26
|
};
|
|
26
27
|
|
package/dist/createGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createGlobal.ts"],"sourcesContent":["import type { CreateOptions } from 'mongoose'\nimport type { CreateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/createGlobal.ts"],"sourcesContent":["import type { CreateOptions } from 'mongoose'\nimport type { CreateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const createGlobal: CreateGlobal = async function createGlobal(\n this: MongooseAdapter,\n { slug, data, req },\n) {\n const Model = this.globals\n\n transform({\n adapter: this,\n data,\n fields: this.payload.config.globals.find((globalConfig) => globalConfig.slug === slug).fields,\n globalSlug: slug,\n operation: 'write',\n })\n\n const options: CreateOptions = {\n session: await getSession(this, req),\n }\n\n let [result] = (await Model.create([data], options)) as any\n\n result = result.toObject()\n\n transform({\n adapter: this,\n data: result,\n fields: this.payload.config.globals.find((globalConfig) => globalConfig.slug === slug).fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["getSession","transform","createGlobal","slug","data","req","Model","globals","adapter","fields","payload","config","find","globalConfig","globalSlug","operation","options","session","result","create","toObject"],"mappings":"AAKA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,GAAG,EAAE;IAEnB,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAE1BN,UAAU;QACRO,SAAS,IAAI;QACbJ;QACAK,QAAQ,IAAI,CAACC,OAAO,CAACC,MAAM,CAACJ,OAAO,CAACK,IAAI,CAAC,CAACC,eAAiBA,aAAaV,IAAI,KAAKA,MAAMM,MAAM;QAC7FK,YAAYX;QACZY,WAAW;IACb;IAEA,MAAMC,UAAyB;QAC7BC,SAAS,MAAMjB,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAI,CAACa,OAAO,GAAI,MAAMZ,MAAMa,MAAM,CAAC;QAACf;KAAK,EAAEY;IAE3CE,SAASA,OAAOE,QAAQ;IAExBnB,UAAU;QACRO,SAAS,IAAI;QACbJ,MAAMc;QACNT,QAAQ,IAAI,CAACC,OAAO,CAACC,MAAM,CAACJ,OAAO,CAACK,IAAI,CAAC,CAACC,eAAiBA,aAAaV,IAAI,KAAKA,MAAMM,MAAM;QAC7FM,WAAW;IACb;IAEA,OAAOG;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,KAAK,mBAAmB,
|
|
1
|
+
{"version":3,"file":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAO5E,eAAO,MAAM,mBAAmB,EAAE,mBA8EjC,CAAA"}
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import { buildVersionGlobalFields } from 'payload';
|
|
2
2
|
import { getSession } from './utilities/getSession.js';
|
|
3
|
-
import {
|
|
3
|
+
import { transform } from './utilities/transform.js';
|
|
4
4
|
export const createGlobalVersion = async function createGlobalVersion({ autosave, createdAt, globalSlug, parent, publishedLocale, req, snapshot, updatedAt, versionData }) {
|
|
5
5
|
const VersionModel = this.versions[globalSlug];
|
|
6
6
|
const options = {
|
|
7
7
|
session: await getSession(this, req)
|
|
8
8
|
};
|
|
9
|
-
const data =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
const data = {
|
|
10
|
+
autosave,
|
|
11
|
+
createdAt,
|
|
12
|
+
latest: true,
|
|
13
|
+
parent,
|
|
14
|
+
publishedLocale,
|
|
15
|
+
snapshot,
|
|
16
|
+
updatedAt,
|
|
17
|
+
version: versionData
|
|
18
|
+
};
|
|
19
|
+
const fields = buildVersionGlobalFields(this.payload.config, this.payload.config.globals.find((global)=>global.slug === globalSlug));
|
|
20
|
+
transform({
|
|
21
|
+
adapter: this,
|
|
22
|
+
data,
|
|
23
|
+
fields,
|
|
24
|
+
operation: 'write'
|
|
22
25
|
});
|
|
23
|
-
|
|
26
|
+
let [doc] = await VersionModel.create([
|
|
24
27
|
data
|
|
25
28
|
], options, req);
|
|
26
29
|
await VersionModel.updateMany({
|
|
@@ -46,14 +49,14 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
|
|
|
46
49
|
latest: 1
|
|
47
50
|
}
|
|
48
51
|
}, options);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
return
|
|
52
|
+
doc = doc.toObject();
|
|
53
|
+
transform({
|
|
54
|
+
adapter: this,
|
|
55
|
+
data: doc,
|
|
56
|
+
fields,
|
|
57
|
+
operation: 'read'
|
|
58
|
+
});
|
|
59
|
+
return doc;
|
|
57
60
|
};
|
|
58
61
|
|
|
59
62
|
//# sourceMappingURL=createGlobalVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import type { CreateOptions } from 'mongoose'\n\nimport { buildVersionGlobalFields, type CreateGlobalVersion
|
|
1
|
+
{"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import type { CreateOptions } from 'mongoose'\n\nimport { buildVersionGlobalFields, type CreateGlobalVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const createGlobalVersion: CreateGlobalVersion = async function createGlobalVersion(\n this: MongooseAdapter,\n {\n autosave,\n createdAt,\n globalSlug,\n parent,\n publishedLocale,\n req,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const VersionModel = this.versions[globalSlug]\n const options: CreateOptions = {\n session: await getSession(this, req),\n }\n\n const data = {\n autosave,\n createdAt,\n latest: true,\n parent,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n }\n\n const fields = buildVersionGlobalFields(\n this.payload.config,\n this.payload.config.globals.find((global) => global.slug === globalSlug),\n )\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n let [doc] = await VersionModel.create([data], options, req)\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 doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildVersionGlobalFields","getSession","transform","createGlobalVersion","autosave","createdAt","globalSlug","parent","publishedLocale","req","snapshot","updatedAt","versionData","VersionModel","versions","options","session","data","latest","version","fields","payload","config","globals","find","global","slug","adapter","operation","doc","create","updateMany","$and","_id","$ne","$eq","$unset","toObject"],"mappings":"AAEA,SAASA,wBAAwB,QAAkC,UAAS;AAI5E,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EACEC,QAAQ,EACRC,SAAS,EACTC,UAAU,EACVC,MAAM,EACNC,eAAe,EACfC,GAAG,EACHC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACZ;IAED,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACR,WAAW;IAC9C,MAAMS,UAAyB;QAC7BC,SAAS,MAAMf,WAAW,IAAI,EAAEQ;IAClC;IAEA,MAAMQ,OAAO;QACXb;QACAC;QACAa,QAAQ;QACRX;QACAC;QACAE;QACAC;QACAQ,SAASP;IACX;IAEA,MAAMQ,SAASpB,yBACb,IAAI,CAACqB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACC,MAAM,CAACC,OAAO,CAACC,IAAI,CAAC,CAACC,SAAWA,OAAOC,IAAI,KAAKpB;IAG/DJ,UAAU;QACRyB,SAAS,IAAI;QACbV;QACAG;QACAQ,WAAW;IACb;IAEA,IAAI,CAACC,IAAI,GAAG,MAAMhB,aAAaiB,MAAM,CAAC;QAACb;KAAK,EAAEF,SAASN;IAEvD,MAAMI,aAAakB,UAAU,CAC3B;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKL,IAAII,GAAG;gBACd;YACF;YACA;gBACE1B,QAAQ;oBACN4B,KAAK5B;gBACP;YACF;YACA;gBACEW,QAAQ;oBACNiB,KAAK;gBACP;YACF;SACD;IACH,GACA;QAAEC,QAAQ;YAAElB,QAAQ;QAAE;IAAE,GACxBH;IAGFc,MAAMA,IAAIQ,QAAQ;IAElBnC,UAAU;QACRyB,SAAS,IAAI;QACbV,MAAMY;QACNT;QACAQ,WAAW;IACb;IAEA,OAAOC;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createVersion.d.ts","sourceRoot":"","sources":["../src/createVersion.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createVersion.d.ts","sourceRoot":"","sources":["../src/createVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAO1E,eAAO,MAAM,aAAa,EAAE,aAyF3B,CAAA"}
|
package/dist/createVersion.js
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
import { Types } from 'mongoose';
|
|
2
1
|
import { buildVersionCollectionFields } from 'payload';
|
|
3
2
|
import { getSession } from './utilities/getSession.js';
|
|
4
|
-
import {
|
|
3
|
+
import { transform } from './utilities/transform.js';
|
|
5
4
|
export const createVersion = async function createVersion({ autosave, collectionSlug, createdAt, parent, publishedLocale, req, snapshot, updatedAt, versionData }) {
|
|
6
5
|
const VersionModel = this.versions[collectionSlug];
|
|
7
6
|
const options = {
|
|
8
7
|
session: await getSession(this, req)
|
|
9
8
|
};
|
|
10
|
-
const data =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
const data = {
|
|
10
|
+
autosave,
|
|
11
|
+
createdAt,
|
|
12
|
+
latest: true,
|
|
13
|
+
parent,
|
|
14
|
+
publishedLocale,
|
|
15
|
+
snapshot,
|
|
16
|
+
updatedAt,
|
|
17
|
+
version: versionData
|
|
18
|
+
};
|
|
19
|
+
const fields = buildVersionCollectionFields(this.payload.config, this.payload.collections[collectionSlug].config);
|
|
20
|
+
transform({
|
|
21
|
+
adapter: this,
|
|
22
|
+
data,
|
|
23
|
+
fields,
|
|
24
|
+
operation: 'write'
|
|
23
25
|
});
|
|
24
|
-
|
|
26
|
+
let [doc] = await VersionModel.create([
|
|
25
27
|
data
|
|
26
28
|
], options, req);
|
|
27
29
|
const parentQuery = {
|
|
@@ -33,13 +35,6 @@ export const createVersion = async function createVersion({ autosave, collection
|
|
|
33
35
|
}
|
|
34
36
|
]
|
|
35
37
|
};
|
|
36
|
-
if (data.parent instanceof Types.ObjectId) {
|
|
37
|
-
parentQuery.$or.push({
|
|
38
|
-
parent: {
|
|
39
|
-
$eq: data.parent.toString()
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
38
|
await VersionModel.updateMany({
|
|
44
39
|
$and: [
|
|
45
40
|
{
|
|
@@ -64,14 +59,14 @@ export const createVersion = async function createVersion({ autosave, collection
|
|
|
64
59
|
latest: 1
|
|
65
60
|
}
|
|
66
61
|
}, options);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
return
|
|
62
|
+
doc = doc.toObject();
|
|
63
|
+
transform({
|
|
64
|
+
adapter: this,
|
|
65
|
+
data: doc,
|
|
66
|
+
fields,
|
|
67
|
+
operation: 'read'
|
|
68
|
+
});
|
|
69
|
+
return doc;
|
|
75
70
|
};
|
|
76
71
|
|
|
77
72
|
//# sourceMappingURL=createVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import type { CreateOptions } from 'mongoose'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import type { CreateOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type CreateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const createVersion: CreateVersion = async function createVersion(\n this: MongooseAdapter,\n {\n autosave,\n collectionSlug,\n createdAt,\n parent,\n publishedLocale,\n req,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const VersionModel = this.versions[collectionSlug]\n const options: CreateOptions = {\n session: await getSession(this, req),\n }\n\n const data = {\n autosave,\n createdAt,\n latest: true,\n parent,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n }\n\n const fields = buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collectionSlug].config,\n )\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n let [doc] = await VersionModel.create([data], options, req)\n\n const parentQuery = {\n $or: [\n {\n parent: {\n $eq: data.parent,\n },\n },\n ],\n }\n\n await VersionModel.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n parentQuery,\n {\n latest: {\n $eq: true,\n },\n },\n {\n updatedAt: {\n $lt: new Date(doc.updatedAt),\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildVersionCollectionFields","getSession","transform","createVersion","autosave","collectionSlug","createdAt","parent","publishedLocale","req","snapshot","updatedAt","versionData","VersionModel","versions","options","session","data","latest","version","fields","payload","config","collections","adapter","operation","doc","create","parentQuery","$or","$eq","updateMany","$and","_id","$ne","$lt","Date","$unset","toObject"],"mappings":"AAEA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,eAAe,EACfC,GAAG,EACHC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACZ;IAED,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACT,eAAe;IAClD,MAAMU,UAAyB;QAC7BC,SAAS,MAAMf,WAAW,IAAI,EAAEQ;IAClC;IAEA,MAAMQ,OAAO;QACXb;QACAE;QACAY,QAAQ;QACRX;QACAC;QACAE;QACAC;QACAQ,SAASP;IACX;IAEA,MAAMQ,SAASpB,6BACb,IAAI,CAACqB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAAClB,eAAe,CAACiB,MAAM;IAGjDpB,UAAU;QACRsB,SAAS,IAAI;QACbP;QACAG;QACAK,WAAW;IACb;IAEA,IAAI,CAACC,IAAI,GAAG,MAAMb,aAAac,MAAM,CAAC;QAACV;KAAK,EAAEF,SAASN;IAEvD,MAAMmB,cAAc;QAClBC,KAAK;YACH;gBACEtB,QAAQ;oBACNuB,KAAKb,KAAKV,MAAM;gBAClB;YACF;SACD;IACH;IAEA,MAAMM,aAAakB,UAAU,CAC3B;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKR,IAAIO,GAAG;gBACd;YACF;YACAL;YACA;gBACEV,QAAQ;oBACNY,KAAK;gBACP;YACF;YACA;gBACEnB,WAAW;oBACTwB,KAAK,IAAIC,KAAKV,IAAIf,SAAS;gBAC7B;YACF;SACD;IACH,GACA;QAAE0B,QAAQ;YAAEnB,QAAQ;QAAE;IAAE,GACxBH;IAGFW,MAAMA,IAAIY,QAAQ;IAElBpC,UAAU;QACRsB,SAAS,IAAI;QACbP,MAAMS;QACNN;QACAK,WAAW;IACb;IAEA,OAAOC;AACT,EAAC"}
|
package/dist/deleteOne.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AASxC,eAAO,MAAM,SAAS,EAAE,SAmCvB,CAAA"}
|
package/dist/deleteOne.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { buildQuery } from './queries/buildQuery.js';
|
|
2
2
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
3
|
import { getSession } from './utilities/getSession.js';
|
|
4
|
-
import {
|
|
4
|
+
import { transform } from './utilities/transform.js';
|
|
5
5
|
export const deleteOne = async function deleteOne({ collection, req, select, where }) {
|
|
6
6
|
const Model = this.collections[collection];
|
|
7
7
|
const options = {
|
|
@@ -22,11 +22,13 @@ export const deleteOne = async function deleteOne({ collection, req, select, whe
|
|
|
22
22
|
if (!doc) {
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
transform({
|
|
26
|
+
adapter: this,
|
|
27
|
+
data: doc,
|
|
28
|
+
fields: this.payload.collections[collection].config.fields,
|
|
29
|
+
operation: 'read'
|
|
30
|
+
});
|
|
31
|
+
return doc;
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
//# sourceMappingURL=deleteOne.js.map
|
package/dist/deleteOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { DeleteOne
|
|
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 { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { collection, req, select, where },\n) {\n const Model = this.collections[collection]\n const options: QueryOptions = {\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.collections[collection].config.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collection,\n fields: this.payload.collections[collection].config.flattenedFields,\n where,\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: this.payload.collections[collection].config.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildQuery","buildProjectionFromSelect","getSession","transform","deleteOne","collection","req","select","where","Model","collections","options","projection","adapter","fields","payload","config","flattenedFields","session","query","collectionSlug","doc","findOneAndDelete","lean","data","operation"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,UAAU,EAAEC,GAAG,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAElC,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAwB;QAC5BC,YAAYX,0BAA0B;YACpCY,SAAS,IAAI;YACbC,QAAQ,IAAI,CAACC,OAAO,CAACL,WAAW,CAACL,WAAW,CAACW,MAAM,CAACC,eAAe;YACnEV;QACF;QACAW,SAAS,MAAMhB,WAAW,IAAI,EAAEI;IAClC;IAEA,MAAMa,QAAQ,MAAMnB,WAAW;QAC7Ba,SAAS,IAAI;QACbO,gBAAgBf;QAChBS,QAAQ,IAAI,CAACC,OAAO,CAACL,WAAW,CAACL,WAAW,CAACW,MAAM,CAACC,eAAe;QACnET;IACF;IAEA,MAAMa,MAAM,MAAMZ,MAAMa,gBAAgB,CAACH,OAAOR,UAAUY;IAE1D,IAAI,CAACF,KAAK;QACR,OAAO;IACT;IAEAlB,UAAU;QACRU,SAAS,IAAI;QACbW,MAAMH;QACNP,QAAQ,IAAI,CAACC,OAAO,CAACL,WAAW,CAACL,WAAW,CAACW,MAAM,CAACF,MAAM;QAC1DW,WAAW;IACb;IAEA,OAAOJ;AACT,EAAC"}
|
package/dist/find.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAanC,eAAO,MAAM,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAanC,eAAO,MAAM,IAAI,EAAE,IAiIlB,CAAA"}
|
package/dist/find.js
CHANGED
|
@@ -4,7 +4,7 @@ import { buildSortParam } from './queries/buildSortParam.js';
|
|
|
4
4
|
import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
|
|
5
5
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
6
6
|
import { getSession } from './utilities/getSession.js';
|
|
7
|
-
import {
|
|
7
|
+
import { transform } from './utilities/transform.js';
|
|
8
8
|
export const find = async function find({ collection, joins = {}, limit = 0, locale, page, pagination, projection, req, select, sort: sortArg, where }) {
|
|
9
9
|
const Model = this.collections[collection];
|
|
10
10
|
const collectionConfig = this.payload.collections[collection].config;
|
|
@@ -97,14 +97,13 @@ export const find = async function find({ collection, joins = {}, limit = 0, loc
|
|
|
97
97
|
} else {
|
|
98
98
|
result = await Model.paginate(query, paginationOptions);
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
};
|
|
100
|
+
transform({
|
|
101
|
+
adapter: this,
|
|
102
|
+
data: result.docs,
|
|
103
|
+
fields: this.payload.collections[collection].config.fields,
|
|
104
|
+
operation: 'read'
|
|
105
|
+
});
|
|
106
|
+
return result;
|
|
108
107
|
};
|
|
109
108
|
|
|
110
109
|
//# sourceMappingURL=find.js.map
|
package/dist/find.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Find } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Find } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const find: Find = async function find(\n this: MongooseAdapter,\n {\n collection,\n joins = {},\n limit = 0,\n locale,\n page,\n pagination,\n projection,\n req,\n select,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n\n const session = await getSession(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.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collection,\n fields: this.payload.collections[collection].config.flattenedFields,\n locale,\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 lean: true,\n leanWithId: true,\n options: {\n session,\n },\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (select) {\n paginationOptions.projection = buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n })\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\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 hint: { _id: 1 },\n session,\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 let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n locale,\n query,\n })\n // build join aggregation\n if (aggregate) {\n result = await Model.aggregatePaginate(Model.aggregate(aggregate), paginationOptions)\n } else {\n result = await Model.paginate(query, paginationOptions)\n }\n\n transform({\n adapter: this,\n data: result.docs,\n fields: this.payload.collections[collection].config.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["flattenWhereToOperators","buildQuery","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","getSession","transform","find","collection","joins","limit","locale","page","pagination","projection","req","select","sort","sortArg","where","Model","collections","collectionConfig","payload","config","session","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","flattenedFields","defaultSort","timestamps","query","adapter","collectionSlug","useEstimatedCount","length","paginationOptions","lean","leanWithId","options","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","aggregatePaginate","paginate","data","docs","operation"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,OAAa,eAAeA,KAEvC,EACEC,UAAU,EACVC,QAAQ,CAAC,CAAC,EACVC,QAAQ,CAAC,EACTC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,UAAU,EACVC,GAAG,EACHC,MAAM,EACNC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACb,WAAW;IAC1C,MAAMc,mBAAmB,IAAI,CAACC,OAAO,CAACF,WAAW,CAACb,WAAW,CAACgB,MAAM;IAEpE,MAAMC,UAAU,MAAMpB,WAAW,IAAI,EAAEU;IAEvC,IAAIW,oBAAoB;IAExB,IAAIP,OAAO;QACT,MAAMQ,cAAc3B,wBAAwBmB;QAC5CO,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAIf;IACJ,IAAI,CAACS,mBAAmB;QACtBT,OAAOf,eAAe;YACpBsB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;YAC3BS,QAAQX,iBAAiBY,eAAe;YACxCvB;YACAM,MAAMC,WAAWI,iBAAiBa,WAAW;YAC7CC,YAAY;QACd;IACF;IAEA,MAAMC,QAAQ,MAAMpC,WAAW;QAC7BqC,SAAS,IAAI;QACbC,gBAAgB/B;QAChByB,QAAQ,IAAI,CAACV,OAAO,CAACF,WAAW,CAACb,WAAW,CAACgB,MAAM,CAACU,eAAe;QACnEvB;QACAQ;IACF;IAEA,4HAA4H;IAC5H,MAAMqB,oBAAoBd,qBAAqB,CAACW,SAASP,OAAOC,IAAI,CAACM,OAAOI,MAAM,KAAK;IACvF,MAAMC,oBAAqC;QACzCC,MAAM;QACNC,YAAY;QACZC,SAAS;YACPpB;QACF;QACAb;QACAC;QACAC;QACAG;QACAuB;IACF;IAEA,IAAIxB,QAAQ;QACV0B,kBAAkB5B,UAAU,GAAGV,0BAA0B;YACvDkC,SAAS,IAAI;YACbL,QAAQX,iBAAiBY,eAAe;YACxClB;QACF;IACF;IAEA,IAAI,IAAI,CAAC8B,SAAS,EAAE;QAClB,MAAMC,gBAAgB;QACtBL,kBAAkBI,SAAS,GAAG;YAC5BnC,QAAQA,UAAUA,WAAW,SAASA,WAAW,MAAMA,SAASoC;YAChE,GAAG,IAAI,CAACD,SAAS;QACnB;IACF;IAEA,IAAI,CAACN,qBAAqBV,OAAOC,IAAI,CAACM,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACO,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BN,kBAAkBO,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpB/B,MAAMgC,cAAc,CAACf,OAAO;gBAC1BgB,MAAM;oBAAEC,KAAK;gBAAE;gBACf7B;YACF;QAEJ;IACF;IAEA,IAAIf,SAAS,GAAG;QACdgC,kBAAkBhC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEgC,kBAAkBG,OAAO,CAACnC,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACfgC,kBAAkB7B,UAAU,GAAG;QACjC;IACF;IAEA,IAAI0C;IAEJ,MAAMC,YAAY,MAAMrD,qBAAqB;QAC3CmC,SAAS,IAAI;QACb9B;QACAc;QACAb;QACAE;QACA0B;IACF;IACA,yBAAyB;IACzB,IAAImB,WAAW;QACbD,SAAS,MAAMnC,MAAMqC,iBAAiB,CAACrC,MAAMoC,SAAS,CAACA,YAAYd;IACrE,OAAO;QACLa,SAAS,MAAMnC,MAAMsC,QAAQ,CAACrB,OAAOK;IACvC;IAEApC,UAAU;QACRgC,SAAS,IAAI;QACbqB,MAAMJ,OAAOK,IAAI;QACjB3B,QAAQ,IAAI,CAACV,OAAO,CAACF,WAAW,CAACb,WAAW,CAACgB,MAAM,CAACS,MAAM;QAC1D4B,WAAW;IACb;IAEA,OAAON;AACT,EAAC"}
|
package/dist/findGlobal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAWzC,eAAO,MAAM,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAWzC,eAAO,MAAM,UAAU,EAAE,UAuCxB,CAAA"}
|
package/dist/findGlobal.js
CHANGED
|
@@ -2,10 +2,11 @@ import { combineQueries } from 'payload';
|
|
|
2
2
|
import { buildQuery } from './queries/buildQuery.js';
|
|
3
3
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
4
4
|
import { getSession } from './utilities/getSession.js';
|
|
5
|
-
import {
|
|
5
|
+
import { transform } from './utilities/transform.js';
|
|
6
6
|
export const findGlobal = async function findGlobal({ slug, locale, req, select, where }) {
|
|
7
7
|
const Model = this.globals;
|
|
8
|
-
const
|
|
8
|
+
const globalConfig = this.payload.globals.config.find((each)=>each.slug === slug);
|
|
9
|
+
const fields = globalConfig.flattenedFields;
|
|
9
10
|
const options = {
|
|
10
11
|
lean: true,
|
|
11
12
|
select: buildProjectionFromSelect({
|
|
@@ -26,16 +27,16 @@ export const findGlobal = async function findGlobal({ slug, locale, req, select,
|
|
|
26
27
|
}
|
|
27
28
|
}, where)
|
|
28
29
|
});
|
|
29
|
-
|
|
30
|
+
const doc = await Model.findOne(query, {}, options);
|
|
30
31
|
if (!doc) {
|
|
31
32
|
return null;
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
transform({
|
|
35
|
+
adapter: this,
|
|
36
|
+
data: doc,
|
|
37
|
+
fields: globalConfig.fields,
|
|
38
|
+
operation: 'read'
|
|
39
|
+
});
|
|
39
40
|
return doc;
|
|
40
41
|
};
|
|
41
42
|
|
package/dist/findGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { FindGlobal } from 'payload'\n\nimport { combineQueries } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { FindGlobal } from 'payload'\n\nimport { combineQueries } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: MongooseAdapter,\n { slug, locale, req, select, where },\n) {\n const Model = this.globals\n const globalConfig = this.payload.globals.config.find((each) => each.slug === slug)\n const fields = globalConfig.flattenedFields\n const options: QueryOptions = {\n lean: true,\n select: buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields,\n globalSlug: slug,\n locale,\n where: combineQueries({ globalType: { equals: slug } }, where),\n })\n\n const doc = (await Model.findOne(query, {}, options)) as any\n\n if (!doc) {\n return null\n }\n\n transform({\n adapter: this,\n data: doc,\n fields: globalConfig.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["combineQueries","buildQuery","buildProjectionFromSelect","getSession","transform","findGlobal","slug","locale","req","select","where","Model","globals","globalConfig","payload","config","find","each","fields","flattenedFields","options","lean","adapter","session","query","globalSlug","globalType","equals","doc","findOne","data","operation"],"mappings":"AAGA,SAASA,cAAc,QAAQ,UAAS;AAIxC,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAEpC,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,eAAe,IAAI,CAACC,OAAO,CAACF,OAAO,CAACG,MAAM,CAACC,IAAI,CAAC,CAACC,OAASA,KAAKX,IAAI,KAAKA;IAC9E,MAAMY,SAASL,aAAaM,eAAe;IAC3C,MAAMC,UAAwB;QAC5BC,MAAM;QACNZ,QAAQP,0BAA0B;YAChCoB,SAAS,IAAI;YACbJ;YACAT;QACF;QACAc,SAAS,MAAMpB,WAAW,IAAI,EAAEK;IAClC;IAEA,MAAMgB,QAAQ,MAAMvB,WAAW;QAC7BqB,SAAS,IAAI;QACbJ;QACAO,YAAYnB;QACZC;QACAG,OAAOV,eAAe;YAAE0B,YAAY;gBAAEC,QAAQrB;YAAK;QAAE,GAAGI;IAC1D;IAEA,MAAMkB,MAAO,MAAMjB,MAAMkB,OAAO,CAACL,OAAO,CAAC,GAAGJ;IAE5C,IAAI,CAACQ,KAAK;QACR,OAAO;IACT;IAEAxB,UAAU;QACRkB,SAAS,IAAI;QACbQ,MAAMF;QACNV,QAAQL,aAAaK,MAAM;QAC3Ba,WAAW;IACb;IAEA,OAAOH;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAYjD,eAAO,MAAM,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAYjD,eAAO,MAAM,kBAAkB,EAAE,kBAkGhC,CAAA"}
|
|
@@ -3,10 +3,11 @@ import { buildQuery } from './queries/buildQuery.js';
|
|
|
3
3
|
import { buildSortParam } from './queries/buildSortParam.js';
|
|
4
4
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
5
5
|
import { getSession } from './utilities/getSession.js';
|
|
6
|
-
import {
|
|
6
|
+
import { transform } from './utilities/transform.js';
|
|
7
7
|
export const findGlobalVersions = async function findGlobalVersions({ global, limit, locale, page, pagination, req, select, skip, sort: sortArg, where }) {
|
|
8
|
+
const globalConfig = this.payload.globals.config.find(({ slug })=>slug === global);
|
|
8
9
|
const Model = this.versions[global];
|
|
9
|
-
const versionFields = buildVersionGlobalFields(this.payload.config,
|
|
10
|
+
const versionFields = buildVersionGlobalFields(this.payload.config, globalConfig, true);
|
|
10
11
|
const session = await getSession(this, req);
|
|
11
12
|
const options = {
|
|
12
13
|
limit,
|
|
@@ -82,14 +83,13 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
|
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
const result = await Model.paginate(query, paginationOptions);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
86
|
+
transform({
|
|
87
|
+
adapter: this,
|
|
88
|
+
data: result.docs,
|
|
89
|
+
fields: buildVersionGlobalFields(this.payload.config, globalConfig),
|
|
90
|
+
operation: 'read'
|
|
91
|
+
});
|
|
92
|
+
return result;
|
|
93
93
|
};
|
|
94
94
|
|
|
95
95
|
//# sourceMappingURL=findGlobalVersions.js.map
|