@payloadcms/plugin-import-export 3.42.0-internal.f9d0258 → 3.42.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.
Files changed (41) hide show
  1. package/dist/export/createExport.d.ts +5 -2
  2. package/dist/export/createExport.d.ts.map +1 -1
  3. package/dist/export/createExport.js +64 -6
  4. package/dist/export/createExport.js.map +1 -1
  5. package/dist/export/download.d.ts +2 -2
  6. package/dist/export/download.d.ts.map +1 -1
  7. package/dist/export/download.js +5 -2
  8. package/dist/export/download.js.map +1 -1
  9. package/dist/export/flattenObject.d.ts +3 -1
  10. package/dist/export/flattenObject.d.ts.map +1 -1
  11. package/dist/export/flattenObject.js +43 -12
  12. package/dist/export/flattenObject.js.map +1 -1
  13. package/dist/export/getCreateExportCollectionTask.d.ts +6 -2
  14. package/dist/export/getCreateExportCollectionTask.d.ts.map +1 -1
  15. package/dist/export/getCreateExportCollectionTask.js +2 -9
  16. package/dist/export/getCreateExportCollectionTask.js.map +1 -1
  17. package/dist/export/getCustomFieldFunctions.d.ts +9 -0
  18. package/dist/export/getCustomFieldFunctions.d.ts.map +1 -0
  19. package/dist/export/getCustomFieldFunctions.js +62 -0
  20. package/dist/export/getCustomFieldFunctions.js.map +1 -0
  21. package/dist/export/getSelect.d.ts +2 -2
  22. package/dist/export/getSelect.d.ts.map +1 -1
  23. package/dist/export/getSelect.js +0 -4
  24. package/dist/export/getSelect.js.map +1 -1
  25. package/dist/exports/types.d.ts +1 -1
  26. package/dist/exports/types.d.ts.map +1 -1
  27. package/dist/exports/types.js.map +1 -1
  28. package/dist/getExportCollection.d.ts.map +1 -1
  29. package/dist/getExportCollection.js +5 -1
  30. package/dist/getExportCollection.js.map +1 -1
  31. package/dist/index.d.ts +8 -1
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +1 -7
  34. package/dist/index.js.map +1 -1
  35. package/dist/translations/languages/zhTw.js +10 -10
  36. package/dist/translations/languages/zhTw.js.map +1 -1
  37. package/dist/types.d.ts +29 -0
  38. package/dist/types.d.ts.map +1 -1
  39. package/dist/types.js +3 -1
  40. package/dist/types.js.map +1 -1
  41. package/package.json +8 -8
@@ -1,6 +1,10 @@
1
1
  import type { PayloadRequest, Sort, User, Where } from 'payload';
2
- type Export = {
2
+ export type Export = {
3
3
  collectionSlug: string;
4
+ /**
5
+ * If true, enables debug logging
6
+ */
7
+ debug?: boolean;
4
8
  drafts?: 'no' | 'yes';
5
9
  exportsCollection: string;
6
10
  fields?: string[];
@@ -25,5 +29,4 @@ export type CreateExportArgs = {
25
29
  user?: User;
26
30
  };
27
31
  export declare const createExport: (args: CreateExportArgs) => Promise<Response | undefined>;
28
- export {};
29
32
  //# sourceMappingURL=createExport.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createExport.d.ts","sourceRoot":"","sources":["../../src/export/createExport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,cAAc,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAU/E,KAAK,MAAM,GAAG;IACZ,cAAc,EAAE,MAAM,CAAA;IACtB,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,kCAoHxD,CAAA"}
1
+ {"version":3,"file":"createExport.d.ts","sourceRoot":"","sources":["../../src/export/createExport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAiB,cAAc,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAW/E,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,kCA8KxD,CAAA"}
@@ -1,11 +1,21 @@
1
- import { stringify } from 'csv-stringify/sync';
1
+ /* eslint-disable perfectionist/sort-objects */ import { stringify } from 'csv-stringify/sync';
2
2
  import { APIError } from 'payload';
3
3
  import { Readable } from 'stream';
4
4
  import { flattenObject } from './flattenObject.js';
5
+ import { getCustomFieldFunctions } from './getCustomFieldFunctions.js';
5
6
  import { getFilename } from './getFilename.js';
6
7
  import { getSelect } from './getSelect.js';
7
8
  export const createExport = async (args)=>{
8
- const { download, input: { id, name: nameArg, collectionSlug, drafts, exportsCollection, fields, format, locale: localeInput, sort, user, where }, req: { locale: localeArg, payload }, req } = args;
9
+ const { download, input: { id, name: nameArg, collectionSlug, debug = false, drafts, exportsCollection, fields, format, locale: localeInput, sort, user, where }, req: { locale: localeArg, payload }, req } = args;
10
+ if (debug) {
11
+ req.payload.logger.info({
12
+ message: 'Starting export process with args:',
13
+ collectionSlug,
14
+ drafts,
15
+ fields,
16
+ format
17
+ });
18
+ }
9
19
  const locale = localeInput ?? localeArg;
10
20
  const collectionConfig = payload.config.collections.find(({ slug })=>slug === collectionSlug);
11
21
  if (!collectionConfig) {
@@ -13,32 +23,58 @@ export const createExport = async (args)=>{
13
23
  }
14
24
  const name = `${nameArg ?? `${getFilename()}-${collectionSlug}`}.${format}`;
15
25
  const isCSV = format === 'csv';
26
+ const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined;
27
+ if (debug) {
28
+ req.payload.logger.info({
29
+ message: 'Export configuration:',
30
+ name,
31
+ isCSV,
32
+ locale
33
+ });
34
+ }
16
35
  const findArgs = {
17
36
  collection: collectionSlug,
18
- depth: 0,
37
+ depth: 1,
19
38
  draft: drafts === 'yes',
20
39
  limit: 100,
21
40
  locale,
22
41
  overrideAccess: false,
23
42
  page: 0,
24
- select: Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined,
43
+ select,
25
44
  sort,
26
45
  user,
27
46
  where
28
47
  };
48
+ if (debug) {
49
+ req.payload.logger.info({
50
+ message: 'Find arguments:',
51
+ findArgs
52
+ });
53
+ }
29
54
  let result = {
30
55
  hasNextPage: true
31
56
  };
57
+ const toCSVFunctions = getCustomFieldFunctions({
58
+ fields: collectionConfig.flattenedFields,
59
+ select
60
+ });
32
61
  if (download) {
62
+ if (debug) {
63
+ req.payload.logger.info('Starting download stream');
64
+ }
33
65
  const encoder = new TextEncoder();
34
66
  const stream = new Readable({
35
67
  async read () {
36
68
  let result = await payload.find(findArgs);
37
69
  let isFirstBatch = true;
38
70
  while(result.docs.length > 0){
71
+ if (debug) {
72
+ req.payload.logger.info(`Processing batch ${findArgs.page + 1} with ${result.docs.length} documents`);
73
+ }
39
74
  const csvInput = result.docs.map((doc)=>flattenObject({
40
75
  doc,
41
- fields
76
+ fields,
77
+ toCSVFunctions
42
78
  }));
43
79
  const csvString = stringify(csvInput, {
44
80
  header: isFirstBatch
@@ -46,6 +82,9 @@ export const createExport = async (args)=>{
46
82
  this.push(encoder.encode(csvString));
47
83
  isFirstBatch = false;
48
84
  if (!result.hasNextPage) {
85
+ if (debug) {
86
+ req.payload.logger.info('Stream complete - no more pages');
87
+ }
49
88
  this.push(null) // End the stream
50
89
  ;
51
90
  break;
@@ -62,15 +101,22 @@ export const createExport = async (args)=>{
62
101
  }
63
102
  });
64
103
  }
104
+ if (debug) {
105
+ req.payload.logger.info('Starting file generation');
106
+ }
65
107
  const outputData = [];
66
108
  let isFirstBatch = true;
67
109
  while(result.hasNextPage){
68
110
  findArgs.page += 1;
69
111
  result = await payload.find(findArgs);
112
+ if (debug) {
113
+ req.payload.logger.info(`Processing batch ${findArgs.page} with ${result.docs.length} documents`);
114
+ }
70
115
  if (isCSV) {
71
116
  const csvInput = result.docs.map((doc)=>flattenObject({
72
117
  doc,
73
- fields
118
+ fields,
119
+ toCSVFunctions
74
120
  }));
75
121
  outputData.push(stringify(csvInput, {
76
122
  header: isFirstBatch
@@ -82,7 +128,13 @@ export const createExport = async (args)=>{
82
128
  }
83
129
  }
84
130
  const buffer = Buffer.from(format === 'json' ? `[${outputData.join(',')}]` : outputData.join(''));
131
+ if (debug) {
132
+ req.payload.logger.info(`${format} file generation complete`);
133
+ }
85
134
  if (!id) {
135
+ if (debug) {
136
+ req.payload.logger.info('Creating new export file');
137
+ }
86
138
  req.file = {
87
139
  name,
88
140
  data: buffer,
@@ -90,6 +142,9 @@ export const createExport = async (args)=>{
90
142
  size: buffer.length
91
143
  };
92
144
  } else {
145
+ if (debug) {
146
+ req.payload.logger.info(`Updating existing export with id: ${id}`);
147
+ }
93
148
  await req.payload.update({
94
149
  id,
95
150
  collection: exportsCollection,
@@ -103,6 +158,9 @@ export const createExport = async (args)=>{
103
158
  user
104
159
  });
105
160
  }
161
+ if (debug) {
162
+ req.payload.logger.info('Export process completed successfully');
163
+ }
106
164
  };
107
165
 
108
166
  //# sourceMappingURL=createExport.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/export/createExport.ts"],"sourcesContent":["import 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 { getFilename } from './getFilename.js'\nimport { getSelect } from './getSelect.js'\n\ntype Export = {\n collectionSlug: string\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 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 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\n const findArgs = {\n collection: collectionSlug,\n depth: 0,\n draft: drafts === 'yes',\n limit: 100,\n locale,\n overrideAccess: false,\n page: 0,\n select: Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined,\n sort,\n user,\n where,\n }\n\n let result: PaginatedDocs = { hasNextPage: true } as PaginatedDocs\n\n if (download) {\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 const csvInput = result.docs.map((doc) => flattenObject({ doc, fields }))\n const csvString = stringify(csvInput, { header: isFirstBatch })\n this.push(encoder.encode(csvString))\n isFirstBatch = false\n\n if (!result.hasNextPage) {\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 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 (isCSV) {\n const csvInput = result.docs.map((doc) => flattenObject({ doc, fields }))\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\n if (!id) {\n req.file = {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n }\n } else {\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}\n"],"names":["stringify","APIError","Readable","flattenObject","getFilename","getSelect","createExport","args","download","input","id","name","nameArg","collectionSlug","drafts","exportsCollection","fields","format","locale","localeInput","sort","user","where","req","localeArg","payload","collectionConfig","config","collections","find","slug","isCSV","findArgs","collection","depth","draft","limit","overrideAccess","page","select","Array","isArray","length","undefined","result","hasNextPage","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":"AAEA,SAASA,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,QAAQ,QAAQ,UAAS;AAClC,SAASC,QAAQ,QAAQ,SAAQ;AAEjC,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,SAAS,QAAQ,iBAAgB;AA6B1C,OAAO,MAAMC,eAAe,OAAOC;IACjC,MAAM,EACJC,QAAQ,EACRC,OAAO,EACLC,EAAE,EACFC,MAAMC,OAAO,EACbC,cAAc,EACdC,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,GAAGhB;IACJ,MAAMW,SAASC,eAAeK;IAC9B,MAAME,mBAAmBD,QAAQE,MAAM,CAACC,WAAW,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASjB;IAChF,IAAI,CAACa,kBAAkB;QACrB,MAAM,IAAIzB,SAAS,CAAC,qBAAqB,EAAEY,eAAe,UAAU,CAAC;IACvE;IAEA,MAAMF,OAAO,GAAGC,WAAW,GAAGR,cAAc,CAAC,EAAES,gBAAgB,CAAC,CAAC,EAAEI,QAAQ;IAC3E,MAAMc,QAAQd,WAAW;IAEzB,MAAMe,WAAW;QACfC,YAAYpB;QACZqB,OAAO;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AQnD,cAAc;oBAAEmD;oBAAKtC;gBAAO;YACtE6C,WAAWJ,IAAI,CAACzD,UAAUoD,UAAU;gBAAEI,QAAQN;YAAa;YAC3DA,eAAe;QACjB,OAAO;YACL,MAAMY,YAAYlB,OAAOO,IAAI,CAACE,GAAG,CAAC,CAACC,MAAQS,KAAK/D,SAAS,CAACsD;YAC1DO,WAAWJ,IAAI,CAACK,UAAUE,IAAI,CAAC;QACjC;IACF;IAEA,MAAMC,SAASC,OAAOC,IAAI,CAAClD,WAAW,SAAS,CAAC,CAAC,EAAE4C,WAAWG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAGH,WAAWG,IAAI,CAAC;IAE7F,IAAI,CAACtD,IAAI;QACPa,IAAI6C,IAAI,GAAG;YACTzD;YACA0D,MAAMJ;YACNK,UAAUvC,QAAQ,aAAa;YAC/BwC,MAAMN,OAAOvB,MAAM;QACrB;IACF,OAAO;QACL,MAAMnB,IAAIE,OAAO,CAAC+C,MAAM,CAAC;YACvB9D;YACAuB,YAAYlB;YACZsD,MAAM,CAAC;YACPD,MAAM;gBACJzD;gBACA0D,MAAMJ;gBACNK,UAAUvC,QAAQ,aAAa;gBAC/BwC,MAAMN,OAAOvB,MAAM;YACrB;YACArB;QACF;IACF;AACF,EAAC"}
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,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,gB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AAQS,KAAKtE,SAAS,CAAC6D;YAC1DO,WAAWJ,IAAI,CAACK,UAAUE,IAAI,CAAC;QACjC;IACF;IAEA,MAAMC,SAASC,OAAOC,IAAI,CAACvD,WAAW,SAAS,CAAC,CAAC,EAAEiD,WAAWG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAGH,WAAWG,IAAI,CAAC;IAC7F,IAAIxD,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,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,3 +1,3 @@
1
- import type { PayloadHandler } from 'payload';
2
- export declare const download: PayloadHandler;
1
+ import type { PayloadRequest } from 'payload';
2
+ export declare const download: (req: PayloadRequest, debug?: boolean) => Promise<Response>;
3
3
  //# sourceMappingURL=download.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/export/download.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAM7C,eAAO,MAAM,QAAQ,EAAE,cAmBtB,CAAA"}
1
+ {"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/export/download.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAM7C,eAAO,MAAM,QAAQ,QAAe,cAAc,uCAmBjD,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import { APIError } from 'payload';
2
2
  import { createExport } from './createExport.js';
3
- export const download = async (req)=>{
3
+ export const download = async (req, debug = false)=>{
4
4
  let body;
5
5
  if (typeof req?.json === 'function') {
6
6
  body = await req.json();
@@ -12,7 +12,10 @@ export const download = async (req)=>{
12
12
  body.data.user = req.user;
13
13
  return createExport({
14
14
  download: true,
15
- input: body.data,
15
+ input: {
16
+ ...body.data,
17
+ debug
18
+ },
16
19
  req
17
20
  });
18
21
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/export/download.ts"],"sourcesContent":["import type { PayloadHandler } from 'payload'\n\nimport { APIError } from 'payload'\n\nimport { createExport } from './createExport.js'\n\nexport const download: PayloadHandler = async (req) => {\n let body\n if (typeof req?.json === 'function') {\n body = await req.json()\n }\n\n if (!body || !body.data) {\n throw new APIError('Request data is required.')\n }\n\n req.payload.logger.info(`Download request received ${body.data.collectionSlug}`)\n\n body.data.user = req.user\n\n return createExport({\n download: true,\n input: body.data,\n req,\n }) as Promise<Response>\n}\n"],"names":["APIError","createExport","download","req","body","json","data","payload","logger","info","collectionSlug","user","input"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAElC,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,OAAO,MAAMC,WAA2B,OAAOC;IAC7C,IAAIC;IACJ,IAAI,OAAOD,KAAKE,SAAS,YAAY;QACnCD,OAAO,MAAMD,IAAIE,IAAI;IACvB;IAEA,IAAI,CAACD,QAAQ,CAACA,KAAKE,IAAI,EAAE;QACvB,MAAM,IAAIN,SAAS;IACrB;IAEAG,IAAII,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,0BAA0B,EAAEL,KAAKE,IAAI,CAACI,cAAc,EAAE;IAE/EN,KAAKE,IAAI,CAACK,IAAI,GAAGR,IAAIQ,IAAI;IAEzB,OAAOV,aAAa;QAClBC,UAAU;QACVU,OAAOR,KAAKE,IAAI;QAChBH;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/export/download.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { APIError } from 'payload'\n\nimport { createExport } from './createExport.js'\n\nexport const download = async (req: PayloadRequest, debug = false) => {\n let body\n if (typeof req?.json === 'function') {\n body = await req.json()\n }\n\n if (!body || !body.data) {\n throw new APIError('Request data is required.')\n }\n\n req.payload.logger.info(`Download request received ${body.data.collectionSlug}`)\n\n body.data.user = req.user\n\n return createExport({\n download: true,\n input: { ...body.data, debug },\n req,\n }) as Promise<Response>\n}\n"],"names":["APIError","createExport","download","req","debug","body","json","data","payload","logger","info","collectionSlug","user","input"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAElC,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,OAAO,MAAMC,WAAW,OAAOC,KAAqBC,QAAQ,KAAK;IAC/D,IAAIC;IACJ,IAAI,OAAOF,KAAKG,SAAS,YAAY;QACnCD,OAAO,MAAMF,IAAIG,IAAI;IACvB;IAEA,IAAI,CAACD,QAAQ,CAACA,KAAKE,IAAI,EAAE;QACvB,MAAM,IAAIP,SAAS;IACrB;IAEAG,IAAIK,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,0BAA0B,EAAEL,KAAKE,IAAI,CAACI,cAAc,EAAE;IAE/EN,KAAKE,IAAI,CAACK,IAAI,GAAGT,IAAIS,IAAI;IAEzB,OAAOX,aAAa;QAClBC,UAAU;QACVW,OAAO;YAAE,GAAGR,KAAKE,IAAI;YAAEH;QAAM;QAC7BD;IACF;AACF,EAAC"}
@@ -1,9 +1,11 @@
1
1
  import type { Document } from 'payload';
2
+ import type { ToCSVFunction } from '../types.js';
2
3
  type Args = {
3
4
  doc: Document;
4
5
  fields?: string[];
5
6
  prefix?: string;
7
+ toCSVFunctions: Record<string, ToCSVFunction>;
6
8
  };
7
- export declare const flattenObject: ({ doc, fields, prefix }: Args) => Record<string, unknown>;
9
+ export declare const flattenObject: ({ doc, fields, prefix, toCSVFunctions, }: Args) => Record<string, unknown>;
8
10
  export {};
9
11
  //# sourceMappingURL=flattenObject.d.ts.map
@@ -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,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,QAAQ,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,aAAa,4BAA6B,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAoDnF,CAAA"}
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,CAmF/B,CAAA"}
@@ -1,20 +1,51 @@
1
- export const flattenObject = ({ doc, fields, prefix })=>{
2
- const result = {};
3
- const flatten = (doc, prefix)=>{
4
- Object.entries(doc).forEach(([key, value])=>{
1
+ export const flattenObject = ({ doc, fields, prefix, toCSVFunctions })=>{
2
+ const row = {};
3
+ const flatten = (siblingDoc, prefix)=>{
4
+ Object.entries(siblingDoc).forEach(([key, value])=>{
5
5
  const newKey = prefix ? `${prefix}_${key}` : key;
6
6
  if (Array.isArray(value)) {
7
7
  value.forEach((item, index)=>{
8
8
  if (typeof item === 'object' && item !== null) {
9
9
  flatten(item, `${newKey}_${index}`);
10
10
  } else {
11
- result[`${newKey}_${index}`] = item;
11
+ if (toCSVFunctions?.[newKey]) {
12
+ const columnName = `${newKey}_${index}`;
13
+ row[columnName] = toCSVFunctions[newKey]({
14
+ columnName,
15
+ doc,
16
+ row,
17
+ siblingDoc,
18
+ value: item
19
+ });
20
+ } else {
21
+ row[`${newKey}_${index}`] = item;
22
+ }
12
23
  }
13
24
  });
14
25
  } else if (typeof value === 'object' && value !== null) {
15
- flatten(value, newKey);
26
+ if (!toCSVFunctions?.[newKey]) {
27
+ flatten(value, newKey);
28
+ } else {
29
+ row[newKey] = toCSVFunctions[newKey]({
30
+ columnName: newKey,
31
+ doc,
32
+ row,
33
+ siblingDoc,
34
+ value
35
+ });
36
+ }
16
37
  } else {
17
- result[newKey] = value;
38
+ if (toCSVFunctions?.[newKey]) {
39
+ row[newKey] = toCSVFunctions[newKey]({
40
+ columnName: newKey,
41
+ doc,
42
+ row,
43
+ siblingDoc,
44
+ value
45
+ });
46
+ } else {
47
+ row[newKey] = value;
48
+ }
18
49
  }
19
50
  });
20
51
  };
@@ -27,21 +58,21 @@ export const flattenObject = ({ doc, fields, prefix })=>{
27
58
  return new RegExp(pattern);
28
59
  };
29
60
  fields.forEach((field)=>{
30
- if (result[field.replace(/\./g, '_')]) {
61
+ if (row[field.replace(/\./g, '_')]) {
31
62
  const sanitizedField = field.replace(/\./g, '_');
32
- orderedResult[sanitizedField] = result[sanitizedField];
63
+ orderedResult[sanitizedField] = row[sanitizedField];
33
64
  } else {
34
65
  const regex = fieldToRegex(field);
35
- Object.keys(result).forEach((key)=>{
66
+ Object.keys(row).forEach((key)=>{
36
67
  if (regex.test(key)) {
37
- orderedResult[key] = result[key];
68
+ orderedResult[key] = row[key];
38
69
  }
39
70
  });
40
71
  }
41
72
  });
42
73
  return orderedResult;
43
74
  }
44
- return result;
75
+ return row;
45
76
  };
46
77
 
47
78
  //# sourceMappingURL=flattenObject.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/export/flattenObject.ts"],"sourcesContent":["import type { Document } from 'payload'\n\ntype Args = {\n doc: Document\n fields?: string[]\n prefix?: string\n}\n\nexport const flattenObject = ({ doc, fields, prefix }: Args): Record<string, unknown> => {\n const result: Record<string, unknown> = {}\n\n const flatten = (doc: Document, prefix?: string) => {\n Object.entries(doc).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 result[`${newKey}_${index}`] = item\n }\n })\n } else if (typeof value === 'object' && value !== null) {\n flatten(value, newKey)\n } else {\n result[newKey] = value\n }\n })\n }\n\n flatten(doc, prefix)\n\n if (fields) {\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 (result[field.replace(/\\./g, '_')]) {\n const sanitizedField = field.replace(/\\./g, '_')\n orderedResult[sanitizedField] = result[sanitizedField]\n } else {\n const regex = fieldToRegex(field)\n Object.keys(result).forEach((key) => {\n if (regex.test(key)) {\n orderedResult[key] = result[key]\n }\n })\n }\n })\n\n return orderedResult\n }\n\n return result\n}\n"],"names":["flattenObject","doc","fields","prefix","result","flatten","Object","entries","forEach","key","value","newKey","Array","isArray","item","index","orderedResult","fieldToRegex","field","parts","split","map","part","pattern","join","RegExp","replace","sanitizedField","regex","keys","test"],"mappings":"AAQA,OAAO,MAAMA,gBAAgB,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,MAAM,EAAQ;IACzD,MAAMC,SAAkC,CAAC;IAEzC,MAAMC,UAAU,CAACJ,KAAeE;QAC9BG,OAAOC,OAAO,CAACN,KAAKO,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;YACvC,MAAMC,SAASR,SAAS,GAAGA,OAAO,CAAC,EAAEM,KAAK,GAAGA;YAE7C,IAAIG,MAAMC,OAAO,CAACH,QAAQ;gBACxBA,MAAMF,OAAO,CAAC,CAACM,MAAMC;oBACnB,IAAI,OAAOD,SAAS,YAAYA,SAAS,MAAM;wBAC7CT,QAAQS,MAAM,GAAGH,OAAO,CAAC,EAAEI,OAAO;oBACpC,OAAO;wBACLX,MAAM,CAAC,GAAGO,OAAO,CAAC,EAAEI,OAAO,CAAC,GAAGD;oBACjC;gBACF;YACF,OAAO,IAAI,OAAOJ,UAAU,YAAYA,UAAU,MAAM;gBACtDL,QAAQK,OAAOC;YACjB,OAAO;gBACLP,MAAM,CAACO,OAAO,GAAGD;YACnB;QACF;IACF;IAEAL,QAAQJ,KAAKE;IAEb,IAAID,QAAQ;QACV,MAAMc,gBAAyC,CAAC;QAEhD,MAAMC,eAAe,CAACC;YACpB,MAAMC,QAAQD,MAAME,KAAK,CAAC,KAAKC,GAAG,CAAC,CAACC,OAAS,GAAGA,KAAK,UAAU,CAAC;YAChE,MAAMC,UAAU,CAAC,CAAC,EAAEJ,MAAMK,IAAI,CAAC,MAAM;YACrC,OAAO,IAAIC,OAAOF;QACpB;QAEArB,OAAOM,OAAO,CAAC,CAACU;YACd,IAAId,MAAM,CAACc,MAAMQ,OAAO,CAAC,OAAO,KAAK,EAAE;gBACrC,MAAMC,iBAAiBT,MAAMQ,OAAO,CAAC,OAAO;gBAC5CV,aAAa,CAACW,eAAe,GAAGvB,MAAM,CAACuB,eAAe;YACxD,OAAO;gBACL,MAAMC,QAAQX,aAAaC;gBAC3BZ,OAAOuB,IAAI,CAACzB,QAAQI,OAAO,CAAC,CAACC;oBAC3B,IAAImB,MAAME,IAAI,CAACrB,MAAM;wBACnBO,aAAa,CAACP,IAAI,GAAGL,MAAM,CAACK,IAAI;oBAClC;gBACF;YACF;QACF;QAEA,OAAOO;IACT;IAEA,OAAOZ;AACT,EAAC"}
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 row[columnName] = toCSVFunctions[newKey]({\n columnName,\n doc,\n row,\n siblingDoc,\n value: item,\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 row[newKey] = toCSVFunctions[newKey]({\n columnName: newKey,\n doc,\n row,\n siblingDoc,\n value,\n })\n }\n } else {\n if (toCSVFunctions?.[newKey]) {\n row[newKey] = toCSVFunctions[newKey]({\n columnName: newKey,\n doc,\n row,\n siblingDoc,\n value,\n })\n } else {\n row[newKey] = value\n }\n }\n })\n }\n\n flatten(doc, prefix)\n\n if (fields) {\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","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;4BACvCZ,GAAG,CAACa,WAAW,GAAGd,cAAc,CAACS,OAAO,CAAC;gCACvCK;gCACAjB;gCACAI;gCACAE;gCACAK,OAAOI;4BACT;wBACF,OAAO;4BACLX,GAAG,CAAC,GAAGQ,OAAO,CAAC,EAAEI,OA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OAAOQ;IACT;IAEA,OAAOd;AACT,EAAC"}
@@ -1,3 +1,7 @@
1
- import type { Config, TaskHandler } from 'payload';
2
- export declare const getCreateCollectionExportTask: (config: Config) => TaskHandler<any, string>;
1
+ import type { Config, TaskConfig } from 'payload';
2
+ import type { Export } from './createExport.js';
3
+ export declare const getCreateCollectionExportTask: (config: Config) => TaskConfig<{
4
+ input: Export;
5
+ output: object;
6
+ }>;
3
7
  //# sourceMappingURL=getCreateExportCollectionTask.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getCreateExportCollectionTask.d.ts","sourceRoot":"","sources":["../../src/export/getCreateExportCollectionTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAQ,MAAM,SAAS,CAAA;AAOxD,eAAO,MAAM,6BAA6B,WAAY,MAAM,KAAG,WAAW,CAAC,GAAG,EAAE,MAAM,CA+CrF,CAAA"}
1
+ {"version":3,"file":"getCreateExportCollectionTask.d.ts","sourceRoot":"","sources":["../../src/export/getCreateExportCollectionTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAQ,MAAM,SAAS,CAAA;AAEvD,OAAO,KAAK,EAAoB,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAKjE,eAAO,MAAM,6BAA6B,WAChC,MAAM,KACb,UAAU,CAAC;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf,CAwCA,CAAA"}
@@ -12,7 +12,6 @@ export const getCreateCollectionExportTask = (config)=>{
12
12
  type: 'text'
13
13
  });
14
14
  return {
15
- // @ts-expect-error plugin tasks cannot have predefined type slug
16
15
  slug: 'createCollectionExport',
17
16
  handler: async ({ input, req })=>{
18
17
  let user;
@@ -31,16 +30,10 @@ export const getCreateCollectionExportTask = (config)=>{
31
30
  user
32
31
  });
33
32
  return {
34
- success: true
33
+ output: {}
35
34
  };
36
35
  },
37
- inputSchema,
38
- outputSchema: [
39
- {
40
- name: 'success',
41
- type: 'checkbox'
42
- }
43
- ]
36
+ inputSchema
44
37
  };
45
38
  };
46
39
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/export/getCreateExportCollectionTask.ts"],"sourcesContent":["import type { Config, TaskHandler, User } from 'payload'\n\nimport type { CreateExportArgs } from './createExport.js'\n\nimport { createExport } from './createExport.js'\nimport { getFields } from './getFields.js'\n\nexport const getCreateCollectionExportTask = (config: Config): TaskHandler<any, string> => {\n const inputSchema = getFields(config).concat(\n {\n name: 'user',\n type: 'text',\n },\n {\n name: 'userCollection',\n type: 'text',\n },\n {\n name: 'exportsCollection',\n type: 'text',\n },\n )\n\n return {\n // @ts-expect-error plugin tasks cannot have predefined type slug\n slug: 'createCollectionExport',\n handler: async ({ input, req }: CreateExportArgs) => {\n let user: undefined | User\n\n if (input.userCollection && input.user) {\n user = (await req.payload.findByID({\n id: input.user,\n collection: input.userCollection,\n })) as User\n }\n\n if (!user) {\n throw new Error('User not found')\n }\n\n await createExport({ input, req, user })\n\n return {\n success: true,\n }\n },\n inputSchema,\n outputSchema: [\n {\n name: 'success',\n type: 'checkbox',\n },\n ],\n }\n}\n"],"names":["createExport","getFields","getCreateCollectionExportTask","config","inputSchema","concat","name","type","slug","handler","input","req","user","userCollection","payload","findByID","id","collection","Error","success","outputSchema"],"mappings":"AAIA,SAASA,YAAY,QAAQ,oBAAmB;AAChD,SAASC,SAAS,QAAQ,iBAAgB;AAE1C,OAAO,MAAMC,gCAAgC,CAACC;IAC5C,MAAMC,cAAcH,UAAUE,QAAQE,MAAM,CAC1C;QACEC,MAAM;QACNC,MAAM;IACR,GACA;QACED,MAAM;QACNC,MAAM;IACR,GACA;QACED,MAAM;QACNC,MAAM;IACR;IAGF,OAAO;QACL,iEAAiE;QACjEC,MAAM;QACNC,SAAS,OAAO,EAAEC,KAAK,EAAEC,GAAG,EAAoB;YAC9C,IAAIC;YAEJ,IAAIF,MAAMG,cAAc,IAAIH,MAAME,IAAI,EAAE;gBACtCA,OAAQ,MAAMD,IAAIG,OAAO,CAACC,QAAQ,CAAC;oBACjCC,IAAIN,MAAME,IAAI;oBACdK,YAAYP,MAAMG,cAAc;gBAClC;YACF;YAEA,IAAI,CAACD,MAAM;gBACT,MAAM,IAAIM,MAAM;YAClB;YAEA,MAAMlB,aAAa;gBAAEU;gBAAOC;gBAAKC;YAAK;YAEtC,OAAO;gBACLO,SAAS;YACX;QACF;QACAf;QACAgB,cAAc;YACZ;gBACEd,MAAM;gBACNC,MAAM;YACR;SACD;IACH;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/export/getCreateExportCollectionTask.ts"],"sourcesContent":["import type { Config, TaskConfig, User } from 'payload'\n\nimport type { CreateExportArgs, Export } from './createExport.js'\n\nimport { createExport } from './createExport.js'\nimport { getFields } from './getFields.js'\n\nexport const getCreateCollectionExportTask = (\n config: Config,\n): TaskConfig<{\n input: Export\n output: object\n}> => {\n const inputSchema = getFields(config).concat(\n {\n name: 'user',\n type: 'text',\n },\n {\n name: 'userCollection',\n type: 'text',\n },\n {\n name: 'exportsCollection',\n type: 'text',\n },\n )\n\n return {\n slug: 'createCollectionExport',\n handler: async ({ input, req }: CreateExportArgs) => {\n let user: undefined | User\n\n if (input.userCollection && input.user) {\n user = (await req.payload.findByID({\n id: input.user,\n collection: input.userCollection,\n })) as User\n }\n\n if (!user) {\n throw new Error('User not found')\n }\n\n await createExport({ input, req, user })\n\n return {\n output: {},\n }\n },\n inputSchema,\n }\n}\n"],"names":["createExport","getFields","getCreateCollectionExportTask","config","inputSchema","concat","name","type","slug","handler","input","req","user","userCollection","payload","findByID","id","collection","Error","output"],"mappings":"AAIA,SAASA,YAAY,QAAQ,oBAAmB;AAChD,SAASC,SAAS,QAAQ,iBAAgB;AAE1C,OAAO,MAAMC,gCAAgC,CAC3CC;IAKA,MAAMC,cAAcH,UAAUE,QAAQE,MAAM,CAC1C;QACEC,MAAM;QACNC,MAAM;IACR,GACA;QACED,MAAM;QACNC,MAAM;IACR,GACA;QACED,MAAM;QACNC,MAAM;IACR;IAGF,OAAO;QACLC,MAAM;QACNC,SAAS,OAAO,EAAEC,KAAK,EAAEC,GAAG,EAAoB;YAC9C,IAAIC;YAEJ,IAAIF,MAAMG,cAAc,IAAIH,MAAME,IAAI,EAAE;gBACtCA,OAAQ,MAAMD,IAAIG,OAAO,CAACC,QAAQ,CAAC;oBACjCC,IAAIN,MAAME,IAAI;oBACdK,YAAYP,MAAMG,cAAc;gBAClC;YACF;YAEA,IAAI,CAACD,MAAM;gBACT,MAAM,IAAIM,MAAM;YAClB;YAEA,MAAMlB,aAAa;gBAAEU;gBAAOC;gBAAKC;YAAK;YAEtC,OAAO;gBACLO,QAAQ,CAAC;YACX;QACF;QACAf;IACF;AACF,EAAC"}
@@ -0,0 +1,9 @@
1
+ import { type FlattenedField, type SelectIncludeType } from 'payload';
2
+ import type { ToCSVFunction } from '../types.js';
3
+ type Args = {
4
+ fields: FlattenedField[];
5
+ select: SelectIncludeType | undefined;
6
+ };
7
+ export declare const getCustomFieldFunctions: ({ fields, select, }: Args) => Record<string, ToCSVFunction>;
8
+ export {};
9
+ //# sourceMappingURL=getCustomFieldFunctions.d.ts.map
@@ -0,0 +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,CA2ErC,CAAA"}
@@ -0,0 +1,62 @@
1
+ import { traverseFields } from 'payload';
2
+ export const getCustomFieldFunctions = ({ fields, select })=>{
3
+ const result = {};
4
+ const buildCustomFunctions = ({ field, parentRef, ref })=>{
5
+ // @ts-expect-error ref is untyped
6
+ ref.prefix = parentRef.prefix || '';
7
+ if (field.type === 'group' || field.type === 'tab') {
8
+ // @ts-expect-error ref is untyped
9
+ const parentPrefix = parentRef?.prefix ? `${parentRef.prefix}_` : '';
10
+ // @ts-expect-error ref is untyped
11
+ ref.prefix = `${parentPrefix}${field.name}_`;
12
+ }
13
+ if (typeof field.custom?.['plugin-import-export']?.toCSV === 'function') {
14
+ // @ts-expect-error ref is untyped
15
+ result[`${ref.prefix}${field.name}`] = field.custom['plugin-import-export']?.toCSV;
16
+ } else if (field.type === 'relationship' || field.type === 'upload') {
17
+ if (field.hasMany !== true) {
18
+ if (!Array.isArray(field.relationTo)) {
19
+ // monomorphic single
20
+ // @ts-expect-error ref is untyped
21
+ result[`${ref.prefix}${field.name}`] = ({ value })=>typeof value === 'object' && value && 'id' in value ? value.id : value;
22
+ } else {
23
+ // polymorphic single
24
+ // @ts-expect-error ref is untyped
25
+ result[`${ref.prefix}${field.name}`] = ({ data, value })=>{
26
+ // @ts-expect-error ref is untyped
27
+ data[`${ref.prefix}${field.name}_id`] = value.id;
28
+ // @ts-expect-error ref is untyped
29
+ data[`${ref.prefix}${field.name}_relationTo`] = value.relationTo;
30
+ return undefined;
31
+ };
32
+ }
33
+ } else {
34
+ if (!Array.isArray(field.relationTo)) {
35
+ // monomorphic many
36
+ // @ts-expect-error ref is untyped
37
+ result[`${ref.prefix}${field.name}`] = ({ value })=>value.map((val)=>typeof val === 'object' ? val.id : val);
38
+ } else {
39
+ // polymorphic many
40
+ // @ts-expect-error ref is untyped
41
+ result[`${ref.prefix}${field.name}`] = ({ data, value })=>value.map((val, i)=>{
42
+ // @ts-expect-error ref is untyped
43
+ data[`${ref.prefix}${field.name}_${i}_id`] = val.id;
44
+ // @ts-expect-error ref is untyped
45
+ data[`${ref.prefix}${field.name}_${i}_relationTo`] = val.relationTo;
46
+ return undefined;
47
+ });
48
+ }
49
+ }
50
+ }
51
+ // TODO: do this so we only return the functions needed based on the select used
52
+ ////@ts-expect-error ref is untyped
53
+ // ref.select = typeof select !== 'undefined' || select[field.name] ? select : {}
54
+ };
55
+ traverseFields({
56
+ callback: buildCustomFunctions,
57
+ fields
58
+ });
59
+ return result;
60
+ };
61
+
62
+ //# sourceMappingURL=getCustomFieldFunctions.js.map
@@ -0,0 +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 data[`${ref.prefix}${field.name}_id`] = value.id\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_relationTo`] = value.relationTo\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: Record<string, unknown>[]\n }) =>\n value.map((val: number | Record<string, unknown> | string, i) => {\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_${i}_id`] = val.id\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_${i}_relationTo`] = val.relationTo\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","undefined","map","val","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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M,CAAC,GAAGI,IAAIC,MAAM,GAAGH,MAAMM,IAAI,EAAE,CAAC,GAAG,CAAC,EACtCO,KAAK,EAGN,GACCA,MAAMI,GAAG,CAAC,CAACC,MACT,OAAOA,QAAQ,WAAWA,IAAIJ,EAAE,GAAGI;gBAEzC,OAAO;oBACL,mBAAmB;oBACnB,kCAAkC;oBAClCpB,MAAM,CAAC,GAAGI,IAAIC,MAAM,GAAGH,MAAMM,IAAI,EAAE,CAAC,GAAG,CAAC,EACtCS,IAAI,EACJF,KAAK,EAIN,GACCA,MAAMI,GAAG,CAAC,CAACC,KAAgDC;4BACzD,kCAAkC;4BAClCJ,IAAI,CAAC,GAAGb,IAAIC,MAAM,GAAGH,MAAMM,IAAI,CAAC,CAAC,EAAEa,EAAE,GAAG,CAAC,CAAC,GAAGD,IAAIJ,EAAE;4BACnD,kCAAkC;4BAClCC,IAAI,CAAC,GAAGb,IAAIC,MAAM,GAAGH,MAAMM,IAAI,CAAC,CAAC,EAAEa,EAAE,WAAW,CAAC,CAAC,GAAGD,IAAIN,UAAU;4BACnE,OAAOI;wBACT;gBACJ;YACF;QACF;IAEA,gFAAgF;IAChF,mCAAmC;IACnC,iFAAiF;IACnF;IAEAtB,eAAe;QAAE0B,UAAUrB;QAAsBH;IAAO;IAExD,OAAOE;AACT,EAAC"}
@@ -1,7 +1,7 @@
1
- import type { SelectType } from 'payload';
1
+ import type { SelectIncludeType } from 'payload';
2
2
  /**
3
3
  * Takes an input of array of string paths in dot notation and returns a select object
4
4
  * example args: ['id', 'title', 'group.value', 'createdAt', 'updatedAt']
5
5
  */
6
- export declare const getSelect: (fields: string[]) => SelectType;
6
+ export declare const getSelect: (fields: string[]) => SelectIncludeType;
7
7
  //# sourceMappingURL=getSelect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getSelect.d.ts","sourceRoot":"","sources":["../../src/export/getSelect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC;;;GAGG;AACH,eAAO,MAAM,SAAS,WAAY,MAAM,EAAE,KAAG,UAwB5C,CAAA"}
1
+ {"version":3,"file":"getSelect.d.ts","sourceRoot":"","sources":["../../src/export/getSelect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD;;;GAGG;AACH,eAAO,MAAM,SAAS,WAAY,MAAM,EAAE,KAAG,iBAoB5C,CAAA"}
@@ -4,10 +4,6 @@
4
4
  */ export const getSelect = (fields)=>{
5
5
  const select = {};
6
6
  fields.forEach((field)=>{
7
- // TODO: this can likely be removed, the form was not saving, leaving in for now
8
- if (!field) {
9
- return;
10
- }
11
7
  const segments = field.split('.');
12
8
  let selectRef = select;
13
9
  segments.forEach((segment, i)=>{
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/export/getSelect.ts"],"sourcesContent":["import type { SelectType } from 'payload'\n\n/**\n * Takes an input of array of string paths in dot notation and returns a select object\n * example args: ['id', 'title', 'group.value', 'createdAt', 'updatedAt']\n */\nexport const getSelect = (fields: string[]): SelectType => {\n const select: SelectType = {}\n\n fields.forEach((field) => {\n // TODO: this can likely be removed, the form was not saving, leaving in for now\n if (!field) {\n return\n }\n const segments = field.split('.')\n let selectRef = select\n\n segments.forEach((segment, i) => {\n if (i === segments.length - 1) {\n selectRef[segment] = true\n } else {\n if (!selectRef[segment]) {\n selectRef[segment] = {}\n }\n selectRef = selectRef[segment] as SelectType\n }\n })\n })\n\n return select\n}\n"],"names":["getSelect","fields","select","forEach","field","segments","split","selectRef","segment","i","length"],"mappings":"AAEA;;;CAGC,GACD,OAAO,MAAMA,YAAY,CAACC;IACxB,MAAMC,SAAqB,CAAC;IAE5BD,OAAOE,OAAO,CAAC,CAACC;QACd,gFAAgF;QAChF,IAAI,CAACA,OAAO;YACV;QACF;QACA,MAAMC,WAAWD,MAAME,KAAK,CAAC;QAC7B,IAAIC,YAAYL;QAEhBG,SAASF,OAAO,CAAC,CAACK,SAASC;YACzB,IAAIA,MAAMJ,SAASK,MAAM,GAAG,GAAG;gBAC7BH,SAAS,CAACC,QAAQ,GAAG;YACvB,OAAO;gBACL,IAAI,CAACD,SAAS,CAACC,QAAQ,EAAE;oBACvBD,SAAS,CAACC,QAAQ,GAAG,CAAC;gBACxB;gBACAD,YAAYA,SAAS,CAACC,QAAQ;YAChC;QACF;IACF;IAEA,OAAON;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/export/getSelect.ts"],"sourcesContent":["import type { SelectIncludeType } from 'payload'\n\n/**\n * Takes an input of array of string paths in dot notation and returns a select object\n * example args: ['id', 'title', 'group.value', 'createdAt', 'updatedAt']\n */\nexport const getSelect = (fields: string[]): SelectIncludeType => {\n const select: SelectIncludeType = {}\n\n fields.forEach((field) => {\n const segments = field.split('.')\n let selectRef = select\n\n segments.forEach((segment, i) => {\n if (i === segments.length - 1) {\n selectRef[segment] = true\n } else {\n if (!selectRef[segment]) {\n selectRef[segment] = {}\n }\n selectRef = selectRef[segment] as SelectIncludeType\n }\n })\n })\n\n return select\n}\n"],"names":["getSelect","fields","select","forEach","field","segments","split","selectRef","segment","i","length"],"mappings":"AAEA;;;CAGC,GACD,OAAO,MAAMA,YAAY,CAACC;IACxB,MAAMC,SAA4B,CAAC;IAEnCD,OAAOE,OAAO,CAAC,CAACC;QACd,MAAMC,WAAWD,MAAME,KAAK,CAAC;QAC7B,IAAIC,YAAYL;QAEhBG,SAASF,OAAO,CAAC,CAACK,SAASC;YACzB,IAAIA,MAAMJ,SAASK,MAAM,GAAG,GAAG;gBAC7BH,SAAS,CAACC,QAAQ,GAAG;YACvB,OAAO;gBACL,IAAI,CAACD,SAAS,CAACC,QAAQ,EAAE;oBACvBD,SAAS,CAACC,QAAQ,GAAG,CAAC;gBACxB;gBACAD,YAAYA,SAAS,CAACC,QAAQ;YAChC;QACF;IACF;IAEA,OAAON;AACT,EAAC"}
@@ -1,2 +1,2 @@
1
- export type { ImportExportPluginConfig } from '../types.js';
1
+ export type { ImportExportPluginConfig, ToCSVFunction } from '../types.js';
2
2
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/exports/types.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/exports/types.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type { ImportExportPluginConfig } from '../types.js'\n"],"names":[],"mappings":"AAAA,WAA2D"}
1
+ {"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type { ImportExportPluginConfig, ToCSVFunction } from '../types.js'\n"],"names":[],"mappings":"AAAA,WAA0E"}
@@ -1 +1 @@
1
- {"version":3,"file":"getExportCollection.d.ts","sourceRoot":"","sources":["../src/getExportCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,gBAAgB,EAChB,MAAM,EACP,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAsB,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAM9E,eAAO,MAAM,mBAAmB,8BAG7B;IACD,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,gBAmEH,CAAA"}
1
+ {"version":3,"file":"getExportCollection.d.ts","sourceRoot":"","sources":["../src/getExportCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,MAAM,EACP,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAsB,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAM9E,eAAO,MAAM,mBAAmB,8BAG7B;IACD,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,gBAsEH,CAAA"}
@@ -17,7 +17,9 @@ export const getExportCollection = ({ config, pluginConfig })=>{
17
17
  disableDuplicate: true,
18
18
  endpoints: [
19
19
  {
20
- handler: download,
20
+ handler: (req)=>{
21
+ return download(req, pluginConfig.debug);
22
+ },
21
23
  method: 'post',
22
24
  path: '/download'
23
25
  }
@@ -42,9 +44,11 @@ export const getExportCollection = ({ config, pluginConfig })=>{
42
44
  return;
43
45
  }
44
46
  const { user } = req;
47
+ const debug = pluginConfig.debug;
45
48
  await createExport({
46
49
  input: {
47
50
  ...args.data,
51
+ debug,
48
52
  user
49
53
  },
50
54
  req
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/getExportCollection.ts"],"sourcesContent":["import type {\n CollectionAfterChangeHook,\n CollectionBeforeChangeHook,\n CollectionBeforeOperationHook,\n CollectionConfig,\n Config,\n} from 'payload'\n\nimport type { CollectionOverride, ImportExportPluginConfig } from './types.js'\n\nimport { createExport } from './export/createExport.js'\nimport { download } from './export/download.js'\nimport { getFields } from './export/getFields.js'\n\nexport const getExportCollection = ({\n config,\n pluginConfig,\n}: {\n config: Config\n pluginConfig: ImportExportPluginConfig\n}): CollectionConfig => {\n const { overrideExportCollection } = pluginConfig\n\n const beforeOperation: CollectionBeforeOperationHook[] = []\n const afterChange: CollectionAfterChangeHook[] = []\n\n let collection: CollectionOverride = {\n slug: 'exports',\n access: {\n update: () => false,\n },\n admin: {\n group: false,\n useAsTitle: 'name',\n },\n disableDuplicate: true,\n endpoints: [\n {\n handler: download,\n method: 'post',\n path: '/download',\n },\n ],\n fields: getFields(config),\n hooks: {\n afterChange,\n beforeOperation,\n },\n upload: {\n filesRequiredOnCreate: false,\n hideFileInputOnCreate: true,\n hideRemoveFile: true,\n },\n }\n\n if (typeof overrideExportCollection === 'function') {\n collection = overrideExportCollection(collection)\n }\n\n if (pluginConfig.disableJobsQueue) {\n beforeOperation.push(async ({ args, operation, req }) => {\n if (operation !== 'create') {\n return\n }\n const { user } = req\n await createExport({ input: { ...args.data, user }, req })\n })\n } else {\n afterChange.push(async ({ doc, operation, req }) => {\n if (operation !== 'create') {\n return\n }\n\n const input = {\n ...doc,\n exportsCollection: collection.slug,\n user: req?.user?.id || req?.user?.user?.id,\n userCollection: 'users',\n }\n await req.payload.jobs.queue({\n input,\n task: 'createCollectionExport',\n })\n })\n }\n\n return collection\n}\n"],"names":["createExport","download","getFields","getExportCollection","config","pluginConfig","overrideExportCollection","beforeOperation","afterChange","collection","slug","access","update","admin","group","useAsTitle","disableDuplicate","endpoints","handler","method","path","fields","hooks","upload","filesRequiredOnCreate","hideFileInputOnCreate","hideRemoveFile","disableJobsQueue","push","args","operation","req","user","input","data","doc","exportsCollection","id","userCollection","payload","jobs","queue","task"],"mappings":"AAUA,SAASA,YAAY,QAAQ,2BAA0B;AACvD,SAASC,QAAQ,QAAQ,uBAAsB;AAC/C,SAASC,SAAS,QAAQ,wBAAuB;AAEjD,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,MAAM,EACNC,YAAY,EAIb;IACC,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;IAErC,MAAME,kBAAmD,EAAE;IAC3D,MAAMC,cAA2C,EAAE;IAEnD,IAAIC,aAAiC;QACnCC,MAAM;QACNC,QAAQ;YACNC,QAAQ,IAAM;QAChB;QACAC,OAAO;YACLC,OAAO;YACPC,YAAY;QACd;QACAC,kBAAkB;QAClBC,WAAW;YACT;gBACEC,SAASjB;gBACTkB,QAAQ;gBACRC,MAAM;YACR;SACD;QACDC,QAAQnB,UAAUE;QAClBkB,OAAO;YACLd;YACAD;QACF;QACAgB,QAAQ;YACNC,uBAAuB;YACvBC,uBAAuB;YACvBC,gBAAgB;QAClB;IACF;IAEA,IAAI,OAAOpB,6BAA6B,YAAY;QAClDG,aAAaH,yBAAyBG;IACxC;IAEA,IAAIJ,aAAasB,gBAAgB,EAAE;QACjCpB,gBAAgBqB,IAAI,CAAC,OAAO,EAAEC,IAAI,EAAEC,SAAS,EAAEC,GAAG,EAAE;YAClD,IAAID,cAAc,UAAU;gBAC1B;YACF;YACA,MAAM,EAAEE,IAAI,EAAE,GAAGD;YACjB,MAAM/B,aAAa;gBAAEiC,OAAO;oBAAE,GAAGJ,KAAKK,IAAI;oBAAEF;gBAAK;gBAAGD;YAAI;QAC1D;IACF,OAAO;QACLvB,YAAYoB,IAAI,CAAC,OAAO,EAAEO,GAAG,EAAEL,SAAS,EAAEC,GAAG,EAAE;YAC7C,IAAID,cAAc,UAAU;gBAC1B;YACF;YAEA,MAAMG,QAAQ;gBACZ,GAAGE,GAAG;gBACNC,mBAAmB3B,WAAWC,IAAI;gBAClCsB,MAAMD,KAAKC,MAAMK,MAAMN,KAAKC,MAAMA,MAAMK;gBACxCC,gBAAgB;YAClB;YACA,MAAMP,IAAIQ,OAAO,CAACC,IAAI,CAACC,KAAK,CAAC;gBAC3BR;gBACAS,MAAM;YACR;QACF;IACF;IAEA,OAAOjC;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/getExportCollection.ts"],"sourcesContent":["import type {\n CollectionAfterChangeHook,\n CollectionBeforeOperationHook,\n CollectionConfig,\n Config,\n} from 'payload'\n\nimport type { CollectionOverride, ImportExportPluginConfig } from './types.js'\n\nimport { createExport } from './export/createExport.js'\nimport { download } from './export/download.js'\nimport { getFields } from './export/getFields.js'\n\nexport const getExportCollection = ({\n config,\n pluginConfig,\n}: {\n config: Config\n pluginConfig: ImportExportPluginConfig\n}): CollectionConfig => {\n const { overrideExportCollection } = pluginConfig\n\n const beforeOperation: CollectionBeforeOperationHook[] = []\n const afterChange: CollectionAfterChangeHook[] = []\n\n let collection: CollectionOverride = {\n slug: 'exports',\n access: {\n update: () => false,\n },\n admin: {\n group: false,\n useAsTitle: 'name',\n },\n disableDuplicate: true,\n endpoints: [\n {\n handler: (req) => {\n return download(req, pluginConfig.debug)\n },\n method: 'post',\n path: '/download',\n },\n ],\n fields: getFields(config),\n hooks: {\n afterChange,\n beforeOperation,\n },\n upload: {\n filesRequiredOnCreate: false,\n hideFileInputOnCreate: true,\n hideRemoveFile: true,\n },\n }\n\n if (typeof overrideExportCollection === 'function') {\n collection = overrideExportCollection(collection)\n }\n\n if (pluginConfig.disableJobsQueue) {\n beforeOperation.push(async ({ args, operation, req }) => {\n if (operation !== 'create') {\n return\n }\n const { user } = req\n const debug = pluginConfig.debug\n await createExport({ input: { ...args.data, debug, user }, req })\n })\n } else {\n afterChange.push(async ({ doc, operation, req }) => {\n if (operation !== 'create') {\n return\n }\n\n const input = {\n ...doc,\n exportsCollection: collection.slug,\n user: req?.user?.id || req?.user?.user?.id,\n userCollection: 'users',\n }\n await req.payload.jobs.queue({\n input,\n task: 'createCollectionExport',\n })\n })\n }\n\n return collection\n}\n"],"names":["createExport","download","getFields","getExportCollection","config","pluginConfig","overrideExportCollection","beforeOperation","afterChange","collection","slug","access","update","admin","group","useAsTitle","disableDuplicate","endpoints","handler","req","debug","method","path","fields","hooks","upload","filesRequiredOnCreate","hideFileInputOnCreate","hideRemoveFile","disableJobsQueue","push","args","operation","user","input","data","doc","exportsCollection","id","userCollection","payload","jobs","queue","task"],"mappings":"AASA,SAASA,YAAY,QAAQ,2BAA0B;AACvD,SAASC,QAAQ,QAAQ,uBAAsB;AAC/C,SAASC,SAAS,QAAQ,wBAAuB;AAEjD,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,MAAM,EACNC,YAAY,EAIb;IACC,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;IAErC,MAAME,kBAAmD,EAAE;IAC3D,MAAMC,cAA2C,EAAE;IAEnD,IAAIC,aAAiC;QACnCC,MAAM;QACNC,QAAQ;YACNC,QAAQ,IAAM;QAChB;QACAC,OAAO;YACLC,OAAO;YACPC,YAAY;QACd;QACAC,kBAAkB;QAClBC,WAAW;YACT;gBACEC,SAAS,CAACC;oBACR,OAAOlB,SAASkB,KAAKd,aAAae,KAAK;gBACzC;gBACAC,QAAQ;gBACRC,MAAM;YACR;SACD;QACDC,QAAQrB,UAAUE;QAClBoB,OAAO;YACLhB;YACAD;QACF;QACAkB,QAAQ;YACNC,uBAAuB;YACvBC,uBAAuB;YACvBC,gBAAgB;QAClB;IACF;IAEA,IAAI,OAAOtB,6BAA6B,YAAY;QAClDG,aAAaH,yBAAyBG;IACxC;IAEA,IAAIJ,aAAawB,gBAAgB,EAAE;QACjCtB,gBAAgBuB,IAAI,CAAC,OAAO,EAAEC,IAAI,EAAEC,SAAS,EAAEb,GAAG,EAAE;YAClD,IAAIa,cAAc,UAAU;gBAC1B;YACF;YACA,MAAM,EAAEC,IAAI,EAAE,GAAGd;YACjB,MAAMC,QAAQf,aAAae,KAAK;YAChC,MAAMpB,aAAa;gBAAEkC,OAAO;oBAAE,GAAGH,KAAKI,IAAI;oBAAEf;oBAAOa;gBAAK;gBAAGd;YAAI;QACjE;IACF,OAAO;QACLX,YAAYsB,IAAI,CAAC,OAAO,EAAEM,GAAG,EAAEJ,SAAS,EAAEb,GAAG,EAAE;YAC7C,IAAIa,cAAc,UAAU;gBAC1B;YACF;YAEA,MAAME,QAAQ;gBACZ,GAAGE,GAAG;gBACNC,mBAAmB5B,WAAWC,IAAI;gBAClCuB,MAAMd,KAAKc,MAAMK,MAAMnB,KAAKc,MAAMA,MAAMK;gBACxCC,gBAAgB;YAClB;YACA,MAAMpB,IAAIqB,OAAO,CAACC,IAAI,CAACC,KAAK,CAAC;gBAC3BR;gBACAS,MAAM;YACR;QACF;IACF;IAEA,OAAOlC;AACT,EAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,11 @@
1
1
  import type { Config } from 'payload';
2
- import type { ImportExportPluginConfig } from './types.js';
2
+ import type { ImportExportPluginConfig, ToCSVFunction } from './types.js';
3
3
  export declare const importExportPlugin: (pluginConfig: ImportExportPluginConfig) => (config: Config) => Config;
4
+ declare module 'payload' {
5
+ interface FieldCustom {
6
+ 'plugin-import-export'?: {
7
+ toCSVFunction?: ToCSVFunction;
8
+ };
9
+ }
10
+ }
4
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,SAAS,CAAA;AAKjD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAM1D,eAAO,MAAM,kBAAkB,iBACd,wBAAwB,cAC9B,MAAM,KAAG,MA+EjB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,SAAS,CAAA;AAKjD,OAAO,KAAK,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAMzE,eAAO,MAAM,kBAAkB,iBACd,wBAAwB,cAC9B,MAAM,KAAG,MA2EjB,CAAA;AAEH,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAiB,WAAW;QAC1B,sBAAsB,CAAC,EAAE;YACvB,aAAa,CAAC,EAAE,aAAa,CAAA;SAC9B,CAAA;KACF;CACF"}
package/dist/index.js CHANGED
@@ -19,13 +19,7 @@ export const importExportPlugin = (pluginConfig)=>(config)=>{
19
19
  config.admin.components = config.admin.components || {};
20
20
  config.admin.components.providers = config.admin.components.providers || [];
21
21
  config.admin.components.providers.push('@payloadcms/plugin-import-export/rsc#ImportExportProvider');
22
- // inject the createExport job into the config
23
- config.jobs = config.jobs || {
24
- tasks: [
25
- getCreateCollectionExportTask(config)
26
- ]
27
- } // cannot type jobs config inside of plugins
28
- ;
22
+ ((config.jobs ??= {}).tasks ??= []).push(getCreateCollectionExportTask(config));
29
23
  let collectionsToUpdate = config.collections;
30
24
  const usePluginCollections = pluginConfig.collections && pluginConfig.collections?.length > 0;
31
25
  if (usePluginCollections) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config, JobsConfig } from 'payload'\n\nimport { deepMergeSimple } from 'payload'\n\nimport type { PluginDefaultTranslationsObject } from './translations/types.js'\nimport type { ImportExportPluginConfig } from './types.js'\n\nimport { getCreateCollectionExportTask } from './export/getCreateExportCollectionTask.js'\nimport { getExportCollection } from './getExportCollection.js'\nimport { translations } from './translations/index.js'\n\nexport const importExportPlugin =\n (pluginConfig: ImportExportPluginConfig) =>\n (config: Config): Config => {\n const exportCollection = getExportCollection({ config, pluginConfig })\n if (config.collections) {\n config.collections.push(exportCollection)\n } else {\n config.collections = [exportCollection]\n }\n\n // inject custom import export provider\n config.admin = config.admin || {}\n config.admin.components = config.admin.components || {}\n config.admin.components.providers = config.admin.components.providers || []\n config.admin.components.providers.push(\n '@payloadcms/plugin-import-export/rsc#ImportExportProvider',\n )\n\n // inject the createExport job into the config\n config.jobs =\n config.jobs ||\n ({\n tasks: [getCreateCollectionExportTask(config)],\n } as unknown as JobsConfig) // cannot type jobs config inside of plugins\n\n let collectionsToUpdate = config.collections\n\n const usePluginCollections = pluginConfig.collections && pluginConfig.collections?.length > 0\n\n if (usePluginCollections) {\n collectionsToUpdate = config.collections?.filter((collection) => {\n return pluginConfig.collections?.includes(collection.slug)\n })\n }\n\n collectionsToUpdate.forEach((collection) => {\n if (!collection.admin) {\n collection.admin = { components: { listMenuItems: [] } }\n }\n const components = collection.admin.components || {}\n if (!components.listMenuItems) {\n components.listMenuItems = []\n }\n if (!components.edit) {\n components.edit = {}\n }\n if (!components.edit.SaveButton) {\n components.edit.SaveButton = '@payloadcms/plugin-import-export/rsc#ExportSaveButton'\n }\n components.listMenuItems.push({\n clientProps: {\n exportCollectionSlug: exportCollection.slug,\n },\n path: '@payloadcms/plugin-import-export/rsc#ExportListMenuItem',\n })\n collection.admin.components = components\n })\n\n if (!config.i18n) {\n config.i18n = {}\n }\n\n // config.i18n.translations = deepMergeSimple(translations, config.i18n?.translations ?? {})\n\n /**\n * Merge plugin translations\n */\n const simplifiedTranslations = Object.entries(translations).reduce(\n (acc, [key, value]) => {\n acc[key] = value.translations\n return acc\n },\n {} as Record<string, PluginDefaultTranslationsObject>,\n )\n\n config.i18n = {\n ...config.i18n,\n translations: deepMergeSimple(simplifiedTranslations, config.i18n?.translations ?? {}),\n }\n\n return config\n }\n"],"names":["deepMergeSimple","getCreateCollectionExportTask","getExportCollection","translations","importExportPlugin","pluginConfig","config","exportCollection","collections","push","admin","components","providers","jobs","tasks","collectionsToUpdate","usePluginCollections","length","filter","collection","includes","slug","forEach","listMenuItems","edit","SaveButton","clientProps","exportCollectionSlug","path","i18n","simplifiedTranslations","Object","entries","reduce","acc","key","value"],"mappings":"AAEA,SAASA,eAAe,QAAQ,UAAS;AAKzC,SAASC,6BAA6B,QAAQ,4CAA2C;AACzF,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,YAAY,QAAQ,0BAAyB;AAEtD,OAAO,MAAMC,qBACX,CAACC,eACD,CAACC;QACC,MAAMC,mBAAmBL,oBAAoB;YAAEI;YAAQD;QAAa;QACpE,IAAIC,OAAOE,WAAW,EAAE;YACtBF,OAAOE,WAAW,CAACC,IAAI,CAACF;QAC1B,OAAO;YACLD,OAAOE,WAAW,GAAG;gBAACD;aAAiB;QACzC;QAEA,uCAAuC;QACvCD,OAAOI,KAAK,GAAGJ,OAAOI,KAAK,IAAI,CAAC;QAChCJ,OAAOI,KAAK,CAACC,UAAU,GAAGL,OAAOI,KAAK,CAACC,UAAU,IAAI,CAAC;QACtDL,OAAOI,KAAK,CAACC,UAAU,CAACC,SAAS,GAAGN,OAAOI,KAAK,CAACC,UAAU,CAACC,SAAS,IAAI,EAAE;QAC3EN,OAAOI,KAAK,CAACC,UAAU,CAACC,SAAS,CAACH,IAAI,CACpC;QAGF,8CAA8C;QAC9CH,OAAOO,IAAI,GACTP,OAAOO,IAAI,IACV;YACCC,OAAO;gBAACb,8BAA8BK;aAAQ;QAChD,EAA4B,4CAA4C;;QAE1E,IAAIS,sBAAsBT,OAAOE,WAAW;QAE5C,MAAMQ,uBAAuBX,aAAaG,WAAW,IAAIH,aAAaG,WAAW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version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config, JobsConfig } from 'payload'\n\nimport { deepMergeSimple } from 'payload'\n\nimport type { PluginDefaultTranslationsObject } from './translations/types.js'\nimport type { ImportExportPluginConfig, ToCSVFunction } from './types.js'\n\nimport { getCreateCollectionExportTask } from './export/getCreateExportCollectionTask.js'\nimport { getExportCollection } from './getExportCollection.js'\nimport { translations } from './translations/index.js'\n\nexport const importExportPlugin =\n (pluginConfig: ImportExportPluginConfig) =>\n (config: Config): Config => {\n const exportCollection = getExportCollection({ config, pluginConfig })\n if (config.collections) {\n config.collections.push(exportCollection)\n } else {\n config.collections = [exportCollection]\n }\n\n // inject custom import export provider\n config.admin = config.admin || {}\n config.admin.components = config.admin.components || {}\n config.admin.components.providers = config.admin.components.providers || []\n config.admin.components.providers.push(\n '@payloadcms/plugin-import-export/rsc#ImportExportProvider',\n )\n\n // inject the createExport job into the config\n ;((config.jobs ??= {}).tasks ??= []).push(getCreateCollectionExportTask(config))\n\n let collectionsToUpdate = config.collections\n\n const usePluginCollections = pluginConfig.collections && pluginConfig.collections?.length > 0\n\n if (usePluginCollections) {\n collectionsToUpdate = config.collections?.filter((collection) => {\n return pluginConfig.collections?.includes(collection.slug)\n })\n }\n\n collectionsToUpdate.forEach((collection) => {\n if (!collection.admin) {\n collection.admin = { components: { listMenuItems: [] } }\n }\n const components = collection.admin.components || {}\n if (!components.listMenuItems) {\n components.listMenuItems = []\n }\n if (!components.edit) {\n components.edit = {}\n }\n if (!components.edit.SaveButton) {\n components.edit.SaveButton = '@payloadcms/plugin-import-export/rsc#ExportSaveButton'\n }\n components.listMenuItems.push({\n clientProps: {\n exportCollectionSlug: exportCollection.slug,\n },\n path: '@payloadcms/plugin-import-export/rsc#ExportListMenuItem',\n })\n collection.admin.components = components\n })\n\n if (!config.i18n) {\n config.i18n = {}\n }\n\n // config.i18n.translations = deepMergeSimple(translations, config.i18n?.translations ?? {})\n\n /**\n * Merge plugin translations\n */\n const simplifiedTranslations = Object.entries(translations).reduce(\n (acc, [key, value]) => {\n acc[key] = value.translations\n return acc\n },\n {} as Record<string, PluginDefaultTranslationsObject>,\n )\n\n config.i18n = {\n ...config.i18n,\n translations: deepMergeSimple(simplifiedTranslations, config.i18n?.translations ?? {}),\n }\n\n return config\n }\n\ndeclare module 'payload' {\n export interface FieldCustom {\n 'plugin-import-export'?: {\n toCSVFunction?: ToCSVFunction\n }\n }\n}\n"],"names":["deepMergeSimple","getCreateCollectionExportTask","getExportCollection","translations","importExportPlugin","pluginConfig","config","exportCollection","collections","push","admin","components","providers","jobs","tasks","collectionsToUpdate","usePluginCollections","length","filter","collection","includes","slug","forEach","listMenuItems","edit","SaveButton","clientProps","exportCollectionSlug","path","i18n","simplifiedTranslations","Object","entries","reduce","acc","key","value"],"mappings":"AAEA,SAASA,eAAe,QAAQ,UAAS;AAKzC,SAASC,6BAA6B,QAAQ,4CAA2C;AACzF,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,YAAY,QAAQ,0BAAyB;AAEtD,OAAO,MAAMC,qBACX,CAACC,eACD,CAACC;QACC,MAAMC,mBAAmBL,oBAAoB;YAAEI;YAAQD;QAAa;QACpE,IAAIC,OAAOE,WAAW,EAAE;YACtBF,OAAOE,WAAW,CAACC,IAAI,CAACF;QAC1B,OAAO;YACLD,OAAOE,WAAW,GAAG;gBAACD;aAAiB;QACzC;QAEA,uCAAuC;QACvCD,OAAOI,KAAK,GAAGJ,OAAOI,KAAK,IAAI,CAAC;QAChCJ,OAAOI,KAAK,CAACC,UAAU,GAAGL,OAAOI,KAAK,CAACC,UAAU,IAAI,CAAC;QACtDL,OAAOI,KAAK,CAACC,UAAU,CAACC,SAAS,GAAGN,OAAOI,KAAK,CAACC,UAAU,CAACC,SAAS,IAAI,EAAE;QAC3EN,OAAOI,KAAK,CAACC,UAAU,CAACC,SAAS,CAACH,IAAI,CACpC;QAIA,CAAA,AAACH,CAAAA,OAAOO,IAAI,KAAK,CAAC,CAAA,EAAGC,KAA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;YACZ,GAAGvB,OAAOuB,IAAI;YACd1B,cAAcH,gBAAgB8B,wBAAwBxB,OAAOuB,IAAI,EAAE1B,gBAAgB,CAAC;QACtF;QAEA,OAAOG;IACT,EAAC"}
@@ -2,20 +2,20 @@ export const zhTwTranslations = {
2
2
  'plugin-import-export': {
3
3
  allLocales: '所有地區',
4
4
  exportDocumentLabel: '匯出 {{label}}',
5
- exportOptions: '出口選項',
5
+ exportOptions: '匯出選項',
6
6
  'field-depth-label': '深度',
7
7
  'field-drafts-label': '包含草稿',
8
- 'field-fields-label': '田野',
9
- 'field-format-label': '出口格式',
10
- 'field-limit-label': '限制',
11
- 'field-locale-label': '地區設定',
8
+ 'field-fields-label': '欄位',
9
+ 'field-format-label': '匯出格式',
10
+ 'field-limit-label': '筆數限制',
11
+ 'field-locale-label': '語言/地區',
12
12
  'field-name-label': '檔案名稱',
13
- 'field-selectionToUse-label': '使用選擇',
14
- 'field-sort-label': '按照排序',
13
+ 'field-selectionToUse-label': '選擇範圍',
14
+ 'field-sort-label': '排序方式',
15
15
  'selectionToUse-allDocuments': '使用所有文件',
16
- 'selectionToUse-currentFilters': '使用當前過濾器',
17
- 'selectionToUse-currentSelection': '使用當前選擇',
18
- totalDocumentsCount: '{{count}} 總文件數'
16
+ 'selectionToUse-currentFilters': '使用目前篩選條件',
17
+ 'selectionToUse-currentSelection': '使用目前選擇',
18
+ totalDocumentsCount: '{{count}} 筆文件'
19
19
  }
20
20
  };
21
21
  export const zhTw = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/translations/languages/zhTw.ts"],"sourcesContent":["import type { PluginDefaultTranslationsObject, PluginLanguage } from '../types.js'\n\nexport const zhTwTranslations: PluginDefaultTranslationsObject = {\n 'plugin-import-export': {\n allLocales: '所有地區',\n exportDocumentLabel: '匯出 {{label}}',\n exportOptions: '出口選項',\n 'field-depth-label': '深度',\n 'field-drafts-label': '包含草稿',\n 'field-fields-label': '田野',\n 'field-format-label': '出口格式',\n 'field-limit-label': '限制',\n 'field-locale-label': '地區設定',\n 'field-name-label': '檔案名稱',\n 'field-selectionToUse-label': '使用選擇',\n 'field-sort-label': '按照排序',\n 'selectionToUse-allDocuments': '使用所有文件',\n 'selectionToUse-currentFilters': '使用當前過濾器',\n 'selectionToUse-currentSelection': '使用當前選擇',\n totalDocumentsCount: '{{count}} 總文件數',\n },\n}\n\nexport const zhTw: PluginLanguage = {\n dateFNSKey: 'zh-TW',\n translations: zhTwTranslations,\n}\n"],"names":["zhTwTranslations","allLocales","exportDocumentLabel","exportOptions","totalDocumentsCount","zhTw","dateFNSKey","translations"],"mappings":"AAEA,OAAO,MAAMA,mBAAoD;IAC/D,wBAAwB;QACtBC,YAAY;QACZC,qBAAqB;QACrBC,eAAe;QACf,qBAAqB;QACrB,sBAAsB;QACtB,sBAAsB;QACtB,sBAAsB;QACtB,qBAAqB;QACrB,sBAAsB;QACtB,oBAAoB;QACpB,8BAA8B;QAC9B,oBAAoB;QACpB,+BAA+B;QAC/B,iCAAiC;QACjC,mCAAmC;QACnCC,qBAAqB;IACvB;AACF,EAAC;AAED,OAAO,MAAMC,OAAuB;IAClCC,YAAY;IACZC,cAAcP;AAChB,EAAC"}
1
+ {"version":3,"sources":["../../../src/translations/languages/zhTw.ts"],"sourcesContent":["import type { PluginDefaultTranslationsObject, PluginLanguage } from '../types.js'\n\nexport const zhTwTranslations: PluginDefaultTranslationsObject = {\n 'plugin-import-export': {\n allLocales: '所有地區',\n exportDocumentLabel: '匯出 {{label}}',\n exportOptions: '匯出選項',\n 'field-depth-label': '深度',\n 'field-drafts-label': '包含草稿',\n 'field-fields-label': '欄位',\n 'field-format-label': '匯出格式',\n 'field-limit-label': '筆數限制',\n 'field-locale-label': '語言/地區',\n 'field-name-label': '檔案名稱',\n 'field-selectionToUse-label': '選擇範圍',\n 'field-sort-label': '排序方式',\n 'selectionToUse-allDocuments': '使用所有文件',\n 'selectionToUse-currentFilters': '使用目前篩選條件',\n 'selectionToUse-currentSelection': '使用目前選擇',\n totalDocumentsCount: '{{count}} 筆文件',\n },\n}\n\nexport const zhTw: PluginLanguage = {\n dateFNSKey: 'zh-TW',\n translations: zhTwTranslations,\n}\n"],"names":["zhTwTranslations","allLocales","exportDocumentLabel","exportOptions","totalDocumentsCount","zhTw","dateFNSKey","translations"],"mappings":"AAEA,OAAO,MAAMA,mBAAoD;IAC/D,wBAAwB;QACtBC,YAAY;QACZC,qBAAqB;QACrBC,eAAe;QACf,qBAAqB;QACrB,sBAAsB;QACtB,sBAAsB;QACtB,sBAAsB;QACtB,qBAAqB;QACrB,sBAAsB;QACtB,oBAAoB;QACpB,8BAA8B;QAC9B,oBAAoB;QACpB,+BAA+B;QAC/B,iCAAiC;QACjC,mCAAmC;QACnCC,qBAAqB;IACvB;AACF,EAAC;AAED,OAAO,MAAMC,OAAuB;IAClCC,YAAY;IACZC,cAAcP;AAChB,EAAC"}
package/dist/types.d.ts CHANGED
@@ -9,6 +9,10 @@ export type ImportExportPluginConfig = {
9
9
  * Defaults to all collections
10
10
  */
11
11
  collections?: string[];
12
+ /**
13
+ * If true, enables debug logging
14
+ */
15
+ debug?: boolean;
12
16
  /**
13
17
  * Enable to force the export to run synchronously
14
18
  */
@@ -20,4 +24,29 @@ export type ImportExportPluginConfig = {
20
24
  */
21
25
  overrideExportCollection?: (collection: CollectionOverride) => CollectionOverride;
22
26
  };
27
+ /**
28
+ * Custom function used to modify the outgoing csv data by manipulating the data, siblingData or by returning the desired value
29
+ */
30
+ export type ToCSVFunction = (args: {
31
+ /**
32
+ * The path of the column for the field, for arrays this includes the index (zero-based)
33
+ */
34
+ columnName: string;
35
+ /**
36
+ * The top level document
37
+ */
38
+ doc: Document;
39
+ /**
40
+ * The object data that can be manipulated to assign data to the CSV
41
+ */
42
+ row: Record<string, unknown>;
43
+ /**
44
+ * The document data at the level where it belongs
45
+ */
46
+ siblingDoc: Record<string, unknown>;
47
+ /**
48
+ * The data for the field.
49
+ */
50
+ value: unknown;
51
+ }) => unknown;
23
52
  //# sourceMappingURL=types.d.ts.map
@@ -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,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,kBAAkB,CAAA;CAClF,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;;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 CHANGED
@@ -1,3 +1,5 @@
1
- export { };
1
+ /**
2
+ * Custom function used to modify the outgoing csv data by manipulating the data, siblingData or by returning the desired value
3
+ */ export { };
2
4
 
3
5
  //# sourceMappingURL=types.js.map
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 * 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"],"names":[],"mappings":"AAOA,WAgBC"}
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,WAqBa"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-import-export",
3
- "version": "3.42.0-internal.f9d0258",
3
+ "version": "3.42.0",
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.42.0-internal.f9d0258",
68
- "@payloadcms/ui": "3.42.0-internal.f9d0258"
67
+ "@payloadcms/translations": "3.42.0",
68
+ "@payloadcms/ui": "3.42.0"
69
69
  },
70
70
  "devDependencies": {
71
- "@payloadcms/eslint-config": "3.28.0",
72
- "@payloadcms/ui": "3.42.0-internal.f9d0258",
73
- "payload": "3.42.0-internal.f9d0258"
71
+ "@payloadcms/ui": "3.42.0",
72
+ "payload": "3.42.0",
73
+ "@payloadcms/eslint-config": "3.28.0"
74
74
  },
75
75
  "peerDependencies": {
76
- "@payloadcms/ui": "3.42.0-internal.f9d0258",
77
- "payload": "3.42.0-internal.f9d0258"
76
+ "@payloadcms/ui": "3.42.0",
77
+ "payload": "3.42.0"
78
78
  },
79
79
  "homepage:": "https://payloadcms.com",
80
80
  "scripts": {