Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

airtable-plusplus

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

airtable-plusplus - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

77

dist/AirtablePlusPlus.d.ts

@@ -1,3 +0,3 @@

import type Base from 'airtable/lib/base';
import type { QueryParams } from 'airtable/lib/query_params';
import type Table from 'airtable/lib/table';
/**

@@ -14,3 +14,3 @@ * Module configuration object

*/
baseID: string;
baseId: string;
/**

@@ -52,4 +52,3 @@ * The name fo the table you want to interact with. **Not the ID, the name**

declare class AirtablePlusPlus<IFields extends Record<string, unknown>> {
base: Base;
private config;
table: Table;
/**

@@ -81,3 +80,3 @@ * Creates an AirtablePlusPlus instance, representing a table.

*/
create(data: Partial<Omit<IFields, 'id'>>, config?: string | Partial<AirtablePlusPlusOptions>): Promise<AirtablePlusPlusRecord<IFields>>;
create(data: Partial<IFields>): Promise<AirtablePlusPlusRecord<IFields>>;
/**

@@ -93,7 +92,6 @@ * Read all data from a table. Can be passed api options

*
* @param params - If string: sets Airtable table name, If object: Airtable api parameters
* @param config - Optional configuration override
* @param params Airtable api parameters
* @returns Array of record objects
*/
read(params?: QueryParams | string, config?: AirtablePlusPlusOptions | string): Promise<AirtablePlusPlusRecord<IFields>[]>;
read(params?: QueryParams): Promise<AirtablePlusPlusRecord<IFields>[]>;
/**

@@ -106,6 +104,5 @@ * Get data for a specific row on Airtable

* @param rowID - Airtable Row ID to query data from
* @param config - Optional config override
* @returns Record object
*/
find(rowID: string, config?: Partial<AirtablePlusPlusOptions>): Promise<AirtablePlusPlusRecord<IFields>>;
find(rowID: string): Promise<AirtablePlusPlusRecord<IFields>>;
/**

@@ -122,6 +119,5 @@ * Updates a row in Airtable. Unlike the replace method anything

* @param data - row data with keys that you'd like to update
* @param config - Optional config override
* @returns Array of record objects
*/
update(rowID: string, data: Partial<IFields>, config?: Partial<AirtablePlusPlusOptions>): Promise<AirtablePlusPlusRecord<IFields>>;
update(rowID: string, data: Partial<IFields>): Promise<AirtablePlusPlusRecord<IFields>>;
/**

@@ -136,6 +132,5 @@ * Performs a bulk update based on a search criteria. The criteria must

* @param data - Data to update if where condition is met
* @param config - Optional configuration override
* @returns Array of record objects
*/
updateWhere(where: string, data: Partial<IFields>, config: Partial<AirtablePlusPlusOptions>): Promise<Promise<AirtablePlusPlusRecord<IFields>>[]>;
updateWhere(where: string, data: Partial<IFields>): Promise<Promise<AirtablePlusPlusRecord<IFields>>[]>;
/**

@@ -151,6 +146,5 @@ * Replaces a given row in airtable. Similar to the update function,

* @param data - row data with keys that you'd like to replace
* @param config - Optional config override
* @returns Record object
*/
replace(rowID: string, data: IFields, config?: Partial<AirtablePlusPlusOptions>): Promise<AirtablePlusPlusRecord<IFields>>;
replace(rowID: string, data: IFields): Promise<AirtablePlusPlusRecord<IFields>>;
/**

@@ -165,6 +159,5 @@ * Performs a bulk replace based on a given search criteria. The criteria must

* @param data - Data to replace if where condition is met
* @param config - Optional configuration override
* @returns Array of record objects
*/
replaceWhere(where: string, data: IFields, config: Partial<AirtablePlusPlusOptions>): Promise<Promise<AirtablePlusPlusRecord<IFields>>[]>;
replaceWhere(where: string, data: IFields): Promise<Promise<AirtablePlusPlusRecord<IFields>>[]>;
/**

@@ -177,10 +170,5 @@ * Deletes a row in the provided table

* @param rowID - Airtable Row ID to delete
* @param {Object} data - row data with keys that you'd like to delete
* @param {Object} [config] - Optional config override
* @param {string} [config.tableName] - Airtable table name
* @param {boolean} [config.complex] - Flag to return full Airtable record object with helper methods attached
* @param {function} [config.base] - Airtable sdk base instance
* @returns {Promise} Record object
* @returns Record object
*/
delete(rowID: string | string[], config?: Partial<AirtablePlusPlusOptions>): Promise<{
delete(rowID: string | string[]): Promise<{
id: string;

@@ -201,14 +189,7 @@ fields: {};

*
* @param {string} where - filterByFormula string to filter table data by
* @param {Object} data - Data to delete if where condition is met
* @param {Object} [config] - Optional configuration override
* @param {string} [config.baseID] - Airtable base ID
* @param {string} [config.tableName] - Airtable table name
* @param {string} [config.camelCase] - Converts column name object keys to camel case in JSON response
* @param {string} [config.concurrency] - Sets concurrency for async iteration functions
* @param {boolean} [config.complex] - Flag to return full Airtable record object with helper methods attached
* @param {function} [config.transform] - Optional global transform function for reads
* @param where - filterByFormula string to filter table data by
* @param data - Data to delete if where condition is met
* @returns {Promise} Array of record objects
*/
deleteWhere(where: string, config?: Partial<AirtablePlusPlusOptions>): Promise<Promise<{
deleteWhere(where: string): Promise<Promise<{
id: string;

@@ -229,22 +210,8 @@ fields: {};

*
* @param {string} key - Primary key to compare value in passed in data object with dest row
* @param {Object} data - Updated data
* @param {Object} [config] - Optional config override
* @param {string} [config.tableName] - Airtable table name
* @param {boolean} [config.complex] - Flag to return full Airtable record object with helper methods attached
* @param {string} [config.baseID] - Airtable base id
* @returns {Promise} Array of record objects
* @param key - Primary key to compare value in passed in data object with dest row
* @param data - Updated data
* @returns Array of record objects
*/
upsert(key: string, data: Partial<IFields>, config?: Partial<AirtablePlusPlusOptions>): Promise<AirtablePlusPlusRecord<IFields> | Promise<AirtablePlusPlusRecord<IFields>>[]>;
upsert(key: string, data: Partial<IFields>): Promise<AirtablePlusPlusRecord<IFields> | Promise<AirtablePlusPlusRecord<IFields>>[]>;
/**
* Performs validations on object for current function run
* Allows the package user to pass in an override config
* object to change table name, apiKey, etc. at any time
*
* @ignore
* @param {Object} config - override config object
* @returns {Object} - local configuration object
*/
protected _mergeConfig(config: string | Partial<AirtablePlusPlusOptions>): AirtablePlusPlusOptions;
/**
* Determines if a Column name is multiple words, which results in being

@@ -256,4 +223,4 @@ * wrapped in curly braces. Useful for Airtable filterByFormula queries.

* @ignore
* @param {string} columnName - Airtable Column name being used in a filter
* @returns {string} - formatted column name
* @param columnName - Airtable Column name being used in a filter
* @returns formatted column name
*/

@@ -260,0 +227,0 @@ protected _formatColumnFilter(columnName?: string): string;

@@ -25,3 +25,3 @@ "use strict";

constructor(config) {
Object.defineProperty(this, "base", {
Object.defineProperty(this, "table", {
enumerable: true,

@@ -32,10 +32,3 @@ configurable: true,

});
Object.defineProperty(this, "config", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.config = config;
this.base = new airtable_1.default({ apiKey: config.apiKey }).base(config.baseID)._base;
this.table = new airtable_1.default({ apiKey: config.apiKey }).base(config.baseId)(config.tableName);
}

@@ -54,7 +47,6 @@ /**

*/
async create(data, config) {
async create(data) {
if (!data)
throw new Error('No data provided');
const { tableName } = this._mergeConfig(config !== null && config !== void 0 ? config : {});
const record = await this.base.table(tableName).create(data);
const record = await this.table.create(data);
return record._rawJson;

@@ -72,15 +64,8 @@ }

*
* @param params - If string: sets Airtable table name, If object: Airtable api parameters
* @param config - Optional configuration override
* @param params Airtable api parameters
* @returns Array of record objects
*/
async read(params, config) {
let { tableName } = this._mergeConfig(config !== null && config !== void 0 ? config : {});
if (typeof params === 'string') {
tableName = params;
params = {};
}
async read(params) {
let data = [];
await this.base
.table(tableName)
await this.table
.select(params)

@@ -90,6 +75,5 @@ .eachPage((records, next) => {

next();
}, (err) => {
if (err)
throw err;
data = data.filter((rows) => Boolean(rows));
})
.catch((err) => {
throw err;
});

@@ -105,8 +89,6 @@ return data;

* @param rowID - Airtable Row ID to query data from
* @param config - Optional config override
* @returns Record object
*/
async find(rowID, config) {
const { tableName } = this._mergeConfig(config !== null && config !== void 0 ? config : {});
const record = await this.base.table(tableName).find(rowID);
async find(rowID) {
const record = await this.table.find(rowID);
return record._rawJson;

@@ -125,8 +107,6 @@ }

* @param data - row data with keys that you'd like to update
* @param config - Optional config override
* @returns Array of record objects
*/
async update(rowID, data, config) {
const { tableName } = this._mergeConfig(config !== null && config !== void 0 ? config : {});
const record = await this.base.table(tableName).update(rowID, data);
async update(rowID, data) {
const record = await this.table.update(rowID, data);
return record._rawJson;

@@ -143,9 +123,7 @@ }

* @param data - Data to update if where condition is met
* @param config - Optional configuration override
* @returns Array of record objects
*/
async updateWhere(where, data, config) {
const cfg = this._mergeConfig(config !== null && config !== void 0 ? config : {});
const rows = await this.read({ filterByFormula: where }, cfg);
return rows.map((row) => this.update(row.id, data, cfg));
async updateWhere(where, data) {
const rows = await this.read({ filterByFormula: where });
return rows.map((row) => this.update(row.id, data));
}

@@ -162,8 +140,6 @@ /**

* @param data - row data with keys that you'd like to replace
* @param config - Optional config override
* @returns Record object
*/
async replace(rowID, data, config) {
const { tableName } = this._mergeConfig(config !== null && config !== void 0 ? config : {});
const record = await this.base.table(tableName).replace(rowID, data);
async replace(rowID, data) {
const record = await this.table.replace(rowID, data);
return record._rawJson;

@@ -180,9 +156,7 @@ }

* @param data - Data to replace if where condition is met
* @param config - Optional configuration override
* @returns Array of record objects
*/
async replaceWhere(where, data, config) {
const cfg = this._mergeConfig(config);
const rows = await this.read({ filterByFormula: where }, cfg);
return rows.map((row) => this.replace(row.id, data, cfg));
async replaceWhere(where, data) {
const rows = await this.read({ filterByFormula: where });
return rows.map((row) => this.replace(row.id, data));
}

@@ -196,13 +170,7 @@ /**

* @param rowID - Airtable Row ID to delete
* @param {Object} data - row data with keys that you'd like to delete
* @param {Object} [config] - Optional config override
* @param {string} [config.tableName] - Airtable table name
* @param {boolean} [config.complex] - Flag to return full Airtable record object with helper methods attached
* @param {function} [config.base] - Airtable sdk base instance
* @returns {Promise} Record object
* @returns Record object
*/
async delete(rowID, config) {
const { tableName } = this._mergeConfig(config !== null && config !== void 0 ? config : {});
async delete(rowID) {
// even if its a single string, it will be fine.
const record = await this.base.table(tableName).destroy(rowID);
const record = await this.table.destroy(rowID);
return Array.isArray(record)

@@ -219,18 +187,10 @@ ? record.map((rec) => ({ id: rec.id, fields: {}, createdTime: null }))

*
* @param {string} where - filterByFormula string to filter table data by
* @param {Object} data - Data to delete if where condition is met
* @param {Object} [config] - Optional configuration override
* @param {string} [config.baseID] - Airtable base ID
* @param {string} [config.tableName] - Airtable table name
* @param {string} [config.camelCase] - Converts column name object keys to camel case in JSON response
* @param {string} [config.concurrency] - Sets concurrency for async iteration functions
* @param {boolean} [config.complex] - Flag to return full Airtable record object with helper methods attached
* @param {function} [config.transform] - Optional global transform function for reads
* @param where - filterByFormula string to filter table data by
* @param data - Data to delete if where condition is met
* @returns {Promise} Array of record objects
*/
async deleteWhere(where, config) {
const cfg = this._mergeConfig(config !== null && config !== void 0 ? config : {});
const rows = (await this.read({ filterByFormula: where }, cfg));
async deleteWhere(where) {
const rows = (await this.read({ filterByFormula: where }));
return rows.map((row) => {
return this.delete(row.id, cfg);
return this.delete(row.id);
});

@@ -245,39 +205,13 @@ }

*
* @param {string} key - Primary key to compare value in passed in data object with dest row
* @param {Object} data - Updated data
* @param {Object} [config] - Optional config override
* @param {string} [config.tableName] - Airtable table name
* @param {boolean} [config.complex] - Flag to return full Airtable record object with helper methods attached
* @param {string} [config.baseID] - Airtable base id
* @returns {Promise} Array of record objects
* @param key - Primary key to compare value in passed in data object with dest row
* @param data - Updated data
* @returns Array of record objects
*/
async upsert(key, data, config) {
async upsert(key, data) {
if (!key || !data)
throw new Error('Key and data are required, but not provided');
const cfg = this._mergeConfig(config !== null && config !== void 0 ? config : {});
const rows = (await this.read({ filterByFormula: `${this._formatColumnFilter(key)} = ${data[key]}` }, cfg));
return rows.length === 0 ? this.create(data, cfg) : rows.map((row) => this.update(row.id, data, cfg));
const rows = (await this.read({ filterByFormula: `${this._formatColumnFilter(key)} = ${data[key]}` }));
return rows.length === 0 ? this.create(data) : rows.map((row) => this.update(row.id, data));
}
/**
* Performs validations on object for current function run
* Allows the package user to pass in an override config
* object to change table name, apiKey, etc. at any time
*
* @ignore
* @param {Object} config - override config object
* @returns {Object} - local configuration object
*/
_mergeConfig(config) {
if (!config)
return this.config;
let override = {};
if (typeof config === 'string')
override.tableName = config;
if (typeof config === 'object') {
override = config;
}
const cfg = { ...this.config, ...override };
return cfg;
}
/**
* Determines if a Column name is multiple words, which results in being

@@ -289,4 +223,4 @@ * wrapped in curly braces. Useful for Airtable filterByFormula queries.

* @ignore
* @param {string} columnName - Airtable Column name being used in a filter
* @returns {string} - formatted column name
* @param columnName - Airtable Column name being used in a filter
* @returns formatted column name
*/

@@ -293,0 +227,0 @@ _formatColumnFilter(columnName = '') {

{
"name": "airtable-plusplus",
"version": "0.1.0",
"version": "0.2.0",
"description": "A TypeScript fork of `airtable-plus`, the Airtable Node library designed for async/await.",

@@ -5,0 +5,0 @@ "main": "./dist/AirtablePlusPlus.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc