-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: take previously irrational design apart & refactor it according…
… to design pattern principles
- Loading branch information
Showing
36 changed files
with
711 additions
and
1,403 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import * as toHash from 'object-hash'; | ||
import * as Yaml from 'js-yaml'; | ||
|
||
export { toHash }; | ||
export { toHash, Yaml }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export * from './interface'; | ||
export * from './declare'; | ||
export * from './type'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { IConfigSubscriber } from './config'; | ||
|
||
export interface IClient<T = any, C = any> { | ||
/** | ||
* Close the client. | ||
* | ||
* @publicApi | ||
*/ | ||
close: () => void | Promise<void>; | ||
/** | ||
* Get the client instance. | ||
* | ||
* @publicApi | ||
*/ | ||
connect: () => T; | ||
/** | ||
* Create the client instance. | ||
* | ||
* @param config C The configuration of client instance | ||
* | ||
* @publicApi | ||
*/ | ||
create: (config: C) => T | Promise<T>; | ||
/** | ||
* Redeploy the client instance. | ||
* | ||
* @param config C The configuration of client instance | ||
* | ||
* @publicApi | ||
*/ | ||
redeploy: (config: C) => T | Promise<T>; | ||
} | ||
|
||
export interface IClientMediator<T = any, C = any> extends IConfigSubscriber { | ||
/** | ||
* Destroy the client from mediator. | ||
* | ||
* @param key string The key of client. | ||
* | ||
* @publicApi | ||
*/ | ||
destroy: (key: string) => void | Promise<void>; | ||
/** | ||
* Deploy the client inside to mediator. | ||
* | ||
* @param key string The key of client. | ||
* @param client IClient<T, C> The client. | ||
* | ||
* @publicApi | ||
*/ | ||
deploy: (key: string, client: IClient<T, C>) => void | Promise<void>; | ||
/** | ||
* Redeploy the client inside to mediator. | ||
* | ||
* @param key string The key of client. | ||
* | ||
* @publicApi | ||
*/ | ||
redeploy: (key: string, config: C) => void | Promise<void>; | ||
/** | ||
* Get the client from mediator. | ||
* | ||
* @param key string The key of client. | ||
* | ||
* @publicApi | ||
*/ | ||
getClient: (key: string) => IClient<T, C>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import { ConfigHandlerOptions } from './options'; | ||
|
||
export interface IConfig<T = any> { | ||
/** | ||
* Deep search the configuration with property key. | ||
* | ||
* @param key string The property of configuration. | ||
* | ||
* @publicApi | ||
*/ | ||
get: <V = any>(key: string) => V; | ||
/** | ||
* Search the configuration with property key. | ||
* | ||
* @param key string The property of configuration. | ||
* | ||
* @publicApi | ||
*/ | ||
search: <K extends keyof T>(key: K) => T[K] | ||
/** | ||
* Set the configuration with property key. | ||
* | ||
* @param key string The property of configuration. | ||
* @param value any The configuration value. | ||
* | ||
* @publicApi | ||
*/ | ||
set: (key: string, value: any) => void; | ||
/** | ||
* Merge the configuration. | ||
* | ||
* @param config any The configuration. | ||
* | ||
* @publicApi | ||
*/ | ||
merge: (config: T) => void; | ||
} | ||
|
||
export interface IConfigSubscriber { | ||
/** | ||
* Updating Configuration. | ||
* | ||
* @param key string The property of configuration. | ||
* @param value any The configuration value. | ||
* | ||
* @publicApi | ||
*/ | ||
update: (key: string, value: any) => void | Promise<void> | ||
} | ||
|
||
export interface IConfigLoader { | ||
/** | ||
* Load configuration. | ||
* | ||
* @publicApi | ||
*/ | ||
execute: <T = any>() => T; | ||
} | ||
|
||
export interface IConfigPoller { | ||
/** | ||
* Open the polling. | ||
* | ||
* @publicApi | ||
*/ | ||
execute: () => void; | ||
/** | ||
* Close the polling. | ||
* | ||
* @publicApi | ||
*/ | ||
close: () => void | Promise<void>; | ||
} | ||
|
||
export interface IConfigObserver { | ||
/** | ||
* Contrasting configuration. | ||
* | ||
* @param key string The property of configuration. | ||
* @param value any The configuration value. | ||
* | ||
* @publicApi | ||
*/ | ||
contrast?: (key: string, value: any) => void; | ||
/** | ||
* Register the subscriber inside client by the key of configuration. | ||
* | ||
* @param key string The key of configuration. | ||
* @param value any The configuration value. | ||
* | ||
* @publicApi | ||
*/ | ||
subscribe?: (key: string, subscriber: IConfigSubscriber) => void; | ||
/** | ||
* Notify subscribers of configuration updates. | ||
* | ||
* @param key string The key of configuration. | ||
* @param value any The configuration value. | ||
* | ||
* @publicApi | ||
*/ | ||
notify?: (key: string, value: any) => void; | ||
/** | ||
* Open the polling. | ||
* | ||
* @publicApi | ||
*/ | ||
polling?: () => void | Promise<void>; | ||
/** | ||
* Close the polling. | ||
* | ||
* @publicApi | ||
*/ | ||
unPolling?: () => void | Promise<void>; | ||
/** | ||
* Remove the subscriber from client by the key of configuration.. | ||
* | ||
* @param key string The key of configuration. | ||
* | ||
* @publicApi | ||
*/ | ||
unSubscribe?: (key: string) => void; | ||
} | ||
|
||
export interface IConfigClient extends IConfigObserver { | ||
/** | ||
* Load configuration. | ||
* | ||
* @param loader: IConfigLoader<T> | ||
* | ||
* @publicApi | ||
*/ | ||
load: <T = any>(loader: IConfigLoader) => T | Promise<T>; | ||
/** | ||
* Register the subscriber inside client. | ||
* | ||
* @param key string The key of configuration. | ||
* @param value any The configuration value. | ||
* | ||
* @publicApi | ||
*/ | ||
subscribeAll?: (subscriber: IConfigSubscriber) => void; | ||
/** | ||
* Remove the subscriber from client. | ||
* | ||
* @publicApi | ||
*/ | ||
unSubscribeAll?: () => void; | ||
} | ||
|
||
export interface IConfigHandler<T = any> { | ||
/** | ||
* Set next handler. | ||
* | ||
* @param handler IConfigHandler | ||
* | ||
* @publicApi | ||
*/ | ||
setNext: (handler: IConfigHandler) => IConfigHandler; | ||
/** | ||
* Handler execute. | ||
* | ||
* @param options: ArkOptions | ||
* | ||
* @publicApi | ||
*/ | ||
execute: (options: ConfigHandlerOptions<T>) => Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './manager'; | ||
export * from './monitor'; | ||
export * from './proxy'; | ||
export * from './client'; | ||
export * from './config'; | ||
export * from './options'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ModuleMetadata } from '@nestjs/common'; | ||
|
||
import { IConfigClient, IConfigLoader } from './config'; | ||
|
||
export interface ConfigClientOptions { | ||
client: IConfigClient; | ||
loader: IConfigLoader; | ||
enablePolling?: boolean; | ||
enableSubscribeAll?: boolean; | ||
} | ||
|
||
export interface ConfigHandlerOptions<T = any> { | ||
args: T; | ||
clients: ConfigClientOptions[]; | ||
enableDynamicDataSource: boolean; | ||
enableDynamicDataSourcePolling: boolean; | ||
} | ||
|
||
export interface ArkOptions<T = any> extends ConfigHandlerOptions<T> { | ||
imports: ModuleMetadata['imports']; | ||
global: boolean; | ||
} |
Oops, something went wrong.