feat: Simplify FlagsmithCache interface #165
Merged
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.
The
FlagsmithCache
interface is unnecessarily complicated:has
is never used by the SDK, it is only used in tests. This change removes it.set
is never used by the SDK, and serves no purpose. This changesset
to be of typePromise<void>
.set
accepts attl
parameter but the SDK never actually uses it. This change removes it.get
used to bePromise<Flags | undefined> | undefined
. In practice, the SDK always awaits this value so it should bePromise<Flags | undefined>
, which is what this change uses.The
Flagsmith
constructor also checks that the supplied cache has the same methods as the ones required byFlagsmithCache
. This check is not thorough enough to be useful and should be done by typechecking. Also, this checking requiresFlagsmithCache
to be indexable by a string, which customers will never need to do and just adds boilerplate. This change removes this check and should be enforced by typechecking.This change also adds JSDoc to
FlagsmithCache
, so we can link to it directly from docs and avoid duplicating code snippets or explanations.These are technically breaking changes, but only for TypeScript users and has no effect at runtime. Prior to 4.0.0 it was impossible to actually refer to the
FlagsmithCache
in TypeScript code because we were not exporting any types. I'd be okay with releasing it as4.1.0
.