Skip to content

Adds decoder functionality#10

Merged
johnnyt merged 1 commit intoriddler:mainfrom
jacobparry:main
Sep 12, 2025
Merged

Adds decoder functionality#10
johnnyt merged 1 commit intoriddler:mainfrom
jacobparry:main

Conversation

@jacobparry
Copy link
Contributor

@jacobparry jacobparry commented Aug 20, 2025

Summary

  • Adds UXID decoder functionality for parsing existing UXIDs
  • Provides separate UXID.EctoType module with proper typing for typed_ecto_schema compatibility https://github.com/bamorim/typed_ecto_schema
  • Maintains backward compatibility with existing encoder functionality

Changes Made

  • New decoder module (lib/uxid/decoder.ex) - supports both uppercase and lowercase UXIDs
  • Enhanced main module - adds UXID.decode/1 function while preserving existing API
  • Case parameter support - both modules now support the new case option from v2.0+
  • Comprehensive test coverage - 46 tests with full coverage for decoder and EctoType functionality

Implementation Details

Case Support

  • Decoder handles both uppercase and lowercase UXIDs seamlessly
  • Both Ecto implementations support the new case parameter
  • Mixed case UXIDs (edge cases) are handled correctly

Test Coverage

  • ✅ 46 tests total (8 new tests added)
  • ✅ All existing functionality preserved
  • ✅ New decoder tests for both uppercase and lowercase
  • ✅ Mixed case decoding edge cases
  • ✅ Comprehensive stress tests

Usage Examples

# Standard usage (existing)
defmodule MyApp.User do
  use Ecto.Schema

  schema "users" do
    field :id, UXID, primary_key: true, autogenerate: true, prefix: "usr"
  end
end


# Decoding UXIDs (new)
{:ok, decoded} = UXID.decode("usr_01h2vx8qf9bhqzd0kf6x8h4n8z")

@johnnyt
Copy link
Member

johnnyt commented Aug 22, 2025

@jacobparry I just updated a few things and you'll need to rebase (sorry about that).

The functionality of the Ecto.UXID module that was removed also lives in the main UXID module. My hope with that was that just using UXID for ecto related things would work across the board. You mentioned that you're using typed_ecto_schema and that is uses the Elixir type of the module, which isn't working.

I updated the UXID.t() to now be a String.t(), and introducted a UXID.Codec module that now holds the expanded struct and type.

Could you check to see if using this GitHub repo in your mix.exs instead of the hex package works with 'typed_ecto_schema`?

@jacobparry jacobparry force-pushed the main branch 2 times, most recently from fcc88df to 192af08 Compare September 4, 2025 02:18
@jacobparry
Copy link
Contributor Author

Your idea of just changing the .t() function to map to a string is good. I had thought of that but didn't know if you had typed the struct to it specifically for a reason.

I updated my PR and took out the extra ecto_type stuff since that is redundant now with the change of the type string.

I left all the decoder work in and extra tests and everything.

@johnnyt
Copy link
Member

johnnyt commented Sep 12, 2025

I just updated a couple of things (including formatting), could you rebase again? I'd love to get this merged in.

Features added:
- Complete UXID decode functionality with uppercase/lowercase support
- New UXID.Decoder module with full pipeline processing
- Enhanced Ecto ParameterizedType with case and delimiter support
- Comprehensive test coverage (40 passing tests)

Technical improvements:
- Support for decoding both regular and prefixed UXIDs
- Consistent Codec-based architecture integration
- Updated benchmark compatibility
- Enhanced tooling versions (.tool-versions, Gemfile.lock)

This maintains full compatibility with the upstream Codec architecture
while adding valuable decode capabilities not present in upstream.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jacobparry jacobparry changed the title Add decoder functionality and separate EctoType for typed_ecto_schema compatibility Add decoder functionality Sep 12, 2025
@johnnyt johnnyt changed the title Add decoder functionality Adds decoder functionality Sep 12, 2025
@johnnyt
Copy link
Member

johnnyt commented Sep 12, 2025

Looks good - thanks for this!

@johnnyt johnnyt merged commit 63f290f into riddler:main Sep 12, 2025
1 check passed
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