npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tse-data-classes

v1.0.3

Published

Classes to normalize and work with ThoughtSpot data payloads.

Readme

Data Classes

Overview

The data classes in src/tse-data-classes.ts wrap the ThoughtSpot payloads so you can treat every payload as tabular data with column metadata, normalized rows, and helper methods to inspect the data. TabularData is the shared base class: it keeps the original payload, lets you set and look up column names (with case-insensitive matching), exposes row/column counts, and provides getDataAsTable() plus populateDataByRow() and populateDataByColumn() so downstream UI code can treat every payload the same way.

Tested Versions

These classes have been tested against ThoughtSpot 10.15.

Installation

Install the published package from npm and use it in your project:

npm install tse-data-classes

The package exports the same classes described below from the default entry point so you can import { TabularData, ActionData } from "tse-data-classes";.

Development

Clone the repository, install the dev dependencies, and build the distributable before publishing or linking:

npm install
npm run build

npm run build emits CommonJS modules plus .d.ts declarations into the dist directory, which is the only directory published to npm.

Each subclass handles one of the payload shapes that ThoughtSpot emits (actions, context menus, liveboards, search results, Spotter responses, etc.). Every class exposes a static createFromJSON(...) factory that normalizes the payload into the tabular structure described above.

Using the Factory Methods

Generic Factory (Recommended)

If you don't know which payload type you're receiving, use the generic factory method on TabularData. It automatically detects the payload structure and returns the appropriate data class instance:

import { TabularData, DataClassType } from "tse-data-classes";

// Auto-detect the payload type
const data = TabularData.createFromJSON(payload);
const rows = data.getDataAsTable();

For cases where auto-detection might be ambiguous (e.g., distinguishing between SpotterData and ActionData), you can provide an explicit type hint:

// Explicit type hint
const spotterData = TabularData.createFromJSON(payload, DataClassType.SpotterData);

The DataClassType enum includes: ActionData, ContextActionData, VizPointClickData, LiveboardActionData, LiveboardData, SearchData, AnswerData, and SpotterData.

Type-Specific Factories

Alternatively, call the factory method that corresponds to the payload you receive from ThoughtSpot. The factories read the embedded column metadata, reorder the values to match the column names, and populate the base TabularData so you can immediately call methods like columnNames, nbrRows, getDataAsTable(), or hasColumn().

Example:

const actionData = ActionData.createFromJSON(payload);
const rows = actionData.getDataAsTable();

The classes and their typical sources are:

  • ActionData.createFromJSON(payload) — menu actions on answers (including visualizations in pinboards) or EventType.Data. Use this for primary actions that return embedded answer data.
  • ContextActionData.createFromJSON(payload) — context menu actions or clicks on selected points. Each selected attribute/measure becomes a column.
  • VizPointClickData.createFromJSON(payload) — visualization point click events. This class stores click metadata (vizId, clickType, status), the embedAnswerData payload, and the tabular columns that describe the clicked/selected points.
  • LiveboardActionData.createFromJSON(payload) — liveboard menu actions. It creates a VizData instance for every visualization container found in the pinboard details.
  • LiveboardData.createFromJSON(payload) — response from the liveboard data API. Each visualization from the API becomes a VizData entry with its own columns and rows.
  • SearchData.createFromJSON(payload) — search results (Search Data API and fetchAnswerData calls). The columns and rows are pulled straight from contents[0].
  • AnswerData.createFromJSON(payload)payload.answerService.fetchData(...) calls. Functionally the same as SearchData but emitted in the answer API shape.
  • SpotterData.createFromJSON(payload) — Spotter API responses. Spotter returns a slightly different embed answer structure, but the factory extracts the columns and values into the same tabular format.

TabularData also exposes utilities such as getOriginalColumnName() and hasColumn() that make it easier to search for columns in a case-insensitive way once the factory has normalized the payload.

TabularData Public API

Every factory returns a TabularData subclass instance with the following public getters and helpers:

  • columnNames — returns the normalized column names so you can build consistent headers or iterate columns in the original order.
  • nbrColumns — reports how many columns were detected in the payload.
  • nbrRows — reports how many rows are stored in the instance.
  • getOriginalColumnName(columnName) — performs a case-insensitive lookup to return the properly cased column name when it exists.
  • hasColumn(columnName) — checks for the presence of a column (case-insensitive).
  • getDataAsTable(columnNames?) — returns the data as an array of rows for the requested columns (all columns when omitted).

Use the public API to inspect an action payload:

const actionData = ActionData.createFromJSON(payload);
console.log("Columns:", actionData.columnNames);
console.log("Row count:", actionData.nbrRows);

if (actionData.hasColumn("Status")) {
  const table = actionData.getDataAsTable();
  const firstRow = table[0];
  console.log("First status value:", firstRow["Status"]);
}

Helper Methods

  • sortObjects(array, attr) — sorts an array of objects in place by the attr key. Useful when you need deterministic ordering before rendering.

  • tabularDataToHTML(tabularData) — renders any TabularData subclass as an HTML table (<table> with header and body rows) using the configured CSS classes (tabular-data, tabular-data-th, etc.).

  • tabularDataToCSV(tabularData) — produces a CSV string (prefixed with data:text/csv) by quoting and escaping all values from getDataAsTable().

    const actionData = ActionData.createFromJSON(payload);
    const csv = tabularDataToCSV(actionData);
    console.log(csv);

These helpers ensure any of the data class instances can be exported or displayed consistently.