@@ -6,7 +6,7 @@ export default {
66 key : "mongodb-new-document" ,
77 name : "New Document" ,
88 description : "Emit new an event when a new document is added to a collection" ,
9- version : "0.0.11 " ,
9+ version : "0.0.12 " ,
1010 type : "source" ,
1111 dedupe : "unique" ,
1212 props : {
@@ -39,6 +39,7 @@ export default {
3939 options : [
4040 "Timestamp" ,
4141 "Integer" ,
42+ "ISO8601" ,
4243 ] ,
4344 } ,
4445 } ,
@@ -57,22 +58,32 @@ export default {
5758 _setLastTs ( lastTs ) {
5859 this . db . set ( "lastTs" , lastTs ) ;
5960 } ,
60- getTs ( doc ) {
61- const tsValue = doc [ this . timestampField ] ;
61+ makeTs ( timestamp ) {
6262 if ( this . timestampFieldType === "Integer" ) {
63- return tsValue ;
63+ return timestamp ;
6464 }
65- if ( typeof tsValue === "string " ) {
66- return new Date ( tsValue ) . getTime ( ) ;
65+ if ( this . timestampFieldType === "Timestamp " ) {
66+ return this . convertToTimestamp ( timestamp ) ;
6767 }
68- try {
69- return JSON . parse ( tsValue ) ;
70- } catch {
71- return tsValue ;
68+ if ( this . timestampFieldType === "ISO8601" ) {
69+ return new Date ( timestamp ) ;
7270 }
71+ return timestamp ;
7372 } ,
74- convertToTimestamp ( timestampStr ) {
75- const bigIntValue = BigInt ( timestampStr ) ;
73+ getTs ( timestamp ) {
74+ if ( this . timestampFieldType === "Integer" ) {
75+ return timestamp ;
76+ }
77+ if ( this . timestampFieldType === "Timestamp" ) {
78+ return timestamp . getHighBits ( ) * 1_000 ;
79+ }
80+ if ( this . timestampFieldType === "ISO8601" ) {
81+ return new Date ( timestamp ) . getTime ( ) ;
82+ }
83+ return timestamp ;
84+ } ,
85+ convertToTimestamp ( timestamp ) {
86+ const bigIntValue = BigInt ( timestamp . toString ( ) ) ;
7687 const seconds = Number ( bigIntValue >> 32n ) ;
7788 const increment = Number ( bigIntValue & 0xFFFFFFFFn ) ;
7889 return new Timestamp ( {
@@ -90,16 +101,16 @@ export default {
90101 } ;
91102 const query = {
92103 [ this . timestampField ] : {
93- $gt : this . timestampFieldType === "Integer"
94- ? lastTs
95- : this . convertToTimestamp ( lastTs ) ,
104+ $gt : this . makeTs ( lastTs ) ,
96105 } ,
97106 } ;
98- const documents = await collection . find ( query ) . sort ( sort )
107+ const documents = await collection
108+ . find ( query )
109+ . sort ( sort )
99110 . toArray ( ) ;
100111 const docs = [ ] ;
101112 for ( const doc of documents ) {
102- const ts = this . getTs ( doc ) ;
113+ const ts = this . getTs ( doc [ this . timestampField ] ) ;
103114 if ( ! ( ts > lastTs ) || ( max && count >= max ) ) {
104115 break ;
105116 }
0 commit comments