diff --git a/src/request/request.ts b/src/request/request.ts index 0923f16..15b6ede 100644 --- a/src/request/request.ts +++ b/src/request/request.ts @@ -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 | undefined { return req.input; } @@ -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]; } diff --git a/src/resource/resource.ts b/src/resource/resource.ts index ce011ba..bd10619 100644 --- a/src/resource/resource.ts +++ b/src/resource/resource.ts @@ -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 | undefined): Record { if (!struct) { return {}; } @@ -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): Record { // In our TypeScript implementation, this is essentially a pass-through // The actual conversion happens in the protobuf serialization layer return obj; @@ -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): Record { try { return asStruct(obj); } catch (error) { @@ -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 { try { - const obj = JSON.parse(json); + const obj = JSON.parse(json) as Record; return asStruct(obj); } catch (error) { throw new Error( @@ -116,7 +136,7 @@ export function mustStructJSON(json: string): { [key: string]: any } { * @returns A Resource */ export function fromObject( - obj: { [key: string]: any }, + obj: Record, connectionDetails?: ConnectionDetails, ready?: Ready ): Resource { @@ -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 | undefined { return resource.resource; } diff --git a/src/response/response.ts b/src/response/response.ts index b932849..af45c27 100644 --- a/src/response/response.ts +++ b/src/response/response.ts @@ -263,7 +263,7 @@ export function setDesiredComposedResources( */ export function setDesiredResources( rsp: RunFunctionResponse, - resources: { [key: string]: { [key: string]: any } } + resources: Record> ): RunFunctionResponse { // Ensure desired state exists if (!rsp.desired) { @@ -337,7 +337,7 @@ export function setDesiredCompositeStatus({ status, }: { rsp: RunFunctionResponse; - status: { [key: string]: any }; + status: Record; }): RunFunctionResponse { // Ensure desired state exists if (!rsp.desired) { @@ -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; return rsp; } @@ -384,7 +384,7 @@ export function setDesiredCompositeStatus({ export function setContextKey( rsp: RunFunctionResponse, key: string, - value: any + value: unknown ): RunFunctionResponse { if (!rsp.context) { rsp.context = {}; @@ -459,7 +459,7 @@ export function setDesiredCompositeResource( */ export function setOutput( rsp: RunFunctionResponse, - output: { [key: string]: any } + output: Record ): RunFunctionResponse { rsp.output = output; return rsp;