@payloadcms/plugin-import-export 4.0.0-internal.e55ccef → 4.0.0-internal.ea6e8f8

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 (141) 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 +0 -3
  8. package/dist/components/ExportPreview/index.d.ts.map +1 -1
  9. package/dist/components/ExportPreview/index.js +11 -1
  10. package/dist/components/ExportPreview/index.js.map +1 -1
  11. package/dist/components/FieldsToExport/index.d.ts +3 -2
  12. package/dist/components/FieldsToExport/index.d.ts.map +1 -1
  13. package/dist/components/FieldsToExport/index.js +18 -15
  14. package/dist/components/FieldsToExport/index.js.map +1 -1
  15. package/dist/components/FieldsToExport/reduceFields.d.ts +6 -0
  16. package/dist/components/FieldsToExport/reduceFields.d.ts.map +1 -1
  17. package/dist/components/FieldsToExport/reduceFields.js +4 -0
  18. package/dist/components/FieldsToExport/reduceFields.js.map +1 -1
  19. package/dist/components/FormatField/index.d.ts +3 -2
  20. package/dist/components/FormatField/index.d.ts.map +1 -1
  21. package/dist/components/FormatField/index.js.map +1 -1
  22. package/dist/components/ImportListMenuItem/index.d.ts.map +1 -1
  23. package/dist/components/ImportListMenuItem/index.js +14 -12
  24. package/dist/components/ImportListMenuItem/index.js.map +1 -1
  25. package/dist/components/ImportPreview/index.css +0 -3
  26. package/dist/components/ImportPreview/index.d.ts.map +1 -1
  27. package/dist/components/ImportPreview/index.js +27 -8
  28. package/dist/components/ImportPreview/index.js.map +1 -1
  29. package/dist/components/LimitField/index.d.ts +3 -2
  30. package/dist/components/LimitField/index.d.ts.map +1 -1
  31. package/dist/components/LimitField/index.js.map +1 -1
  32. package/dist/components/LocaleField/index.d.ts +3 -2
  33. package/dist/components/LocaleField/index.d.ts.map +1 -1
  34. package/dist/components/LocaleField/index.js.map +1 -1
  35. package/dist/components/Page/index.d.ts +3 -2
  36. package/dist/components/Page/index.d.ts.map +1 -1
  37. package/dist/components/Page/index.js.map +1 -1
  38. package/dist/components/RelationshipCell/getRelationshipGroupKey.d.ts +7 -0
  39. package/dist/components/RelationshipCell/getRelationshipGroupKey.d.ts.map +1 -0
  40. package/dist/components/RelationshipCell/getRelationshipGroupKey.js +3 -0
  41. package/dist/components/RelationshipCell/getRelationshipGroupKey.js.map +1 -0
  42. package/dist/components/RelationshipCell/getRelationshipGroups.d.ts +43 -0
  43. package/dist/components/RelationshipCell/getRelationshipGroups.d.ts.map +1 -0
  44. package/dist/components/RelationshipCell/getRelationshipGroups.js +109 -0
  45. package/dist/components/RelationshipCell/getRelationshipGroups.js.map +1 -0
  46. package/dist/components/RelationshipCell/index.css +30 -0
  47. package/dist/components/RelationshipCell/index.d.ts +15 -0
  48. package/dist/components/RelationshipCell/index.d.ts.map +1 -0
  49. package/dist/components/RelationshipCell/index.js +57 -0
  50. package/dist/components/RelationshipCell/index.js.map +1 -0
  51. package/dist/components/SortBy/index.d.ts +3 -2
  52. package/dist/components/SortBy/index.d.ts.map +1 -1
  53. package/dist/components/SortBy/index.js.map +1 -1
  54. package/dist/components/SortOrder/index.d.ts +3 -2
  55. package/dist/components/SortOrder/index.d.ts.map +1 -1
  56. package/dist/components/SortOrder/index.js.map +1 -1
  57. package/dist/export/batchProcessor.d.ts +2 -1
  58. package/dist/export/batchProcessor.d.ts.map +1 -1
  59. package/dist/export/batchProcessor.js +6 -2
  60. package/dist/export/batchProcessor.js.map +1 -1
  61. package/dist/export/createExport.d.ts +2 -0
  62. package/dist/export/createExport.d.ts.map +1 -1
  63. package/dist/export/createExport.js +6 -1
  64. package/dist/export/createExport.js.map +1 -1
  65. package/dist/export/getCreateExportCollectionTask.d.ts.map +1 -1
  66. package/dist/export/getCreateExportCollectionTask.js +11 -0
  67. package/dist/export/getCreateExportCollectionTask.js.map +1 -1
  68. package/dist/export/getExportCollection.d.ts.map +1 -1
  69. package/dist/export/getExportCollection.js +5 -0
  70. package/dist/export/getExportCollection.js.map +1 -1
  71. package/dist/export/handleDownload.d.ts.map +1 -1
  72. package/dist/export/handleDownload.js +7 -3
  73. package/dist/export/handleDownload.js.map +1 -1
  74. package/dist/export/handlePreview.d.ts.map +1 -1
  75. package/dist/export/handlePreview.js +24 -5
  76. package/dist/export/handlePreview.js.map +1 -1
  77. package/dist/exports/types.d.ts +1 -1
  78. package/dist/exports/types.d.ts.map +1 -1
  79. package/dist/exports/types.js.map +1 -1
  80. package/dist/import/batchProcessor.d.ts +2 -1
  81. package/dist/import/batchProcessor.d.ts.map +1 -1
  82. package/dist/import/batchProcessor.js +15 -8
  83. package/dist/import/batchProcessor.js.map +1 -1
  84. package/dist/import/createImport.d.ts +3 -2
  85. package/dist/import/createImport.d.ts.map +1 -1
  86. package/dist/import/createImport.js +8 -1
  87. package/dist/import/createImport.js.map +1 -1
  88. package/dist/import/getCreateImportCollectionTask.d.ts.map +1 -1
  89. package/dist/import/getCreateImportCollectionTask.js +5 -2
  90. package/dist/import/getCreateImportCollectionTask.js.map +1 -1
  91. package/dist/import/getImportCollection.d.ts.map +1 -1
  92. package/dist/import/getImportCollection.js +2 -0
  93. package/dist/import/getImportCollection.js.map +1 -1
  94. package/dist/import/handlePreview.d.ts.map +1 -1
  95. package/dist/import/handlePreview.js +5 -1
  96. package/dist/import/handlePreview.js.map +1 -1
  97. package/dist/types.d.ts +17 -1
  98. package/dist/types.d.ts.map +1 -1
  99. package/dist/types.js.map +1 -1
  100. package/dist/utilities/getExportFieldFunctions.js +64 -27
  101. package/dist/utilities/getExportFieldFunctions.js.map +1 -1
  102. package/dist/utilities/getFileFromDoc.js +3 -3
  103. package/dist/utilities/getFileFromDoc.js.map +1 -1
  104. package/dist/utilities/getSelect.d.ts.map +1 -1
  105. package/dist/utilities/getSelect.js +11 -3
  106. package/dist/utilities/getSelect.js.map +1 -1
  107. package/dist/utilities/getSubmittedFormValues.d.ts +12 -0
  108. package/dist/utilities/getSubmittedFormValues.d.ts.map +1 -0
  109. package/dist/utilities/getSubmittedFormValues.js +24 -0
  110. package/dist/utilities/getSubmittedFormValues.js.map +1 -0
  111. package/dist/utilities/setNestedValue.d.ts +2 -1
  112. package/dist/utilities/setNestedValue.d.ts.map +1 -1
  113. package/dist/utilities/setNestedValue.js +65 -34
  114. package/dist/utilities/setNestedValue.js.map +1 -1
  115. package/package.json +9 -9
  116. package/dist/components/FieldsToExport/reduceFields.spec.js +0 -239
  117. package/dist/components/FieldsToExport/reduceFields.spec.js.map +0 -1
  118. package/dist/utilities/applyFieldHooks.spec.js +0 -205
  119. package/dist/utilities/applyFieldHooks.spec.js.map +0 -1
  120. package/dist/utilities/buildDisabledFieldRegex.spec.js +0 -64
  121. package/dist/utilities/buildDisabledFieldRegex.spec.js.map +0 -1
  122. package/dist/utilities/fieldToRegex.spec.js +0 -151
  123. package/dist/utilities/fieldToRegex.spec.js.map +0 -1
  124. package/dist/utilities/filterToSelectedFields.spec.js +0 -204
  125. package/dist/utilities/filterToSelectedFields.spec.js.map +0 -1
  126. package/dist/utilities/flattenObject.spec.js +0 -158
  127. package/dist/utilities/flattenObject.spec.js.map +0 -1
  128. package/dist/utilities/getExportFieldFunctions.spec.js +0 -50
  129. package/dist/utilities/getExportFieldFunctions.spec.js.map +0 -1
  130. package/dist/utilities/getImportFieldFunctions.spec.js +0 -167
  131. package/dist/utilities/getImportFieldFunctions.spec.js.map +0 -1
  132. package/dist/utilities/getSchemaColumns.spec.js +0 -157
  133. package/dist/utilities/getSchemaColumns.spec.js.map +0 -1
  134. package/dist/utilities/parseCSV.spec.js +0 -195
  135. package/dist/utilities/parseCSV.spec.js.map +0 -1
  136. package/dist/utilities/processRichTextField.spec.js +0 -308
  137. package/dist/utilities/processRichTextField.spec.js.map +0 -1
  138. package/dist/utilities/siblingDoc.spec.js +0 -278
  139. package/dist/utilities/siblingDoc.spec.js.map +0 -1
  140. package/dist/utilities/unflattenObject.spec.js +0 -819
  141. package/dist/utilities/unflattenObject.spec.js.map +0 -1
@@ -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,QA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
3
- "version": "4.0.0-internal.e55ccef",
3
+ "version": "4.0.0-internal.ea6e8f8",
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.1",
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.e55ccef",
68
- "@payloadcms/ui": "4.0.0-internal.e55ccef"
67
+ "@payloadcms/translations": "4.0.0-internal.ea6e8f8",
68
+ "@payloadcms/ui": "4.0.0-internal.ea6e8f8"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@payloadcms/eslint-config": "3.28.0",
72
- "payload": "4.0.0-internal.e55ccef",
73
- "@payloadcms/ui": "4.0.0-internal.e55ccef"
72
+ "payload": "4.0.0-internal.ea6e8f8",
73
+ "@payloadcms/ui": "4.0.0-internal.ea6e8f8"
74
74
  },
75
75
  "peerDependencies": {
76
- "payload": "4.0.0-internal.e55ccef",
77
- "@payloadcms/ui": "4.0.0-internal.e55ccef"
76
+ "@payloadcms/ui": "4.0.0-internal.ea6e8f8",
77
+ "payload": "4.0.0-internal.ea6e8f8"
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
  }
@@ -1,239 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { reduceFields } from './reduceFields.js';
3
- const values = (result)=>result.map((f)=>f.value);
4
- describe('reduceFields', ()=>{
5
- describe('excludeUnsortable', ()=>{
6
- it('should include array and blocks fields by default', ()=>{
7
- const fields = [
8
- {
9
- name: 'title',
10
- type: 'text'
11
- },
12
- {
13
- name: 'items',
14
- type: 'array',
15
- fields: [
16
- {
17
- name: 'text',
18
- type: 'text'
19
- }
20
- ]
21
- },
22
- {
23
- name: 'layout',
24
- type: 'blocks',
25
- blocks: []
26
- }
27
- ];
28
- const result = values(reduceFields({
29
- fields
30
- }));
31
- expect(result).toContain('title');
32
- expect(result).toContain('items');
33
- expect(result).toContain('layout');
34
- });
35
- it('should exclude array fields when excludeUnsortable is true', ()=>{
36
- const fields = [
37
- {
38
- name: 'title',
39
- type: 'text'
40
- },
41
- {
42
- name: 'items',
43
- type: 'array',
44
- fields: [
45
- {
46
- name: 'text',
47
- type: 'text'
48
- }
49
- ]
50
- }
51
- ];
52
- const result = values(reduceFields({
53
- excludeUnsortable: true,
54
- fields
55
- }));
56
- expect(result).toContain('title');
57
- expect(result).not.toContain('items');
58
- });
59
- it('should exclude blocks fields when excludeUnsortable is true', ()=>{
60
- const fields = [
61
- {
62
- name: 'title',
63
- type: 'text'
64
- },
65
- {
66
- name: 'layout',
67
- type: 'blocks',
68
- blocks: []
69
- }
70
- ];
71
- const result = values(reduceFields({
72
- excludeUnsortable: true,
73
- fields
74
- }));
75
- expect(result).toContain('title');
76
- expect(result).not.toContain('layout');
77
- });
78
- });
79
- describe('disabledFields', ()=>{
80
- it('should include all fields when disabledFields is empty', ()=>{
81
- const fields = [
82
- {
83
- name: 'title',
84
- type: 'text'
85
- },
86
- {
87
- name: 'slug',
88
- type: 'text'
89
- }
90
- ];
91
- const result = values(reduceFields({
92
- disabledFields: [],
93
- fields
94
- }));
95
- expect(result).toContain('title');
96
- expect(result).toContain('slug');
97
- });
98
- it('should exclude a field whose path is in disabledFields', ()=>{
99
- const fields = [
100
- {
101
- name: 'title',
102
- type: 'text'
103
- },
104
- {
105
- name: 'slug',
106
- type: 'text'
107
- }
108
- ];
109
- const result = values(reduceFields({
110
- disabledFields: [
111
- 'slug'
112
- ],
113
- fields
114
- }));
115
- expect(result).toContain('title');
116
- expect(result).not.toContain('slug');
117
- });
118
- it('should exclude nested fields whose paths start with a disabled parent path', ()=>{
119
- const fields = [
120
- {
121
- name: 'meta',
122
- type: 'group',
123
- fields: [
124
- {
125
- name: 'title',
126
- type: 'text'
127
- },
128
- {
129
- name: 'description',
130
- type: 'text'
131
- }
132
- ]
133
- }
134
- ];
135
- const result = values(reduceFields({
136
- disabledFields: [
137
- 'meta.description'
138
- ],
139
- fields
140
- }));
141
- expect(result).toContain('meta.title');
142
- expect(result).not.toContain('meta.description');
143
- });
144
- });
145
- describe('combined excludeUnsortable and disabledFields', ()=>{
146
- it('should apply both filters simultaneously', ()=>{
147
- const fields = [
148
- {
149
- name: 'title',
150
- type: 'text'
151
- },
152
- {
153
- name: 'slug',
154
- type: 'text'
155
- },
156
- {
157
- name: 'items',
158
- type: 'array',
159
- fields: [
160
- {
161
- name: 'text',
162
- type: 'text'
163
- }
164
- ]
165
- }
166
- ];
167
- const result = values(reduceFields({
168
- disabledFields: [
169
- 'slug'
170
- ],
171
- excludeUnsortable: true,
172
- fields
173
- }));
174
- expect(result).toContain('title');
175
- expect(result).not.toContain('slug');
176
- expect(result).not.toContain('items');
177
- });
178
- });
179
- describe('recursive propagation through group sub-fields', ()=>{
180
- it('should propagate excludeUnsortable into group sub-fields', ()=>{
181
- const fields = [
182
- {
183
- name: 'meta',
184
- type: 'group',
185
- fields: [
186
- {
187
- name: 'title',
188
- type: 'text'
189
- },
190
- {
191
- name: 'tags',
192
- type: 'array',
193
- fields: [
194
- {
195
- name: 'tag',
196
- type: 'text'
197
- }
198
- ]
199
- }
200
- ]
201
- }
202
- ];
203
- const result = values(reduceFields({
204
- excludeUnsortable: true,
205
- fields
206
- }));
207
- expect(result).toContain('meta.title');
208
- expect(result).not.toContain('meta.tags');
209
- });
210
- it('should propagate disabledFields into group sub-fields', ()=>{
211
- const fields = [
212
- {
213
- name: 'meta',
214
- type: 'group',
215
- fields: [
216
- {
217
- name: 'title',
218
- type: 'text'
219
- },
220
- {
221
- name: 'description',
222
- type: 'text'
223
- }
224
- ]
225
- }
226
- ];
227
- const result = values(reduceFields({
228
- disabledFields: [
229
- 'meta.description'
230
- ],
231
- fields
232
- }));
233
- expect(result).toContain('meta.title');
234
- expect(result).not.toContain('meta.description');
235
- });
236
- });
237
- });
238
-
239
- //# sourceMappingURL=reduceFields.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/components/FieldsToExport/reduceFields.spec.ts"],"sourcesContent":["import type { ClientField } from 'payload'\n\nimport { describe, expect, it } from 'vitest'\n\nimport { reduceFields } from './reduceFields.js'\n\nconst values = (result: ReturnType<typeof reduceFields>) => result.map((f) => f.value)\n\ndescribe('reduceFields', () => {\n describe('excludeUnsortable', () => {\n it('should include array and blocks fields by default', () => {\n const fields: ClientField[] = [\n { name: 'title', type: 'text' },\n { name: 'items', type: 'array', fields: [{ name: 'text', type: 'text' }] },\n { name: 'layout', type: 'blocks', blocks: [] },\n ]\n\n const result = values(reduceFields({ fields }))\n\n expect(result).toContain('title')\n expect(result).toContain('items')\n expect(result).toContain('layout')\n })\n\n it('should exclude array fields when excludeUnsortable is true', () => {\n const fields: ClientField[] = [\n { name: 'title', type: 'text' },\n { name: 'items', type: 'array', fields: [{ name: 'text', type: 'text' }] },\n ]\n\n const result = values(reduceFields({ excludeUnsortable: true, fields }))\n\n expect(result).toContain('title')\n expect(result).not.toContain('items')\n })\n\n it('should exclude blocks fields when excludeUnsortable is true', () => {\n const fields: ClientField[] = [\n { name: 'title', type: 'text' },\n { name: 'layout', type: 'blocks', blocks: [] },\n ]\n\n const result = values(reduceFields({ excludeUnsortable: true, fields }))\n\n expect(result).toContain('title')\n expect(result).not.toContain('layout')\n })\n })\n\n describe('disabledFields', () => {\n it('should include all fields when disabledFields is empty', () => {\n const fields: ClientField[] = [\n { name: 'title', type: 'text' },\n { name: 'slug', type: 'text' },\n ]\n\n const result = values(reduceFields({ disabledFields: [], fields }))\n\n expect(result).toContain('title')\n expect(result).toContain('slug')\n })\n\n it('should exclude a field whose path is in disabledFields', () => {\n const fields: ClientField[] = [\n { name: 'title', type: 'text' },\n { name: 'slug', type: 'text' },\n ]\n\n const result = values(reduceFields({ disabledFields: ['slug'], fields }))\n\n expect(result).toContain('title')\n expect(result).not.toContain('slug')\n })\n\n it('should exclude nested fields whose paths start with a disabled parent path', () => {\n const fields: ClientField[] = [\n {\n name: 'meta',\n type: 'group',\n fields: [\n { name: 'title', type: 'text' },\n { name: 'description', type: 'text' },\n ],\n },\n ]\n\n const result = values(reduceFields({ disabledFields: ['meta.description'], fields }))\n\n expect(result).toContain('meta.title')\n expect(result).not.toContain('meta.description')\n })\n })\n\n describe('combined excludeUnsortable and disabledFields', () => {\n it('should apply both filters simultaneously', () => {\n const fields: ClientField[] = [\n { name: 'title', type: 'text' },\n { name: 'slug', type: 'text' },\n { name: 'items', type: 'array', fields: [{ name: 'text', type: 'text' }] },\n ]\n\n const result = values(\n reduceFields({ disabledFields: ['slug'], excludeUnsortable: true, fields }),\n )\n\n expect(result).toContain('title')\n expect(result).not.toContain('slug')\n expect(result).not.toContain('items')\n })\n })\n\n describe('recursive propagation through group sub-fields', () => {\n it('should propagate excludeUnsortable into group sub-fields', () => {\n const fields: ClientField[] = [\n {\n name: 'meta',\n type: 'group',\n fields: [\n { name: 'title', type: 'text' },\n { name: 'tags', type: 'array', fields: [{ name: 'tag', type: 'text' }] },\n ],\n },\n ]\n\n const result = values(reduceFields({ excludeUnsortable: true, fields }))\n\n expect(result).toContain('meta.title')\n expect(result).not.toContain('meta.tags')\n })\n\n it('should propagate disabledFields into group sub-fields', () => {\n const fields: ClientField[] = [\n {\n name: 'meta',\n type: 'group',\n fields: [\n { name: 'title', type: 'text' },\n { name: 'description', type: 'text' },\n ],\n },\n ]\n\n const result = values(reduceFields({ disabledFields: ['meta.description'], fields }))\n\n expect(result).toContain('meta.title')\n expect(result).not.toContain('meta.description')\n })\n })\n})\n"],"names":["describe","expect","it","reduceFields","values","result","map","f","value","fields","name","type","blocks","toContain","excludeUnsortable","not","disabledFields"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,MAAMC,SAAS,CAACC,SAA4CA,OAAOC,GAAG,CAAC,CAACC,IAAMA,EAAEC,KAAK;AAErFR,SAAS,gBAAgB;IACvBA,SAAS,qBAAqB;QAC5BE,GAAG,qDAAqD;YACtD,MAAMO,SAAwB;gBAC5B;oBAAEC,MAAM;oBAASC,MAAM;gBAAO;gBAC9B;oBAAED,MAAM;oBAASC,MAAM;oBAASF,QAAQ;wBAAC;4BAAEC,MAAM;4BAAQC,MAAM;wBAAO;qBAAE;gBAAC;gBACzE;oBAAED,MAAM;oBAAUC,MAAM;oBAAUC,QAAQ,EAAE;gBAAC;aAC9C;YAED,MAAMP,SAASD,OAAOD,aAAa;gBAAEM;YAAO;YAE5CR,OAAOI,QAAQQ,SAAS,CAAC;YACzBZ,OAAOI,QAAQQ,SAAS,CAAC;YACzBZ,OAAOI,QAAQQ,SAAS,CAAC;QAC3B;QAEAX,GAAG,8DAA8D;YAC/D,MAAMO,SAAwB;gBAC5B;oBAAEC,MAAM;oBAASC,MAAM;gBAAO;gBAC9B;oBAAED,MAAM;oBAASC,MAAM;oBAASF,QAAQ;wBAAC;4BAAEC,MAAM;4BAAQC,MAAM;wBAAO;qBAAE;gBAAC;aAC1E;YAED,MAAMN,SAASD,OAAOD,aAAa;gBAAEW,mBAAmB;gBAAML;YAAO;YAErER,OAAOI,QAAQQ,SAAS,CAAC;YACzBZ,OAAOI,QAAQU,GAAG,CAACF,SAA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AEa,gBAAgB;oBAAC;iBAAmB;gBAAEP;YAAO;YAElFR,OAAOI,QAAQQ,SAAS,CAAC;YACzBZ,OAAOI,QAAQU,GAAG,CAACF,SAAS,CAAC;QAC/B;IACF;AACF"}
@@ -1,205 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
- import { applyFieldHooks } from './applyFieldHooks.js';
3
- const mockReq = {
4
- payload: {
5
- logger: {
6
- error: vi.fn()
7
- }
8
- }
9
- };
10
- describe('applyFieldHooks parent + child traversal', ()=>{
11
- it('should run a parent group hook and still run child field hooks against the transformed value (export)', ()=>{
12
- const fields = [
13
- {
14
- name: 'meta',
15
- type: 'group',
16
- flattenedFields: [
17
- {
18
- name: 'slug',
19
- type: 'text'
20
- }
21
- ]
22
- }
23
- ];
24
- const fieldHooks = {
25
- meta: {
26
- type: 'beforeExport',
27
- fn: ({ value })=>{
28
- const obj = value ?? {};
29
- return {
30
- ...obj,
31
- slug: `${obj.slug ?? ''}-from-parent`
32
- };
33
- }
34
- },
35
- meta_slug: {
36
- type: 'beforeExport',
37
- fn: ({ value })=>`${value}-from-child`
38
- }
39
- };
40
- const result = applyFieldHooks({
41
- type: 'beforeExport',
42
- data: {
43
- meta: {
44
- slug: 'raw'
45
- }
46
- },
47
- fieldHooks,
48
- fields,
49
- format: 'json',
50
- operation: 'export',
51
- req: mockReq
52
- });
53
- // Parent hook ran first ('raw' → 'raw-from-parent'), then child hook ran against
54
- // the transformed value ('raw-from-parent' → 'raw-from-parent-from-child').
55
- expect(result.meta).toEqual({
56
- slug: 'raw-from-parent-from-child'
57
- });
58
- });
59
- it('should run a parent group hook and still run child field hooks (import)', ()=>{
60
- const fields = [
61
- {
62
- name: 'meta',
63
- type: 'group',
64
- flattenedFields: [
65
- {
66
- name: 'slug',
67
- type: 'text'
68
- }
69
- ]
70
- }
71
- ];
72
- const fieldHooks = {
73
- meta: {
74
- type: 'beforeImport',
75
- fn: ({ value })=>{
76
- const obj = value ?? {};
77
- return {
78
- ...obj,
79
- slug: `${obj.slug ?? ''}-from-parent`
80
- };
81
- }
82
- },
83
- meta_slug: {
84
- type: 'beforeImport',
85
- fn: ({ value })=>`${value}-from-child`
86
- }
87
- };
88
- const result = applyFieldHooks({
89
- type: 'beforeImport',
90
- data: {
91
- meta: {
92
- slug: 'raw'
93
- }
94
- },
95
- fieldHooks,
96
- fields,
97
- format: 'json',
98
- operation: 'import',
99
- req: mockReq
100
- });
101
- expect(result.meta).toEqual({
102
- slug: 'raw-from-parent-from-child'
103
- });
104
- });
105
- it('should run a parent array hook then child hooks for each item', ()=>{
106
- const fields = [
107
- {
108
- name: 'items',
109
- type: 'array',
110
- flattenedFields: [
111
- {
112
- name: 'note',
113
- type: 'text'
114
- }
115
- ]
116
- }
117
- ];
118
- const fieldHooks = {
119
- items: {
120
- type: 'beforeExport',
121
- fn: ({ value })=>{
122
- if (!Array.isArray(value)) {
123
- return value;
124
- }
125
- return value.map((item)=>({
126
- ...item,
127
- note: `${item.note ?? ''}-parent`
128
- }));
129
- }
130
- },
131
- items_note: {
132
- type: 'beforeExport',
133
- fn: ({ value })=>`${value}-child`
134
- }
135
- };
136
- const result = applyFieldHooks({
137
- type: 'beforeExport',
138
- data: {
139
- items: [
140
- {
141
- note: 'a'
142
- },
143
- {
144
- note: 'b'
145
- }
146
- ]
147
- },
148
- fieldHooks,
149
- fields,
150
- format: 'json',
151
- operation: 'export',
152
- req: mockReq
153
- });
154
- expect(result.items).toEqual([
155
- {
156
- note: 'a-parent-child'
157
- },
158
- {
159
- note: 'b-parent-child'
160
- }
161
- ]);
162
- });
163
- it('should not recurse into children when the parent hook returns a primitive', ()=>{
164
- const fields = [
165
- {
166
- name: 'meta',
167
- type: 'group',
168
- flattenedFields: [
169
- {
170
- name: 'slug',
171
- type: 'text'
172
- }
173
- ]
174
- }
175
- ];
176
- const childFn = vi.fn(({ value })=>`${value}-from-child`);
177
- const fieldHooks = {
178
- meta: {
179
- type: 'beforeExport',
180
- fn: ()=>'serialized'
181
- },
182
- meta_slug: {
183
- type: 'beforeExport',
184
- fn: childFn
185
- }
186
- };
187
- const result = applyFieldHooks({
188
- type: 'beforeExport',
189
- data: {
190
- meta: {
191
- slug: 'raw'
192
- }
193
- },
194
- fieldHooks,
195
- fields,
196
- format: 'json',
197
- operation: 'export',
198
- req: mockReq
199
- });
200
- expect(result.meta).toBe('serialized');
201
- expect(childFn).not.toHaveBeenCalled();
202
- });
203
- });
204
-
205
- //# sourceMappingURL=applyFieldHooks.spec.js.map