-
Notifications
You must be signed in to change notification settings - Fork 19
/
ADBProvider.js
189 lines (169 loc) · 5.58 KB
/
ADBProvider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* eslint-disable no-unused-vars */
import AxonClient from '../AxonClient';
import AxonError from '../Errors/AxonError';
import NoAbstractInstanceException from '../Errors/NoAbstractInstanceException';
import NotImplementedException from '../Errors/NotImplementedException';
/**
* @typedef {String|Boolean|Object.<string, any>|Array<any>|Number|Date} updateDBVal
* @typedef {import('../AxonOptions').default} AxonOptions
* @typedef {import('../Core/Models/AxonConfig').default} AxonConfig
* @typedef {import('../Core/Models/GuildConfig').default} GuildConfig
* @typedef {{
* id: String, prefix: String, createdAt: Date, updatedAt: Date, bannedUsers: Array<String>, bannedGuilds: Array<String>
* }} AxonConfigRaw
* @typedef {{
* guildID: string, prefixes: Array<String>, createdAt: Date, updatedAt: Date, modules: Array<String>, commands: Array<String>, listeners: Array<String>,
* ignoredUsers: Array<String>, ignoredRoles: Array<String>, ignoredChannels: Array<String>, modOnly: Boolean, modRoles: Array<String>, modUsers: Array<String>
* }} GuildConfigRaw
* @typedef {import('../Utility/Constants/AxonEnums').DB_TYPES} DB_TYPES
*/
/**
* Abstract class for all DB services.
* Extend this class to create your own Database provider.
* You just need to write these methods for the framework to be able to interact with the database.
*
* The provider creates guildconfigs with DB data.
*
* @author KhaaZ
*
* @abstract
* @class ADBProvider
*
* @prop {AxonClient} axon - The AxonClient
* @prop {DB_TYPES} type - The Database type
*/
class ADBProvider {
/**
* Creates an instance of ADBProvider.
*
* @param {AxonClient} axonClient
* @param {DB_TYPES} [type=0]
* @memberof ADBProvider
*/
constructor(axonClient, type = 0) {
if (this.constructor === 'ADBProvider') {
throw new NoAbstractInstanceException();
}
if (!axonClient || !(axonClient instanceof AxonClient) ) {
throw new AxonError('First argument needs to be the AxonClient.', 'ADBProvider');
}
this.axon = axonClient;
this.type = type;
}
/**
* Init the ADBProvider.
* Method called just after instantiation. Can be overridden with anything that will be used by the provider.
*
* @memberof ADBProvider
*/
init() {
throw new NotImplementedException();
}
// **** INIT **** //
/**
* Initialises a default Axon config.
*
* @returns {Promise<AxonConfig>} Newly created Axon config from the DB
*
* @memberof ADBProvider
*/
async initAxon() {
throw new NotImplementedException();
}
/**
* Initialises a default Guild config.
* Use default AxonClient prefix settings when creating the new guild config.
*
* @param {String} gID - Guild ID
*
* @returns {Promise<GuildConfig|null>} Newly created Guild config from the DB
*
* @memberof ADBProvider
*/
async initGuild(gID) {
throw new NotImplementedException();
}
// **** FETCHERS **** //
/**
* Retrieves the axon config from the DB
*
* @returns {Promise<AxonConfig|null>} AxonSchema Object or null
*
* @memberof ADBProvider
*/
async fetchAxon() {
throw new NotImplementedException();
}
/**
* Retrieves the Guild config for the specified guild.
*
* @param {String} gID - Guild ID
* @returns {Promise<GuildConfig|null>}
*
* @memberof ADBProvider
*/
async fetchGuild(gID) {
throw new NotImplementedException();
}
// **** UPDATES **** //
/**
* Update AxonConfig in the DB.
* Update the specific key with the value given as second parameters.
* Generic method to update Database.
*
* @param {String} key - The identifier in the Database
* @param {updateDBVal} value - The value to update in the DB
* @returns {Promise<Boolean>} Whether the request was successful or not
*
* @memberof ADBProvider
*/
async updateAxon(key, value) {
throw new NotImplementedException();
}
/**
* Update GuildConfig in the DB.
* Update the specific key with the value given as third parameters.
* Specify the guild with the guild ID.
* Generic method to update Database.
*
* @param {String} key - The identifier in the Database
* @param {String} gID - The guild ID to update
* @param {updateDBVal} value - The value to update in the DB
* @returns {Promise<Boolean>} Whether the request was successful or not
*
* @memberof ADBProvider
*/
async updateGuild(key, gID, value) {
throw new NotImplementedException();
}
/**
* Updates the Axon config in the DB with a new Axon config object.
*
* @param {AxonConfig|AxonConfigRaw} data - the schema object to update
* @returns {Promise<AxonConfig|null>} Updated AxonConfig from the DB
*
* @memberof ADBProvider
*/
async saveAxon(data) {
throw new NotImplementedException();
}
/**
* Updates the given guild in the DB with a new schema object.
*
* @param {String} gID - Guild ID
* @param {GuildConfig|GuildConfigRaw} data - The schema object to update
* @returns {Promise<GuildConfig|null>} Updated GuildConfig from the DB
*
* @memberof ADBProvider
*/
async saveGuild(gID, data) {
throw new NotImplementedException();
}
get GuildConfig() {
return this.axon.extensions.GuildConfig;
}
get AxonConfig() {
return this.axon.extensions.AxonConfig;
}
}
export default ADBProvider;