import type { InjectionKey, Ref } from 'vue'; import { inject as vueInject, provide as vueProvide } from 'vue'; import type { Org, OrgPermissions, Pipeline, PipelineConfig, Repo, RepoPermissions } from '~/lib/api/types'; import type { Tab } from './useTabs'; export interface InjectKeys { repo: Ref; 'repo-permissions': Ref; org: Ref; 'org-permissions': Ref; pipeline: Ref; 'pipeline-configs': Ref; tabs: Ref; pipelines: Ref; } export function requiredInject(key: T): InjectKeys[T] { const value = vueInject(key); if (value === undefined) { throw new Error(`Unexpected: ${key} should be provided at this place`); } return value; } export function provide(key: T, value: InjectKeys[T]): void { return vueProvide(key, value as T extends InjectionKey ? V : InjectKeys[T]); }