Skip to content
Open
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
41 changes: 41 additions & 0 deletions components/memento_database/actions/create-entry/create-entry.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import mementoDatabase from "../../memento_database.app.mjs";
import { parseJson } from "../../common/utils.mjs";

export default {
key: "memento_database-create-entry",
name: "Create Entry",
description: "Create an entry in a library on Memento Database. [See the documentation](https://mementodatabase.docs.apiary.io/#reference/0/entries/create-a-new-entry)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
props: {
mementoDatabase,
libraryId: {
propDefinition: [
mementoDatabase,
"libraryId",
],
},
fields: {
propDefinition: [
mementoDatabase,
"fields",
],
},
},
async run({ $ }) {
const entry = await this.mementoDatabase.createEntry({
$,
libraryId: this.libraryId,
data: {
fields: parseJson(this.fields),
},
});
$.export("$summary", `Successfully created entry with ID: ${entry.id}`);
return entry;
},
};
31 changes: 31 additions & 0 deletions components/memento_database/actions/get-library/get-library.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import mementoDatabase from "../../memento_database.app.mjs";

export default {
key: "memento_database-get-library",
name: "Get Library",
description: "Get a library by ID on Memento Database. [See the documentation](https://mementodatabase.docs.apiary.io/#reference/0/library/get-a-library)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
mementoDatabase,
libraryId: {
propDefinition: [
mementoDatabase,
"libraryId",
],
},
},
async run({ $ }) {
const library = await this.mementoDatabase.getLibrary({
$,
libraryId: this.libraryId,
});
$.export("$summary", `Successfully retrieved library with ID: ${library.id}`);
return library;
},
};
63 changes: 63 additions & 0 deletions components/memento_database/actions/list-entries/list-entries.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import mementoDatabase from "../../memento_database.app.mjs";

export default {
key: "memento_database-list-entries",
name: "List Entries",
description: "List entries in a library on Memento Database. [See the documentation](https://mementodatabase.docs.apiary.io/#reference/0/entries/list-entries-on-a-library)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
mementoDatabase,
libraryId: {
propDefinition: [
mementoDatabase,
"libraryId",
],
},
fields: {
type: "string",
label: "Fields",
description: "The comma-separated list of fields ids to include in the response. *all - include all fields.",
default: "all",
},
startRevision: {
type: "integer",
label: "Start Revision",
description: "Only entries updated/created at or after this revision are returned",
optional: true,
},
pageToken: {
type: "string",
label: "Page Token",
description: "The token for continuing a previous list request on the next page",
optional: true,
},
pageSize: {
type: "integer",
label: "Page Size",
description: "The maximum number of entries to return",
optional: true,
},
},
async run({ $ }) {
const response = await this.mementoDatabase.listEntries({
$,
libraryId: this.libraryId,
params: {
fields: this.fields,
startRevision: this.startRevision,
pageSize: this.pageSize,
pageToken: this.pageToken,
},
});
$.export("$summary", `Successfully listed ${response.entries.length} entr${response.entries.length === 1
? "y"
: "ies"}`);
return response;
},
};
51 changes: 51 additions & 0 deletions components/memento_database/actions/update-entry/update-entry.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import mementoDatabase from "../../memento_database.app.mjs";
import { parseJson } from "../../common/utils.mjs";

export default {
key: "memento_database-update-entry",
name: "Update Entry",
description: "Update an entry in a library on Memento Database. [See the documentation](https://mementodatabase.docs.apiary.io/#reference/0/entry/edit-an-entry)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: true,
openWorldHint: true,
readOnlyHint: false,
},
props: {
mementoDatabase,
libraryId: {
propDefinition: [
mementoDatabase,
"libraryId",
],
},
entryId: {
propDefinition: [
mementoDatabase,
"entryId",
(c) => ({
libraryId: c.libraryId,
}),
],
},
fields: {
propDefinition: [
mementoDatabase,
"fields",
],
},
},
async run({ $ }) {
const entry = await this.mementoDatabase.updateEntry({
$,
libraryId: this.libraryId,
entryId: this.entryId,
data: {
fields: parseJson(this.fields),
},
});
$.export("$summary", `Successfully updated entry with ID: ${entry.id}`);
return entry;
},
};
40 changes: 40 additions & 0 deletions components/memento_database/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export const parseJson = (input, maxDepth = 100) => {
const seen = new WeakSet();
const parse = (value) => {
if (maxDepth <= 0) {
return value;
}
if (typeof(value) === "string") {
// Only parse if the string looks like a JSON object or array
const trimmed = value.trim();
if (
(trimmed.startsWith("{") && trimmed.endsWith("}")) ||
(trimmed.startsWith("[") && trimmed.endsWith("]"))
) {
try {
return parseJson(JSON.parse(value), maxDepth - 1);
} catch (e) {
return value;
}
}
return value;
} else if (typeof(value) === "object" && value !== null && !Array.isArray(value)) {
if (seen.has(value)) {
return value;
}
seen.add(value);
return Object.entries(value)
.reduce((acc, [
key,
val,
]) => Object.assign(acc, {
[key]: parse(val),
}), {});
} else if (Array.isArray(value)) {
return value.map((item) => parse(item));
}
return value;
};

return parse(input);
};
108 changes: 104 additions & 4 deletions components/memento_database/memento_database.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,111 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "memento_database",
propDefinitions: {},
propDefinitions: {
libraryId: {
type: "string",
label: "Library ID",
description: "The ID of a library",
async options() {
const { libraries } = await this.listLibraries();
return libraries?.map(({
id: value, name: label,
}) => ({
value,
label,
})) || [];
},
},
entryId: {
type: "string",
label: "Entry ID",
description: "The ID of an entry",
async options({
libraryId, prevContext,
}) {
const {
entries, nextPageToken,
} = await this.listEntries({
libraryId,
params: {
pageToken: prevContext?.pageToken,
},
});
const options = entries?.map(({ id }) => ({
value: id,
label: `Entry ${id}`,
})) || [];
return {
options,
context: {
pageToken: nextPageToken,
},
};
},
},
fields: {
type: "string[]",
label: "Fields",
description: "An array of objects containing the fields of the entry. Note: The field IDs must already exist in the library. Example: `[{ \"id\": 1, \"value\": \"Record 1\" }, { \"id\": 2, \"value\": 1000 }]`",
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.mementodatabase.com/v1";
},
_makeRequest({
$ = this, path, params, ...opts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
params: {
...params,
token: `${this.$auth.api_token}`,
},
...opts,
});
},
getLibrary({
libraryId, ...opts
}) {
return this._makeRequest({
path: `/libraries/${libraryId}`,
...opts,
});
},
listLibraries(opts = {}) {
return this._makeRequest({
path: "/libraries",
...opts,
});
},
listEntries({
libraryId, ...opts
}) {
return this._makeRequest({
path: `/libraries/${libraryId}/entries`,
...opts,
});
},
createEntry({
libraryId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/libraries/${libraryId}/entries`,
...opts,
});
},
updateEntry({
libraryId, entryId, ...opts
}) {
return this._makeRequest({
method: "PATCH",
path: `/libraries/${libraryId}/entries/${entryId}`,
...opts,
});
},
},
};
7 changes: 5 additions & 2 deletions components/memento_database/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/memento_database",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Memento Database Components",
"main": "memento_database.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.1"
}
}
}
Loading
Loading