{"id":13726062,"url":"https://github.com/phink/changeset","last_synced_at":"2025-05-07T21:31:08.227Z","repository":{"id":71513306,"uuid":"134634563","full_name":"phink/changeset","owner":"phink","description":"(unreleased) Data validation with first-class and first-order labels in OCaml","archived":false,"fork":false,"pushed_at":"2018-06-29T14:23:20.000Z","size":88,"stargazers_count":30,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2024-08-04T01:28:28.817Z","etag":null,"topics":["data-validation","ocaml"],"latest_commit_sha":null,"homepage":"https://phink.github.io/changeset/changeset_lib/index.html","language":"OCaml","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/phink.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}},"created_at":"2018-05-23T23:05:40.000Z","updated_at":"2022-12-06T12:47:40.000Z","dependencies_parsed_at":"2023-09-10T01:30:52.950Z","dependency_job_id":null,"html_url":"https://github.com/phink/changeset","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phink%2Fchangeset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phink%2Fchangeset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phink%2Fchangeset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phink%2Fchangeset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phink","download_url":"https://codeload.github.com/phink/changeset/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224654106,"owners_count":17347670,"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":["data-validation","ocaml"],"created_at":"2024-08-03T01:02:51.322Z","updated_at":"2024-11-14T16:33:13.509Z","avatar_url":"https://github.com/phink.png","language":"OCaml","funding_links":[],"categories":["OCaml"],"sub_categories":[],"readme":"*This is WIP.*\n\n| Service | OCaml | Service |\n| ------- | ----- | ------- |\n| Circle  | 4.06  |[![Build Status](https://circleci.com/gh/phink/changeset/tree/develop.svg?style=svg)](https://circleci.com/gh/phink/changeset/tree/develop) |\n\n# Changeset\n\n**Data validation with first-class and first-order labels in OCaml.**\n\nHomepage for the library is\n[available here](https://phink.github.io/changeset/changeset_lib/index.html).\n\nChangesets are tools to validate data while accumulating errors along the way.\nThey are composed of:\n\n- **Changes**: an heterogeneous map whose keys are of type `'a label` and\nvalues `'a`.\nWhen deriving a changeset from a record type definition, the labels\ncorrespond to the fields of this one.\n\n- **Errors**: a list of strings associated with labels.\n\nLabels are first-class, that means you can give them as argument to functions,\nand first-order, so you can pattern match against them. The library\npromotes the pipeline design approach.\n\nThere is a ppx deriving plugin so there is no need to write any\nboilerplate code.\n\n#### Install using opam\n```\n$ opam pin add changeset_lib https://github.com/phink/changeset.git\n$ opam pin add ppx_changeset https://github.com/phink/changeset.git\n```\n\n#### Update the libraries and preprocess section in your jbuild file:\n\n```\n(libraries (... changeset))\n(preprocess (pps (... ppx_changeset)))\n```\n\n### Minimal example\n\n```ocaml\ntype t = {\n  age: int;\n  phone: string;\n  password: string;\n} [@@deriving changeset]\n\nlet validate cset =\n  cset\n  |\u003e Changeset.validate_int Age [`greater_than_or_equal_to 0]\n  |\u003e Changeset.validate_string_length Password [`min 12]\n  |\u003e Changeset.validate_format Phone (Str.regexp \"^\\\\+?[1-9][0-9]+$\")\n\nlet create t =\n  let cset = Changeset.from_record t in\n  Changeset.apply (validate cset)\n\nlet data = {age = 12; password = \"dolphin\"; phone = \"+14155552671\"}\n\nlet () = match create data with\n  | Ok t -\u003e (* do what you want *)\n  | Error cset -\u003e\n    Stdio.prerr_endline (Changeset.show_errors cset)\n```\n\nExecution\n\n```json\n{\n  \"errors\":{\n    \"password\":\"should be at least 12 character(s)\"\n  }\n}\n```\n\n### Limitations\n\nParameterized source types are not yet supported.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphink%2Fchangeset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphink%2Fchangeset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphink%2Fchangeset/lists"}