{"id":13912557,"url":"https://github.com/fullcube/loopback-ds-computed-mixin","last_synced_at":"2025-07-18T12:31:48.687Z","repository":{"id":35462573,"uuid":"39730363","full_name":"fullcube/loopback-ds-computed-mixin","owner":"fullcube","description":"A mixin to enable computed (dynamic) properties for loopback Models","archived":false,"fork":false,"pushed_at":"2020-06-01T01:17:04.000Z","size":136,"stargazers_count":32,"open_issues_count":16,"forks_count":12,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-07-10T19:22:00.200Z","etag":null,"topics":["fullcube","lb2","loopback","loopback-mixin","mit"],"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/fullcube.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}},"created_at":"2015-07-26T15:30:58.000Z","updated_at":"2023-04-22T15:56:19.000Z","dependencies_parsed_at":"2022-09-17T18:12:03.727Z","dependency_job_id":null,"html_url":"https://github.com/fullcube/loopback-ds-computed-mixin","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/fullcube/loopback-ds-computed-mixin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fullcube%2Floopback-ds-computed-mixin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fullcube%2Floopback-ds-computed-mixin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fullcube%2Floopback-ds-computed-mixin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fullcube%2Floopback-ds-computed-mixin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fullcube","download_url":"https://codeload.github.com/fullcube/loopback-ds-computed-mixin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fullcube%2Floopback-ds-computed-mixin/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265321133,"owners_count":23746382,"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":["fullcube","lb2","loopback","loopback-mixin","mit"],"created_at":"2024-08-07T01:01:33.129Z","updated_at":"2025-07-18T12:31:48.421Z","avatar_url":"https://github.com/fullcube.png","language":"JavaScript","funding_links":[],"categories":["others"],"sub_categories":[],"readme":"COMPUTED\n================\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/fullcube/loopback-ds-computed-mixin.svg)](https://greenkeeper.io/)\n\n[![CircleCI](https://circleci.com/gh/fullcube/loopback-ds-computed-mixin.svg?style=svg)](https://circleci.com/gh/fullcube/loopback-ds-computed-mixin) [![Coverage Status](https://coveralls.io/repos/github/fullcube/loopback-ds-computed-mixin/badge.svg?branch=master)](https://coveralls.io/github/fullcube/loopback-ds-computed-mixin?branch=master) [![Dependencies](http://img.shields.io/david/fullcube/loopback-ds-computed-mixin.svg?style=flat)](https://david-dm.org/fullcube/loopback-ds-computed-mixin) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n\nThis is a mixin for the LoopBack framework that adds computed properties to a model.\n\nA computed property is a property of which the value is set dynamically after reading model data from the data source.\n\n- The mixin uses the `loaded` observer.\n- It only runs when a single instance gets loaded, e.g. it checks `ctx.instance`.\n- It only runs when it is a new instance, e.g. it checks `ctx.isNewInstance`.\n- It overrides the configured property if one exists in the data source.\n\nINSTALL\n=============\n\n```bash\nnpm install --save loopback-ds-computed-mixin\n```\n\nSERVER CONFIG\n=============\nAdd the mixins property to your server/model-config.json:\n\n```\n{\n  \"_meta\": {\n    \"sources\": [\n      \"loopback/common/models\",\n      \"loopback/server/models\",\n      \"../common/models\",\n      \"./models\"\n    ],\n    \"mixins\": [\n      \"loopback/common/mixins\",\n      \"../node_modules/loopback-ds-computed-mixin/lib\",\n      \"../common/mixins\"\n    ]\n  }\n}\n```\n\nCONFIG\n=============\n\nTo use with your Models add the `mixins` attribute to the definition object of your model config.\n\nThe property you want to compute has to be defined in the model. The callback can be a promise too.\n\n```json\n{\n    \"name\": \"Item\",\n    \"properties\": {\n        \"name\": \"String\",\n        \"description\": \"String\",\n        \"status\": \"String\",\n        \"readonly\": \"boolean\"\n    },\n    \"mixins\": {\n        \"Computed\": {\n            \"properties\": {\n                \"readonly\": \"computeReadonly\"\n            }\n        }\n    }\n}\n```\n\nOn your model you have to define the callback method.\n\n```javascript\n// Set an item to readonly if status is archived\nItem.computeReadonly = function computeReadonly(item) {\n  return item.status === 'archived';\n};\n\n```\n\nTESTING\n=============\n\nRun the tests in `test.js`\n\n```bash\n  npm test\n```\n\nRun with debugging output on:\n\n```bash\n  DEBUG='loopback:mixin:computed' npm test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffullcube%2Floopback-ds-computed-mixin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffullcube%2Floopback-ds-computed-mixin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffullcube%2Floopback-ds-computed-mixin/lists"}