import type { Ctx } from "./types.ts"; export interface Registry { readonly name: string; readonly conflict: "error" | "last"; /** Type carrier only; never set. */ readonly value?: V; } /** `conflict: "error"` rejects two objects registering one key; `"last"` keeps the later registration. */ export const defineRegistry = (name: string, options: { conflict?: "error" | "last" } = {}): Registry => ({ name, conflict: options.conflict ?? "error", }); export type RegistryTable = ReadonlyMap; export interface RegistryView { /** Table of `ctx.codeVersion`, or of the current code version without ctx. */ table(ctx?: Ctx): RegistryTable; get(key: string, ctx?: Ctx): V | undefined; /** Called with the current table immediately and whenever a new table is installed. */ subscribe(listener: (table: RegistryTable, codeVersion: number) => void): () => void; } export interface Registration { readonly registry: Registry; readonly key: string; readonly value: unknown; }