All files / core/blong-kukum/primitives component.ts

100% Statements 63/63
100% Branches 5/5
100% Functions 2/2
100% Lines 63/63

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 55 56 57 58 59 60 61 62 63 641x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 6x 6x 6x 2x 2x 2x 2x 2x 2x 2x 2x 2x 6x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 6x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 6x 6x 1x 1x 1x  
import {capitalize, checkObject, checkSubject, type PrimitiveDescriptor} from '../engine.ts';
 
/** `component` — browser page handlers, action files and portal contributions. */
 
const component: PrimitiveDescriptor = {
    id: 'component',
    title: 'Browser component',
    skill: 'blong-browser',
    summary: 'A browser page handler, its actions file and its portal menu contribution.',
    kinds: ['component', 'actions', 'portal'],
    defaultKind: 'component',
    roots: ['component'],
    check(ctx) {
        return [...checkSubject(ctx.subject), ...checkObject(ctx.object)];
    },
    files(ctx) {
        const object = ctx.object;
        switch (ctx.kind) {
            case 'actions':
                return [
                    {
                        path: `component/${ctx.subject}.actions.ts`,
                        content: `import type {IAction} from '@feasibleone/blong-browser';
 
export const ${ctx.subject}${capitalize(object)}Actions: Record<string, IAction> = {};
`,
                    },
                ];
            case 'portal':
                return [
                    {
                        path: `component/${ctx.subject}.portal.ts`,
                        content: `import {handler} from '@feasibleone/blong';
 
export default handler(({handler: {portalMenuItem}}) => ({
    async '${ctx.subject}.portal.params'() {
        return {menu: [{id: '${ctx.subject}.${object}', label: '${capitalize(object)}'}]};
    },
}));
`,
                    },
                ];
            default:
                return [
                    {
                        path: `component/${ctx.subject}.${object}.component.ts`,
                        content: `import {handler} from '@feasibleone/blong';
 
export default handler(() => ({
    '${ctx.subject}.${object}.browse': async () => ({
        title: '${capitalize(object)}',
        permission: '${ctx.subject}.${object}.find',
        component: async () => (await import('./${capitalize(object)}.js')).${capitalize(object)},
    }),
}));
`,
                    },
                ];
        }
    },
};
 
export default component;