@bee.js/node 0.0.28 → 0.0.32

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.
@@ -1,14 +1,14 @@
1
- const script = {} //TODO require("../scripts")
2
-
3
- module.exports = async (task, services) => {
4
- let params = task.params
5
- let data = await script[params.script](params)
6
-
7
- if(task.console === 2) {
8
- console.log(`# Script ${params.script} data result:`)
9
- console.log(data)
10
- }
11
-
12
- if(data && params && params.callback)
13
- await services[params.callback.service]({...params.callback, params: {...params.callback.params, data: data } }, services)
1
+ const script = {} //TODO require("../scripts")
2
+
3
+ module.exports = async (task, services) => {
4
+ let params = task.params
5
+ let data = await script[params.script](params)
6
+
7
+ if(task.console === 2) {
8
+ console.log(`# Script ${params.script} data result:`)
9
+ console.log(data)
10
+ }
11
+
12
+ if(data && params && params.callback)
13
+ await services[params.callback.service]({...params.callback, params: {...params.callback.params, data: data } }, services)
14
14
  }
package/services/SHELL.js CHANGED
@@ -1,3 +1,3 @@
1
- module.exports = (params)=> {
2
- //TODO
1
+ module.exports = (params)=> {
2
+ //TODO
3
3
  }
package/services/index.js CHANGED
@@ -1,10 +1,10 @@
1
- module.exports = {
2
- CRON: require('./CRON'),
3
- LOGS: require('./LOGS'),
4
- HTTP: require('./HTTP'),
5
- HTTPS: require('./HTTPS'),
6
- SHELL: require('./SHELL'),
7
- EMAIL: require('./EMAIL'),
8
- SCRIPT: require('./SCRIPT'),
9
- TIME: ()=> new Date().toISOString(),
1
+ module.exports = {
2
+ CRON: require('./CRON'),
3
+ LOGS: require('./LOGS'),
4
+ HTTP: require('./HTTP'),
5
+ HTTPS: require('./HTTPS'),
6
+ SHELL: require('./SHELL'),
7
+ EMAIL: require('./EMAIL'),
8
+ SCRIPT: require('./SCRIPT'),
9
+ TIME: ()=> new Date().toISOString(),
10
10
  }
package/tools/beeTools.js CHANGED
@@ -1,19 +1,19 @@
1
- module.exports = {
2
- ...require("./hash"),
3
- ...require("./guid"),
4
- ...require("./slug"),
5
- ...require("./string"),
6
- ...require("./model"),
7
-
8
- captcha: function() {
9
- //TODO
10
- },
11
-
12
- zip: function() {
13
- //TODO
14
- },
15
-
16
- console: {
17
- log: (message, error)=> console.log(`# ${(new Date().toISOString()) + (error ? ' ERROR' : '')}: ${message}`)
18
- }
1
+ module.exports = {
2
+ ...require("./hash"),
3
+ ...require("./guid"),
4
+ ...require("./slug"),
5
+ ...require("./string"),
6
+ ...require("./model"),
7
+
8
+ captcha: function() {
9
+ //TODO
10
+ },
11
+
12
+ zip: function() {
13
+ //TODO
14
+ },
15
+
16
+ console: {
17
+ log: (message, error)=> console.log(`# ${(new Date().toISOString()) + (error ? ' ERROR' : '')}: ${message}`)
18
+ }
19
19
  }
package/tools/guid.js CHANGED
@@ -1,15 +1,15 @@
1
- const uuid = require('uuid')
2
-
3
- module.exports = {
4
- guid: function(fn, param) {
5
- return fn
6
- ? uuid[fn](param)
7
- : uuid.v4()
8
- },
9
-
10
- guidToBin: function(param) {
11
- return typeof(param) == "string" && param.length == 36 //&& uuid.validate(param)
12
- ? "0x" + param.replace(/-/g,'')
13
- : param
14
- },
1
+ const uuid = require('uuid')
2
+
3
+ module.exports = {
4
+ guid: function(fn, param) {
5
+ return fn
6
+ ? uuid[fn](param)
7
+ : uuid.v4()
8
+ },
9
+
10
+ guidToBin: function(param) {
11
+ return typeof(param) == "string" && param.length == 36 //&& uuid.validate(param)
12
+ ? "0x" + param.replace(/-/g,'')
13
+ : param
14
+ },
15
15
  }
package/tools/hash.js CHANGED
@@ -1,13 +1,13 @@
1
- const crypto = require('crypto')
2
-
3
- module.exports = {
4
- md5: function(param = "") {
5
- return param
6
- ? crypto.createHash('md5').update(param).digest('hex')
7
- : "";
8
- },
9
-
10
- sha256: function() {
11
-
12
- },
1
+ const crypto = require('crypto')
2
+
3
+ module.exports = {
4
+ md5: function(param = "") {
5
+ return param
6
+ ? crypto.createHash('md5').update(param).digest('hex')
7
+ : "";
8
+ },
9
+
10
+ sha256: function() {
11
+
12
+ },
13
13
  }
package/tools/model.js CHANGED
@@ -1,21 +1,21 @@
1
- const tools = require('./beeTools')
2
-
3
- module.exports = {
4
- validDataModel: function(req, model, data) {
5
- let schema = configs.models[model].schema
6
- let onlyFields = req.onlyFields[model] || []
7
-
8
- data = data || req.body
9
-
10
- for([field, props] of Object.entries(schema)) {
11
- if(onlyFields.length && !onlyFields.includes(field)) continue
12
-
13
- // data required
14
- if(!props.null && ["", undefined].includes(data[field])) return { error: true, message: `'${field}' cannot be null` }
15
-
16
- // TODO validar tamanho de dados e tipo de dados (numeric, email)
17
- }
18
-
19
- return true
20
- },
1
+ const tools = require('./beeTools')
2
+
3
+ module.exports = {
4
+ validDataModel: function(req, model, data) {
5
+ let schema = configs.models[model].schema
6
+ let onlyFields = req.onlyFields[model] || []
7
+
8
+ data = data || req.body
9
+
10
+ for([field, props] of Object.entries(schema)) {
11
+ if(onlyFields.length && !onlyFields.includes(field)) continue
12
+
13
+ // data required
14
+ if(!props.null && ["", undefined].includes(data[field])) return { error: true, message: `'${field}' cannot be null` }
15
+
16
+ // TODO validar tamanho de dados e tipo de dados (numeric, email)
17
+ }
18
+
19
+ return true
20
+ },
21
21
  }
package/tools/slug.js CHANGED
@@ -1,17 +1,17 @@
1
- module.exports = {
2
- toSlug: function(string) {
3
- return string
4
- .toLowerCase()
5
- .normalize('NFD')
6
- .replace(/[^\w ]+/g,'')
7
- .replace(/ +/g,'-')
8
- },
9
-
10
- firstSlug: function(slug = "") {
11
- return ((param = slug.split("-"))=>param[0])()
12
- },
13
-
14
- lastSlug: function(slug = "") {
15
- return ((param = slug.split("-"))=>param[param.length-1])()
16
- },
1
+ module.exports = {
2
+ toSlug: function(string) {
3
+ return string
4
+ .toLowerCase()
5
+ .normalize('NFD')
6
+ .replace(/[^\w ]+/g,'')
7
+ .replace(/ +/g,'-')
8
+ },
9
+
10
+ firstSlug: function(slug = "") {
11
+ return ((param = slug.split("-"))=>param[0])()
12
+ },
13
+
14
+ lastSlug: function(slug = "") {
15
+ return ((param = slug.split("-"))=>param[param.length-1])()
16
+ },
17
17
  }
package/tools/string.js CHANGED
@@ -1,56 +1,56 @@
1
- module.exports = {
2
- onlyNumbers: function(string = "") {
3
- return string.replace(/\D/g, "")
4
- },
5
-
6
- onlyLetters: function(string = "") {
7
- return string.replace(/[^a-zA-Z]+/g, '')
8
- },
9
-
10
- sqlEscape: function(string = "") {
11
- return string.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function (char) {
12
- switch (char) {
13
- case "\0":
14
- return "\\0";
15
- case "\x08":
16
- return "\\b";
17
- case "\x09":
18
- return "\\t";
19
- case "\x1a":
20
- return "\\z";
21
- case "\n":
22
- return "\\n";
23
- case "\r":
24
- return "\\r";
25
- case "\"":
26
- case "'":
27
- case "\\":
28
- case "%":
29
- return "\\"+char;
30
- default:
31
- return char;
32
- }
33
- });
34
- },
35
-
36
- randomString: function(length = 45, characters = null) {
37
- characters = characters || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
38
-
39
- let result = '';
40
- let charactersLength = characters.length;
41
-
42
- for(let i = 0; i < length; i++)
43
- result += characters.charAt(Math.floor(Math.random() * charactersLength));
44
-
45
- return result;
46
- },
47
-
48
- isStrongPassword: function(password = "") {
49
- return password.match(/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,20}$/)
50
- },
51
-
52
- isEmail: function(email = "") {
53
- const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
54
- return re.test(String(email).toLowerCase());
55
- }
1
+ module.exports = {
2
+ onlyNumbers: function(string = "") {
3
+ return string.replace(/\D/g, "")
4
+ },
5
+
6
+ onlyLetters: function(string = "") {
7
+ return string.replace(/[^a-zA-Z]+/g, '')
8
+ },
9
+
10
+ sqlEscape: function(string = "") {
11
+ return string.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function (char) {
12
+ switch (char) {
13
+ case "\0":
14
+ return "\\0";
15
+ case "\x08":
16
+ return "\\b";
17
+ case "\x09":
18
+ return "\\t";
19
+ case "\x1a":
20
+ return "\\z";
21
+ case "\n":
22
+ return "\\n";
23
+ case "\r":
24
+ return "\\r";
25
+ case "\"":
26
+ case "'":
27
+ case "\\":
28
+ case "%":
29
+ return "\\"+char;
30
+ default:
31
+ return char;
32
+ }
33
+ });
34
+ },
35
+
36
+ randomString: function(length = 45, characters = null) {
37
+ characters = characters || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
38
+
39
+ let result = '';
40
+ let charactersLength = characters.length;
41
+
42
+ for(let i = 0; i < length; i++)
43
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
44
+
45
+ return result;
46
+ },
47
+
48
+ isStrongPassword: function(password = "") {
49
+ return password.match(/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,20}$/)
50
+ },
51
+
52
+ isEmail: function(email = "") {
53
+ const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
54
+ return re.test(String(email).toLowerCase());
55
+ }
56
56
  }