{"_id":"@camilaprav/peacock","_rev":"5-d1549d5d5c979622580dd92e32f8a33f","name":"@camilaprav/peacock","dist-tags":{"latest":"0.0.4"},"versions":{"0.0.0":{"name":"@camilaprav/peacock","version":"0.0.0","author":{"name":"Camila Prá"},"license":"AGPL-3.0-or-later","_id":"@camilaprav/peacock@0.0.0","maintainers":[{"name":"camilaprav","email":"camila@guiprav.com"}],"homepage":"https://github.com/camilaprav/peacock#readme","bugs":{"url":"https://github.com/camilaprav/peacock/issues"},"dist":{"shasum":"97ecdb88d55bfff0fafaa935d60d39e0ad087a16","tarball":"https://registry.npmjs.org/@camilaprav/peacock/-/peacock-0.0.0.tgz","fileCount":10,"integrity":"sha512-nuyq3AiYyM/Vdzj4KODdwlsuKO2Hho7yFouF+Qv4guVsF3g+ebwIPZZXClMVzkyCXWGSdcCSwILKJNU0FjTGHQ==","signatures":[{"sig":"MEQCIFrfCZ4yXNVcIDOJm7v9x99fWy2aKpdKYPJGLuDSCh0mAiAbj0/49Tam6QSPitIQJ0ypKk3+G4Gv8Dhf/TuF10qFcw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":56230},"type":"module","browser":"peacock.browser.js","gitHead":"700d3a0835c84e29338cf2beea8a5410328e65cf","scripts":{"build":"./build.sh","start":"node server.js"},"_npmUser":{"name":"camilaprav","email":"camila@guiprav.com"},"repository":{"url":"git+https://github.com/camilaprav/peacock.git","type":"git"},"_npmVersion":"9.7.2","description":"Isomorphic document database, file hosting, and mail sending","directories":{},"_nodeVersion":"20.4.0","dependencies":{"cors":"^2.8.5","busboy":"^1.6.0","mkdirp":"^3.0.1","express":"^5.1.0","@seald-io/nedb":"^4.1.1"},"_hasShrinkwrap":false,"devDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/peacock_0.0.0_1744581017845_0.08238990836223081","host":"s3://npm-registry-packages-npm-production"}},"0.0.1":{"name":"@camilaprav/peacock","version":"0.0.1","author":{"name":"Camila Prá"},"license":"AGPL-3.0-or-later","_id":"@camilaprav/peacock@0.0.1","maintainers":[{"name":"camilaprav","email":"camila@guiprav.com"}],"homepage":"https://github.com/camilaprav/peacock#readme","bugs":{"url":"https://github.com/camilaprav/peacock/issues"},"dist":{"shasum":"29af39997e150c1a57aaf26dfc0f127dbd51f868","tarball":"https://registry.npmjs.org/@camilaprav/peacock/-/peacock-0.0.1.tgz","fileCount":10,"integrity":"sha512-eyoeeCPLwh87/ChirJD7I5LLt/v8QtC7GEQU3DzZHaQxeetuQfBrwjxA+nD8HWvYm+Cqp0yy7eTySNLHF31utQ==","signatures":[{"sig":"MEQCICHtsg+cVEfZYH6ImiAcwfFSWdD5bM6IjYmDAfrDt+l4AiAwBEWiyjm9SHiQ0DhW2VidXdqxWto5+K5SxF0nqcJLPw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":56230},"type":"module","browser":"peacock.browser.js","gitHead":"bb04c736e7234373ad3b1ed4522639b29256bb88","scripts":{"build":"./build.sh","start":"node server.js"},"_npmUser":{"name":"camilaprav","email":"camila@guiprav.com"},"repository":{"url":"git+https://github.com/camilaprav/peacock.git","type":"git"},"_npmVersion":"9.7.2","description":"Isomorphic document database, file hosting, and mail sending","directories":{},"_nodeVersion":"20.4.0","dependencies":{"cors":"^2.8.5","busboy":"^1.6.0","mkdirp":"^3.0.1","express":"^5.1.0","@seald-io/nedb":"^4.1.1"},"_hasShrinkwrap":false,"devDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/peacock_0.0.1_1744581173157_0.9337775045402177","host":"s3://npm-registry-packages-npm-production"}},"0.0.2":{"name":"@camilaprav/peacock","version":"0.0.2","author":{"name":"Camila Prá"},"license":"AGPL-3.0-or-later","_id":"@camilaprav/peacock@0.0.2","maintainers":[{"name":"camilaprav","email":"camila@guiprav.com"}],"homepage":"https://github.com/camilaprav/peacock#readme","bugs":{"url":"https://github.com/camilaprav/peacock/issues"},"dist":{"shasum":"a7f590f2550bad5e2de19fc398b8e18f35ddba06","tarball":"https://registry.npmjs.org/@camilaprav/peacock/-/peacock-0.0.2.tgz","fileCount":10,"integrity":"sha512-EBDxeISB9I8/U6vkJdwqrpoIFk+NkMo3VzO//SMr5B0XRyCXDrSWkR5I0rD+grHZPjRAODkBJ2lX649byjs1Lg==","signatures":[{"sig":"MEUCIFOsYXlvX6ocSEGy112Nm8vIyFFzyG1i6d3ucMSdizpqAiEA2uNxPCIN5IwXs1PsdcgpVpyvl5YenOz4po7RcO/tTS8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":55734},"type":"module","browser":"peacock.browser.js","gitHead":"4a21619e54be47638511b324731020350e254f61","scripts":{"build":"./build.sh","start":"node server.js"},"_npmUser":{"name":"camilaprav","email":"camila@guiprav.com"},"repository":{"url":"git+https://github.com/camilaprav/peacock.git","type":"git"},"_npmVersion":"9.7.2","description":"Isomorphic document database, file hosting, and mail sending","directories":{},"_nodeVersion":"20.4.0","dependencies":{"cors":"^2.8.5","busboy":"^1.6.0","mkdirp":"^3.0.1","express":"^5.1.0","@seald-io/nedb":"^4.1.1"},"_hasShrinkwrap":false,"devDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/peacock_0.0.2_1744614906738_0.9149034991413965","host":"s3://npm-registry-packages-npm-production"}},"0.0.3":{"name":"@camilaprav/peacock","version":"0.0.3","author":{"name":"Camila Prá"},"license":"AGPL-3.0-or-later","_id":"@camilaprav/peacock@0.0.3","maintainers":[{"name":"camilaprav","email":"camila@guiprav.com"}],"homepage":"https://github.com/camilaprav/peacock#readme","bugs":{"url":"https://github.com/camilaprav/peacock/issues"},"dist":{"shasum":"dabf27bfbbee7d83b49a8c04802a04b5f4d07dc7","tarball":"https://registry.npmjs.org/@camilaprav/peacock/-/peacock-0.0.3.tgz","fileCount":10,"integrity":"sha512-1iR/mAoyjqoDXsL1w7JCLLwxSuUnxLEM4ijKPV1neaJp5E5u0tgfH+fhThRTJ23VxPQz6sa3c7sNiRcE1bH8ew==","signatures":[{"sig":"MEQCIAShEP2lD8MjCRhSaXdRfDBWKT++/wZkHu8Msr0kimTvAiB0s7KpKT+0sxTvFACaDviVk15e2FRj0zI0Crn47TN4qA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":55808},"type":"module","browser":"peacock.browser.js","gitHead":"52d0c23623caa0a050329d9fd173330075488c9f","scripts":{"build":"./build.sh","start":"node server.js"},"_npmUser":{"name":"camilaprav","email":"camila@guiprav.com"},"repository":{"url":"git+https://github.com/camilaprav/peacock.git","type":"git"},"_npmVersion":"9.7.2","description":"Isomorphic document database, file hosting, and mail sending","directories":{},"_nodeVersion":"20.4.0","dependencies":{"cors":"^2.8.5","busboy":"^1.6.0","mkdirp":"^3.0.1","express":"^5.1.0","@seald-io/nedb":"^4.1.1"},"_hasShrinkwrap":false,"devDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/peacock_0.0.3_1744619898735_0.7051862045450534","host":"s3://npm-registry-packages-npm-production"}},"0.0.4":{"name":"@camilaprav/peacock","version":"0.0.4","description":"Isomorphic document database, file hosting, and mail sending","type":"module","browser":"peacock.browser.js","scripts":{"build":"./build.sh","start":"node server.js"},"dependencies":{"@seald-io/nedb":"^4.1.1","busboy":"^1.6.0","cors":"^2.8.5","express":"^5.1.0","mkdirp":"^3.0.1"},"devDependencies":{},"repository":{"type":"git","url":"git+https://github.com/camilaprav/peacock.git"},"author":{"name":"Camila Prá"},"license":"AGPL-3.0-or-later","bugs":{"url":"https://github.com/camilaprav/peacock/issues"},"homepage":"https://github.com/camilaprav/peacock#readme","gitHead":"4f0adc4a78f36f9755e7066354acb0787cc062e1","_id":"@camilaprav/peacock@0.0.4","_nodeVersion":"20.4.0","_npmVersion":"9.7.2","dist":{"integrity":"sha512-OSCATPMh28XaQkgGpOzLCWK8LyyTLyuIe6ciSV4IfddZ/BrRfMoR8AWzSYWgYKhQ5cjQPw2SvZfav4ZAZ2mKYQ==","shasum":"3229bc7ebe15382f2929cbd766aa38f4301991d9","tarball":"https://registry.npmjs.org/@camilaprav/peacock/-/peacock-0.0.4.tgz","fileCount":10,"unpackedSize":55822,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDjh5+0KKl7h7GktFpt7LdZBaCSzBpF1uyIUlXQuHw8zwIhAKHm+/HmbK39OSj/zlUncS4p2H5yIE/yFlDECRMH06Cc"}]},"_npmUser":{"name":"camilaprav","email":"camila@guiprav.com"},"directories":{},"maintainers":[{"name":"camilaprav","email":"camila@guiprav.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/peacock_0.0.4_1744630897121_0.04982587402000993"},"_hasShrinkwrap":false}},"time":{"created":"2025-04-13T21:50:17.786Z","modified":"2025-04-14T11:41:37.498Z","0.0.0":"2025-04-13T21:50:18.058Z","0.0.1":"2025-04-13T21:52:53.353Z","0.0.2":"2025-04-14T07:15:06.912Z","0.0.3":"2025-04-14T08:38:19.025Z","0.0.4":"2025-04-14T11:41:37.331Z"},"bugs":{"url":"https://github.com/camilaprav/peacock/issues"},"author":{"name":"Camila Prá"},"license":"AGPL-3.0-or-later","homepage":"https://github.com/camilaprav/peacock#readme","repository":{"type":"git","url":"git+https://github.com/camilaprav/peacock.git"},"description":"Isomorphic document database, file hosting, and mail sending","maintainers":[{"name":"camilaprav","email":"camila@guiprav.com"}],"readme":"# 🦚 Peacock\n\nPeacock is a lightweight, FeathersJS-inspired middleware for Express that provides RESTful API endpoints for embedded document database operations and file uploads. It supports both Node.js and browser environments with the same core logic.\n\n⚠️ **Work in Progress**: This project is still under active development. APIs may change, and breaking updates are possible until a stable release is published.\n\nIt is **strongly recommended to start with the browser-based version**, and only migrate to a server when it's time to actually share data between users. This helps reduce setup complexity and makes development faster and more self-contained.\n\n---\n\n## 🚀 Features\n\n- 🗃️ **Embedded Document Database API**  \n  REST-style endpoints (`GET`, `POST`, `PUT`, `DELETE`) to interact with NeDB collections scoped by namespace. Collections are created on-demand—no need for pre-registration.\n\n- 📁 **File Upload API**  \n  Upload files via `multipart/form-data`, automatically store them under a unique URL, and support retrieval. **Note:** File uploads are stored separately and have no connection to NeDB.\n\n- 🔄 **Pluggable Hooks**  \n  Add custom middleware logic (`before`, `after`, and `around`) per collection. The hook system is designed to mimic [FeathersJS](https://feathersjs.com)'s service lifecycle hooks for familiarity and flexibility.\n\n- 🌐 **Dual Environment Support**  \n  Works in both Node.js (with Express) and browser (with localForage).\n\n- 🧩 **Extensible Roadmap**  \n  A MongoDB adapter and built-in mail sending functionality are planned for future releases.\n\n---\n\n## 🌍 Usage in the browser\n\nYou can use Peacock directly in the browser by importing it and adding it as a middleware to [xfetch](https://github.com/yourusername/xfetch):\n\n```js\nimport xfetch from 'https://esm.sh/@camilaprav/xfetch';\nimport peacock from 'https://esm.sh/@camilaprav/peacock';\n\n// Register Peacock as a middleware\nxfetch.middlewares.push(peacock);\n```\n\nTo target the local (in-browser) Peacock middleware, requests must be made to the `peacock://` protocol:\n\n```js\nawait xfetch('peacock://browser/db/myspace/users');\nawait xfetch('peacock://browser/upload/myspace', { body: formData });\n```\n\nTo switch to a real server implementation later, simply change your `xfetch` request URLs to standard HTTPS that points to a Peacock server:\n\n```js\nawait xfetch('https://api.example.com/db/myspace/users');\n```\n\nThis allows you to use the same request logic in both environments with minimal changes.\n\n---\n\n## 🧩 Hooks API\n\nYou can register lifecycle hooks for specific collections:\n\n```js\npeacock.hooks('myspace/users', {\n  before: [\n    async (ctx) => {\n      if (ctx.method === 'create') {\n        ctx.data.createdAt = new Date();\n      }\n    }\n  ]\n});\n```\n\nAvailable hook types: `around`, `before`, `after`.\n\nThe hook system mimics FeathersJS's lifecycle model, allowing you to extend and customize behavior with familiar patterns.\n\nEach hook receives a `ctx` object:\n```js\n{\n  method,     // One of: 'get', 'find', 'create', 'update', 'remove'\n  id,         // Document ID (if applicable)\n  params,     // URL query parameters\n  data,       // Request body (for POST/PUT)\n  result,     // The result to send back\n  req,        // Raw Express request\n  res         // Raw Express response\n}\n```\n\n---\n\n## 📦 Installation\n\n```bash\ngit clone https://github.com/camilaprav/peacock\ncd peacock\nnpm install\n```\n\nTo build the server and browser versions:\n\n```bash\nnpm run build\n```\n\nThis creates:\n- `peacock.server.js` – for use in Node.js environments.\n- `peacock.browser.js` – for use in browser apps.\n\n---\n\n## 🧑‍💻 Server Usage\n\n### Start the server\n\n```bash\nnode server.js\n```\n\n### Database API\n\n`/db/:namespace/:collection[/:id]`\n\nCollections are created automatically upon first access—no setup required.\n\n#### Examples\n\n- `GET /db/myspace/users` – find documents\n- `GET /db/myspace/users/:id` – get one document\n- `POST /db/myspace/users` – insert document\n- `PUT /db/myspace/users` – update document (by `_id`)\n- `DELETE /db/myspace/users?name=John` – remove matching documents\n\n### File Upload\n\n`POST /upload/:namespace`  \nUploads a file under the given namespace.\n\n#### Request\n\n- Content-Type: `multipart/form-data`\n- Form field: `file`\n\n#### Response\n```json\n{\n  \"namespace\": \"myspace\",\n  \"id\": \"generated-id\",\n  \"url\": \"/uploads/myspace/generated-id/filename.ext\"\n}\n```\n\n---\n\n## 🧪 Development Notes\n\n- **Browser version** uses ES modules and `localForage` for simulated file storage.\n- Designed to be environment-agnostic while maintaining modularity and clarity.\n\n---\n\n## 📜 License\n\nAffero General Public License v3.0 or later (AGPLv3+)\n\nYou are free to use, modify, and redistribute this software under the terms of the AGPLv3+. If you deploy Peacock as part of a networked service, you must make the source code available to users of that service.\n\n---\n\n## 🧠 Inspiration\n\nPeacock is inspired by [FeathersJS](https://feathersjs.com), but takes a more minimal and file-centric approach. It aims to be portable, environment-aware, and easy to plug into any web stack.\n","readmeFilename":"README.md"}