{"_id":"@bogojob/mongofsmanager","_rev":"2-0c85355dd19c4aa39fd0742186b639f8","name":"@bogojob/mongofsmanager","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@bogojob/mongofsmanager","version":"1.0.0","main":"index.js","type":"module","publishConfig":{"registry":"https://registry.npmjs.org/"},"repository":{"type":"git","url":"git+https://registry.npmjs.org/bogojob/mongofsmanager.git"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1","start":"node server.js"},"author":{"name":"natale paolo santo stefano - bogojob@gmail.com"},"license":"MIT","dependencies":{"@bogojob/mongofsmanager":"github:bogojob/mongofsmanager","dotenv":"^14.3.2","mongoose":"^6.1.8"},"description":"file system manager based on mongodb document","keywords":["mongodb","filesystem","manager"],"gitHead":"9c47ae847b0d55c2fd5ad4df915e5ecb60a4b93a","_id":"@bogojob/mongofsmanager@1.0.0","_nodeVersion":"17.0.1","_npmVersion":"8.1.4","dist":{"integrity":"sha512-004tnDF/mrIAxF5V3lVhlMSqjMfLgISq4RKqCOET3HxG2BxtvcTOqGXVdB/TwdKADoS0GoyNG9KE/rudfxlkdQ==","shasum":"1194cf99a8952b0c9ee8bf291b0985c4c6423483","tarball":"https://registry.npmjs.org/@bogojob/mongofsmanager/-/mongofsmanager-1.0.0.tgz","fileCount":10,"unpackedSize":34307,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiLeGtACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrI6Q/7BPXphbZCthG0u4GM5k5J4nRilqNBm1up6nFO4Uoxj8NSnGiM\r\nONUFbrzjUow8VjnlymNe0BsusRDZ0Zo5oDn4m6eaihdghKoR76D7tHrT2VXm\r\nncMPB7Z2pGXZ/vrjQtl3T7/b99vpLDveMEpwodlBikANZcMKuyBAEKPqVjdA\r\nJZJNdk47a5n/A0sAlKsYtfmDAQuZc4YwcS/o9ERWfe4DD6Po/+oPU39uau4L\r\ndCK0/DmuyB9JMc5UNx8tm9pcANfXkxHm1uUJ7/jX43jUzuhtdCda5f8Qi5A4\r\nhKRkTOJqP58XCp0GxRvJhLaE9gkDYtAc5NoArB0FX55vD0KSbn19xJBxzkhh\r\n6ymOQRLxeR0R08toqKadrnP+XURTrCQ7wNd/dIX+KRYF1lwISdLf3jTeXqyD\r\nuzbLhGLF2NvYXJ/q8ThVlmpf/NA3WS+g5yYh4tnM5AWIWsjjUAWxwwXFjGy4\r\nAUACl/PceXo9gD5yhV7L+g7c9eKO8lwC+yjNkGYWM6YTG4uj9QQbheDPgSSd\r\nc7BGofcvcKi/OrY2e6g949DiiXS+RAFWo0CoRuEb9XPewYlRz1iD6poqHS9q\r\nWHWeqd/Jv3AhPuoD/DRwpAHHNvVeY89DkUPsXdROSHCuaTz4AcmEQjnV1hpM\r\nWLxmMzuRIJGsEeng98GVM2oF3WWwrCXie20=\r\n=FGk7\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICpSUbhiOs6yd3bx9d+g9zi9vcT77+yAjE3lBnsIgLKlAiB7g0mYL0fNxo4wG5EwtjRSwIfBrFruDk7r4FlHMkprwQ=="}]},"_npmUser":{"name":"bogojob","email":"bogojob@gmail.com"},"directories":{},"maintainers":[{"name":"bogojob","email":"bogojob@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongofsmanager_1.0.0_1647174060935_0.6157462938424918"},"_hasShrinkwrap":false},"1.0.1":{"name":"@bogojob/mongofsmanager","version":"1.0.1","main":"index.js","type":"module","publishConfig":{"registry":"https://registry.npmjs.org/"},"repository":{"type":"git","url":"git+https://registry.npmjs.org/bogojob/mongofsmanager.git"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1","start":"node server.js"},"author":{"name":"natale paolo santo stefano - bogojob@gmail.com"},"license":"MIT","dependencies":{"@bogojob/mongofsmanager":"github:bogojob/mongofsmanager","dotenv":"^14.3.2","mongoose":"^6.1.8"},"description":"file system manager based on mongodb document","keywords":["mongodb","filesystem","manager"],"gitHead":"723cdea72ce108ba1247420d17e91730a87ca5e8","_id":"@bogojob/mongofsmanager@1.0.1","_nodeVersion":"17.8.0","_npmVersion":"8.5.5","dist":{"integrity":"sha512-l+8uW79n9xL7WK09sF+/37suDgGOLZMgPJY9R7LM90qFINpj5C6iDKuJYsKWRDgEOW19AOHRmX9tGKhn9cWfjA==","shasum":"6d75c1a45a0125692856e1f8c78519b8e7f83bb7","tarball":"https://registry.npmjs.org/@bogojob/mongofsmanager/-/mongofsmanager-1.0.1.tgz","fileCount":10,"unpackedSize":35097,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiQxegACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoBYhAAo0M8rw5XxKXYV4a9nhnRr7CdIDS1RgGJ4hvVMtZLypJSjnNS\r\nrxfWNfZKNQilrkZ42cQPekc2eogh9uLsQHC6nrp6xqUDnPjQTkCMN5tdp4lp\r\nqeMolqt+CWN5hzbrIu641ZPT+3xid5gP13y+hM3VYdyQUGDvv5G8nps1WddN\r\noxMVfgPVnAjr8I+WBTXOAAf5qNUuKTuDXWMtUxXMdzxrMjJBN/jwr/GvEg4W\r\n052H9WV1JWiurBJm0+1q3MuxJwuSBjLdALV1R4V2ZqLT2O7W+iTHwdiVjvgm\r\nu3ojE8UMMP+BCGKIlTtVehqCkcMsV+yq/CWsVrxIi8iYbqu7WbdiJo2vTFcl\r\n54zFWKApopLB8Ql0q1CaKWzm+fK/VafT6KyB5Cfd+yuCq4mk5eEm5Mf8n/u6\r\nVyPEsKl7Ln8K6bC34Vv5sJjatG230zrXduNapuBeQIAdO1CSRgGz8HfA2dFr\r\nqDJfk4lCSUzoyXpg3iyguxVKMwkJOLT1aemrmUcJjWd7LOWdEjEo+3w89NdN\r\ngjC2i1poJYq8xT2lJCEM14N1SH8TyvFycXVBCc6AqzFnmyWdGfkMmurSyKHO\r\n5njKNCTIhH7Cy2yqLmpFjmzknencu9ui3g+UQ6B32nfLZmzy5CgOgbnOqUvx\r\nTtwFwpapvp9Pfdb6MVeg5A6A9gw4rktckJ4=\r\n=DDPY\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCErofQ3L5p7sk6zUJPYEjSw0oijd/oFF2yl41e42mrsQIgOLvJm6k1e+jBeRC+TpPK9m1VoIrHBbuk06ahprLv4p4="}]},"_npmUser":{"name":"bogojob","email":"bogojob@gmail.com"},"directories":{},"maintainers":[{"name":"bogojob","email":"bogojob@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongofsmanager_1.0.1_1648564128081_0.3081965654509635"},"_hasShrinkwrap":false}},"time":{"created":"2022-03-13T12:21:00.873Z","1.0.0":"2022-03-13T12:21:01.121Z","modified":"2022-04-04T19:58:51.639Z","1.0.1":"2022-03-29T14:28:48.411Z"},"maintainers":[{"name":"bogojob","email":"bogojob@gmail.com"}],"description":"file system manager based on mongodb document","keywords":["mongodb","filesystem","manager"],"repository":{"type":"git","url":"git+https://registry.npmjs.org/bogojob/mongofsmanager.git"},"author":{"name":"natale paolo santo stefano - bogojob@gmail.com"},"license":"MIT","readme":"# mongofsmanager\n\n## mongo filesystem manager\n\n**manages a filesystem based on mongodb document**\n\nThis library is designed to manage a filesystem type structure saved as a document within a mongodb database.\n\n## Structure\n\nof recursive tree type must have the following form:\n\n```json\n{\n  \"_id\": \"61b8645a684702c3180ac9bf\",\n  \"mail\": \"maymail@myprovider.com\",\n  \"firstname\": \"\",\n  \"lastname\": \"\",\n  \"size\": 200000,\n  \"filesystem\": {\n    \"nodes\": [\n      {\n        \"_id\": \"61bdca6e2aa6c5c6f4313450\",\n        \"name\": \"cities\",\n        \"type\": \"directory\",\n        \"mime\": \"\",\n        \"size\": 200000,\n        \"childs\": [\n          {\n            \"_id\": \"61f826088e67b91c1d492f4b\",\n            \"name\": \"IMG_20210906_105712.jpg\",\n            \"type\": \"file\",\n            \"mime\": \"image/jpeg\",\n            \"size\": 100000,\n            \"childs\": []\n          },\n          {\n            \"_id\": \"62264f13293942dd585a5d5b\",\n            \"name\": \"Venice\",\n            \"type\": \"directory\",\n            \"mime\": \"\",\n            \"size\": 100000,\n            \"childs\": [\n              {\n                \"_id\": \"622650c02caf5dffc8714d56\",\n                \"name\": \"Piazza San Marco\",\n                \"type\": \"file\",\n                \"mime\": \"image/jpeg\",\n                \"size\": 100000,\n                \"childs\": []\n              }\n            ]\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\nThe only mandatory fields are:\n\n1. \\_id \\<string\\>\n1. filesystem \\<object\\>\n1. nodes \\<array\\>\n1. type \\<string\\> values 'directory' \\| 'file'\n1. childs \\<array\\>\n1. size \\<number\\>\n\nwhich must respect the defined type.  \nAll other fields shown in the example can have other names and be of other types as they are not treated by the library functions.\n\nThe subdocuments contained in the _childs_ field in addition to containing **obligatorily** the _type_, _childs_, _size_ fields may contain other fields.\n\n\n## Available operations\n\nthe operations made available by the package, are the classic operations that are carried out on a filesystem that is: \n\n- insert a new node that can be a directory or a file in any point of the structure\n- move the node\n- delete the node\n\n\n*Note: In case the created node is of type _file_, it will be up to the developer to decide where and how to save the content.*\n\n\nNote: after each operation, all updates to the size fields of the affected nodes are made. This keeps the size of each filesystem directory consistent.\n\n## How to use\n\n**Mongodb [Schema](https://mongoosejs.com/docs/guide.html) example**\n\n\n\n```javascript\nimport mongoose from 'mongoose';\nconst nodeSchema = new mongoose.Schema(\n    {\n        _id: mongoose.Types.ObjectId,\n        name: String,\n        type: { type: String, enum: ['directory', 'file'], default: 'directory' },\n        mime: String,\n        size: Number,\n        childs: []\n       \n    });\n\nconst userSchema = new mongoose.Schema(\n    {\n        _id: mongoose.Types.ObjectId,\n        mail: { type: String, unique: true },\n        firstname: String,\n        lastname: String,\n        filesystem: { nodes: [nodeSchema], size: Number }\n    }\n);\n\nconst userModel = mongoose.model('user', userSchema);\nexport {\n    userModel\n   \n}\n```\n\n---\n\n\n### example for add operation\n\n```javascript\nimport { MongoFS as mongofs } from './MongoFS.js';\n/* import your mongodb model */\nimport { yourmodel } from './model.js'\nconst model = yourmodel;\n\n/* setting variables */\n/* document in mongodb on which crud operations will be done  */\nconst docid = \"61b8645a684702c3180ac9bf\";\n/* node to find: !! must be a directory type !!\nuse: 000000000000000000000000 for add a node into filesystem root */\nconst tofind = \"622650c02caf5dffc8714d56\";\n\n/* object node you want to add */\nconst payload = {\n    \"_id\": new mongoose.Types.ObjectId(),\n    \"name\": \"filename\",\n    \"type\": \"file\",\n    \"mime\": \"image/jpeg\",\n    \"size\": 100000,\n    \"childs\": []\n}\n\n\nlet mfs = undefined;\n\n/**prepare Mongodb connection**/\nmongoose.connect(path your mongodb,()=>{\n  console.log('mongodb connect: succefully ');\n (async () => {\n    try {\n        mfs = new mongofs({ tofind: tofind, docid: docid, model: model,payload:payload });\n        await mfs.init();\n        let n = await mfs.addfs();\n        console.log('node: ' + JSON.stringify(n));\n        process.exit(1);\n    } catch (error) {\n        console.log('error from class mongofs:' + error);\n        process.exit(0);\n    }\n})()\n})\n```\n---\n\n### example for remove operation\n\n```javascript\nimport { MongoFS as mongofs } from './MongoFS.js';\n/* import your mongodb model */\nimport { yourmodel } from './model.js'\nconst model = yourmodel;\n\n/* setting variables */\n/* document in mongodb on which crud operations will be done  */\nconst docid = \"61b8645a684702c3180ac9bf\";\n/* node to find e that must be removed */\nconst tofind = \"622650c02caf5dffc8714d56\";\n/* object node that you wont add */\nconst payload = {\n  \"_id\": new mongoose.Types.ObjectId(tofind)\n}\n\n\nlet mfs = undefined;\n\n/**prepare Mongodb connection**/\nmongoose.connect(path your mongodb,()=>{\n  console.log('mongodb connect: succefully ');\n (async () => {\n    try {\n        mfs = new mongofs({ tofind: tofind, docid: docid, model: model,payload:payload });\n        await mfs.init();\n        let n = await mfs.removefs();\n        console.log('node: ' + JSON.stringify(n));\n        process.exit(1);\n    } catch (error) {\n        console.log('error from class mongofs:' + error);\n        process.exit(0);\n    }\n})()\n\n})\n```\n---\n\n### example for move operation\n\n```javascript\nimport { MongoFS as mongofs } from './MongoFS.js';\n/* import your mongodb model */\nimport { yourmodel } from './model.js'\nconst model = yourmodel;\n\n/* setting variables */\n/* document in mongodb on which crud operations will be done  */\nconst docid = \"61b8645a684702c3180ac9bf\";\n/* node to find e that must be removed */\nconst tofind = \"622650c02caf5dffc8714d56\";\n/* tofind will moved into this node. !! todest must be directory type !! */\nconst todest = \"880be54e68a999c20a6b79c8\";\n\nlet mfs = undefined;\n\n/**prepare Mongodb connection**/\nmongoose.connect(path your mongodb,()=>{\n  console.log('mongodb connect: succefully ');\n (async () => {\n    try {\n        mfs = new mongofs({ tofind: tofind, todest:todest,docid: docid, model: model });\n        await mfs.init();\n        let n = await mfs.movefs();\n        console.log('node: ' + JSON.stringify(n));\n        process.exit(1);\n    } catch (error) {\n        console.log('error from class mongofs:' + error);\n        process.exit(0);\n    }\n})()\n\n})\n```\n\n---\n\n### table of options ###\n\n| options | meaning |\n| ------ | ------ |\n| tofind  | node subjected to operation |\n| todest | node of type directory that will receive another node in its childs field. Valid for move operation only. |\n| docid  | id which identifies the document in the mongodb and which contains the filesystem on which to operate |\n| model  | Mongo db Model Schema |\n| payload | this is an element that changes depending on the type of operation. (see examples)It is always an object. It is not present in the case of move |\n\n\n","readmeFilename":"README.md"}