{"id":23385498,"url":"https://github.com/tratteo/omnimodel","last_synced_at":"2026-02-13T03:49:44.639Z","repository":{"id":63960180,"uuid":"572128029","full_name":"tratteo/omnimodel","owner":"tratteo","description":"Model complex data and access it in an easy and safe way","archived":false,"fork":false,"pushed_at":"2024-11-26T10:25:34.000Z","size":244,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T03:43:50.448Z","etag":null,"topics":["dart","flutter","library","package"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/omnimodel","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tratteo.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-11-29T16:00:10.000Z","updated_at":"2024-11-26T10:25:38.000Z","dependencies_parsed_at":"2023-01-14T16:45:26.860Z","dependency_job_id":"3bfaf715-c182-40af-8584-d5b17e03ee25","html_url":"https://github.com/tratteo/omnimodel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tratteo/omnimodel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tratteo%2Fomnimodel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tratteo%2Fomnimodel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tratteo%2Fomnimodel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tratteo%2Fomnimodel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tratteo","download_url":"https://codeload.github.com/tratteo/omnimodel/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tratteo%2Fomnimodel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275114698,"owners_count":25407926,"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-09-14T02:00:10.474Z","response_time":75,"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":["dart","flutter","library","package"],"created_at":"2024-12-22T00:18:30.711Z","updated_at":"2026-02-13T03:49:39.607Z","avatar_url":"https://github.com/tratteo.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":" \u003cdiv align=\"center\"\u003e\n\u003c!-- do not remove line below --\u003e\n\n\u003ca href=\"\"\u003e![GitHub](https://img.shields.io/github/license/tratteo/omnimodel?color=orange\u0026label=License)\u003c/a\u003e\n\u003ca href=\"\"\u003e![GitHub top language](https://img.shields.io/github/languages/top/tratteo/omnimodel?color=blue\u0026label=dart\u0026logo=dart)\u003c/a\u003e\n\u003ca href=\"\"\u003e![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/tratteo/omnimodel/dart.yml?branch=main\u0026label=Test\u0026logo=github)\u003c/a\u003e\n\u003ca href=\"\"\u003e![GitHub last commit (branch)](https://img.shields.io/github/last-commit/tratteo/omnimodel/main?label=Last%20commit\u0026color=brightgreen\u0026logo=github)\u003c/a\u003e\n\n\u003c/div\u003e\n\n### Model complex data and access it in an easy and safe way\n\n## Features\n\nThis package introduces a class that basically is a wrapper to any data that is representable as a `Map\u003cString, dynamic\u003e`.\n\nThe **OmniModel** allows to easily and safely access data inside the construct.\n\nThe package has been idealized for developing an easy and modular interface to communicate with any non relational, Json based database.\n\n## Usage\n\nThe `OmniModel` simply wraps the data and allows for easy and safe access. When accessing keys, it is possible to define the behaviour in case of missing entry in the original data.\n\nThe package also includes some useful tools such a (suppressable) automatic logging behaviour suggesting the closest match in case of key mispell by the developer. The algorithm uses a very precise **similarity convolution** algorithm.\n\n### Steps\n\n-   Create the `OmniModel` with one of the various factories\n-   Access entries in a controlled way\n-   Access nested models in a modular way by recursively parsing models with `OmniModel.tokenAsModel()`\n\nAdvanced usages can be found in the `/example` folder.\n\n## Examples\n\nSuppose a certain `Map` containing the following data:\n```dart\ndata = {\n    \"name\": \"Mario\",\n    \"surname\": \"Rossi\",\n    \"meta\":{\n        \"age\": 25,\n        \"birth_date\": null,\n        \"address\": \"Via Prima 12\",\n    },    \n    \"interests\": [\n        \"Computer Science\",\n        \"Physics\",\n        \"Food\",\n        \"Outdoor\",\n    ]\n}\n```\nThe **OmniModel** allows to safe wrap the data structure and handle missing values and default cases with ease. \nCreate the model form the map and start using it:\n```dart\nvar model = OmniModel.fromMap(data);\n```\nNested fields can be accessed simply by concatenating the keys with a separator (default `\".\"`):\n```dart\n//--\u003e Null default value\nvar age = model.tokenOrNull\u003cnum\u003e(\"meta.age\");\n\n//--\u003e Default value\nvar birth_date = model.tokenOr\u003cString\u003e(\"meta.birth_date\", \"01/01/1970\");\n\n//--\u003e Different types\nvar interests = model.tokenOr\u003cList\u003cString\u003e\u003e(\"interests\", List.empty());\n\n//--\u003e Access nested models\nvar metaModel = model.tokenAsModel(\"meta\");\n// metaModel is now:\n//{\n//    \"age\": 25,\n//    \"birth_date\": null,\n//    \"address\": \"Via Prima 12\",\n//}\n\n//--\u003e Edit the model with side effect, do not worry about non existing nested models, they are automatically created\nmodel.edit({\n    \"birth_date\": \"08/08/1998\",\n    \"meta.phones\": {\"mobile\":\"+39 3331234567\"}\n});\n// Add an interest\nmodel.edit({\n    \"interests\": model.tokenOr\u003cList\u003cString\u003e\u003e(\"interests\", List.empty())..add(\"Maths\")\n});\n\n//--\u003e Or get a new model instance\nvar newModel = model.copyWith({\n    \"birth_date\": \"08/08/1998\",\n    \"meta.phone\": {\"mobile\":\"+39 3331234567\"}\n});\n\n//--\u003e Get the most similar keys to the provided one. Uses a similarity convolution algorithm\nvar closeMatch = model.similar(\"metadata\") //\u003c--- will return \"meta\"\n```\n## Flutter\nThe `OmniModel` package is very useful in situations of declarative programming. With **Flutter**, the possibility to prevent null checks on each data key allows to make the code smaller and less bug prone.\n```dart\nif(data[\"meta\"] != null \u0026\u0026 data[\"meta\"][\"birth_date\"] != null)\n    Text(\n        data[\"meta\"][\"birth_date\"]\n    );\nelse\n    Text(\n        \"Birth date not provided\"\n    );\n\n\n//---\u003e With the OmniModel the code is smaller and easier to mantain.\n// Also the generic nature of the tokenOr method allows to enforce static types\n\nText(\n    model.tokenOr\u003cString\u003e(\"meta.birth_date\",\"Birth date not provided\")\n);\n\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftratteo%2Fomnimodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftratteo%2Fomnimodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftratteo%2Fomnimodel/lists"}