@xuda.io/xuda-debug-utils-module 1.0.0

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.
Files changed (2) hide show
  1. package/index.mjs +243 -0
  2. package/package.json +8 -0
package/index.mjs ADDED
@@ -0,0 +1,243 @@
1
+ export const watch = function (
2
+ SESSION_ID,
3
+ key,
4
+ type,
5
+ info,
6
+ result,
7
+ condition,
8
+ not_executed
9
+ ) {
10
+ if (!glb.DEBUG_MODE) return;
11
+ var _session = SESSION_OBJ[SESSION_ID];
12
+ if (!glb?.DEBUG_INFO_OBJ?.command?.watch?.[key]) return;
13
+ var obj = glb.DEBUG_INFO_OBJ.command.watch[key];
14
+ if (!obj) return;
15
+ if (obj.type === type) {
16
+ var result_str = "";
17
+
18
+ if (typeof result !== "object") {
19
+ result_str = " -> " + result;
20
+ }
21
+
22
+ var cond_label = "";
23
+ if (condition) cond_label = "Condition:";
24
+ else condition = "";
25
+ if (!not_executed) {
26
+ console.info(
27
+ "%c Watch: " + obj.name + result_str,
28
+ "color: dark-gray; font-weight: bold;",
29
+ info,
30
+ typeof result === "object" ? result : "",
31
+ cond_label,
32
+ condition
33
+ );
34
+ } else {
35
+ console.info(
36
+ "%c Watch: " + obj.name + result_str,
37
+ "color: gray; font-weight: normal;",
38
+ info,
39
+ typeof result === "object" ? result : "",
40
+ cond_label,
41
+ condition,
42
+ "- NOT EXECUTED !!"
43
+ );
44
+ }
45
+
46
+ const watch_obj = {
47
+ service: "watch_log",
48
+
49
+ data: {
50
+ name: obj.name,
51
+ type: type,
52
+ info: info,
53
+ result: result,
54
+ condition: condition,
55
+ not_executed: not_executed,
56
+ },
57
+ id: STUDIO_WEBSOCKET_CONNECTION_ID,
58
+ uid: _session.USR_OBJ._id,
59
+ source: "runtime",
60
+ app_id: _session.app_id,
61
+ gtp_token: _session.gtp_token,
62
+ app_token: _session.app_token,
63
+ };
64
+ if (
65
+ typeof IS_DOCKER === "undefined" &&
66
+ typeof IS_PROCESS_SERVER === "undefined" &&
67
+ !glb.IS_WORKER
68
+ ) {
69
+ STUDIO_PEER_CONN_SEND_METHOD(watch_obj);
70
+ // STUDIO_WEBSOCKET.emit("message", watch_obj);
71
+ } else {
72
+ func.utils.post_back_to_client(
73
+ SESSION_ID,
74
+ "send_watch_to_studio_websocket",
75
+ _session.worker_id,
76
+ watch_obj
77
+ );
78
+ }
79
+ }
80
+ };
81
+ export const log = function (SESSION_ID, node_idP, jsonP) {
82
+ if (typeof IS_PROCESS_SERVER !== "undefined") return;
83
+ var _session = SESSION_OBJ[SESSION_ID];
84
+
85
+ if (glb.DEBUG_MODE) {
86
+ if (jsonP.error || jsonP.warning) {
87
+ var desc =
88
+ jsonP.action +
89
+ (typeof jsonP.prop !== "undefined"
90
+ ? "Prop: " + jsonP.prop.toString()
91
+ : "") +
92
+ (typeof jsonP.details !== "undefined" &&
93
+ jsonP.details !== jsonP.prop.toString()
94
+ ? " Result: " + jsonP.details.toString()
95
+ : "");
96
+ if (jsonP.error) {
97
+ if (!glb.IS_WORKER)
98
+ func.utils.alerts.toast(
99
+ SESSION_ID,
100
+ typeof jsonP.error !== "boolean" ? jsonP.error : "Error",
101
+ desc,
102
+ "error"
103
+ );
104
+ // console.log(jsonP);
105
+ if (typeof jsonP.error !== "boolean") desc = jsonP.error + ": " + desc;
106
+ console.info(
107
+ "%c Error: " + desc,
108
+ "color: red; font-weight: bold;",
109
+ jsonP
110
+ );
111
+ }
112
+ if (jsonP.warning) {
113
+ if (!glb.IS_WORKER)
114
+ func.utils.alerts.toast(
115
+ SESSION_ID,
116
+ typeof jsonP.warning !== "boolean" ? jsonP.warning : "Warning",
117
+ desc,
118
+ "warning"
119
+ );
120
+
121
+ if (typeof jsonP.warning !== "boolean")
122
+ desc = jsonP.warning + ": " + desc;
123
+
124
+ console.info(
125
+ "%c Warring: " + desc,
126
+ "color: orange; font-weight: bold;",
127
+ jsonP
128
+ );
129
+ // console.log(jsonP);
130
+ }
131
+ }
132
+ }
133
+
134
+ //TRACE_ON
135
+ if (jsonP.error || glb.TRACE_ON) {
136
+ var d = new Date(); //.valueOf();
137
+ var ms = d.getMilliseconds();
138
+ var t =
139
+ _.padStart((d.getHours() + 1).toString(), 2) +
140
+ ":" +
141
+ _.padStart((d.getMinutes() + 1).toString(), 2) +
142
+ ":" +
143
+ _.padStart(d.getSeconds().toString(), 2) +
144
+ ":" +
145
+ _.padStart(ms.toString(), 3);
146
+
147
+ var json_new = _.assignIn(
148
+ {
149
+ node_id: node_idP,
150
+ time: t,
151
+ },
152
+ jsonP
153
+ );
154
+ if (glb.DEBUG_MODE) {
155
+ write(SESSION_ID, json_new);
156
+ }
157
+ if (glb.TRACE_ON) {
158
+ let obj = {
159
+ source: "runtime",
160
+ service: "trace",
161
+ client_id_from: _session.SYS_GLOBAL_OBJ_CLIENT_INFO.fingerprint,
162
+ client_id_to: glb.TRACE_CLIENT_ID,
163
+ data: json_new,
164
+ };
165
+ // if (CPI_WEBSOCKET) {
166
+ // // TBD move to peer
167
+ // CPI_WEBSOCKET.emit("message", obj);
168
+ // }
169
+ }
170
+ }
171
+ };
172
+ export const write = function (SESSION_ID, logP) {
173
+ var _session = SESSION_OBJ[SESSION_ID];
174
+ const obj = {
175
+ service: "debug_log",
176
+ data: { data: logP },
177
+ id: STUDIO_WEBSOCKET_CONNECTION_ID,
178
+ session_id: SESSION_ID,
179
+ uid: _session.USR_OBJ._id,
180
+ source: "runtime",
181
+ app_id: _session.app_id,
182
+ gtp_token: _session.gtp_token,
183
+ app_token: _session.app_token,
184
+
185
+ ts: Date.now(),
186
+ };
187
+ if (_session.engine_mode === "live_preview") {
188
+ if (
189
+ typeof IS_DOCKER === "undefined" &&
190
+ typeof IS_PROCESS_SERVER === "undefined" &&
191
+ !glb.IS_WORKER
192
+ ) {
193
+ if (STUDIO_PEER_CONN_SEND_METHOD) STUDIO_PEER_CONN_SEND_METHOD(obj);
194
+ // STUDIO_WEBSOCKET.emit("message", obj);
195
+ } else if (glb.IS_WORKER) {
196
+ func.utils.post_back_to_client(
197
+ SESSION_ID,
198
+ "write_debug_log",
199
+ _session.worker_id,
200
+ obj
201
+ );
202
+ }
203
+ } else {
204
+ console.log(logP);
205
+ }
206
+ };
207
+
208
+ export const read_command = async function (data) {
209
+ glb.DEBUG_INFO_OBJ.command = data;
210
+ if (!glb.DEBUG_INFO_OBJ.command) return;
211
+ if (glb.DEBUG_INFO_OBJ.command.log === "stop") {
212
+ const module = await func.common.get_module(
213
+ SESSION_ID,
214
+ "xuda-live-preview-module.esm.js"
215
+ );
216
+ module.send_STUDIO_WEBSOCKET(SESSION_ID, "close");
217
+
218
+ window.close();
219
+ return;
220
+ }
221
+
222
+ $.each(WEB_WORKER[SESSION_ID], function (key, val) {
223
+ if (
224
+ RUNTIME_SERVER_WEBSOCKET &&
225
+ RUNTIME_SERVER_WEBSOCKET_CONNECTED &&
226
+ (!_session.opt.app_computing_mode ||
227
+ _session.opt.app_computing_mode === "server")
228
+ ) {
229
+ var obj1 = {
230
+ service: "update_debug_info",
231
+ data: glb.DEBUG_INFO_OBJ,
232
+ id: key,
233
+ };
234
+ WEB_WORKER[SESSION_ID][key].worker.emit("message", obj1);
235
+ } else {
236
+ WEB_WORKER[SESSION_ID][key].worker.postMessage({
237
+ service: "update_debug_info",
238
+ data: glb.DEBUG_INFO_OBJ,
239
+ id: key,
240
+ });
241
+ }
242
+ });
243
+ };
package/package.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@xuda.io/xuda-debug-utils-module",
3
+ "version": "1.0.0",
4
+ "main": "index.mjs",
5
+ "type": "module",
6
+ "description": "Auto-generated build for xuda-debug-utils-module.mjs",
7
+ "author": "Auto Publisher"
8
+ }