| 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, MessageShape } from "./types.js"; |
| 5 |
/** |
| 6 |
* Options for parsing JSON data. |
| 7 |
*/ |
| 8 |
export interface JsonReadOptions { |
| 9 |
/** |
| 10 |
* Ignore unknown fields: Proto3 JSON parser should reject unknown fields |
| 11 |
* by default. This option ignores unknown fields in parsing, as well as |
| 12 |
* unrecognized enum string representations. |
| 13 |
*/ |
| 14 |
ignoreUnknownFields: boolean; |
| 15 |
/** |
| 16 |
* This option is required to read `google.protobuf.Any` and extensions |
| 17 |
* from JSON format. |
| 18 |
*/ |
| 19 |
registry?: Registry | undefined; |
| 20 |
/** |
| 21 |
* The maximum depth of nested messages to parse. If a message nests deeper |
| 22 |
* than this limit, parsing fails with an error instead of exhausting the |
| 23 |
* call stack. Defaults to 100. |
| 24 |
*/ |
| 25 |
recursionLimit: number; |
| 26 |
} |
| 27 |
/** |
| 28 |
* Parse a message from a JSON string. |
| 29 |
* |
| 30 |
* Duplicate keys are rejected. |
| 31 |
*/ |
| 32 |
export declare function fromJsonString<Desc extends DescMessage>(schema: Desc, json: string, options?: Partial<JsonReadOptions>): MessageShape<Desc>; |
| 33 |
/** |
| 34 |
* Parse a message from a JSON string, merging fields into the target. |
| 35 |
* |
| 36 |
* Repeated fields are appended. Map entries are added, overwriting |
| 37 |
* existing keys. |
| 38 |
* |
| 39 |
* If a message field is already present, it will be merged with the |
| 40 |
* new data. |
| 41 |
* |
| 42 |
* Duplicate keys in the JSON are rejected, as in `fromJsonString`. |
| 43 |
*/ |
| 44 |
export declare function mergeFromJsonString<Desc extends DescMessage>(schema: Desc, target: MessageShape<Desc>, json: string, options?: Partial<JsonReadOptions>): MessageShape<Desc>; |
| 45 |
/** |
| 46 |
* Parse a message from a JSON value. |
| 47 |
* |
| 48 |
* Duplicate keys are rejected, but a value parsed by JSON.parse has already |
| 49 |
* dropped duplicates (the last one wins). Use `fromJsonString` for strict |
| 50 |
* duplicate-key checking. |
| 51 |
*/ |
| 52 |
export declare function fromJson<Desc extends DescMessage>(schema: Desc, json: JsonValue, options?: Partial<JsonReadOptions>): MessageShape<Desc>; |
| 53 |
/** |
| 54 |
* Parse a message from a JSON value, merging fields into the target. |
| 55 |
* |
| 56 |
* Repeated fields are appended. Map entries are added, overwriting |
| 57 |
* existing keys. |
| 58 |
* |
| 59 |
* If a message field is already present, it will be merged with the |
| 60 |
* new data. |
| 61 |
* |
| 62 |
* Duplicate keys are rejected as in `fromJson`; use `mergeFromJsonString` |
| 63 |
* for strict checking. |
| 64 |
*/ |
| 65 |
export declare function mergeFromJson<Desc extends DescMessage>(schema: Desc, target: MessageShape<Desc>, json: JsonValue, options?: Partial<JsonReadOptions>): MessageShape<Desc>; |
| 66 |
/** |
| 67 |
* Parses an enum value from JSON. |
| 68 |
*/ |
| 69 |
export declare function enumFromJson<Desc extends DescEnum>(descEnum: Desc, json: EnumJsonType<Desc>): EnumShape<Desc>; |
| 70 |
/** |
| 71 |
* Is the given value a JSON enum value? |
| 72 |
*/ |
| 73 |
export declare function isEnumJson<Desc extends DescEnum>(descEnum: Desc, value: unknown): value is EnumJsonType<Desc>; |