Skip to content

[ECO-5356] Remove public raw values from enums. #316

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 1 commit into
base: main
Choose a base branch
from

Conversation

maratal
Copy link
Collaborator

@maratal maratal commented Jul 3, 2025

Closes #279

Summary by CodeRabbit

  • Refactor

    • Updated enums to use internal raw value handling, enhancing encapsulation.
    • Introduced an internal protocol for raw value representation within the module.
    • Enhanced error handling for decoding message actions from JSON.
  • Bug Fixes

    • Improved validation and error reporting for message actions during data decoding.

@maratal maratal requested a review from umair-ably July 3, 2025 14:25
Copy link

coderabbitai bot commented Jul 3, 2025

"""

Walkthrough

This change refactors several enums in the codebase to remove their direct conformance to RawRepresentable with public raw values. Instead, internal protocols and manual mappings are introduced, separating the wire/raw representation from the public API. Additional internal error handling is added where necessary for decoding.

Changes

File(s) Change Summary
Sources/AblyChat/Events.swift Removed : String conformance from enums; added internal raw value mapping and custom protocol conformance.
Sources/AblyChat/MessageReaction.swift Removed : String conformance from enums; added internal raw value mapping and protocol conformance.
Sources/AblyChat/InternalRawRepresentable.swift Introduced internal InternalRawRepresentable protocol for raw value mapping.
Sources/AblyChat/Message.swift Updated decoding logic for Message to use new enum mapping and error handling.

Sequence Diagram(s)

sequenceDiagram
    participant Decoder
    participant Message
    participant MessageAction (enum)
    participant InternalRawRepresentable

    Decoder->>Message: decode(from: JSON)
    Message->>Decoder: extract "action" as String
    Message->>MessageAction: init?(rawValue: String)
    alt valid action
        MessageAction-->>Message: MessageAction instance
        Message-->>Decoder: Message instance
    else invalid action
        Message-->>Decoder: throw DecodingError
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Remove public enums with a raw value (separate wire representation) (#279, ECO-5356)

Suggested reviewers

  • lawrence-forooghian
  • umair-ably

Poem

A hop, a skip, a code refactor,
No public raw strings—much neater after!
Enums now keep their secrets inside,
With protocols guiding the way they confide.
The wire speaks strings, but the API’s clean,
A rabbit’s delight—so tidy, so keen! 🐇✨
"""


📜 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 1f07c14 and 8f6626a.

📒 Files selected for processing (4)
  • Sources/AblyChat/Events.swift (3 hunks)
  • Sources/AblyChat/InternalRawRepresentable.swift (1 hunks)
  • Sources/AblyChat/Message.swift (1 hunks)
  • Sources/AblyChat/MessageReaction.swift (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • Sources/AblyChat/InternalRawRepresentable.swift
  • Sources/AblyChat/Message.swift
  • Sources/AblyChat/MessageReaction.swift
  • Sources/AblyChat/Events.swift
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Example app, iOS (Xcode 16.3)
  • GitHub Check: Xcode, iOS (Xcode 16.2)
  • GitHub Check: SPM (Xcode 16.1)
  • GitHub Check: check-documentation
  • GitHub Check: Generate code coverage
  • GitHub Check: spec-coverage
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 279-no-public-raw-values

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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 auto-generate unit tests to generate unit tests for 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 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.

@maratal maratal changed the title Remove public raw values from enums. [ECO-5356] Remove public raw values from enums. Jul 3, 2025
@github-actions github-actions bot temporarily deployed to staging/pull/316/AblyChat July 3, 2025 14:26 Inactive
@maratal maratal force-pushed the 279-no-public-raw-values branch from 3a6d7eb to 939e576 Compare July 3, 2025 20:22
@github-actions github-actions bot temporarily deployed to staging/pull/316/AblyChat July 3, 2025 20:23 Inactive
extension MessageAction: InternalRawRepresentable {
internal typealias RawValue = String

internal init?(rawValue: String) {
Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian Jul 8, 2025

Choose a reason for hiding this comment

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

Would be nice if we could avoid duplicating the raw values. There are various ways you could do this, but perhaps the easiest would be to just have an internal WireMessageAction: String type that you convert to and from MessageAction.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -171,9 +171,13 @@ extension Message: JSONObjectDecodable {
values: summaryJson
)
}
let rawAction = try jsonObject.stringValueForKey("action")
guard let action = MessageAction(rawValue: rawAction) else {
throw JSONValueDecodingError.failedToDecodeFromRawValue(rawAction).toInternalError()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also would be good to have a convenience method à la rawRepresentableValueForKey

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure I've understood, this method belongs to jsonObject and similar to stringValueForKey?

@maratal maratal force-pushed the 279-no-public-raw-values branch from 939e576 to 1f07c14 Compare July 8, 2025 13:35
@github-actions github-actions bot temporarily deployed to staging/pull/316/AblyChat July 8, 2025 13:36 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Separate wire representation of events from public API
3 participants