{"_id":"@baguettejs/middlewares","_rev":"3-446269a9edc3eb4c74e42a9dee768fff","name":"@baguettejs/middlewares","dist-tags":{"latest":"1.0.0"},"versions":{"0.1.0":{"name":"@baguettejs/middlewares","version":"0.1.0","keywords":["utils","typescript","helpers","baguettejs","framework"],"author":{"name":"Cyprien Tertrais"},"license":"MIT","_id":"@baguettejs/middlewares@0.1.0","maintainers":[{"name":"cyprientertrais","email":"cyprien.tertrais@hotmail.com"}],"dist":{"shasum":"1288def1e29db761a34a26b1e9c9ec4c8625cb86","tarball":"https://registry.npmjs.org/@baguettejs/middlewares/-/middlewares-0.1.0.tgz","fileCount":11,"integrity":"sha512-gkLzA48ydYXgvrLMmgOGIlrSR9vex2Qm3e+OHWlYOS/QNjPXL+XBGYkEF77Z8vXOUrQIfL6TBamRsAdWIixTrg==","signatures":[{"sig":"MEUCIBHJxf3Zv0Bfk9F/DJI07GXQOPtvO/13GlINB+WAnkZfAiEAzKNeTdEl2IKxhpQpC43BMnRt06nsDTBjU3DZOU5ZUZk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":37123},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"2bc6bdcf95400680d3370162a2aa32e1fb8d666f","scripts":{"build":"tsc -b tsconfig.json","clean":"rm -rf dist"},"_npmUser":{"name":"cyprientertrais","email":"cyprien.tertrais@hotmail.com"},"_npmVersion":"lerna/9.0.0/node@v22.19.0+arm64 (darwin)","description":"Utility functions for the BaguetteJS framework","directories":{},"_nodeVersion":"22.19.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/middlewares_0.1.0_1760596441791_0.5396372734636239","host":"s3://npm-registry-packages-npm-production"}},"0.2.1":{"name":"@baguettejs/middlewares","version":"0.2.1","keywords":["utils","typescript","helpers","baguettejs","framework"],"author":{"name":"Cyprien Tertrais"},"license":"MIT","_id":"@baguettejs/middlewares@0.2.1","maintainers":[{"name":"cyprientertrais","email":"cyprien.tertrais@hotmail.com"}],"dist":{"shasum":"9ab89c88c40650f0f3cafc15e8d18089328c215e","tarball":"https://registry.npmjs.org/@baguettejs/middlewares/-/middlewares-0.2.1.tgz","fileCount":11,"integrity":"sha512-5AQa5yb2lSRz+PU6r68xHINSGbCtUVZ6ZVnUpLDIakQue3/XID4Q3vB13OeZdta9fyjXyt12xf+WvLXe74ywzg==","signatures":[{"sig":"MEYCIQCxOJLUg0PfgEKYgN/9jkaSB80biA5WZ86EZXuxDUWoXQIhANgED1o5gk1kw0RA+syNBqXAPxVwFjFeIab3YhZinEbP","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":37123},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"b1e8d4e8492a200987f8d1d78470d6e90fbc33d3","scripts":{"build":"tsc -b tsconfig.json","clean":"rm -rf dist"},"_npmUser":{"name":"cyprientertrais","email":"cyprien.tertrais@hotmail.com"},"_npmVersion":"lerna/9.0.0/node@v22.19.0+arm64 (darwin)","description":"Utility functions for the BaguetteJS framework","directories":{},"_nodeVersion":"22.19.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/middlewares_0.2.1_1760635533270_0.9728336633873269","host":"s3://npm-registry-packages-npm-production"}},"1.0.0":{"_id":"@baguettejs/middlewares@1.0.0","bugs":{"url":"https://github.com/baguettejs/baguettejs/issues"},"dist":{"shasum":"cea34ba1a89e363649ea24322b60438cae658856","tarball":"https://registry.npmjs.org/@baguettejs/middlewares/-/middlewares-1.0.0.tgz","fileCount":8,"integrity":"sha512-1bqQrElWzUKD/FHNh/SqpyAVUqfcrz8FH3TNkfSZ8Wh3PyY2aO7D85d9Jz9RmYvUQDAEM3gKkHWePdKJvwlQLg==","signatures":[{"sig":"MEUCIGkikWc55T6tD915EiM15Sn4qQABxReujWtlnNB+nc2YAiEA/rAkj1AaJ5RLAZMEBJVXbDf2YG4kG5eMzkFuk8HAyJw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC5pHL62IIwceYeUQCTcgAi07c4SBNJiPia/ETd7xTUXAIhANqJb8CswPk24uv93Yyu9NhTYeL7melkkakVAL8zLMCW"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@baguettejs%2fmiddlewares@1.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":4268},"main":"dist/index.js","name":"@baguettejs/middlewares","type":"module","types":"dist/index.d.ts","author":{"name":"Cyprien Tertrais"},"gitHead":"99fded26afe14facbda546afc082537eb93894de","license":"MIT","scripts":{"build":"bun x tsc -b tsconfig.json","clean":"bun x tsc -b tsconfig.json --clean"},"version":"1.0.0","_npmUser":{"name":"cyprientertrais","email":"cyprien.tertrais@hotmail.com"},"homepage":"https://github.com/baguettejs/baguettejs#readme","keywords":["utils","typescript","helpers","baguettejs","framework"],"repository":{"url":"git+https://github.com/baguettejs/baguettejs.git","type":"git","directory":"packages/middlewares"},"_npmVersion":"10.9.8","description":"Utility functions for the BaguetteJS framework","directories":{},"maintainers":[{"name":"cyprientertrais","email":"cyprien.tertrais@hotmail.com"}],"_nodeVersion":"22.23.2","dependencies":{"@baguettejs/core":"^1.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@types/bun":"^1.4.2","typescript":"^5.9.2"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/middlewares_1.0.0_1789620279045_0.3642556322619499"}}},"time":{"created":"2025-10-16T06:34:01.682Z","modified":"2026-09-17T04:44:39.479Z","0.1.0":"2025-10-16T06:34:01.996Z","0.2.1":"2025-10-16T17:25:33.452Z","1.0.0":"2026-09-17T04:44:39.147Z"},"author":{"name":"Cyprien Tertrais"},"license":"MIT","keywords":["utils","typescript","helpers","baguettejs","framework"],"description":"Utility functions for the BaguetteJS framework","maintainers":[{"name":"cyprientertrais","email":"cyprien.tertrais@hotmail.com"}],"readme":"# ⚙️ @baguettejs/middlewares\n\nThe `@baguettejs/middlewares` package provides middleware utilities and decorators for the **BaguetteJS** framework.  \nIt allows developers to easily define, register, and execute middlewares at both **global** and **route** levels.\n\n---\n\n## 📦 Installation\n\n```bash\nbun add @baguettejs/middlewares\n```\n\nor\n\n```bash\nbun add @baguettejs/middlewares\n```\n\n---\n\n## 🧠 Features\n\n### 🧩 Middleware Decorator\n\nUse the `@Middleware()` decorator to attach middleware functions to controllers or specific routes.  \nA middleware can modify the request, perform checks, or log information before a controller executes.\n\n#### Example\n\n```ts\nimport { Controller, Get, Middleware } from '@baguettejs/core';\n\nfunction logger(req: any, res: any, next: Function) {\n  console.log(`[${new Date().toISOString()}] ${req.method} ${req.url}`);\n  next();\n}\n\n@Controller('/users')\nexport class UserController {\n  @Get('/')\n  @Middleware(logger)\n  getAll() {\n    return [{ name: 'Alice' }, { name: 'Bob' }];\n  }\n}\n```\n\n🧩 Result:\n- Every request to `/users` will trigger the `logger` middleware before executing the controller.\n\n---\n\n### 🌍 Global Middlewares\n\nYou can also register global middlewares that run before every route:\n\n```ts\nimport { App } from '@baguettejs/core';\n\nfunction cors(req: any, res: any, next: Function) {\n  res.setHeader('Access-Control-Allow-Origin', '*');\n  next();\n}\n\nconst app = new App();\napp.use(cors);\nawait app.bootstrap('src/controllers');\napp.listen(3000);\napp.bootstrap('src/controllers');\n```\n\n---\n\n## ⚙️ Middleware Signature\n\n```ts\nexport type NextFunction = () => Promise<void> | void;\n\nexport type MiddlewareHandler = (\n  req: Request,\n  res: Response,\n  next: NextFunction\n) => Promise<void> | void;\n```\n\nEach middleware receives:\n- `req` — the request object\n- `res` — the response object\n- `next()` — a function to call the next middleware (or continue to the controller)\n\n---\n\n## 🔗 Related Packages\n\n- [`@baguettejs/core`](https://github.com/baguettejs/core) — Main framework runtime and routing.\n- [`@baguettejs/utils`](https://github.com/baguettejs/utils) — Shared reflection and scanning utilities.\n\n---\n\n## 🧑‍💻 Contributing\n\nPull requests are welcome!  \nIf you’d like to contribute a custom middleware (e.g. logging, auth, CORS, body parsing), feel free to open an issue or PR.\n\n---\n\n## 🪪 License\n\nMIT © 2025 [BaguetteJS](https://github.com/baguettejs)\n","readmeFilename":"readme.md","homepage":"https://github.com/baguettejs/baguettejs#readme","repository":{"url":"git+https://github.com/baguettejs/baguettejs.git","type":"git","directory":"packages/middlewares"},"bugs":{"url":"https://github.com/baguettejs/baguettejs/issues"}}