Skip to content

Commit

Permalink
fix: launcher start config types
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewPattell committed Mar 8, 2023
1 parent 16d796e commit aeb22e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/helpers/get-ms-start-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import _ from 'lodash';
import type { ICommonConstants } from '@helpers/get-constants';
import GetDbConfig from '@helpers/get-db-config';
import { GetMsOptions, GetMsParams } from '@helpers/get-ms-config';
import type { IStartConfig, IStartConfigWithDb } from '@helpers/launchers';
import type { IStartConfig, IStartConfigWithDb, IStartConfigSocket } from '@helpers/launchers';

export type TOverloadMsStartConfigParams<T extends Record<string, any>> = T['DB'] extends Record<
string,
any
>
? PartialProps<IStartConfigWithDb, 'msOptions' | 'msParams' | 'dbOptions'>
: PartialProps<IStartConfig, 'msOptions' | 'msParams'>;
? PartialProps<IStartConfigSocket<IStartConfigWithDb>, 'msOptions' | 'msParams' | 'dbOptions'>
: PartialProps<IStartConfigSocket<IStartConfig>, 'msOptions' | 'msParams'>;

export type TOverloadMsStartConfigReturn<T extends Record<string, any>> = T['DB'] extends Record<
string,
any
>
? IStartConfigWithDb
: IStartConfig;
? IStartConfigSocket<IStartConfigWithDb>
: IStartConfigSocket<IStartConfig>;

/**
* Get default microservice start config
Expand Down
10 changes: 6 additions & 4 deletions src/helpers/launchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type {
IGatewayParams,
IMicroserviceOptions,
IMicroserviceParams,
ISocketOptions,
ISocketParams,
} from '@lomray/microservice-nodejs-lib';
import { Gateway, Microservice, Socket } from '@lomray/microservice-nodejs-lib';
import type { IMiddlewareRepository } from '@lomray/microservice-remote-middleware';
Expand All @@ -24,8 +26,8 @@ type TRemoteMiddleware = { isEnable?: boolean } & (

export interface IStartConfig {
type: 'gateway' | 'microservice' | 'socket';
msOptions: Partial<IGatewayOptions | IMicroserviceOptions>;
msParams: Partial<IGatewayParams> | IMicroserviceParams;
msOptions: Partial<IGatewayOptions | IMicroserviceOptions | ISocketOptions>;
msParams: Partial<IGatewayParams | IMicroserviceParams | ISocketParams>;
registerMethods?: (ms: Microservice | Gateway | Socket) => Promise<void> | void;
registerEvents?: (ms: Microservice | Gateway | Socket) => Promise<void> | void;
registerJobs?: (jobService: Jobs) => Promise<void> | void;
Expand All @@ -46,9 +48,9 @@ export interface IStartConfigWithDb extends IStartConfig {
shouldUseDbRemoteOptions?: boolean;
}

export type IStartConfigSocket = {
export type IStartConfigSocket<T = IStartConfig | IStartConfigWithDb> = {
registerRooms?: (ms: Socket) => Promise<void> | void;
} & (IStartConfig | IStartConfigWithDb);
} & T;

/**
* 1. Initialize
Expand Down

0 comments on commit aeb22e0

Please sign in to comment.