From 0e8356e9b1acd95be5b94f0e55bba9d749a36d12 Mon Sep 17 00:00:00 2001 From: afeuerstein <32029275+afeuerstein@users.noreply.github.com> Date: Tue, 6 Apr 2021 21:32:44 +0200 Subject: remove compiled typescript code from repo --- dist/util/Database.js | 81 --------------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 dist/util/Database.js (limited to 'dist/util/Database.js') diff --git a/dist/util/Database.js b/dist/util/Database.js deleted file mode 100644 index b80fd835..00000000 --- a/dist/util/Database.js +++ /dev/null @@ -1,81 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.MongooseCache = void 0; -require("./MongoBigInt"); -const mongoose_1 = __importDefault(require("mongoose")); -const mongodb_1 = require("mongodb"); -const events_1 = __importDefault(require("events")); -const uri = process.env.MONGO_URL || "mongodb://localhost:27017/fosscord?readPreference=secondaryPreferred"; -console.log(`[DB] connect: ${uri}`); -const connection = mongoose_1.default.createConnection(uri, { autoIndex: true }); -exports.default = connection; -class MongooseCache extends events_1.default { - constructor(collection, pipeline, opts) { - super(); - this.collection = collection; - this.pipeline = pipeline; - this.opts = opts; - this.init = async () => { - this.stream = this.collection.watch(this.pipeline, { fullDocument: "updateLookup" }); - this.stream.on("change", this.change); - this.stream.on("close", this.destroy); - this.stream.on("error", console.error); - if (!this.opts.onlyEvents) { - const arr = await this.collection.aggregate(this.pipeline).toArray(); - this.data = arr.length ? arr[0] : arr; - } - }; - this.convertResult = (obj) => { - if (obj instanceof mongodb_1.Long) - return BigInt(obj.toString()); - if (typeof obj === "object") { - Object.keys(obj).forEach((key) => { - obj[key] = this.convertResult(obj[key]); - }); - } - return obj; - }; - this.change = (doc) => { - try { - // @ts-ignore - if (doc.fullDocument) { - // @ts-ignore - if (!this.opts.onlyEvents) - this.data = doc.fullDocument; - } - switch (doc.operationType) { - case "dropDatabase": - return this.destroy(); - case "drop": - return this.destroy(); - case "delete": - return this.emit("delete", doc.documentKey._id.toHexString()); - case "insert": - return this.emit("insert", doc.fullDocument); - case "update": - case "replace": - return this.emit("change", doc.fullDocument); - case "invalidate": - return this.destroy(); - default: - return; - } - } - catch (error) { - this.emit("error", error); - } - }; - this.destroy = () => { - this.stream?.off("change", this.change); - this.emit("close"); - if (this.stream.isClosed()) - return; - return this.stream.close(); - }; - } -} -exports.MongooseCache = MongooseCache; -//# sourceMappingURL=Database.js.map \ No newline at end of file -- cgit 1.5.1