-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Correct client evaluation typings. (#554)
Some code was refactored to make server and client share evaluation results. This should not have been done because the results are not the same in client and server SDKs. Server SDKs can always produce a reason and client SDKs cannot. This meant that the typing said that reason was required in the client SDK, but it could be null. This is a 'feat' to ensure a minor version bump in case of minor incompatibilities.
- Loading branch information
1 parent
115bd82
commit 64ab88d
Showing
18 changed files
with
109 additions
and
191 deletions.
There are no files selected for viewing
This file contains 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
18 changes: 0 additions & 18 deletions
18
packages/shared/common/src/internal/evaluation/evaluationDetail.ts
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,4 @@ | ||
import ErrorKinds from './ErrorKinds'; | ||
import { createErrorEvaluationDetail, createSuccessEvaluationDetail } from './evaluationDetail'; | ||
import EventFactoryBase, { EvalEventArgs } from './EventFactoryBase'; | ||
|
||
export { | ||
createSuccessEvaluationDetail, | ||
createErrorEvaluationDetail, | ||
ErrorKinds, | ||
EvalEventArgs, | ||
EventFactoryBase, | ||
}; | ||
export { ErrorKinds, EvalEventArgs, EventFactoryBase }; |
This file contains 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
This file contains 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
File renamed without changes.
File renamed without changes.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { | ||
LDEvaluationDetail as CommonDetail, | ||
LDEvaluationDetailTyped as CommonDetailTyped, | ||
LDEvaluationReason, | ||
} from '@launchdarkly/js-sdk-common'; | ||
|
||
// Implementation note: In client-side SDKs the reason is optional. The common type, which is also | ||
// used by server SDKs, has a required reason. This file contains a client specific | ||
// LDEvaluationDetail which has an optional reason. | ||
|
||
// TODO: On major version change "reason" to be optional instead of nullable. | ||
|
||
/** | ||
* An object that combines the result of a feature flag evaluation with information about | ||
* how it was calculated. | ||
* | ||
* This is the result of calling `LDClient.variationDetail`. | ||
*/ | ||
export type LDEvaluationDetail = Omit<CommonDetail, 'reason'> & { | ||
/** | ||
* An optional object describing the main factor that influenced the flag evaluation value. | ||
*/ | ||
reason: LDEvaluationReason | null; | ||
}; | ||
|
||
/** | ||
* An object that combines the result of a feature flag evaluation with information about | ||
* how it was calculated. | ||
* | ||
* This is the result of calling detailed variation methods. | ||
*/ | ||
export type LDEvaluationDetailTyped<TFlag> = Omit<CommonDetailTyped<TFlag>, 'reason'> & { | ||
/** | ||
* An optional object describing the main factor that influenced the flag evaluation value. | ||
*/ | ||
reason: LDEvaluationReason | null; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
26 changes: 26 additions & 0 deletions
26
packages/shared/sdk-client/src/evaluation/evaluationDetail.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { internal, LDEvaluationReason, LDFlagValue } from '@launchdarkly/js-sdk-common'; | ||
|
||
import { LDEvaluationDetail } from '../api'; | ||
|
||
export function createErrorEvaluationDetail( | ||
errorKind: internal.ErrorKinds, | ||
def?: LDFlagValue, | ||
): LDEvaluationDetail { | ||
return { | ||
value: def ?? null, | ||
variationIndex: null, | ||
reason: { kind: 'ERROR', errorKind }, | ||
}; | ||
} | ||
|
||
export function createSuccessEvaluationDetail( | ||
value: LDFlagValue, | ||
variationIndex?: number, | ||
reason?: LDEvaluationReason, | ||
): LDEvaluationDetail { | ||
return { | ||
value, | ||
variationIndex: variationIndex ?? null, | ||
reason: reason ?? null, | ||
}; | ||
} |
Oops, something went wrong.