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

@bnjmnt4n/supabase-client

v0.0.1

Published

An alternative Supabase client.

Downloads

2

Readme

supabase-client

An alternative TypeScript-based Supabase client.

This package is an alternative to the official @supabase/supabase-js client, with the intention of experiment with better TypeScript type definitions. In the future, this package might also contain other experiments such as a more tree-shaking-friendly API, and other UX/DX improvements, with the hope that they might eventually be upstreamed into @supabase/supabase-js v2.

Features

  • Use of template literals types to construct return type definitions of your queries, without having to manually specify them:

    // Before:
    // Instead of having to specify the query and the definition:
    
    type WorkspaceWithTeam =
      definition["workspaces"] & {
        team: {
          user: Pick<definition["users"], "id" | "email">;
        };
      };
    
    supabase
      .from<WorkspaceWithTeam>("workspaces")
      .select(`
        *,
        team:members(
          user:users(
            id,
            email
          )
        )
      `);
    
    // After:
    // Just specify the query once!
    supabase
      .from("workspaces")
      .select(`
        *,
        team:members(
          user:users(
            id,
            email
          )
        )
      `);
  • Type-checking of your select(query) format

  • IntelliSense suggestions of fields in filter conditions:

    supabase
      .from("workspaces")
      .select(`
        name,
        id,
        team:members(
          user:users(
            id,
            email
          )
        )
      `)
      .filter("|", "eq", X);
      // Provides auto-complete suggestions of "name" | "id" | "team.user.id" | "team.user.email"

Usage

Install using npm or yarn:

npm i @supabase/supabase-js 
npm i --D @bnjmnt4n/supbase-client

For now, this package only provides alternative types for the @supabase/supabase-js client. TypeScript v4.5.0+ is required.

import { createClient } from "@supabase/supabase-js";
import { type SupabaseClient } from "@bnjmnt4n/supabase-client";

// Type-definitions for each table in your schema. See 
import { definitions } from "lib/__generated__/supabase.ts";

const supabase = createClient(SUPABASE_URL, SUPABASE_KEY, OPTIONS)
  as unknown as SupabaseClient<definitions>;

const { data, error } = await supabase
  .from("users")
  .select(`
    email,
    name,
    products(
      id,
      name
    )
  `)
  .maybeSingle();

if (data) {
  data.name;
  data.email;

  if ("length" in data.products) {
    // Array of products.
    data.products[0].id;
  } else {
    // Single products.
    data.products.id;
  }
}

Bugs/Issues?

If there are any issues with the types, you can simply cast the client back to the original type definitions:

import { type SupabaseClient } from "@supabase/supabase-js";

(supabase as unknown as SupabaseClient).from("").select();

Do report any bugs though!