Skip to content

Commit

Permalink
feat(cmd-api-server): user defined type guard isHealthcheckResponse
Browse files Browse the repository at this point in the history
Useful for validating if an untyped object has the
API surface of a HealthCheckResponse as defined
in the OpenAPI specs of the API server.

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz authored and kikoncuo committed Apr 13, 2021
1 parent 3a98360 commit 16077d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Bools } from "@hyperledger/cactus-common";
import { HealthCheckResponse } from "../generated/openapi/typescript-axios/api";

export function isHealthcheckResponse(x: unknown): x is HealthCheckResponse {
return (
!!x &&
typeof x === "object" &&
Bools.isBooleanStrict((x as HealthCheckResponse).success) &&
typeof (x as HealthCheckResponse).memoryUsage === "object" &&
typeof (x as HealthCheckResponse).memoryUsage.rss === "number" &&
typeof (x as HealthCheckResponse).memoryUsage.heapTotal === "number" &&
typeof (x as HealthCheckResponse).memoryUsage.heapUsed === "number" &&
typeof (x as HealthCheckResponse).memoryUsage.external === "number" &&
typeof (x as HealthCheckResponse).createdAt === "string"
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ export {
} from "./config/self-signed-pki-generator";

export * from "./generated/openapi/typescript-axios/index";

export { isHealthcheckResponse } from "./model/is-healthcheck-response-type-guard";

0 comments on commit 16077d4

Please sign in to comment.