mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-16 13:36:33 +00:00
22414744b0
Co-authored-by: qwerty287 <qwerty287@posteo.de> Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com> Co-authored-by: Anbraten <6918444+anbraten@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
22 lines
728 B
TypeScript
22 lines
728 B
TypeScript
import type { InjectionKey, Ref } from 'vue';
|
|
import { inject as vueInject, provide as vueProvide } from 'vue';
|
|
|
|
import type { Org, OrgPermissions, Repo } from '~/lib/api/types';
|
|
|
|
export interface InjectKeys {
|
|
repo: Ref<Repo>;
|
|
org: Ref<Org | undefined>;
|
|
'org-permissions': Ref<OrgPermissions | undefined>;
|
|
}
|
|
|
|
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 {
|
|
return vueProvide(key, value as T extends InjectionKey<infer V> ? V : InjectKeys[T]);
|
|
}
|