-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathresource-instance.ts
More file actions
96 lines (92 loc) · 2.85 KB
/
resource-instance.ts
File metadata and controls
96 lines (92 loc) · 2.85 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
import { SteveGetResponse } from '@shell/types/rancher/steve.api';
/**
* Instance-level operations available on resources returned by the Resources API.
*
* These methods operate on a specific resource that has already been fetched.
*/
export interface ResourceInstanceApi {
/**
* Applies a partial update to a resource using HTTP PATCH (merge-patch).
*
* Only the fields provided in `data` are sent to the server — the rest of the resource
* remains unchanged. The server response is merged back into this instance.
*
* Requires edit permissions (`canEdit`).
*
* @param data - An object containing only the fields to update.
* @returns a resource instance, updated with the server response.
*
* @example
* ```ts
* import { useResources, K8S } from '@shell/apis';
*
* const resources = useResources();
* const configMap = await resources.cluster.find(K8S.CONFIG_MAP, 'default/my-config');
*
* await configMap.patch({ newKey: 'newValue' });
* ```
*/
patch(data: Record<string, any>): Promise<ResourceInstanceApi>;
/**
* Performs a full replacement update of a resource using HTTP PUT.
*
* Sends the entire current state of the resource to the server.
*
* Requires edit permissions (`canEdit`).
*
* @returns a resource instance, updated with the server response.
*
* @example
* ```ts
* import { useResources, K8S } from '@shell/apis';
*
* const resources = useResources();
* const configMap = await resources.cluster.find(K8S.CONFIG_MAP, 'default/my-config');
*
* configMap.data.myKey = 'updatedValue';
* await configMap.update();
* ```
*/
update(): Promise<ResourceInstanceApi>;
/**
* Deletes a resource instance.
*
* Requires delete permissions (`canDelete`).
*
* @returns A promise that resolves when the resource has been deleted.
*
* @example
* ```ts
* import { useResources, K8S } from '@shell/apis';
*
* const resources = useResources();
* const pod = await resources.cluster.find(K8S.POD, 'default/my-pod-123');
*
* await pod.delete();
* ```
*/
delete(): Promise<void>;
}
/**
* Represents a single resource instance returned from the Resources API.
*
* Provides instance-level operations such as deleting or updating a resource instance.
* The resource data (metadata, spec, status, etc.) is accessible directly on the instance.
*
* @template T - The shape of the underlying resource data (defaults to SteveGetResponse)
*
* @example
* ```ts
* import { useResources, K8S } from '@shell/apis';
*
* const resources = useResources();
* const pod = await resources.cluster.find(K8S.POD, 'my-pod-123');
*
* // Access resource data directly
* console.log(pod.metadata.name);
*
* // Use instance operations
* await pod.delete();
* ```
*/
export type ResourceInstance<T = SteveGetResponse> = T & ResourceInstanceApi;