@bufbuild/protobuf 2.2.5 → 2.3.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/dist/cjs/clone.js +4 -6
- package/dist/cjs/codegenv1/boot.js +1 -1
- package/dist/cjs/codegenv1/embed.js +0 -1
- package/dist/cjs/codegenv1/file.js +1 -1
- package/dist/cjs/codegenv1/symbols.js +1 -1
- package/dist/cjs/create.js +0 -1
- package/dist/cjs/equals.js +2 -1
- package/dist/cjs/extensions.js +1 -1
- package/dist/cjs/from-binary.js +5 -3
- package/dist/cjs/from-json.js +8 -10
- package/dist/cjs/proto-int64.js +4 -1
- package/dist/cjs/reflect/guard.js +2 -1
- package/dist/cjs/reflect/index.d.ts +1 -0
- package/dist/cjs/reflect/index.js +1 -0
- package/dist/cjs/reflect/names.d.ts +8 -0
- package/dist/cjs/reflect/names.js +28 -0
- package/dist/cjs/reflect/path.d.ts +107 -0
- package/dist/cjs/reflect/path.js +376 -0
- package/dist/cjs/reflect/reflect-check.js +3 -3
- package/dist/cjs/reflect/reflect-types.d.ts +1 -1
- package/dist/cjs/reflect/reflect.js +9 -7
- package/dist/cjs/reflect/scalar.js +4 -5
- package/dist/cjs/reflect/unsafe.d.ts +3 -6
- package/dist/cjs/reflect/unsafe.js +11 -10
- package/dist/cjs/registry.js +17 -25
- package/dist/cjs/to-binary.js +1 -1
- package/dist/cjs/to-json.d.ts +6 -0
- package/dist/cjs/to-json.js +16 -18
- package/dist/cjs/wire/base64-encoding.js +4 -3
- package/dist/cjs/wire/binary-encoding.js +7 -6
- package/dist/cjs/wire/text-encoding.js +1 -1
- package/dist/cjs/wire/text-format.js +3 -4
- package/dist/cjs/wire/varint.js +0 -1
- package/dist/esm/clone.js +4 -6
- package/dist/esm/codegenv1/boot.js +1 -1
- package/dist/esm/codegenv1/embed.js +0 -1
- package/dist/esm/codegenv1/file.js +1 -1
- package/dist/esm/codegenv1/symbols.js +1 -1
- package/dist/esm/create.js +0 -2
- package/dist/esm/equals.js +2 -1
- package/dist/esm/extensions.js +1 -1
- package/dist/esm/from-binary.js +5 -3
- package/dist/esm/from-json.js +8 -10
- package/dist/esm/proto-int64.js +4 -1
- package/dist/esm/reflect/guard.js +2 -1
- package/dist/esm/reflect/index.d.ts +1 -0
- package/dist/esm/reflect/index.js +1 -0
- package/dist/esm/reflect/names.d.ts +8 -0
- package/dist/esm/reflect/names.js +27 -0
- package/dist/esm/reflect/path.d.ts +107 -0
- package/dist/esm/reflect/path.js +369 -0
- package/dist/esm/reflect/reflect-check.js +3 -3
- package/dist/esm/reflect/reflect-types.d.ts +1 -1
- package/dist/esm/reflect/reflect-types.js +0 -1
- package/dist/esm/reflect/reflect.js +9 -7
- package/dist/esm/reflect/scalar.js +4 -5
- package/dist/esm/reflect/unsafe.d.ts +3 -6
- package/dist/esm/reflect/unsafe.js +11 -10
- package/dist/esm/registry.js +17 -25
- package/dist/esm/to-binary.js +1 -1
- package/dist/esm/to-json.d.ts +6 -0
- package/dist/esm/to-json.js +16 -18
- package/dist/esm/wire/base64-encoding.js +4 -3
- package/dist/esm/wire/binary-encoding.js +7 -6
- package/dist/esm/wire/text-encoding.js +1 -1
- package/dist/esm/wire/text-format.js +3 -4
- package/dist/esm/wire/varint.js +0 -1
- package/package.json +9 -24
|
@@ -20,8 +20,9 @@ export const unsafeLocal = Symbol.for("reflect unsafe local");
|
|
|
20
20
|
*
|
|
21
21
|
* @private
|
|
22
22
|
*/
|
|
23
|
-
export function unsafeOneofCase(
|
|
24
|
-
|
|
23
|
+
export function unsafeOneofCase(
|
|
24
|
+
// biome-ignore lint/suspicious/noExplicitAny: `any` is the best choice for dynamic access
|
|
25
|
+
target, oneof) {
|
|
25
26
|
const c = target[oneof.localName].case;
|
|
26
27
|
if (c === undefined) {
|
|
27
28
|
return c;
|
|
@@ -33,11 +34,12 @@ oneof) {
|
|
|
33
34
|
*
|
|
34
35
|
* @private
|
|
35
36
|
*/
|
|
36
|
-
export function unsafeIsSet(
|
|
37
|
-
|
|
37
|
+
export function unsafeIsSet(
|
|
38
|
+
// biome-ignore lint/suspicious/noExplicitAny: `any` is the best choice for dynamic access
|
|
39
|
+
target, field) {
|
|
38
40
|
const name = field.localName;
|
|
39
41
|
if (field.oneof) {
|
|
40
|
-
return target[field.oneof.localName].case === name;
|
|
42
|
+
return target[field.oneof.localName].case === name;
|
|
41
43
|
}
|
|
42
44
|
if (field.presence != IMPLICIT) {
|
|
43
45
|
// Fields with explicit presence have properties on the prototype chain
|
|
@@ -45,12 +47,11 @@ field) {
|
|
|
45
47
|
return (target[name] !== undefined &&
|
|
46
48
|
Object.prototype.hasOwnProperty.call(target, name));
|
|
47
49
|
}
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
49
50
|
switch (field.fieldKind) {
|
|
50
51
|
case "list":
|
|
51
52
|
return target[name].length > 0;
|
|
52
53
|
case "map":
|
|
53
|
-
return Object.keys(target[name]).length > 0;
|
|
54
|
+
return Object.keys(target[name]).length > 0;
|
|
54
55
|
case "scalar":
|
|
55
56
|
return !isScalarZeroValue(field.scalar, target[name]);
|
|
56
57
|
case "enum":
|
|
@@ -104,8 +105,9 @@ export function unsafeSet(target, field, value) {
|
|
|
104
105
|
*
|
|
105
106
|
* @private
|
|
106
107
|
*/
|
|
107
|
-
export function unsafeClear(
|
|
108
|
-
|
|
108
|
+
export function unsafeClear(
|
|
109
|
+
// biome-ignore lint/suspicious/noExplicitAny: `any` is the best choice for dynamic access
|
|
110
|
+
target, field) {
|
|
109
111
|
const name = field.localName;
|
|
110
112
|
if (field.oneof) {
|
|
111
113
|
const oneofLocalName = field.oneof.localName;
|
|
@@ -120,7 +122,6 @@ field) {
|
|
|
120
122
|
delete target[name];
|
|
121
123
|
}
|
|
122
124
|
else {
|
|
123
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
124
125
|
switch (field.fieldKind) {
|
|
125
126
|
case "map":
|
|
126
127
|
target[name] = {};
|
package/dist/esm/registry.js
CHANGED
|
@@ -59,7 +59,6 @@ export function createFileRegistry(...args) {
|
|
|
59
59
|
const input = args[0];
|
|
60
60
|
const resolve = args[1];
|
|
61
61
|
const seen = new Set();
|
|
62
|
-
// eslint-disable-next-line no-inner-declarations
|
|
63
62
|
function recurseDeps(file) {
|
|
64
63
|
const deps = [];
|
|
65
64
|
for (const protoFileName of file.dependency) {
|
|
@@ -115,13 +114,11 @@ function createBaseRegistry() {
|
|
|
115
114
|
},
|
|
116
115
|
addFile(file, skipTypes, withDeps) {
|
|
117
116
|
files.set(file.proto.name, file);
|
|
118
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
119
117
|
if (!skipTypes) {
|
|
120
118
|
for (const type of nestedTypes(file)) {
|
|
121
119
|
this.add(type);
|
|
122
120
|
}
|
|
123
121
|
}
|
|
124
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
125
122
|
if (withDeps) {
|
|
126
123
|
for (const f of file.dependencies) {
|
|
127
124
|
this.addFile(f, skipTypes, withDeps);
|
|
@@ -132,7 +129,9 @@ function createBaseRegistry() {
|
|
|
132
129
|
if (desc.kind == "extension") {
|
|
133
130
|
let numberToExt = extendees.get(desc.extendee.typeName);
|
|
134
131
|
if (!numberToExt) {
|
|
135
|
-
extendees.set(desc.extendee.typeName,
|
|
132
|
+
extendees.set(desc.extendee.typeName,
|
|
133
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: no
|
|
134
|
+
(numberToExt = new Map()));
|
|
136
135
|
}
|
|
137
136
|
numberToExt.set(desc.number, desc);
|
|
138
137
|
}
|
|
@@ -222,7 +221,7 @@ const PACKED = 1;
|
|
|
222
221
|
const DELIMITED = 2;
|
|
223
222
|
// bootstrap-inject google.protobuf.FeatureSet.EnumType.OPEN: const $name: FeatureSet_EnumType.$localName = $number;
|
|
224
223
|
const OPEN = 1;
|
|
225
|
-
//
|
|
224
|
+
// biome-ignore format: want this to read well
|
|
226
225
|
// bootstrap-inject defaults: EDITION_PROTO2 to EDITION_2023: export const minimumEdition: SupportedEdition = $minimumEdition, maximumEdition: SupportedEdition = $maximumEdition;
|
|
227
226
|
// generated from protoc v30.0
|
|
228
227
|
export const minimumEdition = 998, maximumEdition = 1000;
|
|
@@ -371,7 +370,7 @@ function addFields(message, reg, mapEntries) {
|
|
|
371
370
|
* parent type, if any.
|
|
372
371
|
*/
|
|
373
372
|
function addEnum(proto, file, parent, reg) {
|
|
374
|
-
var _a, _b, _c;
|
|
373
|
+
var _a, _b, _c, _d, _e;
|
|
375
374
|
const sharedPrefix = findEnumSharedPrefix(proto.name, proto.value);
|
|
376
375
|
const desc = {
|
|
377
376
|
kind: "enum",
|
|
@@ -391,25 +390,26 @@ function addEnum(proto, file, parent, reg) {
|
|
|
391
390
|
};
|
|
392
391
|
desc.open = isEnumOpen(desc);
|
|
393
392
|
reg.add(desc);
|
|
394
|
-
proto.value
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
393
|
+
for (const p of proto.value) {
|
|
394
|
+
const name = p.name;
|
|
395
|
+
desc.values.push(
|
|
396
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: no
|
|
397
|
+
(desc.value[p.number] = {
|
|
398
398
|
kind: "enum_value",
|
|
399
|
-
proto,
|
|
400
|
-
deprecated: (
|
|
399
|
+
proto: p,
|
|
400
|
+
deprecated: (_d = (_c = proto.options) === null || _c === void 0 ? void 0 : _c.deprecated) !== null && _d !== void 0 ? _d : false,
|
|
401
401
|
parent: desc,
|
|
402
402
|
name,
|
|
403
403
|
localName: safeObjectProperty(sharedPrefix == undefined
|
|
404
404
|
? name
|
|
405
405
|
: name.substring(sharedPrefix.length)),
|
|
406
|
-
number:
|
|
406
|
+
number: p.number,
|
|
407
407
|
toString() {
|
|
408
408
|
return `enum value ${desc.typeName}.${name}`;
|
|
409
409
|
},
|
|
410
410
|
}));
|
|
411
|
-
}
|
|
412
|
-
((
|
|
411
|
+
}
|
|
412
|
+
((_e = parent === null || parent === void 0 ? void 0 : parent.nestedEnums) !== null && _e !== void 0 ? _e : file.enums).push(desc);
|
|
413
413
|
}
|
|
414
414
|
/**
|
|
415
415
|
* Create a descriptor for a message, including nested types, and add it to our
|
|
@@ -611,14 +611,12 @@ function newField(proto, parentOrFile, reg, oneof, mapEntries) {
|
|
|
611
611
|
case TYPE_GROUP:
|
|
612
612
|
field.listKind = "message";
|
|
613
613
|
field.message = reg.getMessage(trimLeadingDot(proto.typeName));
|
|
614
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
615
614
|
assert(field.message);
|
|
616
615
|
field.delimitedEncoding = isDelimitedEncoding(proto, parentOrFile);
|
|
617
616
|
break;
|
|
618
617
|
case TYPE_ENUM:
|
|
619
618
|
field.listKind = "enum";
|
|
620
619
|
field.enum = reg.getEnum(trimLeadingDot(proto.typeName));
|
|
621
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
622
620
|
assert(field.enum);
|
|
623
621
|
break;
|
|
624
622
|
default:
|
|
@@ -636,9 +634,7 @@ function newField(proto, parentOrFile, reg, oneof, mapEntries) {
|
|
|
636
634
|
case TYPE_GROUP:
|
|
637
635
|
field.fieldKind = "message";
|
|
638
636
|
field.message = reg.getMessage(trimLeadingDot(proto.typeName));
|
|
639
|
-
assert(
|
|
640
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
641
|
-
field.message, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
|
|
637
|
+
assert(field.message, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
|
|
642
638
|
field.delimitedEncoding = isDelimitedEncoding(proto, parentOrFile);
|
|
643
639
|
field.getDefaultValue = () => undefined;
|
|
644
640
|
break;
|
|
@@ -775,9 +771,7 @@ function findOneof(proto, allOneofs) {
|
|
|
775
771
|
return undefined;
|
|
776
772
|
}
|
|
777
773
|
const oneof = allOneofs[proto.oneofIndex];
|
|
778
|
-
assert(
|
|
779
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
780
|
-
oneof, `invalid FieldDescriptorProto: oneof #${proto.oneofIndex} for field #${proto.number} not found`);
|
|
774
|
+
assert(oneof, `invalid FieldDescriptorProto: oneof #${proto.oneofIndex} for field #${proto.number} not found`);
|
|
781
775
|
return oneof;
|
|
782
776
|
}
|
|
783
777
|
/**
|
|
@@ -814,7 +808,6 @@ function isPackedField(proto, parent) {
|
|
|
814
808
|
if (proto.label != LABEL_REPEATED) {
|
|
815
809
|
return false;
|
|
816
810
|
}
|
|
817
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
818
811
|
switch (proto.type) {
|
|
819
812
|
case TYPE_STRING:
|
|
820
813
|
case TYPE_BYTES:
|
|
@@ -901,7 +894,6 @@ function resolveFeature(name, ref) {
|
|
|
901
894
|
* Assert that condition is truthy or throw error (with message)
|
|
902
895
|
*/
|
|
903
896
|
function assert(condition, msg) {
|
|
904
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we want the implicit conversion to boolean
|
|
905
897
|
if (!condition) {
|
|
906
898
|
throw new Error(msg);
|
|
907
899
|
}
|
package/dist/esm/to-binary.js
CHANGED
|
@@ -31,7 +31,7 @@ function writeFields(writer, opts, msg) {
|
|
|
31
31
|
for (const f of msg.sortedFields) {
|
|
32
32
|
if (!msg.isSet(f)) {
|
|
33
33
|
if (f.presence == LEGACY_REQUIRED) {
|
|
34
|
-
throw new Error(`cannot encode
|
|
34
|
+
throw new Error(`cannot encode ${f} to binary: required field not set`);
|
|
35
35
|
}
|
|
36
36
|
continue;
|
|
37
37
|
}
|
package/dist/esm/to-json.d.ts
CHANGED
|
@@ -38,6 +38,12 @@ export interface JsonWriteOptions {
|
|
|
38
38
|
* Options for serializing to JSON.
|
|
39
39
|
*/
|
|
40
40
|
export interface JsonWriteStringOptions extends JsonWriteOptions {
|
|
41
|
+
/**
|
|
42
|
+
* Format JSON with indentation. Indicates the number of space characters to
|
|
43
|
+
* be used as indentation.
|
|
44
|
+
*
|
|
45
|
+
* This option is passed to JSON.stringify as `space`.
|
|
46
|
+
*/
|
|
41
47
|
prettySpaces: number;
|
|
42
48
|
}
|
|
43
49
|
/**
|
package/dist/esm/to-json.js
CHANGED
|
@@ -19,7 +19,6 @@ import { isWrapperDesc } from "./wkt/wrappers.js";
|
|
|
19
19
|
import { base64Encode } from "./wire/index.js";
|
|
20
20
|
import { createExtensionContainer, getExtension } from "./extensions.js";
|
|
21
21
|
import { checkField, formatVal } from "./reflect/reflect-check.js";
|
|
22
|
-
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
23
22
|
// bootstrap-inject google.protobuf.FeatureSet.FieldPresence.LEGACY_REQUIRED: const $name: FeatureSet_FieldPresence.$localName = $number;
|
|
24
23
|
const LEGACY_REQUIRED = 3;
|
|
25
24
|
// bootstrap-inject google.protobuf.FeatureSet.FieldPresence.IMPLICIT: const $name: FeatureSet_FieldPresence.$localName = $number;
|
|
@@ -58,7 +57,7 @@ export function enumToJson(descEnum, value) {
|
|
|
58
57
|
}
|
|
59
58
|
const name = (_a = descEnum.value[value]) === null || _a === void 0 ? void 0 : _a.name;
|
|
60
59
|
if (name === undefined) {
|
|
61
|
-
throw new Error(`${
|
|
60
|
+
throw new Error(`${value} is not a value in ${descEnum}`);
|
|
62
61
|
}
|
|
63
62
|
return name;
|
|
64
63
|
}
|
|
@@ -71,7 +70,7 @@ function reflectToJson(msg, opts) {
|
|
|
71
70
|
for (const f of msg.sortedFields) {
|
|
72
71
|
if (!msg.isSet(f)) {
|
|
73
72
|
if (f.presence == LEGACY_REQUIRED) {
|
|
74
|
-
throw new Error(`cannot encode
|
|
73
|
+
throw new Error(`cannot encode ${f} to JSON: required field not set`);
|
|
75
74
|
}
|
|
76
75
|
if (!opts.alwaysEmitImplicit || f.presence !== IMPLICIT) {
|
|
77
76
|
// Fields with implicit presence omit zero values (e.g. empty string) by default
|
|
@@ -85,21 +84,21 @@ function reflectToJson(msg, opts) {
|
|
|
85
84
|
}
|
|
86
85
|
if (opts.registry) {
|
|
87
86
|
const tagSeen = new Set();
|
|
88
|
-
for (const
|
|
87
|
+
for (const { no } of (_a = msg.getUnknown()) !== null && _a !== void 0 ? _a : []) {
|
|
89
88
|
// Same tag can appear multiple times, so we
|
|
90
89
|
// keep track and skip identical ones.
|
|
91
|
-
if (tagSeen.has(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
90
|
+
if (!tagSeen.has(no)) {
|
|
91
|
+
tagSeen.add(no);
|
|
92
|
+
const extension = opts.registry.getExtensionFor(msg.desc, no);
|
|
93
|
+
if (!extension) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const value = getExtension(msg.message, extension);
|
|
97
|
+
const [container, field] = createExtensionContainer(extension, value);
|
|
98
|
+
const jsonValue = fieldToJson(field, container.get(field), opts);
|
|
99
|
+
if (jsonValue !== undefined) {
|
|
100
|
+
json[extension.jsonName] = jsonValue;
|
|
101
|
+
}
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
104
|
}
|
|
@@ -197,7 +196,7 @@ function scalarToJson(field, value) {
|
|
|
197
196
|
if (typeof value != "number") {
|
|
198
197
|
throw new Error(`cannot encode ${field} to JSON: ${(_b = checkField(field, value)) === null || _b === void 0 ? void 0 : _b.message}`);
|
|
199
198
|
}
|
|
200
|
-
if (isNaN(value))
|
|
199
|
+
if (Number.isNaN(value))
|
|
201
200
|
return "NaN";
|
|
202
201
|
if (value === Number.POSITIVE_INFINITY)
|
|
203
202
|
return "Infinity";
|
|
@@ -317,7 +316,6 @@ function durationToJson(val) {
|
|
|
317
316
|
function fieldMaskToJson(val) {
|
|
318
317
|
return val.paths
|
|
319
318
|
.map((p) => {
|
|
320
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
321
319
|
if (p.match(/_[0-9]?_/g) || p.match(/[A-Z]/g)) {
|
|
322
320
|
throw new Error(`cannot encode message ${val.$typeName} to JSON: lowerCamelCase of path name "` +
|
|
323
321
|
p +
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unnecessary-condition, prefer-const */
|
|
15
14
|
/**
|
|
16
15
|
* Decodes a base64 string to a byte array.
|
|
17
16
|
*
|
|
@@ -42,7 +41,6 @@ export function base64Decode(base64Str) {
|
|
|
42
41
|
// @ts-expect-error TS7029: Fallthrough case in switch
|
|
43
42
|
case "=":
|
|
44
43
|
groupPos = 0; // reset state when padding found
|
|
45
|
-
// eslint-disable-next-line no-fallthrough
|
|
46
44
|
case "\n":
|
|
47
45
|
case "\r":
|
|
48
46
|
case "\t":
|
|
@@ -135,7 +133,10 @@ function getEncodeTable(encoding) {
|
|
|
135
133
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
|
|
136
134
|
encodeTableUrl = encodeTableStd.slice(0, -2).concat("-", "_");
|
|
137
135
|
}
|
|
138
|
-
return encoding == "url"
|
|
136
|
+
return encoding == "url"
|
|
137
|
+
? // biome-ignore lint/style/noNonNullAssertion: TS fails to narrow down
|
|
138
|
+
encodeTableUrl
|
|
139
|
+
: encodeTableStd;
|
|
139
140
|
}
|
|
140
141
|
function getDecodeTable() {
|
|
141
142
|
if (!decodeTable) {
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
import { varint32read, varint32write, varint64read, varint64write, } from "./varint.js";
|
|
15
15
|
import { protoInt64 } from "../proto-int64.js";
|
|
16
16
|
import { getTextEncoding } from "./text-encoding.js";
|
|
17
|
-
/* eslint-disable prefer-const,no-case-declarations,@typescript-eslint/restrict-plus-operands */
|
|
18
17
|
/**
|
|
19
18
|
* Protobuf binary format wire types.
|
|
20
19
|
*
|
|
@@ -275,7 +274,7 @@ export class BinaryWriter {
|
|
|
275
274
|
* Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint.
|
|
276
275
|
*/
|
|
277
276
|
sint64(value) {
|
|
278
|
-
|
|
277
|
+
const tc = protoInt64.enc(value),
|
|
279
278
|
// zigzag encode
|
|
280
279
|
sign = tc.hi >> 31, lo = (tc.lo << 1) ^ sign, hi = ((tc.hi << 1) | (tc.lo >>> 31)) ^ sign;
|
|
281
280
|
varint64write(lo, hi, this.buf);
|
|
@@ -285,7 +284,7 @@ export class BinaryWriter {
|
|
|
285
284
|
* Write a `uint64` value, an unsigned 64-bit varint.
|
|
286
285
|
*/
|
|
287
286
|
uint64(value) {
|
|
288
|
-
|
|
287
|
+
const tc = protoInt64.uEnc(value);
|
|
289
288
|
varint64write(tc.lo, tc.hi, this.buf);
|
|
290
289
|
return this;
|
|
291
290
|
}
|
|
@@ -326,11 +325,9 @@ export class BinaryReader {
|
|
|
326
325
|
// ignore
|
|
327
326
|
}
|
|
328
327
|
break;
|
|
329
|
-
// eslint-disable-next-line
|
|
330
328
|
// @ts-expect-error TS7029: Fallthrough case in switch
|
|
331
329
|
case WireType.Bit64:
|
|
332
330
|
this.pos += 4;
|
|
333
|
-
// eslint-disable-next-line no-fallthrough
|
|
334
331
|
case WireType.Bit32:
|
|
335
332
|
this.pos += 4;
|
|
336
333
|
break;
|
|
@@ -411,12 +408,14 @@ export class BinaryReader {
|
|
|
411
408
|
* Read a `fixed32` field, an unsigned, fixed-length 32-bit integer.
|
|
412
409
|
*/
|
|
413
410
|
fixed32() {
|
|
411
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: no
|
|
414
412
|
return this.view.getUint32((this.pos += 4) - 4, true);
|
|
415
413
|
}
|
|
416
414
|
/**
|
|
417
415
|
* Read a `sfixed32` field, a signed, fixed-length 32-bit integer.
|
|
418
416
|
*/
|
|
419
417
|
sfixed32() {
|
|
418
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: no
|
|
420
419
|
return this.view.getInt32((this.pos += 4) - 4, true);
|
|
421
420
|
}
|
|
422
421
|
/**
|
|
@@ -435,12 +434,14 @@ export class BinaryReader {
|
|
|
435
434
|
* Read a `float` field, 32-bit floating point number.
|
|
436
435
|
*/
|
|
437
436
|
float() {
|
|
437
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: no
|
|
438
438
|
return this.view.getFloat32((this.pos += 4) - 4, true);
|
|
439
439
|
}
|
|
440
440
|
/**
|
|
441
441
|
* Read a `double` field, a 64-bit floating point number.
|
|
442
442
|
*/
|
|
443
443
|
double() {
|
|
444
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: no
|
|
444
445
|
return this.view.getFloat64((this.pos += 8) - 8, true);
|
|
445
446
|
}
|
|
446
447
|
/**
|
|
@@ -496,7 +497,7 @@ function assertFloat32(arg) {
|
|
|
496
497
|
if (typeof arg == "string") {
|
|
497
498
|
const o = arg;
|
|
498
499
|
arg = Number(arg);
|
|
499
|
-
if (isNaN(arg) && o !== "NaN") {
|
|
500
|
+
if (Number.isNaN(arg) && o !== "NaN") {
|
|
500
501
|
throw new Error("invalid float32: " + o);
|
|
501
502
|
}
|
|
502
503
|
}
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
import { ScalarType } from "../descriptors.js";
|
|
15
15
|
import { protoInt64 } from "../proto-int64.js";
|
|
16
|
-
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
17
16
|
/**
|
|
18
17
|
* Parse an enum value from the Protobuf text format.
|
|
19
18
|
*
|
|
@@ -136,7 +135,7 @@ function unescapeBytesDefaultValue(str) {
|
|
|
136
135
|
return false;
|
|
137
136
|
}
|
|
138
137
|
const n = parseInt(s + t, 8);
|
|
139
|
-
if (isNaN(n)) {
|
|
138
|
+
if (Number.isNaN(n)) {
|
|
140
139
|
return false;
|
|
141
140
|
}
|
|
142
141
|
b.push(n);
|
|
@@ -149,7 +148,7 @@ function unescapeBytesDefaultValue(str) {
|
|
|
149
148
|
return false;
|
|
150
149
|
}
|
|
151
150
|
const n = parseInt(s + t, 16);
|
|
152
|
-
if (isNaN(n)) {
|
|
151
|
+
if (Number.isNaN(n)) {
|
|
153
152
|
return false;
|
|
154
153
|
}
|
|
155
154
|
b.push(n);
|
|
@@ -162,7 +161,7 @@ function unescapeBytesDefaultValue(str) {
|
|
|
162
161
|
return false;
|
|
163
162
|
}
|
|
164
163
|
const n = parseInt(s + t, 16);
|
|
165
|
-
if (isNaN(n)) {
|
|
164
|
+
if (Number.isNaN(n)) {
|
|
166
165
|
return false;
|
|
167
166
|
}
|
|
168
167
|
const chunk = new Uint8Array(4);
|
package/dist/esm/wire/varint.js
CHANGED
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
// of the input file used when generating it. This code is not
|
|
31
31
|
// standalone and requires a support library to be linked with it. This
|
|
32
32
|
// support library is itself covered by the above license.
|
|
33
|
-
/* eslint-disable prefer-const,@typescript-eslint/restrict-plus-operands */
|
|
34
33
|
/**
|
|
35
34
|
* Read a 64 bit varint as two JS numbers.
|
|
36
35
|
*
|
package/package.json
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protobuf",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"license": "(Apache-2.0 AND BSD-3-Clause)",
|
|
5
5
|
"description": "A complete implementation of Protocol Buffers in TypeScript, suitable for web browsers and Node.js.",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"protobuf",
|
|
8
|
-
"schema",
|
|
9
|
-
"typescript",
|
|
10
|
-
"ecmascript"
|
|
11
|
-
],
|
|
6
|
+
"keywords": ["protobuf", "schema", "typescript", "ecmascript"],
|
|
12
7
|
"repository": {
|
|
13
8
|
"type": "git",
|
|
14
9
|
"url": "https://github.com/bufbuild/protobuf-es.git",
|
|
@@ -21,9 +16,9 @@
|
|
|
21
16
|
"build:esm": "../../node_modules/typescript/bin/tsc --project tsconfig.json --outDir ./dist/esm",
|
|
22
17
|
"bootstrap:inject": "node scripts/bootstrap-inject.mjs src",
|
|
23
18
|
"bootstrap:wkt": "protoc --es_out=src/wkt/gen --es_opt=bootstrap_wkt=true,target=ts,import_extension=js,json_types=true --proto_path $(upstream-include wkt) $(upstream-files wkt) && license-header src/wkt/gen",
|
|
24
|
-
"format": "
|
|
19
|
+
"format": "biome format --write",
|
|
25
20
|
"license-header": "license-header --ignore 'src/wire/varint.ts'",
|
|
26
|
-
"lint": "
|
|
21
|
+
"lint": "biome lint --error-on-warnings",
|
|
27
22
|
"attw": "attw --pack"
|
|
28
23
|
},
|
|
29
24
|
"type": "module",
|
|
@@ -53,24 +48,14 @@
|
|
|
53
48
|
},
|
|
54
49
|
"typesVersions": {
|
|
55
50
|
"*": {
|
|
56
|
-
"codegenv1": [
|
|
57
|
-
|
|
58
|
-
],
|
|
59
|
-
"
|
|
60
|
-
"./dist/cjs/reflect/index.d.ts"
|
|
61
|
-
],
|
|
62
|
-
"wkt": [
|
|
63
|
-
"./dist/cjs/wkt/index.d.ts"
|
|
64
|
-
],
|
|
65
|
-
"wire": [
|
|
66
|
-
"./dist/cjs/wire/index.d.ts"
|
|
67
|
-
]
|
|
51
|
+
"codegenv1": ["./dist/cjs/codegenv1/index.d.ts"],
|
|
52
|
+
"reflect": ["./dist/cjs/reflect/index.d.ts"],
|
|
53
|
+
"wkt": ["./dist/cjs/wkt/index.d.ts"],
|
|
54
|
+
"wire": ["./dist/cjs/wire/index.d.ts"]
|
|
68
55
|
}
|
|
69
56
|
},
|
|
70
57
|
"devDependencies": {
|
|
71
58
|
"upstream-protobuf": "*"
|
|
72
59
|
},
|
|
73
|
-
"files": [
|
|
74
|
-
"dist/**"
|
|
75
|
-
]
|
|
60
|
+
"files": ["dist/**"]
|
|
76
61
|
}
|