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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (345) 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/index.d.ts +2 -2
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +32 -67
  7. package/dist/index.js.map +1 -1
  8. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +5 -4
  9. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
  10. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +1 -1
  11. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
  12. package/dist/predefinedMigrations/v2-v3/index.d.ts +2 -2
  13. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -1
  14. package/dist/predefinedMigrations/v2-v3/index.js +2 -2
  15. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -1
  16. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +5 -4
  17. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -1
  18. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -1
  19. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +3 -2
  20. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -1
  21. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -1
  22. package/dist/types.d.ts +42 -78
  23. package/dist/types.d.ts.map +1 -1
  24. package/dist/types.js.map +1 -1
  25. package/package.json +10 -10
  26. package/dist/count.d.ts +0 -3
  27. package/dist/count.d.ts.map +0 -1
  28. package/dist/count.js +0 -41
  29. package/dist/count.js.map +0 -1
  30. package/dist/create.d.ts +0 -3
  31. package/dist/create.d.ts.map +0 -1
  32. package/dist/create.js +0 -19
  33. package/dist/create.js.map +0 -1
  34. package/dist/createGlobal.d.ts +0 -4
  35. package/dist/createGlobal.d.ts.map +0 -1
  36. package/dist/createGlobal.js +0 -19
  37. package/dist/createGlobal.js.map +0 -1
  38. package/dist/createGlobalVersion.d.ts +0 -5
  39. package/dist/createGlobalVersion.d.ts.map +0 -1
  40. package/dist/createGlobalVersion.js +0 -33
  41. package/dist/createGlobalVersion.js.map +0 -1
  42. package/dist/createMigration.d.ts +0 -3
  43. package/dist/createMigration.d.ts.map +0 -1
  44. package/dist/createMigration.js +0 -102
  45. package/dist/createMigration.js.map +0 -1
  46. package/dist/createVersion.d.ts +0 -4
  47. package/dist/createVersion.d.ts.map +0 -1
  48. package/dist/createVersion.js +0 -40
  49. package/dist/createVersion.js.map +0 -1
  50. package/dist/deleteMany.d.ts +0 -3
  51. package/dist/deleteMany.d.ts.map +0 -1
  52. package/dist/deleteMany.js +0 -28
  53. package/dist/deleteMany.js.map +0 -1
  54. package/dist/deleteOne.d.ts +0 -3
  55. package/dist/deleteOne.d.ts.map +0 -1
  56. package/dist/deleteOne.js +0 -59
  57. package/dist/deleteOne.js.map +0 -1
  58. package/dist/deleteVersions.d.ts +0 -3
  59. package/dist/deleteVersions.d.ts.map +0 -1
  60. package/dist/deleteVersions.js +0 -31
  61. package/dist/deleteVersions.js.map +0 -1
  62. package/dist/destroy.d.ts +0 -3
  63. package/dist/destroy.d.ts.map +0 -1
  64. package/dist/destroy.js +0 -15
  65. package/dist/destroy.js.map +0 -1
  66. package/dist/find/buildFindManyArgs.d.ts +0 -17
  67. package/dist/find/buildFindManyArgs.d.ts.map +0 -1
  68. package/dist/find/buildFindManyArgs.js +0 -65
  69. package/dist/find/buildFindManyArgs.js.map +0 -1
  70. package/dist/find/chainMethods.d.ts +0 -16
  71. package/dist/find/chainMethods.d.ts.map +0 -1
  72. package/dist/find/chainMethods.js +0 -12
  73. package/dist/find/chainMethods.js.map +0 -1
  74. package/dist/find/findMany.d.ts +0 -21
  75. package/dist/find/findMany.d.ts.map +0 -1
  76. package/dist/find/findMany.js +0 -152
  77. package/dist/find/findMany.js.map +0 -1
  78. package/dist/find/traverseFields.d.ts +0 -17
  79. package/dist/find/traverseFields.d.ts.map +0 -1
  80. package/dist/find/traverseFields.js +0 -156
  81. package/dist/find/traverseFields.js.map +0 -1
  82. package/dist/find.d.ts +0 -3
  83. package/dist/find.d.ts.map +0 -1
  84. package/dist/find.js +0 -21
  85. package/dist/find.js.map +0 -1
  86. package/dist/findGlobal.d.ts +0 -3
  87. package/dist/findGlobal.d.ts.map +0 -1
  88. package/dist/findGlobal.js +0 -23
  89. package/dist/findGlobal.js.map +0 -1
  90. package/dist/findGlobalVersions.d.ts +0 -3
  91. package/dist/findGlobalVersions.d.ts.map +0 -1
  92. package/dist/findGlobalVersions.js +0 -24
  93. package/dist/findGlobalVersions.js.map +0 -1
  94. package/dist/findOne.d.ts +0 -4
  95. package/dist/findOne.d.ts.map +0 -1
  96. package/dist/findOne.js +0 -21
  97. package/dist/findOne.js.map +0 -1
  98. package/dist/findVersions.d.ts +0 -3
  99. package/dist/findVersions.d.ts.map +0 -1
  100. package/dist/findVersions.js +0 -24
  101. package/dist/findVersions.js.map +0 -1
  102. package/dist/init.d.ts +0 -3
  103. package/dist/init.d.ts.map +0 -1
  104. package/dist/init.js +0 -91
  105. package/dist/init.js.map +0 -1
  106. package/dist/migrate.d.ts +0 -3
  107. package/dist/migrate.d.ts.map +0 -1
  108. package/dist/migrate.js +0 -99
  109. package/dist/migrate.js.map +0 -1
  110. package/dist/migrateDown.d.ts +0 -3
  111. package/dist/migrateDown.d.ts.map +0 -1
  112. package/dist/migrateDown.js +0 -63
  113. package/dist/migrateDown.js.map +0 -1
  114. package/dist/migrateFresh.d.ts +0 -8
  115. package/dist/migrateFresh.d.ts.map +0 -1
  116. package/dist/migrateFresh.js +0 -72
  117. package/dist/migrateFresh.js.map +0 -1
  118. package/dist/migrateRefresh.d.ts +0 -6
  119. package/dist/migrateRefresh.d.ts.map +0 -1
  120. package/dist/migrateRefresh.js +0 -102
  121. package/dist/migrateRefresh.js.map +0 -1
  122. package/dist/migrateReset.d.ts +0 -6
  123. package/dist/migrateReset.d.ts.map +0 -1
  124. package/dist/migrateReset.js +0 -82
  125. package/dist/migrateReset.js.map +0 -1
  126. package/dist/migrateStatus.d.ts +0 -3
  127. package/dist/migrateStatus.d.ts.map +0 -1
  128. package/dist/migrateStatus.js +0 -44
  129. package/dist/migrateStatus.js.map +0 -1
  130. package/dist/queries/buildAndOrConditions.d.ts +0 -16
  131. package/dist/queries/buildAndOrConditions.d.ts.map +0 -1
  132. package/dist/queries/buildAndOrConditions.js +0 -28
  133. package/dist/queries/buildAndOrConditions.js.map +0 -1
  134. package/dist/queries/buildQuery.d.ts +0 -30
  135. package/dist/queries/buildQuery.d.ts.map +0 -1
  136. package/dist/queries/buildQuery.js +0 -72
  137. package/dist/queries/buildQuery.js.map +0 -1
  138. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.d.ts +0 -2
  139. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.d.ts.map +0 -1
  140. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js +0 -14
  141. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +0 -1
  142. package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts +0 -2
  143. package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts.map +0 -1
  144. package/dist/queries/createJSONQuery/formatJSONPathSegment.js +0 -5
  145. package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +0 -1
  146. package/dist/queries/createJSONQuery/index.d.ts +0 -10
  147. package/dist/queries/createJSONQuery/index.d.ts.map +0 -1
  148. package/dist/queries/createJSONQuery/index.js +0 -54
  149. package/dist/queries/createJSONQuery/index.js.map +0 -1
  150. package/dist/queries/getTableColumnFromPath.d.ts +0 -50
  151. package/dist/queries/getTableColumnFromPath.d.ts.map +0 -1
  152. package/dist/queries/getTableColumnFromPath.js +0 -516
  153. package/dist/queries/getTableColumnFromPath.js.map +0 -1
  154. package/dist/queries/operatorMap.d.ts +0 -18
  155. package/dist/queries/operatorMap.d.ts.map +0 -1
  156. package/dist/queries/operatorMap.js +0 -24
  157. package/dist/queries/operatorMap.js.map +0 -1
  158. package/dist/queries/parseParams.d.ts +0 -16
  159. package/dist/queries/parseParams.d.ts.map +0 -1
  160. package/dist/queries/parseParams.js +0 -183
  161. package/dist/queries/parseParams.js.map +0 -1
  162. package/dist/queries/sanitizeQueryValue.d.ts +0 -15
  163. package/dist/queries/sanitizeQueryValue.d.ts.map +0 -1
  164. package/dist/queries/sanitizeQueryValue.js +0 -89
  165. package/dist/queries/sanitizeQueryValue.js.map +0 -1
  166. package/dist/queries/selectDistinct.d.ts +0 -22
  167. package/dist/queries/selectDistinct.d.ts.map +0 -1
  168. package/dist/queries/selectDistinct.js +0 -30
  169. package/dist/queries/selectDistinct.js.map +0 -1
  170. package/dist/queryDrafts.d.ts +0 -3
  171. package/dist/queryDrafts.d.ts.map +0 -1
  172. package/dist/queryDrafts.js +0 -40
  173. package/dist/queryDrafts.js.map +0 -1
  174. package/dist/schema/build.d.ts +0 -34
  175. package/dist/schema/build.d.ts.map +0 -1
  176. package/dist/schema/build.js +0 -369
  177. package/dist/schema/build.js.map +0 -1
  178. package/dist/schema/createIndex.d.ts +0 -12
  179. package/dist/schema/createIndex.d.ts.map +0 -1
  180. package/dist/schema/createIndex.js +0 -18
  181. package/dist/schema/createIndex.js.map +0 -1
  182. package/dist/schema/createTableName.d.ts +0 -30
  183. package/dist/schema/createTableName.d.ts.map +0 -1
  184. package/dist/schema/createTableName.js +0 -31
  185. package/dist/schema/createTableName.js.map +0 -1
  186. package/dist/schema/idToUUID.d.ts +0 -3
  187. package/dist/schema/idToUUID.d.ts.map +0 -1
  188. package/dist/schema/idToUUID.js +0 -11
  189. package/dist/schema/idToUUID.js.map +0 -1
  190. package/dist/schema/parentIDColumnMap.d.ts +0 -4
  191. package/dist/schema/parentIDColumnMap.d.ts.map +0 -1
  192. package/dist/schema/parentIDColumnMap.js +0 -9
  193. package/dist/schema/parentIDColumnMap.js.map +0 -1
  194. package/dist/schema/setColumnID.d.ts +0 -11
  195. package/dist/schema/setColumnID.d.ts.map +0 -1
  196. package/dist/schema/setColumnID.js +0 -24
  197. package/dist/schema/setColumnID.js.map +0 -1
  198. package/dist/schema/traverseFields.d.ts +0 -36
  199. package/dist/schema/traverseFields.d.ts.map +0 -1
  200. package/dist/schema/traverseFields.js +0 -614
  201. package/dist/schema/traverseFields.js.map +0 -1
  202. package/dist/schema/validateExistingBlockIsIdentical.d.ts +0 -12
  203. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +0 -1
  204. package/dist/schema/validateExistingBlockIsIdentical.js +0 -76
  205. package/dist/schema/validateExistingBlockIsIdentical.js.map +0 -1
  206. package/dist/transactions/beginTransaction.d.ts +0 -3
  207. package/dist/transactions/beginTransaction.d.ts.map +0 -1
  208. package/dist/transactions/beginTransaction.js +0 -51
  209. package/dist/transactions/beginTransaction.js.map +0 -1
  210. package/dist/transactions/commitTransaction.d.ts +0 -3
  211. package/dist/transactions/commitTransaction.d.ts.map +0 -1
  212. package/dist/transactions/commitTransaction.js +0 -14
  213. package/dist/transactions/commitTransaction.js.map +0 -1
  214. package/dist/transactions/rollbackTransaction.d.ts +0 -3
  215. package/dist/transactions/rollbackTransaction.d.ts.map +0 -1
  216. package/dist/transactions/rollbackTransaction.js +0 -13
  217. package/dist/transactions/rollbackTransaction.js.map +0 -1
  218. package/dist/transform/read/hasManyNumber.d.ts +0 -10
  219. package/dist/transform/read/hasManyNumber.d.ts.map +0 -1
  220. package/dist/transform/read/hasManyNumber.js +0 -10
  221. package/dist/transform/read/hasManyNumber.js.map +0 -1
  222. package/dist/transform/read/hasManyText.d.ts +0 -10
  223. package/dist/transform/read/hasManyText.d.ts.map +0 -1
  224. package/dist/transform/read/hasManyText.js +0 -10
  225. package/dist/transform/read/hasManyText.js.map +0 -1
  226. package/dist/transform/read/index.d.ts +0 -13
  227. package/dist/transform/read/index.d.ts.map +0 -1
  228. package/dist/transform/read/index.js +0 -44
  229. package/dist/transform/read/index.js.map +0 -1
  230. package/dist/transform/read/relationship.d.ts +0 -10
  231. package/dist/transform/read/relationship.d.ts.map +0 -1
  232. package/dist/transform/read/relationship.js +0 -60
  233. package/dist/transform/read/relationship.js.map +0 -1
  234. package/dist/transform/read/traverseFields.d.ts +0 -57
  235. package/dist/transform/read/traverseFields.d.ts.map +0 -1
  236. package/dist/transform/read/traverseFields.js +0 -435
  237. package/dist/transform/read/traverseFields.js.map +0 -1
  238. package/dist/transform/write/array.d.ts +0 -26
  239. package/dist/transform/write/array.d.ts.map +0 -1
  240. package/dist/transform/write/array.js +0 -58
  241. package/dist/transform/write/array.js.map +0 -1
  242. package/dist/transform/write/blocks.d.ts +0 -25
  243. package/dist/transform/write/blocks.d.ts.map +0 -1
  244. package/dist/transform/write/blocks.js +0 -54
  245. package/dist/transform/write/blocks.js.map +0 -1
  246. package/dist/transform/write/index.d.ts +0 -13
  247. package/dist/transform/write/index.d.ts.map +0 -1
  248. package/dist/transform/write/index.js +0 -41
  249. package/dist/transform/write/index.js.map +0 -1
  250. package/dist/transform/write/numbers.d.ts +0 -8
  251. package/dist/transform/write/numbers.d.ts.map +0 -1
  252. package/dist/transform/write/numbers.js +0 -11
  253. package/dist/transform/write/numbers.js.map +0 -1
  254. package/dist/transform/write/relationships.d.ts +0 -10
  255. package/dist/transform/write/relationships.d.ts.map +0 -1
  256. package/dist/transform/write/relationships.js +0 -23
  257. package/dist/transform/write/relationships.js.map +0 -1
  258. package/dist/transform/write/selects.d.ts +0 -8
  259. package/dist/transform/write/selects.d.ts.map +0 -1
  260. package/dist/transform/write/selects.js +0 -20
  261. package/dist/transform/write/selects.js.map +0 -1
  262. package/dist/transform/write/texts.d.ts +0 -8
  263. package/dist/transform/write/texts.d.ts.map +0 -1
  264. package/dist/transform/write/texts.js +0 -11
  265. package/dist/transform/write/texts.js.map +0 -1
  266. package/dist/transform/write/traverseFields.d.ts +0 -50
  267. package/dist/transform/write/traverseFields.d.ts.map +0 -1
  268. package/dist/transform/write/traverseFields.js +0 -445
  269. package/dist/transform/write/traverseFields.js.map +0 -1
  270. package/dist/transform/write/types.d.ts +0 -43
  271. package/dist/transform/write/types.d.ts.map +0 -1
  272. package/dist/transform/write/types.js +0 -3
  273. package/dist/transform/write/types.js.map +0 -1
  274. package/dist/update.d.ts +0 -3
  275. package/dist/update.d.ts.map +0 -1
  276. package/dist/update.js +0 -54
  277. package/dist/update.js.map +0 -1
  278. package/dist/updateGlobal.d.ts +0 -4
  279. package/dist/updateGlobal.d.ts.map +0 -1
  280. package/dist/updateGlobal.js +0 -25
  281. package/dist/updateGlobal.js.map +0 -1
  282. package/dist/updateGlobalVersion.d.ts +0 -4
  283. package/dist/updateGlobalVersion.d.ts.map +0 -1
  284. package/dist/updateGlobalVersion.js +0 -36
  285. package/dist/updateGlobalVersion.js.map +0 -1
  286. package/dist/updateVersion.d.ts +0 -4
  287. package/dist/updateVersion.d.ts.map +0 -1
  288. package/dist/updateVersion.js +0 -36
  289. package/dist/updateVersion.js.map +0 -1
  290. package/dist/upsertRow/deleteExistingArrayRows.d.ts +0 -10
  291. package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +0 -1
  292. package/dist/upsertRow/deleteExistingArrayRows.js +0 -10
  293. package/dist/upsertRow/deleteExistingArrayRows.js.map +0 -1
  294. package/dist/upsertRow/deleteExistingRowsByPath.d.ts +0 -14
  295. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +0 -1
  296. package/dist/upsertRow/deleteExistingRowsByPath.js +0 -33
  297. package/dist/upsertRow/deleteExistingRowsByPath.js.map +0 -1
  298. package/dist/upsertRow/index.d.ts +0 -4
  299. package/dist/upsertRow/index.d.ts.map +0 -1
  300. package/dist/upsertRow/index.js +0 -281
  301. package/dist/upsertRow/index.js.map +0 -1
  302. package/dist/upsertRow/insertArrays.d.ts +0 -13
  303. package/dist/upsertRow/insertArrays.d.ts.map +0 -1
  304. package/dist/upsertRow/insertArrays.js +0 -68
  305. package/dist/upsertRow/insertArrays.js.map +0 -1
  306. package/dist/upsertRow/types.d.ts +0 -32
  307. package/dist/upsertRow/types.d.ts.map +0 -1
  308. package/dist/upsertRow/types.js +0 -3
  309. package/dist/upsertRow/types.js.map +0 -1
  310. package/dist/utilities/appendPrefixToKeys.d.ts +0 -2
  311. package/dist/utilities/appendPrefixToKeys.d.ts.map +0 -1
  312. package/dist/utilities/appendPrefixToKeys.js +0 -6
  313. package/dist/utilities/appendPrefixToKeys.js.map +0 -1
  314. package/dist/utilities/createBlocksMap.d.ts +0 -5
  315. package/dist/utilities/createBlocksMap.d.ts.map +0 -1
  316. package/dist/utilities/createBlocksMap.js +0 -29
  317. package/dist/utilities/createBlocksMap.js.map +0 -1
  318. package/dist/utilities/createMigrationTable.d.ts +0 -3
  319. package/dist/utilities/createMigrationTable.d.ts.map +0 -1
  320. package/dist/utilities/createMigrationTable.js +0 -13
  321. package/dist/utilities/createMigrationTable.js.map +0 -1
  322. package/dist/utilities/createRelationshipMap.d.ts +0 -2
  323. package/dist/utilities/createRelationshipMap.d.ts.map +0 -1
  324. package/dist/utilities/createRelationshipMap.js +0 -19
  325. package/dist/utilities/createRelationshipMap.js.map +0 -1
  326. package/dist/utilities/hasLocalesTable.d.ts +0 -3
  327. package/dist/utilities/hasLocalesTable.d.ts.map +0 -1
  328. package/dist/utilities/hasLocalesTable.js +0 -11
  329. package/dist/utilities/hasLocalesTable.js.map +0 -1
  330. package/dist/utilities/isArrayOfRows.d.ts +0 -2
  331. package/dist/utilities/isArrayOfRows.d.ts.map +0 -1
  332. package/dist/utilities/isArrayOfRows.js +0 -5
  333. package/dist/utilities/isArrayOfRows.js.map +0 -1
  334. package/dist/utilities/migrationTableExists.d.ts +0 -3
  335. package/dist/utilities/migrationTableExists.d.ts.map +0 -1
  336. package/dist/utilities/migrationTableExists.js +0 -9
  337. package/dist/utilities/migrationTableExists.js.map +0 -1
  338. package/dist/utilities/parseError.d.ts +0 -5
  339. package/dist/utilities/parseError.d.ts.map +0 -1
  340. package/dist/utilities/parseError.js +0 -17
  341. package/dist/utilities/parseError.js.map +0 -1
  342. package/dist/utilities/pushDevSchema.d.ts +0 -9
  343. package/dist/utilities/pushDevSchema.d.ts.map +0 -1
  344. package/dist/utilities/pushDevSchema.js +0 -58
  345. package/dist/utilities/pushDevSchema.js.map +0 -1
@@ -1,156 +0,0 @@
1
- /* eslint-disable no-param-reassign */ import { fieldAffectsData, tabHasName } from 'payload/shared';
2
- import toSnakeCase from 'to-snake-case';
3
- export const traverseFields = ({ _locales, adapter, currentArgs, currentTableName, depth, fields, path, topLevelArgs, topLevelTableName })=>{
4
- fields.forEach((field)=>{
5
- // handle simple relationship
6
- if (depth > 0 && (field.type === 'upload' || field.type === 'relationship' && !field.hasMany && typeof field.relationTo === 'string')) {
7
- if (field.localized) {
8
- _locales.with[`${path}${field.name}`] = true;
9
- } else {
10
- currentArgs.with[`${path}${field.name}`] = true;
11
- }
12
- }
13
- if (field.type === 'collapsible' || field.type === 'row') {
14
- traverseFields({
15
- _locales,
16
- adapter,
17
- currentArgs,
18
- currentTableName,
19
- depth,
20
- fields: field.fields,
21
- path,
22
- topLevelArgs,
23
- topLevelTableName
24
- });
25
- return;
26
- }
27
- if (field.type === 'tabs') {
28
- field.tabs.forEach((tab)=>{
29
- const tabPath = tabHasName(tab) ? `${path}${tab.name}_` : path;
30
- traverseFields({
31
- _locales,
32
- adapter,
33
- currentArgs,
34
- currentTableName,
35
- depth,
36
- fields: tab.fields,
37
- path: tabPath,
38
- topLevelArgs,
39
- topLevelTableName
40
- });
41
- });
42
- return;
43
- }
44
- if (fieldAffectsData(field)) {
45
- switch(field.type){
46
- case 'array':
47
- {
48
- const withArray = {
49
- columns: {
50
- _parentID: false
51
- },
52
- orderBy: ({ _order }, { asc })=>[
53
- asc(_order)
54
- ],
55
- with: {}
56
- };
57
- const arrayTableName = adapter.tableNameMap.get(`${currentTableName}_${path}${toSnakeCase(field.name)}`);
58
- const arrayTableNameWithLocales = `${arrayTableName}${adapter.localesSuffix}`;
59
- if (adapter.tables[arrayTableNameWithLocales]) {
60
- withArray.with._locales = {
61
- columns: {
62
- id: false,
63
- _parentID: false
64
- },
65
- with: {}
66
- };
67
- }
68
- currentArgs.with[`${path}${field.name}`] = withArray;
69
- traverseFields({
70
- _locales: withArray.with._locales,
71
- adapter,
72
- currentArgs: withArray,
73
- currentTableName: arrayTableName,
74
- depth,
75
- fields: field.fields,
76
- path: '',
77
- topLevelArgs,
78
- topLevelTableName
79
- });
80
- break;
81
- }
82
- case 'select':
83
- {
84
- if (field.hasMany) {
85
- const withSelect = {
86
- columns: {
87
- id: false,
88
- order: false,
89
- parent: false
90
- },
91
- orderBy: ({ order }, { asc })=>[
92
- asc(order)
93
- ]
94
- };
95
- currentArgs.with[`${path}${field.name}`] = withSelect;
96
- }
97
- break;
98
- }
99
- case 'blocks':
100
- field.blocks.forEach((block)=>{
101
- const blockKey = `_blocks_${block.slug}`;
102
- if (!topLevelArgs[blockKey]) {
103
- const withBlock = {
104
- columns: {
105
- _parentID: false
106
- },
107
- orderBy: ({ _order }, { asc })=>[
108
- asc(_order)
109
- ],
110
- with: {}
111
- };
112
- const tableName = adapter.tableNameMap.get(`${topLevelTableName}_blocks_${toSnakeCase(block.slug)}`);
113
- if (adapter.tables[`${tableName}${adapter.localesSuffix}`]) {
114
- withBlock.with._locales = {
115
- with: {}
116
- };
117
- }
118
- topLevelArgs.with[blockKey] = withBlock;
119
- traverseFields({
120
- _locales: withBlock.with._locales,
121
- adapter,
122
- currentArgs: withBlock,
123
- currentTableName: tableName,
124
- depth,
125
- fields: block.fields,
126
- path: '',
127
- topLevelArgs,
128
- topLevelTableName
129
- });
130
- }
131
- });
132
- break;
133
- case 'group':
134
- traverseFields({
135
- _locales,
136
- adapter,
137
- currentArgs,
138
- currentTableName,
139
- depth,
140
- fields: field.fields,
141
- path: `${path}${field.name}_`,
142
- topLevelArgs,
143
- topLevelTableName
144
- });
145
- break;
146
- default:
147
- {
148
- break;
149
- }
150
- }
151
- }
152
- });
153
- return topLevelArgs;
154
- };
155
-
156
- //# sourceMappingURL=traverseFields.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/find/traverseFields.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Field } from 'payload'\n\nimport { fieldAffectsData, tabHasName } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../types.js'\nimport type { Result } from './buildFindManyArgs.js'\n\ntype TraverseFieldArgs = {\n _locales: Result\n adapter: PostgresAdapter\n currentArgs: Result\n currentTableName: string\n depth?: number\n fields: Field[]\n path: string\n topLevelArgs: Record<string, unknown>\n topLevelTableName: string\n}\n\nexport const traverseFields = ({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields,\n path,\n topLevelArgs,\n topLevelTableName,\n}: TraverseFieldArgs) => {\n fields.forEach((field) => {\n // handle simple relationship\n if (\n depth > 0 &&\n (field.type === 'upload' ||\n (field.type === 'relationship' && !field.hasMany && typeof field.relationTo === 'string'))\n ) {\n if (field.localized) {\n _locales.with[`${path}${field.name}`] = true\n } else {\n currentArgs.with[`${path}${field.name}`] = true\n }\n }\n\n if (field.type === 'collapsible' || field.type === 'row') {\n traverseFields({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields: field.fields,\n path,\n topLevelArgs,\n topLevelTableName,\n })\n\n return\n }\n\n if (field.type === 'tabs') {\n field.tabs.forEach((tab) => {\n const tabPath = tabHasName(tab) ? `${path}${tab.name}_` : path\n\n traverseFields({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields: tab.fields,\n path: tabPath,\n topLevelArgs,\n topLevelTableName,\n })\n })\n\n return\n }\n\n if (fieldAffectsData(field)) {\n switch (field.type) {\n case 'array': {\n const withArray: Result = {\n columns: {\n _parentID: false,\n },\n orderBy: ({ _order }, { asc }) => [asc(_order)],\n with: {},\n }\n\n const arrayTableName = adapter.tableNameMap.get(\n `${currentTableName}_${path}${toSnakeCase(field.name)}`,\n )\n\n const arrayTableNameWithLocales = `${arrayTableName}${adapter.localesSuffix}`\n\n if (adapter.tables[arrayTableNameWithLocales]) {\n withArray.with._locales = {\n columns: {\n id: false,\n _parentID: false,\n },\n with: {},\n }\n }\n currentArgs.with[`${path}${field.name}`] = withArray\n\n traverseFields({\n _locales: withArray.with._locales,\n adapter,\n currentArgs: withArray,\n currentTableName: arrayTableName,\n depth,\n fields: field.fields,\n path: '',\n topLevelArgs,\n topLevelTableName,\n })\n\n break\n }\n\n case 'select': {\n if (field.hasMany) {\n const withSelect: Result = {\n columns: {\n id: false,\n order: false,\n parent: false,\n },\n orderBy: ({ order }, { asc }) => [asc(order)],\n }\n\n currentArgs.with[`${path}${field.name}`] = withSelect\n }\n\n break\n }\n\n case 'blocks':\n field.blocks.forEach((block) => {\n const blockKey = `_blocks_${block.slug}`\n\n if (!topLevelArgs[blockKey]) {\n const withBlock: Result = {\n columns: {\n _parentID: false,\n },\n orderBy: ({ _order }, { asc }) => [asc(_order)],\n with: {},\n }\n\n const tableName = adapter.tableNameMap.get(\n `${topLevelTableName}_blocks_${toSnakeCase(block.slug)}`,\n )\n\n if (adapter.tables[`${tableName}${adapter.localesSuffix}`]) {\n withBlock.with._locales = {\n with: {},\n }\n }\n topLevelArgs.with[blockKey] = withBlock\n\n traverseFields({\n _locales: withBlock.with._locales,\n adapter,\n currentArgs: withBlock,\n currentTableName: tableName,\n depth,\n fields: block.fields,\n path: '',\n topLevelArgs,\n topLevelTableName,\n })\n }\n })\n\n break\n\n case 'group':\n traverseFields({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields: field.fields,\n path: `${path}${field.name}_`,\n topLevelArgs,\n topLevelTableName,\n })\n\n break\n\n default: {\n break\n }\n }\n }\n })\n\n return topLevelArgs\n}\n"],"names":["fieldAffectsData","tabHasName","toSnakeCase","traverseFields","_locales","adapter","currentArgs","currentTableName","depth","fields","path","topLevelArgs","topLevelTableName","forEach","field","type","hasMany","relationTo","localized","with","name","tabs","tab","tabPath","withArray","columns","_parentID","orderBy","_order","asc","arrayTableName","tableNameMap","get","arrayTableNameWithLocales","localesSuffix","tables","id","withSelect","order","parent","blocks","block","blockKey","slug","withBlock","tableName"],"mappings":"AAAA,oCAAoC,GAGpC,SAASA,gBAAgB,EAAEC,UAAU,QAAQ,iBAAgB;AAC7D,OAAOC,iBAAiB,gBAAe;AAiBvC,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,QAAQ,EACRC,OAAO,EACPC,WAAW,EACXC,gBAAgB,EAChBC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,YAAY,EACZC,iBAAiB,EACC;IAClBH,OAAOI,OAAO,CAAC,CAACC;QACd,6BAA6B;QAC7B,IACEN,QAAQ,KACPM,CAAAA,MAAMC,IAAI,KAAK,YACbD,MAAMC,IAAI,KAAK,kBAAkB,CAACD,MAAME,OAAO,IAAI,OAAOF,MAAMG,UAAU,KAAK,QAAQ,GAC1F;YACA,IAAIH,MAAMI,SAAS,EAAE;gBACnBd,SAASe,IAAI,CAAC,CAAC,EAAET,KAAK,EAAEI,MAAMM,IAAI,CAAC,CAAC,CAAC,GAAG;YAC1C,OAAO;gBACLd,YAAYa,IAAI,CAAC,CAAC,EAAET,KAAK,EAAEI,MAAMM,IAAI,CAAC,CAAC,CAAC,GAAG;YAC7C;QACF;QAEA,IAAIN,MAAMC,IAAI,KAAK,iBAAiBD,MAAMC,IAAI,KAAK,OAAO;YACxDZ,eAAe;gBACbC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,QAAQK,MAAML,MAAM;gBACpBC;gBACAC;gBACAC;YACF;YAEA;QACF;QAEA,IAAIE,MAAMC,IAAI,KAAK,QAAQ;YACzBD,MAAMO,IAAI,CAACR,OAAO,CAAC,CAACS;gBAClB,MAAMC,UAAUtB,WAAWqB,OAAO,CAAC,EAAEZ,KAAK,EAAEY,IAAIF,IAAI,CAAC,CAAC,CAAC,GAAGV;gBAE1DP,eAAe;oBACbC;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F;oBAEA;gBAEF;oBAAS;wBACP;oBACF;YACF;QACF;IACF;IAEA,OAAOD;AACT,EAAC"}
package/dist/find.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { Find } from 'payload';
2
- export declare const find: Find;
3
- //# sourceMappingURL=find.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAqD,MAAM,SAAS,CAAA;AAQtF,eAAO,MAAM,IAAI,EAAE,IA8BlB,CAAA"}
package/dist/find.js DELETED
@@ -1,21 +0,0 @@
1
- import toSnakeCase from 'to-snake-case';
2
- import { findMany } from './find/findMany.js';
3
- export const find = async function find({ collection, limit, locale, page = 1, pagination, req = {}, sort: sortArg, where }) {
4
- const collectionConfig = this.payload.collections[collection].config;
5
- const sort = typeof sortArg === 'string' ? sortArg : collectionConfig.defaultSort;
6
- const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug));
7
- return findMany({
8
- adapter: this,
9
- fields: collectionConfig.fields,
10
- limit,
11
- locale,
12
- page,
13
- pagination,
14
- req,
15
- sort,
16
- tableName,
17
- where
18
- });
19
- };
20
-
21
- //# sourceMappingURL=find.js.map
package/dist/find.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { Find, PayloadRequestWithData, SanitizedCollectionConfig } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const find: Find = async function find(\n this: PostgresAdapter,\n {\n collection,\n limit,\n locale,\n page = 1,\n pagination,\n req = {} as PayloadRequestWithData,\n sort: sortArg,\n where,\n },\n) {\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n const sort = typeof sortArg === 'string' ? sortArg : collectionConfig.defaultSort\n\n const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug))\n\n return findMany({\n adapter: this,\n fields: collectionConfig.fields,\n limit,\n locale,\n page,\n pagination,\n req,\n sort,\n tableName,\n where,\n })\n}\n"],"names":["toSnakeCase","findMany","find","collection","limit","locale","page","pagination","req","sort","sortArg","where","collectionConfig","payload","collections","config","defaultSort","tableName","tableNameMap","get","slug","adapter","fields"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,OAAa,eAAeA,KAEvC,EACEC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,OAAO,CAAC,EACRC,UAAU,EACVC,MAAM,CAAC,CAA2B,EAClCC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACX,WAAW,CAACY,MAAM;IAC/F,MAAMN,OAAO,OAAOC,YAAY,WAAWA,UAAUE,iBAAiBI,WAAW;IAEjF,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACnB,YAAYY,iBAAiBQ,IAAI;IAEzE,OAAOnB,SAAS;QACdoB,SAAS,IAAI;QACbC,QAAQV,iBAAiBU,MAAM;QAC/BlB;QACAC;QACAC;QACAC;QACAC;QACAC;QACAQ;QACAN;IACF;AACF,EAAC"}
@@ -1,3 +0,0 @@
1
- import type { FindGlobal } from 'payload';
2
- export declare const findGlobal: FindGlobal;
3
- //# sourceMappingURL=findGlobal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAQzC,eAAO,MAAM,UAAU,EAAE,UA2BxB,CAAA"}
@@ -1,23 +0,0 @@
1
- import toSnakeCase from 'to-snake-case';
2
- import { findMany } from './find/findMany.js';
3
- export const findGlobal = async function findGlobal({ slug, locale, req, where }) {
4
- const globalConfig = this.payload.globals.config.find((config)=>config.slug === slug);
5
- const tableName = this.tableNameMap.get(toSnakeCase(globalConfig.slug));
6
- const { docs: [doc] } = await findMany({
7
- adapter: this,
8
- fields: globalConfig.fields,
9
- limit: 1,
10
- locale,
11
- pagination: false,
12
- req,
13
- tableName,
14
- where
15
- });
16
- if (doc) {
17
- doc.globalType = slug;
18
- return doc;
19
- }
20
- return {};
21
- };
22
-
23
- //# sourceMappingURL=findGlobal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: PostgresAdapter,\n { slug, locale, req, where },\n) {\n const globalConfig = this.payload.globals.config.find((config) => config.slug === slug)\n\n const tableName = this.tableNameMap.get(toSnakeCase(globalConfig.slug))\n\n const {\n docs: [doc],\n } = await findMany({\n adapter: this,\n fields: globalConfig.fields,\n limit: 1,\n locale,\n pagination: false,\n req,\n tableName,\n where,\n })\n\n if (doc) {\n doc.globalType = slug\n return doc\n }\n\n return {}\n}\n"],"names":["toSnakeCase","findMany","findGlobal","slug","locale","req","where","globalConfig","payload","globals","config","find","tableName","tableNameMap","get","docs","doc","adapter","fields","limit","pagination","globalType"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAE5B,MAAMC,eAAe,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOP,IAAI,KAAKA;IAElF,MAAMS,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACd,YAAYO,aAAaJ,IAAI;IAErE,MAAM,EACJY,MAAM,CAACC,IAAI,EACZ,GAAG,MAAMf,SAAS;QACjBgB,SAAS,IAAI;QACbC,QAAQX,aAAaW,MAAM;QAC3BC,OAAO;QACPf;QACAgB,YAAY;QACZf;QACAO;QACAN;IACF;IAEA,IAAIU,KAAK;QACPA,IAAIK,UAAU,GAAGlB;QACjB,OAAOa;IACT;IAEA,OAAO,CAAC;AACV,EAAC"}
@@ -1,3 +0,0 @@
1
- import type { FindGlobalVersions } from 'payload';
2
- export declare const findGlobalVersions: FindGlobalVersions;
3
- //# sourceMappingURL=findGlobalVersions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAiD,MAAM,SAAS,CAAA;AAShG,eAAO,MAAM,kBAAkB,EAAE,kBAsChC,CAAA"}
@@ -1,24 +0,0 @@
1
- import { buildVersionGlobalFields } from 'payload';
2
- import toSnakeCase from 'to-snake-case';
3
- import { findMany } from './find/findMany.js';
4
- export const findGlobalVersions = async function findGlobalVersions({ global, limit, locale, page, pagination, req = {}, skip, sort: sortArg, where }) {
5
- const globalConfig = this.payload.globals.config.find(({ slug })=>slug === global);
6
- const sort = typeof sortArg === 'string' ? sortArg : '-createdAt';
7
- const tableName = this.tableNameMap.get(`_${toSnakeCase(globalConfig.slug)}${this.versionsSuffix}`);
8
- const fields = buildVersionGlobalFields(globalConfig);
9
- return findMany({
10
- adapter: this,
11
- fields,
12
- limit,
13
- locale,
14
- page,
15
- pagination,
16
- req,
17
- skip,
18
- sort,
19
- tableName,
20
- where
21
- });
22
- };
23
-
24
- //# sourceMappingURL=findGlobalVersions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { FindGlobalVersions, PayloadRequestWithData, SanitizedGlobalConfig } from 'payload'\n\nimport { buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: PostgresAdapter,\n {\n global,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequestWithData,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const globalConfig: SanitizedGlobalConfig = this.payload.globals.config.find(\n ({ slug }) => slug === global,\n )\n const sort = typeof sortArg === 'string' ? sortArg : '-createdAt'\n\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(globalConfig.slug)}${this.versionsSuffix}`,\n )\n\n const fields = buildVersionGlobalFields(globalConfig)\n\n return findMany({\n adapter: this,\n fields,\n limit,\n locale,\n page,\n pagination,\n req,\n skip,\n sort,\n tableName,\n where,\n })\n}\n"],"names":["buildVersionGlobalFields","toSnakeCase","findMany","findGlobalVersions","global","limit","locale","page","pagination","req","skip","sort","sortArg","where","globalConfig","payload","globals","config","find","slug","tableName","tableNameMap","get","versionsSuffix","fields","adapter"],"mappings":"AAEA,SAASA,wBAAwB,QAAQ,UAAS;AAClD,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EACEC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAA2B,EAClCC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,eAAsC,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAC1E,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASf;IAEzB,MAAMO,OAAO,OAAOC,YAAY,WAAWA,UAAU;IAErD,MAAMQ,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAErB,YAAYa,aAAaK,IAAI,EAAE,EAAE,IAAI,CAACI,cAAc,CAAC,CAAC;IAG5D,MAAMC,SAASxB,yBAAyBc;IAExC,OAAOZ,SAAS;QACduB,SAAS,IAAI;QACbD;QACAnB;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAS;QACAP;IACF;AACF,EAAC"}
package/dist/findOne.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type { FindOneArgs, TypeWithID } from 'payload';
2
- import type { PostgresAdapter } from './types.js';
3
- export declare function findOne<T extends TypeWithID>(this: PostgresAdapter, { collection, locale, req, where }: FindOneArgs): Promise<T>;
4
- //# sourceMappingURL=findOne.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EAGX,UAAU,EACX,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAIjD,wBAAsB,OAAO,CAAC,CAAC,SAAS,UAAU,EAChD,IAAI,EAAE,eAAe,EACrB,EAAE,UAAU,EAAE,MAAM,EAAE,GAAkC,EAAE,KAAK,EAAE,EAAE,WAAW,GAC7E,OAAO,CAAC,CAAC,CAAC,CAmBZ"}
package/dist/findOne.js DELETED
@@ -1,21 +0,0 @@
1
- import toSnakeCase from 'to-snake-case';
2
- import { findMany } from './find/findMany.js';
3
- export async function findOne({ collection, locale, req = {}, where }) {
4
- const collectionConfig = this.payload.collections[collection].config;
5
- const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug));
6
- const { docs } = await findMany({
7
- adapter: this,
8
- fields: collectionConfig.fields,
9
- limit: 1,
10
- locale,
11
- page: 1,
12
- pagination: false,
13
- req,
14
- sort: undefined,
15
- tableName,
16
- where
17
- });
18
- return docs?.[0] || null;
19
- }
20
-
21
- //# sourceMappingURL=findOne.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type {\n FindOneArgs,\n PayloadRequestWithData,\n SanitizedCollectionConfig,\n TypeWithID,\n} from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport async function findOne<T extends TypeWithID>(\n this: PostgresAdapter,\n { collection, locale, req = {} as PayloadRequestWithData, where }: FindOneArgs,\n): Promise<T> {\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n\n const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug))\n\n const { docs } = await findMany({\n adapter: this,\n fields: collectionConfig.fields,\n limit: 1,\n locale,\n page: 1,\n pagination: false,\n req,\n sort: undefined,\n tableName,\n where,\n })\n\n return docs?.[0] || null\n}\n"],"names":["toSnakeCase","findMany","findOne","collection","locale","req","where","collectionConfig","payload","collections","config","tableName","tableNameMap","get","slug","docs","adapter","fields","limit","page","pagination","sort","undefined"],"mappings":"AAOA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,eAAeC,QAEpB,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAA2B,EAAEC,KAAK,EAAe;IAE9E,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACN,WAAW,CAACO,MAAM;IAE/F,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACb,YAAYO,iBAAiBO,IAAI;IAEzE,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAMd,SAAS;QAC9Be,SAAS,IAAI;QACbC,QAAQV,iBAAiBU,MAAM;QAC/BC,OAAO;QACPd;QACAe,MAAM;QACNC,YAAY;QACZf;QACAgB,MAAMC;QACNX;QACAL;IACF;IAEA,OAAOS,MAAM,CAAC,EAAE,IAAI;AACtB"}
@@ -1,3 +0,0 @@
1
- import type { FindVersions } from 'payload';
2
- export declare const findVersions: FindVersions;
3
- //# sourceMappingURL=findVersions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAqD,MAAM,SAAS,CAAA;AAS9F,eAAO,MAAM,YAAY,EAAE,YAoC1B,CAAA"}
@@ -1,24 +0,0 @@
1
- import { buildVersionCollectionFields } from 'payload';
2
- import toSnakeCase from 'to-snake-case';
3
- import { findMany } from './find/findMany.js';
4
- export const findVersions = async function findVersions({ collection, limit, locale, page, pagination, req = {}, skip, sort: sortArg, where }) {
5
- const collectionConfig = this.payload.collections[collection].config;
6
- const sort = typeof sortArg === 'string' ? sortArg : collectionConfig.defaultSort;
7
- const tableName = this.tableNameMap.get(`_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`);
8
- const fields = buildVersionCollectionFields(collectionConfig);
9
- return findMany({
10
- adapter: this,
11
- fields,
12
- limit,
13
- locale,
14
- page,
15
- pagination,
16
- req,
17
- skip,
18
- sort,
19
- tableName,
20
- where
21
- });
22
- };
23
-
24
- //# sourceMappingURL=findVersions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { FindVersions, PayloadRequestWithData, SanitizedCollectionConfig } from 'payload'\n\nimport { buildVersionCollectionFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: PostgresAdapter,\n {\n collection,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequestWithData,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n const sort = typeof sortArg === 'string' ? sortArg : collectionConfig.defaultSort\n\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`,\n )\n\n const fields = buildVersionCollectionFields(collectionConfig)\n\n return findMany({\n adapter: this,\n fields,\n limit,\n locale,\n page,\n pagination,\n req,\n skip,\n sort,\n tableName,\n where,\n })\n}\n"],"names":["buildVersionCollectionFields","toSnakeCase","findMany","findVersions","collection","limit","locale","page","pagination","req","skip","sort","sortArg","where","collectionConfig","payload","collections","config","defaultSort","tableName","tableNameMap","get","slug","versionsSuffix","fields","adapter"],"mappings":"AAEA,SAASA,4BAA4B,QAAQ,UAAS;AACtD,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EACEC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAA2B,EAClCC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACZ,WAAW,CAACa,MAAM;IAC/F,MAAMN,OAAO,OAAOC,YAAY,WAAWA,UAAUE,iBAAiBI,WAAW;IAEjF,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAEpB,YAAYa,iBAAiBQ,IAAI,EAAE,EAAE,IAAI,CAACC,cAAc,CAAC,CAAC;IAGhE,MAAMC,SAASxB,6BAA6Bc;IAE5C,OAAOZ,SAAS;QACduB,SAAS,IAAI;QACbD;QACAnB;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAQ;QACAN;IACF;AACF,EAAC"}
package/dist/init.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { Init } from 'payload';
2
- export declare const init: Init;
3
- //# sourceMappingURL=init.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAWnC,eAAO,MAAM,IAAI,EAAE,IA6FlB,CAAA"}
package/dist/init.js DELETED
@@ -1,91 +0,0 @@
1
- /* eslint-disable no-param-reassign */ import { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core';
2
- import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
3
- import toSnakeCase from 'to-snake-case';
4
- import { buildTable } from './schema/build.js';
5
- import { createTableName } from './schema/createTableName.js';
6
- export const init = function init() {
7
- if (this.schemaName) {
8
- this.pgSchema = pgSchema(this.schemaName);
9
- } else {
10
- this.pgSchema = {
11
- table: pgTable
12
- };
13
- }
14
- if (this.payload.config.localization) {
15
- this.enums.enum__locales = pgEnum('_locales', this.payload.config.localization.locales.map(({ code })=>code));
16
- }
17
- this.payload.config.collections.forEach((collection)=>{
18
- createTableName({
19
- adapter: this,
20
- config: collection
21
- });
22
- if (collection.versions) {
23
- createTableName({
24
- adapter: this,
25
- config: collection,
26
- versions: true,
27
- versionsCustomName: true
28
- });
29
- }
30
- });
31
- this.payload.config.collections.forEach((collection)=>{
32
- const tableName = this.tableNameMap.get(toSnakeCase(collection.slug));
33
- buildTable({
34
- adapter: this,
35
- disableNotNull: !!collection?.versions?.drafts,
36
- disableUnique: false,
37
- fields: collection.fields,
38
- tableName,
39
- timestamps: collection.timestamps,
40
- versions: false
41
- });
42
- if (collection.versions) {
43
- const versionsTableName = this.tableNameMap.get(`_${toSnakeCase(collection.slug)}${this.versionsSuffix}`);
44
- const versionFields = buildVersionCollectionFields(collection);
45
- buildTable({
46
- adapter: this,
47
- disableNotNull: !!collection.versions?.drafts,
48
- disableUnique: true,
49
- fields: versionFields,
50
- tableName: versionsTableName,
51
- timestamps: true,
52
- versions: true
53
- });
54
- }
55
- });
56
- this.payload.config.globals.forEach((global)=>{
57
- const tableName = createTableName({
58
- adapter: this,
59
- config: global
60
- });
61
- buildTable({
62
- adapter: this,
63
- disableNotNull: !!global?.versions?.drafts,
64
- disableUnique: false,
65
- fields: global.fields,
66
- tableName,
67
- timestamps: false,
68
- versions: false
69
- });
70
- if (global.versions) {
71
- const versionsTableName = createTableName({
72
- adapter: this,
73
- config: global,
74
- versions: true,
75
- versionsCustomName: true
76
- });
77
- const versionFields = buildVersionGlobalFields(global);
78
- buildTable({
79
- adapter: this,
80
- disableNotNull: !!global.versions?.drafts,
81
- disableUnique: true,
82
- fields: versionFields,
83
- tableName: versionsTableName,
84
- timestamps: true,
85
- versions: true
86
- });
87
- }
88
- });
89
- };
90
-
91
- //# sourceMappingURL=init.js.map
package/dist/init.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/init.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { SanitizedCollectionConfig } from 'payload'\nimport type { Init } from 'payload'\n\nimport { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { buildTable } from './schema/build.js'\nimport { createTableName } from './schema/createTableName.js'\n\nexport const init: Init = function init(this: PostgresAdapter) {\n if (this.schemaName) {\n this.pgSchema = pgSchema(this.schemaName)\n } else {\n this.pgSchema = { table: pgTable }\n }\n\n if (this.payload.config.localization) {\n this.enums.enum__locales = pgEnum(\n '_locales',\n this.payload.config.localization.locales.map(({ code }) => code) as [string, ...string[]],\n )\n }\n\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n createTableName({\n adapter: this,\n config: collection,\n })\n\n if (collection.versions) {\n createTableName({\n adapter: this,\n config: collection,\n versions: true,\n versionsCustomName: true,\n })\n }\n })\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n\n buildTable({\n adapter: this,\n disableNotNull: !!collection?.versions?.drafts,\n disableUnique: false,\n fields: collection.fields,\n tableName,\n timestamps: collection.timestamps,\n versions: false,\n })\n\n if (collection.versions) {\n const versionsTableName = this.tableNameMap.get(\n `_${toSnakeCase(collection.slug)}${this.versionsSuffix}`,\n )\n const versionFields = buildVersionCollectionFields(collection)\n\n buildTable({\n adapter: this,\n disableNotNull: !!collection.versions?.drafts,\n disableUnique: true,\n fields: versionFields,\n tableName: versionsTableName,\n timestamps: true,\n versions: true,\n })\n }\n })\n\n this.payload.config.globals.forEach((global) => {\n const tableName = createTableName({ adapter: this, config: global })\n\n buildTable({\n adapter: this,\n disableNotNull: !!global?.versions?.drafts,\n disableUnique: false,\n fields: global.fields,\n tableName,\n timestamps: false,\n versions: false,\n })\n\n if (global.versions) {\n const versionsTableName = createTableName({\n adapter: this,\n config: global,\n versions: true,\n versionsCustomName: true,\n })\n const versionFields = buildVersionGlobalFields(global)\n\n buildTable({\n adapter: this,\n disableNotNull: !!global.versions?.drafts,\n disableUnique: true,\n fields: versionFields,\n tableName: versionsTableName,\n timestamps: true,\n versions: true,\n })\n }\n })\n}\n"],"names":["pgEnum","pgSchema","pgTable","buildVersionCollectionFields","buildVersionGlobalFields","toSnakeCase","buildTable","createTableName","init","schemaName","table","payload","config","localization","enums","enum__locales","locales","map","code","collections","forEach","collection","adapter","versions","versionsCustomName","tableName","tableNameMap","get","slug","disableNotNull","drafts","disableUnique","fields","timestamps","versionsTableName","versionsSuffix","versionFields","globals","global"],"mappings":"AAAA,oCAAoC,GAIpC,SAASA,MAAM,EAAEC,QAAQ,EAAEC,OAAO,QAAQ,sBAAqB;AAC/D,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAChF,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,SAASC,eAAe,QAAQ,8BAA6B;AAE7D,OAAO,MAAMC,OAAa,SAASA;IACjC,IAAI,IAAI,CAACC,UAAU,EAAE;QACnB,IAAI,CAACR,QAAQ,GAAGA,SAAS,IAAI,CAACQ,UAAU;IAC1C,OAAO;QACL,IAAI,CAACR,QAAQ,GAAG;YAAES,OAAOR;QAAQ;IACnC;IAEA,IAAI,IAAI,CAACS,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;QACpC,IAAI,CAACC,KAAK,CAACC,aAAa,GAAGf,OACzB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W;YACTgB,SAAS,IAAI;YACbO,gBAAgB,CAAC,CAACS,QAAQf,UAAUO;YACpCC,eAAe;YACfC,QAAQM,OAAON,MAAM;YACrBP;YACAQ,YAAY;YACZV,UAAU;QACZ;QAEA,IAAIe,OAAOf,QAAQ,EAAE;YACnB,MAAMW,oBAAoB3B,gBAAgB;gBACxCe,SAAS,IAAI;gBACbV,QAAQ0B;gBACRf,UAAU;gBACVC,oBAAoB;YACtB;YACA,MAAMY,gBAAgBhC,yBAAyBkC;YAE/ChC,WAAW;gBACTgB,SAAS,IAAI;gBACbO,gBAAgB,CAAC,CAACS,OAAOf,QAAQ,EAAEO;gBACnCC,eAAe;gBACfC,QAAQI;gBACRX,WAAWS;gBACXD,YAAY;gBACZV,UAAU;YACZ;QACF;IACF;AACF,EAAC"}
package/dist/migrate.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { PostgresAdapter } from './types.js';
2
- export declare function migrate(this: PostgresAdapter): Promise<void>;
3
- //# sourceMappingURL=migrate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAQjD,wBAAsB,OAAO,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CA8DlE"}
package/dist/migrate.js DELETED
@@ -1,99 +0,0 @@
1
- /* eslint-disable no-restricted-syntax, no-await-in-loop */ import { createRequire } from 'module';
2
- import { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload';
3
- import prompts from 'prompts';
4
- import { createMigrationTable } from './utilities/createMigrationTable.js';
5
- import { migrationTableExists } from './utilities/migrationTableExists.js';
6
- import { parseError } from './utilities/parseError.js';
7
- const require = createRequire(import.meta.url);
8
- export async function migrate() {
9
- const { payload } = this;
10
- const migrationFiles = await readMigrationFiles({
11
- payload
12
- });
13
- if (!migrationFiles.length) {
14
- payload.logger.info({
15
- msg: 'No migrations to run.'
16
- });
17
- return;
18
- }
19
- let latestBatch = 0;
20
- let migrationsInDB = [];
21
- const hasMigrationTable = await migrationTableExists(this.drizzle);
22
- if (hasMigrationTable) {
23
- ({ docs: migrationsInDB } = await payload.find({
24
- collection: 'payload-migrations',
25
- limit: 0,
26
- sort: '-name'
27
- }));
28
- if (Number(migrationsInDB?.[0]?.batch) > 0) {
29
- latestBatch = Number(migrationsInDB[0]?.batch);
30
- }
31
- } else {
32
- await createMigrationTable(this);
33
- }
34
- if (migrationsInDB.find((m)=>m.batch === -1)) {
35
- const { confirm: runMigrations } = await prompts({
36
- name: 'confirm',
37
- type: 'confirm',
38
- initial: false,
39
- message: "It looks like you've run Payload in dev mode, meaning you've dynamically pushed changes to your database.\n\n" + "If you'd like to run migrations, data loss will occur. Would you like to proceed?"
40
- }, {
41
- onCancel: ()=>{
42
- process.exit(0);
43
- }
44
- });
45
- if (!runMigrations) {
46
- process.exit(0);
47
- }
48
- }
49
- const newBatch = latestBatch + 1;
50
- // Execute 'up' function for each migration sequentially
51
- for (const migration of migrationFiles){
52
- const alreadyRan = migrationsInDB.find((existing)=>existing.name === migration.name);
53
- // If already ran, skip
54
- if (alreadyRan) {
55
- continue; // eslint-disable-line no-continue
56
- }
57
- await runMigrationFile(payload, migration, newBatch);
58
- }
59
- }
60
- async function runMigrationFile(payload, migration, batch) {
61
- const { generateDrizzleJson } = require('drizzle-kit/payload');
62
- const start = Date.now();
63
- const req = {
64
- payload
65
- };
66
- payload.logger.info({
67
- msg: `Migrating: ${migration.name}`
68
- });
69
- const pgAdapter = payload.db;
70
- const drizzleJSON = generateDrizzleJson(pgAdapter.schema);
71
- try {
72
- await initTransaction(req);
73
- await migration.up({
74
- payload,
75
- req
76
- });
77
- payload.logger.info({
78
- msg: `Migrated: ${migration.name} (${Date.now() - start}ms)`
79
- });
80
- await payload.create({
81
- collection: 'payload-migrations',
82
- data: {
83
- name: migration.name,
84
- batch,
85
- schema: drizzleJSON
86
- },
87
- req
88
- });
89
- await commitTransaction(req);
90
- } catch (err) {
91
- await killTransaction(req);
92
- payload.logger.error({
93
- err,
94
- msg: parseError(err, `Error running migration ${migration.name}`)
95
- });
96
- }
97
- }
98
-
99
- //# sourceMappingURL=migrate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/migrate.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { Payload } from 'payload'\nimport type { PayloadRequestWithData } from 'payload'\nimport type { Migration } from 'payload'\n\nimport { createRequire } from 'module'\nimport { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload'\nimport prompts from 'prompts'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { createMigrationTable } from './utilities/createMigrationTable.js'\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\nimport { parseError } from './utilities/parseError.js'\n\nconst require = createRequire(import.meta.url)\n\nexport async function migrate(this: PostgresAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n if (!migrationFiles.length) {\n payload.logger.info({ msg: 'No migrations to run.' })\n return\n }\n\n let latestBatch = 0\n let migrationsInDB = []\n\n const hasMigrationTable = await migrationTableExists(this.drizzle)\n\n if (hasMigrationTable) {\n ;({ docs: migrationsInDB } = await payload.find({\n collection: 'payload-migrations',\n limit: 0,\n sort: '-name',\n }))\n if (Number(migrationsInDB?.[0]?.batch) > 0) {\n latestBatch = Number(migrationsInDB[0]?.batch)\n }\n } else {\n await createMigrationTable(this)\n }\n\n if (migrationsInDB.find((m) => m.batch === -1)) {\n const { confirm: runMigrations } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message:\n \"It looks like you've run Payload in dev mode, meaning you've dynamically pushed changes to your database.\\n\\n\" +\n \"If you'd like to run migrations, data loss will occur. Would you like to proceed?\",\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!runMigrations) {\n process.exit(0)\n }\n }\n\n const newBatch = latestBatch + 1\n\n // Execute 'up' function for each migration sequentially\n for (const migration of migrationFiles) {\n const alreadyRan = migrationsInDB.find((existing) => existing.name === migration.name)\n\n // If already ran, skip\n if (alreadyRan) {\n continue // eslint-disable-line no-continue\n }\n\n await runMigrationFile(payload, migration, newBatch)\n }\n}\n\nasync function runMigrationFile(payload: Payload, migration: Migration, batch: number) {\n const { generateDrizzleJson } = require('drizzle-kit/payload')\n\n const start = Date.now()\n const req = { payload } as PayloadRequestWithData\n\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n\n const pgAdapter = payload.db\n const drizzleJSON = generateDrizzleJson(pgAdapter.schema)\n\n try {\n await initTransaction(req)\n await migration.up({ payload, req })\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n batch,\n schema: drizzleJSON,\n },\n req,\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}`),\n })\n }\n}\n"],"names":["createRequire","commitTransaction","initTransaction","killTransaction","readMigrationFiles","prompts","createMigrationTable","migrationTableExists","parseError","require","url","migrate","payload","migrationFiles","length","logger","info","msg","latestBatch","migrationsInDB","hasMigrationTable","drizzle","docs","find","collection","limit","sort","Number","batch","m","confirm","runMigrations","name","type","initial","message","onCancel","process","exit","newBatch","migration","alreadyRan","existing","runMigrationFile","generateDrizzleJson","start","Date","now","req","pgAdapter","db","drizzleJSON","schema","up","create","data","err","error"],"mappings":"AAAA,yDAAyD,GAKzD,SAASA,aAAa,QAAQ,SAAQ;AACtC,SAASC,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,EAAEC,kBAAkB,QAAQ,UAAS;AACjG,OAAOC,aAAa,UAAS;AAI7B,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,MAAMC,U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7C;AACF;AAEA,eAAeI,iBAAiB/B,OAAgB,EAAE4B,SAAoB,EAAEZ,KAAa;IACnF,MAAM,EAAEgB,mBAAmB,EAAE,GAAGnC,QAAQ;IAExC,MAAMoC,QAAQC,KAAKC,GAAG;IACtB,MAAMC,MAAM;QAAEpC;IAAQ;IAEtBA,QAAQG,MAAM,CAACC,IAAI,CAAC;QAAEC,KAAK,CAAC,WAAW,EAAEuB,UAAUR,IAAI,CAAC,CAAC;IAAC;IAE1D,MAAMiB,YAAYrC,QAAQsC,EAAE;IAC5B,MAAMC,cAAcP,oBAAoBK,UAAUG,MAAM;IAExD,IAAI;QACF,MAAMlD,gBAAgB8C;QACtB,MAAMR,UAAUa,EAAE,CAAC;YAAEzC;YAASoC;QAAI;QAClCpC,QAAQG,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK,CAAC,WAAW,EAAEuB,UAAUR,IAAI,CAAC,EAAE,EAAEc,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;QAAC;QACpF,MAAMjC,QAAQ0C,MAAM,CAAC;YACnB9B,YAAY;YACZ+B,MAAM;gBACJvB,MAAMQ,UAAUR,IAAI;gBACpBJ;gBACAwB,QAAQD;YACV;YACAH;QACF;QACA,MAAM/C,kBAAkB+C;IAC1B,EAAE,OAAOQ,KAAc;QACrB,MAAMrD,gBAAgB6C;QACtBpC,QAAQG,MAAM,CAAC0C,KAAK,CAAC;YACnBD;YACAvC,KAAKT,WAAWgD,KAAK,CAAC,wBAAwB,EAAEhB,UAAUR,IAAI,CAAC,CAAC;QAClE;IACF;AACF"}
@@ -1,3 +0,0 @@
1
- import type { PostgresAdapter } from './types.js';
2
- export declare function migrateDown(this: PostgresAdapter): Promise<void>;
3
- //# sourceMappingURL=migrateDown.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrateDown.d.ts","sourceRoot":"","sources":["../src/migrateDown.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAKjD,wBAAsB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAwDtE"}