@payloadcms/plugin-import-export 3.71.0-internal.ef75fa0 → 3.71.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CollectionField/index.d.ts.map +1 -1
- package/dist/components/CollectionField/index.js +8 -3
- package/dist/components/CollectionField/index.js.map +1 -1
- package/dist/components/ExportListMenuItem/index.d.ts +0 -1
- package/dist/components/ExportListMenuItem/index.d.ts.map +1 -1
- package/dist/components/ExportListMenuItem/index.js +0 -1
- package/dist/components/ExportListMenuItem/index.js.map +1 -1
- package/dist/components/ExportPreview/index.d.ts +4 -0
- package/dist/components/ExportPreview/index.d.ts.map +1 -0
- package/dist/components/ExportPreview/index.js +252 -0
- package/dist/components/ExportPreview/index.js.map +1 -0
- package/dist/components/ExportPreview/index.scss +36 -0
- package/dist/components/ImportCollectionField/index.d.ts +3 -0
- package/dist/components/ImportCollectionField/index.d.ts.map +1 -0
- package/dist/components/ImportCollectionField/index.js +17 -0
- package/dist/components/ImportCollectionField/index.js.map +1 -0
- package/dist/components/ImportListMenuItem/index.d.ts +6 -0
- package/dist/components/ImportListMenuItem/index.d.ts.map +1 -0
- package/dist/components/ImportListMenuItem/index.js +48 -0
- package/dist/components/ImportListMenuItem/index.js.map +1 -0
- package/dist/components/ImportPreview/index.d.ts +4 -0
- package/dist/components/ImportPreview/index.d.ts.map +1 -0
- package/dist/components/ImportPreview/index.js +624 -0
- package/dist/components/ImportPreview/index.js.map +1 -0
- package/dist/components/ImportPreview/index.scss +41 -0
- package/dist/components/ImportSaveButton/index.d.ts +2 -0
- package/dist/components/ImportSaveButton/index.d.ts.map +1 -0
- package/dist/components/ImportSaveButton/index.js +18 -0
- package/dist/components/ImportSaveButton/index.js.map +1 -0
- package/dist/components/Page/index.scss +4 -2
- package/dist/constants.d.ts +21 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +21 -0
- package/dist/constants.js.map +1 -0
- package/dist/export/batchProcessor.d.ts +107 -0
- package/dist/export/batchProcessor.d.ts.map +1 -0
- package/dist/export/batchProcessor.js +187 -0
- package/dist/export/batchProcessor.js.map +1 -0
- package/dist/export/createExport.d.ts +9 -4
- package/dist/export/createExport.d.ts.map +1 -1
- package/dist/export/createExport.js +163 -111
- package/dist/export/createExport.js.map +1 -1
- package/dist/export/getCreateExportCollectionTask.d.ts +1 -2
- package/dist/export/getCreateExportCollectionTask.d.ts.map +1 -1
- package/dist/export/getCreateExportCollectionTask.js +10 -18
- package/dist/export/getCreateExportCollectionTask.js.map +1 -1
- package/dist/export/getExportCollection.d.ts +8 -0
- package/dist/export/getExportCollection.d.ts.map +1 -0
- package/dist/export/getExportCollection.js +100 -0
- package/dist/export/getExportCollection.js.map +1 -0
- package/dist/export/getFields.d.ts +8 -2
- package/dist/export/getFields.d.ts.map +1 -1
- package/dist/export/getFields.js +7 -9
- package/dist/export/getFields.js.map +1 -1
- package/dist/export/handleDownload.d.ts +3 -0
- package/dist/export/handleDownload.d.ts.map +1 -0
- package/dist/export/handleDownload.js +42 -0
- package/dist/export/handleDownload.js.map +1 -0
- package/dist/export/handlePreview.d.ts +3 -0
- package/dist/export/handlePreview.d.ts.map +1 -0
- package/dist/export/handlePreview.js +163 -0
- package/dist/export/handlePreview.js.map +1 -0
- package/dist/exports/rsc.d.ts +5 -1
- package/dist/exports/rsc.d.ts.map +1 -1
- package/dist/exports/rsc.js +5 -1
- package/dist/exports/rsc.js.map +1 -1
- package/dist/import/batchProcessor.d.ts +46 -0
- package/dist/import/batchProcessor.d.ts.map +1 -0
- package/dist/import/batchProcessor.js +529 -0
- package/dist/import/batchProcessor.js.map +1 -0
- package/dist/import/createImport.d.ts +45 -0
- package/dist/import/createImport.d.ts.map +1 -0
- package/dist/import/createImport.js +175 -0
- package/dist/import/createImport.js.map +1 -0
- package/dist/import/getCreateImportCollectionTask.d.ts +13 -0
- package/dist/import/getCreateImportCollectionTask.d.ts.map +1 -0
- package/dist/import/getCreateImportCollectionTask.js +81 -0
- package/dist/import/getCreateImportCollectionTask.js.map +1 -0
- package/dist/import/getFields.d.ts +7 -0
- package/dist/import/getFields.d.ts.map +1 -0
- package/dist/import/getFields.js +150 -0
- package/dist/import/getFields.js.map +1 -0
- package/dist/import/getImportCollection.d.ts +8 -0
- package/dist/import/getImportCollection.d.ts.map +1 -0
- package/dist/import/getImportCollection.js +258 -0
- package/dist/import/getImportCollection.js.map +1 -0
- package/dist/import/handlePreview.d.ts +3 -0
- package/dist/import/handlePreview.d.ts.map +1 -0
- package/dist/import/handlePreview.js +94 -0
- package/dist/import/handlePreview.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +68 -110
- package/dist/index.js.map +1 -1
- package/dist/translations/languages/ar.d.ts.map +1 -1
- package/dist/translations/languages/ar.js +21 -1
- package/dist/translations/languages/ar.js.map +1 -1
- package/dist/translations/languages/az.d.ts.map +1 -1
- package/dist/translations/languages/az.js +21 -1
- package/dist/translations/languages/az.js.map +1 -1
- package/dist/translations/languages/bg.d.ts.map +1 -1
- package/dist/translations/languages/bg.js +21 -1
- package/dist/translations/languages/bg.js.map +1 -1
- package/dist/translations/languages/bnBd.d.ts +4 -0
- package/dist/translations/languages/bnBd.d.ts.map +1 -0
- package/dist/translations/languages/bnBd.js +48 -0
- package/dist/translations/languages/bnBd.js.map +1 -0
- package/dist/translations/languages/bnIn.d.ts +4 -0
- package/dist/translations/languages/bnIn.d.ts.map +1 -0
- package/dist/translations/languages/bnIn.js +48 -0
- package/dist/translations/languages/bnIn.js.map +1 -0
- package/dist/translations/languages/ca.d.ts.map +1 -1
- package/dist/translations/languages/ca.js +21 -1
- package/dist/translations/languages/ca.js.map +1 -1
- package/dist/translations/languages/cs.d.ts.map +1 -1
- package/dist/translations/languages/cs.js +21 -1
- package/dist/translations/languages/cs.js.map +1 -1
- package/dist/translations/languages/da.d.ts.map +1 -1
- package/dist/translations/languages/da.js +21 -1
- package/dist/translations/languages/da.js.map +1 -1
- package/dist/translations/languages/de.d.ts.map +1 -1
- package/dist/translations/languages/de.js +21 -1
- package/dist/translations/languages/de.js.map +1 -1
- package/dist/translations/languages/en.d.ts +20 -0
- package/dist/translations/languages/en.d.ts.map +1 -1
- package/dist/translations/languages/en.js +21 -1
- package/dist/translations/languages/en.js.map +1 -1
- package/dist/translations/languages/es.d.ts.map +1 -1
- package/dist/translations/languages/es.js +21 -1
- package/dist/translations/languages/es.js.map +1 -1
- package/dist/translations/languages/et.d.ts.map +1 -1
- package/dist/translations/languages/et.js +21 -1
- package/dist/translations/languages/et.js.map +1 -1
- package/dist/translations/languages/fa.d.ts.map +1 -1
- package/dist/translations/languages/fa.js +21 -1
- package/dist/translations/languages/fa.js.map +1 -1
- package/dist/translations/languages/fr.d.ts.map +1 -1
- package/dist/translations/languages/fr.js +21 -1
- package/dist/translations/languages/fr.js.map +1 -1
- package/dist/translations/languages/he.d.ts.map +1 -1
- package/dist/translations/languages/he.js +21 -1
- package/dist/translations/languages/he.js.map +1 -1
- package/dist/translations/languages/hr.d.ts.map +1 -1
- package/dist/translations/languages/hr.js +21 -1
- package/dist/translations/languages/hr.js.map +1 -1
- package/dist/translations/languages/hu.d.ts.map +1 -1
- package/dist/translations/languages/hu.js +21 -1
- package/dist/translations/languages/hu.js.map +1 -1
- package/dist/translations/languages/hy.d.ts.map +1 -1
- package/dist/translations/languages/hy.js +21 -1
- package/dist/translations/languages/hy.js.map +1 -1
- package/dist/translations/languages/id.d.ts +4 -0
- package/dist/translations/languages/id.d.ts.map +1 -0
- package/dist/translations/languages/id.js +48 -0
- package/dist/translations/languages/id.js.map +1 -0
- package/dist/translations/languages/is.d.ts.map +1 -1
- package/dist/translations/languages/is.js +21 -1
- package/dist/translations/languages/is.js.map +1 -1
- package/dist/translations/languages/it.d.ts.map +1 -1
- package/dist/translations/languages/it.js +21 -1
- package/dist/translations/languages/it.js.map +1 -1
- package/dist/translations/languages/ja.d.ts.map +1 -1
- package/dist/translations/languages/ja.js +21 -1
- package/dist/translations/languages/ja.js.map +1 -1
- package/dist/translations/languages/ko.d.ts.map +1 -1
- package/dist/translations/languages/ko.js +21 -1
- package/dist/translations/languages/ko.js.map +1 -1
- package/dist/translations/languages/lt.d.ts.map +1 -1
- package/dist/translations/languages/lt.js +21 -1
- package/dist/translations/languages/lt.js.map +1 -1
- package/dist/translations/languages/lv.d.ts.map +1 -1
- package/dist/translations/languages/lv.js +26 -6
- package/dist/translations/languages/lv.js.map +1 -1
- package/dist/translations/languages/my.d.ts.map +1 -1
- package/dist/translations/languages/my.js +21 -1
- package/dist/translations/languages/my.js.map +1 -1
- package/dist/translations/languages/nb.d.ts.map +1 -1
- package/dist/translations/languages/nb.js +21 -1
- package/dist/translations/languages/nb.js.map +1 -1
- package/dist/translations/languages/nl.d.ts.map +1 -1
- package/dist/translations/languages/nl.js +21 -1
- package/dist/translations/languages/nl.js.map +1 -1
- package/dist/translations/languages/pl.d.ts.map +1 -1
- package/dist/translations/languages/pl.js +21 -1
- package/dist/translations/languages/pl.js.map +1 -1
- package/dist/translations/languages/pt.d.ts.map +1 -1
- package/dist/translations/languages/pt.js +21 -1
- package/dist/translations/languages/pt.js.map +1 -1
- package/dist/translations/languages/ro.d.ts.map +1 -1
- package/dist/translations/languages/ro.js +21 -1
- package/dist/translations/languages/ro.js.map +1 -1
- package/dist/translations/languages/rs.d.ts.map +1 -1
- package/dist/translations/languages/rs.js +21 -1
- package/dist/translations/languages/rs.js.map +1 -1
- package/dist/translations/languages/rsLatin.d.ts.map +1 -1
- package/dist/translations/languages/rsLatin.js +21 -1
- package/dist/translations/languages/rsLatin.js.map +1 -1
- package/dist/translations/languages/ru.d.ts.map +1 -1
- package/dist/translations/languages/ru.js +21 -1
- package/dist/translations/languages/ru.js.map +1 -1
- package/dist/translations/languages/sk.d.ts.map +1 -1
- package/dist/translations/languages/sk.js +21 -1
- package/dist/translations/languages/sk.js.map +1 -1
- package/dist/translations/languages/sl.d.ts.map +1 -1
- package/dist/translations/languages/sl.js +21 -1
- package/dist/translations/languages/sl.js.map +1 -1
- package/dist/translations/languages/sv.d.ts.map +1 -1
- package/dist/translations/languages/sv.js +21 -1
- package/dist/translations/languages/sv.js.map +1 -1
- package/dist/translations/languages/ta.d.ts.map +1 -1
- package/dist/translations/languages/ta.js +21 -1
- package/dist/translations/languages/ta.js.map +1 -1
- package/dist/translations/languages/th.d.ts.map +1 -1
- package/dist/translations/languages/th.js +21 -1
- package/dist/translations/languages/th.js.map +1 -1
- package/dist/translations/languages/tr.d.ts.map +1 -1
- package/dist/translations/languages/tr.js +21 -1
- package/dist/translations/languages/tr.js.map +1 -1
- package/dist/translations/languages/uk.d.ts.map +1 -1
- package/dist/translations/languages/uk.js +21 -1
- package/dist/translations/languages/uk.js.map +1 -1
- package/dist/translations/languages/vi.d.ts.map +1 -1
- package/dist/translations/languages/vi.js +21 -1
- package/dist/translations/languages/vi.js.map +1 -1
- package/dist/translations/languages/zh.d.ts.map +1 -1
- package/dist/translations/languages/zh.js +21 -1
- package/dist/translations/languages/zh.js.map +1 -1
- package/dist/translations/languages/zhTw.d.ts.map +1 -1
- package/dist/translations/languages/zhTw.js +21 -1
- package/dist/translations/languages/zhTw.js.map +1 -1
- package/dist/translations/types.d.ts +13 -0
- package/dist/translations/types.d.ts.map +1 -1
- package/dist/translations/types.js.map +1 -1
- package/dist/types.d.ts +166 -22
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/flattenObject.d.ts +11 -0
- package/dist/utilities/flattenObject.d.ts.map +1 -0
- package/dist/utilities/flattenObject.js +129 -0
- package/dist/utilities/flattenObject.js.map +1 -0
- package/dist/utilities/getExportFieldFunctions.d.ts +12 -0
- package/dist/utilities/getExportFieldFunctions.d.ts.map +1 -0
- package/dist/utilities/getExportFieldFunctions.js +102 -0
- package/dist/utilities/getExportFieldFunctions.js.map +1 -0
- package/dist/utilities/getFilename.d.ts +6 -0
- package/dist/utilities/getFilename.d.ts.map +1 -0
- package/dist/utilities/getFilename.js +13 -0
- package/dist/utilities/getFilename.js.map +1 -0
- package/dist/utilities/getFlattenedFieldKeys.d.ts +12 -1
- package/dist/utilities/getFlattenedFieldKeys.d.ts.map +1 -1
- package/dist/utilities/getFlattenedFieldKeys.js +35 -10
- package/dist/utilities/getFlattenedFieldKeys.js.map +1 -1
- package/dist/utilities/getImportFieldFunctions.d.ts +12 -0
- package/dist/utilities/getImportFieldFunctions.d.ts.map +1 -0
- package/dist/utilities/getImportFieldFunctions.js +130 -0
- package/dist/utilities/getImportFieldFunctions.js.map +1 -0
- package/dist/utilities/getPluginCollections.d.ts +39 -0
- package/dist/utilities/getPluginCollections.d.ts.map +1 -0
- package/dist/utilities/getPluginCollections.js +102 -0
- package/dist/utilities/getPluginCollections.js.map +1 -0
- package/dist/utilities/getSchemaColumns.d.ts +43 -0
- package/dist/utilities/getSchemaColumns.d.ts.map +1 -0
- package/dist/utilities/getSchemaColumns.js +163 -0
- package/dist/utilities/getSchemaColumns.js.map +1 -0
- package/dist/utilities/getSelect.d.ts +11 -0
- package/dist/utilities/getSelect.d.ts.map +1 -0
- package/dist/utilities/getSelect.js +27 -0
- package/dist/utilities/getSelect.js.map +1 -0
- package/dist/utilities/parseCSV.d.ts +11 -0
- package/dist/utilities/parseCSV.d.ts.map +1 -0
- package/dist/utilities/parseCSV.js +67 -0
- package/dist/utilities/parseCSV.js.map +1 -0
- package/dist/utilities/parseCSV.spec.js +169 -0
- package/dist/utilities/parseCSV.spec.js.map +1 -0
- package/dist/utilities/parseJSON.d.ts +11 -0
- package/dist/utilities/parseJSON.d.ts.map +1 -0
- package/dist/utilities/parseJSON.js +25 -0
- package/dist/utilities/parseJSON.js.map +1 -0
- package/dist/utilities/processRichTextField.d.ts +6 -0
- package/dist/utilities/processRichTextField.d.ts.map +1 -0
- package/dist/utilities/processRichTextField.js +45 -0
- package/dist/utilities/processRichTextField.js.map +1 -0
- package/dist/utilities/unflattenObject.d.ts +11 -0
- package/dist/utilities/unflattenObject.d.ts.map +1 -0
- package/dist/utilities/unflattenObject.js +431 -0
- package/dist/utilities/unflattenObject.js.map +1 -0
- package/dist/utilities/unflattenObject.spec.js +680 -0
- package/dist/utilities/unflattenObject.spec.js.map +1 -0
- package/dist/utilities/useBatchProcessor.d.ts +103 -0
- package/dist/utilities/useBatchProcessor.d.ts.map +1 -0
- package/dist/utilities/useBatchProcessor.js +88 -0
- package/dist/utilities/useBatchProcessor.js.map +1 -0
- package/dist/utilities/validateLimitValue.d.ts +1 -1
- package/dist/utilities/validateLimitValue.d.ts.map +1 -1
- package/dist/utilities/validateLimitValue.js +1 -4
- package/dist/utilities/validateLimitValue.js.map +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { APIError } from 'payload';
|
|
2
|
+
import { getImportFieldFunctions } from '../utilities/getImportFieldFunctions.js';
|
|
3
|
+
import { parseCSV } from '../utilities/parseCSV.js';
|
|
4
|
+
import { parseJSON } from '../utilities/parseJSON.js';
|
|
5
|
+
import { removeDisabledFields } from '../utilities/removeDisabledFields.js';
|
|
6
|
+
import { unflattenObject } from '../utilities/unflattenObject.js';
|
|
7
|
+
import { createImportBatchProcessor } from './batchProcessor.js';
|
|
8
|
+
export const createImport = async ({ batchSize = 100, collectionSlug, debug = false, defaultVersionStatus = 'published', file, format, importMode = 'create', matchField = 'id', req, userCollection, userID })=>{
|
|
9
|
+
let user;
|
|
10
|
+
if (userCollection && userID) {
|
|
11
|
+
user = await req.payload.findByID({
|
|
12
|
+
id: userID,
|
|
13
|
+
collection: userCollection
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (!user) {
|
|
17
|
+
throw new APIError('User is required for import operations', 401, null, true);
|
|
18
|
+
}
|
|
19
|
+
if (debug) {
|
|
20
|
+
req.payload.logger.debug({
|
|
21
|
+
collectionSlug,
|
|
22
|
+
format,
|
|
23
|
+
importMode,
|
|
24
|
+
matchField,
|
|
25
|
+
message: 'Starting import process with args:',
|
|
26
|
+
transactionID: req.transactionID
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (!collectionSlug) {
|
|
30
|
+
throw new APIError('Collection slug is required', 400, null, true);
|
|
31
|
+
}
|
|
32
|
+
if (!file || !file?.data) {
|
|
33
|
+
throw new APIError('No file data provided for import', 400, null, true);
|
|
34
|
+
}
|
|
35
|
+
if (debug) {
|
|
36
|
+
req.payload.logger.debug({
|
|
37
|
+
fileName: file.name,
|
|
38
|
+
fileSize: file.data.length,
|
|
39
|
+
message: 'File info',
|
|
40
|
+
mimeType: file.mimetype
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const collectionConfig = req.payload.config.collections.find(({ slug })=>slug === collectionSlug);
|
|
44
|
+
if (!collectionConfig) {
|
|
45
|
+
if (!collectionSlug) {
|
|
46
|
+
throw new APIError('Collection slug is required', 400, null, true);
|
|
47
|
+
}
|
|
48
|
+
throw new APIError(`Collection with slug ${collectionSlug} not found`, 400, null, true);
|
|
49
|
+
}
|
|
50
|
+
// Get disabled fields configuration
|
|
51
|
+
const disabledFields = collectionConfig.admin?.custom?.['plugin-import-export']?.disabledFields ?? [];
|
|
52
|
+
// Get fromCSV functions for field transformations
|
|
53
|
+
const fromCSVFunctions = getImportFieldFunctions({
|
|
54
|
+
fields: collectionConfig.flattenedFields || []
|
|
55
|
+
});
|
|
56
|
+
// Parse the file data
|
|
57
|
+
let documents;
|
|
58
|
+
if (format === 'csv') {
|
|
59
|
+
const rawData = await parseCSV({
|
|
60
|
+
data: file.data,
|
|
61
|
+
req
|
|
62
|
+
});
|
|
63
|
+
// Debug logging
|
|
64
|
+
if (debug && rawData.length > 0) {
|
|
65
|
+
req.payload.logger.info({
|
|
66
|
+
firstRow: rawData[0],
|
|
67
|
+
msg: 'Parsed CSV data - FULL'
|
|
68
|
+
});
|
|
69
|
+
req.payload.logger.info({
|
|
70
|
+
msg: 'Parsed CSV data',
|
|
71
|
+
rows: rawData.map((row, i)=>({
|
|
72
|
+
excerpt: row.excerpt,
|
|
73
|
+
hasManyNumber: row.hasManyNumber,
|
|
74
|
+
hasOnePolymorphic_id: row.hasOnePolymorphic_id,
|
|
75
|
+
hasOnePolymorphic_relationTo: row.hasOnePolymorphic_relationTo,
|
|
76
|
+
index: i,
|
|
77
|
+
title: row.title
|
|
78
|
+
}))
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
documents = rawData;
|
|
82
|
+
// Unflatten CSV data
|
|
83
|
+
documents = documents.map((doc)=>{
|
|
84
|
+
const unflattened = unflattenObject({
|
|
85
|
+
data: doc,
|
|
86
|
+
fields: collectionConfig.flattenedFields ?? [],
|
|
87
|
+
fromCSVFunctions,
|
|
88
|
+
req
|
|
89
|
+
});
|
|
90
|
+
return unflattened ?? {};
|
|
91
|
+
}).filter((doc)=>doc && Object.keys(doc).length > 0);
|
|
92
|
+
// Debug after unflatten
|
|
93
|
+
if (debug && documents.length > 0) {
|
|
94
|
+
req.payload.logger.info({
|
|
95
|
+
msg: 'After unflatten',
|
|
96
|
+
rows: documents.map((row, i)=>({
|
|
97
|
+
hasManyNumber: row.hasManyNumber,
|
|
98
|
+
hasManyPolymorphic: row.hasManyPolymorphic,
|
|
99
|
+
hasOnePolymorphic: row.hasOnePolymorphic,
|
|
100
|
+
hasTitle: 'title' in row,
|
|
101
|
+
index: i,
|
|
102
|
+
title: row.title
|
|
103
|
+
}))
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (debug) {
|
|
107
|
+
req.payload.logger.debug({
|
|
108
|
+
documentCount: documents.length,
|
|
109
|
+
message: 'After unflattening CSV',
|
|
110
|
+
rawDataCount: rawData.length
|
|
111
|
+
});
|
|
112
|
+
// Debug: show a sample of raw vs unflattened
|
|
113
|
+
if (rawData.length > 0 && documents.length > 0) {
|
|
114
|
+
req.payload.logger.debug({
|
|
115
|
+
message: 'Sample data transformation',
|
|
116
|
+
raw: Object.keys(rawData[0] || {}).filter((k)=>k.includes('localized')),
|
|
117
|
+
unflattened: JSON.stringify(documents[0], null, 2)
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
documents = parseJSON({
|
|
123
|
+
data: file.data,
|
|
124
|
+
req
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
if (debug) {
|
|
128
|
+
req.payload.logger.debug({
|
|
129
|
+
message: `Parsed ${documents.length} documents from ${format} file`
|
|
130
|
+
});
|
|
131
|
+
if (documents.length > 0) {
|
|
132
|
+
req.payload.logger.debug({
|
|
133
|
+
doc: documents[0],
|
|
134
|
+
message: 'First document sample:'
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Remove disabled fields from all documents
|
|
139
|
+
if (disabledFields.length > 0) {
|
|
140
|
+
documents = documents.map((doc)=>removeDisabledFields(doc, disabledFields));
|
|
141
|
+
}
|
|
142
|
+
if (debug) {
|
|
143
|
+
req.payload.logger.debug({
|
|
144
|
+
batchSize,
|
|
145
|
+
documentCount: documents.length,
|
|
146
|
+
message: 'Processing import in batches'
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
// Create batch processor
|
|
150
|
+
const processor = createImportBatchProcessor({
|
|
151
|
+
batchSize,
|
|
152
|
+
defaultVersionStatus
|
|
153
|
+
});
|
|
154
|
+
// Process import with batch processor
|
|
155
|
+
const result = await processor.processImport({
|
|
156
|
+
collectionSlug,
|
|
157
|
+
documents,
|
|
158
|
+
importMode,
|
|
159
|
+
matchField,
|
|
160
|
+
req,
|
|
161
|
+
user
|
|
162
|
+
});
|
|
163
|
+
if (debug) {
|
|
164
|
+
req.payload.logger.info({
|
|
165
|
+
errors: result.errors.length,
|
|
166
|
+
imported: result.imported,
|
|
167
|
+
message: 'Import completed',
|
|
168
|
+
total: result.total,
|
|
169
|
+
updated: result.updated
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=createImport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/import/createImport.ts"],"sourcesContent":["import type { PayloadRequest, TypedUser } from 'payload'\n\nimport { APIError } from 'payload'\n\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 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 type ImportResult = {\n errors: Array<{\n doc: Record<string, unknown>\n error: string\n index: number\n }>\n imported: number\n total: number\n updated: number\n}\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 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 })) 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 message: '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 message: 'File info',\n mimeType: file.mimetype,\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 // Get fromCSV functions for field transformations\n const fromCSVFunctions = getImportFieldFunctions({\n fields: collectionConfig.flattenedFields || [],\n })\n\n // Parse the file data\n let documents: Record<string, unknown>[]\n if (format === 'csv') {\n const rawData = await parseCSV({\n data: file.data,\n req,\n })\n\n // Debug logging\n if (debug && rawData.length > 0) {\n req.payload.logger.info({\n firstRow: rawData[0], // Show the complete first row\n msg: 'Parsed CSV data - FULL',\n })\n req.payload.logger.info({\n msg: 'Parsed CSV data',\n rows: rawData.map((row, i) => ({\n excerpt: row.excerpt,\n hasManyNumber: row.hasManyNumber, // Add this to see what we get from CSV\n hasOnePolymorphic_id: row.hasOnePolymorphic_id,\n hasOnePolymorphic_relationTo: row.hasOnePolymorphic_relationTo,\n index: i,\n title: row.title,\n })),\n })\n }\n\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 fromCSVFunctions,\n req,\n })\n return unflattened ?? {}\n })\n .filter((doc) => doc && Object.keys(doc).length > 0)\n\n // Debug after unflatten\n if (debug && documents.length > 0) {\n req.payload.logger.info({\n msg: 'After unflatten',\n rows: documents.map((row, i) => ({\n hasManyNumber: row.hasManyNumber, // Add this to see the actual value\n hasManyPolymorphic: row.hasManyPolymorphic,\n hasOnePolymorphic: row.hasOnePolymorphic,\n hasTitle: 'title' in row,\n index: i,\n title: row.title,\n })),\n })\n }\n\n if (debug) {\n req.payload.logger.debug({\n documentCount: documents.length,\n message: 'After unflattening CSV',\n rawDataCount: rawData.length,\n })\n\n // Debug: show a sample of raw vs unflattened\n if (rawData.length > 0 && documents.length > 0) {\n req.payload.logger.debug({\n message: 'Sample data transformation',\n raw: Object.keys(rawData[0] || {}).filter((k) => k.includes('localized')),\n unflattened: JSON.stringify(documents[0], null, 2),\n })\n }\n }\n } else {\n documents = parseJSON({ data: file.data, req })\n }\n\n if (debug) {\n req.payload.logger.debug({\n message: `Parsed ${documents.length} documents from ${format} file`,\n })\n if (documents.length > 0) {\n req.payload.logger.debug({\n doc: documents[0],\n message: 'First document sample:',\n })\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 message: 'Processing import in batches',\n })\n }\n\n // Create batch processor\n const processor = createImportBatchProcessor({\n batchSize,\n defaultVersionStatus,\n })\n\n // Process import with batch processor\n const result = await processor.processImport({\n collectionSlug,\n documents,\n importMode,\n matchField,\n req,\n user,\n })\n\n if (debug) {\n req.payload.logger.info({\n errors: result.errors.length,\n imported: result.imported,\n message: 'Import completed',\n total: result.total,\n updated: result.updated,\n })\n }\n\n return result\n}\n"],"names":["APIError","getImportFieldFunctions","parseCSV","parseJSON","removeDisabledFields","unflattenObject","createImportBatchProcessor","createImport","batchSize","collectionSlug","debug","defaultVersionStatus","file","format","importMode","matchField","req","userCollection","userID","user","payload","findByID","id","collection","logger","message","transactionID","data","fileName","name","fileSize","length","mimeType","mimetype","collectionConfig","config","collections","find","slug","disabledFields","admin","custom","fromCSVFunctions","fields","flattenedFields","documents","rawData","info","firstRow","msg","rows","map","row","i","excerpt","hasManyNumber","hasOnePolymorphic_id","hasOnePolymorphic_relationTo","index","title","doc","unflattened","filter","Object","keys","hasManyPolymorphic","hasOnePolymorphic","hasTitle","documentCount","rawDataCount","raw","k","includes","JSON","stringify","processor","result","processImport","errors","imported","total","updated"],"mappings":"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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Config, TaskConfig } from 'payload';
|
|
2
|
+
import type { Import } from './createImport.js';
|
|
3
|
+
export type ImportTaskInput = {
|
|
4
|
+
defaultVersionStatus?: 'draft' | 'published';
|
|
5
|
+
importId?: string;
|
|
6
|
+
importsCollection?: string;
|
|
7
|
+
user?: string;
|
|
8
|
+
} & Import;
|
|
9
|
+
export declare const getCreateCollectionImportTask: (config: Config) => TaskConfig<{
|
|
10
|
+
input: ImportTaskInput;
|
|
11
|
+
output: object;
|
|
12
|
+
}>;
|
|
13
|
+
//# sourceMappingURL=getCreateImportCollectionTask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCreateImportCollectionTask.d.ts","sourceRoot":"","sources":["../../src/import/getCreateImportCollectionTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAa,MAAM,SAAS,CAAA;AAE5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAK/C,MAAM,MAAM,eAAe,GAAG;IAC5B,oBAAoB,CAAC,EAAE,OAAO,GAAG,WAAW,CAAA;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,GAAG,MAAM,CAAA;AAEV,eAAO,MAAM,6BAA6B,WAChC,MAAM,KACb,UAAU,CAAC;IACZ,KAAK,EAAE,eAAe,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;CACf,CA4FA,CAAA"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { createImport } from './createImport.js';
|
|
2
|
+
import { getFields } from './getFields.js';
|
|
3
|
+
export const getCreateCollectionImportTask = (config)=>{
|
|
4
|
+
const inputSchema = getFields(config).concat({
|
|
5
|
+
name: 'user',
|
|
6
|
+
type: 'text'
|
|
7
|
+
}, {
|
|
8
|
+
name: 'userCollection',
|
|
9
|
+
type: 'text'
|
|
10
|
+
}, {
|
|
11
|
+
name: 'importsCollection',
|
|
12
|
+
type: 'text'
|
|
13
|
+
}, {
|
|
14
|
+
name: 'file',
|
|
15
|
+
type: 'group',
|
|
16
|
+
fields: [
|
|
17
|
+
{
|
|
18
|
+
name: 'data',
|
|
19
|
+
type: 'text'
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'mimetype',
|
|
23
|
+
type: 'text'
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'name',
|
|
27
|
+
type: 'text'
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}, {
|
|
31
|
+
name: 'format',
|
|
32
|
+
type: 'select',
|
|
33
|
+
options: [
|
|
34
|
+
'csv',
|
|
35
|
+
'json'
|
|
36
|
+
]
|
|
37
|
+
}, {
|
|
38
|
+
name: 'debug',
|
|
39
|
+
type: 'checkbox'
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
slug: 'createCollectionImport',
|
|
43
|
+
handler: async ({ input, req })=>{
|
|
44
|
+
// Convert file data back to Buffer if it was serialized
|
|
45
|
+
if (input.file && typeof input.file.data === 'string') {
|
|
46
|
+
input.file.data = Buffer.from(input.file.data, 'base64');
|
|
47
|
+
}
|
|
48
|
+
const result = await createImport({
|
|
49
|
+
...input,
|
|
50
|
+
req
|
|
51
|
+
});
|
|
52
|
+
// Update the import document with results if importId is provided
|
|
53
|
+
if (input.importId) {
|
|
54
|
+
await req.payload.update({
|
|
55
|
+
id: input.importId,
|
|
56
|
+
collection: input.importsCollection || 'imports',
|
|
57
|
+
data: {
|
|
58
|
+
status: result.errors.length === 0 ? 'completed' : result.imported + result.updated === 0 ? 'failed' : 'partial',
|
|
59
|
+
summary: {
|
|
60
|
+
imported: result.imported,
|
|
61
|
+
issueDetails: result.errors.length > 0 ? result.errors.map((e)=>({
|
|
62
|
+
data: e.doc,
|
|
63
|
+
error: e.error,
|
|
64
|
+
row: e.index + 1
|
|
65
|
+
})) : undefined,
|
|
66
|
+
issues: result.errors.length,
|
|
67
|
+
total: result.total,
|
|
68
|
+
updated: result.updated
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
output: result
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
inputSchema
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=getCreateImportCollectionTask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/import/getCreateImportCollectionTask.ts"],"sourcesContent":["import type { Config, TaskConfig, TypedUser } from 'payload'\n\nimport type { Import } from './createImport.js'\n\nimport { createImport } from './createImport.js'\nimport { getFields } from './getFields.js'\n\nexport type ImportTaskInput = {\n defaultVersionStatus?: 'draft' | 'published'\n importId?: string\n importsCollection?: string\n user?: string\n} & Import\n\nexport const getCreateCollectionImportTask = (\n config: Config,\n): TaskConfig<{\n input: ImportTaskInput\n output: object\n}> => {\n const inputSchema = getFields(config).concat(\n {\n name: 'user',\n type: 'text',\n },\n {\n name: 'userCollection',\n type: 'text',\n },\n {\n name: 'importsCollection',\n type: 'text',\n },\n {\n name: 'file',\n type: 'group',\n fields: [\n {\n name: 'data',\n type: 'text',\n },\n {\n name: 'mimetype',\n type: 'text',\n },\n {\n name: 'name',\n type: 'text',\n },\n ],\n },\n {\n name: 'format',\n type: 'select',\n options: ['csv', 'json'],\n },\n {\n name: 'debug',\n type: 'checkbox',\n },\n )\n\n return {\n slug: 'createCollectionImport',\n handler: async ({ input, req }) => {\n // Convert file data back to Buffer if it was serialized\n if (input.file && typeof input.file.data === 'string') {\n input.file.data = Buffer.from(input.file.data, 'base64')\n }\n\n const result = await createImport({\n ...input,\n req,\n })\n\n // Update the import document with results if importId is provided\n if (input.importId) {\n await req.payload.update({\n id: input.importId,\n collection: input.importsCollection || 'imports',\n data: {\n status:\n result.errors.length === 0\n ? 'completed'\n : result.imported + result.updated === 0\n ? 'failed'\n : 'partial',\n summary: {\n imported: result.imported,\n issueDetails:\n result.errors.length > 0\n ? result.errors.map((e) => ({\n data: e.doc,\n error: e.error,\n row: e.index + 1,\n }))\n : undefined,\n issues: result.errors.length,\n total: result.total,\n updated: result.updated,\n },\n },\n })\n }\n\n return {\n output: result,\n }\n },\n inputSchema,\n }\n}\n"],"names":["createImport","getFields","getCreateCollectionImportTask","config","inputSchema","concat","name","type","fields","options","slug","handler","input","req","file","data","Buffer","from","result","importId","payload","update","id","collection","importsCollection","status","errors","length","imported","updated","summary","issueDetails","map","e","doc","error","row","index","undefined","issues","total","output"],"mappings":"AAIA,SAASA,YAAY,QAAQ,oBAAmB;AAChD,SAASC,SAAS,QAAQ,iBAAgB;AAS1C,OAAO,MAAMC,gCAAgC,CAC3CC;IAKA,MAAMC,cAAcH,UAAUE,QAAQE,MAAM,CAC1C;QACEC,MAAM;QACNC,MAAM;IACR,GACA;QACED,MAAM;QACNC,MAAM;IACR,GACA;QACED,MAAM;QACNC,MAAM;IACR,GACA;QACED,MAAM;QACNC,MAAM;QACNC,QAAQ;YACN;gBACEF,MAAM;gBACNC,MAAM;YACR;YACA;gBACED,MAAM;gBACNC,MAAM;YACR;YACA;gBACED,MAAM;gBACNC,MAAM;YACR;SACD;IACH,GACA;QACED,MAAM;QACNC,MAAM;QACNE,SAAS;YAAC;YAAO;SAAO;IAC1B,GACA;QACEH,MAAM;QACNC,MAAM;IACR;IAGF,OAAO;QACLG,MAAM;QACNC,SAAS,OAAO,EAAEC,KAAK,EAAEC,GAAG,EAAE;YAC5B,wDAAwD;YACxD,IAAID,MAAME,IAAI,IAAI,OAAOF,MAAME,IAAI,CAACC,IAAI,KAAK,UAAU;gBACrDH,MAAME,IAAI,CAACC,IAAI,GAAGC,OAAOC,IAAI,CAACL,MAAME,IAAI,CAACC,IAAI,EAAE;YACjD;YAEA,MAAMG,SAAS,MAAMlB,aAAa;gBAChC,GAAGY,KAAK;gBACRC;YACF;YAEA,kEAAkE;YAClE,IAAID,MAAMO,QAAQ,EAAE;gBAClB,MAAMN,IAAIO,OAAO,CAACC,MAAM,CAAC;oBACvBC,IAAIV,MAAMO,QAAQ;oBAClBI,YAAYX,MAAMY,iBAAiB,IAAI;oBACvCT,MAAM;wBACJU,QACEP,OAAOQ,MAAM,CAACC,MAAM,KAAK,IACrB,cACAT,OAAOU,QAAQ,GAAGV,OAAOW,OAAO,KAAK,IACnC,WACA;wBACRC,SAAS;4BACPF,UAAUV,OAAOU,QAAQ;4BACzBG,cACEb,OAAOQ,MAAM,CAACC,MAAM,GAAG,IACnBT,OAAOQ,MAAM,CAACM,GAAG,CAAC,CAACC,IAAO,CAAA;oCACxBlB,MAAMkB,EAAEC,GAAG;oCACXC,OAAOF,EAAEE,KAAK;oCACdC,KAAKH,EAAEI,KAAK,GAAG;gCACjB,CAAA,KACAC;4BACNC,QAAQrB,OAAOQ,MAAM,CAACC,MAAM;4BAC5Ba,OAAOtB,OAAOsB,KAAK;4BACnBX,SAASX,OAAOW,OAAO;wBACzB;oBACF;gBACF;YACF;YAEA,OAAO;gBACLY,QAAQvB;YACV;QACF;QACAd;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFields.d.ts","sourceRoot":"","sources":["../../src/import/getFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE5C,KAAK,gBAAgB,GAAG;IACtB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,SAAS,WAAY,MAAM,YAAY,gBAAgB,KAAG,KAAK,EAuJ3E,CAAA"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
export const getFields = (config, options)=>{
|
|
2
|
+
const collectionOptions = options?.collectionSlugs || config.collections?.map(({ slug })=>slug) || [];
|
|
3
|
+
return [
|
|
4
|
+
{
|
|
5
|
+
name: 'collectionSlug',
|
|
6
|
+
type: 'select',
|
|
7
|
+
options: collectionOptions,
|
|
8
|
+
required: true,
|
|
9
|
+
admin: {
|
|
10
|
+
components: {
|
|
11
|
+
Field: '@payloadcms/plugin-import-export/rsc#ImportCollectionField'
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
15
|
+
label: ({ t })=>t('plugin-import-export:field-collectionSlug-label'),
|
|
16
|
+
validate: (value)=>{
|
|
17
|
+
if (!value) {
|
|
18
|
+
return 'Collection is required';
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'importMode',
|
|
25
|
+
type: 'select',
|
|
26
|
+
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
27
|
+
label: ({ t })=>t('plugin-import-export:field-importMode-label'),
|
|
28
|
+
options: [
|
|
29
|
+
{
|
|
30
|
+
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
31
|
+
label: ({ t })=>t('plugin-import-export:field-importMode-create-label'),
|
|
32
|
+
value: 'create'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
36
|
+
label: ({ t })=>t('plugin-import-export:field-importMode-update-label'),
|
|
37
|
+
value: 'update'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
41
|
+
label: ({ t })=>t('plugin-import-export:field-importMode-upsert-label'),
|
|
42
|
+
value: 'upsert'
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'matchField',
|
|
48
|
+
type: 'text',
|
|
49
|
+
admin: {
|
|
50
|
+
condition: (_, siblingData)=>siblingData?.importMode !== 'create',
|
|
51
|
+
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
52
|
+
description: ({ t })=>t('plugin-import-export:field-matchField-description')
|
|
53
|
+
},
|
|
54
|
+
defaultValue: 'id',
|
|
55
|
+
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
56
|
+
label: ({ t })=>t('plugin-import-export:field-matchField-label')
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'status',
|
|
60
|
+
type: 'select',
|
|
61
|
+
admin: {
|
|
62
|
+
readOnly: true
|
|
63
|
+
},
|
|
64
|
+
defaultValue: 'pending',
|
|
65
|
+
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
66
|
+
label: ({ t })=>t('plugin-import-export:field-status-label'),
|
|
67
|
+
options: [
|
|
68
|
+
{
|
|
69
|
+
label: 'Pending',
|
|
70
|
+
value: 'pending'
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
label: 'Completed',
|
|
74
|
+
value: 'completed'
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
label: 'Partial',
|
|
78
|
+
value: 'partial'
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
label: 'Failed',
|
|
82
|
+
value: 'failed'
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: 'summary',
|
|
88
|
+
type: 'group',
|
|
89
|
+
admin: {
|
|
90
|
+
condition: (data)=>data?.status === 'completed' || data?.status === 'partial' || data?.status === 'failed'
|
|
91
|
+
},
|
|
92
|
+
fields: [
|
|
93
|
+
{
|
|
94
|
+
name: 'imported',
|
|
95
|
+
type: 'number',
|
|
96
|
+
admin: {
|
|
97
|
+
readOnly: true
|
|
98
|
+
},
|
|
99
|
+
label: 'Imported'
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'updated',
|
|
103
|
+
type: 'number',
|
|
104
|
+
admin: {
|
|
105
|
+
readOnly: true
|
|
106
|
+
},
|
|
107
|
+
label: 'Updated'
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'total',
|
|
111
|
+
type: 'number',
|
|
112
|
+
admin: {
|
|
113
|
+
readOnly: true
|
|
114
|
+
},
|
|
115
|
+
label: 'Total'
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: 'issues',
|
|
119
|
+
type: 'number',
|
|
120
|
+
admin: {
|
|
121
|
+
readOnly: true
|
|
122
|
+
},
|
|
123
|
+
label: 'Issues'
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: 'issueDetails',
|
|
127
|
+
type: 'json',
|
|
128
|
+
admin: {
|
|
129
|
+
condition: (_, siblingData)=>siblingData?.issues > 0,
|
|
130
|
+
readOnly: true
|
|
131
|
+
},
|
|
132
|
+
label: 'Issue Details'
|
|
133
|
+
}
|
|
134
|
+
],
|
|
135
|
+
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
136
|
+
label: ({ t })=>t('plugin-import-export:field-summary-label')
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: 'preview',
|
|
140
|
+
type: 'ui',
|
|
141
|
+
admin: {
|
|
142
|
+
components: {
|
|
143
|
+
Field: '@payloadcms/plugin-import-export/rsc#ImportPreview'
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
];
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
//# sourceMappingURL=getFields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/import/getFields.ts"],"sourcesContent":["import type { Config, Field } from 'payload'\n\ntype GetFieldsOptions = {\n collectionSlugs?: string[]\n}\n\nexport const getFields = (config: Config, options?: GetFieldsOptions): Field[] => {\n const collectionOptions =\n options?.collectionSlugs || config.collections?.map(({ slug }) => slug) || []\n\n return [\n {\n name: 'collectionSlug',\n type: 'select',\n options: collectionOptions,\n required: true,\n\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#ImportCollectionField',\n },\n },\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-collectionSlug-label'),\n validate: (value: any) => {\n if (!value) {\n return 'Collection is required'\n }\n return true\n },\n },\n {\n name: 'importMode',\n type: 'select',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-importMode-label'),\n options: [\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-importMode-create-label'),\n value: 'create',\n },\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-importMode-update-label'),\n value: 'update',\n },\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-importMode-upsert-label'),\n value: 'upsert',\n },\n ],\n },\n {\n name: 'matchField',\n type: 'text',\n admin: {\n condition: (_, siblingData) => siblingData?.importMode !== 'create',\n // @ts-expect-error - this is not correctly typed in plugins right now\n description: ({ t }) => t('plugin-import-export:field-matchField-description'),\n },\n defaultValue: 'id',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-matchField-label'),\n },\n {\n name: 'status',\n type: 'select',\n admin: {\n readOnly: true,\n },\n defaultValue: 'pending',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-status-label'),\n options: [\n {\n label: 'Pending',\n value: 'pending',\n },\n {\n label: 'Completed',\n value: 'completed',\n },\n {\n label: 'Partial',\n value: 'partial',\n },\n {\n label: 'Failed',\n value: 'failed',\n },\n ],\n },\n {\n name: 'summary',\n type: 'group',\n admin: {\n condition: (data) =>\n data?.status === 'completed' || data?.status === 'partial' || data?.status === 'failed',\n },\n fields: [\n {\n name: 'imported',\n type: 'number',\n admin: {\n readOnly: true,\n },\n label: 'Imported',\n },\n {\n name: 'updated',\n type: 'number',\n admin: {\n readOnly: true,\n },\n label: 'Updated',\n },\n {\n name: 'total',\n type: 'number',\n admin: {\n readOnly: true,\n },\n label: 'Total',\n },\n {\n name: 'issues',\n type: 'number',\n admin: {\n readOnly: true,\n },\n label: 'Issues',\n },\n {\n name: 'issueDetails',\n type: 'json',\n admin: {\n condition: (_, siblingData) => siblingData?.issues > 0,\n readOnly: true,\n },\n label: 'Issue Details',\n },\n ],\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-summary-label'),\n },\n {\n name: 'preview',\n type: 'ui',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#ImportPreview',\n },\n },\n },\n ]\n}\n"],"names":["getFields","config","options","collectionOptions","collectionSlugs","collections","map","slug","name","type","required","admin","components","Field","label","t","validate","value","condition","_","siblingData","importMode","description","defaultValue","readOnly","data","status","fields","issues"],"mappings":"AAMA,OAAO,MAAMA,YAAY,CAACC,QAAgBC;IACxC,MAAMC,oBACJD,SAASE,mBAAmBH,OAAOI,WAAW,EAAEC,IAAI,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAAS,EAAE;IAE/E,OAAO;QACL;YACEC,MAAM;YACNC,MAAM;YACNP,SAASC;YACTO,UAAU;YAEVC,OAAO;gBACLC,YAAY;oBACVC,OAAO;gBACT;YACF;YACA,sEAAsE;YACtEC,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;YACpBC,UAAU,CAACC;gBACT,IAAI,CAACA,OAAO;oBACV,OAAO;gBACT;gBACA,OAAO;YACT;QACF;QACA;YACET,MAAM;YACNC,MAAM;YACN,sEAAsE;YACtEK,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;YACpBb,SAAS;gBACP;oBACE,sEAAsE;oBACtEY,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;oBACpBE,OAAO;gBACT;gBACA;oBACE,sEAAsE;oBACtEH,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;oBACpBE,OAAO;gBACT;gBACA;oBACE,sEAAsE;oBACtEH,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;oBACpBE,OAAO;gBACT;aACD;QACH;QACA;YACET,MAAM;YACNC,MAAM;YACNE,OAAO;gBACLO,WAAW,CAACC,GAAGC,cAAgBA,aAAaC,eAAe;gBAC3D,sEAAsE;gBACtEC,aAAa,CAAC,EAAEP,CAAC,EAAE,GAAKA,EAAE;YAC5B;YACAQ,cAAc;YACd,sEAAsE;YACtET,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;QACtB;QACA;YACEP,MAAM;YACNC,MAAM;YACNE,OAAO;gBACLa,UAAU;YACZ;YACAD,cAAc;YACd,sEAAsE;YACtET,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;YACpBb,SAAS;gBACP;oBACEY,OAAO;oBACPG,OAAO;gBACT;gBACA;oBACEH,OAAO;oBACPG,OAAO;gBACT;gBACA;oBACEH,OAAO;oBACPG,OAAO;gBACT;gBACA;oBACEH,OAAO;oBACPG,OAAO;gBACT;aACD;QACH;QACA;YACET,MAAM;YACNC,MAAM;YACNE,OAAO;gBACLO,WAAW,CAACO,OACVA,MAAMC,WAAW,eAAeD,MAAMC,WAAW,aAAaD,MAAMC,WAAW;YACnF;YACAC,QAAQ;gBACN;oBACEnB,MAAM;oBACNC,MAAM;oBACNE,OAAO;wBACLa,UAAU;oBACZ;oBACAV,OAAO;gBACT;gBACA;oBACEN,MAAM;oBACNC,MAAM;oBACNE,OAAO;wBACLa,UAAU;oBACZ;oBACAV,OAAO;gBACT;gBACA;oBACEN,MAAM;oBACNC,MAAM;oBACNE,OAAO;wBACLa,UAAU;oBACZ;oBACAV,OAAO;gBACT;gBACA;oBACEN,MAAM;oBACNC,MAAM;oBACNE,OAAO;wBACLa,UAAU;oBACZ;oBACAV,OAAO;gBACT;gBACA;oBACEN,MAAM;oBACNC,MAAM;oBACNE,OAAO;wBACLO,WAAW,CAACC,GAAGC,cAAgBA,aAAaQ,SAAS;wBACrDJ,UAAU;oBACZ;oBACAV,OAAO;gBACT;aACD;YACD,sEAAsE;YACtEA,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;QACtB;QACA;YACEP,MAAM;YACNC,MAAM;YACNE,OAAO;gBACLC,YAAY;oBACVC,OAAO;gBACT;YACF;QACF;KACD;AACH,EAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CollectionConfig, Config } from 'payload';
|
|
2
|
+
import type { ImportConfig, ImportExportPluginConfig } from '../types.js';
|
|
3
|
+
export declare const getImportCollection: ({ config, importConfig, pluginConfig, }: {
|
|
4
|
+
config: Config;
|
|
5
|
+
importConfig?: ImportConfig;
|
|
6
|
+
pluginConfig: ImportExportPluginConfig;
|
|
7
|
+
}) => CollectionConfig;
|
|
8
|
+
//# sourceMappingURL=getImportCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getImportCollection.d.ts","sourceRoot":"","sources":["../../src/import/getImportCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,MAAM,EACP,MAAM,SAAS,CAAA;AAKhB,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAOzE,eAAO,MAAM,mBAAmB,4CAI7B;IACD,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,gBA6QH,CAAA"}
|