{"_id":"@ar4mirez/hapi-octopus","name":"@ar4mirez/hapi-octopus","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"@ar4mirez/hapi-octopus","description":"HAPI plugin to auto-load routes, methods, pres, handlers and more.","version":"1.0.1","author":{"name":"Angel Ramirez","email":"angel@cuemby.com"},"main":"lib/index.js","engines":{"node":">=18.0.0"},"bugs":{"url":"https://github.com/ar4mirez/hapi-octopus/issues"},"homepage":"https://github.com/ar4mirez/hapi-octopus#readme","license":"ISC","dependencies":{"glob":"^10.4.5","joi":"^17.13.3"},"devDependencies":{"@hapi/code":"^9.0.3","@hapi/hapi":"^21.4.4","@hapi/lab":"^26.0.0"},"scripts":{"test":"lab -v -c"},"repository":{"type":"git","url":"git+https://github.com/ar4mirez/hapi-octopus.git"},"_id":"@ar4mirez/hapi-octopus@1.0.1","gitHead":"36893482eb26f1423347f8c3e2cadcad4b6c75df","_nodeVersion":"20.20.1","_npmVersion":"10.8.2","dist":{"integrity":"sha512-rS3dxRLCnHPY3UgOiXS6MLeczAanNVuAkNeiG56CIygerNquufbzMgDdJ+v9WyaIKJuFzth02X+v93oHndboVg==","shasum":"e269d6e95ddf2282f76786b5275b366230151a46","tarball":"https://registry.npmjs.org/@ar4mirez/hapi-octopus/-/hapi-octopus-1.0.1.tgz","fileCount":6,"unpackedSize":13046,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@ar4mirez%2fhapi-octopus@1.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDKx0xMOddlkaVlWPraAy0UyXKTqqi4WnC8R0JVuc7pbAIhAJLL9Wnl8sPbAGyKbgJQhrz4TSz+Waogy8yPmwHhJE+l"}]},"_npmUser":{"name":"ar4mirez","email":"angel@cuemby.com"},"directories":{},"maintainers":[{"name":"ar4mirez","email":"angel@cuemby.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/hapi-octopus_1.0.1_1773852323692_0.23896565205538867"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-18T16:45:23.622Z","1.0.1":"2026-03-18T16:45:23.833Z","modified":"2026-03-18T16:45:24.459Z"},"maintainers":[{"name":"ar4mirez","email":"angel@cuemby.com"}],"description":"HAPI plugin to auto-load routes, methods, pres, handlers and more.","homepage":"https://github.com/ar4mirez/hapi-octopus#readme","repository":{"type":"git","url":"git+https://github.com/ar4mirez/hapi-octopus.git"},"author":{"name":"Angel Ramirez","email":"angel@cuemby.com"},"bugs":{"url":"https://github.com/ar4mirez/hapi-octopus/issues"},"license":"ISC","readme":"# hapi-octopus\n\n[![travis build](https://img.shields.io/travis/ar4mirez/hapi-octopus.svg?style=flat-square)](https://travis-ci.org/ar4mirez/hapi-octopus)\n[![codecov coverage](https://img.shields.io/codecov/c/github/ar4mirez/hapi-octopus.svg?style=flat-square)](https://codecov.io/github/ar4mirez/hapi-octopus)\n[![version](https://img.shields.io/npm/v/hapi-octopus.svg?style=flat-square)](http://npm.im/hapi-octopus)\n[![downloads](https://img.shields.io/npm/dm/hapi-octopus.svg?style=flat-square)](http://npm-stat.com/charts.html?package=hapi-octopus&from=2015-08-01)\n[![SEE LINCESE](https://img.shields.io/npm/l/hapi-octopus.svg?style=flat-square)](https://github.com/ar4mirez/hapi-octopus/blob/master/LICENSE.md)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)\n\n***hapi v17 version***\n\nA multi-purpose plugin that allows you to autoload `methods`, `handlers`,\n`routes` and `decorators` using a simple signature convention.\n\n***Is currently in a sort of stable version. I'm trying to keep it with 100% coverage\nbut just be aware the API might change a little based on my needs or beacuse I love\nrefactoring :p. Any help is apreciated if you are nice and polite.***\n\n## Installation\n\n```javascript\nnpm i --save hapi-octopus\n```\n\n## Usage\n\n```javascript\nconst octopus = require('hapi-octopus');\n\n// using server register.\nawait server.register({\n  plugin: octopus,\n  options: {\n    methods: {\n      cwd: `${process.cwd()}/methods`\n    },\n    handlers: {\n      cwd: `${process.cwd()}/handlers`\n    },\n    routes: {\n      cwd: `${process.cwd()}/routes`\n    },\n    decorators: {\n      cwd: `${process.cwd()}/decorators`\n    }\n  }\n}});\n\n// using manifest.\n{\n  ...\n  registration: [\n    {\n      plugin: octopus,\n      options: {\n        methods: {\n          cwd: `${process.cwd()}/methods`\n        },\n        handlers: {\n          cwd: `${process.cwd()}/handlers`\n        },\n        routes: {\n          cwd: `${process.cwd()}/routes`\n        },\n        decorators: {\n          cwd: `${process.cwd()}/decorators`\n        }\n      }\n    }\n  ]\n}\n```\n\n### Register methods.\n\n#### Signature\n`name: string`: optional if not present export.key will be used instead. ex: `exports.multiply`\n\n`method: function`: required body of method in hapijs. [methods](https://hapijs.com/api#servermethodmethods)\n\n`options: object`: optional same in hapijs. [methods](https://hapijs.com/api#servermethodname-method-options)\n\n`prefix: string`: optional if not present filename will be used instead. ex: `math.js`.\n\n```javascript\n\n// /path/to/methods/math.js\n\nexports.mulitply = {\n  method: (a, b) => (a * b),\n  options: {},\n};\n/*\n  this method will be available as:\n    - server.methods.math.multiply(2, 4);\n  optional values prefix and name are the same as saying\n    - prefix = 'math'\n    - name = 'multiply'\n*/\n\n```\n\n### Register handlers.\n\n#### Signature\n`name: string`: optional if not present export.key will be used instead. ex: `exports.multiply`\n\n`method: function`: required see in hapijs. [handlers](https://hapijs.com/api#serverhandlername-method)\n\n`options: object`: optional same in hapijs. [handlers](https://hapijs.com/api#serverhandlername-method)\n\n`prefix: string`: optional if not present filename will be used instead. ex: `math.js`.\n\n```javascript\n// /path/to/handlers/customer.js\n\nexports.all = {\n  method: (route, options) => {\n    return (request, h) => {\n      ...\n      return {\n        total: 10,\n        data: customers\n      })\n    }\n  }\n};\n\n/*\n  this method will be available as:\n    - server.methods.math.multiply(2, 4);\n  optional values prefix and name are the same as saying\n    - prefix = 'customer'\n    - name = 'all'\n*/\n\n// in a route you can use it like this.\n\nserver.route({\n  method: 'GET',\n  path: '/customer/create',\n  handler: {\n    customerAll: {} // always prefix+name camelCase.\n  }\n})\n```\n\n### Register routes.\n\nRoutes can be registered in 2 ways: exporting an array|object or using a function.\n\n#### Array| Object Signature\n`routes: array|object`: required for this signature should return an array or object of hapijs [routes](https://hapijs.com/api#serverrouteoptions).\n\n```javascript\nexports.customers = {\n  routes: [\n    {method: 'GET', path: '/customers', handler: {customerAll: {}}},\n    {method: 'POST', path: '/customers', handler: {customerCreate: {}}}\n  ]\n}\n\nexports.update = {\n  routes: {\n    method: 'PATCH',\n    path: '/customers/{id}',\n    handler: {\n      customerUpdate: {}\n    }\n  }\n}\n```\n\n#### Function Signature\n`method: function`: required for this signature should receive a server object.\n\n`options: object`: optional options to be passed a long with server object.\n\n```javascript\nexports.customers = {\n  method: (server, options) => {\n    console.log(options);\n\n    server.route([\n      {method: 'GET', path: '/customers', handler: {customerAll: {}}},\n      {method: 'POST', path: '/customers', handler: {customerCreate: {}}}\n    ])\n  }\n}\n```\n\n### Register decorators.\n\n`decorate: string`: required and accept only `request|toolkit|server`.\n\n`name: string`: optional name must be unique since will be used as accessor\nfrom decoration, if name is not passed `exports.key` will be used instead.\n\n`method: any`: required could be anything from `object|array|function|string` is what you'll get from decoration.\n\nsee more info about [decorators](https://hapijs.com/api#serverdecoratetype-property-method-options)\n\n````javascript\nexports.reply404 = {\n  decorate: 'toolkit',\n  method: () => {\n    return this.response({\n      message: 'Standard 404 error'\n    });\n  }\n};\n\n// will be accesible from a handler like:\n\n...\nhandler: (request, h) => {\n  return h.response(({anotherMessage: 'ahh whatever really.'}).code(404);\n}\n\n````\n","readmeFilename":"README.md","_rev":"1-5fb25b0f1739583dfd989482f0e796e8"}