@openstatus/health-grpc 0.1.4-dev.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.
- package/README.md +79 -0
- package/dist/_virtual/rolldown_runtime.cjs +30 -0
- package/dist/mod.cjs +59 -0
- package/dist/mod.d.cts +38 -0
- package/dist/mod.d.cts.map +1 -0
- package/dist/mod.d.ts +38 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +57 -0
- package/dist/mod.js.map +1 -0
- package/package.json +67 -0
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# @openstatus/health-grpc
|
|
2
|
+
|
|
3
|
+
gRPC probe for [`@openstatus/health`](https://jsr.io/@openstatus/health).
|
|
4
|
+
Calls the standard
|
|
5
|
+
[`grpc.health.v1.Health/Check`](https://github.com/grpc/grpc/blob/master/doc/health-checking.md)
|
|
6
|
+
method through a generated `@grpc/grpc-js` client and fails the check
|
|
7
|
+
unless the server answers `SERVING` — for every upstream that speaks gRPC
|
|
8
|
+
and implements the health protocol, which most do.
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
deno add jsr:@openstatus/health jsr:@openstatus/health-grpc
|
|
12
|
+
npm install @openstatus/health @openstatus/health-grpc grpc-health-check @grpc/grpc-js
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { credentials } from "@grpc/grpc-js";
|
|
17
|
+
import { HealthClient } from "grpc-health-check";
|
|
18
|
+
import { createHealthHandler } from "@openstatus/health";
|
|
19
|
+
import { grpcProbe } from "@openstatus/health-grpc";
|
|
20
|
+
|
|
21
|
+
const client = new HealthClient(env.ORDERS_GRPC_ADDR, credentials.createInsecure());
|
|
22
|
+
|
|
23
|
+
Deno.serve(
|
|
24
|
+
createHealthHandler({
|
|
25
|
+
probes: [grpcProbe({ client, service: "orders.Orders" })],
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Any client with `check(request, callback)` works: the `HealthClient` from
|
|
31
|
+
[`grpc-health-check`](https://github.com/grpc/grpc-node/tree/master/packages/grpc-health-check),
|
|
32
|
+
stubs generated from `health.proto` with `@grpc/proto-loader` or
|
|
33
|
+
`ts-proto`'s grpc-js output. `service` names the service to ask about;
|
|
34
|
+
the default empty string asks about the server as a whole. The probe
|
|
35
|
+
accepts the status as the enum number (`1`) or its name (`"SERVING"`),
|
|
36
|
+
whichever way the stubs were generated, and reports `NOT_SERVING`,
|
|
37
|
+
`SERVICE_UNKNOWN` or a transport error otherwise. A `timeoutMs` cancels
|
|
38
|
+
the call in flight. Reuse the client your application already holds: a
|
|
39
|
+
grpc-js channel reconnects on its own and one client per process is the
|
|
40
|
+
intended pattern.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
grpcProbe({
|
|
44
|
+
client,
|
|
45
|
+
service: "orders.Orders",
|
|
46
|
+
// optional overrides from the Probe contract
|
|
47
|
+
name: "orders",
|
|
48
|
+
critical: true,
|
|
49
|
+
timeoutMs: 1000,
|
|
50
|
+
skip: () => env.ORDERS_GRPC_ADDR == null,
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Non-critical by default: an upstream that is down degrades the report
|
|
55
|
+
instead of taking this service out of rotation with it. Set
|
|
56
|
+
`critical: true` when requests cannot be served without that upstream.
|
|
57
|
+
|
|
58
|
+
The client is typed structurally as `{ check(request, callback) }`, so
|
|
59
|
+
`@grpc/grpc-js` is an optional peer dependency for its types only and the
|
|
60
|
+
probe adds no runtime import of it. The factory throws `ProbeConfigError`
|
|
61
|
+
at construction when the client has no `check()`.
|
|
62
|
+
|
|
63
|
+
## About openstatus
|
|
64
|
+
|
|
65
|
+
[openstatus](https://www.openstatus.dev/) is the open-source uptime monitoring
|
|
66
|
+
and status page platform. This package is part of
|
|
67
|
+
[`@openstatus/health`](https://github.com/openstatusHQ/health), the `/health`
|
|
68
|
+
endpoints behind openstatus's own services, extracted so any JavaScript server
|
|
69
|
+
can expose one. Point an
|
|
70
|
+
[openstatus monitor](https://www.openstatus.dev/docs/reference/http-monitor)
|
|
71
|
+
at the endpoint and assert on `status` in the body to be alerted on
|
|
72
|
+
`degraded` before it becomes `unhealthy`.
|
|
73
|
+
|
|
74
|
+
Source: [github.com/openstatusHQ/health](https://github.com/openstatusHQ/health).
|
|
75
|
+
Issues and PRs welcome.
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
[MIT](https://github.com/openstatusHQ/health/blob/main/LICENSE)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
|
|
25
|
+
Object.defineProperty(exports, '__toESM', {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return __toESM;
|
|
29
|
+
}
|
|
30
|
+
});
|
package/dist/mod.cjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const __openstatus_health = require_rolldown_runtime.__toESM(require("@openstatus/health"));
|
|
3
|
+
|
|
4
|
+
//#region src/mod.ts
|
|
5
|
+
/** Probe name when `name` is unset. */
|
|
6
|
+
const grpcDefaultName = "grpc";
|
|
7
|
+
/** Service checked when `service` is unset: the empty string means the server as a whole. */
|
|
8
|
+
const grpcDefaultService = "";
|
|
9
|
+
/** A probe that calls `Health/Check` and expects `SERVING`; non-critical by default. Throws `ProbeConfigError` without `check()` or for a non-string `service`. */
|
|
10
|
+
function grpcProbe(options) {
|
|
11
|
+
const client = options.client;
|
|
12
|
+
if (typeof client?.check !== "function") throw new __openstatus_health.ProbeConfigError("grpcProbe", "client", `must expose check(), got ${describe(client)}`);
|
|
13
|
+
const service = options.service === void 0 ? grpcDefaultService : options.service;
|
|
14
|
+
if (typeof service !== "string") throw new __openstatus_health.ProbeConfigError("grpcProbe", "service", `must be a string, got ${String(service)}`);
|
|
15
|
+
return {
|
|
16
|
+
name: options.name ?? grpcDefaultName,
|
|
17
|
+
critical: options.critical ?? false,
|
|
18
|
+
timeoutMs: options.timeoutMs,
|
|
19
|
+
skip: options.skip,
|
|
20
|
+
run: (signal) => new Promise((resolve, reject) => {
|
|
21
|
+
signal.throwIfAborted();
|
|
22
|
+
const onAbort = () => {
|
|
23
|
+
call.cancel();
|
|
24
|
+
reject(signal.reason);
|
|
25
|
+
};
|
|
26
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
27
|
+
const call = client.check({ service }, (error, response) => {
|
|
28
|
+
signal.removeEventListener("abort", onAbort);
|
|
29
|
+
if (error != null) {
|
|
30
|
+
reject(error);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const status = response?.status;
|
|
34
|
+
if (status === 1 || status === "SERVING") {
|
|
35
|
+
resolve();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
reject(/* @__PURE__ */ new Error(`serving status ${describeStatus(status)}`));
|
|
39
|
+
});
|
|
40
|
+
})
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function describeStatus(status) {
|
|
44
|
+
if (status === 0 || status === "UNKNOWN") return "UNKNOWN";
|
|
45
|
+
if (status === 2 || status === "NOT_SERVING") return "NOT_SERVING";
|
|
46
|
+
if (status === 3 || status === "SERVICE_UNKNOWN") return "SERVICE_UNKNOWN";
|
|
47
|
+
return String(status);
|
|
48
|
+
}
|
|
49
|
+
function describe(client) {
|
|
50
|
+
if (client == null) return String(client);
|
|
51
|
+
if (typeof client !== "object") return typeof client;
|
|
52
|
+
const keys = Object.keys(client);
|
|
53
|
+
return keys.length === 0 ? "an object with no keys" : `an object with keys ${keys.slice(0, 8).join(", ")}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
exports.grpcDefaultName = grpcDefaultName;
|
|
58
|
+
exports.grpcDefaultService = grpcDefaultService;
|
|
59
|
+
exports.grpcProbe = grpcProbe;
|
package/dist/mod.d.cts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Probe, ProbeOverrides } from "@openstatus/health";
|
|
2
|
+
|
|
3
|
+
//#region src/mod.d.ts
|
|
4
|
+
|
|
5
|
+
/** Probe name when `name` is unset. */
|
|
6
|
+
declare const grpcDefaultName = "grpc";
|
|
7
|
+
/** Service checked when `service` is unset: the empty string means the server as a whole. */
|
|
8
|
+
declare const grpcDefaultService = "";
|
|
9
|
+
/** What `Check` answers; `status` is `1` or `"SERVING"` when healthy, depending on how enums were loaded. */
|
|
10
|
+
interface GrpcHealthCheckResponse {
|
|
11
|
+
/** The `ServingStatus` enum value. */
|
|
12
|
+
readonly status?: number | string;
|
|
13
|
+
}
|
|
14
|
+
/** The subset of a `ClientUnaryCall` the probe uses. */
|
|
15
|
+
interface GrpcLikeCall {
|
|
16
|
+
/** Cancel the in-flight call. */
|
|
17
|
+
cancel(): void;
|
|
18
|
+
}
|
|
19
|
+
/** The subset of a generated `Health` client the probe uses. */
|
|
20
|
+
interface GrpcLikeHealthClient {
|
|
21
|
+
/** Call `Health/Check` for `service`. */
|
|
22
|
+
check(request: {
|
|
23
|
+
readonly service: string;
|
|
24
|
+
}, callback: (error: Error | null, response?: GrpcHealthCheckResponse) => void): GrpcLikeCall;
|
|
25
|
+
}
|
|
26
|
+
/** Options for `grpcProbe()`. */
|
|
27
|
+
interface GrpcProbeOptions extends ProbeOverrides {
|
|
28
|
+
/** A `grpc.health.v1.Health` client, e.g. from `grpc-health-check` or your generated stubs. */
|
|
29
|
+
readonly client: GrpcLikeHealthClient;
|
|
30
|
+
/** The service name to check. Default `grpcDefaultService`. */
|
|
31
|
+
readonly service?: string;
|
|
32
|
+
}
|
|
33
|
+
/** A probe that calls `Health/Check` and expects `SERVING`; non-critical by default. Throws `ProbeConfigError` without `check()` or for a non-string `service`. */
|
|
34
|
+
declare function grpcProbe(options: GrpcProbeOptions): Probe;
|
|
35
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
36
|
+
//#endregion
|
|
37
|
+
export { GrpcHealthCheckResponse, GrpcLikeCall, GrpcLikeHealthClient, GrpcProbeOptions, grpcDefaultName, grpcDefaultService, grpcProbe };
|
|
38
|
+
//# sourceMappingURL=mod.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.cts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AAoDmB,cA/BN,eAAA,GA+BM,MAAA;;AAFqC,cA3B3C,kBAAA,GA2B2C,EAAA;AAQxD;AAAyB,UAhCR,uBAAA,CAgCQ;EAAA;EAA0B,SAAG,MAAA,CAAA,EAAA,MAAA,GAAA,MAAA;AAAK;;UA1B1C,YAAA;;;;;UAMA,oBAAA;;;;uBAKJ,yBACI,mCAEZ;;;UAIY,gBAAA,SAAyB;;mBAEvB;;;;;iBAMH,SAAA,UAAmB,mBAAmB"}
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Probe, ProbeOverrides } from "@openstatus/health";
|
|
2
|
+
|
|
3
|
+
//#region src/mod.d.ts
|
|
4
|
+
|
|
5
|
+
/** Probe name when `name` is unset. */
|
|
6
|
+
declare const grpcDefaultName = "grpc";
|
|
7
|
+
/** Service checked when `service` is unset: the empty string means the server as a whole. */
|
|
8
|
+
declare const grpcDefaultService = "";
|
|
9
|
+
/** What `Check` answers; `status` is `1` or `"SERVING"` when healthy, depending on how enums were loaded. */
|
|
10
|
+
interface GrpcHealthCheckResponse {
|
|
11
|
+
/** The `ServingStatus` enum value. */
|
|
12
|
+
readonly status?: number | string;
|
|
13
|
+
}
|
|
14
|
+
/** The subset of a `ClientUnaryCall` the probe uses. */
|
|
15
|
+
interface GrpcLikeCall {
|
|
16
|
+
/** Cancel the in-flight call. */
|
|
17
|
+
cancel(): void;
|
|
18
|
+
}
|
|
19
|
+
/** The subset of a generated `Health` client the probe uses. */
|
|
20
|
+
interface GrpcLikeHealthClient {
|
|
21
|
+
/** Call `Health/Check` for `service`. */
|
|
22
|
+
check(request: {
|
|
23
|
+
readonly service: string;
|
|
24
|
+
}, callback: (error: Error | null, response?: GrpcHealthCheckResponse) => void): GrpcLikeCall;
|
|
25
|
+
}
|
|
26
|
+
/** Options for `grpcProbe()`. */
|
|
27
|
+
interface GrpcProbeOptions extends ProbeOverrides {
|
|
28
|
+
/** A `grpc.health.v1.Health` client, e.g. from `grpc-health-check` or your generated stubs. */
|
|
29
|
+
readonly client: GrpcLikeHealthClient;
|
|
30
|
+
/** The service name to check. Default `grpcDefaultService`. */
|
|
31
|
+
readonly service?: string;
|
|
32
|
+
}
|
|
33
|
+
/** A probe that calls `Health/Check` and expects `SERVING`; non-critical by default. Throws `ProbeConfigError` without `check()` or for a non-string `service`. */
|
|
34
|
+
declare function grpcProbe(options: GrpcProbeOptions): Probe;
|
|
35
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
36
|
+
//#endregion
|
|
37
|
+
export { GrpcHealthCheckResponse, GrpcLikeCall, GrpcLikeHealthClient, GrpcProbeOptions, grpcDefaultName, grpcDefaultService, grpcProbe };
|
|
38
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AAoDmB,cA/BN,eAAA,GA+BM,MAAA;;AAFqC,cA3B3C,kBAAA,GA2B2C,EAAA;AAQxD;AAAyB,UAhCR,uBAAA,CAgCQ;EAAA;EAA0B,SAAG,MAAA,CAAA,EAAA,MAAA,GAAA,MAAA;AAAK;;UA1B1C,YAAA;;;;;UAMA,oBAAA;;;;uBAKJ,yBACI,mCAEZ;;;UAIY,gBAAA,SAAyB;;mBAEvB;;;;;iBAMH,SAAA,UAAmB,mBAAmB"}
|
package/dist/mod.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ProbeConfigError } from "@openstatus/health";
|
|
2
|
+
|
|
3
|
+
//#region src/mod.ts
|
|
4
|
+
/** Probe name when `name` is unset. */
|
|
5
|
+
const grpcDefaultName = "grpc";
|
|
6
|
+
/** Service checked when `service` is unset: the empty string means the server as a whole. */
|
|
7
|
+
const grpcDefaultService = "";
|
|
8
|
+
/** A probe that calls `Health/Check` and expects `SERVING`; non-critical by default. Throws `ProbeConfigError` without `check()` or for a non-string `service`. */
|
|
9
|
+
function grpcProbe(options) {
|
|
10
|
+
const client = options.client;
|
|
11
|
+
if (typeof client?.check !== "function") throw new ProbeConfigError("grpcProbe", "client", `must expose check(), got ${describe(client)}`);
|
|
12
|
+
const service = options.service === void 0 ? grpcDefaultService : options.service;
|
|
13
|
+
if (typeof service !== "string") throw new ProbeConfigError("grpcProbe", "service", `must be a string, got ${String(service)}`);
|
|
14
|
+
return {
|
|
15
|
+
name: options.name ?? grpcDefaultName,
|
|
16
|
+
critical: options.critical ?? false,
|
|
17
|
+
timeoutMs: options.timeoutMs,
|
|
18
|
+
skip: options.skip,
|
|
19
|
+
run: (signal) => new Promise((resolve, reject) => {
|
|
20
|
+
signal.throwIfAborted();
|
|
21
|
+
const onAbort = () => {
|
|
22
|
+
call.cancel();
|
|
23
|
+
reject(signal.reason);
|
|
24
|
+
};
|
|
25
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
26
|
+
const call = client.check({ service }, (error, response) => {
|
|
27
|
+
signal.removeEventListener("abort", onAbort);
|
|
28
|
+
if (error != null) {
|
|
29
|
+
reject(error);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const status = response?.status;
|
|
33
|
+
if (status === 1 || status === "SERVING") {
|
|
34
|
+
resolve();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
reject(/* @__PURE__ */ new Error(`serving status ${describeStatus(status)}`));
|
|
38
|
+
});
|
|
39
|
+
})
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function describeStatus(status) {
|
|
43
|
+
if (status === 0 || status === "UNKNOWN") return "UNKNOWN";
|
|
44
|
+
if (status === 2 || status === "NOT_SERVING") return "NOT_SERVING";
|
|
45
|
+
if (status === 3 || status === "SERVICE_UNKNOWN") return "SERVICE_UNKNOWN";
|
|
46
|
+
return String(status);
|
|
47
|
+
}
|
|
48
|
+
function describe(client) {
|
|
49
|
+
if (client == null) return String(client);
|
|
50
|
+
if (typeof client !== "object") return typeof client;
|
|
51
|
+
const keys = Object.keys(client);
|
|
52
|
+
return keys.length === 0 ? "an object with no keys" : `an object with keys ${keys.slice(0, 8).join(", ")}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
export { grpcDefaultName, grpcDefaultService, grpcProbe };
|
|
57
|
+
//# sourceMappingURL=mod.js.map
|
package/dist/mod.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","names":["options: GrpcProbeOptions","status: number | string | undefined","client: GrpcLikeHealthClient"],"sources":["../src/mod.ts"],"sourcesContent":["/**\n * gRPC probe for `@openstatus/health`: calls `grpc.health.v1.Health/Check`\n * through a generated `@grpc/grpc-js` health client and expects `SERVING`.\n *\n * ```ts\n * import { HealthClient } from \"grpc-health-check\";\n * import { grpcProbe } from \"@openstatus/health-grpc\";\n *\n * const probe = grpcProbe({ client: new HealthClient(address, credentials) });\n * ```\n *\n * @module\n */\n\nimport {\n type Probe,\n ProbeConfigError,\n type ProbeOverrides,\n} from \"@openstatus/health\";\n\n/** Probe name when `name` is unset. */\nexport const grpcDefaultName = \"grpc\";\n/** Service checked when `service` is unset: the empty string means the server as a whole. */\nexport const grpcDefaultService = \"\";\n\n/** What `Check` answers; `status` is `1` or `\"SERVING\"` when healthy, depending on how enums were loaded. */\nexport interface GrpcHealthCheckResponse {\n /** The `ServingStatus` enum value. */\n readonly status?: number | string;\n}\n\n/** The subset of a `ClientUnaryCall` the probe uses. */\nexport interface GrpcLikeCall {\n /** Cancel the in-flight call. */\n cancel(): void;\n}\n\n/** The subset of a generated `Health` client the probe uses. */\nexport interface GrpcLikeHealthClient {\n /** Call `Health/Check` for `service`. */\n check(\n request: { readonly service: string },\n callback: (\n error: Error | null,\n response?: GrpcHealthCheckResponse,\n ) => void,\n ): GrpcLikeCall;\n}\n\n/** Options for `grpcProbe()`. */\nexport interface GrpcProbeOptions extends ProbeOverrides {\n /** A `grpc.health.v1.Health` client, e.g. from `grpc-health-check` or your generated stubs. */\n readonly client: GrpcLikeHealthClient;\n /** The service name to check. Default `grpcDefaultService`. */\n readonly service?: string;\n}\n\n/** A probe that calls `Health/Check` and expects `SERVING`; non-critical by default. Throws `ProbeConfigError` without `check()` or for a non-string `service`. */\nexport function grpcProbe(options: GrpcProbeOptions): Probe {\n const client = options.client;\n if (typeof client?.check !== \"function\") {\n throw new ProbeConfigError(\n \"grpcProbe\",\n \"client\",\n `must expose check(), got ${describe(client)}`,\n );\n }\n const service = options.service === undefined\n ? grpcDefaultService\n : options.service;\n if (typeof service !== \"string\") {\n throw new ProbeConfigError(\n \"grpcProbe\",\n \"service\",\n `must be a string, got ${String(service)}`,\n );\n }\n return {\n name: options.name ?? grpcDefaultName,\n critical: options.critical ?? false,\n timeoutMs: options.timeoutMs,\n skip: options.skip,\n run: (signal) =>\n new Promise<void>((resolve, reject) => {\n signal.throwIfAborted();\n const onAbort = () => {\n call.cancel();\n reject(signal.reason);\n };\n signal.addEventListener(\"abort\", onAbort, { once: true });\n const call = client.check({ service }, (error, response) => {\n signal.removeEventListener(\"abort\", onAbort);\n if (error != null) {\n reject(error);\n return;\n }\n const status = response?.status;\n if (status === 1 || status === \"SERVING\") {\n resolve();\n return;\n }\n reject(new Error(`serving status ${describeStatus(status)}`));\n });\n }),\n };\n}\n\nfunction describeStatus(status: number | string | undefined): string {\n if (status === 0 || status === \"UNKNOWN\") return \"UNKNOWN\";\n if (status === 2 || status === \"NOT_SERVING\") return \"NOT_SERVING\";\n if (status === 3 || status === \"SERVICE_UNKNOWN\") return \"SERVICE_UNKNOWN\";\n return String(status);\n}\n\nfunction describe(client: GrpcLikeHealthClient): string {\n if (client == null) return String(client);\n if (typeof client !== \"object\") return typeof client;\n const keys = Object.keys(client);\n return keys.length === 0\n ? \"an object with no keys\"\n : `an object with keys ${keys.slice(0, 8).join(\", \")}`;\n}\n"],"mappings":";;;;AAqBA,MAAa,kBAAkB;;AAE/B,MAAa,qBAAqB;;AAmClC,SAAgB,UAAUA,SAAkC;CAC1D,MAAM,SAAS,QAAQ;AACvB,YAAW,QAAQ,UAAU,WAC3B,OAAM,IAAI,iBACR,aACA,WACC,2BAA2B,SAAS,OAAO,CAAC;CAGjD,MAAM,UAAU,QAAQ,qBACpB,qBACA,QAAQ;AACZ,YAAW,YAAY,SACrB,OAAM,IAAI,iBACR,aACA,YACC,wBAAwB,OAAO,QAAQ,CAAC;AAG7C,QAAO;EACL,MAAM,QAAQ,QAAQ;EACtB,UAAU,QAAQ,YAAY;EAC9B,WAAW,QAAQ;EACnB,MAAM,QAAQ;EACd,KAAK,CAAC,WACJ,IAAI,QAAc,CAAC,SAAS,WAAW;AACrC,UAAO,gBAAgB;GACvB,MAAM,UAAU,MAAM;AACpB,SAAK,QAAQ;AACb,WAAO,OAAO,OAAO;GACtB;AACD,UAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAM,EAAC;GACzD,MAAM,OAAO,OAAO,MAAM,EAAE,QAAS,GAAE,CAAC,OAAO,aAAa;AAC1D,WAAO,oBAAoB,SAAS,QAAQ;AAC5C,QAAI,SAAS,MAAM;AACjB,YAAO,MAAM;AACb;IACD;IACD,MAAM,SAAS,UAAU;AACzB,QAAI,WAAW,KAAK,WAAW,WAAW;AACxC,cAAS;AACT;IACD;AACD,2BAAO,IAAI,OAAO,iBAAiB,eAAe,OAAO,CAAC,GAAG;GAC9D,EAAC;EACH;CACJ;AACF;AAED,SAAS,eAAeC,QAA6C;AACnE,KAAI,WAAW,KAAK,WAAW,UAAW,QAAO;AACjD,KAAI,WAAW,KAAK,WAAW,cAAe,QAAO;AACrD,KAAI,WAAW,KAAK,WAAW,kBAAmB,QAAO;AACzD,QAAO,OAAO,OAAO;AACtB;AAED,SAAS,SAASC,QAAsC;AACtD,KAAI,UAAU,KAAM,QAAO,OAAO,OAAO;AACzC,YAAW,WAAW,SAAU,eAAc;CAC9C,MAAM,OAAO,OAAO,KAAK,OAAO;AAChC,QAAO,KAAK,WAAW,IACnB,4BACC,sBAAsB,KAAK,MAAM,GAAG,EAAE,CAAC,KAAK,KAAK,CAAC;AACxD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openstatus/health-grpc",
|
|
3
|
+
"version": "0.1.4-dev.0",
|
|
4
|
+
"description": "gRPC health check probe for @openstatus/health",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"openstatus",
|
|
7
|
+
"health",
|
|
8
|
+
"healthcheck",
|
|
9
|
+
"grpc",
|
|
10
|
+
"grpc-js",
|
|
11
|
+
"health-check"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": {
|
|
15
|
+
"name": "openstatus",
|
|
16
|
+
"url": "https://www.openstatus.dev/"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/openstatusHQ/health",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/openstatusHQ/health.git",
|
|
22
|
+
"directory": "packages/grpc/"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/openstatusHQ/health/issues"
|
|
26
|
+
},
|
|
27
|
+
"type": "module",
|
|
28
|
+
"module": "./dist/mod.js",
|
|
29
|
+
"main": "./dist/mod.cjs",
|
|
30
|
+
"types": "./dist/mod.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": {
|
|
34
|
+
"import": "./dist/mod.d.ts",
|
|
35
|
+
"require": "./dist/mod.d.cts"
|
|
36
|
+
},
|
|
37
|
+
"import": "./dist/mod.js",
|
|
38
|
+
"require": "./dist/mod.cjs"
|
|
39
|
+
},
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"sideEffects": false,
|
|
43
|
+
"files": [
|
|
44
|
+
"dist/"
|
|
45
|
+
],
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=22"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@openstatus/health": "^0.1.4-dev.0",
|
|
51
|
+
"@grpc/grpc-js": ">=1.0.0"
|
|
52
|
+
},
|
|
53
|
+
"peerDependenciesMeta": {
|
|
54
|
+
"@grpc/grpc-js": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"tsdown": "^0.12.7",
|
|
60
|
+
"typescript": "^5.8.3"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "tsdown",
|
|
64
|
+
"prepack": "tsdown",
|
|
65
|
+
"test": "node --experimental-transform-types --test"
|
|
66
|
+
}
|
|
67
|
+
}
|