All files / core/blong-kukum/orchestrator/kukum find.ts

71.42% Statements 25/35
66.66% Branches 2/3
100% Functions 1/1
71.42% Lines 25/35

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 361x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x                     1x  
import {library} from '@feasibleone/blong';
import {find as findInstances} from '../../engine.ts';
import {
    baseResult,
    contextOf,
    descriptorFor,
    type KukumLibContext,
    type OperationParams,
    type OperationResult,
} from '../../operation.ts';
 
/** `kukum.<primitive>.find` — the existing artifacts of a primitive, read from disk. */
export default library(
    () =>
        async function find(
            this: KukumLibContext,
            id: string,
            params: OperationParams,
        ): Promise<OperationResult> {
            const host = this.platform;
            const root = host.resolve(params.target ?? '.');
            const descriptor = descriptorFor(id);
            const base = baseResult(id, 'find', contextOf(id, params));
            const instances = await findInstances(host, descriptor, root);
            return {
                ...base,
                files: instances.map(path => ({
                    path,
                    content: '',
                    action: 'existing',
                    handWritten: false,
                })),
            };
        },
);