Skip to content

Commit

Permalink
Fix missing JSDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
afharo committed Aug 5, 2024
1 parent d888c6e commit acaf70b
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* Side Public License, v 1.
*/

export { FeatureFlagsService } from './src/feature_flags_service';
export { FeatureFlagsService, type FeatureFlagsSetupDeps } from './src/feature_flags_service';
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ export interface FeatureFlagsSetupDeps {
injectedMetadata: InternalInjectedMetadataSetup;
}

/**
* The browser-side Feature Flags Service
* @private
*/
export class FeatureFlagsService {
private readonly featureFlagsClient: Client;
private readonly logger: Logger;
private isProviderReadyPromise?: Promise<void>;
private context: MultiContextEvaluationContext = { kind: 'multi' };
private overrides: Record<string, unknown> = {};

/**
* The core service's constructor
* @param core {@link CoreContext}
*/
constructor(core: CoreContext) {
this.logger = core.logger.get('feature-flags-service');
this.featureFlagsClient = OpenFeature.getClient();
Expand All @@ -46,9 +54,10 @@ export class FeatureFlagsService {

/**
* Setup lifecycle method
* @param deps {@link FeatureFlagsSetup} including the {@link InternalInjectedMetadataSetup} used to retrieve the feature flags.
*/
public setup({ injectedMetadata }: FeatureFlagsSetupDeps): FeatureFlagsSetup {
const featureFlagsInjectedMetadata = injectedMetadata.getFeatureFlags();
public setup(deps: FeatureFlagsSetupDeps): FeatureFlagsSetup {
const featureFlagsInjectedMetadata = deps.injectedMetadata.getFeatureFlags();
if (featureFlagsInjectedMetadata) {
this.overrides = featureFlagsInjectedMetadata.overrides;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,20 @@ const createFeatureFlagsServiceMock = (): jest.Mocked<PublicMethodsOf<FeatureFla
};
};

/**
* Mocks for the Feature Flags service (browser-side)
*/
export const coreFeatureFlagsMock = {
/**
* Mocks the entire feature flags service
*/
create: createFeatureFlagsServiceMock,
/**
* Mocks the setup contract
*/
createSetup: createFeatureFlagsSetup,
/**
* Mocks the start contract
*/
createStart: createFeatureFlagsStart,
};
Original file line number Diff line number Diff line change
Expand Up @@ -116,36 +116,48 @@ export interface FeatureFlagsStart {

/**
* Evaluates a boolean flag
* @param flagName The flag ID to evaluate
* @param fallbackValue If the flag cannot be evaluated for whatever reason, the fallback value is provided.
* @public
*/
getBooleanValue(flagName: string, fallbackValue: boolean): boolean;

/**
* Evaluates a string flag
* @param flagName The flag ID to evaluate
* @param fallbackValue If the flag cannot be evaluated for whatever reason, the fallback value is provided.
* @public
*/
getStringValue<Value extends string>(flagName: string, fallbackValue: Value): Value;

/**
* Evaluates a number flag
* @param flagName The flag ID to evaluate
* @param fallbackValue If the flag cannot be evaluated for whatever reason, the fallback value is provided.
* @public
*/
getNumberValue<Value extends number>(flagName: string, fallbackValue: Value): Value;

/**
* Returns an observable of a boolean flag
* @param flagName The flag ID to evaluate
* @param fallbackValue If the flag cannot be evaluated for whatever reason, the fallback value is provided.
* @public
*/
getBooleanValue$(flagName: string, fallbackValue: boolean): Observable<boolean>;

/**
* Returns an observable of a string flag
* @param flagName The flag ID to evaluate
* @param fallbackValue If the flag cannot be evaluated for whatever reason, the fallback value is provided.
* @public
*/
getStringValue$<Value extends string>(flagName: string, fallbackValue: Value): Observable<Value>;

/**
* Returns an observable of a number flag
* @param flagName The flag ID to evaluate
* @param fallbackValue If the flag cannot be evaluated for whatever reason, the fallback value is provided.
* @public
*/
getNumberValue$<Value extends number>(flagName: string, fallbackValue: Value): Observable<Value>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,32 @@ import type { ServiceConfigDescriptor } from '@kbn/core-base-server-internal';
import { schema } from '@kbn/config-schema';

/**
* The definition of the validation config schema
* @private
*/
const configSchema = schema.object({
overrides: schema.maybe(schema.recordOf(schema.string(), schema.any())),
});

/**
* Type definition of the Feature Flags configuration
* @private
*/
export interface FeatureFlagsConfig {
overrides?: Record<string, unknown>;
}

/**
* Config descriptor for the feature flags service
* @private
*/
export const featureFlagsConfig: ServiceConfigDescriptor<FeatureFlagsConfig> = {
/**
* All config is prefixed by `feature_flags`
*/
path: 'feature_flags',
/**
* The definition of the validation config schema
*/
schema: configSchema,
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ export interface InternalFeatureFlagsSetup extends FeatureFlagsSetup {
getOverrides: () => Record<string, unknown>;
}

/**
* The server-side Feature Flags Service
* @private
*/
export class FeatureFlagsService {
private readonly featureFlagsClient: Client;
private readonly logger: Logger;
private overrides: Record<string, unknown> = {};
private context: MultiContextEvaluationContext = { kind: 'multi' };

/**
* The core service's constructor
* @param core {@link CoreContext}
*/
constructor(private readonly core: CoreContext) {
this.logger = core.logger.get('feature-flags-service');
this.featureFlagsClient = OpenFeature.getClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,28 @@ const createFeatureFlagsServiceMock = (): jest.Mocked<PublicMethodsOf<FeatureFla
};
};

/**
* Mocks for the Feature Flags service (browser-side)
*/
export const coreFeatureFlagsMock = {
/**
* Mocks the entire feature flags service
*/
create: createFeatureFlagsServiceMock,
/**
* Mocks the core-internal setup contract
*/
createInternalSetup: createFeatureFlagsInternalSetup,
/**
* Mocks the setup contract
*/
createSetup: createFeatureFlagsSetup,
/**
* Mocks the start contract
*/
createStart: createFeatureFlagsStart,
/**
* Mocks the request handler context contract
*/
createRequestHandlerContext,
};
Original file line number Diff line number Diff line change
Expand Up @@ -116,36 +116,48 @@ export interface FeatureFlagsStart {

/**
* Evaluates a boolean flag
* @param flagName The flag ID to evaluate
* @param fallbackValue If the flag cannot be evaluated for whatever reason, the fallback value is provided.
* @public
*/
getBooleanValue(flagName: string, fallbackValue: boolean): Promise<boolean>;

/**
* Evaluates a string flag
* @param flagName The flag ID to evaluate
* @param fallbackValue If the flag cannot be evaluated for whatever reason, the fallback value is provided.
* @public
*/
getStringValue<Value extends string>(flagName: string, fallbackValue: Value): Promise<Value>;

/**
* Evaluates a number flag
* @param flagName The flag ID to evaluate
* @param fallbackValue If the flag cannot be evaluated for whatever reason, the fallback value is provided.
* @public
*/
getNumberValue<Value extends number>(flagName: string, fallbackValue: Value): Promise<Value>;

/**
* Returns an observable of a boolean flag
* @param flagName The flag ID to evaluate
* @param fallbackValue If the flag cannot be evaluated for whatever reason, the fallback value is provided.
* @public
*/
getBooleanValue$(flagName: string, fallbackValue: boolean): Observable<boolean>;

/**
* Returns an observable of a string flag
* @param flagName The flag ID to evaluate
* @param fallbackValue If the flag cannot be evaluated for whatever reason, the fallback value is provided.
* @public
*/
getStringValue$<Value extends string>(flagName: string, fallbackValue: Value): Observable<Value>;

/**
* Returns an observable of a number flag
* @param flagName The flag ID to evaluate
* @param fallbackValue If the flag cannot be evaluated for whatever reason, the fallback value is provided.
* @public
*/
getNumberValue$<Value extends number>(flagName: string, fallbackValue: Value): Observable<Value>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import type { FeatureFlagsStart } from '..';

/**
* The HTTP request handler context for evaluating feature flags
*/
export type FeatureFlagsRequestHandlerContext = Pick<
FeatureFlagsStart,
'getBooleanValue' | 'getStringValue' | 'getNumberValue'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,34 @@ import type { RequestHandlerContextBase } from '@kbn/core-http-server';
import type { IUiSettingsClient } from '@kbn/core-ui-settings-server';

/**
* `uiSettings` http request context provider during the preboot phase.
* @public
*/
export interface PrebootUiSettingsRequestHandlerContext {
/**
* The {@link IUiSettingsClient | UI Settings client}.
*/
client: IUiSettingsClient;
}

/**
* The `core` context provided to route handler during the preboot phase.
* @public
*/
export interface PrebootCoreRequestHandlerContext {
/**
* {@link PrebootUiSettingsRequestHandlerContext}
*/
uiSettings: PrebootUiSettingsRequestHandlerContext;
}

/**
* Base context passed to a route handler during the preboot phase, containing the `core` context part.
* @public
*/
export interface PrebootRequestHandlerContext extends RequestHandlerContextBase {
/**
* Promise that resolves the {@link PrebootCoreRequestHandlerContext}
*/
core: Promise<PrebootCoreRequestHandlerContext>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,33 @@ import type { FeatureFlagsRequestHandlerContext } from '@kbn/core-feature-flags-
* @public
*/
export interface CoreRequestHandlerContext {
/**
* {@link SavedObjectsRequestHandlerContext}
*/
savedObjects: SavedObjectsRequestHandlerContext;
/**
* {@link ElasticsearchRequestHandlerContext}
*/
elasticsearch: ElasticsearchRequestHandlerContext;
/**
* {@link FeatureFlagsRequestHandlerContext}
*/
featureFlags: FeatureFlagsRequestHandlerContext;
/**
* {@link UiSettingsRequestHandlerContext}
*/
uiSettings: UiSettingsRequestHandlerContext;
/**
* {@link DeprecationsRequestHandlerContext}
*/
deprecations: DeprecationsRequestHandlerContext;
/**
* {@link SecurityRequestHandlerContext}
*/
security: SecurityRequestHandlerContext;
/**
* {@link UserProfileRequestHandlerContext}
*/
userProfile: UserProfileRequestHandlerContext;
}

Expand All @@ -45,6 +66,9 @@ export interface CoreRequestHandlerContext {
* @public
*/
export interface RequestHandlerContext extends RequestHandlerContextBase {
/**
* Promise that resolves the {@link CoreRequestHandlerContext}
*/
core: Promise<CoreRequestHandlerContext>;
}

Expand Down

0 comments on commit acaf70b

Please sign in to comment.