@payloadcms/db-postgres 3.0.0-canary.cee5702 → 3.0.0-canary.d6053cd

Sign up to get free protection for your applications and to get access to all the features.
Files changed (271) 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.map +1 -1
  5. package/dist/count.d.ts +1 -1
  6. package/dist/count.d.ts.map +1 -1
  7. package/dist/count.js +1 -1
  8. package/dist/count.js.map +1 -1
  9. package/dist/create.d.ts +1 -1
  10. package/dist/create.d.ts.map +1 -1
  11. package/dist/create.js +1 -1
  12. package/dist/create.js.map +1 -1
  13. package/dist/createGlobal.d.ts +2 -3
  14. package/dist/createGlobal.d.ts.map +1 -1
  15. package/dist/createGlobal.js +1 -1
  16. package/dist/createGlobal.js.map +1 -1
  17. package/dist/createGlobalVersion.d.ts +2 -4
  18. package/dist/createGlobalVersion.d.ts.map +1 -1
  19. package/dist/createGlobalVersion.js +2 -2
  20. package/dist/createGlobalVersion.js.map +1 -1
  21. package/dist/createMigration.d.ts +1 -1
  22. package/dist/createMigration.d.ts.map +1 -1
  23. package/dist/createMigration.js +3 -3
  24. package/dist/createMigration.js.map +1 -1
  25. package/dist/createVersion.d.ts +1 -2
  26. package/dist/createVersion.d.ts.map +1 -1
  27. package/dist/createVersion.js +2 -2
  28. package/dist/createVersion.js.map +1 -1
  29. package/dist/deleteMany.d.ts +1 -1
  30. package/dist/deleteMany.d.ts.map +1 -1
  31. package/dist/deleteMany.js +1 -1
  32. package/dist/deleteMany.js.map +1 -1
  33. package/dist/deleteOne.d.ts +1 -1
  34. package/dist/deleteOne.d.ts.map +1 -1
  35. package/dist/deleteOne.js +1 -1
  36. package/dist/deleteOne.js.map +1 -1
  37. package/dist/deleteVersions.d.ts +1 -1
  38. package/dist/deleteVersions.d.ts.map +1 -1
  39. package/dist/deleteVersions.js +2 -2
  40. package/dist/deleteVersions.js.map +1 -1
  41. package/dist/destroy.d.ts +1 -1
  42. package/dist/destroy.d.ts.map +1 -1
  43. package/dist/destroy.js.map +1 -1
  44. package/dist/exports/migration-utils.js.map +1 -1
  45. package/dist/find/buildFindManyArgs.d.ts +1 -1
  46. package/dist/find/buildFindManyArgs.d.ts.map +1 -1
  47. package/dist/find/buildFindManyArgs.js.map +1 -1
  48. package/dist/find/chainMethods.d.ts.map +1 -1
  49. package/dist/find/chainMethods.js.map +1 -1
  50. package/dist/find/findMany.d.ts +1 -2
  51. package/dist/find/findMany.d.ts.map +1 -1
  52. package/dist/find/findMany.js +1 -1
  53. package/dist/find/findMany.js.map +1 -1
  54. package/dist/find/traverseFields.d.ts +1 -1
  55. package/dist/find/traverseFields.d.ts.map +1 -1
  56. package/dist/find/traverseFields.js +1 -1
  57. package/dist/find/traverseFields.js.map +1 -1
  58. package/dist/find.d.ts +1 -1
  59. package/dist/find.d.ts.map +1 -1
  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.map +1 -1
  64. package/dist/findGlobalVersions.d.ts +1 -1
  65. package/dist/findGlobalVersions.d.ts.map +1 -1
  66. package/dist/findGlobalVersions.js +1 -1
  67. package/dist/findGlobalVersions.js.map +1 -1
  68. package/dist/findOne.d.ts +1 -2
  69. package/dist/findOne.d.ts.map +1 -1
  70. package/dist/findOne.js.map +1 -1
  71. package/dist/findVersions.d.ts +1 -1
  72. package/dist/findVersions.d.ts.map +1 -1
  73. package/dist/findVersions.js +1 -1
  74. package/dist/findVersions.js.map +1 -1
  75. package/dist/index.d.ts +1 -1
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js +1 -1
  78. package/dist/index.js.map +1 -1
  79. package/dist/init.d.ts +1 -1
  80. package/dist/init.d.ts.map +1 -1
  81. package/dist/init.js +1 -1
  82. package/dist/init.js.map +1 -1
  83. package/dist/migrate.d.ts.map +1 -1
  84. package/dist/migrate.js +1 -1
  85. package/dist/migrate.js.map +1 -1
  86. package/dist/migrateDown.js +1 -1
  87. package/dist/migrateDown.js.map +1 -1
  88. package/dist/migrateFresh.d.ts.map +1 -1
  89. package/dist/migrateFresh.js +1 -1
  90. package/dist/migrateFresh.js.map +1 -1
  91. package/dist/migrateRefresh.js +1 -1
  92. package/dist/migrateRefresh.js.map +1 -1
  93. package/dist/migrateReset.js +1 -1
  94. package/dist/migrateReset.js.map +1 -1
  95. package/dist/migrateStatus.js +1 -1
  96. package/dist/migrateStatus.js.map +1 -1
  97. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -1
  98. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +2 -3
  99. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
  100. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +0 -1
  101. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
  102. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +1 -1
  103. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -1
  104. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +1 -1
  105. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -1
  106. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -1
  107. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -1
  108. package/dist/predefinedMigrations/v2-v3/index.d.ts +2 -3
  109. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -1
  110. package/dist/predefinedMigrations/v2-v3/index.js +6 -6
  111. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -1
  112. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +2 -2
  113. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -1
  114. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -1
  115. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +1 -2
  116. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -1
  117. package/dist/predefinedMigrations/v2-v3/traverseFields.js +1 -1
  118. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -1
  119. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -1
  120. package/dist/queries/buildAndOrConditions.d.ts +1 -1
  121. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  122. package/dist/queries/buildAndOrConditions.js.map +1 -1
  123. package/dist/queries/buildQuery.d.ts +1 -1
  124. package/dist/queries/buildQuery.d.ts.map +1 -1
  125. package/dist/queries/buildQuery.js.map +1 -1
  126. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +1 -1
  127. package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +1 -1
  128. package/dist/queries/createJSONQuery/index.js.map +1 -1
  129. package/dist/queries/getTableColumnFromPath.d.ts +1 -1
  130. package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
  131. package/dist/queries/getTableColumnFromPath.js +2 -3
  132. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  133. package/dist/queries/operatorMap.js.map +1 -1
  134. package/dist/queries/parseParams.d.ts +1 -1
  135. package/dist/queries/parseParams.d.ts.map +1 -1
  136. package/dist/queries/parseParams.js +2 -2
  137. package/dist/queries/parseParams.js.map +1 -1
  138. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  139. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  140. package/dist/queries/sanitizeQueryValue.js +2 -3
  141. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  142. package/dist/queries/selectDistinct.d.ts.map +1 -1
  143. package/dist/queries/selectDistinct.js.map +1 -1
  144. package/dist/queryDrafts.d.ts +1 -1
  145. package/dist/queryDrafts.d.ts.map +1 -1
  146. package/dist/queryDrafts.js +1 -2
  147. package/dist/queryDrafts.js.map +1 -1
  148. package/dist/schema/build.d.ts +1 -1
  149. package/dist/schema/build.d.ts.map +1 -1
  150. package/dist/schema/build.js.map +1 -1
  151. package/dist/schema/createIndex.js.map +1 -1
  152. package/dist/schema/createTableName.d.ts +1 -1
  153. package/dist/schema/createTableName.d.ts.map +1 -1
  154. package/dist/schema/createTableName.js +1 -1
  155. package/dist/schema/createTableName.js.map +1 -1
  156. package/dist/schema/idToUUID.d.ts +1 -1
  157. package/dist/schema/idToUUID.d.ts.map +1 -1
  158. package/dist/schema/idToUUID.js.map +1 -1
  159. package/dist/schema/parentIDColumnMap.js.map +1 -1
  160. package/dist/schema/setColumnID.d.ts +1 -1
  161. package/dist/schema/setColumnID.d.ts.map +1 -1
  162. package/dist/schema/setColumnID.js +2 -2
  163. package/dist/schema/setColumnID.js.map +1 -1
  164. package/dist/schema/traverseFields.d.ts +1 -1
  165. package/dist/schema/traverseFields.d.ts.map +1 -1
  166. package/dist/schema/traverseFields.js +2 -2
  167. package/dist/schema/traverseFields.js.map +1 -1
  168. package/dist/schema/validateExistingBlockIsIdentical.d.ts +1 -1
  169. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +1 -1
  170. package/dist/schema/validateExistingBlockIsIdentical.js +2 -2
  171. package/dist/schema/validateExistingBlockIsIdentical.js.map +1 -1
  172. package/dist/transactions/beginTransaction.d.ts +1 -1
  173. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  174. package/dist/transactions/beginTransaction.js.map +1 -1
  175. package/dist/transactions/commitTransaction.d.ts +1 -1
  176. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  177. package/dist/transactions/commitTransaction.js +1 -0
  178. package/dist/transactions/commitTransaction.js.map +1 -1
  179. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  180. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  181. package/dist/transactions/rollbackTransaction.js +5 -4
  182. package/dist/transactions/rollbackTransaction.js.map +1 -1
  183. package/dist/transform/read/hasManyNumber.d.ts +1 -1
  184. package/dist/transform/read/hasManyNumber.d.ts.map +1 -1
  185. package/dist/transform/read/hasManyNumber.js.map +1 -1
  186. package/dist/transform/read/hasManyText.d.ts +1 -1
  187. package/dist/transform/read/hasManyText.d.ts.map +1 -1
  188. package/dist/transform/read/hasManyText.js.map +1 -1
  189. package/dist/transform/read/index.d.ts +2 -3
  190. package/dist/transform/read/index.d.ts.map +1 -1
  191. package/dist/transform/read/index.js.map +1 -1
  192. package/dist/transform/read/relationship.d.ts +1 -1
  193. package/dist/transform/read/relationship.d.ts.map +1 -1
  194. package/dist/transform/read/relationship.js.map +1 -1
  195. package/dist/transform/read/traverseFields.d.ts +2 -2
  196. package/dist/transform/read/traverseFields.d.ts.map +1 -1
  197. package/dist/transform/read/traverseFields.js +1 -1
  198. package/dist/transform/read/traverseFields.js.map +1 -1
  199. package/dist/transform/write/array.d.ts +1 -1
  200. package/dist/transform/write/array.d.ts.map +1 -1
  201. package/dist/transform/write/array.js.map +1 -1
  202. package/dist/transform/write/blocks.d.ts +1 -1
  203. package/dist/transform/write/blocks.d.ts.map +1 -1
  204. package/dist/transform/write/blocks.js.map +1 -1
  205. package/dist/transform/write/index.d.ts +1 -1
  206. package/dist/transform/write/index.d.ts.map +1 -1
  207. package/dist/transform/write/index.js.map +1 -1
  208. package/dist/transform/write/numbers.js.map +1 -1
  209. package/dist/transform/write/relationships.d.ts +1 -1
  210. package/dist/transform/write/relationships.d.ts.map +1 -1
  211. package/dist/transform/write/relationships.js +1 -1
  212. package/dist/transform/write/relationships.js.map +1 -1
  213. package/dist/transform/write/selects.js.map +1 -1
  214. package/dist/transform/write/texts.js.map +1 -1
  215. package/dist/transform/write/traverseFields.d.ts +1 -1
  216. package/dist/transform/write/traverseFields.d.ts.map +1 -1
  217. package/dist/transform/write/traverseFields.js +1 -1
  218. package/dist/transform/write/traverseFields.js.map +1 -1
  219. package/dist/transform/write/types.js.map +1 -1
  220. package/dist/types.d.ts +3 -5
  221. package/dist/types.d.ts.map +1 -1
  222. package/dist/types.js.map +1 -1
  223. package/dist/update.d.ts +1 -1
  224. package/dist/update.d.ts.map +1 -1
  225. package/dist/update.js +1 -1
  226. package/dist/update.js.map +1 -1
  227. package/dist/updateGlobal.d.ts +2 -3
  228. package/dist/updateGlobal.d.ts.map +1 -1
  229. package/dist/updateGlobal.js +1 -1
  230. package/dist/updateGlobal.js.map +1 -1
  231. package/dist/updateGlobalVersion.d.ts +1 -2
  232. package/dist/updateGlobalVersion.d.ts.map +1 -1
  233. package/dist/updateGlobalVersion.js +2 -2
  234. package/dist/updateGlobalVersion.js.map +1 -1
  235. package/dist/updateVersion.d.ts +1 -2
  236. package/dist/updateVersion.d.ts.map +1 -1
  237. package/dist/updateVersion.js +2 -2
  238. package/dist/updateVersion.js.map +1 -1
  239. package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +1 -1
  240. package/dist/upsertRow/deleteExistingArrayRows.js.map +1 -1
  241. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
  242. package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -1
  243. package/dist/upsertRow/index.d.ts +2 -2
  244. package/dist/upsertRow/index.d.ts.map +1 -1
  245. package/dist/upsertRow/index.js +9 -7
  246. package/dist/upsertRow/index.js.map +1 -1
  247. package/dist/upsertRow/insertArrays.d.ts.map +1 -1
  248. package/dist/upsertRow/insertArrays.js.map +1 -1
  249. package/dist/upsertRow/types.d.ts +2 -2
  250. package/dist/upsertRow/types.d.ts.map +1 -1
  251. package/dist/upsertRow/types.js.map +1 -1
  252. package/dist/utilities/appendPrefixToKeys.d.ts.map +1 -1
  253. package/dist/utilities/appendPrefixToKeys.js.map +1 -1
  254. package/dist/utilities/createBlocksMap.d.ts.map +1 -1
  255. package/dist/utilities/createBlocksMap.js.map +1 -1
  256. package/dist/utilities/createMigrationTable.d.ts.map +1 -1
  257. package/dist/utilities/createMigrationTable.js.map +1 -1
  258. package/dist/utilities/createRelationshipMap.d.ts.map +1 -1
  259. package/dist/utilities/createRelationshipMap.js.map +1 -1
  260. package/dist/utilities/hasLocalesTable.d.ts +1 -1
  261. package/dist/utilities/hasLocalesTable.d.ts.map +1 -1
  262. package/dist/utilities/hasLocalesTable.js +1 -1
  263. package/dist/utilities/hasLocalesTable.js.map +1 -1
  264. package/dist/utilities/isArrayOfRows.js.map +1 -1
  265. package/dist/utilities/migrationTableExists.d.ts.map +1 -1
  266. package/dist/utilities/migrationTableExists.js.map +1 -1
  267. package/dist/utilities/parseError.js.map +1 -1
  268. package/dist/utilities/pushDevSchema.d.ts.map +1 -1
  269. package/dist/utilities/pushDevSchema.js +1 -1
  270. package/dist/utilities/pushDevSchema.js.map +1 -1
  271. package/package.json +16 -13
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/queries/createJSONQuery/convertPathToJSONTraversal.ts"],"sourcesContent":["import { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nexport const convertPathToJSONTraversal = (incomingSegments: string[]) => {\n const segments = [...incomingSegments]\n segments.shift()\n\n return segments.reduce((res, segment, i) => {\n const formattedSegment = formatJSONPathSegment(segment)\n\n if (i + 1 === segments.length) return `${res}->>${formattedSegment}`\n return `${res}->${formattedSegment}`\n }, '')\n}\n"],"names":["formatJSONPathSegment","convertPathToJSONTraversal","incomingSegments","segments","shift","reduce","res","segment","i","formattedSegment","length"],"rangeMappings":";;;;;;;;;;;","mappings":"AAAA,SAASA,qBAAqB,QAAQ,6BAA4B;AAElE,OAAO,MAAMC,6BAA6B,CAACC;IACzC,MAAMC,WAAW;WAAID;KAAiB;IACtCC,SAASC,KAAK;IAEd,OAAOD,SAASE,MAAM,CAAC,CAACC,KAAKC,SAASC;QACpC,MAAMC,mBAAmBT,sBAAsBO;QAE/C,IAAIC,IAAI,MAAML,SAASO,MAAM,EAAE,OAAO,CAAC,EAAEJ,IAAI,GAAG,EAAEG,iBAAiB,CAAC;QACpE,OAAO,CAAC,EAAEH,IAAI,EAAE,EAAEG,iBAAiB,CAAC;IACtC,GAAG;AACL,EAAC"}
1
+ {"version":3,"sources":["../../../src/queries/createJSONQuery/convertPathToJSONTraversal.ts"],"sourcesContent":["import { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nexport const convertPathToJSONTraversal = (incomingSegments: string[]) => {\n const segments = [...incomingSegments]\n segments.shift()\n\n return segments.reduce((res, segment, i) => {\n const formattedSegment = formatJSONPathSegment(segment)\n\n if (i + 1 === segments.length) return `${res}->>${formattedSegment}`\n return `${res}->${formattedSegment}`\n }, '')\n}\n"],"names":["formatJSONPathSegment","convertPathToJSONTraversal","incomingSegments","segments","shift","reduce","res","segment","i","formattedSegment","length"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,6BAA4B;AAElE,OAAO,MAAMC,6BAA6B,CAACC;IACzC,MAAMC,WAAW;WAAID;KAAiB;IACtCC,SAASC,KAAK;IAEd,OAAOD,SAASE,MAAM,CAAC,CAACC,KAAKC,SAASC;QACpC,MAAMC,mBAAmBT,sBAAsBO;QAE/C,IAAIC,IAAI,MAAML,SAASO,MAAM,EAAE,OAAO,CAAC,EAAEJ,IAAI,GAAG,EAAEG,iBAAiB,CAAC;QACpE,OAAO,CAAC,EAAEH,IAAI,EAAE,EAAEG,iBAAiB,CAAC;IACtC,GAAG;AACL,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/queries/createJSONQuery/formatJSONPathSegment.ts"],"sourcesContent":["export const formatJSONPathSegment = (segment: string) => {\n return Number.isNaN(parseInt(segment)) ? `'${segment}'` : segment\n}\n"],"names":["formatJSONPathSegment","segment","Number","isNaN","parseInt"],"rangeMappings":";;","mappings":"AAAA,OAAO,MAAMA,wBAAwB,CAACC;IACpC,OAAOC,OAAOC,KAAK,CAACC,SAASH,YAAY,CAAC,CAAC,EAAEA,QAAQ,CAAC,CAAC,GAAGA;AAC5D,EAAC"}
1
+ {"version":3,"sources":["../../../src/queries/createJSONQuery/formatJSONPathSegment.ts"],"sourcesContent":["export const formatJSONPathSegment = (segment: string) => {\n return Number.isNaN(parseInt(segment)) ? `'${segment}'` : segment\n}\n"],"names":["formatJSONPathSegment","segment","Number","isNaN","parseInt"],"mappings":"AAAA,OAAO,MAAMA,wBAAwB,CAACC;IACpC,OAAOC,OAAOC,KAAK,CAACC,SAASH,YAAY,CAAC,CAAC,EAAEA,QAAQ,CAAC,CAAC,GAAGA;AAC5D,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/queries/createJSONQuery/index.ts"],"sourcesContent":["import { convertPathToJSONTraversal } from './convertPathToJSONTraversal.js'\nimport { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nconst operatorMap = {\n contains: '~*',\n equals: '=',\n like: '~*',\n}\n\ntype FromArrayArgs = {\n isRoot?: true\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: unknown\n}\n\nconst fromArray = ({ isRoot, operator, pathSegments, treatAsArray, value }: FromArrayArgs) => {\n const newPathSegments = pathSegments.slice(isRoot ? 1 : 2)\n const alias = `${pathSegments[isRoot ? 0 : 1]}_alias_${newPathSegments.length}`\n\n newPathSegments.unshift(alias)\n\n const arrayElements = isRoot\n ? pathSegments[0]\n : `${pathSegments[0]} -> ${formatJSONPathSegment(pathSegments[1])}`\n\n return `EXISTS (\n SELECT 1\n FROM jsonb_array_elements(${arrayElements}) AS ${alias}\n WHERE ${createJSONQuery({\n operator,\n pathSegments: newPathSegments,\n treatAsArray,\n value,\n })}\n )`\n}\n\ntype CreateConstraintArgs = {\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: unknown\n}\n\nconst createConstraint = ({ operator, pathSegments, value }: CreateConstraintArgs): string => {\n const jsonQuery = convertPathToJSONTraversal(pathSegments)\n return `${pathSegments[0]}${jsonQuery} ${operatorMap[operator]} '${value}'`\n}\n\ntype Args = {\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n treatRootAsArray?: boolean\n value: unknown\n}\n\nexport const createJSONQuery = ({\n operator,\n pathSegments,\n treatAsArray,\n treatRootAsArray,\n value,\n}: Args): string => {\n if (treatRootAsArray) {\n return fromArray({\n isRoot: true,\n operator,\n pathSegments,\n treatAsArray,\n value,\n })\n }\n\n if (treatAsArray.includes(pathSegments[1])) {\n return fromArray({\n operator,\n pathSegments,\n treatAsArray,\n value,\n })\n }\n\n return createConstraint({ operator, pathSegments, treatAsArray, value })\n}\n"],"names":["convertPathToJSONTraversal","formatJSONPathSegment","operatorMap","contains","equals","like","fromArray","isRoot","operator","pathSegments","treatAsArray","value","newPathSegments","slice","alias","length","unshift","arrayElements","createJSONQuery","createConstraint","jsonQuery","treatRootAsArray","includes"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,0BAA0B,QAAQ,kCAAiC;AAC5E,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE,MAAMC,cAAc;IAClBC,UAAU;IACVC,QAAQ;IACRC,MAAM;AACR;AAUA,MAAMC,YAAY,CAAC,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,YAAY,EAAEC,KAAK,EAAiB;IACvF,MAAMC,kBAAkBH,aAAaI,KAAK,CAACN,SAAS,IAAI;IACxD,MAAMO,QAAQ,CAAC,EAAEL,YAAY,CAACF,SAAS,IAAI,EAAE,CAAC,OAAO,EAAEK,gBAAgBG,MAAM,CAAC,CAAC;IAE/EH,gBAAgBI,OAAO,CAACF;IAExB,MAAMG,gBAAgBV,SAClBE,YAAY,CAAC,EAAE,GACf,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,IAAI,EAAER,sBAAsBQ,YAAY,CAAC,EAAE,EAAE,CAAC;IAErE,OAAO,CAAC;;8BAEoB,EAAEQ,cAAc,KAAK,EAAEH,MAAM;UACjD,EAAEI,gBAAgB;QACtBV;QACAC,cAAcG;QACdF;QACAC;IACF,GAAG;GACJ,CAAC;AACJ;AASA,MAAMQ,mBAAmB,CAAC,EAAEX,QAAQ,EAAEC,YAAY,EAAEE,KAAK,EAAwB;IAC/E,MAAMS,YAAYpB,2BAA2BS;IAC7C,OAAO,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,EAAEW,UAAU,CAAC,EAAElB,WAAW,CAACM,SAAS,CAAC,EAAE,EAAEG,MAAM,CAAC,CAAC;AAC7E;AAUA,OAAO,MAAMO,kBAAkB,CAAC,EAC9BV,QAAQ,EACRC,YAAY,EACZC,YAAY,EACZW,gBAAgB,EAChBV,KAAK,EACA;IACL,IAAIU,kBAAkB;QACpB,OAAOf,UAAU;YACfC,QAAQ;YACRC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,IAAID,aAAaY,QAAQ,CAACb,YAAY,CAAC,EAAE,GAAG;QAC1C,OAAOH,UAAU;YACfE;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAOQ,iBAAiB;QAAEX;QAAUC;QAAcC;QAAcC;IAAM;AACxE,EAAC"}
1
+ {"version":3,"sources":["../../../src/queries/createJSONQuery/index.ts"],"sourcesContent":["import { convertPathToJSONTraversal } from './convertPathToJSONTraversal.js'\nimport { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nconst operatorMap = {\n contains: '~*',\n equals: '=',\n like: '~*',\n}\n\ntype FromArrayArgs = {\n isRoot?: true\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: unknown\n}\n\nconst fromArray = ({ isRoot, operator, pathSegments, treatAsArray, value }: FromArrayArgs) => {\n const newPathSegments = pathSegments.slice(isRoot ? 1 : 2)\n const alias = `${pathSegments[isRoot ? 0 : 1]}_alias_${newPathSegments.length}`\n\n newPathSegments.unshift(alias)\n\n const arrayElements = isRoot\n ? pathSegments[0]\n : `${pathSegments[0]} -> ${formatJSONPathSegment(pathSegments[1])}`\n\n return `EXISTS (\n SELECT 1\n FROM jsonb_array_elements(${arrayElements}) AS ${alias}\n WHERE ${createJSONQuery({\n operator,\n pathSegments: newPathSegments,\n treatAsArray,\n value,\n })}\n )`\n}\n\ntype CreateConstraintArgs = {\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: unknown\n}\n\nconst createConstraint = ({ operator, pathSegments, value }: CreateConstraintArgs): string => {\n const jsonQuery = convertPathToJSONTraversal(pathSegments)\n return `${pathSegments[0]}${jsonQuery} ${operatorMap[operator]} '${value}'`\n}\n\ntype Args = {\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n treatRootAsArray?: boolean\n value: unknown\n}\n\nexport const createJSONQuery = ({\n operator,\n pathSegments,\n treatAsArray,\n treatRootAsArray,\n value,\n}: Args): string => {\n if (treatRootAsArray) {\n return fromArray({\n isRoot: true,\n operator,\n pathSegments,\n treatAsArray,\n value,\n })\n }\n\n if (treatAsArray.includes(pathSegments[1])) {\n return fromArray({\n operator,\n pathSegments,\n treatAsArray,\n value,\n })\n }\n\n return createConstraint({ operator, pathSegments, treatAsArray, value })\n}\n"],"names":["convertPathToJSONTraversal","formatJSONPathSegment","operatorMap","contains","equals","like","fromArray","isRoot","operator","pathSegments","treatAsArray","value","newPathSegments","slice","alias","length","unshift","arrayElements","createJSONQuery","createConstraint","jsonQuery","treatRootAsArray","includes"],"mappings":"AAAA,SAASA,0BAA0B,QAAQ,kCAAiC;AAC5E,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE,MAAMC,cAAc;IAClBC,UAAU;IACVC,QAAQ;IACRC,MAAM;AACR;AAUA,MAAMC,YAAY,CAAC,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,YAAY,EAAEC,KAAK,EAAiB;IACvF,MAAMC,kBAAkBH,aAAaI,KAAK,CAACN,SAAS,IAAI;IACxD,MAAMO,QAAQ,CAAC,EAAEL,YAAY,CAACF,SAAS,IAAI,EAAE,CAAC,OAAO,EAAEK,gBAAgBG,MAAM,CAAC,CAAC;IAE/EH,gBAAgBI,OAAO,CAACF;IAExB,MAAMG,gBAAgBV,SAClBE,YAAY,CAAC,EAAE,GACf,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,IAAI,EAAER,sBAAsBQ,YAAY,CAAC,EAAE,EAAE,CAAC;IAErE,OAAO,CAAC;;8BAEoB,EAAEQ,cAAc,KAAK,EAAEH,MAAM;UACjD,EAAEI,gBAAgB;QACtBV;QACAC,cAAcG;QACdF;QACAC;IACF,GAAG;GACJ,CAAC;AACJ;AASA,MAAMQ,mBAAmB,CAAC,EAAEX,QAAQ,EAAEC,YAAY,EAAEE,KAAK,EAAwB;IAC/E,MAAMS,YAAYpB,2BAA2BS;IAC7C,OAAO,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,EAAEW,UAAU,CAAC,EAAElB,WAAW,CAACM,SAAS,CAAC,EAAE,EAAEG,MAAM,CAAC,CAAC;AAC7E;AAUA,OAAO,MAAMO,kBAAkB,CAAC,EAC9BV,QAAQ,EACRC,YAAY,EACZC,YAAY,EACZW,gBAAgB,EAChBV,KAAK,EACA;IACL,IAAIU,kBAAkB;QACpB,OAAOf,UAAU;YACfC,QAAQ;YACRC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,IAAID,aAAaY,QAAQ,CAACb,YAAY,CAAC,EAAE,GAAG;QAC1C,OAAOH,UAAU;YACfE;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAOQ,iBAAiB;QAAEX;QAAUC;QAAcC;QAAcC;IAAM;AACxE,EAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { SQL } from 'drizzle-orm';
2
2
  import type { PgTableWithColumns } from 'drizzle-orm/pg-core';
3
- import type { Field, FieldAffectingData, TabAsField } from 'payload/types';
3
+ import type { Field, FieldAffectingData, TabAsField } from 'payload';
4
4
  import type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js';
5
5
  import type { BuildQueryJoinAliases } from './buildQuery.js';
6
6
  type Constraint = {
@@ -1 +1 @@
1
- {"version":3,"file":"getTableColumnFromPath.d.ts","sourceRoot":"","sources":["../../src/queries/getTableColumnFromPath.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAA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C,CAAA;IACnD,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAA;IAC1B,MAAM,EAAE,CAAC,KAAK,GAAG,UAAU,CAAC,EAAE,CAAA;IAC9B,KAAK,EAAE,qBAAqB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;OAEG;IACH,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AACD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,8QAgBhC,IAAI,KAAG,WAykBT,CAAA"}
@@ -1,8 +1,7 @@
1
1
  /* eslint-disable no-param-reassign */ import { and, eq, like, sql } from 'drizzle-orm';
2
2
  import { alias } from 'drizzle-orm/pg-core';
3
- import { APIError } from 'payload/errors';
4
- import { fieldAffectsData, tabHasName } from 'payload/types';
5
- import { flattenTopLevelFields } from 'payload/utilities';
3
+ import { APIError, flattenTopLevelFields } from 'payload';
4
+ import { fieldAffectsData, tabHasName } from 'payload/shared';
6
5
  import toSnakeCase from 'to-snake-case';
7
6
  import { v4 as uuid } from 'uuid';
8
7
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/getTableColumnFromPath.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, FieldAffectingData, NumberField, TabAsField, TextField } from 'payload/types'\n\nimport { and, eq, like, sql } from 'drizzle-orm'\nimport { alias } from 'drizzle-orm/pg-core'\nimport { APIError } from 'payload/errors'\nimport { fieldAffectsData, tabHasName } from 'payload/types'\nimport { flattenTopLevelFields } from 'payload/utilities'\nimport toSnakeCase from 'to-snake-case'\nimport { v4 as uuid } from 'uuid'\n\nimport type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\ntype Constraint = {\n columnName: string\n table: GenericTable | PgTableWithColumns<any>\n value: unknown\n}\n\ntype TableColumn = {\n columnName?: string\n constraints: Constraint[]\n field: FieldAffectingData\n getNotNullColumnByValue?: (val: unknown) => string\n pathSegments?: string[]\n rawColumn?: SQL\n table: GenericTable | PgTableWithColumns<any>\n}\n\ntype Args = {\n adapter: PostgresAdapter\n aliasTable?: GenericTable | PgTableWithColumns<any>\n collectionPath: string\n columnPrefix?: string\n constraintPath?: string\n constraints?: Constraint[]\n fields: (Field | TabAsField)[]\n joins: BuildQueryJoinAliases\n locale?: string\n pathSegments: string[]\n rootTableName?: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n /**\n * If creating a new table name for arrays and blocks, this suffix should be appended to the table name\n */\n tableNameSuffix?: string\n /**\n * The raw value of the query before sanitization\n */\n value: unknown\n}\n/**\n * Transforms path to table and column name\n * Adds tables to `join`\n * @returns TableColumn\n */\nexport const getTableColumnFromPath = ({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix = '',\n constraintPath: incomingConstraintPath,\n constraints = [],\n fields,\n joins,\n locale: incomingLocale,\n pathSegments: incomingSegments,\n rootTableName: incomingRootTableName,\n selectFields,\n tableName,\n tableNameSuffix = '',\n value,\n}: Args): TableColumn => {\n const fieldPath = incomingSegments[0]\n let locale = incomingLocale\n const rootTableName = incomingRootTableName || tableName\n let constraintPath = incomingConstraintPath || ''\n\n const field = flattenTopLevelFields(fields as Field[]).find(\n (fieldToFind) => fieldAffectsData(fieldToFind) && fieldToFind.name === fieldPath,\n ) as Field | TabAsField\n let newTableName = tableName\n\n if (!field && fieldPath === 'id') {\n selectFields.id = adapter.tables[newTableName].id\n return {\n columnName: 'id',\n constraints,\n field: {\n name: 'id',\n type: adapter.idType === 'uuid' ? 'text' : 'number',\n } as NumberField | TextField,\n table: adapter.tables[newTableName],\n }\n }\n\n if (field) {\n const pathSegments = [...incomingSegments]\n\n // If next segment is a locale,\n // we need to take it out and use it as the locale from this point on\n if ('localized' in field && field.localized && adapter.payload.config.localization) {\n const matchedLocale = adapter.payload.config.localization.localeCodes.find(\n (locale) => locale === pathSegments[1],\n )\n\n if (matchedLocale) {\n locale = matchedLocale\n pathSegments.splice(1, 1)\n }\n }\n\n switch (field.type) {\n case 'tabs': {\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix,\n constraintPath,\n constraints,\n fields: field.tabs.map((tab) => ({\n ...tab,\n type: 'tab',\n })),\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix,\n value,\n })\n }\n case 'tab': {\n if (tabHasName(field)) {\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix: `${columnPrefix}${field.name}_`,\n constraintPath: `${constraintPath}${field.name}.`,\n constraints,\n fields: field.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix: `${tableNameSuffix}${toSnakeCase(field.name)}_`,\n value,\n })\n }\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix,\n constraintPath,\n constraints,\n fields: field.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix,\n value,\n })\n }\n\n case 'group': {\n if (locale && field.localized && adapter.payload.config.localization) {\n newTableName = `${tableName}${adapter.localesSuffix}`\n\n joins.push({\n condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),\n table: adapter.tables[newTableName],\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n }\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix: `${columnPrefix}${field.name}_`,\n constraintPath: `${constraintPath}${field.name}.`,\n constraints,\n fields: field.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix: `${tableNameSuffix}${toSnakeCase(field.name)}_`,\n value,\n })\n }\n\n case 'select': {\n if (field.hasMany) {\n const newTableName = adapter.tableNameMap.get(\n `${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`,\n )\n\n if (locale && field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(\n eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),\n eq(adapter.tables[newTableName]._locale, locale),\n ),\n table: adapter.tables[newTableName],\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins.push({\n condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),\n table: adapter.tables[newTableName],\n })\n }\n\n return {\n columnName: 'value',\n constraints,\n field,\n table: adapter.tables[newTableName],\n }\n }\n break\n }\n\n case 'text':\n case 'number': {\n if (field.hasMany) {\n let tableType = 'texts'\n let columnName = 'text'\n if (field.type === 'number') {\n tableType = 'numbers'\n columnName = 'number'\n }\n newTableName = `${tableName}_${tableType}`\n const joinConstraints = [\n eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),\n eq(adapter.tables[newTableName].path, `${constraintPath}${field.name}`),\n ]\n\n if (locale && field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(...joinConstraints, eq(adapter.tables[newTableName]._locale, locale)),\n table: adapter.tables[newTableName],\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: 'locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins.push({\n condition: and(...joinConstraints),\n table: adapter.tables[newTableName],\n })\n }\n\n return {\n columnName,\n constraints,\n field,\n table: adapter.tables[newTableName],\n }\n }\n break\n }\n\n case 'array': {\n newTableName = adapter.tableNameMap.get(\n `${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`,\n )\n\n constraintPath = `${constraintPath}${field.name}.%.`\n if (locale && field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(\n eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),\n eq(adapter.tables[newTableName]._locale, locale),\n ),\n table: adapter.tables[newTableName],\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins.push({\n condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),\n table: adapter.tables[newTableName],\n })\n }\n return getTableColumnFromPath({\n adapter,\n collectionPath,\n constraintPath,\n constraints,\n fields: field.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n value,\n })\n }\n\n case 'blocks': {\n let blockTableColumn: TableColumn\n let newTableName: string\n\n // handle blockType queries\n if (pathSegments[1] === 'blockType') {\n // find the block config using the value\n const blockTypes = Array.isArray(value) ? value : [value]\n blockTypes.forEach((blockType) => {\n const block = field.blocks.find((block) => block.slug === blockType)\n newTableName = adapter.tableNameMap.get(\n `${tableName}_blocks_${toSnakeCase(block.slug)}`,\n )\n const newAliasTableName = toSnakeCase(uuid())\n const newAliasTable = alias(adapter.tables[newTableName], newAliasTableName)\n\n joins.push({\n condition: eq(adapter.tables[tableName].id, newAliasTable._parentID),\n table: newAliasTable,\n })\n constraints.push({\n columnName: '_path',\n table: newAliasTable,\n value: pathSegments[0],\n })\n })\n return {\n constraints,\n field,\n getNotNullColumnByValue: () => 'id',\n table: adapter.tables[tableName],\n }\n }\n\n const hasBlockField = field.blocks.some((block) => {\n newTableName = adapter.tableNameMap.get(`${tableName}_blocks_${toSnakeCase(block.slug)}`)\n constraintPath = `${constraintPath}${field.name}.%.`\n\n let result\n const blockConstraints = []\n const blockSelectFields = {}\n try {\n result = getTableColumnFromPath({\n adapter,\n collectionPath,\n constraintPath,\n constraints: blockConstraints,\n fields: block.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields: blockSelectFields,\n tableName: newTableName,\n value,\n })\n } catch (error) {\n // this is fine, not every block will have the field\n }\n if (!result) {\n return\n }\n blockTableColumn = result\n constraints = constraints.concat(blockConstraints)\n selectFields = { ...selectFields, ...blockSelectFields }\n if (field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(\n eq(\n (aliasTable || adapter.tables[tableName]).id,\n adapter.tables[newTableName]._parentID,\n ),\n eq(adapter.tables[newTableName]._locale, locale),\n ),\n table: adapter.tables[newTableName],\n })\n if (locale) {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins.push({\n condition: eq(\n (aliasTable || adapter.tables[tableName]).id,\n adapter.tables[newTableName]._parentID,\n ),\n table: adapter.tables[newTableName],\n })\n }\n return true\n })\n if (hasBlockField) {\n return {\n columnName: blockTableColumn.columnName,\n constraints,\n field: blockTableColumn.field,\n pathSegments: pathSegments.slice(1),\n rawColumn: blockTableColumn.rawColumn,\n table: blockTableColumn.table,\n }\n }\n break\n }\n\n case 'relationship':\n case 'upload': {\n const newCollectionPath = pathSegments.slice(1).join('.')\n if (Array.isArray(field.relationTo) || (field.type === 'relationship' && field.hasMany)) {\n let relationshipFields\n const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`\n const aliasRelationshipTableName = uuid()\n const aliasRelationshipTable = alias(\n adapter.tables[relationTableName],\n aliasRelationshipTableName,\n )\n\n // Join in the relationships table\n if (locale && field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(\n eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent),\n eq(aliasRelationshipTable.locale, locale),\n like(aliasRelationshipTable.path, `${constraintPath}${field.name}`),\n ),\n table: aliasRelationshipTable,\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: 'locale',\n table: aliasRelationshipTable,\n value: locale,\n })\n }\n } else {\n // Join in the relationships table\n joins.push({\n condition: and(\n eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent),\n like(aliasRelationshipTable.path, `${constraintPath}${field.name}`),\n ),\n table: aliasRelationshipTable,\n })\n }\n\n selectFields[`${relationTableName}.path`] = aliasRelationshipTable.path\n\n let newAliasTable\n\n if (typeof field.relationTo === 'string') {\n const relationshipConfig = adapter.payload.collections[field.relationTo].config\n\n newTableName = adapter.tableNameMap.get(toSnakeCase(relationshipConfig.slug))\n\n // parent to relationship join table\n relationshipFields = relationshipConfig.fields\n\n newAliasTable = alias(adapter.tables[newTableName], toSnakeCase(uuid()))\n\n joins.push({\n condition: eq(newAliasTable.id, aliasRelationshipTable[`${field.relationTo}ID`]),\n table: newAliasTable,\n })\n\n if (newCollectionPath === '' || newCollectionPath === 'id') {\n return {\n columnName: `${field.relationTo}ID`,\n constraints,\n field,\n table: aliasRelationshipTable,\n }\n }\n } else if (newCollectionPath === 'value') {\n const tableColumnsNames = field.relationTo.map((relationTo) => {\n const relationTableName = adapter.tableNameMap.get(\n toSnakeCase(adapter.payload.collections[relationTo].config.slug),\n )\n\n return `\"${aliasRelationshipTableName}\".\"${relationTableName}_id\"`\n })\n return {\n constraints,\n field,\n rawColumn: sql.raw(`COALESCE(${tableColumnsNames.join(', ')})`),\n table: aliasRelationshipTable,\n }\n } else if (newCollectionPath === 'relationTo') {\n const relationTo = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n\n return {\n constraints,\n field,\n getNotNullColumnByValue: (val) => {\n const matchedRelation = relationTo.find((relation) => relation === val)\n if (matchedRelation) return `${matchedRelation}ID`\n return undefined\n },\n table: aliasRelationshipTable,\n }\n } else {\n throw new APIError('Not supported')\n }\n\n return getTableColumnFromPath({\n adapter,\n aliasTable: newAliasTable,\n collectionPath: newCollectionPath,\n constraints,\n fields: relationshipFields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName: newTableName,\n selectFields,\n tableName: newTableName,\n value,\n })\n } else if (\n pathSegments.length > 1 &&\n !(pathSegments.length === 2 && pathSegments[1] === 'id')\n ) {\n // simple relationships\n const columnName = `${columnPrefix}${field.name}`\n const newTableName = adapter.tableNameMap.get(\n toSnakeCase(adapter.payload.collections[field.relationTo].config.slug),\n )\n const aliasTableName = uuid()\n const newAliasTable = alias(adapter.tables[newTableName], aliasTableName)\n\n if (field.localized && adapter.payload.config.localization) {\n const aliasLocaleTableName = uuid()\n const aliasLocaleTable = alias(\n adapter.tables[`${rootTableName}${adapter.localesSuffix}`],\n aliasLocaleTableName,\n )\n joins.push({\n condition: and(\n eq(aliasLocaleTable._parentID, adapter.tables[rootTableName].id),\n eq(aliasLocaleTable._locale, locale),\n ),\n table: aliasLocaleTable,\n })\n joins.push({\n condition: eq(aliasLocaleTable[columnName], newAliasTable.id),\n table: newAliasTable,\n })\n } else {\n joins.push({\n condition: eq(\n newAliasTable.id,\n aliasTable ? aliasTable[columnName] : adapter.tables[tableName][columnName],\n ),\n table: newAliasTable,\n })\n }\n\n return getTableColumnFromPath({\n adapter,\n aliasTable: newAliasTable,\n collectionPath: newCollectionPath,\n constraintPath: '',\n constraints,\n fields: adapter.payload.collections[field.relationTo].config.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n selectFields,\n tableName: newTableName,\n value,\n })\n }\n break\n }\n\n default: {\n // fall through\n break\n }\n }\n\n if (fieldAffectsData(field)) {\n if (field.localized && adapter.payload.config.localization) {\n // If localized, we go to localized table and set aliasTable to undefined\n // so it is not picked up below to be used as targetTable\n const parentTable = aliasTable || adapter.tables[tableName]\n newTableName = `${tableName}${adapter.localesSuffix}`\n\n joins.push({\n condition: eq(parentTable.id, adapter.tables[newTableName]._parentID),\n table: adapter.tables[newTableName],\n })\n\n aliasTable = undefined\n\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n }\n\n const targetTable = aliasTable || adapter.tables[newTableName]\n\n selectFields[`${newTableName}.${columnPrefix}${field.name}`] =\n targetTable[`${columnPrefix}${field.name}`]\n\n return {\n columnName: `${columnPrefix}${field.name}`,\n constraints,\n field,\n pathSegments,\n table: targetTable,\n }\n }\n }\n\n throw new APIError(`Cannot find field for path at ${fieldPath}`)\n}\n"],"names":["and","eq","like","sql","alias","APIError","fieldAffectsData","tabHasName","flattenTopLevelFields","toSnakeCase","v4","uuid","getTableColumnFromPath","adapter","aliasTable","collectionPath","columnPrefix","constraintPath","incomingConstraintPath","constraints","fields","joins","locale","incomingLocale","pathSegments","incomingSegments","rootTableName","incomingRootTableName","selectFields","tableName","tableNameSuffix","value","fieldPath","field","find","fieldToFind","name","newTableName","id","tables","columnName","type","idType","table","localized","payload","config","localization","matchedLocale","localeCodes","splice","tabs","map","tab","slice","localesSuffix","push","condition","_parentID","hasMany","tableNameMap","get","parent","_locale","tableType","joinConstraints","path","blockTableColumn","blockTypes","Array","isArray","forEach","blockType","block","blocks","slug","newAliasTableName","newAliasTable","getNotNullColumnByValue","hasBlockField","some","result","blockConstraints","blockSelectFields","error","concat","rawColumn","newCollectionPath","join","relationTo","relationshipFields","relationTableName","relationshipsSuffix","aliasRelationshipTableName","aliasRelationshipTable","relationshipConfig","collections","tableColumnsNames","raw","val","matchedRelation","relation","undefined","length","aliasTableName","aliasLocaleTableName","aliasLocaleTable","parentTable","targetTable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,QAAQ0B,MAAM,CAACF,aAAa;gBACrC;gBAEAvB,aAAawF;gBAEb,IAAIhF,WAAW,OAAO;oBACpBH,YAAYqC,IAAI,CAAC;wBACfhB,YAAY;wBACZG,OAAO9B,QAAQ0B,MAAM,CAACF,aAAa;wBACnCN,OAAOT;oBACT;gBACF;YACF;YAEA,MAAMsF,cAAc9F,cAAcD,QAAQ0B,MAAM,CAACF,aAAa;YAE9DT,YAAY,CAAC,CAAC,EAAES,aAAa,CAAC,EAAErB,aAAa,EAAEiB,MAAMG,IAAI,CAAC,CAAC,CAAC,GAC1DwE,WAAW,CAAC,CAAC,EAAE5F,aAAa,EAAEiB,MAAMG,IAAI,CAAC,CAAC,CAAC;YAE7C,OAAO;gBACLI,YAAY,CAAC,EAAExB,aAAa,EAAEiB,MAAMG,IAAI,CAAC,CAAC;gBAC1CjB;gBACAc;gBACAT;gBACAmB,OAAOiE;YACT;QACF;IACF;IAEA,MAAM,IAAIvG,SAAS,CAAC,8BAA8B,EAAE2B,UAAU,CAAC;AACjE,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/getTableColumnFromPath.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, FieldAffectingData, NumberField, TabAsField, TextField } from 'payload'\n\nimport { and, eq, like, sql } from 'drizzle-orm'\nimport { alias } from 'drizzle-orm/pg-core'\nimport { APIError, flattenTopLevelFields } from 'payload'\nimport { fieldAffectsData, tabHasName } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\nimport { v4 as uuid } from 'uuid'\n\nimport type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\ntype Constraint = {\n columnName: string\n table: GenericTable | PgTableWithColumns<any>\n value: unknown\n}\n\ntype TableColumn = {\n columnName?: string\n constraints: Constraint[]\n field: FieldAffectingData\n getNotNullColumnByValue?: (val: unknown) => string\n pathSegments?: string[]\n rawColumn?: SQL\n table: GenericTable | PgTableWithColumns<any>\n}\n\ntype Args = {\n adapter: PostgresAdapter\n aliasTable?: GenericTable | PgTableWithColumns<any>\n collectionPath: string\n columnPrefix?: string\n constraintPath?: string\n constraints?: Constraint[]\n fields: (Field | TabAsField)[]\n joins: BuildQueryJoinAliases\n locale?: string\n pathSegments: string[]\n rootTableName?: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n /**\n * If creating a new table name for arrays and blocks, this suffix should be appended to the table name\n */\n tableNameSuffix?: string\n /**\n * The raw value of the query before sanitization\n */\n value: unknown\n}\n/**\n * Transforms path to table and column name\n * Adds tables to `join`\n * @returns TableColumn\n */\nexport const getTableColumnFromPath = ({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix = '',\n constraintPath: incomingConstraintPath,\n constraints = [],\n fields,\n joins,\n locale: incomingLocale,\n pathSegments: incomingSegments,\n rootTableName: incomingRootTableName,\n selectFields,\n tableName,\n tableNameSuffix = '',\n value,\n}: Args): TableColumn => {\n const fieldPath = incomingSegments[0]\n let locale = incomingLocale\n const rootTableName = incomingRootTableName || tableName\n let constraintPath = incomingConstraintPath || ''\n\n const field = flattenTopLevelFields(fields as Field[]).find(\n (fieldToFind) => fieldAffectsData(fieldToFind) && fieldToFind.name === fieldPath,\n ) as Field | TabAsField\n let newTableName = tableName\n\n if (!field && fieldPath === 'id') {\n selectFields.id = adapter.tables[newTableName].id\n return {\n columnName: 'id',\n constraints,\n field: {\n name: 'id',\n type: adapter.idType === 'uuid' ? 'text' : 'number',\n } as NumberField | TextField,\n table: adapter.tables[newTableName],\n }\n }\n\n if (field) {\n const pathSegments = [...incomingSegments]\n\n // If next segment is a locale,\n // we need to take it out and use it as the locale from this point on\n if ('localized' in field && field.localized && adapter.payload.config.localization) {\n const matchedLocale = adapter.payload.config.localization.localeCodes.find(\n (locale) => locale === pathSegments[1],\n )\n\n if (matchedLocale) {\n locale = matchedLocale\n pathSegments.splice(1, 1)\n }\n }\n\n switch (field.type) {\n case 'tabs': {\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix,\n constraintPath,\n constraints,\n fields: field.tabs.map((tab) => ({\n ...tab,\n type: 'tab',\n })),\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix,\n value,\n })\n }\n case 'tab': {\n if (tabHasName(field)) {\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix: `${columnPrefix}${field.name}_`,\n constraintPath: `${constraintPath}${field.name}.`,\n constraints,\n fields: field.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix: `${tableNameSuffix}${toSnakeCase(field.name)}_`,\n value,\n })\n }\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix,\n constraintPath,\n constraints,\n fields: field.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix,\n value,\n })\n }\n\n case 'group': {\n if (locale && field.localized && adapter.payload.config.localization) {\n newTableName = `${tableName}${adapter.localesSuffix}`\n\n joins.push({\n condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),\n table: adapter.tables[newTableName],\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n }\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix: `${columnPrefix}${field.name}_`,\n constraintPath: `${constraintPath}${field.name}.`,\n constraints,\n fields: field.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix: `${tableNameSuffix}${toSnakeCase(field.name)}_`,\n value,\n })\n }\n\n case 'select': {\n if (field.hasMany) {\n const newTableName = adapter.tableNameMap.get(\n `${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`,\n )\n\n if (locale && field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(\n eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),\n eq(adapter.tables[newTableName]._locale, locale),\n ),\n table: adapter.tables[newTableName],\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins.push({\n condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),\n table: adapter.tables[newTableName],\n })\n }\n\n return {\n columnName: 'value',\n constraints,\n field,\n table: adapter.tables[newTableName],\n }\n }\n break\n }\n\n case 'text':\n case 'number': {\n if (field.hasMany) {\n let tableType = 'texts'\n let columnName = 'text'\n if (field.type === 'number') {\n tableType = 'numbers'\n columnName = 'number'\n }\n newTableName = `${tableName}_${tableType}`\n const joinConstraints = [\n eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),\n eq(adapter.tables[newTableName].path, `${constraintPath}${field.name}`),\n ]\n\n if (locale && field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(...joinConstraints, eq(adapter.tables[newTableName]._locale, locale)),\n table: adapter.tables[newTableName],\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: 'locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins.push({\n condition: and(...joinConstraints),\n table: adapter.tables[newTableName],\n })\n }\n\n return {\n columnName,\n constraints,\n field,\n table: adapter.tables[newTableName],\n }\n }\n break\n }\n\n case 'array': {\n newTableName = adapter.tableNameMap.get(\n `${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`,\n )\n\n constraintPath = `${constraintPath}${field.name}.%.`\n if (locale && field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(\n eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),\n eq(adapter.tables[newTableName]._locale, locale),\n ),\n table: adapter.tables[newTableName],\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins.push({\n condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),\n table: adapter.tables[newTableName],\n })\n }\n return getTableColumnFromPath({\n adapter,\n collectionPath,\n constraintPath,\n constraints,\n fields: field.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n value,\n })\n }\n\n case 'blocks': {\n let blockTableColumn: TableColumn\n let newTableName: string\n\n // handle blockType queries\n if (pathSegments[1] === 'blockType') {\n // find the block config using the value\n const blockTypes = Array.isArray(value) ? value : [value]\n blockTypes.forEach((blockType) => {\n const block = field.blocks.find((block) => block.slug === blockType)\n newTableName = adapter.tableNameMap.get(\n `${tableName}_blocks_${toSnakeCase(block.slug)}`,\n )\n const newAliasTableName = toSnakeCase(uuid())\n const newAliasTable = alias(adapter.tables[newTableName], newAliasTableName)\n\n joins.push({\n condition: eq(adapter.tables[tableName].id, newAliasTable._parentID),\n table: newAliasTable,\n })\n constraints.push({\n columnName: '_path',\n table: newAliasTable,\n value: pathSegments[0],\n })\n })\n return {\n constraints,\n field,\n getNotNullColumnByValue: () => 'id',\n table: adapter.tables[tableName],\n }\n }\n\n const hasBlockField = field.blocks.some((block) => {\n newTableName = adapter.tableNameMap.get(`${tableName}_blocks_${toSnakeCase(block.slug)}`)\n constraintPath = `${constraintPath}${field.name}.%.`\n\n let result\n const blockConstraints = []\n const blockSelectFields = {}\n try {\n result = getTableColumnFromPath({\n adapter,\n collectionPath,\n constraintPath,\n constraints: blockConstraints,\n fields: block.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields: blockSelectFields,\n tableName: newTableName,\n value,\n })\n } catch (error) {\n // this is fine, not every block will have the field\n }\n if (!result) {\n return\n }\n blockTableColumn = result\n constraints = constraints.concat(blockConstraints)\n selectFields = { ...selectFields, ...blockSelectFields }\n if (field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(\n eq(\n (aliasTable || adapter.tables[tableName]).id,\n adapter.tables[newTableName]._parentID,\n ),\n eq(adapter.tables[newTableName]._locale, locale),\n ),\n table: adapter.tables[newTableName],\n })\n if (locale) {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins.push({\n condition: eq(\n (aliasTable || adapter.tables[tableName]).id,\n adapter.tables[newTableName]._parentID,\n ),\n table: adapter.tables[newTableName],\n })\n }\n return true\n })\n if (hasBlockField) {\n return {\n columnName: blockTableColumn.columnName,\n constraints,\n field: blockTableColumn.field,\n pathSegments: pathSegments.slice(1),\n rawColumn: blockTableColumn.rawColumn,\n table: blockTableColumn.table,\n }\n }\n break\n }\n\n case 'relationship':\n case 'upload': {\n const newCollectionPath = pathSegments.slice(1).join('.')\n if (Array.isArray(field.relationTo) || (field.type === 'relationship' && field.hasMany)) {\n let relationshipFields\n const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`\n const aliasRelationshipTableName = uuid()\n const aliasRelationshipTable = alias(\n adapter.tables[relationTableName],\n aliasRelationshipTableName,\n )\n\n // Join in the relationships table\n if (locale && field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(\n eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent),\n eq(aliasRelationshipTable.locale, locale),\n like(aliasRelationshipTable.path, `${constraintPath}${field.name}`),\n ),\n table: aliasRelationshipTable,\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: 'locale',\n table: aliasRelationshipTable,\n value: locale,\n })\n }\n } else {\n // Join in the relationships table\n joins.push({\n condition: and(\n eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent),\n like(aliasRelationshipTable.path, `${constraintPath}${field.name}`),\n ),\n table: aliasRelationshipTable,\n })\n }\n\n selectFields[`${relationTableName}.path`] = aliasRelationshipTable.path\n\n let newAliasTable\n\n if (typeof field.relationTo === 'string') {\n const relationshipConfig = adapter.payload.collections[field.relationTo].config\n\n newTableName = adapter.tableNameMap.get(toSnakeCase(relationshipConfig.slug))\n\n // parent to relationship join table\n relationshipFields = relationshipConfig.fields\n\n newAliasTable = alias(adapter.tables[newTableName], toSnakeCase(uuid()))\n\n joins.push({\n condition: eq(newAliasTable.id, aliasRelationshipTable[`${field.relationTo}ID`]),\n table: newAliasTable,\n })\n\n if (newCollectionPath === '' || newCollectionPath === 'id') {\n return {\n columnName: `${field.relationTo}ID`,\n constraints,\n field,\n table: aliasRelationshipTable,\n }\n }\n } else if (newCollectionPath === 'value') {\n const tableColumnsNames = field.relationTo.map((relationTo) => {\n const relationTableName = adapter.tableNameMap.get(\n toSnakeCase(adapter.payload.collections[relationTo].config.slug),\n )\n\n return `\"${aliasRelationshipTableName}\".\"${relationTableName}_id\"`\n })\n return {\n constraints,\n field,\n rawColumn: sql.raw(`COALESCE(${tableColumnsNames.join(', ')})`),\n table: aliasRelationshipTable,\n }\n } else if (newCollectionPath === 'relationTo') {\n const relationTo = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n\n return {\n constraints,\n field,\n getNotNullColumnByValue: (val) => {\n const matchedRelation = relationTo.find((relation) => relation === val)\n if (matchedRelation) return `${matchedRelation}ID`\n return undefined\n },\n table: aliasRelationshipTable,\n }\n } else {\n throw new APIError('Not supported')\n }\n\n return getTableColumnFromPath({\n adapter,\n aliasTable: newAliasTable,\n collectionPath: newCollectionPath,\n constraints,\n fields: relationshipFields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName: newTableName,\n selectFields,\n tableName: newTableName,\n value,\n })\n } else if (\n pathSegments.length > 1 &&\n !(pathSegments.length === 2 && pathSegments[1] === 'id')\n ) {\n // simple relationships\n const columnName = `${columnPrefix}${field.name}`\n const newTableName = adapter.tableNameMap.get(\n toSnakeCase(adapter.payload.collections[field.relationTo].config.slug),\n )\n const aliasTableName = uuid()\n const newAliasTable = alias(adapter.tables[newTableName], aliasTableName)\n\n if (field.localized && adapter.payload.config.localization) {\n const aliasLocaleTableName = uuid()\n const aliasLocaleTable = alias(\n adapter.tables[`${rootTableName}${adapter.localesSuffix}`],\n aliasLocaleTableName,\n )\n joins.push({\n condition: and(\n eq(aliasLocaleTable._parentID, adapter.tables[rootTableName].id),\n eq(aliasLocaleTable._locale, locale),\n ),\n table: aliasLocaleTable,\n })\n joins.push({\n condition: eq(aliasLocaleTable[columnName], newAliasTable.id),\n table: newAliasTable,\n })\n } else {\n joins.push({\n condition: eq(\n newAliasTable.id,\n aliasTable ? aliasTable[columnName] : adapter.tables[tableName][columnName],\n ),\n table: newAliasTable,\n })\n }\n\n return getTableColumnFromPath({\n adapter,\n aliasTable: newAliasTable,\n collectionPath: newCollectionPath,\n constraintPath: '',\n constraints,\n fields: adapter.payload.collections[field.relationTo].config.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n selectFields,\n tableName: newTableName,\n value,\n })\n }\n break\n }\n\n default: {\n // fall through\n break\n }\n }\n\n if (fieldAffectsData(field)) {\n if (field.localized && adapter.payload.config.localization) {\n // If localized, we go to localized table and set aliasTable to undefined\n // so it is not picked up below to be used as targetTable\n const parentTable = aliasTable || adapter.tables[tableName]\n newTableName = `${tableName}${adapter.localesSuffix}`\n\n joins.push({\n condition: eq(parentTable.id, adapter.tables[newTableName]._parentID),\n table: adapter.tables[newTableName],\n })\n\n aliasTable = undefined\n\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n }\n\n const targetTable = aliasTable || adapter.tables[newTableName]\n\n selectFields[`${newTableName}.${columnPrefix}${field.name}`] =\n targetTable[`${columnPrefix}${field.name}`]\n\n return {\n columnName: `${columnPrefix}${field.name}`,\n constraints,\n field,\n pathSegments,\n table: targetTable,\n }\n }\n }\n\n throw new APIError(`Cannot find field for path at ${fieldPath}`)\n}\n"],"names":["and","eq","like","sql","alias","APIError","flattenTopLevelFields","fieldAffectsData","tabHasName","toSnakeCase","v4","uuid","getTableColumnFromPath","adapter","aliasTable","collectionPath","columnPrefix","constraintPath","incomingConstraintPath","constraints","fields","joins","locale","incomingLocale","pathSegments","incomingSegments","rootTableName","incomingRootTableName","selectFields","tableName","tableNameSuffix","value","fieldPath","field","find","fieldToFind","name","newTableName","id","tables","columnName","type","idType","table","localized","payload","config","localization","matchedLocale","localeCodes","splice","tabs","map","tab","slice","localesSuffix","push","condition","_parentID","hasMany","tableNameMap","get","parent","_locale","tableType","joinConstraints","path","blockTableColumn","blockTypes","Array","isArray","forEach","blockType","block","blocks","slug","newAliasTableName","newAliasTable","getNotNullColumnByValue","hasBlockField","some","result","blockConstraints","blockSelectFields","error","concat","rawColumn","newCollectionPath","join","relationTo","relationshipFields","relationTableName","relationshipsSuffix","aliasRelationshipTableName","aliasRelationshipTable","relationshipConfig","collections","tableColumnsNames","raw","val","matchedRelation","relation","undefined","length","aliasTableName","aliasLocaleTableName","aliasLocaleTable","parentTable","targetTable"],"mappings":"AAAA,oCAAoC,GAKpC,SAASA,GAAG,EAAEC,EAAE,EAAEC,IAAI,EAAEC,GAAG,QAAQ,cAAa;AAChD,SAASC,KAAK,QAAQ,sBAAqB;AAC3C,SAASC,QAAQ,EAAEC,qBAAqB,QAAQ,UAAS;AACzD,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,iBAAgB;AAC7D,OAAOC,iBAAiB,gBAAe;AACvC,SAASC,MAAMC,IAAI,QAAQ,OAAM;AA4CjC;;;;CAIC,GACD,OAAO,MAAMC,yBAAyB,CAAC,EACrCC,OAAO,EACPC,UAAU,EACVC,cAAc,EACdC,eAAe,EAAE,EACjBC,gBAAgBC,sBAAsB,EACtCC,cAAc,EAAE,EAChBC,MAAM,EACNC,KAAK,EACLC,QAAQC,cAAc,EACtBC,cAAcC,gBAAgB,EAC9BC,eAAeC,qBAAqB,EACpCC,YAAY,EACZC,SAAS,EACTC,kBAAkB,EAAE,EACpBC,KAAK,EACA;IACL,MAAMC,YAAYP,gBAAgB,CAAC,EAAE;IACrC,IAAIH,SAASC;IAC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cD,QAAQ0B,MAAM,CAACV,UAAU;gBAC3DQ,eAAe,CAAC,EAAER,UAAU,EAAEhB,QAAQ0C,aAAa,CAAC,CAAC;gBAErDlC,MAAMmC,IAAI,CAAC;oBACTC,WAAWxD,GAAG0G,YAAYrE,EAAE,EAAEzB,QAAQ0B,MAAM,CAACF,aAAa,CAACqB,SAAS;oBACpEf,OAAO9B,QAAQ0B,MAAM,CAACF,aAAa;gBACrC;gBAEAvB,aAAawF;gBAEb,IAAIhF,WAAW,OAAO;oBACpBH,YAAYqC,IAAI,CAAC;wBACfhB,YAAY;wBACZG,OAAO9B,QAAQ0B,MAAM,CAACF,aAAa;wBACnCN,OAAOT;oBACT;gBACF;YACF;YAEA,MAAMsF,cAAc9F,cAAcD,QAAQ0B,MAAM,CAACF,aAAa;YAE9DT,YAAY,CAAC,CAAC,EAAES,aAAa,CAAC,EAAErB,aAAa,EAAEiB,MAAMG,IAAI,CAAC,CAAC,CAAC,GAC1DwE,WAAW,CAAC,CAAC,EAAE5F,aAAa,EAAEiB,MAAMG,IAAI,CAAC,CAAC,CAAC;YAE7C,OAAO;gBACLI,YAAY,CAAC,EAAExB,aAAa,EAAEiB,MAAMG,IAAI,CAAC,CAAC;gBAC1CjB;gBACAc;gBACAT;gBACAmB,OAAOiE;YACT;QACF;IACF;IAEA,MAAM,IAAIvG,SAAS,CAAC,8BAA8B,EAAE2B,UAAU,CAAC;AACjE,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/operatorMap.ts"],"sourcesContent":["import {\n and,\n eq,\n gt,\n gte,\n ilike,\n inArray,\n isNotNull,\n isNull,\n lt,\n lte,\n ne,\n notInArray,\n or,\n} from 'drizzle-orm'\n\nexport const operatorMap = {\n // intersects: intersects,\n and,\n contains: ilike,\n equals: eq,\n exists: isNotNull,\n greater_than: gt,\n greater_than_equal: gte,\n in: inArray,\n isNull, // handles exists: false\n less_than: lt,\n less_than_equal: lte,\n like: ilike,\n not_equals: ne,\n // TODO: geojson queries\n // near: near,\n // within: within,\n // all: all,\n not_in: notInArray,\n or,\n}\n"],"names":["and","eq","gt","gte","ilike","inArray","isNotNull","isNull","lt","lte","ne","notInArray","or","operatorMap","contains","equals","exists","greater_than","greater_than_equal","in","less_than","less_than_equal","like","not_equals","not_in"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SACEA,GAAG,EACHC,EAAE,EACFC,EAAE,EACFC,GAAG,EACHC,KAAK,EACLC,OAAO,EACPC,SAAS,EACTC,MAAM,EACNC,EAAE,EACFC,GAAG,EACHC,EAAE,EACFC,UAAU,EACVC,EAAE,QACG,cAAa;AAEpB,OAAO,MAAMC,cAAc;IACzB,0BAA0B;IAC1Bb;IACAc,UAAUV;IACVW,QAAQd;IACRe,QAAQV;IACRW,cAAcf;IACdgB,oBAAoBf;IACpBgB,IAAId;IACJE;IACAa,WAAWZ;IACXa,iBAAiBZ;IACjBa,MAAMlB;IACNmB,YAAYb;IACZ,wBAAwB;IACxB,cAAc;IACd,kBAAkB;IAClB,YAAY;IACZc,QAAQb;IACRC;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/operatorMap.ts"],"sourcesContent":["import {\n and,\n eq,\n gt,\n gte,\n ilike,\n inArray,\n isNotNull,\n isNull,\n lt,\n lte,\n ne,\n notInArray,\n or,\n} from 'drizzle-orm'\n\nexport const operatorMap = {\n // intersects: intersects,\n and,\n contains: ilike,\n equals: eq,\n exists: isNotNull,\n greater_than: gt,\n greater_than_equal: gte,\n in: inArray,\n isNull, // handles exists: false\n less_than: lt,\n less_than_equal: lte,\n like: ilike,\n not_equals: ne,\n // TODO: geojson queries\n // near: near,\n // within: within,\n // all: all,\n not_in: notInArray,\n or,\n}\n"],"names":["and","eq","gt","gte","ilike","inArray","isNotNull","isNull","lt","lte","ne","notInArray","or","operatorMap","contains","equals","exists","greater_than","greater_than_equal","in","less_than","less_than_equal","like","not_equals","not_in"],"mappings":"AAAA,SACEA,GAAG,EACHC,EAAE,EACFC,EAAE,EACFC,GAAG,EACHC,KAAK,EACLC,OAAO,EACPC,SAAS,EACTC,MAAM,EACNC,EAAE,EACFC,GAAG,EACHC,EAAE,EACFC,UAAU,EACVC,EAAE,QACG,cAAa;AAEpB,OAAO,MAAMC,cAAc;IACzB,0BAA0B;IAC1Bb;IACAc,UAAUV;IACVW,QAAQd;IACRe,QAAQV;IACRW,cAAcf;IACdgB,oBAAoBf;IACpBgB,IAAId;IACJE;IACAa,WAAWZ;IACXa,iBAAiBZ;IACjBa,MAAMlB;IACNmB,YAAYb;IACZ,wBAAwB;IACxB,cAAc;IACd,kBAAkB;IAClB,YAAY;IACZc,QAAQb;IACRC;AACF,EAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { SQL } from 'drizzle-orm';
2
- import type { Field, Where } from 'payload/types';
2
+ import type { Field, Where } from 'payload';
3
3
  import type { GenericColumn, PostgresAdapter } from '../types.js';
4
4
  import type { BuildQueryJoinAliases } from './buildQuery.js';
5
5
  type Args = {
@@ -1 +1 @@
1
- {"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAY,KAAK,EAAE,MAAM,eAAe,CAAA;AAM3D,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAS5D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,KAAK,EAAE,qBAAqB,CAAA;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,wBAAsB,WAAW,CAAC,EAChC,OAAO,EACP,MAAM,EACN,KAAK,EACL,MAAM,EACN,YAAY,EACZ,SAAS,EACT,KAAK,GACN,EAAE,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CA6MrB"}
1
+ {"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAY,KAAK,EAAE,MAAM,SAAS,CAAA;AAMrD,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAS5D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,KAAK,EAAE,qBAAqB,CAAA;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,wBAAsB,WAAW,CAAC,EAChC,OAAO,EACP,MAAM,EACN,KAAK,EACL,MAAM,EACN,YAAY,EACZ,SAAS,EACT,KAAK,GACN,EAAE,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CA6MrB"}
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable no-await-in-loop */ import { and, ilike, isNotNull, isNull, ne, notInArray, or, sql } from 'drizzle-orm';
2
- import { QueryError } from 'payload/errors';
3
- import { validOperators } from 'payload/types';
2
+ import { QueryError } from 'payload';
3
+ import { validOperators } from 'payload/shared';
4
4
  import { buildAndOrConditions } from './buildAndOrConditions.js';
5
5
  import { convertPathToJSONTraversal } from './createJSONQuery/convertPathToJSONTraversal.js';
6
6
  import { createJSONQuery } from './createJSONQuery/index.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["/* eslint-disable no-await-in-loop */\nimport type { SQL } from 'drizzle-orm'\nimport type { Field, Operator, Where } from 'payload/types'\n\nimport { and, ilike, isNotNull, isNull, ne, notInArray, or, sql } from 'drizzle-orm'\nimport { QueryError } from 'payload/errors'\nimport { validOperators } from 'payload/types'\n\nimport type { GenericColumn, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { convertPathToJSONTraversal } from './createJSONQuery/convertPathToJSONTraversal.js'\nimport { createJSONQuery } from './createJSONQuery/index.js'\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\ntype Args = {\n adapter: PostgresAdapter\n fields: Field[]\n joins: BuildQueryJoinAliases\n locale: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n where: Where\n}\n\nexport async function parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where,\n}: Args): Promise<SQL> {\n let result: SQL\n const constraints: SQL[] = []\n\n if (typeof where === 'object' && Object.keys(where).length > 0) {\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 if (relationOrPath) {\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 adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: condition,\n })\n if (builtConditions.length > 0) {\n result = operatorMap[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 (let operator of Object.keys(pathOperators)) {\n if (validOperators.includes(operator as Operator)) {\n const val = where[relationOrPath][operator]\n const {\n columnName,\n constraints: queryConstraints,\n field,\n getNotNullColumnByValue,\n pathSegments,\n rawColumn,\n table,\n } = getTableColumnFromPath({\n adapter,\n collectionPath: relationOrPath,\n fields,\n joins,\n locale,\n pathSegments: relationOrPath.replace(/__/g, '.').split('.'),\n selectFields,\n tableName,\n value: val,\n })\n\n queryConstraints.forEach(({ columnName: col, table: constraintTable, value }) => {\n if (typeof value === 'string' && value.indexOf('%') > -1) {\n constraints.push(operatorMap.like(constraintTable[col], value))\n } else {\n constraints.push(operatorMap.equals(constraintTable[col], value))\n }\n })\n\n if (\n ['json', 'richText'].includes(field.type) &&\n Array.isArray(pathSegments) &&\n pathSegments.length > 1\n ) {\n const segments = pathSegments.slice(1)\n segments.unshift(table[columnName].name)\n\n if (field.type === 'richText') {\n const jsonQuery = createJSONQuery({\n operator,\n pathSegments: segments,\n treatAsArray: ['children'],\n treatRootAsArray: true,\n value: val,\n })\n\n constraints.push(sql.raw(jsonQuery))\n break\n }\n\n const jsonQuery = convertPathToJSONTraversal(pathSegments)\n const operatorKeys = {\n contains: { operator: 'ilike', wildcard: '%' },\n equals: { operator: '=', wildcard: '' },\n exists: { operator: val === true ? 'is not null' : 'is null' },\n like: { operator: 'like', wildcard: '%' },\n not_equals: { operator: '<>', wildcard: '' },\n }\n let formattedValue = `'${operatorKeys[operator].wildcard}${val}${operatorKeys[operator].wildcard}'`\n\n if (operator === 'exists') {\n formattedValue = ''\n }\n\n constraints.push(\n sql.raw(\n `${table[columnName].name}${jsonQuery} ${operatorKeys[operator].operator} ${formattedValue}`,\n ),\n )\n\n break\n }\n\n if (getNotNullColumnByValue) {\n const columnName = getNotNullColumnByValue(val)\n if (columnName) {\n constraints.push(isNotNull(table[columnName]))\n } else {\n throw new QueryError([{ path: relationOrPath }])\n }\n break\n }\n\n if (\n operator === 'like' &&\n (field.type === 'number' || table[columnName].columnType === 'PgUUID')\n ) {\n operator = 'equals'\n }\n\n if (operator === 'like') {\n constraints.push(\n and(...val.split(' ').map((word) => ilike(table[columnName], `%${word}%`))),\n )\n break\n }\n\n const sanitizedQueryValue = sanitizeQueryValue({\n adapter,\n field,\n operator,\n relationOrPath,\n val,\n })\n\n if (sanitizedQueryValue === null) {\n break\n }\n\n const { operator: queryOperator, value: queryValue } = sanitizedQueryValue\n\n if (queryOperator === 'not_equals' && queryValue !== null) {\n constraints.push(\n or(\n isNull(rawColumn || table[columnName]),\n /* eslint-disable @typescript-eslint/no-explicit-any */\n ne<any>(rawColumn || table[columnName], queryValue),\n ),\n )\n break\n }\n\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n Array.isArray(queryValue) &&\n operator === 'not_in'\n ) {\n constraints.push(\n sql`(${notInArray(table[columnName], queryValue)} OR\n ${table[columnName]}\n IS\n NULL)`,\n )\n\n break\n }\n\n if (operator === 'equals' && queryValue === null) {\n constraints.push(isNull(rawColumn || table[columnName]))\n break\n }\n\n if (operator === 'not_equals' && queryValue === null) {\n constraints.push(isNotNull(rawColumn || table[columnName]))\n break\n }\n\n constraints.push(\n operatorMap[queryOperator](rawColumn || table[columnName], queryValue),\n )\n }\n }\n }\n }\n }\n }\n }\n if (constraints.length > 0) {\n if (result) {\n result = and(result, ...constraints)\n } else {\n result = and(...constraints)\n }\n }\n if (constraints.length === 1 && !result) {\n ;[result] = constraints\n }\n\n return result\n}\n"],"names":["and","ilike","isNotNull","isNull","ne","notInArray","or","sql","QueryError","validOperators","buildAndOrConditions","convertPathToJSONTraversal","createJSONQuery","getTableColumnFromPath","operatorMap","sanitizeQueryValue","parseParams","adapter","fields","joins","locale","selectFields","tableName","where","result","constraints","Object","keys","length","relationOrPath","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","pathOperators","operator","includes","val","columnName","queryConstraints","field","getNotNullColumnByValue","pathSegments","rawColumn","table","collectionPath","replace","split","value","forEach","col","constraintTable","indexOf","push","like","equals","type","segments","slice","unshift","name","jsonQuery","treatAsArray","treatRootAsArray","raw","operatorKeys","contains","wildcard","exists","not_equals","formattedValue","path","columnType","map","word","sanitizedQueryValue","queryOperator","queryValue"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,mCAAmC,GAInC,SAASA,GAAG,EAAEC,KAAK,EAAEC,SAAS,EAAEC,MAAM,EAAEC,EAAE,EAAEC,UAAU,EAAEC,EAAE,EAAEC,GAAG,QAAQ,cAAa;AACpF,SAASC,UAAU,QAAQ,iBAAgB;AAC3C,SAASC,cAAc,QAAQ,gBAAe;AAK9C,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,0BAA0B,QAAQ,kDAAiD;AAC5F,SAASC,eAAe,QAAQ,6BAA4B;AAC5D,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAY5D,OAAO,eAAeC,YAAY,EAChCC,OAAO,EACPC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,YAAY,EACZC,SAAS,EACTC,KAAK,EACA;IACL,IAAIC;IACJ,MAAMC,cAAqB,EAAE;IAE7B,IAAI,OAAOF,UAAU,YAAYG,OAAOC,IAAI,CAACJ,OAAOK,MAAM,GAAG,GAAG;QAC9D,uEAAuE;QACvE,KAAK,MAAMC,kBAAkBH,OAAOC,IAAI,CAACJ,OAAQ;YAC/C,IAAIM,gBAAgB;gBAClB,MAAMC,YAAYP,KAAK,CAACM,eAAe;gBACvC,IAAIE;gBACJ,IAAIF,eAAeG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EjC,KAAK,CAACN,WAAW,CAAC;;yBAEf,CAAC;oCAGR;gCACF;gCAEA,IAAIH,aAAa,YAAY0C,eAAe,MAAM;oCAChDtD,YAAY8B,IAAI,CAACpD,OAAO0C,aAAaC,KAAK,CAACN,WAAW;oCACtD;gCACF;gCAEA,IAAIH,aAAa,gBAAgB0C,eAAe,MAAM;oCACpDtD,YAAY8B,IAAI,CAACrD,UAAU2C,aAAaC,KAAK,CAACN,WAAW;oCACzD;gCACF;gCAEAf,YAAY8B,IAAI,CACdzC,WAAW,CAACgE,cAAc,CAACjC,aAAaC,KAAK,CAACN,WAAW,EAAEuC;4BAE/D;wBACF;oBACF;gBACF;YACF;QACF;IACF;IACA,IAAItD,YAAYG,MAAM,GAAG,GAAG;QAC1B,IAAIJ,QAAQ;YACVA,SAASxB,IAAIwB,WAAWC;QAC1B,OAAO;YACLD,SAASxB,OAAOyB;QAClB;IACF;IACA,IAAIA,YAAYG,MAAM,KAAK,KAAK,CAACJ,QAAQ;QACtC,CAACA,OAAO,GAAGC;IACd;IAEA,OAAOD;AACT"}
1
+ {"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["/* eslint-disable no-await-in-loop */\nimport type { SQL } from 'drizzle-orm'\nimport type { Field, Operator, Where } from 'payload'\n\nimport { and, ilike, isNotNull, isNull, ne, notInArray, or, sql } from 'drizzle-orm'\nimport { QueryError } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport type { GenericColumn, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { convertPathToJSONTraversal } from './createJSONQuery/convertPathToJSONTraversal.js'\nimport { createJSONQuery } from './createJSONQuery/index.js'\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\ntype Args = {\n adapter: PostgresAdapter\n fields: Field[]\n joins: BuildQueryJoinAliases\n locale: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n where: Where\n}\n\nexport async function parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where,\n}: Args): Promise<SQL> {\n let result: SQL\n const constraints: SQL[] = []\n\n if (typeof where === 'object' && Object.keys(where).length > 0) {\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 if (relationOrPath) {\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 adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: condition,\n })\n if (builtConditions.length > 0) {\n result = operatorMap[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 (let operator of Object.keys(pathOperators)) {\n if (validOperators.includes(operator as Operator)) {\n const val = where[relationOrPath][operator]\n const {\n columnName,\n constraints: queryConstraints,\n field,\n getNotNullColumnByValue,\n pathSegments,\n rawColumn,\n table,\n } = getTableColumnFromPath({\n adapter,\n collectionPath: relationOrPath,\n fields,\n joins,\n locale,\n pathSegments: relationOrPath.replace(/__/g, '.').split('.'),\n selectFields,\n tableName,\n value: val,\n })\n\n queryConstraints.forEach(({ columnName: col, table: constraintTable, value }) => {\n if (typeof value === 'string' && value.indexOf('%') > -1) {\n constraints.push(operatorMap.like(constraintTable[col], value))\n } else {\n constraints.push(operatorMap.equals(constraintTable[col], value))\n }\n })\n\n if (\n ['json', 'richText'].includes(field.type) &&\n Array.isArray(pathSegments) &&\n pathSegments.length > 1\n ) {\n const segments = pathSegments.slice(1)\n segments.unshift(table[columnName].name)\n\n if (field.type === 'richText') {\n const jsonQuery = createJSONQuery({\n operator,\n pathSegments: segments,\n treatAsArray: ['children'],\n treatRootAsArray: true,\n value: val,\n })\n\n constraints.push(sql.raw(jsonQuery))\n break\n }\n\n const jsonQuery = convertPathToJSONTraversal(pathSegments)\n const operatorKeys = {\n contains: { operator: 'ilike', wildcard: '%' },\n equals: { operator: '=', wildcard: '' },\n exists: { operator: val === true ? 'is not null' : 'is null' },\n like: { operator: 'like', wildcard: '%' },\n not_equals: { operator: '<>', wildcard: '' },\n }\n let formattedValue = `'${operatorKeys[operator].wildcard}${val}${operatorKeys[operator].wildcard}'`\n\n if (operator === 'exists') {\n formattedValue = ''\n }\n\n constraints.push(\n sql.raw(\n `${table[columnName].name}${jsonQuery} ${operatorKeys[operator].operator} ${formattedValue}`,\n ),\n )\n\n break\n }\n\n if (getNotNullColumnByValue) {\n const columnName = getNotNullColumnByValue(val)\n if (columnName) {\n constraints.push(isNotNull(table[columnName]))\n } else {\n throw new QueryError([{ path: relationOrPath }])\n }\n break\n }\n\n if (\n operator === 'like' &&\n (field.type === 'number' || table[columnName].columnType === 'PgUUID')\n ) {\n operator = 'equals'\n }\n\n if (operator === 'like') {\n constraints.push(\n and(...val.split(' ').map((word) => ilike(table[columnName], `%${word}%`))),\n )\n break\n }\n\n const sanitizedQueryValue = sanitizeQueryValue({\n adapter,\n field,\n operator,\n relationOrPath,\n val,\n })\n\n if (sanitizedQueryValue === null) {\n break\n }\n\n const { operator: queryOperator, value: queryValue } = sanitizedQueryValue\n\n if (queryOperator === 'not_equals' && queryValue !== null) {\n constraints.push(\n or(\n isNull(rawColumn || table[columnName]),\n /* eslint-disable @typescript-eslint/no-explicit-any */\n ne<any>(rawColumn || table[columnName], queryValue),\n ),\n )\n break\n }\n\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n Array.isArray(queryValue) &&\n operator === 'not_in'\n ) {\n constraints.push(\n sql`(${notInArray(table[columnName], queryValue)} OR\n ${table[columnName]}\n IS\n NULL)`,\n )\n\n break\n }\n\n if (operator === 'equals' && queryValue === null) {\n constraints.push(isNull(rawColumn || table[columnName]))\n break\n }\n\n if (operator === 'not_equals' && queryValue === null) {\n constraints.push(isNotNull(rawColumn || table[columnName]))\n break\n }\n\n constraints.push(\n operatorMap[queryOperator](rawColumn || table[columnName], queryValue),\n )\n }\n }\n }\n }\n }\n }\n }\n if (constraints.length > 0) {\n if (result) {\n result = and(result, ...constraints)\n } else {\n result = and(...constraints)\n }\n }\n if (constraints.length === 1 && !result) {\n ;[result] = constraints\n }\n\n return result\n}\n"],"names":["and","ilike","isNotNull","isNull","ne","notInArray","or","sql","QueryError","validOperators","buildAndOrConditions","convertPathToJSONTraversal","createJSONQuery","getTableColumnFromPath","operatorMap","sanitizeQueryValue","parseParams","adapter","fields","joins","locale","selectFields","tableName","where","result","constraints","Object","keys","length","relationOrPath","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","pathOperators","operator","includes","val","columnName","queryConstraints","field","getNotNullColumnByValue","pathSegments","rawColumn","table","collectionPath","replace","split","value","forEach","col","constraintTable","indexOf","push","like","equals","type","segments","slice","unshift","name","jsonQuery","treatAsArray","treatRootAsArray","raw","operatorKeys","contains","wildcard","exists","not_equals","formattedValue","path","columnType","map","word","sanitizedQueryValue","queryOperator","queryValue"],"mappings":"AAAA,mCAAmC,GAInC,SAASA,GAAG,EAAEC,KAAK,EAAEC,SAAS,EAAEC,MAAM,EAAEC,EAAE,EAAEC,UAAU,EAAEC,EAAE,EAAEC,GAAG,QAAQ,cAAa;AACpF,SAASC,UAAU,QAAQ,UAAS;AACpC,SAASC,cAAc,QAAQ,iBAAgB;AAK/C,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,0BAA0B,QAAQ,kDAAiD;AAC5F,SAASC,eAAe,QAAQ,6BAA4B;AAC5D,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAY5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Ae,MAAM;oCACzDtD,YAAY8B,IAAI,CACdjD,GACEH,OAAO0C,aAAaC,KAAK,CAACN,WAAW,GACrC,qDAAqD,GACrDpC,GAAQyC,aAAaC,KAAK,CAACN,WAAW,EAAEuC;oCAG5C;gCACF;gCAEA,IACE,AAACrC,CAAAA,MAAMgB,IAAI,KAAK,kBAAkBhB,MAAMgB,IAAI,KAAK,QAAO,KACxDzB,MAAMC,OAAO,CAAC6C,eACd1C,aAAa,UACb;oCACAZ,YAAY8B,IAAI,CACdhD,GAAG,CAAC,CAAC,EAAEF,WAAWyC,KAAK,CAACN,WAAW,EAAEuC,YAAY;oBACjD,EAAEjC,KAAK,CAACN,WAAW,CAAC;;yBAEf,CAAC;oCAGR;gCACF;gCAEA,IAAIH,aAAa,YAAY0C,eAAe,MAAM;oCAChDtD,YAAY8B,IAAI,CAACpD,OAAO0C,aAAaC,KAAK,CAACN,WAAW;oCACtD;gCACF;gCAEA,IAAIH,aAAa,gBAAgB0C,eAAe,MAAM;oCACpDtD,YAAY8B,IAAI,CAACrD,UAAU2C,aAAaC,KAAK,CAACN,WAAW;oCACzD;gCACF;gCAEAf,YAAY8B,IAAI,CACdzC,WAAW,CAACgE,cAAc,CAACjC,aAAaC,KAAK,CAACN,WAAW,EAAEuC;4BAE/D;wBACF;oBACF;gBACF;YACF;QACF;IACF;IACA,IAAItD,YAAYG,MAAM,GAAG,GAAG;QAC1B,IAAIJ,QAAQ;YACVA,SAASxB,IAAIwB,WAAWC;QAC1B,OAAO;YACLD,SAASxB,OAAOyB;QAClB;IACF;IACA,IAAIA,YAAYG,MAAM,KAAK,KAAK,CAACJ,QAAQ;QACtC,CAACA,OAAO,GAAGC;IACd;IAEA,OAAOD;AACT"}
@@ -1,4 +1,4 @@
1
- import { type Field, type TabAsField } from 'payload/types';
1
+ import { type Field, type TabAsField } from 'payload';
2
2
  import type { PostgresAdapter } from '../types.js';
3
3
  type SanitizeQueryValueArgs = {
4
4
  adapter: PostgresAdapter;
@@ -1 +1 @@
1
- {"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,UAAU,EAAoB,MAAM,eAAe,CAAA;AAG7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,KAAK,sBAAsB,GAAG;IAC5B,OAAO,EAAE,eAAe,CAAA;IACxB,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,EAAE,MAAM,CAAA;IACtB,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AAED,eAAO,MAAM,kBAAkB,oEAM5B,sBAAsB,KAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAyF7D,CAAA"}
1
+ {"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,KAAK,EAAE,KAAK,UAAU,EAAkC,MAAM,SAAS,CAAA;AAG/F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,KAAK,sBAAsB,GAAG;IAC5B,OAAO,EAAE,eAAe,CAAA;IACxB,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,EAAE,MAAM,CAAA;IACtB,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AAED,eAAO,MAAM,kBAAkB,oEAM5B,sBAAsB,KAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAyF7D,CAAA"}
@@ -1,6 +1,5 @@
1
- import { APIError } from 'payload/errors';
2
- import { fieldAffectsData } from 'payload/types';
3
- import { createArrayFromCommaDelineated } from 'payload/utilities';
1
+ import { APIError, createArrayFromCommaDelineated } from 'payload';
2
+ import { fieldAffectsData } from 'payload/shared';
4
3
  export const sanitizeQueryValue = ({ adapter, field, operator: operatorArg, relationOrPath, val })=>{
5
4
  let operator = operatorArg;
6
5
  let formattedValue = val;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import { APIError } from 'payload/errors'\nimport { type Field, type TabAsField, fieldAffectsData } from 'payload/types'\nimport { createArrayFromCommaDelineated } from 'payload/utilities'\n\nimport type { PostgresAdapter } from '../types.js'\n\ntype SanitizeQueryValueArgs = {\n adapter: PostgresAdapter\n field: Field | TabAsField\n operator: string\n relationOrPath: string\n val: any\n}\n\nexport const sanitizeQueryValue = ({\n adapter,\n field,\n operator: operatorArg,\n relationOrPath,\n val,\n}: SanitizeQueryValueArgs): { operator: string; value: unknown } => {\n let operator = operatorArg\n let formattedValue = val\n\n if (!fieldAffectsData(field)) return { operator, value: formattedValue }\n\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n !relationOrPath.endsWith('relationTo') &&\n Array.isArray(formattedValue)\n ) {\n const allPossibleIDTypes: (number | string)[] = []\n formattedValue.forEach((val) => {\n if (adapter.idType !== 'uuid' && typeof val === 'string') {\n allPossibleIDTypes.push(val, parseInt(val))\n } else if (typeof val === 'string') {\n allPossibleIDTypes.push(val)\n } else {\n allPossibleIDTypes.push(val, String(val))\n }\n })\n formattedValue = allPossibleIDTypes\n }\n\n // Cast incoming values as proper searchable types\n if (field.type === 'checkbox' && typeof val === 'string') {\n if (val.toLowerCase() === 'true') formattedValue = true\n if (val.toLowerCase() === 'false') formattedValue = false\n }\n\n if (['all', 'in', 'not_in'].includes(operator)) {\n if (typeof formattedValue === 'string') {\n formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n if (field.type === 'number') {\n formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n }\n }\n\n if (!Array.isArray(formattedValue) || formattedValue.length === 0) {\n return null\n }\n }\n\n if (field.type === 'number' && typeof formattedValue === 'string') {\n formattedValue = Number(val)\n }\n\n if (field.type === 'date' && operator !== 'exists') {\n if (typeof val === 'string') {\n formattedValue = new Date(val)\n if (Number.isNaN(Date.parse(formattedValue))) {\n return { operator, value: undefined }\n }\n }\n\n if (typeof val === 'number') {\n formattedValue = new Date(val)\n }\n }\n\n if (['relationship', 'upload'].includes(field.type)) {\n if (val === 'null') {\n formattedValue = null\n }\n }\n\n if ('hasMany' in field && field.hasMany && operator === 'contains') {\n operator = 'equals'\n }\n\n if (operator === 'near' || operator === 'within' || operator === 'intersects') {\n throw new APIError(\n `Querying with '${operator}' is not supported with the postgres database adapter.`,\n )\n }\n\n if (operator === 'contains') {\n formattedValue = `%${formattedValue}%`\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n if (formattedValue === false) {\n operator = 'isNull'\n }\n }\n\n return { operator, value: formattedValue }\n}\n"],"names":["APIError","fieldAffectsData","createArrayFromCommaDelineated","sanitizeQueryValue","adapter","field","operator","operatorArg","relationOrPath","val","formattedValue","value","type","endsWith","Array","isArray","allPossibleIDTypes","forEach","idType","push","parseInt","String","toLowerCase","includes","map","arrayVal","parseFloat","length","Number","Date","isNaN","parse","undefined","hasMany"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,QAAQ,QAAQ,iBAAgB;AACzC,SAAsCC,gBAAgB,QAAQ,gBAAe;AAC7E,SAASC,8BAA8B,QAAQ,oBAAmB;AAYlE,OAAO,MAAMC,qBAAqB,CAAC,EACjCC,OAAO,EACPC,KAAK,EACLC,UAAUC,WAAW,EACrBC,cAAc,EACdC,GAAG,EACoB;IACvB,IAAIH,WAAWC;IACf,IAAIG,iBAAiBD;IAErB,IAAI,CAACR,iBAAiBI,QAAQ,OAAO;QAAEC;QAAUK,OAAOD;IAAe;IAEvE,IACE,AAACL,CAAAA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AAO;oBAAEJ;oBAAUK,OAAOqB;gBAAU;YACtC;QACF;QAEA,IAAI,OAAOvB,QAAQ,UAAU;YAC3BC,iBAAiB,IAAImB,KAAKpB;QAC5B;IACF;IAEA,IAAI;QAAC;QAAgB;KAAS,CAACc,QAAQ,CAAClB,MAAMO,IAAI,GAAG;QACnD,IAAIH,QAAQ,QAAQ;YAClBC,iBAAiB;QACnB;IACF;IAEA,IAAI,aAAaL,SAASA,MAAM4B,OAAO,IAAI3B,aAAa,YAAY;QAClEA,WAAW;IACb;IAEA,IAAIA,aAAa,UAAUA,aAAa,YAAYA,aAAa,cAAc;QAC7E,MAAM,IAAIN,SACR,CAAC,eAAe,EAAEM,SAAS,sDAAsD,CAAC;IAEtF;IAEA,IAAIA,aAAa,YAAY;QAC3BI,iBAAiB,CAAC,CAAC,EAAEA,eAAe,CAAC,CAAC;IACxC;IAEA,IAAIJ,aAAa,UAAU;QACzBI,iBAAiBA,mBAAmB,UAAUA,mBAAmB;QACjE,IAAIA,mBAAmB,OAAO;YAC5BJ,WAAW;QACb;IACF;IAEA,OAAO;QAAEA;QAAUK,OAAOD;IAAe;AAC3C,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import { APIError, type Field, type TabAsField, createArrayFromCommaDelineated } from 'payload'\nimport { fieldAffectsData } from 'payload/shared'\n\nimport type { PostgresAdapter } from '../types.js'\n\ntype SanitizeQueryValueArgs = {\n adapter: PostgresAdapter\n field: Field | TabAsField\n operator: string\n relationOrPath: string\n val: any\n}\n\nexport const sanitizeQueryValue = ({\n adapter,\n field,\n operator: operatorArg,\n relationOrPath,\n val,\n}: SanitizeQueryValueArgs): { operator: string; value: unknown } => {\n let operator = operatorArg\n let formattedValue = val\n\n if (!fieldAffectsData(field)) return { operator, value: formattedValue }\n\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n !relationOrPath.endsWith('relationTo') &&\n Array.isArray(formattedValue)\n ) {\n const allPossibleIDTypes: (number | string)[] = []\n formattedValue.forEach((val) => {\n if (adapter.idType !== 'uuid' && typeof val === 'string') {\n allPossibleIDTypes.push(val, parseInt(val))\n } else if (typeof val === 'string') {\n allPossibleIDTypes.push(val)\n } else {\n allPossibleIDTypes.push(val, String(val))\n }\n })\n formattedValue = allPossibleIDTypes\n }\n\n // Cast incoming values as proper searchable types\n if (field.type === 'checkbox' && typeof val === 'string') {\n if (val.toLowerCase() === 'true') formattedValue = true\n if (val.toLowerCase() === 'false') formattedValue = false\n }\n\n if (['all', 'in', 'not_in'].includes(operator)) {\n if (typeof formattedValue === 'string') {\n formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n if (field.type === 'number') {\n formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n }\n }\n\n if (!Array.isArray(formattedValue) || formattedValue.length === 0) {\n return null\n }\n }\n\n if (field.type === 'number' && typeof formattedValue === 'string') {\n formattedValue = Number(val)\n }\n\n if (field.type === 'date' && operator !== 'exists') {\n if (typeof val === 'string') {\n formattedValue = new Date(val)\n if (Number.isNaN(Date.parse(formattedValue))) {\n return { operator, value: undefined }\n }\n }\n\n if (typeof val === 'number') {\n formattedValue = new Date(val)\n }\n }\n\n if (['relationship', 'upload'].includes(field.type)) {\n if (val === 'null') {\n formattedValue = null\n }\n }\n\n if ('hasMany' in field && field.hasMany && operator === 'contains') {\n operator = 'equals'\n }\n\n if (operator === 'near' || operator === 'within' || operator === 'intersects') {\n throw new APIError(\n `Querying with '${operator}' is not supported with the postgres database adapter.`,\n )\n }\n\n if (operator === 'contains') {\n formattedValue = `%${formattedValue}%`\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n if (formattedValue === false) {\n operator = 'isNull'\n }\n }\n\n return { operator, value: formattedValue }\n}\n"],"names":["APIError","createArrayFromCommaDelineated","fieldAffectsData","sanitizeQueryValue","adapter","field","operator","operatorArg","relationOrPath","val","formattedValue","value","type","endsWith","Array","isArray","allPossibleIDTypes","forEach","idType","push","parseInt","String","toLowerCase","includes","map","arrayVal","parseFloat","length","Number","Date","isNaN","parse","undefined","hasMany"],"mappings":"AAAA,SAASA,QAAQ,EAA+BC,8BAA8B,QAAQ,UAAS;AAC/F,SAASC,gBAAgB,QAAQ,iBAAgB;AAYjD,OAAO,MAAMC,qBAAqB,CAAC,EACjCC,OAAO,EACPC,KAAK,EACLC,UAAUC,WAAW,EACrBC,cAAc,EACdC,GAAG,EACoB;IACvB,IAAIH,WAAWC;IACf,IAAIG,iBAAiBD;IAErB,IAAI,CAACP,iBAAiBG,QAAQ,OAAO;QAAEC;QAAUK,OAAOD;IAAe;IAEvE,IACE,AAACL,CAAAA,MAAMO,IAAI,KAAK,kBAAkBP,MAAMO,IAAI,KAAK,QAAO,KACxD,CAACJ,eAAeK,QAAQ,CAAC,iBACzBC,MAAMC,OAAO,CAACL,iBACd;QACA,MAAMM,qBAA0C,EAAE;QAClDN,eAAeO,OAAO,CAAC,CAACR;YACtB,IAAIL,QAAQc,MAAM,KAAK,UAAU,OAAOT,QAAQ,UAAU;gBACxDO,mBAAmBG,IAAI,CAACV,KAAKW,SAASX;YACxC,OAAO,IAAI,OAAOA,QAAQ,UAAU;gBAClCO,mBAAmBG,IAAI,CAACV;YAC1B,OAAO;gBACLO,mBAAmBG,IAAI,CAACV,KAAKY,OAAOZ;YACtC;QACF;QACAC,iBAAiBM;IACnB;IAEA,kDAAkD;IAClD,IAAIX,MAAMO,IAAI,KAAK,cAAc,OAAOH,QAAQ,UAAU;QACxD,IAAIA,IAAIa,WAAW,OAAO,QAAQZ,iBAAiB;QACnD,IAAID,IAAIa,WAAW,OAAO,SAASZ,iBAAiB;IACtD;IAEA,IAAI;QAAC;QAAO;QAAM;KAAS,CAACa,QAAQ,CAACjB,WAAW;QAC9C,IAAI,OAAOI,mBAAmB,UAAU;YACtCA,iBAAiBT,+BAA+BS;YAEhD,IAAIL,MAAMO,IAAI,KAAK,UAAU;gBAC3BF,iBAAiBA,eAAec,GAAG,CAAC,CAACC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,EAAE,EAAE,SAAS,CAAA;IACb,KAAK,EAAE,qBAAqB,CAAA;IAC5B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,GAAG,CAAA;CACX,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,4EAQxB,IAAI,KAAG,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EAAE,CAkB/E,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/selectDistinct.ts"],"sourcesContent":["import type { QueryPromise, SQL } from 'drizzle-orm'\n\nimport type { ChainedMethods } from '../find/chainMethods.js'\nimport type { DrizzleDB, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\nimport { chainMethods } from '../find/chainMethods.js'\nimport { type GenericColumn } from '../types.js'\n\ntype Args = {\n adapter: PostgresAdapter\n chainedMethods?: ChainedMethods\n db: DrizzleDB\n joins: BuildQueryJoinAliases\n selectFields: Record<string, GenericColumn>\n tableName: string\n where: SQL\n}\n\n/**\n * Selects distinct records from a table only if there are joins that need to be used, otherwise return null\n */\nexport const selectDistinct = ({\n adapter,\n chainedMethods = [],\n db,\n joins,\n selectFields,\n tableName,\n where,\n}: Args): QueryPromise<Record<string, GenericColumn> & { id: number | string }[]> => {\n if (Object.keys(joins).length > 0) {\n if (where) {\n chainedMethods.push({ args: [where], method: 'where' })\n }\n\n joins.forEach(({ condition, table }) => {\n chainedMethods.push({\n args: [table, condition],\n method: 'leftJoin',\n })\n })\n\n return chainMethods({\n methods: chainedMethods,\n query: db.selectDistinct(selectFields).from(adapter.tables[tableName]),\n })\n }\n}\n"],"names":["chainMethods","selectDistinct","adapter","chainedMethods","db","joins","selectFields","tableName","where","Object","keys","length","push","args","method","forEach","condition","table","methods","query","from","tables"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAMA,SAASA,YAAY,QAAQ,0BAAyB;AAatD;;CAEC,GACD,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,OAAO,EACPC,iBAAiB,EAAE,EACnBC,EAAE,EACFC,KAAK,EACLC,YAAY,EACZC,SAAS,EACTC,KAAK,EACA;IACL,IAAIC,OAAOC,IAAI,CAACL,OAAOM,MAAM,GAAG,GAAG;QACjC,IAAIH,OAAO;YACTL,eAAeS,IAAI,CAAC;gBAAEC,MAAM;oBAACL;iBAAM;gBAAEM,QAAQ;YAAQ;QACvD;QAEAT,MAAMU,OAAO,CAAC,CAAC,EAAEC,SAAS,EAAEC,KAAK,EAAE;YACjCd,eAAeS,IAAI,CAAC;gBAClBC,MAAM;oBAACI;oBAAOD;iBAAU;gBACxBF,QAAQ;YACV;QACF;QAEA,OAAOd,aAAa;YAClBkB,SAASf;YACTgB,OAAOf,GAAGH,cAAc,CAACK,cAAcc,IAAI,CAAClB,QAAQmB,MAAM,CAACd,UAAU;QACvE;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/selectDistinct.ts"],"sourcesContent":["import type { QueryPromise, SQL } from 'drizzle-orm'\n\nimport type { ChainedMethods } from '../find/chainMethods.js'\nimport type { DrizzleDB, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\nimport { chainMethods } from '../find/chainMethods.js'\nimport { type GenericColumn } from '../types.js'\n\ntype Args = {\n adapter: PostgresAdapter\n chainedMethods?: ChainedMethods\n db: DrizzleDB\n joins: BuildQueryJoinAliases\n selectFields: Record<string, GenericColumn>\n tableName: string\n where: SQL\n}\n\n/**\n * Selects distinct records from a table only if there are joins that need to be used, otherwise return null\n */\nexport const selectDistinct = ({\n adapter,\n chainedMethods = [],\n db,\n joins,\n selectFields,\n tableName,\n where,\n}: Args): QueryPromise<Record<string, GenericColumn> & { id: number | string }[]> => {\n if (Object.keys(joins).length > 0) {\n if (where) {\n chainedMethods.push({ args: [where], method: 'where' })\n }\n\n joins.forEach(({ condition, table }) => {\n chainedMethods.push({\n args: [table, condition],\n method: 'leftJoin',\n })\n })\n\n return chainMethods({\n methods: chainedMethods,\n query: db.selectDistinct(selectFields).from(adapter.tables[tableName]),\n })\n }\n}\n"],"names":["chainMethods","selectDistinct","adapter","chainedMethods","db","joins","selectFields","tableName","where","Object","keys","length","push","args","method","forEach","condition","table","methods","query","from","tables"],"mappings":"AAMA,SAASA,YAAY,QAAQ,0BAAyB;AAatD;;CAEC,GACD,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,OAAO,EACPC,iBAAiB,EAAE,EACnBC,EAAE,EACFC,KAAK,EACLC,YAAY,EACZC,SAAS,EACTC,KAAK,EACA;IACL,IAAIC,OAAOC,IAAI,CAACL,OAAOM,MAAM,GAAG,GAAG;QACjC,IAAIH,OAAO;YACTL,eAAeS,IAAI,CAAC;gBAAEC,MAAM;oBAACL;iBAAM;gBAAEM,QAAQ;YAAQ;QACvD;QAEAT,MAAMU,OAAO,CAAC,CAAC,EAAEC,SAAS,EAAEC,KAAK,EAAE;YACjCd,eAAeS,IAAI,CAAC;gBAClBC,MAAM;oBAACI;oBAAOD;iBAAU;gBACxBF,QAAQ;YACV;QACF;QAEA,OAAOd,aAAa;YAClBkB,SAASf;YACTgB,OAAOf,GAAGH,cAAc,CAACK,cAAcc,IAAI,CAAClB,QAAQmB,MAAM,CAACd,UAAU;QACvE;IACF;AACF,EAAC"}
@@ -1,3 +1,3 @@
1
- import { type QueryDrafts } from 'payload/database';
1
+ import type { QueryDrafts } from 'payload';
2
2
  export declare const queryDrafts: QueryDrafts;
3
3
  //# sourceMappingURL=queryDrafts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,kBAAkB,CAAA;AAQnE,eAAO,MAAM,WAAW,EAAE,WAgDzB,CAAA"}
1
+ {"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,WAAW,EAA6B,MAAM,SAAS,CAAA;AASrF,eAAO,MAAM,WAAW,EAAE,WAuCzB,CAAA"}
@@ -1,5 +1,4 @@
1
- import { combineQueries } from 'payload/database';
2
- import { buildVersionCollectionFields } from 'payload/versions';
1
+ import { buildVersionCollectionFields, combineQueries } from 'payload';
3
2
  import toSnakeCase from 'to-snake-case';
4
3
  import { findMany } from './find/findMany.js';
5
4
  export const queryDrafts = async function queryDrafts({ collection, limit, locale, page = 1, pagination, req = {}, sort, where }) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PayloadRequestWithData, SanitizedCollectionConfig } from 'payload/types'\n\nimport { type QueryDrafts, combineQueries } from 'payload/database'\nimport { buildVersionCollectionFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: PostgresAdapter,\n {\n collection,\n limit,\n locale,\n page = 1,\n pagination,\n req = {} as PayloadRequestWithData,\n sort,\n where,\n },\n) {\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`,\n )\n const fields = buildVersionCollectionFields(collectionConfig)\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const result = await findMany({\n adapter: this,\n fields,\n limit,\n locale,\n page,\n pagination,\n req,\n sort,\n tableName,\n where: combinedWhere,\n })\n\n return {\n ...result,\n docs: result.docs.map((doc) => {\n // eslint-disable-next-line no-param-reassign\n doc = {\n id: doc.parent,\n ...doc.version,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n\n return doc\n }),\n }\n}\n"],"names":["combineQueries","buildVersionCollectionFields","toSnakeCase","findMany","queryDrafts","collection","limit","locale","page","pagination","req","sort","where","collectionConfig","payload","collections","config","tableName","tableNameMap","get","slug","versionsSuffix","fields","combinedWhere","latest","equals","result","adapter","docs","map","doc","id","parent","version","createdAt","updatedAt"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAA2BA,cAAc,QAAQ,mBAAkB;AACnE,SAASC,4BAA4B,QAAQ,mBAAkB;AAC/D,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EACEC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,OAAO,CAAC,EACRC,UAAU,EACVC,MAAM,CAAC,CAA2B,EAClCC,IAAI,EACJC,KAAK,EACN;IAED,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACV,WAAW,CAACW,MAAM;IAC/F,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAEjB,YAAYW,iBAAiBO,IAAI,EAAE,EAAE,IAAI,CAACC,cAAc,CAAC,CAAC;IAEhE,MAAMC,SAASrB,6BAA6BY;IAE5C,MAAMU,gBAAgBvB,eAAe;QAAEwB,QAAQ;YAAEC,QAAQ;QAAK;IAAE,GAAGb;IAEnE,MAAMc,SAAS,MAAMvB,SAAS;QAC5BwB,SAAS,IAAI;QACbL;QACAhB;QACAC;QACAC;QACAC;QACAC;QACAC;QACAM;QACAL,OAAOW;IACT;IAEA,OAAO;QACL,GAAGG,MAAM;QACTE,MAAMF,OAAOE,IAAI,CAACC,GAAG,CAAC,CAACC;YACrB,6CAA6C;YAC7CA,MAAM;gBACJC,IAAID,IAAIE,MAAM;gBACd,GAAGF,IAAIG,OAAO;gBACdC,WAAWJ,IAAII,SAAS;gBACxBC,WAAWL,IAAIK,SAAS;YAC1B;YAEA,OAAOL;QACT;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PayloadRequest, QueryDrafts, SanitizedCollectionConfig } from 'payload'\n\nimport { buildVersionCollectionFields, combineQueries } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: PostgresAdapter,\n { collection, limit, locale, page = 1, pagination, req = {} as PayloadRequest, sort, where },\n) {\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`,\n )\n const fields = buildVersionCollectionFields(collectionConfig)\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const result = await findMany({\n adapter: this,\n fields,\n limit,\n locale,\n page,\n pagination,\n req,\n sort,\n tableName,\n where: combinedWhere,\n })\n\n return {\n ...result,\n docs: result.docs.map((doc) => {\n // eslint-disable-next-line no-param-reassign\n doc = {\n id: doc.parent,\n ...doc.version,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n\n return doc\n }),\n }\n}\n"],"names":["buildVersionCollectionFields","combineQueries","toSnakeCase","findMany","queryDrafts","collection","limit","locale","page","pagination","req","sort","where","collectionConfig","payload","collections","config","tableName","tableNameMap","get","slug","versionsSuffix","fields","combinedWhere","latest","equals","result","adapter","docs","map","doc","id","parent","version","createdAt","updatedAt"],"mappings":"AAEA,SAASA,4BAA4B,EAAEC,cAAc,QAAQ,UAAS;AACtE,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,OAAO,CAAC,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,IAAI,EAAEC,KAAK,EAAE;IAE5F,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACV,WAAW,CAACW,MAAM;IAC/F,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAEjB,YAAYW,iBAAiBO,IAAI,EAAE,EAAE,IAAI,CAACC,cAAc,CAAC,CAAC;IAEhE,MAAMC,SAAStB,6BAA6Ba;IAE5C,MAAMU,gBAAgBtB,eAAe;QAAEuB,QAAQ;YAAEC,QAAQ;QAAK;IAAE,GAAGb;IAEnE,MAAMc,SAAS,MAAMvB,SAAS;QAC5BwB,SAAS,IAAI;QACbL;QACAhB;QACAC;QACAC;QACAC;QACAC;QACAC;QACAM;QACAL,OAAOW;IACT;IAEA,OAAO;QACL,GAAGG,MAAM;QACTE,MAAMF,OAAOE,IAAI,CAACC,GAAG,CAAC,CAACC;YACrB,6CAA6C;YAC7CA,MAAM;gBACJC,IAAID,IAAIE,MAAM;gBACd,GAAGF,IAAIG,OAAO;gBACdC,WAAWJ,IAAII,SAAS;gBACxBC,WAAWL,IAAIK,SAAS;YAC1B;YAEA,OAAOL;QACT;IACF;AACF,EAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { ForeignKeyBuilder, IndexBuilder, PgColumnBuilder, UniqueConstraintBuilder } from 'drizzle-orm/pg-core';
2
- import type { Field } from 'payload/types';
2
+ import type { Field } from 'payload';
3
3
  import type { GenericColumns, PostgresAdapter } from '../types.js';
4
4
  export type BaseExtraConfig = Record<string, (cols: GenericColumns) => ForeignKeyBuilder | IndexBuilder | UniqueConstraintBuilder>;
5
5
  export type RelationMap = Map<string, {
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/schema/build.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,eAAe,EAEf,uBAAuB,EACxB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAA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