-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Memento Database - new components #19537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
michelle0927
wants to merge
3
commits into
master
Choose a base branch
from
issue-17639
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+518
−13
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
components/memento_database/actions/create-entry/create-entry.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
31
components/memento_database/actions/get-library/get-library.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
63
components/memento_database/actions/list-entries/list-entries.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
51
components/memento_database/actions/update-entry/update-entry.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| }; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }]`", | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| 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, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.