All files / blong-gogo/src/orchestrator/common dispatch.ts

43.75% Statements 14/32
100% Branches 2/2
50% Functions 1/2
43.75% Lines 14/32

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 331x 1x 1x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x                                     29x  
import {orchestrator, type IMeta} from '@feasibleone/blong/types';
 
export default orchestrator<{destination?: string; appendNamespace?: string}>(({remote}) => ({
    activation: {
        default: {
            type: 'dispatch',
        },
    },
    start() {
        super.connect();
        return super.start();
    },
    async exec(...params: unknown[]) {
        // Support both `destination` (slash-based routing, auto-stripped by methodPath)
        // and `appendNamespace` (dot-based prefix, stripped via stripNamespace on receiver).
        const destination = this.config.destination;
        const appendNamespace = this.config.appendNamespace;
        const prefix = destination ?? appendNamespace;
        const separator = destination ? '/' : '.';
        if (prefix && params.length > 1) {
            const $meta = params.pop() as IMeta;
            if ($meta?.method) {
                return (
                    (await remote.dispatch(...params, {
                        ...$meta,
                        method: prefix + separator + $meta.method,
                    })) as unknown[]
                )?.[0];
            }
        }
    },
}));