UNPKG

alclient

Version:

A node client for interacting with Adventure Land - The Code MMORPG. This package extends the functionality of 'alclient' by managing a mongo database.

44 lines 1.59 kB
import { LRUCache } from "lru-cache"; import Mongoose from "mongoose"; export * from "./achievements/achievements.model.js"; export * from "./achievements/achievements.types.js"; export * from "./banks/banks.model.js"; export * from "./banks/banks.types.js"; export * from "./deaths/deaths.model.js"; export * from "./deaths/deaths.types.js"; export * from "./entities/entities.model.js"; export * from "./entities/entities.types.js"; export * from "./instances/instances.model.js"; export * from "./instances/instances.types.js"; export * from "./npcs/npcs.model.js"; export * from "./npcs/npcs.types.js"; export * from "./players/players.model.js"; export * from "./players/players.types.js"; export * from "./respawns/respawns.model.js"; export * from "./respawns/respawns.types.js"; export class Database { static nextUpdate = new LRUCache({ max: 1000 }); static connection; constructor() { // Private to force static methods } static async connect(uri = "mongodb://localhost:27017/alclient") { // Check if we're already connected if (this.connection) { await Mongoose.disconnect(); } const connect = await Mongoose.connect(uri); this.connection = Mongoose.connection; this.connection.on("error", () => { console.error("Error connecting to MongoDB"); }); return connect; } static disconnect() { // Check if we never connected if (!this.connection) return; Mongoose.disconnect(); } } //# sourceMappingURL=Database.js.map