kleros / kleros-v2

Kleros version 2
https://v2.kleros.builders
MIT License
58 stars 41 forks source link

chore(sdk): making the curate v2 mappings work #1619

Closed kemuru closed 1 month ago

kemuru commented 2 months ago

ready for review.

LATEST UPDATE: I updated replacePlaceholdersWithValues() to use mustache instead of the direct string manipulation it was doing. I updated the Escrow V2 and Curate V2 mappings to add triple curly braches in some places too, you can find these updated mappings in the links below. contract would need to be updated with the updated templates/mappings too.

This PR makes the curate v2 mappings work. Also allows accessing indexes of an array returned by the subgraph.

How to check that the mappings work:

1) go to https://deploy-preview-1619--kleros-v2.netlify.app/#/dispute-template 2) paste these 3 things: externalDisputeID, template, and data mappings. You will find them below:

Curate V2 template and mappings: https://github.com/kleros/curate-v2/issues/33#issuecomment-2174530564 Escrow V2 template and mappings: https://github.com/kleros/escrow-v2/issues/12#issuecomment-2081673981

The idea is that, with just an externalDisputeID, we are able to populate all the needed information from any arbitrable, such as escrow v2, curate v2, or any arbitrable that we integrate with. that would be ideal and would make integrations super easy

We should make this SDK super bullet proof and understandable, make it a good dev experience, not only for the projects we integrate with, but also for us while building this.

(OUTDATED...

image

)

(OUTDATED.... on the SDK, I reverted some of the changes to jsonAction() and replacePlaceholdersWithValues(). basically Aleix reviewed and I realized that my changes are a hacky way to make the curate v2 "json" mapping work, but it will break normal jsons. context: we upload the item data json and registry metadata json with a different format to the contracts (picture 2) (subgraph link here with the query) and our jsonAction() mapping can't parse that. possible solutions?: upload the item data json and registry metadata jsons, with the supported format directly, or, make the jsonAction() mapping more sophisticated and handle the both cases (normal jsons, and stringified jsons with backlashes "\") correctly)

image (35)

image (36)

IGNORE:

some JSON Mappings I need to paste here to not lose this info, this is for testing purposes, ignore:

template:

{
    "title": "A reality.eth question",
    "description": "A reality.eth question has been raised to arbitration.",
    "question": "{{ question }}",
    "type": "{{ type }}",
    "answers": [
        "{{# answers }}",
        {
            "title": "{{ title }}",
            "description": "{{ description }}",
            "id": "{{ id }}",
            "reserved": "{{ reserved }}"
        },"{{^ last }}","{{/ last }}",
        "{{/ answers }}"

    ],
    "policyURI": "/ipfs/QmZ5XaV2RVgBADq5qMpbuEwgCuPZdRgCeu8rhGtJWLV6yz",
    "frontendUrl": "https://reality.eth.limo/app/#!/question/{{ realityAddress }}-{{ questionId }}",
    "arbitrableChainID": "100",
    "arbitrableAddress": "0x2e39b8f43d0870ba896f516f78f57cde773cf805",
    "arbitratorChainID": "421613",
    "arbitratorAddress": "0xD08Ab99480d02bf9C092828043f611BcDFEA917b",
    "category": "Oracle",
    "lang": "en_US",
    "specification": "KIP99",
    "version": "1.0"
}

data mappings:

[
  {
    "type": "json",
    "value": {
      "source": "**Kleros Moderate:** Did the user, **degenape6** (ID: 1554345080), break the Telegram group, ***[Kleros Trading Group]()*** (ID: -1001151472172), ***[rules](https://cdn.kleros.link/ipfs/Qme3Qbj9rKUNHUe9vj9rqCLnTVUCWKy2YfveQF8HiuWQSu/Kleros%20Moderate%20Community%20Rules.pdf)*** due to conduct related to the ***[message](https://t.me/c/1151472172/116662)*** (***[backup](https://cdn.kleros.link/ipfs/QmVbFrZR1bcyQzZjvLyXwL9ekDxrqHERykdreRxXrw4nqg/animations_file_23.mp4)***)?",
      "type": "single-select",
      "answers": [
        {
          "title": "Refuse to Arbitrate or Invalid",
          "id": "0x00",
          "reserved": true
        }
      ],
      "question": "0xe2a3bd38e3ad4e22336ac35b221bbbdd808d716209f84014c7bc3bf62f8e3b39",
      "realityAddress": "0x14a6748192aBC6E10CA694Ae07bDd4327D6c7A51"
    },
    "seek": [
      "source",
      "type",
      "answers",
      "realityAddress"
    ],
    "populate": [
      "question",
      "type",
      "answers",
      "realityAddress"
    ]
  }
]

PR-Codex overview

The focus of this PR is to improve data mapping functionality in the kleros-sdk by enhancing JSON parsing and placeholder replacement.

Detailed summary

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

These changes improve the overall functionality and reliability of the data mapping processes.

coderabbitai[bot] commented 2 months ago

Walkthrough

The recent updates mainly enhance the kleros-sdk by introducing JSON parsing, refining object property handling, and improving string placeholder replacements. Key changes include JSON parsing in jsonAction function, the addition of a nested property access helper in createResultObject, and enhanced replacePlaceholdersWithValues functionality using the mustache library.

Changes

File Path Change Summary
.../jsonAction.ts Added JSON parsing for value before processing.
.../executeActions.ts Introduced a blank line after the await executeAction call, no functional changes.
.../createResultObject.ts Changed seek and populate to arrays, added nested property access helper (getNestedValue).
.../replacePlaceholdersWithValues.ts Improved placeholder replacements using mustache, added logic for string pattern handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SDK as kleros-sdk
    participant JsonAction as jsonAction
    participant ResultObj as createResultObject

    User->>SDK: Call jsonAction with mapping
    SDK->>JsonAction: jsonAction(mapping)
    JsonAction->>JsonAction: Parse value if string
    JsonAction-->>ResultObj: createResultObject(parsedValue, seek, populate)
    ResultObj->>JsonAction: Return result
    JsonAction->>SDK: Return result
    SDK->>User: Provide processed result

Poem

In the land of code so bright,
Where JSON strings take flight,
Nested keys with glee,
Unlock truths like a key,
Through mustache and seek,
Data's future, sleek,
For devs, a wondrous sight!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
netlify[bot] commented 2 months ago

Deploy Preview for kleros-v2-university failed. Why did it fail? →

Name Link
Latest commit 1620fdaa1b7f7557223638054c449cbe786dbbd2
Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/6670c7c2644c690008f417f4
netlify[bot] commented 2 months ago

Deploy Preview for kleros-v2 ready!

Name Link
Latest commit 1620fdaa1b7f7557223638054c449cbe786dbbd2
Latest deploy log https://app.netlify.com/sites/kleros-v2/deploys/6670c7c2ec8ef10008cbc1fa
Deploy Preview https://deploy-preview-1619--kleros-v2.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] commented 2 months ago

Deploy Preview for kleros-v2-neo ready!

Name Link
Latest commit 1620fdaa1b7f7557223638054c449cbe786dbbd2
Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/6670c7c20406550008d8bf7c
Deploy Preview https://deploy-preview-1619--kleros-v2-neo.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] commented 2 months ago

Deploy Preview for kleros-v2-university failed. Why did it fail? →

Name Link
Latest commit 78dbbf69139004d751475f44dd5811ef6a52329d
Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/667a20f56fc82300082768f1
netlify[bot] commented 2 months ago

Deploy Preview for kleros-v2-neo ready!

Name Link
Latest commit 78dbbf69139004d751475f44dd5811ef6a52329d
Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/667a20f585c1660008900f28
Deploy Preview https://deploy-preview-1619--kleros-v2-neo.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] commented 2 months ago

Deploy Preview for kleros-v2 ready!

Name Link
Latest commit 78dbbf69139004d751475f44dd5811ef6a52329d
Latest deploy log https://app.netlify.com/sites/kleros-v2/deploys/667a20f5c147fc0008436eb9
Deploy Preview https://deploy-preview-1619--kleros-v2.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

codeclimate[bot] commented 1 month ago

Code Climate has analyzed commit 78dbbf69 and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 2

View more on Code Climate.

sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud