/**
* `mount` — the *server* implementation, selected automatically in a React
* Server Component graph via the package's `react-server` export condition.
*
* It is the exact twin of the client `mount` (see `../react/rec.tsx`): same
* name, same arguments, the same compile-time check that `layer` provides every
* service the tree needs. The difference is invisible to you — the bundler hands
* server components this version, which drives the REC against an Effect runtime
* and returns an *async React Server Component* (no hooks, no client JS). You
* import `mount` from `@tmonier/effract` in every file; where it runs decides
* which implementation you get.
*
* ```tsx
* // app/page.tsx — a React Server Component
* const Page = rec(function* () {
* return {yield* StatsBadge}; // resolved on the server
* });
* export default mount(AppLive, Page); // same call as on the client
* ```
*/
import type { ReactNode } from 'react';
import * as Layer from 'effect/Layer';
import * as ManagedRuntime from 'effect/ManagedRuntime';
import { driveServerRec } from '#application/server-driver.ts';
import { QueryCache, queryCacheNoop } from '#infrastructure/query-cache.ts';
import type { Effective, MissingServices, REC } from '#infrastructure/rec-core.tsx';
/**
* A self-contained runtime: every service the tree needs is already provided.
* Typed with `never` requirements so any concrete app runtime (which provides
* *some* services) is assignable — the requirement channel is contravariant.
*/
type ServerRuntime = ManagedRuntime.ManagedRuntime;
/**
* Shared runtimes, one per layer identity — used only under `{ scope: 'shared' }`.
* The default is a *fresh* runtime per render (see below), so this is opt-in.
*/
const sharedRuntimes = new WeakMap