total5 0.0.1-4 → 0.0.1-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/bundles.js CHANGED
@@ -400,7 +400,7 @@ exports.extract = function(callback, skip) {
400
400
  try {
401
401
 
402
402
  if (F.Fs.readFileSync('bundles.debug')) {
403
- F.isbundle = true;
403
+ F.isBundle = true;
404
404
  F.dir(F.path.root('/.src/'));
405
405
  callback();
406
406
  return;
@@ -428,7 +428,7 @@ exports.extract = function(callback, skip) {
428
428
  });
429
429
  }, function() {
430
430
  extract(function() {
431
- F.isbundle = true;
431
+ F.isBundle = true;
432
432
  F.dir(F.path.root('/.src/'));
433
433
  callback();
434
434
  });
@@ -436,21 +436,11 @@ exports.extract = function(callback, skip) {
436
436
  };
437
437
 
438
438
  try {
439
-
440
439
  var files = F.Fs.readdirSync(bundles);
441
440
  if (files.length)
442
441
  extractbundles();
443
442
  else
444
443
  callback();
445
-
446
- /*
447
- if (F.$bundling) {
448
- makebundle();
449
- return;
450
- } else {
451
- F.isbundle = true;
452
- F.dir(F.path.root('/.src/'));
453
- }*/
454
444
  } catch(e) {
455
445
  callback();
456
446
  }
@@ -586,12 +586,12 @@ Instance.prototype.reload = function(data, restart = false) {
586
586
  else
587
587
  flow.kill(9);
588
588
  } else
589
- flow.postMessage2({ TYPE: 'stream/replace', data: data });
589
+ flow.postMessage2({ TYPE: 'stream/rewrite', data: data });
590
590
  } else {
591
591
  for (let key in data)
592
592
  flow.$schema[key] = data[key];
593
593
  flow.variables = data.variables;
594
- flow.replace(data, () => flow.proxy.refreshmeta());
594
+ flow.rewrite(data, () => flow.proxy.refreshmeta());
595
595
  }
596
596
 
597
597
  return self;
@@ -1065,11 +1065,11 @@ function init_current(meta, callback, nested) {
1065
1065
  flow.save();
1066
1066
  break;
1067
1067
 
1068
- case 'stream/replace':
1068
+ case 'stream/rewrite':
1069
1069
  for (var key in msg.data)
1070
1070
  flow.$schema[key] = msg.data[key];
1071
1071
 
1072
- flow.replace(msg.data, function() {
1072
+ flow.rewrite(msg.data, function() {
1073
1073
 
1074
1074
  // @err {Error}
1075
1075
 
package/flowstream.js CHANGED
@@ -277,7 +277,7 @@ function variables(str, data, encoding) {
277
277
  if (typeof(str) !== 'string' || str.indexOf('{') === -1)
278
278
  return str;
279
279
 
280
- var main = this.main;
280
+ var main = this.main ? this.main : this;
281
281
 
282
282
  if (data == null || data == true)
283
283
  data = this;
@@ -1276,7 +1276,8 @@ FP.load = function(data, callback) {
1276
1276
  return self;
1277
1277
  };
1278
1278
 
1279
- FP.replace = function(data, callback) {
1279
+ FP.replace = variables;
1280
+ FP.rewrite = function(data, callback) {
1280
1281
 
1281
1282
  var self = this;
1282
1283
  if (self.loading) {
package/global.js CHANGED
@@ -23,6 +23,7 @@ global.NEWDB = F.newdb;
23
23
  global.REQUIRE = F.require;
24
24
  global.CRON = F.cron;
25
25
  global.UID = F.uid;
26
+ global.SUCCESS = value => DEF.onSuccess(value);
26
27
  global.MEMORIZE = F.memorize;
27
28
  global.AUDIT = F.audit;
28
29
  global.TRANSLATE = F.translate;
package/index.js CHANGED
@@ -37,6 +37,7 @@ global.DEF = {};
37
37
  F.id = '';
38
38
  F.clusterid = '';
39
39
  F.is5 = F.version = 5000;
40
+ F.isBundle = false;
40
41
  F.version_header = '5';
41
42
  F.version_node = process.version + '';
42
43
  F.EMPTYOBJECT = EMPTYOBJECT;
@@ -489,7 +490,7 @@ function unlink(arr, callback) {
489
490
  if (F.errors.push(obj) > 10)
490
491
  F.errors.shift();
491
492
 
492
- EMIT('error', obj);
493
+ F.$events.error && F.emit('error', obj);
493
494
  F.stats.error++;
494
495
  };
495
496
 
@@ -730,21 +731,35 @@ F.load = async function(types, callback) {
730
731
  }
731
732
 
732
733
  if (!types.length || types.includes('env')) {
733
- var env = await read(F.path.root('.env'));
734
+ let env = await read(F.path.root('.env'));
734
735
  env && F.loadenv(env);
735
736
  }
736
737
 
737
738
  if (!types.length || types.includes('config')) {
738
- var config = await read(F.path.root('config'));
739
+ let config = await read(F.path.root('config'));
739
740
  config && F.loadconfig(config);
740
741
  }
741
742
 
742
743
  if (!types.length || types.includes('resources')) {
743
- var resources = await list(F.path.root('resources'), 'resource');
744
+ let resources = await list(F.path.root('resources'), 'resource');
744
745
  for (let resource of resources)
745
746
  F.loadresource(F.TUtils.getName(resource).replace(/\.resource$/i, ''), await read(resource));
746
747
  }
747
748
 
749
+ if (!types.length || types.includes('jsonschemas')) {
750
+ let jsonschemas = await list(F.path.root('jsonschemas'), 'json');
751
+ for (let jsonschema of jsonschemas) {
752
+ let json = await read(jsonschema);
753
+ json = json.parseJSON();
754
+ json && F.newjsonschema(F.TUtils.getName(jsonschema).replace(/\.json$/i, ''), json);
755
+ }
756
+ jsonschemas = await list(F.path.root('jsonschemas'), 'txt');
757
+ for (let jsonschema of jsonschemas) {
758
+ let txt = await read(jsonschema);
759
+ txt && F.newjsonschema(F.TUtils.getName(jsonschema).replace(/\.txt$/i, ''), txt);
760
+ }
761
+ }
762
+
748
763
  let loader = ['modules', 'controllers', 'actions', 'schemas', 'models', 'definitions', 'sources', 'middleware'];
749
764
  var files = [];
750
765
  var tmp;
@@ -2274,6 +2289,10 @@ F.backup = function(filename, files, callback, filter) {
2274
2289
  });
2275
2290
  };
2276
2291
 
2292
+ F.restart = function() {
2293
+ process.send && process.send('total:restart');
2294
+ };
2295
+
2277
2296
  F.exit = function(signal) {
2278
2297
 
2279
2298
  if (F.isexited)
@@ -2291,7 +2310,7 @@ F.exit = function(signal) {
2291
2310
  } catch (e) {}
2292
2311
  }
2293
2312
 
2294
- let key = '$exit';
2313
+ let key = 'exit';
2295
2314
 
2296
2315
  F.$events[key] && F.emit(key, signal);
2297
2316
 
@@ -2425,6 +2444,12 @@ F.mail = function(email, subject, name, model, language, callback) {
2425
2444
  callback = tmp;
2426
2445
  }
2427
2446
 
2447
+ // Localization
2448
+ if (typeof(language) === 'string') {
2449
+ if (subject.includes('@('))
2450
+ subject = TRANSLATE(language, subject);
2451
+ }
2452
+
2428
2453
  let body = F.view(name, model, view => view.language = language || '');
2429
2454
  return F.def.onMail(email, subject, body, callback);
2430
2455
  };
@@ -2437,14 +2462,15 @@ F.htmlmail = function(email, subject, body, language, callback) {
2437
2462
  callback = tmp;
2438
2463
  }
2439
2464
 
2440
- // Translation
2465
+ // Localization
2441
2466
  if (typeof(language) === 'string') {
2442
- subject = subject.indexOf('@(') === -1 ? TRANSLATE(language, subject) : TRANSLATOR(language, subject);
2443
- if (body.indexOf('@(') !== -1)
2444
- body = TRANSLATOR(language, body);
2467
+ if (subject.includes('@('))
2468
+ subject = TRANSLATE(language, subject);
2469
+ if (body.includes('@('))
2470
+ body = TRANSLATE(language, body);
2445
2471
  }
2446
2472
 
2447
- var body = body.indexOf('<body>') === -1 ? ('<!DOCTYPE html><html><head><title>' + subject + '</title><meta charset="utf-8" /></head><body style="padding:0;margin:0;font-family:Arial;font-size:14px;font-weight:normal">' + body + '</body></html>') : body;
2473
+ body = body.indexOf('<body>') === -1 ? ('<!DOCTYPE html><html><head><title>' + subject + '</title><meta charset="utf-8" /></head><body style="padding:0;margin:0;font-family:Arial;font-size:14px;font-weight:normal">' + body + '</body></html>') : body;
2448
2474
  return F.def.onMail(email, subject, body, callback);
2449
2475
  };
2450
2476
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "total5",
3
- "version": "0.0.1-4",
3
+ "version": "0.0.1-5",
4
4
  "description": "Total.js framework v5",
5
5
  "main": "index.js",
6
6
  "directories": {
package/tms.js CHANGED
@@ -361,7 +361,7 @@ exports.unsubscribe = function(name, callback) {
361
361
  return false;
362
362
  };
363
363
 
364
- F.on('@tms', function() {
364
+ F.on('$tms', function() {
365
365
 
366
366
  var endpoint = F.config.$tmsurl;
367
367
  var is = Cache.url !== endpoint;