Skip to content

createStreamType

createStreamType<T, S>(Model, selection, options?): {(instance): StreamTypeBase<Project<T, S>>; id: number; fields: Record<string, boolean | number>; cache?: number; }

Defined in: server.ts:189

Creates a stream type for reactive model streaming to clients with automatic updates.

Specify which fields to include; when they change, updates are pushed to subscribed clients. Supports nested linked models and type-safe field selection.

T

The model type

S extends true | { [K in string | number | symbol]?: FieldSelection<T[K]> }

The field selection

any

The Edinburgh model class

S & ValidateSelection<T, S>

Field selection: true for simple fields, nested object for linked models

Optional settings

number

Seconds the client should linger the stream after out-of-scope, enabling instant reuse and dedup on repeat calls

Stream type class to instantiate in API functions

{(instance): StreamTypeBase<Project<T, S>>; id: number; fields: Record<string, boolean | number>; cache?: number; }

id: number

fields: Record<string, boolean | number>

optional cache?: number

const Person = E.defineModel('Person', class {
name = E.field(E.string);
age = E.field(E.number);
password = E.field(E.string);
friends = E.field(E.array(E.link(() => Person)));
}, { pk: 'name' });
// Exclude password, include friends' names; cache 30s
const PersonStream = createStreamType(Person, {
name: true,
age: true,
friends: { name: true }
}, { cache: 30 });
export function streamPerson() {
const person = Person.get('Alice')!;
return new PersonStream(person);
}