{"_id":"@alonsojr1980/mongoose-generator","_rev":"5-264e6825d5fff8c9a070cc2388cfaeb0","name":"@alonsojr1980/mongoose-generator","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.2":{"name":"@alonsojr1980/mongoose-generator","version":"1.0.2","description":"Easy to use sequencial ID generator for Mongoose","main":"index.js","scripts":{"test":"mocha ./test/tests.js","debug-test":"node ./test/manual.js "},"repository":{"type":"git","url":"git+https://github.com/alonsojr1980/mongoose-generator.git"},"keywords":["mongoose","gen_id","sequential","id","mongo"],"author":{"name":"Alonso Júnior","email":"alonsorsjunior@gmail","url":"www.alonsojr.com.br"},"license":"MIT","bugs":{"url":"https://github.com/alonsojr1980/mongoose-generator/issues"},"homepage":"https://github.com/alonsojr1980/mongoose-generator#readme","devDependencies":{"mongoose":"^5.5.7"},"gitHead":"9b3a760f7434182e0bae584bc4ddc47d68a42d72","_id":"@alonsojr1980/mongoose-generator@1.0.2","_npmVersion":"6.4.1","_nodeVersion":"10.11.0","_npmUser":{"name":"alonsojr1980","email":"alonsorsjunior@gmail.com"},"dist":{"integrity":"sha512-wdWt8Q/uFli6hLtubm+dtDWe5lKfwoQI1fMqkOKKkO5wr0hDcf/fVJJiDGuP/5aNvitIYUn3rT93lnaHWvzfmg==","shasum":"2a36983eb4a980321a41755889ea56bed2254607","tarball":"https://registry.npmjs.org/@alonsojr1980/mongoose-generator/-/mongoose-generator-1.0.2.tgz","fileCount":6,"unpackedSize":9922,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc1xpQCRA9TVsSAnZWagAATDcP/RvAAWqslc3ikTg57VA+\nz+qjQVdXfSPsuMFwO7L6ZsW6xnd2WodfogNDKOrPwKXF4SKByPYHjz+9J7kC\nSl/1/0NbDb9i6yCRQpzQ9r4osvQKlEI0chf7tFmP8Y0QuR++p9AaOKDjbLfX\n5who46DqyFupbenCGL3CRiG8STCNVNGsilaq5bKSS/oGuCXOFniBZKluTEmH\n4evyBFYEFGKHXL+/3bkiQAzBppDuc2TDlKLz8l2qr11NMIwCNBgbvmhCE5oI\nMdDfI2zBepkkWbZp8hJ3qJxaASRD06u+GqqWsfFR3tJUhfv5B/SId/IVHX7E\neVMEMDBOfjcRPiWUsoxpXPR7v4xfNIRygRET3ENj3uVrFYizSc+wIj2Vu1dW\ntTyWYpDe0fEM9iVdkIsBgVdVfakwCib9k6aLK1/ue0ncGSiQBfDNX5blVjaf\n6+UhDjo5NYOBGq4EHWO873YoB7TgMc24jCirCODr5V5KYNlTEJaXMJTv6AB6\nlhKOyr5gAb9PGhNkiMnPJR9Hj231jcAmYP1WmObcu+LJ583OWQgNREqBV/7T\nVbiz0SKIdA/ASOfVLnR5V6+E3CfAZSpqzyzHikLoBDLQSQ124I/jwHp7uY/9\n3ZNlqjeyMi+O9eEObNh43wT3CifK7N78kxoKLaB+gD1rom96WRDs7A0gYcp7\ngY0j\r\n=lqwV\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCFDlY5YAMmIPYm984hkynfAZ5E/1+kvs7pCaHgmnXRqgIgOJoLmmPXWm/5AzHjMHovTc9lhFptNr3u7c/MY+dK41I="}]},"maintainers":[{"name":"alonsojr1980","email":"alonsorsjunior@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongoose-generator_1.0.2_1557600847817_0.7394350199938409"},"_hasShrinkwrap":false,"deprecated":"this version has bug, please update"},"1.0.3":{"name":"@alonsojr1980/mongoose-generator","version":"1.0.3","description":"Easy to use sequencial ID generator for Mongoose","main":"index.js","scripts":{"test":"mocha ./test/tests.js","debug-test":"node ./test/manual.js "},"repository":{"type":"git","url":"git+https://github.com/alonsojr1980/mongoose-generator.git"},"keywords":["mongoose","gen_id","sequential","id","mongo"],"author":{"name":"Alonso Júnior","email":"alonsorsjunior@gmail","url":"www.alonsojr.com.br"},"license":"MIT","bugs":{"url":"https://github.com/alonsojr1980/mongoose-generator/issues"},"homepage":"https://github.com/alonsojr1980/mongoose-generator#readme","devDependencies":{"mongoose":"^5.5.7"},"gitHead":"9b3a760f7434182e0bae584bc4ddc47d68a42d72","_id":"@alonsojr1980/mongoose-generator@1.0.3","_npmVersion":"6.4.1","_nodeVersion":"10.11.0","_npmUser":{"name":"alonsojr1980","email":"alonsorsjunior@gmail.com"},"dist":{"integrity":"sha512-H42Usetev3rv6d2IW579T6JzqALHGmRT4UyYqAobMyHD7Z6iqs0iFCN/HMd8S1pAtj0CDEj6juJ96ll471Tgew==","shasum":"c993ad514689ef99b4b9cb154429c9d4675dcd76","tarball":"https://registry.npmjs.org/@alonsojr1980/mongoose-generator/-/mongoose-generator-1.0.3.tgz","fileCount":6,"unpackedSize":10049,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc3GQsCRA9TVsSAnZWagAAi+MQAI5lfEbWN8190/L8qGFD\nBipJbE1CxypbfJto6AWrz7ridK33jWwVIbPe4tq9h2s9E1xodkPhHnJRmjxm\nW8CNcwmQIJfNLc0K6T0TS7+30kBVtMLIihKu+HeI3aiVmRZNkeJyDxXoKBzr\nMLrP/bvpD1xKP48fyBzT72f7bEHlJ5Dfo3j7tmR1FGkh0jq5NYZqIo2+2NJy\nrD8A0ilYBT3apINuqMGcyKtMUpOG8dCEszO3q1KrlSo1i+Przqzzb3h+uM23\nfNmYSFwUYicqW+xFlsQIzGoO3ELNahSvu1DFmucBafLTodAcxXygOxQpT4v1\naY2GwzIwIkn3jEmPyC24xqHhiGNrjg4F2GHzOfNA5s73MOf97a9llkORBX98\nnP8A9qzVzQuYswEOH/m7ptY5tVcqDFgvXjWP3vb+vt44xcHU0rDJtkRfSIwB\nKpSWFvbhx2R111acIjRi1SuYKvhmrRTHK69nYpIpK7xkvesyQ+NM9NVZIlU3\nB/87GPk7Z0jarVXAHiVjxhDozf9rzKxW4YDQei0W+fxu5kC9CVBd3w2dQRMm\niQykI1rjhDhqbqAn+t8EMGIWkgiutMdu7DhPMk3s0xygrnQC8nMCSnqux6sY\nWNsN1hGfuz/uFLwcXDxeeFwlIYGlybCF2erR7l3mZs4zrLe2JXiBpMLXU48E\n4vJi\r\n=ANZr\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC9uyXV16Wgvy4K9RCWU4jgJETj6wL3NIEELi5bT5x1OgIhAMphkxounNMz1+myxPHaMDm9cvCIrmKlndmzx0a6PCWg"}]},"maintainers":[{"name":"alonsojr1980","email":"alonsorsjunior@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongoose-generator_1.0.3_1557947435785_0.07380827020740277"},"_hasShrinkwrap":false}},"time":{"created":"2019-05-11T18:15:21.288Z","1.0.0":"2019-05-11T18:15:21.420Z","modified":"2022-04-04T13:37:02.249Z","1.0.2":"2019-05-11T18:54:07.938Z","1.0.3":"2019-05-15T19:10:35.935Z"},"maintainers":[{"name":"alonsojr1980","email":"alonsorsjunior@gmail.com"}],"description":"Easy to use sequencial ID generator for Mongoose","homepage":"https://github.com/alonsojr1980/mongoose-generator#readme","keywords":["mongoose","gen_id","sequential","id","mongo"],"repository":{"type":"git","url":"git+https://github.com/alonsojr1980/mongoose-generator.git"},"author":{"name":"Alonso Júnior","email":"alonsorsjunior@gmail","url":"www.alonsojr.com.br"},"bugs":{"url":"https://github.com/alonsojr1980/mongoose-generator/issues"},"license":"MIT","readme":"![alonso jr](https://img.shields.io/badge/Alonso%20Jr.-www.alonsojr.com.br-crimson.svg)\n\n# @alonsojr1980/mongoose-generator\nPlugin for generating sequential field values. It adds a `pre('save')` hook to the attached schema and some useful [static methods](#static-methods).\n\n\n## Basic usage example\n\n```javascript\nconst Generator = require('@alonsojr1980/mongoose-generator');\nconst mongoose = require('mongoose');                \n\nconst UserSchema = new mongoose.Schema({\n    name: String,\n    age: Number\n});\n\nconst nameOfTheGenerator = 'users';\nUserSchema.plugin(Generator, nameOfTheGenerator);\n\nconst model = mongoose.model('User', UserSchema);\nconst user1 = model({name: \"ALONSO\"});\nuser1.save(() => {\n    console.log(user1._id); //outputs 1\n});\n```\n>> The following document will be added to a collection named **generators**:\n**{\"name\": \"users\", \"sequence\": 1}**\n\n## Default plugin options\n```javascript\nconst pluginOptions = {\n    collection: \"generators\", // name of the collection that'll hold generator docs\n    name: undefined, // name of the doc in the generators' collection\n    startAt: 100, // first sequence value, when the generator is created and saved or reseted with gen_id_reset()\n    increment: 1, // increment of the generator\n    field: \"_id\" // field of the model that'll receive the generator's sequence\n}\n```\n## Custom options example\n\n```javascript\nconst BusSchema = new mongoose.Schema({\n    sequentialNumber: Number,\n    licensePlate: String\n});\n\nconst pluginOptions = {\n    collection: \"generators\", \n    name: \"buses\",\n    startAt: 100,\n    increment: 1,\n    field: \"sequentialNumber\"\n}\n\nBusSchema.plugin(Generator, pluginOptions);\n\nconst model = mongoose.model('Bus', BusSchema);\nconst bus1 = model({licensePlate: \"BUS-7777\"});\n\nbus1.save(() => {\n    console.log(bus1.sequentialNumber); //outputs 101\n});\n```\n>> The following document will be added to a collection named **generators**: <br>\n**{\"name\": \"buses\", \"sequence\": 101}**\n\n## Static methods added to the model <a id=\"static-methods\"></a>\n```javascript\n// returns the current sequence value\ncurrentSequence((err, sequence) => {});\n\n// resets the sequence to the startAt value passed in the options object\n// or to 0 (default value). Beware of existing documents with that sequence!\ngen_id_reset((err, sequence) => {})\n```\n>> Remember that static methods are called in the model, not in the document instance.\n\n## Static methods usage example\n```javascript\nconst BusSchema = new mongoose.Schema({\n    sequentialNumber: Number,\n    licensePlate: String\n});\n\nconst pluginOptions = {\n    name: \"buses\",\n    startAt: 0\n}\n\nBusSchema.plugin(Generator, pluginOptions);\n\nconst model = mongoose.model('Bus', BusSchema);\nmodel.gen_id_reset((err, seq) => {\n    console.log(seq); //outputs 0\n});\n```","readmeFilename":"readme.md"}