@healthzkit/cockroach 0.0.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,79 @@
1
+ # @healthzkit/cockroach
2
+
3
+ CockroachDB **healthzkit** `HealthAdapter` helper for **[`pg`](https://node-postgres.com/)** (node-postgres). CockroachDB speaks the PostgreSQL wire protocol, so the adapter runs a lightweight SQL probe (default **`SELECT 1`**) via `client.query`. Successful checks return `ok` with `metadata.latencyMs` plus any fields from an optional `metadata` hook; failures return `fail` with the caught error.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @healthzkit/cockroach healthzkit pg
9
+ ```
10
+
11
+ **Peer:** `pg` ≥ 8.
12
+
13
+ ## Options
14
+
15
+ `cockroachPgAdapter` accepts `BaseCockroachOptions`:
16
+
17
+ | Option | Description |
18
+ | ---------- | ---------------------------------------------------------------------------------------------------------------------------------- |
19
+ | `query` | SQL executed for the probe. Default `SELECT 1`. |
20
+ | `metadata` | Optional async `(client) => Record<string, unknown>` merged into check metadata with `latencyMs`. |
21
+ | `pgOption` | Optional `pg` `Pool` constructor options (except `connectionString`). Only with `connectionString`. Merged into the internal pool. |
22
+
23
+ Pass either `connectionString` or `client` (not both).
24
+
25
+ ## Connection string
26
+
27
+ The adapter maintains an internal `Pool` with `max: 1`, `connect()`s a client for each check, runs `client.query(query)`, then `release()`s the client in a `finally` block.
28
+
29
+ ```ts
30
+ import { createHealthKit } from "healthzkit";
31
+ import { cockroachPgAdapter } from "@healthzkit/cockroach";
32
+
33
+ const kit = createHealthKit({
34
+ checks: [
35
+ {
36
+ name: "cockroach",
37
+ type: ["readiness"],
38
+ adapter: cockroachPgAdapter({
39
+ connectionString: process.env.DATABASE_URL!,
40
+ }),
41
+ },
42
+ ],
43
+ });
44
+ ```
45
+
46
+ Optional `pgOption` merges into the internal `Pool` constructor (everything except `connectionString`).
47
+
48
+ ## Existing client or pool
49
+
50
+ Pass `client` as:
51
+
52
+ - A `Pool`: each check calls `pool.connect()`, runs the query on the `PoolClient`, then releases it.
53
+ - A `PoolClient` or other `ClientBase`: the query runs on that instance; release is a no-op.
54
+
55
+ ```ts
56
+ import { Pool } from "pg";
57
+ import { cockroachPgAdapter } from "@healthzkit/cockroach";
58
+
59
+ const pool = new Pool({ connectionString: process.env.DATABASE_URL! });
60
+
61
+ const adapter = cockroachPgAdapter({
62
+ client: pool,
63
+ query: "SELECT current_database()",
64
+ });
65
+ ```
66
+
67
+ ## Scheduling
68
+
69
+ For busy clusters, pair this adapter with a `schedule` on the check so readiness reads cached results instead of hitting CockroachDB on every probe. See the **Scheduling** section in the `healthzkit` README.
70
+
71
+ ## Development
72
+
73
+ From the monorepo root:
74
+
75
+ ```bash
76
+ vp install
77
+ vp test --filter @healthzkit/cockroach
78
+ vp pack --filter @healthzkit/cockroach
79
+ ```
@@ -0,0 +1,2 @@
1
+ import { i as cockroachPgAdapter, t as CockroachPgAdapterOptions } from "./pg-CgrYo7g9.mjs";
2
+ export { type CockroachPgAdapterOptions, cockroachPgAdapter };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import{t as e}from"./pg-iF7bm_uc.mjs";export{e as cockroachPgAdapter};
@@ -0,0 +1,32 @@
1
+ import { HealthAdapter, MetadataFn } from "@healthzkit/shared";
2
+ import { ClientBase, Pool, PoolClient } from "pg";
3
+
4
+ //#region src/shared.d.ts
5
+ interface BaseCockroachOptions<TClient> {
6
+ /**
7
+ * Query to run as the healthcheck.
8
+ * @default "SELECT 1"
9
+ */
10
+ query?: string;
11
+ /**
12
+ * Optional function to populate metadata in the check result.
13
+ * Receives the resolved client so you can run additional queries.
14
+ */
15
+ metadata?: MetadataFn<TClient>;
16
+ }
17
+ //#endregion
18
+ //#region src/pg.d.ts
19
+ interface CockroachPgAdapterOptionsWithClient extends BaseCockroachOptions<ClientBase> {
20
+ client: Pool | PoolClient | ClientBase;
21
+ connectionString?: never;
22
+ pgOption?: never;
23
+ }
24
+ interface CockroachPgAdapterOptionsWithConfig extends BaseCockroachOptions<ClientBase> {
25
+ connectionString: string;
26
+ pgOption?: Omit<ConstructorParameters<typeof Pool>[0], "connectionString">;
27
+ client?: never;
28
+ }
29
+ type CockroachPgAdapterOptions = CockroachPgAdapterOptionsWithClient | CockroachPgAdapterOptionsWithConfig;
30
+ declare function cockroachPgAdapter(options: CockroachPgAdapterOptions): HealthAdapter;
31
+ //#endregion
32
+ export { cockroachPgAdapter as i, CockroachPgAdapterOptionsWithClient as n, CockroachPgAdapterOptionsWithConfig as r, CockroachPgAdapterOptions as t };
@@ -0,0 +1 @@
1
+ import{buildErrorResult as e,buildResult as t}from"@healthzkit/shared";function n(n){let r=null;async function i(){let{Pool:e}=await import(`pg`);if(`connectionString`in n){if(`client`in n)throw Error(`cockroachPgAdapter accepts either connectionString or client, not both`);if(!n.connectionString)throw Error(`cockroachPgAdapter connectionString must be a non-empty string`);r||=new e({connectionString:n.connectionString,max:1,...n.pgOption});let t=await r.connect();return{client:t,release:()=>t.release()}}if(`client`in n){if(n.client instanceof e){let e=await n.client.connect();return{client:e,release:()=>e.release()}}return{client:n.client,release:()=>{}}}throw Error(`cockroachPgAdapter requires either connectionString or client`)}return{async check(){let r=()=>{};try{let e=Date.now(),{client:a,release:o}=await i();r=o,await a.query(n.query??`SELECT 1`);let s=Date.now()-e,c=n.metadata?await n.metadata(a):void 0;return t(s,c instanceof Promise?await c:c)}catch(t){return e(t)}finally{r()}}}}export{n as t};
package/dist/pg.d.mts ADDED
@@ -0,0 +1,2 @@
1
+ import { i as cockroachPgAdapter, n as CockroachPgAdapterOptionsWithClient, r as CockroachPgAdapterOptionsWithConfig, t as CockroachPgAdapterOptions } from "./pg-CgrYo7g9.mjs";
2
+ export { CockroachPgAdapterOptions, CockroachPgAdapterOptionsWithClient, CockroachPgAdapterOptionsWithConfig, cockroachPgAdapter };
package/dist/pg.mjs ADDED
@@ -0,0 +1 @@
1
+ import{t as e}from"./pg-iF7bm_uc.mjs";export{e as cockroachPgAdapter};
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@healthzkit/cockroach",
3
+ "version": "0.0.0",
4
+ "license": "AGPL-3.0-only",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/alasti-company/healthzkit.dev",
8
+ "directory": "packages/cockroach"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "type": "module",
14
+ "exports": {
15
+ ".": "./dist/index.mjs",
16
+ "./pg": "./dist/pg.mjs",
17
+ "./package.json": "./package.json"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "scripts": {
23
+ "build": "vp pack",
24
+ "dev": "vp pack --watch",
25
+ "test": "vp test",
26
+ "check": "vp check",
27
+ "prepublishOnly": "vp run build"
28
+ },
29
+ "dependencies": {
30
+ "@healthzkit/shared": "workspace:*"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "catalog:",
34
+ "@types/pg": "^8.2.0",
35
+ "@typescript/native-preview": "7.0.0-dev.20260509.2",
36
+ "bumpp": "^11.1.0",
37
+ "healthzkit": "workspace:*",
38
+ "pg": "8.21.0",
39
+ "typescript": "catalog:",
40
+ "vite-plus": "catalog:"
41
+ },
42
+ "peerDependencies": {
43
+ "pg": ">=8.0.0"
44
+ },
45
+ "peerDependenciesMeta": {
46
+ "pg": {
47
+ "optional": false
48
+ }
49
+ }
50
+ }