Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/airtable_oauth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/airtable_oauth",
"version": "0.4.1",
"version": "0.4.2",
"description": "Pipedream Airtable (OAuth) Components",
"main": "airtable_oauth.app.mjs",
"keywords": [
Expand Down
7 changes: 7 additions & 0 deletions components/airtable_oauth/sources/common/common.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,12 @@ export default {
const formattedTimestamp = new Date(timestampMillis).toISOString();
this._setLastTimestamp(formattedTimestamp);
},
getListRecordsParams(params) {
return {
filterByFormula: `LAST_MODIFIED_TIME() > "${this._getLastTimestamp()}"`,
returnFieldsByFieldId: this.returnFieldsByFieldId || false,
...params,
};
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

export default {
...base,
name: "New, Modified or Deleted Records",

Check warning on line 6 in components/airtable_oauth/sources/new-modified-or-deleted-records/new-modified-or-deleted-records.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
description: "Emit new event each time a record is added, updated, or deleted in an Airtable table. Supports tables up to 10,000 records",
key: "airtable_oauth-new-modified-or-deleted-records",
version: "0.0.8",
version: "0.0.9",
type: "source",
dedupe: "unique",
props: {
Expand Down Expand Up @@ -53,38 +53,46 @@
const prevAllRecordIds = this._getPrevAllRecordIds();

const lastTimestamp = this._getLastTimestamp();
const params = {
filterByFormula: `LAST_MODIFIED_TIME() > "${lastTimestamp}"`,
returnFieldsByFieldId: this.returnFieldsByFieldId || false,
};
const params = this.getListRecordsParams();

const records = await this.airtable.listRecords({
baseId,
tableId,
params,
});

let allRecordIds = [],
newRecordsCount = 0,
let newRecordsCount = 0,
modifiedRecordsCount = 0,
deletedRecordsCount = 0;

if (records) {
for (const record of records) {
if (!lastTimestamp || moment(record.createdTime) > moment(lastTimestamp)) {
record.type = "new_record";
if (!lastTimestamp || moment(record.createdTime) > moment(lastTimestamp)) {;
this.$emit({
...record,
type: "new_record",
metadata,
}, {
id: record.id,
summary: `New record: ${record.id}`,
ts: moment(record.createdTime).valueOf(),
});
newRecordsCount++;

} else {
record.type = "record_modified";
const ts = Date.now();
const id = `${record.id}-${ts}`;
this.$emit({
...record,
type: "record_modified",
metadata,
}, {
id,
summary: `Record modified: ${record.id}`,
ts,
});
modifiedRecordsCount++;
}

record.metadata = metadata;

this.$emit(record, {
summary: `${record.type}: ${JSON.stringify(record.fields)}`,
id: record.id,
});
}
}

Expand All @@ -95,26 +103,27 @@
tableId,
params,
});
if (!data.length || data.length === 0) return;
allRecordIds = [
...data.map((record) => record.id),
];

const allRecordIds = data.map((record) => record.id);

if (prevAllRecordIds) {
const deletedRecordIds = prevAllRecordIds.filter(
(prevRecord) => !allRecordIds.includes(prevRecord),
);
const currentRecordIdSet = new Set(allRecordIds);
const deletedRecordIds =
prevAllRecordIds.filter((prevRecord) => !currentRecordIdSet.has(prevRecord));

for (const recordID of deletedRecordIds) {
deletedRecordsCount++;
const deletedRecordObj = {
const ts = Date.now();
const id = `${recordID}-${ts}`;
this.$emit({
id: recordID,
metadata,
type: "record_deleted",
id: recordID,
};
this.$emit(deletedRecordObj, {
}, {
id,
summary: `Record deleted: ${recordID}`,
id: recordID,
ts,
});
deletedRecordsCount++;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
name: "New or Modified Records in View",
description: "Emit new event for each new or modified record in a view",
key: "airtable_oauth-new-or-modified-records-in-view",
version: "0.0.9",
version: "0.0.10",
type: "source",
props: {
...base.props,
Expand Down Expand Up @@ -48,11 +48,9 @@ export default {
} = this;

const lastTimestamp = this._getLastTimestamp();
const params = {
const params = this.getListRecordsParams({
view: viewId,
filterByFormula: `LAST_MODIFIED_TIME() > "${lastTimestamp}"`,
returnFieldsByFieldId: this.returnFieldsByFieldId || false,
};
});

const records = await this.airtable.listRecords({
baseId,
Expand All @@ -74,19 +72,31 @@ export default {
let newRecords = 0, modifiedRecords = 0;
for (const record of records) {
if (!lastTimestamp || moment(record.createdTime) > moment(lastTimestamp)) {
record.type = "new_record";
this.$emit({
...record,
type: "new_record",
metadata,
}, {
id: record.id,
summary: `New record: ${record.id}`,
ts: moment(record.createdTime).valueOf(),
});
newRecords++;

} else {
record.type = "record_modified";
const ts = Date.now();
const id = `${record.id}-${ts}`;
this.$emit({
...record,
type: "record_modified",
metadata,
}, {
id,
summary: `Record modified: ${record.id}`,
ts,
});
modifiedRecords++;
}

record.metadata = metadata;

this.$emit(record, {
summary: `${record.type}: ${JSON.stringify(record.fields)}`,
id: record.id,
});
}
console.log(`Emitted ${newRecords} new records(s) and ${modifiedRecords} modified record(s).`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
name: "New Records in View",
description: "Emit new event for each new record in a view",
key: "airtable_oauth-new-records-in-view",
version: "0.0.8",
version: "0.0.9",
type: "source",
dedupe: "unique",
props: {
Expand Down Expand Up @@ -49,11 +49,10 @@ export default {
} = this;

const lastTimestamp = this._getLastTimestamp();
const params = {
const params = this.getListRecordsParams({
view: viewId,
filterByFormula: `CREATED_TIME() > "${lastTimestamp}"`,
returnFieldsByFieldId: this.returnFieldsByFieldId || false,
};
});

const records = await this.airtable.listRecords({
baseId,
Expand Down
2 changes: 0 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading