Skip to content

Commit

Permalink
Refactor/move features to feature oriented architecture (#4994)
Browse files Browse the repository at this point in the history
This PR gathers feature related files in the same folder.
  • Loading branch information
FredrikOseberg authored Oct 11, 2023
1 parent a3b4e9d commit bc96216
Show file tree
Hide file tree
Showing 51 changed files with 183 additions and 187 deletions.
4 changes: 2 additions & 2 deletions src/lib/db/feature-strategy-store.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dbInit from '../../test/e2e/helpers/database-init';
import getLogger from '../../test/fixtures/no-logger';
import FeatureStrategiesStore from './feature-strategy-store';
import FeatureToggleStore from './feature-toggle-store';
import FeatureStrategiesStore from '../features/feature-toggle/feature-toggle-strategies-store';
import FeatureToggleStore from '../features/feature-toggle/feature-toggle-store';
import StrategyStore from './strategy-store';
import { IFeatureStrategy, PartialSome } from '../types';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/db/feature-toggle-client-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '../types';
import { DEFAULT_ENV, ensureStringValue, mapValues } from '../util';
import EventEmitter from 'events';
import FeatureToggleStore from './feature-toggle-store';
import FeatureToggleStore from '../features/feature-toggle/feature-toggle-store';
import { Db } from './db';
import Raw = Knex.Raw;

Expand Down
4 changes: 2 additions & 2 deletions src/lib/db/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IUnleashConfig, IUnleashStores } from '../types';

import EventStore from './event-store';
import FeatureToggleStore from './feature-toggle-store';
import FeatureToggleStore from '../features/feature-toggle/feature-toggle-store';
import FeatureTypeStore from './feature-type-store';
import StrategyStore from './strategy-store';
import ClientInstanceStore from './client-instance-store';
Expand All @@ -18,7 +18,7 @@ import SessionStore from './session-store';
import { AccessStore } from './access-store';
import { ResetTokenStore } from './reset-token-store';
import UserFeedbackStore from './user-feedback-store';
import FeatureStrategyStore from './feature-strategy-store';
import FeatureStrategyStore from '../features/feature-toggle/feature-toggle-strategies-store';
import FeatureToggleClientStore from './feature-toggle-client-store';
import EnvironmentStore from './environment-store';
import FeatureTagStore from './feature-tag-store';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Db } from '../../db/db';
import { IUnleashConfig } from '../../types';
import ExportImportService from './export-import-service';
import { ImportTogglesStore } from './import-toggles-store';
import FeatureToggleStore from '../../db/feature-toggle-store';
import FeatureToggleStore from '../feature-toggle/feature-toggle-store';
import TagStore from '../../db/tag-store';
import TagTypeStore from '../../db/tag-type-store';
import ProjectStore from '../../db/project-store';
import FeatureTagStore from '../../db/feature-tag-store';
import StrategyStore from '../../db/strategy-store';
import ContextFieldStore from '../../db/context-field-store';
import FeatureStrategiesStore from '../../db/feature-strategy-store';
import FeatureStrategiesStore from '../feature-toggle/feature-toggle-strategies-store';
import {
ContextService,
EventService,
Expand All @@ -27,15 +27,15 @@ import {
} from '../feature-toggle/createFeatureToggleService';
import SegmentStore from '../../db/segment-store';
import { FeatureEnvironmentStore } from '../../db/feature-environment-store';
import FakeFeatureToggleStore from '../../../test/fixtures/fake-feature-toggle-store';
import FakeFeatureToggleStore from '../feature-toggle/fakes/fake-feature-toggle-store';
import FakeTagStore from '../../../test/fixtures/fake-tag-store';
import FakeTagTypeStore from '../../../test/fixtures/fake-tag-type-store';
import FakeSegmentStore from '../../../test/fixtures/fake-segment-store';
import FakeProjectStore from '../../../test/fixtures/fake-project-store';
import FakeFeatureTagStore from '../../../test/fixtures/fake-feature-tag-store';
import FakeContextFieldStore from '../../../test/fixtures/fake-context-field-store';
import FakeEventStore from '../../../test/fixtures/fake-event-store';
import FakeFeatureStrategiesStore from '../../../test/fixtures/fake-feature-strategies-store';
import FakeFeatureStrategiesStore from '../feature-toggle/fakes/fake-feature-strategies-store';
import FakeFeatureEnvironmentStore from '../../../test/fixtures/fake-feature-environment-store';
import FakeStrategiesStore from '../../../test/fixtures/fake-strategies-store';
import EventStore from '../../db/event-store';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { Logger } from '../../logger';
import { IFeatureTagStore } from '../../types/stores/feature-tag-store';
import { ITagTypeStore } from '../../types/stores/tag-type-store';
import { IStrategy } from '../../types/stores/strategy-store';
import { IFeatureToggleStore } from '../../types/stores/feature-toggle-store';
import { IFeatureStrategiesStore } from '../../types/stores/feature-strategies-store';
import { IFeatureToggleStore } from '../feature-toggle/types/feature-toggle-store-type';
import { IFeatureStrategiesStore } from '../feature-toggle/types/feature-toggle-strategies-store-type';
import { IFeatureEnvironmentStore } from '../../types/stores/feature-environment-store';
import { IContextFieldStore, IUnleashStores } from '../../types/stores';
import { ISegmentStore } from '../../types/stores/segment-store';
Expand Down Expand Up @@ -48,7 +48,7 @@ import {
import { ImportPermissionsService, Mode } from './import-permissions-service';
import { ImportValidationMessages } from './import-validation-messages';
import { findDuplicates } from '../../util/findDuplicates';
import { FeatureNameCheckResultWithFeaturePattern } from '../../services/feature-toggle-service';
import { FeatureNameCheckResultWithFeaturePattern } from '../feature-toggle/feature-toggle-service';

export default class ExportImportService {
private logger: Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ImportTogglesValidateItemSchema,
} from '../../openapi';
import { IContextFieldDto } from '../../types/stores/context-field-store';
import { FeatureNameCheckResultWithFeaturePattern } from '../../services/feature-toggle-service';
import { FeatureNameCheckResultWithFeaturePattern } from '../feature-toggle/feature-toggle-service';
import { ProjectFeaturesLimit } from './import-toggles-store-type';

export interface IErrorsParams {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/features/feature-toggle/createFeatureToggleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
FeatureToggleService,
GroupService,
} from '../../services';
import FeatureStrategiesStore from '../../db/feature-strategy-store';
import FeatureToggleStore from '../../db/feature-toggle-store';
import FeatureStrategiesStore from './feature-toggle-strategies-store';
import FeatureToggleStore from './feature-toggle-store';
import FeatureToggleClientStore from '../../db/feature-toggle-client-store';
import ProjectStore from '../../db/project-store';
import { FeatureEnvironmentStore } from '../../db/feature-environment-store';
Expand All @@ -18,8 +18,8 @@ import EnvironmentStore from '../../db/environment-store';
import { Db } from '../../db/db';
import { IUnleashConfig } from '../../types';
import FakeEventStore from '../../../test/fixtures/fake-event-store';
import FakeFeatureStrategiesStore from '../../../test/fixtures/fake-feature-strategies-store';
import FakeFeatureToggleStore from '../../../test/fixtures/fake-feature-toggle-store';
import FakeFeatureStrategiesStore from './fakes/fake-feature-strategies-store';
import FakeFeatureToggleStore from './fakes/fake-feature-toggle-store';
import FakeFeatureToggleClientStore from '../../../test/fixtures/fake-feature-toggle-client-store';
import FakeProjectStore from '../../../test/fixtures/fake-project-store';
import FakeFeatureEnvironmentStore from '../../../test/fixtures/fake-feature-environment-store';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
IFeatureToggleQuery,
IFeatureStrategy,
FeatureToggle,
} from '../../lib/types/model';
import NotFoundError from '../../lib/error/notfound-error';
import { IFeatureStrategiesStore } from '../../lib/types/stores/feature-strategies-store';
import { IFeatureProjectUserParams } from '../../lib/routes/admin-api/project/project-features';
} from '../../../types/model';
import NotFoundError from '../../../error/notfound-error';
import { IFeatureStrategiesStore } from '../types/feature-toggle-strategies-store-type';
import { IFeatureProjectUserParams } from '../feature-toggle-controller';

interface ProjectEnvironment {
projectName: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {
IFeatureToggleQuery,
IFeatureToggleStore,
} from '../../lib/types/stores/feature-toggle-store';
import NotFoundError from '../../lib/error/notfound-error';
} from '../types/feature-toggle-store-type';
import NotFoundError from '../../../error/notfound-error';
import {
FeatureToggle,
FeatureToggleDTO,
IFeatureEnvironment,
IVariant,
} from 'lib/types/model';
import { LastSeenInput } from '../../lib/services/client-metrics/last-seen/last-seen-service';
import { EnvironmentFeatureNames } from '../../lib/db/feature-toggle-store';
import { LastSeenInput } from '../../../services/client-metrics/last-seen/last-seen-service';
import { EnvironmentFeatureNames } from '../feature-toggle-store';

export default class FakeFeatureToggleStore implements IFeatureToggleStore {
features: FeatureToggle[] = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Request, Response } from 'express';
import { applyPatch, Operation } from 'fast-json-patch';
import Controller from '../../controller';
import Controller from '../../routes/controller';
import {
CREATE_FEATURE,
CREATE_FEATURE_STRATEGY,
Expand All @@ -14,10 +14,10 @@ import {
UPDATE_FEATURE,
UPDATE_FEATURE_ENVIRONMENT,
UPDATE_FEATURE_STRATEGY,
} from '../../../types';
import { Logger } from '../../../logger';
import { extractUsername } from '../../../util';
import { IAuthRequest } from '../../unleash-types';
} from '../../types';
import { Logger } from '../../logger';
import { extractUsername } from '../../util';
import { IAuthRequest } from '../../routes/unleash-types';
import {
AdminFeaturesQuerySchema,
BulkToggleFeaturesSchema,
Expand All @@ -40,19 +40,16 @@ import {
TagSchema,
UpdateFeatureSchema,
UpdateFeatureStrategySchema,
} from '../../../openapi';
} from '../../openapi';
import {
FeatureTagService,
FeatureToggleService,
OpenApiService,
} from '../../../services';
import { querySchema } from '../../../schema/feature-schema';
import { BatchStaleSchema } from '../../../openapi/spec/batch-stale-schema';
import {
TransactionCreator,
UnleashTransaction,
} from '../../../db/transaction';
import { BadDataError } from '../../../error';
} from '../../services';
import { querySchema } from '../../schema/feature-schema';
import { BatchStaleSchema } from '../../openapi/spec/batch-stale-schema';
import { TransactionCreator, UnleashTransaction } from '../../db/transaction';
import { BadDataError } from '../../error';

interface FeatureStrategyParams {
projectId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,61 +45,61 @@ import {
StrategyIds,
Unsaved,
WeightType,
} from '../types';
import { Logger } from '../logger';
} from '../../types';
import { Logger } from '../../logger';
import {
ForbiddenError,
FOREIGN_KEY_VIOLATION,
OperationDeniedError,
PatternError,
PermissionError,
} from '../error';
import BadDataError from '../error/bad-data-error';
import NameExistsError from '../error/name-exists-error';
import InvalidOperationError from '../error/invalid-operation-error';
} from '../../error';
import BadDataError from '../../error/bad-data-error';
import NameExistsError from '../../error/name-exists-error';
import InvalidOperationError from '../../error/invalid-operation-error';
import {
constraintSchema,
featureMetadataSchema,
nameSchema,
variantsArraySchema,
} from '../schema/feature-schema';
import NotFoundError from '../error/notfound-error';
} from '../../schema/feature-schema';
import NotFoundError from '../../error/notfound-error';
import {
FeatureConfigurationClient,
IFeatureStrategiesStore,
} from '../types/stores/feature-strategies-store';
} from './types/feature-toggle-strategies-store-type';
import {
DATE_OPERATORS,
DEFAULT_ENV,
NUM_OPERATORS,
SEMVER_OPERATORS,
STRING_OPERATORS,
} from '../util';
} from '../../util';
import { applyPatch, deepClone, Operation } from 'fast-json-patch';
import {
validateDate,
validateLegalValues,
validateNumber,
validateSemver,
validateString,
} from '../util/validators/constraint-types';
} from '../../util/validators/constraint-types';
import { IContextFieldStore } from 'lib/types/stores/context-field-store';
import { SetStrategySortOrderSchema } from 'lib/openapi/spec/set-strategy-sort-order-schema';
import {
getDefaultStrategy,
getProjectDefaultStrategy,
} from '../features/playground/feature-evaluator/helpers';
import { AccessService } from './access-service';
import { User } from '../server-impl';
import { IFeatureProjectUserParams } from '../routes/admin-api/project/project-features';
import { unique } from '../util/unique';
} from '../playground/feature-evaluator/helpers';
import { AccessService } from '../../services/access-service';
import { User } from '../../server-impl';
import { IFeatureProjectUserParams } from './feature-toggle-controller';
import { unique } from '../../util/unique';
import { ISegmentService } from 'lib/segments/segment-service-interface';
import { IChangeRequestAccessReadModel } from '../features/change-request-access-service/change-request-access-read-model';
import { checkFeatureFlagNamesAgainstPattern } from '../features/feature-naming-pattern/feature-naming-validation';
import { IPrivateProjectChecker } from '../features/private-project/privateProjectCheckerType';
import { IDependentFeaturesReadModel } from '../features/dependent-features/dependent-features-read-model-type';
import EventService from './event-service';
import { DependentFeaturesService } from '../features/dependent-features/dependent-features-service';
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';
import { IDependentFeaturesReadModel } from '../dependent-features/dependent-features-read-model-type';
import EventService from '../../services/event-service';
import { DependentFeaturesService } from '../dependent-features/dependent-features-service';

interface IFeatureContext {
featureName: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Knex } from 'knex';
import EventEmitter from 'events';
import metricsHelper from '../util/metrics-helper';
import { DB_TIME } from '../metric-events';
import NotFoundError from '../error/notfound-error';
import { Logger, LogProvider } from '../logger';
import { FeatureToggle, FeatureToggleDTO, IVariant } from '../types/model';
import { IFeatureToggleStore } from '../types/stores/feature-toggle-store';
import { Db } from './db';
import { LastSeenInput } from '../services/client-metrics/last-seen/last-seen-service';
import { NameExistsError } from '../error';
import metricsHelper from '../../util/metrics-helper';
import { DB_TIME } from '../../metric-events';
import NotFoundError from '../../error/notfound-error';
import { Logger, LogProvider } from '../../logger';
import { FeatureToggle, FeatureToggleDTO, IVariant } from '../../types/model';
import { IFeatureToggleStore } from './types/feature-toggle-store-type';
import { Db } from '../../db/db';
import { LastSeenInput } from '../../services/client-metrics/last-seen/last-seen-service';
import { NameExistsError } from '../../error';

export type EnvironmentFeatureNames = { [key: string]: string[] };

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Knex } from 'knex';
import EventEmitter from 'events';
import { v4 as uuidv4 } from 'uuid';
import metricsHelper from '../util/metrics-helper';
import { DB_TIME } from '../metric-events';
import { Logger, LogProvider } from '../logger';
import NotFoundError from '../error/notfound-error';
import metricsHelper from '../../util/metrics-helper';
import { DB_TIME } from '../../metric-events';
import { Logger, LogProvider } from '../../logger';
import NotFoundError from '../../error/notfound-error';
import {
FeatureToggleWithEnvironment,
IConstraint,
Expand All @@ -19,11 +19,11 @@ import {
ITag,
PartialDeep,
PartialSome,
} from '../types';
} from '../../types';
import FeatureToggleStore from './feature-toggle-store';
import { ensureStringValue, mapValues } from '../util';
import { IFeatureProjectUserParams } from '../routes/admin-api/project/project-features';
import { Db } from './db';
import { ensureStringValue, mapValues } from '../../util';
import { IFeatureProjectUserParams } from './feature-toggle-controller';
import { Db } from '../../db/db';
import Raw = Knex.Raw;

const COLUMNS = [
Expand Down
Loading

0 comments on commit bc96216

Please sign in to comment.