trellis
Version:
Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications
45 lines • 2.41 kB
TypeScript
/**
* Trellis Svelte — schema-typed, live entity stores.
*
* The Svelte half of the typed read surface. Like the realtime adapter, it takes
* no dependency on the `svelte` package — it returns the structural store
* contract (`subscribe(run) => unsubscribe`), so `$entities` works in markup. The
* store is lazy: the first subscriber opens the {@link liveEntities} subscription
* (live + hydrated) and the last to unsubscribe disposes it. Shipped under
* `trellis/svelte/typed`.
*
* import { defineType } from 'trellis/schema';
* import { entitiesStore, mutations } from 'trellis/svelte/typed';
*
* const sections = entitiesStore(client, NavSection); // {#each $sections.data as s}…
*
* @module trellis/svelte/typed
*/
import { type LiveEntitiesOptions, type LiveEntityOptions } from '../client/live.js';
import type { TrellisDb } from '../client/sdk.js';
import { type EntityMutations } from '../schema/mutations.js';
import type { AnyType, InferEntitiesRead, InferEntityRead, InferType, ResolveSpecFor } from '../schema/define.js';
import type { WhereInput } from '../schema/eql.js';
/** Minimal Svelte store contract (a structural subset of `svelte/store`'s `Readable`). */
export interface Readable<T> {
subscribe(run: (value: T) => void): () => void;
}
export interface TypedRead<T> {
data: T;
loading: boolean;
error: Error | null;
}
export type TypedReadOptions<S extends AnyType> = LiveEntitiesOptions & {
where?: WhereInput;
resolve?: ResolveSpecFor<S>;
};
export type TypedEntityOptions<S extends AnyType> = LiveEntityOptions & {
resolve?: ResolveSpecFor<S>;
};
/** Live list of a type as a Svelte store. */
export declare function entitiesStore<S extends AnyType, O extends Partial<InferType<S>> | TypedReadOptions<S> | undefined = undefined>(client: TrellisDb, schema: S, opts?: O): Readable<TypedRead<InferEntitiesRead<S, O>>>;
/** Live single entity by id as a Svelte store — read-first, then type subscription. */
export declare function entityStore<S extends AnyType, O extends TypedEntityOptions<S> | undefined = undefined>(client: TrellisDb, schema: S, id: string | null | undefined, opts?: O): Readable<TypedRead<InferEntityRead<S, O>>>;
/** Schema-typed create/update/remove. */
export declare function mutations<S extends AnyType>(client: TrellisDb, schema: S): EntityMutations<InferType<S>>;
//# sourceMappingURL=schema-hooks.d.ts.map