@payloadcms/plugin-import-export 4.0.0-internal.38b7f1d → 4.0.0-internal.4804abd
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/@types/assets.d.js +2 -0
- package/dist/@types/assets.d.js.map +1 -0
- package/dist/components/ExportPreview/index.css +55 -0
- package/dist/components/ExportPreview/index.d.ts +1 -1
- package/dist/components/ExportPreview/index.d.ts.map +1 -1
- package/dist/components/ExportPreview/index.js +1 -1
- package/dist/components/ExportPreview/index.js.map +1 -1
- package/dist/components/FieldsToExport/reduceFields.d.ts.map +1 -1
- package/dist/components/FormatField/index.d.ts.map +1 -1
- package/dist/components/FormatField/index.js +6 -3
- package/dist/components/FormatField/index.js.map +1 -1
- package/dist/components/ImportPreview/index.css +48 -0
- package/dist/components/ImportPreview/index.d.ts +1 -1
- package/dist/components/ImportPreview/index.d.ts.map +1 -1
- package/dist/components/ImportPreview/index.js +17 -3
- package/dist/components/ImportPreview/index.js.map +1 -1
- package/dist/components/Page/index.d.ts +1 -1
- package/dist/components/Page/index.d.ts.map +1 -1
- package/dist/components/Page/index.js +1 -1
- package/dist/components/Page/index.js.map +1 -1
- package/dist/components/SortBy/index.css +9 -0
- package/dist/components/SortBy/index.d.ts +1 -1
- package/dist/components/SortBy/index.d.ts.map +1 -1
- package/dist/components/SortBy/index.js +1 -2
- package/dist/components/SortBy/index.js.map +1 -1
- package/dist/components/SortOrder/index.css +9 -0
- package/dist/components/SortOrder/index.d.ts +1 -1
- package/dist/components/SortOrder/index.d.ts.map +1 -1
- package/dist/components/SortOrder/index.js +1 -2
- package/dist/components/SortOrder/index.js.map +1 -1
- package/dist/export/createExport.d.ts.map +1 -1
- package/dist/export/getCreateExportCollectionTask.d.ts.map +1 -1
- package/dist/export/getExportCollection.d.ts.map +1 -1
- package/dist/export/getFields.d.ts.map +1 -1
- package/dist/export/handleDownload.d.ts.map +1 -1
- package/dist/export/handlePreview.d.ts.map +1 -1
- package/dist/export/handlePreview.js +1 -1
- package/dist/export/handlePreview.js.map +1 -1
- package/dist/exports/types.d.ts +1 -1
- package/dist/exports/types.d.ts.map +1 -1
- package/dist/exports/types.js.map +1 -1
- package/dist/import/createImport.d.ts.map +1 -1
- package/dist/import/createImport.js +1 -1
- package/dist/import/createImport.js.map +1 -1
- package/dist/import/getCreateImportCollectionTask.d.ts.map +1 -1
- package/dist/import/getFields.d.ts.map +1 -1
- package/dist/import/getImportCollection.d.ts.map +1 -1
- package/dist/import/handlePreview.d.ts.map +1 -1
- package/dist/index.d.ts +1 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -5
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +0 -32
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/applyFieldHooks.d.ts +1 -2
- package/dist/utilities/applyFieldHooks.d.ts.map +1 -1
- package/dist/utilities/applyFieldHooks.js +2 -3
- package/dist/utilities/applyFieldHooks.js.map +1 -1
- package/dist/utilities/buildDisabledFieldRegex.d.ts.map +1 -1
- package/dist/utilities/collectDisabledFieldPaths.d.ts.map +1 -1
- package/dist/utilities/fieldToRegex.d.ts.map +1 -1
- package/dist/utilities/flattenObject.d.ts.map +1 -1
- package/dist/utilities/flattenObject.js +3 -13
- package/dist/utilities/flattenObject.js.map +1 -1
- package/dist/utilities/flattenedFields.d.ts.map +1 -1
- package/dist/utilities/flattenedFields.js +3 -0
- package/dist/utilities/flattenedFields.js.map +1 -1
- package/dist/utilities/getExportFieldFunctions.d.ts.map +1 -1
- package/dist/utilities/getExportFieldFunctions.js +0 -8
- package/dist/utilities/getExportFieldFunctions.js.map +1 -1
- package/dist/utilities/getFileFromDoc.d.ts.map +1 -1
- package/dist/utilities/getFlattenedFieldKeys.d.ts.map +1 -1
- package/dist/utilities/getImportFieldFunctions.d.ts.map +1 -1
- package/dist/utilities/getImportFieldFunctions.js +0 -8
- package/dist/utilities/getImportFieldFunctions.js.map +1 -1
- package/dist/utilities/getPluginCollections.d.ts.map +1 -1
- package/dist/utilities/getSchemaColumns.d.ts +1 -1
- package/dist/utilities/getSchemaColumns.d.ts.map +1 -1
- package/dist/utilities/getSchemaColumns.js +2 -2
- package/dist/utilities/getSchemaColumns.js.map +1 -1
- package/dist/utilities/getSelect.d.ts.map +1 -1
- package/dist/utilities/isPlainObject.d.ts.map +1 -1
- package/dist/utilities/parseCSV.d.ts.map +1 -1
- package/dist/utilities/parseJSON.d.ts.map +1 -1
- package/dist/utilities/polymorphicRel.d.ts.map +1 -1
- package/dist/utilities/processRichTextField.d.ts.map +1 -1
- package/dist/utilities/processRichTextField.js +7 -0
- package/dist/utilities/processRichTextField.js.map +1 -1
- package/dist/utilities/processRichTextField.spec.js +308 -0
- package/dist/utilities/processRichTextField.spec.js.map +1 -0
- package/dist/utilities/removeDisabledFields.d.ts.map +1 -1
- package/dist/utilities/setNestedValue.d.ts.map +1 -1
- package/dist/utilities/sortHelpers.d.ts.map +1 -1
- package/dist/utilities/unflattenObject.d.ts.map +1 -1
- package/dist/utilities/unflattenObject.js +29 -18
- package/dist/utilities/unflattenObject.js.map +1 -1
- package/dist/utilities/unflattenObject.spec.js +106 -0
- package/dist/utilities/unflattenObject.spec.js.map +1 -1
- package/dist/utilities/unflattenPostProcess.d.ts.map +1 -1
- package/dist/utilities/unflattenPostProcess.js +39 -13
- package/dist/utilities/unflattenPostProcess.js.map +1 -1
- package/dist/utilities/validateLimitValue.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/components/ExportPreview/index.scss +0 -48
- package/dist/components/FieldsToExport/index.scss +0 -0
- package/dist/components/ImportPreview/index.scss +0 -41
- package/dist/components/SortBy/index.scss +0 -3
- package/dist/components/SortOrder/index.scss +0 -3
- package/dist/utilities/legacyHookDispatch.spec.js +0 -227
- package/dist/utilities/legacyHookDispatch.spec.js.map +0 -1
- /package/dist/components/Page/{index.scss → index.css} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SortBy/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAgBzD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SortBy/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAgBzD,OAAO,aAAa,CAAA;AAIpB,eAAO,MAAM,MAAM,EAAE,0BAoHpB,CAAA"}
|
|
@@ -5,7 +5,7 @@ import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
|
5
5
|
import { applySortOrder, normalizeQueryParam, stripSortDash } from '../../utilities/sortHelpers.js';
|
|
6
6
|
import { reduceFields } from '../FieldsToExport/reduceFields.js';
|
|
7
7
|
import { useImportExport } from '../ImportExportProvider/index.js';
|
|
8
|
-
import './index.
|
|
8
|
+
import './index.css';
|
|
9
9
|
const baseClass = 'sort-by-fields';
|
|
10
10
|
export const SortBy = (props)=>{
|
|
11
11
|
const { id } = useDocumentInfo();
|
|
@@ -115,7 +115,6 @@ export const SortBy = (props)=>{
|
|
|
115
115
|
path: props.path
|
|
116
116
|
}),
|
|
117
117
|
/*#__PURE__*/ _jsx(ReactSelect, {
|
|
118
|
-
className: baseClass,
|
|
119
118
|
disabled: props.readOnly,
|
|
120
119
|
getOptionValue: (option)=>String(option.value),
|
|
121
120
|
inputId: `field-${props.path.replace(/\./g, '__')}`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/SortBy/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, useMemo, useRef, useState } from 'react'\n\nimport { applySortOrder, normalizeQueryParam, stripSortDash } from '../../utilities/sortHelpers.js'\nimport { reduceFields } from '../FieldsToExport/reduceFields.js'\nimport { useImportExport } from '../ImportExportProvider/index.js'\nimport './index.
|
|
1
|
+
{"version":3,"sources":["../../../src/components/SortBy/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, useMemo, useRef, useState } from 'react'\n\nimport { applySortOrder, normalizeQueryParam, stripSortDash } from '../../utilities/sortHelpers.js'\nimport { reduceFields } from '../FieldsToExport/reduceFields.js'\nimport { useImportExport } from '../ImportExportProvider/index.js'\nimport './index.css'\n\nconst baseClass = 'sort-by-fields'\n\nexport const SortBy: SelectFieldClientComponent = (props) => {\n const { id } = useDocumentInfo()\n\n // The \"sort\" text field that stores 'title' or '-title'\n const { setValue: setSort, value: sortRaw } = useField<string>()\n\n // Sibling order field ('asc' | 'desc') used when writing sort on change\n const { value: sortOrder = 'asc' } = useField<string>({ path: 'sortOrder' })\n // Needed so we can initialize sortOrder when SortOrder component is hidden\n const { setValue: setSortOrder } = useField<'asc' | 'desc'>({ path: 'sortOrder' })\n\n const { value: collectionSlug } = useField<string>({ path: 'collectionSlug' })\n const { query } = useListQuery()\n const { getEntityConfig } = useConfig()\n const { collection } = useImportExport()\n\n // ReactSelect's displayed option\n const [displayedValue, setDisplayedValue] = useState<{\n id: string\n label: ReactNode\n value: string\n } | null>(null)\n\n const collectionConfig = getEntityConfig({ collectionSlug: collectionSlug ?? collection })\n const fieldOptions = useMemo(\n () => reduceFields({ excludeUnsortable: true, fields: collectionConfig?.fields }),\n [collectionConfig?.fields],\n )\n\n // Normalize the stored value for display (strip the '-') and pick the option\n useEffect(() => {\n const clean = stripSortDash(sortRaw)\n if (!clean) {\n setDisplayedValue(null)\n return\n }\n\n const option = fieldOptions.find((f) => f.value === clean)\n if (option && (!displayedValue || displayedValue.value !== clean)) {\n setDisplayedValue(option)\n }\n }, [sortRaw, fieldOptions, displayedValue])\n\n // One-time init guard so clearing `sort` doesn't rehydrate from query again\n const didInitRef = useRef(false)\n\n // Sync the visible select from list-view query sort (preferred) or groupBy (fallback)\n // and initialize both `sort` and `sortOrder` here as SortOrder may be hidden by admin.condition.\n useEffect(() => {\n if (didInitRef.current) {\n return\n }\n if (id) {\n didInitRef.current = true\n return\n }\n if (typeof sortRaw === 'string' && sortRaw.length > 0) {\n // Already initialized elsewhere\n didInitRef.current = true\n return\n }\n\n const qsSort = normalizeQueryParam(query?.sort)\n const qsGroupBy = normalizeQueryParam(query?.groupBy)\n\n const source = qsSort ?? qsGroupBy\n if (!source) {\n didInitRef.current = true\n return\n }\n\n const isDesc = !!qsSort && qsSort.startsWith('-')\n const base = stripSortDash(source)\n const order: 'asc' | 'desc' = isDesc ? 'desc' : 'asc'\n\n // Write BOTH fields so preview/export have the right values even if SortOrder is hidden\n setSort(applySortOrder(base, order))\n setSortOrder(order)\n\n const option = fieldOptions.find((f) => f.value === base)\n if (option) {\n setDisplayedValue(option)\n }\n\n didInitRef.current = true\n }, [id, query?.groupBy, query?.sort, sortRaw, fieldOptions, setSort, setSortOrder])\n\n // When user selects a different field, store it with the current order applied\n const onChange = (option: { id: string; label: ReactNode; value: string } | null) => {\n if (!option) {\n setSort('')\n setDisplayedValue(null)\n } else {\n setDisplayedValue(option)\n const next = applySortOrder(option.value, String(sortOrder) as 'asc' | 'desc')\n setSort(next)\n }\n }\n\n return (\n <div className={baseClass}>\n <FieldLabel label={props.field.label} path={props.path} />\n <ReactSelect\n disabled={props.readOnly}\n getOptionValue={(option) => String(option.value)}\n inputId={`field-${props.path.replace(/\\./g, '__')}`}\n isClearable={true}\n isSortable={true}\n // @ts-expect-error react select option\n onChange={onChange}\n options={fieldOptions}\n // @ts-expect-error react select\n value={displayedValue}\n />\n </div>\n )\n}\n"],"names":["FieldLabel","ReactSelect","useConfig","useDocumentInfo","useField","useListQuery","React","useEffect","useMemo","useRef","useState","applySortOrder","normalizeQueryParam","stripSortDash","reduceFields","useImportExport","baseClass","SortBy","props","id","setValue","setSort","value","sortRaw","sortOrder","path","setSortOrder","collectionSlug","query","getEntityConfig","collection","displayedValue","setDisplayedValue","collectionConfig","fieldOptions","excludeUnsortable","fields","clean","option","find","f","didInitRef","current","length","qsSort","sort","qsGroupBy","groupBy","source","isDesc","startsWith","base","order","onChange","next","String","div","className","label","field","disabled","readOnly","getOptionValue","inputId","replace","isClearable","isSortable","options"],"mappings":"AAAA;;AAKA,SACEA,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,YAAY,QACP,iBAAgB;AACvB,OAAOC,SAASC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAEnE,SAASC,cAAc,EAAEC,mBAAmB,EAAEC,aAAa,QAAQ,iCAAgC;AACnG,SAASC,YAAY,QAAQ,oCAAmC;AAChE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,OAAO,cAAa;AAEpB,MAAMC,YAAY;AAElB,OAAO,MAAMC,SAAqC,CAACC;IACjD,MAAM,EAAEC,EAAE,EAAE,GAAGhB;IAEf,wDAAwD;IACxD,MAAM,EAAEiB,UAAUC,OAAO,EAAEC,OAAOC,OAAO,EAAE,GAAGnB;IAE9C,wEAAwE;IACxE,MAAM,EAAEkB,OAAOE,YAAY,KAAK,EAAE,GAAGpB,SAAiB;QAAEqB,MAAM;IAAY;IAC1E,2EAA2E;IAC3E,MAAM,EAAEL,UAAUM,YAAY,EAAE,GAAGtB,SAAyB;QAAEqB,MAAM;IAAY;IAEhF,MAAM,EAAEH,OAAOK,cAAc,EAAE,GAAGvB,SAAiB;QAAEqB,MAAM;IAAiB;IAC5E,MAAM,EAAEG,KAAK,EAAE,GAAGvB;IAClB,MAAM,EAAEwB,eAAe,EAAE,GAAG3B;IAC5B,MAAM,EAAE4B,UAAU,EAAE,GAAGf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AAMd,SAASJ,aAAaK,IAAI,CAAC,CAACC,IAAMA,EAAElB,KAAK,KAAK6B;QACpD,IAAIb,QAAQ;YACVN,kBAAkBM;QACpB;QAEAG,WAAWC,OAAO,GAAG;IACvB,GAAG;QAACvB;QAAIS,OAAOmB;QAASnB,OAAOiB;QAAMtB;QAASW;QAAcb;QAASK;KAAa;IAElF,+EAA+E;IAC/E,MAAM2B,WAAW,CAACf;QAChB,IAAI,CAACA,QAAQ;YACXjB,QAAQ;YACRW,kBAAkB;QACpB,OAAO;YACLA,kBAAkBM;YAClB,MAAMgB,OAAO3C,eAAe2B,OAAOhB,KAAK,EAAEiC,OAAO/B;YACjDH,QAAQiC;QACV;IACF;IAEA,qBACE,MAACE;QAAIC,WAAWzC;;0BACd,KAAChB;gBAAW0D,OAAOxC,MAAMyC,KAAK,CAACD,KAAK;gBAAEjC,MAAMP,MAAMO,IAAI;;0BACtD,KAACxB;gBACC2D,UAAU1C,MAAM2C,QAAQ;gBACxBC,gBAAgB,CAACxB,SAAWiB,OAAOjB,OAAOhB,KAAK;gBAC/CyC,SAAS,CAAC,MAAM,EAAE7C,MAAMO,IAAI,CAACuC,OAAO,CAAC,OAAO,OAAO;gBACnDC,aAAa;gBACbC,YAAY;gBACZ,uCAAuC;gBACvCb,UAAUA;gBACVc,SAASjC;gBACT,gCAAgC;gBAChCZ,OAAOS;;;;AAIf,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SortOrder/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAMzD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SortOrder/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAMzD,OAAO,aAAa,CAAA;AAcpB,eAAO,MAAM,SAAS,EAAE,0BAsGvB,CAAA"}
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { FieldLabel, ReactSelect, useDocumentInfo, useField, useListQuery } from '@payloadcms/ui';
|
|
4
4
|
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import { applySortOrder, normalizeQueryParam, stripSortDash } from '../../utilities/sortHelpers.js';
|
|
6
|
-
import './index.
|
|
6
|
+
import './index.css';
|
|
7
7
|
const baseClass = 'sort-order-field';
|
|
8
8
|
const options = [
|
|
9
9
|
{
|
|
@@ -103,7 +103,6 @@ export const SortOrder = (props)=>{
|
|
|
103
103
|
path: props.path
|
|
104
104
|
}),
|
|
105
105
|
/*#__PURE__*/ _jsx(ReactSelect, {
|
|
106
|
-
className: baseClass,
|
|
107
106
|
disabled: props.readOnly,
|
|
108
107
|
inputId: `field-${props.path.replace(/\./g, '__')}`,
|
|
109
108
|
isClearable: false,
|
|
@@ -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.
|
|
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.css'\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 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,OAAO,cAAa;AAEpB,MAAMC,YAAY;AAKlB,MAAMC,UAAU;IACd;QAAEC,OAAO;QAAaC,OAAO;IAAe;IAC5C;QAAED,OAAO;QAAcC,OAAO;IAAgB;CAC/C;AAED,MAAMC,gBAA6BH,OAAO,CAAC,EAAE;AAE7C,OAAO,MAA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AM,GAAG,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,MAAM,CAAA;AAEV,eAAO,MAAM,YAAY,GAAU,MAAM,gBAAgB,kCAgmBxD,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCreateExportCollectionTask.d.ts","sourceRoot":"","sources":["../../src/export/getCreateExportCollectionTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAS,UAAU,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAI/C;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;CACvB,GAAG,MAAM,CAAA;AAmGV,eAAO,MAAM,6BAA6B,
|
|
1
|
+
{"version":3,"file":"getCreateExportCollectionTask.d.ts","sourceRoot":"","sources":["../../src/export/getCreateExportCollectionTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAS,UAAU,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAI/C;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;CACvB,GAAG,MAAM,CAAA;AAmGV,eAAO,MAAM,6BAA6B,GACxC,QAAQ,MAAM,KACb,UAAU,CAAC;IACZ,KAAK,EAAE,cAAc,CAAA;IACrB,MAAM,EAAE,MAAM,CAAA;CACf,CAuBA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getExportCollection.d.ts","sourceRoot":"","sources":["../../src/export/getExportCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,MAAM,EACP,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB,EAAS,MAAM,aAAa,CAAA;AAWhF,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"getExportCollection.d.ts","sourceRoot":"","sources":["../../src/export/getExportCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,MAAM,EACP,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB,EAAS,MAAM,aAAa,CAAA;AAWhF,eAAO,MAAM,mBAAmB,GAAI,0DAKjC;IACD;;OAEG;IACH,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,gBA8JH,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFields.d.ts","sourceRoot":"","sources":["../../src/export/getFields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAA+B,MAAM,SAAS,CAAA;AAKzE,KAAK,gBAAgB,GAAG;IACtB;;;OAGG;IACH,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"getFields.d.ts","sourceRoot":"","sources":["../../src/export/getFields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAA+B,MAAM,SAAS,CAAA;AAKzE,KAAK,gBAAgB,GAAG;IACtB;;;OAGG;IACH,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,SAAS,gBAAgB,KAAG,KAAK,EA6Q1D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleDownload.d.ts","sourceRoot":"","sources":["../../src/export/handleDownload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAO7C,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"handleDownload.d.ts","sourceRoot":"","sources":["../../src/export/handleDownload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAO7C,eAAO,MAAM,cAAc,GAAU,KAAK,cAAc,EAAE,eAAa,sBA2DtE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlePreview.d.ts","sourceRoot":"","sources":["../../src/export/handlePreview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,SAAS,CAAA;AA2C1D,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"handlePreview.d.ts","sourceRoot":"","sources":["../../src/export/handlePreview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,SAAS,CAAA;AA2C1D,eAAO,MAAM,aAAa,GAAU,KAAK,cAAc,KAAG,OAAO,CAAC,QAAQ,CAuQzE,CAAA"}
|
|
@@ -145,7 +145,7 @@ export const handlePreview = async (req)=>{
|
|
|
145
145
|
const possibleKeys = getFlattenedFieldKeys(targetCollection.config.flattenedFields, '', {
|
|
146
146
|
localeCodes
|
|
147
147
|
});
|
|
148
|
-
// Flatten docs without padding yet. This preserves the exact keys produced by
|
|
148
|
+
// Flatten docs without padding yet. This preserves the exact keys produced by beforeExport hooks,
|
|
149
149
|
// allowing mergeColumns to detect which schema columns were replaced with derived ones.
|
|
150
150
|
transformed = docs.map((doc)=>flattenObject({
|
|
151
151
|
data: doc,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/handlePreview.ts"],"sourcesContent":["import type { PayloadRequest, Sort, Where } from 'payload'\n\nimport { addDataAndFileToRequest } from 'payload'\nimport { getObjectDotNotation } from 'payload/shared'\n\nimport type { ExportBeforeHook, ExportPreviewResponse } from '../types.js'\n\nimport {\n DEFAULT_PREVIEW_LIMIT,\n MAX_PREVIEW_LIMIT,\n MIN_PREVIEW_LIMIT,\n MIN_PREVIEW_PAGE,\n} from '../constants.js'\nimport { applyFieldHooks } from '../utilities/applyFieldHooks.js'\nimport { flattenObject } from '../utilities/flattenObject.js'\nimport { getExportFieldFunctions } from '../utilities/getExportFieldFunctions.js'\nimport { getFlattenedFieldKeys } from '../utilities/getFlattenedFieldKeys.js'\nimport { getSchemaColumns, mergeColumns } from '../utilities/getSchemaColumns.js'\nimport { getSelect } from '../utilities/getSelect.js'\nimport { removeDisabledFields } from '../utilities/removeDisabledFields.js'\nimport { resolveLimit } from '../utilities/resolveLimit.js'\nimport { setNestedValue } from '../utilities/setNestedValue.js'\n\nconst applyExportBeforeHook = async (\n hook: ExportBeforeHook | undefined,\n data: Record<string, unknown>[],\n originalDocs: unknown[],\n format: 'csv' | 'json' | ({} & string),\n req: PayloadRequest,\n): Promise<Record<string, unknown>[]> => {\n if (!hook || data.length === 0) {\n return data\n }\n return hook({\n batchNumber: 1,\n data,\n format,\n originalData: originalDocs as Record<string, unknown>[],\n req,\n totalBatches: 1,\n })\n}\n\nexport const handlePreview = async (req: PayloadRequest): Promise<Response> => {\n await addDataAndFileToRequest(req)\n\n const {\n collectionSlug,\n draft: draftFromReq,\n fields,\n limit: exportLimit,\n locale,\n previewLimit: rawPreviewLimit = DEFAULT_PREVIEW_LIMIT,\n previewPage: rawPreviewPage = 1,\n sort,\n where: whereFromReq = {},\n } = req.data as {\n collectionSlug: string\n draft?: 'no' | 'yes'\n fields?: string[]\n format?: 'csv' | 'json'\n limit?: number\n locale?: string\n previewLimit?: number\n previewPage?: number\n sort?: Sort\n where?: Where\n }\n\n // Validate and clamp pagination values to safe bounds\n const previewLimit = Math.max(MIN_PREVIEW_LIMIT, Math.min(rawPreviewLimit, MAX_PREVIEW_LIMIT))\n const previewPage = Math.max(MIN_PREVIEW_PAGE, rawPreviewPage)\n\n const targetCollection = req.payload.collections[collectionSlug]\n if (!targetCollection) {\n return Response.json(\n { error: `Collection with slug ${collectionSlug} not found` },\n { status: 400 },\n )\n }\n\n const pluginConfig = targetCollection.config.custom?.['plugin-import-export']\n const maxLimit = await resolveLimit({\n limit: pluginConfig?.exportLimit,\n req,\n })\n\n const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined\n const draft = draftFromReq === 'yes'\n const collectionHasVersions = Boolean(targetCollection.config.versions)\n\n // Only filter by _status for versioned collections\n const publishedWhere: Where = collectionHasVersions ? { _status: { equals: 'published' } } : {}\n\n const where: Where = {\n and: [whereFromReq, draft ? {} : publishedWhere],\n }\n\n // Count total docs matching export criteria\n const countResult = await req.payload.count({\n collection: collectionSlug,\n overrideAccess: false,\n req,\n where,\n })\n\n const totalMatchingDocs = countResult.totalDocs\n\n // Calculate actual export count (respecting both export limit and max limit)\n let effectiveLimit = totalMatchingDocs\n\n // Apply user's export limit if provided\n if (exportLimit && exportLimit > 0) {\n effectiveLimit = Math.min(effectiveLimit, exportLimit)\n }\n\n // Apply max limit if configured\n if (typeof maxLimit === 'number' && maxLimit > 0) {\n effectiveLimit = Math.min(effectiveLimit, maxLimit)\n }\n\n const exportTotalDocs = effectiveLimit\n\n // Calculate preview pagination that respects export limit\n // Preview should only show docs that will actually be exported\n const previewStartIndex = (previewPage - 1) * previewLimit\n\n // Calculate pagination info based on export limit (not raw DB results)\n const previewTotalPages = exportTotalDocs === 0 ? 0 : Math.ceil(exportTotalDocs / previewLimit)\n\n const isCSV = req?.data?.format === 'csv'\n\n // Get locale codes for locale expansion when locale='all'\n const localeCodes =\n locale === 'all' && req.payload.config.localization\n ? req.payload.config.localization.localeCodes\n : undefined\n\n // Get disabled fields configuration\n const disabledFields =\n targetCollection.config.admin?.custom?.['plugin-import-export']?.disabledFields ?? []\n\n // Compute schema-based columns for CSV (provides base ordering and handles empty exports)\n const schemaColumns = isCSV\n ? getSchemaColumns({\n collectionConfig: targetCollection.config,\n disabledFields,\n fields,\n locale: locale ?? undefined,\n localeCodes,\n })\n : undefined\n\n // columns will be finalized after data is available (merged with data-discovered columns)\n let columns = schemaColumns\n\n // If we're beyond the effective limit (considering both user limit and maxLimit), return empty docs\n if (exportTotalDocs > 0 && previewStartIndex >= exportTotalDocs) {\n const response: ExportPreviewResponse = {\n columns,\n docs: [],\n exportTotalDocs,\n hasNextPage: false,\n hasPrevPage: previewPage > 1,\n limit: previewLimit,\n maxLimit,\n page: previewPage,\n totalDocs: exportTotalDocs,\n totalPages: previewTotalPages,\n }\n return Response.json(response)\n }\n\n // Fetch preview page with full previewLimit to maintain consistent pagination offsets\n // We'll trim the results afterwards if needed to respect export limit\n const result = await req.payload.find({\n collection: collectionSlug,\n depth: 1,\n draft,\n limit: previewLimit,\n locale,\n overrideAccess: false,\n page: previewPage,\n req,\n select,\n sort,\n where,\n })\n\n // Trim docs to respect effective limit boundary (user limit clamped by maxLimit)\n let docs = result.docs\n if (exportTotalDocs > 0) {\n const remainingInExport = exportTotalDocs - previewStartIndex\n if (remainingInExport < docs.length) {\n docs = docs.slice(0, remainingInExport)\n }\n }\n\n // Transform docs based on format\n let transformed: Record<string, unknown>[]\n\n const exportFieldHooks = getExportFieldFunctions({\n fields: targetCollection.config.flattenedFields,\n })\n\n const exportHooks = targetCollection.config.custom?.['plugin-import-export']?.exportHooks\n\n if (isCSV) {\n const possibleKeys = getFlattenedFieldKeys(targetCollection.config.flattenedFields, '', {\n localeCodes,\n })\n\n // Flatten docs without padding yet. This preserves the exact keys produced by toCSV hooks,\n // allowing mergeColumns to detect which schema columns were replaced with derived ones.\n transformed = docs.map((doc) =>\n flattenObject({\n data: doc,\n exportFieldHooks,\n fields,\n format: 'csv',\n req,\n }),\n )\n\n transformed = await applyExportBeforeHook(exportHooks?.before, transformed, docs, 'csv', req)\n\n if (schemaColumns && transformed.length > 0) {\n const dataColumns: string[] = []\n const seenCols = new Set<string>()\n for (const row of transformed) {\n for (const key of Object.keys(row)) {\n if (!seenCols.has(key)) {\n seenCols.add(key)\n dataColumns.push(key)\n }\n }\n }\n const mergedColumns = mergeColumns(schemaColumns, dataColumns)\n columns =\n Boolean(exportHooks?.before) && transformed.length > 0\n ? mergedColumns.filter((col) => dataColumns.includes(col))\n : mergedColumns\n }\n\n // Pad rows with null for missing columns (uses merged columns, not raw schema)\n if (!fields || fields.length === 0) {\n const paddingKeys = columns ?? possibleKeys\n for (const row of transformed) {\n for (const key of paddingKeys) {\n if (!(key in row)) {\n row[key] = null\n }\n }\n }\n }\n } else {\n transformed = docs.map((doc) => {\n // Apply field-level export hooks for JSON format\n let output: Record<string, unknown> = applyFieldHooks({\n type: 'beforeExport',\n data: doc as Record<string, unknown>,\n fieldHooks: exportFieldHooks,\n fields: targetCollection.config.flattenedFields,\n format: 'json',\n operation: 'export',\n req,\n })\n\n // Remove disabled fields\n output = removeDisabledFields(output, disabledFields)\n\n // Then trim to selected fields only (if fields are provided)\n if (Array.isArray(fields) && fields.length > 0) {\n const trimmed: Record<string, unknown> = {}\n\n for (const key of fields) {\n const value = getObjectDotNotation(output, key)\n setNestedValue(trimmed, key, value ?? null)\n }\n\n output = trimmed\n }\n\n return output\n })\n\n transformed = await applyExportBeforeHook(exportHooks?.before, transformed, docs, 'json', req)\n }\n\n const hasNextPage = previewPage < previewTotalPages\n const hasPrevPage = previewPage > 1\n\n const response: ExportPreviewResponse = {\n columns,\n docs: transformed,\n exportTotalDocs,\n hasNextPage,\n hasPrevPage,\n limit: previewLimit,\n maxLimit,\n page: previewPage,\n totalDocs: exportTotalDocs,\n totalPages: previewTotalPages,\n }\n\n return Response.json(response)\n}\n"],"names":["addDataAndFileToRequest","getObjectDotNotation","DEFAULT_PREVIEW_LIMIT","MAX_PREVIEW_LIMIT","MIN_PREVIEW_LIMIT","MIN_PREVIEW_PAGE","applyFieldHooks","flattenObject","getExportFieldFunctions","getFlattenedFieldKeys","getSchemaColumns","mergeColumns","getSelect","removeDisabledFields","resolveLimit","setNestedValue","applyExportBeforeHook","hook","data","originalDocs","format","req","length","batchNumber","originalData","totalBatches","handlePreview","collectionSlug","draft","draftFromReq","fields","limit","exportLimit","locale","previewLimit","rawPreviewLimit","previewPage","rawPreviewPage","sort","where","whereFromReq","Math","max","min","targetCollection","payload","collections","Response","json","error","status","pluginConfig","config","custom","maxLimit","select","Array","isArray","undefined","collectionHasVersions","Boolean","versions","publishedWhere","_status","equals","and","countResult","count","collection","overrideAccess","totalMatchingDocs","totalDocs","effectiveLimit","exportTotalDocs","previewStartIndex","previewTotalPages","ceil","isCSV","localeCodes","localization","disabledFields","admin","schemaColumns","collectionConfig","columns","response","docs","hasNextPage","hasPrevPage","page","totalPages","result","find","depth","remainingInExport","slice","transformed","exportFieldHooks","flattenedFields","exportHooks","possibleKeys","map","doc","before","dataColumns","seenCols","Set","row","key","Object","keys","has","add","push","mergedColumns","filter","col","includes","paddingKeys","output","type","fieldHooks","operation","trimmed","value"],"mappings":"AAEA,SAASA,uBAAuB,QAAQ,UAAS;AACj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,OAAO;QACLZ,cAAcV,KAAKe,GAAG,CAAC,CAACC;YACtB,iDAAiD;YACjD,IAAIiB,SAAkCjH,gBAAgB;gBACpDkH,MAAM;gBACNtG,MAAMoF;gBACNmB,YAAYxB;gBACZnE,QAAQc,iBAAiBQ,MAAM,CAAC8C,eAAe;gBAC/C9E,QAAQ;gBACRsG,WAAW;gBACXrG;YACF;YAEA,yBAAyB;YACzBkG,SAAS1G,qBAAqB0G,QAAQvC;YAEtC,6DAA6D;YAC7D,IAAIxB,MAAMC,OAAO,CAAC3B,WAAWA,OAAOR,MAAM,GAAG,GAAG;gBAC9C,MAAMqG,UAAmC,CAAC;gBAE1C,KAAK,MAAMf,OAAO9E,OAAQ;oBACxB,MAAM8F,QAAQ3H,qBAAqBsH,QAAQX;oBAC3C7F,eAAe4G,SAASf,KAAKgB,SAAS;gBACxC;gBAEAL,SAASI;YACX;YAEA,OAAOJ;QACT;QAEAvB,cAAc,MAAMhF,sBAAsBmF,aAAaI,QAAQP,aAAaV,MAAM,QAAQjE;IAC5F;IAEA,MAAMkE,cAAcnD,cAAcuC;IAClC,MAAMa,cAAcpD,cAAc;IAElC,MAAMiD,WAAkC;QACtCD;QACAE,MAAMU;QACNvB;QACAc;QACAC;QACAzD,OAAOG;QACPoB;QACAmC,MAAMrD;QACNmC,WAAWE;QACXiB,YAAYf;IACd;IAEA,OAAO5B,SAASC,IAAI,CAACqC;AACvB,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/export/handlePreview.ts"],"sourcesContent":["import type { PayloadRequest, Sort, Where } from 'payload'\n\nimport { addDataAndFileToRequest } from 'payload'\nimport { getObjectDotNotation } from 'payload/shared'\n\nimport type { ExportBeforeHook, ExportPreviewResponse } from '../types.js'\n\nimport {\n DEFAULT_PREVIEW_LIMIT,\n MAX_PREVIEW_LIMIT,\n MIN_PREVIEW_LIMIT,\n MIN_PREVIEW_PAGE,\n} from '../constants.js'\nimport { applyFieldHooks } from '../utilities/applyFieldHooks.js'\nimport { flattenObject } from '../utilities/flattenObject.js'\nimport { getExportFieldFunctions } from '../utilities/getExportFieldFunctions.js'\nimport { getFlattenedFieldKeys } from '../utilities/getFlattenedFieldKeys.js'\nimport { getSchemaColumns, mergeColumns } from '../utilities/getSchemaColumns.js'\nimport { getSelect } from '../utilities/getSelect.js'\nimport { removeDisabledFields } from '../utilities/removeDisabledFields.js'\nimport { resolveLimit } from '../utilities/resolveLimit.js'\nimport { setNestedValue } from '../utilities/setNestedValue.js'\n\nconst applyExportBeforeHook = async (\n hook: ExportBeforeHook | undefined,\n data: Record<string, unknown>[],\n originalDocs: unknown[],\n format: 'csv' | 'json' | ({} & string),\n req: PayloadRequest,\n): Promise<Record<string, unknown>[]> => {\n if (!hook || data.length === 0) {\n return data\n }\n return hook({\n batchNumber: 1,\n data,\n format,\n originalData: originalDocs as Record<string, unknown>[],\n req,\n totalBatches: 1,\n })\n}\n\nexport const handlePreview = async (req: PayloadRequest): Promise<Response> => {\n await addDataAndFileToRequest(req)\n\n const {\n collectionSlug,\n draft: draftFromReq,\n fields,\n limit: exportLimit,\n locale,\n previewLimit: rawPreviewLimit = DEFAULT_PREVIEW_LIMIT,\n previewPage: rawPreviewPage = 1,\n sort,\n where: whereFromReq = {},\n } = req.data as {\n collectionSlug: string\n draft?: 'no' | 'yes'\n fields?: string[]\n format?: 'csv' | 'json'\n limit?: number\n locale?: string\n previewLimit?: number\n previewPage?: number\n sort?: Sort\n where?: Where\n }\n\n // Validate and clamp pagination values to safe bounds\n const previewLimit = Math.max(MIN_PREVIEW_LIMIT, Math.min(rawPreviewLimit, MAX_PREVIEW_LIMIT))\n const previewPage = Math.max(MIN_PREVIEW_PAGE, rawPreviewPage)\n\n const targetCollection = req.payload.collections[collectionSlug]\n if (!targetCollection) {\n return Response.json(\n { error: `Collection with slug ${collectionSlug} not found` },\n { status: 400 },\n )\n }\n\n const pluginConfig = targetCollection.config.custom?.['plugin-import-export']\n const maxLimit = await resolveLimit({\n limit: pluginConfig?.exportLimit,\n req,\n })\n\n const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined\n const draft = draftFromReq === 'yes'\n const collectionHasVersions = Boolean(targetCollection.config.versions)\n\n // Only filter by _status for versioned collections\n const publishedWhere: Where = collectionHasVersions ? { _status: { equals: 'published' } } : {}\n\n const where: Where = {\n and: [whereFromReq, draft ? {} : publishedWhere],\n }\n\n // Count total docs matching export criteria\n const countResult = await req.payload.count({\n collection: collectionSlug,\n overrideAccess: false,\n req,\n where,\n })\n\n const totalMatchingDocs = countResult.totalDocs\n\n // Calculate actual export count (respecting both export limit and max limit)\n let effectiveLimit = totalMatchingDocs\n\n // Apply user's export limit if provided\n if (exportLimit && exportLimit > 0) {\n effectiveLimit = Math.min(effectiveLimit, exportLimit)\n }\n\n // Apply max limit if configured\n if (typeof maxLimit === 'number' && maxLimit > 0) {\n effectiveLimit = Math.min(effectiveLimit, maxLimit)\n }\n\n const exportTotalDocs = effectiveLimit\n\n // Calculate preview pagination that respects export limit\n // Preview should only show docs that will actually be exported\n const previewStartIndex = (previewPage - 1) * previewLimit\n\n // Calculate pagination info based on export limit (not raw DB results)\n const previewTotalPages = exportTotalDocs === 0 ? 0 : Math.ceil(exportTotalDocs / previewLimit)\n\n const isCSV = req?.data?.format === 'csv'\n\n // Get locale codes for locale expansion when locale='all'\n const localeCodes =\n locale === 'all' && req.payload.config.localization\n ? req.payload.config.localization.localeCodes\n : undefined\n\n // Get disabled fields configuration\n const disabledFields =\n targetCollection.config.admin?.custom?.['plugin-import-export']?.disabledFields ?? []\n\n // Compute schema-based columns for CSV (provides base ordering and handles empty exports)\n const schemaColumns = isCSV\n ? getSchemaColumns({\n collectionConfig: targetCollection.config,\n disabledFields,\n fields,\n locale: locale ?? undefined,\n localeCodes,\n })\n : undefined\n\n // columns will be finalized after data is available (merged with data-discovered columns)\n let columns = schemaColumns\n\n // If we're beyond the effective limit (considering both user limit and maxLimit), return empty docs\n if (exportTotalDocs > 0 && previewStartIndex >= exportTotalDocs) {\n const response: ExportPreviewResponse = {\n columns,\n docs: [],\n exportTotalDocs,\n hasNextPage: false,\n hasPrevPage: previewPage > 1,\n limit: previewLimit,\n maxLimit,\n page: previewPage,\n totalDocs: exportTotalDocs,\n totalPages: previewTotalPages,\n }\n return Response.json(response)\n }\n\n // Fetch preview page with full previewLimit to maintain consistent pagination offsets\n // We'll trim the results afterwards if needed to respect export limit\n const result = await req.payload.find({\n collection: collectionSlug,\n depth: 1,\n draft,\n limit: previewLimit,\n locale,\n overrideAccess: false,\n page: previewPage,\n req,\n select,\n sort,\n where,\n })\n\n // Trim docs to respect effective limit boundary (user limit clamped by maxLimit)\n let docs = result.docs\n if (exportTotalDocs > 0) {\n const remainingInExport = exportTotalDocs - previewStartIndex\n if (remainingInExport < docs.length) {\n docs = docs.slice(0, remainingInExport)\n }\n }\n\n // Transform docs based on format\n let transformed: Record<string, unknown>[]\n\n const exportFieldHooks = getExportFieldFunctions({\n fields: targetCollection.config.flattenedFields,\n })\n\n const exportHooks = targetCollection.config.custom?.['plugin-import-export']?.exportHooks\n\n if (isCSV) {\n const possibleKeys = getFlattenedFieldKeys(targetCollection.config.flattenedFields, '', {\n localeCodes,\n })\n\n // Flatten docs without padding yet. This preserves the exact keys produced by beforeExport hooks,\n // allowing mergeColumns to detect which schema columns were replaced with derived ones.\n transformed = docs.map((doc) =>\n flattenObject({\n data: doc,\n exportFieldHooks,\n fields,\n format: 'csv',\n req,\n }),\n )\n\n transformed = await applyExportBeforeHook(exportHooks?.before, transformed, docs, 'csv', req)\n\n if (schemaColumns && transformed.length > 0) {\n const dataColumns: string[] = []\n const seenCols = new Set<string>()\n for (const row of transformed) {\n for (const key of Object.keys(row)) {\n if (!seenCols.has(key)) {\n seenCols.add(key)\n dataColumns.push(key)\n }\n }\n }\n const mergedColumns = mergeColumns(schemaColumns, dataColumns)\n columns =\n Boolean(exportHooks?.before) && transformed.length > 0\n ? mergedColumns.filter((col) => dataColumns.includes(col))\n : mergedColumns\n }\n\n // Pad rows with null for missing columns (uses merged columns, not raw schema)\n if (!fields || fields.length === 0) {\n const paddingKeys = columns ?? possibleKeys\n for (const row of transformed) {\n for (const key of paddingKeys) {\n if (!(key in row)) {\n row[key] = null\n }\n }\n }\n }\n } else {\n transformed = docs.map((doc) => {\n // Apply field-level export hooks for JSON format\n let output: Record<string, unknown> = applyFieldHooks({\n type: 'beforeExport',\n data: doc as Record<string, unknown>,\n fieldHooks: exportFieldHooks,\n fields: targetCollection.config.flattenedFields,\n format: 'json',\n operation: 'export',\n req,\n })\n\n // Remove disabled fields\n output = removeDisabledFields(output, disabledFields)\n\n // Then trim to selected fields only (if fields are provided)\n if (Array.isArray(fields) && fields.length > 0) {\n const trimmed: Record<string, unknown> = {}\n\n for (const key of fields) {\n const value = getObjectDotNotation(output, key)\n setNestedValue(trimmed, key, value ?? null)\n }\n\n output = trimmed\n }\n\n return output\n })\n\n transformed = await applyExportBeforeHook(exportHooks?.before, transformed, docs, 'json', req)\n }\n\n const hasNextPage = previewPage < previewTotalPages\n const hasPrevPage = previewPage > 1\n\n const response: ExportPreviewResponse = {\n columns,\n docs: transformed,\n exportTotalDocs,\n hasNextPage,\n hasPrevPage,\n limit: previewLimit,\n maxLimit,\n page: previewPage,\n totalDocs: exportTotalDocs,\n totalPages: previewTotalPages,\n }\n\n return Response.json(response)\n}\n"],"names":["addDataAndFileToRequest","getObjectDotNotation","DEFAULT_PREVIEW_LIMIT","MAX_PREVIEW_LIMIT","MIN_PREVIEW_LIMIT","MIN_PREVIEW_PAGE","applyFieldHooks","flattenObject","getExportFieldFunctions","getFlattenedFieldKeys","getSchemaColumns","mergeColumns","getSelect","removeDisabledFields","resolveLimit","setNestedValue","applyExportBeforeHook","hook","data","originalDocs","format","req","length","batchNumber","originalData","totalBatches","handlePreview","collectionSlug","draft","draftFromReq","fields","limit","exportLimit","locale","previewLimit","rawPreviewLimit","previewPage","rawPreviewPage","sort","where","whereFromReq","Math","max","min","targetCollection","payload","collections","Response","json","error","status","pluginConfig","config","custom","maxLimit","select","Array","isArray","undefined","collectionHasVersions","Boolean","versions","publishedWhere","_status","equals","and","countResult","count","collection","overrideAccess","totalMatchingDocs","totalDocs","effectiveLimit","exportTotalDocs","previewStartIndex","previewTotalPages","ceil","isCSV","localeCodes","localization","disabledFields","admin","schemaColumns","collectionConfig","columns","response","docs","hasNextPage","hasPrevPage","page","totalPages","result","find","depth","remainingInExport","slice","transformed","exportFieldHooks","flattenedFields","exportHooks","possibleKeys","map","doc","before","dataColumns","seenCols","Set","row","key","Object","keys","has","add","push","mergedColumns","filter","col","includes","paddingKeys","output","type","fieldHooks","operation","trimmed","value"],"mappings":"AAEA,SAASA,uBAAuB,QAAQ,UAAS;AACjD,SAASC,oBAAoB,QAAQ,iBAAgB;AAIrD,SACEC,qBAAqB,EACrBC,iBAAiB,EACjBC,iBAAiB,EACjBC,gBAAgB,QACX,kBAAiB;AACxB,SAASC,eAAe,QAAQ,kCAAiC;AACjE,SAASC,aAAa,QAAQ,gCAA+B;AAC7D,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,qBAAqB,QAAQ,wCAAuC;AAC7E,SAASC,gBAAgB,EAAEC,YAAY,QAAQ,mCAAkC;AACjF,SAASC,SAAS,QAAQ,4BAA2B;AACrD,SAASC,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,YAAY,QAAQ,+BAA8B;AAC3D,SAASC,cAAc,QAAQ,iCAAgC;AAE/D,MAAMC,wBAAwB,OAC5BC,MACAC,MACAC,cACAC,QACAC;IAEA,IAAI,CAACJ,QAAQC,KAAKI,MAAM,KAAK,GAAG;QAC9B,OAAOJ;IACT;IACA,OAAOD,KAAK;QACVM,aAAa;QACbL;QACAE;QACAI,cAAcL;QACdE;QACAI,cAAc;IAChB;AACF;AAEA,OAAO,MAAMC,gBAAgB,OAAOL;IAClC,MAAMrB,wBAAwBqB;IAE9B,MAAM,EACJM,cAAc,EACdC,OAAOC,YAAY,EACnBC,MAAM,EACNC,OAAOC,WAAW,EAClBC,MAAM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C,WAAWE;QACXiB,YAAYf;IACd;IAEA,OAAO5B,SAASC,IAAI,CAACqC;AACvB,EAAC"}
|
package/dist/exports/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { ExportAfterHook, ExportBeforeHook, FieldBeforeExportHook, FieldBeforeImportHook,
|
|
1
|
+
export type { ExportAfterHook, ExportBeforeHook, FieldBeforeExportHook, FieldBeforeImportHook, ImportAfterHook, ImportBeforeHook, ImportExportPluginConfig, ImportResult, Limit, LimitFunction, } from '../types.js';
|
|
2
2
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/exports/types.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/exports/types.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,YAAY,EACZ,KAAK,EACL,aAAa,GACd,MAAM,aAAa,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type {\n ExportAfterHook,\n ExportBeforeHook,\n FieldBeforeExportHook,\n FieldBeforeImportHook,\n
|
|
1
|
+
{"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type {\n ExportAfterHook,\n ExportBeforeHook,\n FieldBeforeExportHook,\n FieldBeforeImportHook,\n ImportAfterHook,\n ImportBeforeHook,\n ImportExportPluginConfig,\n ImportResult,\n Limit,\n LimitFunction,\n} from '../types.js'\n"],"names":[],"mappings":"AAAA,WAWoB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createImport.d.ts","sourceRoot":"","sources":["../../src/import/createImport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAa,MAAM,SAAS,CAAA;AAIxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAU/C,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAEvD,MAAM,MAAM,MAAM,GAAG;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,IAAI,CAAC,EAAE;QACL,IAAI,EAAE,MAAM,CAAA;QACZ,QAAQ,EAAE,MAAM,CAAA;QAChB,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;IACD,MAAM,EAAE,KAAK,GAAG,MAAM,CAAA;IACtB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB;;OAEG;IACH,UAAU,EAAE,UAAU,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,oBAAoB,CAAC,EAAE,OAAO,GAAG,WAAW,CAAA;IAC5C,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,MAAM,CAAA;AAEV,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"createImport.d.ts","sourceRoot":"","sources":["../../src/import/createImport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAa,MAAM,SAAS,CAAA;AAIxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAU/C,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAEvD,MAAM,MAAM,MAAM,GAAG;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,IAAI,CAAC,EAAE;QACL,IAAI,EAAE,MAAM,CAAA;QACZ,QAAQ,EAAE,MAAM,CAAA;QAChB,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;IACD,MAAM,EAAE,KAAK,GAAG,MAAM,CAAA;IACtB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB;;OAEG;IACH,UAAU,EAAE,UAAU,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,oBAAoB,CAAC,EAAE,OAAO,GAAG,WAAW,CAAA;IAC5C,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,MAAM,CAAA;AAEV,eAAO,MAAM,YAAY,GAAU,0IAahC,gBAAgB,KAAG,OAAO,CAAC,YAAY,CAuLzC,CAAA"}
|
|
@@ -52,7 +52,7 @@ export const createImport = async ({ batchSize = 100, collectionSlug, debug = fa
|
|
|
52
52
|
// Get disabled fields configuration
|
|
53
53
|
const disabledFields = collectionConfig.admin?.custom?.['plugin-import-export']?.disabledFields ?? [];
|
|
54
54
|
const importHooks = collectionConfig.custom?.['plugin-import-export']?.importHooks;
|
|
55
|
-
// Get
|
|
55
|
+
// Get beforeImport functions for field transformations
|
|
56
56
|
const importFieldHooks = getImportFieldFunctions({
|
|
57
57
|
fields: collectionConfig.flattenedFields || []
|
|
58
58
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/import/createImport.ts"],"sourcesContent":["import type { PayloadRequest, TypedUser } from 'payload'\n\nimport { APIError } from 'payload'\n\nimport type { ImportResult } from '../types.js'\n\nimport { applyFieldHooks } from '../utilities/applyFieldHooks.js'\nimport { getImportFieldFunctions } from '../utilities/getImportFieldFunctions.js'\nimport { parseCSV } from '../utilities/parseCSV.js'\nimport { parseJSON } from '../utilities/parseJSON.js'\nimport { removeDisabledFields } from '../utilities/removeDisabledFields.js'\nimport { unflattenObject } from '../utilities/unflattenObject.js'\nimport { createImportBatchProcessor } from './batchProcessor.js'\n\nexport type ImportMode = 'create' | 'update' | 'upsert'\n\nexport type Import = {\n /**\n * Number of documents to process in each batch during import\n * @default 100\n */\n batchSize?: number\n collectionSlug: string\n /**\n * If true, enabled debug logging\n */\n debug?: boolean\n file?: {\n data: Buffer\n mimetype: string\n name: string\n }\n format: 'csv' | 'json'\n id?: number | string\n /**\n * Import mode: create, update or upset\n */\n importMode: ImportMode\n matchField?: string\n /**\n * Maximum number of documents that can be imported in a single operation.\n * This value has already been resolved from the plugin config.\n */\n maxLimit?: number\n name: string\n userCollection?: string\n userID?: number | string\n}\n\nexport type CreateImportArgs = {\n defaultVersionStatus?: 'draft' | 'published'\n req: PayloadRequest\n} & Import\n\nexport const createImport = async ({\n batchSize = 100,\n collectionSlug,\n debug = false,\n defaultVersionStatus = 'published',\n file,\n format,\n importMode = 'create',\n matchField = 'id',\n maxLimit,\n req,\n userCollection,\n userID,\n}: CreateImportArgs): Promise<ImportResult> => {\n let user: TypedUser | undefined\n\n if (userCollection && userID) {\n user = (await req.payload.findByID({\n id: userID,\n collection: userCollection,\n req,\n })) as TypedUser\n }\n\n if (!user) {\n throw new APIError('User is required for import operations', 401, null, true)\n }\n\n if (debug) {\n req.payload.logger.debug({\n collectionSlug,\n format,\n importMode,\n matchField,\n msg: 'Starting import process with args:',\n transactionID: req.transactionID, // Log transaction ID to verify we're in same transaction\n })\n }\n\n if (!collectionSlug) {\n throw new APIError('Collection slug is required', 400, null, true)\n }\n\n if (!file || !file?.data) {\n throw new APIError('No file data provided for import', 400, null, true)\n }\n\n if (debug) {\n req.payload.logger.debug({\n fileName: file.name,\n fileSize: file.data.length,\n mimeType: file.mimetype,\n msg: 'File info',\n })\n }\n\n const collectionConfig = req.payload.config.collections.find(\n ({ slug }) => slug === collectionSlug,\n )\n\n if (!collectionConfig) {\n if (!collectionSlug) {\n throw new APIError('Collection slug is required', 400, null, true)\n }\n throw new APIError(`Collection with slug ${collectionSlug} not found`, 400, null, true)\n }\n\n // Get disabled fields configuration\n const disabledFields =\n collectionConfig.admin?.custom?.['plugin-import-export']?.disabledFields ?? []\n\n const importHooks = collectionConfig.custom?.['plugin-import-export']?.importHooks\n\n // Get fromCSV functions for field transformations\n const importFieldHooks = getImportFieldFunctions({\n fields: collectionConfig.flattenedFields || [],\n })\n\n // Parse the file data\n let originalDocs: Record<string, unknown>[] | undefined\n let documents: Record<string, unknown>[]\n if (format === 'csv') {\n const rawData = await parseCSV({\n data: file.data,\n req,\n })\n\n originalDocs = rawData\n documents = rawData\n\n // Unflatten CSV data\n documents = documents\n .map((doc) => {\n const unflattened = unflattenObject({\n data: doc,\n fields: collectionConfig.flattenedFields ?? [],\n format,\n importFieldHooks,\n req,\n })\n return unflattened ?? {}\n })\n .filter((doc) => doc && Object.keys(doc).length > 0)\n\n if (debug) {\n req.payload.logger.debug({\n documentCount: documents.length,\n msg: 'After unflattening CSV',\n rawDataCount: rawData.length,\n })\n }\n } else {\n const parsedDocs = parseJSON({ data: file.data, req })\n originalDocs = parsedDocs\n // Apply field-level import hooks for JSON format\n documents = parsedDocs.map((doc) =>\n applyFieldHooks({\n type: 'beforeImport',\n data: doc,\n fieldHooks: importFieldHooks,\n fields: collectionConfig.flattenedFields ?? [],\n format,\n operation: 'import',\n req,\n }),\n )\n }\n\n if (debug) {\n req.payload.logger.debug({\n msg: `Parsed ${documents.length} documents from ${format} file`,\n })\n if (documents.length > 0) {\n req.payload.logger.debug({\n doc: documents[0],\n msg: 'First document sample:',\n })\n }\n }\n\n // Enforce maxLimit before processing to save memory/time\n if (typeof maxLimit === 'number' && maxLimit > 0 && documents.length > maxLimit) {\n throw new APIError(\n `Import file contains ${documents.length} documents but limit is ${maxLimit}`,\n 400,\n null,\n true,\n )\n }\n\n // Remove disabled fields from all documents\n if (disabledFields.length > 0) {\n documents = documents.map((doc) => removeDisabledFields(doc, disabledFields))\n }\n\n if (debug) {\n req.payload.logger.debug({\n batchSize,\n documentCount: documents.length,\n msg: 'Processing import in batches',\n })\n }\n\n // Create batch processor\n const processor = createImportBatchProcessor({\n batchSize,\n defaultVersionStatus,\n })\n\n const totalBatches = documents.length > 0 ? Math.ceil(documents.length / batchSize) : 1\n\n // Process import with batch processor\n const result = await processor.processImport({\n collectionSlug,\n docs: documents,\n format,\n hooks: importHooks,\n importMode,\n matchField,\n originalDocs,\n req,\n totalBatches,\n user,\n })\n\n if (debug) {\n req.payload.logger.info({\n errors: result.errors.length,\n imported: result.imported,\n msg: 'Import completed',\n total: result.total,\n updated: result.updated,\n })\n }\n\n return result\n}\n"],"names":["APIError","applyFieldHooks","getImportFieldFunctions","parseCSV","parseJSON","removeDisabledFields","unflattenObject","createImportBatchProcessor","createImport","batchSize","collectionSlug","debug","defaultVersionStatus","file","format","importMode","matchField","maxLimit","req","userCollection","userID","user","payload","findByID","id","collection","logger","msg","transactionID","data","fileName","name","fileSize","length","mimeType","mimetype","collectionConfig","config","collections","find","slug","disabledFields","admin","custom","importHooks","importFieldHooks","fields","flattenedFields","originalDocs","documents","rawData","map","doc","unflattened","filter","Object","keys","documentCount","rawDataCount","parsedDocs","type","fieldHooks","operation","processor","totalBatches","Math","ceil","result","processImport","docs","hooks","info","errors","imported","total","updated"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAIlC,SAASC,eAAe,QAAQ,kCAAiC;AACjE,SAASC,uBAAuB,QAAQ,0CAAyC;AAC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O1B;QACP7B;QACAC;QACAgC;QACA9B;QACA8C;QACA3C;IACF;IAEA,IAAIV,OAAO;QACTO,IAAII,OAAO,CAACI,MAAM,CAAC6C,IAAI,CAAC;YACtBC,QAAQL,OAAOK,MAAM,CAACvC,MAAM;YAC5BwC,UAAUN,OAAOM,QAAQ;YACzB9C,KAAK;YACL+C,OAAOP,OAAOO,KAAK;YACnBC,SAASR,OAAOQ,OAAO;QACzB;IACF;IAEA,OAAOR;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/import/createImport.ts"],"sourcesContent":["import type { PayloadRequest, TypedUser } from 'payload'\n\nimport { APIError } from 'payload'\n\nimport type { ImportResult } from '../types.js'\n\nimport { applyFieldHooks } from '../utilities/applyFieldHooks.js'\nimport { getImportFieldFunctions } from '../utilities/getImportFieldFunctions.js'\nimport { parseCSV } from '../utilities/parseCSV.js'\nimport { parseJSON } from '../utilities/parseJSON.js'\nimport { removeDisabledFields } from '../utilities/removeDisabledFields.js'\nimport { unflattenObject } from '../utilities/unflattenObject.js'\nimport { createImportBatchProcessor } from './batchProcessor.js'\n\nexport type ImportMode = 'create' | 'update' | 'upsert'\n\nexport type Import = {\n /**\n * Number of documents to process in each batch during import\n * @default 100\n */\n batchSize?: number\n collectionSlug: string\n /**\n * If true, enabled debug logging\n */\n debug?: boolean\n file?: {\n data: Buffer\n mimetype: string\n name: string\n }\n format: 'csv' | 'json'\n id?: number | string\n /**\n * Import mode: create, update or upset\n */\n importMode: ImportMode\n matchField?: string\n /**\n * Maximum number of documents that can be imported in a single operation.\n * This value has already been resolved from the plugin config.\n */\n maxLimit?: number\n name: string\n userCollection?: string\n userID?: number | string\n}\n\nexport type CreateImportArgs = {\n defaultVersionStatus?: 'draft' | 'published'\n req: PayloadRequest\n} & Import\n\nexport const createImport = async ({\n batchSize = 100,\n collectionSlug,\n debug = false,\n defaultVersionStatus = 'published',\n file,\n format,\n importMode = 'create',\n matchField = 'id',\n maxLimit,\n req,\n userCollection,\n userID,\n}: CreateImportArgs): Promise<ImportResult> => {\n let user: TypedUser | undefined\n\n if (userCollection && userID) {\n user = (await req.payload.findByID({\n id: userID,\n collection: userCollection,\n req,\n })) as TypedUser\n }\n\n if (!user) {\n throw new APIError('User is required for import operations', 401, null, true)\n }\n\n if (debug) {\n req.payload.logger.debug({\n collectionSlug,\n format,\n importMode,\n matchField,\n msg: 'Starting import process with args:',\n transactionID: req.transactionID, // Log transaction ID to verify we're in same transaction\n })\n }\n\n if (!collectionSlug) {\n throw new APIError('Collection slug is required', 400, null, true)\n }\n\n if (!file || !file?.data) {\n throw new APIError('No file data provided for import', 400, null, true)\n }\n\n if (debug) {\n req.payload.logger.debug({\n fileName: file.name,\n fileSize: file.data.length,\n mimeType: file.mimetype,\n msg: 'File info',\n })\n }\n\n const collectionConfig = req.payload.config.collections.find(\n ({ slug }) => slug === collectionSlug,\n )\n\n if (!collectionConfig) {\n if (!collectionSlug) {\n throw new APIError('Collection slug is required', 400, null, true)\n }\n throw new APIError(`Collection with slug ${collectionSlug} not found`, 400, null, true)\n }\n\n // Get disabled fields configuration\n const disabledFields =\n collectionConfig.admin?.custom?.['plugin-import-export']?.disabledFields ?? []\n\n const importHooks = collectionConfig.custom?.['plugin-import-export']?.importHooks\n\n // Get beforeImport functions for field transformations\n const importFieldHooks = getImportFieldFunctions({\n fields: collectionConfig.flattenedFields || [],\n })\n\n // Parse the file data\n let originalDocs: Record<string, unknown>[] | undefined\n let documents: Record<string, unknown>[]\n if (format === 'csv') {\n const rawData = await parseCSV({\n data: file.data,\n req,\n })\n\n originalDocs = rawData\n documents = rawData\n\n // Unflatten CSV data\n documents = documents\n .map((doc) => {\n const unflattened = unflattenObject({\n data: doc,\n fields: collectionConfig.flattenedFields ?? [],\n format,\n importFieldHooks,\n req,\n })\n return unflattened ?? {}\n })\n .filter((doc) => doc && Object.keys(doc).length > 0)\n\n if (debug) {\n req.payload.logger.debug({\n documentCount: documents.length,\n msg: 'After unflattening CSV',\n rawDataCount: rawData.length,\n })\n }\n } else {\n const parsedDocs = parseJSON({ data: file.data, req })\n originalDocs = parsedDocs\n // Apply field-level import hooks for JSON format\n documents = parsedDocs.map((doc) =>\n applyFieldHooks({\n type: 'beforeImport',\n data: doc,\n fieldHooks: importFieldHooks,\n fields: collectionConfig.flattenedFields ?? [],\n format,\n operation: 'import',\n req,\n }),\n )\n }\n\n if (debug) {\n req.payload.logger.debug({\n msg: `Parsed ${documents.length} documents from ${format} file`,\n })\n if (documents.length > 0) {\n req.payload.logger.debug({\n doc: documents[0],\n msg: 'First document sample:',\n })\n }\n }\n\n // Enforce maxLimit before processing to save memory/time\n if (typeof maxLimit === 'number' && maxLimit > 0 && documents.length > maxLimit) {\n throw new APIError(\n `Import file contains ${documents.length} documents but limit is ${maxLimit}`,\n 400,\n null,\n true,\n )\n }\n\n // Remove disabled fields from all documents\n if (disabledFields.length > 0) {\n documents = documents.map((doc) => removeDisabledFields(doc, disabledFields))\n }\n\n if (debug) {\n req.payload.logger.debug({\n batchSize,\n documentCount: documents.length,\n msg: 'Processing import in batches',\n })\n }\n\n // Create batch processor\n const processor = createImportBatchProcessor({\n batchSize,\n defaultVersionStatus,\n })\n\n const totalBatches = documents.length > 0 ? Math.ceil(documents.length / batchSize) : 1\n\n // Process import with batch processor\n const result = await processor.processImport({\n collectionSlug,\n docs: documents,\n format,\n hooks: importHooks,\n importMode,\n matchField,\n originalDocs,\n req,\n totalBatches,\n user,\n })\n\n if (debug) {\n req.payload.logger.info({\n errors: result.errors.length,\n imported: result.imported,\n msg: 'Import completed',\n total: result.total,\n updated: result.updated,\n })\n }\n\n return result\n}\n"],"names":["APIError","applyFieldHooks","getImportFieldFunctions","parseCSV","parseJSON","removeDisabledFields","unflattenObject","createImportBatchProcessor","createImport","batchSize","collectionSlug","debug","defaultVersionStatus","file","format","importMode","matchField","maxLimit","req","userCollection","userID","user","payload","findByID","id","collection","logger","msg","transactionID","data","fileName","name","fileSize","length","mimeType","mimetype","collectionConfig","config","collections","find","slug","disabledFields","admin","custom","importHooks","importFieldHooks","fields","flattenedFields","originalDocs","documents","rawData","map","doc","unflattened","filter","Object","keys","documentCount","rawDataCount","parsedDocs","type","fieldHooks","operation","processor","totalBatches","Math","ceil","result","processImport","docs","hooks","info","errors","imported","total","updated"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAIlC,SAASC,eAAe,QAAQ,kCAAiC;AACjE,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,SAAS,QAAQ,4BAA2B;AACrD,SAASC,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,eAAe,QAAQ,kCAAiC;AACjE,SAASC,0BAA0B,QAAQ,sBAAqB;AA0ChE,OAAO,MAAMC,eAAe,OAAO,EACjCC,YAAY,GAAG,EACfC,cAAc,EACdC,QAAQ,KAAK,EACbC,uBAAuB,WAAW,EAClCC,IAAI,EACJC,MAAM,EACNC,aAAa,QAAQ,EACrBC,aAAa,IAAI,EACjBC,QAAQ,EACRC,GAAG,EACHC,cAAc,EACdC,MAAM,EACW;IACjB,IAAIC;IAEJ,IAAIF,kBAAkBC,QAAQ;QAC5BC,OAAQ,MAAMH,IAAII,OAAO,CAACC,QAAQ,CAAC;YACjCC,IAAIJ;YACJK,YAAYN;YACZD;QACF;IACF;IAEA,IAAI,CAACG,MAAM;QACT,MAAM,IAAIrB,SAAS,0CAA0C,KAAK,MAAM;IAC1E;IAEA,IAAIW,OAAO;QACTO,IAAII,OAAO,CAACI,MAAM,CAACf,KAAK,CAAC;YACvBD;YACAI;YACAC;YACAC;YACAW,KAAK;YACLC,eAAeV,IAAIU,aAAa;QAClC;IACF;IAEA,IAAI,CAAClB,gBAAgB;QACnB,MAAM,IAAIV,SAAS,+BAA+B,KAAK,MAAM;IAC/D;IAEA,IAAI,CAACa,QAAQ,CAACA,MAAMgB,MAAM;QACxB,MAAM,IAAI7B,SAAS,oCAAoC,KAAK,MAAM;IACpE;IAEA,IAAIW,OAA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;IACF;IAEA,yBAAyB;IACzB,MAAMoC,YAAYxD,2BAA2B;QAC3CE;QACAG;IACF;IAEA,MAAMoD,eAAef,UAAUhB,MAAM,GAAG,IAAIgC,KAAKC,IAAI,CAACjB,UAAUhB,MAAM,GAAGxB,aAAa;IAEtF,sCAAsC;IACtC,MAAM0D,SAAS,MAAMJ,UAAUK,aAAa,CAAC;QAC3C1D;QACA2D,MAAMpB;QACNnC;QACAwD,OAAO1B;QACP7B;QACAC;QACAgC;QACA9B;QACA8C;QACA3C;IACF;IAEA,IAAIV,OAAO;QACTO,IAAII,OAAO,CAACI,MAAM,CAAC6C,IAAI,CAAC;YACtBC,QAAQL,OAAOK,MAAM,CAACvC,MAAM;YAC5BwC,UAAUN,OAAOM,QAAQ;YACzB9C,KAAK;YACL+C,OAAOP,OAAOO,KAAK;YACnBC,SAASR,OAAOQ,OAAO;QACzB;IACF;IAEA,OAAOR;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCreateImportCollectionTask.d.ts","sourceRoot":"","sources":["../../src/import/getCreateImportCollectionTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAOjD,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,oBAAoB,CAAC,EAAE,OAAO,GAAG,WAAW,CAAA;IAC5C,gBAAgB,EAAE,MAAM,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,6BAA6B,
|
|
1
|
+
{"version":3,"file":"getCreateImportCollectionTask.d.ts","sourceRoot":"","sources":["../../src/import/getCreateImportCollectionTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAOjD,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,oBAAoB,CAAC,EAAE,OAAO,GAAG,WAAW,CAAA;IAC5C,gBAAgB,EAAE,MAAM,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,6BAA6B,GACxC,SAAS,MAAM,KACd,UAAU,CAAC;IACZ,KAAK,EAAE,eAAe,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;CACf,CAgJA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFields.d.ts","sourceRoot":"","sources":["../../src/import/getFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAkB,MAAM,SAAS,CAAA;AAEpD,KAAK,gBAAgB,GAAG;IACtB;;;OAGG;IACH,eAAe,EAAE,MAAM,EAAE,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"getFields.d.ts","sourceRoot":"","sources":["../../src/import/getFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAkB,MAAM,SAAS,CAAA;AAEpD,KAAK,gBAAgB,GAAG;IACtB;;;OAGG;IACH,eAAe,EAAE,MAAM,EAAE,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,SAAS,gBAAgB,KAAG,KAAK,EA0J1D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getImportCollection.d.ts","sourceRoot":"","sources":["../../src/import/getImportCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA6B,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAI1E,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAYzE,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"getImportCollection.d.ts","sourceRoot":"","sources":["../../src/import/getImportCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA6B,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAI1E,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAYzE,eAAO,MAAM,mBAAmB,GAAI,kDAIjC;IACD;;OAEG;IACH,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,gBAoVH,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlePreview.d.ts","sourceRoot":"","sources":["../../src/import/handlePreview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAoB7C,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"handlePreview.d.ts","sourceRoot":"","sources":["../../src/import/handlePreview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAoB7C,eAAO,MAAM,aAAa,GAAU,KAAK,cAAc,KAAG,OAAO,CAAC,QAAQ,CAuIzE,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Config } from 'payload';
|
|
2
|
-
import type { ExportAfterHook, ExportBeforeHook, FieldBeforeExportHook, FieldBeforeImportHook,
|
|
2
|
+
import type { ExportAfterHook, ExportBeforeHook, FieldBeforeExportHook, FieldBeforeImportHook, ImportAfterHook, ImportBeforeHook, ImportExportPluginConfig, Limit } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Adds CSV/JSON import and export functionality to selected collections.
|
|
5
5
|
*
|
|
@@ -22,11 +22,6 @@ declare module 'payload' {
|
|
|
22
22
|
* @default false
|
|
23
23
|
*/
|
|
24
24
|
disabled?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* @deprecated use `hooks.beforeImport` instead.
|
|
27
|
-
* Still functional, but will be removed in a future major version.
|
|
28
|
-
*/
|
|
29
|
-
fromCSV?: FromCSVFunction;
|
|
30
25
|
/**
|
|
31
26
|
* Field-level lifecycle hooks for import/export transformations.
|
|
32
27
|
* Works for both CSV and JSON formats.
|
|
@@ -43,11 +38,6 @@ declare module 'payload' {
|
|
|
43
38
|
*/
|
|
44
39
|
beforeImport?: FieldBeforeImportHook;
|
|
45
40
|
};
|
|
46
|
-
/**
|
|
47
|
-
* @deprecated use `hooks.beforeExport` instead.
|
|
48
|
-
* Still functional, but will be removed in a future major version.
|
|
49
|
-
*/
|
|
50
|
-
toCSV?: ToCSVFunction;
|
|
51
41
|
};
|
|
52
42
|
}
|
|
53
43
|
interface CollectionAdminCustom {
|
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,EAAE,MAAM,SAAS,CAAA;AAKrC,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAKrC,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,KAAK,EAEN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E,MAAM,CAAA;YACxB;;;eAGG;YACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;YAChC;;;eAGG;YACH,WAAW,CAAC,EAAE;gBAAE,KAAK,CAAC,EAAE,eAAe,CAAC;gBAAC,MAAM,CAAC,EAAE,gBAAgB,CAAA;aAAE,CAAA;YACpE;;;;eAIG;YACH,WAAW,CAAC,EAAE,KAAK,CAAA;SACpB,CAAA;KACF;CACF"}
|
package/dist/index.js
CHANGED
|
@@ -171,11 +171,19 @@ import { getPluginCollections } from './utilities/getPluginCollections.js';
|
|
|
171
171
|
config.i18n = {};
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
174
|
-
* Merge plugin translations
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
174
|
+
* Merge plugin translations — only for languages the user has enabled.
|
|
175
|
+
* Plugins run before sanitize, so `supportedLanguages` may be undefined; sanitize will
|
|
176
|
+
* default it to `{ en }`, so we mirror that here to avoid merging 30+ unused tables.
|
|
177
|
+
*/ const supportedLanguageKeys = config.i18n?.supportedLanguages ? Object.keys(config.i18n.supportedLanguages) : [
|
|
178
|
+
'en'
|
|
179
|
+
];
|
|
180
|
+
const simplifiedTranslations = {};
|
|
181
|
+
for (const lang of supportedLanguageKeys){
|
|
182
|
+
const entry = translations[lang];
|
|
183
|
+
if (entry) {
|
|
184
|
+
simplifiedTranslations[lang] = entry.translations;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
179
187
|
config.i18n = {
|
|
180
188
|
...config.i18n,
|
|
181
189
|
translations: deepMergeSimple(simplifiedTranslations, config.i18n?.translations ?? {})
|