total5 0.0.10-2 → 0.0.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/api.js CHANGED
@@ -140,7 +140,7 @@ APICallProto.error = APICallProto.err = function(err, reverse) {
140
140
  return this;
141
141
  };
142
142
 
143
- APICallProto.callback = function($) {
143
+ APICallProto.callback = APICallProto.pipe = function($) {
144
144
  var t = this;
145
145
  t.$callback = typeof($) === 'function' ? $ : $.callback();
146
146
  return t;
package/bin/total5 CHANGED
@@ -36,12 +36,13 @@ function load(args) {
36
36
  setTimeout(load, 10, ARGS);
37
37
 
38
38
  FUNC.help = function() {
39
- console.log('translate : it makes a resource file with a localized dictionary from the current directory');
40
- console.log('minify <filename> : it minifies .js, .css and .html files');
41
- console.log('bundle <filename> : it makes a bundle from the current directory');
42
- console.log('extract <filename> : it extracts a bundle into the current directory');
43
- console.log('edit <url?id=project> : it opens remote editing of the current directory with the Total.js Code Editor');
44
- console.log('8000 : it starts a web server on port "8000" for the current directory');
39
+ console.log('translate : it makes a resource file with a localized dictionary from the current directory');
40
+ console.log('minify <filename> : it minifies .js, .css and .html files');
41
+ console.log('bundle <filename> : it makes a bundle from the current directory');
42
+ console.log('extract <filename> : it extracts a bundle into the current directory');
43
+ console.log('edit <url?id=project> : it opens remote editing of the current directory with the Total.js Code Editor');
44
+ console.log('proxyclient <server_endpoint> <local_port> : It connects a local port with a remote totaljs proxy server');
45
+ console.log('8000 : it starts a web server on port "8000" for the current directory');
45
46
  done();
46
47
  };
47
48
 
@@ -241,6 +242,10 @@ FUNC.server = function(port) {
241
242
  F.http({ load: 'none', port: port || 8000 });
242
243
  };
243
244
 
245
+ FUNC.proxyclient = function(endpoint, port) {
246
+ require('../proxyclient').init(endpoint, port);
247
+ };
248
+
244
249
  FUNC.edit = function(url) {
245
250
  if (!url)
246
251
  throw new Error('Invalid URL address');
package/builders.js CHANGED
@@ -117,7 +117,17 @@ Options.prototype.transform = function(name, value, callback) {
117
117
  };
118
118
 
119
119
  Options.prototype.action = function(schema, payload) {
120
- return F.action(schema, payload, this.controller);
120
+ let t = this;
121
+ let action = F.action(schema, payload, this.controller);
122
+ if (!t.controller) {
123
+ if (t.user)
124
+ action.options.user = t.user;
125
+ if (t.query)
126
+ action.options.query = t.query;
127
+ if (t.params)
128
+ action.options.params = t.params;
129
+ }
130
+ return action;
121
131
  };
122
132
 
123
133
  Options.prototype.promisify = function(fn, a, b, c) {
@@ -231,7 +241,7 @@ Options.prototype.successful = function(callback) {
231
241
  };
232
242
  };
233
243
 
234
- Options.prototype.callback = function(value) {
244
+ Options.prototype.callback = Options.prototype.pipe = function(value) {
235
245
 
236
246
  var self = this;
237
247
 
@@ -1489,7 +1499,7 @@ ActionCaller.prototype.done = function($, fn) {
1489
1499
  return this;
1490
1500
  };
1491
1501
 
1492
- ActionCaller.prototype.callback = function(value) {
1502
+ ActionCaller.prototype.callback = ActionCaller.prototype.pipe = function(value) {
1493
1503
  this.options.callback = value;
1494
1504
  return this;
1495
1505
  };
package/changelog.txt CHANGED
@@ -1,9 +1,24 @@
1
+ ========================
2
+ 0.0.11
3
+ ========================
4
+
5
+ - fixed `controller` and `user` argument in the `TRANSFORM()` method
6
+ - fixed assigning `user`, `query` and `params` properties in the `$.action()` method
7
+ - fixed nullable `value` argument in the `querybuilder.permit()`
8
+ - fixed parsing `CONF.version`
9
+ - added `QueryBuilder.pipe()` method as alias to `QueryBuilder.callback()`
10
+ - added `API.pipe()` method as alias to `API.callback()`
11
+ - added `Action.pipe()` method as alias to `Action.callback()`
12
+ - added `RESTBuilder.pipe()` method as alias to `RESTBuilder.callback()`
13
+ - added support for localization in the `TEMPLATE()` method
14
+
1
15
  ========================
2
16
  0.0.10
3
17
  ========================
4
18
 
5
19
  - improved HTMLParser parser
6
20
  - extended `Flow.socket(flow, socket, [verify(client)], [check(client, msg)])` by adding `check` argument for verifying permissions
21
+ - fixed icons in FlowStream core for TMS
7
22
 
8
23
  ========================
9
24
  0.0.9
@@ -3182,7 +3182,7 @@ TMS.refresh = function(fs, callback) {
3182
3182
  readme.push(beautifyjsonschema(m.schema));
3183
3183
 
3184
3184
  var id = 'pub' + item.id + 'X' + m.id;
3185
- var template = TEMPLATE_PUBLISH.format(item.meta.name, m.id, readme.join('\n'), m.icon || 'fas fa-broadcast-tower', m.url, id, item.meta.name.max(15), item.id);
3185
+ var template = TEMPLATE_PUBLISH.format(item.meta.name, m.id, readme.join('\n'), m.icon || 'ti ti-antenna', m.url, id, item.meta.name.max(15), item.id);
3186
3186
  var com = fs.add(id, template);
3187
3187
  m.url = url;
3188
3188
  com.type = 'pub';
@@ -3204,7 +3204,7 @@ TMS.refresh = function(fs, callback) {
3204
3204
  readme.push(beautifyjsonschema(m));
3205
3205
 
3206
3206
  var id = 'sub' + item.id + 'X' + m.id;
3207
- var template = TEMPLATE_SUBSCRIBE.format(item.meta.name, m.id, readme.join('\n'), m.icon || 'fas fa-satellite-dish', m.url, id, item.meta.name.max(15), item.id);
3207
+ var template = TEMPLATE_SUBSCRIBE.format(item.meta.name, m.id, readme.join('\n'), m.icon || 'ti ti-satellite', m.url, id, item.meta.name.max(15), item.id);
3208
3208
  var com = fs.add(id, template);
3209
3209
  m.url = url;
3210
3210
  com.type = 'sub';
@@ -3226,7 +3226,7 @@ TMS.refresh = function(fs, callback) {
3226
3226
  readme.push(beautifyjsonschema(m.schema));
3227
3227
 
3228
3228
  var id = 'cal' + item.id + 'X' + m.id;
3229
- var template = TEMPLATE_CALL.format(item.meta.name, m.id, readme.join('\n'), m.icon || 'fa fa-plug', m.url, id, item.meta.name.max(15), item.id);
3229
+ var template = TEMPLATE_CALL.format(item.meta.name, m.id, readme.join('\n'), m.icon || 'ti ti-plug', m.url, id, item.meta.name.max(15), item.id);
3230
3230
  var com = fs.add(id, template);
3231
3231
  m.url = url;
3232
3232
  com.type = 'call';
package/index.js CHANGED
@@ -36,7 +36,7 @@ global.DEF = {};
36
36
 
37
37
  F.id = '';
38
38
  F.clusterid = '';
39
- F.is5 = F.version = 5010;
39
+ F.is5 = F.version = 5011;
40
40
  F.isBundle = false;
41
41
  F.isLoaded = false;
42
42
  F.version_header = '5';
@@ -608,7 +608,7 @@ F.loadconfig = function(value) {
608
608
  F.Http.globalAgent.maxSockets = 9999;
609
609
 
610
610
  if (!F.config.$httpetag)
611
- F.config.$httpetag = F.config.version.replace(/\.|\s/g, '');
611
+ F.config.$httpetag = (F.config.version || '').toString().replace(/\.|\s/g, '');
612
612
 
613
613
  if (smtp)
614
614
  F.config.smtp = smtp;
@@ -1976,11 +1976,15 @@ function transform(items, opt, index) {
1976
1976
  F.transform = function(name, value, callback, controller) {
1977
1977
 
1978
1978
  if (typeof(callback) !== 'function')
1979
- return new Promise((resolve, reject) => F.transform(name, value, (err, response) => err ? reject(err) : resolve(response), controller));
1979
+ return new Promise((resolve, reject) => F.transform(name, value, (err, response) => err ? reject(err) : resolve(response), callback || controller));
1980
1980
 
1981
1981
  var items = F.transformations[name];
1982
1982
  if (items) {
1983
1983
  let opt = new F.TBuilders.Options(controller, new F.TBuilders.ErrorBuilder());
1984
+
1985
+ if (controller)
1986
+ opt.user = controller.user;
1987
+
1984
1988
  opt.value = value;
1985
1989
  opt.$callback = callback;
1986
1990
  transform(items, opt, 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "total5",
3
- "version": "0.0.10-2",
3
+ "version": "0.0.11",
4
4
  "description": "Total.js framework v5",
5
5
  "main": "index.js",
6
6
  "directories": {
package/proxyclient.js ADDED
@@ -0,0 +1,145 @@
1
+ // Total.js client for Proxy
2
+ // The MIT License
3
+ // Copyright 2017-2023 (c) Peter Širka <petersirka@gmail.com>
4
+
5
+ const BUFFER_INIT = Buffer.alloc(1);
6
+ BUFFER_INIT.writeUInt8(0);
7
+
8
+ const BUFFER_DATA = Buffer.alloc(1);
9
+ BUFFER_DATA.writeUInt8(1);
10
+
11
+ const BUFFER_END = Buffer.alloc(1);
12
+ BUFFER_END.writeUInt8(2);
13
+
14
+ const BUFFER_ERROR = Buffer.alloc(1);
15
+ BUFFER_END.writeUInt8(3);
16
+
17
+ const BUFFER_ABORT = Buffer.alloc(1);
18
+ BUFFER_END.writeUInt8(4);
19
+
20
+ const Pending = {};
21
+
22
+ function help() {
23
+ console.log('Proxy client arguments:');
24
+ console.log('client [WSS proxy server] [port or ip:port]');
25
+ }
26
+
27
+ function log() {
28
+
29
+ let arr = [new Date().format('yyyy-MM-dd HH:mm:ss')];
30
+
31
+ for (let index in arguments)
32
+ arr.push(arguments[index]);
33
+
34
+ console.log.apply(console, arr);
35
+ }
36
+
37
+ function connect(Source, Target) {
38
+
39
+ F.websocketclient(function(client) {
40
+
41
+ client.options.type = 'binary';
42
+ client.connect(Target.replace(/^http/i, 'ws'));
43
+
44
+ client.on('open', function() {
45
+ log('\x1b[42m[OK]\x1b[0m', 'Proxy client successfully connected to \x1b[41m{0}\x1b[0m'.format(Target));
46
+ });
47
+
48
+ client.on('close', function() {
49
+ log('\x1b[41m[NO]\x1b[0m', 'Proxy client is disconnected.');
50
+ });
51
+
52
+ client.on('message', function(msg) {
53
+
54
+ let type = msg.readInt8(0);
55
+ let id = msg.readInt32BE(1);
56
+ let data = msg.slice(5);
57
+ let req = Pending[id];
58
+
59
+ switch (type) {
60
+ case 0: // init
61
+
62
+ let tmp = JSON.parse(data.toString('utf8'));
63
+ let opt = {};
64
+ opt.hostname = Source[0];
65
+ opt.port = Source[1];
66
+ opt.headers = tmp.headers;
67
+ opt.headers['x-proxy'] = 'Total.js';
68
+ opt.headers.host = Source[0] + ':' + Source[1];
69
+ opt.method = tmp.method;
70
+ opt.path = tmp.url;
71
+
72
+ log('\x1b[43m[' + opt.method + ']\x1b[0m', '\x1b[34m' + tmp.ip + '\x1b[0m', opt.path);
73
+
74
+ req = Total.Http.request(opt);
75
+ req.ID = Buffer.alloc(4);
76
+ req.ID.writeUInt32BE(id);
77
+
78
+ Pending[id] = req;
79
+
80
+ req.on('error', function(err) {
81
+ delete Pending[id];
82
+ client.send(Buffer.concat([BUFFER_ERROR, req.ID, Buffer.from(err.toString(), 'utf8')]));
83
+ });
84
+
85
+ req.on('abort', function() {
86
+ delete Pending[id];
87
+ client.send(Buffer.concat([BUFFER_ABORT, req.ID]));
88
+ });
89
+
90
+ req.on('response', function(res) {
91
+
92
+ let obj = {};
93
+ obj.status = res.statusCode;
94
+ obj.headers = res.headers;
95
+
96
+ delete Pending[id];
97
+ res.req = req;
98
+ client.send(Buffer.concat([BUFFER_INIT, req.ID, Buffer.from(JSON.stringify(obj))]));
99
+ res.on('data', chunk => client.send(Buffer.concat([BUFFER_DATA, req.ID, chunk])));
100
+
101
+ res.on('error', function(err) {
102
+ delete Pending[id];
103
+ client.send(Buffer.concat([BUFFER_ERROR, req.ID, Buffer.from(err.toString(), 'utf8')]));
104
+ });
105
+
106
+ res.on('abort', function() {
107
+ delete Pending[id];
108
+ client.send(Buffer.concat([BUFFER_ABORT, req.ID]));
109
+ });
110
+
111
+ res.on('end', () => client.send(Buffer.concat([BUFFER_END, req.ID])));
112
+ });
113
+ break;
114
+
115
+ case 1: // data
116
+ req && req.write(data);
117
+ break;
118
+
119
+ case 2: // end
120
+ req && req.end();
121
+ break;
122
+ }
123
+
124
+ });
125
+ });
126
+ }
127
+
128
+ exports.init = function (endpoint, port) {
129
+ let Target = endpoint;
130
+ let Source = port;
131
+
132
+ if (!Target || !Source) {
133
+ help();
134
+ return;
135
+ }
136
+
137
+ Source = Source.split(':');
138
+
139
+ if (!Source[1]) {
140
+ Source[1] = +Source[0];
141
+ Source[0] = '127.0.0.1';
142
+ }
143
+
144
+ connect(Source, Target);
145
+ };
package/querybuilder.js CHANGED
@@ -153,7 +153,7 @@ CTP.next = function(t) {
153
153
 
154
154
  };
155
155
 
156
- CTP.callback = function($) {
156
+ CTP.callback = CTP.pipe = function($) {
157
157
  var t = this;
158
158
  t.$callback = typeof($) === 'function' ? $ : $.callback();
159
159
  return t;
@@ -499,7 +499,7 @@ QBP.set = function(name) {
499
499
  return this;
500
500
  };
501
501
 
502
- QBP.callback = function($) {
502
+ QBP.callback = QBP.pipe = function($) {
503
503
  var t = this;
504
504
  t.main.callback = typeof($) === 'function' ? $ : $.callback();
505
505
  return t;
@@ -1192,9 +1192,11 @@ QBP.permit = function(name, type, value, userid, required) {
1192
1192
  var types = type.split('');
1193
1193
  var arr = [];
1194
1194
 
1195
- for (let m of value) {
1196
- for (let n of types)
1197
- arr.push(n + m);
1195
+ if (value && value.length) {
1196
+ for (let m of value) {
1197
+ for (let n of types)
1198
+ arr.push(n + m);
1199
+ }
1198
1200
  }
1199
1201
 
1200
1202
  t.options.checksum += (t.options.checksum ? ' ' : '') + 'permit' + type + arr.join('');
package/templates.js CHANGED
@@ -6,7 +6,7 @@ exports.render = function(body, model, $) {
6
6
  return new Promise(function(resolve, reject) {
7
7
 
8
8
  var cache = F.temporary.templates;
9
- var id = 'Ttemplate' + HASH(body);
9
+ var id = 'Ttemplate' + HASH(body) + ($ ? $.language : '');
10
10
  var data = cache[id];
11
11
 
12
12
  if (data) {
@@ -45,7 +45,7 @@ exports.render = function(body, model, $) {
45
45
  return;
46
46
  }
47
47
 
48
- data = parse(response.body);
48
+ data = parse(response.body, $);
49
49
  cache[id] = data;
50
50
 
51
51
  try {
@@ -83,7 +83,7 @@ exports.render = function(body, model, $) {
83
83
  return;
84
84
  }
85
85
 
86
- data = parse(response.toString('utf8'));
86
+ data = parse(response.toString('utf8'), $);
87
87
 
88
88
  if (!DEBUG)
89
89
  cache[id] = data;
@@ -102,7 +102,7 @@ exports.render = function(body, model, $) {
102
102
  }
103
103
  }
104
104
 
105
- data = cache[id] = parse(body);
105
+ data = cache[id] = parse(body, $);
106
106
 
107
107
  try {
108
108
  resolve(data.template({ value: model || data.model }, null, data.helpers));
@@ -115,7 +115,10 @@ exports.render = function(body, model, $) {
115
115
  });
116
116
  };
117
117
 
118
- function parse(body) {
118
+ function parse(body, $) {
119
+
120
+ if ($ && $.language)
121
+ body = F.translate($.language, body);
119
122
 
120
123
  var helpers = {};
121
124
  var model = EMPTYOBJECT;