snowbase 5.1.0 → 6.0.0
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/CHANGELOG.md +34 -0
- package/LICENSE +7 -0
- package/README.md +224 -31
- package/bin/snowbase.js +291 -0
- package/package.json +50 -16
- package/src/Snowbase.js +403 -0
- package/src/SnowbaseAsync.js +402 -0
- package/src/helpers/crypto.js +69 -0
- package/src/helpers/utils.js +234 -0
- package/src/helpers/utilsAsync.js +229 -0
- package/src/storages/FileStorage.js +170 -0
- package/src/storages/FileStorageAsync.js +167 -0
- package/.upm/store.json +0 -1
- package/index.js +0 -5
- package/src/Local.js +0 -45
- package/src/Server.js +0 -121
- package/src/index.js +0 -4
package/src/Server.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
const server = process.env.server;
|
|
2
|
-
const fetch = require('node-fetch');
|
|
3
|
-
const {EventEmitter} = require('events');
|
|
4
|
-
|
|
5
|
-
module.exports = class ServerDatabase extends EventEmitter {
|
|
6
|
-
constructor(options={}) {
|
|
7
|
-
super();
|
|
8
|
-
this.connected = false;
|
|
9
|
-
this.connectedAt = null;
|
|
10
|
-
if (options.type === 'alpha-discord') {
|
|
11
|
-
if (options.token) {
|
|
12
|
-
this.type = 'alpha-discord-bot';
|
|
13
|
-
this.token = options.token;
|
|
14
|
-
}
|
|
15
|
-
} else {
|
|
16
|
-
if (!options.login) throw new Error('Invalid key to connect');
|
|
17
|
-
if (!options.password) throw new Error('Invalid password to connect');
|
|
18
|
-
this.client = {
|
|
19
|
-
login: options.login,
|
|
20
|
-
password: options.password
|
|
21
|
-
};
|
|
22
|
-
this.type = 'personal'
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
this.connect();
|
|
26
|
-
};
|
|
27
|
-
async connect() {
|
|
28
|
-
let body = JSON.stringify(this);
|
|
29
|
-
const connection = await fetch(server + '/connect', {
|
|
30
|
-
method: 'POST',
|
|
31
|
-
headers: {
|
|
32
|
-
body
|
|
33
|
-
}
|
|
34
|
-
}).then(d => d.json());
|
|
35
|
-
if (connection.connected !== true) throw new Error('Cannot connect to the Server: '+ connection.message);
|
|
36
|
-
this.connected = true;
|
|
37
|
-
this.connectedAt = Date.now();
|
|
38
|
-
this.emit('connected');
|
|
39
|
-
return connection;
|
|
40
|
-
}
|
|
41
|
-
async get(key) {
|
|
42
|
-
if (!this.connected) throw new Error('Need to have a connection for database.');
|
|
43
|
-
if (typeof key != 'string') throw new Error('Key must be a string!');
|
|
44
|
-
|
|
45
|
-
const info = {
|
|
46
|
-
key,
|
|
47
|
-
connected: this.connected
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
if (this.type == 'alpha-discord-bot') {
|
|
51
|
-
info.type = this.type;
|
|
52
|
-
info.client = {
|
|
53
|
-
login: this.token
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
info.client = this.client;
|
|
57
|
-
}
|
|
58
|
-
const value = await fetch(server + '/get', {
|
|
59
|
-
method: 'POST',
|
|
60
|
-
headers: {
|
|
61
|
-
body: JSON.stringify(info)
|
|
62
|
-
}
|
|
63
|
-
}).then(a => a.json());
|
|
64
|
-
if (value.error) throw new Error('Cannot get response: ' + value.message)
|
|
65
|
-
return value.value;
|
|
66
|
-
};
|
|
67
|
-
async save(key, value) {
|
|
68
|
-
if (!this.connected) throw new Error('Need to have a connection for database.');
|
|
69
|
-
|
|
70
|
-
if (typeof value != 'string' || typeof key != 'string') throw new Error('Key and value must be a string');
|
|
71
|
-
|
|
72
|
-
const info = {
|
|
73
|
-
key,
|
|
74
|
-
value,
|
|
75
|
-
connected: this.connected
|
|
76
|
-
};
|
|
77
|
-
if (this.type == 'alpha-discord-bot') {
|
|
78
|
-
info.type = this.type;
|
|
79
|
-
info.client = {
|
|
80
|
-
login: this.token
|
|
81
|
-
}
|
|
82
|
-
} else {
|
|
83
|
-
info.client = this.client;
|
|
84
|
-
};
|
|
85
|
-
const save = await fetch(server + '/save', {
|
|
86
|
-
method: 'POST',
|
|
87
|
-
headers: {
|
|
88
|
-
body: JSON.stringify(info)
|
|
89
|
-
}
|
|
90
|
-
}).then(r => r.json());
|
|
91
|
-
if (save.error) throw new Error('Cannot save the value:' + save.message);
|
|
92
|
-
this.emit(save.eventName, save.eventContent[0], save.eventContent[1]);
|
|
93
|
-
return save;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
async remove(key) {
|
|
97
|
-
if (!this.connected) throw new Error('Need to have a connection for database.');
|
|
98
|
-
if (typeof key != 'string') throw new Error('Invalid key to remove.');
|
|
99
|
-
const info = {
|
|
100
|
-
key,
|
|
101
|
-
connected: this.connected
|
|
102
|
-
};
|
|
103
|
-
if (this.type == 'alpha-discord-bot') {
|
|
104
|
-
info.type = this.type;
|
|
105
|
-
info.client = {
|
|
106
|
-
login: this.token
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
info.client = this.client;
|
|
110
|
-
};
|
|
111
|
-
const remove = await fetch(server + '/remove', {
|
|
112
|
-
method: 'POST',
|
|
113
|
-
headers: {
|
|
114
|
-
body: JSON.stringify(info)
|
|
115
|
-
}
|
|
116
|
-
}).then(r => r.json());
|
|
117
|
-
if (remove.error) throw new Error('Cannot remove the value:' + remove.message);
|
|
118
|
-
this.emit(remove.eventName, remove.eventContent[0], remove.eventContent[1])
|
|
119
|
-
return remove;
|
|
120
|
-
}
|
|
121
|
-
}
|
package/src/index.js
DELETED