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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (369) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +10 -6
  3. package/dist/connect.js.map +1 -1
  4. package/dist/countDistinct.d.ts +3 -0
  5. package/dist/countDistinct.d.ts.map +1 -0
  6. package/dist/countDistinct.js +24 -0
  7. package/dist/countDistinct.js.map +1 -0
  8. package/dist/createJSONQuery/convertPathToJSONTraversal.d.ts.map +1 -0
  9. package/dist/createJSONQuery/convertPathToJSONTraversal.js.map +1 -0
  10. package/dist/createJSONQuery/formatJSONPathSegment.d.ts.map +1 -0
  11. package/dist/createJSONQuery/formatJSONPathSegment.js.map +1 -0
  12. package/dist/createJSONQuery/index.d.ts.map +1 -0
  13. package/dist/createJSONQuery/index.js.map +1 -0
  14. package/dist/createMigration.d.ts.map +1 -1
  15. package/dist/createMigration.js +20 -31
  16. package/dist/createMigration.js.map +1 -1
  17. package/dist/defaultSnapshot.d.ts +3 -0
  18. package/dist/defaultSnapshot.d.ts.map +1 -0
  19. package/dist/defaultSnapshot.js +17 -0
  20. package/dist/defaultSnapshot.js.map +1 -0
  21. package/dist/deleteWhere.d.ts +3 -0
  22. package/dist/deleteWhere.d.ts.map +1 -0
  23. package/dist/deleteWhere.js +6 -0
  24. package/dist/deleteWhere.js.map +1 -0
  25. package/dist/dropDatabase.d.ts +3 -0
  26. package/dist/dropDatabase.d.ts.map +1 -0
  27. package/dist/dropDatabase.js +9 -0
  28. package/dist/dropDatabase.js.map +1 -0
  29. package/dist/execute.d.ts +3 -0
  30. package/dist/execute.d.ts.map +1 -0
  31. package/dist/execute.js +11 -0
  32. package/dist/execute.js.map +1 -0
  33. package/dist/getMigrationTemplate.d.ts +4 -0
  34. package/dist/getMigrationTemplate.d.ts.map +1 -0
  35. package/dist/getMigrationTemplate.js +13 -0
  36. package/dist/getMigrationTemplate.js.map +1 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +39 -64
  39. package/dist/index.js.map +1 -1
  40. package/dist/init.d.ts.map +1 -1
  41. package/dist/init.js +14 -10
  42. package/dist/init.js.map +1 -1
  43. package/dist/insert.d.ts +3 -0
  44. package/dist/insert.d.ts.map +1 -0
  45. package/dist/insert.js +12 -0
  46. package/dist/insert.js.map +1 -0
  47. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +3 -2
  48. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
  49. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +1 -1
  50. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
  51. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -1
  52. package/dist/predefinedMigrations/v2-v3/index.js +2 -2
  53. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -1
  54. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +3 -2
  55. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -1
  56. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -1
  57. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +3 -2
  58. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -1
  59. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -1
  60. package/dist/requireDrizzleKit.d.ts +3 -0
  61. package/dist/requireDrizzleKit.d.ts.map +1 -0
  62. package/dist/requireDrizzleKit.js +5 -0
  63. package/dist/requireDrizzleKit.js.map +1 -0
  64. package/dist/schema/build.d.ts +4 -0
  65. package/dist/schema/build.d.ts.map +1 -1
  66. package/dist/schema/build.js +2 -2
  67. package/dist/schema/build.js.map +1 -1
  68. package/dist/schema/createIndex.d.ts.map +1 -1
  69. package/dist/schema/createIndex.js +1 -1
  70. package/dist/schema/createIndex.js.map +1 -1
  71. package/dist/schema/traverseFields.d.ts.map +1 -1
  72. package/dist/schema/traverseFields.js +13 -14
  73. package/dist/schema/traverseFields.js.map +1 -1
  74. package/dist/schema/withDefault.d.ts +4 -0
  75. package/dist/schema/withDefault.d.ts.map +1 -0
  76. package/dist/schema/withDefault.js +10 -0
  77. package/dist/schema/withDefault.js.map +1 -0
  78. package/dist/types.d.ts +95 -33
  79. package/dist/types.d.ts.map +1 -1
  80. package/dist/types.js.map +1 -1
  81. package/package.json +8 -8
  82. package/dist/count.d.ts +0 -3
  83. package/dist/count.d.ts.map +0 -1
  84. package/dist/count.js +0 -41
  85. package/dist/count.js.map +0 -1
  86. package/dist/create.d.ts +0 -3
  87. package/dist/create.d.ts.map +0 -1
  88. package/dist/create.js +0 -19
  89. package/dist/create.js.map +0 -1
  90. package/dist/createGlobal.d.ts +0 -4
  91. package/dist/createGlobal.d.ts.map +0 -1
  92. package/dist/createGlobal.js +0 -19
  93. package/dist/createGlobal.js.map +0 -1
  94. package/dist/createGlobalVersion.d.ts +0 -4
  95. package/dist/createGlobalVersion.d.ts.map +0 -1
  96. package/dist/createGlobalVersion.js +0 -33
  97. package/dist/createGlobalVersion.js.map +0 -1
  98. package/dist/createVersion.d.ts +0 -4
  99. package/dist/createVersion.d.ts.map +0 -1
  100. package/dist/createVersion.js +0 -40
  101. package/dist/createVersion.js.map +0 -1
  102. package/dist/deleteMany.d.ts +0 -3
  103. package/dist/deleteMany.d.ts.map +0 -1
  104. package/dist/deleteMany.js +0 -28
  105. package/dist/deleteMany.js.map +0 -1
  106. package/dist/deleteOne.d.ts +0 -3
  107. package/dist/deleteOne.d.ts.map +0 -1
  108. package/dist/deleteOne.js +0 -59
  109. package/dist/deleteOne.js.map +0 -1
  110. package/dist/deleteVersions.d.ts +0 -3
  111. package/dist/deleteVersions.d.ts.map +0 -1
  112. package/dist/deleteVersions.js +0 -31
  113. package/dist/deleteVersions.js.map +0 -1
  114. package/dist/destroy.d.ts +0 -3
  115. package/dist/destroy.d.ts.map +0 -1
  116. package/dist/destroy.js +0 -15
  117. package/dist/destroy.js.map +0 -1
  118. package/dist/find/buildFindManyArgs.d.ts +0 -17
  119. package/dist/find/buildFindManyArgs.d.ts.map +0 -1
  120. package/dist/find/buildFindManyArgs.js +0 -65
  121. package/dist/find/buildFindManyArgs.js.map +0 -1
  122. package/dist/find/chainMethods.d.ts +0 -16
  123. package/dist/find/chainMethods.d.ts.map +0 -1
  124. package/dist/find/chainMethods.js +0 -12
  125. package/dist/find/chainMethods.js.map +0 -1
  126. package/dist/find/findMany.d.ts +0 -21
  127. package/dist/find/findMany.d.ts.map +0 -1
  128. package/dist/find/findMany.js +0 -152
  129. package/dist/find/findMany.js.map +0 -1
  130. package/dist/find/traverseFields.d.ts +0 -17
  131. package/dist/find/traverseFields.d.ts.map +0 -1
  132. package/dist/find/traverseFields.js +0 -156
  133. package/dist/find/traverseFields.js.map +0 -1
  134. package/dist/find.d.ts +0 -3
  135. package/dist/find.d.ts.map +0 -1
  136. package/dist/find.js +0 -21
  137. package/dist/find.js.map +0 -1
  138. package/dist/findGlobal.d.ts +0 -3
  139. package/dist/findGlobal.d.ts.map +0 -1
  140. package/dist/findGlobal.js +0 -23
  141. package/dist/findGlobal.js.map +0 -1
  142. package/dist/findGlobalVersions.d.ts +0 -3
  143. package/dist/findGlobalVersions.d.ts.map +0 -1
  144. package/dist/findGlobalVersions.js +0 -24
  145. package/dist/findGlobalVersions.js.map +0 -1
  146. package/dist/findOne.d.ts +0 -4
  147. package/dist/findOne.d.ts.map +0 -1
  148. package/dist/findOne.js +0 -21
  149. package/dist/findOne.js.map +0 -1
  150. package/dist/findVersions.d.ts +0 -3
  151. package/dist/findVersions.d.ts.map +0 -1
  152. package/dist/findVersions.js +0 -24
  153. package/dist/findVersions.js.map +0 -1
  154. package/dist/migrate.d.ts +0 -3
  155. package/dist/migrate.d.ts.map +0 -1
  156. package/dist/migrate.js +0 -99
  157. package/dist/migrate.js.map +0 -1
  158. package/dist/migrateDown.d.ts +0 -3
  159. package/dist/migrateDown.d.ts.map +0 -1
  160. package/dist/migrateDown.js +0 -63
  161. package/dist/migrateDown.js.map +0 -1
  162. package/dist/migrateFresh.d.ts +0 -8
  163. package/dist/migrateFresh.d.ts.map +0 -1
  164. package/dist/migrateFresh.js +0 -72
  165. package/dist/migrateFresh.js.map +0 -1
  166. package/dist/migrateRefresh.d.ts +0 -6
  167. package/dist/migrateRefresh.d.ts.map +0 -1
  168. package/dist/migrateRefresh.js +0 -102
  169. package/dist/migrateRefresh.js.map +0 -1
  170. package/dist/migrateReset.d.ts +0 -6
  171. package/dist/migrateReset.d.ts.map +0 -1
  172. package/dist/migrateReset.js +0 -82
  173. package/dist/migrateReset.js.map +0 -1
  174. package/dist/migrateStatus.d.ts +0 -3
  175. package/dist/migrateStatus.d.ts.map +0 -1
  176. package/dist/migrateStatus.js +0 -44
  177. package/dist/migrateStatus.js.map +0 -1
  178. package/dist/queries/buildAndOrConditions.d.ts +0 -16
  179. package/dist/queries/buildAndOrConditions.d.ts.map +0 -1
  180. package/dist/queries/buildAndOrConditions.js +0 -28
  181. package/dist/queries/buildAndOrConditions.js.map +0 -1
  182. package/dist/queries/buildQuery.d.ts +0 -30
  183. package/dist/queries/buildQuery.d.ts.map +0 -1
  184. package/dist/queries/buildQuery.js +0 -72
  185. package/dist/queries/buildQuery.js.map +0 -1
  186. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.d.ts.map +0 -1
  187. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +0 -1
  188. package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts.map +0 -1
  189. package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +0 -1
  190. package/dist/queries/createJSONQuery/index.d.ts.map +0 -1
  191. package/dist/queries/createJSONQuery/index.js.map +0 -1
  192. package/dist/queries/getTableColumnFromPath.d.ts +0 -50
  193. package/dist/queries/getTableColumnFromPath.d.ts.map +0 -1
  194. package/dist/queries/getTableColumnFromPath.js +0 -516
  195. package/dist/queries/getTableColumnFromPath.js.map +0 -1
  196. package/dist/queries/operatorMap.d.ts +0 -18
  197. package/dist/queries/operatorMap.d.ts.map +0 -1
  198. package/dist/queries/operatorMap.js +0 -24
  199. package/dist/queries/operatorMap.js.map +0 -1
  200. package/dist/queries/parseParams.d.ts +0 -16
  201. package/dist/queries/parseParams.d.ts.map +0 -1
  202. package/dist/queries/parseParams.js +0 -183
  203. package/dist/queries/parseParams.js.map +0 -1
  204. package/dist/queries/sanitizeQueryValue.d.ts +0 -15
  205. package/dist/queries/sanitizeQueryValue.d.ts.map +0 -1
  206. package/dist/queries/sanitizeQueryValue.js +0 -89
  207. package/dist/queries/sanitizeQueryValue.js.map +0 -1
  208. package/dist/queries/selectDistinct.d.ts +0 -22
  209. package/dist/queries/selectDistinct.d.ts.map +0 -1
  210. package/dist/queries/selectDistinct.js +0 -30
  211. package/dist/queries/selectDistinct.js.map +0 -1
  212. package/dist/queryDrafts.d.ts +0 -3
  213. package/dist/queryDrafts.d.ts.map +0 -1
  214. package/dist/queryDrafts.js +0 -40
  215. package/dist/queryDrafts.js.map +0 -1
  216. package/dist/schema/createTableName.d.ts +0 -30
  217. package/dist/schema/createTableName.d.ts.map +0 -1
  218. package/dist/schema/createTableName.js +0 -31
  219. package/dist/schema/createTableName.js.map +0 -1
  220. package/dist/schema/validateExistingBlockIsIdentical.d.ts +0 -12
  221. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +0 -1
  222. package/dist/schema/validateExistingBlockIsIdentical.js +0 -76
  223. package/dist/schema/validateExistingBlockIsIdentical.js.map +0 -1
  224. package/dist/transactions/beginTransaction.d.ts +0 -3
  225. package/dist/transactions/beginTransaction.d.ts.map +0 -1
  226. package/dist/transactions/beginTransaction.js +0 -51
  227. package/dist/transactions/beginTransaction.js.map +0 -1
  228. package/dist/transactions/commitTransaction.d.ts +0 -3
  229. package/dist/transactions/commitTransaction.d.ts.map +0 -1
  230. package/dist/transactions/commitTransaction.js +0 -15
  231. package/dist/transactions/commitTransaction.js.map +0 -1
  232. package/dist/transactions/rollbackTransaction.d.ts +0 -3
  233. package/dist/transactions/rollbackTransaction.d.ts.map +0 -1
  234. package/dist/transactions/rollbackTransaction.js +0 -14
  235. package/dist/transactions/rollbackTransaction.js.map +0 -1
  236. package/dist/transform/read/hasManyNumber.d.ts +0 -10
  237. package/dist/transform/read/hasManyNumber.d.ts.map +0 -1
  238. package/dist/transform/read/hasManyNumber.js +0 -10
  239. package/dist/transform/read/hasManyNumber.js.map +0 -1
  240. package/dist/transform/read/hasManyText.d.ts +0 -10
  241. package/dist/transform/read/hasManyText.d.ts.map +0 -1
  242. package/dist/transform/read/hasManyText.js +0 -10
  243. package/dist/transform/read/hasManyText.js.map +0 -1
  244. package/dist/transform/read/index.d.ts +0 -13
  245. package/dist/transform/read/index.d.ts.map +0 -1
  246. package/dist/transform/read/index.js +0 -44
  247. package/dist/transform/read/index.js.map +0 -1
  248. package/dist/transform/read/relationship.d.ts +0 -10
  249. package/dist/transform/read/relationship.d.ts.map +0 -1
  250. package/dist/transform/read/relationship.js +0 -60
  251. package/dist/transform/read/relationship.js.map +0 -1
  252. package/dist/transform/read/traverseFields.d.ts +0 -57
  253. package/dist/transform/read/traverseFields.d.ts.map +0 -1
  254. package/dist/transform/read/traverseFields.js +0 -435
  255. package/dist/transform/read/traverseFields.js.map +0 -1
  256. package/dist/transform/write/array.d.ts +0 -26
  257. package/dist/transform/write/array.d.ts.map +0 -1
  258. package/dist/transform/write/array.js +0 -58
  259. package/dist/transform/write/array.js.map +0 -1
  260. package/dist/transform/write/blocks.d.ts +0 -25
  261. package/dist/transform/write/blocks.d.ts.map +0 -1
  262. package/dist/transform/write/blocks.js +0 -54
  263. package/dist/transform/write/blocks.js.map +0 -1
  264. package/dist/transform/write/index.d.ts +0 -13
  265. package/dist/transform/write/index.d.ts.map +0 -1
  266. package/dist/transform/write/index.js +0 -41
  267. package/dist/transform/write/index.js.map +0 -1
  268. package/dist/transform/write/numbers.d.ts +0 -8
  269. package/dist/transform/write/numbers.d.ts.map +0 -1
  270. package/dist/transform/write/numbers.js +0 -11
  271. package/dist/transform/write/numbers.js.map +0 -1
  272. package/dist/transform/write/relationships.d.ts +0 -10
  273. package/dist/transform/write/relationships.d.ts.map +0 -1
  274. package/dist/transform/write/relationships.js +0 -23
  275. package/dist/transform/write/relationships.js.map +0 -1
  276. package/dist/transform/write/selects.d.ts +0 -8
  277. package/dist/transform/write/selects.d.ts.map +0 -1
  278. package/dist/transform/write/selects.js +0 -20
  279. package/dist/transform/write/selects.js.map +0 -1
  280. package/dist/transform/write/texts.d.ts +0 -8
  281. package/dist/transform/write/texts.d.ts.map +0 -1
  282. package/dist/transform/write/texts.js +0 -11
  283. package/dist/transform/write/texts.js.map +0 -1
  284. package/dist/transform/write/traverseFields.d.ts +0 -50
  285. package/dist/transform/write/traverseFields.d.ts.map +0 -1
  286. package/dist/transform/write/traverseFields.js +0 -445
  287. package/dist/transform/write/traverseFields.js.map +0 -1
  288. package/dist/transform/write/types.d.ts +0 -43
  289. package/dist/transform/write/types.d.ts.map +0 -1
  290. package/dist/transform/write/types.js +0 -3
  291. package/dist/transform/write/types.js.map +0 -1
  292. package/dist/update.d.ts +0 -3
  293. package/dist/update.d.ts.map +0 -1
  294. package/dist/update.js +0 -54
  295. package/dist/update.js.map +0 -1
  296. package/dist/updateGlobal.d.ts +0 -4
  297. package/dist/updateGlobal.d.ts.map +0 -1
  298. package/dist/updateGlobal.js +0 -25
  299. package/dist/updateGlobal.js.map +0 -1
  300. package/dist/updateGlobalVersion.d.ts +0 -4
  301. package/dist/updateGlobalVersion.d.ts.map +0 -1
  302. package/dist/updateGlobalVersion.js +0 -36
  303. package/dist/updateGlobalVersion.js.map +0 -1
  304. package/dist/updateVersion.d.ts +0 -4
  305. package/dist/updateVersion.d.ts.map +0 -1
  306. package/dist/updateVersion.js +0 -36
  307. package/dist/updateVersion.js.map +0 -1
  308. package/dist/upsertRow/deleteExistingArrayRows.d.ts +0 -10
  309. package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +0 -1
  310. package/dist/upsertRow/deleteExistingArrayRows.js +0 -10
  311. package/dist/upsertRow/deleteExistingArrayRows.js.map +0 -1
  312. package/dist/upsertRow/deleteExistingRowsByPath.d.ts +0 -14
  313. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +0 -1
  314. package/dist/upsertRow/deleteExistingRowsByPath.js +0 -33
  315. package/dist/upsertRow/deleteExistingRowsByPath.js.map +0 -1
  316. package/dist/upsertRow/index.d.ts +0 -4
  317. package/dist/upsertRow/index.d.ts.map +0 -1
  318. package/dist/upsertRow/index.js +0 -281
  319. package/dist/upsertRow/index.js.map +0 -1
  320. package/dist/upsertRow/insertArrays.d.ts +0 -13
  321. package/dist/upsertRow/insertArrays.d.ts.map +0 -1
  322. package/dist/upsertRow/insertArrays.js +0 -68
  323. package/dist/upsertRow/insertArrays.js.map +0 -1
  324. package/dist/upsertRow/types.d.ts +0 -32
  325. package/dist/upsertRow/types.d.ts.map +0 -1
  326. package/dist/upsertRow/types.js +0 -3
  327. package/dist/upsertRow/types.js.map +0 -1
  328. package/dist/utilities/appendPrefixToKeys.d.ts +0 -2
  329. package/dist/utilities/appendPrefixToKeys.d.ts.map +0 -1
  330. package/dist/utilities/appendPrefixToKeys.js +0 -6
  331. package/dist/utilities/appendPrefixToKeys.js.map +0 -1
  332. package/dist/utilities/createBlocksMap.d.ts +0 -5
  333. package/dist/utilities/createBlocksMap.d.ts.map +0 -1
  334. package/dist/utilities/createBlocksMap.js +0 -29
  335. package/dist/utilities/createBlocksMap.js.map +0 -1
  336. package/dist/utilities/createMigrationTable.d.ts +0 -3
  337. package/dist/utilities/createMigrationTable.d.ts.map +0 -1
  338. package/dist/utilities/createMigrationTable.js +0 -13
  339. package/dist/utilities/createMigrationTable.js.map +0 -1
  340. package/dist/utilities/createRelationshipMap.d.ts +0 -2
  341. package/dist/utilities/createRelationshipMap.d.ts.map +0 -1
  342. package/dist/utilities/createRelationshipMap.js +0 -19
  343. package/dist/utilities/createRelationshipMap.js.map +0 -1
  344. package/dist/utilities/hasLocalesTable.d.ts +0 -3
  345. package/dist/utilities/hasLocalesTable.d.ts.map +0 -1
  346. package/dist/utilities/hasLocalesTable.js +0 -11
  347. package/dist/utilities/hasLocalesTable.js.map +0 -1
  348. package/dist/utilities/isArrayOfRows.d.ts +0 -2
  349. package/dist/utilities/isArrayOfRows.d.ts.map +0 -1
  350. package/dist/utilities/isArrayOfRows.js +0 -5
  351. package/dist/utilities/isArrayOfRows.js.map +0 -1
  352. package/dist/utilities/migrationTableExists.d.ts +0 -3
  353. package/dist/utilities/migrationTableExists.d.ts.map +0 -1
  354. package/dist/utilities/migrationTableExists.js +0 -9
  355. package/dist/utilities/migrationTableExists.js.map +0 -1
  356. package/dist/utilities/parseError.d.ts +0 -5
  357. package/dist/utilities/parseError.d.ts.map +0 -1
  358. package/dist/utilities/parseError.js +0 -17
  359. package/dist/utilities/parseError.js.map +0 -1
  360. package/dist/utilities/pushDevSchema.d.ts +0 -9
  361. package/dist/utilities/pushDevSchema.d.ts.map +0 -1
  362. package/dist/utilities/pushDevSchema.js +0 -58
  363. package/dist/utilities/pushDevSchema.js.map +0 -1
  364. /package/dist/{queries/createJSONQuery → createJSONQuery}/convertPathToJSONTraversal.d.ts +0 -0
  365. /package/dist/{queries/createJSONQuery → createJSONQuery}/convertPathToJSONTraversal.js +0 -0
  366. /package/dist/{queries/createJSONQuery → createJSONQuery}/formatJSONPathSegment.d.ts +0 -0
  367. /package/dist/{queries/createJSONQuery → createJSONQuery}/formatJSONPathSegment.js +0 -0
  368. /package/dist/{queries/createJSONQuery → createJSONQuery}/index.d.ts +0 -0
  369. /package/dist/{queries/createJSONQuery → createJSONQuery}/index.js +0 -0
@@ -1,72 +0,0 @@
1
- import { sql } from 'drizzle-orm';
2
- import { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload';
3
- import prompts from 'prompts';
4
- import { parseError } from './utilities/parseError.js';
5
- /**
6
- * Drop the current database and run all migrate up functions
7
- */ export async function migrateFresh({ forceAcceptWarning = false }) {
8
- const { payload } = this;
9
- if (forceAcceptWarning === false) {
10
- const { confirm: acceptWarning } = await prompts({
11
- name: 'confirm',
12
- type: 'confirm',
13
- initial: false,
14
- message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`
15
- }, {
16
- onCancel: ()=>{
17
- process.exit(0);
18
- }
19
- });
20
- if (!acceptWarning) {
21
- process.exit(0);
22
- }
23
- }
24
- payload.logger.info({
25
- msg: `Dropping database.`
26
- });
27
- await this.drizzle.execute(sql.raw(`drop schema ${this.schemaName || 'public'} cascade;
28
- create schema ${this.schemaName || 'public'};`));
29
- const migrationFiles = await readMigrationFiles({
30
- payload
31
- });
32
- payload.logger.debug({
33
- msg: `Found ${migrationFiles.length} migration files.`
34
- });
35
- const req = {
36
- payload
37
- };
38
- // Run all migrate up
39
- for (const migration of migrationFiles){
40
- payload.logger.info({
41
- msg: `Migrating: ${migration.name}`
42
- });
43
- try {
44
- const start = Date.now();
45
- await initTransaction(req);
46
- await migration.up({
47
- payload,
48
- req
49
- });
50
- await payload.create({
51
- collection: 'payload-migrations',
52
- data: {
53
- name: migration.name,
54
- batch: 1
55
- },
56
- req
57
- });
58
- await commitTransaction(req);
59
- payload.logger.info({
60
- msg: `Migrated: ${migration.name} (${Date.now() - start}ms)`
61
- });
62
- } catch (err) {
63
- await killTransaction(req);
64
- payload.logger.error({
65
- err,
66
- msg: parseError(err, `Error running migration ${migration.name}. Rolling back`)
67
- });
68
- }
69
- }
70
- }
71
-
72
- //# sourceMappingURL=migrateFresh.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { sql } from 'drizzle-orm'\nimport { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload'\nimport prompts from 'prompts'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { parseError } from './utilities/parseError.js'\n\n/**\n * Drop the current database and run all migrate up functions\n */\nexport async function migrateFresh(\n this: PostgresAdapter,\n { forceAcceptWarning = false },\n): Promise<void> {\n const { payload } = this\n\n if (forceAcceptWarning === false) {\n const { confirm: acceptWarning } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`,\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!acceptWarning) {\n process.exit(0)\n }\n }\n\n payload.logger.info({\n msg: `Dropping database.`,\n })\n\n await this.drizzle.execute(\n sql.raw(`drop schema ${this.schemaName || 'public'} cascade;\n create schema ${this.schemaName || 'public'};`),\n )\n\n const migrationFiles = await readMigrationFiles({ payload })\n payload.logger.debug({\n msg: `Found ${migrationFiles.length} migration files.`,\n })\n\n const req = { payload } as PayloadRequest\n // Run all migrate up\n for (const migration of migrationFiles) {\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n await migration.up({ payload, req })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n batch: 1,\n },\n req,\n })\n await commitTransaction(req)\n\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: parseError(err, `Error running migration ${migration.name}. Rolling back`),\n })\n }\n }\n}\n"],"names":["sql","commitTransaction","initTransaction","killTransaction","readMigrationFiles","prompts","parseError","migrateFresh","forceAcceptWarning","payload","confirm","acceptWarning","name","type","initial","message","onCancel","process","exit","logger","info","msg","drizzle","execute","raw","schemaName","migrationFiles","debug","length","req","migration","start","Date","now","up","create","collection","data","batch","err","error"],"mappings":"AAEA,SAASA,GAAG,QAAQ,cAAa;AACjC,SAASC,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,EAAEC,kBAAkB,QAAQ,UAAS;AACjG,OAAOC,aAAa,UAAS;AAI7B,SAASC,UAAU,QAAQ,4BAA2B;AAEtD;;CAEC,GACD,OAAO,eAAeC,aAEpB,EAAEC,qBAAqB,KAAK,EAAE;IAE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IAAI,CAAC;gBAAEC,KAAK,CAAC,WAAW,EAAES,UAAUlB,IAAI,CAAC,EAAE,EAAEoB,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YAAC;QACtF,EAAE,OAAOQ,KAAc;YACrB,MAAMpC,gBAAgB0B;YACtBpB,QAAQU,MAAM,CAACqB,KAAK,CAAC;gBACnBD;gBACAlB,KAAKf,WAAWiC,KAAK,CAAC,wBAAwB,EAAET,UAAUlB,IAAI,CAAC,cAAc,CAAC;YAChF;QACF;IACF;AACF"}
@@ -1,6 +0,0 @@
1
- import type { PostgresAdapter } from './types.js';
2
- /**
3
- * Run all migration down functions before running up
4
- */
5
- export declare function migrateRefresh(this: PostgresAdapter): Promise<void>;
6
- //# sourceMappingURL=migrateRefresh.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrateRefresh.d.ts","sourceRoot":"","sources":["../src/migrateRefresh.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAKjD;;GAEG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,eAAe,iBAsFzD"}
@@ -1,102 +0,0 @@
1
- /* eslint-disable no-restricted-syntax, no-await-in-loop */ import { commitTransaction, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload';
2
- import { migrationTableExists } from './utilities/migrationTableExists.js';
3
- import { parseError } from './utilities/parseError.js';
4
- /**
5
- * Run all migration down functions before running up
6
- */ export async function migrateRefresh() {
7
- const { payload } = this;
8
- const migrationFiles = await readMigrationFiles({
9
- payload
10
- });
11
- const { existingMigrations, latestBatch } = await getMigrations({
12
- payload
13
- });
14
- if (!existingMigrations?.length) {
15
- payload.logger.info({
16
- msg: 'No migrations to rollback.'
17
- });
18
- return;
19
- }
20
- payload.logger.info({
21
- msg: `Rolling back batch ${latestBatch} consisting of ${existingMigrations.length} migration(s).`
22
- });
23
- const req = {
24
- payload
25
- };
26
- // Reverse order of migrations to rollback
27
- existingMigrations.reverse();
28
- for (const migration of existingMigrations){
29
- try {
30
- const migrationFile = migrationFiles.find((m)=>m.name === migration.name);
31
- if (!migrationFile) {
32
- throw new Error(`Migration ${migration.name} not found locally.`);
33
- }
34
- payload.logger.info({
35
- msg: `Migrating down: ${migration.name}`
36
- });
37
- const start = Date.now();
38
- await initTransaction(req);
39
- await migrationFile.down({
40
- payload,
41
- req
42
- });
43
- payload.logger.info({
44
- msg: `Migrated down: ${migration.name} (${Date.now() - start}ms)`
45
- });
46
- const tableExists = await migrationTableExists(this.drizzle);
47
- if (tableExists) {
48
- await payload.delete({
49
- collection: 'payload-migrations',
50
- req,
51
- where: {
52
- name: {
53
- equals: migration.name
54
- }
55
- }
56
- });
57
- }
58
- await commitTransaction(req);
59
- } catch (err) {
60
- await killTransaction(req);
61
- payload.logger.error({
62
- err,
63
- msg: parseError(err, `Error running migration ${migration.name}. Rolling back.`)
64
- });
65
- process.exit(1);
66
- }
67
- }
68
- // Run all migrate up
69
- for (const migration of migrationFiles){
70
- payload.logger.info({
71
- msg: `Migrating: ${migration.name}`
72
- });
73
- try {
74
- const start = Date.now();
75
- await initTransaction(req);
76
- await migration.up({
77
- payload,
78
- req
79
- });
80
- await payload.create({
81
- collection: 'payload-migrations',
82
- data: {
83
- name: migration.name,
84
- executed: true
85
- },
86
- req
87
- });
88
- await commitTransaction(req);
89
- payload.logger.info({
90
- msg: `Migrated: ${migration.name} (${Date.now() - start}ms)`
91
- });
92
- } catch (err) {
93
- await killTransaction(req);
94
- payload.logger.error({
95
- err,
96
- msg: parseError(err, `Error running migration ${migration.name}. Rolling back.`)
97
- });
98
- }
99
- }
100
- }
101
-
102
- //# sourceMappingURL=migrateRefresh.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/migrateRefresh.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { PayloadRequest } from 'payload'\n\nimport {\n commitTransaction,\n getMigrations,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\nimport { parseError } from './utilities/parseError.js'\n\n/**\n * Run all migration down functions before running up\n */\nexport async function migrateRefresh(this: PostgresAdapter) {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations, latestBatch } = await getMigrations({\n payload,\n })\n\n if (!existingMigrations?.length) {\n payload.logger.info({ msg: 'No migrations to rollback.' })\n return\n }\n\n payload.logger.info({\n msg: `Rolling back batch ${latestBatch} consisting of ${existingMigrations.length} migration(s).`,\n })\n\n const req = { payload } as PayloadRequest\n\n // Reverse order of migrations to rollback\n existingMigrations.reverse()\n\n for (const migration of existingMigrations) {\n try {\n const migrationFile = migrationFiles.find((m) => m.name === migration.name)\n if (!migrationFile) {\n throw new Error(`Migration ${migration.name} not found locally.`)\n }\n\n payload.logger.info({ msg: `Migrating down: ${migration.name}` })\n const start = Date.now()\n await initTransaction(req)\n await migrationFile.down({ payload, req })\n payload.logger.info({\n msg: `Migrated down: ${migration.name} (${Date.now() - start}ms)`,\n })\n\n const tableExists = await migrationTableExists(this.drizzle)\n if (tableExists) {\n await payload.delete({\n collection: 'payload-migrations',\n req,\n where: {\n name: {\n equals: migration.name,\n },\n },\n })\n }\n await commitTransaction(req)\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: parseError(err, `Error running migration ${migration.name}. Rolling back.`),\n })\n process.exit(1)\n }\n }\n\n // Run all migrate up\n for (const migration of migrationFiles) {\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n await migration.up({ payload, req })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n executed: true,\n },\n req,\n })\n await commitTransaction(req)\n\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: parseError(err, `Error running migration ${migration.name}. Rolling back.`),\n })\n }\n }\n}\n"],"names":["commitTransaction","getMigrations","initTransaction","killTransaction","readMigrationFiles","migrationTableExists","parseError","migrateRefresh","payload","migrationFiles","existingMigrations","latestBatch","length","logger","info","msg","req","reverse","migration","migrationFile","find","m","name","Error","start","Date","now","down","tableExists","drizzle","delete","collection","where","equals","err","error","process","exit","up","create","data","executed"],"mappings":"AAAA,yDAAyD,GAGzD,SACEA,iBAAiB,EACjBC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,UAAS;AAIhB,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,UAAU,QAAQ,4BAA2B;AAEtD;;CAEC,GACD,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAML,mBAAmB;QAAEI;IAAQ;IAE1D,MAAM,EAAEE,kBAAkB,EAAEC,WAAW,EAAE,GAAG,MAAMV,cAAc;QAC9DO;IACF;IAEA,IAAI,CAACE,oBAAoBE,QAAQ;QAC/BJ,QAAQK,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK;QAA6B;QACxD;IACF;IAEAP,QAAQK,MAAM,CAACC,IAAI,CAAC;QAClBC,KAAK,CAAC,mBAAmB,EAAEJ,YAAY,eAAe,EAAED,mBAAmBE,MAAM,CAAC,cAAc,CAAC;IACnG;IAEA,MAAMI,MAAM;QAAER;IAAQ;IAEtB,0CAA0C;IAC1CE,mBAAmBO,OAAO;IAE1B,KAAK,MAAMC,aAAaR,mBAAoB;QAC1C,IAAI;YACF,MAAMS,gBAAgBV,eAAeW,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;YAC1E,IAAI,CAACH,eAAe;gBAClB,MAAM,IAAII,MAAM,CAAC,UAAU,EAAEL,UAAUI,IAAI,CAAC,mBAAmB,CAAC;YAClE;YAEAd,QAAQK,MAAM,CAACC,IAAI,CAAC;gBAAEC,KAAK,C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C,IAAI,CAAC;gBAAEC,KAAK,CAAC,WAAW,EAAEG,UAAUI,IAAI,CAAC,EAAE,EAAEG,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YAAC;QACtF,EAAE,OAAOU,KAAc;YACrB,MAAM/B,gBAAgBa;YACtBR,QAAQK,MAAM,CAACsB,KAAK,CAAC;gBACnBD;gBACAnB,KAAKT,WAAW4B,KAAK,CAAC,wBAAwB,EAAEhB,UAAUI,IAAI,CAAC,eAAe,CAAC;YACjF;QACF;IACF;AACF"}
@@ -1,6 +0,0 @@
1
- import type { PostgresAdapter } from './types.js';
2
- /**
3
- * Run all migrate down functions
4
- */
5
- export declare function migrateReset(this: PostgresAdapter): Promise<void>;
6
- //# sourceMappingURL=migrateReset.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrateReset.d.ts","sourceRoot":"","sources":["../src/migrateReset.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAIjD;;GAEG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAsEvE"}
@@ -1,82 +0,0 @@
1
- /* eslint-disable no-restricted-syntax, no-await-in-loop */ import { commitTransaction, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload';
2
- import { migrationTableExists } from './utilities/migrationTableExists.js';
3
- /**
4
- * Run all migrate down functions
5
- */ export async function migrateReset() {
6
- const { payload } = this;
7
- const migrationFiles = await readMigrationFiles({
8
- payload
9
- });
10
- const { existingMigrations } = await getMigrations({
11
- payload
12
- });
13
- if (!existingMigrations?.length) {
14
- payload.logger.info({
15
- msg: 'No migrations to reset.'
16
- });
17
- return;
18
- }
19
- const req = {
20
- payload
21
- };
22
- // Rollback all migrations in order
23
- for (const migration of existingMigrations){
24
- const migrationFile = migrationFiles.find((m)=>m.name === migration.name);
25
- try {
26
- if (!migrationFile) {
27
- throw new Error(`Migration ${migration.name} not found locally.`);
28
- }
29
- const start = Date.now();
30
- payload.logger.info({
31
- msg: `Migrating down: ${migrationFile.name}`
32
- });
33
- await initTransaction(req);
34
- await migrationFile.down({
35
- payload,
36
- req
37
- });
38
- payload.logger.info({
39
- msg: `Migrated down: ${migrationFile.name} (${Date.now() - start}ms)`
40
- });
41
- const tableExists = await migrationTableExists(this.drizzle);
42
- if (tableExists) {
43
- await payload.delete({
44
- id: migration.id,
45
- collection: 'payload-migrations',
46
- req
47
- });
48
- }
49
- await commitTransaction(req);
50
- } catch (err) {
51
- let msg = `Error running migration ${migrationFile.name}.`;
52
- if (err instanceof Error) msg += ` ${err.message}`;
53
- await killTransaction(req);
54
- payload.logger.error({
55
- err,
56
- msg
57
- });
58
- process.exit(1);
59
- }
60
- }
61
- // Delete dev migration
62
- const tableExists = await migrationTableExists(this.drizzle);
63
- if (tableExists) {
64
- try {
65
- await payload.delete({
66
- collection: 'payload-migrations',
67
- where: {
68
- batch: {
69
- equals: -1
70
- }
71
- }
72
- });
73
- } catch (err) {
74
- payload.logger.error({
75
- error: err,
76
- msg: 'Error deleting dev migration'
77
- });
78
- }
79
- }
80
- }
81
-
82
- //# sourceMappingURL=migrateReset.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/migrateReset.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { PayloadRequest } from 'payload'\n\nimport {\n commitTransaction,\n getMigrations,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\n\n/**\n * Run all migrate down functions\n */\nexport async function migrateReset(this: PostgresAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations } = await getMigrations({ payload })\n\n if (!existingMigrations?.length) {\n payload.logger.info({ msg: 'No migrations to reset.' })\n return\n }\n\n const req = { payload } as PayloadRequest\n\n // Rollback all migrations in order\n for (const migration of existingMigrations) {\n const migrationFile = migrationFiles.find((m) => m.name === migration.name)\n try {\n if (!migrationFile) {\n throw new Error(`Migration ${migration.name} not found locally.`)\n }\n\n const start = Date.now()\n payload.logger.info({ msg: `Migrating down: ${migrationFile.name}` })\n await initTransaction(req)\n await migrationFile.down({ payload, req })\n payload.logger.info({\n msg: `Migrated down: ${migrationFile.name} (${Date.now() - start}ms)`,\n })\n\n const tableExists = await migrationTableExists(this.drizzle)\n if (tableExists) {\n await payload.delete({\n id: migration.id,\n collection: 'payload-migrations',\n req,\n })\n }\n\n await commitTransaction(req)\n } catch (err: unknown) {\n let msg = `Error running migration ${migrationFile.name}.`\n\n if (err instanceof Error) msg += ` ${err.message}`\n\n await killTransaction(req)\n payload.logger.error({\n err,\n msg,\n })\n process.exit(1)\n }\n }\n\n // Delete dev migration\n\n const tableExists = await migrationTableExists(this.drizzle)\n if (tableExists) {\n try {\n await payload.delete({\n collection: 'payload-migrations',\n where: {\n batch: {\n equals: -1,\n },\n },\n })\n } catch (err: unknown) {\n payload.logger.error({ error: err, msg: 'Error deleting dev migration' })\n }\n }\n}\n"],"names":["commitTransaction","getMigrations","initTransaction","killTransaction","readMigrationFiles","migrationTableExists","migrateReset","payload","migrationFiles","existingMigrations","length","logger","info","msg","req","migration","migrationFile","find","m","name","Error","start","Date","now","down","tableExists","drizzle","delete","id","collection","err","message","error","process","exit","where","batch","equals"],"mappings":"AAAA,yDAAyD,GAGzD,SACEA,iBAAiB,EACjBC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,UAAS;AAIhB,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E;;CAEC,GACD,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMJ,mBAAmB;QAAEG;IAAQ;IAE1D,MAAM,EAAEE,kBAAkB,EAAE,GAAG,MAAMR,cAAc;QAAEM;IAAQ;IAE7D,IAAI,CAACE,oBAAoBC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C;QACf;IACF;IAEA,uBAAuB;IAEvB,MAAMT,cAAc,MAAMpB,qBAAqB,IAAI,CAACqB,OAAO;IAC3D,IAAID,aAAa;QACf,IAAI;YACF,MAAMlB,QAAQoB,MAAM,CAAC;gBACnBE,YAAY;gBACZM,OAAO;oBACLC,OAAO;wBACLC,QAAQ,CAAC;oBACX;gBACF;YACF;QACF,EAAE,OAAOP,KAAc;YACrBvB,QAAQI,MAAM,CAACqB,KAAK,CAAC;gBAAEA,OAAOF;gBAAKjB,KAAK;YAA+B;QACzE;IACF;AACF"}
@@ -1,3 +0,0 @@
1
- import type { PostgresAdapter } from './types.js';
2
- export declare function migrateStatus(this: PostgresAdapter): Promise<void>;
3
- //# sourceMappingURL=migrateStatus.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrateStatus.d.ts","sourceRoot":"","sources":["../src/migrateStatus.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAIjD,wBAAsB,aAAa,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAuCxE"}
@@ -1,44 +0,0 @@
1
- import { Table } from 'console-table-printer';
2
- import { getMigrations, readMigrationFiles } from 'payload';
3
- import { migrationTableExists } from './utilities/migrationTableExists.js';
4
- export async function migrateStatus() {
5
- const { payload } = this;
6
- const migrationFiles = await readMigrationFiles({
7
- payload
8
- });
9
- payload.logger.debug({
10
- msg: `Found ${migrationFiles.length} migration files.`
11
- });
12
- let existingMigrations = [];
13
- const hasMigrationTable = await migrationTableExists(this.drizzle);
14
- if (hasMigrationTable) {
15
- ({ existingMigrations } = await getMigrations({
16
- payload
17
- }));
18
- }
19
- if (!migrationFiles.length) {
20
- payload.logger.info({
21
- msg: 'No migrations found.'
22
- });
23
- return;
24
- }
25
- // Compare migration files to existing migrations
26
- const statuses = migrationFiles.map((migration)=>{
27
- const existingMigration = existingMigrations.find((m)=>m.name === migration.name);
28
- return {
29
- Name: migration.name,
30
- // eslint-disable-next-line perfectionist/sort-objects
31
- Batch: existingMigration?.batch,
32
- Ran: existingMigration ? 'Yes' : 'No'
33
- };
34
- });
35
- const p = new Table();
36
- statuses.forEach((s)=>{
37
- p.addRow(s, {
38
- color: s.Ran === 'Yes' ? 'green' : 'red'
39
- });
40
- });
41
- p.printTable();
42
- }
43
-
44
- //# sourceMappingURL=migrateStatus.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/migrateStatus.ts"],"sourcesContent":["import { Table } from 'console-table-printer'\nimport { getMigrations, readMigrationFiles } from 'payload'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\n\nexport async function migrateStatus(this: PostgresAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n payload.logger.debug({\n msg: `Found ${migrationFiles.length} migration files.`,\n })\n\n let existingMigrations = []\n const hasMigrationTable = await migrationTableExists(this.drizzle)\n\n if (hasMigrationTable) {\n ;({ existingMigrations } = await getMigrations({ payload }))\n }\n\n if (!migrationFiles.length) {\n payload.logger.info({ msg: 'No migrations found.' })\n return\n }\n\n // Compare migration files to existing migrations\n const statuses = migrationFiles.map((migration) => {\n const existingMigration = existingMigrations.find((m) => m.name === migration.name)\n return {\n Name: migration.name,\n // eslint-disable-next-line perfectionist/sort-objects\n Batch: existingMigration?.batch,\n Ran: existingMigration ? 'Yes' : 'No',\n }\n })\n\n const p = new Table()\n\n statuses.forEach((s) => {\n p.addRow(s, {\n color: s.Ran === 'Yes' ? 'green' : 'red',\n })\n })\n p.printTable()\n}\n"],"names":["Table","getMigrations","readMigrationFiles","migrationTableExists","migrateStatus","payload","migrationFiles","logger","debug","msg","length","existingMigrations","hasMigrationTable","drizzle","info","statuses","map","migration","existingMigration","find","m","name","Name","Batch","batch","Ran","p","forEach","s","addRow","color","printTable"],"mappings":"AAAA,SAASA,KAAK,QAAQ,wBAAuB;AAC7C,SAASC,aAAa,EAAEC,kBAAkB,QAAQ,UAAS;AAI3D,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMJ,mBAAmB;QAAEG;IAAQ;IAE1DA,QAAQE,MAAM,CAACC,KAAK,CAAC;QACnBC,KAAK,CAAC,MAAM,EAAEH,eAAeI,MAAM,CAAC,iBAAiB,CAAC;IACxD;IAEA,IAAIC,qBAAqB,EAAE;IAC3B,MAAMC,oBAAoB,MAAMT,qBAAqB,IAAI,CAACU,OAAO;IAEjE,IAAID,mBAAmB;QACnB,CAAA,EAAED,kBAAkB,EAAE,GAAG,MAAMV,cAAc;YAAEI;QAAQ,EAAC;IAC5D;IAEA,IAAI,CAACC,eAAeI,MAAM,EAAE;QAC1BL,QAAQE,MAAM,CAACO,IAAI,CAAC;YAAEL,KAAK;QAAuB;QAClD;IACF;IAEA,iDAAiD;IACjD,MAAMM,WAAWT,eAAeU,GAAG,CAAC,CAACC;QACnC,MAAMC,oBAAoBP,mBAAmBQ,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;QAClF,OAAO;YACLC,MAAML,UAAUI,IAAI;YACpB,sDAAsD;YACtDE,OAAOL,mBAAmBM;YAC1BC,KAAKP,oBAAoB,QAAQ;QACnC;IACF;IAEA,MAAMQ,IAAI,IAAI1B;IAEde,SAASY,OAAO,CAAC,CAACC;QAChBF,EAAEG,MAAM,CAACD,GAAG;YACVE,OAAOF,EAAEH,GAAG,KAAK,QAAQ,UAAU;QACrC;IACF;IACAC,EAAEK,UAAU;AACd"}
@@ -1,16 +0,0 @@
1
- import type { SQL } from 'drizzle-orm';
2
- import type { Field, Where } from 'payload';
3
- import type { GenericColumn, PostgresAdapter } from '../types.js';
4
- import type { BuildQueryJoinAliases } from './buildQuery.js';
5
- export declare function buildAndOrConditions({ adapter, fields, joins, locale, selectFields, tableName, where, }: {
6
- adapter: PostgresAdapter;
7
- collectionSlug?: string;
8
- fields: Field[];
9
- globalSlug?: string;
10
- joins: BuildQueryJoinAliases;
11
- locale?: string;
12
- selectFields: Record<string, GenericColumn>;
13
- tableName: string;
14
- where: Where[];
15
- }): Promise<SQL[]>;
16
- //# sourceMappingURL=buildAndOrConditions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildAndOrConditions.d.ts","sourceRoot":"","sources":["../../src/queries/buildAndOrConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE3C,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAI5D,wBAAsB,oBAAoB,CAAC,EACzC,OAAO,EACP,MAAM,EACN,KAAK,EACL,MAAM,EACN,YAAY,EACZ,SAAS,EACT,KAAK,GACN,EAAE;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,qBAAqB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,KAAK,EAAE,CAAA;CACf,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAwBjB"}
@@ -1,28 +0,0 @@
1
- import { parseParams } from './parseParams.js';
2
- export async function buildAndOrConditions({ adapter, fields, joins, locale, selectFields, tableName, where }) {
3
- const completedConditions = [];
4
- // Loop over all AND / OR operations and add them to the AND / OR query param
5
- // Operations should come through as an array
6
- // eslint-disable-next-line no-restricted-syntax
7
- for (const condition of where){
8
- // If the operation is properly formatted as an object
9
- if (typeof condition === 'object') {
10
- // eslint-disable-next-line no-await-in-loop
11
- const result = await parseParams({
12
- adapter,
13
- fields,
14
- joins,
15
- locale,
16
- selectFields,
17
- tableName,
18
- where: condition
19
- });
20
- if (result && Object.keys(result).length > 0) {
21
- completedConditions.push(result);
22
- }
23
- }
24
- }
25
- return completedConditions;
26
- }
27
-
28
- //# sourceMappingURL=buildAndOrConditions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { Field, Where } from 'payload'\n\nimport type { GenericColumn, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\nimport { parseParams } from './parseParams.js'\n\nexport async function buildAndOrConditions({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where,\n}: {\n adapter: PostgresAdapter\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n joins: BuildQueryJoinAliases\n locale?: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n where: Where[]\n}): Promise<SQL[]> {\n const completedConditions = []\n // Loop over all AND / OR operations and add them to the AND / OR query param\n // Operations should come through as an array\n // eslint-disable-next-line no-restricted-syntax\n for (const condition of where) {\n // If the operation is properly formatted as an object\n if (typeof condition === 'object') {\n // eslint-disable-next-line no-await-in-loop\n const result = await parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: condition,\n })\n if (result && Object.keys(result).length > 0) {\n completedConditions.push(result)\n }\n }\n }\n return completedConditions\n}\n"],"names":["parseParams","buildAndOrConditions","adapter","fields","joins","locale","selectFields","tableName","where","completedConditions","condition","result","Object","keys","length","push"],"mappings":"AAMA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,qBAAqB,EACzCC,OAAO,EACPC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,YAAY,EACZC,SAAS,EACTC,KAAK,EAWN;IACC,MAAMC,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAC7C,gDAAgD;IAChD,KAAK,MAAMC,aAAaF,MAAO;QAC7B,sDAAsD;QACtD,IAAI,OAAOE,cAAc,UAAU;YACjC,4CAA4C;YAC5C,MAAMC,SAAS,MAAMX,YAAY;gBAC/BE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,OAAOE;YACT;YACA,IAAIC,UAAUC,OAAOC,IAAI,CAACF,QAAQG,MAAM,GAAG,GAAG;gBAC5CL,oBAAoBM,IAAI,CAACJ;YAC3B;QACF;IACF;IACA,OAAOF;AACT"}
@@ -1,30 +0,0 @@
1
- import type { SQL } from 'drizzle-orm';
2
- import type { PgTableWithColumns } from 'drizzle-orm/pg-core';
3
- import type { Field, Where } from 'payload';
4
- import { asc, desc } from 'drizzle-orm';
5
- import type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js';
6
- export type BuildQueryJoins = Record<string, SQL>;
7
- export type BuildQueryJoinAliases = {
8
- condition: SQL;
9
- table: GenericTable | PgTableWithColumns<any>;
10
- }[];
11
- type BuildQueryArgs = {
12
- adapter: PostgresAdapter;
13
- fields: Field[];
14
- locale?: string;
15
- sort?: string;
16
- tableName: string;
17
- where: Where;
18
- };
19
- type Result = {
20
- joins: BuildQueryJoinAliases;
21
- orderBy: {
22
- column: GenericColumn;
23
- order: typeof asc | typeof desc;
24
- };
25
- selectFields: Record<string, GenericColumn>;
26
- where: SQL;
27
- };
28
- declare const buildQuery: ({ adapter, fields, locale, sort, tableName, where: incomingWhere, }: BuildQueryArgs) => Promise<Result>;
29
- export default buildQuery;
30
- //# sourceMappingURL=buildQuery.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE3C,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAEvC,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAK/E,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAEjD,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,GAAG,CAAA;IACd,KAAK,EAAE,YAAY,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;CAC9C,EAAE,CAAA;AAEH,KAAK,cAAc,GAAG;IACpB,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,KAAK,EAAE,qBAAqB,CAAA;IAC5B,OAAO,EAAE;QACP,MAAM,EAAE,aAAa,CAAA;QACrB,KAAK,EAAE,OAAO,GAAG,GAAG,OAAO,IAAI,CAAA;KAChC,CAAA;IACD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,KAAK,EAAE,GAAG,CAAA;CACX,CAAA;AACD,QAAA,MAAM,UAAU,wEAOb,cAAc,KAAG,OAAO,CAAC,MAAM,CA2EjC,CAAA;AAED,eAAe,UAAU,CAAA"}
@@ -1,72 +0,0 @@
1
- import { asc, desc } from 'drizzle-orm';
2
- import { getTableColumnFromPath } from './getTableColumnFromPath.js';
3
- import { parseParams } from './parseParams.js';
4
- const buildQuery = async function buildQuery({ adapter, fields, locale, sort, tableName, where: incomingWhere }) {
5
- const selectFields = {
6
- id: adapter.tables[tableName].id
7
- };
8
- const joins = [];
9
- const orderBy = {
10
- column: null,
11
- order: null
12
- };
13
- if (sort) {
14
- let sortPath;
15
- if (sort[0] === '-') {
16
- sortPath = sort.substring(1);
17
- orderBy.order = desc;
18
- } else {
19
- sortPath = sort;
20
- orderBy.order = asc;
21
- }
22
- try {
23
- const { columnName: sortTableColumnName, table: sortTable } = getTableColumnFromPath({
24
- adapter,
25
- collectionPath: sortPath,
26
- fields,
27
- joins,
28
- locale,
29
- pathSegments: sortPath.replace(/__/g, '.').split('.'),
30
- selectFields,
31
- tableName,
32
- value: sortPath
33
- });
34
- orderBy.column = sortTable?.[sortTableColumnName];
35
- } catch (err) {
36
- // continue
37
- }
38
- }
39
- if (!orderBy?.column) {
40
- orderBy.order = desc;
41
- const createdAt = adapter.tables[tableName]?.createdAt;
42
- if (createdAt) {
43
- orderBy.column = createdAt;
44
- } else {
45
- orderBy.column = adapter.tables[tableName].id;
46
- }
47
- }
48
- if (orderBy.column) {
49
- selectFields.sort = orderBy.column;
50
- }
51
- let where;
52
- if (incomingWhere && Object.keys(incomingWhere).length > 0) {
53
- where = await parseParams({
54
- adapter,
55
- fields,
56
- joins,
57
- locale,
58
- selectFields,
59
- tableName,
60
- where: incomingWhere
61
- });
62
- }
63
- return {
64
- joins,
65
- orderBy,
66
- selectFields,
67
- where
68
- };
69
- };
70
- export default buildQuery;
71
-
72
- //# sourceMappingURL=buildQuery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, Where } from 'payload'\n\nimport { asc, desc } from 'drizzle-orm'\n\nimport type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js'\n\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\nimport { parseParams } from './parseParams.js'\n\nexport type BuildQueryJoins = Record<string, SQL>\n\nexport type BuildQueryJoinAliases = {\n condition: SQL\n table: GenericTable | PgTableWithColumns<any>\n}[]\n\ntype BuildQueryArgs = {\n adapter: PostgresAdapter\n fields: Field[]\n locale?: string\n sort?: string\n tableName: string\n where: Where\n}\n\ntype Result = {\n joins: BuildQueryJoinAliases\n orderBy: {\n column: GenericColumn\n order: typeof asc | typeof desc\n }\n selectFields: Record<string, GenericColumn>\n where: SQL\n}\nconst buildQuery = async function buildQuery({\n adapter,\n fields,\n locale,\n sort,\n tableName,\n where: incomingWhere,\n}: BuildQueryArgs): Promise<Result> {\n const selectFields: Record<string, GenericColumn> = {\n id: adapter.tables[tableName].id,\n }\n const joins: BuildQueryJoinAliases = []\n\n const orderBy: Result['orderBy'] = {\n column: null,\n order: null,\n }\n\n if (sort) {\n let sortPath\n\n if (sort[0] === '-') {\n sortPath = sort.substring(1)\n orderBy.order = desc\n } else {\n sortPath = sort\n orderBy.order = asc\n }\n\n try {\n const { columnName: sortTableColumnName, table: sortTable } = getTableColumnFromPath({\n adapter,\n collectionPath: sortPath,\n fields,\n joins,\n locale,\n pathSegments: sortPath.replace(/__/g, '.').split('.'),\n selectFields,\n tableName,\n value: sortPath,\n })\n orderBy.column = sortTable?.[sortTableColumnName]\n } catch (err) {\n // continue\n }\n }\n\n if (!orderBy?.column) {\n orderBy.order = desc\n const createdAt = adapter.tables[tableName]?.createdAt\n\n if (createdAt) {\n orderBy.column = createdAt\n } else {\n orderBy.column = adapter.tables[tableName].id\n }\n }\n\n if (orderBy.column) {\n selectFields.sort = orderBy.column\n }\n\n let where: SQL\n\n if (incomingWhere && Object.keys(incomingWhere).length > 0) {\n where = await parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: incomingWhere,\n })\n }\n\n return {\n joins,\n orderBy,\n selectFields,\n where,\n }\n}\n\nexport default buildQuery\n"],"names":["asc","desc","getTableColumnFromPath","parseParams","buildQuery","adapter","fields","locale","sort","tableName","where","incomingWhere","selectFields","id","tables","joins","orderBy","column","order","sortPath","substring","columnName","sortTableColumnName","table","sortTable","collectionPath","pathSegments","replace","split","value","err","createdAt","Object","keys","length"],"mappings":"AAIA,SAASA,GAAG,EAAEC,IAAI,QAAQ,cAAa;AAIvC,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,WAAW,QAAQ,mBAAkB;AA2B9C,MAAMC,aAAa,eAAeA,WAAW,EAC3CC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,SAAS,EACTC,OAAOC,aAAa,EACL;IACf,MAAMC,eAA8C;QAClDC,IAAIR,QAAQS,MAAM,CAACL,UAAU,CAACI,EAAE;IAClC;IACA,MAAME,QAA+B,EAAE;IAEvC,MAAMC,UAA6B;QACjCC,QAAQ;QACRC,OAAO;IACT;IAEA,IAAIV,MAAM;QACR,IAAIW;QAEJ,IAAIX,IAAI,CAAC,EAAE,KAAK,KAAK;YACnBW,WAAWX,KAAKY,SAAS,CAAC;YAC1BJ,QAAQE,KAAK,GAAGjB;QAClB,OAAO;YACLkB,WAAWX;YACXQ,QAAQE,KAAK,GAAGlB;QAClB;QAEA,IAAI;YACF,MAAM,EAAEqB,YAAYC,mBAAmB,EAAEC,OAAOC,SAAS,EAAE,GAAGtB,uBAAuB;gBACnFG;gBACAoB,gBAAgBN;gBAChBb;gBACAS;gBACAR;gBACAmB,cAAcP,SAASQ,OAAO,CAAC,OAAO,KAAKC,KAAK,CAAC;gBACjDhB;gBACAH;gBACAoB,OAAOV;YACT;YACAH,QAAQC,MAAM,GAAGO,WAAW,CAACF,oBAAoB;QACnD,EAAE,OAAOQ,KAAK;QACZ,WAAW;QACb;IACF;IAEA,IAAI,CAACd,SAASC,QAAQ;QACpBD,QAAQE,KAAK,GAAGjB;QAChB,MAAM8B,YAAY1B,QAAQS,MAAM,CAACL,UAAU,EAAEsB;QAE7C,IAAIA,WAAW;YACbf,QAAQC,MAAM,GAAGc;QACnB,OAAO;YACLf,QAAQC,MAAM,GAAGZ,QAAQS,MAAM,CAACL,UAAU,CAACI,EAAE;QAC/C;IACF;IAEA,IAAIG,QAAQC,MAAM,EAAE;QAClBL,aAAaJ,IAAI,GAAGQ,QAAQC,MAAM;IACpC;IAEA,IAAIP;IAEJ,IAAIC,iBAAiBqB,OAAOC,IAAI,CAACtB,eAAeuB,MAAM,GAAG,GAAG;QAC1DxB,QAAQ,MAAMP,YAAY;YACxBE;YACAC;YACAS;YACAR;YACAK;YACAH;YACAC,OAAOC;QACT;IACF;IAEA,OAAO;QACLI;QACAC;QACAJ;QACAF;IACF;AACF;AAEA,eAAeN,WAAU"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"convertPathToJSONTraversal.d.ts","sourceRoot":"","sources":["../../../src/queries/createJSONQuery/convertPathToJSONTraversal.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,0BAA0B,qBAAsB,MAAM,EAAE,WAUpE,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/queries/createJSONQuery/convertPathToJSONTraversal.ts"],"sourcesContent":["import { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nexport const convertPathToJSONTraversal = (incomingSegments: string[]) => {\n const segments = [...incomingSegments]\n segments.shift()\n\n return segments.reduce((res, segment, i) => {\n const formattedSegment = formatJSONPathSegment(segment)\n\n if (i + 1 === segments.length) return `${res}->>${formattedSegment}`\n return `${res}->${formattedSegment}`\n }, '')\n}\n"],"names":["formatJSONPathSegment","convertPathToJSONTraversal","incomingSegments","segments","shift","reduce","res","segment","i","formattedSegment","length"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,6BAA4B;AAElE,OAAO,MAAMC,6BAA6B,CAACC;IACzC,MAAMC,WAAW;WAAID;KAAiB;IACtCC,SAASC,KAAK;IAEd,OAAOD,SAASE,MAAM,CAAC,CAACC,KAAKC,SAASC;QACpC,MAAMC,mBAAmBT,sBAAsBO;QAE/C,IAAIC,IAAI,MAAML,SAASO,MAAM,EAAE,OAAO,CAAC,EAAEJ,IAAI,GAAG,EAAEG,iBAAiB,CAAC;QACpE,OAAO,CAAC,EAAEH,IAAI,EAAE,EAAEG,iBAAiB,CAAC;IACtC,GAAG;AACL,EAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatJSONPathSegment.d.ts","sourceRoot":"","sources":["../../../src/queries/createJSONQuery/formatJSONPathSegment.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,YAAa,MAAM,WAEpD,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/queries/createJSONQuery/formatJSONPathSegment.ts"],"sourcesContent":["export const formatJSONPathSegment = (segment: string) => {\n return Number.isNaN(parseInt(segment)) ? `'${segment}'` : segment\n}\n"],"names":["formatJSONPathSegment","segment","Number","isNaN","parseInt"],"mappings":"AAAA,OAAO,MAAMA,wBAAwB,CAACC;IACpC,OAAOC,OAAOC,KAAK,CAACC,SAASH,YAAY,CAAC,CAAC,EAAEA,QAAQ,CAAC,CAAC,GAAGA;AAC5D,EAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/queries/createJSONQuery/index.ts"],"names":[],"mappings":"AAmDA,KAAK,IAAI,GAAG;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAED,eAAO,MAAM,eAAe,uEAMzB,IAAI,KAAG,MAqBT,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/queries/createJSONQuery/index.ts"],"sourcesContent":["import { convertPathToJSONTraversal } from './convertPathToJSONTraversal.js'\nimport { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nconst operatorMap = {\n contains: '~*',\n equals: '=',\n like: '~*',\n}\n\ntype FromArrayArgs = {\n isRoot?: true\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: unknown\n}\n\nconst fromArray = ({ isRoot, operator, pathSegments, treatAsArray, value }: FromArrayArgs) => {\n const newPathSegments = pathSegments.slice(isRoot ? 1 : 2)\n const alias = `${pathSegments[isRoot ? 0 : 1]}_alias_${newPathSegments.length}`\n\n newPathSegments.unshift(alias)\n\n const arrayElements = isRoot\n ? pathSegments[0]\n : `${pathSegments[0]} -> ${formatJSONPathSegment(pathSegments[1])}`\n\n return `EXISTS (\n SELECT 1\n FROM jsonb_array_elements(${arrayElements}) AS ${alias}\n WHERE ${createJSONQuery({\n operator,\n pathSegments: newPathSegments,\n treatAsArray,\n value,\n })}\n )`\n}\n\ntype CreateConstraintArgs = {\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: unknown\n}\n\nconst createConstraint = ({ operator, pathSegments, value }: CreateConstraintArgs): string => {\n const jsonQuery = convertPathToJSONTraversal(pathSegments)\n return `${pathSegments[0]}${jsonQuery} ${operatorMap[operator]} '${value}'`\n}\n\ntype Args = {\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n treatRootAsArray?: boolean\n value: unknown\n}\n\nexport const createJSONQuery = ({\n operator,\n pathSegments,\n treatAsArray,\n treatRootAsArray,\n value,\n}: Args): string => {\n if (treatRootAsArray) {\n return fromArray({\n isRoot: true,\n operator,\n pathSegments,\n treatAsArray,\n value,\n })\n }\n\n if (treatAsArray.includes(pathSegments[1])) {\n return fromArray({\n operator,\n pathSegments,\n treatAsArray,\n value,\n })\n }\n\n return createConstraint({ operator, pathSegments, treatAsArray, value })\n}\n"],"names":["convertPathToJSONTraversal","formatJSONPathSegment","operatorMap","contains","equals","like","fromArray","isRoot","operator","pathSegments","treatAsArray","value","newPathSegments","slice","alias","length","unshift","arrayElements","createJSONQuery","createConstraint","jsonQuery","treatRootAsArray","includes"],"mappings":"AAAA,SAASA,0BAA0B,QAAQ,kCAAiC;AAC5E,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE,MAAMC,c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