{"id":20170244,"url":"https://github.com/fabrix-app/spool-annotations","last_synced_at":"2026-04-29T15:05:15.246Z","repository":{"id":95882752,"uuid":"140315507","full_name":"fabrix-app/spool-annotations","owner":"fabrix-app","description":"Spool: Annotations","archived":false,"fork":false,"pushed_at":"2018-08-20T23:21:40.000Z","size":36,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-05T18:48:11.393Z","etag":null,"topics":["fabrix","nodejs","spool","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fabrix-app.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-09T16:47:30.000Z","updated_at":"2018-11-18T13:33:55.000Z","dependencies_parsed_at":"2023-05-20T02:31:43.160Z","dependency_job_id":null,"html_url":"https://github.com/fabrix-app/spool-annotations","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fabrix-app/spool-annotations","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabrix-app%2Fspool-annotations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabrix-app%2Fspool-annotations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabrix-app%2Fspool-annotations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabrix-app%2Fspool-annotations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fabrix-app","download_url":"https://codeload.github.com/fabrix-app/spool-annotations/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabrix-app%2Fspool-annotations/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32430809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T13:34:34.882Z","status":"ssl_error","status_checked_at":"2026-04-29T13:34:29.830Z","response_time":110,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fabrix","nodejs","spool","typescript"],"created_at":"2024-11-14T01:17:48.749Z","updated_at":"2026-04-29T15:05:15.231Z","avatar_url":"https://github.com/fabrix-app.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# spool-annotations\n\n[![Gitter][gitter-image]][gitter-url]\n[![NPM version][npm-image]][npm-url]\n[![Build Status][ci-image]][ci-url]\n[![Test Coverage][coverage-image]][coverage-url]\n[![Dependency Status][daviddm-image]][daviddm-url]\n[![Follow @FabrixApp on Twitter][twitter-image]][twitter-url]\n\n:package: Add Route, Policy and custom annotations support for Fabrix applications\n\n## Intallation\nWith fab cli :\n\n```\nnpm install -g @fabrix/fab-cli\nfab spool spool-annotations\n```\n\nWith npm (you will have to create config file manually) :\n\n`npm install --save @fabrix/spool-annotations`\n\n## Configuration\nFirst you need to add this spool to your __main__ configuration : \n```js\n// config/main.ts\n\nexport const annotations = {\n   // ...\n\n   spools: [\n      // ...\n      require('@fabrix/spool-annotations').AnnotationsSpool,\n      // ...\n   ]\n   // ...\n}\n```\n\nThen :\n```js\n// config/annotations.ts\nexport const annotations = {\n  policy: true,//enable policy annotations\n  route: true,//enable route annotations\n  pathToScan: './api/controllers',//or ./api for hmvc\n  customAnnotations: null, //Add your custom annotations here, require('./annotations') for example\n\n}\n```\n\n## Usage\n\n### Route\nA route added with annotation will replace any previous route set under `config/routes.ts` (for a same path).\n```\nmodule.exports = class DefaultController extends Controller {\n\n  /**\n   * Return some info about this application\n   * @Route(\"GET /default/info\") or @Route({method: [\"GET\"], path: \"/default/info\"})\n   */\n  info (request, reply) {\n    reply.json(this.app.services.DefaultService.getApplicationInfo())\n  }\n}\n```\n\nYou can also use @METHOD for defining new routes.\n```\nmodule.exports = class DefaultController extends Controller {\n\n  /**\n   * Return some info about this application\n   * @GET('/default/info')\n   * @HEAD('/default/info')\n   * @OPTIONS('/default/info')\n   * @POST('/default/info')\n   * @PUT('/default/info')\n   * @PATCH('/default/info')\n   * @DELETE('/default/info')\n   */\n  info (request, reply) {\n    reply.json(this.app.services.DefaultService.getApplicationInfo())\n  }\n}\n```\n\nA more complex sample with validation.\n```\nmodule.exports = class DefaultController extends Controller {\n\n  /**\n   * Return some info about this application\n   * @GET(path:{'/default/info'}, config: { validate: {\n   * query: { infos: Joi.sring().required() }\n   * }})\n   */\n  info (request, reply) {\n    reply.json(this.app.services.DefaultService.getApplicationInfo())\n  }\n}\n```\n\nSee [hapijs tutorial on validation](http://hapijs.com/tutorials/validation) and [joi schema validation](https://github.com/hapijs/joi) for more complex with validate object.\n\n### Policy\nA policy added with annotation will be added to policies set under `config/policies.ts`.\n```\nmodule.exports = class DefaultController extends Controller {\n\n  /**\n   * Return some info about this application\n   * @Policy(\"Default.auth\") or @Policy([\"Default.auth\", \"Default.acl\"])\n   */\n  info (request, reply) {\n    reply.json(this.app.services.Defaultervice.getApplicationInfo())\n  }\n}\n```\n\n### Custom\nCreate your own annotation like this :\n\n```\n'use strict'\nconst Annotation = require('ecmas-annotations').Annotation\n\nexport class MyCustomAnnotation extends Annotation {\n\n    /**\n     * The possible targets\n     *\n     * (Annotation.CONSTRUCTOR, Annotation.PROPERTY, Annotation.METHOD)\n     *\n     * @type {Array}\n     */\n    static get targets() {\n      return [Annotation.METHOD]\n    }\n\n    /**\n     * The function to call when annotations are find\n     *\n     * @type {Function}\n     */\n    handler(app, annotation) {\n      //Do whatever you want when annotation is found\n    }\n\n    /**\n     * File path\n     *\n     * @type {String}\n     * @required\n     */\n    static get path() {\n      return __filename\n    }\n\n}\n\n```\nNow I can add `@MyCustomAnnotation(\"It works\")` on methods.\n\n## License\n[MIT](https://github.com/jaumard/spool-annotations/blob/master/LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/@fabrix/spool-annotations.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@fabrix/spool-annotations\n[ci-image]: https://img.shields.io/circleci/project/github/fabrix-app/spool-annotations/master.svg\n[ci-url]: https://circleci.com/gh/fabrix-app/spool-annotations/tree/master\n[daviddm-image]: http://img.shields.io/david/fabrix-app/spool-annotations.svg?style=flat-square\n[daviddm-url]: https://david-dm.org/fabrix-app/spool-annotations\n[gitter-image]: http://img.shields.io/badge/+%20GITTER-JOIN%20CHAT%20%E2%86%92-1DCE73.svg?style=flat-square\n[gitter-url]: https://gitter.im/fabrix-app/fabrix\n[twitter-image]: https://img.shields.io/twitter/follow/FabrixApp.svg?style=social\n[twitter-url]: https://twitter.com/FabrixApp\n[coverage-image]: https://img.shields.io/codeclimate/coverage/github/fabrix-app/spool-annotations.svg?style=flat-square\n[coverage-url]: https://codeclimate.com/github/fabrix-app/spool-annotations/coverage\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabrix-app%2Fspool-annotations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabrix-app%2Fspool-annotations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabrix-app%2Fspool-annotations/lists"}