Skip to content

Commit

Permalink
♻️ refactor(bootstrap): remove bootsrap calls
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Mar 11, 2024
1 parent 29980c6 commit 8f22bda
Show file tree
Hide file tree
Showing 26 changed files with 19 additions and 159 deletions.
7 changes: 1 addition & 6 deletions src/backend/configuration/configuration.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { IApplicationService } from "backend/types";
import { progammingError } from "backend/lib/errors";
import { AppConfigurationValueType } from "shared/configurations/constants";
import {
Expand All @@ -12,15 +11,11 @@ import {
AppConfigurationKeys,
} from "../../shared/configurations";

export class ConfigurationApiService implements IApplicationService {
export class ConfigurationApiService {
constructor(
private _appConfigPersistenceService: AbstractConfigDataPersistenceService<unknown>
) {}

async bootstrap() {
await this._appConfigPersistenceService.setup();
}

async show<T extends AppConfigurationKeys>(
key: T,
entity?: string
Expand Down
7 changes: 1 addition & 6 deletions src/backend/dashboard-widgets/dashboard-widgets.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
createConfigDomainPersistenceService,
AbstractConfigDataPersistenceService,
} from "backend/lib/config-persistence";
import { IApplicationService } from "backend/types";
import {
HOME_DASHBOARD_KEY,
IWidgetConfig,
Expand Down Expand Up @@ -52,7 +51,7 @@ const runAsyncJavascriptString = async (
}
};

export class DashboardWidgetsApiService implements IApplicationService {
export class DashboardWidgetsApiService {
constructor(
private readonly _dashboardWidgetsPersistenceService: AbstractConfigDataPersistenceService<IWidgetConfig>,
private readonly _entitiesApiService: EntitiesApiService,
Expand All @@ -61,10 +60,6 @@ export class DashboardWidgetsApiService implements IApplicationService {
private readonly _rDBMSApiDataService: RDBMSDataApiService
) {}

async bootstrap() {
await this._dashboardWidgetsPersistenceService.setup();
}

async runScript(
script$1: string,
currentUser: IAccountProfile,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/data/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class DataApiService implements IDataApiService {
private _configurationApiService: ConfigurationApiService
) {}

async bootstrap() {
async runOnLoad() {
await this.getDataAccessInstance().bootstrap();
}

Expand Down
3 changes: 1 addition & 2 deletions src/backend/data/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { IApplicationService } from "backend/types";
import { PaginatedData, QueryFilterSchema } from "shared/types/data";
import { IAccountProfile } from "shared/types/user";

Expand All @@ -11,7 +10,7 @@ export interface IPaginationFilters {

export const FOR_CODE_COV = 1;

export interface IDataApiService extends IApplicationService {
export interface IDataApiService {
fetchData(
entity: string,
select: string[],
Expand Down
8 changes: 1 addition & 7 deletions src/backend/entities/entities.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,20 @@ import {
ConfigurationApiService,
} from "backend/configuration/configuration.service";
import { rolesApiService, RolesApiService } from "backend/roles/roles.service";
import { IApplicationService } from "backend/types";
import { noop } from "shared/lib/noop";
import { IDBSchema, IEntityField, IEntityRelation } from "shared/types/db";
import { DataCrudKeys } from "shared/types/data";
import { CRUD_HIDDEN_KEY_CONFIG } from "shared/configurations/permissions";
import { sortListByOrder } from "shared/lib/array/sort";
import { SchemasApiService, schemasApiService } from "../schema/schema.service";
import { PortalFieldsFilterService } from "./portal";

export class EntitiesApiService implements IApplicationService {
export class EntitiesApiService {
constructor(
private _schemasApiService: SchemasApiService,
private _configurationApiService: ConfigurationApiService,
private _rolesApiService: RolesApiService
) {}

async bootstrap() {
noop();
}

private async getDBSchemaModels(): Promise<Record<string, IDBSchema>> {
return Object.fromEntries(
(await this._schemasApiService.getDBSchema()).map((model) => [
Expand Down
7 changes: 1 addition & 6 deletions src/backend/form-actions/form-actions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ import {
createConfigDomainPersistenceService,
AbstractConfigDataPersistenceService,
} from "backend/lib/config-persistence";
import { IApplicationService } from "backend/types";
import { nanoid } from "nanoid";
import { IFormAction } from "shared/types/actions";

export class FormActionsApiService implements IApplicationService {
export class FormActionsApiService {
constructor(
private readonly _formActionsPersistenceService: AbstractConfigDataPersistenceService<IFormAction>
) {}

async bootstrap() {
await this._formActionsPersistenceService.setup();
}

async createFormAction(action: Omit<IFormAction, "id">) {
const id = nanoid();

Expand Down
14 changes: 1 addition & 13 deletions src/backend/integrations-configurations/services/_base.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
import { AbstractConfigDataPersistenceService } from "backend/lib/config-persistence";
import { EncryptionApiService } from "backend/lib/encryption/encryption.service";
import { BadRequestError, progammingError } from "backend/lib/errors";
import { IApplicationService } from "backend/types";
import { noop } from "shared/lib/noop";
import { IGroupCredential } from "../types";

export const INTEGRATION_CONFIG_GROUP_DEMILITER = "___";

export abstract class IntegrationsConfigurationApiService
implements IApplicationService
{
export abstract class IntegrationsConfigurationApiService {
constructor(
protected _persistenceService: AbstractConfigDataPersistenceService<string>,
protected _encryptionApiService: EncryptionApiService
) {}

static GROUP_DEMILITER = INTEGRATION_CONFIG_GROUP_DEMILITER;

async bootstrap() {
try {
await this._persistenceService.setup();
} catch (error) {
noop();
}
}

async hasKey(key: string): Promise<boolean> {
return (await this.getValue(key)) !== undefined;
}
Expand Down
8 changes: 1 addition & 7 deletions src/backend/integrations/integrations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ import {
createKeyValueDomainPersistenceService,
KeyValueStoreApiService,
} from "backend/lib/key-value";
import { IApplicationService } from "backend/types";
import { noop } from "shared/lib/noop";
import {
formActionsApiService,
FormActionsApiService,
} from "backend/form-actions/form-actions.service";
import { ACTION_INTEGRATIONS } from "./libs";

export class IntegrationsApiService implements IApplicationService {
export class IntegrationsApiService {
constructor(
private readonly _activatedIntegrationsPersistenceService: KeyValueStoreApiService<
ActionIntegrations[]
Expand All @@ -30,10 +28,6 @@ export class IntegrationsApiService implements IApplicationService {
private readonly _formActionsApiService: FormActionsApiService
) {}

async bootstrap() {
noop();
}

listActionIntegrations(): IIntegrationsList[] {
return Object.entries(ACTION_INTEGRATIONS).map(
([key, { title, description, configurationSchema }]) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export abstract class AbstractConfigDataPersistenceService<T> {

protected readonly _configApiService!: ConfigApiService;

public abstract setup(): Promise<void>;

constructor(configDomain: ConfigDomain, configApiService: ConfigApiService) {
this._configDomain = configDomain;
this._configApiService = configApiService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ export class DatabaseConfigDataPersistenceAdaptor<
return DatabaseConfigDataPersistenceAdaptor._dbInstance;
}

async setup() {
await this.getDbInstance();
}

async _resetToEmpty() {
await (await this.getDbInstance())(CONFIG_TABLE_NAME)
.where("domain", "=", this._configDomain)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fs from "fs-extra";
import { noop } from "shared/lib/noop";
import path from "path";
import { ConfigApiService } from "../config/config.service";

Expand All @@ -13,10 +12,6 @@ export class JsonFileConfigDataPersistenceAdaptor<
super(configDomain, configApiService);
}

async setup() {
noop();
}

private pathToConfigDomain = (type: ConfigDomain) => {
const file =
this._configApiService.getNodeEnvironment() === "test"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { noop } from "shared/lib/noop";
import { ConfigApiService } from "../config/config.service";
import { AbstractConfigDataPersistenceService } from "./AbstractConfigDataPersistenceService";
import { ConfigDomain } from "./types";
Expand All @@ -12,10 +11,6 @@ export class MemoryConfigDataPersistenceAdaptor<
super(configDomain, configApiService);
}

async setup() {
noop();
}

getItemLastUpdated() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ export class RedisConfigDataPersistenceAdaptor<
return null;
}

async setup() {
await this.getRedisInstance();
}

constructor(configDomain: ConfigDomain, _configApiService: ConfigApiService) {
super(configDomain, _configApiService);
}
Expand Down
6 changes: 1 addition & 5 deletions src/backend/lib/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ export class ConfigApiService {

constructor(protected processEnv: Record<string, unknown>) {
if (!this.processEnv.DO_NOT_BOOSTRAP_CONFIG) {
this.bootstrap();
this.assertConfiguration();
}
}

bootstrap() {
this.assertConfiguration();
}

getConfigValue<T>(key: ConfigKeys): T {
return this.processEnv[key] as unknown as T;
}
Expand Down
4 changes: 0 additions & 4 deletions src/backend/lib/temp-storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ export class TempStorageApiService {
private readonly _tempStoragePersistenceService: AbstractConfigDataPersistenceService<ITempStorage>
) {}

async bootstrap() {
await this._tempStoragePersistenceService.setup();
}

async clearItem(key: string) {
await this._tempStoragePersistenceService.removeItem(key);
}
Expand Down
7 changes: 1 addition & 6 deletions src/backend/list-order/list-order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ import {
createConfigDomainPersistenceService,
AbstractConfigDataPersistenceService,
} from "backend/lib/config-persistence";
import { IApplicationService } from "backend/types";

export class ListOrderApiService implements IApplicationService {
export class ListOrderApiService {
constructor(
private readonly _listOrderPersistenceService: AbstractConfigDataPersistenceService<
string[]
>
) {}

async bootstrap() {
await this._listOrderPersistenceService.setup();
}

async getItemOrder(listId: string): Promise<string[]> {
return await this._listOrderPersistenceService.getItem(listId, []);
}
Expand Down
10 changes: 1 addition & 9 deletions src/backend/menu/menu.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { IApplicationService } from "backend/types";
import { nanoid } from "nanoid";
import {
INavigationMenuItem,
Expand All @@ -12,7 +11,6 @@ import {
EntitiesApiService,
entitiesApiService,
} from "backend/entities/entities.service";
import { noop } from "shared/lib/noop";
import {
ConfigurationApiService,
configurationApiService,
Expand Down Expand Up @@ -46,19 +44,13 @@ const SYSTEM_LINKS_CONFIG_MAP: Record<
},
};

export class NavigationMenuApiService
implements IApplicationService, IBaseNavigationMenuApiService
{
export class NavigationMenuApiService implements IBaseNavigationMenuApiService {
constructor(
private readonly _entitiesApiService: EntitiesApiService,
private readonly _configurationApiService: ConfigurationApiService,
private readonly _rolesApiService: RolesApiService
) {}

async bootstrap() {
noop();
}

async getMenuItems(userRole: string) {
const portalMenuItems = await getPortalMenuItems(userRole, this);

Expand Down
7 changes: 1 addition & 6 deletions src/backend/roles/roles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
AbstractConfigDataPersistenceService,
} from "backend/lib/config-persistence";
import { BadRequestError } from "backend/lib/errors";
import { IApplicationService } from "backend/types";
import { canRoleDoThisAsync } from "shared/logic/permissions";
import {
isSystemRole,
Expand All @@ -18,15 +17,11 @@ export interface IRole {
permissions: string[];
}

export class RolesApiService implements IApplicationService {
export class RolesApiService {
constructor(
private readonly _rolesPersistenceService: AbstractConfigDataPersistenceService<IRole>
) {}

async bootstrap() {
await this._rolesPersistenceService.setup();
}

async listRoles(): Promise<string[]> {
const roles = await this._rolesPersistenceService.getAllItems();

Expand Down
6 changes: 2 additions & 4 deletions src/backend/schema/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
CredentialsApiService,
credentialsApiService,
} from "backend/integrations-configurations";
import { IApplicationService } from "backend/types";
import { IDBSchema, IEntityField } from "shared/types/db";
import { IDataSourceCredentials } from "shared/types/data-sources";
import { DATABASE_CREDENTIAL_GROUP } from "backend/data/fields";
Expand All @@ -13,16 +12,15 @@ import {
AbstractConfigDataPersistenceService,
} from "../lib/config-persistence";

export class SchemasApiService implements IApplicationService {
export class SchemasApiService {
private dbSchema: IDBSchema[];

constructor(
private _schemaConfigDataPersistenceService: AbstractConfigDataPersistenceService<IDBSchema>,
private _credentialsService: CredentialsApiService
) {}

async bootstrap() {
await this._schemaConfigDataPersistenceService.setup();
async runOnLoad() {
await this.loadDbSchema();
}

Expand Down
Loading

0 comments on commit 8f22bda

Please sign in to comment.