All files / src/services namespace-tier-context.ts

100% Statements 10/10
100% Branches 2/2
100% Functions 3/3
100% Lines 10/10

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 3186x   86x             86x       86x 995x     86x 861x 861x       86x         29x    
import { AsyncLocalStorage } from 'node:async_hooks';
import type { GitLabTier } from './GitLabVersionDetector';
import { normalizeInstanceUrl } from '../utils/url';
 
interface NamespaceTierContext {
  instanceUrl: string;
  tier: GitLabTier | null;
}
 
const storage = new AsyncLocalStorage<NamespaceTierContext>();
 
/** GitLab.com subscriptions attach to top-level groups, not the shared instance.
 * https://docs.gitlab.com/subscriptions/manage_subscription/ */
export function hasNamespaceSubscriptions(instanceUrl: string): boolean {
  return normalizeInstanceUrl(instanceUrl) === 'https://gitlab.com';
}
 
export function currentNamespaceTier(instanceUrl: string): NamespaceTierContext | undefined {
  const context = storage.getStore();
  return context?.instanceUrl === normalizeInstanceUrl(instanceUrl) ? context : undefined;
}
 
/** A request's subscription never changes another request or the connection's metadata. */
export function runWithNamespaceTier<T>(
  instanceUrl: string,
  tier: GitLabTier | null,
  fn: () => T,
): T {
  return storage.run({ instanceUrl: normalizeInstanceUrl(instanceUrl), tier }, fn);
}