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 | 4x 17x 14x 4x 1x 1x | import type { MethodSchema } from '@metamask/kernel-utils';
import type { CapabilityRecord, CapabilitySpec } from '../types.ts';
type SchemaEntry = [string, { schema: MethodSchema }];
/**
* Extract only the serializable schemas from the capabilities
*
* @param capabilities - The capabilities to extract the schemas from
* @returns A record mapping capability names to their schemas
*/
export const extractCapabilitySchemas = (
capabilities: CapabilityRecord,
): Record<
keyof typeof capabilities,
(typeof capabilities)[keyof typeof capabilities]['schema']
> =>
Object.fromEntries(
(Object.entries(capabilities) as unknown as SchemaEntry[]).map(
([name, { schema }]) => [name, schema],
),
);
type CapabilityEntry = [string, CapabilitySpec<never, unknown>];
/**
* Extract only the functions from the capabilities
*
* @param capabilities - The capabilities to extract the functions from
* @returns A record mapping capability names to their functions
*/
export const extractCapabilities = (
capabilities: CapabilityRecord,
): Record<
keyof typeof capabilities,
(typeof capabilities)[keyof typeof capabilities]['func']
> =>
Object.fromEntries(
(Object.entries(capabilities) as unknown as CapabilityEntry[]).map(
([name, { func }]) => [name, func],
),
);
|