-
Notifications
You must be signed in to change notification settings - Fork 83
feat: Created declaration file for project config index.d.ts module #567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| * limitations under the License. | ||
| */ | ||
|
|
||
| declare module '@optimizely/optimizely-sdk/lib/core/event_builder' { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it's event_builder?
|
|
||
| declare module '@optimizely/optimizely-sdk/lib/core/project_config' { | ||
| import { LogHandler } from '@optimizely/js-sdk-logging'; | ||
| import { Experiment, Variation } from '@optimizely/optimizely-sdk'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that importing a root-level module from a module downstream is an anti-pattern. I think it makes more sense to export Experiment and Variation interfaces from ProjectConfig and then import them here from ProjectConfig. Wdyt @mjc1283
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikeng13 Agreed 👍 !
There might be issues with importing/exporting in declaration files (not TS source files), and sharing them into the root level index.d.ts. I believe @yavorona ran into this with user attributes, and we ended up creating a shared_types.ts file. The goal was to keep definitions identical in shared_types.ts and root index.d.ts.
However, if we can actually keep the definitions where they belong in lower modules like this, and still export them appropriately, I'm all for it.
| interface Config { | ||
| // TODO[OASIS-6649]: Don't use object type | ||
| // eslint-disable-next-line @typescript-eslint/ban-types | ||
| datafile: object; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need any?
| id: string | ||
| policy: string | ||
| trafficAllocation: Array<{ | ||
| entityId: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a separate type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interface TrafficAllocationRange {
entityId: string;
endOfRange: number;
}
// ...
interface Group {
trafficAllocation: TrafficAllocationRange[];
}| key: string; | ||
| } | ||
|
|
||
| interface Variable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FeatureVariable
| defaultValue: string; | ||
| id: string; | ||
| key: string; | ||
| type: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we also have subtype as well.
| type: string; | ||
| } | ||
|
|
||
| interface RollOut { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rollout
|
|
||
| interface RollOut { | ||
| experiments: Experiment[]; | ||
| id: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key is missing
| revision: string; | ||
| } | ||
|
|
||
| export interface EventBuilder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be here, please remove it. It should be in a separate file.
| export interface EventBuilder { | ||
| // TODO[OASIS-6649]: Don't use object type | ||
| // eslint-disable-next-line @typescript-eslint/ban-types | ||
| createMutationSafeDatafileCopy(datafile: object): object; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have some doubt, this should be a part of projectconfig.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely not, this is a function within the project config module, not a method of a ProjectConfig.
This ProjectConfig seems to be confusing ProjectConfig data object with project_config module.
| createMutationSafeDatafileCopy(datafile: object): object; | ||
| // TODO[OASIS-6649]: Don't use object type | ||
| // eslint-disable-next-line @typescript-eslint/ban-types | ||
| createProjectConfig(datafile: object, datafileString: string | null): ProjectConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have some doubt, this should be a part of projectconfig.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, should not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this as well.
| getVariableValueForVariation(projectConfig: ProjectConfig, variable: Variable, variation: Variation, logger: LogHandler) : string | null | ||
| // TODO[OASIS-6649]: Don't use any type | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| getTypeCastValue(variableValue: string, variableType: string, logger: LogHandler): any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have some doubt, this should be a part of projectconfig.
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| getTypeCastValue(variableValue: string, variableType: string, logger: LogHandler): any | ||
| getAudiencesById(projectConfig: ProjectConfig): {[id: string]: Audience} | ||
| eventWithKeyExists(projectConfig: ProjectConfig, eventKey: string): boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have some doubt, this should be a part of projectconfig.
| getAudiencesById(projectConfig: ProjectConfig): {[id: string]: Audience} | ||
| eventWithKeyExists(projectConfig: ProjectConfig, eventKey: string): boolean | ||
| isFeatureExperiment(projectConfig: ProjectConfig, experimentId: string): boolean | ||
| toDatafile(projectConfig: ProjectConfig): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have some doubt, this should be a part of projectconfig.
| eventWithKeyExists(projectConfig: ProjectConfig, eventKey: string): boolean | ||
| isFeatureExperiment(projectConfig: ProjectConfig, experimentId: string): boolean | ||
| toDatafile(projectConfig: ProjectConfig): string | ||
| tryCreatingProjectConfig(config: Config): { config: ProjectConfig, error: string | null} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have some doubt, this should be a part of projectconfig.
| */ | ||
|
|
||
| declare module '@optimizely/optimizely-sdk/lib/core/project_config' { | ||
| // TODO[OASIS-6649]: Don't use any type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no any type, please remove it.
| export type UserAttributes = { | ||
| // TODO[OASIS-6649]: Don't use any type | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| [name: string]: any; | ||
| }; | ||
|
|
||
| export type EventTags = { | ||
| [key: string]: string | number | boolean; | ||
| }; | ||
|
|
||
| export type ConditionTree<Leaf> = Leaf | unknown[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UserAttributes, EventTags, and ConditionTree are not related to project_config and should not be defined here.
UserAttributes is already defined in shared_types.ts.
ConditionTree is already defined in condition_tree.ts.
| export type UserAttributes = { | ||
| // TODO[OASIS-6649]: Don't use any type | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| [name: string]: any; | ||
| }; | ||
|
|
||
| export type EventTags = { | ||
| [key: string]: string | number | boolean; | ||
| }; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't remove these from here, these are part of the public interface used by SDK users.
| interface Experiment { | ||
| id: string; | ||
| key: string; | ||
| status: string; | ||
| layerId: string; | ||
| variations: Variation[]; | ||
| trafficAllocation: Array<{ | ||
| entityId: string; | ||
| endOfRange: number; | ||
| }>; | ||
| audienceIds: string[]; | ||
| // TODO[OASIS-6649]: Don't use object type | ||
| // eslint-disable-next-line @typescript-eslint/ban-types | ||
| forcedVariations: object; | ||
| } | ||
|
|
||
| interface Variation { | ||
| id: string; | ||
| key: string; | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't remove this, this is part of the public interface used by SDK users.
| export type Condition = { | ||
| name: string; | ||
| type: string; | ||
| match?: string; | ||
| value: string | number | boolean | null; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This duplicates the definition already existing in custom_attribute_condition_evaluator.ts. It is OK to relocate that definition to this file.
| declare module '@optimizely/optimizely-sdk/lib/core/project_config' { | ||
| export interface ProjectConfig {} | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add function definitions which will be called or used from lib/optimizely/index.js
| * limitations under the License. * | ||
| ***************************************************************************/ | ||
|
|
||
| import { ConditionTree } from '../project_config/entities'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't import.
| * @return {string} Experiment ID corresponding to the provided experiment key | ||
| * @throws If experiment key is not in datafile | ||
| */ | ||
| export function getExperimentId(configObj: ProjectConfig, experimentKey: string): string | never; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is | never required?
Summary
Testplan