Skip to content

feat(sql): implement TypeID specification 0.3.0 in typeid-sql #537

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

Merged
merged 1 commit into from
Aug 8, 2025

Conversation

joschi
Copy link
Contributor

@joschi joschi commented Jul 30, 2025

Summary

Implement TypeID specification 0.3.0 in typeid-sql.

Note

PLEASE tag the repository with the specification and provide a changelog. 🙏

How was it tested?

yarn install
yarn test

Community Contribution License

All community contributions in this pull request are licensed to the project maintainers under the terms of the Apache 2 License.

By creating this pull request I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the Community Contribution License.

@joschi
Copy link
Contributor Author

joschi commented Jul 30, 2025

This would supersede #363 and #467.

@joschi joschi force-pushed the typeid-sql-spec-0.3 branch 2 times, most recently from be313e1 to 341d77b Compare July 30, 2025 14:42
@LucilleH LucilleH requested review from loreto and Copilot July 30, 2025 18:25
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements TypeID specification 0.3.0 in the typeid-sql project, updating the prefix validation rules to allow underscores within prefixes while maintaining proper formatting constraints.

  • Updates prefix regex from [a-z]{0,63} to ^([a-z]([a-z_]{0,61}[a-z])?)?$ to allow underscores
  • Adds comprehensive test coverage for underscore handling in prefixes
  • Includes testing infrastructure and documentation improvements

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
typeid/typeid-sql/sql/03_typeid.sql Updates core TypeID functions with new prefix validation regex and improves parsing logic
typeid/typeid-sql/supabase/tests/03_typeid.test.sql Adds tests for underscore handling and updates error message expectations
typeid/typeid-sql/supabase/tests/03_typed_text.test.sql Adds underscore-specific test cases and updates validation error messages
typeid/typeid-sql/package.json Adds npm scripts for test automation
typeid/typeid-sql/README.md Documents testing procedures and requirements
Comments suppressed due to low confidence (2)

typeid/typeid-sql/supabase/tests/03_typeid.test.sql:128

  • The test description 'Print valid: valid-alphabet-underscores' is inconsistent with the test name 'valid-prefix-underscores'. Consider using 'Print valid: valid-prefix-underscores' for consistency.
  'Print valid: valid-alphabet-underscores'

typeid/typeid-sql/supabase/tests/03_typeid.test.sql:133

  • The test description 'Print valid: valid-alphabet-underscores' should be more specific since this test uses 'pre_____fix' with multiple consecutive underscores. Consider 'Print valid: valid-prefix-multiple-underscores'.
  'Print valid: valid-alphabet-underscores'

begin
if (typeid_str is null) then
return null;
end if;
if position('_' in typeid_str) = 0 then
return ('', base32_decode(typeid_str))::typeid;
end if;
prefix = split_part(typeid_str, '_', 1);
suffix = split_part(typeid_str, '_', 2);
matches = regexp_match(typeid_str, '^(.*)_(.*)$');
Copy link
Preview

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The regex ^(.*)_(.*)$ uses greedy matching which could be inefficient for strings with multiple underscores. Consider using ^(.*?)_(.*)$ with non-greedy matching or ^([^_]+)_(.*)$ to match only the first underscore more efficiently.

Suggested change
matches = regexp_match(typeid_str, '^(.*)_(.*)$');
matches = regexp_match(typeid_str, '^([^_]+)_(.*)$');

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@loreto WDYT? We could already match the correct regular expression here (prefix + suffix) but would lose fidelity in the error messages afterwards.

@joschi joschi force-pushed the typeid-sql-spec-0.3 branch from 341d77b to 18fca9c Compare August 6, 2025 14:42
@loreto
Copy link
Contributor

loreto commented Aug 6, 2025

Apologies for the delay. I'll take a look at this PR today.

Copy link
Contributor

@loreto loreto left a comment

Choose a reason for hiding this comment

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

LGTM

@loreto loreto merged commit 2a0e4ca into jetify-com:main Aug 8, 2025
9 checks passed
@joschi joschi deleted the typeid-sql-spec-0.3 branch August 8, 2025 21:11
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.

2 participants