UNPKG

@xuda.io/runtime-bundle

Version:

The Xuda Runtime Bundle refers to a collection of scripts and libraries packaged together to provide the necessary runtime environment for executing plugins or components in the Xuda platform.

116 lines (95 loc) 3.26 kB
export const new_node_id = (type, app_id) => { const abbreviate = (word) => { if (word.length <= 3) { return word; } // Remove vowels except the first letter let abbreviation = word[0]; const vowels = 'aeiou'; for (let i = 1; i < word.length && abbreviation.length < 3; i++) { if (!vowels.includes(word[i].toLowerCase())) { abbreviation += word[i]; } } // If the abbreviation is still less than 3 letters, pad it with the remaining letters if (abbreviation.length < 3) { abbreviation = word.substring(0, 3); } return abbreviation; }; var last12uuid = crypto.randomUUID().split('-')[4]; if (type) { var menuAbbreviated = abbreviate(type.replaceAll('_', '')); return `${app_id.substr(app_id.length - 3)}_${menuAbbreviated}_${last12uuid}`; } return app_id.substr(app_id.length - 3) + '_' + last12uuid; }; export const createDoc = function ({ _id, id, uid, checkedInUserName, app_id, parentId, properties, studio_meta = {}, minimal = false } = {}) { // Accept both `_id` and legacy `id` from callers (TreeComp paste, AddComponent, migration helpers). if (!_id && id) _id = id; // `properties` is optional for `minimal: true` clones — guard against undefined. const props = properties || {}; if (!_id) { _id = new_node_id(props.menuType, app_id); } const t = Date.now(); var doc = { _id, stat: 3, app_id, docType: 'studio', docDate: t, ts: t, order_ts: t, studio_meta: { ...{ created: t, createdByUid: uid, checkedInUserId: uid, savedByUid: uid, checkedInUserName, parentId: parentId || (props.menuType === 'globals' ? 'globals' : props.menuType === 'table' ? 'database' : props.menuType === 'route' ? 'routes' : 'programs'), }, ...studio_meta, }, properties: props, }; if (minimal) return doc; if (props.menuType) { switch (props.menuType) { case 'table': if (!doc.tableIndexes) doc.tableIndexes = []; if (!doc.tableFields) doc.tableFields = []; break; case 'alert': if (!doc.alertData) doc.alertData = {}; break; case 'javascript': if (!doc.scriptData) doc.scriptData = {}; break; case 'ai_agent': if (!doc.agentConfig) doc.agentConfig = {}; break; case 'folder': break; case 'route': if (!doc.routeMenu) doc.routeMenu = {}; break; case 'api': if (!doc.scriptData) doc.scriptData = {}; case 'component': if (!doc.progUi) doc.progUi = [{ id: 'root', type: 'element', tagName: doc?.properties?.renderType !== 'form' ? 'xu-multi-view' : 'xu-single-view', attributes: {}, children: [] }]; default: //get_data, set_data, batch if (!doc.progDataSource) doc.progDataSource = { dataSourceType: '', }; if (!doc.progFields) doc.progFields = []; if (!doc.progEvents) doc.progEvents = []; break; } } return doc; }; export const valid_menuType = ['globals', 'table', 'get_data', 'set_data', 'batch', 'alert', 'javascript', 'folder', 'route', 'api', 'component', 'ai_agent'];