{"id":16010363,"url":"https://github.com/amauryd/fastest-validator-decorators","last_synced_at":"2025-05-08T19:50:42.978Z","repository":{"id":42350684,"uuid":"215089041","full_name":"AmauryD/fastest-validator-decorators","owner":"AmauryD","description":"Typescript decorators for the fastest-validator library","archived":false,"fork":false,"pushed_at":"2024-10-13T09:03:47.000Z","size":415,"stargazers_count":17,"open_issues_count":4,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-05T21:09:13.719Z","etag":null,"topics":["decorators","fastest-validator","schema","typescript","validate","validation","validator"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/AmauryD.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":"2019-10-14T16:11:26.000Z","updated_at":"2024-10-13T09:03:50.000Z","dependencies_parsed_at":"2024-02-23T09:28:49.392Z","dependency_job_id":"10a56804-1b11-4a7a-833c-2bf55464be92","html_url":"https://github.com/AmauryD/fastest-validator-decorators","commit_stats":{"total_commits":83,"total_committers":6,"mean_commits":"13.833333333333334","dds":"0.40963855421686746","last_synced_commit":"6944c15a11ab568a2693e518b741f72dd14af45c"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmauryD%2Ffastest-validator-decorators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmauryD%2Ffastest-validator-decorators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmauryD%2Ffastest-validator-decorators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmauryD%2Ffastest-validator-decorators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AmauryD","download_url":"https://codeload.github.com/AmauryD/fastest-validator-decorators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253141392,"owners_count":21860535,"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":["decorators","fastest-validator","schema","typescript","validate","validation","validator"],"created_at":"2024-10-08T13:05:31.392Z","updated_at":"2025-05-08T19:50:42.934Z","avatar_url":"https://github.com/AmauryD.png","language":"TypeScript","readme":"[![npm version](https://img.shields.io/npm/v/fastest-validator-decorators.svg)](https://www.npmjs.com/package/fastest-validator-decorators)\n[![npm downloads](https://img.shields.io/npm/dm/fastest-validator-decorators.svg)](https://www.npmjs.com/package/fastest-validator-decorators)\n[![GitHub issues](https://img.shields.io/github/issues/tobydeh/fastest-validator-decorators.svg)](https://github.com/tobydeh/fastest-validator-decorators/issues)\n[![License](https://img.shields.io/github/license/tobydeh/fastest-validator-decorators.svg)](https://github.com/tobydeh/fastest-validator-decorators/blob/master/LICENSE)\n\n# Fastest Validator Decorators\n\n**Fastest Validator Decorators** is a TypeScript library providing a set of decorators that streamline the integration with the [fastest-validator](https://github.com/icebob/fastest-validator#readme), a high-performance validation library for JavaScript and TypeScript. This package simplifies schema definition and validation by leveraging TypeScript's decorator feature.\n\n:boom: Upgrading from version 1.x? Check the [Migration Guide](MIGRATING.md).\n\n## Key Features\n- **Type-safe schema validation** using TypeScript decorators.\n- Supports all validation types provided by fastest-validator.\n- **Nested object and array validation** made simple with decorators.\n- **Async validation support**, enabling you to run asynchronous validation tasks.\n  \n## Installation\n\nInstall the package via npm:\n\n```bash\nnpm install --save fastest-validator-decorators fastest-validator\n```\n\n:warning: **Note:** `fastest-validator` is a peer dependency, so ensure it's also installed.\n\nNext, enable decorators in your `tsconfig.json`:\n\n```json\n{\n  \"compilerOptions\": {\n    \"experimentalDecorators\": true,\n    \"emitDecoratorMetadata\": true\n  }\n}\n```\n\n## Usage Example\n\nHere’s a basic example of how to use the decorators in your project:\n\n```ts\nimport {\n  Schema, Array, UUID, Enum, Email, Number, Nested, getSchema, validate, validateOrReject\n} from \"fastest-validator-decorators\";\n\n@Schema({ strict: true })\nclass Entity1 {\n  @Array({ items: \"string\" })\n  prop1: string[];\n}\n\n@Schema()\nclass Entity2 {\n  @UUID()\n  prop1: string;\n\n  @Enum({ values: [\"one\", \"two\"] })\n  prop2: \"one\" | \"two\";\n\n  @Email()\n  prop3: string;\n\n  @Number({ positive: true })\n  prop4: number;\n\n  @Nested()\n  prop5: Entity1;\n}\n\n// Generating a validation schema\nconst schema = getSchema(Entity2);\n\n// Creating and validating instances\nconst entity = new Entity2();\nentity.prop1 = \"invalid-uuid\";  // Validation error: invalid UUID\nentity.prop2 = \"one\";\nentity.prop3 = \"user@example.com\";\nentity.prop4 = -10;  // Validation error: number is not positive\n\nconst result = validate(entity); // true or error list\nawait validateOrReject(entity);   // true or throws an error\n```\n\n## Available Decorators\n\nFastest Validator Decorators supports the following decorators for schema definition. Each decorator corresponds to a validation type from [fastest-validator](https://github.com/icebob/fastest-validator#readme).\n\n- **@Schema**: Defines the validation schema for a class.\n- **@Field**: Generic decorator for defining custom fields.\n- **@String**, **@Boolean**, **@Number**, **@UUID**, **@ObjectId**, **@Email**, **@Date**, **@Enum**, **@Array**, **@Equal**, **@Instance**, **@Currency**, **@Func**, **@Luhn**, **@Mac**, **@Url**, **@Any**, **@Multi**: Each of these applies a specific fastest-validator type with custom options.\n  \nYou can also use **@Nested** and **@NestedArray** for validating complex objects and arrays of objects.\n\n### Decorator Stacking\n\nThe library allows stacking multiple decorators on a single property. For example:\n\n```ts\n@String()\n@Number()\nprop1: string | number;\n```\n\nThis syntax resolves to the @Multi decorator, which validates the property against multiple types.\n\n### Async Validation Support\n\nAsync validation is supported by adding the `async: true` option to your schema. Here's an example of how to use asynchronous checks within a custom validation:\n\n```ts\n@Schema({ async: true, strict: true })\nclass User {\n  @Custom({\n    async check(value, errors) {\n      const isUserInDB = await db.checkUserName(value);\n      if (isUserInDB) errors.push({ type: \"unique\", actual: value });\n      return value;\n    }\n  })\n  username: string;\n}\n\nconst user = new User();\nuser.username = \"existingUser\";\nawait validateOrReject(user);  // async validation\n```\n\n## API Methods\n\n- **getSchema(Class)**: Retrieves the fastest-validator schema for a given class.\n- **validate(instance)**: Validates the provided instance and returns `true` or an error list.\n- **validateOrReject(instance)**: Same as `validate()`, but throws errors if validation fails.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famauryd%2Ffastest-validator-decorators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famauryd%2Ffastest-validator-decorators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famauryd%2Ffastest-validator-decorators/lists"}