Skip to content

feat(kleros-sdk): predefined-lambdas-for-mustache #2024

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
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

tractorss
Copy link
Contributor

@tractorss tractorss commented Jun 13, 2025

PR-Codex overview

This PR introduces a new utility function for converting values to hex representation and integrates it into the populateTemplate function to enhance data rendering capabilities.

Detailed summary

  • Added a new lambdas object in lambdas.ts with a hex function.
  • The hex function converts a string value to its hexadecimal representation.
  • Updated the populateTemplate function to include lambdas in the rendering process.

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

Summary by CodeRabbit

  • New Features
    • Added support for custom template functions, including a new function to convert numbers to hexadecimal format within templates.
  • Enhancements
    • Templates can now utilize additional built-in functions during rendering for more flexible data formatting.

@tractorss tractorss requested a review from a team as a code owner June 13, 2025 10:54
Copy link

netlify bot commented Jun 13, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 33a47a9
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet/deploys/684c04d4dd8452000825aa8a
😎 Deploy Preview https://deploy-preview-2024--kleros-v2-testnet.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 project configuration.

Copy link

netlify bot commented Jun 13, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit 33a47a9
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-neo/deploys/684c04d4925ad20008e363bb
😎 Deploy Preview https://deploy-preview-2024--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 project configuration.

Copy link
Contributor

coderabbitai bot commented Jun 13, 2025

"""

Walkthrough

A new utility object named lambdas is introduced, providing a hex method for string-to-hexadecimal conversion. The populateTemplate function is updated to merge these lambdas with provided data during Mustache template rendering, enabling the use of custom lambda functions within templates.

Changes

File(s) Change Summary
kleros-sdk/src/dataMappings/utils/lambdas.ts Added new exported lambdas object with a hex lambda for string-to-hexadecimal conversion.
kleros-sdk/src/dataMappings/utils/populateTemplate.ts Updated populateTemplate to merge lambdas with data for Mustache template rendering.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant populateTemplate
    participant Mustache
    participant lambdas

    Caller->>populateTemplate: Call with (mustacheTemplate, data)
    populateTemplate->>lambdas: Import lambdas
    populateTemplate->>Mustache: Render template with { ...data, ...lambdas }
    Mustache->>lambdas: Call hex lambda (if used in template)
    Mustache->>populateTemplate: Return rendered string
    populateTemplate->>Caller: Return parsed and validated result
Loading

Poem

In the land of code where lambdas hop,
A hex converter joins the crop.
Templates now with magic blend,
Data and lambdas, hand in hand.
Mustache smiles with rabbit glee—
More clever rendering, thanks to me!
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2925a4e and 33a47a9.

📒 Files selected for processing (2)
  • kleros-sdk/src/dataMappings/utils/lambdas.ts (1 hunks)
  • kleros-sdk/src/dataMappings/utils/populateTemplate.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • kleros-sdk/src/dataMappings/utils/lambdas.ts
  • kleros-sdk/src/dataMappings/utils/populateTemplate.ts
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: contracts-testing
  • GitHub Check: SonarCloud
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Mend Security Check
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Jun 13, 2025

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

Name Link
🔨 Latest commit 33a47a9
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-university/deploys/684c04d47036580008f53cf2

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
kleros-sdk/src/dataMappings/utils/lambdas.ts (2)

6-9: Guard against negative / large numbers and drop redundant .toLowerCase()

  1. parseInt preserves the sign; for negative values you’ll end up with "-0x…".
    Clarify whether that is intended or bail out for < 0.

  2. num.toString(16) already yields lowercase, so the extra .toLowerCase() is dead code.

If negative numbers are not expected, short-circuit early:

-      if (!isNaN(num)) {
-        return "0x" + num.toString(16).toLowerCase();
+      if (!Number.isNaN(num) && num >= 0) {
+        return `0x${num.toString(16)}`;
       }

1-13: Add unit tests for the new lambda

lambdas.hex is a user-facing helper; edge-cases (non-numeric strings, negative numbers, 0, large ints) deserve automated tests to prevent regressions.
Consider placing them alongside existing template-population tests.

🧰 Tools
🪛 Biome (1.9.4)

[error] 4-4: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b75799 and 2925a4e.

📒 Files selected for processing (2)
  • kleros-sdk/src/dataMappings/utils/lambdas.ts (1 hunks)
  • kleros-sdk/src/dataMappings/utils/populateTemplate.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
kleros-sdk/src/dataMappings/utils/populateTemplate.ts (1)
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1703
File: kleros-sdk/src/utils/getDispute.ts:43-43
Timestamp: 2024-10-14T15:29:32.954Z
Learning: In the Kleros SDK, when using the `populateTemplate` function in `kleros-sdk/src/utils/getDispute.ts`, missing variables in Mustache templates are acceptable. Mustache fills in blanks, and it's preferable to return the partially populated template without throwing errors, as it's still helpful for the consumer.
🧬 Code Graph Analysis (1)
kleros-sdk/src/dataMappings/utils/populateTemplate.ts (1)
kleros-sdk/src/dataMappings/utils/lambdas.ts (1)
  • lambdas (1-13)
🪛 Biome (1.9.4)
kleros-sdk/src/dataMappings/utils/lambdas.ts

[error] 4-4: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Analyze (javascript)
  • GitHub Check: SonarCloud
  • GitHub Check: contracts-testing
  • GitHub Check: Mend Security Check
🔇 Additional comments (1)
kleros-sdk/src/dataMappings/utils/populateTemplate.ts (1)

4-4: Import looks good

Straightforward addition of the shared lambdas util.

Copy link

netlify bot commented Jun 13, 2025

Deploy Preview for kleros-v2-testnet-devtools ready!

Name Link
🔨 Latest commit 33a47a9
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet-devtools/deploys/684c04d4dd8452000825aa8f
😎 Deploy Preview https://deploy-preview-2024--kleros-v2-testnet-devtools.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 project configuration.

Copy link

codeclimate bot commented Jun 13, 2025

Code Climate has analyzed commit 33a47a9 and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Style 3

View more on Code Climate.

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants