@payloadcms/db-mongodb 3.10.0 → 3.11.1-canary.3f6217a
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/count.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAQpC,eAAO,MAAM,KAAK,EAAE,KA6CnB,CAAA"}
|
package/dist/count.js
CHANGED
|
@@ -1,34 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { flattenWhereToOperators } from 'payload';
|
|
2
2
|
import { getSession } from './utilities/getSession.js';
|
|
3
3
|
export const count = async function count({ collection, locale, req, where }) {
|
|
4
4
|
const Model = this.collections[collection];
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const options = {
|
|
6
|
+
session: await getSession(this, req)
|
|
7
|
+
};
|
|
8
|
+
let hasNearConstraint = false;
|
|
9
|
+
if (where) {
|
|
10
|
+
const constraints = flattenWhereToOperators(where);
|
|
11
|
+
hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
|
|
12
|
+
}
|
|
7
13
|
const query = await Model.buildQuery({
|
|
8
14
|
locale,
|
|
9
15
|
payload: this.payload,
|
|
10
|
-
session,
|
|
11
16
|
where
|
|
12
17
|
});
|
|
13
18
|
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
|
|
14
19
|
const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
|
|
20
|
+
if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
|
|
21
|
+
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
|
|
22
|
+
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
|
|
23
|
+
// which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses
|
|
24
|
+
// the correct indexed field
|
|
25
|
+
options.hint = {
|
|
26
|
+
_id: 1
|
|
27
|
+
};
|
|
28
|
+
}
|
|
15
29
|
let result;
|
|
16
30
|
if (useEstimatedCount) {
|
|
17
|
-
result = await Model.
|
|
31
|
+
result = await Model.estimatedDocumentCount({
|
|
32
|
+
session: options.session
|
|
33
|
+
});
|
|
18
34
|
} else {
|
|
19
|
-
|
|
20
|
-
session
|
|
21
|
-
};
|
|
22
|
-
if (this.disableIndexHints !== true) {
|
|
23
|
-
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
|
|
24
|
-
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
|
|
25
|
-
// which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses
|
|
26
|
-
// the correct indexed field
|
|
27
|
-
options.hint = {
|
|
28
|
-
_id: 1
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
result = await Model.collection.countDocuments(query, options);
|
|
35
|
+
result = await Model.countDocuments(query, options);
|
|
32
36
|
}
|
|
33
37
|
return {
|
|
34
38
|
totalDocs: result
|
package/dist/count.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { Count } from 'payload'\n\nimport
|
|
1
|
+
{"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { Count } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\n\nexport const count: Count = async function count(\n this: MongooseAdapter,\n { collection, locale, req, where },\n) {\n const Model = this.collections[collection]\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","getSession","count","collection","locale","req","where","Model","collections","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","query","buildQuery","payload","useEstimatedCount","length","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,QAAe,eAAeA,MAEzC,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAElC,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAwB;QAC5BC,SAAS,MAAMT,WAAW,IAAI,EAAEI;IAClC;IAEA,IAAIM,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcZ,wBAAwBM;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMX,MAAMY,UAAU,CAAC;QACnCf;QACAgB,SAAS,IAAI,CAACA,OAAO;QACrBd;IACF;IAEA,4HAA4H;IAC5H,MAAMe,oBAAoBV,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBN,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5Bd,QAAQe,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIL,mBAAmB;QACrBK,SAAS,MAAMnB,MAAMoB,sBAAsB,CAAC;YAAEjB,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLgB,SAAS,MAAMnB,MAAMqB,cAAc,CAACV,OAAOT;IAC7C;IAEA,OAAO;QACLoB,WAAWH;IACb;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"countGlobalVersions.d.ts","sourceRoot":"","sources":["../src/countGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"countGlobalVersions.d.ts","sourceRoot":"","sources":["../src/countGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAQlD,eAAO,MAAM,mBAAmB,EAAE,mBA6CjC,CAAA"}
|
|
@@ -1,34 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { flattenWhereToOperators } from 'payload';
|
|
2
2
|
import { getSession } from './utilities/getSession.js';
|
|
3
3
|
export const countGlobalVersions = async function countGlobalVersions({ global, locale, req, where }) {
|
|
4
4
|
const Model = this.versions[global];
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const options = {
|
|
6
|
+
session: await getSession(this, req)
|
|
7
|
+
};
|
|
8
|
+
let hasNearConstraint = false;
|
|
9
|
+
if (where) {
|
|
10
|
+
const constraints = flattenWhereToOperators(where);
|
|
11
|
+
hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
|
|
12
|
+
}
|
|
7
13
|
const query = await Model.buildQuery({
|
|
8
14
|
locale,
|
|
9
15
|
payload: this.payload,
|
|
10
|
-
session,
|
|
11
16
|
where
|
|
12
17
|
});
|
|
13
18
|
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
|
|
14
19
|
const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
|
|
20
|
+
if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
|
|
21
|
+
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
|
|
22
|
+
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
|
|
23
|
+
// which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses
|
|
24
|
+
// the correct indexed field
|
|
25
|
+
options.hint = {
|
|
26
|
+
_id: 1
|
|
27
|
+
};
|
|
28
|
+
}
|
|
15
29
|
let result;
|
|
16
30
|
if (useEstimatedCount) {
|
|
17
|
-
result = await Model.
|
|
31
|
+
result = await Model.estimatedDocumentCount({
|
|
32
|
+
session: options.session
|
|
33
|
+
});
|
|
18
34
|
} else {
|
|
19
|
-
|
|
20
|
-
session
|
|
21
|
-
};
|
|
22
|
-
if (Object.keys(query).length === 0 && this.disableIndexHints !== true) {
|
|
23
|
-
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
|
|
24
|
-
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
|
|
25
|
-
// which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses
|
|
26
|
-
// the correct indexed field
|
|
27
|
-
options.hint = {
|
|
28
|
-
_id: 1
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
result = await Model.collection.countDocuments(query, options);
|
|
35
|
+
result = await Model.countDocuments(query, options);
|
|
32
36
|
}
|
|
33
37
|
return {
|
|
34
38
|
totalDocs: result
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/countGlobalVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountGlobalVersions } from 'payload'\n\nimport
|
|
1
|
+
{"version":3,"sources":["../src/countGlobalVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountGlobalVersions } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\n\nexport const countGlobalVersions: CountGlobalVersions = async function countGlobalVersions(\n this: MongooseAdapter,\n { global, locale, req, where },\n) {\n const Model = this.versions[global]\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","getSession","countGlobalVersions","global","locale","req","where","Model","versions","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","query","buildQuery","payload","useEstimatedCount","length","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EAAEC,MAAM,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAE9B,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACL,OAAO;IACnC,MAAMM,UAAwB;QAC5BC,SAAS,MAAMT,WAAW,IAAI,EAAEI;IAClC;IAEA,IAAIM,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcZ,wBAAwBM;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMX,MAAMY,UAAU,CAAC;QACnCf;QACAgB,SAAS,IAAI,CAACA,OAAO;QACrBd;IACF;IAEA,4HAA4H;IAC5H,MAAMe,oBAAoBV,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBN,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5Bd,QAAQe,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIL,mBAAmB;QACrBK,SAAS,MAAMnB,MAAMoB,sBAAsB,CAAC;YAAEjB,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLgB,SAAS,MAAMnB,MAAMqB,cAAc,CAACV,OAAOT;IAC7C;IAEA,OAAO;QACLoB,WAAWH;IACb;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../src/countVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../src/countVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAQ5C,eAAO,MAAM,aAAa,EAAE,aA6C3B,CAAA"}
|
package/dist/countVersions.js
CHANGED
|
@@ -1,34 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { flattenWhereToOperators } from 'payload';
|
|
2
2
|
import { getSession } from './utilities/getSession.js';
|
|
3
3
|
export const countVersions = async function countVersions({ collection, locale, req, where }) {
|
|
4
4
|
const Model = this.versions[collection];
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const options = {
|
|
6
|
+
session: await getSession(this, req)
|
|
7
|
+
};
|
|
8
|
+
let hasNearConstraint = false;
|
|
9
|
+
if (where) {
|
|
10
|
+
const constraints = flattenWhereToOperators(where);
|
|
11
|
+
hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
|
|
12
|
+
}
|
|
7
13
|
const query = await Model.buildQuery({
|
|
8
14
|
locale,
|
|
9
15
|
payload: this.payload,
|
|
10
|
-
session,
|
|
11
16
|
where
|
|
12
17
|
});
|
|
13
18
|
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
|
|
14
19
|
const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
|
|
20
|
+
if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
|
|
21
|
+
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
|
|
22
|
+
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
|
|
23
|
+
// which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses
|
|
24
|
+
// the correct indexed field
|
|
25
|
+
options.hint = {
|
|
26
|
+
_id: 1
|
|
27
|
+
};
|
|
28
|
+
}
|
|
15
29
|
let result;
|
|
16
30
|
if (useEstimatedCount) {
|
|
17
|
-
result = await Model.
|
|
31
|
+
result = await Model.estimatedDocumentCount({
|
|
32
|
+
session: options.session
|
|
33
|
+
});
|
|
18
34
|
} else {
|
|
19
|
-
|
|
20
|
-
session
|
|
21
|
-
};
|
|
22
|
-
if (this.disableIndexHints !== true) {
|
|
23
|
-
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
|
|
24
|
-
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
|
|
25
|
-
// which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses
|
|
26
|
-
// the correct indexed field
|
|
27
|
-
options.hint = {
|
|
28
|
-
_id: 1
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
result = await Model.collection.countDocuments(query, options);
|
|
35
|
+
result = await Model.countDocuments(query, options);
|
|
32
36
|
}
|
|
33
37
|
return {
|
|
34
38
|
totalDocs: result
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/countVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountVersions } from 'payload'\n\nimport
|
|
1
|
+
{"version":3,"sources":["../src/countVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountVersions } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\n\nexport const countVersions: CountVersions = async function countVersions(\n this: MongooseAdapter,\n { collection, locale, req, where },\n) {\n const Model = this.versions[collection]\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","getSession","countVersions","collection","locale","req","where","Model","versions","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","query","buildQuery","payload","useEstimatedCount","length","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAElC,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACL,WAAW;IACvC,MAAMM,UAAwB;QAC5BC,SAAS,MAAMT,WAAW,IAAI,EAAEI;IAClC;IAEA,IAAIM,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcZ,wBAAwBM;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMX,MAAMY,UAAU,CAAC;QACnCf;QACAgB,SAAS,IAAI,CAACA,OAAO;QACrBd;IACF;IAEA,4HAA4H;IAC5H,MAAMe,oBAAoBV,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBN,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5Bd,QAAQe,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIL,mBAAmB;QACrBK,SAAS,MAAMnB,MAAMoB,sBAAsB,CAAC;YAAEjB,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLgB,SAAS,MAAMnB,MAAMqB,cAAc,CAACV,OAAOT;IAC7C;IAEA,OAAO;QACLoB,WAAWH;IACb;AACF,EAAC"}
|
package/dist/create.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAY,MAAM,SAAS,CAAA;AAQ/C,eAAO,MAAM,MAAM,EAAE,MAsCpB,CAAA"}
|
package/dist/create.js
CHANGED
|
@@ -1,31 +1,25 @@
|
|
|
1
1
|
import { getSession } from './utilities/getSession.js';
|
|
2
2
|
import { handleError } from './utilities/handleError.js';
|
|
3
|
-
import {
|
|
3
|
+
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
4
4
|
export const create = async function create({ collection, data, req }) {
|
|
5
5
|
const Model = this.collections[collection];
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
adapter: this,
|
|
6
|
+
const options = {
|
|
7
|
+
session: await getSession(this, req)
|
|
8
|
+
};
|
|
9
|
+
let doc;
|
|
10
|
+
const sanitizedData = sanitizeRelationshipIDs({
|
|
11
|
+
config: this.payload.config,
|
|
13
12
|
data,
|
|
14
|
-
fields
|
|
15
|
-
operation: 'create'
|
|
13
|
+
fields: this.payload.collections[collection].config.fields
|
|
16
14
|
});
|
|
15
|
+
if (this.payload.collections[collection].customIDType) {
|
|
16
|
+
sanitizedData._id = sanitizedData.id;
|
|
17
|
+
}
|
|
17
18
|
try {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
transform({
|
|
23
|
-
adapter: this,
|
|
24
|
-
data,
|
|
25
|
-
fields,
|
|
26
|
-
operation: 'read'
|
|
27
|
-
});
|
|
28
|
-
return data;
|
|
19
|
+
;
|
|
20
|
+
[doc] = await Model.create([
|
|
21
|
+
sanitizedData
|
|
22
|
+
], options);
|
|
29
23
|
} catch (error) {
|
|
30
24
|
handleError({
|
|
31
25
|
collection,
|
|
@@ -33,6 +27,15 @@ export const create = async function create({ collection, data, req }) {
|
|
|
33
27
|
req
|
|
34
28
|
});
|
|
35
29
|
}
|
|
30
|
+
// doc.toJSON does not do stuff like converting ObjectIds to string, or date strings to date objects. That's why we use JSON.parse/stringify here
|
|
31
|
+
const result = JSON.parse(JSON.stringify(doc));
|
|
32
|
+
const verificationToken = doc._verificationToken;
|
|
33
|
+
// custom id type reset
|
|
34
|
+
result.id = result._id;
|
|
35
|
+
if (verificationToken) {
|
|
36
|
+
result._verificationToken = verificationToken;
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
36
39
|
};
|
|
37
40
|
|
|
38
41
|
//# sourceMappingURL=create.js.map
|
package/dist/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { Create } 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 { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.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 const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields: this.payload.collections[collection].config.fields,\n })\n\n if (this.payload.collections[collection].customIDType) {\n sanitizedData._id = sanitizedData.id\n }\n\n try {\n ;[doc] = await Model.create([sanitizedData], options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n // doc.toJSON does not do stuff like converting ObjectIds to string, or date strings to date objects. That's why we use JSON.parse/stringify here\n const result: Document = JSON.parse(JSON.stringify(doc))\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n\n return result\n}\n"],"names":["getSession","handleError","sanitizeRelationshipIDs","create","collection","data","req","Model","collections","options","session","doc","sanitizedData","config","payload","fields","customIDType","_id","id","error","result","JSON","parse","stringify","verificationToken","_verificationToken"],"mappings":"AAKA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,uBAAuB,QAAQ,yCAAwC;AAEhF,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;IAEJ,MAAMC,gBAAgBV,wBAAwB;QAC5CW,QAAQ,IAAI,CAACC,OAAO,CAACD,MAAM;QAC3BR;QACAU,QAAQ,IAAI,CAACD,OAAO,CAACN,WAAW,CAACJ,WAAW,CAACS,MAAM,CAACE,MAAM;IAC5D;IAEA,IAAI,IAAI,CAACD,OAAO,CAACN,WAAW,CAACJ,WAAW,CAACY,YAAY,EAAE;QACrDJ,cAAcK,GAAG,GAAGL,cAAcM,EAAE;IACtC;IAEA,IAAI;;QACD,CAACP,IAAI,GAAG,MAAMJ,MAAMJ,MAAM,CAAC;YAACS;SAAc,EAAEH;IAC/C,EAAE,OAAOU,OAAO;QACdlB,YAAY;YAAEG;YAAYe;YAAOb;QAAI;IACvC;IAEA,iJAAiJ;IACjJ,MAAMc,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACZ;IACnD,MAAMa,oBAAoBb,IAAIc,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOF,EAAE,GAAGE,OAAOH,GAAG;IACtB,IAAIO,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IAEA,OAAOJ;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createGlobal.d.ts","sourceRoot":"","sources":["../src/createGlobal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createGlobal.d.ts","sourceRoot":"","sources":["../src/createGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAQ3C,eAAO,MAAM,YAAY,EAAE,YA4B1B,CAAA"}
|
package/dist/createGlobal.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { getSession } from './utilities/getSession.js';
|
|
2
|
-
import {
|
|
2
|
+
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
|
3
|
+
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
3
4
|
export const createGlobal = async function createGlobal({ slug, data, req }) {
|
|
4
5
|
const Model = this.globals;
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const global = sanitizeRelationshipIDs({
|
|
7
|
+
config: this.payload.config,
|
|
8
|
+
data: {
|
|
9
|
+
globalType: slug,
|
|
10
|
+
...data
|
|
11
|
+
},
|
|
12
|
+
fields: this.payload.config.globals.find((globalConfig)=>globalConfig.slug === slug).fields
|
|
12
13
|
});
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return data;
|
|
14
|
+
const options = {
|
|
15
|
+
session: await getSession(this, req)
|
|
16
|
+
};
|
|
17
|
+
let [result] = await Model.create([
|
|
18
|
+
global
|
|
19
|
+
], options);
|
|
20
|
+
result = JSON.parse(JSON.stringify(result));
|
|
21
|
+
// custom id type reset
|
|
22
|
+
result.id = result._id;
|
|
23
|
+
result = sanitizeInternalFields(result);
|
|
24
|
+
return result;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
//# sourceMappingURL=createGlobal.js.map
|
package/dist/createGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createGlobal.ts"],"sourcesContent":["import 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 { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\n\nexport const createGlobal: CreateGlobal = async function createGlobal(\n this: MongooseAdapter,\n { slug, data, req },\n) {\n const Model = this.globals\n\n const global = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: {\n globalType: slug,\n ...data,\n },\n fields: this.payload.config.globals.find((globalConfig) => globalConfig.slug === slug).fields,\n })\n\n const options: CreateOptions = {\n session: await getSession(this, req),\n }\n\n let [result] = (await Model.create([global], options)) as any\n\n result = JSON.parse(JSON.stringify(result))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["getSession","sanitizeInternalFields","sanitizeRelationshipIDs","createGlobal","slug","data","req","Model","globals","global","config","payload","globalType","fields","find","globalConfig","options","session","result","create","JSON","parse","stringify","id","_id"],"mappings":"AAKA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAEhF,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,GAAG,EAAE;IAEnB,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAE1B,MAAMC,SAASP,wBAAwB;QACrCQ,QAAQ,IAAI,CAACC,OAAO,CAACD,MAAM;QAC3BL,MAAM;YACJO,YAAYR;YACZ,GAAGC,IAAI;QACT;QACAQ,QAAQ,IAAI,CAACF,OAAO,CAACD,MAAM,CAACF,OAAO,CAACM,IAAI,CAAC,CAACC,eAAiBA,aAAaX,IAAI,KAAKA,MAAMS,MAAM;IAC/F;IAEA,MAAMG,UAAyB;QAC7BC,SAAS,MAAMjB,WAAW,IAAI,EAAEM;IAClC;IAEA,IAAI,CAACY,OAAO,GAAI,MAAMX,MAAMY,MAAM,CAAC;QAACV;KAAO,EAAEO;IAE7CE,SAASE,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACJ;IAEnC,uBAAuB;IACvBA,OAAOK,EAAE,GAAGL,OAAOM,GAAG;IACtBN,SAASjB,uBAAuBiB;IAEhC,OAAOA;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,KAAK,mBAAmB,EAAiB,MAAM,SAAS,CAAA;AAO3F,eAAO,MAAM,mBAAmB,EAAE,mBAwEjC,CAAA"}
|
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
import { buildVersionGlobalFields } from 'payload';
|
|
2
2
|
import { getSession } from './utilities/getSession.js';
|
|
3
|
-
import {
|
|
3
|
+
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.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
|
-
const
|
|
7
|
-
|
|
8
|
-
autosave,
|
|
9
|
-
createdAt,
|
|
10
|
-
latest: true,
|
|
11
|
-
parent,
|
|
12
|
-
publishedLocale,
|
|
13
|
-
snapshot,
|
|
14
|
-
updatedAt,
|
|
15
|
-
version: versionData
|
|
6
|
+
const options = {
|
|
7
|
+
session: await getSession(this, req)
|
|
16
8
|
};
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
const data = sanitizeRelationshipIDs({
|
|
10
|
+
config: this.payload.config,
|
|
11
|
+
data: {
|
|
12
|
+
autosave,
|
|
13
|
+
createdAt,
|
|
14
|
+
latest: true,
|
|
15
|
+
parent,
|
|
16
|
+
publishedLocale,
|
|
17
|
+
snapshot,
|
|
18
|
+
updatedAt,
|
|
19
|
+
version: versionData
|
|
20
|
+
},
|
|
21
|
+
fields: buildVersionGlobalFields(this.payload.config, this.payload.config.globals.find((global)=>global.slug === globalSlug))
|
|
23
22
|
});
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
await VersionModel.collection.updateMany({
|
|
23
|
+
const [doc] = await VersionModel.create([
|
|
24
|
+
data
|
|
25
|
+
], options, req);
|
|
26
|
+
await VersionModel.updateMany({
|
|
29
27
|
$and: [
|
|
30
28
|
{
|
|
31
29
|
_id: {
|
|
32
|
-
$ne:
|
|
30
|
+
$ne: doc._id
|
|
33
31
|
}
|
|
34
32
|
},
|
|
35
33
|
{
|
|
@@ -47,16 +45,15 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
|
|
|
47
45
|
$unset: {
|
|
48
46
|
latest: 1
|
|
49
47
|
}
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return data;
|
|
48
|
+
}, options);
|
|
49
|
+
const result = JSON.parse(JSON.stringify(doc));
|
|
50
|
+
const verificationToken = doc._verificationToken;
|
|
51
|
+
// custom id type reset
|
|
52
|
+
result.id = result._id;
|
|
53
|
+
if (verificationToken) {
|
|
54
|
+
result._verificationToken = verificationToken;
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
60
57
|
};
|
|
61
58
|
|
|
62
59
|
//# sourceMappingURL=createGlobalVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import { buildVersionGlobalFields, type CreateGlobalVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import type { CreateOptions } from 'mongoose'\n\nimport { buildVersionGlobalFields, type CreateGlobalVersion, 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 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 = 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: buildVersionGlobalFields(\n this.payload.config,\n this.payload.config.globals.find((global) => global.slug === globalSlug),\n ),\n })\n\n const [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 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":["buildVersionGlobalFields","getSession","sanitizeRelationshipIDs","createGlobalVersion","autosave","createdAt","globalSlug","parent","publishedLocale","req","snapshot","updatedAt","versionData","VersionModel","versions","options","session","data","config","payload","latest","version","fields","globals","find","global","slug","doc","create","updateMany","$and","_id","$ne","$eq","$unset","result","JSON","parse","stringify","verificationToken","_verificationToken","id"],"mappings":"AAEA,SAASA,wBAAwB,QAAiD,UAAS;AAI3F,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,uBAAuB,QAAQ,yCAAwC;AAEhF,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,OAAOf,wBAAwB;QACnCgB,QAAQ,IAAI,CAACC,OAAO,CAACD,MAAM;QAC3BD,MAAM;YACJb;YACAC;YACAe,QAAQ;YACRb;YACAC;YACAE;YACAC;YACAU,SAAST;QACX;QACAU,QAAQtB,yBACN,IAAI,CAACmB,OAAO,CAACD,MAAM,EACnB,IAAI,CAACC,OAAO,CAACD,MAAM,CAACK,OAAO,CAACC,IAAI,CAAC,CAACC,SAAWA,OAAOC,IAAI,KAAKpB;IAEjE;IAEA,MAAM,CAACqB,IAAI,GAAG,MAAMd,aAAae,MAAM,CAAC;QAACX;KAAK,EAAEF,SAASN;IAEzD,MAAMI,aAAagB,UAAU,CAC3B;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKL,IAAII,GAAG;gBACd;YACF;YACA;gBACExB,QAAQ;oBACN0B,KAAK1B;gBACP;YACF;YACA;gBACEa,QAAQ;oBACNa,KAAK;gBACP;YACF;SACD;IACH,GACA;QAAEC,QAAQ;YAAEd,QAAQ;QAAE;IAAE,GACxBL;IAGF,MAAMoB,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACX;IACnD,MAAMY,oBAAoBZ,IAAIa,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOM,EAAE,GAAGN,OAAOJ,GAAG;IACtB,IAAIQ,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;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":"AAGA,OAAO,EAAgC,KAAK,aAAa,EAAiB,MAAM,SAAS,CAAA;AAOzF,eAAO,MAAM,aAAa,EAAE,aA0F3B,CAAA"}
|