From 99d47b8f6eba059b826b478298d5fa2a528405d3 Mon Sep 17 00:00:00 2001 From: Brandon Valosek Date: Mon, 25 Mar 2019 11:52:00 -0500 Subject: [PATCH] [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 --- types/airtable/airtable-tests.ts | 43 ++++++++++++++++++++++ types/airtable/index.d.ts | 62 ++++++++++++++++++++++++++++++++ types/airtable/tsconfig.json | 23 ++++++++++++ types/airtable/tslint.json | 1 + 4 files changed, 129 insertions(+) create mode 100644 types/airtable/airtable-tests.ts create mode 100644 types/airtable/index.d.ts create mode 100644 types/airtable/tsconfig.json create mode 100644 types/airtable/tslint.json diff --git a/types/airtable/airtable-tests.ts b/types/airtable/airtable-tests.ts new file mode 100644 index 0000000000..7d7dfbdc60 --- /dev/null +++ b/types/airtable/airtable-tests.ts @@ -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; + +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 + } + } + } + } +}; diff --git a/types/airtable/index.d.ts b/types/airtable/index.d.ts new file mode 100644 index 0000000000..f3b6efa4ee --- /dev/null +++ b/types/airtable/index.d.ts @@ -0,0 +1,62 @@ +// Type definitions for airtable 0.5 +// Project: https://github.com/airtable/airtable.js +// Definitions by: Brandon Valosek +// 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; + } + + interface Base { + (tableName: string): Table<{}>; + } + + interface Table { + select(opt?: SelectOptions): Query; + } + + interface SelectOptions { + view?: string; + } + + interface Query { + all(): Promise>; + firstPage(): Promise>; + } + + type Response = ReadonlyArray>; + + interface Row { + 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; + } + } +} diff --git a/types/airtable/tsconfig.json b/types/airtable/tsconfig.json new file mode 100644 index 0000000000..9ec625d762 --- /dev/null +++ b/types/airtable/tsconfig.json @@ -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" + ] +} diff --git a/types/airtable/tslint.json b/types/airtable/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/airtable/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }