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.
Type Parameters
Section titled “Type Parameters”T
The model type
S extends true | { [K in string | number | symbol]?: FieldSelection<T[K]> }
The field selection
Parameters
Section titled “Parameters”any
The Edinburgh model class
selection
Section titled “selection”S & ValidateSelection<T, S>
Field selection: true for simple fields, nested object for linked models
options?
Section titled “options?”Optional settings
cache?
Section titled “cache?”number
Seconds the client should linger the stream after out-of-scope, enabling instant reuse and dedup on repeat calls
Returns
Section titled “Returns”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
Section titled “fields”fields:
Record<string,boolean|number>
cache?
Section titled “cache?”
optionalcache?:number
Example
Section titled “Example”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 30sconst PersonStream = createStreamType(Person, { name: true, age: true, friends: { name: true }}, { cache: 30 });
export function streamPerson() { const person = Person.get('Alice')!; return new PersonStream(person);}