@payloadcms/db-postgres 3.0.0-canary.f6e77b8 → 3.0.0-canary.f83d96a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (288) 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 +12 -7
  5. package/dist/connect.js.map +1 -1
  6. package/dist/count.d.ts +1 -1
  7. package/dist/count.d.ts.map +1 -1
  8. package/dist/count.js +1 -10
  9. package/dist/count.js.map +1 -1
  10. package/dist/create.d.ts +1 -1
  11. package/dist/create.d.ts.map +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.map +1 -1
  16. package/dist/createGlobalVersion.d.ts +2 -3
  17. package/dist/createGlobalVersion.d.ts.map +1 -1
  18. package/dist/createGlobalVersion.js +1 -1
  19. package/dist/createGlobalVersion.js.map +1 -1
  20. package/dist/createMigration.d.ts +1 -1
  21. package/dist/createMigration.d.ts.map +1 -1
  22. package/dist/createMigration.js +56 -35
  23. package/dist/createMigration.js.map +1 -1
  24. package/dist/createVersion.d.ts +1 -2
  25. package/dist/createVersion.d.ts.map +1 -1
  26. package/dist/createVersion.js +3 -7
  27. package/dist/createVersion.js.map +1 -1
  28. package/dist/deleteMany.d.ts +1 -1
  29. package/dist/deleteMany.d.ts.map +1 -1
  30. package/dist/deleteMany.js.map +1 -1
  31. package/dist/deleteOne.d.ts +1 -1
  32. package/dist/deleteOne.d.ts.map +1 -1
  33. package/dist/deleteOne.js +2 -2
  34. package/dist/deleteOne.js.map +1 -1
  35. package/dist/deleteVersions.d.ts +1 -1
  36. package/dist/deleteVersions.d.ts.map +1 -1
  37. package/dist/deleteVersions.js +1 -1
  38. package/dist/deleteVersions.js.map +1 -1
  39. package/dist/destroy.d.ts +1 -1
  40. package/dist/destroy.d.ts.map +1 -1
  41. package/dist/destroy.js +4 -0
  42. package/dist/destroy.js.map +1 -1
  43. package/dist/exports/migration-utils.d.ts +2 -0
  44. package/dist/exports/migration-utils.d.ts.map +1 -0
  45. package/dist/exports/migration-utils.js +3 -0
  46. package/dist/exports/migration-utils.js.map +1 -0
  47. package/dist/find/buildFindManyArgs.d.ts +6 -2
  48. package/dist/find/buildFindManyArgs.d.ts.map +1 -1
  49. package/dist/find/buildFindManyArgs.js +2 -1
  50. package/dist/find/buildFindManyArgs.js.map +1 -1
  51. package/dist/find/chainMethods.d.ts.map +1 -1
  52. package/dist/find/chainMethods.js.map +1 -1
  53. package/dist/find/findMany.d.ts +1 -2
  54. package/dist/find/findMany.d.ts.map +1 -1
  55. package/dist/find/findMany.js +4 -15
  56. package/dist/find/findMany.js.map +1 -1
  57. package/dist/find/traverseFields.d.ts +4 -3
  58. package/dist/find/traverseFields.d.ts.map +1 -1
  59. package/dist/find/traverseFields.js +23 -5
  60. package/dist/find/traverseFields.js.map +1 -1
  61. package/dist/find.d.ts +1 -1
  62. package/dist/find.d.ts.map +1 -1
  63. package/dist/find.js.map +1 -1
  64. package/dist/findGlobal.d.ts +1 -1
  65. package/dist/findGlobal.d.ts.map +1 -1
  66. package/dist/findGlobal.js.map +1 -1
  67. package/dist/findGlobalVersions.d.ts +1 -1
  68. package/dist/findGlobalVersions.d.ts.map +1 -1
  69. package/dist/findGlobalVersions.js +1 -1
  70. package/dist/findGlobalVersions.js.map +1 -1
  71. package/dist/findOne.d.ts +1 -2
  72. package/dist/findOne.d.ts.map +1 -1
  73. package/dist/findOne.js.map +1 -1
  74. package/dist/findVersions.d.ts +1 -1
  75. package/dist/findVersions.d.ts.map +1 -1
  76. package/dist/findVersions.js +1 -1
  77. package/dist/findVersions.js.map +1 -1
  78. package/dist/index.d.ts +1 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +10 -1
  81. package/dist/index.js.map +1 -1
  82. package/dist/init.d.ts +1 -1
  83. package/dist/init.d.ts.map +1 -1
  84. package/dist/init.js +15 -20
  85. package/dist/init.js.map +1 -1
  86. package/dist/migrate.d.ts.map +1 -1
  87. package/dist/migrate.js +1 -1
  88. package/dist/migrate.js.map +1 -1
  89. package/dist/migrateDown.js +1 -1
  90. package/dist/migrateDown.js.map +1 -1
  91. package/dist/migrateFresh.d.ts.map +1 -1
  92. package/dist/migrateFresh.js +1 -1
  93. package/dist/migrateFresh.js.map +1 -1
  94. package/dist/migrateRefresh.js +1 -1
  95. package/dist/migrateRefresh.js.map +1 -1
  96. package/dist/migrateReset.js +1 -1
  97. package/dist/migrateReset.js.map +1 -1
  98. package/dist/migrateStatus.js +1 -1
  99. package/dist/migrateStatus.js.map +1 -1
  100. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  101. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  102. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  103. package/dist/predefinedMigrations/relationships-v2-v3.mjs +11 -0
  104. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +19 -0
  105. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -0
  106. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +169 -0
  107. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -0
  108. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +11 -0
  109. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -0
  110. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +191 -0
  111. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -0
  112. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts +3 -0
  113. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -0
  114. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js +56 -0
  115. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -0
  116. package/dist/predefinedMigrations/v2-v3/index.d.ts +23 -0
  117. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -0
  118. package/dist/predefinedMigrations/v2-v3/index.js +211 -0
  119. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -0
  120. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +19 -0
  121. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -0
  122. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +57 -0
  123. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -0
  124. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +22 -0
  125. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -0
  126. package/dist/predefinedMigrations/v2-v3/traverseFields.js +85 -0
  127. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -0
  128. package/dist/predefinedMigrations/v2-v3/types.d.ts +9 -0
  129. package/dist/predefinedMigrations/v2-v3/types.d.ts.map +1 -0
  130. package/dist/predefinedMigrations/v2-v3/types.js +6 -0
  131. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -0
  132. package/dist/queries/buildAndOrConditions.d.ts +4 -5
  133. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  134. package/dist/queries/buildAndOrConditions.js +1 -2
  135. package/dist/queries/buildAndOrConditions.js.map +1 -1
  136. package/dist/queries/buildQuery.d.ts +2 -3
  137. package/dist/queries/buildQuery.d.ts.map +1 -1
  138. package/dist/queries/buildQuery.js +1 -5
  139. package/dist/queries/buildQuery.js.map +1 -1
  140. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +1 -1
  141. package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +1 -1
  142. package/dist/queries/createJSONQuery/index.js.map +1 -1
  143. package/dist/queries/getTableColumnFromPath.d.ts +4 -5
  144. package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
  145. package/dist/queries/getTableColumnFromPath.js +170 -99
  146. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  147. package/dist/queries/operatorMap.js.map +1 -1
  148. package/dist/queries/parseParams.d.ts +4 -5
  149. package/dist/queries/parseParams.d.ts.map +1 -1
  150. package/dist/queries/parseParams.js +9 -8
  151. package/dist/queries/parseParams.js.map +1 -1
  152. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  153. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  154. package/dist/queries/sanitizeQueryValue.js +2 -3
  155. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  156. package/dist/queries/selectDistinct.d.ts +3 -4
  157. package/dist/queries/selectDistinct.d.ts.map +1 -1
  158. package/dist/queries/selectDistinct.js +3 -14
  159. package/dist/queries/selectDistinct.js.map +1 -1
  160. package/dist/queryDrafts.d.ts +1 -1
  161. package/dist/queryDrafts.d.ts.map +1 -1
  162. package/dist/queryDrafts.js +1 -2
  163. package/dist/queryDrafts.js.map +1 -1
  164. package/dist/schema/build.d.ts +9 -5
  165. package/dist/schema/build.d.ts.map +1 -1
  166. package/dist/schema/build.js +161 -112
  167. package/dist/schema/build.js.map +1 -1
  168. package/dist/schema/createIndex.js.map +1 -1
  169. package/dist/schema/createTableName.d.ts +1 -1
  170. package/dist/schema/createTableName.d.ts.map +1 -1
  171. package/dist/schema/createTableName.js +1 -1
  172. package/dist/schema/createTableName.js.map +1 -1
  173. package/dist/schema/idToUUID.d.ts +1 -1
  174. package/dist/schema/idToUUID.d.ts.map +1 -1
  175. package/dist/schema/idToUUID.js.map +1 -1
  176. package/dist/schema/parentIDColumnMap.js.map +1 -1
  177. package/dist/schema/setColumnID.d.ts +1 -1
  178. package/dist/schema/setColumnID.d.ts.map +1 -1
  179. package/dist/schema/setColumnID.js +2 -2
  180. package/dist/schema/setColumnID.js.map +1 -1
  181. package/dist/schema/traverseFields.d.ts +5 -7
  182. package/dist/schema/traverseFields.d.ts.map +1 -1
  183. package/dist/schema/traverseFields.js +105 -42
  184. package/dist/schema/traverseFields.js.map +1 -1
  185. package/dist/schema/validateExistingBlockIsIdentical.d.ts +1 -1
  186. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +1 -1
  187. package/dist/schema/validateExistingBlockIsIdentical.js +2 -2
  188. package/dist/schema/validateExistingBlockIsIdentical.js.map +1 -1
  189. package/dist/transactions/beginTransaction.d.ts +1 -1
  190. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  191. package/dist/transactions/beginTransaction.js +4 -0
  192. package/dist/transactions/beginTransaction.js.map +1 -1
  193. package/dist/transactions/commitTransaction.d.ts +1 -1
  194. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  195. package/dist/transactions/commitTransaction.js.map +1 -1
  196. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  197. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  198. package/dist/transactions/rollbackTransaction.js.map +1 -1
  199. package/dist/transform/read/hasManyNumber.d.ts +1 -1
  200. package/dist/transform/read/hasManyNumber.d.ts.map +1 -1
  201. package/dist/transform/read/hasManyNumber.js.map +1 -1
  202. package/dist/transform/read/hasManyText.d.ts +1 -1
  203. package/dist/transform/read/hasManyText.d.ts.map +1 -1
  204. package/dist/transform/read/hasManyText.js.map +1 -1
  205. package/dist/transform/read/index.d.ts +4 -3
  206. package/dist/transform/read/index.d.ts.map +1 -1
  207. package/dist/transform/read/index.js +2 -1
  208. package/dist/transform/read/index.js.map +1 -1
  209. package/dist/transform/read/relationship.d.ts +1 -1
  210. package/dist/transform/read/relationship.d.ts.map +1 -1
  211. package/dist/transform/read/relationship.js +0 -4
  212. package/dist/transform/read/relationship.js.map +1 -1
  213. package/dist/transform/read/traverseFields.d.ts +8 -3
  214. package/dist/transform/read/traverseFields.d.ts.map +1 -1
  215. package/dist/transform/read/traverseFields.js +70 -56
  216. package/dist/transform/read/traverseFields.js.map +1 -1
  217. package/dist/transform/write/array.d.ts +1 -1
  218. package/dist/transform/write/array.d.ts.map +1 -1
  219. package/dist/transform/write/array.js.map +1 -1
  220. package/dist/transform/write/blocks.d.ts +1 -1
  221. package/dist/transform/write/blocks.d.ts.map +1 -1
  222. package/dist/transform/write/blocks.js.map +1 -1
  223. package/dist/transform/write/index.d.ts +1 -1
  224. package/dist/transform/write/index.d.ts.map +1 -1
  225. package/dist/transform/write/index.js.map +1 -1
  226. package/dist/transform/write/numbers.js.map +1 -1
  227. package/dist/transform/write/relationships.d.ts +1 -1
  228. package/dist/transform/write/relationships.d.ts.map +1 -1
  229. package/dist/transform/write/relationships.js +1 -1
  230. package/dist/transform/write/relationships.js.map +1 -1
  231. package/dist/transform/write/selects.js.map +1 -1
  232. package/dist/transform/write/texts.js.map +1 -1
  233. package/dist/transform/write/traverseFields.d.ts +1 -1
  234. package/dist/transform/write/traverseFields.d.ts.map +1 -1
  235. package/dist/transform/write/traverseFields.js +21 -4
  236. package/dist/transform/write/traverseFields.js.map +1 -1
  237. package/dist/transform/write/types.js.map +1 -1
  238. package/dist/types.d.ts +4 -3
  239. package/dist/types.d.ts.map +1 -1
  240. package/dist/types.js.map +1 -1
  241. package/dist/update.d.ts +1 -1
  242. package/dist/update.d.ts.map +1 -1
  243. package/dist/update.js +1 -2
  244. package/dist/update.js.map +1 -1
  245. package/dist/updateGlobal.d.ts +2 -3
  246. package/dist/updateGlobal.d.ts.map +1 -1
  247. package/dist/updateGlobal.js.map +1 -1
  248. package/dist/updateGlobalVersion.d.ts +1 -2
  249. package/dist/updateGlobalVersion.d.ts.map +1 -1
  250. package/dist/updateGlobalVersion.js +1 -1
  251. package/dist/updateGlobalVersion.js.map +1 -1
  252. package/dist/updateVersion.d.ts +1 -2
  253. package/dist/updateVersion.d.ts.map +1 -1
  254. package/dist/updateVersion.js +1 -1
  255. package/dist/updateVersion.js.map +1 -1
  256. package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +1 -1
  257. package/dist/upsertRow/deleteExistingArrayRows.js.map +1 -1
  258. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
  259. package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -1
  260. package/dist/upsertRow/index.d.ts +2 -2
  261. package/dist/upsertRow/index.d.ts.map +1 -1
  262. package/dist/upsertRow/index.js +12 -8
  263. package/dist/upsertRow/index.js.map +1 -1
  264. package/dist/upsertRow/insertArrays.d.ts.map +1 -1
  265. package/dist/upsertRow/insertArrays.js.map +1 -1
  266. package/dist/upsertRow/types.d.ts +6 -1
  267. package/dist/upsertRow/types.d.ts.map +1 -1
  268. package/dist/upsertRow/types.js.map +1 -1
  269. package/dist/utilities/appendPrefixToKeys.d.ts.map +1 -1
  270. package/dist/utilities/appendPrefixToKeys.js.map +1 -1
  271. package/dist/utilities/createBlocksMap.d.ts.map +1 -1
  272. package/dist/utilities/createBlocksMap.js.map +1 -1
  273. package/dist/utilities/createMigrationTable.d.ts.map +1 -1
  274. package/dist/utilities/createMigrationTable.js.map +1 -1
  275. package/dist/utilities/createRelationshipMap.d.ts.map +1 -1
  276. package/dist/utilities/createRelationshipMap.js.map +1 -1
  277. package/dist/utilities/hasLocalesTable.d.ts +1 -1
  278. package/dist/utilities/hasLocalesTable.d.ts.map +1 -1
  279. package/dist/utilities/hasLocalesTable.js +1 -1
  280. package/dist/utilities/hasLocalesTable.js.map +1 -1
  281. package/dist/utilities/isArrayOfRows.js.map +1 -1
  282. package/dist/utilities/migrationTableExists.d.ts.map +1 -1
  283. package/dist/utilities/migrationTableExists.js.map +1 -1
  284. package/dist/utilities/parseError.js.map +1 -1
  285. package/dist/utilities/pushDevSchema.d.ts.map +1 -1
  286. package/dist/utilities/pushDevSchema.js +1 -1
  287. package/dist/utilities/pushDevSchema.js.map +1 -1
  288. package/package.json +20 -11
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, Where } from 'payload/types'\n\nimport { asc, desc } from 'drizzle-orm'\n\nimport type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js'\n\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\nimport { parseParams } from './parseParams.js'\n\nexport type BuildQueryJoins = Record<string, SQL>\n\nexport type BuildQueryJoinAliases = {\n condition: SQL\n table: GenericTable | PgTableWithColumns<any>\n}[]\n\ntype BuildQueryArgs = {\n adapter: PostgresAdapter\n fields: Field[]\n locale?: string\n sort?: string\n tableName: string\n where: Where\n}\n\ntype Result = {\n joinAliases: BuildQueryJoinAliases\n joins: BuildQueryJoins\n orderBy: {\n column: GenericColumn\n order: typeof asc | typeof desc\n }\n selectFields: Record<string, GenericColumn>\n where: SQL\n}\nconst buildQuery = async function buildQuery({\n adapter,\n fields,\n locale,\n sort,\n tableName,\n where: incomingWhere,\n}: BuildQueryArgs): Promise<Result> {\n const selectFields: Record<string, GenericColumn> = {\n id: adapter.tables[tableName].id,\n }\n const joins: BuildQueryJoins = {}\n const joinAliases: BuildQueryJoinAliases = []\n\n const orderBy: Result['orderBy'] = {\n column: null,\n order: null,\n }\n\n if (sort) {\n let sortPath\n\n if (sort[0] === '-') {\n sortPath = sort.substring(1)\n orderBy.order = desc\n } else {\n sortPath = sort\n orderBy.order = asc\n }\n\n try {\n const { columnName: sortTableColumnName, table: sortTable } = getTableColumnFromPath({\n adapter,\n collectionPath: sortPath,\n fields,\n joinAliases,\n joins,\n locale,\n pathSegments: sortPath.replace(/__/g, '.').split('.'),\n selectFields,\n tableName,\n value: sortPath,\n })\n orderBy.column = sortTable?.[sortTableColumnName]\n } catch (err) {\n // continue\n }\n }\n\n if (!orderBy?.column) {\n orderBy.order = desc\n const createdAt = adapter.tables[tableName]?.createdAt\n\n if (createdAt) {\n orderBy.column = createdAt\n } else {\n orderBy.column = adapter.tables[tableName].id\n }\n }\n\n if (orderBy.column) {\n selectFields.sort = orderBy.column\n }\n\n let where: SQL\n\n if (incomingWhere && Object.keys(incomingWhere).length > 0) {\n where = await parseParams({\n adapter,\n fields,\n joinAliases,\n joins,\n locale,\n selectFields,\n tableName,\n where: incomingWhere,\n })\n }\n\n return {\n joinAliases,\n joins,\n orderBy,\n selectFields,\n where,\n }\n}\n\nexport default buildQuery\n"],"names":["asc","desc","getTableColumnFromPath","parseParams","buildQuery","adapter","fields","locale","sort","tableName","where","incomingWhere","selectFields","id","tables","joins","joinAliases","orderBy","column","order","sortPath","substring","columnName","sortTableColumnName","table","sortTable","collectionPath","pathSegments","replace","split","value","err","createdAt","Object","keys","length"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,GAAG,EAAEC,IAAI,QAAQ,cAAa;AAIvC,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,WAAW,QAAQ,mBAAkB;AA4B9C,MAAMC,aAAa,eAAeA,WAAW,EAC3CC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,SAAS,EACTC,OAAOC,aAAa,EACL;IACf,MAAMC,eAA8C;QAClDC,IAAIR,QAAQS,MAAM,CAACL,UAAU,CAACI,EAAE;IAClC;IACA,MAAME,QAAyB,CAAC;IAChC,MAAMC,cAAqC,EAAE;IAE7C,MAAMC,UAA6B;QACjCC,QAAQ;QACRC,OAAO;IACT;IAEA,IAAIX,MAAM;QACR,IAAIY;QAEJ,IAAIZ,IAAI,CAAC,EAAE,KAAK,KAAK;YACnBY,WAAWZ,KAAKa,SAAS,CAAC;YAC1BJ,QAAQE,KAAK,GAAGlB;QAClB,OAAO;YACLmB,WAAWZ;YACXS,QAAQE,KAAK,GAAGnB;QAClB;QAEA,IAAI;YACF,MAAM,EAAEsB,YAAYC,mBAAmB,EAAEC,OAAOC,SAAS,EAAE,GAAGvB,uBAAuB;gBACnFG;gBACAqB,gBAAgBN;gBAChBd;gBACAU;gBACAD;gBACAR;gBACAoB,cAAcP,SAASQ,OAAO,CAAC,OAAO,KAAKC,KAAK,CAAC;gBACjDjB;gBACAH;gBACAqB,OAAOV;YACT;YACAH,QAAQC,MAAM,GAAGO,WAAW,CAACF,oBAAoB;QACnD,EAAE,OAAOQ,KAAK;QACZ,WAAW;QACb;IACF;IAEA,IAAI,CAACd,SAASC,QAAQ;QACpBD,QAAQE,KAAK,GAAGlB;QAChB,MAAM+B,YAAY3B,QAAQS,MAAM,CAACL,UAAU,EAAEuB;QAE7C,IAAIA,WAAW;YACbf,QAAQC,MAAM,GAAGc;QACnB,OAAO;YACLf,QAAQC,MAAM,GAAGb,QAAQS,MAAM,CAACL,UAAU,CAACI,EAAE;QAC/C;IACF;IAEA,IAAII,QAAQC,MAAM,EAAE;QAClBN,aAAaJ,IAAI,GAAGS,QAAQC,MAAM;IACpC;IAEA,IAAIR;IAEJ,IAAIC,iBAAiBsB,OAAOC,IAAI,CAACvB,eAAewB,MAAM,GAAG,GAAG;QAC1DzB,QAAQ,MAAMP,YAAY;YACxBE;YACAC;YACAU;YACAD;YACAR;YACAK;YACAH;YACAC,OAAOC;QACT;IACF;IAEA,OAAO;QACLK;QACAD;QACAE;QACAL;QACAF;IACF;AACF;AAEA,eAAeN,WAAU"}
1
+ {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, Where } from 'payload'\n\nimport { asc, desc } from 'drizzle-orm'\n\nimport type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js'\n\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\nimport { parseParams } from './parseParams.js'\n\nexport type BuildQueryJoins = Record<string, SQL>\n\nexport type BuildQueryJoinAliases = {\n condition: SQL\n table: GenericTable | PgTableWithColumns<any>\n}[]\n\ntype BuildQueryArgs = {\n adapter: PostgresAdapter\n fields: Field[]\n locale?: string\n sort?: string\n tableName: string\n where: Where\n}\n\ntype Result = {\n joins: BuildQueryJoinAliases\n orderBy: {\n column: GenericColumn\n order: typeof asc | typeof desc\n }\n selectFields: Record<string, GenericColumn>\n where: SQL\n}\nconst buildQuery = async function buildQuery({\n adapter,\n fields,\n locale,\n sort,\n tableName,\n where: incomingWhere,\n}: BuildQueryArgs): Promise<Result> {\n const selectFields: Record<string, GenericColumn> = {\n id: adapter.tables[tableName].id,\n }\n const joins: BuildQueryJoinAliases = []\n\n const orderBy: Result['orderBy'] = {\n column: null,\n order: null,\n }\n\n if (sort) {\n let sortPath\n\n if (sort[0] === '-') {\n sortPath = sort.substring(1)\n orderBy.order = desc\n } else {\n sortPath = sort\n orderBy.order = asc\n }\n\n try {\n const { columnName: sortTableColumnName, table: sortTable } = getTableColumnFromPath({\n adapter,\n collectionPath: sortPath,\n fields,\n joins,\n locale,\n pathSegments: sortPath.replace(/__/g, '.').split('.'),\n selectFields,\n tableName,\n value: sortPath,\n })\n orderBy.column = sortTable?.[sortTableColumnName]\n } catch (err) {\n // continue\n }\n }\n\n if (!orderBy?.column) {\n orderBy.order = desc\n const createdAt = adapter.tables[tableName]?.createdAt\n\n if (createdAt) {\n orderBy.column = createdAt\n } else {\n orderBy.column = adapter.tables[tableName].id\n }\n }\n\n if (orderBy.column) {\n selectFields.sort = orderBy.column\n }\n\n let where: SQL\n\n if (incomingWhere && Object.keys(incomingWhere).length > 0) {\n where = await parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: incomingWhere,\n })\n }\n\n return {\n joins,\n orderBy,\n selectFields,\n where,\n }\n}\n\nexport default buildQuery\n"],"names":["asc","desc","getTableColumnFromPath","parseParams","buildQuery","adapter","fields","locale","sort","tableName","where","incomingWhere","selectFields","id","tables","joins","orderBy","column","order","sortPath","substring","columnName","sortTableColumnName","table","sortTable","collectionPath","pathSegments","replace","split","value","err","createdAt","Object","keys","length"],"mappings":"AAIA,SAASA,GAAG,EAAEC,IAAI,QAAQ,cAAa;AAIvC,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,WAAW,QAAQ,mBAAkB;AA2B9C,MAAMC,aAAa,eAAeA,WAAW,EAC3CC,OAAO,EACPC,M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K;YACAH;YACAC,OAAOC;QACT;IACF;IAEA,OAAO;QACLI;QACAC;QACAJ;QACAF;IACF;AACF;AAEA,eAAeN,WAAU"}
@@ -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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C;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,8 +1,8 @@
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
- import type { BuildQueryJoinAliases, BuildQueryJoins } from './buildQuery.js';
5
+ import type { BuildQueryJoinAliases } from './buildQuery.js';
6
6
  type Constraint = {
7
7
  columnName: string;
8
8
  table: GenericTable | PgTableWithColumns<any>;
@@ -25,8 +25,7 @@ type Args = {
25
25
  constraintPath?: string;
26
26
  constraints?: Constraint[];
27
27
  fields: (Field | TabAsField)[];
28
- joinAliases: BuildQueryJoinAliases;
29
- joins: BuildQueryJoins;
28
+ joins: BuildQueryJoinAliases;
30
29
  locale?: string;
31
30
  pathSegments: string[];
32
31
  rootTableName?: string;
@@ -46,6 +45,6 @@ type Args = {
46
45
  * Adds tables to `join`
47
46
  * @returns TableColumn
48
47
  */
49
- export declare const getTableColumnFromPath: ({ adapter, aliasTable, collectionPath, columnPrefix, constraintPath: incomingConstraintPath, constraints, fields, joinAliases, joins, locale: incomingLocale, pathSegments: incomingSegments, rootTableName: incomingRootTableName, selectFields, tableName, tableNameSuffix, value, }: Args) => TableColumn;
48
+ export declare const getTableColumnFromPath: ({ adapter, aliasTable, collectionPath, columnPrefix, constraintPath: incomingConstraintPath, constraints, fields, joins, locale: incomingLocale, pathSegments: incomingSegments, rootTableName: incomingRootTableName, selectFields, tableName, tableNameSuffix, value, }: Args) => TableColumn;
50
49
  export {};
51
50
  //# sourceMappingURL=getTableColumnFromPath.d.ts.map
@@ -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,EAAe,UAAU,EAAa,MAAM,eAAe,CAAA;AAUlG,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAE7E,KAAK,UAAU,GAAG;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,YAAY,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;IAC7C,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAED,KAAK,WAAW,GAAG;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,UAAU,EAAE,CAAA;IACzB,KAAK,EAAE,kBAAkB,CAAA;IACzB,uBAAuB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAA;IAClD,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,SAAS,CAAC,EAAE,GAAG,CAAA;IACf,KAAK,EAAE,YAAY,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;CAC9C,CAAA;AA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slint-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
  /**
9
8
  * Transforms path to table and column name
10
9
  * Adds tables to `join`
11
10
  * @returns TableColumn
12
- */ export const getTableColumnFromPath = ({ adapter, aliasTable, collectionPath, columnPrefix = '', constraintPath: incomingConstraintPath, constraints = [], fields, joinAliases, joins, locale: incomingLocale, pathSegments: incomingSegments, rootTableName: incomingRootTableName, selectFields, tableName, tableNameSuffix = '', value })=>{
11
+ */ export const getTableColumnFromPath = ({ adapter, aliasTable, collectionPath, columnPrefix = '', constraintPath: incomingConstraintPath, constraints = [], fields, joins, locale: incomingLocale, pathSegments: incomingSegments, rootTableName: incomingRootTableName, selectFields, tableName, tableNameSuffix = '', value })=>{
13
12
  const fieldPath = incomingSegments[0];
14
13
  let locale = incomingLocale;
15
14
  const rootTableName = incomingRootTableName || tableName;
@@ -55,7 +54,6 @@ import { v4 as uuid } from 'uuid';
55
54
  ...tab,
56
55
  type: 'tab'
57
56
  })),
58
- joinAliases,
59
57
  joins,
60
58
  locale,
61
59
  pathSegments: pathSegments.slice(1),
@@ -77,7 +75,6 @@ import { v4 as uuid } from 'uuid';
77
75
  constraintPath: `${constraintPath}${field.name}.`,
78
76
  constraints,
79
77
  fields: field.fields,
80
- joinAliases,
81
78
  joins,
82
79
  locale,
83
80
  pathSegments: pathSegments.slice(1),
@@ -96,7 +93,6 @@ import { v4 as uuid } from 'uuid';
96
93
  constraintPath,
97
94
  constraints,
98
95
  fields: field.fields,
99
- joinAliases,
100
96
  joins,
101
97
  locale,
102
98
  pathSegments: pathSegments.slice(1),
@@ -111,7 +107,10 @@ import { v4 as uuid } from 'uuid';
111
107
  {
112
108
  if (locale && field.localized && adapter.payload.config.localization) {
113
109
  newTableName = `${tableName}${adapter.localesSuffix}`;
114
- joins[tableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID);
110
+ joins.push({
111
+ condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),
112
+ table: adapter.tables[newTableName]
113
+ });
115
114
  if (locale !== 'all') {
116
115
  constraints.push({
117
116
  columnName: '_locale',
@@ -128,7 +127,6 @@ import { v4 as uuid } from 'uuid';
128
127
  constraintPath: `${constraintPath}${field.name}.`,
129
128
  constraints,
130
129
  fields: field.fields,
131
- joinAliases,
132
130
  joins,
133
131
  locale,
134
132
  pathSegments: pathSegments.slice(1),
@@ -144,7 +142,10 @@ import { v4 as uuid } from 'uuid';
144
142
  if (field.hasMany) {
145
143
  const newTableName = adapter.tableNameMap.get(`${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`);
146
144
  if (locale && field.localized && adapter.payload.config.localization) {
147
- joins[newTableName] = and(eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent), eq(adapter.tables[newTableName]._locale, locale));
145
+ joins.push({
146
+ condition: and(eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent), eq(adapter.tables[newTableName]._locale, locale)),
147
+ table: adapter.tables[newTableName]
148
+ });
148
149
  if (locale !== 'all') {
149
150
  constraints.push({
150
151
  columnName: '_locale',
@@ -153,7 +154,10 @@ import { v4 as uuid } from 'uuid';
153
154
  });
154
155
  }
155
156
  } else {
156
- joins[newTableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent);
157
+ joins.push({
158
+ condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),
159
+ table: adapter.tables[newTableName]
160
+ });
157
161
  }
158
162
  return {
159
163
  columnName: 'value',
@@ -180,7 +184,10 @@ import { v4 as uuid } from 'uuid';
180
184
  eq(adapter.tables[newTableName].path, `${constraintPath}${field.name}`)
181
185
  ];
182
186
  if (locale && field.localized && adapter.payload.config.localization) {
183
- joins[newTableName] = and(...joinConstraints, eq(adapter.tables[newTableName]._locale, locale));
187
+ joins.push({
188
+ condition: and(...joinConstraints, eq(adapter.tables[newTableName]._locale, locale)),
189
+ table: adapter.tables[newTableName]
190
+ });
184
191
  if (locale !== 'all') {
185
192
  constraints.push({
186
193
  columnName: 'locale',
@@ -189,7 +196,10 @@ import { v4 as uuid } from 'uuid';
189
196
  });
190
197
  }
191
198
  } else {
192
- joins[newTableName] = and(...joinConstraints);
199
+ joins.push({
200
+ condition: and(...joinConstraints),
201
+ table: adapter.tables[newTableName]
202
+ });
193
203
  }
194
204
  return {
195
205
  columnName,
@@ -205,7 +215,10 @@ import { v4 as uuid } from 'uuid';
205
215
  newTableName = adapter.tableNameMap.get(`${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`);
206
216
  constraintPath = `${constraintPath}${field.name}.%.`;
207
217
  if (locale && field.localized && adapter.payload.config.localization) {
208
- joins[newTableName] = and(eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID), eq(adapter.tables[newTableName]._locale, locale));
218
+ joins.push({
219
+ condition: and(eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID), eq(adapter.tables[newTableName]._locale, locale)),
220
+ table: adapter.tables[newTableName]
221
+ });
209
222
  if (locale !== 'all') {
210
223
  constraints.push({
211
224
  columnName: '_locale',
@@ -214,7 +227,10 @@ import { v4 as uuid } from 'uuid';
214
227
  });
215
228
  }
216
229
  } else {
217
- joins[newTableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID);
230
+ joins.push({
231
+ condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),
232
+ table: adapter.tables[newTableName]
233
+ });
218
234
  }
219
235
  return getTableColumnFromPath({
220
236
  adapter,
@@ -222,7 +238,6 @@ import { v4 as uuid } from 'uuid';
222
238
  constraintPath,
223
239
  constraints,
224
240
  fields: field.fields,
225
- joinAliases,
226
241
  joins,
227
242
  locale,
228
243
  pathSegments: pathSegments.slice(1),
@@ -245,10 +260,15 @@ import { v4 as uuid } from 'uuid';
245
260
  blockTypes.forEach((blockType)=>{
246
261
  const block = field.blocks.find((block)=>block.slug === blockType);
247
262
  newTableName = adapter.tableNameMap.get(`${tableName}_blocks_${toSnakeCase(block.slug)}`);
248
- joins[newTableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID);
263
+ const newAliasTableName = toSnakeCase(uuid());
264
+ const newAliasTable = alias(adapter.tables[newTableName], newAliasTableName);
265
+ joins.push({
266
+ condition: eq(adapter.tables[tableName].id, newAliasTable._parentID),
267
+ table: newAliasTable
268
+ });
249
269
  constraints.push({
250
270
  columnName: '_path',
251
- table: adapter.tables[newTableName],
271
+ table: newAliasTable,
252
272
  value: pathSegments[0]
253
273
  });
254
274
  });
@@ -272,7 +292,6 @@ import { v4 as uuid } from 'uuid';
272
292
  constraintPath,
273
293
  constraints: blockConstraints,
274
294
  fields: block.fields,
275
- joinAliases,
276
295
  joins,
277
296
  locale,
278
297
  pathSegments: pathSegments.slice(1),
@@ -294,7 +313,10 @@ import { v4 as uuid } from 'uuid';
294
313
  ...blockSelectFields
295
314
  };
296
315
  if (field.localized && adapter.payload.config.localization) {
297
- joins[newTableName] = and(eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID), eq(adapter.tables[newTableName]._locale, locale));
316
+ joins.push({
317
+ condition: and(eq((aliasTable || adapter.tables[tableName]).id, adapter.tables[newTableName]._parentID), eq(adapter.tables[newTableName]._locale, locale)),
318
+ table: adapter.tables[newTableName]
319
+ });
298
320
  if (locale) {
299
321
  constraints.push({
300
322
  columnName: '_locale',
@@ -303,7 +325,10 @@ import { v4 as uuid } from 'uuid';
303
325
  });
304
326
  }
305
327
  } else {
306
- joins[newTableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID);
328
+ joins.push({
329
+ condition: eq((aliasTable || adapter.tables[tableName]).id, adapter.tables[newTableName]._parentID),
330
+ table: adapter.tables[newTableName]
331
+ });
307
332
  }
308
333
  return true;
309
334
  });
@@ -322,103 +347,149 @@ import { v4 as uuid } from 'uuid';
322
347
  case 'relationship':
323
348
  case 'upload':
324
349
  {
325
- let relationshipFields;
326
- const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`;
327
350
  const newCollectionPath = pathSegments.slice(1).join('.');
328
- const aliasRelationshipTableName = uuid();
329
- const aliasRelationshipTable = alias(adapter.tables[relationTableName], aliasRelationshipTableName);
330
- // Join in the relationships table
331
- if (locale && field.localized && adapter.payload.config.localization) {
332
- joinAliases.push({
333
- condition: and(eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent), eq(aliasRelationshipTable.locale, locale), like(aliasRelationshipTable.path, `${constraintPath}${field.name}`)),
334
- table: aliasRelationshipTable
335
- });
336
- if (locale !== 'all') {
337
- constraints.push({
338
- columnName: 'locale',
339
- table: aliasRelationshipTable,
340
- value: locale
351
+ if (Array.isArray(field.relationTo) || field.type === 'relationship' && field.hasMany) {
352
+ let relationshipFields;
353
+ const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`;
354
+ const aliasRelationshipTableName = uuid();
355
+ const aliasRelationshipTable = alias(adapter.tables[relationTableName], aliasRelationshipTableName);
356
+ // Join in the relationships table
357
+ if (locale && field.localized && adapter.payload.config.localization) {
358
+ joins.push({
359
+ condition: and(eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent), eq(aliasRelationshipTable.locale, locale), like(aliasRelationshipTable.path, `${constraintPath}${field.name}`)),
360
+ table: aliasRelationshipTable
361
+ });
362
+ if (locale !== 'all') {
363
+ constraints.push({
364
+ columnName: 'locale',
365
+ table: aliasRelationshipTable,
366
+ value: locale
367
+ });
368
+ }
369
+ } else {
370
+ // Join in the relationships table
371
+ joins.push({
372
+ condition: and(eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent), like(aliasRelationshipTable.path, `${constraintPath}${field.name}`)),
373
+ table: aliasRelationshipTable
341
374
  });
342
375
  }
343
- } else {
344
- // Join in the relationships table
345
- joinAliases.push({
346
- condition: and(eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent), like(aliasRelationshipTable.path, `${constraintPath}${field.name}`)),
347
- table: aliasRelationshipTable
348
- });
349
- }
350
- selectFields[`${relationTableName}.path`] = aliasRelationshipTable.path;
351
- let newAliasTable;
352
- if (typeof field.relationTo === 'string') {
353
- const relationshipConfig = adapter.payload.collections[field.relationTo].config;
354
- newTableName = adapter.tableNameMap.get(toSnakeCase(relationshipConfig.slug));
355
- // parent to relationship join table
356
- relationshipFields = relationshipConfig.fields;
357
- newAliasTable = alias(adapter.tables[newTableName], toSnakeCase(uuid()));
358
- joinAliases.push({
359
- condition: eq(newAliasTable.id, aliasRelationshipTable[`${field.relationTo}ID`]),
360
- table: newAliasTable
361
- });
362
- if (newCollectionPath === '' || newCollectionPath === 'id') {
376
+ selectFields[`${relationTableName}.path`] = aliasRelationshipTable.path;
377
+ let newAliasTable;
378
+ if (typeof field.relationTo === 'string') {
379
+ const relationshipConfig = adapter.payload.collections[field.relationTo].config;
380
+ newTableName = adapter.tableNameMap.get(toSnakeCase(relationshipConfig.slug));
381
+ // parent to relationship join table
382
+ relationshipFields = relationshipConfig.fields;
383
+ newAliasTable = alias(adapter.tables[newTableName], toSnakeCase(uuid()));
384
+ joins.push({
385
+ condition: eq(newAliasTable.id, aliasRelationshipTable[`${field.relationTo}ID`]),
386
+ table: newAliasTable
387
+ });
388
+ if (newCollectionPath === '' || newCollectionPath === 'id') {
389
+ return {
390
+ columnName: `${field.relationTo}ID`,
391
+ constraints,
392
+ field,
393
+ table: aliasRelationshipTable
394
+ };
395
+ }
396
+ } else if (newCollectionPath === 'value') {
397
+ const tableColumnsNames = field.relationTo.map((relationTo)=>{
398
+ const relationTableName = adapter.tableNameMap.get(toSnakeCase(adapter.payload.collections[relationTo].config.slug));
399
+ return `"${aliasRelationshipTableName}"."${relationTableName}_id"`;
400
+ });
363
401
  return {
364
- columnName: `${field.relationTo}ID`,
365
402
  constraints,
366
403
  field,
404
+ rawColumn: sql.raw(`COALESCE(${tableColumnsNames.join(', ')})`),
367
405
  table: aliasRelationshipTable
368
406
  };
407
+ } else if (newCollectionPath === 'relationTo') {
408
+ const relationTo = Array.isArray(field.relationTo) ? field.relationTo : [
409
+ field.relationTo
410
+ ];
411
+ return {
412
+ constraints,
413
+ field,
414
+ getNotNullColumnByValue: (val)=>{
415
+ const matchedRelation = relationTo.find((relation)=>relation === val);
416
+ if (matchedRelation) return `${matchedRelation}ID`;
417
+ return undefined;
418
+ },
419
+ table: aliasRelationshipTable
420
+ };
421
+ } else {
422
+ throw new APIError('Not supported');
369
423
  }
370
- } else if (newCollectionPath === 'value') {
371
- const tableColumnsNames = field.relationTo.map((relationTo)=>{
372
- const relationTableName = adapter.tableNameMap.get(toSnakeCase(adapter.payload.collections[relationTo].config.slug));
373
- return `"${aliasRelationshipTableName}"."${relationTableName}_id"`;
374
- });
375
- return {
424
+ return getTableColumnFromPath({
425
+ adapter,
426
+ aliasTable: newAliasTable,
427
+ collectionPath: newCollectionPath,
376
428
  constraints,
377
- field,
378
- rawColumn: sql.raw(`COALESCE(${tableColumnsNames.join(', ')})`),
379
- table: aliasRelationshipTable
380
- };
381
- } else if (newCollectionPath === 'relationTo') {
382
- const relationTo = Array.isArray(field.relationTo) ? field.relationTo : [
383
- field.relationTo
384
- ];
385
- return {
429
+ fields: relationshipFields,
430
+ joins,
431
+ locale,
432
+ pathSegments: pathSegments.slice(1),
433
+ rootTableName: newTableName,
434
+ selectFields,
435
+ tableName: newTableName,
436
+ value
437
+ });
438
+ } else if (pathSegments.length > 1 && !(pathSegments.length === 2 && pathSegments[1] === 'id')) {
439
+ // simple relationships
440
+ const columnName = `${columnPrefix}${field.name}`;
441
+ const newTableName = adapter.tableNameMap.get(toSnakeCase(adapter.payload.collections[field.relationTo].config.slug));
442
+ const aliasTableName = uuid();
443
+ const newAliasTable = alias(adapter.tables[newTableName], aliasTableName);
444
+ if (field.localized && adapter.payload.config.localization) {
445
+ const aliasLocaleTableName = uuid();
446
+ const aliasLocaleTable = alias(adapter.tables[`${rootTableName}${adapter.localesSuffix}`], aliasLocaleTableName);
447
+ joins.push({
448
+ condition: and(eq(aliasLocaleTable._parentID, adapter.tables[rootTableName].id), eq(aliasLocaleTable._locale, locale)),
449
+ table: aliasLocaleTable
450
+ });
451
+ joins.push({
452
+ condition: eq(aliasLocaleTable[columnName], newAliasTable.id),
453
+ table: newAliasTable
454
+ });
455
+ } else {
456
+ joins.push({
457
+ condition: eq(newAliasTable.id, aliasTable ? aliasTable[columnName] : adapter.tables[tableName][columnName]),
458
+ table: newAliasTable
459
+ });
460
+ }
461
+ return getTableColumnFromPath({
462
+ adapter,
463
+ aliasTable: newAliasTable,
464
+ collectionPath: newCollectionPath,
465
+ constraintPath: '',
386
466
  constraints,
387
- field,
388
- getNotNullColumnByValue: (val)=>{
389
- const matchedRelation = relationTo.find((relation)=>relation === val);
390
- if (matchedRelation) return `${matchedRelation}ID`;
391
- return undefined;
392
- },
393
- table: aliasRelationshipTable
394
- };
395
- } else {
396
- throw new APIError('Not supported');
467
+ fields: adapter.payload.collections[field.relationTo].config.fields,
468
+ joins,
469
+ locale,
470
+ pathSegments: pathSegments.slice(1),
471
+ selectFields,
472
+ tableName: newTableName,
473
+ value
474
+ });
397
475
  }
398
- return getTableColumnFromPath({
399
- adapter,
400
- aliasTable: newAliasTable,
401
- collectionPath: newCollectionPath,
402
- constraints,
403
- fields: relationshipFields,
404
- joinAliases,
405
- joins,
406
- locale,
407
- pathSegments: pathSegments.slice(1),
408
- rootTableName: newTableName,
409
- selectFields,
410
- tableName: newTableName,
411
- value
412
- });
476
+ break;
477
+ }
478
+ default:
479
+ {
480
+ break;
413
481
  }
414
482
  }
415
483
  if (fieldAffectsData(field)) {
416
484
  if (field.localized && adapter.payload.config.localization) {
417
485
  // If localized, we go to localized table and set aliasTable to undefined
418
486
  // so it is not picked up below to be used as targetTable
419
- newTableName = `${tableName}${adapter.localesSuffix}`;
420
487
  const parentTable = aliasTable || adapter.tables[tableName];
421
- joins[newTableName] = eq(parentTable.id, adapter.tables[newTableName]._parentID);
488
+ newTableName = `${tableName}${adapter.localesSuffix}`;
489
+ joins.push({
490
+ condition: eq(parentTable.id, adapter.tables[newTableName]._parentID),
491
+ table: adapter.tables[newTableName]
492
+ });
422
493
  aliasTable = undefined;
423
494
  if (locale !== 'all') {
424
495
  constraints.push({