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

@tremor/tinybird-utils

Package Overview
Dependencies
Maintainers
3
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tremor/tinybird-utils

Utilities to fetch data from Tinybird.

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
3
Weekly downloads
 
Created
Source

Tremor Tinybird Plugin

npm i tinybird-utils

API

The plugin exports a useFetchPipe function that provides a single interface to easily query Tinybird pipes using SWR.

Arguments:

  • name: The name of the Tinybird pipe.
  • queryParams (optional): The query parameters of the pipe as a JSON-object.
  • config (optional): The Tinybird configuration as a JSON-object.
  • responseType (optional): The API response type. 'JSON' | 'CSV' | 'Ndjson' | 'Parquet'

Example:

// Example.tsx
import { useFetchPipe } from 'tinybird-utils';
import { LineChart } from '@tremor/react';

export default function Example() {
  const { data, status } = useFetchPipe('my_sales_data_pipe', {
    date_from: '2023-01-01',
    date_to: '2023-03-01'
  });

  return status === 'loading' ? (
    <p>Loading...</p>
  ) : (
    <LineChart data={data} index="date" categories={['sales', 'profit']} />
  );
}

Configuration

Configuration parameters:

  • token: The Tinybird auth token
  • baseUrl (optional): The Tinybird API base url, i.e. the tinybird pipe prefix up to the pipe name. Default: https://api.tinybird.co/v0/pipes/

(1) Using the TbConfigProvider:

// ContextProvider.tsx
import { TbConfigProvider } from 'tinybird-utils';

export default function ContextProvider({ children }) {
  const token = '<my tinybird auth token>';
  const baseUrl = 'https://ui.us-east.tinybird.co/v0/pipes/';

  return (
    <TbConfigProvider
      token={token}
      // Optional
      baseUrl={baseUrl}>
      {children}
    </TbConfigProvider>
  );
}

The config values can be set in one of the TbConfigProviders child components using the TbConfigContext and the provided setters:

// Example.tsx
import { TbConfigContext } from 'tinybird-utils';
import { useContext } from 'react';

...
const { setToken, setBaseUrl } = useContext(TbConfigContext);
...

Once the config parameters are set in the TbConfigProvider, the useFetchPipe function will automatically obtain the config from the TbConfigContext.

(2) Directly providing a config via the config argument of the useFetchPipe as a JSON-object.

const { data } = useFetchPipe(
  'my_pipe',
  {
    date_from: '2023-01-01',
    date_to: '2023-03-01'
  },
  {
    token: '<my tinybird token>',
    // Optional
    baseUrl: 'https://api.us-east.tinybird.co/v0/pipes/'
  }
);

FAQs

Package last updated on 05 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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