@payloadcms/db-mongodb 3.10.0 → 3.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +22 -18
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts.map +1 -1
- package/dist/countGlobalVersions.js +22 -18
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +22 -18
- package/dist/countVersions.js.map +1 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +24 -21
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +20 -20
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +30 -33
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +31 -34
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +4 -5
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +14 -18
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +1 -2
- package/dist/deleteVersions.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +74 -39
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +17 -18
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +62 -32
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +20 -29
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +61 -32
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +14 -18
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts +1 -3
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +1 -2
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +0 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +6 -2
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +1 -3
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +10 -14
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +7 -1
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js +2 -2
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.js +2 -2
- package/dist/queries/getLocalizedSortProperty.js.map +1 -1
- package/dist/queries/parseParams.d.ts +1 -3
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +1 -2
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +0 -16
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +66 -40
- package/dist/queryDrafts.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +21 -24
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +26 -28
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +23 -28
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +24 -27
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts +4 -4
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +28 -7
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.js +1 -18
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
- package/dist/utilities/sanitizeInternalFields.d.ts +2 -0
- package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -0
- package/dist/utilities/sanitizeInternalFields.js +20 -0
- package/dist/utilities/sanitizeInternalFields.js.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.js +125 -0
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
- package/dist/utilities/{transform.spec.js → sanitizeRelationshipIDs.spec.js} +7 -23
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
- package/package.json +3 -3
- package/dist/utilities/findMany.d.ts +0 -20
- package/dist/utilities/findMany.d.ts.map +0 -1
- package/dist/utilities/findMany.js +0 -84
- package/dist/utilities/findMany.js.map +0 -1
- package/dist/utilities/getHasNearConstraint.d.ts +0 -3
- package/dist/utilities/getHasNearConstraint.d.ts.map +0 -1
- package/dist/utilities/getHasNearConstraint.js +0 -26
- package/dist/utilities/getHasNearConstraint.js.map +0 -1
- package/dist/utilities/transform.d.ts +0 -25
- package/dist/utilities/transform.d.ts.map +0 -1
- package/dist/utilities/transform.js +0 -254
- package/dist/utilities/transform.js.map +0 -1
- package/dist/utilities/transform.spec.js.map +0 -1
package/dist/createVersion.js
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
import { Types } from 'mongoose';
|
|
2
2
|
import { buildVersionCollectionFields } from 'payload';
|
|
3
3
|
import { getSession } from './utilities/getSession.js';
|
|
4
|
-
import {
|
|
4
|
+
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
5
5
|
export const createVersion = async function createVersion({ autosave, collectionSlug, createdAt, parent, publishedLocale, req, snapshot, updatedAt, versionData }) {
|
|
6
6
|
const VersionModel = this.versions[collectionSlug];
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
autosave,
|
|
10
|
-
createdAt,
|
|
11
|
-
latest: true,
|
|
12
|
-
parent,
|
|
13
|
-
publishedLocale,
|
|
14
|
-
snapshot,
|
|
15
|
-
updatedAt,
|
|
16
|
-
version: versionData
|
|
7
|
+
const options = {
|
|
8
|
+
session: await getSession(this, req)
|
|
17
9
|
};
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
const data = sanitizeRelationshipIDs({
|
|
11
|
+
config: this.payload.config,
|
|
12
|
+
data: {
|
|
13
|
+
autosave,
|
|
14
|
+
createdAt,
|
|
15
|
+
latest: true,
|
|
16
|
+
parent,
|
|
17
|
+
publishedLocale,
|
|
18
|
+
snapshot,
|
|
19
|
+
updatedAt,
|
|
20
|
+
version: versionData
|
|
21
|
+
},
|
|
22
|
+
fields: buildVersionCollectionFields(this.payload.config, this.payload.collections[collectionSlug].config)
|
|
24
23
|
});
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
data._id = insertedID;
|
|
24
|
+
const [doc] = await VersionModel.create([
|
|
25
|
+
data
|
|
26
|
+
], options, req);
|
|
29
27
|
const parentQuery = {
|
|
30
28
|
$or: [
|
|
31
29
|
{
|
|
@@ -42,11 +40,11 @@ export const createVersion = async function createVersion({ autosave, collection
|
|
|
42
40
|
}
|
|
43
41
|
});
|
|
44
42
|
}
|
|
45
|
-
await VersionModel.
|
|
43
|
+
await VersionModel.updateMany({
|
|
46
44
|
$and: [
|
|
47
45
|
{
|
|
48
46
|
_id: {
|
|
49
|
-
$ne:
|
|
47
|
+
$ne: doc._id
|
|
50
48
|
}
|
|
51
49
|
},
|
|
52
50
|
parentQuery,
|
|
@@ -57,7 +55,7 @@ export const createVersion = async function createVersion({ autosave, collection
|
|
|
57
55
|
},
|
|
58
56
|
{
|
|
59
57
|
updatedAt: {
|
|
60
|
-
$lt: new Date(
|
|
58
|
+
$lt: new Date(doc.updatedAt)
|
|
61
59
|
}
|
|
62
60
|
}
|
|
63
61
|
]
|
|
@@ -65,16 +63,15 @@ export const createVersion = async function createVersion({ autosave, collection
|
|
|
65
63
|
$unset: {
|
|
66
64
|
latest: 1
|
|
67
65
|
}
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return data;
|
|
66
|
+
}, options);
|
|
67
|
+
const result = JSON.parse(JSON.stringify(doc));
|
|
68
|
+
const verificationToken = doc._verificationToken;
|
|
69
|
+
// custom id type reset
|
|
70
|
+
result.id = result._id;
|
|
71
|
+
if (verificationToken) {
|
|
72
|
+
result._verificationToken = verificationToken;
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
78
75
|
};
|
|
79
76
|
|
|
80
77
|
//# sourceMappingURL=createVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import { Types } from 'mongoose'\nimport { buildVersionCollectionFields, type CreateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import type { CreateOptions } from 'mongoose'\n\nimport { Types } from 'mongoose'\nimport { buildVersionCollectionFields, type CreateVersion, type Document } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.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 = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: {\n autosave,\n createdAt,\n latest: true,\n parent,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n },\n fields: buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collectionSlug].config,\n ),\n })\n\n const [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 if (data.parent instanceof Types.ObjectId) {\n parentQuery.$or.push({\n parent: {\n $eq: data.parent.toString(),\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 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":["Types","buildVersionCollectionFields","getSession","sanitizeRelationshipIDs","createVersion","autosave","collectionSlug","createdAt","parent","publishedLocale","req","snapshot","updatedAt","versionData","VersionModel","versions","options","session","data","config","payload","latest","version","fields","collections","doc","create","parentQuery","$or","$eq","ObjectId","push","toString","updateMany","$and","_id","$ne","$lt","Date","$unset","result","JSON","parse","stringify","verificationToken","_verificationToken","id"],"mappings":"AAEA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,4BAA4B,QAA2C,UAAS;AAIzF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,uBAAuB,QAAQ,yCAAwC;AAEhF,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,OAAOf,wBAAwB;QACnCgB,QAAQ,IAAI,CAACC,OAAO,CAACD,MAAM;QAC3BD,MAAM;YACJb;YACAE;YACAc,QAAQ;YACRb;YACAC;YACAE;YACAC;YACAU,SAAST;QACX;QACAU,QAAQtB,6BACN,IAAI,CAACmB,OAAO,CAACD,MAAM,EACnB,IAAI,CAACC,OAAO,CAACI,WAAW,CAAClB,eAAe,CAACa,MAAM;IAEnD;IAEA,MAAM,CAACM,IAAI,GAAG,MAAMX,aAAaY,MAAM,CAAC;QAACR;KAAK,EAAEF,SAASN;IAEzD,MAAMiB,cAAc;QAClBC,KAAK;YACH;gBACEpB,QAAQ;oBACNqB,KAAKX,KAAKV,MAAM;gBAClB;YACF;SACD;IACH;IACA,IAAIU,KAAKV,MAAM,YAAYR,MAAM8B,QAAQ,EAAE;QACzCH,YAAYC,GAAG,CAACG,IAAI,CAAC;YACnBvB,QAAQ;gBACNqB,KAAKX,KAAKV,MAAM,CAACwB,QAAQ;YAC3B;QACF;IACF;IAEA,MAAMlB,aAAamB,UAAU,CAC3B;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKX,IAAIU,GAAG;gBACd;YACF;YACAR;YACA;gBACEN,QAAQ;oBACNQ,KAAK;gBACP;YACF;YACA;gBACEjB,WAAW;oBACTyB,KAAK,IAAIC,KAAKb,IAAIb,SAAS;gBAC7B;YACF;SACD;IACH,GACA;QAAE2B,QAAQ;YAAElB,QAAQ;QAAE;IAAE,GACxBL;IAGF,MAAMwB,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAAClB;IACnD,MAAMmB,oBAAoBnB,IAAIoB,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOM,EAAE,GAAGN,OAAOL,GAAG;IACtB,IAAIS,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
|
package/dist/deleteMany.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAMzC,eAAO,MAAM,UAAU,EAAE,UAexB,CAAA"}
|
package/dist/deleteMany.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { getSession } from './utilities/getSession.js';
|
|
2
2
|
export const deleteMany = async function deleteMany({ collection, req, where }) {
|
|
3
3
|
const Model = this.collections[collection];
|
|
4
|
-
const
|
|
4
|
+
const options = {
|
|
5
|
+
session: await getSession(this, req)
|
|
6
|
+
};
|
|
5
7
|
const query = await Model.buildQuery({
|
|
6
8
|
payload: this.payload,
|
|
7
|
-
session,
|
|
8
9
|
where
|
|
9
10
|
});
|
|
10
|
-
await Model.
|
|
11
|
-
session
|
|
12
|
-
});
|
|
11
|
+
await Model.deleteMany(query, options);
|
|
13
12
|
};
|
|
14
13
|
|
|
15
14
|
//# sourceMappingURL=deleteMany.js.map
|
package/dist/deleteMany.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection, req, where },\n) {\n const Model = this.collections[collection]\n
|
|
1
|
+
{"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteOptions } from 'mongodb'\nimport type { DeleteMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection, req, where },\n) {\n const Model = this.collections[collection]\n const options: DeleteOptions = {\n session: await getSession(this, req),\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":["getSession","deleteMany","collection","req","where","Model","collections","options","session","query","buildQuery","payload"],"mappings":"AAKA,SAASA,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAE1B,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAyB;QAC7BC,SAAS,MAAMR,WAAW,IAAI,EAAEG;IAClC;IAEA,MAAMM,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMC,MAAMJ,UAAU,CAACQ,OAAOF;AAChC,EAAC"}
|
package/dist/deleteOne.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,SAAS,CAAA;AAQlD,eAAO,MAAM,SAAS,EAAE,SA4BvB,CAAA"}
|
package/dist/deleteOne.js
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
2
2
|
import { getSession } from './utilities/getSession.js';
|
|
3
|
-
import {
|
|
3
|
+
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
|
4
4
|
export const deleteOne = async function deleteOne({ collection, req, select, where }) {
|
|
5
5
|
const Model = this.collections[collection];
|
|
6
|
-
const
|
|
7
|
-
const query = await Model.buildQuery({
|
|
8
|
-
payload: this.payload,
|
|
9
|
-
session,
|
|
10
|
-
where
|
|
11
|
-
});
|
|
12
|
-
const fields = this.payload.collections[collection].config.flattenedFields;
|
|
13
|
-
const doc = await Model.collection.findOneAndDelete(query, {
|
|
6
|
+
const options = {
|
|
14
7
|
projection: buildProjectionFromSelect({
|
|
15
8
|
adapter: this,
|
|
16
|
-
fields,
|
|
9
|
+
fields: this.payload.collections[collection].config.flattenedFields,
|
|
17
10
|
select
|
|
18
11
|
}),
|
|
19
|
-
session
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
fields,
|
|
25
|
-
operation: 'read'
|
|
12
|
+
session: await getSession(this, req)
|
|
13
|
+
};
|
|
14
|
+
const query = await Model.buildQuery({
|
|
15
|
+
payload: this.payload,
|
|
16
|
+
where
|
|
26
17
|
});
|
|
27
|
-
|
|
18
|
+
const doc = await Model.findOneAndDelete(query, options).lean();
|
|
19
|
+
let result = JSON.parse(JSON.stringify(doc));
|
|
20
|
+
// custom id type reset
|
|
21
|
+
result.id = result._id;
|
|
22
|
+
result = sanitizeInternalFields(result);
|
|
23
|
+
return result;
|
|
28
24
|
};
|
|
29
25
|
|
|
30
26
|
//# sourceMappingURL=deleteOne.js.map
|
package/dist/deleteOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { DeleteOne, Document } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.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 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":["buildProjectionFromSelect","getSession","sanitizeInternalFields","deleteOne","collection","req","select","where","Model","collections","options","projection","adapter","fields","payload","config","flattenedFields","session","query","buildQuery","doc","findOneAndDelete","lean","result","JSON","parse","stringify","id","_id"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,sBAAsB,QAAQ,wCAAuC;AAE9E,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,MAAMV,MAAMW,UAAU,CAAC;QACnCL,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMa,MAAM,MAAMZ,MAAMa,gBAAgB,CAACH,OAAOR,SAASY,IAAI;IAE7D,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEjD,uBAAuB;IACvBG,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASrB,uBAAuBqB;IAEhC,OAAOA;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAM7C,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAM7C,eAAO,MAAM,cAAc,EAAE,cAe5B,CAAA"}
|
package/dist/deleteVersions.js
CHANGED
|
@@ -5,10 +5,9 @@ export const deleteVersions = async function deleteVersions({ collection, locale
|
|
|
5
5
|
const query = await VersionsModel.buildQuery({
|
|
6
6
|
locale,
|
|
7
7
|
payload: this.payload,
|
|
8
|
-
session,
|
|
9
8
|
where
|
|
10
9
|
});
|
|
11
|
-
await VersionsModel.
|
|
10
|
+
await VersionsModel.deleteMany(query, {
|
|
12
11
|
session
|
|
13
12
|
});
|
|
14
13
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: MongooseAdapter,\n { collection, locale, req, where },\n) {\n const VersionsModel = this.versions[collection]\n\n const session = await getSession(this, req)\n\n const query = await VersionsModel.buildQuery({\n locale,\n payload: this.payload,\n
|
|
1
|
+
{"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: MongooseAdapter,\n { collection, locale, req, where },\n) {\n const VersionsModel = this.versions[collection]\n\n const session = await getSession(this, req)\n\n const query = await VersionsModel.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n await VersionsModel.deleteMany(query, { session })\n}\n"],"names":["getSession","deleteVersions","collection","locale","req","where","VersionsModel","versions","session","query","buildQuery","payload","deleteMany"],"mappings":"AAIA,SAASA,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,iBAAiC,eAAeA,eAE3D,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAElC,MAAMC,gBAAgB,IAAI,CAACC,QAAQ,CAACL,WAAW;IAE/C,MAAMM,UAAU,MAAMR,WAAW,IAAI,EAAEI;IAEvC,MAAMK,QAAQ,MAAMH,cAAcI,UAAU,CAAC;QAC3CP;QACAQ,SAAS,IAAI,CAACA,OAAO;QACrBN;IACF;IAEA,MAAMC,cAAcM,UAAU,CAACH,OAAO;QAAED;IAAQ;AAClD,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;AAYnC,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;AAYnC,eAAO,MAAM,IAAI,EAAE,IAgIlB,CAAA"}
|
package/dist/find.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
+
import { flattenWhereToOperators } from 'payload';
|
|
1
2
|
import { buildSortParam } from './queries/buildSortParam.js';
|
|
2
3
|
import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
|
|
3
4
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
4
|
-
import { findMany } from './utilities/findMany.js';
|
|
5
|
-
import { getHasNearConstraint } from './utilities/getHasNearConstraint.js';
|
|
6
5
|
import { getSession } from './utilities/getSession.js';
|
|
7
|
-
import {
|
|
8
|
-
export const find = async function find({ collection, joins = {}, limit = 0, locale, page, pagination, req, select, sort: sortArg, where }) {
|
|
6
|
+
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
|
7
|
+
export const find = async function find({ collection, joins = {}, limit = 0, locale, page, pagination, projection, req, select, sort: sortArg, where }) {
|
|
9
8
|
const Model = this.collections[collection];
|
|
10
9
|
const collectionConfig = this.payload.collections[collection].config;
|
|
11
10
|
const session = await getSession(this, req);
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
let hasNearConstraint = false;
|
|
12
|
+
if (where) {
|
|
13
|
+
const constraints = flattenWhereToOperators(where);
|
|
14
|
+
hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
|
|
15
|
+
}
|
|
14
16
|
let sort;
|
|
15
17
|
if (!hasNearConstraint) {
|
|
16
18
|
sort = buildSortParam({
|
|
17
19
|
config: this.payload.config,
|
|
18
|
-
fields,
|
|
20
|
+
fields: collectionConfig.flattenedFields,
|
|
19
21
|
locale,
|
|
20
22
|
sort: sortArg || collectionConfig.defaultSort,
|
|
21
23
|
timestamps: true
|
|
@@ -24,49 +26,82 @@ export const find = async function find({ collection, joins = {}, limit = 0, loc
|
|
|
24
26
|
const query = await Model.buildQuery({
|
|
25
27
|
locale,
|
|
26
28
|
payload: this.payload,
|
|
27
|
-
session,
|
|
28
29
|
where
|
|
29
30
|
});
|
|
30
31
|
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
|
|
31
32
|
const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
locale: locale && locale !== 'all' && locale !== '*' ? locale : 'en',
|
|
39
|
-
...this.collation
|
|
40
|
-
} : undefined;
|
|
41
|
-
const joinAgreggation = await buildJoinAggregation({
|
|
42
|
-
adapter: this,
|
|
43
|
-
collection,
|
|
44
|
-
collectionConfig,
|
|
45
|
-
joins,
|
|
46
|
-
locale,
|
|
47
|
-
session
|
|
48
|
-
});
|
|
49
|
-
const result = await findMany({
|
|
50
|
-
adapter: this,
|
|
51
|
-
collation,
|
|
52
|
-
collection: Model.collection,
|
|
53
|
-
joinAgreggation,
|
|
54
|
-
limit,
|
|
33
|
+
const paginationOptions = {
|
|
34
|
+
lean: true,
|
|
35
|
+
leanWithId: true,
|
|
36
|
+
options: {
|
|
37
|
+
session
|
|
38
|
+
},
|
|
55
39
|
page,
|
|
56
40
|
pagination,
|
|
57
41
|
projection,
|
|
58
|
-
query,
|
|
59
|
-
session,
|
|
60
42
|
sort,
|
|
61
43
|
useEstimatedCount
|
|
62
|
-
}
|
|
63
|
-
|
|
44
|
+
};
|
|
45
|
+
if (select) {
|
|
46
|
+
paginationOptions.projection = buildProjectionFromSelect({
|
|
47
|
+
adapter: this,
|
|
48
|
+
fields: collectionConfig.flattenedFields,
|
|
49
|
+
select
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (this.collation) {
|
|
53
|
+
const defaultLocale = 'en';
|
|
54
|
+
paginationOptions.collation = {
|
|
55
|
+
locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
|
|
56
|
+
...this.collation
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
|
|
60
|
+
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
|
|
61
|
+
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
|
|
62
|
+
// which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses
|
|
63
|
+
// the correct indexed field
|
|
64
|
+
paginationOptions.useCustomCountFn = ()=>{
|
|
65
|
+
return Promise.resolve(Model.countDocuments(query, {
|
|
66
|
+
hint: {
|
|
67
|
+
_id: 1
|
|
68
|
+
},
|
|
69
|
+
session
|
|
70
|
+
}));
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (limit >= 0) {
|
|
74
|
+
paginationOptions.limit = limit;
|
|
75
|
+
// limit must also be set here, it's ignored when pagination is false
|
|
76
|
+
paginationOptions.options.limit = limit;
|
|
77
|
+
// Disable pagination if limit is 0
|
|
78
|
+
if (limit === 0) {
|
|
79
|
+
paginationOptions.pagination = false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
let result;
|
|
83
|
+
const aggregate = await buildJoinAggregation({
|
|
64
84
|
adapter: this,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
85
|
+
collection,
|
|
86
|
+
collectionConfig,
|
|
87
|
+
joins,
|
|
88
|
+
locale,
|
|
89
|
+
query
|
|
68
90
|
});
|
|
69
|
-
|
|
91
|
+
// build join aggregation
|
|
92
|
+
if (aggregate) {
|
|
93
|
+
result = await Model.aggregatePaginate(Model.aggregate(aggregate), paginationOptions);
|
|
94
|
+
} else {
|
|
95
|
+
result = await Model.paginate(query, paginationOptions);
|
|
96
|
+
}
|
|
97
|
+
const docs = JSON.parse(JSON.stringify(result.docs));
|
|
98
|
+
return {
|
|
99
|
+
...result,
|
|
100
|
+
docs: docs.map((doc)=>{
|
|
101
|
+
doc.id = doc._id;
|
|
102
|
+
return sanitizeInternalFields(doc);
|
|
103
|
+
})
|
|
104
|
+
};
|
|
70
105
|
};
|
|
71
106
|
|
|
72
107
|
//# sourceMappingURL=find.js.map
|
package/dist/find.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type {
|
|
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 { buildSortParam } from './queries/buildSortParam.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.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 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 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 const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["flattenWhereToOperators","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","getSession","sanitizeInternalFields","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","buildQuery","useEstimatedCount","length","paginationOptions","lean","leanWithId","options","adapter","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","aggregatePaginate","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"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"}
|
package/dist/findGlobal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAUzC,eAAO,MAAM,UAAU,EAAE,UAoCxB,CAAA"}
|
package/dist/findGlobal.js
CHANGED
|
@@ -1,39 +1,38 @@
|
|
|
1
1
|
import { combineQueries } from 'payload';
|
|
2
2
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
3
|
import { getSession } from './utilities/getSession.js';
|
|
4
|
-
import {
|
|
4
|
+
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
|
5
5
|
export const findGlobal = async function findGlobal({ slug, locale, req, select, where }) {
|
|
6
6
|
const Model = this.globals;
|
|
7
|
-
const
|
|
7
|
+
const options = {
|
|
8
|
+
lean: true,
|
|
9
|
+
select: buildProjectionFromSelect({
|
|
10
|
+
adapter: this,
|
|
11
|
+
fields: this.payload.globals.config.find((each)=>each.slug === slug).flattenedFields,
|
|
12
|
+
select
|
|
13
|
+
}),
|
|
14
|
+
session: await getSession(this, req)
|
|
15
|
+
};
|
|
8
16
|
const query = await Model.buildQuery({
|
|
9
17
|
globalSlug: slug,
|
|
10
18
|
locale,
|
|
11
19
|
payload: this.payload,
|
|
12
|
-
session,
|
|
13
20
|
where: combineQueries({
|
|
14
21
|
globalType: {
|
|
15
22
|
equals: slug
|
|
16
23
|
}
|
|
17
24
|
}, where)
|
|
18
25
|
});
|
|
19
|
-
|
|
20
|
-
const doc = await Model.collection.findOne(query, {
|
|
21
|
-
projection: buildProjectionFromSelect({
|
|
22
|
-
adapter: this,
|
|
23
|
-
fields,
|
|
24
|
-
select
|
|
25
|
-
}),
|
|
26
|
-
session: await getSession(this, req)
|
|
27
|
-
});
|
|
26
|
+
let doc = await Model.findOne(query, {}, options);
|
|
28
27
|
if (!doc) {
|
|
29
28
|
return null;
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
if (doc._id) {
|
|
31
|
+
doc.id = doc._id;
|
|
32
|
+
delete doc._id;
|
|
33
|
+
}
|
|
34
|
+
doc = JSON.parse(JSON.stringify(doc));
|
|
35
|
+
doc = sanitizeInternalFields(doc);
|
|
37
36
|
return doc;
|
|
38
37
|
};
|
|
39
38
|
|
package/dist/findGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal } from 'payload'\n\nimport { combineQueries } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\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 { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.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 options: QueryOptions = {\n lean: true,\n select: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.globals.config.find((each) => each.slug === slug).flattenedFields,\n select,\n }),\n session: await getSession(this, req),\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","buildProjectionFromSelect","getSession","sanitizeInternalFields","findGlobal","slug","locale","req","select","where","Model","globals","options","lean","adapter","fields","payload","config","find","each","flattenedFields","session","query","buildQuery","globalSlug","globalType","equals","doc","findOne","_id","id","JSON","parse","stringify"],"mappings":"AAGA,SAASA,cAAc,QAAQ,UAAS;AAIxC,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,sBAAsB,QAAQ,wCAAuC;AAE9E,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAEpC,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAwB;QAC5BC,MAAM;QACNL,QAAQP,0BAA0B;YAChCa,SAAS,IAAI;YACbC,QAAQ,IAAI,CAACC,OAAO,CAACL,OAAO,CAACM,MAAM,CAACC,IAAI,CAAC,CAACC,OAASA,KAAKd,IAAI,KAAKA,MAAMe,eAAe;YACtFZ;QACF;QACAa,SAAS,MAAMnB,WAAW,IAAI,EAAEK;IAClC;IAEA,MAAMe,QAAQ,MAAMZ,MAAMa,UAAU,CAAC;QACnCC,YAAYnB;QACZC;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBP,OAAOT,eAAe;YAAEyB,YAAY;gBAAEC,QAAQrB;YAAK;QAAE,GAAGI;IAC1D;IAEA,IAAIkB,MAAO,MAAMjB,MAAMkB,OAAO,CAACN,OAAO,CAAC,GAAGV;IAE1C,IAAI,CAACe,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,MAAMxB,uBAAuBwB;IAE7B,OAAOA;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;
|
|
1
|
+
{"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAWjD,eAAO,MAAM,kBAAkB,EAAE,kBAqGhC,CAAA"}
|