All files / blong-gogo/src ResolutionLocal.ts

88.88% Statements 48/54
75% Branches 9/12
75% Functions 9/12
88.88% Lines 48/54

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 551x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 2x 2x 2x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import {Internal, type IManifest} from '@feasibleone/blong/types';
 
import type {IResolution} from './Resolution.ts';
 
interface IConfig {
    portRpc: number;
    portGateway: number;
    domain: string;
}
export default class ResolutionLocal extends Internal implements IResolution {
    #config: IConfig = {
        portRpc: 8091,
        portGateway: 8080,
        domain: 'localhost',
    };
    #manifest: IManifest | undefined;
 
    public constructor(config: IConfig, {manifest}: {manifest?: IManifest} = {}) {
        super();
        this.merge(this.#config, config);
        this.#manifest = manifest;
    }

    public async resolve(
        service: string,
        // invalidate: boolean,
        // namespace: string,
    ): ReturnType<IResolution['resolve']> {
        const isRpc = service.startsWith('rpc-');
        // Prefer manifest-published ports over config defaults, so that
        // services listening on random ports (port:0 in dev intent) are
        // discoverable by GatewayCodec / _discoverService.
        // The manifest property may be a plain value or a Deferred/thenable
        // — `await` handles both.
        const manifestPort = this.#manifest
            ? await this.#manifest[isRpc ? 'rpcPort' : 'gatewayPort']
            : undefined;
        return {
            hostname: 'localhost',
            port:
                manifestPort != null
                    ? `${manifestPort}`
                    : isRpc
                      ? `${this.#config.portRpc}`
                      : `${this.#config.portGateway}`,
        };
    }
 
    public announce(): void {}
 
    public async start(): Promise<void> {}
 
    public async stop(): Promise<void> {}
}