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

supabase-ts

v0.2.1

Published

Make request to supabase using the power of fp-ts, io-ts, and parsing.

Downloads

27

Readme

supabase-ts

What happens when the type of the response from a supabase request is different from expected? We don't want our app to crash, do we?

Welcome supabase-ts!

Make request to supabase using the power of fp-ts, io-ts, and parsing.

Use supabase with Functional Programming and fp-ts.

Getting started

npm install supabase-ts

Extend your usual SupabaseClient using createClientIO from supabase-ts.

createClientIO accepts two generic types:

  • A union of string with the names of all the tables/views of your database. supabase-ts will enforce the correct table names, no more typos!
  • The default request error type
import { createClient } from '@supabase/supabase-js';
import { createClientIO } from 'supabase-ts';

// Enforce tables and views names
type SupabaseTable = 'table1' | 'table2';
type SupabaseView = 'view1' | 'view2';

// Define default request error type
type ErrorMessage = string;

const supabaseClient = createClient('URL', 'KEY');
export const supabase = createClientIO<SupabaseTable | SupabaseView, ErrorMessage>(supabaseClient);

Use the exported supabase client to perform requests:

  • requestListWithValidation: Perform a request to supabase and return a list of values.
  • requestSingleWithValidation: Perform a request to supabase and return a single value.

For every request you must provide an io-ts type used to validate the response from supabase. supabase-ts will make sure that the shape of the return data respects the defined schema from io-ts.

const schema = t.type({ name: t.string });
type Schema = t.TypeOf<typeof schema>;
const tableValidated = {
  name: 'table1', // Required to be `string` from `SupabaseTable | SupabaseView`!
  schema,
} as const; // Required to be `const` for type-safety

const responseList: TE.TaskEither<string, readonly Schema[]> =
  supabaseClientIO.requestListWithValidation(tableValidated)(
    (query) => query.select(),
    {
      // Handle all possible errors
      onNoDataError: () => '',
      onRequestError: () => '',
      onValidationError: () => '',
    }
  );

const responseSingle: TE.TaskEither<string, Schema> =
  supabaseClientIO.requestSingleWithValidation(tableValidated)(
    (query) => query.select(),
    {
      // Handle all possible errors
      onZeroData: () => '',
      onNoDataError: () => '',
      onRequestError: () => '',
      onValidationError: () => '',
    }
  );

📃 Versioning

  • v0.2.1 - 27 November 2021
  • v0.1.3 - 24 September 2021
  • v0.1.2 - 18 September 2021
  • v0.1.1 - 17 September 2021
  • v0.1.0 - 17 September 2021

😀 Support

Currently the best way to support me would be to follow me on my Twitter.

Another option (or Option) would be to buy me a coffee.

👀 License

MIT License, see the LICENSE.md file for details.