@realtime-md/plugin-api-types
v0.1.0
Published
TypeScript type definitions for the Realtime.md Obsidian plugin API (app.plugins.plugins["realtime"]).
Downloads
71
Readme
@realtime-md/plugin-api-types
TypeScript type definitions for the Realtime Obsidian plugin's public API, exposed to other plugins as app.plugins.plugins["realtime"].
Types only — no runtime code. The Realtime plugin itself implements these interfaces, so they cannot drift from the real API.
Install
npm install --save-dev @realtime-md/plugin-api-typesUse
import type { RealtimePluginApi } from "@realtime-md/plugin-api-types";
const realtime = this.app.plugins.plugins["realtime"] as
| (Plugin & RealtimePluginApi)
| undefined;
if (!realtime) return; // Realtime not installed/enabled
// Synced SQLite databases (see the docs/plugin-sql guide):
await realtime.sql.whenAvailable();
const db = await realtime.sql.open({
pluginId: "my-plugin",
name: "main",
schemaVersion: 1,
migrate: async (tx) => {
await tx.exec("CREATE TABLE IF NOT EXISTS items (id TEXT PRIMARY KEY, label TEXT)");
await tx.exec("SELECT crsql_as_crr('items')");
},
});
// Remote cursors (robot identities with audited, Git-attributed edits):
const cursor = await realtime.cursors.acquire({ pluginId: "my-plugin" });
await cursor.notes.append("Log.md", "- did a thing");What's exported
RealtimePluginApi— the root surface (sql,cursors)- SQL:
RealtimeSql,OpenOptions,DatabaseHandle,SqlTx,MigrateFn,DbState,SqlValue,RemoteChange, … - Cursors:
RealtimeCursors,RemoteCursorHandle,CursorNotesApi,CursorNote, … - Replication wire format:
Batch,ChangeRow,Cursor,EncodedVal
For driving the Realtime server (REST, OAuth, streaming) from outside Obsidian, see @realtime-md/sdk.
