Skip to content

Commit 9e744c7

Browse files
Add TTL functionality to Data Store actions (#15824)
* Add TTL functionality to Data Store actions - Added TTL prop to all Data Store actions to support record expiration - Created helper methods for human-readable TTL formatting - Added a new "Update record expiration" action for modifying TTL on existing records - Added preset TTL options for common time periods - Improved summaries and return values with TTL information 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Update pnpm-lock.yaml * Update TTL max limit to 1 year and increment versions of all data store actions * Update components/data_stores/actions/update-ttl/update-ttl.mjs Co-authored-by: Guilherme Falcão <[email protected]> --------- Co-authored-by: Guilherme Falcão <[email protected]>
1 parent 3a09673 commit 9e744c7

File tree

16 files changed

+292
-31
lines changed

16 files changed

+292
-31
lines changed

components/data_stores/actions/add-update-multiple-records/add-update-multiple-records.mjs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "data_stores-add-update-multiple-records",
55
name: "Add or update multiple records",
66
description: "Add or update multiple records to your [Pipedream Data Store](https://pipedream.com/data-stores/).",
7-
version: "0.0.6",
7+
version: "0.0.7",
88
type: "action",
99
props: {
1010
app,
@@ -19,6 +19,12 @@ export default {
1919
type: "object",
2020
description: "Enter data you'd like to add as key-value pairs, or reference an object from a previous step using a custom expression (e.g., `{{steps.data.$return_value}}`). Note that any keys that are duplicated will get overwritten with the last value entered (so `[{jerry: \"constanza\", jerry: \"seinfeld\"}]` will get stored as `[{jerry: \"seinfeld\"}]`).",
2121
},
22+
ttl: {
23+
propDefinition: [
24+
app,
25+
"ttl",
26+
],
27+
},
2228
},
2329
methods: {
2430
/**
@@ -83,14 +89,30 @@ export default {
8389
}
8490
const map = this.getHashMapOfData(this.data);
8591
const keys = Object.keys(map);
86-
const promises = Object.keys(map).map((key) => this.dataStore.set(key, map[key]));
92+
93+
const promises = Object.keys(map).map((key) => {
94+
if (this.ttl) {
95+
return this.dataStore.set(key, map[key], {
96+
ttl: this.ttl,
97+
});
98+
} else {
99+
return this.dataStore.set(key, map[key]);
100+
}
101+
});
102+
87103
await Promise.all(promises);
104+
88105
if (keys.length === 0) {
89106
$.export("$summary", "No data was added to the data store.");
90107
} else {
91108
// eslint-disable-next-line multiline-ternary
92-
$.export("$summary", `Successfully added or updated ${keys.length} record${keys.length === 1 ? "" : "s"}`);
109+
$.export("$summary", `Successfully added or updated ${keys.length} record${keys.length === 1 ? "" : "s"}${this.ttl ? ` (expires in ${this.app.formatTtl(this.ttl)})` : ""}`);
93110
}
94-
return map;
111+
112+
// Include TTL in the returned map
113+
return {
114+
...map,
115+
_ttl: this.ttl || null,
116+
};
95117
},
96118
};

components/data_stores/actions/add-update-record/add-update-record.mjs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "data_stores-add-update-record",
55
name: "Add or update a single record",
66
description: "Add or update a single record in your [Pipedream Data Store](https://pipedream.com/data-stores/).",
7-
version: "0.0.9",
7+
version: "0.0.10",
88
type: "action",
99
props: {
1010
app,
@@ -30,20 +30,36 @@ export default {
3030
"value",
3131
],
3232
},
33+
ttl: {
34+
propDefinition: [
35+
app,
36+
"ttl",
37+
],
38+
},
3339
},
3440
async run({ $ }) {
3541
const {
3642
key,
3743
value,
44+
ttl,
3845
} = this;
3946
const exists = await this.dataStore.has(key);
4047
const parsedValue = this.app.parseValue(value);
41-
await this.dataStore.set(key, parsedValue);
48+
49+
if (ttl) {
50+
await this.dataStore.set(key, parsedValue, {
51+
ttl,
52+
});
53+
} else {
54+
await this.dataStore.set(key, parsedValue);
55+
}
56+
4257
// eslint-disable-next-line multiline-ternary
43-
$.export("$summary", `Successfully ${exists ? "updated the record for" : "added a new record with the"} key, \`${key}\`.`);
58+
$.export("$summary", `Successfully ${exists ? "updated the record for" : "added a new record with the"} key, \`${key}\`${ttl ? ` (expires in ${this.app.formatTtl(ttl)})` : ""}.`);
4459
return {
4560
key,
4661
value: parsedValue,
62+
ttl: ttl || null,
4763
};
4864
},
4965
};

components/data_stores/actions/append-to-record/append-to-record.mjs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "data_stores-append-to-record",
66
name: "Append to record",
77
description: "Append to a record in your data store [Pipedream Data Store](https://pipedream.com/data-stores/). If the record does not exist, a new record will be created in an array format.",
8-
version: "0.0.2",
8+
version: "0.0.3",
99
type: "action",
1010
props: {
1111
app,
@@ -31,11 +31,18 @@ export default {
3131
"value",
3232
],
3333
},
34+
ttl: {
35+
propDefinition: [
36+
app,
37+
"ttl",
38+
],
39+
},
3440
},
3541
async run({ $ }) {
3642
const {
3743
key,
3844
value,
45+
ttl,
3946
} = this;
4047
const currentValue = await this.dataStore.get(key);
4148
if (currentValue && !Array.isArray(currentValue)) {
@@ -44,12 +51,23 @@ export default {
4451
const recordSet = currentValue ?? [];
4552
const parsedValue = this.app.parseValue(value);
4653
recordSet.push(parsedValue);
47-
await this.dataStore.set(key, recordSet);
48-
// eslint-disable-next-line multiline-ternary
49-
$.export("$summary", `Successfully ${currentValue ? "appended to the record for" : "created new record with the"} key: \`${key}\`.`);
54+
55+
if (ttl) {
56+
await this.dataStore.set(key, recordSet, {
57+
ttl,
58+
});
59+
// eslint-disable-next-line multiline-ternary
60+
$.export("$summary", `Successfully ${currentValue ? "appended to the record for" : "created new record with the"} key: \`${key}\` (expires in ${this.app.formatTtl(ttl)}).`);
61+
} else {
62+
await this.dataStore.set(key, recordSet);
63+
// eslint-disable-next-line multiline-ternary
64+
$.export("$summary", `Successfully ${currentValue ? "appended to the record for" : "created new record with the"} key: \`${key}\`.`);
65+
}
66+
5067
return {
5168
key,
5269
value: parsedValue,
70+
ttl: ttl || null,
5371
};
5472
},
5573
};

components/data_stores/actions/delete-all-records/delete-all-records.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "data_stores-delete-all-records",
55
name: "Delete All Records",
66
description: "Delete all records in your [Pipedream Data Store](https://pipedream.com/data-stores/).",
7-
version: "0.0.2",
7+
version: "0.0.3",
88
type: "action",
99
props: {
1010
app,

components/data_stores/actions/delete-single-record/delete-single-record.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "data_stores-delete-single-record",
55
name: "Delete a single record",
66
description: "Delete a single record in your [Pipedream Data Store](https://pipedream.com/data-stores/).",
7-
version: "0.0.8",
7+
version: "0.0.9",
88
type: "action",
99
props: {
1010
app,

components/data_stores/actions/get-all-records/get-all-records.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "data_stores-get-all-records",
55
name: "Get all records",
66
description: "Get all records in your [Pipedream Data Store](https://pipedream.com/data-stores/). The memory consumption of the workflow can be affected, since this action will be exposing, to the workflow, the entire data from the selected datastore.",
7-
version: "0.0.3",
7+
version: "0.0.4",
88
type: "action",
99
props: {
1010
app,

components/data_stores/actions/get-difference/get-difference.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "data_stores-get-difference",
66
name: "Get Difference",
77
description: "Get the difference between two data stores. Result contains key/value pairs where the key exists in one data store, but not the other. [Pipedream Data Stores](https://pipedream.com/data-stores/).",
8-
version: "0.0.2",
8+
version: "0.0.3",
99
type: "action",
1010
props: {
1111
app,

components/data_stores/actions/get-record-keys/get-record-keys.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "data_stores-get-record-keys",
55
name: "Get Record Keys",
66
description: "Get all record keys in your [Pipedream Data Store](https://pipedream.com/data-stores/) that matches with your query. The memory consumption of the workflow can be affected, since this action will be exposing, to the workflow, the entire data from the selected datastore",
7-
version: "0.0.3",
7+
version: "0.0.4",
88
type: "action",
99
props: {
1010
app,

components/data_stores/actions/get-record-or-create/get-record-or-create.mjs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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.10",
7+
version: "0.0.11",
88
type: "action",
99
props: {
1010
app,
@@ -30,6 +30,12 @@ export default {
3030
"addRecordIfNotFound",
3131
],
3232
},
33+
ttl: {
34+
propDefinition: [
35+
app,
36+
"ttl",
37+
],
38+
},
3339
},
3440
async additionalProps() {
3541
const props = {};
@@ -52,8 +58,25 @@ export default {
5258
}
5359

5460
const parsedValue = this.app.parseValue(this.value);
55-
await this.dataStore.set(this.key, parsedValue);
56-
$.export("$summary", `Successfully added a new record with the key, \`${this.key}\`.`);
61+
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+
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+
};
78+
}
79+
5780
return parsedValue;
5881
},
5982
};

components/data_stores/actions/has-key-or-create/has-key-or-create.mjs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "data_stores-has-key-or-create",
55
name: "Check for existence of key",
66
description: "Check if a key exists in your [Pipedream Data Store](https://pipedream.com/data-stores/) or create one if it doesn't exist.",
7-
version: "0.1.2",
7+
version: "0.1.3",
88
type: "action",
99
props: {
1010
app,
@@ -30,6 +30,12 @@ export default {
3030
"addRecordIfNotFound",
3131
],
3232
},
33+
ttl: {
34+
propDefinition: [
35+
app,
36+
"ttl",
37+
],
38+
},
3339
},
3440
async additionalProps() {
3541
const props = {};
@@ -58,13 +64,22 @@ export default {
5864
}
5965

6066
const parsedValue = this.app.parseValue(this.value);
61-
await this.dataStore.set(this.key, parsedValue);
62-
$.export("$summary", `Key \`${this.key}\` was not found. Successfully added a new record.`);
67+
68+
if (this.ttl) {
69+
await this.dataStore.set(this.key, parsedValue, {
70+
ttl: this.ttl,
71+
});
72+
$.export("$summary", `Key \`${this.key}\` was not found. Successfully added a new record (expires in ${this.app.formatTtl(this.ttl)}).`);
73+
} else {
74+
await this.dataStore.set(this.key, parsedValue);
75+
$.export("$summary", `Key \`${this.key}\` was not found. Successfully added a new record.`);
76+
}
6377

6478
return {
6579
existingKeyFound: false,
6680
newKeyCreated: true,
6781
value: parsedValue,
82+
ttl: this.ttl || null,
6883
};
6984
},
7085
};

0 commit comments

Comments
 (0)