Mock Adapter

Mock Adapter is a simple in-memory adapter for URPC that provides temporary data storage during application runtime. It's perfect for testing, prototyping, and development scenarios where you don't need persistent data storage.

Basic Usage

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

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

URPC.init({
  plugins: [MyPlugin],
  entityConfigs: {
    user: {
      defaultSource: "mock",
    },
  },
  globalAdapters: [
    {
      source: "mock",
      factory: () => new MockAdapter(),
    },
  ],
});

Creating Data

async function createUser() {
  await repo<UserEntity>({
    entity: "user",
  }).create({
    data: {
      id: "1",
      name: "John Doe",
      email: "[email protected]",
      avatar: "https://example.com/avatar.png",
    },
  });
}

Querying Data

async function getUsers() {
  const users = await repo({
    entity: "user",
  }).findMany();

  console.log("All users:", users);
}