An entity source. Given the Entity, every member it declares (fields,
relations, derived members) may be requested; given anything with a
name and fields, those fields. A request for anything else never
reaches read or authorize. Given only a name, every field passes.
A refusal of mutation, as a value of its declared Refusal: fail a
Source with it (yield* RemoteServer.refuse(SavePost, { _tag: 'Field', ... }))
and the client reads it, decoded, with Data.refusal. message is what a
person reads, beside it.
A failure whose message the caller reads as it is: fail a Source with it
(yield* RemoteServer.tell('That report is still being built')) for words
written for whoever asked. Every other RemoteServerError is this side's:
reported, and answered "Internal error". It takes text, not what was
caught: an error's own message may say anything.
Reports a failure on this side that no handler answers, as the server
reports its own: a scheduled job's, or an adapter's on a transport of its
own. cause goes to a ServerDefect under a new incident, with during
(what was being done: publish due e3). It answers what a caller may be
told of it, the fixed words and that id, and nothing of cause.
A writer's refusal of a row that does not hold the write's when: fail
update or delete with it (yield* RemoteServer.unmet()), and
RemoteServer.write answers the mutation's Unmet refusal.
A writer's refusal of an insert whose id a row already holds: fail
insert with it (yield* RemoteServer.taken()), and RemoteServer.write
answers the mutation's Taken refusal, naming the Entity and the id.
A writer's refusal of a row that would break an invariant: fail update
or insert with it, naming the invariant's id and path when the caller
may be told them, and RemoteServer.write answers the mutation's
Invalid refusal.
A refusal of who is asking: fail a Source with it
(yield* RemoteServer.forbid()) and the write never runs. reason, when
given, is what the person who asked reads; without it the refusal says
nothing of why. answer sends it as a 403, and the client's mutation
fails with _tag: 'Forbidden'.
A refusal of a caller who could not be told: a serveFetch or
defineDocumentHost resolver fails with it (RemoteServer.unauthenticated())
when the credential it was sent no longer holds, and a write refused to a
visitor fails with it (GuardServer does), so a client can tell a session
that ended from a refusal. It answers 401, with reason, when given, for
the person who asked; a durable write so answered waits for a sign-in.
The Source of a mutation that is a declared Write, with no handler: the
input bound to the write lands through writer, and the row as written
answers as a patch (a deletion as deleted). An update writes only the
keys the client named, when it named some, and fails for a row that is not
there; an insert of an id already taken is refused as taken, alike
whatever the row holds, unless the writer's ledger records this operation
as the insert that made it (a retry), answered with that row; a delete of
a row already gone succeeds. A row that moved past the revision the write
expects is refused as a conflict, and one that does not hold its when
as unmet; a write with a when needs a writer that checks it
(preconditions), and is refused here without one. A row the write
would leave outside its postcondition (ensures) is refused as
invalid, as one breaking an invariant is; a write with one needs a
writer that judges it (postconditions).
Reads through source as the read handlers and the live hub do: only the
asked fields the source declares and its authorize allows, each record
through its filter and holding no other field. None when the principal
may read none of the fields asked. What a live source of its own reads
with, so it sends no more than a read would.
The fields of fields that readAs reads for principal: those the
source declares and its authorize allows, in the order asked. Asks
nothing of the store.
A LiveHub over entity sources. Pass it to handlers as live, and every
mutation's answered patches and deletions are published to it; call
hub.changed(ref, fields) yourself only for a write that is not a
mutation (a database trigger, a job). Each subscriber that selects any of
those fields receives them, re-read through the entity source under its
own principal.
The server: its sources by name. viewer says who asks, as a row
(principal => Option.some(Remote.ref(User, principal.id))), or none for
a visitor: what a declared write's Expr.viewer sets. A server
registering such an insert without one is refused here. It is also whom
each answer says it is for (principal, the row's key), which a durable
write carries back: one made for another viewer than who asks is refused
before it runs (RemotePrincipalChanged). A server without viewer
names no one in its answers, and refuses a write that names someone,
since it cannot check it; a write that names no one runs (#405).
clockSkew is how far from this server's clock a client's time (the
now a write is sent with, when the reader acted) may be and still be
the write's time: 60 seconds unless given, and 0 to never take it. A
time beyond it is replaced by the server's own, and reported as
ClockSkewed. It bounds how far a client can backdate or postdate a row.
Checks every source name against the declared domain, so an undeclared
entity/query/mutation fails at startup rather than returning nothing at
call time.
Reads entity requirements through the entity sources, level by level,
following relations as FoldkitRemoteRead does. Shared by the read
handler and the query handler's payload: a query page's items are just
requirements the page names, so one response carries both.
Answers one JSON request through handlers: what an HTTP endpoint, a
worker or a server in the page calls with the body it received, parsed.
The request and its payload are decoded by the protocol's own schemas
before a handler sees them, so an operation name is one of Remote's three
and nothing else. A body that is not a request is a 400; a caller who
could not be told a 401; a refusal of who is asking a 403; a write made
for someone else (RemotePrincipalChanged) a 409; a mutation's
declared refusal a 422, or a 409 when it is Refusal.taken; a handler's
failure a 500 with its message, and the incident it carries; a defect
a 500 that says nothing of it but the incident its cause was reported
under, as a ServerDefect (Diagnostics, by default the log).
Remote.json and Remote.http are the other end.
Compiles the server into Remote's RPC handlers, answering as principal:
a value, or a Context key (G.Principal) read on each call, which
authentication provides per request. Unknown entities, entities with no
allowed fields, and unknown mutations return an error or nothing rather
than leaking existence.