@payloadcms/plugin-import-export 0.0.1-beta.0 → 3.27.0-canary.7f71c2e

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/README.md CHANGED
@@ -5,13 +5,3 @@ A plugin for [Payload](https://github.com/payloadcms/payload) to easily import a
5
5
  - [Source code](https://github.com/payloadcms/payload/tree/main/packages/plugin-import-export)
6
6
  - [Documentation](https://payloadcms.com/docs/plugins/import-export)
7
7
  - [Documentation source](https://github.com/payloadcms/payload/tree/main/docs/plugins/import-export.mdx)
8
-
9
- [//]: # 'TODO: Remove requirements'
10
-
11
- ## Requirements
12
-
13
- ### Exports
14
-
15
- - [ ] The export button should be visible on the collection list.
16
-
17
- Create writable streams for each collection and write the data to the streams. The streams should be piped to a zip stream and sent to the client.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ExportSaveButton/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAiBpC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ExportSaveButton/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAkEpC,CAAA"}
@@ -1,13 +1,57 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { Button, SaveButton, useTranslation } from '@payloadcms/ui';
3
+ import { Button, SaveButton, useConfig, useForm, useTranslation } from '@payloadcms/ui';
4
4
  import React from 'react';
5
5
  export const ExportSaveButton = ()=>{
6
6
  const { t } = useTranslation();
7
+ const { config: { routes: { api }, serverURL } } = useConfig();
8
+ const { getData } = useForm();
7
9
  const label = t('general:save');
8
- const handleDownload = ()=>{
9
- console.log('Download');
10
- // TODO: create a post to the download endpoint to stream data back to the client
10
+ const handleDownload = async ()=>{
11
+ try {
12
+ const data = getData();
13
+ const response = await fetch(`${serverURL}${api}/exports/download`, {
14
+ body: JSON.stringify({
15
+ data
16
+ }),
17
+ credentials: 'include',
18
+ headers: {
19
+ 'Content-Type': 'application/json'
20
+ },
21
+ method: 'POST'
22
+ });
23
+ if (!response.ok) {
24
+ throw new Error('Failed to download file');
25
+ }
26
+ const fileStream = response.body;
27
+ const reader = fileStream?.getReader();
28
+ const decoder = new TextDecoder();
29
+ let result = '';
30
+ while(reader){
31
+ const { done, value } = await reader.read();
32
+ if (done) {
33
+ break;
34
+ }
35
+ result += decoder.decode(value, {
36
+ stream: true
37
+ });
38
+ }
39
+ const blob = new Blob([
40
+ result
41
+ ], {
42
+ type: 'text/plain'
43
+ });
44
+ const url = URL.createObjectURL(blob);
45
+ const a = document.createElement('a');
46
+ a.href = url;
47
+ a.download = `${data.name}.${data.format}`;
48
+ document.body.appendChild(a);
49
+ a.click();
50
+ document.body.removeChild(a);
51
+ URL.revokeObjectURL(url);
52
+ } catch (error) {
53
+ console.error('Error downloading file:', error);
54
+ }
11
55
  };
12
56
  return /*#__PURE__*/ _jsxs(React.Fragment, {
13
57
  children: [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/ExportSaveButton/index.tsx"],"sourcesContent":["'use client'\n\nimport { Button, SaveButton, useTranslation } from '@payloadcms/ui'\nimport React from 'react'\n\nexport const ExportSaveButton: React.FC = () => {\n const { t } = useTranslation()\n const label = t('general:save')\n\n const handleDownload = () => {\n console.log('Download')\n // TODO: create a post to the download endpoint to stream data back to the client\n }\n\n return (\n <React.Fragment>\n <SaveButton label={label}></SaveButton>\n <Button onClick={handleDownload} size=\"medium\" type=\"button\">\n Download\n </Button>\n </React.Fragment>\n )\n}\n"],"names":["Button","SaveButton","useTranslation","React","ExportSaveButton","t","label","handleDownload","console","log","Fragment","onClick","size","type"],"mappings":"AAAA;;AAEA,SAASA,MAAM,EAAEC,UAAU,EAAEC,cAAc,QAAQ,iBAAgB;AACnE,OAAOC,WAAW,QAAO;AAEzB,OAAO,MAAMC,mBAA6B;IACxC,MAAM,EAAEC,CAAC,EAAE,GAAGH;IACd,MAAMI,QAAQD,EAAE;IAEhB,MAAME,iBAAiB;QACrBC,QAAQC,GAAG,CAAC;IACZ,iFAAiF;IACnF;IAEA,qBACE,MAACN,MAAMO,QAAQ;;0BACb,KAACT;gBAAWK,OAAOA;;0BACnB,KAACN;gBAAOW,SAASJ;gBAAgBK,MAAK;gBAASC,MAAK;0BAAS;;;;AAKnE,EAAC"}
1
+ {"version":3,"sources":["../../../src/components/ExportSaveButton/index.tsx"],"sourcesContent":["'use client'\n\nimport { Button, SaveButton, useConfig, useForm, useTranslation } from '@payloadcms/ui'\nimport React from 'react'\n\nexport const ExportSaveButton: React.FC = () => {\n const { t } = useTranslation()\n const {\n config: {\n routes: { api },\n serverURL,\n },\n } = useConfig()\n\n const { getData } = useForm()\n\n const label = t('general:save')\n\n const handleDownload = async () => {\n try {\n const data = getData()\n const response = await fetch(`${serverURL}${api}/exports/download`, {\n body: JSON.stringify({\n data,\n }),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n })\n\n if (!response.ok) {\n throw new Error('Failed to download file')\n }\n\n const fileStream = response.body\n const reader = fileStream?.getReader()\n const decoder = new TextDecoder()\n let result = ''\n\n while (reader) {\n const { done, value } = await reader.read()\n if (done) {\n break\n }\n result += decoder.decode(value, { stream: true })\n }\n\n const blob = new Blob([result], { type: 'text/plain' })\n const url = URL.createObjectURL(blob)\n const a = document.createElement('a')\n a.href = url\n a.download = `${data.name}.${data.format}`\n document.body.appendChild(a)\n a.click()\n document.body.removeChild(a)\n URL.revokeObjectURL(url)\n } catch (error) {\n console.error('Error downloading file:', error)\n }\n }\n\n return (\n <React.Fragment>\n <SaveButton label={label}></SaveButton>\n <Button onClick={handleDownload} size=\"medium\" type=\"button\">\n Download\n </Button>\n </React.Fragment>\n )\n}\n"],"names":["Button","SaveButton","useConfig","useForm","useTranslation","React","ExportSaveButton","t","config","routes","api","serverURL","getData","label","handleDownload","data","response","fetch","body","JSON","stringify","credentials","headers","method","ok","Error","fileStream","reader","getReader","decoder","TextDecoder","result","done","value","read","decode","stream","blob","Blob","type","url","URL","createObjectURL","a","document","createElement","href","download","name","format","appendChild","click","removeChild","revokeObjectURL","error","console","Fragment","onClick","size"],"mappings":"AAAA;;AAEA,SAASA,MAAM,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,cAAc,QAAQ,iBAAgB;AACvF,OAAOC,WAAW,QAAO;AAEzB,OAAO,MAAMC,mBAA6B;IACxC,MAAM,EAAEC,CAAC,EAAE,GAAGH;IACd,MAAM,EACJI,QAAQ,EACNC,QAAQ,EAAEC,GAAG,EAAE,EACfC,SAAS,EACV,EACF,GAAGT;IAEJ,MAAM,EAAEU,OAAO,EAAE,GAAGT;IAEpB,MAAMU,QAAQN,EAAE;IAEhB,MAAMO,iBAAiB;QACrB,IAAI;YACF,MAAMC,OAAOH;YACb,MAAMI,WAAW,MAAMC,MAAM,GAAGN,YAAYD,IAAI,iBAAiB,CAAC,EAAE;gBAClEQ,MAAMC,KAAKC,SAAS,CAAC;oBACnBL;gBACF;gBACAM,aAAa;gBACbC,SAAS;oBACP,gBAAgB;gBAClB;gBACAC,QAAQ;YACV;YAEA,IAAI,CAACP,SAASQ,EAAE,EAAE;gBAChB,MAAM,IAAIC,MAAM;YAClB;YAEA,MAAMC,aAAaV,SAASE,IAAI;YAChC,MAAMS,SAASD,YAAYE;YAC3B,MAAMC,UAAU,IAAIC;YACpB,IAAIC,SAAS;YAEb,MAAOJ,OAAQ;gBACb,MAAM,EAAEK,IAAI,EAAEC,KAAK,EAAE,GAAG,MAAMN,OAAOO,IAAI;gBACzC,IAAIF,MAAM;oBACR;gBACF;gBACAD,UAAUF,QAAQM,MAAM,CAACF,OAAO;oBAAEG,QAAQ;gBAAK;YACjD;YAEA,MAAMC,OAAO,IAAIC,KAAK;gBAACP;aAAO,EAAE;gBAAEQ,MAAM;YAAa;YACrD,MAAMC,MAAMC,IAAIC,eAAe,CAACL;YAChC,MAAMM,IAAIC,SAASC,aAAa,CAAC;YACjCF,EAAEG,IAAI,GAAGN;YACTG,EAAEI,QAAQ,GAAG,GAAGhC,KAAKiC,IAAI,CAAC,CAAC,EAAEjC,KAAKkC,MAAM,EAAE;YAC1CL,SAAS1B,IAAI,CAACgC,WAAW,CAACP;YAC1BA,EAAEQ,KAAK;YACPP,SAAS1B,IAAI,CAACkC,WAAW,CAACT;YAC1BF,IAAIY,eAAe,CAACb;QACtB,EAAE,OAAOc,OAAO;YACdC,QAAQD,KAAK,CAAC,2BAA2BA;QAC3C;IACF;IAEA,qBACE,MAACjD,MAAMmD,QAAQ;;0BACb,KAACvD;gBAAWY,OAAOA;;0BACnB,KAACb;gBAAOyD,SAAS3C;gBAAgB4C,MAAK;gBAASnB,MAAK;0BAAS;;;;AAKnE,EAAC"}
@@ -15,10 +15,14 @@ type Export = {
15
15
  where?: Where;
16
16
  };
17
17
  export type CreateExportArgs = {
18
+ /**
19
+ * If true, stream the file instead of saving it
20
+ */
21
+ download?: boolean;
18
22
  input: Export;
19
23
  req: PayloadRequest;
20
24
  user?: User;
21
25
  };
22
- export declare const createExport: (args: CreateExportArgs) => Promise<void>;
26
+ export declare const createExport: (args: CreateExportArgs) => Promise<Response | undefined>;
23
27
  export {};
24
28
  //# 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,iBAAiB,EAAE,MAAM,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,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AC7B;;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,kCAkHxD,CAAA"}
@@ -1,17 +1,18 @@
1
- import { Buffer } from 'buffer';
2
1
  import { stringify } from 'csv-stringify/sync';
3
2
  import { APIError } from 'payload';
3
+ import { Readable } from 'stream';
4
4
  import { flattenObject } from './flattenObject.js';
5
5
  import { getFilename } from './getFilename.js';
6
6
  import { getSelect } from './getSelect.js';
7
7
  export const createExport = async (args)=>{
8
- const { input: { id, name: nameArg, collectionSlug, exportsCollection, fields, format, locale: localeInput, sort, user, where }, req: { locale: localeArg, payload }, req } = args;
8
+ const { download, input: { id, name: nameArg, collectionSlug, exportsCollection, fields, format, locale: localeInput, sort, user, where }, req: { locale: localeArg, payload }, req } = args;
9
9
  const locale = localeInput ?? localeArg;
10
10
  const collectionConfig = payload.config.collections.find(({ slug })=>slug === collectionSlug);
11
11
  if (!collectionConfig) {
12
12
  throw new APIError(`Collection with slug ${collectionSlug} not found`);
13
13
  }
14
14
  const name = `${nameArg ?? `${getFilename()}-${collectionSlug}`}.${format}`;
15
+ const isCSV = format === 'csv';
15
16
  const findArgs = {
16
17
  collection: collectionSlug,
17
18
  depth: 0,
@@ -27,31 +28,58 @@ export const createExport = async (args)=>{
27
28
  let result = {
28
29
  hasNextPage: true
29
30
  };
31
+ if (download) {
32
+ const encoder = new TextEncoder();
33
+ const stream = new Readable({
34
+ async read () {
35
+ let result = await payload.find(findArgs);
36
+ let isFirstBatch = true;
37
+ while(result.docs.length > 0){
38
+ const csvInput = result.docs.map((doc)=>flattenObject(doc));
39
+ const csvString = stringify(csvInput, {
40
+ header: isFirstBatch
41
+ });
42
+ this.push(encoder.encode(csvString));
43
+ isFirstBatch = false;
44
+ if (!result.hasNextPage) {
45
+ this.push(null) // End the stream
46
+ ;
47
+ break;
48
+ }
49
+ findArgs.page += 1;
50
+ result = await payload.find(findArgs);
51
+ }
52
+ }
53
+ });
54
+ return new Response(stream, {
55
+ headers: {
56
+ 'Content-Disposition': `attachment; filename="${name}"`,
57
+ 'Content-Type': isCSV ? 'text/csv' : 'application/json'
58
+ }
59
+ });
60
+ }
30
61
  const outputData = [];
31
62
  let isFirstBatch = true;
32
63
  while(result.hasNextPage){
33
- findArgs.page = findArgs.page + 1;
64
+ findArgs.page += 1;
34
65
  result = await payload.find(findArgs);
35
- if (format === 'csv') {
66
+ if (isCSV) {
36
67
  const csvInput = result.docs.map((doc)=>flattenObject(doc));
37
- const csvString = stringify(csvInput, {
68
+ outputData.push(stringify(csvInput, {
38
69
  header: isFirstBatch
39
- });
40
- outputData.push(csvString);
70
+ }));
41
71
  isFirstBatch = false;
42
- }
43
- if (format === 'json') {
72
+ } else {
44
73
  const jsonInput = result.docs.map((doc)=>JSON.stringify(doc));
45
74
  outputData.push(jsonInput.join(',\n'));
46
75
  }
47
76
  }
48
77
  const buffer = Buffer.from(format === 'json' ? `[${outputData.join(',')}]` : outputData.join(''));
49
- // when `disableJobsQueue` is true, the export is created synchronously in a beforeOperation hook
50
78
  if (!id) {
51
79
  req.file = {
52
80
  name,
53
81
  data: buffer,
54
- mimetype: format === 'json' ? 'application/json' : `text/${format}`,
82
+ mimetype: isCSV ? 'text/csv' : 'application/json',
55
83
  size: buffer.length
56
84
  };
57
85
  } else {
@@ -62,9 +90,10 @@ export const createExport = async (args)=>{
62
90
  file: {
63
91
  name,
64
92
  data: buffer,
65
- mimetype: format === 'json' ? 'application/json' : `text/${format}`,
93
+ mimetype: isCSV ? 'text/csv' : 'application/json',
66
94
  size: buffer.length
67
- }
95
+ },
96
+ user
68
97
  });
69
98
  }
70
99
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/export/createExport.ts"],"sourcesContent":["import type { PaginatedDocs, PayloadRequest, Sort, User, Where } from 'payload'\n\nimport { Buffer } from 'buffer'\nimport { stringify } from 'csv-stringify/sync'\nimport { APIError } from 'payload'\n\nimport { flattenObject } from './flattenObject.js'\nimport { getFilename } from './getFilename.js'\nimport { getSelect } from './getSelect.js'\n\ntype Export = {\n collectionSlug: string\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 input: Export\n req: PayloadRequest\n user?: User\n}\n\nexport const createExport = async (args: CreateExportArgs) => {\n const {\n input: {\n id,\n name: nameArg,\n collectionSlug,\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 const locale = localeInput ?? localeArg\n\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 const name = `${nameArg ?? `${getFilename()}-${collectionSlug}`}.${format}`\n\n const findArgs = {\n collection: collectionSlug,\n depth: 0,\n limit: 100,\n locale,\n overrideAccess: false,\n page: 0,\n select: fields ? getSelect(fields) : undefined,\n sort,\n user,\n where,\n }\n\n let result: PaginatedDocs = { hasNextPage: true } as PaginatedDocs\n const outputData: string[] = []\n\n let isFirstBatch = true\n\n while (result.hasNextPage) {\n findArgs.page = findArgs.page + 1\n result = await payload.find(findArgs)\n\n if (format === 'csv') {\n const csvInput = result.docs.map((doc) => flattenObject(doc))\n\n const csvString = stringify(csvInput, {\n header: isFirstBatch, // Only include header in the first batch\n })\n\n outputData.push(csvString)\n isFirstBatch = false\n }\n\n if (format === 'json') {\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 // when `disableJobsQueue` is true, the export is created synchronously in a beforeOperation hook\n if (!id) {\n req.file = {\n name,\n data: buffer,\n mimetype: format === 'json' ? 'application/json' : `text/${format}`,\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: format === 'json' ? 'application/json' : `text/${format}`,\n size: buffer.length,\n },\n })\n }\n}\n"],"names":["Buffer","stringify","APIError","flattenObject","getFilename","getSelect","createExport","args","input","id","name","nameArg","collectionSlug","exportsCollection","fields","format","locale","localeInput","sort","user","where","req","localeArg","payload","collectionConfig","config","collections","find","slug","findArgs","collection","depth","limit","overrideAccess","page","select","undefined","result","hasNextPage","outputData","isFirstBatch","csvInput","docs","map","doc","csvString","header","push","jsonInput","JSON","join","buffer","from","file","data","mimetype","size","length","update"],"mappings":"AAEA,SAASA,MAAM,QAAQ,SAAQ;AAC/B,SAASC,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,QAAQ,QAAQ,UAAS;AAElC,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,SAAS,QAAQ,iBAAgB;AAwB1C,OAAO,MAAMC,eAAe,OAAOC;IACjC,MAAM,EACJC,OAAO,EACLC,EAAE,EACFC,MAAMC,OAAO,EACbC,cAAc,EACdC,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,GAAGd;IAEJ,MAAMS,SAASC,eAAeK;IAE9B,MAAME,mBAAmBD,QAAQE,MAAM,CAACC,WAAW,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAAShB;IAChF,IAAI,CAACY,kBAAkB;QACrB,MAAM,IAAItB,SAAS,CAAC,qBAAqB,EAAEU,eAAe,UAAU,CAAC;IACvE;IACA,MAAMF,OAAO,GAAGC,WAAW,GAAGP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M;gBACJ3C;gBACA4C,MAAMH;gBACNI,UAAUxC,WAAW,SAAS,qBAAqB,CAAC,KAAK,EAAEA,QAAQ;gBACnEyC,MAAML,OAAOM,MAAM;YACrB;QACF;IACF;AACF,EAAC"}
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 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 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 limit: 100,\n locale,\n overrideAccess: false,\n page: 0,\n select: fields ? 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))\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))\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","exportsCollection","fields","format","locale","localeInput","sort","user","where","req","localeArg","payload","collectionConfig","config","collections","find","slug","isCSV","findArgs","collection","depth","limit","overrideAccess","page","select","undefined","result","hasNextPage","encoder","TextEncoder","stream","read","isFirstBatch","docs","length","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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MzB,IAAIE,OAAO,CAAC4C,MAAM,CAAC;YACvB1D;YACAsB,YAAYlB;YACZmD,MAAM,CAAC;YACPD,MAAM;gBACJrD;gBACAsD,MAAMJ;gBACNK,UAAUpC,QAAQ,aAAa;gBAC/BqC,MAAMN,OAAOd,MAAM;YACrB;YACA3B;QACF;IACF;AACF,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { PayloadHandler } from 'payload';
2
+ export declare const download: PayloadHandler;
3
+ //# sourceMappingURL=download.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,20 @@
1
+ import { APIError } from 'payload';
2
+ import { createExport } from './createExport.js';
3
+ export const download = async (req)=>{
4
+ let body;
5
+ if (typeof req?.json === 'function') {
6
+ body = await req.json();
7
+ }
8
+ if (!body || !body.data) {
9
+ throw new APIError('Request data is required.');
10
+ }
11
+ req.payload.logger.info(`Download request received ${body.data.collectionSlug}`);
12
+ body.data.user = req.user;
13
+ return createExport({
14
+ download: true,
15
+ input: body.data,
16
+ req
17
+ });
18
+ };
19
+
20
+ //# sourceMappingURL=download.js.map
@@ -0,0 +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 +1 @@
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;AAK9E,eAAO,MAAM,mBAAmB,8BAG7B;IACD,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,gBA4DH,CAAA"}
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,4 +1,5 @@
1
1
  import { createExport } from './export/createExport.js';
2
+ import { download } from './export/download.js';
2
3
  import { getFields } from './export/getFields.js';
3
4
  export const getExportCollection = ({ config, pluginConfig })=>{
4
5
  const { overrideExportCollection } = pluginConfig;
@@ -14,6 +15,13 @@ export const getExportCollection = ({ config, pluginConfig })=>{
14
15
  useAsTitle: 'name'
15
16
  },
16
17
  disableDuplicate: true,
18
+ endpoints: [
19
+ {
20
+ handler: download,
21
+ method: 'post',
22
+ path: '/download'
23
+ }
24
+ ],
17
25
  fields: getFields(config),
18
26
  hooks: {
19
27
  afterChange,
@@ -1 +1 @@
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 { 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 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","getFields","getExportCollection","config","pluginConfig","overrideExportCollection","beforeOperation","afterChange","collection","slug","access","update","admin","group","useAsTitle","disableDuplicate","fields","hooks","upload","filesRequiredOnCreate","hideFileInputOnCreate","hideRemoveFile","disableJobsQueue","push","args","operation","req","user","input","data","doc","exportsCollection","id","userCollection","payload","jobs","queue","task"],"mappings":"AASA,SAASA,YAAY,QAAQ,2BAA0B;AACvD,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,QAAQf,UAAUE;QAClBc,OAAO;YACLV;YACAD;QACF;QACAY,QAAQ;YACNC,uBAAuB;YACvBC,uBAAuB;YACvBC,gBAAgB;QAClB;IACF;IAEA,IAAI,OAAOhB,6BAA6B,YAAY;QAClDG,aAAaH,yBAAyBG;IACxC;IAEA,IAAIJ,aAAakB,gBAAgB,EAAE;QACjChB,gBAAgBiB,IAAI,CAAC,OAAO,EAAEC,IAAI,EAAEC,SAAS,EAAEC,GAAG,EAAE;YAClD,IAAID,cAAc,UAAU;gBAC1B;YACF;YACA,MAAM,EAAEE,IAAI,EAAE,GAAGD;YACjB,MAAM1B,aAAa;gBAAE4B,OAAO;oBAAE,GAAGJ,KAAKK,IAAI;oBAAEF;gBAAK;gBAAGD;YAAI;QAC1D;IACF,OAAO;QACLnB,YAAYgB,IAAI,CAAC,OAAO,EAAEO,GAAG,EAAEL,SAAS,EAAEC,GAAG,EAAE;YAC7C,IAAID,cAAc,UAAU;gBAC1B;YACF;YAEA,MAAMG,QAAQ;gBACZ,GAAGE,GAAG;gBACNC,mBAAmBvB,WAAWC,IAAI;gBAClCkB,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,OAAO7B;AACT,EAAC"}
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"}
package/dist/types.d.ts CHANGED
@@ -13,10 +13,6 @@ export type ImportExportPluginConfig = {
13
13
  * Enable to force the export to run synchronously
14
14
  */
15
15
  disableJobsQueue?: boolean;
16
- /**
17
- * Globals to include the Import/Export controls in
18
- */
19
- globals?: string[];
20
16
  /**
21
17
  * This function takes the default export collection configured in the plugin and allows you to override it by modifying and returning it
22
18
  * @param collection
@@ -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;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB;;;;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,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,kBAAkB,CAAA;CAClF,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 * Enable to force the export to run synchronously\n */\n disableJobsQueue?: boolean\n /**\n * Globals to include the Import/Export controls in\n */\n globals?: string[]\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,WAoBC"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-import-export",
3
- "version": "0.0.1-beta.0",
3
+ "version": "3.27.0-canary.7f71c2e",
4
4
  "description": "Import-Export plugin for Payload",
5
5
  "keywords": [
6
6
  "payload",
@@ -54,17 +54,17 @@
54
54
  "csv-parse": "^5.6.0",
55
55
  "csv-stringify": "^6.5.2",
56
56
  "qs-esm": "7.0.2",
57
- "@payloadcms/translations": "3.25.0",
58
- "@payloadcms/ui": "3.25.0"
57
+ "@payloadcms/translations": "3.27.0-canary.7f71c2e",
58
+ "@payloadcms/ui": "3.27.0-canary.7f71c2e"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@payloadcms/eslint-config": "3.9.0",
62
- "@payloadcms/ui": "3.25.0",
63
- "payload": "3.25.0"
62
+ "@payloadcms/ui": "3.27.0-canary.7f71c2e",
63
+ "payload": "3.27.0-canary.7f71c2e"
64
64
  },
65
65
  "peerDependencies": {
66
- "@payloadcms/ui": "3.25.0",
67
- "payload": "3.25.0"
66
+ "payload": "3.27.0-canary.7f71c2e",
67
+ "@payloadcms/ui": "3.27.0-canary.7f71c2e"
68
68
  },
69
69
  "homepage:": "https://payloadcms.com",
70
70
  "scripts": {