@@ -4,7 +4,7 @@ export default {
44 key : "data_stores-get-record-or-create" ,
55 name : "Get record (or create one if not found)" ,
66 description : "Get a single record in your [Pipedream Data Store](https://pipedream.com/data-stores/) or create one if it doesn't exist." ,
7- version : "0.0.11 " ,
7+ version : "0.0.12 " ,
88 type : "action" ,
99 props : {
1010 app,
@@ -46,37 +46,41 @@ export default {
4646 } ,
4747 async run ( { $ } ) {
4848 const record = await this . dataStore . get ( this . key ) ;
49+ let summary , response ;
4950
5051 if ( record !== undefined ) {
51- $ . export ( "$ summary" , `Found data for the key, \`${ this . key } \`.` ) ;
52- return record ;
52+ summary = `Found data for the key, \`${ this . key } \`.` ;
53+ response = record ;
5354 }
54-
55- if ( ! this . app . shouldAddRecord ( this . addRecordIfNotFound ) ) {
56- $ . export ( "$summary" , `No data found for key, \`${ this . key } \`.` ) ;
57- return ;
55+ else if ( ! this . app . shouldAddRecord ( this . addRecordIfNotFound ) ) {
56+ summary = `No data found for key, \`${ this . key } \`.` ;
5857 }
58+ else {
59+ const parsedValue = this . app . parseValue ( this . value ) ;
5960
60- const parsedValue = this . app . parseValue ( this . value ) ;
61+ if ( this . ttl ) {
62+ await this . dataStore . set ( this . key , parsedValue , {
63+ ttl : this . ttl ,
64+ } ) ;
65+ summary = `Successfully added a new record with the key, \`${ this . key } \` (expires in ${ this . app . formatTtl ( this . ttl ) } ).` ;
66+ } else {
67+ await this . dataStore . set ( this . key , parsedValue ) ;
68+ summary = `Successfully added a new record with the key, \`${ this . key } \`.` ;
69+ }
6170
62- if ( this . ttl ) {
63- await this . dataStore . set ( this . key , parsedValue , {
64- ttl : this . ttl ,
65- } ) ;
66- $ . export ( "$summary" , `Successfully added a new record with the key, \`${ this . key } \` (expires in ${ this . app . formatTtl ( this . ttl ) } ).` ) ;
67- } else {
68- await this . dataStore . set ( this . key , parsedValue ) ;
69- $ . export ( "$summary" , `Successfully added a new record with the key, \`${ this . key } \`.` ) ;
70- }
71+ // Include TTL information in the return value if it was set
72+ if ( this . ttl ) {
73+ return {
74+ value : parsedValue ,
75+ ttl : this . ttl ,
76+ } ;
77+ }
7178
72- // Include TTL information in the return value if it was set
73- if ( this . ttl ) {
74- return {
75- value : parsedValue ,
76- ttl : this . ttl ,
77- } ;
79+ response = parsedValue ;
7880 }
7981
80- return parsedValue ;
82+ $ . export ( "$summary" , summary ) ;
83+ $ . export ( "key" , this . key ) ;
84+ return response ;
8185 } ,
8286} ;
0 commit comments