@bufbuild/protobuf 2.12.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/commonjs/codegenv1/boot.d.ts +1 -0
- package/dist/{cjs/codegenv1/types.js → commonjs/codegenv1/boot.js} +3 -7
- package/dist/{cjs → commonjs}/codegenv1/symbols.d.ts +5 -0
- package/dist/{cjs → commonjs}/codegenv1/types.d.ts +9 -5
- package/dist/commonjs/codegenv2/enum.d.ts +29 -0
- package/dist/{cjs → commonjs}/codegenv2/enum.js +18 -0
- package/dist/{cjs → commonjs}/codegenv2/symbols.d.ts +10 -0
- package/dist/{cjs → commonjs}/codegenv2/symbols.js +2 -0
- package/dist/{cjs → commonjs}/codegenv2/types.d.ts +9 -5
- package/dist/{cjs → commonjs}/create.js +3 -3
- package/dist/{cjs → commonjs}/descriptors.d.ts +2 -2
- package/dist/{cjs → commonjs}/equals.d.ts +8 -3
- package/dist/{cjs → commonjs}/equals.js +8 -3
- package/dist/{cjs → commonjs}/extensions.d.ts +2 -1
- package/dist/{cjs → commonjs}/extensions.js +3 -4
- package/dist/{cjs → commonjs}/from-binary.d.ts +16 -2
- package/dist/{cjs → commonjs}/from-binary.js +30 -24
- package/dist/{cjs → commonjs}/from-json.d.ts +19 -2
- package/dist/{cjs → commonjs}/from-json.js +174 -54
- package/dist/{cjs → commonjs}/index.d.ts +1 -0
- package/dist/{cjs → commonjs}/index.js +1 -0
- package/dist/commonjs/json-value.js +15 -0
- package/dist/commonjs/package.json +4 -0
- package/dist/{cjs → commonjs}/proto-int64.js +1 -0
- package/dist/{cjs → commonjs}/reflect/reflect-check.js +3 -1
- package/dist/{cjs → commonjs}/reflect/reflect.js +3 -2
- package/dist/commonjs/reflect/scalar.d.ts +43 -0
- package/dist/{cjs → commonjs}/reflect/scalar.js +33 -6
- package/dist/{cjs → commonjs}/reflect/unsafe.js +1 -1
- package/dist/{cjs → commonjs}/registry.js +20 -20
- package/dist/{cjs → commonjs}/to-binary.js +1 -1
- package/dist/{cjs → commonjs}/to-json.js +2 -2
- package/dist/commonjs/txtpb/from-text.d.ts +35 -0
- package/dist/commonjs/txtpb/from-text.js +684 -0
- package/dist/commonjs/txtpb/index.d.ts +4 -0
- package/dist/commonjs/txtpb/index.js +21 -0
- package/dist/commonjs/txtpb/is-group-like.d.ts +19 -0
- package/dist/commonjs/txtpb/is-group-like.js +47 -0
- package/dist/commonjs/txtpb/reader.d.ts +91 -0
- package/dist/commonjs/txtpb/reader.js +481 -0
- package/dist/commonjs/txtpb/to-text.d.ts +34 -0
- package/dist/commonjs/txtpb/to-text.js +358 -0
- package/dist/commonjs/txtpb/writer.d.ts +76 -0
- package/dist/commonjs/txtpb/writer.js +220 -0
- package/dist/{cjs → commonjs}/types.d.ts +7 -0
- package/dist/{cjs/codegenv2 → commonjs}/types.js +0 -7
- package/dist/commonjs/unknown-enum.d.ts +10 -0
- package/dist/commonjs/unknown-enum.js +26 -0
- package/dist/{cjs → commonjs}/wire/binary-encoding.d.ts +4 -2
- package/dist/{cjs → commonjs}/wire/binary-encoding.js +8 -3
- package/dist/{cjs → commonjs}/wire/size-delimited.d.ts +19 -1
- package/dist/{cjs → commonjs}/wire/size-delimited.js +54 -16
- package/dist/esm/codegenv1/boot.d.ts +1 -0
- package/dist/esm/codegenv1/boot.js +14 -0
- package/dist/esm/codegenv1/symbols.d.ts +5 -0
- package/dist/esm/codegenv1/types.d.ts +9 -5
- package/dist/esm/codegenv1/types.js +0 -7
- package/dist/esm/codegenv2/enum.d.ts +15 -4
- package/dist/esm/codegenv2/enum.js +17 -0
- package/dist/esm/codegenv2/symbols.d.ts +10 -0
- package/dist/esm/codegenv2/symbols.js +2 -0
- package/dist/esm/codegenv2/types.d.ts +9 -5
- package/dist/esm/codegenv2/types.js +0 -7
- package/dist/esm/create.js +3 -3
- package/dist/esm/descriptors.d.ts +2 -2
- package/dist/esm/equals.d.ts +8 -3
- package/dist/esm/equals.js +8 -3
- package/dist/esm/extensions.d.ts +2 -1
- package/dist/esm/extensions.js +4 -5
- package/dist/esm/from-binary.d.ts +16 -2
- package/dist/esm/from-binary.js +29 -24
- package/dist/esm/from-json.d.ts +19 -2
- package/dist/esm/from-json.js +174 -54
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/package.json +4 -0
- package/dist/esm/proto-int64.js +1 -0
- package/dist/esm/reflect/reflect-check.js +3 -1
- package/dist/esm/reflect/reflect.js +3 -2
- package/dist/esm/reflect/scalar.d.ts +27 -5
- package/dist/esm/reflect/scalar.js +33 -6
- package/dist/esm/reflect/unsafe.js +1 -1
- package/dist/esm/registry.js +20 -20
- package/dist/esm/to-binary.js +1 -1
- package/dist/esm/to-json.js +2 -2
- package/dist/esm/txtpb/from-text.d.ts +35 -0
- package/dist/esm/txtpb/from-text.js +680 -0
- package/dist/esm/txtpb/index.d.ts +4 -0
- package/dist/esm/txtpb/index.js +15 -0
- package/dist/esm/txtpb/is-group-like.d.ts +19 -0
- package/dist/esm/txtpb/is-group-like.js +44 -0
- package/dist/esm/txtpb/reader.d.ts +91 -0
- package/dist/esm/txtpb/reader.js +477 -0
- package/dist/esm/txtpb/to-text.d.ts +34 -0
- package/dist/esm/txtpb/to-text.js +355 -0
- package/dist/esm/txtpb/writer.d.ts +76 -0
- package/dist/esm/txtpb/writer.js +214 -0
- package/dist/esm/types.d.ts +7 -0
- package/dist/esm/unknown-enum.d.ts +10 -0
- package/dist/esm/unknown-enum.js +23 -0
- package/dist/esm/wire/binary-encoding.d.ts +4 -2
- package/dist/esm/wire/binary-encoding.js +8 -3
- package/dist/esm/wire/size-delimited.d.ts +19 -1
- package/dist/esm/wire/size-delimited.js +54 -16
- package/package.json +109 -30
- package/dist/cjs/codegenv2/enum.d.ts +0 -18
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/reflect/scalar.d.ts +0 -21
- /package/dist/{cjs → commonjs}/clone.d.ts +0 -0
- /package/dist/{cjs → commonjs}/clone.js +0 -0
- /package/dist/{cjs → commonjs}/codegenv1/enum.d.ts +0 -0
- /package/dist/{cjs → commonjs}/codegenv1/enum.js +0 -0
- /package/dist/{cjs → commonjs}/codegenv1/extension.d.ts +0 -0
- /package/dist/{cjs → commonjs}/codegenv1/extension.js +0 -0
- /package/dist/{cjs → commonjs}/codegenv1/file.d.ts +0 -0
- /package/dist/{cjs → commonjs}/codegenv1/file.js +0 -0
- /package/dist/{cjs → commonjs}/codegenv1/index.d.ts +0 -0
- /package/dist/{cjs → commonjs}/codegenv1/index.js +0 -0
- /package/dist/{cjs → commonjs}/codegenv1/message.d.ts +0 -0
- /package/dist/{cjs → commonjs}/codegenv1/message.js +0 -0
- /package/dist/{cjs → commonjs}/codegenv1/service.d.ts +0 -0
- /package/dist/{cjs → commonjs}/codegenv1/service.js +0 -0
- /package/dist/{cjs → commonjs}/codegenv1/symbols.js +0 -0
- /package/dist/{cjs → commonjs/codegenv1}/types.js +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/boot.d.ts +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/boot.js +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/embed.d.ts +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/embed.js +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/extension.d.ts +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/extension.js +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/file.d.ts +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/file.js +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/index.d.ts +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/index.js +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/message.d.ts +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/message.js +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/restore-json-names.d.ts +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/restore-json-names.js +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/scalar.d.ts +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/scalar.js +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/service.d.ts +0 -0
- /package/dist/{cjs → commonjs}/codegenv2/service.js +0 -0
- /package/dist/{cjs/json-value.js → commonjs/codegenv2/types.js} +0 -0
- /package/dist/{cjs → commonjs}/create.d.ts +0 -0
- /package/dist/{cjs → commonjs}/descriptors.js +0 -0
- /package/dist/{cjs → commonjs}/fields.d.ts +0 -0
- /package/dist/{cjs → commonjs}/fields.js +0 -0
- /package/dist/{cjs → commonjs}/is-message.d.ts +0 -0
- /package/dist/{cjs → commonjs}/is-message.js +0 -0
- /package/dist/{cjs → commonjs}/json-value.d.ts +0 -0
- /package/dist/{cjs → commonjs}/merge.d.ts +0 -0
- /package/dist/{cjs → commonjs}/merge.js +0 -0
- /package/dist/{cjs → commonjs}/proto-int64.d.ts +0 -0
- /package/dist/{cjs → commonjs}/reflect/error.d.ts +0 -0
- /package/dist/{cjs → commonjs}/reflect/error.js +0 -0
- /package/dist/{cjs → commonjs}/reflect/guard.d.ts +0 -0
- /package/dist/{cjs → commonjs}/reflect/guard.js +0 -0
- /package/dist/{cjs → commonjs}/reflect/index.d.ts +0 -0
- /package/dist/{cjs → commonjs}/reflect/index.js +0 -0
- /package/dist/{cjs → commonjs}/reflect/names.d.ts +0 -0
- /package/dist/{cjs → commonjs}/reflect/names.js +0 -0
- /package/dist/{cjs → commonjs}/reflect/nested-types.d.ts +0 -0
- /package/dist/{cjs → commonjs}/reflect/nested-types.js +0 -0
- /package/dist/{cjs → commonjs}/reflect/path.d.ts +0 -0
- /package/dist/{cjs → commonjs}/reflect/path.js +0 -0
- /package/dist/{cjs → commonjs}/reflect/reflect-check.d.ts +0 -0
- /package/dist/{cjs → commonjs}/reflect/reflect-types.d.ts +0 -0
- /package/dist/{cjs → commonjs}/reflect/reflect-types.js +0 -0
- /package/dist/{cjs → commonjs}/reflect/reflect.d.ts +0 -0
- /package/dist/{cjs → commonjs}/reflect/unsafe.d.ts +0 -0
- /package/dist/{cjs → commonjs}/registry.d.ts +0 -0
- /package/dist/{cjs → commonjs}/to-binary.d.ts +0 -0
- /package/dist/{cjs → commonjs}/to-json.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wire/base64-encoding.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wire/base64-encoding.js +0 -0
- /package/dist/{cjs → commonjs}/wire/index.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wire/index.js +0 -0
- /package/dist/{cjs → commonjs}/wire/text-encoding.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wire/text-encoding.js +0 -0
- /package/dist/{cjs → commonjs}/wire/text-format.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wire/text-format.js +0 -0
- /package/dist/{cjs → commonjs}/wire/varint.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wire/varint.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/any.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/any.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/duration.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/duration.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/any_pb.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/any_pb.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/api_pb.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/api_pb.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/compiler/plugin_pb.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/compiler/plugin_pb.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/cpp_features_pb.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/cpp_features_pb.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/descriptor_pb.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/descriptor_pb.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/duration_pb.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/duration_pb.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/empty_pb.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/empty_pb.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/field_mask_pb.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/field_mask_pb.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/go_features_pb.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/go_features_pb.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/java_features_pb.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/java_features_pb.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/source_context_pb.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/source_context_pb.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/struct_pb.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/struct_pb.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/timestamp_pb.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/timestamp_pb.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/type_pb.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/type_pb.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/wrappers_pb.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/gen/google/protobuf/wrappers_pb.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/index.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/index.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/timestamp.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/timestamp.js +0 -0
- /package/dist/{cjs → commonjs}/wkt/wrappers.d.ts +0 -0
- /package/dist/{cjs → commonjs}/wkt/wrappers.js +0 -0
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ code generator plugin.
|
|
|
6
6
|
## Protocol Buffers for ECMAScript
|
|
7
7
|
|
|
8
8
|
A complete implementation of [Protocol Buffers](https://protobuf.dev/) in TypeScript,
|
|
9
|
-
suitable for web browsers, Node.js, and
|
|
9
|
+
suitable for web browsers, Node.js, Deno, and Bun, created by [Buf](https://buf.build).
|
|
10
10
|
|
|
11
11
|
**Protobuf-ES** is a solid, modern alternative to existing Protobuf implementations for the JavaScript ecosystem. It's
|
|
12
12
|
the first project in this space to provide a comprehensive plugin framework and decouple the base types from RPC
|
|
@@ -19,7 +19,7 @@ Some additional features that set it apart from the others:
|
|
|
19
19
|
- Generation of idiomatic JavaScript and TypeScript code
|
|
20
20
|
- Generation of [much smaller bundles](https://github.com/bufbuild/protobuf-es/tree/main/packages/bundle-size/)
|
|
21
21
|
- Implementation of all proto3 features, including the [canonical JSON format](https://protobuf.dev/programming-guides/proto3/#json)
|
|
22
|
-
- Implementation of all proto2 features,
|
|
22
|
+
- Implementation of all proto2 features, including extensions and the text format
|
|
23
23
|
- Usage of standard JavaScript APIs instead of the [Closure Library](http://googlecode.blogspot.com/2009/11/introducing-closure-tools.html)
|
|
24
24
|
- Compatibility is covered by the Protocol Buffers [conformance tests](https://github.com/bufbuild/protobuf-es/tree/main/packages/protobuf-conformance/)
|
|
25
25
|
- Descriptor and reflection support
|
|
@@ -32,10 +32,10 @@ npm install @bufbuild/protobuf
|
|
|
32
32
|
|
|
33
33
|
## Documentation
|
|
34
34
|
|
|
35
|
-
To learn how to work with `@bufbuild/protobuf`, check out the docs for the [Runtime API](https://
|
|
36
|
-
and the [generated code](https://
|
|
35
|
+
To learn how to work with `@bufbuild/protobuf`, check out the docs for the [Runtime API](https://protobufes.com/guides/messages/)
|
|
36
|
+
and the [generated code](https://protobufes.com/reference/generated-code/).
|
|
37
37
|
|
|
38
|
-
Official documentation for the Protobuf-ES project can be found at [
|
|
38
|
+
Official documentation for the Protobuf-ES project can be found at [protobufes.com](https://protobufes.com/).
|
|
39
39
|
|
|
40
40
|
For more information on Buf, check out the official [Buf documentation](https://buf.build/docs/).
|
|
41
41
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { boot } from "../codegenv2/boot.js";
|
|
@@ -13,10 +13,6 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.a = false;
|
|
20
|
-
this.b = false;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
16
|
+
exports.boot = void 0;
|
|
17
|
+
var boot_js_1 = require("../codegenv2/boot.js");
|
|
18
|
+
Object.defineProperty(exports, "boot", { enumerable: true, get: function () { return boot_js_1.boot; } });
|
|
@@ -132,4 +132,9 @@ export declare const symbols: {
|
|
|
132
132
|
readonly bootstrapWktFrom: "../../json-value.js";
|
|
133
133
|
readonly from: "@bufbuild/protobuf";
|
|
134
134
|
};
|
|
135
|
+
readonly UnknownEnum: {
|
|
136
|
+
readonly typeOnly: true;
|
|
137
|
+
readonly bootstrapWktFrom: "../../types.js";
|
|
138
|
+
readonly from: "@bufbuild/protobuf";
|
|
139
|
+
};
|
|
135
140
|
};
|
|
@@ -56,11 +56,15 @@ export type GenService<RuntimeShape extends GenServiceMethods> = Omit<DescServic
|
|
|
56
56
|
* @private
|
|
57
57
|
*/
|
|
58
58
|
export type GenServiceMethods = Record<string, Pick<DescMethod, "input" | "output" | "methodKind">>;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
type brandv1<A, B = unknown> = {
|
|
60
|
+
/**
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
readonly $codegenv1: {
|
|
64
|
+
a: A;
|
|
65
|
+
b: B;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
64
68
|
/**
|
|
65
69
|
* Union of the property names of all fields, including oneof members.
|
|
66
70
|
* For an anonymous message (no generated message shape), it's simply a string.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { DescEnum, DescFile } from "../descriptors.js";
|
|
2
|
+
import type { GenEnum } from "./types.js";
|
|
3
|
+
import type { JsonValue } from "../json-value.js";
|
|
4
|
+
/**
|
|
5
|
+
* Hydrate an enum descriptor.
|
|
6
|
+
*
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
export declare function enumDesc<Shape extends number, JsonType extends JsonValue = JsonValue>(file: DescFile, path: number, ...paths: number[]): GenEnum<Shape, JsonType>;
|
|
10
|
+
/**
|
|
11
|
+
* Construct a TypeScript enum object at runtime from a descriptor.
|
|
12
|
+
*
|
|
13
|
+
* The returned object is identical to a transpiled TS enum and includes the
|
|
14
|
+
* reverse mapping, see https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings
|
|
15
|
+
*/
|
|
16
|
+
export declare function tsEnum(desc: DescEnum): {
|
|
17
|
+
[key: number]: string;
|
|
18
|
+
[k: string]: string | number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Construct an object enum at runtime from a descriptor.
|
|
22
|
+
*
|
|
23
|
+
* The returned object is a record of enum value name to integer value. It's
|
|
24
|
+
* a subset of transpiled TS enums - it does not include the reverse mapping,
|
|
25
|
+
* and only supports lookup by value name.
|
|
26
|
+
*/
|
|
27
|
+
export declare function objEnum(desc: DescEnum): {
|
|
28
|
+
[key: string]: number;
|
|
29
|
+
};
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.enumDesc = enumDesc;
|
|
17
17
|
exports.tsEnum = tsEnum;
|
|
18
|
+
exports.objEnum = objEnum;
|
|
18
19
|
/**
|
|
19
20
|
* Hydrate an enum descriptor.
|
|
20
21
|
*
|
|
@@ -29,6 +30,9 @@ function enumDesc(file, path, ...paths) {
|
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
* Construct a TypeScript enum object at runtime from a descriptor.
|
|
33
|
+
*
|
|
34
|
+
* The returned object is identical to a transpiled TS enum and includes the
|
|
35
|
+
* reverse mapping, see https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings
|
|
32
36
|
*/
|
|
33
37
|
function tsEnum(desc) {
|
|
34
38
|
const enumObject = {};
|
|
@@ -38,3 +42,17 @@ function tsEnum(desc) {
|
|
|
38
42
|
}
|
|
39
43
|
return enumObject;
|
|
40
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Construct an object enum at runtime from a descriptor.
|
|
47
|
+
*
|
|
48
|
+
* The returned object is a record of enum value name to integer value. It's
|
|
49
|
+
* a subset of transpiled TS enums - it does not include the reverse mapping,
|
|
50
|
+
* and only supports lookup by value name.
|
|
51
|
+
*/
|
|
52
|
+
function objEnum(desc) {
|
|
53
|
+
const enumObject = {};
|
|
54
|
+
for (const value of desc.values) {
|
|
55
|
+
enumObject[value.localName] = value.number;
|
|
56
|
+
}
|
|
57
|
+
return enumObject;
|
|
58
|
+
}
|
|
@@ -70,6 +70,11 @@ export declare const symbols: {
|
|
|
70
70
|
readonly bootstrapWktFrom: "../../json-value.js";
|
|
71
71
|
readonly from: "@bufbuild/protobuf";
|
|
72
72
|
};
|
|
73
|
+
readonly UnknownEnum: {
|
|
74
|
+
readonly typeOnly: true;
|
|
75
|
+
readonly bootstrapWktFrom: "../../types.js";
|
|
76
|
+
readonly from: "@bufbuild/protobuf";
|
|
77
|
+
};
|
|
73
78
|
readonly codegen: {
|
|
74
79
|
readonly boot: {
|
|
75
80
|
readonly typeOnly: false;
|
|
@@ -106,6 +111,11 @@ export declare const symbols: {
|
|
|
106
111
|
readonly bootstrapWktFrom: "../../codegenv2/enum.js";
|
|
107
112
|
readonly from: string;
|
|
108
113
|
};
|
|
114
|
+
readonly objEnum: {
|
|
115
|
+
readonly typeOnly: false;
|
|
116
|
+
readonly bootstrapWktFrom: "../../codegenv2/enum.js";
|
|
117
|
+
readonly from: string;
|
|
118
|
+
};
|
|
109
119
|
readonly GenFile: {
|
|
110
120
|
readonly typeOnly: true;
|
|
111
121
|
readonly bootstrapWktFrom: "../../codegenv2/types.js";
|
|
@@ -55,6 +55,7 @@ exports.symbols = {
|
|
|
55
55
|
protoInt64: { typeOnly: false, bootstrapWktFrom: "../../proto-int64.js", from: exports.packageName },
|
|
56
56
|
JsonValue: { typeOnly: true, bootstrapWktFrom: "../../json-value.js", from: exports.packageName },
|
|
57
57
|
JsonObject: { typeOnly: true, bootstrapWktFrom: "../../json-value.js", from: exports.packageName },
|
|
58
|
+
UnknownEnum: { typeOnly: true, bootstrapWktFrom: "../../types.js", from: exports.packageName },
|
|
58
59
|
codegen: {
|
|
59
60
|
boot: { typeOnly: false, bootstrapWktFrom: "../../codegenv2/boot.js", from: exports.packageName + "/codegenv2" },
|
|
60
61
|
fileDesc: { typeOnly: false, bootstrapWktFrom: "../../codegenv2/file.js", from: exports.packageName + "/codegenv2" },
|
|
@@ -63,6 +64,7 @@ exports.symbols = {
|
|
|
63
64
|
messageDesc: { typeOnly: false, bootstrapWktFrom: "../../codegenv2/message.js", from: exports.packageName + "/codegenv2" },
|
|
64
65
|
serviceDesc: { typeOnly: false, bootstrapWktFrom: "../../codegenv2/service.js", from: exports.packageName + "/codegenv2" },
|
|
65
66
|
tsEnum: { typeOnly: false, bootstrapWktFrom: "../../codegenv2/enum.js", from: exports.packageName + "/codegenv2" },
|
|
67
|
+
objEnum: { typeOnly: false, bootstrapWktFrom: "../../codegenv2/enum.js", from: exports.packageName + "/codegenv2" },
|
|
66
68
|
GenFile: { typeOnly: true, bootstrapWktFrom: "../../codegenv2/types.js", from: exports.packageName + "/codegenv2" },
|
|
67
69
|
GenEnum: { typeOnly: true, bootstrapWktFrom: "../../codegenv2/types.js", from: exports.packageName + "/codegenv2" },
|
|
68
70
|
GenExtension: { typeOnly: true, bootstrapWktFrom: "../../codegenv2/types.js", from: exports.packageName + "/codegenv2" },
|
|
@@ -62,11 +62,15 @@ export type GenService<RuntimeShape extends GenServiceMethods> = Omit<DescServic
|
|
|
62
62
|
* @private
|
|
63
63
|
*/
|
|
64
64
|
export type GenServiceMethods = Record<string, Pick<DescMethod, "input" | "output" | "methodKind">>;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
type brandv2<A, B = unknown> = {
|
|
66
|
+
/**
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
readonly $codegenv2: {
|
|
70
|
+
a: A;
|
|
71
|
+
b: B;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
70
74
|
/**
|
|
71
75
|
* Union of the property names of all fields, including oneof members.
|
|
72
76
|
* For an anonymous message (no generated message shape), it's simply a string.
|
|
@@ -20,11 +20,11 @@ const scalar_js_1 = require("./reflect/scalar.js");
|
|
|
20
20
|
const guard_js_1 = require("./reflect/guard.js");
|
|
21
21
|
const unsafe_js_1 = require("./reflect/unsafe.js");
|
|
22
22
|
const wrappers_js_1 = require("./wkt/wrappers.js");
|
|
23
|
-
// bootstrap-inject google.protobuf.Edition.EDITION_PROTO3: const $name
|
|
23
|
+
// bootstrap-inject google.protobuf.Edition.EDITION_PROTO3: const $name = $number;
|
|
24
24
|
const EDITION_PROTO3 = 999;
|
|
25
|
-
// bootstrap-inject google.protobuf.Edition.EDITION_PROTO2: const $name
|
|
25
|
+
// bootstrap-inject google.protobuf.Edition.EDITION_PROTO2: const $name = $number;
|
|
26
26
|
const EDITION_PROTO2 = 998;
|
|
27
|
-
// bootstrap-inject google.protobuf.FeatureSet.FieldPresence.IMPLICIT: const $name
|
|
27
|
+
// bootstrap-inject google.protobuf.FeatureSet.FieldPresence.IMPLICIT: const $name = $number;
|
|
28
28
|
const IMPLICIT = 2;
|
|
29
29
|
/**
|
|
30
30
|
* Create a new message instance.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DescriptorProto, Edition, EnumDescriptorProto, EnumValueDescriptorProto, FeatureSet_FieldPresence, FieldDescriptorProto, FileDescriptorProto, MethodDescriptorProto, MethodOptions_IdempotencyLevel, OneofDescriptorProto, ServiceDescriptorProto } from "./wkt/gen/google/protobuf/descriptor_pb.js";
|
|
2
2
|
import type { ScalarValue } from "./reflect/scalar.js";
|
|
3
|
-
export type SupportedEdition = Extract<Edition, Edition.EDITION_PROTO2 | Edition.EDITION_PROTO3 | Edition.EDITION_2023 | Edition.EDITION_2024>;
|
|
4
|
-
type SupportedFieldPresence = Extract<FeatureSet_FieldPresence, FeatureSet_FieldPresence.EXPLICIT | FeatureSet_FieldPresence.IMPLICIT | FeatureSet_FieldPresence.LEGACY_REQUIRED>;
|
|
3
|
+
export type SupportedEdition = Extract<Edition, typeof Edition.EDITION_PROTO2 | typeof Edition.EDITION_PROTO3 | typeof Edition.EDITION_2023 | typeof Edition.EDITION_2024>;
|
|
4
|
+
type SupportedFieldPresence = Extract<FeatureSet_FieldPresence, typeof FeatureSet_FieldPresence.EXPLICIT | typeof FeatureSet_FieldPresence.IMPLICIT | typeof FeatureSet_FieldPresence.LEGACY_REQUIRED>;
|
|
5
5
|
/**
|
|
6
6
|
* Scalar value types. This is a subset of field types declared by protobuf
|
|
7
7
|
* enum google.protobuf.FieldDescriptorProto.Type The types GROUP and MESSAGE
|
|
@@ -32,10 +32,15 @@ interface EqualsOptions {
|
|
|
32
32
|
unknown?: boolean;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* Compare two messages of the same type.
|
|
35
|
+
* Compare two messages of the same type for equality.
|
|
36
36
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
37
|
+
* Fields are compared one by one, but only when set: a field set in one message
|
|
38
|
+
* but not the other makes them unequal, while fields set in both are compared
|
|
39
|
+
* by value. Extensions and unknown fields are disregarded by default.
|
|
40
|
+
*
|
|
41
|
+
* Float and double values are compared with IEEE semantics: NaN does not equal
|
|
42
|
+
* NaN, and -0 equals 0 (with the exception for singular fields with implicit
|
|
43
|
+
* presence: -0 is set, +0 is unset).
|
|
39
44
|
*/
|
|
40
45
|
export declare function equals<Desc extends DescMessage>(schema: Desc, a: MessageShape<Desc>, b: MessageShape<Desc>, options?: EqualsOptions): boolean;
|
|
41
46
|
export {};
|
|
@@ -20,10 +20,15 @@ const descriptors_js_1 = require("./descriptors.js");
|
|
|
20
20
|
const index_js_1 = require("./wkt/index.js");
|
|
21
21
|
const extensions_js_1 = require("./extensions.js");
|
|
22
22
|
/**
|
|
23
|
-
* Compare two messages of the same type.
|
|
23
|
+
* Compare two messages of the same type for equality.
|
|
24
24
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
25
|
+
* Fields are compared one by one, but only when set: a field set in one message
|
|
26
|
+
* but not the other makes them unequal, while fields set in both are compared
|
|
27
|
+
* by value. Extensions and unknown fields are disregarded by default.
|
|
28
|
+
*
|
|
29
|
+
* Float and double values are compared with IEEE semantics: NaN does not equal
|
|
30
|
+
* NaN, and -0 equals 0 (with the exception for singular fields with implicit
|
|
31
|
+
* presence: -0 is set, +0 is unset).
|
|
27
32
|
*/
|
|
28
33
|
function equals(schema, a, b, options) {
|
|
29
34
|
if (a.$typeName != schema.typeName || b.$typeName != schema.typeName) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AnyDesc, DescEnum, DescEnumValue, DescExtension, DescField, DescFile, DescMessage, DescMethod, DescOneof, DescService } from "./descriptors.js";
|
|
2
|
+
import type { BinaryReadOptions } from "./from-binary.js";
|
|
2
3
|
import type { ReflectMessage } from "./reflect/reflect-types.js";
|
|
3
4
|
import type { Extendee, ExtensionValueShape } from "./types.js";
|
|
4
5
|
import type { EnumOptions, EnumValueOptions, FieldOptions, FileOptions, MessageOptions, MethodOptions, OneofOptions, ServiceOptions } from "./wkt/gen/google/protobuf/descriptor_pb.js";
|
|
@@ -16,7 +17,7 @@ import type { EnumOptions, EnumValueOptions, FieldOptions, FileOptions, MessageO
|
|
|
16
17
|
*
|
|
17
18
|
* If the extension does not extend the given message, an error is raised.
|
|
18
19
|
*/
|
|
19
|
-
export declare function getExtension<Desc extends DescExtension>(message: Extendee<Desc>, extension: Desc): ExtensionValueShape<Desc>;
|
|
20
|
+
export declare function getExtension<Desc extends DescExtension>(message: Extendee<Desc>, extension: Desc, options?: Partial<BinaryReadOptions>): ExtensionValueShape<Desc>;
|
|
20
21
|
/**
|
|
21
22
|
* Set an extension value on a message. If the message already has a value for
|
|
22
23
|
* this extension, the value is replaced.
|
|
@@ -41,14 +41,13 @@ const wrappers_js_1 = require("./wkt/wrappers.js");
|
|
|
41
41
|
*
|
|
42
42
|
* If the extension does not extend the given message, an error is raised.
|
|
43
43
|
*/
|
|
44
|
-
function getExtension(message, extension) {
|
|
44
|
+
function getExtension(message, extension, options) {
|
|
45
45
|
assertExtendee(extension, message);
|
|
46
46
|
const ufs = filterUnknownFields(message.$unknown, extension);
|
|
47
47
|
const [container, field, get] = createExtensionContainer(extension);
|
|
48
|
+
const ctx = (0, from_binary_js_1.makeReadContext)(options);
|
|
48
49
|
for (const uf of ufs) {
|
|
49
|
-
(0, from_binary_js_1.readField)(container, new binary_encoding_js_1.BinaryReader(uf.data), field, uf.wireType,
|
|
50
|
-
readUnknownFields: true,
|
|
51
|
-
});
|
|
50
|
+
(0, from_binary_js_1.readField)(container, new binary_encoding_js_1.BinaryReader(uf.data), field, uf.wireType, ctx);
|
|
52
51
|
}
|
|
53
52
|
return get();
|
|
54
53
|
}
|
|
@@ -13,7 +13,20 @@ export interface BinaryReadOptions {
|
|
|
13
13
|
* For more details see https://developers.google.com/protocol-buffers/docs/proto3#unknowns
|
|
14
14
|
*/
|
|
15
15
|
readUnknownFields: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The maximum depth of nested messages to parse. If a message nests deeper
|
|
18
|
+
* than this limit, parsing fails with an error instead of exhausting the
|
|
19
|
+
* call stack. Defaults to 100.
|
|
20
|
+
*/
|
|
21
|
+
recursionLimit: number;
|
|
22
|
+
}
|
|
23
|
+
interface BinaryReadContext extends BinaryReadOptions {
|
|
24
|
+
depth: number;
|
|
16
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* @private Only exported for getExtension()
|
|
28
|
+
*/
|
|
29
|
+
export declare function makeReadContext(options?: Partial<BinaryReadOptions>): BinaryReadContext;
|
|
17
30
|
/**
|
|
18
31
|
* Parse serialized binary data.
|
|
19
32
|
*/
|
|
@@ -29,6 +42,7 @@ export declare function fromBinary<Desc extends DescMessage>(schema: Desc, bytes
|
|
|
29
42
|
*/
|
|
30
43
|
export declare function mergeFromBinary<Desc extends DescMessage>(schema: Desc, target: MessageShape<Desc>, bytes: Uint8Array, options?: Partial<BinaryReadOptions>): MessageShape<Desc>;
|
|
31
44
|
/**
|
|
32
|
-
* @private
|
|
45
|
+
* @private Only exported for getExtension()
|
|
33
46
|
*/
|
|
34
|
-
export declare function readField(message: ReflectMessage, reader: BinaryReader, field: DescField, wireType: WireType,
|
|
47
|
+
export declare function readField(message: ReflectMessage, reader: BinaryReader, field: DescField, wireType: WireType, ctx: BinaryReadContext): void;
|
|
48
|
+
export {};
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.makeReadContext = makeReadContext;
|
|
16
17
|
exports.fromBinary = fromBinary;
|
|
17
18
|
exports.mergeFromBinary = mergeFromBinary;
|
|
18
19
|
exports.readField = readField;
|
|
@@ -21,19 +22,18 @@ const scalar_js_1 = require("./reflect/scalar.js");
|
|
|
21
22
|
const reflect_js_1 = require("./reflect/reflect.js");
|
|
22
23
|
const binary_encoding_js_1 = require("./wire/binary-encoding.js");
|
|
23
24
|
const varint_js_1 = require("./wire/varint.js");
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return options ? Object.assign(Object.assign({}, readDefaults), options) : readDefaults;
|
|
25
|
+
/**
|
|
26
|
+
* @private Only exported for getExtension()
|
|
27
|
+
*/
|
|
28
|
+
function makeReadContext(options) {
|
|
29
|
+
return Object.assign(Object.assign({ readUnknownFields: true, recursionLimit: 100 }, options), { depth: 0 });
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Parse serialized binary data.
|
|
33
33
|
*/
|
|
34
34
|
function fromBinary(schema, bytes, options) {
|
|
35
35
|
const msg = (0, reflect_js_1.reflect)(schema, undefined, false);
|
|
36
|
-
readMessage(msg, new binary_encoding_js_1.BinaryReader(bytes),
|
|
36
|
+
readMessage(msg, new binary_encoding_js_1.BinaryReader(bytes), makeReadContext(options), false, bytes.byteLength);
|
|
37
37
|
return msg.message;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
@@ -46,7 +46,7 @@ function fromBinary(schema, bytes, options) {
|
|
|
46
46
|
* new data.
|
|
47
47
|
*/
|
|
48
48
|
function mergeFromBinary(schema, target, bytes, options) {
|
|
49
|
-
readMessage((0, reflect_js_1.reflect)(schema, target, false), new binary_encoding_js_1.BinaryReader(bytes),
|
|
49
|
+
readMessage((0, reflect_js_1.reflect)(schema, target, false), new binary_encoding_js_1.BinaryReader(bytes), makeReadContext(options), false, bytes.byteLength);
|
|
50
50
|
return target;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
@@ -57,8 +57,11 @@ function mergeFromBinary(schema, target, bytes, options) {
|
|
|
57
57
|
*
|
|
58
58
|
* @private
|
|
59
59
|
*/
|
|
60
|
-
function readMessage(message, reader,
|
|
60
|
+
function readMessage(message, reader, ctx, delimited, lengthOrDelimitedFieldNo) {
|
|
61
61
|
var _a;
|
|
62
|
+
if (++ctx.depth > ctx.recursionLimit) {
|
|
63
|
+
throw new Error(`cannot decode ${message.desc} from binary: maximum recursion depth of ${ctx.recursionLimit} reached`);
|
|
64
|
+
}
|
|
62
65
|
const end = delimited ? reader.len : reader.pos + lengthOrDelimitedFieldNo;
|
|
63
66
|
let fieldNo;
|
|
64
67
|
let wireType;
|
|
@@ -70,13 +73,15 @@ function readMessage(message, reader, options, delimited, lengthOrDelimitedField
|
|
|
70
73
|
}
|
|
71
74
|
const field = message.findNumber(fieldNo);
|
|
72
75
|
if (!field) {
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
// Use remaining recursion budget for skipping nested groups
|
|
77
|
+
const recursionLimit = ctx.recursionLimit - ctx.depth;
|
|
78
|
+
const data = reader.skip(wireType, fieldNo, recursionLimit);
|
|
79
|
+
if (ctx.readUnknownFields) {
|
|
75
80
|
unknownFields.push({ no: fieldNo, wireType, data });
|
|
76
81
|
}
|
|
77
82
|
continue;
|
|
78
83
|
}
|
|
79
|
-
readField(message, reader, field, wireType,
|
|
84
|
+
readField(message, reader, field, wireType, ctx);
|
|
80
85
|
}
|
|
81
86
|
if (delimited) {
|
|
82
87
|
if (wireType != binary_encoding_js_1.WireType.EndGroup || fieldNo !== lengthOrDelimitedFieldNo) {
|
|
@@ -86,11 +91,12 @@ function readMessage(message, reader, options, delimited, lengthOrDelimitedField
|
|
|
86
91
|
if (unknownFields.length > 0) {
|
|
87
92
|
message.setUnknown(unknownFields);
|
|
88
93
|
}
|
|
94
|
+
ctx.depth--;
|
|
89
95
|
}
|
|
90
96
|
/**
|
|
91
|
-
* @private
|
|
97
|
+
* @private Only exported for getExtension()
|
|
92
98
|
*/
|
|
93
|
-
function readField(message, reader, field, wireType,
|
|
99
|
+
function readField(message, reader, field, wireType, ctx) {
|
|
94
100
|
var _a;
|
|
95
101
|
switch (field.fieldKind) {
|
|
96
102
|
case "scalar":
|
|
@@ -106,7 +112,7 @@ function readField(message, reader, field, wireType, options) {
|
|
|
106
112
|
if (ok) {
|
|
107
113
|
message.set(field, val);
|
|
108
114
|
}
|
|
109
|
-
else if (
|
|
115
|
+
else if (ctx.readUnknownFields) {
|
|
110
116
|
const bytes = [];
|
|
111
117
|
(0, varint_js_1.varint32write)(val, bytes);
|
|
112
118
|
const unknownFields = (_a = message.getUnknown()) !== null && _a !== void 0 ? _a : [];
|
|
@@ -120,18 +126,18 @@ function readField(message, reader, field, wireType, options) {
|
|
|
120
126
|
}
|
|
121
127
|
break;
|
|
122
128
|
case "message":
|
|
123
|
-
message.set(field, readMessageField(reader,
|
|
129
|
+
message.set(field, readMessageField(reader, ctx, field, message.get(field)));
|
|
124
130
|
break;
|
|
125
131
|
case "list":
|
|
126
|
-
readListField(reader, wireType, message.get(field),
|
|
132
|
+
readListField(reader, wireType, message.get(field), ctx);
|
|
127
133
|
break;
|
|
128
134
|
case "map":
|
|
129
|
-
readMapEntry(reader, message.get(field),
|
|
135
|
+
readMapEntry(reader, message.get(field), ctx);
|
|
130
136
|
break;
|
|
131
137
|
}
|
|
132
138
|
}
|
|
133
139
|
// Read a map field, expecting key field = 1, value field = 2
|
|
134
|
-
function readMapEntry(reader, map,
|
|
140
|
+
function readMapEntry(reader, map, ctx) {
|
|
135
141
|
const field = map.field();
|
|
136
142
|
let key;
|
|
137
143
|
let val;
|
|
@@ -155,7 +161,7 @@ function readMapEntry(reader, map, options) {
|
|
|
155
161
|
val = reader.int32();
|
|
156
162
|
break;
|
|
157
163
|
case "message":
|
|
158
|
-
val = readMessageField(reader,
|
|
164
|
+
val = readMessageField(reader, ctx, field);
|
|
159
165
|
break;
|
|
160
166
|
}
|
|
161
167
|
break;
|
|
@@ -179,11 +185,11 @@ function readMapEntry(reader, map, options) {
|
|
|
179
185
|
}
|
|
180
186
|
map.set(key, val);
|
|
181
187
|
}
|
|
182
|
-
function readListField(reader, wireType, list,
|
|
188
|
+
function readListField(reader, wireType, list, ctx) {
|
|
183
189
|
var _a;
|
|
184
190
|
const field = list.field();
|
|
185
191
|
if (field.listKind === "message") {
|
|
186
|
-
list.add(readMessageField(reader,
|
|
192
|
+
list.add(readMessageField(reader, ctx, field));
|
|
187
193
|
return;
|
|
188
194
|
}
|
|
189
195
|
const scalarType = (_a = field.scalar) !== null && _a !== void 0 ? _a : descriptors_js_1.ScalarType.INT32;
|
|
@@ -199,10 +205,10 @@ function readListField(reader, wireType, list, options) {
|
|
|
199
205
|
list.add(readScalar(reader, scalarType, field.utf8Validation));
|
|
200
206
|
}
|
|
201
207
|
}
|
|
202
|
-
function readMessageField(reader,
|
|
208
|
+
function readMessageField(reader, ctx, field, mergeMessage) {
|
|
203
209
|
const delimited = field.delimitedEncoding;
|
|
204
210
|
const message = mergeMessage !== null && mergeMessage !== void 0 ? mergeMessage : (0, reflect_js_1.reflect)(field.message, undefined, false);
|
|
205
|
-
readMessage(message, reader,
|
|
211
|
+
readMessage(message, reader, ctx, delimited, delimited ? field.number : reader.uint32());
|
|
206
212
|
return message;
|
|
207
213
|
}
|
|
208
214
|
function readScalar(reader, type, validateUtf8 = false) {
|
|
@@ -17,33 +17,50 @@ export interface JsonReadOptions {
|
|
|
17
17
|
* from JSON format.
|
|
18
18
|
*/
|
|
19
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;
|
|
20
26
|
}
|
|
21
27
|
/**
|
|
22
28
|
* Parse a message from a JSON string.
|
|
29
|
+
*
|
|
30
|
+
* Duplicate keys are rejected.
|
|
23
31
|
*/
|
|
24
32
|
export declare function fromJsonString<Desc extends DescMessage>(schema: Desc, json: string, options?: Partial<JsonReadOptions>): MessageShape<Desc>;
|
|
25
33
|
/**
|
|
26
|
-
* Parse a message from a JSON string, merging fields.
|
|
34
|
+
* Parse a message from a JSON string, merging fields into the target.
|
|
27
35
|
*
|
|
28
36
|
* Repeated fields are appended. Map entries are added, overwriting
|
|
29
37
|
* existing keys.
|
|
30
38
|
*
|
|
31
39
|
* If a message field is already present, it will be merged with the
|
|
32
40
|
* new data.
|
|
41
|
+
*
|
|
42
|
+
* Duplicate keys in the JSON are rejected, as in `fromJsonString`.
|
|
33
43
|
*/
|
|
34
44
|
export declare function mergeFromJsonString<Desc extends DescMessage>(schema: Desc, target: MessageShape<Desc>, json: string, options?: Partial<JsonReadOptions>): MessageShape<Desc>;
|
|
35
45
|
/**
|
|
36
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.
|
|
37
51
|
*/
|
|
38
52
|
export declare function fromJson<Desc extends DescMessage>(schema: Desc, json: JsonValue, options?: Partial<JsonReadOptions>): MessageShape<Desc>;
|
|
39
53
|
/**
|
|
40
|
-
* Parse a message from a JSON value, merging fields.
|
|
54
|
+
* Parse a message from a JSON value, merging fields into the target.
|
|
41
55
|
*
|
|
42
56
|
* Repeated fields are appended. Map entries are added, overwriting
|
|
43
57
|
* existing keys.
|
|
44
58
|
*
|
|
45
59
|
* If a message field is already present, it will be merged with the
|
|
46
60
|
* new data.
|
|
61
|
+
*
|
|
62
|
+
* Duplicate keys are rejected as in `fromJson`; use `mergeFromJsonString`
|
|
63
|
+
* for strict checking.
|
|
47
64
|
*/
|
|
48
65
|
export declare function mergeFromJson<Desc extends DescMessage>(schema: Desc, target: MessageShape<Desc>, json: JsonValue, options?: Partial<JsonReadOptions>): MessageShape<Desc>;
|
|
49
66
|
/**
|