refactor(community): give the provider port vendor-neutral types - #62
Closed
yufoxda wants to merge 2 commits into
Closed
refactor(community): give the provider port vendor-neutral types#62yufoxda wants to merge 2 commits into
yufoxda wants to merge 2 commits into
Conversation
The port was generic in name only. Its methods returned DiscordGuildMembership, DiscordMessage and DiscordReactionUser, and every identifier was validated against the Discord snowflake format, so the identifier regex reached callers that have no reason to know what a snowflake is. Replacing the provider would have meant editing the interface and both api_v0 services rather than swapping an adapter. The port now speaks CommunityRole, CommunityMembership, CommunityMessage, CommunityReactionUser and CommunityAccountProfile, treats identifiers as opaque strings, and drops the Discord message length limit. Discord's snowflake format, its 2000-character limit, and the global_name field it returns are refinements applied in discord/schema.ts, which is the only layer that issues those values. The provider-specific field name is mapped to displayName at the adapter boundary, matching the provider_display_name column it is stored in. Behaviour is unchanged: the adapter still rejects a malformed provider response and a guild member response for another user, both of which depend on the snowflake assertion that moved. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
yufoxda
force-pushed
the
refactor/community-neutral-types
branch
from
July 27, 2026 07:45
636e09e to
c18ece5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CommunityProviderは名前だけが汎用で、中身は Discord 固有でした。可換性を実際に成立させます。何が問題だったか
DiscordGuildMembership/DiscordMessage/DiscordReactionUserを返していた^\d{17,20}$)で検証されており、その正規表現がアプリ層まで到達していた結果として、プロバイダを差し替えるには「アダプタを入れ替える」のではなく、インターフェースと api_v0 の2つのサービスを書き換える必要がありました。
変更内容
ポート(中立) —
lib/community/type.ts,interface.tsCommunityRole/CommunityMembership/CommunityMessage/CommunityReactionUser/CommunityAccountProfileに変更アダプタ(Discord固有) —
lib/community/discord/schema.ts(新規)global_nameの写像をここに集約.extend()して精緻化するため、検証は緩まないglobal_name→displayNameに写像。保存先のprovider_display_name列とも整合挙動は不変
snowflake 検証に依存する以下のテストが、移動後も通ることを確認済みです。
getCurrentDiscordUser rejects malformed provider responses as a bad gatewaygetGuildMembershipAPI rejects a guild member response for another user検証
tsc --noEmitクリーンglobalName参照なし=影響なし)境界の確認
interface.ts/type.tsに Discord 語彙なし(コメントを除く)api_v0に Discord 固有型の参照なしDiscordSnowflakeSchemaはlib/community/discord/配下のみ🤖 Generated with Claude Code