@payloadcms/db-mongodb 3.0.0-canary.f6e77b8 → 3.0.0-canary.fb04843

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. package/README.md +1 -1
  2. package/dist/connect.d.ts +1 -1
  3. package/dist/connect.d.ts.map +1 -1
  4. package/dist/connect.js +18 -4
  5. package/dist/connect.js.map +1 -1
  6. package/dist/count.d.ts +1 -1
  7. package/dist/count.d.ts.map +1 -1
  8. package/dist/count.js +10 -3
  9. package/dist/count.js.map +1 -1
  10. package/dist/countGlobalVersions.d.ts +3 -0
  11. package/dist/countGlobalVersions.d.ts.map +1 -0
  12. package/dist/countGlobalVersions.js +40 -0
  13. package/dist/countGlobalVersions.js.map +1 -0
  14. package/dist/countVersions.d.ts +3 -0
  15. package/dist/countVersions.d.ts.map +1 -0
  16. package/dist/countVersions.js +40 -0
  17. package/dist/countVersions.js.map +1 -0
  18. package/dist/create.d.ts +1 -1
  19. package/dist/create.d.ts.map +1 -1
  20. package/dist/create.js +17 -4
  21. package/dist/create.js.map +1 -1
  22. package/dist/createGlobal.d.ts +1 -1
  23. package/dist/createGlobal.d.ts.map +1 -1
  24. package/dist/createGlobal.js +11 -6
  25. package/dist/createGlobal.js.map +1 -1
  26. package/dist/createGlobalVersion.d.ts +1 -1
  27. package/dist/createGlobalVersion.d.ts.map +1 -1
  28. package/dist/createGlobalVersion.js +14 -5
  29. package/dist/createGlobalVersion.js.map +1 -1
  30. package/dist/createMigration.d.ts +1 -1
  31. package/dist/createMigration.d.ts.map +1 -1
  32. package/dist/createMigration.js +20 -32
  33. package/dist/createMigration.js.map +1 -1
  34. package/dist/createVersion.d.ts +1 -1
  35. package/dist/createVersion.d.ts.map +1 -1
  36. package/dist/createVersion.js +32 -10
  37. package/dist/createVersion.js.map +1 -1
  38. package/dist/deleteMany.d.ts +1 -1
  39. package/dist/deleteMany.d.ts.map +1 -1
  40. package/dist/deleteMany.js +1 -1
  41. package/dist/deleteMany.js.map +1 -1
  42. package/dist/deleteOne.d.ts +1 -1
  43. package/dist/deleteOne.d.ts.map +1 -1
  44. package/dist/deleteOne.js +12 -4
  45. package/dist/deleteOne.js.map +1 -1
  46. package/dist/deleteVersions.d.ts +1 -1
  47. package/dist/deleteVersions.d.ts.map +1 -1
  48. package/dist/deleteVersions.js +1 -1
  49. package/dist/deleteVersions.js.map +1 -1
  50. package/dist/destroy.d.ts +1 -1
  51. package/dist/destroy.d.ts.map +1 -1
  52. package/dist/destroy.js.map +1 -1
  53. package/dist/exports/migration-utils.d.ts +3 -0
  54. package/dist/exports/migration-utils.d.ts.map +1 -0
  55. package/dist/exports/migration-utils.js +4 -0
  56. package/dist/exports/migration-utils.js.map +1 -0
  57. package/dist/find.d.ts +1 -1
  58. package/dist/find.d.ts.map +1 -1
  59. package/dist/find.js +36 -7
  60. package/dist/find.js.map +1 -1
  61. package/dist/findGlobal.d.ts +1 -1
  62. package/dist/findGlobal.d.ts.map +1 -1
  63. package/dist/findGlobal.js +11 -5
  64. package/dist/findGlobal.js.map +1 -1
  65. package/dist/findGlobalVersions.d.ts +1 -1
  66. package/dist/findGlobalVersions.d.ts.map +1 -1
  67. package/dist/findGlobalVersions.js +19 -9
  68. package/dist/findGlobalVersions.js.map +1 -1
  69. package/dist/findOne.d.ts +1 -1
  70. package/dist/findOne.d.ts.map +1 -1
  71. package/dist/findOne.js +28 -4
  72. package/dist/findOne.js.map +1 -1
  73. package/dist/findVersions.d.ts +1 -1
  74. package/dist/findVersions.d.ts.map +1 -1
  75. package/dist/findVersions.js +17 -6
  76. package/dist/findVersions.js.map +1 -1
  77. package/dist/index.d.ts +59 -35
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +18 -7
  80. package/dist/index.js.map +1 -1
  81. package/dist/init.d.ts +1 -1
  82. package/dist/init.d.ts.map +1 -1
  83. package/dist/init.js +19 -17
  84. package/dist/init.js.map +1 -1
  85. package/dist/migrateFresh.d.ts.map +1 -1
  86. package/dist/migrateFresh.js +1 -1
  87. package/dist/migrateFresh.js.map +1 -1
  88. package/dist/models/buildCollectionSchema.d.ts +2 -29
  89. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  90. package/dist/models/buildCollectionSchema.js +16 -4
  91. package/dist/models/buildCollectionSchema.js.map +1 -1
  92. package/dist/models/buildGlobalModel.d.ts +1 -1
  93. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  94. package/dist/models/buildGlobalModel.js +2 -2
  95. package/dist/models/buildGlobalModel.js.map +1 -1
  96. package/dist/models/buildSchema.d.ts +2 -29
  97. package/dist/models/buildSchema.d.ts.map +1 -1
  98. package/dist/models/buildSchema.js +116 -23
  99. package/dist/models/buildSchema.js.map +1 -1
  100. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts +6 -0
  101. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -0
  102. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +141 -0
  103. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -0
  104. package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts +5 -0
  105. package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts.map +1 -0
  106. package/dist/predefinedMigrations/migrateVersionsV1_V2.js +107 -0
  107. package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -0
  108. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  109. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  110. package/dist/predefinedMigrations/relationships-v2-v3.js +9 -0
  111. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  112. package/dist/predefinedMigrations/versions-v1-v2.d.ts +4 -0
  113. package/dist/predefinedMigrations/versions-v1-v2.d.ts.map +1 -0
  114. package/dist/predefinedMigrations/versions-v1-v2.js +8 -0
  115. package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -0
  116. package/dist/queries/buildAndOrConditions.d.ts +1 -2
  117. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  118. package/dist/queries/buildAndOrConditions.js +0 -2
  119. package/dist/queries/buildAndOrConditions.js.map +1 -1
  120. package/dist/queries/buildQuery.d.ts +3 -4
  121. package/dist/queries/buildQuery.d.ts.map +1 -1
  122. package/dist/queries/buildQuery.js +2 -3
  123. package/dist/queries/buildQuery.js.map +1 -1
  124. package/dist/queries/buildSearchParams.d.ts +1 -2
  125. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  126. package/dist/queries/buildSearchParams.js +34 -22
  127. package/dist/queries/buildSearchParams.js.map +1 -1
  128. package/dist/queries/buildSortParam.d.ts +3 -29
  129. package/dist/queries/buildSortParam.d.ts.map +1 -1
  130. package/dist/queries/buildSortParam.js +26 -17
  131. package/dist/queries/buildSortParam.js.map +1 -1
  132. package/dist/queries/getLocalizedSortProperty.d.ts +1 -2
  133. package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
  134. package/dist/queries/getLocalizedSortProperty.js +2 -2
  135. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  136. package/dist/queries/getLocalizedSortProperty.spec.js +44 -44
  137. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  138. package/dist/queries/mock.js.map +1 -1
  139. package/dist/queries/operatorMap.js.map +1 -1
  140. package/dist/queries/parseParams.d.ts +1 -3
  141. package/dist/queries/parseParams.d.ts.map +1 -1
  142. package/dist/queries/parseParams.js +8 -6
  143. package/dist/queries/parseParams.js.map +1 -1
  144. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  145. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  146. package/dist/queries/sanitizeQueryValue.js +145 -28
  147. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  148. package/dist/queryDrafts.d.ts +1 -1
  149. package/dist/queryDrafts.d.ts.map +1 -1
  150. package/dist/queryDrafts.js +37 -10
  151. package/dist/queryDrafts.js.map +1 -1
  152. package/dist/testCredentials.js.map +1 -1
  153. package/dist/transactions/beginTransaction.d.ts +1 -1
  154. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  155. package/dist/transactions/beginTransaction.js +3 -1
  156. package/dist/transactions/beginTransaction.js.map +1 -1
  157. package/dist/transactions/commitTransaction.d.ts +1 -1
  158. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  159. package/dist/transactions/commitTransaction.js +3 -0
  160. package/dist/transactions/commitTransaction.js.map +1 -1
  161. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  162. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  163. package/dist/transactions/rollbackTransaction.js +13 -7
  164. package/dist/transactions/rollbackTransaction.js.map +1 -1
  165. package/dist/types.d.ts +7 -31
  166. package/dist/types.d.ts.map +1 -1
  167. package/dist/types.js.map +1 -1
  168. package/dist/updateGlobal.d.ts +1 -1
  169. package/dist/updateGlobal.d.ts.map +1 -1
  170. package/dist/updateGlobal.js +18 -5
  171. package/dist/updateGlobal.js.map +1 -1
  172. package/dist/updateGlobalVersion.d.ts +2 -3
  173. package/dist/updateGlobalVersion.d.ts.map +1 -1
  174. package/dist/updateGlobalVersion.js +19 -5
  175. package/dist/updateGlobalVersion.js.map +1 -1
  176. package/dist/updateOne.d.ts +1 -1
  177. package/dist/updateOne.d.ts.map +1 -1
  178. package/dist/updateOne.js +25 -7
  179. package/dist/updateOne.js.map +1 -1
  180. package/dist/updateVersion.d.ts +1 -1
  181. package/dist/updateVersion.d.ts.map +1 -1
  182. package/dist/updateVersion.js +18 -4
  183. package/dist/updateVersion.js.map +1 -1
  184. package/dist/upsert.d.ts +3 -0
  185. package/dist/upsert.d.ts.map +1 -0
  186. package/dist/upsert.js +15 -0
  187. package/dist/upsert.js.map +1 -0
  188. package/dist/utilities/buildJoinAggregation.d.ts +18 -0
  189. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
  190. package/dist/utilities/buildJoinAggregation.js +159 -0
  191. package/dist/utilities/buildJoinAggregation.js.map +1 -0
  192. package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
  193. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
  194. package/dist/utilities/buildProjectionFromSelect.js +171 -0
  195. package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
  196. package/dist/utilities/getDBName.d.ts +1 -1
  197. package/dist/utilities/getDBName.d.ts.map +1 -1
  198. package/dist/utilities/getDBName.js +3 -1
  199. package/dist/utilities/getDBName.js.map +1 -1
  200. package/dist/utilities/handleError.d.ts +6 -2
  201. package/dist/utilities/handleError.d.ts.map +1 -1
  202. package/dist/utilities/handleError.js +12 -9
  203. package/dist/utilities/handleError.js.map +1 -1
  204. package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
  205. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  206. package/dist/utilities/sanitizeInternalFields.js +1 -2
  207. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  208. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  209. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  210. package/dist/utilities/sanitizeRelationshipIDs.js +115 -0
  211. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  212. package/dist/utilities/sanitizeRelationshipIDs.spec.js +383 -0
  213. package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
  214. package/dist/withSession.d.ts +3 -27
  215. package/dist/withSession.d.ts.map +1 -1
  216. package/dist/withSession.js +10 -4
  217. package/dist/withSession.js.map +1 -1
  218. package/license.md +22 -0
  219. package/package.json +29 -17
  220. package/predefinedMigrations/versions-v1-v2.js +0 -96
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildSearchParams.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport type { PathToQuery } from 'payload/database'\nimport type { Field } from 'payload/types'\nimport type { Operator } from 'payload/types'\n\nimport ObjectIdImport from 'bson-objectid'\nimport mongoose from 'mongoose'\nimport { getLocalizedPaths } from 'payload/database'\nimport { fieldAffectsData } from 'payload/types'\nimport { validOperators } from 'payload/types'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\nconst ObjectId = (ObjectIdImport.default ||\n ObjectIdImport) as unknown as typeof ObjectIdImport.default\n\ntype SearchParam = {\n path?: string\n rawQuery?: unknown\n value?: unknown\n}\n\nconst subQueryOptions = {\n lean: true,\n limit: 50,\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 payload,\n val,\n}: {\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n incomingPath: string\n locale?: string\n operator: string\n payload: Payload\n val: unknown\n}): Promise<SearchParam> {\n // Replace GraphQL nested field double underscore formatting\n let sanitizedPath = incomingPath.replace(/__/g, '.')\n if (sanitizedPath === 'id') sanitizedPath = '_id'\n\n let paths: PathToQuery[] = []\n\n let hasCustomID = false\n\n if (sanitizedPath === '_id') {\n const customIDFieldType = payload.collections[collectionSlug]?.customIDType\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 Field,\n path: '_id',\n })\n } else {\n paths = await getLocalizedPaths({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: sanitizedPath,\n locale,\n payload,\n })\n }\n\n const [{ field, path }] = paths\n\n if (path) {\n const {\n operator: formattedOperator,\n rawQuery,\n val: formattedValue,\n } = sanitizeQueryValue({\n field,\n hasCustomID,\n operator,\n path,\n val,\n })\n\n if (rawQuery) return { value: rawQuery }\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\n const initialRelationshipQuery = {\n value: {},\n } as SearchParam\n\n const relationshipQuery = await pathsToQuery.reduce(\n async (priorQuery, { collectionSlug: slug, path: subPath }, i) => {\n const priorQueryResult = await priorQuery\n\n const SubModel = (payload.db as MongooseAdapter).collections[slug]\n\n // On the \"deepest\" collection,\n // Search on the value passed through the query\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 result = await SubModel.find(subQuery, subQueryOptions)\n\n const $in: unknown[] = []\n\n result.forEach((doc) => {\n const stringID = doc._id.toString()\n $in.push(stringID)\n\n if (mongoose.Types.ObjectId.isValid(stringID)) {\n $in.push(doc._id)\n }\n })\n\n if (pathsToQuery.length === 1) {\n return {\n path,\n value: { $in },\n }\n }\n\n const nextSubPath = pathsToQuery[i + 1].path\n\n return {\n value: { [nextSubPath]: { $in } },\n }\n }\n\n const subQuery = priorQueryResult.value\n const result = await SubModel.find(subQuery, subQueryOptions)\n\n const $in = result.map((doc) => doc._id.toString())\n\n // If it is the last recursion\n // then pass through the search param\n if (i + 1 === pathsToQuery.length) {\n return {\n path,\n value: { $in },\n }\n }\n\n return {\n value: {\n _id: { $in },\n },\n }\n },\n Promise.resolve(initialRelationshipQuery),\n )\n\n return relationshipQuery\n }\n\n if (formattedOperator && validOperators.includes(formattedOperator as Operator)) {\n const operatorKey = operatorMap[formattedOperator]\n\n if (field.type === 'relationship' || field.type === 'upload') {\n let hasNumberIDRelation\n\n const result = {\n value: {\n $or: [{ [path]: { [operatorKey]: formattedValue } }],\n },\n }\n\n if (typeof formattedValue === 'string') {\n if (mongoose.Types.ObjectId.isValid(formattedValue)) {\n result.value.$or.push({\n [path]: { [operatorKey]: new 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.$or.push({ [path]: { [operatorKey]: parseFloat(formattedValue) } })\n }\n }\n\n if (result.value.$or.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: word.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\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"],"names":["ObjectIdImport","mongoose","getLocalizedPaths","validOperators","operatorMap","sanitizeQueryValue","ObjectId","default","subQueryOptions","lean","limit","buildSearchParam","collectionSlug","fields","globalSlug","incomingPath","locale","operator","payload","val","sanitizedPath","replace","paths","hasCustomID","customIDFieldType","collections","customIDType","idFieldType","push","complete","field","name","type","path","formattedOperator","rawQuery","formattedValue","value","length","pathsToQuery","slice","reverse","initialRelationshipQuery","relationshipQuery","reduce","priorQuery","slug","subPath","i","priorQueryResult","SubModel","db","subQuery","buildQuery","where","result","find","$in","forEach","doc","stringID","_id","toString","Types","isValid","nextSubPath","map","Promise","resolve","includes","operatorKey","hasNumberIDRelation","$or","Array","isArray","relationTo","isRelatedToCustomNumberID","parseFloat","words","split","$and","word","$options","$regex","undefined"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,OAAOA,oBAAoB,gBAAe;AAC1C,OAAOC,cAAc,WAAU;AAC/B,SAASC,iBAAiB,QAAQ,mBAAkB;AAEpD,S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I,CAAC;4BAAE,CAACK,KAAK,EAAE;gCAAE,CAACqC,YAAY,EAAEO,WAAWzC;4BAAgB;wBAAE;oBAClF;gBACF;gBAEA,IAAImB,OAAOlB,KAAK,CAACmC,GAAG,CAAClC,MAAM,GAAG,GAAG;oBAC/B,OAAOiB;gBACT;YACF;YAEA,IAAIrB,sBAAsB,UAAU,OAAOE,mBAAmB,UAAU;gBACtE,MAAM0C,QAAQ1C,eAAe2C,KAAK,CAAC;gBAEnC,MAAMxB,SAAS;oBACblB,OAAO;wBACL2C,MAAMF,MAAMZ,GAAG,CAAC,CAACe,OAAU,CAAA;gCACzB,CAAChD,KAAK,EAAE;oCACNiD,UAAU;oCACVC,QAAQF,KAAK5D,OAAO,CAAC,uBAAuB;gCAC9C;4BACF,CAAA;oBACF;gBACF;gBAEA,OAAOkC;YACT;YAEA,yDAAyD;YACzD,wDAAwD;YACxD,IAAI,CAACe,aAAa;gBAChB,OAAO;oBACLrC;oBACAI,OAAOD;gBACT;YACF;YAEA,OAAO;gBACLH;gBACAI,OAAO;oBAAE,CAACiC,YAAY,EAAElC;gBAAe;YACzC;QACF;IACF;IACA,OAAOgD;AACT"}
1
+ {"version":3,"sources":["../../src/queries/buildSearchParams.ts"],"sourcesContent":["import type { Field, Operator, PathToQuery, Payload } from 'payload'\n\nimport { Types } from 'mongoose'\nimport { getLocalizedPaths } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\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 limit: 50,\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 payload,\n val,\n}: {\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n incomingPath: string\n locale?: string\n operator: string\n payload: Payload\n val: unknown\n}): Promise<SearchParam> {\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 = payload.collections[collectionSlug]?.customIDType\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 Field,\n path: '_id',\n })\n } else {\n paths = await getLocalizedPaths({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: sanitizedPath,\n locale,\n payload,\n })\n }\n\n const [{ field, path }] = paths\n\n if (path) {\n const sanitizedQueryValue = sanitizeQueryValue({\n field,\n hasCustomID,\n operator,\n path,\n val,\n })\n\n if (!sanitizedQueryValue) {\n return undefined\n }\n\n const { operator: formattedOperator, rawQuery, val: formattedValue } = sanitizedQueryValue\n\n if (rawQuery) {\n return { value: rawQuery }\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\n const initialRelationshipQuery = {\n value: {},\n } as SearchParam\n\n const relationshipQuery = await pathsToQuery.reduce(\n async (priorQuery, { collectionSlug: slug, path: subPath }, i) => {\n const priorQueryResult = await priorQuery\n\n const SubModel = (payload.db as MongooseAdapter).collections[slug]\n\n // On the \"deepest\" collection,\n // Search on the value passed through the query\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 result = await SubModel.find(subQuery, subQueryOptions)\n\n const $in: unknown[] = []\n\n result.forEach((doc) => {\n const stringID = doc._id.toString()\n $in.push(stringID)\n\n if (Types.ObjectId.isValid(stringID)) {\n $in.push(doc._id)\n }\n })\n\n if (pathsToQuery.length === 1) {\n return {\n path,\n value: { $in },\n }\n }\n\n const nextSubPath = pathsToQuery[i + 1].path\n\n return {\n value: { [nextSubPath]: { $in } },\n }\n }\n\n const subQuery = priorQueryResult.value\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 return {\n path,\n value: { $in },\n }\n }\n\n return {\n value: {\n _id: { $in },\n },\n }\n },\n Promise.resolve(initialRelationshipQuery),\n )\n\n return relationshipQuery\n }\n\n if (formattedOperator && validOperators.includes(formattedOperator as Operator)) {\n const operatorKey = operatorMap[formattedOperator]\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 if (result.value[multiIDCondition].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: word.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\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"],"names":["Types","getLocalizedPaths","validOperators","operatorMap","sanitizeQueryValue","subQueryOptions","lean","limit","buildSearchParam","collectionSlug","fields","globalSlug","incomingPath","locale","operator","payload","val","sanitizedPath","replace","paths","hasCustomID","customIDFieldType","collections","customIDType","idFieldType","push","complete","field","name","type","path","sanitizedQueryValue","undefined","formattedOperator","rawQuery","formattedValue","value","length","pathsToQuery","slice","reverse","initialRelationshipQuery","relationshipQuery","reduce","priorQuery","slug","subPath","i","priorQueryResult","SubModel","db","subQuery","buildQuery","where","result","find","$in","forEach","doc","stringID","_id","toString","ObjectId","isValid","nextSubPath","map","Promise","resolve","includes","operatorKey","hasNumberIDRelation","multiIDCondition","Array","isArray","relationTo","isRelatedToCustomNumberID","parseFloat","words","split","$and","word","$options","$regex"],"mappings":"AAEA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,iBAAiB,QAAQ,UAAS;AAC3C,SAASC,cAAc,QAAQ,iBAAgB;AAI/C,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAQ5D,MAAMC,kBAAkB;IACtBC,MAAM;IACNC,OAAO;AACT;AAEA;;CAEC,GACD,OAAO,eAAeC,iBAAiB,EACrCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,YAAY,EACZC,MAAM,EACNC,QAAQ,EACRC,OAAO,EACPC,GAAG,EAUJ;IACC,4DAA4D;IAC5D,IAAIC,gBAAgBL,aAAaM,OAAO,CAAC,OAAO;IAChD,IAAID,kBAAkB,MAAM;QAC1BA,gBAAgB;IAClB;IAEA,IAAIE,QAAuB,EAAE;IAE7B,IAAIC,cAAc;IAElB,IAAIH,kBAAkB,OAAO;QAC3B,MAAMI,oBAAoBN,QAAQO,WAAW,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CACzB,CAAClD,KAAK,EAAE;oCACNmD,UAAU;oCACVC,QAAQF,KAAK9D,OAAO,CAAC,uBAAuB;gCAC9C;4BACF,CAAA;oBACF;gBACF;gBAEA,OAAOoC;YACT;YAEA,yDAAyD;YACzD,wDAAwD;YACxD,IAAI,CAACe,aAAa;gBAChB,OAAO;oBACLvC;oBACAM,OAAOD;gBACT;YACF;YAEA,OAAO;gBACLL;gBACAM,OAAO;oBAAE,CAACiC,YAAY,EAAElC;gBAAe;YACzC;QACF;IACF;IACA,OAAOH;AACT"}
@@ -1,36 +1,10 @@
1
- /// <reference types="mongoose/types/aggregate.js" />
2
- /// <reference types="mongoose/types/callback.js" />
3
- /// <reference types="mongoose/types/collection.js" />
4
- /// <reference types="mongoose/types/connection.js" />
5
- /// <reference types="mongoose/types/cursor.js" />
6
- /// <reference types="mongoose/types/document.js" />
7
- /// <reference types="mongoose/types/error.js" />
8
- /// <reference types="mongoose/types/expressions.js" />
9
- /// <reference types="mongoose/types/helpers.js" />
10
- /// <reference types="mongoose/types/middlewares.js" />
11
- /// <reference types="mongoose/types/indexes.js" />
12
- /// <reference types="mongoose/types/models.js" />
13
- /// <reference types="mongoose/types/mongooseoptions.js" />
14
- /// <reference types="mongoose/types/pipelinestage.js" />
15
- /// <reference types="mongoose/types/populate.js" />
16
- /// <reference types="mongoose/types/query.js" />
17
- /// <reference types="mongoose/types/schemaoptions.js" />
18
- /// <reference types="mongoose/types/schematypes.js" />
19
- /// <reference types="mongoose/types/session.js" />
20
- /// <reference types="mongoose/types/types.js" />
21
- /// <reference types="mongoose/types/utility.js" />
22
- /// <reference types="mongoose/types/validation.js" />
23
- /// <reference types="mongoose/types/virtuals.js" />
24
- /// <reference types="mongoose/types/inferschematype.js" />
25
- /// <reference types="mongoose-paginate-v2" />
26
1
  import type { PaginateOptions } from 'mongoose';
27
- import type { SanitizedConfig } from 'payload/config';
28
- import type { Field } from 'payload/types';
2
+ import type { Field, SanitizedConfig, Sort } from 'payload';
29
3
  type Args = {
30
4
  config: SanitizedConfig;
31
5
  fields: Field[];
32
6
  locale: string;
33
- sort: string;
7
+ sort: Sort;
34
8
  timestamps: boolean;
35
9
  };
36
10
  export type SortArgs = {
@@ -38,6 +12,6 @@ export type SortArgs = {
38
12
  property: string;
39
13
  }[];
40
14
  export type SortDirection = 'asc' | 'desc';
41
- export declare const buildSortParam: ({ config, fields, locale, sort, timestamps, }: Args) => PaginateOptions['sort'];
15
+ export declare const buildSortParam: ({ config, fields, locale, sort, timestamps, }: Args) => PaginateOptions["sort"];
42
16
  export {};
43
17
  //# sourceMappingURL=buildSortParam.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildSortParam.d.ts","sourceRoot":"","sources":["../../src/queries/buildSortParam.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAI1C,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,SAAS,EAAE,aAAa,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;CACjB,EAAE,CAAA;AAEH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAA;AAE1C,eAAO,MAAM,cAAc,kDAMxB,IAAI,KAAG,eAAe,CAAC,MAAM,CA6B/B,CAAA"}
1
+ {"version":3,"file":"buildSortParam.d.ts","sourceRoot":"","sources":["../../src/queries/buildSortParam.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAI3D,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,IAAI,CAAA;IACV,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,SAAS,EAAE,aAAa,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;CACjB,EAAE,CAAA;AAEH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAA;AAE1C,eAAO,MAAM,cAAc,kDAMxB,IAAI,KAAG,eAAe,CAAC,MAAM,CAsC/B,CAAA"}
@@ -1,32 +1,41 @@
1
1
  import { getLocalizedSortProperty } from './getLocalizedSortProperty.js';
2
2
  export const buildSortParam = ({ config, fields, locale, sort, timestamps })=>{
3
- let sortProperty;
4
- let sortDirection = 'desc';
5
3
  if (!sort) {
6
4
  if (timestamps) {
7
- sortProperty = 'createdAt';
5
+ sort = '-createdAt';
8
6
  } else {
9
- sortProperty = '_id';
7
+ sort = '-id';
10
8
  }
11
- } else if (sort.indexOf('-') === 0) {
12
- sortProperty = sort.substring(1);
13
- } else {
14
- sortProperty = sort;
15
- sortDirection = 'asc';
16
9
  }
17
- if (sortProperty === 'id') {
18
- sortProperty = '_id';
19
- } else {
20
- sortProperty = getLocalizedSortProperty({
10
+ if (typeof sort === 'string') {
11
+ sort = [
12
+ sort
13
+ ];
14
+ }
15
+ const sorting = sort.reduce((acc, item)=>{
16
+ let sortProperty;
17
+ let sortDirection;
18
+ if (item.indexOf('-') === 0) {
19
+ sortProperty = item.substring(1);
20
+ sortDirection = 'desc';
21
+ } else {
22
+ sortProperty = item;
23
+ sortDirection = 'asc';
24
+ }
25
+ if (sortProperty === 'id') {
26
+ acc['_id'] = sortDirection;
27
+ return acc;
28
+ }
29
+ const localizedProperty = getLocalizedSortProperty({
21
30
  config,
22
31
  fields,
23
32
  locale,
24
33
  segments: sortProperty.split('.')
25
34
  });
26
- }
27
- return {
28
- [sortProperty]: sortDirection
29
- };
35
+ acc[localizedProperty] = sortDirection;
36
+ return acc;
37
+ }, {});
38
+ return sorting;
30
39
  };
31
40
 
32
41
  //# sourceMappingURL=buildSortParam.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildSortParam.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { SanitizedConfig } from 'payload/config'\nimport type { Field } from 'payload/types'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\ntype Args = {\n config: SanitizedConfig\n fields: Field[]\n locale: string\n sort: string\n timestamps: boolean\n}\n\nexport type SortArgs = {\n direction: SortDirection\n property: string\n}[]\n\nexport type SortDirection = 'asc' | 'desc'\n\nexport const buildSortParam = ({\n config,\n fields,\n locale,\n sort,\n timestamps,\n}: Args): PaginateOptions['sort'] => {\n let sortProperty: string\n let sortDirection: SortDirection = 'desc'\n\n if (!sort) {\n if (timestamps) {\n sortProperty = 'createdAt'\n } else {\n sortProperty = '_id'\n }\n } else if (sort.indexOf('-') === 0) {\n sortProperty = sort.substring(1)\n } else {\n sortProperty = sort\n sortDirection = 'asc'\n }\n\n if (sortProperty === 'id') {\n sortProperty = '_id'\n } else {\n sortProperty = getLocalizedSortProperty({\n config,\n fields,\n locale,\n segments: sortProperty.split('.'),\n })\n }\n\n return { [sortProperty]: sortDirection }\n}\n"],"names":["getLocalizedSortProperty","buildSortParam","config","fields","locale","sort","timestamps","sortProperty","sortDirection","indexOf","substring","segments","split"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,wBAAwB,QAAQ,gCAA+B;AAiBxE,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,UAAU,EACL;IACL,IAAIC;IACJ,IAAIC,gBAA+B;IAEnC,IAAI,CAACH,MAAM;QACT,IAAIC,YAAY;YACdC,eAAe;QACjB,OAAO;YACLA,eAAe;QACjB;IACF,OAAO,IAAIF,KAAKI,OAAO,CAAC,SAAS,GAAG;QAClCF,eAAeF,KAAKK,SAAS,CAAC;IAChC,OAAO;QACLH,eAAeF;QACfG,gBAAgB;IAClB;IAEA,IAAID,iBAAiB,MAAM;QACzBA,eAAe;IACjB,OAAO;QACLA,eAAeP,yBAAyB;YACtCE;YACAC;YACAC;YACAO,UAAUJ,aAAaK,KAAK,CAAC;QAC/B;IACF;IAEA,OAAO;QAAE,CAACL,aAAa,EAAEC;IAAc;AACzC,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/buildSortParam.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Field, SanitizedConfig, Sort } from 'payload'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\ntype Args = {\n config: SanitizedConfig\n fields: Field[]\n locale: string\n sort: Sort\n timestamps: boolean\n}\n\nexport type SortArgs = {\n direction: SortDirection\n property: string\n}[]\n\nexport type SortDirection = 'asc' | 'desc'\n\nexport const buildSortParam = ({\n config,\n fields,\n locale,\n sort,\n timestamps,\n}: Args): PaginateOptions['sort'] => {\n if (!sort) {\n if (timestamps) {\n sort = '-createdAt'\n } else {\n sort = '-id'\n }\n }\n\n if (typeof sort === 'string') {\n sort = [sort]\n }\n\n const sorting = sort.reduce<PaginateOptions['sort']>((acc, item) => {\n let sortProperty: string\n let sortDirection: SortDirection\n if (item.indexOf('-') === 0) {\n sortProperty = item.substring(1)\n sortDirection = 'desc'\n } else {\n sortProperty = item\n sortDirection = 'asc'\n }\n if (sortProperty === 'id') {\n acc['_id'] = sortDirection\n return acc\n }\n const localizedProperty = getLocalizedSortProperty({\n config,\n fields,\n locale,\n segments: sortProperty.split('.'),\n })\n acc[localizedProperty] = sortDirection\n return acc\n }, {})\n\n return sorting\n}\n"],"names":["getLocalizedSortProperty","buildSortParam","config","fields","locale","sort","timestamps","sorting","reduce","acc","item","sortProperty","sortDirection","indexOf","substring","localizedProperty","segments","split"],"mappings":"AAGA,SAASA,wBAAwB,QAAQ,gCAA+B;AAiBxE,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,UAAU,EACL;IACL,IAAI,CAACD,MAAM;QACT,IAAIC,YAAY;YACdD,OAAO;QACT,OAAO;YACLA,OAAO;QACT;IACF;IAEA,IAAI,OAAOA,SAAS,UAAU;QAC5BA,OAAO;YAACA;SAAK;IACf;IAEA,MAAME,UAAUF,KAAKG,MAAM,CAA0B,CAACC,KAAKC;QACzD,IAAIC;QACJ,IAAIC;QACJ,IAAIF,KAAKG,OAAO,CAAC,SAAS,GAAG;YAC3BF,eAAeD,KAAKI,SAAS,CAAC;YAC9BF,gBAAgB;QAClB,OAAO;YACLD,eAAeD;YACfE,gBAAgB;QAClB;QACA,IAAID,iBAAiB,MAAM;YACzBF,GAAG,CAAC,MAAM,GAAGG;YACb,OAAOH;QACT;QACA,MAAMM,oBAAoBf,yBAAyB;YACjDE;YACAC;YACAC;YACAY,UAAUL,aAAaM,KAAK,CAAC;QAC/B;QACAR,GAAG,CAACM,kBAAkB,GAAGH;QACzB,OAAOH;IACT,GAAG,CAAC;IAEJ,OAAOF;AACT,EAAC"}
@@ -1,5 +1,4 @@
1
- import type { SanitizedConfig } from 'payload/config';
2
- import type { Field } from 'payload/types';
1
+ import type { Field, SanitizedConfig } from 'payload';
3
2
  type Args = {
4
3
  config: SanitizedConfig;
5
4
  fields: Field[];
@@ -1 +1 @@
1
- {"version":3,"file":"getLocalizedSortProperty.d.ts","sourceRoot":"","sources":["../../src/queries/getLocalizedSortProperty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAK1C,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,wBAAwB,oGAMlC,IAAI,KAAG,MAkFT,CAAA"}
1
+ {"version":3,"file":"getLocalizedSortProperty.d.ts","sourceRoot":"","sources":["../../src/queries/getLocalizedSortProperty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAKrD,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,wBAAwB,oGAMlC,IAAI,KAAG,MAkFT,CAAA"}
@@ -1,5 +1,5 @@
1
- import { fieldAffectsData, fieldIsPresentationalOnly } from 'payload/types';
2
- import { flattenTopLevelFields } from 'payload/utilities';
1
+ import { flattenTopLevelFields } from 'payload';
2
+ import { fieldAffectsData, fieldIsPresentationalOnly } from 'payload/shared';
3
3
  export const getLocalizedSortProperty = ({ config, fields: incomingFields, locale, result: incomingResult, segments: incomingSegments })=>{
4
4
  // If localization is not enabled, accept exactly
5
5
  // what is sent in
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/getLocalizedSortProperty.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload/config'\nimport type { Field } from 'payload/types'\n\nimport { fieldAffectsData, fieldIsPresentationalOnly } from 'payload/types'\nimport { flattenTopLevelFields } from 'payload/utilities'\n\ntype Args = {\n config: SanitizedConfig\n fields: Field[]\n locale: string\n result?: string\n segments: string[]\n}\n\nexport const getLocalizedSortProperty = ({\n config,\n fields: incomingFields,\n locale,\n result: incomingResult,\n segments: incomingSegments,\n}: Args): string => {\n // If localization is not enabled, accept exactly\n // what is sent in\n if (!config.localization) {\n return incomingSegments.join('.')\n }\n\n // Flatten incoming fields (row, etc)\n const fields = flattenTopLevelFields(incomingFields)\n\n const segments = [...incomingSegments]\n\n // Retrieve first segment, and remove from segments\n const firstSegment = segments.shift()\n\n // Attempt to find a matched field\n const matchedField = fields.find(\n (field) => fieldAffectsData(field) && field.name === firstSegment,\n )\n\n if (matchedField && !fieldIsPresentationalOnly(matchedField)) {\n let nextFields: Field[]\n const remainingSegments = [...segments]\n let localizedSegment = matchedField.name\n\n if (matchedField.localized) {\n // Check to see if next segment is a locale\n if (segments.length > 0) {\n const nextSegmentIsLocale = config.localization.localeCodes.includes(remainingSegments[0])\n\n // If next segment is locale, remove it from remaining segments\n // and use it to localize the current segment\n if (nextSegmentIsLocale) {\n const nextSegment = remainingSegments.shift()\n localizedSegment = `${matchedField.name}.${nextSegment}`\n }\n } else {\n // If no more segments, but field is localized, use default locale\n localizedSegment = `${matchedField.name}.${locale}`\n }\n }\n\n // If there are subfields, pass them through\n if (\n matchedField.type === 'tab' ||\n matchedField.type === 'group' ||\n matchedField.type === 'array'\n ) {\n nextFields = matchedField.fields\n }\n\n if (matchedField.type === 'blocks') {\n nextFields = matchedField.blocks.reduce((flattenedBlockFields, block) => {\n return [\n ...flattenedBlockFields,\n ...block.fields.filter(\n (blockField) =>\n (fieldAffectsData(blockField) &&\n blockField.name !== 'blockType' &&\n blockField.name !== 'blockName') ||\n !fieldAffectsData(blockField),\n ),\n ]\n }, [])\n }\n\n const result = incomingResult ? `${incomingResult}.${localizedSegment}` : localizedSegment\n\n if (nextFields) {\n return getLocalizedSortProperty({\n config,\n fields: nextFields,\n locale,\n result,\n segments: remainingSegments,\n })\n }\n\n return result\n }\n\n return incomingSegments.join('.')\n}\n"],"names":["fieldAffectsData","fieldIsPresentationalOnly","flattenTopLevelFields","getLocalizedSortProperty","config","fields","incomingFields","locale","result","incomingResult","segments","incomingSegments","localization","join","firstSegment","shift","matchedField","find","field","name","nextFields","remainingSegments","localizedSegment","localized","length","nextSegmentIsLocale","localeCodes","includes","nextSegment","type","blocks","reduce","flattenedBlockFields","block","filter","blockField"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,gBAAgB,EAAEC,yBAAyB,QAAQ,gBAAe;AAC3E,SAASC,qBAAqB,QAAQ,oBAAmB;AAUzD,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,MAAM,EACNC,QAAQC,cAAc,EACtBC,MAAM,EACNC,QAAQC,cAAc,EACtBC,UAAUC,gBAAgB,EACrB;IACL,iDAAiD;IACjD,kBAAkB;IAClB,IAAI,CAACP,OAAOQ,YAAY,EAAE;QACxB,OAAOD,iBAAiBE,IAAI,CAAC;IAC/B;IAEA,qCAAqC;IACrC,MAAMR,SAASH,sBAAsBI;IAErC,MAAMI,WAAW;WAAIC;KAAiB;IAEtC,mDAAmD;IACnD,MAAMG,eAAeJ,SAASK,KAAK;IAEnC,kCAAkC;IAClC,MAAMC,eAAeX,OAAOY,IAAI,CAC9B,CAACC,QAAUlB,iBAAiBkB,UAAUA,MAAMC,IAAI,KAAKL;IAGvD,IAAIE,gBAAgB,CAACf,0BAA0Be,eAAe;QAC5D,IAAII;QACJ,MAAMC,oBAAoB;eAAIX;SAAS;QACvC,IAAIY,mBAAmBN,aAAaG,IAAI;QAExC,IAAIH,aAAaO,SAAS,EAAE;YAC1B,2CAA2C;YAC3C,IAAIb,SAASc,MAAM,GAAG,GAAG;gBACvB,MAAMC,sBAAsBrB,OAAOQ,YAAY,CAACc,WAAW,CAACC,QAAQ,CAACN,iBAAiB,CAAC,EAAE;gBAEzF,+DAA+D;gBAC/D,6CAA6C;gBAC7C,IAAII,qBAAqB;oBACvB,MAAMG,cAAcP,kBAAkBN,KAAK;oBAC3CO,mBAAmB,CAAC,EAAEN,aAAaG,IAAI,CAAC,CAAC,EAAES,YAAY,CAAC;gBAC1D;YACF,OAAO;gBACL,kEAAkE;gBAClEN,mBAAmB,CAAC,EAAEN,aAAaG,IAAI,CAAC,CAAC,EAAEZ,OAAO,CAAC;YACrD;QACF;QAEA,4CAA4C;QAC5C,IACES,aAAaa,IAAI,KAAK,SACtBb,aAAaa,IAAI,KAAK,WACtBb,aAAaa,IAAI,KAAK,SACtB;YACAT,aAAaJ,aAAaX,MAAM;QAClC;QAEA,IAAIW,aAAaa,IAAI,KAAK,UAAU;YAClCT,aAAaJ,aAAac,MAAM,CAACC,MAAM,CAAC,CAACC,sBAAsBC;gBAC7D,OAAO;uBACFD;uBACAC,MAAM5B,MAAM,CAAC6B,MAAM,CACpB,CAACC,aACC,AAACnC,iBAAiBmC,eAChBA,WAAWhB,IAAI,KAAK,eACpBgB,WAAWhB,IAAI,KAAK,eACtB,CAACnB,iBAAiBmC;iBAEvB;YACH,GAAG,EAAE;QACP;QAEA,MAAM3B,SAASC,iBAAiB,CAAC,EAAEA,eAAe,CAAC,EAAEa,iBAAiB,CAAC,GAAGA;QAE1E,IAAIF,YAAY;YACd,OAAOjB,yBAAyB;gBAC9BC;gBACAC,QAAQe;gBACRb;gBACAC;gBACAE,UAAUW;YACZ;QACF;QAEA,OAAOb;IACT;IAEA,OAAOG,iBAAiBE,IAAI,CAAC;AAC/B,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/getLocalizedSortProperty.ts"],"sourcesContent":["import type { Field, SanitizedConfig } from 'payload'\n\nimport { flattenTopLevelFields } from 'payload'\nimport { fieldAffectsData, fieldIsPresentationalOnly } from 'payload/shared'\n\ntype Args = {\n config: SanitizedConfig\n fields: Field[]\n locale: string\n result?: string\n segments: string[]\n}\n\nexport const getLocalizedSortProperty = ({\n config,\n fields: incomingFields,\n locale,\n result: incomingResult,\n segments: incomingSegments,\n}: Args): string => {\n // If localization is not enabled, accept exactly\n // what is sent in\n if (!config.localization) {\n return incomingSegments.join('.')\n }\n\n // Flatten incoming fields (row, etc)\n const fields = flattenTopLevelFields(incomingFields)\n\n const segments = [...incomingSegments]\n\n // Retrieve first segment, and remove from segments\n const firstSegment = segments.shift()\n\n // Attempt to find a matched field\n const matchedField = fields.find(\n (field) => fieldAffectsData(field) && field.name === firstSegment,\n )\n\n if (matchedField && !fieldIsPresentationalOnly(matchedField)) {\n let nextFields: Field[]\n const remainingSegments = [...segments]\n let localizedSegment = matchedField.name\n\n if (matchedField.localized) {\n // Check to see if next segment is a locale\n if (segments.length > 0) {\n const nextSegmentIsLocale = config.localization.localeCodes.includes(remainingSegments[0])\n\n // If next segment is locale, remove it from remaining segments\n // and use it to localize the current segment\n if (nextSegmentIsLocale) {\n const nextSegment = remainingSegments.shift()\n localizedSegment = `${matchedField.name}.${nextSegment}`\n }\n } else {\n // If no more segments, but field is localized, use default locale\n localizedSegment = `${matchedField.name}.${locale}`\n }\n }\n\n // If there are subfields, pass them through\n if (\n matchedField.type === 'tab' ||\n matchedField.type === 'group' ||\n matchedField.type === 'array'\n ) {\n nextFields = matchedField.fields\n }\n\n if (matchedField.type === 'blocks') {\n nextFields = matchedField.blocks.reduce((flattenedBlockFields, block) => {\n return [\n ...flattenedBlockFields,\n ...block.fields.filter(\n (blockField) =>\n (fieldAffectsData(blockField) &&\n blockField.name !== 'blockType' &&\n blockField.name !== 'blockName') ||\n !fieldAffectsData(blockField),\n ),\n ]\n }, [])\n }\n\n const result = incomingResult ? `${incomingResult}.${localizedSegment}` : localizedSegment\n\n if (nextFields) {\n return getLocalizedSortProperty({\n config,\n fields: nextFields,\n locale,\n result,\n segments: remainingSegments,\n })\n }\n\n return result\n }\n\n return incomingSegments.join('.')\n}\n"],"names":["flattenTopLevelFields","fieldAffectsData","fieldIsPresentationalOnly","getLocalizedSortProperty","config","fields","incomingFields","locale","result","incomingResult","segments","incomingSegments","localization","join","firstSegment","shift","matchedField","find","field","name","nextFields","remainingSegments","localizedSegment","localized","length","nextSegmentIsLocale","localeCodes","includes","nextSegment","type","blocks","reduce","flattenedBlockFields","block","filter","blockField"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,UAAS;AAC/C,SAASC,gBAAgB,EAAEC,yBAAyB,QAAQ,iBAAgB;AAU5E,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,MAAM,EACNC,QAAQC,cAAc,EACtBC,MAAM,EACNC,QAAQC,cAAc,EACtBC,UAAUC,gBAAgB,EACrB;IACL,iDAAiD;IACjD,kBAAkB;IAClB,IAAI,CAACP,OAAOQ,YAAY,EAAE;QACxB,OAAOD,iBAAiBE,IAAI,CAAC;IAC/B;IAEA,qCAAqC;IACrC,MAAMR,SAASL,sBAAsBM;IAErC,MAAMI,WAAW;WAAIC;KAAiB;IAEtC,mDAAmD;IACnD,MAAMG,eAAeJ,SAASK,KAAK;IAEnC,kCAAkC;IAClC,MAAMC,eAAeX,OAAOY,IAAI,CAC9B,CAACC,QAAUjB,iBAAiBiB,UAAUA,MAAMC,IAAI,KAAKL;IAGvD,IAAIE,gBAAgB,CAACd,0BAA0Bc,eAAe;QAC5D,IAAII;QACJ,MAAMC,oBAAoB;eAAIX;SAAS;QACvC,IAAIY,mBAAmBN,aAAaG,IAAI;QAExC,IAAIH,aAAaO,SAAS,EAAE;YAC1B,2CAA2C;YAC3C,IAAIb,SAASc,MAAM,GAAG,GAAG;gBACvB,MAAMC,sBAAsBrB,OAAOQ,YAAY,CAACc,WAAW,CAACC,QAAQ,CAACN,iBAAiB,CAAC,EAAE;gBAEzF,+DAA+D;gBAC/D,6CAA6C;gBAC7C,IAAII,qBAAqB;oBACvB,MAAMG,cAAcP,kBAAkBN,KAAK;oBAC3CO,mBAAmB,CAAC,EAAEN,aAAaG,IAAI,CAAC,CAAC,EAAES,YAAY,CAAC;gBAC1D;YACF,OAAO;gBACL,kEAAkE;gBAClEN,mBAAmB,CAAC,EAAEN,aAAaG,IAAI,CAAC,CAAC,EAAEZ,OAAO,CAAC;YACrD;QACF;QAEA,4CAA4C;QAC5C,IACES,aAAaa,IAAI,KAAK,SACtBb,aAAaa,IAAI,KAAK,WACtBb,aAAaa,IAAI,KAAK,SACtB;YACAT,aAAaJ,aAAaX,MAAM;QAClC;QAEA,IAAIW,aAAaa,IAAI,KAAK,UAAU;YAClCT,aAAaJ,aAAac,MAAM,CAACC,MAAM,CAAC,CAACC,sBAAsBC;gBAC7D,OAAO;uBACFD;uBACAC,MAAM5B,MAAM,CAAC6B,MAAM,CACpB,CAACC,aACC,AAAClC,iBAAiBkC,eAChBA,WAAWhB,IAAI,KAAK,eACpBgB,WAAWhB,IAAI,KAAK,eACtB,CAAClB,iBAAiBkC;iBAEvB;YACH,GAAG,EAAE;QACP;QAEA,MAAM3B,SAASC,iBAAiB,CAAC,EAAEA,eAAe,CAAC,EAAEa,iBAAiB,CAAC,GAAGA;QAE1E,IAAIF,YAAY;YACd,OAAOjB,yBAAyB;gBAC9BC;gBACAC,QAAQe;gBACRb;gBACAC;gBACAE,UAAUW;YACZ;QACF;QAEA,OAAOb;IACT;IAEA,OAAOG,iBAAiBE,IAAI,CAAC;AAC/B,EAAC"}
@@ -1,24 +1,21 @@
1
- import { sanitizeConfig } from 'payload/config';
1
+ import { sanitizeConfig } from 'payload';
2
2
  import { getLocalizedSortProperty } from './getLocalizedSortProperty.js';
3
3
  let config;
4
4
  describe('get localized sort property', ()=>{
5
5
  beforeAll(async ()=>{
6
6
  config = await sanitizeConfig({
7
7
  localization: {
8
+ defaultLocale: 'en',
9
+ fallback: true,
8
10
  locales: [
9
11
  'en',
10
12
  'es'
11
- ],
12
- defaultLocale: 'en',
13
- fallback: true
13
+ ]
14
14
  }
15
15
  });
16
16
  });
17
- it('passes through a non-localized sort property', async ()=>{
17
+ it('passes through a non-localized sort property', ()=>{
18
18
  const result = getLocalizedSortProperty({
19
- segments: [
20
- 'title'
21
- ],
22
19
  config,
23
20
  fields: [
24
21
  {
@@ -26,15 +23,15 @@ describe('get localized sort property', ()=>{
26
23
  type: 'text'
27
24
  }
28
25
  ],
29
- locale: 'en'
26
+ locale: 'en',
27
+ segments: [
28
+ 'title'
29
+ ]
30
30
  });
31
31
  expect(result).toStrictEqual('title');
32
32
  });
33
33
  it('properly localizes an un-localized sort property', ()=>{
34
34
  const result = getLocalizedSortProperty({
35
- segments: [
36
- 'title'
37
- ],
38
35
  config,
39
36
  fields: [
40
37
  {
@@ -43,16 +40,15 @@ describe('get localized sort property', ()=>{
43
40
  localized: true
44
41
  }
45
42
  ],
46
- locale: 'en'
43
+ locale: 'en',
44
+ segments: [
45
+ 'title'
46
+ ]
47
47
  });
48
48
  expect(result).toStrictEqual('title.en');
49
49
  });
50
50
  it('keeps specifically asked-for localized sort properties', ()=>{
51
51
  const result = getLocalizedSortProperty({
52
- segments: [
53
- 'title',
54
- 'es'
55
- ],
56
52
  config,
57
53
  fields: [
58
54
  {
@@ -61,16 +57,16 @@ describe('get localized sort property', ()=>{
61
57
  localized: true
62
58
  }
63
59
  ],
64
- locale: 'en'
60
+ locale: 'en',
61
+ segments: [
62
+ 'title',
63
+ 'es'
64
+ ]
65
65
  });
66
66
  expect(result).toStrictEqual('title.es');
67
67
  });
68
68
  it('properly localizes nested sort properties', ()=>{
69
69
  const result = getLocalizedSortProperty({
70
- segments: [
71
- 'group',
72
- 'title'
73
- ],
74
70
  config,
75
71
  fields: [
76
72
  {
@@ -85,17 +81,16 @@ describe('get localized sort property', ()=>{
85
81
  ]
86
82
  }
87
83
  ],
88
- locale: 'en'
84
+ locale: 'en',
85
+ segments: [
86
+ 'group',
87
+ 'title'
88
+ ]
89
89
  });
90
90
  expect(result).toStrictEqual('group.title.en');
91
91
  });
92
92
  it('keeps requested locale with nested sort properties', ()=>{
93
93
  const result = getLocalizedSortProperty({
94
- segments: [
95
- 'group',
96
- 'title',
97
- 'es'
98
- ],
99
94
  config,
100
95
  fields: [
101
96
  {
@@ -110,15 +105,17 @@ describe('get localized sort property', ()=>{
110
105
  ]
111
106
  }
112
107
  ],
113
- locale: 'en'
108
+ locale: 'en',
109
+ segments: [
110
+ 'group',
111
+ 'title',
112
+ 'es'
113
+ ]
114
114
  });
115
115
  expect(result).toStrictEqual('group.title.es');
116
116
  });
117
117
  it('properly localizes field within row', ()=>{
118
118
  const result = getLocalizedSortProperty({
119
- segments: [
120
- 'title'
121
- ],
122
119
  config,
123
120
  fields: [
124
121
  {
@@ -132,16 +129,15 @@ describe('get localized sort property', ()=>{
132
129
  ]
133
130
  }
134
131
  ],
135
- locale: 'en'
132
+ locale: 'en',
133
+ segments: [
134
+ 'title'
135
+ ]
136
136
  });
137
137
  expect(result).toStrictEqual('title.en');
138
138
  });
139
139
  it('properly localizes field within named tab', ()=>{
140
140
  const result = getLocalizedSortProperty({
141
- segments: [
142
- 'tab',
143
- 'title'
144
- ],
145
141
  config,
146
142
  fields: [
147
143
  {
@@ -160,34 +156,38 @@ describe('get localized sort property', ()=>{
160
156
  ]
161
157
  }
162
158
  ],
163
- locale: 'en'
159
+ locale: 'en',
160
+ segments: [
161
+ 'tab',
162
+ 'title'
163
+ ]
164
164
  });
165
165
  expect(result).toStrictEqual('tab.title.en');
166
166
  });
167
167
  it('properly localizes field within unnamed tab', ()=>{
168
168
  const result = getLocalizedSortProperty({
169
- segments: [
170
- 'title'
171
- ],
172
169
  config,
173
170
  fields: [
174
171
  {
175
172
  type: 'tabs',
176
173
  tabs: [
177
174
  {
178
- label: 'Tab',
179
175
  fields: [
180
176
  {
181
177
  name: 'title',
182
178
  type: 'text',
183
179
  localized: true
184
180
  }
185
- ]
181
+ ],
182
+ label: 'Tab'
186
183
  }
187
184
  ]
188
185
  }
189
186
  ],
190
- locale: 'en'
187
+ locale: 'en',
188
+ segments: [
189
+ 'title'
190
+ ]
191
191
  });
192
192
  expect(result).toStrictEqual('title.en');
193
193
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/getLocalizedSortProperty.spec.ts"],"sourcesContent":["import { SanitizedConfig, sanitizeConfig } from 'payload/config'\nimport { Config } from 'payload/config'\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\nlet config: SanitizedConfig\n\ndescribe('get localized sort property', () => {\n beforeAll(async () => {\n config = (await sanitizeConfig({\n localization: {\n locales: ['en', 'es'],\n defaultLocale: 'en',\n fallback: true,\n },\n } as Config)) as SanitizedConfig\n })\n it('passes through a non-localized sort property', async () => {\n const result = getLocalizedSortProperty({\n segments: ['title'],\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n locale: 'en',\n })\n\n expect(result).toStrictEqual('title')\n })\n\n it('properly localizes an un-localized sort property', () => {\n const result = getLocalizedSortProperty({\n segments: ['title'],\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n locale: 'en',\n })\n\n expect(result).toStrictEqual('title.en')\n })\n\n it('keeps specifically asked-for localized sort properties', () => {\n const result = getLocalizedSortProperty({\n segments: ['title', 'es'],\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n locale: 'en',\n })\n\n expect(result).toStrictEqual('title.es')\n })\n\n it('properly localizes nested sort properties', () => {\n const result = getLocalizedSortProperty({\n segments: ['group', 'title'],\n config,\n fields: [\n {\n name: 'group',\n type: 'group',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n locale: 'en',\n })\n\n expect(result).toStrictEqual('group.title.en')\n })\n\n it('keeps requested locale with nested sort properties', () => {\n const result = getLocalizedSortProperty({\n segments: ['group', 'title', 'es'],\n config,\n fields: [\n {\n name: 'group',\n type: 'group',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n locale: 'en',\n })\n\n expect(result).toStrictEqual('group.title.es')\n })\n\n it('properly localizes field within row', () => {\n const result = getLocalizedSortProperty({\n segments: ['title'],\n config,\n fields: [\n {\n type: 'row',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n locale: 'en',\n })\n\n expect(result).toStrictEqual('title.en')\n })\n\n it('properly localizes field within named tab', () => {\n const result = getLocalizedSortProperty({\n segments: ['tab', 'title'],\n config,\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n name: 'tab',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n },\n ],\n locale: 'en',\n })\n\n expect(result).toStrictEqual('tab.title.en')\n })\n\n it('properly localizes field within unnamed tab', () => {\n const result = getLocalizedSortProperty({\n segments: ['title'],\n config,\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n label: 'Tab',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n },\n ],\n locale: 'en',\n })\n\n expect(result).toStrictEqual('title.en')\n })\n})\n"],"names":["sanitizeConfig","getLocalizedSortProperty","config","describe","beforeAll","localization","locales","defaultLocale","fallback","it","result","segments","fields","name","type","locale","expect","toStrictEqual","localized","tabs","label"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAA0BA,cAAc,QAAQ,iBAAgB;AAEhE,SAASC,wBAAwB,QAAQ,gCAA+B;AAExE,IAAIC;AAEJC,SAAS,+BAA+B;IACtCC,UAAU;QACRF,SAAU,MAAMF,eAAe;YAC7BK,cAAc;gBACZC,SAAS;oBAAC;oBAAM;iBAAK;gBACrBC,eAAe;gBACfC,UAAU;YACZ;QACF;IACF;IACAC,GAAG,gDAAgD;QACjD,MAAMC,SAAST,yBAAyB;YACtCU,UAAU;gBAAC;aAAQ;YACnBT;YACAU,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;gBACR;aACD;YACDC,QAA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gBACH;aACD;YACDH,QAAQ;QACV;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,6CAA6C;QAC9C,MAAMC,SAAST,yBAAyB;YACtCU,UAAU;gBAAC;gBAAO;aAAQ;YAC1BT;YACAU,QAAQ;gBACN;oBACEE,MAAM;oBACNK,MAAM;wBACJ;4BACEN,MAAM;4BACND,QAAQ;gCACN;oCACEC,MAAM;oCACNC,MAAM;oCACNI,WAAW;gCACb;6BACD;wBACH;qBACD;gBACH;aACD;YACDH,QAAQ;QACV;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,+CAA+C;QAChD,MAAMC,SAAST,yBAAyB;YACtCU,UAAU;gBAAC;aAAQ;YACnBT;YACAU,QAAQ;gBACN;oBACEE,MAAM;oBACNK,MAAM;wBACJ;4BACEC,OAAO;4BACPR,QAAQ;gCACN;oCACEC,MAAM;oCACNC,MAAM;oCACNI,WAAW;gCACb;6BACD;wBACH;qBACD;gBACH;aACD;YACDH,QAAQ;QACV;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;AACF"}
1
+ {"version":3,"sources":["../../src/queries/getLocalizedSortProperty.spec.ts"],"sourcesContent":["import type { Config, SanitizedConfig } from 'payload'\n\nimport { sanitizeConfig } from 'payload'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\nlet config: SanitizedConfig\n\ndescribe('get localized sort property', () => {\n beforeAll(async () => {\n config = await sanitizeConfig({\n localization: {\n defaultLocale: 'en',\n fallback: true,\n locales: ['en', 'es'],\n },\n } as Config)\n })\n it('passes through a non-localized sort property', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title')\n })\n\n it('properly localizes an un-localized sort property', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title.en')\n })\n\n it('keeps specifically asked-for localized sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n locale: 'en',\n segments: ['title', 'es'],\n })\n\n expect(result).toStrictEqual('title.es')\n })\n\n it('properly localizes nested sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n name: 'group',\n type: 'group',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n locale: 'en',\n segments: ['group', 'title'],\n })\n\n expect(result).toStrictEqual('group.title.en')\n })\n\n it('keeps requested locale with nested sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n name: 'group',\n type: 'group',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n locale: 'en',\n segments: ['group', 'title', 'es'],\n })\n\n expect(result).toStrictEqual('group.title.es')\n })\n\n it('properly localizes field within row', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n type: 'row',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title.en')\n })\n\n it('properly localizes field within named tab', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n name: 'tab',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n },\n ],\n locale: 'en',\n segments: ['tab', 'title'],\n })\n\n expect(result).toStrictEqual('tab.title.en')\n })\n\n it('properly localizes field within unnamed tab', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n label: 'Tab',\n },\n ],\n },\n ],\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title.en')\n })\n})\n"],"names":["sanitizeConfig","getLocalizedSortProperty","config","describe","beforeAll","localization","defaultLocale","fallback","locales","it","result","fields","name","type","locale","segments","expect","toStrictEqual","localized","tabs","label"],"mappings":"AAEA,SAASA,cAAc,QAAQ,UAAS;AAExC,SAASC,wBAAwB,QAAQ,gCAA+B;AAExE,IAAIC;AAEJC,SAAS,+BAA+B;IACtCC,UAAU;QACRF,SAAS,MAAMF,eAAe;YAC5BK,cAAc;gBACZC,eAAe;gBACfC,UAAU;gBACVC,SAAS;oBAAC;oBAAM;iBAAK;YACvB;QACF;IACF;IACAC,GAAG,gDAAgD;QACjD,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;gBACR;aACD;YACDC,QAAQ;YACRC,UAAU;gBAAC;aAAQ;QACrB;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,oDAAoD;QACrD,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;oBACNK,WAAW;gBACb;aACD;YACDJ,QAAQ;YACRC,UAAU;gBAAC;aAAQ;QACrB;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,0DAA0D;QAC3D,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;oBACNK,WAAW;gBACb;aACD;YACDJ,QAAQ;YACRC,UAAU;gBAAC;gBAAS;aAAK;QAC3B;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,6CAA6C;QAC9C,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;oBACNF,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNK,WAAW;wBACb;qBACD;gBACH;aACD;YACDJ,QAAQ;YACRC,UAAU;gBAAC;gBAAS;aAAQ;QAC9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,"sources":["../../src/queries/mock.js"],"names":[],"rangeMappings":"","mappings":""}
1
+ {"version":3,"sources":["../../src/queries/mock.js"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/operatorMap.ts"],"sourcesContent":["export const operatorMap = {\n all: '$all',\n equals: '$eq',\n exists: '$exists',\n greater_than: '$gt',\n greater_than_equal: '$gte',\n in: '$in',\n intersects: '$geoIntersects',\n less_than: '$lt',\n less_than_equal: '$lte',\n near: '$near',\n not_equals: '$ne',\n not_in: '$nin',\n within: '$geoWithin',\n}\n"],"names":["operatorMap","all","equals","exists","greater_than","greater_than_equal","in","intersects","less_than","less_than_equal","near","not_equals","not_in","within"],"rangeMappings":";;;;;;;;;;;;;;","mappings":"AAAA,OAAO,MAAMA,cAAc;IACzBC,KAAK;IACLC,QAAQ;IACRC,QAAQ;IACRC,cAAc;IACdC,oBAAoB;IACpBC,IAAI;IACJC,YAAY;IACZC,WAAW;IACXC,iBAAiB;IACjBC,MAAM;IACNC,YAAY;IACZC,QAAQ;IACRC,QAAQ;AACV,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/operatorMap.ts"],"sourcesContent":["export const operatorMap = {\n all: '$all',\n equals: '$eq',\n exists: '$exists',\n greater_than: '$gt',\n greater_than_equal: '$gte',\n in: '$in',\n intersects: '$geoIntersects',\n less_than: '$lt',\n less_than_equal: '$lte',\n near: '$near',\n not_equals: '$ne',\n not_in: '$nin',\n within: '$geoWithin',\n}\n"],"names":["operatorMap","all","equals","exists","greater_than","greater_than_equal","in","intersects","less_than","less_than_equal","near","not_equals","not_in","within"],"mappings":"AAAA,OAAO,MAAMA,cAAc;IACzBC,KAAK;IACLC,QAAQ;IACRC,QAAQ;IACRC,cAAc;IACdC,oBAAoB;IACpBC,IAAI;IACJC,YAAY;IACZC,WAAW;IACXC,iBAAiB;IACjBC,MAAM;IACNC,YAAY;IACZC,QAAQ;IACRC,QAAQ;AACV,EAAC"}
@@ -1,6 +1,4 @@
1
- import type { Payload } from 'payload';
2
- import type { Where } from 'payload/types';
3
- import type { Field } from 'payload/types';
1
+ import type { Field, Payload, Where } from 'payload';
4
2
  export declare function parseParams({ collectionSlug, fields, globalSlug, locale, payload, where, }: {
5
3
  collectionSlug?: string;
6
4
  fields: Field[];
@@ -1 +1 @@
1
- {"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,EAAY,KAAK,EAAE,MAAM,eAAe,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAS1C,wBAAsB,WAAW,CAAC,EAChC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA0DnC"}
1
+ {"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAY,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAQ9D,wBAAsB,WAAW,CAAC,EAChC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA+DnC"}
@@ -1,6 +1,5 @@
1
- /* eslint-disable no-restricted-syntax */ /* eslint-disable no-await-in-loop */ import deepmerge from 'deepmerge';
2
- import { validOperators } from 'payload/types';
3
- import { combineMerge } from 'payload/utilities';
1
+ import { deepMergeWithCombinedArrays } from 'payload';
2
+ import { validOperators } from 'payload/shared';
4
3
  import { buildAndOrConditions } from './buildAndOrConditions.js';
5
4
  import { buildSearchParam } from './buildSearchParams.js';
6
5
  export async function parseParams({ collectionSlug, fields, globalSlug, locale, payload, where }) {
@@ -24,7 +23,9 @@ export async function parseParams({ collectionSlug, fields, globalSlug, locale,
24
23
  payload,
25
24
  where: condition
26
25
  });
27
- if (builtConditions.length > 0) result[conditionOperator] = builtConditions;
26
+ if (builtConditions.length > 0) {
27
+ result[conditionOperator] = builtConditions;
28
+ }
28
29
  } else {
29
30
  // It's a path - and there can be multiple comparisons on a single path.
30
31
  // For example - title like 'test' and title not equal to 'tester'
@@ -49,8 +50,9 @@ export async function parseParams({ collectionSlug, fields, globalSlug, locale,
49
50
  [searchParam.path]: searchParam.value
50
51
  };
51
52
  } else if (typeof searchParam?.value === 'object') {
52
- result = deepmerge(result, searchParam.value, {
53
- arrayMerge: combineMerge
53
+ result = deepMergeWithCombinedArrays(result, searchParam.value, {
54
+ // dont clone Types.ObjectIDs
55
+ clone: false
54
56
  });
55
57
  }
56
58
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax */\n/* eslint-disable no-await-in-loop */\nimport type { FilterQuery } from 'mongoose'\nimport type { Payload } from 'payload'\nimport type { Operator, Where } from 'payload/types'\nimport type { Field } from 'payload/types'\n\nimport deepmerge from 'deepmerge'\nimport { validOperators } from 'payload/types'\nimport { combineMerge } from 'payload/utilities'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { buildSearchParam } from './buildSearchParams.js'\n\nexport async function parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n}: {\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n locale: string\n payload: Payload\n where: Where\n}): Promise<Record<string, unknown>> {\n let result = {} as FilterQuery<any>\n\n if (typeof where === 'object') {\n // We need to determine if the whereKey is an AND, OR, or a schema path\n for (const relationOrPath of Object.keys(where)) {\n const condition = where[relationOrPath]\n let conditionOperator: '$and' | '$or'\n if (relationOrPath.toLowerCase() === 'and') {\n conditionOperator = '$and'\n } else if (relationOrPath.toLowerCase() === 'or') {\n conditionOperator = '$or'\n }\n if (Array.isArray(condition)) {\n const builtConditions = await buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where: condition,\n })\n if (builtConditions.length > 0) result[conditionOperator] = builtConditions\n } else {\n // It's a path - and there can be multiple comparisons on a single path.\n // For example - title like 'test' and title not equal to 'tester'\n // So we need to loop on keys again here to handle each operator independently\n const pathOperators = where[relationOrPath]\n if (typeof pathOperators === 'object') {\n for (const operator of Object.keys(pathOperators)) {\n if (validOperators.includes(operator as Operator)) {\n const searchParam = await buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: relationOrPath,\n locale,\n operator,\n payload,\n val: pathOperators[operator],\n })\n\n if (searchParam?.value && searchParam?.path) {\n result = {\n ...result,\n [searchParam.path]: searchParam.value,\n }\n } else if (typeof searchParam?.value === 'object') {\n result = deepmerge(result, searchParam.value, { arrayMerge: combineMerge })\n }\n }\n }\n }\n }\n }\n }\n\n return result\n}\n"],"names":["deepmerge","validOperators","combineMerge","buildAndOrConditions","buildSearchParam","parseParams","collectionSlug","fields","globalSlug","locale","payload","where","result","relationOrPath","Object","keys","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","length","pathOperators","operator","includes","searchParam","incomingPath","val","value","path","arrayMerge"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;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S;4BAC9B;4BAEA,IAAIE,aAAaG,SAASH,aAAaI,MAAM;gCAC3ClB,SAAS;oCACP,GAAGA,MAAM;oCACT,CAACc,YAAYI,IAAI,CAAC,EAAEJ,YAAYG,KAAK;gCACvC;4BACF,OAAO,IAAI,OAAOH,aAAaG,UAAU,UAAU;gCACjDjB,SAASZ,UAAUY,QAAQc,YAAYG,KAAK,EAAE;oCAAEE,YAAY7B;gCAAa;4BAC3E;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOU;AACT"}
1
+ {"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { FilterQuery } from 'mongoose'\nimport type { Field, Operator, Payload, Where } from 'payload'\n\nimport { deepMergeWithCombinedArrays } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { buildSearchParam } from './buildSearchParams.js'\n\nexport async function parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n}: {\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n locale: string\n payload: Payload\n where: Where\n}): Promise<Record<string, unknown>> {\n let result = {} as FilterQuery<any>\n\n if (typeof where === 'object') {\n // We need to determine if the whereKey is an AND, OR, or a schema path\n for (const relationOrPath of Object.keys(where)) {\n const condition = where[relationOrPath]\n let conditionOperator: '$and' | '$or'\n if (relationOrPath.toLowerCase() === 'and') {\n conditionOperator = '$and'\n } else if (relationOrPath.toLowerCase() === 'or') {\n conditionOperator = '$or'\n }\n if (Array.isArray(condition)) {\n const builtConditions = await buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where: condition,\n })\n if (builtConditions.length > 0) {\n result[conditionOperator] = builtConditions\n }\n } else {\n // It's a path - and there can be multiple comparisons on a single path.\n // For example - title like 'test' and title not equal to 'tester'\n // So we need to loop on keys again here to handle each operator independently\n const pathOperators = where[relationOrPath]\n if (typeof pathOperators === 'object') {\n for (const operator of Object.keys(pathOperators)) {\n if (validOperators.includes(operator as Operator)) {\n const searchParam = await buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: relationOrPath,\n locale,\n operator,\n payload,\n val: pathOperators[operator],\n })\n\n if (searchParam?.value && searchParam?.path) {\n result = {\n ...result,\n [searchParam.path]: searchParam.value,\n }\n } else if (typeof searchParam?.value === 'object') {\n result = deepMergeWithCombinedArrays(result, searchParam.value, {\n // dont clone Types.ObjectIDs\n clone: false,\n })\n }\n }\n }\n }\n }\n }\n }\n\n return result\n}\n"],"names":["deepMergeWithCombinedArrays","validOperators","buildAndOrConditions","buildSearchParam","parseParams","collectionSlug","fields","globalSlug","locale","payload","where","result","relationOrPath","Object","keys","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","length","pathOperators","operator","includes","searchParam","incomingPath","val","value","path","clone"],"mappings":"AAGA,SAASA,2BAA2B,QAAQ,UAAS;AACrD,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,gBAAgB,QAAQ,yBAAwB;AAEzD,OAAO,eAAeC,YAAY,EAChCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EAQN;IACC,IAAIC,SAAS,CAAC;IAEd,IAAI,OAAOD,UAAU,UAAU;QAC7B,uEAAuE;QACvE,KAAK,MAAME,kBAAkBC,OAAOC,IAAI,CAACJ,OAAQ;YAC/C,MAAMK,YAAYL,KAAK,CAACE,eAAe;YACvC,IAAII;YACJ,IAAIJ,eAAeK,WAAW,OAAO,OAAO;gBAC1CD,oBAAoB;YACtB,OAAO,IAAIJ,eAAeK,WAAW,OAAO,MAAM;gBAChDD,oBAAoB;YACtB;YACA,IAAIE,MAAMC,OAAO,CAACJ,YAAY;gBAC5B,MAAMK,kBAAkB,MAAMlB,qBAAqB;oBACjDG;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC,OAAOK;gBACT;gBACA,IAAIK,gBAAgBC,MAAM,GAAG,GAAG;oBAC9BV,MAAM,CAACK,kBAAkB,GAAGI;gBAC9B;YACF,OAAO;gBACL,wEAAwE;gBACxE,kEAAkE;gBAClE,8EAA8E;gBAC9E,MAAME,gBAAgBZ,KAAK,CAACE,eAAe;gBAC3C,IAAI,OAAOU,kBAAkB,UAAU;oBACrC,KAAK,MAAMC,YAAYV,OAAOC,IAAI,CAACQ,eAAgB;wBACjD,IAAIrB,eAAeuB,QAAQ,CAACD,WAAuB;4BACjD,MAAME,cAAc,MAAMtB,iBAAiB;gCACzCE;gCACAC;gCACAC;gCACAmB,cAAcd;gCACdJ;gCACAe;gCACAd;gCACAkB,KAAKL,aAAa,CAACC,SAAS;4BAC9B;4BAEA,IAAIE,aAAaG,SAASH,aAAaI,MAAM;gCAC3ClB,SAAS;oCACP,GAAGA,MAAM;oCACT,CAACc,YAAYI,IAAI,CAAC,EAAEJ,YAAYG,KAAK;gCACvC;4BACF,OAAO,IAAI,OAAOH,aAAaG,UAAU,UAAU;gCACjDjB,SAASX,4BAA4BW,QAAQc,YAAYG,KAAK,EAAE;oCAC9D,6BAA6B;oCAC7BE,OAAO;gCACT;4BACF;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOnB;AACT"}
@@ -1,4 +1,4 @@
1
- import type { Field, TabAsField } from 'payload/types';
1
+ import type { Field, TabAsField } from 'payload';
2
2
  type SanitizeQueryValueArgs = {
3
3
  field: Field | TabAsField;
4
4
  hasCustomID: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAKtD,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AAED,eAAO,MAAM,kBAAkB,iDAM5B,sBAAsB,KAAG;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;CAgKd,CAAA"}
1
+ {"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAKhD,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AA0BD,eAAO,MAAM,kBAAkB,iDAM5B,sBAAsB,KAAG;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;CAsOd,CAAA"}