All files / kernel-utils/src vat-bundle.ts

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

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                  111x                             111x 100x  
import type { Infer } from '@metamask/superstruct';
import { array, is, literal, object, string } from '@metamask/superstruct';
 
/**
 * A bundle produced by the vat bundler.
 *
 * Contains the bundled code as an IIFE that assigns exports to `__vatExports__`,
 * along with metadata about the bundle's exports and external dependencies.
 */
export const VatBundleStruct = object({
  moduleFormat: literal('iife'),
  code: string(),
  exports: array(string()),
  external: array(string()),
});
 
export type VatBundle = Infer<typeof VatBundleStruct>;
 
/**
 * Type guard to check if a value is a VatBundle.
 *
 * @param value - The value to check.
 * @returns True if the value is a VatBundle.
 */
export const isVatBundle = (value: unknown): value is VatBundle =>
  is(value, VatBundleStruct);