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