Skip to content

Commit 16077d4

Browse files
petermetzkikoncuo
authored andcommitted
feat(cmd-api-server): user defined type guard isHealthcheckResponse
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 <[email protected]>
1 parent 3a98360 commit 16077d4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Bools } from "@hyperledger/cactus-common";
2+
import { HealthCheckResponse } from "../generated/openapi/typescript-axios/api";
3+
4+
export function isHealthcheckResponse(x: unknown): x is HealthCheckResponse {
5+
return (
6+
!!x &&
7+
typeof x === "object" &&
8+
Bools.isBooleanStrict((x as HealthCheckResponse).success) &&
9+
typeof (x as HealthCheckResponse).memoryUsage === "object" &&
10+
typeof (x as HealthCheckResponse).memoryUsage.rss === "number" &&
11+
typeof (x as HealthCheckResponse).memoryUsage.heapTotal === "number" &&
12+
typeof (x as HealthCheckResponse).memoryUsage.heapUsed === "number" &&
13+
typeof (x as HealthCheckResponse).memoryUsage.external === "number" &&
14+
typeof (x as HealthCheckResponse).createdAt === "string"
15+
);
16+
}

packages/cactus-cmd-api-server/src/main/typescript/public-api.ts

+2
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ export {
1717
} from "./config/self-signed-pki-generator";
1818

1919
export * from "./generated/openapi/typescript-axios/index";
20+
21+
export { isHealthcheckResponse } from "./model/is-healthcheck-response-type-guard";

0 commit comments

Comments
 (0)