Skip to content

Thoughts after using this in a project #7

@mark-dropbear

Description

@mark-dropbear

The Trap: The API has a subtle "footgun" regarding .value vs .toString()/parse().

  • id.value returns the raw Base32 string (e.g., AD836J3H9NPT2).
  • id.toString() returns the full string with checksum (e.g., task_list/AD836J3H9NPT2T).
  • ResourceId.parse() strictly requires the checksum.
  • The Workflow Failure: Developers naturally want to use the "clean" ID in URLs (e.g., /lists/{id}). If they use id.value for this, and then try to reconstruct the ID later (e.g., ResourceId.parse('task_list/$idFromUrl')), it fails with "Checksum mismatch" because the checksum char is missing. This is exactly what broke our app.

Initial Suggestions:

  • Add id.uid (or id.code): A property that returns the value + checksum (e.g., AD836J3H9NPT2T). This is the "safe" string to use in URLs or DB keys if you aren't storing the prefix.
  • Rename .value to .rawValue: To make it explicit that it's incomplete/unsafe for parsing.
  • Enhance parse(): Maybe allow parse() to accept a valid raw value if a flag is set (e.g., strict: false), calculating the checksum itself? (Though this weakens the "typo-proof" feature).
  • Documentation: Explicitly warn that id.value strips the checksum and cannot be fed back into parse() even with the prefix.
  • The package is solid (the checksum saved us from a mismatch!), but this specific interaction flow is counter-intuitive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions