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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tremor/tinybird-utils

v0.0.1

Published

Utilities to fetch data from Tinybird.

Downloads

4

Readme

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/'
  }
);