All files / sample-services/src/echo-service service.ts

0% Statements 0/5
0% Branches 0/3
0% Functions 0/2
0% Lines 0/5

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                                                                                                     
import { makeDiscoverableExo } from '@metamask/kernel-utils/discoverable';
 
export const ECHO_SERVICE_DESCRIPTION =
  'Echoes back whatever text it is given, optionally reversed. Useful for testing connectivity and round-trip latency.';
 
/**
 * Build a trivial Echo service exo. Used during development to give the
 * service matcher at least one meaningful alternative to rank alongside
 * the real wallet service.
 *
 * @returns A discoverable exo with an `echo` method.
 */
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function makeEchoService() {
  return makeDiscoverableExo(
    'EchoService',
    {
      async echo(message: string, reverse: boolean = false): Promise<string> {
        if (reverse) {
          // Use Array.from so multi-code-point characters (e.g., emoji)
          // survive the reversal intact.
          return Array.from(message).reverse().join('');
        }
        return message;
      },
    },
    {
      echo: {
        description:
          'Return the input message, optionally reversed end-for-end.',
        args: {
          message: {
            type: 'string',
            description: 'Any text.',
          },
          reverse: {
            type: 'boolean',
            description:
              'If true, the returned string is the input reversed character by character. Defaults to false.',
          },
        },
        returns: {
          type: 'string',
          description:
            'The input text, returned unchanged when `reverse` is false (or omitted) and reversed when `reverse` is true.',
        },
      },
    },
  );
}