@payloadcms/db-postgres 3.0.0-beta.9 → 3.0.0-canary.0017c67

Sign up to get free protection for your applications and to get access to all the features.
Files changed (301) 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 +3 -0
  7. package/dist/count.d.ts.map +1 -0
  8. package/dist/count.js +41 -0
  9. package/dist/count.js.map +1 -0
  10. package/dist/create.d.ts +1 -1
  11. package/dist/create.d.ts.map +1 -1
  12. package/dist/create.js +3 -5
  13. package/dist/create.js.map +1 -1
  14. package/dist/createGlobal.d.ts +2 -3
  15. package/dist/createGlobal.d.ts.map +1 -1
  16. package/dist/createGlobal.js +3 -5
  17. package/dist/createGlobal.js.map +1 -1
  18. package/dist/createGlobalVersion.d.ts +3 -4
  19. package/dist/createGlobalVersion.d.ts.map +1 -1
  20. package/dist/createGlobalVersion.js +3 -7
  21. package/dist/createGlobalVersion.js.map +1 -1
  22. package/dist/createMigration.d.ts +1 -1
  23. package/dist/createMigration.d.ts.map +1 -1
  24. package/dist/createMigration.js +56 -35
  25. package/dist/createMigration.js.map +1 -1
  26. package/dist/createVersion.d.ts +1 -2
  27. package/dist/createVersion.d.ts.map +1 -1
  28. package/dist/createVersion.js +11 -19
  29. package/dist/createVersion.js.map +1 -1
  30. package/dist/deleteMany.d.ts +1 -1
  31. package/dist/deleteMany.d.ts.map +1 -1
  32. package/dist/deleteMany.js +2 -5
  33. package/dist/deleteMany.js.map +1 -1
  34. package/dist/deleteOne.d.ts +1 -1
  35. package/dist/deleteOne.d.ts.map +1 -1
  36. package/dist/deleteOne.js +4 -7
  37. package/dist/deleteOne.js.map +1 -1
  38. package/dist/deleteVersions.d.ts +1 -1
  39. package/dist/deleteVersions.d.ts.map +1 -1
  40. package/dist/deleteVersions.js +3 -7
  41. package/dist/deleteVersions.js.map +1 -1
  42. package/dist/destroy.d.ts +1 -1
  43. package/dist/destroy.d.ts.map +1 -1
  44. package/dist/destroy.js +11 -7
  45. package/dist/destroy.js.map +1 -1
  46. package/dist/exports/migration-utils.d.ts +2 -0
  47. package/dist/exports/migration-utils.d.ts.map +1 -0
  48. package/dist/exports/migration-utils.js +3 -0
  49. package/dist/exports/migration-utils.js.map +1 -0
  50. package/dist/find/buildFindManyArgs.d.ts +6 -2
  51. package/dist/find/buildFindManyArgs.d.ts.map +1 -1
  52. package/dist/find/buildFindManyArgs.js +4 -3
  53. package/dist/find/buildFindManyArgs.js.map +1 -1
  54. package/dist/find/chainMethods.d.ts.map +1 -1
  55. package/dist/find/chainMethods.js.map +1 -1
  56. package/dist/find/findMany.d.ts +1 -2
  57. package/dist/find/findMany.d.ts.map +1 -1
  58. package/dist/find/findMany.js +4 -15
  59. package/dist/find/findMany.js.map +1 -1
  60. package/dist/find/traverseFields.d.ts +4 -3
  61. package/dist/find/traverseFields.d.ts.map +1 -1
  62. package/dist/find/traverseFields.js +27 -25
  63. package/dist/find/traverseFields.js.map +1 -1
  64. package/dist/find.d.ts +1 -1
  65. package/dist/find.d.ts.map +1 -1
  66. package/dist/find.js +2 -5
  67. package/dist/find.js.map +1 -1
  68. package/dist/findGlobal.d.ts +1 -1
  69. package/dist/findGlobal.d.ts.map +1 -1
  70. package/dist/findGlobal.js +2 -5
  71. package/dist/findGlobal.js.map +1 -1
  72. package/dist/findGlobalVersions.d.ts +1 -1
  73. package/dist/findGlobalVersions.d.ts.map +1 -1
  74. package/dist/findGlobalVersions.js +3 -7
  75. package/dist/findGlobalVersions.js.map +1 -1
  76. package/dist/findOne.d.ts +1 -2
  77. package/dist/findOne.d.ts.map +1 -1
  78. package/dist/findOne.js +2 -5
  79. package/dist/findOne.js.map +1 -1
  80. package/dist/findVersions.d.ts +1 -1
  81. package/dist/findVersions.d.ts.map +1 -1
  82. package/dist/findVersions.js +3 -7
  83. package/dist/findVersions.js.map +1 -1
  84. package/dist/index.d.ts +1 -1
  85. package/dist/index.d.ts.map +1 -1
  86. package/dist/index.js +18 -9
  87. package/dist/index.js.map +1 -1
  88. package/dist/init.d.ts +1 -1
  89. package/dist/init.d.ts.map +1 -1
  90. package/dist/init.js +20 -23
  91. package/dist/init.js.map +1 -1
  92. package/dist/migrate.d.ts.map +1 -1
  93. package/dist/migrate.js +1 -1
  94. package/dist/migrate.js.map +1 -1
  95. package/dist/migrateDown.js +1 -1
  96. package/dist/migrateDown.js.map +1 -1
  97. package/dist/migrateFresh.d.ts.map +1 -1
  98. package/dist/migrateFresh.js +1 -1
  99. package/dist/migrateFresh.js.map +1 -1
  100. package/dist/migrateRefresh.js +1 -1
  101. package/dist/migrateRefresh.js.map +1 -1
  102. package/dist/migrateReset.js +1 -1
  103. package/dist/migrateReset.js.map +1 -1
  104. package/dist/migrateStatus.js +1 -1
  105. package/dist/migrateStatus.js.map +1 -1
  106. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  107. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  108. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  109. package/dist/predefinedMigrations/relationships-v2-v3.mjs +11 -0
  110. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +19 -0
  111. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -0
  112. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +169 -0
  113. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -0
  114. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +11 -0
  115. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -0
  116. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +191 -0
  117. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -0
  118. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts +3 -0
  119. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -0
  120. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js +56 -0
  121. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -0
  122. package/dist/predefinedMigrations/v2-v3/index.d.ts +23 -0
  123. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -0
  124. package/dist/predefinedMigrations/v2-v3/index.js +211 -0
  125. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -0
  126. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +19 -0
  127. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -0
  128. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +57 -0
  129. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -0
  130. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +22 -0
  131. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -0
  132. package/dist/predefinedMigrations/v2-v3/traverseFields.js +85 -0
  133. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -0
  134. package/dist/predefinedMigrations/v2-v3/types.d.ts +9 -0
  135. package/dist/predefinedMigrations/v2-v3/types.d.ts.map +1 -0
  136. package/dist/predefinedMigrations/v2-v3/types.js +6 -0
  137. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -0
  138. package/dist/queries/buildAndOrConditions.d.ts +4 -5
  139. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  140. package/dist/queries/buildAndOrConditions.js +1 -2
  141. package/dist/queries/buildAndOrConditions.js.map +1 -1
  142. package/dist/queries/buildQuery.d.ts +2 -3
  143. package/dist/queries/buildQuery.d.ts.map +1 -1
  144. package/dist/queries/buildQuery.js +1 -5
  145. package/dist/queries/buildQuery.js.map +1 -1
  146. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +1 -1
  147. package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +1 -1
  148. package/dist/queries/createJSONQuery/index.js.map +1 -1
  149. package/dist/queries/getTableColumnFromPath.d.ts +4 -5
  150. package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
  151. package/dist/queries/getTableColumnFromPath.js +250 -146
  152. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  153. package/dist/queries/operatorMap.js.map +1 -1
  154. package/dist/queries/parseParams.d.ts +4 -5
  155. package/dist/queries/parseParams.d.ts.map +1 -1
  156. package/dist/queries/parseParams.js +9 -8
  157. package/dist/queries/parseParams.js.map +1 -1
  158. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  159. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  160. package/dist/queries/sanitizeQueryValue.js +2 -3
  161. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  162. package/dist/queries/selectDistinct.d.ts +3 -4
  163. package/dist/queries/selectDistinct.d.ts.map +1 -1
  164. package/dist/queries/selectDistinct.js +3 -14
  165. package/dist/queries/selectDistinct.js.map +1 -1
  166. package/dist/queryDrafts.d.ts +1 -1
  167. package/dist/queryDrafts.d.ts.map +1 -1
  168. package/dist/queryDrafts.js +3 -8
  169. package/dist/queryDrafts.js.map +1 -1
  170. package/dist/schema/build.d.ts +12 -7
  171. package/dist/schema/build.d.ts.map +1 -1
  172. package/dist/schema/build.js +208 -124
  173. package/dist/schema/build.js.map +1 -1
  174. package/dist/schema/createIndex.js.map +1 -1
  175. package/dist/schema/{getTableName.d.ts → createTableName.d.ts} +6 -8
  176. package/dist/schema/createTableName.d.ts.map +1 -0
  177. package/dist/schema/createTableName.js +31 -0
  178. package/dist/schema/createTableName.js.map +1 -0
  179. package/dist/schema/idToUUID.d.ts +1 -1
  180. package/dist/schema/idToUUID.d.ts.map +1 -1
  181. package/dist/schema/idToUUID.js.map +1 -1
  182. package/dist/schema/parentIDColumnMap.js.map +1 -1
  183. package/dist/schema/setColumnID.d.ts +1 -1
  184. package/dist/schema/setColumnID.d.ts.map +1 -1
  185. package/dist/schema/setColumnID.js +2 -2
  186. package/dist/schema/setColumnID.js.map +1 -1
  187. package/dist/schema/traverseFields.d.ts +5 -7
  188. package/dist/schema/traverseFields.d.ts.map +1 -1
  189. package/dist/schema/traverseFields.js +147 -63
  190. package/dist/schema/traverseFields.js.map +1 -1
  191. package/dist/schema/validateExistingBlockIsIdentical.d.ts +3 -2
  192. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +1 -1
  193. package/dist/schema/validateExistingBlockIsIdentical.js +15 -9
  194. package/dist/schema/validateExistingBlockIsIdentical.js.map +1 -1
  195. package/dist/transactions/beginTransaction.d.ts +1 -1
  196. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  197. package/dist/transactions/beginTransaction.js +4 -0
  198. package/dist/transactions/beginTransaction.js.map +1 -1
  199. package/dist/transactions/commitTransaction.d.ts +1 -1
  200. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  201. package/dist/transactions/commitTransaction.js.map +1 -1
  202. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  203. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  204. package/dist/transactions/rollbackTransaction.js.map +1 -1
  205. package/dist/transform/read/hasManyNumber.d.ts +1 -1
  206. package/dist/transform/read/hasManyNumber.d.ts.map +1 -1
  207. package/dist/transform/read/hasManyNumber.js.map +1 -1
  208. package/dist/transform/read/hasManyText.d.ts +1 -1
  209. package/dist/transform/read/hasManyText.d.ts.map +1 -1
  210. package/dist/transform/read/hasManyText.js.map +1 -1
  211. package/dist/transform/read/index.d.ts +4 -3
  212. package/dist/transform/read/index.d.ts.map +1 -1
  213. package/dist/transform/read/index.js +2 -1
  214. package/dist/transform/read/index.js.map +1 -1
  215. package/dist/transform/read/relationship.d.ts +1 -1
  216. package/dist/transform/read/relationship.d.ts.map +1 -1
  217. package/dist/transform/read/relationship.js +0 -4
  218. package/dist/transform/read/relationship.js.map +1 -1
  219. package/dist/transform/read/traverseFields.d.ts +8 -3
  220. package/dist/transform/read/traverseFields.d.ts.map +1 -1
  221. package/dist/transform/read/traverseFields.js +70 -56
  222. package/dist/transform/read/traverseFields.js.map +1 -1
  223. package/dist/transform/write/array.d.ts +1 -1
  224. package/dist/transform/write/array.d.ts.map +1 -1
  225. package/dist/transform/write/array.js.map +1 -1
  226. package/dist/transform/write/blocks.d.ts +1 -1
  227. package/dist/transform/write/blocks.d.ts.map +1 -1
  228. package/dist/transform/write/blocks.js +1 -1
  229. package/dist/transform/write/blocks.js.map +1 -1
  230. package/dist/transform/write/index.d.ts +1 -1
  231. package/dist/transform/write/index.d.ts.map +1 -1
  232. package/dist/transform/write/index.js.map +1 -1
  233. package/dist/transform/write/numbers.js.map +1 -1
  234. package/dist/transform/write/relationships.d.ts +1 -1
  235. package/dist/transform/write/relationships.d.ts.map +1 -1
  236. package/dist/transform/write/relationships.js +1 -1
  237. package/dist/transform/write/relationships.js.map +1 -1
  238. package/dist/transform/write/selects.js.map +1 -1
  239. package/dist/transform/write/texts.js.map +1 -1
  240. package/dist/transform/write/traverseFields.d.ts +1 -1
  241. package/dist/transform/write/traverseFields.d.ts.map +1 -1
  242. package/dist/transform/write/traverseFields.js +23 -6
  243. package/dist/transform/write/traverseFields.js.map +1 -1
  244. package/dist/transform/write/types.js.map +1 -1
  245. package/dist/types.d.ts +7 -9
  246. package/dist/types.d.ts.map +1 -1
  247. package/dist/types.js.map +1 -1
  248. package/dist/update.d.ts +1 -1
  249. package/dist/update.d.ts.map +1 -1
  250. package/dist/update.js +3 -7
  251. package/dist/update.js.map +1 -1
  252. package/dist/updateGlobal.d.ts +2 -3
  253. package/dist/updateGlobal.d.ts.map +1 -1
  254. package/dist/updateGlobal.js +2 -5
  255. package/dist/updateGlobal.js.map +1 -1
  256. package/dist/updateGlobalVersion.d.ts +1 -2
  257. package/dist/updateGlobalVersion.d.ts.map +1 -1
  258. package/dist/updateGlobalVersion.js +3 -7
  259. package/dist/updateGlobalVersion.js.map +1 -1
  260. package/dist/updateVersion.d.ts +1 -2
  261. package/dist/updateVersion.d.ts.map +1 -1
  262. package/dist/updateVersion.js +3 -7
  263. package/dist/updateVersion.js.map +1 -1
  264. package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +1 -1
  265. package/dist/upsertRow/deleteExistingArrayRows.js.map +1 -1
  266. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
  267. package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -1
  268. package/dist/upsertRow/index.d.ts +2 -2
  269. package/dist/upsertRow/index.d.ts.map +1 -1
  270. package/dist/upsertRow/index.js +10 -7
  271. package/dist/upsertRow/index.js.map +1 -1
  272. package/dist/upsertRow/insertArrays.d.ts.map +1 -1
  273. package/dist/upsertRow/insertArrays.js +3 -3
  274. package/dist/upsertRow/insertArrays.js.map +1 -1
  275. package/dist/upsertRow/types.d.ts +7 -2
  276. package/dist/upsertRow/types.d.ts.map +1 -1
  277. package/dist/upsertRow/types.js.map +1 -1
  278. package/dist/utilities/appendPrefixToKeys.d.ts.map +1 -1
  279. package/dist/utilities/appendPrefixToKeys.js.map +1 -1
  280. package/dist/utilities/createBlocksMap.d.ts.map +1 -1
  281. package/dist/utilities/createBlocksMap.js.map +1 -1
  282. package/dist/utilities/createMigrationTable.d.ts.map +1 -1
  283. package/dist/utilities/createMigrationTable.js.map +1 -1
  284. package/dist/utilities/createRelationshipMap.d.ts.map +1 -1
  285. package/dist/utilities/createRelationshipMap.js.map +1 -1
  286. package/dist/utilities/hasLocalesTable.d.ts +1 -1
  287. package/dist/utilities/hasLocalesTable.d.ts.map +1 -1
  288. package/dist/utilities/hasLocalesTable.js +1 -1
  289. package/dist/utilities/hasLocalesTable.js.map +1 -1
  290. package/dist/utilities/isArrayOfRows.js.map +1 -1
  291. package/dist/utilities/migrationTableExists.d.ts.map +1 -1
  292. package/dist/utilities/migrationTableExists.js.map +1 -1
  293. package/dist/utilities/parseError.js.map +1 -1
  294. package/dist/utilities/pushDevSchema.d.ts.map +1 -1
  295. package/dist/utilities/pushDevSchema.js +1 -1
  296. package/dist/utilities/pushDevSchema.js.map +1 -1
  297. package/package.json +34 -29
  298. package/dist/schema/getTableName.d.ts.map +0 -1
  299. package/dist/schema/getTableName.js +0 -31
  300. package/dist/schema/getTableName.js.map +0 -1
  301. package/src/index.ts +0 -156
@@ -1,13 +1,10 @@
1
1
  import { inArray } from 'drizzle-orm';
2
+ import toSnakeCase from 'to-snake-case';
2
3
  import { findMany } from './find/findMany.js';
3
- import { getTableName } from './schema/getTableName.js';
4
4
  export const deleteMany = async function deleteMany({ collection, req = {}, where }) {
5
5
  const db = this.sessions[req.transactionID]?.db || this.drizzle;
6
6
  const collectionConfig = this.payload.collections[collection].config;
7
- const tableName = getTableName({
8
- adapter: this,
9
- config: collectionConfig
10
- });
7
+ const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug));
11
8
  const result = await findMany({
12
9
  adapter: this,
13
10
  fields: collectionConfig.fields,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany } from 'payload/database'\nimport type { PayloadRequest } from 'payload/types'\n\nimport { inArray } from 'drizzle-orm'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\nimport { getTableName } from './schema/getTableName.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: PostgresAdapter,\n { collection, req = {} as PayloadRequest, where },\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collectionConfig = this.payload.collections[collection].config\n const tableName = getTableName({ adapter: this, config: collectionConfig })\n\n const result = await findMany({\n adapter: this,\n fields: collectionConfig.fields,\n limit: 0,\n locale: req.locale,\n page: 1,\n pagination: false,\n req,\n tableName,\n where,\n })\n\n const ids = []\n\n result.docs.forEach((data) => {\n ids.push(data.id)\n })\n\n if (ids.length > 0) {\n await db.delete(this.tables[tableName]).where(inArray(this.tables[tableName].id, ids))\n }\n}\n"],"names":["inArray","findMany","getTableName","deleteMany","collection","req","where","db","sessions","transactionID","drizzle","collectionConfig","payload","collections","config","tableName","adapter","result","fields","limit","locale","page","pagination","ids","docs","forEach","data","push","id","length","delete","tables"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,OAAO,QAAQ,cAAa;AAIrC,SAASC,QAAQ,QAAQ,qBAAoB;AAC7C,SAASC,YAAY,QAAQ,2BAA0B;AAEvD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEjD,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACH,IAAII,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACT,WAAW,CAACU,MAAM;IACpE,MAAMC,YAAYb,aAAa;QAAEc,SAAS,IAAI;QAAEF,QAAQH;IAAiB;IAEzE,MAAMM,SAAS,MAAMhB,SAAS;QAC5Be,SAAS,IAAI;QACbE,QAAQP,iBAAiBO,MAAM;QAC/BC,OAAO;QACPC,QAAQf,IAAIe,MAAM;QAClBC,MAAM;QACNC,YAAY;QACZjB;QACAU;QACAT;IACF;IAEA,MAAMiB,MAAM,EAAE;IAEdN,OAAOO,IAAI,CAACC,OAAO,CAAC,CAACC;QACnBH,IAAII,IAAI,CAACD,KAAKE,EAAE;IAClB;IAEA,IAAIL,IAAIM,MAAM,GAAG,GAAG;QAClB,MAAMtB,GAAGuB,MAAM,CAAC,IAAI,CAACC,MAAM,CAAChB,UAAU,EAAET,KAAK,CAACN,QAAQ,IAAI,CAAC+B,MAAM,CAAChB,UAAU,CAACa,EAAE,EAAEL;IACnF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany, PayloadRequestWithData } from 'payload'\n\nimport { inArray } from 'drizzle-orm'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: PostgresAdapter,\n { collection, req = {} as PayloadRequestWithData, where },\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collectionConfig = this.payload.collections[collection].config\n\n const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug))\n\n const result = await findMany({\n adapter: this,\n fields: collectionConfig.fields,\n limit: 0,\n locale: req.locale,\n page: 1,\n pagination: false,\n req,\n tableName,\n where,\n })\n\n const ids = []\n\n result.docs.forEach((data) => {\n ids.push(data.id)\n })\n\n if (ids.length > 0) {\n await db.delete(this.tables[tableName]).where(inArray(this.tables[tableName].id, ids))\n }\n}\n"],"names":["inArray","toSnakeCase","findMany","deleteMany","collection","req","where","db","sessions","transactionID","drizzle","collectionConfig","payload","collections","config","tableName","tableNameMap","get","slug","result","adapter","fields","limit","locale","page","pagination","ids","docs","forEach","data","push","id","length","delete","tables"],"mappings":"AAEA,SAASA,OAAO,QAAQ,cAAa;AACrC,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAA2B,EAAEC,KAAK,EAAE;IAEzD,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACH,IAAII,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACT,WAAW,CAACU,MAAM;IAEpE,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAAChB,YAAYU,iBAAiBO,IAAI;IAEzE,MAAMC,SAAS,MAAMjB,SAAS;QAC5BkB,SAAS,IAAI;QACbC,QAAQV,iBAAiBU,MAAM;QAC/BC,OAAO;QACPC,QAAQlB,IAAIkB,MAAM;QAClBC,MAAM;QACNC,YAAY;QACZpB;QACAU;QACAT;IACF;IAEA,MAAMoB,MAAM,EAAE;IAEdP,OAAOQ,IAAI,CAACC,OAAO,CAAC,CAACC;QACnBH,IAAII,IAAI,CAACD,KAAKE,EAAE;IAClB;IAEA,IAAIL,IAAIM,MAAM,GAAG,GAAG;QAClB,MAAMzB,GAAG0B,MAAM,CAAC,IAAI,CAACC,MAAM,CAACnB,UAAU,EAAET,KAAK,CAACN,QAAQ,IAAI,CAACkC,MAAM,CAACnB,UAAU,CAACgB,EAAE,EAAEL;IACnF;AACF,EAAC"}
@@ -1,3 +1,3 @@
1
- import type { DeleteOne } from 'payload/database';
1
+ import type { DeleteOne } from 'payload';
2
2
  export declare const deleteOne: DeleteOne;
3
3
  //# sourceMappingURL=deleteOne.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAajD,eAAO,MAAM,SAAS,EAAE,SAyDvB,CAAA"}
1
+ {"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAA0B,MAAM,SAAS,CAAA;AAYhE,eAAO,MAAM,SAAS,EAAE,SAwDvB,CAAA"}
package/dist/deleteOne.js CHANGED
@@ -1,18 +1,15 @@
1
1
  import { eq } from 'drizzle-orm';
2
+ import toSnakeCase from 'to-snake-case';
2
3
  import { buildFindManyArgs } from './find/buildFindManyArgs.js';
3
4
  import buildQuery from './queries/buildQuery.js';
4
5
  import { selectDistinct } from './queries/selectDistinct.js';
5
- import { getTableName } from './schema/getTableName.js';
6
6
  import { transform } from './transform/read/index.js';
7
7
  export const deleteOne = async function deleteOne({ collection: collectionSlug, req = {}, where: whereArg }) {
8
8
  const db = this.sessions[req.transactionID]?.db || this.drizzle;
9
9
  const collection = this.payload.collections[collectionSlug].config;
10
- const tableName = getTableName({
11
- adapter: this,
12
- config: collection
13
- });
10
+ const tableName = this.tableNameMap.get(toSnakeCase(collection.slug));
14
11
  let docToDelete;
15
- const { joinAliases, joins, selectFields, where } = await buildQuery({
12
+ const { joins, selectFields, where } = await buildQuery({
16
13
  adapter: this,
17
14
  fields: collection.fields,
18
15
  locale: req.locale,
@@ -30,7 +27,6 @@ export const deleteOne = async function deleteOne({ collection: collectionSlug,
30
27
  }
31
28
  ],
32
29
  db,
33
- joinAliases,
34
30
  joins,
35
31
  selectFields,
36
32
  tableName,
@@ -51,6 +47,7 @@ export const deleteOne = async function deleteOne({ collection: collectionSlug,
51
47
  docToDelete = await db.query[tableName].findFirst(findManyArgs);
52
48
  }
53
49
  const result = transform({
50
+ adapter: this,
54
51
  config: this.payload.config,
55
52
  data: docToDelete,
56
53
  fields: collection.fields
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne } from 'payload/database'\nimport type { PayloadRequest } from 'payload/types'\n\nimport { eq } from 'drizzle-orm'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { buildFindManyArgs } from './find/buildFindManyArgs.js'\nimport buildQuery from './queries/buildQuery.js'\nimport { selectDistinct } from './queries/selectDistinct.js'\nimport { getTableName } from './schema/getTableName.js'\nimport { transform } from './transform/read/index.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: PostgresAdapter,\n { collection: collectionSlug, req = {} as PayloadRequest, where: whereArg },\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collection = this.payload.collections[collectionSlug].config\n const tableName = getTableName({\n adapter: this,\n config: collection,\n })\n let docToDelete: Record<string, unknown>\n\n const { joinAliases, joins, selectFields, where } = await buildQuery({\n adapter: this,\n fields: collection.fields,\n locale: req.locale,\n tableName,\n where: whereArg,\n })\n\n const selectDistinctResult = await selectDistinct({\n adapter: this,\n chainedMethods: [{ args: [1], method: 'limit' }],\n db,\n joinAliases,\n joins,\n selectFields,\n tableName,\n where,\n })\n\n if (selectDistinctResult?.[0]?.id) {\n docToDelete = await db.query[tableName].findFirst({\n where: eq(this.tables[tableName].id, selectDistinctResult[0].id),\n })\n } else {\n const findManyArgs = buildFindManyArgs({\n adapter: this,\n depth: 0,\n fields: collection.fields,\n tableName,\n })\n\n findManyArgs.where = where\n\n docToDelete = await db.query[tableName].findFirst(findManyArgs)\n }\n\n const result = transform({\n config: this.payload.config,\n data: docToDelete,\n fields: collection.fields,\n })\n\n await db.delete(this.tables[tableName]).where(eq(this.tables[tableName].id, docToDelete.id))\n\n return result\n}\n"],"names":["eq","buildFindManyArgs","buildQuery","selectDistinct","getTableName","transform","deleteOne","collection","collectionSlug","req","where","whereArg","db","sessions","transactionID","drizzle","payload","collections","config","tableName","adapter","docToDelete","joinAliases","joins","selectFields","fields","locale","selectDistinctResult","chainedMethods","args","method","id","query","findFirst","tables","findManyArgs","depth","result","data","delete"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,EAAE,QAAQ,cAAa;AAIhC,SAASC,iBAAiB,QAAQ,8BAA6B;AAC/D,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,YAAY,QAAQ,2BAA0B;AACvD,SAASC,SAAS,QAAQ,4BAA2B;AAErD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,YAAYC,cAAc,EAAEC,MAAM,CAAC,CAAmB,EAAEC,OAAOC,QAAQ,EAAE;IAE3E,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACJ,IAAIK,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMR,aAAa,IAAI,CAACS,OAAO,CAACC,WAAW,CAACT,eAAe,CAACU,MAAM;IAClE,MAAMC,YAAYf,aAAa;QAC7BgB,SAAS,IAAI;QACbF,QAAQX;IACV;IACA,IAAIc;IAEJ,MAAM,EAAEC,WAAW,EAAEC,KAAK,EAAEC,YAAY,EAAEd,KAAK,EAAE,GAAG,MAAMR,WAAW;QACnEkB,SAAS,IAAI;QACbK,QAAQlB,WAAWkB,MAAM;QACzBC,QAAQjB,IAAIiB,MAAM;QAClBP;QACAT,OAAOC;IACT;IAEA,MAAMgB,uBAAuB,MAAMxB,eAAe;QAChDiB,SAAS,IAAI;QACbQ,gBAAgB;YAAC;gBAAEC,MAAM;oBAAC;iBAAE;gBAAEC,QAAQ;YAAQ;SAAE;QAChDlB;QACAU;QACAC;QACAC;QACAL;QACAT;IACF;IAEA,IAAIiB,sBAAsB,CAAC,EAAE,EAAEI,IAAI;QACjCV,cAAc,MAAMT,GAAGoB,KAAK,CAACb,UAAU,CAACc,SAAS,CAAC;YAChDvB,OAAOV,GAAG,IAAI,CAACkC,MAAM,CAACf,UAAU,CAACY,EAAE,EAAEJ,oBAAoB,CAAC,EAAE,CAACI,EAAE;QACjE;IACF,OAAO;QACL,MAAMI,eAAelC,kBAAkB;YACrCmB,SAAS,IAAI;YACbgB,OAAO;YACPX,QAAQlB,WAAWkB,MAAM;YACzBN;QACF;QAEAgB,aAAazB,KAAK,GAAGA;QAErBW,cAAc,MAAMT,GAAGoB,KAAK,CAACb,UAAU,CAACc,SAAS,CAACE;IACpD;IAEA,MAAME,SAAShC,UAAU;QACvBa,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;QAC3BoB,MAAMjB;QACNI,QAAQlB,WAAWkB,MAAM;IAC3B;IAEA,MAAMb,GAAG2B,MAAM,CAAC,IAAI,CAACL,MAAM,CAACf,UAAU,EAAET,KAAK,CAACV,GAAG,IAAI,CAACkC,MAAM,CAACf,UAAU,CAACY,EAAE,EAAEV,YAAYU,EAAE;IAE1F,OAAOM;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne, PayloadRequestWithData } from 'payload'\n\nimport { eq } from 'drizzle-orm'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { buildFindManyArgs } from './find/buildFindManyArgs.js'\nimport buildQuery from './queries/buildQuery.js'\nimport { selectDistinct } from './queries/selectDistinct.js'\nimport { transform } from './transform/read/index.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: PostgresAdapter,\n { collection: collectionSlug, req = {} as PayloadRequestWithData, where: whereArg },\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collection = this.payload.collections[collectionSlug].config\n\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n\n let docToDelete: Record<string, unknown>\n\n const { joins, selectFields, where } = await buildQuery({\n adapter: this,\n fields: collection.fields,\n locale: req.locale,\n tableName,\n where: whereArg,\n })\n\n const selectDistinctResult = await selectDistinct({\n adapter: this,\n chainedMethods: [{ args: [1], method: 'limit' }],\n db,\n joins,\n selectFields,\n tableName,\n where,\n })\n\n if (selectDistinctResult?.[0]?.id) {\n docToDelete = await db.query[tableName].findFirst({\n where: eq(this.tables[tableName].id, selectDistinctResult[0].id),\n })\n } else {\n const findManyArgs = buildFindManyArgs({\n adapter: this,\n depth: 0,\n fields: collection.fields,\n tableName,\n })\n\n findManyArgs.where = where\n\n docToDelete = await db.query[tableName].findFirst(findManyArgs)\n }\n\n const result = transform({\n adapter: this,\n config: this.payload.config,\n data: docToDelete,\n fields: collection.fields,\n })\n\n await db.delete(this.tables[tableName]).where(eq(this.tables[tableName].id, docToDelete.id))\n\n return result\n}\n"],"names":["eq","toSnakeCase","buildFindManyArgs","buildQuery","selectDistinct","transform","deleteOne","collection","collectionSlug","req","where","whereArg","db","sessions","transactionID","drizzle","payload","collections","config","tableName","tableNameMap","get","slug","docToDelete","joins","selectFields","adapter","fields","locale","selectDistinctResult","chainedMethods","args","method","id","query","findFirst","tables","findManyArgs","depth","result","data","delete"],"mappings":"AAEA,SAASA,EAAE,QAAQ,cAAa;AAChC,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,iBAAiB,QAAQ,8BAA6B;AAC/D,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,SAAS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AAI;QACbR,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;QAC3BsB,MAAMjB;QACNI,QAAQpB,WAAWoB,MAAM;IAC3B;IAEA,MAAMf,GAAG6B,MAAM,CAAC,IAAI,CAACL,MAAM,CAACjB,UAAU,EAAET,KAAK,CAACV,GAAG,IAAI,CAACoC,MAAM,CAACjB,UAAU,CAACc,EAAE,EAAEV,YAAYU,EAAE;IAE1F,OAAOM;AACT,EAAC"}
@@ -1,3 +1,3 @@
1
- import type { DeleteVersions } from 'payload/database';
1
+ import type { DeleteVersions } from 'payload';
2
2
  export declare const deleteVersions: DeleteVersions;
3
3
  //# sourceMappingURL=deleteVersions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAWtD,eAAO,MAAM,cAAc,EAAE,cAqC5B,CAAA"}
1
+ {"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAqD,MAAM,SAAS,CAAA;AAUhG,eAAO,MAAM,cAAc,EAAE,cAoC5B,CAAA"}
@@ -1,15 +1,11 @@
1
1
  import { inArray } from 'drizzle-orm';
2
- import { buildVersionCollectionFields } from 'payload/versions';
2
+ import { buildVersionCollectionFields } from 'payload';
3
+ import toSnakeCase from 'to-snake-case';
3
4
  import { findMany } from './find/findMany.js';
4
- import { getTableName } from './schema/getTableName.js';
5
5
  export const deleteVersions = async function deleteVersion({ collection, locale, req = {}, where: where }) {
6
6
  const db = this.sessions[req.transactionID]?.db || this.drizzle;
7
7
  const collectionConfig = this.payload.collections[collection].config;
8
- const tableName = getTableName({
9
- adapter: this,
10
- config: collectionConfig,
11
- versions: true
12
- });
8
+ const tableName = this.tableNameMap.get(`_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`);
13
9
  const fields = buildVersionCollectionFields(collectionConfig);
14
10
  const { docs } = await findMany({
15
11
  adapter: this,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions } from 'payload/database'\nimport type { PayloadRequest, SanitizedCollectionConfig } from 'payload/types'\n\nimport { inArray } from 'drizzle-orm'\nimport { buildVersionCollectionFields } from 'payload/versions'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\nimport { getTableName } from './schema/getTableName.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersion(\n this: PostgresAdapter,\n { collection, locale, req = {} as PayloadRequest, where: where },\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n\n const tableName = getTableName({\n adapter: this,\n config: collectionConfig,\n versions: true,\n })\n const fields = buildVersionCollectionFields(collectionConfig)\n\n const { docs } = await findMany({\n adapter: this,\n fields,\n limit: 0,\n locale,\n page: 1,\n pagination: false,\n req,\n tableName,\n where,\n })\n\n const ids = []\n\n docs.forEach((doc) => {\n ids.push(doc.id)\n })\n\n if (ids.length > 0) {\n await db.delete(this.tables[tableName]).where(inArray(this.tables[tableName].id, ids))\n }\n\n return docs\n}\n"],"names":["inArray","buildVersionCollectionFields","findMany","getTableName","deleteVersions","deleteVersion","collection","locale","req","where","db","sessions","transactionID","drizzle","collectionConfig","payload","collections","config","tableName","adapter","versions","fields","docs","limit","page","pagination","ids","forEach","doc","push","id","length","delete","tables"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,OAAO,QAAQ,cAAa;AACrC,SAASC,4BAA4B,QAAQ,mBAAkB;AAI/D,SAASC,QAAQ,QAAQ,qBAAoB;AAC7C,SAASC,YAAY,QAAQ,2BAA0B;AAEvD,OAAO,MAAMC,iBAAiC,eAAeC,cAE3D,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,OAAOA,KAAK,EAAE;IAEhE,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACH,IAAII,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACV,WAAW,CAACW,MAAM;IAE/F,MAAMC,YAAYf,aAAa;QAC7BgB,SAAS,IAAI;QACbF,QAAQH;QACRM,UAAU;IACZ;IACA,MAAMC,SAASpB,6BAA6Ba;IAE5C,MAAM,EAAEQ,IAAI,EAAE,GAAG,MAAMpB,SAAS;QAC9BiB,SAAS,IAAI;QACbE;QACAE,OAAO;QACPhB;QACAiB,MAAM;QACNC,YAAY;QACZjB;QACAU;QACAT;IACF;IAEA,MAAMiB,MAAM,EAAE;IAEdJ,KAAKK,OAAO,CAAC,CAACC;QACZF,IAAIG,IAAI,CAACD,IAAIE,EAAE;IACjB;IAEA,IAAIJ,IAAIK,MAAM,GAAG,GAAG;QAClB,MAAMrB,GAAGsB,MAAM,CAAC,IAAI,CAACC,MAAM,CAACf,UAAU,EAAET,KAAK,CAACT,QAAQ,IAAI,CAACiC,MAAM,CAACf,UAAU,CAACY,EAAE,EAAEJ;IACnF;IAEA,OAAOJ;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions, PayloadRequestWithData, SanitizedCollectionConfig } from 'payload'\n\nimport { inArray } from 'drizzle-orm'\nimport { buildVersionCollectionFields } 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 deleteVersions: DeleteVersions = async function deleteVersion(\n this: PostgresAdapter,\n { collection, locale, req = {} as PayloadRequestWithData, where: where },\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`,\n )\n\n const fields = buildVersionCollectionFields(collectionConfig)\n\n const { docs } = await findMany({\n adapter: this,\n fields,\n limit: 0,\n locale,\n page: 1,\n pagination: false,\n req,\n tableName,\n where,\n })\n\n const ids = []\n\n docs.forEach((doc) => {\n ids.push(doc.id)\n })\n\n if (ids.length > 0) {\n await db.delete(this.tables[tableName]).where(inArray(this.tables[tableName].id, ids))\n }\n\n return docs\n}\n"],"names":["inArray","buildVersionCollectionFields","toSnakeCase","findMany","deleteVersions","deleteVersion","collection","locale","req","where","db","sessions","transactionID","drizzle","collectionConfig","payload","collections","config","tableName","tableNameMap","get","slug","versionsSuffix","fields","docs","adapter","limit","page","pagination","ids","forEach","doc","push","id","length","delete","tables"],"mappings":"AAEA,SAASA,OAAO,QAAQ,cAAa;AACrC,SAASC,4BAA4B,QAAQ,UAAS;AACtD,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,iBAAiC,eAAeC,cAE3D,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAA2B,EAAEC,OAAOA,KAAK,EAAE;IAExE,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACH,IAAII,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACV,WAAW,CAACW,MAAM;IAE/F,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAElB,YAAYY,iBAAiBO,IAAI,EAAE,EAAE,IAAI,CAACC,cAAc,CAAC,CAAC;IAGhE,MAAMC,SAAStB,6BAA6Ba;IAE5C,MAAM,EAAEU,IAAI,EAAE,GAAG,MAAMrB,SAAS;QAC9BsB,SAAS,IAAI;QACbF;QACAG,OAAO;QACPnB;QACAoB,MAAM;QACNC,YAAY;QACZpB;QACAU;QACAT;IACF;IAEA,MAAMoB,MAAM,EAAE;IAEdL,KAAKM,OAAO,CAAC,CAACC;QACZF,IAAIG,IAAI,CAACD,IAAIE,EAAE;IACjB;IAEA,IAAIJ,IAAIK,MAAM,GAAG,GAAG;QAClB,MAAMxB,GAAGyB,MAAM,CAAC,IAAI,CAACC,MAAM,CAAClB,UAAU,EAAET,KAAK,CAACT,QAAQ,IAAI,CAACoC,MAAM,CAAClB,UAAU,CAACe,EAAE,EAAEJ;IACnF;IAEA,OAAOL;AACT,EAAC"}
package/dist/destroy.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { Destroy } from 'payload/database';
1
+ import type { Destroy } from 'payload';
2
2
  export declare const destroy: Destroy;
3
3
  //# sourceMappingURL=destroy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"destroy.d.ts","sourceRoot":"","sources":["../src/destroy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAM/C,eAAO,MAAM,OAAO,EAAE,OAOrB,CAAA"}
1
+ {"version":3,"file":"destroy.d.ts","sourceRoot":"","sources":["../src/destroy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAKtC,eAAO,MAAM,OAAO,EAAE,OAWrB,CAAA"}
package/dist/destroy.js CHANGED
@@ -1,11 +1,15 @@
1
- import { pushDevSchema } from './utilities/pushDevSchema.js';
1
+ // eslint-disable-next-line @typescript-eslint/require-await
2
2
  export const destroy = async function destroy() {
3
- if (process.env.NODE_ENV !== 'production') {
4
- await pushDevSchema(this);
5
- } else {
6
- // TODO: this hangs test suite for some reason
7
- // await this.pool.end()
8
- }
3
+ this.enums = {};
4
+ this.schema = {};
5
+ this.tables = {};
6
+ this.relations = {};
7
+ this.fieldConstraints = {};
8
+ this.drizzle = undefined;
9
+ this.initializing = new Promise((res, rej)=>{
10
+ this.resolveInitializing = res;
11
+ this.rejectInitializing = rej;
12
+ });
9
13
  };
10
14
 
11
15
  //# sourceMappingURL=destroy.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/destroy.ts"],"sourcesContent":["import type { Destroy } from 'payload/database'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { pushDevSchema } from './utilities/pushDevSchema.js'\n\nexport const destroy: Destroy = async function destroy(this: PostgresAdapter) {\n if (process.env.NODE_ENV !== 'production') {\n await pushDevSchema(this)\n } else {\n // TODO: this hangs test suite for some reason\n // await this.pool.end()\n }\n}\n"],"names":["pushDevSchema","destroy","process","env","NODE_ENV"],"rangeMappings":";;;;;;;;","mappings":"AAIA,SAASA,aAAa,QAAQ,+BAA8B;AAE5D,OAAO,MAAMC,UAAmB,eAAeA;IAC7C,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,MAAMJ,cAAc,IAAI;IAC1B,OAAO;IACL,8CAA8C;IAC9C,wBAAwB;IAC1B;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/destroy.ts"],"sourcesContent":["import type { Destroy } from 'payload'\n\nimport type { PostgresAdapter } from './types.js'\n\n// eslint-disable-next-line @typescript-eslint/require-await\nexport const destroy: Destroy = async function destroy(this: PostgresAdapter) {\n this.enums = {}\n this.schema = {}\n this.tables = {}\n this.relations = {}\n this.fieldConstraints = {}\n this.drizzle = undefined\n this.initializing = new Promise((res, rej) => {\n this.resolveInitializing = res\n this.rejectInitializing = rej\n })\n}\n"],"names":["destroy","enums","schema","tables","relations","fieldConstraints","drizzle","undefined","initializing","Promise","res","rej","resolveInitializing","rejectInitializing"],"mappings":"AAIA,4DAA4D;AAC5D,OAAO,MAAMA,UAAmB,eAAeA;IAC7C,IAAI,CAACC,KAAK,GAAG,CAAC;IACd,IAAI,CAACC,MAAM,GAAG,CAAC;IACf,IAAI,CAACC,MAAM,GAAG,CAAC;IACf,IAAI,CAACC,SAAS,GAAG,CAAC;IAClB,IAAI,CAACC,gBAAgB,GAAG,CAAC;IACzB,IAAI,CAACC,OAAO,GAAGC;IACf,IAAI,CAACC,YAAY,GAAG,IAAIC,QAAQ,CAACC,KAAKC;QACpC,IAAI,CAACC,mBAAmB,GAAGF;QAC3B,IAAI,CAACG,kBAAkB,GAAGF;IAC5B;AACF,EAAC"}
@@ -0,0 +1,2 @@
1
+ export { migratePostgresV2toV3 } from '../predefinedMigrations/v2-v3/index.js';
2
+ //# sourceMappingURL=migration-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-utils.d.ts","sourceRoot":"","sources":["../../src/exports/migration-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAA"}
@@ -0,0 +1,3 @@
1
+ export { migratePostgresV2toV3 } from '../predefinedMigrations/v2-v3/index.js';
2
+
3
+ //# sourceMappingURL=migration-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/exports/migration-utils.ts"],"sourcesContent":["export { migratePostgresV2toV3 } from '../predefinedMigrations/v2-v3/index.js'\n"],"names":["migratePostgresV2toV3"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,yCAAwC"}
@@ -1,5 +1,5 @@
1
1
  import type { DBQueryConfig } from 'drizzle-orm';
2
- import type { Field } from 'payload/types';
2
+ import type { Field } from 'payload';
3
3
  import type { PostgresAdapter } from '../types.js';
4
4
  type BuildFindQueryArgs = {
5
5
  adapter: PostgresAdapter;
@@ -7,7 +7,11 @@ type BuildFindQueryArgs = {
7
7
  fields: Field[];
8
8
  tableName: string;
9
9
  };
10
- export type Result = DBQueryConfig<'many', true, any, any>;
10
+ export type Result = DBQueryConfig<'many', true, any, any> & {
11
+ with?: DBQueryConfig<'many', true, any, any> & {
12
+ _locales?: DBQueryConfig<'many', true, any, any>;
13
+ };
14
+ };
11
15
  export declare const buildFindManyArgs: ({ adapter, depth, fields, tableName, }: BuildFindQueryArgs) => Record<string, unknown>;
12
16
  export {};
13
17
  //# sourceMappingURL=buildFindManyArgs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildFindManyArgs.d.ts","sourceRoot":"","sources":["../../src/find/buildFindManyArgs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAE1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE,eAAe,CAAA;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAI1D,eAAO,MAAM,iBAAiB,2CAK3B,kBAAkB,KAAG,OAAO,MAAM,EAAE,OAAO,CA2D7C,CAAA"}
1
+ {"version":3,"file":"buildFindManyArgs.d.ts","sourceRoot":"","sources":["../../src/find/buildFindManyArgs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE,eAAe,CAAA;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG;IAC3D,IAAI,CAAC,EAAE,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG;QAC7C,QAAQ,CAAC,EAAE,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;KACjD,CAAA;CACF,CAAA;AAID,eAAO,MAAM,iBAAiB,2CAK3B,kBAAkB,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CA4D7C,CAAA"}
@@ -9,7 +9,8 @@ export const buildFindManyArgs = ({ adapter, depth, fields, tableName })=>{
9
9
  columns: {
10
10
  id: false,
11
11
  _parentID: false
12
- }
12
+ },
13
+ with: {}
13
14
  };
14
15
  if (adapter.tables[`${tableName}_texts`]) {
15
16
  result.with._texts = {
@@ -33,7 +34,7 @@ export const buildFindManyArgs = ({ adapter, depth, fields, tableName })=>{
33
34
  ]
34
35
  };
35
36
  }
36
- if (adapter.tables[`${tableName}_rels`]) {
37
+ if (adapter.tables[`${tableName}${adapter.relationshipsSuffix}`]) {
37
38
  result.with._rels = {
38
39
  columns: {
39
40
  id: false,
@@ -44,7 +45,7 @@ export const buildFindManyArgs = ({ adapter, depth, fields, tableName })=>{
44
45
  ]
45
46
  };
46
47
  }
47
- if (adapter.tables[`${tableName}_locales`]) {
48
+ if (adapter.tables[`${tableName}${adapter.localesSuffix}`]) {
48
49
  result.with._locales = _locales;
49
50
  }
50
51
  traverseFields({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/find/buildFindManyArgs.ts"],"sourcesContent":["import type { DBQueryConfig } from 'drizzle-orm'\nimport type { Field } from 'payload/types'\n\nimport type { PostgresAdapter } from '../types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\ntype BuildFindQueryArgs = {\n adapter: PostgresAdapter\n depth: number\n fields: Field[]\n tableName: string\n}\n\nexport type Result = DBQueryConfig<'many', true, any, any>\n\n// Generate the Drizzle query for findMany based on\n// a collection field structure\nexport const buildFindManyArgs = ({\n adapter,\n depth,\n fields,\n tableName,\n}: BuildFindQueryArgs): Record<string, unknown> => {\n const result: Result = {\n with: {},\n }\n\n const _locales: Result = {\n columns: {\n id: false,\n _parentID: false,\n },\n }\n\n if (adapter.tables[`${tableName}_texts`]) {\n result.with._texts = {\n columns: {\n id: false,\n parent: false,\n },\n orderBy: ({ order }, { asc: ASC }) => [ASC(order)],\n }\n }\n\n if (adapter.tables[`${tableName}_numbers`]) {\n result.with._numbers = {\n columns: {\n id: false,\n parent: false,\n },\n orderBy: ({ order }, { asc: ASC }) => [ASC(order)],\n }\n }\n\n if (adapter.tables[`${tableName}_rels`]) {\n result.with._rels = {\n columns: {\n id: false,\n parent: false,\n },\n orderBy: ({ order }, { asc: ASC }) => [ASC(order)],\n }\n }\n\n if (adapter.tables[`${tableName}_locales`]) {\n result.with._locales = _locales\n }\n\n traverseFields({\n _locales,\n adapter,\n currentArgs: result,\n currentTableName: tableName,\n depth,\n fields,\n path: '',\n topLevelArgs: result,\n topLevelTableName: tableName,\n })\n\n return result\n}\n"],"names":["traverseFields","buildFindManyArgs","adapter","depth","fields","tableName","result","with","_locales","columns","id","_parentID","tables","_texts","parent","orderBy","order","asc","ASC","_numbers","_rels","currentArgs","currentTableName","path","topLevelArgs","topLevelTableName"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,SAASA,cAAc,QAAQ,sBAAqB;AAWpD,mDAAmD;AACnD,+BAA+B;AAC/B,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,OAAO,EACPC,KAAK,EACLC,MAAM,EACNC,SAAS,EACU;IACnB,MAAMC,SAAiB;QACrBC,MAAM,CAAC;IACT;IAEA,MAAMC,WAAmB;QACvBC,SAAS;YACPC,IAAI;YACJC,WAAW;QACb;IACF;IAEA,IAAIT,QAAQU,MAAM,CAAC,CAAC,EAAEP,UAAU,MAAM,CAAC,CAAC,EAAE;QACxCC,OAAOC,IAAI,CAACM,MAAM,GAAG;YACnBJ,SAAS;gBACPC,IAAI;gBACJI,QAAQ;YACV;YACAC,SAAS,CAAC,EAAEC,KAAK,EAAE,EAAE,EAAEC,KAAKC,GAAG,EAAE,GAAK;oBAACA,IAAIF;iBAAO;QACpD;IACF;IAEA,IAAId,QAAQU,MAAM,CAAC,CAAC,EAAEP,UAAU,QAAQ,CAAC,CAAC,EAAE;QAC1CC,OAAOC,IAAI,CAACY,QAAQ,GAAG;YACrBV,SAAS;gBACPC,IAAI;gBACJI,QAAQ;YACV;YACAC,SAAS,CAAC,EAAEC,KAAK,EAAE,EAAE,EAAEC,KAAKC,GAAG,EAAE,GAAK;oBAACA,IAAIF;iBAAO;QACpD;IACF;IAEA,IAAId,QAAQU,MAAM,CAAC,CAAC,EAAEP,UAAU,KAAK,CAAC,CAAC,EAAE;QACvCC,OAAOC,IAAI,CAACa,KAAK,GAAG;YAClBX,SAAS;gBACPC,IAAI;gBACJI,QAAQ;YACV;YACAC,SAAS,CAAC,EAAEC,KAAK,EAAE,EAAE,EAAEC,KAAKC,GAAG,EAAE,GAAK;oBAACA,IAAIF;iBAAO;QACpD;IACF;IAEA,IAAId,QAAQU,MAAM,CAAC,CAAC,EAAEP,UAAU,QAAQ,CAAC,CAAC,EAAE;QAC1CC,OAAOC,IAAI,CAACC,QAAQ,GAAGA;IACzB;IAEAR,eAAe;QACbQ;QACAN;QACAmB,aAAaf;QACbgB,kBAAkBjB;QAClBF;QACAC;QACAmB,MAAM;QACNC,cAAclB;QACdmB,mBAAmBpB;IACrB;IAEA,OAAOC;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/find/buildFindManyArgs.ts"],"sourcesContent":["import type { DBQueryConfig } from 'drizzle-orm'\nimport type { Field } from 'payload'\n\nimport type { PostgresAdapter } from '../types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\ntype BuildFindQueryArgs = {\n adapter: PostgresAdapter\n depth: number\n fields: Field[]\n tableName: string\n}\n\nexport type Result = DBQueryConfig<'many', true, any, any> & {\n with?: DBQueryConfig<'many', true, any, any> & {\n _locales?: DBQueryConfig<'many', true, any, any>\n }\n}\n\n// Generate the Drizzle query for findMany based on\n// a collection field structure\nexport const buildFindManyArgs = ({\n adapter,\n depth,\n fields,\n tableName,\n}: BuildFindQueryArgs): Record<string, unknown> => {\n const result: Result = {\n with: {},\n }\n\n const _locales: Result = {\n columns: {\n id: false,\n _parentID: false,\n },\n with: {},\n }\n\n if (adapter.tables[`${tableName}_texts`]) {\n result.with._texts = {\n columns: {\n id: false,\n parent: false,\n },\n orderBy: ({ order }, { asc: ASC }) => [ASC(order)],\n }\n }\n\n if (adapter.tables[`${tableName}_numbers`]) {\n result.with._numbers = {\n columns: {\n id: false,\n parent: false,\n },\n orderBy: ({ order }, { asc: ASC }) => [ASC(order)],\n }\n }\n\n if (adapter.tables[`${tableName}${adapter.relationshipsSuffix}`]) {\n result.with._rels = {\n columns: {\n id: false,\n parent: false,\n },\n orderBy: ({ order }, { asc: ASC }) => [ASC(order)],\n }\n }\n\n if (adapter.tables[`${tableName}${adapter.localesSuffix}`]) {\n result.with._locales = _locales\n }\n\n traverseFields({\n _locales,\n adapter,\n currentArgs: result,\n currentTableName: tableName,\n depth,\n fields,\n path: '',\n topLevelArgs: result,\n topLevelTableName: tableName,\n })\n\n return result\n}\n"],"names":["traverseFields","buildFindManyArgs","adapter","depth","fields","tableName","result","with","_locales","columns","id","_parentID","tables","_texts","parent","orderBy","order","asc","ASC","_numbers","relationshipsSuffix","_rels","localesSuffix","currentArgs","currentTableName","path","topLevelArgs","topLevelTableName"],"mappings":"AAKA,SAASA,cAAc,QAAQ,sBAAqB;AAepD,mDAAmD;AACnD,+BAA+B;AAC/B,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,OAAO,EACPC,KAAK,EACLC,MAAM,EACNC,SAAS,EACU;IACnB,MAAMC,SAAiB;QACrBC,MAAM,CAAC;IACT;IAEA,MAAMC,WAAmB;QACvBC,SAAS;YACPC,IAAI;YACJC,WAAW;QACb;QACAJ,MAAM,CAAC;IACT;IAEA,IAAIL,QAAQU,MAAM,CAAC,CAAC,EAAEP,UAAU,MAAM,CAAC,CAAC,EAAE;QACxCC,OAAOC,IA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OAAO,EAAE,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;CACf,EAAE,CAAA;AAEH;;;;GAIG;AACH,QAAA,MAAM,YAAY;;;MAA4B,aAAa,CAAC,CAI3D,CAAA;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
1
+ {"version":3,"file":"chainMethods.d.ts","sourceRoot":"","sources":["../../src/find/chainMethods.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,OAAO,EAAE,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;CACf,EAAE,CAAA;AAEH;;;;GAIG;AACH,QAAA,MAAM,YAAY,GAAI,CAAC;;;MAAuB,YAAY,CAAC,CAAC,CAI3D,CAAA;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/find/chainMethods.ts"],"sourcesContent":["import type { QueryPromise } from 'drizzle-orm'\n\nexport type ChainedMethods = {\n args: unknown[]\n method: string\n}[]\n\n/**\n * Call and returning methods that would normally be chained together but cannot be because of control logic\n * @param methods\n * @param query\n */\nconst chainMethods = <T>({ methods, query }): QueryPromise<T> => {\n return methods.reduce((query, { args, method }) => {\n return query[method](...args)\n }, query)\n}\n\nexport { chainMethods }\n"],"names":["chainMethods","methods","query","reduce","args","method"],"rangeMappings":";;;;;;;;;","mappings":"AAOA;;;;CAIC,GACD,MAAMA,eAAe,CAAI,EAAEC,OAAO,EAAEC,KAAK,EAAE;IACzC,OAAOD,QAAQE,MAAM,CAAC,CAACD,OAAO,EAAEE,IAAI,EAAEC,MAAM,EAAE;QAC5C,OAAOH,KAAK,CAACG,OAAO,IAAID;IAC1B,GAAGF;AACL;AAEA,SAASF,YAAY,GAAE"}
1
+ {"version":3,"sources":["../../src/find/chainMethods.ts"],"sourcesContent":["import type { QueryPromise } from 'drizzle-orm'\n\nexport type ChainedMethods = {\n args: unknown[]\n method: string\n}[]\n\n/**\n * Call and returning methods that would normally be chained together but cannot be because of control logic\n * @param methods\n * @param query\n */\nconst chainMethods = <T>({ methods, query }): QueryPromise<T> => {\n return methods.reduce((query, { args, method }) => {\n return query[method](...args)\n }, query)\n}\n\nexport { chainMethods }\n"],"names":["chainMethods","methods","query","reduce","args","method"],"mappings":"AAOA;;;;CAIC,GACD,MAAMA,eAAe,CAAI,EAAEC,OAAO,EAAEC,KAAK,EAAE;IACzC,OAAOD,QAAQE,MAAM,CAAC,CAACD,OAAO,EAAEE,IAAI,EAAEC,MAAM,EAAE;QAC5C,OAAOH,KAAK,CAACG,OAAO,IAAID;IAC1B,GAAGF;AACL;AAEA,SAASF,YAAY,GAAE"}
@@ -1,5 +1,4 @@
1
- import type { FindArgs } from 'payload/database';
2
- import type { Field } from 'payload/types';
1
+ import type { Field, FindArgs } from 'payload';
3
2
  import type { PostgresAdapter } from '../types.js';
4
3
  type Args = Omit<FindArgs, 'collection'> & {
5
4
  adapter: PostgresAdapter;
@@ -1 +1 @@
1
- {"version":3,"file":"findMany.d.ts","sourceRoot":"","sources":["../../src/find/findMany.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,KAAK,EAAE,KAAK,EAA8B,MAAM,eAAe,CAAA;AAItE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AASlD,KAAK,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,GAAG;IACzC,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,QAAQ,iHAYlB,IAAI;;;;;;;;;;;EAgKN,CAAA"}
1
+ {"version":3,"file":"findMany.d.ts","sourceRoot":"","sources":["../../src/find/findMany.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAsC,MAAM,SAAS,CAAA;AAIlF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AASlD,KAAK,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,GAAG;IACzC,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,QAAQ,iHAYlB,IAAI;;;;;;;;;;;EAsJN,CAAA"}
@@ -13,7 +13,7 @@ export const findMany = async function find({ adapter, fields, limit: limitArg,
13
13
  let hasPrevPage;
14
14
  let hasNextPage;
15
15
  let pagingCounter;
16
- const { joinAliases, joins, orderBy, selectFields, where } = await buildQuery({
16
+ const { joins, orderBy, selectFields, where } = await buildQuery({
17
17
  adapter,
18
18
  fields,
19
19
  locale,
@@ -54,7 +54,6 @@ export const findMany = async function find({ adapter, fields, limit: limitArg,
54
54
  adapter,
55
55
  chainedMethods: selectDistinctMethods,
56
56
  db,
57
- joinAliases,
58
57
  joins,
59
58
  selectFields,
60
59
  tableName,
@@ -94,7 +93,7 @@ export const findMany = async function find({ adapter, fields, limit: limitArg,
94
93
  const findPromise = db.query[tableName].findMany(findManyArgs);
95
94
  if (pagination !== false && (orderedIDs ? orderedIDs?.length <= limit : true)) {
96
95
  const selectCountMethods = [];
97
- joinAliases.forEach(({ condition, table })=>{
96
+ joins.forEach(({ condition, table })=>{
98
97
  selectCountMethods.push({
99
98
  args: [
100
99
  table,
@@ -103,22 +102,11 @@ export const findMany = async function find({ adapter, fields, limit: limitArg,
103
102
  method: 'leftJoin'
104
103
  });
105
104
  });
106
- Object.entries(joins).forEach(([joinTable, condition])=>{
107
- if (joinTable) {
108
- selectCountMethods.push({
109
- args: [
110
- adapter.tables[joinTable],
111
- condition
112
- ],
113
- method: 'leftJoin'
114
- });
115
- }
116
- });
117
105
  const countResult = await chainMethods({
118
106
  methods: selectCountMethods,
119
107
  query: db.select({
120
108
  count: sql`count
121
- (DISTINCT ${adapter.tables[tableName].id})`
109
+ (DISTINCT ${adapter.tables[tableName].id})`
122
110
  }).from(table).where(where)
123
111
  });
124
112
  totalDocs = Number(countResult[0].count);
@@ -141,6 +129,7 @@ export const findMany = async function find({ adapter, fields, limit: limitArg,
141
129
  }
142
130
  const docs = rawDocs.map((data)=>{
143
131
  return transform({
132
+ adapter,
144
133
  config: adapter.payload.config,
145
134
  data,
146
135
  fields
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/find/findMany.ts"],"sourcesContent":["import type { FindArgs } from 'payload/database'\nimport type { Field, PayloadRequest, TypeWithID } from 'payload/types'\n\nimport { inArray, sql } from 'drizzle-orm'\n\nimport type { PostgresAdapter } from '../types.js'\nimport type { ChainedMethods } from './chainMethods.js'\n\nimport buildQuery from '../queries/buildQuery.js'\nimport { selectDistinct } from '../queries/selectDistinct.js'\nimport { transform } from '../transform/read/index.js'\nimport { buildFindManyArgs } from './buildFindManyArgs.js'\nimport { chainMethods } from './chainMethods.js'\n\ntype Args = Omit<FindArgs, 'collection'> & {\n adapter: PostgresAdapter\n fields: Field[]\n tableName: string\n}\n\nexport const findMany = async function find({\n adapter,\n fields,\n limit: limitArg,\n locale,\n page = 1,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort,\n tableName,\n where: whereArg,\n}: Args) {\n const db = adapter.sessions[req.transactionID]?.db || adapter.drizzle\n const table = adapter.tables[tableName]\n\n const limit = limitArg ?? 10\n let totalDocs: number\n let totalPages: number\n let hasPrevPage: boolean\n let hasNextPage: boolean\n let pagingCounter: number\n\n const { joinAliases, joins, orderBy, selectFields, where } = await buildQuery({\n adapter,\n fields,\n locale,\n sort,\n tableName,\n where: whereArg,\n })\n\n const orderedIDMap: Record<number | string, number> = {}\n let orderedIDs: (number | string)[]\n\n const selectDistinctMethods: ChainedMethods = []\n\n if (orderBy?.order && orderBy?.column) {\n selectDistinctMethods.push({\n args: [orderBy.order(orderBy.column)],\n method: 'orderBy',\n })\n }\n\n const findManyArgs = buildFindManyArgs({\n adapter,\n depth: 0,\n fields,\n tableName,\n })\n\n selectDistinctMethods.push({ args: [skip || (page - 1) * limit], method: 'offset' })\n selectDistinctMethods.push({ args: [limit === 0 ? undefined : limit], method: 'limit' })\n\n const selectDistinctResult = await selectDistinct({\n adapter,\n chainedMethods: selectDistinctMethods,\n db,\n joinAliases,\n joins,\n selectFields,\n tableName,\n where,\n })\n\n if (selectDistinctResult) {\n if (selectDistinctResult.length === 0) {\n return {\n docs: [],\n hasNextPage: false,\n hasPrevPage: false,\n limit,\n nextPage: null,\n page: 1,\n pagingCounter: 0,\n prevPage: null,\n totalDocs: 0,\n totalPages: 0,\n }\n } else {\n // set the id in an object for sorting later\n selectDistinctResult.forEach(({ id }, i) => {\n orderedIDMap[id] = i\n })\n orderedIDs = Object.keys(orderedIDMap)\n findManyArgs.where = inArray(adapter.tables[tableName].id, orderedIDs)\n }\n } else {\n findManyArgs.limit = limitArg === 0 ? undefined : limitArg\n\n const offset = skip || (page - 1) * limitArg\n\n if (!Number.isNaN(offset)) findManyArgs.offset = offset\n\n if (where) {\n findManyArgs.where = where\n }\n findManyArgs.orderBy = orderBy.order(orderBy.column)\n }\n\n const findPromise = db.query[tableName].findMany(findManyArgs)\n\n if (pagination !== false && (orderedIDs ? orderedIDs?.length <= limit : true)) {\n const selectCountMethods: ChainedMethods = []\n\n joinAliases.forEach(({ condition, table }) => {\n selectCountMethods.push({\n args: [table, condition],\n method: 'leftJoin',\n })\n })\n\n Object.entries(joins).forEach(([joinTable, condition]) => {\n if (joinTable) {\n selectCountMethods.push({\n args: [adapter.tables[joinTable], condition],\n method: 'leftJoin',\n })\n }\n })\n\n const countResult = await chainMethods({\n methods: selectCountMethods,\n query: db\n .select({\n count: sql<number>`count\n (DISTINCT ${adapter.tables[tableName].id})`,\n })\n .from(table)\n .where(where),\n })\n totalDocs = Number(countResult[0].count)\n totalPages = typeof limit === 'number' && limit !== 0 ? Math.ceil(totalDocs / limit) : 1\n hasPrevPage = page > 1\n hasNextPage = totalPages > page\n pagingCounter = (page - 1) * limit + 1\n }\n\n const rawDocs = await findPromise\n // sort rawDocs from selectQuery\n if (Object.keys(orderedIDMap).length > 0) {\n rawDocs.sort((a, b) => orderedIDMap[a.id] - orderedIDMap[b.id])\n }\n\n if (pagination === false || !totalDocs) {\n totalDocs = rawDocs.length\n totalPages = 1\n pagingCounter = 1\n hasPrevPage = false\n hasNextPage = false\n }\n\n const docs = rawDocs.map((data: TypeWithID) => {\n return transform({\n config: adapter.payload.config,\n data,\n fields,\n })\n })\n\n return {\n docs,\n hasNextPage,\n hasPrevPage,\n limit,\n nextPage: hasNextPage ? page + 1 : null,\n page,\n pagingCounter,\n prevPage: hasPrevPage ? page - 1 : null,\n totalDocs,\n totalPages,\n }\n}\n"],"names":["inArray","sql","buildQuery","selectDistinct","transform","buildFindManyArgs","chainMethods","findMany","find","adapter","fields","limit","limitArg","locale","page","pagination","req","skip","sort","tableName","where","whereArg","db","sessions","transactionID","drizzle","table","tables","totalDocs","totalPages","hasPrevPage","hasNextPage","pagingCounter","joinAliases","joins","orderBy","selectFields","orderedIDMap","orderedIDs","selectDistinctMethods","order","column","push","args","method","findManyArgs","depth","undefined","selectDistinctResult","chainedMethods","length","docs","nextPage","prevPage","forEach","id","i","Object","keys","offset","Number","isNaN","findPromise","query","selectCountMethods","condition","entries","joinTable","countResult","methods","select","count","from","Math","ceil","rawDocs","a","b","map","data","config","payload"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,OAAO,EAAEC,GAAG,QAAQ,cAAa;AAK1C,OAAOC,gBAAgB,2BAA0B;AACjD,SAASC,cAAc,QAAQ,+BAA8B;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;QACAD;QACAnB;QACAyC,UAAUrB,cAAcjB,OAAO,IAAI;QACnCA;QACAkB;QACAqB,UAAUvB,cAAchB,OAAO,IAAI;QACnCc;QACAC;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/find/findMany.ts"],"sourcesContent":["import type { Field, FindArgs, PayloadRequestWithData, TypeWithID } from 'payload'\n\nimport { inArray, sql } from 'drizzle-orm'\n\nimport type { PostgresAdapter } from '../types.js'\nimport type { ChainedMethods } from './chainMethods.js'\n\nimport buildQuery from '../queries/buildQuery.js'\nimport { selectDistinct } from '../queries/selectDistinct.js'\nimport { transform } from '../transform/read/index.js'\nimport { buildFindManyArgs } from './buildFindManyArgs.js'\nimport { chainMethods } from './chainMethods.js'\n\ntype Args = Omit<FindArgs, 'collection'> & {\n adapter: PostgresAdapter\n fields: Field[]\n tableName: string\n}\n\nexport const findMany = async function find({\n adapter,\n fields,\n limit: limitArg,\n locale,\n page = 1,\n pagination,\n req = {} as PayloadRequestWithData,\n skip,\n sort,\n tableName,\n where: whereArg,\n}: Args) {\n const db = adapter.sessions[req.transactionID]?.db || adapter.drizzle\n const table = adapter.tables[tableName]\n\n const limit = limitArg ?? 10\n let totalDocs: number\n let totalPages: number\n let hasPrevPage: boolean\n let hasNextPage: boolean\n let pagingCounter: number\n\n const { joins, orderBy, selectFields, where } = await buildQuery({\n adapter,\n fields,\n locale,\n sort,\n tableName,\n where: whereArg,\n })\n\n const orderedIDMap: Record<number | string, number> = {}\n let orderedIDs: (number | string)[]\n\n const selectDistinctMethods: ChainedMethods = []\n\n if (orderBy?.order && orderBy?.column) {\n selectDistinctMethods.push({\n args: [orderBy.order(orderBy.column)],\n method: 'orderBy',\n })\n }\n\n const findManyArgs = buildFindManyArgs({\n adapter,\n depth: 0,\n fields,\n tableName,\n })\n\n selectDistinctMethods.push({ args: [skip || (page - 1) * limit], method: 'offset' })\n selectDistinctMethods.push({ args: [limit === 0 ? undefined : limit], method: 'limit' })\n\n const selectDistinctResult = await selectDistinct({\n adapter,\n chainedMethods: selectDistinctMethods,\n db,\n joins,\n selectFields,\n tableName,\n where,\n })\n\n if (selectDistinctResult) {\n if (selectDistinctResult.length === 0) {\n return {\n docs: [],\n hasNextPage: false,\n hasPrevPage: false,\n limit,\n nextPage: null,\n page: 1,\n pagingCounter: 0,\n prevPage: null,\n totalDocs: 0,\n totalPages: 0,\n }\n } else {\n // set the id in an object for sorting later\n selectDistinctResult.forEach(({ id }, i) => {\n orderedIDMap[id] = i\n })\n orderedIDs = Object.keys(orderedIDMap)\n findManyArgs.where = inArray(adapter.tables[tableName].id, orderedIDs)\n }\n } else {\n findManyArgs.limit = limitArg === 0 ? undefined : limitArg\n\n const offset = skip || (page - 1) * limitArg\n\n if (!Number.isNaN(offset)) findManyArgs.offset = offset\n\n if (where) {\n findManyArgs.where = where\n }\n findManyArgs.orderBy = orderBy.order(orderBy.column)\n }\n\n const findPromise = db.query[tableName].findMany(findManyArgs)\n\n if (pagination !== false && (orderedIDs ? orderedIDs?.length <= limit : true)) {\n const selectCountMethods: ChainedMethods = []\n joins.forEach(({ condition, table }) => {\n selectCountMethods.push({\n args: [table, condition],\n method: 'leftJoin',\n })\n })\n\n const countResult = await chainMethods({\n methods: selectCountMethods,\n query: db\n .select({\n count: sql<number>`count\n (DISTINCT ${adapter.tables[tableName].id})`,\n })\n .from(table)\n .where(where),\n })\n totalDocs = Number(countResult[0].count)\n totalPages = typeof limit === 'number' && limit !== 0 ? Math.ceil(totalDocs / limit) : 1\n hasPrevPage = page > 1\n hasNextPage = totalPages > page\n pagingCounter = (page - 1) * limit + 1\n }\n\n const rawDocs = await findPromise\n // sort rawDocs from selectQuery\n if (Object.keys(orderedIDMap).length > 0) {\n rawDocs.sort((a, b) => orderedIDMap[a.id] - orderedIDMap[b.id])\n }\n\n if (pagination === false || !totalDocs) {\n totalDocs = rawDocs.length\n totalPages = 1\n pagingCounter = 1\n hasPrevPage = false\n hasNextPage = false\n }\n\n const docs = rawDocs.map((data: TypeWithID) => {\n return transform({\n adapter,\n config: adapter.payload.config,\n data,\n fields,\n })\n })\n\n return {\n docs,\n hasNextPage,\n hasPrevPage,\n limit,\n nextPage: hasNextPage ? page + 1 : null,\n page,\n pagingCounter,\n prevPage: hasPrevPage ? page - 1 : null,\n totalDocs,\n totalPages,\n }\n}\n"],"names":["inArray","sql","buildQuery","selectDistinct","transform","buildFindManyArgs","chainMethods","findMany","find","adapter","fields","limit","limitArg","locale","page","pagination","req","skip","sort","tableName","where","whereArg","db","sessions","transactionID","drizzle","table","tables","totalDocs","totalPages","hasPrevPage","hasNextPage","pagingCounter","joins","orderBy","selectFields","orderedIDMap","orderedIDs","selectDistinctMethods","order","column","push","args","method","findManyArgs","depth","undefined","selectDistinctResult","chainedMethods","length","docs","nextPage","prevPage","forEach","id","i","Object","keys","offset","Number","isNaN","findPromise","query","selectCountMethods","condition","countResult","methods","select","count","from","Math","ceil","rawDocs","a","b","map","data","config","payload"],"mappings":"AAEA,SAASA,OAAO,EAAEC,GAAG,QAAQ,cAAa;AAK1C,OAAOC,gBAAgB,2BAA0B;AACjD,SAASC,cAAc,QAAQ,+BAA8B;AAC7D,SAASC,SAAS,QAAQ,6BAA4B;AACtD,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,YAAY,QAAQ,oBAAmB;AAQhD,OAAO,MAAMC,WAAW,eAAeC,KAAK,EAC1CC,OAAO,EACPC,MAAM,EACNC,OAAOC,QAAQ,EACfC,MAAM,EACNC,OAAO,CAAC,EACRC,UAAU,EACVC,MAAM,CAAC,CAA2B,EAClCC,IAAI,EACJC,IAAI,EACJC,SAAS,EACTC,OAAOC,QAAQ,EACV;IACL,MAAMC,KAAKb,QAAQc,QAAQ,CAACP,IAAIQ,aAAa,CAAC,EAAEF,MAAMb,QAAQgB,OAAO;IACrE,MAAMC,QAAQjB,QAAQkB,MAAM,CAACR,UAAU;IAEvC,MAAMR,QAAQC,YAAY;IAC1B,IAAIgB;IACJ,IAAIC;IACJ,IAAIC;IACJ,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AACrB,cAAca,MAAM,GAAG,GAAG;QACxCuB,QAAQtD,IAAI,CAAC,CAACuD,GAAGC,IAAMtC,YAAY,CAACqC,EAAEnB,EAAE,CAAC,GAAGlB,YAAY,CAACsC,EAAEpB,EAAE,CAAC;IAChE;IAEA,IAAIvC,eAAe,SAAS,CAACa,WAAW;QACtCA,YAAY4C,QAAQvB,MAAM;QAC1BpB,aAAa;QACbG,gBAAgB;QAChBF,cAAc;QACdC,cAAc;IAChB;IAEA,MAAMmB,OAAOsB,QAAQG,GAAG,CAAC,CAACC;QACxB,OAAOxE,UAAU;YACfK;YACAoE,QAAQpE,QAAQqE,OAAO,CAACD,MAAM;YAC9BD;YACAlE;QACF;IACF;IAEA,OAAO;QACLwC;QACAnB;QACAD;QACAnB;QACAwC,UAAUpB,cAAcjB,OAAO,IAAI;QACnCA;QACAkB;QACAoB,UAAUtB,cAAchB,OAAO,IAAI;QACnCc;QACAC;IACF;AACF,EAAC"}
@@ -1,9 +1,10 @@
1
- import type { Field } from 'payload/types';
1
+ import type { Field } from 'payload';
2
2
  import type { PostgresAdapter } from '../types.js';
3
+ import type { Result } from './buildFindManyArgs.js';
3
4
  type TraverseFieldArgs = {
4
- _locales: Record<string, unknown>;
5
+ _locales: Result;
5
6
  adapter: PostgresAdapter;
6
- currentArgs: Record<string, unknown>;
7
+ currentArgs: Result;
7
8
  currentTableName: string;
8
9
  depth?: number;
9
10
  fields: Field[];
@@ -1 +1 @@
1
- {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/find/traverseFields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAI1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAKlD,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC,OAAO,EAAE,eAAe,CAAA;IACxB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,gBAAgB,EAAE,MAAM,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACrC,iBAAiB,EAAE,MAAM,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,cAAc,gHAUxB,iBAAiB,4BAmKnB,CAAA"}
1
+ {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/find/traverseFields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAKpC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAEpD,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,eAAe,CAAA;IACxB,WAAW,EAAE,MAAM,CAAA;IACnB,gBAAgB,EAAE,MAAM,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACrC,iBAAiB,EAAE,MAAM,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,cAAc,gHAUxB,iBAAiB,4BA8KnB,CAAA"}
@@ -1,7 +1,15 @@
1
- /* eslint-disable no-param-reassign */ import { fieldAffectsData, tabHasName } from 'payload/types';
2
- import { getTableName } from '../schema/getTableName.js';
1
+ /* eslint-disable no-param-reassign */ import { fieldAffectsData, tabHasName } from 'payload/shared';
2
+ import toSnakeCase from 'to-snake-case';
3
3
  export const traverseFields = ({ _locales, adapter, currentArgs, currentTableName, depth, fields, path, topLevelArgs, topLevelTableName })=>{
4
4
  fields.forEach((field)=>{
5
+ // handle simple relationship
6
+ if (depth > 0 && (field.type === 'upload' || field.type === 'relationship' && !field.hasMany && typeof field.relationTo === 'string')) {
7
+ if (field.localized) {
8
+ _locales.with[`${path}${field.name}`] = true;
9
+ } else {
10
+ currentArgs.with[`${path}${field.name}`] = true;
11
+ }
12
+ }
5
13
  if (field.type === 'collapsible' || field.type === 'row') {
6
14
  traverseFields({
7
15
  _locales,
@@ -46,23 +54,20 @@ export const traverseFields = ({ _locales, adapter, currentArgs, currentTableNam
46
54
  ],
47
55
  with: {}
48
56
  };
49
- const arrayTableName = getTableName({
50
- adapter,
51
- config: field,
52
- parentTableName: currentTableName,
53
- prefix: `${currentTableName}_${path}`
54
- });
55
- const arrayTableNameWithLocales = getTableName({
56
- adapter,
57
- config: field,
58
- locales: true,
59
- parentTableName: currentTableName,
60
- prefix: `${currentTableName}_${path}`
61
- });
62
- if (adapter.tables[arrayTableNameWithLocales]) withArray.with._locales = _locales;
57
+ const arrayTableName = adapter.tableNameMap.get(`${currentTableName}_${path}${toSnakeCase(field.name)}`);
58
+ const arrayTableNameWithLocales = `${arrayTableName}${adapter.localesSuffix}`;
59
+ if (adapter.tables[arrayTableNameWithLocales]) {
60
+ withArray.with._locales = {
61
+ columns: {
62
+ id: false,
63
+ _parentID: false
64
+ },
65
+ with: {}
66
+ };
67
+ }
63
68
  currentArgs.with[`${path}${field.name}`] = withArray;
64
69
  traverseFields({
65
- _locales,
70
+ _locales: withArray.with._locales,
66
71
  adapter,
67
72
  currentArgs: withArray,
68
73
  currentTableName: arrayTableName,
@@ -104,18 +109,15 @@ export const traverseFields = ({ _locales, adapter, currentArgs, currentTableNam
104
109
  ],
105
110
  with: {}
106
111
  };
107
- const tableName = getTableName({
108
- adapter,
109
- config: block,
110
- parentTableName: topLevelTableName,
111
- prefix: `${topLevelTableName}_blocks_`
112
- });
112
+ const tableName = adapter.tableNameMap.get(`${topLevelTableName}_blocks_${toSnakeCase(block.slug)}`);
113
113
  if (adapter.tables[`${tableName}${adapter.localesSuffix}`]) {
114
- withBlock.with._locales = _locales;
114
+ withBlock.with._locales = {
115
+ with: {}
116
+ };
115
117
  }
116
118
  topLevelArgs.with[blockKey] = withBlock;
117
119
  traverseFields({
118
- _locales,
120
+ _locales: withBlock.with._locales,
119
121
  adapter,
120
122
  currentArgs: withBlock,
121
123
  currentTableName: tableName,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/find/traverseFields.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Field } from 'payload/types'\n\nimport { fieldAffectsData, tabHasName } from 'payload/types'\n\nimport type { PostgresAdapter } from '../types.js'\nimport type { Result } from './buildFindManyArgs.js'\n\nimport { getTableName } from '../schema/getTableName.js'\n\ntype TraverseFieldArgs = {\n _locales: Record<string, unknown>\n adapter: PostgresAdapter\n currentArgs: Record<string, unknown>\n currentTableName: string\n depth?: number\n fields: Field[]\n path: string\n topLevelArgs: Record<string, unknown>\n topLevelTableName: string\n}\n\nexport const traverseFields = ({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields,\n path,\n topLevelArgs,\n topLevelTableName,\n}: TraverseFieldArgs) => {\n fields.forEach((field) => {\n if (field.type === 'collapsible' || field.type === 'row') {\n traverseFields({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields: field.fields,\n path,\n topLevelArgs,\n topLevelTableName,\n })\n\n return\n }\n\n if (field.type === 'tabs') {\n field.tabs.forEach((tab) => {\n const tabPath = tabHasName(tab) ? `${path}${tab.name}_` : path\n\n traverseFields({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields: tab.fields,\n path: tabPath,\n topLevelArgs,\n topLevelTableName,\n })\n })\n\n return\n }\n\n if (fieldAffectsData(field)) {\n switch (field.type) {\n case 'array': {\n const withArray: Result = {\n columns: {\n _parentID: false,\n },\n orderBy: ({ _order }, { asc }) => [asc(_order)],\n with: {},\n }\n\n const arrayTableName = getTableName({\n adapter,\n config: field,\n parentTableName: currentTableName,\n prefix: `${currentTableName}_${path}`,\n })\n\n const arrayTableNameWithLocales = getTableName({\n adapter,\n config: field,\n locales: true,\n parentTableName: currentTableName,\n prefix: `${currentTableName}_${path}`,\n })\n\n if (adapter.tables[arrayTableNameWithLocales]) withArray.with._locales = _locales\n currentArgs.with[`${path}${field.name}`] = withArray\n\n traverseFields({\n _locales,\n adapter,\n currentArgs: withArray,\n currentTableName: arrayTableName,\n depth,\n fields: field.fields,\n path: '',\n topLevelArgs,\n topLevelTableName,\n })\n\n break\n }\n\n case 'select': {\n if (field.hasMany) {\n const withSelect: Result = {\n columns: {\n id: false,\n order: false,\n parent: false,\n },\n orderBy: ({ order }, { asc }) => [asc(order)],\n }\n\n currentArgs.with[`${path}${field.name}`] = withSelect\n }\n\n break\n }\n\n case 'blocks':\n field.blocks.forEach((block) => {\n const blockKey = `_blocks_${block.slug}`\n\n if (!topLevelArgs[blockKey]) {\n const withBlock: Result = {\n columns: {\n _parentID: false,\n },\n orderBy: ({ _order }, { asc }) => [asc(_order)],\n with: {},\n }\n\n const tableName = getTableName({\n adapter,\n config: block,\n parentTableName: topLevelTableName,\n prefix: `${topLevelTableName}_blocks_`,\n })\n\n if (adapter.tables[`${tableName}${adapter.localesSuffix}`]) {\n withBlock.with._locales = _locales\n }\n topLevelArgs.with[blockKey] = withBlock\n\n traverseFields({\n _locales,\n adapter,\n currentArgs: withBlock,\n currentTableName: tableName,\n depth,\n fields: block.fields,\n path: '',\n topLevelArgs,\n topLevelTableName,\n })\n }\n })\n\n break\n\n case 'group':\n traverseFields({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields: field.fields,\n path: `${path}${field.name}_`,\n topLevelArgs,\n topLevelTableName,\n })\n\n break\n\n default: {\n break\n }\n }\n }\n })\n\n return topLevelArgs\n}\n"],"names":["fieldAffectsData","tabHasName","getTableName","traverseFields","_locales","adapter","currentArgs","currentTableName","depth","fields","path","topLevelArgs","topLevelTableName","forEach","field","type","tabs","tab","tabPath","name","withArray","columns","_parentID","orderBy","_order","asc","with","arrayTableName","config","parentTableName","prefix","arrayTableNameWithLocales","locales","tables","hasMany","withSelect","id","order","parent","blocks","block","blockKey","slug","withBlock","tableName","localesSuffix"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAGpC,SAASA,gBAAgB,EAAEC,UAAU,QAAQ,gBAAe;AAK5D,SAASC,YAAY,QAAQ,4BAA2B;AAcxD,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,QAAQ,EACRC,OAAO,EACPC,WAAW,EACXC,gBAAgB,EAChBC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,YAAY,EACZC,iBAAiB,EACC;IAClBH,OAAOI,OAAO,CAAC,CAACC;QACd,IAAIA,MAAMC,IAAI,KAAK,iBAAiBD,MAAMC,IAAI,KAAK,OAAO;YACxDZ,eAAe;gBACbC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,QAAQK,MAAML,MAAM;gBACpBC;gBACAC;gBACAC;YACF;YAEA;QACF;QAEA,IAAIE,MAAMC,IAAI,KAAK,QAAQ;YACzBD,MAAME,IAAI,CAACH,OAAO,CAAC,CAACI;gBAClB,MAAMC,UAAUjB,WAAWgB,OAAO,CAAC,EAAEP,KAAK,EAAEO,IAAIE,IAAI,CAAC,CAAC,CAAC,GAAGT;gBAE1DP,eAAe;oBACbC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC,QAAQQ,IAAIR,MAAM;oBAClBC,MAAMQ;oBACNP;oBACAC;gBACF;YACF;YAEA;QACF;QAEA,IAAIZ,iBAAiBc,QAAQ;YAC3B,OAAQA,MAAMC,IAAI;gBAChB,KAAK;oBAAS;w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wBACpB,MAAMC,WAAW,CAAC,QAAQ,EAAED,MAAME,IAAI,CAAC,CAAC;wBAExC,IAAI,CAAC/B,YAAY,CAAC8B,SAAS,EAAE;4BAC3B,MAAME,YAAoB;gCACxBtB,SAAS;oCACPC,WAAW;gCACb;gCACAC,SAAS,CAAC,EAAEC,MAAM,EAAE,EAAE,EAAEC,GAAG,EAAE,GAAK;wCAACA,IAAID;qCAAQ;gCAC/CE,MAAM,CAAC;4BACT;4BAEA,MAAMkB,YAAY1C,aAAa;gCAC7BG;gCACAuB,QAAQY;gCACRX,iBAAiBjB;gCACjBkB,QAAQ,CAAC,EAAElB,kBAAkB,QAAQ,CAAC;4BACxC;4BAEA,IAAIP,QAAQ4B,MAAM,CAAC,CAAC,EAAEW,UAAU,EAAEvC,QAAQwC,aAAa,CAAC,CAAC,CAAC,EAAE;gCAC1DF,UAAUjB,IAAI,CAACtB,QAAQ,GAAGA;4BAC5B;4BACAO,aAAae,IAAI,CAACe,SAAS,GAAGE;4BAE9BxC,eAAe;gCACbC;gCACAC;gCACAC,aAAaqC;gCACbpC,kBAAkBqC;gCAClBpC;gCACAC,QAAQ+B,MAAM/B,MAAM;gCACpBC,MAAM;gCACNC;gCACAC;4BACF;wBACF;oBACF;oBAEA;gBAEF,KAAK;oBACHT,eAAe;wBACbC;wBACAC;wBACAC;wBACAC;wBACAC;wBACAC,QAAQK,MAAML,MAAM;wBACpBC,MAAM,CAAC,EAAEA,KAAK,EAAEI,MAAMK,IAAI,CAAC,CAAC,CAAC;wBAC7BR;wBACAC;oBACF;oBAEA;gBAEF;oBAAS;wBACP;oBACF;YACF;QACF;IACF;IAEA,OAAOD;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/find/traverseFields.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Field } from 'payload'\n\nimport { fieldAffectsData, tabHasName } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../types.js'\nimport type { Result } from './buildFindManyArgs.js'\n\ntype TraverseFieldArgs = {\n _locales: Result\n adapter: PostgresAdapter\n currentArgs: Result\n currentTableName: string\n depth?: number\n fields: Field[]\n path: string\n topLevelArgs: Record<string, unknown>\n topLevelTableName: string\n}\n\nexport const traverseFields = ({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields,\n path,\n topLevelArgs,\n topLevelTableName,\n}: TraverseFieldArgs) => {\n fields.forEach((field) => {\n // handle simple relationship\n if (\n depth > 0 &&\n (field.type === 'upload' ||\n (field.type === 'relationship' && !field.hasMany && typeof field.relationTo === 'string'))\n ) {\n if (field.localized) {\n _locales.with[`${path}${field.name}`] = true\n } else {\n currentArgs.with[`${path}${field.name}`] = true\n }\n }\n\n if (field.type === 'collapsible' || field.type === 'row') {\n traverseFields({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields: field.fields,\n path,\n topLevelArgs,\n topLevelTableName,\n })\n\n return\n }\n\n if (field.type === 'tabs') {\n field.tabs.forEach((tab) => {\n const tabPath = tabHasName(tab) ? `${path}${tab.name}_` : path\n\n traverseFields({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields: tab.fields,\n path: tabPath,\n topLevelArgs,\n topLevelTableName,\n })\n })\n\n return\n }\n\n if (fieldAffectsData(field)) {\n switch (field.type) {\n case 'array': {\n const withArray: Result = {\n columns: {\n _parentID: false,\n },\n orderBy: ({ _order }, { asc }) => [asc(_order)],\n with: {},\n }\n\n const arrayTableName = adapter.tableNameMap.get(\n `${currentTableName}_${path}${toSnakeCase(field.name)}`,\n )\n\n const arrayTableNameWithLocales = `${arrayTableName}${adapter.localesSuffix}`\n\n if (adapter.tables[arrayTableNameWithLocales]) {\n withArray.with._locales = {\n columns: {\n id: false,\n _parentID: false,\n },\n with: {},\n }\n }\n currentArgs.with[`${path}${field.name}`] = withArray\n\n traverseFields({\n _locales: withArray.with._locales,\n adapter,\n currentArgs: withArray,\n currentTableName: arrayTableName,\n depth,\n fields: field.fields,\n path: '',\n topLevelArgs,\n topLevelTableName,\n })\n\n break\n }\n\n case 'select': {\n if (field.hasMany) {\n const withSelect: Result = {\n columns: {\n id: false,\n order: false,\n parent: false,\n },\n orderBy: ({ order }, { asc }) => [asc(order)],\n }\n\n currentArgs.with[`${path}${field.name}`] = withSelect\n }\n\n break\n }\n\n case 'blocks':\n field.blocks.forEach((block) => {\n const blockKey = `_blocks_${block.slug}`\n\n if (!topLevelArgs[blockKey]) {\n const withBlock: Result = {\n columns: {\n _parentID: false,\n },\n orderBy: ({ _order }, { asc }) => [asc(_order)],\n with: {},\n }\n\n const tableName = adapter.tableNameMap.get(\n `${topLevelTableName}_blocks_${toSnakeCase(block.slug)}`,\n )\n\n if (adapter.tables[`${tableName}${adapter.localesSuffix}`]) {\n withBlock.with._locales = {\n with: {},\n }\n }\n topLevelArgs.with[blockKey] = withBlock\n\n traverseFields({\n _locales: withBlock.with._locales,\n adapter,\n currentArgs: withBlock,\n currentTableName: tableName,\n depth,\n fields: block.fields,\n path: '',\n topLevelArgs,\n topLevelTableName,\n })\n }\n })\n\n break\n\n case 'group':\n traverseFields({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields: field.fields,\n path: `${path}${field.name}_`,\n topLevelArgs,\n topLevelTableName,\n })\n\n break\n\n default: {\n break\n }\n }\n }\n })\n\n return topLevelArgs\n}\n"],"names":["fieldAffectsData","tabHasName","toSnakeCase","traverseFields","_locales","adapter","currentArgs","currentTableName","depth","fields","path","topLevelArgs","topLevelTableName","forEach","field","type","hasMany","relationTo","localized","with","name","tabs","tab","tabPath","withArray","columns","_parentID","orderBy","_order","asc","arrayTableName","tableNameMap","get","arrayTableNameWithLocales","localesSuffix","tables","id","withSelect","order","parent","blocks","block","blockKey","slug","withBlock","tableName"],"mappings":"AAAA,oCAAoC,GAGpC,SAASA,gBAAgB,EAAEC,UAAU,QAAQ,iBAAgB;AAC7D,OAAOC,iBAAiB,gBAAe;AAiBvC,OAAO,MAAMC,iBAAiB,C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