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

@naturalcycles/airtable-lib

v3.0.1

Published

High-level API and CLI for Airtable

Downloads

733

Readme

@naturalcycles/airtable-lib

High-level API and CLI for Airtable.

npm code style: prettier

Features

  • Allows high level API access to Airtable contents
  • Allows to download Airtable data to json (backup), upload it back with all links and order preserved (not trivial if using stock low-level api)
  • Allows optional validation and transformation (mostly stripping and setting defaults) of data via Joi schemas.

API

  • AirtableLib: high-level access object
    • fetchBase ...
  • AirtableDao: access object for Airtable Table
  • AirtableCache: indexed contents of Airtable Base (indexed by airtableId)

Concept

Entities

Entities are preferrably named without "Airtable" in their name, e.g Coupon, not AirtableCoupon.

Entities extend AirtableRecord to have airtableId required property. Idea is to not strip it unless absolutely needed. Currently airtable-lib doesn't do any stripping. Keeping airtableId is useful to be able to resolve links in runtime. AirtableCache always keeps and index of all records of Base by airtableId. airtableId is unique within your Base (not just within Table), that's why index is built as airtableId > record, not airtableId > Table > record.

Linking

Any linked field in Airtable creates link in both directions (between 2 tables). Convention is to "hide" one link (typically "back-link") in Airtable UI to indicate that it's not used (if it's indeed not used and stripped from data by joi schema).

There was an idea to have a "resolve step" when downloading Airtable Base as json, to be able to replace airtableIds in links to whole objects. The problem there is that it creates a circular dependency in javascript which is a very bad thing (e.g you cannot console.log such object, or send it over the wire). Decision was made to NOT have a resolve step but instead have a AirtableCache with the index of all base records (from airtableId to Record), so it's possible to quickly resolve links in runtime. This is a design decision.

Backup / restore

Backing up Airtable base to json file stores all airtableIds that are used to resolve links.

When restoring from json to Airtable Base airtableIds cannot be preserved, that's Airtable limitation, it needs to generate an airtableId every time an "insert" is made. Restore still works though, with some extra logic. It relies on existing links in json file, builds a map from "oldAirtableId" to "newlyGeneratedAirtableId" and this way preserves the linking. Next time backup to json is made from Airtable base - airtableIds will be different (non-deterministic), something to be aware of.

Backing up (as per current Airtable API) does not preserve order of rows. Restoring from json - does preserve order (but requires to upload records sequentially one-by-one, which is slower than concurrent uploading). To overcome this limitation it's recommended to specify "sort order" in AirtableTableSchema, which allows order to be deterministic. Same order needs to be applied in the UI, to be consistent between UI and json export.

Packaging

  • engines.node >= 10.13: Latest Node.js LTS
  • main: dist/index.js: commonjs, es2018
  • types: dist/index.d.ts: typescript types
  • /src folder with source *.ts files included