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

airtable-schema-gen

v2.0.4

Published

A CLI tool to generate Zod schemas from Airtable records

Downloads

77

Readme

Airtable to Zod Code Generator

An Airtable to Zod Code Generator that generates zod schemas for Airtable records.

We also ship an accessor to handle Airtable's JS SDK.

Usage

npx airtable-schema-gen

CLI Options

--version              Show version number                       [boolean]
--api-key              Your Airtable api key. Reads AIRTABLE_API_KEY in en
                       vironment. (required)                      [string]
--base-id              Your Airtable base id. Reads AIRTABLE_BASE_ID in en
                       vironment. (required)                      [string]
--base-name            Your Airtable base name. Used for the accessor. Rea
                       ds AIRTABLE_BASE_NAME in environment. (optional: de
                       faults to 'default')                       [string]
--table-ids            Space separated list of Airtable table IDs to inclu
                       de (optional).                              [array]
--out-dir              Output directory. (optional: defaults to 'out')
                                                                  [string]
--schema-out-dir       Output directory for the schemas file.     [string]
--accessor-out-dir     Output directory for the accessor file.    [string]
-v, --verbose              Enable verbose logging.  [boolean] [default: false]
-h, --help                 Show help                                 [boolean]

Example

import Airtable from "airtable"
import { defaultBaseAccessor } from "./defaultBase.accessor"
import * as defaultSchemas from "./defaultBase.schemas"

const apiKey = process.env.AIRTABLE_API_KEY!

Airtable.configure({
  apiKey,
  endpointUrl: "https://api.airtable.com",
})

// You can export this from here or create an airtable object,
// add this as a key, and export the airtable object instead.
export const defaultBase = {
  ...defaultSchemas,
  base: Airtable.base(defaultBaseAccessor.id)
  tables: defaultTables,
}

Then somewhere else:

import { defaultBase } from "./wherever-you-keep-this"

const { base, tables, exampleRecordSchema } = defaultBase

const exampleData = await base(tables.example.id)
  .select()
  .then((records) =>
    records.map((record) => {
      const result = exampleRecordSchema.parse(record.fields)
      // add the id to the schema if you want
      return { ...result, id: record.id }
      // otherwise return the result
      return result
    }),
  )