mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
feat: allow every store to participate in transaction (#3016)
This commit is contained in:
parent
cb9414a3f2
commit
96b21f08b0
@ -1,5 +1,4 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import { Knex } from 'knex';
|
||||
import metricsHelper from '../util/metrics-helper';
|
||||
import { DB_TIME } from '../metric-events';
|
||||
import { Logger } from '../logger';
|
||||
@ -17,6 +16,7 @@ import {
|
||||
ENVIRONMENT_PERMISSION_TYPE,
|
||||
ROOT_PERMISSION_TYPE,
|
||||
} from '../util/constants';
|
||||
import { Db } from './db';
|
||||
|
||||
const T = {
|
||||
ROLE_USER: 'role_user',
|
||||
@ -47,9 +47,9 @@ export class AccessStore implements IAccessStore {
|
||||
|
||||
private timer: Function;
|
||||
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: Function) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: Function) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('access-store.ts');
|
||||
this.timer = (action: string) =>
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { Knex } from 'knex';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import User from '../types/user';
|
||||
|
||||
import NotFoundError from '../error/notfound-error';
|
||||
import { IUserLookup } from '../types/stores/user-store';
|
||||
import { IAccountStore } from '../types';
|
||||
import { Db } from './db';
|
||||
|
||||
const TABLE = 'users';
|
||||
|
||||
@ -47,11 +47,11 @@ const rowToUser = (row) => {
|
||||
};
|
||||
|
||||
export class AccountStore implements IAccountStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
constructor(db: Knex, getLogger: LogProvider) {
|
||||
constructor(db: Db, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('account-store.ts');
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { Knex } from 'knex';
|
||||
import EventEmitter from 'events';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import { IAddon, IAddonDto, IAddonStore } from '../types/stores/addon-store';
|
||||
@ -6,6 +5,7 @@ import { IAddon, IAddonDto, IAddonStore } from '../types/stores/addon-store';
|
||||
import metricsHelper from '../util/metrics-helper';
|
||||
import { DB_TIME } from '../metric-events';
|
||||
import NotFoundError from '../error/notfound-error';
|
||||
import { Db } from './db';
|
||||
|
||||
const COLUMNS = [
|
||||
'id',
|
||||
@ -20,13 +20,13 @@ const COLUMNS = [
|
||||
const TABLE = 'addons';
|
||||
|
||||
export default class AddonStore implements IAddonStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
private readonly timer: Function;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('addons-store.ts');
|
||||
this.timer = (action) =>
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import { Knex } from 'knex';
|
||||
import metricsHelper from '../util/metrics-helper';
|
||||
import { DB_TIME } from '../metric-events';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
@ -12,6 +11,7 @@ import {
|
||||
isAllProjects,
|
||||
} from '../types/models/api-token';
|
||||
import { ALL_PROJECTS } from '../util/constants';
|
||||
import { Db } from './db';
|
||||
|
||||
const TABLE = 'api_tokens';
|
||||
const API_LINK_TABLE = 'api_token_project';
|
||||
@ -80,9 +80,9 @@ export class ApiTokenStore implements IApiTokenStore {
|
||||
|
||||
private timer: Function;
|
||||
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('api-tokens.js');
|
||||
this.timer = (action: string) =>
|
||||
|
@ -1,5 +1,4 @@
|
||||
import EventEmitter from 'events';
|
||||
import { Knex } from 'knex';
|
||||
import NotFoundError from '../error/notfound-error';
|
||||
import {
|
||||
IClientApplication,
|
||||
@ -7,6 +6,7 @@ import {
|
||||
} from '../types/stores/client-applications-store';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import { IApplicationQuery } from '../types/query';
|
||||
import { Db } from './db';
|
||||
|
||||
const COLUMNS = [
|
||||
'app_name',
|
||||
@ -60,11 +60,11 @@ const remapRow = (input) => {
|
||||
export default class ClientApplicationsStore
|
||||
implements IClientApplicationsStore
|
||||
{
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('client-applications-store.ts');
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import EventEmitter from 'events';
|
||||
import { Knex } from 'knex';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import {
|
||||
IClientInstance,
|
||||
@ -8,6 +7,7 @@ import {
|
||||
} from '../types/stores/client-instance-store';
|
||||
import { hoursToMilliseconds, subDays } from 'date-fns';
|
||||
import Timeout = NodeJS.Timeout;
|
||||
import { Db } from './db';
|
||||
|
||||
const metricsHelper = require('../util/metrics-helper');
|
||||
const { DB_TIME } = require('../metric-events');
|
||||
@ -43,7 +43,7 @@ const mapToDb = (client) => ({
|
||||
});
|
||||
|
||||
export default class ClientInstanceStore implements IClientInstanceStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
@ -53,7 +53,7 @@ export default class ClientInstanceStore implements IClientInstanceStore {
|
||||
|
||||
private timer: Timeout;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.eventBus = eventBus;
|
||||
this.logger = getLogger('client-instance-store.ts');
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { Knex } from 'knex';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import {
|
||||
IClientMetricsEnv,
|
||||
@ -8,6 +7,7 @@ import {
|
||||
import NotFoundError from '../error/notfound-error';
|
||||
import { startOfHour } from 'date-fns';
|
||||
import { collapseHourlyMetrics } from '../util/collapseHourlyMetrics';
|
||||
import { Db } from './db';
|
||||
|
||||
interface ClientMetricsEnvTable {
|
||||
feature_name: string;
|
||||
@ -39,11 +39,11 @@ const toRow = (metric: IClientMetricsEnv): ClientMetricsEnvTable => ({
|
||||
});
|
||||
|
||||
export class ClientMetricsStoreV2 implements IClientMetricsStoreV2 {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
constructor(db: Knex, getLogger: LogProvider) {
|
||||
constructor(db: Db, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('client-metrics-store-v2.js');
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Knex } from 'knex';
|
||||
import { Db } from './db';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import {
|
||||
IContextField,
|
||||
@ -45,11 +45,11 @@ interface ICreateContextField {
|
||||
}
|
||||
|
||||
class ContextFieldStore implements IContextFieldStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
constructor(db: Knex, getLogger: LogProvider) {
|
||||
constructor(db: Db, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('context-field-store.ts');
|
||||
}
|
||||
|
3
src/lib/db/db.ts
Normal file
3
src/lib/db/db.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { Knex } from 'knex';
|
||||
|
||||
export type Db = Knex | Knex.Transaction;
|
@ -1,5 +1,5 @@
|
||||
import EventEmitter from 'events';
|
||||
import { Knex } from 'knex';
|
||||
import { Db } from './db';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import metricsHelper from '../util/metrics-helper';
|
||||
import { DB_TIME } from '../metric-events';
|
||||
@ -95,11 +95,11 @@ const TABLE = 'environments';
|
||||
export default class EnvironmentStore implements IEnvironmentStore {
|
||||
private logger: Logger;
|
||||
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private timer: (string) => any;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('db/environment-store.ts');
|
||||
this.timer = (action) =>
|
||||
|
@ -1,10 +1,11 @@
|
||||
import { Knex } from 'knex';
|
||||
import { IEvent, IBaseEvent } from '../types/events';
|
||||
import { LogProvider, Logger } from '../logger';
|
||||
import { IEventStore } from '../types/stores/event-store';
|
||||
import { ITag } from '../types/model';
|
||||
import { SearchEventsSchema } from '../openapi/spec/search-events-schema';
|
||||
import { AnyEventEmitter } from '../util/anyEventEmitter';
|
||||
import { Db } from './db';
|
||||
import { Knex } from 'knex';
|
||||
|
||||
const EVENT_COLUMNS = [
|
||||
'id',
|
||||
@ -76,11 +77,11 @@ export interface IEventTable {
|
||||
const TABLE = 'events';
|
||||
|
||||
class EventStore extends AnyEventEmitter implements IEventStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
constructor(db: Knex, getLogger: LogProvider) {
|
||||
constructor(db: Db, getLogger: LogProvider) {
|
||||
super();
|
||||
this.db = db;
|
||||
this.logger = getLogger('lib/db/event-store.ts');
|
||||
|
@ -1,9 +1,9 @@
|
||||
import EventEmitter from 'events';
|
||||
import { IFavoriteFeaturesStore } from '../types';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import { Knex } from 'knex';
|
||||
import { IFavoriteFeatureKey } from '../types/stores/favorite-features';
|
||||
import { IFavoriteFeature } from '../types/favorites';
|
||||
import { Db } from './db';
|
||||
|
||||
const T = {
|
||||
FAVORITE_FEATURES: 'favorite_features',
|
||||
@ -28,9 +28,9 @@ export class FavoriteFeaturesStore implements IFavoriteFeaturesStore {
|
||||
|
||||
private eventBus: EventEmitter;
|
||||
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.eventBus = eventBus;
|
||||
this.logger = getLogger('lib/db/favorites-store.ts');
|
||||
|
@ -1,11 +1,11 @@
|
||||
import EventEmitter from 'events';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import { Knex } from 'knex';
|
||||
import { IFavoriteProject } from '../types/favorites';
|
||||
import {
|
||||
IFavoriteProjectKey,
|
||||
IFavoriteProjectsStore,
|
||||
} from '../types/stores/favorite-projects';
|
||||
import { Db } from './db';
|
||||
|
||||
const T = {
|
||||
FAVORITE_PROJECTS: 'favorite_projects',
|
||||
@ -30,9 +30,9 @@ export class FavoriteProjectsStore implements IFavoriteProjectsStore {
|
||||
|
||||
private eventBus: EventEmitter;
|
||||
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.eventBus = eventBus;
|
||||
this.logger = getLogger('lib/db/favorites-store.ts');
|
||||
|
@ -1,5 +1,4 @@
|
||||
import EventEmitter from 'events';
|
||||
import { Knex } from 'knex';
|
||||
import {
|
||||
FeatureEnvironmentKey,
|
||||
IFeatureEnvironmentStore,
|
||||
@ -10,6 +9,7 @@ import { DB_TIME } from '../metric-events';
|
||||
import { IFeatureEnvironment, IVariant } from '../types/model';
|
||||
import NotFoundError from '../error/notfound-error';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { Db } from './db';
|
||||
|
||||
const T = {
|
||||
featureEnvs: 'feature_environments',
|
||||
@ -30,13 +30,13 @@ interface ISegmentRow {
|
||||
}
|
||||
|
||||
export class FeatureEnvironmentStore implements IFeatureEnvironmentStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
private readonly timer: Function;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('feature-environment-store.ts');
|
||||
this.timer = (action) =>
|
||||
|
@ -23,6 +23,7 @@ import { mapValues } from '../util/map-values';
|
||||
import { IFlagResolver } from '../types/experimental';
|
||||
import { IFeatureProjectUserParams } from '../routes/admin-api/project/features';
|
||||
import Raw = Knex.Raw;
|
||||
import { Db } from './db';
|
||||
|
||||
const COLUMNS = [
|
||||
'id',
|
||||
@ -117,7 +118,7 @@ function mapStrategyUpdate(
|
||||
}
|
||||
|
||||
class FeatureStrategiesStore implements IFeatureStrategiesStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
@ -126,7 +127,7 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore {
|
||||
private flagResolver: IFlagResolver;
|
||||
|
||||
constructor(
|
||||
db: Knex,
|
||||
db: Db,
|
||||
eventBus: EventEmitter,
|
||||
getLogger: LogProvider,
|
||||
flagResolver: IFlagResolver,
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { Knex } from 'knex';
|
||||
import { EventEmitter } from 'stream';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import { ITag } from '../types/model';
|
||||
@ -11,6 +10,7 @@ import {
|
||||
IFeatureTag,
|
||||
IFeatureTagStore,
|
||||
} from '../types/stores/feature-tag-store';
|
||||
import { Db } from './db';
|
||||
|
||||
const COLUMNS = ['feature_name', 'tag_type', 'tag_value'];
|
||||
const TABLE = 'feature_tag';
|
||||
@ -22,13 +22,13 @@ interface FeatureTagTable {
|
||||
}
|
||||
|
||||
class FeatureTagStore implements IFeatureTagStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
private readonly timer: Function;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('feature-tag-store.ts');
|
||||
this.timer = (action) =>
|
||||
|
@ -17,6 +17,7 @@ import { ensureStringValue } from '../util/ensureStringValue';
|
||||
import { mapValues } from '../util/map-values';
|
||||
import { IFlagResolver } from '../types/experimental';
|
||||
import Raw = Knex.Raw;
|
||||
import { Db } from './db';
|
||||
|
||||
export interface FeaturesTable {
|
||||
name: string;
|
||||
@ -46,7 +47,7 @@ export interface IGetAdminFeatures {
|
||||
export default class FeatureToggleClientStore
|
||||
implements IFeatureToggleClientStore
|
||||
{
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
@ -57,7 +58,7 @@ export default class FeatureToggleClientStore
|
||||
private flagResolver: IFlagResolver;
|
||||
|
||||
constructor(
|
||||
db: Knex,
|
||||
db: Db,
|
||||
eventBus: EventEmitter,
|
||||
getLogger: LogProvider,
|
||||
inlineSegmentConstraints: boolean,
|
||||
|
@ -6,6 +6,7 @@ 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';
|
||||
|
||||
const FEATURE_COLUMNS = [
|
||||
'name',
|
||||
@ -40,13 +41,13 @@ const TABLE = 'features';
|
||||
const FEATURE_ENVIRONMENTS_TABLE = 'feature_environments';
|
||||
|
||||
export default class FeatureToggleStore implements IFeatureToggleStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
private timer: Function;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('feature-toggle-store.ts');
|
||||
this.timer = (action) =>
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { Knex } from 'knex';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import {
|
||||
IFeatureType,
|
||||
IFeatureTypeStore,
|
||||
} from '../types/stores/feature-type-store';
|
||||
import { Db } from './db';
|
||||
|
||||
const COLUMNS = ['id', 'name', 'description', 'lifetime_days'];
|
||||
const TABLE = 'feature_types';
|
||||
@ -16,11 +16,11 @@ interface IFeatureTypeRow {
|
||||
}
|
||||
|
||||
class FeatureTypeStore implements IFeatureTypeStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
constructor(db: Knex, getLogger: LogProvider) {
|
||||
constructor(db: Db, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('feature-type-store.ts');
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import Group, {
|
||||
IGroupUserModel,
|
||||
} from '../types/group';
|
||||
import Transaction = Knex.Transaction;
|
||||
import { Db } from './db';
|
||||
|
||||
const T = {
|
||||
GROUPS: 'groups',
|
||||
@ -62,9 +63,9 @@ const groupToRow = (group: IStoreGroup) => ({
|
||||
});
|
||||
|
||||
export default class GroupStore implements IGroupStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
constructor(db: Knex) {
|
||||
constructor(db: Db) {
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { Knex } from 'knex';
|
||||
import { IUnleashConfig } from '../types/option';
|
||||
import { IUnleashStores } from '../types/stores';
|
||||
|
||||
@ -36,10 +35,11 @@ import { FavoriteFeaturesStore } from './favorite-features-store';
|
||||
import { FavoriteProjectsStore } from './favorite-projects-store';
|
||||
import { AccountStore } from './account-store';
|
||||
import ProjectStatsStore from './project-stats-store';
|
||||
import { Db } from './db';
|
||||
|
||||
export const createStores = (
|
||||
config: IUnleashConfig,
|
||||
db: Knex,
|
||||
db: Db,
|
||||
): IUnleashStores => {
|
||||
const { getLogger, eventBus } = config;
|
||||
const eventStore = new EventStore(db, getLogger);
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { Knex } from 'knex';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import { IPatStore } from '../types/stores/pat-store';
|
||||
import Pat, { IPat } from '../types/models/pat';
|
||||
import NotFoundError from '../error/notfound-error';
|
||||
import { Db } from './db';
|
||||
|
||||
const TABLE = 'personal_access_tokens';
|
||||
|
||||
@ -38,11 +38,11 @@ const toRow = (pat: IPat) => ({
|
||||
});
|
||||
|
||||
export default class PatStore implements IPatStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
constructor(db: Knex, getLogger: LogProvider) {
|
||||
constructor(db: Db, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('pat-store.ts');
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { Knex } from 'knex';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
|
||||
import metricsHelper from '../util/metrics-helper';
|
||||
@ -6,6 +5,7 @@ import { DB_TIME } from '../metric-events';
|
||||
import EventEmitter from 'events';
|
||||
import { IProjectStats } from 'lib/services/project-service';
|
||||
import { IProjectStatsStore } from 'lib/types/stores/project-stats-store-type';
|
||||
import { Db } from './db';
|
||||
|
||||
const TABLE = 'project_stats';
|
||||
|
||||
@ -35,13 +35,13 @@ interface IProjectStatsRow {
|
||||
}
|
||||
|
||||
class ProjectStatsStore implements IProjectStatsStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
private timer: Function;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('project-stats-store.ts');
|
||||
this.timer = (action) =>
|
||||
|
@ -15,6 +15,7 @@ import { DB_TIME } from '../metric-events';
|
||||
import EventEmitter from 'events';
|
||||
import { IFlagResolver } from '../types';
|
||||
import Raw = Knex.Raw;
|
||||
import { Db } from './db';
|
||||
|
||||
const COLUMNS = [
|
||||
'id',
|
||||
@ -37,7 +38,7 @@ export interface IProjectMembersCount {
|
||||
}
|
||||
|
||||
class ProjectStore implements IProjectStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
@ -46,7 +47,7 @@ class ProjectStore implements IProjectStore {
|
||||
private timer: Function;
|
||||
|
||||
constructor(
|
||||
db: Knex,
|
||||
db: Db,
|
||||
eventBus: EventEmitter,
|
||||
getLogger: LogProvider,
|
||||
flagResolver: IFlagResolver,
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import { Knex } from 'knex';
|
||||
import metricsHelper from '../util/metrics-helper';
|
||||
import { DB_TIME } from '../metric-events';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
@ -8,6 +7,7 @@ import { PublicSignupTokenSchema } from '../openapi/spec/public-signup-token-sch
|
||||
import { IPublicSignupTokenStore } from '../types/stores/public-signup-token-store';
|
||||
import { UserSchema } from '../openapi/spec/user-schema';
|
||||
import { IPublicSignupTokenCreate } from '../types/models/public-signup-token';
|
||||
import { Db } from './db';
|
||||
|
||||
const TABLE = 'public_signup_tokens';
|
||||
const TOKEN_USERS_TABLE = 'public_signup_tokens_user';
|
||||
@ -91,9 +91,9 @@ export class PublicSignupTokenStore implements IPublicSignupTokenStore {
|
||||
|
||||
private timer: Function;
|
||||
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('public-signup-tokens.js');
|
||||
this.timer = (action: string) =>
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import { Knex } from 'knex';
|
||||
import metricsHelper from '../util/metrics-helper';
|
||||
import { DB_TIME } from '../metric-events';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
@ -11,6 +10,7 @@ import {
|
||||
IResetTokenQuery,
|
||||
IResetTokenStore,
|
||||
} from '../types/stores/reset-token-store';
|
||||
import { Db } from './db';
|
||||
|
||||
const TABLE = 'reset_tokens';
|
||||
|
||||
@ -37,9 +37,9 @@ export class ResetTokenStore implements IResetTokenStore {
|
||||
|
||||
private timer: Function;
|
||||
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('db/reset-token-store.ts');
|
||||
this.timer = (action: string) =>
|
||||
|
@ -1,5 +1,4 @@
|
||||
import EventEmitter from 'events';
|
||||
import { Knex } from 'knex';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import NotFoundError from '../error/notfound-error';
|
||||
import { ICustomRole } from 'lib/types/model';
|
||||
@ -9,6 +8,7 @@ import {
|
||||
IRoleStore,
|
||||
} from 'lib/types/stores/role-store';
|
||||
import { IRole, IUserRole } from 'lib/types/stores/access-store';
|
||||
import { Db } from './db';
|
||||
|
||||
const T = {
|
||||
ROLE_USER: 'role_user',
|
||||
@ -30,9 +30,9 @@ export default class RoleStore implements IRoleStore {
|
||||
|
||||
private eventBus: EventEmitter;
|
||||
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.eventBus = eventBus;
|
||||
this.logger = getLogger('lib/db/role-store.ts');
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { ISegmentStore } from '../types/stores/segment-store';
|
||||
import { IConstraint, IFeatureStrategySegment, ISegment } from '../types/model';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import { Knex } from 'knex';
|
||||
import EventEmitter from 'events';
|
||||
import NotFoundError from '../error/notfound-error';
|
||||
import { PartialSome } from '../types/partial';
|
||||
import User from '../types/user';
|
||||
import { Db } from './db';
|
||||
|
||||
const T = {
|
||||
segments: 'segments',
|
||||
@ -42,9 +42,9 @@ export default class SegmentStore implements ISegmentStore {
|
||||
|
||||
private eventBus: EventEmitter;
|
||||
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.eventBus = eventBus;
|
||||
this.logger = getLogger('lib/db/segment-store.ts');
|
||||
|
@ -1,9 +1,9 @@
|
||||
import EventEmitter from 'events';
|
||||
import { Knex } from 'knex';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import NotFoundError from '../error/notfound-error';
|
||||
import { ISession, ISessionStore } from '../types/stores/session-store';
|
||||
import { addDays } from 'date-fns';
|
||||
import { Db } from './db';
|
||||
|
||||
const TABLE = 'unleash_session';
|
||||
|
||||
@ -19,9 +19,9 @@ export default class SessionStore implements ISessionStore {
|
||||
|
||||
private eventBus: EventEmitter;
|
||||
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.eventBus = eventBus;
|
||||
this.logger = getLogger('lib/db/session-store.ts');
|
||||
|
@ -1,15 +1,15 @@
|
||||
import { Knex } from 'knex';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import { ISettingStore } from '../types/stores/settings-store';
|
||||
import { Db } from './db';
|
||||
|
||||
const TABLE = 'settings';
|
||||
|
||||
export default class SettingStore implements ISettingStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
constructor(db: Knex, getLogger: LogProvider) {
|
||||
constructor(db: Db, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('settings-store.ts');
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { Knex } from 'knex';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
|
||||
import NotFoundError from '../error/notfound-error';
|
||||
@ -9,6 +8,7 @@ import {
|
||||
IStrategyImport,
|
||||
IStrategyStore,
|
||||
} from '../types/stores/strategy-store';
|
||||
import { Db } from './db';
|
||||
|
||||
const STRATEGY_COLUMNS = [
|
||||
'name',
|
||||
@ -29,11 +29,11 @@ interface IStrategyRow {
|
||||
display_name: string;
|
||||
}
|
||||
export default class StrategyStore implements IStrategyStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
constructor(db: Knex, getLogger: LogProvider) {
|
||||
constructor(db: Db, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('strategy-store.ts');
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { Knex } from 'knex';
|
||||
import { EventEmitter } from 'events';
|
||||
import { DB_TIME } from '../metric-events';
|
||||
import metricsHelper from '../util/metrics-helper';
|
||||
@ -6,6 +5,7 @@ import { LogProvider, Logger } from '../logger';
|
||||
import NotFoundError from '../error/notfound-error';
|
||||
import { ITag } from '../types/model';
|
||||
import { ITagStore } from '../types/stores/tag-store';
|
||||
import { Db } from './db';
|
||||
|
||||
const COLUMNS = ['type', 'value'];
|
||||
const TABLE = 'tags';
|
||||
@ -16,13 +16,13 @@ interface ITagTable {
|
||||
}
|
||||
|
||||
export default class TagStore implements ITagStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
private readonly timer: Function;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('tag-store.ts');
|
||||
this.timer = (action) =>
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { Knex } from 'knex';
|
||||
import { EventEmitter } from 'events';
|
||||
import { LogProvider, Logger } from '../logger';
|
||||
import { DB_TIME } from '../metric-events';
|
||||
import metricsHelper from '../util/metrics-helper';
|
||||
import NotFoundError from '../error/notfound-error';
|
||||
import { ITagType, ITagTypeStore } from '../types/stores/tag-type-store';
|
||||
import { Db } from './db';
|
||||
|
||||
const COLUMNS = ['name', 'description', 'icon'];
|
||||
const TABLE = 'tag_types';
|
||||
@ -16,13 +16,13 @@ interface ITagTypeTable {
|
||||
}
|
||||
|
||||
export default class TagTypeStore implements ITagTypeStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
private readonly timer: Function;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('tag-type-store.ts');
|
||||
this.timer = (action) =>
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { Knex } from 'knex';
|
||||
import { EventEmitter } from 'events';
|
||||
import { LogProvider, Logger } from '../logger';
|
||||
import {
|
||||
@ -6,6 +5,7 @@ import {
|
||||
IUserFeedbackKey,
|
||||
IUserFeedbackStore,
|
||||
} from '../types/stores/user-feedback-store';
|
||||
import { Db } from './db';
|
||||
|
||||
const COLUMNS = ['given', 'user_id', 'feedback_id', 'nevershow'];
|
||||
const TABLE = 'user_feedback';
|
||||
@ -32,11 +32,11 @@ const rowToField = (row: IUserFeedbackTable): IUserFeedback => ({
|
||||
});
|
||||
|
||||
export default class UserFeedbackStore implements IUserFeedbackStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('user-feedback-store.ts');
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { Knex } from 'knex';
|
||||
import { EventEmitter } from 'events';
|
||||
import { LogProvider, Logger } from '../logger';
|
||||
import {
|
||||
@ -6,6 +5,7 @@ import {
|
||||
IUserSplashKey,
|
||||
IUserSplashStore,
|
||||
} from '../types/stores/user-splash-store';
|
||||
import { Db } from './db';
|
||||
|
||||
const COLUMNS = ['user_id', 'splash_id', 'seen'];
|
||||
const TABLE = 'user_splash';
|
||||
@ -29,11 +29,11 @@ const rowToField = (row: IUserSplashTable): IUserSplash => ({
|
||||
});
|
||||
|
||||
export default class UserSplashStore implements IUserSplashStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('user-splash-store.ts');
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
/* eslint camelcase: "off" */
|
||||
|
||||
import { Knex } from 'knex';
|
||||
import { Logger, LogProvider } from '../logger';
|
||||
import User from '../types/user';
|
||||
|
||||
@ -11,6 +10,7 @@ import {
|
||||
IUserStore,
|
||||
IUserUpdateFields,
|
||||
} from '../types/stores/user-store';
|
||||
import { Db } from './db';
|
||||
|
||||
const TABLE = 'users';
|
||||
|
||||
@ -60,11 +60,11 @@ const rowToUser = (row) => {
|
||||
};
|
||||
|
||||
class UserStore implements IUserStore {
|
||||
private db: Knex;
|
||||
private db: Db;
|
||||
|
||||
private logger: Logger;
|
||||
|
||||
constructor(db: Knex, getLogger: LogProvider) {
|
||||
constructor(db: Db, getLogger: LogProvider) {
|
||||
this.db = db;
|
||||
this.logger = getLogger('user-store.ts');
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import { SimpleAuthSettings } from './types/settings/simple-auth-settings';
|
||||
import { Knex } from 'knex';
|
||||
import * as permissions from './types/permissions';
|
||||
import * as eventType from './types/events';
|
||||
import { Db } from './db/db';
|
||||
|
||||
async function createApp(
|
||||
config: IUnleashConfig,
|
||||
@ -183,6 +184,7 @@ export {
|
||||
RoleName,
|
||||
IAuthType,
|
||||
Knex,
|
||||
Db,
|
||||
permissions,
|
||||
eventType,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user