simply-xp 2.0.0-dev.2-fix.0 → 2.0.0-dev.3-fix.1
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/lib/src/connect.js +7 -7
- package/lib/src/create.js +1 -1
- package/lib/src/functions/database.d.ts +9 -0
- package/lib/src/functions/database.js +11 -5
- package/lib/src/functions/xplogs.d.ts +5 -2
- package/lib/src/functions/xplogs.js +15 -1
- package/lib/src/migrate.d.ts +7 -5
- package/lib/src/migrate.js +6 -6
- package/lib/src/reset.d.ts +3 -3
- package/lib/src/reset.js +3 -3
- package/package.json +2 -2
package/lib/src/connect.js
CHANGED
|
@@ -8,27 +8,27 @@
|
|
|
8
8
|
* @link `Documentation:` https://simplyxp.js.org/docs/connect
|
|
9
9
|
* @returns {Promise<boolean>}
|
|
10
10
|
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
11
|
-
*/async function connect(uri,options={type:void 0}){var e,{type:
|
|
11
|
+
*/async function connect(uri,options={type:void 0}){var e,{type:o,auto_create:t,auto_purge:r,notify:a,debug:n}=options;if(!uri)throw new xplogs_1.XpFatal({function:"connect()",message:"No URI Provided"});switch(!1===a&&(xp_1.xp.notify=!1),t&&(xp_1.xp.auto_create=!0),r&&(xp_1.xp.auto_purge=!0),n&&(xp_1.xp.debug=!0),o||(options.type="mongodb",xplogs_1.XpLog.warn("connect()","Database type not provided, defaulting to MongoDB")),o){case"mongodb":if(e=(await Promise.resolve().then(()=>__importStar(require("mongodb")))).MongoClient,!await checkPackageVersion("mongodb"))return xplogs_1.XpLog.err("connect()","MongoDB V4 or higher is required");e=await e.connect(uri).catch(error=>{throw new xplogs_1.XpFatal({function:"connect()",message:error.message})}),xp_1.xp.dbType="mongodb",xp_1.xp.database=e||void 0;break;case"sqlite":try{var[s,i]=await Promise.all([Promise.resolve().then(()=>__importStar(require("better-sqlite3"))),checkPackageVersion("sqlite")]);if(!i)return xplogs_1.XpLog.err("connect()","better-sqlite3 V7 or higher is required");xp_1.xp.database=new s.default(uri),xp_1.xp.dbType="sqlite",xp_1.xp.database.exec(`CREATE TABLE IF NOT EXISTS "simply-xps"
|
|
12
12
|
(
|
|
13
|
-
user TEXT
|
|
14
|
-
guild TEXT,
|
|
15
|
-
name TEXT DEFAULT
|
|
13
|
+
user TEXT NOT NULL,
|
|
14
|
+
guild TEXT NOT NULL,
|
|
15
|
+
name TEXT DEFAULT "Unknown",
|
|
16
16
|
level INTEGER DEFAULT 0,
|
|
17
17
|
xp INTEGER DEFAULT 0
|
|
18
18
|
)`),xp_1.xp.database.exec(`CREATE TABLE IF NOT EXISTS "simply-xp-levelroles"
|
|
19
19
|
(
|
|
20
20
|
gid TEXT UNIQUE,
|
|
21
21
|
lvlrole TEXT NOT NULL
|
|
22
|
-
)`)}catch(
|
|
22
|
+
)`)}catch(o){if("object"==typeof o&&null!==o&&void 0!==(e=o).code&&"MODULE_NOT_FOUND"!==e.code)throw new xplogs_1.XpFatal({function:"connect()",message:e.message})}break;default:throw new xplogs_1.XpFatal({function:"connect()",message:"DATABASE TYPE NOT PROVIDED OR INVALID"})}return!!xp_1.xp.database&&(xplogs_1.XpLog.info("connect()","Connected to database!"),!0)}
|
|
23
23
|
/**
|
|
24
24
|
* Returns the package manager used
|
|
25
25
|
* @private
|
|
26
26
|
* @returns {Promise<"yarn" | "npm" | "pnpm">}
|
|
27
|
-
*/async function getPackageManager(){const e=(await Promise.resolve().then(()=>__importStar(require("fs")))).existsSync;var
|
|
27
|
+
*/async function getPackageManager(){const e=(await Promise.resolve().then(()=>__importStar(require("fs")))).existsSync;var o=["yarn.lock","pnpm-lock.yaml","pnpm-lock.json","package-lock.json"].filter(lockfile=>e(lockfile));if(1===o.length){if("yarn.lock"===o[0])return xplogs_1.XpLog.debug("getPackageManager()","Using Yarn"),"yarn";if("pnpm-lock.yaml"===o[0]||"pnpm-lock.json"===o[0])return xplogs_1.XpLog.debug("getPackageManager()","Using PNPM"),"pnpm"}return xplogs_1.XpLog.debug("getPackageManager()","Using NPM"),"npm"}
|
|
28
28
|
/**
|
|
29
29
|
* Check database package versions
|
|
30
30
|
* @private
|
|
31
31
|
* @param {"mongodb" | "sqlite"} type
|
|
32
32
|
* @returns {Promise<boolean>}
|
|
33
33
|
* @throws {XpFatal} If the package version is not supported
|
|
34
|
-
*/async function checkPackageVersion(type){var e,
|
|
34
|
+
*/async function checkPackageVersion(type){var e,o;switch(type){case"mongodb":try{return e=await Promise.resolve().then(()=>__importStar(require("mongodb/package.json"))),4<=parseInt(e.version.substring(0,1))}catch(e){return xplogs_1.XpLog.info("checkPackageVersion()","Installing MongoDB [5.x] | Please wait..."),(0,child_process_1.execSync)(await getPackageManager()+" add mongodb@5.x.x"),xplogs_1.XpLog.warn("checkPackageVersion()","Installed MongoDB. Please restart!"),process.exit(1)}case"sqlite":try{return o=await Promise.resolve().then(()=>__importStar(require("better-sqlite3/package.json"))),7<=parseInt(o.version.substring(0,1))}catch(e){return xplogs_1.XpLog.info("checkPackageVersion()","Installing better-sqlite3 [V8] | Please wait..."),(0,child_process_1.execSync)(await getPackageManager()+" add better-sqlite3@8.x.x"),xplogs_1.XpLog.warn("checkPackageVersion()","Installed better-sqlite3. Please restart!"),process.exit(1)}}}var __createBinding=this&&this.__createBinding||(Object.create?function(o,m,k,k2){void 0===k2&&(k2=k);var e=Object.getOwnPropertyDescriptor(m,k);e&&("get"in e?m.__esModule:!e.writable&&!e.configurable)||(e={enumerable:!0,get:function(){return m[k]}}),Object.defineProperty(o,k2,e)}:function(o,m,k,k2){o[k2=void 0===k2?k:k2]=m[k]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(o,v){Object.defineProperty(o,"default",{enumerable:!0,value:v})}:function(o,v){o.default=v}),__importStar=this&&this.__importStar||function(mod){var e,o;if(mod&&mod.__esModule)return mod;if(e={},null!=mod)for(o in mod)"default"!==o&&Object.prototype.hasOwnProperty.call(mod,o)&&__createBinding(e,mod,o);return __setModuleDefault(e,mod),e};Object.defineProperty(exports,"__esModule",{value:!0}),exports.checkPackageVersion=exports.connect=void 0;const xplogs_1=require("./functions/xplogs"),child_process_1=require("child_process"),xp_1=require("../xp");exports.connect=connect,exports.checkPackageVersion=checkPackageVersion;
|
package/lib/src/create.js
CHANGED
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
* @link `Documentation:` https://simplyxp.js.org/docs/create
|
|
9
9
|
* @returns {Promise<UserResult>}
|
|
10
10
|
* @throws {XpFatal} If invalid parameters are provided
|
|
11
|
-
*/async function create(userId,guildId,username){if(!userId)throw new xplogs_1.XpFatal({function:"create()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"create()",message:"Guild ID was not provided"});if(
|
|
11
|
+
*/async function create(userId,guildId,username){if(!userId)throw new xplogs_1.XpFatal({function:"create()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"create()",message:"Guild ID was not provided"});var e;if(username)return await(e=(await Promise.resolve().then(()=>__importStar(require("./functions/database")))).db).findOne({collection:"simply-xps",data:{user:userId,guild:guildId}})||e.createOne({collection:"simply-xps",data:{name:username,user:userId,guild:guildId,level:0,xp:0}});throw new xplogs_1.XpFatal({function:"create()",message:"Username was not provided"})}var __createBinding=this&&this.__createBinding||(Object.create?function(o,m,k,k2){void 0===k2&&(k2=k);var e=Object.getOwnPropertyDescriptor(m,k);e&&("get"in e?m.__esModule:!e.writable&&!e.configurable)||(e={enumerable:!0,get:function(){return m[k]}}),Object.defineProperty(o,k2,e)}:function(o,m,k,k2){o[k2=void 0===k2?k:k2]=m[k]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(o,v){Object.defineProperty(o,"default",{enumerable:!0,value:v})}:function(o,v){o.default=v}),__importStar=this&&this.__importStar||function(mod){var e,t;if(mod&&mod.__esModule)return mod;if(e={},null!=mod)for(t in mod)"default"!==t&&Object.prototype.hasOwnProperty.call(mod,t)&&__createBinding(e,mod,t);return __setModuleDefault(e,mod),e};Object.defineProperty(exports,"__esModule",{value:!0}),exports.create=void 0;const xplogs_1=require("./functions/xplogs");exports.create=create;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Collection } from "mongodb";
|
|
1
2
|
/**
|
|
2
3
|
* Options for creating a user document.
|
|
3
4
|
* @property {string} collection - The collection to create the document in.
|
|
@@ -65,6 +66,14 @@ export type LevelRoleResult = {
|
|
|
65
66
|
* @class db
|
|
66
67
|
*/
|
|
67
68
|
export declare class db {
|
|
69
|
+
/**
|
|
70
|
+
* Gets a collection from the database.
|
|
71
|
+
* @param {collection} collection - The collection to get.
|
|
72
|
+
* @link https://simplyxp.js.org/docs/handlers/database#getCollection Documentation
|
|
73
|
+
* @returns {Collection} The collection.
|
|
74
|
+
* @throws {XpFatal} Throws an error if there is no database connection, or database type is invalid.
|
|
75
|
+
*/
|
|
76
|
+
static getCollection(collection: string): Collection;
|
|
68
77
|
/**
|
|
69
78
|
* Creates one document in the database.
|
|
70
79
|
*
|
|
@@ -5,8 +5,15 @@
|
|
|
5
5
|
* @param {string} functionName
|
|
6
6
|
* @returns {void}
|
|
7
7
|
* @private
|
|
8
|
-
*/
|
|
9
|
-
|
|
8
|
+
*/function handleError(error,functionName){throw new xplogs_1.XpFatal({function:"db."+functionName,message:error})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.db=void 0;const xplogs_1=require("./xplogs"),xp_1=require("../../xp");class db{
|
|
9
|
+
/**
|
|
10
|
+
* Gets a collection from the database.
|
|
11
|
+
* @param {collection} collection - The collection to get.
|
|
12
|
+
* @link https://simplyxp.js.org/docs/handlers/database#getCollection Documentation
|
|
13
|
+
* @returns {Collection} The collection.
|
|
14
|
+
* @throws {XpFatal} Throws an error if there is no database connection, or database type is invalid.
|
|
15
|
+
*/
|
|
16
|
+
static getCollection(collection){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"getCollection()",message:"No database connection"});if("mongodb"!==xp_1.xp.dbType)throw new xplogs_1.XpFatal({function:"getCollection()",message:"MongoDB has to be your database type to use this function."});return xp_1.xp.database.db().collection(collection)}
|
|
10
17
|
/**
|
|
11
18
|
* Creates one document in the database.
|
|
12
19
|
*
|
|
@@ -15,8 +22,7 @@ function handleError(error,functionName){throw new xplogs_1.XpFatal({function:"d
|
|
|
15
22
|
* @link https://simplyxp.js.org/docs/handlers/database#createOne Documentation
|
|
16
23
|
* @returns {Promise<UserResult | LevelRoleResult>} The created document.
|
|
17
24
|
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
18
|
-
*/
|
|
19
|
-
static async createOne(query){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"createOne()",message:"No database connection"});let e;switch(xp_1.xp.dbType){case"mongodb":e=xp_1.xp.database.db().collection(query.collection).insertOne(query.data).catch(error=>handleError(error,"createOne()"));break;case"sqlite":e="simply-xps"===query.collection?xp_1.xp.database.prepare('INSERT INTO "simply-xps" (user, guild, xp, level, name) VALUES (?, ?, ?, ?, ?)').run(query.data.user,query.data.guild,query.data.xp,query.data.level,query.data?.name):xp_1.xp.database.prepare('INSERT INTO "simply-xp-levelroles" (guild, level, role) VALUES (?, ?, ?)').run(query.data.guild,query.data.level,query.data.roles)}return e}
|
|
25
|
+
*/static async createOne(query){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"createOne()",message:"No database connection"});let e;switch(xp_1.xp.dbType){case"mongodb":e=xp_1.xp.database.db().collection(query.collection).insertOne(query.data).catch(error=>handleError(error,"createOne()"));break;case"sqlite":e="simply-xps"===query.collection?xp_1.xp.database.prepare('INSERT INTO "simply-xps" (user, guild, name, xp, level) VALUES (?, ?, ?, ?, ?)').run(query.data.user,query.data.guild,query.data?.name,query.data.xp,query.data.level):xp_1.xp.database.prepare('INSERT INTO "simply-xp-levelroles" (guild, level, role) VALUES (?, ?, ?)').run(query.data.guild,query.data.level,query.data.roles)}return e}
|
|
20
26
|
/**
|
|
21
27
|
* Deletes one document from the database.
|
|
22
28
|
*
|
|
@@ -54,4 +60,4 @@ static async createOne(query){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({f
|
|
|
54
60
|
* @link https://simplyxp.js.org/docs/handlers/database#updateOne Documentation
|
|
55
61
|
* @returns {Promise<UserResult | LevelRoleResult>} The updated document.
|
|
56
62
|
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
57
|
-
*/static async updateOne(filter,update,options){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"updateOne()",message:"No database connection"});switch(xp_1.xp.dbType){case"mongodb":await xp_1.xp.database.db().collection(update.collection).updateOne(filter.data,{$set:update.data},options).catch(error=>handleError(error,"updateOne()"));break;case"sqlite":if("simply-xps"===filter.collection&&"simply-xps"===update.collection)xp_1.xp.database.prepare('UPDATE "simply-xps" SET
|
|
63
|
+
*/static async updateOne(filter,update,options){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"updateOne()",message:"No database connection"});switch(xp_1.xp.dbType){case"mongodb":await xp_1.xp.database.db().collection(update.collection).updateOne(filter.data,{$set:update.data},options).catch(error=>handleError(error,"updateOne()"));break;case"sqlite":if("simply-xps"===filter.collection&&"simply-xps"===update.collection)xp_1.xp.database.prepare('UPDATE "simply-xps" SET name = ?, xp = ?, level = ? WHERE guild = ? AND user = ?').run(update.data?.name,update.data.xp,update.data.level,filter.data.guild,filter.data.user);else{if("simply-xp-levelroles"!==filter.collection||"simply-xp-levelroles"!==update.collection)throw new xplogs_1.XpFatal({function:"updateOne()",message:"Collection mismatch, expected same collection on both filter and update."});xp_1.xp.database.prepare('UPDATE "simply-xp-levelroles" SET role = ? WHERE guild = ? AND level = ?').run(update.data.roles,filter.data.guild,filter.data.level)}}return db.findOne(update)}}exports.db=db;
|
|
@@ -17,6 +17,7 @@ export declare class XpFatal extends Error {
|
|
|
17
17
|
/**
|
|
18
18
|
* Emits a log message
|
|
19
19
|
* @class XpLog
|
|
20
|
+
* @private
|
|
20
21
|
*/
|
|
21
22
|
export declare class XpLog {
|
|
22
23
|
/**
|
|
@@ -38,16 +39,18 @@ export declare class XpLog {
|
|
|
38
39
|
* Emits an info log
|
|
39
40
|
* @param {string} command - The command or context of the log message
|
|
40
41
|
* @param {string} message - The log message
|
|
42
|
+
* @returns {boolean} Returns true
|
|
41
43
|
* @private
|
|
42
44
|
*/
|
|
43
|
-
static info(command: string, message: string):
|
|
45
|
+
static info(command: string, message: string): boolean;
|
|
44
46
|
/**
|
|
45
47
|
* Emits an error log
|
|
46
48
|
* @param {string} command - The command or context of the log message
|
|
47
49
|
* @param {string} message - The log message
|
|
50
|
+
* @returns {boolean} Returns false
|
|
48
51
|
* @private
|
|
49
52
|
*/
|
|
50
|
-
static err(command: string, message: string):
|
|
53
|
+
static err(command: string, message: string): boolean;
|
|
51
54
|
/**
|
|
52
55
|
* Emits a warning log
|
|
53
56
|
* @param {string} command - The command or context of the log message
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.XpLog=exports.XpFatal=void 0;const xp_1=require("../../xp");class XpFatal extends Error{constructor(options){super(options.function+": "+options.message)}}exports.XpFatal=XpFatal,Object.defineProperty(XpFatal.prototype,"name",{value:"SimplyXpFatal"});class XpLog{static log(level,command,message){var e=level.toUpperCase(),command=command.toUpperCase();console.log(`[35m[SIMPLY XP][0m ${{debug:"[36m",info:"[34m",error:"[31m",warn:"[33m"}[level]}(${e})[0m ${command}: `+message)}static debug(command,message){xp_1.xp.debug&&XpLog.log("debug",command,message)}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.XpLog=exports.XpFatal=void 0;const xp_1=require("../../xp");class XpFatal extends Error{constructor(options){super(options.function+": "+options.message)}}exports.XpFatal=XpFatal,Object.defineProperty(XpFatal.prototype,"name",{value:"SimplyXpFatal"});class XpLog{static log(level,command,message){var e=level.toUpperCase(),command=command.toUpperCase();console.log(`[35m[SIMPLY XP][0m ${{debug:"[36m",info:"[34m",error:"[31m",warn:"[33m"}[level]}(${e})[0m ${command}: `+message)}static debug(command,message){xp_1.xp.debug&&XpLog.log("debug",command,message)}
|
|
2
|
+
/**
|
|
3
|
+
* Emits an info log
|
|
4
|
+
* @param {string} command - The command or context of the log message
|
|
5
|
+
* @param {string} message - The log message
|
|
6
|
+
* @returns {boolean} Returns true
|
|
7
|
+
* @private
|
|
8
|
+
*/static info(command,message){return xp_1.xp.notify&&XpLog.log("info",command,message),!0}
|
|
9
|
+
/**
|
|
10
|
+
* Emits an error log
|
|
11
|
+
* @param {string} command - The command or context of the log message
|
|
12
|
+
* @param {string} message - The log message
|
|
13
|
+
* @returns {boolean} Returns false
|
|
14
|
+
* @private
|
|
15
|
+
*/static err(command,message){return XpLog.log("error",command,message),!1}static warn(command,message){XpLog.log("warn",command,message)}}exports.XpLog=XpLog;
|
package/lib/src/migrate.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { MongoClient } from "mongodb";
|
|
2
|
+
import { Database } from "better-sqlite3";
|
|
1
3
|
/**
|
|
2
4
|
* Migration functions
|
|
3
5
|
* @class migrate
|
|
@@ -6,20 +8,20 @@ export declare class migrate {
|
|
|
6
8
|
/**
|
|
7
9
|
* Effortlessly migrate from discord-xp to simply-xp.
|
|
8
10
|
* @async
|
|
9
|
-
* @param {URL} dbUrl - MongoDB URL
|
|
10
11
|
* @param {boolean} deleteOld - Delete old data after migration
|
|
11
12
|
* @link `Documentation:` https://simplyxp.js.org/docs/migrate/discord_xp
|
|
12
13
|
* @returns {Promise<boolean>} - Returns true if migration is successful
|
|
13
|
-
* @throws {
|
|
14
|
+
* @throws {XpLog.err} - If migration fails.
|
|
14
15
|
*/
|
|
15
|
-
static discord_xp(
|
|
16
|
+
static discord_xp(deleteOld?: boolean): Promise<boolean>;
|
|
16
17
|
/**
|
|
17
18
|
* Effortlessly migrate from MongoDB to SQLite. (or vice versa)
|
|
18
19
|
* @async
|
|
19
|
-
* @param {"mongodb"|"sqlite"}
|
|
20
|
+
* @param {"mongodb"|"sqlite"} dbType
|
|
21
|
+
* @param {Database | MongoClient} connection
|
|
20
22
|
* @link `Documentation:` https://simplyxp.js.org/docs/migrate/database
|
|
21
23
|
* @returns {Promise<boolean>} - Returns true if migration is successful
|
|
22
24
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
23
25
|
*/
|
|
24
|
-
static
|
|
26
|
+
static fromDB(dbType: "mongodb" | "sqlite", connection: Database | MongoClient): Promise<boolean>;
|
|
25
27
|
}
|
package/lib/src/migrate.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.migrate=void 0;const xplogs_1=require("./functions/xplogs"),database_1=require("./functions/database"),xp_1=require("../xp"),connect_1=require("./connect");class migrate{
|
|
2
2
|
/**
|
|
3
3
|
* Effortlessly migrate from discord-xp to simply-xp.
|
|
4
4
|
* @async
|
|
5
|
-
* @param {URL} dbUrl - MongoDB URL
|
|
6
5
|
* @param {boolean} deleteOld - Delete old data after migration
|
|
7
6
|
* @link `Documentation:` https://simplyxp.js.org/docs/migrate/discord_xp
|
|
8
7
|
* @returns {Promise<boolean>} - Returns true if migration is successful
|
|
9
|
-
* @throws {
|
|
8
|
+
* @throws {XpLog.err} - If migration fails.
|
|
10
9
|
*/
|
|
11
|
-
static async discord_xp(
|
|
10
|
+
static async discord_xp(deleteOld=!1){var e=await database_1.db.getCollection("levels").find().toArray();xplogs_1.XpLog.debug("migrate.discord_xp()",`FOUND ${e.length} DOCUMENTS`);try{for(const t of e)await database_1.db.findOne({collection:"simply-xps",data:{guild:t.guildID,user:t.userID}})||(await database_1.db.createOne({collection:"simply-xps",data:{guild:t.guildID,user:t.userID,xp:t.xp,level:(0,xp_1.convertFrom)(t.xp,"xp")}}),deleteOld&&await database_1.db.getCollection("levels").deleteOne({userID:t.userID,guildID:t.guildID}));return!0}catch(e){return xplogs_1.XpLog.err("migrate.discord_xp()",e),!1}}
|
|
12
11
|
/**
|
|
13
12
|
* Effortlessly migrate from MongoDB to SQLite. (or vice versa)
|
|
14
13
|
* @async
|
|
15
|
-
* @param {"mongodb"|"sqlite"}
|
|
14
|
+
* @param {"mongodb"|"sqlite"} dbType
|
|
15
|
+
* @param {Database | MongoClient} connection
|
|
16
16
|
* @link `Documentation:` https://simplyxp.js.org/docs/migrate/database
|
|
17
17
|
* @returns {Promise<boolean>} - Returns true if migration is successful
|
|
18
18
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
19
|
-
*/static async
|
|
19
|
+
*/static async fromDB(dbType,connection){if(!dbType)throw new xplogs_1.XpFatal({function:"migrate.database()",message:"No database type provided"});if(!connection)throw new xplogs_1.XpFatal({function:"migrate.database()",message:"No database connection provided"});if(xp_1.xp.dbType===dbType)return xplogs_1.XpLog.info("migrate.fromDB()","Same database received, that was unnecessary!");switch(dbType){case"mongodb":try{if(!await(0,connect_1.checkPackageVersion)("mongodb"))return xplogs_1.XpLog.err("migrate.fromDB()","MongoDB V4 or higher is required");connection.db().collection("simply-xps").find().toArray().then(async results=>{xplogs_1.XpLog.debug("migrate.fromDB()",`FOUND ${results.length} DOCUMENTS`);for(const e of results)await database_1.db.findOne({collection:"simply-xps",data:{guild:e.guild,user:e.user}})?await database_1.db.updateOne({collection:"simply-xps",data:{guild:e.guild,user:e.user}},{collection:"simply-xps",data:{guild:e.guild,user:e.user,name:e.name,xp:e.xp,level:e.level}}):await database_1.db.createOne({collection:"simply-xps",data:{guild:e.guild,user:e.user,xp:e.xp,level:e.level}});return!0})}catch(e){xplogs_1.XpLog.err("migrate.fromDB()",e)}return!1;case"sqlite":return xplogs_1.XpLog.warn("migrate.fromDB()","SQLite migration is not yet supported, soon though!"),!1}}}exports.migrate=migrate;
|
package/lib/src/reset.d.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* @async
|
|
4
4
|
* @param {string} userId
|
|
5
5
|
* @param {string} guildId
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {
|
|
6
|
+
* @param {boolean?} erase - Erase user entry from the database
|
|
7
|
+
* @param {string?} username - Username to use if auto_create is enabled
|
|
8
8
|
* @link `Documentation:` https://simplyxp.js.org/docs/reset
|
|
9
9
|
* @returns {Promise<boolean>}
|
|
10
10
|
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
11
11
|
*/
|
|
12
|
-
export declare function reset(userId: string, guildId: string,
|
|
12
|
+
export declare function reset(userId: string, guildId: string, erase?: boolean, username?: string): Promise<boolean>;
|
package/lib/src/reset.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* @async
|
|
5
5
|
* @param {string} userId
|
|
6
6
|
* @param {string} guildId
|
|
7
|
-
* @param {
|
|
8
|
-
* @param {
|
|
7
|
+
* @param {boolean?} erase - Erase user entry from the database
|
|
8
|
+
* @param {string?} username - Username to use if auto_create is enabled
|
|
9
9
|
* @link `Documentation:` https://simplyxp.js.org/docs/reset
|
|
10
10
|
* @returns {Promise<boolean>}
|
|
11
11
|
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
12
|
-
*/async function reset(userId,guildId,
|
|
12
|
+
*/async function reset(userId,guildId,erase=!1,username){var e;if(userId&&guildId)return e={guild:guildId,user:userId},await database_1.db.findOne({collection:"simply-xps",data:e})?(erase?await database_1.db.deleteOne({collection:"simply-xps",data:e}).catch(error=>{throw new xplogs_1.XpFatal({function:"reset()",message:error})}):await database_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{...e,level:0,xp:0}}).catch(error=>{throw new xplogs_1.XpFatal({function:"reset()",message:error})}),!0):xp_1.xp.auto_create&&!erase&&username?(await database_1.db.createOne({collection:"simply-xps",data:e}).catch(error=>{throw new xplogs_1.XpFatal({function:"reset()",message:error.stack})}),!0):xplogs_1.XpLog.info("reset()","User was not found, we did not know what to do without a username.");throw new xplogs_1.XpFatal({function:"reset()",message:"Invalid parameters provided"})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.reset=void 0;const xplogs_1=require("./functions/xplogs"),xp_1=require("../xp"),database_1=require("./functions/database");exports.reset=reset;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simply-xp",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.3-fix.1",
|
|
4
4
|
"description": "The easiest way to implement xp system",
|
|
5
5
|
"main": "lib/xp.js",
|
|
6
6
|
"scripts": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"eslint": "^8.46.0",
|
|
53
53
|
"guilded.ts": "^0.20.2",
|
|
54
54
|
"jsdoc-to-markdown": "^8.0.0",
|
|
55
|
-
"mongodb": "5.7.0",
|
|
55
|
+
"mongodb": "^5.7.0",
|
|
56
56
|
"typescript": "^5.1.6",
|
|
57
57
|
"uglify-js": "^3.17.4"
|
|
58
58
|
},
|