toEndoPolicy = async (policyOrPolicyPath, options = {}) => {
  await Promise.resolve()

  const policy = await loadPolicies(policyOrPolicyPath, options)

  const lavamoatResources = /** @type {Resources} */ (
    policy.resources ?? create(null)
  )

  const rootPolicyRef = policy.root?.usePolicy

  /**
   * Actual conversion starts here.
   *
   * This converts {@link LavaMoatPolicy.resources LavaMoat's resources property}
   * to {@link LavaMoatEndoPolicy.resources Endo's resources property}.
   *
   * @type {LavaMoatEndoPolicy['resources']}
   */
  const resources = fromEntries(
    entries(lavamoatResources).reduce((acc, [resourceName, resourcePolicy]) => {
      const pkgPolicy = convertToEndoPackagePolicy(resourcePolicy)
      if (pkgPolicy) {
        acc.push([resourceName, pkgPolicy])
      }
      return acc
    }, /** @type {[resourceName: string, endoPolicy: LavaMoatEndoPackagePolicy][]} */ ([]))
  )

  /** @type {NonNullable<LavaMoatEndoPolicy['entry']>} */
  let entry
  // if we have a rootPolicyRef, we are going to copy its policy from resources
  // into the `entry` field.
  if (rootPolicyRef) {
    // if the root policy is undefined, then the root requested no resources
    // (which isn't very interesting, but whatever). create an empty resource policy for it
    if (!resources[rootPolicyRef]) {
      resources[rootPolicyRef] = {}
    }
    entry = resources[rootPolicyRef]
  } else {
    entry = ENDO_POLICY_ENTRY_TRUSTED
  }

  /** @type {LavaMoatEndoPolicy} */
  const endoPolicy = {
    ...ENDO_POLICY_BOILERPLATE,
    [ENDO_POLICY_RESOURCES]: resources,
    [ENDO_POLICY_ENTRY]: entry,
  }

  return endoPolicy
}
Converts a LavaMoat policy to an Endo policy.

Takes policy overrides into account, if provided.

Performs validation of policy and policy overrides.

@privateRemarks
The overloads aren't strictly necessary, but they're a little nicer to
understand for consumers.
@param {LavaMoatPolicy | string | URL} [policyOrPolicyPath] LavaMoat policy
  to convert (or path to policy file)
@param {ToEndoPolicyOptions} [options] Options for conversion
@returns {Promise<LavaMoatEndoPolicy>}
@public