npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@alicanyucelankara06/generic-service

v1.0.0

Published

Angular 21 Generic CRUD Service Package

Readme

@acy/generic-service

Angular 21 için Generic CRUD Service paketi. Tüm entity servisleriniz için temel sınıf sağlar.

Özellikler

  • CRUD OperasyonlarıgetAll, getById, create, update, patch, delete
  • Pagination — Sayfalı veri çekme, sayfa navigasyonu
  • Arama & Filtreleme — Esnek query parametreleri
  • Toplu İşlemlerdeleteMany
  • Angular Signals — Reactive state yönetimi (items, loading, error vb.)
  • Hata Yönetimi — Standart API hata modeli
  • KonfigürasyonInjectionToken ile merkezi ayarlar

Kurulum

npm install @acy/generic-service

Konfigürasyon

app.config.ts içinde:

import { ApplicationConfig, provideHttpClient } from '@angular/core';
import { provideGenericServiceConfig } from '@acy/generic-service';

export const appConfig: ApplicationConfig = {
  providers: [
    provideHttpClient(),
    provideGenericServiceConfig({
      baseUrl: 'https://api.example.com',
      defaultPageSize: 20,
      enableLogging: true,
    }),
  ],
};

Kullanım

1. Entity Model Tanımla

import { BaseEntity } from '@acy/generic-service';

export interface User extends BaseEntity {
  id: number;
  name: string;
  email: string;
  role: 'admin' | 'user';
}

2. Service Oluştur

import { Injectable } from '@angular/core';
import { GenericService } from '@acy/generic-service';
import { User } from './user.model';

@Injectable({ providedIn: 'root' })
export class UserService extends GenericService<User> {
  constructor() {
    super('users'); // API endpoint: https://api.example.com/users
  }
}

3. Component İçinde Kullan

import { Component, inject, OnInit } from '@angular/core';
import { UserService } from './user.service';

@Component({
  selector: 'app-user-list',
  template: `
    @if (userService.loading()) {
      <p>Yükleniyor...</p>
    }

    @if (userService.error(); as error) {
      <p class="error">{{ error.message }}</p>
    }

    @for (user of userService.items(); track user.id) {
      <div (click)="userService.select(user)">
        {{ user.name }} - {{ user.email }}
      </div>
    }

    <div class="pagination">
      <button (click)="userService.previousPage()">Önceki</button>
      <span>{{ userService.currentPage() }} / {{ userService.totalPages() }}</span>
      <button (click)="userService.nextPage()">Sonraki</button>
    </div>
  `,
})
export class UserListComponent implements OnInit {
  protected readonly userService = inject(UserService);

  ngOnInit() {
    this.userService.getPaged().subscribe();
  }
}

4. CRUD İşlemleri

// Tümünü getir
this.userService.getAll().subscribe();

// Sayfalı getir
this.userService.getPaged({ page: 1, pageSize: 10, sort: 'name' }).subscribe();

// ID ile getir
this.userService.getById(1).subscribe();

// Yeni oluştur
this.userService.create({ name: 'Ali', email: '[email protected]', role: 'user' }).subscribe();

// Güncelle
this.userService.update(1, { name: 'Ali Can' }).subscribe();

// PATCH
this.userService.patch(1, { role: 'admin' }).subscribe();

// Sil
this.userService.delete(1).subscribe();

// Toplu sil
this.userService.deleteMany([1, 2, 3]).subscribe();

// Ara
this.userService.search('ali').subscribe();

5. Override Örnekleri

@Injectable({ providedIn: 'root' })
export class ProductService extends GenericService<Product> {
  constructor() {
    super('products');
  }

  // Özel endpoint
  getByCategory(categoryId: number) {
    return this.http.get<Product[]>(`${this.apiUrl}/category/${categoryId}`);
  }

  // buildHttpParams override
  protected override buildHttpParams(params?: QueryParams): HttpParams {
    let httpParams = super.buildHttpParams(params);
    httpParams = httpParams.set('include', 'category,tags');
    return httpParams;
  }
}

API Referansı

GenericService

| Method | Dönüş Tipi | Açıklama | |---|---|---| | getAll(params?) | Observable<T[]> | Tüm kayıtları getirir | | getPaged(params?) | Observable<PagedResponse<T>> | Sayfalı getirir | | getById(id) | Observable<T> | Tek kayıt | | create(item) | Observable<T> | Yeni kayıt | | update(id, item) | Observable<T> | Tam güncelleme | | patch(id, item) | Observable<T> | Kısmi güncelleme | | delete(id) | Observable<void> | Silme | | deleteMany(ids) | Observable<void> | Toplu silme | | search(term, params?) | Observable<T[]> | Arama |

Signals (Readonly)

| Signal | Tip | Açıklama | |---|---|---| | items | Signal<T[]> | Mevcut liste | | selectedItem | Signal<T \| null> | Seçili kayıt | | loading | Signal<boolean> | Yükleniyor mu | | error | Signal<ApiError \| null> | Son hata | | totalCount | Signal<number> | Toplam kayıt | | currentPage | Signal<number> | Mevcut sayfa | | pageSize | Signal<number> | Sayfa boyutu | | totalPages | Signal<number> | Toplam sayfa (computed) | | hasData | Signal<boolean> | Veri var mı (computed) |

Build

npm run build

Lisans

MIT