Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "data_stores-add-update-multiple-records",
name: "Add or update multiple records",
description: "Add or update multiple records to your [Pipedream Data Store](https://pipedream.com/data-stores/).",
version: "0.0.6",
version: "0.0.7",
type: "action",
props: {
app,
Expand All @@ -19,6 +19,12 @@ export default {
type: "object",
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\"}]`).",
},
ttl: {
propDefinition: [
app,
"ttl",
],
},
},
methods: {
/**
Expand Down Expand Up @@ -83,14 +89,30 @@ export default {
}
const map = this.getHashMapOfData(this.data);
const keys = Object.keys(map);
const promises = Object.keys(map).map((key) => this.dataStore.set(key, map[key]));

const promises = Object.keys(map).map((key) => {
if (this.ttl) {
return this.dataStore.set(key, map[key], {
ttl: this.ttl,
});
} else {
return this.dataStore.set(key, map[key]);
}
});

await Promise.all(promises);

if (keys.length === 0) {
$.export("$summary", "No data was added to the data store.");
} else {
// eslint-disable-next-line multiline-ternary
$.export("$summary", `Successfully added or updated ${keys.length} record${keys.length === 1 ? "" : "s"}`);
$.export("$summary", `Successfully added or updated ${keys.length} record${keys.length === 1 ? "" : "s"}${this.ttl ? ` (expires in ${this.app.formatTtl(this.ttl)})` : ""}`);
}
return map;

// Include TTL in the returned map
return {
...map,
_ttl: this.ttl || null,
};
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "data_stores-add-update-record",
name: "Add or update a single record",
description: "Add or update a single record in your [Pipedream Data Store](https://pipedream.com/data-stores/).",
version: "0.0.9",
version: "0.0.10",
type: "action",
props: {
app,
Expand All @@ -30,20 +30,36 @@ export default {
"value",
],
},
ttl: {
propDefinition: [
app,
"ttl",
],
},
},
async run({ $ }) {
const {
key,
value,
ttl,
} = this;
const exists = await this.dataStore.has(key);
const parsedValue = this.app.parseValue(value);
await this.dataStore.set(key, parsedValue);

if (ttl) {
await this.dataStore.set(key, parsedValue, {
ttl,
});
} else {
await this.dataStore.set(key, parsedValue);
}

// eslint-disable-next-line multiline-ternary
$.export("$summary", `Successfully ${exists ? "updated the record for" : "added a new record with the"} key, \`${key}\`.`);
$.export("$summary", `Successfully ${exists ? "updated the record for" : "added a new record with the"} key, \`${key}\`${ttl ? ` (expires in ${this.app.formatTtl(ttl)})` : ""}.`);
return {
key,
value: parsedValue,
ttl: ttl || null,
};
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "data_stores-append-to-record",
name: "Append to record",
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.",
version: "0.0.2",
version: "0.0.3",
type: "action",
props: {
app,
Expand All @@ -31,11 +31,18 @@ export default {
"value",
],
},
ttl: {
propDefinition: [
app,
"ttl",
],
},
},
async run({ $ }) {
const {
key,
value,
ttl,
} = this;
const currentValue = await this.dataStore.get(key);
if (currentValue && !Array.isArray(currentValue)) {
Expand All @@ -44,12 +51,23 @@ export default {
const recordSet = currentValue ?? [];
const parsedValue = this.app.parseValue(value);
recordSet.push(parsedValue);
await this.dataStore.set(key, recordSet);
// eslint-disable-next-line multiline-ternary
$.export("$summary", `Successfully ${currentValue ? "appended to the record for" : "created new record with the"} key: \`${key}\`.`);

if (ttl) {
await this.dataStore.set(key, recordSet, {
ttl,
});
// eslint-disable-next-line multiline-ternary
$.export("$summary", `Successfully ${currentValue ? "appended to the record for" : "created new record with the"} key: \`${key}\` (expires in ${this.app.formatTtl(ttl)}).`);
} else {
await this.dataStore.set(key, recordSet);
// eslint-disable-next-line multiline-ternary
$.export("$summary", `Successfully ${currentValue ? "appended to the record for" : "created new record with the"} key: \`${key}\`.`);
}

return {
key,
value: parsedValue,
ttl: ttl || null,
};
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "data_stores-get-record-or-create",
name: "Get record (or create one if not found)",
description: "Get a single record in your [Pipedream Data Store](https://pipedream.com/data-stores/) or create one if it doesn't exist.",
version: "0.0.10",
version: "0.0.11",
type: "action",
props: {
app,
Expand All @@ -30,6 +30,12 @@ export default {
"addRecordIfNotFound",
],
},
ttl: {
propDefinition: [
app,
"ttl",
],
},
},
async additionalProps() {
const props = {};
Expand All @@ -52,8 +58,25 @@ export default {
}

const parsedValue = this.app.parseValue(this.value);
await this.dataStore.set(this.key, parsedValue);
$.export("$summary", `Successfully added a new record with the key, \`${this.key}\`.`);

if (this.ttl) {
await this.dataStore.set(this.key, parsedValue, {
ttl: this.ttl,
});
$.export("$summary", `Successfully added a new record with the key, \`${this.key}\` (expires in ${this.app.formatTtl(this.ttl)}).`);
} else {
await this.dataStore.set(this.key, parsedValue);
$.export("$summary", `Successfully added a new record with the key, \`${this.key}\`.`);
}

// Include TTL information in the return value if it was set
if (this.ttl) {
return {
value: parsedValue,
ttl: this.ttl,
};
}

return parsedValue;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "data_stores-has-key-or-create",
name: "Check for existence of key",
description: "Check if a key exists in your [Pipedream Data Store](https://pipedream.com/data-stores/) or create one if it doesn't exist.",
version: "0.1.2",
version: "0.1.3",
type: "action",
props: {
app,
Expand All @@ -30,6 +30,12 @@ export default {
"addRecordIfNotFound",
],
},
ttl: {
propDefinition: [
app,
"ttl",
],
},
},
async additionalProps() {
const props = {};
Expand Down Expand Up @@ -58,13 +64,22 @@ export default {
}

const parsedValue = this.app.parseValue(this.value);
await this.dataStore.set(this.key, parsedValue);
$.export("$summary", `Key \`${this.key}\` was not found. Successfully added a new record.`);

if (this.ttl) {
await this.dataStore.set(this.key, parsedValue, {
ttl: this.ttl,
});
$.export("$summary", `Key \`${this.key}\` was not found. Successfully added a new record (expires in ${this.app.formatTtl(this.ttl)}).`);
} else {
await this.dataStore.set(this.key, parsedValue);
$.export("$summary", `Key \`${this.key}\` was not found. Successfully added a new record.`);
}

return {
existingKeyFound: false,
newKeyCreated: true,
value: parsedValue,
ttl: this.ttl || null,
};
},
};
121 changes: 121 additions & 0 deletions components/data_stores/actions/update-ttl/update-ttl.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import app from "../../data_stores.app.mjs";

export default {
key: "data_stores-update-ttl",
name: "Update record expiration",
description: "Update the expiration time for a record in your [Pipedream Data Store](https://pipedream.com/data-stores/).",
version: "0.0.1",
type: "action",
props: {
app,
dataStore: {
propDefinition: [
app,
"dataStore",
],
},
key: {
propDefinition: [
app,
"key",
({ dataStore }) => ({
dataStore,
}),
],
description: "Select the key for the record you'd like to update the expiration time.",
},
ttlOption: {
type: "string",
label: "Expiration Type",
description: "Choose a common expiration time or specify a custom value",
options: [
{
label: "Custom value",
value: "custom",
},
{
label: "No expiration (remove expiry)",
value: "0",
},
{
label: "1 hour",
value: "3600",
},
{
label: "1 day",
value: "86400",
},
{
label: "1 week",
value: "604800",
},
{
label: "30 days",
value: "2592000",
},
{
label: "90 days",
value: "7776000",
},
{
label: "1 year",
value: "31536000",
},
],
reloadProps: true,
},
},
async additionalProps() {
const props = {};
if (this.ttlOption === "custom") {
props.ttl = {
type: "integer",
label: "Custom TTL (seconds)",
description: "The number of seconds until this record expires and is automatically deleted. Use 0 to remove expiration.",
min: 0,
max: 63072000, // 2 years (safe upper limit)
};
}
return props;
},
async run({ $ }) {
const {
key, ttlOption, ttl,
} = this;

// Determine TTL value to use
const ttlValue = ttlOption === "custom"
? ttl
: parseInt(ttlOption, 10);

if (!await this.dataStore.has(key)) {
$.export("$summary", `No record found with key \`${key}\`.`);
return {
success: false,
message: `No record found with key ${key}`,
};
}

if (ttlValue === 0) {
// Remove expiration
await this.dataStore.setTtl(key, null);
$.export("$summary", `Successfully removed expiration for key \`${key}\`.`);
return {
success: true,
key,
ttl: null,
message: "Expiration removed",
};
} else {
// Update TTL
await this.dataStore.setTtl(key, ttlValue);
$.export("$summary", `Successfully updated expiration for key \`${key}\` (expires in ${this.app.formatTtl(ttlValue)}).`);
return {
success: true,
key,
ttl: ttlValue,
ttlFormatted: this.app.formatTtl(ttlValue),
};
}
},
};
Loading
Loading