{"_id":"@codestra/next-serverless-mongoose","_rev":"5-2768bb36cd4707e0650b26587222e2b8","name":"@codestra/next-serverless-mongoose","dist-tags":{"latest":"1.2.0"},"versions":{"1.1.3":{"name":"@codestra/next-serverless-mongoose","version":"1.1.3","description":"Mongoose helper functions to connect with mongodb in nextjs api-routes","main":"lib/index.js","scripts":{"test":"jest --config jestconfig.json","test:dev":"jest --config jestconfig.dev.json --watch","build":"tsc","format":"prettier --write \"src/**/*.ts\" \"src/**/*.js\"","lint":"tslint -p tsconfig.json","prepare":"npm run build","prepublishOnly":"npm test && npm run lint","preversion":"npm run lint","version":"npm run format && git add -A src","postversion":"git push && git push --tags","dev":"tsc --watch"},"repository":{"type":"git","url":"git+https://github.com/codestra/next-serverless-mongoose.git"},"keywords":["mongoose","next"],"author":{"name":"codestra"},"license":"MIT","bugs":{"url":"https://github.com/codestra/next-serverless-mongoose/issues"},"homepage":"https://github.com/codestra/next-serverless-mongoose#readme","devDependencies":{"@types/jest":"^26.0.24","codecov":"^3.1.0","jest":"^27.0.6","prettier":"^2.3.2","ts-jest":"^27.0.4","tslint-config-prettier":"^1.18.0","typescript":"^4.3.5"},"dependencies":{"@babel/preset-env":"^7.14.8","@types/react":"^17.0.15","@types/react-dom":"^17.0.9","babel-jest":"^27.0.6","dotenv":"^10.0.0","mongodb-client-encryption":"^1.2.6","mongodb-memory-server":"^7.3.2","mongoose":"^5.13.3","next":"^11.0.1","tslint":"^6.1.3"},"publishConfig":{"@codestra:registry":"https://npm.pkg.github.com"},"_id":"@codestra/next-serverless-mongoose@1.1.3","dist":{"shasum":"371a8f58e17c25f67402ceb81ed16e716f96b6fc","integrity":"sha512-HKV1HIkbf9EoAVpRerEjkqIkGQFtffVDZELc+R8tIgbL0HKRB81DdxqkL6yb0Vdozkw0HOX8xURNh92yvmLW0w==","tarball":"https://registry.npmjs.org/@codestra/next-serverless-mongoose/-/next-serverless-mongoose-1.1.3.tgz","fileCount":12,"unpackedSize":17699,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhD9pcCRA9TVsSAnZWagAAUk0P/11Vq6PweB6ejM7EUQsP\nseRksamKLHLYYu6GDreXvjQ/QTfUSnXbkk5fRv8jNAerAqah7nI71wSFQQIe\nGa4mZUSpJi6oP6eUxB6sJ5pUjBbTvdwPVtrFaxEOgkTqVuUZrXW48DVlkqYA\nyXcGeRqoVejr94SN5OAcqmsSGdBqFMDLUcBeos0OPvGvY1LzS8FVkuTToX4y\n9RUNHw2P/RA+flYNTWTfCu6mEgQnC+HD1MJIflwJ4Dx8i39JbEMgA32gBJ6S\nR8XzzDsTIdYILg2KuMKsCwBNlpFGral5pOzD2ugBRLvkhZFqCQmkLmHbATp8\nZ3guWTRyUlcq2gdYyfqX/9mTTxxy8brdKlqygzu/O9aYSdYqxksjn7hSAMmA\nlxrwuKoPephscLr3AI8oPi5Bwzq2P8Hrcd9pE/nRuACF6xyoTgvu+70WshNt\n+nzcqSrv2Mo2yNZxs/cHGPGQ53ruaBu6wyOjo8QZQU8G/K7bZqGp16Q9gFdn\n1rC+m2rfW2HuCQHpNSXkKUqoKbu3MR3InTWi8i8cV1frxbUi4YLdBUu7UAqk\n1Cuk/LszWN2FsZDbPIVGORrTn1pAVqf975DlN8GoKPxNPUhHuDGDDP6mrdMO\nu+hYH+cYegOAZpEdKJYNwbGmBolFnvlqpObyaL4TzvGtQNJugIWhdZt2Zwmf\nBn1V\r\n=zveI\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDASb0EXefCmukVAVkSmbZu8gVc4rqUetS+9xgjyETN+wIgVY2joaUiKt5yrTxznb4369Dd+uw/l83L77RA+LwSdH4="}]},"_npmUser":{"name":"sajadghawami","email":"sajad.ghawami@codestra.io"},"directories":{},"maintainers":[{"name":"sajadghawami","email":"sajad.ghawami@codestra.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/next-serverless-mongoose_1.1.3_1628428891987_0.0027692263035035136"},"_hasShrinkwrap":false},"1.1.5":{"name":"@codestra/next-serverless-mongoose","version":"1.1.5","description":"Mongoose helper functions to connect with mongodb in nextjs api-routes","main":"lib/index.js","scripts":{"test":"jest --config jestconfig.json","test:dev":"jest --config jestconfig.dev.json --watch","build":"tsc","format":"prettier --write \"src/**/*.ts\"","lint":"tslint -p tsconfig.json","prepare":"npm run build","prepublishOnly":"npm test && npm run lint","preversion":"npm run lint","version":"npm run format && git add -A src","postversion":"git push && git push --tags","dev":"tsc --watch"},"repository":{"type":"git","url":"git+https://github.com/codestra/next-serverless-mongoose.git"},"keywords":["mongoose","next"],"author":{"name":"codestra"},"license":"MIT","bugs":{"url":"https://github.com/codestra/next-serverless-mongoose/issues"},"homepage":"https://github.com/codestra/next-serverless-mongoose#readme","devDependencies":{"@types/jest":"^26.0.24","codecov":"^3.1.0","jest":"^27.0.6","prettier":"^2.3.2","ts-jest":"^27.0.4","tslint-config-prettier":"^1.18.0","typescript":"^4.3.5"},"dependencies":{"@babel/preset-env":"^7.14.8","@types/react":"^17.0.15","@types/react-dom":"^17.0.9","babel-jest":"^27.0.6","dotenv":"^10.0.0","mongodb-client-encryption":"^1.2.6","mongodb-memory-server":"^7.3.2","mongoose":"^5.13.3","next":"^11.0.1","tslint":"^6.1.3"},"publishConfig":{"@codestra:registry":"https://npm.pkg.github.com"},"_id":"@codestra/next-serverless-mongoose@1.1.5","dist":{"shasum":"059ec096594db6359f001e8efedf82a889241a62","integrity":"sha512-HoeC160TvNBEP8j/J9zAaQaVZsTKrP7+xBrBiIy0LkPT4DResXaA1JQVwMEsmoBKH4fd/sQtSDou8H/fKUIHDg==","tarball":"https://registry.npmjs.org/@codestra/next-serverless-mongoose/-/next-serverless-mongoose-1.1.5.tgz","fileCount":12,"unpackedSize":17731,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCOBCMy5EhtsG0RN2wz4K8rTSqB4uiFWSA7VJrlJE2zhAIhAIxynLAp2BpjbpfthBNe/uSIGH96aOtNJGs3q2xPjzv3"}]},"_npmUser":{"name":"sajadghawami","email":"sajad.ghawami@codestra.io"},"directories":{},"maintainers":[{"name":"sajadghawami","email":"sajad.ghawami@codestra.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/next-serverless-mongoose_1.1.5_1632242725437_0.9063108467598602"},"_hasShrinkwrap":false},"1.1.6":{"name":"@codestra/next-serverless-mongoose","version":"1.1.6","description":"Mongoose helper functions to connect with mongodb in nextjs api-routes","main":"lib/index.js","scripts":{"test":"jest --config jestconfig.json","test:dev":"jest --config jestconfig.dev.json --watch","build":"tsc","format":"prettier --write \"src/**/*.ts\"","lint":"tslint -p tsconfig.json","prepare":"npm run build","prepublishOnly":"npm test && npm run lint","preversion":"npm run lint","version":"npm run format && git add -A src","postversion":"git push && git push --tags","dev":"tsc --watch"},"repository":{"type":"git","url":"git+https://github.com/codestra/next-serverless-mongoose.git"},"keywords":["mongoose","next"],"author":{"name":"codestra"},"license":"MIT","bugs":{"url":"https://github.com/codestra/next-serverless-mongoose/issues"},"homepage":"https://github.com/codestra/next-serverless-mongoose#readme","devDependencies":{"@types/jest":"^26.0.24","codecov":"^3.1.0","jest":"^27.0.6","prettier":"^2.3.2","ts-jest":"^27.0.4","tslint-config-prettier":"^1.18.0","typescript":"^4.3.5"},"dependencies":{"@babel/preset-env":"^7.14.8","@types/react":"^17.0.15","@types/react-dom":"^17.0.9","babel-jest":"^27.0.6","dotenv":"^10.0.0","mongodb-client-encryption":"^1.2.6","mongodb-memory-server":"^7.3.2","mongoose":"^5.13.3","next":"^11.0.1","tslint":"^6.1.3"},"publishConfig":{"@codestra:registry":"https://npm.pkg.github.com"},"_id":"@codestra/next-serverless-mongoose@1.1.6","dist":{"shasum":"b32f2a39bdc576e23102d2bf0f5ca179923f1f6f","integrity":"sha512-2FQYoPyYjpdhWehU6Zp8biIzX5t4EaGj10m2J7Wqt3fU5RSMrhVSdJ7E358povAkecR1te8yNSRWGoE3SQa0NQ==","tarball":"https://registry.npmjs.org/@codestra/next-serverless-mongoose/-/next-serverless-mongoose-1.1.6.tgz","fileCount":12,"unpackedSize":17593,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCzuqoBwL98Gxbyyu7FBAaWqYkmnF9Ym5uosgMENsZOoAIgYuD9KnzvlBwpL/YG/1JcZVTpPPe5HKWzLe17x34fCBI="}]},"_npmUser":{"name":"sajadghawami","email":"sajad.ghawami@codestra.io"},"directories":{},"maintainers":[{"name":"sajadghawami","email":"sajad.ghawami@codestra.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/next-serverless-mongoose_1.1.6_1632248340480_0.550312385089966"},"_hasShrinkwrap":false},"1.2.0":{"name":"@codestra/next-serverless-mongoose","version":"1.2.0","description":"Mongoose helper functions to connect with mongodb in nextjs api-routes","main":"lib/index.js","scripts":{"test":"jest --config jestconfig.json","test:dev":"jest --config jestconfig.dev.json --watch","build":"tsc","format":"prettier --write \"src/**/*.ts\"","lint":"tslint -p tsconfig.json","prepare":"npm run build","prepublishOnly":"npm test && npm run lint","preversion":"npm run lint","version":"npm run format && git add -A src","postversion":"git push && git push --tags","dev":"tsc --watch"},"repository":{"type":"git","url":"git+https://github.com/codestra/next-serverless-mongoose.git"},"keywords":["mongoose","next"],"author":{"name":"codestra"},"license":"MIT","bugs":{"url":"https://github.com/codestra/next-serverless-mongoose/issues"},"homepage":"https://github.com/codestra/next-serverless-mongoose#readme","devDependencies":{"@types/jest":"^26.0.24","codecov":"^3.1.0","jest":"^27.0.6","prettier":"^2.3.2","ts-jest":"^27.0.4","tslint-config-prettier":"^1.18.0","typescript":"^4.3.5"},"dependencies":{"@babel/preset-env":"^7.14.8","@types/react":"^17.0.15","@types/react-dom":"^17.0.9","babel-jest":"^27.0.6","dotenv":"^10.0.0","mongodb-client-encryption":"^1.2.6","mongodb-memory-server":"^7.3.2","mongoose":"^6.0.7","next":"^11.0.1","tslint":"^6.1.3"},"publishConfig":{"@codestra:registry":"https://npm.pkg.github.com"},"_id":"@codestra/next-serverless-mongoose@1.2.0","dist":{"shasum":"2c8a8e03992296323af8e65bf347d527fc57179f","integrity":"sha512-n8a92ausrUBiQM7dweM8Rj8ISSGT1qa8AOnxfPo/iou9rJXPbY+lJ47PQU+qec6bCZ0yBvRzhNHGslzi2iG05g==","tarball":"https://registry.npmjs.org/@codestra/next-serverless-mongoose/-/next-serverless-mongoose-1.2.0.tgz","fileCount":12,"unpackedSize":17592,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhzdMUCRA9TVsSAnZWagAAQVsQAJGTiwnaZGY9ESCSXiEY\nlREIJYHvLMdtKL01Obj1SHnFYYuNM9rK+qV50kuHp4HDKmGrV0W692WO6JvF\nbU1911nymT3rZi/8/bmOh/D9lF9imVf+cYgzyt8qC6jM0pRpVFtxyMCE1UuP\nNlsYGsejDAaKNRY7oDleEDzOvYgymLDgpwThcqSkSFo01RTCtyQf8mDCmOrt\nklvgzZAaVJwJgkLtf2b5zqxyMpzM/xRVxFvcWhigXqhR9patIYDVjg4TxQLd\n3rw+2IEvq7Xi/53n5WxpUxoRlOLJfK2+/oaTtQdfLPmAsrsLvXgfLzfKLezh\npHZI3+FNKCG18Psx34F2rok6MEiRyqr57T1uoB1Wg4JmsIa1ArGBCM1NcAOJ\n7VWPZIfeNqNwG3KjsdqThiRLlVUjdgES9R/sKm8UmjvqQCMSLVj08XGjxmeK\nyK9y74sBEzXfaqh+D0RgCX9gSjcFYyEyLh7NW1xAEk3UMyem9IMEVMNp5beJ\nSFQJW8enDdWwu0XEZ2Y/N8AfOnAqkChxHGCq3z46NGMncXF2qG7mG5Gl3rby\ngMtJwYepC7d3lF5iKirnlorAEKBWEI5DHah6NSC6jY/C1WNLwomxpF+sX95n\n5yzUmDhxI+i0TS/oOXuwlwgvj2CrESikqzy75iEpwcoHMVDAgN8XuLEw6MXH\nuZ3t\r\n=Mrzv\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHaOwuOwyC2YxAqjELv1gxYn6w7Cu+E97lQrjtrpUc3HAiB/QAV1DO5IpeIXAmABRZBN0+sBXgSc4RZ2hv0JrfqgYA=="}]},"_npmUser":{"name":"sajadghawami","email":"sajad.ghawami@codestra.io"},"directories":{},"maintainers":[{"name":"sajadghawami","email":"sajad.ghawami@codestra.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/next-serverless-mongoose_1.2.0_1632394455662_0.6222559102487848"},"_hasShrinkwrap":false}},"time":{"created":"2021-08-08T13:21:31.922Z","1.1.3":"2021-08-08T13:21:32.142Z","modified":"2022-04-05T00:06:45.377Z","1.1.5":"2021-09-21T16:45:25.616Z","1.1.6":"2021-09-21T18:19:00.649Z","1.2.0":"2021-09-23T10:54:15.828Z"},"maintainers":[{"name":"sajadghawami","email":"sajad.ghawami@codestra.io"}],"description":"Mongoose helper functions to connect with mongodb in nextjs api-routes","homepage":"https://github.com/codestra/next-serverless-mongoose#readme","keywords":["mongoose","next"],"repository":{"type":"git","url":"git+https://github.com/codestra/next-serverless-mongoose.git"},"author":{"name":"codestra"},"bugs":{"url":"https://github.com/codestra/next-serverless-mongoose/issues"},"license":"MIT","readme":"# next-serverless-mongoose\n\nnext-serverless-mongoose is a package that provides helper functions to easily connect with a mongodb. This package was mainly build for usage with nextjs-api-routes and mongoose.\n\n## Installation\n\nUse [npm](https://nodejs.org/en/download/) for installation:\n\n```bash\nnpm install @codestra/next-serverless-mongoose\n```\n\nOr use [yarn](https://yarnpkg.com/) for installation:\n\n```bash\nyarn add @codestra/next-serverless-mongoose\n```\n\n## Usage\n\nThis package provides currently two functions to deal with a mongodb connection.\nBoth these function assume that you have set one of the two following alternatives in your `.env.local` file:\n\n```bash\nMONGODB_URI=example-uri.com\n```\n\nOr the following:\n\n```bash\nMONGODB_HOST=example-host\nMONGODB_DATABASE_NAME=example-database-name\n```\n\nIf one of these two alternatives have been set, the following functions will automagically make sure that you have a running mongodb-connection and you will be able to do your operations.\n\nFor the authentication, you can set the following:\n\n```bash\nMONGODB_USER=example-user\nMONGODB_PASS=example-password\n```\n\n### useMongoose\n\nThe `useMongoose` function has to be called before any other mongoose operation in the api-route. It will automatically connect to the mongodb with the provided details from the environment.\n\nExample:\n\n```javascript\nimport { NextApiRequest, NextApiResponse } from 'next';\nimport { useMongoose } from '@codestra/next-serverless-mongoose';\nimport User from '../../models/User';\n\nconst handler = async (req: NextApiRequest, res: NextApiResponse) => {\n  const mongoose = await useMongoose();\n  console.log(mongoose.connection.readyState);\n  // returns 1: connected\n\n  await User.create({\n    name: 'Name',\n  });\n\n  res.status(200).json({ message: 'created user' });\n};\n\nexport default handler;\n```\n\n### withMongoose\n\nThe `withMongoose` function acts as a wrapper around the `handle` function of the api-route. It also makes sure that you have a running mongodb-connection based on the environment variables. This function will alter the `request` from `nextjs` and add a `mongoose` field.\nAt this point you will be able to call any other mongoose function as long as you have wrapped the `handler` with it.\n\nExample:\n\n```javascript\nimport { NextApiResponse } from 'next';\nimport { withMongoose, NextApiRequestWithMongoose } from '@codestra/next-serverless-mongoose';\nimport User from '../../models/User';\n\nconst handler = async (req: NextApiRequestWithMongoose, res: NextApiResponse) => {\n  console.log(req.mongoose.connection.readyState);\n  // returns 1: connected\n\n  await User.create({\n    name: 'Name',\n  });\n\n  res.status(200).json({ message: 'created user' });\n};\n\nexport default withMongoose(handler);\n```\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## Credits and Inspiration\n\n- [nextjs with-mongoose example](https://github.com/vercel/next.js/tree/canary/examples/with-mongodb-mongoose)\n- [nextjs middleware](https://hoangvvo.com/blog/nextjs-middleware)\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","readmeFilename":"README.md"}