// runtime/base-classes/tenant-context.ts
import { AsyncLocalStorage } from "async_hooks";
var als = new AsyncLocalStorage();
function withRequester(ctx, fn) {
  return als.run(ctx, fn);
}
function requireRequester() {
  const ctx = als.getStore();
  if (!ctx) {
    throw new Error(
      "No requester context active. Wrap the entry point in withRequester({ userId, organizationId }, fn). See tenant-context.ts."
    );
  }
  return ctx;
}
function tryGetRequester() {
  return als.getStore();
}
function requireRequesterScope() {
  return requireRequester().scope ?? "user";
}
function withUserScope(userId, organizationId, fn) {
  return withRequester({ userId, organizationId, scope: "user" }, fn);
}
function withOrgScope(userId, organizationId, orgUserIds, fn) {
  return withRequester(
    { userId, organizationId, scope: "org", orgUserIds },
    fn
  );
}
function withSuperuserScope(userId, fn) {
  return withRequester(
    { userId, organizationId: null, scope: "superuser" },
    fn
  );
}

export {
  withRequester,
  requireRequester,
  tryGetRequester,
  requireRequesterScope,
  withUserScope,
  withOrgScope,
  withSuperuserScope
};
//# sourceMappingURL=chunk-ZUKFQL6E.js.map