@openstatus/health-cloudflare-d1 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 +78 -0
- package/dist/_virtual/rolldown_runtime.cjs +30 -0
- package/dist/mod.cjs +30 -0
- package/dist/mod.d.cts +27 -0
- package/dist/mod.d.cts.map +1 -0
- package/dist/mod.d.ts +27 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +29 -0
- package/dist/mod.js.map +1 -0
- package/package.json +63 -0
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# @openstatus/health-cloudflare-d1
|
|
2
|
+
|
|
3
|
+
[Cloudflare D1](https://developers.cloudflare.com/d1/) probe for
|
|
4
|
+
[`@openstatus/health`](https://jsr.io/@openstatus/health). Runs `select 1`
|
|
5
|
+
through the `D1Database` binding of a Worker and fails the check when the
|
|
6
|
+
statement does.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
deno add jsr:@openstatus/health jsr:@openstatus/health-cloudflare-d1
|
|
10
|
+
npm install @openstatus/health @openstatus/health-cloudflare-d1
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createLazyHealthHandler } from "@openstatus/health";
|
|
15
|
+
import { d1Probe } from "@openstatus/health-cloudflare-d1";
|
|
16
|
+
|
|
17
|
+
interface Env {
|
|
18
|
+
DB: D1Database;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
fetch: createLazyHealthHandler<Request, Env>((env) => ({
|
|
23
|
+
path: "/health",
|
|
24
|
+
probes: [d1Probe({ db: env.DB })],
|
|
25
|
+
})),
|
|
26
|
+
};
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Bindings only exist inside `fetch(request, env)` in Workers, but the handler
|
|
30
|
+
must be built once or every request gets a fresh cache and the probe runs on
|
|
31
|
+
every poll. `createLazyHealthHandler` runs your callback on the first request
|
|
32
|
+
and reuses the handler it builds; with Hono, build the probe once inside a
|
|
33
|
+
route handler that receives `c.env` and memoise it the same way. The probe
|
|
34
|
+
calls `db.prepare("select 1").first()`, which round-trips to the D1 storage
|
|
35
|
+
and needs no table. For the colo and version the response came from, add
|
|
36
|
+
`@openstatus/health-cloudflare`'s `extend` hook.
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
d1Probe({
|
|
40
|
+
db: env.DB,
|
|
41
|
+
// optional overrides from the Probe contract
|
|
42
|
+
name: "d1",
|
|
43
|
+
critical: false,
|
|
44
|
+
timeoutMs: 1000,
|
|
45
|
+
skip: () => env.HEALTH_SKIP_D1 === "true",
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The factory validates `db` when it is called, before `skip` is ever
|
|
50
|
+
consulted, so `skip` cannot stand in for a missing binding; leave the probe
|
|
51
|
+
out of `probes` instead when the Worker may run without D1.
|
|
52
|
+
|
|
53
|
+
Critical by default: a D1 that does not answer usually means requests cannot
|
|
54
|
+
be served, so the report turns `unhealthy`. Set `critical: false` when the
|
|
55
|
+
Worker can serve without it.
|
|
56
|
+
|
|
57
|
+
The binding is typed structurally as `{ prepare(query): { first() } }`, so
|
|
58
|
+
the package has no dependency on `@cloudflare/workers-types` and works with
|
|
59
|
+
the types `wrangler types` generates. The factory throws `ProbeConfigError`
|
|
60
|
+
at construction when the binding has no `prepare()`.
|
|
61
|
+
|
|
62
|
+
## About openstatus
|
|
63
|
+
|
|
64
|
+
[openstatus](https://www.openstatus.dev/) is the open-source uptime monitoring
|
|
65
|
+
and status page platform. This package is part of
|
|
66
|
+
[`@openstatus/health`](https://github.com/openstatusHQ/health), the `/health`
|
|
67
|
+
endpoints behind openstatus's own services, extracted so any JavaScript server
|
|
68
|
+
can expose one. Point an
|
|
69
|
+
[openstatus monitor](https://www.openstatus.dev/docs/reference/http-monitor)
|
|
70
|
+
at the endpoint and assert on `status` in the body to be alerted on
|
|
71
|
+
`degraded` before it becomes `unhealthy`.
|
|
72
|
+
|
|
73
|
+
Source: [github.com/openstatusHQ/health](https://github.com/openstatusHQ/health).
|
|
74
|
+
Issues and PRs welcome.
|
|
75
|
+
|
|
76
|
+
## License
|
|
77
|
+
|
|
78
|
+
[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,30 @@
|
|
|
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 d1DefaultName = "database";
|
|
7
|
+
/** A probe that runs `select 1`; critical by default. Throws `ProbeConfigError` without `prepare()`. */
|
|
8
|
+
function d1Probe(options) {
|
|
9
|
+
const db = options.db;
|
|
10
|
+
if (typeof db?.prepare !== "function") throw new __openstatus_health.ProbeConfigError("d1Probe", "db", `must expose prepare(), got ${describe(db)}`);
|
|
11
|
+
return {
|
|
12
|
+
name: options.name ?? d1DefaultName,
|
|
13
|
+
critical: options.critical ?? true,
|
|
14
|
+
timeoutMs: options.timeoutMs,
|
|
15
|
+
skip: options.skip,
|
|
16
|
+
run: async () => {
|
|
17
|
+
await db.prepare("select 1").first();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function describe(db) {
|
|
22
|
+
if (db == null) return String(db);
|
|
23
|
+
if (typeof db !== "object") return typeof db;
|
|
24
|
+
const keys = Object.keys(db);
|
|
25
|
+
return keys.length === 0 ? "an object with no keys" : `an object with keys ${keys.slice(0, 8).join(", ")}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.d1DefaultName = d1DefaultName;
|
|
30
|
+
exports.d1Probe = d1Probe;
|
package/dist/mod.d.cts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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 d1DefaultName = "database";
|
|
7
|
+
/** The subset of a `D1PreparedStatement` the probe uses. */
|
|
8
|
+
interface D1LikeStatement {
|
|
9
|
+
/** Run the statement and resolve with the first row. */
|
|
10
|
+
first(): PromiseLike<ProbeResult>;
|
|
11
|
+
}
|
|
12
|
+
/** The subset of a `D1Database` binding the probe uses. */
|
|
13
|
+
interface D1LikeDatabase {
|
|
14
|
+
/** Prepare one statement. */
|
|
15
|
+
prepare(query: string): D1LikeStatement;
|
|
16
|
+
}
|
|
17
|
+
/** Options for `d1Probe()`. */
|
|
18
|
+
interface D1ProbeOptions extends ProbeOverrides {
|
|
19
|
+
/** The `D1Database` binding from `env`. */
|
|
20
|
+
readonly db: D1LikeDatabase;
|
|
21
|
+
}
|
|
22
|
+
/** A probe that runs `select 1`; critical by default. Throws `ProbeConfigError` without `prepare()`. */
|
|
23
|
+
declare function d1Probe(options: D1ProbeOptions): Probe;
|
|
24
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
25
|
+
//#endregion
|
|
26
|
+
export { D1LikeDatabase, D1LikeStatement, D1ProbeOptions, d1DefaultName, d1Probe };
|
|
27
|
+
//# sourceMappingURL=mod.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.cts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AA+CuD,cArB1C,aAAA,GAqB0C,UAAA;;UAlBtC,eAAA;;WAEN,YAAY;;;UAIN,cAAA;;0BAES;;;UAIT,cAAA,SAAuB;;eAEzB;;;iBAIC,OAAA,UAAiB,iBAAiB"}
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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 d1DefaultName = "database";
|
|
7
|
+
/** The subset of a `D1PreparedStatement` the probe uses. */
|
|
8
|
+
interface D1LikeStatement {
|
|
9
|
+
/** Run the statement and resolve with the first row. */
|
|
10
|
+
first(): PromiseLike<ProbeResult>;
|
|
11
|
+
}
|
|
12
|
+
/** The subset of a `D1Database` binding the probe uses. */
|
|
13
|
+
interface D1LikeDatabase {
|
|
14
|
+
/** Prepare one statement. */
|
|
15
|
+
prepare(query: string): D1LikeStatement;
|
|
16
|
+
}
|
|
17
|
+
/** Options for `d1Probe()`. */
|
|
18
|
+
interface D1ProbeOptions extends ProbeOverrides {
|
|
19
|
+
/** The `D1Database` binding from `env`. */
|
|
20
|
+
readonly db: D1LikeDatabase;
|
|
21
|
+
}
|
|
22
|
+
/** A probe that runs `select 1`; critical by default. Throws `ProbeConfigError` without `prepare()`. */
|
|
23
|
+
declare function d1Probe(options: D1ProbeOptions): Probe;
|
|
24
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
25
|
+
//#endregion
|
|
26
|
+
export { D1LikeDatabase, D1LikeStatement, D1ProbeOptions, d1DefaultName, d1Probe };
|
|
27
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AA+CuD,cArB1C,aAAA,GAqB0C,UAAA;;UAlBtC,eAAA;;WAEN,YAAY;;;UAIN,cAAA;;0BAES;;;UAIT,cAAA,SAAuB;;eAEzB;;;iBAIC,OAAA,UAAiB,iBAAiB"}
|
package/dist/mod.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ProbeConfigError } from "@openstatus/health";
|
|
2
|
+
|
|
3
|
+
//#region src/mod.ts
|
|
4
|
+
/** Probe name when `name` is unset. */
|
|
5
|
+
const d1DefaultName = "database";
|
|
6
|
+
/** A probe that runs `select 1`; critical by default. Throws `ProbeConfigError` without `prepare()`. */
|
|
7
|
+
function d1Probe(options) {
|
|
8
|
+
const db = options.db;
|
|
9
|
+
if (typeof db?.prepare !== "function") throw new ProbeConfigError("d1Probe", "db", `must expose prepare(), got ${describe(db)}`);
|
|
10
|
+
return {
|
|
11
|
+
name: options.name ?? d1DefaultName,
|
|
12
|
+
critical: options.critical ?? true,
|
|
13
|
+
timeoutMs: options.timeoutMs,
|
|
14
|
+
skip: options.skip,
|
|
15
|
+
run: async () => {
|
|
16
|
+
await db.prepare("select 1").first();
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function describe(db) {
|
|
21
|
+
if (db == null) return String(db);
|
|
22
|
+
if (typeof db !== "object") return typeof db;
|
|
23
|
+
const keys = Object.keys(db);
|
|
24
|
+
return keys.length === 0 ? "an object with no keys" : `an object with keys ${keys.slice(0, 8).join(", ")}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { d1DefaultName, d1Probe };
|
|
29
|
+
//# sourceMappingURL=mod.js.map
|
package/dist/mod.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","names":["options: D1ProbeOptions","db: D1LikeDatabase"],"sources":["../src/mod.ts"],"sourcesContent":["/**\n * Cloudflare D1 probe for `@openstatus/health`: runs `select 1` through a\n * Workers `D1Database` binding.\n *\n * ```ts\n * import { createLazyHealthHandler } from \"@openstatus/health\";\n * import { d1Probe } from \"@openstatus/health-cloudflare-d1\";\n *\n * export default {\n * fetch: createLazyHealthHandler<Request, Env>((env) => ({\n * probes: [d1Probe({ db: env.DB })],\n * })),\n * };\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 d1DefaultName = \"database\";\n\n/** The subset of a `D1PreparedStatement` the probe uses. */\nexport interface D1LikeStatement {\n /** Run the statement and resolve with the first row. */\n first(): PromiseLike<ProbeResult>;\n}\n\n/** The subset of a `D1Database` binding the probe uses. */\nexport interface D1LikeDatabase {\n /** Prepare one statement. */\n prepare(query: string): D1LikeStatement;\n}\n\n/** Options for `d1Probe()`. */\nexport interface D1ProbeOptions extends ProbeOverrides {\n /** The `D1Database` binding from `env`. */\n readonly db: D1LikeDatabase;\n}\n\n/** A probe that runs `select 1`; critical by default. Throws `ProbeConfigError` without `prepare()`. */\nexport function d1Probe(options: D1ProbeOptions): Probe {\n const db = options.db;\n if (typeof db?.prepare !== \"function\") {\n throw new ProbeConfigError(\n \"d1Probe\",\n \"db\",\n `must expose prepare(), got ${describe(db)}`,\n );\n }\n return {\n name: options.name ?? d1DefaultName,\n critical: options.critical ?? true,\n timeoutMs: options.timeoutMs,\n skip: options.skip,\n run: async () => {\n await db.prepare(\"select 1\").first();\n },\n };\n}\n\nfunction describe(db: D1LikeDatabase): string {\n if (db == null) return String(db);\n if (typeof db !== \"object\") return typeof db;\n const keys = Object.keys(db);\n return keys.length === 0\n ? \"an object with no keys\"\n : `an object with keys ${keys.slice(0, 8).join(\", \")}`;\n}\n"],"mappings":";;;;AA0BA,MAAa,gBAAgB;;AAqB7B,SAAgB,QAAQA,SAAgC;CACtD,MAAM,KAAK,QAAQ;AACnB,YAAW,IAAI,YAAY,WACzB,OAAM,IAAI,iBACR,WACA,OACC,6BAA6B,SAAS,GAAG,CAAC;AAG/C,QAAO;EACL,MAAM,QAAQ,QAAQ;EACtB,UAAU,QAAQ,YAAY;EAC9B,WAAW,QAAQ;EACnB,MAAM,QAAQ;EACd,KAAK,YAAY;AACf,SAAM,GAAG,QAAQ,WAAW,CAAC,OAAO;EACrC;CACF;AACF;AAED,SAAS,SAASC,IAA4B;AAC5C,KAAI,MAAM,KAAM,QAAO,OAAO,GAAG;AACjC,YAAW,OAAO,SAAU,eAAc;CAC1C,MAAM,OAAO,OAAO,KAAK,GAAG;AAC5B,QAAO,KAAK,WAAW,IACnB,4BACC,sBAAsB,KAAK,MAAM,GAAG,EAAE,CAAC,KAAK,KAAK,CAAC;AACxD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openstatus/health-cloudflare-d1",
|
|
3
|
+
"version": "0.1.4-dev.0",
|
|
4
|
+
"description": "Cloudflare D1 probe for @openstatus/health",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"openstatus",
|
|
7
|
+
"health",
|
|
8
|
+
"healthcheck",
|
|
9
|
+
"cloudflare",
|
|
10
|
+
"d1",
|
|
11
|
+
"workers",
|
|
12
|
+
"sqlite",
|
|
13
|
+
"database"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "openstatus",
|
|
18
|
+
"url": "https://www.openstatus.dev/"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/openstatusHQ/health",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/openstatusHQ/health.git",
|
|
24
|
+
"directory": "packages/cloudflare-d1/"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/openstatusHQ/health/issues"
|
|
28
|
+
},
|
|
29
|
+
"type": "module",
|
|
30
|
+
"module": "./dist/mod.js",
|
|
31
|
+
"main": "./dist/mod.cjs",
|
|
32
|
+
"types": "./dist/mod.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": {
|
|
36
|
+
"import": "./dist/mod.d.ts",
|
|
37
|
+
"require": "./dist/mod.d.cts"
|
|
38
|
+
},
|
|
39
|
+
"import": "./dist/mod.js",
|
|
40
|
+
"require": "./dist/mod.cjs"
|
|
41
|
+
},
|
|
42
|
+
"./package.json": "./package.json"
|
|
43
|
+
},
|
|
44
|
+
"sideEffects": false,
|
|
45
|
+
"files": [
|
|
46
|
+
"dist/"
|
|
47
|
+
],
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=22"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@openstatus/health": "^0.1.4-dev.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"tsdown": "^0.12.7",
|
|
56
|
+
"typescript": "^5.8.3"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsdown",
|
|
60
|
+
"prepack": "tsdown",
|
|
61
|
+
"test": "node --experimental-transform-types --test"
|
|
62
|
+
}
|
|
63
|
+
}
|