molly-db 1.3.1 → 1.3.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.
@@ -5,13 +5,29 @@ const output = new Object();
5
5
 
6
6
  /*--────────────────────────────────────────────────────────────────────────────────────────────--*/
7
7
 
8
- module.exports = function( data,db ){
9
- return new Promise((response,reject)=>{
10
- utils.validator( db,data ).then(()=>{
11
- try { response(Array.isArray(data) ? data.map(x=>utils[x.type](x,db)) :
12
- utils[data.type](data,db))
13
- } catch(e) { response(JSON.stringify({ status:404, message:`error: ${e.message}` })) }
14
- }).catch(e=>{ reject(JSON.stringify(e)) });
8
+ function copy( A,B ){
9
+ const result = new Object();
10
+ Object.keys(A).map(x=>result[x] = A[x]);
11
+ Object.keys(B).map(x=>result[x] = B[x]);
12
+ return result;
13
+ }
14
+
15
+ /*--────────────────────────────────────────────────────────────────────────────────────────────--*/
16
+
17
+ module.exports = function( data,inst,db ){
18
+ return new Promise(async(response,reject)=>{
19
+ const input = Array.isArray(inst) ? inst : [inst];
20
+ const result = new Array();
21
+
22
+ for( var i in input ){
23
+ const cfg = copy(data,input[i]); try {
24
+ const bool = await utils.validator(db,cfg);
25
+ if( bool ) result.push(utils[cfg.type](cfg,db));
26
+ else return reject({ status:404, message:`error` })
27
+ } catch(e) {
28
+ return reject({ status:404, message:`error: ${e.message}` })
29
+ }
30
+ } return response( result );
15
31
  })
16
32
  };
17
33
 
package/module/utils.js CHANGED
@@ -23,16 +23,16 @@ output.validator = function( db, params ){
23
23
  validator = [
24
24
  [!params?.db, {status:404,message:'error: no db name added'}],
25
25
  [!params?.table, {status:404,message:'error: no table name added'}]
26
- ].some(x=>{ if(x[0]) reject(x[1]); return x[0];}); if(validator) return 0;
26
+ ].some(x=>{ if(x[0]) response(0); /*reject(x[1])*/ return x[0];}); if(validator) return 0;
27
27
 
28
28
  if( !(/table|db|all/gi).test(params.type) ){
29
29
  validator = [
30
30
  [!vdb(params?.db), {status:404,message:`erorr: no db called ${params.db} exist`}],
31
31
  [!vtb(params?.table), {status:404,message:`error: no table called ${params.table} exist`}]
32
- ].some(x=>{ if(x[0]) reject(x[1]); return x[0];}); if(validator) return 0;
32
+ ].some(x=>{ if(x[0]) response(0); /*reject(x[1])*/ return x[0];}); if(validator) return 0;
33
33
  }
34
34
 
35
- response();
35
+ response(1); //response();
36
36
  });
37
37
  }
38
38
 
@@ -25,15 +25,6 @@ function saveTimeout(data,db){
25
25
 
26
26
  /*--────────────────────────────────────────────────────────────────────────────────────────────--*/
27
27
 
28
- function copy( A,B ){
29
- const result = new Object();
30
- Object.keys(A).map(x=>result[x] = A[x]);
31
- Object.keys(B).map(x=>result[x] = B[x]);
32
- return result;
33
- }
34
-
35
- /*--────────────────────────────────────────────────────────────────────────────────────────────--*/
36
-
37
28
  module.exports = (args)=>{
38
29
  init( args ).then((db)=>{ saveTimeout( args, db );
39
30
  const dir = path.join(__dirname,'server_worker.js');
@@ -43,8 +34,7 @@ module.exports = (args)=>{
43
34
  const error = '{ "status":"404", "message":"error data" }';
44
35
  try {
45
36
  const raw = Buffer.from(msg).toString();
46
- const data = copy( args,JSON.parse(raw) );
47
- memory(data,db).then(x=>{
37
+ memory(args,JSON.parse(raw),db).then(x=>{
48
38
  const out = JSON.stringify(x); srv.postMessage(out||empty);
49
39
  }).catch(e=>{
50
40
  const out = JSON.stringify(e); srv.postMessage(out||empty);
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "license": "MIT",
12
12
  "main": "main.js",
13
13
  "name": "molly-db",
14
- "version": "1.3.1",
14
+ "version": "1.3.2",
15
15
  "author": "bececrazy",
16
16
  "description": "Molly-db is a free and open source library for nodejs that allow you create a lightweight encrypted database using Json files",
17
17
  "keywords": [