diff options
Diffstat (limited to 'packages/surface-registry/src/registry.ts')
| -rw-r--r-- | packages/surface-registry/src/registry.ts | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/packages/surface-registry/src/registry.ts b/packages/surface-registry/src/registry.ts index 5780910..840ef5a 100644 --- a/packages/surface-registry/src/registry.ts +++ b/packages/surface-registry/src/registry.ts @@ -6,7 +6,7 @@ import type { SurfaceCatalog, SurfaceCatalogEntry, SurfaceSpec } from "@dispatch * the default/global behaviour. */ export interface SurfaceContext { - readonly conversationId?: string; + readonly conversationId?: string; } /** @@ -14,20 +14,20 @@ export interface SurfaceContext { * Each provider owns one surface identified by its catalog entry id. */ export interface SurfaceProvider { - /** Discovery metadata for the surface catalog. */ - readonly catalogEntry: SurfaceCatalogEntry; + /** Discovery metadata for the surface catalog. */ + readonly catalogEntry: SurfaceCatalogEntry; - /** Build the current surface spec (may be async for dynamic surfaces). */ - getSpec(context?: SurfaceContext): SurfaceSpec | Promise<SurfaceSpec>; + /** Build the current surface spec (may be async for dynamic surfaces). */ + getSpec(context?: SurfaceContext): SurfaceSpec | Promise<SurfaceSpec>; - /** Run a backend action by id with an optional payload. */ - invoke(actionId: string, payload?: unknown, context?: SurfaceContext): void | Promise<void>; + /** Run a backend action by id with an optional payload. */ + invoke(actionId: string, payload?: unknown, context?: SurfaceContext): void | Promise<void>; - /** - * Optional: subscribe to spec changes. Returns an unsubscribe disposer. - * When the spec changes, the caller should re-fetch via getSpec() and push. - */ - subscribe?(onChange: () => void): () => void; + /** + * Optional: subscribe to spec changes. Returns an unsubscribe disposer. + * When the spec changes, the caller should re-fetch via getSpec() and push. + */ + subscribe?(onChange: () => void): () => void; } /** @@ -35,18 +35,18 @@ export interface SurfaceProvider { * `host.getService(surfaceRegistryHandle)`. */ export interface SurfaceRegistry { - /** - * Register a surface provider. Returns an unregister disposer. - * If a provider with the same id is already registered, the new one - * replaces it (last-wins semantics). - */ - register(provider: SurfaceProvider): () => void; + /** + * Register a surface provider. Returns an unregister disposer. + * If a provider with the same id is already registered, the new one + * replaces it (last-wins semantics). + */ + register(provider: SurfaceProvider): () => void; - /** Return discovery metadata for all currently registered providers. */ - getCatalog(): SurfaceCatalog; + /** Return discovery metadata for all currently registered providers. */ + getCatalog(): SurfaceCatalog; - /** Look up a provider by its surface id. */ - getSurface(id: string): SurfaceProvider | undefined; + /** Look up a provider by its surface id. */ + getSurface(id: string): SurfaceProvider | undefined; } /** @@ -54,36 +54,36 @@ export interface SurfaceRegistry { * the decision logic is a plain Map behind the SurfaceRegistry interface. */ export function createSurfaceRegistry(): SurfaceRegistry { - const providers = new Map<string, SurfaceProvider>(); + const providers = new Map<string, SurfaceProvider>(); - return { - register(provider: SurfaceProvider): () => void { - const id = provider.catalogEntry.id; - providers.set(id, provider); + return { + register(provider: SurfaceProvider): () => void { + const id = provider.catalogEntry.id; + providers.set(id, provider); - let disposed = false; - return () => { - if (!disposed) { - disposed = true; - // Only delete if the current entry is still this provider - // (another register with the same id may have replaced it). - if (providers.get(id) === provider) { - providers.delete(id); - } - } - }; - }, + let disposed = false; + return () => { + if (!disposed) { + disposed = true; + // Only delete if the current entry is still this provider + // (another register with the same id may have replaced it). + if (providers.get(id) === provider) { + providers.delete(id); + } + } + }; + }, - getCatalog(): SurfaceCatalog { - const entries: SurfaceCatalogEntry[] = []; - for (const provider of providers.values()) { - entries.push(provider.catalogEntry); - } - return entries; - }, + getCatalog(): SurfaceCatalog { + const entries: SurfaceCatalogEntry[] = []; + for (const provider of providers.values()) { + entries.push(provider.catalogEntry); + } + return entries; + }, - getSurface(id: string): SurfaceProvider | undefined { - return providers.get(id); - }, - }; + getSurface(id: string): SurfaceProvider | undefined { + return providers.get(id); + }, + }; } |
