@xuda.io/runtime-bundle 1.0.488 → 1.0.489
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 +7 -34
- package/js/xuda-runtime-bundle.min.js +1 -1
- package/js/xuda-runtime-slim.js +7 -34
- package/js/xuda-runtime-slim.min.es.js +7 -34
- package/js/xuda-runtime-slim.min.js +1 -1
- package/js/xuda-server-bundle.min.mjs +1 -1
- package/js/xuda-server-bundle.mjs +7 -34
- package/js/xuda-worker-bundle.js +7 -34
- package/js/xuda-worker-bundle.min.js +1 -1
- package/package.json +1 -1
package/js/xuda-runtime-slim.js
CHANGED
|
@@ -10987,50 +10987,23 @@ func.expression.parse = function (input) {
|
|
|
10987
10987
|
const segments = [];
|
|
10988
10988
|
let pos = 0;
|
|
10989
10989
|
|
|
10990
|
-
const parts = input.split(/(
|
|
10990
|
+
const parts = input.split(/(@\w+)/).filter(Boolean);
|
|
10991
10991
|
|
|
10992
|
-
for (
|
|
10993
|
-
|
|
10994
|
-
|
|
10995
|
-
if (part === '@' && i + 1 < parts.length) {
|
|
10996
|
-
const nextPart = parts[i + 1];
|
|
10997
|
-
const varEnd = nextPart.search(/[.\[]/); // Split at first . or [
|
|
10998
|
-
let fieldId, remainder;
|
|
10999
|
-
|
|
11000
|
-
if (varEnd > 0) {
|
|
11001
|
-
fieldId = nextPart.slice(0, varEnd);
|
|
11002
|
-
remainder = nextPart.slice(varEnd);
|
|
11003
|
-
} else {
|
|
11004
|
-
fieldId = nextPart;
|
|
11005
|
-
remainder = '';
|
|
11006
|
-
}
|
|
11007
|
-
|
|
11008
|
-
// Add @variable segment
|
|
11009
|
-
const fullVarValue = `@${fieldId}`;
|
|
10992
|
+
for (const part of parts) {
|
|
10993
|
+
if (part.startsWith('@')) {
|
|
10994
|
+
const fieldId = part.slice(1);
|
|
11010
10995
|
segments.push({
|
|
11011
|
-
value:
|
|
10996
|
+
value: part,
|
|
11012
10997
|
fieldId,
|
|
11013
10998
|
pos,
|
|
11014
10999
|
});
|
|
11015
|
-
|
|
11016
|
-
|
|
11017
|
-
// Add remainder as a separate segment, if any
|
|
11018
|
-
if (remainder) {
|
|
11019
|
-
segments.push({
|
|
11020
|
-
value: remainder,
|
|
11021
|
-
pos,
|
|
11022
|
-
});
|
|
11023
|
-
pos += remainder.length;
|
|
11024
|
-
}
|
|
11025
|
-
|
|
11026
|
-
i++; // Skip the next part since we consumed it
|
|
11027
|
-
} else if (part !== '@') {
|
|
11000
|
+
} else {
|
|
11028
11001
|
segments.push({
|
|
11029
11002
|
value: part,
|
|
11030
11003
|
pos,
|
|
11031
11004
|
});
|
|
11032
|
-
pos += part.length;
|
|
11033
11005
|
}
|
|
11006
|
+
pos += part.length;
|
|
11034
11007
|
}
|
|
11035
11008
|
|
|
11036
11009
|
return segments;
|
|
@@ -14800,50 +14800,23 @@ func.expression.parse = function (input) {
|
|
|
14800
14800
|
const segments = [];
|
|
14801
14801
|
let pos = 0;
|
|
14802
14802
|
|
|
14803
|
-
const parts = input.split(/(
|
|
14803
|
+
const parts = input.split(/(@\w+)/).filter(Boolean);
|
|
14804
14804
|
|
|
14805
|
-
for (
|
|
14806
|
-
|
|
14807
|
-
|
|
14808
|
-
if (part === '@' && i + 1 < parts.length) {
|
|
14809
|
-
const nextPart = parts[i + 1];
|
|
14810
|
-
const varEnd = nextPart.search(/[.\[]/); // Split at first . or [
|
|
14811
|
-
let fieldId, remainder;
|
|
14812
|
-
|
|
14813
|
-
if (varEnd > 0) {
|
|
14814
|
-
fieldId = nextPart.slice(0, varEnd);
|
|
14815
|
-
remainder = nextPart.slice(varEnd);
|
|
14816
|
-
} else {
|
|
14817
|
-
fieldId = nextPart;
|
|
14818
|
-
remainder = '';
|
|
14819
|
-
}
|
|
14820
|
-
|
|
14821
|
-
// Add @variable segment
|
|
14822
|
-
const fullVarValue = `@${fieldId}`;
|
|
14805
|
+
for (const part of parts) {
|
|
14806
|
+
if (part.startsWith('@')) {
|
|
14807
|
+
const fieldId = part.slice(1);
|
|
14823
14808
|
segments.push({
|
|
14824
|
-
value:
|
|
14809
|
+
value: part,
|
|
14825
14810
|
fieldId,
|
|
14826
14811
|
pos,
|
|
14827
14812
|
});
|
|
14828
|
-
|
|
14829
|
-
|
|
14830
|
-
// Add remainder as a separate segment, if any
|
|
14831
|
-
if (remainder) {
|
|
14832
|
-
segments.push({
|
|
14833
|
-
value: remainder,
|
|
14834
|
-
pos,
|
|
14835
|
-
});
|
|
14836
|
-
pos += remainder.length;
|
|
14837
|
-
}
|
|
14838
|
-
|
|
14839
|
-
i++; // Skip the next part since we consumed it
|
|
14840
|
-
} else if (part !== '@') {
|
|
14813
|
+
} else {
|
|
14841
14814
|
segments.push({
|
|
14842
14815
|
value: part,
|
|
14843
14816
|
pos,
|
|
14844
14817
|
});
|
|
14845
|
-
pos += part.length;
|
|
14846
14818
|
}
|
|
14819
|
+
pos += part.length;
|
|
14847
14820
|
}
|
|
14848
14821
|
|
|
14849
14822
|
return segments;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
${refIdP.value}
|
|
3
3
|
})(document.querySelector(\`[xu-ui-id=${elementP}]\`),evt)`,null,null,null,evt);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);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){$(document).trigger(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?.triggers?.[eventIdP].name.event;if(_field_obj?.triggers?.[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&&!_.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||_.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;if(elementP){$element=$(`[xu-ui-id="${elementP}"]`).clone(true)}let ret_field_id=await func.expression.get(SESSION_ID,val.id.trim(),dsSessionP,"update",null,null,null,null,null,null,$element?.length?$element?.data()?.xuData?.iterate_info:null);let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,$element?.length?$element?.data()?.xuData?.iterate_info:null);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);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+" "+_.capitalize(source)+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+" "+_.capitalize(source)+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=_.reduce(payload_arr,(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)){_.forEach(_session.WORKER_OBJ.jobs,function(val2,key2){if(key2===val){found=true;return false}})}if(!found){do_callback();return}},100);var do_callback=function(){window.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"))document.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.UI.screen.init(SESSION_ID,params_obj.prog,null,null,$("#embed_"+SESSION_ID),null,null,null,null,null,"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(_.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(){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}}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();return{result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found}};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.substr(0,6)==="_DATE_"){ret=ret.substr(6)}else if(ret&&ret.length===10&&ret.substr(4,1)==="-"&&ret.substr(7,1)==="-"||ret==="self"){ret=ret}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);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const split=func.expression.parse(ret)||[];console.log(valP,split);for await(const[arr_key,val]of Object.entries(split)){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=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){property2=await func.expression.get_property(val.value).property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{property1=await func.expression.get_property(val.value).property1;property2=await func.expression.get_property(val.value).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;_.forEach(var_Arr,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=_.assignIn(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_org=function(strP){var extract_str=function(strP,posP){if(!posP)posP=0;var clean_split_str=function(arrP){var arr=[];if(arrP&&arrP.length>1&&arrP[0]===""&&arrP[1].indexOf("@")>-1){for(var i=1;i<=arrP.length;i++){arr.push(arrP[i])}return arr}else return arrP};var nonLettersPatt=/\W/;var validSymbolsNoArray=/[^.@\[]/;var validSymbolsWithArray=/[^.@"'\[\]]/;var validSymbols=validSymbolsNoArray;var splitTmp=strP.replace(/@/g,"^^@").split("^^");var split=clean_split_str(splitTmp);var obj=[];if(split){for(let val of split){if(val){var pos=strP.indexOf(val);if(val&&val.substr(0,1)==="@"){var tmpStr="";var word_start_pos=undefined;var word_end_pos=undefined;for(var i=0;i<=val.length;i++){var key1=i;var val1=val.substr(i,1);if(val1==="."&&!word_start_pos)word_start_pos=key1;if(word_start_pos&&key1>word_start_pos&&nonLettersPatt.test(val1))word_end_pos=key1;if(word_start_pos&&word_start_pos>=0&&word_end_pos&&word_end_pos>=0){var word=val.substr(word_start_pos+1,word_end_pos-word_start_pos-1);tmpStr=tmpStr.substr(0,word_start_pos)+"^^"+tmpStr.substr(word_start_pos,word_end_pos);if(val.substr(word_end_pos,1)===".")word_start_pos=word_end_pos;else word_start_pos=null;word_end_pos=null}if(val1==="[")validSymbols=validSymbolsWithArray;if(nonLettersPatt.test(val1)&&validSymbols.test(val1)&&tmpStr.indexOf("^^")===-1){tmpStr+="^^"+val1}else tmpStr+=val1}if(tmpStr.indexOf("^^")>-1){var obj1=extract_str(tmpStr,pos);obj=obj.concat(obj1)}else{var fieldId=undefined;if(val){fieldId=val.substr(1,val.length);if(val.indexOf(".")>-1)fieldId=val.substr(1,val.indexOf(".")-1);if(val.indexOf("[")>-1)fieldId=val.substr(1,val.indexOf("[")-1)}obj.push({value:val,fieldId:fieldId,pos:pos+posP})}}else{obj.push({value:val,pos:pos+posP})}}}return obj}};var res=extract_str(strP);return res};func.expression.parse_bad=function(strP){const nonLettersPatt=/\W/;const validSymbolsNoArray=/[^.@\[]/;const validSymbolsWithArray=/[^.@"'\[\]]/;function extractStr(str,startPos=0){const cleanSplit=arr=>arr?.length>1&&arr[0]===""&&arr[1].includes("@")?arr.slice(1):arr;const segments=cleanSplit(str.replace(/@/g,"^^@").split("^^"));const result=[];for(const val of segments||[]){if(!val)continue;const pos=str.indexOf(val)+startPos;if(val.startsWith("@")){let tmpStr="";let wordStart=null;let wordEnd=null;let validSymbols=validSymbolsNoArray;for(let i=0;i<val.length;i++){const char=val[i];if(char==="[")validSymbols=validSymbolsWithArray;if(char==="."&&wordStart===null)wordStart=i;else if(wordStart!==null&&nonLettersPatt.test(char))wordEnd=i;if(wordStart!==null&&wordEnd!==null){const word=val.slice(wordStart+1,wordEnd);tmpStr=tmpStr.slice(0,wordStart)+"^^"+tmpStr.slice(wordStart,wordEnd);wordStart=char==="."?wordEnd:null;wordEnd=null}tmpStr+=nonLettersPatt.test(char)&&validSymbols.test(char)&&!tmpStr.includes("^^")?"^^"+char:char}if(tmpStr.includes("^^")){result.push(...extractStr(tmpStr,pos))}else{const fieldIdMatch=val.match(/^@([^.\[]+)/);result.push({value:val,fieldId:fieldIdMatch?fieldIdMatch[1]:undefined,pos:pos})}}else{result.push({value:val,pos:pos})}}return result}return extractStr(strP)};func.expression.parse=function(input){if(typeof input!=="string")return[];const segments=[];let pos=0;const parts=input.split(/(@)/).filter(Boolean);for(let i=0;i<parts.length;i++){const part=parts[i];if(part==="@"&&i+1<parts.length){const nextPart=parts[i+1];const varEnd=nextPart.search(/[.\[]/);let fieldId,remainder;if(varEnd>0){fieldId=nextPart.slice(0,varEnd);remainder=nextPart.slice(varEnd)}else{fieldId=nextPart;remainder=""}const fullVarValue=`@${fieldId}`;segments.push({value:fullVarValue,fieldId:fieldId,pos:pos});pos+=fullVarValue.length;if(remainder){segments.push({value:remainder,pos:pos});pos+=remainder.length}i++}else if(part!=="@"){segments.push({value:part,pos:pos});pos+=part.length}}return segments};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.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){const api_utils=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 xu=api_utils;if(typeof IS_PROCESS_SERVER==="undefined"&&typeof IS_DOCKER==="undefined"){try{return eval(val)}catch(err){try{return JSON5.parse(val)}catch(err){return val}}}if(sourceP==="javascript"){process.on("uncaughtException",err=>{console.error("Asynchronous error caught.",err);func.events.delete_job(SESSION_ID,job_id);if(typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined"){if(SESSION_OBJ[SESSION_ID].crawler)return;return __.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}});try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules","/");const script=new VM.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});let vm=new VM.NodeVM({require:{external:true},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,axios:axios,got:got,FormData:FormData},timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){console.error("Failed to execute script.",err);if(typeof IS_PROCESS_SERVER!=="undefined"){func.events.delete_job(SESSION_ID,jobNo);return __.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}}else{try{try{let vm=new VM.VM({sandbox:{xu:xu,func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id},timeout:1e3,allowAsync:false});let ret=val;if(typeof val==="string"){ret=await vm.run(val)}return ret}catch(err){throw""}}catch(err){try{return JSON5.parse(val)}catch(err){return val}}}};func.UI.main={};func.UI.main.clear_SYNC_INTERVAL=function(){$("body").unbind("mousemove keypress mousedown")};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(!val.data.dir==="in")continue;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.UI.screen.init(SESSION_ID,prog,null,null,$("#embed_"+SESSION_ID),null,null,null,null,get_params_obj(),"call_embed");document.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];var hash="";if(window.location.hash)hash=window.location.hash.substr(1);_session.SYS_GLOBAL_STR_BROWSER_HASH_ID=hash;_session.SYS_GLOBAL_STR_BROWSER_TITLE=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");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(){$("<div>").attr("id","embed_"+SESSION_ID).addClass("xu_embed_div").data({xuData:{}}).appendTo($(_session.root_element))};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(){$(".loader").remove();$(_session.root_element).removeClass("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(navigator.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();$(_session.root_element).show();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.io started.");await glb.lifecycle.execute(SESSION_ID,"systemReady");$(document).keydown(function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,1)});$(document).keyup(function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,0)});await updateOnlineStatus();window.addEventListener("online",updateOnlineStatus);window.addEventListener("offline",updateOnlineStatus);console.log("xuda.io system ready.");$("body")[0].dispatchEvent(glb.system_ready_event)};func.UI.main.set_custom_css=function(SESSION_ID,callbackP){if(SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system?.["SYS_GLOBAL_STR_SITE_CSS"])$("<style type='text/css'> "+SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system["SYS_GLOBAL_STR_SITE_CSS"]+" </style>").appendTo("head");callbackP()};func.index={};$(document).ready(function(){func.index.init_document_listeners();func.UI.utils.indicator.worker.normal();func.index.init_service_workers()});function xuda(...args){let element=null;let opt={};let callback=null;for(const arg of args){if(arg instanceof HTMLElement){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(!$(element).length){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(window.location.href);glb.worker_type="Worker";if(opt.debug_js){glb.debug_js=true;if((location.host.includes("localhost")||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(){const{root_element,domain}=_session;$(root_element).css("position","relative");$(root_element).append(`
|
|
5
|
+
})(document.querySelector(\`[xu-ui-id=${elementP}]\`),evt)`,true,null,null,evt);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){$(document).trigger(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?.triggers?.[eventIdP].name.event;if(_field_obj?.triggers?.[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&&!_.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||_.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;if(elementP){$element=$(`[xu-ui-id="${elementP}"]`).clone(true)}let ret_field_id=await func.expression.get(SESSION_ID,val.id.trim(),dsSessionP,"update",null,null,null,null,null,null,$element?.length?$element?.data()?.xuData?.iterate_info:null);let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,$element?.length?$element?.data()?.xuData?.iterate_info:null);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);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+" "+_.capitalize(source)+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+" "+_.capitalize(source)+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=_.reduce(payload_arr,(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)){_.forEach(_session.WORKER_OBJ.jobs,function(val2,key2){if(key2===val){found=true;return false}})}if(!found){do_callback();return}},100);var do_callback=function(){window.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"))document.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.UI.screen.init(SESSION_ID,params_obj.prog,null,null,$("#embed_"+SESSION_ID),null,null,null,null,null,"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(_.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(){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}}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();return{result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found}};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.substr(0,6)==="_DATE_"){ret=ret.substr(6)}else if(ret&&ret.length===10&&ret.substr(4,1)==="-"&&ret.substr(7,1)==="-"||ret==="self"){ret=ret}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);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const split=func.expression.parse(ret)||[];console.log(valP,split);for await(const[arr_key,val]of Object.entries(split)){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=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){property2=await func.expression.get_property(val.value).property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{property1=await func.expression.get_property(val.value).property1;property2=await func.expression.get_property(val.value).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;_.forEach(var_Arr,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=_.assignIn(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_org=function(strP){var extract_str=function(strP,posP){if(!posP)posP=0;var clean_split_str=function(arrP){var arr=[];if(arrP&&arrP.length>1&&arrP[0]===""&&arrP[1].indexOf("@")>-1){for(var i=1;i<=arrP.length;i++){arr.push(arrP[i])}return arr}else return arrP};var nonLettersPatt=/\W/;var validSymbolsNoArray=/[^.@\[]/;var validSymbolsWithArray=/[^.@"'\[\]]/;var validSymbols=validSymbolsNoArray;var splitTmp=strP.replace(/@/g,"^^@").split("^^");var split=clean_split_str(splitTmp);var obj=[];if(split){for(let val of split){if(val){var pos=strP.indexOf(val);if(val&&val.substr(0,1)==="@"){var tmpStr="";var word_start_pos=undefined;var word_end_pos=undefined;for(var i=0;i<=val.length;i++){var key1=i;var val1=val.substr(i,1);if(val1==="."&&!word_start_pos)word_start_pos=key1;if(word_start_pos&&key1>word_start_pos&&nonLettersPatt.test(val1))word_end_pos=key1;if(word_start_pos&&word_start_pos>=0&&word_end_pos&&word_end_pos>=0){var word=val.substr(word_start_pos+1,word_end_pos-word_start_pos-1);tmpStr=tmpStr.substr(0,word_start_pos)+"^^"+tmpStr.substr(word_start_pos,word_end_pos);if(val.substr(word_end_pos,1)===".")word_start_pos=word_end_pos;else word_start_pos=null;word_end_pos=null}if(val1==="[")validSymbols=validSymbolsWithArray;if(nonLettersPatt.test(val1)&&validSymbols.test(val1)&&tmpStr.indexOf("^^")===-1){tmpStr+="^^"+val1}else tmpStr+=val1}if(tmpStr.indexOf("^^")>-1){var obj1=extract_str(tmpStr,pos);obj=obj.concat(obj1)}else{var fieldId=undefined;if(val){fieldId=val.substr(1,val.length);if(val.indexOf(".")>-1)fieldId=val.substr(1,val.indexOf(".")-1);if(val.indexOf("[")>-1)fieldId=val.substr(1,val.indexOf("[")-1)}obj.push({value:val,fieldId:fieldId,pos:pos+posP})}}else{obj.push({value:val,pos:pos+posP})}}}return obj}};var res=extract_str(strP);return res};func.expression.parse_bad=function(strP){const nonLettersPatt=/\W/;const validSymbolsNoArray=/[^.@\[]/;const validSymbolsWithArray=/[^.@"'\[\]]/;function extractStr(str,startPos=0){const cleanSplit=arr=>arr?.length>1&&arr[0]===""&&arr[1].includes("@")?arr.slice(1):arr;const segments=cleanSplit(str.replace(/@/g,"^^@").split("^^"));const result=[];for(const val of segments||[]){if(!val)continue;const pos=str.indexOf(val)+startPos;if(val.startsWith("@")){let tmpStr="";let wordStart=null;let wordEnd=null;let validSymbols=validSymbolsNoArray;for(let i=0;i<val.length;i++){const char=val[i];if(char==="[")validSymbols=validSymbolsWithArray;if(char==="."&&wordStart===null)wordStart=i;else if(wordStart!==null&&nonLettersPatt.test(char))wordEnd=i;if(wordStart!==null&&wordEnd!==null){const word=val.slice(wordStart+1,wordEnd);tmpStr=tmpStr.slice(0,wordStart)+"^^"+tmpStr.slice(wordStart,wordEnd);wordStart=char==="."?wordEnd:null;wordEnd=null}tmpStr+=nonLettersPatt.test(char)&&validSymbols.test(char)&&!tmpStr.includes("^^")?"^^"+char:char}if(tmpStr.includes("^^")){result.push(...extractStr(tmpStr,pos))}else{const fieldIdMatch=val.match(/^@([^.\[]+)/);result.push({value:val,fieldId:fieldIdMatch?fieldIdMatch[1]:undefined,pos:pos})}}else{result.push({value:val,pos:pos})}}return result}return extractStr(strP)};func.expression.parse=function(input){if(typeof input!=="string")return[];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}return segments};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.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){const api_utils=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 xu=api_utils;if(typeof IS_PROCESS_SERVER==="undefined"&&typeof IS_DOCKER==="undefined"){try{return eval(val)}catch(err){try{return JSON5.parse(val)}catch(err){return val}}}if(sourceP==="javascript"){process.on("uncaughtException",err=>{console.error("Asynchronous error caught.",err);func.events.delete_job(SESSION_ID,job_id);if(typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined"){if(SESSION_OBJ[SESSION_ID].crawler)return;return __.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}});try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules","/");const script=new VM.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});let vm=new VM.NodeVM({require:{external:true},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,axios:axios,got:got,FormData:FormData},timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){console.error("Failed to execute script.",err);if(typeof IS_PROCESS_SERVER!=="undefined"){func.events.delete_job(SESSION_ID,jobNo);return __.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}}else{try{try{let vm=new VM.VM({sandbox:{xu:xu,func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id},timeout:1e3,allowAsync:false});let ret=val;if(typeof val==="string"){ret=await vm.run(val)}return ret}catch(err){throw""}}catch(err){try{return JSON5.parse(val)}catch(err){return val}}}};func.UI.main={};func.UI.main.clear_SYNC_INTERVAL=function(){$("body").unbind("mousemove keypress mousedown")};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(!val.data.dir==="in")continue;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.UI.screen.init(SESSION_ID,prog,null,null,$("#embed_"+SESSION_ID),null,null,null,null,get_params_obj(),"call_embed");document.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];var hash="";if(window.location.hash)hash=window.location.hash.substr(1);_session.SYS_GLOBAL_STR_BROWSER_HASH_ID=hash;_session.SYS_GLOBAL_STR_BROWSER_TITLE=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");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(){$("<div>").attr("id","embed_"+SESSION_ID).addClass("xu_embed_div").data({xuData:{}}).appendTo($(_session.root_element))};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(){$(".loader").remove();$(_session.root_element).removeClass("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(navigator.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();$(_session.root_element).show();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.io started.");await glb.lifecycle.execute(SESSION_ID,"systemReady");$(document).keydown(function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,1)});$(document).keyup(function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,0)});await updateOnlineStatus();window.addEventListener("online",updateOnlineStatus);window.addEventListener("offline",updateOnlineStatus);console.log("xuda.io system ready.");$("body")[0].dispatchEvent(glb.system_ready_event)};func.UI.main.set_custom_css=function(SESSION_ID,callbackP){if(SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system?.["SYS_GLOBAL_STR_SITE_CSS"])$("<style type='text/css'> "+SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system["SYS_GLOBAL_STR_SITE_CSS"]+" </style>").appendTo("head");callbackP()};func.index={};$(document).ready(function(){func.index.init_document_listeners();func.UI.utils.indicator.worker.normal();func.index.init_service_workers()});function xuda(...args){let element=null;let opt={};let callback=null;for(const arg of args){if(arg instanceof HTMLElement){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(!$(element).length){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(window.location.href);glb.worker_type="Worker";if(opt.debug_js){glb.debug_js=true;if((location.host.includes("localhost")||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(){const{root_element,domain}=_session;$(root_element).css("position","relative");$(root_element).append(`
|
|
6
6
|
|
|
7
7
|
<style>
|
|
8
8
|
.loader {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
${refIdP.value}
|
|
3
3
|
})(document.querySelector(\`[xu-ui-id=${elementP}]\`),evt)`,null,null,null,evt);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);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){$(document).trigger(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?.triggers?.[eventIdP].name.event;if(_field_obj?.triggers?.[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&&!_.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||_.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;if(elementP){$element=$(`[xu-ui-id="${elementP}"]`).clone(true)}let ret_field_id=await func.expression.get(SESSION_ID,val.id.trim(),dsSessionP,"update",null,null,null,null,null,null,$element?.length?$element?.data()?.xuData?.iterate_info:null);let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,$element?.length?$element?.data()?.xuData?.iterate_info:null);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);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+" "+_.capitalize(source)+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+" "+_.capitalize(source)+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=_.reduce(payload_arr,(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)){_.forEach(_session.WORKER_OBJ.jobs,function(val2,key2){if(key2===val){found=true;return false}})}if(!found){do_callback();return}},100);var do_callback=function(){window.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"))document.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.UI.screen.init(SESSION_ID,params_obj.prog,null,null,$("#embed_"+SESSION_ID),null,null,null,null,null,"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(_.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(){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}}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();return{result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found}};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.substr(0,6)==="_DATE_"){ret=ret.substr(6)}else if(ret&&ret.length===10&&ret.substr(4,1)==="-"&&ret.substr(7,1)==="-"||ret==="self"){ret=ret}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);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const split=func.expression.parse(ret)||[];console.log(valP,split);for await(const[arr_key,val]of Object.entries(split)){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=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){property2=await func.expression.get_property(val.value).property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{property1=await func.expression.get_property(val.value).property1;property2=await func.expression.get_property(val.value).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;_.forEach(var_Arr,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=_.assignIn(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_org=function(strP){var extract_str=function(strP,posP){if(!posP)posP=0;var clean_split_str=function(arrP){var arr=[];if(arrP&&arrP.length>1&&arrP[0]===""&&arrP[1].indexOf("@")>-1){for(var i=1;i<=arrP.length;i++){arr.push(arrP[i])}return arr}else return arrP};var nonLettersPatt=/\W/;var validSymbolsNoArray=/[^.@\[]/;var validSymbolsWithArray=/[^.@"'\[\]]/;var validSymbols=validSymbolsNoArray;var splitTmp=strP.replace(/@/g,"^^@").split("^^");var split=clean_split_str(splitTmp);var obj=[];if(split){for(let val of split){if(val){var pos=strP.indexOf(val);if(val&&val.substr(0,1)==="@"){var tmpStr="";var word_start_pos=undefined;var word_end_pos=undefined;for(var i=0;i<=val.length;i++){var key1=i;var val1=val.substr(i,1);if(val1==="."&&!word_start_pos)word_start_pos=key1;if(word_start_pos&&key1>word_start_pos&&nonLettersPatt.test(val1))word_end_pos=key1;if(word_start_pos&&word_start_pos>=0&&word_end_pos&&word_end_pos>=0){var word=val.substr(word_start_pos+1,word_end_pos-word_start_pos-1);tmpStr=tmpStr.substr(0,word_start_pos)+"^^"+tmpStr.substr(word_start_pos,word_end_pos);if(val.substr(word_end_pos,1)===".")word_start_pos=word_end_pos;else word_start_pos=null;word_end_pos=null}if(val1==="[")validSymbols=validSymbolsWithArray;if(nonLettersPatt.test(val1)&&validSymbols.test(val1)&&tmpStr.indexOf("^^")===-1){tmpStr+="^^"+val1}else tmpStr+=val1}if(tmpStr.indexOf("^^")>-1){var obj1=extract_str(tmpStr,pos);obj=obj.concat(obj1)}else{var fieldId=undefined;if(val){fieldId=val.substr(1,val.length);if(val.indexOf(".")>-1)fieldId=val.substr(1,val.indexOf(".")-1);if(val.indexOf("[")>-1)fieldId=val.substr(1,val.indexOf("[")-1)}obj.push({value:val,fieldId:fieldId,pos:pos+posP})}}else{obj.push({value:val,pos:pos+posP})}}}return obj}};var res=extract_str(strP);return res};func.expression.parse_bad=function(strP){const nonLettersPatt=/\W/;const validSymbolsNoArray=/[^.@\[]/;const validSymbolsWithArray=/[^.@"'\[\]]/;function extractStr(str,startPos=0){const cleanSplit=arr=>arr?.length>1&&arr[0]===""&&arr[1].includes("@")?arr.slice(1):arr;const segments=cleanSplit(str.replace(/@/g,"^^@").split("^^"));const result=[];for(const val of segments||[]){if(!val)continue;const pos=str.indexOf(val)+startPos;if(val.startsWith("@")){let tmpStr="";let wordStart=null;let wordEnd=null;let validSymbols=validSymbolsNoArray;for(let i=0;i<val.length;i++){const char=val[i];if(char==="[")validSymbols=validSymbolsWithArray;if(char==="."&&wordStart===null)wordStart=i;else if(wordStart!==null&&nonLettersPatt.test(char))wordEnd=i;if(wordStart!==null&&wordEnd!==null){const word=val.slice(wordStart+1,wordEnd);tmpStr=tmpStr.slice(0,wordStart)+"^^"+tmpStr.slice(wordStart,wordEnd);wordStart=char==="."?wordEnd:null;wordEnd=null}tmpStr+=nonLettersPatt.test(char)&&validSymbols.test(char)&&!tmpStr.includes("^^")?"^^"+char:char}if(tmpStr.includes("^^")){result.push(...extractStr(tmpStr,pos))}else{const fieldIdMatch=val.match(/^@([^.\[]+)/);result.push({value:val,fieldId:fieldIdMatch?fieldIdMatch[1]:undefined,pos:pos})}}else{result.push({value:val,pos:pos})}}return result}return extractStr(strP)};func.expression.parse=function(input){if(typeof input!=="string")return[];const segments=[];let pos=0;const parts=input.split(/(@)/).filter(Boolean);for(let i=0;i<parts.length;i++){const part=parts[i];if(part==="@"&&i+1<parts.length){const nextPart=parts[i+1];const varEnd=nextPart.search(/[.\[]/);let fieldId,remainder;if(varEnd>0){fieldId=nextPart.slice(0,varEnd);remainder=nextPart.slice(varEnd)}else{fieldId=nextPart;remainder=""}const fullVarValue=`@${fieldId}`;segments.push({value:fullVarValue,fieldId:fieldId,pos:pos});pos+=fullVarValue.length;if(remainder){segments.push({value:remainder,pos:pos});pos+=remainder.length}i++}else if(part!=="@"){segments.push({value:part,pos:pos});pos+=part.length}}return segments};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.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){const api_utils=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 xu=api_utils;if(typeof IS_PROCESS_SERVER==="undefined"&&typeof IS_DOCKER==="undefined"){try{return eval(val)}catch(err){try{return JSON5.parse(val)}catch(err){return val}}}if(sourceP==="javascript"){process.on("uncaughtException",err=>{console.error("Asynchronous error caught.",err);func.events.delete_job(SESSION_ID,job_id);if(typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined"){if(SESSION_OBJ[SESSION_ID].crawler)return;return __.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}});try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules","/");const script=new VM.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});let vm=new VM.NodeVM({require:{external:true},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,axios:axios,got:got,FormData:FormData},timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){console.error("Failed to execute script.",err);if(typeof IS_PROCESS_SERVER!=="undefined"){func.events.delete_job(SESSION_ID,jobNo);return __.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}}else{try{try{let vm=new VM.VM({sandbox:{xu:xu,func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id},timeout:1e3,allowAsync:false});let ret=val;if(typeof val==="string"){ret=await vm.run(val)}return ret}catch(err){throw""}}catch(err){try{return JSON5.parse(val)}catch(err){return val}}}}; export default {
|
|
5
|
+
})(document.querySelector(\`[xu-ui-id=${elementP}]\`),evt)`,true,null,null,evt);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){$(document).trigger(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?.triggers?.[eventIdP].name.event;if(_field_obj?.triggers?.[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&&!_.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||_.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;if(elementP){$element=$(`[xu-ui-id="${elementP}"]`).clone(true)}let ret_field_id=await func.expression.get(SESSION_ID,val.id.trim(),dsSessionP,"update",null,null,null,null,null,null,$element?.length?$element?.data()?.xuData?.iterate_info:null);let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,$element?.length?$element?.data()?.xuData?.iterate_info:null);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);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+" "+_.capitalize(source)+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+" "+_.capitalize(source)+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=_.reduce(payload_arr,(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)){_.forEach(_session.WORKER_OBJ.jobs,function(val2,key2){if(key2===val){found=true;return false}})}if(!found){do_callback();return}},100);var do_callback=function(){window.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"))document.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.UI.screen.init(SESSION_ID,params_obj.prog,null,null,$("#embed_"+SESSION_ID),null,null,null,null,null,"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(_.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(){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}}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();return{result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found}};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.substr(0,6)==="_DATE_"){ret=ret.substr(6)}else if(ret&&ret.length===10&&ret.substr(4,1)==="-"&&ret.substr(7,1)==="-"||ret==="self"){ret=ret}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);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const split=func.expression.parse(ret)||[];console.log(valP,split);for await(const[arr_key,val]of Object.entries(split)){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=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){property2=await func.expression.get_property(val.value).property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{property1=await func.expression.get_property(val.value).property1;property2=await func.expression.get_property(val.value).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;_.forEach(var_Arr,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=_.assignIn(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_org=function(strP){var extract_str=function(strP,posP){if(!posP)posP=0;var clean_split_str=function(arrP){var arr=[];if(arrP&&arrP.length>1&&arrP[0]===""&&arrP[1].indexOf("@")>-1){for(var i=1;i<=arrP.length;i++){arr.push(arrP[i])}return arr}else return arrP};var nonLettersPatt=/\W/;var validSymbolsNoArray=/[^.@\[]/;var validSymbolsWithArray=/[^.@"'\[\]]/;var validSymbols=validSymbolsNoArray;var splitTmp=strP.replace(/@/g,"^^@").split("^^");var split=clean_split_str(splitTmp);var obj=[];if(split){for(let val of split){if(val){var pos=strP.indexOf(val);if(val&&val.substr(0,1)==="@"){var tmpStr="";var word_start_pos=undefined;var word_end_pos=undefined;for(var i=0;i<=val.length;i++){var key1=i;var val1=val.substr(i,1);if(val1==="."&&!word_start_pos)word_start_pos=key1;if(word_start_pos&&key1>word_start_pos&&nonLettersPatt.test(val1))word_end_pos=key1;if(word_start_pos&&word_start_pos>=0&&word_end_pos&&word_end_pos>=0){var word=val.substr(word_start_pos+1,word_end_pos-word_start_pos-1);tmpStr=tmpStr.substr(0,word_start_pos)+"^^"+tmpStr.substr(word_start_pos,word_end_pos);if(val.substr(word_end_pos,1)===".")word_start_pos=word_end_pos;else word_start_pos=null;word_end_pos=null}if(val1==="[")validSymbols=validSymbolsWithArray;if(nonLettersPatt.test(val1)&&validSymbols.test(val1)&&tmpStr.indexOf("^^")===-1){tmpStr+="^^"+val1}else tmpStr+=val1}if(tmpStr.indexOf("^^")>-1){var obj1=extract_str(tmpStr,pos);obj=obj.concat(obj1)}else{var fieldId=undefined;if(val){fieldId=val.substr(1,val.length);if(val.indexOf(".")>-1)fieldId=val.substr(1,val.indexOf(".")-1);if(val.indexOf("[")>-1)fieldId=val.substr(1,val.indexOf("[")-1)}obj.push({value:val,fieldId:fieldId,pos:pos+posP})}}else{obj.push({value:val,pos:pos+posP})}}}return obj}};var res=extract_str(strP);return res};func.expression.parse_bad=function(strP){const nonLettersPatt=/\W/;const validSymbolsNoArray=/[^.@\[]/;const validSymbolsWithArray=/[^.@"'\[\]]/;function extractStr(str,startPos=0){const cleanSplit=arr=>arr?.length>1&&arr[0]===""&&arr[1].includes("@")?arr.slice(1):arr;const segments=cleanSplit(str.replace(/@/g,"^^@").split("^^"));const result=[];for(const val of segments||[]){if(!val)continue;const pos=str.indexOf(val)+startPos;if(val.startsWith("@")){let tmpStr="";let wordStart=null;let wordEnd=null;let validSymbols=validSymbolsNoArray;for(let i=0;i<val.length;i++){const char=val[i];if(char==="[")validSymbols=validSymbolsWithArray;if(char==="."&&wordStart===null)wordStart=i;else if(wordStart!==null&&nonLettersPatt.test(char))wordEnd=i;if(wordStart!==null&&wordEnd!==null){const word=val.slice(wordStart+1,wordEnd);tmpStr=tmpStr.slice(0,wordStart)+"^^"+tmpStr.slice(wordStart,wordEnd);wordStart=char==="."?wordEnd:null;wordEnd=null}tmpStr+=nonLettersPatt.test(char)&&validSymbols.test(char)&&!tmpStr.includes("^^")?"^^"+char:char}if(tmpStr.includes("^^")){result.push(...extractStr(tmpStr,pos))}else{const fieldIdMatch=val.match(/^@([^.\[]+)/);result.push({value:val,fieldId:fieldIdMatch?fieldIdMatch[1]:undefined,pos:pos})}}else{result.push({value:val,pos:pos})}}return result}return extractStr(strP)};func.expression.parse=function(input){if(typeof input!=="string")return[];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}return segments};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.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){const api_utils=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 xu=api_utils;if(typeof IS_PROCESS_SERVER==="undefined"&&typeof IS_DOCKER==="undefined"){try{return eval(val)}catch(err){try{return JSON5.parse(val)}catch(err){return val}}}if(sourceP==="javascript"){process.on("uncaughtException",err=>{console.error("Asynchronous error caught.",err);func.events.delete_job(SESSION_ID,job_id);if(typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined"){if(SESSION_OBJ[SESSION_ID].crawler)return;return __.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}});try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules","/");const script=new VM.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});let vm=new VM.NodeVM({require:{external:true},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,axios:axios,got:got,FormData:FormData},timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){console.error("Failed to execute script.",err);if(typeof IS_PROCESS_SERVER!=="undefined"){func.events.delete_job(SESSION_ID,jobNo);return __.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}}else{try{try{let vm=new VM.VM({sandbox:{xu:xu,func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id},timeout:1e3,allowAsync:false});let ret=val;if(typeof val==="string"){ret=await vm.run(val)}return ret}catch(err){throw""}}catch(err){try{return JSON5.parse(val)}catch(err){return val}}}}; export default {
|
|
6
6
|
glb,
|
|
7
7
|
func,
|
|
8
8
|
APP_OBJ,
|
|
@@ -8266,50 +8266,23 @@ func.expression.parse = function (input) {
|
|
|
8266
8266
|
const segments = [];
|
|
8267
8267
|
let pos = 0;
|
|
8268
8268
|
|
|
8269
|
-
const parts = input.split(/(
|
|
8269
|
+
const parts = input.split(/(@\w+)/).filter(Boolean);
|
|
8270
8270
|
|
|
8271
|
-
for (
|
|
8272
|
-
|
|
8273
|
-
|
|
8274
|
-
if (part === '@' && i + 1 < parts.length) {
|
|
8275
|
-
const nextPart = parts[i + 1];
|
|
8276
|
-
const varEnd = nextPart.search(/[.\[]/); // Split at first . or [
|
|
8277
|
-
let fieldId, remainder;
|
|
8278
|
-
|
|
8279
|
-
if (varEnd > 0) {
|
|
8280
|
-
fieldId = nextPart.slice(0, varEnd);
|
|
8281
|
-
remainder = nextPart.slice(varEnd);
|
|
8282
|
-
} else {
|
|
8283
|
-
fieldId = nextPart;
|
|
8284
|
-
remainder = '';
|
|
8285
|
-
}
|
|
8286
|
-
|
|
8287
|
-
// Add @variable segment
|
|
8288
|
-
const fullVarValue = `@${fieldId}`;
|
|
8271
|
+
for (const part of parts) {
|
|
8272
|
+
if (part.startsWith('@')) {
|
|
8273
|
+
const fieldId = part.slice(1);
|
|
8289
8274
|
segments.push({
|
|
8290
|
-
value:
|
|
8275
|
+
value: part,
|
|
8291
8276
|
fieldId,
|
|
8292
8277
|
pos,
|
|
8293
8278
|
});
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
// Add remainder as a separate segment, if any
|
|
8297
|
-
if (remainder) {
|
|
8298
|
-
segments.push({
|
|
8299
|
-
value: remainder,
|
|
8300
|
-
pos,
|
|
8301
|
-
});
|
|
8302
|
-
pos += remainder.length;
|
|
8303
|
-
}
|
|
8304
|
-
|
|
8305
|
-
i++; // Skip the next part since we consumed it
|
|
8306
|
-
} else if (part !== '@') {
|
|
8279
|
+
} else {
|
|
8307
8280
|
segments.push({
|
|
8308
8281
|
value: part,
|
|
8309
8282
|
pos,
|
|
8310
8283
|
});
|
|
8311
|
-
pos += part.length;
|
|
8312
8284
|
}
|
|
8285
|
+
pos += part.length;
|
|
8313
8286
|
}
|
|
8314
8287
|
|
|
8315
8288
|
return segments;
|
package/js/xuda-worker-bundle.js
CHANGED
|
@@ -8266,50 +8266,23 @@ func.expression.parse = function (input) {
|
|
|
8266
8266
|
const segments = [];
|
|
8267
8267
|
let pos = 0;
|
|
8268
8268
|
|
|
8269
|
-
const parts = input.split(/(
|
|
8269
|
+
const parts = input.split(/(@\w+)/).filter(Boolean);
|
|
8270
8270
|
|
|
8271
|
-
for (
|
|
8272
|
-
|
|
8273
|
-
|
|
8274
|
-
if (part === '@' && i + 1 < parts.length) {
|
|
8275
|
-
const nextPart = parts[i + 1];
|
|
8276
|
-
const varEnd = nextPart.search(/[.\[]/); // Split at first . or [
|
|
8277
|
-
let fieldId, remainder;
|
|
8278
|
-
|
|
8279
|
-
if (varEnd > 0) {
|
|
8280
|
-
fieldId = nextPart.slice(0, varEnd);
|
|
8281
|
-
remainder = nextPart.slice(varEnd);
|
|
8282
|
-
} else {
|
|
8283
|
-
fieldId = nextPart;
|
|
8284
|
-
remainder = '';
|
|
8285
|
-
}
|
|
8286
|
-
|
|
8287
|
-
// Add @variable segment
|
|
8288
|
-
const fullVarValue = `@${fieldId}`;
|
|
8271
|
+
for (const part of parts) {
|
|
8272
|
+
if (part.startsWith('@')) {
|
|
8273
|
+
const fieldId = part.slice(1);
|
|
8289
8274
|
segments.push({
|
|
8290
|
-
value:
|
|
8275
|
+
value: part,
|
|
8291
8276
|
fieldId,
|
|
8292
8277
|
pos,
|
|
8293
8278
|
});
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
// Add remainder as a separate segment, if any
|
|
8297
|
-
if (remainder) {
|
|
8298
|
-
segments.push({
|
|
8299
|
-
value: remainder,
|
|
8300
|
-
pos,
|
|
8301
|
-
});
|
|
8302
|
-
pos += remainder.length;
|
|
8303
|
-
}
|
|
8304
|
-
|
|
8305
|
-
i++; // Skip the next part since we consumed it
|
|
8306
|
-
} else if (part !== '@') {
|
|
8279
|
+
} else {
|
|
8307
8280
|
segments.push({
|
|
8308
8281
|
value: part,
|
|
8309
8282
|
pos,
|
|
8310
8283
|
});
|
|
8311
|
-
pos += part.length;
|
|
8312
8284
|
}
|
|
8285
|
+
pos += part.length;
|
|
8313
8286
|
}
|
|
8314
8287
|
|
|
8315
8288
|
return segments;
|