Skip to content

Commit

Permalink
feat: change the interface convention for the remote configuration ce…
Browse files Browse the repository at this point in the history
…nter
  • Loading branch information
ChoGathK committed Sep 19, 2022
1 parent 20428be commit 6a5cb8f
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 53 deletions.
7 changes: 2 additions & 5 deletions src/common/interface/async-provider.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { FactoryProvider } from '../declare';

/**
* Asynchronous provider factory for creating
*
* @see: [factory provider objects](https://docs.nestjs.com/fundamentals/custom-providers#factory-providers-usefactory)
*/
export interface AsyncProviderFactory {
/**
* Create a factory provider by specifying the creation parameters externally.
*
* @see: [factory provider objects](https://docs.nestjs.com/fundamentals/custom-providers#factory-providers-usefactory)
*
* @returns FactoryProvider
*
* @publicApi
Expand Down
57 changes: 55 additions & 2 deletions src/common/interface/client.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,72 @@
export interface Client<T = any> {
/**
* Gets the client instance object.
*
* @publicApi
*/
getInstance: () => T;
/**
* Close the client instance.
*
* @publicApi
*/
close: (...args: any[]) => void;
}

export interface AsyncClient<T = any> {
/**
* Gets the client instance object.
*
* @publicApi
*/
getInstance: () => T;
/**
* Close the client instance.
*
* @publicApi
*/
close: (...args: any[]) => Promise<void>;
}

export interface ClientAdapter<T = any, O = any> {
getClient: (key: string) => Client<T>;
/**
* Creating the client.
*
* @publicApi
*/
create: (options: O) => Client<T>;
/**
* Gets the client.
*
* @publicApi
*/
getClient: (key: string) => Client<T>;
/**
* Gets the client instance object.
*
* @publicApi
*/
getInstance: (key: string) => T;

}

export interface AsyncClientAdapter<T = any, O = any> {
getClient: (key: string) => AsyncClient<T>;
/**
* Creating the client.
*
* @publicApi
*/
create: (options: O) => Promise<AsyncClient<T>>;
/**
* Gets the client.
*
* @publicApi
*/
getClient: (key: string) => AsyncClient<T>;
/**
* Gets the client instance object.
*
* @publicApi
*/
getInstance: (key: string) => T;
}
80 changes: 36 additions & 44 deletions src/common/interface/module.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
import { ModuleMetadata } from '../declare';

/**
* Infrastructure module registration options.
*/
export interface InfrastructureRegisterOptions {

export interface ApiRegisterOptions {
/**
* Optional list of imported modules that export the providers which are required in this module.
*/
import?: ModuleMetadata['imports'];
/**
* Optional list of providers that will be instantiated by the Nest injector and that may be shared at least across this module.
*/
export?: ModuleMetadata['exports'];
/**
* Optional list of providers that will be instantiated by the Nest injector and that may be shared at least across this module.
* Optional list of controllers defined in this module which have to be instantiated.
*
* @required
*/
provider: ModuleMetadata['providers'];
controller: ModuleMetadata['controllers'];
/**
* Optional list of `consumer` that will be instantiated by the Nest injector and that may be shared at least across this module.
*/
consumer?: ModuleMetadata['providers'];
/**
* Optional list of `AOP` providers that will be instantiated by the Nest injector and that may be shared at least across this module.
*/
aop?: ModuleMetadata['providers'];
}

export interface ContainerRegisterOptions {
/**
* Api modules that need to be imported.
*/
api?: ModuleMetadata['imports'];
/**
* Infrastructure modules that need to be imported.
*/
infrastructure?: ModuleMetadata['imports'];
/**
* Optional list of `AOP` providers that will be instantiated by the Nest injector and that may be shared at least across this module.
*/
aop?: ModuleMetadata['providers'];
}
/**
* Domain module registration options.
*/

export interface DomainRegisterOptions {
/**
* Optional list of imported modules that export the providers which are required in this module.
Expand All @@ -48,43 +63,20 @@ export interface DomainRegisterOptions {
*/
provider?: ModuleMetadata['providers'];
}
/**
* Api module registration options.
*/
export interface ApiRegisterOptions {

export interface InfrastructureRegisterOptions {
/**
* Optional list of imported modules that export the providers which are required in this module.
*/
import?: ModuleMetadata['imports'];
/**
* Optional list of controllers defined in this module which have to be instantiated.
*
* @required
*/
controller: ModuleMetadata['controllers'];
/**
* Optional list of `consumer` that will be instantiated by the Nest injector and that may be shared at least across this module.
*/
consumer?: ModuleMetadata['providers'];
/**
* Optional list of `AOP` providers that will be instantiated by the Nest injector and that may be shared at least across this module.
*/
aop?: ModuleMetadata['providers'];
}
/**
* Application container module registration options.
*/
export interface ContainerRegisterOptions {
/**
* Api modules that need to be imported.
*/
api?: ModuleMetadata['imports'];
/**
* Infrastructure modules that need to be imported.
* Optional list of providers that will be instantiated by the Nest injector and that may be shared at least across this module.
*/
infrastructure?: ModuleMetadata['imports'];
export?: ModuleMetadata['exports'];
/**
* Optional list of `AOP` providers that will be instantiated by the Nest injector and that may be shared at least across this module.
* Optional list of providers that will be instantiated by the Nest injector and that may be shared at least across this module.
*
* @required
*/
aop?: ModuleMetadata['providers'];
provider: ModuleMetadata['providers'];
}
30 changes: 28 additions & 2 deletions src/common/interface/remote-config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
export interface RemoteConfigClient {
/**
* Close the remote configuration center.
*
* @publicApi
*/
close?: (...args: any[]) => Promise<any>;
/**
* Periodic synchronization of configuration information (polling).
*
* @publicApi
*/
sync?: () => Promise<any>;
/**
* Subscribe to configuration information (callbacks or hot updates).
*
* @publicApi
*/
subscribe?: () => Promise<any>;
/**
* Use customize arguments to initialize the remote configuration center.
*
* @publicApi
*/
init: (...args: any[]) => Promise<Partial<any>>;
sync: (...args: any[]) => Promise<Partial<any>>;
subscribe?: (key: string, callback: (value: any) => any, ...args: any[]) => Promise<void>;
}

export interface RemoteConfigInfo<T = any> {
/**
* Key in the remote configuration center.
*/
key: string;
/**
* Indicates the actual configuration value.
*/
value?: T;
}

0 comments on commit 6a5cb8f

Please sign in to comment.