You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@foxglove/rosbag2

Package Overview
Dependencies
Maintainers
0
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@foxglove/rosbag2 - npm Package Compare versions

Comparing version

to
6.0.0

4

dist/metadata.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseQosProfiles = void 0;
exports.parseQosProfiles = parseQosProfiles;
const rostime_1 = require("@foxglove/rostime");

@@ -41,6 +41,6 @@ const types_1 = require("./types");

}
exports.parseQosProfiles = parseQosProfiles;
function getQosProfiles(array) {
const profiles = [];
for (const entryMaybe of array) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (entryMaybe == undefined) {

@@ -47,0 +47,0 @@ continue;

import type { MessageDefinition } from "@foxglove/message-definition";
import { MessageReaderOptions } from "@foxglove/rosmsg2-serialization";
import { Time } from "@foxglove/rostime";

@@ -7,5 +8,4 @@ import { Message, MessageReadOptions, SqliteDb, TopicDefinition } from "./types";

export declare class Rosbag2 {
private messageReaders_;
private databases_;
constructor(files: SqliteDb[]);
#private;
constructor(files: SqliteDb[], messageReaderOptions?: MessageReaderOptions);
open(): Promise<void>;

@@ -17,4 +17,3 @@ close(): Promise<void>;

messageCounts(): Promise<Map<string, number>>;
private decodeMessage;
}
//# sourceMappingURL=Rosbag2.d.ts.map
"use strict";
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _Rosbag2_messageReaders, _Rosbag2_databases, _Rosbag2_messageReaderOptions, _Rosbag2_decodeMessage;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -38,7 +50,9 @@ exports.Rosbag2 = exports.ROS2_DEFINITIONS_ARRAY = exports.ROS2_TO_DEFINITIONS = void 0;

class Rosbag2 {
constructor(files) {
this.messageReaders_ = new Map();
this.decodeMessage = (rawMessage) => {
constructor(files, messageReaderOptions) {
_Rosbag2_messageReaders.set(this, new Map());
_Rosbag2_databases.set(this, void 0);
_Rosbag2_messageReaderOptions.set(this, void 0);
_Rosbag2_decodeMessage.set(this, (rawMessage) => {
// Find or create a message reader for this message
let reader = this.messageReaders_.get(rawMessage.topic.type);
let reader = __classPrivateFieldGet(this, _Rosbag2_messageReaders, "f").get(rawMessage.topic.type);
if (reader == undefined) {

@@ -49,11 +63,12 @@ const msgdef = exports.ROS2_TO_DEFINITIONS.get(rawMessage.topic.type);

}
reader = new rosmsg2_serialization_1.MessageReader([msgdef, ...exports.ROS2_DEFINITIONS_ARRAY]);
this.messageReaders_.set(rawMessage.topic.type, reader);
reader = new rosmsg2_serialization_1.MessageReader([msgdef, ...exports.ROS2_DEFINITIONS_ARRAY], __classPrivateFieldGet(this, _Rosbag2_messageReaderOptions, "f"));
__classPrivateFieldGet(this, _Rosbag2_messageReaders, "f").set(rawMessage.topic.type, reader);
}
return reader.readMessage(rawMessage.data);
};
this.databases_ = files;
});
__classPrivateFieldSet(this, _Rosbag2_databases, files, "f");
__classPrivateFieldSet(this, _Rosbag2_messageReaderOptions, messageReaderOptions, "f");
}
async open() {
for (const db of this.databases_) {
for (const db of __classPrivateFieldGet(this, _Rosbag2_databases, "f")) {
await db.open();

@@ -63,34 +78,23 @@ }

async close() {
if (this.databases_ != undefined) {
for (const db of this.databases_) {
await db.close();
}
for (const db of __classPrivateFieldGet(this, _Rosbag2_databases, "f")) {
await db.close();
}
this.databases_ = [];
__classPrivateFieldSet(this, _Rosbag2_databases, [], "f");
}
async readTopics() {
if (this.databases_ == undefined) {
throw new Error("Cannot read topics before opening rosbag");
}
if (this.databases_.length === 0) {
if (__classPrivateFieldGet(this, _Rosbag2_databases, "f").length === 0) {
return [];
}
const firstDb = this.databases_[0];
const firstDb = __classPrivateFieldGet(this, _Rosbag2_databases, "f")[0];
return await firstDb.readTopics();
}
readMessages(opts = {}) {
if (this.databases_ == undefined) {
throw new Error("Cannot read messages before opening rosbag");
}
if (this.databases_.length === 0) {
if (__classPrivateFieldGet(this, _Rosbag2_databases, "f").length === 0) {
return new MessageIterator_1.MessageIterator([]);
}
const rowIterators = this.databases_.map((db) => db.readMessages(opts));
return new MessageIterator_1.MessageIterator(rowIterators, opts.rawMessages !== true ? this.decodeMessage : undefined);
const rowIterators = __classPrivateFieldGet(this, _Rosbag2_databases, "f").map((db) => db.readMessages(opts));
return new MessageIterator_1.MessageIterator(rowIterators, opts.rawMessages !== true ? __classPrivateFieldGet(this, _Rosbag2_decodeMessage, "f") : undefined);
}
async timeRange() {
if (this.databases_ == undefined) {
throw new Error("Cannot read time range before opening rosbag");
}
if (this.databases_.length === 0) {
if (__classPrivateFieldGet(this, _Rosbag2_databases, "f").length === 0) {
return [

@@ -103,3 +107,3 @@ { sec: 0, nsec: 0 },

let max = { sec: Number.MIN_SAFE_INTEGER, nsec: 0 };
for (const db of this.databases_) {
for (const db of __classPrivateFieldGet(this, _Rosbag2_databases, "f")) {
const [curMin, curMax] = await db.timeRange();

@@ -112,10 +116,7 @@ min = minTime(min, curMin);

async messageCounts() {
if (this.databases_ == undefined) {
throw new Error("Cannot read message counts before opening rosbag");
}
const allCounts = new Map();
if (this.databases_.length === 0) {
if (__classPrivateFieldGet(this, _Rosbag2_databases, "f").length === 0) {
return allCounts;
}
for (const db of this.databases_) {
for (const db of __classPrivateFieldGet(this, _Rosbag2_databases, "f")) {
const counts = await db.messageCounts();

@@ -130,2 +131,3 @@ for (const [topic, count] of counts) {

exports.Rosbag2 = Rosbag2;
_Rosbag2_messageReaders = new WeakMap(), _Rosbag2_databases = new WeakMap(), _Rosbag2_messageReaderOptions = new WeakMap(), _Rosbag2_decodeMessage = new WeakMap();
function minTime(a, b) {

@@ -132,0 +134,0 @@ return (0, rostime_1.isLessThan)(a, b) ? a : b;

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

QosPolicyDurability[QosPolicyDurability["Unknown"] = 3] = "Unknown";
})(QosPolicyDurability = exports.QosPolicyDurability || (exports.QosPolicyDurability = {}));
})(QosPolicyDurability || (exports.QosPolicyDurability = QosPolicyDurability = {}));
var QosPolicyHistory;

@@ -18,3 +18,3 @@ (function (QosPolicyHistory) {

QosPolicyHistory[QosPolicyHistory["Unknown"] = 3] = "Unknown";
})(QosPolicyHistory = exports.QosPolicyHistory || (exports.QosPolicyHistory = {}));
})(QosPolicyHistory || (exports.QosPolicyHistory = QosPolicyHistory = {}));
var QosPolicyLiveliness;

@@ -26,3 +26,3 @@ (function (QosPolicyLiveliness) {

QosPolicyLiveliness[QosPolicyLiveliness["Unknown"] = 4] = "Unknown";
})(QosPolicyLiveliness = exports.QosPolicyLiveliness || (exports.QosPolicyLiveliness = {}));
})(QosPolicyLiveliness || (exports.QosPolicyLiveliness = QosPolicyLiveliness = {}));
var QosPolicyReliability;

@@ -34,3 +34,3 @@ (function (QosPolicyReliability) {

QosPolicyReliability[QosPolicyReliability["Unknown"] = 3] = "Unknown";
})(QosPolicyReliability = exports.QosPolicyReliability || (exports.QosPolicyReliability = {}));
})(QosPolicyReliability || (exports.QosPolicyReliability = QosPolicyReliability = {}));
//# sourceMappingURL=types.js.map

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.parseYaml = void 0;
exports.parseYaml = parseYaml;
const js_yaml_1 = __importDefault(require("js-yaml"));

@@ -43,3 +43,2 @@ // keep most of the original `int` options as is

}
exports.parseYaml = parseYaml;
//# sourceMappingURL=yaml.js.map
{
"name": "@foxglove/rosbag2",
"version": "5.0.1",
"description": "ROS2 (Robot Operating System) bag reader and writer abstract implementation",
"version": "6.0.0",
"description": "ROS 2 (Robot Operating System) bag reader and writer abstract implementation",
"license": "MIT",

@@ -35,4 +35,4 @@ "keywords": [

"build": "tsc -b",
"lint:ci": "eslint --report-unused-disable-directives .",
"lint": "eslint --report-unused-disable-directives --fix .",
"lint:ci": "eslint .",
"lint": "eslint --fix .",
"prepack": "yarn build",

@@ -43,26 +43,20 @@ "prepublishOnly": "yarn lint:ci && yarn test",

"devDependencies": {
"@foxglove/eslint-plugin": "0.21.0",
"@types/jest": "^29.4.0",
"@types/js-yaml": "^4.0.5",
"@typescript-eslint/eslint-plugin": "5.54.0",
"@typescript-eslint/parser": "5.54.0",
"eslint": "8.35.0",
"eslint-config-prettier": "8.6.0",
"eslint-plugin-es": "4.1.0",
"eslint-plugin-filenames": "1.3.2",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jest": "27.2.1",
"eslint-plugin-prettier": "4.2.1",
"jest": "29.4.3",
"prettier": "2.8.4",
"ts-jest": "29.0.5",
"typescript": "4.9.5"
"@foxglove/eslint-plugin": "2.0.0",
"@types/jest": "29.5.14",
"@types/js-yaml": "4.0.9",
"eslint": "9.16.0",
"jest": "29.7.0",
"prettier": "3.4.2",
"ts-jest": "29.2.5",
"typescript": "5.7.2",
"typescript-eslint": "8.17.0"
},
"dependencies": {
"@foxglove/rosmsg-msgs-common": "^3.0.0",
"@foxglove/rosmsg2-serialization": "^2.0.0",
"@foxglove/rosmsg-msgs-common": "^3.2.1",
"@foxglove/rosmsg2-serialization": "^3.0.0",
"@foxglove/rostime": "^1.1.2",
"@foxglove/schemas": "^1.3.1",
"@foxglove/schemas": "^1.6.5",
"js-yaml": "^4.1.0"
}
}
},
"packageManager": "yarn@4.5.3"
}

@@ -25,2 +25,2 @@ # @foxglove/rosbag2

Join our [Slack channel](https://foxglove.dev/join-slack) to ask questions, share feedback, and stay up to date on what our team is working on.
Join our [Slack channel](https://foxglove.dev/slack) to ask questions, share feedback, and stay up to date on what our team is working on.

@@ -10,6 +10,8 @@ import type { Message, RawMessage } from "./types";

export class MessageIterator implements AsyncIterableIterator<Message> {
// eslint-disable-next-line @foxglove/prefer-hash-private
private rowIterators: AsyncIterableIterator<RawMessage>[];
// eslint-disable-next-line @foxglove/prefer-hash-private
private decoder?: MessageDecoder;
constructor(rowIterators: AsyncIterableIterator<RawMessage>[], decoder?: MessageDecoder) {
public constructor(rowIterators: AsyncIterableIterator<RawMessage>[], decoder?: MessageDecoder) {
this.rowIterators = rowIterators;

@@ -19,7 +21,7 @@ this.decoder = decoder;

[Symbol.asyncIterator](): AsyncIterableIterator<Message> {
public [Symbol.asyncIterator](): AsyncIterableIterator<Message> {
return this;
}
async next(): Promise<IteratorResult<Message>> {
public async next(): Promise<IteratorResult<Message>> {
while (this.rowIterators.length > 0) {

@@ -26,0 +28,0 @@ const front = this.rowIterators[0]!;

@@ -53,2 +53,3 @@ import { Duration, Time, areEqual as areTimesEqual } from "@foxglove/rostime";

for (const entryMaybe of array) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (entryMaybe == undefined) {

@@ -91,4 +92,4 @@ continue;

: typeof value === "bigint" || typeof value === "number"
? Boolean(value)
: undefined;
? Boolean(value)
: undefined;
}

@@ -95,0 +96,0 @@

@@ -12,6 +12,11 @@ import { fromNanoSec } from "@foxglove/rostime";

export class RawMessageIterator implements AsyncIterableIterator<RawMessage> {
// eslint-disable-next-line @foxglove/prefer-hash-private
private dbIterator: IterableIterator<MessageRow>;
// eslint-disable-next-line @foxglove/prefer-hash-private
private topicsMap: Map<bigint, TopicDefinition>;
constructor(dbIterator: IterableIterator<MessageRow>, topicsMap: Map<bigint, TopicDefinition>) {
public constructor(
dbIterator: IterableIterator<MessageRow>,
topicsMap: Map<bigint, TopicDefinition>,
) {
this.dbIterator = dbIterator;

@@ -21,7 +26,7 @@ this.topicsMap = topicsMap;

[Symbol.asyncIterator](): AsyncIterableIterator<RawMessage> {
public [Symbol.asyncIterator](): AsyncIterableIterator<RawMessage> {
return this;
}
async next(): Promise<IteratorResult<RawMessage>> {
public async next(): Promise<IteratorResult<RawMessage>> {
const res = this.dbIterator.next();

@@ -28,0 +33,0 @@ if (res.done === true) {

import type { MessageDefinition } from "@foxglove/message-definition";
import { ros2galactic } from "@foxglove/rosmsg-msgs-common";
import { MessageReader } from "@foxglove/rosmsg2-serialization";
import { MessageReader, MessageReaderOptions } from "@foxglove/rosmsg2-serialization";
import { Time, isLessThan as isTimeLessThan } from "@foxglove/rostime";

@@ -44,11 +44,13 @@ import { foxgloveMessageSchemas, generateRosMsgDefinition } from "@foxglove/schemas/internal";

export class Rosbag2 {
private messageReaders_ = new Map<string, MessageReader>();
private databases_: SqliteDb[];
#messageReaders = new Map<string, MessageReader>();
#databases: SqliteDb[];
#messageReaderOptions?: MessageReaderOptions;
constructor(files: SqliteDb[]) {
this.databases_ = files;
public constructor(files: SqliteDb[], messageReaderOptions?: MessageReaderOptions) {
this.#databases = files;
this.#messageReaderOptions = messageReaderOptions;
}
async open(): Promise<void> {
for (const db of this.databases_) {
public async open(): Promise<void> {
for (const db of this.#databases) {
await db.open();

@@ -58,46 +60,32 @@ }

async close(): Promise<void> {
if (this.databases_ != undefined) {
for (const db of this.databases_) {
await db.close();
}
public async close(): Promise<void> {
for (const db of this.#databases) {
await db.close();
}
this.databases_ = [];
this.#databases = [];
}
async readTopics(): Promise<TopicDefinition[]> {
if (this.databases_ == undefined) {
throw new Error("Cannot read topics before opening rosbag");
}
if (this.databases_.length === 0) {
public async readTopics(): Promise<TopicDefinition[]> {
if (this.#databases.length === 0) {
return [];
}
const firstDb = this.databases_[0]!;
const firstDb = this.#databases[0]!;
return await firstDb.readTopics();
}
readMessages(opts: MessageReadOptions = {}): AsyncIterableIterator<Message> {
if (this.databases_ == undefined) {
throw new Error("Cannot read messages before opening rosbag");
}
if (this.databases_.length === 0) {
public readMessages(opts: MessageReadOptions = {}): AsyncIterableIterator<Message> {
if (this.#databases.length === 0) {
return new MessageIterator([]);
}
const rowIterators = this.databases_.map((db) => db.readMessages(opts));
const rowIterators = this.#databases.map((db) => db.readMessages(opts));
return new MessageIterator(
rowIterators,
opts.rawMessages !== true ? this.decodeMessage : undefined,
opts.rawMessages !== true ? this.#decodeMessage : undefined,
);
}
async timeRange(): Promise<[min: Time, max: Time]> {
if (this.databases_ == undefined) {
throw new Error("Cannot read time range before opening rosbag");
}
if (this.databases_.length === 0) {
public async timeRange(): Promise<[min: Time, max: Time]> {
if (this.#databases.length === 0) {
return [

@@ -111,3 +99,3 @@ { sec: 0, nsec: 0 },

let max = { sec: Number.MIN_SAFE_INTEGER, nsec: 0 };
for (const db of this.databases_) {
for (const db of this.#databases) {
const [curMin, curMax] = await db.timeRange();

@@ -120,13 +108,9 @@ min = minTime(min, curMin);

async messageCounts(): Promise<Map<string, number>> {
if (this.databases_ == undefined) {
throw new Error("Cannot read message counts before opening rosbag");
}
public async messageCounts(): Promise<Map<string, number>> {
const allCounts = new Map<string, number>();
if (this.databases_.length === 0) {
if (this.#databases.length === 0) {
return allCounts;
}
for (const db of this.databases_) {
for (const db of this.#databases) {
const counts = await db.messageCounts();

@@ -140,5 +124,5 @@ for (const [topic, count] of counts) {

private decodeMessage = (rawMessage: RawMessage): unknown => {
#decodeMessage = (rawMessage: RawMessage): unknown => {
// Find or create a message reader for this message
let reader = this.messageReaders_.get(rawMessage.topic.type);
let reader = this.#messageReaders.get(rawMessage.topic.type);
if (reader == undefined) {

@@ -149,4 +133,4 @@ const msgdef = ROS2_TO_DEFINITIONS.get(rawMessage.topic.type);

}
reader = new MessageReader([msgdef, ...ROS2_DEFINITIONS_ARRAY]);
this.messageReaders_.set(rawMessage.topic.type, reader);
reader = new MessageReader([msgdef, ...ROS2_DEFINITIONS_ARRAY], this.#messageReaderOptions);
this.#messageReaders.set(rawMessage.topic.type, reader);
}

@@ -153,0 +137,0 @@

@@ -62,2 +62,3 @@ import { Duration, Time } from "@foxglove/rostime";

type: string;
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
serializationFormat: "cdr" | string;

@@ -64,0 +65,0 @@ offeredQosProfiles: QosProfile[];

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet