@bufbuild/protobuf 0.0.1-alpha.1 → 0.0.2-alpha.2

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.
Files changed (138) hide show
  1. package/dist/cjs/binary-encoding.js +414 -409
  2. package/dist/cjs/binary-format.js +13 -0
  3. package/dist/cjs/descriptor-registry.js +420 -449
  4. package/dist/cjs/descriptor-set.js +429 -513
  5. package/dist/cjs/enum.js +13 -0
  6. package/dist/cjs/field-list.js +13 -0
  7. package/dist/cjs/field.js +43 -30
  8. package/dist/cjs/google/protobuf/any_pb.js +122 -140
  9. package/dist/cjs/google/protobuf/api_pb.js +177 -224
  10. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +125 -227
  11. package/dist/cjs/google/protobuf/descriptor_pb.js +1029 -1888
  12. package/dist/cjs/google/protobuf/duration_pb.js +72 -88
  13. package/dist/cjs/google/protobuf/empty_pb.js +17 -17
  14. package/dist/cjs/google/protobuf/field_mask_pb.js +77 -94
  15. package/dist/cjs/google/protobuf/source_context_pb.js +25 -25
  16. package/dist/cjs/google/protobuf/struct_pb.js +144 -181
  17. package/dist/cjs/google/protobuf/timestamp_pb.js +86 -123
  18. package/dist/cjs/google/protobuf/type_pb.js +406 -462
  19. package/dist/cjs/google/protobuf/wrappers_pb.js +407 -470
  20. package/dist/cjs/google/varint.js +166 -171
  21. package/dist/cjs/index.js +41 -122
  22. package/dist/cjs/json-format.js +13 -0
  23. package/dist/cjs/message-type.js +13 -0
  24. package/dist/cjs/message.js +89 -85
  25. package/dist/cjs/private/assert.js +33 -26
  26. package/dist/cjs/private/base64.js +93 -79
  27. package/dist/cjs/private/binary-format-common.js +208 -208
  28. package/dist/cjs/private/binary-format-proto2.js +88 -109
  29. package/dist/cjs/private/binary-format-proto3.js +70 -90
  30. package/dist/cjs/private/enum.js +77 -44
  31. package/dist/cjs/private/field-list.js +64 -50
  32. package/dist/cjs/private/field-wrapper.js +21 -10
  33. package/dist/cjs/private/field.js +35 -25
  34. package/dist/cjs/private/json-format-common.js +427 -440
  35. package/dist/cjs/private/json-format-proto2.js +91 -89
  36. package/dist/cjs/private/json-format-proto3.js +82 -93
  37. package/dist/cjs/private/message-type.js +39 -27
  38. package/dist/cjs/private/names.js +71 -62
  39. package/dist/cjs/private/options-map.js +13 -0
  40. package/dist/cjs/private/proto-runtime.js +25 -16
  41. package/dist/cjs/private/scalars.js +113 -103
  42. package/dist/cjs/private/util-common.js +193 -210
  43. package/dist/cjs/private/util.js +13 -0
  44. package/dist/cjs/proto-int64.js +123 -111
  45. package/dist/cjs/proto2.js +63 -63
  46. package/dist/cjs/proto3.js +74 -74
  47. package/dist/cjs/service-type.js +27 -17
  48. package/dist/cjs/type-registry.js +46 -31
  49. package/dist/esm/binary-encoding.js +414 -414
  50. package/dist/esm/binary-format.js +13 -0
  51. package/dist/esm/descriptor-registry.js +422 -458
  52. package/dist/esm/descriptor-set.js +430 -478
  53. package/dist/esm/enum.js +13 -0
  54. package/dist/esm/field-list.js +13 -0
  55. package/dist/esm/field.js +42 -29
  56. package/dist/esm/google/protobuf/any_pb.js +122 -140
  57. package/dist/esm/google/protobuf/api_pb.js +177 -197
  58. package/dist/esm/google/protobuf/compiler/plugin_pb.js +123 -216
  59. package/dist/esm/google/protobuf/descriptor_pb.js +1013 -1804
  60. package/dist/esm/google/protobuf/duration_pb.js +72 -88
  61. package/dist/esm/google/protobuf/empty_pb.js +17 -17
  62. package/dist/esm/google/protobuf/field_mask_pb.js +77 -94
  63. package/dist/esm/google/protobuf/source_context_pb.js +25 -25
  64. package/dist/esm/google/protobuf/struct_pb.js +143 -180
  65. package/dist/esm/google/protobuf/timestamp_pb.js +86 -123
  66. package/dist/esm/google/protobuf/type_pb.js +401 -421
  67. package/dist/esm/google/protobuf/wrappers_pb.js +406 -397
  68. package/dist/esm/google/varint.js +165 -164
  69. package/dist/esm/index.js +14 -1
  70. package/dist/esm/json-format.js +13 -0
  71. package/dist/esm/message-type.js +13 -0
  72. package/dist/esm/message.js +89 -85
  73. package/dist/esm/private/assert.js +32 -21
  74. package/dist/esm/private/base64.js +92 -78
  75. package/dist/esm/private/binary-format-common.js +209 -207
  76. package/dist/esm/private/binary-format-proto2.js +89 -81
  77. package/dist/esm/private/binary-format-proto3.js +71 -67
  78. package/dist/esm/private/enum.js +75 -43
  79. package/dist/esm/private/field-list.js +64 -50
  80. package/dist/esm/private/field-wrapper.js +21 -10
  81. package/dist/esm/private/field.js +35 -22
  82. package/dist/esm/private/json-format-common.js +427 -435
  83. package/dist/esm/private/json-format-proto2.js +89 -81
  84. package/dist/esm/private/json-format-proto3.js +79 -80
  85. package/dist/esm/private/message-type.js +40 -28
  86. package/dist/esm/private/names.js +70 -57
  87. package/dist/esm/private/options-map.js +13 -0
  88. package/dist/esm/private/proto-runtime.js +26 -12
  89. package/dist/esm/private/scalars.js +112 -99
  90. package/dist/esm/private/util-common.js +193 -192
  91. package/dist/esm/private/util.js +13 -0
  92. package/dist/esm/proto-int64.js +123 -111
  93. package/dist/esm/proto2.js +63 -57
  94. package/dist/esm/proto3.js +74 -68
  95. package/dist/esm/service-type.js +25 -12
  96. package/dist/esm/type-registry.js +46 -31
  97. package/dist/types/binary-encoding.d.ts +398 -398
  98. package/dist/types/binary-format.d.ts +69 -91
  99. package/dist/types/descriptor-registry.d.ts +23 -29
  100. package/dist/types/descriptor-set.d.ts +107 -128
  101. package/dist/types/enum.d.ts +21 -21
  102. package/dist/types/field-list.d.ts +21 -21
  103. package/dist/types/field.d.ts +191 -231
  104. package/dist/types/google/protobuf/any_pb.d.ts +56 -77
  105. package/dist/types/google/protobuf/api_pb.d.ts +144 -187
  106. package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +195 -257
  107. package/dist/types/google/protobuf/descriptor_pb.d.ts +1360 -1737
  108. package/dist/types/google/protobuf/duration_pb.d.ts +30 -50
  109. package/dist/types/google/protobuf/empty_pb.d.ts +9 -28
  110. package/dist/types/google/protobuf/field_mask_pb.d.ts +17 -37
  111. package/dist/types/google/protobuf/source_context_pb.d.ts +16 -35
  112. package/dist/types/google/protobuf/struct_pb.d.ts +64 -115
  113. package/dist/types/google/protobuf/timestamp_pb.d.ts +31 -51
  114. package/dist/types/google/protobuf/type_pb.d.ts +355 -422
  115. package/dist/types/google/protobuf/wrappers_pb.d.ts +181 -297
  116. package/dist/types/google/varint.d.ts +6 -13
  117. package/dist/types/index.d.ts +4 -27
  118. package/dist/types/json-format.d.ts +70 -89
  119. package/dist/types/message-type.d.ts +37 -45
  120. package/dist/types/message.d.ts +62 -87
  121. package/dist/types/private/assert.d.ts +1 -4
  122. package/dist/types/private/binary-format-common.d.ts +6 -32
  123. package/dist/types/private/enum.d.ts +13 -11
  124. package/dist/types/private/field-list.d.ts +14 -21
  125. package/dist/types/private/field-wrapper.d.ts +4 -10
  126. package/dist/types/private/field.d.ts +12 -12
  127. package/dist/types/private/json-format-common.d.ts +5 -27
  128. package/dist/types/private/message-type.d.ts +12 -7
  129. package/dist/types/private/names.d.ts +1 -4
  130. package/dist/types/private/options-map.d.ts +1 -1
  131. package/dist/types/private/proto-runtime.d.ts +34 -42
  132. package/dist/types/private/scalars.d.ts +5 -12
  133. package/dist/types/private/util-common.d.ts +1 -4
  134. package/dist/types/private/util.d.ts +29 -41
  135. package/dist/types/proto-int64.d.ts +42 -42
  136. package/dist/types/service-type.d.ts +36 -56
  137. package/dist/types/type-registry.d.ts +13 -15
  138. package/package.json +2 -3
package/dist/cjs/enum.js CHANGED
@@ -1,2 +1,15 @@
1
1
  "use strict";
2
+ // Copyright 2021-2022 Buf Technologies, Inc.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
2
15
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,15 @@
1
1
  "use strict";
2
+ // Copyright 2021-2022 Buf Technologies, Inc.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
2
15
  Object.defineProperty(exports, "__esModule", { value: true });
package/dist/cjs/field.js CHANGED
@@ -1,4 +1,17 @@
1
1
  "use strict";
2
+ // Copyright 2021-2022 Buf Technologies, Inc.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
2
15
  Object.defineProperty(exports, "__esModule", { value: true });
3
16
  exports.ScalarType = void 0;
4
17
  /**
@@ -8,33 +21,33 @@ exports.ScalarType = void 0;
8
21
  */
9
22
  var ScalarType;
10
23
  (function (ScalarType) {
11
- // 0 is reserved for errors.
12
- // Order is weird for historical reasons.
13
- ScalarType[(ScalarType["DOUBLE"] = 1)] = "DOUBLE";
14
- ScalarType[(ScalarType["FLOAT"] = 2)] = "FLOAT";
15
- // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
16
- // negative values are likely.
17
- ScalarType[(ScalarType["INT64"] = 3)] = "INT64";
18
- ScalarType[(ScalarType["UINT64"] = 4)] = "UINT64";
19
- // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
20
- // negative values are likely.
21
- ScalarType[(ScalarType["INT32"] = 5)] = "INT32";
22
- ScalarType[(ScalarType["FIXED64"] = 6)] = "FIXED64";
23
- ScalarType[(ScalarType["FIXED32"] = 7)] = "FIXED32";
24
- ScalarType[(ScalarType["BOOL"] = 8)] = "BOOL";
25
- ScalarType[(ScalarType["STRING"] = 9)] = "STRING";
26
- // Tag-delimited aggregate.
27
- // Group type is deprecated and not supported in proto3. However, Proto3
28
- // implementations should still be able to parse the group wire format and
29
- // treat group fields as unknown fields.
30
- // TYPE_GROUP = 10,
31
- // TYPE_MESSAGE = 11, // Length-delimited aggregate.
32
- // New in version 2.
33
- ScalarType[(ScalarType["BYTES"] = 12)] = "BYTES";
34
- ScalarType[(ScalarType["UINT32"] = 13)] = "UINT32";
35
- // TYPE_ENUM = 14,
36
- ScalarType[(ScalarType["SFIXED32"] = 15)] = "SFIXED32";
37
- ScalarType[(ScalarType["SFIXED64"] = 16)] = "SFIXED64";
38
- ScalarType[(ScalarType["SINT32"] = 17)] = "SINT32";
39
- ScalarType[(ScalarType["SINT64"] = 18)] = "SINT64";
40
- })((ScalarType = exports.ScalarType || (exports.ScalarType = {})));
24
+ // 0 is reserved for errors.
25
+ // Order is weird for historical reasons.
26
+ ScalarType[ScalarType["DOUBLE"] = 1] = "DOUBLE";
27
+ ScalarType[ScalarType["FLOAT"] = 2] = "FLOAT";
28
+ // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
29
+ // negative values are likely.
30
+ ScalarType[ScalarType["INT64"] = 3] = "INT64";
31
+ ScalarType[ScalarType["UINT64"] = 4] = "UINT64";
32
+ // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
33
+ // negative values are likely.
34
+ ScalarType[ScalarType["INT32"] = 5] = "INT32";
35
+ ScalarType[ScalarType["FIXED64"] = 6] = "FIXED64";
36
+ ScalarType[ScalarType["FIXED32"] = 7] = "FIXED32";
37
+ ScalarType[ScalarType["BOOL"] = 8] = "BOOL";
38
+ ScalarType[ScalarType["STRING"] = 9] = "STRING";
39
+ // Tag-delimited aggregate.
40
+ // Group type is deprecated and not supported in proto3. However, Proto3
41
+ // implementations should still be able to parse the group wire format and
42
+ // treat group fields as unknown fields.
43
+ // TYPE_GROUP = 10,
44
+ // TYPE_MESSAGE = 11, // Length-delimited aggregate.
45
+ // New in version 2.
46
+ ScalarType[ScalarType["BYTES"] = 12] = "BYTES";
47
+ ScalarType[ScalarType["UINT32"] = 13] = "UINT32";
48
+ // TYPE_ENUM = 14,
49
+ ScalarType[ScalarType["SFIXED32"] = 15] = "SFIXED32";
50
+ ScalarType[ScalarType["SFIXED64"] = 16] = "SFIXED64";
51
+ ScalarType[ScalarType["SINT32"] = 17] = "SINT32";
52
+ ScalarType[ScalarType["SINT64"] = 18] = "SINT64";
53
+ })(ScalarType = exports.ScalarType || (exports.ScalarType = {}));
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
- // @generated by protoc-gen-es v0.0.1-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
4
4
  // @generated from file google/protobuf/any.proto (package google.protobuf, syntax proto3)
5
5
  //
6
6
  // Protocol Buffers - Google's data interchange format
@@ -123,158 +123,140 @@ const index_js_1 = require("../../index.js");
123
123
  * @generated from message google.protobuf.Any
124
124
  */
125
125
  class Any extends index_js_1.Message {
126
- constructor(data) {
127
- super();
128
- /**
129
- * A URL/resource name that uniquely identifies the type of the serialized
130
- * protocol buffer message. This string must contain at least
131
- * one "/" character. The last segment of the URL's path must represent
132
- * the fully qualified name of the type (as in
133
- * `path/google.protobuf.Duration`). The name should be in a canonical form
134
- * (e.g., leading "." is not accepted).
135
- *
136
- * In practice, teams usually precompile into the binary all types that they
137
- * expect it to use in the context of Any. However, for URLs which use the
138
- * scheme `http`, `https`, or no scheme, one can optionally set up a type
139
- * server that maps type URLs to message definitions as follows:
140
- *
141
- * * If no scheme is provided, `https` is assumed.
142
- * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
143
- * value in binary format, or produce an error.
144
- * * Applications are allowed to cache lookup results based on the
145
- * URL, or have them precompiled into a binary to avoid any
146
- * lookup. Therefore, binary compatibility needs to be preserved
147
- * on changes to types. (Use versioned type names to manage
148
- * breaking changes.)
149
- *
150
- * Note: this functionality is not currently available in the official
151
- * protobuf release, and it is not used for type URLs beginning with
152
- * type.googleapis.com.
153
- *
154
- * Schemes other than `http`, `https` (or the empty scheme) might be
155
- * used with implementation specific semantics.
156
- *
157
- *
158
- * @generated from field: string type_url = 1;
159
- */
160
- this.typeUrl = "";
161
- /**
162
- * Must be a valid serialized protocol buffer of the above specified type.
163
- *
164
- * @generated from field: bytes value = 2;
165
- */
166
- this.value = new Uint8Array(0);
167
- index_js_1.proto3.util.initPartial(data, this);
168
- }
169
- toJson(options) {
170
- if (this.typeUrl === "") {
171
- return {};
126
+ constructor(data) {
127
+ super();
128
+ /**
129
+ * A URL/resource name that uniquely identifies the type of the serialized
130
+ * protocol buffer message. This string must contain at least
131
+ * one "/" character. The last segment of the URL's path must represent
132
+ * the fully qualified name of the type (as in
133
+ * `path/google.protobuf.Duration`). The name should be in a canonical form
134
+ * (e.g., leading "." is not accepted).
135
+ *
136
+ * In practice, teams usually precompile into the binary all types that they
137
+ * expect it to use in the context of Any. However, for URLs which use the
138
+ * scheme `http`, `https`, or no scheme, one can optionally set up a type
139
+ * server that maps type URLs to message definitions as follows:
140
+ *
141
+ * * If no scheme is provided, `https` is assumed.
142
+ * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
143
+ * value in binary format, or produce an error.
144
+ * * Applications are allowed to cache lookup results based on the
145
+ * URL, or have them precompiled into a binary to avoid any
146
+ * lookup. Therefore, binary compatibility needs to be preserved
147
+ * on changes to types. (Use versioned type names to manage
148
+ * breaking changes.)
149
+ *
150
+ * Note: this functionality is not currently available in the official
151
+ * protobuf release, and it is not used for type URLs beginning with
152
+ * type.googleapis.com.
153
+ *
154
+ * Schemes other than `http`, `https` (or the empty scheme) might be
155
+ * used with implementation specific semantics.
156
+ *
157
+ *
158
+ * @generated from field: string type_url = 1;
159
+ */
160
+ this.typeUrl = "";
161
+ /**
162
+ * Must be a valid serialized protocol buffer of the above specified type.
163
+ *
164
+ * @generated from field: bytes value = 2;
165
+ */
166
+ this.value = new Uint8Array(0);
167
+ index_js_1.proto3.util.initPartial(data, this);
172
168
  }
173
- const typeName = this.typeUrlToName(this.typeUrl);
174
- const messageType = options?.typeRegistry?.findMessage(typeName);
175
- if (!messageType) {
176
- throw new Error(
177
- `cannot encode message google.protobuf.Any to JSON: "${this.typeUrl}" is not in the type registry`
178
- );
169
+ toJson(options) {
170
+ if (this.typeUrl === "") {
171
+ return {};
172
+ }
173
+ const typeName = this.typeUrlToName(this.typeUrl);
174
+ const messageType = options?.typeRegistry?.findMessage(typeName);
175
+ if (!messageType) {
176
+ throw new Error(`cannot encode message google.protobuf.Any to JSON: "${this.typeUrl}" is not in the type registry`);
177
+ }
178
+ const message = messageType.fromBinary(this.value);
179
+ let json = message.toJson(options);
180
+ if (typeName.startsWith("google.protobuf.") || (json === null || Array.isArray(json) || typeof json !== "object")) {
181
+ json = { value: json };
182
+ }
183
+ json["@type"] = this.typeUrl;
184
+ return json;
179
185
  }
180
- const message = messageType.fromBinary(this.value);
181
- let json = message.toJson(options);
182
- if (
183
- typeName.startsWith("google.protobuf.") ||
184
- json === null ||
185
- Array.isArray(json) ||
186
- typeof json !== "object"
187
- ) {
188
- json = { value: json };
186
+ fromJson(json, options) {
187
+ if (json === null || Array.isArray(json) || typeof json != "object") {
188
+ throw new Error(`cannot decode message google.protobuf.Any from JSON: expected object but got ${json === null ? "null" : Array.isArray(json) ? "array" : typeof json}`);
189
+ }
190
+ const typeUrl = json["@type"];
191
+ if (typeof typeUrl != "string" || typeUrl == "") {
192
+ throw new Error(`cannot decode message google.protobuf.Any from JSON: "@type" is empty`);
193
+ }
194
+ const typeName = this.typeUrlToName(typeUrl), messageType = options?.typeRegistry?.findMessage(typeName);
195
+ if (!messageType) {
196
+ throw new Error(`cannot decode message google.protobuf.Any from JSON: ${typeUrl} is not in the type registry`);
197
+ }
198
+ let message;
199
+ if (typeName.startsWith("google.protobuf.") && Object.prototype.hasOwnProperty.call(json, "value")) {
200
+ message = messageType.fromJson(json["value"], options);
201
+ }
202
+ else {
203
+ const copy = Object.assign({}, json);
204
+ delete copy["@type"];
205
+ message = messageType.fromJson(copy, options);
206
+ }
207
+ this.packFrom(message);
208
+ return this;
189
209
  }
190
- json["@type"] = this.typeUrl;
191
- return json;
192
- }
193
- fromJson(json, options) {
194
- if (json === null || Array.isArray(json) || typeof json != "object") {
195
- throw new Error(
196
- `cannot decode message google.protobuf.Any from JSON: expected object but got ${
197
- json === null ? "null" : Array.isArray(json) ? "array" : typeof json
198
- }`
199
- );
210
+ packFrom(message) {
211
+ this.value = message.toBinary();
212
+ this.typeUrl = this.typeNameToUrl(message.getType().typeName);
200
213
  }
201
- const typeUrl = json["@type"];
202
- if (typeof typeUrl != "string" || typeUrl == "") {
203
- throw new Error(
204
- `cannot decode message google.protobuf.Any from JSON: "@type" is empty`
205
- );
214
+ unpackTo(target) {
215
+ if (!this.is(target.getType())) {
216
+ return false;
217
+ }
218
+ target.fromBinary(this.value);
219
+ return true;
206
220
  }
207
- const typeName = this.typeUrlToName(typeUrl),
208
- messageType = options?.typeRegistry?.findMessage(typeName);
209
- if (!messageType) {
210
- throw new Error(
211
- `cannot decode message google.protobuf.Any from JSON: ${typeUrl} is not in the type registry`
212
- );
221
+ is(type) {
222
+ return this.typeUrl === this.typeNameToUrl(type.typeName);
213
223
  }
214
- let message;
215
- if (
216
- typeName.startsWith("google.protobuf.") &&
217
- Object.prototype.hasOwnProperty.call(json, "value")
218
- ) {
219
- message = messageType.fromJson(json["value"], options);
220
- } else {
221
- const copy = Object.assign({}, json);
222
- delete copy["@type"];
223
- message = messageType.fromJson(copy, options);
224
+ typeNameToUrl(name) {
225
+ return `type.googleapis.com/${name}`;
224
226
  }
225
- this.packFrom(message);
226
- return this;
227
- }
228
- packFrom(message) {
229
- this.value = message.toBinary();
230
- this.typeUrl = this.typeNameToUrl(message.getType().typeName);
231
- }
232
- unpackTo(target) {
233
- if (!this.is(target.getType())) {
234
- return false;
227
+ typeUrlToName(url) {
228
+ if (!url.length) {
229
+ throw new Error(`invalid type url: ${url}`);
230
+ }
231
+ const slash = url.lastIndexOf("/");
232
+ const name = slash > 0 ? url.substring(slash + 1) : url;
233
+ if (!name.length) {
234
+ throw new Error(`invalid type url: ${url}`);
235
+ }
236
+ return name;
235
237
  }
236
- target.fromBinary(this.value);
237
- return true;
238
- }
239
- is(type) {
240
- return this.typeUrl === this.typeNameToUrl(type.typeName);
241
- }
242
- typeNameToUrl(name) {
243
- return `type.googleapis.com/${name}`;
244
- }
245
- typeUrlToName(url) {
246
- if (!url.length) {
247
- throw new Error(`invalid type url: ${url}`);
238
+ static pack(message) {
239
+ const any = new Any();
240
+ any.packFrom(message);
241
+ return any;
248
242
  }
249
- const slash = url.lastIndexOf("/");
250
- const name = slash > 0 ? url.substring(slash + 1) : url;
251
- if (!name.length) {
252
- throw new Error(`invalid type url: ${url}`);
243
+ static fromBinary(bytes, options) {
244
+ return new Any().fromBinary(bytes, options);
245
+ }
246
+ static fromJson(jsonValue, options) {
247
+ return new Any().fromJson(jsonValue, options);
248
+ }
249
+ static fromJsonString(jsonString, options) {
250
+ return new Any().fromJsonString(jsonString, options);
251
+ }
252
+ static equals(a, b) {
253
+ return index_js_1.proto3.util.equals(Any, a, b);
253
254
  }
254
- return name;
255
- }
256
- static pack(message) {
257
- const any = new Any();
258
- any.packFrom(message);
259
- return any;
260
- }
261
- static fromBinary(bytes, options) {
262
- return new Any().fromBinary(bytes, options);
263
- }
264
- static fromJson(jsonValue, options) {
265
- return new Any().fromJson(jsonValue, options);
266
- }
267
- static fromJsonString(jsonString, options) {
268
- return new Any().fromJsonString(jsonString, options);
269
- }
270
- static equals(a, b) {
271
- return index_js_1.proto3.util.equals(Any, a, b);
272
- }
273
255
  }
274
256
  exports.Any = Any;
275
257
  Any.runtime = index_js_1.proto3;
276
258
  Any.typeName = "google.protobuf.Any";
277
259
  Any.fields = index_js_1.proto3.util.newFieldList(() => [
278
- { no: 1, name: "type_url", kind: "scalar", T: 9 /* ScalarType.STRING */ },
279
- { no: 2, name: "value", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
260
+ { no: 1, name: "type_url", kind: "scalar", T: 9 /* ScalarType.STRING */ },
261
+ { no: 2, name: "value", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
280
262
  ]);