Skip to content

Conversation

@ozayr-zaviar
Copy link
Contributor

@ozayr-zaviar ozayr-zaviar commented Sep 15, 2020

Summary

  • index.d.ts file added in lib/core/project_config

Testplan

  • All unit tests must work fine. For now, we don't have any unit tests for declaration file.

@coveralls
Copy link

coveralls commented Sep 15, 2020

Coverage Status

Coverage remained the same at 96.638% when pulling 941c5f5 on uzair/project_config_interface into 25c8bd0 on master.

* limitations under the License.
*/

declare module '@optimizely/optimizely-sdk/lib/core/event_builder' {
Copy link
Contributor

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';
Copy link
Contributor

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

Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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

Copy link
Contributor

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 {
Copy link
Contributor

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;
Copy link
Contributor

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 {
Copy link
Contributor

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;
Copy link
Contributor

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 {
Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, should not.

Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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}
Copy link
Contributor

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.

@msohailhussain msohailhussain marked this pull request as ready for review September 15, 2020 19:05
@msohailhussain msohailhussain requested a review from a team as a code owner September 15, 2020 19:05
@msohailhussain msohailhussain requested review from mjc1283 and removed request for mikeproeng37 and msohailhussain September 15, 2020 19:06
*/

declare module '@optimizely/optimizely-sdk/lib/core/project_config' {
// TODO[OASIS-6649]: Don't use any type
Copy link
Contributor

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.

Comment on lines 17 to 27
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[];
Copy link
Contributor

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.

Comment on lines 167 to 176
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;
};

Copy link
Contributor

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.

Comment on lines 183 to 203
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;
}

Copy link
Contributor

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.

Comment on lines 59 to 64
export type Condition = {
name: string;
type: string;
match?: string;
value: string | number | boolean | null;
};
Copy link
Contributor

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.

Comment on lines 17 to 19
declare module '@optimizely/optimizely-sdk/lib/core/project_config' {
export interface ProjectConfig {}
}
Copy link
Contributor

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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't import.

@ozayr-zaviar ozayr-zaviar changed the title index.d.ts file for Project Config added feat: Created declaration file for project config module Sep 22, 2020
@msohailhussain msohailhussain changed the title feat: Created declaration file for project config module feat: Created declaration file for project config index.d.ts module Sep 22, 2020
* @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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is | never required?

@mjc1283 mjc1283 merged commit eaf61d0 into master Sep 23, 2020
@mjc1283 mjc1283 deleted the uzair/project_config_interface branch September 23, 2020 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants