{"id":16244591,"url":"https://github.com/endykaufman/ngx-repository","last_synced_at":"2025-03-16T12:32:54.704Z","repository":{"id":29825711,"uuid":"122881387","full_name":"EndyKaufman/ngx-repository","owner":"EndyKaufman","description":"Custom repository service for Angular9+, for easy work with the REST backend, with switch on fly from REST backend to the MOCK backend with save and use all CRUD operations","archived":false,"fork":false,"pushed_at":"2024-03-26T22:09:44.000Z","size":5104,"stargazers_count":4,"open_issues_count":38,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-14T13:52:37.289Z","etag":null,"topics":["angular","angular9","class-transformer","class-validator","dynamic","fake-http-client","mock","repository-service","rest"],"latest_commit_sha":null,"homepage":"https://endykaufman.github.io/ngx-repository","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/EndyKaufman.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-25T21:59:04.000Z","updated_at":"2023-06-14T13:30:25.000Z","dependencies_parsed_at":"2024-10-10T14:19:52.932Z","dependency_job_id":"0d8b8a01-9b00-4faf-a424-5da66fe83762","html_url":"https://github.com/EndyKaufman/ngx-repository","commit_stats":{"total_commits":97,"total_committers":2,"mean_commits":48.5,"dds":"0.030927835051546393","last_synced_commit":"ced11d8c1894cf5b0cc9bd22bd3eecc9545d4c83"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EndyKaufman%2Fngx-repository","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EndyKaufman%2Fngx-repository/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EndyKaufman%2Fngx-repository/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EndyKaufman%2Fngx-repository/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EndyKaufman","download_url":"https://codeload.github.com/EndyKaufman/ngx-repository/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814891,"owners_count":20352056,"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":["angular","angular9","class-transformer","class-validator","dynamic","fake-http-client","mock","repository-service","rest"],"created_at":"2024-10-10T14:19:49.190Z","updated_at":"2025-03-16T12:32:54.286Z","avatar_url":"https://github.com/EndyKaufman.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ngx-repository\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/EndyKaufman/ngx-repository.svg)](https://greenkeeper.io/)\n[![Build Status](https://travis-ci.org/EndyKaufman/ngx-repository.svg?branch=master)](https://travis-ci.org/EndyKaufman/ngx-repository)\n[![npm version](https://badge.fury.io/js/ngx-repository.svg)](https://badge.fury.io/js/ngx-repository)\n\n\nCustom repository service for Angular9+, for easy work with the REST backend, with switch on fly from REST backend to the MOCK backend with save and use all CRUD operations\n\n[![How it work](https://img.youtube.com/vi/lEFD8ey82ek/0.jpg)](https://www.youtube.com/watch?v=lEFD8ey82ek)\n\n## Installation\n\n```bash\nnpm i --save ngx-repository\n```\n\n## Links\n\n[Demo](https://endykaufman.github.io/ngx-repository) - Demo application with ngx-repository.\n\n[Stackblitz](https://stackblitz.com/edit/ngx-repository) - Simply sample of usage on https://stackblitz.com\n\n## Usage\n\napp.module.ts\n```js \nimport { NgxRepositoryModule } from 'ngx-repository';\nimport { UsersGridComponent } from './users-grid.component';\n\n@NgModule({\n  imports: [\n    ...\n    NgxRepositoryModule,\n    ...\n  ],\n  declarations: [\n    ...\n    UsersGridComponent,\n    ...\n  ],\n  ...\n})\nexport class AppModule {}\n```\n\nuser-model.ts\n```js \nimport { IModel } from 'ngx-repository';\nimport { IsNotEmpty, IsOptional } from 'class-validator';\nimport { plainToClassFromExist } from 'class-transformer';\n\nexport class UserModel implements IModel {\n    @IsOptional()\n    id: number;\n    @IsNotEmpty()\n    username: string;\n    password: string;\n    constructor(data?: any) {\n        plainToClassFromExist(this, data);\n    }\n}\n```\n\nusers-grid.component.ts\n```js\nimport { Component, OnInit } from '@angular/core';\nimport { DynamicRepository, Repository } from 'ngx-repository';\nimport { UserModel } from './user-model';\nimport { Observable } from 'rxjs';\n\n@Component({\n  selector: 'users-grid',\n  template: `\n\u003cbutton (click)=\"create()\"\u003e Create \u003c/button\u003e\n\u003cul\u003e\n  \u003cli *ngFor=\"let item of items$ | async\"\u003e\n    \u003cspan *ngIf=\"editedUser?.id!==item?.id\"\u003e\n      {{item.username}}\n      \u003cbutton (click)=\"startEdit(item)\"\u003e Edit \u003c/button\u003e\n      \u003cbutton (click)=\"delete(item) \"\u003e Delete \u003c/button\u003e\n    \u003c/span\u003e\n    \u003cspan *ngIf=\"editedUser?.id===item?.id\"\u003e\n      \u003cinput [(ngModel)]=\"editedUser.username\" /\u003e\n      \u003cbutton (click)=\"save(editedUser)\"\u003e Save \u003c/button\u003e\n      \u003cbutton (click)=\"cancel()\"\u003e Cancel \u003c/button\u003e\n    \u003c/span\u003e\n  \u003c/li\u003e\n\u003c/ul\u003e\n  `\n})\nexport class UsersGridComponent implements OnInit {\n  public editedUser: UserModel;\n  public repository: Repository\u003cUserModel\u003e;\n  public items$: Observable\u003cUserModel[]\u003e\n  private mockedItems = [\n    {\n        'username': 'user1',\n        'password': 'password1',\n        'id': 1,\n    }, {\n        'username': 'user2',\n        'password': 'password2',\n        'id': 2,\n    }, {\n        'username': 'user3',\n        'password': 'password3',\n        'id': 3,\n    }, {\n        'username': 'user4',\n        'password': 'password4',\n        'id': 4,\n    }\n  ];\n  constructor(\n    private dynamicRepository: DynamicRepository\n  ) {\n    this.repository = this.dynamicRepository.fork\u003cUserModel\u003e(UserModel);\n  }\n  ngOnInit() {\n    this.repository.useMock({\n        items: this.mockedItems,\n        paginationMeta: {\n            perPage: 2\n        }\n    });\n    /* For real backend\n    this.repository.useRest({\n      apiUrl: environment.apiUrl,\n      paginationMeta: {\n        perPage: 2\n      }\n    });*/\n    this.items$ = this.repository.items$;\n  }\n  startEdit(user: UserModel) {\n    this.editedUser = this.repository.clone(user);\n  }\n  cancel() {\n    this.editedUser = undefined;\n  }\n  save(user: UserModel) {\n    this.repository.save(user).subscribe();\n    this.editedUser = undefined;\n  }\n  create() {\n    this.repository.create(new UserModel({\n      username: 'new user'\n    })).subscribe();\n  }\n  delete(user: UserModel) {\n    this.repository.delete(user.id).subscribe();\n  }\n}\n```\n\napp.component.ts\n```html\n...\n\u003cusers-grid\u003e\u003c/users-grid\u003e\n...\n```\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fendykaufman%2Fngx-repository","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fendykaufman%2Fngx-repository","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fendykaufman%2Fngx-repository/lists"}