@lcap/nasl 2.18.0-beta.5 → 2.18.0-beta.7

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 (88) hide show
  1. package/out/common/BaseNode.js +1 -0
  2. package/out/common/BaseNode.js.map +1 -1
  3. package/out/concepts/BatchAssignment__.js +63 -46
  4. package/out/concepts/BatchAssignment__.js.map +1 -1
  5. package/out/concepts/CallLogic__.d.ts +2 -1
  6. package/out/concepts/CallLogic__.js +26 -11
  7. package/out/concepts/CallLogic__.js.map +1 -1
  8. package/out/concepts/Destination__.d.ts +2 -1
  9. package/out/concepts/Destination__.js +90 -22
  10. package/out/concepts/Destination__.js.map +1 -1
  11. package/out/concepts/Logic__.js +6 -7
  12. package/out/concepts/Logic__.js.map +1 -1
  13. package/out/concepts/MatchExpression__.d.ts +97 -0
  14. package/out/concepts/MatchExpression__.js +281 -0
  15. package/out/concepts/MatchExpression__.js.map +1 -0
  16. package/out/concepts/ViewElement__.js +1 -1
  17. package/out/concepts/ViewElement__.js.map +1 -1
  18. package/out/concepts/View__.js +4 -0
  19. package/out/concepts/View__.js.map +1 -1
  20. package/out/generator/genBundleFiles.js +32 -182
  21. package/out/generator/genBundleFiles.js.map +1 -1
  22. package/out/generator/genMetaData.d.ts +1 -10
  23. package/out/generator/genMetaData.js +189 -50
  24. package/out/generator/genMetaData.js.map +1 -1
  25. package/out/generator/genReleaseBody.js +11 -2
  26. package/out/generator/genReleaseBody.js.map +1 -1
  27. package/out/server/extendBaseNode.js +4 -18
  28. package/out/server/extendBaseNode.js.map +1 -1
  29. package/out/server/formatTsUtils.d.ts +1 -2
  30. package/out/server/formatTsUtils.js +30 -47
  31. package/out/server/formatTsUtils.js.map +1 -1
  32. package/out/server/getProcesses.js +1 -1
  33. package/out/server/getProcesses.js.map +1 -1
  34. package/out/server/naslServer.js +8 -7
  35. package/out/server/naslServer.js.map +1 -1
  36. package/out/server/translator.js +19 -4
  37. package/out/server/translator.js.map +1 -1
  38. package/out/templator/sql-parser/index.d.ts +1 -0
  39. package/out/templator/sql-parser/index.js +228 -0
  40. package/out/templator/sql-parser/index.js.map +1 -0
  41. package/out/templator/sql-parser/parser.js +26664 -0
  42. package/out/templator/sql-parser/parser.js.map +1 -0
  43. package/package.json +2 -2
  44. package/sandbox/stdlib/dist/nasl.logging.js +0 -0
  45. package/sandbox/stdlib/nasl.util.ts +1 -1
  46. package/src/automate/engine/dist/index.dev.js +517 -0
  47. package/src/common/BaseNode.ts +1 -0
  48. package/src/common/dist/BaseNode.js +1101 -0
  49. package/src/concepts/BatchAssignment__.ts +66 -50
  50. package/src/concepts/CallLogic__.ts +26 -11
  51. package/src/concepts/Destination__.ts +92 -22
  52. package/src/concepts/Logic__.ts +6 -7
  53. package/src/concepts/ViewElement__.ts +8 -29
  54. package/src/concepts/View__.ts +4 -0
  55. package/src/concepts/basics/stdlib/dist/nasl.util.js +1503 -0
  56. package/src/concepts/basics/stdlib/dist/reference2TypeAnnotationList.js +24 -0
  57. package/src/concepts/dist/Anchor__.js +179 -0
  58. package/src/concepts/dist/Assignment__.js +301 -0
  59. package/src/concepts/dist/CallFunction__.js +513 -0
  60. package/src/concepts/dist/CallInterface__.js +533 -0
  61. package/src/concepts/dist/CallLogic__.js +892 -0
  62. package/src/concepts/dist/ForEachStatement__.js +426 -0
  63. package/src/concepts/dist/MatchCase__.js +587 -0
  64. package/src/concepts/dist/Match__.js +631 -0
  65. package/src/concepts/dist/MemberExpression__.js +348 -0
  66. package/src/concepts/dist/Param__.js +538 -0
  67. package/src/concepts/dist/Return__.js +494 -0
  68. package/src/concepts/dist/Variable__.js +537 -0
  69. package/src/concepts/dist/ViewElement__.js +1680 -0
  70. package/src/generator/dist/genBundleFiles.js +261 -0
  71. package/src/generator/dist/genMetaData.js +249 -0
  72. package/src/generator/genBundleFiles.ts +34 -219
  73. package/src/generator/genMetaData.ts +182 -77
  74. package/src/generator/genReleaseBody.ts +10 -3
  75. package/src/server/dist/formatTsUtils.js +683 -0
  76. package/src/server/dist/naslServer.js +3474 -0
  77. package/src/server/extendBaseNode.ts +4 -19
  78. package/src/server/formatTsUtils.ts +30 -46
  79. package/src/server/getProcesses.ts +1 -1
  80. package/src/server/naslServer.ts +8 -7
  81. package/src/server/translator.ts +18 -4
  82. package/src/service/storage/dist/init.js +572 -0
  83. package/ts-worker/dist/webpack.config.dev.js +108 -0
  84. package/dist/bundle.js +0 -3962
  85. package/dist/bundle.js.LICENSE.txt +0 -16
  86. package/out/generator/release.d.ts +0 -1
  87. package/out/generator/release.js +0 -51
  88. package/out/generator/release.js.map +0 -1
@@ -0,0 +1,572 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
39
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
40
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
41
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
42
+ r[k] = a[j];
43
+ return r;
44
+ };
45
+ exports.__esModule = true;
46
+ exports.loadAppSync = exports.loadApp = exports.handleApp = exports.batchAction = exports.batchQuery = void 0;
47
+ var concepts_1 = require("../../concepts");
48
+ var decorators_1 = require("../../decorators");
49
+ var config_1 = require("../../config");
50
+ var vue_1 = require("vue");
51
+ var service_1 = require("./service");
52
+ /// #if !process.env.NODE_ENV || process.env.BUILD_TARGET === 'node'
53
+ var fs = require("fs-extra");
54
+ var jsoner = require("./jsoner");
55
+ /// #endif
56
+ exports.batchQuery = service_1["default"].batchQuery;
57
+ exports.batchAction = service_1["default"].batchAction;
58
+ function getLogic(key, app, diffLogicList) {
59
+ var _a;
60
+ if (!diffLogicList.includes(key)) {
61
+ diffLogicList.push(key);
62
+ if (key.startsWith('app')) {
63
+ var index = key.lastIndexOf('.');
64
+ var name_1 = key.slice(index + 1);
65
+ var logic = app.logics.find(function (item) { return item.name === name_1; });
66
+ if (logic && logic.body && logic.body.length > 2) {
67
+ logic.body.map(function (item) { return getStatement(item, app, diffLogicList); });
68
+ }
69
+ }
70
+ else if (key.startsWith('extensions')) {
71
+ var _pathArr = key.split('.');
72
+ var _name_1 = _pathArr[1];
73
+ var _path_1 = _pathArr[3];
74
+ var _list = app.dependencies;
75
+ var _module = _list.find(function (it) {
76
+ var name = it.name.replaceAll('-', '_');
77
+ return name === _name_1;
78
+ });
79
+ var logic = (_a = _module === null || _module === void 0 ? void 0 : _module.logics) === null || _a === void 0 ? void 0 : _a.find(function (item) { return item.name === _path_1; });
80
+ if (logic && logic.body && logic.body.length > 2) {
81
+ logic.body.map(function (item) { return getStatement(item, app, diffLogicList); });
82
+ }
83
+ }
84
+ }
85
+ }
86
+ /* 获取LogicITEM */
87
+ function getStatement(state, app, diffLogicList) {
88
+ var _a, _b, _c, _d, _e;
89
+ var logicItems = [];
90
+ switch (state.concept) {
91
+ case 'Assignment':
92
+ logicItems = [state.left, state.right];
93
+ break;
94
+ case 'IfStatement':
95
+ logicItems = __spreadArrays(state.consequent, state.alternate);
96
+ break;
97
+ case 'ForEachStatement':
98
+ logicItems = __spreadArrays(state.body, [state.each, state.start, state.end]);
99
+ break;
100
+ case 'Match':
101
+ logicItems = state.cases.map(getStatement).flat(1);
102
+ break;
103
+ case 'MatchCase':
104
+ logicItems = __spreadArrays(state.patterns, state.body);
105
+ break;
106
+ case 'SwitchStatement':
107
+ logicItems = state.cases.map(getStatement).flat(1);
108
+ break;
109
+ case 'SwitchCase':
110
+ logicItems = __spreadArrays([state.test], state.consequent);
111
+ break;
112
+ case 'WhileStatement':
113
+ logicItems = __spreadArrays([state.test], state.body);
114
+ break;
115
+ case 'CallLogic':
116
+ logicItems = (_a = state.arguments) === null || _a === void 0 ? void 0 : _a.map(function (item) { return item.expression; });
117
+ getLogic(state.calleewholeKey, app, diffLogicList);
118
+ break;
119
+ case 'CallFunction':
120
+ logicItems = (_b = state.arguments) === null || _b === void 0 ? void 0 : _b.map(function (item) { return item.expression; });
121
+ break;
122
+ case 'CallInterface':
123
+ logicItems = (_c = state.arguments) === null || _c === void 0 ? void 0 : _c.map(function (item) { return item.expression; });
124
+ break;
125
+ case 'BatchAssignment':
126
+ logicItems = __spreadArrays([(_d = state.left) === null || _d === void 0 ? void 0 : _d.expression], (_e = state.left) === null || _e === void 0 ? void 0 : _e.members, state.rights.map(function (item) { return __spreadArrays([item === null || item === void 0 ? void 0 : item.expression], item === null || item === void 0 ? void 0 : item.members); }).flat(1));
127
+ default:
128
+ break;
129
+ }
130
+ return logicItems.filter(function (item) { return !!item; });
131
+ }
132
+ /* 小程序影响的服务端发布 */
133
+ function getMiniAppChange(target, obj, action) {
134
+ var _a;
135
+ if (!target.app.miniEnable) {
136
+ return false;
137
+ }
138
+ /* 分端以后需要改 */
139
+ var len = (_a = target.nodePath) === null || _a === void 0 ? void 0 : _a.split('.').length;
140
+ if (len > 2) {
141
+ return false;
142
+ }
143
+ if (action === 'delete') {
144
+ return true;
145
+ }
146
+ else {
147
+ if ('name' in obj || 'title' in obj) {
148
+ return true;
149
+ }
150
+ }
151
+ }
152
+ /**
153
+ * 执行更新
154
+ */
155
+ function doAction(app, actionItem) {
156
+ return __awaiter(this, void 0, void 0, function () {
157
+ var hasFrontEnd, hasBackEnd, actionList, _a, list, actionMsg, action, itemloop, loopEle, ChangedNASLType, err, error_1, json, actionMap, msg;
158
+ return __generator(this, function (_b) {
159
+ switch (_b.label) {
160
+ case 0:
161
+ app.emit('saving');
162
+ hasFrontEnd = false;
163
+ hasBackEnd = false;
164
+ actionList = [];
165
+ _a = actionItem || {}, list = _a.list, actionMsg = _a.actionMsg, action = _a.action;
166
+ itemloop = function (_i, app, diffArr) {
167
+ var _l = getStatement(_i, app, diffArr);
168
+ if (_l.length) {
169
+ _l.map(function (_ii) { return itemloop(_ii, app, diffArr); });
170
+ }
171
+ };
172
+ loopEle = function (view, checkAuth) {
173
+ var _a, _b;
174
+ if (view instanceof concepts_1.View) {
175
+ (_a = view === null || view === void 0 ? void 0 : view.elements) === null || _a === void 0 ? void 0 : _a.forEach(function (item) { return loopEle(item, checkAuth); });
176
+ }
177
+ (_b = view === null || view === void 0 ? void 0 : view.children) === null || _b === void 0 ? void 0 : _b.forEach(function (item) { return loopEle(item, checkAuth); });
178
+ if (view instanceof concepts_1.ViewElement) {
179
+ if (view.bindEvents.length) {
180
+ var diffArr_1 = [];
181
+ view.bindEvents.forEach(function (bindEvent) {
182
+ bindEvent.logics.forEach(function (logic) {
183
+ logic.body.forEach(function (logicItem) { return itemloop(logicItem, app, diffArr_1); });
184
+ });
185
+ });
186
+ var result = diffArr_1.filter(function (item) { return item.startsWith('app') || item.startsWith('extensions'); });
187
+ if (result.length) {
188
+ hasBackEnd = true;
189
+ }
190
+ }
191
+ if (view.tag === 'u-uploader' || view.tag === 'van-uploader') {
192
+ var bute = view === null || view === void 0 ? void 0 : view.bindAttrs.find(function (item) { return item.name === 'url'; });
193
+ if (checkAuth) {
194
+ if ((bute === null || bute === void 0 ? void 0 : bute.value.endsWith('/import')) && !view.view.parentAuth) {
195
+ hasBackEnd = true;
196
+ }
197
+ }
198
+ else {
199
+ if (bute === null || bute === void 0 ? void 0 : bute.value.endsWith('/import')) {
200
+ hasBackEnd = true;
201
+ }
202
+ }
203
+ }
204
+ }
205
+ };
206
+ try {
207
+ if (Array.isArray(list)) {
208
+ list.forEach(function (event) {
209
+ var _a, _b, _c, _d, _e, _f, _g, _h;
210
+ var emitTarget = (_a = event === null || event === void 0 ? void 0 : event.originEvent) === null || _a === void 0 ? void 0 : _a.target;
211
+ var _path = event.originEvent.path;
212
+ var _root = ((_b = _path.split('.')) === null || _b === void 0 ? void 0 : _b[1]) || '';
213
+ if (['dataSources', 'processes', 'logics', 'enums', 'structures', 'interfaces', 'interfaceDependencies', 'configuration', 'dependencies'].some(function (item) { return _root.startsWith(item); })) {
214
+ hasBackEnd = true;
215
+ }
216
+ if (emitTarget.concept === 'Logic') {
217
+ var diffArr_2 = [];
218
+ if (emitTarget.body.length > 2) {
219
+ emitTarget.body.forEach(function (it) {
220
+ itemloop(it, app, diffArr_2);
221
+ });
222
+ }
223
+ var result = diffArr_2.filter(function (item) { return item.startsWith('app') || item.startsWith('extensions'); });
224
+ if (result.length) {
225
+ hasBackEnd = true;
226
+ }
227
+ }
228
+ if (emitTarget.view) {
229
+ hasFrontEnd = true;
230
+ }
231
+ if (emitTarget.concept === 'View') {
232
+ if (getMiniAppChange(emitTarget, (_c = event === null || event === void 0 ? void 0 : event.originEvent) === null || _c === void 0 ? void 0 : _c.object, (_d = event === null || event === void 0 ? void 0 : event.originEvent) === null || _d === void 0 ? void 0 : _d.action)) {
233
+ hasBackEnd = true;
234
+ }
235
+ var isDelete_1 = ((_e = event === null || event === void 0 ? void 0 : event.originEvent) === null || _e === void 0 ? void 0 : _e.action) === 'delete';
236
+ var isUpdateAuth = ((_f = event === null || event === void 0 ? void 0 : event.originEvent) === null || _f === void 0 ? void 0 : _f.action) === 'update' && ((_g = event === null || event === void 0 ? void 0 : event.originEvent) === null || _g === void 0 ? void 0 : _g.object) && 'auth' in ((_h = event === null || event === void 0 ? void 0 : event.originEvent) === null || _h === void 0 ? void 0 : _h.object);
237
+ if (isDelete_1 || isUpdateAuth) {
238
+ var app_1 = emitTarget.app;
239
+ var diffArr_3 = [];
240
+ emitTarget.logics.forEach(function (logic) {
241
+ if (logic.body.length > 2) {
242
+ logic.body.forEach(function (it) {
243
+ itemloop(it, app_1, diffArr_3);
244
+ });
245
+ }
246
+ });
247
+ var result = diffArr_3.filter(function (item) { return item.startsWith('app') || item.startsWith('extensions'); });
248
+ if (result.length) {
249
+ hasBackEnd = true;
250
+ }
251
+ emitTarget.children.forEach(function (item) { return loopEle(item, isDelete_1); });
252
+ emitTarget.elements.forEach(function (item) { return loopEle(item, isDelete_1); });
253
+ }
254
+ hasFrontEnd = true;
255
+ }
256
+ if (emitTarget.concept === 'ViewElement') {
257
+ loopEle(emitTarget, true);
258
+ }
259
+ if (emitTarget.concept === 'BindAttribute' && emitTarget.name === 'url' && emitTarget.value.endsWith('/import')) {
260
+ if (!emitTarget.view.parentAuth) {
261
+ hasBackEnd = true;
262
+ }
263
+ }
264
+ if (emitTarget.concept === 'CallLogic') {
265
+ var arrlist = [];
266
+ getLogic(emitTarget.calleeKey, emitTarget.app, arrlist);
267
+ var result = arrlist.filter(function (item) { return item.startsWith('app') || item.startsWith('extensions'); });
268
+ // console.log(result, 'CallLogic');
269
+ if (result.length) {
270
+ hasBackEnd = true;
271
+ }
272
+ }
273
+ event.eventList.forEach(function (_a) {
274
+ var action = _a.action, path = _a.path, objItem = _a.object;
275
+ if (Array.isArray(objItem)) {
276
+ if (action === 'update') {
277
+ actionList.push({
278
+ action: action,
279
+ path: path,
280
+ node: objItem[0]
281
+ });
282
+ }
283
+ else {
284
+ objItem.forEach(function (item, index) {
285
+ actionList.push({
286
+ action: action,
287
+ path: path,
288
+ node: item
289
+ });
290
+ });
291
+ }
292
+ }
293
+ else {
294
+ actionList.push({
295
+ action: action,
296
+ path: path,
297
+ object: objItem
298
+ });
299
+ }
300
+ });
301
+ });
302
+ }
303
+ }
304
+ catch (error) {
305
+ console.log(error);
306
+ app.emit('refresh');
307
+ }
308
+ ChangedNASLType = '';
309
+ if (hasFrontEnd && hasBackEnd) {
310
+ ChangedNASLType = 'both';
311
+ }
312
+ else if (hasFrontEnd) {
313
+ ChangedNASLType = 'web';
314
+ }
315
+ else if (hasBackEnd) {
316
+ ChangedNASLType = 'backend';
317
+ }
318
+ if (!(config_1.config.storage.protocol === 'http')) return [3 /*break*/, 5];
319
+ _b.label = 1;
320
+ case 1:
321
+ _b.trys.push([1, 3, , 4]);
322
+ return [4 /*yield*/, service_1["default"].batchAction({
323
+ body: actionList,
324
+ headers: {
325
+ appId: app.id,
326
+ ChangedNASLType: ChangedNASLType
327
+ }
328
+ })];
329
+ case 2:
330
+ _b.sent();
331
+ return [3 /*break*/, 4];
332
+ case 3:
333
+ error_1 = _b.sent();
334
+ err = error_1;
335
+ // 401650, 检测到当前应用拉取操作已被强制结束, 用户确认后再刷新
336
+ if ((error_1 === null || error_1 === void 0 ? void 0 : error_1.code) !== 401650)
337
+ app.emit('refresh');
338
+ return [3 /*break*/, 4];
339
+ case 4: return [3 /*break*/, 9];
340
+ case 5:
341
+ if (!(config_1.config.storage.protocol === 'mock')) return [3 /*break*/, 6];
342
+ return [3 /*break*/, 9];
343
+ case 6: return [4 /*yield*/, fs.readJSON(config_1.config.storage.basePath)];
344
+ case 7:
345
+ json = _b.sent();
346
+ jsoner.batchAction(json, actionList);
347
+ return [4 /*yield*/, fs.writeJSON(config_1.config.storage.basePath, json, {
348
+ spaces: 4
349
+ })];
350
+ case 8:
351
+ _b.sent();
352
+ _b.label = 9;
353
+ case 9:
354
+ app.emit('saved', err);
355
+ if (!app._historying) {
356
+ if (app._historyIndex !== app._historyList.length) {
357
+ app._historyList = app._historyList.splice(0, app._historyIndex);
358
+ }
359
+ app._historyList.push({
360
+ actionMsg: actionMsg,
361
+ list: list.map(function (item) { return item.originEvent; })
362
+ });
363
+ app._historyIndex = app._historyList.length;
364
+ }
365
+ else {
366
+ actionMap = {
367
+ undo: '已撤销操作:',
368
+ redo: '已重做操作:'
369
+ };
370
+ msg = actionMap[action];
371
+ msg += actionMsg;
372
+ vue_1["default"].prototype.$toast.info(msg);
373
+ app._historying = false;
374
+ }
375
+ return [2 /*return*/];
376
+ }
377
+ });
378
+ });
379
+ }
380
+ function handleApp(app) {
381
+ var _this = this;
382
+ app._isCollectingCount = 0;
383
+ app._collectingList = [];
384
+ app._historyList = [];
385
+ app._historyIndex = 0;
386
+ app._historying = false;
387
+ app._timer = null;
388
+ app.on('undo', function () {
389
+ app._historying = true;
390
+ });
391
+ app.on('redo', function () {
392
+ app._historying = true;
393
+ });
394
+ /**
395
+ * 开启收集
396
+ */
397
+ app.on('collect:start', function (event) {
398
+ if (app._timer) {
399
+ clearTimeout(app._timer);
400
+ }
401
+ if (!app._noTimer) {
402
+ app._noTimer = event.noTimer;
403
+ }
404
+ if (!app._noTimer) {
405
+ app._timer = setTimeout(function () {
406
+ console.error('收集超时,请及时排查原因');
407
+ app.emit('refresh');
408
+ }, 800);
409
+ }
410
+ if (!app._isCollectingCount) {
411
+ app._actionMsg = event === null || event === void 0 ? void 0 : event.actionMsg;
412
+ app._action = event === null || event === void 0 ? void 0 : event.action;
413
+ }
414
+ app._isCollectingCount++;
415
+ });
416
+ /**
417
+ * 结束收集
418
+ */
419
+ app.on('collect:end', function () { return __awaiter(_this, void 0, void 0, function () {
420
+ var collectingList, actionMsg, action;
421
+ return __generator(this, function (_a) {
422
+ switch (_a.label) {
423
+ case 0:
424
+ app._isCollectingCount--;
425
+ if (!(app._isCollectingCount === 0)) return [3 /*break*/, 3];
426
+ if (app._timer) {
427
+ clearTimeout(app._timer);
428
+ }
429
+ collectingList = app._collectingList;
430
+ actionMsg = app._actionMsg;
431
+ action = app._action;
432
+ app._collectingList = [];
433
+ app._actionMsg = '';
434
+ app._action = '';
435
+ app._noTimer = undefined;
436
+ if (!(Array.isArray(collectingList) && collectingList.length)) return [3 /*break*/, 2];
437
+ app.naslServer.embeddedTSEmitter.emit('change', {
438
+ value: collectingList
439
+ });
440
+ return [4 /*yield*/, doAction(app, {
441
+ list: collectingList,
442
+ actionMsg: actionMsg,
443
+ action: action
444
+ })];
445
+ case 1:
446
+ _a.sent();
447
+ _a.label = 2;
448
+ case 2: return [3 /*break*/, 4];
449
+ case 3:
450
+ if (app._isCollectingCount < 0) {
451
+ app._isCollectingCount = 0;
452
+ throw Error('关闭收集有问题,请排查');
453
+ }
454
+ _a.label = 4;
455
+ case 4: return [2 /*return*/];
456
+ }
457
+ });
458
+ }); });
459
+ /**
460
+ * 有变更
461
+ */
462
+ app.on('storage', function (event) {
463
+ // 是否正在收集
464
+ if (app._isCollectingCount === 0) {
465
+ app.naslServer.embeddedTSEmitter.emit('change', {
466
+ value: [event]
467
+ });
468
+ var actionMsg = '';
469
+ var _a = event.originEvent || {}, action = _a.action, target = _a.target;
470
+ var _b = target || {}, concept = _b.concept, name = _b.name;
471
+ switch (action) {
472
+ case 'create':
473
+ actionMsg = '添加';
474
+ break;
475
+ case 'delete':
476
+ actionMsg = '删除';
477
+ break;
478
+ case 'update':
479
+ actionMsg = '修改';
480
+ break;
481
+ }
482
+ actionMsg += decorators_1.getConceptConstructor(concept).nodeTitle;
483
+ if (name) {
484
+ actionMsg += "\u201C" + name + "\u201D";
485
+ }
486
+ doAction(app, {
487
+ list: [event],
488
+ actionMsg: actionMsg
489
+ });
490
+ }
491
+ else {
492
+ app._collectingList.push(event);
493
+ }
494
+ });
495
+ }
496
+ exports.handleApp = handleApp;
497
+ /**
498
+ * 加载 app
499
+ * @param appId 如果是从文件读,就不需要传
500
+ * @returns app 对象
501
+ */
502
+ function loadApp(appId) {
503
+ return __awaiter(this, void 0, void 0, function () {
504
+ var app, data, json;
505
+ return __generator(this, function (_a) {
506
+ switch (_a.label) {
507
+ case 0:
508
+ if (!(config_1.config.storage.protocol === 'http')) return [3 /*break*/, 2];
509
+ return [4 /*yield*/, service_1["default"].batchQuery({
510
+ body: [
511
+ {
512
+ path: 'app'
513
+ },
514
+ ],
515
+ headers: {
516
+ appId: appId
517
+ }
518
+ })];
519
+ case 1:
520
+ data = _a.sent();
521
+ // const data = res?.data?.result;
522
+ app = new concepts_1.App(Object.assign(data === null || data === void 0 ? void 0 : data[0], { id: appId }));
523
+ return [3 /*break*/, 5];
524
+ case 2:
525
+ if (!(config_1.config.storage.protocol === 'mock')) return [3 /*break*/, 3];
526
+ app = new concepts_1.App({
527
+ id: appId,
528
+ concept: 'App',
529
+ name: 'devapp',
530
+ title: '开发应用',
531
+ scope: 'pc',
532
+ envs: 'dev,online',
533
+ hasAuth: true,
534
+ dataSources: [],
535
+ structures: [],
536
+ enums: [],
537
+ logics: [],
538
+ interfaces: [],
539
+ views: [],
540
+ processes: [],
541
+ roles: [],
542
+ dependencies: [],
543
+ interfaceDependencies: [],
544
+ componentDependencies: []
545
+ });
546
+ return [3 /*break*/, 5];
547
+ case 3: return [4 /*yield*/, fs.readJSON(config_1.config.storage.basePath)];
548
+ case 4:
549
+ json = _a.sent();
550
+ app = new concepts_1.App(appId ? Object.assign(json, { id: appId }) : json);
551
+ _a.label = 5;
552
+ case 5:
553
+ config_1.config.scope = app.scope;
554
+ handleApp(app);
555
+ app._isCollectingCount = 0;
556
+ return [2 /*return*/, app];
557
+ }
558
+ });
559
+ });
560
+ }
561
+ exports.loadApp = loadApp;
562
+ /**
563
+ * 加载 app
564
+ * @returns app 对象
565
+ */
566
+ function loadAppSync() {
567
+ var json = fs.readJSONSync(config_1.config.storage.basePath);
568
+ var app = new concepts_1.App(json);
569
+ handleApp(app);
570
+ return app;
571
+ }
572
+ exports.loadAppSync = loadAppSync;
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+
3
+ var path = require('path'); // const HtmlWebpackPlugin = require('html-webpack-plugin');
4
+
5
+
6
+ module.exports = {
7
+ mode: 'development',
8
+ //mode: 'production',
9
+ entry: {
10
+ bundle: './src/index.js'
11
+ },
12
+ output: {
13
+ path: path.resolve(__dirname, '../../../src/static/'),
14
+ filename: 'ts-worker.js'
15
+ },
16
+ target: 'webworker',
17
+ resolve: {
18
+ // Use our versions of Node modules.
19
+ alias: {
20
+ // fs: 'browserfs/dist/shims/fs.js',
21
+ // os: require.resolve('os-browserify/browser'),
22
+ // // path: require.resolve('path-browserify'),
23
+ // buffer: 'browserfs/dist/shims/buffer.js',
24
+ // path: 'browserfs/dist/shims/path.js',
25
+ // processGlobal: 'browserfs/dist/shims/process.js',
26
+ // bufferGlobal: 'browserfs/dist/shims/bufferGlobal.js',
27
+ // bfsGlobal: require.resolve('browserfs'),
28
+ ts: path.resolve(__dirname, 'typescript')
29
+ },
30
+ // DISABLE Webpack's built-in process and Buffer polyfills!
31
+ fallback: {
32
+ fs: false,
33
+ os: false,
34
+ inspector: false,
35
+ // fs: 'browserfs/dist/shims/fs.js',
36
+ crypto: require.resolve('crypto-browserify'),
37
+ stream: require.resolve('stream-browserify'),
38
+ path: require.resolve('path-browserify'),
39
+ // processGlobal: 'browserfs/dist/shims/process.js',
40
+ // bufferGlobal: 'browserfs/dist/shims/bufferGlobal.js',
41
+ // bfsGlobal: require.resolve('browserfs'),
42
+ // process: false,
43
+ // Buffer: false,
44
+ child_process: false,
45
+ worker_threads: false,
46
+ net: false,
47
+ readline: false,
48
+ perf_hooks: false
49
+ },
50
+ extensions: ['.ts', '.tsx', '.js']
51
+ },
52
+ node: {
53
+ __dirname: true,
54
+ __filename: true
55
+ },
56
+ // REQUIRED to avoid issue "Uncaught TypeError: BrowserFS.BFSRequire is not a function"
57
+ // See: https://github.com/jvilk/BrowserFS/issues/201
58
+ module: {
59
+ // noParse: /browserfs\.js/,
60
+ rules: [{
61
+ test: /\.tsx?$/,
62
+ loader: 'ts-loader'
63
+ }, {
64
+ test: /\.jsx?$|\.tsx?$/,
65
+ loader: 'ifdef-loader'
66
+ }, {
67
+ include: [/node_modules[\\/]@?typescript[\\/]/ // /vusion-api\/out\/fs\/Library\.js$/,
68
+ // /prettier\/index\.js$/,
69
+ // /prettier\/third-party\.js$/,
70
+ // /prettier\/parser-glimmer\.js$/,
71
+ // /babel\/core\/lib\/config\/files\/plugins\.js$/,
72
+ // /babel\/core\/lib\/config\/files\/configuration\.js$/,
73
+ // /\/src\/extension\//,
74
+ // /node-plop\/lib\/node-plop\.js$/,
75
+ ],
76
+ use: [require.resolve('./webpack/loaders/non-webpack-require-loader')]
77
+ }]
78
+ },
79
+ plugins: [// Expose BrowserFS, process, and Buffer globals.
80
+ // NOTE: If you intend to use BrowserFS in a script tag, you do not need
81
+ // to expose a BrowserFS global.
82
+ // new NodePolyfillPlugin(),
83
+ // new webpack.ProvidePlugin({ BrowserFS: 'bfsGlobal', process: 'processGlobal', Buffer: 'bufferGlobal' }),
84
+ // 先不打开
85
+ // new HtmlWebpackPlugin({
86
+ // filename: 'index.html',
87
+ // chunks: ['bundle'],
88
+ // }),
89
+ // new HtmlWebpackPlugin({
90
+ // filename: 'webpack.html',
91
+ // chunks: ['webpack'],
92
+ // }),
93
+ ],
94
+ devServer: {
95
+ port: 8700,
96
+ // static: {
97
+ // directory: __dirname,
98
+ // },
99
+ proxy: {
100
+ '/src': {
101
+ target: 'http://localhost:8080',
102
+ pathRewrite: {
103
+ '/src': '/src'
104
+ }
105
+ }
106
+ }
107
+ }
108
+ };