total5 0.0.3 → 0.0.4-2

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
@@ -111,6 +111,29 @@ Options.prototype.action = function(schema, payload) {
111
111
  return F.action(schema, payload, this.controller);
112
112
  };
113
113
 
114
+ Options.prototype.promisify = function(fn, a, b, c) {
115
+ var $ = this;
116
+ return new Promise(function(resolve) {
117
+
118
+ var callback = function(err, response) {
119
+ if (err)
120
+ $.invalid(err);
121
+ else
122
+ resolve(response);
123
+ };
124
+
125
+ if (c !== undefined)
126
+ fn(a, b, c, callback);
127
+ else if (b !== undefined)
128
+ fn(a, b, callback);
129
+ else if (a !== undefined)
130
+ fn(a, callback);
131
+ else
132
+ fn(callback);
133
+
134
+ });
135
+ };
136
+
114
137
  Options.prototype.publish = function(value) {
115
138
  var self = this;
116
139
  var name = self.id;
@@ -233,11 +256,15 @@ Options.prototype.output = function(name) {
233
256
  return self;
234
257
  };
235
258
 
259
+ function $errorhandling(self) {
260
+ self.$callback(true);
261
+ }
262
+
236
263
  Options.prototype.invalid = function(error, path, index) {
237
264
  var self = this;
238
265
  self.error.push(error, path, index);
239
- self.$callback(true);
240
- return self;
266
+ setTimeout($errorhandling, 1, self);
267
+ return self.error;
241
268
  };
242
269
 
243
270
  Options.prototype.cookie = function(name, value, expire, options) {
@@ -1362,7 +1389,16 @@ ActionCaller.prototype.finish = function(value) {
1362
1389
  var self = this;
1363
1390
  self.finish = null;
1364
1391
  if (self.options.callback) {
1365
- self.options.callback(self.error.length ? self.error : null, value === undefined ? self.$.response : value);
1392
+
1393
+ if (self.options.callback instanceof Options) {
1394
+ let $ = self.options.callback;
1395
+ if (self.error.length)
1396
+ $.invalid(self.error);
1397
+ else
1398
+ $.callback(value === undefined ? self.$.response : value);
1399
+ } else
1400
+ self.options.callback(self.error.length ? self.error : null, value === undefined ? self.$.response : value);
1401
+
1366
1402
  self.options.callback = null;
1367
1403
  }
1368
1404
  };
package/changelog.txt CHANGED
@@ -1,3 +1,17 @@
1
+ ========================
2
+ 0.0.4
3
+ ========================
4
+
5
+ - improved `Number.pluralize()` method
6
+ - added `PROMISIFY(fn, [a], [b])` method
7
+ - added `$.promisify(fn, [a], [b])` method
8
+ - added `FILESTORAGE().copy(id, path, [callback(err, meta)])`
9
+ - fixed formatting `0` number in the `Tangular.format` helper
10
+ - improved `$.invalid()` method, now it returns `ErrorBuilder`
11
+ - improved `$.callback()`, it accepts another instance of `$`
12
+ - improved `DATA.query()` method
13
+ - fixed removing existing CRONs by [Marek Mraz](https://github.com/Mrazbb)
14
+
1
15
  ========================
2
16
  0.0.3
3
17
  ========================
package/controller.js CHANGED
@@ -319,6 +319,22 @@ Controller.prototype.empty = function() {
319
319
  F.stats.response.empty++;
320
320
  };
321
321
 
322
+ function $errorhandling(ctrl, err) {
323
+
324
+ var response = ctrl.response;
325
+ response.headers['content-type'] = 'application/json';
326
+ response.headers['cache-control'] = NOCACHE;
327
+ response.headers.vary = 'Accept-Encoding, Last-Modified, User-Agent';
328
+ response.value = JSON.stringify(err.output(ctrl.language));
329
+ response.status = err.status === 408 ? 503 : err.status;
330
+ ctrl.flush();
331
+
332
+ var key = 'error' + err.status;
333
+
334
+ if (F.stats.response[key] != null)
335
+ F.stats.response[key]++;
336
+ }
337
+
322
338
  Controller.prototype.invalid = function(value) {
323
339
 
324
340
  var ctrl = this;
@@ -326,7 +342,6 @@ Controller.prototype.invalid = function(value) {
326
342
  if (ctrl.destroyed)
327
343
  return;
328
344
 
329
- var response = ctrl.response;
330
345
  var err;
331
346
 
332
347
  if (value instanceof F.TBuilders.ErrorBuilder) {
@@ -336,17 +351,7 @@ Controller.prototype.invalid = function(value) {
336
351
  err.push(value);
337
352
  }
338
353
 
339
- response.headers['content-type'] = 'application/json';
340
- response.headers['cache-control'] = NOCACHE;
341
- response.headers.vary = 'Accept-Encoding, Last-Modified, User-Agent';
342
- response.value = JSON.stringify(err.output(ctrl.language));
343
- response.status = err.status === 408 ? 503 : err.status;
344
- ctrl.flush();
345
-
346
- var key = 'error' + err.status;
347
-
348
- if (F.stats.response[key] != null)
349
- F.stats.response[key]++;
354
+ setTimeout($errorhandling, 1, ctrl, err);
350
355
  };
351
356
 
352
357
  Controller.prototype.flush = function() {
package/filestorage.js CHANGED
@@ -373,6 +373,84 @@ FP._read = function(id, callback, nostream) {
373
373
  return self;
374
374
  };
375
375
 
376
+ FP.copy = function(id, path, callback) {
377
+ var self = this;
378
+ if (callback)
379
+ return self._copy(id, path, callback);
380
+ else
381
+ return new Promise((resolve, reject) => self._copy(id, path, (err, res) => err ? reject(err) : resolve(res)));
382
+ };
383
+
384
+ FP._copy = function(id, path, callback) {
385
+
386
+ var self = this;
387
+
388
+ if (self.pause) {
389
+ setTimeout(self._copy, 500, id, path, callback);
390
+ return self;
391
+ }
392
+
393
+ var filename = Path.join(self.makedirectory(id), id + '.file');
394
+
395
+ F.stats.performance.open++;
396
+ Fs.open(filename, 'r', function(err, fd) {
397
+
398
+ if (err) {
399
+ callback(err);
400
+ return;
401
+ }
402
+
403
+ var buffer = Buffer.alloc(HEADERSIZE);
404
+ Fs.read(fd, buffer, 0, HEADERSIZE, 0, function(err) {
405
+
406
+ if (err) {
407
+ Fs.close(fd, NOOP);
408
+ callback(err);
409
+ return;
410
+ }
411
+
412
+ var str = buffer.toString('utf8').replace(REGCLEAN, '');
413
+ if (!str) {
414
+ // Invalid file
415
+ Fs.close(fd, function() {
416
+ if (buffer.length === HEADERSIZE)
417
+ Fs.unlink(filename, NOOP);
418
+ });
419
+ callback('File not found');
420
+ return;
421
+ }
422
+
423
+ var meta = str.parseJSON(true);
424
+ if (!meta) {
425
+ Fs.close(fd, NOOP);
426
+ callback('Invalid file');
427
+ return;
428
+ }
429
+
430
+ meta.id = id;
431
+
432
+ if (meta.expire && meta.expire < NOW) {
433
+ Fs.close(fd, NOOP);
434
+ callback('File is expired');
435
+ return;
436
+ }
437
+
438
+ F.stats.performance.open++;
439
+
440
+ var reader = Fs.createReadStream(filename, { fd: fd, start: HEADERSIZE });
441
+ var writer = Fs.createWriteStream(path.includes('.') ? path : Path.join(path, meta.name));
442
+
443
+ reader.pipe(writer);
444
+
445
+ CLEANUP(reader, function() {
446
+ callback(err, meta);
447
+ Fs.close(fd, NOOP);
448
+ });
449
+
450
+ });
451
+ });
452
+ };
453
+
376
454
  FP.readbuffer = function(id, callback) {
377
455
  var self = this;
378
456
  if (callback)
package/global.js CHANGED
@@ -64,6 +64,27 @@ global.ErrorBuilder = F.TBuilders.ErrorBuilder;
64
64
  global.DOWNLOAD = F.download;
65
65
  global.OPENCLIENT = (url, id) => require('./openclient').create(url, id);
66
66
  global.NEWMACRO = (str, nocompile, isasync) => require('./macros').compile(str, nocompile, isasync);
67
+ global.PROMISIFY = function(fn, a, b, c) {
68
+ return new Promise(function(resolve, reject) {
69
+
70
+ var callback = function(err, response) {
71
+ if (err)
72
+ reject(err);
73
+ else
74
+ resolve(response);
75
+ };
76
+
77
+ if (c !== undefined)
78
+ fn(a, b, c, callback);
79
+ else if (b !== undefined)
80
+ fn(a, b, callback);
81
+ else if (a !== undefined)
82
+ fn(a, callback);
83
+ else
84
+ fn(callback);
85
+
86
+ });
87
+ };
67
88
 
68
89
  global.BLOCKED = function($, limit, expire) {
69
90
 
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 = 5003;
39
+ F.is5 = F.version = 5004;
40
40
  F.isBundle = false;
41
41
  F.isLoaded = false;
42
42
  F.version_header = '5';
@@ -1664,7 +1664,7 @@ F.cron = function(line, fn) {
1664
1664
  obj.remove = function() {
1665
1665
  let index = F.crons.indexOf(this);
1666
1666
  if (index !== -1)
1667
- F.crons.splice(index, 0);
1667
+ F.crons.splice(index, 1);
1668
1668
  };
1669
1669
  F.crons.push(obj);
1670
1670
  return obj;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "total5",
3
- "version": "0.0.3",
3
+ "version": "0.0.4-2",
4
4
  "description": "Total.js framework v5",
5
5
  "main": "index.js",
6
6
  "directories": {
package/querybuilder.js CHANGED
@@ -335,7 +335,8 @@ CTP.remove = CTP.rem = function(table) {
335
335
 
336
336
  CTP.query = function(table, query, params) {
337
337
 
338
- if (query == null) {
338
+ if (query == null || typeof(query) === 'object') {
339
+ params = query;
339
340
  query = table;
340
341
  table = 'default/';
341
342
  } else
package/tangular.js CHANGED
@@ -402,7 +402,7 @@
402
402
  };
403
403
 
404
404
  Thelpers.pluralize = function(r,e,t,a,n){ return r||(r=0),'number'!=typeof r&&(r=parseFloat(r.toString().replace(/\s/g,'').replace(',','.'))),r.pluralize(e,t,a,n)};
405
- Thelpers.format=function(r,e,t,a){var n=typeof r;if(r==0||r==null)return'';if('number'===n||r instanceof Date)return r.format(e==null?null:e,t,a);'string'!==n&&(r=r.toString()),r=r.trim();for(var i=!1,o=0,f=0,u=0,l=r.length;l>u;u++){var g=r.charCodeAt(u);if(58===g||32===g||84===g){i=!0;break;}if(45===g){if(o++,1===o)continue;i=!0;break;}if(46===g){if(f++,1===f)continue;i=!0;break;}}return i?r.parseDate().format(e||'dd.MM.yyyy'):r.parseFloat().format(e,t,a)};
405
+ Thelpers.format=function(r,e,t,a){var n=typeof r;if(r==null)return'';if('number'===n||r instanceof Date)return r.format(e==null?null:e,t,a);'string'!==n&&(r=r.toString()),r=r.trim();for(var i=!1,o=0,f=0,u=0,l=r.length;l>u;u++){var g=r.charCodeAt(u);if(58===g||32===g||84===g){i=!0;break;}if(45===g){if(o++,1===o)continue;i=!0;break;}if(46===g){if(f++,1===f)continue;i=!0;break;}}return i?r.parseDate().format(e||'dd.MM.yyyy'):r.parseFloat().format(e,t,a)};
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
 
package/utils.js CHANGED
@@ -4256,6 +4256,16 @@ NP.pluralize = function(zero, one, few, other) {
4256
4256
  var num = this;
4257
4257
  var value = '';
4258
4258
 
4259
+ if (!one && typeof(zero) === 'string') {
4260
+ zero = zero.split(',');
4261
+ if (zero instanceof Array) {
4262
+ one = zero[1];
4263
+ few = zero[2];
4264
+ other = zero[3];
4265
+ zero = zero[0];
4266
+ }
4267
+ }
4268
+
4259
4269
  if (num == 0)
4260
4270
  value = zero || '';
4261
4271
  else if (num == 1)