async function resolveEntityFeatureAccess(entityTypes, getRequiredFeatures, checkFeatures) {
  const access = /* @__PURE__ */ new Map();
  const featuresByEntity = /* @__PURE__ */ new Map();
  const unionFeatures = /* @__PURE__ */ new Set();
  for (const entityType of new Set(entityTypes)) {
    const features = getRequiredFeatures(entityType) ?? [];
    featuresByEntity.set(entityType, features);
    if (features.length === 0) {
      access.set(entityType, true);
    } else {
      for (const feature of features) unionFeatures.add(feature);
    }
  }
  const gated = [...featuresByEntity.entries()].filter(([, features]) => features.length > 0);
  if (gated.length === 0) return access;
  if (await checkFeatures([...unionFeatures])) {
    for (const [entityType] of gated) access.set(entityType, true);
    return access;
  }
  for (const [entityType, features] of gated) {
    access.set(entityType, await checkFeatures(features));
  }
  return access;
}
async function runWidgetDataBatch(entries, deps) {
  const access = await resolveEntityFeatureAccess(
    entries.map((entry) => entry.request.entityType),
    deps.getRequiredFeatures,
    deps.checkFeatures
  );
  return Promise.all(
    entries.map(async (entry) => {
      if (access.get(entry.request.entityType) === false) {
        return { id: entry.id, ok: false, error: "Forbidden" };
      }
      try {
        const data = await deps.fetchOne(entry.request);
        return { id: entry.id, ok: true, data };
      } catch (error) {
        return { id: entry.id, ok: false, error: deps.describeError(error) };
      }
    })
  );
}
export {
  resolveEntityFeatureAccess,
  runWidgetDataBatch
};
//# sourceMappingURL=widgetDataBatch.js.map
