@healthzkit/mongo 0.0.3 → 0.0.4

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.
@@ -1,4 +1,4 @@
1
- import { n as HealthAdapter, t as BaseMongoOptions } from "./shared-CkMHx8WJ.mjs";
1
+ import { n as HealthAdapter, t as BaseMongoOptions } from "./shared-D2N9p6gZ.mjs";
2
2
  import { MongoClient, MongoClientOptions } from "mongodb";
3
3
 
4
4
  //#region src/mongodb.d.ts
package/dist/mongodb.mjs CHANGED
@@ -1 +1 @@
1
- import{n as e,t}from"./dist-iC8gGE1z.mjs";function n(n){let r=null,i=null,a=null;async function o(e,t){return i??=(async()=>{let{MongoClient:n}=await import(`mongodb`),i=new n(e,t);return await i.connect(),r=i,i})().catch(e=>{throw i=null,r=null,e}),i}async function s(){if(`connectionString`in n&&n.connectionString)return o(n.connectionString,n.mongoOptions);if(`client`in n&&n.client)return a??=n.client.connect().then(()=>void 0).catch(e=>{throw a=null,e}),await a,n.client;throw Error(`mongoAdapter: provide a non-empty connectionString or a client`)}return{async check(){try{let e=await s(),r=Date.now();await e.db(`admin`).command({ping:1});let i=Date.now()-r,a=n.metadata?n.metadata(e):void 0;return t(i,a instanceof Promise?await a:a)}catch(t){return e(t)}},async close(){r&&(await r.close(),r=null,i=null)}}}export{n as mongodbAdapter};
1
+ import{n as e,t}from"./shared-BiUsKU63.mjs";function n(n){let r=null,i=null,a=null;async function o(e,t){return i??=(async()=>{let{MongoClient:n}=await import(`mongodb`),i=new n(e,t);return await i.connect(),r=i,i})().catch(e=>{throw i=null,r=null,e}),i}async function s(){if(`connectionString`in n&&n.connectionString)return o(n.connectionString,n.mongoOptions);if(`client`in n&&n.client)return a??=n.client.connect().then(()=>void 0).catch(e=>{throw a=null,e}),await a,n.client;throw Error(`mongoAdapter: provide a non-empty connectionString or a client`)}return{async check(){try{let t=await s(),r=Date.now();await t.db(`admin`).command({ping:1});let i=Date.now()-r,a=n.metadata?n.metadata(t):void 0;return e(i,a instanceof Promise?await a:a)}catch(e){return t(e)}},async close(){r&&(await r.close(),r=null,i=null)}}}export{n as mongodbAdapter};
@@ -1,4 +1,4 @@
1
- import { n as HealthAdapter, t as BaseMongoOptions } from "./shared-CkMHx8WJ.mjs";
1
+ import { n as HealthAdapter, t as BaseMongoOptions } from "./shared-D2N9p6gZ.mjs";
2
2
  import { ConnectOptions, Connection, Mongoose } from "mongoose";
3
3
 
4
4
  //#region src/mongoose.d.ts
package/dist/mongoose.mjs CHANGED
@@ -1 +1 @@
1
- import{n as e,t}from"./dist-iC8gGE1z.mjs";function n(n){let r=null;async function i(e,t){return r??=(async()=>{let{default:n}=await import(`mongoose`);return await n.connect(e,t),n})().catch(e=>{throw r=null,e}),r}async function a(){if(`connectionString`in n&&n.connectionString)return i(n.connectionString,n.mongooseOptions);let e=n.connection;if(!e)throw Error(`mongoose adapter requires connection or connectionString`);return`readyState`in e&&e.readyState!==1&&await e.asPromise(),e}return{async check(){try{let e=await a(),r=Date.now(),i=`db`in e?e.db:e.connection.db;if(!i)throw Error(`mongoose adapter: database unavailable`);await i.admin().command({ping:1});let o=Date.now()-r,s=n.metadata?n.metadata(e):void 0;return t(o,s instanceof Promise?await s:s)}catch(t){return e(t)}}}}export{n as mongooseAdapter};
1
+ import{n as e,t}from"./shared-BiUsKU63.mjs";function n(n){let r=null;async function i(e,t){return r??=(async()=>{let{default:n}=await import(`mongoose`);return await n.connect(e,t),n})().catch(e=>{throw r=null,e}),r}async function a(){if(`connectionString`in n&&n.connectionString)return i(n.connectionString,n.mongooseOptions);let e=n.connection;if(!e)throw Error(`mongoose adapter requires connection or connectionString`);return`readyState`in e&&e.readyState!==1&&await e.asPromise(),e}return{async check(){try{let t=await a(),r=Date.now(),i=`db`in t?t.db:t.connection.db;if(!i)throw Error(`mongoose adapter: database unavailable`);await i.admin().command({ping:1});let o=Date.now()-r,s=n.metadata?n.metadata(t):void 0;return e(o,s instanceof Promise?await s:s)}catch(e){return t(e)}}}}export{n as mongooseAdapter};
@@ -0,0 +1 @@
1
+ import{buildErrorResult as e,buildResult as t}from"@healthzkit/shared";export{t as n,e as t};
@@ -0,0 +1,12 @@
1
+ import { HealthAdapter, MetadataFn } from "@healthzkit/shared";
2
+
3
+ //#region src/shared.d.ts
4
+ interface BaseMongoOptions<TClient> {
5
+ /**
6
+ * Optional function to populate metadata in the check result.
7
+ * Receives the resolved client so you can run additional queries.
8
+ */
9
+ metadata?: MetadataFn<TClient>;
10
+ }
11
+ //#endregion
12
+ export { HealthAdapter as n, BaseMongoOptions as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@healthzkit/mongo",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "license": "AGPL-3.0-only",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,6 +20,9 @@
20
20
  "publishConfig": {
21
21
  "access": "public"
22
22
  },
23
+ "dependencies": {
24
+ "@healthzkit/shared": "0.0.0"
25
+ },
23
26
  "devDependencies": {
24
27
  "@types/mongodb": "^4.0.7",
25
28
  "@types/mongoose": "^5.11.97",
@@ -30,7 +33,6 @@
30
33
  "mongoose": "^9.6.2",
31
34
  "typescript": "^5",
32
35
  "vite-plus": "latest",
33
- "@healthzkit/shared": "0.0.0",
34
36
  "healthzkit": "0.0.3"
35
37
  },
36
38
  "peerDependencies": {
@@ -1 +0,0 @@
1
- function e(e,t){return{status:`ok`,metadata:{...t,latencyMs:e}}}function t(e){return{status:`fail`,error:e instanceof Error?e:Error(String(e))}}export{t as n,e as t};
@@ -1,16 +0,0 @@
1
- import { HealthAdapter } from "healthzkit";
2
-
3
- //#region ../../tools/shared/dist/index.d.mts
4
- //#region src/index.d.ts
5
- type MetadataFn<TClient> = (client: TClient) => Promise<Record<string, unknown>> | Record<string, unknown>;
6
- //#endregion
7
- //#region src/shared.d.ts
8
- interface BaseMongoOptions<TClient> {
9
- /**
10
- * Optional function to populate metadata in the check result.
11
- * Receives the resolved client so you can run additional queries.
12
- */
13
- metadata?: MetadataFn<TClient>;
14
- }
15
- //#endregion
16
- export { HealthAdapter as n, BaseMongoOptions as t };