You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@bufbuild/protobuf

Package Overview
Dependencies
Maintainers
6
Versions
73
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
2.9.0
to
2.10.0
+9
dist/cjs/wkt/duration.d.ts
import type { Duration } from "./gen/google/protobuf/duration_pb.js";
/**
* Create a google.protobuf.Duration message from a Unix timestamp in milliseconds.
*/
export declare function durationFromMs(durationMs: number): Duration;
/**
* Convert a google.protobuf.Duration to a Unix timestamp in milliseconds.
*/
export declare function durationMs(duration: Duration): number;
"use strict";
// Copyright 2021-2025 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.durationFromMs = durationFromMs;
exports.durationMs = durationMs;
const duration_pb_js_1 = require("./gen/google/protobuf/duration_pb.js");
const create_js_1 = require("../create.js");
const proto_int64_js_1 = require("../proto-int64.js");
/**
* Create a google.protobuf.Duration message from a Unix timestamp in milliseconds.
*/
function durationFromMs(durationMs) {
const sign = durationMs < 0 ? -1 : 1;
const absDurationMs = Math.abs(durationMs);
const absSeconds = Math.floor(absDurationMs / 1000);
const absNanos = (absDurationMs - absSeconds * 1000) * 1000000;
return (0, create_js_1.create)(duration_pb_js_1.DurationSchema, {
seconds: proto_int64_js_1.protoInt64.parse(absSeconds * sign),
nanos: absNanos === 0 ? 0 : absNanos * sign, // deliberately avoid signed 0 - it does not serialize
});
}
/**
* Convert a google.protobuf.Duration to a Unix timestamp in milliseconds.
*/
function durationMs(duration) {
return Number(duration.seconds) * 1000 + Math.round(duration.nanos / 1000000);
}
import type { Duration } from "./gen/google/protobuf/duration_pb.js";
/**
* Create a google.protobuf.Duration message from a Unix timestamp in milliseconds.
*/
export declare function durationFromMs(durationMs: number): Duration;
/**
* Convert a google.protobuf.Duration to a Unix timestamp in milliseconds.
*/
export declare function durationMs(duration: Duration): number;
// Copyright 2021-2025 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { DurationSchema } from "./gen/google/protobuf/duration_pb.js";
import { create } from "../create.js";
import { protoInt64 } from "../proto-int64.js";
/**
* Create a google.protobuf.Duration message from a Unix timestamp in milliseconds.
*/
export function durationFromMs(durationMs) {
const sign = durationMs < 0 ? -1 : 1;
const absDurationMs = Math.abs(durationMs);
const absSeconds = Math.floor(absDurationMs / 1000);
const absNanos = (absDurationMs - absSeconds * 1000) * 1000000;
return create(DurationSchema, {
seconds: protoInt64.parse(absSeconds * sign),
nanos: absNanos === 0 ? 0 : absNanos * sign, // deliberately avoid signed 0 - it does not serialize
});
}
/**
* Convert a google.protobuf.Duration to a Unix timestamp in milliseconds.
*/
export function durationMs(duration) {
return Number(duration.seconds) * 1000 + Math.round(duration.nanos / 1000000);
}
+9
-5

@@ -42,10 +42,14 @@ "use strict";

}
const messageSortedFields = new WeakMap();
class ReflectMessageImpl {
get sortedFields() {
var _a;
return ((_a = this._sortedFields) !== null && _a !== void 0 ? _a :
// biome-ignore lint/suspicious/noAssignInExpressions: no
(this._sortedFields = this.desc.fields
const cached = messageSortedFields.get(this.desc);
if (cached) {
return cached;
}
const sortedFields = this.desc.fields
.concat()
.sort((a, b) => a.number - b.number)));
.sort((a, b) => a.number - b.number);
messageSortedFields.set(this.desc, sortedFields);
return sortedFields;
}

@@ -52,0 +56,0 @@ constructor(messageDesc, message, check = true) {

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

// bootstrap-inject defaults: EDITION_PROTO2 to EDITION_2024: export const minimumEdition: SupportedEdition = $minimumEdition, maximumEdition: SupportedEdition = $maximumEdition;
// generated from protoc v32.0
// generated from protoc v33.0
exports.minimumEdition = 998, exports.maximumEdition = 1001;

@@ -235,0 +235,0 @@ const featureDefaults = {

@@ -300,9 +300,13 @@ "use strict";

function durationToJson(val) {
if (Number(val.seconds) > 315576000000 ||
Number(val.seconds) < -315576000000) {
const seconds = Number(val.seconds);
const nanos = val.nanos;
if (seconds > 315576000000 || seconds < -315576000000) {
throw new Error(`cannot encode message ${val.$typeName} to JSON: value out of range`);
}
if ((seconds > 0 && nanos < 0) || (seconds < 0 && nanos > 0)) {
throw new Error(`cannot encode message ${val.$typeName} to JSON: nanos sign must match seconds sign`);
}
let text = val.seconds.toString();
if (val.nanos !== 0) {
let nanosStr = Math.abs(val.nanos).toString();
if (nanos !== 0) {
let nanosStr = Math.abs(nanos).toString();
nanosStr = "0".repeat(9 - nanosStr.length) + nanosStr;

@@ -316,3 +320,3 @@ if (nanosStr.substring(3) === "000000") {

text += "." + nanosStr;
if (val.nanos < 0 && Number(val.seconds) == 0) {
if (nanos < 0 && seconds == 0) {
text = "-" + text;

@@ -375,2 +379,5 @@ }

}
if (val.nanos > 999999999) {
throw new Error(`cannot encode message ${val.$typeName} to JSON: nanos must not be greater than 99999999`);
}
let z = "Z";

@@ -377,0 +384,0 @@ if (val.nanos > 0) {

@@ -103,5 +103,5 @@ import type { GenFile, GenMessage } from "../../../../codegenv2/types.js";

/**
* Represents seconds of UTC time since Unix epoch
* 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
* 9999-12-31T23:59:59Z inclusive.
* Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must
* be between -315576000000 and 315576000000 inclusive (which corresponds to
* 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z).
*

@@ -112,5 +112,6 @@ * @generated from field: int64 seconds = 1;

/**
* Non-negative fractions of a second at nanosecond resolution. Negative
* second values with fractions must still have non-negative nanos values
* that count forward in time. Must be from 0 to 999,999,999
* Non-negative fractions of a second at nanosecond resolution. This field is
* the nanosecond portion of the duration, not an alternative to seconds.
* Negative second values with fractions must still have non-negative nanos
* values that count forward in time. Must be between 0 and 999,999,999
* inclusive.

@@ -117,0 +118,0 @@ *

export * from "./timestamp.js";
export * from "./duration.js";
export * from "./any.js";

@@ -3,0 +4,0 @@ export * from "./wrappers.js";

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

__exportStar(require("./timestamp.js"), exports);
__exportStar(require("./duration.js"), exports);
__exportStar(require("./any.js"), exports);

@@ -33,0 +34,0 @@ __exportStar(require("./wrappers.js"), exports);

@@ -37,10 +37,14 @@ // Copyright 2021-2025 Buf Technologies, Inc.

}
const messageSortedFields = new WeakMap();
class ReflectMessageImpl {
get sortedFields() {
var _a;
return ((_a = this._sortedFields) !== null && _a !== void 0 ? _a :
// biome-ignore lint/suspicious/noAssignInExpressions: no
(this._sortedFields = this.desc.fields
const cached = messageSortedFields.get(this.desc);
if (cached) {
return cached;
}
const sortedFields = this.desc.fields
.concat()
.sort((a, b) => a.number - b.number)));
.sort((a, b) => a.number - b.number);
messageSortedFields.set(this.desc, sortedFields);
return sortedFields;
}

@@ -47,0 +51,0 @@ constructor(messageDesc, message, check = true) {

@@ -226,3 +226,3 @@ // Copyright 2021-2025 Buf Technologies, Inc.

// bootstrap-inject defaults: EDITION_PROTO2 to EDITION_2024: export const minimumEdition: SupportedEdition = $minimumEdition, maximumEdition: SupportedEdition = $maximumEdition;
// generated from protoc v32.0
// generated from protoc v33.0
export const minimumEdition = 998, maximumEdition = 1001;

@@ -229,0 +229,0 @@ const featureDefaults = {

@@ -295,9 +295,13 @@ // Copyright 2021-2025 Buf Technologies, Inc.

function durationToJson(val) {
if (Number(val.seconds) > 315576000000 ||
Number(val.seconds) < -315576000000) {
const seconds = Number(val.seconds);
const nanos = val.nanos;
if (seconds > 315576000000 || seconds < -315576000000) {
throw new Error(`cannot encode message ${val.$typeName} to JSON: value out of range`);
}
if ((seconds > 0 && nanos < 0) || (seconds < 0 && nanos > 0)) {
throw new Error(`cannot encode message ${val.$typeName} to JSON: nanos sign must match seconds sign`);
}
let text = val.seconds.toString();
if (val.nanos !== 0) {
let nanosStr = Math.abs(val.nanos).toString();
if (nanos !== 0) {
let nanosStr = Math.abs(nanos).toString();
nanosStr = "0".repeat(9 - nanosStr.length) + nanosStr;

@@ -311,3 +315,3 @@ if (nanosStr.substring(3) === "000000") {

text += "." + nanosStr;
if (val.nanos < 0 && Number(val.seconds) == 0) {
if (nanos < 0 && seconds == 0) {
text = "-" + text;

@@ -370,2 +374,5 @@ }

}
if (val.nanos > 999999999) {
throw new Error(`cannot encode message ${val.$typeName} to JSON: nanos must not be greater than 99999999`);
}
let z = "Z";

@@ -372,0 +379,0 @@ if (val.nanos > 0) {

@@ -103,5 +103,5 @@ import type { GenFile, GenMessage } from "../../../../codegenv2/types.js";

/**
* Represents seconds of UTC time since Unix epoch
* 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
* 9999-12-31T23:59:59Z inclusive.
* Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must
* be between -315576000000 and 315576000000 inclusive (which corresponds to
* 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z).
*

@@ -112,5 +112,6 @@ * @generated from field: int64 seconds = 1;

/**
* Non-negative fractions of a second at nanosecond resolution. Negative
* second values with fractions must still have non-negative nanos values
* that count forward in time. Must be from 0 to 999,999,999
* Non-negative fractions of a second at nanosecond resolution. This field is
* the nanosecond portion of the duration, not an alternative to seconds.
* Negative second values with fractions must still have non-negative nanos
* values that count forward in time. Must be between 0 and 999,999,999
* inclusive.

@@ -117,0 +118,0 @@ *

export * from "./timestamp.js";
export * from "./duration.js";
export * from "./any.js";

@@ -3,0 +4,0 @@ export * from "./wrappers.js";

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

export * from "./timestamp.js";
export * from "./duration.js";
export * from "./any.js";

@@ -17,0 +18,0 @@ export * from "./wrappers.js";

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

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

@@ -9,3 +9,3 @@ # @bufbuild/protobuf

A complete implementation of [Protocol Buffers](https://protobuf.dev/) in TypeScript,
suitable for web browsers and Node.js, created by [Buf](https://buf.build).
suitable for web browsers, Node.js, and Deno, created by [Buf](https://buf.build).

@@ -12,0 +12,0 @@ **Protobuf-ES** is a solid, modern alternative to existing Protobuf implementations for the JavaScript ecosystem. It's