molly-db 1.0.16 → 1.0.20
Sign up to get free protection for your applications and to get access to all the features.
- package/main.js +4 -25
- package/module/_init_.js +1 -3
- package/module/_worker_.js +23 -8
- package/package.json +4 -4
package/main.js
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
const worker = require('worker_threads');
|
2
|
-
const fetch = require('axios');
|
3
2
|
const url = require('url');
|
4
3
|
const fs = require('fs');
|
5
4
|
|
@@ -15,32 +14,12 @@ function config( _config ) {
|
|
15
14
|
|
16
15
|
/* --------------------------------------------------------------------------------------- */
|
17
16
|
|
18
|
-
function startWorker(_path,_self){
|
19
|
-
return new Promise((response,reject)=>{
|
20
|
-
const wrk = new worker.Worker(
|
21
|
-
_path,{ workerData:_self,
|
22
|
-
env: worker.SHARE_ENV,
|
23
|
-
}); wrk.on('exit',(err)=>{ console.log(err);
|
24
|
-
response(startWorker(_path,_self));
|
25
|
-
}); wrk.on('message',(msg)=>{
|
26
|
-
console.log(msg); response(msg)
|
27
|
-
});
|
28
|
-
});
|
29
|
-
}
|
30
|
-
|
31
|
-
/* --------------------------------------------------------------------------------------- */
|
32
|
-
|
33
17
|
class molly_db{
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
this.port = opt.port || 27017;
|
39
|
-
this.path = opt.path.replace(/^\./,process.cwd());
|
40
|
-
this.workerPath = `${__dirname}/module/_worker_.js`;
|
41
|
-
return startWorker( this.workerPath,this );
|
18
|
+
constructor( opt ){ if( opt.pass )
|
19
|
+
this.pass = opt.pass; this.port = opt.port || 27017;
|
20
|
+
this.path = opt.path.replace( /^\./,process.cwd() );
|
21
|
+
return require(`${__dirname}/module/_worker_.js`)(this);
|
42
22
|
}
|
43
|
-
|
44
23
|
}
|
45
24
|
|
46
25
|
/* --------------------------------------------------------------------------------------- */
|
package/module/_init_.js
CHANGED
@@ -6,9 +6,7 @@ function fillDB( _db, _table, _path ){
|
|
6
6
|
|
7
7
|
if( (/^http/).test(_path) ){ try{
|
8
8
|
const stream = await fetch.get(_path,{responseType:'stream'});
|
9
|
-
_itr = readline.createInterface({
|
10
|
-
input: stream.data
|
11
|
-
})
|
9
|
+
_itr = readline.createInterface({ input: stream })
|
12
10
|
} catch(e) { console.log(`error reading ${_path}`); return response(); }}
|
13
11
|
|
14
12
|
else if( fs.existsSync(_path) )
|
package/module/_worker_.js
CHANGED
@@ -2,13 +2,17 @@ const worker = require('worker_threads');
|
|
2
2
|
const readline = require('readline');
|
3
3
|
const crypto = require('./_crypto_');
|
4
4
|
const { Buffer } = require('buffer');
|
5
|
-
const fetch = require('
|
5
|
+
const fetch = require('molly-fetch');
|
6
|
+
const cluster = require('cluster');
|
6
7
|
const http = require('http');
|
7
8
|
const url = require('url');
|
8
9
|
const fs = require('fs');
|
9
10
|
|
10
|
-
|
11
|
+
/* --------------------------------------------------------------------------------------- */
|
12
|
+
|
13
|
+
let query;
|
11
14
|
const db = new Object();
|
15
|
+
|
12
16
|
/* --------------------------------------------------------------------------------------- */
|
13
17
|
|
14
18
|
function _init_(){
|
@@ -25,11 +29,22 @@ function app(req,res){
|
|
25
29
|
|
26
30
|
/* --------------------------------------------------------------------------------------- */
|
27
31
|
|
28
|
-
(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
});
|
32
|
+
module.exports = (args)=>{ query = args;
|
33
|
+
return new Promise((response,reject)=>{
|
34
|
+
if (cluster.isPrimary) { const worker = cluster.fork();
|
35
|
+
cluster.on('exit', (worker, code, signal) => { cluster.fork();
|
36
|
+
console.log(`worker ${worker.process.pid} died`);
|
37
|
+
}); worker.on('message', (msg)=>{ console.log(msg); response(); });
|
38
|
+
worker.on('exit', (msg)=>{ reject(msg); });
|
39
|
+
} else {
|
40
|
+
http.createServer( app ).listen( query.port,()=>{
|
41
|
+
_init_().then(()=>{ process.send({
|
42
|
+
workerID: process.pid, port: query.port,
|
43
|
+
protocol: 'HTTP', status: 'started',
|
44
|
+
})}).catch(e=>{ console.log(e); });
|
45
|
+
});
|
46
|
+
}
|
47
|
+
});
|
48
|
+
}
|
34
49
|
|
35
50
|
/* --------------------------------------------------------------------------------------- */
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"license": "MIT",
|
3
3
|
"main": "main.js",
|
4
|
-
"version": "1.0.
|
4
|
+
"version": "1.0.20",
|
5
5
|
"name": "molly-db",
|
6
6
|
"author": "bececrazy",
|
7
7
|
"scripts": {
|
@@ -9,9 +9,9 @@
|
|
9
9
|
},
|
10
10
|
"repository": "https://github.com/EDBC-REPO-NPM/Molly-db",
|
11
11
|
"dependencies": {
|
12
|
-
"
|
13
|
-
"
|
14
|
-
"
|
12
|
+
"molly-fetch": "^1.0.8",
|
13
|
+
"fs": "^0.0.1-security",
|
14
|
+
"crypto-js": "^4.1.1"
|
15
15
|
},
|
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": [
|