forked from PipedreamHQ/pipedream
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Airtable Create & Update Record actions - Column names as distinct pr…
…ops (PipedreamHQ#2600) * Add fields as additional props to Airtable actions Updates Create Single Record and Update Record to use $.airtable.table prop * Add fields as additional props to Airtable actions Updates Create Single Record and Update Record to use $.airtable.table prop * Convert Airtable components from CJS to ESM * Rev Airtable component versions Increments major version for Create Single Record & Update Record actions Increment patch version of other Airtable components * Add JSDocs for Airtable utils * Fix .eslintrc putout/multiple-properties-destructuring minProperties Changes minProperties from 1 -> 2 to avoid conflicting linter errors when destructuring a single property * Add ConfigurationError in additionalProps & async options in Airtable Create Single Record & Update Record actions Refactored/removed some guard clauses * Update prop descriptions for tableId,viewId,sortFieldId Instructs to use a custom expression when referencing previous props dynamically * Show record prop on additionalProps error if manual table input
- Loading branch information
Showing
27 changed files
with
699 additions
and
398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import airtable from "../airtable.app.mjs"; | ||
|
||
export default { | ||
props: { | ||
airtable, | ||
baseId: { | ||
propDefinition: [ | ||
airtable, | ||
"baseId", | ||
], | ||
withLabel: true, | ||
}, | ||
tableId: { | ||
propDefinition: [ | ||
airtable, | ||
"tableId", | ||
({ baseId }) => ({ | ||
baseId, | ||
}), | ||
], | ||
withLabel: true, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
components/airtable/actions/create-single-record/create-single-record.js
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
components/airtable/actions/create-single-record/create-single-record.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import airtable from "../../airtable.app.mjs"; | ||
import { | ||
makeFieldProps, | ||
makeRecord, | ||
} from "../../common/utils.mjs"; | ||
import common from "../common.mjs"; | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
|
||
export default { | ||
key: "airtable-create-single-record", | ||
name: "Create single record", | ||
description: "Adds a record to a table.", | ||
version: "1.0.0", | ||
type: "action", | ||
props: { | ||
...common.props, | ||
// eslint-disable-next-line pipedream/props-label,pipedream/props-description | ||
tableId: { | ||
...common.props.tableId, | ||
reloadProps: true, | ||
}, | ||
typecast: { | ||
propDefinition: [ | ||
airtable, | ||
"typecast", | ||
], | ||
}, | ||
}, | ||
async additionalProps() { | ||
const baseId = this.baseId?.value ?? this.baseId; | ||
const tableId = this.tableId?.value ?? this.tableId; | ||
try { | ||
const tableSchema = await this.airtable.table(baseId, tableId); | ||
return makeFieldProps(tableSchema); | ||
} catch (err) { | ||
const hasManualTableInput = !this.tableId?.label; | ||
// If manual input and .table throws error, return a record prop | ||
// otherwise, throw ConfigurationError | ||
if (hasManualTableInput) { | ||
return { | ||
// Use record propDefinition directly to workaround lack of support | ||
// for propDefinition in additionalProps | ||
record: airtable.propDefinitions.record, | ||
}; | ||
} | ||
throw new ConfigurationError("Could not find a table for the specified base ID and table ID. Please adjust the action configuration to continue."); | ||
} | ||
}, | ||
async run({ $ }) { | ||
const baseId = this.baseId?.value ?? this.baseId; | ||
const tableId = this.tableId?.value ?? this.tableId; | ||
|
||
const table = this.airtable.base(baseId)(tableId); | ||
|
||
const record = this.record ?? makeRecord(this); | ||
|
||
this.airtable.validateRecord(record); | ||
|
||
const data = [ | ||
{ | ||
fields: record, | ||
}, | ||
]; | ||
|
||
const params = { | ||
typecast: this.typecast, | ||
}; | ||
|
||
let response; | ||
try { | ||
[ | ||
response, | ||
] = await table.create(data, params); | ||
} catch (err) { | ||
this.airtable.throwFormattedError(err); | ||
} | ||
|
||
$.export("$summary", `Added 1 record to ${this.baseId?.label || baseId}: [${this.tableId?.label || tableId}](https://airtable.com/${baseId}/${tableId})`); | ||
return response; | ||
}, | ||
}; |
28 changes: 0 additions & 28 deletions
28
components/airtable/actions/delete-record/delete-record.js
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
components/airtable/actions/delete-record/delete-record.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import airtable from "../../airtable.app.mjs"; | ||
import common from "../common.mjs"; | ||
|
||
export default { | ||
key: "airtable-delete-record", | ||
name: "Delete Record", | ||
description: "Delete a record from a table by record ID.", | ||
version: "0.2.0", | ||
type: "action", | ||
props: { | ||
...common.props, | ||
recordId: { | ||
propDefinition: [ | ||
airtable, | ||
"recordId", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const baseId = this.baseId?.value ?? this.baseId; | ||
const tableId = this.tableId?.value ?? this.tableId; | ||
const recordId = this.recordId?.value ?? this.recordId; | ||
|
||
this.airtable.validateRecordID(recordId); | ||
const base = this.airtable.base(baseId); | ||
let response; | ||
try { | ||
response = await base(this.tableId.value).destroy(recordId); | ||
} catch (err) { | ||
this.airtable.throwFormattedError(err); | ||
} | ||
|
||
$.export("$summary", `Deleted record "${this.recordId?.label || recordId}" from ${this.baseId?.label || baseId}: [${this.tableId?.label || tableId}](https://airtable.com/${baseId}/${tableId})`); | ||
return response; | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.