fix(ts-sdk): Add primaryKey() and index() to SumBuilderImpl and SumColumnBuilder#4389
fix(ts-sdk): Add primaryKey() and index() to SumBuilderImpl and SumColumnBuilder#4389Ludv1gL wants to merge 1 commit intoclockworklabs:masterfrom
Conversation
…lumnBuilder Codegen unconditionally calls .primaryKey() on all primary key columns, including enum types. But SumBuilderImpl (used for all object-form enums) only implemented Defaultable and Nameable — not PrimaryKeyable or Indexable. This caused a runtime TypeError when any enum type was used as a primary key column. Add Indexable and PrimaryKeyable interfaces and their methods to both SumBuilderImpl and SumColumnBuilder, matching the existing pattern in SimpleSumBuilderImpl and SimpleSumColumnBuilder. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@gefjon correct me if I'm wrong, but I don't believe we support indexing and filtering on sum types, and to add support we'd have to add support in all languages. Definitely shouldn't have a runtime error, but I think the fix is to disallow primary keys on sum types, at least for now. |
I believe we allow filtering and primary-key annotations on simple enums, i.e. those where all variants have the unit payload. It's possible I'm misremembering, thought. |
|
Yeah and I definitely remember this was added to the C++ library back in the day since it was in sdk-test. |
|
I asked a friend and got this summary, which aligns with my intuition that the Typescript SDK is the odd one out:
|
cloutiertyler
left a comment
There was a problem hiding this comment.
In that case, I'm going to approve this one.
Summary
.primaryKey()on all primary key columns, including enum typesSumBuilderImpl(used for all object-form enums via__t.enum("Name", { ... })) only implementedDefaultableandNameable— notPrimaryKeyableorIndexableTypeError: SC.primaryKey is not a functionwhenever an enum type is used as a primary key columnFix
Add
IndexableandPrimaryKeyableinterfaces and their methods to:SumBuilderImpl(the base class for all enum type builders)SumColumnBuilder(the column builder returned bySumBuilderImplmethods)This matches the existing pattern already present in
SimpleSumBuilderImplandSimpleSumColumnBuilder.Why SumBuilderImpl and not just SimpleSumBuilderImpl?
Codegen always generates object-form enums:
The runtime dispatch in
type_builders.ts(line ~3656) routes object-form enums toSumBuilder(backed bySumBuilderImpl), never toSimpleSumBuilder. SoSimpleSumBuilderImpl's existingprimaryKey()/index()methods are effectively dead code for codegen output.Test plan
TypeError: SC.primaryKey is not a functionSimpleSumBuilderImpl/SimpleSumColumnBuilderbehavior is unchanged (subclass overrides still work)🤖 Generated with Claude Code