Socket
Book a DemoInstallSign in
Socket

cca-core

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cca-core

A lightweight TypeScript framework for building modular and maintainable applications with TypeORM integration.

0.2.18
latest
npmnpm
Version published
Weekly downloads
95
-71.3%
Maintainers
1
Weekly downloads
 
Created
Source

CCA-Core

A lightweight TypeScript framework for building modular and maintainable applications with TypeORM integration.

Installation

npm install cca-core

Overview

CCA-Core provides a set of base classes and interfaces to help structure your application following best practices. The library focuses on:

  • Dependency injection container pattern
  • Repository pattern for data access
  • Service pattern for business logic
  • Caching mechanism
  • Error handling
  • Pagination utilities

Core Components

Container

The BaseContainer class serves as a dependency injection container for your application:

import { BaseContainer, BaseDatabase } from "cca-core";

const container = new BaseContainer({
  database: myDatabase,
  // Optional: custom cache service, mapper
});

// Register repositories and services
container.registerRepository("userRepository", userRepository);
container.registerService("userService", userService);

// Initialize the container
await container.initialize();

// Access registered components
const userRepo = container.getRepository("userRepository");
const userService = container.getService("userService");

Database

The BaseDatabase abstract class provides a foundation for database connections:

import { BaseDatabase } from "cca-core";
import { DataSource } from "typeorm";

class MyDatabase extends BaseDatabase {
  constructor() {
    super(
      new DataSource({
        /* typeorm config */
      })
    );
  }

  async connect(): Promise<void> {
    await this.dataSource.initialize();
  }

  async disconnect(): Promise<void> {
    await this.dataSource.destroy();
  }
}

Repository

The BaseRepository class implements common CRUD operations:

import { BaseRepository } from "cca-core";
import { User } from "./entities/User";

class UserRepository extends BaseRepository<User> {
  // Add custom repository methods here
}

Key features include:

  • CRUD operations (create, update, delete, find)
  • Pagination support
  • Soft delete pattern
  • Error handling

Caching

The BaseCacheService provides in-memory caching with TTL support:

import { BaseCacheService } from "cca-core";

const cache = new BaseCacheService();
await cache.set("key", value, 3600); // Cache for 1 hour
const cachedValue = await cache.get("key");

Utilities

Helpful utility functions:

  • ConfigManager(): ConfigManager manages application configuration, supporting async loading, type safety, and notifications when configuration is available.
  • generateSlug(): Convert a string to a URL-friendly slug
  • validateRepository(): Validate a repository instance

Interfaces

The module provides type-safe interfaces:

  • IBaseEntity: Core entity interface
  • IBaseRepository: Repository interface
  • IExtendedBaseRepository: Extended repository interface
  • IBaseService: Service interface
  • IBaseCacheService: Cache service interface
  • IPaginationOptions: Pagination request options
  • IPaginatedResult: Paginated response structure

Error Handling

Built-in error handling with the BaseError class and utility functions.

Example Usage

import {
  BaseContainer,
  BaseDatabase,
  BaseRepository,
  generateSlug,
} from "cca-core";

// Set up database
class MyDatabase extends BaseDatabase {
  // implementation
}

// Create repositories
class UserRepository extends BaseRepository<User> {
  // custom methods
}

// Create container
const container = new BaseContainer({
  database: new MyDatabase(),
});

// Register components
container.registerRepository("users", new UserRepository(/* ... */));

// Initialize
await container.initialize();

// Use the container
const userRepo = container.getRepository("users");
const users = await userRepo.getAll();

// Use utilities
const slug = generateSlug("My Article Title"); // "my-article-title"

License

MIT License - Copyright (c) 2025 Mindaugas Baltrunas

FAQs

Package last updated on 28 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.