All files / kernel-node-runtime/src/io index.ts

75% Statements 3/4
50% Branches 1/2
100% Functions 2/2
75% Lines 3/4

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                          5x 2x   2x                
import type { IOListenerFactory, IOConfig } from '@metamask/ocap-kernel';
 
import { makeSocketIOListener } from './socket-listener.ts';
 
export { makeSocketIOListener } from './socket-listener.ts';
 
/**
 * Create an IOListenerFactory for the Node.js environment.
 * Dispatches on `config.type` to the appropriate listener implementation.
 *
 * @returns An IOListenerFactory.
 */
export function makeIOListenerFactory(): IOListenerFactory {
  return async (name: string, config: IOConfig) => {
    switch (config.type) {
      case 'socket':
        return makeSocketIOListener(name, config.path);
      default:
        throw new Error(
          `Unsupported IO listener type "${config.type}" for listener "${name}"`,
        );
    }
  };
}