Debian Codegraph @

node/@bufbuild/protobuf/dist/commonjs/to-json.d.ts

raw
1 import { type DescEnum, type DescMessage } from "./descriptors.js";
2 import type { JsonValue } from "./json-value.js";
3 import type { Registry } from "./registry.js";
4 import type { EnumJsonType, EnumShape, MessageJsonType, MessageShape } from "./types.js";
5 /**
6 * Options for serializing to JSON.
7 */
8 export interface JsonWriteOptions {
9 /**
10 * By default, fields with implicit presence are not serialized if they are
11 * unset. For example, an empty list field or a proto3 int32 field with 0 is
12 * not serialized. With this option enabled, such fields are included in the
13 * output.
14 */
15 alwaysEmitImplicit: boolean;
16 /**
17 * Emit enum values as integers instead of strings: The name of an enum
18 * value is used by default in JSON output. An option may be provided to
19 * use the numeric value of the enum value instead.
20 */
21 enumAsInteger: boolean;
22 /**
23 * Use proto field name instead of lowerCamelCase name: By default proto3
24 * JSON printer should convert the field name to lowerCamelCase and use
25 * that as the JSON name. An implementation may provide an option to use
26 * proto field name as the JSON name instead. Proto3 JSON parsers are
27 * required to accept both the converted lowerCamelCase name and the proto
28 * field name.
29 */
30 useProtoFieldName: boolean;
31 /**
32 * This option is required to write `google.protobuf.Any` and extensions
33 * to JSON format.
34 */
35 registry?: Registry | undefined;
36 }
37 /**
38 * Options for serializing to JSON.
39 */
40 export interface JsonWriteStringOptions extends JsonWriteOptions {
41 /**
42 * Format JSON with indentation. Indicates the number of space characters to
43 * be used as indentation.
44 *
45 * This option is passed to JSON.stringify as `space`.
46 */
47 prettySpaces: number;
48 }
49 /**
50 * Serialize the message to a JSON value, a JavaScript value that can be
51 * passed to JSON.stringify().
52 */
53 export declare function toJson<Desc extends DescMessage, Opts extends Partial<JsonWriteOptions> | undefined = undefined>(schema: Desc, message: MessageShape<Desc>, options?: Opts): ToJson<Desc, Opts>;
54 type ToJson<Desc extends DescMessage, Opts extends undefined | Partial<JsonWriteOptions>> = Opts extends undefined | {
55 alwaysEmitImplicit?: false;
56 enumAsInteger?: false;
57 useProtoFieldName?: false;
58 } ? MessageJsonType<Desc> : JsonValue;
59 /**
60 * Serialize the message to a JSON string.
61 */
62 export declare function toJsonString<Desc extends DescMessage>(schema: Desc, message: MessageShape<Desc>, options?: Partial<JsonWriteStringOptions>): string;
63 /**
64 * Serialize a single enum value to JSON.
65 */
66 export declare function enumToJson<Desc extends DescEnum>(descEnum: Desc, value: EnumShape<Desc>): EnumJsonType<Desc>;
67 export {};