Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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-delete-all-records",
name: "Delete All Records",
description: "Delete all records in your [Pipedream Data Store](https://pipedream.com/data-stores/).",
version: "0.0.2",
version: "0.0.3",
type: "action",
props: {
app,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "data_stores-delete-single-record",
name: "Delete a single record",
description: "Delete a single record in your [Pipedream Data Store](https://pipedream.com/data-stores/).",
version: "0.0.8",
version: "0.0.9",
type: "action",
props: {
app,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "data_stores-get-all-records",
name: "Get all records",
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.",
version: "0.0.3",
version: "0.0.4",
type: "action",
props: {
app,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "data_stores-get-difference",
name: "Get Difference",
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/).",
version: "0.0.2",
version: "0.0.3",
type: "action",
props: {
app,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "data_stores-get-record-keys",
name: "Get Record Keys",
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",
version: "0.0.3",
version: "0.0.4",
type: "action",
props: {
app,
Expand Down
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,
};
},
};
2 changes: 1 addition & 1 deletion components/data_stores/actions/list-keys/list-keys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "data_stores-list-keys",
name: "List keys",
description: "List all keys in your [Pipedream Data Store](https://pipedream.com/data-stores/).",
version: "0.0.2",
version: "0.0.3",
type: "action",
props: {
app,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "data_stores-list-records",
name: "List Records",
description: "List all records in your [Pipedream Data Store](https://pipedream.com/data-stores/).",
version: "0.0.3",
version: "0.0.4",
type: "action",
props: {
app,
Expand Down
Loading
Loading