From 439ebfef45e45891c0d65a0a44c81c44752efd5f Mon Sep 17 00:00:00 2001 From: Muhsin Shah Date: Mon, 8 Apr 2024 13:00:37 +0530 Subject: [PATCH] added auto-removed file after merging --- server/src/helpers/import_export.helpers.ts | 53 +++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 server/src/helpers/import_export.helpers.ts diff --git a/server/src/helpers/import_export.helpers.ts b/server/src/helpers/import_export.helpers.ts new file mode 100644 index 0000000000..db9b02ddec --- /dev/null +++ b/server/src/helpers/import_export.helpers.ts @@ -0,0 +1,53 @@ +export function updateEntityReferences(node, resourceMapping: Record = {}) { + if (typeof node === 'object') { + for (const key in node) { + let value = node[key]; + if (typeof value === 'string' && value.includes('{{') && value.includes('}}')) { + const referenceExists = value; + + if (referenceExists) { + const ref = value.replace('{{', '').replace('}}', ''); + + const entityName = ref.split('.')[1]; + + if (resourceMapping[entityName]) { + const newValue = value.replace(entityName, resourceMapping[entityName]); + + node[key] = newValue; + } + } + } else if (typeof value === 'object') { + value = updateEntityReferences(value, resourceMapping); + } + } + } + + return node; +} + +export function findAllEntityReferences(node, allRefs): [] { + if (typeof node === 'object') { + for (const key in node) { + const value = node[key]; + if (typeof value === 'string' && value.includes('{{') && value.includes('}}')) { + const referenceExists = value; + + if (referenceExists) { + const ref = value.replace('{{', '').replace('}}', ''); + + const entityName = ref.split('.')[1]; + + allRefs.push(entityName); + } + } else if (typeof value === 'object') { + findAllEntityReferences(value, allRefs); + } + } + } + return allRefs; +} + +export function isValidUUID(uuid) { + const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; + return uuidRegex.test(uuid); +}