@payloadcms/plugin-import-export 4.0.0-internal.c2b57ce → 4.0.0-internal.c6494b5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/dist/components/CollectionField/index.d.ts +3 -2
  2. package/dist/components/CollectionField/index.d.ts.map +1 -1
  3. package/dist/components/CollectionField/index.js.map +1 -1
  4. package/dist/components/ExportListMenuItem/index.d.ts.map +1 -1
  5. package/dist/components/ExportListMenuItem/index.js +14 -12
  6. package/dist/components/ExportListMenuItem/index.js.map +1 -1
  7. package/dist/components/ExportPreview/index.css +52 -0
  8. package/dist/components/ExportPreview/index.d.ts +1 -1
  9. package/dist/components/ExportPreview/index.d.ts.map +1 -1
  10. package/dist/components/ExportPreview/index.js +12 -2
  11. package/dist/components/ExportPreview/index.js.map +1 -1
  12. package/dist/components/FieldsToExport/index.d.ts +3 -2
  13. package/dist/components/FieldsToExport/index.d.ts.map +1 -1
  14. package/dist/components/FieldsToExport/index.js +18 -15
  15. package/dist/components/FieldsToExport/index.js.map +1 -1
  16. package/dist/components/FieldsToExport/reduceFields.d.ts +6 -0
  17. package/dist/components/FieldsToExport/reduceFields.d.ts.map +1 -1
  18. package/dist/components/FieldsToExport/reduceFields.js +4 -0
  19. package/dist/components/FieldsToExport/reduceFields.js.map +1 -1
  20. package/dist/components/FormatField/index.d.ts +3 -2
  21. package/dist/components/FormatField/index.d.ts.map +1 -1
  22. package/dist/components/FormatField/index.js +6 -3
  23. package/dist/components/FormatField/index.js.map +1 -1
  24. package/dist/components/ImportListMenuItem/index.d.ts.map +1 -1
  25. package/dist/components/ImportListMenuItem/index.js +14 -12
  26. package/dist/components/ImportListMenuItem/index.js.map +1 -1
  27. package/dist/components/ImportPreview/index.css +45 -0
  28. package/dist/components/ImportPreview/index.d.ts +1 -1
  29. package/dist/components/ImportPreview/index.d.ts.map +1 -1
  30. package/dist/components/ImportPreview/index.js +44 -11
  31. package/dist/components/ImportPreview/index.js.map +1 -1
  32. package/dist/components/LimitField/index.d.ts +3 -2
  33. package/dist/components/LimitField/index.d.ts.map +1 -1
  34. package/dist/components/LimitField/index.js.map +1 -1
  35. package/dist/components/LocaleField/index.d.ts +3 -2
  36. package/dist/components/LocaleField/index.d.ts.map +1 -1
  37. package/dist/components/LocaleField/index.js.map +1 -1
  38. package/dist/components/Page/index.d.ts +4 -3
  39. package/dist/components/Page/index.d.ts.map +1 -1
  40. package/dist/components/Page/index.js +1 -1
  41. package/dist/components/Page/index.js.map +1 -1
  42. package/dist/components/RelationshipCell/getRelationshipGroupKey.d.ts +7 -0
  43. package/dist/components/RelationshipCell/getRelationshipGroupKey.d.ts.map +1 -0
  44. package/dist/components/RelationshipCell/getRelationshipGroupKey.js +3 -0
  45. package/dist/components/RelationshipCell/getRelationshipGroupKey.js.map +1 -0
  46. package/dist/components/RelationshipCell/getRelationshipGroups.d.ts +43 -0
  47. package/dist/components/RelationshipCell/getRelationshipGroups.d.ts.map +1 -0
  48. package/dist/components/RelationshipCell/getRelationshipGroups.js +109 -0
  49. package/dist/components/RelationshipCell/getRelationshipGroups.js.map +1 -0
  50. package/dist/components/RelationshipCell/index.css +30 -0
  51. package/dist/components/RelationshipCell/index.d.ts +15 -0
  52. package/dist/components/RelationshipCell/index.d.ts.map +1 -0
  53. package/dist/components/RelationshipCell/index.js +57 -0
  54. package/dist/components/RelationshipCell/index.js.map +1 -0
  55. package/dist/components/SortBy/index.css +9 -0
  56. package/dist/components/SortBy/index.d.ts +4 -3
  57. package/dist/components/SortBy/index.d.ts.map +1 -1
  58. package/dist/components/SortBy/index.js +1 -2
  59. package/dist/components/SortBy/index.js.map +1 -1
  60. package/dist/components/SortOrder/index.css +9 -0
  61. package/dist/components/SortOrder/index.d.ts +4 -3
  62. package/dist/components/SortOrder/index.d.ts.map +1 -1
  63. package/dist/components/SortOrder/index.js +1 -2
  64. package/dist/components/SortOrder/index.js.map +1 -1
  65. package/dist/export/batchProcessor.d.ts +4 -3
  66. package/dist/export/batchProcessor.d.ts.map +1 -1
  67. package/dist/export/batchProcessor.js +6 -2
  68. package/dist/export/batchProcessor.js.map +1 -1
  69. package/dist/export/createExport.d.ts +4 -2
  70. package/dist/export/createExport.d.ts.map +1 -1
  71. package/dist/export/createExport.js +7 -2
  72. package/dist/export/createExport.js.map +1 -1
  73. package/dist/export/getCreateExportCollectionTask.d.ts.map +1 -1
  74. package/dist/export/getCreateExportCollectionTask.js +11 -0
  75. package/dist/export/getCreateExportCollectionTask.js.map +1 -1
  76. package/dist/export/getExportCollection.d.ts.map +1 -1
  77. package/dist/export/getExportCollection.js +9 -4
  78. package/dist/export/getExportCollection.js.map +1 -1
  79. package/dist/export/getFields.d.ts.map +1 -1
  80. package/dist/export/handleDownload.d.ts.map +1 -1
  81. package/dist/export/handleDownload.js +7 -3
  82. package/dist/export/handleDownload.js.map +1 -1
  83. package/dist/export/handlePreview.d.ts.map +1 -1
  84. package/dist/export/handlePreview.js +24 -5
  85. package/dist/export/handlePreview.js.map +1 -1
  86. package/dist/exports/types.d.ts +1 -1
  87. package/dist/exports/types.d.ts.map +1 -1
  88. package/dist/exports/types.js.map +1 -1
  89. package/dist/import/batchProcessor.d.ts +4 -3
  90. package/dist/import/batchProcessor.d.ts.map +1 -1
  91. package/dist/import/batchProcessor.js +15 -8
  92. package/dist/import/batchProcessor.js.map +1 -1
  93. package/dist/import/createImport.d.ts +3 -2
  94. package/dist/import/createImport.d.ts.map +1 -1
  95. package/dist/import/createImport.js +8 -1
  96. package/dist/import/createImport.js.map +1 -1
  97. package/dist/import/getCreateImportCollectionTask.d.ts.map +1 -1
  98. package/dist/import/getCreateImportCollectionTask.js +5 -2
  99. package/dist/import/getCreateImportCollectionTask.js.map +1 -1
  100. package/dist/import/getFields.d.ts.map +1 -1
  101. package/dist/import/getImportCollection.d.ts.map +1 -1
  102. package/dist/import/getImportCollection.js +6 -4
  103. package/dist/import/getImportCollection.js.map +1 -1
  104. package/dist/import/handlePreview.d.ts.map +1 -1
  105. package/dist/import/handlePreview.js +5 -1
  106. package/dist/import/handlePreview.js.map +1 -1
  107. package/dist/index.d.ts +1 -2
  108. package/dist/index.d.ts.map +1 -1
  109. package/dist/index.js +6 -3
  110. package/dist/index.js.map +1 -1
  111. package/dist/translations/languages/en.d.ts.map +1 -1
  112. package/dist/types.d.ts +17 -1
  113. package/dist/types.d.ts.map +1 -1
  114. package/dist/types.js.map +1 -1
  115. package/dist/utilities/applyFieldHooks.d.ts.map +1 -1
  116. package/dist/utilities/applyFieldHooks.js +1 -1
  117. package/dist/utilities/applyFieldHooks.js.map +1 -1
  118. package/dist/utilities/buildDisabledFieldRegex.d.ts.map +1 -1
  119. package/dist/utilities/collectDisabledFieldPaths.d.ts.map +1 -1
  120. package/dist/utilities/fieldToRegex.d.ts.map +1 -1
  121. package/dist/utilities/flattenObject.d.ts.map +1 -1
  122. package/dist/utilities/flattenedFields.d.ts.map +1 -1
  123. package/dist/utilities/flattenedFields.js +3 -0
  124. package/dist/utilities/flattenedFields.js.map +1 -1
  125. package/dist/utilities/getExportFieldFunctions.d.ts.map +1 -1
  126. package/dist/utilities/getExportFieldFunctions.js +64 -27
  127. package/dist/utilities/getExportFieldFunctions.js.map +1 -1
  128. package/dist/utilities/getFileFromDoc.d.ts.map +1 -1
  129. package/dist/utilities/getFileFromDoc.js +3 -3
  130. package/dist/utilities/getFileFromDoc.js.map +1 -1
  131. package/dist/utilities/getFlattenedFieldKeys.d.ts.map +1 -1
  132. package/dist/utilities/getImportFieldFunctions.d.ts.map +1 -1
  133. package/dist/utilities/getPluginCollections.d.ts.map +1 -1
  134. package/dist/utilities/getSchemaColumns.d.ts.map +1 -1
  135. package/dist/utilities/getSelect.d.ts.map +1 -1
  136. package/dist/utilities/getSelect.js +11 -3
  137. package/dist/utilities/getSelect.js.map +1 -1
  138. package/dist/utilities/getSubmittedFormValues.d.ts +12 -0
  139. package/dist/utilities/getSubmittedFormValues.d.ts.map +1 -0
  140. package/dist/utilities/getSubmittedFormValues.js +24 -0
  141. package/dist/utilities/getSubmittedFormValues.js.map +1 -0
  142. package/dist/utilities/isPlainObject.d.ts.map +1 -1
  143. package/dist/utilities/parseCSV.d.ts.map +1 -1
  144. package/dist/utilities/parseJSON.d.ts.map +1 -1
  145. package/dist/utilities/polymorphicRel.d.ts.map +1 -1
  146. package/dist/utilities/processRichTextField.d.ts.map +1 -1
  147. package/dist/utilities/processRichTextField.js +7 -0
  148. package/dist/utilities/processRichTextField.js.map +1 -1
  149. package/dist/utilities/removeDisabledFields.d.ts.map +1 -1
  150. package/dist/utilities/setNestedValue.d.ts +2 -1
  151. package/dist/utilities/setNestedValue.d.ts.map +1 -1
  152. package/dist/utilities/setNestedValue.js +65 -34
  153. package/dist/utilities/setNestedValue.js.map +1 -1
  154. package/dist/utilities/sortHelpers.d.ts +1 -1
  155. package/dist/utilities/sortHelpers.d.ts.map +1 -1
  156. package/dist/utilities/unflattenObject.d.ts.map +1 -1
  157. package/dist/utilities/unflattenObject.js +21 -2
  158. package/dist/utilities/unflattenObject.js.map +1 -1
  159. package/dist/utilities/unflattenPostProcess.d.ts.map +1 -1
  160. package/dist/utilities/unflattenPostProcess.js +39 -13
  161. package/dist/utilities/unflattenPostProcess.js.map +1 -1
  162. package/dist/utilities/validateLimitValue.d.ts.map +1 -1
  163. package/license.md +1 -1
  164. package/package.json +9 -9
  165. package/dist/components/ExportPreview/index.scss +0 -48
  166. package/dist/components/FieldsToExport/index.scss +0 -0
  167. package/dist/components/FieldsToExport/reduceFields.spec.js +0 -239
  168. package/dist/components/FieldsToExport/reduceFields.spec.js.map +0 -1
  169. package/dist/components/ImportPreview/index.scss +0 -41
  170. package/dist/components/SortBy/index.scss +0 -3
  171. package/dist/components/SortOrder/index.scss +0 -3
  172. package/dist/utilities/applyFieldHooks.spec.js +0 -205
  173. package/dist/utilities/applyFieldHooks.spec.js.map +0 -1
  174. package/dist/utilities/buildDisabledFieldRegex.spec.js +0 -64
  175. package/dist/utilities/buildDisabledFieldRegex.spec.js.map +0 -1
  176. package/dist/utilities/fieldToRegex.spec.js +0 -151
  177. package/dist/utilities/fieldToRegex.spec.js.map +0 -1
  178. package/dist/utilities/filterToSelectedFields.spec.js +0 -204
  179. package/dist/utilities/filterToSelectedFields.spec.js.map +0 -1
  180. package/dist/utilities/flattenObject.spec.js +0 -158
  181. package/dist/utilities/flattenObject.spec.js.map +0 -1
  182. package/dist/utilities/getExportFieldFunctions.spec.js +0 -50
  183. package/dist/utilities/getExportFieldFunctions.spec.js.map +0 -1
  184. package/dist/utilities/getImportFieldFunctions.spec.js +0 -167
  185. package/dist/utilities/getImportFieldFunctions.spec.js.map +0 -1
  186. package/dist/utilities/getSchemaColumns.spec.js +0 -157
  187. package/dist/utilities/getSchemaColumns.spec.js.map +0 -1
  188. package/dist/utilities/parseCSV.spec.js +0 -195
  189. package/dist/utilities/parseCSV.spec.js.map +0 -1
  190. package/dist/utilities/siblingDoc.spec.js +0 -278
  191. package/dist/utilities/siblingDoc.spec.js.map +0 -1
  192. package/dist/utilities/unflattenObject.spec.js +0 -713
  193. package/dist/utilities/unflattenObject.spec.js.map +0 -1
  194. /package/dist/components/Page/{index.scss → index.css} +0 -0
@@ -2,6 +2,13 @@
2
2
  * Process rich text fields to ensure proper data types for Lexical editor.
3
3
  * Lexical expects certain properties to be numbers, not strings.
4
4
  */ export const processRichTextField = (value)=>{
5
+ if (typeof value === 'string') {
6
+ try {
7
+ value = JSON.parse(value);
8
+ } catch {
9
+ return value;
10
+ }
11
+ }
5
12
  if (!value || typeof value !== 'object') {
6
13
  return value;
7
14
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/processRichTextField.ts"],"sourcesContent":["/**\n * Process rich text fields to ensure proper data types for Lexical editor.\n * Lexical expects certain properties to be numbers, not strings.\n */\nexport const processRichTextField = (value: unknown): unknown => {\n if (!value || typeof value !== 'object') {\n return value\n }\n\n // Properties that should be numbers in Lexical\n const numericProperties = [\n 'detail',\n 'format',\n 'indent',\n 'version',\n 'value',\n 'start',\n 'textFormat',\n 'textStyle',\n ]\n\n const processNode = (node: unknown): unknown => {\n if (!node || typeof node !== 'object') {\n return node\n }\n\n // Process current node's properties\n const processed: Record<string, unknown> = {}\n for (const [key, val] of Object.entries(node as Record<string, unknown>)) {\n if (numericProperties.includes(key) && typeof val === 'string') {\n // Convert string numbers to actual numbers\n const num = parseFloat(val)\n processed[key] = isNaN(num) ? val : num\n } else if (key === 'children' && Array.isArray(val)) {\n // Recursively process children\n processed[key] = val.map((child) => processNode(child))\n } else if (typeof val === 'object' && val !== null) {\n // Recursively process nested objects\n processed[key] = processNode(val)\n } else {\n processed[key] = val\n }\n }\n\n return processed\n }\n\n return processNode(value)\n}\n"],"names":["processRichTextField","value","numericProperties","processNode","node","processed","key","val","Object","entries","includes","num","parseFloat","isNaN","Array","isArray","map","child"],"mappings":"AAAA;;;CAGC,GACD,OAAO,MAAMA,uBAAuB,CAACC;IACnC,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU;QACvC,OAAOA;IACT;IAEA,+CAA+C;IAC/C,MAAMC,oBAAoB;QACxB;QACA;QACA;QACA;QACA;QACA;QACA;QACA;KACD;IAED,MAAMC,cAAc,CAACC;QACnB,IAAI,CAACA,QAAQ,OAAOA,SAAS,UAAU;YACrC,OAAOA;QACT;QAEA,oCAAoC;QACpC,MAAMC,YAAqC,CAAC;QAC5C,KAAK,MAAM,CAACC,KAAKC,IAAI,IAAIC,OAAOC,OAAO,CAACL,MAAkC;YACxE,IAAIF,kBAAkBQ,QAAQ,CAACJ,QAAQ,OAAOC,QAAQ,UAAU;gBAC9D,2CAA2C;gBAC3C,MAAMI,MAAMC,WAAWL;gBACvBF,SAAS,CAACC,IAAI,GAAGO,MAAMF,OAAOJ,MAAMI;YACtC,OAAO,IAAIL,QAAQ,cAAcQ,MAAMC,OAAO,CAACR,MAAM;gBACnD,+BAA+B;gBAC/BF,SAAS,CAACC,IAAI,GAAGC,IAAIS,GAAG,CAAC,CAACC,QAAUd,YAAYc;YAClD,OAAO,IAAI,OAAOV,QAAQ,YAAYA,QAAQ,MAAM;gBAClD,qCAAqC;gBACrCF,SAAS,CAACC,IAAI,GAAGH,YAAYI;YAC/B,OAAO;gBACLF,SAAS,CAACC,IAAI,GAAGC;YACnB;QACF;QAEA,OAAOF;IACT;IAEA,OAAOF,YAAYF;AACrB,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/processRichTextField.ts"],"sourcesContent":["/**\n * Process rich text fields to ensure proper data types for Lexical editor.\n * Lexical expects certain properties to be numbers, not strings.\n */\nexport const processRichTextField = (value: unknown): unknown => {\n if (typeof value === 'string') {\n try {\n value = JSON.parse(value)\n } catch {\n return value\n }\n }\n\n if (!value || typeof value !== 'object') {\n return value\n }\n\n // Properties that should be numbers in Lexical\n const numericProperties = [\n 'detail',\n 'format',\n 'indent',\n 'version',\n 'value',\n 'start',\n 'textFormat',\n 'textStyle',\n ]\n\n const processNode = (node: unknown): unknown => {\n if (!node || typeof node !== 'object') {\n return node\n }\n\n // Process current node's properties\n const processed: Record<string, unknown> = {}\n for (const [key, val] of Object.entries(node as Record<string, unknown>)) {\n if (numericProperties.includes(key) && typeof val === 'string') {\n // Convert string numbers to actual numbers\n const num = parseFloat(val)\n processed[key] = isNaN(num) ? val : num\n } else if (key === 'children' && Array.isArray(val)) {\n // Recursively process children\n processed[key] = val.map((child) => processNode(child))\n } else if (typeof val === 'object' && val !== null) {\n // Recursively process nested objects\n processed[key] = processNode(val)\n } else {\n processed[key] = val\n }\n }\n\n return processed\n }\n\n return processNode(value)\n}\n"],"names":["processRichTextField","value","JSON","parse","numericProperties","processNode","node","processed","key","val","Object","entries","includes","num","parseFloat","isNaN","Array","isArray","map","child"],"mappings":"AAAA;;;CAGC,GACD,OAAO,MAAMA,uBAAuB,CAACC;IACnC,IAAI,OAAOA,UAAU,UAAU;QAC7B,IAAI;YACFA,QAAQC,KAAKC,KAAK,CAACF;QACrB,EAAE,OAAM;YACN,OAAOA;QACT;IACF;IAEA,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU;QACvC,OAAOA;IACT;IAEA,+CAA+C;IAC/C,MAAMG,oBAAoB;QACxB;QACA;QACA;QACA;QACA;QACA;QACA;QACA;KACD;IAED,MAAMC,cAAc,CAACC;QACnB,IAAI,CAACA,QAAQ,OAAOA,SAAS,UAAU;YACrC,OAAOA;QACT;QAEA,oCAAoC;QACpC,MAAMC,YAAqC,CAAC;QAC5C,KAAK,MAAM,CAACC,KAAKC,IAAI,IAAIC,OAAOC,OAAO,CAACL,MAAkC;YACxE,IAAIF,kBAAkBQ,QAAQ,CAACJ,QAAQ,OAAOC,QAAQ,UAAU;gBAC9D,2CAA2C;gBAC3C,MAAMI,MAAMC,WAAWL;gBACvBF,SAAS,CAACC,IAAI,GAAGO,MAAMF,OAAOJ,MAAMI;YACtC,OAAO,IAAIL,QAAQ,cAAcQ,MAAMC,OAAO,CAACR,MAAM;gBACnD,+BAA+B;gBAC/BF,SAAS,CAACC,IAAI,GAAGC,IAAIS,GAAG,CAAC,CAACC,QAAUd,YAAYc;YAClD,OAAO,IAAI,OAAOV,QAAQ,YAAYA,QAAQ,MAAM;gBAClD,qCAAqC;gBACrCF,SAAS,CAACC,IAAI,GAAGH,YAAYI;YAC/B,OAAO;gBACLF,SAAS,CAACC,IAAI,GAAGC;YACnB;QACF;QAEA,OAAOF;IACT;IAEA,OAAOF,YAAYJ;AACrB,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"removeDisabledFields.d.ts","sourceRoot":"","sources":["../../src/utilities/removeDisabledFields.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,oBAAoB,GAC/B,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAU,MAAM,EAAO,KACtB,MAAM,CAAC,MAAM,EAAE,OAAO,CA8DxB,CAAA"}
1
+ {"version":3,"file":"removeDisabledFields.d.ts","sourceRoot":"","sources":["../../src/utilities/removeDisabledFields.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,oBAAoB,QAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,aAClB,MAAM,EAAE,KACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CA8DxB,CAAA"}
@@ -14,6 +14,7 @@
14
14
  * @param obj - The target object to mutate.
15
15
  * @param path - A dot-separated string path indicating where to assign the value.
16
16
  * @param value - The value to set at the specified path.
17
+ * @param source - The source object used to validate array boundaries.
17
18
  */
18
- export declare const setNestedValue: (obj: Record<string, unknown>, path: string, value: unknown) => void;
19
+ export declare const setNestedValue: (obj: Record<string, unknown>, path: string, value: unknown, source?: Record<string, unknown>) => void;
19
20
  //# sourceMappingURL=setNestedValue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"setNestedValue.d.ts","sourceRoot":"","sources":["../../src/utilities/setNestedValue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,eAAO,MAAM,cAAc,GACzB,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,MAAM,MAAM,EACZ,OAAO,OAAO,KACb,IA8CF,CAAA"}
1
+ {"version":3,"file":"setNestedValue.d.ts","sourceRoot":"","sources":["../../src/utilities/setNestedValue.ts"],"names":[],"mappings":"AAoDA;;;;;;;;;;;;;;;;;GAiBG;AAEH,eAAO,MAAM,cAAc,QACpB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QACtB,MAAM,SACL,OAAO,WACL,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC/B,IAyCF,CAAA"}
@@ -1,3 +1,34 @@
1
+ import { APIError } from 'payload';
2
+ import { hasUnsupportedFieldPathSegment, setOwnProperty } from 'payload/shared';
3
+ const MAX_UNVERIFIED_SPARSE_ARRAY_GAP = 1;
4
+ const createObject = ()=>Object.create(null);
5
+ const isArrayIndex = (part)=>{
6
+ if (!/^(?:0|[1-9]\d*)$/.test(part)) {
7
+ return false;
8
+ }
9
+ const index = Number(part);
10
+ return Number.isSafeInteger(index) && index >= 0;
11
+ };
12
+ const getPathKey = (target, part, source)=>{
13
+ if (!Array.isArray(target) || !isArrayIndex(part)) {
14
+ return part;
15
+ }
16
+ const index = Number(part);
17
+ if (Array.isArray(source) && index >= source.length || !Array.isArray(source) && index > target.length + MAX_UNVERIFIED_SPARSE_ARRAY_GAP) {
18
+ throw new APIError('Invalid field path.', 400, null, true);
19
+ }
20
+ return index;
21
+ };
22
+ const getSourceValue = (source, part)=>{
23
+ if (source === null || typeof source !== 'object') {
24
+ return undefined;
25
+ }
26
+ const key = Array.isArray(source) && isArrayIndex(part) ? Number(part) : part;
27
+ if (!Object.hasOwn(source, key)) {
28
+ return undefined;
29
+ }
30
+ return source[key];
31
+ };
1
32
  /**
2
33
  * Sets a value deeply into a nested object or array, based on a dot-notation path.
3
34
  *
@@ -14,44 +45,44 @@
14
45
  * @param obj - The target object to mutate.
15
46
  * @param path - A dot-separated string path indicating where to assign the value.
16
47
  * @param value - The value to set at the specified path.
17
- */ export const setNestedValue = (obj, path, value)=>{
48
+ * @param source - The source object used to validate array boundaries.
49
+ */ export const setNestedValue = (obj, path, value, source)=>{
18
50
  const parts = path.split('.');
51
+ if (hasUnsupportedFieldPathSegment({
52
+ segments: parts
53
+ })) {
54
+ throw new APIError('Invalid field path.', 400, null, true);
55
+ }
56
+ const lastPart = parts.pop();
57
+ if (lastPart === undefined) {
58
+ return;
59
+ }
19
60
  let current = obj;
20
- for(let i = 0; i < parts.length; i++){
21
- const part = parts[i];
22
- const isLast = i === parts.length - 1;
23
- const isIndex = !Number.isNaN(Number(part));
24
- if (isIndex) {
25
- const index = Number(part);
26
- // Ensure the current target is an array
27
- if (!Array.isArray(current)) {
28
- current = [];
29
- }
30
- const currentArray = current;
31
- // Ensure the array slot is initialized
32
- if (!currentArray[index]) {
33
- currentArray[index] = {};
34
- }
35
- if (isLast) {
36
- currentArray[index] = value;
37
- } else {
38
- current = currentArray[index];
39
- }
40
- } else {
41
- const currentObj = current;
42
- // Ensure the object key exists
43
- if (isLast) {
44
- if (typeof part === 'string') {
45
- currentObj[part] = value;
46
- }
47
- } else {
48
- if (typeof currentObj[part] !== 'object' || currentObj[part] === null) {
49
- currentObj[part] = {};
50
- }
51
- current = currentObj[part];
52
- }
61
+ let sourceCurrent = source;
62
+ for (const [i, part] of parts.entries()){
63
+ const key = getPathKey(current, part, sourceCurrent);
64
+ const currentRecord = current;
65
+ const nextPart = parts[i + 1] ?? lastPart;
66
+ const nextSource = getSourceValue(sourceCurrent, part);
67
+ const hasOwnNextValue = Object.hasOwn(currentRecord, key);
68
+ const nextValue = hasOwnNextValue ? currentRecord[key] : undefined;
69
+ if (!hasOwnNextValue || typeof nextValue !== 'object' || nextValue === null) {
70
+ setOwnProperty({
71
+ key,
72
+ target: currentRecord,
73
+ value: isArrayIndex(nextPart) ? [] : createObject()
74
+ });
53
75
  }
76
+ current = currentRecord[key];
77
+ sourceCurrent = nextSource;
54
78
  }
79
+ const lastKey = getPathKey(current, lastPart, sourceCurrent);
80
+ const finalRecord = current;
81
+ setOwnProperty({
82
+ key: lastKey,
83
+ target: finalRecord,
84
+ value
85
+ });
55
86
  };
56
87
 
57
88
  //# sourceMappingURL=setNestedValue.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/setNestedValue.ts"],"sourcesContent":["/**\n * Sets a value deeply into a nested object or array, based on a dot-notation path.\n *\n * This function:\n * - Supports array indexing (e.g., \"array.0.field1\")\n * - Creates intermediate arrays/objects as needed\n * - Mutates the target object directly\n *\n * @example\n * const obj = {}\n * setNestedValue(obj, 'group.array.0.field1', 'hello')\n * // Result: { group: { array: [ { field1: 'hello' } ] } }\n *\n * @param obj - The target object to mutate.\n * @param path - A dot-separated string path indicating where to assign the value.\n * @param value - The value to set at the specified path.\n */\n\nexport const setNestedValue = (\n obj: Record<string, unknown>,\n path: string,\n value: unknown,\n): void => {\n const parts = path.split('.')\n let current: unknown = obj\n\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i]\n const isLast = i === parts.length - 1\n const isIndex = !Number.isNaN(Number(part))\n\n if (isIndex) {\n const index = Number(part)\n\n // Ensure the current target is an array\n if (!Array.isArray(current)) {\n current = []\n }\n\n const currentArray = current as unknown[]\n\n // Ensure the array slot is initialized\n if (!currentArray[index]) {\n currentArray[index] = {}\n }\n\n if (isLast) {\n currentArray[index] = value\n } else {\n current = currentArray[index]\n }\n } else {\n const currentObj = current as Record<string, unknown>\n\n // Ensure the object key exists\n if (isLast) {\n if (typeof part === 'string') {\n currentObj[part] = value\n }\n } else {\n if (typeof currentObj[part as string] !== 'object' || currentObj[part as string] === null) {\n currentObj[part as string] = {}\n }\n\n current = currentObj[part as string]\n }\n }\n }\n}\n"],"names":["setNestedValue","obj","path","value","parts","split","current","i","length","part","isLast","isIndex","Number","isNaN","index","Array","isArray","currentArray","currentObj"],"mappings":"AAAA;;;;;;;;;;;;;;;;CAgBC,GAED,OAAO,MAAMA,iBAAiB,CAC5BC,KACAC,MACAC;IAEA,MAAMC,QAAQF,KAAKG,KAAK,CAAC;IACzB,IAAIC,UAAmBL;IAEvB,IAAK,IAAIM,IAAI,GAAGA,IAAIH,MAAMI,MAAM,EAAED,IAAK;QACrC,MAAME,OAAOL,KAAK,CAACG,EAAE;QACrB,MAAMG,SAASH,MAAMH,MAAMI,MAAM,GAAG;QACpC,MAAMG,UAAU,CAACC,OAAOC,KAAK,CAACD,OAAOH;QAErC,IAAIE,SAAS;YACX,MAAMG,QAAQF,OAAOH;YAErB,wCAAwC;YACxC,IAAI,CAACM,MAAMC,OAAO,CAACV,UAAU;gBAC3BA,UAAU,EAAE;YACd;YAEA,MAAMW,eAAeX;YAErB,uCAAuC;YACvC,IAAI,CAACW,YAAY,CAACH,MAAM,EAAE;gBACxBG,YAAY,CAACH,MAAM,GAAG,CAAC;YACzB;YAEA,IAAIJ,QAAQ;gBACVO,YAAY,CAACH,MAAM,GAAGX;YACxB,OAAO;gBACLG,UAAUW,YAAY,CAACH,MAAM;YAC/B;QACF,OAAO;YACL,MAAMI,aAAaZ;YAEnB,+BAA+B;YAC/B,IAAII,QAAQ;gBACV,IAAI,OAAOD,SAAS,UAAU;oBAC5BS,UAAU,CAACT,KAAK,GAAGN;gBACrB;YACF,OAAO;gBACL,IAAI,OAAOe,UAAU,CAACT,KAAe,KAAK,YAAYS,UAAU,CAACT,KAAe,KAAK,MAAM;oBACzFS,UAAU,CAACT,KAAe,GAAG,CAAC;gBAChC;gBAEAH,UAAUY,UAAU,CAACT,KAAe;YACtC;QACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/setNestedValue.ts"],"sourcesContent":["import { APIError } from 'payload'\nimport { hasUnsupportedFieldPathSegment, setOwnProperty } from 'payload/shared'\n\nconst MAX_UNVERIFIED_SPARSE_ARRAY_GAP = 1\n\nconst createObject = (): Record<string, unknown> => Object.create(null) as Record<string, unknown>\n\nconst isArrayIndex = (part: string): boolean => {\n if (!/^(?:0|[1-9]\\d*)$/.test(part)) {\n return false\n }\n\n const index = Number(part)\n\n return Number.isSafeInteger(index) && index >= 0\n}\n\nconst getPathKey = (\n target: Record<string, unknown> | unknown[],\n part: string,\n source: unknown,\n): number | string => {\n if (!Array.isArray(target) || !isArrayIndex(part)) {\n return part\n }\n\n const index = Number(part)\n\n if (\n (Array.isArray(source) && index >= source.length) ||\n (!Array.isArray(source) && index > target.length + MAX_UNVERIFIED_SPARSE_ARRAY_GAP)\n ) {\n throw new APIError('Invalid field path.', 400, null, true)\n }\n\n return index\n}\n\nconst getSourceValue = (source: unknown, part: string): unknown => {\n if (source === null || typeof source !== 'object') {\n return undefined\n }\n\n const key = Array.isArray(source) && isArrayIndex(part) ? Number(part) : part\n\n if (!Object.hasOwn(source, key)) {\n return undefined\n }\n\n return (source as Record<number | string, unknown>)[key]\n}\n\n/**\n * Sets a value deeply into a nested object or array, based on a dot-notation path.\n *\n * This function:\n * - Supports array indexing (e.g., \"array.0.field1\")\n * - Creates intermediate arrays/objects as needed\n * - Mutates the target object directly\n *\n * @example\n * const obj = {}\n * setNestedValue(obj, 'group.array.0.field1', 'hello')\n * // Result: { group: { array: [ { field1: 'hello' } ] } }\n *\n * @param obj - The target object to mutate.\n * @param path - A dot-separated string path indicating where to assign the value.\n * @param value - The value to set at the specified path.\n * @param source - The source object used to validate array boundaries.\n */\n\nexport const setNestedValue = (\n obj: Record<string, unknown>,\n path: string,\n value: unknown,\n source?: Record<string, unknown>,\n): void => {\n const parts = path.split('.')\n\n if (hasUnsupportedFieldPathSegment({ segments: parts })) {\n throw new APIError('Invalid field path.', 400, null, true)\n }\n\n const lastPart = parts.pop()\n\n if (lastPart === undefined) {\n return\n }\n\n let current: Record<string, unknown> | unknown[] = obj\n let sourceCurrent: unknown = source\n\n for (const [i, part] of parts.entries()) {\n const key = getPathKey(current, part, sourceCurrent)\n const currentRecord = current as Record<number | string, unknown>\n const nextPart = parts[i + 1] ?? lastPart\n const nextSource = getSourceValue(sourceCurrent, part)\n\n const hasOwnNextValue = Object.hasOwn(currentRecord, key)\n const nextValue = hasOwnNextValue ? currentRecord[key] : undefined\n\n if (!hasOwnNextValue || typeof nextValue !== 'object' || nextValue === null) {\n setOwnProperty({\n key,\n target: currentRecord,\n value: isArrayIndex(nextPart) ? [] : createObject(),\n })\n }\n\n current = currentRecord[key] as Record<string, unknown> | unknown[]\n sourceCurrent = nextSource\n }\n\n const lastKey = getPathKey(current, lastPart, sourceCurrent)\n const finalRecord = current as Record<number | string, unknown>\n\n setOwnProperty({ key: lastKey, target: finalRecord, value })\n}\n"],"names":["APIError","hasUnsupportedFieldPathSegment","setOwnProperty","MAX_UNVERIFIED_SPARSE_ARRAY_GAP","createObject","Object","create","isArrayIndex","part","test","index","Number","isSafeInteger","getPathKey","target","source","Array","isArray","length","getSourceValue","undefined","key","hasOwn","setNestedValue","obj","path","value","parts","split","segments","lastPart","pop","current","sourceCurrent","i","entries","currentRecord","nextPart","nextSource","hasOwnNextValue","nextValue","lastKey","finalRecord"],"mappings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1B,IAAID,aAAaV,WAAW;QAC1B;IACF;IAEA,IAAIY,UAA+CR;IACnD,IAAIS,gBAAyBlB;IAE7B,KAAK,MAAM,CAACmB,GAAG1B,KAAK,IAAImB,MAAMQ,OAAO,GAAI;QACvC,MAAMd,MAAMR,WAAWmB,SAASxB,MAAMyB;QACtC,MAAMG,gBAAgBJ;QACtB,MAAMK,WAAWV,KAAK,CAACO,IAAI,EAAE,IAAIJ;QACjC,MAAMQ,aAAanB,eAAec,eAAezB;QAEjD,MAAM+B,kBAAkBlC,OAAOiB,MAAM,CAACc,eAAef;QACrD,MAAMmB,YAAYD,kBAAkBH,aAAa,CAACf,IAAI,GAAGD;QAEzD,IAAI,CAACmB,mBAAmB,OAAOC,cAAc,YAAYA,cAAc,MAAM;YAC3EtC,eAAe;gBACbmB;gBACAP,QAAQsB;gBACRV,OAAOnB,aAAa8B,YAAY,EAAE,GAAGjC;YACvC;QACF;QAEA4B,UAAUI,aAAa,CAACf,IAAI;QAC5BY,gBAAgBK;IAClB;IAEA,MAAMG,UAAU5B,WAAWmB,SAASF,UAAUG;IAC9C,MAAMS,cAAcV;IAEpB9B,eAAe;QAAEmB,KAAKoB;QAAS3B,QAAQ4B;QAAahB;IAAM;AAC5D,EAAC"}
@@ -1,6 +1,6 @@
1
1
  /** Remove a leading '-' from a sort value (e.g. "-title" -> "title") */
2
2
  export declare const stripSortDash: (v?: null | string) => string;
3
3
  /** Apply order to a base field (("title","desc") -> "-title") */
4
- export declare const applySortOrder: (field: string, order: "asc" | "desc") => string;
4
+ export declare const applySortOrder: (field: string, order: 'asc' | 'desc') => string;
5
5
  export declare const normalizeQueryParam: (v: unknown) => string | undefined;
6
6
  //# sourceMappingURL=sortHelpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sortHelpers.d.ts","sourceRoot":"","sources":["../../src/utilities/sortHelpers.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,eAAO,MAAM,aAAa,GAAI,IAAI,IAAI,GAAG,MAAM,KAAG,MAAwC,CAAA;AAE1F,iEAAiE;AACjE,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,OAAO,KAAK,GAAG,MAAM,KAAG,MAC9B,CAAA;AAGxC,eAAO,MAAM,mBAAmB,GAAI,GAAG,OAAO,KAAG,MAAM,GAAG,SAQzD,CAAA"}
1
+ {"version":3,"file":"sortHelpers.d.ts","sourceRoot":"","sources":["../../src/utilities/sortHelpers.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,eAAO,MAAM,aAAa,OAAQ,IAAI,GAAG,MAAM,KAAG,MAAwC,CAAA;AAE1F,iEAAiE;AACjE,eAAO,MAAM,cAAc,UAAW,MAAM,SAAS,KAAK,GAAG,MAAM,KAAG,MAC9B,CAAA;AAGxC,eAAO,MAAM,mBAAmB,MAAO,OAAO,KAAG,MAAM,GAAG,SAQzD,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"unflattenObject.d.ts","sourceRoot":"","sources":["../../src/utilities/unflattenObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAKvD,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,CAAA;IACvC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAA;IACvD,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAiCD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,GAAI,kDAM7B,aAAa,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CA0TxC,CAAA"}
1
+ {"version":3,"file":"unflattenObject.d.ts","sourceRoot":"","sources":["../../src/utilities/unflattenObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAKvD,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,CAAA;IACvC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAA;IACvD,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAuCD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,qDAMzB,aAAa,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAyUxC,CAAA"}
@@ -1,4 +1,4 @@
1
- import { getNestedFlattenedFields } from './flattenedFields.js';
1
+ import { getBlockFlattenedFields, getNestedFlattenedFields } from './flattenedFields.js';
2
2
  import { postProcessDocument } from './unflattenPostProcess.js';
3
3
  const indexSegment = /^\d+$/;
4
4
  const collectArrayLikeNames = (fields, into)=>{
@@ -9,6 +9,11 @@ const collectArrayLikeNames = (fields, into)=>{
9
9
  if (field.type === 'array' || field.type === 'blocks') {
10
10
  into.add(field.name);
11
11
  }
12
+ if (field.type === 'blocks') {
13
+ for (const block of field.blocks ?? []){
14
+ collectArrayLikeNames(getBlockFlattenedFields(block), into);
15
+ }
16
+ }
12
17
  const nested = getNestedFlattenedFields(field);
13
18
  if (nested) {
14
19
  collectArrayLikeNames(nested, into);
@@ -230,7 +235,9 @@ const collectArrayLikeNames = (fields, into)=>{
230
235
  blockObject[blockFieldName] = value;
231
236
  } else {
232
237
  if (!blockObject[blockFieldName] || typeof blockObject[blockFieldName] !== 'object') {
233
- blockObject[blockFieldName] = {};
238
+ const segmentAfterBlockField = pathSegments[i + 4];
239
+ const blockFieldIsArray = segmentAfterBlockField !== undefined && indexSegment.test(segmentAfterBlockField);
240
+ blockObject[blockFieldName] = blockFieldIsArray ? [] : {};
234
241
  }
235
242
  currentObject = blockObject[blockFieldName];
236
243
  i = i + 3;
@@ -254,6 +261,18 @@ const collectArrayLikeNames = (fields, into)=>{
254
261
  currentObject = arr[arrayIndex];
255
262
  i++;
256
263
  }
264
+ } else if (Array.isArray(currentObject) && indexSegment.test(segment)) {
265
+ // currentObject is an array we arrived at via block field traversal — treat the
266
+ // segment as a numeric index rather than a plain property name.
267
+ const idx = parseInt(segment, 10);
268
+ const arr = currentObject;
269
+ while(arr.length <= idx){
270
+ arr.push(null);
271
+ }
272
+ if (arr[idx] === null || arr[idx] === undefined) {
273
+ arr[idx] = {};
274
+ }
275
+ currentObject = arr[idx];
257
276
  } else {
258
277
  // Skip if already set to null (polymorphic relationship already processed)
259
278
  if (currentObject[segment] === null && isLast && segment === 'relationTo') {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/unflattenObject.ts"],"sourcesContent":["import type { FlattenedField, PayloadRequest } from 'payload'\n\nimport type { ImportFieldHookEntry } from '../types.js'\n\nimport { getNestedFlattenedFields } from './flattenedFields.js'\nimport { postProcessDocument } from './unflattenPostProcess.js'\n\ntype UnflattenArgs = {\n data: Record<string, unknown>\n fields: FlattenedField[]\n format?: 'csv' | 'json' | ({} & string)\n importFieldHooks?: Record<string, ImportFieldHookEntry>\n req: PayloadRequest\n}\n\nconst indexSegment = /^\\d+$/\n\nconst collectArrayLikeNames = (fields: FlattenedField[], into: Set<string>): void => {\n for (const field of fields) {\n if (!('name' in field) || !field.name) {\n continue\n }\n if (field.type === 'array' || field.type === 'blocks') {\n into.add(field.name)\n }\n const nested = getNestedFlattenedFields(field)\n if (nested) {\n collectArrayLikeNames(nested, into)\n }\n }\n}\n\n/**\n * Drops numeric array-index segments from a flat key so a runtime key like\n * `items_0_note` matches the static, index-free key a user hook is registered\n * under. A digit-only segment is only stripped when the segment immediately\n * before it names an array or blocks field, so a literal field name like\n * `2024` is preserved.\n */\nconst toLogicalKey = (flatKey: string, arrayLikeNames: Set<string>): string => {\n const segments = flatKey.split('_')\n return segments\n .filter((seg, i) => !indexSegment.test(seg) || !arrayLikeNames.has(segments[i - 1] ?? ''))\n .join('_')\n}\n\n/**\n * Converts flattened CSV data back into a nested document structure.\n *\n * The algorithm:\n * 1. Sorts keys to ensure array indices are processed in order\n * 2. For each flattened key (e.g., \"blocks_0_hero_title\"), splits by underscore into path segments\n * 3. Traverses/builds the nested structure, handling:\n * - Arrays (numeric segments like \"0\", \"1\")\n * - Blocks (blockType detection from slug patterns)\n * - Polymorphic relationships (_relationTo and _id suffix pairs)\n * - Regular nested objects\n * 4. Post-processes to handle localized fields, hasMany conversions, and relationship transforms\n */\nexport const unflattenObject = ({\n data,\n fields,\n format = 'csv',\n importFieldHooks = {},\n req,\n}: UnflattenArgs): Record<string, unknown> => {\n if (!data || typeof data !== 'object') {\n return {}\n }\n\n const result: Record<string, unknown> = {}\n\n const arrayLikeNames = new Set<string>()\n collectArrayLikeNames(fields, arrayLikeNames)\n\n // Sort keys to ensure array indices are processed in order\n const sortedKeys = Object.keys(data).sort((a, b) => {\n // Extract array indices from flattened keys (e.g., \"field_0_subfield\" -> \"0\")\n const aMatch = a.match(/_(\\d+)(?:_|$)/)\n const bMatch = b.match(/_(\\d+)(?:_|$)/)\n\n if (aMatch && bMatch && aMatch.index !== undefined && bMatch.index !== undefined) {\n const aBase = a.substring(0, aMatch.index)\n const bBase = b.substring(0, bMatch.index)\n\n if (aBase === bBase) {\n return (parseInt(aMatch?.[1] ?? '0', 10) || 0) - (parseInt(bMatch?.[1] ?? '0', 10) || 0)\n }\n }\n\n return a.localeCompare(b)\n })\n\n for (const flatKey of sortedKeys) {\n let value = data[flatKey]\n\n // Skip undefined values but keep null for required field validation\n if (value === undefined) {\n continue\n }\n\n // Preserve system fields with underscore prefix (like _status) without splitting\n if (flatKey === '_status') {\n result[flatKey] = value\n continue\n }\n\n // Check if this is a _relationTo key for a polymorphic relationship\n if (flatKey.endsWith('_relationTo')) {\n const baseKey = flatKey.replace(/_relationTo$/, '')\n const idKey = `${baseKey}_id`\n\n // Check if this is a polymorphic relationship field\n const isPolymorphic = fields.some(\n (field) =>\n field.name === baseKey &&\n field.type === 'relationship' &&\n 'relationTo' in field &&\n Array.isArray(field.relationTo),\n )\n\n if (isPolymorphic) {\n if (baseKey in result) {\n continue\n }\n\n // If the corresponding _id key is undefined, skip processing entirely\n // This prevents creating empty objects when we should preserve existing data\n if (!(idKey in data) || data[idKey] === undefined) {\n continue\n }\n }\n }\n\n // Check if this is a _id key for a polymorphic relationship where _relationTo is undefined\n if (flatKey.endsWith('_id')) {\n const baseKey = flatKey.replace(/_id$/, '')\n const relationToKey = `${baseKey}_relationTo`\n\n // Check if this is a polymorphic relationship field\n const isPolymorphic = fields.some(\n (field) =>\n field.name === baseKey &&\n field.type === 'relationship' &&\n 'relationTo' in field &&\n Array.isArray(field.relationTo),\n )\n\n if (isPolymorphic) {\n // If the corresponding _relationTo key is undefined, skip processing entirely\n // This prevents creating empty objects when we should preserve existing data\n if (!(relationToKey in data) || data[relationToKey] === undefined) {\n continue\n }\n }\n }\n\n const importHookEntry =\n importFieldHooks[flatKey] ?? importFieldHooks[toLogicalKey(flatKey, arrayLikeNames)]\n if (importHookEntry) {\n try {\n value = importHookEntry.fn({\n columnName: flatKey,\n data,\n format,\n siblingData: data,\n siblingDoc: data,\n value,\n })\n } catch (error) {\n req.payload.logger.error({\n err: error,\n msg: `[plugin-import-export] Field-level beforeImport hook for \"${flatKey}\" threw — falling back to original value`,\n })\n // Keep the original value so the row is not dropped — downstream\n // validation will surface any deeper issue per-row.\n }\n }\n\n // Example: \"blocks_0_content_text\" -> [\"blocks\", \"0\", \"content\", \"text\"]\n const pathSegments = flatKey.split('_')\n let currentObject: Record<string, unknown> = result\n\n for (let i = 0; i < pathSegments.length; i++) {\n const segment = pathSegments[i]\n if (!segment) {\n continue\n } // Skip empty segments\n\n const nextSegment = pathSegments[i + 1]\n const isLast = i === pathSegments.length - 1\n\n // Check if next segment is a numeric array index (e.g., \"0\", \"1\", \"2\")\n const isArrayIndex = nextSegment !== undefined && /^\\d+$/.test(nextSegment)\n\n if (isLast) {\n // Special handling for blockType suffix in blocks\n if (segment === 'blockType' && i >= 3) {\n // Pattern: blocks_0_hero_blockType -> set blockType on the block\n const blockFieldName = pathSegments[0] // 'blocks'\n const isBlockField = fields.some(\n (field) => field.name === blockFieldName && field.type === 'blocks',\n )\n\n if (isBlockField && pathSegments[1]?.match(/^\\d+$/)) {\n const parent = getParentObject(result, pathSegments.slice(0, 2))\n if (parent && typeof parent === 'object') {\n parent.blockType = value\n }\n continue\n }\n }\n\n // Special handling for relationship fields with _id suffix\n if (segment === 'id' && i > 0) {\n const parentKey = pathSegments[i - 1]\n const isPreviousSegmentArrayIndex = parentKey ? /^\\d+$/.test(parentKey) : false\n\n if (!isPreviousSegmentArrayIndex) {\n // Check if this is a relationship field\n const isRelationship = fields.some(\n (field) => field.name === parentKey && field.type === 'relationship',\n )\n\n if (isRelationship) {\n // Check if this is a polymorphic relationship field\n const field = fields.find((f) => f.name === parentKey && f.type === 'relationship')\n const isPolymorphic =\n field && 'relationTo' in field && Array.isArray(field.relationTo)\n\n if (isPolymorphic) {\n const relationToKey = pathSegments.slice(0, i).concat('relationTo').join('_')\n const relationToValue = data[relationToKey]\n\n const parent = getParentObject(result, pathSegments.slice(0, i - 1))\n if (parent && parentKey && typeof parent === 'object') {\n // Both fields must be defined to create/update the relationship\n // If either is undefined, skip the field entirely (preserve existing data)\n if (value !== undefined && relationToValue !== undefined) {\n // Check if both are explicitly null\n if (relationToValue === null && value === null) {\n // Only set to null if explicitly null (user typed \"null\" in CSV)\n parent[parentKey] = null\n } else if (relationToValue || value) {\n // At least one has a value, create the relationship\n parent[parentKey] = {\n relationTo: relationToValue,\n value, // This will be transformed to proper format in postProcess\n }\n }\n // If both are empty strings, don't set the field (handled by not meeting the above conditions)\n }\n // If either is undefined, don't set the field at all (preserve existing data)\n }\n continue\n } else if (!isPolymorphic) {\n const parent = getParentObject(result, pathSegments.slice(0, i - 1))\n if (parent && parentKey && typeof parent === 'object') {\n parent[parentKey] = value\n }\n continue\n }\n }\n }\n }\n\n // _relationTo suffix is handled when processing the _id field above\n if (segment === 'relationTo' && i > 0) {\n const parentKey = pathSegments[i - 1]\n if (parentKey && !parentKey.match(/^\\d+$/)) {\n const field = fields.find((f) => f.name === parentKey && f.type === 'relationship')\n const isPolymorphic = field && 'relationTo' in field && Array.isArray(field.relationTo)\n\n if (isPolymorphic) {\n // For polymorphic relationships, this is handled when processing the _id field\n // Skip it entirely\n continue\n }\n }\n }\n\n currentObject[segment] = value\n } else if (isArrayIndex && nextSegment !== undefined) {\n if (!currentObject[segment] || !Array.isArray(currentObject[segment])) {\n currentObject[segment] = []\n }\n\n const arrayIndex = parseInt(nextSegment)\n const arr = currentObject[segment] as unknown[]\n\n // Ensure array has sufficient length\n while (arr.length <= arrayIndex) {\n arr.push(null)\n }\n\n // Handle array of objects\n if (arr[arrayIndex] === null || arr[arrayIndex] === undefined) {\n arr[arrayIndex] = {}\n }\n\n // Handle blocks field with block slug pattern (e.g., blocks_0_hero_title)\n const isBlocksField = fields.some((f) => f.name === segment && f.type === 'blocks')\n if (isBlocksField && i + 3 < pathSegments.length) {\n const blockSlug = pathSegments[i + 2]\n const blockFieldName = pathSegments[i + 3]\n\n if (blockSlug && blockFieldName) {\n const blockObject = arr[arrayIndex] as Record<string, unknown>\n blockObject.blockType = blockSlug\n\n if (i + 3 === pathSegments.length - 1) {\n blockObject[blockFieldName] = value\n } else {\n if (!blockObject[blockFieldName] || typeof blockObject[blockFieldName] !== 'object') {\n blockObject[blockFieldName] = {}\n }\n currentObject = blockObject[blockFieldName] as Record<string, unknown>\n i = i + 3\n continue\n }\n break\n }\n }\n\n if (i + 2 === pathSegments.length - 1) {\n const lastSegment = pathSegments[pathSegments.length - 1]\n if (lastSegment && arr[arrayIndex] && typeof arr[arrayIndex] === 'object') {\n ;(arr[arrayIndex] as Record<string, unknown>)[lastSegment] = value\n }\n break\n } else if (i + 1 === pathSegments.length - 1) {\n // Direct array value (e.g., tags_0 = \"value\")\n arr[arrayIndex] = value\n break\n } else {\n currentObject = arr[arrayIndex] as Record<string, unknown>\n i++\n }\n } else {\n // Skip if already set to null (polymorphic relationship already processed)\n if (currentObject[segment] === null && isLast && segment === 'relationTo') {\n continue\n }\n\n if (\n !currentObject[segment] ||\n typeof currentObject[segment] !== 'object' ||\n Array.isArray(currentObject[segment])\n ) {\n currentObject[segment] = {}\n }\n\n // Handle polymorphic relationship arrays\n if (segment === 'relationTo' && i > 0 && pathSegments[i - 1]?.match(/^\\d+$/)) {\n currentObject[segment] = value\n } else if (\n typeof currentObject[segment] === 'object' &&\n !Array.isArray(currentObject[segment]) &&\n currentObject[segment] !== null\n ) {\n currentObject = currentObject[segment] as Record<string, unknown>\n }\n }\n }\n }\n\n try {\n // Post-process to handle special structures\n postProcessDocument(result, fields)\n } catch (err) {\n // Log but don't throw - return partially processed result\n\n req.payload.logger.error({\n err,\n msg: '[plugin-import-export] Error in postProcessDocument',\n })\n }\n\n return result\n}\n\nconst getParentObject = (\n obj: Record<string, unknown>,\n segments: string[],\n): Record<string, unknown> | undefined => {\n let current: Record<string, unknown> = obj\n\n for (let i = 0; i < segments.length; i++) {\n const segment = segments[i]\n const nextSegment = segments[i + 1]\n\n if (!segment) {\n continue\n }\n\n if (nextSegment && /^\\d+$/.test(nextSegment)) {\n const arrayIndex = parseInt(nextSegment)\n const arr = current[segment] as unknown[]\n\n if (Array.isArray(arr) && arr[arrayIndex]) {\n current = arr[arrayIndex] as Record<string, unknown>\n i++ // Skip the index\n } else {\n return undefined\n }\n } else {\n const next = current[segment]\n if (typeof next === 'object' && next !== null && !Array.isArray(next)) {\n current = next as Record<string, unknown>\n } else {\n return undefined\n }\n }\n }\n\n return current\n}\n"],"names":["getNestedFlattenedFields","postProcessDocument","indexSegment","collectArrayLikeNames","fields","into","field","name","type","add","nested","toLogicalKey","flatKey","arrayLikeNames","segments","split","filter","seg","i","test","has","join","unflattenObject","data","format","importFieldHooks","req","result","Set","sortedKeys","Object","keys","sort","a","b","aMatch","match","bMatch","index","undefined","aBase","substring","bBase","parseInt","localeCompare","value","endsWith","baseKey","replace","idKey","isPolymorphic","some","Array","isArray","relationTo","relationToKey","importHookEntry","fn","columnName","siblingData","siblingDoc","error","payload","logger","err","msg","pathSegments","currentObject","length","segment","nextSegment","isLast","isArrayIndex","blockFieldName","isBlockField","parent","getParentObject","slice","blockType","parentKey","isPreviousSegmentArrayIndex","isRelationship","find","f","concat","relationToValue","arrayIndex","arr","push","isBlocksField","blockSlug","blockObject","lastSegment","obj","current","next"],"mappings":"AAIA,SAASA,wBAAwB,QAAQ,uBAAsB;AAC/D,SAASC,mBAAmB,QAAQ,4BAA2B;AAU/D,MAAMC,eAAe;AAErB,MAAMC,wBAAwB,CAACC,QAA0BC;IACvD,KAAK,MAAMC,SAASF,OAAQ;QAC1B,IAAI,CAAE,CAAA,UAAUE,KAAI,KAAM,CAACA,MAAMC,IAAI,EAAE;YACrC;QACF;QACA,IAAID,MAAME,IAAI,KAAK,WAAWF,MAAME,IAAI,KAAK,UAAU;YACrDH,KAAKI,GAAG,CAACH,MAAMC,IAAI;QACrB;QACA,MAAMG,SAASV,yBAAyBM;QACxC,IAAII,QAAQ;YACVP,sBAAsBO,QAAQL;QAChC;IACF;AACF;AAEA;;;;;;CAMC,GACD,MAAMM,eAAe,CAACC,SAAiBC;IACrC,MAAMC,WAAWF,QAAQG,KAAK,CAAC;IAC/B,OAAOD,SACJE,MAAM,CAAC,CAACC,KAAKC,IAAM,CAAChB,aAAaiB,IAAI,CAACF,QAAQ,CAACJ,eAAeO,GAAG,CAACN,QAAQ,CAACI,IAAI,EAAE,IAAI,KACrFG,IAAI,CAAC;AACV;AAEA;;;;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IACF;IAEA,OAAOuD;AACT"}
1
+ {"version":3,"sources":["../../src/utilities/unflattenObject.ts"],"sourcesContent":["import type { FlattenedField, PayloadRequest } from 'payload'\n\nimport type { ImportFieldHookEntry } from '../types.js'\n\nimport { getBlockFlattenedFields, getNestedFlattenedFields } from './flattenedFields.js'\nimport { postProcessDocument } from './unflattenPostProcess.js'\n\ntype UnflattenArgs = {\n data: Record<string, unknown>\n fields: FlattenedField[]\n format?: 'csv' | 'json' | ({} & string)\n importFieldHooks?: Record<string, ImportFieldHookEntry>\n req: PayloadRequest\n}\n\nconst indexSegment = /^\\d+$/\n\nconst collectArrayLikeNames = (fields: FlattenedField[], into: Set<string>): void => {\n for (const field of fields) {\n if (!('name' in field) || !field.name) {\n continue\n }\n if (field.type === 'array' || field.type === 'blocks') {\n into.add(field.name)\n }\n if (field.type === 'blocks') {\n for (const block of (field as { blocks?: Array<{ flattenedFields?: FlattenedField[] }> })\n .blocks ?? []) {\n collectArrayLikeNames(getBlockFlattenedFields(block), into)\n }\n }\n const nested = getNestedFlattenedFields(field)\n if (nested) {\n collectArrayLikeNames(nested, into)\n }\n }\n}\n\n/**\n * Drops numeric array-index segments from a flat key so a runtime key like\n * `items_0_note` matches the static, index-free key a user hook is registered\n * under. A digit-only segment is only stripped when the segment immediately\n * before it names an array or blocks field, so a literal field name like\n * `2024` is preserved.\n */\nconst toLogicalKey = (flatKey: string, arrayLikeNames: Set<string>): string => {\n const segments = flatKey.split('_')\n return segments\n .filter((seg, i) => !indexSegment.test(seg) || !arrayLikeNames.has(segments[i - 1] ?? ''))\n .join('_')\n}\n\n/**\n * Converts flattened CSV data back into a nested document structure.\n *\n * The algorithm:\n * 1. Sorts keys to ensure array indices are processed in order\n * 2. For each flattened key (e.g., \"blocks_0_hero_title\"), splits by underscore into path segments\n * 3. Traverses/builds the nested structure, handling:\n * - Arrays (numeric segments like \"0\", \"1\")\n * - Blocks (blockType detection from slug patterns)\n * - Polymorphic relationships (_relationTo and _id suffix pairs)\n * - Regular nested objects\n * 4. Post-processes to handle localized fields, hasMany conversions, and relationship transforms\n */\nexport const unflattenObject = ({\n data,\n fields,\n format = 'csv',\n importFieldHooks = {},\n req,\n}: UnflattenArgs): Record<string, unknown> => {\n if (!data || typeof data !== 'object') {\n return {}\n }\n\n const result: Record<string, unknown> = {}\n\n const arrayLikeNames = new Set<string>()\n collectArrayLikeNames(fields, arrayLikeNames)\n\n // Sort keys to ensure array indices are processed in order\n const sortedKeys = Object.keys(data).sort((a, b) => {\n // Extract array indices from flattened keys (e.g., \"field_0_subfield\" -> \"0\")\n const aMatch = a.match(/_(\\d+)(?:_|$)/)\n const bMatch = b.match(/_(\\d+)(?:_|$)/)\n\n if (aMatch && bMatch && aMatch.index !== undefined && bMatch.index !== undefined) {\n const aBase = a.substring(0, aMatch.index)\n const bBase = b.substring(0, bMatch.index)\n\n if (aBase === bBase) {\n return (parseInt(aMatch?.[1] ?? '0', 10) || 0) - (parseInt(bMatch?.[1] ?? '0', 10) || 0)\n }\n }\n\n return a.localeCompare(b)\n })\n\n for (const flatKey of sortedKeys) {\n let value = data[flatKey]\n\n // Skip undefined values but keep null for required field validation\n if (value === undefined) {\n continue\n }\n\n // Preserve system fields with underscore prefix (like _status) without splitting\n if (flatKey === '_status') {\n result[flatKey] = value\n continue\n }\n\n // Check if this is a _relationTo key for a polymorphic relationship\n if (flatKey.endsWith('_relationTo')) {\n const baseKey = flatKey.replace(/_relationTo$/, '')\n const idKey = `${baseKey}_id`\n\n // Check if this is a polymorphic relationship field\n const isPolymorphic = fields.some(\n (field) =>\n field.name === baseKey &&\n field.type === 'relationship' &&\n 'relationTo' in field &&\n Array.isArray(field.relationTo),\n )\n\n if (isPolymorphic) {\n if (baseKey in result) {\n continue\n }\n\n // If the corresponding _id key is undefined, skip processing entirely\n // This prevents creating empty objects when we should preserve existing data\n if (!(idKey in data) || data[idKey] === undefined) {\n continue\n }\n }\n }\n\n // Check if this is a _id key for a polymorphic relationship where _relationTo is undefined\n if (flatKey.endsWith('_id')) {\n const baseKey = flatKey.replace(/_id$/, '')\n const relationToKey = `${baseKey}_relationTo`\n\n // Check if this is a polymorphic relationship field\n const isPolymorphic = fields.some(\n (field) =>\n field.name === baseKey &&\n field.type === 'relationship' &&\n 'relationTo' in field &&\n Array.isArray(field.relationTo),\n )\n\n if (isPolymorphic) {\n // If the corresponding _relationTo key is undefined, skip processing entirely\n // This prevents creating empty objects when we should preserve existing data\n if (!(relationToKey in data) || data[relationToKey] === undefined) {\n continue\n }\n }\n }\n\n const importHookEntry =\n importFieldHooks[flatKey] ?? importFieldHooks[toLogicalKey(flatKey, arrayLikeNames)]\n if (importHookEntry) {\n try {\n value = importHookEntry.fn({\n columnName: flatKey,\n data,\n format,\n siblingData: data,\n siblingDoc: data,\n value,\n })\n } catch (error) {\n req.payload.logger.error({\n err: error,\n msg: `[plugin-import-export] Field-level beforeImport hook for \"${flatKey}\" threw — falling back to original value`,\n })\n // Keep the original value so the row is not dropped — downstream\n // validation will surface any deeper issue per-row.\n }\n }\n\n // Example: \"blocks_0_content_text\" -> [\"blocks\", \"0\", \"content\", \"text\"]\n const pathSegments = flatKey.split('_')\n let currentObject: Record<string, unknown> = result\n\n for (let i = 0; i < pathSegments.length; i++) {\n const segment = pathSegments[i]\n if (!segment) {\n continue\n } // Skip empty segments\n\n const nextSegment = pathSegments[i + 1]\n const isLast = i === pathSegments.length - 1\n\n // Check if next segment is a numeric array index (e.g., \"0\", \"1\", \"2\")\n const isArrayIndex = nextSegment !== undefined && /^\\d+$/.test(nextSegment)\n\n if (isLast) {\n // Special handling for blockType suffix in blocks\n if (segment === 'blockType' && i >= 3) {\n // Pattern: blocks_0_hero_blockType -> set blockType on the block\n const blockFieldName = pathSegments[0] // 'blocks'\n const isBlockField = fields.some(\n (field) => field.name === blockFieldName && field.type === 'blocks',\n )\n\n if (isBlockField && pathSegments[1]?.match(/^\\d+$/)) {\n const parent = getParentObject(result, pathSegments.slice(0, 2))\n if (parent && typeof parent === 'object') {\n parent.blockType = value\n }\n continue\n }\n }\n\n // Special handling for relationship fields with _id suffix\n if (segment === 'id' && i > 0) {\n const parentKey = pathSegments[i - 1]\n const isPreviousSegmentArrayIndex = parentKey ? /^\\d+$/.test(parentKey) : false\n\n if (!isPreviousSegmentArrayIndex) {\n // Check if this is a relationship field\n const isRelationship = fields.some(\n (field) => field.name === parentKey && field.type === 'relationship',\n )\n\n if (isRelationship) {\n // Check if this is a polymorphic relationship field\n const field = fields.find((f) => f.name === parentKey && f.type === 'relationship')\n const isPolymorphic =\n field && 'relationTo' in field && Array.isArray(field.relationTo)\n\n if (isPolymorphic) {\n const relationToKey = pathSegments.slice(0, i).concat('relationTo').join('_')\n const relationToValue = data[relationToKey]\n\n const parent = getParentObject(result, pathSegments.slice(0, i - 1))\n if (parent && parentKey && typeof parent === 'object') {\n // Both fields must be defined to create/update the relationship\n // If either is undefined, skip the field entirely (preserve existing data)\n if (value !== undefined && relationToValue !== undefined) {\n // Check if both are explicitly null\n if (relationToValue === null && value === null) {\n // Only set to null if explicitly null (user typed \"null\" in CSV)\n parent[parentKey] = null\n } else if (relationToValue || value) {\n // At least one has a value, create the relationship\n parent[parentKey] = {\n relationTo: relationToValue,\n value, // This will be transformed to proper format in postProcess\n }\n }\n // If both are empty strings, don't set the field (handled by not meeting the above conditions)\n }\n // If either is undefined, don't set the field at all (preserve existing data)\n }\n continue\n } else if (!isPolymorphic) {\n const parent = getParentObject(result, pathSegments.slice(0, i - 1))\n if (parent && parentKey && typeof parent === 'object') {\n parent[parentKey] = value\n }\n continue\n }\n }\n }\n }\n\n // _relationTo suffix is handled when processing the _id field above\n if (segment === 'relationTo' && i > 0) {\n const parentKey = pathSegments[i - 1]\n if (parentKey && !parentKey.match(/^\\d+$/)) {\n const field = fields.find((f) => f.name === parentKey && f.type === 'relationship')\n const isPolymorphic = field && 'relationTo' in field && Array.isArray(field.relationTo)\n\n if (isPolymorphic) {\n // For polymorphic relationships, this is handled when processing the _id field\n // Skip it entirely\n continue\n }\n }\n }\n\n currentObject[segment] = value\n } else if (isArrayIndex && nextSegment !== undefined) {\n if (!currentObject[segment] || !Array.isArray(currentObject[segment])) {\n currentObject[segment] = []\n }\n\n const arrayIndex = parseInt(nextSegment)\n const arr = currentObject[segment] as unknown[]\n\n // Ensure array has sufficient length\n while (arr.length <= arrayIndex) {\n arr.push(null)\n }\n\n // Handle array of objects\n if (arr[arrayIndex] === null || arr[arrayIndex] === undefined) {\n arr[arrayIndex] = {}\n }\n\n // Handle blocks field with block slug pattern (e.g., blocks_0_hero_title)\n const isBlocksField = fields.some((f) => f.name === segment && f.type === 'blocks')\n if (isBlocksField && i + 3 < pathSegments.length) {\n const blockSlug = pathSegments[i + 2]\n const blockFieldName = pathSegments[i + 3]\n\n if (blockSlug && blockFieldName) {\n const blockObject = arr[arrayIndex] as Record<string, unknown>\n blockObject.blockType = blockSlug\n\n if (i + 3 === pathSegments.length - 1) {\n blockObject[blockFieldName] = value\n } else {\n if (!blockObject[blockFieldName] || typeof blockObject[blockFieldName] !== 'object') {\n const segmentAfterBlockField = pathSegments[i + 4]\n const blockFieldIsArray =\n segmentAfterBlockField !== undefined && indexSegment.test(segmentAfterBlockField)\n blockObject[blockFieldName] = blockFieldIsArray ? [] : {}\n }\n currentObject = blockObject[blockFieldName] as Record<string, unknown>\n i = i + 3\n continue\n }\n break\n }\n }\n\n if (i + 2 === pathSegments.length - 1) {\n const lastSegment = pathSegments[pathSegments.length - 1]\n if (lastSegment && arr[arrayIndex] && typeof arr[arrayIndex] === 'object') {\n ;(arr[arrayIndex] as Record<string, unknown>)[lastSegment] = value\n }\n break\n } else if (i + 1 === pathSegments.length - 1) {\n // Direct array value (e.g., tags_0 = \"value\")\n arr[arrayIndex] = value\n break\n } else {\n currentObject = arr[arrayIndex] as Record<string, unknown>\n i++\n }\n } else if (Array.isArray(currentObject) && indexSegment.test(segment)) {\n // currentObject is an array we arrived at via block field traversal — treat the\n // segment as a numeric index rather than a plain property name.\n const idx = parseInt(segment, 10)\n const arr = currentObject as unknown[]\n while (arr.length <= idx) {\n arr.push(null)\n }\n if (arr[idx] === null || arr[idx] === undefined) {\n arr[idx] = {}\n }\n currentObject = arr[idx] as Record<string, unknown>\n } else {\n // Skip if already set to null (polymorphic relationship already processed)\n if (currentObject[segment] === null && isLast && segment === 'relationTo') {\n continue\n }\n\n if (\n !currentObject[segment] ||\n typeof currentObject[segment] !== 'object' ||\n Array.isArray(currentObject[segment])\n ) {\n currentObject[segment] = {}\n }\n\n // Handle polymorphic relationship arrays\n if (segment === 'relationTo' && i > 0 && pathSegments[i - 1]?.match(/^\\d+$/)) {\n currentObject[segment] = value\n } else if (\n typeof currentObject[segment] === 'object' &&\n !Array.isArray(currentObject[segment]) &&\n currentObject[segment] !== null\n ) {\n currentObject = currentObject[segment] as Record<string, unknown>\n }\n }\n }\n }\n\n try {\n // Post-process to handle special structures\n postProcessDocument(result, fields)\n } catch (err) {\n // Log but don't throw - return partially processed result\n\n req.payload.logger.error({\n err,\n msg: '[plugin-import-export] Error in postProcessDocument',\n })\n }\n\n return result\n}\n\nconst getParentObject = (\n obj: Record<string, unknown>,\n segments: string[],\n): Record<string, unknown> | undefined => {\n let current: Record<string, unknown> = obj\n\n for (let i = 0; i < segments.length; i++) {\n const segment = segments[i]\n const nextSegment = segments[i + 1]\n\n if (!segment) {\n continue\n }\n\n if (nextSegment && /^\\d+$/.test(nextSegment)) {\n const arrayIndex = parseInt(nextSegment)\n const arr = current[segment] as unknown[]\n\n if (Array.isArray(arr) && arr[arrayIndex]) {\n current = arr[arrayIndex] as Record<string, unknown>\n i++ // Skip the index\n } else {\n return undefined\n }\n } else {\n const next = current[segment]\n if (typeof next === 'object' && next !== null && !Array.isArray(next)) {\n current = next as Record<string, unknown>\n } else {\n return undefined\n }\n }\n }\n\n return current\n}\n"],"names":["getBlockFlattenedFields","getNestedFlattenedFields","postProcessDocument","indexSegment","collectArrayLikeNames","fields","into","field","name","type","add","block","blocks","nested","toLogicalKey","flatKey","arrayLikeNames","segments","split","filter","seg","i","test","has","join","unflattenObject","data","format","importFieldHooks","req","result","Set","sortedKeys","Object","keys","sort","a","b","aMatch","match","bMatch","index","undefined","aBase","substring","bBase","parseInt","localeCompare","value","endsWith","baseKey","replace","idKey","isPolymorphic","some","Array","isArray","relationTo","relationToKey","importHookEntry","fn","columnName","siblingData","siblingDoc","error","payload","logger","err","msg","pathSegments","currentObject","length","segment","nextSegment","isLast","isArrayIndex","blockFieldName","isBlockField","parent","getParentObject","slice","blockType","parentKey","isPreviousSegmentArrayIndex","isRelationship","find","f","concat","relationToValue","arrayIndex","arr","push","isBlocksField","blockSlug","blockObject","segmentAfterBlockField","blockFieldIsArray","lastSegment","idx","obj","current","next"],"mappings":"AAIA,SAASA,uBAAuB,EAAEC,wBAAwB,QAAQ,uBAAsB;AACxF,SAASC,mBAAmB,QAAQ,4BAA2B;AAU/D,MAAMC,eAAe;AAErB,MAAMC,wBAAwB,CAACC,QAA0BC;IACvD,KAAK,MAAMC,SAASF,OAAQ;QAC1B,IAAI,CAAE,CAAA,UAAUE,KAAI,KAAM,CAACA,MAAMC,IAAI,EAAE;YACrC;QACF;QACA,IAAID,MAAME,IAAI,KAAK,WAAWF,MAAME,IAAI,KAAK,UAAU;YACrDH,KAAKI,GAAG,CAACH,MAAMC,IAAI;QACrB;QACA,IAAID,MAAME,IAAI,KAAK,UAAU;YAC3B,KAAK,MAAME,SAAS,AAACJ,MAClBK,MAAM,IAAI,EAAE,CAAE;gBACfR,sBAAsBJ,wBAAwBW,QAAQL;YACxD;QACF;QACA,MAAMO,SAASZ,yBAAyBM;QACxC,IAAIM,QAAQ;YACVT,sBAAsBS,QAAQP;QAChC;IACF;AACF;AAEA;;;;;;CAMC,GACD,MAAMQ,eAAe,CAACC,SAAiBC;IACrC,MAAMC,WAAWF,QAAQG,KAAK,CAAC;IAC/B,OAAOD,SACJE,MAAM,CAAC,CAACC,KAAKC,IAAM,CAAClB,aAAamB,IAAI,CAACF,QAAQ,CAACJ,eAAeO,GAAG,CAAC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AAM,EAAElD,IAAK;QACxC,MAAMmD,UAAUvD,QAAQ,CAACI,EAAE;QAC3B,MAAMoD,cAAcxD,QAAQ,CAACI,IAAI,EAAE;QAEnC,IAAI,CAACmD,SAAS;YACZ;QACF;QAEA,IAAIC,eAAe,QAAQnD,IAAI,CAACmD,cAAc;YAC5C,MAAMgB,aAAa3C,SAAS2B;YAC5B,MAAMiB,MAAMU,OAAO,CAAC5B,QAAQ;YAE5B,IAAIjB,MAAMC,OAAO,CAACkC,QAAQA,GAAG,CAACD,WAAW,EAAE;gBACzCW,UAAUV,GAAG,CAACD,WAAW;gBACzBpE,KAAI,iBAAiB;YACvB,OAAO;gBACL,OAAOqB;YACT;QACF,OAAO;YACL,MAAM2D,OAAOD,OAAO,CAAC5B,QAAQ;YAC7B,IAAI,OAAO6B,SAAS,YAAYA,SAAS,QAAQ,CAAC9C,MAAMC,OAAO,CAAC6C,OAAO;gBACrED,UAAUC;YACZ,OAAO;gBACL,OAAO3D;YACT;QACF;IACF;IAEA,OAAO0D;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"unflattenPostProcess.d.ts","sourceRoot":"","sources":["../../src/utilities/unflattenPostProcess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAuK7C;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,GAC9B,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,QAAQ,cAAc,EAAE,KACvB,IAMF,CAAA"}
1
+ {"version":3,"file":"unflattenPostProcess.d.ts","sourceRoot":"","sources":["../../src/utilities/unflattenPostProcess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAuM7C;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,QACzB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,UACpB,cAAc,EAAE,KACvB,IAMF,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { getBlockFlattenedFields, getNestedFlattenedFields } from './flattenedFields.js';
1
2
  import { isPlainObject } from './isPlainObject.js';
2
3
  import { processRichTextField } from './processRichTextField.js';
3
4
  const normalizeLocalizedFields = (doc, fields)=>{
@@ -107,29 +108,54 @@ const normalizePolymorphicRelationships = (doc, fields)=>{
107
108
  }
108
109
  }
109
110
  };
110
- const normalizeRichText = (doc, fields)=>{
111
- for (const field of fields.filter((f)=>f.type === 'richText')){
112
- if (field.name in doc && doc[field.name]) {
113
- doc[field.name] = processRichTextField(doc[field.name]);
111
+ const normalizeRichTextInFields = (doc, fields)=>{
112
+ for (const field of fields){
113
+ if (!('name' in field) || !field.name || !(field.name in doc)) {
114
+ continue;
114
115
  }
115
- }
116
- for (const field of fields.filter((f)=>f.type === 'blocks')){
117
- const blocks = doc[field.name];
118
- if (!Array.isArray(blocks)) {
116
+ const value = doc[field.name];
117
+ if (value === null || value === undefined) {
119
118
  continue;
120
119
  }
121
- for (const block of blocks){
122
- if (!isPlainObject(block)) {
120
+ if (field.type === 'richText') {
121
+ doc[field.name] = processRichTextField(value);
122
+ } else if (field.type === 'blocks') {
123
+ if (!Array.isArray(value)) {
124
+ continue;
125
+ }
126
+ const blockDefs = field.blocks ?? [];
127
+ for (const blockItem of value){
128
+ if (!isPlainObject(blockItem)) {
129
+ continue;
130
+ }
131
+ const blockDef = blockDefs.find((b)=>b.slug === blockItem.blockType);
132
+ if (blockDef) {
133
+ normalizeRichTextInFields(blockItem, getBlockFlattenedFields(blockDef));
134
+ }
135
+ }
136
+ } else if (field.type === 'array') {
137
+ if (!Array.isArray(value)) {
123
138
  continue;
124
139
  }
125
- for (const [key, value] of Object.entries(block)){
126
- if (key === 'richText' || typeof key === 'string' && key.includes('richText')) {
127
- block[key] = processRichTextField(value);
140
+ const nestedFields = getNestedFlattenedFields(field) ?? [];
141
+ for (const item of value){
142
+ if (!isPlainObject(item)) {
143
+ continue;
128
144
  }
145
+ normalizeRichTextInFields(item, nestedFields);
129
146
  }
147
+ } else if (field.type === 'group' || field.type === 'tab') {
148
+ if (!isPlainObject(value)) {
149
+ continue;
150
+ }
151
+ const nestedFields = getNestedFlattenedFields(field) ?? [];
152
+ normalizeRichTextInFields(value, nestedFields);
130
153
  }
131
154
  }
132
155
  };
156
+ const normalizeRichText = (doc, fields)=>{
157
+ normalizeRichTextInFields(doc, fields);
158
+ };
133
159
  /**
134
160
  * Post-processes the unflattened document to handle special field types:
135
161
  * - Localized fields: transforms field_locale keys to nested { field: { locale: value } }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/unflattenPostProcess.ts"],"sourcesContent":["import type { FlattenedField } from 'payload'\n\nimport { isPlainObject } from './isPlainObject.js'\nimport { processRichTextField } from './processRichTextField.js'\n\nconst normalizeLocalizedFields = (doc: Record<string, unknown>, fields: FlattenedField[]): void => {\n const processed = new Set<string>()\n\n for (const field of fields.filter((f) => f.localized)) {\n if (processed.has(field.name)) {\n continue\n }\n\n const localePattern = new RegExp(`^${field.name}_([a-z]{2}(?:_[A-Z]{2})?)$`)\n const localeData: Record<string, unknown> = {}\n const keysToDelete: string[] = []\n\n for (const [key, value] of Object.entries(doc)) {\n const match = key.match(localePattern)\n if (match && match[1]) {\n localeData[match[1]] = value\n keysToDelete.push(key)\n }\n }\n\n if (Object.keys(localeData).length > 0) {\n doc[field.name] = localeData\n keysToDelete.forEach((key) => delete doc[key])\n processed.add(field.name)\n }\n }\n}\n\nconst normalizeHasManyNumbers = (doc: Record<string, unknown>, fields: FlattenedField[]): void => {\n const numberFields = fields.filter((field) => field.type === 'number' && field.hasMany)\n for (const field of numberFields) {\n if (!(field.name in doc)) {\n continue\n }\n const value = doc[field.name]\n\n if (typeof value === 'string' && value.includes(',')) {\n doc[field.name] = value\n .split(',')\n .map((v) => v.trim())\n .filter((v) => v !== '')\n .map((v) => {\n const num = parseFloat(v)\n return isNaN(num) ? 0 : num\n })\n } else if (Array.isArray(value)) {\n doc[field.name] = value\n .filter((v) => v !== null && v !== undefined && v !== '')\n .map((v) => {\n if (typeof v === 'string') {\n const num = parseFloat(v)\n return isNaN(num) ? 0 : num\n }\n return v\n })\n } else if (value !== null && value !== undefined && value !== '') {\n const num = typeof value === 'string' ? parseFloat(value) : value\n doc[field.name] = isNaN(num as number) ? [] : [num]\n } else {\n doc[field.name] = []\n }\n }\n}\n\nconst normalizeHasManyRelationships = (\n doc: Record<string, unknown>,\n fields: FlattenedField[],\n): void => {\n const relationshipFields = fields.filter(\n (field) =>\n (field.type === 'relationship' || field.type === 'upload') &&\n field.hasMany === true &&\n !Array.isArray(field.relationTo),\n )\n\n for (const field of relationshipFields) {\n const value = doc[field.name]\n\n if (typeof value === 'string' && value.includes(',')) {\n doc[field.name] = value\n .split(',')\n .map((v) => v.trim())\n .filter((v) => v !== '')\n } else if (Array.isArray(value)) {\n doc[field.name] = value.filter((v) => v !== null && v !== undefined && v !== '')\n } else if (value !== null && value !== undefined && value !== '') {\n doc[field.name] = [value]\n }\n }\n}\n\nconst normalizePolymorphicRelationships = (\n doc: Record<string, unknown>,\n fields: FlattenedField[],\n): void => {\n for (const [key, value] of Object.entries(doc)) {\n if (Array.isArray(value)) {\n const hasPolymorphicItems = value.some((item) => isPlainObject(item) && 'relationTo' in item)\n\n if (!hasPolymorphicItems) {\n continue\n }\n\n const processedArray: unknown[] = []\n for (const item of value) {\n if (isPlainObject(item) && 'relationTo' in item) {\n if (!item.relationTo || (!item.id && !item.value)) {\n continue\n }\n if ('id' in item) {\n item.value = item.id\n delete item.id\n }\n processedArray.push(item)\n } else if (item !== null && item !== undefined) {\n processedArray.push(item)\n }\n }\n\n if (value.length !== processedArray.length) {\n doc[key] = processedArray.length > 0 ? processedArray : []\n }\n } else if (isPlainObject(value)) {\n if ('relationTo' in value && ('id' in value || 'value' in value)) {\n if (!value.relationTo || (!value.id && !value.value)) {\n doc[key] = null\n } else if ('id' in value && !('value' in value)) {\n value.value = value.id\n delete value.id\n }\n } else {\n normalizePolymorphicRelationships(value, fields)\n }\n }\n }\n}\n\nconst normalizeRichText = (doc: Record<string, unknown>, fields: FlattenedField[]): void => {\n for (const field of fields.filter((f) => f.type === 'richText')) {\n if (field.name in doc && doc[field.name]) {\n doc[field.name] = processRichTextField(doc[field.name])\n }\n }\n\n for (const field of fields.filter((f) => f.type === 'blocks')) {\n const blocks = doc[field.name]\n if (!Array.isArray(blocks)) {\n continue\n }\n for (const block of blocks) {\n if (!isPlainObject(block)) {\n continue\n }\n for (const [key, value] of Object.entries(block)) {\n if (key === 'richText' || (typeof key === 'string' && key.includes('richText'))) {\n block[key] = processRichTextField(value)\n }\n }\n }\n }\n}\n\n/**\n * Post-processes the unflattened document to handle special field types:\n * - Localized fields: transforms field_locale keys to nested { field: { locale: value } }\n * - Number hasMany: converts comma-separated strings or arrays to number arrays\n * - Relationship hasMany: converts comma-separated IDs to arrays\n * - Polymorphic relationships: transforms flat {relationTo, id} to {relationTo, value}\n * - Rich text fields: ensures proper data structure\n */\nexport const postProcessDocument = (\n doc: Record<string, unknown>,\n fields: FlattenedField[],\n): void => {\n normalizeLocalizedFields(doc, fields)\n normalizeHasManyNumbers(doc, fields)\n normalizeHasManyRelationships(doc, fields)\n normalizePolymorphicRelationships(doc, fields)\n normalizeRichText(doc, fields)\n}\n"],"names":["isPlainObject","processRichTextField","normalizeLocalizedFields","doc","fields","processed","Set","field","filter","f","localized","has","name","localePattern","RegExp","localeData","keysToDelete","key","value","Object","entries","match","push","keys","length","forEach","add","normalizeHasManyNumbers","numberFields","type","hasMany","includes","split","map","v","trim","num","parseFloat","isNaN","Array","isArray","undefined","normalizeHasManyRelationships","relationshipFields","relationTo","normalizePolymorphicRelationships","hasPolymorphicItems","some","item","processedArray","id","normalizeRichText","blocks","block","postProcessDocument"],"mappings":"AAEA,SAASA,aAAa,QAAQ,qBAAoB;AAClD,SAASC,oBAAoB,QAAQ,4BAA2B;AAEhE,MAAMC,2BAA2B,CAACC,KAA8BC;IAC9D,MAAMC,YAAY,IAAIC;IAEtB,KAAK,MAAMC,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;IAEAF,yBAAyBC,KAAKC;IAC9BuB,wBAAwBxB,KAAKC;IAC7BsC,8BAA8BvC,KAAKC;IACnCyC,kCAAkC1C,KAAKC;IACvC+C,kBAAkBhD,KAAKC;AACzB,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/unflattenPostProcess.ts"],"sourcesContent":["import type { FlattenedField } from 'payload'\n\nimport { getBlockFlattenedFields, getNestedFlattenedFields } from './flattenedFields.js'\nimport { isPlainObject } from './isPlainObject.js'\nimport { processRichTextField } from './processRichTextField.js'\n\nconst normalizeLocalizedFields = (doc: Record<string, unknown>, fields: FlattenedField[]): void => {\n const processed = new Set<string>()\n\n for (const field of fields.filter((f) => f.localized)) {\n if (processed.has(field.name)) {\n continue\n }\n\n const localePattern = new RegExp(`^${field.name}_([a-z]{2}(?:_[A-Z]{2})?)$`)\n const localeData: Record<string, unknown> = {}\n const keysToDelete: string[] = []\n\n for (const [key, value] of Object.entries(doc)) {\n const match = key.match(localePattern)\n if (match && match[1]) {\n localeData[match[1]] = value\n keysToDelete.push(key)\n }\n }\n\n if (Object.keys(localeData).length > 0) {\n doc[field.name] = localeData\n keysToDelete.forEach((key) => delete doc[key])\n processed.add(field.name)\n }\n }\n}\n\nconst normalizeHasManyNumbers = (doc: Record<string, unknown>, fields: FlattenedField[]): void => {\n const numberFields = fields.filter((field) => field.type === 'number' && field.hasMany)\n for (const field of numberFields) {\n if (!(field.name in doc)) {\n continue\n }\n const value = doc[field.name]\n\n if (typeof value === 'string' && value.includes(',')) {\n doc[field.name] = value\n .split(',')\n .map((v) => v.trim())\n .filter((v) => v !== '')\n .map((v) => {\n const num = parseFloat(v)\n return isNaN(num) ? 0 : num\n })\n } else if (Array.isArray(value)) {\n doc[field.name] = value\n .filter((v) => v !== null && v !== undefined && v !== '')\n .map((v) => {\n if (typeof v === 'string') {\n const num = parseFloat(v)\n return isNaN(num) ? 0 : num\n }\n return v\n })\n } else if (value !== null && value !== undefined && value !== '') {\n const num = typeof value === 'string' ? parseFloat(value) : value\n doc[field.name] = isNaN(num as number) ? [] : [num]\n } else {\n doc[field.name] = []\n }\n }\n}\n\nconst normalizeHasManyRelationships = (\n doc: Record<string, unknown>,\n fields: FlattenedField[],\n): void => {\n const relationshipFields = fields.filter(\n (field) =>\n (field.type === 'relationship' || field.type === 'upload') &&\n field.hasMany === true &&\n !Array.isArray(field.relationTo),\n )\n\n for (const field of relationshipFields) {\n const value = doc[field.name]\n\n if (typeof value === 'string' && value.includes(',')) {\n doc[field.name] = value\n .split(',')\n .map((v) => v.trim())\n .filter((v) => v !== '')\n } else if (Array.isArray(value)) {\n doc[field.name] = value.filter((v) => v !== null && v !== undefined && v !== '')\n } else if (value !== null && value !== undefined && value !== '') {\n doc[field.name] = [value]\n }\n }\n}\n\nconst normalizePolymorphicRelationships = (\n doc: Record<string, unknown>,\n fields: FlattenedField[],\n): void => {\n for (const [key, value] of Object.entries(doc)) {\n if (Array.isArray(value)) {\n const hasPolymorphicItems = value.some((item) => isPlainObject(item) && 'relationTo' in item)\n\n if (!hasPolymorphicItems) {\n continue\n }\n\n const processedArray: unknown[] = []\n for (const item of value) {\n if (isPlainObject(item) && 'relationTo' in item) {\n if (!item.relationTo || (!item.id && !item.value)) {\n continue\n }\n if ('id' in item) {\n item.value = item.id\n delete item.id\n }\n processedArray.push(item)\n } else if (item !== null && item !== undefined) {\n processedArray.push(item)\n }\n }\n\n if (value.length !== processedArray.length) {\n doc[key] = processedArray.length > 0 ? processedArray : []\n }\n } else if (isPlainObject(value)) {\n if ('relationTo' in value && ('id' in value || 'value' in value)) {\n if (!value.relationTo || (!value.id && !value.value)) {\n doc[key] = null\n } else if ('id' in value && !('value' in value)) {\n value.value = value.id\n delete value.id\n }\n } else {\n normalizePolymorphicRelationships(value, fields)\n }\n }\n }\n}\n\nconst normalizeRichTextInFields = (\n doc: Record<string, unknown>,\n fields: FlattenedField[],\n): void => {\n for (const field of fields) {\n if (!('name' in field) || !field.name || !(field.name in doc)) {\n continue\n }\n const value = doc[field.name]\n if (value === null || value === undefined) {\n continue\n }\n\n if (field.type === 'richText') {\n doc[field.name] = processRichTextField(value)\n } else if (field.type === 'blocks') {\n if (!Array.isArray(value)) {\n continue\n }\n const blockDefs =\n (field as { blocks?: Array<{ flattenedFields?: FlattenedField[]; slug: string }> })\n .blocks ?? []\n for (const blockItem of value) {\n if (!isPlainObject(blockItem)) {\n continue\n }\n const blockDef = blockDefs.find((b) => b.slug === blockItem.blockType)\n if (blockDef) {\n normalizeRichTextInFields(blockItem, getBlockFlattenedFields(blockDef))\n }\n }\n } else if (field.type === 'array') {\n if (!Array.isArray(value)) {\n continue\n }\n const nestedFields = getNestedFlattenedFields(field) ?? []\n for (const item of value) {\n if (!isPlainObject(item)) {\n continue\n }\n normalizeRichTextInFields(item, nestedFields)\n }\n } else if (field.type === 'group' || field.type === 'tab') {\n if (!isPlainObject(value)) {\n continue\n }\n const nestedFields = getNestedFlattenedFields(field) ?? []\n normalizeRichTextInFields(value, nestedFields)\n }\n }\n}\n\nconst normalizeRichText = (doc: Record<string, unknown>, fields: FlattenedField[]): void => {\n normalizeRichTextInFields(doc, fields)\n}\n\n/**\n * Post-processes the unflattened document to handle special field types:\n * - Localized fields: transforms field_locale keys to nested { field: { locale: value } }\n * - Number hasMany: converts comma-separated strings or arrays to number arrays\n * - Relationship hasMany: converts comma-separated IDs to arrays\n * - Polymorphic relationships: transforms flat {relationTo, id} to {relationTo, value}\n * - Rich text fields: ensures proper data structure\n */\nexport const postProcessDocument = (\n doc: Record<string, unknown>,\n fields: FlattenedField[],\n): void => {\n normalizeLocalizedFields(doc, fields)\n normalizeHasManyNumbers(doc, fields)\n normalizeHasManyRelationships(doc, fields)\n normalizePolymorphicRelationships(doc, fields)\n normalizeRichText(doc, fields)\n}\n"],"names":["getBlockFlattenedFields","getNestedFlattenedFields","isPlainObject","processRichTextField","normalizeLocalizedFields","doc","fields","processed","Set","field","filter","f","localized","has","name","localePattern","RegExp","localeData","keysToDelete","key","value","Object","entries","match","push","keys","length","forEach","add","normalizeHasManyNumbers","numberFields","type","hasMany","includes","split","map","v","trim","num","parseFloat","isNaN","Array","isArray","undefined","normalizeHasManyRelationships","relationshipFields","relationTo","normalizePolymorphicRelationships","hasPolymorphicItems","some","item","processedArray","id","normalizeRichTextInFields","blockDefs","blocks","blockItem","blockDef","find","b","slug","blockType","nestedFields","normalizeRichText","postProcessDocument"],"mappings":"AAEA,SAASA,uBAAuB,EAAEC,wBAAwB,QAAQ,uBAAsB;AACxF,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,oBAAoB,QAAQ,4BAA2B;AAEhE,MAAMC,2BAA2B,CAACC,KAA8BC;IAC9D,MAAMC,YAAY,IAAIC;IAEtB,KAAK,MAAMC,SAASH,OAAOI,MAAM,CAAC,CAACC,IAAMA,EAAEC,SAAS,EAAG;QACrD,IAAIL,UAAUM,GAAG,CAACJ,MAAMK,IAAI,GAAG;YAC7B;QACF;QAEA,MAAMC,gBAAgB,IAAIC,OAAO,CAAC,CAAC,EAAEP,MAAMK,IAAI,CAAC,0BAA0B,CAAC;QAC3E,MAAMG,aAAsC,CAAC;QAC7C,MAAMC,eAAyB,EAAE;QAEjC,KAAK,MAAM,CAACC,KAAKC,MAAM,IAAIC,OAAOC,OAAO,CAACjB,KAAM;YAC9C,MAAMkB,QAAQJ,IAAII,KAAK,CAACR;YACxB,IAAIQ,SAASA,KAAK,CAAC,EAAE,EAAE;gBACrBN,UAAU,CAACM,KAAK,CAAC,EAAE,CAAC,GAAGH;gBACvBF,aAAaM,IAAI,CAACL;YACpB;QACF;QAEA,IAAIE,OAAOI,IAAI,CAACR,YAAYS,MAAM,GAAG,GAAG;YACtCrB,GAAG,CAACI,MAAMK,IAAI,CAAC,GAAGG;YAClBC,aAAaS,OAAO,CAAC,CAACR,MAAQ,OAAOd,GAAG,CAACc,IAAI;YAC7CZ,UAAUqB,GAAG,CAACnB,MAAMK,IAAI;QAC1B;IACF;AACF;AAEA,MAAMe,0BAA0B,CAACxB,KAA8BC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O,IAAIX,MAAMsB,IAAI,KAAK,UAAU;YAClC,IAAI,CAACU,MAAMC,OAAO,CAACtB,QAAQ;gBACzB;YACF;YACA,MAAMkC,YACJ,AAAC7C,MACE8C,MAAM,IAAI,EAAE;YACjB,KAAK,MAAMC,aAAapC,MAAO;gBAC7B,IAAI,CAAClB,cAAcsD,YAAY;oBAC7B;gBACF;gBACA,MAAMC,WAAWH,UAAUI,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUK,SAAS;gBACrE,IAAIJ,UAAU;oBACZJ,0BAA0BG,WAAWxD,wBAAwByD;gBAC/D;YACF;QACF,OAAO,IAAIhD,MAAMsB,IAAI,KAAK,SAAS;YACjC,IAAI,CAACU,MAAMC,OAAO,CAACtB,QAAQ;gBACzB;YACF;YACA,MAAM0C,eAAe7D,yBAAyBQ,UAAU,EAAE;YAC1D,KAAK,MAAMyC,QAAQ9B,MAAO;gBACxB,IAAI,CAAClB,cAAcgD,OAAO;oBACxB;gBACF;gBACAG,0BAA0BH,MAAMY;YAClC;QACF,OAAO,IAAIrD,MAAMsB,IAAI,KAAK,WAAWtB,MAAMsB,IAAI,KAAK,OAAO;YACzD,IAAI,CAAC7B,cAAckB,QAAQ;gBACzB;YACF;YACA,MAAM0C,eAAe7D,yBAAyBQ,UAAU,EAAE;YAC1D4C,0BAA0BjC,OAAO0C;QACnC;IACF;AACF;AAEA,MAAMC,oBAAoB,CAAC1D,KAA8BC;IACvD+C,0BAA0BhD,KAAKC;AACjC;AAEA;;;;;;;CAOC,GACD,OAAO,MAAM0D,sBAAsB,CACjC3D,KACAC;IAEAF,yBAAyBC,KAAKC;IAC9BuB,wBAAwBxB,KAAKC;IAC7BsC,8BAA8BvC,KAAKC;IACnCyC,kCAAkC1C,KAAKC;IACvCyD,kBAAkB1D,KAAKC;AACzB,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"validateLimitValue.d.ts","sourceRoot":"","sources":["../../src/utilities/validateLimitValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAEzD,eAAO,MAAM,kBAAkB,GAC7B,OAAO,IAAI,GAAG,MAAM,GAAG,SAAS,EAChC,GAAG,SAAS,KACX,MAAM,GAAG,SAMX,CAAA"}
1
+ {"version":3,"file":"validateLimitValue.d.ts","sourceRoot":"","sources":["../../src/utilities/validateLimitValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAEzD,eAAO,MAAM,kBAAkB,UACtB,IAAI,GAAG,MAAM,GAAG,SAAS,KAC7B,SAAS,KACX,MAAM,GAAG,SAMX,CAAA"}
package/license.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2018-2024 Payload CMS, Inc. <info@payloadcms.com>
3
+ Copyright (c) 2018-2026 Payload CMS, LLC <info@payloadcms.com>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-import-export",
3
- "version": "4.0.0-internal.c2b57ce",
3
+ "version": "4.0.0-internal.c6494b5",
4
4
  "description": "Import-Export plugin for Payload",
5
5
  "keywords": [
6
6
  "payload",
@@ -60,21 +60,21 @@
60
60
  "dist"
61
61
  ],
62
62
  "dependencies": {
63
- "@faceless-ui/modal": "3.0.0",
63
+ "@faceless-ui/modal": "3.0.2",
64
64
  "csv-parse": "5.6.0",
65
65
  "csv-stringify": "6.5.2",
66
66
  "qs-esm": "8.0.1",
67
- "@payloadcms/translations": "4.0.0-internal.c2b57ce",
68
- "@payloadcms/ui": "4.0.0-internal.c2b57ce"
67
+ "@payloadcms/ui": "4.0.0-internal.c6494b5",
68
+ "@payloadcms/translations": "4.0.0-internal.c6494b5"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@payloadcms/eslint-config": "3.28.0",
72
- "@payloadcms/ui": "4.0.0-internal.c2b57ce",
73
- "payload": "4.0.0-internal.c2b57ce"
72
+ "payload": "4.0.0-internal.c6494b5",
73
+ "@payloadcms/ui": "4.0.0-internal.c6494b5"
74
74
  },
75
75
  "peerDependencies": {
76
- "@payloadcms/ui": "4.0.0-internal.c2b57ce",
77
- "payload": "4.0.0-internal.c2b57ce"
76
+ "@payloadcms/ui": "4.0.0-internal.c6494b5",
77
+ "payload": "4.0.0-internal.c6494b5"
78
78
  },
79
79
  "homepage:": "https://payloadcms.com",
80
80
  "scripts": {
@@ -83,7 +83,7 @@
83
83
  "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
84
84
  "build:types": "tsc --emitDeclarationOnly --outDir dist",
85
85
  "clean": "rimraf {dist,*.tsbuildinfo}",
86
- "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
86
+ "copyfiles": "copyfiles -u 1 -e \"**/*.spec.*\" \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
87
87
  "lint": "eslint .",
88
88
  "lint:fix": "eslint . --fix"
89
89
  }