Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/request/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export function getObservedComposedResources(req: RunFunctionRequest): { [key: s
* }
* ```
*/
export function getInput(req: RunFunctionRequest): { [key: string]: any } | undefined {
export function getInput(req: RunFunctionRequest): Record<string, unknown> | undefined {
return req.input;
}

Expand All @@ -147,7 +147,7 @@ export function getInput(req: RunFunctionRequest): { [key: string]: any } | unde
* }
* ```
*/
export function getContextKey(req: RunFunctionRequest, key: string): [any, boolean] {
export function getContextKey(req: RunFunctionRequest, key: string): [unknown, boolean] {
if (req.context && key in req.context) {
return [req.context[key], true];
}
Expand Down
34 changes: 27 additions & 7 deletions src/resource/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,15 @@ export function newDesiredComposed(): DesiredComposed {
* Convert a protobuf Struct to a Kubernetes object (plain JavaScript object)
* This is a more efficient conversion that avoids JSON round-trips when possible
*
* Note: This function is ported from the Go SDK for API compatibility.
* In TypeScript, this is a pass-through operation since JavaScript objects
* work directly with the protobuf library. This function may be deprecated
* in a future version once usage patterns are better understood.
*
* @param struct - The protobuf Struct to convert
* @returns A plain JavaScript object representing the Kubernetes resource
*/
export function asObject(struct: { [key: string]: any } | undefined): { [key: string]: any } {
export function asObject(struct: Record<string, unknown> | undefined): Record<string, unknown> {
if (!struct) {
return {};
}
Expand All @@ -60,10 +65,15 @@ export function asObject(struct: { [key: string]: any } | undefined): { [key: st
* Convert a Kubernetes object to a protobuf Struct
* This is used when creating Resource objects from plain JavaScript objects
*
* Note: This function is ported from the Go SDK for API compatibility.
* In TypeScript, this is a pass-through operation since JavaScript objects
* work directly with the protobuf library. This function may be deprecated
* in a future version once usage patterns are better understood.
*
* @param obj - The plain JavaScript object to convert
* @returns A protobuf Struct representation
*/
export function asStruct(obj: { [key: string]: any }): { [key: string]: any } {
export function asStruct(obj: Record<string, unknown>): Record<string, unknown> {
// In our TypeScript implementation, this is essentially a pass-through
// The actual conversion happens in the protobuf serialization layer
return obj;
Expand All @@ -73,11 +83,16 @@ export function asStruct(obj: { [key: string]: any }): { [key: string]: any } {
* Helper function for tests: Convert an object to a Struct, panics on failure
* Only use this in test code
*
* Note: This function is ported from the Go SDK for API compatibility.
* In TypeScript, this simply calls asStruct() which is a pass-through operation.
* This function may be deprecated in a future version once usage patterns are
* better understood.
*
* @param obj - The object to convert
* @returns A Struct representation
* @throws Error if conversion fails
*/
export function mustStructObject(obj: { [key: string]: any }): { [key: string]: any } {
export function mustStructObject(obj: Record<string, unknown>): Record<string, unknown> {
try {
return asStruct(obj);
} catch (error) {
Expand All @@ -91,13 +106,18 @@ export function mustStructObject(obj: { [key: string]: any }): { [key: string]:
* Helper function for tests: Parse a JSON string into a Struct, panics on failure
* Only use this in test code
*
* Note: This function is ported from the Go SDK for API compatibility.
* In TypeScript, this parses JSON and calls asStruct() which is a pass-through operation.
* Consider using JSON.parse() directly. This function may be deprecated in a future
* version once usage patterns are better understood.
*
* @param json - The JSON string to parse
* @returns A Struct representation
* @throws Error if parsing or conversion fails
*/
export function mustStructJSON(json: string): { [key: string]: any } {
export function mustStructJSON(json: string): Record<string, unknown> {
try {
const obj = JSON.parse(json);
const obj = JSON.parse(json) as Record<string, unknown>;
return asStruct(obj);
} catch (error) {
throw new Error(
Expand All @@ -116,7 +136,7 @@ export function mustStructJSON(json: string): { [key: string]: any } {
* @returns A Resource
*/
export function fromObject(
obj: { [key: string]: any },
obj: Record<string, unknown>,
connectionDetails?: ConnectionDetails,
ready?: Ready
): Resource {
Expand All @@ -134,6 +154,6 @@ export function fromObject(
* @param resource - The Resource to extract from
* @returns The plain JavaScript object, or undefined if not present
*/
export function toObject(resource: Resource): { [key: string]: any } | undefined {
export function toObject(resource: Resource): Record<string, unknown> | undefined {
return resource.resource;
}
10 changes: 5 additions & 5 deletions src/response/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export function setDesiredComposedResources(
*/
export function setDesiredResources(
rsp: RunFunctionResponse,
resources: { [key: string]: { [key: string]: any } }
resources: Record<string, Record<string, unknown>>
): RunFunctionResponse {
// Ensure desired state exists
if (!rsp.desired) {
Expand Down Expand Up @@ -337,7 +337,7 @@ export function setDesiredCompositeStatus({
status,
}: {
rsp: RunFunctionResponse;
status: { [key: string]: any };
status: Record<string, unknown>;
}): RunFunctionResponse {
// Ensure desired state exists
if (!rsp.desired) {
Expand All @@ -357,7 +357,7 @@ export function setDesiredCompositeStatus({
// Merge the status
rsp.desired.composite.resource = merge(rsp.desired.composite.resource, {
status: status,
}) as { [key: string]: any };
}) as Record<string, unknown>;

return rsp;
}
Expand All @@ -384,7 +384,7 @@ export function setDesiredCompositeStatus({
export function setContextKey(
rsp: RunFunctionResponse,
key: string,
value: any
value: unknown
): RunFunctionResponse {
if (!rsp.context) {
rsp.context = {};
Expand Down Expand Up @@ -459,7 +459,7 @@ export function setDesiredCompositeResource(
*/
export function setOutput(
rsp: RunFunctionResponse,
output: { [key: string]: any }
output: Record<string, unknown>
): RunFunctionResponse {
rsp.output = output;
return rsp;
Expand Down