@payloadcms/db-mongodb 3.60.0-canary.11 → 3.60.0-canary.12

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.
@@ -313,6 +313,20 @@ import { transform } from './transform.js';
313
313
  }
314
314
  /**
315
315
  * Extracts relationTo filter values from a WHERE clause
316
+ *
317
+ * @purpose When you have a polymorphic join field that can reference multiple collection types (e.g. the documentsAndFolders join field on
318
+ * folders that points to all folder-enabled collections), Payload needs to decide which collections to actually query. Without filtering,
319
+ * it would query ALL possible collections even when the WHERE clause clearly indicates it only needs specific ones.
320
+ *
321
+ * extractRelationToFilter analyzes the WHERE clause to extract relationTo conditions and returns only the collection slugs that
322
+ * could possibly match, avoiding unnecessary database queries.
323
+ *
324
+ * @description The function recursively traverses a WHERE clause looking for relationTo conditions in these patterns:
325
+ *
326
+ * 1. Direct conditions: { relationTo: { equals: 'posts' } }
327
+ * 2. IN conditions: { relationTo: { in: ['posts', 'media'] } }
328
+ * 3. Nested in AND/OR: Recursively searches through logical operators
329
+
316
330
  * @param where - The WHERE clause to search
317
331
  * @returns Array of collection slugs if relationTo filter found, null otherwise
318
332
  */ function extractRelationToFilter(where) {
@@ -333,20 +347,34 @@ import { transform } from './transform.js';
333
347
  }
334
348
  // Check for relationTo in logical operators
335
349
  if (where.and && Array.isArray(where.and)) {
350
+ const allResults = [];
336
351
  for (const condition of where.and){
337
352
  const result = extractRelationToFilter(condition);
338
353
  if (result) {
339
- return result;
354
+ allResults.push(...result);
340
355
  }
341
356
  }
357
+ if (allResults.length > 0) {
358
+ return [
359
+ ...new Set(allResults)
360
+ ] // Remove duplicates
361
+ ;
362
+ }
342
363
  }
343
364
  if (where.or && Array.isArray(where.or)) {
365
+ const allResults = [];
344
366
  for (const condition of where.or){
345
367
  const result = extractRelationToFilter(condition);
346
368
  if (result) {
347
- return result;
369
+ allResults.push(...result);
348
370
  }
349
371
  }
372
+ if (allResults.length > 0) {
373
+ return [
374
+ ...new Set(allResults)
375
+ ] // Remove duplicates
376
+ ;
377
+ }
350
378
  }
351
379
  return null;
352
380
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/resolveJoins.ts"],"sourcesContent":["import type { JoinQuery, SanitizedJoins, Where } from 'payload'\n\nimport {\n appendVersionToQueryKey,\n buildVersionCollectionFields,\n combineQueries,\n getQueryDraftsSort,\n} from 'payload'\nimport { fieldShouldBeLocalized } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { buildQuery } from '../queries/buildQuery.js'\nimport { buildSortParam } from '../queries/buildSortParam.js'\nimport { transform } from './transform.js'\n\nexport type ResolveJoinsArgs = {\n /** The MongoDB adapter instance */\n adapter: MongooseAdapter\n /** The slug of the collection being queried */\n collectionSlug: string\n /** Array of documents to resolve joins for */\n docs: Record<string, unknown>[]\n /** Join query specifications (which joins to resolve and how) */\n joins?: JoinQuery\n /** Optional locale for localized queries */\n locale?: string\n /** Optional projection for the join query */\n projection?: Record<string, true>\n /** Whether to resolve versions instead of published documents */\n versions?: boolean\n}\n\n/**\n * Resolves join relationships for a collection of documents.\n * This function fetches related documents based on join configurations and\n * attaches them to the original documents with pagination support.\n */\nexport async function resolveJoins({\n adapter,\n collectionSlug,\n docs,\n joins,\n locale,\n projection,\n versions = false,\n}: ResolveJoinsArgs): Promise<void> {\n // Early return if no joins are specified or no documents to process\n if (!joins || docs.length === 0) {\n return\n }\n\n // Get the collection configuration from the adapter\n const collectionConfig = adapter.payload.collections[collectionSlug]?.config\n if (!collectionConfig) {\n return\n }\n\n // Build a map of join paths to their configurations for quick lookup\n // This flattens the nested join structure into a single map keyed by join path\n const joinMap: Record<string, { targetCollection: string } & SanitizedJoin> = {}\n\n // Add regular joins\n for (const [target, joinList] of Object.entries(collectionConfig.joins)) {\n for (const join of joinList) {\n joinMap[join.joinPath] = { ...join, targetCollection: target }\n }\n }\n\n // Add polymorphic joins\n for (const join of collectionConfig.polymorphicJoins || []) {\n // For polymorphic joins, we use the collections array as the target\n joinMap[join.joinPath] = { ...join, targetCollection: join.field.collection as string }\n }\n\n // Process each requested join concurrently\n const joinPromises = Object.entries(joins).map(async ([joinPath, joinQuery]) => {\n if (!joinQuery) {\n return null\n }\n\n // If a projection is provided, and the join path is not in the projection, skip it\n if (projection && !projection[joinPath]) {\n return null\n }\n\n // Get the join definition from our map\n const joinDef = joinMap[joinPath]\n if (!joinDef) {\n return null\n }\n\n // Normalize collections to always be an array for unified processing\n const allCollections = Array.isArray(joinDef.field.collection)\n ? joinDef.field.collection\n : [joinDef.field.collection]\n\n // Use the provided locale or fall back to the default locale for localized fields\n const localizationConfig = adapter.payload.config.localization\n const effectiveLocale =\n locale ||\n (typeof localizationConfig === 'object' &&\n localizationConfig &&\n localizationConfig.defaultLocale)\n\n // Extract relationTo filter from the where clause to determine which collections to query\n const relationToFilter = extractRelationToFilter(joinQuery.where || {})\n\n // Determine which collections to query based on relationTo filter\n const collections = relationToFilter\n ? allCollections.filter((col) => relationToFilter.includes(col))\n : allCollections\n\n // Check if this is a polymorphic collection join (where field.collection is an array)\n const isPolymorphicJoin = Array.isArray(joinDef.field.collection)\n\n // Apply pagination settings\n const limit = joinQuery.limit ?? joinDef.field.defaultLimit ?? 10\n const page = joinQuery.page ?? 1\n const skip = (page - 1) * limit\n\n // Process collections concurrently\n const collectionPromises = collections.map(async (joinCollectionSlug) => {\n const targetConfig = adapter.payload.collections[joinCollectionSlug]?.config\n if (!targetConfig) {\n return null\n }\n\n const useDrafts = versions && Boolean(targetConfig.versions?.drafts)\n let JoinModel\n if (useDrafts) {\n JoinModel = adapter.versions[targetConfig.slug]\n } else {\n JoinModel = adapter.collections[targetConfig.slug]\n }\n\n if (!JoinModel) {\n return null\n }\n\n // Extract all parent document IDs to use in the join query\n const parentIDs = docs.map((d) => (versions ? (d.parent ?? d._id ?? d.id) : (d._id ?? d.id)))\n\n // Build the base query\n let whereQuery: null | Record<string, unknown> = null\n whereQuery = isPolymorphicJoin\n ? filterWhereForCollection(\n joinQuery.where || {},\n targetConfig.flattenedFields,\n true, // exclude relationTo for individual collections\n )\n : joinQuery.where || {}\n\n // Skip this collection if the WHERE clause cannot be satisfied for polymorphic collection joins\n if (whereQuery === null) {\n return null\n }\n whereQuery = useDrafts\n ? await JoinModel.buildQuery({\n locale,\n payload: adapter.payload,\n where: combineQueries(appendVersionToQueryKey(whereQuery as Where), {\n latest: {\n equals: true,\n },\n }),\n })\n : await buildQuery({\n adapter,\n collectionSlug: joinCollectionSlug,\n fields: targetConfig.flattenedFields,\n locale,\n where: whereQuery as Where,\n })\n\n // Handle localized paths and version prefixes\n let dbFieldName = joinDef.field.on\n\n if (effectiveLocale && typeof localizationConfig === 'object' && localizationConfig) {\n const pathSegments = joinDef.field.on.split('.')\n const transformedSegments: string[] = []\n const fields = useDrafts\n ? buildVersionCollectionFields(adapter.payload.config, targetConfig, true)\n : targetConfig.flattenedFields\n\n for (let i = 0; i < pathSegments.length; i++) {\n const segment = pathSegments[i]!\n transformedSegments.push(segment)\n\n // Check if this segment corresponds to a localized field\n const fieldAtSegment = fields.find((f) => f.name === segment)\n if (fieldAtSegment && fieldAtSegment.localized) {\n transformedSegments.push(effectiveLocale)\n }\n }\n\n dbFieldName = transformedSegments.join('.')\n }\n\n // Add version prefix for draft queries\n if (useDrafts) {\n dbFieldName = `version.${dbFieldName}`\n }\n\n // Check if the target field is a polymorphic relationship\n const isPolymorphic = joinDef.targetField\n ? Array.isArray(joinDef.targetField.relationTo)\n : false\n\n if (isPolymorphic) {\n // For polymorphic relationships, we need to match both relationTo and value\n whereQuery[`${dbFieldName}.relationTo`] = collectionSlug\n whereQuery[`${dbFieldName}.value`] = { $in: parentIDs }\n } else {\n // For regular relationships and polymorphic collection joins\n whereQuery[dbFieldName] = { $in: parentIDs }\n }\n\n // Build the sort parameters for the query\n const fields = useDrafts\n ? buildVersionCollectionFields(adapter.payload.config, targetConfig, true)\n : targetConfig.flattenedFields\n\n const sort = buildSortParam({\n adapter,\n config: adapter.payload.config,\n fields,\n locale,\n sort: useDrafts\n ? getQueryDraftsSort({\n collectionConfig: targetConfig,\n sort: joinQuery.sort || joinDef.field.defaultSort || targetConfig.defaultSort,\n })\n : joinQuery.sort || joinDef.field.defaultSort || targetConfig.defaultSort,\n timestamps: true,\n })\n\n const projection = buildJoinProjection(dbFieldName, useDrafts, sort)\n\n const [results, dbCount] = await Promise.all([\n JoinModel.find(whereQuery, projection, {\n sort,\n ...(isPolymorphicJoin ? {} : { limit, skip }),\n }).lean(),\n isPolymorphicJoin ? Promise.resolve(0) : JoinModel.countDocuments(whereQuery),\n ])\n\n const count = isPolymorphicJoin ? results.length : dbCount\n\n transform({\n adapter,\n data: results,\n fields: useDrafts\n ? buildVersionCollectionFields(adapter.payload.config, targetConfig, false)\n : targetConfig.fields,\n operation: 'read',\n })\n\n // Return results with collection info for grouping\n return {\n collectionSlug: joinCollectionSlug,\n count,\n dbFieldName,\n results,\n sort,\n useDrafts,\n }\n })\n\n const collectionResults = await Promise.all(collectionPromises)\n\n // Group the results by parent ID\n const grouped: Record<\n string,\n {\n docs: Record<string, unknown>[]\n sort: Record<string, string>\n }\n > = {}\n\n let totalCount = 0\n for (const collectionResult of collectionResults) {\n if (!collectionResult) {\n continue\n }\n\n const { collectionSlug, count, dbFieldName, results, sort, useDrafts } = collectionResult\n\n totalCount += count\n\n for (const result of results) {\n if (useDrafts) {\n result.id = result.parent\n }\n\n const parentValues = getByPathWithArrays(result, dbFieldName) as (\n | { relationTo: string; value: number | string }\n | number\n | string\n )[]\n\n if (parentValues.length === 0) {\n continue\n }\n\n for (let parentValue of parentValues) {\n if (!parentValue) {\n continue\n }\n\n if (typeof parentValue === 'object') {\n parentValue = parentValue.value\n }\n\n const joinData = {\n relationTo: collectionSlug,\n value: result.id,\n }\n\n const parentKey = parentValue as string\n if (!grouped[parentKey]) {\n grouped[parentKey] = {\n docs: [],\n sort,\n }\n }\n\n // Always store the ObjectID reference in polymorphic format\n grouped[parentKey].docs.push({\n ...result,\n __joinData: joinData,\n })\n }\n }\n }\n\n for (const results of Object.values(grouped)) {\n results.docs.sort((a, b) => {\n for (const [fieldName, sortOrder] of Object.entries(results.sort)) {\n const sort = sortOrder === 'asc' ? 1 : -1\n const aValue = a[fieldName] as Date | number | string\n const bValue = b[fieldName] as Date | number | string\n if (aValue < bValue) {\n return -1 * sort\n }\n if (aValue > bValue) {\n return 1 * sort\n }\n }\n return 0\n })\n results.docs = results.docs.map(\n (doc) => (isPolymorphicJoin ? doc.__joinData : doc.id) as Record<string, unknown>,\n )\n }\n\n // Determine if the join field should be localized\n const localeSuffix =\n fieldShouldBeLocalized({\n field: joinDef.field,\n parentIsLocalized: joinDef.parentIsLocalized,\n }) &&\n adapter.payload.config.localization &&\n effectiveLocale\n ? `.${effectiveLocale}`\n : ''\n\n // Adjust the join path with locale suffix if needed\n const localizedJoinPath = `${joinPath}${localeSuffix}`\n\n return {\n grouped,\n isPolymorphicJoin,\n joinQuery,\n limit,\n localizedJoinPath,\n page,\n skip,\n totalCount,\n }\n })\n\n // Wait for all join operations to complete\n const joinResults = await Promise.all(joinPromises)\n\n // Process the results and attach them to documents\n for (const joinResult of joinResults) {\n if (!joinResult) {\n continue\n }\n\n const { grouped, isPolymorphicJoin, joinQuery, limit, localizedJoinPath, skip, totalCount } =\n joinResult\n\n // Attach the joined data to each parent document\n for (const doc of docs) {\n const id = (versions ? (doc.parent ?? doc._id ?? doc.id) : (doc._id ?? doc.id)) as string\n const all = grouped[id]?.docs || []\n\n // Calculate the slice for pagination\n // When limit is 0, it means unlimited - return all results\n const slice = isPolymorphicJoin\n ? limit === 0\n ? all\n : all.slice(skip, skip + limit)\n : // For non-polymorphic joins, we assume that page and limit were applied at the database level\n all\n\n // Create the join result object with pagination metadata\n const value: Record<string, unknown> = {\n docs: slice,\n hasNextPage: limit === 0 ? false : totalCount > skip + slice.length,\n }\n\n // Include total count if requested\n if (joinQuery.count) {\n value.totalDocs = totalCount\n }\n\n // Navigate to the correct nested location in the document and set the join data\n // This handles nested join paths like \"user.posts\" by creating intermediate objects\n const segments = localizedJoinPath.split('.')\n let ref: Record<string, unknown>\n if (versions) {\n if (!doc.version) {\n doc.version = {}\n }\n ref = doc.version as Record<string, unknown>\n } else {\n ref = doc\n }\n\n for (let i = 0; i < segments.length - 1; i++) {\n const seg = segments[i]!\n if (!ref[seg]) {\n ref[seg] = {}\n }\n ref = ref[seg] as Record<string, unknown>\n }\n // Set the final join data at the target path\n ref[segments[segments.length - 1]!] = value\n }\n }\n}\n\n/**\n * Extracts relationTo filter values from a WHERE clause\n * @param where - The WHERE clause to search\n * @returns Array of collection slugs if relationTo filter found, null otherwise\n */\nfunction extractRelationToFilter(where: Record<string, unknown>): null | string[] {\n if (!where || typeof where !== 'object') {\n return null\n }\n\n // Check for direct relationTo conditions\n if (where.relationTo && typeof where.relationTo === 'object') {\n const relationTo = where.relationTo as Record<string, unknown>\n if (relationTo.in && Array.isArray(relationTo.in)) {\n return relationTo.in as string[]\n }\n if (relationTo.equals) {\n return [relationTo.equals as string]\n }\n }\n\n // Check for relationTo in logical operators\n if (where.and && Array.isArray(where.and)) {\n for (const condition of where.and) {\n const result = extractRelationToFilter(condition)\n if (result) {\n return result\n }\n }\n }\n\n if (where.or && Array.isArray(where.or)) {\n for (const condition of where.or) {\n const result = extractRelationToFilter(condition)\n if (result) {\n return result\n }\n }\n }\n\n return null\n}\n\n/**\n * Filters a WHERE clause to only include fields that exist in the target collection\n * This is needed for polymorphic joins where different collections have different fields\n * @param where - The original WHERE clause\n * @param availableFields - The fields available in the target collection\n * @param excludeRelationTo - Whether to exclude relationTo field (for individual collections)\n * @returns A filtered WHERE clause, or null if the query cannot match this collection\n */\nfunction filterWhereForCollection(\n where: Record<string, unknown>,\n availableFields: Array<{ name: string }>,\n excludeRelationTo: boolean = false,\n): null | Record<string, unknown> {\n if (!where || typeof where !== 'object') {\n return where\n }\n\n const fieldNames = new Set(availableFields.map((f) => f.name))\n // Add special fields that are available in polymorphic relationships\n if (!excludeRelationTo) {\n fieldNames.add('relationTo')\n }\n\n const filtered: Record<string, unknown> = {}\n\n for (const [key, value] of Object.entries(where)) {\n if (key === 'and') {\n // Handle AND operator - all conditions must be satisfiable\n if (Array.isArray(value)) {\n const filteredConditions: Record<string, unknown>[] = []\n\n for (const condition of value) {\n const filteredCondition = filterWhereForCollection(\n condition,\n availableFields,\n excludeRelationTo,\n )\n\n // If any condition in AND cannot be satisfied, the whole AND fails\n if (filteredCondition === null) {\n return null\n }\n\n if (Object.keys(filteredCondition).length > 0) {\n filteredConditions.push(filteredCondition)\n }\n }\n\n if (filteredConditions.length > 0) {\n filtered[key] = filteredConditions\n }\n }\n } else if (key === 'or') {\n // Handle OR operator - at least one condition must be satisfiable\n if (Array.isArray(value)) {\n const filteredConditions = value\n .map((condition) =>\n filterWhereForCollection(condition, availableFields, excludeRelationTo),\n )\n .filter((condition) => condition !== null && Object.keys(condition).length > 0)\n\n if (filteredConditions.length > 0) {\n filtered[key] = filteredConditions\n }\n // If no OR conditions can be satisfied, we still continue (OR is more permissive)\n }\n } else if (key === 'relationTo' && excludeRelationTo) {\n // Skip relationTo field for non-polymorphic collections\n continue\n } else if (fieldNames.has(key)) {\n // Include the condition if the field exists in this collection\n filtered[key] = value\n } else {\n // Field doesn't exist in this collection - this makes the query unsatisfiable\n return null\n }\n }\n\n return filtered\n}\n\ntype SanitizedJoin = SanitizedJoins[string][number]\n\n/**\n * Builds projection for join queries\n */\nfunction buildJoinProjection(\n baseFieldName: string,\n useDrafts: boolean,\n sort: Record<string, string>,\n): Record<string, 1> {\n const projection: Record<string, 1> = {\n _id: 1,\n [baseFieldName]: 1,\n }\n\n if (useDrafts) {\n projection.parent = 1\n }\n\n for (const fieldName of Object.keys(sort)) {\n projection[fieldName] = 1\n }\n\n return projection\n}\n\n/**\n * Enhanced utility function to safely traverse nested object properties using dot notation\n * Handles arrays by searching through array elements for matching values\n * @param doc - The document to traverse\n * @param path - Dot-separated path (e.g., \"array.category\")\n * @returns Array of values found at the specified path (for arrays) or single value\n */\nfunction getByPathWithArrays(doc: unknown, path: string): unknown[] {\n const segments = path.split('.')\n let current = doc\n\n for (let i = 0; i < segments.length; i++) {\n const segment = segments[i]!\n\n if (current === undefined || current === null) {\n return []\n }\n\n // Get the value at the current segment\n const value = (current as Record<string, unknown>)[segment]\n\n if (value === undefined || value === null) {\n return []\n }\n\n // If this is the last segment, return the value(s)\n if (i === segments.length - 1) {\n return Array.isArray(value) ? value : [value]\n }\n\n // If the value is an array and we have more segments to traverse\n if (Array.isArray(value)) {\n const remainingPath = segments.slice(i + 1).join('.')\n const results: unknown[] = []\n\n // Search through each array element\n for (const item of value) {\n if (item && typeof item === 'object') {\n const subResults = getByPathWithArrays(item, remainingPath)\n results.push(...subResults)\n }\n }\n\n return results\n }\n\n // Continue traversing\n current = value\n }\n\n return []\n}\n"],"names":["appendVersionToQueryKey","buildVersionCollectionFields","combineQueries","getQueryDraftsSort","fieldShouldBeLocalized","buildQuery","buildSortParam","transform","resolveJoins","adapter","collectionSlug","docs","joins","locale","projection","versions","length","collectionConfig","payload","collections","config","joinMap","target","joinList","Object","entries","join","joinPath","targetCollection","polymorphicJoins","field","collection","joinPromises","map","joinQuery","joinDef","allCollections","Array","isArray","localizationConfig","localization","effectiveLocale","defaultLocale","relationToFilter","extractRelationToFilter","where","filter","col","includes","isPolymorphicJoin","limit","defaultLimit","page","skip","collectionPromises","joinCollectionSlug","targetConfig","useDrafts","Boolean","drafts","JoinModel","slug","parentIDs","d","parent","_id","id","whereQuery","filterWhereForCollection","flattenedFields","latest","equals","fields","dbFieldName","on","pathSegments","split","transformedSegments","i","segment","push","fieldAtSegment","find","f","name","localized","isPolymorphic","targetField","relationTo","$in","sort","defaultSort","timestamps","buildJoinProjection","results","dbCount","Promise","all","lean","resolve","countDocuments","count","data","operation","collectionResults","grouped","totalCount","collectionResult","result","parentValues","getByPathWithArrays","parentValue","value","joinData","parentKey","__joinData","values","a","b","fieldName","sortOrder","aValue","bValue","doc","localeSuffix","parentIsLocalized","localizedJoinPath","joinResults","joinResult","slice","hasNextPage","totalDocs","segments","ref","version","seg","in","and","condition","or","availableFields","excludeRelationTo","fieldNames","Set","add","filtered","key","filteredConditions","filteredCondition","keys","has","baseFieldName","path","current","undefined","remainingPath","item","subResults"],"mappings":"AAEA,SACEA,uBAAuB,EACvBC,4BAA4B,EAC5BC,cAAc,EACdC,kBAAkB,QACb,UAAS;AAChB,SAASC,sBAAsB,QAAQ,iBAAgB;AAIvD,SAASC,UAAU,QAAQ,2BAA0B;AACrD,SAASC,cAAc,QAAQ,+BAA8B;AAC7D,SAASC,SAAS,QAAQ,iBAAgB;AAmB1C;;;;CAIC,GACD,OAAO,eAAeC,aAAa,EACjCC,OAAO,EACPC,cAAc,EACdC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,UAAU,EACVC,WAAW,KAAK,EACC;IACjB,oEAAoE;IACpE,IAAI,CAACH,SAASD,KAAKK,MAAM,KAAK,GAAG;QAC/B;IACF;IAEA,oDAAoD;IACpD,MAAMC,mBAAmBR,QAAQS,OAAO,CAACC,WAAW,CAACT,eAAe,EAAEU;IACtE,IAAI,CAACH,kBAAkB;QACrB;IACF;IAEA,qEAAqE;IACrE,+EAA+E;IAC/E,MAAMI,UAAwE,CAAC;IAE/E,oBAAoB;IACpB,KAAK,MAAM,CAACC,QAAQC,SAAS,IAAIC,OAAOC,OAAO,CAACR,iBAAiBL,KAAK,EAAG;QACvE,KAAK,MAAMc,QAAQH,SAAU;YAC3BF,OAAO,CAACK,KAAKC,QAAQ,CAAC,GAAG;gBAAE,GAAGD,IAAI;gBAAEE,kBAAkBN;YAAO;QAC/D;IACF;IAEA,wBAAwB;IACxB,KAAK,MAAMI,QAAQT,iBAAiBY,gBAAgB,IAAI,EAAE,CAAE;QAC1D,oEAAoE;QACpER,OAAO,CAACK,KAAKC,QAAQ,CAAC,GAAG;YAAE,GAAGD,IAAI;YAAEE,kBAAkBF,KAAKI,KAAK,CAACC,UAAU;QAAW;IACxF;IAEA,2CAA2C;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Q;gBAACA;aAAM;QAC/C;QAEA,iEAAiE;QACjE,IAAI3E,MAAMC,OAAO,CAAC0E,QAAQ;YACxB,MAAM2C,gBAAgBvB,SAASH,KAAK,CAACnD,IAAI,GAAGpD,IAAI,CAAC;YACjD,MAAMoE,UAAqB,EAAE;YAE7B,oCAAoC;YACpC,KAAK,MAAM8D,QAAQ5C,MAAO;gBACxB,IAAI4C,QAAQ,OAAOA,SAAS,UAAU;oBACpC,MAAMC,aAAa/C,oBAAoB8C,MAAMD;oBAC7C7D,QAAQd,IAAI,IAAI6E;gBAClB;YACF;YAEA,OAAO/D;QACT;QAEA,sBAAsB;QACtB2D,UAAUzC;IACZ;IAEA,OAAO,EAAE;AACX"}
1
+ {"version":3,"sources":["../../src/utilities/resolveJoins.ts"],"sourcesContent":["import type { JoinQuery, SanitizedJoins, Where } from 'payload'\n\nimport {\n appendVersionToQueryKey,\n buildVersionCollectionFields,\n combineQueries,\n getQueryDraftsSort,\n} from 'payload'\nimport { fieldShouldBeLocalized } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { buildQuery } from '../queries/buildQuery.js'\nimport { buildSortParam } from '../queries/buildSortParam.js'\nimport { transform } from './transform.js'\n\nexport type ResolveJoinsArgs = {\n /** The MongoDB adapter instance */\n adapter: MongooseAdapter\n /** The slug of the collection being queried */\n collectionSlug: string\n /** Array of documents to resolve joins for */\n docs: Record<string, unknown>[]\n /** Join query specifications (which joins to resolve and how) */\n joins?: JoinQuery\n /** Optional locale for localized queries */\n locale?: string\n /** Optional projection for the join query */\n projection?: Record<string, true>\n /** Whether to resolve versions instead of published documents */\n versions?: boolean\n}\n\n/**\n * Resolves join relationships for a collection of documents.\n * This function fetches related documents based on join configurations and\n * attaches them to the original documents with pagination support.\n */\nexport async function resolveJoins({\n adapter,\n collectionSlug,\n docs,\n joins,\n locale,\n projection,\n versions = false,\n}: ResolveJoinsArgs): Promise<void> {\n // Early return if no joins are specified or no documents to process\n if (!joins || docs.length === 0) {\n return\n }\n\n // Get the collection configuration from the adapter\n const collectionConfig = adapter.payload.collections[collectionSlug]?.config\n if (!collectionConfig) {\n return\n }\n\n // Build a map of join paths to their configurations for quick lookup\n // This flattens the nested join structure into a single map keyed by join path\n const joinMap: Record<string, { targetCollection: string } & SanitizedJoin> = {}\n\n // Add regular joins\n for (const [target, joinList] of Object.entries(collectionConfig.joins)) {\n for (const join of joinList) {\n joinMap[join.joinPath] = { ...join, targetCollection: target }\n }\n }\n\n // Add polymorphic joins\n for (const join of collectionConfig.polymorphicJoins || []) {\n // For polymorphic joins, we use the collections array as the target\n joinMap[join.joinPath] = { ...join, targetCollection: join.field.collection as string }\n }\n\n // Process each requested join concurrently\n const joinPromises = Object.entries(joins).map(async ([joinPath, joinQuery]) => {\n if (!joinQuery) {\n return null\n }\n\n // If a projection is provided, and the join path is not in the projection, skip it\n if (projection && !projection[joinPath]) {\n return null\n }\n\n // Get the join definition from our map\n const joinDef = joinMap[joinPath]\n if (!joinDef) {\n return null\n }\n\n // Normalize collections to always be an array for unified processing\n const allCollections = Array.isArray(joinDef.field.collection)\n ? joinDef.field.collection\n : [joinDef.field.collection]\n\n // Use the provided locale or fall back to the default locale for localized fields\n const localizationConfig = adapter.payload.config.localization\n const effectiveLocale =\n locale ||\n (typeof localizationConfig === 'object' &&\n localizationConfig &&\n localizationConfig.defaultLocale)\n\n // Extract relationTo filter from the where clause to determine which collections to query\n const relationToFilter = extractRelationToFilter(joinQuery.where || {})\n\n // Determine which collections to query based on relationTo filter\n const collections = relationToFilter\n ? allCollections.filter((col) => relationToFilter.includes(col))\n : allCollections\n\n // Check if this is a polymorphic collection join (where field.collection is an array)\n const isPolymorphicJoin = Array.isArray(joinDef.field.collection)\n\n // Apply pagination settings\n const limit = joinQuery.limit ?? joinDef.field.defaultLimit ?? 10\n const page = joinQuery.page ?? 1\n const skip = (page - 1) * limit\n\n // Process collections concurrently\n const collectionPromises = collections.map(async (joinCollectionSlug) => {\n const targetConfig = adapter.payload.collections[joinCollectionSlug]?.config\n if (!targetConfig) {\n return null\n }\n\n const useDrafts = versions && Boolean(targetConfig.versions?.drafts)\n let JoinModel\n if (useDrafts) {\n JoinModel = adapter.versions[targetConfig.slug]\n } else {\n JoinModel = adapter.collections[targetConfig.slug]\n }\n\n if (!JoinModel) {\n return null\n }\n\n // Extract all parent document IDs to use in the join query\n const parentIDs = docs.map((d) => (versions ? (d.parent ?? d._id ?? d.id) : (d._id ?? d.id)))\n\n // Build the base query\n let whereQuery: null | Record<string, unknown> = null\n whereQuery = isPolymorphicJoin\n ? filterWhereForCollection(\n joinQuery.where || {},\n targetConfig.flattenedFields,\n true, // exclude relationTo for individual collections\n )\n : joinQuery.where || {}\n\n // Skip this collection if the WHERE clause cannot be satisfied for polymorphic collection joins\n if (whereQuery === null) {\n return null\n }\n whereQuery = useDrafts\n ? await JoinModel.buildQuery({\n locale,\n payload: adapter.payload,\n where: combineQueries(appendVersionToQueryKey(whereQuery as Where), {\n latest: {\n equals: true,\n },\n }),\n })\n : await buildQuery({\n adapter,\n collectionSlug: joinCollectionSlug,\n fields: targetConfig.flattenedFields,\n locale,\n where: whereQuery as Where,\n })\n\n // Handle localized paths and version prefixes\n let dbFieldName = joinDef.field.on\n\n if (effectiveLocale && typeof localizationConfig === 'object' && localizationConfig) {\n const pathSegments = joinDef.field.on.split('.')\n const transformedSegments: string[] = []\n const fields = useDrafts\n ? buildVersionCollectionFields(adapter.payload.config, targetConfig, true)\n : targetConfig.flattenedFields\n\n for (let i = 0; i < pathSegments.length; i++) {\n const segment = pathSegments[i]!\n transformedSegments.push(segment)\n\n // Check if this segment corresponds to a localized field\n const fieldAtSegment = fields.find((f) => f.name === segment)\n if (fieldAtSegment && fieldAtSegment.localized) {\n transformedSegments.push(effectiveLocale)\n }\n }\n\n dbFieldName = transformedSegments.join('.')\n }\n\n // Add version prefix for draft queries\n if (useDrafts) {\n dbFieldName = `version.${dbFieldName}`\n }\n\n // Check if the target field is a polymorphic relationship\n const isPolymorphic = joinDef.targetField\n ? Array.isArray(joinDef.targetField.relationTo)\n : false\n\n if (isPolymorphic) {\n // For polymorphic relationships, we need to match both relationTo and value\n whereQuery[`${dbFieldName}.relationTo`] = collectionSlug\n whereQuery[`${dbFieldName}.value`] = { $in: parentIDs }\n } else {\n // For regular relationships and polymorphic collection joins\n whereQuery[dbFieldName] = { $in: parentIDs }\n }\n\n // Build the sort parameters for the query\n const fields = useDrafts\n ? buildVersionCollectionFields(adapter.payload.config, targetConfig, true)\n : targetConfig.flattenedFields\n\n const sort = buildSortParam({\n adapter,\n config: adapter.payload.config,\n fields,\n locale,\n sort: useDrafts\n ? getQueryDraftsSort({\n collectionConfig: targetConfig,\n sort: joinQuery.sort || joinDef.field.defaultSort || targetConfig.defaultSort,\n })\n : joinQuery.sort || joinDef.field.defaultSort || targetConfig.defaultSort,\n timestamps: true,\n })\n\n const projection = buildJoinProjection(dbFieldName, useDrafts, sort)\n\n const [results, dbCount] = await Promise.all([\n JoinModel.find(whereQuery, projection, {\n sort,\n ...(isPolymorphicJoin ? {} : { limit, skip }),\n }).lean(),\n isPolymorphicJoin ? Promise.resolve(0) : JoinModel.countDocuments(whereQuery),\n ])\n\n const count = isPolymorphicJoin ? results.length : dbCount\n\n transform({\n adapter,\n data: results,\n fields: useDrafts\n ? buildVersionCollectionFields(adapter.payload.config, targetConfig, false)\n : targetConfig.fields,\n operation: 'read',\n })\n\n // Return results with collection info for grouping\n return {\n collectionSlug: joinCollectionSlug,\n count,\n dbFieldName,\n results,\n sort,\n useDrafts,\n }\n })\n\n const collectionResults = await Promise.all(collectionPromises)\n\n // Group the results by parent ID\n const grouped: Record<\n string,\n {\n docs: Record<string, unknown>[]\n sort: Record<string, string>\n }\n > = {}\n\n let totalCount = 0\n for (const collectionResult of collectionResults) {\n if (!collectionResult) {\n continue\n }\n\n const { collectionSlug, count, dbFieldName, results, sort, useDrafts } = collectionResult\n\n totalCount += count\n\n for (const result of results) {\n if (useDrafts) {\n result.id = result.parent\n }\n\n const parentValues = getByPathWithArrays(result, dbFieldName) as (\n | { relationTo: string; value: number | string }\n | number\n | string\n )[]\n\n if (parentValues.length === 0) {\n continue\n }\n\n for (let parentValue of parentValues) {\n if (!parentValue) {\n continue\n }\n\n if (typeof parentValue === 'object') {\n parentValue = parentValue.value\n }\n\n const joinData = {\n relationTo: collectionSlug,\n value: result.id,\n }\n\n const parentKey = parentValue as string\n if (!grouped[parentKey]) {\n grouped[parentKey] = {\n docs: [],\n sort,\n }\n }\n\n // Always store the ObjectID reference in polymorphic format\n grouped[parentKey].docs.push({\n ...result,\n __joinData: joinData,\n })\n }\n }\n }\n\n for (const results of Object.values(grouped)) {\n results.docs.sort((a, b) => {\n for (const [fieldName, sortOrder] of Object.entries(results.sort)) {\n const sort = sortOrder === 'asc' ? 1 : -1\n const aValue = a[fieldName] as Date | number | string\n const bValue = b[fieldName] as Date | number | string\n if (aValue < bValue) {\n return -1 * sort\n }\n if (aValue > bValue) {\n return 1 * sort\n }\n }\n return 0\n })\n results.docs = results.docs.map(\n (doc) => (isPolymorphicJoin ? doc.__joinData : doc.id) as Record<string, unknown>,\n )\n }\n\n // Determine if the join field should be localized\n const localeSuffix =\n fieldShouldBeLocalized({\n field: joinDef.field,\n parentIsLocalized: joinDef.parentIsLocalized,\n }) &&\n adapter.payload.config.localization &&\n effectiveLocale\n ? `.${effectiveLocale}`\n : ''\n\n // Adjust the join path with locale suffix if needed\n const localizedJoinPath = `${joinPath}${localeSuffix}`\n\n return {\n grouped,\n isPolymorphicJoin,\n joinQuery,\n limit,\n localizedJoinPath,\n page,\n skip,\n totalCount,\n }\n })\n\n // Wait for all join operations to complete\n const joinResults = await Promise.all(joinPromises)\n\n // Process the results and attach them to documents\n for (const joinResult of joinResults) {\n if (!joinResult) {\n continue\n }\n\n const { grouped, isPolymorphicJoin, joinQuery, limit, localizedJoinPath, skip, totalCount } =\n joinResult\n\n // Attach the joined data to each parent document\n for (const doc of docs) {\n const id = (versions ? (doc.parent ?? doc._id ?? doc.id) : (doc._id ?? doc.id)) as string\n const all = grouped[id]?.docs || []\n\n // Calculate the slice for pagination\n // When limit is 0, it means unlimited - return all results\n const slice = isPolymorphicJoin\n ? limit === 0\n ? all\n : all.slice(skip, skip + limit)\n : // For non-polymorphic joins, we assume that page and limit were applied at the database level\n all\n\n // Create the join result object with pagination metadata\n const value: Record<string, unknown> = {\n docs: slice,\n hasNextPage: limit === 0 ? false : totalCount > skip + slice.length,\n }\n\n // Include total count if requested\n if (joinQuery.count) {\n value.totalDocs = totalCount\n }\n\n // Navigate to the correct nested location in the document and set the join data\n // This handles nested join paths like \"user.posts\" by creating intermediate objects\n const segments = localizedJoinPath.split('.')\n let ref: Record<string, unknown>\n if (versions) {\n if (!doc.version) {\n doc.version = {}\n }\n ref = doc.version as Record<string, unknown>\n } else {\n ref = doc\n }\n\n for (let i = 0; i < segments.length - 1; i++) {\n const seg = segments[i]!\n if (!ref[seg]) {\n ref[seg] = {}\n }\n ref = ref[seg] as Record<string, unknown>\n }\n // Set the final join data at the target path\n ref[segments[segments.length - 1]!] = value\n }\n }\n}\n\n/**\n * Extracts relationTo filter values from a WHERE clause\n *\n * @purpose When you have a polymorphic join field that can reference multiple collection types (e.g. the documentsAndFolders join field on\n * folders that points to all folder-enabled collections), Payload needs to decide which collections to actually query. Without filtering,\n * it would query ALL possible collections even when the WHERE clause clearly indicates it only needs specific ones.\n *\n * extractRelationToFilter analyzes the WHERE clause to extract relationTo conditions and returns only the collection slugs that\n * could possibly match, avoiding unnecessary database queries.\n *\n * @description The function recursively traverses a WHERE clause looking for relationTo conditions in these patterns:\n *\n * 1. Direct conditions: { relationTo: { equals: 'posts' } }\n * 2. IN conditions: { relationTo: { in: ['posts', 'media'] } }\n * 3. Nested in AND/OR: Recursively searches through logical operators\n\n * @param where - The WHERE clause to search\n * @returns Array of collection slugs if relationTo filter found, null otherwise\n */\nfunction extractRelationToFilter(where: Record<string, unknown>): null | string[] {\n if (!where || typeof where !== 'object') {\n return null\n }\n\n // Check for direct relationTo conditions\n if (where.relationTo && typeof where.relationTo === 'object') {\n const relationTo = where.relationTo as Record<string, unknown>\n if (relationTo.in && Array.isArray(relationTo.in)) {\n return relationTo.in as string[]\n }\n if (relationTo.equals) {\n return [relationTo.equals as string]\n }\n }\n\n // Check for relationTo in logical operators\n if (where.and && Array.isArray(where.and)) {\n const allResults: string[] = []\n for (const condition of where.and) {\n const result = extractRelationToFilter(condition)\n if (result) {\n allResults.push(...result)\n }\n }\n if (allResults.length > 0) {\n return [...new Set(allResults)] // Remove duplicates\n }\n }\n\n if (where.or && Array.isArray(where.or)) {\n const allResults: string[] = []\n for (const condition of where.or) {\n const result = extractRelationToFilter(condition)\n if (result) {\n allResults.push(...result)\n }\n }\n if (allResults.length > 0) {\n return [...new Set(allResults)] // Remove duplicates\n }\n }\n\n return null\n}\n\n/**\n * Filters a WHERE clause to only include fields that exist in the target collection\n * This is needed for polymorphic joins where different collections have different fields\n * @param where - The original WHERE clause\n * @param availableFields - The fields available in the target collection\n * @param excludeRelationTo - Whether to exclude relationTo field (for individual collections)\n * @returns A filtered WHERE clause, or null if the query cannot match this collection\n */\nfunction filterWhereForCollection(\n where: Record<string, unknown>,\n availableFields: Array<{ name: string }>,\n excludeRelationTo: boolean = false,\n): null | Record<string, unknown> {\n if (!where || typeof where !== 'object') {\n return where\n }\n\n const fieldNames = new Set(availableFields.map((f) => f.name))\n // Add special fields that are available in polymorphic relationships\n if (!excludeRelationTo) {\n fieldNames.add('relationTo')\n }\n\n const filtered: Record<string, unknown> = {}\n\n for (const [key, value] of Object.entries(where)) {\n if (key === 'and') {\n // Handle AND operator - all conditions must be satisfiable\n if (Array.isArray(value)) {\n const filteredConditions: Record<string, unknown>[] = []\n\n for (const condition of value) {\n const filteredCondition = filterWhereForCollection(\n condition,\n availableFields,\n excludeRelationTo,\n )\n\n // If any condition in AND cannot be satisfied, the whole AND fails\n if (filteredCondition === null) {\n return null\n }\n\n if (Object.keys(filteredCondition).length > 0) {\n filteredConditions.push(filteredCondition)\n }\n }\n\n if (filteredConditions.length > 0) {\n filtered[key] = filteredConditions\n }\n }\n } else if (key === 'or') {\n // Handle OR operator - at least one condition must be satisfiable\n if (Array.isArray(value)) {\n const filteredConditions = value\n .map((condition) =>\n filterWhereForCollection(condition, availableFields, excludeRelationTo),\n )\n .filter((condition) => condition !== null && Object.keys(condition).length > 0)\n\n if (filteredConditions.length > 0) {\n filtered[key] = filteredConditions\n }\n // If no OR conditions can be satisfied, we still continue (OR is more permissive)\n }\n } else if (key === 'relationTo' && excludeRelationTo) {\n // Skip relationTo field for non-polymorphic collections\n continue\n } else if (fieldNames.has(key)) {\n // Include the condition if the field exists in this collection\n filtered[key] = value\n } else {\n // Field doesn't exist in this collection - this makes the query unsatisfiable\n return null\n }\n }\n\n return filtered\n}\n\ntype SanitizedJoin = SanitizedJoins[string][number]\n\n/**\n * Builds projection for join queries\n */\nfunction buildJoinProjection(\n baseFieldName: string,\n useDrafts: boolean,\n sort: Record<string, string>,\n): Record<string, 1> {\n const projection: Record<string, 1> = {\n _id: 1,\n [baseFieldName]: 1,\n }\n\n if (useDrafts) {\n projection.parent = 1\n }\n\n for (const fieldName of Object.keys(sort)) {\n projection[fieldName] = 1\n }\n\n return projection\n}\n\n/**\n * Enhanced utility function to safely traverse nested object properties using dot notation\n * Handles arrays by searching through array elements for matching values\n * @param doc - The document to traverse\n * @param path - Dot-separated path (e.g., \"array.category\")\n * @returns Array of values found at the specified path (for arrays) or single value\n */\nfunction getByPathWithArrays(doc: unknown, path: string): unknown[] {\n const segments = path.split('.')\n let current = doc\n\n for (let i = 0; i < segments.length; i++) {\n const segment = segments[i]!\n\n if (current === undefined || current === null) {\n return []\n }\n\n // Get the value at the current segment\n const value = (current as Record<string, unknown>)[segment]\n\n if (value === undefined || value === null) {\n return []\n }\n\n // If this is the last segment, return the value(s)\n if (i === segments.length - 1) {\n return Array.isArray(value) ? value : [value]\n }\n\n // If the value is an array and we have more segments to traverse\n if (Array.isArray(value)) {\n const remainingPath = segments.slice(i + 1).join('.')\n const results: unknown[] = []\n\n // Search through each array element\n for (const item of value) {\n if (item && typeof item === 'object') {\n const subResults = getByPathWithArrays(item, remainingPath)\n results.push(...subResults)\n }\n }\n\n return results\n }\n\n // Continue traversing\n current = value\n }\n\n return []\n}\n"],"names":["appendVersionToQueryKey","buildVersionCollectionFields","combineQueries","getQueryDraftsSort","fieldShouldBeLocalized","buildQuery","buildSortParam","transform","resolveJoins","adapter","collectionSlug","docs","joins","locale","projection","versions","length","collectionConfig","payload","collections","config","joinMap","target","joinList","Object","entries","join","joinPath","targetCollection","polymorphicJoins","field","collection","joinPromises","map","joinQuery","joinDef","allCollections","Array","isArray","localizationConfig","localization","effectiveLocale","defaultLocale","relationToFilter","extractRelationToFilter","where","filter","col","includes","isPolymorphicJoin","limit","defaultLimit","page","skip","collectionPromises","joinCollectionSlug","targetConfig","useDrafts","Boolean","drafts","JoinModel","slug","parentIDs","d","parent","_id","id","whereQuery","filterWhereForCollection","flattenedFields","latest","equals","fields","dbFieldName","on","pathSegments","split","transformedSegments","i","segment","push","fieldAtSegment","find","f","name","localized","isPolymorphic","targetField","relationTo","$in","sort","defaultSort","timestamps","buildJoinProjection","results","dbCount","Promise","all","lean","resolve","countDocuments","count","data","operation","collectionResults","grouped","totalCount","collectionResult","result","parentValues","getByPathWithArrays","parentValue","value","joinData","parentKey","__joinData","values","a","b","fieldName","sortOrder","aValue","bValue","doc","localeSuffix","parentIsLocalized","localizedJoinPath","joinResults","joinResult","slice","hasNextPage","totalDocs","segments","ref","version","seg","in","and","allResults","condition","Set","or","availableFields","excludeRelationTo","fieldNames","add","filtered","key","filteredConditions","filteredCondition","keys","has","baseFieldName","path","current","undefined","remainingPath","item","subResults"],"mappings":"AAEA,SACEA,uBAAuB,EACvBC,4BAA4B,EAC5BC,cAAc,EACdC,kBAAkB,QACb,UAAS;AAChB,SAASC,sBAAsB,QAAQ,iBAAgB;AAIvD,SAASC,UAAU,QAAQ,2BAA0B;AACrD,SAASC,cAAc,QAA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;aAAM;QAC/C;QAEA,iEAAiE;QACjE,IAAI3E,MAAMC,OAAO,CAAC0E,QAAQ;YACxB,MAAM4C,gBAAgBxB,SAASH,KAAK,CAACnD,IAAI,GAAGpD,IAAI,CAAC;YACjD,MAAMoE,UAAqB,EAAE;YAE7B,oCAAoC;YACpC,KAAK,MAAM+D,QAAQ7C,MAAO;gBACxB,IAAI6C,QAAQ,OAAOA,SAAS,UAAU;oBACpC,MAAMC,aAAahD,oBAAoB+C,MAAMD;oBAC7C9D,QAAQd,IAAI,IAAI8E;gBAClB;YACF;YAEA,OAAOhE;QACT;QAEA,sBAAsB;QACtB4D,UAAU1C;IACZ;IAEA,OAAO,EAAE;AACX"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/db-mongodb",
3
- "version": "3.60.0-canary.11",
3
+ "version": "3.60.0-canary.12",
4
4
  "description": "The officially supported MongoDB database adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -49,11 +49,11 @@
49
49
  "@types/uuid": "10.0.0",
50
50
  "mongodb": "6.16.0",
51
51
  "mongodb-memory-server": "10.1.4",
52
- "payload": "3.60.0-canary.11",
53
- "@payloadcms/eslint-config": "3.28.0"
52
+ "@payloadcms/eslint-config": "3.28.0",
53
+ "payload": "3.60.0-canary.12"
54
54
  },
55
55
  "peerDependencies": {
56
- "payload": "3.60.0-canary.11"
56
+ "payload": "3.60.0-canary.12"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "pnpm build:types && pnpm build:swc",