@openstatus/health-prisma 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,85 @@
1
+ # @openstatus/health-prisma
2
+
3
+ [Prisma](https://www.prisma.io/) probe for
4
+ [`@openstatus/health`](https://jsr.io/@openstatus/health). Runs `select 1`
5
+ through `$queryRawUnsafe()` on every SQL connector — or the `ping` command
6
+ through `$runCommandRaw()` when `connector` is `"mongodb"` — and fails the
7
+ check when the round trip does.
8
+
9
+ ```sh
10
+ deno add jsr:@openstatus/health jsr:@openstatus/health-prisma
11
+ npm install @openstatus/health @openstatus/health-prisma
12
+ ```
13
+
14
+ ```ts
15
+ import { PrismaClient } from "@prisma/client";
16
+ import { createHealthHandler } from "@openstatus/health";
17
+ import { prismaProbe } from "@openstatus/health-prisma";
18
+
19
+ const prisma = new PrismaClient();
20
+
21
+ Deno.serve(
22
+ createHealthHandler({ probes: [prismaProbe({ client: prisma })] }),
23
+ );
24
+ ```
25
+
26
+ `connector` selects the call; it defaults to `"sql"`:
27
+
28
+ | `connector` | Connectors | Call |
29
+ | ----------- | ---------- | ---- |
30
+ | `"sql"` | PostgreSQL, MySQL, SQLite, SQL Server, CockroachDB | `client.$queryRawUnsafe("select 1")` |
31
+ | `"mongodb"` | MongoDB | `client.$runCommandRaw({ ping: 1 })` |
32
+
33
+ The choice is explicit rather than detected because Prisma's runtime defines
34
+ both methods on every generated client and only its type declarations hide
35
+ the one your connector does not support, so a MongoDB client would otherwise
36
+ be sent SQL.
37
+
38
+ `$queryRawUnsafe` is used with a constant string only — nothing from the
39
+ request reaches it — and is the raw entry point that takes a plain string
40
+ rather than a tagged template. Prisma opens its connection pool lazily on the
41
+ first query, so the first probe after start-up also pays for the connect.
42
+ Prisma's raw APIs take no `AbortSignal`, so a query that outlives
43
+ `timeoutMs` is reported as `timeout` but keeps its pooled connection busy
44
+ until the database answers; set a server-side statement timeout on the
45
+ database user if that matters.
46
+
47
+ ```ts
48
+ prismaProbe({
49
+ client: prisma,
50
+ connector: "mongodb",
51
+ // optional overrides from the Probe contract
52
+ name: "primary",
53
+ critical: false,
54
+ timeoutMs: 2000,
55
+ skip: () => env.DATABASE_URL == null,
56
+ });
57
+ ```
58
+
59
+ Critical by default: a database that does not answer usually means requests
60
+ cannot be served, so the report turns `unhealthy` and the instance is taken
61
+ out of rotation. Set `critical: false` for a replica or reporting database.
62
+
63
+ The client is typed structurally as `{ $queryRawUnsafe(query) }` or
64
+ `{ $runCommandRaw(command) }`, so `@prisma/client` is an optional peer
65
+ dependency for its types only and the probe adds no runtime import of it.
66
+ The factory throws `ProbeConfigError` at construction when the client lacks
67
+ the method for the chosen `connector`.
68
+
69
+ ## About openstatus
70
+
71
+ [openstatus](https://www.openstatus.dev/) is the open-source uptime monitoring
72
+ and status page platform. This package is part of
73
+ [`@openstatus/health`](https://github.com/openstatusHQ/health), the `/health`
74
+ endpoints behind openstatus's own services, extracted so any JavaScript server
75
+ can expose one. Point an
76
+ [openstatus monitor](https://www.openstatus.dev/docs/reference/http-monitor)
77
+ at the endpoint and assert on `status` in the body to be alerted on
78
+ `degraded` before it becomes `unhealthy`.
79
+
80
+ Source: [github.com/openstatusHQ/health](https://github.com/openstatusHQ/health).
81
+ Issues and PRs welcome.
82
+
83
+ ## License
84
+
85
+ [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,37 @@
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 prismaDefaultName = "database";
7
+ /** Connector when `connector` is unset. */
8
+ const prismaDefaultConnector = "sql";
9
+ /** A probe that runs `select 1` or, on MongoDB, `{ ping: 1 }`; critical by default. Throws `ProbeConfigError` when the client lacks the method for `connector`. */
10
+ function prismaProbe(options) {
11
+ const client = options.client;
12
+ const connector = options.connector ?? prismaDefaultConnector;
13
+ if (connector !== "sql" && connector !== "mongodb") throw new __openstatus_health.ProbeConfigError("prismaProbe", "connector", `must be "sql" or "mongodb", got ${String(connector)}`);
14
+ const method = connector === "mongodb" ? "$runCommandRaw" : "$queryRawUnsafe";
15
+ if (typeof client?.[method] !== "function") throw new __openstatus_health.ProbeConfigError("prismaProbe", "client", `must expose ${method}() for the ${connector} connector, got ${describe(client)}`);
16
+ const run = connector === "mongodb" ? () => client.$runCommandRaw({ ping: 1 }) : () => client.$queryRawUnsafe("select 1");
17
+ return {
18
+ name: options.name ?? prismaDefaultName,
19
+ critical: options.critical ?? true,
20
+ timeoutMs: options.timeoutMs,
21
+ skip: options.skip,
22
+ run: async () => {
23
+ await run();
24
+ }
25
+ };
26
+ }
27
+ function describe(client) {
28
+ if (client == null) return String(client);
29
+ if (typeof client !== "object") return typeof client;
30
+ const keys = Object.keys(client);
31
+ return keys.length === 0 ? "an object with no keys" : `an object with keys ${keys.slice(0, 8).join(", ")}`;
32
+ }
33
+
34
+ //#endregion
35
+ exports.prismaDefaultConnector = prismaDefaultConnector;
36
+ exports.prismaDefaultName = prismaDefaultName;
37
+ exports.prismaProbe = prismaProbe;
package/dist/mod.d.cts ADDED
@@ -0,0 +1,32 @@
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 prismaDefaultName = "database";
7
+ /** Connector when `connector` is unset. */
8
+ declare const prismaDefaultConnector = "sql";
9
+ /** Which raw entry point the probe calls. */
10
+ type PrismaConnector = "sql" | "mongodb";
11
+ /** The subset of a `PrismaClient` the probe uses; the method for the chosen `connector` must exist. */
12
+ interface PrismaLikeClient {
13
+ /** SQL connectors. */
14
+ $queryRawUnsafe?(query: string): PromiseLike<ProbeResult>;
15
+ /** The MongoDB connector. */
16
+ $runCommandRaw?(command: {
17
+ readonly ping: 1;
18
+ }): PromiseLike<ProbeResult>;
19
+ }
20
+ /** Options for `prismaProbe()`. */
21
+ interface PrismaProbeOptions extends ProbeOverrides {
22
+ /** A generated `PrismaClient`. */
23
+ readonly client: PrismaLikeClient;
24
+ /** `"mongodb"` calls `$runCommandRaw()`; anything else calls `$queryRawUnsafe()`. Default `prismaDefaultConnector`. */
25
+ readonly connector?: PrismaConnector;
26
+ }
27
+ /** A probe that runs `select 1` or, on MongoDB, `{ ping: 1 }`; critical by default. Throws `ProbeConfigError` when the client lacks the method for `connector`. */
28
+ declare function prismaProbe(options: PrismaProbeOptions): Probe;
29
+ //# sourceMappingURL=mod.d.ts.map
30
+ //#endregion
31
+ export { PrismaConnector, PrismaLikeClient, PrismaProbeOptions, prismaDefaultConnector, prismaDefaultName, prismaProbe };
32
+ //# sourceMappingURL=mod.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.cts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AAwC4C,cAhB/B,iBAAA,GAgB+B,UAAA;AAAc;AAQ1C,cAtBH,sBAAA,GAsBc,KAAA;;AAAU,KAnBzB,eAAA,GAmByB,KAAA,GAAA,SAAA;;AAA0B,UAhB9C,gBAAA,CAgB8C;;mCAd5B,YAAY;;;;MAEG,YAAY;;;UAI7C,kBAAA,SAA2B;;mBAEzB;;uBAEI;;;iBAIP,WAAA,UAAqB,qBAAqB"}
package/dist/mod.d.ts ADDED
@@ -0,0 +1,32 @@
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 prismaDefaultName = "database";
7
+ /** Connector when `connector` is unset. */
8
+ declare const prismaDefaultConnector = "sql";
9
+ /** Which raw entry point the probe calls. */
10
+ type PrismaConnector = "sql" | "mongodb";
11
+ /** The subset of a `PrismaClient` the probe uses; the method for the chosen `connector` must exist. */
12
+ interface PrismaLikeClient {
13
+ /** SQL connectors. */
14
+ $queryRawUnsafe?(query: string): PromiseLike<ProbeResult>;
15
+ /** The MongoDB connector. */
16
+ $runCommandRaw?(command: {
17
+ readonly ping: 1;
18
+ }): PromiseLike<ProbeResult>;
19
+ }
20
+ /** Options for `prismaProbe()`. */
21
+ interface PrismaProbeOptions extends ProbeOverrides {
22
+ /** A generated `PrismaClient`. */
23
+ readonly client: PrismaLikeClient;
24
+ /** `"mongodb"` calls `$runCommandRaw()`; anything else calls `$queryRawUnsafe()`. Default `prismaDefaultConnector`. */
25
+ readonly connector?: PrismaConnector;
26
+ }
27
+ /** A probe that runs `select 1` or, on MongoDB, `{ ping: 1 }`; critical by default. Throws `ProbeConfigError` when the client lacks the method for `connector`. */
28
+ declare function prismaProbe(options: PrismaProbeOptions): Probe;
29
+ //# sourceMappingURL=mod.d.ts.map
30
+ //#endregion
31
+ export { PrismaConnector, PrismaLikeClient, PrismaProbeOptions, prismaDefaultConnector, prismaDefaultName, prismaProbe };
32
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AAwC4C,cAhB/B,iBAAA,GAgB+B,UAAA;AAAc;AAQ1C,cAtBH,sBAAA,GAsBc,KAAA;;AAAU,KAnBzB,eAAA,GAmByB,KAAA,GAAA,SAAA;;AAA0B,UAhB9C,gBAAA,CAgB8C;;mCAd5B,YAAY;;;;MAEG,YAAY;;;UAI7C,kBAAA,SAA2B;;mBAEzB;;uBAEI;;;iBAIP,WAAA,UAAqB,qBAAqB"}
package/dist/mod.js ADDED
@@ -0,0 +1,35 @@
1
+ import { ProbeConfigError } from "@openstatus/health";
2
+
3
+ //#region src/mod.ts
4
+ /** Probe name when `name` is unset. */
5
+ const prismaDefaultName = "database";
6
+ /** Connector when `connector` is unset. */
7
+ const prismaDefaultConnector = "sql";
8
+ /** A probe that runs `select 1` or, on MongoDB, `{ ping: 1 }`; critical by default. Throws `ProbeConfigError` when the client lacks the method for `connector`. */
9
+ function prismaProbe(options) {
10
+ const client = options.client;
11
+ const connector = options.connector ?? prismaDefaultConnector;
12
+ if (connector !== "sql" && connector !== "mongodb") throw new ProbeConfigError("prismaProbe", "connector", `must be "sql" or "mongodb", got ${String(connector)}`);
13
+ const method = connector === "mongodb" ? "$runCommandRaw" : "$queryRawUnsafe";
14
+ if (typeof client?.[method] !== "function") throw new ProbeConfigError("prismaProbe", "client", `must expose ${method}() for the ${connector} connector, got ${describe(client)}`);
15
+ const run = connector === "mongodb" ? () => client.$runCommandRaw({ ping: 1 }) : () => client.$queryRawUnsafe("select 1");
16
+ return {
17
+ name: options.name ?? prismaDefaultName,
18
+ critical: options.critical ?? true,
19
+ timeoutMs: options.timeoutMs,
20
+ skip: options.skip,
21
+ run: async () => {
22
+ await run();
23
+ }
24
+ };
25
+ }
26
+ function describe(client) {
27
+ if (client == null) return String(client);
28
+ if (typeof client !== "object") return typeof client;
29
+ const keys = Object.keys(client);
30
+ return keys.length === 0 ? "an object with no keys" : `an object with keys ${keys.slice(0, 8).join(", ")}`;
31
+ }
32
+
33
+ //#endregion
34
+ export { prismaDefaultConnector, prismaDefaultName, prismaProbe };
35
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","names":["options: PrismaProbeOptions","run: () => PromiseLike<ProbeResult>","client: PrismaLikeClient"],"sources":["../src/mod.ts"],"sourcesContent":["/**\n * Prisma probe for `@openstatus/health`: runs `select 1` through\n * `$queryRawUnsafe()` on SQL databases, or the `ping` command through\n * `$runCommandRaw()` when `connector` is `\"mongodb\"`.\n *\n * ```ts\n * import { PrismaClient } from \"@prisma/client\";\n * import { prismaProbe } from \"@openstatus/health-prisma\";\n *\n * const probe = prismaProbe({ client: new PrismaClient() });\n * const mongo = prismaProbe({ client: new PrismaClient(), connector: \"mongodb\" });\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 prismaDefaultName = \"database\";\n/** Connector when `connector` is unset. */\nexport const prismaDefaultConnector = \"sql\";\n\n/** Which raw entry point the probe calls. */\nexport type PrismaConnector = \"sql\" | \"mongodb\";\n\n/** The subset of a `PrismaClient` the probe uses; the method for the chosen `connector` must exist. */\nexport interface PrismaLikeClient {\n /** SQL connectors. */\n $queryRawUnsafe?(query: string): PromiseLike<ProbeResult>;\n /** The MongoDB connector. */\n $runCommandRaw?(command: { readonly ping: 1 }): PromiseLike<ProbeResult>;\n}\n\n/** Options for `prismaProbe()`. */\nexport interface PrismaProbeOptions extends ProbeOverrides {\n /** A generated `PrismaClient`. */\n readonly client: PrismaLikeClient;\n /** `\"mongodb\"` calls `$runCommandRaw()`; anything else calls `$queryRawUnsafe()`. Default `prismaDefaultConnector`. */\n readonly connector?: PrismaConnector;\n}\n\n/** A probe that runs `select 1` or, on MongoDB, `{ ping: 1 }`; critical by default. Throws `ProbeConfigError` when the client lacks the method for `connector`. */\nexport function prismaProbe(options: PrismaProbeOptions): Probe {\n const client = options.client;\n const connector = options.connector ?? prismaDefaultConnector;\n if (connector !== \"sql\" && connector !== \"mongodb\") {\n throw new ProbeConfigError(\n \"prismaProbe\",\n \"connector\",\n `must be \"sql\" or \"mongodb\", got ${String(connector)}`,\n );\n }\n const method = connector === \"mongodb\" ? \"$runCommandRaw\" : \"$queryRawUnsafe\";\n if (typeof client?.[method] !== \"function\") {\n throw new ProbeConfigError(\n \"prismaProbe\",\n \"client\",\n `must expose ${method}() for the ${connector} connector, got ${\n describe(client)\n }`,\n );\n }\n const run: () => PromiseLike<ProbeResult> = connector === \"mongodb\"\n ? () => client.$runCommandRaw!({ ping: 1 })\n : () => client.$queryRawUnsafe!(\"select 1\");\n return {\n name: options.name ?? prismaDefaultName,\n critical: options.critical ?? true,\n timeoutMs: options.timeoutMs,\n skip: options.skip,\n run: async () => {\n await run();\n },\n };\n}\n\nfunction describe(client: PrismaLikeClient): 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":";;;;AAwBA,MAAa,oBAAoB;;AAEjC,MAAa,yBAAyB;;AAsBtC,SAAgB,YAAYA,SAAoC;CAC9D,MAAM,SAAS,QAAQ;CACvB,MAAM,YAAY,QAAQ,aAAa;AACvC,KAAI,cAAc,SAAS,cAAc,UACvC,OAAM,IAAI,iBACR,eACA,cACC,kCAAkC,OAAO,UAAU,CAAC;CAGzD,MAAM,SAAS,cAAc,YAAY,mBAAmB;AAC5D,YAAW,SAAS,YAAY,WAC9B,OAAM,IAAI,iBACR,eACA,WACC,cAAc,OAAO,aAAa,UAAU,kBAC3C,SAAS,OAAO,CACjB;CAGL,MAAMC,MAAsC,cAAc,YACtD,MAAM,OAAO,eAAgB,EAAE,MAAM,EAAG,EAAC,GACzC,MAAM,OAAO,gBAAiB,WAAW;AAC7C,QAAO;EACL,MAAM,QAAQ,QAAQ;EACtB,UAAU,QAAQ,YAAY;EAC9B,WAAW,QAAQ;EACnB,MAAM,QAAQ;EACd,KAAK,YAAY;AACf,SAAM,KAAK;EACZ;CACF;AACF;AAED,SAAS,SAASC,QAAkC;AAClD,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-prisma",
3
+ "version": "0.1.4-dev.0",
4
+ "description": "Prisma probe for @openstatus/health",
5
+ "keywords": [
6
+ "openstatus",
7
+ "health",
8
+ "healthcheck",
9
+ "prisma",
10
+ "orm",
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/prisma/"
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
+ "@prisma/client": ">=5.0.0"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "@prisma/client": {
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
+ }