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/notion/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/notion",
"version": "0.9.0",
"version": "0.9.1",
"description": "Pipedream Notion Components",
"main": "notion.app.mjs",
"keywords": [
Expand Down
42 changes: 24 additions & 18 deletions components/notion/sources/updated-page/updated-page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
key: "notion-updated-page",
name: "New or Updated Page in Database (By Property)",
description: "Emit new event when a page is created or updated in the selected database. [See the documentation](https://developers.notion.com/reference/page)",
version: "0.1.10",
version: "0.1.11",
type: "source",
dedupe: "unique",
props: {
Expand Down Expand Up @@ -38,7 +38,7 @@
description: "Only emit events when one or more of the selected properties have changed",
optional: true,
},
alert: {

Check warning on line 41 in components/notion/sources/updated-page/updated-page.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

Check warning on line 41 in components/notion/sources/updated-page/updated-page.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props
type: "alert",
alertType: "warning",
content: "Source not saving? Your database might be too large. If deployment takes longer than one minute, an error will occur.",
Expand Down Expand Up @@ -166,14 +166,17 @@
break;
}

// Check if this is a new page first
const pageExistsInDB = propertyValues[page.id] != null;
isNewPage = !pageExistsInDB;

for (const propertyName of propertiesToCheck) {
const previousValue = structuredClone(propertyValues[page.id]?.[propertyName]);
// value used to compare and to save to this.db
const currentValueToSave = this._maybeRemoveFileSubItems(page.properties[propertyName]);
// (unmodified) value that should be emitted
const currentValueToEmit = page.properties[propertyName];

const pageExistsInDB = propertyValues[page.id] != null;
const propertyChanged =
JSON.stringify(previousValue) !== JSON.stringify(currentValueToSave);

Expand All @@ -191,25 +194,28 @@
}

if (!pageExistsInDB) {
isNewPage = true;
propertyHasChanged = true;
propertyValues[page.id] = {
[propertyName]: currentValueToSave,
};
changes.push({
property: propertyName,
previousValue,
currentValue: currentValueToEmit,
});
}
}
// For new pages, always track the properties
if (!propertyValues[page.id]) {
propertyValues[page.id] = {};
}
propertyValues[page.id][propertyName] = currentValueToSave;

if (isNewPage && !this.includeNewPages) {
console.log(`Ignoring new page: ${page.id}`);
continue;
// Only mark as changed (to emit event) if includeNewPages is true
if (this.includeNewPages) {
propertyHasChanged = true;
changes.push({
property: propertyName,
previousValue,
currentValue: currentValueToEmit,
});
}
}
}

if (propertyHasChanged) {
// Only emit events if:
// 1. It's an existing page with changes, OR
// 2. It's a new page and includeNewPages is true
if (propertyHasChanged && (!isNewPage || this.includeNewPages)) {
this._emitEvent(page, changes, isNewPage);
}
}
Expand Down
5 changes: 1 addition & 4 deletions pnpm-lock.yaml

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

Loading