@payloadcms/plugin-import-export 3.68.0-internal-debug.e9b66ee → 3.68.0-internal.35482da
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.js +2 -1
- package/dist/components/ExportSaveButton/index.js.map +1 -1
- package/dist/components/Page/index.js +2 -1
- package/dist/components/Page/index.js.map +1 -1
- package/dist/components/SortOrder/index.js +4 -2
- package/dist/components/SortOrder/index.js.map +1 -1
- package/dist/export/createExport.js +8 -4
- package/dist/export/createExport.js.map +1 -1
- package/dist/utilities/collectDisabledFieldPaths.js +2 -1
- package/dist/utilities/collectDisabledFieldPaths.js.map +1 -1
- package/package.json +7 -7
|
@@ -17,7 +17,8 @@ export const ExportSaveButton = ()=>{
|
|
|
17
17
|
let timeoutID = null;
|
|
18
18
|
let toastID = null;
|
|
19
19
|
try {
|
|
20
|
-
setModified(false)
|
|
20
|
+
setModified(false) // Reset modified state
|
|
21
|
+
;
|
|
21
22
|
const data = getData();
|
|
22
23
|
// Set a timeout to show toast if the request takes longer than 200ms
|
|
23
24
|
timeoutID = setTimeout(()=>{
|
|
@@ -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 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 // Try to parse the error message from the JSON response\n let errorMsg = 'Failed to download file'\n try {\n const errorJson = await response.json()\n if (errorJson?.errors?.[0]?.message) {\n errorMsg = errorJson.errors[0].message\n }\n } catch {\n // Ignore JSON parse errors, fallback to generic message\n }\n throw new Error(errorMsg)\n }\n\n const fileStream = response.body\n const reader = fileStream?.getReader()\n const decoder = new TextDecoder()\n let result = ''\n\n while (reader) {\n const { done, value } = await reader.read()\n if (done) {\n break\n }\n result += decoder.decode(value, { stream: true })\n }\n\n const blob = new Blob([result], { type: 'text/plain' })\n const url = URL.createObjectURL(blob)\n const a = document.createElement('a')\n a.href = url\n a.download = `${data.name}.${data.format}`\n document.body.appendChild(a)\n a.click()\n document.body.removeChild(a)\n URL.revokeObjectURL(url)\n } catch (error: any) {\n toast.error(error.message || 'Error downloading file')\n }\n }\n\n return (\n <React.Fragment>\n {!disableSave && <SaveButton label={label} />}\n {!disableDownload && (\n <Button disabled={!modified} onClick={handleDownload} size=\"medium\" type=\"button\">\n <Translation i18nKey=\"upload:download\" t={t} />\n </Button>\n )}\n </React.Fragment>\n )\n}\n"],"names":["Button","SaveButton","toast","Translation","useConfig","useForm","useFormModified","useTranslation","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","errorMsg","errorJson","json","errors","message","Error","fileStream","reader","getReader","decoder","TextDecoder","result","done","value","read","decode","stream","blob","Blob","type","url","URL","createObjectURL","a","document","createElement","href","download","name","format","appendChild","click","removeChild","revokeObjectURL","error","Fragment","disabled","onClick","size","i18nKey"],"mappings":"AAAA;;AAEA,SACEA,MAAM,EACNC,UAAU,EACVC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,eAAe,EACfC,cAAc,QACT,iBAAgB;AACvB,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,kBAAkBL,yBAAyBG,OAAOC,QAAQC,oBAAoB;IAEpF,MAAMC,QAAQf,EAAE;IAEhB,MAAMgB,iBAAiB;QACrB,IAAIC,YAAkD;QACtD,IAAIC,UAAkC;QAEtC,IAAI;YACFX,YAAY,
|
|
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 // Try to parse the error message from the JSON response\n let errorMsg = 'Failed to download file'\n try {\n const errorJson = await response.json()\n if (errorJson?.errors?.[0]?.message) {\n errorMsg = errorJson.errors[0].message\n }\n } catch {\n // Ignore JSON parse errors, fallback to generic message\n }\n throw new Error(errorMsg)\n }\n\n const fileStream = response.body\n const reader = fileStream?.getReader()\n const decoder = new TextDecoder()\n let result = ''\n\n while (reader) {\n const { done, value } = await reader.read()\n if (done) {\n break\n }\n result += decoder.decode(value, { stream: true })\n }\n\n const blob = new Blob([result], { type: 'text/plain' })\n const url = URL.createObjectURL(blob)\n const a = document.createElement('a')\n a.href = url\n a.download = `${data.name}.${data.format}`\n document.body.appendChild(a)\n a.click()\n document.body.removeChild(a)\n URL.revokeObjectURL(url)\n } catch (error: any) {\n toast.error(error.message || 'Error downloading file')\n }\n }\n\n return (\n <React.Fragment>\n {!disableSave && <SaveButton label={label} />}\n {!disableDownload && (\n <Button disabled={!modified} onClick={handleDownload} size=\"medium\" type=\"button\">\n <Translation i18nKey=\"upload:download\" t={t} />\n </Button>\n )}\n </React.Fragment>\n )\n}\n"],"names":["Button","SaveButton","toast","Translation","useConfig","useForm","useFormModified","useTranslation","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","errorMsg","errorJson","json","errors","message","Error","fileStream","reader","getReader","decoder","TextDecoder","result","done","value","read","decode","stream","blob","Blob","type","url","URL","createObjectURL","a","document","createElement","href","download","name","format","appendChild","click","removeChild","revokeObjectURL","error","Fragment","disabled","onClick","size","i18nKey"],"mappings":"AAAA;;AAEA,SACEA,MAAM,EACNC,UAAU,EACVC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,eAAe,EACfC,cAAc,QACT,iBAAgB;AACvB,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,kBAAkBL,yBAAyBG,OAAOC,QAAQC,oBAAoB;IAEpF,MAAMC,QAAQf,EAAE;IAEhB,MAAMgB,iBAAiB;QACrB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AMM,IAAIC,SAASC,aAAa,CAAC;YACjCF,EAAEG,IAAI,GAAGN;YACTG,EAAEI,QAAQ,GAAG,GAAGzC,KAAK0C,IAAI,CAAC,CAAC,EAAE1C,KAAK2C,MAAM,EAAE;YAC1CL,SAASjC,IAAI,CAACuC,WAAW,CAACP;YAC1BA,EAAEQ,KAAK;YACPP,SAASjC,IAAI,CAACyC,WAAW,CAACT;YAC1BF,IAAIY,eAAe,CAACb;QACtB,EAAE,OAAOc,OAAY;YACnB3E,MAAM2E,KAAK,CAACA,MAAM9B,OAAO,IAAI;QAC/B;IACF;IAEA,qBACE,MAACvC,MAAMsE,QAAQ;;YACZ,CAACzD,6BAAe,KAACpB;gBAAWwB,OAAOA;;YACnC,CAACD,iCACA,KAACxB;gBAAO+E,UAAU,CAAC7D;gBAAU8D,SAAStD;gBAAgBuD,MAAK;gBAASnB,MAAK;0BACvE,cAAA,KAAC3D;oBAAY+E,SAAQ;oBAAkBxE,GAAGA;;;;;AAKpD,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Page/index.tsx"],"sourcesContent":["'use client'\n\nimport type { NumberFieldClientComponent } from 'payload'\n\nimport { NumberField, useField } from '@payloadcms/ui'\nimport React, { useEffect } from 'react'\n\nimport './index.scss'\n\nconst baseClass = 'page-field'\n\nexport const Page: NumberFieldClientComponent = (props) => {\n const { setValue } = useField<number>()\n const { value: limitValue } = useField<number>({ path: 'limit' })\n\n // Effect to reset page to 1 if limit is removed\n useEffect(() => {\n if (!limitValue) {\n setValue(1) // Reset page to 1\n }\n }, [limitValue, setValue])\n\n return (\n <div className={baseClass}>\n <NumberField\n field={{\n name: props.field.name,\n admin: {\n autoComplete: undefined,\n placeholder: undefined,\n step: 1,\n },\n label: props.field.label,\n min: 1,\n }}\n onChange={(value) => setValue(value ?? 1)} // Update the page value on change\n path={props.path}\n />\n </div>\n )\n}\n"],"names":["NumberField","useField","React","useEffect","baseClass","Page","props","setValue","value","limitValue","path","div","className","field","name","admin","autoComplete","undefined","placeholder","step","label","min","onChange"],"mappings":"AAAA;;AAIA,SAASA,WAAW,EAAEC,QAAQ,QAAQ,iBAAgB;AACtD,OAAOC,SAASC,SAAS,QAAQ,QAAO;AAExC,OAAO,eAAc;AAErB,MAAMC,YAAY;AAElB,OAAO,MAAMC,OAAmC,CAACC;IAC/C,MAAM,EAAEC,QAAQ,EAAE,GAAGN;IACrB,MAAM,EAAEO,OAAOC,UAAU,EAAE,GAAGR,SAAiB;QAAES,MAAM;IAAQ;IAE/D,gDAAgD;IAChDP,UAAU;QACR,IAAI,CAACM,YAAY;YACfF,SAAS,
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Page/index.tsx"],"sourcesContent":["'use client'\n\nimport type { NumberFieldClientComponent } from 'payload'\n\nimport { NumberField, useField } from '@payloadcms/ui'\nimport React, { useEffect } from 'react'\n\nimport './index.scss'\n\nconst baseClass = 'page-field'\n\nexport const Page: NumberFieldClientComponent = (props) => {\n const { setValue } = useField<number>()\n const { value: limitValue } = useField<number>({ path: 'limit' })\n\n // Effect to reset page to 1 if limit is removed\n useEffect(() => {\n if (!limitValue) {\n setValue(1) // Reset page to 1\n }\n }, [limitValue, setValue])\n\n return (\n <div className={baseClass}>\n <NumberField\n field={{\n name: props.field.name,\n admin: {\n autoComplete: undefined,\n placeholder: undefined,\n step: 1,\n },\n label: props.field.label,\n min: 1,\n }}\n onChange={(value) => setValue(value ?? 1)} // Update the page value on change\n path={props.path}\n />\n </div>\n )\n}\n"],"names":["NumberField","useField","React","useEffect","baseClass","Page","props","setValue","value","limitValue","path","div","className","field","name","admin","autoComplete","undefined","placeholder","step","label","min","onChange"],"mappings":"AAAA;;AAIA,SAASA,WAAW,EAAEC,QAAQ,QAAQ,iBAAgB;AACtD,OAAOC,SAASC,SAAS,QAAQ,QAAO;AAExC,OAAO,eAAc;AAErB,MAAMC,YAAY;AAElB,OAAO,MAAMC,OAAmC,CAACC;IAC/C,MAAM,EAAEC,QAAQ,EAAE,GAAGN;IACrB,MAAM,EAAEO,OAAOC,UAAU,EAAE,GAAGR,SAAiB;QAAES,MAAM;IAAQ;IAE/D,gDAAgD;IAChDP,UAAU;QACR,IAAI,CAACM,YAAY;YACfF,SAAS,GAAG,kBAAkB;;QAChC;IACF,GAAG;QAACE;QAAYF;KAAS;IAEzB,qBACE,KAACI;QAAIC,WAAWR;kBACd,cAAA,KAACJ;YACCa,OAAO;gBACLC,MAAMR,MAAMO,KAAK,CAACC,IAAI;gBACtBC,OAAO;oBACLC,cAAcC;oBACdC,aAAaD;oBACbE,MAAM;gBACR;gBACAC,OAAOd,MAAMO,KAAK,CAACO,KAAK;gBACxBC,KAAK;YACP;YACAC,UAAU,CAACd,QAAUD,SAASC,SAAS;YACvCE,MAAMJ,MAAMI,IAAI;;;AAIxB,EAAC"}
|
|
@@ -56,14 +56,16 @@ export const SortOrder = (props)=>{
|
|
|
56
56
|
const base = stripSortDash(qsSort);
|
|
57
57
|
const order = isDesc ? 'desc' : 'asc';
|
|
58
58
|
setOrder(order);
|
|
59
|
-
setSort(applySortOrder(base, order))
|
|
59
|
+
setSort(applySortOrder(base, order)) // combined: 'title' or '-title'
|
|
60
|
+
;
|
|
60
61
|
didInitRef.current = true;
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
64
|
// Fallback: groupBy (always ascending)
|
|
64
65
|
if (qsGroupBy) {
|
|
65
66
|
setOrder('asc');
|
|
66
|
-
setSort(applySortOrder(qsGroupBy, 'asc'))
|
|
67
|
+
setSort(applySortOrder(qsGroupBy, 'asc')) // write 'groupByField' (no dash)
|
|
68
|
+
;
|
|
67
69
|
didInitRef.current = true;
|
|
68
70
|
return;
|
|
69
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/SortOrder/index.tsx"],"sourcesContent":["'use client'\n\nimport type { SelectFieldClientComponent } from 'payload'\n\nimport { FieldLabel, ReactSelect, useDocumentInfo, useField, useListQuery } from '@payloadcms/ui'\nimport React, { useEffect, useMemo, useRef, useState } from 'react'\n\nimport { applySortOrder, normalizeQueryParam, stripSortDash } from '../../utilities/sortHelpers.js'\nimport './index.scss'\n\nconst baseClass = 'sort-order-field'\n\ntype Order = 'asc' | 'desc'\ntype OrderOption = { label: string; value: Order }\n\nconst options = [\n { label: 'Ascending', value: 'asc' as const },\n { label: 'Descending', value: 'desc' as const },\n] as const\n\nconst defaultOption: OrderOption = options[0]\n\nexport const SortOrder: SelectFieldClientComponent = (props) => {\n const { id } = useDocumentInfo()\n const { query } = useListQuery()\n\n // 'sortOrder' select field: 'asc' | 'desc'\n const { setValue: setOrder, value: orderValueRaw } = useField<Order>()\n\n // 'sort' text field: 'title' | '-title'\n const { setValue: setSort, value: sortRaw } = useField<string>({ path: 'sort' })\n\n // The current order value, defaulting to 'asc' for UI\n const orderValue: Order = orderValueRaw || 'asc'\n\n // Map 'asc' | 'desc' to the option object for ReactSelect\n const currentOption = useMemo<OrderOption>(\n () => options.find((o) => o.value === orderValue) ?? defaultOption,\n [orderValue],\n )\n const [displayed, setDisplayed] = useState<null | OrderOption>(currentOption)\n\n // One-time init guard so clearing `sort` doesn't rehydrate from query again\n const didInitRef = useRef(false)\n\n // Derive from list-view query.sort if present; otherwise fall back to groupBy\n useEffect(() => {\n if (didInitRef.current) {\n return\n }\n\n // Existing export -> don't initialize here\n if (id) {\n didInitRef.current = true\n return\n }\n\n // If sort already has a value, treat as initialized\n if (typeof sortRaw === 'string' && sortRaw.length > 0) {\n didInitRef.current = true\n return\n }\n\n const qsSort = normalizeQueryParam(query?.sort)\n const qsGroupBy = normalizeQueryParam(query?.groupBy)\n\n if (qsSort) {\n const isDesc = qsSort.startsWith('-')\n const base = stripSortDash(qsSort)\n const order: Order = isDesc ? 'desc' : 'asc'\n setOrder(order)\n setSort(applySortOrder(base, order)) // combined: 'title' or '-title'\n didInitRef.current = true\n return\n }\n\n // Fallback: groupBy (always ascending)\n if (qsGroupBy) {\n setOrder('asc')\n setSort(applySortOrder(qsGroupBy, 'asc')) // write 'groupByField' (no dash)\n didInitRef.current = true\n return\n }\n\n // Nothing to initialize\n didInitRef.current = true\n }, [id, query?.sort, query?.groupBy, sortRaw, setOrder, setSort])\n\n // Keep the select's displayed option in sync with the stored order\n useEffect(() => {\n setDisplayed(currentOption ?? defaultOption)\n }, [currentOption])\n\n // Handle manual order changes via ReactSelect:\n // - update the order field\n // - rewrite the combined \"sort\" string to add/remove the leading '-'\n const onChange = (option: null | OrderOption) => {\n const next = option?.value ?? 'asc'\n setOrder(next)\n\n const base = stripSortDash(sortRaw)\n if (base) {\n setSort(applySortOrder(base, next))\n }\n\n setDisplayed(option ?? defaultOption)\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 inputId={`field-${props.path.replace(/\\./g, '__')}`}\n isClearable={false}\n isSearchable={false}\n // @ts-expect-error react-select option typing differs from our local type\n onChange={onChange}\n options={options as unknown as OrderOption[]}\n // @ts-expect-error react-select option typing differs from our local type\n value={displayed}\n />\n </div>\n )\n}\n"],"names":["FieldLabel","ReactSelect","useDocumentInfo","useField","useListQuery","React","useEffect","useMemo","useRef","useState","applySortOrder","normalizeQueryParam","stripSortDash","baseClass","options","label","value","defaultOption","SortOrder","props","id","query","setValue","setOrder","orderValueRaw","setSort","sortRaw","path","orderValue","currentOption","find","o","displayed","setDisplayed","didInitRef","current","length","qsSort","sort","qsGroupBy","groupBy","isDesc","startsWith","base","order","onChange","option","next","div","className","field","disabled","readOnly","inputId","replace","isClearable","isSearchable"],"mappings":"AAAA;;AAIA,SAASA,UAAU,EAAEC,WAAW,EAAEC,eAAe,EAAEC,QAAQ,EAAEC,YAAY,QAAQ,iBAAgB;AACjG,OAAOC,SAASC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAEnE,SAASC,cAAc,EAAEC,mBAAmB,EAAEC,aAAa,QAAQ,iCAAgC;AACnG,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ACTnB,QAAQf,eAAeiC,MAAMC,
|
|
1
|
+
{"version":3,"sources":["../../../src/components/SortOrder/index.tsx"],"sourcesContent":["'use client'\n\nimport type { SelectFieldClientComponent } from 'payload'\n\nimport { FieldLabel, ReactSelect, useDocumentInfo, useField, useListQuery } from '@payloadcms/ui'\nimport React, { useEffect, useMemo, useRef, useState } from 'react'\n\nimport { applySortOrder, normalizeQueryParam, stripSortDash } from '../../utilities/sortHelpers.js'\nimport './index.scss'\n\nconst baseClass = 'sort-order-field'\n\ntype Order = 'asc' | 'desc'\ntype OrderOption = { label: string; value: Order }\n\nconst options = [\n { label: 'Ascending', value: 'asc' as const },\n { label: 'Descending', value: 'desc' as const },\n] as const\n\nconst defaultOption: OrderOption = options[0]\n\nexport const SortOrder: SelectFieldClientComponent = (props) => {\n const { id } = useDocumentInfo()\n const { query } = useListQuery()\n\n // 'sortOrder' select field: 'asc' | 'desc'\n const { setValue: setOrder, value: orderValueRaw } = useField<Order>()\n\n // 'sort' text field: 'title' | '-title'\n const { setValue: setSort, value: sortRaw } = useField<string>({ path: 'sort' })\n\n // The current order value, defaulting to 'asc' for UI\n const orderValue: Order = orderValueRaw || 'asc'\n\n // Map 'asc' | 'desc' to the option object for ReactSelect\n const currentOption = useMemo<OrderOption>(\n () => options.find((o) => o.value === orderValue) ?? defaultOption,\n [orderValue],\n )\n const [displayed, setDisplayed] = useState<null | OrderOption>(currentOption)\n\n // One-time init guard so clearing `sort` doesn't rehydrate from query again\n const didInitRef = useRef(false)\n\n // Derive from list-view query.sort if present; otherwise fall back to groupBy\n useEffect(() => {\n if (didInitRef.current) {\n return\n }\n\n // Existing export -> don't initialize here\n if (id) {\n didInitRef.current = true\n return\n }\n\n // If sort already has a value, treat as initialized\n if (typeof sortRaw === 'string' && sortRaw.length > 0) {\n didInitRef.current = true\n return\n }\n\n const qsSort = normalizeQueryParam(query?.sort)\n const qsGroupBy = normalizeQueryParam(query?.groupBy)\n\n if (qsSort) {\n const isDesc = qsSort.startsWith('-')\n const base = stripSortDash(qsSort)\n const order: Order = isDesc ? 'desc' : 'asc'\n setOrder(order)\n setSort(applySortOrder(base, order)) // combined: 'title' or '-title'\n didInitRef.current = true\n return\n }\n\n // Fallback: groupBy (always ascending)\n if (qsGroupBy) {\n setOrder('asc')\n setSort(applySortOrder(qsGroupBy, 'asc')) // write 'groupByField' (no dash)\n didInitRef.current = true\n return\n }\n\n // Nothing to initialize\n didInitRef.current = true\n }, [id, query?.sort, query?.groupBy, sortRaw, setOrder, setSort])\n\n // Keep the select's displayed option in sync with the stored order\n useEffect(() => {\n setDisplayed(currentOption ?? defaultOption)\n }, [currentOption])\n\n // Handle manual order changes via ReactSelect:\n // - update the order field\n // - rewrite the combined \"sort\" string to add/remove the leading '-'\n const onChange = (option: null | OrderOption) => {\n const next = option?.value ?? 'asc'\n setOrder(next)\n\n const base = stripSortDash(sortRaw)\n if (base) {\n setSort(applySortOrder(base, next))\n }\n\n setDisplayed(option ?? defaultOption)\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 inputId={`field-${props.path.replace(/\\./g, '__')}`}\n isClearable={false}\n isSearchable={false}\n // @ts-expect-error react-select option typing differs from our local type\n onChange={onChange}\n options={options as unknown as OrderOption[]}\n // @ts-expect-error react-select option typing differs from our local type\n value={displayed}\n />\n </div>\n )\n}\n"],"names":["FieldLabel","ReactSelect","useDocumentInfo","useField","useListQuery","React","useEffect","useMemo","useRef","useState","applySortOrder","normalizeQueryParam","stripSortDash","baseClass","options","label","value","defaultOption","SortOrder","props","id","query","setValue","setOrder","orderValueRaw","setSort","sortRaw","path","orderValue","currentOption","find","o","displayed","setDisplayed","didInitRef","current","length","qsSort","sort","qsGroupBy","groupBy","isDesc","startsWith","base","order","onChange","option","next","div","className","field","disabled","readOnly","inputId","replace","isClearable","isSearchable"],"mappings":"AAAA;;AAIA,SAASA,UAAU,EAAEC,WAAW,EAAEC,eAAe,EAA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
|
|
@@ -141,7 +141,8 @@ export const createExport = async (args)=>{
|
|
|
141
141
|
});
|
|
142
142
|
});
|
|
143
143
|
fetched += result.docs.length;
|
|
144
|
-
scanPage += 1
|
|
144
|
+
scanPage += 1 // Increment page for next batch
|
|
145
|
+
;
|
|
145
146
|
hasMore = result.hasNextPage && fetched < maxDocs;
|
|
146
147
|
}
|
|
147
148
|
if (debug) {
|
|
@@ -211,7 +212,8 @@ export const createExport = async (args)=>{
|
|
|
211
212
|
}
|
|
212
213
|
fetched += result.docs.length;
|
|
213
214
|
isFirstBatch = false;
|
|
214
|
-
streamPage += 1
|
|
215
|
+
streamPage += 1 // Increment stream page for the next batch
|
|
216
|
+
;
|
|
215
217
|
if (!result.hasNextPage || fetched >= maxDocs) {
|
|
216
218
|
if (debug) {
|
|
217
219
|
req.payload.logger.debug('Stream complete - no more pages');
|
|
@@ -219,7 +221,8 @@ export const createExport = async (args)=>{
|
|
|
219
221
|
if (!isCSV) {
|
|
220
222
|
this.push(encoder.encode(']'));
|
|
221
223
|
}
|
|
222
|
-
this.push(null)
|
|
224
|
+
this.push(null) // End the stream
|
|
225
|
+
;
|
|
223
226
|
}
|
|
224
227
|
}
|
|
225
228
|
});
|
|
@@ -278,7 +281,8 @@ export const createExport = async (args)=>{
|
|
|
278
281
|
}
|
|
279
282
|
fetched += result.docs.length;
|
|
280
283
|
hasNextPage = result.hasNextPage && fetched < maxDocs;
|
|
281
|
-
currentPage += 1
|
|
284
|
+
currentPage += 1 // Increment page for next batch
|
|
285
|
+
;
|
|
282
286
|
}
|
|
283
287
|
// Prepare final output
|
|
284
288
|
if (isCSV) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/createExport.ts"],"sourcesContent":["/* eslint-disable perfectionist/sort-objects */\nimport type { PayloadRequest, Sort, TypedUser, Where } from 'payload'\n\nimport { stringify } from 'csv-stringify/sync'\nimport { APIError } from 'payload'\nimport { Readable } from 'stream'\n\nimport { buildDisabledFieldRegex } from '../utilities/buildDisabledFieldRegex.js'\nimport { validateLimitValue } from '../utilities/validateLimitValue.js'\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 limit?: number\n locale?: string\n name: string\n page?: number\n slug: string\n sort: Sort\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?: null | 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 page,\n limit: incomingLimit,\n where,\n },\n req: { locale: localeArg, payload },\n req,\n user,\n } = args\n\n if (!user) {\n throw new APIError('User authentication is required to create exports')\n }\n\n if (debug) {\n req.payload.logger.debug({\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.debug({ message: 'Export configuration:', name, isCSV, locale })\n }\n\n const batchSize = 100 // fixed per request\n\n const hardLimit =\n typeof incomingLimit === 'number' && incomingLimit > 0 ? incomingLimit : undefined\n\n const { totalDocs } = await payload.count({\n collection: collectionSlug,\n user,\n locale,\n overrideAccess: false,\n })\n\n const totalPages = Math.max(1, Math.ceil(totalDocs / batchSize))\n const requestedPage = page || 1\n const adjustedPage = requestedPage > totalPages ? 1 : requestedPage\n\n const findArgs = {\n collection: collectionSlug,\n depth: 1,\n draft: drafts === 'yes',\n limit: batchSize,\n locale,\n overrideAccess: false,\n page: 0, // The page will be incremented manually in the loop\n select,\n sort,\n user,\n where,\n }\n\n if (debug) {\n req.payload.logger.debug({ message: 'Find arguments:', findArgs })\n }\n\n const toCSVFunctions = getCustomFieldFunctions({\n fields: collectionConfig.flattenedFields,\n })\n\n const disabledFields =\n collectionConfig.admin?.custom?.['plugin-import-export']?.disabledFields ?? []\n\n const disabledRegexes: RegExp[] = disabledFields.map(buildDisabledFieldRegex)\n\n const filterDisabledCSV = (row: Record<string, unknown>): Record<string, unknown> => {\n const filtered: Record<string, unknown> = {}\n\n for (const [key, value] of Object.entries(row)) {\n const isDisabled = disabledRegexes.some((regex) => regex.test(key))\n if (!isDisabled) {\n filtered[key] = value\n }\n }\n\n return filtered\n }\n\n const filterDisabledJSON = (doc: any, parentPath = ''): any => {\n if (Array.isArray(doc)) {\n return doc.map((item) => filterDisabledJSON(item, parentPath))\n }\n\n if (typeof doc !== 'object' || doc === null) {\n return doc\n }\n\n const filtered: Record<string, any> = {}\n for (const [key, value] of Object.entries(doc)) {\n const currentPath = parentPath ? `${parentPath}.${key}` : key\n\n // Only remove if this exact path is disabled\n const isDisabled = disabledFields.includes(currentPath)\n\n if (!isDisabled) {\n filtered[key] = filterDisabledJSON(value, currentPath)\n }\n }\n\n return filtered\n }\n\n if (download) {\n if (debug) {\n req.payload.logger.debug('Pre-scanning all columns before streaming')\n }\n\n const limitErrorMsg = validateLimitValue(\n incomingLimit,\n req.t,\n batchSize, // step i.e. 100\n )\n if (limitErrorMsg) {\n throw new APIError(limitErrorMsg)\n }\n\n const allColumns: string[] = []\n\n if (isCSV) {\n const allColumnsSet = new Set<string>()\n\n // Use the incoming page value here, defaulting to 1 if undefined\n let scanPage = adjustedPage\n let hasMore = true\n let fetched = 0\n const maxDocs = typeof hardLimit === 'number' ? hardLimit : Number.POSITIVE_INFINITY\n\n while (hasMore) {\n const remaining = Math.max(0, maxDocs - fetched)\n if (remaining === 0) {\n break\n }\n\n const result = await payload.find({\n ...findArgs,\n page: scanPage,\n limit: Math.min(batchSize, remaining),\n })\n\n result.docs.forEach((doc) => {\n const flat = filterDisabledCSV(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 fetched += result.docs.length\n scanPage += 1 // Increment page for next batch\n hasMore = result.hasNextPage && fetched < maxDocs\n }\n\n if (debug) {\n req.payload.logger.debug(`Discovered ${allColumns.length} columns`)\n }\n }\n\n const encoder = new TextEncoder()\n let isFirstBatch = true\n let streamPage = adjustedPage\n let fetched = 0\n const maxDocs = typeof hardLimit === 'number' ? hardLimit : Number.POSITIVE_INFINITY\n\n const stream = new Readable({\n async read() {\n const remaining = Math.max(0, maxDocs - fetched)\n\n if (remaining === 0) {\n if (!isCSV) {\n this.push(encoder.encode(']'))\n }\n this.push(null)\n return\n }\n\n const result = await payload.find({\n ...findArgs,\n page: streamPage,\n limit: Math.min(batchSize, remaining),\n })\n\n if (debug) {\n req.payload.logger.debug(`Streaming batch ${streamPage} with ${result.docs.length} docs`)\n }\n\n if (result.docs.length === 0) {\n // Close JSON array properly if JSON\n if (!isCSV) {\n this.push(encoder.encode(']'))\n }\n this.push(null)\n return\n }\n\n if (isCSV) {\n // --- CSV Streaming ---\n const batchRows = result.docs.map((doc) =>\n filterDisabledCSV(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 } else {\n // --- JSON Streaming ---\n const batchRows = result.docs.map((doc) => filterDisabledJSON(doc))\n\n // Convert each filtered/flattened row into JSON string\n const batchJSON = batchRows.map((row) => JSON.stringify(row)).join(',')\n\n if (isFirstBatch) {\n this.push(encoder.encode('[' + batchJSON))\n } else {\n this.push(encoder.encode(',' + batchJSON))\n }\n }\n\n fetched += result.docs.length\n isFirstBatch = false\n streamPage += 1 // Increment stream page for the next batch\n\n if (!result.hasNextPage || fetched >= maxDocs) {\n if (debug) {\n req.payload.logger.debug('Stream complete - no more pages')\n }\n if (!isCSV) {\n this.push(encoder.encode(']'))\n }\n this.push(null) // End the stream\n }\n },\n })\n\n return new Response(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.debug('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\n // Start from the incoming page value, defaulting to 1 if undefined\n let currentPage = adjustedPage\n let fetched = 0\n let hasNextPage = true\n const maxDocs = typeof hardLimit === 'number' ? hardLimit : Number.POSITIVE_INFINITY\n\n while (hasNextPage) {\n const remaining = Math.max(0, maxDocs - fetched)\n\n if (remaining === 0) {\n break\n }\n\n const result = await payload.find({\n ...findArgs,\n page: currentPage,\n limit: Math.min(batchSize, remaining),\n })\n\n if (debug) {\n req.payload.logger.debug(\n `Processing batch ${currentPage} with ${result.docs.length} documents`,\n )\n }\n\n if (isCSV) {\n const batchRows = result.docs.map((doc) =>\n filterDisabledCSV(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 batchRows = result.docs.map((doc) => filterDisabledJSON(doc))\n outputData.push(batchRows.map((doc) => JSON.stringify(doc)).join(',\\n'))\n }\n\n fetched += result.docs.length\n hasNextPage = result.hasNextPage && fetched < maxDocs\n currentPage += 1 // Increment page for next batch\n }\n\n // Prepare final output\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.debug(`${format} file generation complete`)\n }\n\n if (!id) {\n if (debug) {\n req.payload.logger.debug('Creating new export file')\n }\n req.file = {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n }\n } else {\n if (debug) {\n req.payload.logger.debug(`Updating existing export with id: ${id}`)\n }\n await req.payload.update({\n id,\n collection: 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.debug('Export process completed successfully')\n }\n}\n"],"names":["stringify","APIError","Readable","buildDisabledFieldRegex","validateLimitValue","flattenObject","getCustomFieldFunctions","getFilename","getSelect","createExport","args","download","input","id","name","nameArg","collectionSlug","debug","drafts","exportsCollection","fields","format","locale","localeInput","sort","page","limit","incomingLimit","where","req","localeArg","payload","user","logger","message","collectionConfig","config","collections","find","slug","isCSV","select","Array","isArray","length","undefined","batchSize","hardLimit","totalDocs","count","collection","overrideAccess","totalPages","Math","max","ceil","requestedPage","adjustedPage","findArgs","depth","draft","toCSVFunctions","flattenedFields","disabledFields","admin","custom","disabledRegexes","map","filterDisabledCSV","row","filtered","key","value","Object","entries","isDisabled","some","regex","test","filterDisabledJSON","doc","parentPath","item","currentPath","includes","limitErrorMsg","t","allColumns","allColumnsSet","Set","scanPage","hasMore","fetched","maxDocs","Number","POSITIVE_INFINITY","remaining","result","min","docs","forEach","flat","keys","has","add","push","hasNextPage","encoder","TextEncoder","isFirstBatch","streamPage","stream","read","encode","batchRows","paddedRows","fullRow","col","csvString","header","columns","batchJSON","JSON","join","Response","headers","outputData","rows","columnsSet","currentPage","buffer","Buffer","from","file","data","mimetype","size","update"],"mappings":"AAAA,6CAA6C,GAG7C,SAASA,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,QAAQ,QAAQ,UAAS;AAClC,SAASC,QAAQ,QAAQ,SAAQ;AAEjC,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,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,OAAOC,aAAa,EACpBC,KAAK,EACN,EACDC,KAAK,EAAEP,QAAQQ,SAAS,EAAEC,OAAO,EAAE,EACnCF,GAAG,EACHG,IAAI,EACL,GAAGtB;IAEJ,IAAI,CAACsB,MAAM;QACT,MAAM,IAAI/B,SAAS;IACrB;IAEA,IAAIgB,OAAO;QACTY,IAAIE,OAAO,CAACE,MAAM,CAAChB,KAAK,CAAC;YACvBiB,SAAS;YACTlB;YACAE;YACAE;YACAC;QACF;IACF;IAEA,MAAMC,SAASC,eAAeO;IAC9B,MAAMK,mBAAmBJ,QAAQK,MAAM,CAACC,WAAW,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASvB;IAChF,IAAI,CAACmB,kBAAkB;QACr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;QACT;QAEAU,WAAWrB,IAAI,CACbzG,UAAUmH,YAAY;YACpBI,QAAQ;YACRC;QACF;IAEJ;IAEA,MAAMU,SAASC,OAAOC,IAAI,CAAC/G,WAAW,SAAS,CAAC,CAAC,EAAEyG,WAAWH,IAAI,CAAC,KAAK,CAAC,CAAC,GAAGG,WAAWH,IAAI,CAAC;IAC7F,IAAI1G,OAAO;QACTY,IAAIE,OAAO,CAACE,MAAM,CAAChB,KAAK,CAAC,GAAGI,OAAO,yBAAyB,CAAC;IAC/D;IAEA,IAAI,CAACR,IAAI;QACP,IAAII,OAAO;YACTY,IAAIE,OAAO,CAACE,MAAM,CAAChB,KAAK,CAAC;QAC3B;QACAY,IAAIwG,IAAI,GAAG;YACTvH;YACAwH,MAAMJ;YACNK,UAAU/F,QAAQ,aAAa;YAC/BgG,MAAMN,OAAOtF,MAAM;QACrB;IACF,OAAO;QACL,IAAI3B,OAAO;YACTY,IAAIE,OAAO,CAACE,MAAM,CAAChB,KAAK,CAAC,CAAC,kCAAkC,EAAEJ,IAAI;QACpE;QACA,MAAMgB,IAAIE,OAAO,CAAC0G,MAAM,CAAC;YACvB5H;YACAqC,YAAY/B;YACZmH,MAAM,CAAC;YACPD,MAAM;gBACJvH;gBACAwH,MAAMJ;gBACNK,UAAU/F,QAAQ,aAAa;gBAC/BgG,MAAMN,OAAOtF,MAAM;YACrB;YACAZ;QACF;IACF;IACA,IAAIf,OAAO;QACTY,IAAIE,OAAO,CAACE,MAAM,CAAChB,KAAK,CAAC;IAC3B;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/export/createExport.ts"],"sourcesContent":["/* eslint-disable perfectionist/sort-objects */\nimport type { PayloadRequest, Sort, TypedUser, Where } from 'payload'\n\nimport { stringify } from 'csv-stringify/sync'\nimport { APIError } from 'payload'\nimport { Readable } from 'stream'\n\nimport { buildDisabledFieldRegex } from '../utilities/buildDisabledFieldRegex.js'\nimport { validateLimitValue } from '../utilities/validateLimitValue.js'\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 limit?: number\n locale?: string\n name: string\n page?: number\n slug: string\n sort: Sort\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?: null | 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 page,\n limit: incomingLimit,\n where,\n },\n req: { locale: localeArg, payload },\n req,\n user,\n } = args\n\n if (!user) {\n throw new APIError('User authentication is required to create exports')\n }\n\n if (debug) {\n req.payload.logger.debug({\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.debug({ message: 'Export configuration:', name, isCSV, locale })\n }\n\n const batchSize = 100 // fixed per request\n\n const hardLimit =\n typeof incomingLimit === 'number' && incomingLimit > 0 ? incomingLimit : undefined\n\n const { totalDocs } = await payload.count({\n collection: collectionSlug,\n user,\n locale,\n overrideAccess: false,\n })\n\n const totalPages = Math.max(1, Math.ceil(totalDocs / batchSize))\n const requestedPage = page || 1\n const adjustedPage = requestedPage > totalPages ? 1 : requestedPage\n\n const findArgs = {\n collection: collectionSlug,\n depth: 1,\n draft: drafts === 'yes',\n limit: batchSize,\n locale,\n overrideAccess: false,\n page: 0, // The page will be incremented manually in the loop\n select,\n sort,\n user,\n where,\n }\n\n if (debug) {\n req.payload.logger.debug({ message: 'Find arguments:', findArgs })\n }\n\n const toCSVFunctions = getCustomFieldFunctions({\n fields: collectionConfig.flattenedFields,\n })\n\n const disabledFields =\n collectionConfig.admin?.custom?.['plugin-import-export']?.disabledFields ?? []\n\n const disabledRegexes: RegExp[] = disabledFields.map(buildDisabledFieldRegex)\n\n const filterDisabledCSV = (row: Record<string, unknown>): Record<string, unknown> => {\n const filtered: Record<string, unknown> = {}\n\n for (const [key, value] of Object.entries(row)) {\n const isDisabled = disabledRegexes.some((regex) => regex.test(key))\n if (!isDisabled) {\n filtered[key] = value\n }\n }\n\n return filtered\n }\n\n const filterDisabledJSON = (doc: any, parentPath = ''): any => {\n if (Array.isArray(doc)) {\n return doc.map((item) => filterDisabledJSON(item, parentPath))\n }\n\n if (typeof doc !== 'object' || doc === null) {\n return doc\n }\n\n const filtered: Record<string, any> = {}\n for (const [key, value] of Object.entries(doc)) {\n const currentPath = parentPath ? `${parentPath}.${key}` : key\n\n // Only remove if this exact path is disabled\n const isDisabled = disabledFields.includes(currentPath)\n\n if (!isDisabled) {\n filtered[key] = filterDisabledJSON(value, currentPath)\n }\n }\n\n return filtered\n }\n\n if (download) {\n if (debug) {\n req.payload.logger.debug('Pre-scanning all columns before streaming')\n }\n\n const limitErrorMsg = validateLimitValue(\n incomingLimit,\n req.t,\n batchSize, // step i.e. 100\n )\n if (limitErrorMsg) {\n throw new APIError(limitErrorMsg)\n }\n\n const allColumns: string[] = []\n\n if (isCSV) {\n const allColumnsSet = new Set<string>()\n\n // Use the incoming page value here, defaulting to 1 if undefined\n let scanPage = adjustedPage\n let hasMore = true\n let fetched = 0\n const maxDocs = typeof hardLimit === 'number' ? hardLimit : Number.POSITIVE_INFINITY\n\n while (hasMore) {\n const remaining = Math.max(0, maxDocs - fetched)\n if (remaining === 0) {\n break\n }\n\n const result = await payload.find({\n ...findArgs,\n page: scanPage,\n limit: Math.min(batchSize, remaining),\n })\n\n result.docs.forEach((doc) => {\n const flat = filterDisabledCSV(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 fetched += result.docs.length\n scanPage += 1 // Increment page for next batch\n hasMore = result.hasNextPage && fetched < maxDocs\n }\n\n if (debug) {\n req.payload.logger.debug(`Discovered ${allColumns.length} columns`)\n }\n }\n\n const encoder = new TextEncoder()\n let isFirstBatch = true\n let streamPage = adjustedPage\n let fetched = 0\n const maxDocs = typeof hardLimit === 'number' ? hardLimit : Number.POSITIVE_INFINITY\n\n const stream = new Readable({\n async read() {\n const remaining = Math.max(0, maxDocs - fetched)\n\n if (remaining === 0) {\n if (!isCSV) {\n this.push(encoder.encode(']'))\n }\n this.push(null)\n return\n }\n\n const result = await payload.find({\n ...findArgs,\n page: streamPage,\n limit: Math.min(batchSize, remaining),\n })\n\n if (debug) {\n req.payload.logger.debug(`Streaming batch ${streamPage} with ${result.docs.length} docs`)\n }\n\n if (result.docs.length === 0) {\n // Close JSON array properly if JSON\n if (!isCSV) {\n this.push(encoder.encode(']'))\n }\n this.push(null)\n return\n }\n\n if (isCSV) {\n // --- CSV Streaming ---\n const batchRows = result.docs.map((doc) =>\n filterDisabledCSV(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 } else {\n // --- JSON Streaming ---\n const batchRows = result.docs.map((doc) => filterDisabledJSON(doc))\n\n // Convert each filtered/flattened row into JSON string\n const batchJSON = batchRows.map((row) => JSON.stringify(row)).join(',')\n\n if (isFirstBatch) {\n this.push(encoder.encode('[' + batchJSON))\n } else {\n this.push(encoder.encode(',' + batchJSON))\n }\n }\n\n fetched += result.docs.length\n isFirstBatch = false\n streamPage += 1 // Increment stream page for the next batch\n\n if (!result.hasNextPage || fetched >= maxDocs) {\n if (debug) {\n req.payload.logger.debug('Stream complete - no more pages')\n }\n if (!isCSV) {\n this.push(encoder.encode(']'))\n }\n this.push(null) // End the stream\n }\n },\n })\n\n return new Response(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.debug('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\n // Start from the incoming page value, defaulting to 1 if undefined\n let currentPage = adjustedPage\n let fetched = 0\n let hasNextPage = true\n const maxDocs = typeof hardLimit === 'number' ? hardLimit : Number.POSITIVE_INFINITY\n\n while (hasNextPage) {\n const remaining = Math.max(0, maxDocs - fetched)\n\n if (remaining === 0) {\n break\n }\n\n const result = await payload.find({\n ...findArgs,\n page: currentPage,\n limit: Math.min(batchSize, remaining),\n })\n\n if (debug) {\n req.payload.logger.debug(\n `Processing batch ${currentPage} with ${result.docs.length} documents`,\n )\n }\n\n if (isCSV) {\n const batchRows = result.docs.map((doc) =>\n filterDisabledCSV(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 batchRows = result.docs.map((doc) => filterDisabledJSON(doc))\n outputData.push(batchRows.map((doc) => JSON.stringify(doc)).join(',\\n'))\n }\n\n fetched += result.docs.length\n hasNextPage = result.hasNextPage && fetched < maxDocs\n currentPage += 1 // Increment page for next batch\n }\n\n // Prepare final output\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.debug(`${format} file generation complete`)\n }\n\n if (!id) {\n if (debug) {\n req.payload.logger.debug('Creating new export file')\n }\n req.file = {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n }\n } else {\n if (debug) {\n req.payload.logger.debug(`Updating existing export with id: ${id}`)\n }\n await req.payload.update({\n id,\n collection: 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.debug('Export process completed successfully')\n }\n}\n"],"names":["stringify","APIError","Readable","buildDisabledFieldRegex","validateLimitValue","flattenObject","getCustomFieldFunctions","getFilename","getSelect","createExport","args","download","input","id","name","nameArg","collectionSlug","debug","drafts","exportsCollection","fields","format","locale","localeInput","sort","page","limit","incomingLimit","where","req","localeArg","payload","user","logger","message","collectionConfig","config","collections","find","slug","isCSV","select","Array","isArray","length","undefined","batchSize","hardLimit","totalDocs","count","collection","overrideAccess","totalPages","Math","max","ceil","requestedPage","adjustedPage","findArgs","depth","draft","toCSVFunctions","flattenedFields","disabledFields","admin","custom","disabledRegexes","map","filterDisabledCSV","row","filtered","key","value","Object","entries","isDisabled","some","regex","test","filterDisabledJSON","doc","parentPath","item","currentPath","includes","limitErrorMsg","t","allColumns","allColumnsSet","Set","scanPage","hasMore","fetched","maxDocs","Number","POSITIVE_INFINITY","remaining","result","min","docs","forEach","flat","keys","has","add","push","hasNextPage","encoder","TextEncoder","isFirstBatch","streamPage","stream","read","encode","batchRows","paddedRows","fullRow","col","csvString","header","columns","batchJSON","JSON","join","Response","headers","outputData","rows","columnsSet","currentPage","buffer","Buffer","from","file","data","mimetype","size","update"],"mappings":"AAAA,6CAA6C,GAG7C,SAASA,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,QAAQ,QAAQ,UAAS;AAClC,SAASC,QAAQ,QAAQ,SAAQ;AAEjC,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,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,OAAOC,aAAa,EACpBC,KAAK,EACN,EACDC,KAAK,EAAEP,QAAQQ,SAAS,EAAEC,OAAO,EAAE,EACnCF,GAAG,EACHG,IAAI,EACL,GAAGtB;IAEJ,IAAI,CAACsB,MAAM;QACT,MAAM,IAAI/B,SAAS;IACrB;IAEA,IAAIgB,OAAO;QACTY,IAAIE,OAAO,CAACE,MAAM,CAAChB,KAAK,CAAC;YACvBiB,SAAS;YACTlB;YACAE;YACAE;YACAC;QACF;IACF;IAEA,MAAMC,SAASC,eAAeO;IAC9B,MAAMK,mBAAmBJ,QAAQK,MAAM,CAACC,WAAW,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASvB;IAChF,IAAI,CAACmB,kBAAkB;QACrB,MAAM,IAAIlC,SAAS,CAAC,qBAAqB,EAAEe,eAAe,UAAU,CAAC;IACvE;IAE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C;QACF;IAEJ;IAEA,MAAMU,SAASC,OAAOC,IAAI,CAAC/G,WAAW,SAAS,CAAC,CAAC,EAAEyG,WAAWH,IAAI,CAAC,KAAK,CAAC,CAAC,GAAGG,WAAWH,IAAI,CAAC;IAC7F,IAAI1G,OAAO;QACTY,IAAIE,OAAO,CAACE,MAAM,CAAChB,KAAK,CAAC,GAAGI,OAAO,yBAAyB,CAAC;IAC/D;IAEA,IAAI,CAACR,IAAI;QACP,IAAII,OAAO;YACTY,IAAIE,OAAO,CAACE,MAAM,CAAChB,KAAK,CAAC;QAC3B;QACAY,IAAIwG,IAAI,GAAG;YACTvH;YACAwH,MAAMJ;YACNK,UAAU/F,QAAQ,aAAa;YAC/BgG,MAAMN,OAAOtF,MAAM;QACrB;IACF,OAAO;QACL,IAAI3B,OAAO;YACTY,IAAIE,OAAO,CAACE,MAAM,CAAChB,KAAK,CAAC,CAAC,kCAAkC,EAAEJ,IAAI;QACpE;QACA,MAAMgB,IAAIE,OAAO,CAAC0G,MAAM,CAAC;YACvB5H;YACAqC,YAAY/B;YACZmH,MAAM,CAAC;YACPD,MAAM;gBACJvH;gBACAwH,MAAMJ;gBACNK,UAAU/F,QAAQ,aAAa;gBAC/BgG,MAAMN,OAAOtF,MAAM;YACrB;YACAZ;QACF;IACF;IACA,IAAIf,OAAO;QACTY,IAAIE,OAAO,CAACE,MAAM,CAAChB,KAAK,CAAC;IAC3B;AACF,EAAC"}
|
|
@@ -26,7 +26,8 @@ import { fieldAffectsData } from 'payload/shared';
|
|
|
26
26
|
const refObj = ref;
|
|
27
27
|
const tabRef = refObj[tab.name] ?? {};
|
|
28
28
|
tabRef.path = tabPath;
|
|
29
|
-
tabRef.__manualRef = true
|
|
29
|
+
tabRef.__manualRef = true // flag this as a manually constructed parentRef
|
|
30
|
+
;
|
|
30
31
|
refObj[tab.name] = tabRef;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/collectDisabledFieldPaths.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { traverseFields } from 'payload'\nimport { fieldAffectsData } from 'payload/shared'\n\n/**\n * Recursively traverses a Payload field schema to collect all field paths\n * that are explicitly disabled for the import/export plugin via:\n * field.custom['plugin-import-export'].disabled\n *\n * Handles nested fields including named tabs, groups, arrays, blocks, etc.\n * Tracks each field’s path by storing it in `ref.path` and manually propagating\n * it through named tab layers via a temporary `__manualRef` marker.\n *\n * @param fields - The top-level array of Payload field definitions\n * @returns An array of dot-notated field paths that are marked as disabled\n */\nexport const collectDisabledFieldPaths = (fields: Field[]): string[] => {\n const disabledPaths: string[] = []\n\n traverseFields({\n callback: ({ field, next, parentRef, ref }) => {\n // Handle named tabs\n if (field.type === 'tabs' && Array.isArray(field.tabs)) {\n for (const tab of field.tabs) {\n if ('name' in tab && typeof tab.name === 'string') {\n // Build the path prefix for this tab\n const parentPath =\n parentRef && typeof (parentRef as { path?: unknown }).path === 'string'\n ? (parentRef as { path: string }).path\n : ''\n const tabPath = parentPath ? `${parentPath}.${tab.name}` : tab.name\n\n // Prepare a ref for this named tab's children to inherit the path\n const refObj = ref as Record<string, any>\n const tabRef = refObj[tab.name] ?? {}\n tabRef.path = tabPath\n tabRef.__manualRef = true // flag this as a manually constructed parentRef\n refObj[tab.name] = tabRef\n }\n }\n\n // Skip further processing of the tab container itself\n return\n }\n\n // Skip unnamed fields (e.g. rows/collapsibles)\n if (!('name' in field) || typeof field.name !== 'string') {\n return\n }\n\n // Determine the path to the current field\n let parentPath: string | undefined\n\n if (\n parentRef &&\n typeof parentRef === 'object' &&\n 'path' in parentRef &&\n typeof (parentRef as { path?: unknown }).path === 'string'\n ) {\n parentPath = (parentRef as { path: string }).path\n } else if ((ref as any)?.__manualRef && typeof (ref as any)?.path === 'string') {\n // Fallback: if current ref is a manual tabRef, use its path\n parentPath = (ref as any).path\n }\n\n const fullPath = parentPath ? `${parentPath}.${field.name}` : field.name\n\n // Store current path for any nested children to use\n ;(ref as any).path = fullPath\n\n // If field is a data-affecting field and disabled via plugin config, collect its path\n if (fieldAffectsData(field) && field.custom?.['plugin-import-export']?.disabled) {\n disabledPaths.push(fullPath)\n return next?.()\n }\n },\n fields,\n })\n\n return disabledPaths\n}\n"],"names":["traverseFields","fieldAffectsData","collectDisabledFieldPaths","fields","disabledPaths","callback","field","next","parentRef","ref","type","Array","isArray","tabs","tab","name","parentPath","path","tabPath","refObj","tabRef","__manualRef","fullPath","custom","disabled","push"],"mappings":"AAEA,SAASA,cAAc,QAAQ,UAAS;AACxC,SAASC,gBAAgB,QAAQ,iBAAgB;AAEjD;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,4BAA4B,CAACC;IACxC,MAAMC,gBAA0B,EAAE;IAElCJ,eAAe;QACbK,UAAU,CAAC,EAAEC,KAAK,EAAEC,IAAI,EAAEC,SAAS,EAAEC,GAAG,EAAE;YACxC,oBAAoB;YACpB,IAAIH,MAAMI,IAAI,KAAK,UAAUC,MAAMC,OAAO,CAACN,MAAMO,IAAI,GAAG;gBACtD,KAAK,MAAMC,OAAOR,MAAMO,IAAI,CAAE;oBAC5B,IAAI,UAAUC,OAAO,OAAOA,IAAIC,IAAI,KAAK,UAAU;wBACjD,qCAAqC;wBACrC,MAAMC,aACJR,aAAa,OAAO,AAACA,UAAiCS,IAAI,KAAK,WAC3D,AAACT,UAA+BS,IAAI,GACpC;wBACN,MAAMC,UAAUF,aAAa,GAAGA,WAAW,CAAC,EAAEF,IAAIC,IAAI,EAAE,GAAGD,IAAIC,IAAI;wBAEnE,kEAAkE;wBAClE,MAAMI,SAASV;wBACf,MAAMW,SAASD,MAAM,CAACL,IAAIC,IAAI,CAAC,IAAI,CAAC;wBACpCK,OAAOH,IAAI,GAAGC;wBACdE,OAAOC,WAAW,GAAG,
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/collectDisabledFieldPaths.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { traverseFields } from 'payload'\nimport { fieldAffectsData } from 'payload/shared'\n\n/**\n * Recursively traverses a Payload field schema to collect all field paths\n * that are explicitly disabled for the import/export plugin via:\n * field.custom['plugin-import-export'].disabled\n *\n * Handles nested fields including named tabs, groups, arrays, blocks, etc.\n * Tracks each field’s path by storing it in `ref.path` and manually propagating\n * it through named tab layers via a temporary `__manualRef` marker.\n *\n * @param fields - The top-level array of Payload field definitions\n * @returns An array of dot-notated field paths that are marked as disabled\n */\nexport const collectDisabledFieldPaths = (fields: Field[]): string[] => {\n const disabledPaths: string[] = []\n\n traverseFields({\n callback: ({ field, next, parentRef, ref }) => {\n // Handle named tabs\n if (field.type === 'tabs' && Array.isArray(field.tabs)) {\n for (const tab of field.tabs) {\n if ('name' in tab && typeof tab.name === 'string') {\n // Build the path prefix for this tab\n const parentPath =\n parentRef && typeof (parentRef as { path?: unknown }).path === 'string'\n ? (parentRef as { path: string }).path\n : ''\n const tabPath = parentPath ? `${parentPath}.${tab.name}` : tab.name\n\n // Prepare a ref for this named tab's children to inherit the path\n const refObj = ref as Record<string, any>\n const tabRef = refObj[tab.name] ?? {}\n tabRef.path = tabPath\n tabRef.__manualRef = true // flag this as a manually constructed parentRef\n refObj[tab.name] = tabRef\n }\n }\n\n // Skip further processing of the tab container itself\n return\n }\n\n // Skip unnamed fields (e.g. rows/collapsibles)\n if (!('name' in field) || typeof field.name !== 'string') {\n return\n }\n\n // Determine the path to the current field\n let parentPath: string | undefined\n\n if (\n parentRef &&\n typeof parentRef === 'object' &&\n 'path' in parentRef &&\n typeof (parentRef as { path?: unknown }).path === 'string'\n ) {\n parentPath = (parentRef as { path: string }).path\n } else if ((ref as any)?.__manualRef && typeof (ref as any)?.path === 'string') {\n // Fallback: if current ref is a manual tabRef, use its path\n parentPath = (ref as any).path\n }\n\n const fullPath = parentPath ? `${parentPath}.${field.name}` : field.name\n\n // Store current path for any nested children to use\n ;(ref as any).path = fullPath\n\n // If field is a data-affecting field and disabled via plugin config, collect its path\n if (fieldAffectsData(field) && field.custom?.['plugin-import-export']?.disabled) {\n disabledPaths.push(fullPath)\n return next?.()\n }\n },\n fields,\n })\n\n return disabledPaths\n}\n"],"names":["traverseFields","fieldAffectsData","collectDisabledFieldPaths","fields","disabledPaths","callback","field","next","parentRef","ref","type","Array","isArray","tabs","tab","name","parentPath","path","tabPath","refObj","tabRef","__manualRef","fullPath","custom","disabled","push"],"mappings":"AAEA,SAASA,cAAc,QAAQ,UAAS;AACxC,SAASC,gBAAgB,QAAQ,iBAAgB;AAEjD;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,4BAA4B,CAACC;IACxC,MAAMC,gBAA0B,EAAE;IAElCJ,eAAe;QACbK,UAAU,CAAC,EAAEC,KAAK,EAAEC,IAAI,EAAEC,SAAS,EAAEC,GAAG,EAAE;YACxC,oBAAoB;YACpB,IAAIH,MAAMI,IAAI,KAAK,UAAUC,MAAMC,OAAO,CAACN,MAAMO,IAAI,GAAG;gBACtD,KAAK,MAAMC,OAAOR,MAAMO,IAAI,CAAE;oBAC5B,IAAI,UAAUC,OAAO,OAAOA,IAAIC,IAAI,KAAK,UAAU;wBACjD,qCAAqC;wBACrC,MAAMC,aACJR,aAAa,OAAO,AAACA,UAAiCS,IAAI,KAAK,WAC3D,AAACT,UAA+BS,IAAI,GACpC;wBACN,MAAMC,UAAUF,aAAa,GAAGA,WAAW,CAAC,EAAEF,IAAIC,IAAI,EAAE,GAAGD,IAAIC,IAAI;wBAEnE,kEAAkE;wBAClE,MAAMI,SAASV;wBACf,MAAMW,SAASD,MAAM,CAACL,IAAIC,IAAI,CAAC,IAAI,CAAC;wBACpCK,OAAOH,IAAI,GAAGC;wBACdE,OAAOC,WAAW,GAAG,KAAK,gDAAgD;;wBAC1EF,MAAM,CAACL,IAAIC,IAAI,CAAC,GAAGK;oBACrB;gBACF;gBAEA,sDAAsD;gBACtD;YACF;YAEA,+CAA+C;YAC/C,IAAI,CAAE,CAAA,UAAUd,KAAI,KAAM,OAAOA,MAAMS,IAAI,KAAK,UAAU;gBACxD;YACF;YAEA,0CAA0C;YAC1C,IAAIC;YAEJ,IACER,aACA,OAAOA,cAAc,YACrB,UAAUA,aACV,OAAO,AAACA,UAAiCS,IAAI,KAAK,UAClD;gBACAD,aAAa,AAACR,UAA+BS,IAAI;YACnD,OAAO,IAAI,AAACR,KAAaY,eAAe,OAAQZ,KAAaQ,SAAS,UAAU;gBAC9E,4DAA4D;gBAC5DD,aAAa,AAACP,IAAYQ,IAAI;YAChC;YAEA,MAAMK,WAAWN,aAAa,GAAGA,WAAW,CAAC,EAAEV,MAAMS,IAAI,EAAE,GAAGT,MAAMS,IAAI;YAGtEN,IAAYQ,IAAI,GAAGK;YAErB,sFAAsF;YACtF,IAAIrB,iBAAiBK,UAAUA,MAAMiB,MAAM,EAAE,CAAC,uBAAuB,EAAEC,UAAU;gBAC/EpB,cAAcqB,IAAI,CAACH;gBACnB,OAAOf;YACT;QACF;QACAJ;IACF;IAEA,OAAOC;AACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-import-export",
|
|
3
|
-
"version": "3.68.0-internal
|
|
3
|
+
"version": "3.68.0-internal.35482da",
|
|
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/translations": "3.68.0-internal
|
|
68
|
-
"@payloadcms/ui": "3.68.0-internal
|
|
67
|
+
"@payloadcms/translations": "3.68.0-internal.35482da",
|
|
68
|
+
"@payloadcms/ui": "3.68.0-internal.35482da"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@payloadcms/eslint-config": "3.28.0",
|
|
72
|
-
"@payloadcms/ui": "3.68.0-internal
|
|
73
|
-
"payload": "3.68.0-internal
|
|
72
|
+
"@payloadcms/ui": "3.68.0-internal.35482da",
|
|
73
|
+
"payload": "3.68.0-internal.35482da"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"@payloadcms/ui": "3.68.0-internal
|
|
77
|
-
"payload": "3.68.0-internal
|
|
76
|
+
"@payloadcms/ui": "3.68.0-internal.35482da",
|
|
77
|
+
"payload": "3.68.0-internal.35482da"
|
|
78
78
|
},
|
|
79
79
|
"homepage:": "https://payloadcms.com",
|
|
80
80
|
"scripts": {
|