[airtable] new package - airtable npm module (Airtable JS API) (#34119)

* [airtable] initialized airtable module and basic types

* [airtable] added FieldSet interface for constraining shape of Rows

* [airtable] using export =, other types in namespace, all in global
This commit is contained in:
Brandon Valosek
2019-03-26 17:21:20 +01:00
committed by timolinn
parent d6692403c7
commit 99d47b8f6e
4 changed files with 129 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
import * as Airtable from 'airtable';
interface Row extends Airtable.FieldSet {
field1: string;
attachments: Airtable.Attachment[];
}
const airtable = new Airtable();
const base = airtable.base('app id');
const table = base('table name') as Airtable.Table<Row>;
async () => {
const query = table.select();
{
const rows = await query.all();
for (const row of rows) {
row.id; // $ExpectType string
row.fields.field1; // $ExpectType string
for (const attachment of row.fields.attachments) {
attachment.id; // $ExpectType string
attachment.filename; // $ExpectType string
attachment.size; // $ExpectType number
attachment.type; // $ExpectType string
attachment.url; // $ExpectType string
if (attachment.thumbnails) {
attachment.thumbnails.full.height; // $ExpectType number
attachment.thumbnails.full.width; // $ExpectType number
attachment.thumbnails.full.url; // $ExpectType string
attachment.thumbnails.large.height; // $ExpectType number
attachment.thumbnails.large.width; // $ExpectType number
attachment.thumbnails.large.url; // $ExpectType string
attachment.thumbnails.small.height; // $ExpectType number
attachment.thumbnails.small.width; // $ExpectType number
attachment.thumbnails.small.url; // $ExpectType string
}
}
}
}
};
+62
View File
@@ -0,0 +1,62 @@
// Type definitions for airtable 0.5
// Project: https://github.com/airtable/airtable.js
// Definitions by: Brandon Valosek <https://github.com/bvalosek>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
export = Airtable;
declare global {
class Airtable {
base(appId: string): Airtable.Base;
}
namespace Airtable {
interface FieldSet {
[ key: string ]: undefined | string | ReadonlyArray<Attachment>;
}
interface Base {
(tableName: string): Table<{}>;
}
interface Table<TFields extends FieldSet> {
select(opt?: SelectOptions): Query<TFields>;
}
interface SelectOptions {
view?: string;
}
interface Query<TFields extends object> {
all(): Promise<Response<TFields>>;
firstPage(): Promise<Response<TFields>>;
}
type Response<TFields> = ReadonlyArray<Row<TFields>>;
interface Row<TFields> {
id: string;
fields: TFields;
}
interface Attachment {
id: string;
url: string;
filename: string;
size: number;
type: string;
thumbnails?: {
small: Thumbnail;
large: Thumbnail;
full: Thumbnail;
};
}
interface Thumbnail {
url: string;
width: number;
height: number;
}
}
}
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"airtable-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }