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

supascriptconsole

v1.0.0

Published

Javascript library for local console logging of Supabase rpc calls (PostgreSQL functions)

Downloads

4

Readme

SupaScriptConsole

Javascript/Typescript library for local (client-side) console logging of Supabase rpc calls (PostgreSQL functions)

Purpose

This library allows you see the console log output from your Supabase / PostgreSQL server functions written in SupaScript. (SupaScript is a JavaScript-based, NodeJS-like, Deno-inspired set of extensions for Supabase & PostgreSQL server functions.)

Example

Here's a screen shot of the Google Chrome Console showing console logging for a function running in a Supabase PostgreSQL instance:

Chrome Debugger

And you can drill down on the "details" object to get complete details on the log item:

Details Drill-down

Install

npm install https://github.com/burggraf/SupaScriptConsole.git --save

Usage

To use it, just call the startLogging() function and pass it an object. The object can either contain a reference to a Supabase object you've already opened with the supabase.js library, or it can contain url and (anon) key strings. (See both examples below)

Import the library at the top of your module:

import { startLogging } from 'supascriptconsole';

Now just call it in your code (usually in a constructor or other startup code):

Option 1: call it with your Supabase url and public (anonymous) key:

startLogging({url: 'https://xxxxxxxxxxxxxxxxxxxx.supabase.co', key:'yyyyyyyyyyyyyyyyyyyyyyyyyyy'});

Option 2: call it with your Supabase object:

import { createClient, SupabaseClient } from '@supabase/supabase-js';
// then
supabase = createClient(myUrl, myKey);
// start logging using the supabase object (which you'll probably use later to call your .rpc functions!
startLogging({supabase: this.supabase});
// Let's call a server function so we can see some pretty console output in our browser console!
const { data, error } = await this.supabase.rpc('test_console');

To stop logging, just assign the output to a variable then call unsubscribe() on that variable later.

this.subscription = startLogging({supabase: this.supabase});
// later
this.subscription.unsubscribe();

How to add logging to your SupaScript functions

See the SupaScript Console Docs

Logging types supported

In your SupaScript functions, you can use:

console.log();
console.info();
console.warn();
console.error();
console.assert();
console.time();
console.timeEnd()

SupaScript (server side) complete example

create or replace function test_console() returns text as $$
  console.time('test-my-function');
  console.log('logged to the console at:', new Date());
  for (let x = 0; x < 100000; x++) {
    const busyWork = 'this is loop #' + x.toString();
  }
  console.log('strings', 12345, {'object': {'with': 'nested', 'items': [1, 2, 3, 'Go!']}});
  console.info('shows up in green');
  console.warn('shows up in yellow');
  console.error('shows up in red');
  console.assert(false, 'only logs if the first parameter evaluates to false');

  console.timeEnd('test-my-function'); // profiling FTW!
  return 'ok';
$$ language plv8;

Call the server function in your client code

const { data, error } = await this.supabase
.rpc('test_console');

Now you can call the function from your client code and view the console debug messages right in your browser while testing your app!