forked from redhat-developer/vscode-openshift-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponentType.ts
More file actions
103 lines (87 loc) · 2.6 KB
/
componentType.ts
File metadata and controls
103 lines (87 loc) · 2.6 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import { Url } from 'url';
import { Data } from './componentTypeDescription';
export enum ComponentKind {
S2I = 's2i',
DEVFILE = 'devfile'
}
export interface RegistryList {
registries: Registry[];
}
export interface Registry {
readonly Name: string;
readonly URL: string;
readonly Secure: boolean;
}
export interface ImageStreamTag {
name: string,
typeName?: string;
annotations: {
description: string;
'openshift.io/display-name': string;
tags: string;
version: string;
sampleRepo: string;
}
}
export function ascDevfileFirst(c1: ComponentType, c2: ComponentType): number {
if(c1.type !== c2.type) {
return c1.type === ComponentKind.DEVFILE? -1: 1;
}
return c1.label.localeCompare(c2.label)
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isDevfileComponent(comp: any): comp is DevfileComponentType {
return comp.Registry;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isRegistry(registry: any): registry is Registry {
return registry.Name && registry.URL && registry.Secure !== undefined;
}
export interface RegistryRef {
Name: string;
URL: Url;
}
export interface DevfileComponentType {
Name: string;
DisplayName: string;
Description: string;
Link: string;
Registry: RegistryRef;
}
export interface ComponentTypesJson {
kind: string;
apiVersion: string;
metadata: {
creationTimestamp: string;
},
items: DevfileComponentType[];
}
export interface ComponentType {
label: string;
description: string;
name: string;
type: ComponentKind;
version: string;
}
export interface ComponentTypeDescription {
RegistryName: string;
Devfile: Data;
}
export class ComponentTypeAdapter implements ComponentType {
constructor(
public readonly type: ComponentKind,
public readonly name: string,
public readonly version: string,
public readonly description: string,
public readonly tags?: string,
public readonly registryName?: string) {
}
get label(): string {
const versionSuffix = this.version? `/${this.version}` : `/${this.registryName}` ;
return `${this.name}${versionSuffix}`;
}
}