airtable-dnd v0.3.1

Install
Install airtable-dnd using npm or yarn
# install using npm
npm install airtable-dnd
# install using yarn
yarn add airtable-dnd⚠ Important note: airtable-dnd internally uses fetch and assumes it exists ⚠
If you're on an environment that already has fetch (Next.js runtimes, browsers, etc.), airtable-dnd will use that.
If you're on an environment that does not have fetch, refer to the "Polyfilling fetch" section on how to implement or bring your own fetch.
Comparison
airtable-dnd vs. Deno version
- Accepts custom
fetchon instantiation options (see "Polyfillingfetch") - Instance options are exposed unlike
airtable-denowhere it's using private identifiers (#options)
airtable-dnd vs. first-party Node.js version
- Does not ship with
fetchimplementation (see "Polyfillingfetch") - First-class support for generic field types with extra field types (
Collaborators,MultipleSelect<T>, etc.) - Single object instance (
new Airtable()instead ofnew Airtable().base()().select()...)
Basic examples
Instantiate Airtable client
import { Airtable } from "airtable-dnd";
const airtable = new Airtable({
apiKey: "keyXXXXXXXXXXXXXX",
baseId: "appXXXXXXXXXXXXXX",
tableName: "Some table name",
});Select record(s)
const results = await airtable.select();Creating record(s)
const createOne = await airtable.create({
Name: "Griko Nibras",
Age: 25,
});
import { Field } from "airtable-dnd";
type Fields = {
Name: string;
Age: number;
Active?: Field.Checkbox;
};
const createMultiple = await airtable.create<Fields>(
[
{ Name: "Foo", Age: 20 },
{ Name: "Bar", Age: 15 },
],
{ typecast: true },
);Updating record(s)
const updateOne = await airtable.update<Fields>("recXXXXXXXXXXXXXX", {
Name: "Adult boi",
Age: 30,
});
const updateMultiple = await airtable.update<Fields>(
[
{
id: "recXXXXXXXXXXXXXX",
fields: { Name: "Adult boi", Age: 30 },
},
{
id: "recXXXXXXXXXXXXXX",
fields: { Name: "Yung boi", Age: 15 },
},
],
{ typecast: true },
);Delete record(s)
const deleteOne = await airtable.delete("recXXXXXXXXXXXXXX");
const deleteMultiple = await airtable.delete([
"recXXXXXXXXXXXXXX",
"recXXXXXXXXXXXXXX",
]);Advanced examples
For advanced examples, refer to the airtable-deno examples file.
Polyfilling fetch
Since Node.js does not have built-in fetch implementation unlike Deno, airtable-dnd has two ways to implement/polyfill fetch.
Polyfill methods
Pass
fetchcompliant object to client instantiationairtable-dndhascross-fetchas a peer dependency for polyfilling, but you can use otherfetchcompliant packages (node-fetch,whatwg-fetch,isomorphic-fetch, etc.), you can import and pass thefetchobject on client instantiation.import fetch from "node-fetch"; const airtable = new Airtable({ fetch, });Polyfill
fetchgloballyAlternatively, you can do a global polyfill with
cross-fetch/polyfillor otherfetchcompliant packages that supports global polyfilling before instantiating or calling the Airtable client.import "cross-fetch/polyfill"; const airtable = new Airtable({ // no need to pass `fetch` since it's polyfilled globally });
Polyfill prioritization
By default, airtable-dnd will use the fetch object passed from the instantiation option, then fallbacks to the global fetch object.
Further reading
All options, parameters, errors, and responses are the same as on the Airtable API documentation.
Dependencies
cross-fetch: https://github.com/lquixada/cross-fetch
License
MIT License Copyright (c) 2020 Griko Nibras
dnd = deno to node :p