feat(server): conditional BaseContext types via typed() factory (#2004)#2294
Merged
Conversation
BaseContext is now generic over ContextFeatures. Auth/tenancy fields only appear on ctx when configured. Use typed(auth) to get narrowed entity() and service() factories. Existing code is unaffected — BaseContext without a type parameter defaults to FullFeatures (all fields present). - Add mixin interfaces: AuthContext, TenantContext, MultiLevelTenantContext - Add ContextFeatures, FullFeatures, NoFeatures type flags - Replace BaseContext interface with conditional type alias - Add TFeatures to EntityConfig and ServiceConfig - Add typed() factory with TypedFactories<F> interface - Add InferFeatures, InferServerFeatures, InferServerContext utilities - Make defineAuth generic to preserve literal types - Add multiLevel field to TenantConfig - Comprehensive type-level tests for all 4 feature tiers Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…d.ts and service/types.ts (#2004) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
ctxwhen the app has those features configuredtyped(auth)factory returns narrowedentity()andservice()factories where hookctxparameters reflect the configured featuresBaseContextwithout a type parameter defaults toFullFeatures(all fields present), so all existing code compiles unchangedPublic API Changes
New types
ContextFeatures,FullFeatures,NoFeatures— feature flag typesAuthContext,TenantContext,MultiLevelTenantContext— mixin interfaces (from@vertz/server/entity)TypedFactories<F>— typed entity/service factory interfaceInferFeatures<TAuth>— derives features from auth configInferServerFeatures<TConfig>,InferServerContext<TConfig>— derives features from server configNew function
typed(auth?)— returns{ entity, service }with narrowed context typesChanged signatures (backwards compatible)
BaseContext<TFeatures = FullFeatures>— now generic (was plain interface)EntityConfig<..., TFeatures = FullFeatures>— new 4th type parameterServiceConfig<..., TFeatures = FullFeatures>— new 3rd type parameterentity()/service()— acceptTFeaturestype parameterdefineAuth<T extends AuthConfig>(config: T): T— now generic (preserves literal types)TenantConfig.multiLevel?: boolean— new optional fieldDesign doc
plans/2004-base-context-conditional-types.mdTest plan
typed()factory type testsInferFeatures+InferServerFeaturestestsdefineAuthgeneric preservation tests@vertz/agentsBaseContextLikestructural compatibility testBaseContextdefaults to FullFeaturesEntityContextassignable toBaseContextdefineAuthidentity behavior🤖 Generated with Claude Code