exploration: Add capability-aware API schema versioning#13
Conversation
| type SelectFields<Fields extends Schema.Struct.Fields, Capabilities extends MatrixCapabilities> = { | ||
| readonly [Key in keyof Fields as Fields[Key] extends VersionedField<Schema.Top, infer Availability> | ||
| ? IsAvailable<Capabilities, Availability> extends true | ||
| ? Key |
There was a problem hiding this comment.
[P1] Keep widened capabilities aligned with runtime
This key remapping treats every non-literal availability result as unsupported because a boolean result does not extend true. For example, with const caps: MatrixCapabilities = { version: matrixVersion(1, 2) }, a field gated since v1.1 is present in schema.fields at runtime, but typeof schema.Type contains only the ungated fields. The same mismatch affects MSC arrays stored as ReadonlyArray<Msc>. This is especially likely for capabilities discovered at startup, and contradicts the documentation claim that literals merely give the most precise type. Please either model unknown gates conservatively (for example as optional/union fields) or reject widened capabilities at the API boundary, and add type/runtime tests for a value typed as MatrixCapabilities.
There was a problem hiding this comment.
Fixed in c92395f. Availability is now modeled as true, false, or uncertain: literal capabilities retain exact required/omitted struct fields, while widened versions or MSC arrays expose undecidable gated fields as optional and keep the runtime fields map typed as a partial map of the original schemas. I also corrected widened ReadonlyArray handling so it no longer implies definite support for every MSC. The new regressions cover both widened MatrixCapabilities and widened MSC arrays at the type and runtime levels; package typecheck, focused tests (7/7), and the full package suite (78/78) pass.
wouter173
left a comment
There was a problem hiding this comment.
Review summary: the literal-capability path, stable/MSC OR semantics, runtime annotation lookup, exports, docs, and focused tests look good. Package typecheck and the 5 versioning tests pass. I found one blocker in the widened-capability path: the inferred schema type can omit fields that the runtime schema contains, so values discovered or stored as MatrixCapabilities are not type/runtime aligned. Details and a suggested direction are in the inline comment.
Summary
Verification
Closes #12