Skip to content

Commit fe0fcba

Browse files
committed
Other data source updates
1 parent 85cb57f commit fe0fcba

File tree

11 files changed

+83
-47
lines changed

11 files changed

+83
-47
lines changed

components/notion/actions/create-page-from-database/create-page-from-database.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@ export default {
1717
notion,
1818
"databaseId",
1919
],
20-
label: "Parent Database ID",
21-
description: "Select a parent database or provide a database ID",
2220
},
23-
dataSource: {
21+
parentDataSource: {
2422
propDefinition: [
2523
notion,
2624
"dataSourceId",
2725
({ parent }) => ({
2826
databaseId: parent,
2927
}),
3028
],
29+
label: "Parent Data Source ID",
30+
description: "Select a parent data source or provide a data source ID",
3131
},
3232
Name: {
3333
type: "string",
3434
label: "Name",
35-
description: "The name of the page. Use this only if the database has a `title` property named `Name`. Otherwise, use the `Properties` prop below to set the title property.",
35+
description: "The name of the page. Use this only if the data source has a `title` property named `Name`. Otherwise, use the `Properties` prop below to set the title property.",
3636
optional: true,
3737
},
3838
properties: {
3939
type: "object",
4040
label: "Properties",
41-
description: "The values of the page's properties. The schema must match the parent database's properties. [See the documentation](https://developers.notion.com/reference/property-object) for information on various property types. Example: `{ \"Tags\": [ \"tag1\" ], \"Link\": \"https://pipedream.com\" }`",
41+
description: "The values of the page's properties. The schema must match the parent data source's properties. [See the documentation](https://developers.notion.com/reference/property-object) for information on various property types. Example: `{ \"Tags\": [ \"tag1\" ], \"Link\": \"https://pipedream.com\" }`",
4242
optional: true,
4343
},
4444
icon: {
@@ -87,7 +87,7 @@ export default {
8787
},
8888
async run({ $ }) {
8989
const MAX_BLOCKS = 100;
90-
const parentPage = await this.notion.retrieveDataSource(this.dataSource);
90+
const parentPage = await this.notion.retrieveDataSource(this.parentDataSource);
9191
const {
9292
children, ...page
9393
} = this.buildPage(parentPage);

components/notion/actions/retrieve-database-schema/retrieve-database-schema.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-schema",
5-
name: "Retrieve Database Schema",
6-
description: "Get the property schema of a database in Notion. [See the documentation](https://developers.notion.com/reference/retrieve-a-database)",
7-
version: "0.0.11",
5+
name: "Retrieve Data Source Schema",
6+
description: "Get the property schema of a data source in Notion. [See the documentation](https://developers.notion.com/reference/retrieve-a-data-source)",
7+
version: "1.0.0",
88
type: "action",
99
props: {
1010
notion,
@@ -14,10 +14,19 @@ 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 response = await this.notion.retrieveDatabase(this.databaseId);
20-
$.export("$summary", "Successfully retrieved database schema");
28+
const response = await this.notion.retrieveDataSource(this.dataSourceId);
29+
$.export("$summary", "Successfully retrieved data source schema");
2130
return response;
2231
},
2332
};

components/notion/actions/update-database/update-database.mjs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import base from "../common/base-page-builder.mjs";
55
export default {
66
...base,
77
key: "notion-update-database",
8-
name: "Update Database",
9-
description: "Update a database. [See the documentation](https://developers.notion.com/reference/update-a-database)",
10-
version: "0.0.2",
8+
name: "Update Data Source",
9+
description: "Update a data source. [See the documentation](https://developers.notion.com/reference/update-a-data-source)",
10+
version: "1.0.0",
1111
type: "action",
1212
props: {
1313
notion,
@@ -16,34 +16,43 @@ export default {
1616
notion,
1717
"databaseId",
1818
],
19+
},
20+
dataSourceId: {
21+
propDefinition: [
22+
notion,
23+
"dataSourceId",
24+
({ databaseId }) => ({
25+
databaseId,
26+
}),
27+
],
1928
reloadProps: true,
2029
},
2130
title: {
2231
type: "string",
2332
label: "Title",
24-
description: "Title of database as it appears in Notion. An array of [rich text objects](https://developers.notion.com/reference/rich-text).",
33+
description: "Title of the data source as it appears in Notion. An array of [rich text objects](https://developers.notion.com/reference/rich-text).",
2534
optional: true,
2635
},
2736
description: {
2837
type: "string",
2938
label: "Description",
30-
description: "An array of [rich text objects](https://developers.notion.com/reference/rich-text) that represents the description of the database that is displayed in the Notion UI. If omitted, then the database description remains unchanged.",
39+
description: "An array of [rich text objects](https://developers.notion.com/reference/rich-text) that represents the description of the data source that is displayed in the Notion UI. If omitted, then the data source description remains unchanged.",
3140
optional: true,
3241
},
3342
properties: {
3443
type: "object",
3544
label: "Properties",
36-
description: "The properties of a database to be changed in the request, in the form of a JSON object. If updating an existing property, then the keys are the names or IDs of the properties as they appear in Notion, and the values are [property schema objects](https://developers.notion.com/reference/rich-text). If adding a new property, then the key is the name of the new database property and the value is a [property schema object](https://developers.notion.com/reference/property-schema-object).",
45+
description: "The properties of a data source to be changed in the request, in the form of a JSON object. If updating an existing property, then the keys are the names or IDs of the properties as they appear in Notion, and the values are [property schema objects](https://developers.notion.com/reference/rich-text). If adding a new property, then the key is the name of the new data source property and the value is a [property schema object](https://developers.notion.com/reference/property-schema-object).",
3746
optional: true,
3847
},
3948
},
4049
async additionalProps(props) {
41-
if (this.databaseId) {
42-
const database = await this.notion.retrieveDatabase(this.databaseId);
50+
if (this.databaseId && this.dataSourceId) {
51+
const dataSource = await this.notion.retrieveDataSource(this.dataSourceId);
4352

44-
props.title.default = database.title.map((text) => text.text.content).join(" ");
45-
props.description.default = database.description.map((text) => text.plain_text).join(" ");
46-
props.properties.default = Object.entries(database.properties).reduce((acc, [
53+
props.title.default = dataSource.title.map((text) => text.text.content).join(" ");
54+
props.description.default = dataSource.description.map((text) => text.plain_text).join(" ");
55+
props.properties.default = Object.entries(dataSource.properties).reduce((acc, [
4756
key,
4857
value,
4958
]) => {
@@ -54,8 +63,8 @@ export default {
5463
}
5564
},
5665
async run({ $ }) {
57-
const response = await this.notion.updateDatabase({
58-
database_id: this.databaseId,
66+
const response = await this.notion.updateDataSource({
67+
dataSource_id: this.dataSourceId,
5968
title: [
6069
{
6170
text: {
@@ -73,7 +82,7 @@ export default {
7382
properties: utils.parseObject(this.properties),
7483
});
7584

76-
$.export("$summary", `Successfully updated database with ID ${response.id}`);
85+
$.export("$summary", `Successfully updated data source with ID ${response.id}`);
7786
return response;
7887
},
7988
};

components/notion/actions/update-page/update-page.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
key: "notion-update-page",
88
name: "Update Page",
99
description: "Update a page's property values. To append page content, use the *Append Block* action instead. [See the documentation](https://developers.notion.com/reference/patch-page)",
10-
version: "1.1.10",
10+
version: "2.0.0",
1111
type: "action",
1212
props: {
1313
notion,
@@ -16,18 +16,18 @@ export default {
1616
alertType: "info",
1717
content: "Properties that are not set will remain unchanged.",
1818
},
19-
databaseId: {
19+
parent: {
2020
propDefinition: [
2121
notion,
2222
"databaseId",
2323
],
2424
},
25-
parent: {
25+
parentDataSource: {
2626
propDefinition: [
2727
notion,
2828
"dataSourceId",
2929
(c) => ({
30-
databaseId: c.databaseId,
30+
databaseId: c.parent,
3131
}),
3232
],
3333
label: "Parent Data Source ID",
@@ -39,7 +39,7 @@ export default {
3939
notion,
4040
"pageIdInDataSource",
4141
(c) => ({
42-
dataSourceId: c.parent,
42+
dataSourceId: c.parentDataSource,
4343
}),
4444
],
4545
},
@@ -60,7 +60,7 @@ export default {
6060
notion,
6161
"propertyTypes",
6262
(c) => ({
63-
parentId: c.parent,
63+
parentId: c.parentDataSource,
6464
parentType: "dataSource",
6565
}),
6666
],
@@ -69,7 +69,7 @@ export default {
6969
},
7070
async additionalProps() {
7171
try {
72-
const { properties } = await this.notion.retrieveDataSource(this.parent);
72+
const { properties } = await this.notion.retrieveDataSource(this.parentDataSource);
7373
const selectedProperties = pick(properties, this.propertyTypes);
7474

7575
return this.buildAdditionalProps({

components/notion/common/notion-meta-properties.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import utils from "./utils.mjs";
22

33
/**
44
* Implementation for Database Meta in Notion - https://developers.notion.com/reference/database
5+
* See also Data Sources - https://developers.notion.com/reference/data-source
56
*
67
* convertToNotion: converts the prop values to send to the Notion API
78
*/
89
export const NOTION_DATA_SOURCE_META = {
910
parent: {
1011
convertToNotion: (property) => ({
1112
type: "data_source_id",
12-
database_id: property.value,
13+
data_source_id: property.value,
1314
}),
1415
},
1516
title: {

components/notion/notion.app.mjs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ export default {
2525
description: "Select a data source from the database or provide a data source ID",
2626
async options({ databaseId }) {
2727
this._checkOptionsContext(databaseId, "Database ID");
28-
const dataSources = await this.getDataSourcesForDatabase(databaseId);
29-
return dataSources?.map((dataSource) => ({
30-
label: dataSource.name,
31-
value: dataSource.id,
32-
})) || [];
28+
const response = await this.getDataSourcesForDatabase(databaseId);
29+
return this._extractDatabaseTitleOptions(response);
3330
},
3431
},
3532
pageId: {

components/notion/sources/common/base.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default {
3434
} = obj;
3535
const ts = Date.parse(lastTime);
3636

37-
if (type === constants.types.DATABASE) {
37+
if (type === constants.types.DATABASE || type === constants.types.DATA_SOURCE) {
3838
title = this.notion.extractDatabaseTitle(obj);
3939
} else {
4040
title = this.notion.extractPageTitle(obj);

components/notion/sources/common/constants.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const types = {
22
DATABASE: "database",
3+
DATA_SOURCE: "data_source",
34
PAGE: "page",
45
};
56

67
const summaries = {
78
DATABASE_ADDED: "Database added",
9+
DATA_SOURCE_ADDED: "Data source added",
810
PAGE_ADDED: "Page added",
911
PAGE_UPDATED: "Page updated",
1012
};

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import sampleEmit from "./test-event.mjs";
66
export default {
77
...base,
88
key: "notion-new-page",
9-
name: "New Page in Database",
10-
description: "Emit new event when a page is created in the selected database. [See the documentation](https://developers.notion.com/reference/page)",
9+
name: "New Page in Data Source",
10+
description: "Emit new event when a page is created in the selected data source. [See the documentation](https://developers.notion.com/reference/page)",
1111
version: "0.0.16",
1212
type: "source",
1313
props: {
@@ -18,6 +18,15 @@ export default {
1818
"databaseId",
1919
],
2020
},
21+
dataSourceId: {
22+
propDefinition: [
23+
notion,
24+
"dataSourceId",
25+
({ databaseId }) => ({
26+
databaseId,
27+
}),
28+
],
29+
},
2130
},
2231
hooks: {
2332
...base.hooks,
@@ -46,7 +55,7 @@ export default {
4655

4756
// Get pages in created order descending until the first page edited after
4857
// lastCreatedTimestamp, then reverse list of pages and emit
49-
const pagesStream = this.notion.getPages(this.databaseId, params);
58+
const pagesStream = this.notion.getPages(this.dataSourceId, params);
5059

5160
for await (const page of pagesStream) {
5261
if (!this.isResultNew(page.created_time, lastCreatedTimestamp)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "notion-page-properties-updated-instant",
77
name: "Page Properties Updated (Instant)",
88
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)",
9-
version: "0.0.2",
9+
version: "1.0.0",
1010
type: "source",
1111
dedupe: "unique",
1212
props: {

0 commit comments

Comments
 (0)