@ bufbuilding/ protocompile (英语)
这个工具在苍蝇上从Protobuf编译了描述符.
测试时需要留言吗? 与 compileMessage 函数,您可以将 Protobuf 源编译为信件描述符 :
import { compileMessage } from "@bufbuild/protocompile";
import { redact } from "./redact.js";
describe("redact", () => {
it("should redact string field", () => {
const schema = compileMessage(`
syntax = "proto3";
message Example {
string foo = 1 [ debug_redact = true ];
}
`);
const message: Message & Record<string, unknown> = create(schema, {
foo: "abc",
});
redact(message);
expect(message.foo).toBe("");
});
});
该套件还输出功能来编译所有其他类型的Protobuf描述符,例如点数和服务.
在引擎盖下,功能外壳到 buf build 命令。 惠璶 @ bufbuilding/ buf 作为使用它们的同伴依赖.
注意这些函数返回匿名描述符 。 它们与生成的描述符在功能上完全相同,但没有生成附加的种类信息.