{"id":43270540,"url":"https://github.com/treeder/models","last_synced_at":"2026-02-01T15:41:25.956Z","repository":{"id":312002364,"uuid":"1045931463","full_name":"treeder/models","owner":"treeder","description":"A way to define an object schema and a parser to turn fields into proper objects.","archived":false,"fork":false,"pushed_at":"2025-11-25T16:47:22.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-28T22:19:37.053Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/treeder.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-27T23:51:03.000Z","updated_at":"2025-11-25T16:47:25.000Z","dependencies_parsed_at":"2025-08-28T07:59:53.020Z","dependency_job_id":"929db91b-583c-4a54-b082-c62c8e70e775","html_url":"https://github.com/treeder/models","commit_stats":null,"previous_names":["treeder/models"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/treeder/models","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treeder%2Fmodels","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treeder%2Fmodels/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treeder%2Fmodels/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treeder%2Fmodels/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/treeder","download_url":"https://codeload.github.com/treeder/models/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treeder%2Fmodels/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28981454,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T15:35:50.179Z","status":"ssl_error","status_checked_at":"2026-02-01T15:35:38.075Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":"2026-02-01T15:41:25.878Z","updated_at":"2026-02-01T15:41:25.952Z","avatar_url":"https://github.com/treeder.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# models\n\nA secondary JSON parser to turn fields into concrete objects.\n\nAfter a `JSON.parse(s)`, run this with `parseModel(ob)` to turn fields into objects, like so:\n\n```js\nlet ob = JSON.parse(s)\nob = parseModel(ob, User)\n```\n\n## Getting Started\n\n```sh\nnpm install treeder/models\n```\n\nOr in your browser:\n\n```js\nimport {parseModel} from 'https://cdn.jsdelivr.net/gh/treeder/models@1/index.js'\n```\n\nFirst define your models. You may find this familiar if you use [Lit](https://lit.dev). And these models can be used for [migrations](https://github.com/treeder/migrations), for SQLite and Cloudflare D1 via [flaregun](https://github.com/treeder/flaregun), and for the handy [api](https://github.com/treeder/api) library. \n\n\n```js\nexport class User {\n  static properties = {\n    id: {\n      type: String,\n      primaryKey: true,\n    },\n    createdAt: {\n      type: Date,\n    },\n    updatedAt: {\n      type: Date,\n    },\n    name: {\n      type: String,\n    },\n    email: {\n      type: String,\n    },\n    data: {\n      type: Object,\n      // you can go deeper into Object properties, only required if you don't want JSON defaults.\n      birthday: {\n        type: Date,\n      }\n    },\n  }\n}\n```\n\nUse standard JavaScript classes:\n\n- String\n- Number\n- Boolean\n- Date\n- BigInt\n- Object\n\nTo use a custom parser, use `parse` instead of `type`:\n\n```js\n{\n  balance: {\n    parse: (n) =\u003e (n ? new Big(n) : new Big(0)),\n  },\n}\n```\n\nThen call `parseModel()` with your object and your new class. \n\n```js\nlet ob = JSON.parse(s)\nob = parseModel(ob, User)\n```\n\nThat's it!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreeder%2Fmodels","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftreeder%2Fmodels","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreeder%2Fmodels/lists"}