UNPKG

trellis

Version:

Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications

72 lines (70 loc) 1.5 kB
import { entityMutations } from "../chunk-USEINYUL.js"; import { liveEntities, liveEntity } from "../chunk-J3WYZO3Q.js"; import "../chunk-JUEMDWLU.js"; import "../chunk-UBGUDMUV.js"; import "../chunk-2ESYSVXG.js"; // src/svelte/schema-hooks.ts function parseReadOptions(opts) { if (!opts) return {}; if ("resolve" in opts || "where" in opts) return opts; return { where: opts }; } function bindLiveResource(create, project) { const res = create(); let stop = null; let count = 0; return { subscribe(run) { if (count++ === 0) stop = res.start(); const off = res.signal.subscribe((v) => run(project(v))); return () => { off(); if (--count === 0) { stop?.(); stop = null; } }; } }; } function liveListStore(client, schema, opts, project) { return bindLiveResource( () => liveEntities(client, schema, opts), project ); } function entitiesStore(client, schema, opts) { return liveListStore( client, schema, parseReadOptions(opts), (v) => ({ data: v.data, loading: v.loading, error: v.error }) ); } function entityStore(client, schema, id, opts) { return bindLiveResource( () => liveEntity(client, schema, id, opts), (v) => ({ data: v.data, loading: v.loading, error: v.error }) ); } function mutations(client, schema) { return entityMutations(client, schema); } export { entitiesStore, entityStore, mutations };