assertDesktopHostResponse()
function assertDesktopHostResponse<TKind>(expected, value):
| Extract<{
kind: "handshake";
result: DesktopHostHandshakeResult;
}, {
kind: TKind;
}>
| Extract<{
kind: "open";
result: DesktopHostOpenResult;
}, {
kind: TKind;
}>
| Extract<{
kind: "execute";
result: SqliteSuccessResult;
}, {
kind: TKind;
}>
| Extract<{
kind: "version";
result: string;
}, {
kind: TKind;
}>
| Extract<{
kind: "close";
}, {
kind: TKind;
}>
| Extract<{
kind: "mute";
}, {
kind: TKind;
}>
| Extract<{
code: RxDBAdapterDesktopErrorCode;
kind: "error";
message: string;
}, {
kind: TKind;
}>;
Defined in: packages/rxdb-adapter-sqlite-core/dist/desktop/desktop-host-protocol.d.ts:442
校验一条 host 应答,并把错误应答还原成本地异常。
Type Parameters
| Type Parameter |
|---|
TKind extends "handshake" | "open" | "execute" | "version" | "close" | "mute" |
Parameters
| Parameter | Type | Description |
|---|---|---|
expected | TKind | 期望的应答类型 |
value | unknown | host 返回的未校验负载 |
Returns
| Extract<{
kind: "handshake";
result: DesktopHostHandshakeResult;
}, {
kind: TKind;
}>
| Extract<{
kind: "open";
result: DesktopHostOpenResult;
}, {
kind: TKind;
}>
| Extract<{
kind: "execute";
result: SqliteSuccessResult;
}, {
kind: TKind;
}>
| Extract<{
kind: "version";
result: string;
}, {
kind: TKind;
}>
| Extract<{
kind: "close";
}, {
kind: TKind;
}>
| Extract<{
kind: "mute";
}, {
kind: TKind;
}>
| Extract<{
code: RxDBAdapterDesktopErrorCode;
kind: "error";
message: string;
}, {
kind: TKind;
}>
与 expected 对应的应答
Remarks
这是与 DesktopHostResponse 配套的解包点:错误应答在这里重新变回
RxDBAdapterDesktopError 抛出,因此调用方写的仍是普通的 try/catch,
感觉不到中间隔着一条 IPC。错误码先经 isRxDBAdapterDesktopErrorCode 过一遍,
不在契约内的字符串一律按协议违规处理。
Throws
RxDBAdapterDesktopError host 报错时按其原始错误码抛出;应答形状不符时抛 protocol_violation