molly-db 1.3.3 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- package/main.js +4 -3
- package/module/import_handler.js +3 -0
- package/module/init_handler.js +2 -1
- package/module/memory_handler.js +1 -1
- package/module/server_worker.js +6 -3
- package/module/utils.js +19 -0
- package/module/worker_handler.js +1 -0
- package/package.json +5 -3
package/main.js
CHANGED
@@ -25,10 +25,11 @@ class molly_db{
|
|
25
25
|
this.path = path.join(process.cwd(),opt.path);
|
26
26
|
else this.path = opt.path;
|
27
27
|
|
28
|
+
this.host = opt.host || 'localhost';
|
28
29
|
this.protocol = opt.protocol || 'http';
|
29
|
-
this.time = opt.saveTime
|
30
|
-
this.import = opt.import
|
31
|
-
this.threads = opt.thread|| 1;
|
30
|
+
this.time = opt.saveTime || .1;
|
31
|
+
this.import = opt.import || '';
|
32
|
+
this.threads = opt.thread || 1;
|
32
33
|
|
33
34
|
return require(dir)(this);
|
34
35
|
}
|
package/module/init_handler.js
CHANGED
package/module/memory_handler.js
CHANGED
@@ -23,7 +23,7 @@ module.exports = function( data,inst,db ){
|
|
23
23
|
const cfg = copy(data,input[i]); try {
|
24
24
|
const bool = await utils.validator(db,cfg);
|
25
25
|
if( !bool[0] ) return reject(bool[1]);
|
26
|
-
else result.push(utils[cfg.type](cfg,db));
|
26
|
+
else result.push(await utils[cfg.type](cfg,db));
|
27
27
|
} catch(e) {
|
28
28
|
return reject({ status:404, message:`error: ${e.message}` })
|
29
29
|
}
|
package/module/server_worker.js
CHANGED
@@ -8,31 +8,34 @@ const ws = require('ws');
|
|
8
8
|
/*--────────────────────────────────────────────────────────────────────────────────────────────--*/
|
9
9
|
|
10
10
|
function createHTTPServer(){
|
11
|
-
http.createServer( app.http ).listen( process.env.port,()=>{
|
11
|
+
http.createServer( app.http ).listen( process.env.port, process.env.host, ()=>{
|
12
12
|
console.log({
|
13
13
|
protocol: 'HTTP', status: 'started',
|
14
14
|
wrkID: process.pid, port: process.env.port,
|
15
|
+
host: process.env.host
|
15
16
|
});
|
16
17
|
});
|
17
18
|
}
|
18
19
|
|
19
20
|
function createWebSocketServer(){
|
20
|
-
const srv = new ws.WebSocketServer({ port: process.env.port });
|
21
|
+
const srv = new ws.WebSocketServer({ port: process.env.port, host: process.env.host });
|
21
22
|
srv.on('connection',(client)=>{
|
22
23
|
client.on('message',(msg)=>app.WebSocket(msg,client));
|
23
24
|
}); console.log ({
|
24
25
|
protocol: 'WebSocket', status: 'started',
|
25
26
|
wrkID: process.pid, port: process.env.port,
|
27
|
+
host: process.env.host
|
26
28
|
});
|
27
29
|
}
|
28
30
|
|
29
31
|
function createSocketServer(){
|
30
|
-
const srv = net.createServer({ port: process.env.port });
|
32
|
+
const srv = net.createServer({ port: process.env.port, host: process.env.host });
|
31
33
|
srv.on('connection',(client)=>{
|
32
34
|
client.on('message',(msg)=>app.Socket(msg,client));
|
33
35
|
}); console.log ({
|
34
36
|
protocol: 'Socket', status: 'started',
|
35
37
|
wrkID: process.pid, port: process.env.port,
|
38
|
+
host: process.env.host
|
36
39
|
});
|
37
40
|
}
|
38
41
|
|
package/module/utils.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
/*--────────────────────────────────────────────────────────────────────────────────────────────--*/
|
2
2
|
|
3
3
|
const crypto = require('./crypto_handler');
|
4
|
+
const init = require('./init_handler');
|
4
5
|
const path = require('path');
|
5
6
|
const output = new Object();
|
6
7
|
const fs = require('fs');
|
@@ -335,4 +336,22 @@ output.saveAll = async function(data,db){
|
|
335
336
|
|
336
337
|
/*--────────────────────────────────────────────────────────────────────────────────────────────--*/
|
337
338
|
|
339
|
+
output.reset = async function(data,db){
|
340
|
+
const args = JSON.parse(process.env.MOLLY_DB_ARGS);
|
341
|
+
return new Promise((response,reject)=>{
|
342
|
+
init( args ).then((ndb)=>{ db = ndb;
|
343
|
+
|
344
|
+
return response({
|
345
|
+
status: 200,
|
346
|
+
database: data.db,
|
347
|
+
table: data.table,
|
348
|
+
message: 'DB Reseted'
|
349
|
+
});
|
350
|
+
|
351
|
+
}).catch((e)=>{ response(parseError(db,data,e)) });
|
352
|
+
})
|
353
|
+
}
|
354
|
+
|
355
|
+
/*--────────────────────────────────────────────────────────────────────────────────────────────--*/
|
356
|
+
|
338
357
|
module.exports = output;
|
package/module/worker_handler.js
CHANGED
@@ -26,6 +26,7 @@ function saveTimeout(data,db){
|
|
26
26
|
/*--────────────────────────────────────────────────────────────────────────────────────────────--*/
|
27
27
|
|
28
28
|
module.exports = (args)=>{
|
29
|
+
process.env.MOLLY_DB_ARGS = JSON.stringify(args);
|
29
30
|
init( args ).then((db)=>{ saveTimeout( args, db );
|
30
31
|
const dir = path.join(__dirname,'server_worker.js');
|
31
32
|
const srv = new worker.Worker(dir,{ workerData: args });
|
package/package.json
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
{
|
2
|
-
"scripts": {
|
2
|
+
"scripts": {
|
3
|
+
"start": "node main"
|
4
|
+
},
|
3
5
|
"repository": "https://github.com/EDBC-REPO-NPM/Molly-db",
|
4
6
|
"dependencies": {
|
5
|
-
"molly-fetch": "^1.0.16",
|
6
7
|
"crypto-js": "^4.1.1",
|
8
|
+
"molly-fetch": "^1.1.2",
|
7
9
|
"ws": "^8.11.0"
|
8
10
|
},
|
9
11
|
"license": "MIT",
|
10
12
|
"main": "main.js",
|
11
13
|
"name": "molly-db",
|
12
|
-
"version": "1.3.
|
14
|
+
"version": "1.3.5",
|
13
15
|
"author": "bececrazy",
|
14
16
|
"description": "Molly-db is a free and open source library for nodejs that allow you create a lightweight encrypted database using Json files",
|
15
17
|
"keywords": [
|