{"id":22382407,"url":"https://github.com/jcoreio/sequelize-validate-subfields-typed-validators","last_synced_at":"2025-03-26T19:40:52.605Z","repository":{"id":78315618,"uuid":"328041790","full_name":"jcoreio/sequelize-validate-subfields-typed-validators","owner":"jcoreio","description":"sequelize-validate-subfields adapter for typed-validators","archived":false,"fork":false,"pushed_at":"2023-11-28T19:09:15.000Z","size":994,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-01T02:11:29.702Z","etag":null,"topics":["sequelize","sequelize-validate-subfields","typed-validators","validation"],"latest_commit_sha":null,"homepage":null,"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/jcoreio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2021-01-09T00:22:46.000Z","updated_at":"2023-11-28T19:08:30.000Z","dependencies_parsed_at":"2025-02-01T01:44:20.796Z","dependency_job_id":"6d57f232-8d3a-46bf-a3a7-d9ce174a8fe8","html_url":"https://github.com/jcoreio/sequelize-validate-subfields-typed-validators","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fsequelize-validate-subfields-typed-validators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fsequelize-validate-subfields-typed-validators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fsequelize-validate-subfields-typed-validators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fsequelize-validate-subfields-typed-validators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcoreio","download_url":"https://codeload.github.com/jcoreio/sequelize-validate-subfields-typed-validators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245726746,"owners_count":20662544,"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":["sequelize","sequelize-validate-subfields","typed-validators","validation"],"created_at":"2024-12-05T00:12:54.007Z","updated_at":"2025-03-26T19:40:52.598Z","avatar_url":"https://github.com/jcoreio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sequelize-validate-subfields-typed-validators\n\n[![CircleCI](https://circleci.com/gh/jcoreio/sequelize-validate-subfields-typed-validators.svg?style=svg)](https://circleci.com/gh/jcoreio/sequelize-validate-subfields-typed-validators)\n[![Coverage Status](https://codecov.io/gh/jcoreio/sequelize-validate-subfields-typed-validators/branch/master/graph/badge.svg)](https://codecov.io/gh/jcoreio/sequelize-validate-subfields-typed-validators)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![npm version](https://badge.fury.io/js/sequelize-validate-subfields-typed-validators.svg)](https://badge.fury.io/js/sequelize-validate-subfields-typed-validators)\n\nuse typed-validators to validate JSON attributes of Sequelize models\n\n# Installation\n\n```sh\nnpm install --save typed-validators sequelize-validate-subfields-typed-validators\n```\n\n# Example\n\n```js\nimport Sequelize from 'sequelize'\nimport * as t from 'typed-validators'\nimport { validateWithTypedValidators } from 'sequelize-validate-subfields-typed-validators'\nimport { flattenValidationErrors } from 'sequelize-validate-subfields'\n\nimport sequelize from './sequelize'\n\nconst UserInfoType = t.alias(\n  'User',\n  t.object({\n    phone: t.string(),\n    address: t.object({\n      required: {\n        line1: t.string(),\n        postalCode: t.number(),\n        state: t.string(),\n      },\n      optional: {\n        line2: t.string(),\n      },\n    }),\n  })\n)\n\nconst User = Sequelize.define('User', {\n  username: {\n    type: Sequelize.STRING,\n    validate: {\n      notEmpty: {\n        msg: 'required',\n      },\n    },\n  },\n  info: {\n    type: Sequelize.JSON,\n    validate: validateWithTypedValidators(UserInfoType),\n  },\n})\n\ntry {\n  User.create({\n    username: '',\n    address: {\n      line2: 2,\n      postalCode: '76034',\n      state: 'TX',\n    },\n  })\n} catch (error) {\n  if (error instanceof Sequelize.ValidationError) {\n    console.error(flattenValidationErrors(error))\n  } else {\n    console.error(error)\n  }\n}\n```\n\nOutput:\n\n```\n[\n  {path: ['username'], message: 'required'},\n  {path: ['address', 'line1'], message: 'must be a string'},\n  {path: ['address', 'line2'], message: 'must be a string'},\n  {path: ['address', 'postalCode'], message: 'must be a number'},\n]\n```\n\n# API\n\n## `convertValidationErrors(validation, [options])`\n\n### Arguments\n\n#### `validation: Validation`\n\nA `typed-validators` `Validation` object containing an `errors` array of `[path, message, type]` tuples.\n\n#### `options?: {reduxFormStyle?: boolean}`\n\nIf `reduxFormStyle` is true, validation errors on object/array fields will be yielded for the `_error` subpath\nunder that field.\n\n### Returns: `Iterable\u003cFieldValidation\u003e`\n\nYields `{path: Array\u003cstring | number\u003e, message: string}` objects about validation errors, the format defined by\n`sequelize-validate-subfields`.\n\n## `validateWithTypedValidators(typeOrValidator, [options])`\n\n### Arguments\n\n#### `typeOrValidator: Type\u003cany\u003e | ((value: any) =\u003e ?Validation)\n\nA `typed-validators` `Type`, or a function taking an attribute value and returning a `typed-validators` `Validation`\nobject or `null`. Errors from applying the given function or validating against the given type will be yielded in\n`sequelize-validate-subfields` format.\n\n#### `options?: {reduxFormStyle?: boolean}`\n\nIf `reduxFormStyle` is true, validation errors on object/array fields will be yielded for the `_error` subpath\nunder that field.\n\n### Returns: `(value: any) =\u003e void`\n\nA Sequelize custom attribute validation function that uses the given `typeOrValidator` to validate attribute values.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Fsequelize-validate-subfields-typed-validators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcoreio%2Fsequelize-validate-subfields-typed-validators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Fsequelize-validate-subfields-typed-validators/lists"}