@payloadcms/db-postgres 3.0.0-canary.ee6d727 → 3.0.0-canary.f118ee4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (357) 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 +10 -6
  5. package/dist/connect.js.map +1 -1
  6. package/dist/exports/migration-utils.js.map +1 -1
  7. package/dist/index.d.ts +1 -2
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +31 -67
  10. package/dist/index.js.map +1 -1
  11. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -1
  12. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +5 -5
  13. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
  14. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +1 -2
  15. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
  16. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +1 -1
  17. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -1
  18. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +1 -1
  19. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -1
  20. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -1
  21. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -1
  22. package/dist/predefinedMigrations/v2-v3/index.d.ts +2 -3
  23. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -1
  24. package/dist/predefinedMigrations/v2-v3/index.js +7 -7
  25. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -1
  26. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +5 -4
  27. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -1
  28. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -1
  29. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +4 -4
  30. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -1
  31. package/dist/predefinedMigrations/v2-v3/traverseFields.js +1 -1
  32. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -1
  33. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -1
  34. package/dist/types.d.ts +42 -80
  35. package/dist/types.d.ts.map +1 -1
  36. package/dist/types.js.map +1 -1
  37. package/package.json +20 -17
  38. package/dist/count.d.ts +0 -3
  39. package/dist/count.d.ts.map +0 -1
  40. package/dist/count.js +0 -41
  41. package/dist/count.js.map +0 -1
  42. package/dist/create.d.ts +0 -3
  43. package/dist/create.d.ts.map +0 -1
  44. package/dist/create.js +0 -19
  45. package/dist/create.js.map +0 -1
  46. package/dist/createGlobal.d.ts +0 -5
  47. package/dist/createGlobal.d.ts.map +0 -1
  48. package/dist/createGlobal.js +0 -19
  49. package/dist/createGlobal.js.map +0 -1
  50. package/dist/createGlobalVersion.d.ts +0 -6
  51. package/dist/createGlobalVersion.d.ts.map +0 -1
  52. package/dist/createGlobalVersion.js +0 -33
  53. package/dist/createGlobalVersion.js.map +0 -1
  54. package/dist/createMigration.d.ts +0 -3
  55. package/dist/createMigration.d.ts.map +0 -1
  56. package/dist/createMigration.js +0 -102
  57. package/dist/createMigration.js.map +0 -1
  58. package/dist/createVersion.d.ts +0 -5
  59. package/dist/createVersion.d.ts.map +0 -1
  60. package/dist/createVersion.js +0 -40
  61. package/dist/createVersion.js.map +0 -1
  62. package/dist/deleteMany.d.ts +0 -3
  63. package/dist/deleteMany.d.ts.map +0 -1
  64. package/dist/deleteMany.js +0 -28
  65. package/dist/deleteMany.js.map +0 -1
  66. package/dist/deleteOne.d.ts +0 -3
  67. package/dist/deleteOne.d.ts.map +0 -1
  68. package/dist/deleteOne.js +0 -59
  69. package/dist/deleteOne.js.map +0 -1
  70. package/dist/deleteVersions.d.ts +0 -3
  71. package/dist/deleteVersions.d.ts.map +0 -1
  72. package/dist/deleteVersions.js +0 -31
  73. package/dist/deleteVersions.js.map +0 -1
  74. package/dist/destroy.d.ts +0 -3
  75. package/dist/destroy.d.ts.map +0 -1
  76. package/dist/destroy.js +0 -15
  77. package/dist/destroy.js.map +0 -1
  78. package/dist/find/buildFindManyArgs.d.ts +0 -17
  79. package/dist/find/buildFindManyArgs.d.ts.map +0 -1
  80. package/dist/find/buildFindManyArgs.js +0 -65
  81. package/dist/find/buildFindManyArgs.js.map +0 -1
  82. package/dist/find/chainMethods.d.ts +0 -16
  83. package/dist/find/chainMethods.d.ts.map +0 -1
  84. package/dist/find/chainMethods.js +0 -12
  85. package/dist/find/chainMethods.js.map +0 -1
  86. package/dist/find/findMany.d.ts +0 -22
  87. package/dist/find/findMany.d.ts.map +0 -1
  88. package/dist/find/findMany.js +0 -152
  89. package/dist/find/findMany.js.map +0 -1
  90. package/dist/find/traverseFields.d.ts +0 -17
  91. package/dist/find/traverseFields.d.ts.map +0 -1
  92. package/dist/find/traverseFields.js +0 -156
  93. package/dist/find/traverseFields.js.map +0 -1
  94. package/dist/find.d.ts +0 -3
  95. package/dist/find.d.ts.map +0 -1
  96. package/dist/find.js +0 -21
  97. package/dist/find.js.map +0 -1
  98. package/dist/findGlobal.d.ts +0 -3
  99. package/dist/findGlobal.d.ts.map +0 -1
  100. package/dist/findGlobal.js +0 -23
  101. package/dist/findGlobal.js.map +0 -1
  102. package/dist/findGlobalVersions.d.ts +0 -3
  103. package/dist/findGlobalVersions.d.ts.map +0 -1
  104. package/dist/findGlobalVersions.js +0 -24
  105. package/dist/findGlobalVersions.js.map +0 -1
  106. package/dist/findOne.d.ts +0 -5
  107. package/dist/findOne.d.ts.map +0 -1
  108. package/dist/findOne.js +0 -21
  109. package/dist/findOne.js.map +0 -1
  110. package/dist/findVersions.d.ts +0 -3
  111. package/dist/findVersions.d.ts.map +0 -1
  112. package/dist/findVersions.js +0 -24
  113. package/dist/findVersions.js.map +0 -1
  114. package/dist/init.d.ts +0 -3
  115. package/dist/init.d.ts.map +0 -1
  116. package/dist/init.js +0 -91
  117. package/dist/init.js.map +0 -1
  118. package/dist/migrate.d.ts +0 -3
  119. package/dist/migrate.d.ts.map +0 -1
  120. package/dist/migrate.js +0 -99
  121. package/dist/migrate.js.map +0 -1
  122. package/dist/migrateDown.d.ts +0 -3
  123. package/dist/migrateDown.d.ts.map +0 -1
  124. package/dist/migrateDown.js +0 -63
  125. package/dist/migrateDown.js.map +0 -1
  126. package/dist/migrateFresh.d.ts +0 -8
  127. package/dist/migrateFresh.d.ts.map +0 -1
  128. package/dist/migrateFresh.js +0 -72
  129. package/dist/migrateFresh.js.map +0 -1
  130. package/dist/migrateRefresh.d.ts +0 -6
  131. package/dist/migrateRefresh.d.ts.map +0 -1
  132. package/dist/migrateRefresh.js +0 -102
  133. package/dist/migrateRefresh.js.map +0 -1
  134. package/dist/migrateReset.d.ts +0 -6
  135. package/dist/migrateReset.d.ts.map +0 -1
  136. package/dist/migrateReset.js +0 -82
  137. package/dist/migrateReset.js.map +0 -1
  138. package/dist/migrateStatus.d.ts +0 -3
  139. package/dist/migrateStatus.d.ts.map +0 -1
  140. package/dist/migrateStatus.js +0 -44
  141. package/dist/migrateStatus.js.map +0 -1
  142. package/dist/queries/buildAndOrConditions.d.ts +0 -16
  143. package/dist/queries/buildAndOrConditions.d.ts.map +0 -1
  144. package/dist/queries/buildAndOrConditions.js +0 -28
  145. package/dist/queries/buildAndOrConditions.js.map +0 -1
  146. package/dist/queries/buildQuery.d.ts +0 -30
  147. package/dist/queries/buildQuery.d.ts.map +0 -1
  148. package/dist/queries/buildQuery.js +0 -72
  149. package/dist/queries/buildQuery.js.map +0 -1
  150. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.d.ts +0 -2
  151. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.d.ts.map +0 -1
  152. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js +0 -14
  153. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +0 -1
  154. package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts +0 -2
  155. package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts.map +0 -1
  156. package/dist/queries/createJSONQuery/formatJSONPathSegment.js +0 -5
  157. package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +0 -1
  158. package/dist/queries/createJSONQuery/index.d.ts +0 -10
  159. package/dist/queries/createJSONQuery/index.d.ts.map +0 -1
  160. package/dist/queries/createJSONQuery/index.js +0 -54
  161. package/dist/queries/createJSONQuery/index.js.map +0 -1
  162. package/dist/queries/getTableColumnFromPath.d.ts +0 -50
  163. package/dist/queries/getTableColumnFromPath.d.ts.map +0 -1
  164. package/dist/queries/getTableColumnFromPath.js +0 -517
  165. package/dist/queries/getTableColumnFromPath.js.map +0 -1
  166. package/dist/queries/operatorMap.d.ts +0 -18
  167. package/dist/queries/operatorMap.d.ts.map +0 -1
  168. package/dist/queries/operatorMap.js +0 -24
  169. package/dist/queries/operatorMap.js.map +0 -1
  170. package/dist/queries/parseParams.d.ts +0 -16
  171. package/dist/queries/parseParams.d.ts.map +0 -1
  172. package/dist/queries/parseParams.js +0 -183
  173. package/dist/queries/parseParams.js.map +0 -1
  174. package/dist/queries/sanitizeQueryValue.d.ts +0 -15
  175. package/dist/queries/sanitizeQueryValue.d.ts.map +0 -1
  176. package/dist/queries/sanitizeQueryValue.js +0 -90
  177. package/dist/queries/sanitizeQueryValue.js.map +0 -1
  178. package/dist/queries/selectDistinct.d.ts +0 -22
  179. package/dist/queries/selectDistinct.d.ts.map +0 -1
  180. package/dist/queries/selectDistinct.js +0 -30
  181. package/dist/queries/selectDistinct.js.map +0 -1
  182. package/dist/queryDrafts.d.ts +0 -3
  183. package/dist/queryDrafts.d.ts.map +0 -1
  184. package/dist/queryDrafts.js +0 -41
  185. package/dist/queryDrafts.js.map +0 -1
  186. package/dist/schema/build.d.ts +0 -34
  187. package/dist/schema/build.d.ts.map +0 -1
  188. package/dist/schema/build.js +0 -369
  189. package/dist/schema/build.js.map +0 -1
  190. package/dist/schema/createIndex.d.ts +0 -12
  191. package/dist/schema/createIndex.d.ts.map +0 -1
  192. package/dist/schema/createIndex.js +0 -18
  193. package/dist/schema/createIndex.js.map +0 -1
  194. package/dist/schema/createTableName.d.ts +0 -30
  195. package/dist/schema/createTableName.d.ts.map +0 -1
  196. package/dist/schema/createTableName.js +0 -31
  197. package/dist/schema/createTableName.js.map +0 -1
  198. package/dist/schema/idToUUID.d.ts +0 -3
  199. package/dist/schema/idToUUID.d.ts.map +0 -1
  200. package/dist/schema/idToUUID.js +0 -11
  201. package/dist/schema/idToUUID.js.map +0 -1
  202. package/dist/schema/parentIDColumnMap.d.ts +0 -4
  203. package/dist/schema/parentIDColumnMap.d.ts.map +0 -1
  204. package/dist/schema/parentIDColumnMap.js +0 -9
  205. package/dist/schema/parentIDColumnMap.js.map +0 -1
  206. package/dist/schema/setColumnID.d.ts +0 -11
  207. package/dist/schema/setColumnID.d.ts.map +0 -1
  208. package/dist/schema/setColumnID.js +0 -24
  209. package/dist/schema/setColumnID.js.map +0 -1
  210. package/dist/schema/traverseFields.d.ts +0 -36
  211. package/dist/schema/traverseFields.d.ts.map +0 -1
  212. package/dist/schema/traverseFields.js +0 -614
  213. package/dist/schema/traverseFields.js.map +0 -1
  214. package/dist/schema/validateExistingBlockIsIdentical.d.ts +0 -12
  215. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +0 -1
  216. package/dist/schema/validateExistingBlockIsIdentical.js +0 -76
  217. package/dist/schema/validateExistingBlockIsIdentical.js.map +0 -1
  218. package/dist/transactions/beginTransaction.d.ts +0 -3
  219. package/dist/transactions/beginTransaction.d.ts.map +0 -1
  220. package/dist/transactions/beginTransaction.js +0 -51
  221. package/dist/transactions/beginTransaction.js.map +0 -1
  222. package/dist/transactions/commitTransaction.d.ts +0 -3
  223. package/dist/transactions/commitTransaction.d.ts.map +0 -1
  224. package/dist/transactions/commitTransaction.js +0 -14
  225. package/dist/transactions/commitTransaction.js.map +0 -1
  226. package/dist/transactions/rollbackTransaction.d.ts +0 -3
  227. package/dist/transactions/rollbackTransaction.d.ts.map +0 -1
  228. package/dist/transactions/rollbackTransaction.js +0 -13
  229. package/dist/transactions/rollbackTransaction.js.map +0 -1
  230. package/dist/transform/read/hasManyNumber.d.ts +0 -10
  231. package/dist/transform/read/hasManyNumber.d.ts.map +0 -1
  232. package/dist/transform/read/hasManyNumber.js +0 -10
  233. package/dist/transform/read/hasManyNumber.js.map +0 -1
  234. package/dist/transform/read/hasManyText.d.ts +0 -10
  235. package/dist/transform/read/hasManyText.d.ts.map +0 -1
  236. package/dist/transform/read/hasManyText.js +0 -10
  237. package/dist/transform/read/hasManyText.js.map +0 -1
  238. package/dist/transform/read/index.d.ts +0 -14
  239. package/dist/transform/read/index.d.ts.map +0 -1
  240. package/dist/transform/read/index.js +0 -44
  241. package/dist/transform/read/index.js.map +0 -1
  242. package/dist/transform/read/relationship.d.ts +0 -10
  243. package/dist/transform/read/relationship.d.ts.map +0 -1
  244. package/dist/transform/read/relationship.js +0 -60
  245. package/dist/transform/read/relationship.js.map +0 -1
  246. package/dist/transform/read/traverseFields.d.ts +0 -57
  247. package/dist/transform/read/traverseFields.d.ts.map +0 -1
  248. package/dist/transform/read/traverseFields.js +0 -435
  249. package/dist/transform/read/traverseFields.js.map +0 -1
  250. package/dist/transform/write/array.d.ts +0 -26
  251. package/dist/transform/write/array.d.ts.map +0 -1
  252. package/dist/transform/write/array.js +0 -58
  253. package/dist/transform/write/array.js.map +0 -1
  254. package/dist/transform/write/blocks.d.ts +0 -25
  255. package/dist/transform/write/blocks.d.ts.map +0 -1
  256. package/dist/transform/write/blocks.js +0 -54
  257. package/dist/transform/write/blocks.js.map +0 -1
  258. package/dist/transform/write/index.d.ts +0 -13
  259. package/dist/transform/write/index.d.ts.map +0 -1
  260. package/dist/transform/write/index.js +0 -41
  261. package/dist/transform/write/index.js.map +0 -1
  262. package/dist/transform/write/numbers.d.ts +0 -8
  263. package/dist/transform/write/numbers.d.ts.map +0 -1
  264. package/dist/transform/write/numbers.js +0 -11
  265. package/dist/transform/write/numbers.js.map +0 -1
  266. package/dist/transform/write/relationships.d.ts +0 -10
  267. package/dist/transform/write/relationships.d.ts.map +0 -1
  268. package/dist/transform/write/relationships.js +0 -23
  269. package/dist/transform/write/relationships.js.map +0 -1
  270. package/dist/transform/write/selects.d.ts +0 -8
  271. package/dist/transform/write/selects.d.ts.map +0 -1
  272. package/dist/transform/write/selects.js +0 -20
  273. package/dist/transform/write/selects.js.map +0 -1
  274. package/dist/transform/write/texts.d.ts +0 -8
  275. package/dist/transform/write/texts.d.ts.map +0 -1
  276. package/dist/transform/write/texts.js +0 -11
  277. package/dist/transform/write/texts.js.map +0 -1
  278. package/dist/transform/write/traverseFields.d.ts +0 -50
  279. package/dist/transform/write/traverseFields.d.ts.map +0 -1
  280. package/dist/transform/write/traverseFields.js +0 -445
  281. package/dist/transform/write/traverseFields.js.map +0 -1
  282. package/dist/transform/write/types.d.ts +0 -43
  283. package/dist/transform/write/types.d.ts.map +0 -1
  284. package/dist/transform/write/types.js +0 -3
  285. package/dist/transform/write/types.js.map +0 -1
  286. package/dist/update.d.ts +0 -3
  287. package/dist/update.d.ts.map +0 -1
  288. package/dist/update.js +0 -54
  289. package/dist/update.js.map +0 -1
  290. package/dist/updateGlobal.d.ts +0 -5
  291. package/dist/updateGlobal.d.ts.map +0 -1
  292. package/dist/updateGlobal.js +0 -25
  293. package/dist/updateGlobal.js.map +0 -1
  294. package/dist/updateGlobalVersion.d.ts +0 -5
  295. package/dist/updateGlobalVersion.d.ts.map +0 -1
  296. package/dist/updateGlobalVersion.js +0 -36
  297. package/dist/updateGlobalVersion.js.map +0 -1
  298. package/dist/updateVersion.d.ts +0 -5
  299. package/dist/updateVersion.d.ts.map +0 -1
  300. package/dist/updateVersion.js +0 -36
  301. package/dist/updateVersion.js.map +0 -1
  302. package/dist/upsertRow/deleteExistingArrayRows.d.ts +0 -10
  303. package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +0 -1
  304. package/dist/upsertRow/deleteExistingArrayRows.js +0 -10
  305. package/dist/upsertRow/deleteExistingArrayRows.js.map +0 -1
  306. package/dist/upsertRow/deleteExistingRowsByPath.d.ts +0 -14
  307. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +0 -1
  308. package/dist/upsertRow/deleteExistingRowsByPath.js +0 -33
  309. package/dist/upsertRow/deleteExistingRowsByPath.js.map +0 -1
  310. package/dist/upsertRow/index.d.ts +0 -4
  311. package/dist/upsertRow/index.d.ts.map +0 -1
  312. package/dist/upsertRow/index.js +0 -279
  313. package/dist/upsertRow/index.js.map +0 -1
  314. package/dist/upsertRow/insertArrays.d.ts +0 -13
  315. package/dist/upsertRow/insertArrays.d.ts.map +0 -1
  316. package/dist/upsertRow/insertArrays.js +0 -68
  317. package/dist/upsertRow/insertArrays.js.map +0 -1
  318. package/dist/upsertRow/types.d.ts +0 -32
  319. package/dist/upsertRow/types.d.ts.map +0 -1
  320. package/dist/upsertRow/types.js +0 -3
  321. package/dist/upsertRow/types.js.map +0 -1
  322. package/dist/utilities/appendPrefixToKeys.d.ts +0 -2
  323. package/dist/utilities/appendPrefixToKeys.d.ts.map +0 -1
  324. package/dist/utilities/appendPrefixToKeys.js +0 -6
  325. package/dist/utilities/appendPrefixToKeys.js.map +0 -1
  326. package/dist/utilities/createBlocksMap.d.ts +0 -5
  327. package/dist/utilities/createBlocksMap.d.ts.map +0 -1
  328. package/dist/utilities/createBlocksMap.js +0 -29
  329. package/dist/utilities/createBlocksMap.js.map +0 -1
  330. package/dist/utilities/createMigrationTable.d.ts +0 -3
  331. package/dist/utilities/createMigrationTable.d.ts.map +0 -1
  332. package/dist/utilities/createMigrationTable.js +0 -13
  333. package/dist/utilities/createMigrationTable.js.map +0 -1
  334. package/dist/utilities/createRelationshipMap.d.ts +0 -2
  335. package/dist/utilities/createRelationshipMap.d.ts.map +0 -1
  336. package/dist/utilities/createRelationshipMap.js +0 -19
  337. package/dist/utilities/createRelationshipMap.js.map +0 -1
  338. package/dist/utilities/hasLocalesTable.d.ts +0 -3
  339. package/dist/utilities/hasLocalesTable.d.ts.map +0 -1
  340. package/dist/utilities/hasLocalesTable.js +0 -11
  341. package/dist/utilities/hasLocalesTable.js.map +0 -1
  342. package/dist/utilities/isArrayOfRows.d.ts +0 -2
  343. package/dist/utilities/isArrayOfRows.d.ts.map +0 -1
  344. package/dist/utilities/isArrayOfRows.js +0 -5
  345. package/dist/utilities/isArrayOfRows.js.map +0 -1
  346. package/dist/utilities/migrationTableExists.d.ts +0 -3
  347. package/dist/utilities/migrationTableExists.d.ts.map +0 -1
  348. package/dist/utilities/migrationTableExists.js +0 -9
  349. package/dist/utilities/migrationTableExists.js.map +0 -1
  350. package/dist/utilities/parseError.d.ts +0 -5
  351. package/dist/utilities/parseError.d.ts.map +0 -1
  352. package/dist/utilities/parseError.js +0 -17
  353. package/dist/utilities/parseError.js.map +0 -1
  354. package/dist/utilities/pushDevSchema.d.ts +0 -9
  355. package/dist/utilities/pushDevSchema.d.ts.map +0 -1
  356. package/dist/utilities/pushDevSchema.js +0 -58
  357. package/dist/utilities/pushDevSchema.js.map +0 -1
@@ -1,614 +0,0 @@
1
- /* eslint-disable no-param-reassign */ import { relations } from 'drizzle-orm';
2
- import { PgNumericBuilder, PgUUIDBuilder, PgVarcharBuilder, boolean, foreignKey, index, integer, jsonb, numeric, pgEnum, text, timestamp, varchar } from 'drizzle-orm/pg-core';
3
- import { InvalidConfiguration } from 'payload/errors';
4
- import { fieldAffectsData, optionIsObject } from 'payload/types';
5
- import toSnakeCase from 'to-snake-case';
6
- import { hasLocalesTable } from '../utilities/hasLocalesTable.js';
7
- import { buildTable } from './build.js';
8
- import { createIndex } from './createIndex.js';
9
- import { createTableName } from './createTableName.js';
10
- import { idToUUID } from './idToUUID.js';
11
- import { parentIDColumnMap } from './parentIDColumnMap.js';
12
- import { validateExistingBlockIsIdentical } from './validateExistingBlockIsIdentical.js';
13
- export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull, disableUnique = false, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName, relationsToBuild, relationships, rootRelationsToBuild, rootTableIDColType, rootTableName, versions })=>{
14
- const throwValidationError = true;
15
- let hasLocalizedField = false;
16
- let hasLocalizedRelationshipField = false;
17
- let hasManyTextField = false;
18
- let hasLocalizedManyTextField = false;
19
- let hasManyNumberField = false;
20
- let hasLocalizedManyNumberField = false;
21
- let parentIDColType = 'integer';
22
- if (columns.id instanceof PgUUIDBuilder) parentIDColType = 'uuid';
23
- if (columns.id instanceof PgNumericBuilder) parentIDColType = 'numeric';
24
- if (columns.id instanceof PgVarcharBuilder) parentIDColType = 'varchar';
25
- fields.forEach((field)=>{
26
- if ('name' in field && field.name === 'id') return;
27
- let columnName;
28
- let fieldName;
29
- let targetTable = columns;
30
- let targetIndexes = indexes;
31
- if (fieldAffectsData(field)) {
32
- columnName = `${columnPrefix || ''}${field.name[0] === '_' ? '_' : ''}${toSnakeCase(field.name)}`;
33
- fieldName = `${fieldPrefix?.replace('.', '_') || ''}${field.name}`;
34
- // If field is localized,
35
- // add the column to the locale table instead of main table
36
- if (adapter.payload.config.localization && (field.localized || forceLocalized) && field.type !== 'array' && field.type !== 'blocks' && ('hasMany' in field && field.hasMany !== true || !('hasMany' in field))) {
37
- hasLocalizedField = true;
38
- targetTable = localesColumns;
39
- targetIndexes = localesIndexes;
40
- }
41
- if ((field.unique || field.index) && ![
42
- 'array',
43
- 'blocks',
44
- 'group',
45
- 'point',
46
- 'relationship',
47
- 'upload'
48
- ].includes(field.type) && !('hasMany' in field && field.hasMany === true)) {
49
- const unique = disableUnique !== true && field.unique;
50
- if (unique) {
51
- const constraintValue = `${fieldPrefix || ''}${field.name}`;
52
- if (!adapter.fieldConstraints?.[rootTableName]) {
53
- adapter.fieldConstraints[rootTableName] = {};
54
- }
55
- adapter.fieldConstraints[rootTableName][`${columnName}_idx`] = constraintValue;
56
- }
57
- targetIndexes[`${newTableName}_${field.name}Idx`] = createIndex({
58
- name: fieldName,
59
- columnName,
60
- tableName: newTableName,
61
- unique
62
- });
63
- }
64
- }
65
- switch(field.type){
66
- case 'text':
67
- {
68
- if (field.hasMany) {
69
- if (field.localized) {
70
- hasLocalizedManyTextField = true;
71
- }
72
- if (field.index) {
73
- hasManyTextField = 'index';
74
- } else if (!hasManyTextField) {
75
- hasManyTextField = true;
76
- }
77
- if (field.unique) {
78
- throw new InvalidConfiguration('Unique is not supported in Postgres for hasMany text fields.');
79
- }
80
- } else {
81
- targetTable[fieldName] = varchar(columnName);
82
- }
83
- break;
84
- }
85
- case 'email':
86
- case 'code':
87
- case 'textarea':
88
- {
89
- targetTable[fieldName] = varchar(columnName);
90
- break;
91
- }
92
- case 'number':
93
- {
94
- if (field.hasMany) {
95
- if (field.localized) {
96
- hasLocalizedManyNumberField = true;
97
- }
98
- if (field.index) {
99
- hasManyNumberField = 'index';
100
- } else if (!hasManyNumberField) {
101
- hasManyNumberField = true;
102
- }
103
- if (field.unique) {
104
- throw new InvalidConfiguration('Unique is not supported in Postgres for hasMany number fields.');
105
- }
106
- } else {
107
- targetTable[fieldName] = numeric(columnName);
108
- }
109
- break;
110
- }
111
- case 'richText':
112
- case 'json':
113
- {
114
- targetTable[fieldName] = jsonb(columnName);
115
- break;
116
- }
117
- case 'date':
118
- {
119
- targetTable[fieldName] = timestamp(columnName, {
120
- mode: 'string',
121
- precision: 3,
122
- withTimezone: true
123
- });
124
- break;
125
- }
126
- case 'point':
127
- {
128
- break;
129
- }
130
- case 'radio':
131
- case 'select':
132
- {
133
- const enumName = createTableName({
134
- adapter,
135
- config: field,
136
- parentTableName: newTableName,
137
- prefix: `enum_${newTableName}_`,
138
- target: 'enumName',
139
- throwValidationError
140
- });
141
- adapter.enums[enumName] = pgEnum(enumName, field.options.map((option)=>{
142
- if (optionIsObject(option)) {
143
- return option.value;
144
- }
145
- return option;
146
- }));
147
- if (field.type === 'select' && field.hasMany) {
148
- const selectTableName = createTableName({
149
- adapter,
150
- config: field,
151
- parentTableName: newTableName,
152
- prefix: `${newTableName}_`,
153
- throwValidationError,
154
- versionsCustomName: versions
155
- });
156
- const baseColumns = {
157
- order: integer('order').notNull(),
158
- parent: parentIDColumnMap[parentIDColType]('parent_id').notNull(),
159
- value: adapter.enums[enumName]('value')
160
- };
161
- const baseExtraConfig = {
162
- orderIdx: (cols)=>index(`${selectTableName}_order_idx`).on(cols.order),
163
- parentFk: (cols)=>foreignKey({
164
- name: `${selectTableName}_parent_fk`,
165
- columns: [
166
- cols.parent
167
- ],
168
- foreignColumns: [
169
- adapter.tables[parentTableName].id
170
- ]
171
- }).onDelete('cascade'),
172
- parentIdx: (cols)=>index(`${selectTableName}_parent_idx`).on(cols.parent)
173
- };
174
- if (field.localized) {
175
- baseColumns.locale = adapter.enums.enum__locales('locale').notNull();
176
- baseExtraConfig.localeIdx = (cols)=>index(`${selectTableName}_locale_idx`).on(cols.locale);
177
- }
178
- if (field.index) {
179
- baseExtraConfig.value = (cols)=>index(`${selectTableName}_value_idx`).on(cols.value);
180
- }
181
- buildTable({
182
- adapter,
183
- baseColumns,
184
- baseExtraConfig,
185
- disableNotNull,
186
- disableUnique,
187
- fields: [],
188
- rootTableName,
189
- tableName: selectTableName,
190
- versions
191
- });
192
- relationsToBuild.set(fieldName, {
193
- type: 'many',
194
- // selects have their own localized table, independent of the base table.
195
- localized: false,
196
- target: selectTableName
197
- });
198
- adapter.relations[`relations_${selectTableName}`] = relations(adapter.tables[selectTableName], ({ one })=>({
199
- parent: one(adapter.tables[parentTableName], {
200
- fields: [
201
- adapter.tables[selectTableName].parent
202
- ],
203
- references: [
204
- adapter.tables[parentTableName].id
205
- ],
206
- relationName: fieldName
207
- })
208
- }));
209
- } else {
210
- targetTable[fieldName] = adapter.enums[enumName](fieldName);
211
- }
212
- break;
213
- }
214
- case 'checkbox':
215
- {
216
- targetTable[fieldName] = boolean(columnName);
217
- break;
218
- }
219
- case 'array':
220
- {
221
- const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
222
- const arrayTableName = createTableName({
223
- adapter,
224
- config: field,
225
- parentTableName: newTableName,
226
- prefix: `${newTableName}_`,
227
- throwValidationError,
228
- versionsCustomName: versions
229
- });
230
- const baseColumns = {
231
- _order: integer('_order').notNull(),
232
- _parentID: parentIDColumnMap[parentIDColType]('_parent_id').notNull()
233
- };
234
- const baseExtraConfig = {
235
- _orderIdx: (cols)=>index(`${arrayTableName}_order_idx`).on(cols._order),
236
- _parentIDFk: (cols)=>foreignKey({
237
- name: `${arrayTableName}_parent_id_fk`,
238
- columns: [
239
- cols['_parentID']
240
- ],
241
- foreignColumns: [
242
- adapter.tables[parentTableName].id
243
- ]
244
- }).onDelete('cascade'),
245
- _parentIDIdx: (cols)=>index(`${arrayTableName}_parent_id_idx`).on(cols._parentID)
246
- };
247
- if (field.localized && adapter.payload.config.localization) {
248
- baseColumns._locale = adapter.enums.enum__locales('_locale').notNull();
249
- baseExtraConfig._localeIdx = (cols)=>index(`${arrayTableName}_locale_idx`).on(cols._locale);
250
- }
251
- const { hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
252
- adapter,
253
- baseColumns,
254
- baseExtraConfig,
255
- disableNotNull: disableNotNullFromHere,
256
- disableUnique,
257
- fields: disableUnique ? idToUUID(field.fields) : field.fields,
258
- rootRelationsToBuild,
259
- rootRelationships: relationships,
260
- rootTableIDColType,
261
- rootTableName,
262
- tableName: arrayTableName,
263
- versions
264
- });
265
- if (subHasManyTextField) {
266
- if (!hasManyTextField || subHasManyTextField === 'index') hasManyTextField = subHasManyTextField;
267
- }
268
- if (subHasManyNumberField) {
269
- if (!hasManyNumberField || subHasManyNumberField === 'index') hasManyNumberField = subHasManyNumberField;
270
- }
271
- relationsToBuild.set(fieldName, {
272
- type: 'many',
273
- // arrays have their own localized table, independent of the base table.
274
- localized: false,
275
- target: arrayTableName
276
- });
277
- adapter.relations[`relations_${arrayTableName}`] = relations(adapter.tables[arrayTableName], ({ many, one })=>{
278
- const result = {
279
- _parentID: one(adapter.tables[parentTableName], {
280
- fields: [
281
- adapter.tables[arrayTableName]._parentID
282
- ],
283
- references: [
284
- adapter.tables[parentTableName].id
285
- ],
286
- relationName: fieldName
287
- })
288
- };
289
- if (hasLocalesTable(field.fields)) {
290
- result._locales = many(adapter.tables[`${arrayTableName}${adapter.localesSuffix}`], {
291
- relationName: '_locales'
292
- });
293
- }
294
- subRelationsToBuild.forEach(({ type, localized, target }, key)=>{
295
- if (type === 'one') {
296
- const arrayWithLocalized = localized ? `${arrayTableName}${adapter.localesSuffix}` : arrayTableName;
297
- result[key] = one(adapter.tables[target], {
298
- fields: [
299
- adapter.tables[arrayWithLocalized][key]
300
- ],
301
- references: [
302
- adapter.tables[target].id
303
- ],
304
- relationName: key
305
- });
306
- }
307
- if (type === 'many') {
308
- result[key] = many(adapter.tables[target], {
309
- relationName: key
310
- });
311
- }
312
- });
313
- return result;
314
- });
315
- break;
316
- }
317
- case 'blocks':
318
- {
319
- const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
320
- field.blocks.forEach((block)=>{
321
- const blockTableName = createTableName({
322
- adapter,
323
- config: block,
324
- parentTableName: rootTableName,
325
- prefix: `${rootTableName}_blocks_`,
326
- throwValidationError,
327
- versionsCustomName: versions
328
- });
329
- if (!adapter.tables[blockTableName]) {
330
- const baseColumns = {
331
- _order: integer('_order').notNull(),
332
- _parentID: parentIDColumnMap[rootTableIDColType]('_parent_id').notNull(),
333
- _path: text('_path').notNull()
334
- };
335
- const baseExtraConfig = {
336
- _orderIdx: (cols)=>index(`${blockTableName}_order_idx`).on(cols._order),
337
- _parentIDIdx: (cols)=>index(`${blockTableName}_parent_id_idx`).on(cols._parentID),
338
- _parentIdFk: (cols)=>foreignKey({
339
- name: `${blockTableName}_parent_id_fk`,
340
- columns: [
341
- cols._parentID
342
- ],
343
- foreignColumns: [
344
- adapter.tables[rootTableName].id
345
- ]
346
- }).onDelete('cascade'),
347
- _pathIdx: (cols)=>index(`${blockTableName}_path_idx`).on(cols._path)
348
- };
349
- if (field.localized && adapter.payload.config.localization) {
350
- baseColumns._locale = adapter.enums.enum__locales('_locale').notNull();
351
- baseExtraConfig._localeIdx = (cols)=>index(`${blockTableName}_locale_idx`).on(cols._locale);
352
- }
353
- const { hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
354
- adapter,
355
- baseColumns,
356
- baseExtraConfig,
357
- disableNotNull: disableNotNullFromHere,
358
- disableUnique,
359
- fields: disableUnique ? idToUUID(block.fields) : block.fields,
360
- rootRelationsToBuild,
361
- rootRelationships: relationships,
362
- rootTableIDColType,
363
- rootTableName,
364
- tableName: blockTableName,
365
- versions
366
- });
367
- if (subHasManyTextField) {
368
- if (!hasManyTextField || subHasManyTextField === 'index') hasManyTextField = subHasManyTextField;
369
- }
370
- if (subHasManyNumberField) {
371
- if (!hasManyNumberField || subHasManyNumberField === 'index') hasManyNumberField = subHasManyNumberField;
372
- }
373
- adapter.relations[`relations_${blockTableName}`] = relations(adapter.tables[blockTableName], ({ many, one })=>{
374
- const result = {
375
- _parentID: one(adapter.tables[rootTableName], {
376
- fields: [
377
- adapter.tables[blockTableName]._parentID
378
- ],
379
- references: [
380
- adapter.tables[rootTableName].id
381
- ],
382
- relationName: `_blocks_${block.slug}`
383
- })
384
- };
385
- if (hasLocalesTable(block.fields)) {
386
- result._locales = many(adapter.tables[`${blockTableName}${adapter.localesSuffix}`], {
387
- relationName: '_locales'
388
- });
389
- }
390
- subRelationsToBuild.forEach(({ type, localized, target }, key)=>{
391
- if (type === 'one') {
392
- const blockWithLocalized = localized ? `${blockTableName}${adapter.localesSuffix}` : blockTableName;
393
- result[key] = one(adapter.tables[target], {
394
- fields: [
395
- adapter.tables[blockWithLocalized][key]
396
- ],
397
- references: [
398
- adapter.tables[target].id
399
- ],
400
- relationName: key
401
- });
402
- }
403
- if (type === 'many') {
404
- result[key] = many(adapter.tables[target], {
405
- relationName: key
406
- });
407
- }
408
- });
409
- return result;
410
- });
411
- } else if (process.env.NODE_ENV !== 'production' && !versions) {
412
- validateExistingBlockIsIdentical({
413
- block,
414
- localized: field.localized,
415
- rootTableName,
416
- table: adapter.tables[blockTableName],
417
- tableLocales: adapter.tables[`${blockTableName}${adapter.localesSuffix}`]
418
- });
419
- }
420
- // blocks relationships are defined from the collection or globals table down to the block, bypassing any subBlocks
421
- rootRelationsToBuild.set(`_blocks_${block.slug}`, {
422
- type: 'many',
423
- // blocks are not localized on the parent table
424
- localized: false,
425
- target: blockTableName
426
- });
427
- });
428
- break;
429
- }
430
- case 'tab':
431
- case 'group':
432
- {
433
- if (!('name' in field)) {
434
- const { hasLocalizedField: groupHasLocalizedField, hasLocalizedManyNumberField: groupHasLocalizedManyNumberField, hasLocalizedManyTextField: groupHasLocalizedManyTextField, hasLocalizedRelationshipField: groupHasLocalizedRelationshipField, hasManyNumberField: groupHasManyNumberField, hasManyTextField: groupHasManyTextField } = traverseFields({
435
- adapter,
436
- columnPrefix,
437
- columns,
438
- disableNotNull,
439
- disableUnique,
440
- fieldPrefix,
441
- fields: field.fields,
442
- forceLocalized,
443
- indexes,
444
- localesColumns,
445
- localesIndexes,
446
- newTableName,
447
- parentTableName,
448
- relationsToBuild,
449
- relationships,
450
- rootRelationsToBuild,
451
- rootTableIDColType,
452
- rootTableName,
453
- versions
454
- });
455
- if (groupHasLocalizedField) hasLocalizedField = true;
456
- if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true;
457
- if (groupHasManyTextField) hasManyTextField = true;
458
- if (groupHasLocalizedManyTextField) hasLocalizedManyTextField = true;
459
- if (groupHasManyNumberField) hasManyNumberField = true;
460
- if (groupHasLocalizedManyNumberField) hasLocalizedManyNumberField = true;
461
- break;
462
- }
463
- const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
464
- const { hasLocalizedField: groupHasLocalizedField, hasLocalizedManyNumberField: groupHasLocalizedManyNumberField, hasLocalizedManyTextField: groupHasLocalizedManyTextField, hasLocalizedRelationshipField: groupHasLocalizedRelationshipField, hasManyNumberField: groupHasManyNumberField, hasManyTextField: groupHasManyTextField } = traverseFields({
465
- adapter,
466
- columnPrefix: `${columnName}_`,
467
- columns,
468
- disableNotNull: disableNotNullFromHere,
469
- disableUnique,
470
- fieldPrefix: `${fieldName}.`,
471
- fields: field.fields,
472
- forceLocalized: field.localized,
473
- indexes,
474
- localesColumns,
475
- localesIndexes,
476
- newTableName: `${parentTableName}_${columnName}`,
477
- parentTableName,
478
- relationsToBuild,
479
- relationships,
480
- rootRelationsToBuild,
481
- rootTableIDColType,
482
- rootTableName,
483
- versions
484
- });
485
- if (groupHasLocalizedField) hasLocalizedField = true;
486
- if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true;
487
- if (groupHasManyTextField) hasManyTextField = true;
488
- if (groupHasLocalizedManyTextField) hasLocalizedManyTextField = true;
489
- if (groupHasManyNumberField) hasManyNumberField = true;
490
- if (groupHasLocalizedManyNumberField) hasLocalizedManyNumberField = true;
491
- break;
492
- }
493
- case 'tabs':
494
- {
495
- const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
496
- const { hasLocalizedField: tabHasLocalizedField, hasLocalizedManyNumberField: tabHasLocalizedManyNumberField, hasLocalizedManyTextField: tabHasLocalizedManyTextField, hasLocalizedRelationshipField: tabHasLocalizedRelationshipField, hasManyNumberField: tabHasManyNumberField, hasManyTextField: tabHasManyTextField } = traverseFields({
497
- adapter,
498
- columnPrefix,
499
- columns,
500
- disableNotNull: disableNotNullFromHere,
501
- disableUnique,
502
- fieldPrefix,
503
- fields: field.tabs.map((tab)=>({
504
- ...tab,
505
- type: 'tab'
506
- })),
507
- forceLocalized,
508
- indexes,
509
- localesColumns,
510
- localesIndexes,
511
- newTableName,
512
- parentTableName,
513
- relationsToBuild,
514
- relationships,
515
- rootRelationsToBuild,
516
- rootTableIDColType,
517
- rootTableName,
518
- versions
519
- });
520
- if (tabHasLocalizedField) hasLocalizedField = true;
521
- if (tabHasLocalizedRelationshipField) hasLocalizedRelationshipField = true;
522
- if (tabHasManyTextField) hasManyTextField = true;
523
- if (tabHasLocalizedManyTextField) hasLocalizedManyTextField = true;
524
- if (tabHasManyNumberField) hasManyNumberField = true;
525
- if (tabHasLocalizedManyNumberField) hasLocalizedManyNumberField = true;
526
- break;
527
- }
528
- case 'row':
529
- case 'collapsible':
530
- {
531
- const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
532
- const { hasLocalizedField: rowHasLocalizedField, hasLocalizedManyNumberField: rowHasLocalizedManyNumberField, hasLocalizedManyTextField: rowHasLocalizedManyTextField, hasLocalizedRelationshipField: rowHasLocalizedRelationshipField, hasManyNumberField: rowHasManyNumberField, hasManyTextField: rowHasManyTextField } = traverseFields({
533
- adapter,
534
- columnPrefix,
535
- columns,
536
- disableNotNull: disableNotNullFromHere,
537
- disableUnique,
538
- fieldPrefix,
539
- fields: field.fields,
540
- forceLocalized,
541
- indexes,
542
- localesColumns,
543
- localesIndexes,
544
- newTableName,
545
- parentTableName,
546
- relationsToBuild,
547
- relationships,
548
- rootRelationsToBuild,
549
- rootTableIDColType,
550
- rootTableName,
551
- versions
552
- });
553
- if (rowHasLocalizedField) hasLocalizedField = true;
554
- if (rowHasLocalizedRelationshipField) hasLocalizedRelationshipField = true;
555
- if (rowHasManyTextField) hasManyTextField = true;
556
- if (rowHasLocalizedManyTextField) hasLocalizedManyTextField = true;
557
- if (rowHasManyNumberField) hasManyNumberField = true;
558
- if (rowHasLocalizedManyNumberField) hasLocalizedManyNumberField = true;
559
- break;
560
- }
561
- case 'relationship':
562
- case 'upload':
563
- if (Array.isArray(field.relationTo)) {
564
- field.relationTo.forEach((relation)=>relationships.add(relation));
565
- } else if (field.type === 'relationship' && field.hasMany) {
566
- relationships.add(field.relationTo);
567
- } else {
568
- // simple relationships get a column on the targetTable with a foreign key to the relationTo table
569
- const relationshipConfig = adapter.payload.collections[field.relationTo].config;
570
- const tableName = adapter.tableNameMap.get(toSnakeCase(field.relationTo));
571
- // get the id type of the related collection
572
- let colType = adapter.idType === 'uuid' ? 'uuid' : 'integer';
573
- const relatedCollectionCustomID = relationshipConfig.fields.find((field)=>fieldAffectsData(field) && field.name === 'id');
574
- if (relatedCollectionCustomID?.type === 'number') colType = 'numeric';
575
- if (relatedCollectionCustomID?.type === 'text') colType = 'varchar';
576
- // make the foreign key column for relationship using the correct id column type
577
- targetTable[fieldName] = parentIDColumnMap[colType](`${columnName}_id`).references(()=>adapter.tables[tableName].id, {
578
- onDelete: 'set null'
579
- });
580
- // add relationship to table
581
- relationsToBuild.set(fieldName, {
582
- type: 'one',
583
- localized: adapter.payload.config.localization && field.localized,
584
- target: tableName
585
- });
586
- // add notNull when not required
587
- if (!disableNotNull && field.required && !field.admin?.condition) {
588
- targetTable[fieldName].notNull();
589
- }
590
- break;
591
- }
592
- if (adapter.payload.config.localization && field.localized) {
593
- hasLocalizedRelationshipField = true;
594
- }
595
- break;
596
- default:
597
- break;
598
- }
599
- const condition = field.admin && field.admin.condition;
600
- if (!disableNotNull && targetTable[fieldName] && 'required' in field && field.required && !condition) {
601
- targetTable[fieldName].notNull();
602
- }
603
- });
604
- return {
605
- hasLocalizedField,
606
- hasLocalizedManyNumberField,
607
- hasLocalizedManyTextField,
608
- hasLocalizedRelationshipField,
609
- hasManyNumberField,
610
- hasManyTextField
611
- };
612
- };
613
-
614
- //# sourceMappingURL=traverseFields.js.map