commit 7375b4d96fc83c87b6e02a31de535603c1d4c671 Author: Elijah Duffy Date: Wed Dec 24 16:59:16 2025 -0800 initial commit & scaffold diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000..4346e8c --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,17 @@ +module.exports = { + root: true, + env: { + node: true, + es2021: true, + }, + parser: '@typescript-eslint/parser', + plugins: ['@typescript-eslint', 'prettier'], + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:prettier/recommended', + ], + rules: { + 'prettier/prettier': 'error', + }, +}; diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..624ae04 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# Node +node_modules/ +packages/*/node_modules/ +.pnpm-store/ +.pnpm-debug.log +pnpm-lock.yaml + +# TypeScript +dist/ +**/dist/ +**/*.tsbuildinfo + +# Go +**/vendor/ +**/*.exe +**/*.out + +# Misc +.env +.DS_Store diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..de2d0d9 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,6 @@ +node_modules +dist +coverage +.env +**/vendor +**/*.pb.go diff --git a/.prettierrc.cjs b/.prettierrc.cjs new file mode 100644 index 0000000..4a3b1a5 --- /dev/null +++ b/.prettierrc.cjs @@ -0,0 +1,8 @@ +module.exports = { + arrowParens: 'always', + singleQuote: true, + trailingComma: 'all', + printWidth: 100, + useTabs: true, + semi: true, +}; diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e32b877 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2025 Elijah Duffy + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..bf5c2b9 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# health (monorepo) + +This repository contains small helper libraries for liveness and readiness checks for different languages and runtimes. + +## Structure + +Repository root contains health packages for each different language or runtime, formatted `-health`. diff --git a/go-health/README.md b/go-health/README.md new file mode 100644 index 0000000..36a5a33 --- /dev/null +++ b/go-health/README.md @@ -0,0 +1 @@ +# go-health diff --git a/go-health/go.mod b/go-health/go.mod new file mode 100644 index 0000000..5389852 --- /dev/null +++ b/go-health/go.mod @@ -0,0 +1,3 @@ +module gitea.auvem.com/end/health/go-health + +go 1.25 diff --git a/go-health/health.go b/go-health/health.go new file mode 100644 index 0000000..b2c91c4 --- /dev/null +++ b/go-health/health.go @@ -0,0 +1 @@ +package health diff --git a/node-health/.eslintrc.cjs b/node-health/.eslintrc.cjs new file mode 100644 index 0000000..af37e6c --- /dev/null +++ b/node-health/.eslintrc.cjs @@ -0,0 +1,10 @@ +module.exports = { + root: true, + extends: ['../../.eslintrc.cjs'], + parserOptions: { + project: './tsconfig.json', + }, + rules: { + // package-level overrides + }, +}; diff --git a/node-health/.prettierrc.cjs b/node-health/.prettierrc.cjs new file mode 100644 index 0000000..61cdb7c --- /dev/null +++ b/node-health/.prettierrc.cjs @@ -0,0 +1 @@ +module.exports = require('../.prettierrc.cjs'); diff --git a/node-health/README.md b/node-health/README.md new file mode 100644 index 0000000..5d6aa84 --- /dev/null +++ b/node-health/README.md @@ -0,0 +1 @@ +# @health/node diff --git a/node-health/package.json b/node-health/package.json new file mode 100644 index 0000000..b69ea16 --- /dev/null +++ b/node-health/package.json @@ -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": {} +} diff --git a/node-health/src/index.ts b/node-health/src/index.ts new file mode 100644 index 0000000..30365a9 --- /dev/null +++ b/node-health/src/index.ts @@ -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 }> +): Promise { + 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 }; +} diff --git a/node-health/tsconfig.json b/node-health/tsconfig.json new file mode 100644 index 0000000..423a872 --- /dev/null +++ b/node-health/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../tsconfig.base.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "dist", + "composite": false + }, + "include": ["src/**/*"] +} diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 0000000..a5bb569 --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ES2021", + "module": "ES2020", + "moduleResolution": "node", + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true + } +}