From 721baa765732ab7f2af0777b359013b10c89fcc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Fri, 13 Aug 2021 19:22:15 +0200 Subject: [PATCH] fix: Clean up exported types even more --- src/lib/server-impl.ts | 48 +++++++++++++++++++++++++++++------------- src/lib/types/user.ts | 1 - src/server-dev.ts | 4 ++-- src/server.ts | 2 +- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/lib/server-impl.ts b/src/lib/server-impl.ts index 51eac27d3f..fdd52a34cc 100644 --- a/src/lib/server-impl.ts +++ b/src/lib/server-impl.ts @@ -1,8 +1,6 @@ import EventEmitter from 'events'; import stoppable, { StoppableServer } from 'stoppable'; import { promisify } from 'util'; -import { IUnleash } from './types/core'; -import { IUnleashConfig, IUnleashOptions } from './types/option'; import version from './util/version'; import migrator from '../migrator'; import getApp from './app'; @@ -10,17 +8,21 @@ import { createMetricsMonitor } from './metrics'; import { createStores } from './db'; import { createServices } from './services'; import { createConfig } from './create-config'; -import User from './types/user'; -import { Logger } from './logger'; - -import * as permissions from './types/permissions'; -import AuthenticationRequired from './types/authentication-required'; -import Controller from './routes/controller'; -import * as eventType from './types/events'; import { addEventHook } from './event-hook'; import registerGracefulShutdown from './util/graceful-shutdown'; import { createDb } from './db/db-pool'; import sessionDb from './middleware/session-db'; +// Types +import { IUnleash } from './types/core'; +import { IUnleashConfig, IUnleashOptions } from './types/option'; +import { IUnleashServices } from './types/services'; +import User, { IUser } from './types/user'; +import { Logger, LogLevel } from './logger'; +import AuthenticationRequired from './types/authentication-required'; +import Controller from './routes/controller'; +import { IAuthRequest } from './routes/unleash-types'; +import * as permissions from './types/permissions'; +import * as eventType from './types/events'; async function createApp( config: IUnleashConfig, @@ -142,14 +144,30 @@ async function create(opts: IUnleashOptions): Promise { } return createApp(config, false); } -const serverImpl = { + +// Module exports +export { start, create, - User, - AuthenticationRequired, - Controller, permissions, eventType, + Controller, + AuthenticationRequired, + User, + LogLevel, +}; + +export default { + start, + create, +}; + +export type { + Logger, + IUnleash, + IUnleashOptions, + IUnleashConfig, + IUser, + IUnleashServices, + IAuthRequest, }; -export default serverImpl; -module.exports = serverImpl; diff --git a/src/lib/types/user.ts b/src/lib/types/user.ts index 3a29517caa..94ba32920f 100644 --- a/src/lib/types/user.ts +++ b/src/lib/types/user.ts @@ -75,7 +75,6 @@ export default class User implements IUser { this.seenAt = seenAt; this.loginAttempts = loginAttempts; this.createdAt = createdAt; - this.imageUrl = this.generateImageUrl(); } generateImageUrl(): string { diff --git a/src/server-dev.ts b/src/server-dev.ts index a7316693e8..40981a32f3 100644 --- a/src/server-dev.ts +++ b/src/server-dev.ts @@ -1,10 +1,10 @@ -import unleash from './lib/server-impl'; +import { start } from './lib/server-impl'; import { createConfig } from './lib/create-config'; import { LogLevel } from './lib/logger'; process.nextTick(async () => { try { - await unleash.start( + await start( createConfig({ db: { user: 'unleash_user', diff --git a/src/server.ts b/src/server.ts index 60f78a134a..141a0642d8 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,3 +1,3 @@ -import unleash from './lib/server-impl'; +import * as unleash from './lib/server-impl'; unleash.start();