{"version":3,"file":"query.mjs","sources":["../../../../src/services/document-service/transform/query.ts"],"sourcesContent":["import type { UID } from '@strapi/types';\n\nimport { curry, assoc } from 'lodash/fp';\nimport { parseHasPublishedVersion, getHasPublishedVersionCondition } from '../draft-and-publish';\n\nimport { pickAllowedQueryParams } from '../params';\n\nconst transformParamsToQuery = curry((uid: UID.Schema, params: any) => {\n  const allowlisted = pickAllowedQueryParams(params ?? {});\n  const query = strapi.get('query-params').transform(uid, allowlisted);\n\n  // Parse and validate hasPublishedVersion if provided (from allowlisted params only)\n  const hasPublishedVersion = parseHasPublishedVersion(allowlisted?.hasPublishedVersion);\n\n  // If hasPublishedVersion is set, wrap the existing filters function to also\n  // apply the hasPublishedVersion condition. This ensures the condition is\n  // applied to both root and nested (populate) queries.\n  if (hasPublishedVersion !== undefined) {\n    const existingFilters = query.filters;\n\n    query.filters = ({ meta, ...rest }: { meta: { uid: UID.Schema } }) => {\n      // Get the existing filters result (from status param)\n      let existingResult = {};\n      if (typeof existingFilters === 'function') {\n        existingResult = existingFilters({ meta, ...rest }) || {};\n      } else if (existingFilters) {\n        existingResult = existingFilters;\n      }\n\n      // Get the hasPublishedVersion condition for this specific model\n      const hasPublishedCondition = getHasPublishedVersionCondition(meta.uid, hasPublishedVersion);\n\n      // Merge both conditions\n      if (hasPublishedCondition) {\n        const conditions = [existingResult, hasPublishedCondition].filter(\n          (c) => Object.keys(c).length\n        );\n        return { $and: conditions };\n      }\n\n      return existingResult;\n    };\n  }\n\n  return assoc('where', { ...params?.lookup, ...query.where }, query);\n});\n\nexport { transformParamsToQuery };\n"],"names":["transformParamsToQuery","curry","uid","params","allowlisted","pickAllowedQueryParams","query","strapi","get","transform","hasPublishedVersion","parseHasPublishedVersion","undefined","existingFilters","filters","meta","rest","existingResult","hasPublishedCondition","getHasPublishedVersionCondition","conditions","filter","c","Object","keys","length","$and","assoc","lookup","where"],"mappings":";;;;AAOA,MAAMA,sBAAAA,GAAyBC,KAAAA,CAAM,CAACC,GAAAA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