@relbyte/http
v0.2.0
Published
Hono HTTP adapter for Relbyte — remote embedded database service
Maintainers
Readme
@relbyte/http
Hono tabanlı HTTP adaptörü — Relbyte'ı hafif bir uzaktan gömülü veritabanı servisi olarak sunar.
Hono taşımayı yönetir; Relbyte veritabanı semantiğini yönetir. Core paketinde HTTP bağımlılığı yoktur.
Kurulum
npm install @relbyte/core @relbyte/http hono
# Node.js sunucusu için (opsiyonel):
npm install @hono/node-serverTemel kullanım
import { Relbyte } from '@relbyte/core';
import { createRelbyteApp } from '@relbyte/http';
import { listenNode } from '@relbyte/http/node.js';
const db = await Relbyte.open('./app.relbyte');
const app = createRelbyteApp({ db });
// Node.js
const server = await listenNode(app, { port: 8787 });
console.log(`http://127.0.0.1:${server.port}`);
// Diğer ortamlar (Workers, Bun, Deno): app.fetch doğrudan kullanılabilircreateRelbyteApp() ile listen() ayrı tutulur — aynı Hono uygulaması birden fazla runtime'da çalışabilir.
Kimlik doğrulama
const app = createRelbyteApp({
db,
authorize: async ({ request }) => {
const token = request.headers.get('authorization');
if (token !== `Bearer ${process.env.RELBYTE_TOKEN}`) return null;
return { read: true, write: true, schema: false, stats: false };
},
});Yetkiler: read, write, schema, stats, admin.
Salt okunur mod
createRelbyteApp({ db, mode: 'read-only' });POST /v1/transaction yazma izni olmadan reddedilir.
Sorgu protokolü
POST /v1/query
Content-Type: application/json
{
"table": "users",
"select": ["id", "name"],
"where": [["age", ">=", 18]],
"orderBy": [["createdAt", "desc"]],
"limit": 100,
"offset": 0
}Yanıt:
{
"data": [{ "id": 1, "name": "Alice" }],
"meta": { "count": 1 }
}NDJSON akışı
POST /v1/query?stream=true
Accept: application/x-ndjsonSatır satır JSON döner; bellek kullanımı sonuç boyutuyla değil batch boyutuyla sınırlıdır. İstek iptal edildiğinde (AbortSignal) sorgu durur ve snapshot serbest bırakılır.
İşlem protokolü
POST /v1/transaction
{
"operations": [
{ "op": "insert", "table": "users", "value": { "id": 42, "name": "Ahmet" } },
{ "op": "update", "table": "users", "value": { "id": 42, "name": "Ahmet Y." } },
{ "op": "delete", "table": "users", "primaryKey": 42 }
]
}Tüm işlemler tek db.transaction() içinde atomik olarak çalışır.
Wire format (tipler)
| Relbyte tipi | HTTP JSON |
|----------------|-------------------------------------|
| timestamp_ms | ISO-8601 UTC (2026-09-12T11:00:00.000Z) |
| date | YYYY-MM-DD |
| int64 | ondalık string ("9223372036854775807") |
| bytes | { "$bytes": "base64..." } |
| json | normal JSON |
Limitler
createRelbyteApp({
db,
limits: {
maxBodyBytes: 1_048_576,
maxRows: 10_000,
maxQueryMs: 30_000,
maxTransactionOperations: 1_000,
maxConcurrentQueries: 64,
maxLimit: 10_000,
maxOffset: 1_000_000,
},
});Hata formatı
{
"error": {
"code": "TABLE_NOT_FOUND",
"message": "Table users2 does not exist"
}
}Tam protokol spesifikasyonu: docs/http-protocol-v1.md.
Kapatma
await app.shutdown(); // aktif istekleri reddeder, db.close() çağırır