bonsaif 1.10.3

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/README.md ADDED
@@ -0,0 +1,201 @@
1
+ Eliminar publicacion
2
+ npm unpublish bonsaif@1.9.23
3
+
4
+
5
+ # [bonsaif.js](http://git.develsuit.com:6000/bonsaif/bonsaif-npm.git)
6
+
7
+ bonsaif t is a library to connect to bonsaif apis
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install bonsaif
13
+ ```
14
+
15
+ ## Examples
16
+
17
+ Here is the first one to get you started:
18
+
19
+ ```js
20
+
21
+ const bonsaif = require('bonsaif');
22
+ // utl,
23
+ const {utl} = require('bonsaif');
24
+
25
+ //ec
26
+ const {ec} = require('bonsaif');
27
+ const tag = "test";
28
+
29
+ // ./cnf/endpoint.js
30
+ const endpointMariaDB= {
31
+ uri: '',
32
+ user: '',
33
+ password: '',
34
+ client:'mariadb'
35
+ };
36
+
37
+ const localMariaDB= {
38
+ uri:'',
39
+ port: '',
40
+ user:'',
41
+ password:'',
42
+ local:true,
43
+ debug:false,
44
+ client:'mariadb'
45
+ };
46
+
47
+ // Execute query
48
+ const run =async()=>{
49
+ //localhost
50
+ let rs = await bonsaif.query({endpoint:localMariaDB, options:{db:'', sys:''}, query:'select * from table', tag});
51
+ //endpoint
52
+ let rs = await bonsaif.query({endpoint:endpointMariaDB, options:{db:'', sys:''}, query:'select * from table', tag});
53
+ while (rs.next()){
54
+ utl.log('row json',rs.row);
55
+ let x = rs.row;
56
+ utl.log('get field ['+x+']');
57
+ utl.log('get field ['+rs.get('column')+']');
58
+ utl.log('get field by Index ['+rs.get(0)+']');
59
+ }
60
+ }
61
+ run();
62
+ /**
63
+ * Execute mongodb
64
+ * https://www.mongodb.com/docs/manual/reference/command/
65
+ **/
66
+ const endpointMongo= {
67
+ uri: '',
68
+ user: '',
69
+ password: '',
70
+ client:'mongodb'
71
+ };
72
+
73
+ const localMongo= {
74
+ uri:'',
75
+ poolSize:8,
76
+ local:true,
77
+ debug:false,
78
+ client:'mongodb'
79
+ };
80
+ const runMongo =async()=>{
81
+
82
+ // localhost
83
+ let insert = await bonsaif.query({endpoint:localMongo, options:{db:'', sys:''}, query:{insert: "collection", documents: [{ 'id':1, 'ds':'demo1' }]}, tag});
84
+
85
+ //endpoint
86
+ let insert = await bonsaif.query({endpoint:endpointMongo, options:{db:'', sys:''}, query:{insert: "collection", documents: [{ 'id':1, 'ds':'demo1' }]}, tag});
87
+ let find = await bonsaif.query({endpoint:endpointMongo, options:{db:'', sys:''}, query:{find: "collection", filter: { 'id':1 }}, tag});
88
+ let update = await bonsaif.query({endpoint:endpointMongo, options:{db:'', sys:''}, query:{update: "collection", filter: { _id:1 } documents: [{ "id":1, "ds":"ds Change", "NewC":1 }]}, tag});
89
+ let upsert = await bonsaif.query({endpoint:endpointMongo, options:{db:'', sys:''}, query:{upsert: "collection", filter: { _id:1 }, document:{ 'id':1, 'ds':'ds1', 'live':0 } }, tag});
90
+ }
91
+
92
+ runMongo();
93
+
94
+
95
+ /**
96
+ * Execute redis
97
+ * https://redis.io/commands/?group=set
98
+ **/
99
+ const endpointRedis= {
100
+ uri: '',
101
+ user: '',
102
+ password: '',
103
+ client:'redis'
104
+ };
105
+
106
+ const localRedis= {
107
+ uri:'',
108
+ local:true,
109
+ debug:false,
110
+ client:'redis'
111
+ };
112
+
113
+ const runRedis =async()=>{
114
+ let redis;
115
+
116
+ // localhost
117
+ redis = await bonsaif.query({endpoint:localRedis, options:{db:'', sys:''} query:{set:"Key:Test", value:"123456"}, tag:'test'});
118
+ utl.log('set ',redis);
119
+
120
+ //endpoint
121
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{set:"Key:Test", value:"123456"}, tag:'test'});
122
+ utl.log('set ',redis);
123
+
124
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{set:"Key:Expire", value:"123456", expire:20}, tag:'test'});
125
+ utl.log('set expire ',redis);
126
+
127
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{get:"Key:Test"}, tag:'test'});
128
+ utl.log('get ',redis);
129
+
130
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{scan:"log*"}, tag:'test'});
131
+ utl.log('scan ',redis);
132
+
133
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{upsert:"log:test", value:{"id_":1, "ds":"ds", live:1, "child_id":2}, filter:{"id_":1}}, tag:'test'});
134
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{upsert:"log:test", value:{"id_":2, "ds":"ds2", live:1, "child_id":2}, filter:{"id_":2}}, tag:'test'});
135
+ utl.log('upsert (sadd) ',redis);
136
+
137
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{hfind:"log:test", filter:{"id_":"*"} }, tag:'test'});
138
+ utl.log('hfind (smembers) ',redis);
139
+
140
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{hfind:"log:test", filter:{"id_":"1"} }, tag:'test'});
141
+ utl.log('hfind (smembers) ',redis);
142
+
143
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{hfind:"log:test", filter:{$and:[{"id_":1},{"child_id":"2"}]},}, tag:'test'});
144
+ utl.log('hfind (smembers) ',redis);
145
+
146
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{hfind:"log:test", filter:{$or:[{"id_":1},{"child_id":"2"}]},}, tag:'test'});
147
+ utl.log('hfind (smembers) ',redis);
148
+
149
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{hfind:"log:test", filter:{"id_":{$in:[1,2]}}}, tag:'test'});
150
+ utl.log('in (smembers) ',redis);
151
+
152
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{set:"Key:Test:Del", value:"123456"}, tag:'test'});
153
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{del:"Key:Test:Del" }, tag:'test'});
154
+ utl.log('del ',redis);
155
+
156
+ //redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{del:"Total" }, tag:'test'});
157
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{incrby:"Total", value:1000, counter:1 }, tag:'test'});
158
+ utl.log('incrby ',redis);
159
+
160
+ //redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{del:"Total:Float" }, tag:'test'});
161
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{incrbyfloat:"Total:Float", value:1000.00, counter:-5.1 }, tag:'test'});
162
+ utl.log('TotalFloat ',redis);
163
+
164
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{sadd:"Member", "value":"1" }, tag:'test'});
165
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{sadd:"Member", "value":"2" }, tag:'test'});
166
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{sadd:"Member", "value":"3" }, tag:'test'});
167
+ utl.log('sadd ',redis);
168
+
169
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{smembers:"Member", "value":"2" }, tag:'test'});
170
+ utl.log('smembers ',redis);
171
+
172
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{srem:"Member", "value":"2" }, tag:'test'});
173
+ utl.log('srem ',redis);
174
+
175
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{hset:"hset", "value":{"id_cli":"1000","username":"1","password": "2", "A":"1" } }, tag:'test'});
176
+ utl.log('hset ',redis);
177
+
178
+ redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{hgetall:"hset"}, tag:'test'});
179
+ utl.log('hgetall ',redis);
180
+ }
181
+
182
+ runRedis();
183
+
184
+ utl.log('custom log '+utl.date()+' '+utl.hour());
185
+
186
+ /**
187
+ * Encript
188
+ **/
189
+
190
+ let key = ec.StringToHex('keyString');
191
+ utl.log('['+ec.fromHexString(key)+']');
192
+
193
+ let keyKP = ec.StringToHexKP('llave','keyStringKP');
194
+ utl.log('['+ec.fromHexStringKP('llave',keyKP)+']');
195
+
196
+
197
+ ```
198
+
199
+
200
+ ## License
201
+ [MIT](https://choosealicense.com/licenses/mit/)
package/index.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * ::: B[]NSAIF() ::: => 2022
3
+ */
4
+ 'use strict';
5
+
6
+ module.exports = require('./lib/bonsaif');
package/lib/bonsaif.js ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * ::: B[]NSAIF() ::: => 2022
3
+ */
4
+
5
+ 'use strict';
6
+
7
+ const utl = require('./utl');
8
+ const execute = require('./execute');
9
+ const ec = require('./ec');
10
+ const network = require('./network');
11
+
12
+ const query=(o)=>{
13
+ return execute.query(o);
14
+ }
15
+
16
+ const backend=(o)=>{
17
+ return execute.backend(o);
18
+ }
19
+
20
+ module.exports={
21
+ utl,
22
+ execute,
23
+ query,
24
+ backend,
25
+ ec,
26
+ network
27
+ }
package/lib/ec.js ADDED
@@ -0,0 +1,202 @@
1
+ /**
2
+ * ::: B[]NSAIF() ::: => 2022
3
+ */
4
+
5
+ 'use strict';
6
+
7
+ const Key = "bonsaif.key";
8
+
9
+ const WH = ["ff1", "ff2", "ff3", "ff4", "ff5", "ff6", "ff7", "ff8", "ff9", "ff",
10
+ "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c0",
11
+ "111", "222", "333", "444", "555", "666", "777", "888", "999", "000",
12
+ "1x", "2x", "3x", "4x", "5x", "6x", "7x", "8x", "9x", "0x"
13
+ //,"we","ue","aw","uf","6a","wa","v0"
14
+ ];
15
+ const WC = ["z", "y", "x", "w", "v", "u", "t", "s", "r", "q",
16
+ "p", "o", "n", "m", "l", "k", "j", "i", "h", "g",
17
+ "Z", "Y", "X", "W", "V", "U", "T", "S", "R", "Q",
18
+ "P", "O", "N", "M", "L", "K", "J", "I", "H", "G"
19
+ //,".",",",":",";","!","*","@"
20
+ ];
21
+
22
+
23
+ const StringToHex = (str) => {
24
+ let tag = "StringToHexW: ";
25
+ try{
26
+ let chars = Array.from(str.trim());
27
+ //logger.log(tag + 'chars', chars);
28
+ let c_key = Array.from(Key)
29
+ //logger.log(tag + 'c_key', c_key);
30
+ let iTkey = Key.length, ikey = 0, ichar = 0;
31
+
32
+ let dchar = 0.0, rchar = 0.0;//doubles
33
+ let strBuffer = "";
34
+ let Hex = "";
35
+
36
+ for (let i = 0; i < chars.length; i++) {
37
+ //ichar = ((int) chars[i] + (int) c_key[ikey]);
38
+ ichar = chars[i].charCodeAt(0) + c_key[ikey].charCodeAt(0);
39
+ dchar = Math.floor(ichar / 2);
40
+ rchar = ichar % 2;
41
+ if (ikey >= iTkey - 1) {
42
+ ikey = 0;
43
+ } else {
44
+ ikey = ikey + 1;
45
+ }
46
+ //Hex = Integer.toHexString((int) dchar);
47
+ let intChar = Math.trunc(dchar);
48
+ Hex = intChar.toString(16);
49
+ if (Hex.length == 1) {
50
+ Hex = "0" + Hex;
51
+ }
52
+ if (rchar > 0) {
53
+ //strBuffer.append("ff");
54
+ strBuffer += "ff";
55
+ }
56
+
57
+ //strBuffer.append(Hex);
58
+ strBuffer += Hex;
59
+ }
60
+ return compress(strBuffer);
61
+ }catch(e){
62
+ return "err"+e;
63
+ }
64
+ }
65
+
66
+ const fromHexString = (hex) => {
67
+ let tag = "fromHexString: ";
68
+ try{
69
+ hex = uncompress(hex);
70
+ let str = "";
71
+ let c_key = Array.from(Key);
72
+ let iTkey = Key.length, ikey = 0, ichar = 0;
73
+ let iV = 0;
74
+ for (let i = 0; i < hex.length; i += 2) {
75
+ if (hex.substring(i, i + 2) == "ff" || hex.substring(i, i + 2) == "FF" || hex.substring(i, i + 2) == "fF" || hex.substring(i, i + 2) == "Ff") {
76
+ iV = 1;
77
+ } else {
78
+ ichar = parseInt(parseInt(hex.substring(i, i + 2), 16), 10);
79
+ ichar = (ichar * 2) - c_key[ikey].charCodeAt(0);
80
+ ichar = ichar + iV;
81
+ //let caracter = String.fromCharCode(ichar).toString();
82
+ //logger.log(tag + 'caracter ' + caracter);
83
+ str += String.fromCharCode(ichar)
84
+ if (ikey >= iTkey - 1) {
85
+ ikey = 0;
86
+ } else {
87
+ ikey = ikey + 1;
88
+ }
89
+ iV = 0;
90
+ }
91
+ }
92
+ return str;
93
+ }catch(e){
94
+ return "err"+e;
95
+ }
96
+ }
97
+
98
+ const compress = (str) =>{
99
+ try{
100
+ let compress = str;
101
+ for (let w = 0; w < WH.length; w++) {
102
+ let replacer = new RegExp(WH[w], 'g')
103
+ compress = compress.replace(replacer, WC[w]);
104
+ }
105
+ return compress.trim();
106
+ }catch(e){
107
+ return "err"+e;
108
+ }
109
+ }
110
+
111
+ const uncompress = (str) => {
112
+ try{
113
+ let uncompress = str;
114
+ for (let w = WH.length - 1; w >= 0; w--) {
115
+ let replacer = new RegExp(WC[w], 'g')
116
+ uncompress = uncompress.replace(replacer, WH[w]);
117
+ }
118
+ return uncompress.trim();
119
+ }catch(e){
120
+ return "err"+e;
121
+ }
122
+ }
123
+
124
+ const StringToHexKP = (K, str) => {
125
+ let tag = "StringToHexKP: ";
126
+ try{
127
+ let chars = Array.from(str);
128
+ //logger.log(tag + 'chars', chars);
129
+ let c_key = Array.from(K)
130
+ //logger.log(tag + 'c_key', c_key);
131
+ let iTkey = K.length, ikey = 0, ichar = 0;
132
+
133
+ let dchar = 0.0, rchar = 0.0;//doubles
134
+ let strBuffer = "";
135
+ let Hex = "";
136
+
137
+ for (let i = 0; i < chars.length; i++) {
138
+ //ichar = ((int) chars[i] + (int) c_key[ikey]);
139
+ ichar = chars[i].charCodeAt(0) + c_key[ikey].charCodeAt(0);
140
+ dchar = Math.floor(ichar / 2);
141
+ rchar = ichar % 2;
142
+ if (ikey >= iTkey - 1) {
143
+ ikey = 0;
144
+ } else {
145
+ ikey = ikey + 1;
146
+ }
147
+ //Hex = Integer.toHexString((int) dchar);
148
+ let intChar = Math.trunc(dchar);
149
+ Hex = intChar.toString(16);
150
+ if (Hex.length == 1) {
151
+ Hex = "0" + Hex;
152
+ }
153
+ if (rchar > 0) {
154
+ //strBuffer.append("ff");
155
+ strBuffer += "ff";
156
+ }
157
+ //strBuffer.append(Hex);
158
+ strBuffer += Hex;
159
+ }
160
+ return compress(strBuffer);
161
+ }catch(e){
162
+ return "err"+e;
163
+ }
164
+ }
165
+
166
+ const fromHexStringKP = (K, hex) => {
167
+ try{
168
+ hex = uncompress(hex);
169
+ let str = '';
170
+
171
+ let c_key = Array.from(K);
172
+ let iTkey = K.length, ikey = 0, ichar = 0;
173
+
174
+ let iV = 0;
175
+ for (let i = 0; i < hex.length; i += 2) {
176
+ if (hex.substring(i, i + 2) == "ff" || hex.substring(i, i + 2) == "FF" || hex.substring(i, i + 2) == "fF" || hex.substring(i, i + 2) == "Ff") {
177
+ iV = 1;
178
+ } else {
179
+ ichar = parseInt(parseInt(hex.substring(i, i + 2), 16), 10);
180
+ ichar = (ichar * 2) - c_key[ikey].charCodeAt(0);
181
+ ichar = ichar + iV;
182
+ str += String.fromCharCode(ichar)
183
+ if (ikey >= iTkey - 1) {
184
+ ikey = 0;
185
+ } else {
186
+ ikey = ikey + 1;
187
+ }
188
+ iV = 0;
189
+ }
190
+ }
191
+ return str;
192
+ }catch(e){
193
+ return "err"+e;
194
+ }
195
+ }
196
+
197
+ module.exports = {
198
+ StringToHex,
199
+ fromHexString,
200
+ StringToHexKP,
201
+ fromHexStringKP
202
+ };