Global Adapters

A collection of adapters for URPC that provide different data storage solutions. Choose the right adapter for your development needs.

Overview

The @unilab/urpc-adapters package provides ready-to-use adapters for URPC, making it easy to get started with different data storage solutions. Whether you need temporary storage for development or persistent storage for production, we have you covered.

Installation

npm install @unilab/urpc-adapters

Available Adapters

Memory Adapter

  • Use case: Development, testing, temporary storage
  • Storage: In-memory (lost on restart)
  • Speed: Fastest access
  • Best for: Development and caching

Mock Adapter

  • Use case: Testing, prototyping
  • Storage: In-memory (lost on restart)
  • Speed: Fast
  • Best for: Unit tests and demos

IndexedDB Adapter

  • Use case: Browser applications
  • Storage: Persistent browser storage
  • Speed: Good performance
  • Best for: Client-side apps, PWAs, offline support

Quick Start

import { URPC } from "@unilab/urpc";
import { MemoryAdapter, MockAdapter, IndexedDBAdapter } from "@unilab/urpc-adapters";
import { UserEntity } from "./entities/user";

const MyPlugin = {
  entities: [UserEntity],
};

URPC.init({
  plugins: [MyPlugin],
  entityConfigs: {
    user: {
      defaultSource: "memory", // Choose your adapter
    },
  },
  globalAdapters: [MemoryAdapter, MockAdapter, IndexedDBAdapter],
});

// Use the repository
const user = await repo({
  entity: UserEntity,
}).create({
  data: {
    id: "1",
    name: "John Doe",
    email: "[email protected]",
  },
});

Choosing the Right Adapter

AdapterPersistenceEnvironmentUse Case
MemoryNoAnyDevelopment, caching
MockNoAnyTesting, prototyping
IndexedDBYesBrowserClient apps, PWAs

Learn More

Get started with the adapter that fits your needs and switch between them as your application grows.