@payloadcms/plugin-import-export 3.75.0 → 3.76.0-canary.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/ExportPreview/index.d.ts.map +1 -1
- package/dist/components/ExportPreview/index.js +30 -12
- package/dist/components/ExportPreview/index.js.map +1 -1
- package/dist/components/ExportPreview/index.scss +12 -0
- package/dist/components/ImportPreview/index.js +3 -15
- package/dist/components/ImportPreview/index.js.map +1 -1
- package/dist/export/createExport.d.ts +5 -0
- package/dist/export/createExport.d.ts.map +1 -1
- package/dist/export/createExport.js +36 -12
- package/dist/export/createExport.js.map +1 -1
- package/dist/export/getCreateExportCollectionTask.d.ts.map +1 -1
- package/dist/export/getCreateExportCollectionTask.js +3 -0
- package/dist/export/getCreateExportCollectionTask.js.map +1 -1
- package/dist/export/getExportCollection.d.ts.map +1 -1
- package/dist/export/getExportCollection.js +21 -1
- package/dist/export/getExportCollection.js.map +1 -1
- package/dist/export/getFields.d.ts.map +1 -1
- package/dist/export/getFields.js +7 -3
- package/dist/export/getFields.js.map +1 -1
- package/dist/export/handleDownload.d.ts.map +1 -1
- package/dist/export/handleDownload.js +18 -1
- package/dist/export/handleDownload.js.map +1 -1
- package/dist/export/handlePreview.d.ts.map +1 -1
- package/dist/export/handlePreview.js +32 -10
- package/dist/export/handlePreview.js.map +1 -1
- package/dist/exports/types.d.ts +1 -1
- package/dist/exports/types.d.ts.map +1 -1
- package/dist/exports/types.js.map +1 -1
- package/dist/import/batchProcessor.js +50 -53
- package/dist/import/batchProcessor.js.map +1 -1
- package/dist/import/createImport.d.ts +6 -1
- package/dist/import/createImport.d.ts.map +1 -1
- package/dist/import/createImport.js +5 -1
- package/dist/import/createImport.js.map +1 -1
- package/dist/import/getCreateImportCollectionTask.d.ts.map +1 -1
- package/dist/import/getCreateImportCollectionTask.js +3 -0
- package/dist/import/getCreateImportCollectionTask.js.map +1 -1
- package/dist/import/getImportCollection.d.ts.map +1 -1
- package/dist/import/getImportCollection.js +15 -0
- package/dist/import/getImportCollection.js.map +1 -1
- package/dist/import/handlePreview.d.ts.map +1 -1
- package/dist/import/handlePreview.js +11 -0
- package/dist/import/handlePreview.js.map +1 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -2
- package/dist/index.js.map +1 -1
- package/dist/translations/languages/ar.d.ts.map +1 -1
- package/dist/translations/languages/ar.js +3 -0
- 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 +3 -0
- 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 +3 -0
- package/dist/translations/languages/bg.js.map +1 -1
- package/dist/translations/languages/bnBd.d.ts.map +1 -1
- package/dist/translations/languages/bnBd.js +22 -19
- package/dist/translations/languages/bnBd.js.map +1 -1
- package/dist/translations/languages/bnIn.d.ts.map +1 -1
- package/dist/translations/languages/bnIn.js +22 -19
- package/dist/translations/languages/bnIn.js.map +1 -1
- package/dist/translations/languages/ca.d.ts.map +1 -1
- package/dist/translations/languages/ca.js +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- package/dist/translations/languages/de.js.map +1 -1
- package/dist/translations/languages/en.d.ts +3 -0
- package/dist/translations/languages/en.d.ts.map +1 -1
- package/dist/translations/languages/en.js +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- package/dist/translations/languages/hy.js.map +1 -1
- package/dist/translations/languages/id.d.ts.map +1 -1
- package/dist/translations/languages/id.js +13 -10
- package/dist/translations/languages/id.js.map +1 -1
- package/dist/translations/languages/is.d.ts.map +1 -1
- package/dist/translations/languages/is.js +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +16 -13
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- 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 +3 -0
- package/dist/translations/languages/zhTw.js.map +1 -1
- package/dist/types.d.ts +44 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/buildDisabledFieldRegex.d.ts +11 -2
- package/dist/utilities/buildDisabledFieldRegex.d.ts.map +1 -1
- package/dist/utilities/buildDisabledFieldRegex.js +33 -7
- package/dist/utilities/buildDisabledFieldRegex.js.map +1 -1
- package/dist/utilities/buildDisabledFieldRegex.spec.js +64 -0
- package/dist/utilities/buildDisabledFieldRegex.spec.js.map +1 -0
- package/dist/utilities/collectTimezoneCompanionFields.d.ts +24 -0
- package/dist/utilities/collectTimezoneCompanionFields.d.ts.map +1 -0
- package/dist/utilities/collectTimezoneCompanionFields.js +89 -0
- package/dist/utilities/collectTimezoneCompanionFields.js.map +1 -0
- package/dist/utilities/collectTimezoneCompanionFields.spec.js +319 -0
- package/dist/utilities/collectTimezoneCompanionFields.spec.js.map +1 -0
- package/dist/utilities/fieldToRegex.d.ts +14 -0
- package/dist/utilities/fieldToRegex.d.ts.map +1 -0
- package/dist/utilities/fieldToRegex.js +34 -0
- package/dist/utilities/fieldToRegex.js.map +1 -0
- package/dist/utilities/fieldToRegex.spec.js +151 -0
- package/dist/utilities/fieldToRegex.spec.js.map +1 -0
- package/dist/utilities/flattenObject.d.ts +7 -1
- package/dist/utilities/flattenObject.d.ts.map +1 -1
- package/dist/utilities/flattenObject.js +30 -18
- package/dist/utilities/flattenObject.js.map +1 -1
- package/dist/utilities/getExportFieldFunctions.d.ts.map +1 -1
- package/dist/utilities/getExportFieldFunctions.js +7 -0
- package/dist/utilities/getExportFieldFunctions.js.map +1 -1
- package/dist/utilities/getImportFieldFunctions.d.ts.map +1 -1
- package/dist/utilities/getImportFieldFunctions.js +2 -16
- package/dist/utilities/getImportFieldFunctions.js.map +1 -1
- package/dist/utilities/getPluginCollections.d.ts +1 -0
- package/dist/utilities/getPluginCollections.d.ts.map +1 -1
- package/dist/utilities/getPluginCollections.js +43 -10
- package/dist/utilities/getPluginCollections.js.map +1 -1
- package/dist/utilities/getSchemaColumns.d.ts +8 -2
- package/dist/utilities/getSchemaColumns.d.ts.map +1 -1
- package/dist/utilities/getSchemaColumns.js +61 -27
- package/dist/utilities/getSchemaColumns.js.map +1 -1
- package/dist/utilities/parseCSV.d.ts.map +1 -1
- package/dist/utilities/parseCSV.js +4 -10
- package/dist/utilities/parseCSV.js.map +1 -1
- package/dist/utilities/resolveLimit.d.ts +15 -0
- package/dist/utilities/resolveLimit.d.ts.map +1 -0
- package/dist/utilities/resolveLimit.js +21 -0
- package/dist/utilities/resolveLimit.js.map +1 -0
- package/dist/utilities/unflattenObject.d.ts +13 -0
- package/dist/utilities/unflattenObject.d.ts.map +1 -1
- package/dist/utilities/unflattenObject.js +64 -65
- package/dist/utilities/unflattenObject.js.map +1 -1
- package/package.json +8 -8
- package/dist/utilities/getvalueAtPath.d.ts +0 -15
- package/dist/utilities/getvalueAtPath.d.ts.map +0 -1
- package/dist/utilities/getvalueAtPath.js +0 -49
- package/dist/utilities/getvalueAtPath.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/fieldToRegex.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport { fieldToRegex } from './fieldToRegex.js'\n\ndescribe('fieldToRegex', () => {\n describe('simple field paths', () => {\n it('should match exact field name', () => {\n const regex = fieldToRegex('title')\n\n expect(regex.test('title')).toBe(true)\n })\n\n it('should match field with array index', () => {\n const regex = fieldToRegex('items')\n\n expect(regex.test('items_0')).toBe(true)\n expect(regex.test('items_1')).toBe(true)\n expect(regex.test('items_99')).toBe(true)\n })\n\n it('should match nested fields under array items', () => {\n const regex = fieldToRegex('items')\n\n expect(regex.test('items_0_title')).toBe(true)\n expect(regex.test('items_1_description')).toBe(true)\n })\n\n it('should not match unrelated fields', () => {\n const regex = fieldToRegex('title')\n\n expect(regex.test('otherField')).toBe(false)\n expect(regex.test('titleExtra')).toBe(false)\n })\n })\n\n describe('dotted field paths', () => {\n it('should match nested field path without indices', () => {\n const regex = fieldToRegex('blocks.content')\n\n expect(regex.test('blocks_content')).toBe(true)\n })\n\n it('should match nested field path with array index in middle', () => {\n const regex = fieldToRegex('blocks.content')\n\n expect(regex.test('blocks_0_content')).toBe(true)\n expect(regex.test('blocks_1_content')).toBe(true)\n expect(regex.test('blocks_42_content')).toBe(true)\n })\n\n it('should match deeply nested paths with multiple indices', () => {\n const regex = fieldToRegex('blocks.content.items')\n\n expect(regex.test('blocks_0_content_items')).toBe(true)\n expect(regex.test('blocks_0_content_0_items')).toBe(true)\n expect(regex.test('blocks_1_content_2_items')).toBe(true)\n })\n\n it('should match nested fields under the matched path', () => {\n const regex = fieldToRegex('blocks.content')\n\n expect(regex.test('blocks_0_content_title')).toBe(true)\n expect(regex.test('blocks_0_content_richText')).toBe(true)\n expect(regex.test('blocks_1_content_0_value')).toBe(true)\n })\n })\n\n describe('complex nested structures', () => {\n it('should handle three-level nesting', () => {\n const regex = fieldToRegex('layout.sections.items')\n\n expect(regex.test('layout_sections_items')).toBe(true)\n expect(regex.test('layout_0_sections_items')).toBe(true)\n expect(regex.test('layout_0_sections_1_items')).toBe(true)\n expect(regex.test('layout_0_sections_1_items_2')).toBe(true)\n expect(regex.test('layout_0_sections_1_items_2_title')).toBe(true)\n })\n\n it('should not match partial field name matches', () => {\n const regex = fieldToRegex('block')\n\n expect(regex.test('blocks')).toBe(false)\n expect(regex.test('blocks_0_content')).toBe(false)\n expect(regex.test('blockType')).toBe(false)\n })\n\n it('should handle field names that look like array indices', () => {\n const regex = fieldToRegex('data.row')\n\n expect(regex.test('data_row')).toBe(true)\n expect(regex.test('data_0_row')).toBe(true)\n expect(regex.test('data_0_row_1')).toBe(true)\n })\n })\n\n describe('edge cases', () => {\n it('should handle single character field names', () => {\n const regex = fieldToRegex('a.b.c')\n\n expect(regex.test('a_b_c')).toBe(true)\n expect(regex.test('a_0_b_c')).toBe(true)\n expect(regex.test('a_0_b_1_c')).toBe(true)\n })\n\n it('should handle field names with numbers', () => {\n const regex = fieldToRegex('field1.field2')\n\n expect(regex.test('field1_field2')).toBe(true)\n expect(regex.test('field1_0_field2')).toBe(true)\n })\n\n it('should match field at end of key exactly', () => {\n const regex = fieldToRegex('meta.title')\n\n expect(regex.test('meta_title')).toBe(true)\n expect(regex.test('meta_0_title')).toBe(true)\n // Should not match if title is a prefix of another word\n expect(regex.test('meta_titleExtra')).toBe(false)\n })\n\n it('should handle field names starting with underscore', () => {\n const regex = fieldToRegex('_status')\n\n expect(regex.test('_status')).toBe(true)\n expect(regex.test('_status_0')).toBe(true)\n expect(regex.test('_statusExtra')).toBe(false)\n })\n\n it('should handle field names containing underscores', () => {\n const regex = fieldToRegex('my_field')\n\n expect(regex.test('my_field')).toBe(true)\n expect(regex.test('my_field_0')).toBe(true)\n expect(regex.test('my_fieldExtra')).toBe(false)\n })\n\n it('should handle nested paths with underscore fields', () => {\n const regex = fieldToRegex('group._status')\n\n expect(regex.test('group__status')).toBe(true)\n expect(regex.test('group_0__status')).toBe(true)\n })\n })\n\n describe('date fields with timezone companions', () => {\n it('should match date field and its _tz companion', () => {\n const regex = fieldToRegex('publishedDate')\n\n expect(regex.test('publishedDate')).toBe(true)\n expect(regex.test('publishedDate_tz')).toBe(true)\n })\n\n it('should match nested date field and its _tz companion', () => {\n const regex = fieldToRegex('meta.publishedDate')\n\n expect(regex.test('meta_publishedDate')).toBe(true)\n expect(regex.test('meta_publishedDate_tz')).toBe(true)\n expect(regex.test('meta_0_publishedDate')).toBe(true)\n expect(regex.test('meta_0_publishedDate_tz')).toBe(true)\n })\n\n it('should match date fields in arrays with _tz companions', () => {\n const regex = fieldToRegex('events.startDate')\n\n expect(regex.test('events_0_startDate')).toBe(true)\n expect(regex.test('events_0_startDate_tz')).toBe(true)\n expect(regex.test('events_1_startDate')).toBe(true)\n expect(regex.test('events_1_startDate_tz')).toBe(true)\n })\n\n it('should match deeply nested date fields with _tz companions', () => {\n const regex = fieldToRegex('blocks.content.scheduledAt')\n\n expect(regex.test('blocks_0_content_scheduledAt')).toBe(true)\n expect(regex.test('blocks_0_content_scheduledAt_tz')).toBe(true)\n expect(regex.test('blocks_0_content_0_scheduledAt')).toBe(true)\n expect(regex.test('blocks_0_content_0_scheduledAt_tz')).toBe(true)\n })\n\n it('should not match _tz suffix on unrelated fields', () => {\n const regex = fieldToRegex('title')\n\n expect(regex.test('title')).toBe(true)\n expect(regex.test('title_tz')).toBe(true) // _tz is treated as a nested field suffix\n expect(regex.test('publishedDate_tz')).toBe(false)\n })\n\n it('should handle date fields with underscores in name', () => {\n const regex = fieldToRegex('start_date')\n\n expect(regex.test('start_date')).toBe(true)\n expect(regex.test('start_date_tz')).toBe(true)\n expect(regex.test('start_date_0')).toBe(true)\n })\n })\n})\n"],"names":["describe","expect","it","fieldToRegex","regex","test","toBe"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,YAAY,QAAQ,oBAAmB;AAEhDH,SAAS,gBAAgB;IACvBA,SAAS,sBAAsB;QAC7BE,GAAG,iCAAiC;YAClC,MAAME,QAAQD,aAAa;YAE3BF,OAAOG,MAAMC,IAAI,CAAC,UAAUC,IAAI,CAAC;QACnC;QAEAJ,GAAG,uCAAuC;YACxC,MAAME,QAAQD,aAAa;YAE3BF,OAAOG,MAAMC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/**
|
|
8
|
+
* Set of auto-generated timezone companion field names (from collectTimezoneCompanionFields).
|
|
9
|
+
* These fields are excluded unless explicitly selected.
|
|
10
|
+
* If not provided, no timezone filtering is applied.
|
|
11
|
+
*/
|
|
12
|
+
timezoneCompanionFields?: Set<string>;
|
|
7
13
|
toCSVFunctions: Record<string, ToCSVFunction>;
|
|
8
14
|
};
|
|
9
|
-
export declare const flattenObject: ({ doc, fields, prefix, toCSVFunctions, }: Args) => Record<string, unknown>;
|
|
15
|
+
export declare const flattenObject: ({ doc, fields, prefix, timezoneCompanionFields, toCSVFunctions, }: Args) => Record<string, unknown>;
|
|
10
16
|
export {};
|
|
11
17
|
//# sourceMappingURL=flattenObject.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenObject.d.ts","sourceRoot":"","sources":["../../src/utilities/flattenObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"flattenObject.d.ts","sourceRoot":"","sources":["../../src/utilities/flattenObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAIhD,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,QAAQ,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACrC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;CAC9C,CAAA;AAED,eAAO,MAAM,aAAa,sEAMvB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAgL/B,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { fieldToRegex } from './fieldToRegex.js';
|
|
2
|
+
export const flattenObject = ({ doc, fields, prefix, timezoneCompanionFields, toCSVFunctions })=>{
|
|
2
3
|
const row = {};
|
|
3
4
|
// Helper to get toCSV function by full path or base field name
|
|
4
5
|
// This allows functions registered for field names (e.g., 'richText') to work
|
|
@@ -103,24 +104,35 @@ export const flattenObject = ({ doc, fields, prefix, toCSVFunctions })=>{
|
|
|
103
104
|
flatten(doc, prefix);
|
|
104
105
|
if (Array.isArray(fields) && fields.length > 0) {
|
|
105
106
|
const orderedResult = {};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
fields
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
107
|
+
// Build all field regexes once
|
|
108
|
+
const fieldPatterns = fields.map((field)=>({
|
|
109
|
+
field,
|
|
110
|
+
regex: fieldToRegex(field)
|
|
111
|
+
}));
|
|
112
|
+
// Track which timezone companion fields were explicitly selected
|
|
113
|
+
// Convert dotted notation to underscore for matching against flattened keys
|
|
114
|
+
const explicitlySelectedTimezoneFields = new Set(fields.filter((f)=>{
|
|
115
|
+
const underscored = f.replace(/\./g, '_');
|
|
116
|
+
return timezoneCompanionFields?.has(underscored);
|
|
117
|
+
}).map((f)=>f.replace(/\./g, '_')));
|
|
118
|
+
// Single pass through row keys - O(keys * fields) regex tests but only one iteration
|
|
119
|
+
const rowKeys = Object.keys(row);
|
|
120
|
+
// Process in field order to maintain user's specified ordering
|
|
121
|
+
for (const { regex } of fieldPatterns){
|
|
122
|
+
for (const key of rowKeys){
|
|
123
|
+
// Skip if already added (a key might match multiple field patterns)
|
|
124
|
+
if (key in orderedResult) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
// Skip auto-generated timezone companion fields unless explicitly selected
|
|
128
|
+
if (timezoneCompanionFields?.has(key) && !explicitlySelectedTimezoneFields.has(key)) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (regex.test(key)) {
|
|
132
|
+
orderedResult[key] = row[key];
|
|
133
|
+
}
|
|
122
134
|
}
|
|
123
|
-
}
|
|
135
|
+
}
|
|
124
136
|
return orderedResult;
|
|
125
137
|
}
|
|
126
138
|
return row;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/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 // Helper to get toCSV function by full path or base field name\n // This allows functions registered for field names (e.g., 'richText') to work\n // even when the field is nested in arrays/blocks (e.g., 'blocks_0_content_richText')\n const getToCSVFunction = (fullPath: string, baseFieldName: string): ToCSVFunction | undefined => {\n return toCSVFunctions?.[fullPath] ?? toCSVFunctions?.[baseFieldName]\n }\n\n const flatten = (siblingDoc: Document, prefix?: string) => {\n Object.entries(siblingDoc).forEach(([key, value]) => {\n const newKey = prefix ? `${prefix}_${key}` : key\n const toCSVFn = getToCSVFunction(newKey, 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 (toCSVFn) {\n try {\n const result = toCSVFn({\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 (!toCSVFn) {\n flatten(value, newKey)\n } else {\n try {\n const result = toCSVFn({\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 (toCSVFn) {\n try {\n const result = toCSVFn({\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","getToCSVFunction","fullPath","baseFieldName","flatten","siblingDoc","Object","entries","forEach","key","value","newKey","toCSVFn","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,+DAA+D;IAC/D,8EAA8E;IAC9E,qFAAqF;IACrF,MAAMC,mBAAmB,CAACC,UAAkBC;QAC1C,OAAOJ,gBAAgB,CAACG,SAAS,IAAIH,gBAAgB,CAACI,cAAc;IACtE;IAEA,MAAMC,UAAU,CAACC,YAAsBP;QACrCQ,OAAOC,OAAO,CAACF,YAAYG,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;YAC9C,MAAMC,SAASb,SAAS,GAAGA,OAAO,CAAC,EAAEW,KAAK,GAAGA;YAC7C,MAAMG,UAAUX,iBAAiBU,QAAQF;YAEzC,IAAII,MAAMC,OAAO,CAACJ,QAAQ;gBACxB,wEAAwE;gBACxE,uEAAuE;gBACvE,IAAIE,SAAS;oBACX,IAAI;wBACF,MAAMG,SAASH,QAAQ;4BACrBI,YAAYL;4BACZM,MAAMjB;4BACNJ;4BACAI;4BACAK;4BACAK;wBACF;wBAEA,IAAI,OAAOK,WAAW,aAAa;4BACjC,gEAAgE;4BAChEf,GAAG,CAACW,OAAO,G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CAAC,OAAO;gBAC5CV,aAAa,CAACW,eAAe,GAAG5C,GAAG,CAAC4C,eAAe;YACrD,OAAO;gBACL,MAAMC,QAAQX,aAAaC;gBAC3B7B,OAAOwC,IAAI,CAAC9C,KAAKQ,OAAO,CAAC,CAACC;oBACxB,IAAIoC,MAAME,IAAI,CAACtC,MAAM;wBACnBwB,aAAa,CAACxB,IAAI,GAAGT,GAAG,CAACS,IAAI;oBAC/B;gBACF;YACF;QACF;QAEA,OAAOwB;IACT;IAEA,OAAOjC;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/flattenObject.ts"],"sourcesContent":["import type { Document } from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\nimport { fieldToRegex } from './fieldToRegex.js'\n\ntype Args = {\n doc: Document\n fields?: string[]\n prefix?: string\n /**\n * Set of auto-generated timezone companion field names (from collectTimezoneCompanionFields).\n * These fields are excluded unless explicitly selected.\n * If not provided, no timezone filtering is applied.\n */\n timezoneCompanionFields?: Set<string>\n toCSVFunctions: Record<string, ToCSVFunction>\n}\n\nexport const flattenObject = ({\n doc,\n fields,\n prefix,\n timezoneCompanionFields,\n toCSVFunctions,\n}: Args): Record<string, unknown> => {\n const row: Record<string, unknown> = {}\n\n // Helper to get toCSV function by full path or base field name\n // This allows functions registered for field names (e.g., 'richText') to work\n // even when the field is nested in arrays/blocks (e.g., 'blocks_0_content_richText')\n const getToCSVFunction = (fullPath: string, baseFieldName: string): ToCSVFunction | undefined => {\n return toCSVFunctions?.[fullPath] ?? toCSVFunctions?.[baseFieldName]\n }\n\n const flatten = (siblingDoc: Document, prefix?: string) => {\n Object.entries(siblingDoc).forEach(([key, value]) => {\n const newKey = prefix ? `${prefix}_${key}` : key\n const toCSVFn = getToCSVFunction(newKey, 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 (toCSVFn) {\n try {\n const result = toCSVFn({\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 (!toCSVFn) {\n flatten(value, newKey)\n } else {\n try {\n const result = toCSVFn({\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 (toCSVFn) {\n try {\n const result = toCSVFn({\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 // Build all field regexes once\n const fieldPatterns = fields.map((field) => ({\n field,\n regex: fieldToRegex(field),\n }))\n\n // Track which timezone companion fields were explicitly selected\n // Convert dotted notation to underscore for matching against flattened keys\n const explicitlySelectedTimezoneFields = new Set(\n fields\n .filter((f) => {\n const underscored = f.replace(/\\./g, '_')\n return timezoneCompanionFields?.has(underscored)\n })\n .map((f) => f.replace(/\\./g, '_')),\n )\n\n // Single pass through row keys - O(keys * fields) regex tests but only one iteration\n const rowKeys = Object.keys(row)\n\n // Process in field order to maintain user's specified ordering\n for (const { regex } of fieldPatterns) {\n for (const key of rowKeys) {\n // Skip if already added (a key might match multiple field patterns)\n if (key in orderedResult) {\n continue\n }\n\n // Skip auto-generated timezone companion fields unless explicitly selected\n if (timezoneCompanionFields?.has(key) && !explicitlySelectedTimezoneFields.has(key)) {\n continue\n }\n\n if (regex.test(key)) {\n orderedResult[key] = row[key]\n }\n }\n }\n\n return orderedResult\n }\n\n return row\n}\n"],"names":["fieldToRegex","flattenObject","doc","fields","prefix","timezoneCompanionFields","toCSVFunctions","row","getToCSVFunction","fullPath","baseFieldName","flatten","siblingDoc","Object","entries","forEach","key","value","newKey","toCSVFn","Array","isArray","result","columnName","data","k","startsWith","error","Error","JSON","stringify","message","item","index","blockType","undefined","itemPrefix","relationTo","id","length","orderedResult","fieldPatterns","map","field","regex","explicitlySelectedTimezoneFields","Set","filter","f","underscored","replace","has","rowKeys","keys","test"],"mappings":"AAIA,SAASA,YAAY,QAAQ,oBAAmB;AAehD,OAAO,MAAMC,gBAAgB,CAAC,EAC5BC,GAAG,EACHC,MAAM,EACNC,MAAM,EACNC,uBAAuB,EACvBC,cAAc,EACT;IACL,MAAMC,MAA+B,CAAC;IAEtC,+DAA+D;IAC/D,8EAA8E;IAC9E,qFAAqF;IACrF,MAAMC,mBAAmB,CAACC,UAAkBC;QAC1C,OAAOJ,g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O;oBACLxB,GAAG,CAACW,OAAO,GAAGD;gBAChB;YACF;QACF;IACF;IAEAN,QAAQT,KAAKE;IAEb,IAAIgB,MAAMC,OAAO,CAAClB,WAAWA,OAAOoC,MAAM,GAAG,GAAG;QAC9C,MAAMC,gBAAyC,CAAC;QAEhD,+BAA+B;QAC/B,MAAMC,gBAAgBtC,OAAOuC,GAAG,CAAC,CAACC,QAAW,CAAA;gBAC3CA;gBACAC,OAAO5C,aAAa2C;YACtB,CAAA;QAEA,iEAAiE;QACjE,4EAA4E;QAC5E,MAAME,mCAAmC,IAAIC,IAC3C3C,OACG4C,MAAM,CAAC,CAACC;YACP,MAAMC,cAAcD,EAAEE,OAAO,CAAC,OAAO;YACrC,OAAO7C,yBAAyB8C,IAAIF;QACtC,GACCP,GAAG,CAAC,CAACM,IAAMA,EAAEE,OAAO,CAAC,OAAO;QAGjC,qFAAqF;QACrF,MAAME,UAAUvC,OAAOwC,IAAI,CAAC9C;QAE5B,+DAA+D;QAC/D,KAAK,MAAM,EAAEqC,KAAK,EAAE,IAAIH,cAAe;YACrC,KAAK,MAAMzB,OAAOoC,QAAS;gBACzB,oEAAoE;gBACpE,IAAIpC,OAAOwB,eAAe;oBACxB;gBACF;gBAEA,2EAA2E;gBAC3E,IAAInC,yBAAyB8C,IAAInC,QAAQ,CAAC6B,iCAAiCM,GAAG,CAACnC,MAAM;oBACnF;gBACF;gBAEA,IAAI4B,MAAMU,IAAI,CAACtC,MAAM;oBACnBwB,aAAa,CAACxB,IAAI,GAAGT,GAAG,CAACS,IAAI;gBAC/B;YACF;QACF;QAEA,OAAOwB;IACT;IAEA,OAAOjC;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getExportFieldFunctions.d.ts","sourceRoot":"","sources":["../../src/utilities/getExportFieldFunctions.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;;;GAGG;AACH,eAAO,MAAM,uBAAuB,eAAgB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"getExportFieldFunctions.d.ts","sourceRoot":"","sources":["../../src/utilities/getExportFieldFunctions.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;;;GAGG;AACH,eAAO,MAAM,uBAAuB,eAAgB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAqHtF,CAAA"}
|
|
@@ -29,6 +29,13 @@ import { traverseFields } from 'payload';
|
|
|
29
29
|
}
|
|
30
30
|
return value;
|
|
31
31
|
};
|
|
32
|
+
} else if (field.type === 'date') {
|
|
33
|
+
// Handle date fields - return value as-is (ISO string format)
|
|
34
|
+
// This prevents the flattener from treating the document as having
|
|
35
|
+
// nested sibling properties like _tz that shouldn't be auto-included
|
|
36
|
+
// @ts-expect-error ref is untyped
|
|
37
|
+
const fieldKey = `${ref.prefix}${field.name}`;
|
|
38
|
+
result[fieldKey] = ({ value })=>value;
|
|
32
39
|
} else if (field.type === 'relationship' || field.type === 'upload') {
|
|
33
40
|
if (field.hasMany !== true) {
|
|
34
41
|
if (!Array.isArray(field.relationTo)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getExportFieldFunctions.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\n/**\n * Gets custom toCSV field functions for export.\n * These functions transform field values when flattening documents for CSV export.\n */\nexport const getExportFieldFunctions = ({ 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 === 'json' || field.type === 'richText') {\n // Serialize JSON and richText fields as JSON strings in a single column\n // This prevents them from being flattened into multiple columns\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n if (value === null || value === undefined) {\n return value\n }\n if (typeof value === 'object') {\n return JSON.stringify(value)\n }\n return value\n }\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","getExportFieldFunctions","fields","result","buildCustomFunctions","field","parentRef","ref","prefix","type","parentPrefix","name","custom","toCSV","value","undefined","JSON","stringify","hasMany","Array","isArray","relationTo","id","data","relatedDoc","forEach","val","i","callback"],"mappings":"AAAA,SAA8BA,cAAc,QAAqC,UAAS;AAQ1F;;;CAGC,GACD,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,UAAUJ,MAAMI,IAAI,KAAK,YAAY;YAC7D,wEAAwE;YACxE,gEAAgE;YAChE,kCAAkC;YAClCN,MAAM,CAAC,GAAGI,IAAIC,MAAM,GAAGH,MAAMM,IAAI,EAAE,CAAC,GAAG,CAAC,EAAEG,KAAK,EAAE;gBAC/C,IAAIA,UAAU,QAAQA,UAAUC,WAAW;oBACzC,OAAOD;gBACT;gBACA,IAAI,OAAOA,UAAU,UAAU;oBAC7B,OAAOE,KAAKC,SAAS,CAACH;gBACxB;gBACA,OAAOA;YACT;QACF,OAAO,IAAIT,MAAMI,IAAI,KAAK,kBAAkBJ,MAAMI,IAAI,KAAK,UAAU;YACnE,IAAIJ,
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getExportFieldFunctions.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\n/**\n * Gets custom toCSV field functions for export.\n * These functions transform field values when flattening documents for CSV export.\n */\nexport const getExportFieldFunctions = ({ 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 === 'json' || field.type === 'richText') {\n // Serialize JSON and richText fields as JSON strings in a single column\n // This prevents them from being flattened into multiple columns\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n if (value === null || value === undefined) {\n return value\n }\n if (typeof value === 'object') {\n return JSON.stringify(value)\n }\n return value\n }\n } else if (field.type === 'date') {\n // Handle date fields - return value as-is (ISO string format)\n // This prevents the flattener from treating the document as having\n // nested sibling properties like _tz that shouldn't be auto-included\n // @ts-expect-error ref is untyped\n const fieldKey = `${ref.prefix}${field.name}`\n\n result[fieldKey] = ({ value }) => value\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","getExportFieldFunctions","fields","result","buildCustomFunctions","field","parentRef","ref","prefix","type","parentPrefix","name","custom","toCSV","value","undefined","JSON","stringify","fieldKey","hasMany","Array","isArray","relationTo","id","data","relatedDoc","forEach","val","i","callback"],"mappings":"AAAA,SAA8BA,cAAc,QAAqC,UAAS;AAQ1F;;;CAGC,GACD,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,I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GH,MAAMM,IAAI,CAAC,CAAC,EAAEiB,EAAE,GAAG,CAAC,CAAC,GAAGL;4BAC/C;wBACF;wBACA,OAAOR,UAAU,8BAA8B;;oBACjD;gBACF,OAAO;oBACL,mBAAmB;oBACnB,kCAAkC;oBAClCZ,MAAM,CAAC,GAAGI,IAAIC,MAAM,GAAGH,MAAMM,IAAI,EAAE,CAAC,GAAG,CAAC,EACtCa,IAAI,EACJV,KAAK,EAIN;wBACC,IAAIM,MAAMC,OAAO,CAACP,QAAQ;4BACxBA,MAAMY,OAAO,CAAC,CAACC,KAAKC;gCAClB,IAAID,OAAO,OAAOA,QAAQ,UAAU;oCAClC,MAAML,aAAaK,IAAIL,UAAU;oCACjC,MAAMG,aAAaE,IAAIb,KAAK;oCAC5B,IAAIQ,cAAcG,cAAc,OAAOA,eAAe,UAAU;wCAC9D,kCAAkC;wCAClCD,IAAI,CAAC,GAAGjB,IAAIC,MAAM,GAAGH,MAAMM,IAAI,CAAC,CAAC,EAAEiB,EAAE,GAAG,CAAC,CAAC,GAAGH,WAAWF,EAAE;wCAC1D,kCAAkC;wCAClCC,IAAI,CAAC,GAAGjB,IAAIC,MAAM,GAAGH,MAAMM,IAAI,CAAC,CAAC,EAAEiB,EAAE,WAAW,CAAC,CAAC,GAAGN;oCACvD;gCACF;4BACF;wBACF;wBACA,OAAOP;oBACT;gBACF;YACF;QACF;IACF;IAEAf,eAAe;QAAE6B,UAAUzB;QAAsBF;IAAO;IAExD,OAAOC;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getImportFieldFunctions.d.ts","sourceRoot":"","sources":["../../src/utilities/getImportFieldFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAA+C,MAAM,SAAS,CAAA;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,cAAc,EAAE,CAAA;CACzB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,eAAgB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"getImportFieldFunctions.d.ts","sourceRoot":"","sources":["../../src/utilities/getImportFieldFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAA+C,MAAM,SAAS,CAAA;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,cAAc,EAAE,CAAA;CACzB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,eAAgB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CA8GxF,CAAA"}
|
|
@@ -30,35 +30,26 @@ import { traverseFields } from 'payload';
|
|
|
30
30
|
return value;
|
|
31
31
|
};
|
|
32
32
|
} else {
|
|
33
|
-
//
|
|
34
|
-
// The CSV has field_id and field_relationTo columns
|
|
35
|
-
// We need to combine them back into { relationTo, value } format
|
|
36
|
-
// This is handled in unflattenObject, so we don't need a fromCSV here
|
|
33
|
+
// Polymorphic single: handled in unflattenObject via _id/_relationTo columns
|
|
37
34
|
}
|
|
38
35
|
} else {
|
|
39
36
|
if (!Array.isArray(field.relationTo)) {
|
|
40
37
|
// @ts-expect-error ref is untyped
|
|
41
38
|
result[`${ref.prefix}${field.name}`] = ({ value })=>{
|
|
42
|
-
// If it's already an array (from JSON import), return as-is
|
|
43
39
|
if (Array.isArray(value)) {
|
|
44
40
|
return value;
|
|
45
41
|
}
|
|
46
|
-
// For CSV, this is handled by array unflattening in unflattenObject
|
|
47
42
|
return value;
|
|
48
43
|
};
|
|
49
44
|
} else {
|
|
50
|
-
//
|
|
51
|
-
// Similar to polymorphic single, handled in unflattenObject
|
|
45
|
+
// Polymorphic many: handled in unflattenObject
|
|
52
46
|
}
|
|
53
47
|
}
|
|
54
48
|
} else if (field.type === 'number') {
|
|
55
|
-
// For hasMany number fields, preserve comma-separated strings for later processing
|
|
56
49
|
if (field.hasMany) {
|
|
57
|
-
// Don't convert - let unflattenObject handle comma-separated values
|
|
58
50
|
// @ts-expect-error ref is untyped
|
|
59
51
|
result[`${ref.prefix}${field.name}`] = ({ value })=>value;
|
|
60
52
|
} else {
|
|
61
|
-
// Ensure single numbers are parsed correctly from CSV strings
|
|
62
53
|
// @ts-expect-error ref is untyped
|
|
63
54
|
result[`${ref.prefix}${field.name}`] = ({ value })=>{
|
|
64
55
|
if (typeof value === 'number') {
|
|
@@ -72,7 +63,6 @@ import { traverseFields } from 'payload';
|
|
|
72
63
|
};
|
|
73
64
|
}
|
|
74
65
|
} else if (field.type === 'checkbox') {
|
|
75
|
-
// Convert string boolean values to actual booleans
|
|
76
66
|
// @ts-expect-error ref is untyped
|
|
77
67
|
result[`${ref.prefix}${field.name}`] = ({ value })=>{
|
|
78
68
|
if (typeof value === 'boolean') {
|
|
@@ -84,17 +74,14 @@ import { traverseFields } from 'payload';
|
|
|
84
74
|
return Boolean(value);
|
|
85
75
|
};
|
|
86
76
|
} else if (field.type === 'date') {
|
|
87
|
-
// Ensure dates are in proper format
|
|
88
77
|
// @ts-expect-error ref is untyped
|
|
89
78
|
result[`${ref.prefix}${field.name}`] = ({ value })=>{
|
|
90
79
|
if (!value) {
|
|
91
80
|
return value;
|
|
92
81
|
}
|
|
93
|
-
// If it's already a valid date string, return as-is
|
|
94
82
|
if (typeof value === 'string' && !isNaN(Date.parse(value))) {
|
|
95
83
|
return value;
|
|
96
84
|
}
|
|
97
|
-
// Try to parse and format
|
|
98
85
|
try {
|
|
99
86
|
const date = new Date(value);
|
|
100
87
|
return isNaN(date.getTime()) ? value : date.toISOString();
|
|
@@ -103,7 +90,6 @@ import { traverseFields } from 'payload';
|
|
|
103
90
|
}
|
|
104
91
|
};
|
|
105
92
|
} else if (field.type === 'json' || field.type === 'richText') {
|
|
106
|
-
// Parse JSON strings back to objects (both json and richText fields)
|
|
107
93
|
// @ts-expect-error ref is untyped
|
|
108
94
|
result[`${ref.prefix}${field.name}`] = ({ value })=>{
|
|
109
95
|
if (typeof value === 'object') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getImportFieldFunctions.ts"],"sourcesContent":["import { type FlattenedField, traverseFields, type TraverseFieldsCallback } from 'payload'\n\nimport type { FromCSVFunction } from '../types.js'\n\ntype Args = {\n fields: FlattenedField[]\n}\n\n/**\n * Gets custom fromCSV field functions for import.\n * These functions transform field values when unflattening CSV data for import.\n */\nexport const getImportFieldFunctions = ({ fields }: Args): Record<string, FromCSVFunction> => {\n const result: Record<string, FromCSVFunction> = {}\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']?.fromCSV === 'function') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = field.custom['plugin-import-export']?.fromCSV\n } else if (field.type === 'relationship' || field.type === 'upload') {\n if (field.hasMany !== true) {\n if (!Array.isArray(field.relationTo)) {\n // monomorphic single relationship - simple ID to value conversion\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n // If it's already an object (from JSON import), return as-is\n if (typeof value === 'object' && value !== null) {\n return value\n }\n // Convert string/number ID to relationship value\n return value\n }\n } else {\n //
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getImportFieldFunctions.ts"],"sourcesContent":["import { type FlattenedField, traverseFields, type TraverseFieldsCallback } from 'payload'\n\nimport type { FromCSVFunction } from '../types.js'\n\ntype Args = {\n fields: FlattenedField[]\n}\n\n/**\n * Gets custom fromCSV field functions for import.\n * These functions transform field values when unflattening CSV data for import.\n */\nexport const getImportFieldFunctions = ({ fields }: Args): Record<string, FromCSVFunction> => {\n const result: Record<string, FromCSVFunction> = {}\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']?.fromCSV === 'function') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = field.custom['plugin-import-export']?.fromCSV\n } else if (field.type === 'relationship' || field.type === 'upload') {\n if (field.hasMany !== true) {\n if (!Array.isArray(field.relationTo)) {\n // monomorphic single relationship - simple ID to value conversion\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n // If it's already an object (from JSON import), return as-is\n if (typeof value === 'object' && value !== null) {\n return value\n }\n // Convert string/number ID to relationship value\n return value\n }\n } else {\n // Polymorphic single: handled in unflattenObject via _id/_relationTo columns\n }\n } else {\n if (!Array.isArray(field.relationTo)) {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n if (Array.isArray(value)) {\n return value\n }\n return value\n }\n } else {\n // Polymorphic many: handled in unflattenObject\n }\n }\n } else if (field.type === 'number') {\n if (field.hasMany) {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => value\n } else {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n if (typeof value === 'number') {\n return value\n }\n if (typeof value === 'string') {\n const parsed = parseFloat(value)\n return isNaN(parsed) ? 0 : parsed\n }\n return value\n }\n }\n } else if (field.type === 'checkbox') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n if (typeof value === 'boolean') {\n return value\n }\n if (typeof value === 'string') {\n return value.toLowerCase() === 'true' || value === '1'\n }\n return Boolean(value)\n }\n } else if (field.type === 'date') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n if (!value) {\n return value\n }\n if (typeof value === 'string' && !isNaN(Date.parse(value))) {\n return value\n }\n try {\n const date = new Date(value as string)\n return isNaN(date.getTime()) ? value : date.toISOString()\n } catch {\n return value\n }\n }\n } else if (field.type === 'json' || field.type === 'richText') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n if (typeof value === 'object') {\n return value\n }\n if (typeof value === 'string') {\n try {\n return JSON.parse(value)\n } catch {\n return value\n }\n }\n return value\n }\n }\n }\n\n traverseFields({ callback: buildCustomFunctions, fields })\n\n return result\n}\n"],"names":["traverseFields","getImportFieldFunctions","fields","result","buildCustomFunctions","field","parentRef","ref","prefix","type","parentPrefix","name","custom","fromCSV","hasMany","Array","isArray","relationTo","value","parsed","parseFloat","isNaN","toLowerCase","Boolean","Date","parse","date","getTime","toISOString","JSON","callback"],"mappings":"AAAA,SAA8BA,cAAc,QAAqC,UAAS;AAQ1F;;;CAGC,GACD,OAAO,MAAMC,0BAA0B,CAAC,EAAEC,MAAM,EAAQ;IACtD,MAAMC,SAA0C,CAAC;IAEjD,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,OAA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I,OAAOA,UAAU,UAAU;oBAC7B,OAAOA;gBACT;gBACA,IAAI,OAAOA,UAAU,UAAU;oBAC7B,IAAI;wBACF,OAAOW,KAAKJ,KAAK,CAACP;oBACpB,EAAE,OAAM;wBACN,OAAOA;oBACT;gBACF;gBACA,OAAOA;YACT;QACF;IACF;IAEAlB,eAAe;QAAE8B,UAAU1B;QAAsBF;IAAO;IAExD,OAAOC;AACT,EAAC"}
|
|
@@ -27,6 +27,7 @@ export type PluginCollectionsResult = {
|
|
|
27
27
|
* - Applies top-level overrideExportCollection/overrideImportCollection if provided
|
|
28
28
|
* - For each collection in `pluginConfig.collections` that has a function override
|
|
29
29
|
* for `export` or `import`, applies the override to create customized collections
|
|
30
|
+
* - Applies settings from collections without overrideCollection to the base collection
|
|
30
31
|
*
|
|
31
32
|
* @param config - The Payload config
|
|
32
33
|
* @param pluginConfig - The import/export plugin config
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPluginCollections.d.ts","sourceRoot":"","sources":["../../src/utilities/getPluginCollections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEvD,OAAO,KAAK,EAA8B,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAKvF,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;OAGG;IACH,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC;;;OAGG;IACH,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC;;OAEG;IACH,iBAAiB,EAAE,gBAAgB,EAAE,CAAA;IACrC;;OAEG;IACH,iBAAiB,EAAE,gBAAgB,EAAE,CAAA;CACtC,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"getPluginCollections.d.ts","sourceRoot":"","sources":["../../src/utilities/getPluginCollections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEvD,OAAO,KAAK,EAA8B,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAKvF,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;OAGG;IACH,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC;;;OAGG;IACH,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC;;OAEG;IACH,iBAAiB,EAAE,gBAAgB,EAAE,CAAA;IACrC;;OAEG;IACH,iBAAiB,EAAE,gBAAgB,EAAE,CAAA;CACtC,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oBAAoB,8BAG9B;IACD,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,OAAO,CAAC,uBAAuB,CA8IlC,CAAA"}
|
|
@@ -7,12 +7,12 @@ import { getImportCollection } from '../import/getImportCollection.js';
|
|
|
7
7
|
* - Applies top-level overrideExportCollection/overrideImportCollection if provided
|
|
8
8
|
* - For each collection in `pluginConfig.collections` that has a function override
|
|
9
9
|
* for `export` or `import`, applies the override to create customized collections
|
|
10
|
+
* - Applies settings from collections without overrideCollection to the base collection
|
|
10
11
|
*
|
|
11
12
|
* @param config - The Payload config
|
|
12
13
|
* @param pluginConfig - The import/export plugin config
|
|
13
14
|
* @returns Object containing arrays of export and import collections
|
|
14
15
|
*/ export const getPluginCollections = async ({ config, pluginConfig })=>{
|
|
15
|
-
// Get the base export and import collections with default configs (no per-collection settings)
|
|
16
16
|
let baseExportCollection = getExportCollection({
|
|
17
17
|
config,
|
|
18
18
|
pluginConfig
|
|
@@ -21,7 +21,6 @@ import { getImportCollection } from '../import/getImportCollection.js';
|
|
|
21
21
|
config,
|
|
22
22
|
pluginConfig
|
|
23
23
|
});
|
|
24
|
-
// Apply top-level collection overrides if provided
|
|
25
24
|
if (pluginConfig.overrideExportCollection && typeof pluginConfig.overrideExportCollection === 'function') {
|
|
26
25
|
baseExportCollection = await pluginConfig.overrideExportCollection({
|
|
27
26
|
collection: baseExportCollection
|
|
@@ -34,14 +33,11 @@ import { getImportCollection } from '../import/getImportCollection.js';
|
|
|
34
33
|
}
|
|
35
34
|
const exportCollections = [];
|
|
36
35
|
const importCollections = [];
|
|
37
|
-
// Maps from target collection slug to the export/import collection slug to use
|
|
38
36
|
const customExportSlugMap = new Map();
|
|
39
37
|
const customImportSlugMap = new Map();
|
|
40
38
|
// Process each collection config for custom collection overrides
|
|
41
39
|
if (pluginConfig.collections && pluginConfig.collections.length > 0) {
|
|
42
40
|
for (const collectionConfig of pluginConfig.collections){
|
|
43
|
-
// Handle export config - only process if overrideCollection is provided
|
|
44
|
-
// Settings like disableJobsQueue require a custom slug to work properly
|
|
45
41
|
const exportConfig = typeof collectionConfig.export === 'object' ? collectionConfig.export : undefined;
|
|
46
42
|
if (exportConfig?.overrideCollection) {
|
|
47
43
|
// Generate a collection with this export config's settings (like disableJobsQueue)
|
|
@@ -56,15 +52,11 @@ import { getImportCollection } from '../import/getImportCollection.js';
|
|
|
56
52
|
// If the slug changed, this is a separate collection; otherwise it modifies the base
|
|
57
53
|
if (customExport.slug !== baseExportCollection.slug) {
|
|
58
54
|
exportCollections.push(customExport);
|
|
59
|
-
// Map this target collection to its custom export collection
|
|
60
55
|
customExportSlugMap.set(collectionConfig.slug, customExport.slug);
|
|
61
56
|
} else {
|
|
62
|
-
// Full override - replace the base
|
|
63
57
|
baseExportCollection = customExport;
|
|
64
58
|
}
|
|
65
59
|
}
|
|
66
|
-
// Handle import config - only process if overrideCollection is provided
|
|
67
|
-
// Settings like disableJobsQueue require a custom slug to work properly
|
|
68
60
|
const importConf = typeof collectionConfig.import === 'object' ? collectionConfig.import : undefined;
|
|
69
61
|
if (importConf?.overrideCollection) {
|
|
70
62
|
// Generate a collection with this import config's settings (like disableJobsQueue)
|
|
@@ -88,7 +80,48 @@ import { getImportCollection } from '../import/getImportCollection.js';
|
|
|
88
80
|
}
|
|
89
81
|
}
|
|
90
82
|
}
|
|
91
|
-
//
|
|
83
|
+
// Apply settings from collections without overrideCollection to the base collection
|
|
84
|
+
// This is done AFTER all overrides so these settings take precedence
|
|
85
|
+
if (pluginConfig.collections && pluginConfig.collections.length > 0) {
|
|
86
|
+
let mergedExportSettings = {};
|
|
87
|
+
let mergedImportSettings = {};
|
|
88
|
+
for (const collectionConfig of pluginConfig.collections){
|
|
89
|
+
const exportConf = typeof collectionConfig.export === 'object' ? collectionConfig.export : undefined;
|
|
90
|
+
const importConf = typeof collectionConfig.import === 'object' ? collectionConfig.import : undefined;
|
|
91
|
+
if (exportConf && !exportConf.overrideCollection) {
|
|
92
|
+
mergedExportSettings = {
|
|
93
|
+
...mergedExportSettings,
|
|
94
|
+
...exportConf
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (importConf && !importConf.overrideCollection) {
|
|
98
|
+
mergedImportSettings = {
|
|
99
|
+
...mergedImportSettings,
|
|
100
|
+
...importConf
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (mergedExportSettings.format !== undefined || mergedExportSettings.disableSave !== undefined || mergedExportSettings.disableDownload !== undefined) {
|
|
105
|
+
baseExportCollection = {
|
|
106
|
+
...baseExportCollection,
|
|
107
|
+
admin: {
|
|
108
|
+
...baseExportCollection.admin,
|
|
109
|
+
custom: {
|
|
110
|
+
...baseExportCollection.admin?.custom,
|
|
111
|
+
...mergedExportSettings.disableDownload !== undefined && {
|
|
112
|
+
disableDownload: mergedExportSettings.disableDownload
|
|
113
|
+
},
|
|
114
|
+
...mergedExportSettings.disableSave !== undefined && {
|
|
115
|
+
disableSave: mergedExportSettings.disableSave
|
|
116
|
+
},
|
|
117
|
+
...mergedExportSettings.format !== undefined && {
|
|
118
|
+
format: mergedExportSettings.format
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
92
125
|
exportCollections.unshift(baseExportCollection);
|
|
93
126
|
importCollections.unshift(baseImportCollection);
|
|
94
127
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getPluginCollections.ts"],"sourcesContent":["import type { CollectionConfig, Config } from 'payload'\n\nimport type { ExportConfig, ImportConfig, ImportExportPluginConfig } from '../types.js'\n\nimport { getExportCollection } from '../export/getExportCollection.js'\nimport { getImportCollection } from '../import/getImportCollection.js'\n\nexport type PluginCollectionsResult = {\n /**\n * Map from target collection slug to the export collection slug to use for it.\n * Only contains entries for collections with custom export collection overrides.\n */\n customExportSlugMap: Map<string, string>\n /**\n * Map from target collection slug to the import collection slug to use for it.\n * Only contains entries for collections with custom import collection overrides.\n */\n customImportSlugMap: Map<string, string>\n /**\n * All export collections (base + any per-collection overrides)\n */\n exportCollections: CollectionConfig[]\n /**\n * All import collections (base + any per-collection overrides)\n */\n importCollections: CollectionConfig[]\n}\n\n/**\n * Processes the plugin config and returns export/import collections.\n *\n * - Creates the base export and import collections\n * - Applies top-level overrideExportCollection/overrideImportCollection if provided\n * - For each collection in `pluginConfig.collections` that has a function override\n * for `export` or `import`, applies the override to create customized collections\n *\n * @param config - The Payload config\n * @param pluginConfig - The import/export plugin config\n * @returns Object containing arrays of export and import collections\n */\nexport const getPluginCollections = async ({\n config,\n pluginConfig,\n}: {\n config: Config\n pluginConfig: ImportExportPluginConfig\n}): Promise<PluginCollectionsResult> => {\n // Get the base export and import collections with default configs (no per-collection settings)\n let baseExportCollection = getExportCollection({\n config,\n pluginConfig,\n })\n let baseImportCollection = getImportCollection({\n config,\n pluginConfig,\n })\n\n // Apply top-level collection overrides if provided\n if (\n pluginConfig.overrideExportCollection &&\n typeof pluginConfig.overrideExportCollection === 'function'\n ) {\n baseExportCollection = await pluginConfig.overrideExportCollection({\n collection: baseExportCollection,\n })\n }\n\n if (\n pluginConfig.overrideImportCollection &&\n typeof pluginConfig.overrideImportCollection === 'function'\n ) {\n baseImportCollection = await pluginConfig.overrideImportCollection({\n collection: baseImportCollection,\n })\n }\n\n const exportCollections: CollectionConfig[] = []\n const importCollections: CollectionConfig[] = []\n\n // Maps from target collection slug to the export/import collection slug to use\n const customExportSlugMap = new Map<string, string>()\n const customImportSlugMap = new Map<string, string>()\n\n // Process each collection config for custom collection overrides\n if (pluginConfig.collections && pluginConfig.collections.length > 0) {\n for (const collectionConfig of pluginConfig.collections) {\n // Handle export config - only process if overrideCollection is provided\n // Settings like disableJobsQueue require a custom slug to work properly\n const exportConfig =\n typeof collectionConfig.export === 'object' ? collectionConfig.export : undefined\n if (exportConfig?.overrideCollection) {\n // Generate a collection with this export config's settings (like disableJobsQueue)\n const collectionWithSettings = getExportCollection({\n config,\n exportConfig,\n pluginConfig,\n })\n\n const customExport = await exportConfig.overrideCollection({\n collection: collectionWithSettings,\n })\n\n // If the slug changed, this is a separate collection; otherwise it modifies the base\n if (customExport.slug !== baseExportCollection.slug) {\n exportCollections.push(customExport)\n // Map this target collection to its custom export collection\n customExportSlugMap.set(collectionConfig.slug, customExport.slug)\n } else {\n // Full override - replace the base\n baseExportCollection = customExport\n }\n }\n\n // Handle import config - only process if overrideCollection is provided\n // Settings like disableJobsQueue require a custom slug to work properly\n const importConf =\n typeof collectionConfig.import === 'object' ? collectionConfig.import : undefined\n if (importConf?.overrideCollection) {\n // Generate a collection with this import config's settings (like disableJobsQueue)\n const collectionWithSettings = getImportCollection({\n config,\n importConfig: importConf,\n pluginConfig,\n })\n\n const customImport = await importConf.overrideCollection({\n collection: collectionWithSettings,\n })\n\n // If the slug changed, this is a separate collection; otherwise it modifies the base\n if (customImport.slug !== baseImportCollection.slug) {\n importCollections.push(customImport)\n // Map this target collection to its custom import collection\n customImportSlugMap.set(collectionConfig.slug, customImport.slug)\n } else {\n // Full override - replace the base\n baseImportCollection = customImport\n }\n }\n }\n }\n\n // Add base collections to the front of the arrays\n exportCollections.unshift(baseExportCollection)\n importCollections.unshift(baseImportCollection)\n\n return {\n customExportSlugMap,\n customImportSlugMap,\n exportCollections,\n importCollections,\n }\n}\n"],"names":["getExportCollection","getImportCollection","getPluginCollections","config","pluginConfig","baseExportCollection","baseImportCollection","overrideExportCollection","collection","overrideImportCollection","exportCollections","importCollections","customExportSlugMap","Map","customImportSlugMap","collections","length","collectionConfig","exportConfig","export","undefined","overrideCollection","collectionWithSettings","customExport","slug","push","set","importConf","import","importConfig","customImport","unshift"],"mappings":"AAIA,SAASA,mBAAmB,QAAQ,mCAAkC;AACtE,SAASC,mBAAmB,QAAQ,mCAAkC;AAuBtE;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,MAAM,EACNC,YAAY,EAIb;IACC,+FAA+F;IAC/F,IAAIC,uBAAuBL,oBAAoB;QAC7CG;QACAC;IACF;IACA,IAAIE,uBAAuBL,oBAAoB;QAC7CE;QACAC;IACF;IAEA,mDAAmD;IACnD,IACEA,aAAaG,wBAAwB,IACrC,OAAOH,aAAaG,wBAAwB,KAAK,YACjD;QACAF,uBAAuB,MAAMD,aAAaG,wBAAwB,CAAC;YACjEC,YAAYH;QACd;IACF;IAEA,IACED,aAAaK,wBAAwB,IACrC,OAAOL,aAAaK,wBAAwB,KAAK,YACjD;QACAH,uBAAuB,MAAMF,aAAaK,wBAAwB,CAAC;YACjED,YAAYF;QACd;IACF;IAEA,MAAMI,oBAAwC,EAAE;IAChD,MAAMC,oBAAwC,EAAE;IAEhD,+EAA+E;IAC/E,MAAMC,sBAAsB,IAAIC;IAChC,MAAMC,sBAAsB,IAAID;IAEhC,iEAAiE;IACjE,IAAIT,aAAaW,WAAW,IAAIX,aAAaW,WAAW,CAACC,MAAM,GAAG,GAAG;QACnE,KAAK,MAAMC,oBAAoBb,aAAaW,WAAW,CAAE;YACvD,wEAAwE;YACxE,wEAAwE;YACxE,MAAMG,eACJ,OAAOD,iBAAiBE,MAAM,KAAK,WAAWF,iBAAiBE,MAAM,GAAGC;YAC1E,IAAIF,cAAcG,oBAAoB;gBACpC,mFAAmF;gBACnF,MAAMC,yBAAyBtB,oBAAoB;oBACjDG;oBACAe;oBACAd;gBACF;gBAEA,MAAMmB,eAAe,MAAML,aAAaG,kBAAkB,CAAC;oBACzDb,YAAYc;gBACd;gBAEA,qFAAqF;gBACrF,IAAIC,aAAaC,IAAI,KAAKnB,qBAAqBmB,IAAI,EAAE;oBACnDd,kBAAkBe,IAAI,CAACF;oBACvB,6DAA6D;oBAC7DX,oBAAoBc,GAAG,CAACT,iBAAiBO,IAAI,EAAED,aAAaC,IAAI;gBAClE,OAAO;oBACL,mCAAmC;oBACnCnB,uBAAuBkB;gBACzB;YACF;YAEA,wEAAwE;YACxE,wEAAwE;YACxE,MAAMI,aACJ,OAAOV,iBAAiBW,MAAM,KAAK,WAAWX,iBAAiBW,MAAM,GAAGR;YAC1E,IAAIO,YAAYN,oBAAoB;gBAClC,mFAAmF;gBACnF,MAAMC,yBAAyBrB,oBAAoB;oBACjDE;oBACA0B,cAAcF;oBACdvB;gBACF;gBAEA,MAAM0B,eAAe,MAAMH,WAAWN,kBAAkB,CAAC;oBACvDb,YAAYc;gBACd;gBAEA,qFAAqF;gBACrF,IAAIQ,aAAaN,IAAI,KAAKlB,qBAAqBkB,IAAI,EAAE;oBACnDb,kBAAkBc,IAAI,CAACK;oBACvB,6DAA6D;oBAC7DhB,oBAAoBY,GAAG,CAACT,iBAAiBO,IAAI,EAAEM,aAAaN,IAAI;gBAClE,OAAO;oBACL,mCAAmC;oBACnClB,uBAAuBwB;gBACzB;YACF;QACF;IACF;IAEA,kDAAkD;IAClDpB,kBAAkBqB,OAAO,CAAC1B;IAC1BM,kBAAkBoB,OAAO,CAACzB;IAE1B,OAAO;QACLM;QACAE;QACAJ;QACAC;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getPluginCollections.ts"],"sourcesContent":["import type { CollectionConfig, Config } from 'payload'\n\nimport type { ExportConfig, ImportConfig, ImportExportPluginConfig } from '../types.js'\n\nimport { getExportCollection } from '../export/getExportCollection.js'\nimport { getImportCollection } from '../import/getImportCollection.js'\n\nexport type PluginCollectionsResult = {\n /**\n * Map from target collection slug to the export collection slug to use for it.\n * Only contains entries for collections with custom export collection overrides.\n */\n customExportSlugMap: Map<string, string>\n /**\n * Map from target collection slug to the import collection slug to use for it.\n * Only contains entries for collections with custom import collection overrides.\n */\n customImportSlugMap: Map<string, string>\n /**\n * All export collections (base + any per-collection overrides)\n */\n exportCollections: CollectionConfig[]\n /**\n * All import collections (base + any per-collection overrides)\n */\n importCollections: CollectionConfig[]\n}\n\n/**\n * Processes the plugin config and returns export/import collections.\n *\n * - Creates the base export and import collections\n * - Applies top-level overrideExportCollection/overrideImportCollection if provided\n * - For each collection in `pluginConfig.collections` that has a function override\n * for `export` or `import`, applies the override to create customized collections\n * - Applies settings from collections without overrideCollection to the base collection\n *\n * @param config - The Payload config\n * @param pluginConfig - The import/export plugin config\n * @returns Object containing arrays of export and import collections\n */\nexport const getPluginCollections = async ({\n config,\n pluginConfig,\n}: {\n config: Config\n pluginConfig: ImportExportPluginConfig\n}): Promise<PluginCollectionsResult> => {\n let baseExportCollection = getExportCollection({\n config,\n pluginConfig,\n })\n let baseImportCollection = getImportCollection({\n config,\n pluginConfig,\n })\n\n if (\n pluginConfig.overrideExportCollection &&\n typeof pluginConfig.overrideExportCollection === 'function'\n ) {\n baseExportCollection = await pluginConfig.overrideExportCollection({\n collection: baseExportCollection,\n })\n }\n\n if (\n pluginConfig.overrideImportCollection &&\n typeof pluginConfig.overrideImportCollection === 'function'\n ) {\n baseImportCollection = await pluginConfig.overrideImportCollection({\n collection: baseImportCollection,\n })\n }\n\n const exportCollections: CollectionConfig[] = []\n const importCollections: CollectionConfig[] = []\n\n const customExportSlugMap = new Map<string, string>()\n const customImportSlugMap = new Map<string, string>()\n\n // Process each collection config for custom collection overrides\n if (pluginConfig.collections && pluginConfig.collections.length > 0) {\n for (const collectionConfig of pluginConfig.collections) {\n const exportConfig =\n typeof collectionConfig.export === 'object' ? collectionConfig.export : undefined\n if (exportConfig?.overrideCollection) {\n // Generate a collection with this export config's settings (like disableJobsQueue)\n const collectionWithSettings = getExportCollection({\n config,\n exportConfig,\n pluginConfig,\n })\n\n const customExport = await exportConfig.overrideCollection({\n collection: collectionWithSettings,\n })\n\n // If the slug changed, this is a separate collection; otherwise it modifies the base\n if (customExport.slug !== baseExportCollection.slug) {\n exportCollections.push(customExport)\n customExportSlugMap.set(collectionConfig.slug, customExport.slug)\n } else {\n baseExportCollection = customExport\n }\n }\n\n const importConf =\n typeof collectionConfig.import === 'object' ? collectionConfig.import : undefined\n if (importConf?.overrideCollection) {\n // Generate a collection with this import config's settings (like disableJobsQueue)\n const collectionWithSettings = getImportCollection({\n config,\n importConfig: importConf,\n pluginConfig,\n })\n\n const customImport = await importConf.overrideCollection({\n collection: collectionWithSettings,\n })\n\n // If the slug changed, this is a separate collection; otherwise it modifies the base\n if (customImport.slug !== baseImportCollection.slug) {\n importCollections.push(customImport)\n // Map this target collection to its custom import collection\n customImportSlugMap.set(collectionConfig.slug, customImport.slug)\n } else {\n // Full override - replace the base\n baseImportCollection = customImport\n }\n }\n }\n }\n\n // Apply settings from collections without overrideCollection to the base collection\n // This is done AFTER all overrides so these settings take precedence\n if (pluginConfig.collections && pluginConfig.collections.length > 0) {\n let mergedExportSettings: Partial<ExportConfig> = {}\n let mergedImportSettings: Partial<ImportConfig> = {}\n\n for (const collectionConfig of pluginConfig.collections) {\n const exportConf =\n typeof collectionConfig.export === 'object' ? collectionConfig.export : undefined\n const importConf =\n typeof collectionConfig.import === 'object' ? collectionConfig.import : undefined\n\n if (exportConf && !exportConf.overrideCollection) {\n mergedExportSettings = { ...mergedExportSettings, ...exportConf }\n }\n if (importConf && !importConf.overrideCollection) {\n mergedImportSettings = { ...mergedImportSettings, ...importConf }\n }\n }\n\n if (\n mergedExportSettings.format !== undefined ||\n mergedExportSettings.disableSave !== undefined ||\n mergedExportSettings.disableDownload !== undefined\n ) {\n baseExportCollection = {\n ...baseExportCollection,\n admin: {\n ...baseExportCollection.admin,\n custom: {\n ...baseExportCollection.admin?.custom,\n ...(mergedExportSettings.disableDownload !== undefined && {\n disableDownload: mergedExportSettings.disableDownload,\n }),\n ...(mergedExportSettings.disableSave !== undefined && {\n disableSave: mergedExportSettings.disableSave,\n }),\n ...(mergedExportSettings.format !== undefined && {\n format: mergedExportSettings.format,\n }),\n },\n },\n }\n }\n }\n\n exportCollections.unshift(baseExportCollection)\n importCollections.unshift(baseImportCollection)\n\n return {\n customExportSlugMap,\n customImportSlugMap,\n exportCollections,\n importCollections,\n }\n}\n"],"names":["getExportCollection","getImportCollection","getPluginCollections","config","pluginConfig","baseExportCollection","baseImportCollection","overrideExportCollection","collection","overrideImportCollection","exportCollections","importCollections","customExportSlugMap","Map","customImportSlugMap","collections","length","collectionConfig","exportConfig","export","undefined","overrideCollection","collectionWithSettings","customExport","slug","push","set","importConf","import","importConfig","customImport","mergedExportSettings","mergedImportSettings","exportConf","format","disableSave","disableDownload","admin","custom","unshift"],"mappings":"AAIA,SAASA,mBAAmB,QAAQ,mCAAkC;AACtE,SAASC,mBAAmB,QAAQ,mCAAkC;AAuBtE;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,MAAM,EACNC,YAAY,EAIb;IACC,IAAIC,uBAAuBL,oBAAoB;QAC7CG;QACAC;IACF;IACA,IAAIE,uBAAuBL,oBAAoB;QAC7CE;QACAC;IACF;IAEA,IACEA,aAAaG,wBAAwB,IACrC,OAAOH,aAAaG,wBAAwB,KAAK,YACjD;QACAF,uBAAuB,MAAMD,aAAaG,wBAAwB,CAAC;YACjEC,YAAYH;QACd;IACF;IAEA,IACED,aAAaK,wBAAwB,IACrC,OAAOL,aAAaK,wBAAwB,KAAK,YACjD;QACAH,uBAAuB,MAAMF,aAAaK,wBAAwB,CAAC;YACjED,YAAYF;QACd;IACF;IAEA,MAAMI,oBAAwC,EAAE;IAChD,MAAMC,oBAAwC,EAAE;IAE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"}
|
|
@@ -20,6 +20,12 @@ export type GetSchemaColumnsArgs = {
|
|
|
20
20
|
* Available locale codes from config. Required when locale='all'.
|
|
21
21
|
*/
|
|
22
22
|
localeCodes?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Set of auto-generated timezone companion field names (from collectTimezoneCompanionFields).
|
|
25
|
+
* These fields are excluded unless explicitly selected.
|
|
26
|
+
* If not provided, no timezone filtering is applied.
|
|
27
|
+
*/
|
|
28
|
+
timezoneCompanionFields?: Set<string>;
|
|
23
29
|
};
|
|
24
30
|
/**
|
|
25
31
|
* Derives CSV column names from the collection schema.
|
|
@@ -33,11 +39,11 @@ export type GetSchemaColumnsArgs = {
|
|
|
33
39
|
* - Works for empty exports
|
|
34
40
|
* - Ensures proper column ordering
|
|
35
41
|
*/
|
|
36
|
-
export declare const getSchemaColumns: ({ collectionConfig, disabledFields, fields: selectedFields, locale, localeCodes, }: GetSchemaColumnsArgs) => string[];
|
|
42
|
+
export declare const getSchemaColumns: ({ collectionConfig, disabledFields, fields: selectedFields, locale, localeCodes, timezoneCompanionFields, }: GetSchemaColumnsArgs) => string[];
|
|
37
43
|
/**
|
|
38
44
|
* Merges schema-derived columns with data-discovered columns.
|
|
39
45
|
* Schema columns provide the base ordering, data columns add any additional
|
|
40
|
-
* columns (e.g., array indices beyond 0, dynamic fields).
|
|
46
|
+
* columns (e.g., array indices beyond 0, dynamic fields, derived columns from toCSV).
|
|
41
47
|
*/
|
|
42
48
|
export declare const mergeColumns: (schemaColumns: string[], dataColumns: string[]) => string[];
|
|
43
49
|
//# sourceMappingURL=getSchemaColumns.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSchemaColumns.d.ts","sourceRoot":"","sources":["../../src/utilities/getSchemaColumns.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAIxD,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB;;OAEG;IACH,MAAM,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"getSchemaColumns.d.ts","sourceRoot":"","sources":["../../src/utilities/getSchemaColumns.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAIxD,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB;;OAEG;IACH,MAAM,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CACtC,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,gHAO1B,oBAAoB,KAAG,MAAM,EA4E/B,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,kBAAmB,MAAM,EAAE,eAAe,MAAM,EAAE,KAAG,MAAM,EA+DnF,CAAA"}
|