@payloadcms/db-mongodb 4.0.0-internal.9496957 → 4.0.0-internal.952ed66
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 +10 -2
- 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/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +24 -1
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +16 -3
- 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 +26 -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 +48 -9
- 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.map +1 -1
- package/dist/migrateFresh.js +1 -0
- 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 +100 -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 +17 -0
- package/dist/predefinedMigrations/migrateBranching.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateBranching.js +90 -0
- package/dist/predefinedMigrations/migrateBranching.js.map +1 -0
- 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/buildRelatedQueryPipeline.d.ts +7 -0
- package/dist/queries/buildRelatedQueryPipeline.d.ts.map +1 -0
- package/dist/queries/buildRelatedQueryPipeline.js +56 -0
- package/dist/queries/buildRelatedQueryPipeline.js.map +1 -0
- package/dist/queries/buildSearchParams.d.ts +4 -2
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +223 -41
- 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 +39 -7
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +69 -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 +91 -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.js +1 -1
- 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 +158 -24
- 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 +115 -26
- package/dist/utilities/resolveJoins.js.map +1 -1
- package/package.json +16 -19
- 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 -546
- package/dist/utilities/transform.spec.js.map +0 -1
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { Types } from 'mongoose';
|
|
2
|
-
import { APIError, escapeRegExp, getFieldByPath, getLocalizedPaths } from 'payload';
|
|
2
|
+
import { APIError, escapeRegExp, getFieldByPath, getLocalizedPaths, resolveBranchQuery, resolveBranchReadState, rewriteBranchIDs } from 'payload';
|
|
3
3
|
import { hasManyRelationshipOperatorSet, isNestedRelationshipQuery, validOperatorSet } from 'payload/shared';
|
|
4
4
|
import { getCollection } from '../utilities/getEntity.js';
|
|
5
5
|
import { isObjectID } from '../utilities/isObjectID.js';
|
|
6
|
+
import { buildBranchVisibilityStages } from './buildBranchVisibility.js';
|
|
7
|
+
import { buildRelatedQueryPipeline } from './buildRelatedQueryPipeline.js';
|
|
6
8
|
import { operatorMap } from './operatorMap.js';
|
|
7
9
|
import { sanitizeQueryValue } from './sanitizeQueryValue.js';
|
|
8
|
-
const subQueryOptions = {
|
|
9
|
-
lean: true
|
|
10
|
-
};
|
|
11
10
|
/**
|
|
12
11
|
* Convert the Payload key / value / operator into a MongoDB query
|
|
13
|
-
*/ export async function buildSearchParam({ collectionSlug, fields, globalSlug, incomingPath, locale, operator, parentIsLocalized, payload, val }) {
|
|
12
|
+
*/ export async function buildSearchParam({ branch, collectionSlug, fields, globalSlug, incomingPath, locale, operator, parentIsLocalized, payload, req, val }) {
|
|
14
13
|
// Replace GraphQL nested field double underscore formatting
|
|
15
14
|
let sanitizedPath = incomingPath.replace(/__/g, '.');
|
|
16
15
|
if (sanitizedPath === 'id') {
|
|
@@ -52,14 +51,29 @@ const subQueryOptions = {
|
|
|
52
51
|
const [{ field, path }] = paths;
|
|
53
52
|
if (hasManyRelationshipOperatorSet.has(operator) && paths.length === 1 && (field.type === 'relationship' || field.type === 'upload') && field.hasMany && typeof field.relationTo === 'string' && isNestedRelationshipQuery(val)) {
|
|
54
53
|
return buildHasManyRelationshipSearchParam({
|
|
54
|
+
branch,
|
|
55
55
|
field,
|
|
56
56
|
locale,
|
|
57
57
|
nestedWhere: val,
|
|
58
58
|
operator: operator,
|
|
59
59
|
path,
|
|
60
|
-
payload
|
|
60
|
+
payload,
|
|
61
|
+
req
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (operator === 'contains' && paths.length === 1 && field.type === 'join' && typeof field.collection === 'string' && isNestedRelationshipQuery(val)) {
|
|
65
|
+
return buildJoinContainsSearchParam({
|
|
66
|
+
branch,
|
|
67
|
+
field,
|
|
68
|
+
locale,
|
|
69
|
+
nestedWhere: val,
|
|
70
|
+
payload,
|
|
71
|
+
req
|
|
61
72
|
});
|
|
62
73
|
}
|
|
74
|
+
if ((operator === 'contains' || operator === 'like' || operator === 'not_like') && (isNestedRelationshipQuery(val) || Array.isArray(val) && val.some((entry)=>isNestedRelationshipQuery(entry)))) {
|
|
75
|
+
throw new APIError(`Invalid value for "${operator}" on path "${path}": expected a string.`, 400);
|
|
76
|
+
}
|
|
63
77
|
if (path) {
|
|
64
78
|
const sanitizedQueryValue = sanitizeQueryValue({
|
|
65
79
|
field,
|
|
@@ -93,6 +107,7 @@ const subQueryOptions = {
|
|
|
93
107
|
let relationshipQuery = {
|
|
94
108
|
value: {}
|
|
95
109
|
};
|
|
110
|
+
let relationshipWhere;
|
|
96
111
|
for (const [i, { collectionSlug, path: subPath }] of pathsToQuery.entries()){
|
|
97
112
|
// The arrays are reversed together, so both entries describe the same relationship hop.
|
|
98
113
|
const parentField = parentPaths[i]?.field;
|
|
@@ -107,17 +122,27 @@ const subQueryOptions = {
|
|
|
107
122
|
collectionSlug
|
|
108
123
|
});
|
|
109
124
|
if (i === 0) {
|
|
110
|
-
const
|
|
111
|
-
|
|
125
|
+
const { branchVisibility, where: relatedWhere } = await resolveRelatedBranchQuery({
|
|
126
|
+
branch,
|
|
127
|
+
collectionSlug,
|
|
112
128
|
payload,
|
|
129
|
+
req,
|
|
113
130
|
where: {
|
|
114
131
|
[subPath]: {
|
|
115
132
|
[formattedOperator]: val
|
|
116
133
|
}
|
|
117
134
|
}
|
|
118
135
|
});
|
|
136
|
+
const subQuery = await SubModel.buildQuery({
|
|
137
|
+
branch,
|
|
138
|
+
locale,
|
|
139
|
+
payload,
|
|
140
|
+
req,
|
|
141
|
+
where: relatedWhere ?? {}
|
|
142
|
+
});
|
|
119
143
|
const select = {
|
|
120
|
-
_id: true
|
|
144
|
+
_id: true,
|
|
145
|
+
_branchDocID: true
|
|
121
146
|
};
|
|
122
147
|
let joinPath = null;
|
|
123
148
|
if (parentField.type === 'join') {
|
|
@@ -138,7 +163,12 @@ const subQueryOptions = {
|
|
|
138
163
|
if (joinPath) {
|
|
139
164
|
select[joinPath] = true;
|
|
140
165
|
}
|
|
141
|
-
const result = await
|
|
166
|
+
const result = await findRelatedDocuments({
|
|
167
|
+
branchVisibility,
|
|
168
|
+
Model: SubModel,
|
|
169
|
+
projection: select,
|
|
170
|
+
query: subQuery
|
|
171
|
+
});
|
|
142
172
|
const $in = [];
|
|
143
173
|
result.forEach((doc)=>{
|
|
144
174
|
if (joinPath) {
|
|
@@ -163,9 +193,10 @@ const subQueryOptions = {
|
|
|
163
193
|
$in.push(ref);
|
|
164
194
|
}
|
|
165
195
|
} else {
|
|
166
|
-
const
|
|
196
|
+
const documentID = doc._branchDocID ?? doc._id;
|
|
197
|
+
const stringID = documentID.toString();
|
|
167
198
|
if (Types.ObjectId.isValid(stringID)) {
|
|
168
|
-
$in.push(
|
|
199
|
+
$in.push(documentID);
|
|
169
200
|
} else {
|
|
170
201
|
$in.push(stringID);
|
|
171
202
|
}
|
|
@@ -181,21 +212,35 @@ const subQueryOptions = {
|
|
|
181
212
|
}
|
|
182
213
|
const nextSubPath = pathsToQuery[i + 1]?.path;
|
|
183
214
|
if (nextSubPath) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
$in
|
|
192
|
-
}
|
|
215
|
+
relationshipWhere = joinPath ? {
|
|
216
|
+
id: {
|
|
217
|
+
in: $in
|
|
218
|
+
}
|
|
219
|
+
} : {
|
|
220
|
+
[nextSubPath]: {
|
|
221
|
+
in: $in
|
|
193
222
|
}
|
|
194
223
|
};
|
|
195
224
|
}
|
|
196
225
|
continue;
|
|
197
226
|
}
|
|
198
|
-
|
|
227
|
+
if (!relationshipWhere) {
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
const { branchVisibility, where: relatedWhere } = await resolveRelatedBranchQuery({
|
|
231
|
+
branch,
|
|
232
|
+
collectionSlug,
|
|
233
|
+
payload,
|
|
234
|
+
req,
|
|
235
|
+
where: relationshipWhere
|
|
236
|
+
});
|
|
237
|
+
const subQuery = await SubModel.buildQuery({
|
|
238
|
+
branch,
|
|
239
|
+
locale,
|
|
240
|
+
payload,
|
|
241
|
+
req,
|
|
242
|
+
where: relatedWhere ?? {}
|
|
243
|
+
});
|
|
199
244
|
/**
|
|
200
245
|
* Follow this join back to its parent IDs.
|
|
201
246
|
* For example, matching songs yield album IDs, then artist IDs.
|
|
@@ -211,7 +256,12 @@ const subQueryOptions = {
|
|
|
211
256
|
if (relationshipField.pathHasLocalized && payload.config.localization) {
|
|
212
257
|
joinPath = joinPath.replace('<locale>', locale || payload.config.localization.defaultLocale);
|
|
213
258
|
}
|
|
214
|
-
const $in = await
|
|
259
|
+
const $in = await findRelatedDistinctValues({
|
|
260
|
+
branchVisibility,
|
|
261
|
+
Model: SubModel,
|
|
262
|
+
path: joinPath,
|
|
263
|
+
query: subQuery
|
|
264
|
+
});
|
|
215
265
|
if (i + 1 === pathsToQuery.length) {
|
|
216
266
|
return {
|
|
217
267
|
path: '_id',
|
|
@@ -220,17 +270,23 @@ const subQueryOptions = {
|
|
|
220
270
|
}
|
|
221
271
|
};
|
|
222
272
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
$in
|
|
227
|
-
}
|
|
273
|
+
relationshipWhere = {
|
|
274
|
+
id: {
|
|
275
|
+
in: $in
|
|
228
276
|
}
|
|
229
277
|
};
|
|
230
278
|
continue;
|
|
231
279
|
}
|
|
232
|
-
const result = await
|
|
233
|
-
|
|
280
|
+
const result = await findRelatedDocuments({
|
|
281
|
+
branchVisibility,
|
|
282
|
+
Model: SubModel,
|
|
283
|
+
projection: {
|
|
284
|
+
_id: true,
|
|
285
|
+
_branchDocID: true
|
|
286
|
+
},
|
|
287
|
+
query: subQuery
|
|
288
|
+
});
|
|
289
|
+
const $in = result.map((doc)=>doc._branchDocID ?? doc._id);
|
|
234
290
|
// If it is the last recursion
|
|
235
291
|
// then pass through the search param
|
|
236
292
|
if (i + 1 === pathsToQuery.length) {
|
|
@@ -243,11 +299,9 @@ const subQueryOptions = {
|
|
|
243
299
|
} else {
|
|
244
300
|
const nextSubPath = pathsToQuery[i + 1]?.path;
|
|
245
301
|
if (nextSubPath) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
$in
|
|
250
|
-
}
|
|
302
|
+
relationshipWhere = {
|
|
303
|
+
[nextSubPath]: {
|
|
304
|
+
in: $in
|
|
251
305
|
}
|
|
252
306
|
};
|
|
253
307
|
}
|
|
@@ -367,7 +421,7 @@ const subQueryOptions = {
|
|
|
367
421
|
* // Simplified MongoDB result, after finding the matching ingredient IDs
|
|
368
422
|
* { ingredients: { $nin: [unhealthyIngredientID] } }
|
|
369
423
|
* ```
|
|
370
|
-
*/ async function buildHasManyRelationshipSearchParam({ field, locale, nestedWhere, operator, path, payload }) {
|
|
424
|
+
*/ async function buildHasManyRelationshipSearchParam({ branch, field, locale, nestedWhere, operator, path, payload, req }) {
|
|
371
425
|
if (field.type !== 'relationship' && field.type !== 'upload' || !field.hasMany || typeof field.relationTo !== 'string' || !isNestedRelationshipQuery(nestedWhere)) {
|
|
372
426
|
return undefined;
|
|
373
427
|
}
|
|
@@ -376,14 +430,29 @@ const subQueryOptions = {
|
|
|
376
430
|
collectionSlug: field.relationTo
|
|
377
431
|
});
|
|
378
432
|
const pathLocale = payload.config.localization ? payload.config.localization.localeCodes.find((localeCode)=>path.split('.').at(-1) === localeCode) : undefined;
|
|
433
|
+
const { branchVisibility, where: relatedWhere } = await resolveRelatedBranchQuery({
|
|
434
|
+
branch,
|
|
435
|
+
collectionSlug: field.relationTo,
|
|
436
|
+
payload,
|
|
437
|
+
req,
|
|
438
|
+
where: nestedWhere
|
|
439
|
+
});
|
|
379
440
|
const matchingRelatedDocumentsQuery = await RelatedModel.buildQuery({
|
|
441
|
+
branch,
|
|
380
442
|
locale: pathLocale ?? locale,
|
|
381
443
|
payload,
|
|
382
|
-
|
|
444
|
+
req,
|
|
445
|
+
where: relatedWhere ?? {}
|
|
383
446
|
});
|
|
384
|
-
const findRelatedDocumentIDs = async (query)=>(await
|
|
385
|
-
|
|
386
|
-
|
|
447
|
+
const findRelatedDocumentIDs = async (query)=>(await findRelatedDocuments({
|
|
448
|
+
branchVisibility,
|
|
449
|
+
Model: RelatedModel,
|
|
450
|
+
projection: {
|
|
451
|
+
_id: true,
|
|
452
|
+
_branchDocID: true
|
|
453
|
+
},
|
|
454
|
+
query
|
|
455
|
+
})).map((document)=>document._branchDocID ?? document._id);
|
|
387
456
|
switch(operator){
|
|
388
457
|
case 'contains':
|
|
389
458
|
{
|
|
@@ -398,7 +467,7 @@ const subQueryOptions = {
|
|
|
398
467
|
case 'equals':
|
|
399
468
|
{
|
|
400
469
|
// Every related document satisfies an empty nested query.
|
|
401
|
-
if (!Object.keys(
|
|
470
|
+
if (!Object.keys(nestedWhere).length) {
|
|
402
471
|
return {
|
|
403
472
|
path,
|
|
404
473
|
value: {
|
|
@@ -432,5 +501,118 @@ const subQueryOptions = {
|
|
|
432
501
|
}
|
|
433
502
|
}
|
|
434
503
|
}
|
|
504
|
+
/**
|
|
505
|
+
* Builds a MongoDB condition for a `contains` query nested on a join field.
|
|
506
|
+
*
|
|
507
|
+
* Finds documents in the joined collection that match the nested query, then follows the join's
|
|
508
|
+
* `on` relationship to collect the parent IDs those documents point back to. Because the nested
|
|
509
|
+
* query resolves against a single joined document, the user's filter and any injected access
|
|
510
|
+
* constraint must be satisfied by the same document.
|
|
511
|
+
*/ async function buildJoinContainsSearchParam({ branch, field, locale, nestedWhere, payload, req }) {
|
|
512
|
+
if (field.type !== 'join' || typeof field.collection !== 'string' || !isNestedRelationshipQuery(nestedWhere)) {
|
|
513
|
+
return undefined;
|
|
514
|
+
}
|
|
515
|
+
const { collectionConfig, Model: JoinedModel } = getCollection({
|
|
516
|
+
adapter: payload.db,
|
|
517
|
+
collectionSlug: field.collection
|
|
518
|
+
});
|
|
519
|
+
const relationshipField = getFieldByPath({
|
|
520
|
+
fields: collectionConfig.flattenedFields,
|
|
521
|
+
path: field.on
|
|
522
|
+
});
|
|
523
|
+
if (!relationshipField) {
|
|
524
|
+
throw new APIError('Relationship field was not found');
|
|
525
|
+
}
|
|
526
|
+
let joinPath = relationshipField.localizedPath;
|
|
527
|
+
if (relationshipField.pathHasLocalized && payload.config.localization) {
|
|
528
|
+
joinPath = joinPath.replace('<locale>', locale || payload.config.localization.defaultLocale);
|
|
529
|
+
}
|
|
530
|
+
const { branchVisibility, where: relatedWhere } = await resolveRelatedBranchQuery({
|
|
531
|
+
branch,
|
|
532
|
+
collectionSlug: field.collection,
|
|
533
|
+
payload,
|
|
534
|
+
req,
|
|
535
|
+
where: nestedWhere
|
|
536
|
+
});
|
|
537
|
+
const subQuery = await JoinedModel.buildQuery({
|
|
538
|
+
branch,
|
|
539
|
+
locale,
|
|
540
|
+
payload,
|
|
541
|
+
req,
|
|
542
|
+
where: relatedWhere ?? {}
|
|
543
|
+
});
|
|
544
|
+
const parentIDs = await findRelatedDistinctValues({
|
|
545
|
+
branchVisibility,
|
|
546
|
+
Model: JoinedModel,
|
|
547
|
+
path: joinPath,
|
|
548
|
+
query: subQuery
|
|
549
|
+
});
|
|
550
|
+
return {
|
|
551
|
+
path: '_id',
|
|
552
|
+
value: {
|
|
553
|
+
$in: parentIDs
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
const resolveRelatedBranchQuery = async ({ branch, collectionSlug, payload, req, where })=>{
|
|
558
|
+
const adapter = payload.db;
|
|
559
|
+
const branchReadState = resolveBranchReadState({
|
|
560
|
+
branch,
|
|
561
|
+
collectionSlug,
|
|
562
|
+
req
|
|
563
|
+
});
|
|
564
|
+
const resolvedWhere = branchReadState.useBranching ? rewriteBranchIDs(where) : await resolveBranchQuery({
|
|
565
|
+
branch,
|
|
566
|
+
collectionSlug,
|
|
567
|
+
req,
|
|
568
|
+
where
|
|
569
|
+
});
|
|
570
|
+
return {
|
|
571
|
+
branchVisibility: branchReadState.useBranching ? buildBranchVisibilityStages({
|
|
572
|
+
adapter,
|
|
573
|
+
branch: branchReadState.branch,
|
|
574
|
+
collectionSlug
|
|
575
|
+
}) : [],
|
|
576
|
+
where: resolvedWhere ?? {}
|
|
577
|
+
};
|
|
578
|
+
};
|
|
579
|
+
const findRelatedDocuments = async ({ branchVisibility, Model, projection, query })=>{
|
|
580
|
+
if (branchVisibility.length) {
|
|
581
|
+
return Model.aggregate([
|
|
582
|
+
...buildRelatedQueryPipeline({
|
|
583
|
+
branchVisibility,
|
|
584
|
+
query
|
|
585
|
+
}),
|
|
586
|
+
{
|
|
587
|
+
$project: projection
|
|
588
|
+
}
|
|
589
|
+
]);
|
|
590
|
+
}
|
|
591
|
+
return Model.find(query).lean().select(projection);
|
|
592
|
+
};
|
|
593
|
+
const findRelatedDistinctValues = async ({ branchVisibility, Model, path, query })=>{
|
|
594
|
+
if (!branchVisibility.length) {
|
|
595
|
+
return Model.distinct(path, query);
|
|
596
|
+
}
|
|
597
|
+
return Model.aggregate([
|
|
598
|
+
...buildRelatedQueryPipeline({
|
|
599
|
+
branchVisibility,
|
|
600
|
+
query
|
|
601
|
+
}),
|
|
602
|
+
{
|
|
603
|
+
$project: {
|
|
604
|
+
value: `$${path}`
|
|
605
|
+
}
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
$unwind: '$value'
|
|
609
|
+
},
|
|
610
|
+
{
|
|
611
|
+
$group: {
|
|
612
|
+
_id: '$value'
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
]).then((results)=>results.map(({ _id })=>_id));
|
|
616
|
+
};
|
|
435
617
|
|
|
436
618
|
//# sourceMappingURL=buildSearchParams.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/buildSearchParams.ts"],"sourcesContent":["import type { QueryFilter } from 'mongoose'\nimport type {\n FlattenedField,\n HasManyRelationshipOperator,\n Operator,\n PathToQuery,\n Payload,\n} from 'payload'\n\nimport { Types } from 'mongoose'\nimport { APIError, escapeRegExp, getFieldByPath, getLocalizedPaths } from 'payload'\nimport {\n hasManyRelationshipOperatorSet,\n isNestedRelationshipQuery,\n validOperatorSet,\n} from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\nimport type { OperatorMapKey } from './operatorMap.js'\n\nimport { getCollection } from '../utilities/getEntity.js'\nimport { isObjectID } from '../utilities/isObjectID.js'\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\ntype SearchParam = {\n path?: string\n rawQuery?: unknown\n value?: unknown\n}\n\nconst subQueryOptions = {\n lean: true,\n}\n\n/**\n * Convert the Payload key / value / operator into a MongoDB query\n */\nexport async function buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath,\n locale,\n operator,\n parentIsLocalized,\n payload,\n val,\n}: {\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n incomingPath: string\n locale?: string\n operator: Operator\n parentIsLocalized: boolean\n payload: Payload\n val: unknown\n}): Promise<SearchParam | undefined> {\n // Replace GraphQL nested field double underscore formatting\n let sanitizedPath = incomingPath.replace(/__/g, '.')\n if (sanitizedPath === 'id') {\n sanitizedPath = '_id'\n }\n\n let paths: PathToQuery[] = []\n\n let hasCustomID = false\n\n if (sanitizedPath === '_id') {\n const customIDFieldType = collectionSlug\n ? payload.collections[collectionSlug]?.customIDType\n : undefined\n\n let idFieldType: 'number' | 'text' = 'text'\n\n if (customIDFieldType) {\n idFieldType = customIDFieldType\n hasCustomID = true\n }\n\n paths.push({\n collectionSlug,\n complete: true,\n field: {\n name: 'id',\n type: idFieldType,\n } as FlattenedField,\n parentIsLocalized: parentIsLocalized ?? false,\n path: '_id',\n })\n } else {\n paths = getLocalizedPaths({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: sanitizedPath,\n locale,\n parentIsLocalized,\n payload,\n })\n }\n\n if (!paths[0]) {\n return undefined\n }\n\n const [{ field, path }] = paths\n\n if (\n hasManyRelationshipOperatorSet.has(operator as HasManyRelationshipOperator) &&\n paths.length === 1 &&\n (field.type === 'relationship' || field.type === 'upload') &&\n field.hasMany &&\n typeof field.relationTo === 'string' &&\n isNestedRelationshipQuery(val)\n ) {\n return buildHasManyRelationshipSearchParam({\n field,\n locale,\n nestedWhere: val,\n operator: operator as HasManyRelationshipOperator,\n path,\n payload,\n })\n }\n\n if (path) {\n const sanitizedQueryValue = sanitizeQueryValue({\n field,\n hasCustomID,\n locale,\n operator,\n parentIsLocalized,\n path,\n payload,\n val,\n })\n\n if (!sanitizedQueryValue) {\n return undefined\n }\n\n const { operator: formattedOperator, rawQuery, val: formattedValue } = sanitizedQueryValue\n\n if (rawQuery && paths.length === 1) {\n return { value: rawQuery }\n }\n\n if (!formattedOperator) {\n return undefined\n }\n\n // If there are multiple collections to search through,\n // Recursively build up a list of query constraints\n if (paths.length > 1) {\n // Remove top collection and reverse array\n // to work backwards from top\n const pathsToQuery = paths.slice(1).reverse()\n const parentPaths = paths.slice(0, -1).reverse()\n\n let relationshipQuery: SearchParam = {\n value: {},\n }\n\n for (const [i, { collectionSlug, path: subPath }] of pathsToQuery.entries()) {\n // The arrays are reversed together, so both entries describe the same relationship hop.\n const parentField = parentPaths[i]?.field\n\n if (!parentField) {\n return undefined\n }\n\n if (!collectionSlug) {\n throw new APIError(`Collection with the slug ${collectionSlug} was not found.`)\n }\n\n const { collectionConfig, Model: SubModel } = getCollection({\n adapter: payload.db as MongooseAdapter,\n collectionSlug,\n })\n\n if (i === 0) {\n const subQuery = await SubModel.buildQuery({\n locale,\n payload,\n where: {\n [subPath]: {\n [formattedOperator]: val,\n },\n },\n })\n\n const select: Record<string, boolean> = {\n _id: true,\n }\n\n let joinPath: null | string = null\n\n if (parentField.type === 'join') {\n const relationshipField = getFieldByPath({\n fields: collectionConfig.flattenedFields,\n path: parentField.on,\n })\n if (!relationshipField) {\n throw new APIError('Relationship field was not found')\n }\n\n let path = relationshipField.localizedPath\n if (relationshipField.pathHasLocalized && payload.config.localization) {\n path = path.replace('<locale>', locale || payload.config.localization.defaultLocale)\n }\n select[path] = true\n\n joinPath = path\n }\n\n if (joinPath) {\n select[joinPath] = true\n }\n\n const result = await SubModel.find(subQuery).lean().select(select)\n\n const $in: unknown[] = []\n\n result.forEach((doc: any) => {\n if (joinPath) {\n let ref = doc\n\n for (const segment of joinPath.split('.')) {\n if (Array.isArray(ref)) {\n ref = ref\n .map((item) => (typeof item === 'object' && item ? item[segment] : undefined))\n .flat()\n .filter((item) => item != null)\n } else if (typeof ref === 'object' && ref) {\n ref = ref[segment]\n } else {\n ref = undefined\n break\n }\n }\n\n if (Array.isArray(ref)) {\n for (const item of ref) {\n if (isObjectID(item)) {\n $in.push(item)\n }\n }\n } else if (isObjectID(ref)) {\n $in.push(ref)\n }\n } else {\n const stringID = doc._id.toString()\n if (Types.ObjectId.isValid(stringID)) {\n $in.push(doc._id)\n } else {\n $in.push(stringID)\n }\n }\n })\n\n if (pathsToQuery.length === 1) {\n return {\n path: joinPath ? '_id' : path,\n value: { $in },\n }\n }\n\n const nextSubPath = pathsToQuery[i + 1]?.path\n\n if (nextSubPath) {\n relationshipQuery = {\n value: joinPath ? { _id: { $in } } : { [nextSubPath]: { $in } },\n }\n }\n\n continue\n }\n\n const subQuery = relationshipQuery.value as QueryFilter<any>\n\n /**\n * Follow this join back to its parent IDs.\n * For example, matching songs yield album IDs, then artist IDs.\n */\n if (parentField.type === 'join') {\n const relationshipField = getFieldByPath({\n fields: collectionConfig.flattenedFields,\n path: parentField.on,\n })\n if (!relationshipField) {\n throw new APIError('Relationship field was not found')\n }\n\n let joinPath = relationshipField.localizedPath\n if (relationshipField.pathHasLocalized && payload.config.localization) {\n joinPath = joinPath.replace(\n '<locale>',\n locale || payload.config.localization.defaultLocale,\n )\n }\n\n const $in = await SubModel.distinct(joinPath, subQuery)\n if (i + 1 === pathsToQuery.length) {\n return { path: '_id', value: { $in } }\n }\n\n relationshipQuery = { value: { _id: { $in } } }\n continue\n }\n\n const result = await SubModel.find(subQuery, subQueryOptions)\n\n const $in = result.map((doc) => doc._id)\n\n // If it is the last recursion\n // then pass through the search param\n if (i + 1 === pathsToQuery.length) {\n relationshipQuery = {\n path,\n value: { $in },\n }\n } else {\n const nextSubPath = pathsToQuery[i + 1]?.path\n if (nextSubPath) {\n relationshipQuery = {\n value: {\n [nextSubPath]: { $in },\n },\n }\n }\n }\n }\n\n return relationshipQuery\n }\n\n if (formattedOperator && validOperatorSet.has(formattedOperator as Operator)) {\n const operatorKey = operatorMap[formattedOperator as OperatorMapKey]\n\n if (field.type === 'relationship' || field.type === 'upload') {\n let hasNumberIDRelation\n let multiIDCondition = '$or'\n if (operatorKey === '$ne') {\n multiIDCondition = '$and'\n }\n\n const result = {\n value: {\n [multiIDCondition]: [{ [path]: { [operatorKey]: formattedValue } }],\n },\n }\n\n if (typeof formattedValue === 'string') {\n if (Types.ObjectId.isValid(formattedValue)) {\n result.value[multiIDCondition]?.push({\n [path]: { [operatorKey]: new Types.ObjectId(formattedValue) },\n })\n } else {\n ;(Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]).forEach(\n (relationTo) => {\n const isRelatedToCustomNumberID =\n payload.collections[relationTo]?.customIDType === 'number'\n\n if (isRelatedToCustomNumberID) {\n hasNumberIDRelation = true\n }\n },\n )\n\n if (hasNumberIDRelation) {\n result.value[multiIDCondition]?.push({\n [path]: { [operatorKey]: parseFloat(formattedValue) },\n })\n }\n }\n }\n\n const length = result.value[multiIDCondition]?.length\n\n if (typeof length === 'number' && length > 1) {\n return result\n }\n }\n\n if (formattedOperator === 'like' && typeof formattedValue === 'string') {\n const words = formattedValue.split(' ')\n\n const result = {\n value: {\n $and: words.map((word) => ({\n [path]: {\n $options: 'i',\n $regex: escapeRegExp(word),\n },\n })),\n },\n }\n\n return result\n }\n\n if (formattedOperator === 'not_like' && typeof formattedValue === 'string') {\n const words = formattedValue.split(' ')\n\n const result = {\n value: {\n $and: words.map((word) => ({\n [path]: {\n $not: {\n $options: 'i',\n $regex: escapeRegExp(word),\n },\n },\n })),\n },\n }\n\n return result\n }\n\n // Some operators like 'near' need to define a full query\n // so if there is no operator key, just return the value\n if (!operatorKey) {\n return {\n path,\n value: formattedValue,\n }\n }\n\n return {\n path,\n value: { [operatorKey]: formattedValue },\n }\n }\n }\n return undefined\n}\n\n/**\n * Builds a MongoDB condition for an operator containing a nested has-many relationship query.\n *\n * First, it finds IDs from the related collection that match the nested query. The parent\n * collection can then use `$in` or `$nin` against its stored relationship IDs.\n *\n * @example\n * ```ts\n * // Input\n * { ingredients: { not_equals: { isHealthy: { equals: false } } } }\n *\n * // Simplified MongoDB result, after finding the matching ingredient IDs\n * { ingredients: { $nin: [unhealthyIngredientID] } }\n * ```\n */\nasync function buildHasManyRelationshipSearchParam({\n field,\n locale,\n nestedWhere,\n operator,\n path,\n payload,\n}: {\n field: FlattenedField\n locale?: string\n nestedWhere: unknown\n operator: HasManyRelationshipOperator\n path: string\n payload: Payload\n}): Promise<SearchParam | undefined> {\n if (\n (field.type !== 'relationship' && field.type !== 'upload') ||\n !field.hasMany ||\n typeof field.relationTo !== 'string' ||\n !isNestedRelationshipQuery(nestedWhere)\n ) {\n return undefined\n }\n\n const { Model: RelatedModel } = getCollection({\n adapter: payload.db as MongooseAdapter,\n collectionSlug: field.relationTo,\n })\n const pathLocale = payload.config.localization\n ? payload.config.localization.localeCodes.find(\n (localeCode) => path.split('.').at(-1) === localeCode,\n )\n : undefined\n const matchingRelatedDocumentsQuery = await RelatedModel.buildQuery({\n locale: pathLocale ?? locale,\n payload,\n where: nestedWhere,\n })\n\n const findRelatedDocumentIDs = async (query: Record<string, unknown>) =>\n (await RelatedModel.find(query).lean().select({ _id: true })).map((document) => document._id)\n\n switch (operator) {\n case 'contains': {\n const matchingRelatedDocumentIDs = await findRelatedDocumentIDs(matchingRelatedDocumentsQuery)\n\n return {\n path,\n value: { $in: matchingRelatedDocumentIDs },\n }\n }\n\n case 'equals': {\n // Every related document satisfies an empty nested query.\n if (!Object.keys(matchingRelatedDocumentsQuery).length) {\n return {\n path,\n value: { $nin: [] },\n }\n }\n\n // MongoDB rejects `$near` and `$text` when they are inverted with `$nor`. Check the parent\n // instead: none of its IDs may fall outside the matching IDs.\n const matchingRelatedDocumentIDs = await findRelatedDocumentIDs(matchingRelatedDocumentsQuery)\n\n return {\n path,\n value: { $not: { $elemMatch: { $nin: matchingRelatedDocumentIDs } } },\n }\n }\n\n case 'not_equals': {\n const matchingRelatedDocumentIDs = await findRelatedDocumentIDs(matchingRelatedDocumentsQuery)\n\n return {\n path,\n value: { $nin: matchingRelatedDocumentIDs },\n }\n }\n }\n}\n"],"names":["Types","APIError","escapeRegExp","getFieldByPath","getLocalizedPaths","hasManyRelationshipOperatorSet","isNestedRelationshipQuery","validOperatorSet","getCollection","isObjectID","operatorMap","sanitizeQueryValue","subQueryOptions","lean","buildSearchParam","collectionSlug","fields","globalSlug","incomingPath","locale","operator","parentIsLocalized","payload","val","sanitizedPath","replace","paths","hasCustomID","customIDFieldType","collections","customIDType","undefined","idFieldType","push","complete","field","name","type","path","has","length","hasMany","relationTo","buildHasManyRelationshipSearchParam","nestedWhere","sanitizedQueryValue","formattedOperator","rawQuery","formattedValue","value","pathsToQuery","slice","reverse","parentPaths","relationshipQuery","i","subPath","entries","parentField","collectionConfig","Model","SubModel","adapter","db","subQuery","buildQuery","where","select","_id","joinPath","relationshipField","flattenedFields","on","localizedPath","pathHasLocalized","config","localization","defaultLocale","result","find","$in","forEach","doc","ref","segment","split","Array","isArray","map","item","flat","filter","stringID","toString","ObjectId","isValid","nextSubPath","distinct","operatorKey","hasNumberIDRelation","multiIDCondition","isRelatedToCustomNumberID","parseFloat","words","$and","word","$options","$regex","$not","RelatedModel","pathLocale","localeCodes","localeCode","at","matchingRelatedDocumentsQuery","findRelatedDocumentIDs","query","document","matchingRelatedDocumentIDs","Object","keys","$nin","$elemMatch"],"mappings":"AASA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,QAAQ,EAAEC,YAAY,EAAEC,cAAc,EAAEC,iBAAiB,QAAQ,UAAS;AACnF,SACEC,8BAA8B,EAC9BC,yBAAyB,EACzBC,gBAAgB,QACX,iBAAgB;AAKvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAQ5D,MAAMC,kBAAkB;IACtBC,MAAM;AACR;AAEA;;CAEC,GACD,OAAO,eAAeC,iBAAiB,EACrCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,YAAY,EACZC,MAAM,EACNC,QAAQ,EACRC,iBAAiB,EACjBC,OAAO,EACPC,GAAG,EAWJ;IACC,4DAA4D;IAC5D,IAAIC,gBAAgBN,aAAaO,OAAO,CAAC,O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tD,OAAO;wBACLF;wBACAW,OAAO;4BAAEwE,MAAM,EAAE;wBAAC;oBACpB;gBACF;gBAEA,2FAA2F;gBAC3F,8DAA8D;gBAC9D,MAAMH,6BAA6B,MAAMH,uBAAuBD;gBAEhE,OAAO;oBACL5E;oBACAW,OAAO;wBAAE2D,MAAM;4BAAEc,YAAY;gCAAED,MAAMH;4BAA2B;wBAAE;oBAAE;gBACtE;YACF;QAEA,KAAK;YAAc;gBACjB,MAAMA,6BAA6B,MAAMH,uBAAuBD;gBAEhE,OAAO;oBACL5E;oBACAW,OAAO;wBAAEwE,MAAMH;oBAA2B;gBAC5C;YACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/queries/buildSearchParams.ts"],"sourcesContent":["import type { PipelineStage, QueryFilter } from 'mongoose'\nimport type {\n FlattenedField,\n HasManyRelationshipOperator,\n Operator,\n PathToQuery,\n Payload,\n PayloadRequest,\n Where,\n} from 'payload'\n\nimport { Types } from 'mongoose'\nimport {\n APIError,\n escapeRegExp,\n getFieldByPath,\n getLocalizedPaths,\n resolveBranchQuery,\n resolveBranchReadState,\n rewriteBranchIDs,\n} from 'payload'\nimport {\n hasManyRelationshipOperatorSet,\n isNestedRelationshipQuery,\n validOperatorSet,\n} from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\nimport type { CollectionModel } from '../types.js'\nimport type { OperatorMapKey } from './operatorMap.js'\n\nimport { getCollection } from '../utilities/getEntity.js'\nimport { isObjectID } from '../utilities/isObjectID.js'\nimport { buildBranchVisibilityStages } from './buildBranchVisibility.js'\nimport { buildRelatedQueryPipeline } from './buildRelatedQueryPipeline.js'\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\ntype SearchParam = {\n path?: string\n rawQuery?: unknown\n value?: unknown\n}\n\n/**\n * Convert the Payload key / value / operator into a MongoDB query\n */\nexport async function buildSearchParam({\n branch,\n collectionSlug,\n fields,\n globalSlug,\n incomingPath,\n locale,\n operator,\n parentIsLocalized,\n payload,\n req,\n val,\n}: {\n branch?: false | string\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n incomingPath: string\n locale?: string\n operator: Operator\n parentIsLocalized: boolean\n payload: Payload\n req?: Partial<PayloadRequest>\n val: unknown\n}): Promise<SearchParam | undefined> {\n // Replace GraphQL nested field double underscore formatting\n let sanitizedPath = incomingPath.replace(/__/g, '.')\n if (sanitizedPath === 'id') {\n sanitizedPath = '_id'\n }\n\n let paths: PathToQuery[] = []\n\n let hasCustomID = false\n\n if (sanitizedPath === '_id') {\n const customIDFieldType = collectionSlug\n ? payload.collections[collectionSlug]?.customIDType\n : undefined\n\n let idFieldType: 'number' | 'text' = 'text'\n\n if (customIDFieldType) {\n idFieldType = customIDFieldType\n hasCustomID = true\n }\n\n paths.push({\n collectionSlug,\n complete: true,\n field: {\n name: 'id',\n type: idFieldType,\n } as FlattenedField,\n parentIsLocalized: parentIsLocalized ?? false,\n path: '_id',\n })\n } else {\n paths = getLocalizedPaths({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: sanitizedPath,\n locale,\n parentIsLocalized,\n payload,\n })\n }\n\n if (!paths[0]) {\n return undefined\n }\n\n const [{ field, path }] = paths\n\n if (\n hasManyRelationshipOperatorSet.has(operator as HasManyRelationshipOperator) &&\n paths.length === 1 &&\n (field.type === 'relationship' || field.type === 'upload') &&\n field.hasMany &&\n typeof field.relationTo === 'string' &&\n isNestedRelationshipQuery(val)\n ) {\n return buildHasManyRelationshipSearchParam({\n branch,\n field,\n locale,\n nestedWhere: val,\n operator: operator as HasManyRelationshipOperator,\n path,\n payload,\n req,\n })\n }\n\n if (\n operator === 'contains' &&\n paths.length === 1 &&\n field.type === 'join' &&\n typeof field.collection === 'string' &&\n isNestedRelationshipQuery(val)\n ) {\n return buildJoinContainsSearchParam({\n branch,\n field,\n locale,\n nestedWhere: val,\n payload,\n req,\n })\n }\n\n if (\n (operator === 'contains' || operator === 'like' || operator === 'not_like') &&\n (isNestedRelationshipQuery(val) ||\n (Array.isArray(val) && val.some((entry) => isNestedRelationshipQuery(entry))))\n ) {\n throw new APIError(`Invalid value for \"${operator}\" on path \"${path}\": expected a string.`, 400)\n }\n\n if (path) {\n const sanitizedQueryValue = sanitizeQueryValue({\n field,\n hasCustomID,\n locale,\n operator,\n parentIsLocalized,\n path,\n payload,\n val,\n })\n\n if (!sanitizedQueryValue) {\n return undefined\n }\n\n const { operator: formattedOperator, rawQuery, val: formattedValue } = sanitizedQueryValue\n\n if (rawQuery && paths.length === 1) {\n return { value: rawQuery }\n }\n\n if (!formattedOperator) {\n return undefined\n }\n\n // If there are multiple collections to search through,\n // Recursively build up a list of query constraints\n if (paths.length > 1) {\n // Remove top collection and reverse array\n // to work backwards from top\n const pathsToQuery = paths.slice(1).reverse()\n const parentPaths = paths.slice(0, -1).reverse()\n\n let relationshipQuery: SearchParam = { value: {} }\n let relationshipWhere: undefined | Where\n\n for (const [i, { collectionSlug, path: subPath }] of pathsToQuery.entries()) {\n // The arrays are reversed together, so both entries describe the same relationship hop.\n const parentField = parentPaths[i]?.field\n\n if (!parentField) {\n return undefined\n }\n\n if (!collectionSlug) {\n throw new APIError(`Collection with the slug ${collectionSlug} was not found.`)\n }\n\n const { collectionConfig, Model: SubModel } = getCollection({\n adapter: payload.db as MongooseAdapter,\n collectionSlug,\n })\n\n if (i === 0) {\n const { branchVisibility, where: relatedWhere } = await resolveRelatedBranchQuery({\n branch,\n collectionSlug,\n payload,\n req,\n where: {\n [subPath]: {\n [formattedOperator]: val,\n },\n },\n })\n const subQuery = await SubModel.buildQuery({\n branch,\n locale,\n payload,\n req,\n where: relatedWhere ?? {},\n })\n\n const select: Record<string, boolean> = {\n _id: true,\n _branchDocID: true,\n }\n\n let joinPath: null | string = null\n\n if (parentField.type === 'join') {\n const relationshipField = getFieldByPath({\n fields: collectionConfig.flattenedFields,\n path: parentField.on,\n })\n if (!relationshipField) {\n throw new APIError('Relationship field was not found')\n }\n\n let path = relationshipField.localizedPath\n if (relationshipField.pathHasLocalized && payload.config.localization) {\n path = path.replace('<locale>', locale || payload.config.localization.defaultLocale)\n }\n select[path] = true\n\n joinPath = path\n }\n\n if (joinPath) {\n select[joinPath] = true\n }\n\n const result = await findRelatedDocuments({\n branchVisibility,\n Model: SubModel,\n projection: select,\n query: subQuery,\n })\n\n const $in: unknown[] = []\n\n result.forEach((doc: any) => {\n if (joinPath) {\n let ref = doc\n\n for (const segment of joinPath.split('.')) {\n if (Array.isArray(ref)) {\n ref = ref\n .map((item) => (typeof item === 'object' && item ? item[segment] : undefined))\n .flat()\n .filter((item) => item != null)\n } else if (typeof ref === 'object' && ref) {\n ref = ref[segment]\n } else {\n ref = undefined\n break\n }\n }\n\n if (Array.isArray(ref)) {\n for (const item of ref) {\n if (isObjectID(item)) {\n $in.push(item)\n }\n }\n } else if (isObjectID(ref)) {\n $in.push(ref)\n }\n } else {\n const documentID = doc._branchDocID ?? doc._id\n const stringID = documentID.toString()\n if (Types.ObjectId.isValid(stringID)) {\n $in.push(documentID)\n } else {\n $in.push(stringID)\n }\n }\n })\n\n if (pathsToQuery.length === 1) {\n return {\n path: joinPath ? '_id' : path,\n value: { $in },\n }\n }\n\n const nextSubPath = pathsToQuery[i + 1]?.path\n\n if (nextSubPath) {\n relationshipWhere = joinPath ? { id: { in: $in } } : { [nextSubPath]: { in: $in } }\n }\n\n continue\n }\n\n if (!relationshipWhere) {\n return undefined\n }\n\n const { branchVisibility, where: relatedWhere } = await resolveRelatedBranchQuery({\n branch,\n collectionSlug,\n payload,\n req,\n where: relationshipWhere,\n })\n const subQuery = (await SubModel.buildQuery({\n branch,\n locale,\n payload,\n req,\n where: relatedWhere ?? {},\n })) as QueryFilter<Record<string, unknown>>\n\n /**\n * Follow this join back to its parent IDs.\n * For example, matching songs yield album IDs, then artist IDs.\n */\n if (parentField.type === 'join') {\n const relationshipField = getFieldByPath({\n fields: collectionConfig.flattenedFields,\n path: parentField.on,\n })\n if (!relationshipField) {\n throw new APIError('Relationship field was not found')\n }\n\n let joinPath = relationshipField.localizedPath\n if (relationshipField.pathHasLocalized && payload.config.localization) {\n joinPath = joinPath.replace(\n '<locale>',\n locale || payload.config.localization.defaultLocale,\n )\n }\n\n const $in = await findRelatedDistinctValues({\n branchVisibility,\n Model: SubModel,\n path: joinPath,\n query: subQuery,\n })\n if (i + 1 === pathsToQuery.length) {\n return { path: '_id', value: { $in } }\n }\n\n relationshipWhere = { id: { in: $in } }\n continue\n }\n\n const result = await findRelatedDocuments({\n branchVisibility,\n Model: SubModel,\n projection: { _id: true, _branchDocID: true },\n query: subQuery,\n })\n\n const $in = result.map((doc) => doc._branchDocID ?? doc._id)\n\n // If it is the last recursion\n // then pass through the search param\n if (i + 1 === pathsToQuery.length) {\n relationshipQuery = {\n path,\n value: { $in },\n }\n } else {\n const nextSubPath = pathsToQuery[i + 1]?.path\n if (nextSubPath) {\n relationshipWhere = { [nextSubPath]: { in: $in } }\n }\n }\n }\n\n return relationshipQuery\n }\n\n if (formattedOperator && validOperatorSet.has(formattedOperator as Operator)) {\n const operatorKey = operatorMap[formattedOperator as OperatorMapKey]\n\n if (field.type === 'relationship' || field.type === 'upload') {\n let hasNumberIDRelation\n let multiIDCondition = '$or'\n if (operatorKey === '$ne') {\n multiIDCondition = '$and'\n }\n\n const result = {\n value: {\n [multiIDCondition]: [{ [path]: { [operatorKey]: formattedValue } }],\n },\n }\n\n if (typeof formattedValue === 'string') {\n if (Types.ObjectId.isValid(formattedValue)) {\n result.value[multiIDCondition]?.push({\n [path]: { [operatorKey]: new Types.ObjectId(formattedValue) },\n })\n } else {\n ;(Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]).forEach(\n (relationTo) => {\n const isRelatedToCustomNumberID =\n payload.collections[relationTo]?.customIDType === 'number'\n\n if (isRelatedToCustomNumberID) {\n hasNumberIDRelation = true\n }\n },\n )\n\n if (hasNumberIDRelation) {\n result.value[multiIDCondition]?.push({\n [path]: { [operatorKey]: parseFloat(formattedValue) },\n })\n }\n }\n }\n\n const length = result.value[multiIDCondition]?.length\n\n if (typeof length === 'number' && length > 1) {\n return result\n }\n }\n\n if (formattedOperator === 'like' && typeof formattedValue === 'string') {\n const words = formattedValue.split(' ')\n\n const result = {\n value: {\n $and: words.map((word) => ({\n [path]: {\n $options: 'i',\n $regex: escapeRegExp(word),\n },\n })),\n },\n }\n\n return result\n }\n\n if (formattedOperator === 'not_like' && typeof formattedValue === 'string') {\n const words = formattedValue.split(' ')\n\n const result = {\n value: {\n $and: words.map((word) => ({\n [path]: {\n $not: {\n $options: 'i',\n $regex: escapeRegExp(word),\n },\n },\n })),\n },\n }\n\n return result\n }\n\n // Some operators like 'near' need to define a full query\n // so if there is no operator key, just return the value\n if (!operatorKey) {\n return {\n path,\n value: formattedValue,\n }\n }\n\n return {\n path,\n value: { [operatorKey]: formattedValue },\n }\n }\n }\n return undefined\n}\n\n/**\n * Builds a MongoDB condition for an operator containing a nested has-many relationship query.\n *\n * First, it finds IDs from the related collection that match the nested query. The parent\n * collection can then use `$in` or `$nin` against its stored relationship IDs.\n *\n * @example\n * ```ts\n * // Input\n * { ingredients: { not_equals: { isHealthy: { equals: false } } } }\n *\n * // Simplified MongoDB result, after finding the matching ingredient IDs\n * { ingredients: { $nin: [unhealthyIngredientID] } }\n * ```\n */\nasync function buildHasManyRelationshipSearchParam({\n branch,\n field,\n locale,\n nestedWhere,\n operator,\n path,\n payload,\n req,\n}: {\n branch?: false | string\n field: FlattenedField\n locale?: string\n nestedWhere: unknown\n operator: HasManyRelationshipOperator\n path: string\n payload: Payload\n req?: Partial<PayloadRequest>\n}): Promise<SearchParam | undefined> {\n if (\n (field.type !== 'relationship' && field.type !== 'upload') ||\n !field.hasMany ||\n typeof field.relationTo !== 'string' ||\n !isNestedRelationshipQuery(nestedWhere)\n ) {\n return undefined\n }\n\n const { Model: RelatedModel } = getCollection({\n adapter: payload.db as MongooseAdapter,\n collectionSlug: field.relationTo,\n })\n const pathLocale = payload.config.localization\n ? payload.config.localization.localeCodes.find(\n (localeCode) => path.split('.').at(-1) === localeCode,\n )\n : undefined\n const { branchVisibility, where: relatedWhere } = await resolveRelatedBranchQuery({\n branch,\n collectionSlug: field.relationTo,\n payload,\n req,\n where: nestedWhere,\n })\n const matchingRelatedDocumentsQuery = await RelatedModel.buildQuery({\n branch,\n locale: pathLocale ?? locale,\n payload,\n req,\n where: relatedWhere ?? {},\n })\n\n const findRelatedDocumentIDs = async (query: Record<string, unknown>) =>\n (\n await findRelatedDocuments({\n branchVisibility,\n Model: RelatedModel,\n projection: { _id: true, _branchDocID: true },\n query,\n })\n ).map((document) => document._branchDocID ?? document._id)\n\n switch (operator) {\n case 'contains': {\n const matchingRelatedDocumentIDs = await findRelatedDocumentIDs(matchingRelatedDocumentsQuery)\n\n return {\n path,\n value: { $in: matchingRelatedDocumentIDs },\n }\n }\n\n case 'equals': {\n // Every related document satisfies an empty nested query.\n if (!Object.keys(nestedWhere).length) {\n return {\n path,\n value: { $nin: [] },\n }\n }\n\n // MongoDB rejects `$near` and `$text` when they are inverted with `$nor`. Check the parent\n // instead: none of its IDs may fall outside the matching IDs.\n const matchingRelatedDocumentIDs = await findRelatedDocumentIDs(matchingRelatedDocumentsQuery)\n\n return {\n path,\n value: { $not: { $elemMatch: { $nin: matchingRelatedDocumentIDs } } },\n }\n }\n\n case 'not_equals': {\n const matchingRelatedDocumentIDs = await findRelatedDocumentIDs(matchingRelatedDocumentsQuery)\n\n return {\n path,\n value: { $nin: matchingRelatedDocumentIDs },\n }\n }\n }\n}\n\n/**\n * Builds a MongoDB condition for a `contains` query nested on a join field.\n *\n * Finds documents in the joined collection that match the nested query, then follows the join's\n * `on` relationship to collect the parent IDs those documents point back to. Because the nested\n * query resolves against a single joined document, the user's filter and any injected access\n * constraint must be satisfied by the same document.\n */\nasync function buildJoinContainsSearchParam({\n branch,\n field,\n locale,\n nestedWhere,\n payload,\n req,\n}: {\n branch?: false | string\n field: FlattenedField\n locale?: string\n nestedWhere: unknown\n payload: Payload\n req?: Partial<PayloadRequest>\n}): Promise<SearchParam | undefined> {\n if (\n field.type !== 'join' ||\n typeof field.collection !== 'string' ||\n !isNestedRelationshipQuery(nestedWhere)\n ) {\n return undefined\n }\n\n const { collectionConfig, Model: JoinedModel } = getCollection({\n adapter: payload.db as MongooseAdapter,\n collectionSlug: field.collection,\n })\n\n const relationshipField = getFieldByPath({\n fields: collectionConfig.flattenedFields,\n path: field.on,\n })\n\n if (!relationshipField) {\n throw new APIError('Relationship field was not found')\n }\n\n let joinPath = relationshipField.localizedPath\n if (relationshipField.pathHasLocalized && payload.config.localization) {\n joinPath = joinPath.replace('<locale>', locale || payload.config.localization.defaultLocale)\n }\n\n const { branchVisibility, where: relatedWhere } = await resolveRelatedBranchQuery({\n branch,\n collectionSlug: field.collection,\n payload,\n req,\n where: nestedWhere,\n })\n const subQuery = await JoinedModel.buildQuery({\n branch,\n locale,\n payload,\n req,\n where: relatedWhere ?? {},\n })\n\n const parentIDs = await findRelatedDistinctValues({\n branchVisibility,\n Model: JoinedModel,\n path: joinPath,\n query: subQuery,\n })\n\n return {\n path: '_id',\n value: { $in: parentIDs },\n }\n}\n\nconst resolveRelatedBranchQuery = async ({\n branch,\n collectionSlug,\n payload,\n req,\n where,\n}: {\n branch?: false | string\n collectionSlug: string\n payload: Payload\n req?: Partial<PayloadRequest>\n where: Where\n}) => {\n const adapter = payload.db as MongooseAdapter\n const branchReadState = resolveBranchReadState({ branch, collectionSlug, req })\n const resolvedWhere = branchReadState.useBranching\n ? rewriteBranchIDs(where)\n : await resolveBranchQuery({ branch, collectionSlug, req, where })\n\n return {\n branchVisibility: branchReadState.useBranching\n ? buildBranchVisibilityStages({\n adapter,\n branch: branchReadState.branch,\n collectionSlug,\n })\n : [],\n where: resolvedWhere ?? {},\n }\n}\n\nconst findRelatedDocuments = async ({\n branchVisibility,\n Model,\n projection,\n query,\n}: {\n branchVisibility: PipelineStage[]\n Model: CollectionModel\n projection: Record<string, boolean>\n query: Record<string, unknown>\n}) => {\n if (branchVisibility.length) {\n return Model.aggregate([\n ...buildRelatedQueryPipeline({ branchVisibility, query }),\n { $project: projection },\n ])\n }\n\n return Model.find(query).lean().select(projection)\n}\n\nconst findRelatedDistinctValues = async ({\n branchVisibility,\n Model,\n path,\n query,\n}: {\n branchVisibility: PipelineStage[]\n Model: CollectionModel\n path: string\n query: Record<string, unknown>\n}) => {\n if (!branchVisibility.length) {\n return Model.distinct(path, query)\n }\n\n return Model.aggregate([\n ...buildRelatedQueryPipeline({ branchVisibility, query }),\n { $project: { value: `$${path}` } },\n { $unwind: '$value' },\n { $group: { _id: '$value' } },\n ]).then((results) => results.map(({ _id }) => _id))\n}\n"],"names":["Types","APIError","escapeRegExp","getFieldByPath","getLocalizedPaths","resolveBranchQuery","resolveBranchReadState","rewriteBranchIDs","hasManyRelationshipOperatorSet","isNestedRelationshipQuery","validOperatorSet","getCollection","isObjectID","buildBranchVisibilityStages","buildRelatedQueryPipeline","operatorMap","sanitizeQueryValue","buildSearchParam","branch","collectionSlug","fields","globalSlug","incomingPath","locale","operator","parentIsLocalized","payload","req","val","sanitizedPath","replace","paths","hasCustomID","customIDFieldType","collections","customIDType","undefined","idFieldType","push","complete","field","name","type","path","has","length","hasMany","relationTo","buildHasManyRelationshipSearchParam","nestedWhere","collection","buildJoinContainsSearchParam","Array","isArray","some","entry","sanitizedQueryValue","formattedOperator","rawQuery","formattedValue","value","pathsToQuery","slice","reverse","parentPaths","relationshipQuery","relationshipWhere","i","subPath","entries","parentField","collectionConfig","Model","SubModel","adapter","db","branchVisibility","where","relatedWhere","resolveRelatedBranchQuery","subQuery","buildQuery","select","_id","_branchDocID","joinPath","relationshipField","flattenedFields","on","localizedPath","pathHasLocalized","config","localization","defaultLocale","result","findRelatedDocuments","projection","query","$in","forEach","doc","ref","segment","split","map","item","flat","filter","documentID","stringID","toString","ObjectId","isValid","nextSubPath","id","in","findRelatedDistinctValues","operatorKey","hasNumberIDRelation","multiIDCondition","isRelatedToCustomNumberID","parseFloat","words","$and","word","$options","$regex","$not","RelatedModel","pathLocale","localeCodes","find","localeCode","at","matchingRelatedDocumentsQuery","findRelatedDocumentIDs","document","matchingRelatedDocumentIDs","Object","keys","$nin","$elemMatch","JoinedModel","parentIDs","branchReadState","resolvedWhere","useBranching","aggregate","$project","lean","distinct","$unwind","$group","then","results"],"mappings":"AAWA,SAASA,KAAK,QAAQ,WAAU;AAChC,SACEC,QAAQ,EACRC,YAAY,EACZC,cAAc,EACdC,iBAAiB,EACjBC,kBAAkB,EAClBC,sBAAsB,EACtBC,gBAAgB,QACX,UAAS;AAChB,SACEC,8BAA8B,EAC9BC,yBAAyB,EACzBC,gBAAgB,QACX,iBAAgB;AAMvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,2BAA2B,QAAQ,6BAA4B;AACxE,SAASC,yBAAyB,QAAQ,iCAAgC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAQ5D;;CAEC,GACD,OAAO,eAAeC,iBAAiB,EACrCC,MAAM,EACNC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,YAAY,EACZC,MAAM,EACNC,QAAQ,EACRC,iBAAiB,EACjBC,OAAO,EACPC,GAAG,EACHC,GAAG,EAaJ;IACC,4DAA4D;IAC5D,IAAIC,gBAAgBP,aAAaQ,OAAO,CAAC,OAAO;IAChD,IAAID,kBAAkB,MAAM;QAC1BA,gBAAgB;IAClB;IAEA,IAAIE,QAAuB,EAAE;IAE7B,IAAIC,cAAc;IAElB,IAAIH,kBAAkB,OAAO;QAC3B,MAAMI,oBAAoBd,iBACtBO,QAAQQ,WAAW,CAACf,eAAe,EAAEgB,eACrCC;QAEJ,IAAIC,cAAiC;QAErC,IAAIJ,mBAAmB;YACrBI,cAAcJ;YACdD,cAAc;QAChB;QAEAD,MAAMO,IAAI,CAAC;YACTnB;YACAoB,UAAU;YACVC,OAAO;gBACLC,MAAM;gBACN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;YAAE8D;YAAkBqB;QAAM;QACvD;YAAEmD,UAAU;gBAAExF,OAAO,CAAC,CAAC,EAAEjB,MAAM;YAAC;QAAE;QAClC;YAAE4G,SAAS;QAAS;QACpB;YAAEC,QAAQ;gBAAErE,KAAK;YAAS;QAAE;KAC7B,EAAEsE,IAAI,CAAC,CAACC,UAAYA,QAAQlD,GAAG,CAAC,CAAC,EAAErB,GAAG,EAAE,GAAKA;AAChD"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type { FlattenedField, Payload, Where } from 'payload';
|
|
1
|
+
import type { FlattenedField, Payload, PayloadRequest, Where } from 'payload';
|
|
2
2
|
type GetBuildQueryPluginArgs = {
|
|
3
3
|
collectionSlug?: string;
|
|
4
4
|
versionsFields?: FlattenedField[];
|
|
5
5
|
};
|
|
6
6
|
export type BuildQueryArgs = {
|
|
7
|
+
branch?: false | string;
|
|
7
8
|
globalSlug?: string;
|
|
8
9
|
locale?: string;
|
|
9
10
|
payload: Payload;
|
|
11
|
+
req?: Partial<PayloadRequest>;
|
|
10
12
|
where: Where;
|
|
11
13
|
};
|
|
12
14
|
export declare const getBuildQueryPlugin: ({ collectionSlug, versionsFields, }?: GetBuildQueryPluginArgs) => (schema: any) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBuildQueryPlugin.d.ts","sourceRoot":"","sources":["../../src/queries/getBuildQueryPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"getBuildQueryPlugin.d.ts","sourceRoot":"","sources":["../../src/queries/getBuildQueryPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAM7E,KAAK,uBAAuB,GAAG;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,cAAc,EAAE,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAKD,eAAO,MAAM,mBAAmB,yCAG7B,uBAAuB,cACiB,GAAG,SAuD7C,CAAA"}
|
|
@@ -6,7 +6,7 @@ import { parseParams } from './parseParams.js';
|
|
|
6
6
|
export const getBuildQueryPlugin = ({ collectionSlug, versionsFields } = {})=>{
|
|
7
7
|
return function buildQueryPlugin(schema) {
|
|
8
8
|
const modifiedSchema = schema;
|
|
9
|
-
async function schemaBuildQuery({ globalSlug, locale, payload, where }) {
|
|
9
|
+
async function schemaBuildQuery({ branch, globalSlug, locale, payload, req, where }) {
|
|
10
10
|
let fields = null;
|
|
11
11
|
if (versionsFields) {
|
|
12
12
|
fields = versionsFields;
|
|
@@ -30,12 +30,14 @@ export const getBuildQueryPlugin = ({ collectionSlug, versionsFields } = {})=>{
|
|
|
30
30
|
throw new APIError('Fields are not initialized.');
|
|
31
31
|
}
|
|
32
32
|
const result = await parseParams({
|
|
33
|
+
branch,
|
|
33
34
|
collectionSlug,
|
|
34
35
|
fields,
|
|
35
36
|
globalSlug,
|
|
36
37
|
locale,
|
|
37
38
|
parentIsLocalized: false,
|
|
38
39
|
payload,
|
|
40
|
+
req,
|
|
39
41
|
where
|
|
40
42
|
});
|
|
41
43
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/getBuildQueryPlugin.ts"],"sourcesContent":["import type { FlattenedField, Payload, Where } from 'payload'\n\nimport { APIError } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\ntype GetBuildQueryPluginArgs = {\n collectionSlug?: string\n versionsFields?: FlattenedField[]\n}\n\nexport type BuildQueryArgs = {\n globalSlug?: string\n locale?: string\n payload: Payload\n where: Where\n}\n\n// This plugin asynchronously builds a list of Mongoose query constraints\n// which can then be used in subsequent Mongoose queries.\n// Deprecated in favor of using simpler buildQuery directly\nexport const getBuildQueryPlugin = ({\n collectionSlug,\n versionsFields,\n}: GetBuildQueryPluginArgs = {}) => {\n return function buildQueryPlugin(schema: any) {\n const modifiedSchema = schema\n async function schemaBuildQuery({\n globalSlug,\n locale,\n payload,\n where,\n }: BuildQueryArgs): Promise<Record<string, unknown>> {\n let fields: FlattenedField[] | null = null\n\n if (versionsFields) {\n fields = versionsFields\n } else {\n if (globalSlug) {\n const globalConfig = payload.globals.config.find(({ slug }) => slug === globalSlug)\n\n if (!globalConfig) {\n throw new APIError(`Global with the slug ${globalSlug} was not found`)\n }\n\n fields = globalConfig.flattenedFields\n }\n if (collectionSlug) {\n const collectionConfig = payload.collections[collectionSlug]?.config\n\n if (!collectionConfig) {\n throw new APIError(`Collection with the slug ${globalSlug} was not found`)\n }\n\n fields = collectionConfig.flattenedFields\n }\n }\n\n if (fields === null) {\n throw new APIError('Fields are not initialized.')\n }\n\n const result = await parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n parentIsLocalized: false,\n payload,\n where,\n })\n\n return result\n }\n modifiedSchema.statics.buildQuery = schemaBuildQuery\n }\n}\n"],"names":["APIError","parseParams","getBuildQueryPlugin","collectionSlug","versionsFields","buildQueryPlugin","schema","modifiedSchema","schemaBuildQuery","globalSlug","locale","payload","where","fields","globalConfig","globals","config","find","slug","flattenedFields","collectionConfig","collections","result","parentIsLocalized","statics","buildQuery"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAElC,SAASC,WAAW,QAAQ,mBAAkB;
|
|
1
|
+
{"version":3,"sources":["../../src/queries/getBuildQueryPlugin.ts"],"sourcesContent":["import type { FlattenedField, Payload, PayloadRequest, Where } from 'payload'\n\nimport { APIError } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\ntype GetBuildQueryPluginArgs = {\n collectionSlug?: string\n versionsFields?: FlattenedField[]\n}\n\nexport type BuildQueryArgs = {\n branch?: false | string\n globalSlug?: string\n locale?: string\n payload: Payload\n req?: Partial<PayloadRequest>\n where: Where\n}\n\n// This plugin asynchronously builds a list of Mongoose query constraints\n// which can then be used in subsequent Mongoose queries.\n// Deprecated in favor of using simpler buildQuery directly\nexport const getBuildQueryPlugin = ({\n collectionSlug,\n versionsFields,\n}: GetBuildQueryPluginArgs = {}) => {\n return function buildQueryPlugin(schema: any) {\n const modifiedSchema = schema\n async function schemaBuildQuery({\n branch,\n globalSlug,\n locale,\n payload,\n req,\n where,\n }: BuildQueryArgs): Promise<Record<string, unknown>> {\n let fields: FlattenedField[] | null = null\n\n if (versionsFields) {\n fields = versionsFields\n } else {\n if (globalSlug) {\n const globalConfig = payload.globals.config.find(({ slug }) => slug === globalSlug)\n\n if (!globalConfig) {\n throw new APIError(`Global with the slug ${globalSlug} was not found`)\n }\n\n fields = globalConfig.flattenedFields\n }\n if (collectionSlug) {\n const collectionConfig = payload.collections[collectionSlug]?.config\n\n if (!collectionConfig) {\n throw new APIError(`Collection with the slug ${globalSlug} was not found`)\n }\n\n fields = collectionConfig.flattenedFields\n }\n }\n\n if (fields === null) {\n throw new APIError('Fields are not initialized.')\n }\n\n const result = await parseParams({\n branch,\n collectionSlug,\n fields,\n globalSlug,\n locale,\n parentIsLocalized: false,\n payload,\n req,\n where,\n })\n\n return result\n }\n modifiedSchema.statics.buildQuery = schemaBuildQuery\n }\n}\n"],"names":["APIError","parseParams","getBuildQueryPlugin","collectionSlug","versionsFields","buildQueryPlugin","schema","modifiedSchema","schemaBuildQuery","branch","globalSlug","locale","payload","req","where","fields","globalConfig","globals","config","find","slug","flattenedFields","collectionConfig","collections","result","parentIsLocalized","statics","buildQuery"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAElC,SAASC,WAAW,QAAQ,mBAAkB;AAgB9C,yEAAyE;AACzE,yDAAyD;AACzD,2DAA2D;AAC3D,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,cAAc,EACdC,cAAc,EACU,GAAG,CAAC,CAAC;IAC7B,OAAO,SAASC,iBAAiBC,MAAW;QAC1C,MAAMC,iBAAiBD;QACvB,eAAeE,iBAAiB,EAC9BC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,GAAG,EACHC,KAAK,EACU;YACf,IAAIC,SAAkC;YAEtC,IAAIX,gBAAgB;gBAClBW,SAASX;YACX,OAAO;gBACL,IAAIM,YAAY;oBACd,MAAMM,eAAeJ,QAAQK,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASV;oBAExE,IAAI,CAACM,cAAc;wBACjB,MAAM,IAAIhB,SAAS,CAAC,qBAAqB,EAAEU,WAAW,cAAc,CAAC;oBACvE;oBAEAK,SAASC,aAAaK,eAAe;gBACvC;gBACA,IAAIlB,gBAAgB;oBAClB,MAAMmB,mBAAmBV,QAAQW,WAAW,CAACpB,eAAe,EAAEe;oBAE9D,IAAI,CAACI,kBAAkB;wBACrB,MAAM,IAAItB,SAAS,CAAC,yBAAyB,EAAEU,WAAW,cAAc,CAAC;oBAC3E;oBAEAK,SAASO,iBAAiBD,eAAe;gBAC3C;YACF;YAEA,IAAIN,WAAW,MAAM;gBACnB,MAAM,IAAIf,SAAS;YACrB;YAEA,MAAMwB,SAAS,MAAMvB,YAAY;gBAC/BQ;gBACAN;gBACAY;gBACAL;gBACAC;gBACAc,mBAAmB;gBACnBb;gBACAC;gBACAC;YACF;YAEA,OAAOU;QACT;QACAjB,eAAemB,OAAO,CAACC,UAAU,GAAGnB;IACtC;AACF,EAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type { FlattenedField, Payload, Where } from 'payload';
|
|
2
|
-
export declare function parseParams({ collectionSlug, fields, globalSlug, locale, parentIsLocalized, payload, where, }: {
|
|
1
|
+
import type { FlattenedField, Payload, PayloadRequest, Where } from 'payload';
|
|
2
|
+
export declare function parseParams({ branch, collectionSlug, fields, globalSlug, locale, parentIsLocalized, payload, req, where, }: {
|
|
3
|
+
branch?: false | string;
|
|
3
4
|
collectionSlug?: string;
|
|
4
5
|
fields: FlattenedField[];
|
|
5
6
|
globalSlug?: string;
|
|
6
7
|
locale?: string;
|
|
7
8
|
parentIsLocalized: boolean;
|
|
8
9
|
payload: Payload;
|
|
10
|
+
req?: Partial<PayloadRequest>;
|
|
9
11
|
where: Where;
|
|
10
12
|
}): Promise<Record<string, unknown>>;
|
|
11
13
|
//# sourceMappingURL=parseParams.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAY,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAY,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAQvF,wBAAsB,WAAW,CAAC,EAChC,MAAM,EACN,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,iBAAiB,EACjB,OAAO,EACP,GAAG,EACH,KAAK,GACN,EAAE;IACD,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,iBAAiB,EAAE,OAAO,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,KAAK,EAAE,KAAK,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAyFnC"}
|