@payloadcms/plugin-import-export 3.78.0-internal-debug.f663370 → 3.78.0-internal.5219978

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 (47) hide show
  1. package/dist/components/ExportSaveButton/index.d.ts.map +1 -1
  2. package/dist/components/ExportSaveButton/index.js +11 -6
  3. package/dist/components/ExportSaveButton/index.js.map +1 -1
  4. package/dist/components/FormatField/index.d.ts +3 -0
  5. package/dist/components/FormatField/index.d.ts.map +1 -0
  6. package/dist/components/FormatField/index.js +95 -0
  7. package/dist/components/FormatField/index.js.map +1 -0
  8. package/dist/export/createExport.d.ts.map +1 -1
  9. package/dist/export/createExport.js +44 -16
  10. package/dist/export/createExport.js.map +1 -1
  11. package/dist/export/getCreateExportCollectionTask.d.ts.map +1 -1
  12. package/dist/export/getCreateExportCollectionTask.js +105 -24
  13. package/dist/export/getCreateExportCollectionTask.js.map +1 -1
  14. package/dist/export/getExportCollection.d.ts.map +1 -1
  15. package/dist/export/getExportCollection.js +75 -66
  16. package/dist/export/getExportCollection.js.map +1 -1
  17. package/dist/export/getFields.d.ts.map +1 -1
  18. package/dist/export/getFields.js +4 -7
  19. package/dist/export/getFields.js.map +1 -1
  20. package/dist/exports/rsc.d.ts +1 -0
  21. package/dist/exports/rsc.d.ts.map +1 -1
  22. package/dist/exports/rsc.js +1 -0
  23. package/dist/exports/rsc.js.map +1 -1
  24. package/dist/import/batchProcessor.d.ts.map +1 -1
  25. package/dist/import/batchProcessor.js +11 -5
  26. package/dist/import/batchProcessor.js.map +1 -1
  27. package/dist/import/createImport.d.ts.map +1 -1
  28. package/dist/import/createImport.js +2 -1
  29. package/dist/import/createImport.js.map +1 -1
  30. package/dist/import/getImportCollection.d.ts.map +1 -1
  31. package/dist/import/getImportCollection.js +229 -181
  32. package/dist/import/getImportCollection.js.map +1 -1
  33. package/dist/index.d.ts +34 -0
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +39 -16
  36. package/dist/index.js.map +1 -1
  37. package/dist/types.d.ts +13 -0
  38. package/dist/types.d.ts.map +1 -1
  39. package/dist/types.js.map +1 -1
  40. package/dist/utilities/getPluginCollections.d.ts +4 -1
  41. package/dist/utilities/getPluginCollections.d.ts.map +1 -1
  42. package/dist/utilities/getPluginCollections.js +4 -43
  43. package/dist/utilities/getPluginCollections.js.map +1 -1
  44. package/dist/utilities/unflattenObject.d.ts.map +1 -1
  45. package/dist/utilities/unflattenObject.js +5 -0
  46. package/dist/utilities/unflattenObject.js.map +1 -1
  47. package/package.json +8 -8
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ExportSaveButton/index.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,MAAM,OAAO,CAAA;AAOzB,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EA+GpC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ExportSaveButton/index.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,MAAM,OAAO,CAAA;AAOzB,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAqHpC,CAAA"}
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { Button, SaveButton, toast, Translation, useConfig, useForm, useFormModified, useTranslation } from '@payloadcms/ui';
3
+ import { Button, SaveButton, toast, Translation, useConfig, useField, useForm, useFormModified, useTranslation } from '@payloadcms/ui';
4
4
  import { formatAdminURL } from 'payload/shared';
5
5
  import React from 'react';
6
6
  export const ExportSaveButton = ()=>{
@@ -8,17 +8,24 @@ export const ExportSaveButton = ()=>{
8
8
  const { config: { routes: { api } }, getEntityConfig } = useConfig();
9
9
  const { getData, setModified } = useForm();
10
10
  const modified = useFormModified();
11
+ const { value: targetCollectionSlug } = useField({
12
+ path: 'collectionSlug'
13
+ });
14
+ const targetCollectionConfig = getEntityConfig({
15
+ collectionSlug: targetCollectionSlug
16
+ });
17
+ const targetPluginConfig = targetCollectionConfig?.admin?.custom?.['plugin-import-export'];
11
18
  const exportsCollectionConfig = getEntityConfig({
12
19
  collectionSlug: 'exports'
13
20
  });
14
- const disableSave = exportsCollectionConfig?.admin?.custom?.disableSave === true;
15
- const disableDownload = exportsCollectionConfig?.admin?.custom?.disableDownload === true;
21
+ const disableSave = targetPluginConfig?.disableSave ?? exportsCollectionConfig?.admin?.custom?.disableSave === true;
22
+ const disableDownload = targetPluginConfig?.disableDownload ?? exportsCollectionConfig?.admin?.custom?.disableDownload === true;
16
23
  const label = t('general:save');
17
24
  const handleDownload = async ()=>{
18
25
  let timeoutID = null;
19
26
  let toastID = null;
20
27
  try {
21
- setModified(false); // Reset modified state
28
+ setModified(false);
22
29
  const data = getData();
23
30
  // Set a timeout to show toast if the request takes longer than 200ms
24
31
  timeoutID = setTimeout(()=>{
@@ -37,11 +44,9 @@ export const ExportSaveButton = ()=>{
37
44
  },
38
45
  method: 'POST'
39
46
  });
40
- // Clear the timeout if fetch completes quickly
41
47
  if (timeoutID) {
42
48
  clearTimeout(timeoutID);
43
49
  }
44
- // Dismiss the toast if it was shown
45
50
  if (toastID) {
46
51
  toast.dismiss(toastID);
47
52
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/ExportSaveButton/index.tsx"],"sourcesContent":["'use client'\n\nimport {\n Button,\n SaveButton,\n toast,\n Translation,\n useConfig,\n useForm,\n useFormModified,\n useTranslation,\n} from '@payloadcms/ui'\nimport { formatAdminURL } from 'payload/shared'\nimport React from 'react'\n\nimport type {\n PluginImportExportTranslationKeys,\n PluginImportExportTranslations,\n} from '../../translations/index.js'\n\nexport const ExportSaveButton: React.FC = () => {\n const { t } = useTranslation<PluginImportExportTranslations, PluginImportExportTranslationKeys>()\n const {\n config: {\n routes: { api },\n },\n getEntityConfig,\n } = useConfig()\n\n const { getData, setModified } = useForm()\n const modified = useFormModified()\n\n const exportsCollectionConfig = getEntityConfig({ collectionSlug: 'exports' })\n\n const disableSave = exportsCollectionConfig?.admin?.custom?.disableSave === true\n\n const disableDownload = exportsCollectionConfig?.admin?.custom?.disableDownload === true\n\n const label = t('general:save')\n\n const handleDownload = async () => {\n let timeoutID: null | ReturnType<typeof setTimeout> = null\n let toastID: null | number | string = null\n\n try {\n setModified(false) // Reset modified state\n const data = getData()\n\n // Set a timeout to show toast if the request takes longer than 200ms\n timeoutID = setTimeout(() => {\n toastID = toast.success('Your export is being processed...')\n }, 200)\n\n const response = await fetch(\n formatAdminURL({\n apiRoute: api,\n path: '/exports/download',\n }),\n {\n body: JSON.stringify({\n data,\n }),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n },\n )\n\n // Clear the timeout if fetch completes quickly\n if (timeoutID) {\n clearTimeout(timeoutID)\n }\n\n // Dismiss the toast if it was shown\n if (toastID) {\n toast.dismiss(toastID)\n }\n\n if (!response.ok) {\n // Try to parse the error message from the JSON response\n let errorMsg = 'Failed to download file'\n try {\n const errorJson = await response.json()\n if (errorJson?.errors?.[0]?.message) {\n errorMsg = errorJson.errors[0].message\n }\n } catch {\n // Ignore JSON parse errors, fallback to generic message\n }\n throw new Error(errorMsg)\n }\n\n const fileStream = response.body\n const reader = fileStream?.getReader()\n const decoder = new TextDecoder()\n let result = ''\n\n while (reader) {\n const { done, value } = await reader.read()\n if (done) {\n break\n }\n result += decoder.decode(value, { stream: true })\n }\n\n const blob = new Blob([result], { type: 'text/plain' })\n const url = URL.createObjectURL(blob)\n const a = document.createElement('a')\n a.href = url\n a.download = `${data.name}.${data.format}`\n document.body.appendChild(a)\n a.click()\n document.body.removeChild(a)\n URL.revokeObjectURL(url)\n } catch (error: any) {\n toast.error(error.message || 'Error downloading file')\n }\n }\n\n return (\n <React.Fragment>\n {!disableSave && <SaveButton label={label} />}\n {!disableDownload && (\n <Button disabled={!modified} onClick={handleDownload} size=\"medium\" type=\"button\">\n <Translation i18nKey=\"upload:download\" t={t} />\n </Button>\n )}\n </React.Fragment>\n )\n}\n"],"names":["Button","SaveButton","toast","Translation","useConfig","useForm","useFormModified","useTranslation","formatAdminURL","React","ExportSaveButton","t","config","routes","api","getEntityConfig","getData","setModified","modified","exportsCollectionConfig","collectionSlug","disableSave","admin","custom","disableDownload","label","handleDownload","timeoutID","toastID","data","setTimeout","success","response","fetch","apiRoute","path","body","JSON","stringify","credentials","headers","method","clearTimeout","dismiss","ok","errorMsg","errorJson","json","errors","message","Error","fileStream","reader","getReader","decoder","TextDecoder","result","done","value","read","decode","stream","blob","Blob","type","url","URL","createObjectURL","a","document","createElement","href","download","name","format","appendChild","click","removeChild","revokeObjectURL","error","Fragment","disabled","onClick","size","i18nKey"],"mappings":"AAAA;;AAEA,SACEA,MAAM,EACNC,UAAU,EACVC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,eAAe,EACfC,cAAc,QACT,iBAAgB;AACvB,SAASC,cAAc,QAAQ,iBAAgB;AAC/C,OAAOC,WAAW,QAAO;AAOzB,OAAO,MAAMC,mBAA6B;IACxC,MAAM,EAAEC,CAAC,EAAE,GAAGJ;IACd,MAAM,EACJK,QAAQ,EACNC,QAAQ,EAAEC,GAAG,EAAE,EAChB,EACDC,eAAe,EAChB,GAAGX;IAEJ,MAAM,EAAEY,OAAO,EAAEC,WAAW,EAAE,GAAGZ;IACjC,MAAMa,WAAWZ;IAEjB,MAAMa,0BAA0BJ,gBAAgB;QAAEK,gBAAgB;IAAU;IAE5E,MAAMC,cAAcF,yBAAyBG,OAAOC,QAAQF,gBAAgB;IAE5E,MAAMG,kBAAkBL,yBAAyBG,OAAOC,QAAQC,oBAAoB;IAEpF,MAAMC,QAAQd,EAAE;IAEhB,MAAMe,iBAAiB;QACrB,IAAIC,YAAkD;QACtD,IAAIC,UAAkC;QAEtC,IAAI;YACFX,YAAY,QAAO,uBAAuB;YAC1C,MAAMY,OAAOb;YAEb,qEAAqE;YACrEW,YAAYG,WAAW;gBACrBF,UAAU1B,M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AC1CL,SAASjC,IAAI,CAACuC,WAAW,CAACP;YAC1BA,EAAEQ,KAAK;YACPP,SAASjC,IAAI,CAACyC,WAAW,CAACT;YAC1BF,IAAIY,eAAe,CAACb;QACtB,EAAE,OAAOc,OAAY;YACnB7E,MAAM6E,KAAK,CAACA,MAAM9B,OAAO,IAAI;QAC/B;IACF;IAEA,qBACE,MAACxC,MAAMuE,QAAQ;;YACZ,CAAC3D,6BAAe,KAACpB;gBAAWwB,OAAOA;;YACnC,CAACD,iCACA,KAACxB;gBAAOiF,UAAU,CAAC/D;gBAAUgE,SAASxD;gBAAgByD,MAAK;gBAASnB,MAAK;0BACvE,cAAA,KAAC7D;oBAAYiF,SAAQ;oBAAkBzE,GAAGA;;;;;AAKpD,EAAC"}
1
+ {"version":3,"sources":["../../../src/components/ExportSaveButton/index.tsx"],"sourcesContent":["'use client'\n\nimport {\n Button,\n SaveButton,\n toast,\n Translation,\n useConfig,\n useField,\n useForm,\n useFormModified,\n useTranslation,\n} from '@payloadcms/ui'\nimport { formatAdminURL } from 'payload/shared'\nimport React from 'react'\n\nimport type {\n PluginImportExportTranslationKeys,\n PluginImportExportTranslations,\n} from '../../translations/index.js'\n\nexport const ExportSaveButton: React.FC = () => {\n const { t } = useTranslation<PluginImportExportTranslations, PluginImportExportTranslationKeys>()\n const {\n config: {\n routes: { api },\n },\n getEntityConfig,\n } = useConfig()\n\n const { getData, setModified } = useForm()\n const modified = useFormModified()\n\n const { value: targetCollectionSlug } = useField<string>({ path: 'collectionSlug' })\n\n const targetCollectionConfig = getEntityConfig({ collectionSlug: targetCollectionSlug })\n const targetPluginConfig = targetCollectionConfig?.admin?.custom?.['plugin-import-export']\n\n const exportsCollectionConfig = getEntityConfig({ collectionSlug: 'exports' })\n\n const disableSave =\n targetPluginConfig?.disableSave ?? exportsCollectionConfig?.admin?.custom?.disableSave === true\n\n const disableDownload =\n targetPluginConfig?.disableDownload ??\n exportsCollectionConfig?.admin?.custom?.disableDownload === true\n\n const label = t('general:save')\n\n const handleDownload = async () => {\n let timeoutID: null | ReturnType<typeof setTimeout> = null\n let toastID: null | number | string = null\n\n try {\n setModified(false)\n const data = getData()\n\n // Set a timeout to show toast if the request takes longer than 200ms\n timeoutID = setTimeout(() => {\n toastID = toast.success('Your export is being processed...')\n }, 200)\n\n const response = await fetch(\n formatAdminURL({\n apiRoute: api,\n path: '/exports/download',\n }),\n {\n body: JSON.stringify({\n data,\n }),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n },\n )\n\n if (timeoutID) {\n clearTimeout(timeoutID)\n }\n\n if (toastID) {\n toast.dismiss(toastID)\n }\n\n if (!response.ok) {\n // Try to parse the error message from the JSON response\n let errorMsg = 'Failed to download file'\n try {\n const errorJson = await response.json()\n if (errorJson?.errors?.[0]?.message) {\n errorMsg = errorJson.errors[0].message\n }\n } catch {\n // Ignore JSON parse errors, fallback to generic message\n }\n throw new Error(errorMsg)\n }\n\n const fileStream = response.body\n const reader = fileStream?.getReader()\n const decoder = new TextDecoder()\n let result = ''\n\n while (reader) {\n const { done, value } = await reader.read()\n if (done) {\n break\n }\n result += decoder.decode(value, { stream: true })\n }\n\n const blob = new Blob([result], { type: 'text/plain' })\n const url = URL.createObjectURL(blob)\n const a = document.createElement('a')\n a.href = url\n a.download = `${data.name}.${data.format}`\n document.body.appendChild(a)\n a.click()\n document.body.removeChild(a)\n URL.revokeObjectURL(url)\n } catch (error: any) {\n toast.error(error.message || 'Error downloading file')\n }\n }\n\n return (\n <React.Fragment>\n {!disableSave && <SaveButton label={label} />}\n {!disableDownload && (\n <Button disabled={!modified} onClick={handleDownload} size=\"medium\" type=\"button\">\n <Translation i18nKey=\"upload:download\" t={t} />\n </Button>\n )}\n </React.Fragment>\n )\n}\n"],"names":["Button","SaveButton","toast","Translation","useConfig","useField","useForm","useFormModified","useTranslation","formatAdminURL","React","ExportSaveButton","t","config","routes","api","getEntityConfig","getData","setModified","modified","value","targetCollectionSlug","path","targetCollectionConfig","collectionSlug","targetPluginConfig","admin","custom","exportsCollectionConfig","disableSave","disableDownload","label","handleDownload","timeoutID","toastID","data","setTimeout","success","response","fetch","apiRoute","body","JSON","stringify","credentials","headers","method","clearTimeout","dismiss","ok","errorMsg","errorJson","json","errors","message","Error","fileStream","reader","getReader","decoder","TextDecoder","result","done","read","decode","stream","blob","Blob","type","url","URL","createObjectURL","a","document","createElement","href","download","name","format","appendChild","click","removeChild","revokeObjectURL","error","Fragment","disabled","onClick","size","i18nKey"],"mappings":"AAAA;;AAEA,SACEA,MAAM,EACNC,UAAU,EACVC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,QAAQ,EACRC,OAAO,EACPC,eAAe,EACfC,cAAc,QACT,iBAAgB;AACvB,SAASC,cAAc,QAAQ,iBAAgB;AAC/C,OAAOC,WAAW,QAAO;AAOzB,OAAO,MAAMC,mBAA6B;IACxC,MAAM,EAAEC,CAAC,EAAE,GAAGJ;IACd,MAAM,EACJK,QAAQ,EACNC,QAAQ,EAAEC,GAAG,EAAE,EAChB,EACDC,eAAe,EAChB,GAAGZ;IAEJ,MAAM,EAAEa,OAAO,EAAEC,WAAW,EAAE,GAAGZ;IACjC,MAAMa,WAAWZ;IAEjB,MAAM,EAAEa,OAAOC,oBAAoB,EAAE,GAAGhB,SAAiB;QAAEiB,MAAM;IAAiB;IAElF,MAAMC,yBAAyBP,gBAAgB;QAAEQ,gBAAgBH;IAAqB;IACtF,MAAMI,qBAAqBF,wBAAwBG,OAAOC,QAAQ,CAAC,uBAAuB;IAE1F,MAAMC,0BAA0BZ,gBAAgB;QAAEQ,gBAAgB;IAAU;IAE5E,MAAMK,cACJJ,oBAAoBI,eAAeD,yBAAyBF,OAAOC,QAAQE,gBAAgB;IAE7F,MAAMC,kBACJL,oBAAoBK,mBACpBF,yBAAyBF,OAAOC,QAAQG,oBAAoB;IAE9D,MAAMC,QAAQnB,EAAE;IAEhB,MAAMoB,iBAAiB;QACrB,IAAIC,YAAkD;QACtD,IAAIC,UAAkC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QAAQ,GAAG,GAAGzC,KAAK0C,IAAI,CAAC,CAAC,EAAE1C,KAAK2C,MAAM,EAAE;YAC1CL,SAAShC,IAAI,CAACsC,WAAW,CAACP;YAC1BA,EAAEQ,KAAK;YACPP,SAAShC,IAAI,CAACwC,WAAW,CAACT;YAC1BF,IAAIY,eAAe,CAACb;QACtB,EAAE,OAAOc,OAAY;YACnBjF,MAAMiF,KAAK,CAACA,MAAM7B,OAAO,IAAI;QAC/B;IACF;IAEA,qBACE,MAAC5C,MAAM0E,QAAQ;;YACZ,CAACvD,6BAAe,KAAC5B;gBAAW8B,OAAOA;;YACnC,CAACD,iCACA,KAAC9B;gBAAOqF,UAAU,CAAClE;gBAAUmE,SAAStD;gBAAgBuD,MAAK;gBAASnB,MAAK;0BACvE,cAAA,KAACjE;oBAAYqF,SAAQ;oBAAkB5E,GAAGA;;;;;AAKpD,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { SelectFieldClientComponent } from 'payload';
2
+ export declare const FormatField: SelectFieldClientComponent;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FormatField/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAczD,eAAO,MAAM,WAAW,EAAE,0BA4DzB,CAAA"}
@@ -0,0 +1,95 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { FieldLabel, ReactSelect, useConfig, useField } from '@payloadcms/ui';
4
+ import React, { useCallback, useEffect, useMemo } from 'react';
5
+ const baseClass = 'field-type select';
6
+ const allOptions = [
7
+ {
8
+ label: 'CSV',
9
+ value: 'csv'
10
+ },
11
+ {
12
+ label: 'JSON',
13
+ value: 'json'
14
+ }
15
+ ];
16
+ export const FormatField = (props)=>{
17
+ const { getEntityConfig } = useConfig();
18
+ const width = props.field.admin?.width;
19
+ const { setValue, value: formatValue } = useField();
20
+ const { value: targetCollectionSlug } = useField({
21
+ path: 'collectionSlug'
22
+ });
23
+ const targetCollectionConfig = getEntityConfig({
24
+ collectionSlug: targetCollectionSlug
25
+ });
26
+ const forcedFormat = targetCollectionConfig?.admin?.custom?.['plugin-import-export']?.exportFormat;
27
+ const options = useMemo(()=>{
28
+ if (forcedFormat) {
29
+ return [
30
+ {
31
+ label: forcedFormat.toUpperCase(),
32
+ value: forcedFormat
33
+ }
34
+ ];
35
+ }
36
+ return allOptions;
37
+ }, [
38
+ forcedFormat
39
+ ]);
40
+ const selectedOption = useMemo(()=>{
41
+ const effectiveValue = forcedFormat || formatValue || 'csv';
42
+ return options.find((o)=>o.value === effectiveValue) ?? options[0];
43
+ }, [
44
+ forcedFormat,
45
+ formatValue,
46
+ options
47
+ ]);
48
+ useEffect(()=>{
49
+ if (forcedFormat && formatValue !== forcedFormat) {
50
+ setValue(forcedFormat);
51
+ }
52
+ }, [
53
+ forcedFormat,
54
+ formatValue,
55
+ setValue
56
+ ]);
57
+ const handleChange = useCallback((selected)=>{
58
+ if (forcedFormat) {
59
+ return;
60
+ }
61
+ if (Array.isArray(selected)) {
62
+ setValue(selected[0]?.value ?? 'csv');
63
+ } else {
64
+ setValue(selected?.value ?? 'csv');
65
+ }
66
+ }, [
67
+ forcedFormat,
68
+ setValue
69
+ ]);
70
+ const isReadOnly = Boolean(forcedFormat) || props.readOnly;
71
+ return /*#__PURE__*/ _jsxs("div", {
72
+ className: baseClass,
73
+ style: {
74
+ width
75
+ },
76
+ children: [
77
+ /*#__PURE__*/ _jsx(FieldLabel, {
78
+ label: props.field.label,
79
+ path: props.path
80
+ }),
81
+ /*#__PURE__*/ _jsx(ReactSelect, {
82
+ className: 'format-field',
83
+ disabled: isReadOnly,
84
+ inputId: `field-${props.path.replace(/\./g, '__')}`,
85
+ isClearable: false,
86
+ isSearchable: false,
87
+ onChange: handleChange,
88
+ options: options,
89
+ value: selectedOption
90
+ })
91
+ ]
92
+ });
93
+ };
94
+
95
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/FormatField/index.tsx"],"sourcesContent":["'use client'\n\nimport type { ReactSelectOption } from '@payloadcms/ui'\nimport type { SelectFieldClientComponent } from 'payload'\n\nimport { FieldLabel, ReactSelect, useConfig, useField } from '@payloadcms/ui'\nimport React, { useCallback, useEffect, useMemo } from 'react'\n\nconst baseClass = 'field-type select'\n\ntype Format = 'csv' | 'json'\n\nconst allOptions: ReactSelectOption[] = [\n { label: 'CSV', value: 'csv' },\n { label: 'JSON', value: 'json' },\n]\n\nexport const FormatField: SelectFieldClientComponent = (props) => {\n const { getEntityConfig } = useConfig()\n const width = props.field.admin?.width\n\n const { setValue, value: formatValue } = useField<Format>()\n const { value: targetCollectionSlug } = useField<string>({ path: 'collectionSlug' })\n\n const targetCollectionConfig = getEntityConfig({ collectionSlug: targetCollectionSlug })\n const forcedFormat = targetCollectionConfig?.admin?.custom?.['plugin-import-export']\n ?.exportFormat as Format | undefined\n\n const options = useMemo<ReactSelectOption[]>(() => {\n if (forcedFormat) {\n return [{ label: forcedFormat.toUpperCase(), value: forcedFormat }]\n }\n return allOptions\n }, [forcedFormat])\n\n const selectedOption = useMemo<ReactSelectOption | undefined>(() => {\n const effectiveValue = forcedFormat || formatValue || 'csv'\n return options.find((o) => o.value === effectiveValue) ?? options[0]\n }, [forcedFormat, formatValue, options])\n\n useEffect(() => {\n if (forcedFormat && formatValue !== forcedFormat) {\n setValue(forcedFormat)\n }\n }, [forcedFormat, formatValue, setValue])\n\n const handleChange = useCallback(\n (selected: ReactSelectOption | ReactSelectOption[]) => {\n if (forcedFormat) {\n return\n }\n if (Array.isArray(selected)) {\n setValue((selected[0]?.value as Format) ?? 'csv')\n } else {\n setValue((selected?.value as Format) ?? 'csv')\n }\n },\n [forcedFormat, setValue],\n )\n\n const isReadOnly = Boolean(forcedFormat) || props.readOnly\n\n return (\n <div className={baseClass} style={{ width }}>\n <FieldLabel label={props.field.label} path={props.path} />\n <ReactSelect\n className={'format-field'}\n disabled={isReadOnly}\n inputId={`field-${props.path.replace(/\\./g, '__')}`}\n isClearable={false}\n isSearchable={false}\n onChange={handleChange}\n options={options}\n value={selectedOption}\n />\n </div>\n )\n}\n"],"names":["FieldLabel","ReactSelect","useConfig","useField","React","useCallback","useEffect","useMemo","baseClass","allOptions","label","value","FormatField","props","getEntityConfig","width","field","admin","setValue","formatValue","targetCollectionSlug","path","targetCollectionConfig","collectionSlug","forcedFormat","custom","exportFormat","options","toUpperCase","selectedOption","effectiveValue","find","o","handleChange","selected","Array","isArray","isReadOnly","Boolean","readOnly","div","className","style","disabled","inputId","replace","isClearable","isSearchable","onChange"],"mappings":"AAAA;;AAKA,SAASA,UAAU,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,iBAAgB;AAC7E,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,QAAQ,QAAO;AAE9D,MAAMC,YAAY;AAIlB,MAAMC,aAAkC;IACtC;QAAEC,OAAO;QAAOC,OAAO;IAAM;IAC7B;QAAED,OAAO;QAAQC,OAAO;IAAO;CAChC;AAED,OAAO,MAAMC,cAA0C,CAACC;IACtD,MAAM,EAAEC,eAAe,EAAE,GAAGZ;IAC5B,MAAMa,QAAQF,MAAMG,KAAK,CAACC,KAAK,EAAEF;IAEjC,MAAM,EAAEG,QAAQ,EAAEP,OAAOQ,WAAW,EAAE,GAAGhB;IACzC,MAAM,EAAEQ,OAAOS,oBAAoB,EAAE,GAAGjB,SAAiB;QAAEkB,MAAM;IAAiB;IAElF,MAAMC,yBAAyBR,gBAAgB;QAAES,gBAAgBH;IAAqB;IACtF,MAAMI,eAAeF,wBAAwBL,OAAOQ,QAAQ,CAAC,uBAAuB,EAChFC;IAEJ,MAAMC,UAAUpB,QAA6B;QAC3C,IAAIiB,cAAc;YAChB,OAAO;gBAAC;oBAAEd,OAAOc,aAAaI,WAAW;oBAAIjB,OAAOa;gBAAa;aAAE;QACrE;QACA,OAAOf;IACT,GAAG;QAACe;KAAa;IAEjB,MAAMK,iBAAiBtB,QAAuC;QAC5D,MAAMuB,iBAAiBN,gBAAgBL,eAAe;QACtD,OAAOQ,QAAQI,IAAI,CAAC,CAACC,IAAMA,EAAErB,KAAK,KAAKmB,mBAAmBH,OAAO,CAAC,EAAE;IACtE,GAAG;QAACH;QAAcL;QAAaQ;KAAQ;IAEvCrB,UAAU;QACR,IAAIkB,gBAAgBL,gBAAgBK,cAAc;YAChDN,SAASM;QACX;IACF,GAAG;QAACA;QAAcL;QAAaD;KAAS;IAExC,MAAMe,eAAe5B,YACnB,CAAC6B;QACC,IAAIV,cAAc;YAChB;QACF;QACA,IAAIW,MAAMC,OAAO,CAACF,WAAW;YAC3BhB,SAAS,AAACgB,QAAQ,CAAC,EAAE,EAAEvB,SAAoB;QAC7C,OAAO;YACLO,SAAS,AAACgB,UAAUvB,SAAoB;QAC1C;IACF,GACA;QAACa;QAAcN;KAAS;IAG1B,MAAMmB,aAAaC,QAAQd,iBAAiBX,MAAM0B,QAAQ;IAE1D,qBACE,MAACC;QAAIC,WAAWjC;QAAWkC,OAAO;YAAE3B;QAAM;;0BACxC,KAACf;gBAAWU,OAAOG,MAAMG,KAAK,CAACN,KAAK;gBAAEW,MAAMR,MAAMQ,IAAI;;0BACtD,KAACpB;gBACCwC,WAAW;gBACXE,UAAUN;gBACVO,SAAS,CAAC,MAAM,EAAE/B,MAAMQ,IAAI,CAACwB,OAAO,CAAC,OAAO,OAAO;gBACnDC,aAAa;gBACbC,cAAc;gBACdC,UAAUf;gBACVN,SAASA;gBACThB,OAAOkB;;;;AAIf,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createExport.d.ts","sourceRoot":"","sources":["../../src/export/createExport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAa,KAAK,EAAE,MAAM,SAAS,CAAA;AAerE,MAAM,MAAM,MAAM,GAAG;IACnB;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,IAAI,GAAG,KAAK,CAAA;IACrB,gBAAgB,EAAE,MAAM,CAAA;IACxB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,EAAE,KAAK,GAAG,MAAM,CAAA;IACtB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,MAAM,CAAA;AAEV,eAAO,MAAM,YAAY,SAAgB,gBAAgB,kCA8fxD,CAAA"}
@@ -14,8 +14,11 @@ export const createExport = async (args)=>{
14
14
  const { locale: localeFromReq, payload } = req;
15
15
  if (debug) {
16
16
  req.payload.logger.debug({
17
- message: 'Starting export process with args:',
17
+ msg: '[createExport] Starting export process',
18
+ exportDocId: id,
19
+ exportName: nameArg,
18
20
  collectionSlug,
21
+ exportCollection,
19
22
  draft: draftsFromInput,
20
23
  fields,
21
24
  format
@@ -378,22 +381,47 @@ export const createExport = async (args)=>{
378
381
  };
379
382
  } else {
380
383
  if (debug) {
381
- req.payload.logger.debug(`Updating existing export with id: ${id}`);
384
+ req.payload.logger.debug({
385
+ msg: '[createExport] Updating export document with file',
386
+ exportDocId: id,
387
+ exportCollection,
388
+ fileName: name,
389
+ fileSize: buffer.length,
390
+ mimeType: isCSV ? 'text/csv' : 'application/json'
391
+ });
392
+ }
393
+ try {
394
+ await req.payload.update({
395
+ id,
396
+ collection: exportCollection,
397
+ data: {},
398
+ file: {
399
+ name,
400
+ data: buffer,
401
+ mimetype: isCSV ? 'text/csv' : 'application/json',
402
+ size: buffer.length
403
+ },
404
+ // Override access only here so that we can be sure the export collection itself is updated as expected
405
+ overrideAccess: true,
406
+ req
407
+ });
408
+ } catch (error) {
409
+ const errorDetails = error instanceof Error ? {
410
+ message: error.message,
411
+ name: error.name,
412
+ stack: error.stack,
413
+ // @ts-expect-error - data might exist on Payload errors
414
+ data: error.data
415
+ } : error;
416
+ req.payload.logger.error({
417
+ msg: '[createExport] Failed to update export document with file',
418
+ err: errorDetails,
419
+ exportDocId: id,
420
+ exportCollection,
421
+ fileName: name
422
+ });
423
+ throw error;
382
424
  }
383
- await req.payload.update({
384
- id,
385
- collection: exportCollection,
386
- data: {},
387
- file: {
388
- name,
389
- data: buffer,
390
- mimetype: isCSV ? 'text/csv' : 'application/json',
391
- size: buffer.length
392
- },
393
- // Override access only here so that we can be sure the export collection itself is updated as expected
394
- overrideAccess: true,
395
- req
396
- });
397
425
  }
398
426
  if (debug) {
399
427
  req.payload.logger.debug('Export process completed successfully');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/export/createExport.ts"],"sourcesContent":["/* eslint-disable perfectionist/sort-objects */\nimport type { PayloadRequest, Sort, TypedUser, Where } from 'payload'\n\nimport { stringify } from 'csv-stringify/sync'\nimport { APIError } from 'payload'\nimport { Readable } from 'stream'\n\nimport { buildDisabledFieldRegex } from '../utilities/buildDisabledFieldRegex.js'\nimport { flattenObject } from '../utilities/flattenObject.js'\nimport { getExportFieldFunctions } from '../utilities/getExportFieldFunctions.js'\nimport { getFilename } from '../utilities/getFilename.js'\nimport { getSchemaColumns, mergeColumns } from '../utilities/getSchemaColumns.js'\nimport { getSelect } from '../utilities/getSelect.js'\nimport { validateLimitValue } from '../utilities/validateLimitValue.js'\nimport { createExportBatchProcessor, type ExportFindArgs } from './batchProcessor.js'\n\nexport type Export = {\n /**\n * Number of documents to process in each batch during export\n * @default 100\n */\n batchSize?: number\n collectionSlug: string\n /**\n * If true, enables debug logging\n */\n debug?: boolean\n drafts?: 'no' | 'yes'\n exportCollection: string\n fields?: string[]\n format: 'csv' | 'json'\n globals?: string[]\n id: number | string\n limit?: number\n locale?: string\n /**\n * Maximum number of documents that can be exported in a single operation.\n * This value has already been resolved from the plugin config.\n */\n maxLimit?: number\n name: string\n page?: number\n sort?: Sort\n userCollection: string\n userID: number | string\n where?: Where\n}\n\nexport type CreateExportArgs = {\n /**\n * If true, stream the file instead of saving it\n */\n download?: boolean\n req: PayloadRequest\n} & Export\n\nexport const createExport = async (args: CreateExportArgs) => {\n const {\n id,\n name: nameArg,\n batchSize = 100,\n collectionSlug,\n debug = false,\n download,\n drafts: draftsFromInput,\n exportCollection,\n fields,\n format,\n limit: incomingLimit,\n maxLimit,\n locale: localeFromInput,\n page,\n req,\n sort,\n userCollection,\n userID,\n where: whereFromInput = {},\n } = args\n const { locale: localeFromReq, payload } = req\n\n if (debug) {\n req.payload.logger.debug({\n message: 'Starting export process with args:',\n collectionSlug,\n draft: draftsFromInput,\n fields,\n format,\n })\n }\n\n const locale = localeFromInput ?? localeFromReq\n const collectionConfig = payload.config.collections.find(({ slug }) => slug === collectionSlug)\n\n if (!collectionConfig) {\n throw new APIError(`Collection with slug ${collectionSlug} not found.`)\n }\n\n let user: TypedUser | undefined\n\n if (userCollection && userID) {\n user = (await req.payload.findByID({\n id: userID,\n collection: userCollection,\n overrideAccess: true,\n })) as TypedUser\n }\n\n if (!user && req.user) {\n user = req?.user?.id ? req.user : req?.user?.user\n }\n\n if (!user) {\n throw new APIError('User authentication is required to create exports.')\n }\n\n const draft = draftsFromInput === 'yes'\n const hasVersions = Boolean(collectionConfig.versions)\n\n // Only filter by _status for versioned collections\n const publishedWhere: Where = hasVersions ? { _status: { equals: 'published' } } : {}\n\n const where: Where = {\n and: [whereFromInput, draft ? {} : publishedWhere],\n }\n\n const baseName = nameArg ?? getFilename()\n const name = `${baseName}-${collectionSlug}.${format}`\n const isCSV = format === 'csv'\n const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined\n\n if (debug) {\n req.payload.logger.debug({ message: 'Export configuration:', name, isCSV, locale })\n }\n\n // Determine maximum export documents:\n // 1. If maxLimit is defined, it sets the absolute ceiling\n // 2. User's limit is applied but clamped to maxLimit if it exceeds it\n let maxExportDocuments: number | undefined\n\n if (typeof maxLimit === 'number' && maxLimit > 0) {\n if (typeof incomingLimit === 'number' && incomingLimit > 0) {\n // User provided a limit - clamp it to maxLimit\n maxExportDocuments = Math.min(incomingLimit, maxLimit)\n } else {\n // No user limit - use maxLimit as the ceiling\n maxExportDocuments = maxLimit\n }\n } else {\n // No maxLimit - use user's limit if provided\n maxExportDocuments =\n typeof incomingLimit === 'number' && incomingLimit > 0 ? incomingLimit : undefined\n }\n\n // Try to count documents - if access is denied, treat as 0 documents\n let totalDocs = 0\n let accessDenied = false\n try {\n const countResult = await payload.count({\n collection: collectionSlug,\n user,\n locale,\n overrideAccess: false,\n })\n totalDocs = countResult.totalDocs\n } catch (error) {\n // Access denied - user can't read from this collection\n // We'll create an empty export file\n accessDenied = true\n if (debug) {\n req.payload.logger.debug({\n message: 'Access denied for collection, creating empty export',\n collectionSlug,\n })\n }\n }\n\n const totalPages = Math.max(1, Math.ceil(totalDocs / batchSize))\n const requestedPage = page || 1\n const adjustedPage = requestedPage > totalPages ? 1 : requestedPage\n\n const findArgs = {\n collection: collectionSlug,\n depth: 1,\n draft,\n limit: batchSize,\n locale,\n overrideAccess: false,\n page: 0,\n select,\n sort,\n user,\n where,\n }\n\n if (debug) {\n req.payload.logger.debug({ message: 'Find arguments:', findArgs })\n }\n\n const toCSVFunctions = getExportFieldFunctions({\n fields: collectionConfig.flattenedFields,\n })\n\n const disabledFields =\n collectionConfig.admin?.custom?.['plugin-import-export']?.disabledFields ?? []\n\n const disabledMatchers = disabledFields.map(buildDisabledFieldRegex)\n\n const filterDisabledCSV = (row: Record<string, unknown>): Record<string, unknown> => {\n const filtered: Record<string, unknown> = {}\n\n for (const [key, value] of Object.entries(row)) {\n const isDisabled = disabledMatchers.some((matcher) => matcher.test(key))\n if (!isDisabled) {\n filtered[key] = value\n }\n }\n\n return filtered\n }\n\n const filterDisabledJSON = (doc: any, parentPath = ''): any => {\n if (Array.isArray(doc)) {\n return doc.map((item) => filterDisabledJSON(item, parentPath))\n }\n\n if (typeof doc !== 'object' || doc === null) {\n return doc\n }\n\n const filtered: Record<string, any> = {}\n for (const [key, value] of Object.entries(doc)) {\n const currentPath = parentPath ? `${parentPath}.${key}` : key\n\n // Only remove if this exact path is disabled\n const isDisabled = disabledFields.includes(currentPath)\n\n if (!isDisabled) {\n filtered[key] = filterDisabledJSON(value, currentPath)\n }\n }\n\n return filtered\n }\n\n if (download) {\n const limitErrorMsg = validateLimitValue(incomingLimit, req.t)\n if (limitErrorMsg) {\n throw new APIError(limitErrorMsg)\n }\n\n // Get schema-based columns first (provides base ordering and handles empty exports)\n let schemaColumns: string[] = []\n if (isCSV) {\n const localeCodes =\n locale === 'all' && payload.config.localization\n ? payload.config.localization.localeCodes\n : undefined\n\n schemaColumns = getSchemaColumns({\n collectionConfig,\n disabledFields,\n fields,\n locale,\n localeCodes,\n })\n\n if (debug) {\n req.payload.logger.debug({\n columnCount: schemaColumns.length,\n msg: 'Schema-based column inference complete',\n })\n }\n }\n\n // allColumns will be finalized after first batch (schema + data columns merged)\n let allColumns: string[] = []\n let columnsFinalized = false\n\n const encoder = new TextEncoder()\n let isFirstBatch = true\n let currentBatchPage = adjustedPage\n let fetched = 0\n const maxDocs =\n typeof maxExportDocuments === 'number' ? maxExportDocuments : Number.POSITIVE_INFINITY\n\n const stream = new Readable({\n async read() {\n const remaining = Math.max(0, maxDocs - fetched)\n\n if (remaining === 0) {\n if (!isCSV) {\n // If first batch with no remaining, output empty array; otherwise just close\n this.push(encoder.encode(isFirstBatch ? '[]' : ']'))\n }\n this.push(null)\n return\n }\n\n const result = await payload.find({\n ...findArgs,\n page: currentBatchPage,\n limit: Math.min(batchSize, remaining),\n })\n\n if (debug) {\n req.payload.logger.debug(\n `Streaming batch ${currentBatchPage} with ${result.docs.length} docs`,\n )\n }\n\n if (result.docs.length === 0) {\n // Close JSON array properly if JSON\n if (!isCSV) {\n // If first batch with no docs, output empty array; otherwise just close\n this.push(encoder.encode(isFirstBatch ? '[]' : ']'))\n }\n this.push(null)\n return\n }\n\n if (isCSV) {\n // --- CSV Streaming ---\n const batchRows = result.docs.map((doc) =>\n filterDisabledCSV(\n flattenObject({\n doc,\n fields,\n toCSVFunctions,\n }),\n ),\n )\n\n // On first batch, discover additional columns from data and merge with schema\n if (!columnsFinalized) {\n const dataColumns: string[] = []\n const seenCols = new Set<string>()\n for (const row of batchRows) {\n for (const key of Object.keys(row)) {\n if (!seenCols.has(key)) {\n seenCols.add(key)\n dataColumns.push(key)\n }\n }\n }\n // Merge schema columns with data-discovered columns\n allColumns = mergeColumns(schemaColumns, dataColumns)\n columnsFinalized = true\n\n if (debug) {\n req.payload.logger.debug({\n dataColumnsCount: dataColumns.length,\n finalColumnsCount: allColumns.length,\n msg: 'Merged schema and data columns',\n })\n }\n }\n\n const paddedRows = batchRows.map((row) => {\n const fullRow: Record<string, unknown> = {}\n for (const col of allColumns) {\n fullRow[col] = row[col] ?? ''\n }\n return fullRow\n })\n\n const csvString = stringify(paddedRows, {\n bom: isFirstBatch,\n header: isFirstBatch,\n columns: allColumns,\n })\n\n this.push(encoder.encode(csvString))\n } else {\n // --- JSON Streaming ---\n const batchRows = result.docs.map((doc) => filterDisabledJSON(doc))\n\n // Convert each filtered/flattened row into JSON string\n const batchJSON = batchRows.map((row) => JSON.stringify(row)).join(',')\n\n if (isFirstBatch) {\n this.push(encoder.encode('[' + batchJSON))\n } else {\n this.push(encoder.encode(',' + batchJSON))\n }\n }\n\n fetched += result.docs.length\n isFirstBatch = false\n currentBatchPage += 1\n\n if (!result.hasNextPage || fetched >= maxDocs) {\n if (debug) {\n req.payload.logger.debug('Stream complete - no more pages')\n }\n if (!isCSV) {\n this.push(encoder.encode(']'))\n }\n this.push(null) // End the stream\n }\n },\n })\n\n return new Response(Readable.toWeb(stream) as ReadableStream, {\n headers: {\n 'Content-Disposition': `attachment; filename=\"${name}\"`,\n 'Content-Type': isCSV ? 'text/csv' : 'application/json',\n },\n })\n }\n\n // Non-download path (buffered export)\n if (debug) {\n req.payload.logger.debug('Starting file generation')\n }\n\n // Create export batch processor\n const processor = createExportBatchProcessor({ batchSize, debug })\n\n // Transform function based on format\n const transformDoc = (doc: unknown) =>\n isCSV\n ? filterDisabledCSV(\n flattenObject({\n doc,\n fields,\n toCSVFunctions,\n }),\n )\n : filterDisabledJSON(doc)\n\n // Skip fetching if access was denied - we'll create an empty export\n let exportResult = {\n columns: [] as string[],\n docs: [] as Record<string, unknown>[],\n fetchedCount: 0,\n }\n\n if (!accessDenied) {\n exportResult = await processor.processExport({\n collectionSlug,\n findArgs: findArgs as ExportFindArgs,\n format,\n maxDocs:\n typeof maxExportDocuments === 'number' ? maxExportDocuments : Number.POSITIVE_INFINITY,\n req,\n startPage: adjustedPage,\n transformDoc,\n })\n }\n\n const { columns: dataColumns, docs: rows } = exportResult\n const outputData: string[] = []\n\n // Prepare final output\n if (isCSV) {\n // Get schema-based columns for consistent ordering\n const localeCodes =\n locale === 'all' && payload.config.localization\n ? payload.config.localization.localeCodes\n : undefined\n\n const schemaColumns = getSchemaColumns({\n collectionConfig,\n disabledFields,\n fields,\n locale,\n localeCodes,\n })\n\n // Merge schema columns with data-discovered columns\n // Schema provides ordering, data provides additional columns (e.g., array indices > 0)\n const finalColumns = mergeColumns(schemaColumns, dataColumns)\n\n const paddedRows = rows.map((row) => {\n const fullRow: Record<string, unknown> = {}\n for (const col of finalColumns) {\n fullRow[col] = row[col] ?? ''\n }\n return fullRow\n })\n\n // Always output CSV with header, even if empty\n outputData.push(\n stringify(paddedRows, {\n bom: true,\n header: true,\n columns: finalColumns,\n }),\n )\n } else {\n // JSON format\n outputData.push(rows.map((doc) => JSON.stringify(doc)).join(',\\n'))\n }\n\n // Ensure we always have valid content for the file\n // For JSON, empty exports produce \"[]\"\n // For CSV, if completely empty (no columns, no rows), produce at least a newline to ensure file creation\n const content = format === 'json' ? `[${outputData.join(',')}]` : outputData.join('')\n const buffer = Buffer.from(content.length > 0 ? content : '\\n')\n if (debug) {\n req.payload.logger.debug(`${format} file generation complete`)\n }\n\n if (!id) {\n if (debug) {\n req.payload.logger.debug('Creating new export file')\n }\n req.file = {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n }\n } else {\n if (debug) {\n req.payload.logger.debug(`Updating existing export with id: ${id}`)\n }\n await req.payload.update({\n id,\n collection: exportCollection,\n data: {},\n file: {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n },\n // Override access only here so that we can be sure the export collection itself is updated as expected\n overrideAccess: true,\n req,\n })\n }\n if (debug) {\n req.payload.logger.debug('Export process completed successfully')\n }\n}\n"],"names":["stringify","APIError","Readable","buildDisabledFieldRegex","flattenObject","getExportFieldFunctions","getFilename","getSchemaColumns","mergeColumns","getSelect","validateLimitValue","createExportBatchProcessor","createExport","args","id","name","nameArg","batchSize","collectionSlug","debug","download","drafts","draftsFromInput","exportCollection","fields","format","limit","incomingLimit","maxLimit","locale","localeFromInput","page","req","sort","userCollection","userID","where","whereFromInput","localeFromReq","payload","logger","message","draft","collectionConfig","config","collections","find","slug","user","findByID","collection","overrideAccess","hasVersions","Boolean","versions","publishedWhere","_status","equals","and","baseName","isCSV","select","Array","isArray","length","undefined","maxExportDocuments","Math","min","totalDocs","accessDenied","countResult","count","error","totalPages","max","ceil","requestedPage","adjustedPage","findArgs","depth","toCSVFunctions","flattenedFields","disabledFields","admin","custom","disabledMatchers","map","filterDisabledCSV","row","filtered","key","value","Object","entries","isDisabled","some","matcher","test","filterDisabledJSON","doc","parentPath","item","currentPath","includes","limitErrorMsg","t","schemaColumns","localeCodes","localization","columnCount","msg","allColumns","columnsFinalized","encoder","TextEncoder","isFirstBatch","currentBatchPage","fetched","maxDocs","Number","POSITIVE_INFINITY","stream","read","remaining","push","encode","result","docs","batchRows","dataColumns","seenCols","Set","keys","has","add","dataColumnsCount","finalColumnsCount","paddedRows","fullRow","col","csvString","bom","header","columns","batchJSON","JSON","join","hasNextPage","Response","toWeb","headers","processor","transformDoc","exportResult","fetchedCount","processExport","startPage","rows","outputData","finalColumns","content","buffer","Buffer","from","file","data","mimetype","size","update"],"mappings":"AAAA,6CAA6C,GAG7C,SAASA,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,QAAQ,QAAQ,UAAS;AAClC,SAASC,QAAQ,QAAQ,SAAQ;AAEjC,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,aAAa,QAAQ,gCAA+B;AAC7D,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,gBAAgB,EAAEC,YAAY,QAAQ,mCAAkC;AACjF,SAASC,SAAS,QAAQ,4BAA2B;AACrD,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,0BAA0B,QAA6B,sBAAqB;AA0CrF,OAAO,MAAMC,eAAe,OAAOC;IACjC,MAAM,EACJC,EAAE,EACFC,MAAMC,OAAO,EACbC,YAAY,GAAG,EACfC,cAAc,EACdC,QAAQ,KAAK,EACbC,QAAQ,EACRC,QAAQC,eAAe,EACvBC,gBAAgB,EAChBC,MAAM,EACNC,MAAM,EACNC,OAAOC,aAAa,EACpBC,QAAQ,EACRC,QAAQC,eAAe,EACvBC,IAAI,EACJC,GAAG,EACHC,IAAI,EACJC,cAAc,EACdC,MAAM,EACNC,OAAOC,iBAAiB,CAAC,CAAC,EAC3B,GAAGxB;IACJ,MAAM,EAAEgB,QAAQS,aAAa,EAAEC,OAAO,EAAE,GAAGP;IAE3C,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GAAGY,WAAWZ,IAAI,CAAC;IAClF,MAAMe,SAASC,OAAOC,IAAI,CAACH,QAAQjG,MAAM,GAAG,IAAIiG,UAAU;IAC1D,IAAI9I,OAAO;QACTa,IAAIO,OAAO,CAACC,MAAM,CAACrB,KAAK,CAAC,GAAGM,OAAO,yBAAyB,CAAC;IAC/D;IAEA,IAAI,CAACX,IAAI;QACP,IAAIK,OAAO;YACTa,IAAIO,OAAO,CAACC,MAAM,CAACrB,KAAK,CAAC;QAC3B;QACAa,IAAIqI,IAAI,GAAG;YACTtJ;YACAuJ,MAAMJ;YACNK,UAAU3G,QAAQ,aAAa;YAC/B4G,MAAMN,OAAOlG,MAAM;QACrB;IACF,OAAO;QACL,IAAI7C,OAAO;YACTa,IAAIO,OAAO,CAACC,MAAM,CAACrB,KAAK,CAAC,CAAC,kCAAkC,EAAEL,IAAI;QACpE;QACA,MAAMkB,IAAIO,OAAO,CAACkI,MAAM,CAAC;YACvB3J;YACAoC,YAAY3B;YACZ+I,MAAM,CAAC;YACPD,MAAM;gBACJtJ;gBACAuJ,MAAMJ;gBACNK,UAAU3G,QAAQ,aAAa;gBAC/B4G,MAAMN,OAAOlG,MAAM;YACrB;YACA,uGAAuG;YACvGb,gBAAgB;YAChBnB;QACF;IACF;IACA,IAAIb,OAAO;QACTa,IAAIO,OAAO,CAACC,MAAM,CAACrB,KAAK,CAAC;IAC3B;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/export/createExport.ts"],"sourcesContent":["/* eslint-disable perfectionist/sort-objects */\nimport type { PayloadRequest, Sort, TypedUser, Where } from 'payload'\n\nimport { stringify } from 'csv-stringify/sync'\nimport { APIError } from 'payload'\nimport { Readable } from 'stream'\n\nimport { buildDisabledFieldRegex } from '../utilities/buildDisabledFieldRegex.js'\nimport { flattenObject } from '../utilities/flattenObject.js'\nimport { getExportFieldFunctions } from '../utilities/getExportFieldFunctions.js'\nimport { getFilename } from '../utilities/getFilename.js'\nimport { getSchemaColumns, mergeColumns } from '../utilities/getSchemaColumns.js'\nimport { getSelect } from '../utilities/getSelect.js'\nimport { validateLimitValue } from '../utilities/validateLimitValue.js'\nimport { createExportBatchProcessor, type ExportFindArgs } from './batchProcessor.js'\n\nexport type Export = {\n /**\n * Number of documents to process in each batch during export\n * @default 100\n */\n batchSize?: number\n collectionSlug: string\n /**\n * If true, enables debug logging\n */\n debug?: boolean\n drafts?: 'no' | 'yes'\n exportCollection: string\n fields?: string[]\n format: 'csv' | 'json'\n globals?: string[]\n id: number | string\n limit?: number\n locale?: string\n /**\n * Maximum number of documents that can be exported in a single operation.\n * This value has already been resolved from the plugin config.\n */\n maxLimit?: number\n name: string\n page?: number\n sort?: Sort\n userCollection: string\n userID: number | string\n where?: Where\n}\n\nexport type CreateExportArgs = {\n /**\n * If true, stream the file instead of saving it\n */\n download?: boolean\n req: PayloadRequest\n} & Export\n\nexport const createExport = async (args: CreateExportArgs) => {\n const {\n id,\n name: nameArg,\n batchSize = 100,\n collectionSlug,\n debug = false,\n download,\n drafts: draftsFromInput,\n exportCollection,\n fields,\n format,\n limit: incomingLimit,\n maxLimit,\n locale: localeFromInput,\n page,\n req,\n sort,\n userCollection,\n userID,\n where: whereFromInput = {},\n } = args\n const { locale: localeFromReq, payload } = req\n\n if (debug) {\n req.payload.logger.debug({\n msg: '[createExport] Starting export process',\n exportDocId: id,\n exportName: nameArg,\n collectionSlug,\n exportCollection,\n draft: draftsFromInput,\n fields,\n format,\n })\n }\n\n const locale = localeFromInput ?? localeFromReq\n const collectionConfig = payload.config.collections.find(({ slug }) => slug === collectionSlug)\n\n if (!collectionConfig) {\n throw new APIError(`Collection with slug ${collectionSlug} not found.`)\n }\n\n let user: TypedUser | undefined\n\n if (userCollection && userID) {\n user = (await req.payload.findByID({\n id: userID,\n collection: userCollection,\n overrideAccess: true,\n })) as TypedUser\n }\n\n if (!user && req.user) {\n user = req?.user?.id ? req.user : req?.user?.user\n }\n\n if (!user) {\n throw new APIError('User authentication is required to create exports.')\n }\n\n const draft = draftsFromInput === 'yes'\n const hasVersions = Boolean(collectionConfig.versions)\n\n // Only filter by _status for versioned collections\n const publishedWhere: Where = hasVersions ? { _status: { equals: 'published' } } : {}\n\n const where: Where = {\n and: [whereFromInput, draft ? {} : publishedWhere],\n }\n\n const baseName = nameArg ?? getFilename()\n const name = `${baseName}-${collectionSlug}.${format}`\n const isCSV = format === 'csv'\n const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined\n\n if (debug) {\n req.payload.logger.debug({ message: 'Export configuration:', name, isCSV, locale })\n }\n\n // Determine maximum export documents:\n // 1. If maxLimit is defined, it sets the absolute ceiling\n // 2. User's limit is applied but clamped to maxLimit if it exceeds it\n let maxExportDocuments: number | undefined\n\n if (typeof maxLimit === 'number' && maxLimit > 0) {\n if (typeof incomingLimit === 'number' && incomingLimit > 0) {\n // User provided a limit - clamp it to maxLimit\n maxExportDocuments = Math.min(incomingLimit, maxLimit)\n } else {\n // No user limit - use maxLimit as the ceiling\n maxExportDocuments = maxLimit\n }\n } else {\n // No maxLimit - use user's limit if provided\n maxExportDocuments =\n typeof incomingLimit === 'number' && incomingLimit > 0 ? incomingLimit : undefined\n }\n\n // Try to count documents - if access is denied, treat as 0 documents\n let totalDocs = 0\n let accessDenied = false\n try {\n const countResult = await payload.count({\n collection: collectionSlug,\n user,\n locale,\n overrideAccess: false,\n })\n totalDocs = countResult.totalDocs\n } catch (error) {\n // Access denied - user can't read from this collection\n // We'll create an empty export file\n accessDenied = true\n if (debug) {\n req.payload.logger.debug({\n message: 'Access denied for collection, creating empty export',\n collectionSlug,\n })\n }\n }\n\n const totalPages = Math.max(1, Math.ceil(totalDocs / batchSize))\n const requestedPage = page || 1\n const adjustedPage = requestedPage > totalPages ? 1 : requestedPage\n\n const findArgs = {\n collection: collectionSlug,\n depth: 1,\n draft,\n limit: batchSize,\n locale,\n overrideAccess: false,\n page: 0,\n select,\n sort,\n user,\n where,\n }\n\n if (debug) {\n req.payload.logger.debug({ message: 'Find arguments:', findArgs })\n }\n\n const toCSVFunctions = getExportFieldFunctions({\n fields: collectionConfig.flattenedFields,\n })\n\n const disabledFields =\n collectionConfig.admin?.custom?.['plugin-import-export']?.disabledFields ?? []\n\n const disabledMatchers = disabledFields.map(buildDisabledFieldRegex)\n\n const filterDisabledCSV = (row: Record<string, unknown>): Record<string, unknown> => {\n const filtered: Record<string, unknown> = {}\n\n for (const [key, value] of Object.entries(row)) {\n const isDisabled = disabledMatchers.some((matcher) => matcher.test(key))\n if (!isDisabled) {\n filtered[key] = value\n }\n }\n\n return filtered\n }\n\n const filterDisabledJSON = (doc: any, parentPath = ''): any => {\n if (Array.isArray(doc)) {\n return doc.map((item) => filterDisabledJSON(item, parentPath))\n }\n\n if (typeof doc !== 'object' || doc === null) {\n return doc\n }\n\n const filtered: Record<string, any> = {}\n for (const [key, value] of Object.entries(doc)) {\n const currentPath = parentPath ? `${parentPath}.${key}` : key\n\n // Only remove if this exact path is disabled\n const isDisabled = disabledFields.includes(currentPath)\n\n if (!isDisabled) {\n filtered[key] = filterDisabledJSON(value, currentPath)\n }\n }\n\n return filtered\n }\n\n if (download) {\n const limitErrorMsg = validateLimitValue(incomingLimit, req.t)\n if (limitErrorMsg) {\n throw new APIError(limitErrorMsg)\n }\n\n // Get schema-based columns first (provides base ordering and handles empty exports)\n let schemaColumns: string[] = []\n if (isCSV) {\n const localeCodes =\n locale === 'all' && payload.config.localization\n ? payload.config.localization.localeCodes\n : undefined\n\n schemaColumns = getSchemaColumns({\n collectionConfig,\n disabledFields,\n fields,\n locale,\n localeCodes,\n })\n\n if (debug) {\n req.payload.logger.debug({\n columnCount: schemaColumns.length,\n msg: 'Schema-based column inference complete',\n })\n }\n }\n\n // allColumns will be finalized after first batch (schema + data columns merged)\n let allColumns: string[] = []\n let columnsFinalized = false\n\n const encoder = new TextEncoder()\n let isFirstBatch = true\n let currentBatchPage = adjustedPage\n let fetched = 0\n const maxDocs =\n typeof maxExportDocuments === 'number' ? maxExportDocuments : Number.POSITIVE_INFINITY\n\n const stream = new Readable({\n async read() {\n const remaining = Math.max(0, maxDocs - fetched)\n\n if (remaining === 0) {\n if (!isCSV) {\n // If first batch with no remaining, output empty array; otherwise just close\n this.push(encoder.encode(isFirstBatch ? '[]' : ']'))\n }\n this.push(null)\n return\n }\n\n const result = await payload.find({\n ...findArgs,\n page: currentBatchPage,\n limit: Math.min(batchSize, remaining),\n })\n\n if (debug) {\n req.payload.logger.debug(\n `Streaming batch ${currentBatchPage} with ${result.docs.length} docs`,\n )\n }\n\n if (result.docs.length === 0) {\n // Close JSON array properly if JSON\n if (!isCSV) {\n // If first batch with no docs, output empty array; otherwise just close\n this.push(encoder.encode(isFirstBatch ? '[]' : ']'))\n }\n this.push(null)\n return\n }\n\n if (isCSV) {\n // --- CSV Streaming ---\n const batchRows = result.docs.map((doc) =>\n filterDisabledCSV(\n flattenObject({\n doc,\n fields,\n toCSVFunctions,\n }),\n ),\n )\n\n // On first batch, discover additional columns from data and merge with schema\n if (!columnsFinalized) {\n const dataColumns: string[] = []\n const seenCols = new Set<string>()\n for (const row of batchRows) {\n for (const key of Object.keys(row)) {\n if (!seenCols.has(key)) {\n seenCols.add(key)\n dataColumns.push(key)\n }\n }\n }\n // Merge schema columns with data-discovered columns\n allColumns = mergeColumns(schemaColumns, dataColumns)\n columnsFinalized = true\n\n if (debug) {\n req.payload.logger.debug({\n dataColumnsCount: dataColumns.length,\n finalColumnsCount: allColumns.length,\n msg: 'Merged schema and data columns',\n })\n }\n }\n\n const paddedRows = batchRows.map((row) => {\n const fullRow: Record<string, unknown> = {}\n for (const col of allColumns) {\n fullRow[col] = row[col] ?? ''\n }\n return fullRow\n })\n\n const csvString = stringify(paddedRows, {\n bom: isFirstBatch,\n header: isFirstBatch,\n columns: allColumns,\n })\n\n this.push(encoder.encode(csvString))\n } else {\n // --- JSON Streaming ---\n const batchRows = result.docs.map((doc) => filterDisabledJSON(doc))\n\n // Convert each filtered/flattened row into JSON string\n const batchJSON = batchRows.map((row) => JSON.stringify(row)).join(',')\n\n if (isFirstBatch) {\n this.push(encoder.encode('[' + batchJSON))\n } else {\n this.push(encoder.encode(',' + batchJSON))\n }\n }\n\n fetched += result.docs.length\n isFirstBatch = false\n currentBatchPage += 1\n\n if (!result.hasNextPage || fetched >= maxDocs) {\n if (debug) {\n req.payload.logger.debug('Stream complete - no more pages')\n }\n if (!isCSV) {\n this.push(encoder.encode(']'))\n }\n this.push(null) // End the stream\n }\n },\n })\n\n return new Response(Readable.toWeb(stream) as ReadableStream, {\n headers: {\n 'Content-Disposition': `attachment; filename=\"${name}\"`,\n 'Content-Type': isCSV ? 'text/csv' : 'application/json',\n },\n })\n }\n\n // Non-download path (buffered export)\n if (debug) {\n req.payload.logger.debug('Starting file generation')\n }\n\n // Create export batch processor\n const processor = createExportBatchProcessor({ batchSize, debug })\n\n // Transform function based on format\n const transformDoc = (doc: unknown) =>\n isCSV\n ? filterDisabledCSV(\n flattenObject({\n doc,\n fields,\n toCSVFunctions,\n }),\n )\n : filterDisabledJSON(doc)\n\n // Skip fetching if access was denied - we'll create an empty export\n let exportResult = {\n columns: [] as string[],\n docs: [] as Record<string, unknown>[],\n fetchedCount: 0,\n }\n\n if (!accessDenied) {\n exportResult = await processor.processExport({\n collectionSlug,\n findArgs: findArgs as ExportFindArgs,\n format,\n maxDocs:\n typeof maxExportDocuments === 'number' ? maxExportDocuments : Number.POSITIVE_INFINITY,\n req,\n startPage: adjustedPage,\n transformDoc,\n })\n }\n\n const { columns: dataColumns, docs: rows } = exportResult\n const outputData: string[] = []\n\n // Prepare final output\n if (isCSV) {\n // Get schema-based columns for consistent ordering\n const localeCodes =\n locale === 'all' && payload.config.localization\n ? payload.config.localization.localeCodes\n : undefined\n\n const schemaColumns = getSchemaColumns({\n collectionConfig,\n disabledFields,\n fields,\n locale,\n localeCodes,\n })\n\n // Merge schema columns with data-discovered columns\n // Schema provides ordering, data provides additional columns (e.g., array indices > 0)\n const finalColumns = mergeColumns(schemaColumns, dataColumns)\n\n const paddedRows = rows.map((row) => {\n const fullRow: Record<string, unknown> = {}\n for (const col of finalColumns) {\n fullRow[col] = row[col] ?? ''\n }\n return fullRow\n })\n\n // Always output CSV with header, even if empty\n outputData.push(\n stringify(paddedRows, {\n bom: true,\n header: true,\n columns: finalColumns,\n }),\n )\n } else {\n // JSON format\n outputData.push(rows.map((doc) => JSON.stringify(doc)).join(',\\n'))\n }\n\n // Ensure we always have valid content for the file\n // For JSON, empty exports produce \"[]\"\n // For CSV, if completely empty (no columns, no rows), produce at least a newline to ensure file creation\n const content = format === 'json' ? `[${outputData.join(',')}]` : outputData.join('')\n const buffer = Buffer.from(content.length > 0 ? content : '\\n')\n if (debug) {\n req.payload.logger.debug(`${format} file generation complete`)\n }\n\n if (!id) {\n if (debug) {\n req.payload.logger.debug('Creating new export file')\n }\n req.file = {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n }\n } else {\n if (debug) {\n req.payload.logger.debug({\n msg: '[createExport] Updating export document with file',\n exportDocId: id,\n exportCollection,\n fileName: name,\n fileSize: buffer.length,\n mimeType: isCSV ? 'text/csv' : 'application/json',\n })\n }\n try {\n await req.payload.update({\n id,\n collection: exportCollection,\n data: {},\n file: {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n },\n // Override access only here so that we can be sure the export collection itself is updated as expected\n overrideAccess: true,\n req,\n })\n } catch (error) {\n const errorDetails =\n error instanceof Error\n ? {\n message: error.message,\n name: error.name,\n stack: error.stack,\n // @ts-expect-error - data might exist on Payload errors\n data: error.data,\n }\n : error\n req.payload.logger.error({\n msg: '[createExport] Failed to update export document with file',\n err: errorDetails,\n exportDocId: id,\n exportCollection,\n fileName: name,\n })\n throw error\n }\n }\n if (debug) {\n req.payload.logger.debug('Export process completed successfully')\n }\n}\n"],"names":["stringify","APIError","Readable","buildDisabledFieldRegex","flattenObject","getExportFieldFunctions","getFilename","getSchemaColumns","mergeColumns","getSelect","validateLimitValue","createExportBatchProcessor","createExport","args","id","name","nameArg","batchSize","collectionSlug","debug","download","drafts","draftsFromInput","exportCollection","fields","format","limit","incomingLimit","maxLimit","locale","localeFromInput","page","req","sort","userCollection","userID","where","whereFromInput","localeFromReq","payload","logger","msg","exportDocId","exportName","draft","collectionConfig","config","collections","find","slug","user","findByID","collection","overrideAccess","hasVersions","Boolean","versions","publishedWhere","_status","equals","and","baseName","isCSV","select","Array","isArray","length","undefined","message","maxExportDocuments","Math","min","totalDocs","accessDenied","countResult","count","error","totalPages","max","ceil","requestedPage","adjustedPage","findArgs","depth","toCSVFunctions","flattenedFields","disabledFields","admin","custom","disabledMatchers","map","filterDisabledCSV","row","filtered","key","value","Object","entries","isDisabled","some","matcher","test","filterDisabledJSON","doc","parentPath","item","currentPath","includes","limitErrorMsg","t","schemaColumns","localeCodes","localization","columnCount","allColumns","columnsFinalized","encoder","TextEncoder","isFirstBatch","currentBatchPage","fetched","maxDocs","Number","POSITIVE_INFINITY","stream","read","remaining","push","encode","result","docs","batchRows","dataColumns","seenCols","Set","keys","has","add","dataColumnsCount","finalColumnsCount","paddedRows","fullRow","col","csvString","bom","header","columns","batchJSON","JSON","join","hasNextPage","Response","toWeb","headers","processor","transformDoc","exportResult","fetchedCount","processExport","startPage","rows","outputData","finalColumns","content","buffer","Buffer","from","file","data","mimetype","size","fileName","fileSize","mimeType","update","errorDetails","Error","stack","err"],"mappings":"AAAA,6CAA6C,GAG7C,SAASA,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,QAAQ,QAAQ,UAAS;AAClC,SAASC,QAAQ,QAAQ,SAAQ;AAEjC,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,aAAa,QAAQ,gCAA+B;AAC7D,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,gBAAgB,EAAEC,YAAY,QAAQ,mCAAkC;AACjF,SAASC,SAAS,QAAQ,4BAA2B;AACrD,SAASC,kBAAkB,QAAQ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B;gBACZiJ,MAAM,CAAC;gBACPD,MAAM;oBACJxJ;oBACAyJ,MAAMJ;oBACNK,UAAU3G,QAAQ,aAAa;oBAC/B4G,MAAMN,OAAOlG,MAAM;gBACrB;gBACA,uGAAuG;gBACvGb,gBAAgB;gBAChBrB;YACF;QACF,EAAE,OAAO4C,OAAO;YACd,MAAMmG,eACJnG,iBAAiBoG,QACb;gBACE5G,SAASQ,MAAMR,OAAO;gBACtBrD,MAAM6D,MAAM7D,IAAI;gBAChBkK,OAAOrG,MAAMqG,KAAK;gBAClB,wDAAwD;gBACxDT,MAAM5F,MAAM4F,IAAI;YAClB,IACA5F;YACN5C,IAAIO,OAAO,CAACC,MAAM,CAACoC,KAAK,CAAC;gBACvBnC,KAAK;gBACLyI,KAAKH;gBACLrI,aAAa5B;gBACbS;gBACAoJ,UAAU5J;YACZ;YACA,MAAM6D;QACR;IACF;IACA,IAAIzD,OAAO;QACTa,IAAIO,OAAO,CAACC,MAAM,CAACrB,KAAK,CAAC;IAC3B;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getCreateExportCollectionTask.d.ts","sourceRoot":"","sources":["../../src/export/getCreateExportCollectionTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAK/C;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;CACvB,GAAG,MAAM,CAAA;AAEV,eAAO,MAAM,6BAA6B,WAChC,MAAM,KACb,UAAU,CAAC;IACZ,KAAK,EAAE,cAAc,CAAA;IACrB,MAAM,EAAE,MAAM,CAAA;CACf,CAkDA,CAAA"}
1
+ {"version":3,"file":"getCreateExportCollectionTask.d.ts","sourceRoot":"","sources":["../../src/export/getCreateExportCollectionTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAS,UAAU,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAI/C;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;CACvB,GAAG,MAAM,CAAA;AAmGV,eAAO,MAAM,6BAA6B,WAChC,MAAM,KACb,UAAU,CAAC;IACZ,KAAK,EAAE,cAAc,CAAA;IACrB,MAAM,EAAE,MAAM,CAAA;CACf,CAuBA,CAAA"}
@@ -1,30 +1,111 @@
1
1
  import { createExport } from './createExport.js';
2
- import { getFields } from './getFields.js';
3
- export const getCreateCollectionExportTask = (config)=>{
4
- // Job queue task needs all collection slugs since it can handle exports for any collection
2
+ /**
3
+ * Creates a minimal inputSchema for the job queue task.
4
+ */ const getJobInputSchema = (config)=>{
5
5
  const allCollectionSlugs = config.collections?.map((c)=>c.slug) || [];
6
- const inputSchema = getFields({
7
- collectionSlugs: allCollectionSlugs,
8
- config
9
- }).concat({
10
- name: 'id',
11
- type: 'text'
12
- }, {
13
- name: 'batchSize',
14
- type: 'number'
15
- }, {
16
- name: 'userID',
17
- type: 'text'
18
- }, {
19
- name: 'userCollection',
20
- type: 'text'
21
- }, {
22
- name: 'exportCollection',
23
- type: 'text'
24
- }, {
25
- name: 'maxLimit',
26
- type: 'number'
6
+ const collectionOptions = allCollectionSlugs.map((slug)=>{
7
+ const collectionConfig = config.collections?.find((c)=>c.slug === slug);
8
+ return {
9
+ label: collectionConfig?.labels?.singular || slug,
10
+ value: slug
11
+ };
27
12
  });
13
+ return [
14
+ {
15
+ name: 'id',
16
+ type: 'text',
17
+ required: true
18
+ },
19
+ {
20
+ name: 'name',
21
+ type: 'text',
22
+ required: true
23
+ },
24
+ {
25
+ name: 'batchSize',
26
+ type: 'number'
27
+ },
28
+ {
29
+ name: 'collectionSlug',
30
+ type: 'select',
31
+ options: collectionOptions,
32
+ required: true
33
+ },
34
+ {
35
+ name: 'drafts',
36
+ type: 'select',
37
+ options: [
38
+ {
39
+ label: 'Yes',
40
+ value: 'yes'
41
+ },
42
+ {
43
+ label: 'No',
44
+ value: 'no'
45
+ }
46
+ ]
47
+ },
48
+ {
49
+ name: 'exportCollection',
50
+ type: 'text',
51
+ required: true
52
+ },
53
+ {
54
+ name: 'fields',
55
+ type: 'text',
56
+ hasMany: true
57
+ },
58
+ {
59
+ name: 'format',
60
+ type: 'select',
61
+ options: [
62
+ {
63
+ label: 'CSV',
64
+ value: 'csv'
65
+ },
66
+ {
67
+ label: 'JSON',
68
+ value: 'json'
69
+ }
70
+ ],
71
+ required: true
72
+ },
73
+ {
74
+ name: 'limit',
75
+ type: 'number'
76
+ },
77
+ {
78
+ name: 'locale',
79
+ type: 'text'
80
+ },
81
+ {
82
+ name: 'maxLimit',
83
+ type: 'number'
84
+ },
85
+ {
86
+ name: 'page',
87
+ type: 'number'
88
+ },
89
+ {
90
+ name: 'sort',
91
+ type: 'text'
92
+ },
93
+ {
94
+ name: 'userCollection',
95
+ type: 'text'
96
+ },
97
+ {
98
+ name: 'userID',
99
+ type: 'text'
100
+ },
101
+ {
102
+ name: 'where',
103
+ type: 'json'
104
+ }
105
+ ];
106
+ };
107
+ export const getCreateCollectionExportTask = (config)=>{
108
+ const inputSchema = getJobInputSchema(config);
28
109
  return {
29
110
  slug: 'createCollectionExport',
30
111
  handler: async ({ input, req })=>{
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/export/getCreateExportCollectionTask.ts"],"sourcesContent":["import type { Config, TaskConfig } from 'payload'\n\nimport type { Export } from './createExport.js'\n\nimport { createExport } from './createExport.js'\nimport { getFields } from './getFields.js'\n\n/**\n * Export input type for job queue serialization.\n * When exports are queued as jobs, the user must be serialized as an ID string or number\n * along with the collection name so it can be rehydrated when the job runs.\n */\nexport type ExportJobInput = {\n user: number | string\n userCollection: string\n} & Export\n\nexport const getCreateCollectionExportTask = (\n config: Config,\n): TaskConfig<{\n input: ExportJobInput\n output: object\n}> => {\n // Job queue task needs all collection slugs since it can handle exports for any collection\n const allCollectionSlugs = config.collections?.map((c) => c.slug) || []\n const inputSchema = getFields({ collectionSlugs: allCollectionSlugs, config }).concat(\n {\n name: 'id',\n type: 'text',\n },\n {\n name: 'batchSize',\n type: 'number',\n },\n {\n name: 'userID',\n type: 'text',\n },\n {\n name: 'userCollection',\n type: 'text',\n },\n {\n name: 'exportCollection',\n type: 'text',\n },\n {\n name: 'maxLimit',\n type: 'number',\n },\n )\n\n return {\n slug: 'createCollectionExport',\n handler: async ({ input, req }) => {\n if (!input) {\n req.payload.logger.error('No input provided to createCollectionExport task')\n\n return { output: {} }\n }\n\n await createExport({\n ...input,\n req,\n })\n\n return {\n output: {},\n }\n },\n inputSchema,\n }\n}\n"],"names":["createExport","getFields","getCreateCollectionExportTask","config","allCollectionSlugs","collections","map","c","slug","inputSchema","collectionSlugs","concat","name","type","handler","input","req","payload","logger","error","output"],"mappings":"AAIA,SAASA,YAAY,QAAQ,oBAAmB;AAChD,SAASC,SAAS,QAAQ,iBAAgB;AAY1C,OAAO,MAAMC,gCAAgC,CAC3CC;IAKA,2FAA2F;IAC3F,MAAMC,qBAAqBD,OAAOE,WAAW,EAAEC,IAAI,CAACC,IAAMA,EAAEC,IAAI,KAAK,EAAE;IACvE,MAAMC,cAAcR,UAAU;QAAES,iBAAiBN;QAAoBD;IAAO,GAAGQ,MAAM,CACnF;QACEC,MAAM;QACNC,MAAM;IACR,GACA;QACED,MAAM;QACNC,MAAM;IACR,GACA;QACED,MAAM;QACNC,MAAM;IACR,GACA;QACED,MAAM;QACNC,MAAM;IACR,GACA;QACED,MAAM;QACNC,MAAM;IACR,GACA;QACED,MAAM;QACNC,MAAM;IACR;IAGF,OAAO;QACLL,MAAM;QACNM,SAAS,OAAO,EAAEC,KAAK,EAAEC,GAAG,EAAE;YAC5B,IAAI,CAACD,OAAO;gBACVC,IAAIC,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;gBAEzB,OAAO;oBAAEC,QAAQ,CAAC;gBAAE;YACtB;YAEA,MAAMpB,aAAa;gBACjB,GAAGe,KAAK;gBACRC;YACF;YAEA,OAAO;gBACLI,QAAQ,CAAC;YACX;QACF;QACAX;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/export/getCreateExportCollectionTask.ts"],"sourcesContent":["import type { Config, Field, TaskConfig } from 'payload'\n\nimport type { Export } from './createExport.js'\n\nimport { createExport } from './createExport.js'\n\n/**\n * Export input type for job queue serialization.\n * When exports are queued as jobs, the user must be serialized as an ID string or number\n * along with the collection name so it can be rehydrated when the job runs.\n */\nexport type ExportJobInput = {\n user: number | string\n userCollection: string\n} & Export\n\n/**\n * Creates a minimal inputSchema for the job queue task.\n */\nconst getJobInputSchema = (config: Config): Field[] => {\n const allCollectionSlugs = config.collections?.map((c) => c.slug) || []\n\n const collectionOptions = allCollectionSlugs.map((slug) => {\n const collectionConfig = config.collections?.find((c) => c.slug === slug)\n return {\n label: collectionConfig?.labels?.singular || slug,\n value: slug,\n }\n })\n\n return [\n {\n name: 'id',\n type: 'text',\n required: true,\n },\n {\n name: 'name',\n type: 'text',\n required: true,\n },\n {\n name: 'batchSize',\n type: 'number',\n },\n {\n name: 'collectionSlug',\n type: 'select',\n options: collectionOptions,\n required: true,\n },\n {\n name: 'drafts',\n type: 'select',\n options: [\n { label: 'Yes', value: 'yes' },\n { label: 'No', value: 'no' },\n ],\n },\n {\n name: 'exportCollection',\n type: 'text',\n required: true,\n },\n {\n name: 'fields',\n type: 'text',\n hasMany: true,\n },\n {\n name: 'format',\n type: 'select',\n options: [\n { label: 'CSV', value: 'csv' },\n { label: 'JSON', value: 'json' },\n ],\n required: true,\n },\n {\n name: 'limit',\n type: 'number',\n },\n {\n name: 'locale',\n type: 'text',\n },\n {\n name: 'maxLimit',\n type: 'number',\n },\n {\n name: 'page',\n type: 'number',\n },\n {\n name: 'sort',\n type: 'text',\n },\n {\n name: 'userCollection',\n type: 'text',\n },\n {\n name: 'userID',\n type: 'text',\n },\n {\n name: 'where',\n type: 'json',\n },\n ]\n}\n\nexport const getCreateCollectionExportTask = (\n config: Config,\n): TaskConfig<{\n input: ExportJobInput\n output: object\n}> => {\n const inputSchema = getJobInputSchema(config)\n\n return {\n slug: 'createCollectionExport',\n handler: async ({ input, req }) => {\n if (!input) {\n req.payload.logger.error('No input provided to createCollectionExport task')\n\n return { output: {} }\n }\n\n await createExport({\n ...input,\n req,\n })\n\n return {\n output: {},\n }\n },\n inputSchema,\n }\n}\n"],"names":["createExport","getJobInputSchema","config","allCollectionSlugs","collections","map","c","slug","collectionOptions","collectionConfig","find","label","labels","singular","value","name","type","required","options","hasMany","getCreateCollectionExportTask","inputSchema","handler","input","req","payload","logger","error","output"],"mappings":"AAIA,SAASA,YAAY,QAAQ,oBAAmB;AAYhD;;CAEC,GACD,MAAMC,oBAAoB,CAACC;IACzB,MAAMC,qBAAqBD,OAAOE,WAAW,EAAEC,IAAI,CAACC,IAAMA,EAAEC,IAAI,KAAK,EAAE;IAEvE,MAAMC,oBAAoBL,mBAAmBE,GAAG,CAAC,CAACE;QAChD,MAAME,mBAAmBP,OAAOE,WAAW,EAAEM,KAAK,CAACJ,IAAMA,EAAEC,IAAI,KAAKA;QACpE,OAAO;YACLI,OAAOF,kBAAkBG,QAAQC,YAAYN;YAC7CO,OAAOP;QACT;IACF;IAEA,OAAO;QACL;YACEQ,MAAM;YACNC,MAAM;YACNC,UAAU;QACZ;QACA;YACEF,MAAM;YACNC,MAAM;YACNC,UAAU;QACZ;QACA;YACEF,MAAM;YACNC,MAAM;QACR;QACA;YACED,MAAM;YACNC,MAAM;YACNE,SAASV;YACTS,UAAU;QACZ;QACA;YACEF,MAAM;YACNC,MAAM;YACNE,SAAS;gBACP;oBAAEP,OAAO;oBAAOG,OAAO;gBAAM;gBAC7B;oBAAEH,OAAO;oBAAMG,OAAO;gBAAK;aAC5B;QACH;QACA;YACEC,MAAM;YACNC,MAAM;YACNC,UAAU;QACZ;QACA;YACEF,MAAM;YACNC,MAAM;YACNG,SAAS;QACX;QACA;YACEJ,MAAM;YACNC,MAAM;YACNE,SAAS;gBACP;oBAAEP,OAAO;oBAAOG,OAAO;gBAAM;gBAC7B;oBAAEH,OAAO;oBAAQG,OAAO;gBAAO;aAChC;YACDG,UAAU;QACZ;QACA;YACEF,MAAM;YACNC,MAAM;QACR;QACA;YACED,MAAM;YACNC,MAAM;QACR;QACA;YACED,MAAM;YACNC,MAAM;QACR;QACA;YACED,MAAM;YACNC,MAAM;QACR;QACA;YACED,MAAM;YACNC,MAAM;QACR;QACA;YACED,MAAM;YACNC,MAAM;QACR;QACA;YACED,MAAM;YACNC,MAAM;QACR;QACA;YACED,MAAM;YACNC,MAAM;QACR;KACD;AACH;AAEA,OAAO,MAAMI,gCAAgC,CAC3ClB;IAKA,MAAMmB,cAAcpB,kBAAkBC;IAEtC,OAAO;QACLK,MAAM;QACNe,SAAS,OAAO,EAAEC,KAAK,EAAEC,GAAG,EAAE;YAC5B,IAAI,CAACD,OAAO;gBACVC,IAAIC,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;gBAEzB,OAAO;oBAAEC,QAAQ,CAAC;gBAAE;YACtB;YAEA,MAAM5B,aAAa;gBACjB,GAAGuB,KAAK;gBACRC;YACF;YAEA,OAAO;gBACLI,QAAQ,CAAC;YACX;QACF;QACAP;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getExportCollection.d.ts","sourceRoot":"","sources":["../../src/export/getExportCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,MAAM,EACP,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB,EAAS,MAAM,aAAa,CAAA;AAShF,eAAO,MAAM,mBAAmB,6DAK7B;IACD;;OAEG;IACH,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,gBAuIH,CAAA"}
1
+ {"version":3,"file":"getExportCollection.d.ts","sourceRoot":"","sources":["../../src/export/getExportCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,MAAM,EACP,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB,EAAS,MAAM,aAAa,CAAA;AAWhF,eAAO,MAAM,mBAAmB,6DAK7B;IACD;;OAEG;IACH,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,gBA8JH,CAAA"}