{"id":25517594,"url":"https://github.com/inlustra/angularentitysystem","last_synced_at":"2025-12-15T20:30:10.880Z","repository":{"id":58238450,"uuid":"52018783","full_name":"Inlustra/AngularEntitySystem","owner":"Inlustra","description":"An entity system wrapper used to turn raw JSON objects into useful entities","archived":false,"fork":false,"pushed_at":"2016-02-24T10:32:47.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-12T09:12:48.810Z","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":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Inlustra.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":"2016-02-18T15:52:15.000Z","updated_at":"2016-02-19T22:36:15.000Z","dependencies_parsed_at":"2022-08-31T00:30:52.278Z","dependency_job_id":null,"html_url":"https://github.com/Inlustra/AngularEntitySystem","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inlustra%2FAngularEntitySystem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inlustra%2FAngularEntitySystem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inlustra%2FAngularEntitySystem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inlustra%2FAngularEntitySystem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Inlustra","download_url":"https://codeload.github.com/Inlustra/AngularEntitySystem/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239684591,"owners_count":19680162,"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-02-19T15:36:01.085Z","updated_at":"2025-12-15T20:30:10.833Z","avatar_url":"https://github.com/Inlustra.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Angular Entity System v0.0.2\n\nAn entity system wrapper used to turn raw JSON objects into useful entities!\n\n## Installation\n\nVia Bower: \n```bash\nbower install angular-entity-system\n```\n\nAdd module to AngularJS:\n```javascript\nangular.module('\u003cYour Module Here\u003e', [\n   'angular-entity-system'\n   ...\n]);\n```\n\n## Example\n\nTake the following json:\n```json\n{\n   \"id\" : 1,\n   \"startTime\":\"2016-02-18T15:21:52.000+0000\",\n   \"endtime\":\"2016-02-19T15:21:52.000+0000\",\n   \"version\":0,\n   \"name\":\"Example Json\"\n}\n```\n\nThe dates are considered Strings and any extra methods such as duration would have to be added manually. with the following code,\nwe can assign meaning to the JSON object. Using Mutators, we can also assign meaning to sub objects. See below for current Mutator types.\n\nFirst, we create our DurationObject and add any extra methods we'd like to that.\n\n```javascript\nangular.module('my-module').factory('DurationObject', [\"Entity\", \"DateMutator\", function (Entity, DateMutator) {\n\n    function DurationObject() {\n    }\n\n    DurationObject.prototype.startTime = new DateMutator();\n    DurationObject.prototype.endTime = new DateMutator();\n\n    DurationObject.prototype.isNewer = function (object) {\n        return this.version \u003e object.version;\n    };\n\n    DurationObject.prototype.status = function () {\n        var now = new Date();\n        if (this.endTime \u003c= now) {\n            return 'Completed';\n        }\n        if (this.startTime \u003c= now) {\n            return 'Active';\n        }\n        return 'Upcoming';\n    };\n\n   ... Extra methods\n\n    return angular.extend(DurationObject, Entity);\n}]);\n```\n\nAnd then we allow the API to gather the JSON and transform it:\n```javascript\n    EntityAPI.get('http://whereeverasingleobject.json').singluar().as(DurationObject); // Returns a single DurationObject\n    EntityAPI.get('http://whereeveranarrayobject.json').as(DurationObject); // Returns an array of DurationObjects\n```\n\n## Components\n\n### Entities\n\nAn Entity is a simple AngularJS object extending the AngularJS Entity Factory.\n```javascript\nreturn angular.extend(DurationObject, Entity);\n```\nThese entities have the Entity.Build function allowing the API to call the build function for your particular entity type, scanning it for Mutators.\n\n### Mutators\n\nCurrently, only 2 Mutators have been written. (More to be added with feedback?).\n\nA Date Mutator and an EntityMutator, allowing inner Objects to also be converted to entities\n\n```json\n{\"innerEntity\": {\"sampleDate\": \"2016-02-19T15:21:52.000+0000\"}}\n```\nWe need an entity per nested object.\n```javascript\n.factory('OuterObject', [\"Entity\", \"EntityMutator\", \"InnerObject\", function (Entity, EntityMutator, InnerObject) {\n\n    function OuterObject() {\n    }\n    \n    OuterObject.prototype.innerEntity = new EntityMutator(InnerObject);\n    \n   ... Extra methods\n    return angular.extend(OuterObject, Entity);\n}]).factory('InnerObject', [\"Entity\", \"DateMutator\", \"InnerObject\", function (Entity, DateMutator, InnerObject) {\n\n    function InnerObject() {\n    }\n    \n    InnerObject.prototype.sampleDate = new DateMutator(); //Doesn't need a 'new' unless the mutator has a state\n    \n   ... Extra methods\n    return angular.extend(InnerObject, Entity);\n}]);\n```\nMutators have been written in such a way that the Builder will accept both an Array and an Object.\n```json\n{\"innerEntity\": {\"sampleDate\": \"2016-02-19T15:21:52.000+0000\"}}\n{\"innerEntity\": {\"sampleDate\": [\"2016-02-19T15:21:52.000+0000\",\"2016-02-19T15:21:52.000+0000\"]}}\n```\n#### Creating Mutators\n\n```javascript\n    .factory('DoNothingMutator', [\"Mutator\", function (Mutator) {\n        return function () { //I'd like to point out that I'm 70% sure that I have too many functions here\n            return new Mutator(function (field) {\n               //This mutator does nothing.\n               return field;\n            }, false); //By Changing false to true, you can modify Arrays, rather than the objects in the array itself (If you want to add methods to the arrays)\n        };\n    }]);\n```\n\nIf anyone would like to add a common Mutator type, please do so with a pull-request and I'll merge them into the main branch\n\n\n### EntityAPI\n\n   Most methods in EntityAPI either return EntityAPI or a promise with the exception of delete. \n   (Need ideas here, the api can certainly be improved)\n   \n#### Config\n   \n   `EntityAPIProvider.setApiUrl(\"http://baseurl.com\");` \n   This adds a base url to all EntityApi methods.\n\n   `EntityAPIProvider.setEntityIdentity(\"MyDatabaseIdentifier\");` \n   Defaults to \"id\", With entity identity being defined, arrays gathered by `EntityAPI.get(\"/MyUrl\").as(EntityType);` \n   To have 3 added methods. \n   ```javascript\n   EntityAPI.get(\"/MyUrl\").as(EntityType).then(function(entityTypeArray) {\n      var singleEntity = entityTypeArray.getEntity(5); //Returns EntityType where (entityTypeArray[index].\u003centityIdentity\u003e == 5)\n      var singleEntityIndex = entityTypeArray.getEntityIndex(5); //Returns index where (entityTypeArray[index].\u003centityIdentity\u003e == 5)\n      entityTypeArray.removeEntity(5); //Removes (Splices) the entity where entityIdentity == 5 \n   });\n   ```\n   `EntityAPIProvider.setEntityIdentity(null);` Stops the methods from being added to the arrays.\n   \n   `EntityAPIProvider.setOnError(function(error){});`\n   Adds a function to be called when $http returns an error\n   \n## License\n\nMIT License\n\nCopyright (c) Thomas Nairn\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finlustra%2Fangularentitysystem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finlustra%2Fangularentitysystem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finlustra%2Fangularentitysystem/lists"}