{"version":3,"sources":["jsdelivr-header.js","/npm/cryptpad-mongo-store@1.0.0/mongo.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACUA,IAAI,YAAc,QAAQ,WAAW,YAEjC,UAAY,8EACZ,gBAAkB,WAElB,OAAS,SAAU,EAAM,EAAa,EAAS,GAC/C,IAAI,EAAM,CAAC,KAAM,EAAa,IAAI,EAAS,MAAM,IAAK,MAAQ,WAC9D,EAAK,UAAU,EAAK,CAAC,GAAG,SAAU,EAAK,GACnC,QAAQ,IAAI,GACR,GAA4B,IAApB,EAAE,cACV,QAAQ,IAAI,oBAAsB,GAGtC,GACJ,GACJ,EAEI,YAAc,SAAU,EAAM,EAAa,GAE3C,EAAK,KAAK,CAAC,KAAK,IAEf,KAAM,CAAE,IAAK,IAEb,SAAQ,SAAU,GACf,EAAG,EAAI,IACX,IAAG,SAAU,GACJ,GACL,QAAQ,IAAI,SAAW,EAC3B,GACJ,EAEA,OAAO,QAAQ,OAAS,SAAU,EAAM,GACpC,YAAY,QAAQ,EAAK,UAAU,SAAS,EAAK,GAC7C,IAAI,EAAO,EAAG,WAAW,EAAK,qBAC9B,GAAI,EAAO,MAAM,EACjB,EAAG,CACC,QAAS,SAAU,EAAa,EAAS,GACrC,OAAO,EAAM,EAAa,EAAS,EACvC,EACA,YAAa,SAAU,EAAa,GAChC,YAAY,EAAM,EAAa,EACnC,GAER,GACJ","file":"/npm/cryptpad-mongo-store@1.0.0/mongo.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/cryptpad-mongo-store@1.0.0/mongo.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/*\n * Copyright 2014 XWiki SAS\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\nvar MongoClient = require('mongodb').MongoClient;\n\nvar MONGO_URI = \"mongodb://demo_user:demo_password@ds027769.mongolab.com:27769/demo_database\";\nvar COLLECTION_NAME = 'cryptpad';\n\nvar insert = function (coll, channelName, content, cb) {\n    var val = {chan: channelName, msg:content, time: (new Date()).getTime()};\n    coll.insertOne(val, {}, function (err, r) {\n        console.log(r);\n        if (err || (r.insertedCount !== 1)) {\n            console.log('failed to insert ' + err);\n            return;\n        }\n        cb();\n    });\n};\n\nvar getMessages = function (coll, channelName, cb) {\n    // find entries with a matching channelname\n    coll.find({chan:channelName})\n    // sort by _id, ascending\n    .sort( { _id: 1 } )\n    // iterate over entries\n    .forEach(function (doc) {\n        cb(doc.msg);\n    }, function (err) {\n        if (!err) { return; }\n        console.log('error ' + err);\n    });\n};\n\nmodule.exports.create = function (conf, cb) {\n    MongoClient.connect(conf.mongoUri, function(err, db) {\n        var coll = db.collection(conf.mongoCollectionName);\n        if (err) { throw err; }\n        cb({\n            message: function (channelName, content, cb) {\n                insert(coll, channelName, content, cb);\n            },\n            getMessages: function (channelName, msgHandler) {\n                getMessages(coll, channelName, msgHandler);\n            }            \n        });\n    });\n};\n"]}