@xuda.io/runtime-bundle 1.0.323 → 1.0.325
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-event-javascript-module.min.mjs +2 -2
- package/js/modules/xuda-event-javascript-module.mjs +40 -101
- package/js/xuda-runtime-bundle.js +144 -306
- package/js/xuda-runtime-bundle.min.js +3 -3
- package/js/xuda-runtime-slim.js +144 -306
- package/js/xuda-runtime-slim.min.es.js +144 -306
- package/js/xuda-runtime-slim.min.js +3 -3
- package/js/xuda-server-bundle.min.mjs +2 -2
- package/js/xuda-server-bundle.mjs +140 -302
- package/js/xuda-worker-bundle.js +140 -302
- package/js/xuda-worker-bundle.min.js +2 -2
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export const run_javascript=async function(SESSION_ID,jobNoP,dsSession,script,evaluate,prog_id,params){const _session=SESSION_OBJ[SESSION_ID];const run_native_javascript_program_in_browser=async function(){const path_to_dist=`https://${_session.domain}/studio-drive/${APP_OBJ[_session.app_id].app_replicate||_session.app_id}/scripts/${prog_id}/dist/`;const index_mjs=await import(`${path_to_dist}index.mjs`);if(index_mjs.css){const css_url=`${path_to_dist}index.css`;func.utils.load_css_on_demand(css_url)}const code=func.utils.replace_studio_drive_url(SESSION_ID,index_mjs.default);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:dsSession,jobNoP:jobNoP});const xu=api_utils;const ret=await code(params,xu,SESSION_ID,SESSION_OBJ,jobNoP);if(!code.toString().includes("func.api.callback")){func.events.delete_job(SESSION_ID,jobNoP)}return ret};const run_native_javascript_program_in_server=async function(){return new Promise(async(resolve,reject)=>{const studio_drive_script_folder=path.join(_conf.studio_drive_path,app_id,"scripts");const studio_drive_script_program_folder=path.join(studio_drive_script_folder,prog_id);const dist=path.join(studio_drive_script_program_folder,"dist");const index_mjs=path.join(dist,"index.mjs");process.on("uncaughtException",err=>{console.error("Asynchronous error caught.",err)});const resolve_local=function(e){if(!script.toString().includes("func.api.callback")){func.events.delete_job(SESSION_ID,jobNoP)}resolve(e)};const reject_local=function(e){func.events.delete_job(SESSION_ID,jobNoP);reject(e)};try{const script=new VM.VMScript(`
|
|
1
|
+
export const run_javascript=async function(SESSION_ID,jobNoP,dsSession,script,evaluate,prog_id,params,evt){const _session=SESSION_OBJ[SESSION_ID];const run_native_javascript_program_in_browser=async function(){const path_to_dist=`https://${_session.domain}/studio-drive/${APP_OBJ[_session.app_id].app_replicate||_session.app_id}/scripts/${prog_id}/dist/`;const index_mjs=await import(`${path_to_dist}index.mjs`);if(index_mjs.css){const css_url=`${path_to_dist}index.css`;func.utils.load_css_on_demand(css_url)}const code=func.utils.replace_studio_drive_url(SESSION_ID,index_mjs.default);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:dsSession,jobNoP:jobNoP});const xu=api_utils;const ret=await code(params,xu,SESSION_ID,SESSION_OBJ,jobNoP);if(!code.toString().includes("func.api.callback")){func.events.delete_job(SESSION_ID,jobNoP)}return ret};const run_native_javascript_program_in_server=async function(){return new Promise(async(resolve,reject)=>{const studio_drive_script_folder=path.join(_conf.studio_drive_path,app_id,"scripts");const studio_drive_script_program_folder=path.join(studio_drive_script_folder,prog_id);const dist=path.join(studio_drive_script_program_folder,"dist");const index_mjs=path.join(dist,"index.mjs");process.on("uncaughtException",err=>{console.error("Asynchronous error caught.",err)});const resolve_local=function(e){if(!script.toString().includes("func.api.callback")){func.events.delete_job(SESSION_ID,jobNoP)}resolve(e)};const reject_local=function(e){func.events.delete_job(SESSION_ID,jobNoP);reject(e)};try{const script=new VM.VMScript(`
|
|
2
2
|
const index_mjs = await import(${index_mjs});
|
|
3
3
|
|
|
4
|
-
try{index_mjs.default(req,params,setup_doc,resolve,reject);}catch(e){ console.error(e); }`,{filename:dist,dirname:dist});let vm=new VM.NodeVM({require:{external:true},sandbox:{resolve:resolve_local,reject:reject_local},timeout:6e4});return await vm.run(script,{filename:dist,dirname:dist})}catch(err){console.error("Failed to execute script.",err)}})};if(evaluate){var script_ret=(await func.expression.get(SESSION_ID,script,dsSession,"javascript",null,null,null,null,null,null,null,()=>{},jobNoP)).result}else{if(prog_id){if(typeof IS_API_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined"||typeof IS_PROCESS_SERVER!=="undefined"){return await run_native_javascript_program_in_server()}else{return await run_native_javascript_program_in_browser()}}else{await func.expression.secure_eval(SESSION_ID,"javascript",func.utils.replace_studio_drive_url(SESSION_ID,script),jobNoP,dsSession,()=>{})}}if(!script.includes("func.api.callback")){func.events.delete_job(SESSION_ID,jobNoP);return}};export const call_javascript=async function(SESSION_ID,jobNoP,refIdP,dsSession,evaluate){const error_log=async function(msg){let _session=SESSION_OBJ[SESSION_ID];func.events.delete_job(SESSION_ID,jobNoP);if(typeof IS_API_SERVER!=="undefined"){return __.rpi.write_log(_session.app_id,"error","api",msg)}if(typeof IS_DOCKER!=="undefined"){return __.rpi.write_log(_session.app_id,"error","worker",msg)}await func.common.db(SESSION_ID,"write_log",{msg:msg,log_type:"error",source:"runtime"})};let view_ret=await func.utils.VIEWS_OBJ.get(SESSION_ID,refIdP.prog);if(!view_ret){return error_log("program not found")}if(!view_ret?.scriptData?.value){return error_log("script is empty")}return await run_javascript(SESSION_ID,jobNoP,dsSession,`(async function(${refIdP?.parameters||{}}) {
|
|
4
|
+
try{index_mjs.default(req,params,setup_doc,resolve,reject);}catch(e){ console.error(e); }`,{filename:dist,dirname:dist});let vm=new VM.NodeVM({require:{external:true},sandbox:{resolve:resolve_local,reject:reject_local},timeout:6e4});return await vm.run(script,{filename:dist,dirname:dist})}catch(err){console.error("Failed to execute script.",err)}})};if(evaluate){var script_ret=(await func.expression.get(SESSION_ID,script,dsSession,"javascript",null,null,null,null,null,null,null,()=>{},jobNoP)).result}else{if(prog_id){if(typeof IS_API_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined"||typeof IS_PROCESS_SERVER!=="undefined"){return await run_native_javascript_program_in_server()}else{return await run_native_javascript_program_in_browser()}}else{await func.expression.secure_eval(SESSION_ID,"javascript",func.utils.replace_studio_drive_url(SESSION_ID,script),jobNoP,dsSession,()=>{},evt)}}if(!script.includes("func.api.callback")){func.events.delete_job(SESSION_ID,jobNoP);return}};export const call_javascript=async function(SESSION_ID,jobNoP,refIdP,dsSession,evaluate){const error_log=async function(msg){let _session=SESSION_OBJ[SESSION_ID];func.events.delete_job(SESSION_ID,jobNoP);if(typeof IS_API_SERVER!=="undefined"){return __.rpi.write_log(_session.app_id,"error","api",msg)}if(typeof IS_DOCKER!=="undefined"){return __.rpi.write_log(_session.app_id,"error","worker",msg)}await func.common.db(SESSION_ID,"write_log",{msg:msg,log_type:"error",source:"runtime"})};let view_ret=await func.utils.VIEWS_OBJ.get(SESSION_ID,refIdP.prog);if(!view_ret){return error_log("program not found")}if(!view_ret?.scriptData?.value){return error_log("script is empty")}return await run_javascript(SESSION_ID,jobNoP,dsSession,`(async function(${refIdP?.parameters||{}}) {
|
|
5
5
|
${view_ret.scriptData.value}
|
|
6
6
|
})();`,evaluate,refIdP.prog,refIdP?.parameters)};
|
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
export const run_javascript = async function (
|
|
2
|
-
SESSION_ID,
|
|
3
|
-
jobNoP,
|
|
4
|
-
dsSession,
|
|
5
|
-
script,
|
|
6
|
-
evaluate,
|
|
7
|
-
prog_id,
|
|
8
|
-
params
|
|
9
|
-
) {
|
|
1
|
+
export const run_javascript = async function (SESSION_ID, jobNoP, dsSession, script, evaluate, prog_id, params, evt) {
|
|
10
2
|
const _session = SESSION_OBJ[SESSION_ID];
|
|
11
3
|
|
|
12
4
|
const run_native_javascript_program_in_browser = async function () {
|
|
13
5
|
// run in browser
|
|
14
6
|
|
|
15
7
|
///// insert the css
|
|
16
|
-
const path_to_dist = `https://${_session.domain}/studio-drive/${APP_OBJ[_session.app_id].app_replicate || _session.app_id
|
|
17
|
-
}/scripts/${prog_id}/dist/`;
|
|
8
|
+
const path_to_dist = `https://${_session.domain}/studio-drive/${APP_OBJ[_session.app_id].app_replicate || _session.app_id}/scripts/${prog_id}/dist/`;
|
|
18
9
|
|
|
19
10
|
const index_mjs = await import(`${path_to_dist}index.mjs`);
|
|
20
11
|
|
|
@@ -23,65 +14,47 @@ export const run_javascript = async function (
|
|
|
23
14
|
func.utils.load_css_on_demand(css_url);
|
|
24
15
|
}
|
|
25
16
|
|
|
26
|
-
const code = func.utils.replace_studio_drive_url(
|
|
27
|
-
SESSION_ID,
|
|
28
|
-
index_mjs.default
|
|
29
|
-
);
|
|
17
|
+
const code = func.utils.replace_studio_drive_url(SESSION_ID, index_mjs.default);
|
|
30
18
|
|
|
31
|
-
const api_utils = await func.common.get_module(
|
|
19
|
+
const api_utils = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
|
|
20
|
+
func,
|
|
21
|
+
glb,
|
|
22
|
+
SESSION_OBJ,
|
|
32
23
|
SESSION_ID,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
SESSION_OBJ,
|
|
38
|
-
SESSION_ID,
|
|
39
|
-
APP_OBJ,
|
|
40
|
-
dsSession,
|
|
41
|
-
jobNoP,
|
|
42
|
-
}
|
|
43
|
-
);
|
|
24
|
+
APP_OBJ,
|
|
25
|
+
dsSession,
|
|
26
|
+
jobNoP,
|
|
27
|
+
});
|
|
44
28
|
|
|
45
29
|
const xu = api_utils;
|
|
46
30
|
|
|
47
31
|
const ret = await code(params, xu, SESSION_ID, SESSION_OBJ, jobNoP);
|
|
48
32
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (!code.toString().includes("func.api.callback")) {
|
|
33
|
+
if (!code.toString().includes('func.api.callback')) {
|
|
53
34
|
func.events.delete_job(SESSION_ID, jobNoP);
|
|
54
35
|
}
|
|
55
|
-
return ret
|
|
36
|
+
return ret;
|
|
56
37
|
};
|
|
57
38
|
|
|
58
39
|
const run_native_javascript_program_in_server = async function () {
|
|
59
40
|
return new Promise(async (resolve, reject) => {
|
|
60
|
-
const studio_drive_script_folder = path.join(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
const dist = path.join(studio_drive_script_program_folder, "dist");
|
|
72
|
-
const index_mjs = path.join(dist, "index.mjs");
|
|
73
|
-
|
|
74
|
-
process.on("uncaughtException", (err) => {
|
|
75
|
-
console.error("Asynchronous error caught.", err);
|
|
41
|
+
const studio_drive_script_folder = path.join(_conf.studio_drive_path, app_id, 'scripts');
|
|
42
|
+
|
|
43
|
+
const studio_drive_script_program_folder = path.join(studio_drive_script_folder, prog_id);
|
|
44
|
+
|
|
45
|
+
const dist = path.join(studio_drive_script_program_folder, 'dist');
|
|
46
|
+
const index_mjs = path.join(dist, 'index.mjs');
|
|
47
|
+
|
|
48
|
+
process.on('uncaughtException', (err) => {
|
|
49
|
+
console.error('Asynchronous error caught.', err);
|
|
76
50
|
});
|
|
77
51
|
const resolve_local = function (e) {
|
|
78
52
|
// resolve({ code: 1, data: e });
|
|
79
53
|
|
|
80
|
-
if (!script.toString().includes(
|
|
54
|
+
if (!script.toString().includes('func.api.callback')) {
|
|
81
55
|
func.events.delete_job(SESSION_ID, jobNoP);
|
|
82
56
|
}
|
|
83
57
|
|
|
84
|
-
|
|
85
58
|
resolve(e);
|
|
86
59
|
};
|
|
87
60
|
|
|
@@ -98,7 +71,7 @@ export const run_javascript = async function (
|
|
|
98
71
|
const index_mjs = await import(${index_mjs});
|
|
99
72
|
|
|
100
73
|
try{index_mjs.default(req,params,setup_doc,resolve,reject);}catch(e){ console.error(e); }`,
|
|
101
|
-
{ filename: dist, dirname: dist }
|
|
74
|
+
{ filename: dist, dirname: dist },
|
|
102
75
|
);
|
|
103
76
|
let vm = new VM.NodeVM({
|
|
104
77
|
require: {
|
|
@@ -115,94 +88,60 @@ export const run_javascript = async function (
|
|
|
115
88
|
dirname: dist,
|
|
116
89
|
});
|
|
117
90
|
} catch (err) {
|
|
118
|
-
console.error(
|
|
91
|
+
console.error('Failed to execute script.', err);
|
|
119
92
|
}
|
|
120
93
|
});
|
|
121
94
|
};
|
|
122
95
|
|
|
123
96
|
if (evaluate) {
|
|
124
|
-
var script_ret = (
|
|
125
|
-
await func.expression.get(
|
|
126
|
-
SESSION_ID,
|
|
127
|
-
script,
|
|
128
|
-
dsSession,
|
|
129
|
-
"javascript",
|
|
130
|
-
null,
|
|
131
|
-
null,
|
|
132
|
-
null,
|
|
133
|
-
null,
|
|
134
|
-
null,
|
|
135
|
-
null,
|
|
136
|
-
null,
|
|
137
|
-
() => { },
|
|
138
|
-
jobNoP
|
|
139
|
-
)
|
|
140
|
-
).result;
|
|
97
|
+
var script_ret = (await func.expression.get(SESSION_ID, script, dsSession, 'javascript', null, null, null, null, null, null, null, () => {}, jobNoP)).result;
|
|
141
98
|
} else {
|
|
142
99
|
if (prog_id) {
|
|
143
|
-
if (
|
|
144
|
-
typeof IS_API_SERVER !== "undefined" ||
|
|
145
|
-
typeof IS_DOCKER !== "undefined" ||
|
|
146
|
-
typeof IS_PROCESS_SERVER !== "undefined"
|
|
147
|
-
) {
|
|
100
|
+
if (typeof IS_API_SERVER !== 'undefined' || typeof IS_DOCKER !== 'undefined' || typeof IS_PROCESS_SERVER !== 'undefined') {
|
|
148
101
|
return await run_native_javascript_program_in_server();
|
|
149
102
|
} else {
|
|
150
103
|
return await run_native_javascript_program_in_browser();
|
|
151
104
|
}
|
|
152
105
|
} else {
|
|
153
|
-
await func.expression.secure_eval(
|
|
154
|
-
SESSION_ID,
|
|
155
|
-
"javascript",
|
|
156
|
-
func.utils.replace_studio_drive_url(SESSION_ID, script),
|
|
157
|
-
jobNoP,
|
|
158
|
-
dsSession,
|
|
159
|
-
() => { }
|
|
160
|
-
);
|
|
106
|
+
await func.expression.secure_eval(SESSION_ID, 'javascript', func.utils.replace_studio_drive_url(SESSION_ID, script), jobNoP, dsSession, () => {}, evt);
|
|
161
107
|
}
|
|
162
108
|
}
|
|
163
109
|
|
|
164
|
-
if (!script.includes(
|
|
110
|
+
if (!script.includes('func.api.callback')) {
|
|
165
111
|
func.events.delete_job(SESSION_ID, jobNoP);
|
|
166
112
|
|
|
167
113
|
return;
|
|
168
114
|
}
|
|
169
115
|
};
|
|
170
116
|
|
|
171
|
-
export const call_javascript = async function (
|
|
172
|
-
SESSION_ID,
|
|
173
|
-
jobNoP,
|
|
174
|
-
refIdP,
|
|
175
|
-
dsSession,
|
|
176
|
-
evaluate,
|
|
177
|
-
|
|
178
|
-
) {
|
|
117
|
+
export const call_javascript = async function (SESSION_ID, jobNoP, refIdP, dsSession, evaluate) {
|
|
179
118
|
const error_log = async function (msg) {
|
|
180
119
|
let _session = SESSION_OBJ[SESSION_ID];
|
|
181
120
|
func.events.delete_job(SESSION_ID, jobNoP);
|
|
182
|
-
if (typeof IS_API_SERVER !==
|
|
183
|
-
return __.rpi.write_log(_session.app_id,
|
|
121
|
+
if (typeof IS_API_SERVER !== 'undefined') {
|
|
122
|
+
return __.rpi.write_log(_session.app_id, 'error', 'api', msg);
|
|
184
123
|
}
|
|
185
124
|
|
|
186
|
-
if (typeof IS_DOCKER !==
|
|
187
|
-
return __.rpi.write_log(_session.app_id,
|
|
125
|
+
if (typeof IS_DOCKER !== 'undefined') {
|
|
126
|
+
return __.rpi.write_log(_session.app_id, 'error', 'worker', msg);
|
|
188
127
|
}
|
|
189
128
|
|
|
190
129
|
// client
|
|
191
|
-
await func.common.db(SESSION_ID,
|
|
130
|
+
await func.common.db(SESSION_ID, 'write_log', {
|
|
192
131
|
msg,
|
|
193
|
-
log_type:
|
|
194
|
-
source:
|
|
132
|
+
log_type: 'error',
|
|
133
|
+
source: 'runtime',
|
|
195
134
|
});
|
|
196
135
|
};
|
|
197
136
|
|
|
198
137
|
let view_ret = await func.utils.VIEWS_OBJ.get(SESSION_ID, refIdP.prog);
|
|
199
138
|
|
|
200
139
|
if (!view_ret) {
|
|
201
|
-
return error_log(
|
|
140
|
+
return error_log('program not found');
|
|
202
141
|
}
|
|
203
142
|
|
|
204
143
|
if (!view_ret?.scriptData?.value) {
|
|
205
|
-
return error_log(
|
|
144
|
+
return error_log('script is empty');
|
|
206
145
|
}
|
|
207
146
|
return await run_javascript(
|
|
208
147
|
SESSION_ID,
|
|
@@ -213,6 +152,6 @@ export const call_javascript = async function (
|
|
|
213
152
|
})();`,
|
|
214
153
|
evaluate,
|
|
215
154
|
refIdP.prog,
|
|
216
|
-
refIdP?.parameters
|
|
155
|
+
refIdP?.parameters,
|
|
217
156
|
);
|
|
218
157
|
};
|