@payloadcms/db-mongodb 4.0.0-internal.e55ccef → 4.0.0-internal.ea6e8f8
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/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.map +1 -1
- package/dist/createGlobalVersion.js +23 -1
- 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 +2 -0
- package/dist/exports/migration-utils.d.ts.map +1 -1
- package/dist/exports/migration-utils.js +2 -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 +94 -36
- 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/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/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/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/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/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +38 -7
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +55 -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 +107 -8
- package/dist/utilities/buildJoinAggregation.js.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 +15 -0
- package/dist/utilities/transform.js.map +1 -1
- package/package.json +6 -6
- 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
|
@@ -21,6 +21,7 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, opti
|
|
|
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 async function updateGlobalVersion({ id, global: globalSlug, locale, opti
|
|
|
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/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { JsonObject, UpdateGlobalVersionArgs } from 'payload'\n\nimport { buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport async function updateGlobalVersion<T extends JsonObject = JsonObject>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n const whereToUse = where || { id: { equals: id } }\n\n const fields = buildVersionGlobalFields(this.payload.config, globalConfig)\n const flattenedFields = buildVersionGlobalFields(this.payload.config, globalConfig, 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/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { JsonObject, UpdateGlobalVersionArgs } from 'payload'\n\nimport { buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport async function updateGlobalVersion<T extends JsonObject = JsonObject>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n const whereToUse = where || { id: { equals: id } }\n\n const fields = buildVersionGlobalFields(this.payload.config, globalConfig)\n const flattenedFields = buildVersionGlobalFields(this.payload.config, globalConfig, 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":["buildVersionGlobalFields","buildQuery","buildProjectionFromSelect","getGlobal","getSession","transform","updateGlobalVersion","id","global","globalSlug","locale","options","optionsArgs","req","returning","select","versionData","where","globalConfig","Model","adapter","versions","whereToUse","equals","fields","payload","config","flattenedFields","query","data","operation","baseOptions","session","timestamps","findOptions","lean","projection","returnDocument","updateOne","doc","findOneAndUpdate"],"mappings":"AAGA,SAASA,wBAAwB,QAAQ,UAAS;AAIlD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,QAAQC,UAAU,EAClBC,MAAM,EACNC,SAASC,cAAc,CAAC,C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updateJobs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAO,UAAU,EAAS,MAAM,SAAS,CAAA;AAWrD,eAAO,MAAM,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"updateJobs.d.ts","sourceRoot":"","sources":["../src/updateJobs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAO,UAAU,EAAS,MAAM,SAAS,CAAA;AAWrD,eAAO,MAAM,UAAU,EAAE,UAiLxB,CAAA"}
|
package/dist/updateJobs.js
CHANGED
|
@@ -24,7 +24,7 @@ export const updateJobs = async function updateMany({ id, data, limit, req, retu
|
|
|
24
24
|
sort: sortArg || collectionConfig.defaultSort,
|
|
25
25
|
timestamps: true
|
|
26
26
|
});
|
|
27
|
-
|
|
27
|
+
const query = await buildQuery({
|
|
28
28
|
adapter: this,
|
|
29
29
|
collectionSlug: collectionConfig.slug,
|
|
30
30
|
fields: collectionConfig.flattenedFields,
|
|
@@ -70,7 +70,7 @@ export const updateJobs = async function updateMany({ id, data, limit, req, retu
|
|
|
70
70
|
const findOptions = {
|
|
71
71
|
...baseOptions,
|
|
72
72
|
lean: true,
|
|
73
|
-
|
|
73
|
+
returnDocument: 'after'
|
|
74
74
|
};
|
|
75
75
|
let result = [];
|
|
76
76
|
try {
|
|
@@ -90,25 +90,82 @@ export const updateJobs = async function updateMany({ id, data, limit, req, retu
|
|
|
90
90
|
doc
|
|
91
91
|
] : [];
|
|
92
92
|
}
|
|
93
|
-
} else {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
} else if (limit === 1) {
|
|
94
|
+
/**
|
|
95
|
+
* Select, update, and return one job atomically in a single database call.
|
|
96
|
+
* We can only do this with limit === 1, which can be expressed as findOne.
|
|
97
|
+
*/ const doc = await Model.findOneAndUpdate(query, updateData, {
|
|
98
|
+
...findOptions,
|
|
99
|
+
projection: returning === false ? {
|
|
100
|
+
_id: 1
|
|
101
|
+
} : undefined,
|
|
102
|
+
sort
|
|
103
|
+
});
|
|
104
|
+
if (returning === false) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
result = doc ? [
|
|
108
|
+
doc
|
|
109
|
+
] : [];
|
|
110
|
+
} else if (typeof limit === 'number' && limit > 1) {
|
|
111
|
+
const candidates = await Model.find(query, {}, {
|
|
112
|
+
...findOptions,
|
|
113
|
+
limit,
|
|
114
|
+
projection: {
|
|
115
|
+
_id: 1
|
|
116
|
+
},
|
|
117
|
+
sort
|
|
118
|
+
});
|
|
119
|
+
if (candidates.length === 0) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
const candidateIDs = candidates.map((candidate)=>candidate._id);
|
|
123
|
+
if (typeof data.processingToken === 'string') {
|
|
124
|
+
/**
|
|
125
|
+
* `processingToken` identifies this claim update. `processing: true` cannot, because every
|
|
126
|
+
* worker writes the same value. The token lets us reliably find the jobs this update won.
|
|
127
|
+
*/ const claimQuery = {
|
|
128
|
+
$and: [
|
|
129
|
+
query,
|
|
130
|
+
{
|
|
131
|
+
_id: {
|
|
132
|
+
$in: candidateIDs
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
};
|
|
137
|
+
await Model.updateMany(claimQuery, updateData, baseOptions);
|
|
138
|
+
if (returning === false) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
const claimedJobsQuery = {
|
|
142
|
+
_id: {
|
|
143
|
+
$in: candidateIDs
|
|
100
144
|
},
|
|
145
|
+
processingToken: {
|
|
146
|
+
$eq: data.processingToken
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
result = await Model.find(claimedJobsQuery, {}, {
|
|
150
|
+
...findOptions,
|
|
101
151
|
sort
|
|
102
152
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
query = {
|
|
153
|
+
} else {
|
|
154
|
+
const limitedUpdateQuery = {
|
|
107
155
|
_id: {
|
|
108
|
-
$in:
|
|
156
|
+
$in: candidateIDs
|
|
109
157
|
}
|
|
110
158
|
};
|
|
159
|
+
await Model.updateMany(limitedUpdateQuery, updateData, baseOptions);
|
|
160
|
+
if (returning === false) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
result = await Model.find(limitedUpdateQuery, {}, {
|
|
164
|
+
...findOptions,
|
|
165
|
+
sort
|
|
166
|
+
});
|
|
111
167
|
}
|
|
168
|
+
} else {
|
|
112
169
|
await Model.updateMany(query, updateData, baseOptions);
|
|
113
170
|
if (returning === false) {
|
|
114
171
|
return null;
|
package/dist/updateJobs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\nimport type { Job, UpdateJobs, Where } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.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 updateJobs: UpdateJobs = async function updateMany(\n this: MongooseAdapter,\n { id, data, limit, req, returning, sort: sortArg, where: whereArg },\n) {\n if (\n !(data?.log as object[])?.length &&\n !(data.log && typeof data.log === 'object' && '$push' in data.log)\n ) {\n delete data.log\n }\n\n const where = id ? { id: { equals: id } } : (whereArg as Where)\n\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug: 'payload-jobs',\n })\n\n const sort: Record<string, unknown> | undefined = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n\n
|
|
1
|
+
{"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\nimport type { Job, UpdateJobs, Where } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.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 updateJobs: UpdateJobs = async function updateMany(\n this: MongooseAdapter,\n { id, data, limit, req, returning, sort: sortArg, where: whereArg },\n) {\n if (\n !(data?.log as object[])?.length &&\n !(data.log && typeof data.log === 'object' && '$push' in data.log)\n ) {\n delete data.log\n }\n\n const where = id ? { id: { equals: id } } : (whereArg as Where)\n\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug: 'payload-jobs',\n })\n\n const sort: Record<string, unknown> | undefined = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collectionConfig.slug,\n fields: collectionConfig.flattenedFields,\n where,\n })\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: collectionConfig.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 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 returnDocument: 'after',\n }\n\n let result: Job[] = []\n\n try {\n if (id) {\n if (returning === false) {\n await Model.updateOne(query, updateData, baseOptions)\n transform({ adapter: this, data, fields: collectionConfig.fields, operation: 'read' })\n\n return null\n } else {\n const doc = await Model.findOneAndUpdate(query, updateData, findOptions)\n result = doc ? [doc] : []\n }\n } else if (limit === 1) {\n /**\n * Select, update, and return one job atomically in a single database call.\n * We can only do this with limit === 1, which can be expressed as findOne.\n */\n const doc = await Model.findOneAndUpdate(query, updateData, {\n ...findOptions,\n projection: returning === false ? { _id: 1 } : undefined,\n sort,\n })\n\n if (returning === false) {\n return null\n }\n\n result = doc ? [doc] : []\n } else if (typeof limit === 'number' && limit > 1) {\n const candidates = await Model.find(\n query,\n {},\n { ...findOptions, limit, projection: { _id: 1 }, sort },\n )\n\n if (candidates.length === 0) {\n return null\n }\n\n const candidateIDs = candidates.map((candidate) => candidate._id)\n\n if (typeof data.processingToken === 'string') {\n /**\n * `processingToken` identifies this claim update. `processing: true` cannot, because every\n * worker writes the same value. The token lets us reliably find the jobs this update won.\n */\n const claimQuery = {\n $and: [query, { _id: { $in: candidateIDs } }],\n }\n\n await Model.updateMany(claimQuery, updateData, baseOptions)\n\n if (returning === false) {\n return null\n }\n\n const claimedJobsQuery = {\n _id: { $in: candidateIDs },\n processingToken: { $eq: data.processingToken },\n }\n\n result = await Model.find(claimedJobsQuery, {}, { ...findOptions, sort })\n } else {\n const limitedUpdateQuery = { _id: { $in: candidateIDs } }\n\n await Model.updateMany(limitedUpdateQuery, updateData, baseOptions)\n\n if (returning === false) {\n return null\n }\n\n result = await Model.find(limitedUpdateQuery, {}, { ...findOptions, sort })\n }\n } else {\n await Model.updateMany(query, updateData, baseOptions)\n\n if (returning === false) {\n return null\n }\n\n result = await Model.find(query, {}, { ...findOptions, sort })\n }\n } catch (error) {\n handleError({ collection: collectionConfig.slug, error, req })\n }\n\n transform({\n adapter: this,\n data: result,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["buildQuery","buildSortParam","getCollection","getSession","handleError","transform","updateJobs","updateMany","id","data","limit","req","returning","sort","sortArg","where","whereArg","log","length","equals","collectionConfig","Model","adapter","collectionSlug","config","payload","fields","flattenedFields","defaultSort","timestamps","query","slug","updateData","$inc","$push","$addToSet","$pull","operation","updateOps","Object","keys","$set","baseOptions","session","findOptions","lean","returnDocument","result","updateOne","doc","findOneAndUpdate","projection","_id","undefined","candidates","find","candidateIDs","map","candidate","processingToken","claimQuery","$and","$in","claimedJobsQuery","$eq","limitedUpdateQuery","error","collection"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,aAAyB,eAAeC,WAEnD,EAAEC,EAAE,EAAEC,IAAI,EAAEC,KAAK,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAMC,OAAO,EAAEC,OAAOC,QAAQ,EAAE;IAEnE,IACE,CAAEP,MAAMQ,KAAkBC,UAC1B,CAAET,CAAAA,KAAKQ,GAAG,IAAI,OAAOR,KAAKQ,GAAG,KAAK,YAAY,WAAWR,KAAKQ,GAAG,AAAD,GAChE;QACA,OAAOR,KAAKQ,GAAG;IACjB;IAEA,MAAMF,QAAQP,KAAK;QAAEA,IAAI;YAAEW,QAAQX;QAAG;IAAE,IAAKQ;IAE7C,MAAM,EAAEI,gBAAgB,EAAEC,KAAK,EAAE,GAAGnB,cAAc;QAChDoB,SAAS,IAAI;QACbC,gBAAgB;IAClB;IAEA,MAAMV,OAA4CZ,eAAe;QAC/DqB,SAAS,IAAI;QACbE,QAAQ,IAAI,CAACC,OAAO,CAACD,MAAM;QAC3BE,QAAQN,iBAAiBO,eAAe;QACxCd,MAAMC,WAAWM,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C;gBAEAZ,SAAS,MAAM1B,MAAMkC,IAAI,CAACQ,kBAAkB,CAAC,GAAG;oBAAE,GAAGnB,WAAW;oBAAE/B;gBAAK;YACzE,OAAO;gBACL,MAAMoD,qBAAqB;oBAAEb,KAAK;wBAAEU,KAAKN;oBAAa;gBAAE;gBAExD,MAAMnC,MAAMd,UAAU,CAAC0D,oBAAoBjC,YAAYU;gBAEvD,IAAI9B,cAAc,OAAO;oBACvB,OAAO;gBACT;gBAEAmC,SAAS,MAAM1B,MAAMkC,IAAI,CAACU,oBAAoB,CAAC,GAAG;oBAAE,GAAGrB,WAAW;oBAAE/B;gBAAK;YAC3E;QACF,OAAO;YACL,MAAMQ,MAAMd,UAAU,CAACuB,OAAOE,YAAYU;YAE1C,IAAI9B,cAAc,OAAO;gBACvB,OAAO;YACT;YAEAmC,SAAS,MAAM1B,MAAMkC,IAAI,CAACzB,OAAO,CAAC,GAAG;gBAAE,GAAGc,WAAW;gBAAE/B;YAAK;QAC9D;IACF,EAAE,OAAOqD,OAAO;QACd9D,YAAY;YAAE+D,YAAY/C,iBAAiBW,IAAI;YAAEmC;YAAOvD;QAAI;IAC9D;IAEAN,UAAU;QACRiB,SAAS,IAAI;QACbb,MAAMsC;QACNrB,QAAQN,iBAAiBM,MAAM;QAC/BW,WAAW;IACb;IAEA,OAAOU;AACT,EAAC"}
|
package/dist/updateMany.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../src/updateMany.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAYlE,eAAO,MAAM,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../src/updateMany.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAYlE,eAAO,MAAM,UAAU,EAAE,UA0IxB,CAAA"}
|
package/dist/updateMany.js
CHANGED
|
@@ -32,6 +32,7 @@ export const updateMany = async function updateMany({ collection: collectionSlug
|
|
|
32
32
|
collectionSlug,
|
|
33
33
|
fields: collectionConfig.flattenedFields,
|
|
34
34
|
locale,
|
|
35
|
+
req,
|
|
35
36
|
where
|
|
36
37
|
});
|
|
37
38
|
const $inc = {};
|
|
@@ -74,12 +75,12 @@ export const updateMany = async function updateMany({ collection: collectionSlug
|
|
|
74
75
|
const findOptions = {
|
|
75
76
|
...baseOptions,
|
|
76
77
|
lean: true,
|
|
77
|
-
new: true,
|
|
78
78
|
projection: buildProjectionFromSelect({
|
|
79
79
|
adapter: this,
|
|
80
80
|
fields: collectionConfig.flattenedFields,
|
|
81
81
|
select
|
|
82
|
-
})
|
|
82
|
+
}),
|
|
83
|
+
returnDocument: 'after'
|
|
83
84
|
};
|
|
84
85
|
try {
|
|
85
86
|
if (typeof limit === 'number' && limit > 0) {
|
package/dist/updateMany.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\n\nimport { flattenWhereToOperators, type UpdateMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.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 updateMany: UpdateMany = async function updateMany(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n data,\n limit,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n sort: sortArg,\n where,\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 { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n let sort: Record<string, unknown> | undefined\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n let query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\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: collectionConfig.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 = data\n data = 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/updateMany.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\n\nimport { flattenWhereToOperators, type UpdateMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.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 updateMany: UpdateMany = async function updateMany(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n data,\n limit,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n sort: sortArg,\n where,\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 { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n let sort: Record<string, unknown> | undefined\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n let query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n req,\n where,\n })\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: collectionConfig.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 = data\n data = 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,\n }),\n returnDocument: 'after',\n }\n\n try {\n if (typeof limit === 'number' && limit > 0) {\n const documentsToUpdate = await Model.find(\n query,\n {},\n { ...findOptions, limit, projection: { _id: 1 }, sort },\n )\n if (documentsToUpdate.length === 0) {\n return null\n }\n\n query = { _id: { $in: documentsToUpdate.map((doc) => doc._id) } }\n }\n\n await Model.updateMany(query, data, baseOptions)\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n\n if (returning === false) {\n return null\n }\n\n const result = await Model.find(\n query,\n {},\n {\n ...findOptions,\n sort,\n },\n )\n\n transform({\n adapter: this,\n data: result,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["flattenWhereToOperators","buildQuery","buildSortParam","buildProjectionFromSelect","getCollection","getSession","handleError","transform","updateMany","collection","collectionSlug","data","limit","locale","options","optionsArgs","req","returning","select","sort","sortArg","where","hasNearConstraint","constraints","some","prop","Object","keys","key","collectionConfig","Model","adapter","config","payload","fields","flattenedFields","defaultSort","timestamps","query","$inc","$push","$addToSet","$pull","operation","updateOps","length","$set","baseOptions","session","findOptions","lean","projection","returnDocument","documentsToUpdate","find","_id","$in","map","doc","error","result"],"mappings":"AAEA,SAASA,uBAAuB,QAAyB,UAAS;AAIlE,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EACEC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,IAAIC,oBAAoB;IAExB,IAAID,OAAO;QACT,MAAME,cAAcvB,wBAAwBqB;QAC5CC,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAA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C,SAAS,MAAM3C,WAAW,IAAI,EAAEW;QAChC,uDAAuD;QACvDqB,YAAY;IACd;IAEA,MAAMY,cAA4B;QAChC,GAAGF,WAAW;QACdG,MAAM;QACNC,YAAYhD,0BAA0B;YACpC4B,SAAS,IAAI;YACbG,QAAQL,iBAAiBM,eAAe;YACxCjB;QACF;QACAkC,gBAAgB;IAClB;IAEA,IAAI;QACF,IAAI,OAAOxC,UAAU,YAAYA,QAAQ,GAAG;YAC1C,MAAMyC,oBAAoB,MAAMvB,MAAMwB,IAAI,CACxChB,OACA,CAAC,GACD;gBAAE,GAAGW,WAAW;gBAAErC;gBAAOuC,YAAY;oBAAEI,KAAK;gBAAE;gBAAGpC;YAAK;YAExD,IAAIkC,kBAAkBR,MAAM,KAAK,GAAG;gBAClC,OAAO;YACT;YAEAP,QAAQ;gBAAEiB,KAAK;oBAAEC,KAAKH,kBAAkBI,GAAG,CAAC,CAACC,MAAQA,IAAIH,GAAG;gBAAE;YAAE;QAClE;QAEA,MAAMzB,MAAMtB,UAAU,CAAC8B,OAAO3B,MAAMoC;IACtC,EAAE,OAAOY,OAAO;QACdrD,YAAY;YAAEG,YAAYC;YAAgBiD;YAAO3C;QAAI;IACvD;IAEA,IAAIC,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,MAAM2C,SAAS,MAAM9B,MAAMwB,IAAI,CAC7BhB,OACA,CAAC,GACD;QACE,GAAGW,WAAW;QACd9B;IACF;IAGFZ,UAAU;QACRwB,SAAS,IAAI;QACbpB,MAAMiD;QACN1B,QAAQL,iBAAiBK,MAAM;QAC/BS,WAAW;IACb;IAEA,OAAOiB;AACT,EAAC"}
|
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,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EACEC,EAAE,EACFC,MAAM,EACNC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,OAAOC,WAAW,CAAC,CAAC,EACrB;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGnB,cAAc;QAAEoB,SAAS,IAAI;QAAEZ;IAAe;IAElF,IAAIH,OAAOgB,aAAahB,OAAO,MAAM;QACnCA,KAAK,MAAMT,mBAAmB;YAAES;YAAIC;YAAQE;YAAgBK;QAAI;IAClE;IAEA,MAAMG,QAAQX,KAAK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B;IAClB;IAEA,IAAI;QACF,IAAI9B,cAAc,OAAO;YACvB,MAAMK,MAAMf,SAAS,CAACoB,OAAOG,YAAYW;YACzCnC,UAAU;gBAAEiB,SAAS,IAAI;gBAAEX;gBAAMc;gBAAQS,WAAW;YAAO;YAC3D,OAAO;QACT,OAAO;YACLN,SAAS,MAAMP,MAAM0B,gBAAgB,CAACrB,OAAOG,YAAYc;QAC3D;IACF,EAAE,OAAOK,OAAO;QACd5C,YAAY;YAAEK,YAAYC;YAAgBsC;YAAOjC;QAAI;IACvD;IAEA,IAAI,CAACa,QAAQ;QACX,OAAO;IACT;IAEAvB,UAAU;QAAEiB,SAAS,IAAI;QAAEX,MAAMiB;QAAQH;QAAQS,WAAW;IAAO;IAEnE,4EAA4E;IAC5E,0EAA0E;IAC1ErC,wBAAwB;QACtBW;QACAE;QACAuC,MAAM;YAACrB;SAAkC;QACzCb;IACF;IAEA,OAAOa;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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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,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":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"aggregatePaginate.d.ts","sourceRoot":"","sources":["../../src/utilities/aggregatePaginate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,eAAO,MAAM,iBAAiB,qKAe3B;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,gBAAgB,CAAC,EAAE,aAAa,EAAE,CAAA;IAClC,SAAS,CAAC,EAAE,gBAAgB,CAAA;IAC5B,eAAe,CAAC,EAAE,aAAa,EAAE,CAAA;IACjC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,eAAe,CAAC,EAAE,aAAa,EAAE,CAAA;IACjC,iBAAiB,CAAC,EAAE,OAAO,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"],"mappings":"AAMA,OAAO,MAAMA,oBAAoB,OAAO,EACtCC,OAAO,EACPC,gBAAgB,EAChBC,SAAS,EACTC,eAAe,EACfC,KAAK,EACLC,KAAK,EACLC,IAAI,EACJC,UAAU,EACVC,UAAU,EACVC,KAAK,EACLC,OAAO,EACPC,IAAI,EACJC,eAAe,EACfC,iBAAiB,EAgBlB;IACC,MAAMC,cAA+B;QAAC;YAAEC,QAAQN;QAAM;WAAOR,oBAAoB,EAAE;KAAE;IAErF,IAAIW,mBAAmBA,gBAAgBI,MAAM,GAAG,GAAG;QACjD,KAAK,MAAMC,SAASL,gBAAiB;YACnCE,YAAYI,IAAI,CAACD;QACnB;IACF;IAEA,IAAIN,MAAM;QACR,MAAMQ,QAAgC,CAAC;QAEvCC,OAAOC,OAAO,CAACV,MAAMW,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;YACxCL,KAAK,CAACI,IAAI,GAAGC,UAAU,SAAS,CAAC,IAAI;QACvC;QAEAV,YAAY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