total5 0.0.16-10 → 0.0.16-11
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/changelog.txt +6 -0
- package/global.js +17 -7
- package/index.js +2 -0
- package/package.json +1 -1
- package/utils.js +88 -14
- package/websocket.js +6 -3
- package/workers.js +1 -1
package/changelog.txt
CHANGED
|
@@ -30,6 +30,12 @@
|
|
|
30
30
|
- fixed `NEWFORK()` method
|
|
31
31
|
- fixed callback with `$` in the `ACTION().callback($)`
|
|
32
32
|
- fixed returing a default JSON schema object in actions
|
|
33
|
+
- added support for nested inline action schemas in action schemas
|
|
34
|
+
- fixed loading of `totalapi` key via `LOADCONFIG()`
|
|
35
|
+
- changed `SIGTERM` for `SIGKILL` in the `NEWFORK()` method
|
|
36
|
+
- extended `data` object in the `DEF.onAudit` delegate by adding `sessionid {String}` property
|
|
37
|
+
- fixed promise in the `AJAX()` method
|
|
38
|
+
- added `options.timeout {Number}` to the `WebSocketClient`
|
|
33
39
|
|
|
34
40
|
========================
|
|
35
41
|
0.0.15
|
package/global.js
CHANGED
|
@@ -147,11 +147,21 @@ global.AJAX = function(url, data, callback) {
|
|
|
147
147
|
data = null;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
if (!callback)
|
|
151
|
-
return new Promise((resolve, reject)
|
|
150
|
+
if (!callback) {
|
|
151
|
+
return new Promise(function(resolve, reject) {
|
|
152
|
+
global.AJAX(url, data, function(err, response) {
|
|
153
|
+
if (err) {
|
|
154
|
+
if (err instanceof Array)
|
|
155
|
+
err = ErrorBuilder.assign(err).reject();
|
|
156
|
+
reject(err);
|
|
157
|
+
} else
|
|
158
|
+
resolve(response);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
152
162
|
|
|
153
|
-
|
|
154
|
-
|
|
163
|
+
const index = url.indexOf(' ');
|
|
164
|
+
const opt = {};
|
|
155
165
|
|
|
156
166
|
if (index !== -1) {
|
|
157
167
|
opt.method = url.substring(0, index);
|
|
@@ -175,14 +185,14 @@ global.AJAX = function(url, data, callback) {
|
|
|
175
185
|
return;
|
|
176
186
|
}
|
|
177
187
|
|
|
178
|
-
|
|
188
|
+
let type = err ? '' : response.headers['content-type'] || '';
|
|
179
189
|
if (type) {
|
|
180
|
-
|
|
190
|
+
const index = type.lastIndexOf(';');
|
|
181
191
|
if (index !== -1)
|
|
182
192
|
type = type.substring(0, index).trim();
|
|
183
193
|
}
|
|
184
194
|
|
|
185
|
-
|
|
195
|
+
let value = null;
|
|
186
196
|
|
|
187
197
|
switch (type.toLowerCase()) {
|
|
188
198
|
case 'text/xml':
|
package/index.js
CHANGED
|
@@ -559,6 +559,7 @@ F.loadconfig = function(value) {
|
|
|
559
559
|
key = 'secret_totalapi';
|
|
560
560
|
else
|
|
561
561
|
key = '$tapi';
|
|
562
|
+
cfg[key] = val;
|
|
562
563
|
break;
|
|
563
564
|
case '$tms':
|
|
564
565
|
break;
|
|
@@ -2085,6 +2086,7 @@ F.audit = function(name, $, message, type) {
|
|
|
2085
2086
|
var data = {};
|
|
2086
2087
|
|
|
2087
2088
|
if ($.user) {
|
|
2089
|
+
data.sessionid = $.user.sessionid || $.sessionid || $.controller?.sessionid;
|
|
2088
2090
|
data.userid = $.user.id;
|
|
2089
2091
|
data.createdby = $.user.name || $.user.nick || $.user.alias;
|
|
2090
2092
|
}
|
package/package.json
CHANGED
package/utils.js
CHANGED
|
@@ -5949,6 +5949,84 @@ exports.connect = function(opt, callback) {
|
|
|
5949
5949
|
meta.socket1.on('clientError', error);
|
|
5950
5950
|
};
|
|
5951
5951
|
|
|
5952
|
+
function extractnested(str, minDepth = 0) {
|
|
5953
|
+
|
|
5954
|
+
const parts = [];
|
|
5955
|
+
|
|
5956
|
+
let out = '';
|
|
5957
|
+
let depth = 0;
|
|
5958
|
+
let capturing = false;
|
|
5959
|
+
let capDepth = 0;
|
|
5960
|
+
let buf = '';
|
|
5961
|
+
|
|
5962
|
+
const isOpen = (c) => c === '[' || c === '{';
|
|
5963
|
+
const isClose = (c) => c === ']' || c === '}';
|
|
5964
|
+
const matches = (o, c) => (o === '[' && c === ']') || (o === '{' && c === '}');
|
|
5965
|
+
const stack = [];
|
|
5966
|
+
|
|
5967
|
+
for (let i = 0; i < str.length; i++) {
|
|
5968
|
+
const ch = str[i];
|
|
5969
|
+
|
|
5970
|
+
if (isOpen(ch)) {
|
|
5971
|
+
|
|
5972
|
+
if (!capturing && depth >= minDepth) {
|
|
5973
|
+
capturing = true;
|
|
5974
|
+
capDepth = depth + 1;
|
|
5975
|
+
buf = '';
|
|
5976
|
+
}
|
|
5977
|
+
|
|
5978
|
+
stack.push(ch);
|
|
5979
|
+
depth++;
|
|
5980
|
+
|
|
5981
|
+
if (capturing) buf += ch;
|
|
5982
|
+
else out += ch;
|
|
5983
|
+
|
|
5984
|
+
continue;
|
|
5985
|
+
}
|
|
5986
|
+
|
|
5987
|
+
if (isClose(ch)) {
|
|
5988
|
+
|
|
5989
|
+
const open = stack[stack.length - 1];
|
|
5990
|
+
if (!open || !matches(open, ch))
|
|
5991
|
+
throw new Error(`Mismatched/unbalanced brackets at index ${i}`);
|
|
5992
|
+
|
|
5993
|
+
if (capturing) buf += ch;
|
|
5994
|
+
else out += ch;
|
|
5995
|
+
|
|
5996
|
+
stack.pop();
|
|
5997
|
+
depth--;
|
|
5998
|
+
|
|
5999
|
+
if (capturing && depth < capDepth) {
|
|
6000
|
+
|
|
6001
|
+
const inner = buf.slice(1, -1);
|
|
6002
|
+
const type = buf[0];
|
|
6003
|
+
const startsWithRef = inner.trimStart().startsWith('@');
|
|
6004
|
+
const hasEnumPipe = type === '{' && inner.includes('|');
|
|
6005
|
+
|
|
6006
|
+
if (!startsWithRef && !hasEnumPipe) {
|
|
6007
|
+
const idx = parts.length;
|
|
6008
|
+
out += type + `#${idx}` + (type === '{' ? '}' : ']');
|
|
6009
|
+
parts.push(inner);
|
|
6010
|
+
} else
|
|
6011
|
+
out += buf;
|
|
6012
|
+
|
|
6013
|
+
capturing = false;
|
|
6014
|
+
buf = '';
|
|
6015
|
+
}
|
|
6016
|
+
|
|
6017
|
+
continue;
|
|
6018
|
+
}
|
|
6019
|
+
|
|
6020
|
+
if (capturing) buf += ch;
|
|
6021
|
+
else out += ch;
|
|
6022
|
+
}
|
|
6023
|
+
|
|
6024
|
+
if (stack.length)
|
|
6025
|
+
throw new Error('Unbalanced opening bracket(s)');
|
|
6026
|
+
|
|
6027
|
+
return { text: out, parts };
|
|
6028
|
+
}
|
|
6029
|
+
|
|
5952
6030
|
SP.toJSONSchema = SP.parseSchema = function(name, url) {
|
|
5953
6031
|
|
|
5954
6032
|
let obj = {};
|
|
@@ -5963,19 +6041,11 @@ SP.toJSONSchema = SP.parseSchema = function(name, url) {
|
|
|
5963
6041
|
obj.properties = {};
|
|
5964
6042
|
|
|
5965
6043
|
let str = this;
|
|
5966
|
-
let nestedtypes
|
|
6044
|
+
let nestedtypes;
|
|
5967
6045
|
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
return '[#' + (nestedtypes.push(text.substring(1, text.length - 1)) - 1) + ']';
|
|
5972
|
-
});
|
|
5973
|
-
|
|
5974
|
-
str = str.replace(/\{.*?\}/g, function(text) {
|
|
5975
|
-
if (text.substring(1, 2) === '@')
|
|
5976
|
-
return text;
|
|
5977
|
-
return '{#' + (nestedtypes.push(text.substring(1, text.length - 1)) - 1) + '}';
|
|
5978
|
-
});
|
|
6046
|
+
let extracted = extractnested(str);
|
|
6047
|
+
nestedtypes = extracted.parts;
|
|
6048
|
+
str = extracted.text;
|
|
5979
6049
|
|
|
5980
6050
|
let prop = str.split(/,|\n/);
|
|
5981
6051
|
let required = [];
|
|
@@ -6034,8 +6104,12 @@ SP.toJSONSchema = SP.parseSchema = function(name, url) {
|
|
|
6034
6104
|
let isenum = type[0] === '{';
|
|
6035
6105
|
|
|
6036
6106
|
if (isenum) {
|
|
6037
|
-
|
|
6038
|
-
|
|
6107
|
+
|
|
6108
|
+
if (type[1] === '@' || type[1] === '#') {
|
|
6109
|
+
tmp = type.substring(2, type.indexOf('}'));
|
|
6110
|
+
tmp = nestedtypes[+tmp];
|
|
6111
|
+
} else
|
|
6112
|
+
tmp = type.substring(1, type.indexOf('}'));
|
|
6039
6113
|
|
|
6040
6114
|
// Nested schema
|
|
6041
6115
|
if ((/[:,\s]/).test(tmp)) {
|
package/websocket.js
CHANGED
|
@@ -169,7 +169,7 @@ function websocket_ondata(chunk) {
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
function websocket_onerror(e) {
|
|
172
|
-
this.destroy &&
|
|
172
|
+
this.destroy && this.destroy();
|
|
173
173
|
this.$controller && this.$controller.onerror(e);
|
|
174
174
|
}
|
|
175
175
|
|
|
@@ -1212,7 +1212,7 @@ function WebSocketClient() {
|
|
|
1212
1212
|
|
|
1213
1213
|
// type: json, text, binary
|
|
1214
1214
|
t.headers = {};
|
|
1215
|
-
t.options = { type: 'json', size: 0, masking: false, compress: true, reconnect: 3000, encodedecode: false, encryptdecrypt: false, rejectunauthorized: false }; // key: Buffer, cert: Buffer, dhparam: Buffer
|
|
1215
|
+
t.options = { type: 'json', size: 0, masking: false, compress: true, reconnect: 3000, encodedecode: false, encryptdecrypt: false, rejectunauthorized: false, timeout: 30000 }; // key: Buffer, cert: Buffer, dhparam: Buffer
|
|
1216
1216
|
t.cookies = {};
|
|
1217
1217
|
|
|
1218
1218
|
t.ondata2 = () => t.ondata();
|
|
@@ -1294,7 +1294,6 @@ WebSocketClient.prototype.connectforce = function(self, url, protocol, origin) {
|
|
|
1294
1294
|
F.stats.performance.online++;
|
|
1295
1295
|
self.req = (secured ? F.Https : F.Http).get(options);
|
|
1296
1296
|
self.req.$main = self;
|
|
1297
|
-
|
|
1298
1297
|
self.req.on('error', function(e) {
|
|
1299
1298
|
self.$events.error && self.emit('error', e);
|
|
1300
1299
|
self.onclose();
|
|
@@ -1337,6 +1336,10 @@ WebSocketClient.prototype.connectforce = function(self, url, protocol, origin) {
|
|
|
1337
1336
|
}
|
|
1338
1337
|
|
|
1339
1338
|
self.closed = false;
|
|
1339
|
+
|
|
1340
|
+
if (self.options.timeout > 0)
|
|
1341
|
+
self.socket.setKeepAlive(true, self.options.timeout);
|
|
1342
|
+
|
|
1340
1343
|
self.socket.on('data', websocket_ondata);
|
|
1341
1344
|
self.socket.on('error', websocket_onerror);
|
|
1342
1345
|
self.socket.on('close', wsclient_close);
|
package/workers.js
CHANGED
|
@@ -63,7 +63,7 @@ exports.createfork = function(name) {
|
|
|
63
63
|
const filename = name[0] === '~' ? name.substring(1) : F.path.root('workers/' + name + '.js');
|
|
64
64
|
const fork = new F.Child.fork(filename, { cwd: HEADER.cwd, argv: ['--worker'] });
|
|
65
65
|
fork.postMessage = fork.send;
|
|
66
|
-
fork.terminate = () => fork.kill('
|
|
66
|
+
fork.terminate = () => fork.kill('SIGKILL');
|
|
67
67
|
return fork;
|
|
68
68
|
};
|
|
69
69
|
|