{"id":13519279,"url":"https://github.com/component/model","last_synced_at":"2025-08-12T15:09:36.814Z","repository":{"id":4928843,"uuid":"6085458","full_name":"component/model","owner":"component","description":"Minimalistic extensible data models","archived":false,"fork":false,"pushed_at":"2015-06-23T06:19:16.000Z","size":561,"stargazers_count":122,"open_issues_count":16,"forks_count":39,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-08-09T03:33:11.024Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"priore/SOAPEngine","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/component.png","metadata":{"files":{"readme":"Readme.md","changelog":"History.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-10-05T03:48:56.000Z","updated_at":"2025-02-14T15:50:45.000Z","dependencies_parsed_at":"2022-09-18T01:01:19.554Z","dependency_job_id":null,"html_url":"https://github.com/component/model","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/component/model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fmodel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fmodel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fmodel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fmodel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/component","download_url":"https://codeload.github.com/component/model/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fmodel/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269688087,"owners_count":24459403,"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-10T02:00:08.965Z","response_time":71,"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-08-01T05:01:56.716Z","updated_at":"2025-08-12T15:09:36.795Z","avatar_url":"https://github.com/component.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# model\n\n  W.I.P minimalistic extensible model component.\n\n## API\n\n### model(name)\n\n  Create a new model with the given `name`.\n\n```js\nvar model = require('model');\nvar User = model('User');\n```\n\n### .attr(name, [meta])\n\n  Define an attribute `name` with optional `meta` data object.\n\n```js\nvar model = require('model');\n\nvar Post = model('Post')\n  .attr('id')\n  .attr('title')\n  .attr('body')\n  .attr('created_at')\n  .attr('updated_at')\n```\n\n  With meta data used by plugins:\n\n```js\nvar model = require('model');\n\nvar Post = model('Post')\n  .attr('id', { required: true, type: 'number' })\n  .attr('title', { required: true, type: 'string' })\n  .attr('body', { required: true, type: 'string' })\n  .attr('created_at', { type: 'date' })\n  .attr('updated_at', { type: 'date' })\n```\n\n### .validate(fn)\n\n  TODO: validation callback docs\n\n### .use(fn)\n\n  TODO: plugin docs\n\n### .url([path])\n\n  Return base url, or url to `path`.\n\n```js\nUser.url()\n// =\u003e \"/users\"\n\nUser.url('add')\n// =\u003e \"/users/add\"\n```\n\n### .route(path)\n\n  Set base path for urls.\n  Note this is defaulted to `'/' + modelName.toLowerCase() + 's'`\n\n```js\nUser.route('/api/u')\n\nUser.url()\n// =\u003e \"/api/u\"\n\nUser.url('add')\n// =\u003e \"/api/u/add\"\n```\n \n### .headers({header: value})\n\n  Sets custom headers for static and method requests on the model.\n\n```js  \nUser.headers({\n  'X-CSRF-Token': 'some token',\n  'X-API-Token': 'api token' \n});\n```\n\n### .ATTR()\n\n  \"Getter\" function generated when `Model.attr(name)` is called.\n\n```js\nvar Post = model('Post')\n  .attr('title')\n  .attr('body')\n\nvar post = new Post({ title: 'Cats' });\n\npost.title()\n// =\u003e \"Cats\"\n```\n\n### .ATTR(value)\n\n  \"Setter\" function generated when `Model.attr(name)` is called.\n\n```js\nvar Post = model('Post')\n  .attr('title')\n  .attr('body')\n\nvar post = new Post;\n\npost.title('Ferrets')\npost.title()\n// =\u003e \"Ferrets\"\n```\n\n  - Emits \"change\" event with `(name, value, previousValue)`.\n  - Emits \"change ATTR\" event with `(value, previousValue)`.\n\n```js\npost.on('change', function(name, val, prev){\n  console.log('changed %s from %s to %s', name, prev, val)\n})\n\npost.on('change title', function(val, prev){\n  console.log('changed title')\n})\n\n```\n\n### .isNew()\n\n  Returns `true` if the model is unsaved.\n\n### .toJSON()\n\n  Return a JSON representation of the model (its attributes).\n\n### .has(attr)\n\n  Check if `attr` is non-`null`.\n\n### .get(attr)\n\n  Get `attr`'s value.\n\n### .set(attrs)\n\n  Set multiple `attrs`.\n\n```js\nuser.set({ name: 'Tobi', age: 2 })\n```\n\n### .changed([attr])\n\n  Check if the model is \"dirty\" and return an object\n  of changed attributes. Optionally check a specific `attr`\n  and return a `Boolean`.\n\n### .error(attr, msg)\n\n  Define error `msg` for `attr`.\n\n### .isValid()\n\n  Run validations and check if the model is valid.\n\n```js\nuser.isValid()\n// =\u003e false\n\nuser.errors\n// =\u003e [{ attr: ..., message: ... }]\n```\n\n### .url([path])\n\n  Return this model's base url or relative to `path`:\n\n```js\nvar user = new User({ id: 5 });\nuser.url('edit');\n// =\u003e \"/users/5/edit\"\n```\n\n### .save(fn)\n\n  Save or update and invoke the given callback `fn(err)`.\n\n```js\nvar user = new User({ name: 'Tobi' })\n\nuser.save(function(err){\n\n})\n```\n\n  Emits \"save\" when complete.\n\n### .destroy([fn])\n\n  Destroy and invoke optional `fn(err)`.\n\n  Emits \"destroy\" when successfully deleted.\n\n## Links\n\n  - [Plugins](https://github.com/component/model/wiki/Plugins) for model\n\n## Testing\n\n```\n$ npm install\n$ make test \u0026\n$ open http://localhost:3000\n```\n\n# License\n\n  MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomponent%2Fmodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcomponent%2Fmodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomponent%2Fmodel/lists"}