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/nocodb/actions/add-record/add-record.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "nocodb-add-record",
name: "Add Record",
description: "This action adds a record in a table. [See the documentation](https://data-apis-v2.nocodb.com/#tag/Table-Records/operation/db-data-table-row-create)",
version: "0.0.4",
version: "0.0.5",
type: "action",
props: {
...common.props,
Expand Down
2 changes: 1 addition & 1 deletion components/nocodb/actions/delete-record/delete-record.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "nocodb-delete-record",
name: "Delete Record",
description: "This action deletes a row in a table. [See the documentation](https://data-apis-v2.nocodb.com/#tag/Table-Records/operation/db-data-table-row-delete)",
version: "0.0.4",
version: "0.0.5",
type: "action",
props: {
...common.props,
Expand Down
2 changes: 1 addition & 1 deletion components/nocodb/actions/get-record/get-record.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "nocodb-get-record",
name: "Get Record (from row number)",
description: "This action gets a row by row Id. [See the documentation](https://data-apis-v2.nocodb.com/#tag/Table-Records/operation/db-data-table-row-read)",
version: "0.0.4",
version: "0.0.5",
type: "action",
props: {
...common.props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "nocodb-list-records-matching-criteria",
name: "List Records in Table Matching Criteria",
description: "This action lists all rows in a table. [See the documentation](https://data-apis-v2.nocodb.com/#tag/Table-Records/operation/db-data-table-row-list)",
version: "0.0.5",
version: "0.0.6",
type: "action",
props: {
...common.props,
Expand Down
2 changes: 1 addition & 1 deletion components/nocodb/actions/update-record/update-record.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "nocodb-update-record",
name: "Update Record",
description: "This action updates a record in a table. [See the documentation](https://data-apis-v2.nocodb.com/#tag/Table-Records/operation/db-data-table-row-update)",
version: "0.0.4",
version: "0.0.5",
type: "action",
props: {
...common.props,
Expand Down
29 changes: 29 additions & 0 deletions components/nocodb/nocodb.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,27 @@ export default {
return rows?.map(({ Id }) => `${Id}` ) || [];
},
},
viewId: {
type: "string",
label: "View ID",
description: "The ID of a view",
async options({
tableId, page,
}) {
const { list } = await this.listViews({
tableId,
params: {
offset: page * DEFAULT_LIMIT,
},
});
return list?.map(({
id: value, title: label,
}) => ({
label,
value,
})) || [];
},
},
data: {
type: "any",
label: "data",
Expand Down Expand Up @@ -233,5 +254,13 @@ export default {
...opts,
});
},
listViews({
tableId, ...opts
}) {
return this._makeRequest({
path: `/meta/tables/${tableId}/views`,
...opts,
});
},
},
};
9 changes: 4 additions & 5 deletions components/nocodb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/nocodb",
"version": "0.0.7",
"version": "0.1.0",
"description": "Pipedream Nocodb Components",
"main": "nocodb.app.mjs",
"keywords": [
Expand All @@ -9,11 +9,10 @@
],
"homepage": "https://pipedream.com/apps/nocodb",
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"dependencies": {
"@pipedream/platform": "^1.6.0",
"moment": "^2.29.4"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
69 changes: 31 additions & 38 deletions components/nocodb/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import moment from "moment";
import nocodb from "../../nocodb.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

Expand Down Expand Up @@ -46,59 +45,53 @@ export default {
_setLastTime(lastTime) {
this.db.set("lastTime", lastTime);
},
async processEvent({
params, lastTime,
}) {
getParams(timeField) {
return {
sort: `-${timeField}`,
};
},
async getRows(records, timeField, lastTime) {
const rows = [];
for await (const row of records) {
if (!lastTime || Date.parse(row[timeField]) >= Date.parse(lastTime)) {
rows.push(row);
} else {
break;
}
}
return rows.reverse();
},
async processEvent(max) {
const timeField = this.getTimeField();
const lastTime = this._getLastTime();

const records = this.nocodb.paginate({
fn: this.nocodb.listTableRow,
args: {
tableId: this.tableId.value,
params,
params: this.getParams(timeField),
},
max,
});

for await (const record of records) {
if (moment(record[timeField]).isAfter(lastTime)) this._setLastTime(record[timeField]);
this.$emit(record, this.getDataToEmit(record));
const rows = await this.getRows(records, timeField, lastTime);

if (!rows.length) {
return;
}

this._setLastTime(rows[rows.length - 1][timeField]);

rows.forEach((row) => this.$emit(row, this.getDataToEmit(row)));
},
},
hooks: {
async activate() {
const timeField = this.getTimeField();
const lastTime = this._getLastTime();
const { list } = await this.nocodb.listTableRow({
tableId: this.tableId.value,
params: {
sort: `-${timeField}`,
},
});

list.reverse();

for (const row of list) {
if (!lastTime || moment(lastTime).isAfter(row[timeField])) {
this._setLastTime(row[timeField]);
}
this.$emit(row, this.getDataToEmit(row));
}
async deploy() {
await this.processEvent(25);
},
},
async run() {
const timeField = this.getTimeField();
const lastTime = this._getLastTime();
const params = {
sort: timeField,
};
// moment is necessary because nocodb query doesn't filter equal datetime in 'greater than'
if (lastTime) params.where = `(${timeField},gte,${moment(lastTime).add(1, "ms")
.toISOString()})`;
return this.processEvent({
params,
lastTime,
});
await this.processEvent();
},
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import common from "../common/base.mjs";

export default {
...common,
key: "nocodb-new-record-in-view",
name: "New Record in View",
description: "Emit new event for each new record in a view. [See the documentation](https://data-apis-v2.nocodb.com/#tag/Table-Records/operation/db-data-table-row-list)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
...common.props,
viewId: {
propDefinition: [
common.props.nocodb,
"viewId",
(c) => ({
tableId: c.tableId.value || c.tableId,
}),
],
},
},
methods: {
...common.methods,
getDataToEmit(record) {
return {
id: record.id,
summary: `New record created (${record.id})`,
ts: Date.parse(record[this.getTimeField()]),
};
},
getTimeField() {
return "created_at";
},
getParams(timeField) {
return {
viewId: this.viewId,
fields: timeField,
};
},
async getRows(records, timeField, lastTime) {
const rows = [];
for await (const row of records) {
if (!lastTime || Date.parse(row[timeField]) >= Date.parse(lastTime)) {
rows.push(row);
}
}
return rows;
},
},
};
2 changes: 1 addition & 1 deletion components/nocodb/sources/new-record/new-record.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
name: "New Record in Table",
key: "nocodb-new-record",
description: "Emit new event for each new record in table. [See the documentation](https://data-apis-v2.nocodb.com/#tag/Table-Records/operation/db-data-table-row-list)",
version: "0.0.5",
version: "0.0.6",
dedupe: "unique",
props: {
...common.props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
name: "New Update in Table",
key: "nocodb-updated-record",
description: "Emit new event for each update in table. [See the documentation](https://data-apis-v2.nocodb.com/#tag/Table-Records/operation/db-data-table-row-list)",
version: "0.0.5",
version: "0.0.6",
dedupe: "unique",
props: {
...common.props,
Expand Down
Loading
Loading