/** Reaches the application's own backend. The path is resource-relative. */ type UiBootstrapFetcher = (path: string) => Promise; /** Why a resource fell back. Kept coarse enough to be worth alerting on. */ type UiBootstrapFailureReason = "fetch-failed" | "response-not-ok" | "invalid-json" | "invalid-envelope" | "invalid-payload"; /** * What the application learns about a fallback. * * Deliberately narrow. Response bodies, headers, cookies, and raw thrown * values never appear here — a branding endpoint answering with a stack trace * or a `Set-Cookie` must not become a log line. `error` is a normalized * summary, never the thrown value itself. */ interface UiBootstrapDiagnostic { resource: string; reason: UiBootstrapFailureReason; path: string; /** Present for `response-not-ok`. */ status?: number; /** Present when something was thrown; `": "` for an `Error`. */ error?: string; } interface UiBootstrapResource { /** Passed to the fetcher unchanged. */ path: string; /** * Narrows the endpoint payload to the application's own type. * * Return `undefined` or throw to reject it — both are the same answer, so a * parser built from `undefined` guards and one built from a schema that * throws are equally usable without a wrapper. */ parse: (input: unknown) => T | undefined; /** * The built-in value, used whenever the endpoint cannot produce a valid one. * * A function, not a value: it is called per load, so an application that * returns a fresh object keeps loads independent. Its failure is *not* * caught — a missing factory theme is a broken build, and a second fallback * would only hide it. */ fallback: () => T; /** Per-resource envelope override. Defaults to the loader-level `select`. */ select?: (payload: unknown) => unknown; } /** * Resources keyed by name. * * `any` rather than `unknown` in the value position: the payload types are * unrelated to each other, and `UiBootstrapResource` is not a * supertype of `UiBootstrapResource` — `parse` and `fallback` * make `T` invariant, so every concrete configuration would fail the * constraint. Inference recovers the real type through `UiBootstrapValue`. */ type UiBootstrapResources = Record>; type UiBootstrapValue = R extends UiBootstrapResource ? T : never; /** The resolved value of every configured resource, keyed by resource name. */ type UiBootstrapSnapshot = { [K in keyof R]: UiBootstrapValue; }; interface UiBootstrapConfig { fetcher: UiBootstrapFetcher; resources: R; /** * Unwraps the endpoint response. * * Defaults to Najm's `{ data }` envelope. Applications behind a different * envelope — or none — pass their own; returning the payload unchanged is a * valid selector, and throwing rejects the response as `invalid-envelope`. */ select?: (payload: unknown) => unknown; /** * Called once per fallback, never for a successful load. * * Optional because there is no sensible default: a package cannot know * whether this application wants `console.warn`, a counter, or a pager. Its * own failure is contained — an observability fault must not take the render * with it. */ onDiagnostic?: (diagnostic: UiBootstrapDiagnostic) => void; } interface UiBootstrapLoader { /** Every resource, loaded concurrently. */ load(): Promise>; /** One resource on its own. */ loadResource(name: K): Promise[K]>; /** `loadResource` pre-bound per name, for destructuring into a facade. */ loaders: { [K in keyof R]: () => Promise[K]>; }; } declare function createUiBootstrapLoader(config: UiBootstrapConfig): UiBootstrapLoader; export { type UiBootstrapConfig as U, type UiBootstrapDiagnostic as a, type UiBootstrapFailureReason as b, type UiBootstrapFetcher as c, type UiBootstrapLoader as d, type UiBootstrapResource as e, type UiBootstrapResources as f, type UiBootstrapSnapshot as g, type UiBootstrapValue as h, createUiBootstrapLoader as i };