pepr 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@
3
3
 
4
4
  import { clone, mergeDeepRight } from "ramda";
5
5
 
6
- import { KubernetesObject, Request } from "./k8s/types";
6
+ import { KubernetesObject, Operation, Request } from "./k8s/types";
7
7
  import { DeepPartial } from "./types";
8
8
 
9
9
  /**
@@ -46,8 +46,17 @@ export class PeprRequest<T extends KubernetesObject> {
46
46
  * @param input - The request object containing the Kubernetes resource to modify.
47
47
  */
48
48
  constructor(private _input: Request<T>) {
49
- // Deep clone the object to prevent mutation of the original object
50
- this.Raw = clone(_input.object);
49
+ // If this is a DELETE operation, use the oldObject instead
50
+ if (_input.operation === Operation.DELETE) {
51
+ this.Raw = clone(_input.oldObject as T);
52
+ } else {
53
+ // Otherwise, use the incoming object
54
+ this.Raw = clone(_input.object);
55
+ }
56
+
57
+ if (!this.Raw) {
58
+ throw new Error("unable to load the request object into PeprRequest.RawP");
59
+ }
51
60
  }
52
61
 
53
62
  /**
@@ -100,6 +109,7 @@ export class PeprRequest<T extends KubernetesObject> {
100
109
  if (this.Raw.metadata?.labels?.[key]) {
101
110
  delete this.Raw.metadata.labels[key];
102
111
  }
112
+
103
113
  return this;
104
114
  }
105
115
 
@@ -112,6 +122,7 @@ export class PeprRequest<T extends KubernetesObject> {
112
122
  if (this.Raw.metadata?.annotations?.[key]) {
113
123
  delete this.Raw.metadata.annotations[key];
114
124
  }
125
+
115
126
  return this;
116
127
  }
117
128
 
@@ -122,7 +133,7 @@ export class PeprRequest<T extends KubernetesObject> {
122
133
  * @returns
123
134
  */
124
135
  HasLabel(key: string) {
125
- return this.Raw?.metadata?.labels?.[key] !== undefined;
136
+ return this.Raw.metadata?.labels?.[key] !== undefined;
126
137
  }
127
138
 
128
139
  /**
@@ -132,6 +143,6 @@ export class PeprRequest<T extends KubernetesObject> {
132
143
  * @returns
133
144
  */
134
145
  HasAnnotation(key: string) {
135
- return this.Raw?.metadata?.annotations?.[key] !== undefined;
146
+ return this.Raw.metadata?.annotations?.[key] !== undefined;
136
147
  }
137
148
  }