@payloadcms/db-postgres 3.0.0-canary.6659da8 → 3.0.0-canary.67aae47

Sign up to get free protection for your applications and to get access to all the features.
Files changed (354) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +35 -12
  3. package/dist/connect.js.map +1 -1
  4. package/dist/exports/migration-utils.js.map +1 -1
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +48 -69
  8. package/dist/index.js.map +1 -1
  9. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -1
  10. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +5 -4
  11. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
  12. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +1 -2
  13. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
  14. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -1
  15. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +3 -1
  16. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -1
  17. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -1
  18. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -1
  19. package/dist/predefinedMigrations/v2-v3/index.d.ts +2 -2
  20. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -1
  21. package/dist/predefinedMigrations/v2-v3/index.js +4 -4
  22. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -1
  23. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +5 -4
  24. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -1
  25. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +9 -3
  26. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -1
  27. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +3 -2
  28. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -1
  29. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -1
  30. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -1
  31. package/dist/types.d.ts +65 -78
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/types.js.map +1 -1
  34. package/package.json +20 -18
  35. package/dist/count.d.ts +0 -3
  36. package/dist/count.d.ts.map +0 -1
  37. package/dist/count.js +0 -41
  38. package/dist/count.js.map +0 -1
  39. package/dist/create.d.ts +0 -3
  40. package/dist/create.d.ts.map +0 -1
  41. package/dist/create.js +0 -19
  42. package/dist/create.js.map +0 -1
  43. package/dist/createGlobal.d.ts +0 -4
  44. package/dist/createGlobal.d.ts.map +0 -1
  45. package/dist/createGlobal.js +0 -19
  46. package/dist/createGlobal.js.map +0 -1
  47. package/dist/createGlobalVersion.d.ts +0 -5
  48. package/dist/createGlobalVersion.d.ts.map +0 -1
  49. package/dist/createGlobalVersion.js +0 -33
  50. package/dist/createGlobalVersion.js.map +0 -1
  51. package/dist/createMigration.d.ts +0 -3
  52. package/dist/createMigration.d.ts.map +0 -1
  53. package/dist/createMigration.js +0 -102
  54. package/dist/createMigration.js.map +0 -1
  55. package/dist/createVersion.d.ts +0 -4
  56. package/dist/createVersion.d.ts.map +0 -1
  57. package/dist/createVersion.js +0 -40
  58. package/dist/createVersion.js.map +0 -1
  59. package/dist/deleteMany.d.ts +0 -3
  60. package/dist/deleteMany.d.ts.map +0 -1
  61. package/dist/deleteMany.js +0 -28
  62. package/dist/deleteMany.js.map +0 -1
  63. package/dist/deleteOne.d.ts +0 -3
  64. package/dist/deleteOne.d.ts.map +0 -1
  65. package/dist/deleteOne.js +0 -59
  66. package/dist/deleteOne.js.map +0 -1
  67. package/dist/deleteVersions.d.ts +0 -3
  68. package/dist/deleteVersions.d.ts.map +0 -1
  69. package/dist/deleteVersions.js +0 -31
  70. package/dist/deleteVersions.js.map +0 -1
  71. package/dist/destroy.d.ts +0 -3
  72. package/dist/destroy.d.ts.map +0 -1
  73. package/dist/destroy.js +0 -15
  74. package/dist/destroy.js.map +0 -1
  75. package/dist/find/buildFindManyArgs.d.ts +0 -17
  76. package/dist/find/buildFindManyArgs.d.ts.map +0 -1
  77. package/dist/find/buildFindManyArgs.js +0 -65
  78. package/dist/find/buildFindManyArgs.js.map +0 -1
  79. package/dist/find/chainMethods.d.ts +0 -16
  80. package/dist/find/chainMethods.d.ts.map +0 -1
  81. package/dist/find/chainMethods.js +0 -12
  82. package/dist/find/chainMethods.js.map +0 -1
  83. package/dist/find/findMany.d.ts +0 -21
  84. package/dist/find/findMany.d.ts.map +0 -1
  85. package/dist/find/findMany.js +0 -152
  86. package/dist/find/findMany.js.map +0 -1
  87. package/dist/find/traverseFields.d.ts +0 -17
  88. package/dist/find/traverseFields.d.ts.map +0 -1
  89. package/dist/find/traverseFields.js +0 -156
  90. package/dist/find/traverseFields.js.map +0 -1
  91. package/dist/find.d.ts +0 -3
  92. package/dist/find.d.ts.map +0 -1
  93. package/dist/find.js +0 -21
  94. package/dist/find.js.map +0 -1
  95. package/dist/findGlobal.d.ts +0 -3
  96. package/dist/findGlobal.d.ts.map +0 -1
  97. package/dist/findGlobal.js +0 -23
  98. package/dist/findGlobal.js.map +0 -1
  99. package/dist/findGlobalVersions.d.ts +0 -3
  100. package/dist/findGlobalVersions.d.ts.map +0 -1
  101. package/dist/findGlobalVersions.js +0 -24
  102. package/dist/findGlobalVersions.js.map +0 -1
  103. package/dist/findOne.d.ts +0 -4
  104. package/dist/findOne.d.ts.map +0 -1
  105. package/dist/findOne.js +0 -21
  106. package/dist/findOne.js.map +0 -1
  107. package/dist/findVersions.d.ts +0 -3
  108. package/dist/findVersions.d.ts.map +0 -1
  109. package/dist/findVersions.js +0 -24
  110. package/dist/findVersions.js.map +0 -1
  111. package/dist/init.d.ts +0 -3
  112. package/dist/init.d.ts.map +0 -1
  113. package/dist/init.js +0 -91
  114. package/dist/init.js.map +0 -1
  115. package/dist/migrate.d.ts +0 -3
  116. package/dist/migrate.d.ts.map +0 -1
  117. package/dist/migrate.js +0 -99
  118. package/dist/migrate.js.map +0 -1
  119. package/dist/migrateDown.d.ts +0 -3
  120. package/dist/migrateDown.d.ts.map +0 -1
  121. package/dist/migrateDown.js +0 -63
  122. package/dist/migrateDown.js.map +0 -1
  123. package/dist/migrateFresh.d.ts +0 -8
  124. package/dist/migrateFresh.d.ts.map +0 -1
  125. package/dist/migrateFresh.js +0 -72
  126. package/dist/migrateFresh.js.map +0 -1
  127. package/dist/migrateRefresh.d.ts +0 -6
  128. package/dist/migrateRefresh.d.ts.map +0 -1
  129. package/dist/migrateRefresh.js +0 -102
  130. package/dist/migrateRefresh.js.map +0 -1
  131. package/dist/migrateReset.d.ts +0 -6
  132. package/dist/migrateReset.d.ts.map +0 -1
  133. package/dist/migrateReset.js +0 -82
  134. package/dist/migrateReset.js.map +0 -1
  135. package/dist/migrateStatus.d.ts +0 -3
  136. package/dist/migrateStatus.d.ts.map +0 -1
  137. package/dist/migrateStatus.js +0 -44
  138. package/dist/migrateStatus.js.map +0 -1
  139. package/dist/queries/buildAndOrConditions.d.ts +0 -16
  140. package/dist/queries/buildAndOrConditions.d.ts.map +0 -1
  141. package/dist/queries/buildAndOrConditions.js +0 -28
  142. package/dist/queries/buildAndOrConditions.js.map +0 -1
  143. package/dist/queries/buildQuery.d.ts +0 -30
  144. package/dist/queries/buildQuery.d.ts.map +0 -1
  145. package/dist/queries/buildQuery.js +0 -72
  146. package/dist/queries/buildQuery.js.map +0 -1
  147. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.d.ts +0 -2
  148. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.d.ts.map +0 -1
  149. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js +0 -14
  150. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +0 -1
  151. package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts +0 -2
  152. package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts.map +0 -1
  153. package/dist/queries/createJSONQuery/formatJSONPathSegment.js +0 -5
  154. package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +0 -1
  155. package/dist/queries/createJSONQuery/index.d.ts +0 -10
  156. package/dist/queries/createJSONQuery/index.d.ts.map +0 -1
  157. package/dist/queries/createJSONQuery/index.js +0 -54
  158. package/dist/queries/createJSONQuery/index.js.map +0 -1
  159. package/dist/queries/getTableColumnFromPath.d.ts +0 -50
  160. package/dist/queries/getTableColumnFromPath.d.ts.map +0 -1
  161. package/dist/queries/getTableColumnFromPath.js +0 -516
  162. package/dist/queries/getTableColumnFromPath.js.map +0 -1
  163. package/dist/queries/operatorMap.d.ts +0 -18
  164. package/dist/queries/operatorMap.d.ts.map +0 -1
  165. package/dist/queries/operatorMap.js +0 -24
  166. package/dist/queries/operatorMap.js.map +0 -1
  167. package/dist/queries/parseParams.d.ts +0 -16
  168. package/dist/queries/parseParams.d.ts.map +0 -1
  169. package/dist/queries/parseParams.js +0 -183
  170. package/dist/queries/parseParams.js.map +0 -1
  171. package/dist/queries/sanitizeQueryValue.d.ts +0 -15
  172. package/dist/queries/sanitizeQueryValue.d.ts.map +0 -1
  173. package/dist/queries/sanitizeQueryValue.js +0 -89
  174. package/dist/queries/sanitizeQueryValue.js.map +0 -1
  175. package/dist/queries/selectDistinct.d.ts +0 -22
  176. package/dist/queries/selectDistinct.d.ts.map +0 -1
  177. package/dist/queries/selectDistinct.js +0 -30
  178. package/dist/queries/selectDistinct.js.map +0 -1
  179. package/dist/queryDrafts.d.ts +0 -3
  180. package/dist/queryDrafts.d.ts.map +0 -1
  181. package/dist/queryDrafts.js +0 -40
  182. package/dist/queryDrafts.js.map +0 -1
  183. package/dist/schema/build.d.ts +0 -34
  184. package/dist/schema/build.d.ts.map +0 -1
  185. package/dist/schema/build.js +0 -369
  186. package/dist/schema/build.js.map +0 -1
  187. package/dist/schema/createIndex.d.ts +0 -12
  188. package/dist/schema/createIndex.d.ts.map +0 -1
  189. package/dist/schema/createIndex.js +0 -18
  190. package/dist/schema/createIndex.js.map +0 -1
  191. package/dist/schema/createTableName.d.ts +0 -30
  192. package/dist/schema/createTableName.d.ts.map +0 -1
  193. package/dist/schema/createTableName.js +0 -31
  194. package/dist/schema/createTableName.js.map +0 -1
  195. package/dist/schema/idToUUID.d.ts +0 -3
  196. package/dist/schema/idToUUID.d.ts.map +0 -1
  197. package/dist/schema/idToUUID.js +0 -11
  198. package/dist/schema/idToUUID.js.map +0 -1
  199. package/dist/schema/parentIDColumnMap.d.ts +0 -4
  200. package/dist/schema/parentIDColumnMap.d.ts.map +0 -1
  201. package/dist/schema/parentIDColumnMap.js +0 -9
  202. package/dist/schema/parentIDColumnMap.js.map +0 -1
  203. package/dist/schema/setColumnID.d.ts +0 -11
  204. package/dist/schema/setColumnID.d.ts.map +0 -1
  205. package/dist/schema/setColumnID.js +0 -24
  206. package/dist/schema/setColumnID.js.map +0 -1
  207. package/dist/schema/traverseFields.d.ts +0 -36
  208. package/dist/schema/traverseFields.d.ts.map +0 -1
  209. package/dist/schema/traverseFields.js +0 -614
  210. package/dist/schema/traverseFields.js.map +0 -1
  211. package/dist/schema/validateExistingBlockIsIdentical.d.ts +0 -12
  212. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +0 -1
  213. package/dist/schema/validateExistingBlockIsIdentical.js +0 -76
  214. package/dist/schema/validateExistingBlockIsIdentical.js.map +0 -1
  215. package/dist/transactions/beginTransaction.d.ts +0 -3
  216. package/dist/transactions/beginTransaction.d.ts.map +0 -1
  217. package/dist/transactions/beginTransaction.js +0 -51
  218. package/dist/transactions/beginTransaction.js.map +0 -1
  219. package/dist/transactions/commitTransaction.d.ts +0 -3
  220. package/dist/transactions/commitTransaction.d.ts.map +0 -1
  221. package/dist/transactions/commitTransaction.js +0 -14
  222. package/dist/transactions/commitTransaction.js.map +0 -1
  223. package/dist/transactions/rollbackTransaction.d.ts +0 -3
  224. package/dist/transactions/rollbackTransaction.d.ts.map +0 -1
  225. package/dist/transactions/rollbackTransaction.js +0 -13
  226. package/dist/transactions/rollbackTransaction.js.map +0 -1
  227. package/dist/transform/read/hasManyNumber.d.ts +0 -10
  228. package/dist/transform/read/hasManyNumber.d.ts.map +0 -1
  229. package/dist/transform/read/hasManyNumber.js +0 -10
  230. package/dist/transform/read/hasManyNumber.js.map +0 -1
  231. package/dist/transform/read/hasManyText.d.ts +0 -10
  232. package/dist/transform/read/hasManyText.d.ts.map +0 -1
  233. package/dist/transform/read/hasManyText.js +0 -10
  234. package/dist/transform/read/hasManyText.js.map +0 -1
  235. package/dist/transform/read/index.d.ts +0 -14
  236. package/dist/transform/read/index.d.ts.map +0 -1
  237. package/dist/transform/read/index.js +0 -44
  238. package/dist/transform/read/index.js.map +0 -1
  239. package/dist/transform/read/relationship.d.ts +0 -10
  240. package/dist/transform/read/relationship.d.ts.map +0 -1
  241. package/dist/transform/read/relationship.js +0 -60
  242. package/dist/transform/read/relationship.js.map +0 -1
  243. package/dist/transform/read/traverseFields.d.ts +0 -57
  244. package/dist/transform/read/traverseFields.d.ts.map +0 -1
  245. package/dist/transform/read/traverseFields.js +0 -435
  246. package/dist/transform/read/traverseFields.js.map +0 -1
  247. package/dist/transform/write/array.d.ts +0 -26
  248. package/dist/transform/write/array.d.ts.map +0 -1
  249. package/dist/transform/write/array.js +0 -58
  250. package/dist/transform/write/array.js.map +0 -1
  251. package/dist/transform/write/blocks.d.ts +0 -25
  252. package/dist/transform/write/blocks.d.ts.map +0 -1
  253. package/dist/transform/write/blocks.js +0 -54
  254. package/dist/transform/write/blocks.js.map +0 -1
  255. package/dist/transform/write/index.d.ts +0 -13
  256. package/dist/transform/write/index.d.ts.map +0 -1
  257. package/dist/transform/write/index.js +0 -41
  258. package/dist/transform/write/index.js.map +0 -1
  259. package/dist/transform/write/numbers.d.ts +0 -8
  260. package/dist/transform/write/numbers.d.ts.map +0 -1
  261. package/dist/transform/write/numbers.js +0 -11
  262. package/dist/transform/write/numbers.js.map +0 -1
  263. package/dist/transform/write/relationships.d.ts +0 -10
  264. package/dist/transform/write/relationships.d.ts.map +0 -1
  265. package/dist/transform/write/relationships.js +0 -23
  266. package/dist/transform/write/relationships.js.map +0 -1
  267. package/dist/transform/write/selects.d.ts +0 -8
  268. package/dist/transform/write/selects.d.ts.map +0 -1
  269. package/dist/transform/write/selects.js +0 -20
  270. package/dist/transform/write/selects.js.map +0 -1
  271. package/dist/transform/write/texts.d.ts +0 -8
  272. package/dist/transform/write/texts.d.ts.map +0 -1
  273. package/dist/transform/write/texts.js +0 -11
  274. package/dist/transform/write/texts.js.map +0 -1
  275. package/dist/transform/write/traverseFields.d.ts +0 -50
  276. package/dist/transform/write/traverseFields.d.ts.map +0 -1
  277. package/dist/transform/write/traverseFields.js +0 -445
  278. package/dist/transform/write/traverseFields.js.map +0 -1
  279. package/dist/transform/write/types.d.ts +0 -43
  280. package/dist/transform/write/types.d.ts.map +0 -1
  281. package/dist/transform/write/types.js +0 -3
  282. package/dist/transform/write/types.js.map +0 -1
  283. package/dist/update.d.ts +0 -3
  284. package/dist/update.d.ts.map +0 -1
  285. package/dist/update.js +0 -54
  286. package/dist/update.js.map +0 -1
  287. package/dist/updateGlobal.d.ts +0 -4
  288. package/dist/updateGlobal.d.ts.map +0 -1
  289. package/dist/updateGlobal.js +0 -25
  290. package/dist/updateGlobal.js.map +0 -1
  291. package/dist/updateGlobalVersion.d.ts +0 -4
  292. package/dist/updateGlobalVersion.d.ts.map +0 -1
  293. package/dist/updateGlobalVersion.js +0 -36
  294. package/dist/updateGlobalVersion.js.map +0 -1
  295. package/dist/updateVersion.d.ts +0 -4
  296. package/dist/updateVersion.d.ts.map +0 -1
  297. package/dist/updateVersion.js +0 -36
  298. package/dist/updateVersion.js.map +0 -1
  299. package/dist/upsertRow/deleteExistingArrayRows.d.ts +0 -10
  300. package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +0 -1
  301. package/dist/upsertRow/deleteExistingArrayRows.js +0 -10
  302. package/dist/upsertRow/deleteExistingArrayRows.js.map +0 -1
  303. package/dist/upsertRow/deleteExistingRowsByPath.d.ts +0 -14
  304. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +0 -1
  305. package/dist/upsertRow/deleteExistingRowsByPath.js +0 -33
  306. package/dist/upsertRow/deleteExistingRowsByPath.js.map +0 -1
  307. package/dist/upsertRow/index.d.ts +0 -4
  308. package/dist/upsertRow/index.d.ts.map +0 -1
  309. package/dist/upsertRow/index.js +0 -279
  310. package/dist/upsertRow/index.js.map +0 -1
  311. package/dist/upsertRow/insertArrays.d.ts +0 -13
  312. package/dist/upsertRow/insertArrays.d.ts.map +0 -1
  313. package/dist/upsertRow/insertArrays.js +0 -68
  314. package/dist/upsertRow/insertArrays.js.map +0 -1
  315. package/dist/upsertRow/types.d.ts +0 -32
  316. package/dist/upsertRow/types.d.ts.map +0 -1
  317. package/dist/upsertRow/types.js +0 -3
  318. package/dist/upsertRow/types.js.map +0 -1
  319. package/dist/utilities/appendPrefixToKeys.d.ts +0 -2
  320. package/dist/utilities/appendPrefixToKeys.d.ts.map +0 -1
  321. package/dist/utilities/appendPrefixToKeys.js +0 -6
  322. package/dist/utilities/appendPrefixToKeys.js.map +0 -1
  323. package/dist/utilities/createBlocksMap.d.ts +0 -5
  324. package/dist/utilities/createBlocksMap.d.ts.map +0 -1
  325. package/dist/utilities/createBlocksMap.js +0 -29
  326. package/dist/utilities/createBlocksMap.js.map +0 -1
  327. package/dist/utilities/createMigrationTable.d.ts +0 -3
  328. package/dist/utilities/createMigrationTable.d.ts.map +0 -1
  329. package/dist/utilities/createMigrationTable.js +0 -13
  330. package/dist/utilities/createMigrationTable.js.map +0 -1
  331. package/dist/utilities/createRelationshipMap.d.ts +0 -2
  332. package/dist/utilities/createRelationshipMap.d.ts.map +0 -1
  333. package/dist/utilities/createRelationshipMap.js +0 -19
  334. package/dist/utilities/createRelationshipMap.js.map +0 -1
  335. package/dist/utilities/hasLocalesTable.d.ts +0 -3
  336. package/dist/utilities/hasLocalesTable.d.ts.map +0 -1
  337. package/dist/utilities/hasLocalesTable.js +0 -11
  338. package/dist/utilities/hasLocalesTable.js.map +0 -1
  339. package/dist/utilities/isArrayOfRows.d.ts +0 -2
  340. package/dist/utilities/isArrayOfRows.d.ts.map +0 -1
  341. package/dist/utilities/isArrayOfRows.js +0 -5
  342. package/dist/utilities/isArrayOfRows.js.map +0 -1
  343. package/dist/utilities/migrationTableExists.d.ts +0 -3
  344. package/dist/utilities/migrationTableExists.d.ts.map +0 -1
  345. package/dist/utilities/migrationTableExists.js +0 -9
  346. package/dist/utilities/migrationTableExists.js.map +0 -1
  347. package/dist/utilities/parseError.d.ts +0 -5
  348. package/dist/utilities/parseError.d.ts.map +0 -1
  349. package/dist/utilities/parseError.js +0 -17
  350. package/dist/utilities/parseError.js.map +0 -1
  351. package/dist/utilities/pushDevSchema.d.ts +0 -9
  352. package/dist/utilities/pushDevSchema.d.ts.map +0 -1
  353. package/dist/utilities/pushDevSchema.js +0 -58
  354. 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';
4
- import { fieldAffectsData, optionIsObject } from 'payload/shared';
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