@payloadcms/db-mongodb 4.0.0-internal.183b315 → 4.0.0-internal.1a2a79e
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/LICENSE.md +1 -1
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +9 -2
- package/dist/connect.js.map +1 -1
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +33 -4
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts.map +1 -1
- package/dist/countGlobalVersions.js +1 -0
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +36 -4
- package/dist/countVersions.js.map +1 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +2 -1
- package/dist/create.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +23 -2
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +9 -2
- package/dist/createMigration.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +17 -4
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteBranchGlobal.d.ts +10 -0
- package/dist/deleteBranchGlobal.d.ts.map +1 -0
- package/dist/deleteBranchGlobal.js +22 -0
- package/dist/deleteBranchGlobal.js.map +1 -0
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +1 -0
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +20 -1
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +1 -0
- package/dist/deleteVersions.js.map +1 -1
- package/dist/exports/migration-utils.d.ts +3 -0
- package/dist/exports/migration-utils.d.ts.map +1 -1
- package/dist/exports/migration-utils.js +3 -0
- package/dist/exports/migration-utils.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +44 -8
- package/dist/find.js.map +1 -1
- package/dist/findDistinct.d.ts.map +1 -1
- package/dist/findDistinct.js +115 -12
- package/dist/findDistinct.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +34 -5
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +10 -2
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +43 -5
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +49 -5
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +89 -67
- package/dist/init.js.map +1 -1
- package/dist/migrateFresh.d.ts +4 -2
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +21 -6
- package/dist/migrateFresh.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +8 -2
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +4 -2
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts +5 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +34 -3
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +4 -0
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +115 -37
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/models/schemaBuildContext.d.ts +21 -0
- package/dist/models/schemaBuildContext.d.ts.map +1 -0
- package/dist/models/schemaBuildContext.js +29 -0
- package/dist/models/schemaBuildContext.js.map +1 -0
- package/dist/predefinedMigrations/branching.d.ts +4 -0
- package/dist/predefinedMigrations/branching.d.ts.map +1 -0
- package/dist/predefinedMigrations/branching.js +9 -0
- package/dist/predefinedMigrations/branching.js.map +1 -0
- package/dist/predefinedMigrations/localize-status.d.ts +4 -0
- package/dist/predefinedMigrations/localize-status.d.ts.map +1 -0
- package/dist/predefinedMigrations/localize-status.js +9 -0
- package/dist/predefinedMigrations/localize-status.js.map +1 -0
- package/dist/predefinedMigrations/migrateBranching.d.ts +15 -0
- package/dist/predefinedMigrations/migrateBranching.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateBranching.js +88 -0
- package/dist/predefinedMigrations/migrateBranching.js.map +1 -0
- package/dist/predefinedMigrations/migrateLocalizeStatus.d.ts +27 -0
- package/dist/predefinedMigrations/migrateLocalizeStatus.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateLocalizeStatus.js +324 -0
- package/dist/predefinedMigrations/migrateLocalizeStatus.js.map +1 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +4 -4
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/predefinedMigrations/migrateSizesToVariants.d.ts +13 -0
- package/dist/predefinedMigrations/migrateSizesToVariants.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateSizesToVariants.js +368 -0
- package/dist/predefinedMigrations/migrateSizesToVariants.js.map +1 -0
- package/dist/predefinedMigrations/sizes-to-variants.d.ts +5 -0
- package/dist/predefinedMigrations/sizes-to-variants.d.ts.map +1 -0
- package/dist/predefinedMigrations/sizes-to-variants.js +8 -0
- package/dist/predefinedMigrations/sizes-to-variants.js.map +1 -0
- package/dist/queries/buildAndOrConditions.d.ts +4 -2
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +3 -1
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildBranchVisibility.d.ts +11 -0
- package/dist/queries/buildBranchVisibility.d.ts.map +1 -0
- package/dist/queries/buildBranchVisibility.js +204 -0
- package/dist/queries/buildBranchVisibility.js.map +1 -0
- package/dist/queries/buildQuery.d.ts +4 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +3 -1
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +4 -2
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +338 -24
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/getBuildQueryPlugin.d.ts +3 -1
- package/dist/queries/getBuildQueryPlugin.d.ts.map +1 -1
- package/dist/queries/getBuildQueryPlugin.js +3 -1
- package/dist/queries/getBuildQueryPlugin.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
- package/dist/queries/getLocalizedSortProperty.js +1 -1
- package/dist/queries/getLocalizedSortProperty.js.map +1 -1
- package/dist/queries/operatorMap.d.ts.map +1 -1
- package/dist/queries/parseParams.d.ts +4 -2
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +5 -1
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +2 -3
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +38 -7
- package/dist/queryDrafts.js.map +1 -1
- package/dist/testCredentials.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +0 -1
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +68 -7
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
- package/dist/transactions/rollbackTransaction.js +10 -9
- package/dist/transactions/rollbackTransaction.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +89 -9
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +3 -2
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateJobs.d.ts.map +1 -1
- package/dist/updateJobs.js +71 -14
- package/dist/updateJobs.js.map +1 -1
- package/dist/updateMany.d.ts.map +1 -1
- package/dist/updateMany.js +3 -2
- package/dist/updateMany.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +30 -4
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +3 -2
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsertBranchGlobalChange.d.ts +3 -0
- package/dist/upsertBranchGlobalChange.d.ts.map +1 -0
- package/dist/upsertBranchGlobalChange.js +28 -0
- package/dist/upsertBranchGlobalChange.js.map +1 -0
- package/dist/utilities/aggregatePaginate.d.ts +2 -1
- package/dist/utilities/aggregatePaginate.d.ts.map +1 -1
- package/dist/utilities/aggregatePaginate.js +21 -5
- package/dist/utilities/aggregatePaginate.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts +4 -2
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +124 -21
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.js +1 -1
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
- package/dist/utilities/getDBName.d.ts.map +1 -1
- package/dist/utilities/getEntity.d.ts +1 -1
- package/dist/utilities/getEntity.d.ts.map +1 -1
- package/dist/utilities/handleError.d.ts.map +1 -1
- package/dist/utilities/isObjectID.d.ts.map +1 -1
- package/dist/utilities/resolveJoins.d.ts +6 -2
- package/dist/utilities/resolveJoins.d.ts.map +1 -1
- package/dist/utilities/resolveJoins.js +114 -26
- package/dist/utilities/resolveJoins.js.map +1 -1
- package/dist/utilities/transform.d.ts.map +1 -1
- package/dist/utilities/transform.js +25 -34
- package/dist/utilities/transform.js.map +1 -1
- package/package.json +18 -21
- package/dist/queries/buildSortParam.spec.js +0 -123
- package/dist/queries/buildSortParam.spec.js.map +0 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +0 -215
- package/dist/queries/getLocalizedSortProperty.spec.js.map +0 -1
- package/dist/utilities/transform.spec.js +0 -479
- package/dist/utilities/transform.spec.js.map +0 -1
package/dist/updateOne.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAaxC,eAAO,MAAM,SAAS,EAAE,SAuHvB,CAAA"}
|
package/dist/updateOne.js
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
+
import { applyBranchIDProjection, resolveBranchRowID, withBranchIDSelect } from 'payload';
|
|
1
2
|
import { buildQuery } from './queries/buildQuery.js';
|
|
2
3
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
4
|
import { getCollection } from './utilities/getEntity.js';
|
|
4
5
|
import { getSession } from './utilities/getSession.js';
|
|
5
6
|
import { handleError } from './utilities/handleError.js';
|
|
6
7
|
import { transform } from './utilities/transform.js';
|
|
7
|
-
export const updateOne = async function updateOne({ id, collection: collectionSlug, data, locale, options: optionsArgs = {}, req, returning, select, where: whereArg = {} }) {
|
|
8
|
+
export const updateOne = async function updateOne({ id, branch, collection: collectionSlug, data, locale, options: optionsArgs = {}, req, returning, select, where: whereArg = {} }) {
|
|
8
9
|
const { collectionConfig, Model } = getCollection({
|
|
9
10
|
adapter: this,
|
|
10
11
|
collectionSlug
|
|
11
12
|
});
|
|
13
|
+
if (id !== undefined && id !== null) {
|
|
14
|
+
id = await resolveBranchRowID({
|
|
15
|
+
id,
|
|
16
|
+
branch,
|
|
17
|
+
collectionSlug,
|
|
18
|
+
req
|
|
19
|
+
});
|
|
20
|
+
}
|
|
12
21
|
const where = id ? {
|
|
13
22
|
id: {
|
|
14
23
|
equals: id
|
|
@@ -17,9 +26,11 @@ export const updateOne = async function updateOne({ id, collection: collectionSl
|
|
|
17
26
|
const fields = collectionConfig.fields;
|
|
18
27
|
const query = await buildQuery({
|
|
19
28
|
adapter: this,
|
|
29
|
+
branch,
|
|
20
30
|
collectionSlug,
|
|
21
31
|
fields: collectionConfig.flattenedFields,
|
|
22
32
|
locale,
|
|
33
|
+
req,
|
|
23
34
|
where
|
|
24
35
|
});
|
|
25
36
|
let result;
|
|
@@ -64,12 +75,17 @@ export const updateOne = async function updateOne({ id, collection: collectionSl
|
|
|
64
75
|
const findOptions = {
|
|
65
76
|
...baseOptions,
|
|
66
77
|
lean: true,
|
|
67
|
-
new: true,
|
|
68
78
|
projection: buildProjectionFromSelect({
|
|
69
79
|
adapter: this,
|
|
70
80
|
fields: collectionConfig.flattenedFields,
|
|
71
|
-
select
|
|
72
|
-
|
|
81
|
+
select: withBranchIDSelect({
|
|
82
|
+
branch,
|
|
83
|
+
collectionSlug,
|
|
84
|
+
req,
|
|
85
|
+
select
|
|
86
|
+
})
|
|
87
|
+
}),
|
|
88
|
+
returnDocument: 'after'
|
|
73
89
|
};
|
|
74
90
|
try {
|
|
75
91
|
if (returning === false) {
|
|
@@ -100,6 +116,16 @@ export const updateOne = async function updateOne({ id, collection: collectionSl
|
|
|
100
116
|
fields,
|
|
101
117
|
operation: 'read'
|
|
102
118
|
});
|
|
119
|
+
// The row written on a branch is the shadow row, so the document it returns
|
|
120
|
+
// carries that row's primary key rather than the document's canonical ID.
|
|
121
|
+
applyBranchIDProjection({
|
|
122
|
+
branch,
|
|
123
|
+
collectionSlug,
|
|
124
|
+
docs: [
|
|
125
|
+
result
|
|
126
|
+
],
|
|
127
|
+
req
|
|
128
|
+
});
|
|
103
129
|
return result;
|
|
104
130
|
};
|
|
105
131
|
|
package/dist/updateOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n collection: collectionSlug,\n data,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n where: whereArg = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n const where = id ? { id: { equals: id } } : whereArg\n const fields = collectionConfig.fields\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n let result\n\n let updateData: UpdateQuery<any> = data\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = updateData\n updateData = updateOps\n }\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n
|
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport { applyBranchIDProjection, resolveBranchRowID, withBranchIDSelect } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n branch,\n collection: collectionSlug,\n data,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n where: whereArg = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n if (id !== undefined && id !== null) {\n id = await resolveBranchRowID({ id, branch, collectionSlug, req })\n }\n\n const where = id ? { id: { equals: id } } : whereArg\n const fields = collectionConfig.fields\n\n const query = await buildQuery({\n adapter: this,\n branch,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n req,\n where,\n })\n\n let result\n\n let updateData: UpdateQuery<any> = data\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = updateData\n updateData = updateOps\n }\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select: withBranchIDSelect({ branch, collectionSlug, req, select }),\n }),\n returnDocument: 'after',\n }\n\n try {\n if (returning === false) {\n await Model.updateOne(query, updateData, baseOptions)\n transform({ adapter: this, data, fields, operation: 'read' })\n return null\n } else {\n result = await Model.findOneAndUpdate(query, updateData, findOptions)\n }\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n\n if (!result) {\n return null\n }\n\n transform({ adapter: this, data: result, fields, operation: 'read' })\n\n // The row written on a branch is the shadow row, so the document it returns\n // carries that row's primary key rather than the document's canonical ID.\n applyBranchIDProjection({\n branch,\n collectionSlug,\n docs: [result as Record<string, unknown>],\n req,\n })\n\n return result\n}\n"],"names":["applyBranchIDProjection","resolveBranchRowID","withBranchIDSelect","buildQuery","buildProjectionFromSelect","getCollection","getSession","handleError","transform","updateOne","id","branch","collection","collectionSlug","data","locale","options","optionsArgs","req","returning","select","where","whereArg","collectionConfig","Model","adapter","undefined","equals","fields","query","flattenedFields","result","updateData","$inc","$push","$addToSet","$pull","operation","updateOps","Object","keys","length","$set","baseOptions","session","timestamps","findOptions","lean","projection","returnDocument","findOneAndUpdate","error","docs"],"mappings":"AAGA,SAASA,uBAAuB,EAAEC,kBAAkB,EAAEC,kBAAkB,QAAQ,UAAS;AAIzF,SAASC,UAAU,QAAQ,0BAAyB;AACpD,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"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAU1E,eAAO,MAAM,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAU1E,eAAO,MAAM,aAAa,EAAE,aAmE3B,CAAA"}
|
package/dist/updateVersion.js
CHANGED
|
@@ -21,6 +21,7 @@ export const updateVersion = async function updateVersion({ id, collection: coll
|
|
|
21
21
|
adapter: this,
|
|
22
22
|
fields: flattenedFields,
|
|
23
23
|
locale,
|
|
24
|
+
req,
|
|
24
25
|
where: whereToUse
|
|
25
26
|
});
|
|
26
27
|
transform({
|
|
@@ -38,12 +39,12 @@ export const updateVersion = async function updateVersion({ id, collection: coll
|
|
|
38
39
|
const findOptions = {
|
|
39
40
|
...baseOptions,
|
|
40
41
|
lean: true,
|
|
41
|
-
new: true,
|
|
42
42
|
projection: buildProjectionFromSelect({
|
|
43
43
|
adapter: this,
|
|
44
44
|
fields: flattenedFields,
|
|
45
45
|
select
|
|
46
|
-
})
|
|
46
|
+
}),
|
|
47
|
+
returnDocument: 'after'
|
|
47
48
|
};
|
|
48
49
|
if (returning === false) {
|
|
49
50
|
await Model.updateOne(query, versionData, baseOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n {\n id,\n collection: collectionSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n const flattenedFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n transform({ adapter: this, data: versionData, fields, operation: 'write' })\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n
|
|
1
|
+
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n {\n id,\n collection: collectionSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n const flattenedFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n req,\n where: whereToUse,\n })\n\n transform({ adapter: this, data: versionData, fields, operation: 'write' })\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n returnDocument: 'after',\n }\n\n if (returning === false) {\n await Model.updateOne(query, versionData, baseOptions)\n return null\n }\n\n const doc = await Model.findOneAndUpdate(query, versionData, findOptions)\n\n if (!doc) {\n return null\n }\n\n transform({ adapter: this, data: doc, fields, operation: 'read' })\n\n return doc\n}\n"],"names":["buildVersionCollectionFields","buildQuery","buildProjectionFromSelect","getCollection","getSession","transform","updateVersion","id","collection","collectionSlug","locale","options","optionsArgs","req","returning","select","versionData","where","collectionConfig","Model","adapter","versions","whereToUse","equals","fields","payload","config","flattenedFields","query","data","operation","baseOptions","session","timestamps","findOptions","lean","projection","returnDocument","updateOne","doc","findOneAndUpdate"],"mappings":"AAEA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,EAAE,EACFC,YAAYC,cAAc,EAC1BC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,WAAW,EACXC,KAAK,EACN;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGhB,cAAc;QAChDiB,SAAS,IAAI;QACbX;QACAY,UAAU;IACZ;IAEA,MAAMC,aAAaL,SAAS;QAAEV,IAAI;YAAEgB,QAAQhB;QAAG;IAAE;IACjD,MAAMiB,SAASxB,6BAA6B,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAER;IAEjE,MAAMS,kBAAkB3B,6BAA6B,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAER,kBAAkB;IAE5F,MAAMU,QAAQ,MAAM3B,WAAW;QAC7BmB,SAAS,IAAI;QACbI,QAAQG;QACRjB;QACAG;QACAI,OAAOK;IACT;IAEAjB,UAAU;QAAEe,SAAS,IAAI;QAAES,MAAMb;QAAaQ;QAAQM,WAAW;IAAQ;IAEzE,MAAMC,cAAc;QAClB,GAAGnB,WAAW;QACdoB,SAAS,MAAM5B,WAAW,IAAI,EAAES;QAChC,uDAAuD;QACvDoB,YAAY;IACd;IAEA,MAAMC,cAA4B;QAChC,GAAGH,WAAW;QACdI,MAAM;QACNC,YAAYlC,0BAA0B;YACpCkB,SAAS,IAAI;YACbI,QAAQG;YACRZ;QACF;QACAsB,gBAAgB;IAClB;IAEA,IAAIvB,cAAc,OAAO;QACvB,MAAMK,MAAMmB,SAAS,CAACV,OAAOZ,aAAae;QAC1C,OAAO;IACT;IAEA,MAAMQ,MAAM,MAAMpB,MAAMqB,gBAAgB,CAACZ,OAAOZ,aAAakB;IAE7D,IAAI,CAACK,KAAK;QACR,OAAO;IACT;IAEAlC,UAAU;QAAEe,SAAS,IAAI;QAAES,MAAMU;QAAKf;QAAQM,WAAW;IAAO;IAEhE,OAAOS;AACT,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upsertBranchGlobalChange.d.ts","sourceRoot":"","sources":["../src/upsertBranchGlobalChange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAQvD,eAAO,MAAM,wBAAwB,EAAE,wBAuBpC,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { branchChangesCollectionSlug } from 'payload';
|
|
2
|
+
import { getSession } from './utilities/getSession.js';
|
|
3
|
+
export const upsertBranchGlobalChange = async function upsertBranchGlobalChange({ branch, globalSlug, req }) {
|
|
4
|
+
const Model = this.collections[branchChangesCollectionSlug];
|
|
5
|
+
const now = new Date().toISOString();
|
|
6
|
+
if (!Model) {
|
|
7
|
+
throw new Error(`Collection model "${branchChangesCollectionSlug}" is not initialized.`);
|
|
8
|
+
}
|
|
9
|
+
await Model.updateOne({
|
|
10
|
+
branch,
|
|
11
|
+
globalSlug
|
|
12
|
+
}, {
|
|
13
|
+
$setOnInsert: {
|
|
14
|
+
branch,
|
|
15
|
+
createdAt: now,
|
|
16
|
+
entityType: 'global',
|
|
17
|
+
globalSlug,
|
|
18
|
+
operation: 'update',
|
|
19
|
+
updatedAt: now
|
|
20
|
+
}
|
|
21
|
+
}, {
|
|
22
|
+
session: await getSession(this, req),
|
|
23
|
+
timestamps: false,
|
|
24
|
+
upsert: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=upsertBranchGlobalChange.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/upsertBranchGlobalChange.ts"],"sourcesContent":["import type { UpsertBranchGlobalChange } from 'payload'\n\nimport { branchChangesCollectionSlug } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\n\nexport const upsertBranchGlobalChange: UpsertBranchGlobalChange =\n async function upsertBranchGlobalChange(this: MongooseAdapter, { branch, globalSlug, req }) {\n const Model = this.collections[branchChangesCollectionSlug]\n const now = new Date().toISOString()\n\n if (!Model) {\n throw new Error(`Collection model \"${branchChangesCollectionSlug}\" is not initialized.`)\n }\n\n await Model.updateOne(\n { branch, globalSlug },\n {\n $setOnInsert: {\n branch,\n createdAt: now,\n entityType: 'global',\n globalSlug,\n operation: 'update',\n updatedAt: now,\n },\n },\n { session: await getSession(this, req), timestamps: false, upsert: true },\n )\n }\n"],"names":["branchChangesCollectionSlug","getSession","upsertBranchGlobalChange","branch","globalSlug","req","Model","collections","now","Date","toISOString","Error","updateOne","$setOnInsert","createdAt","entityType","operation","updatedAt","session","timestamps","upsert"],"mappings":"AAEA,SAASA,2BAA2B,QAAQ,UAAS;AAIrD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,2BACX,eAAeA,yBAAgD,EAAEC,MAAM,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACxF,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACP,4BAA4B;IAC3D,MAAMQ,MAAM,IAAIC,OAAOC,WAAW;IAElC,IAAI,CAACJ,OAAO;QACV,MAAM,IAAIK,MAAM,CAAC,kBAAkB,EAAEX,4BAA4B,qBAAqB,CAAC;IACzF;IAEA,MAAMM,MAAMM,SAAS,CACnB;QAAET;QAAQC;IAAW,GACrB;QACES,cAAc;YACZV;YACAW,WAAWN;YACXO,YAAY;YACZX;YACAY,WAAW;YACXC,WAAWT;QACb;IACF,GACA;QAAEU,SAAS,MAAMjB,WAAW,IAAI,EAAEI;QAAMc,YAAY;QAAOC,QAAQ;IAAK;AAE5E,EAAC"}
|
|
@@ -2,8 +2,9 @@ import type { CollationOptions } from 'mongodb';
|
|
|
2
2
|
import type { ClientSession, Model, PipelineStage } from 'mongoose';
|
|
3
3
|
import type { PaginatedDocs } from 'payload';
|
|
4
4
|
import type { MongooseAdapter } from '../index.js';
|
|
5
|
-
export declare const aggregatePaginate: ({ adapter, collation, joinAggregation, limit, Model, page, pagination, projection, query, session, sort, sortAggregation, useEstimatedCount, }: {
|
|
5
|
+
export declare const aggregatePaginate: ({ adapter, branchVisibility, collation, joinAggregation, limit, Model, page, pagination, projection, query, session, sort, sortAggregation, useEstimatedCount, }: {
|
|
6
6
|
adapter: MongooseAdapter;
|
|
7
|
+
branchVisibility?: PipelineStage[];
|
|
7
8
|
collation?: CollationOptions;
|
|
8
9
|
joinAggregation?: PipelineStage[];
|
|
9
10
|
limit?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregatePaginate.d.ts","sourceRoot":"","sources":["../../src/utilities/aggregatePaginate.ts"],"names":[],"mappings":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CAAA;CAC5B,KAAG,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CA+F7B,CAAA"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export const aggregatePaginate = async ({ adapter, collation, joinAggregation, limit, Model, page, pagination, projection, query, session, sort, sortAggregation, useEstimatedCount })=>{
|
|
1
|
+
export const aggregatePaginate = async ({ adapter, branchVisibility, collation, joinAggregation, limit, Model, page, pagination, projection, query, session, sort, sortAggregation, useEstimatedCount })=>{
|
|
2
2
|
const aggregation = [
|
|
3
3
|
{
|
|
4
4
|
$match: query
|
|
5
|
-
}
|
|
5
|
+
},
|
|
6
|
+
...branchVisibility ?? []
|
|
6
7
|
];
|
|
7
8
|
if (sortAggregation && sortAggregation.length > 0) {
|
|
8
9
|
for (const stage of sortAggregation){
|
|
@@ -40,10 +41,25 @@ export const aggregatePaginate = async ({ adapter, collation, joinAggregation, l
|
|
|
40
41
|
}
|
|
41
42
|
let countPromise = Promise.resolve(null);
|
|
42
43
|
if (pagination !== false && limit) {
|
|
43
|
-
if (
|
|
44
|
+
if (branchVisibility?.length) {
|
|
45
|
+
countPromise = Model.aggregate([
|
|
46
|
+
{
|
|
47
|
+
$match: query
|
|
48
|
+
},
|
|
49
|
+
...branchVisibility,
|
|
50
|
+
{
|
|
51
|
+
$count: 'count'
|
|
52
|
+
}
|
|
53
|
+
], {
|
|
54
|
+
collation,
|
|
55
|
+
session
|
|
56
|
+
}).then((result)=>result[0]?.count ?? 0);
|
|
57
|
+
} else if (useEstimatedCount) {
|
|
44
58
|
countPromise = Model.estimatedDocumentCount(query);
|
|
45
59
|
} else {
|
|
46
|
-
|
|
60
|
+
// Only hint the _id index for unfiltered counts. With a filter, MongoDB picks the matching index on its own,
|
|
61
|
+
// while forcing _id would make it scan the whole collection.
|
|
62
|
+
const hint = adapter.disableIndexHints !== true && Object.keys(query).length === 0 ? {
|
|
47
63
|
_id: 1
|
|
48
64
|
} : undefined;
|
|
49
65
|
countPromise = Model.countDocuments(query, {
|
|
@@ -63,7 +79,7 @@ export const aggregatePaginate = async ({ adapter, collation, joinAggregation, l
|
|
|
63
79
|
countPromise
|
|
64
80
|
]);
|
|
65
81
|
const count = countResult === null ? docs.length : countResult;
|
|
66
|
-
const totalPages = pagination !== false && typeof limit === 'number' && limit !== 0 ? Math.ceil(count / limit) : 1;
|
|
82
|
+
const totalPages = pagination !== false && typeof limit === 'number' && limit !== 0 ? Math.max(1, Math.ceil(count / limit)) : 1;
|
|
67
83
|
const hasPrevPage = typeof page === 'number' && pagination !== false && page > 1;
|
|
68
84
|
const hasNextPage = typeof page === 'number' && pagination !== false && totalPages > page;
|
|
69
85
|
const pagingCounter = typeof page === 'number' && pagination !== false && typeof limit === 'number' ? (page - 1) * limit + 1 : 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/aggregatePaginate.ts"],"sourcesContent":["import type { CollationOptions } from 'mongodb'\nimport type { ClientSession, Model, PipelineStage } from 'mongoose'\nimport type { PaginatedDocs } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const aggregatePaginate = async ({\n adapter,\n collation,\n joinAggregation,\n limit,\n Model,\n page,\n pagination,\n projection,\n query,\n session,\n sort,\n sortAggregation,\n useEstimatedCount,\n}: {\n adapter: MongooseAdapter\n collation?: CollationOptions\n joinAggregation?: PipelineStage[]\n limit?: number\n Model: Model<any>\n page?: number\n pagination?: boolean\n projection?: Record<string, boolean>\n query: Record<string, unknown>\n session?: ClientSession\n sort?: object\n sortAggregation?: PipelineStage[]\n useEstimatedCount?: boolean\n}): Promise<PaginatedDocs<any>> => {\n const aggregation: PipelineStage[] = [{ $match: query }]\n\n if (sortAggregation && sortAggregation.length > 0) {\n for (const stage of sortAggregation) {\n aggregation.push(stage)\n }\n }\n\n if (sort) {\n const $sort: Record<string, -1 | 1> = {}\n\n Object.entries(sort).forEach(([key, value]) => {\n $sort[key] = value === 'desc' ? -1 : 1\n })\n\n aggregation.push({ $sort })\n }\n\n if (page) {\n aggregation.push({ $skip: (page - 1) * (limit ?? 0) })\n }\n\n if (limit) {\n aggregation.push({ $limit: limit })\n }\n\n if (joinAggregation) {\n for (const stage of joinAggregation) {\n aggregation.push(stage)\n }\n }\n\n if (projection) {\n aggregation.push({ $project: projection })\n }\n\n let countPromise: Promise<null | number> = Promise.resolve(null)\n\n if (pagination !== false && limit) {\n if (useEstimatedCount) {\n countPromise = Model.estimatedDocumentCount(query)\n } else {\n const hint
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/aggregatePaginate.ts"],"sourcesContent":["import type { CollationOptions } from 'mongodb'\nimport type { ClientSession, Model, PipelineStage } from 'mongoose'\nimport type { PaginatedDocs } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const aggregatePaginate = async ({\n adapter,\n branchVisibility,\n collation,\n joinAggregation,\n limit,\n Model,\n page,\n pagination,\n projection,\n query,\n session,\n sort,\n sortAggregation,\n useEstimatedCount,\n}: {\n adapter: MongooseAdapter\n branchVisibility?: PipelineStage[]\n collation?: CollationOptions\n joinAggregation?: PipelineStage[]\n limit?: number\n Model: Model<any>\n page?: number\n pagination?: boolean\n projection?: Record<string, boolean>\n query: Record<string, unknown>\n session?: ClientSession\n sort?: object\n sortAggregation?: PipelineStage[]\n useEstimatedCount?: boolean\n}): Promise<PaginatedDocs<any>> => {\n const aggregation: PipelineStage[] = [{ $match: query }, ...(branchVisibility ?? [])]\n\n if (sortAggregation && sortAggregation.length > 0) {\n for (const stage of sortAggregation) {\n aggregation.push(stage)\n }\n }\n\n if (sort) {\n const $sort: Record<string, -1 | 1> = {}\n\n Object.entries(sort).forEach(([key, value]) => {\n $sort[key] = value === 'desc' ? -1 : 1\n })\n\n aggregation.push({ $sort })\n }\n\n if (page) {\n aggregation.push({ $skip: (page - 1) * (limit ?? 0) })\n }\n\n if (limit) {\n aggregation.push({ $limit: limit })\n }\n\n if (joinAggregation) {\n for (const stage of joinAggregation) {\n aggregation.push(stage)\n }\n }\n\n if (projection) {\n aggregation.push({ $project: projection })\n }\n\n let countPromise: Promise<null | number> = Promise.resolve(null)\n\n if (pagination !== false && limit) {\n if (branchVisibility?.length) {\n countPromise = Model.aggregate(\n [{ $match: query }, ...branchVisibility, { $count: 'count' }],\n { collation, session },\n ).then((result) => result[0]?.count ?? 0)\n } else if (useEstimatedCount) {\n countPromise = Model.estimatedDocumentCount(query)\n } else {\n // Only hint the _id index for unfiltered counts. With a filter, MongoDB picks the matching index on its own,\n // while forcing _id would make it scan the whole collection.\n const hint =\n adapter.disableIndexHints !== true && Object.keys(query).length === 0\n ? { _id: 1 }\n : undefined\n countPromise = Model.countDocuments(query, {\n collation,\n session,\n ...(hint ? { hint } : {}),\n })\n }\n }\n\n const [docs, countResult] = await Promise.all([\n Model.aggregate(aggregation, { collation, session }),\n countPromise,\n ])\n\n const count = countResult === null ? docs.length : countResult\n\n const totalPages =\n pagination !== false && typeof limit === 'number' && limit !== 0\n ? Math.max(1, Math.ceil(count / limit))\n : 1\n\n const hasPrevPage = typeof page === 'number' && pagination !== false && page > 1\n const hasNextPage = typeof page === 'number' && pagination !== false && totalPages > page\n const pagingCounter =\n typeof page === 'number' && pagination !== false && typeof limit === 'number'\n ? (page - 1) * limit + 1\n : 1\n\n const result: PaginatedDocs = {\n docs,\n hasNextPage,\n hasPrevPage,\n limit: limit ?? 0,\n nextPage: hasNextPage ? page + 1 : null,\n page,\n pagingCounter,\n prevPage: hasPrevPage ? page - 1 : null,\n totalDocs: count,\n totalPages,\n }\n\n return result\n}\n"],"names":["aggregatePaginate","adapter","branchVisibility","collation","joinAggregation","limit","Model","page","pagination","projection","query","session","sort","sortAggregation","useEstimatedCount","aggregation","$match","length","stage","push","$sort","Object","entries","forEach","key","value","$skip","$limit","$project","countPromise","Promise","resolve","aggregate","$count","then","result","count","estimatedDocumentCount","hint","disableIndexHints","keys","_id","undefined","countDocuments","docs","countResult","all","totalPages","Math","max","ceil","hasPrevPage","hasNextPage","pagingCounter","nextPage","prevPage","totalDocs"],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AACT,EAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { PipelineStage } from 'mongoose';
|
|
2
|
-
import { type CollectionSlug, type JoinQuery, type SanitizedCollectionConfig } from 'payload';
|
|
2
|
+
import { type CollectionSlug, type JoinQuery, type PayloadRequest, type SanitizedCollectionConfig } from 'payload';
|
|
3
3
|
import type { MongooseAdapter } from '../index.js';
|
|
4
4
|
type BuildJoinAggregationArgs = {
|
|
5
5
|
adapter: MongooseAdapter;
|
|
6
|
+
branch?: false | string;
|
|
6
7
|
collection: CollectionSlug;
|
|
7
8
|
collectionConfig: SanitizedCollectionConfig;
|
|
8
9
|
draftsEnabled?: boolean;
|
|
@@ -10,9 +11,10 @@ type BuildJoinAggregationArgs = {
|
|
|
10
11
|
locale?: string;
|
|
11
12
|
projection?: Record<string, true>;
|
|
12
13
|
query?: Record<string, unknown>;
|
|
14
|
+
req?: Partial<PayloadRequest>;
|
|
13
15
|
/** whether the query is from drafts */
|
|
14
16
|
versions?: boolean;
|
|
15
17
|
};
|
|
16
|
-
export declare const buildJoinAggregation: ({ adapter, collection, collectionConfig, draftsEnabled, joins, locale, projection, versions, }: BuildJoinAggregationArgs) => Promise<PipelineStage[]
|
|
18
|
+
export declare const buildJoinAggregation: ({ adapter, branch, collection, collectionConfig, draftsEnabled, joins, locale, projection, req, versions, }: BuildJoinAggregationArgs) => Promise<PipelineStage[]>;
|
|
17
19
|
export {};
|
|
18
20
|
//# 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,UAAU,CAAA;AAE7C,OAAO,EAIL,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"buildJoinAggregation.d.ts","sourceRoot":"","sources":["../../src/utilities/buildJoinAggregation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE7C,OAAO,EAIL,KAAK,cAAc,EAKnB,KAAK,SAAS,EACd,KAAK,cAAc,EAKnB,KAAK,yBAAyB,EAE/B,MAAM,SAAS,CAAA;AAGhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAQlD,KAAK,wBAAwB,GAAG;IAC9B,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IACvB,UAAU,EAAE,cAAc,CAAA;IAC1B,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAEjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,uCAAuC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,oBAAoB,gHAW9B,wBAAwB,KAAG,OAAO,CAAC,aAAa,EAAE,CAuiBpD,CAAA"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { APIError, appendVersionToQueryKey, buildVersionCollectionFields, combineQueries, getQueryDraftsSort } from 'payload';
|
|
1
|
+
import { APIError, appendVersionToQueryKey, buildVersionCollectionFields, combineQueries, getBranchPredicateSync, getQueryDraftsSort, resolveBranchReadState, resolveBranchVersionQuery, rewriteBranchIDs, rewriteBranchVersionParents } from 'payload';
|
|
2
2
|
import { fieldShouldBeLocalized, hasDraftsEnabled } from 'payload/shared';
|
|
3
|
+
import { buildBranchVisibilityStages } from '../queries/buildBranchVisibility.js';
|
|
3
4
|
import { buildQuery } from '../queries/buildQuery.js';
|
|
4
5
|
import { buildSortParam } from '../queries/buildSortParam.js';
|
|
5
6
|
import { getCollection } from './getEntity.js';
|
|
6
|
-
export const buildJoinAggregation = async ({ adapter, collection, collectionConfig, draftsEnabled, joins, locale, projection, versions })=>{
|
|
7
|
+
export const buildJoinAggregation = async ({ adapter, branch, collection, collectionConfig, draftsEnabled, joins, locale, projection, req, versions })=>{
|
|
7
8
|
if (!adapter.useJoinAggregations) {
|
|
8
|
-
return;
|
|
9
|
+
return [];
|
|
9
10
|
}
|
|
10
11
|
if (Object.keys(collectionConfig.joins).length === 0 && collectionConfig.polymorphicJoins.length == 0 || joins === false) {
|
|
11
|
-
return;
|
|
12
|
+
return [];
|
|
12
13
|
}
|
|
13
14
|
const joinConfig = adapter.payload.collections[collection]?.config?.joins;
|
|
14
15
|
if (!joinConfig) {
|
|
@@ -49,8 +50,10 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
49
50
|
});
|
|
50
51
|
const $match = await buildQuery({
|
|
51
52
|
adapter,
|
|
53
|
+
branch,
|
|
52
54
|
fields: aggregatedFields,
|
|
53
55
|
locale,
|
|
56
|
+
req,
|
|
54
57
|
where: whereJoin
|
|
55
58
|
});
|
|
56
59
|
const sortProperty = Object.keys(sort)[0]// assert because buildSortParam always returns at least 1 key.
|
|
@@ -62,6 +65,29 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
62
65
|
for (const collectionSlug of join.field.collection){
|
|
63
66
|
const alias = `${as}.docs.${collectionSlug}`;
|
|
64
67
|
aliases.push(alias);
|
|
68
|
+
const joinBranchPredicate = getBranchPredicateSync({
|
|
69
|
+
branch,
|
|
70
|
+
collectionSlug,
|
|
71
|
+
req
|
|
72
|
+
});
|
|
73
|
+
const joinBranchReadState = resolveBranchReadState({
|
|
74
|
+
branch,
|
|
75
|
+
collectionSlug,
|
|
76
|
+
req
|
|
77
|
+
});
|
|
78
|
+
const branchMatch = joinBranchPredicate ? await buildQuery({
|
|
79
|
+
adapter,
|
|
80
|
+
branch,
|
|
81
|
+
fields: adapter.payload.collections[collectionSlug].config.flattenedFields,
|
|
82
|
+
locale,
|
|
83
|
+
req,
|
|
84
|
+
where: joinBranchPredicate
|
|
85
|
+
}) : undefined;
|
|
86
|
+
const branchVisibility = joinBranchReadState.useBranching ? buildBranchVisibilityStages({
|
|
87
|
+
adapter,
|
|
88
|
+
branch: joinBranchReadState.branch,
|
|
89
|
+
collectionSlug
|
|
90
|
+
}) : [];
|
|
65
91
|
const basePipeline = [
|
|
66
92
|
{
|
|
67
93
|
$addFields: {
|
|
@@ -81,10 +107,26 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
81
107
|
]
|
|
82
108
|
}
|
|
83
109
|
},
|
|
84
|
-
$match
|
|
110
|
+
$match,
|
|
111
|
+
...branchMatch ? [
|
|
112
|
+
branchMatch
|
|
113
|
+
] : []
|
|
85
114
|
]
|
|
86
115
|
}
|
|
87
|
-
}
|
|
116
|
+
},
|
|
117
|
+
...branchVisibility,
|
|
118
|
+
...joinBranchPredicate || branchVisibility.length ? [
|
|
119
|
+
{
|
|
120
|
+
$set: {
|
|
121
|
+
_id: {
|
|
122
|
+
$ifNull: [
|
|
123
|
+
'$_branchDocID',
|
|
124
|
+
'$_id'
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
] : []
|
|
88
130
|
];
|
|
89
131
|
const { Model: JoinModel } = getCollection({
|
|
90
132
|
adapter,
|
|
@@ -104,10 +146,12 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
104
146
|
[sortProperty]: sortDirection
|
|
105
147
|
}
|
|
106
148
|
},
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
149
|
+
...limitJoin > 0 ? [
|
|
150
|
+
{
|
|
151
|
+
// Unfortunately, we can't use $skip here because we can lose data, instead we do $slice then
|
|
152
|
+
$limit: page ? page * limitJoin : limitJoin
|
|
153
|
+
}
|
|
154
|
+
] : [],
|
|
111
155
|
{
|
|
112
156
|
$project: {
|
|
113
157
|
value: '$_id',
|
|
@@ -191,16 +235,18 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
191
235
|
}
|
|
192
236
|
}
|
|
193
237
|
});
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
238
|
+
if (limitJoin > 0) {
|
|
239
|
+
aggregate.push({
|
|
240
|
+
$set: {
|
|
241
|
+
[`${as}.docs`]: {
|
|
242
|
+
$slice: [
|
|
243
|
+
`$${as}.docs`,
|
|
244
|
+
...sliceValue
|
|
245
|
+
]
|
|
246
|
+
}
|
|
201
247
|
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
204
250
|
}
|
|
205
251
|
for (const slug of Object.keys(joinConfig)){
|
|
206
252
|
const joinsList = joinConfig[slug];
|
|
@@ -247,19 +293,75 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
247
293
|
});
|
|
248
294
|
const sortProperty = Object.keys(sort)[0];
|
|
249
295
|
const sortDirection = sort[sortProperty] === 'asc' ? 1 : -1;
|
|
296
|
+
// A join subquery must carry the same branch predicate as the top-level
|
|
297
|
+
// read, or a branch would see main's related documents.
|
|
298
|
+
const joinBranchPredicate = getBranchPredicateSync({
|
|
299
|
+
branch,
|
|
300
|
+
collectionSlug: collectionConfig.slug,
|
|
301
|
+
req
|
|
302
|
+
});
|
|
303
|
+
const joinBranchReadState = resolveBranchReadState({
|
|
304
|
+
branch,
|
|
305
|
+
collectionSlug: collectionConfig.slug,
|
|
306
|
+
req
|
|
307
|
+
});
|
|
308
|
+
const resolvedWhereJoin = useDrafts ? joinBranchReadState.useBranching ? rewriteBranchVersionParents(appendVersionToQueryKey(whereJoin)) ?? {} : await resolveBranchVersionQuery({
|
|
309
|
+
branch,
|
|
310
|
+
collectionSlug: collectionConfig.slug,
|
|
311
|
+
req,
|
|
312
|
+
where: appendVersionToQueryKey(whereJoin)
|
|
313
|
+
}) ?? {} : joinBranchReadState.useBranching ? rewriteBranchIDs(whereJoin) ?? {} : joinBranchPredicate ? {
|
|
314
|
+
and: [
|
|
315
|
+
whereJoin,
|
|
316
|
+
joinBranchPredicate
|
|
317
|
+
]
|
|
318
|
+
} : whereJoin;
|
|
250
319
|
const $match = await JoinModel.buildQuery({
|
|
320
|
+
branch,
|
|
251
321
|
locale,
|
|
252
322
|
payload: adapter.payload,
|
|
253
|
-
|
|
323
|
+
req,
|
|
324
|
+
where: useDrafts ? combineQueries(resolvedWhereJoin, {
|
|
254
325
|
latest: {
|
|
255
326
|
equals: true
|
|
256
327
|
}
|
|
257
|
-
}) :
|
|
328
|
+
}) : resolvedWhereJoin
|
|
258
329
|
});
|
|
330
|
+
const branchVisibility = joinBranchReadState.useBranching ? buildBranchVisibilityStages({
|
|
331
|
+
adapter,
|
|
332
|
+
branch: joinBranchReadState.branch,
|
|
333
|
+
collectionSlug: collectionConfig.slug,
|
|
334
|
+
mode: useDrafts ? 'drafts' : 'documents'
|
|
335
|
+
}) : [];
|
|
259
336
|
const pipeline = [
|
|
260
337
|
{
|
|
261
338
|
$match
|
|
262
339
|
},
|
|
340
|
+
...branchVisibility,
|
|
341
|
+
// Surface the canonical document ID rather than the shadow row's own
|
|
342
|
+
// primary key, so join results address documents the same way every
|
|
343
|
+
// other read does.
|
|
344
|
+
...joinBranchPredicate || branchVisibility.length ? [
|
|
345
|
+
useDrafts ? {
|
|
346
|
+
$set: {
|
|
347
|
+
parent: {
|
|
348
|
+
$ifNull: [
|
|
349
|
+
'$_branchParent',
|
|
350
|
+
'$parent'
|
|
351
|
+
]
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
} : {
|
|
355
|
+
$set: {
|
|
356
|
+
_id: {
|
|
357
|
+
$ifNull: [
|
|
358
|
+
'$_branchDocID',
|
|
359
|
+
'$_id'
|
|
360
|
+
]
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
] : [],
|
|
263
365
|
{
|
|
264
366
|
$sort: {
|
|
265
367
|
[sortProperty]: sortDirection
|
|
@@ -290,6 +392,7 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
290
392
|
{
|
|
291
393
|
$match
|
|
292
394
|
},
|
|
395
|
+
...branchVisibility,
|
|
293
396
|
{
|
|
294
397
|
$count: 'result'
|
|
295
398
|
}
|