@@ -8,7 +8,7 @@ export default {
88  key : "notion-updated-page" , 
99  name : "Updated Page in Database" ,  /* eslint-disable-line pipedream/source-name */ 
1010  description : "Emit new event when a page in a database is updated. To select a specific page, use `Updated Page ID` instead" , 
11-   version : "0.0.15 " , 
11+   version : "0.0.16 " , 
1212  type : "source" , 
1313  dedupe : "unique" , 
1414  props : { 
@@ -40,14 +40,12 @@ export default {
4040  } , 
4141  hooks : { 
4242    async  deploy ( )  { 
43-       if  ( ! this . properties ?. length )  { 
44-         return ; 
45-       } 
43+       const  properties  =  await  this . getProperties ( ) ; 
4644      const  propertyValues  =  { } ; 
4745      const  pagesStream  =  this . notion . getPages ( this . databaseId ) ; 
4846      for  await  ( const  page  of  pagesStream )  { 
4947        propertyValues [ page . id ]  =  { } ; 
50-         for  ( const  property  of  this . properties )  { 
48+         for  ( const  property  of  properties )  { 
5149          propertyValues [ page . id ] [ property ]  =  JSON . stringify ( page . properties [ property ] ) ; 
5250        } 
5351      } 
@@ -62,70 +60,61 @@ export default {
6260    _setPropertyValues ( propertyValues )  { 
6361      this . db . set ( "propertyValues" ,  propertyValues ) ; 
6462    } , 
63+     async  getProperties ( )  { 
64+       if  ( this . properties ?. length )  { 
65+         return  this . properties ; 
66+       } 
67+       const  {  properties }  =  await  this . notion . retrieveDatabase ( this . databaseId ) ; 
68+       return  Object . keys ( properties ) ; 
69+     } , 
70+     generateMeta ( obj ,  summary )  { 
71+       const  {  id }  =  obj ; 
72+       const  title  =  this . notion . extractPageTitle ( obj ) ; 
73+       const  ts  =  Date . now ( ) ; 
74+       return  { 
75+         id : `${ id } ${ ts }  , 
76+         summary : `${ summary } ${ title } ${ id }  , 
77+         ts, 
78+       } ; 
79+     } , 
6580  } , 
6681  async  run ( )  { 
6782    const  lastCheckedTimestamp  =  this . getLastUpdatedTimestamp ( ) ; 
68-     const  lastCheckedTimestampDate  =  new  Date ( lastCheckedTimestamp ) ; 
69-     const  lastCheckedTimestampISO  =  lastCheckedTimestampDate . toISOString ( ) ; 
7083    const  propertyValues  =  this . _getPropertyValues ( ) ; 
7184
72-     // Add a filter so that we only receive pages that have been updated since the last call. 
7385    const  params  =  { 
7486      ...this . lastUpdatedSortParam ( ) , 
75-       filter : { 
76-         timestamp : "last_edited_time" , 
77-         last_edited_time : { 
78-           after : lastCheckedTimestampISO , 
79-         } , 
80-       } , 
8187    } ; 
8288    let  newLastUpdatedTimestamp  =  lastCheckedTimestamp ; 
83- 
89+      const   properties   =   await   this . getProperties ( ) ; 
8490    const  pagesStream  =  this . notion . getPages ( this . databaseId ,  params ) ; 
8591
8692    for  await  ( const  page  of  pagesStream )  { 
87-       if  ( ! this . isResultNew ( page . last_edited_time ,  lastCheckedTimestamp ) )  { 
88-         // The call to getPages() includes a descending sort by last_edited_time. 
89-         // As soon as one page !isResultNew(), all of the following ones will also. 
90-         // NOTE: the last_edited_filter means this will never be called, 
91-         // but it's worth keeping as future-proofing. 
92-         break ; 
93-       } 
94- 
9593      newLastUpdatedTimestamp  =  Math . max ( 
9694        newLastUpdatedTimestamp , 
9795        Date . parse ( page ?. last_edited_time ) , 
9896      ) ; 
9997
100-       if  ( this . properties ?. length )  { 
101-         let  propertyChangeFound  =  false ; 
102-         for  ( const  property  of  this . properties )  { 
103-           const  currentProperty  =  JSON . stringify ( page . properties [ property ] ) ; 
104-           if  ( ! propertyValues [ page . id ]  ||  currentProperty  !==  propertyValues [ page . id ] [ property ] )  { 
105-             propertyChangeFound  =  true ; 
106-             propertyValues [ page . id ]  =  { 
107-               ...propertyValues [ page . id ] , 
108-               [ property ] : currentProperty , 
109-             } ; 
110-           } 
111-         } 
112-         if  ( ! propertyChangeFound )  { 
113-           continue ; 
98+       let  propertyChangeFound  =  false ; 
99+       for  ( const  property  of  properties )  { 
100+         const  currentProperty  =  JSON . stringify ( page . properties [ property ] ) ; 
101+         if  ( ! propertyValues [ page . id ]  ||  currentProperty  !==  propertyValues [ page . id ] [ property ] )  { 
102+           propertyChangeFound  =  true ; 
103+           propertyValues [ page . id ]  =  { 
104+             ...propertyValues [ page . id ] , 
105+             [ property ] : currentProperty , 
106+           } ; 
114107        } 
115108      } 
109+       if  ( ! propertyChangeFound  &&  Date . parse ( page ?. last_edited_time )  <=  lastCheckedTimestamp )  { 
110+         continue ; 
111+       } 
116112
117113      if  ( ! this . includeNewPages  &&  page ?. last_edited_time  ===  page ?. created_time )  { 
118114        continue ; 
119115      } 
120116
121-       const  meta  =  this . generateMeta ( 
122-         page , 
123-         constants . types . PAGE , 
124-         constants . timestamps . LAST_EDITED_TIME , 
125-         constants . summaries . PAGE_UPDATED , 
126-         true , 
127-       ) ; 
128- 
117+       const  meta  =  this . generateMeta ( page ,  constants . summaries . PAGE_UPDATED ) ; 
129118      this . $emit ( page ,  meta ) ; 
130119    } 
131120
0 commit comments