{"id":23512781,"url":"https://github.com/baethon/adonis-validator-extras","last_synced_at":"2025-05-13T19:29:10.244Z","repository":{"id":102098215,"uuid":"113075056","full_name":"baethon/adonis-validator-extras","owner":"baethon","description":"Validator goodies for Adonis framework","archived":false,"fork":false,"pushed_at":"2017-12-22T15:07:13.000Z","size":38,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-16T21:18:11.439Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/baethon.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null}},"created_at":"2017-12-04T17:45:40.000Z","updated_at":"2020-04-30T21:51:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"0769f204-dd01-4d79-969a-9ebade3712a1","html_url":"https://github.com/baethon/adonis-validator-extras","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baethon%2Fadonis-validator-extras","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baethon%2Fadonis-validator-extras/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baethon%2Fadonis-validator-extras/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baethon%2Fadonis-validator-extras/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baethon","download_url":"https://codeload.github.com/baethon/adonis-validator-extras/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254012550,"owners_count":21999285,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-12-25T13:19:27.459Z","updated_at":"2025-05-13T19:29:10.218Z","avatar_url":"https://github.com/baethon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @baethon/adonis-validator-extras\n\nPackage contains some extensions for [Adonis Validation](https://github.com/adonisjs/adonis-validation-provider) extension.\n\n# Table of contents\n\n\u003c!-- TOC depthFrom:2 --\u003e\n\n- [Installation](#installation)\n- [Request extension](#request-extension)\n- [Validator rules flattener](#validator-rules-flattener)\n- [development](#development)\n    - [tests \u0026 linting](#tests--linting)\n    - [issues \u0026 PR](#issues--pr)\n\n\u003c!-- /TOC --\u003e\n\n## Installation\n\n1. Install package\n    ```bash\n    # via adonis\n    adonis install @baethon/adonis-validator-extras\n\n    # or for Yarn users\n    adonis install --yarn @baethon/adonis-validator-extras\n\n    # or via yarn\n    yarn add @baethon/adonis-validator-extras\n\n    # or via npm\n    npm i @baethon/adonis-validator-extras\n    ```\n1. Add `@baethon/adonis-validator-extras/providers/ValidationExtenderProvider` to application providers\n\n## Request extension\n\nModule provides `validated()` macro for request instance. It will return data from request which went through [route validators](http://adonisjs.com/docs/4.0/validator#_route_validator).\n\nOnly defined data will be returned.\n\n```js\nRoute\n  .post('/test', ({ request }) =\u003e {\n    console.log(request.validated())\n  })\n  .validator('Test')\n```\n\nThis method will fail with exception if request was not validated with `validator()`.\n\n## Validator rules flattener\n\n[Indicative](http://indicative.adonisjs.com/) has support for nested rules.\n\nIn many ways they can be inconvienient:\n\n```js\nclass Test {\n  get rules () {\n    return {\n      name: 'required',\n      'address.street': 'string',\n      'address.city': 'string'\n    }\n  }\n}\n```\n\nIt gets even worse with arrays:\n\n```js\nclass Test {\n  get rules () {\n    return {\n      name: 'required',\n      'family.*.name': 'string',\n      'family.*.age': 'integer',\n    }\n  }\n}\n```\n\nPackage provides `flattenRules` helper which allows to write nested rules in more natural manner and later _flatten_ them to format accepted by Indicative.\n\n```js\nconst { flattenRules } = require('@baethon/adonis-validator-extras')\n\nclass Test {\n  get rules () {\n    return {\n      name: 'required',\n      family: [{\n        name: 'string',\n        age: 'integer'\n      }]\n    }\n  }\n}\n\nmodule.exports = flattenRules(Test)\n```\n\n`flattenRules` will process rules only once. Results are cached which means that `rules` getter **will be static**.\n\nFlattened rules support string interpolation of values from `ctx`:\n\n```js\nconst { flattenRules } = require('@baethon/adonis-validator-extras')\n\nclass Test {\n  get rules () {\n    return {\n      email: 'unique:users,email,id,{{params.id}}'\n    }\n  }\n}\n\nmodule.exports = flattenRules(Test)\n```\n\nIt's also possible to call methods from context (without any arguments):\n\n```js\nconst { flattenRules } = require('@baethon/adonis-validator-extras')\n\nclass Test {\n  get rules () {\n    return {\n      email: 'unique:users,email,id,{{request.all().id}}'\n    }\n  }\n}\n\nmodule.exports = flattenRules(Test)\n```\n\n\n## development\n\nIf you're planning to contribute to the package please make sure to adhere to following conventions.\n\n### tests \u0026 linting\n\n* lint your code using [standard](https://standardjs.com/); run `npm run lint` to check if there are any linting errors\n* make sure to write tests for all the changes/bug fixes\n\n### issues \u0026 PR\n\n* try to provide regression test when you find a bug\n* share some context on what you are trying to do, with enough code to reproduce the issue\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaethon%2Fadonis-validator-extras","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaethon%2Fadonis-validator-extras","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaethon%2Fadonis-validator-extras/lists"}