initial commit & scaffold
This commit is contained in:
10
node-health/.eslintrc.cjs
Normal file
10
node-health/.eslintrc.cjs
Normal file
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
extends: ['../../.eslintrc.cjs'],
|
||||
parserOptions: {
|
||||
project: './tsconfig.json',
|
||||
},
|
||||
rules: {
|
||||
// package-level overrides
|
||||
},
|
||||
};
|
||||
1
node-health/.prettierrc.cjs
Normal file
1
node-health/.prettierrc.cjs
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('../.prettierrc.cjs');
|
||||
1
node-health/README.md
Normal file
1
node-health/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# @health/node
|
||||
19
node-health/package.json
Normal file
19
node-health/package.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "@health/node",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.json",
|
||||
"lint": "eslint --ext .ts,.js src",
|
||||
"format": "prettier --write \"src/**/*.{ts,js,json}\"",
|
||||
"test": "echo \"No tests configured\" && exit 0",
|
||||
"check": "npm run lint && npm run build"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {}
|
||||
}
|
||||
30
node-health/src/index.ts
Normal file
30
node-health/src/index.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Simple liveness & readiness helpers
|
||||
*/
|
||||
|
||||
export type ReadinessResult = {
|
||||
ok: boolean;
|
||||
details: { name: string; ok: boolean; error?: string }[];
|
||||
};
|
||||
|
||||
export function liveness() {
|
||||
return {
|
||||
status: 'ok',
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
}
|
||||
|
||||
export async function readiness(
|
||||
checks: Array<{ name: string; fn: () => Promise<boolean> | boolean }>
|
||||
): Promise<ReadinessResult> {
|
||||
const results: ReadinessResult['details'] = [];
|
||||
for (const c of checks) {
|
||||
try {
|
||||
const r = await Promise.resolve(c.fn());
|
||||
results.push({ name: c.name, ok: !!r });
|
||||
} catch (err: any) {
|
||||
results.push({ name: c.name, ok: false, error: err?.message ?? String(err) });
|
||||
}
|
||||
}
|
||||
return { ok: results.every((r) => r.ok), details: results };
|
||||
}
|
||||
9
node-health/tsconfig.json
Normal file
9
node-health/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "dist",
|
||||
"composite": false
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
Reference in New Issue
Block a user