Skip to content

Commit

Permalink
fix: interface define
Browse files Browse the repository at this point in the history
  • Loading branch information
ChoGathK committed Oct 14, 2022
1 parent 928070c commit 0d45db3
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 20 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"dependencies": {
"@nestjs/common": "^8.4.7",
"@vodyani/class-decorator": "^8.2.3",
"@vodyani/core": "^8.9.2",
"@vodyani/core": "^8.9.4",
"@vodyani/utils": "^8.7.1",
"js-yaml": "^4.1.0",
"lodash": "4.17.21"
Expand Down
4 changes: 2 additions & 2 deletions src/provider/dynamic-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class AsyncDynamicDataSourceProvider<T = any, C = any> implements IClient
public async redeploy(key: string, config: C) {
const client = this.getClient(key);

await client.redeploy(config);
await client.create(config);

this.clients.set(key, client);
this.keys.add(key);
Expand Down Expand Up @@ -90,7 +90,7 @@ export class DynamicDataSourceProvider<T = any, C = any> implements IClientMedia
public redeploy(key: string, config: C) {
const client = this.getClient(key);

client.redeploy(config);
client.create(config);

this.clients.set(key, client);
this.keys.add(key);
Expand Down
6 changes: 2 additions & 4 deletions src/struct/config-client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IConfigClient, IConfigClientSubscriber, IConfigLoader } from '@vodyani/core';
import { IConfigClientSubscriber, IConfigLoader } from '@vodyani/core';
import { isValidString, toHash } from '@vodyani/utils';

export abstract class AbstractConfigClient implements IConfigClient {
export class LocalConfigClient {
private subscriber: IConfigClientSubscriber;

private hash: string;
Expand Down Expand Up @@ -44,5 +44,3 @@ export abstract class AbstractConfigClient implements IConfigClient {
this.subscriber = null;
}
}

export class LocalConfigClient extends AbstractConfigClient {}
16 changes: 14 additions & 2 deletions src/struct/config-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ export class JSONConfigLoader implements IConfigLoader {
constructor(
private readonly path: string,
private readonly defaultEnv: string,
private readonly currentEnv: string,
private readonly currentEnv?: string,
) {}

public execute() {
const defaultResult = this.readJSONFile(this.defaultEnv);

if (!this.currentEnv) {
return defaultResult;
}

const currentResult = this.readJSONFile(this.currentEnv);

return toDeepMerge(defaultResult, currentResult);
}

Expand All @@ -29,12 +35,18 @@ export class YamlConfigLoader implements IConfigLoader {
constructor(
private readonly path: string,
private readonly defaultEnv: string,
private readonly currentEnv: string,
private readonly currentEnv?: string,
) {}

public execute() {
const defaultResult = this.readYamlFile(this.defaultEnv);

if (!this.currentEnv) {
return defaultResult;
}

const currentResult = this.readYamlFile(this.currentEnv);

return toDeepMerge(defaultResult, currentResult);
}

Expand Down
4 changes: 2 additions & 2 deletions test/struct/config-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolve } from 'path';

import { describe, it, expect } from '@jest/globals';

import { JSONConfigLoader, ConfigClientSubscriber, AbstractConfigClient, ConfigProvider } from '../../src';
import { JSONConfigLoader, ConfigClientSubscriber, LocalConfigClient, ConfigProvider } from '../../src';

interface File {
json: {
Expand All @@ -19,7 +19,7 @@ describe('LocalConfigClient', () => {
const loader = new JSONConfigLoader(jsonFilePath, 'DEFAULT', 'LOCAL');

it('LocalConfigClient', async () => {
class DemoConfigClient extends AbstractConfigClient {
class DemoConfigClient extends LocalConfigClient {
public polling(): void {
this.contrast({ poller: 'DemoConfigClient' });
super.polling();
Expand Down
4 changes: 2 additions & 2 deletions test/struct/config-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolve } from 'path';

import { describe, expect, it } from '@jest/globals';

import { ConfigClientSubscriber, ConfigHandlerOptions, ConfigProvider, JSONConfigLoader, AbstractConfigClient } from '../../src';
import { ConfigClientSubscriber, ConfigHandlerOptions, ConfigProvider, JSONConfigLoader, LocalConfigClient } from '../../src';
import { ConfigArgumentHandler, ConfigClientHandler } from '../../src/struct/config-handler';

interface File {
Expand All @@ -15,7 +15,7 @@ interface File {
poller?: string;
}

class DemoConfigClient extends AbstractConfigClient {
class DemoConfigClient extends LocalConfigClient {
public polling(): void {
this.contrast({ poller: 'DemoConfigClient' });
super.polling();
Expand Down
12 changes: 12 additions & 0 deletions test/struct/config-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ describe('ConfigLoader', () => {
expect(config.json.list).toEqual([1, 2]);
expect(config.json.name).toBe('json');
expect(config.json.age).toBe(3);

const loader2 = new JSONConfigLoader(jsonFilePath, 'DEFAULT');
const config2 = loader2.execute();

expect(config2.json.list).toEqual([1]);
expect(config2.json.name).toBe('json');
});

it('YamlConfigLoader', async () => {
Expand All @@ -27,5 +33,11 @@ describe('ConfigLoader', () => {
expect(config.yaml.list).toEqual([1, 2]);
expect(config.yaml.name).toBe('yaml');
expect(config.yaml.age).toBe(3);

const loader2 = new YamlConfigLoader(yamlFilePath, 'DEFAULT');
const config2 = loader2.execute();

expect(config2.yaml.list).toEqual([1]);
expect(config2.yaml.name).toBe('yaml');
});
});

0 comments on commit 0d45db3

Please sign in to comment.