Calls
The call protocol of @chia1104/motoko-wire maps onto an instance here,
free of any transport:
runCall<M>(instance, call: Call<M>, { sessionOptions? }?): Promise<CallResult<M>> // a call parsed with wire's callSchemas
callErrorOf(error): CallError | undefined // { code, message }; undefined: not the runtime'srunCall runs the call on the instance and rejects with what the instance threw. A createSession
call carries only its request ID, so what the session runs with is the server's to choose:
sessionOptions() answers it, as createSession's options without requestId, and is asked for each
createSession, a retry's too, whose first session stands as it was made. A throw or rejection makes
no session, and runCall rejects with it. The transports take it from the app: motokoHandler's and
MotokoCapability's sessionOptions. callErrorOf maps
the runtime's errors to their codes (SessionNotFoundError is session_not_found, SessionBusyError
session_busy, SessionOwnedError session_owned, ApprovalNotPendingError approval_not_pending,
ReplyNotPendingError reply_not_pending, InvalidRequestError invalid_request, InvalidCursorError
invalid_cursor, InstanceClosedError instance_closed, LeaseHeldError lease_held); for any
other error it returns undefined, and the transport reports the error and answers internal. What
only a transport knows stays there: whether its caller is readonly (it refuses a call whose
callSchemas[method].writes is true) and the app's authorize.