@payloadcms/db-mongodb 4.0.0-internal.a2d053c → 4.0.0-internal.a5acc33
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 +1 -0
- 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 +1 -0
- package/dist/exports/migration-utils.d.ts.map +1 -1
- package/dist/exports/migration-utils.js +1 -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 +70 -11
- 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/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +30 -1
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +36 -10
- package/dist/models/buildSchema.js.map +1 -1
- 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/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 +177 -45
- 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 +89 -7
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +1 -0
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateMany.d.ts.map +1 -1
- package/dist/updateMany.js +3 -1
- package/dist/updateMany.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +28 -2
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +1 -0
- 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 +18 -4
- 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 +141 -11
- 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 +3 -3
|
@@ -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,20 +51,24 @@ 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
|
|
61
62
|
});
|
|
62
63
|
}
|
|
63
64
|
if (operator === 'contains' && paths.length === 1 && field.type === 'join' && typeof field.collection === 'string' && isNestedRelationshipQuery(val)) {
|
|
64
65
|
return buildJoinContainsSearchParam({
|
|
66
|
+
branch,
|
|
65
67
|
field,
|
|
66
68
|
locale,
|
|
67
69
|
nestedWhere: val,
|
|
68
|
-
payload
|
|
70
|
+
payload,
|
|
71
|
+
req
|
|
69
72
|
});
|
|
70
73
|
}
|
|
71
74
|
if ((operator === 'contains' || operator === 'like' || operator === 'not_like') && (isNestedRelationshipQuery(val) || Array.isArray(val) && val.some((entry)=>isNestedRelationshipQuery(entry)))) {
|
|
@@ -104,6 +107,7 @@ const subQueryOptions = {
|
|
|
104
107
|
let relationshipQuery = {
|
|
105
108
|
value: {}
|
|
106
109
|
};
|
|
110
|
+
let relationshipWhere;
|
|
107
111
|
for (const [i, { collectionSlug, path: subPath }] of pathsToQuery.entries()){
|
|
108
112
|
// The arrays are reversed together, so both entries describe the same relationship hop.
|
|
109
113
|
const parentField = parentPaths[i]?.field;
|
|
@@ -118,17 +122,27 @@ const subQueryOptions = {
|
|
|
118
122
|
collectionSlug
|
|
119
123
|
});
|
|
120
124
|
if (i === 0) {
|
|
121
|
-
const
|
|
122
|
-
|
|
125
|
+
const { branchVisibility, where: relatedWhere } = await resolveRelatedBranchQuery({
|
|
126
|
+
branch,
|
|
127
|
+
collectionSlug,
|
|
123
128
|
payload,
|
|
129
|
+
req,
|
|
124
130
|
where: {
|
|
125
131
|
[subPath]: {
|
|
126
132
|
[formattedOperator]: val
|
|
127
133
|
}
|
|
128
134
|
}
|
|
129
135
|
});
|
|
136
|
+
const subQuery = await SubModel.buildQuery({
|
|
137
|
+
branch,
|
|
138
|
+
locale,
|
|
139
|
+
payload,
|
|
140
|
+
req,
|
|
141
|
+
where: relatedWhere ?? {}
|
|
142
|
+
});
|
|
130
143
|
const select = {
|
|
131
|
-
_id: true
|
|
144
|
+
_id: true,
|
|
145
|
+
_branchDocID: true
|
|
132
146
|
};
|
|
133
147
|
let joinPath = null;
|
|
134
148
|
if (parentField.type === 'join') {
|
|
@@ -149,7 +163,12 @@ const subQueryOptions = {
|
|
|
149
163
|
if (joinPath) {
|
|
150
164
|
select[joinPath] = true;
|
|
151
165
|
}
|
|
152
|
-
const result = await
|
|
166
|
+
const result = await findRelatedDocuments({
|
|
167
|
+
branchVisibility,
|
|
168
|
+
Model: SubModel,
|
|
169
|
+
projection: select,
|
|
170
|
+
query: subQuery
|
|
171
|
+
});
|
|
153
172
|
const $in = [];
|
|
154
173
|
result.forEach((doc)=>{
|
|
155
174
|
if (joinPath) {
|
|
@@ -174,9 +193,10 @@ const subQueryOptions = {
|
|
|
174
193
|
$in.push(ref);
|
|
175
194
|
}
|
|
176
195
|
} else {
|
|
177
|
-
const
|
|
196
|
+
const documentID = doc._branchDocID ?? doc._id;
|
|
197
|
+
const stringID = documentID.toString();
|
|
178
198
|
if (Types.ObjectId.isValid(stringID)) {
|
|
179
|
-
$in.push(
|
|
199
|
+
$in.push(documentID);
|
|
180
200
|
} else {
|
|
181
201
|
$in.push(stringID);
|
|
182
202
|
}
|
|
@@ -192,21 +212,35 @@ const subQueryOptions = {
|
|
|
192
212
|
}
|
|
193
213
|
const nextSubPath = pathsToQuery[i + 1]?.path;
|
|
194
214
|
if (nextSubPath) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
$in
|
|
203
|
-
}
|
|
215
|
+
relationshipWhere = joinPath ? {
|
|
216
|
+
id: {
|
|
217
|
+
in: $in
|
|
218
|
+
}
|
|
219
|
+
} : {
|
|
220
|
+
[nextSubPath]: {
|
|
221
|
+
in: $in
|
|
204
222
|
}
|
|
205
223
|
};
|
|
206
224
|
}
|
|
207
225
|
continue;
|
|
208
226
|
}
|
|
209
|
-
|
|
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
|
+
});
|
|
210
244
|
/**
|
|
211
245
|
* Follow this join back to its parent IDs.
|
|
212
246
|
* For example, matching songs yield album IDs, then artist IDs.
|
|
@@ -222,7 +256,12 @@ const subQueryOptions = {
|
|
|
222
256
|
if (relationshipField.pathHasLocalized && payload.config.localization) {
|
|
223
257
|
joinPath = joinPath.replace('<locale>', locale || payload.config.localization.defaultLocale);
|
|
224
258
|
}
|
|
225
|
-
const $in = await
|
|
259
|
+
const $in = await findRelatedDistinctValues({
|
|
260
|
+
branchVisibility,
|
|
261
|
+
Model: SubModel,
|
|
262
|
+
path: joinPath,
|
|
263
|
+
query: subQuery
|
|
264
|
+
});
|
|
226
265
|
if (i + 1 === pathsToQuery.length) {
|
|
227
266
|
return {
|
|
228
267
|
path: '_id',
|
|
@@ -231,17 +270,23 @@ const subQueryOptions = {
|
|
|
231
270
|
}
|
|
232
271
|
};
|
|
233
272
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
$in
|
|
238
|
-
}
|
|
273
|
+
relationshipWhere = {
|
|
274
|
+
id: {
|
|
275
|
+
in: $in
|
|
239
276
|
}
|
|
240
277
|
};
|
|
241
278
|
continue;
|
|
242
279
|
}
|
|
243
|
-
const result = await
|
|
244
|
-
|
|
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);
|
|
245
290
|
// If it is the last recursion
|
|
246
291
|
// then pass through the search param
|
|
247
292
|
if (i + 1 === pathsToQuery.length) {
|
|
@@ -254,11 +299,9 @@ const subQueryOptions = {
|
|
|
254
299
|
} else {
|
|
255
300
|
const nextSubPath = pathsToQuery[i + 1]?.path;
|
|
256
301
|
if (nextSubPath) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
$in
|
|
261
|
-
}
|
|
302
|
+
relationshipWhere = {
|
|
303
|
+
[nextSubPath]: {
|
|
304
|
+
in: $in
|
|
262
305
|
}
|
|
263
306
|
};
|
|
264
307
|
}
|
|
@@ -378,7 +421,7 @@ const subQueryOptions = {
|
|
|
378
421
|
* // Simplified MongoDB result, after finding the matching ingredient IDs
|
|
379
422
|
* { ingredients: { $nin: [unhealthyIngredientID] } }
|
|
380
423
|
* ```
|
|
381
|
-
*/ async function buildHasManyRelationshipSearchParam({ field, locale, nestedWhere, operator, path, payload }) {
|
|
424
|
+
*/ async function buildHasManyRelationshipSearchParam({ branch, field, locale, nestedWhere, operator, path, payload, req }) {
|
|
382
425
|
if (field.type !== 'relationship' && field.type !== 'upload' || !field.hasMany || typeof field.relationTo !== 'string' || !isNestedRelationshipQuery(nestedWhere)) {
|
|
383
426
|
return undefined;
|
|
384
427
|
}
|
|
@@ -387,14 +430,29 @@ const subQueryOptions = {
|
|
|
387
430
|
collectionSlug: field.relationTo
|
|
388
431
|
});
|
|
389
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
|
+
});
|
|
390
440
|
const matchingRelatedDocumentsQuery = await RelatedModel.buildQuery({
|
|
441
|
+
branch,
|
|
391
442
|
locale: pathLocale ?? locale,
|
|
392
443
|
payload,
|
|
393
|
-
|
|
444
|
+
req,
|
|
445
|
+
where: relatedWhere ?? {}
|
|
394
446
|
});
|
|
395
|
-
const findRelatedDocumentIDs = async (query)=>(await
|
|
396
|
-
|
|
397
|
-
|
|
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);
|
|
398
456
|
switch(operator){
|
|
399
457
|
case 'contains':
|
|
400
458
|
{
|
|
@@ -409,7 +467,7 @@ const subQueryOptions = {
|
|
|
409
467
|
case 'equals':
|
|
410
468
|
{
|
|
411
469
|
// Every related document satisfies an empty nested query.
|
|
412
|
-
if (!Object.keys(
|
|
470
|
+
if (!Object.keys(nestedWhere).length) {
|
|
413
471
|
return {
|
|
414
472
|
path,
|
|
415
473
|
value: {
|
|
@@ -450,7 +508,7 @@ const subQueryOptions = {
|
|
|
450
508
|
* `on` relationship to collect the parent IDs those documents point back to. Because the nested
|
|
451
509
|
* query resolves against a single joined document, the user's filter and any injected access
|
|
452
510
|
* constraint must be satisfied by the same document.
|
|
453
|
-
*/ async function buildJoinContainsSearchParam({ field, locale, nestedWhere, payload }) {
|
|
511
|
+
*/ async function buildJoinContainsSearchParam({ branch, field, locale, nestedWhere, payload, req }) {
|
|
454
512
|
if (field.type !== 'join' || typeof field.collection !== 'string' || !isNestedRelationshipQuery(nestedWhere)) {
|
|
455
513
|
return undefined;
|
|
456
514
|
}
|
|
@@ -469,12 +527,26 @@ const subQueryOptions = {
|
|
|
469
527
|
if (relationshipField.pathHasLocalized && payload.config.localization) {
|
|
470
528
|
joinPath = joinPath.replace('<locale>', locale || payload.config.localization.defaultLocale);
|
|
471
529
|
}
|
|
530
|
+
const { branchVisibility, where: relatedWhere } = await resolveRelatedBranchQuery({
|
|
531
|
+
branch,
|
|
532
|
+
collectionSlug: field.collection,
|
|
533
|
+
payload,
|
|
534
|
+
req,
|
|
535
|
+
where: nestedWhere
|
|
536
|
+
});
|
|
472
537
|
const subQuery = await JoinedModel.buildQuery({
|
|
538
|
+
branch,
|
|
473
539
|
locale,
|
|
474
540
|
payload,
|
|
475
|
-
|
|
541
|
+
req,
|
|
542
|
+
where: relatedWhere ?? {}
|
|
543
|
+
});
|
|
544
|
+
const parentIDs = await findRelatedDistinctValues({
|
|
545
|
+
branchVisibility,
|
|
546
|
+
Model: JoinedModel,
|
|
547
|
+
path: joinPath,
|
|
548
|
+
query: subQuery
|
|
476
549
|
});
|
|
477
|
-
const parentIDs = await JoinedModel.distinct(joinPath, subQuery);
|
|
478
550
|
return {
|
|
479
551
|
path: '_id',
|
|
480
552
|
value: {
|
|
@@ -482,5 +554,65 @@ const subQueryOptions = {
|
|
|
482
554
|
}
|
|
483
555
|
};
|
|
484
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
|
+
};
|
|
485
617
|
|
|
486
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 (\n operator === 'contains' &&\n paths.length === 1 &&\n field.type === 'join' &&\n typeof field.collection === 'string' &&\n isNestedRelationshipQuery(val)\n ) {\n return buildJoinContainsSearchParam({\n field,\n locale,\n nestedWhere: val,\n payload,\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 = {\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\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 field,\n locale,\n nestedWhere,\n payload,\n}: {\n field: FlattenedField\n locale?: string\n nestedWhere: unknown\n payload: Payload\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 subQuery = await JoinedModel.buildQuery({\n locale,\n payload,\n where: nestedWhere,\n })\n\n const parentIDs = await JoinedModel.distinct(joinPath, subQuery)\n\n return {\n path: '_id',\n value: { $in: parentIDs },\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","collection","buildJoinContainsSearchParam","Array","isArray","some","entry","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","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","JoinedModel","parentIDs"],"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,OAAO;IAChD,IAAID,kBAAkB,MAAM;QAC1BA,gBAAgB;IAClB;IAEA,IAAIE,QAAuB,EAAE;IAE7B,IAAIC,cAAc;IAElB,IAAIH,kBAAkB,OAAO;QAC3B,MAAMI,oBAAoBb,iBACtBO,QAAQO,WAAW,CAACd,eAAe,EAAEe,eACrCC;QAEJ,IAAIC,cAAiC;QAErC,IAAIJ,mBAAmB;YACrBI,cAAcJ;YACdD,cAAc;QAChB;QAEAD,MAAMO,IAAI,C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Y,EAAE;QACrEP,WAAWA,SAASlD,OAAO,CAAC,YAAYN,UAAUG,QAAQ2D,MAAM,CAACC,YAAY,CAACC,aAAa;IAC7F;IAEA,MAAMb,WAAW,MAAMyD,YAAYxD,UAAU,CAAC;QAC5CpD;QACAG;QACAkD,OAAO5B;IACT;IAEA,MAAMoF,YAAY,MAAMD,YAAY1B,QAAQ,CAAC1B,UAAUL;IAEvD,OAAO;QACLhC,MAAM;QACNiB,OAAO;YAAE+B,KAAK0C;QAAU;IAC1B;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;gBACNC,MAAML;YACR;YACAZ,mBAAmBA,qBAAqB;YACxCkB,MAAM;QACR;IACF,OAAO;QACLZ,QAAQ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AAM;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"}
|