Skip to content

Commit

Permalink
Updated client code
Browse files Browse the repository at this point in the history
  • Loading branch information
mrinc committed Dec 15, 2023
1 parent 92dacfd commit e73b9b3
Showing 1 changed file with 48 additions and 27 deletions.
75 changes: 48 additions & 27 deletions nodejs/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,53 @@ import {
BSBServiceClient,
BSBServiceConstructor,
} from "./base";
import { LoggingConfig, EventsConfig, PluginDefition, PluginType, DEBUG_MODE } from './interfaces';
import {
LoggingConfig,
EventsConfig,
PluginDefition,
PluginType,
DEBUG_MODE,
} from "./interfaces";
import { SBLogging, ServiceBase } from "./serviceBase";
import {Plugin as DefaultConfig} from './plugins/config-default/plugin';
import { randomUUID } from "crypto";

export class SBClient<Client extends BSBServiceClient> {
private serviceBase: ServiceBase;
public client!: Client;

private useDefaultConfigPlugin: boolean;
private configSetup: boolean = false;
constructor(useDefaultConfigPlugin: boolean = false) {
this.useDefaultConfigPlugin = useDefaultConfigPlugin;

Check warning on line 24 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L24

Added line #L24 was not covered by tests
const CWD = process.env.APP_DIR || process.cwd();
this.serviceBase = new ServiceBase(false, true, CWD);

Check warning on line 26 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L26

Added line #L26 was not covered by tests
}

public async initAndRun(client: typeof BSBServiceClient, ...args: any[]) {
if (!this.useDefaultConfigPlugin)
this.serviceBase.setConfigPlugin("config-bsb-internal-client", FakeServiceConfig);

public async addClient(client: typeof BSBServiceClient, ...args: any[]) {

Check warning on line 29 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L29

Added line #L29 was not covered by tests
if (!this.useDefaultConfigPlugin && !this.configSetup) {
this.configSetup = true;
this.serviceBase.setConfigPlugin(

Check warning on line 32 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L31-L32

Added lines #L31 - L32 were not covered by tests
"config-bsb-internal-client",
FakeServiceConfig
);
}
const service = this.serviceBase.addService(

Check warning on line 37 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L37

Added line #L37 was not covered by tests
"service-bsb-internal-client",
"service-bsb-internal-client-" + randomUUID(),
FakeServiceClient,
{}
);
this.client = new (client as any)(service, ...args);
return new (client as any)(service, ...args);

Check warning on line 42 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L42

Added line #L42 was not covered by tests
}

public async init() {
await this.serviceBase.init();

Check warning on line 46 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L45-L46

Added lines #L45 - L46 were not covered by tests
}
public async run() {
await this.serviceBase.run();

Check warning on line 49 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L48-L49

Added lines #L48 - L49 were not covered by tests
}
}

class FakeServiceClient extends BSBService<any> {
export class FakeServiceClient extends BSBService<any> {
public initBeforePlugins?: string[] | undefined;
public initAfterPlugins?: string[] | undefined;
public runBeforePlugins?: string[] | undefined;
Expand All @@ -53,31 +68,37 @@ class FakeServiceClient extends BSBService<any> {
}
}

class FakeServiceConfig extends BSBConfig {
private config: DefaultConfig;
constructor(appId: string, mode: DEBUG_MODE, pluginName: string, cwd: string, pluginCwd: string, logging: SBLogging) {
super(appId, mode, pluginName, cwd, pluginCwd, logging)
this.config = new DefaultConfig(appId, mode, pluginName, cwd, pluginCwd, logging);
export class FakeServiceConfig extends BSBConfig {
constructor(
appId: string,
mode: DEBUG_MODE,
pluginName: string,
cwd: string,
pluginCwd: string,
logging: SBLogging

Check warning on line 78 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L78

Added line #L78 was not covered by tests
) {
super(appId, mode, pluginName, cwd, pluginCwd, logging);

Check warning on line 80 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L80

Added line #L80 was not covered by tests
}
async getLoggingPlugins(): Promise<Record<string, LoggingConfig>> {
return this.config.getLoggingPlugins();
return {};

Check warning on line 83 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L82-L83

Added lines #L82 - L83 were not covered by tests
}
async getEventsPlugins(): Promise<Record<string, EventsConfig>> {
return this.config.getEventsPlugins();
return {};

Check warning on line 86 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L85-L86

Added lines #L85 - L86 were not covered by tests
}
async getServicePlugins(): Promise<Record<string, PluginDefition>> {
return this.config.getServicePlugins();
return {};

Check warning on line 89 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L88-L89

Added lines #L88 - L89 were not covered by tests
}
async getServicePluginDefinition(pluginName: string): Promise<{ name: string; enabled: boolean; }> {
return this.config.getServicePluginDefinition(pluginName);
async getServicePluginDefinition(
pluginName: string

Check warning on line 92 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L92

Added line #L92 was not covered by tests
): Promise<{ name: string; enabled: boolean }> {
return { name: pluginName, enabled: false };

Check warning on line 94 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L94

Added line #L94 was not covered by tests
}
async getPluginConfig(pluginType: PluginType, plugin: string): Promise<object | null> {
return this.config.getPluginConfig(pluginType, plugin);
}
dispose() {
this.config.dispose();
}
init() {
this.config.init();
async getPluginConfig(
pluginType: PluginType,
plugin: string

Check warning on line 98 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L98

Added line #L98 was not covered by tests
): Promise<object | null> {
return null;

Check warning on line 100 in nodejs/src/client.ts

View check run for this annotation

Codecov / codecov/patch

nodejs/src/client.ts#L100

Added line #L100 was not covered by tests
}
dispose?(): void;
init?(): void;
}

0 comments on commit e73b9b3

Please sign in to comment.