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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. package/dist/connect.js.map +1 -1
  2. package/dist/count.js.map +1 -1
  3. package/dist/create.js.map +1 -1
  4. package/dist/createGlobal.d.ts +2 -2
  5. package/dist/createGlobal.d.ts.map +1 -1
  6. package/dist/createGlobal.js.map +1 -1
  7. package/dist/createGlobalVersion.js.map +1 -1
  8. package/dist/createMigration.js.map +1 -1
  9. package/dist/createVersion.js.map +1 -1
  10. package/dist/deleteMany.js.map +1 -1
  11. package/dist/deleteOne.js.map +1 -1
  12. package/dist/deleteVersions.js.map +1 -1
  13. package/dist/destroy.js.map +1 -1
  14. package/dist/exports/migration-utils.js.map +1 -1
  15. package/dist/find/buildFindManyArgs.d.ts.map +1 -1
  16. package/dist/find/buildFindManyArgs.js.map +1 -1
  17. package/dist/find/chainMethods.d.ts.map +1 -1
  18. package/dist/find/chainMethods.js.map +1 -1
  19. package/dist/find/findMany.js.map +1 -1
  20. package/dist/find/traverseFields.js.map +1 -1
  21. package/dist/find.js.map +1 -1
  22. package/dist/findGlobal.js.map +1 -1
  23. package/dist/findGlobalVersions.js.map +1 -1
  24. package/dist/findOne.js.map +1 -1
  25. package/dist/findVersions.js.map +1 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/init.js.map +1 -1
  28. package/dist/migrate.js.map +1 -1
  29. package/dist/migrateDown.js.map +1 -1
  30. package/dist/migrateFresh.js.map +1 -1
  31. package/dist/migrateRefresh.js.map +1 -1
  32. package/dist/migrateReset.js.map +1 -1
  33. package/dist/migrateStatus.js.map +1 -1
  34. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -1
  35. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
  36. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +0 -1
  37. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
  38. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -1
  39. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -1
  40. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -1
  41. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -1
  42. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -1
  43. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -1
  44. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -1
  45. package/dist/queries/buildAndOrConditions.js.map +1 -1
  46. package/dist/queries/buildQuery.d.ts.map +1 -1
  47. package/dist/queries/buildQuery.js.map +1 -1
  48. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +1 -1
  49. package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +1 -1
  50. package/dist/queries/createJSONQuery/index.js.map +1 -1
  51. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  52. package/dist/queries/operatorMap.js.map +1 -1
  53. package/dist/queries/parseParams.js.map +1 -1
  54. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  55. package/dist/queries/selectDistinct.d.ts.map +1 -1
  56. package/dist/queries/selectDistinct.js.map +1 -1
  57. package/dist/queryDrafts.js.map +1 -1
  58. package/dist/schema/build.js.map +1 -1
  59. package/dist/schema/createIndex.js.map +1 -1
  60. package/dist/schema/createTableName.js.map +1 -1
  61. package/dist/schema/idToUUID.js.map +1 -1
  62. package/dist/schema/parentIDColumnMap.js.map +1 -1
  63. package/dist/schema/setColumnID.js.map +1 -1
  64. package/dist/schema/traverseFields.js.map +1 -1
  65. package/dist/schema/validateExistingBlockIsIdentical.js.map +1 -1
  66. package/dist/transactions/beginTransaction.js.map +1 -1
  67. package/dist/transactions/commitTransaction.js.map +1 -1
  68. package/dist/transactions/rollbackTransaction.js.map +1 -1
  69. package/dist/transform/read/hasManyNumber.js.map +1 -1
  70. package/dist/transform/read/hasManyText.js.map +1 -1
  71. package/dist/transform/read/index.d.ts +2 -3
  72. package/dist/transform/read/index.d.ts.map +1 -1
  73. package/dist/transform/read/index.js.map +1 -1
  74. package/dist/transform/read/relationship.js.map +1 -1
  75. package/dist/transform/read/traverseFields.d.ts.map +1 -1
  76. package/dist/transform/read/traverseFields.js.map +1 -1
  77. package/dist/transform/write/array.js.map +1 -1
  78. package/dist/transform/write/blocks.js.map +1 -1
  79. package/dist/transform/write/index.js.map +1 -1
  80. package/dist/transform/write/numbers.js.map +1 -1
  81. package/dist/transform/write/relationships.js.map +1 -1
  82. package/dist/transform/write/selects.js.map +1 -1
  83. package/dist/transform/write/texts.js.map +1 -1
  84. package/dist/transform/write/traverseFields.js.map +1 -1
  85. package/dist/transform/write/types.js.map +1 -1
  86. package/dist/types.js.map +1 -1
  87. package/dist/update.js.map +1 -1
  88. package/dist/updateGlobal.d.ts +2 -2
  89. package/dist/updateGlobal.d.ts.map +1 -1
  90. package/dist/updateGlobal.js.map +1 -1
  91. package/dist/updateGlobalVersion.js.map +1 -1
  92. package/dist/updateVersion.js.map +1 -1
  93. package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +1 -1
  94. package/dist/upsertRow/deleteExistingArrayRows.js.map +1 -1
  95. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
  96. package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -1
  97. package/dist/upsertRow/index.d.ts +1 -1
  98. package/dist/upsertRow/index.d.ts.map +1 -1
  99. package/dist/upsertRow/index.js.map +1 -1
  100. package/dist/upsertRow/insertArrays.d.ts.map +1 -1
  101. package/dist/upsertRow/insertArrays.js.map +1 -1
  102. package/dist/upsertRow/types.js.map +1 -1
  103. package/dist/utilities/appendPrefixToKeys.d.ts.map +1 -1
  104. package/dist/utilities/appendPrefixToKeys.js.map +1 -1
  105. package/dist/utilities/createBlocksMap.d.ts.map +1 -1
  106. package/dist/utilities/createBlocksMap.js.map +1 -1
  107. package/dist/utilities/createMigrationTable.d.ts.map +1 -1
  108. package/dist/utilities/createMigrationTable.js.map +1 -1
  109. package/dist/utilities/createRelationshipMap.d.ts.map +1 -1
  110. package/dist/utilities/createRelationshipMap.js.map +1 -1
  111. package/dist/utilities/hasLocalesTable.js.map +1 -1
  112. package/dist/utilities/isArrayOfRows.js.map +1 -1
  113. package/dist/utilities/migrationTableExists.d.ts.map +1 -1
  114. package/dist/utilities/migrationTableExists.js.map +1 -1
  115. package/dist/utilities/parseError.js.map +1 -1
  116. package/dist/utilities/pushDevSchema.js.map +1 -1
  117. package/package.json +9 -9
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/transform/write/blocks.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { BlockField } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { BlockRowToInsert, RelationshipToDelete } from './types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: PostgresAdapter\n baseTableName: string\n blocks: {\n [blockType: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n data: Record<string, unknown>[]\n field: BlockField\n locale?: string\n numbers: Record<string, unknown>[]\n path: string\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n selects: {\n [tableName: string]: Record<string, unknown>[]\n }\n texts: Record<string, unknown>[]\n}\nexport const transformBlocks = ({\n adapter,\n baseTableName,\n blocks,\n blocksToDelete,\n data,\n field,\n locale,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n}: Args) => {\n data.forEach((blockRow, i) => {\n if (typeof blockRow.blockType !== 'string') return\n const matchedBlock = field.blocks.find(({ slug }) => slug === blockRow.blockType)\n if (!matchedBlock) return\n const blockType = toSnakeCase(blockRow.blockType)\n\n if (!blocks[blockType]) blocks[blockType] = []\n\n const newRow: BlockRowToInsert = {\n arrays: {},\n locales: {},\n row: {\n _order: i + 1,\n _path: `${path}${field.name}`,\n },\n }\n\n if (field.localized && locale) newRow.row._locale = locale\n\n const blockTableName = adapter.tableNameMap.get(`${baseTableName}_blocks_${blockType}`)\n\n const hasUUID = adapter.tables[blockTableName]._uuid\n\n // If we have declared a _uuid field on arrays,\n // that means the ID has to be unique,\n // and our ids within arrays are not unique.\n // So move the ID to a uuid field for storage\n // and allow the database to generate a serial id automatically\n if (hasUUID) {\n newRow.row._uuid = blockRow.id\n delete blockRow.id\n }\n\n traverseFields({\n adapter,\n arrays: newRow.arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: '',\n data: blockRow,\n fieldPrefix: '',\n fields: matchedBlock.fields,\n locales: newRow.locales,\n numbers,\n parentTableName: blockTableName,\n path: `${path || ''}${field.name}.${i}.`,\n relationships,\n relationshipsToDelete,\n row: newRow.row,\n selects,\n texts,\n })\n\n blocks[blockType].push(newRow)\n })\n}\n"],"names":["toSnakeCase","traverseFields","transformBlocks","adapter","baseTableName","blocks","blocksToDelete","data","field","locale","numbers","path","relationships","relationshipsToDelete","selects","texts","forEach","blockRow","i","blockType","matchedBlock","find","slug","newRow","arrays","locales","row","_order","_path","name","localized","_locale","blockTableName","tableNameMap","get","hasUUID","tables","_uuid","id","columnPrefix","fieldPrefix","fields","parentTableName","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAGpC,OAAOA,iBAAiB,gBAAe;AAKvC,SAASC,cAAc,QAAQ,sBAAqB;AAqBpD,OAAO,MAAMC,kBAAkB,CAAC,EAC9BC,OAAO,EACPC,aAAa,EACbC,MAAM,EACNC,cAAc,EACdC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,IAAI,EACJC,aAAa,EACbC,qBAAqB,EACrBC,OAAO,EACPC,KAAK,EACA;IACLR,KAAKS,OAAO,CAAC,CAACC,UAAUC;QACtB,IAAI,OAAOD,SAASE,SAAS,KAAK,UAAU;QAC5C,MAAMC,eAAeZ,MAAMH,MAAM,CAACgB,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version":3,"sources":["../../../src/transform/write/blocks.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { BlockField } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { BlockRowToInsert, RelationshipToDelete } from './types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: PostgresAdapter\n baseTableName: string\n blocks: {\n [blockType: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n data: Record<string, unknown>[]\n field: BlockField\n locale?: string\n numbers: Record<string, unknown>[]\n path: string\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n selects: {\n [tableName: string]: Record<string, unknown>[]\n }\n texts: Record<string, unknown>[]\n}\nexport const transformBlocks = ({\n adapter,\n baseTableName,\n blocks,\n blocksToDelete,\n data,\n field,\n locale,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n}: Args) => {\n data.forEach((blockRow, i) => {\n if (typeof blockRow.blockType !== 'string') return\n const matchedBlock = field.blocks.find(({ slug }) => slug === blockRow.blockType)\n if (!matchedBlock) return\n const blockType = toSnakeCase(blockRow.blockType)\n\n if (!blocks[blockType]) blocks[blockType] = []\n\n const newRow: BlockRowToInsert = {\n arrays: {},\n locales: {},\n row: {\n _order: i + 1,\n _path: `${path}${field.name}`,\n },\n }\n\n if (field.localized && locale) newRow.row._locale = locale\n\n const blockTableName = adapter.tableNameMap.get(`${baseTableName}_blocks_${blockType}`)\n\n const hasUUID = adapter.tables[blockTableName]._uuid\n\n // If we have declared a _uuid field on arrays,\n // that means the ID has to be unique,\n // and our ids within arrays are not unique.\n // So move the ID to a uuid field for storage\n // and allow the database to generate a serial id automatically\n if (hasUUID) {\n newRow.row._uuid = blockRow.id\n delete blockRow.id\n }\n\n traverseFields({\n adapter,\n arrays: newRow.arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: '',\n data: blockRow,\n fieldPrefix: '',\n fields: matchedBlock.fields,\n locales: newRow.locales,\n numbers,\n parentTableName: blockTableName,\n path: `${path || ''}${field.name}.${i}.`,\n relationships,\n relationshipsToDelete,\n row: newRow.row,\n selects,\n texts,\n })\n\n blocks[blockType].push(newRow)\n })\n}\n"],"names":["toSnakeCase","traverseFields","transformBlocks","adapter","baseTableName","blocks","blocksToDelete","data","field","locale","numbers","path","relationships","relationshipsToDelete","selects","texts","forEach","blockRow","i","blockType","matchedBlock","find","slug","newRow","arrays","locales","row","_order","_path","name","localized","_locale","blockTableName","tableNameMap","get","hasUUID","tables","_uuid","id","columnPrefix","fieldPrefix","fields","parentTableName","push"],"mappings":"AAAA,oCAAoC,GAGpC,OAAOA,iBAAiB,gBAAe;AAKvC,SAASC,cAAc,QAAQ,sBAAqB;AAqBpD,OAAO,MAAMC,kBAAkB,CAAC,EAC9BC,OAAO,EACPC,aAAa,EACbC,MAAM,EACNC,cAAc,EACdC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,IAAI,EACJC,aAAa,EACbC,qBAAqB,EACrBC,OAAO,EACPC,KAAK,EACA;IACLR,KAAKS,OAAO,CAAC,CAACC,UAAUC;QACtB,IAAI,OAAOD,SAASE,SAAS,KAAK,UAAU;QAC5C,MAAMC,eAAeZ,MAAMH,MAAM,CAACgB,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASL,SAASE,SAAS;QAChF,IAAI,CAACC,cAAc;QACnB,MAAMD,YAAYnB,YAAYiB,SAASE,SAAS;QAEhD,IAAI,CAACd,MAAM,CAACc,UAAU,EAAEd,MAAM,CAACc,UAAU,GAAG,EAAE;QAE9C,MAAMI,SAA2B;YAC/BC,QAAQ,CAAC;YACTC,SAAS,CAAC;YACVC,KAAK;gBACHC,QAAQT,IAAI;gBACZU,OAAO,CAAC,EAAEjB,KAAK,EAAEH,MAAMqB,IAAI,CAAC,CAAC;YAC/B;QACF;QAEA,IAAIrB,MAAMsB,SAAS,IAAIrB,QAAQc,OAAOG,GAAG,CAACK,OAAO,GAAGtB;QAEpD,MAAMuB,iBAAiB7B,QAAQ8B,YAAY,CAACC,GAAG,CAAC,CAAC,EAAE9B,cAAc,QAAQ,EAAEe,UAAU,CAAC;QAEtF,MAAMgB,UAAUhC,QAAQiC,MAAM,CAACJ,eAAe,CAACK,KAAK;QAEpD,+CAA+C;QAC/C,sCAAsC;QACtC,4CAA4C;QAC5C,6CAA6C;QAC7C,+DAA+D;QAC/D,IAAIF,SAAS;YACXZ,OAAOG,GAAG,CAACW,KAAK,GAAGpB,SAASqB,EAAE;YAC9B,OAAOrB,SAASqB,EAAE;QACpB;QAEArC,eAAe;YACbE;YACAqB,QAAQD,OAAOC,MAAM;YACrBpB;YACAC;YACAC;YACAiC,cAAc;YACdhC,MAAMU;YACNuB,aAAa;YACbC,QAAQrB,aAAaqB,MAAM;YAC3BhB,SAASF,OAAOE,OAAO;YACvBf;YACAgC,iBAAiBV;YACjBrB,MAAM,CAAC,EAAEA,QAAQ,GAAG,EAAEH,MAAMqB,IAAI,CAAC,CAAC,EAAEX,EAAE,CAAC,CAAC;YACxCN;YACAC;YACAa,KAAKH,OAAOG,GAAG;YACfZ;YACAC;QACF;QAEAV,MAAM,CAACc,UAAU,CAACwB,IAAI,CAACpB;IACzB;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/transform/write/index.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Field } from 'payload'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { RowToInsert } from './types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: PostgresAdapter\n data: Record<string, unknown>\n fields: Field[]\n path?: string\n tableName: string\n}\n\nexport const transformForWrite = ({\n adapter,\n data,\n fields,\n path = '',\n tableName,\n}: Args): RowToInsert => {\n // Split out the incoming data into rows to insert / delete\n const rowToInsert: RowToInsert = {\n arrays: {},\n blocks: {},\n blocksToDelete: new Set(),\n locales: {},\n numbers: [],\n relationships: [],\n relationshipsToDelete: [],\n row: {},\n selects: {},\n texts: [],\n }\n\n // This function is responsible for building up the\n // above rowToInsert\n traverseFields({\n adapter,\n arrays: rowToInsert.arrays,\n baseTableName: tableName,\n blocks: rowToInsert.blocks,\n blocksToDelete: rowToInsert.blocksToDelete,\n columnPrefix: '',\n data,\n fieldPrefix: '',\n fields,\n locales: rowToInsert.locales,\n numbers: rowToInsert.numbers,\n parentTableName: tableName,\n path,\n relationships: rowToInsert.relationships,\n relationshipsToDelete: rowToInsert.relationshipsToDelete,\n row: rowToInsert.row,\n selects: rowToInsert.selects,\n texts: rowToInsert.texts,\n })\n\n return rowToInsert\n}\n"],"names":["traverseFields","transformForWrite","adapter","data","fields","path","tableName","rowToInsert","arrays","blocks","blocksToDelete","Set","locales","numbers","relationships","relationshipsToDelete","row","selects","texts","baseTableName","columnPrefix","fieldPrefix","parentTableName"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAMpC,SAASA,cAAc,QAAQ,sBAAqB;AAUpD,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,OAAO,EACPC,IAAI,EACJC,MAAM,EACNC,OAAO,EAAE,EACTC,SAAS,EACJ;IACL,2DAA2D;IAC3D,MAAMC,cAA2B;QAC/BC,QAAQ,CAAC;QACTC,QAAQ,CAAC;QACTC,gBAAgB,IAAIC;QACpBC,SAAS,CAAC;QACVC,SAAS,EAAE;QACXC,eAAe,EAAE;QACjBC,uBAAuB,EAAE;QACzBC,KAAK,CAAC;QACNC,SAAS,CAAC;QACVC,OAAO,EAAE;IACX;IAEA,mDAAmD;IACnD,oBAAoB;IACpBlB,eAAe;QACbE;QACAM,QAAQD,YAAYC,MAAM;QAC1BW,eAAeb;QACfG,QAAQF,YAAYE,MAAM;QAC1BC,gBAAgBH,YAAYG,cAAc;QAC1CU,cAAc;QACdjB;QACAkB,aAAa;QACbjB;QACAQ,SAASL,YAAYK,OAAO;QAC5BC,SAASN,YAAYM,OAAO;QAC5BS,iBAAiBhB;QACjBD;QACAS,eAAeP,YAAYO,aAAa;QACxCC,uBAAuBR,YAAYQ,qBAAqB;QACxDC,KAAKT,YAAYS,GAAG;QACpBC,SAASV,YAAYU,OAAO;QAC5BC,OAAOX,YAAYW,KAAK;IAC1B;IAEA,OAAOX;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../src/transform/write/index.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Field } from 'payload'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { RowToInsert } from './types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: PostgresAdapter\n data: Record<string, unknown>\n fields: Field[]\n path?: string\n tableName: string\n}\n\nexport const transformForWrite = ({\n adapter,\n data,\n fields,\n path = '',\n tableName,\n}: Args): RowToInsert => {\n // Split out the incoming data into rows to insert / delete\n const rowToInsert: RowToInsert = {\n arrays: {},\n blocks: {},\n blocksToDelete: new Set(),\n locales: {},\n numbers: [],\n relationships: [],\n relationshipsToDelete: [],\n row: {},\n selects: {},\n texts: [],\n }\n\n // This function is responsible for building up the\n // above rowToInsert\n traverseFields({\n adapter,\n arrays: rowToInsert.arrays,\n baseTableName: tableName,\n blocks: rowToInsert.blocks,\n blocksToDelete: rowToInsert.blocksToDelete,\n columnPrefix: '',\n data,\n fieldPrefix: '',\n fields,\n locales: rowToInsert.locales,\n numbers: rowToInsert.numbers,\n parentTableName: tableName,\n path,\n relationships: rowToInsert.relationships,\n relationshipsToDelete: rowToInsert.relationshipsToDelete,\n row: rowToInsert.row,\n selects: rowToInsert.selects,\n texts: rowToInsert.texts,\n })\n\n return rowToInsert\n}\n"],"names":["traverseFields","transformForWrite","adapter","data","fields","path","tableName","rowToInsert","arrays","blocks","blocksToDelete","Set","locales","numbers","relationships","relationshipsToDelete","row","selects","texts","baseTableName","columnPrefix","fieldPrefix","parentTableName"],"mappings":"AAAA,oCAAoC,GAMpC,SAASA,cAAc,QAAQ,sBAAqB;AAUpD,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,OAAO,EACPC,IAAI,EACJC,MAAM,EACNC,OAAO,EAAE,EACTC,SAAS,EACJ;IACL,2DAA2D;IAC3D,MAAMC,cAA2B;QAC/BC,QAAQ,CAAC;QACTC,QAAQ,CAAC;QACTC,gBAAgB,IAAIC;QACpBC,SAAS,CAAC;QACVC,SAAS,EAAE;QACXC,eAAe,EAAE;QACjBC,uBAAuB,EAAE;QACzBC,KAAK,CAAC;QACNC,SAAS,CAAC;QACVC,OAAO,EAAE;IACX;IAEA,mDAAmD;IACnD,oBAAoB;IACpBlB,eAAe;QACbE;QACAM,QAAQD,YAAYC,MAAM;QAC1BW,eAAeb;QACfG,QAAQF,YAAYE,MAAM;QAC1BC,gBAAgBH,YAAYG,cAAc;QAC1CU,cAAc;QACdjB;QACAkB,aAAa;QACbjB;QACAQ,SAASL,YAAYK,OAAO;QAC5BC,SAASN,YAAYM,OAAO;QAC5BS,iBAAiBhB;QACjBD;QACAS,eAAeP,YAAYO,aAAa;QACxCC,uBAAuBR,YAAYQ,qBAAqB;QACxDC,KAAKT,YAAYS,GAAG;QACpBC,SAASV,YAAYU,OAAO;QAC5BC,OAAOX,YAAYW,KAAK;IAC1B;IAEA,OAAOX;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/transform/write/numbers.ts"],"sourcesContent":["type Args = {\n baseRow: Record<string, unknown>\n data: unknown[]\n numbers: Record<string, unknown>[]\n}\n\nexport const transformNumbers = ({ baseRow, data, numbers }: Args) => {\n data.forEach((val, i) => {\n numbers.push({\n ...baseRow,\n number: val,\n order: i + 1,\n })\n })\n}\n"],"names":["transformNumbers","baseRow","data","numbers","forEach","val","i","push","number","order"],"rangeMappings":";;;;;;;;","mappings":"AAMA,OAAO,MAAMA,mBAAmB,CAAC,EAAEC,OAAO,EAAEC,IAAI,EAAEC,OAAO,EAAQ;IAC/DD,KAAKE,OAAO,CAAC,CAACC,KAAKC;QACjBH,QAAQI,IAAI,CAAC;YACX,GAAGN,OAAO;YACVO,QAAQH;YACRI,OAAOH,IAAI;QACb;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/transform/write/numbers.ts"],"sourcesContent":["type Args = {\n baseRow: Record<string, unknown>\n data: unknown[]\n numbers: Record<string, unknown>[]\n}\n\nexport const transformNumbers = ({ baseRow, data, numbers }: Args) => {\n data.forEach((val, i) => {\n numbers.push({\n ...baseRow,\n number: val,\n order: i + 1,\n })\n })\n}\n"],"names":["transformNumbers","baseRow","data","numbers","forEach","val","i","push","number","order"],"mappings":"AAMA,OAAO,MAAMA,mBAAmB,CAAC,EAAEC,OAAO,EAAEC,IAAI,EAAEC,OAAO,EAAQ;IAC/DD,KAAKE,OAAO,CAAC,CAACC,KAAKC;QACjBH,QAAQI,IAAI,CAAC;YACX,GAAGN,OAAO;YACVO,QAAQH;YACRI,OAAOH,IAAI;QACb;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/transform/write/relationships.ts"],"sourcesContent":["import type { RelationshipField, UploadField } from 'payload'\n\nimport { valueIsValueWithRelation } from 'payload/shared'\n\ntype Args = {\n baseRow: Record<string, unknown>\n data: unknown\n field: RelationshipField | UploadField\n relationships: Record<string, unknown>[]\n}\n\nexport const transformRelationship = ({ baseRow, data, field, relationships }: Args) => {\n const relations = Array.isArray(data) ? data : [data]\n\n relations.forEach((relation, i) => {\n if (relation) {\n const relationRow = { ...baseRow }\n if ('hasMany' in field && field.hasMany) relationRow.order = i + 1\n\n if (Array.isArray(field.relationTo) && valueIsValueWithRelation(relation)) {\n relationRow[`${relation.relationTo}ID`] = relation.value\n relationships.push(relationRow)\n } else {\n relationRow[`${field.relationTo}ID`] = relation\n if (relation) relationships.push(relationRow)\n }\n }\n })\n}\n"],"names":["valueIsValueWithRelation","transformRelationship","baseRow","data","field","relationships","relations","Array","isArray","forEach","relation","i","relationRow","hasMany","order","relationTo","value","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,wBAAwB,QAAQ,iBAAgB;AASzD,OAAO,MAAMC,wBAAwB,CAAC,EAAEC,OAAO,EAAEC,IAAI,EAAEC,KAAK,EAAEC,aAAa,EAAQ;IACjF,MAAMC,YAAYC,MAAMC,OAAO,CAACL,QAAQA,OAAO;QAACA;KAAK;IAErDG,UAAUG,OAAO,CAAC,CAACC,UAAUC;QAC3B,IAAID,UAAU;YACZ,MAAME,cAAc;gBAAE,GAAGV,OAAO;YAAC;YACjC,IAAI,aAAaE,SAASA,MAAMS,OAAO,EAAED,YAAYE,KAAK,GAAGH,IAAI;YAEjE,IAAIJ,MAAMC,OAAO,CAACJ,MAAMW,UAAU,KAAKf,yBAAyBU,WAAW;gBACzEE,WAAW,CAAC,CAAC,EAAEF,SAASK,UAAU,CAAC,EAAE,CAAC,CAAC,GAAGL,SAASM,KAAK;gBACxDX,cAAcY,IAAI,CAACL;YACrB,OAAO;gBACLA,WAAW,CAAC,CAAC,EAAER,MAAMW,UAAU,CAAC,EAAE,CAAC,CAAC,GAAGL;gBACvC,IAAIA,UAAUL,cAAcY,IAAI,CAACL;YACnC;QACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/transform/write/relationships.ts"],"sourcesContent":["import type { RelationshipField, UploadField } from 'payload'\n\nimport { valueIsValueWithRelation } from 'payload/shared'\n\ntype Args = {\n baseRow: Record<string, unknown>\n data: unknown\n field: RelationshipField | UploadField\n relationships: Record<string, unknown>[]\n}\n\nexport const transformRelationship = ({ baseRow, data, field, relationships }: Args) => {\n const relations = Array.isArray(data) ? data : [data]\n\n relations.forEach((relation, i) => {\n if (relation) {\n const relationRow = { ...baseRow }\n if ('hasMany' in field && field.hasMany) relationRow.order = i + 1\n\n if (Array.isArray(field.relationTo) && valueIsValueWithRelation(relation)) {\n relationRow[`${relation.relationTo}ID`] = relation.value\n relationships.push(relationRow)\n } else {\n relationRow[`${field.relationTo}ID`] = relation\n if (relation) relationships.push(relationRow)\n }\n }\n })\n}\n"],"names":["valueIsValueWithRelation","transformRelationship","baseRow","data","field","relationships","relations","Array","isArray","forEach","relation","i","relationRow","hasMany","order","relationTo","value","push"],"mappings":"AAEA,SAASA,wBAAwB,QAAQ,iBAAgB;AASzD,OAAO,MAAMC,wBAAwB,CAAC,EAAEC,OAAO,EAAEC,IAAI,EAAEC,KAAK,EAAEC,aAAa,EAAQ;IACjF,MAAMC,YAAYC,MAAMC,OAAO,CAACL,QAAQA,OAAO;QAACA;KAAK;IAErDG,UAAUG,OAAO,CAAC,CAACC,UAAUC;QAC3B,IAAID,UAAU;YACZ,MAAME,cAAc;gBAAE,GAAGV,OAAO;YAAC;YACjC,IAAI,aAAaE,SAASA,MAAMS,OAAO,EAAED,YAAYE,KAAK,GAAGH,IAAI;YAEjE,IAAIJ,MAAMC,OAAO,CAACJ,MAAMW,UAAU,KAAKf,yBAAyBU,WAAW;gBACzEE,WAAW,CAAC,CAAC,EAAEF,SAASK,UAAU,CAAC,EAAE,CAAC,CAAC,GAAGL,SAASM,KAAK;gBACxDX,cAAcY,IAAI,CAACL;YACrB,OAAO;gBACLA,WAAW,CAAC,CAAC,EAAER,MAAMW,UAAU,CAAC,EAAE,CAAC,CAAC,GAAGL;gBACvC,IAAIA,UAAUL,cAAcY,IAAI,CAACL;YACnC;QACF;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/transform/write/selects.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport { isArrayOfRows } from '../../utilities/isArrayOfRows.js'\n\ntype Args = {\n data: unknown\n id?: unknown\n locale?: string\n}\n\nexport const transformSelects = ({ id, data, locale }: Args) => {\n const newRows: Record<string, unknown>[] = []\n\n if (isArrayOfRows(data)) {\n data.forEach((value, i) => {\n const newRow: Record<string, unknown> = {\n order: i + 1,\n parent: id,\n value,\n }\n\n if (locale) {\n newRow.locale = locale\n }\n\n newRows.push(newRow)\n })\n }\n\n return newRows\n}\n"],"names":["isArrayOfRows","transformSelects","id","data","locale","newRows","forEach","value","i","newRow","order","parent","push"],"rangeMappings":";;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GACpC,SAASA,aAAa,QAAQ,mCAAkC;AAQhE,OAAO,MAAMC,mBAAmB,CAAC,EAAEC,EAAE,EAAEC,IAAI,EAAEC,MAAM,EAAQ;IACzD,MAAMC,UAAqC,EAAE;IAE7C,IAAIL,cAAcG,OAAO;QACvBA,KAAKG,OAAO,CAAC,CAACC,OAAOC;YACnB,MAAMC,SAAkC;gBACtCC,OAAOF,IAAI;gBACXG,QAAQT;gBACRK;YACF;YAEA,IAAIH,QAAQ;gBACVK,OAAOL,MAAM,GAAGA;YAClB;YAEAC,QAAQO,IAAI,CAACH;QACf;IACF;IAEA,OAAOJ;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../src/transform/write/selects.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport { isArrayOfRows } from '../../utilities/isArrayOfRows.js'\n\ntype Args = {\n data: unknown\n id?: unknown\n locale?: string\n}\n\nexport const transformSelects = ({ id, data, locale }: Args) => {\n const newRows: Record<string, unknown>[] = []\n\n if (isArrayOfRows(data)) {\n data.forEach((value, i) => {\n const newRow: Record<string, unknown> = {\n order: i + 1,\n parent: id,\n value,\n }\n\n if (locale) {\n newRow.locale = locale\n }\n\n newRows.push(newRow)\n })\n }\n\n return newRows\n}\n"],"names":["isArrayOfRows","transformSelects","id","data","locale","newRows","forEach","value","i","newRow","order","parent","push"],"mappings":"AAAA,oCAAoC,GACpC,SAASA,aAAa,QAAQ,mCAAkC;AAQhE,OAAO,MAAMC,mBAAmB,CAAC,EAAEC,EAAE,EAAEC,IAAI,EAAEC,MAAM,EAAQ;IACzD,MAAMC,UAAqC,EAAE;IAE7C,IAAIL,cAAcG,OAAO;QACvBA,KAAKG,OAAO,CAAC,CAACC,OAAOC;YACnB,MAAMC,SAAkC;gBACtCC,OAAOF,IAAI;gBACXG,QAAQT;gBACRK;YACF;YAEA,IAAIH,QAAQ;gBACVK,OAAOL,MAAM,GAAGA;YAClB;YAEAC,QAAQO,IAAI,CAACH;QACf;IACF;IAEA,OAAOJ;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/transform/write/texts.ts"],"sourcesContent":["type Args = {\n baseRow: Record<string, unknown>\n data: unknown[]\n texts: Record<string, unknown>[]\n}\n\nexport const transformTexts = ({ baseRow, data, texts }: Args) => {\n data.forEach((val, i) => {\n texts.push({\n ...baseRow,\n order: i + 1,\n text: val,\n })\n })\n}\n"],"names":["transformTexts","baseRow","data","texts","forEach","val","i","push","order","text"],"rangeMappings":";;;;;;;;","mappings":"AAMA,OAAO,MAAMA,iBAAiB,CAAC,EAAEC,OAAO,EAAEC,IAAI,EAAEC,KAAK,EAAQ;IAC3DD,KAAKE,OAAO,CAAC,CAACC,KAAKC;QACjBH,MAAMI,IAAI,CAAC;YACT,GAAGN,OAAO;YACVO,OAAOF,IAAI;YACXG,MAAMJ;QACR;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/transform/write/texts.ts"],"sourcesContent":["type Args = {\n baseRow: Record<string, unknown>\n data: unknown[]\n texts: Record<string, unknown>[]\n}\n\nexport const transformTexts = ({ baseRow, data, texts }: Args) => {\n data.forEach((val, i) => {\n texts.push({\n ...baseRow,\n order: i + 1,\n text: val,\n })\n })\n}\n"],"names":["transformTexts","baseRow","data","texts","forEach","val","i","push","order","text"],"mappings":"AAMA,OAAO,MAAMA,iBAAiB,CAAC,EAAEC,OAAO,EAAEC,IAAI,EAAEC,KAAK,EAAQ;IAC3DD,KAAKE,OAAO,CAAC,CAACC,KAAKC;QACjBH,MAAMI,IAAI,CAAC;YACT,GAAGN,OAAO;YACVO,OAAOF,IAAI;YACXG,MAAMJ;QACR;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/transform/write/traverseFields.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Field } from 'payload'\n\nimport { fieldAffectsData } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { ArrayRowToInsert, BlockRowToInsert, RelationshipToDelete } from './types.js'\n\nimport { isArrayOfRows } from '../../utilities/isArrayOfRows.js'\nimport { transformArray } from './array.js'\nimport { transformBlocks } from './blocks.js'\nimport { transformNumbers } from './numbers.js'\nimport { transformRelationship } from './relationships.js'\nimport { transformSelects } from './selects.js'\nimport { transformTexts } from './texts.js'\n\ntype Args = {\n adapter: PostgresAdapter\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n /**\n * This is the name of the base table\n */\n baseTableName: string\n blocks: {\n [blockType: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n /**\n * A snake-case field prefix, representing prior fields\n * Ex: my_group_my_named_tab_\n */\n columnPrefix: string\n data: Record<string, unknown>\n existingLocales?: Record<string, unknown>[]\n /**\n * A prefix that will retain camel-case formatting, representing prior fields\n * Ex: myGroup_myNamedTab_\n */\n fieldPrefix: string\n fields: Field[]\n forcedLocale?: string\n locales: {\n [locale: string]: Record<string, unknown>\n }\n numbers: Record<string, unknown>[]\n /**\n * This is the name of the parent table\n */\n parentTableName: string\n path: string\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n row: Record<string, unknown>\n selects: {\n [tableName: string]: Record<string, unknown>[]\n }\n texts: Record<string, unknown>[]\n}\n\nexport const traverseFields = ({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix,\n data,\n existingLocales,\n fieldPrefix,\n fields,\n forcedLocale,\n locales,\n numbers,\n parentTableName,\n path,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n}: Args) => {\n fields.forEach((field) => {\n let columnName = ''\n let fieldName = ''\n let fieldData: unknown\n\n if (fieldAffectsData(field)) {\n columnName = `${columnPrefix || ''}${toSnakeCase(field.name)}`\n fieldName = `${fieldPrefix || ''}${field.name}`\n fieldData = data[field.name]\n }\n\n if (field.type === 'array') {\n const arrayTableName = adapter.tableNameMap.get(`${parentTableName}_${columnName}`)\n\n if (!arrays[arrayTableName]) arrays[arrayTableName] = []\n\n if (field.localized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n const newRows = transformArray({\n adapter,\n arrayTableName,\n baseTableName,\n blocks,\n blocksToDelete,\n data: localeData,\n field,\n locale: localeKey,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n })\n\n arrays[arrayTableName] = arrays[arrayTableName].concat(newRows)\n }\n })\n }\n } else {\n const newRows = transformArray({\n adapter,\n arrayTableName,\n baseTableName,\n blocks,\n blocksToDelete,\n data: data[field.name],\n field,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n })\n\n arrays[arrayTableName] = arrays[arrayTableName].concat(newRows)\n }\n\n return\n }\n\n if (field.type === 'blocks') {\n field.blocks.forEach(({ slug }) => {\n blocksToDelete.add(toSnakeCase(slug))\n })\n\n if (field.localized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n transformBlocks({\n adapter,\n baseTableName,\n blocks,\n blocksToDelete,\n data: localeData,\n field,\n locale: localeKey,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n })\n }\n })\n }\n } else if (isArrayOfRows(fieldData)) {\n transformBlocks({\n adapter,\n baseTableName,\n blocks,\n blocksToDelete,\n data: fieldData,\n field,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n })\n }\n\n return\n }\n\n if (field.type === 'group') {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n if (field.localized) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnName}_`,\n data: localeData as Record<string, unknown>,\n existingLocales,\n fieldPrefix: `${fieldName}_`,\n fields: field.fields,\n forcedLocale: localeKey,\n locales,\n numbers,\n parentTableName,\n path: `${path || ''}${field.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n })\n } else {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnName}_`,\n data: data[field.name] as Record<string, unknown>,\n existingLocales,\n fieldPrefix: `${fieldName}_`,\n fields: field.fields,\n locales,\n numbers,\n parentTableName,\n path: `${path || ''}${field.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n }\n }\n\n return\n }\n\n if (field.type === 'tabs') {\n field.tabs.forEach((tab) => {\n if ('name' in tab) {\n if (typeof data[tab.name] === 'object' && data[tab.name] !== null) {\n if (tab.localized) {\n Object.entries(data[tab.name]).forEach(([localeKey, localeData]) => {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnPrefix || ''}${toSnakeCase(tab.name)}_`,\n data: localeData as Record<string, unknown>,\n existingLocales,\n fieldPrefix: `${fieldPrefix || ''}${tab.name}_`,\n fields: tab.fields,\n forcedLocale: localeKey,\n locales,\n numbers,\n parentTableName,\n path: `${path || ''}${tab.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n })\n } else {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnPrefix || ''}${toSnakeCase(tab.name)}_`,\n data: data[tab.name] as Record<string, unknown>,\n existingLocales,\n fieldPrefix: `${fieldPrefix || ''}${tab.name}_`,\n fields: tab.fields,\n locales,\n numbers,\n parentTableName,\n path: `${path || ''}${tab.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n }\n }\n } else {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix,\n data,\n existingLocales,\n fieldPrefix,\n fields: tab.fields,\n locales,\n numbers,\n parentTableName,\n path,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n }\n })\n }\n\n if (field.type === 'row' || field.type === 'collapsible') {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix,\n data,\n existingLocales,\n fieldPrefix,\n fields: field.fields,\n locales,\n numbers,\n parentTableName,\n path,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n const relationshipPath = `${path || ''}${field.name}`\n\n if (\n field.localized &&\n (Array.isArray(field.relationTo) || ('hasMany' in field && field.hasMany))\n ) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (localeData === null) {\n relationshipsToDelete.push({\n locale: localeKey,\n path: relationshipPath,\n })\n return\n }\n\n transformRelationship({\n baseRow: {\n locale: localeKey,\n path: relationshipPath,\n },\n data: localeData,\n field,\n relationships,\n })\n })\n }\n return\n } else if (Array.isArray(field.relationTo) || ('hasMany' in field && field.hasMany)) {\n if (fieldData === null || (Array.isArray(fieldData) && fieldData.length === 0)) {\n relationshipsToDelete.push({ path: relationshipPath })\n return\n }\n\n transformRelationship({\n baseRow: {\n path: relationshipPath,\n },\n data: fieldData,\n field,\n relationships,\n })\n return\n } else {\n if (\n !field.localized &&\n fieldData &&\n typeof fieldData === 'object' &&\n 'id' in fieldData &&\n fieldData?.id\n ) {\n fieldData = fieldData.id\n } else if (field.localized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (typeof localeData === 'object') {\n if (localeData && 'id' in localeData && localeData?.id) {\n fieldData[localeKey] = localeData.id\n }\n } else {\n fieldData[localeKey] = localeData\n }\n })\n }\n }\n }\n }\n\n if (field.type === 'text' && field.hasMany) {\n const textPath = `${path || ''}${field.name}`\n\n if (field.localized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n transformTexts({\n baseRow: {\n locale: localeKey,\n path: textPath,\n },\n data: localeData,\n texts,\n })\n }\n })\n }\n } else if (Array.isArray(fieldData)) {\n transformTexts({\n baseRow: {\n path: textPath,\n },\n data: fieldData,\n texts,\n })\n }\n\n return\n }\n\n if (field.type === 'number' && field.hasMany) {\n const numberPath = `${path || ''}${field.name}`\n\n if (field.localized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n transformNumbers({\n baseRow: {\n locale: localeKey,\n path: numberPath,\n },\n data: localeData,\n numbers,\n })\n }\n })\n }\n } else if (Array.isArray(fieldData)) {\n transformNumbers({\n baseRow: {\n path: numberPath,\n },\n data: fieldData,\n numbers,\n })\n }\n\n return\n }\n\n if (field.type === 'select' && field.hasMany) {\n const selectTableName = adapter.tableNameMap.get(`${parentTableName}_${columnName}`)\n if (!selects[selectTableName]) selects[selectTableName] = []\n\n if (field.localized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n const newRows = transformSelects({\n id: data._uuid || data.id,\n data: localeData,\n locale: localeKey,\n })\n\n selects[selectTableName] = selects[selectTableName].concat(newRows)\n }\n })\n }\n } else if (Array.isArray(data[field.name])) {\n const newRows = transformSelects({\n id: data._uuid || data.id,\n data: data[field.name],\n })\n\n selects[selectTableName] = selects[selectTableName].concat(newRows)\n }\n\n return\n }\n\n if (fieldAffectsData(field)) {\n const valuesToTransform: { localeKey?: string; ref: unknown; value: unknown }[] = []\n\n if (field.localized) {\n if (typeof fieldData === 'object' && fieldData !== null) {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (!locales[localeKey]) locales[localeKey] = {}\n\n valuesToTransform.push({\n localeKey,\n ref: locales,\n value: localeData,\n })\n })\n }\n } else {\n let ref = row\n\n if (forcedLocale) {\n if (!locales[forcedLocale]) locales[forcedLocale] = {}\n ref = locales[forcedLocale]\n }\n\n valuesToTransform.push({ ref, value: fieldData })\n }\n\n valuesToTransform.forEach(({ localeKey, ref, value }) => {\n if (typeof value !== 'undefined') {\n let formattedValue = value\n\n if (field.type === 'date' && field.name === 'updatedAt') {\n formattedValue = new Date().toISOString()\n }\n\n if (localeKey) {\n ref[localeKey][fieldName] = formattedValue\n } else {\n ref[fieldName] = formattedValue\n }\n }\n })\n }\n })\n}\n"],"names":["fieldAffectsData","toSnakeCase","isArrayOfRows","transformArray","transformBlocks","transformNumbers","transformRelationship","transformSelects","transformTexts","traverseFields","adapter","arrays","baseTableName","blocks","blocksToDelete","columnPrefix","data","existingLocales","fieldPrefix","fields","forcedLocale","locales","numbers","parentTableName","path","relationships","relationshipsToDelete","row","selects","texts","forEach","field","columnName","fieldName","fieldData","name","type","arrayTableName","tableNameMap","get","localized","Object","entries","localeKey","localeData","Array","isArray","newRows","locale","concat","slug","add","tabs","tab","relationshipPath","relationTo","hasMany","push","baseRow","length","id","textPath","numberPath","selectTableName","_uuid","valuesToTransform","ref","value","formattedValue","Date","toISOString"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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a,GAAG,CAAC;oBACrD8C,MAAM7C,OAAO,CAACD,aAAa;gBAC7B;gBAEA6C,kBAAkBR,IAAI,CAAC;oBAAES;oBAAKC,OAAOjC;gBAAU;YACjD;YAEA+B,kBAAkBnC,OAAO,CAAC,CAAC,EAAEa,SAAS,EAAEuB,GAAG,EAAEC,KAAK,EAAE;gBAClD,IAAI,OAAOA,UAAU,aAAa;oBAChC,IAAIC,iBAAiBD;oBAErB,IAAIpC,MAAMK,IAAI,KAAK,UAAUL,MAAMI,IAAI,KAAK,aAAa;wBACvDiC,iBAAiB,IAAIC,OAAOC,WAAW;oBACzC;oBAEA,IAAI3B,WAAW;wBACbuB,GAAG,CAACvB,UAAU,CAACV,UAAU,GAAGmC;oBAC9B,OAAO;wBACLF,GAAG,CAACjC,UAAU,GAAGmC;oBACnB;gBACF;YACF;QACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/transform/write/traverseFields.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Field } from 'payload'\n\nimport { fieldAffectsData } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { ArrayRowToInsert, BlockRowToInsert, RelationshipToDelete } from './types.js'\n\nimport { isArrayOfRows } from '../../utilities/isArrayOfRows.js'\nimport { transformArray } from './array.js'\nimport { transformBlocks } from './blocks.js'\nimport { transformNumbers } from './numbers.js'\nimport { transformRelationship } from './relationships.js'\nimport { transformSelects } from './selects.js'\nimport { transformTexts } from './texts.js'\n\ntype Args = {\n adapter: PostgresAdapter\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n /**\n * This is the name of the base table\n */\n baseTableName: string\n blocks: {\n [blockType: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n /**\n * A snake-case field prefix, representing prior fields\n * Ex: my_group_my_named_tab_\n */\n columnPrefix: string\n data: Record<string, unknown>\n existingLocales?: Record<string, unknown>[]\n /**\n * A prefix that will retain camel-case formatting, representing prior fields\n * Ex: myGroup_myNamedTab_\n */\n fieldPrefix: string\n fields: Field[]\n forcedLocale?: string\n locales: {\n [locale: string]: Record<string, unknown>\n }\n numbers: Record<string, unknown>[]\n /**\n * This is the name of the parent table\n */\n parentTableName: string\n path: string\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n row: Record<string, unknown>\n selects: {\n [tableName: string]: Record<string, unknown>[]\n }\n texts: Record<string, unknown>[]\n}\n\nexport const traverseFields = ({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix,\n data,\n existingLocales,\n fieldPrefix,\n fields,\n forcedLocale,\n locales,\n numbers,\n parentTableName,\n path,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n}: Args) => {\n fields.forEach((field) => {\n let columnName = ''\n let fieldName = ''\n let fieldData: unknown\n\n if (fieldAffectsData(field)) {\n columnName = `${columnPrefix || ''}${toSnakeCase(field.name)}`\n fieldName = `${fieldPrefix || ''}${field.name}`\n fieldData = data[field.name]\n }\n\n if (field.type === 'array') {\n const arrayTableName = adapter.tableNameMap.get(`${parentTableName}_${columnName}`)\n\n if (!arrays[arrayTableName]) arrays[arrayTableName] = []\n\n if (field.localized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n const newRows = transformArray({\n adapter,\n arrayTableName,\n baseTableName,\n blocks,\n blocksToDelete,\n data: localeData,\n field,\n locale: localeKey,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n })\n\n arrays[arrayTableName] = arrays[arrayTableName].concat(newRows)\n }\n })\n }\n } else {\n const newRows = transformArray({\n adapter,\n arrayTableName,\n baseTableName,\n blocks,\n blocksToDelete,\n data: data[field.name],\n field,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n })\n\n arrays[arrayTableName] = arrays[arrayTableName].concat(newRows)\n }\n\n return\n }\n\n if (field.type === 'blocks') {\n field.blocks.forEach(({ slug }) => {\n blocksToDelete.add(toSnakeCase(slug))\n })\n\n if (field.localized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n transformBlocks({\n adapter,\n baseTableName,\n blocks,\n blocksToDelete,\n data: localeData,\n field,\n locale: localeKey,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n })\n }\n })\n }\n } else if (isArrayOfRows(fieldData)) {\n transformBlocks({\n adapter,\n baseTableName,\n blocks,\n blocksToDelete,\n data: fieldData,\n field,\n numbers,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n })\n }\n\n return\n }\n\n if (field.type === 'group') {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n if (field.localized) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnName}_`,\n data: localeData as Record<string, unknown>,\n existingLocales,\n fieldPrefix: `${fieldName}_`,\n fields: field.fields,\n forcedLocale: localeKey,\n locales,\n numbers,\n parentTableName,\n path: `${path || ''}${field.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n })\n } else {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnName}_`,\n data: data[field.name] as Record<string, unknown>,\n existingLocales,\n fieldPrefix: `${fieldName}_`,\n fields: field.fields,\n locales,\n numbers,\n parentTableName,\n path: `${path || ''}${field.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n }\n }\n\n return\n }\n\n if (field.type === 'tabs') {\n field.tabs.forEach((tab) => {\n if ('name' in tab) {\n if (typeof data[tab.name] === 'object' && data[tab.name] !== null) {\n if (tab.localized) {\n Object.entries(data[tab.name]).forEach(([localeKey, localeData]) => {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnPrefix || ''}${toSnakeCase(tab.name)}_`,\n data: localeData as Record<string, unknown>,\n existingLocales,\n fieldPrefix: `${fieldPrefix || ''}${tab.name}_`,\n fields: tab.fields,\n forcedLocale: localeKey,\n locales,\n numbers,\n parentTableName,\n path: `${path || ''}${tab.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n })\n } else {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnPrefix || ''}${toSnakeCase(tab.name)}_`,\n data: data[tab.name] as Record<string, unknown>,\n existingLocales,\n fieldPrefix: `${fieldPrefix || ''}${tab.name}_`,\n fields: tab.fields,\n locales,\n numbers,\n parentTableName,\n path: `${path || ''}${tab.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n }\n }\n } else {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix,\n data,\n existingLocales,\n fieldPrefix,\n fields: tab.fields,\n locales,\n numbers,\n parentTableName,\n path,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n }\n })\n }\n\n if (field.type === 'row' || field.type === 'collapsible') {\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix,\n data,\n existingLocales,\n fieldPrefix,\n fields: field.fields,\n locales,\n numbers,\n parentTableName,\n path,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n })\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n const relationshipPath = `${path || ''}${field.name}`\n\n if (\n field.localized &&\n (Array.isArray(field.relationTo) || ('hasMany' in field && field.hasMany))\n ) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (localeData === null) {\n relationshipsToDelete.push({\n locale: localeKey,\n path: relationshipPath,\n })\n return\n }\n\n transformRelationship({\n baseRow: {\n locale: localeKey,\n path: relationshipPath,\n },\n data: localeData,\n field,\n relationships,\n })\n })\n }\n return\n } else if (Array.isArray(field.relationTo) || ('hasMany' in field && field.hasMany)) {\n if (fieldData === null || (Array.isArray(fieldData) && fieldData.length === 0)) {\n relationshipsToDelete.push({ path: relationshipPath })\n return\n }\n\n transformRelationship({\n baseRow: {\n path: relationshipPath,\n },\n data: fieldData,\n field,\n relationships,\n })\n return\n } else {\n if (\n !field.localized &&\n fieldData &&\n typeof fieldData === 'object' &&\n 'id' in fieldData &&\n fieldData?.id\n ) {\n fieldData = fieldData.id\n } else if (field.localized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (typeof localeData === 'object') {\n if (localeData && 'id' in localeData && localeData?.id) {\n fieldData[localeKey] = localeData.id\n }\n } else {\n fieldData[localeKey] = localeData\n }\n })\n }\n }\n }\n }\n\n if (field.type === 'text' && field.hasMany) {\n const textPath = `${path || ''}${field.name}`\n\n if (field.localized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n transformTexts({\n baseRow: {\n locale: localeKey,\n path: textPath,\n },\n data: localeData,\n texts,\n })\n }\n })\n }\n } else if (Array.isArray(fieldData)) {\n transformTexts({\n baseRow: {\n path: textPath,\n },\n data: fieldData,\n texts,\n })\n }\n\n return\n }\n\n if (field.type === 'number' && field.hasMany) {\n const numberPath = `${path || ''}${field.name}`\n\n if (field.localized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n transformNumbers({\n baseRow: {\n locale: localeKey,\n path: numberPath,\n },\n data: localeData,\n numbers,\n })\n }\n })\n }\n } else if (Array.isArray(fieldData)) {\n transformNumbers({\n baseRow: {\n path: numberPath,\n },\n data: fieldData,\n numbers,\n })\n }\n\n return\n }\n\n if (field.type === 'select' && field.hasMany) {\n const selectTableName = adapter.tableNameMap.get(`${parentTableName}_${columnName}`)\n if (!selects[selectTableName]) selects[selectTableName] = []\n\n if (field.localized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n const newRows = transformSelects({\n id: data._uuid || data.id,\n data: localeData,\n locale: localeKey,\n })\n\n selects[selectTableName] = selects[selectTableName].concat(newRows)\n }\n })\n }\n } else if (Array.isArray(data[field.name])) {\n const newRows = transformSelects({\n id: data._uuid || data.id,\n data: data[field.name],\n })\n\n selects[selectTableName] = selects[selectTableName].concat(newRows)\n }\n\n return\n }\n\n if (fieldAffectsData(field)) {\n const valuesToTransform: { localeKey?: string; ref: unknown; value: unknown }[] = []\n\n if (field.localized) {\n if (typeof fieldData === 'object' && fieldData !== null) {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (!locales[localeKey]) locales[localeKey] = {}\n\n valuesToTransform.push({\n localeKey,\n ref: locales,\n value: localeData,\n })\n })\n }\n } else {\n let ref = row\n\n if (forcedLocale) {\n if (!locales[forcedLocale]) locales[forcedLocale] = {}\n ref = locales[forcedLocale]\n }\n\n valuesToTransform.push({ ref, value: fieldData })\n }\n\n valuesToTransform.forEach(({ localeKey, ref, value }) => {\n if (typeof value !== 'undefined') {\n let formattedValue = value\n\n if (field.type === 'date' && field.name === 'updatedAt') {\n formattedValue = new Date().toISOString()\n }\n\n if (localeKey) {\n ref[localeKey][fieldName] = formattedValue\n } else {\n ref[fieldName] = formattedValue\n }\n }\n })\n }\n })\n}\n"],"names":["fieldAffectsData","toSnakeCase","isArrayOfRows","transformArray","transformBlocks","transformNumbers","transformRelationship","transformSelects","transformTexts","traverseFields","adapter","arrays","baseTableName","blocks","blocksToDelete","columnPrefix","data","existingLocales","fieldPrefix","fields","forcedLocale","locales","numbers","parentTableName","path","relationships","relationshipsToDelete","row","selects","texts","forEach","field","columnName","fieldName","fieldData","name","type","arrayTableName","tableNameMap","get","localized","Object","entries","localeKey","localeData","Array","isArray","newRows","locale","concat","slug","add","tabs","tab","relationshipPath","relationTo","hasMany","push","baseRow","length","id","textPath","numberPath","selectTableName","_uuid","valuesToTransform","ref","value","formattedValue","Date","toISOString"],"mappings":"AAAA,oCAAoC,GAGpC,SAASA,gBAAgB,QAAQ,iBAAgB;AACjD,OAAOC,iBAAiB,gBAAe;AAKvC,SAASC,aAAa,QAAQ,mCAAkC;AAChE,SAASC,cAAc,QAAQ,aAAY;AAC3C,SAASC,eAAe,QAAQ,cAAa;AAC7C,SAASC,gBAAgB,QAAQ,eAAc;AAC/C,SAASC,qBAAqB,QAAQ,qBAAoB;AAC1D,SAASC,gBAAgB,QAAQ,eAAc;AAC/C,SAASC,cAAc,QAAQ,aAAY;AA+C3C,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,OAAO,EACPC,MAAM,EACNC,aAAa,EACbC,MAAM,EACNC,cAAc,EACdC,YAAY,EACZC,IAAI,EACJC,eAAe,EACfC,WAAW,EACXC,MAAM,EACNC,YAAY,EACZC,OAAO,EACPC,OAAO,EACPC,eAAe,EACfC,IAAI,EACJC,aAAa,EACbC,qBAAqB,EACrBC,GAAG,EACHC,OAAO,EACPC,KAAK,EACA;IACLV,OAAOW,OAAO,CAAC,CAACC;QACd,IAAIC,aAAa;QACjB,IAAIC,YAAY;QAChB,IAAIC;QAEJ,IAAIlC,iBAAiB+B,QAAQ;YAC3BC,aAAa,CAAC,EAAEjB,gBAAgB,GAAG,EAAEd,YAAY8B,MAAMI,IAAI,EAAE,CAAC;YAC9DF,YAAY,CAAC,EAAEf,eAAe,GAAG,EAAEa,MAAMI,IAAI,CAAC,CAAC;YAC/CD,YAAYlB,IAAI,CAACe,MAAMI,IAAI,CAAC;QAC9B;QAEA,IAAIJ,MAAMK,IAAI,KAAK,SAAS;YAC1B,MAAMC,iBAAiB3B,QAAQ4B,YAAY,CAACC,GAAG,CAAC,CAAC,EAAEhB,gBAAgB,CAAC,EAAES,WAAW,C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,IAAIsB,MAAMvC;gBAEV,IAAIP,cAAc;oBAChB,IAAI,CAACC,OAAO,CAACD,aAAa,EAAEC,OAAO,CAACD,aAAa,GAAG,CAAC;oBACrD8C,MAAM7C,OAAO,CAACD,aAAa;gBAC7B;gBAEA6C,kBAAkBR,IAAI,CAAC;oBAAES;oBAAKC,OAAOjC;gBAAU;YACjD;YAEA+B,kBAAkBnC,OAAO,CAAC,CAAC,EAAEa,SAAS,EAAEuB,GAAG,EAAEC,KAAK,EAAE;gBAClD,IAAI,OAAOA,UAAU,aAAa;oBAChC,IAAIC,iBAAiBD;oBAErB,IAAIpC,MAAMK,IAAI,KAAK,UAAUL,MAAMI,IAAI,KAAK,aAAa;wBACvDiC,iBAAiB,IAAIC,OAAOC,WAAW;oBACzC;oBAEA,IAAI3B,WAAW;wBACbuB,GAAG,CAACvB,UAAU,CAACV,UAAU,GAAGmC;oBAC9B,OAAO;wBACLF,GAAG,CAACjC,UAAU,GAAGmC;oBACnB;gBACF;YACF;QACF;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/transform/write/types.ts"],"sourcesContent":["export type ArrayRowToInsert = {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n locales: {\n [locale: string]: Record<string, unknown>\n }\n row: Record<string, unknown>\n}\n\nexport type BlockRowToInsert = {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n locales: {\n [locale: string]: Record<string, unknown>\n }\n row: Record<string, unknown>\n}\n\nexport type RelationshipToDelete = {\n locale?: string\n path: string\n}\n\nexport type RowToInsert = {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n blocks: {\n [blockType: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n locales: {\n [locale: string]: Record<string, unknown>\n }\n numbers: Record<string, unknown>[]\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n row: Record<string, unknown>\n selects: {\n [tableName: string]: Record<string, unknown>[]\n }\n texts: Record<string, unknown>[]\n}\n"],"names":[],"rangeMappings":"","mappings":"AAyBA,WAmBC"}
1
+ {"version":3,"sources":["../../../src/transform/write/types.ts"],"sourcesContent":["export type ArrayRowToInsert = {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n locales: {\n [locale: string]: Record<string, unknown>\n }\n row: Record<string, unknown>\n}\n\nexport type BlockRowToInsert = {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n locales: {\n [locale: string]: Record<string, unknown>\n }\n row: Record<string, unknown>\n}\n\nexport type RelationshipToDelete = {\n locale?: string\n path: string\n}\n\nexport type RowToInsert = {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n blocks: {\n [blockType: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n locales: {\n [locale: string]: Record<string, unknown>\n }\n numbers: Record<string, unknown>[]\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n row: Record<string, unknown>\n selects: {\n [tableName: string]: Record<string, unknown>[]\n }\n texts: Record<string, unknown>[]\n}\n"],"names":[],"mappings":"AAyBA,WAmBC"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n ColumnBaseConfig,\n ColumnDataType,\n DrizzleConfig,\n ExtractTablesWithRelations,\n Relation,\n Relations,\n} from 'drizzle-orm'\nimport type { NodePgDatabase, NodePgQueryResultHKT } from 'drizzle-orm/node-postgres'\nimport type {\n PgColumn,\n PgEnum,\n PgSchema,\n PgTableWithColumns,\n PgTransaction,\n} from 'drizzle-orm/pg-core'\nimport type { PgTableFn } from 'drizzle-orm/pg-core/table'\nimport type { BaseDatabaseAdapter, Payload, PayloadRequestWithData } from 'payload'\nimport type { Pool, PoolConfig } from 'pg'\n\nexport type DrizzleDB = NodePgDatabase<Record<string, unknown>>\n\nexport type Args = {\n idType?: 'serial' | 'uuid'\n localesSuffix?: string\n logger?: DrizzleConfig['logger']\n migrationDir?: string\n pool: PoolConfig\n push?: boolean\n relationshipsSuffix?: string\n schemaName?: string\n versionsSuffix?: string\n}\n\nexport type GenericColumn = PgColumn<\n ColumnBaseConfig<ColumnDataType, string>,\n Record<string, unknown>\n>\n\nexport type GenericColumns = {\n [x: string]: GenericColumn\n}\n\nexport type GenericTable = PgTableWithColumns<{\n columns: GenericColumns\n dialect: string\n name: string\n schema: undefined\n}>\n\nexport type GenericEnum = PgEnum<[string, ...string[]]>\n\nexport type GenericRelation = Relations<string, Record<string, Relation<string>>>\n\nexport type DrizzleTransaction = PgTransaction<\n NodePgQueryResultHKT,\n Record<string, unknown>,\n ExtractTablesWithRelations<Record<string, unknown>>\n>\n\nexport type PostgresAdapter = BaseDatabaseAdapter & {\n drizzle: DrizzleDB\n enums: Record<string, GenericEnum>\n /**\n * An object keyed on each table, with a key value pair where the constraint name is the key, followed by the dot-notation field name\n * Used for returning properly formed errors from unique fields\n */\n fieldConstraints: Record<string, Record<string, string>>\n idType: Args['idType']\n initializing: Promise<void>\n localesSuffix?: string\n logger: DrizzleConfig['logger']\n pgSchema?: { table: PgTableFn } | PgSchema\n pool: Pool\n poolOptions: Args['pool']\n push: boolean\n rejectInitializing: () => void\n relations: Record<string, GenericRelation>\n relationshipsSuffix?: string\n resolveInitializing: () => void\n schema: Record<string, GenericEnum | GenericRelation | GenericTable>\n schemaName?: Args['schemaName']\n sessions: {\n [id: string]: {\n db: DrizzleTransaction\n reject: () => Promise<void>\n resolve: () => Promise<void>\n }\n }\n tableNameMap: Map<string, string>\n tables: Record<string, GenericTable | PgTableWithColumns<any>>\n versionsSuffix?: string\n}\n\nexport type IDType = 'integer' | 'numeric' | 'uuid' | 'varchar'\n\nexport type PostgresAdapterResult = (args: { payload: Payload }) => PostgresAdapter\n\nexport type MigrateUpArgs = { payload: Payload; req?: Partial<PayloadRequestWithData> }\nexport type MigrateDownArgs = { payload: Payload; req?: Partial<PayloadRequestWithData> }\n\ndeclare module 'payload' {\n export interface DatabaseAdapter\n extends Omit<Args, 'migrationDir' | 'pool'>,\n BaseDatabaseAdapter {\n drizzle: DrizzleDB\n enums: Record<string, GenericEnum>\n fieldConstraints: Record<string, Record<string, string>>\n localeSuffix?: string\n pool: Pool\n push: boolean\n relations: Record<string, GenericRelation>\n relationshipsSuffix?: string\n schema: Record<string, GenericEnum | GenericRelation | GenericTable>\n sessions: {\n [id: string]: {\n db: DrizzleTransaction\n reject: () => Promise<void>\n resolve: () => Promise<void>\n }\n }\n tables: Record<string, GenericTable>\n versionsSuffix?: string\n }\n}\n"],"names":[],"rangeMappings":"","mappings":"AAmGA,WAAyF"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n ColumnBaseConfig,\n ColumnDataType,\n DrizzleConfig,\n ExtractTablesWithRelations,\n Relation,\n Relations,\n} from 'drizzle-orm'\nimport type { NodePgDatabase, NodePgQueryResultHKT } from 'drizzle-orm/node-postgres'\nimport type {\n PgColumn,\n PgEnum,\n PgSchema,\n PgTableWithColumns,\n PgTransaction,\n} from 'drizzle-orm/pg-core'\nimport type { PgTableFn } from 'drizzle-orm/pg-core/table'\nimport type { BaseDatabaseAdapter, Payload, PayloadRequestWithData } from 'payload'\nimport type { Pool, PoolConfig } from 'pg'\n\nexport type DrizzleDB = NodePgDatabase<Record<string, unknown>>\n\nexport type Args = {\n idType?: 'serial' | 'uuid'\n localesSuffix?: string\n logger?: DrizzleConfig['logger']\n migrationDir?: string\n pool: PoolConfig\n push?: boolean\n relationshipsSuffix?: string\n schemaName?: string\n versionsSuffix?: string\n}\n\nexport type GenericColumn = PgColumn<\n ColumnBaseConfig<ColumnDataType, string>,\n Record<string, unknown>\n>\n\nexport type GenericColumns = {\n [x: string]: GenericColumn\n}\n\nexport type GenericTable = PgTableWithColumns<{\n columns: GenericColumns\n dialect: string\n name: string\n schema: undefined\n}>\n\nexport type GenericEnum = PgEnum<[string, ...string[]]>\n\nexport type GenericRelation = Relations<string, Record<string, Relation<string>>>\n\nexport type DrizzleTransaction = PgTransaction<\n NodePgQueryResultHKT,\n Record<string, unknown>,\n ExtractTablesWithRelations<Record<string, unknown>>\n>\n\nexport type PostgresAdapter = BaseDatabaseAdapter & {\n drizzle: DrizzleDB\n enums: Record<string, GenericEnum>\n /**\n * An object keyed on each table, with a key value pair where the constraint name is the key, followed by the dot-notation field name\n * Used for returning properly formed errors from unique fields\n */\n fieldConstraints: Record<string, Record<string, string>>\n idType: Args['idType']\n initializing: Promise<void>\n localesSuffix?: string\n logger: DrizzleConfig['logger']\n pgSchema?: { table: PgTableFn } | PgSchema\n pool: Pool\n poolOptions: Args['pool']\n push: boolean\n rejectInitializing: () => void\n relations: Record<string, GenericRelation>\n relationshipsSuffix?: string\n resolveInitializing: () => void\n schema: Record<string, GenericEnum | GenericRelation | GenericTable>\n schemaName?: Args['schemaName']\n sessions: {\n [id: string]: {\n db: DrizzleTransaction\n reject: () => Promise<void>\n resolve: () => Promise<void>\n }\n }\n tableNameMap: Map<string, string>\n tables: Record<string, GenericTable | PgTableWithColumns<any>>\n versionsSuffix?: string\n}\n\nexport type IDType = 'integer' | 'numeric' | 'uuid' | 'varchar'\n\nexport type PostgresAdapterResult = (args: { payload: Payload }) => PostgresAdapter\n\nexport type MigrateUpArgs = { payload: Payload; req?: Partial<PayloadRequestWithData> }\nexport type MigrateDownArgs = { payload: Payload; req?: Partial<PayloadRequestWithData> }\n\ndeclare module 'payload' {\n export interface DatabaseAdapter\n extends Omit<Args, 'migrationDir' | 'pool'>,\n BaseDatabaseAdapter {\n drizzle: DrizzleDB\n enums: Record<string, GenericEnum>\n fieldConstraints: Record<string, Record<string, string>>\n localeSuffix?: string\n pool: Pool\n push: boolean\n relations: Record<string, GenericRelation>\n relationshipsSuffix?: string\n schema: Record<string, GenericEnum | GenericRelation | GenericTable>\n sessions: {\n [id: string]: {\n db: DrizzleTransaction\n reject: () => Promise<void>\n resolve: () => Promise<void>\n }\n }\n tables: Record<string, GenericTable>\n versionsSuffix?: string\n }\n}\n"],"names":[],"mappings":"AAmGA,WAAyF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/update.ts"],"sourcesContent":["import type { UpdateOne } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport buildQuery from './queries/buildQuery.js'\nimport { selectDistinct } from './queries/selectDistinct.js'\nimport { upsertRow } from './upsertRow/index.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: PostgresAdapter,\n { id, collection: collectionSlug, data, draft, locale, req, where: whereArg },\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collection = this.payload.collections[collectionSlug].config\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n const whereToUse = whereArg || { id: { equals: id } }\n let idToUpdate = id\n\n const { joins, selectFields, where } = await buildQuery({\n adapter: this,\n fields: collection.fields,\n locale,\n tableName,\n where: whereToUse,\n })\n\n const selectDistinctResult = await selectDistinct({\n adapter: this,\n chainedMethods: [{ args: [1], method: 'limit' }],\n db,\n joins,\n selectFields,\n tableName,\n where,\n })\n\n if (selectDistinctResult?.[0]?.id) {\n idToUpdate = selectDistinctResult?.[0]?.id\n }\n\n const result = await upsertRow({\n id: idToUpdate,\n adapter: this,\n data,\n db,\n fields: collection.fields,\n operation: 'update',\n req,\n tableName,\n })\n\n return result\n}\n"],"names":["toSnakeCase","buildQuery","selectDistinct","upsertRow","updateOne","id","collection","collectionSlug","data","draft","locale","req","where","whereArg","db","sessions","transactionID","drizzle","payload","collections","config","tableName","tableNameMap","get","slug","whereToUse","equals","idToUpdate","joins","selectFields","adapter","fields","selectDistinctResult","chainedMethods","args","method","result","operation"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,EAAE,EAAEC,YAAYC,cAAc,EAAEC,IAAI,EAAEC,KAAK,EAAEC,MAAM,EAAEC,GAAG,EAAEC,OAAOC,QAAQ,EAAE;IAE7E,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACJ,IAAIK,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMX,aAAa,IAAI,CAACY,OAAO,CAACC,WAAW,CAACZ,eAAe,CAACa,MAAM;IAClE,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACvB,YAAYM,WAAWkB,IAAI;IACnE,MAAMC,aAAaZ,YAAY;QAAER,IAAI;YAAEqB,QAAQrB;QAAG;IAAE;IACpD,IAAIsB,aAAatB;IAEjB,MAAM,EAAEuB,KAAK,EAAEC,YAAY,EAAEjB,KAAK,EAAE,GAAG,MAAMX,WAAW;QACtD6B,SAAS,IAAI;QACbC,QAAQzB,WAAWyB,MAAM;QACzBrB;QACAW;QACAT,OAAOa;IACT;IAEA,MAAMO,uBAAuB,MAAM9B,eAAe;QAChD4B,SAAS,IAAI;QACbG,gBAAgB;YAAC;gBAAEC,MAAM;oBAAC;iBAAE;gBAAEC,QAAQ;YAAQ;SAAE;QAChDrB;QACAc;QACAC;QACAR;QACAT;IACF;IAEA,IAAIoB,sBAAsB,CAAC,EAAE,EAAE3B,IAAI;QACjCsB,aAAaK,sBAAsB,CAAC,EAAE,EAAE3B;IAC1C;IAEA,MAAM+B,SAAS,MAAMjC,UAAU;QAC7BE,IAAIsB;QACJG,SAAS,IAAI;QACbtB;QACAM;QACAiB,QAAQzB,WAAWyB,MAAM;QACzBM,WAAW;QACX1B;QACAU;IACF;IAEA,OAAOe;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/update.ts"],"sourcesContent":["import type { UpdateOne } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport buildQuery from './queries/buildQuery.js'\nimport { selectDistinct } from './queries/selectDistinct.js'\nimport { upsertRow } from './upsertRow/index.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: PostgresAdapter,\n { id, collection: collectionSlug, data, draft, locale, req, where: whereArg },\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collection = this.payload.collections[collectionSlug].config\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n const whereToUse = whereArg || { id: { equals: id } }\n let idToUpdate = id\n\n const { joins, selectFields, where } = await buildQuery({\n adapter: this,\n fields: collection.fields,\n locale,\n tableName,\n where: whereToUse,\n })\n\n const selectDistinctResult = await selectDistinct({\n adapter: this,\n chainedMethods: [{ args: [1], method: 'limit' }],\n db,\n joins,\n selectFields,\n tableName,\n where,\n })\n\n if (selectDistinctResult?.[0]?.id) {\n idToUpdate = selectDistinctResult?.[0]?.id\n }\n\n const result = await upsertRow({\n id: idToUpdate,\n adapter: this,\n data,\n db,\n fields: collection.fields,\n operation: 'update',\n req,\n tableName,\n })\n\n return result\n}\n"],"names":["toSnakeCase","buildQuery","selectDistinct","upsertRow","updateOne","id","collection","collectionSlug","data","draft","locale","req","where","whereArg","db","sessions","transactionID","drizzle","payload","collections","config","tableName","tableNameMap","get","slug","whereToUse","equals","idToUpdate","joins","selectFields","adapter","fields","selectDistinctResult","chainedMethods","args","method","result","operation"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,EAAE,EAAEC,YAAYC,cAAc,EAAEC,IAAI,EAAEC,KAAK,EAAEC,MAAM,EAAEC,GAAG,EAAEC,OAAOC,QAAQ,EAAE;IAE7E,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACJ,IAAIK,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMX,aAAa,IAAI,CAACY,OAAO,CAACC,WAAW,CAACZ,eAAe,CAACa,MAAM;IAClE,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACvB,YAAYM,WAAWkB,IAAI;IACnE,MAAMC,aAAaZ,YAAY;QAAER,IAAI;YAAEqB,QAAQrB;QAAG;IAAE;IACpD,IAAIsB,aAAatB;IAEjB,MAAM,EAAEuB,KAAK,EAAEC,YAAY,EAAEjB,KAAK,EAAE,GAAG,MAAMX,WAAW;QACtD6B,SAAS,IAAI;QACbC,QAAQzB,WAAWyB,MAAM;QACzBrB;QACAW;QACAT,OAAOa;IACT;IAEA,MAAMO,uBAAuB,MAAM9B,eAAe;QAChD4B,SAAS,IAAI;QACbG,gBAAgB;YAAC;gBAAEC,MAAM;oBAAC;iBAAE;gBAAEC,QAAQ;YAAQ;SAAE;QAChDrB;QACAc;QACAC;QACAR;QACAT;IACF;IAEA,IAAIoB,sBAAsB,CAAC,EAAE,EAAE3B,IAAI;QACjCsB,aAAaK,sBAAsB,CAAC,EAAE,EAAE3B;IAC1C;IAEA,MAAM+B,SAAS,MAAMjC,UAAU;QAC7BE,IAAIsB;QACJG,SAAS,IAAI;QACbtB;QACAM;QACAiB,QAAQzB,WAAWyB,MAAM;QACzBM,WAAW;QACX1B;QACAU;IACF;IAEA,OAAOe;AACT,EAAC"}
@@ -1,4 +1,4 @@
1
- import type { TypeWithID, UpdateGlobalArgs } from 'payload';
1
+ import type { UpdateGlobalArgs } from 'payload';
2
2
  import type { PostgresAdapter } from './types.js';
3
- export declare function updateGlobal<T extends TypeWithID>(this: PostgresAdapter, { slug, data, req }: UpdateGlobalArgs): Promise<T>;
3
+ export declare function updateGlobal<T extends Record<string, unknown>>(this: PostgresAdapter, { slug, data, req }: UpdateGlobalArgs): Promise<T>;
4
4
  //# sourceMappingURL=updateGlobal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA0B,UAAU,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAInF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAIjD,wBAAsB,YAAY,CAAC,CAAC,SAAS,UAAU,EACrD,IAAI,EAAE,eAAe,EACrB,EAAE,IAAI,EAAE,IAAI,EAAE,GAAkC,EAAE,EAAE,gBAAgB,GACnE,OAAO,CAAC,CAAC,CAAC,CAkBZ"}
1
+ {"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA0B,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAIvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAIjD,wBAAsB,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClE,IAAI,EAAE,eAAe,EACrB,EAAE,IAAI,EAAE,IAAI,EAAE,GAAkC,EAAE,EAAE,gBAAgB,GACnE,OAAO,CAAC,CAAC,CAAC,CAkBZ"}
@@ -1 +1 @@
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
+ {"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { PayloadRequestWithData, 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 Record<string, unknown>>(\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"],"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 +1 @@
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
+ {"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"],"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 +1 @@
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
+ {"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"],"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 +1 @@
1
- {"version":3,"file":"deleteExistingArrayRows.d.ts","sourceRoot":"","sources":["../../src/upsertRow/deleteExistingArrayRows.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,EAAE,EAAE,SAAS,CAAA;IACb,QAAQ,EAAE,OAAO,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,uBAAuB,0CAKjC,IAAI,KAAG,QAAQ,IAAI,CAMrB,CAAA"}
1
+ {"version":3,"file":"deleteExistingArrayRows.d.ts","sourceRoot":"","sources":["../../src/upsertRow/deleteExistingArrayRows.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,EAAE,EAAE,SAAS,CAAA;IACb,QAAQ,EAAE,OAAO,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,uBAAuB,0CAKjC,IAAI,KAAG,OAAO,CAAC,IAAI,CAMrB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/upsertRow/deleteExistingArrayRows.ts"],"sourcesContent":["import { and, eq } from 'drizzle-orm'\n\nimport type { DrizzleDB, PostgresAdapter } from '../types.js'\n\ntype Args = {\n adapter: PostgresAdapter\n db: DrizzleDB\n parentID: unknown\n tableName: string\n}\n\nexport const deleteExistingArrayRows = async ({\n adapter,\n db,\n parentID,\n tableName,\n}: Args): Promise<void> => {\n const table = adapter.tables[tableName]\n\n const whereConstraints = [eq(table._parentID, parentID)]\n\n await db.delete(table).where(and(...whereConstraints))\n}\n"],"names":["and","eq","deleteExistingArrayRows","adapter","db","parentID","tableName","table","tables","whereConstraints","_parentID","delete","where"],"rangeMappings":";;;;;;;","mappings":"AAAA,SAASA,GAAG,EAAEC,EAAE,QAAQ,cAAa;AAWrC,OAAO,MAAMC,0BAA0B,OAAO,EAC5CC,OAAO,EACPC,EAAE,EACFC,QAAQ,EACRC,SAAS,EACJ;IACL,MAAMC,QAAQJ,QAAQK,MAAM,CAACF,UAAU;IAEvC,MAAMG,mBAAmB;QAACR,GAAGM,MAAMG,SAAS,EAAEL;KAAU;IAExD,MAAMD,GAAGO,MAAM,CAACJ,OAAOK,KAAK,CAACZ,OAAOS;AACtC,EAAC"}
1
+ {"version":3,"sources":["../../src/upsertRow/deleteExistingArrayRows.ts"],"sourcesContent":["import { and, eq } from 'drizzle-orm'\n\nimport type { DrizzleDB, PostgresAdapter } from '../types.js'\n\ntype Args = {\n adapter: PostgresAdapter\n db: DrizzleDB\n parentID: unknown\n tableName: string\n}\n\nexport const deleteExistingArrayRows = async ({\n adapter,\n db,\n parentID,\n tableName,\n}: Args): Promise<void> => {\n const table = adapter.tables[tableName]\n\n const whereConstraints = [eq(table._parentID, parentID)]\n\n await db.delete(table).where(and(...whereConstraints))\n}\n"],"names":["and","eq","deleteExistingArrayRows","adapter","db","parentID","tableName","table","tables","whereConstraints","_parentID","delete","where"],"mappings":"AAAA,SAASA,GAAG,EAAEC,EAAE,QAAQ,cAAa;AAWrC,OAAO,MAAMC,0BAA0B,OAAO,EAC5CC,OAAO,EACPC,EAAE,EACFC,QAAQ,EACRC,SAAS,EACJ;IACL,MAAMC,QAAQJ,QAAQK,MAAM,CAACF,UAAU;IAEvC,MAAMG,mBAAmB;QAACR,GAAGM,MAAMG,SAAS,EAAEL;KAAU;IAExD,MAAMD,GAAGO,MAAM,CAACJ,OAAOK,KAAK,CAACZ,OAAOS;AACtC,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"deleteExistingRowsByPath.d.ts","sourceRoot":"","sources":["../../src/upsertRow/deleteExistingRowsByPath.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,EAAE,EAAE,SAAS,CAAA;IACb,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,OAAO,CAAA;IACjB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAC/B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,wBAAwB,oGASlC,IAAI,KAAG,QAAQ,IAAI,CAkCrB,CAAA"}
1
+ {"version":3,"file":"deleteExistingRowsByPath.d.ts","sourceRoot":"","sources":["../../src/upsertRow/deleteExistingRowsByPath.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,EAAE,EAAE,SAAS,CAAA;IACb,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,OAAO,CAAA;IACjB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAC/B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,wBAAwB,oGASlC,IAAI,KAAG,OAAO,CAAC,IAAI,CAkCrB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/upsertRow/deleteExistingRowsByPath.ts"],"sourcesContent":["import { and, eq, inArray } from 'drizzle-orm'\n\nimport type { DrizzleDB, PostgresAdapter } from '../types.js'\n\ntype Args = {\n adapter: PostgresAdapter\n db: DrizzleDB\n localeColumnName?: string\n parentColumnName?: string\n parentID: unknown\n pathColumnName?: string\n rows: Record<string, unknown>[]\n tableName: string\n}\n\nexport const deleteExistingRowsByPath = async ({\n adapter,\n db,\n localeColumnName = '_locale',\n parentColumnName = '_parentID',\n parentID,\n pathColumnName = '_path',\n rows,\n tableName,\n}: Args): Promise<void> => {\n const localizedPathsToDelete = new Set<string>()\n const pathsToDelete = new Set<string>()\n const table = adapter.tables[tableName]\n\n rows.forEach((row) => {\n const path = row[pathColumnName]\n const localeData = row[localeColumnName]\n if (typeof path === 'string') {\n if (typeof localeData === 'string') {\n localizedPathsToDelete.add(path)\n } else {\n pathsToDelete.add(path)\n }\n }\n })\n\n if (localizedPathsToDelete.size > 0) {\n const whereConstraints = [eq(table[parentColumnName], parentID)]\n\n if (pathColumnName)\n whereConstraints.push(inArray(table[pathColumnName], Array.from(localizedPathsToDelete)))\n\n await db.delete(table).where(and(...whereConstraints))\n }\n\n if (pathsToDelete.size > 0) {\n const whereConstraints = [eq(table[parentColumnName], parentID)]\n\n if (pathColumnName)\n whereConstraints.push(inArray(table[pathColumnName], Array.from(pathsToDelete)))\n\n await db.delete(table).where(and(...whereConstraints))\n }\n}\n"],"names":["and","eq","inArray","deleteExistingRowsByPath","adapter","db","localeColumnName","parentColumnName","parentID","pathColumnName","rows","tableName","localizedPathsToDelete","Set","pathsToDelete","table","tables","forEach","row","path","localeData","add","size","whereConstraints","push","Array","from","delete","where"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,GAAG,EAAEC,EAAE,EAAEC,OAAO,QAAQ,cAAa;AAe9C,OAAO,MAAMC,2BAA2B,OAAO,EAC7CC,OAAO,EACPC,EAAE,EACFC,mBAAmB,SAAS,EAC5BC,mBAAmB,WAAW,EAC9BC,QAAQ,EACRC,iBAAiB,OAAO,EACxBC,IAAI,EACJC,SAAS,EACJ;IACL,MAAMC,yBAAyB,IAAIC;IACnC,MAAMC,gBAAgB,IAAID;IAC1B,MAAME,QAAQX,QAAQY,MAAM,CAACL,UAAU;IAEvCD,KAAKO,OAAO,CAAC,CAACC;QACZ,MAAMC,OAAOD,GAAG,CAACT,eAAe;QAChC,MAAMW,aAAaF,GAAG,CAACZ,iBAAiB;QACxC,IAAI,OAAOa,SAAS,UAAU;YAC5B,IAAI,OAAOC,eAAe,UAAU;gBAClCR,uBAAuBS,GAAG,CAACF;YAC7B,OAAO;gBACLL,cAAcO,GAAG,CAACF;YACpB;QACF;IACF;IAEA,IAAIP,uBAAuBU,IAAI,GAAG,GAAG;QACnC,MAAMC,mBAAmB;YAACtB,GAAGc,KAAK,CAACR,iBAAiB,EAAEC;SAAU;QAEhE,IAAIC,gBACFc,iBAAiBC,IAAI,CAACtB,QAAQa,KAAK,CAACN,eAAe,EAAEgB,MAAMC,IAAI,CAACd;QAElE,MAAMP,GAAGsB,MAAM,CAACZ,OAAOa,KAAK,CAAC5B,OAAOuB;IACtC;IAEA,IAAIT,cAAcQ,IAAI,GAAG,GAAG;QAC1B,MAAMC,mBAAmB;YAACtB,GAAGc,KAAK,CAACR,iBAAiB,EAAEC;SAAU;QAEhE,IAAIC,gBACFc,iBAAiBC,IAAI,CAACtB,QAAQa,KAAK,CAACN,eAAe,EAAEgB,MAAMC,IAAI,CAACZ;QAElE,MAAMT,GAAGsB,MAAM,CAACZ,OAAOa,KAAK,CAAC5B,OAAOuB;IACtC;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/upsertRow/deleteExistingRowsByPath.ts"],"sourcesContent":["import { and, eq, inArray } from 'drizzle-orm'\n\nimport type { DrizzleDB, PostgresAdapter } from '../types.js'\n\ntype Args = {\n adapter: PostgresAdapter\n db: DrizzleDB\n localeColumnName?: string\n parentColumnName?: string\n parentID: unknown\n pathColumnName?: string\n rows: Record<string, unknown>[]\n tableName: string\n}\n\nexport const deleteExistingRowsByPath = async ({\n adapter,\n db,\n localeColumnName = '_locale',\n parentColumnName = '_parentID',\n parentID,\n pathColumnName = '_path',\n rows,\n tableName,\n}: Args): Promise<void> => {\n const localizedPathsToDelete = new Set<string>()\n const pathsToDelete = new Set<string>()\n const table = adapter.tables[tableName]\n\n rows.forEach((row) => {\n const path = row[pathColumnName]\n const localeData = row[localeColumnName]\n if (typeof path === 'string') {\n if (typeof localeData === 'string') {\n localizedPathsToDelete.add(path)\n } else {\n pathsToDelete.add(path)\n }\n }\n })\n\n if (localizedPathsToDelete.size > 0) {\n const whereConstraints = [eq(table[parentColumnName], parentID)]\n\n if (pathColumnName)\n whereConstraints.push(inArray(table[pathColumnName], Array.from(localizedPathsToDelete)))\n\n await db.delete(table).where(and(...whereConstraints))\n }\n\n if (pathsToDelete.size > 0) {\n const whereConstraints = [eq(table[parentColumnName], parentID)]\n\n if (pathColumnName)\n whereConstraints.push(inArray(table[pathColumnName], Array.from(pathsToDelete)))\n\n await db.delete(table).where(and(...whereConstraints))\n }\n}\n"],"names":["and","eq","inArray","deleteExistingRowsByPath","adapter","db","localeColumnName","parentColumnName","parentID","pathColumnName","rows","tableName","localizedPathsToDelete","Set","pathsToDelete","table","tables","forEach","row","path","localeData","add","size","whereConstraints","push","Array","from","delete","where"],"mappings":"AAAA,SAASA,GAAG,EAAEC,EAAE,EAAEC,OAAO,QAAQ,cAAa;AAe9C,OAAO,MAAMC,2BAA2B,OAAO,EAC7CC,OAAO,EACPC,EAAE,EACFC,mBAAmB,SAAS,EAC5BC,mBAAmB,WAAW,EAC9BC,QAAQ,EACRC,iBAAiB,OAAO,EACxBC,IAAI,EACJC,SAAS,EACJ;IACL,MAAMC,yBAAyB,IAAIC;IACnC,MAAMC,gBAAgB,IAAID;IAC1B,MAAME,QAAQX,QAAQY,MAAM,CAACL,UAAU;IAEvCD,KAAKO,OAAO,CAAC,CAACC;QACZ,MAAMC,OAAOD,GAAG,CAACT,eAAe;QAChC,MAAMW,aAAaF,GAAG,CAACZ,iBAAiB;QACxC,IAAI,OAAOa,SAAS,UAAU;YAC5B,IAAI,OAAOC,eAAe,UAAU;gBAClCR,uBAAuBS,GAAG,CAACF;YAC7B,OAAO;gBACLL,cAAcO,GAAG,CAACF;YACpB;QACF;IACF;IAEA,IAAIP,uBAAuBU,IAAI,GAAG,GAAG;QACnC,MAAMC,mBAAmB;YAACtB,GAAGc,KAAK,CAACR,iBAAiB,EAAEC;SAAU;QAEhE,IAAIC,gBACFc,iBAAiBC,IAAI,CAACtB,QAAQa,KAAK,CAACN,eAAe,EAAEgB,MAAMC,IAAI,CAACd;QAElE,MAAMP,GAAGsB,MAAM,CAACZ,OAAOa,KAAK,CAAC5B,OAAOuB;IACtC;IAEA,IAAIT,cAAcQ,IAAI,GAAG,GAAG;QAC1B,MAAMC,mBAAmB;YAACtB,GAAGc,KAAK,CAACR,iBAAiB,EAAEC;SAAU;QAEhE,IAAIC,gBACFc,iBAAiBC,IAAI,CAACtB,QAAQa,KAAK,CAACN,eAAe,EAAEgB,MAAMC,IAAI,CAACZ;QAElE,MAAMT,GAAGsB,MAAM,CAACZ,OAAOa,KAAK,CAAC5B,OAAOuB;IACtC;AACF,EAAC"}
@@ -1,4 +1,4 @@
1
1
  import type { TypeWithID } from 'payload';
2
2
  import type { Args } from './types.js';
3
- export declare const upsertRow: <T extends TypeWithID>({ id, adapter, data, db, fields, ignoreResult, operation, path, req, tableName, upsertTarget, where, }: Args) => Promise<T>;
3
+ export declare const upsertRow: <T extends Record<string, unknown> | 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,SAAS,CAAA;AAMzC,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,GAAU,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,0GAa3E,IAAI,KAAG,OAAO,CAAC,CAAC,CAsUlB,CAAA"}
@@ -1 +1 @@
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAGpC,SAASA,EAAE,QAAQ,cAAa;AAChC,SAASC,eAAe,QAAQ,UAAS;AAKzC,SAASC,iBAAiB,QAAQ,+BAA8B;AAChE,SAASC,SAAS,QAAQ,6BAA4B;AACtD,SAASC,iBAAiB,QAAQ,8BAA6B;AAC/D,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,wBAAwB,QAAQ,gCAA+B;AACxE,SAASC,YAAY,QAAQ,oBAAmB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A,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 Record<string, unknown> | 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"],"mappings":"AAAA,oCAAoC,GAGpC,SAASA,EAAE,QAAQ,cAAa;AAChC,SAASC,eAAe,QAAQ,UAAS;AAKzC,SAASC,iBAAiB,QAAQ,+BAA8B;AAChE,SAASC,SAAS,QAAQ,6BAA4B;AACtD,SAASC,iBAAiB,QAAQ,8BAA6B;AAC/D,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,wBAAwB,QAAQ,gCAA+B;AACxE,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,OAAO,MAAMC,YAAY,OAAuD,EAC9EC,EAAE,EACFC,OAAO,EACPC,IAAI,EACJC,EAAE,EACFC,MAAM,EACNC,YAAY,EACZC,SAAS,EACTC,OAAO,EAAE,EACTC,GAAG,EACHC,SAAS,EACTC,YAAY,EACZC,KAAK,EACA;IACL,sDAAsD;IACtD,uDAAuD;IACvD,MAAMC,cAAcjB,kBAAkB;QACpCM;QACAC;QACAE;QACAG;QACAE;IACF;IAEA,gCAAgC;IAChC,IAAII;IAEJ,IAAI;QACF,IAAIP,cAAc,UAAU;YAC1B,MAAMQ,SAASJ,gBAAgBT,QAAQc,MAAM,CAACN,UAAU,CAACT,EAAE;YAE3D,I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,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 +1 @@
1
- {"version":3,"file":"insertArrays.d.ts","sourceRoot":"","sources":["../../src/upsertRow/insertArrays.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE;QACN,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAA;KACxC,EAAE,CAAA;IACH,EAAE,EAAE,SAAS,CAAA;IACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;CACtC,CAAA;AAYD,eAAO,MAAM,YAAY,wCAA+C,IAAI,KAAG,QAAQ,IAAI,CA4E1F,CAAA"}
1
+ {"version":3,"file":"insertArrays.d.ts","sourceRoot":"","sources":["../../src/upsertRow/insertArrays.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE;QACN,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAA;KACxC,EAAE,CAAA;IACH,EAAE,EAAE,SAAS,CAAA;IACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;CACtC,CAAA;AAYD,eAAO,MAAM,YAAY,wCAA+C,IAAI,KAAG,OAAO,CAAC,IAAI,CA4E1F,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/upsertRow/insertArrays.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { ArrayRowToInsert } from '../transform/write/types.js'\nimport type { DrizzleDB, PostgresAdapter } from '../types.js'\n\ntype Args = {\n adapter: PostgresAdapter\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }[]\n db: DrizzleDB\n parentRows: Record<string, unknown>[]\n}\n\ntype RowsByTable = {\n [tableName: string]: {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }[]\n locales: Record<string, unknown>[]\n rows: Record<string, unknown>[]\n }\n}\n\nexport const insertArrays = async ({ adapter, arrays, db, parentRows }: Args): Promise<void> => {\n // Maintain a map of flattened rows by table\n const rowsByTable: RowsByTable = {}\n\n arrays.forEach((arraysByTable, parentRowIndex) => {\n Object.entries(arraysByTable).forEach(([tableName, arrayRows]) => {\n // If the table doesn't exist in map, initialize it\n if (!rowsByTable[tableName]) {\n rowsByTable[tableName] = {\n arrays: [],\n locales: [],\n rows: [],\n }\n }\n\n const parentID = parentRows[parentRowIndex].id\n\n // Add any sub arrays that need to be created\n // We will call this recursively below\n arrayRows.forEach((arrayRow, i) => {\n if (Object.keys(arrayRow.arrays).length > 0) {\n rowsByTable[tableName].arrays.push(arrayRow.arrays)\n }\n\n // Set up parent IDs for both row and locale row\n arrayRow.row._parentID = parentID\n rowsByTable[tableName].rows.push(arrayRow.row)\n\n Object.entries(arrayRow.locales).forEach(([arrayRowLocale, arrayRowLocaleData]) => {\n arrayRowLocaleData._parentID = arrayRow.row.id\n arrayRowLocaleData._locale = arrayRowLocale\n rowsByTable[tableName].locales.push(arrayRowLocaleData)\n if (!arrayRow.row.id) {\n arrayRowLocaleData._getParentID = (rows) => rows[i].id\n }\n })\n })\n })\n })\n\n // Insert all corresponding arrays\n // (one insert per array table)\n for (const [tableName, row] of Object.entries(rowsByTable)) {\n // the nested arrays need the ID for the parentID foreign key\n let insertedRows: Args['parentRows']\n if (row.rows.length > 0) {\n insertedRows = await db.insert(adapter.tables[tableName]).values(row.rows).returning()\n }\n\n // Insert locale rows\n if (adapter.tables[`${tableName}${adapter.localesSuffix}`] && row.locales.length > 0) {\n if (!row.locales[0]._parentID) {\n row.locales = row.locales.map((localeRow) => {\n if (typeof localeRow._getParentID === 'function') {\n localeRow._parentID = localeRow._getParentID(insertedRows)\n delete localeRow._getParentID\n }\n return localeRow\n })\n }\n await db\n .insert(adapter.tables[`${tableName}${adapter.localesSuffix}`])\n .values(row.locales)\n .returning()\n }\n\n // If there are sub arrays, call this function recursively\n if (row.arrays.length > 0) {\n await insertArrays({\n adapter,\n arrays: row.arrays,\n db,\n parentRows: insertedRows,\n })\n }\n }\n}\n"],"names":["insertArrays","adapter","arrays","db","parentRows","rowsByTable","forEach","arraysByTable","parentRowIndex","Object","entries","tableName","arrayRows","locales","rows","parentID","id","arrayRow","i","keys","length","push","row","_parentID","arrayRowLocale","arrayRowLocaleData","_locale","_getParentID","insertedRows","insert","tables","values","returning","localesSuffix","map","localeRow"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAuBpC,OAAO,MAAMA,eAAe,OAAO,EAAEC,OAAO,EAAEC,MAAM,EAAEC,EAAE,EAAEC,UAAU,EAAQ;IAC1E,4CAA4C;IAC5C,MAAMC,cAA2B,CAAC;IAElCH,OAAOI,OAAO,CAAC,CAACC,eAAeC;QAC7BC,OAAOC,OAAO,CAACH,eAAeD,OAAO,CAAC,CAAC,CAACK,WAAWC,UAAU;YAC3D,mDAAmD;YACnD,IAAI,CAACP,WAAW,CAACM,UAAU,EAAE;gBAC3BN,WAAW,CAACM,UAAU,GAAG;oBACvBT,QAAQ,EAA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EV,QAAQgC,aAAa,CAAC,CAAC,CAAC,IAAIX,IAAIT,OAAO,CAACO,MAAM,GAAG,GAAG;YACpF,IAAI,CAACE,IAAIT,OAAO,CAAC,EAAE,CAACU,SAAS,EAAE;gBAC7BD,IAAIT,OAAO,GAAGS,IAAIT,OAAO,CAACqB,GAAG,CAAC,CAACC;oBAC7B,IAAI,OAAOA,UAAUR,YAAY,KAAK,YAAY;wBAChDQ,UAAUZ,SAAS,GAAGY,UAAUR,YAAY,CAACC;wBAC7C,OAAOO,UAAUR,YAAY;oBAC/B;oBACA,OAAOQ;gBACT;YACF;YACA,MAAMhC,GACH0B,MAAM,CAAC5B,QAAQ6B,MAAM,CAAC,CAAC,EAAEnB,UAAU,EAAEV,QAAQgC,aAAa,CAAC,CAAC,CAAC,EAC7DF,MAAM,CAACT,IAAIT,OAAO,EAClBmB,SAAS;QACd;QAEA,0DAA0D;QAC1D,IAAIV,IAAIpB,MAAM,CAACkB,MAAM,GAAG,GAAG;YACzB,MAAMpB,aAAa;gBACjBC;gBACAC,QAAQoB,IAAIpB,MAAM;gBAClBC;gBACAC,YAAYwB;YACd;QACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/upsertRow/insertArrays.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { ArrayRowToInsert } from '../transform/write/types.js'\nimport type { DrizzleDB, PostgresAdapter } from '../types.js'\n\ntype Args = {\n adapter: PostgresAdapter\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }[]\n db: DrizzleDB\n parentRows: Record<string, unknown>[]\n}\n\ntype RowsByTable = {\n [tableName: string]: {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }[]\n locales: Record<string, unknown>[]\n rows: Record<string, unknown>[]\n }\n}\n\nexport const insertArrays = async ({ adapter, arrays, db, parentRows }: Args): Promise<void> => {\n // Maintain a map of flattened rows by table\n const rowsByTable: RowsByTable = {}\n\n arrays.forEach((arraysByTable, parentRowIndex) => {\n Object.entries(arraysByTable).forEach(([tableName, arrayRows]) => {\n // If the table doesn't exist in map, initialize it\n if (!rowsByTable[tableName]) {\n rowsByTable[tableName] = {\n arrays: [],\n locales: [],\n rows: [],\n }\n }\n\n const parentID = parentRows[parentRowIndex].id\n\n // Add any sub arrays that need to be created\n // We will call this recursively below\n arrayRows.forEach((arrayRow, i) => {\n if (Object.keys(arrayRow.arrays).length > 0) {\n rowsByTable[tableName].arrays.push(arrayRow.arrays)\n }\n\n // Set up parent IDs for both row and locale row\n arrayRow.row._parentID = parentID\n rowsByTable[tableName].rows.push(arrayRow.row)\n\n Object.entries(arrayRow.locales).forEach(([arrayRowLocale, arrayRowLocaleData]) => {\n arrayRowLocaleData._parentID = arrayRow.row.id\n arrayRowLocaleData._locale = arrayRowLocale\n rowsByTable[tableName].locales.push(arrayRowLocaleData)\n if (!arrayRow.row.id) {\n arrayRowLocaleData._getParentID = (rows) => rows[i].id\n }\n })\n })\n })\n })\n\n // Insert all corresponding arrays\n // (one insert per array table)\n for (const [tableName, row] of Object.entries(rowsByTable)) {\n // the nested arrays need the ID for the parentID foreign key\n let insertedRows: Args['parentRows']\n if (row.rows.length > 0) {\n insertedRows = await db.insert(adapter.tables[tableName]).values(row.rows).returning()\n }\n\n // Insert locale rows\n if (adapter.tables[`${tableName}${adapter.localesSuffix}`] && row.locales.length > 0) {\n if (!row.locales[0]._parentID) {\n row.locales = row.locales.map((localeRow) => {\n if (typeof localeRow._getParentID === 'function') {\n localeRow._parentID = localeRow._getParentID(insertedRows)\n delete localeRow._getParentID\n }\n return localeRow\n })\n }\n await db\n .insert(adapter.tables[`${tableName}${adapter.localesSuffix}`])\n .values(row.locales)\n .returning()\n }\n\n // If there are sub arrays, call this function recursively\n if (row.arrays.length > 0) {\n await insertArrays({\n adapter,\n arrays: row.arrays,\n db,\n parentRows: insertedRows,\n })\n }\n }\n}\n"],"names":["insertArrays","adapter","arrays","db","parentRows","rowsByTable","forEach","arraysByTable","parentRowIndex","Object","entries","tableName","arrayRows","locales","rows","parentID","id","arrayRow","i","keys","length","push","row","_parentID","arrayRowLocale","arrayRowLocaleData","_locale","_getParentID","insertedRows","insert","tables","values","returning","localesSuffix","map","localeRow"],"mappings":"AAAA,oCAAoC,GAuBpC,OAAO,MAAMA,eAAe,OAAO,EAAEC,OAAO,EAAEC,MAAM,EAAEC,EAAE,EAAEC,UAAU,EAAQ;IAC1E,4CAA4C;IAC5C,MAAMC,cAA2B,CAAC;IAElCH,OAAOI,OAAO,CAAC,CAACC,eAAeC;QAC7BC,OAAOC,OAAO,CAACH,eAAeD,OAAO,CAAC,CAAC,CAACK,WAAWC,UAAU;YAC3D,mDAAmD;YACnD,IAAI,CAACP,WAAW,CAACM,UAAU,EAAE;gBAC3BN,WAAW,CAACM,UAAU,GAAG;oBACvBT,QAAQ,EAAE;oBACVW,SAAS,EAAE;oBACXC,MAAM,EAAE;gBACV;YACF;YAEA,MAAMC,WAAWX,UAAU,CAACI,eAAe,CAACQ,EAAE;YAE9C,6CAA6C;YAC7C,sCAAsC;YACtCJ,UAAUN,OAAO,CAAC,CAACW,UAAUC;gBAC3B,IAAIT,OAAOU,IAAI,CAACF,SAASf,MAAM,EAAEkB,MAAM,GAAG,GAAG;oBAC3Cf,WAAW,CAACM,UAAU,CAACT,MAAM,CAACmB,IAAI,CAACJ,SAASf,MAAM;gBACpD;gBAEA,gDAAgD;gBAChDe,SAASK,GAAG,CAACC,SAAS,GAAGR;gBACzBV,WAAW,CAACM,UAAU,CAACG,IAAI,CAACO,IAAI,CAACJ,SAASK,GAAG;gBAE7Cb,OAAOC,OAAO,CAACO,SAASJ,OAAO,EAAEP,OAAO,CAAC,CAAC,CAACkB,gBAAgBC,mBAAmB;oBAC5EA,mBAAmBF,SAAS,GAAGN,SAASK,GAAG,CAACN,EAAE;oBAC9CS,mBAAmBC,OAAO,GAAGF;oBAC7BnB,WAAW,CAACM,UAAU,CAACE,OAAO,CAACQ,IAAI,CAACI;oBACpC,IAAI,CAACR,SAASK,GAAG,CAACN,EA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{"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
+ {"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":[],"mappings":"AAkCA,WAA0C"}
@@ -1 +1 @@
1
- {"version":3,"file":"appendPrefixToKeys.d.ts","sourceRoot":"","sources":["../../src/utilities/appendPrefixToKeys.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,WAAY,OAAO,MAAM,EAAE,OAAO,CAAC,UAAU,MAAM,KAAG,CAI9E,CAAA"}
1
+ {"version":3,"file":"appendPrefixToKeys.d.ts","sourceRoot":"","sources":["../../src/utilities/appendPrefixToKeys.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,GAAI,CAAC,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,MAAM,KAAG,CAI9E,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/appendPrefixToKeys.ts"],"sourcesContent":["export const appendPrefixToObjectKeys = <T>(obj: Record<string, unknown>, prefix: string): T =>\n Object.entries(obj).reduce((res, [key, val]) => {\n res[`${prefix}_${key}`] = val\n return res\n }, {} as T)\n"],"names":["appendPrefixToObjectKeys","obj","prefix","Object","entries","reduce","res","key","val"],"rangeMappings":";;;","mappings":"AAAA,OAAO,MAAMA,2BAA2B,CAAIC,KAA8BC,SACxEC,OAAOC,OAAO,CAACH,KAAKI,MAAM,CAAC,CAACC,KAAK,CAACC,KAAKC,IAAI;QACzCF,GAAG,CAAC,CAAC,EAAEJ,OAAO,CAAC,EAAEK,IAAI,CAAC,CAAC,GAAGC;QAC1B,OAAOF;IACT,GAAG,CAAC,GAAO"}
1
+ {"version":3,"sources":["../../src/utilities/appendPrefixToKeys.ts"],"sourcesContent":["export const appendPrefixToObjectKeys = <T>(obj: Record<string, unknown>, prefix: string): T =>\n Object.entries(obj).reduce((res, [key, val]) => {\n res[`${prefix}_${key}`] = val\n return res\n }, {} as T)\n"],"names":["appendPrefixToObjectKeys","obj","prefix","Object","entries","reduce","res","key","val"],"mappings":"AAAA,OAAO,MAAMA,2BAA2B,CAAIC,KAA8BC,SACxEC,OAAOC,OAAO,CAACH,KAAKI,MAAM,CAAC,CAACC,KAAK,CAACC,KAAKC,IAAI;QACzCF,GAAG,CAAC,CAAC,EAAEJ,OAAO,CAAC,EAAEK,IAAI,CAAC,CAAC,GAAGC;QAC1B,OAAOF;IACT,GAAG,CAAC,GAAO"}