Skip to content

Commit

Permalink
Add docs for validateMergedFeatures
Browse files Browse the repository at this point in the history
  • Loading branch information
timostamm committed Nov 27, 2023
1 parent ad1965d commit 169354c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/protobuf/src/private/feature-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ export function createFeatureResolver(
};
}

// When protoc generates google.protobuf.FeatureSetDefaults, it ensures that
// fields are not repeated or required, do not use oneof, and have a default
// value.
//
// When features for an element are resolved, features of the element and its
// parents are merged into the default FeatureSet for the edition. Because unset
// fields in the FeatureSet of an element do not unset the default FeatureSet
// values, a resolved FeatureSet is guaranteed to have all fields set. This is
// also the case for extensions to FeatureSet that a user might provide, and for
// features from the future.
//
// We cannot exhaustively validate correctness of FeatureSetDefaults at runtime
// without knowing the schema: If no value for a feature is provided, we do not
// know that it exists at all.
//
// As a sanity check, we validate that all fields known to our version of
// FeatureSet are set.
function validateMergedFeatures(
featureSet: FeatureSet,
): featureSet is MergedFeatureSet {
Expand Down

0 comments on commit 169354c

Please sign in to comment.