### GET /table Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Retrieves the AirtableTsTable object for the given table definition, which includes Airtable schema details. ```APIDOC ## GET /table ### Description Retrieves the AirtableTsTable object for the given table definition. This is the Airtable.js table, enriched with a `fields` key that includes details of the Airtable schema for this table. This is useful for advanced use cases where you need direct access to the Airtable table object. ### Method GET ### Endpoint `/table` ### Parameters #### Path Parameters - **table** (Table) - Required - Table definition object ### Request Example ```ts const airtableTsTable = await db.table(studentTable); // Now you can use the raw Airtable table object with field information console.log(airtableTsTable.fields); // Access the table's field definitions ``` ### Response #### Success Response (200) - **AirtableTsTable** (object) - The AirtableTsTable object with schema details #### Response Example ```json { "id": "tblXXXXXXXXXXXXXX", "name": "Students", "fields": [ { "id": "fldXXXXXXXXXXXXXX", "name": "firstName", "type": "singleLineText" }, { "id": "fldYYYYYYYYYYYYYY", "name": "grade", "type": "number" } ] } ``` ``` -------------------------------- ### AirtableTs Class Reference Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md The AirtableTs class is the main entry point for interacting with your Airtable base. It provides methods to scan, get, update, and delete records, as well as access the raw Airtable JS SDK. ```APIDOC ## Constructor ### Description Creates a new instance of the AirtableTs client. ### Method `new AirtableTs(options: AirtableTsOptions)` ### Parameters #### Request Body - **apiKey** (string) - Required - Your Airtable API key. Create one at https://airtable.com/create/tokens. Recommended scopes: schema.bases:read, data.records:read, data.records:write - **baseSchemaCacheDurationMs** (number) - Optional - Duration in milliseconds to cache base schema (default: 120,000ms = 2 minutes) - Other options from Airtable.js are supported, including: `apiVersion`, `customHeaders`, `endpointUrl`, `noRetryIfRateLimited`, `requestTimeout` ### Request Example ```json { "apiKey": "pat1234.abcdef", "baseSchemaCacheDurationMs": 300000 } ``` ### Response #### Success Response (200) - **AirtableTs** (object) - An instance of the AirtableTs client. #### Response Example ```javascript const db = new AirtableTs({ apiKey: 'pat1234.abcdef', baseSchemaCacheDurationMs: 300000, // 5 minutes }); ``` ``` -------------------------------- ### GET /record Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Retrieves a single record from a table by its ID. ```APIDOC ## GET /record ### Description Retrieves a single record from a table by its ID. ### Method GET ### Endpoint `/record` ### Parameters #### Path Parameters - **table** (Table) - Required - Table definition object - **id** (string) - Required - The ID of the record to retrieve ### Request Example ```ts const student = await db.get(studentTable, 'rec1234'); console.log(student.firstName); // Access fields with type safety ``` ### Response #### Success Response (200) - **T** (object) - The retrieved record #### Response Example ```json { "id": "rec1234", "firstName": "John", "lastName": "Doe" } ``` ``` -------------------------------- ### GET /scan Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Retrieves all records from a table, with optional filtering parameters. ```APIDOC ## GET /scan ### Description Retrieves all records from a table, with optional filtering parameters. ### Method GET ### Endpoint `/scan` ### Parameters #### Path Parameters - **table** (Table) - Required - Table definition object - **params** (ScanParams) - Optional - Parameters for filtering, sorting, and limiting results - **filterByFormula** (string) - Optional - An Airtable formula to filter records. Use `airtable-ts-formula` for type-safe formulae. - **sort** (Array) - Optional - Array of sort objects (e.g., `[{field: 'firstName', direction: 'asc'}]`) - **maxRecords** (number) - Optional - Maximum number of records to return - **view** (string) - Optional - Name of a view to use for record selection - **timeZone** (string) - Optional - Timezone for interpreting date values - **userLocale** (string) - Optional - Locale for formatting date values ### Request Example ```ts // Get all records const allStudents = await db.scan(studentTable); // Get records with filtering and sorting const topStudents = await db.scan(studentTable, { filterByFormula: '{grade} >= 90', sort: [{field: 'grade', direction: 'desc'}], maxRecords: 10 }); ``` ### Response #### Success Response (200) - **T[]** (array) - An array of records from the table #### Response Example ```json [ { "id": "rec1234", "firstName": "John", "grade": 95 }, { "id": "rec5678", "firstName": "Jane", "grade": 92 } ] ``` ``` -------------------------------- ### Get AirtableTsTable Object (TypeScript) Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Retrieves the AirtableTsTable object for a given table definition. This object is the raw Airtable.js table enriched with schema details, useful for advanced operations. ```typescript async table(table: Table): Promise> ``` ```typescript const airtableTsTable = await db.table(studentTable); // Now you can use the raw Airtable table object with field information console.log(airtableTsTable.fields); // Access the table's field definitions ``` -------------------------------- ### Initialize AirtableTs SDK and Define Tables Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Demonstrates how to initialize the AirtableTs client with an API key and define table structures with schemas and mappings. It shows how to fetch, update, and remove records, as well as access the raw Airtable SDK instance. ```typescript import { AirtableTs, Table } from 'airtable-ts'; const db = new AirtableTs({ // Create your own at https://airtable.com/create/tokens // Recommended scopes: schema.bases:read, data.records:read, data.records:write apiKey: 'pat1234.abcdef', }); // Tip: use airtable-ts-codegen to autogenerate these from your Airtable base export const studentTable: Table<{ id: string, firstName: string, classes: string[] }> = { name: 'student', baseId: 'app1234', tableId: 'tbl1234', schema: { firstName: 'string', classes: 'string[]' }, // optional: use mappings with field ids to prevent renamings breaking your app, // or with field names to make handling renamings easy mappings: { firstName: 'fld1234', classes: 'Classes student is enrolled in' }, }; export const classTable: Table<{ id: string, title: string }> = { name: 'class', baseId: 'app1234', tableId: 'tbl4567', schema: { title: 'string' }, }; // Now we can get all the records in a table (a scan) const classes = await db.scan(classTable); // Get, update and delete specific records: const student = await db.get(studentTable, 'rec1234'); await db.update(studentTable, { id: 'rec1234', firstName: 'Adam' }); await db.remove(studentTable, 'rec5678'); // Or for a more involved example: async function prefixTitleOfFirstClassOfFirstStudent(prefix: string) { const students = await db.scan(studentTable); if (!students[0]) throw new Error('There are no students'); if (!students[0].classes[0]) throw new Error('First student does not have a class'); const currentClass = await db.get(classTable, students[0].classes[0]); const newTitle = prefix + currentClass.title; await db.update(classTable, { id: currentClass.id, title: newTitle }); } // And should you ever need it, access to the raw Airtable JS SDK const rawSdk: Airtable = db.airtable; ``` -------------------------------- ### AirtableTs Constructor Options Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Illustrates the various options available when creating a new instance of the AirtableTs client. This includes essential parameters like the API key and optional settings for managing base schema caching and other Airtable.js configurations. ```typescript const db = new AirtableTs({ apiKey: 'pat1234.abcdef', baseSchemaCacheDurationMs: 300000, // 5 minutes }); ``` -------------------------------- ### POST /insert Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Creates a new record in a table and returns the new record. ```APIDOC ## POST /insert ### Description Creates a new record in a table. Returns the new record. ### Method POST ### Endpoint `/insert` ### Parameters #### Path Parameters - **table** (Table) - Required - Table definition object - **data** (Partial>) - Required - The data for the new record (without an ID, as Airtable will generate one) ### Request Example ```ts const newStudent = await db.insert(studentTable, { firstName: 'Jane', classes: ['rec5678', 'rec9012'] }); console.log(newStudent.id); // The new record ID generated by Airtable ``` ### Response #### Success Response (200) - **T** (object) - The newly created record #### Response Example ```json { "id": "recXYZ123", "firstName": "Jane", "classes": ["rec5678", "rec9012"] } ``` ``` -------------------------------- ### Access Raw Airtable.js SDK (TypeScript) Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Provides access to the underlying Airtable.js SDK instance through the `airtable` property of the database object. ```typescript const rawSdk: Airtable = db.airtable; ``` -------------------------------- ### Airtable SDK Access Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Provides access to the underlying Airtable.js SDK. ```APIDOC ## Airtable SDK Access ### Description The underlying Airtable.js SDK is exposed in the `airtable` property. ### Method N/A ### Endpoint N/A ### Request Example ```ts const rawSdk: Airtable = db.airtable; // Use the raw SDK for advanced operations not covered by Airtable-TS ``` ### Response #### Success Response (200) - **Airtable** (object) - The raw Airtable.js SDK instance #### Response Example ```javascript // Example of using the raw SDK (depends on Airtable.js API) // const base = rawSdk.base('your_base_id'); // const table = base.getTable('your_table_name'); // console.log(table); ``` ``` -------------------------------- ### Insert New Record (TypeScript) Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Creates a new record in an Airtable table. Accepts the table definition and the data for the new record. Returns the newly created record, including its generated ID. ```typescript async insert(table: Table, data: Partial>): Promise ``` ```typescript const newStudent = await db.insert(studentTable, { firstName: 'Jane', classes: ['rec5678', 'rec9012'] }); console.log(newStudent.id); // The new record ID generated by Airtable ``` -------------------------------- ### Scan Records with Filtering and Sorting (TypeScript) Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Retrieves multiple records from an Airtable table, supporting optional filtering, sorting, and limiting parameters. Uses ScanParams for configuration. ```typescript async scan(table: Table, params?: ScanParams): Promise ``` ```typescript // Get all records const allStudents = await db.scan(studentTable); // Get records with filtering and sorting const topStudents = await db.scan(studentTable, { filterByFormula: '{grade} >= 90', sort: [{field: 'grade', direction: 'desc'}], maxRecords: 10 }); ``` -------------------------------- ### Table Operations API Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Provides methods to perform CRUD operations on Airtable tables using type-safe definitions. ```APIDOC ## Scan Table ### Description Retrieves all records from a specified table. ### Method `db.scan(table: Table)` ### Parameters #### Request Body - **table** (Table) - Required - An object defining the table structure, including name, baseId, tableId, schema, and optional mappings. ### Request Example ```javascript // Assuming studentTable and classTable are defined as per the example const classes = await db.scan(classTable); ``` ### Response #### Success Response (200) - **Array** - An array of records from the table, where T is the type defined for the table schema. ## Get Record ### Description Retrieves a single record from a specified table by its ID. ### Method `db.get(table: Table, recordId: string)` ### Parameters #### Path Parameters - **table** (Table) - Required - An object defining the table structure. - **recordId** (string) - Required - The unique ID of the record to retrieve. ### Request Example ```javascript const student = await db.get(studentTable, 'rec1234'); ``` ### Response #### Success Response (200) - **T** - The record object matching the table schema. ## Update Record ### Description Updates an existing record in a specified table. ### Method `db.update(table: Table, record: Partial & { id: string })` ### Parameters #### Request Body - **table** (Table) - Required - An object defining the table structure. - **record** (Partial & { id: string }) - Required - An object containing the record ID and the fields to update. ### Request Example ```javascript await db.update(studentTable, { id: 'rec1234', firstName: 'Adam' }); ``` ### Response #### Success Response (200) - **T** - The updated record object. ## Remove Record ### Description Deletes a record from a specified table by its ID. ### Method `db.remove(table: Table, recordId: string)` ### Parameters #### Path Parameters - **table** (Table) - Required - An object defining the table structure. - **recordId** (string) - Required - The unique ID of the record to delete. ### Request Example ```javascript await db.remove(studentTable, 'rec5678'); ``` ### Response #### Success Response (200) - **{ id: string }** - An object containing the ID of the deleted record. ``` -------------------------------- ### PUT /update Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Updates an existing record in a table and returns the updated record. ```APIDOC ## PUT /update ### Description Updates an existing record in a table. Returns the updated record. ### Method PUT ### Endpoint `/update` ### Parameters #### Path Parameters - **table** (Table) - Required - Table definition object - **data** (Partial & { id: string }) - Required - The data to update, must include the record ID ### Request Example ```ts const updatedStudent = await db.update(studentTable, { id: 'rec1234', firstName: 'John', // Only include fields you want to update }); ``` ### Response #### Success Response (200) - **T** (object) - The updated record #### Response Example ```json { "id": "rec1234", "firstName": "John", "lastName": "Doe" } ``` ``` -------------------------------- ### DELETE /remove Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Deletes a record from a table. ```APIDOC ## DELETE /remove ### Description Deletes a record from a table. ### Method DELETE ### Endpoint `/remove` ### Parameters #### Path Parameters - **table** (Table) - Required - Table definition object - **id** (string) - Required - The ID of the record to delete ### Request Example ```ts await db.remove(studentTable, 'rec1234'); ``` ### Response #### Success Response (200) - **{ id: string }** (object) - An object containing the ID of the deleted record #### Response Example ```json { "id": "rec1234" } ``` ``` -------------------------------- ### Update Existing Record (TypeScript) Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Updates an existing record in an Airtable table. Requires the table definition and an object containing the record's ID and the fields to update. Returns the updated record. ```typescript async update(table: Table, data: Partial & { id: string }): Promise ``` ```typescript const updatedStudent = await db.update(studentTable, { id: 'rec1234', firstName: 'John', // Only include fields you want to update }); ``` -------------------------------- ### Retrieve Single Record (TypeScript) Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Retrieves a single record from an Airtable table using its ID. Requires the table definition and the record ID. Returns the retrieved record with type safety. ```typescript async get(table: Table, id: string): Promise ``` ```typescript const student = await db.get(studentTable, 'rec1234'); console.log(student.firstName); // Access fields with type safety ``` -------------------------------- ### Delete Record (TypeScript) Source: https://github.com/domdomegg/airtable-ts/blob/master/README.md Deletes a record from an Airtable table by its ID. Requires the table definition and the ID of the record to be deleted. Returns an object containing the ID of the deleted record. ```typescript async remove(table: Table, id: string): Promise<{ id: string }> ``` ```typescript await db.remove(studentTable, 'rec1234'); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.