npm.io
0.1.15 • Published 5d ago

@hono-crud/memory

Licence
MIT
Version
0.1.15
Deps
0
Size
60 kB
Vulns
0
Weekly
237

@hono-crud/memory

In-memory CRUD adapter for hono-crud. Ideal for tests, demos, and prototyping — no database required.

Install

npm install @hono-crud/memory hono-crud hono zod

Usage

import { Hono } from 'hono';
import { defineMeta, defineModel, fromHono, registerCrud } from 'hono-crud';
import {
  MemoryCreateEndpoint,
  MemoryListEndpoint,
  MemoryReadEndpoint,
  clearStorage,
} from '@hono-crud/memory';
import { z } from 'zod';

const UserSchema = z.object({ id: z.uuid(), name: z.string() });
const UserModel = defineModel({ tableName: 'users', schema: UserSchema, primaryKeys: ['id'] });
const userMeta = defineMeta({ model: UserModel });

class UserCreate extends MemoryCreateEndpoint { _meta = userMeta; }
class UserRead extends MemoryReadEndpoint { _meta = userMeta; }
class UserList extends MemoryListEndpoint { _meta = userMeta; }

const app = fromHono(new Hono());
registerCrud(app, '/users', { create: UserCreate, read: UserRead, list: UserList });

// Reset the in-memory store (handy in tests)
clearStorage();

Exports the Memory*Endpoint classes, the MemoryAdapters bundle, and the getStore / clearStorage helpers.

Keywords