@healthzkit/postgres 0.0.1

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,23 @@
1
+ # vite-plus-starter
2
+
3
+ A starter for creating a Vite Plus project.
4
+
5
+ ## Development
6
+
7
+ - Install dependencies:
8
+
9
+ ```bash
10
+ vp install
11
+ ```
12
+
13
+ - Run the unit tests:
14
+
15
+ ```bash
16
+ vp test
17
+ ```
18
+
19
+ - Build the library:
20
+
21
+ ```bash
22
+ vp pack
23
+ ```
@@ -0,0 +1,3 @@
1
+ import { PgAdapterOptions, pgAdapter } from "./pg.mjs";
2
+ import { PostgresJsAdapterOptions, postgresJsAdapter } from "./postgres.mjs";
3
+ export { type PgAdapterOptions, type PostgresJsAdapterOptions, pgAdapter, postgresJsAdapter };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import{pgAdapter as e}from"./pg.mjs";import{postgresJsAdapter as t}from"./postgres.mjs";export{e as pgAdapter,t as postgresJsAdapter};
package/dist/pg.d.mts ADDED
@@ -0,0 +1,16 @@
1
+ import { n as HealthAdapter, t as BasePostgresOptions } from "./shared-CTJ6HzL3.mjs";
2
+ import { ClientBase, Pool, PoolClient } from "pg";
3
+
4
+ //#region src/pg.d.ts
5
+ interface PgAdapterOptionsWithClent extends BasePostgresOptions<ClientBase> {
6
+ client: Pool | PoolClient | ClientBase;
7
+ connectionString?: never;
8
+ }
9
+ interface PgAdapterOptionsWithConnectionString extends BasePostgresOptions<ClientBase> {
10
+ connectionString: string;
11
+ client?: never;
12
+ }
13
+ type PgAdapterOptions = PgAdapterOptionsWithClent | PgAdapterOptionsWithConnectionString;
14
+ declare function pgAdapter(options: PgAdapterOptions): HealthAdapter;
15
+ //#endregion
16
+ export { PgAdapterOptions, PgAdapterOptionsWithClent, PgAdapterOptionsWithConnectionString, pgAdapter };
package/dist/pg.mjs ADDED
@@ -0,0 +1 @@
1
+ import{n as e,t}from"./shared-BhE-9Ws4.mjs";function n(n){let r=null;async function i(){if(`connectionString`in n&&n.connectionString){let{Pool:e}=await import(`pg`);r||=new e({connectionString:n.connectionString,max:1});let t=await r.connect();return{client:t,release:()=>t.release()}}let e=n.client;if(`connect`in e&&typeof e.connect==`function`){let t=await e.connect();return{client:t,release:()=>t.release()}}return{client:n.client,release:()=>{}}}return{async check(){let r=()=>{};try{let t=Date.now(),{client:a,release:o}=await i();return r=o,await a.query(n.query??`SELECT 1`),e(Date.now()-t,n.metadata?await n.metadata(a):void 0)}catch(e){return t(e)}finally{r()}}}}export{n as pgAdapter};
@@ -0,0 +1,16 @@
1
+ import { n as HealthAdapter, t as BasePostgresOptions } from "./shared-CTJ6HzL3.mjs";
2
+ import { Sql, TransactionSql } from "postgres";
3
+
4
+ //#region src/postgres.d.ts
5
+ interface PostgresJsAdapterOptionsWithClient extends BasePostgresOptions<Sql> {
6
+ client: Sql | TransactionSql;
7
+ connectionString?: never;
8
+ }
9
+ interface PostgresJsAdapterOptionsWithConnectionString extends BasePostgresOptions<Sql> {
10
+ connectionString: string;
11
+ client?: never;
12
+ }
13
+ type PostgresJsAdapterOptions = PostgresJsAdapterOptionsWithClient | PostgresJsAdapterOptionsWithConnectionString;
14
+ declare function postgresJsAdapter(options: PostgresJsAdapterOptions): HealthAdapter;
15
+ //#endregion
16
+ export { PostgresJsAdapterOptions, PostgresJsAdapterOptionsWithClient, PostgresJsAdapterOptionsWithConnectionString, postgresJsAdapter };
@@ -0,0 +1 @@
1
+ import{n as e,t}from"./shared-BhE-9Ws4.mjs";function n(n){let r=null;async function i(){if(`connectionString`in n&&n.connectionString){let e=await import(`postgres`),t=e.default??e;return r||=t(n.connectionString,{max:1}),r}return n.client}return{async check(){try{let t=await i(),r=Date.now();return await t.unsafe(n.query??`SELECT 1`),e(Date.now()-r,n.metadata?await n.metadata(t):void 0)}catch(e){return t(e)}}}}export{n as postgresJsAdapter};
@@ -0,0 +1 @@
1
+ function e(e,t){return{status:`ok`,metadata:{latencyMs:e,...t}}}function t(e){return{status:`fail`,error:e instanceof Error?e:Error(String(e))}}export{e as n,t};
@@ -0,0 +1,18 @@
1
+ import { HealthAdapter } from "healthzkit";
2
+
3
+ //#region src/shared.d.ts
4
+ type MetadataFn<TClient> = (client: TClient) => Promise<Record<string, unknown>>;
5
+ interface BasePostgresOptions<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
+ export { HealthAdapter as n, BasePostgresOptions as t };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@healthzkit/postgres",
3
+ "version": "0.0.1",
4
+ "files": [
5
+ "dist"
6
+ ],
7
+ "type": "module",
8
+ "exports": {
9
+ ".": "./dist/index.mjs",
10
+ "./pg": "./dist/pg.mjs",
11
+ "./postgres": "./dist/postgres.mjs",
12
+ "./package.json": "./package.json"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "devDependencies": {
18
+ "@types/node": "^25.5.0",
19
+ "@types/pg": "^8.20.0",
20
+ "@typescript/native-preview": "7.0.0-dev.20260328.1",
21
+ "bumpp": "^11.0.1",
22
+ "pg": "^8.20.0",
23
+ "postgres": "^3.4.9",
24
+ "typescript": "^6.0.2",
25
+ "vite-plus": "^0.1.14",
26
+ "healthzkit": "0.0.1"
27
+ },
28
+ "peerDependencies": {
29
+ "pg": ">=8.0.0",
30
+ "postgres": ">=3.0.0"
31
+ },
32
+ "peerDependenciesMeta": {
33
+ "pg": {
34
+ "optional": true
35
+ },
36
+ "postgres": {
37
+ "optional": true
38
+ }
39
+ },
40
+ "scripts": {
41
+ "build": "vp pack",
42
+ "dev": "vp pack --watch",
43
+ "test": "vp test",
44
+ "check": "vp check"
45
+ }
46
+ }