@xuda.io/runtime-bundle 1.0.1423 → 1.0.1424
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/js/xuda-runtime-bundle.js +20 -1
- package/js/xuda-runtime-bundle.min.js +1 -1
- package/js/xuda-runtime-slim.js +20 -1
- package/js/xuda-runtime-slim.min.es.js +20 -1
- package/js/xuda-runtime-slim.min.js +1 -1
- package/js/xuda-server-bundle.min.mjs +1 -1
- package/js/xuda-server-bundle.mjs +20 -1
- package/js/xuda-worker-bundle.js +20 -1
- package/js/xuda-worker-bundle.min.js +1 -1
- package/package.json +1 -1
package/js/xuda-runtime-slim.js
CHANGED
|
@@ -20158,6 +20158,25 @@ func.expression.get = async function (SESSION_ID, valP, dsSessionP, sourceP, row
|
|
|
20158
20158
|
|
|
20159
20159
|
// var split = [];
|
|
20160
20160
|
var var_Arr = [];
|
|
20161
|
+
const get_iterate_value_ret = function (fieldIdP) {
|
|
20162
|
+
if (!iterate_info || (iterate_info.iterator_key !== fieldIdP && iterate_info.iterator_val !== fieldIdP)) {
|
|
20163
|
+
return null;
|
|
20164
|
+
}
|
|
20165
|
+
|
|
20166
|
+
const iter_value = iterate_info.iterator_key === fieldIdP ? iterate_info._key : iterate_info._val;
|
|
20167
|
+
const iter_type = typeof iter_value !== 'undefined' ? {}.toString.call(iter_value).match(/\s([a-zA-Z]+)/)[1].toLowerCase() : 'string';
|
|
20168
|
+
|
|
20169
|
+
return {
|
|
20170
|
+
ret: {
|
|
20171
|
+
value: iter_value,
|
|
20172
|
+
type: iter_type,
|
|
20173
|
+
prop: ['array', 'object'].includes(iter_type) ? iter_value : null,
|
|
20174
|
+
},
|
|
20175
|
+
fieldIdP,
|
|
20176
|
+
currentRecordId: rowIdP,
|
|
20177
|
+
found: typeof iter_value !== 'undefined',
|
|
20178
|
+
};
|
|
20179
|
+
};
|
|
20161
20180
|
const split = func.expression.parse(ret) || [];
|
|
20162
20181
|
// console.log(valP, split);
|
|
20163
20182
|
const split_entries = Object.entries(split);
|
|
@@ -20254,7 +20273,7 @@ func.expression.get = async function (SESSION_ID, valP, dsSessionP, sourceP, row
|
|
|
20254
20273
|
} // put default
|
|
20255
20274
|
fields[val.fieldId] = var_Arr[key].value;
|
|
20256
20275
|
|
|
20257
|
-
const ret = await func.datasource.get_value(SESSION_ID, val.fieldId, dsSessionP, rowIdP); // find field in dataSources
|
|
20276
|
+
const ret = get_iterate_value_ret(val.fieldId) || (await func.datasource.get_value(SESSION_ID, val.fieldId, dsSessionP, rowIdP)); // find field in dataSources
|
|
20258
20277
|
|
|
20259
20278
|
await replace_value_in_string(ret.ret, ret.fieldIdP);
|
|
20260
20279
|
}
|
|
@@ -20849,6 +20849,25 @@ func.expression.get = async function (SESSION_ID, valP, dsSessionP, sourceP, row
|
|
|
20849
20849
|
|
|
20850
20850
|
// var split = [];
|
|
20851
20851
|
var var_Arr = [];
|
|
20852
|
+
const get_iterate_value_ret = function (fieldIdP) {
|
|
20853
|
+
if (!iterate_info || (iterate_info.iterator_key !== fieldIdP && iterate_info.iterator_val !== fieldIdP)) {
|
|
20854
|
+
return null;
|
|
20855
|
+
}
|
|
20856
|
+
|
|
20857
|
+
const iter_value = iterate_info.iterator_key === fieldIdP ? iterate_info._key : iterate_info._val;
|
|
20858
|
+
const iter_type = typeof iter_value !== 'undefined' ? {}.toString.call(iter_value).match(/\s([a-zA-Z]+)/)[1].toLowerCase() : 'string';
|
|
20859
|
+
|
|
20860
|
+
return {
|
|
20861
|
+
ret: {
|
|
20862
|
+
value: iter_value,
|
|
20863
|
+
type: iter_type,
|
|
20864
|
+
prop: ['array', 'object'].includes(iter_type) ? iter_value : null,
|
|
20865
|
+
},
|
|
20866
|
+
fieldIdP,
|
|
20867
|
+
currentRecordId: rowIdP,
|
|
20868
|
+
found: typeof iter_value !== 'undefined',
|
|
20869
|
+
};
|
|
20870
|
+
};
|
|
20852
20871
|
const split = func.expression.parse(ret) || [];
|
|
20853
20872
|
// console.log(valP, split);
|
|
20854
20873
|
const split_entries = Object.entries(split);
|
|
@@ -20945,7 +20964,7 @@ func.expression.get = async function (SESSION_ID, valP, dsSessionP, sourceP, row
|
|
|
20945
20964
|
} // put default
|
|
20946
20965
|
fields[val.fieldId] = var_Arr[key].value;
|
|
20947
20966
|
|
|
20948
|
-
const ret = await func.datasource.get_value(SESSION_ID, val.fieldId, dsSessionP, rowIdP); // find field in dataSources
|
|
20967
|
+
const ret = get_iterate_value_ret(val.fieldId) || (await func.datasource.get_value(SESSION_ID, val.fieldId, dsSessionP, rowIdP)); // find field in dataSources
|
|
20949
20968
|
|
|
20950
20969
|
await replace_value_in_string(ret.ret, ret.fieldIdP);
|
|
20951
20970
|
}
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
${refIdP.value}
|
|
70
70
|
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,null,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},execute_evaluate_javascript:async function(){const module=await func.common.get_module(SESSION_ID,"xuda-event-javascript-module.mjs");const result=await module.run_javascript(SESSION_ID,jobNoP,dsSession,`(async function(el,evt) {
|
|
71
71
|
${refIdP.value}
|
|
72
|
-
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,true,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},loader_on:async function(){glb.CURRENT_APP_LOADING=null;LOADER_ACTIVE=true;LOADER_TEXT=descP;func.events.delete_job(SESSION_ID,jobNoP)},loader_off:async function(){LOADER_ACTIVE=false;func.events.delete_job(SESSION_ID,jobNoP)},emit_event:async function(){if(refIdP.value){func.runtime.platform.emit(refIdP.value,[_session.DS_GLB[dsSession]])}else{func.utils.debug_report(SESSION_ID,"func.events.execute","Event name missing","E")}func.events.delete_job(SESSION_ID,jobNoP)},invoke_action:async function(){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,null,expCond);await func.action.execute(SESSION_ID,refIdP.value,_ds,null,null,jobNoP,containerP)},raise_event:async function(){var _ds=_session.DS_GLB[dsSession];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(callingSourceP==="grid"||callingSourceP==="form"){let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",field_elm);var event_name=_field_obj?.workflow?.[eventIdP].name.event;if(_field_obj?.workflow?.[eventIdP].name?.properties["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,props[`xu-exp:event`],dsSession,"event_name expression")).result}if(field_elm&&event_name){const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);return await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,null,calling_trigger_prop?.data?.name?.parameters||{})}}if(callingSourceP.includes("event")){let event_name=refIdP.event;if(refIdP?.properties?.["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,refIdP.properties["xu-exp:event"],dsSession,"event_name expression")).result}const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,calling_trigger_prop?.props?.async,calling_trigger_prop?.data?.name?.parameters||{})}func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond)},get_data:async function(){const params_obj=await get_params_obj();if(!await get_prog_id()){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}var _ds=_session.DS_GLB[dsSession];if(!_ds){func.events.delete_job(SESSION_ID,jobNoP);return}if(_ds){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,calling_trigger_prop,expCond);const ret=await func.datasource.create(SESSION_ID,await get_prog_id(),args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,null,null,args.callingSourceP,args.calling_jobP,args.screen_dsP,args.is_panelP,params_obj);let _ds_new=_session.DS_GLB[ret.dsSessionP];let parameters=args?.calling_trigger_prop?.data?.name?.parameters;if(parameters&&!xu_isEmpty(parameters)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds_new.dsSession,_ds.dsSession)}func.events.delete_job(SESSION_ID,jobNoP);return _ds_new}},set_data:async function(){return this.get_data()},batch:async function(){const result=await this.get_data();return result},update:async function(){const obj_values_to_update=func.datasource.get_viewFields_for_update_function(SESSION_ID,calling_trigger_prop,null,dsSessionP);if(!obj_values_to_update||xu_isEmpty(obj_values_to_update)){func.utils.debug_report(SESSION_ID,"Update values object is empty","","W");if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);return}var updates=[];for await(const[key,val]of Object.entries(obj_values_to_update)){var $element;var iterate_info=null;if(elementP){const element_meta=func.runtime.ui.get_meta(elementP,"xuData");iterate_info=element_meta?.iterate_info||null}let ret_field_id=await func.expression.get(SESSION_ID,val.id.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let _field_id=ret_field_id.result;let _value=ret_value.result;updates.push({_field_id:_field_id,_value:_value})}let datasource_changes={};for await(const change of updates){let ret_get_value=await func.datasource.get_value(SESSION_ID,change._field_id,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][change._field_id]=change._value}}await func.datasource.update(SESSION_ID,datasource_changes,null,null,triggerP);if(_ds.PARAM_OUT_INFO){for await(const[key,val]of Object.entries(_ds.PARAM_OUT_INFO)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds.dsSession,val.parentDataSourceNo)}}if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"call_alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},delay:async function(){return new Promise(resolve=>{setTimeout(function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);resolve()},refIdP.value)})},comment:async function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_project_api:async function(){const params_obj=await get_params_obj();const _prog_id=await get_prog_id();if(!_prog_id){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const api_ret=await func.api.call_project_api(_prog_id,params_obj);await func.datasource.set_outputField(SESSION_ID,dsSessionP,api_ret,args);func.events.delete_job(SESSION_ID,jobNoP)},call_system_api:async function(){const api_method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"api_method");if(!api_method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > api_method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}let payload={};const _payload=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");if(_payload){const get_payload_property_value=async function(prop_name){let _prop=_payload;let _value=_prop[prop_name];if(_prop?.[`xu-exp:${prop_name}`]){_value=(await func.expression.get(SESSION_ID,_prop[`xu-exp:${prop_name}`],dsSession,`${prop_name} expression`)).result}return _value};for await(let[key,val]of Object.entries(_payload)){const new_key=key.replaceAll("xu-exp:","");payload[new_key]=await get_payload_property_value(new_key)}}const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_system_api(api_method,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)},call_external_api:async function(){const method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"method");if(!method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const url=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"url");if(!url){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > url not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const payload_arr=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");const report_conversion_error=function(res,typeP,valP){var msg=`${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;if(error){return func.utils.debug_report(SESSION_ID,msg,"","W")}func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","E")};const report_conversion_warn=function(res){var msg=`${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","W")};if(error){return report_conversion_error()}const module=await func.common.get_module(SESSION_ID,"xuda-get-cast-util-module.mjs");var payload=payload_arr.reduce((ret,val,key)=>{ret[val.key]=module.cast(val.type,val.val,report_conversion_error,report_conversion_warn);return ret},{});const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_external_api(method,url,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)}};return await fx[functionP]()};func.events.delete_job=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSessionP;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.delete_job_0=function(SESSION_ID){var job_index=0;var _session=SESSION_OBJ[SESSION_ID];if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSession;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj&&ds_obj.loops_limit&&ds_obj.loops_count<ds_obj.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.check_jobs_idle=async function(SESSION_ID,jobsP){return new Promise((resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(!jobsP||jobsP&&jobsP.length===0){resolve();return}var listener=setInterval(function(){var found;for(const[key,val]of Object.entries(jobsP)){for(const[key2,val2]of Object.entries(_session.WORKER_OBJ.jobs)){if(key2===val){found=true;break}}}if(!found){do_callback();return}},100);var do_callback=function(){clearInterval(listener);resolve()}})};var loop_detected_obj={};setInterval(function(){loop_detected_obj={}},1e3);func.events.set_browser_changes=function(dsP,fieldsChangedP){if(fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))func.runtime.platform.set_title(dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"])};func.events.execute_PENDING_OPEN_URL_EVENTS=async function(){for(let[key,url]of Object.entries(PENDING_OPEN_URL_EVENTS)){if(url){glb.WINDOW_LOCATION_SEARCH=url;glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes();const params_obj=func.common.getObjectFromUrl(url,glb.ROOT_ELEMENT_ATTRIBUTES);if(!params_obj.prog){return console.warn("prog empty")}await func.utils.TREE_OBJ.get(SESSION_ID,params_obj.prog);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,params_obj.prog);if(screen_ret){await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:params_obj.prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:null,source_functionP:"pendingUrlEvent_embed"})}else{console.error("Program not exist",params_obj.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}}else{console.warn("url empty")}}};func.events.invoke=async function(event_id){var _session=SESSION_OBJ[SESSION_ID];if(!event_id){console.warn("event_id Cannot be empty");return false}var ds;for await(const[ds_key,val]of Object.entries(_session.DS_GLB)){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,val.prog_id);if(xu_isEmpty(_view_obj.progEvents))continue;if(ds)break;for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val?.data?.type==="user_defined"&&val.data.event_name===event_id){ds=ds_key;break}}}if(!ds){console.warn("event_id not found");return false}func.events.validate(SESSION_ID,"user_defined",ds,event_id)};func.expression={};func.expression.get=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP,debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){class xu_class{async get(){if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=true}var ret;var fields={};var error;var warning;function evalJson(text){return eval("("+text+")")}if(valP===null){ret=""}else{switch(typeof valP){case"string":ret=valP;break;case"undefined":ret="";break;case"boolean":ret=valP?"Y":"N";break;default:ret=valP.toString();break}}if(ret.includes("&"))ret=ret.replace(/\&/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const end_results=function(){const replace_quotes=function(ret){for(const[key,val]of Object.entries(fields)){if(typeof val==="string")ret=ret.replace('"'+val+'"',val.replace(/"/gi,""))}return ret};if(["update","javascript"].includes(sourceP)){if(typeof ret==="string")ret=replace_quotes(ret)}const log_error=function(){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}};if(error)log_error();if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=false}const results={result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found};return results};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.startsWith("_DATE_")){ret=ret.slice(6)}else if(ret==="self"||ret&&ret.length===10&&ret[4]==="-"&&ret[7]==="-"){}else{ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}return end_results()}else{ret=ret.replace(/_NULL/gi,"");return end_results()}}catch(err){return end_results()}};if(!func.expression.validate_variables(valP)){return await variable_not_exist()}const validate_email=async function(){const ret=await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback,null,true);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const split=func.expression.parse(ret)||[];const split_entries=Object.entries(split);for(let entry_i=0;entry_i<split_entries.length;entry_i++){const[arr_key,val]=split_entries[entry_i];const key=Number(arr_key);var_Arr[key]={};var_Arr[key].value=val.value;const replace_value_in_string=async function(retP,fieldIdP){if(iterate_info?.iterator_key===fieldIdP||iterate_info?.iterator_val===fieldIdP){if(iterate_info.iterator_key===fieldIdP){retP.value=iterate_info._key}if(iterate_info.iterator_val===fieldIdP){retP.value=iterate_info._val}}const set_value=function(valP){if(typeof valP!=="undefined"){var_Arr[key].value=valP;if(typeof valP==="string")var_Arr[key].type="string"}else{if(retP.type==="object"){var_Arr[key].value="";var_Arr[key].type="string"}}};if(sourceP==="exp"&&retP.type!=="exp"){var_Arr[key].type=retP.type;return}if(typeof retP.value!=="undefined"){var_Arr[key].type=retP.type;var_Arr[key].value=typeof retP.value==="string"&&!retP.value.includes("<svg xmlns=")&&retP.value.indexOf("\\")===-1&&!["UI Attr EXP","update"].includes(sourceP)?retP.value.replaceAll('"','\\"'):retP.value;if(val.value.indexOf("[")>-1|val.value.indexOf(".")>-1){var data=retP.prop;if(retP.type==="object")data=retP.value;var property1,property2;if(val.value.indexOf("[")===-1&&val.value.indexOf("]")>-1&&val.value.substr(0,1)==="@"){var prevData=var_Arr[key-1].value;var_Arr[key].value=prevData[data];if(val.value.indexOf(".")>-1){const props_split=await func.expression.get_property(val.value);property2=props_split.property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{const props=await func.expression.get_property(val.value);property1=props.property1;property2=props.property2;if(property1){var_Arr[key].value=data[property1];if(property2){if(data[property1])set_value(data[property1][property2])}}if(property2&&!property1){if(data){set_value(data[property2])}}}fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}else{fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}}};if(val.fieldId){if(val.fieldId&&val.fieldId.substr(0,5)==="_THIS"&&calling_fieldIdP&&(val.fieldId.length===5||val.fieldId.length>5&&val.fieldId.substr(5,1)===".")){if(val.fieldId.length===5)val.fieldId=calling_fieldIdP;else val.fieldId=calling_fieldIdP+val.fieldId(5,val.fieldId.length-1)}if(!sourceP==="exp"){var_Arr[key].value='""'}fields[val.fieldId]=var_Arr[key].value;const ret=await func.datasource.get_value(SESSION_ID,val.fieldId,dsSessionP,rowIdP);await replace_value_in_string(ret.ret,ret.fieldIdP)}}try{var res=[];var exp_exist;var var_error_found;var_Arr.forEach(function(val,key){if(sourceP==="UI Property EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,true);if(ret.changed){res[key]=ret.value;return true}}if(sourceP==="UI Attr EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,var_Arr.length==1?false:true);if(ret.changed){res[key]=ret.value;return true}}if(val.type==="exp"){exp_exist=true}res[key]=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){res[key]="`"+val.value+"`"}if(["api_rendered_output"].includes(sourceP)&&["json"].includes(api_output_type)&&["string","date"].includes(val.type)){res[key]=`"`+val.value+`"`}}if(val.fieldId&&val.value&&typeof val.value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP)){if(val.value.indexOf("↵")>-1){res[key]=val.value.split("↵").join("")}res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"")}if(["init","update","virtual"].includes(sourceP)){if(val.value.indexOf("↵")>-1)res[key]=val.value.split("↵").join("\n");res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"\\n")}if(typeof IS_PROCESS_SERVER!=="undefined"){res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"<br>")}fields[val.fieldId]=res[key]}if(typeof val.value==="object"&&var_Arr.length>1){if(!Array.isArray(val.value)&&!var_Arr[key+1].value?.includes(".")){res[key]="("+JSON.stringify(val.value)+")"}else{res[key]=JSON.stringify(val.value)}}if(!exp_exist&&sourceP!=="exp"&&val.value&&typeof val.value==="string"&&val.value.substr(0,1)==="@"){warning="Error encoding "+val.value;var_error_found=true;res[key]=0}});const join=function(arrP){return arrP.join("")};var exp=undefined;if(exp_exist&&sourceP!=="exp"){exp=await func.expression.get(SESSION_ID,join(res),dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);if(exp.res)res=exp.res;else res=[exp.result];fields=Object.assign(exp.fields,fieldsP)}var result=join(res);if(res.length===1){result=res[0]}if(secondPassP){ret=result}else if(sourceP!=="exp"){if(res.length===1&&typeof res[0]==="string"&&typeof res[0]!=="object"){ret=join(res);if(ret&&ret.substr(0,1)==="@"){error="Error encoding @ var";var_error_found=true}}else{if(!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,result,jobNo,dsSessionP,js_script_callback)}else{if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(result))}else{ret=result}}}}return end_results()}catch(err){ret=result;error=err.message;return end_results()}}}const new_class=new xu_class;return new_class.get()};func.expression._parse_cache=new Map;func.expression.parse=function(input){if(typeof input!=="string")return[];if(func.expression._parse_cache.has(input)){return func.expression._parse_cache.get(input).map(function(s){return Object.assign({},s)})}const segments=[];let pos=0;const parts=input.split(/(@\w+)/).filter(Boolean);for(const part of parts){if(part.startsWith("@")){const fieldId=part.slice(1);segments.push({value:part,fieldId:fieldId,pos:pos})}else{segments.push({value:part,pos:pos})}pos+=part.length}if(func.expression._parse_cache.size>=500){const firstKey=func.expression._parse_cache.keys().next().value;func.expression._parse_cache.delete(firstKey)}func.expression._parse_cache.set(input,segments);return segments.map(function(s){return Object.assign({},s)})};func.expression.get_property=async function(valP){async function secure_eval(val){if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(val)}catch(err){console.error(err);return}}try{let vm=new VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(val)}catch(err){throw""}}var property1,property2;if(valP.indexOf("[")>-1&&valP.indexOf("]")>-1){property1=valP.substr(valP.indexOf("[")+1,valP.indexOf("]")-valP.indexOf("[")-1);property1=await secure_eval(property1)}if(valP.indexOf(".")>-1)property2=valP.substr(valP.indexOf(".")+1,valP.length);return{property1:property1,property2:property2}};func.expression.validate_constant=function(valP){var patt=/["']/;if(typeof valP==="string"&&patt.test(valP.substr(0,1))&&patt.test(valP.substr(0,valP.length-1)))return true;else return false};func.expression.validate_variables=function(valP){if(typeof valP==="string"&&valP.indexOf("@")>-1)return true;else return false};func.expression.remove_quotes=function(valP){if(func.expression.validate_constant(valP))return valP.substr(1,valP.length-2);else return valP};func.expression.secure_eval=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt,ignore_errors){if(typeof val!=="string")return val;const xu=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const isServer=typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined";if(!isServer){try{return eval(val)}catch(err){try{if(sourceP==="javascript"&&!ignore_errors)console.error(err);return JSON5.parse(val)}catch(err){if(sourceP==="javascript"&&!ignore_errors)console.error(err);return val}}}const sandbox={func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,...sourceP==="javascript"?{axios:axios,got:got,FormData:FormData}:{}};const handleError=err=>{console.error("Execution error:",err);func.events.delete_job(SESSION_ID,job_id);if(isServer&&!SESSION_OBJ[SESSION_ID].crawler){if(sourceP==="javascript"){__.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}else{__.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}return val};if(sourceP==="javascript"){process.on("uncaughtException",handleError);try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules");const script=new VMScript(`try { ${val} } catch (e) { func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, "${job_id}"); }`,{filename:dir,dirname:dir});const vm=new NodeVM({require:{external:true},sandbox:sandbox,timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){return handleError(err)}}try{const vm=new VM({sandbox:sandbox,timeout:1e3,allowAsync:false});return await vm.run(val)}catch{try{return JSON5.parse(val)}catch{return val}}};func.UI.main={};func.UI.main.clear_SYNC_INTERVAL=function(){};func.UI.main.embed_prog_execute=async function(SESSION_ID,prog){var _session=SESSION_OBJ[SESSION_ID];const _prog=await func.utils.VIEWS_OBJ.get(SESSION_ID,prog);const get_params_obj=function(){var params_obj={};if(_prog?.properties?.progParams){for(const[key,val]of Object.entries(_prog.properties.progParams)){if(typeof _session.url_params?.[val.data.parameter]!=="undefined"){params_obj[val.data.parameter]=_session.url_params?.[val.data.parameter];continue}console.warn(`Warning: Program ${_prog.properties.menuName} expected In parameter: ${val.data.parameter} but received null instead`)}}return params_obj};let screen_ret=await func.utils.get_screen_obj(SESSION_ID,prog);if(screen_ret){let ret_init=await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:get_params_obj(),source_functionP:"call_embed"});func.runtime.platform.set_title(screen_ret.properties.menuTitle);return}console.error("Program not exist",prog);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)};func.UI.main.embed_loader=async function(SESSION_ID){var _session=SESSION_OBJ[SESSION_ID];const platform=func.runtime.platform;const browser_hash=platform.get_url_hash();var hash="";if(browser_hash)hash=browser_hash.substr(1);_session.SYS_GLOBAL_STR_BROWSER_HASH_ID=hash;_session.SYS_GLOBAL_STR_BROWSER_TITLE=platform.get_document()?.title||"";const init_system_ds=async function(){if(!["main"].includes(_session.opt.app_computing_mode)){await func.index.new_webworker(SESSION_ID,{menuName:"Main"})}const ret=await func.datasource.create(SESSION_ID,"system");func.index.set_ds_0_proxy(SESSION_ID);return ret};const set_SYS_GLOBAL_KEYS_STATE=async function(SESSION_ID,e,state){if(!_session?.DS_GLB?.[0])return;if(e.keyCode!==16&&e.keyCode!==17&&e.keyCode!==18&&e.keyCode!==91){return}var data={};if(e.keyCode===17){data.SYS_GLOBAL_BOL_CONTROL_KEY_STATE=state}if(e.keyCode===16){data.SYS_GLOBAL_BOL_SHIFT_KEY_STATE=state}if(e.keyCode===18){data.SYS_GLOBAL_BOL_ALT_KEY_STATE=state}if(e.keyCode===91){data.SYS_GLOBAL_BOL_COMMAND_KEY_STATE=state}var datasource_changes={[0]:{["data_system"]:data}};await func.datasource.update(SESSION_ID,datasource_changes)};const start_workers=async function(){_session.WORKER_OBJ.fx=new func.utils.job_worker(SESSION_ID);_session.WORKER_OBJ.fx.init()};const create_embed_container=async function(){func.runtime.ui.ensure_embed_container(SESSION_ID)};const execute_PENDING_OPEN_URL_EVENTS=async function(){if(typeof func.events.execute_PENDING_OPEN_URL_EVENTS!=="undefined"&&glb.is_cordova){func.events.execute_PENDING_OPEN_URL_EVENTS()}};const remove_loader=async function(){document.querySelectorAll(".loader").forEach(function(el){el.remove()});const root_node=func.runtime.ui.get_first_node(_session.root_element);if(root_node?.classList){root_node.classList.remove("loader_background_color")}};const perform_callback=async function(){if(_session.api_callback){_session.api_callback("xuda_ready",SESSION_ID,SESSION_OBJ)}};const call_program=async function(){if(_session.route_id){const route_obj=await func.utils.DOCS_OBJ.get(SESSION_ID,_session.route_id);function flattenMenuItems(menu){let flatMenu={};function recurse(items){for(let item of items){flatMenu[item.id]=item;if(item.children&&item.children.length>0){recurse(item.children)}}}recurse(menu);return flatMenu}const flatMenu=flattenMenuItems(route_obj.routeMenu.menu);const menu_obj=flatMenu[_session.menu_id];if(_session.menu_id){if(menu_obj){_session.prog_id=menu_obj.prog_id;if(menu_obj.prog_params){_session.url_params={..._session.url_params,...menu_obj.prog_params}}if(menu_obj.global_params){_session.url_params={..._session.url_params,...menu_obj.global_params}}}}}if(!_session.prog_id)return;await func.utils.TREE_OBJ.get(SESSION_ID,_session.prog_id);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,_session.prog_id);if(screen_ret){func.UI.main.embed_prog_execute(SESSION_ID,_session.prog_id)}else{console.error("Program not exist",_session.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}};const register_run_background_plugins=async function(){if(typeof glb.SLIM_BUNDLE!=="undefined"||glb.SLIM_BUNDLE)return;for await(const[plugin_name,val]of Object.entries(APP_OBJ[_session.app_id].app_plugins_purchased)){if(val.installed&&val.run_in_background&&val.manifest?.["runtime.mjs"]?.exist){try{const plugin_runtime_src=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,`${val.manifest["runtime.mjs"].dist?"dist/":""}runtime.mjs`);if(val.manifest["runtime.mjs"].dist&&val.manifest?.["runtime.mjs"]?.css){const plugin_runtime_css_url=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,"dist/runtime.css");func.utils.load_css_on_demand(plugin_runtime_css_url)}const plugin_script=await import(plugin_runtime_src);eval(plugin_script);let plugin_setup_script_ret=null;if(val.manifest?.["index.mjs"]?.exist){const plugin_setup_src=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,`${val.manifest["index.mjs"].dist?"dist/":""}index.mjs`);let plugin_setup_script=await import(plugin_setup_src);if(plugin_setup_script){plugin_setup_script_ret=await func.utils.get_plugin_setup(SESSION_ID,plugin_name);if(plugin_setup_script_ret.code<0){throw plugin_setup_script_ret}}}glb.lifecycle.plugins[plugin_name]={plugin_script:plugin_script,setup_data:plugin_setup_script_ret?.data}}catch(err){console.error(err)}}}};async function updateOnlineStatus(){if(!_session?.DS_GLB?.[0])return;var data={};if(IS_ONLINE){data.SYS_GLOBAL_BOL_ONLINE=1}else{data.SYS_GLOBAL_BOL_ONLINE=0}var datasource_changes={[0]:{["data_system"]:data}};await func.datasource.update(SESSION_ID,datasource_changes)}await register_run_background_plugins();func.runtime.ui.show_root_element(SESSION_ID);func.UI.component.create_app_root_component(SESSION_ID);await glb.lifecycle.execute(SESSION_ID,"beforeInit");await start_workers();await init_system_ds();await glb.lifecycle.execute(SESSION_ID,"initialized");await create_embed_container();await execute_PENDING_OPEN_URL_EVENTS();await remove_loader();await func.UI.worker.init(SESSION_ID);await glb.lifecycle.execute(SESSION_ID,"beforeMounted");await call_program();await glb.lifecycle.execute(SESSION_ID,"mounted");await perform_callback();func.utils.debug.write(SESSION_ID,"Xuda.ai started.");await glb.lifecycle.execute(SESSION_ID,"systemReady");if(func.runtime.platform.has_document()){document.addEventListener("keydown",function(e){func.runtime.platform.emit("keydown",e)});document.addEventListener("keyup",function(e){func.runtime.platform.emit("keyup",e)})}func.runtime.platform.on("keydown",function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,1)});func.runtime.platform.on("keyup",function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,0)});await updateOnlineStatus();platform.add_window_listener("online",updateOnlineStatus);platform.add_window_listener("offline",updateOnlineStatus);console.log("xuda.ai system ready.");platform.dispatch_body_event(glb.system_ready_event)};func.UI.main.set_custom_css=function(SESSION_ID,callbackP){const css=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system?.["SYS_GLOBAL_STR_SITE_CSS"];if(css){func.runtime.platform.inject_css(css)}callbackP()};func.index={};if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",function(){func.index.init_document_listeners();func.UI.utils.indicator.worker.normal();func.index.init_service_workers()})}else{setTimeout(function(){func.index.init_document_listeners();func.UI.utils.indicator.worker.normal();func.index.init_service_workers()},0)}function xuda(...args){const platform=func.runtime.platform;const runtime_location=platform.get_location();let element=null;let opt={};let callback=null;for(const arg of args){if(platform.is_html_element(arg)){element=arg}else if(typeof arg==="object"&&arg!==null&&!Array.isArray(arg)){opt=arg}else if(typeof arg==="function"){callback=arg}}if(!element){if(typeof glb.SLIM_BUNDLE==="undefined"||!glb.SLIM_BUNDLE){return console.error("Xuda Error - element argument is empty")}element="body";console.warn("root element set to body")}if(typeof element==="string"?!document.querySelector(element):!element){return console.error("Xuda Error - element not found")}if(typeof opt==="undefined"){return console.error("Xuda Error - opt argument is undefined")}if(typeof opt!=="object"){return console.error("Xuda Error - opt argument is not an object")}glb.URL_PARAMS=func.common.getJsonFromUrl(platform.get_url_href());glb.worker_type="Worker";if(opt.debug_js){glb.debug_js=true;if((runtime_location?.host?.includes("localhost")||runtime_location?.host?.includes("127.0.0.1"))&&typeof glb.SLIM_BUNDLE==="undefined"&&typeof glb.CODE_BUNDLE==="undefined"){glb.worker_type="Dev"}else{glb.worker_type="Debug"}}const call_xuda=async function(){const _instance_id=Date.now().toString()+Math.round(Math.random()*1e4).toString();const _api_callback=callback;const create_index_html=function(){func.runtime.ui.ensure_app_shell(SESSION_ID,_session.domain)};const device_ready=async function(){return new Promise(function(resolve,reject){if(!func.utils.get_device()){return resolve()}platform.get_document().addEventListener("deviceready",function(){glb.is_cordova=true;resolve()},false)})};const get_fingerprint_component=async function(){return new Promise(function(resolve,reject){Fingerprint2.get(function(components){resolve(components)})})};const get_session_id=function(){return func.runtime.session.get_fingerprint(components,_instance_id)};const get_fingerprint=function(){return func.runtime.session.get_fingerprint(components)};const init_SESSION=function(){return func.runtime.session.create_state(SESSION_ID,{opt:opt,root_element:typeof element==="string"?document.querySelector(element):element,worker_type:glb.worker_type,api_callback:_api_callback,code_bundle:glb.CODE_BUNDLE,slim_bundle:glb.SLIM_BUNDLE,url_params:opt.url_params})};const set_SESSION=async function(){for await(const key of["gtp_token","app_token","prog_id","domain","engine_mode","crawler","app_id","route_id","menu_id","local_live_preview","project_data"]){_session[key]=func.UI.utils.get_url_attribute(SESSION_ID,key);if(!_session[key]){func.runtime.session.set_default_value(_session,key)}switch(key){case"domain":if(_session[key].includes("localhost")||_session[key].includes("127.0.0.1")){const getSubdomain=url=>{let domain=url;if(url.includes("://")){domain=url.split("://")[1]}let subdomain="";if(!_session[key].includes("127.0.0.1")){subdomain=domain.split(".")[0]}return subdomain};_session[key]=getSubdomain(_session[key])?getSubdomain(_session[key])+".xuda.ai":"xuda.ai"}break;case"project_data":{if(typeof glb.SLIM_BUNDLE!=="undefined"||glb.SLIM_BUNDLE){const{root_element}=_session;if(!_session[key]){_session[key]={}}if(!_session[key].programs){_session[key].programs={}}if(!_session[key].globals){_session[key].globals={_id:"globals",progDataSource:{},properties:{menuType:"globals"},studio_meta:{},progEvents:[],progFields:[]}}const _templates=document.querySelectorAll("template");if(_templates.length){const module=await func.common.get_module(SESSION_ID,"xuda-cli-plugin-html-parser-module.esm.mjs");_templates.forEach(function(el,idx){const _id=el.getAttribute("id")||"template_"+idx.toString();if(!_session[key].programs[_id]){_session[key].programs[_id]={_id:_id,progDataSource:{},properties:{menuType:"component",renderType:"form"},studio_meta:{},progEvents:[],progFields:[]}}if(el.innerHTML){window.xudaStringify=module.xudaStringify;const progUi=module.xudaPrase(el.innerHTML);_session[key].programs[_id].progUi=progUi?.[0]?.children||[]}});if(!_session.prog_id){_session.prog_id=_templates[0]?.getAttribute("id")||"template_0"}root_element.innerHTML=""}}break}default:break}}_session.crawler=opt.crawler};const set_SYS_GLOBAL_OBJ_CLIENT_INFO=function(){func.runtime.session.populate_client_info(_session,components)};const init_globals=function(){const{app_id,worker_type}=_session;if(worker_type!=="Worker"){glb.DEBUG_MODE=true}SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal=-1;PROJECT_OBJ[app_id]={};DOCS_OBJ[app_id]={};glb.APP_INFO[app_id]={};glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes(SESSION_ID);DATASOURCE_INTERVALS[SESSION_ID]={}};const print_version_info=function(){const version_name=`Xuda.ai ${opt.engine_mode} ${opt?.app_version||""} Session Id: ${SESSION_ID}`;const divider="#".repeat(version_name.length);console.info(divider);console.info(version_name);console.info(divider)};const print_xuda_banner=function(){var banner="";["__ ___ _ ____ _ ","\\ \\/ / | | | _ \\ / \\ "," \\ /| | | | | | |/ _ \\ "," / \\| |_| | |_| / ___ \\ ","/_/\\_\\\\___/|____/_/ \\_\\"].forEach(e=>{banner+=e+"\r\n"});console.info(banner)};print_xuda_banner();await func.index.checkConnectivity();var SESSION_ID=Date.now();var components;if(typeof glb.SLIM_BUNDLE==="undefined"||!glb.SLIM_BUNDLE){await device_ready();components=await get_fingerprint_component();SESSION_ID=get_session_id();print_version_info()}var _session=init_SESSION();await set_SESSION();create_index_html();APP_OBJ[_session.app_id]={};init_globals();if(typeof glb.SLIM_BUNDLE!=="undefined"&&glb.SLIM_BUNDLE){await func.UI.main.embed_loader(SESSION_ID);return}set_SYS_GLOBAL_OBJ_CLIENT_INFO(SESSION_ID);if(!_session.app_id){func.UI.utils.progressScreen.show(SESSION_ID,"Error reading app_id",false,true);console.error("no app_id found");return}const module=await func.common.get_module(SESSION_ID,"xuda-project-loader-module.esm.js");const db_adapter=await func.common.get_module(SESSION_ID,"xuda-db-adapter-module.mjs");func.db=db_adapter._db;await module.project_loader(SESSION_ID,_session.app_id);func.db.pouch.init_db_replication(SESSION_ID)};glb.system_ready_event=new Event("on_mounted");call_xuda();return{on_mounted:function(fn){document.body.addEventListener("on_mounted",e=>{fn()},false)}}}func.index.call_worker=async function(SESSION_ID,obj,params,promiseP){var _session=SESSION_OBJ[SESSION_ID];if(_session.opt.app_computing_mode==="main"){return}return new Promise(async function(resolve,reject){var worker_id;const set_promise_queue=function(worker_id){var t=glb.worker_queue_num++;try{func.runtime.workers.set_promise(SESSION_ID,worker_id,t,{resolve:promiseP?promiseP.resolve:resolve,reject:promiseP?promiseP.reject:reject,worker_id:worker_id})}catch(e){console.log(worker_id)}return t};const get_worker_id=function(ds){if(!_session.DS_GLB[ds]){if(ds==0){console.error("Error - onscreen (window,modal etc..) event cannot be invoked by on_load");return}else{return}}if(ds==0){return 1}if(_session.DS_GLB[ds].worker_id){return _session.DS_GLB[ds].worker_id}else{if(typeof _session.DS_GLB[ds].parentDataSourceNo!=="undefined"){return get_worker_id(_session.DS_GLB[ds].parentDataSourceNo)}}};if(obj.service==="datasource_create"){if(!params||params&&!params.done){var prog_obj=await func.utils.TREE_OBJ.get(SESSION_ID,obj.data.prog_id);if(!prog_obj||!prog_obj.dedicatedWorker){if(!Object.keys(WEB_WORKER[SESSION_ID]).length){worker_id=await func.index.new_webworker(SESSION_ID,{menuName:"Main"},obj)}else{if(obj.data.IS_DATASOURCE_REFRESH){worker_id=get_worker_id(obj.data.parentDataSourceNo)}else{worker_id=get_worker_id(obj.data.parentDataSourceNoP)}if(!worker_id){debugger}}}else{if(obj.data.IS_DATASOURCE_REFRESH){worker_id=get_worker_id(obj.data.parentDataSourceNo)}else{worker_id=await func.index.new_webworker(SESSION,prog_obj,obj);return _resolve()}}}else{worker_id=params.worker_id}}else{if(params&¶ms.worker_id){worker_id=params.worker_id}else{worker_id=get_worker_id(obj.data.dssession)}if(!worker_id)worker_id=1}try{var msg=obj;msg.worker_id=worker_id;if(!worker_id){console.warn("missing worker_id")}msg.promise_queue_id=set_promise_queue(worker_id);if(!WEB_WORKER[SESSION_ID][worker_id]){return resolve()}msg=JSON.stringify(obj,func.utils.clean_stringify_null,"\t");let msg_obj=JSON.parse(msg);if(!func.runtime.workers.is_server_transport(_session)){msg_obj.data=JSON.stringify(msg_obj.data)}func.runtime.workers.send_message(SESSION_ID,worker_id,_session,msg_obj,WEBSOCKET_PROCESS_PID)}catch(e){console.error(e);return reject(e)}})};func.index.init_SCREEN_BLOCKER=async function(SESSION_ID){const get_loader=async function(){if(func.runtime.session.is_slim(SESSION_ID)||typeof UI_FRAMEWORK_PLUGIN?.loader!=="function"){return{dismiss:function(){}}}return await UI_FRAMEWORK_PLUGIN.loader(LOADER_TEXT)};setInterval(async function(){if(glb.CURRENT_APP_LOADING||!LOADER_ACTIVE&&xu_isEmpty(SCREEN_BLOCKER_OBJ)){return}glb.CURRENT_APP_LOADING=1;const loader=await get_loader();glb.CURRENT_APP_LOADING=loader;var interval=setInterval(function(){if(xu_isEmpty(SCREEN_BLOCKER_OBJ)&&!LOADER_ACTIVE){if(glb.CURRENT_APP_LOADING){glb.CURRENT_APP_LOADING.dismiss()}clearInterval(interval);glb.CURRENT_APP_LOADING=null}},100)},1e3)};func.index.init_document_listeners=function(){const platform=func.runtime.platform;document.addEventListener("keydown",function(event){CLIENT_ACTIVITY_TS=Date.now();var keys={72:{key:"h",name:"Help",fx:function(){let SESSION_ID=Object.keys(SESSION_OBJ)[0];let _session=SESSION_OBJ[SESSION_ID];let app_id=_session.app_id;if(!_session.opt.enable_utility_screen)return;func.UI.utils.progressScreen.show(SESSION_ID,`
|
|
72
|
+
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,true,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},loader_on:async function(){glb.CURRENT_APP_LOADING=null;LOADER_ACTIVE=true;LOADER_TEXT=descP;func.events.delete_job(SESSION_ID,jobNoP)},loader_off:async function(){LOADER_ACTIVE=false;func.events.delete_job(SESSION_ID,jobNoP)},emit_event:async function(){if(refIdP.value){func.runtime.platform.emit(refIdP.value,[_session.DS_GLB[dsSession]])}else{func.utils.debug_report(SESSION_ID,"func.events.execute","Event name missing","E")}func.events.delete_job(SESSION_ID,jobNoP)},invoke_action:async function(){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,null,expCond);await func.action.execute(SESSION_ID,refIdP.value,_ds,null,null,jobNoP,containerP)},raise_event:async function(){var _ds=_session.DS_GLB[dsSession];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(callingSourceP==="grid"||callingSourceP==="form"){let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",field_elm);var event_name=_field_obj?.workflow?.[eventIdP].name.event;if(_field_obj?.workflow?.[eventIdP].name?.properties["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,props[`xu-exp:event`],dsSession,"event_name expression")).result}if(field_elm&&event_name){const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);return await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,null,calling_trigger_prop?.data?.name?.parameters||{})}}if(callingSourceP.includes("event")){let event_name=refIdP.event;if(refIdP?.properties?.["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,refIdP.properties["xu-exp:event"],dsSession,"event_name expression")).result}const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,calling_trigger_prop?.props?.async,calling_trigger_prop?.data?.name?.parameters||{})}func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond)},get_data:async function(){const params_obj=await get_params_obj();if(!await get_prog_id()){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}var _ds=_session.DS_GLB[dsSession];if(!_ds){func.events.delete_job(SESSION_ID,jobNoP);return}if(_ds){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,calling_trigger_prop,expCond);const ret=await func.datasource.create(SESSION_ID,await get_prog_id(),args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,null,null,args.callingSourceP,args.calling_jobP,args.screen_dsP,args.is_panelP,params_obj);let _ds_new=_session.DS_GLB[ret.dsSessionP];let parameters=args?.calling_trigger_prop?.data?.name?.parameters;if(parameters&&!xu_isEmpty(parameters)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds_new.dsSession,_ds.dsSession)}func.events.delete_job(SESSION_ID,jobNoP);return _ds_new}},set_data:async function(){return this.get_data()},batch:async function(){const result=await this.get_data();return result},update:async function(){const obj_values_to_update=func.datasource.get_viewFields_for_update_function(SESSION_ID,calling_trigger_prop,null,dsSessionP);if(!obj_values_to_update||xu_isEmpty(obj_values_to_update)){func.utils.debug_report(SESSION_ID,"Update values object is empty","","W");if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);return}var updates=[];for await(const[key,val]of Object.entries(obj_values_to_update)){var $element;var iterate_info=null;if(elementP){const element_meta=func.runtime.ui.get_meta(elementP,"xuData");iterate_info=element_meta?.iterate_info||null}let ret_field_id=await func.expression.get(SESSION_ID,val.id.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let _field_id=ret_field_id.result;let _value=ret_value.result;updates.push({_field_id:_field_id,_value:_value})}let datasource_changes={};for await(const change of updates){let ret_get_value=await func.datasource.get_value(SESSION_ID,change._field_id,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][change._field_id]=change._value}}await func.datasource.update(SESSION_ID,datasource_changes,null,null,triggerP);if(_ds.PARAM_OUT_INFO){for await(const[key,val]of Object.entries(_ds.PARAM_OUT_INFO)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds.dsSession,val.parentDataSourceNo)}}if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"call_alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},delay:async function(){return new Promise(resolve=>{setTimeout(function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);resolve()},refIdP.value)})},comment:async function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_project_api:async function(){const params_obj=await get_params_obj();const _prog_id=await get_prog_id();if(!_prog_id){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const api_ret=await func.api.call_project_api(_prog_id,params_obj);await func.datasource.set_outputField(SESSION_ID,dsSessionP,api_ret,args);func.events.delete_job(SESSION_ID,jobNoP)},call_system_api:async function(){const api_method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"api_method");if(!api_method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > api_method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}let payload={};const _payload=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");if(_payload){const get_payload_property_value=async function(prop_name){let _prop=_payload;let _value=_prop[prop_name];if(_prop?.[`xu-exp:${prop_name}`]){_value=(await func.expression.get(SESSION_ID,_prop[`xu-exp:${prop_name}`],dsSession,`${prop_name} expression`)).result}return _value};for await(let[key,val]of Object.entries(_payload)){const new_key=key.replaceAll("xu-exp:","");payload[new_key]=await get_payload_property_value(new_key)}}const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_system_api(api_method,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)},call_external_api:async function(){const method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"method");if(!method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const url=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"url");if(!url){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > url not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const payload_arr=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");const report_conversion_error=function(res,typeP,valP){var msg=`${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;if(error){return func.utils.debug_report(SESSION_ID,msg,"","W")}func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","E")};const report_conversion_warn=function(res){var msg=`${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","W")};if(error){return report_conversion_error()}const module=await func.common.get_module(SESSION_ID,"xuda-get-cast-util-module.mjs");var payload=payload_arr.reduce((ret,val,key)=>{ret[val.key]=module.cast(val.type,val.val,report_conversion_error,report_conversion_warn);return ret},{});const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_external_api(method,url,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)}};return await fx[functionP]()};func.events.delete_job=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSessionP;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.delete_job_0=function(SESSION_ID){var job_index=0;var _session=SESSION_OBJ[SESSION_ID];if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSession;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj&&ds_obj.loops_limit&&ds_obj.loops_count<ds_obj.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.check_jobs_idle=async function(SESSION_ID,jobsP){return new Promise((resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(!jobsP||jobsP&&jobsP.length===0){resolve();return}var listener=setInterval(function(){var found;for(const[key,val]of Object.entries(jobsP)){for(const[key2,val2]of Object.entries(_session.WORKER_OBJ.jobs)){if(key2===val){found=true;break}}}if(!found){do_callback();return}},100);var do_callback=function(){clearInterval(listener);resolve()}})};var loop_detected_obj={};setInterval(function(){loop_detected_obj={}},1e3);func.events.set_browser_changes=function(dsP,fieldsChangedP){if(fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))func.runtime.platform.set_title(dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"])};func.events.execute_PENDING_OPEN_URL_EVENTS=async function(){for(let[key,url]of Object.entries(PENDING_OPEN_URL_EVENTS)){if(url){glb.WINDOW_LOCATION_SEARCH=url;glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes();const params_obj=func.common.getObjectFromUrl(url,glb.ROOT_ELEMENT_ATTRIBUTES);if(!params_obj.prog){return console.warn("prog empty")}await func.utils.TREE_OBJ.get(SESSION_ID,params_obj.prog);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,params_obj.prog);if(screen_ret){await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:params_obj.prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:null,source_functionP:"pendingUrlEvent_embed"})}else{console.error("Program not exist",params_obj.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}}else{console.warn("url empty")}}};func.events.invoke=async function(event_id){var _session=SESSION_OBJ[SESSION_ID];if(!event_id){console.warn("event_id Cannot be empty");return false}var ds;for await(const[ds_key,val]of Object.entries(_session.DS_GLB)){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,val.prog_id);if(xu_isEmpty(_view_obj.progEvents))continue;if(ds)break;for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val?.data?.type==="user_defined"&&val.data.event_name===event_id){ds=ds_key;break}}}if(!ds){console.warn("event_id not found");return false}func.events.validate(SESSION_ID,"user_defined",ds,event_id)};func.expression={};func.expression.get=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP,debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){class xu_class{async get(){if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=true}var ret;var fields={};var error;var warning;function evalJson(text){return eval("("+text+")")}if(valP===null){ret=""}else{switch(typeof valP){case"string":ret=valP;break;case"undefined":ret="";break;case"boolean":ret=valP?"Y":"N";break;default:ret=valP.toString();break}}if(ret.includes("&"))ret=ret.replace(/\&/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const end_results=function(){const replace_quotes=function(ret){for(const[key,val]of Object.entries(fields)){if(typeof val==="string")ret=ret.replace('"'+val+'"',val.replace(/"/gi,""))}return ret};if(["update","javascript"].includes(sourceP)){if(typeof ret==="string")ret=replace_quotes(ret)}const log_error=function(){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}};if(error)log_error();if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=false}const results={result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found};return results};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.startsWith("_DATE_")){ret=ret.slice(6)}else if(ret==="self"||ret&&ret.length===10&&ret[4]==="-"&&ret[7]==="-"){}else{ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}return end_results()}else{ret=ret.replace(/_NULL/gi,"");return end_results()}}catch(err){return end_results()}};if(!func.expression.validate_variables(valP)){return await variable_not_exist()}const validate_email=async function(){const ret=await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback,null,true);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const get_iterate_value_ret=function(fieldIdP){if(!iterate_info||iterate_info.iterator_key!==fieldIdP&&iterate_info.iterator_val!==fieldIdP){return null}const iter_value=iterate_info.iterator_key===fieldIdP?iterate_info._key:iterate_info._val;const iter_type=typeof iter_value!=="undefined"?{}.toString.call(iter_value).match(/\s([a-zA-Z]+)/)[1].toLowerCase():"string";return{ret:{value:iter_value,type:iter_type,prop:["array","object"].includes(iter_type)?iter_value:null},fieldIdP:fieldIdP,currentRecordId:rowIdP,found:typeof iter_value!=="undefined"}};const split=func.expression.parse(ret)||[];const split_entries=Object.entries(split);for(let entry_i=0;entry_i<split_entries.length;entry_i++){const[arr_key,val]=split_entries[entry_i];const key=Number(arr_key);var_Arr[key]={};var_Arr[key].value=val.value;const replace_value_in_string=async function(retP,fieldIdP){if(iterate_info?.iterator_key===fieldIdP||iterate_info?.iterator_val===fieldIdP){if(iterate_info.iterator_key===fieldIdP){retP.value=iterate_info._key}if(iterate_info.iterator_val===fieldIdP){retP.value=iterate_info._val}}const set_value=function(valP){if(typeof valP!=="undefined"){var_Arr[key].value=valP;if(typeof valP==="string")var_Arr[key].type="string"}else{if(retP.type==="object"){var_Arr[key].value="";var_Arr[key].type="string"}}};if(sourceP==="exp"&&retP.type!=="exp"){var_Arr[key].type=retP.type;return}if(typeof retP.value!=="undefined"){var_Arr[key].type=retP.type;var_Arr[key].value=typeof retP.value==="string"&&!retP.value.includes("<svg xmlns=")&&retP.value.indexOf("\\")===-1&&!["UI Attr EXP","update"].includes(sourceP)?retP.value.replaceAll('"','\\"'):retP.value;if(val.value.indexOf("[")>-1|val.value.indexOf(".")>-1){var data=retP.prop;if(retP.type==="object")data=retP.value;var property1,property2;if(val.value.indexOf("[")===-1&&val.value.indexOf("]")>-1&&val.value.substr(0,1)==="@"){var prevData=var_Arr[key-1].value;var_Arr[key].value=prevData[data];if(val.value.indexOf(".")>-1){const props_split=await func.expression.get_property(val.value);property2=props_split.property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{const props=await func.expression.get_property(val.value);property1=props.property1;property2=props.property2;if(property1){var_Arr[key].value=data[property1];if(property2){if(data[property1])set_value(data[property1][property2])}}if(property2&&!property1){if(data){set_value(data[property2])}}}fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}else{fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}}};if(val.fieldId){if(val.fieldId&&val.fieldId.substr(0,5)==="_THIS"&&calling_fieldIdP&&(val.fieldId.length===5||val.fieldId.length>5&&val.fieldId.substr(5,1)===".")){if(val.fieldId.length===5)val.fieldId=calling_fieldIdP;else val.fieldId=calling_fieldIdP+val.fieldId(5,val.fieldId.length-1)}if(!sourceP==="exp"){var_Arr[key].value='""'}fields[val.fieldId]=var_Arr[key].value;const ret=get_iterate_value_ret(val.fieldId)||await func.datasource.get_value(SESSION_ID,val.fieldId,dsSessionP,rowIdP);await replace_value_in_string(ret.ret,ret.fieldIdP)}}try{var res=[];var exp_exist;var var_error_found;var_Arr.forEach(function(val,key){if(sourceP==="UI Property EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,true);if(ret.changed){res[key]=ret.value;return true}}if(sourceP==="UI Attr EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,var_Arr.length==1?false:true);if(ret.changed){res[key]=ret.value;return true}}if(val.type==="exp"){exp_exist=true}res[key]=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){res[key]="`"+val.value+"`"}if(["api_rendered_output"].includes(sourceP)&&["json"].includes(api_output_type)&&["string","date"].includes(val.type)){res[key]=`"`+val.value+`"`}}if(val.fieldId&&val.value&&typeof val.value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP)){if(val.value.indexOf("↵")>-1){res[key]=val.value.split("↵").join("")}res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"")}if(["init","update","virtual"].includes(sourceP)){if(val.value.indexOf("↵")>-1)res[key]=val.value.split("↵").join("\n");res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"\\n")}if(typeof IS_PROCESS_SERVER!=="undefined"){res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"<br>")}fields[val.fieldId]=res[key]}if(typeof val.value==="object"&&var_Arr.length>1){if(!Array.isArray(val.value)&&!var_Arr[key+1].value?.includes(".")){res[key]="("+JSON.stringify(val.value)+")"}else{res[key]=JSON.stringify(val.value)}}if(!exp_exist&&sourceP!=="exp"&&val.value&&typeof val.value==="string"&&val.value.substr(0,1)==="@"){warning="Error encoding "+val.value;var_error_found=true;res[key]=0}});const join=function(arrP){return arrP.join("")};var exp=undefined;if(exp_exist&&sourceP!=="exp"){exp=await func.expression.get(SESSION_ID,join(res),dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);if(exp.res)res=exp.res;else res=[exp.result];fields=Object.assign(exp.fields,fieldsP)}var result=join(res);if(res.length===1){result=res[0]}if(secondPassP){ret=result}else if(sourceP!=="exp"){if(res.length===1&&typeof res[0]==="string"&&typeof res[0]!=="object"){ret=join(res);if(ret&&ret.substr(0,1)==="@"){error="Error encoding @ var";var_error_found=true}}else{if(!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,result,jobNo,dsSessionP,js_script_callback)}else{if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(result))}else{ret=result}}}}return end_results()}catch(err){ret=result;error=err.message;return end_results()}}}const new_class=new xu_class;return new_class.get()};func.expression._parse_cache=new Map;func.expression.parse=function(input){if(typeof input!=="string")return[];if(func.expression._parse_cache.has(input)){return func.expression._parse_cache.get(input).map(function(s){return Object.assign({},s)})}const segments=[];let pos=0;const parts=input.split(/(@\w+)/).filter(Boolean);for(const part of parts){if(part.startsWith("@")){const fieldId=part.slice(1);segments.push({value:part,fieldId:fieldId,pos:pos})}else{segments.push({value:part,pos:pos})}pos+=part.length}if(func.expression._parse_cache.size>=500){const firstKey=func.expression._parse_cache.keys().next().value;func.expression._parse_cache.delete(firstKey)}func.expression._parse_cache.set(input,segments);return segments.map(function(s){return Object.assign({},s)})};func.expression.get_property=async function(valP){async function secure_eval(val){if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(val)}catch(err){console.error(err);return}}try{let vm=new VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(val)}catch(err){throw""}}var property1,property2;if(valP.indexOf("[")>-1&&valP.indexOf("]")>-1){property1=valP.substr(valP.indexOf("[")+1,valP.indexOf("]")-valP.indexOf("[")-1);property1=await secure_eval(property1)}if(valP.indexOf(".")>-1)property2=valP.substr(valP.indexOf(".")+1,valP.length);return{property1:property1,property2:property2}};func.expression.validate_constant=function(valP){var patt=/["']/;if(typeof valP==="string"&&patt.test(valP.substr(0,1))&&patt.test(valP.substr(0,valP.length-1)))return true;else return false};func.expression.validate_variables=function(valP){if(typeof valP==="string"&&valP.indexOf("@")>-1)return true;else return false};func.expression.remove_quotes=function(valP){if(func.expression.validate_constant(valP))return valP.substr(1,valP.length-2);else return valP};func.expression.secure_eval=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt,ignore_errors){if(typeof val!=="string")return val;const xu=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const isServer=typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined";if(!isServer){try{return eval(val)}catch(err){try{if(sourceP==="javascript"&&!ignore_errors)console.error(err);return JSON5.parse(val)}catch(err){if(sourceP==="javascript"&&!ignore_errors)console.error(err);return val}}}const sandbox={func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,...sourceP==="javascript"?{axios:axios,got:got,FormData:FormData}:{}};const handleError=err=>{console.error("Execution error:",err);func.events.delete_job(SESSION_ID,job_id);if(isServer&&!SESSION_OBJ[SESSION_ID].crawler){if(sourceP==="javascript"){__.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}else{__.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}return val};if(sourceP==="javascript"){process.on("uncaughtException",handleError);try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules");const script=new VMScript(`try { ${val} } catch (e) { func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, "${job_id}"); }`,{filename:dir,dirname:dir});const vm=new NodeVM({require:{external:true},sandbox:sandbox,timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){return handleError(err)}}try{const vm=new VM({sandbox:sandbox,timeout:1e3,allowAsync:false});return await vm.run(val)}catch{try{return JSON5.parse(val)}catch{return val}}};func.UI.main={};func.UI.main.clear_SYNC_INTERVAL=function(){};func.UI.main.embed_prog_execute=async function(SESSION_ID,prog){var _session=SESSION_OBJ[SESSION_ID];const _prog=await func.utils.VIEWS_OBJ.get(SESSION_ID,prog);const get_params_obj=function(){var params_obj={};if(_prog?.properties?.progParams){for(const[key,val]of Object.entries(_prog.properties.progParams)){if(typeof _session.url_params?.[val.data.parameter]!=="undefined"){params_obj[val.data.parameter]=_session.url_params?.[val.data.parameter];continue}console.warn(`Warning: Program ${_prog.properties.menuName} expected In parameter: ${val.data.parameter} but received null instead`)}}return params_obj};let screen_ret=await func.utils.get_screen_obj(SESSION_ID,prog);if(screen_ret){let ret_init=await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:get_params_obj(),source_functionP:"call_embed"});func.runtime.platform.set_title(screen_ret.properties.menuTitle);return}console.error("Program not exist",prog);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)};func.UI.main.embed_loader=async function(SESSION_ID){var _session=SESSION_OBJ[SESSION_ID];const platform=func.runtime.platform;const browser_hash=platform.get_url_hash();var hash="";if(browser_hash)hash=browser_hash.substr(1);_session.SYS_GLOBAL_STR_BROWSER_HASH_ID=hash;_session.SYS_GLOBAL_STR_BROWSER_TITLE=platform.get_document()?.title||"";const init_system_ds=async function(){if(!["main"].includes(_session.opt.app_computing_mode)){await func.index.new_webworker(SESSION_ID,{menuName:"Main"})}const ret=await func.datasource.create(SESSION_ID,"system");func.index.set_ds_0_proxy(SESSION_ID);return ret};const set_SYS_GLOBAL_KEYS_STATE=async function(SESSION_ID,e,state){if(!_session?.DS_GLB?.[0])return;if(e.keyCode!==16&&e.keyCode!==17&&e.keyCode!==18&&e.keyCode!==91){return}var data={};if(e.keyCode===17){data.SYS_GLOBAL_BOL_CONTROL_KEY_STATE=state}if(e.keyCode===16){data.SYS_GLOBAL_BOL_SHIFT_KEY_STATE=state}if(e.keyCode===18){data.SYS_GLOBAL_BOL_ALT_KEY_STATE=state}if(e.keyCode===91){data.SYS_GLOBAL_BOL_COMMAND_KEY_STATE=state}var datasource_changes={[0]:{["data_system"]:data}};await func.datasource.update(SESSION_ID,datasource_changes)};const start_workers=async function(){_session.WORKER_OBJ.fx=new func.utils.job_worker(SESSION_ID);_session.WORKER_OBJ.fx.init()};const create_embed_container=async function(){func.runtime.ui.ensure_embed_container(SESSION_ID)};const execute_PENDING_OPEN_URL_EVENTS=async function(){if(typeof func.events.execute_PENDING_OPEN_URL_EVENTS!=="undefined"&&glb.is_cordova){func.events.execute_PENDING_OPEN_URL_EVENTS()}};const remove_loader=async function(){document.querySelectorAll(".loader").forEach(function(el){el.remove()});const root_node=func.runtime.ui.get_first_node(_session.root_element);if(root_node?.classList){root_node.classList.remove("loader_background_color")}};const perform_callback=async function(){if(_session.api_callback){_session.api_callback("xuda_ready",SESSION_ID,SESSION_OBJ)}};const call_program=async function(){if(_session.route_id){const route_obj=await func.utils.DOCS_OBJ.get(SESSION_ID,_session.route_id);function flattenMenuItems(menu){let flatMenu={};function recurse(items){for(let item of items){flatMenu[item.id]=item;if(item.children&&item.children.length>0){recurse(item.children)}}}recurse(menu);return flatMenu}const flatMenu=flattenMenuItems(route_obj.routeMenu.menu);const menu_obj=flatMenu[_session.menu_id];if(_session.menu_id){if(menu_obj){_session.prog_id=menu_obj.prog_id;if(menu_obj.prog_params){_session.url_params={..._session.url_params,...menu_obj.prog_params}}if(menu_obj.global_params){_session.url_params={..._session.url_params,...menu_obj.global_params}}}}}if(!_session.prog_id)return;await func.utils.TREE_OBJ.get(SESSION_ID,_session.prog_id);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,_session.prog_id);if(screen_ret){func.UI.main.embed_prog_execute(SESSION_ID,_session.prog_id)}else{console.error("Program not exist",_session.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}};const register_run_background_plugins=async function(){if(typeof glb.SLIM_BUNDLE!=="undefined"||glb.SLIM_BUNDLE)return;for await(const[plugin_name,val]of Object.entries(APP_OBJ[_session.app_id].app_plugins_purchased)){if(val.installed&&val.run_in_background&&val.manifest?.["runtime.mjs"]?.exist){try{const plugin_runtime_src=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,`${val.manifest["runtime.mjs"].dist?"dist/":""}runtime.mjs`);if(val.manifest["runtime.mjs"].dist&&val.manifest?.["runtime.mjs"]?.css){const plugin_runtime_css_url=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,"dist/runtime.css");func.utils.load_css_on_demand(plugin_runtime_css_url)}const plugin_script=await import(plugin_runtime_src);eval(plugin_script);let plugin_setup_script_ret=null;if(val.manifest?.["index.mjs"]?.exist){const plugin_setup_src=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,`${val.manifest["index.mjs"].dist?"dist/":""}index.mjs`);let plugin_setup_script=await import(plugin_setup_src);if(plugin_setup_script){plugin_setup_script_ret=await func.utils.get_plugin_setup(SESSION_ID,plugin_name);if(plugin_setup_script_ret.code<0){throw plugin_setup_script_ret}}}glb.lifecycle.plugins[plugin_name]={plugin_script:plugin_script,setup_data:plugin_setup_script_ret?.data}}catch(err){console.error(err)}}}};async function updateOnlineStatus(){if(!_session?.DS_GLB?.[0])return;var data={};if(IS_ONLINE){data.SYS_GLOBAL_BOL_ONLINE=1}else{data.SYS_GLOBAL_BOL_ONLINE=0}var datasource_changes={[0]:{["data_system"]:data}};await func.datasource.update(SESSION_ID,datasource_changes)}await register_run_background_plugins();func.runtime.ui.show_root_element(SESSION_ID);func.UI.component.create_app_root_component(SESSION_ID);await glb.lifecycle.execute(SESSION_ID,"beforeInit");await start_workers();await init_system_ds();await glb.lifecycle.execute(SESSION_ID,"initialized");await create_embed_container();await execute_PENDING_OPEN_URL_EVENTS();await remove_loader();await func.UI.worker.init(SESSION_ID);await glb.lifecycle.execute(SESSION_ID,"beforeMounted");await call_program();await glb.lifecycle.execute(SESSION_ID,"mounted");await perform_callback();func.utils.debug.write(SESSION_ID,"Xuda.ai started.");await glb.lifecycle.execute(SESSION_ID,"systemReady");if(func.runtime.platform.has_document()){document.addEventListener("keydown",function(e){func.runtime.platform.emit("keydown",e)});document.addEventListener("keyup",function(e){func.runtime.platform.emit("keyup",e)})}func.runtime.platform.on("keydown",function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,1)});func.runtime.platform.on("keyup",function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,0)});await updateOnlineStatus();platform.add_window_listener("online",updateOnlineStatus);platform.add_window_listener("offline",updateOnlineStatus);console.log("xuda.ai system ready.");platform.dispatch_body_event(glb.system_ready_event)};func.UI.main.set_custom_css=function(SESSION_ID,callbackP){const css=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system?.["SYS_GLOBAL_STR_SITE_CSS"];if(css){func.runtime.platform.inject_css(css)}callbackP()};func.index={};if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",function(){func.index.init_document_listeners();func.UI.utils.indicator.worker.normal();func.index.init_service_workers()})}else{setTimeout(function(){func.index.init_document_listeners();func.UI.utils.indicator.worker.normal();func.index.init_service_workers()},0)}function xuda(...args){const platform=func.runtime.platform;const runtime_location=platform.get_location();let element=null;let opt={};let callback=null;for(const arg of args){if(platform.is_html_element(arg)){element=arg}else if(typeof arg==="object"&&arg!==null&&!Array.isArray(arg)){opt=arg}else if(typeof arg==="function"){callback=arg}}if(!element){if(typeof glb.SLIM_BUNDLE==="undefined"||!glb.SLIM_BUNDLE){return console.error("Xuda Error - element argument is empty")}element="body";console.warn("root element set to body")}if(typeof element==="string"?!document.querySelector(element):!element){return console.error("Xuda Error - element not found")}if(typeof opt==="undefined"){return console.error("Xuda Error - opt argument is undefined")}if(typeof opt!=="object"){return console.error("Xuda Error - opt argument is not an object")}glb.URL_PARAMS=func.common.getJsonFromUrl(platform.get_url_href());glb.worker_type="Worker";if(opt.debug_js){glb.debug_js=true;if((runtime_location?.host?.includes("localhost")||runtime_location?.host?.includes("127.0.0.1"))&&typeof glb.SLIM_BUNDLE==="undefined"&&typeof glb.CODE_BUNDLE==="undefined"){glb.worker_type="Dev"}else{glb.worker_type="Debug"}}const call_xuda=async function(){const _instance_id=Date.now().toString()+Math.round(Math.random()*1e4).toString();const _api_callback=callback;const create_index_html=function(){func.runtime.ui.ensure_app_shell(SESSION_ID,_session.domain)};const device_ready=async function(){return new Promise(function(resolve,reject){if(!func.utils.get_device()){return resolve()}platform.get_document().addEventListener("deviceready",function(){glb.is_cordova=true;resolve()},false)})};const get_fingerprint_component=async function(){return new Promise(function(resolve,reject){Fingerprint2.get(function(components){resolve(components)})})};const get_session_id=function(){return func.runtime.session.get_fingerprint(components,_instance_id)};const get_fingerprint=function(){return func.runtime.session.get_fingerprint(components)};const init_SESSION=function(){return func.runtime.session.create_state(SESSION_ID,{opt:opt,root_element:typeof element==="string"?document.querySelector(element):element,worker_type:glb.worker_type,api_callback:_api_callback,code_bundle:glb.CODE_BUNDLE,slim_bundle:glb.SLIM_BUNDLE,url_params:opt.url_params})};const set_SESSION=async function(){for await(const key of["gtp_token","app_token","prog_id","domain","engine_mode","crawler","app_id","route_id","menu_id","local_live_preview","project_data"]){_session[key]=func.UI.utils.get_url_attribute(SESSION_ID,key);if(!_session[key]){func.runtime.session.set_default_value(_session,key)}switch(key){case"domain":if(_session[key].includes("localhost")||_session[key].includes("127.0.0.1")){const getSubdomain=url=>{let domain=url;if(url.includes("://")){domain=url.split("://")[1]}let subdomain="";if(!_session[key].includes("127.0.0.1")){subdomain=domain.split(".")[0]}return subdomain};_session[key]=getSubdomain(_session[key])?getSubdomain(_session[key])+".xuda.ai":"xuda.ai"}break;case"project_data":{if(typeof glb.SLIM_BUNDLE!=="undefined"||glb.SLIM_BUNDLE){const{root_element}=_session;if(!_session[key]){_session[key]={}}if(!_session[key].programs){_session[key].programs={}}if(!_session[key].globals){_session[key].globals={_id:"globals",progDataSource:{},properties:{menuType:"globals"},studio_meta:{},progEvents:[],progFields:[]}}const _templates=document.querySelectorAll("template");if(_templates.length){const module=await func.common.get_module(SESSION_ID,"xuda-cli-plugin-html-parser-module.esm.mjs");_templates.forEach(function(el,idx){const _id=el.getAttribute("id")||"template_"+idx.toString();if(!_session[key].programs[_id]){_session[key].programs[_id]={_id:_id,progDataSource:{},properties:{menuType:"component",renderType:"form"},studio_meta:{},progEvents:[],progFields:[]}}if(el.innerHTML){window.xudaStringify=module.xudaStringify;const progUi=module.xudaPrase(el.innerHTML);_session[key].programs[_id].progUi=progUi?.[0]?.children||[]}});if(!_session.prog_id){_session.prog_id=_templates[0]?.getAttribute("id")||"template_0"}root_element.innerHTML=""}}break}default:break}}_session.crawler=opt.crawler};const set_SYS_GLOBAL_OBJ_CLIENT_INFO=function(){func.runtime.session.populate_client_info(_session,components)};const init_globals=function(){const{app_id,worker_type}=_session;if(worker_type!=="Worker"){glb.DEBUG_MODE=true}SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal=-1;PROJECT_OBJ[app_id]={};DOCS_OBJ[app_id]={};glb.APP_INFO[app_id]={};glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes(SESSION_ID);DATASOURCE_INTERVALS[SESSION_ID]={}};const print_version_info=function(){const version_name=`Xuda.ai ${opt.engine_mode} ${opt?.app_version||""} Session Id: ${SESSION_ID}`;const divider="#".repeat(version_name.length);console.info(divider);console.info(version_name);console.info(divider)};const print_xuda_banner=function(){var banner="";["__ ___ _ ____ _ ","\\ \\/ / | | | _ \\ / \\ "," \\ /| | | | | | |/ _ \\ "," / \\| |_| | |_| / ___ \\ ","/_/\\_\\\\___/|____/_/ \\_\\"].forEach(e=>{banner+=e+"\r\n"});console.info(banner)};print_xuda_banner();await func.index.checkConnectivity();var SESSION_ID=Date.now();var components;if(typeof glb.SLIM_BUNDLE==="undefined"||!glb.SLIM_BUNDLE){await device_ready();components=await get_fingerprint_component();SESSION_ID=get_session_id();print_version_info()}var _session=init_SESSION();await set_SESSION();create_index_html();APP_OBJ[_session.app_id]={};init_globals();if(typeof glb.SLIM_BUNDLE!=="undefined"&&glb.SLIM_BUNDLE){await func.UI.main.embed_loader(SESSION_ID);return}set_SYS_GLOBAL_OBJ_CLIENT_INFO(SESSION_ID);if(!_session.app_id){func.UI.utils.progressScreen.show(SESSION_ID,"Error reading app_id",false,true);console.error("no app_id found");return}const module=await func.common.get_module(SESSION_ID,"xuda-project-loader-module.esm.js");const db_adapter=await func.common.get_module(SESSION_ID,"xuda-db-adapter-module.mjs");func.db=db_adapter._db;await module.project_loader(SESSION_ID,_session.app_id);func.db.pouch.init_db_replication(SESSION_ID)};glb.system_ready_event=new Event("on_mounted");call_xuda();return{on_mounted:function(fn){document.body.addEventListener("on_mounted",e=>{fn()},false)}}}func.index.call_worker=async function(SESSION_ID,obj,params,promiseP){var _session=SESSION_OBJ[SESSION_ID];if(_session.opt.app_computing_mode==="main"){return}return new Promise(async function(resolve,reject){var worker_id;const set_promise_queue=function(worker_id){var t=glb.worker_queue_num++;try{func.runtime.workers.set_promise(SESSION_ID,worker_id,t,{resolve:promiseP?promiseP.resolve:resolve,reject:promiseP?promiseP.reject:reject,worker_id:worker_id})}catch(e){console.log(worker_id)}return t};const get_worker_id=function(ds){if(!_session.DS_GLB[ds]){if(ds==0){console.error("Error - onscreen (window,modal etc..) event cannot be invoked by on_load");return}else{return}}if(ds==0){return 1}if(_session.DS_GLB[ds].worker_id){return _session.DS_GLB[ds].worker_id}else{if(typeof _session.DS_GLB[ds].parentDataSourceNo!=="undefined"){return get_worker_id(_session.DS_GLB[ds].parentDataSourceNo)}}};if(obj.service==="datasource_create"){if(!params||params&&!params.done){var prog_obj=await func.utils.TREE_OBJ.get(SESSION_ID,obj.data.prog_id);if(!prog_obj||!prog_obj.dedicatedWorker){if(!Object.keys(WEB_WORKER[SESSION_ID]).length){worker_id=await func.index.new_webworker(SESSION_ID,{menuName:"Main"},obj)}else{if(obj.data.IS_DATASOURCE_REFRESH){worker_id=get_worker_id(obj.data.parentDataSourceNo)}else{worker_id=get_worker_id(obj.data.parentDataSourceNoP)}if(!worker_id){debugger}}}else{if(obj.data.IS_DATASOURCE_REFRESH){worker_id=get_worker_id(obj.data.parentDataSourceNo)}else{worker_id=await func.index.new_webworker(SESSION,prog_obj,obj);return _resolve()}}}else{worker_id=params.worker_id}}else{if(params&¶ms.worker_id){worker_id=params.worker_id}else{worker_id=get_worker_id(obj.data.dssession)}if(!worker_id)worker_id=1}try{var msg=obj;msg.worker_id=worker_id;if(!worker_id){console.warn("missing worker_id")}msg.promise_queue_id=set_promise_queue(worker_id);if(!WEB_WORKER[SESSION_ID][worker_id]){return resolve()}msg=JSON.stringify(obj,func.utils.clean_stringify_null,"\t");let msg_obj=JSON.parse(msg);if(!func.runtime.workers.is_server_transport(_session)){msg_obj.data=JSON.stringify(msg_obj.data)}func.runtime.workers.send_message(SESSION_ID,worker_id,_session,msg_obj,WEBSOCKET_PROCESS_PID)}catch(e){console.error(e);return reject(e)}})};func.index.init_SCREEN_BLOCKER=async function(SESSION_ID){const get_loader=async function(){if(func.runtime.session.is_slim(SESSION_ID)||typeof UI_FRAMEWORK_PLUGIN?.loader!=="function"){return{dismiss:function(){}}}return await UI_FRAMEWORK_PLUGIN.loader(LOADER_TEXT)};setInterval(async function(){if(glb.CURRENT_APP_LOADING||!LOADER_ACTIVE&&xu_isEmpty(SCREEN_BLOCKER_OBJ)){return}glb.CURRENT_APP_LOADING=1;const loader=await get_loader();glb.CURRENT_APP_LOADING=loader;var interval=setInterval(function(){if(xu_isEmpty(SCREEN_BLOCKER_OBJ)&&!LOADER_ACTIVE){if(glb.CURRENT_APP_LOADING){glb.CURRENT_APP_LOADING.dismiss()}clearInterval(interval);glb.CURRENT_APP_LOADING=null}},100)},1e3)};func.index.init_document_listeners=function(){const platform=func.runtime.platform;document.addEventListener("keydown",function(event){CLIENT_ACTIVITY_TS=Date.now();var keys={72:{key:"h",name:"Help",fx:function(){let SESSION_ID=Object.keys(SESSION_OBJ)[0];let _session=SESSION_OBJ[SESSION_ID];let app_id=_session.app_id;if(!_session.opt.enable_utility_screen)return;func.UI.utils.progressScreen.show(SESSION_ID,`
|
|
73
73
|
<center>Utility Screen</center>
|
|
74
74
|
<div class="help_screen">
|
|
75
75
|
<button name="hard_reload">
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
${refIdP.value}
|
|
3
3
|
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,null,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},execute_evaluate_javascript:async function(){const module=await func.common.get_module(SESSION_ID,"xuda-event-javascript-module.mjs");const result=await module.run_javascript(SESSION_ID,jobNoP,dsSession,`(async function(el,evt) {
|
|
4
4
|
${refIdP.value}
|
|
5
|
-
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,true,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},loader_on:async function(){glb.CURRENT_APP_LOADING=null;LOADER_ACTIVE=true;LOADER_TEXT=descP;func.events.delete_job(SESSION_ID,jobNoP)},loader_off:async function(){LOADER_ACTIVE=false;func.events.delete_job(SESSION_ID,jobNoP)},emit_event:async function(){if(refIdP.value){func.runtime.platform.emit(refIdP.value,[_session.DS_GLB[dsSession]])}else{func.utils.debug_report(SESSION_ID,"func.events.execute","Event name missing","E")}func.events.delete_job(SESSION_ID,jobNoP)},invoke_action:async function(){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,null,expCond);await func.action.execute(SESSION_ID,refIdP.value,_ds,null,null,jobNoP,containerP)},raise_event:async function(){var _ds=_session.DS_GLB[dsSession];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(callingSourceP==="grid"||callingSourceP==="form"){let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",field_elm);var event_name=_field_obj?.workflow?.[eventIdP].name.event;if(_field_obj?.workflow?.[eventIdP].name?.properties["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,props[`xu-exp:event`],dsSession,"event_name expression")).result}if(field_elm&&event_name){const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);return await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,null,calling_trigger_prop?.data?.name?.parameters||{})}}if(callingSourceP.includes("event")){let event_name=refIdP.event;if(refIdP?.properties?.["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,refIdP.properties["xu-exp:event"],dsSession,"event_name expression")).result}const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,calling_trigger_prop?.props?.async,calling_trigger_prop?.data?.name?.parameters||{})}func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond)},get_data:async function(){const params_obj=await get_params_obj();if(!await get_prog_id()){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}var _ds=_session.DS_GLB[dsSession];if(!_ds){func.events.delete_job(SESSION_ID,jobNoP);return}if(_ds){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,calling_trigger_prop,expCond);const ret=await func.datasource.create(SESSION_ID,await get_prog_id(),args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,null,null,args.callingSourceP,args.calling_jobP,args.screen_dsP,args.is_panelP,params_obj);let _ds_new=_session.DS_GLB[ret.dsSessionP];let parameters=args?.calling_trigger_prop?.data?.name?.parameters;if(parameters&&!xu_isEmpty(parameters)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds_new.dsSession,_ds.dsSession)}func.events.delete_job(SESSION_ID,jobNoP);return _ds_new}},set_data:async function(){return this.get_data()},batch:async function(){const result=await this.get_data();return result},update:async function(){const obj_values_to_update=func.datasource.get_viewFields_for_update_function(SESSION_ID,calling_trigger_prop,null,dsSessionP);if(!obj_values_to_update||xu_isEmpty(obj_values_to_update)){func.utils.debug_report(SESSION_ID,"Update values object is empty","","W");if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);return}var updates=[];for await(const[key,val]of Object.entries(obj_values_to_update)){var $element;var iterate_info=null;if(elementP){const element_meta=func.runtime.ui.get_meta(elementP,"xuData");iterate_info=element_meta?.iterate_info||null}let ret_field_id=await func.expression.get(SESSION_ID,val.id.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let _field_id=ret_field_id.result;let _value=ret_value.result;updates.push({_field_id:_field_id,_value:_value})}let datasource_changes={};for await(const change of updates){let ret_get_value=await func.datasource.get_value(SESSION_ID,change._field_id,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][change._field_id]=change._value}}await func.datasource.update(SESSION_ID,datasource_changes,null,null,triggerP);if(_ds.PARAM_OUT_INFO){for await(const[key,val]of Object.entries(_ds.PARAM_OUT_INFO)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds.dsSession,val.parentDataSourceNo)}}if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"call_alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},delay:async function(){return new Promise(resolve=>{setTimeout(function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);resolve()},refIdP.value)})},comment:async function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_project_api:async function(){const params_obj=await get_params_obj();const _prog_id=await get_prog_id();if(!_prog_id){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const api_ret=await func.api.call_project_api(_prog_id,params_obj);await func.datasource.set_outputField(SESSION_ID,dsSessionP,api_ret,args);func.events.delete_job(SESSION_ID,jobNoP)},call_system_api:async function(){const api_method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"api_method");if(!api_method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > api_method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}let payload={};const _payload=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");if(_payload){const get_payload_property_value=async function(prop_name){let _prop=_payload;let _value=_prop[prop_name];if(_prop?.[`xu-exp:${prop_name}`]){_value=(await func.expression.get(SESSION_ID,_prop[`xu-exp:${prop_name}`],dsSession,`${prop_name} expression`)).result}return _value};for await(let[key,val]of Object.entries(_payload)){const new_key=key.replaceAll("xu-exp:","");payload[new_key]=await get_payload_property_value(new_key)}}const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_system_api(api_method,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)},call_external_api:async function(){const method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"method");if(!method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const url=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"url");if(!url){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > url not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const payload_arr=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");const report_conversion_error=function(res,typeP,valP){var msg=`${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;if(error){return func.utils.debug_report(SESSION_ID,msg,"","W")}func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","E")};const report_conversion_warn=function(res){var msg=`${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","W")};if(error){return report_conversion_error()}const module=await func.common.get_module(SESSION_ID,"xuda-get-cast-util-module.mjs");var payload=payload_arr.reduce((ret,val,key)=>{ret[val.key]=module.cast(val.type,val.val,report_conversion_error,report_conversion_warn);return ret},{});const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_external_api(method,url,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)}};return await fx[functionP]()};func.events.delete_job=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSessionP;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.delete_job_0=function(SESSION_ID){var job_index=0;var _session=SESSION_OBJ[SESSION_ID];if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSession;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj&&ds_obj.loops_limit&&ds_obj.loops_count<ds_obj.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.check_jobs_idle=async function(SESSION_ID,jobsP){return new Promise((resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(!jobsP||jobsP&&jobsP.length===0){resolve();return}var listener=setInterval(function(){var found;for(const[key,val]of Object.entries(jobsP)){for(const[key2,val2]of Object.entries(_session.WORKER_OBJ.jobs)){if(key2===val){found=true;break}}}if(!found){do_callback();return}},100);var do_callback=function(){clearInterval(listener);resolve()}})};var loop_detected_obj={};setInterval(function(){loop_detected_obj={}},1e3);func.events.set_browser_changes=function(dsP,fieldsChangedP){if(fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))func.runtime.platform.set_title(dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"])};func.events.execute_PENDING_OPEN_URL_EVENTS=async function(){for(let[key,url]of Object.entries(PENDING_OPEN_URL_EVENTS)){if(url){glb.WINDOW_LOCATION_SEARCH=url;glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes();const params_obj=func.common.getObjectFromUrl(url,glb.ROOT_ELEMENT_ATTRIBUTES);if(!params_obj.prog){return console.warn("prog empty")}await func.utils.TREE_OBJ.get(SESSION_ID,params_obj.prog);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,params_obj.prog);if(screen_ret){await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:params_obj.prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:null,source_functionP:"pendingUrlEvent_embed"})}else{console.error("Program not exist",params_obj.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}}else{console.warn("url empty")}}};func.events.invoke=async function(event_id){var _session=SESSION_OBJ[SESSION_ID];if(!event_id){console.warn("event_id Cannot be empty");return false}var ds;for await(const[ds_key,val]of Object.entries(_session.DS_GLB)){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,val.prog_id);if(xu_isEmpty(_view_obj.progEvents))continue;if(ds)break;for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val?.data?.type==="user_defined"&&val.data.event_name===event_id){ds=ds_key;break}}}if(!ds){console.warn("event_id not found");return false}func.events.validate(SESSION_ID,"user_defined",ds,event_id)};func.expression={};func.expression.get=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP,debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){class xu_class{async get(){if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=true}var ret;var fields={};var error;var warning;function evalJson(text){return eval("("+text+")")}if(valP===null){ret=""}else{switch(typeof valP){case"string":ret=valP;break;case"undefined":ret="";break;case"boolean":ret=valP?"Y":"N";break;default:ret=valP.toString();break}}if(ret.includes("&"))ret=ret.replace(/\&/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const end_results=function(){const replace_quotes=function(ret){for(const[key,val]of Object.entries(fields)){if(typeof val==="string")ret=ret.replace('"'+val+'"',val.replace(/"/gi,""))}return ret};if(["update","javascript"].includes(sourceP)){if(typeof ret==="string")ret=replace_quotes(ret)}const log_error=function(){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}};if(error)log_error();if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=false}const results={result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found};return results};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.startsWith("_DATE_")){ret=ret.slice(6)}else if(ret==="self"||ret&&ret.length===10&&ret[4]==="-"&&ret[7]==="-"){}else{ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}return end_results()}else{ret=ret.replace(/_NULL/gi,"");return end_results()}}catch(err){return end_results()}};if(!func.expression.validate_variables(valP)){return await variable_not_exist()}const validate_email=async function(){const ret=await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback,null,true);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const split=func.expression.parse(ret)||[];const split_entries=Object.entries(split);for(let entry_i=0;entry_i<split_entries.length;entry_i++){const[arr_key,val]=split_entries[entry_i];const key=Number(arr_key);var_Arr[key]={};var_Arr[key].value=val.value;const replace_value_in_string=async function(retP,fieldIdP){if(iterate_info?.iterator_key===fieldIdP||iterate_info?.iterator_val===fieldIdP){if(iterate_info.iterator_key===fieldIdP){retP.value=iterate_info._key}if(iterate_info.iterator_val===fieldIdP){retP.value=iterate_info._val}}const set_value=function(valP){if(typeof valP!=="undefined"){var_Arr[key].value=valP;if(typeof valP==="string")var_Arr[key].type="string"}else{if(retP.type==="object"){var_Arr[key].value="";var_Arr[key].type="string"}}};if(sourceP==="exp"&&retP.type!=="exp"){var_Arr[key].type=retP.type;return}if(typeof retP.value!=="undefined"){var_Arr[key].type=retP.type;var_Arr[key].value=typeof retP.value==="string"&&!retP.value.includes("<svg xmlns=")&&retP.value.indexOf("\\")===-1&&!["UI Attr EXP","update"].includes(sourceP)?retP.value.replaceAll('"','\\"'):retP.value;if(val.value.indexOf("[")>-1|val.value.indexOf(".")>-1){var data=retP.prop;if(retP.type==="object")data=retP.value;var property1,property2;if(val.value.indexOf("[")===-1&&val.value.indexOf("]")>-1&&val.value.substr(0,1)==="@"){var prevData=var_Arr[key-1].value;var_Arr[key].value=prevData[data];if(val.value.indexOf(".")>-1){const props_split=await func.expression.get_property(val.value);property2=props_split.property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{const props=await func.expression.get_property(val.value);property1=props.property1;property2=props.property2;if(property1){var_Arr[key].value=data[property1];if(property2){if(data[property1])set_value(data[property1][property2])}}if(property2&&!property1){if(data){set_value(data[property2])}}}fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}else{fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}}};if(val.fieldId){if(val.fieldId&&val.fieldId.substr(0,5)==="_THIS"&&calling_fieldIdP&&(val.fieldId.length===5||val.fieldId.length>5&&val.fieldId.substr(5,1)===".")){if(val.fieldId.length===5)val.fieldId=calling_fieldIdP;else val.fieldId=calling_fieldIdP+val.fieldId(5,val.fieldId.length-1)}if(!sourceP==="exp"){var_Arr[key].value='""'}fields[val.fieldId]=var_Arr[key].value;const ret=await func.datasource.get_value(SESSION_ID,val.fieldId,dsSessionP,rowIdP);await replace_value_in_string(ret.ret,ret.fieldIdP)}}try{var res=[];var exp_exist;var var_error_found;var_Arr.forEach(function(val,key){if(sourceP==="UI Property EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,true);if(ret.changed){res[key]=ret.value;return true}}if(sourceP==="UI Attr EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,var_Arr.length==1?false:true);if(ret.changed){res[key]=ret.value;return true}}if(val.type==="exp"){exp_exist=true}res[key]=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){res[key]="`"+val.value+"`"}if(["api_rendered_output"].includes(sourceP)&&["json"].includes(api_output_type)&&["string","date"].includes(val.type)){res[key]=`"`+val.value+`"`}}if(val.fieldId&&val.value&&typeof val.value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP)){if(val.value.indexOf("↵")>-1){res[key]=val.value.split("↵").join("")}res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"")}if(["init","update","virtual"].includes(sourceP)){if(val.value.indexOf("↵")>-1)res[key]=val.value.split("↵").join("\n");res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"\\n")}if(typeof IS_PROCESS_SERVER!=="undefined"){res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"<br>")}fields[val.fieldId]=res[key]}if(typeof val.value==="object"&&var_Arr.length>1){if(!Array.isArray(val.value)&&!var_Arr[key+1].value?.includes(".")){res[key]="("+JSON.stringify(val.value)+")"}else{res[key]=JSON.stringify(val.value)}}if(!exp_exist&&sourceP!=="exp"&&val.value&&typeof val.value==="string"&&val.value.substr(0,1)==="@"){warning="Error encoding "+val.value;var_error_found=true;res[key]=0}});const join=function(arrP){return arrP.join("")};var exp=undefined;if(exp_exist&&sourceP!=="exp"){exp=await func.expression.get(SESSION_ID,join(res),dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);if(exp.res)res=exp.res;else res=[exp.result];fields=Object.assign(exp.fields,fieldsP)}var result=join(res);if(res.length===1){result=res[0]}if(secondPassP){ret=result}else if(sourceP!=="exp"){if(res.length===1&&typeof res[0]==="string"&&typeof res[0]!=="object"){ret=join(res);if(ret&&ret.substr(0,1)==="@"){error="Error encoding @ var";var_error_found=true}}else{if(!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,result,jobNo,dsSessionP,js_script_callback)}else{if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(result))}else{ret=result}}}}return end_results()}catch(err){ret=result;error=err.message;return end_results()}}}const new_class=new xu_class;return new_class.get()};func.expression._parse_cache=new Map;func.expression.parse=function(input){if(typeof input!=="string")return[];if(func.expression._parse_cache.has(input)){return func.expression._parse_cache.get(input).map(function(s){return Object.assign({},s)})}const segments=[];let pos=0;const parts=input.split(/(@\w+)/).filter(Boolean);for(const part of parts){if(part.startsWith("@")){const fieldId=part.slice(1);segments.push({value:part,fieldId:fieldId,pos:pos})}else{segments.push({value:part,pos:pos})}pos+=part.length}if(func.expression._parse_cache.size>=500){const firstKey=func.expression._parse_cache.keys().next().value;func.expression._parse_cache.delete(firstKey)}func.expression._parse_cache.set(input,segments);return segments.map(function(s){return Object.assign({},s)})};func.expression.get_property=async function(valP){async function secure_eval(val){if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(val)}catch(err){console.error(err);return}}try{let vm=new VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(val)}catch(err){throw""}}var property1,property2;if(valP.indexOf("[")>-1&&valP.indexOf("]")>-1){property1=valP.substr(valP.indexOf("[")+1,valP.indexOf("]")-valP.indexOf("[")-1);property1=await secure_eval(property1)}if(valP.indexOf(".")>-1)property2=valP.substr(valP.indexOf(".")+1,valP.length);return{property1:property1,property2:property2}};func.expression.validate_constant=function(valP){var patt=/["']/;if(typeof valP==="string"&&patt.test(valP.substr(0,1))&&patt.test(valP.substr(0,valP.length-1)))return true;else return false};func.expression.validate_variables=function(valP){if(typeof valP==="string"&&valP.indexOf("@")>-1)return true;else return false};func.expression.remove_quotes=function(valP){if(func.expression.validate_constant(valP))return valP.substr(1,valP.length-2);else return valP};func.expression.secure_eval=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt,ignore_errors){if(typeof val!=="string")return val;const xu=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const isServer=typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined";if(!isServer){try{return eval(val)}catch(err){try{if(sourceP==="javascript"&&!ignore_errors)console.error(err);return JSON5.parse(val)}catch(err){if(sourceP==="javascript"&&!ignore_errors)console.error(err);return val}}}const sandbox={func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,...sourceP==="javascript"?{axios:axios,got:got,FormData:FormData}:{}};const handleError=err=>{console.error("Execution error:",err);func.events.delete_job(SESSION_ID,job_id);if(isServer&&!SESSION_OBJ[SESSION_ID].crawler){if(sourceP==="javascript"){__.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}else{__.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}return val};if(sourceP==="javascript"){process.on("uncaughtException",handleError);try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules");const script=new VMScript(`try { ${val} } catch (e) { func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, "${job_id}"); }`,{filename:dir,dirname:dir});const vm=new NodeVM({require:{external:true},sandbox:sandbox,timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){return handleError(err)}}try{const vm=new VM({sandbox:sandbox,timeout:1e3,allowAsync:false});return await vm.run(val)}catch{try{return JSON5.parse(val)}catch{return val}}}; export default {
|
|
5
|
+
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,true,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},loader_on:async function(){glb.CURRENT_APP_LOADING=null;LOADER_ACTIVE=true;LOADER_TEXT=descP;func.events.delete_job(SESSION_ID,jobNoP)},loader_off:async function(){LOADER_ACTIVE=false;func.events.delete_job(SESSION_ID,jobNoP)},emit_event:async function(){if(refIdP.value){func.runtime.platform.emit(refIdP.value,[_session.DS_GLB[dsSession]])}else{func.utils.debug_report(SESSION_ID,"func.events.execute","Event name missing","E")}func.events.delete_job(SESSION_ID,jobNoP)},invoke_action:async function(){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,null,expCond);await func.action.execute(SESSION_ID,refIdP.value,_ds,null,null,jobNoP,containerP)},raise_event:async function(){var _ds=_session.DS_GLB[dsSession];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(callingSourceP==="grid"||callingSourceP==="form"){let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",field_elm);var event_name=_field_obj?.workflow?.[eventIdP].name.event;if(_field_obj?.workflow?.[eventIdP].name?.properties["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,props[`xu-exp:event`],dsSession,"event_name expression")).result}if(field_elm&&event_name){const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);return await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,null,calling_trigger_prop?.data?.name?.parameters||{})}}if(callingSourceP.includes("event")){let event_name=refIdP.event;if(refIdP?.properties?.["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,refIdP.properties["xu-exp:event"],dsSession,"event_name expression")).result}const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,calling_trigger_prop?.props?.async,calling_trigger_prop?.data?.name?.parameters||{})}func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond)},get_data:async function(){const params_obj=await get_params_obj();if(!await get_prog_id()){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}var _ds=_session.DS_GLB[dsSession];if(!_ds){func.events.delete_job(SESSION_ID,jobNoP);return}if(_ds){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,calling_trigger_prop,expCond);const ret=await func.datasource.create(SESSION_ID,await get_prog_id(),args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,null,null,args.callingSourceP,args.calling_jobP,args.screen_dsP,args.is_panelP,params_obj);let _ds_new=_session.DS_GLB[ret.dsSessionP];let parameters=args?.calling_trigger_prop?.data?.name?.parameters;if(parameters&&!xu_isEmpty(parameters)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds_new.dsSession,_ds.dsSession)}func.events.delete_job(SESSION_ID,jobNoP);return _ds_new}},set_data:async function(){return this.get_data()},batch:async function(){const result=await this.get_data();return result},update:async function(){const obj_values_to_update=func.datasource.get_viewFields_for_update_function(SESSION_ID,calling_trigger_prop,null,dsSessionP);if(!obj_values_to_update||xu_isEmpty(obj_values_to_update)){func.utils.debug_report(SESSION_ID,"Update values object is empty","","W");if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);return}var updates=[];for await(const[key,val]of Object.entries(obj_values_to_update)){var $element;var iterate_info=null;if(elementP){const element_meta=func.runtime.ui.get_meta(elementP,"xuData");iterate_info=element_meta?.iterate_info||null}let ret_field_id=await func.expression.get(SESSION_ID,val.id.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let _field_id=ret_field_id.result;let _value=ret_value.result;updates.push({_field_id:_field_id,_value:_value})}let datasource_changes={};for await(const change of updates){let ret_get_value=await func.datasource.get_value(SESSION_ID,change._field_id,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][change._field_id]=change._value}}await func.datasource.update(SESSION_ID,datasource_changes,null,null,triggerP);if(_ds.PARAM_OUT_INFO){for await(const[key,val]of Object.entries(_ds.PARAM_OUT_INFO)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds.dsSession,val.parentDataSourceNo)}}if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"call_alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},delay:async function(){return new Promise(resolve=>{setTimeout(function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);resolve()},refIdP.value)})},comment:async function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_project_api:async function(){const params_obj=await get_params_obj();const _prog_id=await get_prog_id();if(!_prog_id){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const api_ret=await func.api.call_project_api(_prog_id,params_obj);await func.datasource.set_outputField(SESSION_ID,dsSessionP,api_ret,args);func.events.delete_job(SESSION_ID,jobNoP)},call_system_api:async function(){const api_method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"api_method");if(!api_method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > api_method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}let payload={};const _payload=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");if(_payload){const get_payload_property_value=async function(prop_name){let _prop=_payload;let _value=_prop[prop_name];if(_prop?.[`xu-exp:${prop_name}`]){_value=(await func.expression.get(SESSION_ID,_prop[`xu-exp:${prop_name}`],dsSession,`${prop_name} expression`)).result}return _value};for await(let[key,val]of Object.entries(_payload)){const new_key=key.replaceAll("xu-exp:","");payload[new_key]=await get_payload_property_value(new_key)}}const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_system_api(api_method,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)},call_external_api:async function(){const method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"method");if(!method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const url=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"url");if(!url){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > url not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const payload_arr=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");const report_conversion_error=function(res,typeP,valP){var msg=`${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;if(error){return func.utils.debug_report(SESSION_ID,msg,"","W")}func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","E")};const report_conversion_warn=function(res){var msg=`${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","W")};if(error){return report_conversion_error()}const module=await func.common.get_module(SESSION_ID,"xuda-get-cast-util-module.mjs");var payload=payload_arr.reduce((ret,val,key)=>{ret[val.key]=module.cast(val.type,val.val,report_conversion_error,report_conversion_warn);return ret},{});const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_external_api(method,url,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)}};return await fx[functionP]()};func.events.delete_job=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSessionP;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.delete_job_0=function(SESSION_ID){var job_index=0;var _session=SESSION_OBJ[SESSION_ID];if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSession;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj&&ds_obj.loops_limit&&ds_obj.loops_count<ds_obj.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.check_jobs_idle=async function(SESSION_ID,jobsP){return new Promise((resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(!jobsP||jobsP&&jobsP.length===0){resolve();return}var listener=setInterval(function(){var found;for(const[key,val]of Object.entries(jobsP)){for(const[key2,val2]of Object.entries(_session.WORKER_OBJ.jobs)){if(key2===val){found=true;break}}}if(!found){do_callback();return}},100);var do_callback=function(){clearInterval(listener);resolve()}})};var loop_detected_obj={};setInterval(function(){loop_detected_obj={}},1e3);func.events.set_browser_changes=function(dsP,fieldsChangedP){if(fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))func.runtime.platform.set_title(dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"])};func.events.execute_PENDING_OPEN_URL_EVENTS=async function(){for(let[key,url]of Object.entries(PENDING_OPEN_URL_EVENTS)){if(url){glb.WINDOW_LOCATION_SEARCH=url;glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes();const params_obj=func.common.getObjectFromUrl(url,glb.ROOT_ELEMENT_ATTRIBUTES);if(!params_obj.prog){return console.warn("prog empty")}await func.utils.TREE_OBJ.get(SESSION_ID,params_obj.prog);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,params_obj.prog);if(screen_ret){await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:params_obj.prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:null,source_functionP:"pendingUrlEvent_embed"})}else{console.error("Program not exist",params_obj.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}}else{console.warn("url empty")}}};func.events.invoke=async function(event_id){var _session=SESSION_OBJ[SESSION_ID];if(!event_id){console.warn("event_id Cannot be empty");return false}var ds;for await(const[ds_key,val]of Object.entries(_session.DS_GLB)){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,val.prog_id);if(xu_isEmpty(_view_obj.progEvents))continue;if(ds)break;for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val?.data?.type==="user_defined"&&val.data.event_name===event_id){ds=ds_key;break}}}if(!ds){console.warn("event_id not found");return false}func.events.validate(SESSION_ID,"user_defined",ds,event_id)};func.expression={};func.expression.get=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP,debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){class xu_class{async get(){if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=true}var ret;var fields={};var error;var warning;function evalJson(text){return eval("("+text+")")}if(valP===null){ret=""}else{switch(typeof valP){case"string":ret=valP;break;case"undefined":ret="";break;case"boolean":ret=valP?"Y":"N";break;default:ret=valP.toString();break}}if(ret.includes("&"))ret=ret.replace(/\&/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const end_results=function(){const replace_quotes=function(ret){for(const[key,val]of Object.entries(fields)){if(typeof val==="string")ret=ret.replace('"'+val+'"',val.replace(/"/gi,""))}return ret};if(["update","javascript"].includes(sourceP)){if(typeof ret==="string")ret=replace_quotes(ret)}const log_error=function(){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}};if(error)log_error();if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=false}const results={result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found};return results};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.startsWith("_DATE_")){ret=ret.slice(6)}else if(ret==="self"||ret&&ret.length===10&&ret[4]==="-"&&ret[7]==="-"){}else{ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}return end_results()}else{ret=ret.replace(/_NULL/gi,"");return end_results()}}catch(err){return end_results()}};if(!func.expression.validate_variables(valP)){return await variable_not_exist()}const validate_email=async function(){const ret=await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback,null,true);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const get_iterate_value_ret=function(fieldIdP){if(!iterate_info||iterate_info.iterator_key!==fieldIdP&&iterate_info.iterator_val!==fieldIdP){return null}const iter_value=iterate_info.iterator_key===fieldIdP?iterate_info._key:iterate_info._val;const iter_type=typeof iter_value!=="undefined"?{}.toString.call(iter_value).match(/\s([a-zA-Z]+)/)[1].toLowerCase():"string";return{ret:{value:iter_value,type:iter_type,prop:["array","object"].includes(iter_type)?iter_value:null},fieldIdP:fieldIdP,currentRecordId:rowIdP,found:typeof iter_value!=="undefined"}};const split=func.expression.parse(ret)||[];const split_entries=Object.entries(split);for(let entry_i=0;entry_i<split_entries.length;entry_i++){const[arr_key,val]=split_entries[entry_i];const key=Number(arr_key);var_Arr[key]={};var_Arr[key].value=val.value;const replace_value_in_string=async function(retP,fieldIdP){if(iterate_info?.iterator_key===fieldIdP||iterate_info?.iterator_val===fieldIdP){if(iterate_info.iterator_key===fieldIdP){retP.value=iterate_info._key}if(iterate_info.iterator_val===fieldIdP){retP.value=iterate_info._val}}const set_value=function(valP){if(typeof valP!=="undefined"){var_Arr[key].value=valP;if(typeof valP==="string")var_Arr[key].type="string"}else{if(retP.type==="object"){var_Arr[key].value="";var_Arr[key].type="string"}}};if(sourceP==="exp"&&retP.type!=="exp"){var_Arr[key].type=retP.type;return}if(typeof retP.value!=="undefined"){var_Arr[key].type=retP.type;var_Arr[key].value=typeof retP.value==="string"&&!retP.value.includes("<svg xmlns=")&&retP.value.indexOf("\\")===-1&&!["UI Attr EXP","update"].includes(sourceP)?retP.value.replaceAll('"','\\"'):retP.value;if(val.value.indexOf("[")>-1|val.value.indexOf(".")>-1){var data=retP.prop;if(retP.type==="object")data=retP.value;var property1,property2;if(val.value.indexOf("[")===-1&&val.value.indexOf("]")>-1&&val.value.substr(0,1)==="@"){var prevData=var_Arr[key-1].value;var_Arr[key].value=prevData[data];if(val.value.indexOf(".")>-1){const props_split=await func.expression.get_property(val.value);property2=props_split.property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{const props=await func.expression.get_property(val.value);property1=props.property1;property2=props.property2;if(property1){var_Arr[key].value=data[property1];if(property2){if(data[property1])set_value(data[property1][property2])}}if(property2&&!property1){if(data){set_value(data[property2])}}}fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}else{fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}}};if(val.fieldId){if(val.fieldId&&val.fieldId.substr(0,5)==="_THIS"&&calling_fieldIdP&&(val.fieldId.length===5||val.fieldId.length>5&&val.fieldId.substr(5,1)===".")){if(val.fieldId.length===5)val.fieldId=calling_fieldIdP;else val.fieldId=calling_fieldIdP+val.fieldId(5,val.fieldId.length-1)}if(!sourceP==="exp"){var_Arr[key].value='""'}fields[val.fieldId]=var_Arr[key].value;const ret=get_iterate_value_ret(val.fieldId)||await func.datasource.get_value(SESSION_ID,val.fieldId,dsSessionP,rowIdP);await replace_value_in_string(ret.ret,ret.fieldIdP)}}try{var res=[];var exp_exist;var var_error_found;var_Arr.forEach(function(val,key){if(sourceP==="UI Property EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,true);if(ret.changed){res[key]=ret.value;return true}}if(sourceP==="UI Attr EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,var_Arr.length==1?false:true);if(ret.changed){res[key]=ret.value;return true}}if(val.type==="exp"){exp_exist=true}res[key]=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){res[key]="`"+val.value+"`"}if(["api_rendered_output"].includes(sourceP)&&["json"].includes(api_output_type)&&["string","date"].includes(val.type)){res[key]=`"`+val.value+`"`}}if(val.fieldId&&val.value&&typeof val.value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP)){if(val.value.indexOf("↵")>-1){res[key]=val.value.split("↵").join("")}res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"")}if(["init","update","virtual"].includes(sourceP)){if(val.value.indexOf("↵")>-1)res[key]=val.value.split("↵").join("\n");res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"\\n")}if(typeof IS_PROCESS_SERVER!=="undefined"){res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"<br>")}fields[val.fieldId]=res[key]}if(typeof val.value==="object"&&var_Arr.length>1){if(!Array.isArray(val.value)&&!var_Arr[key+1].value?.includes(".")){res[key]="("+JSON.stringify(val.value)+")"}else{res[key]=JSON.stringify(val.value)}}if(!exp_exist&&sourceP!=="exp"&&val.value&&typeof val.value==="string"&&val.value.substr(0,1)==="@"){warning="Error encoding "+val.value;var_error_found=true;res[key]=0}});const join=function(arrP){return arrP.join("")};var exp=undefined;if(exp_exist&&sourceP!=="exp"){exp=await func.expression.get(SESSION_ID,join(res),dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);if(exp.res)res=exp.res;else res=[exp.result];fields=Object.assign(exp.fields,fieldsP)}var result=join(res);if(res.length===1){result=res[0]}if(secondPassP){ret=result}else if(sourceP!=="exp"){if(res.length===1&&typeof res[0]==="string"&&typeof res[0]!=="object"){ret=join(res);if(ret&&ret.substr(0,1)==="@"){error="Error encoding @ var";var_error_found=true}}else{if(!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,result,jobNo,dsSessionP,js_script_callback)}else{if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(result))}else{ret=result}}}}return end_results()}catch(err){ret=result;error=err.message;return end_results()}}}const new_class=new xu_class;return new_class.get()};func.expression._parse_cache=new Map;func.expression.parse=function(input){if(typeof input!=="string")return[];if(func.expression._parse_cache.has(input)){return func.expression._parse_cache.get(input).map(function(s){return Object.assign({},s)})}const segments=[];let pos=0;const parts=input.split(/(@\w+)/).filter(Boolean);for(const part of parts){if(part.startsWith("@")){const fieldId=part.slice(1);segments.push({value:part,fieldId:fieldId,pos:pos})}else{segments.push({value:part,pos:pos})}pos+=part.length}if(func.expression._parse_cache.size>=500){const firstKey=func.expression._parse_cache.keys().next().value;func.expression._parse_cache.delete(firstKey)}func.expression._parse_cache.set(input,segments);return segments.map(function(s){return Object.assign({},s)})};func.expression.get_property=async function(valP){async function secure_eval(val){if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(val)}catch(err){console.error(err);return}}try{let vm=new VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(val)}catch(err){throw""}}var property1,property2;if(valP.indexOf("[")>-1&&valP.indexOf("]")>-1){property1=valP.substr(valP.indexOf("[")+1,valP.indexOf("]")-valP.indexOf("[")-1);property1=await secure_eval(property1)}if(valP.indexOf(".")>-1)property2=valP.substr(valP.indexOf(".")+1,valP.length);return{property1:property1,property2:property2}};func.expression.validate_constant=function(valP){var patt=/["']/;if(typeof valP==="string"&&patt.test(valP.substr(0,1))&&patt.test(valP.substr(0,valP.length-1)))return true;else return false};func.expression.validate_variables=function(valP){if(typeof valP==="string"&&valP.indexOf("@")>-1)return true;else return false};func.expression.remove_quotes=function(valP){if(func.expression.validate_constant(valP))return valP.substr(1,valP.length-2);else return valP};func.expression.secure_eval=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt,ignore_errors){if(typeof val!=="string")return val;const xu=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const isServer=typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined";if(!isServer){try{return eval(val)}catch(err){try{if(sourceP==="javascript"&&!ignore_errors)console.error(err);return JSON5.parse(val)}catch(err){if(sourceP==="javascript"&&!ignore_errors)console.error(err);return val}}}const sandbox={func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,...sourceP==="javascript"?{axios:axios,got:got,FormData:FormData}:{}};const handleError=err=>{console.error("Execution error:",err);func.events.delete_job(SESSION_ID,job_id);if(isServer&&!SESSION_OBJ[SESSION_ID].crawler){if(sourceP==="javascript"){__.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}else{__.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}return val};if(sourceP==="javascript"){process.on("uncaughtException",handleError);try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules");const script=new VMScript(`try { ${val} } catch (e) { func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, "${job_id}"); }`,{filename:dir,dirname:dir});const vm=new NodeVM({require:{external:true},sandbox:sandbox,timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){return handleError(err)}}try{const vm=new VM({sandbox:sandbox,timeout:1e3,allowAsync:false});return await vm.run(val)}catch{try{return JSON5.parse(val)}catch{return val}}}; export default {
|
|
6
6
|
glb,
|
|
7
7
|
func,
|
|
8
8
|
APP_OBJ,
|
|
@@ -9275,6 +9275,25 @@ func.expression.get = async function (SESSION_ID, valP, dsSessionP, sourceP, row
|
|
|
9275
9275
|
|
|
9276
9276
|
// var split = [];
|
|
9277
9277
|
var var_Arr = [];
|
|
9278
|
+
const get_iterate_value_ret = function (fieldIdP) {
|
|
9279
|
+
if (!iterate_info || (iterate_info.iterator_key !== fieldIdP && iterate_info.iterator_val !== fieldIdP)) {
|
|
9280
|
+
return null;
|
|
9281
|
+
}
|
|
9282
|
+
|
|
9283
|
+
const iter_value = iterate_info.iterator_key === fieldIdP ? iterate_info._key : iterate_info._val;
|
|
9284
|
+
const iter_type = typeof iter_value !== 'undefined' ? {}.toString.call(iter_value).match(/\s([a-zA-Z]+)/)[1].toLowerCase() : 'string';
|
|
9285
|
+
|
|
9286
|
+
return {
|
|
9287
|
+
ret: {
|
|
9288
|
+
value: iter_value,
|
|
9289
|
+
type: iter_type,
|
|
9290
|
+
prop: ['array', 'object'].includes(iter_type) ? iter_value : null,
|
|
9291
|
+
},
|
|
9292
|
+
fieldIdP,
|
|
9293
|
+
currentRecordId: rowIdP,
|
|
9294
|
+
found: typeof iter_value !== 'undefined',
|
|
9295
|
+
};
|
|
9296
|
+
};
|
|
9278
9297
|
const split = func.expression.parse(ret) || [];
|
|
9279
9298
|
// console.log(valP, split);
|
|
9280
9299
|
const split_entries = Object.entries(split);
|
|
@@ -9371,7 +9390,7 @@ func.expression.get = async function (SESSION_ID, valP, dsSessionP, sourceP, row
|
|
|
9371
9390
|
} // put default
|
|
9372
9391
|
fields[val.fieldId] = var_Arr[key].value;
|
|
9373
9392
|
|
|
9374
|
-
const ret = await func.datasource.get_value(SESSION_ID, val.fieldId, dsSessionP, rowIdP); // find field in dataSources
|
|
9393
|
+
const ret = get_iterate_value_ret(val.fieldId) || (await func.datasource.get_value(SESSION_ID, val.fieldId, dsSessionP, rowIdP)); // find field in dataSources
|
|
9375
9394
|
|
|
9376
9395
|
await replace_value_in_string(ret.ret, ret.fieldIdP);
|
|
9377
9396
|
}
|
package/js/xuda-worker-bundle.js
CHANGED
|
@@ -9275,6 +9275,25 @@ func.expression.get = async function (SESSION_ID, valP, dsSessionP, sourceP, row
|
|
|
9275
9275
|
|
|
9276
9276
|
// var split = [];
|
|
9277
9277
|
var var_Arr = [];
|
|
9278
|
+
const get_iterate_value_ret = function (fieldIdP) {
|
|
9279
|
+
if (!iterate_info || (iterate_info.iterator_key !== fieldIdP && iterate_info.iterator_val !== fieldIdP)) {
|
|
9280
|
+
return null;
|
|
9281
|
+
}
|
|
9282
|
+
|
|
9283
|
+
const iter_value = iterate_info.iterator_key === fieldIdP ? iterate_info._key : iterate_info._val;
|
|
9284
|
+
const iter_type = typeof iter_value !== 'undefined' ? {}.toString.call(iter_value).match(/\s([a-zA-Z]+)/)[1].toLowerCase() : 'string';
|
|
9285
|
+
|
|
9286
|
+
return {
|
|
9287
|
+
ret: {
|
|
9288
|
+
value: iter_value,
|
|
9289
|
+
type: iter_type,
|
|
9290
|
+
prop: ['array', 'object'].includes(iter_type) ? iter_value : null,
|
|
9291
|
+
},
|
|
9292
|
+
fieldIdP,
|
|
9293
|
+
currentRecordId: rowIdP,
|
|
9294
|
+
found: typeof iter_value !== 'undefined',
|
|
9295
|
+
};
|
|
9296
|
+
};
|
|
9278
9297
|
const split = func.expression.parse(ret) || [];
|
|
9279
9298
|
// console.log(valP, split);
|
|
9280
9299
|
const split_entries = Object.entries(split);
|
|
@@ -9371,7 +9390,7 @@ func.expression.get = async function (SESSION_ID, valP, dsSessionP, sourceP, row
|
|
|
9371
9390
|
} // put default
|
|
9372
9391
|
fields[val.fieldId] = var_Arr[key].value;
|
|
9373
9392
|
|
|
9374
|
-
const ret = await func.datasource.get_value(SESSION_ID, val.fieldId, dsSessionP, rowIdP); // find field in dataSources
|
|
9393
|
+
const ret = get_iterate_value_ret(val.fieldId) || (await func.datasource.get_value(SESSION_ID, val.fieldId, dsSessionP, rowIdP)); // find field in dataSources
|
|
9375
9394
|
|
|
9376
9395
|
await replace_value_in_string(ret.ret, ret.fieldIdP);
|
|
9377
9396
|
}
|