@payloadcms/plugin-import-export 3.43.0-canary.0 → 3.43.0-canary.1
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.
|
@@ -50,7 +50,7 @@ export const flattenObject = ({ doc, fields, prefix, toCSVFunctions })=>{
|
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
52
|
flatten(doc, prefix);
|
|
53
|
-
if (fields) {
|
|
53
|
+
if (Array.isArray(fields) && fields.length > 0) {
|
|
54
54
|
const orderedResult = {};
|
|
55
55
|
const fieldToRegex = (field)=>{
|
|
56
56
|
const parts = field.split('.').map((part)=>`${part}(?:_\\d+)?`);
|
|
@@ -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 (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,OAAO,CAAC,GAAGD;wBAC9B;oBACF;gBACF;YACF,OAAO,IAAI,OAAOJ,UAAU,YAAYA,UAAU,MAAM;gBACtD,IAAI,CAACR,gBAAgB,CAACS,OAAO,EAAE;oBAC7BP,QAAQM,OAAOC;gBACjB,OAAO;oBACLR,GAAG,CAACQ,OAAO,GAAGT,cAAc,CAACS,OAAO,CAAC;wBACnCK,YAAYL;wBACZZ;wBACAI;wBACAE;wBACAK;oBACF;gBACF;YACF,OAAO;gBACL,IAAIR,gBAAgB,CAACS,OAAO,EAAE;oBAC5BR,GAAG,CAACQ,OAAO,GAAGT,cAAc,CAACS,OAAO,CAAC;wBACnCK,YAAYL;wBACZZ;wBACAI;wBACAE;wBACAK;oBACF;gBACF,OAAO;oBACLP,GAAG,CAACQ,OAAO,GAAGD;gBAChB;YACF;QACF;IACF;IAEAN,QAAQL,KAAKE;IAEb,
|
|
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,CAACC,KAAKC,MAAM;YAC9C,MAAMC,SAASV,SAAS,GAAGA,OAAO,CAAC,EA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AC;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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-import-export",
|
|
3
|
-
"version": "3.43.0-canary.
|
|
3
|
+
"version": "3.43.0-canary.1",
|
|
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.43.0-canary.
|
|
68
|
-
"@payloadcms/ui": "3.43.0-canary.
|
|
67
|
+
"@payloadcms/translations": "3.43.0-canary.1",
|
|
68
|
+
"@payloadcms/ui": "3.43.0-canary.1"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@payloadcms/eslint-config": "3.28.0",
|
|
72
|
-
"
|
|
73
|
-
"
|
|
72
|
+
"@payloadcms/ui": "3.43.0-canary.1",
|
|
73
|
+
"payload": "3.43.0-canary.1"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"@payloadcms/ui": "3.43.0-canary.
|
|
77
|
-
"payload": "3.43.0-canary.
|
|
76
|
+
"@payloadcms/ui": "3.43.0-canary.1",
|
|
77
|
+
"payload": "3.43.0-canary.1"
|
|
78
78
|
},
|
|
79
79
|
"homepage:": "https://payloadcms.com",
|
|
80
80
|
"scripts": {
|