{"id":22382435,"url":"https://github.com/jcoreio/sequelize-validate-subfields-flow-runtime","last_synced_at":"2025-03-26T19:40:57.359Z","repository":{"id":40707460,"uuid":"117787932","full_name":"jcoreio/sequelize-validate-subfields-flow-runtime","owner":"jcoreio","description":"use flow-runtime to validate JSON attributes of Sequelize models","archived":false,"fork":false,"pushed_at":"2023-01-04T01:20:40.000Z","size":4165,"stargazers_count":0,"open_issues_count":22,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-02T06:04:16.828Z","etag":null,"topics":["es2015"],"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}},"created_at":"2018-01-17T05:19:24.000Z","updated_at":"2020-12-15T06:30:11.000Z","dependencies_parsed_at":"2023-02-01T17:30:51.557Z","dependency_job_id":null,"html_url":"https://github.com/jcoreio/sequelize-validate-subfields-flow-runtime","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fsequelize-validate-subfields-flow-runtime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fsequelize-validate-subfields-flow-runtime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fsequelize-validate-subfields-flow-runtime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fsequelize-validate-subfields-flow-runtime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcoreio","download_url":"https://codeload.github.com/jcoreio/sequelize-validate-subfields-flow-runtime/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245726805,"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":["es2015"],"created_at":"2024-12-05T00:13:00.097Z","updated_at":"2025-03-26T19:40:57.334Z","avatar_url":"https://github.com/jcoreio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sequelize-validate-subfields-flow-runtime\n\n[![CircleCI](https://circleci.com/gh/jcoreio/sequelize-validate-subfields-flow-runtime.svg?style=svg)](https://circleci.com/gh/jcoreio/sequelize-validate-subfields-flow-runtime)\n[![Coverage Status](https://codecov.io/gh/jcoreio/sequelize-validate-subfields-flow-runtime/branch/master/graph/badge.svg)](https://codecov.io/gh/jcoreio/sequelize-validate-subfields-flow-runtime)\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-flow-runtime.svg)](https://badge.fury.io/js/sequelize-validate-subfields-flow-runtime)\n\nuse flow-runtime to validate JSON attributes of Sequelize models\n\n# Installation\n\n```sh\nnpm install --save flow-runtime sequelize-validate-subfields-flow-runtime\n```\n\n# Example\n\nUsing `reify` below requires `babel-plugin-flow-runtime` [to be configured](https://codemix.github.io/flow-runtime/#/docs)!\n\n```js\nimport Sequelize from 'sequelize'\nimport { reify, validate } from 'flow-runtime'\nimport type { Type } from 'flow-runtime'\nimport { validateWithFlowRuntime } from 'sequelize-validate-subfields-flow-runtime'\nimport { flattenValidationErrors } from 'sequelize-validate-subfields'\n\nimport sequelize from './sequelize'\n\ntype UserInfo = {\n  phone: string,\n  address: {\n    line1: string,\n    line2?: string,\n    postalCode: number,\n    state: string,\n  },\n}\n\nconst UserInfoType = (reify: Type\u003cUserInfo\u003e)\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: validateWithFlowRuntime(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 `flow-runtime` `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## `validateWithFlowRuntime(typeOrValidator, [options])`\n\n### Arguments\n\n#### `typeOrValidator: Type\u003cany\u003e | ((value: any) =\u003e ?Validation)\n\nA reified `flow-runtime` `Type`, or a function taking an attribute value and returning a `flow-runtime` `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-flow-runtime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcoreio%2Fsequelize-validate-subfields-flow-runtime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Fsequelize-validate-subfields-flow-runtime/lists"}