verteilen-core 1.0.16 → 1.1.1
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/dist/index.js +1 -0
- package/dist/src/interface/enum.js +10 -1
- package/dist/src/interface/server.js +1 -0
- package/dist/src/script/execute_manager.js +1 -1
- package/dist/src/script/socket_manager.js +6 -5
- package/dist/src/server/io.js +181 -0
- package/dist/src/server/plugin.js +290 -0
- package/dist/src/server/server.js +41 -0
- package/dist/src/server.js +18 -0
- package/dist/test/client/execute.test.js +4 -2
- package/dist/test/client/task.test.js +2 -1
- package/index.ts +3 -1
- package/package.json +1 -1
- package/src/interface/base.ts +15 -3
- package/src/interface/bus.ts +7 -0
- package/src/interface/enum.ts +4 -0
- package/src/interface/record.ts +9 -0
- package/src/interface/server.ts +2 -0
- package/src/interface/table.ts +35 -15
- package/src/interface/ui.ts +99 -4
- package/src/script/execute_manager.ts +1 -1
- package/src/script/socket_manager.ts +6 -5
- package/src/server/io.ts +243 -0
- package/src/server/plugin.ts +314 -0
- package/src/server/server.ts +47 -0
- package/src/server.ts +5 -0
- package/test/client/execute.test.ts +4 -2
- package/test/client/task.test.ts +2 -1
package/dist/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./src/computed"), exports);
|
|
18
18
|
__exportStar(require("./src/interface"), exports);
|
|
19
|
+
__exportStar(require("./src/server"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ParameterTemplateText = exports.ProjectTemplateText = exports.JobType2Text = exports.JobTypeText = exports.JobResultText = exports.ConnectionText = exports.JobCategoryText = exports.ExecuteStateText = exports.DataTypeText = exports.ServiceMode = exports.JavascriptLib = exports.RenderUpdateType = exports.ExecuteState = exports.ParameterTemplate = exports.ProjectTemplate = exports.JobType2 = exports.JobType = exports.ConditionResult = exports.JobCategory = exports.FrontendUpdate = exports.ResourceType = exports.DataTypeBase = exports.DataType = exports.SocketState = void 0;
|
|
3
|
+
exports.ParameterTemplateText = exports.ProjectTemplateText = exports.JobType2Text = exports.JobTypeText = exports.JobResultText = exports.ConnectionText = exports.JobCategoryText = exports.ExecuteStateText = exports.DataTypeText = exports.ServiceMode = exports.JavascriptLib = exports.RecordType = exports.RenderUpdateType = exports.ExecuteState = exports.ParameterTemplate = exports.ProjectTemplate = exports.JobType2 = exports.JobType = exports.ConditionResult = exports.JobCategory = exports.FrontendUpdate = exports.ResourceType = exports.DataTypeBase = exports.DataType = exports.SocketState = void 0;
|
|
4
4
|
var SocketState;
|
|
5
5
|
(function (SocketState) {
|
|
6
6
|
SocketState[SocketState["CONNECTING"] = 0] = "CONNECTING";
|
|
@@ -103,6 +103,15 @@ var RenderUpdateType;
|
|
|
103
103
|
RenderUpdateType[RenderUpdateType["Node"] = 2] = "Node";
|
|
104
104
|
RenderUpdateType[RenderUpdateType["Parameter"] = 4] = "Parameter";
|
|
105
105
|
})(RenderUpdateType || (exports.RenderUpdateType = RenderUpdateType = {}));
|
|
106
|
+
var RecordType;
|
|
107
|
+
(function (RecordType) {
|
|
108
|
+
RecordType[RecordType["PROJECT"] = 0] = "PROJECT";
|
|
109
|
+
RecordType[RecordType["PARAMETER"] = 1] = "PARAMETER";
|
|
110
|
+
RecordType[RecordType["NODE"] = 2] = "NODE";
|
|
111
|
+
RecordType[RecordType["LOG"] = 3] = "LOG";
|
|
112
|
+
RecordType[RecordType["LIB"] = 4] = "LIB";
|
|
113
|
+
RecordType[RecordType["USER"] = 5] = "USER";
|
|
114
|
+
})(RecordType || (exports.RecordType = RecordType = {}));
|
|
106
115
|
var JavascriptLib;
|
|
107
116
|
(function (JavascriptLib) {
|
|
108
117
|
JavascriptLib[JavascriptLib["ALL"] = 127] = "ALL";
|
|
@@ -38,7 +38,7 @@ class ExecuteManager extends runner_1.ExecuteManager_Runner {
|
|
|
38
38
|
this.current_projects = this.record.projects;
|
|
39
39
|
this.current_nodes = [];
|
|
40
40
|
this.record.nodes.forEach(x => {
|
|
41
|
-
const n = this.websocket_manager.targets.find(y => y.uuid == x.
|
|
41
|
+
const n = this.websocket_manager.targets.find(y => y.uuid == x.uuid);
|
|
42
42
|
if (n != undefined)
|
|
43
43
|
this.current_nodes.push(n);
|
|
44
44
|
});
|
|
@@ -57,7 +57,7 @@ class WebsocketManager {
|
|
|
57
57
|
this.server_update = () => this.sendUpdate();
|
|
58
58
|
this.server_record = (ns) => {
|
|
59
59
|
ns.forEach(x => {
|
|
60
|
-
this.serverconnect(x.url, x.
|
|
60
|
+
this.serverconnect(x.url, x.uuid);
|
|
61
61
|
});
|
|
62
62
|
};
|
|
63
63
|
this.shell_open = (uuid) => {
|
|
@@ -184,16 +184,17 @@ class WebsocketManager {
|
|
|
184
184
|
const data = [];
|
|
185
185
|
this.targets.forEach(x => {
|
|
186
186
|
if (x.websocket.readyState == interface_1.SocketState.CLOSED) {
|
|
187
|
-
data.push({
|
|
187
|
+
data.push({ uuid: x.uuid, url: x.websocket.url });
|
|
188
188
|
}
|
|
189
189
|
});
|
|
190
|
-
data.forEach(d => this.removeByUUID(d.
|
|
190
|
+
data.forEach(d => this.removeByUUID(d.uuid));
|
|
191
191
|
data.forEach(d => {
|
|
192
|
-
this.serverconnect(d.url, d.
|
|
192
|
+
this.serverconnect(d.url, d.uuid);
|
|
193
193
|
});
|
|
194
194
|
result = this.targets.map(x => {
|
|
195
195
|
return {
|
|
196
|
-
|
|
196
|
+
s: false,
|
|
197
|
+
uuid: x.uuid,
|
|
197
198
|
state: x.websocket.readyState,
|
|
198
199
|
url: x.websocket.url,
|
|
199
200
|
connection_rate: x.ms,
|
|
@@ -0,0 +1,181 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CreateRecordMongoLoader = exports.CreateRecordIOLoader = exports.CreateRecordMemoryLoader = exports._CreateRecordIOLoader = exports._CreateRecordMemoryLoader = void 0;
|
|
13
|
+
const interface_1 = require("../interface");
|
|
14
|
+
const _CreateRecordMemoryLoader = (loader, type) => {
|
|
15
|
+
const get_array = (type) => {
|
|
16
|
+
switch (type) {
|
|
17
|
+
default:
|
|
18
|
+
case interface_1.RecordType.PROJECT: return loader.projects;
|
|
19
|
+
case interface_1.RecordType.PARAMETER: return loader.parameter;
|
|
20
|
+
case interface_1.RecordType.NODE: return loader.nodes;
|
|
21
|
+
case interface_1.RecordType.LOG: return loader.logs;
|
|
22
|
+
case interface_1.RecordType.LIB: return loader.libs;
|
|
23
|
+
case interface_1.RecordType.USER: return loader.user;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
load_all: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
return get_array(type).map(x => JSON.stringify(x));
|
|
29
|
+
}),
|
|
30
|
+
delete_all: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
const arr = get_array(type).map(x => JSON.stringify(x));
|
|
32
|
+
arr.splice(0, arr.length);
|
|
33
|
+
}),
|
|
34
|
+
list_all: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
return get_array(type).map(x => x.uuid);
|
|
36
|
+
}),
|
|
37
|
+
save: (name, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
const arr = get_array(type);
|
|
39
|
+
const b = arr.findIndex(x => name == x.uuid);
|
|
40
|
+
if (b != -1)
|
|
41
|
+
arr[b] = JSON.parse(data);
|
|
42
|
+
else
|
|
43
|
+
arr.push(JSON.parse(data));
|
|
44
|
+
}),
|
|
45
|
+
load: (name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const arr = get_array(type);
|
|
47
|
+
const b = arr.find(x => name == x.uuid);
|
|
48
|
+
return b ? JSON.stringify(b) : "";
|
|
49
|
+
}),
|
|
50
|
+
rename: (name, newname) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
+
const arr = get_array(type);
|
|
52
|
+
const b = arr.findIndex(x => x.uuid == name);
|
|
53
|
+
if (b != -1)
|
|
54
|
+
arr[b].uuid = newname;
|
|
55
|
+
}),
|
|
56
|
+
delete: (name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
const arr = get_array(type);
|
|
58
|
+
const b = arr.findIndex(x => x.uuid == name);
|
|
59
|
+
if (b != -1)
|
|
60
|
+
arr.splice(b, 1);
|
|
61
|
+
})
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
exports._CreateRecordMemoryLoader = _CreateRecordMemoryLoader;
|
|
65
|
+
const _CreateRecordIOLoader = (loader, memory, type, folder, ext = ".json") => {
|
|
66
|
+
const get_array = (type) => {
|
|
67
|
+
switch (type) {
|
|
68
|
+
default:
|
|
69
|
+
case interface_1.RecordType.PROJECT: return memory.projects;
|
|
70
|
+
case interface_1.RecordType.PARAMETER: return memory.parameter;
|
|
71
|
+
case interface_1.RecordType.NODE: return memory.nodes;
|
|
72
|
+
case interface_1.RecordType.LOG: return memory.logs;
|
|
73
|
+
case interface_1.RecordType.LIB: return memory.libs;
|
|
74
|
+
case interface_1.RecordType.USER: return memory.user;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
load_all: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
+
const root = loader.join(loader.root, folder);
|
|
80
|
+
if (!loader.exists(root))
|
|
81
|
+
yield loader.mkdir(root);
|
|
82
|
+
const files = yield loader.read_dir_file(root);
|
|
83
|
+
const r = files.map(x => loader.read_string(x, { encoding: 'utf8', flag: 'r' }));
|
|
84
|
+
const p = yield Promise.all(r);
|
|
85
|
+
const arr = get_array(type);
|
|
86
|
+
arr.splice(0, arr.length);
|
|
87
|
+
arr.push(...p.map(x => JSON.parse(x)));
|
|
88
|
+
return p;
|
|
89
|
+
}),
|
|
90
|
+
delete_all: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
+
const root = loader.join(loader.root, folder);
|
|
92
|
+
if (loader.exists(root))
|
|
93
|
+
yield loader.rm(root);
|
|
94
|
+
yield loader.mkdir(root);
|
|
95
|
+
const arr = get_array(type);
|
|
96
|
+
arr.splice(0, arr.length);
|
|
97
|
+
}),
|
|
98
|
+
list_all: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
+
const root = loader.join(loader.root, folder);
|
|
100
|
+
if (!loader.exists(root))
|
|
101
|
+
yield loader.mkdir(root);
|
|
102
|
+
return loader.read_dir_file(root);
|
|
103
|
+
}),
|
|
104
|
+
save: (name, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
+
const root = loader.join(loader.root, folder);
|
|
106
|
+
if (!loader.exists(root))
|
|
107
|
+
yield loader.mkdir(root);
|
|
108
|
+
const file = loader.join(root, name + ext);
|
|
109
|
+
yield loader.write_string(file, data);
|
|
110
|
+
const arr = get_array(type);
|
|
111
|
+
const b = arr.findIndex(x => x.uuid == name);
|
|
112
|
+
if (b != -1)
|
|
113
|
+
arr.push(JSON.parse(data));
|
|
114
|
+
else
|
|
115
|
+
arr[b] = JSON.parse(data);
|
|
116
|
+
}),
|
|
117
|
+
load: (name, cache) => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
|
+
if (cache) {
|
|
119
|
+
const arr = get_array(type);
|
|
120
|
+
const b = arr.findIndex(x => x.uuid == name);
|
|
121
|
+
if (b != -1)
|
|
122
|
+
return arr[b];
|
|
123
|
+
}
|
|
124
|
+
const root = loader.join(loader.root, folder);
|
|
125
|
+
if (!loader.exists(root))
|
|
126
|
+
yield loader.mkdir(root);
|
|
127
|
+
const file = loader.join(root, name + ext);
|
|
128
|
+
return loader.read_string(file);
|
|
129
|
+
}),
|
|
130
|
+
rename: (name, newname) => __awaiter(void 0, void 0, void 0, function* () {
|
|
131
|
+
const root = loader.join(loader.root, folder);
|
|
132
|
+
if (!loader.exists(root))
|
|
133
|
+
yield loader.mkdir(root);
|
|
134
|
+
const oldfile = loader.join(root, name + ext);
|
|
135
|
+
const newfile = loader.join(root, newname + ext);
|
|
136
|
+
yield loader.cp(oldfile, newfile);
|
|
137
|
+
yield loader.rm(oldfile);
|
|
138
|
+
const arr = get_array(type);
|
|
139
|
+
const b = arr.findIndex(x => x.uuid == name);
|
|
140
|
+
if (b != -1)
|
|
141
|
+
arr[b].uuid = newname;
|
|
142
|
+
}),
|
|
143
|
+
delete: (name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
144
|
+
const root = loader.join(loader.root, folder);
|
|
145
|
+
if (!loader.exists(root))
|
|
146
|
+
yield loader.mkdir(root);
|
|
147
|
+
const file = loader.join(root, name + ext);
|
|
148
|
+
yield loader.rm(file);
|
|
149
|
+
const arr = get_array(type);
|
|
150
|
+
const b = arr.findIndex(x => x.uuid == name);
|
|
151
|
+
if (b != -1)
|
|
152
|
+
arr.splice(b, 1);
|
|
153
|
+
})
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
exports._CreateRecordIOLoader = _CreateRecordIOLoader;
|
|
157
|
+
const CreateRecordMemoryLoader = (loader) => {
|
|
158
|
+
return {
|
|
159
|
+
project: (0, exports._CreateRecordMemoryLoader)(loader, interface_1.RecordType.PROJECT),
|
|
160
|
+
parameter: (0, exports._CreateRecordMemoryLoader)(loader, interface_1.RecordType.PARAMETER),
|
|
161
|
+
node: (0, exports._CreateRecordMemoryLoader)(loader, interface_1.RecordType.NODE),
|
|
162
|
+
log: (0, exports._CreateRecordMemoryLoader)(loader, interface_1.RecordType.LOG),
|
|
163
|
+
lib: (0, exports._CreateRecordMemoryLoader)(loader, interface_1.RecordType.LIB),
|
|
164
|
+
user: (0, exports._CreateRecordMemoryLoader)(loader, interface_1.RecordType.USER),
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
exports.CreateRecordMemoryLoader = CreateRecordMemoryLoader;
|
|
168
|
+
const CreateRecordIOLoader = (loader, memory) => {
|
|
169
|
+
return {
|
|
170
|
+
project: (0, exports._CreateRecordIOLoader)(loader, memory, interface_1.RecordType.PROJECT, "record"),
|
|
171
|
+
parameter: (0, exports._CreateRecordIOLoader)(loader, memory, interface_1.RecordType.PARAMETER, "parameter"),
|
|
172
|
+
node: (0, exports._CreateRecordIOLoader)(loader, memory, interface_1.RecordType.NODE, "node"),
|
|
173
|
+
log: (0, exports._CreateRecordIOLoader)(loader, memory, interface_1.RecordType.LOG, "log"),
|
|
174
|
+
lib: (0, exports._CreateRecordIOLoader)(loader, memory, interface_1.RecordType.LIB, "lib", ""),
|
|
175
|
+
user: (0, exports._CreateRecordIOLoader)(loader, memory, interface_1.RecordType.USER, "user"),
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
exports.CreateRecordIOLoader = CreateRecordIOLoader;
|
|
179
|
+
const CreateRecordMongoLoader = (loader, folder, ext = ".json") => {
|
|
180
|
+
};
|
|
181
|
+
exports.CreateRecordMongoLoader = CreateRecordMongoLoader;
|
|
@@ -0,0 +1,290 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CreatePluginLoader = exports.GetCurrentPlugin = void 0;
|
|
13
|
+
const GetCurrentPlugin = (loader) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
return new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const b = {
|
|
16
|
+
plugins: [],
|
|
17
|
+
templates: []
|
|
18
|
+
};
|
|
19
|
+
const root = loader.join(loader.root, 'template');
|
|
20
|
+
const root2 = loader.join(loader.root, 'plugin');
|
|
21
|
+
if (!loader.exists(root))
|
|
22
|
+
yield loader.mkdir(root);
|
|
23
|
+
if (!loader.exists(root2))
|
|
24
|
+
yield loader.mkdir(root2);
|
|
25
|
+
const files = (yield loader.read_dir_file(root)).filter(x => x.endsWith('.json'));
|
|
26
|
+
const _configs = files.map(file => loader.read_string(loader.join(root, file), { encoding: 'utf-8' }));
|
|
27
|
+
const configs = (yield Promise.all(_configs)).map(x => JSON.parse(x));
|
|
28
|
+
for (let index = 0; index < configs.length; index++) {
|
|
29
|
+
const config = configs[index];
|
|
30
|
+
const ps = config.projects.map(x => ({
|
|
31
|
+
value: -1,
|
|
32
|
+
group: x.group,
|
|
33
|
+
filename: x.filename,
|
|
34
|
+
title: x.title
|
|
35
|
+
}));
|
|
36
|
+
const ps2 = config.parameters.map(x => ({
|
|
37
|
+
value: -1,
|
|
38
|
+
group: x.group,
|
|
39
|
+
filename: x.filename,
|
|
40
|
+
title: x.title
|
|
41
|
+
}));
|
|
42
|
+
b.templates.push({
|
|
43
|
+
name: files[index].replace('.json', ''),
|
|
44
|
+
project: ps,
|
|
45
|
+
parameter: ps2,
|
|
46
|
+
url: config.url
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const files2 = (yield loader.read_dir_dir(root2)).filter(x => x.endsWith('.json'));
|
|
50
|
+
const p_config2 = files2.map(file => {
|
|
51
|
+
return loader.read_string(loader.join(root2, file), { encoding: 'utf-8' });
|
|
52
|
+
});
|
|
53
|
+
const configs2 = (yield Promise.all(p_config2)).map(x => JSON.parse(x));
|
|
54
|
+
for (let index = 0; index < configs2.length; index++) {
|
|
55
|
+
const config = configs2[index];
|
|
56
|
+
config.title = files2[index].replace('.json', '');
|
|
57
|
+
b.plugins.push(config);
|
|
58
|
+
}
|
|
59
|
+
resolve(b);
|
|
60
|
+
return b;
|
|
61
|
+
}));
|
|
62
|
+
});
|
|
63
|
+
exports.GetCurrentPlugin = GetCurrentPlugin;
|
|
64
|
+
const CreatePluginLoader = (loader, memory, socket, feedback) => {
|
|
65
|
+
return {
|
|
66
|
+
load_all: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
const cp = yield (0, exports.GetCurrentPlugin)(loader);
|
|
68
|
+
memory.templates = cp.templates;
|
|
69
|
+
memory.plugins = cp.plugins;
|
|
70
|
+
return cp;
|
|
71
|
+
}),
|
|
72
|
+
get_project: (group, filename) => {
|
|
73
|
+
let find = false;
|
|
74
|
+
let result = undefined;
|
|
75
|
+
for (let x of memory.templates) {
|
|
76
|
+
for (let y of x.project) {
|
|
77
|
+
if (y.group == group && y.filename == filename) {
|
|
78
|
+
result = JSON.stringify(y);
|
|
79
|
+
find = true;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (find)
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
},
|
|
88
|
+
get_parameter: (group, filename) => {
|
|
89
|
+
let find = false;
|
|
90
|
+
let result = undefined;
|
|
91
|
+
for (let x of memory.templates) {
|
|
92
|
+
for (let y of x.parameter) {
|
|
93
|
+
if (y.group == group && y.filename == filename) {
|
|
94
|
+
result = JSON.stringify(y);
|
|
95
|
+
find = true;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (find)
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
},
|
|
104
|
+
get_plugin: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
+
return memory.plugins;
|
|
106
|
+
}),
|
|
107
|
+
import_template: (name, url, token) => __awaiter(void 0, void 0, void 0, function* () {
|
|
108
|
+
const root = loader.join(loader.root, 'template');
|
|
109
|
+
const error_children = [];
|
|
110
|
+
const tokens = [undefined, ...token.split(' ')];
|
|
111
|
+
const content_folder = loader.join(root, name);
|
|
112
|
+
const project_folder = loader.join(content_folder, 'project');
|
|
113
|
+
const parameter_folder = loader.join(content_folder, 'parameter');
|
|
114
|
+
if (!loader.exists(root))
|
|
115
|
+
yield loader.mkdir(root);
|
|
116
|
+
let req = {};
|
|
117
|
+
let ob = undefined;
|
|
118
|
+
for (let t of tokens) {
|
|
119
|
+
if (t == undefined) {
|
|
120
|
+
req = { method: 'GET', cache: "no-store" };
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
req = {
|
|
124
|
+
method: 'GET',
|
|
125
|
+
cache: "no-store",
|
|
126
|
+
headers: {
|
|
127
|
+
"Authorization": t ? `Bearer ${t}` : ''
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const res = yield fetch(url, req);
|
|
133
|
+
const tex = yield res.text();
|
|
134
|
+
ob = JSON.parse(tex);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
console.error(error);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (ob == undefined) {
|
|
142
|
+
const p = { title: "Import Failed", type: "error", message: `Cannot find the json from url ${url}, or maybe just the wrong token` };
|
|
143
|
+
const h = { name: "makeToast", data: JSON.stringify(p) };
|
|
144
|
+
if (feedback.electron) {
|
|
145
|
+
feedback.electron("makeToast", JSON.stringify(p));
|
|
146
|
+
}
|
|
147
|
+
if (feedback.socket) {
|
|
148
|
+
feedback.socket(JSON.stringify(h));
|
|
149
|
+
}
|
|
150
|
+
return memory;
|
|
151
|
+
}
|
|
152
|
+
ob.url = url;
|
|
153
|
+
loader.write_string(loader.join(root, name + '.json'), JSON.stringify(ob, null, 4));
|
|
154
|
+
if (!loader.exists(content_folder))
|
|
155
|
+
loader.mkdir(content_folder);
|
|
156
|
+
if (!loader.exists(project_folder))
|
|
157
|
+
loader.mkdir(project_folder);
|
|
158
|
+
if (!loader.exists(parameter_folder))
|
|
159
|
+
loader.mkdir(parameter_folder);
|
|
160
|
+
const folder = url.substring(0, url.lastIndexOf('/'));
|
|
161
|
+
const project_calls = [];
|
|
162
|
+
const parameter_calls = [];
|
|
163
|
+
ob.projects.forEach((p) => {
|
|
164
|
+
project_calls.push(fetch(folder + "/" + p.filename + '.json', req));
|
|
165
|
+
});
|
|
166
|
+
const pss = yield Promise.all(project_calls);
|
|
167
|
+
const project_calls2 = pss.map(x => x.text());
|
|
168
|
+
const pss_result = yield Promise.all(project_calls2);
|
|
169
|
+
pss_result.forEach((text, index) => {
|
|
170
|
+
const n = ob.projects[index].filename + '.json';
|
|
171
|
+
try {
|
|
172
|
+
const project = JSON.parse(text);
|
|
173
|
+
loader.write_string(loader.join(project_folder, n), JSON.stringify(project, null, 4));
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
console.log("Parse error:\n", text);
|
|
177
|
+
error_children.push([`Import Project ${n} Error`, error.message]);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
ob.parameters.forEach((p) => {
|
|
181
|
+
parameter_calls.push(fetch(folder + "/" + p.filename + '.json', req));
|
|
182
|
+
});
|
|
183
|
+
const pss2 = yield Promise.all(parameter_calls);
|
|
184
|
+
const parameter_calls2 = pss2.map(x => x.text());
|
|
185
|
+
const pss_result2 = yield Promise.all(parameter_calls2);
|
|
186
|
+
pss_result2.forEach((text, index) => {
|
|
187
|
+
const n = ob.parameters[index].filename + '.json';
|
|
188
|
+
try {
|
|
189
|
+
const parameter = JSON.parse(text);
|
|
190
|
+
loader.write_string(loader.join(parameter_folder, n), JSON.stringify(parameter, null, 4));
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
console.log("Parse error:\n", text);
|
|
194
|
+
error_children.push([`Import Parameter ${n} Error`, error.message]);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
for (let x of error_children) {
|
|
198
|
+
const p = { title: x[0], type: "error", message: x[1] };
|
|
199
|
+
const h = { name: "makeToast", data: JSON.stringify(p) };
|
|
200
|
+
if (feedback.electron) {
|
|
201
|
+
feedback.electron("makeToast", JSON.stringify(p));
|
|
202
|
+
}
|
|
203
|
+
if (feedback.socket) {
|
|
204
|
+
feedback.socket(JSON.stringify(h));
|
|
205
|
+
}
|
|
206
|
+
return memory;
|
|
207
|
+
}
|
|
208
|
+
const cp = yield (0, exports.GetCurrentPlugin)(loader);
|
|
209
|
+
memory.templates = cp.templates;
|
|
210
|
+
memory.plugins = cp.plugins;
|
|
211
|
+
return cp;
|
|
212
|
+
}),
|
|
213
|
+
import_plugin: (name, url, token) => __awaiter(void 0, void 0, void 0, function* () {
|
|
214
|
+
const root = loader.join(loader.root, 'plugin');
|
|
215
|
+
const tokens = [undefined, ...token.split(' ')];
|
|
216
|
+
if (!loader.exists(root))
|
|
217
|
+
yield loader.mkdir(root);
|
|
218
|
+
let req = {};
|
|
219
|
+
let ob = undefined;
|
|
220
|
+
for (let t of tokens) {
|
|
221
|
+
if (t == undefined) {
|
|
222
|
+
req = { method: 'GET', cache: "no-store" };
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
req = {
|
|
226
|
+
method: 'GET',
|
|
227
|
+
cache: "no-store",
|
|
228
|
+
headers: {
|
|
229
|
+
"Authorization": t ? `Bearer ${t}` : ''
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
let tex = "";
|
|
234
|
+
try {
|
|
235
|
+
const res = yield fetch(url, req);
|
|
236
|
+
tex = yield res.text();
|
|
237
|
+
ob = JSON.parse(tex);
|
|
238
|
+
console.log("Fetch plugin json successfully");
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
console.warn(error, tex);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (ob == undefined) {
|
|
246
|
+
const p = { title: "Import Failed", type: "error", message: `Cannot find the json from url ${url}, or maybe just the wrong token` };
|
|
247
|
+
const h = { name: "makeToast", data: JSON.stringify(p) };
|
|
248
|
+
if (feedback.electron) {
|
|
249
|
+
feedback.electron("makeToast", JSON.stringify(p));
|
|
250
|
+
}
|
|
251
|
+
if (feedback.socket) {
|
|
252
|
+
feedback.socket(JSON.stringify(h));
|
|
253
|
+
}
|
|
254
|
+
return memory;
|
|
255
|
+
}
|
|
256
|
+
ob.url = url;
|
|
257
|
+
loader.write_string(loader.join(root, name + '.json'), JSON.stringify(ob, null, 4));
|
|
258
|
+
const cp = yield (0, exports.GetCurrentPlugin)(loader);
|
|
259
|
+
memory.templates = cp.templates;
|
|
260
|
+
memory.plugins = cp.plugins;
|
|
261
|
+
return cp;
|
|
262
|
+
}),
|
|
263
|
+
delete_template: (name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
264
|
+
const root = loader.join(loader.root, 'template');
|
|
265
|
+
if (loader.exists(loader.join(root, name + '.json')))
|
|
266
|
+
yield loader.rm(loader.join(root, name + '.json'));
|
|
267
|
+
if (loader.exists(loader.join(root, name)))
|
|
268
|
+
yield loader.rm(loader.join(root, name));
|
|
269
|
+
}),
|
|
270
|
+
delete_plugin: (name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
271
|
+
const root = loader.join(loader.root, 'plugin');
|
|
272
|
+
if (loader.exists(loader.join(root, name + '.json')))
|
|
273
|
+
yield loader.rm(loader.join(root, name + '.json'));
|
|
274
|
+
}),
|
|
275
|
+
plugin_download: (uuid, plugin, tokens) => __awaiter(void 0, void 0, void 0, function* () {
|
|
276
|
+
const p = JSON.parse(plugin);
|
|
277
|
+
const p2 = Object.assign(Object.assign({}, p), { token: tokens.split(' ') });
|
|
278
|
+
const t = socket(uuid);
|
|
279
|
+
const h = { name: 'plugin_download', data: p2 };
|
|
280
|
+
t === null || t === void 0 ? void 0 : t.websocket.send(JSON.stringify(h));
|
|
281
|
+
}),
|
|
282
|
+
plugin_remove: (uuid, plugin) => __awaiter(void 0, void 0, void 0, function* () {
|
|
283
|
+
const p = JSON.parse(plugin);
|
|
284
|
+
const t = socket(uuid);
|
|
285
|
+
const h = { name: 'plugin_remove', data: p };
|
|
286
|
+
t === null || t === void 0 ? void 0 : t.websocket.send(JSON.stringify(h));
|
|
287
|
+
}),
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
exports.CreatePluginLoader = CreatePluginLoader;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Server = void 0;
|
|
4
|
+
const io_1 = require("./io");
|
|
5
|
+
class Server {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.memory = {
|
|
8
|
+
projects: [],
|
|
9
|
+
parameter: [],
|
|
10
|
+
nodes: [],
|
|
11
|
+
logs: [],
|
|
12
|
+
libs: [],
|
|
13
|
+
user: [],
|
|
14
|
+
};
|
|
15
|
+
this.plugin = {
|
|
16
|
+
templates: [],
|
|
17
|
+
plugins: [],
|
|
18
|
+
};
|
|
19
|
+
this.io = undefined;
|
|
20
|
+
this.loader = undefined;
|
|
21
|
+
this.plugin_loader = undefined;
|
|
22
|
+
this.LoadFromDisk = () => {
|
|
23
|
+
const ts = [
|
|
24
|
+
this.current_loader.project.load_all(),
|
|
25
|
+
this.current_loader.parameter.load_all(),
|
|
26
|
+
this.current_loader.node.load_all(),
|
|
27
|
+
this.current_loader.log.load_all(),
|
|
28
|
+
this.current_loader.lib.load_all(),
|
|
29
|
+
this.current_loader.user.load_all(),
|
|
30
|
+
];
|
|
31
|
+
return Promise.all(ts);
|
|
32
|
+
};
|
|
33
|
+
this.memory_loader = (0, io_1.CreateRecordMemoryLoader)(this.memory);
|
|
34
|
+
}
|
|
35
|
+
get current_loader() {
|
|
36
|
+
if (this.loader)
|
|
37
|
+
return this.loader;
|
|
38
|
+
return this.memory_loader;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.Server = Server;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./server/server"), exports);
|
|
18
|
+
__exportStar(require("./server/io"), exports);
|
|
@@ -27,7 +27,8 @@ describe("Client Execute Test", () => {
|
|
|
27
27
|
script: "",
|
|
28
28
|
string_args: ["Not Exist"],
|
|
29
29
|
number_args: [],
|
|
30
|
-
boolean_args: []
|
|
30
|
+
boolean_args: [],
|
|
31
|
+
id_args: [],
|
|
31
32
|
};
|
|
32
33
|
execute = new job_execute_1.ClientJobExecute((str) => console.log(str), (str) => console.log(str), job, undefined, { plugins: [] });
|
|
33
34
|
yield expect(execute.execute()).rejects.toBeDefined();
|
|
@@ -42,7 +43,8 @@ describe("Client Execute Test", () => {
|
|
|
42
43
|
script: "",
|
|
43
44
|
string_args: [process.cwd()],
|
|
44
45
|
number_args: [],
|
|
45
|
-
boolean_args: []
|
|
46
|
+
boolean_args: [],
|
|
47
|
+
id_args: [],
|
|
46
48
|
};
|
|
47
49
|
execute = new job_execute_1.ClientJobExecute((str) => console.log(str), (str) => console.log(str), job, undefined, { plugins: [] });
|
|
48
50
|
yield expect(execute.execute()).resolves.toBeDefined();
|
package/index.ts
CHANGED