UNPKG

@m-ld/gateway

Version:

m-ld gateway for services

51 lines (50 loc) 1.96 kB
import type { MeldClone, MeldReadState, MeldState, MeldUpdate, Write } from '@m-ld/m-ld'; import type { BackendLevel } from '../lib/index.js'; import { Subdomain, SubdomainSpec } from '../data/Subdomain.js'; type JsonMeldUpdate = Omit<MeldUpdate, 'trace'>; export interface SubdomainUpdate extends JsonMeldUpdate { /** * The number of times this update has been emitted. A number greater than one * indicates a timeout or restart has lead to uncertainty whether the update * was processed. */ '@emitCount': number; } export declare function tickKey(tick: number): string; /** * Mediates access to the given clone. * * Updates may be emitted by the `update` event, {@link #poll} and {@link #write}, * which emit disjoint sets of updates under normal operation. */ export declare class SubdomainClone extends Subdomain { private readonly _clone; private readonly queueStore; private _state; private events; private _closing; constructor(spec: SubdomainSpec, _clone: MeldClone, backend: BackendLevel); on(eventName: 'echo', listener: (sdu: SubdomainUpdate) => void): this; on(eventName: 'update', listener: (sdu: SubdomainUpdate) => void): this; on(eventName: 'lockRelease', listener: () => void): this; once(eventName: string, listener: (...args: any[]) => void): this; /** Getter omits state, which is managed by this class */ get clone(): Omit<MeldClone, keyof MeldState>; get state(): MeldReadState; private enqueue; private doAndStayLocked; get tick(): number; /** * Report the update queue, incrementing the dequeue count. * LOCKS the state until a `lockRelease` event. */ poll(): AsyncGenerator<SubdomainUpdate>; /** * LOCKS the state until a `lockRelease` event. */ write(request?: Write): Promise<SubdomainUpdate | null>; get locked(): boolean; unlock(): Promise<void>; close(): Promise<void>; } export {};