@payloadcms/plugin-import-export 3.48.0-canary.1 → 3.48.0-canary.3
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.
- package/dist/components/ExportSaveButton/index.d.ts.map +1 -1
- package/dist/components/ExportSaveButton/index.js +8 -3
- package/dist/components/ExportSaveButton/index.js.map +1 -1
- package/dist/components/FieldsToExport/index.d.ts.map +1 -1
- package/dist/components/FieldsToExport/index.js +2 -0
- package/dist/components/FieldsToExport/index.js.map +1 -1
- package/dist/components/FieldsToExport/reduceFields.d.ts +2 -1
- package/dist/components/FieldsToExport/reduceFields.d.ts.map +1 -1
- package/dist/components/FieldsToExport/reduceFields.js +7 -1
- package/dist/components/FieldsToExport/reduceFields.js.map +1 -1
- package/dist/components/Preview/index.d.ts.map +1 -1
- package/dist/components/Preview/index.js +7 -1
- package/dist/components/Preview/index.js.map +1 -1
- package/dist/export/createExport.d.ts.map +1 -1
- package/dist/export/createExport.js +14 -6
- package/dist/export/createExport.js.map +1 -1
- package/dist/export/getCreateExportCollectionTask.d.ts +2 -1
- package/dist/export/getCreateExportCollectionTask.d.ts.map +1 -1
- package/dist/export/getCreateExportCollectionTask.js +2 -2
- package/dist/export/getCreateExportCollectionTask.js.map +1 -1
- package/dist/export/getFields.d.ts +2 -1
- package/dist/export/getFields.d.ts.map +1 -1
- package/dist/export/getFields.js +7 -2
- package/dist/export/getFields.js.map +1 -1
- package/dist/getExportCollection.d.ts.map +1 -1
- package/dist/getExportCollection.js +5 -1
- package/dist/getExportCollection.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +20 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ExportSaveButton/index.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,MAAM,OAAO,CAAA;AAOzB,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ExportSaveButton/index.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,MAAM,OAAO,CAAA;AAOzB,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAiGpC,CAAA"}
|
|
@@ -4,9 +4,14 @@ import { Button, SaveButton, toast, Translation, useConfig, useForm, useFormModi
|
|
|
4
4
|
import React from 'react';
|
|
5
5
|
export const ExportSaveButton = ()=>{
|
|
6
6
|
const { t } = useTranslation();
|
|
7
|
-
const { config: { routes: { api }, serverURL } } = useConfig();
|
|
7
|
+
const { config: { routes: { api }, serverURL }, getEntityConfig } = useConfig();
|
|
8
8
|
const { getData, setModified } = useForm();
|
|
9
9
|
const modified = useFormModified();
|
|
10
|
+
const exportsCollectionConfig = getEntityConfig({
|
|
11
|
+
collectionSlug: 'exports'
|
|
12
|
+
});
|
|
13
|
+
const disableSave = exportsCollectionConfig?.admin?.custom?.disableSave === true;
|
|
14
|
+
const disableDownload = exportsCollectionConfig?.admin?.custom?.disableDownload === true;
|
|
10
15
|
const label = t('general:save');
|
|
11
16
|
const handleDownload = async ()=>{
|
|
12
17
|
let timeoutID = null;
|
|
@@ -73,10 +78,10 @@ export const ExportSaveButton = ()=>{
|
|
|
73
78
|
};
|
|
74
79
|
return /*#__PURE__*/ _jsxs(React.Fragment, {
|
|
75
80
|
children: [
|
|
76
|
-
/*#__PURE__*/ _jsx(SaveButton, {
|
|
81
|
+
!disableSave && /*#__PURE__*/ _jsx(SaveButton, {
|
|
77
82
|
label: label
|
|
78
83
|
}),
|
|
79
|
-
/*#__PURE__*/ _jsx(Button, {
|
|
84
|
+
!disableDownload && /*#__PURE__*/ _jsx(Button, {
|
|
80
85
|
disabled: !modified,
|
|
81
86
|
onClick: handleDownload,
|
|
82
87
|
size: "medium",
|
|
@@ -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 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 serverURL,\n },\n } = useConfig()\n\n const { getData, setModified } = useForm()\n const modified = useFormModified()\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(`${serverURL}${api}/exports/download`, {\n body: JSON.stringify({\n data,\n }),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\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 throw new Error('Failed to download file')\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) {\n console.error('Error downloading file:', error)\n toast.error('Error downloading file')\n }\n }\n\n return (\n <React.Fragment>\n <SaveButton label={label}
|
|
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 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 serverURL,\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(`${serverURL}${api}/exports/download`, {\n body: JSON.stringify({\n data,\n }),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\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 throw new Error('Failed to download file')\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) {\n console.error('Error downloading file:', error)\n toast.error('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","React","ExportSaveButton","t","config","routes","api","serverURL","getEntityConfig","getData","setModified","modified","exportsCollectionConfig","collectionSlug","disableSave","admin","custom","disableDownload","label","handleDownload","timeoutID","toastID","data","setTimeout","success","response","fetch","body","JSON","stringify","credentials","headers","method","clearTimeout","dismiss","ok","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","console","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,OAAOC,WAAW,QAAO;AAOzB,OAAO,MAAMC,mBAA6B;IACxC,MAAM,EAAEC,CAAC,EAAE,GAAGH;IACd,MAAM,EACJI,QAAQ,EACNC,QAAQ,EAAEC,GAAG,EAAE,EACfC,SAAS,EACV,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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AAE;YAC1CL,SAAS5B,IAAI,CAACkC,WAAW,CAACP;YAC1BA,EAAEQ,KAAK;YACPP,SAAS5B,IAAI,CAACoC,WAAW,CAACT;YAC1BF,IAAIY,eAAe,CAACb;QACtB,EAAE,OAAOc,OAAO;YACdC,QAAQD,KAAK,CAAC,2BAA2BA;YACzCtE,MAAMsE,KAAK,CAAC;QACd;IACF;IAEA,qBACE,MAAChE,MAAMkE,QAAQ;;YACZ,CAACrD,6BAAe,KAACpB;gBAAWwB,OAAOA;;YACnC,CAACD,iCACA,KAACxB;gBAAO2E,UAAU,CAACzD;gBAAU0D,SAASlD;gBAAgBmD,MAAK;gBAASpB,MAAK;0BACvE,cAAA,KAACtD;oBAAY2E,SAAQ;oBAAkBpE,GAAGA;;;;;AAKpD,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FieldsToExport/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAkBzD,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FieldsToExport/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAkBzD,eAAO,MAAM,cAAc,EAAE,0BA2E5B,CAAA"}
|
|
@@ -17,7 +17,9 @@ export const FieldsToExport = (props)=>{
|
|
|
17
17
|
const collectionConfig = getEntityConfig({
|
|
18
18
|
collectionSlug: collectionSlug ?? collection
|
|
19
19
|
});
|
|
20
|
+
const disabledFields = collectionConfig?.admin?.custom?.['plugin-import-export']?.disabledFields ?? [];
|
|
20
21
|
const fieldOptions = reduceFields({
|
|
22
|
+
disabledFields,
|
|
21
23
|
fields: collectionConfig?.fields
|
|
22
24
|
});
|
|
23
25
|
useEffect(()=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/FieldsToExport/index.tsx"],"sourcesContent":["'use client'\n\nimport type { SelectFieldClientComponent } from 'payload'\nimport type { ReactNode } from 'react'\n\nimport {\n FieldLabel,\n ReactSelect,\n useConfig,\n useDocumentInfo,\n useField,\n useListQuery,\n} from '@payloadcms/ui'\nimport React, { useEffect } from 'react'\n\nimport { useImportExport } from '../ImportExportProvider/index.js'\nimport { reduceFields } from './reduceFields.js'\n\nconst baseClass = 'fields-to-export'\n\nexport const FieldsToExport: SelectFieldClientComponent = (props) => {\n const { id } = useDocumentInfo()\n const { setValue, value } = useField<string[]>()\n const { value: collectionSlug } = useField<string>({ path: 'collectionSlug' })\n const { getEntityConfig } = useConfig()\n const { collection } = useImportExport()\n const { query } = useListQuery()\n\n const collectionConfig = getEntityConfig({ collectionSlug: collectionSlug ?? collection })\n const fieldOptions = reduceFields({
|
|
1
|
+
{"version":3,"sources":["../../../src/components/FieldsToExport/index.tsx"],"sourcesContent":["'use client'\n\nimport type { SelectFieldClientComponent } from 'payload'\nimport type { ReactNode } from 'react'\n\nimport {\n FieldLabel,\n ReactSelect,\n useConfig,\n useDocumentInfo,\n useField,\n useListQuery,\n} from '@payloadcms/ui'\nimport React, { useEffect } from 'react'\n\nimport { useImportExport } from '../ImportExportProvider/index.js'\nimport { reduceFields } from './reduceFields.js'\n\nconst baseClass = 'fields-to-export'\n\nexport const FieldsToExport: SelectFieldClientComponent = (props) => {\n const { id } = useDocumentInfo()\n const { setValue, value } = useField<string[]>()\n const { value: collectionSlug } = useField<string>({ path: 'collectionSlug' })\n const { getEntityConfig } = useConfig()\n const { collection } = useImportExport()\n const { query } = useListQuery()\n\n const collectionConfig = getEntityConfig({ collectionSlug: collectionSlug ?? collection })\n\n const disabledFields =\n collectionConfig?.admin?.custom?.['plugin-import-export']?.disabledFields ?? []\n\n const fieldOptions = reduceFields({\n disabledFields,\n fields: collectionConfig?.fields,\n })\n\n useEffect(() => {\n if (id || !collectionSlug) {\n return\n }\n\n const queryColumns = query?.columns\n\n if (Array.isArray(queryColumns)) {\n const cleanColumns = queryColumns.filter(\n (col): col is string => typeof col === 'string' && !col.startsWith('-'),\n )\n // If columns are specified in the query, use them\n setValue(cleanColumns)\n } else {\n // Fallback if no columns in query\n setValue(collectionConfig?.admin?.defaultColumns ?? [])\n }\n }, [id, collectionSlug, query?.columns, collectionConfig?.admin?.defaultColumns, setValue])\n\n const onChange = (options: { id: string; label: ReactNode; value: string }[]) => {\n if (!options) {\n setValue([])\n return\n }\n\n const updatedValue = options.map((option) =>\n typeof option === 'object' ? option.value : option,\n )\n\n setValue(updatedValue)\n }\n\n return (\n <div className={baseClass}>\n <FieldLabel label={props.field.label} path={props.path} />\n <ReactSelect\n className={baseClass}\n disabled={props.readOnly}\n getOptionValue={(option) => String(option.value)}\n inputId={`field-${props.path.replace(/\\./g, '__')}`}\n isClearable={true}\n isMulti={true}\n isSortable={true}\n // @ts-expect-error react select option\n onChange={onChange}\n options={fieldOptions}\n value={\n Array.isArray(value)\n ? value.map((val) => {\n const match = fieldOptions.find((opt) => opt.value === val)\n return match ? { ...match, id: val } : { id: val, label: val, value: val }\n })\n : []\n }\n />\n </div>\n )\n}\n"],"names":["FieldLabel","ReactSelect","useConfig","useDocumentInfo","useField","useListQuery","React","useEffect","useImportExport","reduceFields","baseClass","FieldsToExport","props","id","setValue","value","collectionSlug","path","getEntityConfig","collection","query","collectionConfig","disabledFields","admin","custom","fieldOptions","fields","queryColumns","columns","Array","isArray","cleanColumns","filter","col","startsWith","defaultColumns","onChange","options","updatedValue","map","option","div","className","label","field","disabled","readOnly","getOptionValue","String","inputId","replace","isClearable","isMulti","isSortable","val","match","find","opt"],"mappings":"AAAA;;AAKA,SACEA,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,YAAY,QACP,iBAAgB;AACvB,OAAOC,SAASC,SAAS,QAAQ,QAAO;AAExC,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,YAAY,QAA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OAAO/B,MAAMgC,KAAK,CAACD,KAAK;gBAAE1B,MAAML,MAAMK,IAAI;;0BACtD,KAAChB;gBACCyC,WAAWhC;gBACXmC,UAAUjC,MAAMkC,QAAQ;gBACxBC,gBAAgB,CAACP,SAAWQ,OAAOR,OAAOzB,KAAK;gBAC/CkC,SAAS,CAAC,MAAM,EAAErC,MAAMK,IAAI,CAACiC,OAAO,CAAC,OAAO,OAAO;gBACnDC,aAAa;gBACbC,SAAS;gBACTC,YAAY;gBACZ,uCAAuC;gBACvCjB,UAAUA;gBACVC,SAASZ;gBACTV,OACEc,MAAMC,OAAO,CAACf,SACVA,MAAMwB,GAAG,CAAC,CAACe;oBACT,MAAMC,QAAQ9B,aAAa+B,IAAI,CAAC,CAACC,MAAQA,IAAI1C,KAAK,KAAKuC;oBACvD,OAAOC,QAAQ;wBAAE,GAAGA,KAAK;wBAAE1C,IAAIyC;oBAAI,IAAI;wBAAEzC,IAAIyC;wBAAKX,OAAOW;wBAAKvC,OAAOuC;oBAAI;gBAC3E,KACA,EAAE;;;;AAKhB,EAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ClientField } from 'payload';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
export declare const reduceFields: ({ fields, labelPrefix, path, }: {
|
|
3
|
+
export declare const reduceFields: ({ disabledFields, fields, labelPrefix, path, }: {
|
|
4
|
+
disabledFields?: string[];
|
|
4
5
|
fields: ClientField[];
|
|
5
6
|
labelPrefix?: React.ReactNode;
|
|
6
7
|
path?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reduceFields.d.ts","sourceRoot":"","sources":["../../../src/components/FieldsToExport/reduceFields.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAG1C,OAAO,KAAmB,MAAM,OAAO,CAAA;AAyCvC,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"reduceFields.d.ts","sourceRoot":"","sources":["../../../src/components/FieldsToExport/reduceFields.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAG1C,OAAO,KAAmB,MAAM,OAAO,CAAA;AAyCvC,eAAO,MAAM,YAAY,mDAKtB;IACD,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,KAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAiExD,CAAA"}
|
|
@@ -36,7 +36,7 @@ const combineLabel = ({ field, prefix })=>{
|
|
|
36
36
|
]
|
|
37
37
|
});
|
|
38
38
|
};
|
|
39
|
-
export const reduceFields = ({ fields, labelPrefix = null, path = '' })=>{
|
|
39
|
+
export const reduceFields = ({ disabledFields = [], fields, labelPrefix = null, path = '' })=>{
|
|
40
40
|
if (!fields) {
|
|
41
41
|
return [];
|
|
42
42
|
}
|
|
@@ -49,6 +49,7 @@ export const reduceFields = ({ fields, labelPrefix = null, path = '' })=>{
|
|
|
49
49
|
return [
|
|
50
50
|
...fieldsToUse,
|
|
51
51
|
...reduceFields({
|
|
52
|
+
disabledFields,
|
|
52
53
|
fields: field.fields,
|
|
53
54
|
labelPrefix: combineLabel({
|
|
54
55
|
field,
|
|
@@ -67,6 +68,7 @@ export const reduceFields = ({ fields, labelPrefix = null, path = '' })=>{
|
|
|
67
68
|
return [
|
|
68
69
|
...tabFields,
|
|
69
70
|
...reduceFields({
|
|
71
|
+
disabledFields,
|
|
70
72
|
fields: tab.fields,
|
|
71
73
|
labelPrefix,
|
|
72
74
|
path: isNamedTab ? createNestedClientFieldPath(path, field) : path
|
|
@@ -78,6 +80,10 @@ export const reduceFields = ({ fields, labelPrefix = null, path = '' })=>{
|
|
|
78
80
|
];
|
|
79
81
|
}
|
|
80
82
|
const val = createNestedClientFieldPath(path, field);
|
|
83
|
+
// If the field is disabled, skip it
|
|
84
|
+
if (disabledFields.includes(val)) {
|
|
85
|
+
return fieldsToUse;
|
|
86
|
+
}
|
|
81
87
|
const formattedField = {
|
|
82
88
|
id: val,
|
|
83
89
|
label: combineLabel({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/FieldsToExport/reduceFields.tsx"],"sourcesContent":["import type { ClientField } from 'payload'\n\nimport { fieldAffectsData, fieldHasSubFields } from 'payload/shared'\nimport React, { Fragment } from 'react'\n\nconst createNestedClientFieldPath = (parentPath: string, field: ClientField): string => {\n if (parentPath) {\n if (fieldAffectsData(field)) {\n return `${parentPath}.${field.name}`\n }\n return parentPath\n }\n\n if (fieldAffectsData(field)) {\n return field.name\n }\n\n return ''\n}\n\nconst combineLabel = ({\n field,\n prefix,\n}: {\n field: ClientField\n prefix?: React.ReactNode\n}): React.ReactNode => {\n return (\n <Fragment>\n {prefix ? (\n <Fragment>\n <span style={{ display: 'inline-block' }}>{prefix}</span>\n {' > '}\n </Fragment>\n ) : null}\n <span style={{ display: 'inline-block' }}>\n {'label' in field && typeof field.label === 'string'\n ? field.label\n : (('name' in field && field.name) ?? 'unnamed field')}\n </span>\n </Fragment>\n )\n}\n\nexport const reduceFields = ({\n fields,\n labelPrefix = null,\n path = '',\n}: {\n fields: ClientField[]\n labelPrefix?: React.ReactNode\n path?: string\n}): { id: string; label: React.ReactNode; value: string }[] => {\n if (!fields) {\n return []\n }\n\n return fields.reduce<{ id: string; label: React.ReactNode; value: string }[]>(\n (fieldsToUse, field) => {\n // escape for a variety of reasons, include ui fields as they have `name`.\n if (field.type === 'ui') {\n return fieldsToUse\n }\n\n if (!(field.type === 'array' || field.type === 'blocks') && fieldHasSubFields(field)) {\n return [\n ...fieldsToUse,\n ...reduceFields({\n fields: field.fields,\n labelPrefix: combineLabel({ field, prefix: labelPrefix }),\n path: createNestedClientFieldPath(path, field),\n }),\n ]\n }\n\n if (field.type === 'tabs' && 'tabs' in field) {\n return [\n ...fieldsToUse,\n ...field.tabs.reduce<{ id: string; label: React.ReactNode; value: string }[]>(\n (tabFields, tab) => {\n if ('fields' in tab) {\n const isNamedTab = 'name' in tab && tab.name\n return [\n ...tabFields,\n ...reduceFields({\n fields: tab.fields,\n labelPrefix,\n path: isNamedTab ? createNestedClientFieldPath(path, field) : path,\n }),\n ]\n }\n return tabFields\n },\n [],\n ),\n ]\n }\n\n const val = createNestedClientFieldPath(path, field)\n\n const formattedField = {\n id: val,\n label: combineLabel({ field, prefix: labelPrefix }),\n value: val,\n }\n\n return [...fieldsToUse, formattedField]\n },\n [],\n )\n}\n"],"names":["fieldAffectsData","fieldHasSubFields","React","Fragment","createNestedClientFieldPath","parentPath","field","name","combineLabel","prefix","span","style","display","label","reduceFields","fields","labelPrefix","path","reduce","fieldsToUse","type","tabs","tabFields","tab","isNamedTab","val","formattedField","id","value"],"mappings":";AAEA,SAASA,gBAAgB,EAAEC,iBAAiB,QAAQ,iBAAgB;AACpE,OAAOC,SAASC,QAAQ,QAAQ,QAAO;AAEvC,MAAMC,8BAA8B,CAACC,YAAoBC;IACvD,IAAID,YAAY;QACd,IAAIL,iBAAiBM,QAAQ;YAC3B,OAAO,GAAGD,WAAW,CAAC,EAAEC,MAAMC,IAAI,EAAE;QACtC;QACA,OAAOF;IACT;IAEA,IAAIL,iBAAiBM,QAAQ;QAC3B,OAAOA,MAAMC,IAAI;IACnB;IAEA,OAAO;AACT;AAEA,MAAMC,eAAe,CAAC,EACpBF,KAAK,EACLG,MAAM,EAIP;IACC,qBACE,MAACN;;YACEM,uBACC,MAACN;;kCACC,KAACO;wBAAKC,OAAO;4BAAEC,SAAS;wBAAe;kCAAIH;;oBAC1C;;iBAED;0BACJ,KAACC;gBAAKC,OAAO;oBAAEC,SAAS;gBAAe;0BACpC,WAAWN,SAAS,OAAOA,MAAMO,KAAK,KAAK,WACxCP,MAAMO,KAAK,GACV,AAAC,CAAA,UAAUP,SAASA,MAAMC,IAAI,AAAD,KAAM;;;;AAIhD;AAEA,OAAO,MAAMO,eAAe,CAAC,EAC3BC,MAAM,EACNC,cAAc,IAAI,EAClBC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"sources":["../../../src/components/FieldsToExport/reduceFields.tsx"],"sourcesContent":["import type { ClientField } from 'payload'\n\nimport { fieldAffectsData, fieldHasSubFields } from 'payload/shared'\nimport React, { Fragment } from 'react'\n\nconst createNestedClientFieldPath = (parentPath: string, field: ClientField): string => {\n if (parentPath) {\n if (fieldAffectsData(field)) {\n return `${parentPath}.${field.name}`\n }\n return parentPath\n }\n\n if (fieldAffectsData(field)) {\n return field.name\n }\n\n return ''\n}\n\nconst combineLabel = ({\n field,\n prefix,\n}: {\n field: ClientField\n prefix?: React.ReactNode\n}): React.ReactNode => {\n return (\n <Fragment>\n {prefix ? (\n <Fragment>\n <span style={{ display: 'inline-block' }}>{prefix}</span>\n {' > '}\n </Fragment>\n ) : null}\n <span style={{ display: 'inline-block' }}>\n {'label' in field && typeof field.label === 'string'\n ? field.label\n : (('name' in field && field.name) ?? 'unnamed field')}\n </span>\n </Fragment>\n )\n}\n\nexport const reduceFields = ({\n disabledFields = [],\n fields,\n labelPrefix = null,\n path = '',\n}: {\n disabledFields?: string[]\n fields: ClientField[]\n labelPrefix?: React.ReactNode\n path?: string\n}): { id: string; label: React.ReactNode; value: string }[] => {\n if (!fields) {\n return []\n }\n\n return fields.reduce<{ id: string; label: React.ReactNode; value: string }[]>(\n (fieldsToUse, field) => {\n // escape for a variety of reasons, include ui fields as they have `name`.\n if (field.type === 'ui') {\n return fieldsToUse\n }\n\n if (!(field.type === 'array' || field.type === 'blocks') && fieldHasSubFields(field)) {\n return [\n ...fieldsToUse,\n ...reduceFields({\n disabledFields,\n fields: field.fields,\n labelPrefix: combineLabel({ field, prefix: labelPrefix }),\n path: createNestedClientFieldPath(path, field),\n }),\n ]\n }\n\n if (field.type === 'tabs' && 'tabs' in field) {\n return [\n ...fieldsToUse,\n ...field.tabs.reduce<{ id: string; label: React.ReactNode; value: string }[]>(\n (tabFields, tab) => {\n if ('fields' in tab) {\n const isNamedTab = 'name' in tab && tab.name\n return [\n ...tabFields,\n ...reduceFields({\n disabledFields,\n fields: tab.fields,\n labelPrefix,\n path: isNamedTab ? createNestedClientFieldPath(path, field) : path,\n }),\n ]\n }\n return tabFields\n },\n [],\n ),\n ]\n }\n\n const val = createNestedClientFieldPath(path, field)\n\n // If the field is disabled, skip it\n if (disabledFields.includes(val)) {\n return fieldsToUse\n }\n\n const formattedField = {\n id: val,\n label: combineLabel({ field, prefix: labelPrefix }),\n value: val,\n }\n\n return [...fieldsToUse, formattedField]\n },\n [],\n )\n}\n"],"names":["fieldAffectsData","fieldHasSubFields","React","Fragment","createNestedClientFieldPath","parentPath","field","name","combineLabel","prefix","span","style","display","label","reduceFields","disabledFields","fields","labelPrefix","path","reduce","fieldsToUse","type","tabs","tabFields","tab","isNamedTab","val","includes","formattedField","id","value"],"mappings":";AAEA,SAASA,gBAAgB,EAAEC,iBAAiB,QAAQ,iBAAgB;AACpE,OAAOC,SAASC,QAAQ,QAAQ,QAAO;AAEvC,MAAMC,8BAA8B,CAACC,YAAoBC;IACvD,IAAID,YAAY;QACd,IAAIL,iBAAiBM,QAAQ;YAC3B,OAAO,GAAGD,WAAW,CAAC,EAAEC,MAAMC,IAAI,EAAE;QACtC;QACA,OAAOF;IACT;IAEA,IAAIL,iBAAiBM,QAAQ;QAC3B,OAAOA,MAAMC,IAAI;IACnB;IAEA,OAAO;AACT;AAEA,MAAMC,eAAe,CAAC,EACpBF,KAAK,EACLG,MAAM,EAIP;IACC,qBACE,MAACN;;YACEM,uBACC,MAACN;;kCACC,KAACO;wBAAKC,OAAO;4BAAEC,SAAS;wBAAe;kCAAIH;;oBAC1C;;iBAED;0BACJ,KAACC;gBAAKC,OAAO;oBAAEC,SAAS;gBAAe;0BACpC,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a;gBAAEF;gBAAOG,QAAQQ;YAAY;YACjDa,OAAOJ;QACT;QAEA,OAAO;eAAIN;YAAaQ;SAAe;IACzC,GACA,EAAE;AAEN,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Preview/index.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,MAAM,OAAO,CAAA;AAQzB,OAAO,cAAc,CAAA;AAIrB,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Preview/index.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,MAAM,OAAO,CAAA;AAQzB,OAAO,cAAc,CAAA;AAIrB,eAAO,MAAM,OAAO,yBAmKnB,CAAA"}
|
|
@@ -36,6 +36,11 @@ export const Preview = ()=>{
|
|
|
36
36
|
const { i18n, t } = useTranslation();
|
|
37
37
|
const collectionSlug = typeof collection === 'string' && collection;
|
|
38
38
|
const collectionConfig = config.collections.find((collection)=>collection.slug === collectionSlug);
|
|
39
|
+
const disabledFieldsUnderscored = React.useMemo(()=>{
|
|
40
|
+
return collectionConfig?.admin?.custom?.['plugin-import-export']?.disabledFields?.map((f)=>f.replace(/\./g, '_')) ?? [];
|
|
41
|
+
}, [
|
|
42
|
+
collectionConfig
|
|
43
|
+
]);
|
|
39
44
|
const isCSV = format === 'csv';
|
|
40
45
|
React.useEffect(()=>{
|
|
41
46
|
const fetchData = async ()=>{
|
|
@@ -80,7 +85,7 @@ export const Preview = ()=>{
|
|
|
80
85
|
const selectedKeys = Array.isArray(fields) && fields.length > 0 ? fields.flatMap((field)=>{
|
|
81
86
|
const regex = fieldToRegex(field);
|
|
82
87
|
return allKeys.filter((key)=>regex.test(key));
|
|
83
|
-
}) : allKeys.filter((key)=>!defaultMetaFields.includes(key));
|
|
88
|
+
}) : allKeys.filter((key)=>!defaultMetaFields.includes(key) && !disabledFieldsUnderscored.includes(key));
|
|
84
89
|
const fieldKeys = Array.isArray(fields) && fields.length > 0 ? selectedKeys // strictly only what was selected
|
|
85
90
|
: [
|
|
86
91
|
...selectedKeys,
|
|
@@ -119,6 +124,7 @@ export const Preview = ()=>{
|
|
|
119
124
|
}, [
|
|
120
125
|
collectionConfig,
|
|
121
126
|
collectionSlug,
|
|
127
|
+
disabledFieldsUnderscored,
|
|
122
128
|
draft,
|
|
123
129
|
fields,
|
|
124
130
|
i18n,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Preview/index.tsx"],"sourcesContent":["'use client'\nimport type { Column } from '@payloadcms/ui'\nimport type { ClientField } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n CodeEditorLazy,\n Table,\n Translation,\n useConfig,\n useField,\n useTranslation,\n} from '@payloadcms/ui'\nimport React from 'react'\n\nimport type {\n PluginImportExportTranslationKeys,\n PluginImportExportTranslations,\n} from '../../translations/index.js'\n\nimport { useImportExport } from '../ImportExportProvider/index.js'\nimport './index.scss'\n\nconst baseClass = 'preview'\n\nexport const Preview = () => {\n const { collection } = useImportExport()\n const { config } = useConfig()\n const { value: where } = useField({ path: 'where' })\n const { value: limit } = useField<number>({ path: 'limit' })\n const { value: fields } = useField<string[]>({ path: 'fields' })\n const { value: sort } = useField({ path: 'sort' })\n const { value: draft } = useField({ path: 'drafts' })\n const { value: locale } = useField({ path: 'locale' })\n const { value: format } = useField({ path: 'format' })\n const [dataToRender, setDataToRender] = React.useState<any[]>([])\n const [resultCount, setResultCount] = React.useState<any>('')\n const [columns, setColumns] = React.useState<Column[]>([])\n const { i18n, t } = useTranslation<\n PluginImportExportTranslations,\n PluginImportExportTranslationKeys\n >()\n\n const collectionSlug = typeof collection === 'string' && collection\n const collectionConfig = config.collections.find(\n (collection) => collection.slug === collectionSlug,\n )\n\n const isCSV = format === 'csv'\n\n React.useEffect(() => {\n const fetchData = async () => {\n if (!collectionSlug || !collectionConfig) {\n return\n }\n\n try {\n const res = await fetch('/api/preview-data', {\n body: JSON.stringify({\n collectionSlug,\n draft,\n fields,\n limit,\n locale,\n sort,\n where,\n }),\n credentials: 'include',\n headers: { 'Content-Type': 'application/json' },\n method: 'POST',\n })\n\n if (!res.ok) {\n return\n }\n\n const { docs, totalDocs }: { docs: Record<string, unknown>[]; totalDocs: number } =\n await res.json()\n\n setResultCount(limit && limit < totalDocs ? limit : totalDocs)\n\n const allKeys = Array.from(new Set(docs.flatMap((doc) => Object.keys(doc))))\n const defaultMetaFields = ['createdAt', 'updatedAt', '_status', 'id']\n\n // Match CSV column ordering by building keys based on fields and regex\n const fieldToRegex = (field: string): RegExp => {\n const parts = field.split('.').map((part) => `${part}(?:_\\\\d+)?`)\n return new RegExp(`^${parts.join('_')}`)\n }\n\n // Construct final list of field keys to match field order + meta order\n const selectedKeys =\n Array.isArray(fields) && fields.length > 0\n ? fields.flatMap((field) => {\n const regex = fieldToRegex(field)\n return allKeys.filter((key) => regex.test(key))\n })\n : allKeys.filter((key) => !defaultMetaFields.includes(key))\n\n const fieldKeys =\n Array.isArray(fields) && fields.length > 0\n ? selectedKeys // strictly only what was selected\n : [...selectedKeys, ...defaultMetaFields.filter((key) => allKeys.includes(key))]\n\n // Build columns based on flattened keys\n const newColumns: Column[] = fieldKeys.map((key) => ({\n accessor: key,\n active: true,\n field: { name: key } as ClientField,\n Heading: getTranslation(key, i18n),\n renderedCells: docs.map((doc: Record<string, unknown>) => {\n const val = doc[key]\n\n if (val === undefined || val === null) {\n return null\n }\n\n // Avoid ESLint warning by type-checking before calling String()\n if (typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean') {\n return String(val)\n }\n\n if (Array.isArray(val)) {\n return val.map(String).join(', ')\n }\n\n return JSON.stringify(val)\n }),\n }))\n\n setColumns(newColumns)\n setDataToRender(docs)\n } catch (error) {\n console.error('Error fetching preview data:', error)\n }\n }\n\n void fetchData()\n }, [collectionConfig, collectionSlug, draft, fields, i18n, limit, locale, sort, where])\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__header`}>\n <h3>\n <Translation i18nKey=\"version:preview\" t={t} />\n </h3>\n {resultCount && (\n <Translation\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n i18nKey=\"plugin-import-export:totalDocumentsCount\"\n t={t}\n variables={{\n count: resultCount,\n }}\n />\n )}\n </div>\n {dataToRender &&\n (isCSV ? (\n <Table columns={columns} data={dataToRender} />\n ) : (\n <CodeEditorLazy language=\"json\" readOnly value={JSON.stringify(dataToRender, null, 2)} />\n ))}\n </div>\n )\n}\n"],"names":["getTranslation","CodeEditorLazy","Table","Translation","useConfig","useField","useTranslation","React","useImportExport","baseClass","Preview","collection","config","value","where","path","limit","fields","sort","draft","locale","format","dataToRender","setDataToRender","useState","resultCount","setResultCount","columns","setColumns","i18n","t","collectionSlug","collectionConfig","collections","find","slug","isCSV","useEffect","fetchData","res","fetch","body","JSON","stringify","credentials","headers","method","ok","docs","totalDocs","json","allKeys","Array","from","Set","flatMap","doc","Object","keys","defaultMetaFields","fieldToRegex","field","parts","split","map","part","RegExp","join","selectedKeys","isArray","length","regex","filter","key","test","includes","fieldKeys","newColumns","accessor","active","name","Heading","renderedCells","val","undefined","String","error","console","div","className","h3","i18nKey","variables","count","data","language","readOnly"],"mappings":"AAAA;;AAIA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SACEC,cAAc,EACdC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,QAAQ,EACRC,cAAc,QACT,iBAAgB;AACvB,OAAOC,WAAW,QAAO;AAOzB,SAASC,eAAe,QAAQ,mCAAkC;AAClE,OAAO,eAAc;AAErB,MAAMC,YAAY;AAElB,OAAO,MAAMC,UAAU;IACrB,MAAM,EAAEC,UAAU,EAAE,GAAGH;IACvB,MAAM,EAAEI,MAAM,EAAE,GAAGR;IACnB,MAAM,EAAES,OAAOC,KAAK,EAAE,GAAGT,SAAS;QAAEU,MAAM;IAAQ;IAClD,MAAM,EAAEF,OAAOG,KAAK,EAAE,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IU,QAAQC,aAAaD,QAAQ,MAAM;gCACrC,OAAO;4BACT;4BAEA,gEAAgE;4BAChE,IAAI,OAAOA,QAAQ,YAAY,OAAOA,QAAQ,YAAY,OAAOA,QAAQ,WAAW;gCAClF,OAAOE,OAAOF;4BAChB;4BAEA,IAAI/B,MAAMiB,OAAO,CAACc,MAAM;gCACtB,OAAOA,IAAInB,GAAG,CAACqB,QAAQlB,IAAI,CAAC;4BAC9B;4BAEA,OAAOzB,KAAKC,SAAS,CAACwC;wBACxB;oBACF,CAAA;gBAEAvD,WAAWiD;gBACXtD,gBAAgByB;YAClB,EAAE,OAAOsC,OAAO;gBACdC,QAAQD,KAAK,CAAC,gCAAgCA;YAChD;QACF;QAEA,KAAKhD;IACP,GAAG;QAACN;QAAkBD;QAAgBZ;QAAOF;QAAQY;QAAMb;QAAOI;QAAQF;QAAMJ;KAAM;IAEtF,qBACE,MAAC0E;QAAIC,WAAWhF;;0BACd,MAAC+E;gBAAIC,WAAW,GAAGhF,UAAU,QAAQ,CAAC;;kCACpC,KAACiF;kCACC,cAAA,KAACvF;4BAAYwF,SAAQ;4BAAkB7D,GAAGA;;;oBAE3CL,6BACC,KAACtB;wBACC,6DAA6D;wBAC7D,mBAAmB;wBACnBwF,SAAQ;wBACR7D,GAAGA;wBACH8D,WAAW;4BACTC,OAAOpE;wBACT;;;;YAILH,gBACEc,CAAAA,sBACC,KAAClC;gBAAMyB,SAASA;gBAASmE,MAAMxE;+BAE/B,KAACrB;gBAAe8F,UAAS;gBAAOC,QAAQ;gBAACnF,OAAO6B,KAAKC,SAAS,CAACrB,cAAc,MAAM;cACrF;;;AAGR,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Preview/index.tsx"],"sourcesContent":["'use client'\nimport type { Column } from '@payloadcms/ui'\nimport type { ClientField } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n CodeEditorLazy,\n Table,\n Translation,\n useConfig,\n useField,\n useTranslation,\n} from '@payloadcms/ui'\nimport React from 'react'\n\nimport type {\n PluginImportExportTranslationKeys,\n PluginImportExportTranslations,\n} from '../../translations/index.js'\n\nimport { useImportExport } from '../ImportExportProvider/index.js'\nimport './index.scss'\n\nconst baseClass = 'preview'\n\nexport const Preview = () => {\n const { collection } = useImportExport()\n const { config } = useConfig()\n const { value: where } = useField({ path: 'where' })\n const { value: limit } = useField<number>({ path: 'limit' })\n const { value: fields } = useField<string[]>({ path: 'fields' })\n const { value: sort } = useField({ path: 'sort' })\n const { value: draft } = useField({ path: 'drafts' })\n const { value: locale } = useField({ path: 'locale' })\n const { value: format } = useField({ path: 'format' })\n const [dataToRender, setDataToRender] = React.useState<any[]>([])\n const [resultCount, setResultCount] = React.useState<any>('')\n const [columns, setColumns] = React.useState<Column[]>([])\n const { i18n, t } = useTranslation<\n PluginImportExportTranslations,\n PluginImportExportTranslationKeys\n >()\n\n const collectionSlug = typeof collection === 'string' && collection\n const collectionConfig = config.collections.find(\n (collection) => collection.slug === collectionSlug,\n )\n\n const disabledFieldsUnderscored = React.useMemo(() => {\n return (\n collectionConfig?.admin?.custom?.['plugin-import-export']?.disabledFields?.map((f: string) =>\n f.replace(/\\./g, '_'),\n ) ?? []\n )\n }, [collectionConfig])\n\n const isCSV = format === 'csv'\n\n React.useEffect(() => {\n const fetchData = async () => {\n if (!collectionSlug || !collectionConfig) {\n return\n }\n\n try {\n const res = await fetch('/api/preview-data', {\n body: JSON.stringify({\n collectionSlug,\n draft,\n fields,\n limit,\n locale,\n sort,\n where,\n }),\n credentials: 'include',\n headers: { 'Content-Type': 'application/json' },\n method: 'POST',\n })\n\n if (!res.ok) {\n return\n }\n\n const { docs, totalDocs }: { docs: Record<string, unknown>[]; totalDocs: number } =\n await res.json()\n\n setResultCount(limit && limit < totalDocs ? limit : totalDocs)\n\n const allKeys = Array.from(new Set(docs.flatMap((doc) => Object.keys(doc))))\n const defaultMetaFields = ['createdAt', 'updatedAt', '_status', 'id']\n\n // Match CSV column ordering by building keys based on fields and regex\n const fieldToRegex = (field: string): RegExp => {\n const parts = field.split('.').map((part) => `${part}(?:_\\\\d+)?`)\n return new RegExp(`^${parts.join('_')}`)\n }\n\n // Construct final list of field keys to match field order + meta order\n const selectedKeys =\n Array.isArray(fields) && fields.length > 0\n ? fields.flatMap((field) => {\n const regex = fieldToRegex(field)\n return allKeys.filter((key) => regex.test(key))\n })\n : allKeys.filter(\n (key) =>\n !defaultMetaFields.includes(key) && !disabledFieldsUnderscored.includes(key),\n )\n\n const fieldKeys =\n Array.isArray(fields) && fields.length > 0\n ? selectedKeys // strictly only what was selected\n : [...selectedKeys, ...defaultMetaFields.filter((key) => allKeys.includes(key))]\n\n // Build columns based on flattened keys\n const newColumns: Column[] = fieldKeys.map((key) => ({\n accessor: key,\n active: true,\n field: { name: key } as ClientField,\n Heading: getTranslation(key, i18n),\n renderedCells: docs.map((doc: Record<string, unknown>) => {\n const val = doc[key]\n\n if (val === undefined || val === null) {\n return null\n }\n\n // Avoid ESLint warning by type-checking before calling String()\n if (typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean') {\n return String(val)\n }\n\n if (Array.isArray(val)) {\n return val.map(String).join(', ')\n }\n\n return JSON.stringify(val)\n }),\n }))\n\n setColumns(newColumns)\n setDataToRender(docs)\n } catch (error) {\n console.error('Error fetching preview data:', error)\n }\n }\n\n void fetchData()\n }, [\n collectionConfig,\n collectionSlug,\n disabledFieldsUnderscored,\n draft,\n fields,\n i18n,\n limit,\n locale,\n sort,\n where,\n ])\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__header`}>\n <h3>\n <Translation i18nKey=\"version:preview\" t={t} />\n </h3>\n {resultCount && (\n <Translation\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n i18nKey=\"plugin-import-export:totalDocumentsCount\"\n t={t}\n variables={{\n count: resultCount,\n }}\n />\n )}\n </div>\n {dataToRender &&\n (isCSV ? (\n <Table columns={columns} data={dataToRender} />\n ) : (\n <CodeEditorLazy language=\"json\" readOnly value={JSON.stringify(dataToRender, null, 2)} />\n ))}\n </div>\n )\n}\n"],"names":["getTranslation","CodeEditorLazy","Table","Translation","useConfig","useField","useTranslation","React","useImportExport","baseClass","Preview","collection","config","value","where","path","limit","fields","sort","draft","locale","format","dataToRender","setDataToRender","useState","resultCount","setResultCount","columns","setColumns","i18n","t","collectionSlug","collectionConfig","collections","find","slug","disabledFieldsUnderscored","useMemo","admin","custom","disabledFields","map","f","replace","isCSV","useEffect","fetchData","res","fetch","body","JSON","stringify","credentials","headers","method","ok","docs","totalDocs","json","allKeys","Array","from","Set","flatMap","doc","Object","keys","defaultMetaFields","fieldToRegex","field","parts","split","part","RegExp","join","selectedKeys","isArray","length","regex","filter","key","test","includes","fieldKeys","newColumns","accessor","active","name","Heading","renderedCells","val","undefined","String","error","console","div","className","h3","i18nKey","variables","count","data","language","readOnly"],"mappings":"AAAA;;AAIA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SACEC,cAAc,EACdC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,QAAQ,EACRC,cAAc,QACT,iBAAgB;AACvB,OAAOC,WAAW,QAAO;AAOzB,SAASC,eAAe,QAAQ,mCAAkC;AAClE,OAAO,eAAc;AAErB,MAAMC,YAAY;AAElB,OAAO,MAAMC,UAAU;IACrB,MAAM,EAAEC,UAAU,EAAE,GAAGH;IACvB,MAAM,EAAEI,MAAM,EAAE,GAAGR;IACnB,MAAM,EAAES,OAAOC,KAAK,EAAE,GAAGT,SAAS;QAAEU,MAAM;IAAQ;IAClD,MAAM,EAAEF,OAAOG,KAAK,EAAE,GAAGX,SAAiB;QAAEU,MAAM;IAAQ;IAC1D,MAAM,EAAEF,OAAOI,MAAM,EAAE,GAAGZ,SAAmB;QAAEU,MAAM;IAAS;IAC9D,MAAM,EAAEF,OAAOK,IAAI,EAAE,GAAGb,SAAS;QAAEU,MAAM;IAAO;IAChD,MAAM,EAAEF,OAAOM,KAAK,EAAE,GAAGd,SAAS;QAAEU,MAAM;IAAS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,QAAQ,MAAM;gCACrC,OAAO;4BACT;4BAEA,gEAAgE;4BAChE,IAAI,OAAOA,QAAQ,YAAY,OAAOA,QAAQ,YAAY,OAAOA,QAAQ,WAAW;gCAClF,OAAOE,OAAOF;4BAChB;4BAEA,IAAI9B,MAAMgB,OAAO,CAACc,MAAM;gCACtB,OAAOA,IAAIjD,GAAG,CAACmD,QAAQlB,IAAI,CAAC;4BAC9B;4BAEA,OAAOxB,KAAKC,SAAS,CAACuC;wBACxB;oBACF,CAAA;gBAEA9D,WAAWwD;gBACX7D,gBAAgBiC;YAClB,EAAE,OAAOqC,OAAO;gBACdC,QAAQD,KAAK,CAAC,gCAAgCA;YAChD;QACF;QAEA,KAAK/C;IACP,GAAG;QACDd;QACAD;QACAK;QACAjB;QACAF;QACAY;QACAb;QACAI;QACAF;QACAJ;KACD;IAED,qBACE,MAACiF;QAAIC,WAAWvF;;0BACd,MAACsF;gBAAIC,WAAW,GAAGvF,UAAU,QAAQ,CAAC;;kCACpC,KAACwF;kCACC,cAAA,KAAC9F;4BAAY+F,SAAQ;4BAAkBpE,GAAGA;;;oBAE3CL,6BACC,KAACtB;wBACC,6DAA6D;wBAC7D,mBAAmB;wBACnB+F,SAAQ;wBACRpE,GAAGA;wBACHqE,WAAW;4BACTC,OAAO3E;wBACT;;;;YAILH,gBACEsB,CAAAA,sBACC,KAAC1C;gBAAMyB,SAASA;gBAAS0E,MAAM/E;+BAE/B,KAACrB;gBAAeqG,UAAS;gBAAOC,QAAQ;gBAAC1F,OAAOqC,KAAKC,SAAS,CAAC7B,cAAc,MAAM;cACrF;;;AAGR,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,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAWrE,MAAM,MAAM,MAAM,GAAG;IACnB,cAA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AAC,EAAE,MAAM,EAAE,CAAA;IAClB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,MAAM,CAAA;IACtB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,cAAc,CAAA;IACnB,IAAI,CAAC,EAAE,SAAS,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,YAAY,SAAgB,gBAAgB,kCAyQxD,CAAA"}
|
|
@@ -54,6 +54,14 @@ export const createExport = async (args)=>{
|
|
|
54
54
|
const toCSVFunctions = getCustomFieldFunctions({
|
|
55
55
|
fields: collectionConfig.flattenedFields
|
|
56
56
|
});
|
|
57
|
+
const disabledFieldsDot = collectionConfig.admin?.custom?.['plugin-import-export']?.disabledFields ?? [];
|
|
58
|
+
const disabledFields = disabledFieldsDot.map((f)=>f.replace(/\./g, '_'));
|
|
59
|
+
const filterDisabled = (row)=>{
|
|
60
|
+
for (const key of disabledFields){
|
|
61
|
+
delete row[key];
|
|
62
|
+
}
|
|
63
|
+
return row;
|
|
64
|
+
};
|
|
57
65
|
if (download) {
|
|
58
66
|
if (debug) {
|
|
59
67
|
req.payload.logger.info('Pre-scanning all columns before streaming');
|
|
@@ -68,11 +76,11 @@ export const createExport = async (args)=>{
|
|
|
68
76
|
page: scanPage
|
|
69
77
|
});
|
|
70
78
|
result.docs.forEach((doc)=>{
|
|
71
|
-
const flat = flattenObject({
|
|
79
|
+
const flat = filterDisabled(flattenObject({
|
|
72
80
|
doc,
|
|
73
81
|
fields,
|
|
74
82
|
toCSVFunctions
|
|
75
|
-
});
|
|
83
|
+
}));
|
|
76
84
|
Object.keys(flat).forEach((key)=>{
|
|
77
85
|
if (!allColumnsSet.has(key)) {
|
|
78
86
|
allColumnsSet.add(key);
|
|
@@ -102,11 +110,11 @@ export const createExport = async (args)=>{
|
|
|
102
110
|
this.push(null);
|
|
103
111
|
return;
|
|
104
112
|
}
|
|
105
|
-
const batchRows = result.docs.map((doc)=>flattenObject({
|
|
113
|
+
const batchRows = result.docs.map((doc)=>filterDisabled(flattenObject({
|
|
106
114
|
doc,
|
|
107
115
|
fields,
|
|
108
116
|
toCSVFunctions
|
|
109
|
-
}));
|
|
117
|
+
})));
|
|
110
118
|
const paddedRows = batchRows.map((row)=>{
|
|
111
119
|
const fullRow = {};
|
|
112
120
|
for (const col of allColumns){
|
|
@@ -156,11 +164,11 @@ export const createExport = async (args)=>{
|
|
|
156
164
|
req.payload.logger.info(`Processing batch ${findArgs.page} with ${result.docs.length} documents`);
|
|
157
165
|
}
|
|
158
166
|
if (isCSV) {
|
|
159
|
-
const batchRows = result.docs.map((doc)=>flattenObject({
|
|
167
|
+
const batchRows = result.docs.map((doc)=>filterDisabled(flattenObject({
|
|
160
168
|
doc,
|
|
161
169
|
fields,
|
|
162
170
|
toCSVFunctions
|
|
163
|
-
}));
|
|
171
|
+
})));
|
|
164
172
|
// Track discovered column keys
|
|
165
173
|
batchRows.forEach((row)=>{
|
|
166
174
|
Object.keys(row).forEach((key)=>{
|
|
@@ -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 { flattenObject } from './flattenObject.js'\nimport { getCustomFieldFunctions } from './getCustomFieldFunctions.js'\nimport { getFilename } from './getFilename.js'\nimport { getSelect } from './getSelect.js'\n\nexport type Export = {\n collectionSlug: string\n /**\n * If true, enables debug logging\n */\n debug?: boolean\n drafts?: 'no' | 'yes'\n exportsCollection: string\n fields?: string[]\n format: 'csv' | 'json'\n globals?: string[]\n id: number | string\n locale?: string\n name: string\n slug: string\n sort: Sort\n user: string\n userCollection: 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 input: Export\n req: PayloadRequest\n user?: TypedUser\n}\n\nexport const createExport = async (args: CreateExportArgs) => {\n const {\n download,\n input: {\n id,\n name: nameArg,\n collectionSlug,\n debug = false,\n drafts,\n exportsCollection,\n fields,\n format,\n locale: localeInput,\n sort,\n user,\n where,\n },\n req: { locale: localeArg, payload },\n req,\n } = args\n\n if (debug) {\n req.payload.logger.info({\n message: 'Starting export process with args:',\n collectionSlug,\n drafts,\n fields,\n format,\n })\n }\n\n const locale = localeInput ?? localeArg\n const collectionConfig = payload.config.collections.find(({ slug }) => slug === collectionSlug)\n if (!collectionConfig) {\n throw new APIError(`Collection with slug ${collectionSlug} not found`)\n }\n\n const name = `${nameArg ?? `${getFilename()}-${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.info({ message: 'Export configuration:', name, isCSV, locale })\n }\n\n const findArgs = {\n collection: collectionSlug,\n depth: 1,\n draft: drafts === 'yes',\n limit: 100,\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.info({ message: 'Find arguments:', findArgs })\n }\n\n const toCSVFunctions = getCustomFieldFunctions({\n fields: collectionConfig.flattenedFields,\n })\n\n if (download) {\n if (debug) {\n req.payload.logger.info('Pre-scanning all columns before streaming')\n }\n\n const allColumnsSet = new Set<string>()\n const allColumns: string[] = []\n let scanPage = 1\n let hasMore = true\n\n while (hasMore) {\n const result = await payload.find({ ...findArgs, page: scanPage })\n\n result.docs.forEach((doc) => {\n const flat = flattenObject({ doc, fields, toCSVFunctions })\n Object.keys(flat).forEach((key) => {\n if (!allColumnsSet.has(key)) {\n allColumnsSet.add(key)\n allColumns.push(key)\n }\n })\n })\n\n hasMore = result.hasNextPage\n scanPage += 1\n }\n\n if (debug) {\n req.payload.logger.info(`Discovered ${allColumns.length} columns`)\n }\n\n const encoder = new TextEncoder()\n let isFirstBatch = true\n let streamPage = 1\n\n const stream = new Readable({\n async read() {\n const result = await payload.find({ ...findArgs, page: streamPage })\n\n if (debug) {\n req.payload.logger.info(`Streaming batch ${streamPage} with ${result.docs.length} docs`)\n }\n\n if (result.docs.length === 0) {\n this.push(null)\n return\n }\n\n const batchRows = result.docs.map((doc) => flattenObject({ doc, fields, toCSVFunctions }))\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 header: isFirstBatch,\n columns: allColumns,\n })\n\n this.push(encoder.encode(csvString))\n isFirstBatch = false\n streamPage += 1\n\n if (!result.hasNextPage) {\n if (debug) {\n req.payload.logger.info('Stream complete - no more pages')\n }\n this.push(null) // End the stream\n }\n },\n })\n\n return new Response(stream as any, {\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.info('Starting file generation')\n }\n\n const outputData: string[] = []\n const rows: Record<string, unknown>[] = []\n const columnsSet = new Set<string>()\n const columns: string[] = []\n let page = 1\n let hasNextPage = true\n\n while (hasNextPage) {\n const result = await payload.find({\n ...findArgs,\n page,\n })\n\n if (debug) {\n req.payload.logger.info(\n `Processing batch ${findArgs.page} with ${result.docs.length} documents`,\n )\n }\n\n if (isCSV) {\n const batchRows = result.docs.map((doc) => flattenObject({ doc, fields, toCSVFunctions }))\n\n // Track discovered column keys\n batchRows.forEach((row) => {\n Object.keys(row).forEach((key) => {\n if (!columnsSet.has(key)) {\n columnsSet.add(key)\n columns.push(key)\n }\n })\n })\n\n rows.push(...batchRows)\n } else {\n const jsonInput = result.docs.map((doc) => JSON.stringify(doc))\n outputData.push(jsonInput.join(',\\n'))\n }\n\n hasNextPage = result.hasNextPage\n page += 1\n }\n\n if (isCSV) {\n const paddedRows = rows.map((row) => {\n const fullRow: Record<string, unknown> = {}\n for (const col of columns) {\n fullRow[col] = row[col] ?? ''\n }\n return fullRow\n })\n\n outputData.push(\n stringify(paddedRows, {\n header: true,\n columns,\n }),\n )\n }\n\n const buffer = Buffer.from(format === 'json' ? `[${outputData.join(',')}]` : outputData.join(''))\n if (debug) {\n req.payload.logger.info(`${format} file generation complete`)\n }\n\n if (!id) {\n if (debug) {\n req.payload.logger.info('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.info(`Updating existing export with id: ${id}`)\n }\n await req.payload.update({\n id,\n collection: exportsCollection,\n data: {},\n file: {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n },\n user,\n })\n }\n if (debug) {\n req.payload.logger.info('Export process completed successfully')\n }\n}\n"],"names":["stringify","APIError","Readable","flattenObject","getCustomFieldFunctions","getFilename","getSelect","createExport","args","download","input","id","name","nameArg","collectionSlug","debug","drafts","exportsCollection","fields","format","locale","localeInput","sort","user","where","req","localeArg","payload","logger","info","message","collectionConfig","config","collections","find","slug","isCSV","select","Array","isArray","length","undefined","findArgs","collection","depth","draft","limit","overrideAccess","page","toCSVFunctions","flattenedFields","allColumnsSet","Set","allColumns","scanPage","hasMore","result","docs","forEach","doc","flat","Object","keys","key","has","add","push","hasNextPage","encoder","TextEncoder","isFirstBatch","streamPage","stream","read","batchRows","map","paddedRows","row","fullRow","col","csvString","header","columns","encode","Response","headers","outputData","rows","columnsSet","jsonInput","JSON","join","buffer","Bu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,OAAO,CAACC,IAAI,GAAGF,GAAG,CAACE,IAAI,IAAI;YAC7B;YACA,OAAOD;QACT;QAEAQ,WAAWpB,IAAI,CACblE,UAAU4E,YAAY;YACpBK,QAAQ;YACRC;QACF;IAEJ;IAEA,MAAMU,SAASC,OAAOC,IAAI,CAAC3E,WAAW,SAAS,CAAC,CAAC,EAAEmE,WAAWK,IAAI,CAAC,KAAK,CAAC,CAAC,GAAGL,WAAWK,IAAI,CAAC;IAC7F,IAAI5E,OAAO;QACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,GAAGV,OAAO,yBAAyB,CAAC;IAC9D;IAEA,IAAI,CAACR,IAAI;QACP,IAAII,OAAO;YACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;QAC1B;QACAJ,IAAIsE,IAAI,GAAG;YACTnF;YACAoF,MAAMJ;YACNK,UAAU7D,QAAQ,aAAa;YAC/B8D,MAAMN,OAAOpD,MAAM;QACrB;IACF,OAAO;QACL,IAAIzB,OAAO;YACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAElB,IAAI;QACnE;QACA,MAAMc,IAAIE,OAAO,CAACwE,MAAM,CAAC;YACvBxF;YACAgC,YAAY1B;YACZ+E,MAAM,CAAC;YACPD,MAAM;gBACJnF;gBACAoF,MAAMJ;gBACNK,UAAU7D,QAAQ,aAAa;gBAC/B8D,MAAMN,OAAOpD,MAAM;YACrB;YACAjB;QACF;IACF;IACA,IAAIR,OAAO;QACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC1B;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 { flattenObject } from './flattenObject.js'\nimport { getCustomFieldFunctions } from './getCustomFieldFunctions.js'\nimport { getFilename } from './getFilename.js'\nimport { getSelect } from './getSelect.js'\n\nexport type Export = {\n collectionSlug: string\n /**\n * If true, enables debug logging\n */\n debug?: boolean\n drafts?: 'no' | 'yes'\n exportsCollection: string\n fields?: string[]\n format: 'csv' | 'json'\n globals?: string[]\n id: number | string\n locale?: string\n name: string\n slug: string\n sort: Sort\n user: string\n userCollection: 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 input: Export\n req: PayloadRequest\n user?: TypedUser\n}\n\nexport const createExport = async (args: CreateExportArgs) => {\n const {\n download,\n input: {\n id,\n name: nameArg,\n collectionSlug,\n debug = false,\n drafts,\n exportsCollection,\n fields,\n format,\n locale: localeInput,\n sort,\n user,\n where,\n },\n req: { locale: localeArg, payload },\n req,\n } = args\n\n if (debug) {\n req.payload.logger.info({\n message: 'Starting export process with args:',\n collectionSlug,\n drafts,\n fields,\n format,\n })\n }\n\n const locale = localeInput ?? localeArg\n const collectionConfig = payload.config.collections.find(({ slug }) => slug === collectionSlug)\n if (!collectionConfig) {\n throw new APIError(`Collection with slug ${collectionSlug} not found`)\n }\n\n const name = `${nameArg ?? `${getFilename()}-${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.info({ message: 'Export configuration:', name, isCSV, locale })\n }\n\n const findArgs = {\n collection: collectionSlug,\n depth: 1,\n draft: drafts === 'yes',\n limit: 100,\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.info({ message: 'Find arguments:', findArgs })\n }\n\n const toCSVFunctions = getCustomFieldFunctions({\n fields: collectionConfig.flattenedFields,\n })\n\n const disabledFieldsDot =\n collectionConfig.admin?.custom?.['plugin-import-export']?.disabledFields ?? []\n const disabledFields = disabledFieldsDot.map((f: string) => f.replace(/\\./g, '_'))\n\n const filterDisabled = (row: Record<string, unknown>): Record<string, unknown> => {\n for (const key of disabledFields) {\n delete row[key]\n }\n return row\n }\n\n if (download) {\n if (debug) {\n req.payload.logger.info('Pre-scanning all columns before streaming')\n }\n\n const allColumnsSet = new Set<string>()\n const allColumns: string[] = []\n let scanPage = 1\n let hasMore = true\n\n while (hasMore) {\n const result = await payload.find({ ...findArgs, page: scanPage })\n\n result.docs.forEach((doc) => {\n const flat = filterDisabled(flattenObject({ doc, fields, toCSVFunctions }))\n Object.keys(flat).forEach((key) => {\n if (!allColumnsSet.has(key)) {\n allColumnsSet.add(key)\n allColumns.push(key)\n }\n })\n })\n\n hasMore = result.hasNextPage\n scanPage += 1\n }\n\n if (debug) {\n req.payload.logger.info(`Discovered ${allColumns.length} columns`)\n }\n\n const encoder = new TextEncoder()\n let isFirstBatch = true\n let streamPage = 1\n\n const stream = new Readable({\n async read() {\n const result = await payload.find({ ...findArgs, page: streamPage })\n\n if (debug) {\n req.payload.logger.info(`Streaming batch ${streamPage} with ${result.docs.length} docs`)\n }\n\n if (result.docs.length === 0) {\n this.push(null)\n return\n }\n\n const batchRows = result.docs.map((doc) =>\n filterDisabled(flattenObject({ doc, fields, toCSVFunctions })),\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 header: isFirstBatch,\n columns: allColumns,\n })\n\n this.push(encoder.encode(csvString))\n isFirstBatch = false\n streamPage += 1\n\n if (!result.hasNextPage) {\n if (debug) {\n req.payload.logger.info('Stream complete - no more pages')\n }\n this.push(null) // End the stream\n }\n },\n })\n\n return new Response(stream as any, {\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.info('Starting file generation')\n }\n\n const outputData: string[] = []\n const rows: Record<string, unknown>[] = []\n const columnsSet = new Set<string>()\n const columns: string[] = []\n let page = 1\n let hasNextPage = true\n\n while (hasNextPage) {\n const result = await payload.find({\n ...findArgs,\n page,\n })\n\n if (debug) {\n req.payload.logger.info(\n `Processing batch ${findArgs.page} with ${result.docs.length} documents`,\n )\n }\n\n if (isCSV) {\n const batchRows = result.docs.map((doc) =>\n filterDisabled(flattenObject({ doc, fields, toCSVFunctions })),\n )\n\n // Track discovered column keys\n batchRows.forEach((row) => {\n Object.keys(row).forEach((key) => {\n if (!columnsSet.has(key)) {\n columnsSet.add(key)\n columns.push(key)\n }\n })\n })\n\n rows.push(...batchRows)\n } else {\n const jsonInput = result.docs.map((doc) => JSON.stringify(doc))\n outputData.push(jsonInput.join(',\\n'))\n }\n\n hasNextPage = result.hasNextPage\n page += 1\n }\n\n if (isCSV) {\n const paddedRows = rows.map((row) => {\n const fullRow: Record<string, unknown> = {}\n for (const col of columns) {\n fullRow[col] = row[col] ?? ''\n }\n return fullRow\n })\n\n outputData.push(\n stringify(paddedRows, {\n header: true,\n columns,\n }),\n )\n }\n\n const buffer = Buffer.from(format === 'json' ? `[${outputData.join(',')}]` : outputData.join(''))\n if (debug) {\n req.payload.logger.info(`${format} file generation complete`)\n }\n\n if (!id) {\n if (debug) {\n req.payload.logger.info('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.info(`Updating existing export with id: ${id}`)\n }\n await req.payload.update({\n id,\n collection: exportsCollection,\n data: {},\n file: {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n },\n user,\n })\n }\n if (debug) {\n req.payload.logger.info('Export process completed successfully')\n }\n}\n"],"names":["stringify","APIError","Readable","flattenObject","getCustomFieldFunctions","getFilename","getSelect","createExport","args","download","input","id","name","nameArg","collectionSlug","debug","drafts","exportsCollection","fields","format","locale","localeInput","sort","user","where","req","localeArg","payload","logger","info","message","collectionConfig","config","collections","find","slug","isCSV","select","Array","isArray","length","undefined","findArgs","collection","depth","draft","limit","overrideAccess","page","toCSVFunctions","flattenedFields","disabledFieldsDot","admin","custom","disabledFields","map","f","replace","filterDisabled","row","key","allColumnsSet","Set","allColumns","scanPage","hasMore","result","docs","forEach","doc","flat","Object","keys","has","add","push","hasNextPage","encoder","TextEncoder","isFirstBatch","streamPage","stream","read","batchRows","paddedRows","fullRow","col","csvString","header","columns","encode","Response","headers","outputData","rows","columnsSet","jsonInput","JSON","join","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,aAAa,QAAQ,qBAAoB;AAClD,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,SAAS,QAAQ,iBAAgB;AAiC1C,OAAO,MAAMC,eAAe,OAAOC;IACjC,MAAM,EACJC,QAAQ,EACRC,OAAO,EACLC,EAAE,EACFC,MAAMC,OAAO,EACbC,cAAc,EACdC,QAAQ,KAAK,EACbC,MAAM,EACNC,iBAAiB,EACjBC,MAAM,EACNC,MAAM,EACNC,QAAQC,WAAW,EACnBC,IAAI,EACJC,IAAI,EACJC,KAAK,EACN,EACDC,KAAK,EAAEL,QAAQM,SAAS,EAAEC,OAAO,EAAE,EACnCF,GAAG,EACJ,GAAGjB;IAEJ,IAAIO,OAAO;QACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;YACtBC,SAAS;YACThB;YACAE;YACAE;YACAC;QACF;IACF;IAEA,MAAMC,SAASC,eAAeK;IAC9B,MAAMK,mBAAmBJ,QAAQK,MAAM,CAACC,WAAW,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA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ACNK,UAAUpE,QAAQ,aAAa;YAC/BqE,MAAMN,OAAO3D,MAAM;QACrB;IACF,OAAO;QACL,IAAIzB,OAAO;YACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAElB,IAAI;QACnE;QACA,MAAMc,IAAIE,OAAO,CAAC+E,MAAM,CAAC;YACvB/F;YACAgC,YAAY1B;YACZsF,MAAM,CAAC;YACPD,MAAM;gBACJ1F;gBACA2F,MAAMJ;gBACNK,UAAUpE,QAAQ,aAAa;gBAC/BqE,MAAMN,OAAO3D,MAAM;YACrB;YACAjB;QACF;IACF;IACA,IAAIR,OAAO;QACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC1B;AACF,EAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Config, TaskConfig } from 'payload';
|
|
2
|
+
import type { ImportExportPluginConfig } from '../types.js';
|
|
2
3
|
import type { Export } from './createExport.js';
|
|
3
|
-
export declare const getCreateCollectionExportTask: (config: Config) => TaskConfig<{
|
|
4
|
+
export declare const getCreateCollectionExportTask: (config: Config, pluginConfig?: ImportExportPluginConfig) => TaskConfig<{
|
|
4
5
|
input: Export;
|
|
5
6
|
output: object;
|
|
6
7
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCreateExportCollectionTask.d.ts","sourceRoot":"","sources":["../../src/export/getCreateExportCollectionTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAa,MAAM,SAAS,CAAA;AAE5D,OAAO,KAAK,EAAoB,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAKjE,eAAO,MAAM,6BAA6B,WAChC,MAAM,
|
|
1
|
+
{"version":3,"file":"getCreateExportCollectionTask.d.ts","sourceRoot":"","sources":["../../src/export/getCreateExportCollectionTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAa,MAAM,SAAS,CAAA;AAE5D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAC3D,OAAO,KAAK,EAAoB,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAKjE,eAAO,MAAM,6BAA6B,WAChC,MAAM,iBACC,wBAAwB,KACtC,UAAU,CAAC;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf,CAwCA,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createExport } from './createExport.js';
|
|
2
2
|
import { getFields } from './getFields.js';
|
|
3
|
-
export const getCreateCollectionExportTask = (config)=>{
|
|
4
|
-
const inputSchema = getFields(config).concat({
|
|
3
|
+
export const getCreateCollectionExportTask = (config, pluginConfig)=>{
|
|
4
|
+
const inputSchema = getFields(config, pluginConfig).concat({
|
|
5
5
|
name: 'user',
|
|
6
6
|
type: 'text'
|
|
7
7
|
}, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/getCreateExportCollectionTask.ts"],"sourcesContent":["import type { Config, TaskConfig, TypedUser } from 'payload'\n\nimport type { CreateExportArgs, Export } from './createExport.js'\n\nimport { createExport } from './createExport.js'\nimport { getFields } from './getFields.js'\n\nexport const getCreateCollectionExportTask = (\n config: Config,\n): TaskConfig<{\n input: Export\n output: object\n}> => {\n const inputSchema = getFields(config).concat(\n {\n name: 'user',\n type: 'text',\n },\n {\n name: 'userCollection',\n type: 'text',\n },\n {\n name: 'exportsCollection',\n type: 'text',\n },\n )\n\n return {\n slug: 'createCollectionExport',\n handler: async ({ input, req }: CreateExportArgs) => {\n let user: TypedUser | undefined\n\n if (input.userCollection && input.user) {\n user = (await req.payload.findByID({\n id: input.user,\n collection: input.userCollection,\n })) as TypedUser\n }\n\n if (!user) {\n throw new Error('User not found')\n }\n\n await createExport({ input, req, user })\n\n return {\n output: {},\n }\n },\n inputSchema,\n }\n}\n"],"names":["createExport","getFields","getCreateCollectionExportTask","config","inputSchema","concat","name","type","slug","handler","input","req","user","userCollection","payload","findByID","id","collection","Error","output"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/export/getCreateExportCollectionTask.ts"],"sourcesContent":["import type { Config, TaskConfig, TypedUser } from 'payload'\n\nimport type { ImportExportPluginConfig } from '../types.js'\nimport type { CreateExportArgs, Export } from './createExport.js'\n\nimport { createExport } from './createExport.js'\nimport { getFields } from './getFields.js'\n\nexport const getCreateCollectionExportTask = (\n config: Config,\n pluginConfig?: ImportExportPluginConfig,\n): TaskConfig<{\n input: Export\n output: object\n}> => {\n const inputSchema = getFields(config, pluginConfig).concat(\n {\n name: 'user',\n type: 'text',\n },\n {\n name: 'userCollection',\n type: 'text',\n },\n {\n name: 'exportsCollection',\n type: 'text',\n },\n )\n\n return {\n slug: 'createCollectionExport',\n handler: async ({ input, req }: CreateExportArgs) => {\n let user: TypedUser | undefined\n\n if (input.userCollection && input.user) {\n user = (await req.payload.findByID({\n id: input.user,\n collection: input.userCollection,\n })) as TypedUser\n }\n\n if (!user) {\n throw new Error('User not found')\n }\n\n await createExport({ input, req, user })\n\n return {\n output: {},\n }\n },\n inputSchema,\n }\n}\n"],"names":["createExport","getFields","getCreateCollectionExportTask","config","pluginConfig","inputSchema","concat","name","type","slug","handler","input","req","user","userCollection","payload","findByID","id","collection","Error","output"],"mappings":"AAKA,SAASA,YAAY,QAAQ,oBAAmB;AAChD,SAASC,SAAS,QAAQ,iBAAgB;AAE1C,OAAO,MAAMC,gCAAgC,CAC3CC,QACAC;IAKA,MAAMC,cAAcJ,UAAUE,QAAQC,cAAcE,MAAM,CACxD;QACEC,MAAM;QACNC,MAAM;IACR,GACA;QACED,MAAM;QACNC,MAAM;IACR,GACA;QACED,MAAM;QACNC,MAAM;IACR;IAGF,OAAO;QACLC,MAAM;QACNC,SAAS,OAAO,EAAEC,KAAK,EAAEC,GAAG,EAAoB;YAC9C,IAAIC;YAEJ,IAAIF,MAAMG,cAAc,IAAIH,MAAME,IAAI,EAAE;gBACtCA,OAAQ,MAAMD,IAAIG,OAAO,CAACC,QAAQ,CAAC;oBACjCC,IAAIN,MAAME,IAAI;oBACdK,YAAYP,MAAMG,cAAc;gBAClC;YACF;YAEA,IAAI,CAACD,MAAM;gBACT,MAAM,IAAIM,MAAM;YAClB;YAEA,MAAMnB,aAAa;gBAAEW;gBAAOC;gBAAKC;YAAK;YAEtC,OAAO;gBACLO,QAAQ,CAAC;YACX;QACF;QACAf;IACF;AACF,EAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { Config, Field } from 'payload';
|
|
2
|
-
|
|
2
|
+
import type { ImportExportPluginConfig } from '../types.js';
|
|
3
|
+
export declare const getFields: (config: Config, pluginConfig?: ImportExportPluginConfig) => Field[];
|
|
3
4
|
//# sourceMappingURL=getFields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFields.d.ts","sourceRoot":"","sources":["../../src/export/getFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAe,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"getFields.d.ts","sourceRoot":"","sources":["../../src/export/getFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAe,MAAM,SAAS,CAAA;AAEzD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAI3D,eAAO,MAAM,SAAS,WAAY,MAAM,iBAAiB,wBAAwB,KAAG,KAAK,EAoNxF,CAAA"}
|
package/dist/export/getFields.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getFilename } from './getFilename.js';
|
|
2
|
-
export const getFields = (config)=>{
|
|
2
|
+
export const getFields = (config, pluginConfig)=>{
|
|
3
3
|
let localeField;
|
|
4
4
|
if (config.localization) {
|
|
5
5
|
localeField = {
|
|
@@ -41,9 +41,14 @@ export const getFields = (config)=>{
|
|
|
41
41
|
name: 'format',
|
|
42
42
|
type: 'select',
|
|
43
43
|
admin: {
|
|
44
|
+
// Hide if a forced format is set via plugin config
|
|
45
|
+
condition: ()=>!pluginConfig?.format,
|
|
44
46
|
width: '33%'
|
|
45
47
|
},
|
|
46
|
-
defaultValue:
|
|
48
|
+
defaultValue: (()=>{
|
|
49
|
+
// Default to plugin-defined format, otherwise 'csv'
|
|
50
|
+
return pluginConfig?.format ?? 'csv';
|
|
51
|
+
})(),
|
|
47
52
|
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
48
53
|
label: ({ t })=>t('plugin-import-export:field-format-label'),
|
|
49
54
|
options: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/getFields.ts"],"sourcesContent":["import type { Config, Field, SelectField } from 'payload'\n\nimport { getFilename } from './getFilename.js'\n\nexport const getFields = (config: Config): Field[] => {\n let localeField: SelectField | undefined\n if (config.localization) {\n localeField = {\n name: 'locale',\n type: 'select',\n admin: {\n width: '33%',\n },\n defaultValue: 'all',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-locale-label'),\n options: [\n {\n label: ({ t }) => t('general:allLocales'),\n value: 'all',\n },\n ...config.localization.locales.map((locale) => ({\n label: typeof locale === 'string' ? locale : locale.label,\n value: typeof locale === 'string' ? locale : locale.code,\n })),\n ],\n }\n }\n\n return [\n {\n type: 'collapsible',\n fields: [\n {\n name: 'name',\n type: 'text',\n defaultValue: () => getFilename(),\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-name-label'),\n },\n {\n type: 'row',\n fields: [\n {\n name: 'format',\n type: 'select',\n admin: {\n width: '33%',\n },\n defaultValue: 'csv',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-format-label'),\n options: [\n {\n label: 'CSV',\n value: 'csv',\n },\n {\n label: 'JSON',\n value: 'json',\n },\n ],\n required: true,\n },\n {\n name: 'limit',\n type: 'number',\n admin: {\n placeholder: 'No limit',\n width: '33%',\n },\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-limit-label'),\n },\n {\n name: 'sort',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#SortBy',\n },\n },\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-sort-label'),\n },\n ],\n },\n {\n type: 'row',\n fields: [\n ...(localeField ? [localeField] : []),\n {\n name: 'drafts',\n type: 'select',\n admin: {\n condition: (data) => {\n const collectionConfig = (config.collections ?? []).find(\n (collection) => collection.slug === data.collectionSlug,\n )\n return Boolean(\n typeof collectionConfig?.versions === 'object' &&\n collectionConfig?.versions?.drafts,\n )\n },\n width: '33%',\n },\n defaultValue: 'yes',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-drafts-label'),\n options: [\n {\n label: ({ t }) => t('general:yes'),\n value: 'yes',\n },\n {\n label: ({ t }) => t('general:no'),\n value: 'no',\n },\n ],\n },\n // {\n // name: 'depth',\n // type: 'number',\n // // @ts-expect-error - this is not correctly typed in plugins right now\n // label: ({ t }) => t('plugin-import-export:field-depth-label'),\n // admin: {\n // width: '33%',\n // },\n // defaultValue: 1,\n // required: true,\n // },\n ],\n },\n {\n name: 'selectionToUse',\n type: 'radio',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#SelectionToUseField',\n },\n },\n options: [\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-currentSelection'),\n value: 'currentSelection',\n },\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-currentFilters'),\n value: 'currentFilters',\n },\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-allDocuments'),\n value: 'all',\n },\n ],\n },\n {\n name: 'fields',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#FieldsToExport',\n },\n },\n hasMany: true,\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-fields-label'),\n },\n {\n name: 'collectionSlug',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#CollectionField',\n },\n hidden: true,\n },\n required: true,\n },\n {\n name: 'where',\n type: 'json',\n admin: {\n hidden: true,\n },\n defaultValue: {},\n hooks: {\n beforeValidate: [\n ({ value }) => {\n return value ?? {}\n },\n ],\n },\n },\n ],\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:exportOptions'),\n },\n {\n name: 'preview',\n type: 'ui',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#Preview',\n },\n },\n },\n ]\n}\n"],"names":["getFilename","getFields","config","localeField","localization","name","type","admin","width","defaultValue","label","t","options","value","locales","map","locale","code","fields","required","placeholder","components","Field","condition","data","collectionConfig","collections","find","collection","slug","collectionSlug","Boolean","versions","drafts","hasMany","hidden","hooks","beforeValidate"],"mappings":"AAEA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAY,CAACC;IACxB,IAAIC;IACJ,IAAID,OAAOE,YAAY,EAAE;QACvBD,cAAc;YACZE,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,OAAO;YACT;YACAC,cAAc;YACd,sEAAsE;YACtEC,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;YACpBC,SAAS;gBACP;oBACEF,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;oBACpBE,OAAO;gBACT;mBACGX,OAAOE,YAAY,CAACU,OAAO,CAACC,GAAG,CAAC,CAACC,SAAY,CAAA;wBAC9CN,OAAO,OAAOM,WAAW,WAAWA,SAASA,OAAON,KAAK;wBACzDG,OAAO,OAAOG,WAAW,WAAWA,SAASA,OAAOC,IAAI;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O;gBACLc,YAAY;oBACVC,OAAO;gBACT;YACF;QACF;KACD;AACH,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/export/getFields.ts"],"sourcesContent":["import type { Config, Field, SelectField } from 'payload'\n\nimport type { ImportExportPluginConfig } from '../types.js'\n\nimport { getFilename } from './getFilename.js'\n\nexport const getFields = (config: Config, pluginConfig?: ImportExportPluginConfig): Field[] => {\n let localeField: SelectField | undefined\n if (config.localization) {\n localeField = {\n name: 'locale',\n type: 'select',\n admin: {\n width: '33%',\n },\n defaultValue: 'all',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-locale-label'),\n options: [\n {\n label: ({ t }) => t('general:allLocales'),\n value: 'all',\n },\n ...config.localization.locales.map((locale) => ({\n label: typeof locale === 'string' ? locale : locale.label,\n value: typeof locale === 'string' ? locale : locale.code,\n })),\n ],\n }\n }\n\n return [\n {\n type: 'collapsible',\n fields: [\n {\n name: 'name',\n type: 'text',\n defaultValue: () => getFilename(),\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-name-label'),\n },\n {\n type: 'row',\n fields: [\n {\n name: 'format',\n type: 'select',\n admin: {\n // Hide if a forced format is set via plugin config\n condition: () => !pluginConfig?.format,\n width: '33%',\n },\n defaultValue: (() => {\n // Default to plugin-defined format, otherwise 'csv'\n return pluginConfig?.format ?? 'csv'\n })(),\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-format-label'),\n options: [\n {\n label: 'CSV',\n value: 'csv',\n },\n {\n label: 'JSON',\n value: 'json',\n },\n ],\n required: true,\n },\n {\n name: 'limit',\n type: 'number',\n admin: {\n placeholder: 'No limit',\n width: '33%',\n },\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-limit-label'),\n },\n {\n name: 'sort',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#SortBy',\n },\n },\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-sort-label'),\n },\n ],\n },\n {\n type: 'row',\n fields: [\n ...(localeField ? [localeField] : []),\n {\n name: 'drafts',\n type: 'select',\n admin: {\n condition: (data) => {\n const collectionConfig = (config.collections ?? []).find(\n (collection) => collection.slug === data.collectionSlug,\n )\n return Boolean(\n typeof collectionConfig?.versions === 'object' &&\n collectionConfig?.versions?.drafts,\n )\n },\n width: '33%',\n },\n defaultValue: 'yes',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-drafts-label'),\n options: [\n {\n label: ({ t }) => t('general:yes'),\n value: 'yes',\n },\n {\n label: ({ t }) => t('general:no'),\n value: 'no',\n },\n ],\n },\n // {\n // name: 'depth',\n // type: 'number',\n // // @ts-expect-error - this is not correctly typed in plugins right now\n // label: ({ t }) => t('plugin-import-export:field-depth-label'),\n // admin: {\n // width: '33%',\n // },\n // defaultValue: 1,\n // required: true,\n // },\n ],\n },\n {\n name: 'selectionToUse',\n type: 'radio',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#SelectionToUseField',\n },\n },\n options: [\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-currentSelection'),\n value: 'currentSelection',\n },\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-currentFilters'),\n value: 'currentFilters',\n },\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-allDocuments'),\n value: 'all',\n },\n ],\n },\n {\n name: 'fields',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#FieldsToExport',\n },\n },\n hasMany: true,\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-fields-label'),\n },\n {\n name: 'collectionSlug',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#CollectionField',\n },\n hidden: true,\n },\n required: true,\n },\n {\n name: 'where',\n type: 'json',\n admin: {\n hidden: true,\n },\n defaultValue: {},\n hooks: {\n beforeValidate: [\n ({ value }) => {\n return value ?? {}\n },\n ],\n },\n },\n ],\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:exportOptions'),\n },\n {\n name: 'preview',\n type: 'ui',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#Preview',\n },\n },\n },\n ]\n}\n"],"names":["getFilename","getFields","config","pluginConfig","localeField","localization","name","type","admin","width","defaultValue","label","t","options","value","locales","map","locale","code","fields","condition","format","required","placeholder","components","Field","data","collectionConfig","collections","find","collection","slug","collectionSlug","Boolean","versions","drafts","hasMany","hidden","hooks","beforeValidate"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAY,CAACC,QAAgBC;IACxC,IAAIC;IACJ,IAAIF,OAAOG,YAAY,EAAE;QACvBD,cAAc;YACZE,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,OAAO;YACT;YACAC,cAAc;YACd,sEAAsE;YACtEC,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;YACpBC,SAAS;gBACP;oBACEF,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;oBACpBE,OAAO;gBACT;mBACGZ,OAAOG,YAAY,CAACU,OAAO,CAACC,GAAG,CAAC,CAACC,SAAY,CAAA;wBAC9CN,OAAO,OAAOM,WAAW,WAAWA,SAASA,OAAON,KAAK;wBACzDG,OAAO,OAAOG,WAAW,WAAWA,SAASA,OAAOC,IAAI;oBAC1D,CAAA;aACD;QACH;IACF;IAEA,OAAO;QACL;YACEX,MAAM;YACNY,QAAQ;gBACN;oBACEb,MAAM;oBACNC,MAAM;oBACNG,cAAc,IAAMV;oBACpB,sEAAsE;oBACtEW,OAAO,CAAC,EAAEC,CAAC,E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D;AACH,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getExportCollection.d.ts","sourceRoot":"","sources":["../src/getExportCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,MAAM,EACP,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAsB,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAM9E,eAAO,MAAM,mBAAmB,8BAG7B;IACD,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,
|
|
1
|
+
{"version":3,"file":"getExportCollection.d.ts","sourceRoot":"","sources":["../src/getExportCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,MAAM,EACP,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAsB,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAM9E,eAAO,MAAM,mBAAmB,8BAG7B;IACD,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,gBA+EH,CAAA"}
|
|
@@ -16,6 +16,10 @@ export const getExportCollection = ({ config, pluginConfig })=>{
|
|
|
16
16
|
SaveButton: '@payloadcms/plugin-import-export/rsc#ExportSaveButton'
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
+
custom: {
|
|
20
|
+
disableDownload: pluginConfig.disableDownload ?? false,
|
|
21
|
+
disableSave: pluginConfig.disableSave ?? false
|
|
22
|
+
},
|
|
19
23
|
group: false,
|
|
20
24
|
useAsTitle: 'name'
|
|
21
25
|
},
|
|
@@ -29,7 +33,7 @@ export const getExportCollection = ({ config, pluginConfig })=>{
|
|
|
29
33
|
path: '/download'
|
|
30
34
|
}
|
|
31
35
|
],
|
|
32
|
-
fields: getFields(config),
|
|
36
|
+
fields: getFields(config, pluginConfig),
|
|
33
37
|
hooks: {
|
|
34
38
|
afterChange,
|
|
35
39
|
beforeOperation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/getExportCollection.ts"],"sourcesContent":["import type {\n CollectionAfterChangeHook,\n CollectionBeforeOperationHook,\n CollectionConfig,\n Config,\n} from 'payload'\n\nimport type { CollectionOverride, ImportExportPluginConfig } from './types.js'\n\nimport { createExport } from './export/createExport.js'\nimport { download } from './export/download.js'\nimport { getFields } from './export/getFields.js'\n\nexport const getExportCollection = ({\n config,\n pluginConfig,\n}: {\n config: Config\n pluginConfig: ImportExportPluginConfig\n}): CollectionConfig => {\n const { overrideExportCollection } = pluginConfig\n\n const beforeOperation: CollectionBeforeOperationHook[] = []\n const afterChange: CollectionAfterChangeHook[] = []\n\n let collection: CollectionOverride = {\n slug: 'exports',\n access: {\n update: () => false,\n },\n admin: {\n components: {\n edit: {\n SaveButton: '@payloadcms/plugin-import-export/rsc#ExportSaveButton',\n },\n },\n group: false,\n useAsTitle: 'name',\n },\n disableDuplicate: true,\n endpoints: [\n {\n handler: (req) => {\n return download(req, pluginConfig.debug)\n },\n method: 'post',\n path: '/download',\n },\n ],\n fields: getFields(config),\n hooks: {\n afterChange,\n beforeOperation,\n },\n upload: {\n filesRequiredOnCreate: false,\n hideFileInputOnCreate: true,\n hideRemoveFile: true,\n },\n }\n\n if (typeof overrideExportCollection === 'function') {\n collection = overrideExportCollection(collection)\n }\n\n if (pluginConfig.disableJobsQueue) {\n beforeOperation.push(async ({ args, operation, req }) => {\n if (operation !== 'create') {\n return\n }\n const { user } = req\n const debug = pluginConfig.debug\n await createExport({ input: { ...args.data, debug, user }, req })\n })\n } else {\n afterChange.push(async ({ doc, operation, req }) => {\n if (operation !== 'create') {\n return\n }\n\n const input = {\n ...doc,\n exportsCollection: collection.slug,\n user: req?.user?.id || req?.user?.user?.id,\n userCollection: 'users',\n }\n await req.payload.jobs.queue({\n input,\n task: 'createCollectionExport',\n })\n })\n }\n\n return collection\n}\n"],"names":["createExport","download","getFields","getExportCollection","config","pluginConfig","overrideExportCollection","beforeOperation","afterChange","collection","slug","access","update","admin","components","edit","SaveButton","group","useAsTitle","disableDuplicate","endpoints","handler","req","debug","method","path","fields","hooks","upload","filesRequiredOnCreate","hideFileInputOnCreate","hideRemoveFile","disableJobsQueue","push","args","operation","user","input","data","doc","exportsCollection","id","userCollection","payload","jobs","queue","task"],"mappings":"AASA,SAASA,YAAY,QAAQ,2BAA0B;AACvD,SAASC,QAAQ,QAAQ,uBAAsB;AAC/C,SAASC,SAAS,QAAQ,wBAAuB;AAEjD,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,MAAM,EACNC,YAAY,EAIb;IACC,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;IAErC,MAAME,kBAAmD,EAAE;IAC3D,MAAMC,cAA2C,EAAE;IAEnD,IAAIC,aAAiC;QACnCC,MAAM;QACNC,QAAQ;YACNC,QAAQ,IAAM;QAChB;QACAC,OAAO;YACLC,YAAY;gBACVC,MAAM;oBACJC,YAAY;gBACd;YACF;YACAC,OAAO;YACPC,YAAY;QACd;QACAC,kBAAkB;QAClBC,WAAW;YACT;gBACEC,SAAS,CAACC;oBACR,
|
|
1
|
+
{"version":3,"sources":["../src/getExportCollection.ts"],"sourcesContent":["import type {\n CollectionAfterChangeHook,\n CollectionBeforeOperationHook,\n CollectionConfig,\n Config,\n} from 'payload'\n\nimport type { CollectionOverride, ImportExportPluginConfig } from './types.js'\n\nimport { createExport } from './export/createExport.js'\nimport { download } from './export/download.js'\nimport { getFields } from './export/getFields.js'\n\nexport const getExportCollection = ({\n config,\n pluginConfig,\n}: {\n config: Config\n pluginConfig: ImportExportPluginConfig\n}): CollectionConfig => {\n const { overrideExportCollection } = pluginConfig\n\n const beforeOperation: CollectionBeforeOperationHook[] = []\n const afterChange: CollectionAfterChangeHook[] = []\n\n let collection: CollectionOverride = {\n slug: 'exports',\n access: {\n update: () => false,\n },\n admin: {\n components: {\n edit: {\n SaveButton: '@payloadcms/plugin-import-export/rsc#ExportSaveButton',\n },\n },\n custom: {\n disableDownload: pluginConfig.disableDownload ?? false,\n disableSave: pluginConfig.disableSave ?? false,\n },\n group: false,\n useAsTitle: 'name',\n },\n disableDuplicate: true,\n endpoints: [\n {\n handler: (req) => {\n return download(req, pluginConfig.debug)\n },\n method: 'post',\n path: '/download',\n },\n ],\n fields: getFields(config, pluginConfig),\n hooks: {\n afterChange,\n beforeOperation,\n },\n upload: {\n filesRequiredOnCreate: false,\n hideFileInputOnCreate: true,\n hideRemoveFile: true,\n },\n }\n\n if (typeof overrideExportCollection === 'function') {\n collection = overrideExportCollection(collection)\n }\n\n if (pluginConfig.disableJobsQueue) {\n beforeOperation.push(async ({ args, operation, req }) => {\n if (operation !== 'create') {\n return\n }\n const { user } = req\n const debug = pluginConfig.debug\n await createExport({ input: { ...args.data, debug, user }, req })\n })\n } else {\n afterChange.push(async ({ doc, operation, req }) => {\n if (operation !== 'create') {\n return\n }\n\n const input = {\n ...doc,\n exportsCollection: collection.slug,\n user: req?.user?.id || req?.user?.user?.id,\n userCollection: 'users',\n }\n await req.payload.jobs.queue({\n input,\n task: 'createCollectionExport',\n })\n })\n }\n\n return collection\n}\n"],"names":["createExport","download","getFields","getExportCollection","config","pluginConfig","overrideExportCollection","beforeOperation","afterChange","collection","slug","access","update","admin","components","edit","SaveButton","custom","disableDownload","disableSave","group","useAsTitle","disableDuplicate","endpoints","handler","req","debug","method","path","fields","hooks","upload","filesRequiredOnCreate","hideFileInputOnCreate","hideRemoveFile","disableJobsQueue","push","args","operation","user","input","data","doc","exportsCollection","id","userCollection","payload","jobs","queue","task"],"mappings":"AASA,SAASA,YAAY,QAAQ,2BAA0B;AACvD,SAASC,QAAQ,QAAQ,uBAAsB;AAC/C,SAASC,SAAS,QAAQ,wBAAuB;AAEjD,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,MAAM,EACNC,YAAY,EAIb;IACC,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;IAErC,MAAME,kBAAmD,EAAE;IAC3D,MAAMC,cAA2C,EAAE;IAEnD,IAAIC,a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CAACC,IAAI,CAACC,KAAK,CAAC;gBAC3BR;gBACAS,MAAM;YACR;QACF;IACF;IAEA,OAAOxC;AACT,EAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,14 @@ export declare const importExportPlugin: (pluginConfig: ImportExportPluginConfig
|
|
|
4
4
|
declare module 'payload' {
|
|
5
5
|
interface FieldCustom {
|
|
6
6
|
'plugin-import-export'?: {
|
|
7
|
+
/**
|
|
8
|
+
* When `true` the field is **completely excluded** from the import-export plugin:
|
|
9
|
+
* - It will not appear in the “Fields to export” selector.
|
|
10
|
+
* - It is hidden from the preview list when no specific fields are chosen.
|
|
11
|
+
* - Its data is omitted from the final CSV / JSON export.
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
disabled?: boolean;
|
|
7
15
|
toCSV?: ToCSVFunction;
|
|
8
16
|
};
|
|
9
17
|
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,SAAS,CAAA;AAKrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAUzE,eAAO,MAAM,kBAAkB,iBACd,wBAAwB,cAC9B,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,SAAS,CAAA;AAKrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAUzE,eAAO,MAAM,kBAAkB,iBACd,wBAAwB,cAC9B,MAAM,KAAG,MAiKjB,CAAA;AAEH,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAiB,WAAW;QAC1B,sBAAsB,CAAC,EAAE;YACvB;;;;;;eAMG;YACH,QAAQ,CAAC,EAAE,OAAO,CAAA;YAClB,KAAK,CAAC,EAAE,aAAa,CAAA;SACtB,CAAA;KACF;CACF"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addDataAndFileToRequest, deepMergeSimple } from 'payload';
|
|
1
|
+
import { addDataAndFileToRequest, deepMergeSimple, flattenTopLevelFields } from 'payload';
|
|
2
2
|
import { flattenObject } from './export/flattenObject.js';
|
|
3
3
|
import { getCreateCollectionExportTask } from './export/getCreateExportCollectionTask.js';
|
|
4
4
|
import { getCustomFieldFunctions } from './export/getCustomFieldFunctions.js';
|
|
@@ -23,7 +23,7 @@ export const importExportPlugin = (pluginConfig)=>(config)=>{
|
|
|
23
23
|
config.admin.components = config.admin.components || {};
|
|
24
24
|
config.admin.components.providers = config.admin.components.providers || [];
|
|
25
25
|
config.admin.components.providers.push('@payloadcms/plugin-import-export/rsc#ImportExportProvider');
|
|
26
|
-
((config.jobs ??= {}).tasks ??= []).push(getCreateCollectionExportTask(config));
|
|
26
|
+
((config.jobs ??= {}).tasks ??= []).push(getCreateCollectionExportTask(config, pluginConfig));
|
|
27
27
|
let collectionsToUpdate = config.collections;
|
|
28
28
|
const usePluginCollections = pluginConfig.collections && pluginConfig.collections?.length > 0;
|
|
29
29
|
if (usePluginCollections) {
|
|
@@ -49,6 +49,20 @@ export const importExportPlugin = (pluginConfig)=>(config)=>{
|
|
|
49
49
|
},
|
|
50
50
|
path: '@payloadcms/plugin-import-export/rsc#ExportListMenuItem'
|
|
51
51
|
});
|
|
52
|
+
// Flatten top-level fields to expose nested fields for export config
|
|
53
|
+
const flattenedFields = flattenTopLevelFields(collection.fields, {
|
|
54
|
+
moveSubFieldsToTop: true
|
|
55
|
+
});
|
|
56
|
+
// Find fields explicitly marked as disabled for import/export
|
|
57
|
+
const disabledFieldAccessors = flattenedFields.filter((field)=>field.custom?.['plugin-import-export']?.disabled).map((field)=>field.accessor || field.name);
|
|
58
|
+
// Store disabled field accessors in the admin config for use in the UI
|
|
59
|
+
collection.admin.custom = {
|
|
60
|
+
...collection.admin.custom || {},
|
|
61
|
+
'plugin-import-export': {
|
|
62
|
+
...collection.admin.custom?.['plugin-import-export'] || {},
|
|
63
|
+
disabledFields: disabledFieldAccessors
|
|
64
|
+
}
|
|
65
|
+
};
|
|
52
66
|
collection.admin.components = components;
|
|
53
67
|
});
|
|
54
68
|
if (!config.i18n) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config, FlattenedField } from 'payload'\n\nimport { addDataAndFileToRequest, deepMergeSimple } from 'payload'\n\nimport type { PluginDefaultTranslationsObject } from './translations/types.js'\nimport type { ImportExportPluginConfig, ToCSVFunction } from './types.js'\n\nimport { flattenObject } from './export/flattenObject.js'\nimport { getCreateCollectionExportTask } from './export/getCreateExportCollectionTask.js'\nimport { getCustomFieldFunctions } from './export/getCustomFieldFunctions.js'\nimport { getSelect } from './export/getSelect.js'\nimport { getExportCollection } from './getExportCollection.js'\nimport { translations } from './translations/index.js'\nimport { getFlattenedFieldKeys } from './utilities/getFlattenedFieldKeys.js'\n\nexport const importExportPlugin =\n (pluginConfig: ImportExportPluginConfig) =>\n (config: Config): Config => {\n const exportCollection = getExportCollection({ config, pluginConfig })\n if (config.collections) {\n config.collections.push(exportCollection)\n } else {\n config.collections = [exportCollection]\n }\n\n // inject custom import export provider\n config.admin = config.admin || {}\n config.admin.components = config.admin.components || {}\n config.admin.components.providers = config.admin.components.providers || []\n config.admin.components.providers.push(\n '@payloadcms/plugin-import-export/rsc#ImportExportProvider',\n )\n\n // inject the createExport job into the config\n ;((config.jobs ??= {}).tasks ??= []).push(getCreateCollectionExportTask(config))\n\n let collectionsToUpdate = config.collections\n\n const usePluginCollections = pluginConfig.collections && pluginConfig.collections?.length > 0\n\n if (usePluginCollections) {\n collectionsToUpdate = config.collections?.filter((collection) => {\n return pluginConfig.collections?.includes(collection.slug)\n })\n }\n\n collectionsToUpdate.forEach((collection) => {\n if (!collection.admin) {\n collection.admin = { components: { listMenuItems: [] } }\n }\n const components = collection.admin.components || {}\n if (!components.listMenuItems) {\n components.listMenuItems = []\n }\n components.listMenuItems.push({\n clientProps: {\n exportCollectionSlug: exportCollection.slug,\n },\n path: '@payloadcms/plugin-import-export/rsc#ExportListMenuItem',\n })\n collection.admin.components = components\n })\n\n if (!config.i18n) {\n config.i18n = {}\n }\n\n // config.i18n.translations = deepMergeSimple(translations, config.i18n?.translations ?? {})\n\n // Inject custom REST endpoints into the config\n config.endpoints = config.endpoints || []\n config.endpoints.push({\n handler: async (req) => {\n await addDataAndFileToRequest(req)\n\n const { collectionSlug, draft, fields, limit, locale, sort, where } = req.data as {\n collectionSlug: string\n draft?: 'no' | 'yes'\n fields?: string[]\n limit?: number\n locale?: string\n sort?: any\n where?: any\n }\n\n const collection = req.payload.collections[collectionSlug]\n if (!collection) {\n return Response.json(\n { error: `Collection with slug ${collectionSlug} not found` },\n { status: 400 },\n )\n }\n\n const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined\n\n const result = await req.payload.find({\n collection: collectionSlug,\n depth: 1,\n draft: draft === 'yes',\n limit: limit && limit > 10 ? 10 : limit,\n locale,\n overrideAccess: false,\n req,\n select,\n sort,\n where,\n })\n\n const docs = result.docs\n\n const toCSVFunctions = getCustomFieldFunctions({\n fields: collection.config.fields as FlattenedField[],\n })\n\n const possibleKeys = getFlattenedFieldKeys(collection.config.fields as FlattenedField[])\n\n const transformed = docs.map((doc) => {\n const row = flattenObject({\n doc,\n fields,\n toCSVFunctions,\n })\n\n for (const key of possibleKeys) {\n if (!(key in row)) {\n row[key] = null\n }\n }\n\n return row\n })\n\n return Response.json({\n docs: transformed,\n totalDocs: result.totalDocs,\n })\n },\n method: 'post',\n path: '/preview-data',\n })\n\n /**\n * Merge plugin translations\n */\n const simplifiedTranslations = Object.entries(translations).reduce(\n (acc, [key, value]) => {\n acc[key] = value.translations\n return acc\n },\n {} as Record<string, PluginDefaultTranslationsObject>,\n )\n\n config.i18n = {\n ...config.i18n,\n translations: deepMergeSimple(simplifiedTranslations, config.i18n?.translations ?? {}),\n }\n\n return config\n }\n\ndeclare module 'payload' {\n export interface FieldCustom {\n 'plugin-import-export'?: {\n toCSV?: ToCSVFunction\n }\n }\n}\n"],"names":["addDataAndFileToRequest","deepMergeSimple","flattenObject","getCreateCollectionExportTask","getCustomFieldFunctions","getSelect","getExportCollection","translations","getFlattenedFieldKeys","importExportPlugin","pluginConfig","config","exportCollection","collections","push","admin","components","providers","jobs","tasks","collectionsToUpdate","usePluginCollections","length","filter","collection","includes","slug","forEach","listMenuItems","clientProps","exportCollectionSlug","path","i18n","endpoints","handler","req","collectionSlug","draft","fields","limit","locale","sort","where","data","payload","Response","json","error","status","select","Array","isArray","undefined","result","find","depth","overrideAccess","docs","toCSVFunctions","possibleKeys","transformed","map","doc","row","key","totalDocs","method","simplifiedTranslations","Object","entries","reduce","acc","value"],"mappings":"AAEA,SAASA,uBAAuB,EAAEC,eAAe,QAAQ,UAAS;AAKlE,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,6BAA6B,QAAQ,4CAA2C;AACzF,SAASC,uBAAuB,QAAQ,sCAAqC;AAC7E,SAASC,SAAS,QAAQ,wBAAuB;AACjD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,YAAY,QAAQ,0BAAyB;AACtD,SAASC,qBAAqB,QAAQ,uCAAsC;AAE5E,OAAO,MAAMC,qBACX,CAACC,eACD,CAACC;QACC,MAAMC,mBAAmBN,oBAAoB;YAAEK;YAAQD;QAAa;QACpE,IAAIC,OAAOE,WAAW,EAAE;YACtBF,OAAOE,WAAW,CAACC,IAAI,CAACF;QAC1B,OAAO;YACLD,OAAOE,WAAW,GAAG;gBAACD;aAAiB;QACzC;QAEA,uCAAuC;QACvCD,OAAOI,KAAK,GAAGJ,OAAOI,KAAK,IAAI,CAAC;QAChCJ,OAAOI,KAAK,CAAC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WZ,OAAOY,SAAS;gBAC7B;YACF;YACAC,QAAQ;YACRnC,MAAM;QACR;QAEA;;KAEC,GACD,MAAMoC,yBAAyBC,OAAOC,OAAO,CAAC9D,cAAc+D,MAAM,CAChE,CAACC,KAAK,CAACP,KAAKQ,MAAM;YAChBD,GAAG,CAACP,IAAI,GAAGQ,MAAMjE,YAAY;YAC7B,OAAOgE;QACT,GACA,CAAC;QAGH5D,OAAOqB,IAAI,GAAG;YACZ,GAAGrB,OAAOqB,IAAI;YACdzB,cAAcN,gBAAgBkE,wBAAwBxD,OAAOqB,IAAI,EAAEzB,gBAAgB,CAAC;QACtF;QAEA,OAAOI;IACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config, FlattenedField } from 'payload'\n\nimport { addDataAndFileToRequest, deepMergeSimple, flattenTopLevelFields } from 'payload'\n\nimport type { PluginDefaultTranslationsObject } from './translations/types.js'\nimport type { ImportExportPluginConfig, ToCSVFunction } from './types.js'\n\nimport { flattenObject } from './export/flattenObject.js'\nimport { getCreateCollectionExportTask } from './export/getCreateExportCollectionTask.js'\nimport { getCustomFieldFunctions } from './export/getCustomFieldFunctions.js'\nimport { getSelect } from './export/getSelect.js'\nimport { getExportCollection } from './getExportCollection.js'\nimport { translations } from './translations/index.js'\nimport { getFlattenedFieldKeys } from './utilities/getFlattenedFieldKeys.js'\n\nexport const importExportPlugin =\n (pluginConfig: ImportExportPluginConfig) =>\n (config: Config): Config => {\n const exportCollection = getExportCollection({ config, pluginConfig })\n if (config.collections) {\n config.collections.push(exportCollection)\n } else {\n config.collections = [exportCollection]\n }\n\n // inject custom import export provider\n config.admin = config.admin || {}\n config.admin.components = config.admin.components || {}\n config.admin.components.providers = config.admin.components.providers || []\n config.admin.components.providers.push(\n '@payloadcms/plugin-import-export/rsc#ImportExportProvider',\n )\n\n // inject the createExport job into the config\n ;((config.jobs ??= {}).tasks ??= []).push(getCreateCollectionExportTask(config, pluginConfig))\n\n let collectionsToUpdate = config.collections\n\n const usePluginCollections = pluginConfig.collections && pluginConfig.collections?.length > 0\n\n if (usePluginCollections) {\n collectionsToUpdate = config.collections?.filter((collection) => {\n return pluginConfig.collections?.includes(collection.slug)\n })\n }\n\n collectionsToUpdate.forEach((collection) => {\n if (!collection.admin) {\n collection.admin = { components: { listMenuItems: [] } }\n }\n const components = collection.admin.components || {}\n if (!components.listMenuItems) {\n components.listMenuItems = []\n }\n components.listMenuItems.push({\n clientProps: {\n exportCollectionSlug: exportCollection.slug,\n },\n path: '@payloadcms/plugin-import-export/rsc#ExportListMenuItem',\n })\n\n // Flatten top-level fields to expose nested fields for export config\n const flattenedFields = flattenTopLevelFields(collection.fields, {\n moveSubFieldsToTop: true,\n })\n\n // Find fields explicitly marked as disabled for import/export\n const disabledFieldAccessors = flattenedFields\n .filter((field) => field.custom?.['plugin-import-export']?.disabled)\n .map((field) => field.accessor || field.name)\n\n // Store disabled field accessors in the admin config for use in the UI\n collection.admin.custom = {\n ...(collection.admin.custom || {}),\n 'plugin-import-export': {\n ...(collection.admin.custom?.['plugin-import-export'] || {}),\n disabledFields: disabledFieldAccessors,\n },\n }\n\n collection.admin.components = components\n })\n\n if (!config.i18n) {\n config.i18n = {}\n }\n\n // config.i18n.translations = deepMergeSimple(translations, config.i18n?.translations ?? {})\n\n // Inject custom REST endpoints into the config\n config.endpoints = config.endpoints || []\n config.endpoints.push({\n handler: async (req) => {\n await addDataAndFileToRequest(req)\n\n const { collectionSlug, draft, fields, limit, locale, sort, where } = req.data as {\n collectionSlug: string\n draft?: 'no' | 'yes'\n fields?: string[]\n limit?: number\n locale?: string\n sort?: any\n where?: any\n }\n\n const collection = req.payload.collections[collectionSlug]\n if (!collection) {\n return Response.json(\n { error: `Collection with slug ${collectionSlug} not found` },\n { status: 400 },\n )\n }\n\n const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined\n\n const result = await req.payload.find({\n collection: collectionSlug,\n depth: 1,\n draft: draft === 'yes',\n limit: limit && limit > 10 ? 10 : limit,\n locale,\n overrideAccess: false,\n req,\n select,\n sort,\n where,\n })\n\n const docs = result.docs\n\n const toCSVFunctions = getCustomFieldFunctions({\n fields: collection.config.fields as FlattenedField[],\n })\n\n const possibleKeys = getFlattenedFieldKeys(collection.config.fields as FlattenedField[])\n\n const transformed = docs.map((doc) => {\n const row = flattenObject({\n doc,\n fields,\n toCSVFunctions,\n })\n\n for (const key of possibleKeys) {\n if (!(key in row)) {\n row[key] = null\n }\n }\n\n return row\n })\n\n return Response.json({\n docs: transformed,\n totalDocs: result.totalDocs,\n })\n },\n method: 'post',\n path: '/preview-data',\n })\n\n /**\n * Merge plugin translations\n */\n const simplifiedTranslations = Object.entries(translations).reduce(\n (acc, [key, value]) => {\n acc[key] = value.translations\n return acc\n },\n {} as Record<string, PluginDefaultTranslationsObject>,\n )\n\n config.i18n = {\n ...config.i18n,\n translations: deepMergeSimple(simplifiedTranslations, config.i18n?.translations ?? {}),\n }\n\n return config\n }\n\ndeclare module 'payload' {\n export interface FieldCustom {\n 'plugin-import-export'?: {\n /**\n * When `true` the field is **completely excluded** from the import-export plugin:\n * - It will not appear in the “Fields to export” selector.\n * - It is hidden from the preview list when no specific fields are chosen.\n * - Its data is omitted from the final CSV / JSON export.\n * @default false\n */\n disabled?: boolean\n toCSV?: ToCSVFunction\n }\n }\n}\n"],"names":["addDataAndFileToRequest","deepMergeSimple","flattenTopLevelFields","flattenObject","getCreateCollectionExportTask","getCustomFieldFunctions","getSelect","getExportCollection","translations","getFlattenedFieldKeys","importExportPlugin","pluginConfig","config","exportCollection","collections","push","admin","components","providers","jobs","tasks","collectionsToUpdate","usePluginCollections","length","filter","collection","includes","slug","forEach","listMenuItems","clientProps","exportCollectionSlug","path","flattenedFields","fields","moveSubFieldsToTop","disabledFieldAccessors","field","custom","disabled","map","accessor","name","disabledFields","i18n","endpoints","handler","req","collectionSlug","draft","limit","locale","sort","where","data","payload","Response","json","error","status","select","Array","isArray","undefined","result","find","depth","overrideAccess","docs","toCSVFunctions","possibleKeys","transformed","doc","row","key","totalDocs","method","simplifiedTranslations","Object","entries","reduce","acc","value"],"mappings":"AAEA,SAASA,uBAAuB,EAAEC,eAAe,EAAEC,qBAAqB,QAAQ,UAAS;AAKzF,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,6BAA6B,QAAQ,4CAA2C;AACzF,SAASC,uBAAuB,QAAQ,sCAAqC;AAC7E,SAASC,SAAS,QAAQ,wBAAuB;AACjD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,YAAY,QAAQ,0BAAyB;AACtD,SAASC,qBAAqB,QAAQ,uCAAsC;AAE5E,OAAO,MAAMC,qBACX,CAACC,eACD,CAACC;QACC,MAAMC,mBAAmBN,oBAAoB;YAAEK;YAAQD;QAAa;QACpE,IAAIC,OAAOE,WAAW,EAAE;YACtBF,OAAOE,WAAW,CAACC,IAAI,CAACF;QAC1B,OAAO;YACLD,OAAOE,WAAW,GAAG;gBAACD;aAAiB;QACzC;QAEA,uCAAuC;QACvCD,OAAOI,KAAK,GAAGJ,OAAOI,KAAK,IAAI,CAAC;QAChCJ,OAAOI,KAAK,CAACC,UAAU,GAAGL,OAAOI,KAAK,CAACC,UAAU,IAAI,CAAC;QACtDL,OAAOI,KAAK,CAACC,UAAU,CAACC,SAAS,GAAGN,OAAOI,KAAK,CAACC,UAAU,CAACC,SAAS,IAAI,EAAE;QAC3EN,OAAOI,KAAK,CAACC,UAAU,CAACC,SAAS,CAACH,IAAI,CACpC;QAIA,CAAA,AAACH,CAAAA,OAAOO,IAAI,KAAK,CAAC,CAAA,EAAGC,KAAK,KAAK,EAAE,AAAD,EAAGL,IAAI,CAACX,8BAA8BQ,QAAQD;QAEhF,IAAIU,sBAAsBT,OAAOE,WAAW;QAE5C,MAAMQ,uBAAuBX,aAAaG,WAAW,IAAIH,aAAaG,WAAW,EAAES,SAAS;QAE5F,IAAID,sBAAsB;YACxBD,sBAAsBT,OAAOE,WAAW,EAAEU,OAAO,CAAC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AAMG;oBACNI,WAAWX,OAAOW,SAAS;gBAC7B;YACF;YACAC,QAAQ;YACR5C,MAAM;QACR;QAEA;;KAEC,GACD,MAAM6C,yBAAyBC,OAAOC,OAAO,CAACvE,cAAcwE,MAAM,CAChE,CAACC,KAAK,CAACP,KAAKQ,MAAM;YAChBD,GAAG,CAACP,IAAI,GAAGQ,MAAM1E,YAAY;YAC7B,OAAOyE;QACT,GACA,CAAC;QAGHrE,OAAOgC,IAAI,GAAG;YACZ,GAAGhC,OAAOgC,IAAI;YACdpC,cAAcP,gBAAgB4E,wBAAwBjE,OAAOgC,IAAI,EAAEpC,gBAAgB,CAAC;QACtF;QAEA,OAAOI;IACT,EAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -13,10 +13,30 @@ export type ImportExportPluginConfig = {
|
|
|
13
13
|
* If true, enables debug logging
|
|
14
14
|
*/
|
|
15
15
|
debug?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* If true, disables the download button in the export preview UI
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
disableDownload?: boolean;
|
|
16
21
|
/**
|
|
17
22
|
* Enable to force the export to run synchronously
|
|
18
23
|
*/
|
|
19
24
|
disableJobsQueue?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* If true, disables the save button in the export preview UI
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
disableSave?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Forces a specific export format (`csv` or `json`) and hides the format dropdown from the UI.
|
|
32
|
+
*
|
|
33
|
+
* When defined, this overrides the user's ability to choose a format manually. The export will
|
|
34
|
+
* always use the specified format, and the format selection field will be hidden.
|
|
35
|
+
*
|
|
36
|
+
* If not set, the user can choose between CSV and JSON in the export UI.
|
|
37
|
+
* @default undefined
|
|
38
|
+
*/
|
|
39
|
+
format?: 'csv' | 'json';
|
|
20
40
|
/**
|
|
21
41
|
* This function takes the default export collection configured in the plugin and allows you to override it by modifying and returning it
|
|
22
42
|
* @param collection
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAErF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,sBAAsB,CAAA;IAC7B,MAAM,EAAE,YAAY,CAAA;CACrB,GAAG,gBAAgB,CAAA;AAEpB,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,kBAAkB,CAAA;CAClF,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE;IACjC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B;;OAEG;IACH,GAAG,EAAE,QAAQ,CAAA;IACb;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC;;OAEG;IACH,KAAK,EAAE,OAAO,CAAA;CACf,KAAK,OAAO,CAAA"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAErF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,sBAAsB,CAAA;IAC7B,MAAM,EAAE,YAAY,CAAA;CACrB,GAAG,gBAAgB,CAAA;AAEpB,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IACvB;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,kBAAkB,CAAA;CAClF,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE;IACjC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B;;OAEG;IACH,GAAG,EAAE,QAAQ,CAAA;IACb;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC;;OAEG;IACH,KAAK,EAAE,OAAO,CAAA;CACf,KAAK,OAAO,CAAA"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { CollectionAdminOptions, CollectionConfig, UploadConfig } from 'payload'\n\nexport type CollectionOverride = {\n admin: CollectionAdminOptions\n upload: UploadConfig\n} & CollectionConfig\n\nexport type ImportExportPluginConfig = {\n /**\n * Collections to include the Import/Export controls in\n * Defaults to all collections\n */\n collections?: string[]\n /**\n * If true, enables debug logging\n */\n debug?: boolean\n /**\n * Enable to force the export to run synchronously\n */\n disableJobsQueue?: boolean\n /**\n * This function takes the default export collection configured in the plugin and allows you to override it by modifying and returning it\n * @param collection\n * @returns collection\n */\n overrideExportCollection?: (collection: CollectionOverride) => CollectionOverride\n}\n\n/**\n * Custom function used to modify the outgoing csv data by manipulating the data, siblingData or by returning the desired value\n */\nexport type ToCSVFunction = (args: {\n /**\n * The path of the column for the field, for arrays this includes the index (zero-based)\n */\n columnName: string\n /**\n * Alias for `row`, the object that accumulates CSV output.\n * Use this to write additional fields into the exported row.\n */\n data: Record<string, unknown>\n /**\n * The top level document\n */\n doc: Document\n /**\n * The object data that can be manipulated to assign data to the CSV\n */\n row: Record<string, unknown>\n /**\n * The document data at the level where it belongs\n */\n siblingDoc: Record<string, unknown>\n /**\n * The data for the field.\n */\n value: unknown\n}) => unknown\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { CollectionAdminOptions, CollectionConfig, UploadConfig } from 'payload'\n\nexport type CollectionOverride = {\n admin: CollectionAdminOptions\n upload: UploadConfig\n} & CollectionConfig\n\nexport type ImportExportPluginConfig = {\n /**\n * Collections to include the Import/Export controls in\n * Defaults to all collections\n */\n collections?: string[]\n /**\n * If true, enables debug logging\n */\n debug?: boolean\n /**\n * If true, disables the download button in the export preview UI\n * @default false\n */\n disableDownload?: boolean\n /**\n * Enable to force the export to run synchronously\n */\n disableJobsQueue?: boolean\n /**\n * If true, disables the save button in the export preview UI\n * @default false\n */\n disableSave?: boolean\n /**\n * Forces a specific export format (`csv` or `json`) and hides the format dropdown from the UI.\n *\n * When defined, this overrides the user's ability to choose a format manually. The export will\n * always use the specified format, and the format selection field will be hidden.\n *\n * If not set, the user can choose between CSV and JSON in the export UI.\n * @default undefined\n */\n format?: 'csv' | 'json'\n /**\n * This function takes the default export collection configured in the plugin and allows you to override it by modifying and returning it\n * @param collection\n * @returns collection\n */\n overrideExportCollection?: (collection: CollectionOverride) => CollectionOverride\n}\n\n/**\n * Custom function used to modify the outgoing csv data by manipulating the data, siblingData or by returning the desired value\n */\nexport type ToCSVFunction = (args: {\n /**\n * The path of the column for the field, for arrays this includes the index (zero-based)\n */\n columnName: string\n /**\n * Alias for `row`, the object that accumulates CSV output.\n * Use this to write additional fields into the exported row.\n */\n data: Record<string, unknown>\n /**\n * The top level document\n */\n doc: Document\n /**\n * The object data that can be manipulated to assign data to the CSV\n */\n row: Record<string, unknown>\n /**\n * The document data at the level where it belongs\n */\n siblingDoc: Record<string, unknown>\n /**\n * The data for the field.\n */\n value: unknown\n}) => unknown\n"],"names":[],"mappings":"AAiDA;;CAEC,GACD,WA0Ba"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-import-export",
|
|
3
|
-
"version": "3.48.0-canary.
|
|
3
|
+
"version": "3.48.0-canary.3",
|
|
4
4
|
"description": "Import-Export plugin for Payload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"payload",
|
|
@@ -64,17 +64,17 @@
|
|
|
64
64
|
"csv-parse": "^5.6.0",
|
|
65
65
|
"csv-stringify": "^6.5.2",
|
|
66
66
|
"qs-esm": "7.0.2",
|
|
67
|
-
"@payloadcms/
|
|
68
|
-
"@payloadcms/
|
|
67
|
+
"@payloadcms/translations": "3.48.0-canary.3",
|
|
68
|
+
"@payloadcms/ui": "3.48.0-canary.3"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@payloadcms/eslint-config": "3.28.0",
|
|
72
|
-
"@payloadcms/ui": "3.48.0-canary.
|
|
73
|
-
"payload": "3.48.0-canary.
|
|
72
|
+
"@payloadcms/ui": "3.48.0-canary.3",
|
|
73
|
+
"payload": "3.48.0-canary.3"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"@payloadcms/ui": "3.48.0-canary.
|
|
77
|
-
"payload": "3.48.0-canary.
|
|
76
|
+
"@payloadcms/ui": "3.48.0-canary.3",
|
|
77
|
+
"payload": "3.48.0-canary.3"
|
|
78
78
|
},
|
|
79
79
|
"homepage:": "https://payloadcms.com",
|
|
80
80
|
"scripts": {
|