/prometheus-react-skills:entity-realtime-surreal-livefrom prometheus-react-skills
Wire SurrealDB LIVE SELECT subscriptions into a Prometheus entity graph via createSurrealLiveAdapter. Covers select-then-live seeding, CREATE/UPDATE/DELETE action mapping, reconnect with exponential backoff, and optional checkpoint-based replay on reconnect.
Ships in prometheus-react-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Hook up SurrealDB's live-query stream to the Prometheus entity graph.
surrealdb.js / surrealdb).useEntity, useEntityList,
useGQLEntity) to update in real time as rows change server-side, no
per-component subscription wiring.If you're on ElectricSQL + PGlite, see entity-realtime-channel /
entity-realtime-local-first instead.
LIVE SELECT per registered table, opened at app startup and
re-opened automatically after reconnects.select-then-live mode, default) so the graph is
populated before the first render — or skip the seed entirely with
live-only mode.EntityChange mapping handled inside the adapter; each
emitted ChangeSet carries affectedListKeys so derived lists refresh.checkpointStore + checkpointField to replay missed updates
after a disconnect.// app-init.ts
import {
createSurrealLiveAdapter,
getRealtimeManager,
type ChannelConfig,
type SurrealLike,
type SurrealTableConfig,
} from "@prometheus-ags/prometheus-entity-management";
// your already-connected Surreal client (see surreal-client.ts in your app)
declare const db: SurrealLike;
const tables: SurrealTableConfig[] = [
{ type: "client", table: "client" },
{ type: "deal", table: "deal" },
{ type: "contact", table: "contact" },
];
const adapter = createSurrealLiveAdapter({
surreal: db,
tables,
initialQueryStrategy: "select-then-live",
});
const channels: ChannelConfig[] = tables.map(({ type }) => ({ type }));
getRealtimeManager().register(adapter, channels);
That's it — every consumer of useEntity, useEntityList, etc. now
receives live updates as the underlying rows change.
Scope tenancy at the connection layer: give each tenant its own
authenticated Surreal client (namespace / database / credentials) and its own
adapter instance with a distinct name, and re-register on tenant change:
import {
createSurrealLiveAdapter,
type SurrealLike,
type SurrealTableConfig,
} from "@prometheus-ags/prometheus-entity-management";
declare const tenantId: string;
declare const tenantDb: SurrealLike; // client connected with this tenant's credentials
declare const tenantTables: SurrealTableConfig[];
const tenantAdapter = createSurrealLiveAdapter({
name: `surreal-live:${tenantId}`,
surreal: tenantDb,
tables: tenantTables,
});
The adapter pulls entity ids via idField (default "id"). When the
SurrealDB row shape differs from your entity model (for example snake_case
columns), map changes with the normalize argument to
RealtimeManager.register(adapter, channels, normalize) rather than inside
components.
For offline-tolerant apps, supply a checkpointStore. The adapter persists
the latest checkpointField value it has seen (default "updated_at"), and
on reconnect runs SELECT * FROM <table> WHERE <field> > <stored> per table
before re-attaching the live stream:
import {
createSurrealLiveAdapter,
type SurrealCheckpointStore,
type SurrealLike,
type SurrealTableConfig,
} from "@prometheus-ags/prometheus-entity-management";
declare const db: SurrealLike;
declare const tables: SurrealTableConfig[];
declare const localforage: {
getItem<T>(key: string): Promise<T | null>;
setItem(key: string, value: string): Promise<unknown>;
};
const checkpointStore: SurrealCheckpointStore = {
get: (key) => localforage.getItem<string>(key).then((value) => value ?? undefined),
set: (key, value) => localforage.setItem(key, value).then(() => undefined),
};
const adapter = createSurrealLiveAdapter({
surreal: db,
tables,
checkpointField: "updated_at",
checkpointStore,
});
UPDATE actions to
op: "upsert" (not "update"), because SurrealDB doesn't distinguish
partial vs full updates on the wire. The engine handles upsert
semantics correctly.{id}, sometimes the full
prior row. The adapter pulls id defensively.affectedListKeys performance. List-key lookup is derived per
ChangeSet emit; supply listKeyResolver to override the default mapping.
Profile in apps with very high update rates; defer optimisation until it
shows up.Canonical behavior reference:
packages/entity-graph-core/src/adapters/surreal-live.test.ts. The
vitest suite uses a hand-rolled fake Surreal client (no live database
needed) and covers every action mapping, reconnect, and replay scenario.
Run from the entity-management repo root:
pnpm test packages/entity-graph-core/src/adapters/surreal-live.test.ts
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub prometheus-ags/prometheus-skill-system --plugin prometheus-react-skills28 skills in this plugin
/entity-auditSlash command /entity-audit — run full codebase audit against @prometheus-ags/prometheus-entity-management CLAUDE.md rules: component/store boundaries, hook I/O, registerSchema coverage, JSDoc on public hooks, and realtime/list patterns. Produces a severitized report using references/audit-checklist.md.
/entity-crud-formBuild EntityFormSheet and EntityDetailSheet configurations from FieldDescriptor arrays: field types, enum options, readonly/create/edit flags, custom editControl/render, and wiring to useEntityCRUD buffers and actions.
/entity-crud-pageScaffold a full CRUD page (list, create, edit, detail, delete) using useEntityCRUD with EntityTable, EntityDetailSheet, and EntityFormSheet. Enforces Components → Hooks → Stores: page composes only; useXxxCRUD hook wraps library CRUD; API module holds fetch/mutations.
/entity-crud-relationsRegister EntitySchema graphs with registerSchema: belongsTo, hasMany, manyToMany, listKeyPrefix alignment, invalidateTargetLists, globalListKeys, and verification that cascadeInvalidation matches list query keys.
/entity-crud-tableBuild EntityTable views with column helpers (textColumn, numberColumn, enumColumn, etc.), SortHeader, selectionColumn, and meta.entityMeta for filters; sync sorting and search with useEntityView via UseEntityViewResult.
/entity-gcSlash command /entity-gc — design application-level eviction for @prometheus-ags/prometheus-entity-management: removeEntity for stale entities, clearPatch for UI overlays, list refresh after bulk delete, route-based cleanup, and policies for long-lived sessions. Notes library has no automatic GC yet.
2 plugins in one repository ship this exact skill · first indexed Nov 27, 2026