{"id":21714621,"url":"https://github.com/metroxe/composite-data","last_synced_at":"2025-06-19T02:37:35.512Z","repository":{"id":57204931,"uuid":"115164897","full_name":"Metroxe/composite-data","owner":"Metroxe","description":"A library of data in a composite pattern to be used for validation and organization of data project-wide","archived":false,"fork":false,"pushed_at":"2019-02-24T18:23:59.000Z","size":689,"stargazers_count":16,"open_issues_count":3,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-21T06:39:45.292Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/Metroxe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-23T02:30:51.000Z","updated_at":"2025-02-20T17:42:07.000Z","dependencies_parsed_at":"2022-09-13T19:51:21.918Z","dependency_job_id":null,"html_url":"https://github.com/Metroxe/composite-data","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Metroxe/composite-data","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Metroxe%2Fcomposite-data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Metroxe%2Fcomposite-data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Metroxe%2Fcomposite-data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Metroxe%2Fcomposite-data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Metroxe","download_url":"https://codeload.github.com/Metroxe/composite-data/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Metroxe%2Fcomposite-data/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260673794,"owners_count":23045002,"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":"2024-11-26T00:37:01.582Z","updated_at":"2025-06-19T02:37:30.499Z","avatar_url":"https://github.com/Metroxe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![logo](https://github.com/Metroxe/composite-data/blob/develop/diagrams/data_composite_3000.png?raw=true)\n\n[![npm version](https://badge.fury.io/js/composite-data.svg)](https://badge.fury.io/js/composite-data)\n[![npm](https://img.shields.io/npm/dt/composite-data.svg)](https://www.npmjs.com/package/composite-data)\n[![Build Status](https://travis-ci.org/Metroxe/composite-data.svg?branch=observer)](https://travis-ci.org/Metroxe/composite-data)\n[![GitHub issues](https://img.shields.io/github/issues/Metroxe/composite-data.svg)](https://github.com/Metroxe/composite-data/issues)\n[![GitHub stars](https://img.shields.io/github/stars/Metroxe/composite-data.svg)](https://github.com/Metroxe/composite-data/stargazers)\n\ncomposite-data is a library that stores data in a composite pattern to be used for cross project validation. Implement a front-end application and a server-side application and be able to use the exact same validation processes in both. The library also allows data to be grouped into object to allow for collections of data to be validated simultaneously. Use this library with data storage and singleton's to create robust form components or use it client side to create comprehensive models that are guaranteed to be inflated easily with client side data and verification processes.\n\n## Installation\n\n### yarn\n```\nyarn add composite-data\n```\n\n### npm\n```\nnpm install composite-data --save\n```\n\n## How To Use This Library\nThere are two types of objects that can be instantiated, **DataLeafs and DataComposites**, as well as two interfaces, **IObserver and IObservable**. Each of these are covered below.\n\n### DataLeaf\nThe DataLeaf is the purest form of information, it sits at the bottom level of the composite, and holds a single object. DataLeaf Also uses a template for the value that it contains, this type for the value is defined by `T`. Also it is important to note that each dataLeaf extends the IObservable Interface\n\n#### `getValue(): T`\nThis will return the current value for the data object. So if it is a string then it will return the string for the leaf. If there is no value it will return `undefined`.\n\n#### `getComponent(): DataLeaf\u003cT\u003e`\nThis will return the object itself, over very useful for iteration of multiple different dataLeaves.\n\n#### `set(value: T | any, force?: boolean): boolean | Promise\u003cboolean\u003e`\nTo change the value held by the leaf, use this method. value is the data you want to replace and the function will always return true or false based on if the value passed validation. In some cases where an api call is needed to validate or a promise/callback is involved in the validation, then a promise that returns a boolean will be returned.\n\n#### `updateObservers(): void`\nThis will update all observers of the current value held.\n\n#### `addObserver(observer: IObserver): void`\nAdds another observer to current instance of the DataLeaf.\n\n### DataComposite\nThe DataObserver is a collection of other `IData` (other `DataComposites` or `DataLeaves`) and are organized via a structure define the template variable `P` which is of type `IDataMap`\n\n#### `getValue(): object`\nThis will return a JSON object of all the children of this data composite. An example of Name is below\n\n```typescript\nconst firstName: FirstName = new FirstName(\"Christopher\");\nconst middleName: MiddleName = new MiddleName(\"Vinson\");\nconst lastName: LastName = new LastName(\"Powroznik\");\nconst fullNameMap: IFullNameMap = {\n    firstName,\n    lastName,\n    middleName,\n};\nconst fullName: FullName = new FullName(fullNameMap);\nconst fullNameValue: object = fullName.getValue();\n\nconsole.log(fullNameValue);\n```\n```json\n{\n    \"firstName\": \"Christopher\",\n    \"middleName\": \"Vinson\",\n    \"lastName\": \"Powroznik\",\n}\n```\n\n#### `getComponent(): P`\nthis will return a IDataMap object specified by the template variable `P`\n\n```typescript\nconst firstName: FirstName = new FirstName(\"Christopher\");\nconst middleName: MiddleName = new MiddleName(\"Vinson\");\nconst lastName: LastName = new LastName(\"Powroznik\");\nconst fullNameMap: IFullNameMap = {\n    firstName,\n    lastName,\n    middleName,\n};\nconst fullName: FullName = new FullName(fullNameMap);\nconst fullNameComponent: IFullNameMap = fullName.getComponent();\n\n// fullNameComponent will be deep equal fullNameMap\n```\n\n#### `set(dataMap: P, force?: boolean): boolean | Promise\u003cboolean\u003e`\nAllows a complete reset of the entire dataMap. It is not advised to use this often as it is better practice to edit each dataLeaf, but this method is more efficient if it necessary to replace every DataLeaf.\n```typescript\nconst firstName: FirstName = new FirstName(\"Christopher\");\nconst middleName: MiddleName = new MiddleName(\"Vinson\");\nconst lastName: LastName = new LastName(\"Powroznik\");\nconst fullNameMap: IFullNameMap = {\n    firstName,\n    lastName,\n    middleName,\n};\nconst fullName: FullName = new FullName();\nfullName.set(fullNameMap);\n```\n\n## Design Patterns\nThe library uses two designs patterns extensively, which are the [composite-pattern](https://en.wikipedia.org/wiki/Composite_pattern) and [observer-pattern](https://en.wikipedia.org/wiki/Observer_pattern). These two design patterns are critical to the development and implementation of this library. In this library these two patterns are implemented loosely to the image below.\n\n![model diagram](diagrams/model_diagram.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetroxe%2Fcomposite-data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetroxe%2Fcomposite-data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetroxe%2Fcomposite-data/lists"}