From 841e2a6e07290a6933089ce560845980834088a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Sun, 2 May 2021 21:11:17 +0200 Subject: [PATCH] fix: more types --- src/lib/db/access-store.ts | 2 +- src/lib/db/addon-store.js | 2 +- src/lib/db/api-token-store.ts | 2 +- src/lib/db/client-instance-store.js | 2 +- src/lib/db/client-metrics-store.js | 2 +- src/lib/db/feature-toggle-store.js | 2 +- src/lib/db/reset-token-store.ts | 2 +- src/lib/db/tag-store.ts | 2 +- src/lib/db/tag-type-store.ts | 2 +- src/lib/{event-hook.js => event-hook.ts} | 13 ++++++++----- src/lib/routes/admin-api/archive.ts | 2 +- src/lib/routes/admin-api/strategy.ts | 2 +- src/lib/types/option.ts | 6 ++++-- src/lib/{ => util}/metrics-helper.ts | 0 src/lib/{ => util}/timer.test.ts | 0 src/lib/{ => util}/timer.ts | 0 16 files changed, 23 insertions(+), 18 deletions(-) rename src/lib/{event-hook.js => event-hook.ts} (68%) rename src/lib/{ => util}/metrics-helper.ts (100%) rename src/lib/{ => util}/timer.test.ts (100%) rename src/lib/{ => util}/timer.ts (100%) diff --git a/src/lib/db/access-store.ts b/src/lib/db/access-store.ts index 63ff1afe00..cf4a0c8b14 100644 --- a/src/lib/db/access-store.ts +++ b/src/lib/db/access-store.ts @@ -1,6 +1,6 @@ import { EventEmitter } from 'events'; import { Knex } from 'knex'; -import metricsHelper from '../metrics-helper'; +import metricsHelper from '../util/metrics-helper'; import { DB_TIME } from '../metric-events'; const T = { diff --git a/src/lib/db/addon-store.js b/src/lib/db/addon-store.js index b890b45ca4..9a2e8dbc89 100644 --- a/src/lib/db/addon-store.js +++ b/src/lib/db/addon-store.js @@ -1,6 +1,6 @@ 'use strict'; -const metricsHelper = require('../metrics-helper'); +const metricsHelper = require('../util/metrics-helper'); const { DB_TIME } = require('../metric-events'); const NotFoundError = require('../error/notfound-error'); diff --git a/src/lib/db/api-token-store.ts b/src/lib/db/api-token-store.ts index 24aa6cbd90..86f81f55dd 100644 --- a/src/lib/db/api-token-store.ts +++ b/src/lib/db/api-token-store.ts @@ -1,6 +1,6 @@ import { EventEmitter } from 'events'; import { Knex } from 'knex'; -import metricsHelper from '../metrics-helper'; +import metricsHelper from '../util/metrics-helper'; import { DB_TIME } from '../metric-events'; import { Logger, LogProvider } from '../logger'; import NotFoundError from '../error/notfound-error'; diff --git a/src/lib/db/client-instance-store.js b/src/lib/db/client-instance-store.js index dfb7369d12..8c6263de18 100644 --- a/src/lib/db/client-instance-store.js +++ b/src/lib/db/client-instance-store.js @@ -2,7 +2,7 @@ 'use strict'; -const metricsHelper = require('../metrics-helper'); +const metricsHelper = require('../util/metrics-helper'); const { DB_TIME } = require('../metric-events'); const COLUMNS = [ diff --git a/src/lib/db/client-metrics-store.js b/src/lib/db/client-metrics-store.js index dc9599baa3..60aa6091c7 100644 --- a/src/lib/db/client-metrics-store.js +++ b/src/lib/db/client-metrics-store.js @@ -1,7 +1,7 @@ 'use strict'; const { EventEmitter } = require('events'); -const metricsHelper = require('../metrics-helper'); +const metricsHelper = require('../util/metrics-helper'); const { DB_TIME } = require('../metric-events'); const TEN_SECONDS = 10 * 1000; diff --git a/src/lib/db/feature-toggle-store.js b/src/lib/db/feature-toggle-store.js index a50f4392aa..d7c9e12583 100644 --- a/src/lib/db/feature-toggle-store.js +++ b/src/lib/db/feature-toggle-store.js @@ -1,6 +1,6 @@ 'use strict'; -const metricsHelper = require('../metrics-helper'); +const metricsHelper = require('../util/metrics-helper'); const { DB_TIME } = require('../metric-events'); const NotFoundError = require('../error/notfound-error'); const FeatureHasTagError = require('../error/feature-has-tag-error'); diff --git a/src/lib/db/reset-token-store.ts b/src/lib/db/reset-token-store.ts index fb9f1fcf9e..1230e70df7 100644 --- a/src/lib/db/reset-token-store.ts +++ b/src/lib/db/reset-token-store.ts @@ -1,6 +1,6 @@ import { EventEmitter } from 'events'; import { Knex } from 'knex'; -import metricsHelper from '../metrics-helper'; +import metricsHelper from '../util/metrics-helper'; import { DB_TIME } from '../metric-events'; import { Logger, LogProvider } from '../logger'; import NotFoundError from '../error/notfound-error'; diff --git a/src/lib/db/tag-store.ts b/src/lib/db/tag-store.ts index beeb2b65b9..c548eae2a8 100644 --- a/src/lib/db/tag-store.ts +++ b/src/lib/db/tag-store.ts @@ -3,7 +3,7 @@ import { Knex } from 'knex'; import { EventEmitter } from 'events'; import { DB_TIME } from '../metric-events'; -import metricsHelper from '../metrics-helper'; +import metricsHelper from '../util/metrics-helper'; import { LogProvider, Logger } from '../logger'; import NotFoundError from '../error/notfound-error'; diff --git a/src/lib/db/tag-type-store.ts b/src/lib/db/tag-type-store.ts index 5712378f73..9e7cf9fba1 100644 --- a/src/lib/db/tag-type-store.ts +++ b/src/lib/db/tag-type-store.ts @@ -2,7 +2,7 @@ import { Knex } from 'knex'; import { EventEmitter } from 'events'; import { LogProvider, Logger } from '../logger'; import { DB_TIME } from '../metric-events'; -import metricsHelper from '../metrics-helper'; +import metricsHelper from '../util/metrics-helper'; import NotFoundError from '../error/notfound-error'; const COLUMNS = ['name', 'description', 'icon']; diff --git a/src/lib/event-hook.js b/src/lib/event-hook.ts similarity index 68% rename from src/lib/event-hook.js rename to src/lib/event-hook.ts index 9c4b1a470e..13a466f856 100644 --- a/src/lib/event-hook.js +++ b/src/lib/event-hook.ts @@ -1,13 +1,16 @@ -'use strict'; - -const { +import EventEmitter from 'node:events'; +import { EventHook } from './types/option'; +import { FEATURE_CREATED, FEATURE_UPDATED, FEATURE_ARCHIVED, FEATURE_REVIVED, -} = require('./types/events'); +} from './types/events'; -exports.addEventHook = (eventHook, eventStore) => { +export const addEventHook = ( + eventHook: EventHook, + eventStore: EventEmitter, +): void => { eventStore.on(FEATURE_CREATED, data => { eventHook(FEATURE_CREATED, data); }); diff --git a/src/lib/routes/admin-api/archive.ts b/src/lib/routes/admin-api/archive.ts index b0cf8ce59b..d5eeb0cf93 100644 --- a/src/lib/routes/admin-api/archive.ts +++ b/src/lib/routes/admin-api/archive.ts @@ -7,7 +7,7 @@ import { IUnleashServices } from '../../types/services'; const Controller = require('../controller'); const extractUser = require('../../extract-user'); -const { UPDATE_FEATURE } = require('../../permissions'); +const { UPDATE_FEATURE } = require('../../types/permissions'); export default class ArchiveController extends Controller { constructor( diff --git a/src/lib/routes/admin-api/strategy.ts b/src/lib/routes/admin-api/strategy.ts index 3861ff6e66..b56b9cf0cc 100644 --- a/src/lib/routes/admin-api/strategy.ts +++ b/src/lib/routes/admin-api/strategy.ts @@ -13,7 +13,7 @@ const { DELETE_STRATEGY, CREATE_STRATEGY, UPDATE_STRATEGY, -} = require('../../permissions'); +} = require('../../types/permissions'); const version = 1; diff --git a/src/lib/types/option.ts b/src/lib/types/option.ts index bdfe72d43c..63ba7a7f97 100644 --- a/src/lib/types/option.ts +++ b/src/lib/types/option.ts @@ -1,5 +1,7 @@ import { LogLevel, LogProvider } from '../logger'; +export type EventHook = (eventName: string, data: object) => void; + export interface ISSLOption { rejectUnauthorized: boolean; ca?: string; @@ -88,7 +90,7 @@ export interface IUnleashOptions { enableOAS?: boolean; preHook?: Function; preRouterHook?: Function; - eventHook?: Function; + eventHook?: EventHook; enterpriseVersion?: string; } @@ -127,6 +129,6 @@ export interface IUnleashConfig { enableOAS: boolean; preHook?: Function; preRouterHook?: Function; - eventHook?: Function; + eventHook?: EventHook; enterpriseVersion?: string; } diff --git a/src/lib/metrics-helper.ts b/src/lib/util/metrics-helper.ts similarity index 100% rename from src/lib/metrics-helper.ts rename to src/lib/util/metrics-helper.ts diff --git a/src/lib/timer.test.ts b/src/lib/util/timer.test.ts similarity index 100% rename from src/lib/timer.test.ts rename to src/lib/util/timer.test.ts diff --git a/src/lib/timer.ts b/src/lib/util/timer.ts similarity index 100% rename from src/lib/timer.ts rename to src/lib/util/timer.ts