@payloadcms/db-postgres 3.0.0-canary.c13f9ba → 3.0.0-canary.ce278e4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) hide show
  1. package/README.md +1 -1
  2. package/dist/connect.d.ts +1 -1
  3. package/dist/connect.d.ts.map +1 -1
  4. package/dist/connect.js.map +1 -1
  5. package/dist/count.d.ts +1 -1
  6. package/dist/count.d.ts.map +1 -1
  7. package/dist/count.js.map +1 -1
  8. package/dist/create.d.ts +1 -1
  9. package/dist/create.d.ts.map +1 -1
  10. package/dist/create.js.map +1 -1
  11. package/dist/createGlobal.d.ts +1 -2
  12. package/dist/createGlobal.d.ts.map +1 -1
  13. package/dist/createGlobal.js.map +1 -1
  14. package/dist/createGlobalVersion.d.ts +2 -3
  15. package/dist/createGlobalVersion.d.ts.map +1 -1
  16. package/dist/createGlobalVersion.js +1 -1
  17. package/dist/createGlobalVersion.js.map +1 -1
  18. package/dist/createMigration.d.ts +1 -1
  19. package/dist/createMigration.d.ts.map +1 -1
  20. package/dist/createMigration.js +3 -3
  21. package/dist/createMigration.js.map +1 -1
  22. package/dist/createVersion.d.ts +1 -2
  23. package/dist/createVersion.d.ts.map +1 -1
  24. package/dist/createVersion.js +1 -1
  25. package/dist/createVersion.js.map +1 -1
  26. package/dist/deleteMany.d.ts +1 -1
  27. package/dist/deleteMany.d.ts.map +1 -1
  28. package/dist/deleteMany.js.map +1 -1
  29. package/dist/deleteOne.d.ts +1 -1
  30. package/dist/deleteOne.d.ts.map +1 -1
  31. package/dist/deleteOne.js.map +1 -1
  32. package/dist/deleteVersions.d.ts +1 -1
  33. package/dist/deleteVersions.d.ts.map +1 -1
  34. package/dist/deleteVersions.js +1 -1
  35. package/dist/deleteVersions.js.map +1 -1
  36. package/dist/destroy.d.ts +1 -1
  37. package/dist/destroy.d.ts.map +1 -1
  38. package/dist/destroy.js.map +1 -1
  39. package/dist/find/buildFindManyArgs.d.ts +1 -1
  40. package/dist/find/buildFindManyArgs.d.ts.map +1 -1
  41. package/dist/find/buildFindManyArgs.js.map +1 -1
  42. package/dist/find/findMany.d.ts +1 -2
  43. package/dist/find/findMany.d.ts.map +1 -1
  44. package/dist/find/findMany.js.map +1 -1
  45. package/dist/find/traverseFields.d.ts +1 -1
  46. package/dist/find/traverseFields.d.ts.map +1 -1
  47. package/dist/find/traverseFields.js +1 -1
  48. package/dist/find/traverseFields.js.map +1 -1
  49. package/dist/find.d.ts +1 -1
  50. package/dist/find.d.ts.map +1 -1
  51. package/dist/find.js.map +1 -1
  52. package/dist/findGlobal.d.ts +1 -1
  53. package/dist/findGlobal.d.ts.map +1 -1
  54. package/dist/findGlobal.js.map +1 -1
  55. package/dist/findGlobalVersions.d.ts +1 -1
  56. package/dist/findGlobalVersions.d.ts.map +1 -1
  57. package/dist/findGlobalVersions.js +1 -1
  58. package/dist/findGlobalVersions.js.map +1 -1
  59. package/dist/findOne.d.ts +1 -2
  60. package/dist/findOne.d.ts.map +1 -1
  61. package/dist/findOne.js.map +1 -1
  62. package/dist/findVersions.d.ts +1 -1
  63. package/dist/findVersions.d.ts.map +1 -1
  64. package/dist/findVersions.js +1 -1
  65. package/dist/findVersions.js.map +1 -1
  66. package/dist/index.d.ts +1 -1
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +1 -1
  69. package/dist/index.js.map +1 -1
  70. package/dist/init.d.ts +1 -1
  71. package/dist/init.d.ts.map +1 -1
  72. package/dist/init.js +1 -1
  73. package/dist/init.js.map +1 -1
  74. package/dist/migrate.d.ts.map +1 -1
  75. package/dist/migrate.js +1 -1
  76. package/dist/migrate.js.map +1 -1
  77. package/dist/migrateDown.js +1 -1
  78. package/dist/migrateDown.js.map +1 -1
  79. package/dist/migrateFresh.d.ts.map +1 -1
  80. package/dist/migrateFresh.js +1 -1
  81. package/dist/migrateFresh.js.map +1 -1
  82. package/dist/migrateRefresh.js +1 -1
  83. package/dist/migrateRefresh.js.map +1 -1
  84. package/dist/migrateReset.js +1 -1
  85. package/dist/migrateReset.js.map +1 -1
  86. package/dist/migrateStatus.js +1 -1
  87. package/dist/migrateStatus.js.map +1 -1
  88. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +1 -2
  89. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
  90. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
  91. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +1 -1
  92. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -1
  93. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +1 -1
  94. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -1
  95. package/dist/predefinedMigrations/v2-v3/index.d.ts +2 -3
  96. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -1
  97. package/dist/predefinedMigrations/v2-v3/index.js +5 -5
  98. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -1
  99. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +2 -2
  100. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -1
  101. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +1 -1
  102. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -1
  103. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +1 -2
  104. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -1
  105. package/dist/predefinedMigrations/v2-v3/traverseFields.js +1 -1
  106. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -1
  107. package/dist/queries/buildAndOrConditions.d.ts +1 -1
  108. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  109. package/dist/queries/buildAndOrConditions.js.map +1 -1
  110. package/dist/queries/buildQuery.d.ts +1 -1
  111. package/dist/queries/buildQuery.d.ts.map +1 -1
  112. package/dist/queries/buildQuery.js.map +1 -1
  113. package/dist/queries/getTableColumnFromPath.d.ts +1 -1
  114. package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
  115. package/dist/queries/getTableColumnFromPath.js +2 -3
  116. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  117. package/dist/queries/parseParams.d.ts +1 -1
  118. package/dist/queries/parseParams.d.ts.map +1 -1
  119. package/dist/queries/parseParams.js +2 -2
  120. package/dist/queries/parseParams.js.map +1 -1
  121. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  122. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  123. package/dist/queries/sanitizeQueryValue.js +2 -3
  124. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  125. package/dist/queryDrafts.d.ts +1 -1
  126. package/dist/queryDrafts.d.ts.map +1 -1
  127. package/dist/queryDrafts.js +1 -2
  128. package/dist/queryDrafts.js.map +1 -1
  129. package/dist/schema/build.d.ts +1 -1
  130. package/dist/schema/build.d.ts.map +1 -1
  131. package/dist/schema/build.js.map +1 -1
  132. package/dist/schema/createTableName.d.ts +1 -1
  133. package/dist/schema/createTableName.d.ts.map +1 -1
  134. package/dist/schema/createTableName.js +1 -1
  135. package/dist/schema/createTableName.js.map +1 -1
  136. package/dist/schema/idToUUID.d.ts +1 -1
  137. package/dist/schema/idToUUID.d.ts.map +1 -1
  138. package/dist/schema/idToUUID.js.map +1 -1
  139. package/dist/schema/setColumnID.d.ts +1 -1
  140. package/dist/schema/setColumnID.d.ts.map +1 -1
  141. package/dist/schema/setColumnID.js +2 -2
  142. package/dist/schema/setColumnID.js.map +1 -1
  143. package/dist/schema/traverseFields.d.ts +1 -1
  144. package/dist/schema/traverseFields.d.ts.map +1 -1
  145. package/dist/schema/traverseFields.js +2 -2
  146. package/dist/schema/traverseFields.js.map +1 -1
  147. package/dist/schema/validateExistingBlockIsIdentical.d.ts +1 -1
  148. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +1 -1
  149. package/dist/schema/validateExistingBlockIsIdentical.js +2 -2
  150. package/dist/schema/validateExistingBlockIsIdentical.js.map +1 -1
  151. package/dist/transactions/beginTransaction.d.ts +1 -1
  152. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  153. package/dist/transactions/beginTransaction.js.map +1 -1
  154. package/dist/transactions/commitTransaction.d.ts +1 -1
  155. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  156. package/dist/transactions/commitTransaction.js.map +1 -1
  157. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  158. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  159. package/dist/transactions/rollbackTransaction.js.map +1 -1
  160. package/dist/transform/read/hasManyNumber.d.ts +1 -1
  161. package/dist/transform/read/hasManyNumber.d.ts.map +1 -1
  162. package/dist/transform/read/hasManyNumber.js.map +1 -1
  163. package/dist/transform/read/hasManyText.d.ts +1 -1
  164. package/dist/transform/read/hasManyText.d.ts.map +1 -1
  165. package/dist/transform/read/hasManyText.js.map +1 -1
  166. package/dist/transform/read/index.d.ts +2 -2
  167. package/dist/transform/read/index.d.ts.map +1 -1
  168. package/dist/transform/read/index.js.map +1 -1
  169. package/dist/transform/read/relationship.d.ts +1 -1
  170. package/dist/transform/read/relationship.d.ts.map +1 -1
  171. package/dist/transform/read/relationship.js.map +1 -1
  172. package/dist/transform/read/traverseFields.d.ts +2 -2
  173. package/dist/transform/read/traverseFields.d.ts.map +1 -1
  174. package/dist/transform/read/traverseFields.js +1 -1
  175. package/dist/transform/read/traverseFields.js.map +1 -1
  176. package/dist/transform/write/array.d.ts +1 -1
  177. package/dist/transform/write/array.d.ts.map +1 -1
  178. package/dist/transform/write/array.js.map +1 -1
  179. package/dist/transform/write/blocks.d.ts +1 -1
  180. package/dist/transform/write/blocks.d.ts.map +1 -1
  181. package/dist/transform/write/blocks.js.map +1 -1
  182. package/dist/transform/write/index.d.ts +1 -1
  183. package/dist/transform/write/index.d.ts.map +1 -1
  184. package/dist/transform/write/index.js.map +1 -1
  185. package/dist/transform/write/relationships.d.ts +1 -1
  186. package/dist/transform/write/relationships.d.ts.map +1 -1
  187. package/dist/transform/write/relationships.js +1 -1
  188. package/dist/transform/write/relationships.js.map +1 -1
  189. package/dist/transform/write/traverseFields.d.ts +1 -1
  190. package/dist/transform/write/traverseFields.d.ts.map +1 -1
  191. package/dist/transform/write/traverseFields.js +1 -1
  192. package/dist/transform/write/traverseFields.js.map +1 -1
  193. package/dist/types.d.ts +1 -3
  194. package/dist/types.d.ts.map +1 -1
  195. package/dist/types.js.map +1 -1
  196. package/dist/update.d.ts +1 -1
  197. package/dist/update.d.ts.map +1 -1
  198. package/dist/update.js.map +1 -1
  199. package/dist/updateGlobal.d.ts +1 -2
  200. package/dist/updateGlobal.d.ts.map +1 -1
  201. package/dist/updateGlobal.js.map +1 -1
  202. package/dist/updateGlobalVersion.d.ts +1 -2
  203. package/dist/updateGlobalVersion.d.ts.map +1 -1
  204. package/dist/updateGlobalVersion.js +1 -1
  205. package/dist/updateGlobalVersion.js.map +1 -1
  206. package/dist/updateVersion.d.ts +1 -2
  207. package/dist/updateVersion.d.ts.map +1 -1
  208. package/dist/updateVersion.js +1 -1
  209. package/dist/updateVersion.js.map +1 -1
  210. package/dist/upsertRow/index.d.ts +1 -1
  211. package/dist/upsertRow/index.d.ts.map +1 -1
  212. package/dist/upsertRow/index.js +1 -1
  213. package/dist/upsertRow/index.js.map +1 -1
  214. package/dist/upsertRow/types.d.ts +1 -1
  215. package/dist/upsertRow/types.d.ts.map +1 -1
  216. package/dist/upsertRow/types.js.map +1 -1
  217. package/dist/utilities/hasLocalesTable.d.ts +1 -1
  218. package/dist/utilities/hasLocalesTable.d.ts.map +1 -1
  219. package/dist/utilities/hasLocalesTable.js +1 -1
  220. package/dist/utilities/hasLocalesTable.js.map +1 -1
  221. package/dist/utilities/pushDevSchema.d.ts.map +1 -1
  222. package/dist/utilities/pushDevSchema.js +1 -1
  223. package/dist/utilities/pushDevSchema.js.map +1 -1
  224. package/package.json +10 -7
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { UpdateGlobalArgs } from 'payload/database'\nimport type { PayloadRequestWithData, TypeWithID } from 'payload/types'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\n\nexport async function updateGlobal<T extends TypeWithID>(\n this: PostgresAdapter,\n { slug, data, req = {} as PayloadRequestWithData }: UpdateGlobalArgs,\n): Promise<T> {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const globalConfig = this.payload.globals.config.find((config) => config.slug === slug)\n const tableName = this.tableNameMap.get(toSnakeCase(globalConfig.slug))\n\n const existingGlobal = await db.query[tableName].findFirst({})\n\n const result = await upsertRow<T>({\n ...(existingGlobal ? { id: existingGlobal.id, operation: 'update' } : { operation: 'create' }),\n adapter: this,\n data,\n db,\n fields: globalConfig.fields,\n req,\n tableName,\n })\n\n return result\n}\n"],"names":["toSnakeCase","upsertRow","updateGlobal","slug","data","req","db","sessions","transactionID","drizzle","globalConfig","payload","globals","config","find","tableName","tableNameMap","get","existingGlobal","query","findFirst","result","id","operation","adapter","fields"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,OAAO,eAAeC,aAEpB,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAA2B,EAAoB;IAEpE,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACF,IAAIG,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,eAAe,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOV,IAAI,KAAKA;IAClF,MAAMY,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACjB,YAAYU,aAAaP,IAAI;IAErE,MAAMe,iBAAiB,MAAMZ,GAAGa,KAAK,CAACJ,UAAU,CAACK,SAAS,CAAC,CAAC;IAE5D,MAAMC,SAAS,MAAMpB,UAAa;QAChC,GAAIiB,iBAAiB;YAAEI,IAAIJ,eAAeI,EAAE;YAAEC,WAAW;QAAS,IAAI;YAAEA,WAAW;QAAS,CAAC;QAC7FC,SAAS,IAAI;QACbpB;QACAE;QACAmB,QAAQf,aAAae,MAAM;QAC3BpB;QACAU;IACF;IAEA,OAAOM;AACT"}
1
+ {"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { PayloadRequestWithData, TypeWithID, UpdateGlobalArgs } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\n\nexport async function updateGlobal<T extends TypeWithID>(\n this: PostgresAdapter,\n { slug, data, req = {} as PayloadRequestWithData }: UpdateGlobalArgs,\n): Promise<T> {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const globalConfig = this.payload.globals.config.find((config) => config.slug === slug)\n const tableName = this.tableNameMap.get(toSnakeCase(globalConfig.slug))\n\n const existingGlobal = await db.query[tableName].findFirst({})\n\n const result = await upsertRow<T>({\n ...(existingGlobal ? { id: existingGlobal.id, operation: 'update' } : { operation: 'create' }),\n adapter: this,\n data,\n db,\n fields: globalConfig.fields,\n req,\n tableName,\n })\n\n return result\n}\n"],"names":["toSnakeCase","upsertRow","updateGlobal","slug","data","req","db","sessions","transactionID","drizzle","globalConfig","payload","globals","config","find","tableName","tableNameMap","get","existingGlobal","query","findFirst","result","id","operation","adapter","fields"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,OAAO,eAAeC,aAEpB,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAA2B,EAAoB;IAEpE,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACF,IAAIG,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,eAAe,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOV,IAAI,KAAKA;IAClF,MAAMY,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACjB,YAAYU,aAAaP,IAAI;IAErE,MAAMe,iBAAiB,MAAMZ,GAAGa,KAAK,CAACJ,UAAU,CAACK,SAAS,CAAC,CAAC;IAE5D,MAAMC,SAAS,MAAMpB,UAAa;QAChC,GAAIiB,iBAAiB;YAAEI,IAAIJ,eAAeI,EAAE;YAAEC,WAAW;QAAS,IAAI;YAAEA,WAAW;QAAS,CAAC;QAC7FC,SAAS,IAAI;QACbpB;QACAE;QACAmB,QAAQf,aAAae,MAAM;QAC3BpB;QACAU;IACF;IAEA,OAAOM;AACT"}
@@ -1,5 +1,4 @@
1
- import type { TypeWithVersion, UpdateGlobalVersionArgs } from 'payload/database';
2
- import type { TypeWithID } from 'payload/types';
1
+ import type { TypeWithID, TypeWithVersion, UpdateGlobalVersionArgs } from 'payload';
3
2
  import type { PostgresAdapter } from './types.js';
4
3
  export declare function updateGlobalVersion<T extends TypeWithID>(this: PostgresAdapter, { id, global, locale, req, versionData, where: whereArg, }: UpdateGlobalVersionArgs<T>): Promise<TypeWithVersion<T>>;
5
4
  //# sourceMappingURL=updateGlobalVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAChF,OAAO,KAAK,EAAiD,UAAU,EAAE,MAAM,eAAe,CAAA;AAK9F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAKjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EACN,MAAM,EACN,GAAkC,EAClC,WAAW,EACX,KAAK,EAAE,QAAQ,GAChB,EAAE,uBAAuB,CAAC,CAAC,CAAC,+BAmC9B"}
1
+ {"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,UAAU,EACV,eAAe,EACf,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAKhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAKjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EACN,MAAM,EACN,GAAkC,EAClC,WAAW,EACX,KAAK,EAAE,QAAQ,GAChB,EAAE,uBAAuB,CAAC,CAAC,CAAC,+BAmC9B"}
@@ -1,4 +1,4 @@
1
- import { buildVersionGlobalFields } from 'payload/versions';
1
+ import { buildVersionGlobalFields } from 'payload';
2
2
  import toSnakeCase from 'to-snake-case';
3
3
  import buildQuery from './queries/buildQuery.js';
4
4
  import { upsertRow } from './upsertRow/index.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { TypeWithVersion, UpdateGlobalVersionArgs } from 'payload/database'\nimport type { PayloadRequestWithData, SanitizedGlobalConfig, TypeWithID } from 'payload/types'\n\nimport { buildVersionGlobalFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport buildQuery from './queries/buildQuery.js'\nimport { upsertRow } from './upsertRow/index.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: PostgresAdapter,\n {\n id,\n global,\n locale,\n req = {} as PayloadRequestWithData,\n versionData,\n where: whereArg,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const globalConfig: SanitizedGlobalConfig = this.payload.globals.config.find(\n ({ slug }) => slug === global,\n )\n const whereToUse = whereArg || { id: { equals: id } }\n\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(globalConfig.slug)}${this.versionsSuffix}`,\n )\n\n const fields = buildVersionGlobalFields(globalConfig)\n\n const { where } = await buildQuery({\n adapter: this,\n fields,\n locale,\n tableName,\n where: whereToUse,\n })\n\n const result = await upsertRow<TypeWithVersion<T>>({\n id,\n adapter: this,\n data: versionData,\n db,\n fields,\n operation: 'update',\n req,\n tableName,\n where,\n })\n\n return result\n}\n"],"names":["buildVersionGlobalFields","toSnakeCase","buildQuery","upsertRow","updateGlobalVersion","id","global","locale","req","versionData","where","whereArg","db","sessions","transactionID","drizzle","globalConfig","payload","globals","config","find","slug","whereToUse","equals","tableName","tableNameMap","get","versionsSuffix","fields","adapter","result","data","operation"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,wBAAwB,QAAQ,mBAAkB;AAC3D,OAAOC,iBAAiB,gBAAe;AAIvC,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,MAAM,EACNC,MAAM,EACNC,MAAM,CAAC,CAA2B,EAClCC,WAAW,EACXC,OAAOC,QAAQ,EACY;IAE7B,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACL,IAAIM,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,eAAsC,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAC1E,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASf;IAEzB,MAAMgB,aAAaX,YAAY;QAAEN,IAAI;YAAEkB,QAAQlB;QAAG;IAAE;IAEpD,MAAMmB,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAEzB,YAAYe,aAAaK,IAAI,EAAE,EAAE,IAAI,CAACM,cAAc,CAAC,CAAC;IAG5D,MAAMC,SAAS5B,yBAAyBgB;IAExC,MAAM,EAAEN,KAAK,EAAE,GAAG,MAAMR,WAAW;QACjC2B,SAAS,IAAI;QACbD;QACArB;QACAiB;QACAd,OAAOY;IACT;IAEA,MAAMQ,SAAS,MAAM3B,UAA8B;QACjDE;QACAwB,SAAS,IAAI;QACbE,MAAMtB;QACNG;QACAgB;QACAI,WAAW;QACXxB;QACAgB;QACAd;IACF;IAEA,OAAOoB;AACT"}
1
+ {"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type {\n PayloadRequestWithData,\n SanitizedGlobalConfig,\n TypeWithID,\n TypeWithVersion,\n UpdateGlobalVersionArgs,\n} from 'payload'\n\nimport { buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport buildQuery from './queries/buildQuery.js'\nimport { upsertRow } from './upsertRow/index.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: PostgresAdapter,\n {\n id,\n global,\n locale,\n req = {} as PayloadRequestWithData,\n versionData,\n where: whereArg,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const globalConfig: SanitizedGlobalConfig = this.payload.globals.config.find(\n ({ slug }) => slug === global,\n )\n const whereToUse = whereArg || { id: { equals: id } }\n\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(globalConfig.slug)}${this.versionsSuffix}`,\n )\n\n const fields = buildVersionGlobalFields(globalConfig)\n\n const { where } = await buildQuery({\n adapter: this,\n fields,\n locale,\n tableName,\n where: whereToUse,\n })\n\n const result = await upsertRow<TypeWithVersion<T>>({\n id,\n adapter: this,\n data: versionData,\n db,\n fields,\n operation: 'update',\n req,\n tableName,\n where,\n })\n\n return result\n}\n"],"names":["buildVersionGlobalFields","toSnakeCase","buildQuery","upsertRow","updateGlobalVersion","id","global","locale","req","versionData","where","whereArg","db","sessions","transactionID","drizzle","globalConfig","payload","globals","config","find","slug","whereToUse","equals","tableName","tableNameMap","get","versionsSuffix","fields","adapter","result","data","operation"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAQA,SAASA,wBAAwB,QAAQ,UAAS;AAClD,OAAOC,iBAAiB,gBAAe;AAIvC,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,MAAM,EACNC,MAAM,EACNC,MAAM,CAAC,CAA2B,EAClCC,WAAW,EACXC,OAAOC,QAAQ,EACY;IAE7B,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACL,IAAIM,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,eAAsC,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAC1E,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASf;IAEzB,MAAMgB,aAAaX,YAAY;QAAEN,IAAI;YAAEkB,QAAQlB;QAAG;IAAE;IAEpD,MAAMmB,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAEzB,YAAYe,aAAaK,IAAI,EAAE,EAAE,IAAI,CAACM,cAAc,CAAC,CAAC;IAG5D,MAAMC,SAAS5B,yBAAyBgB;IAExC,MAAM,EAAEN,KAAK,EAAE,GAAG,MAAMR,WAAW;QACjC2B,SAAS,IAAI;QACbD;QACArB;QACAiB;QACAd,OAAOY;IACT;IAEA,MAAMQ,SAAS,MAAM3B,UAA8B;QACjDE;QACAwB,SAAS,IAAI;QACbE,MAAMtB;QACNG;QACAgB;QACAI,WAAW;QACXxB;QACAgB;QACAd;IACF;IAEA,OAAOoB;AACT"}
@@ -1,5 +1,4 @@
1
- import type { TypeWithVersion, UpdateVersionArgs } from 'payload/database';
2
- import type { TypeWithID } from 'payload/types';
1
+ import type { TypeWithID, TypeWithVersion, UpdateVersionArgs } from 'payload';
3
2
  import type { PostgresAdapter } from './types.js';
4
3
  export declare function updateVersion<T extends TypeWithID>(this: PostgresAdapter, { id, collection, locale, req, versionData, where: whereArg, }: UpdateVersionArgs<T>): Promise<TypeWithVersion<T>>;
5
4
  //# sourceMappingURL=updateVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAC1E,OAAO,KAAK,EAAqD,UAAU,EAAE,MAAM,eAAe,CAAA;AAKlG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAKjD,wBAAsB,aAAa,CAAC,CAAC,SAAS,UAAU,EACtD,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,UAAU,EACV,MAAM,EACN,GAAkC,EAClC,WAAW,EACX,KAAK,EAAE,QAAQ,GAChB,EAAE,iBAAiB,CAAC,CAAC,CAAC,+BAgCxB"}
1
+ {"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,UAAU,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,SAAS,CAAA;AAKhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAKjD,wBAAsB,aAAa,CAAC,CAAC,SAAS,UAAU,EACtD,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,UAAU,EACV,MAAM,EACN,GAAkC,EAClC,WAAW,EACX,KAAK,EAAE,QAAQ,GAChB,EAAE,iBAAiB,CAAC,CAAC,CAAC,+BAgCxB"}
@@ -1,4 +1,4 @@
1
- import { buildVersionCollectionFields } from 'payload/versions';
1
+ import { buildVersionCollectionFields } from 'payload';
2
2
  import toSnakeCase from 'to-snake-case';
3
3
  import buildQuery from './queries/buildQuery.js';
4
4
  import { upsertRow } from './upsertRow/index.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { TypeWithVersion, UpdateVersionArgs } from 'payload/database'\nimport type { PayloadRequestWithData, SanitizedCollectionConfig, TypeWithID } from 'payload/types'\n\nimport { buildVersionCollectionFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport buildQuery from './queries/buildQuery.js'\nimport { upsertRow } from './upsertRow/index.js'\n\nexport async function updateVersion<T extends TypeWithID>(\n this: PostgresAdapter,\n {\n id,\n collection,\n locale,\n req = {} as PayloadRequestWithData,\n versionData,\n where: whereArg,\n }: UpdateVersionArgs<T>,\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n const whereToUse = whereArg || { id: { equals: id } }\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`,\n )\n\n const fields = buildVersionCollectionFields(collectionConfig)\n\n const { where } = await buildQuery({\n adapter: this,\n fields,\n locale,\n tableName,\n where: whereToUse,\n })\n\n const result = await upsertRow<TypeWithVersion<T>>({\n id,\n adapter: this,\n data: versionData,\n db,\n fields,\n operation: 'update',\n req,\n tableName,\n where,\n })\n\n return result\n}\n"],"names":["buildVersionCollectionFields","toSnakeCase","buildQuery","upsertRow","updateVersion","id","collection","locale","req","versionData","where","whereArg","db","sessions","transactionID","drizzle","collectionConfig","payload","collections","config","whereToUse","equals","tableName","tableNameMap","get","slug","versionsSuffix","fields","adapter","result","data","operation"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,4BAA4B,QAAQ,mBAAkB;AAC/D,OAAOC,iBAAiB,gBAAe;AAIvC,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,OAAO,eAAeC,cAEpB,EACEC,EAAE,EACFC,UAAU,EACVC,MAAM,EACNC,MAAM,CAAC,CAA2B,EAClCC,WAAW,EACXC,OAAOC,QAAQ,EACM;IAEvB,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACL,IAAIM,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACZ,WAAW,CAACa,MAAM;IAC/F,MAAMC,aAAaT,YAAY;QAAEN,IAAI;YAAEgB,QAAQhB;QAAG;IAAE;IACpD,MAAMiB,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAEvB,YAAYe,iBAAiBS,IAAI,EAAE,EAAE,IAAI,CAACC,cAAc,CAAC,CAAC;IAGhE,MAAMC,SAAS3B,6BAA6BgB;IAE5C,MAAM,EAAEN,KAAK,EAAE,GAAG,MAAMR,WAAW;QACjC0B,SAAS,IAAI;QACbD;QACApB;QACAe;QACAZ,OAAOU;IACT;IAEA,MAAMS,SAAS,MAAM1B,UAA8B;QACjDE;QACAuB,SAAS,IAAI;QACbE,MAAMrB;QACNG;QACAe;QACAI,WAAW;QACXvB;QACAc;QACAZ;IACF;IAEA,OAAOmB;AACT"}
1
+ {"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type {\n PayloadRequestWithData,\n SanitizedCollectionConfig,\n TypeWithID,\n TypeWithVersion,\n UpdateVersionArgs,\n} from 'payload'\n\nimport { buildVersionCollectionFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport buildQuery from './queries/buildQuery.js'\nimport { upsertRow } from './upsertRow/index.js'\n\nexport async function updateVersion<T extends TypeWithID>(\n this: PostgresAdapter,\n {\n id,\n collection,\n locale,\n req = {} as PayloadRequestWithData,\n versionData,\n where: whereArg,\n }: UpdateVersionArgs<T>,\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n const whereToUse = whereArg || { id: { equals: id } }\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`,\n )\n\n const fields = buildVersionCollectionFields(collectionConfig)\n\n const { where } = await buildQuery({\n adapter: this,\n fields,\n locale,\n tableName,\n where: whereToUse,\n })\n\n const result = await upsertRow<TypeWithVersion<T>>({\n id,\n adapter: this,\n data: versionData,\n db,\n fields,\n operation: 'update',\n req,\n tableName,\n where,\n })\n\n return result\n}\n"],"names":["buildVersionCollectionFields","toSnakeCase","buildQuery","upsertRow","updateVersion","id","collection","locale","req","versionData","where","whereArg","db","sessions","transactionID","drizzle","collectionConfig","payload","collections","config","whereToUse","equals","tableName","tableNameMap","get","slug","versionsSuffix","fields","adapter","result","data","operation"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAQA,SAASA,4BAA4B,QAAQ,UAAS;AACtD,OAAOC,iBAAiB,gBAAe;AAIvC,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,OAAO,eAAeC,cAEpB,EACEC,EAAE,EACFC,UAAU,EACVC,MAAM,EACNC,MAAM,CAAC,CAA2B,EAClCC,WAAW,EACXC,OAAOC,QAAQ,EACM;IAEvB,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACL,IAAIM,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACZ,WAAW,CAACa,MAAM;IAC/F,MAAMC,aAAaT,YAAY;QAAEN,IAAI;YAAEgB,QAAQhB;QAAG;IAAE;IACpD,MAAMiB,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAEvB,YAAYe,iBAAiBS,IAAI,EAAE,EAAE,IAAI,CAACC,cAAc,CAAC,CAAC;IAGhE,MAAMC,SAAS3B,6BAA6BgB;IAE5C,MAAM,EAAEN,KAAK,EAAE,GAAG,MAAMR,WAAW;QACjC0B,SAAS,IAAI;QACbD;QACApB;QACAe;QACAZ,OAAOU;IACT;IAEA,MAAMS,SAAS,MAAM1B,UAA8B;QACjDE;QACAuB,SAAS,IAAI;QACbE,MAAMrB;QACNG;QACAe;QACAI,WAAW;QACXvB;QACAc;QACAZ;IACF;IAEA,OAAOmB;AACT"}
@@ -1,4 +1,4 @@
1
- import type { TypeWithID } from 'payload/types';
1
+ import type { TypeWithID } from 'payload';
2
2
  import type { Args } from './types.js';
3
3
  export declare const upsertRow: <T extends TypeWithID>({ id, adapter, data, db, fields, ignoreResult, operation, path, req, tableName, upsertTarget, where, }: Args) => Promise<T>;
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/upsertRow/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAM/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAStC,eAAO,MAAM,SAAS,iIAanB,IAAI,KAAG,QAAQ,CAAC,CAsUlB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/upsertRow/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAMzC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAStC,eAAO,MAAM,SAAS,iIAanB,IAAI,KAAG,QAAQ,CAAC,CAsUlB,CAAA"}
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-param-reassign */ import { eq } from 'drizzle-orm';
2
- import { ValidationError } from 'payload/errors';
2
+ import { ValidationError } from 'payload';
3
3
  import { buildFindManyArgs } from '../find/buildFindManyArgs.js';
4
4
  import { transform } from '../transform/read/index.js';
5
5
  import { transformForWrite } from '../transform/write/index.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/upsertRow/index.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { TypeWithID } from 'payload/types'\n\nimport { eq } from 'drizzle-orm'\nimport { ValidationError } from 'payload/errors'\n\nimport type { BlockRowToInsert } from '../transform/write/types.js'\nimport type { Args } from './types.js'\n\nimport { buildFindManyArgs } from '../find/buildFindManyArgs.js'\nimport { transform } from '../transform/read/index.js'\nimport { transformForWrite } from '../transform/write/index.js'\nimport { deleteExistingArrayRows } from './deleteExistingArrayRows.js'\nimport { deleteExistingRowsByPath } from './deleteExistingRowsByPath.js'\nimport { insertArrays } from './insertArrays.js'\n\nexport const upsertRow = async <T extends TypeWithID>({\n id,\n adapter,\n data,\n db,\n fields,\n ignoreResult,\n operation,\n path = '',\n req,\n tableName,\n upsertTarget,\n where,\n}: Args): Promise<T> => {\n // Split out the incoming data into the corresponding:\n // base row, locales, relationships, blocks, and arrays\n const rowToInsert = transformForWrite({\n adapter,\n data,\n fields,\n path,\n tableName,\n })\n\n // First, we insert the main row\n let insertedRow: Record<string, unknown>\n\n try {\n if (operation === 'update') {\n const target = upsertTarget || adapter.tables[tableName].id\n\n if (id) {\n rowToInsert.row.id = id\n ;[insertedRow] = await db\n .insert(adapter.tables[tableName])\n .values(rowToInsert.row)\n .onConflictDoUpdate({ set: rowToInsert.row, target })\n .returning()\n } else {\n ;[insertedRow] = await db\n .insert(adapter.tables[tableName])\n .values(rowToInsert.row)\n .onConflictDoUpdate({ set: rowToInsert.row, target, where })\n .returning()\n }\n } else {\n ;[insertedRow] = await db\n .insert(adapter.tables[tableName])\n .values(rowToInsert.row)\n .returning()\n }\n\n const localesToInsert: Record<string, unknown>[] = []\n const relationsToInsert: Record<string, unknown>[] = []\n const textsToInsert: Record<string, unknown>[] = []\n const numbersToInsert: Record<string, unknown>[] = []\n const blocksToInsert: { [blockType: string]: BlockRowToInsert[] } = {}\n const selectsToInsert: { [selectTableName: string]: Record<string, unknown>[] } = {}\n\n // If there are locale rows with data, add the parent and locale to each\n if (Object.keys(rowToInsert.locales).length > 0) {\n Object.entries(rowToInsert.locales).forEach(([locale, localeRow]) => {\n localeRow._parentID = insertedRow.id\n localeRow._locale = locale\n localesToInsert.push(localeRow)\n })\n }\n\n // If there are relationships, add parent to each\n if (rowToInsert.relationships.length > 0) {\n rowToInsert.relationships.forEach((relation) => {\n relation.parent = insertedRow.id\n relationsToInsert.push(relation)\n })\n }\n\n // If there are texts, add parent to each\n if (rowToInsert.texts.length > 0) {\n rowToInsert.texts.forEach((textRow) => {\n textRow.parent = insertedRow.id\n textsToInsert.push(textRow)\n })\n }\n\n // If there are numbers, add parent to each\n if (rowToInsert.numbers.length > 0) {\n rowToInsert.numbers.forEach((numberRow) => {\n numberRow.parent = insertedRow.id\n numbersToInsert.push(numberRow)\n })\n }\n\n // If there are selects, add parent to each, and then\n // store by table name and rows\n if (Object.keys(rowToInsert.selects).length > 0) {\n Object.entries(rowToInsert.selects).forEach(([selectTableName, selectRows]) => {\n selectRows.forEach((row) => {\n if (typeof row.parent === 'undefined') {\n row.parent = insertedRow.id\n }\n if (!selectsToInsert[selectTableName]) selectsToInsert[selectTableName] = []\n selectsToInsert[selectTableName].push(row)\n })\n })\n }\n\n // If there are blocks, add parent to each, and then\n // store by table name and rows\n Object.keys(rowToInsert.blocks).forEach((blockName) => {\n rowToInsert.blocks[blockName].forEach((blockRow) => {\n blockRow.row._parentID = insertedRow.id\n if (!blocksToInsert[blockName]) blocksToInsert[blockName] = []\n if (blockRow.row.uuid) {\n delete blockRow.row.uuid\n }\n blocksToInsert[blockName].push(blockRow)\n })\n })\n\n // //////////////////////////////////\n // INSERT LOCALES\n // //////////////////////////////////\n\n if (localesToInsert.length > 0) {\n const localeTable = adapter.tables[`${tableName}${adapter.localesSuffix}`]\n\n if (operation === 'update') {\n await db.delete(localeTable).where(eq(localeTable._parentID, insertedRow.id))\n }\n\n await db.insert(localeTable).values(localesToInsert)\n }\n\n // //////////////////////////////////\n // INSERT RELATIONSHIPS\n // //////////////////////////////////\n\n const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`\n\n if (operation === 'update') {\n await deleteExistingRowsByPath({\n adapter,\n db,\n localeColumnName: 'locale',\n parentColumnName: 'parent',\n parentID: insertedRow.id,\n pathColumnName: 'path',\n rows: [...relationsToInsert, ...rowToInsert.relationshipsToDelete],\n tableName: relationshipsTableName,\n })\n }\n\n if (relationsToInsert.length > 0) {\n await db.insert(adapter.tables[relationshipsTableName]).values(relationsToInsert)\n }\n\n // //////////////////////////////////\n // INSERT hasMany TEXTS\n // //////////////////////////////////\n\n const textsTableName = `${tableName}_texts`\n\n if (operation === 'update') {\n await deleteExistingRowsByPath({\n adapter,\n db,\n localeColumnName: 'locale',\n parentColumnName: 'parent',\n parentID: insertedRow.id,\n pathColumnName: 'path',\n rows: textsToInsert,\n tableName: textsTableName,\n })\n }\n\n if (textsToInsert.length > 0) {\n await db.insert(adapter.tables[textsTableName]).values(textsToInsert).returning()\n }\n\n // //////////////////////////////////\n // INSERT hasMany NUMBERS\n // //////////////////////////////////\n\n const numbersTableName = `${tableName}_numbers`\n\n if (operation === 'update') {\n await deleteExistingRowsByPath({\n adapter,\n db,\n localeColumnName: 'locale',\n parentColumnName: 'parent',\n parentID: insertedRow.id,\n pathColumnName: 'path',\n rows: numbersToInsert,\n tableName: numbersTableName,\n })\n }\n\n if (numbersToInsert.length > 0) {\n await db.insert(adapter.tables[numbersTableName]).values(numbersToInsert).returning()\n }\n\n // //////////////////////////////////\n // INSERT BLOCKS\n // //////////////////////////////////\n\n const insertedBlockRows: Record<string, Record<string, unknown>[]> = {}\n\n if (operation === 'update') {\n for (const blockName of rowToInsert.blocksToDelete) {\n const blockTableName = adapter.tableNameMap.get(`${tableName}_blocks_${blockName}`)\n const blockTable = adapter.tables[blockTableName]\n await db.delete(blockTable).where(eq(blockTable._parentID, insertedRow.id))\n }\n }\n\n for (const [blockName, blockRows] of Object.entries(blocksToInsert)) {\n const blockTableName = adapter.tableNameMap.get(`${tableName}_blocks_${blockName}`)\n insertedBlockRows[blockName] = await db\n .insert(adapter.tables[blockTableName])\n .values(blockRows.map(({ row }) => row))\n .returning()\n\n insertedBlockRows[blockName].forEach((row, i) => {\n blockRows[i].row = row\n })\n\n const blockLocaleIndexMap: number[] = []\n\n const blockLocaleRowsToInsert = blockRows.reduce((acc, blockRow, i) => {\n if (Object.entries(blockRow.locales).length > 0) {\n Object.entries(blockRow.locales).forEach(([blockLocale, blockLocaleData]) => {\n if (Object.keys(blockLocaleData).length > 0) {\n blockLocaleData._parentID = blockRow.row.id\n blockLocaleData._locale = blockLocale\n acc.push(blockLocaleData)\n blockLocaleIndexMap.push(i)\n }\n })\n }\n\n return acc\n }, [])\n\n if (blockLocaleRowsToInsert.length > 0) {\n await db\n .insert(adapter.tables[`${blockTableName}${adapter.localesSuffix}`])\n .values(blockLocaleRowsToInsert)\n .returning()\n }\n\n await insertArrays({\n adapter,\n arrays: blockRows.map(({ arrays }) => arrays),\n db,\n parentRows: insertedBlockRows[blockName],\n })\n }\n\n // //////////////////////////////////\n // INSERT ARRAYS RECURSIVELY\n // //////////////////////////////////\n\n if (operation === 'update') {\n for (const arrayTableName of Object.keys(rowToInsert.arrays)) {\n await deleteExistingArrayRows({\n adapter,\n db,\n parentID: insertedRow.id,\n tableName: arrayTableName,\n })\n }\n }\n\n await insertArrays({\n adapter,\n arrays: [rowToInsert.arrays],\n db,\n parentRows: [insertedRow],\n })\n\n // //////////////////////////////////\n // INSERT hasMany SELECTS\n // //////////////////////////////////\n\n for (const [selectTableName, tableRows] of Object.entries(selectsToInsert)) {\n const selectTable = adapter.tables[selectTableName]\n if (operation === 'update') {\n await db.delete(selectTable).where(eq(selectTable.parent, insertedRow.id))\n }\n await db.insert(selectTable).values(tableRows).returning()\n }\n\n // //////////////////////////////////\n // Error Handling\n // //////////////////////////////////\n } catch (error) {\n throw error.code === '23505'\n ? new ValidationError(\n [\n {\n field: adapter.fieldConstraints[tableName][error.constraint],\n message: req.t('error:valueMustBeUnique'),\n },\n ],\n req.t,\n )\n : error\n }\n\n if (ignoreResult) return data as T\n\n // //////////////////////////////////\n // RETRIEVE NEWLY UPDATED ROW\n // //////////////////////////////////\n\n const findManyArgs = buildFindManyArgs({\n adapter,\n depth: 0,\n fields,\n tableName,\n })\n\n findManyArgs.where = eq(adapter.tables[tableName].id, insertedRow.id)\n\n const doc = await db.query[tableName].findFirst(findManyArgs)\n\n // //////////////////////////////////\n // TRANSFORM DATA\n // //////////////////////////////////\n\n const result = transform<T>({\n adapter,\n config: adapter.payload.config,\n data: doc,\n fields,\n })\n\n return result\n}\n"],"names":["eq","ValidationError","buildFindManyArgs","transform","transformForWrite","deleteExistingArrayRows","deleteExistingRowsByPath","insertArrays","upsertRow","id","adapter","data","db","fields","ignoreResult","operation","path","req","tableName","upsertTarget","where","rowToInsert","insertedRow","target","tables","row","insert","values","onConflictDoUpdate","set","returning","localesToInsert","relationsToInsert","textsToInsert","numbersToInsert","blocksToInsert","selectsToInsert","Object","keys","locales","length","entries","forEach","locale","localeRow","_parentID","_locale","push","relationships","relation","parent","texts","textRow","numbers","numberRow","selects","selectTableName","selectRows","blocks","blockName","blockRow","uuid","localeTable","localesSuffix","delete","relationshipsTableName","relationshipsSuffix","localeColumnName","parentColumnName","parentID","pathColumnName","rows","relationshipsToDelete","textsTableName","numbersTableName","insertedBlockRows","blocksToDelete","blockTableName","tableNameMap","get","blockTable","blockRows","map","i","blockLocaleIndexMap","blockLocaleRowsToInsert","reduce","acc","blockLocale","blockLocaleData","arrays","parentRows","arrayTableName","tableRows","selectTable","error","code","field","fieldConstraints","constraint","message","t","findManyArgs","depth","doc","query","findFirst","result","config","payload"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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ACkC,iBAAiBqC,UAAU,IAAIxD,OAAOI,OAAO,CAACL,iBAAkB;YAC1E,MAAM0D,cAAcpF,QAAQc,MAAM,CAACgC,gBAAgB;YACnD,IAAIzC,cAAc,UAAU;gBAC1B,MAAMH,GAAGoD,MAAM,CAAC8B,aAAa1E,KAAK,CAACpB,GAAG8F,YAAY5C,MAAM,EAAE5B,YAAYb,EAAE;YAC1E;YACA,MAAMG,GAAGc,MAAM,CAACoE,aAAanE,MAAM,CAACkE,WAAW/D,SAAS;QAC1D;IAEA,qCAAqC;IACrC,iBAAiB;IACjB,qCAAqC;IACvC,EAAE,OAAOiE,OAAO;QACd,MAAMA,MAAMC,IAAI,KAAK,UACjB,IAAI/F,gBACF;YACE;gBACEgG,OAAOvF,QAAQwF,gBAAgB,CAAChF,UAAU,CAAC6E,MAAMI,UAAU,CAAC;gBAC5DC,SAASnF,IAAIoF,CAAC,CAAC;YACjB;SACD,EACDpF,IAAIoF,CAAC,IAEPN;IACN;IAEA,IAAIjF,cAAc,OAAOH;IAEzB,qCAAqC;IACrC,6BAA6B;IAC7B,qCAAqC;IAErC,MAAM2F,eAAepG,kBAAkB;QACrCQ;QACA6F,OAAO;QACP1F;QACAK;IACF;IAEAoF,aAAalF,KAAK,GAAGpB,GAAGU,QAAQc,MAAM,CAACN,UAAU,CAACT,EAAE,EAAEa,YAAYb,EAAE;IAEpE,MAAM+F,MAAM,MAAM5F,GAAG6F,KAAK,CAACvF,UAAU,CAACwF,SAAS,CAACJ;IAEhD,qCAAqC;IACrC,iBAAiB;IACjB,qCAAqC;IAErC,MAAMK,SAASxG,UAAa;QAC1BO;QACAkG,QAAQlG,QAAQmG,OAAO,CAACD,MAAM;QAC9BjG,MAAM6F;QACN3F;IACF;IAEA,OAAO8F;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/upsertRow/index.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { TypeWithID } from 'payload'\n\nimport { eq } from 'drizzle-orm'\nimport { ValidationError } from 'payload'\n\nimport type { BlockRowToInsert } from '../transform/write/types.js'\nimport type { Args } from './types.js'\n\nimport { buildFindManyArgs } from '../find/buildFindManyArgs.js'\nimport { transform } from '../transform/read/index.js'\nimport { transformForWrite } from '../transform/write/index.js'\nimport { deleteExistingArrayRows } from './deleteExistingArrayRows.js'\nimport { deleteExistingRowsByPath } from './deleteExistingRowsByPath.js'\nimport { insertArrays } from './insertArrays.js'\n\nexport const upsertRow = async <T extends TypeWithID>({\n id,\n adapter,\n data,\n db,\n fields,\n ignoreResult,\n operation,\n path = '',\n req,\n tableName,\n upsertTarget,\n where,\n}: Args): Promise<T> => {\n // Split out the incoming data into the corresponding:\n // base row, locales, relationships, blocks, and arrays\n const rowToInsert = transformForWrite({\n adapter,\n data,\n fields,\n path,\n tableName,\n })\n\n // First, we insert the main row\n let insertedRow: Record<string, unknown>\n\n try {\n if (operation === 'update') {\n const target = upsertTarget || adapter.tables[tableName].id\n\n if (id) {\n rowToInsert.row.id = id\n ;[insertedRow] = await db\n .insert(adapter.tables[tableName])\n .values(rowToInsert.row)\n .onConflictDoUpdate({ set: rowToInsert.row, target })\n .returning()\n } else {\n ;[insertedRow] = await db\n .insert(adapter.tables[tableName])\n .values(rowToInsert.row)\n .onConflictDoUpdate({ set: rowToInsert.row, target, where })\n .returning()\n }\n } else {\n ;[insertedRow] = await db\n .insert(adapter.tables[tableName])\n .values(rowToInsert.row)\n .returning()\n }\n\n const localesToInsert: Record<string, unknown>[] = []\n const relationsToInsert: Record<string, unknown>[] = []\n const textsToInsert: Record<string, unknown>[] = []\n const numbersToInsert: Record<string, unknown>[] = []\n const blocksToInsert: { [blockType: string]: BlockRowToInsert[] } = {}\n const selectsToInsert: { [selectTableName: string]: Record<string, unknown>[] } = {}\n\n // If there are locale rows with data, add the parent and locale to each\n if (Object.keys(rowToInsert.locales).length > 0) {\n Object.entries(rowToInsert.locales).forEach(([locale, localeRow]) => {\n localeRow._parentID = insertedRow.id\n localeRow._locale = locale\n localesToInsert.push(localeRow)\n })\n }\n\n // If there are relationships, add parent to each\n if (rowToInsert.relationships.length > 0) {\n rowToInsert.relationships.forEach((relation) => {\n relation.parent = insertedRow.id\n relationsToInsert.push(relation)\n })\n }\n\n // If there are texts, add parent to each\n if (rowToInsert.texts.length > 0) {\n rowToInsert.texts.forEach((textRow) => {\n textRow.parent = insertedRow.id\n textsToInsert.push(textRow)\n })\n }\n\n // If there are numbers, add parent to each\n if (rowToInsert.numbers.length > 0) {\n rowToInsert.numbers.forEach((numberRow) => {\n numberRow.parent = insertedRow.id\n numbersToInsert.push(numberRow)\n })\n }\n\n // If there are selects, add parent to each, and then\n // store by table name and rows\n if (Object.keys(rowToInsert.selects).length > 0) {\n Object.entries(rowToInsert.selects).forEach(([selectTableName, selectRows]) => {\n selectRows.forEach((row) => {\n if (typeof row.parent === 'undefined') {\n row.parent = insertedRow.id\n }\n if (!selectsToInsert[selectTableName]) selectsToInsert[selectTableName] = []\n selectsToInsert[selectTableName].push(row)\n })\n })\n }\n\n // If there are blocks, add parent to each, and then\n // store by table name and rows\n Object.keys(rowToInsert.blocks).forEach((blockName) => {\n rowToInsert.blocks[blockName].forEach((blockRow) => {\n blockRow.row._parentID = insertedRow.id\n if (!blocksToInsert[blockName]) blocksToInsert[blockName] = []\n if (blockRow.row.uuid) {\n delete blockRow.row.uuid\n }\n blocksToInsert[blockName].push(blockRow)\n })\n })\n\n // //////////////////////////////////\n // INSERT LOCALES\n // //////////////////////////////////\n\n if (localesToInsert.length > 0) {\n const localeTable = adapter.tables[`${tableName}${adapter.localesSuffix}`]\n\n if (operation === 'update') {\n await db.delete(localeTable).where(eq(localeTable._parentID, insertedRow.id))\n }\n\n await db.insert(localeTable).values(localesToInsert)\n }\n\n // //////////////////////////////////\n // INSERT RELATIONSHIPS\n // //////////////////////////////////\n\n const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`\n\n if (operation === 'update') {\n await deleteExistingRowsByPath({\n adapter,\n db,\n localeColumnName: 'locale',\n parentColumnName: 'parent',\n parentID: insertedRow.id,\n pathColumnName: 'path',\n rows: [...relationsToInsert, ...rowToInsert.relationshipsToDelete],\n tableName: relationshipsTableName,\n })\n }\n\n if (relationsToInsert.length > 0) {\n await db.insert(adapter.tables[relationshipsTableName]).values(relationsToInsert)\n }\n\n // //////////////////////////////////\n // INSERT hasMany TEXTS\n // //////////////////////////////////\n\n const textsTableName = `${tableName}_texts`\n\n if (operation === 'update') {\n await deleteExistingRowsByPath({\n adapter,\n db,\n localeColumnName: 'locale',\n parentColumnName: 'parent',\n parentID: insertedRow.id,\n pathColumnName: 'path',\n rows: textsToInsert,\n tableName: textsTableName,\n })\n }\n\n if (textsToInsert.length > 0) {\n await db.insert(adapter.tables[textsTableName]).values(textsToInsert).returning()\n }\n\n // //////////////////////////////////\n // INSERT hasMany NUMBERS\n // //////////////////////////////////\n\n const numbersTableName = `${tableName}_numbers`\n\n if (operation === 'update') {\n await deleteExistingRowsByPath({\n adapter,\n db,\n localeColumnName: 'locale',\n parentColumnName: 'parent',\n parentID: insertedRow.id,\n pathColumnName: 'path',\n rows: numbersToInsert,\n tableName: numbersTableName,\n })\n }\n\n if (numbersToInsert.length > 0) {\n await db.insert(adapter.tables[numbersTableName]).values(numbersToInsert).returning()\n }\n\n // //////////////////////////////////\n // INSERT BLOCKS\n // //////////////////////////////////\n\n const insertedBlockRows: Record<string, Record<string, unknown>[]> = {}\n\n if (operation === 'update') {\n for (const blockName of rowToInsert.blocksToDelete) {\n const blockTableName = adapter.tableNameMap.get(`${tableName}_blocks_${blockName}`)\n const blockTable = adapter.tables[blockTableName]\n await db.delete(blockTable).where(eq(blockTable._parentID, insertedRow.id))\n }\n }\n\n for (const [blockName, blockRows] of Object.entries(blocksToInsert)) {\n const blockTableName = adapter.tableNameMap.get(`${tableName}_blocks_${blockName}`)\n insertedBlockRows[blockName] = await db\n .insert(adapter.tables[blockTableName])\n .values(blockRows.map(({ row }) => row))\n .returning()\n\n insertedBlockRows[blockName].forEach((row, i) => {\n blockRows[i].row = row\n })\n\n const blockLocaleIndexMap: number[] = []\n\n const blockLocaleRowsToInsert = blockRows.reduce((acc, blockRow, i) => {\n if (Object.entries(blockRow.locales).length > 0) {\n Object.entries(blockRow.locales).forEach(([blockLocale, blockLocaleData]) => {\n if (Object.keys(blockLocaleData).length > 0) {\n blockLocaleData._parentID = blockRow.row.id\n blockLocaleData._locale = blockLocale\n acc.push(blockLocaleData)\n blockLocaleIndexMap.push(i)\n }\n })\n }\n\n return acc\n }, [])\n\n if (blockLocaleRowsToInsert.length > 0) {\n await db\n .insert(adapter.tables[`${blockTableName}${adapter.localesSuffix}`])\n .values(blockLocaleRowsToInsert)\n .returning()\n }\n\n await insertArrays({\n adapter,\n arrays: blockRows.map(({ arrays }) => arrays),\n db,\n parentRows: insertedBlockRows[blockName],\n })\n }\n\n // //////////////////////////////////\n // INSERT ARRAYS RECURSIVELY\n // //////////////////////////////////\n\n if (operation === 'update') {\n for (const arrayTableName of Object.keys(rowToInsert.arrays)) {\n await deleteExistingArrayRows({\n adapter,\n db,\n parentID: insertedRow.id,\n tableName: arrayTableName,\n })\n }\n }\n\n await insertArrays({\n adapter,\n arrays: [rowToInsert.arrays],\n db,\n parentRows: [insertedRow],\n })\n\n // //////////////////////////////////\n // INSERT hasMany SELECTS\n // //////////////////////////////////\n\n for (const [selectTableName, tableRows] of Object.entries(selectsToInsert)) {\n const selectTable = adapter.tables[selectTableName]\n if (operation === 'update') {\n await db.delete(selectTable).where(eq(selectTable.parent, insertedRow.id))\n }\n await db.insert(selectTable).values(tableRows).returning()\n }\n\n // //////////////////////////////////\n // Error Handling\n // //////////////////////////////////\n } catch (error) {\n throw error.code === '23505'\n ? new ValidationError(\n [\n {\n field: adapter.fieldConstraints[tableName][error.constraint],\n message: req.t('error:valueMustBeUnique'),\n },\n ],\n req.t,\n )\n : error\n }\n\n if (ignoreResult) return data as T\n\n // //////////////////////////////////\n // RETRIEVE NEWLY UPDATED ROW\n // //////////////////////////////////\n\n const findManyArgs = buildFindManyArgs({\n adapter,\n depth: 0,\n fields,\n tableName,\n })\n\n findManyArgs.where = eq(adapter.tables[tableName].id, insertedRow.id)\n\n const doc = await db.query[tableName].findFirst(findManyArgs)\n\n // //////////////////////////////////\n // TRANSFORM DATA\n // //////////////////////////////////\n\n const result = transform<T>({\n adapter,\n config: adapter.payload.config,\n data: doc,\n fields,\n })\n\n return result\n}\n"],"names":["eq","ValidationError","buildFindManyArgs","transform","transformForWrite","deleteExistingArrayRows","deleteExistingRowsByPath","insertArrays","upsertRow","id","adapter","data","db","fields","ignoreResult","operation","path","req","tableName","upsertTarget","where","rowToInsert","insertedRow","target","tables","row","insert","values","onConflictDoUpdate","set","returning","localesToInsert","relationsToInsert","textsToInsert","numbersToInsert","blocksToInsert","selectsToInsert","Object","keys","locales","length","entries","forEach","locale","localeRow","_parentID","_locale","push","relationships","relation","parent","texts","textRow","numbers","numberRow","selects","selectTableName","selectRows","blocks","blockName","blockRow","uuid","localeTable","localesSuffix","delete","relationshipsTableName","relationshipsSuffix","localeColumnName","parentColumnName","parentID","pathColumnName","rows","relationshipsToDelete","textsTableName","numbersTableName","insertedBlockRows","blocksToDelete","blockTableName","tableNameMap","get","blockTable","blockRows","map","i","blockLocaleIndexMap","blockLocaleRowsToInsert","reduce","acc","blockLocale","blockLocaleData","arrays","parentRows","arrayTableName","tableRows","selectTable","error","code","field","fieldConstraints","constraint","message","t","findManyArgs","depth","doc","query","findFirst","result","config","payload"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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gC,gBAAgB;YACnD,IAAIzC,cAAc,UAAU;gBAC1B,MAAMH,GAAGoD,MAAM,CAAC8B,aAAa1E,KAAK,CAACpB,GAAG8F,YAAY5C,MAAM,EAAE5B,YAAYb,EAAE;YAC1E;YACA,MAAMG,GAAGc,MAAM,CAACoE,aAAanE,MAAM,CAACkE,WAAW/D,SAAS;QAC1D;IAEA,qCAAqC;IACrC,iBAAiB;IACjB,qCAAqC;IACvC,EAAE,OAAOiE,OAAO;QACd,MAAMA,MAAMC,IAAI,KAAK,UACjB,IAAI/F,gBACF;YACE;gBACEgG,OAAOvF,QAAQwF,gBAAgB,CAAChF,UAAU,CAAC6E,MAAMI,UAAU,CAAC;gBAC5DC,SAASnF,IAAIoF,CAAC,CAAC;YACjB;SACD,EACDpF,IAAIoF,CAAC,IAEPN;IACN;IAEA,IAAIjF,cAAc,OAAOH;IAEzB,qCAAqC;IACrC,6BAA6B;IAC7B,qCAAqC;IAErC,MAAM2F,eAAepG,kBAAkB;QACrCQ;QACA6F,OAAO;QACP1F;QACAK;IACF;IAEAoF,aAAalF,KAAK,GAAGpB,GAAGU,QAAQc,MAAM,CAACN,UAAU,CAACT,EAAE,EAAEa,YAAYb,EAAE;IAEpE,MAAM+F,MAAM,MAAM5F,GAAG6F,KAAK,CAACvF,UAAU,CAACwF,SAAS,CAACJ;IAEhD,qCAAqC;IACrC,iBAAiB;IACjB,qCAAqC;IAErC,MAAMK,SAASxG,UAAa;QAC1BO;QACAkG,QAAQlG,QAAQmG,OAAO,CAACD,MAAM;QAC9BjG,MAAM6F;QACN3F;IACF;IAEA,OAAO8F;AACT,EAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { SQL } from 'drizzle-orm';
2
- import type { Field, PayloadRequestWithData } from 'payload/types';
2
+ import type { Field, PayloadRequestWithData } from 'payload';
3
3
  import type { DrizzleDB, GenericColumn, PostgresAdapter } from '../types.js';
4
4
  type BaseArgs = {
5
5
  adapter: PostgresAdapter;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/upsertRow/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAElE,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE5E,KAAK,QAAQ,GAAG;IACd,OAAO,EAAE,eAAe,CAAA;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,EAAE,EAAE,SAAS,CAAA;IACb,MAAM,EAAE,KAAK,EAAE,CAAA;IACf;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,sBAAsB,CAAA;IAC3B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,KAAK,UAAU,GAAG,QAAQ,GAAG;IAC3B,EAAE,CAAC,EAAE,KAAK,CAAA;IACV,SAAS,EAAE,QAAQ,CAAA;IACnB,YAAY,CAAC,EAAE,KAAK,CAAA;IACpB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,KAAK,UAAU,GAAG,QAAQ,GAAG;IAC3B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,SAAS,EAAE,QAAQ,CAAA;IACnB,YAAY,CAAC,EAAE,aAAa,CAAA;IAC5B,KAAK,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,UAAU,GAAG,UAAU,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/upsertRow/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE5E,KAAK,QAAQ,GAAG;IACd,OAAO,EAAE,eAAe,CAAA;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,EAAE,EAAE,SAAS,CAAA;IACb,MAAM,EAAE,KAAK,EAAE,CAAA;IACf;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,sBAAsB,CAAA;IAC3B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,KAAK,UAAU,GAAG,QAAQ,GAAG;IAC3B,EAAE,CAAC,EAAE,KAAK,CAAA;IACV,SAAS,EAAE,QAAQ,CAAA;IACnB,YAAY,CAAC,EAAE,KAAK,CAAA;IACpB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,KAAK,UAAU,GAAG,QAAQ,GAAG;IAC3B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,SAAS,EAAE,QAAQ,CAAA;IACnB,YAAY,CAAC,EAAE,aAAa,CAAA;IAC5B,KAAK,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,UAAU,GAAG,UAAU,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/upsertRow/types.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { Field, PayloadRequestWithData } from 'payload/types'\n\nimport type { DrizzleDB, GenericColumn, PostgresAdapter } from '../types.js'\n\ntype BaseArgs = {\n adapter: PostgresAdapter\n data: Record<string, unknown>\n db: DrizzleDB\n fields: Field[]\n /**\n * When true, skips reading the data back from the database and returns the input data\n * @default false\n */\n ignoreResult?: boolean\n path?: string\n req: PayloadRequestWithData\n tableName: string\n}\n\ntype CreateArgs = BaseArgs & {\n id?: never\n operation: 'create'\n upsertTarget?: never\n where?: never\n}\n\ntype UpdateArgs = BaseArgs & {\n id?: number | string\n operation: 'update'\n upsertTarget?: GenericColumn\n where?: SQL<unknown>\n}\n\nexport type Args = CreateArgs | UpdateArgs\n"],"names":[],"rangeMappings":"","mappings":"AAkCA,WAA0C"}
1
+ {"version":3,"sources":["../../src/upsertRow/types.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { Field, PayloadRequestWithData } from 'payload'\n\nimport type { DrizzleDB, GenericColumn, PostgresAdapter } from '../types.js'\n\ntype BaseArgs = {\n adapter: PostgresAdapter\n data: Record<string, unknown>\n db: DrizzleDB\n fields: Field[]\n /**\n * When true, skips reading the data back from the database and returns the input data\n * @default false\n */\n ignoreResult?: boolean\n path?: string\n req: PayloadRequestWithData\n tableName: string\n}\n\ntype CreateArgs = BaseArgs & {\n id?: never\n operation: 'create'\n upsertTarget?: never\n where?: never\n}\n\ntype UpdateArgs = BaseArgs & {\n id?: number | string\n operation: 'update'\n upsertTarget?: GenericColumn\n where?: SQL<unknown>\n}\n\nexport type Args = CreateArgs | UpdateArgs\n"],"names":[],"rangeMappings":"","mappings":"AAkCA,WAA0C"}
@@ -1,3 +1,3 @@
1
- import type { Field } from 'payload/types';
1
+ import type { Field } from 'payload';
2
2
  export declare const hasLocalesTable: (fields: Field[]) => boolean;
3
3
  //# sourceMappingURL=hasLocalesTable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hasLocalesTable.d.ts","sourceRoot":"","sources":["../../src/utilities/hasLocalesTable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAI1C,eAAO,MAAM,eAAe,WAAY,KAAK,EAAE,KAAG,OAOjD,CAAA"}
1
+ {"version":3,"file":"hasLocalesTable.d.ts","sourceRoot":"","sources":["../../src/utilities/hasLocalesTable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpC,eAAO,MAAM,eAAe,WAAY,KAAK,EAAE,KAAG,OAOjD,CAAA"}
@@ -1,4 +1,4 @@
1
- import { fieldAffectsData, fieldHasSubFields } from 'payload/types';
1
+ import { fieldAffectsData, fieldHasSubFields } from 'payload/shared';
2
2
  export const hasLocalesTable = (fields)=>{
3
3
  return fields.some((field)=>{
4
4
  if (fieldAffectsData(field) && field.localized) return true;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/hasLocalesTable.ts"],"sourcesContent":["import type { Field } from 'payload/types'\n\nimport { fieldAffectsData, fieldHasSubFields } from 'payload/types'\n\nexport const hasLocalesTable = (fields: Field[]): boolean => {\n return fields.some((field) => {\n if (fieldAffectsData(field) && field.localized) return true\n if (fieldHasSubFields(field) && field.type !== 'array') return hasLocalesTable(field.fields)\n if (field.type === 'tabs') return field.tabs.some((tab) => hasLocalesTable(tab.fields))\n return false\n })\n}\n"],"names":["fieldAffectsData","fieldHasSubFields","hasLocalesTable","fields","some","field","localized","type","tabs","tab"],"rangeMappings":";;;;;;;;","mappings":"AAEA,SAASA,gBAAgB,EAAEC,iBAAiB,QAAQ,gBAAe;AAEnE,OAAO,MAAMC,kBAAkB,CAACC;IAC9B,OAAOA,OAAOC,IAAI,CAAC,CAACC;QAClB,IAAIL,iBAAiBK,UAAUA,MAAMC,SAAS,EAAE,OAAO;QACvD,IAAIL,kBAAkBI,UAAUA,MAAME,IAAI,KAAK,SAAS,OAAOL,gBAAgBG,MAAMF,MAAM;QAC3F,IAAIE,MAAME,IAAI,KAAK,QAAQ,OAAOF,MAAMG,IAAI,CAACJ,IAAI,CAAC,CAACK,MAAQP,gBAAgBO,IAAIN,MAAM;QACrF,OAAO;IACT;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/hasLocalesTable.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { fieldAffectsData, fieldHasSubFields } from 'payload/shared'\n\nexport const hasLocalesTable = (fields: Field[]): boolean => {\n return fields.some((field) => {\n if (fieldAffectsData(field) && field.localized) return true\n if (fieldHasSubFields(field) && field.type !== 'array') return hasLocalesTable(field.fields)\n if (field.type === 'tabs') return field.tabs.some((tab) => hasLocalesTable(tab.fields))\n return false\n })\n}\n"],"names":["fieldAffectsData","fieldHasSubFields","hasLocalesTable","fields","some","field","localized","type","tabs","tab"],"rangeMappings":";;;;;;;;","mappings":"AAEA,SAASA,gBAAgB,EAAEC,iBAAiB,QAAQ,iBAAgB;AAEpE,OAAO,MAAMC,kBAAkB,CAACC;IAC9B,OAAOA,OAAOC,IAAI,CAAC,CAACC;QAClB,IAAIL,iBAAiBK,UAAUA,MAAMC,SAAS,EAAE,OAAO;QACvD,IAAIL,kBAAkBI,UAAUA,MAAME,IAAI,KAAK,SAAS,OAAOL,gBAAgBG,MAAMF,MAAM;QAC3F,IAAIE,MAAME,IAAI,KAAK,QAAQ,OAAOF,MAAMG,IAAI,CAACJ,IAAI,CAAC,CAACK,MAAQP,gBAAgBO,IAAIN,MAAM;QACrF,OAAO;IACT;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"pushDevSchema.d.ts","sourceRoot":"","sources":["../../src/utilities/pushDevSchema.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD;;;;;GAKG;AACH,eAAO,MAAM,aAAa,OAAc,eAAe,kBAmEtD,CAAA"}
1
+ {"version":3,"file":"pushDevSchema.d.ts","sourceRoot":"","sources":["../../src/utilities/pushDevSchema.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD;;;;;GAKG;AACH,eAAO,MAAM,aAAa,OAAc,eAAe,kBAgEtD,CAAA"}
@@ -11,7 +11,7 @@ const require = createRequire(import.meta.url);
11
11
  */ export const pushDevSchema = async (db)=>{
12
12
  const { pushSchema } = require('drizzle-kit/payload');
13
13
  // This will prompt if clarifications are needed for Drizzle to push new schema
14
- const { apply, hasDataLoss, statementsToExecute, warnings } = await pushSchema(db.schema, db.drizzle);
14
+ const { apply, hasDataLoss, warnings } = await pushSchema(db.schema, db.drizzle);
15
15
  if (warnings.length) {
16
16
  let message = `Warnings detected during schema push: \n\n${warnings.join('\n')}\n\n`;
17
17
  if (hasDataLoss) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/pushDevSchema.ts"],"sourcesContent":["import { eq } from 'drizzle-orm'\nimport { numeric, timestamp, varchar } from 'drizzle-orm/pg-core'\nimport { createRequire } from 'module'\nimport prompts from 'prompts'\n\nimport type { PostgresAdapter } from '../types.js'\n\nconst require = createRequire(import.meta.url)\n\n/**\n * Pushes the development schema to the database using Drizzle.\n *\n * @param {PostgresAdapter} db - The PostgresAdapter instance connected to the database.\n * @returns {Promise<void>} - A promise that resolves once the schema push is complete.\n */\nexport const pushDevSchema = async (db: PostgresAdapter) => {\n const { pushSchema } = require('drizzle-kit/payload')\n\n // This will prompt if clarifications are needed for Drizzle to push new schema\n const { apply, hasDataLoss, statementsToExecute, warnings } = await pushSchema(\n db.schema,\n db.drizzle,\n )\n\n if (warnings.length) {\n let message = `Warnings detected during schema push: \\n\\n${warnings.join('\\n')}\\n\\n`\n\n if (hasDataLoss) {\n message += `DATA LOSS WARNING: Possible data loss detected if schema is pushed.\\n\\n`\n }\n\n message += `Accept warnings and push schema to database?`\n\n const { confirm: acceptWarnings } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message,\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n // Exit if user does not accept warnings.\n // Q: Is this the right type of exit for this interaction?\n if (!acceptWarnings) {\n process.exit(0)\n }\n }\n\n await apply()\n\n // Migration table def in order to use query using drizzle\n const migrationsSchema = db.pgSchema.table('payload_migrations', {\n name: varchar('name'),\n batch: numeric('batch'),\n created_at: timestamp('created_at'),\n updated_at: timestamp('updated_at'),\n })\n\n const devPush = await db.drizzle\n .select()\n .from(migrationsSchema)\n .where(eq(migrationsSchema.batch, '-1'))\n\n if (!devPush.length) {\n await db.drizzle.insert(migrationsSchema).values({\n name: 'dev',\n batch: '-1',\n })\n } else {\n await db.drizzle\n .update(migrationsSchema)\n .set({\n updated_at: new Date(),\n })\n .where(eq(migrationsSchema.batch, '-1'))\n }\n}\n"],"names":["eq","numeric","timestamp","varchar","createRequire","prompts","require","url","pushDevSchema","db","pushSchema","apply","hasDataLoss","statementsToExecute","warnings","schema","drizzle","length","message","join","confirm","acceptWarnings","name","type","initial","onCancel","process","exit","migrationsSchema","pgSchema","table","batch","created_at","updated_at","devPush","select","from","where","insert","values","update","set","Date"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,EAAE,QAAQ,cAAa;AAChC,SAASC,OAAO,EAAEC,SAAS,EAAEC,OAAO,QAAQ,sBAAqB;AACjE,SAASC,aAAa,QAAQ,SAAQ;AACtC,OAAOC,aAAa,UAAS;AAI7B,MAAMC,UAAUF,cAAc,YAAYG,GAAG;AAE7C;;;;;CAKC,GACD,OAAO,MAAMC,gBAAgB,OAAOC;IAClC,MAAM,EAAEC,UAAU,EAAE,GAAGJ,QAAQ;IAE/B,+EAA+E;IAC/E,MAAM,EAAEK,KAAK,EAAEC,WAAW,EAAEC,mBAAmB,EAAEC,QAAQ,EAAE,GAAG,MAAMJ,WAClED,GAAGM,MAAM,EACTN,GAAGO,OAAO;IAGZ,IAAIF,SAASG,MAAM,EAAE;QACnB,IAAIC,UAAU,CAAC,0CAA0C,EAAEJ,SAASK,IAAI,CAAC,MAAM,IAAI,CAAC;QAEpF,IAAIP,aAAa;YACfM,WAAW,CAAC,uEAAuE,CAAC;QACtF;QAEAA,WAAW,CAAC,4CAA4C,CAAC;QAEzD,MAAM,EAAEE,SAASC,cAAc,EAAE,GAAG,MAAMhB,QACxC;YACEiB,MAAM;YACNC,MAAM;YACNC,SAAS;YACTN;QACF,GACA;YACEO,UAAU;gBACRC,QAAQC,IAAI,CAAC;YACf;QACF;QAGF,yCAAyC;QACzC,0DAA0D;QAC1D,IAAI,CAACN,gBAAgB;YACnBK,QAAQC,IAAI,CAAC;QACf;IACF;IAEA,MAAMhB;IAEN,0DAA0D;IAC1D,MAAMiB,mBAAmBnB,GAAGoB,QAAQ,CAACC,KAAK,CAAC,sBAAsB;QAC/DR,MAAMnB,QAAQ;QACd4B,OAAO9B,QAAQ;QACf+B,YAAY9B,UAAU;QACtB+B,YAAY/B,UAAU;IACxB;IAEA,MAAMgC,UAAU,MAAMzB,GAAGO,OAAO,CAC7BmB,MAAM,GACNC,IAAI,CAACR,kBACLS,KAAK,CAACrC,GAAG4B,iBAAiBG,KAAK,EAAE;IAEpC,IAAI,CAACG,QAAQjB,MAAM,EAAE;QACnB,MAAMR,GAAGO,OAAO,CAACsB,MAAM,CAACV,kBAAkBW,MAAM,CAAC;YAC/CjB,MAAM;YACNS,OAAO;QACT;IACF,OAAO;QACL,MAAMtB,GAAGO,OAAO,CACbwB,MAAM,CAACZ,kBACPa,GAAG,CAAC;YACHR,YAAY,IAAIS;QAClB,GACCL,KAAK,CAACrC,GAAG4B,iBAAiBG,KAAK,EAAE;IACtC;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/pushDevSchema.ts"],"sourcesContent":["import { eq } from 'drizzle-orm'\nimport { numeric, timestamp, varchar } from 'drizzle-orm/pg-core'\nimport { createRequire } from 'module'\nimport prompts from 'prompts'\n\nimport type { PostgresAdapter } from '../types.js'\n\nconst require = createRequire(import.meta.url)\n\n/**\n * Pushes the development schema to the database using Drizzle.\n *\n * @param {PostgresAdapter} db - The PostgresAdapter instance connected to the database.\n * @returns {Promise<void>} - A promise that resolves once the schema push is complete.\n */\nexport const pushDevSchema = async (db: PostgresAdapter) => {\n const { pushSchema } = require('drizzle-kit/payload')\n\n // This will prompt if clarifications are needed for Drizzle to push new schema\n const { apply, hasDataLoss, warnings } = await pushSchema(db.schema, db.drizzle)\n\n if (warnings.length) {\n let message = `Warnings detected during schema push: \\n\\n${warnings.join('\\n')}\\n\\n`\n\n if (hasDataLoss) {\n message += `DATA LOSS WARNING: Possible data loss detected if schema is pushed.\\n\\n`\n }\n\n message += `Accept warnings and push schema to database?`\n\n const { confirm: acceptWarnings } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message,\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n // Exit if user does not accept warnings.\n // Q: Is this the right type of exit for this interaction?\n if (!acceptWarnings) {\n process.exit(0)\n }\n }\n\n await apply()\n\n // Migration table def in order to use query using drizzle\n const migrationsSchema = db.pgSchema.table('payload_migrations', {\n name: varchar('name'),\n batch: numeric('batch'),\n created_at: timestamp('created_at'),\n updated_at: timestamp('updated_at'),\n })\n\n const devPush = await db.drizzle\n .select()\n .from(migrationsSchema)\n .where(eq(migrationsSchema.batch, '-1'))\n\n if (!devPush.length) {\n await db.drizzle.insert(migrationsSchema).values({\n name: 'dev',\n batch: '-1',\n })\n } else {\n await db.drizzle\n .update(migrationsSchema)\n .set({\n updated_at: new Date(),\n })\n .where(eq(migrationsSchema.batch, '-1'))\n }\n}\n"],"names":["eq","numeric","timestamp","varchar","createRequire","prompts","require","url","pushDevSchema","db","pushSchema","apply","hasDataLoss","warnings","schema","drizzle","length","message","join","confirm","acceptWarnings","name","type","initial","onCancel","process","exit","migrationsSchema","pgSchema","table","batch","created_at","updated_at","devPush","select","from","where","insert","values","update","set","Date"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,EAAE,QAAQ,cAAa;AAChC,SAASC,OAAO,EAAEC,SAAS,EAAEC,OAAO,QAAQ,sBAAqB;AACjE,SAASC,aAAa,QAAQ,SAAQ;AACtC,OAAOC,aAAa,UAAS;AAI7B,MAAMC,UAAUF,cAAc,YAAYG,GAAG;AAE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IS;QAClB,GACCL,KAAK,CAACpC,GAAG2B,iBAAiBG,KAAK,EAAE;IACtC;AACF,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/db-postgres",
3
- "version": "3.0.0-canary.c13f9ba",
3
+ "version": "3.0.0-canary.ce278e4",
4
4
  "description": "The officially supported Postgres database adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -42,20 +42,23 @@
42
42
  "pg": "8.11.3",
43
43
  "prompts": "2.4.2",
44
44
  "to-snake-case": "1.0.0",
45
- "uuid": "9.0.0"
45
+ "uuid": "10.0.0"
46
46
  },
47
47
  "devDependencies": {
48
+ "@hyrious/esbuild-plugin-commonjs": "^0.2.4",
48
49
  "@types/pg": "8.10.2",
49
50
  "@types/to-snake-case": "1.0.0",
50
- "payload": "3.0.0-canary.c13f9ba",
51
- "@payloadcms/eslint-config": "1.1.1"
51
+ "esbuild": "^0.21.4",
52
+ "@payloadcms/eslint-config": "1.1.1",
53
+ "payload": "3.0.0-canary.ce278e4"
52
54
  },
53
55
  "peerDependencies": {
54
- "payload": "3.0.0-canary.c13f9ba"
56
+ "payload": "3.0.0-canary.ce278e4"
55
57
  },
56
58
  "scripts": {
57
- "build": "pnpm build:swc && pnpm build:types && pnpm renamePredefinedMigrations",
58
- "build:swc": "swc ./src -d ./dist --config-file .swcrc",
59
+ "build": "rimraf .dist && rimraf tsconfig.tsbuildinfo && pnpm build:types && pnpm build:swc && pnpm build:esbuild && pnpm renamePredefinedMigrations",
60
+ "build:esbuild": "echo skipping esbuild",
61
+ "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
59
62
  "build:types": "tsc --emitDeclarationOnly --outDir dist",
60
63
  "clean": "rimraf {dist,*.tsbuildinfo}",
61
64
  "renamePredefinedMigrations": "tsx ./scripts/renamePredefinedMigrations.ts"