mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
added auto-removed file after merging
This commit is contained in:
parent
121fe41107
commit
439ebfef45
1 changed files with 53 additions and 0 deletions
53
server/src/helpers/import_export.helpers.ts
Normal file
53
server/src/helpers/import_export.helpers.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
export function updateEntityReferences(node, resourceMapping: Record<string, string> = {}) {
|
||||
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);
|
||||
}
|
||||
Loading…
Reference in a new issue