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 | import { E } from '@endo/eventual-send';
import type { MethodSchema } from '@metamask/kernel-utils';
import { GET_DESCRIPTION } from '@metamask/kernel-utils/discoverable';
import { methodsToRemotableSpec } from '@metamask/service-discovery-types';
import type { RemotableSpec } from '@metamask/service-discovery-types';
/**
* Build a `RemotableSpec` describing `service`'s API by invoking the
* discoverable-exo sigil `__getDescription__` and mapping the result into
* the wire-format spec.
*
* @param service - The discoverable service exo.
* @param description - Natural-language description to attach to the
* resulting RemotableSpec.
* @returns A RemotableSpec describing the service's methods.
*/
export async function getRemotableSpec(
service: unknown,
description: string,
): Promise<RemotableSpec> {
const presence = E(service) as unknown as {
[GET_DESCRIPTION]: () => Promise<Record<string, MethodSchema>>;
};
const methods = await presence[GET_DESCRIPTION]();
return methodsToRemotableSpec({ methods, description });
}
|