Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bufbuild/protobuf

Package Overview
Dependencies
Maintainers
6
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bufbuild/protobuf - npm Package Compare versions

Comparing version 0.0.10 to 0.1.0

114

dist/cjs/create-registry-from-desc.js

@@ -16,3 +16,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.DescriptorRegistry = exports.createRegistryFromDescriptors = void 0;
exports.createRegistryFromDescriptors = void 0;
const assert_js_1 = require("./private/assert.js");

@@ -142,3 +142,3 @@ const proto3_js_1 = require("./proto3.js");

const I = this.findMessage(method.input.typeName);
const O = this.findMessage(method.input.typeName);
const O = this.findMessage(method.output.typeName);
(0, assert_js_1.assert)(I, `message "${method.input.typeName}" for ${method.toString()} not found`);

@@ -165,112 +165,2 @@ (0, assert_js_1.assert)(O, `output message "${method.output.typeName}" for ${method.toString()} not found`);

exports.createRegistryFromDescriptors = createRegistryFromDescriptors;
/**
* DescriptorRegistry is a type registry that dynamically creates types
* from a set of google.protobuf.FileDescriptorProto.
*
* By default, all well-known types with a specialized JSON representation
* are replaced with their generated counterpart in this package.
*/
class DescriptorRegistry {
constructor(descriptorSet, replaceWkt = true) {
this.enums = {};
this.messages = {};
this.services = {};
this.desc = descriptorSet;
if (replaceWkt) {
for (const mt of wkMessages) {
this.messages[mt.typeName] = mt;
}
for (const et of wkEnums) {
this.enums[et.typeName] = et;
}
}
}
/**
* Conveniently create a DescriptorRegistry from a FileDescriptorSet,
* or a FileDescriptorSet in binary format.
*/
static fromFileDescriptorSet(input) {
return new DescriptorRegistry((0, create_descriptor_set_js_1.createDescriptorSet)(input));
}
/**
* May raise an error on invalid descriptors.
*/
findEnum(typeName) {
const existing = this.enums[typeName];
if (existing) {
return existing;
}
const desc = this.desc.enums.get(typeName);
if (!desc) {
return undefined;
}
const runtime = desc.file.syntax == "proto3" ? proto3_js_1.proto3 : proto2_js_1.proto2;
const type = runtime.makeEnumType(typeName, desc.values.map((u) => ({
no: u.number,
name: u.name,
localName: (0, names_js_1.localName)(u),
})), {});
this.enums[typeName] = type;
return type;
}
/**
* May raise an error on invalid descriptors.
*/
findMessage(typeName) {
const existing = this.messages[typeName];
if (existing) {
return existing;
}
const desc = this.desc.messages.get(typeName);
if (!desc) {
return undefined;
}
const runtime = desc.file.syntax == "proto3" ? proto3_js_1.proto3 : proto2_js_1.proto2;
const fields = [];
const type = runtime.makeMessageType(typeName, () => fields, {
localName: (0, names_js_1.localName)(desc),
});
this.messages[typeName] = type;
for (const field of desc.fields) {
const fieldInfo = makeFieldInfo(field, this);
fields.push(fieldInfo);
}
return type;
}
/**
* May raise an error on invalid descriptors.
*/
findService(typeName) {
const existing = this.services[typeName];
if (existing) {
return existing;
}
const desc = this.desc.services.get(typeName);
if (!desc) {
return undefined;
}
const methods = {};
for (const method of desc.methods) {
const I = this.findMessage(method.input.typeName);
const O = this.findMessage(method.input.typeName);
(0, assert_js_1.assert)(I, `message "${method.input.typeName}" for ${method.toString()} not found`);
(0, assert_js_1.assert)(O, `output message "${method.output.typeName}" for ${method.toString()} not found`);
const m = {
name: method.name,
localName: (0, names_js_1.localName)(method),
I,
O,
kind: method.methodKind,
idempotency: method.idempotency,
options: {},
};
methods[m.localName] = m;
}
return (this.services[typeName] = {
typeName: desc.typeName,
methods,
});
}
}
exports.DescriptorRegistry = DescriptorRegistry;
function makeFieldInfo(desc, resolver) {

@@ -277,0 +167,0 @@ switch (desc.kind) {

2

dist/cjs/create-registry.js

@@ -18,3 +18,3 @@ "use strict";

/**
* Create a new registry from the given types. Note that
* Create a new registry from the given types.
*/

@@ -21,0 +21,0 @@ function createRegistry(...types) {

@@ -1172,4 +1172,4 @@ "use strict";

* extension (denoted with parentheses in options specs in .proto files).
* E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
* "foo.(bar.baz).qux".
* E.g.,{ ["foo", false], ["bar.baz", true], ["moo", false] } represents
* "foo.(bar.baz).moo".
*

@@ -1176,0 +1176,0 @@ * @generated from message google.protobuf.UninterpretedOption.NamePart

@@ -28,3 +28,2 @@ "use strict";

*
* The JSON representation for `Empty` is empty JSON object `{}`.
*

@@ -31,0 +30,0 @@ * @generated from message google.protobuf.Empty

@@ -17,3 +17,3 @@ "use strict";

exports.ListValue = exports.Value = exports.Struct = exports.NullValue = void 0;
// @generated by protoc-gen-es v0.0.10 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
// @generated by protoc-gen-es v0.1.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
// @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)

@@ -20,0 +20,0 @@ /* eslint-disable */

@@ -17,3 +17,3 @@ "use strict";

exports.Option = exports.EnumValue = exports.Enum = exports.Field_Cardinality = exports.Field_Kind = exports.Field = exports.Type = exports.Syntax = void 0;
// @generated by protoc-gen-es v0.0.10 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
// @generated by protoc-gen-es v0.1.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
// @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)

@@ -20,0 +20,0 @@ /* eslint-disable */

@@ -35,3 +35,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.varint32read = exports.varint32write = exports.int64toString = exports.int64fromString = exports.varint64write = exports.varint64read = void 0;
exports.varint32read = exports.varint32write = exports.uInt64ToString = exports.int64ToString = exports.int64FromString = exports.varint64write = exports.varint64read = void 0;
/* eslint-disable prefer-const,@typescript-eslint/restrict-plus-operands */

@@ -116,18 +116,16 @@ /**

// constants for binary math
const TWO_PWR_32_DBL = (1 << 16) * (1 << 16);
const TWO_PWR_32_DBL = 0x100000000;
/**
* Parse decimal string of 64 bit integer value as two JS numbers.
*
* Returns tuple:
* [0]: minus sign?
* [1]: low bits
* [2]: high bits
* Copyright 2008 Google Inc. All rights reserved.
*
* Copyright 2008 Google Inc.
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
*/
function int64fromString(dec) {
function int64FromString(dec) {
// Check for minus sign.
let minus = dec[0] == "-";
if (minus)
const minus = dec[0] === "-";
if (minus) {
dec = dec.slice(1);
}
// Work 6 decimal digits at a time, acting like we're converting base 1e6

@@ -154,15 +152,43 @@ // digits to binary. This is safe to do with floating point math because

add1e6digit(-6);
return [minus, lowBits, highBits];
return minus ? negate(lowBits, highBits) : newBits(lowBits, highBits);
}
exports.int64fromString = int64fromString;
exports.int64FromString = int64FromString;
/**
* Format 64 bit integer value (as two JS numbers) to decimal string.
* Losslessly converts a 64-bit signed integer in 32:32 split representation
* into a decimal string.
*
* Copyright 2008 Google Inc.
* Copyright 2008 Google Inc. All rights reserved.
*
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
*/
function int64toString(bitsLow, bitsHigh) {
function int64ToString(lo, hi) {
let bits = newBits(lo, hi);
// If we're treating the input as a signed value and the high bit is set, do
// a manual two's complement conversion before the decimal conversion.
const negative = (bits.hi & 0x80000000);
if (negative) {
bits = negate(bits.lo, bits.hi);
}
const result = uInt64ToString(bits.lo, bits.hi);
return negative ? "-" + result : result;
}
exports.int64ToString = int64ToString;
/**
* Losslessly converts a 64-bit unsigned integer in 32:32 split representation
* into a decimal string.
*
* Copyright 2008 Google Inc. All rights reserved.
*
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
*/
function uInt64ToString(lo, hi) {
({ lo, hi } = toUnsigned(lo, hi));
// Skip the expensive conversion if the number is small enough to use the
// built-in conversions.
if (bitsHigh <= 0x1fffff) {
return "" + (TWO_PWR_32_DBL * bitsHigh + bitsLow);
// Number.MAX_SAFE_INTEGER = 0x001FFFFF FFFFFFFF, thus any number with
// highBits <= 0x1FFFFF can be safely expressed with a double and retain
// integer precision.
// Proven by: Number.isSafeInteger(0x1FFFFF * 2**32 + 0xFFFFFFFF) == true.
if (hi <= 0x1FFFFF) {
return String(TWO_PWR_32_DBL * hi + lo);
}

@@ -178,13 +204,13 @@ // What this code is doing is essentially converting the input number from

// intermediate digits don't overflow.
let low = bitsLow & 0xffffff;
let mid = (((bitsLow >>> 24) | (bitsHigh << 8)) >>> 0) & 0xffffff;
let high = (bitsHigh >> 16) & 0xffff;
const low = lo & 0xFFFFFF;
const mid = ((lo >>> 24) | (hi << 8)) & 0xFFFFFF;
const high = (hi >> 16) & 0xFFFF;
// Assemble our three base-1e7 digits, ignoring carries. The maximum
// value in a digit at this step is representable as a 48-bit integer, which
// can be stored in a 64-bit floating point number.
let digitA = low + mid * 6777216 + high * 6710656;
let digitB = mid + high * 8147497;
let digitC = high * 2;
let digitA = low + (mid * 6777216) + (high * 6710656);
let digitB = mid + (high * 8147497);
let digitC = (high * 2);
// Apply carries from A to B and from B to C.
let base = 10000000;
const base = 10000000;
if (digitA >= base) {

@@ -198,18 +224,40 @@ digitB += Math.floor(digitA / base);

}
// Convert base-1e7 digits to base-10, with optional leading zeroes.
function decimalFrom1e7(digit1e7, needLeadingZeros) {
let partial = digit1e7 ? String(digit1e7) : "";
if (needLeadingZeros) {
return "0000000".slice(partial.length) + partial;
}
return partial;
// If digitC is 0, then we should have returned in the trivial code path
// at the top for non-safe integers. Given this, we can assume both digitB
// and digitA need leading zeros.
return digitC.toString() + decimalFrom1e7WithLeadingZeros(digitB) +
decimalFrom1e7WithLeadingZeros(digitA);
}
exports.uInt64ToString = uInt64ToString;
function toUnsigned(lo, hi) {
return { lo: lo >>> 0, hi: hi >>> 0 };
}
function newBits(lo, hi) {
return { lo: lo | 0, hi: hi | 0 };
}
/**
* Returns two's compliment negation of input.
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Signed_32-bit_integers
*/
function negate(lowBits, highBits) {
highBits = ~highBits;
if (lowBits) {
lowBits = ~lowBits + 1;
}
return (decimalFrom1e7(digitC, /*needLeadingZeros=*/ 0) +
decimalFrom1e7(digitB, /*needLeadingZeros=*/ digitC) +
// If the final 1e7 digit didn't need leading zeros, we would have
// returned via the trivial code path at the top.
decimalFrom1e7(digitA, /*needLeadingZeros=*/ 1));
else {
// If lowBits is 0, then bitwise-not is 0xFFFFFFFF,
// adding 1 to that, results in 0x100000000, which leaves
// the low bits 0x0 and simply adds one to the high bits.
highBits += 1;
}
return newBits(lowBits, highBits);
}
exports.int64toString = int64toString;
/**
* Returns decimal representation of digit1e7 with leading zeros.
*/
const decimalFrom1e7WithLeadingZeros = (digit1e7) => {
const partial = String(digit1e7);
return "0000000".slice(partial.length) + partial;
};
/**
* Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)`

@@ -216,0 +264,0 @@ *

@@ -30,3 +30,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.TypeRegistry = exports.LegacyDescriptorSet = exports.LegacyDescriptorRegistry = exports.createRegistryFromDescriptors = exports.createRegistry = exports.createDescriptorSet = exports.BinaryReader = exports.BinaryWriter = exports.WireType = exports.MethodIdempotency = exports.MethodKind = exports.ScalarType = exports.Message = exports.codegenInfo = exports.protoBase64 = exports.protoInt64 = exports.proto2 = exports.proto3 = void 0;
exports.createRegistryFromDescriptors = exports.createRegistry = exports.createDescriptorSet = exports.BinaryReader = exports.BinaryWriter = exports.WireType = exports.MethodIdempotency = exports.MethodKind = exports.ScalarType = exports.Message = exports.codegenInfo = exports.protoBase64 = exports.protoInt64 = exports.proto2 = exports.proto3 = void 0;
var proto3_js_1 = require("./proto3.js");

@@ -62,8 +62,2 @@ Object.defineProperty(exports, "proto3", { enumerable: true, get: function () { return proto3_js_1.proto3; } });

Object.defineProperty(exports, "createRegistryFromDescriptors", { enumerable: true, get: function () { return create_registry_from_desc_js_1.createRegistryFromDescriptors; } });
var legacy_descriptor_registry_js_1 = require("./legacy-descriptor-registry.js");
Object.defineProperty(exports, "LegacyDescriptorRegistry", { enumerable: true, get: function () { return legacy_descriptor_registry_js_1.LegacyDescriptorRegistry; } });
var legacy_descriptor_set_js_1 = require("./legacy-descriptor-set.js");
Object.defineProperty(exports, "LegacyDescriptorSet", { enumerable: true, get: function () { return legacy_descriptor_set_js_1.LegacyDescriptorSet; } });
var legacy_type_registry_js_1 = require("./legacy-type-registry.js");
Object.defineProperty(exports, "TypeRegistry", { enumerable: true, get: function () { return legacy_type_registry_js_1.TypeRegistry; } });
// ideally, we would export these types with sub-path exports:

@@ -70,0 +64,0 @@ __exportStar(require("./google/protobuf/compiler/plugin_pb.js"), exports);

@@ -79,3 +79,3 @@ "use strict";

if (!Array.isArray(jsonValue)) {
throw new Error(`cannot decode field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonValue)}"`);
throw new Error(`cannot decode field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonValue)}`);
}

@@ -85,3 +85,3 @@ const targetArray = target[localName];

if (jsonItem === null) {
throw new Error(`cannot decode field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonItem)}"`);
throw new Error(`cannot decode field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonItem)}`);
}

@@ -104,3 +104,3 @@ let val;

catch (e) {
let m = `cannot decode field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonItem)}"`;
let m = `cannot decode field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonItem)}`;
if (e instanceof Error && e.message.length > 0) {

@@ -143,3 +143,3 @@ m += `: ${e.message}`;

catch (e) {
let m = `cannot decode map value for field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonValue)}"`;
let m = `cannot decode map value for field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonValue)}`;
if (e instanceof Error && e.message.length > 0) {

@@ -162,3 +162,3 @@ m += `: ${e.message}`;

catch (e) {
let m = `cannot decode map key for field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonValue)}"`;
let m = `cannot decode map key for field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonValue)}`;
if (e instanceof Error && e.message.length > 0) {

@@ -198,3 +198,3 @@ m += `: ${e.message}`;

catch (e) {
let m = `cannot decode field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonValue)}"`;
let m = `cannot decode field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonValue)}`;
if (e instanceof Error && e.message.length > 0) {

@@ -201,0 +201,0 @@ m += `: ${e.message}`;

@@ -17,2 +17,3 @@ "use strict";

exports.protoInt64 = void 0;
const assert_js_1 = require("./private/assert.js");
const varint_js_1 = require("./google/varint.js");

@@ -26,3 +27,6 @@ function makeInt64Support() {

typeof dv.setBigInt64 === "function" &&
typeof dv.setBigUint64 === "function";
typeof dv.setBigUint64 === "function" &&
(typeof process != "object" ||
typeof process.env != "object" ||
process.env.BUF_BIGINT_DISABLE !== "1");
if (ok) {

@@ -73,2 +77,4 @@ const MIN = BigInt("-9223372036854775808"), MAX = BigInt("9223372036854775807"), UMIN = BigInt("0"), UMAX = BigInt("18446744073709551615");

}
const assertInt64String = (value) => (0, assert_js_1.assert)(/^-?[0-9]+$/.test(value), `int64 invalid: ${value}`);
const assertUInt64String = (value) => (0, assert_js_1.assert)(/^[0-9]+$/.test(value), `uint64 invalid: ${value}`);
return {

@@ -78,57 +84,34 @@ zero: "0",

parse(value) {
if (!/^-?[0-9]+$/.test(value)) {
throw new Error(`int64 invalid: ${value}`);
if (typeof value != "string") {
value = value.toString();
}
assertInt64String(value);
return value;
},
uParse(value) {
if (!/^-?[0-9]+$/.test(value)) {
throw new Error(`uint64 invalid: ${value}`);
if (typeof value != "string") {
value = value.toString();
}
assertUInt64String(value);
return value;
},
enc(value) {
if (typeof value == "string") {
if (!/^-?[0-9]+$/.test(value)) {
throw new Error(`int64 invalid: ${value}`);
}
if (typeof value != "string") {
value = value.toString();
}
else {
value = value.toString(10);
}
const [, lo, hi] = (0, varint_js_1.int64fromString)(value);
return { lo, hi };
assertInt64String(value);
return (0, varint_js_1.int64FromString)(value);
},
uEnc(value) {
if (typeof value == "string") {
if (!/^-?[0-9]+$/.test(value)) {
throw new Error(`uint64 invalid: ${value}`);
}
if (typeof value != "string") {
value = value.toString();
}
else {
value = value.toString(10);
}
const [minus, lo, hi] = (0, varint_js_1.int64fromString)(value);
if (minus) {
throw new Error(`uint64 invalid: ${value}`);
}
return { lo, hi };
assertUInt64String(value);
return (0, varint_js_1.int64FromString)(value);
},
dec(lo, hi) {
const minus = (hi & 0x80000000) !== 0;
if (minus) {
// negate
hi = ~hi;
if (lo) {
lo = ~lo + 1;
}
else {
hi += 1;
}
return ("-" + (0, varint_js_1.int64toString)(lo, hi));
}
return (0, varint_js_1.int64toString)(lo, hi);
return (0, varint_js_1.int64ToString)(lo, hi);
},
uDec(lo, hi) {
return (0, varint_js_1.int64toString)(lo, hi);
return (0, varint_js_1.uInt64ToString)(lo, hi);
},

@@ -135,0 +118,0 @@ };

@@ -138,3 +138,3 @@ // Copyright 2021-2022 Buf Technologies, Inc.

const I = this.findMessage(method.input.typeName);
const O = this.findMessage(method.input.typeName);
const O = this.findMessage(method.output.typeName);
assert(I, `message "${method.input.typeName}" for ${method.toString()} not found`);

@@ -160,111 +160,2 @@ assert(O, `output message "${method.output.typeName}" for ${method.toString()} not found`);

}
/**
* DescriptorRegistry is a type registry that dynamically creates types
* from a set of google.protobuf.FileDescriptorProto.
*
* By default, all well-known types with a specialized JSON representation
* are replaced with their generated counterpart in this package.
*/
export class DescriptorRegistry {
constructor(descriptorSet, replaceWkt = true) {
this.enums = {};
this.messages = {};
this.services = {};
this.desc = descriptorSet;
if (replaceWkt) {
for (const mt of wkMessages) {
this.messages[mt.typeName] = mt;
}
for (const et of wkEnums) {
this.enums[et.typeName] = et;
}
}
}
/**
* Conveniently create a DescriptorRegistry from a FileDescriptorSet,
* or a FileDescriptorSet in binary format.
*/
static fromFileDescriptorSet(input) {
return new DescriptorRegistry(createDescriptorSet(input));
}
/**
* May raise an error on invalid descriptors.
*/
findEnum(typeName) {
const existing = this.enums[typeName];
if (existing) {
return existing;
}
const desc = this.desc.enums.get(typeName);
if (!desc) {
return undefined;
}
const runtime = desc.file.syntax == "proto3" ? proto3 : proto2;
const type = runtime.makeEnumType(typeName, desc.values.map((u) => ({
no: u.number,
name: u.name,
localName: localName(u),
})), {});
this.enums[typeName] = type;
return type;
}
/**
* May raise an error on invalid descriptors.
*/
findMessage(typeName) {
const existing = this.messages[typeName];
if (existing) {
return existing;
}
const desc = this.desc.messages.get(typeName);
if (!desc) {
return undefined;
}
const runtime = desc.file.syntax == "proto3" ? proto3 : proto2;
const fields = [];
const type = runtime.makeMessageType(typeName, () => fields, {
localName: localName(desc),
});
this.messages[typeName] = type;
for (const field of desc.fields) {
const fieldInfo = makeFieldInfo(field, this);
fields.push(fieldInfo);
}
return type;
}
/**
* May raise an error on invalid descriptors.
*/
findService(typeName) {
const existing = this.services[typeName];
if (existing) {
return existing;
}
const desc = this.desc.services.get(typeName);
if (!desc) {
return undefined;
}
const methods = {};
for (const method of desc.methods) {
const I = this.findMessage(method.input.typeName);
const O = this.findMessage(method.input.typeName);
assert(I, `message "${method.input.typeName}" for ${method.toString()} not found`);
assert(O, `output message "${method.output.typeName}" for ${method.toString()} not found`);
const m = {
name: method.name,
localName: localName(method),
I,
O,
kind: method.methodKind,
idempotency: method.idempotency,
options: {},
};
methods[m.localName] = m;
}
return (this.services[typeName] = {
typeName: desc.typeName,
methods,
});
}
}
function makeFieldInfo(desc, resolver) {

@@ -271,0 +162,0 @@ switch (desc.kind) {

@@ -15,3 +15,3 @@ // Copyright 2021-2022 Buf Technologies, Inc.

/**
* Create a new registry from the given types. Note that
* Create a new registry from the given types.
*/

@@ -18,0 +18,0 @@ export function createRegistry(...types) {

@@ -1147,4 +1147,4 @@ // Copyright 2021-2022 Buf Technologies, Inc.

* extension (denoted with parentheses in options specs in .proto files).
* E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
* "foo.(bar.baz).qux".
* E.g.,{ ["foo", false], ["bar.baz", true], ["moo", false] } represents
* "foo.(bar.baz).moo".
*

@@ -1151,0 +1151,0 @@ * @generated from message google.protobuf.UninterpretedOption.NamePart

@@ -25,3 +25,2 @@ // Copyright 2021-2022 Buf Technologies, Inc.

*
* The JSON representation for `Empty` is empty JSON object `{}`.
*

@@ -28,0 +27,0 @@ * @generated from message google.protobuf.Empty

@@ -14,3 +14,3 @@ // Copyright 2021-2022 Buf Technologies, Inc.

// limitations under the License.
// @generated by protoc-gen-es v0.0.10 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
// @generated by protoc-gen-es v0.1.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
// @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)

@@ -17,0 +17,0 @@ /* eslint-disable */

@@ -14,3 +14,3 @@ // Copyright 2021-2022 Buf Technologies, Inc.

// limitations under the License.
// @generated by protoc-gen-es v0.0.10 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
// @generated by protoc-gen-es v0.1.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
// @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)

@@ -17,0 +17,0 @@ /* eslint-disable */

@@ -110,18 +110,16 @@ // Copyright 2008 Google Inc. All rights reserved.

// constants for binary math
const TWO_PWR_32_DBL = (1 << 16) * (1 << 16);
const TWO_PWR_32_DBL = 0x100000000;
/**
* Parse decimal string of 64 bit integer value as two JS numbers.
*
* Returns tuple:
* [0]: minus sign?
* [1]: low bits
* [2]: high bits
* Copyright 2008 Google Inc. All rights reserved.
*
* Copyright 2008 Google Inc.
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
*/
export function int64fromString(dec) {
export function int64FromString(dec) {
// Check for minus sign.
let minus = dec[0] == "-";
if (minus)
const minus = dec[0] === "-";
if (minus) {
dec = dec.slice(1);
}
// Work 6 decimal digits at a time, acting like we're converting base 1e6

@@ -148,14 +146,41 @@ // digits to binary. This is safe to do with floating point math because

add1e6digit(-6);
return [minus, lowBits, highBits];
return minus ? negate(lowBits, highBits) : newBits(lowBits, highBits);
}
/**
* Format 64 bit integer value (as two JS numbers) to decimal string.
* Losslessly converts a 64-bit signed integer in 32:32 split representation
* into a decimal string.
*
* Copyright 2008 Google Inc.
* Copyright 2008 Google Inc. All rights reserved.
*
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
*/
export function int64toString(bitsLow, bitsHigh) {
export function int64ToString(lo, hi) {
let bits = newBits(lo, hi);
// If we're treating the input as a signed value and the high bit is set, do
// a manual two's complement conversion before the decimal conversion.
const negative = (bits.hi & 0x80000000);
if (negative) {
bits = negate(bits.lo, bits.hi);
}
const result = uInt64ToString(bits.lo, bits.hi);
return negative ? "-" + result : result;
}
/**
* Losslessly converts a 64-bit unsigned integer in 32:32 split representation
* into a decimal string.
*
* Copyright 2008 Google Inc. All rights reserved.
*
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
*/
export function uInt64ToString(lo, hi) {
({ lo, hi } = toUnsigned(lo, hi));
// Skip the expensive conversion if the number is small enough to use the
// built-in conversions.
if (bitsHigh <= 0x1fffff) {
return "" + (TWO_PWR_32_DBL * bitsHigh + bitsLow);
// Number.MAX_SAFE_INTEGER = 0x001FFFFF FFFFFFFF, thus any number with
// highBits <= 0x1FFFFF can be safely expressed with a double and retain
// integer precision.
// Proven by: Number.isSafeInteger(0x1FFFFF * 2**32 + 0xFFFFFFFF) == true.
if (hi <= 0x1FFFFF) {
return String(TWO_PWR_32_DBL * hi + lo);
}

@@ -171,13 +196,13 @@ // What this code is doing is essentially converting the input number from

// intermediate digits don't overflow.
let low = bitsLow & 0xffffff;
let mid = (((bitsLow >>> 24) | (bitsHigh << 8)) >>> 0) & 0xffffff;
let high = (bitsHigh >> 16) & 0xffff;
const low = lo & 0xFFFFFF;
const mid = ((lo >>> 24) | (hi << 8)) & 0xFFFFFF;
const high = (hi >> 16) & 0xFFFF;
// Assemble our three base-1e7 digits, ignoring carries. The maximum
// value in a digit at this step is representable as a 48-bit integer, which
// can be stored in a 64-bit floating point number.
let digitA = low + mid * 6777216 + high * 6710656;
let digitB = mid + high * 8147497;
let digitC = high * 2;
let digitA = low + (mid * 6777216) + (high * 6710656);
let digitB = mid + (high * 8147497);
let digitC = (high * 2);
// Apply carries from A to B and from B to C.
let base = 10000000;
const base = 10000000;
if (digitA >= base) {

@@ -191,17 +216,39 @@ digitB += Math.floor(digitA / base);

}
// Convert base-1e7 digits to base-10, with optional leading zeroes.
function decimalFrom1e7(digit1e7, needLeadingZeros) {
let partial = digit1e7 ? String(digit1e7) : "";
if (needLeadingZeros) {
return "0000000".slice(partial.length) + partial;
}
return partial;
// If digitC is 0, then we should have returned in the trivial code path
// at the top for non-safe integers. Given this, we can assume both digitB
// and digitA need leading zeros.
return digitC.toString() + decimalFrom1e7WithLeadingZeros(digitB) +
decimalFrom1e7WithLeadingZeros(digitA);
}
function toUnsigned(lo, hi) {
return { lo: lo >>> 0, hi: hi >>> 0 };
}
function newBits(lo, hi) {
return { lo: lo | 0, hi: hi | 0 };
}
/**
* Returns two's compliment negation of input.
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Signed_32-bit_integers
*/
function negate(lowBits, highBits) {
highBits = ~highBits;
if (lowBits) {
lowBits = ~lowBits + 1;
}
return (decimalFrom1e7(digitC, /*needLeadingZeros=*/ 0) +
decimalFrom1e7(digitB, /*needLeadingZeros=*/ digitC) +
// If the final 1e7 digit didn't need leading zeros, we would have
// returned via the trivial code path at the top.
decimalFrom1e7(digitA, /*needLeadingZeros=*/ 1));
else {
// If lowBits is 0, then bitwise-not is 0xFFFFFFFF,
// adding 1 to that, results in 0x100000000, which leaves
// the low bits 0x0 and simply adds one to the high bits.
highBits += 1;
}
return newBits(lowBits, highBits);
}
/**
* Returns decimal representation of digit1e7 with leading zeros.
*/
const decimalFrom1e7WithLeadingZeros = (digit1e7) => {
const partial = String(digit1e7);
return "0000000".slice(partial.length) + partial;
};
/**
* Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)`

@@ -208,0 +255,0 @@ *

@@ -29,5 +29,2 @@ // Copyright 2021-2022 Buf Technologies, Inc.

export { createRegistryFromDescriptors } from "./create-registry-from-desc.js";
export { LegacyDescriptorRegistry } from "./legacy-descriptor-registry.js";
export { LegacyDescriptorSet } from "./legacy-descriptor-set.js";
export { TypeRegistry } from "./legacy-type-registry.js";
// ideally, we would export these types with sub-path exports:

@@ -34,0 +31,0 @@ export * from "./google/protobuf/compiler/plugin_pb.js";

@@ -76,3 +76,3 @@ // Copyright 2021-2022 Buf Technologies, Inc.

if (!Array.isArray(jsonValue)) {
throw new Error(`cannot decode field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonValue)}"`);
throw new Error(`cannot decode field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonValue)}`);
}

@@ -82,3 +82,3 @@ const targetArray = target[localName];

if (jsonItem === null) {
throw new Error(`cannot decode field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonItem)}"`);
throw new Error(`cannot decode field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonItem)}`);
}

@@ -101,3 +101,3 @@ let val;

catch (e) {
let m = `cannot decode field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonItem)}"`;
let m = `cannot decode field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonItem)}`;
if (e instanceof Error && e.message.length > 0) {

@@ -140,3 +140,3 @@ m += `: ${e.message}`;

catch (e) {
let m = `cannot decode map value for field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonValue)}"`;
let m = `cannot decode map value for field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonValue)}`;
if (e instanceof Error && e.message.length > 0) {

@@ -159,3 +159,3 @@ m += `: ${e.message}`;

catch (e) {
let m = `cannot decode map key for field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonValue)}"`;
let m = `cannot decode map key for field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonValue)}`;
if (e instanceof Error && e.message.length > 0) {

@@ -195,3 +195,3 @@ m += `: ${e.message}`;

catch (e) {
let m = `cannot decode field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonValue)}"`;
let m = `cannot decode field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonValue)}`;
if (e instanceof Error && e.message.length > 0) {

@@ -198,0 +198,0 @@ m += `: ${e.message}`;

@@ -14,3 +14,4 @@ // Copyright 2021-2022 Buf Technologies, Inc.

// limitations under the License.
import { int64fromString, int64toString } from "./google/varint.js";
import { assert } from "./private/assert.js";
import { int64FromString, int64ToString, uInt64ToString, } from "./google/varint.js";
function makeInt64Support() {

@@ -23,3 +24,6 @@ const dv = new DataView(new ArrayBuffer(8));

typeof dv.setBigInt64 === "function" &&
typeof dv.setBigUint64 === "function";
typeof dv.setBigUint64 === "function" &&
(typeof process != "object" ||
typeof process.env != "object" ||
process.env.BUF_BIGINT_DISABLE !== "1");
if (ok) {

@@ -70,2 +74,4 @@ const MIN = BigInt("-9223372036854775808"), MAX = BigInt("9223372036854775807"), UMIN = BigInt("0"), UMAX = BigInt("18446744073709551615");

}
const assertInt64String = (value) => assert(/^-?[0-9]+$/.test(value), `int64 invalid: ${value}`);
const assertUInt64String = (value) => assert(/^[0-9]+$/.test(value), `uint64 invalid: ${value}`);
return {

@@ -75,57 +81,34 @@ zero: "0",

parse(value) {
if (!/^-?[0-9]+$/.test(value)) {
throw new Error(`int64 invalid: ${value}`);
if (typeof value != "string") {
value = value.toString();
}
assertInt64String(value);
return value;
},
uParse(value) {
if (!/^-?[0-9]+$/.test(value)) {
throw new Error(`uint64 invalid: ${value}`);
if (typeof value != "string") {
value = value.toString();
}
assertUInt64String(value);
return value;
},
enc(value) {
if (typeof value == "string") {
if (!/^-?[0-9]+$/.test(value)) {
throw new Error(`int64 invalid: ${value}`);
}
if (typeof value != "string") {
value = value.toString();
}
else {
value = value.toString(10);
}
const [, lo, hi] = int64fromString(value);
return { lo, hi };
assertInt64String(value);
return int64FromString(value);
},
uEnc(value) {
if (typeof value == "string") {
if (!/^-?[0-9]+$/.test(value)) {
throw new Error(`uint64 invalid: ${value}`);
}
if (typeof value != "string") {
value = value.toString();
}
else {
value = value.toString(10);
}
const [minus, lo, hi] = int64fromString(value);
if (minus) {
throw new Error(`uint64 invalid: ${value}`);
}
return { lo, hi };
assertUInt64String(value);
return int64FromString(value);
},
dec(lo, hi) {
const minus = (hi & 0x80000000) !== 0;
if (minus) {
// negate
hi = ~hi;
if (lo) {
lo = ~lo + 1;
}
else {
hi += 1;
}
return ("-" + int64toString(lo, hi));
}
return int64toString(lo, hi);
return int64ToString(lo, hi);
},
uDec(lo, hi) {
return int64toString(lo, hi);
return uInt64ToString(lo, hi);
},

@@ -132,0 +115,0 @@ };

@@ -1,5 +0,2 @@

import type { MessageType } from "./message-type.js";
import type { EnumType } from "./enum.js";
import type { IEnumTypeRegistry, IMessageTypeRegistry, IServiceTypeRegistry } from "./type-registry.js";
import type { ServiceType } from "./service-type.js";
import { FileDescriptorSet } from "./google/protobuf/descriptor_pb.js";

@@ -19,32 +16,1 @@ import type { DescriptorSet } from "./descriptor-set.js";

export declare function createRegistryFromDescriptors(input: DescriptorSet | FileDescriptorSet | Uint8Array, replaceWkt?: boolean): IMessageTypeRegistry & IEnumTypeRegistry & IServiceTypeRegistry;
/**
* DescriptorRegistry is a type registry that dynamically creates types
* from a set of google.protobuf.FileDescriptorProto.
*
* By default, all well-known types with a specialized JSON representation
* are replaced with their generated counterpart in this package.
*/
export declare class DescriptorRegistry implements IMessageTypeRegistry, IEnumTypeRegistry, IServiceTypeRegistry {
private readonly desc;
private readonly enums;
private readonly messages;
private readonly services;
constructor(descriptorSet: DescriptorSet, replaceWkt?: boolean);
/**
* Conveniently create a DescriptorRegistry from a FileDescriptorSet,
* or a FileDescriptorSet in binary format.
*/
static fromFileDescriptorSet(input: FileDescriptorSet | Uint8Array): DescriptorRegistry;
/**
* May raise an error on invalid descriptors.
*/
findEnum(typeName: string): EnumType | undefined;
/**
* May raise an error on invalid descriptors.
*/
findMessage(typeName: string): MessageType | undefined;
/**
* May raise an error on invalid descriptors.
*/
findService(typeName: string): ServiceType | undefined;
}

@@ -6,4 +6,4 @@ import type { MessageType } from "./message-type.js";

/**
* Create a new registry from the given types. Note that
* Create a new registry from the given types.
*/
export declare function createRegistry(...types: Array<MessageType | EnumType | ServiceType>): IMessageTypeRegistry & IEnumTypeRegistry & IServiceTypeRegistry;

@@ -15,3 +15,2 @@ import type { PartialMessage, PlainMessage } from "../../message.js";

*
* The JSON representation for `Empty` is empty JSON object `{}`.
*

@@ -18,0 +17,0 @@ * @generated from message google.protobuf.Empty

@@ -24,17 +24,29 @@ /**

*
* Returns tuple:
* [0]: minus sign?
* [1]: low bits
* [2]: high bits
* Copyright 2008 Google Inc. All rights reserved.
*
* Copyright 2008 Google Inc.
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
*/
export declare function int64fromString(dec: string): [boolean, number, number];
export declare function int64FromString(dec: string): {
lo: number;
hi: number;
};
/**
* Format 64 bit integer value (as two JS numbers) to decimal string.
* Losslessly converts a 64-bit signed integer in 32:32 split representation
* into a decimal string.
*
* Copyright 2008 Google Inc.
* Copyright 2008 Google Inc. All rights reserved.
*
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
*/
export declare function int64toString(bitsLow: number, bitsHigh: number): string;
export declare function int64ToString(lo: number, hi: number): string;
/**
* Losslessly converts a 64-bit unsigned integer in 32:32 split representation
* into a decimal string.
*
* Copyright 2008 Google Inc. All rights reserved.
*
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
*/
export declare function uInt64ToString(lo: number, hi: number): string;
/**
* Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)`

@@ -41,0 +53,0 @@ *

@@ -23,5 +23,2 @@ export { proto3 } from "./proto3.js";

export { createRegistryFromDescriptors } from "./create-registry-from-desc.js";
export { LegacyDescriptorRegistry } from "./legacy-descriptor-registry.js";
export { LegacyDescriptorSet } from "./legacy-descriptor-set.js";
export { TypeRegistry } from "./legacy-type-registry.js";
export * from "./google/protobuf/compiler/plugin_pb.js";

@@ -28,0 +25,0 @@ export * from "./google/protobuf/api_pb.js";

@@ -70,3 +70,5 @@ import type { BinaryReadOptions, BinaryWriteOptions } from "./binary-format.js";

*/
export declare type PlainMessage<T extends Message> = Omit<T, keyof Message>;
export declare type PlainMessage<T extends Message> = {
[P in keyof T as T[P] extends Function ? never : P]: T[P];
};
/**

@@ -73,0 +75,0 @@ * PartialMessage<T> constructs a type from a message. The resulting type

@@ -32,18 +32,19 @@ /**

* If you need to manipulate 64-bit integral values that are outside the
* range of safe representation as Number, you can work with the two's
* complement directly. The following example negates a field value:
* range of safe representation as a JavaScript Number, we recommend you
* use a third party library, for example the npm package "long":
*
* ```ts
* let t = protoInt64.enc(message.int64Field);
* t.hi = ~t.hi;
* if (t.lo) {
* t.lo = ~t.lo + 1;
* } else {
* t.hi += 1;
* }
* message.int64Field = protoInt64.dec(t.lo, t.hi);
* // convert the field value to a Long
* const bits = protoInt64.enc(message.int64Field);
* const longValue = Long.fromBits(bits.lo, bits.hi);
*
* // perform arithmetic
* const longResult = longValue.subtract(1);
*
* // set the result in the field
* message.int64Field = protoInt64.dec(longResult.low, longResult.high);
*
* // Assuming int64Field contains 9223372036854775807:
* console.log(message.int64Field); // 9223372036854775806
* ```
*
* There are several 3rd party libraries that provide arithmetic operations
* on a two's complement, for example the npm package "long".
*/

@@ -50,0 +51,0 @@ interface Int64Support {

{
"name": "@bufbuild/protobuf",
"version": "0.0.10",
"version": "0.1.0",
"license": "(Apache-2.0 AND BSD-3-Clause)",

@@ -15,6 +15,6 @@ "description": "A complete implementation of Protocol Buffers in TypeScript, suitable for web browsers and Node.js.",

"build": "npm run build:cjs && npm run build:esm+types",
"build:cjs": "npx tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm+types": "npx tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types"
"build:cjs": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm+types": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types"
},
"main": "./dist/esm/index.js",
"main": "./dist/cjs/index.js",
"type": "module",

@@ -24,8 +24,4 @@ "types": "./dist/types/index.d.ts",

"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"default": "./dist/esm/index.js"
"require": "./dist/cjs/index.js"
},
"devDependencies": {
"typescript": "^4.7.4"
},
"files": [

@@ -32,0 +28,0 @@ "dist/**/"

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc