-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
api.ts
299 lines (288 loc) · 7.46 KB
/
api.ts
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
* Copyright 2021 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Entity, EntityName, Location } from '@backstage/catalog-model';
/**
* A Symbol to define if a catalog filter exists or not.
*
* @public
*/
export const CATALOG_FILTER_EXISTS = Symbol.for(
// Random UUID to ensure no collisions
'CATALOG_FILTER_EXISTS_0e15b590c0b343a2bae3e787e84c2111',
);
/**
* A request type for retrieving catalog Entities.
*
* @public
*/
export type CatalogEntitiesRequest = {
/**
* If given, return only entities that match the given patterns.
*
* @remarks
*
* If multiple filter sets are given as an array, then there is effectively an
* OR between each filter set.
*
* Within one filter set, there is effectively an AND between the various
* keys.
*
* Within one key, if there are more than one value, then there is effectively
* an OR between them.
*
* Example: For an input of
*
* ```
* [
* { kind: ['API', 'Component'] },
* { 'metadata.name': 'a', 'metadata.namespace': 'b' }
* ]
* ```
*
* This effectively means
*
* ```
* (kind = EITHER 'API' OR 'Component')
* OR
* (metadata.name = 'a' AND metadata.namespace = 'b' )
* ```
*
* Each key is a dot separated path in each object.
*
* As a value you can also pass in the symbol `CATALOG_FILTER_EXISTS`
* (exported from this package), which means that you assert on the existence
* of that key, no matter what its value is.
*/
filter?:
| Record<string, string | symbol | (string | symbol)[]>[]
| Record<string, string | symbol | (string | symbol)[]>
| undefined;
/**
* If given, return only the parts of each entity that match those dot
* separated paths in each object.
*
* @remarks
*
* Example: For an input of `['kind', 'metadata.annotations']`, then response
* objects will be shaped like
*
* ```
* {
* "kind": "Component",
* "metadata": {
* "annotations": {
* "foo": "bar"
* }
* }
* }
* ```
*/
fields?: string[] | undefined;
/**
* If given, skips over the first N items in the result set.
*/
offset?: number;
/**
* If given, returns at most N items from the result set.
*/
limit?: number;
/**
* If given, skips over all items before that cursor as returned by a previous
* request.
*/
after?: string;
};
/**
* A request type for Catalog Entity Ancestor information.
*
* @public
*/
export type CatalogEntityAncestorsRequest = {
entityRef: string;
};
/**
* A response type for Catalog Entity Ancestor information.
*
* @public
*/
export type CatalogEntityAncestorsResponse = {
rootEntityRef: string;
items: { entity: Entity; parentEntityRefs: string[] }[];
};
/**
* A response type for the result of a catalog operation in list form.
*
* @public
*/
export type CatalogListResponse<T> = {
items: T[];
};
/**
* Options you can pass into a catalog request for additional information.
*
* @public
*/
export type CatalogRequestOptions = {
token?: string;
};
/**
* Public functions for interacting with the Catalog API.
*
* @public
*/
export interface CatalogApi {
/**
* Gets the Entities from the catalog based on your request and options.
*
* @param request - An object with your filters and fields.
* @param options - An object with your preferred options.
*
* @returns A CatalogListResponse with items typed Catalog Model Entity.
*
*/
getEntities(
request?: CatalogEntitiesRequest,
options?: CatalogRequestOptions,
): Promise<CatalogListResponse<Entity>>;
/**
* Gets the Entity ancestor information from the catalog based on your request and options.
*
* @param request - An object with your filters and fields.
* @param options - An object with your preferred options.
*
* @returns A CatalogEntityAncestorsResponse.
*/
getEntityAncestors(
request: CatalogEntityAncestorsRequest,
options?: CatalogRequestOptions,
): Promise<CatalogEntityAncestorsResponse>;
/**
* Gets a single Entity from the catalog by Entity name.
*
* @param name - A complete Entity name, with the full kind-namespace-name triplet.
* @param options - An object with your preferred options.
*
* @returns A {@link catalog-model#Entity}.
*/
getEntityByName(
name: EntityName,
options?: CatalogRequestOptions,
): Promise<Entity | undefined>;
/**
* Removes a single Entity from the catalog by Entity UID.
*
* @param uid - A string of the Entity UID.
* @param options - An object with your preferred options.
*
*/
removeEntityByUid(
uid: string,
options?: CatalogRequestOptions,
): Promise<void>;
/**
* Refreshes an Entity in the catalog.
*
* @param entityRef - A string in the form of 'Kind/default:foo'.
* @param options - An object with your preferred options.
*
*/
refreshEntity(
entityRef: string,
options?: CatalogRequestOptions,
): Promise<void>;
// Locations
/**
* Gets a Location object by ID from the catalog.
*
* @param id - A string in of the Location Id.
* @param options - An object with your preferred options.
*
* @returns A {@link catalog-model#Location_2}.
*/
getLocationById(
id: string,
options?: CatalogRequestOptions,
): Promise<Location | undefined>;
/**
* Gets origin location by Entity.
*
* @param entity - An {@link catalog-model#Entity}.
* @param options - An object with your preferred options.
*
* @returns A {@link catalog-model#Location_2}.
*/
getOriginLocationByEntity(
entity: Entity,
options?: CatalogRequestOptions,
): Promise<Location | undefined>;
/**
* Gets Location by Entity.
*
* @param entity - An {@link catalog-model#Entity}.
* @param options - An object with your preferred options.
*
* @returns A {@link catalog-model#Location_2}.
*/
getLocationByEntity(
entity: Entity,
options?: CatalogRequestOptions,
): Promise<Location | undefined>;
/**
* Adds a Location.
*
* @param location - A request type for adding a Location to the catalog.
* @param options - An object with your preferred options.
*
* @returns A AddLocationResponse.
*/
addLocation(
location: AddLocationRequest,
options?: CatalogRequestOptions,
): Promise<AddLocationResponse>;
/**
* Removes a Location by Id.
*
* @param id - A string in of the Location Id.
* @param options - An object with your preferred options.
*
*/
removeLocationById(
id: string,
options?: CatalogRequestOptions,
): Promise<void>;
}
/**
* A request type for adding a Location to the catalog.
*
* @public
*/
export type AddLocationRequest = {
type?: string;
target: string;
dryRun?: boolean;
presence?: 'optional' | 'required';
};
/**
* A response type for adding a Location to the catalog.
*
* @public
*/
export type AddLocationResponse = {
location: Location;
entities: Entity[];
// Exists is only set in DryRun mode.
exists?: boolean;
};