@payloadcms/db-mongodb 3.2.2-canary.d2399ed → 3.2.3-canary.2d2e7d5
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 +21 -19
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts.map +1 -1
- package/dist/countGlobalVersions.js +21 -19
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +21 -19
- package/dist/countVersions.js.map +1 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +22 -22
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +19 -21
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +30 -35
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +30 -35
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +6 -6
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +13 -17
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +6 -6
- package/dist/deleteVersions.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +74 -41
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +18 -19
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +62 -33
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +19 -32
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +62 -34
- package/dist/findVersions.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +16 -20
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js +2 -2
- package/dist/predefinedMigrations/migrateVersionsV1_V2.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 +65 -41
- package/dist/queryDrafts.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +23 -25
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +27 -28
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +24 -28
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +26 -28
- 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/dist/{getSession.d.ts → withSession.d.ts} +4 -2
- package/dist/withSession.d.ts.map +1 -0
- package/dist/{getSession.js → withSession.js} +5 -3
- package/dist/withSession.js.map +1 -0
- package/package.json +3 -3
- package/dist/getSession.d.ts.map +0 -1
- package/dist/getSession.js.map +0 -1
- 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 -17
- package/dist/utilities/transform.d.ts.map +0 -1
- package/dist/utilities/transform.js +0 -250
- package/dist/utilities/transform.js.map +0 -1
- package/dist/utilities/transform.spec.js.map +0 -1
package/dist/queryDrafts.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { buildVersionCollectionFields, combineQueries } from 'payload';
|
|
2
|
-
import { getSession } from './getSession.js';
|
|
1
|
+
import { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload';
|
|
3
2
|
import { buildSortParam } from './queries/buildSortParam.js';
|
|
4
3
|
import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
|
|
5
4
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { transform } from './utilities/transform.js';
|
|
5
|
+
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
|
6
|
+
import { withSession } from './withSession.js';
|
|
9
7
|
export const queryDrafts = async function queryDrafts({ collection, joins, limit, locale, page, pagination, req = {}, select, sort: sortArg, where }) {
|
|
10
8
|
const VersionModel = this.versions[collection];
|
|
11
9
|
const collectionConfig = this.payload.collections[collection].config;
|
|
12
|
-
const
|
|
13
|
-
|
|
10
|
+
const options = await withSession(this, req);
|
|
11
|
+
let hasNearConstraint;
|
|
14
12
|
let sort;
|
|
13
|
+
if (where) {
|
|
14
|
+
const constraints = flattenWhereToOperators(where);
|
|
15
|
+
hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
|
|
16
|
+
}
|
|
15
17
|
if (!hasNearConstraint) {
|
|
16
18
|
sort = buildSortParam({
|
|
17
19
|
config: this.payload.config,
|
|
@@ -29,57 +31,79 @@ export const queryDrafts = async function queryDrafts({ collection, joins, limit
|
|
|
29
31
|
const versionQuery = await VersionModel.buildQuery({
|
|
30
32
|
locale,
|
|
31
33
|
payload: this.payload,
|
|
32
|
-
session,
|
|
33
34
|
where: combinedWhere
|
|
34
35
|
});
|
|
35
|
-
const versionFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true);
|
|
36
36
|
const projection = buildProjectionFromSelect({
|
|
37
37
|
adapter: this,
|
|
38
|
-
fields:
|
|
38
|
+
fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),
|
|
39
39
|
select
|
|
40
40
|
});
|
|
41
41
|
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
|
|
42
42
|
const useEstimatedCount = hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0;
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
const paginationOptions = {
|
|
44
|
+
lean: true,
|
|
45
|
+
leanWithId: true,
|
|
46
|
+
options,
|
|
47
|
+
page,
|
|
48
|
+
pagination,
|
|
49
|
+
projection,
|
|
50
|
+
sort,
|
|
51
|
+
useEstimatedCount
|
|
52
|
+
};
|
|
53
|
+
if (this.collation) {
|
|
54
|
+
const defaultLocale = 'en';
|
|
55
|
+
paginationOptions.collation = {
|
|
56
|
+
locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
|
|
57
|
+
...this.collation
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (!useEstimatedCount && Object.keys(versionQuery).length === 0 && this.disableIndexHints !== true) {
|
|
61
|
+
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
|
|
62
|
+
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
|
|
63
|
+
// which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses
|
|
64
|
+
// the correct indexed field
|
|
65
|
+
paginationOptions.useCustomCountFn = ()=>{
|
|
66
|
+
return Promise.resolve(VersionModel.countDocuments(versionQuery, {
|
|
67
|
+
hint: {
|
|
68
|
+
_id: 1
|
|
69
|
+
}
|
|
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
|
+
}
|
|
78
|
+
let result;
|
|
79
|
+
const aggregate = await buildJoinAggregation({
|
|
48
80
|
adapter: this,
|
|
49
81
|
collection,
|
|
50
82
|
collectionConfig,
|
|
51
83
|
joins,
|
|
52
84
|
locale,
|
|
53
85
|
projection,
|
|
54
|
-
session,
|
|
55
|
-
versions: true
|
|
56
|
-
});
|
|
57
|
-
const result = await findMany({
|
|
58
|
-
adapter: this,
|
|
59
|
-
collation,
|
|
60
|
-
collection: VersionModel.collection,
|
|
61
|
-
joinAgreggation,
|
|
62
|
-
limit,
|
|
63
|
-
page,
|
|
64
|
-
pagination,
|
|
65
|
-
projection,
|
|
66
86
|
query: versionQuery,
|
|
67
|
-
|
|
68
|
-
sort,
|
|
69
|
-
useEstimatedCount
|
|
70
|
-
});
|
|
71
|
-
transform({
|
|
72
|
-
adapter: this,
|
|
73
|
-
data: result.docs,
|
|
74
|
-
fields: versionFields,
|
|
75
|
-
operation: 'read'
|
|
87
|
+
versions: true
|
|
76
88
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
result
|
|
80
|
-
|
|
89
|
+
// build join aggregation
|
|
90
|
+
if (aggregate) {
|
|
91
|
+
result = await VersionModel.aggregatePaginate(VersionModel.aggregate(aggregate), paginationOptions);
|
|
92
|
+
} else {
|
|
93
|
+
result = await VersionModel.paginate(versionQuery, paginationOptions);
|
|
81
94
|
}
|
|
82
|
-
|
|
95
|
+
const docs = JSON.parse(JSON.stringify(result.docs));
|
|
96
|
+
return {
|
|
97
|
+
...result,
|
|
98
|
+
docs: docs.map((doc)=>{
|
|
99
|
+
doc = {
|
|
100
|
+
_id: doc.parent,
|
|
101
|
+
id: doc.parent,
|
|
102
|
+
...doc.version
|
|
103
|
+
};
|
|
104
|
+
return sanitizeInternalFields(doc);
|
|
105
|
+
})
|
|
106
|
+
};
|
|
83
107
|
};
|
|
84
108
|
|
|
85
109
|
//# sourceMappingURL=queryDrafts.js.map
|
package/dist/queryDrafts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { PayloadRequest, QueryDrafts } from 'payload'\n\nimport { buildVersionCollectionFields, combineQueries, 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 { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n {\n collection,\n joins,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n select,\n sort: sortArg,\n where,\n },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const versionQuery = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: combinedWhere,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),\n select,\n })\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\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 (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n VersionModel.countDocuments(versionQuery, {\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n locale,\n projection,\n query: versionQuery,\n versions: true,\n })\n\n // build join aggregation\n if (aggregate) {\n result = await VersionModel.aggregatePaginate(\n VersionModel.aggregate(aggregate),\n paginationOptions,\n )\n } else {\n result = await VersionModel.paginate(versionQuery, paginationOptions)\n }\n\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc = {\n _id: doc.parent,\n id: doc.parent,\n ...doc.version,\n }\n\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["buildVersionCollectionFields","combineQueries","flattenWhereToOperators","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","sanitizeInternalFields","withSession","queryDrafts","collection","joins","limit","locale","page","pagination","req","select","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","flattenedFields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","projection","adapter","useEstimatedCount","length","paginationOptions","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","query","aggregatePaginate","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAI/F,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EACEC,UAAU,EACVC,KAAK,EACLC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,MAAM,EACNC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACZ,WAAW;IAC9C,MAAMa,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACf,WAAW,CAACgB,MAAM;IACpE,MAAMC,UAAU,MAAMnB,YAAY,IAAI,EAAEQ;IAExC,IAAIY;IACJ,IAAIV;IAEJ,IAAIE,OAAO;QACT,MAAMS,cAAc1B,wBAAwBiB;QAC5CQ,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAI,CAACN,mBAAmB;QACtBV,OAAOd,eAAe;YACpBsB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;YAC3BS,QAAQZ,iBAAiBa,eA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MC,YAAY,MAAMxD,qBAAqB;QAC3CwC,SAAS,IAAI;QACbnC;QACAa;QACAZ;QACAE;QACA+B;QACAkB,OAAOpB;QACPpB,UAAU;IACZ;IAEA,yBAAyB;IACzB,IAAIuC,WAAW;QACbD,SAAS,MAAMvC,aAAa0C,iBAAiB,CAC3C1C,aAAawC,SAAS,CAACA,YACvBb;IAEJ,OAAO;QACLY,SAAS,MAAMvC,aAAa2C,QAAQ,CAACtB,cAAcM;IACrD;IAEA,MAAMiB,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACR,OAAOK,IAAI;IAElD,OAAO;QACL,GAAGL,MAAM;QACTK,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,MAAM;gBACJX,KAAKW,IAAIC,MAAM;gBACfC,IAAIF,IAAIC,MAAM;gBACd,GAAGD,IAAIG,OAAO;YAChB;YAEA,OAAOlE,uBAAuB+D;QAChC;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,SAAS,CAAA;AAS3D,eAAO,MAAM,YAAY,EAAE,YAoC1B,CAAA"}
|
package/dist/updateGlobal.js
CHANGED
|
@@ -1,36 +1,34 @@
|
|
|
1
|
-
import { getSession } from './getSession.js';
|
|
2
1
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
|
-
import {
|
|
2
|
+
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
|
3
|
+
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
4
|
+
import { withSession } from './withSession.js';
|
|
4
5
|
export const updateGlobal = async function updateGlobal({ slug, data, options: optionsArgs = {}, req = {}, select }) {
|
|
5
6
|
const Model = this.globals;
|
|
6
|
-
const fields = this.payload.config.globals.find((global)=>global.slug === slug).
|
|
7
|
-
const
|
|
8
|
-
transform({
|
|
9
|
-
adapter: this,
|
|
10
|
-
data,
|
|
11
|
-
fields,
|
|
12
|
-
operation: 'update'
|
|
13
|
-
});
|
|
14
|
-
const result = await Model.collection.findOneAndUpdate({
|
|
15
|
-
globalType: slug
|
|
16
|
-
}, {
|
|
17
|
-
$set: data
|
|
18
|
-
}, {
|
|
7
|
+
const fields = this.payload.config.globals.find((global)=>global.slug === slug).fields;
|
|
8
|
+
const options = {
|
|
19
9
|
...optionsArgs,
|
|
10
|
+
...await withSession(this, req),
|
|
11
|
+
lean: true,
|
|
12
|
+
new: true,
|
|
20
13
|
projection: buildProjectionFromSelect({
|
|
21
14
|
adapter: this,
|
|
22
|
-
fields,
|
|
15
|
+
fields: this.payload.config.globals.find((global)=>global.slug === slug).flattenedFields,
|
|
23
16
|
select
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
fields,
|
|
32
|
-
operation: 'read'
|
|
17
|
+
})
|
|
18
|
+
};
|
|
19
|
+
let result;
|
|
20
|
+
const sanitizedData = sanitizeRelationshipIDs({
|
|
21
|
+
config: this.payload.config,
|
|
22
|
+
data,
|
|
23
|
+
fields
|
|
33
24
|
});
|
|
25
|
+
result = await Model.findOneAndUpdate({
|
|
26
|
+
globalType: slug
|
|
27
|
+
}, sanitizedData, options);
|
|
28
|
+
result = JSON.parse(JSON.stringify(result));
|
|
29
|
+
// custom id type reset
|
|
30
|
+
result.id = result._id;
|
|
31
|
+
result = sanitizeInternalFields(result);
|
|
34
32
|
return result;
|
|
35
33
|
};
|
|
36
34
|
|
package/dist/updateGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { PayloadRequest, UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { PayloadRequest, UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, options: optionsArgs = {}, req = {} as PayloadRequest, select },\n) {\n const Model = this.globals\n const fields = this.payload.config.globals.find((global) => global.slug === slug).fields\n\n const options: QueryOptions = {\n ...optionsArgs,\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.config.globals.find((global) => global.slug === slug).flattenedFields,\n select,\n }),\n }\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields,\n })\n\n result = await Model.findOneAndUpdate({ globalType: slug }, sanitizedData, options)\n\n result = JSON.parse(JSON.stringify(result))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildProjectionFromSelect","sanitizeInternalFields","sanitizeRelationshipIDs","withSession","updateGlobal","slug","data","options","optionsArgs","req","select","Model","globals","fields","payload","config","find","global","lean","new","projection","adapter","flattenedFields","result","sanitizedData","findOneAndUpdate","globalType","JSON","parse","stringify","id","_id"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAE;IAE7E,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,SAAS,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOZ,IAAI,KAAKA,MAAMQ,MAAM;IAExF,MAAMN,UAAwB;QAC5B,GAAGC,WAAW;QACd,GAAI,MAAML,YAAY,IAAI,EAAEM,IAAI;QAChCS,MAAM;QACNC,KAAK;QACLC,YAAYpB,0BAA0B;YACpCqB,SAAS,IAAI;YACbR,QAAQ,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOZ,IAAI,KAAKA,MAAMiB,eAAe;YAC1FZ;QACF;IACF;IAEA,IAAIa;IAEJ,MAAMC,gBAAgBtB,wBAAwB;QAC5Ca,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BT;QACAO;IACF;IAEAU,SAAS,MAAMZ,MAAMc,gBAAgB,CAAC;QAAEC,YAAYrB;IAAK,GAAGmB,eAAejB;IAE3EgB,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEnC,uBAAuB;IACvBA,OAAOO,EAAE,GAAGP,OAAOQ,GAAG;IACtBR,SAAStB,uBAAuBsB;IAEhC,OAAOA;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,uBAAuB,EAC7B,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAMjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,OAAO,EAAE,WAAgB,EACzB,GAA0B,EAC1B,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBA4C9B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { buildVersionGlobalFields } from 'payload';
|
|
2
|
-
import { getSession } from './getSession.js';
|
|
3
2
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
4
|
-
import {
|
|
3
|
+
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
4
|
+
import { withSession } from './withSession.js';
|
|
5
5
|
export async function updateGlobalVersion({ id, global: globalSlug, locale, options: optionsArgs = {}, req = {}, select, versionData, where }) {
|
|
6
6
|
const VersionModel = this.versions[globalSlug];
|
|
7
7
|
const whereToUse = where || {
|
|
@@ -9,39 +9,38 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, opti
|
|
|
9
9
|
equals: id
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const currentGlobal = this.payload.config.globals.find((global)=>global.slug === globalSlug);
|
|
13
|
+
const fields = buildVersionGlobalFields(this.payload.config, currentGlobal);
|
|
14
|
+
const options = {
|
|
15
|
+
...optionsArgs,
|
|
16
|
+
...await withSession(this, req),
|
|
17
|
+
lean: true,
|
|
18
|
+
new: true,
|
|
19
|
+
projection: buildProjectionFromSelect({
|
|
20
|
+
adapter: this,
|
|
21
|
+
fields: buildVersionGlobalFields(this.payload.config, currentGlobal, true),
|
|
22
|
+
select
|
|
23
|
+
})
|
|
24
|
+
};
|
|
14
25
|
const query = await VersionModel.buildQuery({
|
|
15
26
|
locale,
|
|
16
27
|
payload: this.payload,
|
|
17
|
-
session,
|
|
18
28
|
where: whereToUse
|
|
19
29
|
});
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
const sanitizedData = sanitizeRelationshipIDs({
|
|
31
|
+
config: this.payload.config,
|
|
22
32
|
data: versionData,
|
|
23
|
-
fields
|
|
24
|
-
operation: 'update'
|
|
25
|
-
});
|
|
26
|
-
const doc = await VersionModel.collection.findOneAndUpdate(query, {
|
|
27
|
-
$set: versionData
|
|
28
|
-
}, {
|
|
29
|
-
...optionsArgs,
|
|
30
|
-
projection: buildProjectionFromSelect({
|
|
31
|
-
adapter: this,
|
|
32
|
-
fields,
|
|
33
|
-
select
|
|
34
|
-
}),
|
|
35
|
-
returnDocument: 'after',
|
|
36
|
-
session
|
|
37
|
-
});
|
|
38
|
-
transform({
|
|
39
|
-
adapter: this,
|
|
40
|
-
data: doc,
|
|
41
|
-
fields,
|
|
42
|
-
operation: 'read'
|
|
33
|
+
fields
|
|
43
34
|
});
|
|
44
|
-
|
|
35
|
+
const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
|
|
36
|
+
const result = JSON.parse(JSON.stringify(doc));
|
|
37
|
+
const verificationToken = doc._verificationToken;
|
|
38
|
+
// custom id type reset
|
|
39
|
+
result.id = result._id;
|
|
40
|
+
if (verificationToken) {
|
|
41
|
+
result._verificationToken = verificationToken;
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
//# sourceMappingURL=updateGlobalVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import {\n buildVersionGlobalFields,\n type PayloadRequest,\n type TypeWithID,\n type UpdateGlobalVersionArgs,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport {\n buildVersionGlobalFields,\n type PayloadRequest,\n type TypeWithID,\n type UpdateGlobalVersionArgs,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n options: optionsArgs = {},\n req = {} as PayloadRequest,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[globalSlug]\n const whereToUse = where || { id: { equals: id } }\n\n const currentGlobal = this.payload.config.globals.find((global) => global.slug === globalSlug)\n const fields = buildVersionGlobalFields(this.payload.config, currentGlobal)\n\n const options: QueryOptions = {\n ...optionsArgs,\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: buildVersionGlobalFields(this.payload.config, currentGlobal, true),\n select,\n }),\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: versionData,\n fields,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options)\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["buildVersionGlobalFields","buildProjectionFromSelect","sanitizeRelationshipIDs","withSession","updateGlobalVersion","id","global","globalSlug","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","currentGlobal","payload","config","globals","find","slug","fields","lean","new","projection","adapter","query","buildQuery","sanitizedData","data","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAEA,SACEA,wBAAwB,QAInB,UAAS;AAIhB,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF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AAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT"}
|
package/dist/updateOne.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,SAAS,EAAE,MAAM,SAAS,CAAA;AAUxD,eAAO,MAAM,SAAS,EAAE,SAqDvB,CAAA"}
|
package/dist/updateOne.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { getSession } from './getSession.js';
|
|
2
1
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
2
|
import { handleError } from './utilities/handleError.js';
|
|
4
|
-
import {
|
|
3
|
+
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
|
4
|
+
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
5
|
+
import { withSession } from './withSession.js';
|
|
5
6
|
export const updateOne = async function updateOne({ id, collection, data, locale, options: optionsArgs = {}, req = {}, select, where: whereArg }) {
|
|
6
7
|
const where = id ? {
|
|
7
8
|
id: {
|
|
@@ -9,40 +10,31 @@ export const updateOne = async function updateOne({ id, collection, data, locale
|
|
|
9
10
|
}
|
|
10
11
|
} : whereArg;
|
|
11
12
|
const Model = this.collections[collection];
|
|
12
|
-
const fields = this.payload.collections[collection].config.
|
|
13
|
-
const
|
|
13
|
+
const fields = this.payload.collections[collection].config.fields;
|
|
14
|
+
const options = {
|
|
15
|
+
...optionsArgs,
|
|
16
|
+
...await withSession(this, req),
|
|
17
|
+
lean: true,
|
|
18
|
+
new: true,
|
|
19
|
+
projection: buildProjectionFromSelect({
|
|
20
|
+
adapter: this,
|
|
21
|
+
fields: this.payload.collections[collection].config.flattenedFields,
|
|
22
|
+
select
|
|
23
|
+
})
|
|
24
|
+
};
|
|
14
25
|
const query = await Model.buildQuery({
|
|
15
26
|
locale,
|
|
16
27
|
payload: this.payload,
|
|
17
|
-
session,
|
|
18
28
|
where
|
|
19
29
|
});
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
let result;
|
|
31
|
+
const sanitizedData = sanitizeRelationshipIDs({
|
|
32
|
+
config: this.payload.config,
|
|
22
33
|
data,
|
|
23
|
-
fields
|
|
24
|
-
operation: 'update'
|
|
34
|
+
fields
|
|
25
35
|
});
|
|
26
36
|
try {
|
|
27
|
-
|
|
28
|
-
$set: data
|
|
29
|
-
}, {
|
|
30
|
-
...optionsArgs,
|
|
31
|
-
projection: buildProjectionFromSelect({
|
|
32
|
-
adapter: this,
|
|
33
|
-
fields,
|
|
34
|
-
select
|
|
35
|
-
}),
|
|
36
|
-
returnDocument: 'after',
|
|
37
|
-
session
|
|
38
|
-
});
|
|
39
|
-
transform({
|
|
40
|
-
adapter: this,
|
|
41
|
-
data: result,
|
|
42
|
-
fields,
|
|
43
|
-
operation: 'read'
|
|
44
|
-
});
|
|
45
|
-
return result;
|
|
37
|
+
result = await Model.findOneAndUpdate(query, sanitizedData, options);
|
|
46
38
|
} catch (error) {
|
|
47
39
|
handleError({
|
|
48
40
|
collection,
|
|
@@ -50,6 +42,10 @@ export const updateOne = async function updateOne({ id, collection, data, locale
|
|
|
50
42
|
req
|
|
51
43
|
});
|
|
52
44
|
}
|
|
45
|
+
result = JSON.parse(JSON.stringify(result));
|
|
46
|
+
result.id = result._id;
|
|
47
|
+
result = sanitizeInternalFields(result);
|
|
48
|
+
return result;
|
|
53
49
|
};
|
|
54
50
|
|
|
55
51
|
//# sourceMappingURL=updateOne.js.map
|
package/dist/updateOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { PayloadRequest, UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { PayloadRequest, UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { handleError } from './utilities/handleError.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n collection,\n data,\n locale,\n options: optionsArgs = {},\n req = {} as PayloadRequest,\n select,\n where: whereArg,\n },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const fields = this.payload.collections[collection].config.fields\n const options: QueryOptions = {\n ...optionsArgs,\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.collections[collection].config.flattenedFields,\n select,\n }),\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields,\n })\n\n try {\n result = await Model.findOneAndUpdate(query, sanitizedData, options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n result = JSON.parse(JSON.stringify(result))\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildProjectionFromSelect","handleError","sanitizeInternalFields","sanitizeRelationshipIDs","withSession","updateOne","id","collection","data","locale","options","optionsArgs","req","select","where","whereArg","equals","Model","collections","fields","payload","config","lean","new","projection","adapter","flattenedFields","query","buildQuery","result","sanitizedData","findOneAndUpdate","error","JSON","parse","stringify","_id"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9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1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqD,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAQ/F,eAAO,MAAM,aAAa,EAAE,aA4D3B,CAAA"}
|
package/dist/updateVersion.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { buildVersionCollectionFields } from 'payload';
|
|
2
|
-
import { getSession } from './getSession.js';
|
|
3
2
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
4
|
-
import {
|
|
3
|
+
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
4
|
+
import { withSession } from './withSession.js';
|
|
5
5
|
export const updateVersion = async function updateVersion({ id, collection, locale, options: optionsArgs = {}, req = {}, select, versionData, where }) {
|
|
6
6
|
const VersionModel = this.versions[collection];
|
|
7
7
|
const whereToUse = where || {
|
|
@@ -9,39 +9,37 @@ export const updateVersion = async function updateVersion({ id, collection, loca
|
|
|
9
9
|
equals: id
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
const fields = buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config
|
|
13
|
-
const
|
|
14
|
-
const query = await VersionModel.buildQuery({
|
|
15
|
-
locale,
|
|
16
|
-
payload: this.payload,
|
|
17
|
-
session,
|
|
18
|
-
where: whereToUse
|
|
19
|
-
});
|
|
20
|
-
transform({
|
|
21
|
-
adapter: this,
|
|
22
|
-
data: versionData,
|
|
23
|
-
fields,
|
|
24
|
-
operation: 'update'
|
|
25
|
-
});
|
|
26
|
-
const doc = await VersionModel.collection.findOneAndUpdate(query, {
|
|
27
|
-
$set: versionData
|
|
28
|
-
}, {
|
|
12
|
+
const fields = buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config);
|
|
13
|
+
const options = {
|
|
29
14
|
...optionsArgs,
|
|
15
|
+
...await withSession(this, req),
|
|
16
|
+
lean: true,
|
|
17
|
+
new: true,
|
|
30
18
|
projection: buildProjectionFromSelect({
|
|
31
19
|
adapter: this,
|
|
32
20
|
fields: buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config, true),
|
|
33
21
|
select
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
})
|
|
23
|
+
};
|
|
24
|
+
const query = await VersionModel.buildQuery({
|
|
25
|
+
locale,
|
|
26
|
+
payload: this.payload,
|
|
27
|
+
where: whereToUse
|
|
37
28
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
data:
|
|
41
|
-
fields
|
|
42
|
-
operation: 'read'
|
|
29
|
+
const sanitizedData = sanitizeRelationshipIDs({
|
|
30
|
+
config: this.payload.config,
|
|
31
|
+
data: versionData,
|
|
32
|
+
fields
|
|
43
33
|
});
|
|
44
|
-
|
|
34
|
+
const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
|
|
35
|
+
const result = JSON.parse(JSON.stringify(doc));
|
|
36
|
+
const verificationToken = doc._verificationToken;
|
|
37
|
+
// custom id type reset
|
|
38
|
+
result.id = result._id;
|
|
39
|
+
if (verificationToken) {
|
|
40
|
+
result._verificationToken = verificationToken;
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
45
43
|
};
|
|
46
44
|
|
|
47
45
|
//# sourceMappingURL=updateVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import { buildVersionCollectionFields, type PayloadRequest, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type PayloadRequest, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n {\n id,\n collection,\n locale,\n options: optionsArgs = {},\n req = {} as PayloadRequest,\n select,\n versionData,\n where,\n },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n )\n\n const options: QueryOptions = {\n ...optionsArgs,\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n true,\n ),\n select,\n }),\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: versionData,\n fields,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options)\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["buildVersionCollectionFields","buildProjectionFromSelect","sanitizeRelationshipIDs","withSession","updateVersion","id","collection","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","fields","payload","config","collections","lean","new","projection","adapter","query","buildQuery","sanitizedData","data","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAEA,SAASA,4BAA4B,QAAiD,UAAS;AAI/F,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,EAAE,EACF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
|
2
1
|
import type { PipelineStage } from 'mongoose';
|
|
3
|
-
import type { CollectionSlug, JoinQuery, SanitizedCollectionConfig } from 'payload';
|
|
2
|
+
import type { CollectionSlug, JoinQuery, SanitizedCollectionConfig, Where } from 'payload';
|
|
4
3
|
import type { MongooseAdapter } from '../index.js';
|
|
5
4
|
type BuildJoinAggregationArgs = {
|
|
6
5
|
adapter: MongooseAdapter;
|
|
7
6
|
collection: CollectionSlug;
|
|
8
7
|
collectionConfig: SanitizedCollectionConfig;
|
|
9
8
|
joins: JoinQuery;
|
|
9
|
+
limit?: number;
|
|
10
10
|
locale: string;
|
|
11
11
|
projection?: Record<string, true>;
|
|
12
|
-
|
|
12
|
+
query?: Where;
|
|
13
13
|
/** whether the query is from drafts */
|
|
14
14
|
versions?: boolean;
|
|
15
15
|
};
|
|
16
|
-
export declare const buildJoinAggregation: ({ adapter, collection, collectionConfig, joins, locale, projection,
|
|
16
|
+
export declare const buildJoinAggregation: ({ adapter, collection, collectionConfig, joins, limit, locale, projection, query, versions, }: BuildJoinAggregationArgs) => Promise<PipelineStage[] | undefined>;
|
|
17
17
|
export {};
|
|
18
18
|
//# sourceMappingURL=buildJoinAggregation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildJoinAggregation.d.ts","sourceRoot":"","sources":["../../src/utilities/buildJoinAggregation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"buildJoinAggregation.d.ts","sourceRoot":"","sources":["../../src/utilities/buildJoinAggregation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,yBAAyB,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,KAAK,wBAAwB,GAAG;IAC9B,OAAO,EAAE,eAAe,CAAA;IACxB,UAAU,EAAE,cAAc,CAAA;IAC1B,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,KAAK,EAAE,SAAS,CAAA;IAEhB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAEjC,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,uCAAuC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,oBAAoB,kGAU9B,wBAAwB,KAAG,OAAO,CAAC,aAAa,EAAE,GAAG,SAAS,CA+JhE,CAAA"}
|