@xuda.io/runtime-bundle 1.0.885 → 1.0.887
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/modules/xuda-api-library.min.mjs +1 -1
- package/js/modules/xuda-api-library.mjs +115 -246
- package/js/modules/xuda-db-adapter-module.min.mjs +1 -1
- package/js/modules/xuda-db-adapter-module.mjs +1 -1
- package/js/modules/xuda-project-loader-module.esm.js +1 -23
- package/js/modules/xuda-project-loader-module.esm.min.js +1 -1
- package/js/xuda-runtime-bundle.js +31 -63
- package/js/xuda-runtime-bundle.min.js +3 -3
- package/js/xuda-runtime-mini-bundle.js +1 -1
- package/js/xuda-runtime-mini-bundle.min.js +1 -1
- package/js/xuda-runtime-slim.js +31 -63
- package/js/xuda-runtime-slim.min.es.js +31 -63
- package/js/xuda-runtime-slim.min.js +3 -3
- package/js/xuda-server-bundle.min.mjs +1 -1
- package/js/xuda-server-bundle.mjs +10 -51
- package/js/xuda-worker-bundle.js +10 -51
- package/js/xuda-worker-bundle.min.js +1 -1
- package/js/xuda_common-bundle.js +6 -47
- package/js/xuda_common-bundle.min.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export class XudaModule{constructor(e){this.func=e.func;this.glb=e.glb;this.SESSION_OBJ=e.SESSION_OBJ;this.SESSION_ID=e.SESSION_ID;this.APP_OBJ=e.APP_OBJ;this.dsSession=e.dsSession;this.job_id=e.job_id;this._session=this.SESSION_OBJ[this.SESSION_ID];return this}async get_field_value(field_id){if(!field_id){console.error("xu.getFieldValue: field_id cannot be empty");return false}let ret_get_value=await this.func.datasource.get_value(this.SESSION_ID,field_id,this.dsSession);if(!ret_get_value.found){console.error(`xu.getFieldValue: ${field_id} field not found`);return false}return ret_get_value.ret.value}async set_field_value(field_id,value,avoid_refresh){if(!field_id){console.error("xu.setFieldValue: field_id cannot be empty");return false}if(typeof value==="undefined"){console.error(`xu.setFieldValue: ${field_id} - value cannot be undefined`);return false}let ret_get_value=await this.func.datasource.get_value(this.SESSION_ID,field_id,this.dsSession);if(!ret_get_value.found){console.error(`xu.setFieldValue: ${field_id} field not found`);return false}let _ds=this._session.DS_GLB[ret_get_value.dsSessionP];const datasource_changes={[_ds.dsSession]:{[ret_get_value.currentRecordId]:{[field_id]:value}}};return await this.func.datasource.update(this.SESSION_ID,datasource_changes,null,avoid_refresh)}async invoke_event(event_id){if(!event_id){console.error("xu.invokeEvent: event_id cannot be empty");return false}let ds;for await(const[key,val]of Object.entries(Object.assign([],this._session.DS_GLB).reverse())){let ds_val=val;let ds_key=ds_val.dsSession;const _view_obj=await this.func.utils.VIEWS_OBJ.get(this.SESSION_ID,ds_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(typeof ds==="undefined"){this.reject("xu.invokeEvent error",`${event_id} event_id not found`,this.job_id);return false}return this.func.events.validate(this.SESSION_ID,"user_defined",ds,event_id)}async read_drive(filename,cb){try{const response=await fetch(`https://${this._session.domain}/workspace-drive/`+filename+"&"+this._session.gtp_token);if(cb){return cb(await response.json())}return await response.json()}catch(e){console.error(e);this.reject("xu.readDrive error",e,this.job_id)}}async write_drive(stream,filename,make_public,cb){var data={app_id:this._session.app_id,gtp_token:this._session.gtp_token,app_token:this._session.app_token,req_from_api:"true",public:make_public?"true":""};const form=new FormData;for(const[key,val]of Object.entries(data)){form.append(key,val)}form.append("file",stream,filename);try{const response=await fetch(this.func.common.get_url(this.SESSION_ID,"rpi","runtime_upload_file"),{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(form)});if(cb){return cb(await response.json())}return await response.json()}catch(e){console.error(e);this.reject("xu.writeDrive error",e,this.job_id)}}resolve(cb,job_id){if(job_id){this.func.events.delete_job(this.SESSION_ID,job_id)}if(cb){cb()}}reject(msg,details,job_id){if(job_id){this.func.events.delete_job(this.SESSION_ID,job_id)}this.log("E",msg,details)}log(type,msg,details){this.func.utils.debug_report(this.SESSION_ID,msg,details,type)}alert(type,display,msg,details){this.func.utils.alerts.execute(this.SESSION_ID,type,display,details,msg)}async call_project_api(prog_id,params,cb){const _prog_obj=await this.func.utils.DOCS_OBJ.get(this.SESSION_ID,prog_id);if(_prog_obj?.properties?.menuType!=="api"){return this.reject("xu.callApiProgram error",`${prog_id} is not an API program`,this.job_id)}if(this._session.engine_mode==="live_preview"||typeof IS_PROCESS_SERVER!=="undefined"){const ret=await this.func.datasource.prepare(this.SESSION_ID,prog_id,null,0,null,null,null,null,null,null,"api",null,null,null,params);try{const _ds=this._session.DS_GLB[ret.dsSessionP];if(typeof _ds.api_rendered_output==="undefined"||typeof _ds.tree_obj.apiOutput==="undefined"||!_ds.tree_obj.apiOutput){throw new Error("undefined api_rendered_output/apiOutput")}if(_ds.tree_obj.apiOutput==="json"){try{return JSON5.parse(_ds.api_rendered_output)}catch(err){console.error(err);return{}}}return _ds.api_rendered_output}catch(e){this.reject("xu.call_project_api error",e.message||e,this.job_id)}}try{const response=await fetch(`https://${this._session.domain}/execute_api_program`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({...params,...{prog_id:prog_id}})});if(cb){return cb(await response.json())}return await response.json()}catch(e){console.error(e);this.reject("xu.get_table_data error",e,this.job_id)}}async call_system_api(api_method,payload={},cb){try{let body={...{app_id:this._session.app_id,app_id_query:this._session.app_id,app_token:this._session.app_token},...payload};const response=await fetch(`https://${this._session.domain}/cpi/${api_method}`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(body)});const json=await response.json();if(cb){return cb(json)}return json}catch(e){console.error(e);this.reject("xu.call_system_api error",e,this.job_id)}}async call_external_api(method,url,payload={},cb){try{let json={...{app_id:this._session.app_id,app_id_query:this._session.app_id,app_token:this._session.app_token},...payload};const response=await fetch(`https://${url}`,{method:method,headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(json)});if(cb){return cb(await response.json())}return await response.json()}catch(e){console.error(e);this.reject("xu.call_external_api error",e,this.job_id)}}async call_javascript(prog_id,params={},evaluate=false){try{const module=await this.func.common.get_module(this.SESSION_ID,"xuda-event-javascript-module.mjs");const result=await module.call_javascript(this.SESSION_ID,this.job_id,{prog:prog_id,parameters:params},this.dsSession,evaluate);return result}catch(e){console.error(e);this.reject("xu.call_javascript error",e,this.job_id)}}async dbs_create(table_id,data,cb){const _table_obj=await this.func.utils.DOCS_OBJ.get(this.SESSION_ID,table_id);if(_table_obj?.properties?.menuType!=="table"){return this.reject("xu.dbsCreate error",`${table_id} is not a table`,this.job_id)}try{const ret=await this.func.common.db(this.SESSION_ID,"dbs_create",{table_id:table_id,table_data:data});if(cb){return cb(ret)}return ret}catch(e){console.error(e);this.reject("xu.dbs_create error",e,this.job_id)}}async dbs_read(table_id,selector={},fields=[],sort,limit=999,skip,cb){const _table_obj=await this.func.utils.DOCS_OBJ.get(this.SESSION_ID,table_id);if(_table_obj?.properties?.menuType!=="table"){return this.reject("xu.dbsRead error",`${table_id} is not a table`,this.job_id)}let data={fields:fields,table_id:table_id,dataSourceFilterModelType:"query",filterModelMongo:selector,limit:limit,skip:skip,sort:sort};try{const ret=await this.func.common.db(this.SESSION_ID,"dbs_read",data);if(cb){return cb(ret)}return ret}catch(e){console.error(e);this.reject("xu.dbs_read error",e,this.job_id)}}async dbs_update(table_id,row_id,data,cb){const _table_obj=await this.func.utils.DOCS_OBJ.get(this.SESSION_ID,table_id);if(_table_obj?.properties?.menuType!=="table"){return this.reject("xu.dbsUpdate error",`${table_id} is not a table`,this.job_id)}if(!row_id){return this.reject("xu.dbsDelete error",`row_id is a mandatory field`,this.job_id)}try{const ret=await this.func.common.db(this.SESSION_ID,"dbs_update",{table_id:table_id,row_id:row_id,table_data:data});if(cb){return cb(ret)}return ret}catch(e){console.error(e);this.reject("xu.dbs_update error",e,this.job_id)}}async dbs_delete(table_id,row_id,cb){const _table_obj=await this.func.utils.DOCS_OBJ.get(this.SESSION_ID,table_id);if(_table_obj?.properties?.menuType!=="table"){return this.reject("xu.dbsDelete error",`${table_id} is not a table`,this.job_id)}if(!row_id){return this.reject("xu.dbsDelete error",`row_id is a mandatory field`,this.job_id)}try{const ret=await this.func.common.db(this.SESSION_ID,"dbs_delete",{table_id:table_id,ids:[row_id]});if(cb){return cb(ret)}return ret}catch(e){console.error(e);this.reject("xu.dbs_delete error",e,this.job_id)}}}
|
|
1
|
+
export class XudaModule{constructor(e){this.func=e.func;this.glb=e.glb;this.SESSION_OBJ=e.SESSION_OBJ;this.SESSION_ID=e.SESSION_ID;this.APP_OBJ=e.APP_OBJ;this.dsSession=e.dsSession;this.job_id=e.job_id;this._session=this.SESSION_OBJ[this.SESSION_ID];return this}async get_field_value(field_id){if(!field_id){console.error("xu.getFieldValue: field_id cannot be empty");return false}let ret_get_value=await this.func.datasource.get_value(this.SESSION_ID,field_id,this.dsSession);if(!ret_get_value.found){console.error(`xu.getFieldValue: ${field_id} field not found`);return false}return ret_get_value.ret.value}async set_field_value(field_id,value,avoid_refresh){if(!field_id){console.error("xu.setFieldValue: field_id cannot be empty");return false}if(typeof value==="undefined"){console.error(`xu.setFieldValue: ${field_id} - value cannot be undefined`);return false}let ret_get_value=await this.func.datasource.get_value(this.SESSION_ID,field_id,this.dsSession);if(!ret_get_value.found){console.error(`xu.setFieldValue: ${field_id} field not found`);return false}let _ds=this._session.DS_GLB[ret_get_value.dsSessionP];const datasource_changes={[_ds.dsSession]:{[ret_get_value.currentRecordId]:{[field_id]:value}}};return await this.func.datasource.update(this.SESSION_ID,datasource_changes,null,avoid_refresh)}async invoke_event(event_id){if(!event_id){console.error("xu.invokeEvent: event_id cannot be empty");return false}let ds;for await(const[key,val]of Object.entries(Object.assign([],this._session.DS_GLB).reverse())){let ds_val=val;let ds_key=ds_val.dsSession;const _view_obj=await this.func.utils.VIEWS_OBJ.get(this.SESSION_ID,ds_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(typeof ds==="undefined"){this.reject("xu.invokeEvent error",`${event_id} event_id not found`,this.job_id);return false}return this.func.events.validate(this.SESSION_ID,"user_defined",ds,event_id)}async read_drive(filename,cb){try{const response=await fetch(`https://${this._session.domain}/workspace-drive/`+filename+"&"+this._session.gtp_token);if(cb){return cb(await response.json())}return await response.json()}catch(e){console.error(e);this.reject("xu.readDrive error",e,this.job_id)}}async write_drive(stream,filename,make_public,cb){var data={app_id:this._session.app_id,gtp_token:this._session.gtp_token,app_token:this._session.app_token,req_from_api:"true",public:make_public?"true":""};const form=new FormData;for(const[key,val]of Object.entries(data)){form.append(key,val)}form.append("file",stream,filename);try{const response=await fetch(this.func.common.get_url(this.SESSION_ID,"rpi","runtime_upload_file"),{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(form)});if(cb){return cb(await response.json())}return await response.json()}catch(e){console.error(e);this.reject("xu.writeDrive error",e,this.job_id)}}resolve(cb,job_id){if(job_id){this.func.events.delete_job(this.SESSION_ID,job_id)}if(cb){cb()}}reject(msg,details,job_id){if(job_id){this.func.events.delete_job(this.SESSION_ID,job_id)}this.log("E",msg,details)}log(type,msg,details){this.func.utils.debug_report(this.SESSION_ID,msg,details,type)}alert(type,display,msg,details){this.func.utils.alerts.execute(this.SESSION_ID,type,display,details,msg)}async call_project_api(prog_id,params,cb){const _prog_obj=await this.func.utils.DOCS_OBJ.get(this.SESSION_ID,prog_id);if(_prog_obj?.properties?.menuType!=="api"){return this.reject("xu.callApiProgram error",`${prog_id} is not an API program`,this.job_id)}if(this._session.engine_mode==="live_preview"||typeof IS_PROCESS_SERVER!=="undefined"){const ret=await this.func.datasource.prepare(this.SESSION_ID,prog_id,null,0,null,null,null,null,null,null,"api",null,null,null,params);try{const _ds=this._session.DS_GLB[ret.dsSessionP];if(typeof _ds.api_rendered_output==="undefined"||typeof _ds.tree_obj.apiOutput==="undefined"||!_ds.tree_obj.apiOutput){throw new Error("undefined api_rendered_output/apiOutput")}if(_ds.tree_obj.apiOutput==="json"){try{return JSON5.parse(_ds.api_rendered_output)}catch(err){console.error(err);return{}}}return _ds.api_rendered_output}catch(e){this.reject("xu.call_project_api error",e.message||e,this.job_id)}}if(["cms"].includes(this._session.engine_mode)){try{const response=await fetch(`https://${this._session.domain}/api`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({...params,...{prog_id:prog_id}})});if(cb){return cb(await response.json())}return await response.json()}catch(e){console.error(e);this.reject("xu.get_table_data error",e,this.job_id)}}try{const response=await fetch(`https://${this._session.domain}/execute_api_program`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({...params,...{prog_id:prog_id}})});if(cb){return cb(await response.json())}return await response.json()}catch(e){console.error(e);this.reject("xu.get_table_data error",e,this.job_id)}}async call_system_api(api_method,payload={},cb){try{let body={...{app_id:this._session.app_id,app_id_query:this._session.app_id,app_token:this._session.app_token},...payload};const response=await fetch(`https://${this._session.domain}/cpi/${api_method}`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(body)});const json=await response.json();if(cb){return cb(json)}return json}catch(e){console.error(e);this.reject("xu.call_system_api error",e,this.job_id)}}async call_external_api(method,url,payload={},cb){try{let json={...{app_id:this._session.app_id,app_id_query:this._session.app_id,app_token:this._session.app_token},...payload};const response=await fetch(`https://${url}`,{method:method,headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(json)});if(cb){return cb(await response.json())}return await response.json()}catch(e){console.error(e);this.reject("xu.call_external_api error",e,this.job_id)}}async call_javascript(prog_id,params={},evaluate=false){try{const module=await this.func.common.get_module(this.SESSION_ID,"xuda-event-javascript-module.mjs");const result=await module.call_javascript(this.SESSION_ID,this.job_id,{prog:prog_id,parameters:params},this.dsSession,evaluate);return result}catch(e){console.error(e);this.reject("xu.call_javascript error",e,this.job_id)}}async dbs_create(table_id,data,cb){const _table_obj=await this.func.utils.DOCS_OBJ.get(this.SESSION_ID,table_id);if(_table_obj?.properties?.menuType!=="table"){return this.reject("xu.dbsCreate error",`${table_id} is not a table`,this.job_id)}try{const ret=await this.func.common.db(this.SESSION_ID,"dbs_create",{table_id:table_id,table_data:data});if(cb){return cb(ret)}return ret}catch(e){console.error(e);this.reject("xu.dbs_create error",e,this.job_id)}}async dbs_read(table_id,selector={},fields=[],sort,limit=999,skip,cb){const _table_obj=await this.func.utils.DOCS_OBJ.get(this.SESSION_ID,table_id);if(_table_obj?.properties?.menuType!=="table"){return this.reject("xu.dbsRead error",`${table_id} is not a table`,this.job_id)}let data={fields:fields,table_id:table_id,dataSourceFilterModelType:"query",filterModelMongo:selector,limit:limit,skip:skip,sort:sort};try{const ret=await this.func.common.db(this.SESSION_ID,"dbs_read",data);if(cb){return cb(ret)}return ret}catch(e){console.error(e);this.reject("xu.dbs_read error",e,this.job_id)}}async dbs_update(table_id,row_id,data,cb){const _table_obj=await this.func.utils.DOCS_OBJ.get(this.SESSION_ID,table_id);if(_table_obj?.properties?.menuType!=="table"){return this.reject("xu.dbsUpdate error",`${table_id} is not a table`,this.job_id)}if(!row_id){return this.reject("xu.dbsDelete error",`row_id is a mandatory field`,this.job_id)}try{const ret=await this.func.common.db(this.SESSION_ID,"dbs_update",{table_id:table_id,row_id:row_id,table_data:data});if(cb){return cb(ret)}return ret}catch(e){console.error(e);this.reject("xu.dbs_update error",e,this.job_id)}}async dbs_delete(table_id,row_id,cb){const _table_obj=await this.func.utils.DOCS_OBJ.get(this.SESSION_ID,table_id);if(_table_obj?.properties?.menuType!=="table"){return this.reject("xu.dbsDelete error",`${table_id} is not a table`,this.job_id)}if(!row_id){return this.reject("xu.dbsDelete error",`row_id is a mandatory field`,this.job_id)}try{const ret=await this.func.common.db(this.SESSION_ID,"dbs_delete",{table_id:table_id,ids:[row_id]});if(cb){return cb(ret)}return ret}catch(e){console.error(e);this.reject("xu.dbs_delete error",e,this.job_id)}}}
|
|
@@ -14,14 +14,10 @@ export class XudaModule {
|
|
|
14
14
|
|
|
15
15
|
async get_field_value(field_id) {
|
|
16
16
|
if (!field_id) {
|
|
17
|
-
console.error(
|
|
17
|
+
console.error('xu.getFieldValue: field_id cannot be empty');
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
|
-
let ret_get_value = await this.func.datasource.get_value(
|
|
21
|
-
this.SESSION_ID,
|
|
22
|
-
field_id,
|
|
23
|
-
this.dsSession
|
|
24
|
-
);
|
|
20
|
+
let ret_get_value = await this.func.datasource.get_value(this.SESSION_ID, field_id, this.dsSession);
|
|
25
21
|
|
|
26
22
|
if (!ret_get_value.found) {
|
|
27
23
|
console.error(`xu.getFieldValue: ${field_id} field not found`);
|
|
@@ -33,22 +29,16 @@ export class XudaModule {
|
|
|
33
29
|
|
|
34
30
|
async set_field_value(field_id, value, avoid_refresh) {
|
|
35
31
|
if (!field_id) {
|
|
36
|
-
console.error(
|
|
32
|
+
console.error('xu.setFieldValue: field_id cannot be empty');
|
|
37
33
|
return false;
|
|
38
34
|
}
|
|
39
35
|
|
|
40
|
-
if (typeof value ===
|
|
41
|
-
console.error(
|
|
42
|
-
`xu.setFieldValue: ${field_id} - value cannot be undefined`
|
|
43
|
-
);
|
|
36
|
+
if (typeof value === 'undefined') {
|
|
37
|
+
console.error(`xu.setFieldValue: ${field_id} - value cannot be undefined`);
|
|
44
38
|
return false;
|
|
45
39
|
}
|
|
46
40
|
|
|
47
|
-
let ret_get_value = await this.func.datasource.get_value(
|
|
48
|
-
this.SESSION_ID,
|
|
49
|
-
field_id,
|
|
50
|
-
this.dsSession
|
|
51
|
-
);
|
|
41
|
+
let ret_get_value = await this.func.datasource.get_value(this.SESSION_ID, field_id, this.dsSession);
|
|
52
42
|
|
|
53
43
|
if (!ret_get_value.found) {
|
|
54
44
|
console.error(`xu.setFieldValue: ${field_id} field not found`);
|
|
@@ -62,70 +52,43 @@ export class XudaModule {
|
|
|
62
52
|
[ret_get_value.currentRecordId]: { [field_id]: value },
|
|
63
53
|
},
|
|
64
54
|
};
|
|
65
|
-
return await this.func.datasource.update(
|
|
66
|
-
this.SESSION_ID,
|
|
67
|
-
datasource_changes,
|
|
68
|
-
null,
|
|
69
|
-
avoid_refresh
|
|
70
|
-
);
|
|
55
|
+
return await this.func.datasource.update(this.SESSION_ID, datasource_changes, null, avoid_refresh);
|
|
71
56
|
}
|
|
72
57
|
|
|
73
58
|
async invoke_event(event_id) {
|
|
74
59
|
if (!event_id) {
|
|
75
|
-
console.error(
|
|
60
|
+
console.error('xu.invokeEvent: event_id cannot be empty');
|
|
76
61
|
return false;
|
|
77
62
|
}
|
|
78
63
|
|
|
79
64
|
let ds;
|
|
80
65
|
|
|
81
|
-
for await (const [key, val] of Object.entries(
|
|
82
|
-
Object.assign([], this._session.DS_GLB).reverse()
|
|
83
|
-
)) {
|
|
66
|
+
for await (const [key, val] of Object.entries(Object.assign([], this._session.DS_GLB).reverse())) {
|
|
84
67
|
let ds_val = val;
|
|
85
68
|
let ds_key = ds_val.dsSession;
|
|
86
|
-
const _view_obj = await this.func.utils.VIEWS_OBJ.get(
|
|
87
|
-
this.SESSION_ID,
|
|
88
|
-
ds_val.prog_id
|
|
89
|
-
);
|
|
69
|
+
const _view_obj = await this.func.utils.VIEWS_OBJ.get(this.SESSION_ID, ds_val.prog_id);
|
|
90
70
|
if (_.isEmpty(_view_obj.progEvents)) continue;
|
|
91
71
|
if (ds) break;
|
|
92
72
|
|
|
93
73
|
for await (const [key, val] of Object.entries(_view_obj.progEvents)) {
|
|
94
|
-
if (
|
|
95
|
-
val?.data?.type === "user_defined" &&
|
|
96
|
-
val.data.event_name === event_id
|
|
97
|
-
) {
|
|
74
|
+
if (val?.data?.type === 'user_defined' && val.data.event_name === event_id) {
|
|
98
75
|
ds = ds_key;
|
|
99
76
|
break;
|
|
100
77
|
}
|
|
101
78
|
}
|
|
102
79
|
}
|
|
103
80
|
|
|
104
|
-
if (typeof ds ===
|
|
105
|
-
this.reject(
|
|
106
|
-
"xu.invokeEvent error",
|
|
107
|
-
`${event_id} event_id not found`,
|
|
108
|
-
this.job_id
|
|
109
|
-
);
|
|
81
|
+
if (typeof ds === 'undefined') {
|
|
82
|
+
this.reject('xu.invokeEvent error', `${event_id} event_id not found`, this.job_id);
|
|
110
83
|
return false;
|
|
111
84
|
}
|
|
112
85
|
|
|
113
|
-
return this.func.events.validate(
|
|
114
|
-
this.SESSION_ID,
|
|
115
|
-
"user_defined",
|
|
116
|
-
ds,
|
|
117
|
-
event_id
|
|
118
|
-
);
|
|
86
|
+
return this.func.events.validate(this.SESSION_ID, 'user_defined', ds, event_id);
|
|
119
87
|
}
|
|
120
88
|
|
|
121
89
|
async read_drive(filename, cb) {
|
|
122
90
|
try {
|
|
123
|
-
const response = await fetch(
|
|
124
|
-
`https://${this._session.domain}/workspace-drive/` +
|
|
125
|
-
filename +
|
|
126
|
-
"&" +
|
|
127
|
-
this._session.gtp_token
|
|
128
|
-
);
|
|
91
|
+
const response = await fetch(`https://${this._session.domain}/workspace-drive/` + filename + '&' + this._session.gtp_token);
|
|
129
92
|
if (cb) {
|
|
130
93
|
return cb(await response.json());
|
|
131
94
|
}
|
|
@@ -133,7 +96,7 @@ export class XudaModule {
|
|
|
133
96
|
return await response.json();
|
|
134
97
|
} catch (e) {
|
|
135
98
|
console.error(e);
|
|
136
|
-
this.reject(
|
|
99
|
+
this.reject('xu.readDrive error', e, this.job_id);
|
|
137
100
|
}
|
|
138
101
|
}
|
|
139
102
|
|
|
@@ -143,27 +106,24 @@ export class XudaModule {
|
|
|
143
106
|
gtp_token: this._session.gtp_token,
|
|
144
107
|
app_token: this._session.app_token,
|
|
145
108
|
|
|
146
|
-
req_from_api:
|
|
147
|
-
public: make_public ?
|
|
109
|
+
req_from_api: 'true',
|
|
110
|
+
public: make_public ? 'true' : '',
|
|
148
111
|
};
|
|
149
112
|
const form = new FormData();
|
|
150
113
|
for (const [key, val] of Object.entries(data)) {
|
|
151
114
|
form.append(key, val);
|
|
152
115
|
}
|
|
153
116
|
|
|
154
|
-
form.append(
|
|
117
|
+
form.append('file', stream, filename);
|
|
155
118
|
try {
|
|
156
|
-
const response = await fetch(
|
|
157
|
-
|
|
158
|
-
{
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
body: JSON.stringify(form),
|
|
165
|
-
}
|
|
166
|
-
);
|
|
119
|
+
const response = await fetch(this.func.common.get_url(this.SESSION_ID, 'rpi', 'runtime_upload_file'), {
|
|
120
|
+
method: 'POST',
|
|
121
|
+
headers: {
|
|
122
|
+
Accept: 'application/json',
|
|
123
|
+
'Content-Type': 'application/json',
|
|
124
|
+
},
|
|
125
|
+
body: JSON.stringify(form),
|
|
126
|
+
});
|
|
167
127
|
if (cb) {
|
|
168
128
|
return cb(await response.json());
|
|
169
129
|
}
|
|
@@ -171,7 +131,7 @@ export class XudaModule {
|
|
|
171
131
|
return await response.json();
|
|
172
132
|
} catch (e) {
|
|
173
133
|
console.error(e);
|
|
174
|
-
this.reject(
|
|
134
|
+
this.reject('xu.writeDrive error', e, this.job_id);
|
|
175
135
|
}
|
|
176
136
|
}
|
|
177
137
|
|
|
@@ -188,7 +148,7 @@ export class XudaModule {
|
|
|
188
148
|
if (job_id) {
|
|
189
149
|
this.func.events.delete_job(this.SESSION_ID, job_id);
|
|
190
150
|
}
|
|
191
|
-
this.log(
|
|
151
|
+
this.log('E', msg, details);
|
|
192
152
|
}
|
|
193
153
|
|
|
194
154
|
log(type, msg, details) {
|
|
@@ -201,54 +161,27 @@ export class XudaModule {
|
|
|
201
161
|
type, // error, warn, info, log
|
|
202
162
|
display, // console, modal, toast, browser
|
|
203
163
|
details,
|
|
204
|
-
msg
|
|
164
|
+
msg,
|
|
205
165
|
);
|
|
206
166
|
}
|
|
207
167
|
|
|
208
168
|
async call_project_api(prog_id, params, cb) {
|
|
209
|
-
const _prog_obj = await this.func.utils.DOCS_OBJ.get(
|
|
210
|
-
this.SESSION_ID,
|
|
211
|
-
prog_id
|
|
212
|
-
);
|
|
169
|
+
const _prog_obj = await this.func.utils.DOCS_OBJ.get(this.SESSION_ID, prog_id);
|
|
213
170
|
|
|
214
|
-
if (_prog_obj?.properties?.menuType !==
|
|
215
|
-
return this.reject(
|
|
216
|
-
"xu.callApiProgram error",
|
|
217
|
-
`${prog_id} is not an API program`,
|
|
218
|
-
this.job_id
|
|
219
|
-
);
|
|
171
|
+
if (_prog_obj?.properties?.menuType !== 'api') {
|
|
172
|
+
return this.reject('xu.callApiProgram error', `${prog_id} is not an API program`, this.job_id);
|
|
220
173
|
}
|
|
221
174
|
// also call internal API if call made from the server itself
|
|
222
|
-
if (this._session.engine_mode ===
|
|
223
|
-
const ret = await this.func.datasource.prepare(
|
|
224
|
-
this.SESSION_ID,
|
|
225
|
-
prog_id,
|
|
226
|
-
null,
|
|
227
|
-
0,
|
|
228
|
-
null,
|
|
229
|
-
null,
|
|
230
|
-
null,
|
|
231
|
-
null,
|
|
232
|
-
null,
|
|
233
|
-
null,
|
|
234
|
-
"api",
|
|
235
|
-
null,
|
|
236
|
-
null,
|
|
237
|
-
null,
|
|
238
|
-
params
|
|
239
|
-
);
|
|
175
|
+
if (this._session.engine_mode === 'live_preview' || typeof IS_PROCESS_SERVER !== 'undefined') {
|
|
176
|
+
const ret = await this.func.datasource.prepare(this.SESSION_ID, prog_id, null, 0, null, null, null, null, null, null, 'api', null, null, null, params);
|
|
240
177
|
try {
|
|
241
178
|
const _ds = this._session.DS_GLB[ret.dsSessionP];
|
|
242
179
|
|
|
243
|
-
if (
|
|
244
|
-
|
|
245
|
-
typeof _ds.tree_obj.apiOutput === "undefined" ||
|
|
246
|
-
!_ds.tree_obj.apiOutput
|
|
247
|
-
) {
|
|
248
|
-
throw new Error("undefined api_rendered_output/apiOutput");
|
|
180
|
+
if (typeof _ds.api_rendered_output === 'undefined' || typeof _ds.tree_obj.apiOutput === 'undefined' || !_ds.tree_obj.apiOutput) {
|
|
181
|
+
throw new Error('undefined api_rendered_output/apiOutput');
|
|
249
182
|
}
|
|
250
183
|
|
|
251
|
-
if (_ds.tree_obj.apiOutput ===
|
|
184
|
+
if (_ds.tree_obj.apiOutput === 'json') {
|
|
252
185
|
try {
|
|
253
186
|
return JSON5.parse(_ds.api_rendered_output);
|
|
254
187
|
} catch (err) {
|
|
@@ -258,24 +191,42 @@ export class XudaModule {
|
|
|
258
191
|
}
|
|
259
192
|
return _ds.api_rendered_output;
|
|
260
193
|
} catch (e) {
|
|
261
|
-
this.reject(
|
|
194
|
+
this.reject('xu.call_project_api error', e.message || e, this.job_id);
|
|
262
195
|
}
|
|
263
196
|
}
|
|
264
197
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
{
|
|
271
|
-
method: "POST",
|
|
198
|
+
// cms
|
|
199
|
+
if (['cms'].includes(this._session.engine_mode)) {
|
|
200
|
+
try {
|
|
201
|
+
const response = await fetch(`https://${this._session.domain}/api`, {
|
|
202
|
+
method: 'POST',
|
|
272
203
|
headers: {
|
|
273
|
-
Accept:
|
|
274
|
-
|
|
204
|
+
Accept: 'application/json',
|
|
205
|
+
'Content-Type': 'application/json',
|
|
275
206
|
},
|
|
276
207
|
body: JSON.stringify({ ...params, ...{ prog_id } }),
|
|
208
|
+
});
|
|
209
|
+
if (cb) {
|
|
210
|
+
return cb(await response.json());
|
|
277
211
|
}
|
|
278
|
-
|
|
212
|
+
|
|
213
|
+
return await response.json();
|
|
214
|
+
} catch (e) {
|
|
215
|
+
console.error(e);
|
|
216
|
+
this.reject('xu.get_table_data error', e, this.job_id);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// deployments
|
|
221
|
+
try {
|
|
222
|
+
const response = await fetch(`https://${this._session.domain}/execute_api_program`, {
|
|
223
|
+
method: 'POST',
|
|
224
|
+
headers: {
|
|
225
|
+
Accept: 'application/json',
|
|
226
|
+
'Content-Type': 'application/json',
|
|
227
|
+
},
|
|
228
|
+
body: JSON.stringify({ ...params, ...{ prog_id } }),
|
|
229
|
+
});
|
|
279
230
|
if (cb) {
|
|
280
231
|
return cb(await response.json());
|
|
281
232
|
}
|
|
@@ -283,7 +234,7 @@ export class XudaModule {
|
|
|
283
234
|
return await response.json();
|
|
284
235
|
} catch (e) {
|
|
285
236
|
console.error(e);
|
|
286
|
-
this.reject(
|
|
237
|
+
this.reject('xu.get_table_data error', e, this.job_id);
|
|
287
238
|
}
|
|
288
239
|
}
|
|
289
240
|
|
|
@@ -298,17 +249,14 @@ export class XudaModule {
|
|
|
298
249
|
...payload,
|
|
299
250
|
};
|
|
300
251
|
|
|
301
|
-
const response = await fetch(
|
|
302
|
-
|
|
303
|
-
{
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
body: JSON.stringify(body),
|
|
310
|
-
}
|
|
311
|
-
);
|
|
252
|
+
const response = await fetch(`https://${this._session.domain}/cpi/${api_method}`, {
|
|
253
|
+
method: 'POST',
|
|
254
|
+
headers: {
|
|
255
|
+
Accept: 'application/json',
|
|
256
|
+
'Content-Type': 'application/json',
|
|
257
|
+
},
|
|
258
|
+
body: JSON.stringify(body),
|
|
259
|
+
});
|
|
312
260
|
|
|
313
261
|
// if (!response.ok) {
|
|
314
262
|
// return { code: response.status, data: response.statusText };
|
|
@@ -322,7 +270,7 @@ export class XudaModule {
|
|
|
322
270
|
return json;
|
|
323
271
|
} catch (e) {
|
|
324
272
|
console.error(e);
|
|
325
|
-
this.reject(
|
|
273
|
+
this.reject('xu.call_system_api error', e, this.job_id);
|
|
326
274
|
}
|
|
327
275
|
}
|
|
328
276
|
|
|
@@ -340,8 +288,8 @@ export class XudaModule {
|
|
|
340
288
|
const response = await fetch(`https://${url}`, {
|
|
341
289
|
method,
|
|
342
290
|
headers: {
|
|
343
|
-
Accept:
|
|
344
|
-
|
|
291
|
+
Accept: 'application/json',
|
|
292
|
+
'Content-Type': 'application/json',
|
|
345
293
|
},
|
|
346
294
|
body: JSON.stringify(json),
|
|
347
295
|
});
|
|
@@ -352,180 +300,101 @@ export class XudaModule {
|
|
|
352
300
|
return await response.json();
|
|
353
301
|
} catch (e) {
|
|
354
302
|
console.error(e);
|
|
355
|
-
this.reject(
|
|
303
|
+
this.reject('xu.call_external_api error', e, this.job_id);
|
|
356
304
|
}
|
|
357
305
|
}
|
|
358
306
|
|
|
359
307
|
async call_javascript(prog_id, params = {}, evaluate = false) {
|
|
360
308
|
try {
|
|
309
|
+
const module = await this.func.common.get_module(this.SESSION_ID, 'xuda-event-javascript-module.mjs');
|
|
361
310
|
|
|
362
|
-
const
|
|
363
|
-
this.SESSION_ID,
|
|
364
|
-
"xuda-event-javascript-module.mjs"
|
|
365
|
-
);
|
|
311
|
+
const result = await module.call_javascript(this.SESSION_ID, this.job_id, { prog: prog_id, parameters: params }, this.dsSession, evaluate);
|
|
366
312
|
|
|
367
|
-
|
|
368
|
-
this.SESSION_ID,
|
|
369
|
-
this.job_id,
|
|
370
|
-
{ prog: prog_id, parameters: params },
|
|
371
|
-
this.dsSession,
|
|
372
|
-
evaluate,
|
|
373
|
-
);
|
|
374
|
-
|
|
375
|
-
return result
|
|
313
|
+
return result;
|
|
376
314
|
} catch (e) {
|
|
377
315
|
console.error(e);
|
|
378
|
-
this.reject(
|
|
316
|
+
this.reject('xu.call_javascript error', e, this.job_id);
|
|
379
317
|
}
|
|
380
318
|
}
|
|
381
319
|
|
|
382
|
-
|
|
383
320
|
async dbs_create(table_id, data, cb) {
|
|
384
|
-
const _table_obj = await this.func.utils.DOCS_OBJ.get(
|
|
385
|
-
this.SESSION_ID,
|
|
386
|
-
table_id
|
|
387
|
-
);
|
|
321
|
+
const _table_obj = await this.func.utils.DOCS_OBJ.get(this.SESSION_ID, table_id);
|
|
388
322
|
|
|
389
|
-
if (_table_obj?.properties?.menuType !==
|
|
390
|
-
return this.reject(
|
|
391
|
-
"xu.dbsCreate error",
|
|
392
|
-
`${table_id} is not a table`,
|
|
393
|
-
this.job_id
|
|
394
|
-
);
|
|
323
|
+
if (_table_obj?.properties?.menuType !== 'table') {
|
|
324
|
+
return this.reject('xu.dbsCreate error', `${table_id} is not a table`, this.job_id);
|
|
395
325
|
}
|
|
396
326
|
|
|
397
|
-
|
|
398
327
|
try {
|
|
399
|
-
|
|
400
|
-
const ret = await this.func.common.db(
|
|
401
|
-
this.SESSION_ID,
|
|
402
|
-
"dbs_create",
|
|
403
|
-
{ table_id, table_data: data },
|
|
404
|
-
|
|
405
|
-
);
|
|
328
|
+
const ret = await this.func.common.db(this.SESSION_ID, 'dbs_create', { table_id, table_data: data });
|
|
406
329
|
if (cb) {
|
|
407
|
-
return cb(ret)
|
|
330
|
+
return cb(ret);
|
|
408
331
|
}
|
|
409
|
-
return ret
|
|
410
|
-
|
|
332
|
+
return ret;
|
|
411
333
|
} catch (e) {
|
|
412
334
|
console.error(e);
|
|
413
|
-
this.reject(
|
|
335
|
+
this.reject('xu.dbs_create error', e, this.job_id);
|
|
414
336
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
337
|
}
|
|
418
338
|
async dbs_read(table_id, selector = {}, fields = [], sort, limit = 999, skip, cb) {
|
|
419
|
-
const _table_obj = await this.func.utils.DOCS_OBJ.get(
|
|
420
|
-
this.SESSION_ID,
|
|
421
|
-
table_id
|
|
422
|
-
);
|
|
339
|
+
const _table_obj = await this.func.utils.DOCS_OBJ.get(this.SESSION_ID, table_id);
|
|
423
340
|
|
|
424
|
-
if (_table_obj?.properties?.menuType !==
|
|
425
|
-
return this.reject(
|
|
426
|
-
"xu.dbsRead error",
|
|
427
|
-
`${table_id} is not a table`,
|
|
428
|
-
this.job_id
|
|
429
|
-
);
|
|
341
|
+
if (_table_obj?.properties?.menuType !== 'table') {
|
|
342
|
+
return this.reject('xu.dbsRead error', `${table_id} is not a table`, this.job_id);
|
|
430
343
|
}
|
|
431
|
-
let data = { fields, table_id, dataSourceFilterModelType:
|
|
344
|
+
let data = { fields, table_id, dataSourceFilterModelType: 'query', filterModelMongo: selector, limit, skip, sort };
|
|
432
345
|
|
|
433
346
|
try {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
const ret = await this.func.common.db(
|
|
437
|
-
this.SESSION_ID,
|
|
438
|
-
"dbs_read",
|
|
439
|
-
data,
|
|
440
|
-
|
|
441
|
-
);
|
|
347
|
+
const ret = await this.func.common.db(this.SESSION_ID, 'dbs_read', data);
|
|
442
348
|
if (cb) {
|
|
443
|
-
return cb(ret)
|
|
349
|
+
return cb(ret);
|
|
444
350
|
}
|
|
445
|
-
return ret
|
|
446
|
-
|
|
351
|
+
return ret;
|
|
447
352
|
} catch (e) {
|
|
448
353
|
console.error(e);
|
|
449
|
-
this.reject(
|
|
354
|
+
this.reject('xu.dbs_read error', e, this.job_id);
|
|
450
355
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
356
|
}
|
|
454
357
|
async dbs_update(table_id, row_id, data, cb) {
|
|
455
|
-
const _table_obj = await this.func.utils.DOCS_OBJ.get(
|
|
456
|
-
this.SESSION_ID,
|
|
457
|
-
table_id
|
|
458
|
-
);
|
|
358
|
+
const _table_obj = await this.func.utils.DOCS_OBJ.get(this.SESSION_ID, table_id);
|
|
459
359
|
|
|
460
|
-
if (_table_obj?.properties?.menuType !==
|
|
461
|
-
return this.reject(
|
|
462
|
-
"xu.dbsUpdate error",
|
|
463
|
-
`${table_id} is not a table`,
|
|
464
|
-
this.job_id
|
|
465
|
-
);
|
|
360
|
+
if (_table_obj?.properties?.menuType !== 'table') {
|
|
361
|
+
return this.reject('xu.dbsUpdate error', `${table_id} is not a table`, this.job_id);
|
|
466
362
|
}
|
|
467
363
|
|
|
468
364
|
if (!row_id) {
|
|
469
|
-
return this.reject(
|
|
470
|
-
"xu.dbsDelete error",
|
|
471
|
-
`row_id is a mandatory field`,
|
|
472
|
-
this.job_id
|
|
473
|
-
);
|
|
365
|
+
return this.reject('xu.dbsDelete error', `row_id is a mandatory field`, this.job_id);
|
|
474
366
|
}
|
|
475
367
|
|
|
476
368
|
try {
|
|
477
|
-
const ret = await this.func.common.db(
|
|
478
|
-
this.SESSION_ID,
|
|
479
|
-
"dbs_update",
|
|
480
|
-
{ table_id, row_id, table_data: data },
|
|
481
|
-
|
|
482
|
-
);
|
|
369
|
+
const ret = await this.func.common.db(this.SESSION_ID, 'dbs_update', { table_id, row_id, table_data: data });
|
|
483
370
|
if (cb) {
|
|
484
|
-
return cb(ret)
|
|
371
|
+
return cb(ret);
|
|
485
372
|
}
|
|
486
|
-
return ret
|
|
373
|
+
return ret;
|
|
487
374
|
} catch (e) {
|
|
488
375
|
console.error(e);
|
|
489
|
-
this.reject(
|
|
376
|
+
this.reject('xu.dbs_update error', e, this.job_id);
|
|
490
377
|
}
|
|
491
378
|
}
|
|
492
379
|
async dbs_delete(table_id, row_id, cb) {
|
|
493
|
-
const _table_obj = await this.func.utils.DOCS_OBJ.get(
|
|
494
|
-
this.SESSION_ID,
|
|
495
|
-
table_id
|
|
496
|
-
);
|
|
380
|
+
const _table_obj = await this.func.utils.DOCS_OBJ.get(this.SESSION_ID, table_id);
|
|
497
381
|
|
|
498
|
-
if (_table_obj?.properties?.menuType !==
|
|
499
|
-
return this.reject(
|
|
500
|
-
"xu.dbsDelete error",
|
|
501
|
-
`${table_id} is not a table`,
|
|
502
|
-
this.job_id
|
|
503
|
-
);
|
|
382
|
+
if (_table_obj?.properties?.menuType !== 'table') {
|
|
383
|
+
return this.reject('xu.dbsDelete error', `${table_id} is not a table`, this.job_id);
|
|
504
384
|
}
|
|
505
385
|
if (!row_id) {
|
|
506
|
-
return this.reject(
|
|
507
|
-
"xu.dbsDelete error",
|
|
508
|
-
`row_id is a mandatory field`,
|
|
509
|
-
this.job_id
|
|
510
|
-
);
|
|
386
|
+
return this.reject('xu.dbsDelete error', `row_id is a mandatory field`, this.job_id);
|
|
511
387
|
}
|
|
512
388
|
|
|
513
389
|
try {
|
|
514
|
-
const ret = await this.func.common.db(
|
|
515
|
-
this.SESSION_ID,
|
|
516
|
-
"dbs_delete",
|
|
517
|
-
{ table_id, ids: [row_id] },
|
|
518
|
-
|
|
519
|
-
);
|
|
390
|
+
const ret = await this.func.common.db(this.SESSION_ID, 'dbs_delete', { table_id, ids: [row_id] });
|
|
520
391
|
if (cb) {
|
|
521
|
-
return cb(ret)
|
|
392
|
+
return cb(ret);
|
|
522
393
|
}
|
|
523
|
-
return ret
|
|
524
|
-
|
|
394
|
+
return ret;
|
|
525
395
|
} catch (e) {
|
|
526
396
|
console.error(e);
|
|
527
|
-
this.reject(
|
|
397
|
+
this.reject('xu.dbs_delete error', e, this.job_id);
|
|
528
398
|
}
|
|
529
399
|
}
|
|
530
400
|
}
|
|
531
|
-
|