{"id":26709395,"url":"https://github.com/js-bits/model","last_synced_at":"2025-04-13T17:32:47.247Z","repository":{"id":174476052,"uuid":"344918367","full_name":"js-bits/model","owner":"js-bits","description":"Abstract multi-purpose data model","archived":false,"fork":false,"pushed_at":"2024-09-12T22:43:59.000Z","size":833,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T08:18:00.777Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/js-bits.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-03-05T19:51:33.000Z","updated_at":"2024-09-12T22:44:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"5efebf84-2a14-4c97-8dff-68d7d0aeb99d","html_url":"https://github.com/js-bits/model","commit_stats":null,"previous_names":["js-bits/model"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-bits%2Fmodel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-bits%2Fmodel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-bits%2Fmodel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-bits%2Fmodel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/js-bits","download_url":"https://codeload.github.com/js-bits/model/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248752371,"owners_count":21156079,"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":[],"created_at":"2025-03-27T08:16:45.391Z","updated_at":"2025-04-13T17:32:47.222Z","avatar_url":"https://github.com/js-bits.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [WORK IN PROGRESS] Multi-purpose data model\n\nInspired by [Backbone.Model](http://backbonejs.org/#Model). Re-imagined and modernized.\n\n`Model` is a static data structure, defined by certain rules using a data schema.\n\n```javascript\nconst Profile = new Model({\n  firstName: String,\n  lastName: String,\n  yearBorn: Number,\n  'verified?': Boolean, // optional property\n});\n\nconst author = new Profile({\n  firstName: 'Trygve',\n  lastName: 'Reenskaug',\n  yearBorn: 1930,\n});\n\nconsole.log(`${author}`);\n// [object Model]\n\nconsole.log(JSON.stringify(author, null, '  '));\n// {\n//   firstName: 'Trygve',\n//   lastName: 'Reenskaug',\n//   yearBorn: 1930,\n//   verified: null\n// }\n```\n\nKey features:\n\n- Strict data schema\n- Runtime data validation\n- Configurable data types\n- Optional deep objects immutability\n- Interactive data store\n- ...\n\n[TBD]\n\n## Installation\n\nInstall with npm:\n\n```\nnpm install @js-bits/model\n```\n\nInstall with yarn:\n\n```\nyarn add @js-bits/model\n```\n\nImport where you need it:\n\n```javascript\nimport { Model, DataType } from '@js-bits/model';\n```\n\nor require for CommonJS:\n\n```javascript\nconst { Model, DataType } = require('@js-bits/model');\n```\n\n## How to use\n\n[TBD]\n\nMore examples can be found in [examples](https://github.com/js-bits/model/tree/main/examples) folder.\n\n## How is this different from [JSON Schema](https://json-schema.org/)?\n\nJSON Schema serves more as a data format description, while `Model` is much more functional and gives you more control over data.\n\n[TBD]\n\n## Ok. But what about TypeScript?\n\nCode written in TypeScript is only checked for errors before it is executed, during compile time. Moreover, not every project is built with TypeScript. And not every project needs TypeScript.\n\n[TypeScript is ‘not worth it’ for developing libraries, says Svelte author, as team switches to JavaScript and JSDoc](https://devclass.com/2023/05/11/typescript-is-not-worth-it-for-developing-libraries-says-svelte-author-as-team-switches-to-javascript-and-jsdoc/)\n\n[TBD]\n\nAs for IDE's code-completion capabilities, you can achieve similar result with [JSDoc](https://jsdoc.app/) annotations.\n\n## Hmm... But we already have [Zod](https://zod.dev/)\n\nSure. `Model` does something similar to what [Zod](https://zod.dev/) does,\nbut while [Zod](https://zod.dev/) is \"a schema declaration and validation library\",\n`Model` goes further and is aimed to serve more like a data store.\nAlso, `Model` has more natural syntax.\n\n[TBD]\n\n## GraphQL?\n\nGraphQL queries tend to grow over time and you have to carry unnecessary data even though you don't use it.\n`Model` allows you to control what data exactly you need to operate.\n\n[TBD]\n\n## How about immutability, then?\n\nWell, immutability is not a dogma.\n\n[TBD]\n\n- https://desalasworks.com/article/immutability-in-javascript-a-contrarian-view/\n- https://stackoverflow.com/questions/34385243/why-is-immutability-so-important-or-needed-in-javascript/43318963#43318963\n- https://medium.com/dailyjs/the-state-of-immutability-169d2cd11310\n- https://stackoverflow.com/questions/1863515/pros-cons-of-immutability-vs-mutability\n\nBut, anyway, you can make your data deeply immutable with this package and still use other benefits (like data validation) at the same time.\n\n```javascript\nObject.freeze(object); // shallow freeze\n// versus\nnew CustomModel(object); // deep freeze\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjs-bits%2Fmodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjs-bits%2Fmodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjs-bits%2Fmodel/lists"}