示例工程 09-typed-ipc-contracts
09-typed-ipc-contracts/app/.tsc/shared/ipc.d.ts
/**
* 三端唯一来源:通道名、请求/响应类型、手写校验器。
* 本文件不 import electron,渲染进程也能安全引用。
*/
export declare const CH: {
readonly create: "notes:create";
readonly list: "notes:list";
readonly cases: "contract:cases";
readonly reset: "notes:reset";
};
export type Note = {
id: number;
title: string;
body: string;
tags: string[];
createdAt: number;
};
export type CreateNoteReq = {
title: string;
body: string;
tags?: string[];
};
export type ListNotesReq = {
limit: number;
};
export type ListNotesRes = {
items: Note[];
total: number;
};
export type PublicError = {
code: string;
message: string;
detail?: string;
requestId: string;
};
export type Envelope<T> = {
ok: true;
value: T;
requestId: string;
} | {
ok: false;
error: PublicError;
};
export type CaseResult = {
name: string;
ok: boolean;
expected: string;
actual: string;
};
export type CaseReport = {
total: number;
passed: number;
failed: number;
cases: CaseResult[];
};
export declare class ContractError extends Error {
readonly code: string;
readonly detail?: string;
constructor(code: string, message: string, detail?: string);
}
export declare function parseCreateNoteReq(value: unknown): CreateNoteReq;
export declare function parseListNotesReq(value: unknown): ListNotesReq;
export declare function toPublicError(error: unknown, requestId: string): PublicError;
//# sourceMappingURL=ipc.d.ts.map