import type { Hono } from 'hono' import type * as App from '../App.js' // Hono's `.route()` drops sub-app metadata, so a group's OpenAPI metadata can't // ride the instance through it. Each group attaches its metadata here and // `App.create` reads it back on mount. The `WeakMap` keeps the association off // the app's type, so `testClient`/`hc` inference is untouched. const registry = new WeakMap, App.create.Metadata>() const defaultChainRegistry = new WeakSet>() /** Attaches a group's OpenAPI metadata to its app instance for `create` to collect on mount. */ export function attach>( app: app, metadata: App.create.Metadata, ): app { registry.set(app, metadata) return app } /** Reads the OpenAPI metadata attached to an app instance, if any. */ export function read(app: Hono): App.create.Metadata | undefined { return registry.get(app) } /** Marks a group whose routes use the root app's default chain access policy. */ export function defaultChain>(app: app): app { defaultChainRegistry.add(app) return app } /** Returns whether a group uses the root app's default chain access policy. */ export function usesDefaultChain(app: Hono): boolean { return defaultChainRegistry.has(app) }