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

savvytable

v1.1.7

Published

Use the SeaTable API in NodeJS

Downloads

317

Readme

savvytable

Installing

npm install savvytable

About

  • Use the SeaTable API in your NodeJS project
  • Typesafe with zod
  • Extend your row schemas with zod

Examples

Base: Initialization

import { Base } from 'savvytable';

const base = new Base({
  url: 'https://table.example.com'.
  token: '<TOKEN>'
});

Base: Authentication

await base.auth();

Query Schema

import { QueryResult, QueryTypes, AsType } from 'savvytable';

const EmployeeRowSchema = QueryResult({
  ID: QueryTypes.AutoNumber,
  Nr: QueryTypes.Number,
  Name: QueryTypes.Text,
  Employee: QueryTypes.Collaborator,
  Worktime: QueryTypes.Link,
});

type EmployeeRow = AsType<typeof EmployeeRowSchema>;

Base: Query

const result: EmployeeRow[] = await base.query({
  query: 'SELECT * FROM Employee',
  rowSchema: EmployeeRowSchema,
});

Table: Initialization

const table = base.Table({
  name: 'Employee',
});

Row Schema

import { Row, RowTypes, AsType } from 'savvytable';

const EmployeeRowSchema = Row({
  _id: RowTypes._Id,
  ID: RowTypes.AutoNumber,
  Nr: Optional(RowTypes.Number),
  Name: Optional(RowTypes.Text),
  Employee: Optional(RowTypes.Collaborator),
  Worktime: Optional(RowTypes.Link),
});

type EmployeeRow = AsType<typeof EmployeeRowSchema>;

Table: Get Row

const result: EmployeeRow = await table.getRow({
  rowId: 'VV_vVwlESmWZ86ANOIt1fQ',
  rowSchema: EmployeeRowSchema,
});

Table: Get Rows

const result: EmployeeRow[] = await table.getRows({
  rowSchema: EmployeeRowSchema,
});

Table: Append Row

const result = await table.addRow({
  row: {
    Name: 'TESTNAME',
  },
});

Table: Insert Row

const result = await table.addRow({
  row: {
    Name: 'TEST_INSERT_ABOVE',
  },
  anchorRowId: 'MNJ3ylTORW631nDJ3OBxeQ',
  rowInsertPosition: 'above',
});

Table: Append Rows

const result = await table.addRows({
  rows: [
    {
      Name: 'ADD_001',
    },
    {
      Name: 'ADD_002',
    },
  ],
});

Table: Update Row

await table.updateRow({
  rowId: 'PsgeZOn5Q7Cm49zZusGjow',
  row: {
    Name: '...',
  },
});

Table: Update Rows

await table.updateRows({
  rows: [
    {
      rowId: 'PsgeZOn5Q7Cm49zZusGjow',
      data: {
        Name: 'UPDATE_ROW_1',
      },
    },
    {
      rowId: 'JEyEg166RvCGl1lsoV-6TQ',
      data: {
        Name: 'UPDATE_ROW_2',
      },
    },
  ],
});

Table: Delete Row

await table.deleteRow({
  rowId: 'GDmShJ84SYaB4KOs_v_Tzw',
});

Table: Delete Rows

await table.deleteRows({
  rowIds: ['L0AJLFTMTamxpjwxR_CNbQ', 'NVGuoFibTESXme8-ySAA9w'],
});

Admin: Initialization

import { Admin } from 'savvytable';

const admin = await Admin.withCredentials({
  url: 'https://table.example.com',
  username: '[email protected]',
  password: '123456',
});

Admin: Get User Info

const result = await admin.getUser({
  userId: '[email protected]',
});

Check Webhook (Express Example)

import { WebhookSchema, Webhook } from 'savvytable';
import express from 'express';

const app = express.app();

app.post('/v1/base-updated/', (req, res) => {
  const parsed = WebhookSchema.safeParse(req.body);

  if (parsed.success) {
    const data: Webhook = parsed.data;
  } else {
    // wrong webhook data
  }
});

Extend Row Schema With Zod

import * as z from 'zod';
import { Row } from 'savvytable';

const EmployeeRowSchema = Row({
  _id: RowTypes._Id,
  ID: z.string().length(4),
  Nr: Optional(RowTypes.Number),
  Name: Optional(RowTypes.Text),
  Employee: Optional(RowTypes.Collaborator),
  Worktime: Optional(z.string().url().startsWith('https://')),
});