UNPKG

@beignet/core

Version:

Core framework primitives for Beignet

45 lines 2.4 kB
import type { StandardSchemaV1 } from "@standard-schema/spec"; /** Browser-visible channel contract. Authorization belongs in a server binding. */ export interface ChannelDefinition<Name extends string = string, Params extends StandardSchemaV1<unknown, Record<string, string>> = StandardSchemaV1<unknown, Record<string, string>>, Events extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>> { readonly kind: "channel"; readonly name: Name; readonly params: Params; readonly events: Events; } export type InferChannelParams<C extends ChannelDefinition> = StandardSchemaV1.InferOutput<C["params"]>; export type InferChannelEvent<C extends ChannelDefinition> = { [Event in keyof C["events"] & string]: { event: Event; data: StandardSchemaV1.InferOutput<C["events"][Event]>; }; }[keyof C["events"] & string]; /** Protocol defaults and safety limits shared by clients, endpoints, and providers. */ export declare const broadcastLimits: Readonly<{ subscriptions: 20; requestBytes: 8192; payloadBytes: 65536; bufferedBytes: 1048576; defaultLifetimeMs: 60000; maxLifetimeMs: 3600000; lifetimeGraceMs: 5000; heartbeatMs: 25000; readyTimeoutMs: 10000; }>; /** Invalid channel configuration or untrusted protocol input. */ export declare class BroadcastValidationError extends Error { constructor(message: string); } export declare function defineChannel<const Name extends string, Params extends StandardSchemaV1<unknown, Record<string, string>>, const Events extends Record<string, StandardSchemaV1>>(name: Name, options: { params: Params; events: Events; }): ChannelDefinition<Name, Params, Events>; /** Provider and transport boundary validation. Uses parsed, canonical parameters. */ export declare function parseChannelParams<C extends ChannelDefinition>(channel: C, input: unknown): Promise<InferChannelParams<C>>; /** Provider and browser boundary validation. Event names select their schema. */ export declare function parseChannelEvent<C extends ChannelDefinition>(channel: C, input: { event: string; data: unknown; }): Promise<InferChannelEvent<C>>; /** Collision-free identity independent of parameter property order. Parse parameters first. */ export declare function channelKey(channel: string, params: Readonly<Record<string, string>>): string; //# sourceMappingURL=index.d.ts.map