{"id":16659868,"url":"https://github.com/bsless/malli-keys-relations","last_synced_at":"2025-08-12T06:05:32.855Z","repository":{"id":140642196,"uuid":"364225776","full_name":"bsless/malli-keys-relations","owner":"bsless","description":"Relational schemas about map keys for malli","archived":false,"fork":false,"pushed_at":"2021-05-25T11:55:34.000Z","size":11,"stargazers_count":22,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-02T21:28:56.611Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bsless.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":"2021-05-04T10:57:21.000Z","updated_at":"2025-04-08T16:13:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"2aa7bc1a-bc76-4bef-96c3-48fac13a5d29","html_url":"https://github.com/bsless/malli-keys-relations","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bsless/malli-keys-relations","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsless%2Fmalli-keys-relations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsless%2Fmalli-keys-relations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsless%2Fmalli-keys-relations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsless%2Fmalli-keys-relations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bsless","download_url":"https://codeload.github.com/bsless/malli-keys-relations/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsless%2Fmalli-keys-relations/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270011172,"owners_count":24511896,"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","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-10-12T10:26:54.104Z","updated_at":"2025-08-12T06:05:32.832Z","avatar_url":"https://github.com/bsless.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# malli-keys-relations\n\nProof of concept implementation for a discussion on the malli channel on\nClojurians slack of schemas describing relations between keys in a map.\n\nHopefully it gets integrated with malli in the future.\n\n## Usage\n\n`(require com.github.bsless.malli-keys-relations)`\n\nEither use `-comparator-relation-schemas` to get a map of all current\nschemas and add it to your registry, or use the provided `registry` var\nwhich includes them and the default registry.\n\nNew schemas:\n\n```clojure\n:keys/=\n:keys/==\n:keys/\u003c\n:keys/\u003e\n:keys/\u003e=\n:keys/\u003c=\n:keys/not=\n```\n\nBoth validation and generation work:\n\n```clojure\n(m/validate\n   (m/schema\n    [:and\n     [:map\n      [:x nat-int?]\n      [:y nat-int?]]\n     [:keys/not= :x :y]]\n    {:registry registry})\n   {:x 1 :y 1})\n\n(mg/generate\n   (m/schema\n    [:and\n     [:map\n      [:x nat-int?]\n      [:y nat-int?]]\n     [:keys/\u003c :x :y]]\n    {:registry registry}))\n```\n\n## Implementation notes\n\n`:and` generators wouldn't work without overriding the default behavior.\n\nOriginally:\n\n```clojure\n(defmethod -schema-generator :and [schema options]\n  (gen/such-that\n   (m/validator schema options)\n   (-\u003e schema (m/children options) first (generator options)) 100))\n```\n\nValidation is done according to entire schema but generation only by the first child\n\nNow:\n\n```clojure\n(defn- derive-from-fmap\n  [schema options gen]\n  (let [props (merge (m/type-properties schema)\n                     (m/properties schema))]\n    (when-some [fmap (:gen/fmap props)]\n      (gen/fmap (m/eval fmap (or options (m/options schema)))\n                gen))))\n\n(defmethod mg/-schema-generator :and [schema options]\n  (let [[h \u0026 t] (m/children schema options)\n        base-gen (mg/generator h options)\n        gen (reduce (fn [gen schema]\n                      (or (derive-from-fmap schema options gen) gen))\n                    base-gen\n                    t)]\n    (gen/such-that (m/validator schema options) gen 100)))\n```\n\nTry to gradually construct a generator from all children if they provide\na `:gen/fmap` and not just a generator.\n\nThis could be a general enhancement of `:and` generators.\n\n## License\n\nCopyright © 2021 Ben Sless\n\nThis program and the accompanying materials are made available under the\nterms of the Eclipse Public License 2.0 which is available at\nhttp://www.eclipse.org/legal/epl-2.0.\n\nThis Source Code may also be made available under the following Secondary\nLicenses when the conditions for such availability set forth in the Eclipse\nPublic License, v. 2.0 are satisfied: GNU General Public License as published by\nthe Free Software Foundation, either version 2 of the License, or (at your\noption) any later version, with the GNU Classpath Exception which is available\nat https://www.gnu.org/software/classpath/license.html.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsless%2Fmalli-keys-relations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbsless%2Fmalli-keys-relations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsless%2Fmalli-keys-relations/lists"}