@payloadcms/plugin-import-export 3.71.0 → 3.71.1
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/package.json +7 -7
- package/dist/components/ExportListMenuItem/index.scss +0 -52
- package/dist/components/Preview/index.d.ts +0 -4
- package/dist/components/Preview/index.d.ts.map +0 -1
- package/dist/components/Preview/index.js +0 -180
- package/dist/components/Preview/index.js.map +0 -1
- package/dist/components/Preview/index.scss +0 -8
- package/dist/export/download.d.ts +0 -3
- package/dist/export/download.d.ts.map +0 -1
- package/dist/export/download.js +0 -41
- package/dist/export/download.js.map +0 -1
- package/dist/export/flattenObject.d.ts +0 -11
- package/dist/export/flattenObject.d.ts.map +0 -1
- package/dist/export/flattenObject.js +0 -122
- package/dist/export/flattenObject.js.map +0 -1
- package/dist/export/getCustomFieldFunctions.d.ts +0 -8
- package/dist/export/getCustomFieldFunctions.d.ts.map +0 -1
- package/dist/export/getCustomFieldFunctions.js +0 -86
- package/dist/export/getCustomFieldFunctions.js.map +0 -1
- package/dist/export/getFilename.d.ts +0 -2
- package/dist/export/getFilename.d.ts.map +0 -1
- package/dist/export/getFilename.js +0 -10
- package/dist/export/getFilename.js.map +0 -1
- package/dist/export/getSelect.d.ts +0 -7
- package/dist/export/getSelect.d.ts.map +0 -1
- package/dist/export/getSelect.js +0 -23
- package/dist/export/getSelect.js.map +0 -1
- package/dist/getExportCollection.d.ts +0 -7
- package/dist/getExportCollection.d.ts.map +0 -1
- package/dist/getExportCollection.js +0 -86
- package/dist/getExportCollection.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-import-export",
|
|
3
|
-
"version": "3.71.
|
|
3
|
+
"version": "3.71.1",
|
|
4
4
|
"description": "Import-Export plugin for Payload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"payload",
|
|
@@ -64,17 +64,17 @@
|
|
|
64
64
|
"csv-parse": "5.6.0",
|
|
65
65
|
"csv-stringify": "6.5.2",
|
|
66
66
|
"qs-esm": "7.0.2",
|
|
67
|
-
"@payloadcms/
|
|
68
|
-
"@payloadcms/
|
|
67
|
+
"@payloadcms/ui": "3.71.1",
|
|
68
|
+
"@payloadcms/translations": "3.71.1"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@payloadcms/ui": "3.71.0",
|
|
72
71
|
"@payloadcms/eslint-config": "3.28.0",
|
|
73
|
-
"
|
|
72
|
+
"@payloadcms/ui": "3.71.1",
|
|
73
|
+
"payload": "3.71.1"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"
|
|
77
|
-
"
|
|
76
|
+
"payload": "3.71.1",
|
|
77
|
+
"@payloadcms/ui": "3.71.1"
|
|
78
78
|
},
|
|
79
79
|
"homepage:": "https://payloadcms.com",
|
|
80
80
|
"scripts": {
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
@import '~@payloadcms/ui/scss';
|
|
2
|
-
|
|
3
|
-
@layer payload-default {
|
|
4
|
-
.export-list-menu-item {
|
|
5
|
-
.doc-drawer__toggler {
|
|
6
|
-
height: 100%;
|
|
7
|
-
width: 100%;
|
|
8
|
-
text-align: left;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// TODO: is any of this css needed?
|
|
13
|
-
&__subheader,
|
|
14
|
-
&__header {
|
|
15
|
-
padding: 0 var(--gutter-h);
|
|
16
|
-
display: flex;
|
|
17
|
-
align-items: center;
|
|
18
|
-
justify-content: space-between;
|
|
19
|
-
border-bottom: 1px solid var(--theme-border-color);
|
|
20
|
-
|
|
21
|
-
& h2 {
|
|
22
|
-
margin: calc(var(--gutter-h) * 0.5) 0;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
&__options,
|
|
27
|
-
&__preview {
|
|
28
|
-
padding: calc(var(--gutter-h) * 0.5) var(--gutter-h);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
&__preview-title {
|
|
32
|
-
display: flex;
|
|
33
|
-
align-items: center;
|
|
34
|
-
justify-content: space-between;
|
|
35
|
-
margin-bottom: calc(var(--gutter-h) * 0.5);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
&__close {
|
|
39
|
-
@include btn-reset;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
&__icon {
|
|
43
|
-
width: 3rem;
|
|
44
|
-
height: 3rem;
|
|
45
|
-
cursor: pointer;
|
|
46
|
-
|
|
47
|
-
&:hover {
|
|
48
|
-
opacity: 0.8;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Preview/index.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,MAAM,OAAO,CAAA;AAQzB,OAAO,cAAc,CAAA;AAKrB,eAAO,MAAM,OAAO,yBAiLnB,CAAA"}
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { getTranslation } from '@payloadcms/translations';
|
|
4
|
-
import { CodeEditorLazy, Table, Translation, useConfig, useField, useTranslation } from '@payloadcms/ui';
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import { buildDisabledFieldRegex } from '../../utilities/buildDisabledFieldRegex.js';
|
|
7
|
-
import './index.scss';
|
|
8
|
-
import { useImportExport } from '../ImportExportProvider/index.js';
|
|
9
|
-
const baseClass = 'preview';
|
|
10
|
-
export const Preview = ()=>{
|
|
11
|
-
const { collection } = useImportExport();
|
|
12
|
-
const { config } = useConfig();
|
|
13
|
-
const { value: where } = useField({
|
|
14
|
-
path: 'where'
|
|
15
|
-
});
|
|
16
|
-
const { value: page } = useField({
|
|
17
|
-
path: 'page'
|
|
18
|
-
});
|
|
19
|
-
const { value: limit } = useField({
|
|
20
|
-
path: 'limit'
|
|
21
|
-
});
|
|
22
|
-
const { value: fields } = useField({
|
|
23
|
-
path: 'fields'
|
|
24
|
-
});
|
|
25
|
-
const { value: sort } = useField({
|
|
26
|
-
path: 'sort'
|
|
27
|
-
});
|
|
28
|
-
const { value: draft } = useField({
|
|
29
|
-
path: 'drafts'
|
|
30
|
-
});
|
|
31
|
-
const { value: locale } = useField({
|
|
32
|
-
path: 'locale'
|
|
33
|
-
});
|
|
34
|
-
const { value: format } = useField({
|
|
35
|
-
path: 'format'
|
|
36
|
-
});
|
|
37
|
-
const [dataToRender, setDataToRender] = React.useState([]);
|
|
38
|
-
const [resultCount, setResultCount] = React.useState('');
|
|
39
|
-
const [columns, setColumns] = React.useState([]);
|
|
40
|
-
const { i18n, t } = useTranslation();
|
|
41
|
-
const collectionSlug = typeof collection === 'string' && collection;
|
|
42
|
-
const collectionConfig = config.collections.find((collection)=>collection.slug === collectionSlug);
|
|
43
|
-
const disabledFieldRegexes = React.useMemo(()=>{
|
|
44
|
-
const disabledFieldPaths = collectionConfig?.admin?.custom?.['plugin-import-export']?.disabledFields ?? [];
|
|
45
|
-
return disabledFieldPaths.map(buildDisabledFieldRegex);
|
|
46
|
-
}, [
|
|
47
|
-
collectionConfig
|
|
48
|
-
]);
|
|
49
|
-
const isCSV = format === 'csv';
|
|
50
|
-
React.useEffect(()=>{
|
|
51
|
-
const fetchData = async ()=>{
|
|
52
|
-
if (!collectionSlug || !collectionConfig) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
const res = await fetch('/api/preview-data', {
|
|
57
|
-
body: JSON.stringify({
|
|
58
|
-
collectionSlug,
|
|
59
|
-
draft,
|
|
60
|
-
fields,
|
|
61
|
-
format,
|
|
62
|
-
limit,
|
|
63
|
-
locale,
|
|
64
|
-
page,
|
|
65
|
-
sort,
|
|
66
|
-
where
|
|
67
|
-
}),
|
|
68
|
-
credentials: 'include',
|
|
69
|
-
headers: {
|
|
70
|
-
'Content-Type': 'application/json'
|
|
71
|
-
},
|
|
72
|
-
method: 'POST'
|
|
73
|
-
});
|
|
74
|
-
if (!res.ok) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const { docs, totalDocs } = await res.json();
|
|
78
|
-
setResultCount(limit && limit < totalDocs ? limit : totalDocs);
|
|
79
|
-
const allKeys = Array.from(new Set(docs.flatMap((doc)=>Object.keys(doc))));
|
|
80
|
-
const defaultMetaFields = [
|
|
81
|
-
'createdAt',
|
|
82
|
-
'updatedAt',
|
|
83
|
-
'_status',
|
|
84
|
-
'id'
|
|
85
|
-
];
|
|
86
|
-
// Match CSV column ordering by building keys based on fields and regex
|
|
87
|
-
const fieldToRegex = (field)=>{
|
|
88
|
-
const parts = field.split('.').map((part)=>`${part}(?:_\\d+)?`);
|
|
89
|
-
return new RegExp(`^${parts.join('_')}`);
|
|
90
|
-
};
|
|
91
|
-
// Construct final list of field keys to match field order + meta order
|
|
92
|
-
const selectedKeys = Array.isArray(fields) && fields.length > 0 ? fields.flatMap((field)=>{
|
|
93
|
-
const regex = fieldToRegex(field);
|
|
94
|
-
return allKeys.filter((key)=>regex.test(key) && !disabledFieldRegexes.some((disabledRegex)=>disabledRegex.test(key)));
|
|
95
|
-
}) : allKeys.filter((key)=>!defaultMetaFields.includes(key) && !disabledFieldRegexes.some((regex)=>regex.test(key)));
|
|
96
|
-
const fieldKeys = Array.isArray(fields) && fields.length > 0 ? selectedKeys // strictly use selected fields only
|
|
97
|
-
: [
|
|
98
|
-
...selectedKeys,
|
|
99
|
-
...defaultMetaFields.filter((key)=>allKeys.includes(key) && !selectedKeys.includes(key))
|
|
100
|
-
];
|
|
101
|
-
// Build columns based on flattened keys
|
|
102
|
-
const newColumns = fieldKeys.map((key)=>({
|
|
103
|
-
accessor: key,
|
|
104
|
-
active: true,
|
|
105
|
-
field: {
|
|
106
|
-
name: key
|
|
107
|
-
},
|
|
108
|
-
Heading: getTranslation(key, i18n),
|
|
109
|
-
renderedCells: docs.map((doc)=>{
|
|
110
|
-
const val = doc[key];
|
|
111
|
-
if (val === undefined || val === null) {
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
// Avoid ESLint warning by type-checking before calling String()
|
|
115
|
-
if (typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean') {
|
|
116
|
-
return String(val);
|
|
117
|
-
}
|
|
118
|
-
if (Array.isArray(val)) {
|
|
119
|
-
return val.map(String).join(', ');
|
|
120
|
-
}
|
|
121
|
-
return JSON.stringify(val);
|
|
122
|
-
})
|
|
123
|
-
}));
|
|
124
|
-
setColumns(newColumns);
|
|
125
|
-
setDataToRender(docs);
|
|
126
|
-
} catch (error) {
|
|
127
|
-
console.error('Error fetching preview data:', error);
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
void fetchData();
|
|
131
|
-
}, [
|
|
132
|
-
collectionConfig,
|
|
133
|
-
collectionSlug,
|
|
134
|
-
disabledFieldRegexes,
|
|
135
|
-
draft,
|
|
136
|
-
fields,
|
|
137
|
-
format,
|
|
138
|
-
i18n,
|
|
139
|
-
limit,
|
|
140
|
-
locale,
|
|
141
|
-
page,
|
|
142
|
-
sort,
|
|
143
|
-
where
|
|
144
|
-
]);
|
|
145
|
-
return /*#__PURE__*/ _jsxs("div", {
|
|
146
|
-
className: baseClass,
|
|
147
|
-
children: [
|
|
148
|
-
/*#__PURE__*/ _jsxs("div", {
|
|
149
|
-
className: `${baseClass}__header`,
|
|
150
|
-
children: [
|
|
151
|
-
/*#__PURE__*/ _jsx("h3", {
|
|
152
|
-
children: /*#__PURE__*/ _jsx(Translation, {
|
|
153
|
-
i18nKey: "version:preview",
|
|
154
|
-
t: t
|
|
155
|
-
})
|
|
156
|
-
}),
|
|
157
|
-
resultCount && /*#__PURE__*/ _jsx(Translation, {
|
|
158
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
159
|
-
// @ts-expect-error
|
|
160
|
-
i18nKey: "plugin-import-export:totalDocumentsCount",
|
|
161
|
-
t: t,
|
|
162
|
-
variables: {
|
|
163
|
-
count: resultCount
|
|
164
|
-
}
|
|
165
|
-
})
|
|
166
|
-
]
|
|
167
|
-
}),
|
|
168
|
-
dataToRender && (isCSV ? /*#__PURE__*/ _jsx(Table, {
|
|
169
|
-
columns: columns,
|
|
170
|
-
data: dataToRender
|
|
171
|
-
}) : /*#__PURE__*/ _jsx(CodeEditorLazy, {
|
|
172
|
-
language: "json",
|
|
173
|
-
readOnly: true,
|
|
174
|
-
value: JSON.stringify(dataToRender, null, 2)
|
|
175
|
-
}))
|
|
176
|
-
]
|
|
177
|
-
});
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Preview/index.tsx"],"sourcesContent":["'use client'\nimport type { Column } from '@payloadcms/ui'\nimport type { ClientField } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n CodeEditorLazy,\n Table,\n Translation,\n useConfig,\n useField,\n useTranslation,\n} from '@payloadcms/ui'\nimport React from 'react'\n\nimport type {\n PluginImportExportTranslationKeys,\n PluginImportExportTranslations,\n} from '../../translations/index.js'\n\nimport { buildDisabledFieldRegex } from '../../utilities/buildDisabledFieldRegex.js'\nimport './index.scss'\nimport { useImportExport } from '../ImportExportProvider/index.js'\n\nconst baseClass = 'preview'\n\nexport const Preview = () => {\n const { collection } = useImportExport()\n const { config } = useConfig()\n const { value: where } = useField({ path: 'where' })\n const { value: page } = useField({ path: 'page' })\n const { value: limit } = useField<number>({ path: 'limit' })\n const { value: fields } = useField<string[]>({ path: 'fields' })\n const { value: sort } = useField({ path: 'sort' })\n const { value: draft } = useField({ path: 'drafts' })\n const { value: locale } = useField({ path: 'locale' })\n const { value: format } = useField({ path: 'format' })\n const [dataToRender, setDataToRender] = React.useState<any[]>([])\n const [resultCount, setResultCount] = React.useState<any>('')\n const [columns, setColumns] = React.useState<Column[]>([])\n const { i18n, t } = useTranslation<\n PluginImportExportTranslations,\n PluginImportExportTranslationKeys\n >()\n\n const collectionSlug = typeof collection === 'string' && collection\n const collectionConfig = config.collections.find(\n (collection) => collection.slug === collectionSlug,\n )\n\n const disabledFieldRegexes: RegExp[] = React.useMemo(() => {\n const disabledFieldPaths =\n collectionConfig?.admin?.custom?.['plugin-import-export']?.disabledFields ?? []\n\n return disabledFieldPaths.map(buildDisabledFieldRegex)\n }, [collectionConfig])\n\n const isCSV = format === 'csv'\n\n React.useEffect(() => {\n const fetchData = async () => {\n if (!collectionSlug || !collectionConfig) {\n return\n }\n\n try {\n const res = await fetch('/api/preview-data', {\n body: JSON.stringify({\n collectionSlug,\n draft,\n fields,\n format,\n limit,\n locale,\n page,\n sort,\n where,\n }),\n credentials: 'include',\n headers: { 'Content-Type': 'application/json' },\n method: 'POST',\n })\n\n if (!res.ok) {\n return\n }\n\n const { docs, totalDocs }: { docs: Record<string, unknown>[]; totalDocs: number } =\n await res.json()\n\n setResultCount(limit && limit < totalDocs ? limit : totalDocs)\n\n const allKeys = Array.from(new Set(docs.flatMap((doc) => Object.keys(doc))))\n const defaultMetaFields = ['createdAt', 'updatedAt', '_status', 'id']\n\n // Match CSV column ordering by building keys based on fields and regex\n const fieldToRegex = (field: string): RegExp => {\n const parts = field.split('.').map((part) => `${part}(?:_\\\\d+)?`)\n return new RegExp(`^${parts.join('_')}`)\n }\n\n // Construct final list of field keys to match field order + meta order\n const selectedKeys =\n Array.isArray(fields) && fields.length > 0\n ? fields.flatMap((field) => {\n const regex = fieldToRegex(field)\n return allKeys.filter(\n (key) =>\n regex.test(key) &&\n !disabledFieldRegexes.some((disabledRegex) => disabledRegex.test(key)),\n )\n })\n : allKeys.filter(\n (key) =>\n !defaultMetaFields.includes(key) &&\n !disabledFieldRegexes.some((regex) => regex.test(key)),\n )\n\n const fieldKeys =\n Array.isArray(fields) && fields.length > 0\n ? selectedKeys // strictly use selected fields only\n : [\n ...selectedKeys,\n ...defaultMetaFields.filter(\n (key) => allKeys.includes(key) && !selectedKeys.includes(key),\n ),\n ]\n\n // Build columns based on flattened keys\n const newColumns: Column[] = fieldKeys.map((key) => ({\n accessor: key,\n active: true,\n field: { name: key } as ClientField,\n Heading: getTranslation(key, i18n),\n renderedCells: docs.map((doc: Record<string, unknown>) => {\n const val = doc[key]\n\n if (val === undefined || val === null) {\n return null\n }\n\n // Avoid ESLint warning by type-checking before calling String()\n if (typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean') {\n return String(val)\n }\n\n if (Array.isArray(val)) {\n return val.map(String).join(', ')\n }\n\n return JSON.stringify(val)\n }),\n }))\n\n setColumns(newColumns)\n setDataToRender(docs)\n } catch (error) {\n console.error('Error fetching preview data:', error)\n }\n }\n\n void fetchData()\n }, [\n collectionConfig,\n collectionSlug,\n disabledFieldRegexes,\n draft,\n fields,\n format,\n i18n,\n limit,\n locale,\n page,\n sort,\n where,\n ])\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__header`}>\n <h3>\n <Translation i18nKey=\"version:preview\" t={t} />\n </h3>\n {resultCount && (\n <Translation\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n i18nKey=\"plugin-import-export:totalDocumentsCount\"\n t={t}\n variables={{\n count: resultCount,\n }}\n />\n )}\n </div>\n {dataToRender &&\n (isCSV ? (\n <Table columns={columns} data={dataToRender} />\n ) : (\n <CodeEditorLazy language=\"json\" readOnly value={JSON.stringify(dataToRender, null, 2)} />\n ))}\n </div>\n )\n}\n"],"names":["getTranslation","CodeEditorLazy","Table","Translation","useConfig","useField","useTranslation","React","buildDisabledFieldRegex","useImportExport","baseClass","Preview","collection","config","value","where","path","page","limit","fields","sort","draft","locale","format","dataToRender","setDataToRender","useState","resultCount","setResultCount","columns","setColumns","i18n","t","collectionSlug","collectionConfig","collections","find","slug","disabledFieldRegexes","useMemo","disabledFieldPaths","admin","custom","disabledFields","map","isCSV","useEffect","fetchData","res","fetch","body","JSON","stringify","credentials","headers","method","ok","docs","totalDocs","json","allKeys","Array","from","Set","flatMap","doc","Object","keys","defaultMetaFields","fieldToRegex","field","parts","split","part","RegExp","join","selectedKeys","isArray","length","regex","filter","key","test","some","disabledRegex","includes","fieldKeys","newColumns","accessor","active","name","Heading","renderedCells","val","undefined","String","error","console","div","className","h3","i18nKey","variables","count","data","language","readOnly"],"mappings":"AAAA;;AAIA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SACEC,cAAc,EACdC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,QAAQ,EACRC,cAAc,QACT,iBAAgB;AACvB,OAAOC,WAAW,QAAO;AAOzB,SAASC,uBAAuB,QAAQ,6CAA4C;AACpF,OAAO,eAAc;AACrB,SAASC,eAAe,QAAQ,mCAAkC;AAElE,MAAMC,YAAY;AAElB,OAAO,MAAMC,UAAU;IACrB,MAAM,EAAEC,UAAU,EAAE,GAAGH;IACvB,MAAM,EAAEI,MAAM,EAAE,GAAGT;IACnB,MAAM,EAAEU,OAAOC,KAAK,EAAE,GAAGV,SAAS;QAAEW,MAAM;IAAQ;IAClD,MAAM,EAAEF,OAAOG,IAAI,EAAE,GAAGZ,SAAS;QAAEW,MAAM;IAAO;IAChD,MAAM,EAAEF,OAAOI,KAAK,EAAE,GAAGb,SAAiB;QAAEW,MAAM;IAAQ;IAC1D,MAAM,EAAEF,OAAOK,MAAM,EAAE,GAAGd,SAAmB;QAAEW,MAAM;IAAS;IAC9D,MAAM,EAAEF,OAAOM,IAAI,EAAE,GAAGf,SAAS;QAAEW,MAAM;IAAO;IAChD,MAAM,EAAEF,OAAOO,KAAK,EAAE,GAAGhB,SAAS;QAAEW,MAAM;IAAS;IACnD,MAAM,EAAEF,OAAOQ,MAAM,EAAE,GAAGjB,SAAS;QAAEW,MAAM;IAAS;IACpD,MAAM,EAAEF,OAAOS,MAAM,EAAE,GAAGlB,SAAS;QAAEW,MAAM;IAAS;IACpD,MAAM,CAACQ,cAAcC,gBAAgB,GA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4BAEA,gEAAgE;4BAChE,IAAI,OAAOA,QAAQ,YAAY,OAAOA,QAAQ,YAAY,OAAOA,QAAQ,WAAW;gCAClF,OAAOE,OAAOF;4BAChB;4BAEA,IAAIhC,MAAMgB,OAAO,CAACgB,MAAM;gCACtB,OAAOA,IAAIjD,GAAG,CAACmD,QAAQpB,IAAI,CAAC;4BAC9B;4BAEA,OAAOxB,KAAKC,SAAS,CAACyC;wBACxB;oBACF,CAAA;gBAEA/D,WAAWyD;gBACX9D,gBAAgBgC;YAClB,EAAE,OAAOuC,OAAO;gBACdC,QAAQD,KAAK,CAAC,gCAAgCA;YAChD;QACF;QAEA,KAAKjD;IACP,GAAG;QACDb;QACAD;QACAK;QACAjB;QACAF;QACAI;QACAQ;QACAb;QACAI;QACAL;QACAG;QACAL;KACD;IAED,qBACE,MAACmF;QAAIC,WAAWzF;;0BACd,MAACwF;gBAAIC,WAAW,GAAGzF,UAAU,QAAQ,CAAC;;kCACpC,KAAC0F;kCACC,cAAA,KAACjG;4BAAYkG,SAAQ;4BAAkBrE,GAAGA;;;oBAE3CL,6BACC,KAACxB;wBACC,6DAA6D;wBAC7D,mBAAmB;wBACnBkG,SAAQ;wBACRrE,GAAGA;wBACHsE,WAAW;4BACTC,OAAO5E;wBACT;;;;YAILH,gBACEqB,CAAAA,sBACC,KAAC3C;gBAAM2B,SAASA;gBAAS2E,MAAMhF;+BAE/B,KAACvB;gBAAewG,UAAS;gBAAOC,QAAQ;gBAAC5F,OAAOqC,KAAKC,SAAS,CAAC5B,cAAc,MAAM;cACrF;;;AAGR,EAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/export/download.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAM7C,eAAO,MAAM,QAAQ,QAAe,cAAc,uCA8BjD,CAAA"}
|
package/dist/export/download.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { APIError } from 'payload';
|
|
2
|
-
import { createExport } from './createExport.js';
|
|
3
|
-
export const download = async (req, debug = false)=>{
|
|
4
|
-
try {
|
|
5
|
-
let body;
|
|
6
|
-
if (typeof req?.json === 'function') {
|
|
7
|
-
body = await req.json();
|
|
8
|
-
}
|
|
9
|
-
if (!body || !body.data) {
|
|
10
|
-
throw new APIError('Request data is required.');
|
|
11
|
-
}
|
|
12
|
-
const { collectionSlug } = body.data || {};
|
|
13
|
-
req.payload.logger.info(`Download request received ${collectionSlug}`);
|
|
14
|
-
const res = await createExport({
|
|
15
|
-
download: true,
|
|
16
|
-
input: {
|
|
17
|
-
...body.data,
|
|
18
|
-
debug
|
|
19
|
-
},
|
|
20
|
-
req,
|
|
21
|
-
user: req.user
|
|
22
|
-
});
|
|
23
|
-
return res;
|
|
24
|
-
} catch (err) {
|
|
25
|
-
// Return JSON for front-end toast
|
|
26
|
-
return new Response(JSON.stringify({
|
|
27
|
-
errors: [
|
|
28
|
-
{
|
|
29
|
-
message: err.message || 'Something went wrong'
|
|
30
|
-
}
|
|
31
|
-
]
|
|
32
|
-
}), {
|
|
33
|
-
headers: {
|
|
34
|
-
'Content-Type': 'application/json'
|
|
35
|
-
},
|
|
36
|
-
status: 400
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
//# sourceMappingURL=download.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/download.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { APIError } from 'payload'\n\nimport { createExport } from './createExport.js'\n\nexport const download = async (req: PayloadRequest, debug = false) => {\n try {\n let body\n if (typeof req?.json === 'function') {\n body = await req.json()\n }\n\n if (!body || !body.data) {\n throw new APIError('Request data is required.')\n }\n\n const { collectionSlug } = body.data || {}\n\n req.payload.logger.info(`Download request received ${collectionSlug}`)\n\n const res = await createExport({\n download: true,\n input: { ...body.data, debug },\n req,\n user: req.user,\n })\n\n return res as Response\n } catch (err) {\n // Return JSON for front-end toast\n return new Response(\n JSON.stringify({ errors: [{ message: (err as Error).message || 'Something went wrong' }] }),\n { headers: { 'Content-Type': 'application/json' }, status: 400 },\n )\n }\n}\n"],"names":["APIError","createExport","download","req","debug","body","json","data","collectionSlug","payload","logger","info","res","input","user","err","Response","JSON","stringify","errors","message","headers","status"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAElC,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,OAAO,MAAMC,WAAW,OAAOC,KAAqBC,QAAQ,KAAK;IAC/D,IAAI;QACF,IAAIC;QACJ,IAAI,OAAOF,KAAKG,SAAS,YAAY;YACnCD,OAAO,MAAMF,IAAIG,IAAI;QACvB;QAEA,IAAI,CAACD,QAAQ,CAACA,KAAKE,IAAI,EAAE;YACvB,MAAM,IAAIP,SAAS;QACrB;QAEA,MAAM,EAAEQ,cAAc,EAAE,GAAGH,KAAKE,IAAI,IAAI,CAAC;QAEzCJ,IAAIM,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,0BAA0B,EAAEH,gBAAgB;QAErE,MAAMI,MAAM,MAAMX,aAAa;YAC7BC,UAAU;YACVW,OAAO;gBAAE,GAAGR,KAAKE,IAAI;gBAAEH;YAAM;YAC7BD;YACAW,MAAMX,IAAIW,IAAI;QAChB;QAEA,OAAOF;IACT,EAAE,OAAOG,KAAK;QACZ,kCAAkC;QAClC,OAAO,IAAIC,SACTC,KAAKC,SAAS,CAAC;YAAEC,QAAQ;gBAAC;oBAAEC,SAAS,AAACL,IAAcK,OAAO,IAAI;gBAAuB;aAAE;QAAC,IACzF;YAAEC,SAAS;gBAAE,gBAAgB;YAAmB;YAAGC,QAAQ;QAAI;IAEnE;AACF,EAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Document } from 'payload';
|
|
2
|
-
import type { ToCSVFunction } from '../types.js';
|
|
3
|
-
type Args = {
|
|
4
|
-
doc: Document;
|
|
5
|
-
fields?: string[];
|
|
6
|
-
prefix?: string;
|
|
7
|
-
toCSVFunctions: Record<string, ToCSVFunction>;
|
|
8
|
-
};
|
|
9
|
-
export declare const flattenObject: ({ doc, fields, prefix, toCSVFunctions, }: Args) => Record<string, unknown>;
|
|
10
|
-
export {};
|
|
11
|
-
//# sourceMappingURL=flattenObject.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flattenObject.d.ts","sourceRoot":"","sources":["../../src/export/flattenObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,QAAQ,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;CAC9C,CAAA;AAED,eAAO,MAAM,aAAa,6CAKvB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAqJ/B,CAAA"}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
export const flattenObject = ({ doc, fields, prefix, toCSVFunctions })=>{
|
|
2
|
-
const row = {};
|
|
3
|
-
const flatten = (siblingDoc, prefix)=>{
|
|
4
|
-
Object.entries(siblingDoc).forEach(([key, value])=>{
|
|
5
|
-
const newKey = prefix ? `${prefix}_${key}` : key;
|
|
6
|
-
if (Array.isArray(value)) {
|
|
7
|
-
// If a custom toCSV function exists for this array field, run it first.
|
|
8
|
-
// If it produces output, skip per-item handling; otherwise, fall back.
|
|
9
|
-
if (toCSVFunctions?.[newKey]) {
|
|
10
|
-
try {
|
|
11
|
-
const result = toCSVFunctions[newKey]({
|
|
12
|
-
columnName: newKey,
|
|
13
|
-
data: row,
|
|
14
|
-
doc,
|
|
15
|
-
row,
|
|
16
|
-
siblingDoc,
|
|
17
|
-
value
|
|
18
|
-
});
|
|
19
|
-
if (typeof result !== 'undefined') {
|
|
20
|
-
// Custom function returned a single value for this array field.
|
|
21
|
-
row[newKey] = result;
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
// If the custom function wrote any keys for this field, consider it handled.
|
|
25
|
-
for(const k in row){
|
|
26
|
-
if (k === newKey || k.startsWith(`${newKey}_`)) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
// Otherwise, fall through to per-item handling.
|
|
31
|
-
} catch (error) {
|
|
32
|
-
throw new Error(`Error in toCSVFunction for array "${newKey}": ${JSON.stringify(value)}\n${error.message}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
value.forEach((item, index)=>{
|
|
36
|
-
if (typeof item === 'object' && item !== null) {
|
|
37
|
-
const blockType = typeof item.blockType === 'string' ? item.blockType : undefined;
|
|
38
|
-
const itemPrefix = blockType ? `${newKey}_${index}_${blockType}` : `${newKey}_${index}`;
|
|
39
|
-
// Case: hasMany polymorphic relationships
|
|
40
|
-
if ('relationTo' in item && 'value' in item && typeof item.value === 'object' && item.value !== null) {
|
|
41
|
-
row[`${itemPrefix}_relationTo`] = item.relationTo;
|
|
42
|
-
row[`${itemPrefix}_id`] = item.value.id;
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
// Fallback: deep-flatten nested objects
|
|
46
|
-
flatten(item, itemPrefix);
|
|
47
|
-
} else {
|
|
48
|
-
// Primitive array item.
|
|
49
|
-
row[`${newKey}_${index}`] = item;
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
} else if (typeof value === 'object' && value !== null) {
|
|
53
|
-
// Object field: use custom toCSV if present, else recurse.
|
|
54
|
-
if (!toCSVFunctions?.[newKey]) {
|
|
55
|
-
flatten(value, newKey);
|
|
56
|
-
} else {
|
|
57
|
-
try {
|
|
58
|
-
const result = toCSVFunctions[newKey]({
|
|
59
|
-
columnName: newKey,
|
|
60
|
-
data: row,
|
|
61
|
-
doc,
|
|
62
|
-
row,
|
|
63
|
-
siblingDoc,
|
|
64
|
-
value
|
|
65
|
-
});
|
|
66
|
-
if (typeof result !== 'undefined') {
|
|
67
|
-
row[newKey] = result;
|
|
68
|
-
}
|
|
69
|
-
} catch (error) {
|
|
70
|
-
throw new Error(`Error in toCSVFunction for nested object "${newKey}": ${JSON.stringify(value)}\n${error.message}`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
} else {
|
|
74
|
-
if (toCSVFunctions?.[newKey]) {
|
|
75
|
-
try {
|
|
76
|
-
const result = toCSVFunctions[newKey]({
|
|
77
|
-
columnName: newKey,
|
|
78
|
-
data: row,
|
|
79
|
-
doc,
|
|
80
|
-
row,
|
|
81
|
-
siblingDoc,
|
|
82
|
-
value
|
|
83
|
-
});
|
|
84
|
-
if (typeof result !== 'undefined') {
|
|
85
|
-
row[newKey] = result;
|
|
86
|
-
}
|
|
87
|
-
} catch (error) {
|
|
88
|
-
throw new Error(`Error in toCSVFunction for field "${newKey}": ${JSON.stringify(value)}\n${error.message}`);
|
|
89
|
-
}
|
|
90
|
-
} else {
|
|
91
|
-
row[newKey] = value;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
flatten(doc, prefix);
|
|
97
|
-
if (Array.isArray(fields) && fields.length > 0) {
|
|
98
|
-
const orderedResult = {};
|
|
99
|
-
const fieldToRegex = (field)=>{
|
|
100
|
-
const parts = field.split('.').map((part)=>`${part}(?:_\\d+)?`);
|
|
101
|
-
const pattern = `^${parts.join('_')}`;
|
|
102
|
-
return new RegExp(pattern);
|
|
103
|
-
};
|
|
104
|
-
fields.forEach((field)=>{
|
|
105
|
-
if (row[field.replace(/\./g, '_')]) {
|
|
106
|
-
const sanitizedField = field.replace(/\./g, '_');
|
|
107
|
-
orderedResult[sanitizedField] = row[sanitizedField];
|
|
108
|
-
} else {
|
|
109
|
-
const regex = fieldToRegex(field);
|
|
110
|
-
Object.keys(row).forEach((key)=>{
|
|
111
|
-
if (regex.test(key)) {
|
|
112
|
-
orderedResult[key] = row[key];
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
return orderedResult;
|
|
118
|
-
}
|
|
119
|
-
return row;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
//# sourceMappingURL=flattenObject.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/flattenObject.ts"],"sourcesContent":["import type { Document } from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\ntype Args = {\n doc: Document\n fields?: string[]\n prefix?: string\n toCSVFunctions: Record<string, ToCSVFunction>\n}\n\nexport const flattenObject = ({\n doc,\n fields,\n prefix,\n toCSVFunctions,\n}: Args): Record<string, unknown> => {\n const row: Record<string, unknown> = {}\n\n const flatten = (siblingDoc: Document, prefix?: string) => {\n Object.entries(siblingDoc).forEach(([key, value]) => {\n const newKey = prefix ? `${prefix}_${key}` : key\n\n if (Array.isArray(value)) {\n // If a custom toCSV function exists for this array field, run it first.\n // If it produces output, skip per-item handling; otherwise, fall back.\n if (toCSVFunctions?.[newKey]) {\n try {\n const result = toCSVFunctions[newKey]({\n columnName: newKey,\n data: row,\n doc,\n row,\n siblingDoc,\n value, // whole array\n })\n\n if (typeof result !== 'undefined') {\n // Custom function returned a single value for this array field.\n row[newKey] = result\n return\n }\n\n // If the custom function wrote any keys for this field, consider it handled.\n for (const k in row) {\n if (k === newKey || k.startsWith(`${newKey}_`)) {\n return\n }\n }\n // Otherwise, fall through to per-item handling.\n } catch (error) {\n throw new Error(\n `Error in toCSVFunction for array \"${newKey}\": ${JSON.stringify(value)}\\n${\n (error as Error).message\n }`,\n )\n }\n }\n\n value.forEach((item, index) => {\n if (typeof item === 'object' && item !== null) {\n const blockType = typeof item.blockType === 'string' ? item.blockType : undefined\n const itemPrefix = blockType ? `${newKey}_${index}_${blockType}` : `${newKey}_${index}`\n\n // Case: hasMany polymorphic relationships\n if (\n 'relationTo' in item &&\n 'value' in item &&\n typeof item.value === 'object' &&\n item.value !== null\n ) {\n row[`${itemPrefix}_relationTo`] = item.relationTo\n row[`${itemPrefix}_id`] = item.value.id\n return\n }\n\n // Fallback: deep-flatten nested objects\n flatten(item, itemPrefix)\n } else {\n // Primitive array item.\n row[`${newKey}_${index}`] = item\n }\n })\n } else if (typeof value === 'object' && value !== null) {\n // Object field: use custom toCSV if present, else recurse.\n if (!toCSVFunctions?.[newKey]) {\n flatten(value, newKey)\n } else {\n try {\n const result = toCSVFunctions[newKey]({\n columnName: newKey,\n data: row,\n doc,\n row,\n siblingDoc,\n value,\n })\n if (typeof result !== 'undefined') {\n row[newKey] = result\n }\n } catch (error) {\n throw new Error(\n `Error in toCSVFunction for nested object \"${newKey}\": ${JSON.stringify(value)}\\n${\n (error as Error).message\n }`,\n )\n }\n }\n } else {\n if (toCSVFunctions?.[newKey]) {\n try {\n const result = toCSVFunctions[newKey]({\n columnName: newKey,\n data: row,\n doc,\n row,\n siblingDoc,\n value,\n })\n if (typeof result !== 'undefined') {\n row[newKey] = result\n }\n } catch (error) {\n throw new Error(\n `Error in toCSVFunction for field \"${newKey}\": ${JSON.stringify(value)}\\n${\n (error as Error).message\n }`,\n )\n }\n } else {\n row[newKey] = value\n }\n }\n })\n }\n\n flatten(doc, prefix)\n\n if (Array.isArray(fields) && fields.length > 0) {\n const orderedResult: Record<string, unknown> = {}\n\n const fieldToRegex = (field: string): RegExp => {\n const parts = field.split('.').map((part) => `${part}(?:_\\\\d+)?`)\n const pattern = `^${parts.join('_')}`\n return new RegExp(pattern)\n }\n\n fields.forEach((field) => {\n if (row[field.replace(/\\./g, '_')]) {\n const sanitizedField = field.replace(/\\./g, '_')\n orderedResult[sanitizedField] = row[sanitizedField]\n } else {\n const regex = fieldToRegex(field)\n Object.keys(row).forEach((key) => {\n if (regex.test(key)) {\n orderedResult[key] = row[key]\n }\n })\n }\n })\n\n return orderedResult\n }\n\n return row\n}\n"],"names":["flattenObject","doc","fields","prefix","toCSVFunctions","row","flatten","siblingDoc","Object","entries","forEach","key","value","newKey","Array","isArray","result","columnName","data","k","startsWith","error","Error","JSON","stringify","message","item","index","blockType","undefined","itemPrefix","relationTo","id","length","orderedResult","fieldToRegex","field","parts","split","map","part","pattern","join","RegExp","replace","sanitizedField","regex","keys","test"],"mappings":"AAWA,OAAO,MAAMA,gBAAgB,CAAC,EAC5BC,GAAG,EACHC,MAAM,EACNC,MAAM,EACNC,cAAc,EACT;IACL,MAAMC,MAA+B,CAAC;IAEtC,MAAMC,UAAU,CAACC,YAAsBJ;QACrCK,OAAOC,OAAO,CAACF,YAAYG,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;YAC9C,MAAMC,SAASV,SAAS,GAAGA,OAAO,CAAC,EAAEQ,KAAK,GAAGA;YAE7C,IAAIG,MAAMC,OAAO,CAACH,QAAQ;gBACxB,wEAAwE;gBACxE,uEAAuE;gBACvE,IAAIR,gBAAgB,CAACS,OAAO,EAAE;oBAC5B,IAAI;wBACF,MAAMG,SAASZ,cAAc,CAACS,OAAO,CAAC;4BACpCI,YAAYJ;4BACZK,MAAMb;4BACNJ;4BACAI;4BACAE;4BACAK;wBACF;wBAEA,IAAI,OAAOI,WAAW,aAAa;4BACjC,gEAAgE;4BAChEX,GAAG,CAACQ,OAAO,GAAGG;4BACd;wBACF;wBAEA,6EAA6E;wBAC7E,IAAK,MAAMG,KAAKd,IAAK;4BACnB,IAAIc,MAAMN,UAAUM,EAAEC,UAAU,CAAC,GAAGP,OAAO,CAAC,CAAC,GAAG;gCAC9C;4BACF;wBACF;oBACA,gDAAgD;oBAClD,EAAE,OAAOQ,OAAO;wBACd,MAAM,IAAIC,MACR,CAAC,kCAAkC,EAAET,OAAO,GAAG,EAAEU,KAAKC,SAAS,CAACZ,OAAO,EAAE,EACvE,AAACS,MAAgBI,OAAO,EACxB;oBAEN;gBACF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B;gBACF;YACF;QACF;QAEA,OAAOuB;IACT;IAEA,OAAO7B;AACT,EAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type FlattenedField } from 'payload';
|
|
2
|
-
import type { ToCSVFunction } from '../types.js';
|
|
3
|
-
type Args = {
|
|
4
|
-
fields: FlattenedField[];
|
|
5
|
-
};
|
|
6
|
-
export declare const getCustomFieldFunctions: ({ fields }: Args) => Record<string, ToCSVFunction>;
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=getCustomFieldFunctions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getCustomFieldFunctions.d.ts","sourceRoot":"","sources":["../../src/export/getCustomFieldFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAA+C,MAAM,SAAS,CAAA;AAE1F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,cAAc,EAAE,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,uBAAuB,eAAgB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAgGtF,CAAA"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { traverseFields } from 'payload';
|
|
2
|
-
export const getCustomFieldFunctions = ({ fields })=>{
|
|
3
|
-
const result = {};
|
|
4
|
-
const buildCustomFunctions = ({ field, parentRef, ref })=>{
|
|
5
|
-
// @ts-expect-error ref is untyped
|
|
6
|
-
ref.prefix = parentRef.prefix || '';
|
|
7
|
-
if (field.type === 'group' || field.type === 'tab') {
|
|
8
|
-
// @ts-expect-error ref is untyped
|
|
9
|
-
const parentPrefix = parentRef?.prefix ? `${parentRef.prefix}_` : '';
|
|
10
|
-
// @ts-expect-error ref is untyped
|
|
11
|
-
ref.prefix = `${parentPrefix}${field.name}_`;
|
|
12
|
-
}
|
|
13
|
-
if (typeof field.custom?.['plugin-import-export']?.toCSV === 'function') {
|
|
14
|
-
// @ts-expect-error ref is untyped
|
|
15
|
-
result[`${ref.prefix}${field.name}`] = field.custom['plugin-import-export']?.toCSV;
|
|
16
|
-
} else if (field.type === 'relationship' || field.type === 'upload') {
|
|
17
|
-
if (field.hasMany !== true) {
|
|
18
|
-
if (!Array.isArray(field.relationTo)) {
|
|
19
|
-
// monomorphic single
|
|
20
|
-
// @ts-expect-error ref is untyped
|
|
21
|
-
result[`${ref.prefix}${field.name}`] = ({ value })=>typeof value === 'object' && value && 'id' in value ? value.id : value;
|
|
22
|
-
} else {
|
|
23
|
-
// polymorphic single
|
|
24
|
-
// @ts-expect-error ref is untyped
|
|
25
|
-
result[`${ref.prefix}${field.name}`] = ({ data, value })=>{
|
|
26
|
-
if (value && typeof value === 'object' && 'relationTo' in value && 'value' in value) {
|
|
27
|
-
const relationTo = value.relationTo;
|
|
28
|
-
const relatedDoc = value.value;
|
|
29
|
-
if (relatedDoc && typeof relatedDoc === 'object') {
|
|
30
|
-
// @ts-expect-error ref is untyped
|
|
31
|
-
data[`${ref.prefix}${field.name}_id`] = relatedDoc.id;
|
|
32
|
-
// @ts-expect-error ref is untyped
|
|
33
|
-
data[`${ref.prefix}${field.name}_relationTo`] = relationTo;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return undefined // prevents further flattening
|
|
37
|
-
;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
if (!Array.isArray(field.relationTo)) {
|
|
42
|
-
// monomorphic many
|
|
43
|
-
// @ts-expect-error ref is untyped
|
|
44
|
-
result[`${ref.prefix}${field.name}`] = ({ data, value })=>{
|
|
45
|
-
if (Array.isArray(value)) {
|
|
46
|
-
value.forEach((val, i)=>{
|
|
47
|
-
const id = typeof val === 'object' && val ? val.id : val;
|
|
48
|
-
// @ts-expect-error ref is untyped
|
|
49
|
-
data[`${ref.prefix}${field.name}_${i}_id`] = id;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
return undefined // prevents further flattening
|
|
53
|
-
;
|
|
54
|
-
};
|
|
55
|
-
} else {
|
|
56
|
-
// polymorphic many
|
|
57
|
-
// @ts-expect-error ref is untyped
|
|
58
|
-
result[`${ref.prefix}${field.name}`] = ({ data, value })=>{
|
|
59
|
-
if (Array.isArray(value)) {
|
|
60
|
-
value.forEach((val, i)=>{
|
|
61
|
-
if (val && typeof val === 'object') {
|
|
62
|
-
const relationTo = val.relationTo;
|
|
63
|
-
const relatedDoc = val.value;
|
|
64
|
-
if (relationTo && relatedDoc && typeof relatedDoc === 'object') {
|
|
65
|
-
// @ts-expect-error ref is untyped
|
|
66
|
-
data[`${ref.prefix}${field.name}_${i}_id`] = relatedDoc.id;
|
|
67
|
-
// @ts-expect-error ref is untyped
|
|
68
|
-
data[`${ref.prefix}${field.name}_${i}_relationTo`] = relationTo;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
return undefined;
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
traverseFields({
|
|
80
|
-
callback: buildCustomFunctions,
|
|
81
|
-
fields
|
|
82
|
-
});
|
|
83
|
-
return result;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
//# sourceMappingURL=getCustomFieldFunctions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/getCustomFieldFunctions.ts"],"sourcesContent":["import { type FlattenedField, traverseFields, type TraverseFieldsCallback } from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\ntype Args = {\n fields: FlattenedField[]\n}\n\nexport const getCustomFieldFunctions = ({ fields }: Args): Record<string, ToCSVFunction> => {\n const result: Record<string, ToCSVFunction> = {}\n\n const buildCustomFunctions: TraverseFieldsCallback = ({ field, parentRef, ref }) => {\n // @ts-expect-error ref is untyped\n ref.prefix = parentRef.prefix || ''\n if (field.type === 'group' || field.type === 'tab') {\n // @ts-expect-error ref is untyped\n const parentPrefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n // @ts-expect-error ref is untyped\n ref.prefix = `${parentPrefix}${field.name}_`\n }\n\n if (typeof field.custom?.['plugin-import-export']?.toCSV === 'function') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = field.custom['plugin-import-export']?.toCSV\n } else if (field.type === 'relationship' || field.type === 'upload') {\n if (field.hasMany !== true) {\n if (!Array.isArray(field.relationTo)) {\n // monomorphic single\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) =>\n typeof value === 'object' && value && 'id' in value ? value.id : value\n } else {\n // polymorphic single\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ data, value }) => {\n if (value && typeof value === 'object' && 'relationTo' in value && 'value' in value) {\n const relationTo = (value as { relationTo: string; value: { id: number | string } })\n .relationTo\n const relatedDoc = (value as { relationTo: string; value: { id: number | string } })\n .value\n if (relatedDoc && typeof relatedDoc === 'object') {\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_id`] = relatedDoc.id\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_relationTo`] = relationTo\n }\n }\n return undefined // prevents further flattening\n }\n }\n } else {\n if (!Array.isArray(field.relationTo)) {\n // monomorphic many\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({\n data,\n value,\n }: {\n data: Record<string, unknown>\n value: Array<number | Record<string, any> | string> | undefined\n }) => {\n if (Array.isArray(value)) {\n value.forEach((val, i) => {\n const id = typeof val === 'object' && val ? val.id : val\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_${i}_id`] = id\n })\n }\n return undefined // prevents further flattening\n }\n } else {\n // polymorphic many\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({\n data,\n value,\n }: {\n data: Record<string, unknown>\n value: Array<Record<string, any>> | undefined\n }) => {\n if (Array.isArray(value)) {\n value.forEach((val, i) => {\n if (val && typeof val === 'object') {\n const relationTo = val.relationTo\n const relatedDoc = val.value\n if (relationTo && relatedDoc && typeof relatedDoc === 'object') {\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_${i}_id`] = relatedDoc.id\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_${i}_relationTo`] = relationTo\n }\n }\n })\n }\n return undefined\n }\n }\n }\n }\n }\n\n traverseFields({ callback: buildCustomFunctions, fields })\n\n return result\n}\n"],"names":["traverseFields","getCustomFieldFunctions","fields","result","buildCustomFunctions","field","parentRef","ref","prefix","type","parentPrefix","name","custom","toCSV","hasMany","Array","isArray","relationTo","value","id","data","relatedDoc","undefined","forEach","val","i","callback"],"mappings":"AAAA,SAA8BA,cAAc,QAAqC,UAAS;AAQ1F,OAAO,MAAMC,0BAA0B,CAAC,EAAEC,MAAM,EAAQ;IACtD,MAAMC,SAAwC,CAAC;IAE/C,MAAMC,uBAA+C,CAAC,EAAEC,KAAK,EAAEC,SAAS,EAAEC,GAAG,EAAE;QAC7E,kCAAkC;QAClCA,IAAIC,MAAM,GAAGF,UAAUE,MAAM,IAAI;QACjC,IAAIH,MAAMI,IAAI,KAAK,WAAWJ,MAAMI,IAAI,KAAK,OAAO;YAClD,kCAAkC;YAClC,MAAMC,eAAeJ,WAAWE,SAAS,GAAGF,UAAUE,MAAM,CAAC,CAAC,CAAC,GAAG;YAClE,kCAAkC;YAClCD,IAAIC,MAAM,GAAG,GAAGE,eAAeL,MAAMM,IAAI,CAAC,CAAC,CAAC;QAC9C;QAEA,IAAI,OAAON,MAAMO,MAAM,EAAE,CAAC,uBAAuB,EAAEC,UAAU,YAAY;YACvE,kCAAkC;YAClCV,MAAM,CAAC,GAAGI,IAAIC,MAAM,GAAGH,MAAMM,IAAI,EAAE,CAAC,GAAGN,MAAMO,MAAM,CAAC,uBAAuB,EAAEC;QAC/E,OAAO,IAAIR,MAAMI,IAAI,KAAK,kBAAkBJ,MAAMI,I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0,0 @@
|
|
|
1
|
-
export const getFilename = ()=>{
|
|
2
|
-
const now = new Date();
|
|
3
|
-
const yyymmdd = now.toISOString().split('T')[0] // "YYYY-MM-DD"
|
|
4
|
-
;
|
|
5
|
-
const hhmmss = now.toTimeString().split(' ')[0] // "HH:MM:SS"
|
|
6
|
-
;
|
|
7
|
-
return `${yyymmdd} ${hhmmss}`;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=getFilename.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/getFilename.ts"],"sourcesContent":["export const getFilename = () => {\n const now = new Date()\n const yyymmdd = now.toISOString().split('T')[0] // \"YYYY-MM-DD\"\n const hhmmss = now.toTimeString().split(' ')[0] // \"HH:MM:SS\"\n\n return `${yyymmdd} ${hhmmss}`\n}\n"],"names":["getFilename","now","Date","yyymmdd","toISOString","split","hhmmss","toTimeString"],"mappings":"AAAA,OAAO,MAAMA,cAAc;IACzB,MAAMC,MAAM,IAAIC;IAChB,MAAMC,UAAUF,IAAIG,WAAW,GAAGC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,eAAe;;IAC/D,MAAMC,SAASL,IAAIM,YAAY,GAAGF,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa;;IAE7D,OAAO,GAAGF,QAAQ,CAAC,EAAEG,QAAQ;AAC/B,EAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { SelectIncludeType } from 'payload';
|
|
2
|
-
/**
|
|
3
|
-
* Takes an input of array of string paths in dot notation and returns a select object
|
|
4
|
-
* example args: ['id', 'title', 'group.value', 'createdAt', 'updatedAt']
|
|
5
|
-
*/
|
|
6
|
-
export declare const getSelect: (fields: string[]) => SelectIncludeType;
|
|
7
|
-
//# sourceMappingURL=getSelect.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getSelect.d.ts","sourceRoot":"","sources":["../../src/export/getSelect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD;;;GAGG;AACH,eAAO,MAAM,SAAS,WAAY,MAAM,EAAE,KAAG,iBAoB5C,CAAA"}
|
package/dist/export/getSelect.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Takes an input of array of string paths in dot notation and returns a select object
|
|
3
|
-
* example args: ['id', 'title', 'group.value', 'createdAt', 'updatedAt']
|
|
4
|
-
*/ export const getSelect = (fields)=>{
|
|
5
|
-
const select = {};
|
|
6
|
-
fields.forEach((field)=>{
|
|
7
|
-
const segments = field.split('.');
|
|
8
|
-
let selectRef = select;
|
|
9
|
-
segments.forEach((segment, i)=>{
|
|
10
|
-
if (i === segments.length - 1) {
|
|
11
|
-
selectRef[segment] = true;
|
|
12
|
-
} else {
|
|
13
|
-
if (!selectRef[segment]) {
|
|
14
|
-
selectRef[segment] = {};
|
|
15
|
-
}
|
|
16
|
-
selectRef = selectRef[segment];
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
return select;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
//# sourceMappingURL=getSelect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/getSelect.ts"],"sourcesContent":["import type { SelectIncludeType } from 'payload'\n\n/**\n * Takes an input of array of string paths in dot notation and returns a select object\n * example args: ['id', 'title', 'group.value', 'createdAt', 'updatedAt']\n */\nexport const getSelect = (fields: string[]): SelectIncludeType => {\n const select: SelectIncludeType = {}\n\n fields.forEach((field) => {\n const segments = field.split('.')\n let selectRef = select\n\n segments.forEach((segment, i) => {\n if (i === segments.length - 1) {\n selectRef[segment] = true\n } else {\n if (!selectRef[segment]) {\n selectRef[segment] = {}\n }\n selectRef = selectRef[segment] as SelectIncludeType\n }\n })\n })\n\n return select\n}\n"],"names":["getSelect","fields","select","forEach","field","segments","split","selectRef","segment","i","length"],"mappings":"AAEA;;;CAGC,GACD,OAAO,MAAMA,YAAY,CAACC;IACxB,MAAMC,SAA4B,CAAC;IAEnCD,OAAOE,OAAO,CAAC,CAACC;QACd,MAAMC,WAAWD,MAAME,KAAK,CAAC;QAC7B,IAAIC,YAAYL;QAEhBG,SAASF,OAAO,CAAC,CAACK,SAASC;YACzB,IAAIA,MAAMJ,SAASK,MAAM,GAAG,GAAG;gBAC7BH,SAAS,CAACC,QAAQ,GAAG;YACvB,OAAO;gBACL,IAAI,CAACD,SAAS,CAACC,QAAQ,EAAE;oBACvBD,SAAS,CAACC,QAAQ,GAAG,CAAC;gBACxB;gBACAD,YAAYA,SAAS,CAACC,QAAQ;YAChC;QACF;IACF;IAEA,OAAON;AACT,EAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig, Config } from 'payload';
|
|
2
|
-
import type { ImportExportPluginConfig } from './types.js';
|
|
3
|
-
export declare const getExportCollection: ({ config, pluginConfig, }: {
|
|
4
|
-
config: Config;
|
|
5
|
-
pluginConfig: ImportExportPluginConfig;
|
|
6
|
-
}) => CollectionConfig;
|
|
7
|
-
//# sourceMappingURL=getExportCollection.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getExportCollection.d.ts","sourceRoot":"","sources":["../src/getExportCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,MAAM,EACP,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAsB,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAM9E,eAAO,MAAM,mBAAmB,8BAG7B;IACD,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,gBA+EH,CAAA"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { createExport } from './export/createExport.js';
|
|
2
|
-
import { download } from './export/download.js';
|
|
3
|
-
import { getFields } from './export/getFields.js';
|
|
4
|
-
export const getExportCollection = ({ config, pluginConfig })=>{
|
|
5
|
-
const { overrideExportCollection } = pluginConfig;
|
|
6
|
-
const beforeOperation = [];
|
|
7
|
-
const afterChange = [];
|
|
8
|
-
let collection = {
|
|
9
|
-
slug: 'exports',
|
|
10
|
-
access: {
|
|
11
|
-
update: ()=>false
|
|
12
|
-
},
|
|
13
|
-
admin: {
|
|
14
|
-
components: {
|
|
15
|
-
edit: {
|
|
16
|
-
SaveButton: '@payloadcms/plugin-import-export/rsc#ExportSaveButton'
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
custom: {
|
|
20
|
-
disableDownload: pluginConfig.disableDownload ?? false,
|
|
21
|
-
disableSave: pluginConfig.disableSave ?? false
|
|
22
|
-
},
|
|
23
|
-
group: false,
|
|
24
|
-
useAsTitle: 'name'
|
|
25
|
-
},
|
|
26
|
-
disableDuplicate: true,
|
|
27
|
-
endpoints: [
|
|
28
|
-
{
|
|
29
|
-
handler: (req)=>{
|
|
30
|
-
return download(req, pluginConfig.debug);
|
|
31
|
-
},
|
|
32
|
-
method: 'post',
|
|
33
|
-
path: '/download'
|
|
34
|
-
}
|
|
35
|
-
],
|
|
36
|
-
fields: getFields(config, pluginConfig),
|
|
37
|
-
hooks: {
|
|
38
|
-
afterChange,
|
|
39
|
-
beforeOperation
|
|
40
|
-
},
|
|
41
|
-
upload: {
|
|
42
|
-
filesRequiredOnCreate: false,
|
|
43
|
-
hideFileInputOnCreate: true,
|
|
44
|
-
hideRemoveFile: true
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
if (typeof overrideExportCollection === 'function') {
|
|
48
|
-
collection = overrideExportCollection(collection);
|
|
49
|
-
}
|
|
50
|
-
if (pluginConfig.disableJobsQueue) {
|
|
51
|
-
beforeOperation.push(async ({ args, operation, req })=>{
|
|
52
|
-
if (operation !== 'create') {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const { user } = req;
|
|
56
|
-
const debug = pluginConfig.debug;
|
|
57
|
-
await createExport({
|
|
58
|
-
input: {
|
|
59
|
-
...args.data,
|
|
60
|
-
debug
|
|
61
|
-
},
|
|
62
|
-
req,
|
|
63
|
-
user
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
} else {
|
|
67
|
-
afterChange.push(async ({ doc, operation, req })=>{
|
|
68
|
-
if (operation !== 'create') {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const input = {
|
|
72
|
-
...doc,
|
|
73
|
-
exportsCollection: collection.slug,
|
|
74
|
-
user: req?.user?.id || req?.user?.user?.id,
|
|
75
|
-
userCollection: req.payload.config.admin.user
|
|
76
|
-
};
|
|
77
|
-
await req.payload.jobs.queue({
|
|
78
|
-
input,
|
|
79
|
-
task: 'createCollectionExport'
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
return collection;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
//# sourceMappingURL=getExportCollection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/getExportCollection.ts"],"sourcesContent":["import type {\n CollectionAfterChangeHook,\n CollectionBeforeOperationHook,\n CollectionConfig,\n Config,\n} from 'payload'\n\nimport type { CollectionOverride, ImportExportPluginConfig } from './types.js'\n\nimport { createExport } from './export/createExport.js'\nimport { download } from './export/download.js'\nimport { getFields } from './export/getFields.js'\n\nexport const getExportCollection = ({\n config,\n pluginConfig,\n}: {\n config: Config\n pluginConfig: ImportExportPluginConfig\n}): CollectionConfig => {\n const { overrideExportCollection } = pluginConfig\n\n const beforeOperation: CollectionBeforeOperationHook[] = []\n const afterChange: CollectionAfterChangeHook[] = []\n\n let collection: CollectionOverride = {\n slug: 'exports',\n access: {\n update: () => false,\n },\n admin: {\n components: {\n edit: {\n SaveButton: '@payloadcms/plugin-import-export/rsc#ExportSaveButton',\n },\n },\n custom: {\n disableDownload: pluginConfig.disableDownload ?? false,\n disableSave: pluginConfig.disableSave ?? false,\n },\n group: false,\n useAsTitle: 'name',\n },\n disableDuplicate: true,\n endpoints: [\n {\n handler: (req) => {\n return download(req, pluginConfig.debug)\n },\n method: 'post',\n path: '/download',\n },\n ],\n fields: getFields(config, pluginConfig),\n hooks: {\n afterChange,\n beforeOperation,\n },\n upload: {\n filesRequiredOnCreate: false,\n hideFileInputOnCreate: true,\n hideRemoveFile: true,\n },\n }\n\n if (typeof overrideExportCollection === 'function') {\n collection = overrideExportCollection(collection)\n }\n\n if (pluginConfig.disableJobsQueue) {\n beforeOperation.push(async ({ args, operation, req }) => {\n if (operation !== 'create') {\n return\n }\n const { user } = req\n const debug = pluginConfig.debug\n await createExport({ input: { ...args.data, debug } as any, req, user })\n })\n } else {\n afterChange.push(async ({ doc, operation, req }) => {\n if (operation !== 'create') {\n return\n }\n\n const input = {\n ...doc,\n exportsCollection: collection.slug,\n user: req?.user?.id || req?.user?.user?.id,\n userCollection: req.payload.config.admin.user,\n }\n await req.payload.jobs.queue({\n input,\n task: 'createCollectionExport',\n })\n })\n }\n\n return collection\n}\n"],"names":["createExport","download","getFields","getExportCollection","config","pluginConfig","overrideExportCollection","beforeOperation","afterChange","collection","slug","access","update","admin","components","edit","SaveButton","custom","disableDownload","disableSave","group","useAsTitle","disableDuplicate","endpoints","handler","req","debug","method","path","fields","hooks","upload","filesRequiredOnCreate","hideFileInputOnCreate","hideRemoveFile","disableJobsQueue","push","args","operation","user","input","data","doc","exportsCollection","id","userCollection","payload","jobs","queue","task"],"mappings":"AASA,SAASA,YAAY,QAAQ,2BAA0B;AACvD,SAASC,QAAQ,QAAQ,uBAAsB;AAC/C,SAASC,SAAS,QAAQ,wBAAuB;AAEjD,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,MAAM,EACNC,YAAY,EAIb;IACC,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;IAErC,MAAME,kBAAmD,EAAE;IAC3D,MAAMC,cAA2C,EAAE;IAEnD,IAAIC,aAAiC;QACnCC,MAAM;QACNC,QAAQ;YACNC,QA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