Skip to content

Commit

Permalink
refactor: segment in feature oriented architecture (#6434)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Mar 5, 2024
1 parent 9eb4e71 commit 5d00157
Show file tree
Hide file tree
Showing 21 changed files with 77 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/lib/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { FeatureEnvironmentStore } from './feature-environment-store';
import { ClientMetricsStoreV2 } from '../features/metrics/client-metrics/client-metrics-store-v2';
import UserSplashStore from './user-splash-store';
import RoleStore from './role-store';
import SegmentStore from './segment-store';
import SegmentStore from '../features/segment/segment-store';
import GroupStore from './group-store';
import PatStore from './pat-store';
import { PublicSignupTokenStore } from './public-signup-token-store';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/features/feature-toggle/feature-toggle-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ import { AccessService } from '../../services/access-service';
import { IUser } from '../../server-impl';
import { IFeatureProjectUserParams } from './feature-toggle-controller';
import { unique } from '../../util/unique';
import { ISegmentService } from '../../segments/segment-service-interface';
import { ISegmentService } from '../segment/segment-service-interface';
import { IChangeRequestAccessReadModel } from '../change-request-access-service/change-request-access-read-model';
import { checkFeatureFlagNamesAgainstPattern } from '../feature-naming-pattern/feature-naming-validation';
import { IPrivateProjectChecker } from '../private-project/privateProjectCheckerType';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '../../../types';
import EnvironmentService from '../../project-environments/environment-service';
import { ForbiddenError, PatternError, PermissionError } from '../../../error';
import { ISegmentService } from '../../../segments/segment-service-interface';
import { ISegmentService } from '../../segment/segment-service-interface';
import { createFeatureToggleService, createSegmentService } from '../..';
import {
insertFeatureEnvironmentsLastSeen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import EnvironmentStore from '../project-environments/environment-store';
import StrategyStore from '../../db/strategy-store';
import ContextFieldStore from '../../db/context-field-store';
import GroupStore from '../../db/group-store';
import SegmentStore from '../../db/segment-store';
import SegmentStore from '../segment/segment-store';
import RoleStore from '../../db/role-store';
import SettingStore from '../../db/setting-store';
import ClientInstanceStore from '../../db/client-instance-store';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/features/instance-stats/instance-stats-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { IGroupStore } from '../../types/stores/group-store';
import { IProjectStore } from '../../features/project/project-store-type';
import { IStrategyStore } from '../../types/stores/strategy-store';
import { IUserStore } from '../../types/stores/user-store';
import { ISegmentStore } from '../../types/stores/segment-store';
import { ISegmentStore } from '../segment/segment-store-type';
import { IRoleStore } from '../../types/stores/role-store';
import VersionService from '../../services/version-service';
import { ISettingStore } from '../../types/stores/settings-store';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { randomId } from '../../../../lib/util/random-id';
import { IFeatureToggleClient, ISegment } from '../../../../lib/types/model';
import { collectIds } from '../../../../lib/util/collect-ids';
import dbInit, { ITestDb } from '../../helpers/database-init';
import getLogger from '../../../fixtures/no-logger';
import { randomId } from '../../util/random-id';
import { IFeatureToggleClient, ISegment } from '../../types/model';
import { collectIds } from '../../util/collect-ids';
import dbInit, { ITestDb } from '../../../test/e2e/helpers/database-init';
import getLogger from '../../../test/fixtures/no-logger';
import {
addStrategyToFeatureEnv,
createFeatureToggle,
} from '../../helpers/app.utils';
} from '../../../test/e2e/helpers/app.utils';
import {
IUnleashTest,
setupAppWithCustomConfig,
} from '../../helpers/test-helper';
import { StrategiesUsingSegment } from '../../../../lib/segments/segment-service-interface';
import { IUser } from '../../../../lib/types';
} from '../../../test/e2e/helpers/test-helper';
import { StrategiesUsingSegment } from './segment-service-interface';
import { IUser } from '../../types';

let app: IUnleashTest;
let db: ITestDb;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
import dbInit, { ITestDb } from '../../helpers/database-init';
import getLogger from '../../../fixtures/no-logger';
import dbInit, { ITestDb } from '../../../test/e2e/helpers/database-init';
import getLogger from '../../../test/fixtures/no-logger';
import {
IUnleashTest,
setupAppWithCustomConfig,
} from '../../helpers/test-helper';
import {
IConstraint,
IFeatureToggleClient,
ISegment,
} from '../../../../lib/types/model';
import { randomId } from '../../../../lib/util/random-id';
import User from '../../../../lib/types/user';
} from '../../../test/e2e/helpers/test-helper';
import { IConstraint, IFeatureToggleClient, ISegment } from '../../types/model';
import { randomId } from '../../util/random-id';
import User from '../../types/user';
import {
DEFAULT_SEGMENT_VALUES_LIMIT,
DEFAULT_STRATEGY_SEGMENTS_LIMIT,
} from '../../../../lib/util/segments';
import { collectIds } from '../../../../lib/util/collect-ids';
import { arraysHaveSameItems } from '../../../../lib/util/arraysHaveSameItems';
} from '../../util/segments';
import { collectIds } from '../../util/collect-ids';
import { arraysHaveSameItems } from '../../util/arraysHaveSameItems';
import {
CreateFeatureSchema,
CreateFeatureStrategySchema,
FeatureStrategySchema,
UpsertSegmentSchema,
} from '../../../../lib/openapi';
import { DEFAULT_ENV } from '../../../../lib/util';
import { DEFAULT_PROJECT } from '../../../../lib/types';
} from '../../openapi';
import { DEFAULT_ENV } from '../../util';
import { DEFAULT_PROJECT } from '../../types';

let db: ITestDb;
let app: IUnleashTest;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/features/segment/createSegmentService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Db, IUnleashConfig } from '../../server-impl';
import { EventService, SegmentService } from '../../services';
import FakeEventStore from '../../../test/fixtures/fake-event-store';
import { ISegmentService } from '../../segments/segment-service-interface';
import { ISegmentService } from './segment-service-interface';
import FeatureStrategiesStore from '../feature-toggle/feature-toggle-strategies-store';
import SegmentStore from '../../db/segment-store';
import SegmentStore from './segment-store';
import FakeSegmentStore from '../../../test/fixtures/fake-segment-store';
import FakeFeatureStrategiesStore from '../feature-toggle/fakes/fake-feature-strategies-store';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/features/segment/segment-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
emptyResponse,
getStandardResponses,
} from '../../openapi/util/standard-responses';
import { ISegmentService } from '../../segments/segment-service-interface';
import { ISegmentService } from './segment-service-interface';
import { SegmentStrategiesSchema } from '../../openapi/spec/segment-strategies-schema';
import { AccessService, OpenApiService } from '../../services';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChangeRequestStrategy } from '../features/change-request-segment-usage-service/change-request-segment-usage-read-model';
import { UpsertSegmentSchema } from '../openapi';
import { IFeatureStrategy, ISegment, IUser } from '../types';
import { ChangeRequestStrategy } from '../change-request-segment-usage-service/change-request-segment-usage-read-model';
import { UpsertSegmentSchema } from '../../openapi';
import { IFeatureStrategy, ISegment, IUser } from '../../types';

export type StrategiesUsingSegment = {
strategies: IFeatureStrategy[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { IUnleashConfig } from '../types/option';
import { IUnleashConfig } from '../../types/option';
import {
IFlagResolver,
IUnleashStores,
SKIP_CHANGE_REQUEST,
SYSTEM_USER,
} from '../types';
import { Logger } from '../logger';
import NameExistsError from '../error/name-exists-error';
import { ISegmentStore } from '../types/stores/segment-store';
import { ISegment } from '../types/model';
import { segmentSchema } from './segment-schema';
} from '../../types';
import { Logger } from '../../logger';
import NameExistsError from '../../error/name-exists-error';
import { ISegmentStore } from './segment-store-type';
import { ISegment } from '../../types/model';
import { segmentSchema } from '../../services/segment-schema';
import {
SEGMENT_CREATED,
SEGMENT_DELETED,
SEGMENT_UPDATED,
} from '../types/events';
import User from '../types/user';
import { IFeatureStrategiesStore } from '../features/feature-toggle/types/feature-toggle-strategies-store-type';
import BadDataError from '../error/bad-data-error';
} from '../../types/events';
import User from '../../types/user';
import { IFeatureStrategiesStore } from '../feature-toggle/types/feature-toggle-strategies-store-type';
import BadDataError from '../../error/bad-data-error';
import {
ISegmentService,
StrategiesUsingSegment,
} from '../segments/segment-service-interface';
import { PermissionError } from '../error';
import { IChangeRequestAccessReadModel } from '../features/change-request-access-service/change-request-access-read-model';
import { IPrivateProjectChecker } from '../features/private-project/privateProjectCheckerType';
import EventService from '../features/events/event-service';
import { IChangeRequestSegmentUsageReadModel } from '../features/change-request-segment-usage-service/change-request-segment-usage-read-model';
} from './segment-service-interface';
import { PermissionError } from '../../error';
import { IChangeRequestAccessReadModel } from '../change-request-access-service/change-request-access-read-model';
import { IPrivateProjectChecker } from '../private-project/privateProjectCheckerType';
import EventService from '../events/event-service';
import { IChangeRequestSegmentUsageReadModel } from '../change-request-segment-usage-service/change-request-segment-usage-read-model';

export class SegmentService implements ISegmentService {
private logger: Logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IFeatureStrategySegment, ISegment } from '../model';
import { Store } from './store';
import User from '../user';
import { IFeatureStrategySegment, ISegment } from '../../types/model';
import { Store } from '../../types/stores/store';
import User from '../../types/user';

export interface ISegmentStore extends Store<ISegment, number> {
getAll(includeChangeRequestUsageData?: boolean): Promise<ISegment[]>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ISegmentStore } from '../types/stores/segment-store';
import dbInit, { ITestDb } from '../../test/e2e/helpers/database-init';
import getLogger from '../../test/fixtures/no-logger';
import NotFoundError from '../error/notfound-error';
import { IUnleashStores, IUser } from '../types';
import { ISegmentStore } from './segment-store-type';
import dbInit, { ITestDb } from '../../../test/e2e/helpers/database-init';
import getLogger from '../../../test/fixtures/no-logger';
import NotFoundError from '../../error/notfound-error';
import { IUnleashStores, IUser } from '../../types';

let stores: IUnleashStores;
let db: ITestDb;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { ISegmentStore } from '../types/stores/segment-store';
import { IConstraint, IFeatureStrategySegment, ISegment } from '../types/model';
import { Logger, LogProvider } from '../logger';
import { ISegmentStore } from './segment-store-type';
import {
IConstraint,
IFeatureStrategySegment,
ISegment,
} from '../../types/model';
import { Logger, LogProvider } from '../../logger';
import EventEmitter from 'events';
import NotFoundError from '../error/notfound-error';
import { PartialSome } from '../types/partial';
import User from '../types/user';
import { Db } from './db';
import { IFlagResolver } from '../types';
import { isDefined } from '../util';
import NotFoundError from '../../error/notfound-error';
import { PartialSome } from '../../types/partial';
import User from '../../types/user';
import { Db } from '../../db/db';
import { IFlagResolver } from '../../types';
import { isDefined } from '../../util';

const T = {
segments: 'segments',
Expand Down
2 changes: 1 addition & 1 deletion src/lib/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export * from './types';
export * from './util';
export * from './error';
export * from './features';
export * from './segments/segment-service-interface';
export * from './features/segment/segment-service-interface';
2 changes: 1 addition & 1 deletion src/lib/services/feature-service-potentially-stale.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createTestConfig } from '../../test/config/test-config';
import FeatureToggleService from '../features/feature-toggle/feature-toggle-service';
import { AccessService } from './access-service';
import { IChangeRequestAccessReadModel } from '../features/change-request-access-service/change-request-access-read-model';
import { ISegmentService } from '../segments/segment-service-interface';
import { ISegmentService } from '../features/segment/segment-service-interface';
import { IPrivateProjectChecker } from '../features/private-project/privateProjectCheckerType';
import { IDependentFeaturesReadModel } from '../features/dependent-features/dependent-features-read-model-type';
import EventService from '../features/events/event-service';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import EnvironmentService from '../features/project-environments/environment-ser
import FeatureTagService from './feature-tag-service';
import ProjectHealthService from './project-health-service';
import UserSplashService from './user-splash-service';
import { SegmentService } from './segment-service';
import { SegmentService } from '../features/segment/segment-service';
import { OpenApiService } from './openapi-service';
import { ClientSpecService } from './client-spec-service';
import { PlaygroundService } from '../features/playground/playground-service';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/services/state-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { IFeatureEnvironmentStore } from '../types/stores/feature-environment-st
import { IUnleashStores } from '../types/stores';
import { DEFAULT_ENV } from '../util/constants';
import { GLOBAL_ENV } from '../types/environment';
import { ISegmentStore } from '../types/stores/segment-store';
import { ISegmentStore } from '../features/segment/segment-store-type';
import { PartialSome } from '../types/partial';
import EventService from '../features/events/event-service';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/types/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
IExportService,
IImportService,
} from '../features/export-import-toggles/export-import-service';
import { ISegmentService } from '../segments/segment-service-interface';
import { ISegmentService } from '../features/segment/segment-service-interface';
import ConfigurationRevisionService from '../features/feature-toggle/configuration-revision-service';
import EventAnnouncerService from '../services/event-announcer-service';
import { IPrivateProjectChecker } from '../features/private-project/privateProjectCheckerType';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { IFeatureToggleClientStore } from '../features/client-feature-toggles/ty
import { IClientMetricsStoreV2 } from '../features/metrics/client-metrics/client-metrics-store-v2-type';
import { IUserSplashStore } from './stores/user-splash-store';
import { IRoleStore } from './stores/role-store';
import { ISegmentStore } from './stores/segment-store';
import { ISegmentStore } from '../features/segment/segment-store-type';
import { IGroupStore } from './stores/group-store';
import { IPatStore } from './stores/pat-store';
import { IPublicSignupTokenStore } from './stores/public-signup-token-store';
Expand Down
2 changes: 1 addition & 1 deletion src/test/fixtures/fake-segment-store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ISegmentStore } from '../../lib/types/stores/segment-store';
import { ISegmentStore } from '../../lib/features/segment/segment-store-type';
import { IFeatureStrategySegment, ISegment } from '../../lib/types/model';

export default class FakeSegmentStore implements ISegmentStore {
Expand Down

0 comments on commit 5d00157

Please sign in to comment.