@payloadcms/plugin-import-export 3.44.0-canary.6 → 3.44.0-canary.8

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.
@@ -1 +1 @@
1
- {"version":3,"file":"flattenObject.d.ts","sourceRoot":"","sources":["../../src/export/flattenObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,QAAQ,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;CAC9C,CAAA;AAED,eAAO,MAAM,aAAa,6CAKvB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAmF/B,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,CA4F/B,CAAA"}
@@ -10,13 +10,16 @@ export const flattenObject = ({ doc, fields, prefix, toCSVFunctions })=>{
10
10
  } else {
11
11
  if (toCSVFunctions?.[newKey]) {
12
12
  const columnName = `${newKey}_${index}`;
13
- row[columnName] = toCSVFunctions[newKey]({
13
+ const result = toCSVFunctions[newKey]({
14
14
  columnName,
15
15
  doc,
16
16
  row,
17
17
  siblingDoc,
18
18
  value: item
19
19
  });
20
+ if (typeof result !== 'undefined') {
21
+ row[columnName] = result;
22
+ }
20
23
  } else {
21
24
  row[`${newKey}_${index}`] = item;
22
25
  }
@@ -26,23 +29,29 @@ export const flattenObject = ({ doc, fields, prefix, toCSVFunctions })=>{
26
29
  if (!toCSVFunctions?.[newKey]) {
27
30
  flatten(value, newKey);
28
31
  } else {
29
- row[newKey] = toCSVFunctions[newKey]({
32
+ const result = toCSVFunctions[newKey]({
30
33
  columnName: newKey,
31
34
  doc,
32
35
  row,
33
36
  siblingDoc,
34
37
  value
35
38
  });
39
+ if (typeof result !== 'undefined') {
40
+ row[newKey] = result;
41
+ }
36
42
  }
37
43
  } else {
38
44
  if (toCSVFunctions?.[newKey]) {
39
- row[newKey] = toCSVFunctions[newKey]({
45
+ const result = toCSVFunctions[newKey]({
40
46
  columnName: newKey,
41
47
  doc,
42
48
  row,
43
49
  siblingDoc,
44
50
  value
45
51
  });
52
+ if (typeof result !== 'undefined') {
53
+ row[newKey] = result;
54
+ }
46
55
  } else {
47
56
  row[newKey] = value;
48
57
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/export/flattenObject.ts"],"sourcesContent":["import type { Document } from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\ntype Args = {\n doc: Document\n fields?: string[]\n prefix?: string\n toCSVFunctions: Record<string, ToCSVFunction>\n}\n\nexport const flattenObject = ({\n doc,\n fields,\n prefix,\n toCSVFunctions,\n}: Args): Record<string, unknown> => {\n const row: Record<string, unknown> = {}\n\n const flatten = (siblingDoc: Document, prefix?: string) => {\n Object.entries(siblingDoc).forEach(([key, value]) => {\n const newKey = prefix ? `${prefix}_${key}` : key\n\n if (Array.isArray(value)) {\n value.forEach((item, index) => {\n if (typeof item === 'object' && item !== null) {\n flatten(item, `${newKey}_${index}`)\n } else {\n if (toCSVFunctions?.[newKey]) {\n const columnName = `${newKey}_${index}`\n 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 (Array.isArray(fields) && fields.length > 0) {\n const orderedResult: Record<string, unknown> = {}\n\n const fieldToRegex = (field: string): RegExp => {\n const parts = field.split('.').map((part) => `${part}(?:_\\\\d+)?`)\n const pattern = `^${parts.join('_')}`\n return new RegExp(pattern)\n }\n\n fields.forEach((field) => {\n if (row[field.replace(/\\./g, '_')]) {\n const sanitizedField = field.replace(/\\./g, '_')\n orderedResult[sanitizedField] = row[sanitizedField]\n } else {\n const regex = fieldToRegex(field)\n Object.keys(row).forEach((key) => {\n if (regex.test(key)) {\n orderedResult[key] = row[key]\n }\n })\n }\n })\n\n return orderedResult\n }\n\n return row\n}\n"],"names":["flattenObject","doc","fields","prefix","toCSVFunctions","row","flatten","siblingDoc","Object","entries","forEach","key","value","newKey","Array","isArray","item","index","columnName","length","orderedResult","fieldToRegex","field","parts","split","map","part","pattern","join","RegExp","replace","sanitizedField","regex","keys","test"],"mappings":"AAWA,OAAO,MAAMA,gBAAgB,CAAC,EAC5BC,GAAG,EACHC,MAAM,EACNC,MAAM,EACNC,cAAc,EACT;IACL,MAAMC,MAA+B,CAAC;IAEtC,MAAMC,UAAU,CAACC,YAAsBJ;QACrCK,OAAOC,OAAO,CAACF,YAAYG,OAAO,CAAC,CAAC,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ME,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;QAEAzB,OAAOQ,OAAO,CAAC,CAACY;YACd,IAAIjB,GAAG,CAACiB,MAAMQ,OAAO,CAAC,OAAO,KAAK,EAAE;gBAClC,MAAMC,iBAAiBT,MAAMQ,OAAO,CAAC,OAAO;gBAC5CV,aAAa,CAACW,eAAe,GAAG1B,GAAG,CAAC0B,eAAe;YACrD,OAAO;gBACL,MAAMC,QAAQX,aAAaC;gBAC3Bd,OAAOyB,IAAI,CAAC5B,KAAKK,OAAO,CAAC,CAACC;oBACxB,IAAIqB,MAAME,IAAI,CAACvB,MAAM;wBACnBS,aAAa,CAACT,IAAI,GAAGN,GAAG,CAACM,IAAI;oBAC/B;gBACF;YACF;QACF;QAEA,OAAOS;IACT;IAEA,OAAOf;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 const result = toCSVFunctions[newKey]({\n columnName,\n doc,\n row,\n siblingDoc,\n value: item,\n })\n if (typeof result !== 'undefined') {\n row[columnName] = result\n }\n } else {\n row[`${newKey}_${index}`] = item\n }\n }\n })\n } else if (typeof value === 'object' && value !== null) {\n if (!toCSVFunctions?.[newKey]) {\n flatten(value, newKey)\n } else {\n const result = toCSVFunctions[newKey]({\n columnName: newKey,\n doc,\n row,\n siblingDoc,\n value,\n })\n if (typeof result !== 'undefined') {\n row[newKey] = result\n }\n }\n } else {\n if (toCSVFunctions?.[newKey]) {\n const result = toCSVFunctions[newKey]({\n columnName: newKey,\n doc,\n row,\n siblingDoc,\n value,\n })\n if (typeof result !== 'undefined') {\n row[newKey] = result\n }\n } else {\n row[newKey] = value\n }\n }\n })\n }\n\n flatten(doc, prefix)\n\n if (Array.isArray(fields) && fields.length > 0) {\n const orderedResult: Record<string, unknown> = {}\n\n const fieldToRegex = (field: string): RegExp => {\n const parts = field.split('.').map((part) => `${part}(?:_\\\\d+)?`)\n const pattern = `^${parts.join('_')}`\n return new RegExp(pattern)\n }\n\n fields.forEach((field) => {\n if (row[field.replace(/\\./g, '_')]) {\n const sanitizedField = field.replace(/\\./g, '_')\n orderedResult[sanitizedField] = row[sanitizedField]\n } else {\n const regex = fieldToRegex(field)\n Object.keys(row).forEach((key) => {\n if (regex.test(key)) {\n orderedResult[key] = row[key]\n }\n })\n }\n })\n\n return orderedResult\n }\n\n return row\n}\n"],"names":["flattenObject","doc","fields","prefix","toCSVFunctions","row","flatten","siblingDoc","Object","entries","forEach","key","value","newKey","Array","isArray","item","index","columnName","result","length","orderedResult","fieldToRegex","field","parts","split","map","part","pattern","join","RegExp","replace","sanitizedField","regex","keys","test"],"mappings":"AAWA,OAAO,MAAMA,gBAAgB,CAAC,EAC5BC,GAAG,EACHC,MAAM,EACNC,MAAM,EACNC,cAAc,EACT;IACL,MAAMC,MAA+B,CAAC;IAEtC,MAAMC,UAAU,CAACC,YAAsBJ;QACrCK,OAAOC,OAAO,CAACF,YAAYG,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;YAC9C,MAAMC,SAASV,SAAS,GAAGA,OAAO,CAAC,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WA,OAAOkB,MAAM,GAAG,GAAG;QAC9C,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;QAEA1B,OAAOQ,OAAO,CAAC,CAACa;YACd,IAAIlB,GAAG,CAACkB,MAAMQ,OAAO,CAAC,OAAO,KAAK,EAAE;gBAClC,MAAMC,iBAAiBT,MAAMQ,OAAO,CAAC,OAAO;gBAC5CV,aAAa,CAACW,eAAe,GAAG3B,GAAG,CAAC2B,eAAe;YACrD,OAAO;gBACL,MAAMC,QAAQX,aAAaC;gBAC3Bf,OAAO0B,IAAI,CAAC7B,KAAKK,OAAO,CAAC,CAACC;oBACxB,IAAIsB,MAAME,IAAI,CAACxB,MAAM;wBACnBU,aAAa,CAACV,IAAI,GAAGN,GAAG,CAACM,IAAI;oBAC/B;gBACF;YACF;QACF;QAEA,OAAOU;IACT;IAEA,OAAOhB;AACT,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-import-export",
3
- "version": "3.44.0-canary.6",
3
+ "version": "3.44.0-canary.8",
4
4
  "description": "Import-Export plugin for Payload",
5
5
  "keywords": [
6
6
  "payload",
@@ -64,17 +64,17 @@
64
64
  "csv-parse": "^5.6.0",
65
65
  "csv-stringify": "^6.5.2",
66
66
  "qs-esm": "7.0.2",
67
- "@payloadcms/translations": "3.44.0-canary.6",
68
- "@payloadcms/ui": "3.44.0-canary.6"
67
+ "@payloadcms/translations": "3.44.0-canary.8",
68
+ "@payloadcms/ui": "3.44.0-canary.8"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@payloadcms/eslint-config": "3.28.0",
72
- "payload": "3.44.0-canary.6",
73
- "@payloadcms/ui": "3.44.0-canary.6"
72
+ "payload": "3.44.0-canary.8",
73
+ "@payloadcms/ui": "3.44.0-canary.8"
74
74
  },
75
75
  "peerDependencies": {
76
- "@payloadcms/ui": "3.44.0-canary.6",
77
- "payload": "3.44.0-canary.6"
76
+ "@payloadcms/ui": "3.44.0-canary.8",
77
+ "payload": "3.44.0-canary.8"
78
78
  },
79
79
  "homepage:": "https://payloadcms.com",
80
80
  "scripts": {