@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/esm/enum.js CHANGED
@@ -1 +1,14 @@
1
+ // Copyright 2021-2022 Buf Technologies, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
1
14
  export {};
@@ -1 +1,14 @@
1
+ // Copyright 2021-2022 Buf Technologies, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
1
14
  export {};
package/dist/esm/field.js CHANGED
@@ -1,3 +1,16 @@
1
+ // Copyright 2021-2022 Buf Technologies, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
1
14
  /**
2
15
  * Scalar value types. This is a subset of field types declared by protobuf
3
16
  * enum google.protobuf.FieldDescriptorProto.Type The types GROUP and MESSAGE
@@ -5,33 +18,33 @@
5
18
  */
6
19
  export var ScalarType;
7
20
  (function (ScalarType) {
8
- // 0 is reserved for errors.
9
- // Order is weird for historical reasons.
10
- ScalarType[(ScalarType["DOUBLE"] = 1)] = "DOUBLE";
11
- ScalarType[(ScalarType["FLOAT"] = 2)] = "FLOAT";
12
- // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
13
- // negative values are likely.
14
- ScalarType[(ScalarType["INT64"] = 3)] = "INT64";
15
- ScalarType[(ScalarType["UINT64"] = 4)] = "UINT64";
16
- // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
17
- // negative values are likely.
18
- ScalarType[(ScalarType["INT32"] = 5)] = "INT32";
19
- ScalarType[(ScalarType["FIXED64"] = 6)] = "FIXED64";
20
- ScalarType[(ScalarType["FIXED32"] = 7)] = "FIXED32";
21
- ScalarType[(ScalarType["BOOL"] = 8)] = "BOOL";
22
- ScalarType[(ScalarType["STRING"] = 9)] = "STRING";
23
- // Tag-delimited aggregate.
24
- // Group type is deprecated and not supported in proto3. However, Proto3
25
- // implementations should still be able to parse the group wire format and
26
- // treat group fields as unknown fields.
27
- // TYPE_GROUP = 10,
28
- // TYPE_MESSAGE = 11, // Length-delimited aggregate.
29
- // New in version 2.
30
- ScalarType[(ScalarType["BYTES"] = 12)] = "BYTES";
31
- ScalarType[(ScalarType["UINT32"] = 13)] = "UINT32";
32
- // TYPE_ENUM = 14,
33
- ScalarType[(ScalarType["SFIXED32"] = 15)] = "SFIXED32";
34
- ScalarType[(ScalarType["SFIXED64"] = 16)] = "SFIXED64";
35
- ScalarType[(ScalarType["SINT32"] = 17)] = "SINT32";
36
- ScalarType[(ScalarType["SINT64"] = 18)] = "SINT64";
21
+ // 0 is reserved for errors.
22
+ // Order is weird for historical reasons.
23
+ ScalarType[ScalarType["DOUBLE"] = 1] = "DOUBLE";
24
+ ScalarType[ScalarType["FLOAT"] = 2] = "FLOAT";
25
+ // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
26
+ // negative values are likely.
27
+ ScalarType[ScalarType["INT64"] = 3] = "INT64";
28
+ ScalarType[ScalarType["UINT64"] = 4] = "UINT64";
29
+ // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
30
+ // negative values are likely.
31
+ ScalarType[ScalarType["INT32"] = 5] = "INT32";
32
+ ScalarType[ScalarType["FIXED64"] = 6] = "FIXED64";
33
+ ScalarType[ScalarType["FIXED32"] = 7] = "FIXED32";
34
+ ScalarType[ScalarType["BOOL"] = 8] = "BOOL";
35
+ ScalarType[ScalarType["STRING"] = 9] = "STRING";
36
+ // Tag-delimited aggregate.
37
+ // Group type is deprecated and not supported in proto3. However, Proto3
38
+ // implementations should still be able to parse the group wire format and
39
+ // treat group fields as unknown fields.
40
+ // TYPE_GROUP = 10,
41
+ // TYPE_MESSAGE = 11, // Length-delimited aggregate.
42
+ // New in version 2.
43
+ ScalarType[ScalarType["BYTES"] = 12] = "BYTES";
44
+ ScalarType[ScalarType["UINT32"] = 13] = "UINT32";
45
+ // TYPE_ENUM = 14,
46
+ ScalarType[ScalarType["SFIXED32"] = 15] = "SFIXED32";
47
+ ScalarType[ScalarType["SFIXED64"] = 16] = "SFIXED64";
48
+ ScalarType[ScalarType["SINT32"] = 17] = "SINT32";
49
+ ScalarType[ScalarType["SINT64"] = 18] = "SINT64";
37
50
  })(ScalarType || (ScalarType = {}));
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.1-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
2
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
3
3
  // @generated from file google/protobuf/any.proto (package google.protobuf, syntax proto3)
4
4
  //
5
5
  // Protocol Buffers - Google's data interchange format
@@ -120,157 +120,139 @@ import { Message, proto3 } from "../../index.js";
120
120
  * @generated from message google.protobuf.Any
121
121
  */
122
122
  export class Any extends Message {
123
- constructor(data) {
124
- super();
125
- /**
126
- * A URL/resource name that uniquely identifies the type of the serialized
127
- * protocol buffer message. This string must contain at least
128
- * one "/" character. The last segment of the URL's path must represent
129
- * the fully qualified name of the type (as in
130
- * `path/google.protobuf.Duration`). The name should be in a canonical form
131
- * (e.g., leading "." is not accepted).
132
- *
133
- * In practice, teams usually precompile into the binary all types that they
134
- * expect it to use in the context of Any. However, for URLs which use the
135
- * scheme `http`, `https`, or no scheme, one can optionally set up a type
136
- * server that maps type URLs to message definitions as follows:
137
- *
138
- * * If no scheme is provided, `https` is assumed.
139
- * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
140
- * value in binary format, or produce an error.
141
- * * Applications are allowed to cache lookup results based on the
142
- * URL, or have them precompiled into a binary to avoid any
143
- * lookup. Therefore, binary compatibility needs to be preserved
144
- * on changes to types. (Use versioned type names to manage
145
- * breaking changes.)
146
- *
147
- * Note: this functionality is not currently available in the official
148
- * protobuf release, and it is not used for type URLs beginning with
149
- * type.googleapis.com.
150
- *
151
- * Schemes other than `http`, `https` (or the empty scheme) might be
152
- * used with implementation specific semantics.
153
- *
154
- *
155
- * @generated from field: string type_url = 1;
156
- */
157
- this.typeUrl = "";
158
- /**
159
- * Must be a valid serialized protocol buffer of the above specified type.
160
- *
161
- * @generated from field: bytes value = 2;
162
- */
163
- this.value = new Uint8Array(0);
164
- proto3.util.initPartial(data, this);
165
- }
166
- toJson(options) {
167
- if (this.typeUrl === "") {
168
- return {};
123
+ constructor(data) {
124
+ super();
125
+ /**
126
+ * A URL/resource name that uniquely identifies the type of the serialized
127
+ * protocol buffer message. This string must contain at least
128
+ * one "/" character. The last segment of the URL's path must represent
129
+ * the fully qualified name of the type (as in
130
+ * `path/google.protobuf.Duration`). The name should be in a canonical form
131
+ * (e.g., leading "." is not accepted).
132
+ *
133
+ * In practice, teams usually precompile into the binary all types that they
134
+ * expect it to use in the context of Any. However, for URLs which use the
135
+ * scheme `http`, `https`, or no scheme, one can optionally set up a type
136
+ * server that maps type URLs to message definitions as follows:
137
+ *
138
+ * * If no scheme is provided, `https` is assumed.
139
+ * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
140
+ * value in binary format, or produce an error.
141
+ * * Applications are allowed to cache lookup results based on the
142
+ * URL, or have them precompiled into a binary to avoid any
143
+ * lookup. Therefore, binary compatibility needs to be preserved
144
+ * on changes to types. (Use versioned type names to manage
145
+ * breaking changes.)
146
+ *
147
+ * Note: this functionality is not currently available in the official
148
+ * protobuf release, and it is not used for type URLs beginning with
149
+ * type.googleapis.com.
150
+ *
151
+ * Schemes other than `http`, `https` (or the empty scheme) might be
152
+ * used with implementation specific semantics.
153
+ *
154
+ *
155
+ * @generated from field: string type_url = 1;
156
+ */
157
+ this.typeUrl = "";
158
+ /**
159
+ * Must be a valid serialized protocol buffer of the above specified type.
160
+ *
161
+ * @generated from field: bytes value = 2;
162
+ */
163
+ this.value = new Uint8Array(0);
164
+ proto3.util.initPartial(data, this);
169
165
  }
170
- const typeName = this.typeUrlToName(this.typeUrl);
171
- const messageType = options?.typeRegistry?.findMessage(typeName);
172
- if (!messageType) {
173
- throw new Error(
174
- `cannot encode message google.protobuf.Any to JSON: "${this.typeUrl}" is not in the type registry`
175
- );
166
+ toJson(options) {
167
+ if (this.typeUrl === "") {
168
+ return {};
169
+ }
170
+ const typeName = this.typeUrlToName(this.typeUrl);
171
+ const messageType = options?.typeRegistry?.findMessage(typeName);
172
+ if (!messageType) {
173
+ throw new Error(`cannot encode message google.protobuf.Any to JSON: "${this.typeUrl}" is not in the type registry`);
174
+ }
175
+ const message = messageType.fromBinary(this.value);
176
+ let json = message.toJson(options);
177
+ if (typeName.startsWith("google.protobuf.") || (json === null || Array.isArray(json) || typeof json !== "object")) {
178
+ json = { value: json };
179
+ }
180
+ json["@type"] = this.typeUrl;
181
+ return json;
176
182
  }
177
- const message = messageType.fromBinary(this.value);
178
- let json = message.toJson(options);
179
- if (
180
- typeName.startsWith("google.protobuf.") ||
181
- json === null ||
182
- Array.isArray(json) ||
183
- typeof json !== "object"
184
- ) {
185
- json = { value: json };
183
+ fromJson(json, options) {
184
+ if (json === null || Array.isArray(json) || typeof json != "object") {
185
+ throw new Error(`cannot decode message google.protobuf.Any from JSON: expected object but got ${json === null ? "null" : Array.isArray(json) ? "array" : typeof json}`);
186
+ }
187
+ const typeUrl = json["@type"];
188
+ if (typeof typeUrl != "string" || typeUrl == "") {
189
+ throw new Error(`cannot decode message google.protobuf.Any from JSON: "@type" is empty`);
190
+ }
191
+ const typeName = this.typeUrlToName(typeUrl), messageType = options?.typeRegistry?.findMessage(typeName);
192
+ if (!messageType) {
193
+ throw new Error(`cannot decode message google.protobuf.Any from JSON: ${typeUrl} is not in the type registry`);
194
+ }
195
+ let message;
196
+ if (typeName.startsWith("google.protobuf.") && Object.prototype.hasOwnProperty.call(json, "value")) {
197
+ message = messageType.fromJson(json["value"], options);
198
+ }
199
+ else {
200
+ const copy = Object.assign({}, json);
201
+ delete copy["@type"];
202
+ message = messageType.fromJson(copy, options);
203
+ }
204
+ this.packFrom(message);
205
+ return this;
186
206
  }
187
- json["@type"] = this.typeUrl;
188
- return json;
189
- }
190
- fromJson(json, options) {
191
- if (json === null || Array.isArray(json) || typeof json != "object") {
192
- throw new Error(
193
- `cannot decode message google.protobuf.Any from JSON: expected object but got ${
194
- json === null ? "null" : Array.isArray(json) ? "array" : typeof json
195
- }`
196
- );
207
+ packFrom(message) {
208
+ this.value = message.toBinary();
209
+ this.typeUrl = this.typeNameToUrl(message.getType().typeName);
197
210
  }
198
- const typeUrl = json["@type"];
199
- if (typeof typeUrl != "string" || typeUrl == "") {
200
- throw new Error(
201
- `cannot decode message google.protobuf.Any from JSON: "@type" is empty`
202
- );
211
+ unpackTo(target) {
212
+ if (!this.is(target.getType())) {
213
+ return false;
214
+ }
215
+ target.fromBinary(this.value);
216
+ return true;
203
217
  }
204
- const typeName = this.typeUrlToName(typeUrl),
205
- messageType = options?.typeRegistry?.findMessage(typeName);
206
- if (!messageType) {
207
- throw new Error(
208
- `cannot decode message google.protobuf.Any from JSON: ${typeUrl} is not in the type registry`
209
- );
218
+ is(type) {
219
+ return this.typeUrl === this.typeNameToUrl(type.typeName);
210
220
  }
211
- let message;
212
- if (
213
- typeName.startsWith("google.protobuf.") &&
214
- Object.prototype.hasOwnProperty.call(json, "value")
215
- ) {
216
- message = messageType.fromJson(json["value"], options);
217
- } else {
218
- const copy = Object.assign({}, json);
219
- delete copy["@type"];
220
- message = messageType.fromJson(copy, options);
221
+ typeNameToUrl(name) {
222
+ return `type.googleapis.com/${name}`;
221
223
  }
222
- this.packFrom(message);
223
- return this;
224
- }
225
- packFrom(message) {
226
- this.value = message.toBinary();
227
- this.typeUrl = this.typeNameToUrl(message.getType().typeName);
228
- }
229
- unpackTo(target) {
230
- if (!this.is(target.getType())) {
231
- return false;
224
+ typeUrlToName(url) {
225
+ if (!url.length) {
226
+ throw new Error(`invalid type url: ${url}`);
227
+ }
228
+ const slash = url.lastIndexOf("/");
229
+ const name = slash > 0 ? url.substring(slash + 1) : url;
230
+ if (!name.length) {
231
+ throw new Error(`invalid type url: ${url}`);
232
+ }
233
+ return name;
232
234
  }
233
- target.fromBinary(this.value);
234
- return true;
235
- }
236
- is(type) {
237
- return this.typeUrl === this.typeNameToUrl(type.typeName);
238
- }
239
- typeNameToUrl(name) {
240
- return `type.googleapis.com/${name}`;
241
- }
242
- typeUrlToName(url) {
243
- if (!url.length) {
244
- throw new Error(`invalid type url: ${url}`);
235
+ static pack(message) {
236
+ const any = new Any();
237
+ any.packFrom(message);
238
+ return any;
245
239
  }
246
- const slash = url.lastIndexOf("/");
247
- const name = slash > 0 ? url.substring(slash + 1) : url;
248
- if (!name.length) {
249
- throw new Error(`invalid type url: ${url}`);
240
+ static fromBinary(bytes, options) {
241
+ return new Any().fromBinary(bytes, options);
242
+ }
243
+ static fromJson(jsonValue, options) {
244
+ return new Any().fromJson(jsonValue, options);
245
+ }
246
+ static fromJsonString(jsonString, options) {
247
+ return new Any().fromJsonString(jsonString, options);
248
+ }
249
+ static equals(a, b) {
250
+ return proto3.util.equals(Any, a, b);
250
251
  }
251
- return name;
252
- }
253
- static pack(message) {
254
- const any = new Any();
255
- any.packFrom(message);
256
- return any;
257
- }
258
- static fromBinary(bytes, options) {
259
- return new Any().fromBinary(bytes, options);
260
- }
261
- static fromJson(jsonValue, options) {
262
- return new Any().fromJson(jsonValue, options);
263
- }
264
- static fromJsonString(jsonString, options) {
265
- return new Any().fromJsonString(jsonString, options);
266
- }
267
- static equals(a, b) {
268
- return proto3.util.equals(Any, a, b);
269
- }
270
252
  }
271
253
  Any.runtime = proto3;
272
254
  Any.typeName = "google.protobuf.Any";
273
255
  Any.fields = proto3.util.newFieldList(() => [
274
- { no: 1, name: "type_url", kind: "scalar", T: 9 /* ScalarType.STRING */ },
275
- { no: 2, name: "value", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
256
+ { no: 1, name: "type_url", kind: "scalar", T: 9 /* ScalarType.STRING */ },
257
+ { no: 2, name: "value", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
276
258
  ]);