Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optimize the naming and interface structure
- Loading branch information
Showing
12 changed files
with
258 additions
and
100 deletions.
There are no files selected for viewing
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,72 +1,68 @@ | ||
export interface Client<T = any> { | ||
import { IConfigSubscriber } from './config'; | ||
|
||
export interface IClientAdapter<T = any, C = any> { | ||
/** | ||
* Gets the client instance object. | ||
* Close the client. | ||
* | ||
* @publicApi | ||
*/ | ||
getInstance: () => T; | ||
close: () => void | Promise<void>; | ||
/** | ||
* Close the client instance. | ||
* Get the client instance. | ||
* | ||
* @publicApi | ||
*/ | ||
close: (...args: any[]) => void; | ||
} | ||
|
||
export interface AsyncClient<T = any> { | ||
connect: () => T; | ||
/** | ||
* Gets the client instance object. | ||
* Create the client instance. | ||
* | ||
* @param config C The configuration of client instance | ||
* | ||
* @publicApi | ||
*/ | ||
getInstance: () => T; | ||
create: (config: C) => void | Promise<void>; | ||
/** | ||
* Close the client instance. | ||
* Redeploy the client instance. | ||
* | ||
* @param config C The configuration of client instance | ||
* | ||
* @publicApi | ||
*/ | ||
close: (...args: any[]) => Promise<void>; | ||
redeploy: (config: C) => void | Promise<void>; | ||
} | ||
|
||
export interface ClientAdapter<T = any, O = any> { | ||
export interface IClientMediator<T = any, C = any> extends IConfigSubscriber { | ||
/** | ||
* Creating the client. | ||
* Destroy the client from mediator. | ||
* | ||
* @publicApi | ||
*/ | ||
create: (options: O) => Client<T>; | ||
/** | ||
* Gets the client. | ||
* @param key string The key of client. | ||
* | ||
* @publicApi | ||
*/ | ||
getClient: (key: string) => Client<T>; | ||
destroy: (key: string) => void | Promise<void>; | ||
/** | ||
* Gets the client instance object. | ||
* Deploy the client inside to mediator. | ||
* | ||
* @publicApi | ||
*/ | ||
getInstance: (key: string) => T; | ||
|
||
} | ||
|
||
export interface AsyncClientAdapter<T = any, O = any> { | ||
/** | ||
* Creating the client. | ||
* @param key string The key of client. | ||
* @param client IClientAdapter<T, C> The client. | ||
* | ||
* @publicApi | ||
*/ | ||
create: (options: O) => Promise<AsyncClient<T>>; | ||
deploy: (key: string, client: IClientAdapter<T, C>) => void | Promise<void>; | ||
/** | ||
* Gets the client. | ||
* Redeploy the client inside to mediator. | ||
* | ||
* @param key string The key of client. | ||
* | ||
* @publicApi | ||
*/ | ||
getClient: (key: string) => AsyncClient<T>; | ||
redeploy: (key: string, config: C) => void | Promise<void>; | ||
/** | ||
* Gets the client instance object. | ||
* Get the client from mediator. | ||
* | ||
* @param key string The key of client. | ||
* | ||
* @publicApi | ||
*/ | ||
getInstance: (key: string) => T; | ||
getClient: (key: string) => IClientAdapter<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,194 @@ | ||
interface Observer { | ||
contrast: (...args: any[]) => void; | ||
subscribe: (...args: any[]) => void | Promise<void>; | ||
notify: (...args: any[]) => void; | ||
polling: (...args: any[]) => void | Promise<void>; | ||
unPolling: (...args: any[]) => void | Promise<void>; | ||
unSubscribe: (...args: any[]) => void; | ||
} | ||
|
||
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] | ||
/** | ||
* Replace the configuration with property key. | ||
* | ||
* @param key string The property of configuration. | ||
* @param value any The configuration value. | ||
* | ||
* @publicApi | ||
*/ | ||
replace: (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 IConfigClientSubscriber { | ||
/** | ||
* Updating Configuration. | ||
* | ||
* @param value any The configuration value. | ||
* | ||
* @publicApi | ||
*/ | ||
update: (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 extends Observer { | ||
/** | ||
* 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 subscriber IConfigSubscriber The configuration subscriber.. | ||
* | ||
* @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; | ||
/** | ||
* Close the polling. | ||
* | ||
* @publicApi | ||
*/ | ||
unPolling: () => 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 Observer { | ||
/** | ||
* Load configuration. | ||
* | ||
* @param loader: IConfigLoader<T> | ||
* | ||
* @publicApi | ||
*/ | ||
init: <T = any>(loader: IConfigLoader) => T | Promise<T>; | ||
/** | ||
* Contrasting configuration. | ||
* | ||
* @param value any The configuration value. | ||
* | ||
* @publicApi | ||
*/ | ||
contrast: (value: any) => void; | ||
/** | ||
* Register the subscriber inside client by the key of configuration. | ||
* | ||
* @param subscriber IConfigClientSubscriber The configuration client subscriber. | ||
* | ||
* @publicApi | ||
*/ | ||
subscribe: (subscriber: IConfigClientSubscriber) => void; | ||
/** | ||
* Notify subscribers of configuration updates. | ||
* | ||
* @param value any The configuration value. | ||
* | ||
* @publicApi | ||
*/ | ||
notify: (value: any) => void; | ||
/** | ||
* Open the polling. | ||
* | ||
* @publicApi | ||
*/ | ||
polling: () => void; | ||
/** | ||
* Close the polling. | ||
* | ||
* @publicApi | ||
*/ | ||
unPolling: () => void; | ||
/** | ||
* Remove the subscriber from client by the key of configuration.. | ||
* | ||
* @publicApi | ||
*/ | ||
unSubscribe: () => 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 './async-provider'; | ||
export * from './client'; | ||
export * from './remote-config'; | ||
export * from './config'; | ||
export * from './provider'; |
2 changes: 1 addition & 1 deletion
2
src/common/interface/async-provider.ts → src/common/interface/provider.ts
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 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
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 { AsyncProvider } from './struct'; | ||
export { AsyncProviderFactory } from './struct'; | ||
export * from './decorator'; | ||
export * from './common'; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.