@payloadcms/plugin-import-export 3.44.0-canary.8 → 3.44.0-internal.6b79dc2
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/export/createExport.d.ts.map +1 -1
- package/dist/export/createExport.js +42 -30
- package/dist/export/createExport.js.map +1 -1
- package/dist/export/flattenObject.d.ts.map +1 -1
- package/dist/export/flattenObject.js +3 -0
- package/dist/export/flattenObject.js.map +1 -1
- package/dist/export/getCustomFieldFunctions.d.ts.map +1 -1
- package/dist/export/getCustomFieldFunctions.js +27 -11
- package/dist/export/getCustomFieldFunctions.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExport.d.ts","sourceRoot":"","sources":["../../src/export/createExport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"createExport.d.ts","sourceRoot":"","sources":["../../src/export/createExport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAWhE,MAAM,MAAM,MAAM,GAAG;IACnB,cAAc,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,IAAI,GAAG,KAAK,CAAA;IACrB,iBAAiB,EAAE,MAAM,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,EAAE,KAAK,GAAG,MAAM,CAAA;IACtB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,MAAM,CAAA;IACtB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,cAAc,CAAA;IACnB,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,CAAA;AAED,eAAO,MAAM,YAAY,SAAgB,gBAAgB,kCAmMxD,CAAA"}
|
|
@@ -51,9 +51,6 @@ export const createExport = async (args)=>{
|
|
|
51
51
|
findArgs
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
|
-
let result = {
|
|
55
|
-
hasNextPage: true
|
|
56
|
-
};
|
|
57
54
|
const toCSVFunctions = getCustomFieldFunctions({
|
|
58
55
|
fields: collectionConfig.flattenedFields,
|
|
59
56
|
select
|
|
@@ -63,35 +60,44 @@ export const createExport = async (args)=>{
|
|
|
63
60
|
req.payload.logger.info('Starting download stream');
|
|
64
61
|
}
|
|
65
62
|
const encoder = new TextEncoder();
|
|
63
|
+
let isFirstBatch = true;
|
|
64
|
+
let columns;
|
|
65
|
+
let page = 1;
|
|
66
66
|
const stream = new Readable({
|
|
67
67
|
async read () {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
const result = await payload.find({
|
|
69
|
+
...findArgs,
|
|
70
|
+
page
|
|
71
|
+
});
|
|
72
|
+
if (debug) {
|
|
73
|
+
req.payload.logger.info(`Processing batch ${page} with ${result.docs.length} documents`);
|
|
74
|
+
}
|
|
75
|
+
if (result.docs.length === 0) {
|
|
76
|
+
this.push(null);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const csvInput = result.docs.map((doc)=>flattenObject({
|
|
80
|
+
doc,
|
|
81
|
+
fields,
|
|
82
|
+
toCSVFunctions
|
|
83
|
+
}));
|
|
84
|
+
if (isFirstBatch) {
|
|
85
|
+
columns = Object.keys(csvInput[0] ?? {});
|
|
86
|
+
}
|
|
87
|
+
const csvString = stringify(csvInput, {
|
|
88
|
+
header: isFirstBatch,
|
|
89
|
+
columns
|
|
90
|
+
});
|
|
91
|
+
this.push(encoder.encode(csvString));
|
|
92
|
+
isFirstBatch = false;
|
|
93
|
+
if (!result.hasNextPage) {
|
|
71
94
|
if (debug) {
|
|
72
|
-
req.payload.logger.info(
|
|
73
|
-
}
|
|
74
|
-
const csvInput = result.docs.map((doc)=>flattenObject({
|
|
75
|
-
doc,
|
|
76
|
-
fields,
|
|
77
|
-
toCSVFunctions
|
|
78
|
-
}));
|
|
79
|
-
const csvString = stringify(csvInput, {
|
|
80
|
-
header: isFirstBatch
|
|
81
|
-
});
|
|
82
|
-
this.push(encoder.encode(csvString));
|
|
83
|
-
isFirstBatch = false;
|
|
84
|
-
if (!result.hasNextPage) {
|
|
85
|
-
if (debug) {
|
|
86
|
-
req.payload.logger.info('Stream complete - no more pages');
|
|
87
|
-
}
|
|
88
|
-
this.push(null) // End the stream
|
|
89
|
-
;
|
|
90
|
-
break;
|
|
95
|
+
req.payload.logger.info('Stream complete - no more pages');
|
|
91
96
|
}
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
this.push(null) // End the stream
|
|
98
|
+
;
|
|
94
99
|
}
|
|
100
|
+
page += 1;
|
|
95
101
|
}
|
|
96
102
|
});
|
|
97
103
|
return new Response(stream, {
|
|
@@ -106,9 +112,13 @@ export const createExport = async (args)=>{
|
|
|
106
112
|
}
|
|
107
113
|
const outputData = [];
|
|
108
114
|
let isFirstBatch = true;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
let page = 1;
|
|
116
|
+
let hasNextPage = true;
|
|
117
|
+
while(hasNextPage){
|
|
118
|
+
const result = await payload.find({
|
|
119
|
+
...findArgs,
|
|
120
|
+
page
|
|
121
|
+
});
|
|
112
122
|
if (debug) {
|
|
113
123
|
req.payload.logger.info(`Processing batch ${findArgs.page} with ${result.docs.length} documents`);
|
|
114
124
|
}
|
|
@@ -126,6 +136,8 @@ export const createExport = async (args)=>{
|
|
|
126
136
|
const jsonInput = result.docs.map((doc)=>JSON.stringify(doc));
|
|
127
137
|
outputData.push(jsonInput.join(',\n'));
|
|
128
138
|
}
|
|
139
|
+
hasNextPage = result.hasNextPage;
|
|
140
|
+
page += 1;
|
|
129
141
|
}
|
|
130
142
|
const buffer = Buffer.from(format === 'json' ? `[${outputData.join(',')}]` : outputData.join(''));
|
|
131
143
|
if (debug) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/createExport.ts"],"sourcesContent":["/* eslint-disable perfectionist/sort-objects */\nimport type { PaginatedDocs, PayloadRequest, Sort, User, Where } from 'payload'\n\nimport { stringify } from 'csv-stringify/sync'\nimport { APIError } from 'payload'\nimport { Readable } from 'stream'\n\nimport { flattenObject } from './flattenObject.js'\nimport { getCustomFieldFunctions } from './getCustomFieldFunctions.js'\nimport { getFilename } from './getFilename.js'\nimport { getSelect } from './getSelect.js'\n\nexport type Export = {\n collectionSlug: string\n /**\n * If true, enables debug logging\n */\n debug?: boolean\n drafts?: 'no' | 'yes'\n exportsCollection: string\n fields?: string[]\n format: 'csv' | 'json'\n globals?: string[]\n id: number | string\n locale?: string\n name: string\n slug: string\n sort: Sort\n user: string\n userCollection: string\n where?: Where\n}\n\nexport type CreateExportArgs = {\n /**\n * If true, stream the file instead of saving it\n */\n download?: boolean\n input: Export\n req: PayloadRequest\n user?: User\n}\n\nexport const createExport = async (args: CreateExportArgs) => {\n const {\n download,\n input: {\n id,\n name: nameArg,\n collectionSlug,\n debug = false,\n drafts,\n exportsCollection,\n fields,\n format,\n locale: localeInput,\n sort,\n user,\n where,\n },\n req: { locale: localeArg, payload },\n req,\n } = args\n\n if (debug) {\n req.payload.logger.info({\n message: 'Starting export process with args:',\n collectionSlug,\n drafts,\n fields,\n format,\n })\n }\n\n const locale = localeInput ?? localeArg\n const collectionConfig = payload.config.collections.find(({ slug }) => slug === collectionSlug)\n if (!collectionConfig) {\n throw new APIError(`Collection with slug ${collectionSlug} not found`)\n }\n\n const name = `${nameArg ?? `${getFilename()}-${collectionSlug}`}.${format}`\n const isCSV = format === 'csv'\n const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined\n\n if (debug) {\n req.payload.logger.info({ message: 'Export configuration:', name, isCSV, locale })\n }\n\n const findArgs = {\n collection: collectionSlug,\n depth: 1,\n draft: drafts === 'yes',\n limit: 100,\n locale,\n overrideAccess: false,\n page: 0,\n select,\n sort,\n user,\n where,\n }\n\n if (debug) {\n req.payload.logger.info({ message: 'Find arguments:', findArgs })\n }\n\n let result: PaginatedDocs = { hasNextPage: true } as PaginatedDocs\n\n const toCSVFunctions = getCustomFieldFunctions({\n fields: collectionConfig.flattenedFields,\n select,\n })\n\n if (download) {\n if (debug) {\n req.payload.logger.info('Starting download stream')\n }\n const encoder = new TextEncoder()\n const stream = new Readable({\n async read() {\n let result = await payload.find(findArgs)\n let isFirstBatch = true\n\n while (result.docs.length > 0) {\n if (debug) {\n req.payload.logger.info(\n `Processing batch ${findArgs.page + 1} with ${result.docs.length} documents`,\n )\n }\n const csvInput = result.docs.map((doc) => flattenObject({ doc, fields, toCSVFunctions }))\n const csvString = stringify(csvInput, { header: isFirstBatch })\n this.push(encoder.encode(csvString))\n isFirstBatch = false\n\n if (!result.hasNextPage) {\n if (debug) {\n req.payload.logger.info('Stream complete - no more pages')\n }\n this.push(null) // End the stream\n break\n }\n\n findArgs.page += 1\n result = await payload.find(findArgs)\n }\n },\n })\n\n return new Response(stream as any, {\n headers: {\n 'Content-Disposition': `attachment; filename=\"${name}\"`,\n 'Content-Type': isCSV ? 'text/csv' : 'application/json',\n },\n })\n }\n\n if (debug) {\n req.payload.logger.info('Starting file generation')\n }\n const outputData: string[] = []\n let isFirstBatch = true\n\n while (result.hasNextPage) {\n findArgs.page += 1\n result = await payload.find(findArgs)\n\n if (debug) {\n req.payload.logger.info(\n `Processing batch ${findArgs.page} with ${result.docs.length} documents`,\n )\n }\n\n if (isCSV) {\n const csvInput = result.docs.map((doc) => flattenObject({ doc, fields, toCSVFunctions }))\n outputData.push(stringify(csvInput, { header: isFirstBatch }))\n isFirstBatch = false\n } else {\n const jsonInput = result.docs.map((doc) => JSON.stringify(doc))\n outputData.push(jsonInput.join(',\\n'))\n }\n }\n\n const buffer = Buffer.from(format === 'json' ? `[${outputData.join(',')}]` : outputData.join(''))\n if (debug) {\n req.payload.logger.info(`${format} file generation complete`)\n }\n\n if (!id) {\n if (debug) {\n req.payload.logger.info('Creating new export file')\n }\n req.file = {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n }\n } else {\n if (debug) {\n req.payload.logger.info(`Updating existing export with id: ${id}`)\n }\n await req.payload.update({\n id,\n collection: exportsCollection,\n data: {},\n file: {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n },\n user,\n })\n }\n if (debug) {\n req.payload.logger.info('Export process completed successfully')\n }\n}\n"],"names":["stringify","APIError","Readable","flattenObject","getCustomFieldFunctions","getFilename","getSelect","createExport","args","download","input","id","name","nameArg","collectionSlug","debug","drafts","exportsCollection","fields","format","locale","localeInput","sort","user","where","req","localeArg","payload","logger","info","message","collectionConfig","config","collections","find","slug","isCSV","select","Array","isArray","length","undefined","findArgs","collection","depth","draft","limit","overrideAccess","page","result","hasNextPage","toCSVFunctions","flattenedFields","encoder","TextEncoder","stream","read","isFirstBatch","docs","csvInput","map","doc","csvString","header","push","encode","Response","headers","outputData","jsonInput","JSON","join","buffer","Buffer","from","file","data","mimetype","size","update"],"mappings":"AAAA,6CAA6C,GAG7C,SAASA,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,QAAQ,QAAQ,UAAS;AAClC,SAASC,QAAQ,QAAQ,SAAQ;AAEjC,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,uBAAu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,IAAI,CAAC;QAC1B;QACAJ,IAAIkD,IAAI,GAAG;YACT/D;YACAgE,MAAMJ;YACNK,UAAUzC,QAAQ,aAAa;YAC/B0C,MAAMN,OAAOhC,MAAM;QACrB;IACF,OAAO;QACL,IAAIzB,OAAO;YACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAElB,IAAI;QACnE;QACA,MAAMc,IAAIE,OAAO,CAACoD,MAAM,CAAC;YACvBpE;YACAgC,YAAY1B;YACZ2D,MAAM,CAAC;YACPD,MAAM;gBACJ/D;gBACAgE,MAAMJ;gBACNK,UAAUzC,QAAQ,aAAa;gBAC/B0C,MAAMN,OAAOhC,MAAM;YACrB;YACAjB;QACF;IACF;IACA,IAAIR,OAAO;QACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC1B;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/export/createExport.ts"],"sourcesContent":["/* eslint-disable perfectionist/sort-objects */\nimport type { PayloadRequest, Sort, User, Where } from 'payload'\n\nimport { stringify } from 'csv-stringify/sync'\nimport { APIError } from 'payload'\nimport { Readable } from 'stream'\n\nimport { flattenObject } from './flattenObject.js'\nimport { getCustomFieldFunctions } from './getCustomFieldFunctions.js'\nimport { getFilename } from './getFilename.js'\nimport { getSelect } from './getSelect.js'\n\nexport type Export = {\n collectionSlug: string\n /**\n * If true, enables debug logging\n */\n debug?: boolean\n drafts?: 'no' | 'yes'\n exportsCollection: string\n fields?: string[]\n format: 'csv' | 'json'\n globals?: string[]\n id: number | string\n locale?: string\n name: string\n slug: string\n sort: Sort\n user: string\n userCollection: string\n where?: Where\n}\n\nexport type CreateExportArgs = {\n /**\n * If true, stream the file instead of saving it\n */\n download?: boolean\n input: Export\n req: PayloadRequest\n user?: User\n}\n\nexport const createExport = async (args: CreateExportArgs) => {\n const {\n download,\n input: {\n id,\n name: nameArg,\n collectionSlug,\n debug = false,\n drafts,\n exportsCollection,\n fields,\n format,\n locale: localeInput,\n sort,\n user,\n where,\n },\n req: { locale: localeArg, payload },\n req,\n } = args\n\n if (debug) {\n req.payload.logger.info({\n message: 'Starting export process with args:',\n collectionSlug,\n drafts,\n fields,\n format,\n })\n }\n\n const locale = localeInput ?? localeArg\n const collectionConfig = payload.config.collections.find(({ slug }) => slug === collectionSlug)\n if (!collectionConfig) {\n throw new APIError(`Collection with slug ${collectionSlug} not found`)\n }\n\n const name = `${nameArg ?? `${getFilename()}-${collectionSlug}`}.${format}`\n const isCSV = format === 'csv'\n const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined\n\n if (debug) {\n req.payload.logger.info({ message: 'Export configuration:', name, isCSV, locale })\n }\n\n const findArgs = {\n collection: collectionSlug,\n depth: 1,\n draft: drafts === 'yes',\n limit: 100,\n locale,\n overrideAccess: false,\n page: 0,\n select,\n sort,\n user,\n where,\n }\n\n if (debug) {\n req.payload.logger.info({ message: 'Find arguments:', findArgs })\n }\n\n const toCSVFunctions = getCustomFieldFunctions({\n fields: collectionConfig.flattenedFields,\n select,\n })\n\n if (download) {\n if (debug) {\n req.payload.logger.info('Starting download stream')\n }\n\n const encoder = new TextEncoder()\n let isFirstBatch = true\n let columns: string[] | undefined\n let page = 1\n\n const stream = new Readable({\n async read() {\n const result = await payload.find({\n ...findArgs,\n page,\n })\n\n if (debug) {\n req.payload.logger.info(`Processing batch ${page} with ${result.docs.length} documents`)\n }\n\n if (result.docs.length === 0) {\n this.push(null)\n return\n }\n\n const csvInput = result.docs.map((doc) => flattenObject({ doc, fields, toCSVFunctions }))\n\n if (isFirstBatch) {\n columns = Object.keys(csvInput[0] ?? {})\n }\n\n const csvString = stringify(csvInput, {\n header: isFirstBatch,\n columns,\n })\n\n this.push(encoder.encode(csvString))\n isFirstBatch = false\n\n if (!result.hasNextPage) {\n if (debug) {\n req.payload.logger.info('Stream complete - no more pages')\n }\n this.push(null) // End the stream\n }\n\n page += 1\n },\n })\n\n return new Response(stream as any, {\n headers: {\n 'Content-Disposition': `attachment; filename=\"${name}\"`,\n 'Content-Type': isCSV ? 'text/csv' : 'application/json',\n },\n })\n }\n\n if (debug) {\n req.payload.logger.info('Starting file generation')\n }\n const outputData: string[] = []\n let isFirstBatch = true\n let page = 1\n let hasNextPage = true\n\n while (hasNextPage) {\n const result = await payload.find({\n ...findArgs,\n page,\n })\n\n if (debug) {\n req.payload.logger.info(\n `Processing batch ${findArgs.page} with ${result.docs.length} documents`,\n )\n }\n\n if (isCSV) {\n const csvInput = result.docs.map((doc) => flattenObject({ doc, fields, toCSVFunctions }))\n outputData.push(stringify(csvInput, { header: isFirstBatch }))\n isFirstBatch = false\n } else {\n const jsonInput = result.docs.map((doc) => JSON.stringify(doc))\n outputData.push(jsonInput.join(',\\n'))\n }\n\n hasNextPage = result.hasNextPage\n page += 1\n }\n\n const buffer = Buffer.from(format === 'json' ? `[${outputData.join(',')}]` : outputData.join(''))\n if (debug) {\n req.payload.logger.info(`${format} file generation complete`)\n }\n\n if (!id) {\n if (debug) {\n req.payload.logger.info('Creating new export file')\n }\n req.file = {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n }\n } else {\n if (debug) {\n req.payload.logger.info(`Updating existing export with id: ${id}`)\n }\n await req.payload.update({\n id,\n collection: exportsCollection,\n data: {},\n file: {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n },\n user,\n })\n }\n if (debug) {\n req.payload.logger.info('Export process completed successfully')\n }\n}\n"],"names":["stringify","APIError","Readable","flattenObject","getCustomFieldFunctions","getFilename","getSelect","createExport","args","download","input","id","name","nameArg","collectionSlug","debug","drafts","exportsCollection","fields","format","locale","localeInput","sort","user","where","req","localeArg","payload","logger","info","message","collectionConfig","config","collections","find","slug","isCSV","select","Array","isArray","length","undefined","findArgs","collection","depth","draft","limit","overrideAccess","page","toCSVFunctions","flattenedFields","encoder","TextEncoder","isFirstBatch","columns","stream","read","result","docs","push","csvInput","map","doc","Object","keys","csvString","header","encode","hasNextPage","Response","headers","outputData","jsonInput","JSON","join","buffer","Buffer","from","file","data","mimetype","size","update"],"mappings":"AAAA,6CAA6C,GAG7C,SAASA,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,QAAQ,QAAQ,UAAS;AAClC,SAASC,QAAQ,QAAQ,SAAQ;AAEjC,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,SAAS,QAAQ,iBAAgB;AAiC1C,OAAO,MAAMC,eAAe,OAAOC;IACjC,MAAM,EACJC,QAAQ,EACRC,OAAO,EACLC,EAAE,EACFC,MAAMC,OAAO,EACbC,cAAc,EACdC,QAAQ,KAAK,EACbC,MAAM,EACNC,iBAAiB,EACjBC,MAAM,EACNC,MAAM,EACNC,QAAQC,WAAW,EACnBC,IAAI,EACJC,IAAI,EACJC,KAAK,EACN,EACDC,KAAK,EAAEL,QAAQM,SAAS,EAAEC,OAAO,EAAE,EACnCF,GAAG,EACJ,GAAGjB;IAEJ,IAAIO,OAAO;QACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;YACtBC,SAAS;YACThB;YACAE;YACAE;YACAC;QACF;IACF;IAEA,MAAMC,SAASC,eAAeK;IAC9B,MAAMK,mBAAmBJ,QAAQK,MAAM,CAACC,WAAW,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASrB;IAChF,IAAI,CAACiB,kBAAkB;QACrB,MAAM,IAAI9B,SAAS,CAAC,qBAAqB,EAAEa,eAAe,UAAU,CAAC;IACvE;IAEA,MAAMF,OAAO,GAAGC,WAAW,GAAGR,cAAc,CAAC,EAAES,gBAAgB,CAAC,CAAC,EAAEK,QAAQ;IAC3E,MAAMiB,QAAQjB,WAAW;IACzB,MAAMkB,SAASC,MAAMC,OAAO,CAACrB,WAAWA,OAAOsB,MAAM,GAAG,IAAIlC,U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AAS,CAAC8D;YAC1DS,WAAWZ,IAAI,CAACa,UAAUE,IAAI,CAAC;QACjC;QAEAN,cAAcX,OAAOW,WAAW;QAChCpB,QAAQ;IACV;IAEA,MAAM2B,SAASC,OAAOC,IAAI,CAAC1D,WAAW,SAAS,CAAC,CAAC,EAAEoD,WAAWG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAGH,WAAWG,IAAI,CAAC;IAC7F,IAAI3D,OAAO;QACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,GAAGV,OAAO,yBAAyB,CAAC;IAC9D;IAEA,IAAI,CAACR,IAAI;QACP,IAAII,OAAO;YACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;QAC1B;QACAJ,IAAIqD,IAAI,GAAG;YACTlE;YACAmE,MAAMJ;YACNK,UAAU5C,QAAQ,aAAa;YAC/B6C,MAAMN,OAAOnC,MAAM;QACrB;IACF,OAAO;QACL,IAAIzB,OAAO;YACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAElB,IAAI;QACnE;QACA,MAAMc,IAAIE,OAAO,CAACuD,MAAM,CAAC;YACvBvE;YACAgC,YAAY1B;YACZ8D,MAAM,CAAC;YACPD,MAAM;gBACJlE;gBACAmE,MAAMJ;gBACNK,UAAU5C,QAAQ,aAAa;gBAC/B6C,MAAMN,OAAOnC,MAAM;YACrB;YACAjB;QACF;IACF;IACA,IAAIR,OAAO;QACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC1B;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenObject.d.ts","sourceRoot":"","sources":["../../src/export/flattenObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,QAAQ,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;CAC9C,CAAA;AAED,eAAO,MAAM,aAAa,6CAKvB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"flattenObject.d.ts","sourceRoot":"","sources":["../../src/export/flattenObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,QAAQ,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;CAC9C,CAAA;AAED,eAAO,MAAM,aAAa,6CAKvB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CA+F/B,CAAA"}
|
|
@@ -12,6 +12,7 @@ export const flattenObject = ({ doc, fields, prefix, toCSVFunctions })=>{
|
|
|
12
12
|
const columnName = `${newKey}_${index}`;
|
|
13
13
|
const result = toCSVFunctions[newKey]({
|
|
14
14
|
columnName,
|
|
15
|
+
data: row,
|
|
15
16
|
doc,
|
|
16
17
|
row,
|
|
17
18
|
siblingDoc,
|
|
@@ -31,6 +32,7 @@ export const flattenObject = ({ doc, fields, prefix, toCSVFunctions })=>{
|
|
|
31
32
|
} else {
|
|
32
33
|
const result = toCSVFunctions[newKey]({
|
|
33
34
|
columnName: newKey,
|
|
35
|
+
data: row,
|
|
34
36
|
doc,
|
|
35
37
|
row,
|
|
36
38
|
siblingDoc,
|
|
@@ -44,6 +46,7 @@ export const flattenObject = ({ doc, fields, prefix, toCSVFunctions })=>{
|
|
|
44
46
|
if (toCSVFunctions?.[newKey]) {
|
|
45
47
|
const result = toCSVFunctions[newKey]({
|
|
46
48
|
columnName: newKey,
|
|
49
|
+
data: row,
|
|
47
50
|
doc,
|
|
48
51
|
row,
|
|
49
52
|
siblingDoc,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/flattenObject.ts"],"sourcesContent":["import type { Document } from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\ntype Args = {\n doc: Document\n fields?: string[]\n prefix?: string\n toCSVFunctions: Record<string, ToCSVFunction>\n}\n\nexport const flattenObject = ({\n doc,\n fields,\n prefix,\n toCSVFunctions,\n}: Args): Record<string, unknown> => {\n const row: Record<string, unknown> = {}\n\n const flatten = (siblingDoc: Document, prefix?: string) => {\n Object.entries(siblingDoc).forEach(([key, value]) => {\n const newKey = prefix ? `${prefix}_${key}` : key\n\n if (Array.isArray(value)) {\n value.forEach((item, index) => {\n if (typeof item === 'object' && item !== null) {\n flatten(item, `${newKey}_${index}`)\n } else {\n if (toCSVFunctions?.[newKey]) {\n const columnName = `${newKey}_${index}`\n const result = toCSVFunctions[newKey]({\n columnName,\n doc,\n row,\n siblingDoc,\n value: item,\n })\n if (typeof result !== 'undefined') {\n row[columnName] = result\n }\n } else {\n row[`${newKey}_${index}`] = item\n }\n }\n })\n } else if (typeof value === 'object' && value !== null) {\n if (!toCSVFunctions?.[newKey]) {\n flatten(value, newKey)\n } else {\n const result = toCSVFunctions[newKey]({\n columnName: newKey,\n doc,\n row,\n siblingDoc,\n value,\n })\n if (typeof result !== 'undefined') {\n row[newKey] = result\n }\n }\n } else {\n if (toCSVFunctions?.[newKey]) {\n const result = toCSVFunctions[newKey]({\n columnName: newKey,\n doc,\n row,\n siblingDoc,\n value,\n })\n if (typeof result !== 'undefined') {\n row[newKey] = result\n }\n } else {\n row[newKey] = value\n }\n }\n })\n }\n\n flatten(doc, prefix)\n\n if (Array.isArray(fields) && fields.length > 0) {\n const orderedResult: Record<string, unknown> = {}\n\n const fieldToRegex = (field: string): RegExp => {\n const parts = field.split('.').map((part) => `${part}(?:_\\\\d+)?`)\n const pattern = `^${parts.join('_')}`\n return new RegExp(pattern)\n }\n\n fields.forEach((field) => {\n if (row[field.replace(/\\./g, '_')]) {\n const sanitizedField = field.replace(/\\./g, '_')\n orderedResult[sanitizedField] = row[sanitizedField]\n } else {\n const regex = fieldToRegex(field)\n Object.keys(row).forEach((key) => {\n if (regex.test(key)) {\n orderedResult[key] = row[key]\n }\n })\n }\n })\n\n return orderedResult\n }\n\n return row\n}\n"],"names":["flattenObject","doc","fields","prefix","toCSVFunctions","row","flatten","siblingDoc","Object","entries","forEach","key","value","newKey","Array","isArray","item","index","columnName","result","length","orderedResult","fieldToRegex","field","parts","split","map","part","pattern","join","RegExp","replace","sanitizedField","regex","keys","test"],"mappings":"AAWA,OAAO,MAAMA,gBAAgB,CAAC,EAC5BC,GAAG,EACHC,MAAM,EACNC,MAAM,EACNC,cAAc,EACT;IACL,MAAMC,MAA+B,CAAC;IAEtC,MAAMC,UAAU,CAACC,YAAsBJ;QACrCK,OAAOC,OAAO,CAACF,YAAYG,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;YAC9C,MAAMC,SAASV,SAAS,GAAGA,OAAO,CAAC,EAAEQ,KAAK,GAAGA;YAE7C,IAAIG,MAAMC,OAAO,CAACH,QAAQ;gBACxBA,MAAMF,OAAO,CAAC,CAACM,MAAMC;oBACnB,IAAI,OAAOD,SAAS,YAAYA,SAAS,MAAM;wBAC7CV,QAAQU,MAAM,GAAGH,OAAO,CAAC,EAAEI,OAAO;oBACpC,OAAO;wBACL,IAAIb,gBAAgB,CAACS,OAAO,EAAE;4BAC5B,MAAMK,aAAa,GAAGL,OAAO,CAAC,EAAEI,OAAO;4BACvC,MAAME,SAASf,cAAc,CAACS,OAAO,CAAC;gCACpCK;
|
|
1
|
+
{"version":3,"sources":["../../src/export/flattenObject.ts"],"sourcesContent":["import type { Document } from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\ntype Args = {\n doc: Document\n fields?: string[]\n prefix?: string\n toCSVFunctions: Record<string, ToCSVFunction>\n}\n\nexport const flattenObject = ({\n doc,\n fields,\n prefix,\n toCSVFunctions,\n}: Args): Record<string, unknown> => {\n const row: Record<string, unknown> = {}\n\n const flatten = (siblingDoc: Document, prefix?: string) => {\n Object.entries(siblingDoc).forEach(([key, value]) => {\n const newKey = prefix ? `${prefix}_${key}` : key\n\n if (Array.isArray(value)) {\n value.forEach((item, index) => {\n if (typeof item === 'object' && item !== null) {\n flatten(item, `${newKey}_${index}`)\n } else {\n if (toCSVFunctions?.[newKey]) {\n const columnName = `${newKey}_${index}`\n const result = toCSVFunctions[newKey]({\n columnName,\n data: row,\n doc,\n row,\n siblingDoc,\n value: item,\n })\n if (typeof result !== 'undefined') {\n row[columnName] = result\n }\n } else {\n row[`${newKey}_${index}`] = item\n }\n }\n })\n } else if (typeof value === 'object' && value !== null) {\n if (!toCSVFunctions?.[newKey]) {\n flatten(value, newKey)\n } else {\n const result = toCSVFunctions[newKey]({\n columnName: newKey,\n data: row,\n doc,\n row,\n siblingDoc,\n value,\n })\n if (typeof result !== 'undefined') {\n row[newKey] = result\n }\n }\n } else {\n if (toCSVFunctions?.[newKey]) {\n const result = toCSVFunctions[newKey]({\n columnName: newKey,\n data: row,\n doc,\n row,\n siblingDoc,\n value,\n })\n if (typeof result !== 'undefined') {\n row[newKey] = result\n }\n } else {\n row[newKey] = value\n }\n }\n })\n }\n\n flatten(doc, prefix)\n\n if (Array.isArray(fields) && fields.length > 0) {\n const orderedResult: Record<string, unknown> = {}\n\n const fieldToRegex = (field: string): RegExp => {\n const parts = field.split('.').map((part) => `${part}(?:_\\\\d+)?`)\n const pattern = `^${parts.join('_')}`\n return new RegExp(pattern)\n }\n\n fields.forEach((field) => {\n if (row[field.replace(/\\./g, '_')]) {\n const sanitizedField = field.replace(/\\./g, '_')\n orderedResult[sanitizedField] = row[sanitizedField]\n } else {\n const regex = fieldToRegex(field)\n Object.keys(row).forEach((key) => {\n if (regex.test(key)) {\n orderedResult[key] = row[key]\n }\n })\n }\n })\n\n return orderedResult\n }\n\n return row\n}\n"],"names":["flattenObject","doc","fields","prefix","toCSVFunctions","row","flatten","siblingDoc","Object","entries","forEach","key","value","newKey","Array","isArray","item","index","columnName","result","data","length","orderedResult","fieldToRegex","field","parts","split","map","part","pattern","join","RegExp","replace","sanitizedField","regex","keys","test"],"mappings":"AAWA,OAAO,MAAMA,gBAAgB,CAAC,EAC5BC,GAAG,EACHC,MAAM,EACNC,MAAM,EACNC,cAAc,EACT;IACL,MAAMC,MAA+B,CAAC;IAEtC,MAAMC,UAAU,CAACC,YAAsBJ;QACrCK,OAAOC,OAAO,CAACF,YAAYG,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;YAC9C,MAAMC,SAASV,SAAS,GAAGA,OAAO,CAAC,EAAEQ,KAAK,GAAGA;YAE7C,IAAIG,MAAMC,OAAO,CAACH,QAAQ;gBACxBA,MAAMF,OAAO,CAAC,CAACM,MAAMC;oBACnB,IAAI,OAAOD,SAAS,YAAYA,SAAS,MAAM;wBAC7CV,QAAQU,MAAM,GAAGH,OAAO,CAAC,EAAEI,OAAO;oBACpC,OAAO;wBACL,IAAIb,gBAAgB,CAACS,OAAO,EAAE;4BAC5B,MAAMK,aAAa,GAAGL,OAAO,CAAC,EAAEI,OAAO;4BACvC,MAAME,SAASf,cAAc,CAACS,OAAO,CAAC;gCACpCK;gCACAE,MAAMf;gCACNJ;gCACAI;gCACAE;gCACAK,OAAOI;4BACT;4BACA,IAAI,OAAOG,WAAW,aAAa;gCACjCd,GAAG,CAACa,WAAW,GAAGC;4BACpB;wBACF,OAAO;4BACLd,GAAG,CAAC,GAAGQ,OAAO,CAAC,EAAEI,OAAO,CAAC,GAAGD;wBAC9B;oBACF;gBACF;YACF,OAAO,IAAI,OAAOJ,UAAU,YAAYA,UAAU,MAAM;gBACtD,IAAI,CAACR,gBAAg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BACnBW,aAAa,CAACX,IAAI,GAAGN,GAAG,CAACM,IAAI;oBAC/B;gBACF;YACF;QACF;QAEA,OAAOW;IACT;IAEA,OAAOjB;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCustomFieldFunctions.d.ts","sourceRoot":"","sources":["../../src/export/getCustomFieldFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EAGvB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,EAAE,iBAAiB,GAAG,SAAS,CAAA;CACtC,CAAA;AAED,eAAO,MAAM,uBAAuB,wBAGjC,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"getCustomFieldFunctions.d.ts","sourceRoot":"","sources":["../../src/export/getCustomFieldFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EAGvB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,EAAE,iBAAiB,GAAG,SAAS,CAAA;CACtC,CAAA;AAED,eAAO,MAAM,uBAAuB,wBAGjC,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CA4FrC,CAAA"}
|
|
@@ -23,10 +23,16 @@ export const getCustomFieldFunctions = ({ fields, select })=>{
|
|
|
23
23
|
// polymorphic single
|
|
24
24
|
// @ts-expect-error ref is untyped
|
|
25
25
|
result[`${ref.prefix}${field.name}`] = ({ data, value })=>{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
if (value && typeof value === 'object' && 'relationTo' in value && 'value' in value) {
|
|
27
|
+
const relationTo = value.relationTo;
|
|
28
|
+
const relatedDoc = value.value;
|
|
29
|
+
if (relatedDoc && typeof relatedDoc === 'object') {
|
|
30
|
+
// @ts-expect-error ref is untyped
|
|
31
|
+
data[`${ref.prefix}${field.name}_id`] = relatedDoc.id;
|
|
32
|
+
// @ts-expect-error ref is untyped
|
|
33
|
+
data[`${ref.prefix}${field.name}_relationTo`] = relationTo;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
30
36
|
return undefined;
|
|
31
37
|
};
|
|
32
38
|
}
|
|
@@ -38,13 +44,23 @@ export const getCustomFieldFunctions = ({ fields, select })=>{
|
|
|
38
44
|
} else {
|
|
39
45
|
// polymorphic many
|
|
40
46
|
// @ts-expect-error ref is untyped
|
|
41
|
-
result[`${ref.prefix}${field.name}`] = ({ data, value })=>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
result[`${ref.prefix}${field.name}`] = ({ data, value })=>{
|
|
48
|
+
if (Array.isArray(value)) {
|
|
49
|
+
value.forEach((val, i)=>{
|
|
50
|
+
if (val && typeof val === 'object') {
|
|
51
|
+
const relationTo = val.relationTo;
|
|
52
|
+
const relatedDoc = val.value;
|
|
53
|
+
if (relationTo && relatedDoc && typeof relatedDoc === 'object') {
|
|
54
|
+
// @ts-expect-error ref is untyped
|
|
55
|
+
data[`${ref.prefix}${field.name}_${i}_id`] = relatedDoc.id;
|
|
56
|
+
// @ts-expect-error ref is untyped
|
|
57
|
+
data[`${ref.prefix}${field.name}_${i}_relationTo`] = relationTo;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
};
|
|
48
64
|
}
|
|
49
65
|
}
|
|
50
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/getCustomFieldFunctions.ts"],"sourcesContent":["import {\n type FlattenedField,\n type SelectIncludeType,\n traverseFields,\n type TraverseFieldsCallback,\n} from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\ntype Args = {\n fields: FlattenedField[]\n select: SelectIncludeType | undefined\n}\n\nexport const getCustomFieldFunctions = ({\n fields,\n select,\n}: Args): Record<string, ToCSVFunction> => {\n const result: Record<string, ToCSVFunction> = {}\n\n const buildCustomFunctions: TraverseFieldsCallback = ({ field, parentRef, ref }) => {\n // @ts-expect-error ref is untyped\n ref.prefix = parentRef.prefix || ''\n if (field.type === 'group' || field.type === 'tab') {\n // @ts-expect-error ref is untyped\n const parentPrefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n // @ts-expect-error ref is untyped\n ref.prefix = `${parentPrefix}${field.name}_`\n }\n\n if (typeof field.custom?.['plugin-import-export']?.toCSV === 'function') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = field.custom['plugin-import-export']?.toCSV\n } else if (field.type === 'relationship' || field.type === 'upload') {\n if (field.hasMany !== true) {\n if (!Array.isArray(field.relationTo)) {\n // monomorphic single\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) =>\n typeof value === 'object' && value && 'id' in value ? value.id : value\n } else {\n // polymorphic single\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ data, value }) => {\n // @ts-expect-error ref is untyped\n
|
|
1
|
+
{"version":3,"sources":["../../src/export/getCustomFieldFunctions.ts"],"sourcesContent":["import {\n type FlattenedField,\n type SelectIncludeType,\n traverseFields,\n type TraverseFieldsCallback,\n} from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\ntype Args = {\n fields: FlattenedField[]\n select: SelectIncludeType | undefined\n}\n\nexport const getCustomFieldFunctions = ({\n fields,\n select,\n}: Args): Record<string, ToCSVFunction> => {\n const result: Record<string, ToCSVFunction> = {}\n\n const buildCustomFunctions: TraverseFieldsCallback = ({ field, parentRef, ref }) => {\n // @ts-expect-error ref is untyped\n ref.prefix = parentRef.prefix || ''\n if (field.type === 'group' || field.type === 'tab') {\n // @ts-expect-error ref is untyped\n const parentPrefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n // @ts-expect-error ref is untyped\n ref.prefix = `${parentPrefix}${field.name}_`\n }\n\n if (typeof field.custom?.['plugin-import-export']?.toCSV === 'function') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = field.custom['plugin-import-export']?.toCSV\n } else if (field.type === 'relationship' || field.type === 'upload') {\n if (field.hasMany !== true) {\n if (!Array.isArray(field.relationTo)) {\n // monomorphic single\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) =>\n typeof value === 'object' && value && 'id' in value ? value.id : value\n } else {\n // polymorphic single\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ data, value }) => {\n if (value && typeof value === 'object' && 'relationTo' in value && 'value' in value) {\n const relationTo = (value as { relationTo: string; value: { id: number | string } })\n .relationTo\n const relatedDoc = (value as { relationTo: string; value: { id: number | string } })\n .value\n if (relatedDoc && typeof relatedDoc === 'object') {\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_id`] = relatedDoc.id\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_relationTo`] = relationTo\n }\n }\n return undefined\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 value,\n }: {\n value: Record<string, unknown>[]\n }) =>\n value.map((val: number | Record<string, unknown> | string) =>\n typeof val === 'object' ? val.id : val,\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 // TODO: do this so we only return the functions needed based on the select used\n ////@ts-expect-error ref is untyped\n // ref.select = typeof select !== 'undefined' || select[field.name] ? select : {}\n }\n\n traverseFields({ callback: buildCustomFunctions, fields })\n\n return result\n}\n"],"names":["traverseFields","getCustomFieldFunctions","fields","select","result","buildCustomFunctions","field","parentRef","ref","prefix","type","parentPrefix","name","custom","toCSV","hasMany","Array","isArray","relationTo","value","id","data","relatedDoc","undefined","map","val","forEach","i","callback"],"mappings":"AAAA,SAGEA,cAAc,QAET,UAAS;AAShB,OAAO,MAAMC,0BAA0B,CAAC,EACtCC,MAAM,EACNC,MAAM,EACD;IACL,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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L,EAAE,GAAGK;gBAEzC,OAAO;oBACL,mBAAmB;oBACnB,kCAAkC;oBAClCrB,MAAM,CAAC,GAAGI,IAAIC,MAAM,GAAGH,MAAMM,IAAI,EAAE,CAAC,GAAG,CAAC,EACtCS,IAAI,EACJF,KAAK,EAIN;wBACC,IAAIH,MAAMC,OAAO,CAACE,QAAQ;4BACxBA,MAAMO,OAAO,CAAC,CAACD,KAAKE;gCAClB,IAAIF,OAAO,OAAOA,QAAQ,UAAU;oCAClC,MAAMP,aAAaO,IAAIP,UAAU;oCACjC,MAAMI,aAAaG,IAAIN,KAAK;oCAC5B,IAAID,cAAcI,cAAc,OAAOA,eAAe,UAAU;wCAC9D,kCAAkC;wCAClCD,IAAI,CAAC,GAAGb,IAAIC,MAAM,GAAGH,MAAMM,IAAI,CAAC,CAAC,EAAEe,EAAE,GAAG,CAAC,CAAC,GAAGL,WAAWF,EAAE;wCAC1D,kCAAkC;wCAClCC,IAAI,CAAC,GAAGb,IAAIC,MAAM,GAAGH,MAAMM,IAAI,CAAC,CAAC,EAAEe,EAAE,WAAW,CAAC,CAAC,GAAGT;oCACvD;gCACF;4BACF;wBACF;wBACA,OAAOK;oBACT;gBACF;YACF;QACF;IAEA,gFAAgF;IAChF,mCAAmC;IACnC,iFAAiF;IACnF;IAEAvB,eAAe;QAAE4B,UAAUvB;QAAsBH;IAAO;IAExD,OAAOE;AACT,EAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -32,6 +32,11 @@ export type ToCSVFunction = (args: {
|
|
|
32
32
|
* The path of the column for the field, for arrays this includes the index (zero-based)
|
|
33
33
|
*/
|
|
34
34
|
columnName: string;
|
|
35
|
+
/**
|
|
36
|
+
* Alias for `row`, the object that accumulates CSV output.
|
|
37
|
+
* Use this to write additional fields into the exported row.
|
|
38
|
+
*/
|
|
39
|
+
data: Record<string, unknown>;
|
|
35
40
|
/**
|
|
36
41
|
* The top level document
|
|
37
42
|
*/
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAErF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,sBAAsB,CAAA;IAC7B,MAAM,EAAE,YAAY,CAAA;CACrB,GAAG,gBAAgB,CAAA;AAEpB,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,kBAAkB,CAAA;CAClF,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE;IACjC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,GAAG,EAAE,QAAQ,CAAA;IACb;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC;;OAEG;IACH,KAAK,EAAE,OAAO,CAAA;CACf,KAAK,OAAO,CAAA"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAErF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,sBAAsB,CAAA;IAC7B,MAAM,EAAE,YAAY,CAAA;CACrB,GAAG,gBAAgB,CAAA;AAEpB,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,kBAAkB,CAAA;CAClF,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE;IACjC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B;;OAEG;IACH,GAAG,EAAE,QAAQ,CAAA;IACb;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC;;OAEG;IACH,KAAK,EAAE,OAAO,CAAA;CACf,KAAK,OAAO,CAAA"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { CollectionAdminOptions, CollectionConfig, UploadConfig } from 'payload'\n\nexport type CollectionOverride = {\n admin: CollectionAdminOptions\n upload: UploadConfig\n} & CollectionConfig\n\nexport type ImportExportPluginConfig = {\n /**\n * Collections to include the Import/Export controls in\n * Defaults to all collections\n */\n collections?: string[]\n /**\n * If true, enables debug logging\n */\n debug?: boolean\n /**\n * Enable to force the export to run synchronously\n */\n disableJobsQueue?: boolean\n /**\n * This function takes the default export collection configured in the plugin and allows you to override it by modifying and returning it\n * @param collection\n * @returns collection\n */\n overrideExportCollection?: (collection: CollectionOverride) => CollectionOverride\n}\n\n/**\n * Custom function used to modify the outgoing csv data by manipulating the data, siblingData or by returning the desired value\n */\nexport type ToCSVFunction = (args: {\n /**\n * The path of the column for the field, for arrays this includes the index (zero-based)\n */\n columnName: string\n /**\n * The top level document\n */\n doc: Document\n /**\n * The object data that can be manipulated to assign data to the CSV\n */\n row: Record<string, unknown>\n /**\n * The document data at the level where it belongs\n */\n siblingDoc: Record<string, unknown>\n /**\n * The data for the field.\n */\n value: unknown\n}) => unknown\n"],"names":[],"mappings":"AA6BA;;CAEC,GACD,
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { CollectionAdminOptions, CollectionConfig, UploadConfig } from 'payload'\n\nexport type CollectionOverride = {\n admin: CollectionAdminOptions\n upload: UploadConfig\n} & CollectionConfig\n\nexport type ImportExportPluginConfig = {\n /**\n * Collections to include the Import/Export controls in\n * Defaults to all collections\n */\n collections?: string[]\n /**\n * If true, enables debug logging\n */\n debug?: boolean\n /**\n * Enable to force the export to run synchronously\n */\n disableJobsQueue?: boolean\n /**\n * This function takes the default export collection configured in the plugin and allows you to override it by modifying and returning it\n * @param collection\n * @returns collection\n */\n overrideExportCollection?: (collection: CollectionOverride) => CollectionOverride\n}\n\n/**\n * Custom function used to modify the outgoing csv data by manipulating the data, siblingData or by returning the desired value\n */\nexport type ToCSVFunction = (args: {\n /**\n * The path of the column for the field, for arrays this includes the index (zero-based)\n */\n columnName: string\n /**\n * Alias for `row`, the object that accumulates CSV output.\n * Use this to write additional fields into the exported row.\n */\n data: Record<string, unknown>\n /**\n * The top level document\n */\n doc: Document\n /**\n * The object data that can be manipulated to assign data to the CSV\n */\n row: Record<string, unknown>\n /**\n * The document data at the level where it belongs\n */\n siblingDoc: Record<string, unknown>\n /**\n * The data for the field.\n */\n value: unknown\n}) => unknown\n"],"names":[],"mappings":"AA6BA;;CAEC,GACD,WA0Ba"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-import-export",
|
|
3
|
-
"version": "3.44.0-
|
|
3
|
+
"version": "3.44.0-internal.6b79dc2",
|
|
4
4
|
"description": "Import-Export plugin for Payload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"payload",
|
|
@@ -64,17 +64,17 @@
|
|
|
64
64
|
"csv-parse": "^5.6.0",
|
|
65
65
|
"csv-stringify": "^6.5.2",
|
|
66
66
|
"qs-esm": "7.0.2",
|
|
67
|
-
"@payloadcms/translations": "3.44.0-
|
|
68
|
-
"@payloadcms/ui": "3.44.0-
|
|
67
|
+
"@payloadcms/translations": "3.44.0-internal.6b79dc2",
|
|
68
|
+
"@payloadcms/ui": "3.44.0-internal.6b79dc2"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
+
"@payloadcms/ui": "3.44.0-internal.6b79dc2",
|
|
71
72
|
"@payloadcms/eslint-config": "3.28.0",
|
|
72
|
-
"payload": "3.44.0-
|
|
73
|
-
"@payloadcms/ui": "3.44.0-canary.8"
|
|
73
|
+
"payload": "3.44.0-internal.6b79dc2"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"@payloadcms/ui": "3.44.0-
|
|
77
|
-
"payload": "3.44.0-
|
|
76
|
+
"@payloadcms/ui": "3.44.0-internal.6b79dc2",
|
|
77
|
+
"payload": "3.44.0-internal.6b79dc2"
|
|
78
78
|
},
|
|
79
79
|
"homepage:": "https://payloadcms.com",
|
|
80
80
|
"scripts": {
|