High-level API and CLI for Airtable.
- 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.
AirtableLib: high-level access object
AirtableDao: access object for Airtable Table
AirtableCache: indexed contents of Airtable Base (indexed by airtableId)
Entities are preferrably named without "Airtable" in their name, e.g
AirtableRecord to have
airtableId required property. Idea is to not strip it
unless absolutely needed. Currently
airtable-lib doesn't do any stripping. Keeping
useful to be able to resolve links in runtime.
AirtableCache always keeps and index of all records
of Base by
airtableId is unique within your Base (not just within Table), that's why
index is built as
airtableId > record, not
airtableId > Table > record.
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
airtableIds in links to whole objects. The problem there is that it creates a circular
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.
engines.node >= 10.13: Latest Node.js LTS
main: dist/index.js: commonjs, es2018
types: dist/index.d.ts: typescript types
/srcfolder with source