@webiny/api-page-builder-import-export 0.0.0-unstable.990c3ab1b6 → 0.0.0-unstable.b02d94bba0
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/client.d.ts +2 -2
- package/client.js.map +1 -1
- package/export/combine/blocksHandler.d.ts +6 -0
- package/export/combine/blocksHandler.js +99 -0
- package/export/combine/blocksHandler.js.map +1 -0
- package/export/combine/formsHandler.d.ts +6 -0
- package/export/combine/formsHandler.js +99 -0
- package/export/combine/formsHandler.js.map +1 -0
- package/{exportPages → export}/combine/index.d.ts +3 -2
- package/export/combine/index.js +40 -0
- package/export/combine/index.js.map +1 -0
- package/export/combine/pagesHandler.d.ts +6 -0
- package/export/combine/pagesHandler.js +99 -0
- package/export/combine/pagesHandler.js.map +1 -0
- package/export/combine/templatesHandler.d.ts +6 -0
- package/export/combine/templatesHandler.js +99 -0
- package/export/combine/templatesHandler.js.map +1 -0
- package/export/process/blocksHandler.d.ts +6 -0
- package/export/process/blocksHandler.js +162 -0
- package/export/process/blocksHandler.js.map +1 -0
- package/export/process/formsHandler.d.ts +6 -0
- package/export/process/formsHandler.js +187 -0
- package/export/process/formsHandler.js.map +1 -0
- package/{exportPages → export}/process/index.d.ts +4 -6
- package/export/process/index.js +37 -0
- package/export/process/index.js.map +1 -0
- package/export/process/pagesHandler.d.ts +6 -0
- package/export/process/pagesHandler.js +189 -0
- package/export/process/pagesHandler.js.map +1 -0
- package/export/process/templatesHandler.d.ts +6 -0
- package/export/process/templatesHandler.js +166 -0
- package/export/process/templatesHandler.js.map +1 -0
- package/{exportPages → export}/s3Stream.d.ts +5 -2
- package/export/s3Stream.js.map +1 -0
- package/export/utils.d.ts +29 -0
- package/export/utils.js +188 -0
- package/export/utils.js.map +1 -0
- package/{exportPages → export}/zipper.d.ts +6 -5
- package/{exportPages → export}/zipper.js +9 -8
- package/export/zipper.js.map +1 -0
- package/graphql/crud/blocks.crud.d.ts +4 -0
- package/graphql/crud/blocks.crud.js +136 -0
- package/graphql/crud/blocks.crud.js.map +1 -0
- package/graphql/crud/forms.crud.d.ts +4 -0
- package/graphql/crud/forms.crud.js +129 -0
- package/graphql/crud/forms.crud.js.map +1 -0
- package/graphql/crud/importExportTasks.crud.d.ts +5 -0
- package/graphql/crud/{pageImportExportTasks.crud.js → importExportTasks.crud.js} +48 -48
- package/graphql/crud/importExportTasks.crud.js.map +1 -0
- package/graphql/crud/pages.crud.d.ts +2 -2
- package/graphql/crud/pages.crud.js +18 -14
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud/templates.crud.d.ts +4 -0
- package/graphql/crud/templates.crud.js +124 -0
- package/graphql/crud/templates.crud.js.map +1 -0
- package/graphql/crud.d.ts +2 -2
- package/graphql/crud.js +5 -2
- package/graphql/crud.js.map +1 -1
- package/graphql/graphql/blocks.gql.d.ts +4 -0
- package/graphql/graphql/blocks.gql.js +52 -0
- package/graphql/graphql/blocks.gql.js.map +1 -0
- package/graphql/graphql/forms.gql.d.ts +4 -0
- package/graphql/graphql/forms.gql.js +60 -0
- package/graphql/graphql/forms.gql.js.map +1 -0
- package/graphql/graphql/importExportTasks.gql.d.ts +4 -0
- package/graphql/graphql/{pageImportExportTasks.gql.js → importExportTasks.gql.js} +17 -17
- package/graphql/graphql/importExportTasks.gql.js.map +1 -0
- package/graphql/graphql/pages.gql.d.ts +2 -2
- package/graphql/graphql/pages.gql.js +3 -9
- package/graphql/graphql/pages.gql.js.map +1 -1
- package/graphql/graphql/templates.gql.d.ts +4 -0
- package/graphql/graphql/templates.gql.js +52 -0
- package/graphql/graphql/templates.gql.js.map +1 -0
- package/graphql/graphql.js +5 -2
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +83 -23
- package/graphql/types.js.map +1 -1
- package/import/constants.d.ts +3 -0
- package/import/constants.js +14 -0
- package/import/constants.js.map +1 -0
- package/import/create/blocksHandler.d.ts +3 -0
- package/import/create/blocksHandler.js +101 -0
- package/import/create/blocksHandler.js.map +1 -0
- package/import/create/formsHandler.d.ts +3 -0
- package/import/create/formsHandler.js +103 -0
- package/import/create/formsHandler.js.map +1 -0
- package/{importPages → import}/create/index.d.ts +7 -5
- package/import/create/index.js +40 -0
- package/import/create/index.js.map +1 -0
- package/import/create/pagesHandler.d.ts +3 -0
- package/import/create/pagesHandler.js +103 -0
- package/import/create/pagesHandler.js.map +1 -0
- package/import/create/templatesHandler.d.ts +3 -0
- package/import/create/templatesHandler.js +99 -0
- package/import/create/templatesHandler.js.map +1 -0
- package/import/process/blocks/blocksHandler.d.ts +3 -0
- package/import/process/blocks/blocksHandler.js +169 -0
- package/import/process/blocks/blocksHandler.js.map +1 -0
- package/import/process/blocks/importBlock.d.ts +11 -0
- package/import/process/blocks/importBlock.js +92 -0
- package/import/process/blocks/importBlock.js.map +1 -0
- package/import/process/blocksHandler.d.ts +3 -0
- package/import/process/blocksHandler.js +175 -0
- package/import/process/blocksHandler.js.map +1 -0
- package/import/process/forms/formsHandler.d.ts +3 -0
- package/import/process/forms/formsHandler.js +176 -0
- package/import/process/forms/formsHandler.js.map +1 -0
- package/import/process/forms/importForm.d.ts +9 -0
- package/import/process/forms/importForm.js +43 -0
- package/import/process/forms/importForm.js.map +1 -0
- package/{importPages → import}/process/index.d.ts +5 -3
- package/import/process/index.js +37 -0
- package/import/process/index.js.map +1 -0
- package/import/process/pages/importPage.d.ts +11 -0
- package/import/process/pages/importPage.js +92 -0
- package/import/process/pages/importPage.js.map +1 -0
- package/import/process/pages/pagesHandler.d.ts +3 -0
- package/import/process/pages/pagesHandler.js +183 -0
- package/import/process/pages/pagesHandler.js.map +1 -0
- package/import/process/pagesHandler.d.ts +3 -0
- package/import/process/pagesHandler.js +180 -0
- package/import/process/pagesHandler.js.map +1 -0
- package/import/process/templates/importTemplate.d.ts +11 -0
- package/import/process/templates/importTemplate.js +66 -0
- package/import/process/templates/importTemplate.js.map +1 -0
- package/import/process/templates/templatesHandler.d.ts +3 -0
- package/import/process/templates/templatesHandler.js +170 -0
- package/import/process/templates/templatesHandler.js.map +1 -0
- package/import/utils/deleteS3Folder.d.ts +1 -0
- package/import/utils/deleteS3Folder.js +19 -0
- package/import/utils/deleteS3Folder.js.map +1 -0
- package/import/utils/extractAndUploadZipFileContents.d.ts +7 -0
- package/import/utils/extractAndUploadZipFileContents.js +122 -0
- package/import/utils/extractAndUploadZipFileContents.js.map +1 -0
- package/import/utils/extractZipAndUploadToS3.d.ts +2 -0
- package/import/utils/extractZipAndUploadToS3.js +98 -0
- package/import/utils/extractZipAndUploadToS3.js.map +1 -0
- package/import/utils/getFileNameWithoutExt.d.ts +1 -0
- package/import/utils/getFileNameWithoutExt.js +11 -0
- package/import/utils/getFileNameWithoutExt.js.map +1 -0
- package/import/utils/index.d.ts +9 -0
- package/import/utils/index.js +104 -0
- package/import/utils/index.js.map +1 -0
- package/import/utils/initialStats.d.ts +7 -0
- package/import/utils/initialStats.js +16 -0
- package/import/utils/initialStats.js.map +1 -0
- package/import/utils/prepareDataDirMap.d.ts +6 -0
- package/import/utils/prepareDataDirMap.js +29 -0
- package/import/utils/prepareDataDirMap.js.map +1 -0
- package/import/utils/updateFilesInData.d.ts +8 -0
- package/import/utils/updateFilesInData.js +48 -0
- package/import/utils/updateFilesInData.js.map +1 -0
- package/import/utils/uploadAssets.d.ts +10 -0
- package/import/utils/uploadAssets.js +51 -0
- package/import/utils/uploadAssets.js.map +1 -0
- package/import/utils/uploadFilesFromS3.d.ts +3 -0
- package/import/utils/uploadFilesFromS3.js +19 -0
- package/import/utils/uploadFilesFromS3.js.map +1 -0
- package/{importPages → import}/utils.d.ts +19 -20
- package/{importPages → import}/utils.js +229 -76
- package/import/utils.js.map +1 -0
- package/package.json +25 -24
- package/types.d.ts +83 -65
- package/types.js +17 -17
- package/types.js.map +1 -1
- package/exportPages/combine/index.js +0 -106
- package/exportPages/combine/index.js.map +0 -1
- package/exportPages/process/index.js +0 -192
- package/exportPages/process/index.js.map +0 -1
- package/exportPages/s3Stream.js.map +0 -1
- package/exportPages/utils.d.ts +0 -13
- package/exportPages/utils.js +0 -100
- package/exportPages/utils.js.map +0 -1
- package/exportPages/zipper.js.map +0 -1
- package/graphql/crud/pageImportExportTasks.crud.d.ts +0 -5
- package/graphql/crud/pageImportExportTasks.crud.js.map +0 -1
- package/graphql/graphql/pageImportExportTasks.gql.d.ts +0 -4
- package/graphql/graphql/pageImportExportTasks.gql.js.map +0 -1
- package/importPages/create/index.js +0 -107
- package/importPages/create/index.js.map +0 -1
- package/importPages/process/index.js +0 -180
- package/importPages/process/index.js.map +0 -1
- package/importPages/utils.js.map +0 -1
- /package/{exportPages → export}/s3Stream.js +0 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.initialStats = initialStats;
|
7
|
+
var _types = require("../../types");
|
8
|
+
function initialStats(total) {
|
9
|
+
return {
|
10
|
+
[_types.ImportExportTaskStatus.PENDING]: total,
|
11
|
+
[_types.ImportExportTaskStatus.PROCESSING]: 0,
|
12
|
+
[_types.ImportExportTaskStatus.COMPLETED]: 0,
|
13
|
+
[_types.ImportExportTaskStatus.FAILED]: 0,
|
14
|
+
total
|
15
|
+
};
|
16
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["initialStats","total","ImportExportTaskStatus","PENDING","PROCESSING","COMPLETED","FAILED"],"sources":["initialStats.ts"],"sourcesContent":["import { ImportExportTaskStatus } from \"~/types\";\n\nexport function initialStats(total: number) {\n return {\n [ImportExportTaskStatus.PENDING]: total,\n [ImportExportTaskStatus.PROCESSING]: 0,\n [ImportExportTaskStatus.COMPLETED]: 0,\n [ImportExportTaskStatus.FAILED]: 0,\n total\n };\n}\n"],"mappings":";;;;;;AAAA;AAEO,SAASA,YAAY,CAACC,KAAa,EAAE;EACxC,OAAO;IACH,CAACC,6BAAsB,CAACC,OAAO,GAAGF,KAAK;IACvC,CAACC,6BAAsB,CAACE,UAAU,GAAG,CAAC;IACtC,CAACF,6BAAsB,CAACG,SAAS,GAAG,CAAC;IACrC,CAACH,6BAAsB,CAACI,MAAM,GAAG,CAAC;IAClCL;EACJ,CAAC;AACL"}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.prepareDataDirMap = prepareDataDirMap;
|
8
|
+
var _dotPropImmutable = _interopRequireDefault(require("dot-prop-immutable"));
|
9
|
+
var _constants = require("../constants");
|
10
|
+
function prepareDataDirMap({
|
11
|
+
map,
|
12
|
+
filePath,
|
13
|
+
newKey
|
14
|
+
}) {
|
15
|
+
const isAsset = filePath.includes(_constants.ASSETS_DIR_NAME);
|
16
|
+
if (isAsset) {
|
17
|
+
/*
|
18
|
+
* We want to use dot (.) as part of object key rather than creating nested object(s).
|
19
|
+
* Also, the file name might contain dots in it beside the extension, so, we are escaping them all.
|
20
|
+
*/
|
21
|
+
const assetKey = filePath.split(`${_constants.ASSETS_DIR_NAME}/`).pop();
|
22
|
+
const oldKey = assetKey.replace(/\./g, "\\.");
|
23
|
+
map = _dotPropImmutable.default.set(map, `assets.${oldKey}`, newKey);
|
24
|
+
} else {
|
25
|
+
// We only need to know the newKey for data file.
|
26
|
+
map = _dotPropImmutable.default.set(map, `data`, newKey);
|
27
|
+
}
|
28
|
+
return map;
|
29
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["prepareDataDirMap","map","filePath","newKey","isAsset","includes","ASSETS_DIR_NAME","assetKey","split","pop","oldKey","replace","dotProp","set"],"sources":["prepareDataDirMap.ts"],"sourcesContent":["import dotProp from \"dot-prop-immutable\";\nimport { ImportData } from \"~/types\";\nimport { ASSETS_DIR_NAME } from \"~/import/constants\";\n\nexport function prepareDataDirMap({\n map,\n filePath,\n newKey\n}: {\n map: ImportData;\n filePath: string;\n newKey: string;\n}): ImportData {\n const isAsset = filePath.includes(ASSETS_DIR_NAME);\n\n if (isAsset) {\n /*\n * We want to use dot (.) as part of object key rather than creating nested object(s).\n * Also, the file name might contain dots in it beside the extension, so, we are escaping them all.\n */\n const assetKey = filePath.split(`${ASSETS_DIR_NAME}/`).pop() as string;\n const oldKey = assetKey.replace(/\\./g, \"\\\\.\");\n\n map = dotProp.set(map, `assets.${oldKey}`, newKey);\n } else {\n // We only need to know the newKey for data file.\n map = dotProp.set(map, `data`, newKey);\n }\n\n return map;\n}\n"],"mappings":";;;;;;;AAAA;AAEA;AAEO,SAASA,iBAAiB,CAAC;EAC9BC,GAAG;EACHC,QAAQ;EACRC;AAKJ,CAAC,EAAc;EACX,MAAMC,OAAO,GAAGF,QAAQ,CAACG,QAAQ,CAACC,0BAAe,CAAC;EAElD,IAAIF,OAAO,EAAE;IACT;AACR;AACA;AACA;IACQ,MAAMG,QAAQ,GAAGL,QAAQ,CAACM,KAAK,CAAE,GAAEF,0BAAgB,GAAE,CAAC,CAACG,GAAG,EAAY;IACtE,MAAMC,MAAM,GAAGH,QAAQ,CAACI,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;IAE7CV,GAAG,GAAGW,yBAAO,CAACC,GAAG,CAACZ,GAAG,EAAG,UAASS,MAAO,EAAC,EAAEP,MAAM,CAAC;EACtD,CAAC,MAAM;IACH;IACAF,GAAG,GAAGW,yBAAO,CAACC,GAAG,CAACZ,GAAG,EAAG,MAAK,EAAEE,MAAM,CAAC;EAC1C;EAEA,OAAOF,GAAG;AACd"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { FileInput } from "@webiny/api-file-manager/types";
|
2
|
+
interface UpdateFilesInDataParams {
|
3
|
+
data: Record<string, any>;
|
4
|
+
fileIdToNewFileMap: Map<string, FileInput>;
|
5
|
+
srcPrefix: string;
|
6
|
+
}
|
7
|
+
export declare function updateFilesInData({ data, fileIdToNewFileMap, srcPrefix }: UpdateFilesInDataParams): void;
|
8
|
+
export {};
|
@@ -0,0 +1,48 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.updateFilesInData = updateFilesInData;
|
7
|
+
function updateFilesInData({
|
8
|
+
data,
|
9
|
+
fileIdToNewFileMap,
|
10
|
+
srcPrefix
|
11
|
+
}) {
|
12
|
+
if (!data || typeof data !== "object") {
|
13
|
+
return;
|
14
|
+
}
|
15
|
+
// Recursively call function if data is array
|
16
|
+
if (Array.isArray(data)) {
|
17
|
+
for (let i = 0; i < data.length; i++) {
|
18
|
+
const element = data[i];
|
19
|
+
updateFilesInData({
|
20
|
+
data: element,
|
21
|
+
fileIdToNewFileMap,
|
22
|
+
srcPrefix
|
23
|
+
});
|
24
|
+
}
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
// Main logic
|
28
|
+
const tuple = Object.entries(data);
|
29
|
+
for (let i = 0; i < tuple.length; i++) {
|
30
|
+
const [key, value] = tuple[i];
|
31
|
+
if (key === "file" && value && fileIdToNewFileMap.has(value.id)) {
|
32
|
+
const newFile = fileIdToNewFileMap.get(value.id);
|
33
|
+
if (!newFile) {
|
34
|
+
continue;
|
35
|
+
}
|
36
|
+
const cleanSrcPrefix = srcPrefix.endsWith("/") ? srcPrefix.slice(0, -1) : srcPrefix;
|
37
|
+
value.key = newFile.key;
|
38
|
+
value.name = newFile.name;
|
39
|
+
value.src = `${cleanSrcPrefix}/${newFile.key}`;
|
40
|
+
} else {
|
41
|
+
updateFilesInData({
|
42
|
+
data: value,
|
43
|
+
srcPrefix,
|
44
|
+
fileIdToNewFileMap
|
45
|
+
});
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["updateFilesInData","data","fileIdToNewFileMap","srcPrefix","Array","isArray","i","length","element","tuple","Object","entries","key","value","has","id","newFile","get","cleanSrcPrefix","endsWith","slice","name","src"],"sources":["updateFilesInData.ts"],"sourcesContent":["import { FileInput } from \"@webiny/api-file-manager/types\";\n\ninterface UpdateFilesInDataParams {\n data: Record<string, any>;\n fileIdToNewFileMap: Map<string, FileInput>;\n srcPrefix: string;\n}\n\nexport function updateFilesInData({\n data,\n fileIdToNewFileMap,\n srcPrefix\n}: UpdateFilesInDataParams) {\n if (!data || typeof data !== \"object\") {\n return;\n }\n // Recursively call function if data is array\n if (Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const element = data[i];\n updateFilesInData({ data: element, fileIdToNewFileMap, srcPrefix });\n }\n return;\n }\n // Main logic\n const tuple = Object.entries(data);\n for (let i = 0; i < tuple.length; i++) {\n const [key, value] = tuple[i];\n\n if (key === \"file\" && value && fileIdToNewFileMap.has(value.id)) {\n const newFile = fileIdToNewFileMap.get(value.id);\n if (!newFile) {\n continue;\n }\n\n const cleanSrcPrefix = srcPrefix.endsWith(\"/\") ? srcPrefix.slice(0, -1) : srcPrefix;\n\n value.key = newFile.key;\n value.name = newFile.name;\n value.src = `${cleanSrcPrefix}/${newFile.key}`;\n } else {\n updateFilesInData({ data: value, srcPrefix, fileIdToNewFileMap });\n }\n }\n}\n"],"mappings":";;;;;;AAQO,SAASA,iBAAiB,CAAC;EAC9BC,IAAI;EACJC,kBAAkB;EAClBC;AACqB,CAAC,EAAE;EACxB,IAAI,CAACF,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IACnC;EACJ;EACA;EACA,IAAIG,KAAK,CAACC,OAAO,CAACJ,IAAI,CAAC,EAAE;IACrB,KAAK,IAAIK,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGL,IAAI,CAACM,MAAM,EAAED,CAAC,EAAE,EAAE;MAClC,MAAME,OAAO,GAAGP,IAAI,CAACK,CAAC,CAAC;MACvBN,iBAAiB,CAAC;QAAEC,IAAI,EAAEO,OAAO;QAAEN,kBAAkB;QAAEC;MAAU,CAAC,CAAC;IACvE;IACA;EACJ;EACA;EACA,MAAMM,KAAK,GAAGC,MAAM,CAACC,OAAO,CAACV,IAAI,CAAC;EAClC,KAAK,IAAIK,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGG,KAAK,CAACF,MAAM,EAAED,CAAC,EAAE,EAAE;IACnC,MAAM,CAACM,GAAG,EAAEC,KAAK,CAAC,GAAGJ,KAAK,CAACH,CAAC,CAAC;IAE7B,IAAIM,GAAG,KAAK,MAAM,IAAIC,KAAK,IAAIX,kBAAkB,CAACY,GAAG,CAACD,KAAK,CAACE,EAAE,CAAC,EAAE;MAC7D,MAAMC,OAAO,GAAGd,kBAAkB,CAACe,GAAG,CAACJ,KAAK,CAACE,EAAE,CAAC;MAChD,IAAI,CAACC,OAAO,EAAE;QACV;MACJ;MAEA,MAAME,cAAc,GAAGf,SAAS,CAACgB,QAAQ,CAAC,GAAG,CAAC,GAAGhB,SAAS,CAACiB,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAGjB,SAAS;MAEnFU,KAAK,CAACD,GAAG,GAAGI,OAAO,CAACJ,GAAG;MACvBC,KAAK,CAACQ,IAAI,GAAGL,OAAO,CAACK,IAAI;MACzBR,KAAK,CAACS,GAAG,GAAI,GAAEJ,cAAe,IAAGF,OAAO,CAACJ,GAAI,EAAC;IAClD,CAAC,MAAM;MACHZ,iBAAiB,CAAC;QAAEC,IAAI,EAAEY,KAAK;QAAEV,SAAS;QAAED;MAAmB,CAAC,CAAC;IACrE;EACJ;AACJ"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { PbImportExportContext } from "../../graphql/types";
|
2
|
+
import { File, FileInput } from "@webiny/api-file-manager/types";
|
3
|
+
import { FileUploadsData } from "../../types";
|
4
|
+
interface UploadAssetsParams {
|
5
|
+
context: PbImportExportContext;
|
6
|
+
files: File[];
|
7
|
+
fileUploadsData: FileUploadsData;
|
8
|
+
}
|
9
|
+
export declare const uploadAssets: (params: UploadAssetsParams) => Promise<Map<string, FileInput>>;
|
10
|
+
export {};
|
@@ -0,0 +1,51 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.uploadAssets = void 0;
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
9
|
+
var _mdbid = _interopRequireDefault(require("mdbid"));
|
10
|
+
var _uploadFilesFromS = require("./uploadFilesFromS3");
|
11
|
+
// @ts-ignore
|
12
|
+
|
13
|
+
const uploadAssets = async params => {
|
14
|
+
const {
|
15
|
+
context,
|
16
|
+
files,
|
17
|
+
fileUploadsData
|
18
|
+
} = params;
|
19
|
+
const oldIdToNewFileMap = new Map();
|
20
|
+
|
21
|
+
/**
|
22
|
+
* This function contains logic of file download from S3.
|
23
|
+
* Current we're not mocking zip file download from S3 in tests at the moment.
|
24
|
+
* So, we're manually mocking it in case of test just by returning an empty object.
|
25
|
+
*/
|
26
|
+
if (process.env.NODE_ENV === "test") {
|
27
|
+
return oldIdToNewFileMap;
|
28
|
+
}
|
29
|
+
|
30
|
+
// A map of temporary file keys (created during ZIP upload) to permanent file keys.
|
31
|
+
const uploadFileMap = new Map();
|
32
|
+
|
33
|
+
// Array of file inputs, to insert into the DB.
|
34
|
+
const createFilesInput = [];
|
35
|
+
for (const oldFile of files) {
|
36
|
+
const id = (0, _mdbid.default)();
|
37
|
+
// We replace the old file ID with a new one.
|
38
|
+
const newKey = `${id}/${oldFile.key.replace(`${oldFile.id}/`, "")}`;
|
39
|
+
const newFile = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, oldFile), {}, {
|
40
|
+
id,
|
41
|
+
key: newKey
|
42
|
+
});
|
43
|
+
createFilesInput.push(newFile);
|
44
|
+
oldIdToNewFileMap.set(oldFile.id, newFile);
|
45
|
+
uploadFileMap.set(fileUploadsData.assets[oldFile.key], newFile);
|
46
|
+
}
|
47
|
+
await (0, _uploadFilesFromS.uploadFilesFromS3)(uploadFileMap);
|
48
|
+
await context.fileManager.createFilesInBatch(createFilesInput);
|
49
|
+
return oldIdToNewFileMap;
|
50
|
+
};
|
51
|
+
exports.uploadAssets = uploadAssets;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["uploadAssets","params","context","files","fileUploadsData","oldIdToNewFileMap","Map","process","env","NODE_ENV","uploadFileMap","createFilesInput","oldFile","id","mdbid","newKey","key","replace","newFile","push","set","assets","uploadFilesFromS3","fileManager","createFilesInBatch"],"sources":["uploadAssets.ts"],"sourcesContent":["// @ts-ignore\nimport mdbid from \"mdbid\";\nimport { PbImportExportContext } from \"~/graphql/types\";\nimport { File, FileInput } from \"@webiny/api-file-manager/types\";\nimport { UploadFileMap, uploadFilesFromS3 } from \"~/import/utils/uploadFilesFromS3\";\nimport { FileUploadsData } from \"~/types\";\n\ninterface UploadAssetsParams {\n context: PbImportExportContext;\n files: File[];\n fileUploadsData: FileUploadsData;\n}\n\nexport const uploadAssets = async (params: UploadAssetsParams) => {\n const { context, files, fileUploadsData } = params;\n\n const oldIdToNewFileMap = new Map<string, FileInput>();\n\n /**\n * This function contains logic of file download from S3.\n * Current we're not mocking zip file download from S3 in tests at the moment.\n * So, we're manually mocking it in case of test just by returning an empty object.\n */\n if (process.env.NODE_ENV === \"test\") {\n return oldIdToNewFileMap;\n }\n\n // A map of temporary file keys (created during ZIP upload) to permanent file keys.\n const uploadFileMap: UploadFileMap = new Map();\n\n // Array of file inputs, to insert into the DB.\n const createFilesInput: FileInput[] = [];\n\n for (const oldFile of files) {\n const id = mdbid();\n // We replace the old file ID with a new one.\n const newKey = `${id}/${oldFile.key.replace(`${oldFile.id}/`, \"\")}`;\n const newFile: FileInput = { ...oldFile, id, key: newKey };\n\n createFilesInput.push(newFile);\n oldIdToNewFileMap.set(oldFile.id, newFile);\n uploadFileMap.set(fileUploadsData.assets[oldFile.key], newFile);\n }\n\n await uploadFilesFromS3(uploadFileMap);\n\n await context.fileManager.createFilesInBatch(createFilesInput);\n\n return oldIdToNewFileMap;\n};\n"],"mappings":";;;;;;;;AACA;AAGA;AAJA;;AAaO,MAAMA,YAAY,GAAG,MAAOC,MAA0B,IAAK;EAC9D,MAAM;IAAEC,OAAO;IAAEC,KAAK;IAAEC;EAAgB,CAAC,GAAGH,MAAM;EAElD,MAAMI,iBAAiB,GAAG,IAAIC,GAAG,EAAqB;;EAEtD;AACJ;AACA;AACA;AACA;EACI,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,MAAM,EAAE;IACjC,OAAOJ,iBAAiB;EAC5B;;EAEA;EACA,MAAMK,aAA4B,GAAG,IAAIJ,GAAG,EAAE;;EAE9C;EACA,MAAMK,gBAA6B,GAAG,EAAE;EAExC,KAAK,MAAMC,OAAO,IAAIT,KAAK,EAAE;IACzB,MAAMU,EAAE,GAAG,IAAAC,cAAK,GAAE;IAClB;IACA,MAAMC,MAAM,GAAI,GAAEF,EAAG,IAAGD,OAAO,CAACI,GAAG,CAACC,OAAO,CAAE,GAAEL,OAAO,CAACC,EAAG,GAAE,EAAE,EAAE,CAAE,EAAC;IACnE,MAAMK,OAAkB,+DAAQN,OAAO;MAAEC,EAAE;MAAEG,GAAG,EAAED;IAAM,EAAE;IAE1DJ,gBAAgB,CAACQ,IAAI,CAACD,OAAO,CAAC;IAC9Bb,iBAAiB,CAACe,GAAG,CAACR,OAAO,CAACC,EAAE,EAAEK,OAAO,CAAC;IAC1CR,aAAa,CAACU,GAAG,CAAChB,eAAe,CAACiB,MAAM,CAACT,OAAO,CAACI,GAAG,CAAC,EAAEE,OAAO,CAAC;EACnE;EAEA,MAAM,IAAAI,mCAAiB,EAACZ,aAAa,CAAC;EAEtC,MAAMR,OAAO,CAACqB,WAAW,CAACC,kBAAkB,CAACb,gBAAgB,CAAC;EAE9D,OAAON,iBAAiB;AAC5B,CAAC;AAAC"}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.uploadFilesFromS3 = uploadFilesFromS3;
|
7
|
+
var _s3Stream = require("../../export/s3Stream");
|
8
|
+
async function uploadFilesFromS3(fileMap) {
|
9
|
+
const promises = [];
|
10
|
+
for (const [source, target] of Array.from(fileMap.entries())) {
|
11
|
+
// Read file.
|
12
|
+
const readStream = _s3Stream.s3Stream.readStream(source);
|
13
|
+
const ws = _s3Stream.s3Stream.writeStream(target.key, target.type);
|
14
|
+
readStream.pipe(ws.streamPassThrough);
|
15
|
+
promises.push(ws.streamPassThroughUploadPromise);
|
16
|
+
console.log(`Successfully queued file "${target.key}"`);
|
17
|
+
}
|
18
|
+
return Promise.all(promises);
|
19
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["uploadFilesFromS3","fileMap","promises","source","target","Array","from","entries","readStream","s3Stream","ws","writeStream","key","type","pipe","streamPassThrough","push","streamPassThroughUploadPromise","console","log","Promise","all"],"sources":["uploadFilesFromS3.ts"],"sourcesContent":["import { s3Stream } from \"~/export/s3Stream\";\nimport { FileInput } from \"@webiny/api-file-manager/types\";\n\nexport type UploadFileMap = Map<string, FileInput>;\n\nexport async function uploadFilesFromS3(fileMap: UploadFileMap) {\n const promises = [];\n for (const [source, target] of Array.from(fileMap.entries())) {\n // Read file.\n const readStream = s3Stream.readStream(source);\n\n const ws = s3Stream.writeStream(target.key, target.type);\n readStream.pipe(ws.streamPassThrough);\n promises.push(ws.streamPassThroughUploadPromise);\n\n console.log(`Successfully queued file \"${target.key}\"`);\n }\n\n return Promise.all(promises);\n}\n"],"mappings":";;;;;;AAAA;AAKO,eAAeA,iBAAiB,CAACC,OAAsB,EAAE;EAC5D,MAAMC,QAAQ,GAAG,EAAE;EACnB,KAAK,MAAM,CAACC,MAAM,EAAEC,MAAM,CAAC,IAAIC,KAAK,CAACC,IAAI,CAACL,OAAO,CAACM,OAAO,EAAE,CAAC,EAAE;IAC1D;IACA,MAAMC,UAAU,GAAGC,kBAAQ,CAACD,UAAU,CAACL,MAAM,CAAC;IAE9C,MAAMO,EAAE,GAAGD,kBAAQ,CAACE,WAAW,CAACP,MAAM,CAACQ,GAAG,EAAER,MAAM,CAACS,IAAI,CAAC;IACxDL,UAAU,CAACM,IAAI,CAACJ,EAAE,CAACK,iBAAiB,CAAC;IACrCb,QAAQ,CAACc,IAAI,CAACN,EAAE,CAACO,8BAA8B,CAAC;IAEhDC,OAAO,CAACC,GAAG,CAAE,6BAA4Bf,MAAM,CAACQ,GAAI,GAAE,CAAC;EAC3D;EAEA,OAAOQ,OAAO,CAACC,GAAG,CAACnB,QAAQ,CAAC;AAChC"}
|
@@ -1,23 +1,15 @@
|
|
1
|
-
import { File } from "
|
2
|
-
import {
|
3
|
-
import { ExportedPageData } from "../
|
4
|
-
interface
|
5
|
-
|
6
|
-
|
7
|
-
name: string;
|
8
|
-
size: number;
|
9
|
-
meta: Record<string, any>;
|
10
|
-
tags: string[];
|
11
|
-
}
|
12
|
-
interface UploadPageAssetsParams {
|
13
|
-
context: PbPageImportExportContext;
|
14
|
-
filesData: FileItem[];
|
1
|
+
import { File } from "@webiny/api-file-manager/types";
|
2
|
+
import { PbImportExportContext } from "../graphql/types";
|
3
|
+
import { ExportedPageData, ExportedBlockData } from "../export/utils";
|
4
|
+
interface UploadAssetsParams {
|
5
|
+
context: PbImportExportContext;
|
6
|
+
filesData: File[];
|
15
7
|
fileUploadsData: FileUploadsData;
|
16
8
|
}
|
17
|
-
interface
|
9
|
+
interface UploadAssetsReturnType {
|
18
10
|
fileIdToKeyMap: Map<string, string>;
|
19
11
|
}
|
20
|
-
export declare const
|
12
|
+
export declare const uploadAssets: (params: UploadAssetsParams) => Promise<UploadAssetsReturnType>;
|
21
13
|
interface FileUploadsData {
|
22
14
|
data: string;
|
23
15
|
assets: Record<string, string>;
|
@@ -25,11 +17,18 @@ interface FileUploadsData {
|
|
25
17
|
interface ImportPageParams {
|
26
18
|
key: string;
|
27
19
|
pageKey: string;
|
28
|
-
context:
|
20
|
+
context: PbImportExportContext;
|
29
21
|
fileUploadsData: FileUploadsData;
|
30
22
|
}
|
31
23
|
export declare function importPage({ pageKey, context, fileUploadsData }: ImportPageParams): Promise<ExportedPageData["page"]>;
|
32
|
-
interface
|
24
|
+
interface ImportBlockParams {
|
25
|
+
key: string;
|
26
|
+
blockKey: string;
|
27
|
+
context: PbImportExportContext;
|
28
|
+
fileUploadsData: FileUploadsData;
|
29
|
+
}
|
30
|
+
export declare function importBlock({ blockKey, context, fileUploadsData }: ImportBlockParams): Promise<ExportedBlockData["block"]>;
|
31
|
+
interface ImportData {
|
33
32
|
assets: Record<string, string>;
|
34
33
|
data: string;
|
35
34
|
key: string;
|
@@ -37,9 +36,9 @@ interface PageImportData {
|
|
37
36
|
/**
|
38
37
|
* Function will read the given zip file from S3 via stream, extract its content and upload it to S3 bucket.
|
39
38
|
* @param zipFileUrl
|
40
|
-
* @return
|
39
|
+
* @return ImportData S3 file keys for all uploaded assets group by page/block.
|
41
40
|
*/
|
42
|
-
export declare function readExtractAndUploadZipFileContents(zipFileUrl: string): Promise<
|
41
|
+
export declare function readExtractAndUploadZipFileContents(zipFileUrl: string): Promise<ImportData[]>;
|
43
42
|
export declare function initialStats(total: number): {
|
44
43
|
pending: number;
|
45
44
|
processing: number;
|