All files / nodejs/src/io index.ts

25% Statements 1/4
0% Branches 0/2
50% Functions 1/2
25% Lines 1/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                          1x                      
import type { IOChannelFactory, IOConfig } from '@metamask/ocap-kernel';
 
import { makeSocketIOChannel } from './socket-channel.ts';
 
export { makeSocketIOChannel } from './socket-channel.ts';
 
/**
 * Create an IOChannelFactory for the Node.js environment.
 * Dispatches on `config.type` to the appropriate channel implementation.
 *
 * @returns An IOChannelFactory.
 */
export function makeIOChannelFactory(): IOChannelFactory {
  return async (name: string, config: IOConfig) => {
    switch (config.type) {
      case 'socket':
        return makeSocketIOChannel(name, config.path);
      default:
        throw new Error(
          `Unsupported IO channel type "${config.type}" for channel "${name}"`,
        );
    }
  };
}