Skip to content

Commit 66ef164

Browse files
committed
More data source updates
1 parent 1e6f76c commit 66ef164

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

components/notion/actions/retrieve-database-content/retrieve-database-content.mjs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import notion from "../../notion.app.mjs";
22

33
export default {
44
key: "notion-retrieve-database-content",
5-
name: "Retrieve Database Content",
6-
description: "Get all content of a database. [See the documentation](https://developers.notion.com/reference/post-database-query)",
7-
version: "0.0.9",
5+
name: "Retrieve Data Source Content",
6+
description: "Get all content of a data source. [See the documentation](https://developers.notion.com/reference/query-a-data-source)",
7+
version: "1.0.0",
88
type: "action",
99
props: {
1010
notion,
@@ -14,12 +14,21 @@ export default {
1414
"databaseId",
1515
],
1616
},
17+
dataSourceId: {
18+
propDefinition: [
19+
notion,
20+
"dataSourceId",
21+
({ databaseId }) => ({
22+
databaseId,
23+
}),
24+
],
25+
},
1726
},
1827
async run({ $ }) {
19-
const { results } = await this.notion.queryDatabase(this.databaseId);
28+
const { results } = await this.notion.queryDataSource(this.dataSourceId);
2029
$.export("$summary", `Successfully retrieved ${results.length} object${results.length === 1
2130
? ""
22-
: "s"} in database`);
31+
: "s"} in data source`);
2332
return results;
2433
},
2534
};

components/notion/notion.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default {
7979
const parentType = response.parent.type;
8080
try {
8181
const { properties } = parentType === "data_source_id"
82-
? await this.retrieveDataSource(response.parent.data_source_id).properties
82+
? await this.retrieveDataSource(response.parent.data_source_id)
8383
: response;
8484

8585
const propEntries = Object.entries(properties);

components/notion/sources/page-properties-updated-instant/page-properties-updated-instant.mjs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
...common,
66
key: "notion-page-properties-updated-instant",
77
name: "Page Properties Updated (Instant)",
8-
description: "Emit new event each time a page property is updated in a database. For use with Page Properties Updated event type. Webhook must be set up in Notion. [See the documentation](https://developers.notion.com/reference/webhooks#step-1-creating-a-webhook-subscription)",
8+
description: "Emit new event each time a page property is updated in a data source. For use with Page Properties Updated event type. Webhook must be set up in Notion. [See the documentation](https://developers.notion.com/reference/webhooks#step-1-creating-a-webhook-subscription)",
99
version: "0.0.2",
1010
type: "source",
1111
dedupe: "unique",
@@ -17,14 +17,23 @@ export default {
1717
"databaseId",
1818
],
1919
},
20+
dataSourceId: {
21+
propDefinition: [
22+
common.props.notion,
23+
"dataSourceId",
24+
({ databaseId }) => ({
25+
databaseId,
26+
}),
27+
],
28+
},
2029
properties: {
2130
type: "string[]",
2231
label: "Properties",
2332
description: "Only emit events when one or more of the selected properties have changed",
2433
optional: true,
2534
async options() {
2635
try {
27-
const { properties } = await this.notion.retrieveDatabase(this.databaseId);
36+
const { properties } = await this.notion.retrieveDataSource(this.dataSourceId);
2837
const propEntries = Object.entries(properties);
2938
return propEntries.map((prop) => ({
3039
label: prop[1].name,
@@ -55,8 +64,8 @@ export default {
5564
return;
5665
}
5766

58-
if (event.data.parent.id !== this.databaseId) {
59-
console.log(`Skipping event for database: ${event.data.parent.id}`);
67+
if (event.data.parent.id !== this.dataSourceId) {
68+
console.log(`Skipping event for data source: ${event.data.parent.id}`);
6069
return;
6170
}
6271

components/notion/sources/updated-page/updated-page.mjs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import sampleEmit from "./test-event.mjs";
77
export default {
88
...base,
99
key: "notion-updated-page",
10-
name: "New or Updated Page in Database (By Property)",
11-
description: "Emit new event when a page is created or updated in the selected database. [See the documentation](https://developers.notion.com/reference/page)",
10+
name: "New or Updated Page in Data Source (By Property)",
11+
description: "Emit new event when a page is created or updated in the selected data source. [See the documentation](https://developers.notion.com/reference/page)",
1212
version: "0.1.12",
1313
type: "source",
1414
dedupe: "unique",
@@ -20,6 +20,15 @@ export default {
2020
"databaseId",
2121
],
2222
},
23+
dataSourceId: {
24+
propDefinition: [
25+
notion,
26+
"dataSourceId",
27+
({ databaseId }) => ({
28+
databaseId,
29+
}),
30+
],
31+
},
2332
includeNewPages: {
2433
type: "boolean",
2534
label: "Include New Pages",
@@ -31,8 +40,8 @@ export default {
3140
notion,
3241
"propertyTypes",
3342
(c) => ({
34-
parentId: c.databaseId,
35-
parentType: "database",
43+
parentId: c.dataSourceId,
44+
parentType: "data_source",
3645
}),
3746
],
3847
description: "Only emit events when one or more of the selected properties have changed",
@@ -51,7 +60,7 @@ export default {
5160
const propertyValues = {};
5261
const propertiesToCheck = await this._getPropertiesToCheck();
5362
const params = this.lastUpdatedSortParam();
54-
const pagesStream = this.notion.getPages(this.databaseId, params);
63+
const pagesStream = this.notion.getPages(this.dataSourceId, params);
5564
for await (const page of pagesStream) {
5665
for (const propertyName of propertiesToCheck) {
5766
const currentValue = this._maybeRemoveFileSubItems(page.properties[propertyName]);
@@ -91,7 +100,7 @@ export default {
91100
if (this.properties?.length) {
92101
return this.properties;
93102
}
94-
const { properties } = await this.notion.retrieveDatabase(this.databaseId);
103+
const { properties } = await this.notion.retrieveDataSource(this.dataSourceId);
95104
return Object.keys(properties);
96105
},
97106
_maybeRemoveFileSubItems(property) {
@@ -150,7 +159,7 @@ export default {
150159
};
151160
let newLastUpdatedTimestamp = lastCheckedTimestamp;
152161
const propertiesToCheck = await this._getPropertiesToCheck();
153-
const pagesStream = this.notion.getPages(this.databaseId, params);
162+
const pagesStream = this.notion.getPages(this.dataSourceId, params);
154163

155164
for await (const page of pagesStream) {
156165
const changes = [];

0 commit comments

Comments
 (0)