@payloadcms/plugin-import-export 4.0.0-internal.38b7f1d → 4.0.0-internal.3b50481

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 (186) 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/handleDownload.d.ts.map +1 -1
  80. package/dist/export/handleDownload.js +7 -3
  81. package/dist/export/handleDownload.js.map +1 -1
  82. package/dist/export/handlePreview.d.ts.map +1 -1
  83. package/dist/export/handlePreview.js +25 -6
  84. package/dist/export/handlePreview.js.map +1 -1
  85. package/dist/exports/types.d.ts +1 -1
  86. package/dist/exports/types.d.ts.map +1 -1
  87. package/dist/exports/types.js.map +1 -1
  88. package/dist/import/batchProcessor.d.ts +4 -3
  89. package/dist/import/batchProcessor.d.ts.map +1 -1
  90. package/dist/import/batchProcessor.js +15 -8
  91. package/dist/import/batchProcessor.js.map +1 -1
  92. package/dist/import/createImport.d.ts +3 -2
  93. package/dist/import/createImport.d.ts.map +1 -1
  94. package/dist/import/createImport.js +9 -2
  95. package/dist/import/createImport.js.map +1 -1
  96. package/dist/import/getCreateImportCollectionTask.d.ts.map +1 -1
  97. package/dist/import/getCreateImportCollectionTask.js +5 -2
  98. package/dist/import/getCreateImportCollectionTask.js.map +1 -1
  99. package/dist/import/getImportCollection.d.ts.map +1 -1
  100. package/dist/import/getImportCollection.js +6 -4
  101. package/dist/import/getImportCollection.js.map +1 -1
  102. package/dist/import/handlePreview.d.ts.map +1 -1
  103. package/dist/import/handlePreview.js +5 -1
  104. package/dist/import/handlePreview.js.map +1 -1
  105. package/dist/index.d.ts +2 -13
  106. package/dist/index.d.ts.map +1 -1
  107. package/dist/index.js +19 -8
  108. package/dist/index.js.map +1 -1
  109. package/dist/translations/languages/en.d.ts.map +1 -1
  110. package/dist/types.d.ts +17 -33
  111. package/dist/types.d.ts.map +1 -1
  112. package/dist/types.js.map +1 -1
  113. package/dist/utilities/applyFieldHooks.d.ts +1 -2
  114. package/dist/utilities/applyFieldHooks.d.ts.map +1 -1
  115. package/dist/utilities/applyFieldHooks.js +2 -3
  116. package/dist/utilities/applyFieldHooks.js.map +1 -1
  117. package/dist/utilities/flattenObject.d.ts.map +1 -1
  118. package/dist/utilities/flattenObject.js +3 -13
  119. package/dist/utilities/flattenObject.js.map +1 -1
  120. package/dist/utilities/flattenedFields.d.ts.map +1 -1
  121. package/dist/utilities/flattenedFields.js +3 -0
  122. package/dist/utilities/flattenedFields.js.map +1 -1
  123. package/dist/utilities/getExportFieldFunctions.js +64 -35
  124. package/dist/utilities/getExportFieldFunctions.js.map +1 -1
  125. package/dist/utilities/getFileFromDoc.js +3 -3
  126. package/dist/utilities/getFileFromDoc.js.map +1 -1
  127. package/dist/utilities/getImportFieldFunctions.js +0 -8
  128. package/dist/utilities/getImportFieldFunctions.js.map +1 -1
  129. package/dist/utilities/getSchemaColumns.d.ts +1 -1
  130. package/dist/utilities/getSchemaColumns.js +2 -2
  131. package/dist/utilities/getSchemaColumns.js.map +1 -1
  132. package/dist/utilities/getSelect.d.ts.map +1 -1
  133. package/dist/utilities/getSelect.js +11 -3
  134. package/dist/utilities/getSelect.js.map +1 -1
  135. package/dist/utilities/getSubmittedFormValues.d.ts +12 -0
  136. package/dist/utilities/getSubmittedFormValues.d.ts.map +1 -0
  137. package/dist/utilities/getSubmittedFormValues.js +24 -0
  138. package/dist/utilities/getSubmittedFormValues.js.map +1 -0
  139. package/dist/utilities/processRichTextField.d.ts.map +1 -1
  140. package/dist/utilities/processRichTextField.js +7 -0
  141. package/dist/utilities/processRichTextField.js.map +1 -1
  142. package/dist/utilities/setNestedValue.d.ts +2 -1
  143. package/dist/utilities/setNestedValue.d.ts.map +1 -1
  144. package/dist/utilities/setNestedValue.js +65 -34
  145. package/dist/utilities/setNestedValue.js.map +1 -1
  146. package/dist/utilities/sortHelpers.d.ts +1 -1
  147. package/dist/utilities/unflattenObject.d.ts.map +1 -1
  148. package/dist/utilities/unflattenObject.js +29 -18
  149. package/dist/utilities/unflattenObject.js.map +1 -1
  150. package/dist/utilities/unflattenPostProcess.d.ts.map +1 -1
  151. package/dist/utilities/unflattenPostProcess.js +39 -13
  152. package/dist/utilities/unflattenPostProcess.js.map +1 -1
  153. package/license.md +1 -1
  154. package/package.json +10 -10
  155. package/dist/components/ExportPreview/index.scss +0 -48
  156. package/dist/components/FieldsToExport/index.scss +0 -0
  157. package/dist/components/FieldsToExport/reduceFields.spec.js +0 -239
  158. package/dist/components/FieldsToExport/reduceFields.spec.js.map +0 -1
  159. package/dist/components/ImportPreview/index.scss +0 -41
  160. package/dist/components/SortBy/index.scss +0 -3
  161. package/dist/components/SortOrder/index.scss +0 -3
  162. package/dist/utilities/applyFieldHooks.spec.js +0 -205
  163. package/dist/utilities/applyFieldHooks.spec.js.map +0 -1
  164. package/dist/utilities/buildDisabledFieldRegex.spec.js +0 -64
  165. package/dist/utilities/buildDisabledFieldRegex.spec.js.map +0 -1
  166. package/dist/utilities/fieldToRegex.spec.js +0 -151
  167. package/dist/utilities/fieldToRegex.spec.js.map +0 -1
  168. package/dist/utilities/filterToSelectedFields.spec.js +0 -204
  169. package/dist/utilities/filterToSelectedFields.spec.js.map +0 -1
  170. package/dist/utilities/flattenObject.spec.js +0 -158
  171. package/dist/utilities/flattenObject.spec.js.map +0 -1
  172. package/dist/utilities/getExportFieldFunctions.spec.js +0 -50
  173. package/dist/utilities/getExportFieldFunctions.spec.js.map +0 -1
  174. package/dist/utilities/getImportFieldFunctions.spec.js +0 -167
  175. package/dist/utilities/getImportFieldFunctions.spec.js.map +0 -1
  176. package/dist/utilities/getSchemaColumns.spec.js +0 -157
  177. package/dist/utilities/getSchemaColumns.spec.js.map +0 -1
  178. package/dist/utilities/legacyHookDispatch.spec.js +0 -227
  179. package/dist/utilities/legacyHookDispatch.spec.js.map +0 -1
  180. package/dist/utilities/parseCSV.spec.js +0 -195
  181. package/dist/utilities/parseCSV.spec.js.map +0 -1
  182. package/dist/utilities/siblingDoc.spec.js +0 -278
  183. package/dist/utilities/siblingDoc.spec.js.map +0 -1
  184. package/dist/utilities/unflattenObject.spec.js +0 -713
  185. package/dist/utilities/unflattenObject.spec.js.map +0 -1
  186. /package/dist/components/Page/{index.scss → index.css} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/getImportFieldFunctions.ts"],"sourcesContent":["import type { FlattenedField } from 'payload'\n\nimport type { FieldBeforeImportHook, ImportFieldHookEntry } from '../types.js'\n\nimport { registerFieldHooks } from './flattenedFields.js'\n\ntype Args = {\n fields: FlattenedField[]\n}\n\n/**\n * Builds a map from logical field path (e.g. `content_textBlock_body`) to\n * the import hook entry. Paths include block slugs but never array indices.\n */\nexport const getImportFieldFunctions = ({ fields }: Args): Record<string, ImportFieldHookEntry> => {\n const result: Record<string, ImportFieldHookEntry> = {}\n registerFieldHooks(fields, '', result, registerImportHandler)\n return result\n}\n\nconst registerImportHandler = (\n field: FlattenedField,\n fullKey: string,\n result: Record<string, ImportFieldHookEntry>,\n): void => {\n const beforeImport = field.custom?.['plugin-import-export']?.hooks?.beforeImport\n\n const fromCSV = field.custom?.['plugin-import-export']?.fromCSV\n\n if (typeof beforeImport === 'function') {\n result[fullKey] = { type: 'beforeImport', fn: beforeImport }\n return\n }\n\n if (typeof fromCSV === 'function') {\n result[fullKey] = { type: 'fromCSV', fn: fromCSV }\n return\n }\n\n const registerBeforeImport = (fn: FieldBeforeImportHook) => {\n result[fullKey] = { type: 'beforeImport', fn }\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (field.hasMany !== true) {\n if (!Array.isArray(field.relationTo)) {\n registerBeforeImport(({ value }) => value)\n }\n } else if (!Array.isArray(field.relationTo)) {\n registerBeforeImport(({ value }) => value)\n }\n return\n }\n\n if (field.type === 'number') {\n if (field.hasMany) {\n registerBeforeImport(({ value }) => value)\n return\n }\n registerBeforeImport(({ value }) => {\n if (isEmptyImportValue(value)) {\n return undefined\n }\n if (typeof value === 'number') {\n return value\n }\n if (typeof value === 'string') {\n const parsed = parseFloat(value)\n return isNaN(parsed) ? undefined : parsed\n }\n return value\n })\n return\n }\n\n if (field.type === 'checkbox') {\n registerBeforeImport(({ value }) => {\n if (isEmptyImportValue(value)) {\n return undefined\n }\n if (typeof value === 'boolean') {\n return value\n }\n if (typeof value === 'string') {\n return value.toLowerCase() === 'true' || value === '1'\n }\n return Boolean(value)\n })\n return\n }\n\n if (field.type === 'date') {\n registerBeforeImport(({ value }) => {\n if (isEmptyImportValue(value)) {\n return undefined\n }\n if (typeof value === 'string' && !isNaN(Date.parse(value))) {\n return value\n }\n try {\n const date = new Date(value as string)\n return isNaN(date.getTime()) ? value : date.toISOString()\n } catch {\n return value\n }\n })\n return\n }\n\n if (field.type === 'json' || field.type === 'richText') {\n registerBeforeImport(({ value }) => {\n if (isEmptyImportValue(value)) {\n return undefined\n }\n if (typeof value === 'object') {\n return value\n }\n if (typeof value === 'string') {\n try {\n return JSON.parse(value)\n } catch {\n return value\n }\n }\n return value\n })\n }\n}\n\nconst isEmptyImportValue = (value: unknown): boolean =>\n value === '' || value === null || value === undefined\n"],"names":["registerFieldHooks","getImportFieldFunctions","fields","result","registerImportHandler","field","fullKey","beforeImport","custom","hooks","fromCSV","type","fn","registerBeforeImport","hasMany","Array","isArray","relationTo","value","isEmptyImportValue","undefined","parsed","parseFloat","isNaN","toLowerCase","Boolean","Date","parse","date","getTime","toISOString","JSON"],"mappings":"AAIA,SAASA,kBAAkB,QAAQ,uBAAsB;AAMzD;;;CAGC,GACD,OAAO,MAAMC,0BAA0B,CAAC,EAAEC,MAAM,EAAQ;IACtD,MAAMC,SAA+C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.ts"],"sourcesContent":["import type { FlattenedField } from 'payload'\n\nimport type { FieldBeforeImportHook, ImportFieldHookEntry } from '../types.js'\n\nimport { registerFieldHooks } from './flattenedFields.js'\n\ntype Args = {\n fields: FlattenedField[]\n}\n\n/**\n * Builds a map from logical field path (e.g. `content_textBlock_body`) to\n * the import hook entry. Paths include block slugs but never array indices.\n */\nexport const getImportFieldFunctions = ({ fields }: Args): Record<string, ImportFieldHookEntry> => {\n const result: Record<string, ImportFieldHookEntry> = {}\n registerFieldHooks(fields, '', result, registerImportHandler)\n return result\n}\n\nconst registerImportHandler = (\n field: FlattenedField,\n fullKey: string,\n result: Record<string, ImportFieldHookEntry>,\n): void => {\n const beforeImport = field.custom?.['plugin-import-export']?.hooks?.beforeImport\n\n if (typeof beforeImport === 'function') {\n result[fullKey] = { type: 'beforeImport', fn: beforeImport }\n return\n }\n\n const registerBeforeImport = (fn: FieldBeforeImportHook) => {\n result[fullKey] = { type: 'beforeImport', fn }\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (field.hasMany !== true) {\n if (!Array.isArray(field.relationTo)) {\n registerBeforeImport(({ value }) => value)\n }\n } else if (!Array.isArray(field.relationTo)) {\n registerBeforeImport(({ value }) => value)\n }\n return\n }\n\n if (field.type === 'number') {\n if (field.hasMany) {\n registerBeforeImport(({ value }) => value)\n return\n }\n registerBeforeImport(({ value }) => {\n if (isEmptyImportValue(value)) {\n return undefined\n }\n if (typeof value === 'number') {\n return value\n }\n if (typeof value === 'string') {\n const parsed = parseFloat(value)\n return isNaN(parsed) ? undefined : parsed\n }\n return value\n })\n return\n }\n\n if (field.type === 'checkbox') {\n registerBeforeImport(({ value }) => {\n if (isEmptyImportValue(value)) {\n return undefined\n }\n if (typeof value === 'boolean') {\n return value\n }\n if (typeof value === 'string') {\n return value.toLowerCase() === 'true' || value === '1'\n }\n return Boolean(value)\n })\n return\n }\n\n if (field.type === 'date') {\n registerBeforeImport(({ value }) => {\n if (isEmptyImportValue(value)) {\n return undefined\n }\n if (typeof value === 'string' && !isNaN(Date.parse(value))) {\n return value\n }\n try {\n const date = new Date(value as string)\n return isNaN(date.getTime()) ? value : date.toISOString()\n } catch {\n return value\n }\n })\n return\n }\n\n if (field.type === 'json' || field.type === 'richText') {\n registerBeforeImport(({ value }) => {\n if (isEmptyImportValue(value)) {\n return undefined\n }\n if (typeof value === 'object') {\n return value\n }\n if (typeof value === 'string') {\n try {\n return JSON.parse(value)\n } catch {\n return value\n }\n }\n return value\n })\n }\n}\n\nconst isEmptyImportValue = (value: unknown): boolean =>\n value === '' || value === null || value === undefined\n"],"names":["registerFieldHooks","getImportFieldFunctions","fields","result","registerImportHandler","field","fullKey","beforeImport","custom","hooks","type","fn","registerBeforeImport","hasMany","Array","isArray","relationTo","value","isEmptyImportValue","undefined","parsed","parseFloat","isNaN","toLowerCase","Boolean","Date","parse","date","getTime","toISOString","JSON"],"mappings":"AAIA,SAASA,kBAAkB,QAAQ,uBAAsB;AAMzD;;;CAGC,GACD,OAAO,MAAMC,0BAA0B,CAAC,EAAEC,MAAM,EAAQ;IACtD,MAAMC,SAA+C,CAAC;IACtDH,mBAAmBE,QAAQ,IAAIC,QAAQC;IACvC,OAAOD;AACT,EAAC;AAED,MAAMC,wBAAwB,CAC5BC,OACAC,SACAH;IAEA,MAAMI,eAAeF,MAAMG,MAAM,EAAE,CAAC,uBAAuB,EAAEC,OAAOF;IAEpE,IAAI,OAAOA,iBAAiB,YAAY;QACtCJ,MAAM,CAACG,QAAQ,GAAG;YAAEI,MAAM;YAAgBC,IAAIJ;QAAa;QAC3D;IACF;IAEA,MAAMK,uBAAuB,CAACD;QAC5BR,MAAM,CAACG,QAAQ,GAAG;YAAEI,MAAM;YAAgBC;QAAG;IAC/C;IAEA,IAAIN,MAAMK,IAAI,KAAK,kBAAkBL,MAAMK,IAAI,KAAK,UAAU;QAC5D,IAAIL,MAAMQ,OAAO,KAAK,MAAM;YAC1B,IAAI,CAACC,MAAMC,OAAO,CAACV,MAAMW,UAAU,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D,EAAE,OAAM;gBACN,OAAOZ;YACT;QACF;QACA;IACF;IAEA,IAAIZ,MAAMK,IAAI,KAAK,UAAUL,MAAMK,IAAI,KAAK,YAAY;QACtDE,qBAAqB,CAAC,EAAEK,KAAK,EAAE;YAC7B,IAAIC,mBAAmBD,QAAQ;gBAC7B,OAAOE;YACT;YACA,IAAI,OAAOF,UAAU,UAAU;gBAC7B,OAAOA;YACT;YACA,IAAI,OAAOA,UAAU,UAAU;gBAC7B,IAAI;oBACF,OAAOa,KAAKJ,KAAK,CAACT;gBACpB,EAAE,OAAM;oBACN,OAAOA;gBACT;YACF;YACA,OAAOA;QACT;IACF;AACF;AAEA,MAAMC,qBAAqB,CAACD,QAC1BA,UAAU,MAAMA,UAAU,QAAQA,UAAUE"}
@@ -37,7 +37,7 @@ export declare const getSchemaColumns: ({ collectionConfig, disabledFields, fiel
37
37
  /**
38
38
  * Merges schema-derived columns with data-discovered columns.
39
39
  * Schema columns provide the base ordering, data columns add any additional
40
- * columns (e.g., array indices beyond 0, dynamic fields, derived columns from toCSV).
40
+ * columns (e.g., array indices beyond 0, dynamic fields, derived columns from beforeExport hooks).
41
41
  */
42
42
  export declare const mergeColumns: (schemaColumns: string[], dataColumns: string[]) => string[];
43
43
  /**
@@ -45,7 +45,7 @@ import { getFlattenedFieldKeys } from './getFlattenedFieldKeys.js';
45
45
  /**
46
46
  * Merges schema-derived columns with data-discovered columns.
47
47
  * Schema columns provide the base ordering, data columns add any additional
48
- * columns (e.g., array indices beyond 0, dynamic fields, derived columns from toCSV).
48
+ * columns (e.g., array indices beyond 0, dynamic fields, derived columns from beforeExport hooks).
49
49
  */ export const mergeColumns = (schemaColumns, dataColumns)=>{
50
50
  const result = [
51
51
  ...schemaColumns
@@ -101,7 +101,7 @@ import { getFlattenedFieldKeys } from './getFlattenedFieldKeys.js';
101
101
  }
102
102
  }
103
103
  }
104
- // Remove schema columns that were fully replaced by toCSV-derived columns (e.g. "user" → "user_id", "user_email")
104
+ // Remove schema columns that were fully replaced by beforeExport-derived columns (e.g. "user" → "user_id", "user_email")
105
105
  for (const [schemaCol, derivedCols] of insertedDerived){
106
106
  if (!dataColumns.includes(schemaCol) && derivedCols.length > 0) {
107
107
  const idx = result.indexOf(schemaCol);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/getSchemaColumns.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from 'payload'\n\nimport { getFlattenedFieldKeys } from './getFlattenedFieldKeys.js'\n\nexport type GetSchemaColumnsArgs = {\n /**\n * The collection configuration to derive columns from\n */\n collectionConfig: SanitizedCollectionConfig\n /**\n * Array of disabled field paths from plugin config\n */\n disabledFields?: string[]\n /**\n * User-selected fields to export. If provided, only these fields (and their nested fields) will be included.\n */\n fields?: string[]\n /**\n * The locale to export. When 'all', localized fields are expanded to include all locale suffixes.\n */\n locale?: null | string\n /**\n * Available locale codes from config. Required when locale='all'.\n */\n localeCodes?: string[]\n}\n\n/**\n * Derives CSV column names from the collection schema.\n * This provides a base set of columns from field definitions.\n *\n * Note: For arrays/blocks with multiple items, the schema only generates index 0.\n * Additional indices from actual data should be merged with these columns.\n *\n * Benefits:\n * - Provides consistent base columns\n * - Works for empty exports\n * - Ensures proper column ordering\n */\nexport const getSchemaColumns = ({\n collectionConfig,\n disabledFields = [],\n fields: selectedFields,\n locale,\n localeCodes,\n}: GetSchemaColumnsArgs): string[] => {\n const expandLocales = locale === 'all' && localeCodes && localeCodes.length > 0\n\n let schemaColumns = getFlattenedFieldKeys(\n collectionConfig.flattenedFields,\n '',\n expandLocales ? { localeCodes } : {},\n )\n\n // Add id if not present in schema\n const hasIdField = schemaColumns.includes('id')\n if (!hasIdField) {\n schemaColumns = ['id', ...schemaColumns]\n }\n\n if (selectedFields && selectedFields.length > 0) {\n schemaColumns = filterToSelectedFields(schemaColumns, selectedFields)\n }\n\n if (disabledFields.length > 0) {\n const disabledSet = new Set<string>()\n for (const path of disabledFields) {\n disabledSet.add(path.replace(/\\./g, '_'))\n }\n schemaColumns = schemaColumns.filter((col) => {\n for (const disabled of disabledSet) {\n if (col === disabled || col.startsWith(`${disabled}_`)) {\n return false\n }\n }\n return true\n })\n }\n\n return schemaColumns\n}\n\n/**\n * Merges schema-derived columns with data-discovered columns.\n * Schema columns provide the base ordering, data columns add any additional\n * columns (e.g., array indices beyond 0, dynamic fields, derived columns from toCSV).\n */\nexport const mergeColumns = (schemaColumns: string[], dataColumns: string[]): string[] => {\n const result = [...schemaColumns]\n const schemaSet = new Set(schemaColumns)\n const insertedDerived = new Map<string, string[]>()\n\n for (const col of dataColumns) {\n if (!schemaSet.has(col)) {\n let inserted = false\n\n for (const schemaCol of schemaColumns) {\n if (col.startsWith(`${schemaCol}_`)) {\n const suffix = col.slice(schemaCol.length + 1)\n // Skip if suffix starts with a digit (array index pattern like field_0_*)\n if (!/^\\d/.test(suffix)) {\n const baseIdx = result.indexOf(schemaCol)\n if (baseIdx !== -1) {\n const derivedList = insertedDerived.get(schemaCol) || []\n const insertIdx = baseIdx + 1 + derivedList.length\n result.splice(insertIdx, 0, col)\n derivedList.push(col)\n insertedDerived.set(schemaCol, derivedList)\n schemaSet.add(col)\n inserted = true\n break\n }\n }\n }\n }\n\n if (!inserted) {\n // Check for array indices (e.g., field_1_*), insert after field_0_*\n const match = col.match(/^(.+?)_(\\d+)(_.*)?$/)\n if (match) {\n const [, basePath, index, suffix] = match\n if (basePath && index) {\n const prevIndex = parseInt(index, 10) - 1\n const prevCol = `${basePath}_${prevIndex}${suffix ?? ''}`\n const prevIdx = result.indexOf(prevCol)\n if (prevIdx !== -1) {\n // Insert after the previous index column\n result.splice(prevIdx + 1, 0, col)\n schemaSet.add(col)\n continue\n }\n }\n }\n\n const createdAtIdx = result.indexOf('createdAt')\n if (createdAtIdx !== -1) {\n result.splice(createdAtIdx, 0, col)\n } else {\n result.push(col)\n }\n schemaSet.add(col)\n }\n }\n }\n\n // Remove schema columns that were fully replaced by toCSV-derived columns (e.g. \"user\" → \"user_id\", \"user_email\")\n for (const [schemaCol, derivedCols] of insertedDerived) {\n if (!dataColumns.includes(schemaCol) && derivedCols.length > 0) {\n const idx = result.indexOf(schemaCol)\n if (idx !== -1) {\n result.splice(idx, 1)\n }\n }\n }\n\n return result\n}\n\n/**\n * Filters schema columns to only include those matching user-selected fields.\n * Preserves the order specified by the user in selectedFields.\n *\n * Container fields (groups, arrays, blocks) don't produce their own column, so we prefix-expand\n * to find their children (e.g., 'group' → 'group_name', 'group_age').\n * Leaf fields (date, text, select) produce an exact column, so we only match exactly to avoid\n * including siblings with similar prefixes (e.g., 'dateWithTimezone' won't pull 'dateWithTimezone_tz').\n */\nexport function filterToSelectedFields(columns: string[], selectedFields: string[]): string[] {\n const result: string[] = []\n const columnsSet = new Set(columns)\n\n // Convert selected fields to underscore notation patterns\n const patterns = selectedFields.map((field) => {\n const underscored = field.replace(/\\./g, '_')\n return {\n exact: underscored,\n original: field,\n prefix: `${underscored}_`,\n }\n })\n\n // Iterate through user-specified fields in order to preserve their ordering\n for (const pattern of patterns) {\n const hasExactColumn = columnsSet.has(pattern.exact)\n\n if (hasExactColumn && !result.includes(pattern.exact)) {\n result.push(pattern.exact)\n }\n\n // Only prefix-expand if no exact column match exists (containers need expansion, leaves don't)\n if (!hasExactColumn) {\n for (const column of columns) {\n if (column.startsWith(pattern.prefix)) {\n if (!result.includes(column)) {\n result.push(column)\n }\n }\n }\n }\n }\n\n return result\n}\n"],"names":["getFlattenedFieldKeys","getSchemaColumns","collectionConfig","disabledFields","fields","selectedFields","locale","localeCodes","expandLocales","length","schemaColumns","flattenedFields","hasIdField","includes","filterToSelectedFields","disabledSet","Set","path","add","replace","filter","col","disabled","startsWith","mergeColumns","dataColumns","result","schemaSet","insertedDerived","Map","has","inserted","schemaCol","suffix","slice","test","baseIdx","indexOf","derivedList","get","insertIdx","splice","push","set","match","basePath","index","prevIndex","parseInt","prevCol","prevIdx","createdAtIdx","derivedCols","idx","columns","columnsSet","patterns","map","field","underscored","exact","original","prefix","pattern","hasExactColumn","column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IAEA,kHAAkH;IAClH,KAAK,MAAM,CAACW,WAAWoB,YAAY,IAAIxB,gBAAiB;QACtD,IAAI,CAACH,YAAYZ,QAAQ,CAACmB,cAAcoB,YAAY3C,MAAM,GAAG,GAAG;YAC9D,MAAM4C,MAAM3B,OAAOW,OAAO,CAACL;YAC3B,IAAIqB,QAAQ,CAAC,GAAG;gBACd3B,OAAOe,MAAM,CAACY,KAAK;YACrB;QACF;IACF;IAEA,OAAO3B;AACT,EAAC;AAED;;;;;;;;CAQC,GACD,OAAO,SAASZ,uBAAuBwC,OAAiB,EAAEjD,cAAwB;IAChF,MAAMqB,SAAmB,EAAE;IAC3B,MAAM6B,aAAa,IAAIvC,IAAIsC;IAE3B,0DAA0D;IAC1D,MAAME,WAAWnD,eAAeoD,GAAG,CAAC,CAACC;QACnC,MAAMC,cAAcD,MAAMvC,OAAO,CAAC,OAAO;QACzC,OAAO;YACLyC,OAAOD;YACPE,UAAUH;YACVI,QAAQ,GAAGH,YAAY,CAAC,CAAC;QAC3B;IACF;IAEA,4EAA4E;IAC5E,KAAK,MAAMI,WAAWP,SAAU;QAC9B,MAAMQ,iBAAiBT,WAAWzB,GAAG,CAACiC,QAAQH,KAAK;QAEnD,IAAII,kBAAkB,CAACtC,OAAOb,QAAQ,CAACkD,QAAQH,KAAK,GAAG;YACrDlC,OAAOgB,IAAI,CAACqB,QAAQH,KAAK;QAC3B;QAEA,+FAA+F;QAC/F,IAAI,CAACI,gBAAgB;YACnB,KAAK,MAAMC,UAAUX,QAAS;gBAC5B,IAAIW,OAAO1C,UAAU,CAACwC,QAAQD,MAAM,GAAG;oBACrC,IAAI,CAACpC,OAAOb,QAAQ,CAACoD,SAAS;wBAC5BvC,OAAOgB,IAAI,CAACuB;oBACd;gBACF;YACF;QACF;IACF;IAEA,OAAOvC;AACT"}
1
+ {"version":3,"sources":["../../src/utilities/getSchemaColumns.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from 'payload'\n\nimport { getFlattenedFieldKeys } from './getFlattenedFieldKeys.js'\n\nexport type GetSchemaColumnsArgs = {\n /**\n * The collection configuration to derive columns from\n */\n collectionConfig: SanitizedCollectionConfig\n /**\n * Array of disabled field paths from plugin config\n */\n disabledFields?: string[]\n /**\n * User-selected fields to export. If provided, only these fields (and their nested fields) will be included.\n */\n fields?: string[]\n /**\n * The locale to export. When 'all', localized fields are expanded to include all locale suffixes.\n */\n locale?: null | string\n /**\n * Available locale codes from config. Required when locale='all'.\n */\n localeCodes?: string[]\n}\n\n/**\n * Derives CSV column names from the collection schema.\n * This provides a base set of columns from field definitions.\n *\n * Note: For arrays/blocks with multiple items, the schema only generates index 0.\n * Additional indices from actual data should be merged with these columns.\n *\n * Benefits:\n * - Provides consistent base columns\n * - Works for empty exports\n * - Ensures proper column ordering\n */\nexport const getSchemaColumns = ({\n collectionConfig,\n disabledFields = [],\n fields: selectedFields,\n locale,\n localeCodes,\n}: GetSchemaColumnsArgs): string[] => {\n const expandLocales = locale === 'all' && localeCodes && localeCodes.length > 0\n\n let schemaColumns = getFlattenedFieldKeys(\n collectionConfig.flattenedFields,\n '',\n expandLocales ? { localeCodes } : {},\n )\n\n // Add id if not present in schema\n const hasIdField = schemaColumns.includes('id')\n if (!hasIdField) {\n schemaColumns = ['id', ...schemaColumns]\n }\n\n if (selectedFields && selectedFields.length > 0) {\n schemaColumns = filterToSelectedFields(schemaColumns, selectedFields)\n }\n\n if (disabledFields.length > 0) {\n const disabledSet = new Set<string>()\n for (const path of disabledFields) {\n disabledSet.add(path.replace(/\\./g, '_'))\n }\n schemaColumns = schemaColumns.filter((col) => {\n for (const disabled of disabledSet) {\n if (col === disabled || col.startsWith(`${disabled}_`)) {\n return false\n }\n }\n return true\n })\n }\n\n return schemaColumns\n}\n\n/**\n * Merges schema-derived columns with data-discovered columns.\n * Schema columns provide the base ordering, data columns add any additional\n * columns (e.g., array indices beyond 0, dynamic fields, derived columns from beforeExport hooks).\n */\nexport const mergeColumns = (schemaColumns: string[], dataColumns: string[]): string[] => {\n const result = [...schemaColumns]\n const schemaSet = new Set(schemaColumns)\n const insertedDerived = new Map<string, string[]>()\n\n for (const col of dataColumns) {\n if (!schemaSet.has(col)) {\n let inserted = false\n\n for (const schemaCol of schemaColumns) {\n if (col.startsWith(`${schemaCol}_`)) {\n const suffix = col.slice(schemaCol.length + 1)\n // Skip if suffix starts with a digit (array index pattern like field_0_*)\n if (!/^\\d/.test(suffix)) {\n const baseIdx = result.indexOf(schemaCol)\n if (baseIdx !== -1) {\n const derivedList = insertedDerived.get(schemaCol) || []\n const insertIdx = baseIdx + 1 + derivedList.length\n result.splice(insertIdx, 0, col)\n derivedList.push(col)\n insertedDerived.set(schemaCol, derivedList)\n schemaSet.add(col)\n inserted = true\n break\n }\n }\n }\n }\n\n if (!inserted) {\n // Check for array indices (e.g., field_1_*), insert after field_0_*\n const match = col.match(/^(.+?)_(\\d+)(_.*)?$/)\n if (match) {\n const [, basePath, index, suffix] = match\n if (basePath && index) {\n const prevIndex = parseInt(index, 10) - 1\n const prevCol = `${basePath}_${prevIndex}${suffix ?? ''}`\n const prevIdx = result.indexOf(prevCol)\n if (prevIdx !== -1) {\n // Insert after the previous index column\n result.splice(prevIdx + 1, 0, col)\n schemaSet.add(col)\n continue\n }\n }\n }\n\n const createdAtIdx = result.indexOf('createdAt')\n if (createdAtIdx !== -1) {\n result.splice(createdAtIdx, 0, col)\n } else {\n result.push(col)\n }\n schemaSet.add(col)\n }\n }\n }\n\n // Remove schema columns that were fully replaced by beforeExport-derived columns (e.g. \"user\" → \"user_id\", \"user_email\")\n for (const [schemaCol, derivedCols] of insertedDerived) {\n if (!dataColumns.includes(schemaCol) && derivedCols.length > 0) {\n const idx = result.indexOf(schemaCol)\n if (idx !== -1) {\n result.splice(idx, 1)\n }\n }\n }\n\n return result\n}\n\n/**\n * Filters schema columns to only include those matching user-selected fields.\n * Preserves the order specified by the user in selectedFields.\n *\n * Container fields (groups, arrays, blocks) don't produce their own column, so we prefix-expand\n * to find their children (e.g., 'group' → 'group_name', 'group_age').\n * Leaf fields (date, text, select) produce an exact column, so we only match exactly to avoid\n * including siblings with similar prefixes (e.g., 'dateWithTimezone' won't pull 'dateWithTimezone_tz').\n */\nexport function filterToSelectedFields(columns: string[], selectedFields: string[]): string[] {\n const result: string[] = []\n const columnsSet = new Set(columns)\n\n // Convert selected fields to underscore notation patterns\n const patterns = selectedFields.map((field) => {\n const underscored = field.replace(/\\./g, '_')\n return {\n exact: underscored,\n original: field,\n prefix: `${underscored}_`,\n }\n })\n\n // Iterate through user-specified fields in order to preserve their ordering\n for (const pattern of patterns) {\n const hasExactColumn = columnsSet.has(pattern.exact)\n\n if (hasExactColumn && !result.includes(pattern.exact)) {\n result.push(pattern.exact)\n }\n\n // Only prefix-expand if no exact column match exists (containers need expansion, leaves don't)\n if (!hasExactColumn) {\n for (const column of columns) {\n if (column.startsWith(pattern.prefix)) {\n if (!result.includes(column)) {\n result.push(column)\n }\n }\n }\n }\n }\n\n return result\n}\n"],"names":["getFlattenedFieldKeys","getSchemaColumns","collectionConfig","disabledFields","fields","selectedFields","locale","localeCodes","expandLocales","length","schemaColumns","flattenedFields","hasIdField","includes","filterToSelectedFields","disabledSet","Set","path","add","replace","filter","col","disabled","startsWith","mergeColumns","dataColumns","result","schemaSet","insertedDerived","Map","has","inserted","schemaCol","suffix","slice","test","baseIdx","indexOf","derivedList","get","insertIdx","splice","push","set","match","basePath","index","prevIndex","parseInt","prevCol","prevIdx","createdAtIdx","derivedCols","idx","columns","columnsSet","patterns","map","field","underscored","exact","original","prefix","pattern","hasExactColumn","column"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,6BAA4B;AAyBlE;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,mBAAmB,CAAC,EAC/BC,gBAAgB,EAChBC,iBAAiB,EAAE,EACnBC,QAAQC,cAAc,EACtBC,MAAM,EACNC,WAAW,EACU;IACrB,MAAMC,gBAAgBF,WAAW,SAASC,eAAeA,YAAYE,MAAM,GAAG;IAE9E,IAAIC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IACF;IAEA,OAAO3B;AACT,EAAC;AAED;;;;;;;;CAQC,GACD,OAAO,SAASZ,uBAAuBwC,OAAiB,EAAEjD,cAAwB;IAChF,MAAMqB,SAAmB,EAAE;IAC3B,MAAM6B,aAAa,IAAIvC,IAAIsC;IAE3B,0DAA0D;IAC1D,MAAME,WAAWnD,eAAeoD,GAAG,CAAC,CAACC;QACnC,MAAMC,cAAcD,MAAMvC,OAAO,CAAC,OAAO;QACzC,OAAO;YACLyC,OAAOD;YACPE,UAAUH;YACVI,QAAQ,GAAGH,YAAY,CAAC,CAAC;QAC3B;IACF;IAEA,4EAA4E;IAC5E,KAAK,MAAMI,WAAWP,SAAU;QAC9B,MAAMQ,iBAAiBT,WAAWzB,GAAG,CAACiC,QAAQH,KAAK;QAEnD,IAAII,kBAAkB,CAACtC,OAAOb,QAAQ,CAACkD,QAAQH,KAAK,GAAG;YACrDlC,OAAOgB,IAAI,CAACqB,QAAQH,KAAK;QAC3B;QAEA,+FAA+F;QAC/F,IAAI,CAACI,gBAAgB;YACnB,KAAK,MAAMC,UAAUX,QAAS;gBAC5B,IAAIW,OAAO1C,UAAU,CAACwC,QAAQD,MAAM,GAAG;oBACrC,IAAI,CAACpC,OAAOb,QAAQ,CAACoD,SAAS;wBAC5BvC,OAAOgB,IAAI,CAACuB;oBACd;gBACF;YACF;QACF;IACF;IAEA,OAAOvC;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"getSelect.d.ts","sourceRoot":"","sources":["../../src/utilities/getSelect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,WAAY,MAAM,EAAE,KAAG,iBAoB5C,CAAA"}
1
+ {"version":3,"file":"getSelect.d.ts","sourceRoot":"","sources":["../../src/utilities/getSelect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAOhD;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,WAAY,MAAM,EAAE,KAAG,iBAyB5C,CAAA"}
@@ -1,3 +1,6 @@
1
+ import { APIError } from 'payload';
2
+ import { hasUnsupportedFieldPathSegment } from 'payload/shared';
3
+ const createSelect = ()=>Object.create(null);
1
4
  /**
2
5
  * Takes an input of array of string paths in dot notation and returns a select object.
3
6
  * Used for both export and import to build Payload's select query format.
@@ -6,16 +9,21 @@
6
9
  * getSelect(['id', 'title', 'group.value', 'createdAt', 'updatedAt'])
7
10
  * // Returns: { id: true, title: true, group: { value: true }, createdAt: true, updatedAt: true }
8
11
  */ export const getSelect = (fields)=>{
9
- const select = {};
12
+ const select = createSelect();
10
13
  fields.forEach((field)=>{
11
14
  const segments = field.split('.');
15
+ if (hasUnsupportedFieldPathSegment({
16
+ segments
17
+ })) {
18
+ throw new APIError('Invalid field path.', 400, null, true);
19
+ }
12
20
  let selectRef = select;
13
21
  segments.forEach((segment, i)=>{
14
22
  if (i === segments.length - 1) {
15
23
  selectRef[segment] = true;
16
24
  } else {
17
- if (!selectRef[segment]) {
18
- selectRef[segment] = {};
25
+ if (!Object.prototype.hasOwnProperty.call(selectRef, segment)) {
26
+ selectRef[segment] = createSelect();
19
27
  }
20
28
  selectRef = selectRef[segment];
21
29
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/getSelect.ts"],"sourcesContent":["import type { SelectIncludeType } from 'payload'\n\n/**\n * Takes an input of array of string paths in dot notation and returns a select object.\n * Used for both export and import to build Payload's select query format.\n *\n * @example\n * getSelect(['id', 'title', 'group.value', 'createdAt', 'updatedAt'])\n * // Returns: { id: true, title: true, group: { value: true }, createdAt: true, updatedAt: true }\n */\nexport const getSelect = (fields: string[]): SelectIncludeType => {\n const select: SelectIncludeType = {}\n\n fields.forEach((field) => {\n const segments = field.split('.')\n let selectRef = select\n\n segments.forEach((segment, i) => {\n if (i === segments.length - 1) {\n selectRef[segment] = true\n } else {\n if (!selectRef[segment]) {\n selectRef[segment] = {}\n }\n selectRef = selectRef[segment] as SelectIncludeType\n }\n })\n })\n\n return select\n}\n"],"names":["getSelect","fields","select","forEach","field","segments","split","selectRef","segment","i","length"],"mappings":"AAEA;;;;;;;CAOC,GACD,OAAO,MAAMA,YAAY,CAACC;IACxB,MAAMC,SAA4B,CAAC;IAEnCD,OAAOE,OAAO,CAAC,CAACC;QACd,MAAMC,WAAWD,MAAME,KAAK,CAAC;QAC7B,IAAIC,YAAYL;QAEhBG,SAASF,OAAO,CAAC,CAACK,SAASC;YACzB,IAAIA,MAAMJ,SAASK,MAAM,GAAG,GAAG;gBAC7BH,SAAS,CAACC,QAAQ,GAAG;YACvB,OAAO;gBACL,IAAI,CAACD,SAAS,CAACC,QAAQ,EAAE;oBACvBD,SAAS,CAACC,QAAQ,GAAG,CAAC;gBACxB;gBACAD,YAAYA,SAAS,CAACC,QAAQ;YAChC;QACF;IACF;IAEA,OAAON;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/getSelect.ts"],"sourcesContent":["import type { SelectIncludeType } from 'payload'\n\nimport { APIError } from 'payload'\nimport { hasUnsupportedFieldPathSegment } from 'payload/shared'\n\nconst createSelect = (): SelectIncludeType => Object.create(null) as SelectIncludeType\n\n/**\n * Takes an input of array of string paths in dot notation and returns a select object.\n * Used for both export and import to build Payload's select query format.\n *\n * @example\n * getSelect(['id', 'title', 'group.value', 'createdAt', 'updatedAt'])\n * // Returns: { id: true, title: true, group: { value: true }, createdAt: true, updatedAt: true }\n */\nexport const getSelect = (fields: string[]): SelectIncludeType => {\n const select = createSelect()\n\n fields.forEach((field) => {\n const segments = field.split('.')\n\n if (hasUnsupportedFieldPathSegment({ segments })) {\n throw new APIError('Invalid field path.', 400, null, true)\n }\n\n let selectRef = select\n\n segments.forEach((segment, i) => {\n if (i === segments.length - 1) {\n selectRef[segment] = true\n } else {\n if (!Object.prototype.hasOwnProperty.call(selectRef, segment)) {\n selectRef[segment] = createSelect()\n }\n selectRef = selectRef[segment] as SelectIncludeType\n }\n })\n })\n\n return select\n}\n"],"names":["APIError","hasUnsupportedFieldPathSegment","createSelect","Object","create","getSelect","fields","select","forEach","field","segments","split","selectRef","segment","i","length","prototype","hasOwnProperty","call"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAClC,SAASC,8BAA8B,QAAQ,iBAAgB;AAE/D,MAAMC,eAAe,IAAyBC,OAAOC,MAAM,CAAC;AAE5D;;;;;;;CAOC,GACD,OAAO,MAAMC,YAAY,CAACC;IACxB,MAAMC,SAASL;IAEfI,OAAOE,OAAO,CAAC,CAACC;QACd,MAAMC,WAAWD,MAAME,KAAK,CAAC;QAE7B,IAAIV,+BAA+B;YAAES;QAAS,IAAI;YAChD,MAAM,IAAIV,SAAS,uBAAuB,KAAK,MAAM;QACvD;QAEA,IAAIY,YAAYL;QAEhBG,SAASF,OAAO,CAAC,CAACK,SAASC;YACzB,IAAIA,MAAMJ,SAASK,MAAM,GAAG,GAAG;gBAC7BH,SAAS,CAACC,QAAQ,GAAG;YACvB,OAAO;gBACL,IAAI,CAACV,OAAOa,SAAS,CAACC,cAAc,CAACC,IAAI,CAACN,WAAWC,UAAU;oBAC7DD,SAAS,CAACC,QAAQ,GAAGX;gBACvB;gBACAU,YAAYA,SAAS,CAACC,QAAQ;YAChC;QACF;IACF;IAEA,OAAON;AACT,EAAC"}
@@ -0,0 +1,12 @@
1
+ export declare const getSubmittedFormValues: ({ formData, omit, }: {
2
+ formData: Record<string, unknown>;
3
+ omit?: string[];
4
+ }) => Record<string, unknown>;
5
+ /** Tracks value changes, including nested custom fields, without depending on field state identity. */
6
+ export declare const getFormStateSignature: ({ fields, omit, }: {
7
+ fields: Record<string, {
8
+ value?: unknown;
9
+ } | undefined>;
10
+ omit?: string[];
11
+ }) => string;
12
+ //# sourceMappingURL=getSubmittedFormValues.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSubmittedFormValues.d.ts","sourceRoot":"","sources":["../../src/utilities/getSubmittedFormValues.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,sBAAsB,wBAGhC;IACD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAIzB,CAAA;AAED,uGAAuG;AACvG,eAAO,MAAM,qBAAqB,sBAG/B;IACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS,CAAC,CAAA;IACvD,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB,KAAG,MAQH,CAAA"}
@@ -0,0 +1,24 @@
1
+ /** Unsaved form values must not appear to come from a saved document. */ const serverOwnedFormKeys = new Set([
2
+ 'createdAt',
3
+ 'id',
4
+ 'updatedAt'
5
+ ]);
6
+ export const getSubmittedFormValues = ({ formData, omit = [] })=>{
7
+ const omitKeys = new Set([
8
+ ...omit,
9
+ ...serverOwnedFormKeys
10
+ ]);
11
+ return Object.fromEntries(Object.entries(formData).filter(([key])=>!omitKeys.has(key)));
12
+ };
13
+ /** Tracks value changes, including nested custom fields, without depending on field state identity. */ export const getFormStateSignature = ({ fields, omit = [] })=>{
14
+ const omitKeys = new Set([
15
+ ...omit,
16
+ ...serverOwnedFormKeys
17
+ ]);
18
+ return JSON.stringify(Object.entries(fields).filter(([path])=>!omitKeys.has(path)).map(([path, field])=>[
19
+ path,
20
+ field?.value
21
+ ]));
22
+ };
23
+
24
+ //# sourceMappingURL=getSubmittedFormValues.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/getSubmittedFormValues.ts"],"sourcesContent":["/** Unsaved form values must not appear to come from a saved document. */\nconst serverOwnedFormKeys = new Set(['createdAt', 'id', 'updatedAt'])\n\nexport const getSubmittedFormValues = ({\n formData,\n omit = [],\n}: {\n formData: Record<string, unknown>\n omit?: string[]\n}): Record<string, unknown> => {\n const omitKeys = new Set([...omit, ...serverOwnedFormKeys])\n\n return Object.fromEntries(Object.entries(formData).filter(([key]) => !omitKeys.has(key)))\n}\n\n/** Tracks value changes, including nested custom fields, without depending on field state identity. */\nexport const getFormStateSignature = ({\n fields,\n omit = [],\n}: {\n fields: Record<string, { value?: unknown } | undefined>\n omit?: string[]\n}): string => {\n const omitKeys = new Set([...omit, ...serverOwnedFormKeys])\n\n return JSON.stringify(\n Object.entries(fields)\n .filter(([path]) => !omitKeys.has(path))\n .map(([path, field]) => [path, field?.value]),\n )\n}\n"],"names":["serverOwnedFormKeys","Set","getSubmittedFormValues","formData","omit","omitKeys","Object","fromEntries","entries","filter","key","has","getFormStateSignature","fields","JSON","stringify","path","map","field","value"],"mappings":"AAAA,uEAAuE,GACvE,MAAMA,sBAAsB,IAAIC,IAAI;IAAC;IAAa;IAAM;CAAY;AAEpE,OAAO,MAAMC,yBAAyB,CAAC,EACrCC,QAAQ,EACRC,OAAO,EAAE,EAIV;IACC,MAAMC,WAAW,IAAIJ,IAAI;WAAIG;WAASJ;KAAoB;IAE1D,OAAOM,OAAOC,WAAW,CAACD,OAAOE,OAAO,CAACL,UAAUM,MAAM,CAAC,CAAC,CAACC,IAAI,GAAK,CAACL,SAASM,GAAG,CAACD;AACrF,EAAC;AAED,qGAAqG,GACrG,OAAO,MAAME,wBAAwB,CAAC,EACpCC,MAAM,EACNT,OAAO,EAAE,EAIV;IACC,MAAMC,WAAW,IAAIJ,IAAI;WAAIG;WAASJ;KAAoB;IAE1D,OAAOc,KAAKC,SAAS,CACnBT,OAAOE,OAAO,CAACK,QACZJ,MAAM,CAAC,CAAC,CAACO,KAAK,GAAK,CAACX,SAASM,GAAG,CAACK,OACjCC,GAAG,CAAC,CAAC,CAACD,MAAME,MAAM,GAAK;YAACF;YAAME,OAAOC;SAAM;AAElD,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"processRichTextField.d.ts","sourceRoot":"","sources":["../../src/utilities/processRichTextField.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,UAAW,OAAO,KAAG,OA4CrD,CAAA"}
1
+ {"version":3,"file":"processRichTextField.d.ts","sourceRoot":"","sources":["../../src/utilities/processRichTextField.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,UAAW,OAAO,KAAG,OAoDrD,CAAA"}
@@ -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"}
@@ -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,QACpB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QACtB,MAAM,SACL,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":"AAAA,SAASA,QAAQ,QAAQ,UAAS;AAClC,SAASC,8BAA8B,EAAEC,cAAc,QAAQ,iBAAgB;AAE/E,MAAMC,kCAAkC;AAExC,MAAMC,eAAe,IAA+BC,OAAOC,MAAM,CAAC;AAElE,MAAMC,eAAe,CAACC;IACpB,IAAI,CAAC,mBAAmBC,IAAI,CAACD,OAAO;QAClC,OAAO;IACT;IAEA,MAAME,QAAQC,OAAOH;IAErB,OAAOG,OAAOC,aAAa,CAACF,UAAUA,SAAS;AACjD;AAEA,MAAMG,aAAa,CACjBC,QACAN,MACAO;IAEA,IAAI,CAACC,MAAMC,OAAO,CAACH,WAAW,CAACP,aAAaC,OAAO;QACjD,OAAOA;IACT;IAEA,MAAME,QAAQC,OAAOH;IAErB,IACE,AAACQ,MAAMC,OAAO,CAACF,WAAWL,SAASK,OAAOG,MAAM,IAC/C,CAACF,MAAMC,OAAO,CAACF,WAAWL,QAAQI,OAAOI,MAAM,GAAGf,iCACnD;QACA,MAAM,IAAIH,SAAS,uBAAuB,KAAK,MAAM;IACvD;IAEA,OAAOU;AACT;AAEA,MAAMS,iBAAiB,CAACJ,QAAiBP;IACvC,IAAIO,WAAW,QAAQ,OAAOA,WAAW,UAAU;QACjD,OAAOK;IACT;IAEA,MAAMC,MAAML,MAAMC,OAAO,CAACF,WAAWR,aAAaC,QAAQG,OAAOH,QAAQA;IAEzE,IAAI,CAACH,OAAOiB,MAAM,CAACP,QAAQM,MAAM;QAC/B,OAAOD;IACT;IAEA,OAAO,AAACL,MAA2C,CAACM,IAAI;AAC1D;AAEA;;;;;;;;;;;;;;;;;CAiBC,GAED,OAAO,MAAME,iBAAiB,CAC5BC,KACAC,MACAC,OACAX;IAEA,MAAMY,QAAQF,KAAKG,KAAK,CAAC;IAEzB,IAAI3B,+BAA+B;QAAE4B,UAAUF;IAAM,IAAI;QACvD,MAAM,IAAI3B,SAAS,uBAAuB,KAAK,MAAM;IACvD;IAEA,MAAM8B,WAAWH,MAAMI,GAAG;IAE1B,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":"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,qDAMzB,aAAa,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAkUxC,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);
@@ -103,22 +108,14 @@ const collectArrayLikeNames = (fields, into)=>{
103
108
  const importHookEntry = importFieldHooks[flatKey] ?? importFieldHooks[toLogicalKey(flatKey, arrayLikeNames)];
104
109
  if (importHookEntry) {
105
110
  try {
106
- if (importHookEntry.type === 'beforeImport') {
107
- value = importHookEntry.fn({
108
- columnName: flatKey,
109
- data,
110
- format,
111
- siblingData: data,
112
- siblingDoc: data,
113
- value
114
- });
115
- } else {
116
- value = importHookEntry.fn({
117
- columnName: flatKey,
118
- data,
119
- value
120
- });
121
- }
111
+ value = importHookEntry.fn({
112
+ columnName: flatKey,
113
+ data,
114
+ format,
115
+ siblingData: data,
116
+ siblingDoc: data,
117
+ value
118
+ });
122
119
  } catch (error) {
123
120
  req.payload.logger.error({
124
121
  err: error,
@@ -238,7 +235,9 @@ const collectArrayLikeNames = (fields, into)=>{
238
235
  blockObject[blockFieldName] = value;
239
236
  } else {
240
237
  if (!blockObject[blockFieldName] || typeof blockObject[blockFieldName] !== 'object') {
241
- blockObject[blockFieldName] = {};
238
+ const segmentAfterBlockField = pathSegments[i + 4];
239
+ const blockFieldIsArray = segmentAfterBlockField !== undefined && indexSegment.test(segmentAfterBlockField);
240
+ blockObject[blockFieldName] = blockFieldIsArray ? [] : {};
242
241
  }
243
242
  currentObject = blockObject[blockFieldName];
244
243
  i = i + 3;
@@ -262,6 +261,18 @@ const collectArrayLikeNames = (fields, into)=>{
262
261
  currentObject = arr[arrayIndex];
263
262
  i++;
264
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];
265
276
  } else {
266
277
  // Skip if already set to null (polymorphic relationship already processed)
267
278
  if (currentObject[segment] === null && isLast && segment === 'relationTo') {