2024-06-06 13:16:59 +00:00
|
|
|
import type { InjectionKey, Ref } from 'vue';
|
|
|
|
import { inject as vueInject, provide as vueProvide } from 'vue';
|
2022-09-27 09:05:00 +00:00
|
|
|
|
2024-11-19 13:04:50 +00:00
|
|
|
import type { Org, OrgPermissions, Pipeline, PipelineConfig, Repo } from '~/lib/api/types';
|
|
|
|
|
|
|
|
import type { Tab } from './useTabs';
|
2022-09-27 09:05:00 +00:00
|
|
|
|
2024-06-06 13:16:59 +00:00
|
|
|
export interface InjectKeys {
|
2022-09-27 09:05:00 +00:00
|
|
|
repo: Ref<Repo>;
|
2023-07-21 17:45:32 +00:00
|
|
|
org: Ref<Org | undefined>;
|
|
|
|
'org-permissions': Ref<OrgPermissions | undefined>;
|
2024-11-19 13:04:50 +00:00
|
|
|
pipeline: Ref<Pipeline | undefined>;
|
|
|
|
'pipeline-configs': Ref<PipelineConfig[] | undefined>;
|
|
|
|
tabs: Ref<Tab[]>;
|
2024-06-06 13:16:59 +00:00
|
|
|
}
|
2022-09-27 09:05:00 +00:00
|
|
|
|
|
|
|
export function inject<T extends keyof InjectKeys>(key: T): InjectKeys[T] {
|
|
|
|
const value = vueInject<InjectKeys[T]>(key);
|
|
|
|
if (value === undefined) {
|
|
|
|
throw new Error(`Please provide a value for ${key}`);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function provide<T extends keyof InjectKeys>(key: T, value: InjectKeys[T]): void {
|
2023-07-02 10:47:36 +00:00
|
|
|
return vueProvide(key, value as T extends InjectionKey<infer V> ? V : InjectKeys[T]);
|
2022-09-27 09:05:00 +00:00
|
|
|
}
|