• Joined on 2026-01-27

sourcedb-client (0.1.0)

Published 2026-06-03 07:11:58 +00:00 by hibna

Installation

registry=https://gits.hibna.com.tr/api/packages/hibna/npm/
npm install sourcedb-client@0.1.0
"sourcedb-client": "0.1.0"

About this package

sourcedb-client

SourceDB'nin HTTP/JSON API'si için tipli, bağımlılıksız JavaScript/TypeScript istemcisi. Node 18+ (global fetch) ve modern tarayıcılarda çalışır; derleme adımı yok.

Sunucuyu çalıştırın:

sourcedb --serve-http 127.0.0.1:7878 --db ./db

Kurulum

npm install sourcedb-client

Not: paket adı kayıt defterinde doluysa kendi kapsamınızla yayınlayın (@kullanici/sourcedb) ya da Gitea npm registry'sini kullanın.

Kullanım

import { SourceDB } from "sourcedb-client";

const db = new SourceDB("http://127.0.0.1:7878", { token: "gizli" }); // token isteğe bağlı

// Sunucu / gözlem
await db.health();                       // { status: "ok" }
await db.metrics();                      // sorgu/gecikme sayaçları
await db.resources();                    // { cpu_percent, rss_bytes, disk_bytes, ... }
await db.tables();                       // [{ name, engine }]
await db.createTable("users", "Collection");
await db.tableStats("users");            // "engine=Collection records=…"

// KeyValue (değerler string olarak saklanır)
const kv = db.kv("oturumlar");
await kv.put("sess:1", "token-abc");
await kv.get("sess:1");                  // "token-abc" | null
await kv.keys({ limit: 100 });           // ["sess:1", ...]
await kv.delete("sess:1");

// Collection (tipli alanlar + ikincil/tam-metin indeks)
const c = db.collection("users");
await c.createIndex("email", { unique: true });
await c.createTextIndex("bio");
await c.put("user:1", { ad: "Ali Veli", email: "ali@x.com", yas: 30, aktif: true, bio: "rust sever" });
await c.get("user:1");                   // { ad, email, yas, aktif, bio } | null
await c.find({ email: "ali@x.com" });    // ["user:1"]
await c.search("bio", "rust", "and");    // ["user:1"]
await c.records({ limit: 50 });          // [{ pk, fields }]
await c.delete("user:1");

// Log (kullanıcı başına akış)
const log = db.log("bildirimler");
await log.append(7, "merhaba");
await log.recent(7, 20);                 // ["merhaba", ...] en yeni → eski

// Odds (oran eşleştirme)
const odds = db.odds("maclar");
await odds.add(1, [{ source: 0, market: "1X2", outcome: 0, value: 1.85 }]);
await odds.match([{ source: 0, market: "1X2", outcome: 0, value: 1.85 }], { tolerance: 0 });
await odds.stats();

Hata yönetimi

Başarısız istekler SourceDBError fırlatır (.status = HTTP kodu):

import { SourceDBError } from "sourcedb-client";
try {
  await db.collection("users").put("user:9", { email: "ali@x.com" }); // benzersiz ihlali
} catch (e) {
  if (e instanceof SourceDBError && e.status === 409) console.log("çakışma:", e.message);
}

TypeScript

Tipler pakette gömülü (index.d.ts); ek @types gerekmez.

import { SourceDB, type CollectionRecord } from "sourcedb-client";
const db = new SourceDB();
const recs: CollectionRecord[] = await db.collection("users").records();

Keywords

sourcedb database client kv key-value fulltext odds log
Details
npm
2026-06-03 07:11:58 +00:00
4
MIT
4.2 KiB
Assets (1)
Versions (5) View all
0.5.4 2026-06-11
0.5.2 2026-06-11
0.5.1 2026-06-11
0.3.0 2026-06-10
0.1.0 2026-06-03