@bufbuild/protobuf 2.0.0-alpha.2 → 2.0.0-alpha.3
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 +1 -1
- package/dist/cjs/clone.d.ts +1 -1
- package/dist/cjs/clone.js +2 -2
- package/dist/cjs/codegenv1/boot.d.ts +1 -1
- package/dist/cjs/codegenv1/boot.js +3 -5
- package/dist/cjs/codegenv1/embed.d.ts +1 -1
- package/dist/cjs/codegenv1/embed.js +39 -34
- package/dist/cjs/codegenv1/enum.d.ts +1 -1
- package/dist/cjs/codegenv1/extension.d.ts +1 -1
- package/dist/cjs/codegenv1/file.d.ts +1 -1
- package/dist/cjs/codegenv1/file.js +5 -7
- package/dist/cjs/codegenv1/index.d.ts +1 -0
- package/dist/cjs/codegenv1/index.js +1 -0
- package/dist/cjs/codegenv1/message.d.ts +1 -1
- package/dist/cjs/codegenv1/scalar.d.ts +5 -0
- package/dist/cjs/codegenv1/scalar.js +39 -0
- package/dist/cjs/codegenv1/service.d.ts +3 -3
- package/dist/cjs/codegenv1/types.d.ts +7 -9
- package/dist/cjs/create.d.ts +1 -1
- package/dist/cjs/create.js +6 -5
- package/dist/cjs/{desc-types.d.ts → descriptors.d.ts} +39 -7
- package/dist/cjs/descriptors.js +53 -0
- package/dist/cjs/equals.d.ts +1 -1
- package/dist/cjs/extensions.d.ts +1 -1
- package/dist/cjs/extensions.js +4 -3
- package/dist/cjs/fields.d.ts +1 -1
- package/dist/cjs/from-binary.d.ts +2 -2
- package/dist/cjs/from-binary.js +22 -22
- package/dist/cjs/from-json.d.ts +4 -4
- package/dist/cjs/from-json.js +200 -181
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/is-message.d.ts +1 -1
- package/dist/cjs/proto-int64.d.ts +4 -1
- package/dist/cjs/proto-int64.js +16 -6
- package/dist/cjs/reflect/error.d.ts +1 -1
- package/dist/cjs/reflect/guard.d.ts +1 -1
- package/dist/cjs/reflect/index.d.ts +0 -1
- package/dist/cjs/reflect/index.js +0 -1
- package/dist/cjs/reflect/names.d.ts +1 -1
- package/dist/cjs/reflect/names.js +1 -1
- package/dist/cjs/reflect/nested-types.d.ts +1 -1
- package/dist/cjs/reflect/reflect-check.d.ts +10 -1
- package/dist/cjs/reflect/reflect-check.js +126 -9
- package/dist/cjs/reflect/reflect-types.d.ts +4 -4
- package/dist/cjs/reflect/reflect.d.ts +1 -1
- package/dist/cjs/reflect/reflect.js +28 -27
- package/dist/cjs/reflect/scalar.d.ts +3 -55
- package/dist/cjs/reflect/scalar.js +26 -220
- package/dist/cjs/reflect/unsafe.d.ts +1 -1
- package/dist/cjs/reflect/unsafe.js +1 -1
- package/dist/cjs/{reflect/registry.d.ts → registry.d.ts} +2 -2
- package/dist/cjs/{reflect/registry.js → registry.js} +54 -36
- package/dist/cjs/to-binary.d.ts +1 -1
- package/dist/cjs/to-binary.js +27 -27
- package/dist/cjs/to-json.d.ts +7 -6
- package/dist/cjs/to-json.js +57 -44
- package/dist/cjs/types.d.ts +1 -1
- package/dist/cjs/wire/base64-encoding.js +2 -2
- package/dist/cjs/wire/binary-encoding.d.ts +20 -0
- package/dist/cjs/wire/binary-encoding.js +54 -8
- package/dist/cjs/wire/size-delimited.d.ts +1 -1
- package/dist/cjs/wire/text-format.d.ts +1 -2
- package/dist/cjs/wire/text-format.js +21 -19
- package/dist/cjs/wkt/any.d.ts +3 -3
- package/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.d.ts +6 -0
- package/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.js +1 -1
- package/dist/cjs/wkt/wrappers.d.ts +1 -1
- package/dist/esm/clone.d.ts +1 -1
- package/dist/esm/clone.js +1 -1
- package/dist/esm/codegenv1/boot.d.ts +1 -1
- package/dist/esm/codegenv1/boot.js +3 -5
- package/dist/esm/codegenv1/embed.d.ts +1 -1
- package/dist/esm/codegenv1/embed.js +9 -4
- package/dist/esm/codegenv1/enum.d.ts +1 -1
- package/dist/esm/codegenv1/extension.d.ts +1 -1
- package/dist/esm/codegenv1/file.d.ts +1 -1
- package/dist/esm/codegenv1/file.js +4 -6
- package/dist/esm/codegenv1/index.d.ts +1 -0
- package/dist/esm/codegenv1/index.js +1 -0
- package/dist/esm/codegenv1/message.d.ts +1 -1
- package/dist/esm/codegenv1/scalar.d.ts +5 -0
- package/dist/esm/codegenv1/scalar.js +35 -0
- package/dist/esm/codegenv1/service.d.ts +3 -3
- package/dist/esm/codegenv1/types.d.ts +7 -9
- package/dist/esm/create.d.ts +1 -1
- package/dist/esm/create.js +4 -3
- package/dist/esm/{desc-types.d.ts → descriptors.d.ts} +39 -7
- package/dist/esm/descriptors.js +50 -0
- package/dist/esm/equals.d.ts +1 -1
- package/dist/esm/extensions.d.ts +1 -1
- package/dist/esm/extensions.js +4 -3
- package/dist/esm/fields.d.ts +1 -1
- package/dist/esm/from-binary.d.ts +2 -2
- package/dist/esm/from-binary.js +4 -4
- package/dist/esm/from-json.d.ts +4 -4
- package/dist/esm/from-json.js +193 -174
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/is-message.d.ts +1 -1
- package/dist/esm/proto-int64.d.ts +4 -1
- package/dist/esm/proto-int64.js +16 -6
- package/dist/esm/reflect/error.d.ts +1 -1
- package/dist/esm/reflect/guard.d.ts +1 -1
- package/dist/esm/reflect/index.d.ts +0 -1
- package/dist/esm/reflect/index.js +0 -1
- package/dist/esm/reflect/names.d.ts +1 -1
- package/dist/esm/reflect/names.js +1 -1
- package/dist/esm/reflect/nested-types.d.ts +1 -1
- package/dist/esm/reflect/reflect-check.d.ts +10 -1
- package/dist/esm/reflect/reflect-check.js +119 -2
- package/dist/esm/reflect/reflect-types.d.ts +4 -4
- package/dist/esm/reflect/reflect-types.js +1 -0
- package/dist/esm/reflect/reflect.d.ts +1 -1
- package/dist/esm/reflect/reflect.js +10 -9
- package/dist/esm/reflect/scalar.d.ts +3 -55
- package/dist/esm/reflect/scalar.js +14 -205
- package/dist/esm/reflect/unsafe.d.ts +1 -1
- package/dist/esm/reflect/unsafe.js +1 -1
- package/dist/esm/{reflect/registry.d.ts → registry.d.ts} +2 -2
- package/dist/esm/{reflect/registry.js → registry.js} +44 -26
- package/dist/esm/to-binary.d.ts +1 -1
- package/dist/esm/to-binary.js +1 -1
- package/dist/esm/to-json.d.ts +7 -6
- package/dist/esm/to-json.js +42 -29
- package/dist/esm/types.d.ts +1 -1
- package/dist/esm/wire/base64-encoding.js +2 -2
- package/dist/esm/wire/binary-encoding.d.ts +20 -0
- package/dist/esm/wire/binary-encoding.js +47 -1
- package/dist/esm/wire/size-delimited.d.ts +1 -1
- package/dist/esm/wire/text-format.d.ts +1 -2
- package/dist/esm/wire/text-format.js +5 -3
- package/dist/esm/wkt/any.d.ts +3 -3
- package/dist/esm/wkt/gen/google/protobuf/descriptor_pb.d.ts +6 -0
- package/dist/esm/wkt/gen/google/protobuf/descriptor_pb.js +1 -1
- package/dist/esm/wkt/wrappers.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/desc-types.js +0 -15
- package/dist/cjs/reflect/assert.d.ts +0 -16
- package/dist/cjs/reflect/assert.js +0 -59
- package/dist/esm/desc-types.js +0 -14
- package/dist/esm/reflect/assert.d.ts +0 -16
- package/dist/esm/reflect/assert.js +0 -52
package/dist/cjs/to-json.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type DescMessage } from "./descriptors.js";
|
|
2
2
|
import type { JsonValue } from "./json-value.js";
|
|
3
|
-
import type { Registry } from "./
|
|
3
|
+
import type { Registry } from "./registry.js";
|
|
4
4
|
import type { MessageShape } from "./types.js";
|
|
5
5
|
/**
|
|
6
6
|
* Options for serializing to JSON.
|
|
7
7
|
*/
|
|
8
8
|
export interface JsonWriteOptions {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* By default, fields with implicit presence are not serialized if they are
|
|
11
|
+
* unset. For example, an empty list field or a proto3 int32 field with 0 is
|
|
12
|
+
* not serialized. With this option enabled, such fields are included in the
|
|
13
|
+
* output.
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
|
+
alwaysEmitImplicit: boolean;
|
|
15
16
|
/**
|
|
16
17
|
* Emit enum values as integers instead of strings: The name of an enum
|
|
17
18
|
* value is used by default in JSON output. An option may be provided to
|
package/dist/cjs/to-json.js
CHANGED
|
@@ -14,21 +14,22 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.toJsonString = exports.toJson = void 0;
|
|
17
|
-
const
|
|
17
|
+
const descriptors_js_1 = require("./descriptors.js");
|
|
18
18
|
const names_js_1 = require("./reflect/names.js");
|
|
19
19
|
const reflect_js_1 = require("./reflect/reflect.js");
|
|
20
|
-
const scalar_js_1 = require("./reflect/scalar.js");
|
|
21
20
|
const index_js_1 = require("./wkt/index.js");
|
|
22
21
|
const wrappers_js_1 = require("./wkt/wrappers.js");
|
|
23
22
|
const index_js_2 = require("./wire/index.js");
|
|
24
23
|
const extensions_js_1 = require("./extensions.js");
|
|
24
|
+
const reflect_check_js_1 = require("./reflect/reflect-check.js");
|
|
25
|
+
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
25
26
|
// bootstrap-inject google.protobuf.FeatureSet.FieldPresence.LEGACY_REQUIRED: const $name: FeatureSet_FieldPresence.$localName = $number;
|
|
26
27
|
const LEGACY_REQUIRED = 3;
|
|
27
28
|
// bootstrap-inject google.protobuf.FeatureSet.FieldPresence.IMPLICIT: const $name: FeatureSet_FieldPresence.$localName = $number;
|
|
28
29
|
const IMPLICIT = 2;
|
|
29
30
|
// Default options for serializing to JSON.
|
|
30
31
|
const jsonWriteDefaults = {
|
|
31
|
-
|
|
32
|
+
alwaysEmitImplicit: false,
|
|
32
33
|
enumAsInteger: false,
|
|
33
34
|
useProtoFieldName: false,
|
|
34
35
|
};
|
|
@@ -61,9 +62,9 @@ function reflectToJson(msg, opts) {
|
|
|
61
62
|
for (const f of msg.sortedFields) {
|
|
62
63
|
if (!msg.isSet(f)) {
|
|
63
64
|
if (f.presence == LEGACY_REQUIRED) {
|
|
64
|
-
throw new Error(`cannot encode field ${msg.desc.typeName}.${f.name} to
|
|
65
|
+
throw new Error(`cannot encode field ${msg.desc.typeName}.${f.name} to JSON: required field not set`);
|
|
65
66
|
}
|
|
66
|
-
if (!opts.
|
|
67
|
+
if (!opts.alwaysEmitImplicit || f.presence !== IMPLICIT) {
|
|
67
68
|
// Fields with implicit presence omit zero values (e.g. empty string) by default
|
|
68
69
|
continue;
|
|
69
70
|
}
|
|
@@ -98,7 +99,7 @@ function reflectToJson(msg, opts) {
|
|
|
98
99
|
function fieldToJson(f, val, opts) {
|
|
99
100
|
switch (f.fieldKind) {
|
|
100
101
|
case "scalar":
|
|
101
|
-
return scalarToJson(f
|
|
102
|
+
return scalarToJson(f, val);
|
|
102
103
|
case "message":
|
|
103
104
|
return reflectToJson(val, opts);
|
|
104
105
|
case "enum":
|
|
@@ -115,7 +116,7 @@ function mapToJson(map, opts) {
|
|
|
115
116
|
switch (f.mapKind) {
|
|
116
117
|
case "scalar":
|
|
117
118
|
for (const [entryKey, entryValue] of map) {
|
|
118
|
-
jsonObj[entryKey.toString()] = scalarToJson(f
|
|
119
|
+
jsonObj[entryKey.toString()] = scalarToJson(f, entryValue); // JSON standard allows only (double quoted) string as property key
|
|
119
120
|
}
|
|
120
121
|
break;
|
|
121
122
|
case "message":
|
|
@@ -131,7 +132,7 @@ function mapToJson(map, opts) {
|
|
|
131
132
|
}
|
|
132
133
|
break;
|
|
133
134
|
}
|
|
134
|
-
return opts.
|
|
135
|
+
return opts.alwaysEmitImplicit || map.size > 0 ? jsonObj : undefined;
|
|
135
136
|
}
|
|
136
137
|
function listToJson(list, opts) {
|
|
137
138
|
const f = list.field();
|
|
@@ -139,7 +140,7 @@ function listToJson(list, opts) {
|
|
|
139
140
|
switch (f.listKind) {
|
|
140
141
|
case "scalar":
|
|
141
142
|
for (const item of list) {
|
|
142
|
-
jsonArr.push(scalarToJson(f
|
|
143
|
+
jsonArr.push(scalarToJson(f, item));
|
|
143
144
|
}
|
|
144
145
|
break;
|
|
145
146
|
case "enum":
|
|
@@ -153,11 +154,13 @@ function listToJson(list, opts) {
|
|
|
153
154
|
}
|
|
154
155
|
break;
|
|
155
156
|
}
|
|
156
|
-
return opts.
|
|
157
|
+
return opts.alwaysEmitImplicit || jsonArr.length > 0 ? jsonArr : undefined;
|
|
157
158
|
}
|
|
158
159
|
function enumToJson(desc, value, enumAsInteger) {
|
|
159
160
|
var _a;
|
|
160
|
-
|
|
161
|
+
if (typeof value != "number") {
|
|
162
|
+
throw new Error(`cannot encode ${desc} to JSON: expected number, got ${(0, reflect_check_js_1.formatVal)(value)}`);
|
|
163
|
+
}
|
|
161
164
|
if (desc.typeName == "google.protobuf.NullValue") {
|
|
162
165
|
return null;
|
|
163
166
|
}
|
|
@@ -167,23 +170,27 @@ function enumToJson(desc, value, enumAsInteger) {
|
|
|
167
170
|
const val = desc.values.find((v) => v.number == value);
|
|
168
171
|
return (_a = val === null || val === void 0 ? void 0 : val.name) !== null && _a !== void 0 ? _a : value; // if we don't know the enum value, just return the number
|
|
169
172
|
}
|
|
170
|
-
function scalarToJson(
|
|
171
|
-
|
|
173
|
+
function scalarToJson(field, value) {
|
|
174
|
+
var _a, _b, _c, _d, _e, _f;
|
|
175
|
+
switch (field.scalar) {
|
|
172
176
|
// int32, fixed32, uint32: JSON value will be a decimal number. Either numbers or strings are accepted.
|
|
173
|
-
case
|
|
174
|
-
case
|
|
175
|
-
case
|
|
176
|
-
case
|
|
177
|
-
case
|
|
178
|
-
|
|
177
|
+
case descriptors_js_1.ScalarType.INT32:
|
|
178
|
+
case descriptors_js_1.ScalarType.SFIXED32:
|
|
179
|
+
case descriptors_js_1.ScalarType.SINT32:
|
|
180
|
+
case descriptors_js_1.ScalarType.FIXED32:
|
|
181
|
+
case descriptors_js_1.ScalarType.UINT32:
|
|
182
|
+
if (typeof value != "number") {
|
|
183
|
+
throw new Error(`cannot encode ${field} to JSON: ${(_a = (0, reflect_check_js_1.checkField)(field, value)) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
184
|
+
}
|
|
179
185
|
return value;
|
|
180
186
|
// float, double: JSON value will be a number or one of the special string values "NaN", "Infinity", and "-Infinity".
|
|
181
187
|
// Either numbers or strings are accepted. Exponent notation is also accepted.
|
|
182
|
-
case
|
|
183
|
-
//
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
188
|
+
case descriptors_js_1.ScalarType.FLOAT:
|
|
189
|
+
case descriptors_js_1.ScalarType.DOUBLE: // eslint-disable-line no-fallthrough
|
|
190
|
+
if (typeof value != "number") {
|
|
191
|
+
throw new Error(`cannot encode ${field} to JSON: ${(_b = (0, reflect_check_js_1.checkField)(field, value)) === null || _b === void 0 ? void 0 : _b.message}`);
|
|
192
|
+
}
|
|
193
|
+
if (isNaN(value))
|
|
187
194
|
return "NaN";
|
|
188
195
|
if (value === Number.POSITIVE_INFINITY)
|
|
189
196
|
return "Infinity";
|
|
@@ -191,28 +198,34 @@ function scalarToJson(type, value) {
|
|
|
191
198
|
return "-Infinity";
|
|
192
199
|
return value;
|
|
193
200
|
// string:
|
|
194
|
-
case
|
|
195
|
-
|
|
201
|
+
case descriptors_js_1.ScalarType.STRING:
|
|
202
|
+
if (typeof value != "string") {
|
|
203
|
+
throw new Error(`cannot encode ${field} to JSON: ${(_c = (0, reflect_check_js_1.checkField)(field, value)) === null || _c === void 0 ? void 0 : _c.message}`);
|
|
204
|
+
}
|
|
196
205
|
return value;
|
|
197
206
|
// bool:
|
|
198
|
-
case
|
|
199
|
-
|
|
207
|
+
case descriptors_js_1.ScalarType.BOOL:
|
|
208
|
+
if (typeof value != "boolean") {
|
|
209
|
+
throw new Error(`cannot encode ${field} to JSON: ${(_d = (0, reflect_check_js_1.checkField)(field, value)) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
210
|
+
}
|
|
200
211
|
return value;
|
|
201
212
|
// JSON value will be a decimal string. Either numbers or strings are accepted.
|
|
202
|
-
case
|
|
203
|
-
case
|
|
204
|
-
case
|
|
205
|
-
case
|
|
206
|
-
case
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
213
|
+
case descriptors_js_1.ScalarType.UINT64:
|
|
214
|
+
case descriptors_js_1.ScalarType.FIXED64:
|
|
215
|
+
case descriptors_js_1.ScalarType.INT64:
|
|
216
|
+
case descriptors_js_1.ScalarType.SFIXED64:
|
|
217
|
+
case descriptors_js_1.ScalarType.SINT64:
|
|
218
|
+
if (typeof value != "bigint" && typeof value != "string") {
|
|
219
|
+
throw new Error(`cannot encode ${field} to JSON: ${(_e = (0, reflect_check_js_1.checkField)(field, value)) === null || _e === void 0 ? void 0 : _e.message}`);
|
|
220
|
+
}
|
|
210
221
|
return value.toString();
|
|
211
222
|
// bytes: JSON value will be the data encoded as a string using standard base64 encoding with paddings.
|
|
212
223
|
// Either standard or URL-safe base64 encoding with/without paddings are accepted.
|
|
213
|
-
case
|
|
214
|
-
|
|
215
|
-
|
|
224
|
+
case descriptors_js_1.ScalarType.BYTES:
|
|
225
|
+
if (value instanceof Uint8Array) {
|
|
226
|
+
return (0, index_js_2.base64Encode)(value);
|
|
227
|
+
}
|
|
228
|
+
throw new Error(`cannot encode ${field} to JSON: ${(_f = (0, reflect_check_js_1.checkField)(field, value)) === null || _f === void 0 ? void 0 : _f.message}`);
|
|
216
229
|
}
|
|
217
230
|
}
|
|
218
231
|
function jsonName(f, opts) {
|
|
@@ -241,7 +254,7 @@ function tryWktToJson(msg, opts) {
|
|
|
241
254
|
default:
|
|
242
255
|
if ((0, wrappers_js_1.isWrapperDesc)(msg.desc)) {
|
|
243
256
|
const valueField = msg.desc.fields[0];
|
|
244
|
-
return scalarToJson(valueField
|
|
257
|
+
return scalarToJson(valueField, msg.get(valueField));
|
|
245
258
|
}
|
|
246
259
|
return undefined;
|
|
247
260
|
}
|
|
@@ -275,7 +288,7 @@ function anyToJson(val, opts) {
|
|
|
275
288
|
function durationToJson(val) {
|
|
276
289
|
if (Number(val.seconds) > 315576000000 ||
|
|
277
290
|
Number(val.seconds) < -315576000000) {
|
|
278
|
-
throw new Error(`cannot encode ${val.$typeName} to JSON: value out of range`);
|
|
291
|
+
throw new Error(`cannot encode message ${val.$typeName} to JSON: value out of range`);
|
|
279
292
|
}
|
|
280
293
|
let text = val.seconds.toString();
|
|
281
294
|
if (val.nanos !== 0) {
|
|
@@ -299,7 +312,7 @@ function fieldMaskToJson(val) {
|
|
|
299
312
|
.map((p) => {
|
|
300
313
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
301
314
|
if (p.match(/_[0-9]?_/g) || p.match(/[A-Z]/g)) {
|
|
302
|
-
throw new Error(`cannot encode ${val.$typeName} to JSON: lowerCamelCase of path name "` +
|
|
315
|
+
throw new Error(`cannot encode message ${val.$typeName} to JSON: lowerCamelCase of path name "` +
|
|
303
316
|
p +
|
|
304
317
|
'" is irreversible');
|
|
305
318
|
}
|
|
@@ -342,10 +355,10 @@ function timestampToJson(val) {
|
|
|
342
355
|
const ms = Number(val.seconds) * 1000;
|
|
343
356
|
if (ms < Date.parse("0001-01-01T00:00:00Z") ||
|
|
344
357
|
ms > Date.parse("9999-12-31T23:59:59Z")) {
|
|
345
|
-
throw new Error(`cannot encode ${val.$typeName} to JSON: must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive`);
|
|
358
|
+
throw new Error(`cannot encode message ${val.$typeName} to JSON: must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive`);
|
|
346
359
|
}
|
|
347
360
|
if (val.nanos < 0) {
|
|
348
|
-
throw new Error(`cannot encode ${val.$typeName} to JSON: nanos must not be negative`);
|
|
361
|
+
throw new Error(`cannot encode message ${val.$typeName} to JSON: nanos must not be negative`);
|
|
349
362
|
}
|
|
350
363
|
let z = "Z";
|
|
351
364
|
if (val.nanos > 0) {
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GenDescEnum, GenDescExtension, GenDescMessage } from "./codegenv1/types.js";
|
|
2
|
-
import type { DescEnum, DescExtension, DescMessage } from "./
|
|
2
|
+
import type { DescEnum, DescExtension, DescMessage } from "./descriptors.js";
|
|
3
3
|
import type { OneofADT } from "./reflect/guard.js";
|
|
4
4
|
import type { WireType } from "./wire/index.js";
|
|
5
5
|
/**
|
|
@@ -52,7 +52,7 @@ function base64Decode(base64Str) {
|
|
|
52
52
|
case " ":
|
|
53
53
|
continue; // skip white-space, and padding
|
|
54
54
|
default:
|
|
55
|
-
throw Error("invalid base64 string
|
|
55
|
+
throw Error("invalid base64 string");
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
switch (groupPos) {
|
|
@@ -77,7 +77,7 @@ function base64Decode(base64Str) {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
if (groupPos == 1)
|
|
80
|
-
throw Error("invalid base64 string
|
|
80
|
+
throw Error("invalid base64 string");
|
|
81
81
|
return bytes.subarray(0, bytePos);
|
|
82
82
|
}
|
|
83
83
|
exports.base64Decode = base64Decode;
|
|
@@ -39,6 +39,26 @@ export declare enum WireType {
|
|
|
39
39
|
*/
|
|
40
40
|
Bit32 = 5
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Maximum value for a 32-bit floating point value (Protobuf FLOAT).
|
|
44
|
+
*/
|
|
45
|
+
export declare const FLOAT32_MAX = 3.4028234663852886e+38;
|
|
46
|
+
/**
|
|
47
|
+
* Minimum value for a 32-bit floating point value (Protobuf FLOAT).
|
|
48
|
+
*/
|
|
49
|
+
export declare const FLOAT32_MIN = -3.4028234663852886e+38;
|
|
50
|
+
/**
|
|
51
|
+
* Maximum value for an unsigned 32-bit integer (Protobuf UINT32, FIXED32).
|
|
52
|
+
*/
|
|
53
|
+
export declare const UINT32_MAX = 4294967295;
|
|
54
|
+
/**
|
|
55
|
+
* Maximum value for a signed 32-bit integer (Protobuf INT32, SFIXED32, SINT32).
|
|
56
|
+
*/
|
|
57
|
+
export declare const INT32_MAX = 2147483647;
|
|
58
|
+
/**
|
|
59
|
+
* Minimum value for a signed 32-bit integer (Protobuf INT32, SFIXED32, SINT32).
|
|
60
|
+
*/
|
|
61
|
+
export declare const INT32_MIN = -2147483648;
|
|
42
62
|
export declare class BinaryWriter {
|
|
43
63
|
private readonly encodeUtf8;
|
|
44
64
|
/**
|
|
@@ -13,9 +13,8 @@
|
|
|
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.BinaryReader = exports.BinaryWriter = exports.WireType = void 0;
|
|
16
|
+
exports.BinaryReader = exports.BinaryWriter = exports.INT32_MIN = exports.INT32_MAX = exports.UINT32_MAX = exports.FLOAT32_MIN = exports.FLOAT32_MAX = exports.WireType = void 0;
|
|
17
17
|
const varint_js_1 = require("./varint.js");
|
|
18
|
-
const assert_js_1 = require("../reflect/assert.js");
|
|
19
18
|
const proto_int64_js_1 = require("../proto-int64.js");
|
|
20
19
|
const text_encoding_js_1 = require("./text-encoding.js");
|
|
21
20
|
/* eslint-disable prefer-const,no-case-declarations,@typescript-eslint/restrict-plus-operands */
|
|
@@ -61,6 +60,26 @@ var WireType;
|
|
|
61
60
|
*/
|
|
62
61
|
WireType[WireType["Bit32"] = 5] = "Bit32";
|
|
63
62
|
})(WireType || (exports.WireType = WireType = {}));
|
|
63
|
+
/**
|
|
64
|
+
* Maximum value for a 32-bit floating point value (Protobuf FLOAT).
|
|
65
|
+
*/
|
|
66
|
+
exports.FLOAT32_MAX = 3.4028234663852886e38;
|
|
67
|
+
/**
|
|
68
|
+
* Minimum value for a 32-bit floating point value (Protobuf FLOAT).
|
|
69
|
+
*/
|
|
70
|
+
exports.FLOAT32_MIN = -3.4028234663852886e38;
|
|
71
|
+
/**
|
|
72
|
+
* Maximum value for an unsigned 32-bit integer (Protobuf UINT32, FIXED32).
|
|
73
|
+
*/
|
|
74
|
+
exports.UINT32_MAX = 0xffffffff;
|
|
75
|
+
/**
|
|
76
|
+
* Maximum value for a signed 32-bit integer (Protobuf INT32, SFIXED32, SINT32).
|
|
77
|
+
*/
|
|
78
|
+
exports.INT32_MAX = 0x7fffffff;
|
|
79
|
+
/**
|
|
80
|
+
* Minimum value for a signed 32-bit integer (Protobuf INT32, SFIXED32, SINT32).
|
|
81
|
+
*/
|
|
82
|
+
exports.INT32_MIN = -0x80000000;
|
|
64
83
|
class BinaryWriter {
|
|
65
84
|
constructor(encodeUtf8 = (0, text_encoding_js_1.getTextEncoding)().encodeUtf8) {
|
|
66
85
|
this.encodeUtf8 = encodeUtf8;
|
|
@@ -142,7 +161,7 @@ class BinaryWriter {
|
|
|
142
161
|
* Write a `uint32` value, an unsigned 32 bit varint.
|
|
143
162
|
*/
|
|
144
163
|
uint32(value) {
|
|
145
|
-
|
|
164
|
+
assertUInt32(value);
|
|
146
165
|
// write value as varint 32, inlined for speed
|
|
147
166
|
while (value > 0x7f) {
|
|
148
167
|
this.buf.push((value & 0x7f) | 0x80);
|
|
@@ -155,7 +174,7 @@ class BinaryWriter {
|
|
|
155
174
|
* Write a `int32` value, a signed 32 bit varint.
|
|
156
175
|
*/
|
|
157
176
|
int32(value) {
|
|
158
|
-
|
|
177
|
+
assertInt32(value);
|
|
159
178
|
(0, varint_js_1.varint32write)(value, this.buf);
|
|
160
179
|
return this;
|
|
161
180
|
}
|
|
@@ -185,7 +204,7 @@ class BinaryWriter {
|
|
|
185
204
|
* Write a `float` value, 32-bit floating point number.
|
|
186
205
|
*/
|
|
187
206
|
float(value) {
|
|
188
|
-
|
|
207
|
+
assertFloat32(value);
|
|
189
208
|
let chunk = new Uint8Array(4);
|
|
190
209
|
new DataView(chunk.buffer).setFloat32(0, value, true);
|
|
191
210
|
return this.raw(chunk);
|
|
@@ -202,7 +221,7 @@ class BinaryWriter {
|
|
|
202
221
|
* Write a `fixed32` value, an unsigned, fixed-length 32-bit integer.
|
|
203
222
|
*/
|
|
204
223
|
fixed32(value) {
|
|
205
|
-
|
|
224
|
+
assertUInt32(value);
|
|
206
225
|
let chunk = new Uint8Array(4);
|
|
207
226
|
new DataView(chunk.buffer).setUint32(0, value, true);
|
|
208
227
|
return this.raw(chunk);
|
|
@@ -211,7 +230,7 @@ class BinaryWriter {
|
|
|
211
230
|
* Write a `sfixed32` value, a signed, fixed-length 32-bit integer.
|
|
212
231
|
*/
|
|
213
232
|
sfixed32(value) {
|
|
214
|
-
|
|
233
|
+
assertInt32(value);
|
|
215
234
|
let chunk = new Uint8Array(4);
|
|
216
235
|
new DataView(chunk.buffer).setInt32(0, value, true);
|
|
217
236
|
return this.raw(chunk);
|
|
@@ -220,7 +239,7 @@ class BinaryWriter {
|
|
|
220
239
|
* Write a `sint32` value, a signed, zigzag-encoded 32-bit varint.
|
|
221
240
|
*/
|
|
222
241
|
sint32(value) {
|
|
223
|
-
|
|
242
|
+
assertInt32(value);
|
|
224
243
|
// zigzag encode
|
|
225
244
|
value = ((value << 1) ^ (value >> 31)) >>> 0;
|
|
226
245
|
(0, varint_js_1.varint32write)(value, this.buf);
|
|
@@ -442,3 +461,30 @@ class BinaryReader {
|
|
|
442
461
|
}
|
|
443
462
|
}
|
|
444
463
|
exports.BinaryReader = BinaryReader;
|
|
464
|
+
/**
|
|
465
|
+
* Assert a valid signed protobuf 32-bit integer.
|
|
466
|
+
*/
|
|
467
|
+
function assertInt32(arg) {
|
|
468
|
+
if (typeof arg !== "number")
|
|
469
|
+
throw new Error("invalid int32: " + typeof arg);
|
|
470
|
+
if (!Number.isInteger(arg) || arg > exports.INT32_MAX || arg < exports.INT32_MIN)
|
|
471
|
+
throw new Error("invalid int32: " + arg);
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Assert a valid unsigned protobuf 32-bit integer.
|
|
475
|
+
*/
|
|
476
|
+
function assertUInt32(arg) {
|
|
477
|
+
if (typeof arg !== "number")
|
|
478
|
+
throw new Error("invalid uint32: " + typeof arg);
|
|
479
|
+
if (!Number.isInteger(arg) || arg > exports.UINT32_MAX || arg < 0)
|
|
480
|
+
throw new Error("invalid uint32: " + arg);
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Assert a valid protobuf float value.
|
|
484
|
+
*/
|
|
485
|
+
function assertFloat32(arg) {
|
|
486
|
+
if (typeof arg !== "number")
|
|
487
|
+
throw new Error("invalid float32: " + typeof arg);
|
|
488
|
+
if (Number.isFinite(arg) && (arg > exports.FLOAT32_MAX || arg < exports.FLOAT32_MIN))
|
|
489
|
+
throw new Error("invalid float32: " + arg);
|
|
490
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DescMessage } from "../
|
|
1
|
+
import type { DescMessage } from "../descriptors.js";
|
|
2
2
|
import type { BinaryWriteOptions } from "../to-binary.js";
|
|
3
3
|
import type { MessageShape } from "../types.js";
|
|
4
4
|
import type { BinaryReadOptions } from "../from-binary.js";
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.parseTextFormatScalarValue = exports.parseTextFormatEnumValue = void 0;
|
|
17
|
-
const
|
|
17
|
+
const descriptors_js_1 = require("../descriptors.js");
|
|
18
18
|
const proto_int64_js_1 = require("../proto-int64.js");
|
|
19
|
-
|
|
19
|
+
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
20
20
|
/**
|
|
21
21
|
* Parse an enum value from the Protobuf text format.
|
|
22
22
|
*
|
|
@@ -24,7 +24,9 @@ const scalar_js_1 = require("../reflect/scalar.js");
|
|
|
24
24
|
*/
|
|
25
25
|
function parseTextFormatEnumValue(descEnum, value) {
|
|
26
26
|
const enumValue = descEnum.values.find((v) => v.name === value);
|
|
27
|
-
|
|
27
|
+
if (!enumValue) {
|
|
28
|
+
throw new Error(`cannot parse ${descEnum} default value: ${value}`);
|
|
29
|
+
}
|
|
28
30
|
return enumValue.number;
|
|
29
31
|
}
|
|
30
32
|
exports.parseTextFormatEnumValue = parseTextFormatEnumValue;
|
|
@@ -35,24 +37,24 @@ exports.parseTextFormatEnumValue = parseTextFormatEnumValue;
|
|
|
35
37
|
*/
|
|
36
38
|
function parseTextFormatScalarValue(type, value) {
|
|
37
39
|
switch (type) {
|
|
38
|
-
case
|
|
40
|
+
case descriptors_js_1.ScalarType.STRING:
|
|
39
41
|
return value;
|
|
40
|
-
case
|
|
42
|
+
case descriptors_js_1.ScalarType.BYTES: {
|
|
41
43
|
const u = unescapeBytesDefaultValue(value);
|
|
42
44
|
if (u === false) {
|
|
43
|
-
throw new Error(`cannot parse ${
|
|
45
|
+
throw new Error(`cannot parse ${descriptors_js_1.ScalarType[type]} default value: ${value}`);
|
|
44
46
|
}
|
|
45
47
|
return u;
|
|
46
48
|
}
|
|
47
|
-
case
|
|
48
|
-
case
|
|
49
|
-
case
|
|
49
|
+
case descriptors_js_1.ScalarType.INT64:
|
|
50
|
+
case descriptors_js_1.ScalarType.SFIXED64:
|
|
51
|
+
case descriptors_js_1.ScalarType.SINT64:
|
|
50
52
|
return proto_int64_js_1.protoInt64.parse(value);
|
|
51
|
-
case
|
|
52
|
-
case
|
|
53
|
+
case descriptors_js_1.ScalarType.UINT64:
|
|
54
|
+
case descriptors_js_1.ScalarType.FIXED64:
|
|
53
55
|
return proto_int64_js_1.protoInt64.uParse(value);
|
|
54
|
-
case
|
|
55
|
-
case
|
|
56
|
+
case descriptors_js_1.ScalarType.DOUBLE:
|
|
57
|
+
case descriptors_js_1.ScalarType.FLOAT:
|
|
56
58
|
switch (value) {
|
|
57
59
|
case "inf":
|
|
58
60
|
return Number.POSITIVE_INFINITY;
|
|
@@ -63,13 +65,13 @@ function parseTextFormatScalarValue(type, value) {
|
|
|
63
65
|
default:
|
|
64
66
|
return parseFloat(value);
|
|
65
67
|
}
|
|
66
|
-
case
|
|
68
|
+
case descriptors_js_1.ScalarType.BOOL:
|
|
67
69
|
return value === "true";
|
|
68
|
-
case
|
|
69
|
-
case
|
|
70
|
-
case
|
|
71
|
-
case
|
|
72
|
-
case
|
|
70
|
+
case descriptors_js_1.ScalarType.INT32:
|
|
71
|
+
case descriptors_js_1.ScalarType.UINT32:
|
|
72
|
+
case descriptors_js_1.ScalarType.SINT32:
|
|
73
|
+
case descriptors_js_1.ScalarType.FIXED32:
|
|
74
|
+
case descriptors_js_1.ScalarType.SFIXED32:
|
|
73
75
|
return parseInt(value, 10);
|
|
74
76
|
}
|
|
75
77
|
}
|
package/dist/cjs/wkt/any.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Message, MessageShape } from "../types.js";
|
|
2
2
|
import type { Any } from "./gen/google/protobuf/any_pb.js";
|
|
3
|
-
import type { DescMessage } from "../
|
|
4
|
-
import type { Registry } from "../
|
|
3
|
+
import type { DescMessage } from "../descriptors.js";
|
|
4
|
+
import type { Registry } from "../registry.js";
|
|
5
5
|
/**
|
|
6
6
|
* Creates a `google.protobuf.Any` from a message.
|
|
7
7
|
*/
|
|
@@ -35,4 +35,4 @@ export declare function anyUnpack<Desc extends DescMessage>(any: Any, messageDes
|
|
|
35
35
|
/**
|
|
36
36
|
* Same as anyUnpack but unpacks into the target message.
|
|
37
37
|
*/
|
|
38
|
-
export declare function anyUnpackTo<Desc extends DescMessage>(any: Any, messageDesc: Desc, message: MessageShape<Desc>):
|
|
38
|
+
export declare function anyUnpackTo<Desc extends DescMessage>(any: Any, messageDesc: Desc, message: MessageShape<Desc>): void;
|
|
@@ -1482,6 +1482,12 @@ export type EnumValueOptions = Message<"google.protobuf.EnumValueOptions"> & {
|
|
|
1482
1482
|
* @generated from field: optional bool debug_redact = 3 [default = false];
|
|
1483
1483
|
*/
|
|
1484
1484
|
debugRedact: boolean;
|
|
1485
|
+
/**
|
|
1486
|
+
* Information about the support window of a feature value.
|
|
1487
|
+
*
|
|
1488
|
+
* @generated from field: optional google.protobuf.FieldOptions.FeatureSupport feature_support = 4;
|
|
1489
|
+
*/
|
|
1490
|
+
featureSupport?: FieldOptions_FeatureSupport;
|
|
1485
1491
|
/**
|
|
1486
1492
|
* The parser stores options it doesn't recognize here. See above.
|
|
1487
1493
|
*
|