@shjjs/visual-ui 3.0.3 → 3.0.4

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.
@@ -207,8 +207,8 @@ const c = class c {
207
207
  const o = this.timerPool.get(t.id);
208
208
  if (o && (clearInterval(o), this.timerPool.delete(t.id)), t.source.isAutoUpdate) {
209
209
  const n = setInterval(() => {
210
- this.executeTask(t, a, r, (s) => {
211
- i(s);
210
+ this.markDataSourceExecuting(t.id), this.executeTask(t, a, r, (s) => {
211
+ i(s), this.markDataSourceCompleted(t.id);
212
212
  });
213
213
  }, t.source.autoUpdateTime * 1e3);
214
214
  this.timerPool.set(t.id, n);
@@ -1,51 +1,72 @@
1
- import { SHJDatasourceV2 as l } from "../index.mjs";
2
- import { httpRequest as f } from "../utils/request.mjs";
3
- import { DataSourceUtils as t } from "../utils/utils.mjs";
4
- const v = (e, h, n) => {
5
- const { api: i } = e.source;
1
+ import { SHJDatasourceV2 as k } from "../index.mjs";
2
+ import { httpRequest as o } from "../utils/request.mjs";
3
+ import { DataSourceUtils as n } from "../utils/utils.mjs";
4
+ const L = async (t, P, l) => {
5
+ var m;
6
+ const e = t == null ? void 0 : t.id, p = (m = t == null ? void 0 : t.source) == null ? void 0 : m.api, a = (c) => {
7
+ l(n.noneData(c));
8
+ };
9
+ if (!p || !e)
10
+ return a(e || "");
11
+ const {
12
+ isHeaders: U,
13
+ isBody: u,
14
+ headers: v,
15
+ contentType: d,
16
+ url: D,
17
+ postParam: E,
18
+ type: y,
19
+ isUseEnv: T = !0
20
+ } = p;
6
21
  try {
7
- if (i) {
8
- let { isHeaders: y, isBody: c, headers: r, contentType: d, url: a, postParam: s } = i;
9
- const E = t.getEnvironments(), o = (U) => {
10
- U.then((m) => {
11
- if (m.status === 200) {
12
- l.processData(
13
- e.source,
14
- m.data,
15
- e.id,
16
- h
17
- ).then((D) => {
18
- D && n(D);
19
- }).catch(() => n(t.noneData(e.id)));
20
- return;
21
- }
22
- n(t.noneData(e.id));
23
- }).catch(() => {
24
- n(t.noneData(e.id));
25
- });
26
- }, p = i.isUseEnv ? E.envBaseUrl : "";
27
- a = t.replaceURLVariables(a), a = t.replaceStringVariables(a), c && (s = t.replaceObjectVariables(s)), y && (r = t.replaceObjectVariables(r)), i.type === "GET" && o(f.get(p + a, { headers: r })), i.type === "POST" && o(
28
- f.post(
29
- p + a,
22
+ const S = n.getEnvironments().envBaseUrl ?? "", V = T ? S : "", g = n.replaceStringVariables(D), i = U ? n.replaceObjectVariables(v) : {}, f = u ? n.replaceObjectVariables(E) : {}, s = V + g;
23
+ if (!s)
24
+ return a(e);
25
+ let r;
26
+ switch (y) {
27
+ case "GET":
28
+ r = o.get(s, { headers: i });
29
+ break;
30
+ case "POST":
31
+ r = o.post(
30
32
  s,
31
- { headers: r },
33
+ f,
34
+ { headers: i },
32
35
  d
33
- )
34
- ), i.type === "PUT" && o(
35
- f.put(
36
- p + a,
36
+ );
37
+ break;
38
+ case "PUT":
39
+ r = o.put(
37
40
  s,
38
- { headers: r },
41
+ f,
42
+ { headers: i },
39
43
  d
40
- )
41
- ), i.type === "DELETE" && o(f.delete(p + a, { headers: r }));
44
+ );
45
+ break;
46
+ case "DELETE":
47
+ r = o.delete(s, {
48
+ headers: i
49
+ });
50
+ break;
51
+ default:
52
+ return a(e);
53
+ }
54
+ const b = await r;
55
+ if (b.status === 200) {
56
+ const h = await k.processData(
57
+ t.source,
58
+ b.data,
59
+ e,
60
+ P
61
+ );
62
+ h ? l(h) : a(e);
42
63
  } else
43
- n(t.noneData(e.id));
64
+ a(e);
44
65
  } catch {
45
- n(t.noneData(e.id));
66
+ a(e);
46
67
  }
47
68
  };
48
69
  export {
49
- f as httpRequest,
50
- v as parseAPIPort
70
+ o as httpRequest,
71
+ L as parseAPIPort
51
72
  };
@@ -1,32 +1,33 @@
1
- import { isArray as u } from "lodash";
2
- const m = (r, a, e, s) => {
3
- if (!u(r))
4
- return r;
5
- let l = null;
6
- return l = r.map((n, c) => {
1
+ import { isArray as c } from "lodash";
2
+ const u = (l, n, r, a) => {
3
+ if (!c(l))
4
+ return l;
5
+ let s = null;
6
+ return s = l.map((e, p) => {
7
7
  const i = {};
8
- return e && c === 0 && (a = f(n, a)), Object.keys(a).forEach((o) => {
9
- const t = a[o];
10
- t.alias ? i[t.alias] = n[t.mapping] : i[t.name] = n[t.mapping];
11
- }), s && (i.userdata = n), i;
12
- }), l;
13
- }, f = (r, a) => {
14
- const e = [];
15
- return Object.keys(r).forEach((s) => {
16
- const l = a.find((n) => n.name === s);
17
- l ? e.push({
18
- alias: l.alias,
19
- name: s,
20
- label: s,
21
- mapping: l.mapping
22
- }) : e.push({
23
- alias: s,
24
- name: s,
25
- label: s,
26
- mapping: s
8
+ return r && p === 0 && (n = f(e, n)), Object.keys(n).forEach((o) => {
9
+ const t = n[o];
10
+ t.alias ? i[t.alias] = e[t.mapping] : i[t.name] = e[t.mapping];
11
+ }), a && (i.userdata = e), i;
12
+ }), s;
13
+ }, f = (l, n) => {
14
+ const r = [];
15
+ return Object.keys(l).forEach((a) => {
16
+ const s = n.find((e) => e.name === a);
17
+ s ? r.push({
18
+ alias: s.alias,
19
+ name: a,
20
+ label: a,
21
+ mapping: s.mapping
22
+ }) : r.push({
23
+ alias: a,
24
+ name: a,
25
+ label: a,
26
+ mapping: a
27
27
  });
28
- }), a.splice(0, a.length), a.push(...e), e;
28
+ }), r;
29
29
  };
30
30
  export {
31
- m as mappingData
31
+ f as dynamicMappingData,
32
+ u as mappingData
32
33
  };
@@ -1,283 +1,137 @@
1
1
  var f = Object.defineProperty;
2
- var d = (l, e, a) => e in l ? f(l, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : l[e] = a;
3
- var c = (l, e, a) => d(l, typeof e != "symbol" ? e + "" : e, a);
4
- import { cloneDeep as h } from "lodash";
5
- import { SHJDatasourceV2 as b } from "../index.mjs";
6
- import { storageData as m } from "./storageData.mjs";
2
+ var b = (l, a, e) => a in l ? f(l, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[a] = e;
3
+ var d = (l, a, e) => b(l, typeof a != "symbol" ? a + "" : a, e);
4
+ import { cloneDeep as g } from "lodash";
5
+ import { SHJDatasourceV2 as u } from "../index.mjs";
6
+ import { storageData as V } from "./storageData.mjs";
7
7
  import "../../event/actions/fullScreenAction.mjs";
8
- import { EventUtils as V } from "../../event/utils/utils.mjs";
9
- const r = class r {
10
- static replaceURLVariables(e) {
11
- try {
12
- const a = e.match(/\${(.*?)}/g);
13
- if (a)
14
- for (let t = 0; t < a.length; t++) {
15
- const i = a[t].substring(2, a[t].length - 1), s = r.extractVariableName(i), n = this.getVariables().find(
16
- (u) => u.name === s
17
- );
18
- if (!n)
19
- continue;
20
- const o = r.getNestedValue(
21
- n._value,
22
- i.substring(s.length)
23
- );
24
- e = e.replaceAll(a[t], o);
8
+ import { EventUtils as m } from "../../event/utils/utils.mjs";
9
+ const i = class i {
10
+ static executeAllVariable(a) {
11
+ a.forEach((e) => {
12
+ e.sources.isVariable = !0;
13
+ }), i.setVariables(a), a.forEach((e) => {
14
+ u.parse({
15
+ sources: [e.sources],
16
+ noUseMapping: !0,
17
+ callback: (t) => {
18
+ i.setVariableById(e, t, !1);
25
19
  }
26
- return e;
27
- } catch {
28
- return e;
29
- }
20
+ });
21
+ });
30
22
  }
31
- static replaceObjectVariables(e) {
32
- const a = this.replaceStringVariables(JSON.stringify(e));
33
- return JSON.parse(a);
23
+ static replaceObjectVariables(a) {
24
+ const e = this.replaceStringVariables(JSON.stringify(a));
25
+ return JSON.parse(e);
34
26
  }
35
- static replaceStringVariables(e) {
36
- try {
37
- const a = e.match(/\$g{(.*?)}/g);
38
- if (a)
39
- for (let t = 0; t < a.length; t++) {
40
- const i = a[t].substring(3, a[t].length - 1), s = this.extractVariableName(i), n = this.getVariables().find(
41
- (u) => u.name === s
42
- );
43
- if (!n)
44
- continue;
45
- const o = this.getNestedValue(
46
- n._value,
47
- i.substring(s.length)
48
- );
49
- e = e.replaceAll(a[t], o);
27
+ static replaceStringVariables(a) {
28
+ return a.replace(/\$g\{([^}]+)\}/g, (e, t) => {
29
+ const { varName: r, propPath: n } = this.parseVariablePath(t), c = this.getVariables().find((o) => o.name === r);
30
+ if (!c)
31
+ return e;
32
+ let s = c._value;
33
+ try {
34
+ for (const o of n) {
35
+ if (s == null) {
36
+ s = void 0;
37
+ break;
38
+ }
39
+ s = s[o];
50
40
  }
51
- return e;
52
- } catch {
53
- return e;
54
- }
55
- }
56
- static getURLVariableNames(e) {
57
- const a = [], t = e.match(/\${(.*?)}/g);
58
- if (t)
59
- for (let i = 0; i < t.length; i++) {
60
- const s = t[i].substring(2, t[i].length - 1), n = r.extractVariableName(s);
61
- a.push(n);
41
+ } catch {
42
+ return "undefined";
62
43
  }
63
- return a;
44
+ return typeof s == "object" ? JSON.stringify(s) : s === void 0 ? "undefined" : String(s);
45
+ });
64
46
  }
65
- static getObjectVariableNames(e) {
66
- return this.getStringVariableNames(JSON.stringify(e));
47
+ static getObjectVariableNames(a) {
48
+ return this.getStringVariableNames(JSON.stringify(a));
67
49
  }
68
- static getStringVariableNames(e) {
69
- const a = [], t = e.match(/\$g{(.*?)}/g);
70
- if (t)
71
- for (let i = 0; i < t.length; i++) {
72
- const s = t[i].substring(3, t[i].length - 1), n = this.extractVariableName(s);
73
- a.push(n);
74
- }
75
- return a;
50
+ static getStringVariableNames(a) {
51
+ const e = /* @__PURE__ */ new Set(), t = /\$g\{([^}]+)\}/g;
52
+ for (const r of a.matchAll(t)) {
53
+ const n = r[1], { varName: c } = this.parseVariablePath(n);
54
+ c && e.add(c);
55
+ }
56
+ return Array.from(e);
57
+ }
58
+ static parseVariablePath(a) {
59
+ const t = a.replace(/\[/g, ".").replace(/\]/g, "").split("."), r = t[0], n = t.slice(1);
60
+ return { varName: r, propPath: n };
76
61
  }
77
- /**
78
- * 获取环境变量
79
- * @returns 环境变量
80
- */
81
62
  static getEnvironments() {
82
63
  return window._apiEnvironment;
83
64
  }
84
- /**
85
- * 设置环境变量
86
- * @param environments 环境变量
87
- */
88
- static setEnvironments(e) {
89
- const a = e.find((t) => t.selected);
90
- a && (window._apiEnvironment = {
91
- envName: a.envName,
92
- envBaseUrl: a.envBaseUrl
65
+ static setEnvironments(a) {
66
+ const e = a.find((t) => t.selected);
67
+ e && (window._apiEnvironment = {
68
+ envName: e.envName,
69
+ envBaseUrl: e.envBaseUrl
93
70
  });
94
71
  }
95
- /**
96
- * 获取变量数据
97
- * @returns 变量数据
98
- */
99
72
  static getVariables() {
100
73
  return window._variables || [];
101
74
  }
102
- /**
103
- * 设置变量数据
104
- * @param variable 变量数据
105
- */
106
- static setVariables(e) {
107
- window._variables = h(e), window._variables.forEach((a) => {
108
- a._callbacks ?? (a._callbacks = /* @__PURE__ */ new Map());
75
+ static setVariables(a) {
76
+ window._variables = g(a), window._variables.forEach((e) => {
77
+ e._callbacks ?? (e._callbacks = /* @__PURE__ */ new Map());
109
78
  });
110
79
  }
111
- /**
112
- *
113
- * @param id
114
- * @returns
115
- */
116
- static getVariableById(e) {
117
- return window._variables.find((a) => a.id === e);
118
- }
119
- /**
120
- *
121
- * @param name
122
- * @returns
123
- */
124
- static getVariableByName(e) {
125
- return window._variables.find((a) => a.name === e);
126
- }
127
- /**
128
- *
129
- * @param name
130
- * @returns
131
- */
132
- static getVariableValueByName(e) {
133
- const a = window._variables.find((t) => t.name === e);
134
- return a ? a._value : null;
135
- }
136
- /**
137
- *
138
- * @param name
139
- * @returns
140
- */
141
- static getVariableInitialStateByName(e) {
142
- const a = window._variables.find((t) => t.name === e);
143
- return a ? a._initialState : null;
144
- }
145
- /**
146
- * 设置变量数据
147
- * @param id 变量 ID
148
- * @param variable 变量数据
149
- */
150
- static setVariableById(e, a, t = !0) {
151
- const i = this.getVariableById(e.id);
152
- if (i) {
153
- i._value = a, i._initialState ?? (i._initialState = !0);
80
+ static setVariableById(a, e, t = !0) {
81
+ const r = this.getVariableById(a.id);
82
+ if (r) {
83
+ r._value = e, r._initialState ?? (r._initialState = !0);
154
84
  try {
155
- m(e.sources.source.storage, a);
85
+ V(a.sources.source.storage, e);
156
86
  } catch {
157
87
  }
158
- i._callbacks ?? (i._callbacks = /* @__PURE__ */ new Map()), i._callbacks.forEach(
159
- (s) => s(e._value)
160
- ), t && V.updateWidgetVariableData(i);
88
+ r._callbacks ?? (r._callbacks = /* @__PURE__ */ new Map()), r._callbacks.forEach(
89
+ (n) => n(a._value)
90
+ ), t && m.updateWidgetVariableData(r);
161
91
  }
162
92
  }
163
- /**
164
- * 检查 WebSocket 是否已存在且有效
165
- * @param wsInstances WebSocket 实例
166
- * @param tId WebSocket 实例的 ID
167
- * @param sourceId WebSocket 实例的源 ID
168
- * @returns 是否有效
169
- */
170
- static hasValidWebSocket(e, a, t) {
171
- const i = e.get(a);
172
- if (!i) return !1;
173
- for (const s of i)
174
- if (s.getId() === t && s.isConnected())
175
- return !0;
176
- return !1;
177
- }
178
- /**
179
- * 只在必要时清理 WebSocket 连接
180
- * @param wsInstances WebSocket 实例
181
- * @param sourceIds 源 ID
182
- * @param tId WebSocket 实例的 ID
183
- */
184
- static cleanupPreviousWebSockets(e, a, t) {
185
- const i = e.get(t);
186
- i && (i.forEach((s) => {
187
- a.includes(s.getId()) || (s.disconnect(), i.delete(s));
188
- }), i.size === 0 && e.delete(t));
189
- }
190
- /**
191
- * 使用 Function 构造函数获取对象中的嵌套值(更简洁但安全性较低)
192
- * @param obj 源对象
193
- * @param path 路径字符串,例如 ".a[0].value"
194
- * @returns 获取到的值,如果路径不存在则返回 undefined
195
- */
196
- static getNestedValue(e, a) {
197
- try {
198
- return a ? new Function("obj", `return obj${a}`)(e) : e;
199
- } catch {
200
- return;
201
- }
93
+ static getVariableById(a) {
94
+ return window._variables.find((e) => e.id === a);
202
95
  }
203
- /**
204
- * 从路径字符串中提取变量名
205
- * @param path 路径字符串,例如 "测试.test" 或 "333[0].aa"
206
- * @returns 提取出的变量名
207
- */
208
- static extractVariableName(e) {
209
- const a = e.match(
210
- /^([\u4e00-\u9fa5a-zA-Z0-9_][\u4e00-\u9fa5a-zA-Z0-9_]*)/
211
- );
212
- return a ? a[1] : "";
96
+ static getVariableByName(a) {
97
+ return window._variables.find((e) => e.name === a);
213
98
  }
214
- /**
215
- * 初始化所有变量
216
- * @param variableData
217
- * @returns
218
- */
219
- static executeAllVariable(e) {
220
- e.forEach((a) => {
221
- a.sources.isVariable = !0;
222
- }), r.setVariables(e), e.forEach((a) => {
223
- b.parse({
224
- sources: [a.sources],
225
- noUseMapping: !0,
226
- callback: (t) => {
227
- r.setVariableById(a, t, !1);
228
- }
229
- });
230
- });
99
+ static getVariableValueByName(a) {
100
+ const e = window._variables.find((t) => t.name === a);
101
+ return e ? e._value : null;
231
102
  }
232
- /**
233
- * 返回空数据
234
- * @param id 数据源 ID
235
- * @returns 空数据
236
- */
237
- static noneData(e) {
103
+ static noneData(a) {
238
104
  return {
239
- id: e,
240
- finalKeyData: { id: e, data: null },
241
- finalUserData: { id: e, data: null },
105
+ id: a,
106
+ finalKeyData: { id: a, data: null },
107
+ finalUserData: { id: a, data: null },
242
108
  filteredData: null,
243
109
  rawData: null,
244
110
  noMappingData: null
245
111
  };
246
112
  }
247
113
  };
248
- /**
249
- * 新增变量
250
- * @param data
251
- */
252
- c(r, "addVariable", (e) => {
253
- b.parse({
254
- sources: [e.sources],
114
+ d(i, "addVariable", (a) => {
115
+ u.parse({
116
+ sources: [a.sources],
255
117
  noUseMapping: !0,
256
- callback: (a) => {
257
- r.getVariables().push(e), r.setVariableById(e, a, !1);
118
+ callback: (e) => {
119
+ i.getVariables().push(a), i.setVariableById(a, e, !1);
258
120
  }
259
121
  });
260
- }), /**
261
- * 更新变量
262
- * @param data
263
- */
264
- c(r, "updateVariable", (e) => {
265
- b.parse({
266
- sources: [e.sources],
122
+ }), d(i, "updateVariable", (a) => {
123
+ u.parse({
124
+ sources: [a.sources],
267
125
  noUseMapping: !0,
268
- callback: (a) => {
269
- r.setVariableById(e, a, !1);
126
+ callback: (e) => {
127
+ i.setVariableById(a, e, !1);
270
128
  }
271
129
  });
272
- }), /**
273
- * 更新变量
274
- * @param data
275
- */
276
- c(r, "deleteVariableById", (e) => {
277
- const a = window._variables.findIndex((t) => t.id === e);
278
- a > -1 && window._variables.splice(a, 1);
130
+ }), d(i, "deleteVariableById", (a) => {
131
+ const e = window._variables.findIndex((t) => t.id === a);
132
+ e > -1 && window._variables.splice(e, 1);
279
133
  });
280
- let g = r;
134
+ let p = i;
281
135
  export {
282
- g as DataSourceUtils
136
+ p as DataSourceUtils
283
137
  };
@@ -1,3 +1,3 @@
1
1
  import { httpRequest } from "../utils/request";
2
- export declare const parseAPIPort: (source: any, noUseMapping: boolean, callback: (data: any) => void) => void;
3
2
  export { httpRequest };
3
+ export declare const parseAPIPort: (source: any, noUseMapping: boolean, callback: (data: any) => void) => Promise<void>;
@@ -1,2 +1,8 @@
1
1
  import { IMapping } from "../types";
2
2
  export declare const mappingData: (data: any[], mapping: IMapping[], dynamicMapping: boolean, isUserdata: boolean) => any;
3
+ export declare const dynamicMappingData: (item: any, mapping: IMapping[]) => {
4
+ alias: string;
5
+ name: string;
6
+ label: string;
7
+ mapping: string;
8
+ }[];