{"id":17290270,"url":"https://github.com/somefive/typescript-data-model","last_synced_at":"2025-03-26T18:25:22.980Z","repository":{"id":57383789,"uuid":"98659088","full_name":"Somefive/typescript-data-model","owner":"Somefive","description":"A typescript library that is designed to use data model.","archived":false,"fork":false,"pushed_at":"2017-08-05T17:14:59.000Z","size":87,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T12:08:36.452Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Somefive.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-07-28T14:47:02.000Z","updated_at":"2017-07-28T14:47:15.000Z","dependencies_parsed_at":"2022-09-14T00:21:12.699Z","dependency_job_id":null,"html_url":"https://github.com/Somefive/typescript-data-model","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/Somefive%2Ftypescript-data-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Somefive%2Ftypescript-data-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Somefive%2Ftypescript-data-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Somefive%2Ftypescript-data-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Somefive","download_url":"https://codeload.github.com/Somefive/typescript-data-model/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245710510,"owners_count":20659910,"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-10-15T10:37:34.187Z","updated_at":"2025-03-26T18:25:22.960Z","avatar_url":"https://github.com/Somefive.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Data Model For Typescript\n#### By Somefive\n\nThis library is used for created data model using Class Object based on Typescript. The data model uses decorators to decorate properties. Currently, there are two kinds of decorators: **Scenario** and **Validator**.\n\n## Installing with npm\nRun `npm install --save-dev typescript-data-model`.\n\nThen use `import {Model, scenario, validate} from 'data-model'`\n\nNotices: since this library use decorators and metadata which are experimental, `experimentalDecorators` and `emitDecoratorMetadata` should be enabled in `tsconfig.json` which means you should add\n```json\n\"experimentalDecorators\": true,        /* Enables experimental support for ES7 decorators. */\n\"emitDecoratorMetadata\": true         /* Enables experimental support for emitting type metadata for decorators. */\n```\nto your `tsconfig.json` file.\n\n## Sample\nSample can be found in [sample/index.ts](./sample/index.ts). You can also run `npm run sample` to compile it into sample/dist and run it.\n\n## Introduction\n\n### Model\nThe **Model** class is the base class which can be extended while used. \n\nThe property **scenario** indicates the current scenario of this model and the property **scenarioDefaultIncluded** decides whether a property should be available while there is no ScenarioFilter applied on it.\n\n**isFieldAvailable** check if one specified field is available under current scenario.\n\n**load** can be used to load properties if the property is available and exists in the given object. \n\n**toDocs** can publish current data model to object that contains specified available fields. If no fields specified then all\navailable fields are going to be published. The option `ignoreNil` will ignore the fields that has null or undefined value. It is set to be true by default. The option `force` will skip the availability check and this is set to false by default.\n\n**validate** can validate specified available fields if validators are suppressed on them. If no fields specified then all available fields are going to be published. The option `force` will skip the availability check and this is set to false by default.\n\n*Watch out:* Each field should be initialized in constructor otherwise when it is not defined explicitly, the validation and scenario will not work on it.\n\n### Scenario\nThe **ScenarioFilter** is composed of list of included and excluded scenarios. The **defaultIncluded** is set to decide whether \nthe suppressed property is available if current scenario is neither in included list nor in excluded list.\n\nThe **ScenarioName** includes *string* and *Symbol* types which are the valid parameter types when creating scenarios.\n\nFor example, Model default scenario are set to be *default*, if *default* is in a property's excluded scenario list then it will be unavailable.\n\nScenarios can be enabled by adding **@scenario(scenarioFilter)** to a property. Such as\n```javascript\n@scenario(new ScenarioFilter(false, [\"passwordEnabledScenario\"]))\npassword: string\n```\n\n### Validation\nThe validation is based on interface **IValidator**. Validation will be used when Model call `validation` to check. If the property is not available then it will be skipped by the validation. \n\nValidation can be enabled by adding **@validation(iValidator)** to a property. Such as\n```javascript\n@validate(new RangeValidator(1,100))\nage: number\n```\n\nThere are several validator available in the library and you can also create you own validator just implement the IValidator interface.\n\n**RegexValidator** is using RegExp to validate string.\n**RangeValidator** is using min and max value to check number in range.\n**ArrayValidator** validates arrays. It takes another validator to validate every item. The error will be displayed in object instead of array.\n**NestedValidator** validates nested Model. You can specified what fields are to be validated in nested Model.\n**ChainValidator** can chain validators.\n**PredicateValidator** takes one predicate such as lambda expression to customize the validation which is a bit simplier than implementing a new validator.\n**NotEmptyValidator** checks if string, array, object are empty or undefined.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsomefive%2Ftypescript-data-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsomefive%2Ftypescript-data-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsomefive%2Ftypescript-data-model/lists"}