total5 0.0.13-3 → 0.0.13-5

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/builders.js CHANGED
@@ -1360,6 +1360,7 @@ ActionCaller.prototype.exec = function() {
1360
1360
  $.controller = self.controller;
1361
1361
  $.fields = action.fields;
1362
1362
  $.user = self.options.user;
1363
+ $.config = action.config || EMPTYOBJECT;
1363
1364
 
1364
1365
  $.$callback = function(err, response) {
1365
1366
 
package/changelog.txt CHANGED
@@ -6,6 +6,8 @@
6
6
  - added auto script loader for `transforms` directory
7
7
  - added support for Python scripts in the `pypelines` folder
8
8
  - added `PYPELINE(name, [options])` method starts a python process
9
+ - added support for custom View engine helpers `DEF.helpers.myhelper`
10
+ - fixed killing workers and pypelines
9
11
 
10
12
  ========================
11
13
  0.0.12
package/components.js CHANGED
@@ -260,7 +260,7 @@ Instance.prototype.debug = function(msg) {
260
260
  };
261
261
 
262
262
  Instance.prototype.throw = function(err) {
263
- this.module.throw(this, error);
263
+ this.module.throw(this, err);
264
264
  };
265
265
 
266
266
  Instance.prototype.dashboard = function(msg) {
@@ -344,8 +344,6 @@ exports.compile = function(html, callback) {
344
344
  return;
345
345
  }
346
346
 
347
- var errors = [];
348
-
349
347
  (com.npm || EMPTYARRAY).wait(function(name, next) {
350
348
  NPMINSTALL(name, function(err) {
351
349
  if (err) {
@@ -378,4 +376,4 @@ exports.compile = function(html, callback) {
378
376
  callback(null, com);
379
377
  });
380
378
 
381
- };
379
+ };
package/debug.js CHANGED
@@ -46,8 +46,7 @@ module.exports.watcher = function(callback) {
46
46
  function killapp(pid) {
47
47
  try {
48
48
  process.kill(pid, 'SIGINT');
49
- } catch (e) {
50
- }
49
+ } catch {}
51
50
  }
52
51
 
53
52
  function runapp() {
@@ -72,11 +71,11 @@ function runwatching() {
72
71
 
73
72
  const FILENAME = F.TUtils.getName(process.argv[1] || 'index.js');
74
73
  const VERSION = F.version_header;
75
- const REG_FILES = /(config|bundles\.debug|\.js|\.ts|\.flow|\.resource)+$/i;
74
+ const REG_FILES = /(config|bundles\.debug|\.js|\.ts|\.flow|\.py|\.resource)+$/i;
76
75
  const REG_PUBLIC = /\/public\//i;
77
76
  const REG_INDEX = new RegExp(FILENAME.replace(/\.js$/, '') + '_.*?\\.js$');
78
- const REG_EXTENSION = /\.(js|ts|resource|package|bundle|build|flow|url)$/i;
79
- const REG_RELOAD = /\.(js|ts|css|html|htm|jpg|png|gif|ico|svg|webp|resource)$/i;
77
+ const REG_EXTENSION = /\.(js|ts|py|resource|package|bundle|build|flow|url)$/i;
78
+ const REG_RELOAD = /\.(js|ts|py|css|html|htm|jpg|png|gif|ico|svg|webp|resource)$/i;
80
79
  const isRELOAD = !!options.livereload;
81
80
  const SPEED = isRELOAD ? 1000 : 1500;
82
81
  const ARGV = F.TUtils.clone(process.argv);
@@ -551,4 +550,4 @@ function init() {
551
550
  setImmediate(runapp);
552
551
  }
553
552
 
554
- Meta.delay = setTimeout(init, 100);
553
+ Meta.delay = setTimeout(init, 100);
@@ -1019,9 +1019,9 @@ function init_current(meta, callback, nested) {
1019
1019
  flow.proxy.ping = 0;
1020
1020
 
1021
1021
  if (meta.import) {
1022
- var tmp = meta.import.split(/,|;/).trim();
1023
- for (var m of tmp) {
1024
- var mod = require(F.path.root(m));
1022
+ let tmp = meta.import.split(/,|;/).trim();
1023
+ for (let m of tmp) {
1024
+ let mod = require(F.path.root(m));
1025
1025
  mod.install && mod.install(flow);
1026
1026
  mod.init && mod.init(flow);
1027
1027
  }
@@ -3382,4 +3382,4 @@ if (process.argv[1].endsWith('flow-flowstream.js')) {
3382
3382
  });
3383
3383
  }
3384
3384
 
3385
- }
3385
+ }
package/index.js CHANGED
@@ -68,6 +68,7 @@ global.DEF = {};
68
68
  F.errors = [];
69
69
  F.paused = [];
70
70
  F.crons = [];
71
+ F.pypelines = [];
71
72
 
72
73
  F.internal = {
73
74
  ticks: 0,
@@ -2492,7 +2493,14 @@ F.exit = function(signal = 15) {
2492
2493
  let worker = F.workers[m];
2493
2494
  try {
2494
2495
  worker && worker.kill && worker.kill(signal);
2495
- } catch (e) {}
2496
+ } catch {}
2497
+ }
2498
+
2499
+
2500
+ for (let m of F.pypelines) {
2501
+ try {
2502
+ m.kill(signal);
2503
+ } catch {}
2496
2504
  }
2497
2505
 
2498
2506
  let key = 'exit';
@@ -2502,7 +2510,7 @@ F.exit = function(signal = 15) {
2502
2510
  if (!F.isWorker && process.send && process.connected) {
2503
2511
  try {
2504
2512
  process.send('total:stop');
2505
- } catch (e) {}
2513
+ } catch {}
2506
2514
  }
2507
2515
 
2508
2516
  F.internal.interval && clearInterval(F.internal.interval);
@@ -2778,6 +2786,15 @@ function httptuningperformance(socket) {
2778
2786
  socket.setKeepAlive(true, 10);
2779
2787
  }
2780
2788
 
2789
+ function forcestop() {
2790
+ console.log('KILLUJEM');
2791
+ F.exit();
2792
+ }
2793
+
2794
+ process.on('SIGTERM', forcestop);
2795
+ process.on('SIGINT', forcestop);
2796
+ process.on('exit', forcestop);
2797
+
2781
2798
  process.on('unhandledRejection', function(e) {
2782
2799
  F.error(e.stack, '');
2783
2800
  });
package/mail.js CHANGED
@@ -731,7 +731,7 @@ Mailer.$send = function(obj, options, autosend) {
731
731
  isAuthorization = true;
732
732
  if (options.token && line.indexOf('XOAUTH2') !== -1) {
733
733
  auth.push('AUTH XOAUTH2');
734
- auth.push(Buffer.from('user=' + options.user + '\1auth=Bearer ' + options.token + '\1\1').toString('base64'));
734
+ auth.push(Buffer.from('user=' + options.user + '\x01auth=Bearer ' + options.token + '\x01\x01').toString('base64'));
735
735
  } else if (line.lastIndexOf('XOAUTH') === -1) {
736
736
  auth.push('AUTH LOGIN');
737
737
  auth.push(Buffer.from(options.user).toString('base64'));
@@ -924,4 +924,4 @@ exports.refresh = function() {
924
924
  if (conn.TS < NOW && (!conn.messages || !conn.messages.length))
925
925
  Mailer.destroy(F.temporary.smtp[key]);
926
926
  }
927
- };
927
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "total5",
3
- "version": "0.0.13-3",
3
+ "version": "0.0.13-5",
4
4
  "description": "Total.js framework v5",
5
5
  "main": "index.js",
6
6
  "directories": {
package/pypeline.js CHANGED
@@ -6,7 +6,6 @@ function Pypeline(filename) {
6
6
 
7
7
  t.socket = PATH.tmp('pypeline_' + HASH(filename).toString(36) + '.socket');
8
8
  t.filename = filename;
9
- t.callbacks = {};
10
9
  t.sockets = [];
11
10
  t.processes = [];
12
11
  t.current = 0;
@@ -63,21 +62,9 @@ Pypeline.prototype.init = function() {
63
62
  });
64
63
 
65
64
  socket.on('end', function() {
66
-
67
- for (let key in t.callbacks) {
68
- let callback = t.callbacks[key];
69
- if (callback.socket === socket) {
70
- try {
71
- callbacks.fn('Disconnected');
72
- } catch {}
73
- delete t.callbacks[key];
74
- }
75
- }
76
-
77
65
  let index = t.sockets.indexOf(socket);
78
66
  if (index !== -1)
79
67
  t.sockets.splice(index);
80
-
81
68
  });
82
69
 
83
70
  let pending = t.pending.splice(0);
@@ -117,14 +104,6 @@ Pypeline.prototype.close = function() {
117
104
  t.process.kill(9);
118
105
  } catch {}
119
106
 
120
- for (let key in t.callbacks) {
121
- let callback = t.callbacks[key];
122
- try {
123
- callbacks.fn('Disconnected');
124
- } catch {}
125
- }
126
-
127
- t.callbacks = null;
128
107
  return t;
129
108
  };
130
109
 
@@ -166,7 +145,6 @@ Pypeline.prototype.run = Pypeline.prototype.restart = function() {
166
145
  }
167
146
 
168
147
  let args = [];
169
- let scr = t.filename.includes('\n');
170
148
 
171
149
  if (t.inline)
172
150
  args.push('-c');
@@ -176,15 +154,22 @@ Pypeline.prototype.run = Pypeline.prototype.restart = function() {
176
154
  args.push(t.filename);
177
155
  args.push(t.socket);
178
156
 
179
- t.process = Total.Child.spawn('python3', args, { cwd: t.inline ? PATH.root() : Total.Path.dirname(t.filename), stdio: ['inherit', 'inherit', 'inherit'] });
157
+ t.process = Total.Child.spawn('python3', args, { cwd: t.inline ? PATH.root() : Total.Path.dirname(t.filename), stdio: ['inherit', 'inherit', 'inherit'], detached: false });
158
+ t.process.$pypelines = t;
159
+ F.pypelines.push(t.process);
180
160
 
181
161
  t.process.on('close', function() {
162
+
163
+ let index = F.pypelines.indexOf(t.process);
164
+ F.pypelines.splice(index, 1);
165
+
182
166
  if (t.autorestart) {
183
167
  t.run();
184
168
  t.emit('restart');
185
169
  } else {
186
170
  t.server.close();
187
171
  t.emit('close');
172
+ F.pypelines.push(t);
188
173
  }
189
174
  });
190
175
 
@@ -221,4 +206,4 @@ exports.init = function(filename, options, inline) {
221
206
  }
222
207
 
223
208
  return pypeline;
224
- };
209
+ };
package/tangular.js CHANGED
@@ -96,7 +96,7 @@
96
96
 
97
97
  self.template = template;
98
98
 
99
- template = template.replace(/\|\|/g, '\1');
99
+ template = template.replace(/\|\|/g, '\x01');
100
100
 
101
101
  self.variables = {};
102
102
  self.commands = [];
@@ -221,9 +221,9 @@
221
221
  var ishelperfirst = ishelper && !i;
222
222
  index = helper.indexOf('(');
223
223
  if (index === -1) {
224
- helper = 'Thelpers.$execute($helpers,model,\'' + helper + '\',' + (ishelperfirst ? '' : '\7)');
224
+ helper = 'Thelpers.$execute($helpers,model,\'' + helper + '\',' + (ishelperfirst ? '' : '\x07)');
225
225
  } else
226
- helper = 'Thelpers.$execute($helpers,model,\'' + helper.substring(0, index) + '\',' + (ishelperfirst ? '' : '\7,') + helper.substring(index + 1);
226
+ helper = 'Thelpers.$execute($helpers,model,\'' + helper.substring(0, index) + '\',' + (ishelperfirst ? '' : '\x07,') + helper.substring(index + 1);
227
227
  helpers[i] = helper;
228
228
  }
229
229
  } else
@@ -315,9 +315,9 @@
315
315
  for (var j = 0; j < cmd.helpers.length; j++) {
316
316
  var helper = cmd.helpers[j];
317
317
  if (j === 0)
318
- str = helper.replace('\7', cmd.cmd.trim()).trim();
318
+ str = helper.replace('\x07', cmd.cmd.trim()).trim();
319
319
  else
320
- str = helper.replace('\7', str.trim());
320
+ str = helper.replace('\x07', str.trim());
321
321
  }
322
322
  builder.push('$tmp=' + str + ';if($tmp!=null)$output+=$tmp;');
323
323
  } else
@@ -406,4 +406,4 @@
406
406
  Thelpers.empty=Thelpers.def=function(e,n){return e?Thelpers.encode(e):n||'---'};
407
407
  Thelpers.currency=function(e,t){switch(typeof e){case'number':return e.currency(t);case'string':return e.parseFloat().currency(t);default:return''}};
408
408
 
409
- })(global);
409
+ })(global);
package/viewengine.js CHANGED
@@ -112,7 +112,6 @@ exports.compile = function(name, content, debug = true) {
112
112
  var isCOMPILATION = false;
113
113
  var builderTMP = '';
114
114
  var sectionName = '';
115
- var components = {};
116
115
  var text;
117
116
 
118
117
  while (command) {
@@ -258,7 +257,7 @@ exports.compile = function(name, content, debug = true) {
258
257
  if (!debug)
259
258
  builder = builder.replace(/(\+\$EMPTY\+)/g, '+').replace(/(\$output=\$EMPTY\+)/g, '$output=').replace(/(\$output\+=\$EMPTY\+)/g, '$output+=').replace(/(\}\$output\+=\$EMPTY)/g, '}').replace(/(\{\$output\+=\$EMPTY;)/g, '{').replace(/(\+\$EMPTY\+)/g, '+').replace(/(>'\+'<)/g, '><').replace(/'\+'/g, '');
260
259
 
261
- var fn = ('(function(self){var model=self.model;var config=F.config;var ctrl=self.controller;var query=ctrl?.query || EMPTYOBJECT,repository=self.repository,controller=self.controller,files=ctrl?.files || EMPTYARRAY,user=ctrl?.user,session=ctrl?.session,body=ctrl?.body,language=ctrl?.language || \'\'' + (isCookie ? ',cookie=name=>ctrl?ctrl.cookie(name):\'\'' : '') + ';' + (nocompressHTML ? 'if(ctrl)ctrl.response.minify=false;' : '') + builder + ';return $output;})');
260
+ var fn = ('(function(self){var model=self.model;var config=F.config;var ctrl=self.controller;var query=ctrl?.query || EMPTYOBJECT,repository=self.repository,controller=self.controller,files=ctrl?.files || EMPTYARRAY,user=ctrl?.user,session=ctrl?.session,body=ctrl?.body,helpers=F.def.helpers;language=ctrl?.language || \'\'' + (isCookie ? ',cookie=name=>ctrl?ctrl.cookie(name):\'\'' : '') + ';' + (nocompressHTML ? 'if(ctrl)ctrl.response.minify=false;' : '') + builder + ';return $output;})');
262
261
  try {
263
262
  fn = eval(fn);
264
263
  } catch (e) {
@@ -609,6 +608,18 @@ View.prototype.layout = function(value) {
609
608
  return '';
610
609
  };
611
610
 
611
+ View.prototype.helper = function(name) {
612
+ var helper = F.def.helpers[name];
613
+ if (!helper)
614
+ return '';
615
+
616
+ var params = [];
617
+ for (var i = 1; i < arguments.length; i++)
618
+ params.push(arguments[i]);
619
+
620
+ return helper.apply(this, params);
621
+ };
622
+
612
623
  View.prototype.json = function(obj, id, beautify, replacer) {
613
624
 
614
625
  if (typeof(id) === 'boolean') {
@@ -912,4 +923,4 @@ View.prototype.render = function(name, model, ispartial = false) {
912
923
  return content;
913
924
  };
914
925
 
915
- exports.View = View;
926
+ exports.View = View;