FetchConfig.server
property · packages/remote-server/src/fetch.ts:91
readonly server: ServerDefinition<P, R>The server definition, as RemoteServer.make built it.
Remote / foldkit-remote-server/fetch
interface · packages/remote-server/src/fetch.ts:89
interface FetchConfig<P, R, Env, RP = never> {
readonly server: ServerDefinition<P, R>
readonly resolvePrincipal: (
request: ScriptedRequest,
env: Env,
) => Effect.Effect<P, RemoteUnauthenticated, RP>
readonly layer: (env: Env) => Layer.Layer<R | RP>
readonly path?: string | undefined
readonly headers?:
((principal: P) => Readonly<Record<string, string>>) | undefined
readonly live?: LiveHub<P, R> | undefined
readonly revalidate?:
| {
readonly every: Duration.Input
readonly key?: ((principal: P) => unknown) | undefined
}
| undefined
readonly liveHeartbeat?: Duration.Input | undefined
readonly diagnostics?:
| ((diagnostic: Diagnostic, request: Request) => Effect.Effect<void>)
| undefined
readonly maxIdsPerEntity?: number | undefined
readonly maxDepth?: number | undefined
readonly runtime?:
ManagedRuntime.ManagedRuntime<NoInfer<R | RP>, never> | undefined
readonly maxBodyBytes?: number | undefined
readonly cache?:
| {
readonly store: CacheStore
readonly visitor: P
readonly check?: boolean | undefined
}
| undefined
}What serveFetch needs of the host runtime, per request.
FetchConfig.serverproperty · packages/remote-server/src/fetch.ts:91
readonly server: ServerDefinition<P, R>The server definition, as RemoteServer.make built it.
FetchConfig.resolvePrincipalproperty · packages/remote-server/src/fetch.ts:99
readonly resolvePrincipal: (
request: ScriptedRequest,
env: Env,
) => Effect.Effect<P, RemoteUnauthenticated, RP>Who this request is, from the request and the environment. Fails with
RemoteServer.unauthenticated(reason?) to refuse the caller: a 401.
What it needs (a session store, an auth service) comes from layer.
A resolver taking any Request fits; one typed for a navigation
(NavigationRequest) does not, since /remote writes.
FetchConfig.layerproperty · packages/remote-server/src/fetch.ts:108
readonly layer: (env: Env) => Layer.Layer<R | RP>What the Sources and the resolver need, from the environment. Built per request, so kept cheap, and closed when the answer is sent, or, for a live stream, when the stream ends.
FetchConfig.pathproperty · packages/remote-server/src/fetch.ts:110
readonly path?: string | undefinedThe path answered; anything else is a 404. Default /remote.
FetchConfig.headersproperty · packages/remote-server/src/fetch.ts:117
readonly headers?:
((principal: P) => Readonly<Record<string, string>>) | undefinedHeaders every answer to principal carries, a live stream's included;
a refusal has no principal and carries none. Whom the request was
answered as, say, for a client to repeat (foldkit-auth's
AuthServer.answered).
FetchConfig.liveproperty · packages/remote-server/src/fetch.ts:119
readonly live?: LiveHub<P, R> | undefinedA hub whose changed/deleted signals reach the live streams this serves.
FetchConfig.revalidateproperty · packages/remote-server/src/fetch.ts:131
readonly revalidate?:
| {
readonly every: Duration.Input
readonly key?: ((principal: P) => unknown) | undefined
}
| undefinedAsks resolvePrincipal again, of the same request, every every while a
live stream is open. A refusal ends the stream with Unauthenticated,
which the client reads as a lost session; a principal whose key
differs from the one the stream opened with (Policy.keyOf, as
liveHub's key) ends it as a live error, which the client opens again
after, as the new principal; without key only a refusal ends it.
Without revalidate a stream serves the principal it opened with until
it closes, a revoked session included.
every must be longer than zero: each pass asks the session store.
FetchConfig.liveHeartbeatproperty · packages/remote-server/src/fetch.ts:138
readonly liveHeartbeat?: Duration.Input | undefinedA heartbeat comment every this often, keeping idle streams alive through proxies. Default 15 seconds.
FetchConfig.diagnosticsproperty · packages/remote-server/src/fetch.ts:146
readonly diagnostics?:
| ((diagnostic: Diagnostic, request: Request) => Effect.Effect<void>)
| undefinedWhere this request's diagnostics go, with the request: each failure
answered "Internal error" or ending a live stream (a ServerDefect: a
broken layer or resolver, a handler's defect), whose cause the caller is
never told, and what the handlers report. The reporter in the Effect
context (Diagnostics.Reporter) when not given, by default the log.
FetchConfig.maxIdsPerEntityproperty · packages/remote-server/src/fetch.ts:150
readonly maxIdsPerEntity?: number | undefinedA read batch may not name more ids of one entity than this; default 1000.
FetchConfig.maxDepthproperty · packages/remote-server/src/fetch.ts:152
readonly maxDepth?: number | undefinedA nested selection may not reach further than this many levels; default 8.
FetchConfig.runtimeproperty · packages/remote-server/src/fetch.ts:158
readonly runtime?:
ManagedRuntime.ManagedRuntime<NoInfer<R | RP>, never> | undefinedOptional shared ManagedRuntime for long-lived servers (Node/Bun). When
supplied, each request runs directly on this runtime instead of building
layer(env) fresh per request (which remains the default for Workers).
FetchConfig.maxBodyBytesproperty · packages/remote-server/src/fetch.ts:166
readonly maxBodyBytes?: number | undefinedA request body may not be larger than this many bytes; default 1 MiB. A
larger one is a 413 with Remote's tooLarge answer, refused before it is
decoded: by its content-length before the principal is resolved, or
once the bytes read pass the limit. Give the client the same number
(Remote.clientLayer(…, { maxBodyBytes })), so it cuts its reads to fit.
FetchConfig.cacheproperty · packages/remote-server/src/fetch.ts:187
readonly cache?:
| {
readonly store: CacheStore
readonly visitor: P
readonly check?: boolean | undefined
}
| undefinedKeeps public reads in store (#428). A read or query is public where
none of the sources it passes through has a rule about who asks
(authorize, filter, visible, a member per viewer) and each declares
how long it stays fresh (EdgeCache.of on its Entity, cache on its
Query). A public read is answered as visitor, whoever asks, so one
answer is right for everyone, and kept for the shortest maxAge it
reaches; it says cache-control: public, max-age=…. Every other answer
says private, no-store. A write answered here purges the kept reads
holding a row it names, and every list of that row's entity.
store is a CacheStore, which serves nothing past its maxAge: an
answer carries no age, so one kept longer would read as fresh. A
PageCacheStore (CacheStore.kv with keep) is refused.
visitor is the principal of someone not signed in: refused when the
server's viewer names a row for it. With check, for development and
tests, each public read is also answered as who asks, and a difference
is reported (CachedReadDiffers) and answered with the asker's own.