From bf1223e07dd1316ff66580ce0abc2503db2c6c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Thu, 9 Dec 2021 21:50:06 +0100 Subject: [PATCH] fix: rename services --- src/lib/routes/admin-api/client-metrics.ts | 2 +- src/lib/routes/admin-api/metrics.ts | 2 +- src/lib/routes/client-api/metrics.test.ts | 2 +- src/lib/routes/client-api/metrics.ts | 4 +- src/lib/routes/client-api/register.ts | 2 +- .../client-metrics/client-metrics-schema.ts | 27 --------- ...trics.test.ts => instance-service.test.ts} | 2 +- ...nstance-service.ts => instance-service.ts} | 6 +- .../services/client-metrics/metrics-schema.ts | 18 ------ ...cs-service-v2.ts => metrics-service-v2.ts} | 2 +- .../client-metrics/register-schema.ts | 17 ------ src/lib/services/client-metrics/schema.ts | 60 +++++++++++++++++++ src/lib/services/index.ts | 4 +- src/lib/types/services.ts | 4 +- .../client-metrics-service.e2e.test.ts | 2 +- 15 files changed, 76 insertions(+), 78 deletions(-) delete mode 100644 src/lib/services/client-metrics/client-metrics-schema.ts rename src/lib/services/client-metrics/{client-metrics.test.ts => instance-service.test.ts} (99%) rename src/lib/services/client-metrics/{client-instance-service.ts => instance-service.ts} (97%) delete mode 100644 src/lib/services/client-metrics/metrics-schema.ts rename src/lib/services/client-metrics/{client-metrics-service-v2.ts => metrics-service-v2.ts} (98%) delete mode 100644 src/lib/services/client-metrics/register-schema.ts create mode 100644 src/lib/services/client-metrics/schema.ts diff --git a/src/lib/routes/admin-api/client-metrics.ts b/src/lib/routes/admin-api/client-metrics.ts index 49caff40a9..7986f51065 100644 --- a/src/lib/routes/admin-api/client-metrics.ts +++ b/src/lib/routes/admin-api/client-metrics.ts @@ -3,7 +3,7 @@ import Controller from '../controller'; import { IUnleashConfig } from '../../types/option'; import { IUnleashServices } from '../../types/services'; import { Logger } from '../../logger'; -import ClientMetricsServiceV2 from '../../services/client-metrics/client-metrics-service-v2'; +import ClientMetricsServiceV2 from '../../services/client-metrics/metrics-service-v2'; class ClientMetricsController extends Controller { private logger: Logger; diff --git a/src/lib/routes/admin-api/metrics.ts b/src/lib/routes/admin-api/metrics.ts index 062cbce731..4d7c959912 100644 --- a/src/lib/routes/admin-api/metrics.ts +++ b/src/lib/routes/admin-api/metrics.ts @@ -4,7 +4,7 @@ import { UPDATE_APPLICATION } from '../../types/permissions'; import { IUnleashConfig } from '../../types/option'; import { IUnleashServices } from '../../types/services'; import { Logger } from '../../logger'; -import ClientInstanceService from '../../services/client-metrics/client-instance-service'; +import ClientInstanceService from '../../services/client-metrics/instance-service'; class MetricsController extends Controller { private logger: Logger; diff --git a/src/lib/routes/client-api/metrics.test.ts b/src/lib/routes/client-api/metrics.test.ts index f19338aadc..98dc6372f4 100644 --- a/src/lib/routes/client-api/metrics.test.ts +++ b/src/lib/routes/client-api/metrics.test.ts @@ -2,7 +2,7 @@ import supertest from 'supertest'; import createStores from '../../../test/fixtures/store'; import getApp from '../../app'; import { createTestConfig } from '../../../test/config/test-config'; -import { clientMetricsSchema } from '../../services/client-metrics/client-metrics-schema'; +import { clientMetricsSchema } from '../../services/client-metrics/schema'; import { createServices } from '../../services'; import { IUnleashStores } from '../../types'; import { IUnleashOptions } from '../../server-impl'; diff --git a/src/lib/routes/client-api/metrics.ts b/src/lib/routes/client-api/metrics.ts index c80936620c..eecaea2fa2 100644 --- a/src/lib/routes/client-api/metrics.ts +++ b/src/lib/routes/client-api/metrics.ts @@ -2,12 +2,12 @@ import { Response } from 'express'; import Controller from '../controller'; import { IUnleashServices } from '../../types'; import { IUnleashConfig } from '../../types/option'; -import ClientInstanceService from '../../services/client-metrics/client-instance-service'; +import ClientInstanceService from '../../services/client-metrics/instance-service'; import { Logger } from '../../logger'; import { IAuthRequest } from '../unleash-types'; import ApiUser from '../../types/api-user'; import { ALL } from '../../types/models/api-token'; -import ClientMetricsServiceV2 from '../../services/client-metrics/client-metrics-service-v2'; +import ClientMetricsServiceV2 from '../../services/client-metrics/metrics-service-v2'; import { User } from '../../server-impl'; import { IClientApp } from '../../types/model'; import { NONE } from '../../types/permissions'; diff --git a/src/lib/routes/client-api/register.ts b/src/lib/routes/client-api/register.ts index 35a3b21b70..792e659a7f 100644 --- a/src/lib/routes/client-api/register.ts +++ b/src/lib/routes/client-api/register.ts @@ -3,7 +3,7 @@ import Controller from '../controller'; import { IUnleashServices } from '../../types'; import { IUnleashConfig } from '../../types/option'; import { Logger } from '../../logger'; -import ClientInstanceService from '../../services/client-metrics/client-instance-service'; +import ClientInstanceService from '../../services/client-metrics/instance-service'; import { IAuthRequest, User } from '../../server-impl'; import { IClientApp } from '../../types/model'; import ApiUser from '../../types/api-user'; diff --git a/src/lib/services/client-metrics/client-metrics-schema.ts b/src/lib/services/client-metrics/client-metrics-schema.ts deleted file mode 100644 index f0bd754923..0000000000 --- a/src/lib/services/client-metrics/client-metrics-schema.ts +++ /dev/null @@ -1,27 +0,0 @@ -import joi from 'joi'; - -const countSchema = joi - .object() - .options({ stripUnknown: true }) - .keys({ - yes: joi.number().min(0).empty('').default(0), - no: joi.number().min(0).empty('').default(0), - variants: joi.object().pattern(joi.string(), joi.number().min(0)), - }); - -export const clientMetricsSchema = joi - .object() - .options({ stripUnknown: true }) - .keys({ - environment: joi.string().optional(), - appName: joi.string().required(), - instanceId: joi.string().required(), - bucket: joi - .object() - .required() - .keys({ - start: joi.date().required(), - stop: joi.date().required(), - toggles: joi.object().pattern(/.*/, countSchema), - }), - }); diff --git a/src/lib/services/client-metrics/client-metrics.test.ts b/src/lib/services/client-metrics/instance-service.test.ts similarity index 99% rename from src/lib/services/client-metrics/client-metrics.test.ts rename to src/lib/services/client-metrics/instance-service.test.ts index e75c3d8ffb..8e09e30e01 100644 --- a/src/lib/services/client-metrics/client-metrics.test.ts +++ b/src/lib/services/client-metrics/instance-service.test.ts @@ -1,4 +1,4 @@ -import ClientInstanceService from './client-instance-service'; +import ClientInstanceService from './instance-service'; import getLogger from '../../../test/fixtures/no-logger'; import { IClientApp } from '../../types/model'; import { secondsToMilliseconds } from 'date-fns'; diff --git a/src/lib/services/client-metrics/client-instance-service.ts b/src/lib/services/client-metrics/instance-service.ts similarity index 97% rename from src/lib/services/client-metrics/client-instance-service.ts rename to src/lib/services/client-metrics/instance-service.ts index e7ac507728..7017ecd5c4 100644 --- a/src/lib/services/client-metrics/client-instance-service.ts +++ b/src/lib/services/client-metrics/instance-service.ts @@ -1,4 +1,4 @@ -import { applicationSchema } from './metrics-schema'; +import { applicationSchema } from './schema'; import { APPLICATION_CREATED } from '../../types/events'; import { IApplication } from './models'; import { IUnleashStores } from '../../types/stores'; @@ -13,11 +13,11 @@ import { IStrategyStore } from '../../types/stores/strategy-store'; import { IClientInstanceStore } from '../../types/stores/client-instance-store'; import { IApplicationQuery } from '../../types/query'; import { IClientApp } from '../../types/model'; -import { clientRegisterSchema } from './register-schema'; +import { clientRegisterSchema } from './schema'; import { minutesToMilliseconds, secondsToMilliseconds } from 'date-fns'; import { IClientMetricsStoreV2 } from '../../types/stores/client-metrics-store-v2'; -import { clientMetricsSchema } from './client-metrics-schema'; +import { clientMetricsSchema } from './schema'; export default class ClientInstanceService { apps = {}; diff --git a/src/lib/services/client-metrics/metrics-schema.ts b/src/lib/services/client-metrics/metrics-schema.ts deleted file mode 100644 index 56b2479dd9..0000000000 --- a/src/lib/services/client-metrics/metrics-schema.ts +++ /dev/null @@ -1,18 +0,0 @@ -import joi from 'joi'; - -export const applicationSchema = joi - .object() - .options({ stripUnknown: false }) - .keys({ - appName: joi.string().required(), - sdkVersion: joi.string().optional(), - strategies: joi - .array() - .optional() - .items(joi.string(), joi.any().strip()), - description: joi.string().allow('').optional(), - url: joi.string().allow('').optional(), - color: joi.string().allow('').optional(), - icon: joi.string().allow('').optional(), - announced: joi.boolean().optional().default(false), - }); diff --git a/src/lib/services/client-metrics/client-metrics-service-v2.ts b/src/lib/services/client-metrics/metrics-service-v2.ts similarity index 98% rename from src/lib/services/client-metrics/client-metrics-service-v2.ts rename to src/lib/services/client-metrics/metrics-service-v2.ts index 27b84f43db..f180e480a8 100644 --- a/src/lib/services/client-metrics/client-metrics-service-v2.ts +++ b/src/lib/services/client-metrics/metrics-service-v2.ts @@ -7,7 +7,7 @@ import { IClientMetricsEnv, IClientMetricsStoreV2, } from '../../types/stores/client-metrics-store-v2'; -import { clientMetricsSchema } from './client-metrics-schema'; +import { clientMetricsSchema } from './schema'; import { hoursToMilliseconds, minutesToMilliseconds } from 'date-fns'; import { IFeatureToggleStore } from '../../types/stores/feature-toggle-store'; import EventEmitter from 'events'; diff --git a/src/lib/services/client-metrics/register-schema.ts b/src/lib/services/client-metrics/register-schema.ts deleted file mode 100644 index 0ad69843b1..0000000000 --- a/src/lib/services/client-metrics/register-schema.ts +++ /dev/null @@ -1,17 +0,0 @@ -import joi from 'joi'; - -export const clientRegisterSchema = joi - .object() - .options({ stripUnknown: true }) - .keys({ - appName: joi.string().required(), - instanceId: joi.string().required(), - sdkVersion: joi.string().optional(), - strategies: joi - .array() - .required() - .items(joi.string(), joi.any().strip()), - started: joi.date().required(), - interval: joi.number().required(), - environment: joi.string().optional(), - }); diff --git a/src/lib/services/client-metrics/schema.ts b/src/lib/services/client-metrics/schema.ts new file mode 100644 index 0000000000..f694233c3e --- /dev/null +++ b/src/lib/services/client-metrics/schema.ts @@ -0,0 +1,60 @@ +import joi from 'joi'; + +const countSchema = joi + .object() + .options({ stripUnknown: true }) + .keys({ + yes: joi.number().min(0).empty('').default(0), + no: joi.number().min(0).empty('').default(0), + variants: joi.object().pattern(joi.string(), joi.number().min(0)), + }); + +export const clientMetricsSchema = joi + .object() + .options({ stripUnknown: true }) + .keys({ + environment: joi.string().optional(), + appName: joi.string().required(), + instanceId: joi.string().required(), + bucket: joi + .object() + .required() + .keys({ + start: joi.date().required(), + stop: joi.date().required(), + toggles: joi.object().pattern(/.*/, countSchema), + }), + }); + +export const applicationSchema = joi + .object() + .options({ stripUnknown: false }) + .keys({ + appName: joi.string().required(), + sdkVersion: joi.string().optional(), + strategies: joi + .array() + .optional() + .items(joi.string(), joi.any().strip()), + description: joi.string().allow('').optional(), + url: joi.string().allow('').optional(), + color: joi.string().allow('').optional(), + icon: joi.string().allow('').optional(), + announced: joi.boolean().optional().default(false), + }); + +export const clientRegisterSchema = joi + .object() + .options({ stripUnknown: true }) + .keys({ + appName: joi.string().required(), + instanceId: joi.string().required(), + sdkVersion: joi.string().optional(), + strategies: joi + .array() + .required() + .items(joi.string(), joi.any().strip()), + started: joi.date().required(), + interval: joi.number().required(), + environment: joi.string().optional(), + }); diff --git a/src/lib/services/index.ts b/src/lib/services/index.ts index 8f1380405c..d2a80e3f5c 100644 --- a/src/lib/services/index.ts +++ b/src/lib/services/index.ts @@ -7,8 +7,8 @@ import HealthService from './health-service'; import ProjectService from './project-service'; import StateService from './state-service'; -import ClientInstanceService from './client-metrics/client-instance-service'; -import ClientMetricsServiceV2 from './client-metrics/client-metrics-service-v2'; +import ClientInstanceService from './client-metrics/instance-service'; +import ClientMetricsServiceV2 from './client-metrics/metrics-service-v2'; import TagTypeService from './tag-type-service'; import TagService from './tag-service'; import StrategyService from './strategy-service'; diff --git a/src/lib/types/services.ts b/src/lib/types/services.ts index d8bca93fec..3144ef3822 100644 --- a/src/lib/types/services.ts +++ b/src/lib/types/services.ts @@ -5,7 +5,7 @@ import StateService from '../services/state-service'; import StrategyService from '../services/strategy-service'; import TagTypeService from '../services/tag-type-service'; import TagService from '../services/tag-service'; -import ClientInstanceService from '../services/client-metrics/client-instance-service'; +import ClientInstanceService from '../services/client-metrics/instance-service'; import ContextService from '../services/context-service'; import VersionService from '../services/version-service'; import { ApiTokenService } from '../services/api-token-service'; @@ -22,7 +22,7 @@ import FeatureToggleService from '../services/feature-toggle-service'; import EnvironmentService from '../services/environment-service'; import FeatureTagService from '../services/feature-tag-service'; import ProjectHealthService from '../services/project-health-service'; -import ClientMetricsServiceV2 from '../services/client-metrics/client-metrics-service-v2'; +import ClientMetricsServiceV2 from '../services/client-metrics/metrics-service-v2'; import UserSplashService from '../services/user-splash-service'; export interface IUnleashServices { diff --git a/src/test/e2e/services/client-metrics-service.e2e.test.ts b/src/test/e2e/services/client-metrics-service.e2e.test.ts index d441f6c0d6..fdb1962aef 100644 --- a/src/test/e2e/services/client-metrics-service.e2e.test.ts +++ b/src/test/e2e/services/client-metrics-service.e2e.test.ts @@ -1,4 +1,4 @@ -import ClientInstanceService from '../../../lib/services/client-metrics/client-instance-service'; +import ClientInstanceService from '../../../lib/services/client-metrics/instance-service'; import { IClientApp } from '../../../lib/types/model'; import { secondsToMilliseconds } from 'date-fns';