@openstatus/health-mongodb 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 ADDED
@@ -0,0 +1,70 @@
1
+ # @openstatus/health-mongodb
2
+
3
+ [MongoDB](https://www.mongodb.com/) probe for
4
+ [`@openstatus/health`](https://jsr.io/@openstatus/health). Runs the
5
+ [`ping`](https://www.mongodb.com/docs/manual/reference/command/ping/) command
6
+ through the official [`mongodb`](https://github.com/mongodb/node-mongodb-native)
7
+ driver and fails the check when the server does not answer.
8
+
9
+ ```sh
10
+ deno add jsr:@openstatus/health jsr:@openstatus/health-mongodb
11
+ npm install @openstatus/health @openstatus/health-mongodb
12
+ ```
13
+
14
+ ```ts
15
+ import { MongoClient } from "mongodb";
16
+ import { createHealthHandler } from "@openstatus/health";
17
+ import { mongodbProbe } from "@openstatus/health-mongodb";
18
+
19
+ const client = new MongoClient(env.MONGODB_URI);
20
+
21
+ Deno.serve(
22
+ createHealthHandler({ probes: [mongodbProbe({ client })] }),
23
+ );
24
+ ```
25
+
26
+ `ping` is the command MongoDB recommends for connectivity checks: it needs
27
+ no privileges beyond being authenticated, touches no collection and returns
28
+ as soon as the server selected by the driver responds. It runs against the
29
+ `admin` database by default; pass `db` to send the command to the database
30
+ your application uses. Note that `ping` does not verify the credentials can
31
+ read or write that database's collections.
32
+
33
+ ```ts
34
+ mongodbProbe({
35
+ client,
36
+ db: "app",
37
+ // optional overrides from the Probe contract
38
+ name: "mongo",
39
+ critical: false,
40
+ timeoutMs: 2000,
41
+ skip: () => env.MONGODB_URI == null,
42
+ });
43
+ ```
44
+
45
+ Critical by default: a MongoDB that does not answer usually means requests
46
+ cannot be served, so the report turns `unhealthy` and the instance is taken
47
+ out of rotation. Set `critical: false` for a secondary or analytics cluster.
48
+
49
+ The client is typed structurally as `{ db(name?): { command({ ping: 1 }) } }`,
50
+ so `mongodb` is an optional peer dependency for its types only and the probe
51
+ adds no runtime import of it. The factory throws `ProbeConfigError` at
52
+ construction when the client has no `db()`.
53
+
54
+ ## About openstatus
55
+
56
+ [openstatus](https://www.openstatus.dev/) is the open-source uptime monitoring
57
+ and status page platform. This package is part of
58
+ [`@openstatus/health`](https://github.com/openstatusHQ/health), the `/health`
59
+ endpoints behind openstatus's own services, extracted so any JavaScript server
60
+ can expose one. Point an
61
+ [openstatus monitor](https://www.openstatus.dev/docs/reference/http-monitor)
62
+ at the endpoint and assert on `status` in the body to be alerted on
63
+ `degraded` before it becomes `unhealthy`.
64
+
65
+ Source: [github.com/openstatusHQ/health](https://github.com/openstatusHQ/health).
66
+ Issues and PRs welcome.
67
+
68
+ ## License
69
+
70
+ [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,34 @@
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 mongodbDefaultName = "database";
7
+ /** Database the `ping` command runs against when `db` is unset. */
8
+ const mongodbDefaultDb = "admin";
9
+ /** A probe that runs `{ ping: 1 }`; critical by default. Throws `ProbeConfigError` without `db()`. */
10
+ function mongodbProbe(options) {
11
+ const client = options.client;
12
+ if (typeof client?.db !== "function") throw new __openstatus_health.ProbeConfigError("mongodbProbe", "client", `must expose db(), got ${describe(client)}`);
13
+ const dbName = options.db ?? mongodbDefaultDb;
14
+ return {
15
+ name: options.name ?? mongodbDefaultName,
16
+ critical: options.critical ?? true,
17
+ timeoutMs: options.timeoutMs,
18
+ skip: options.skip,
19
+ run: async (signal) => {
20
+ await client.db(dbName).command({ ping: 1 }, { signal });
21
+ }
22
+ };
23
+ }
24
+ function describe(client) {
25
+ if (client == null) return String(client);
26
+ if (typeof client !== "object") return typeof client;
27
+ const keys = Object.keys(client);
28
+ return keys.length === 0 ? "an object with no keys" : `an object with keys ${keys.slice(0, 8).join(", ")}`;
29
+ }
30
+
31
+ //#endregion
32
+ exports.mongodbDefaultDb = mongodbDefaultDb;
33
+ exports.mongodbDefaultName = mongodbDefaultName;
34
+ exports.mongodbProbe = mongodbProbe;
package/dist/mod.d.cts ADDED
@@ -0,0 +1,38 @@
1
+ import { Probe, ProbeOverrides, ProbeResult } from "@openstatus/health";
2
+
3
+ //#region src/mod.d.ts
4
+
5
+ /** Probe name when `name` is unset. */
6
+ declare const mongodbDefaultName = "database";
7
+ /** Database the `ping` command runs against when `db` is unset. */
8
+ declare const mongodbDefaultDb = "admin";
9
+ /** What the probe passes to `command()`. */
10
+ interface MongoCommandOptions {
11
+ /** Aborts when the probe times out. */
12
+ readonly signal?: AbortSignal;
13
+ }
14
+ /** The subset of a `mongodb` `Db` the probe uses. */
15
+ interface MongoLikeDb {
16
+ /** Run a database command. */
17
+ command(command: {
18
+ readonly ping: 1;
19
+ }, options?: MongoCommandOptions): PromiseLike<ProbeResult>;
20
+ }
21
+ /** The subset of a `MongoClient` the probe uses. */
22
+ interface MongoLikeClient {
23
+ /** Select a database. */
24
+ db(name?: string): MongoLikeDb;
25
+ }
26
+ /** Options for `mongodbProbe()`. */
27
+ interface MongodbProbeOptions extends ProbeOverrides {
28
+ /** A `MongoClient`. */
29
+ readonly client: MongoLikeClient;
30
+ /** Database to run `ping` on. Default `mongodbDefaultDb`. */
31
+ readonly db?: string;
32
+ }
33
+ /** A probe that runs `{ ping: 1 }`; critical by default. Throws `ProbeConfigError` without `db()`. */
34
+ declare function mongodbProbe(options: MongodbProbeOptions): Probe;
35
+ //# sourceMappingURL=mod.d.ts.map
36
+ //#endregion
37
+ export { MongoCommandOptions, MongoLikeClient, MongoLikeDb, MongodbProbeOptions, mongodbDefaultDb, mongodbDefaultName, mongodbProbe };
38
+ //# sourceMappingURL=mod.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.cts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AAkDmB,cA5BN,kBAAA,GA4BM,UAAA;;AAFwC,cAxB9C,gBAAA,GAwB8C,OAAA;AAQ3D;AAA4B,UA7BX,mBAAA,CA6BW;EAAA;EAA6B,SAAG,MAAA,CAAA,EA3BxC,WA2BwC;AAAK;;UAvBhD,WAAA;;;;eAIH,sBACT,YAAY;;;UAIA,eAAA;;qBAEI;;;UAIJ,mBAAA,SAA4B;;mBAE1B;;;;;iBAMH,YAAA,UAAsB,sBAAsB"}
package/dist/mod.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ import { Probe, ProbeOverrides, ProbeResult } from "@openstatus/health";
2
+
3
+ //#region src/mod.d.ts
4
+
5
+ /** Probe name when `name` is unset. */
6
+ declare const mongodbDefaultName = "database";
7
+ /** Database the `ping` command runs against when `db` is unset. */
8
+ declare const mongodbDefaultDb = "admin";
9
+ /** What the probe passes to `command()`. */
10
+ interface MongoCommandOptions {
11
+ /** Aborts when the probe times out. */
12
+ readonly signal?: AbortSignal;
13
+ }
14
+ /** The subset of a `mongodb` `Db` the probe uses. */
15
+ interface MongoLikeDb {
16
+ /** Run a database command. */
17
+ command(command: {
18
+ readonly ping: 1;
19
+ }, options?: MongoCommandOptions): PromiseLike<ProbeResult>;
20
+ }
21
+ /** The subset of a `MongoClient` the probe uses. */
22
+ interface MongoLikeClient {
23
+ /** Select a database. */
24
+ db(name?: string): MongoLikeDb;
25
+ }
26
+ /** Options for `mongodbProbe()`. */
27
+ interface MongodbProbeOptions extends ProbeOverrides {
28
+ /** A `MongoClient`. */
29
+ readonly client: MongoLikeClient;
30
+ /** Database to run `ping` on. Default `mongodbDefaultDb`. */
31
+ readonly db?: string;
32
+ }
33
+ /** A probe that runs `{ ping: 1 }`; critical by default. Throws `ProbeConfigError` without `db()`. */
34
+ declare function mongodbProbe(options: MongodbProbeOptions): Probe;
35
+ //# sourceMappingURL=mod.d.ts.map
36
+ //#endregion
37
+ export { MongoCommandOptions, MongoLikeClient, MongoLikeDb, MongodbProbeOptions, mongodbDefaultDb, mongodbDefaultName, mongodbProbe };
38
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AAkDmB,cA5BN,kBAAA,GA4BM,UAAA;;AAFwC,cAxB9C,gBAAA,GAwB8C,OAAA;AAQ3D;AAA4B,UA7BX,mBAAA,CA6BW;EAAA;EAA6B,SAAG,MAAA,CAAA,EA3BxC,WA2BwC;AAAK;;UAvBhD,WAAA;;;;eAIH,sBACT,YAAY;;;UAIA,eAAA;;qBAEI;;;UAIJ,mBAAA,SAA4B;;mBAE1B;;;;;iBAMH,YAAA,UAAsB,sBAAsB"}
package/dist/mod.js ADDED
@@ -0,0 +1,32 @@
1
+ import { ProbeConfigError } from "@openstatus/health";
2
+
3
+ //#region src/mod.ts
4
+ /** Probe name when `name` is unset. */
5
+ const mongodbDefaultName = "database";
6
+ /** Database the `ping` command runs against when `db` is unset. */
7
+ const mongodbDefaultDb = "admin";
8
+ /** A probe that runs `{ ping: 1 }`; critical by default. Throws `ProbeConfigError` without `db()`. */
9
+ function mongodbProbe(options) {
10
+ const client = options.client;
11
+ if (typeof client?.db !== "function") throw new ProbeConfigError("mongodbProbe", "client", `must expose db(), got ${describe(client)}`);
12
+ const dbName = options.db ?? mongodbDefaultDb;
13
+ return {
14
+ name: options.name ?? mongodbDefaultName,
15
+ critical: options.critical ?? true,
16
+ timeoutMs: options.timeoutMs,
17
+ skip: options.skip,
18
+ run: async (signal) => {
19
+ await client.db(dbName).command({ ping: 1 }, { signal });
20
+ }
21
+ };
22
+ }
23
+ function describe(client) {
24
+ if (client == null) return String(client);
25
+ if (typeof client !== "object") return typeof client;
26
+ const keys = Object.keys(client);
27
+ return keys.length === 0 ? "an object with no keys" : `an object with keys ${keys.slice(0, 8).join(", ")}`;
28
+ }
29
+
30
+ //#endregion
31
+ export { mongodbDefaultDb, mongodbDefaultName, mongodbProbe };
32
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","names":["options: MongodbProbeOptions","client: MongoLikeClient"],"sources":["../src/mod.ts"],"sourcesContent":["/**\n * MongoDB probe for `@openstatus/health`: runs the `ping` command through the\n * official `mongodb` driver.\n *\n * ```ts\n * import { MongoClient } from \"mongodb\";\n * import { mongodbProbe } from \"@openstatus/health-mongodb\";\n *\n * const probe = mongodbProbe({ client: new MongoClient(env.MONGODB_URI) });\n * ```\n *\n * @module\n */\n\nimport {\n type Probe,\n ProbeConfigError,\n type ProbeOverrides,\n type ProbeResult,\n} from \"@openstatus/health\";\n\n/** Probe name when `name` is unset. */\nexport const mongodbDefaultName = \"database\";\n/** Database the `ping` command runs against when `db` is unset. */\nexport const mongodbDefaultDb = \"admin\";\n\n/** What the probe passes to `command()`. */\nexport interface MongoCommandOptions {\n /** Aborts when the probe times out. */\n readonly signal?: AbortSignal;\n}\n\n/** The subset of a `mongodb` `Db` the probe uses. */\nexport interface MongoLikeDb {\n /** Run a database command. */\n command(\n command: { readonly ping: 1 },\n options?: MongoCommandOptions,\n ): PromiseLike<ProbeResult>;\n}\n\n/** The subset of a `MongoClient` the probe uses. */\nexport interface MongoLikeClient {\n /** Select a database. */\n db(name?: string): MongoLikeDb;\n}\n\n/** Options for `mongodbProbe()`. */\nexport interface MongodbProbeOptions extends ProbeOverrides {\n /** A `MongoClient`. */\n readonly client: MongoLikeClient;\n /** Database to run `ping` on. Default `mongodbDefaultDb`. */\n readonly db?: string;\n}\n\n/** A probe that runs `{ ping: 1 }`; critical by default. Throws `ProbeConfigError` without `db()`. */\nexport function mongodbProbe(options: MongodbProbeOptions): Probe {\n const client = options.client;\n if (typeof client?.db !== \"function\") {\n throw new ProbeConfigError(\n \"mongodbProbe\",\n \"client\",\n `must expose db(), got ${describe(client)}`,\n );\n }\n const dbName = options.db ?? mongodbDefaultDb;\n return {\n name: options.name ?? mongodbDefaultName,\n critical: options.critical ?? true,\n timeoutMs: options.timeoutMs,\n skip: options.skip,\n run: async (signal) => {\n await client.db(dbName).command({ ping: 1 }, { signal });\n },\n };\n}\n\nfunction describe(client: MongoLikeClient): 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":";;;;AAsBA,MAAa,qBAAqB;;AAElC,MAAa,mBAAmB;;AAgChC,SAAgB,aAAaA,SAAqC;CAChE,MAAM,SAAS,QAAQ;AACvB,YAAW,QAAQ,OAAO,WACxB,OAAM,IAAI,iBACR,gBACA,WACC,wBAAwB,SAAS,OAAO,CAAC;CAG9C,MAAM,SAAS,QAAQ,MAAM;AAC7B,QAAO;EACL,MAAM,QAAQ,QAAQ;EACtB,UAAU,QAAQ,YAAY;EAC9B,WAAW,QAAQ;EACnB,MAAM,QAAQ;EACd,KAAK,OAAO,WAAW;AACrB,SAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAG,GAAE,EAAE,OAAQ,EAAC;EACzD;CACF;AACF;AAED,SAAS,SAASC,QAAiC;AACjD,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,68 @@
1
+ {
2
+ "name": "@openstatus/health-mongodb",
3
+ "version": "0.1.4-dev.0",
4
+ "description": "MongoDB ping probe for @openstatus/health",
5
+ "keywords": [
6
+ "openstatus",
7
+ "health",
8
+ "healthcheck",
9
+ "mongodb",
10
+ "mongo",
11
+ "database"
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/mongodb/"
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
+ "mongodb": ">=5.0.0"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "mongodb": {
55
+ "optional": true
56
+ }
57
+ },
58
+ "devDependencies": {
59
+ "mongodb": "^6.17.0",
60
+ "tsdown": "^0.12.7",
61
+ "typescript": "^5.8.3"
62
+ },
63
+ "scripts": {
64
+ "build": "tsdown",
65
+ "prepack": "tsdown",
66
+ "test": "node --experimental-transform-types --test"
67
+ }
68
+ }