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

100% Statements 32/32
100% Branches 9/9
100% Functions 3/3
100% Lines 32/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 49x 49x 49x 49x 49x 49x 49x 6x 6x 49x 28x 28x 28x 28x 28x 28x 28x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 28x 49x  
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];
            }
        }
    },
}));