-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/compt 82 custom indicator api and health service #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
afcf4dd
2e42a1d
f856137
c74b8ae
41d7af3
8f9af5e
5dff0e2
af6f235
a5d8377
914f341
60eedae
7891e1e
b9e39f6
dbe9e52
801e648
2e5d559
83cd1d6
0b633fa
10b4423
4fdefba
bbb1f18
80cdcaf
e29be84
eff4978
a73cb21
7898821
543a07a
63c1336
f8e8e01
d4947d7
36a99ab
15c05f7
042c48c
f63633f
052cecf
86f470c
8eae15f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1 @@ | ||
| #!/usr/bin/env sh | ||
| . "$(dirname -- "$0")/_/husky.sh" | ||
|
|
||
| npx lint-staged | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,80 @@ | ||
| // @ts-check | ||
| import eslint from "@eslint/js"; | ||
| import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended"; | ||
| import globals from "globals"; | ||
| import importPlugin from "eslint-plugin-import"; | ||
| import tseslint from "typescript-eslint"; | ||
|
|
||
| export default tseslint.config( | ||
| export default [ | ||
| { | ||
| ignores: ["eslint.config.mjs"], | ||
| ignores: [ | ||
| "dist/**", | ||
| "coverage/**", | ||
| "node_modules/**", | ||
| // Ignore all example files for CSR architecture | ||
| "src/example-kit.*", | ||
| "src/controllers/example.controller.ts", | ||
| "src/services/example.service.ts", | ||
| "src/entities/example.entity.ts", | ||
| "src/repositories/example.repository.ts", | ||
| "src/guards/example.guard.ts", | ||
| "src/decorators/example.decorator.ts", | ||
| "src/dto/create-example.dto.ts", | ||
| "src/dto/update-example.dto.ts", | ||
| ], | ||
| }, | ||
|
|
||
| eslint.configs.recommended, | ||
| ...tseslint.configs.recommendedTypeChecked, | ||
| eslintPluginPrettierRecommended, | ||
|
|
||
| // TypeScript ESLint (includes recommended rules) | ||
| ...tseslint.configs.recommended, | ||
|
|
||
| // Base TS rules (all TS files) | ||
| { | ||
| files: ["**/*.ts"], | ||
| languageOptions: { | ||
| globals: { | ||
| ...globals.node, | ||
| ...globals.jest, | ||
| }, | ||
| sourceType: "commonjs", | ||
| parser: tseslint.parser, | ||
| parserOptions: { | ||
| projectService: true, | ||
| project: "./tsconfig.eslint.json", | ||
| tsconfigRootDir: import.meta.dirname, | ||
| ecmaVersion: "latest", | ||
| sourceType: "module", | ||
| }, | ||
| globals: { ...globals.node, ...globals.jest }, | ||
| }, | ||
| plugins: { | ||
| "@typescript-eslint": tseslint.plugin, | ||
| import: importPlugin, | ||
| }, | ||
| rules: { | ||
| "@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }], | ||
| "@typescript-eslint/consistent-type-imports": ["error", { prefer: "type-imports" }], | ||
|
|
||
| "import/no-duplicates": "error", | ||
| "import/order": [ | ||
| "error", | ||
| { | ||
| "newlines-between": "always", | ||
| alphabetize: { order: "asc", caseInsensitive: true }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
|
|
||
| // Architecture boundary: core must not import Nest | ||
| { | ||
| files: ["src/core/**/*.ts"], | ||
| rules: { | ||
| "@typescript-eslint/no-explicit-any": "off", | ||
| "@typescript-eslint/no-floating-promises": "warn", | ||
| "@typescript-eslint/no-unsafe-argument": "warn", | ||
| "@typescript-eslint/no-unused-vars": [ | ||
| "no-restricted-imports": [ | ||
| "error", | ||
| { | ||
| argsIgnorePattern: "^_", | ||
| varsIgnorePattern: "^_", | ||
| patterns: [ | ||
| { | ||
| group: ["@nestjs/*"], | ||
| message: "Do not import NestJS in core/. Keep core framework-free.", | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| "no-unused-vars": "off", | ||
| }, | ||
| }, | ||
| ); | ||
| ]; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| "name": "@ciscode/nestjs-developerkit", | ||||||||||||||||||||||||||
| "name": "@ciscode/health-kit", | ||||||||||||||||||||||||||
| "version": "1.0.0", | ||||||||||||||||||||||||||
| "description": "Template for NestJS developer kits (npm packages).", | ||||||||||||||||||||||||||
| "description": "NestJS health-check module — liveness & readiness probes with built-in PostgreSQL, Redis, and HTTP indicators.", | ||||||||||||||||||||||||||
| "author": "CisCode", | ||||||||||||||||||||||||||
|
Comment on lines
1
to
5
|
||||||||||||||||||||||||||
| "publishConfig": { | ||||||||||||||||||||||||||
| "access": "public" | ||||||||||||||||||||||||||
|
|
@@ -45,10 +45,15 @@ | |||||||||||||||||||||||||
| "peerDependencies": { | ||||||||||||||||||||||||||
| "@nestjs/common": "^10 || ^11", | ||||||||||||||||||||||||||
| "@nestjs/core": "^10 || ^11", | ||||||||||||||||||||||||||
| "@nestjs/platform-express": "^10 || ^11", | ||||||||||||||||||||||||||
| "@nestjs/terminus": "^10 || ^11", | ||||||||||||||||||||||||||
| "reflect-metadata": "^0.2.2", | ||||||||||||||||||||||||||
| "rxjs": "^7" | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| "peerDependenciesMeta": { | ||||||||||||||||||||||||||
| "@nestjs/terminus": { | ||||||||||||||||||||||||||
| "optional": true | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
|
Comment on lines
+48
to
+56
|
||||||||||||||||||||||||||
| "@nestjs/terminus": "^10 || ^11", | |
| "reflect-metadata": "^0.2.2", | |
| "rxjs": "^7" | |
| }, | |
| "peerDependenciesMeta": { | |
| "@nestjs/terminus": { | |
| "optional": true | |
| } | |
| }, | |
| "reflect-metadata": "^0.2.2", | |
| "rxjs": "^7" | |
| }, |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,62 @@ | ||||||||||
| import { ServiceUnavailableException } from "@nestjs/common"; | ||||||||||
| import type { TestingModule } from "@nestjs/testing"; | ||||||||||
| import { Test } from "@nestjs/testing"; | ||||||||||
| import { HealthService } from "@services/health.service"; | ||||||||||
| import type { HealthCheckResult } from "@services/health.service"; | ||||||||||
|
|
||||||||||
| import { createHealthController } from "./health.controller"; | ||||||||||
|
|
||||||||||
| // ── Helpers ────────────────────────────────────────────────────────────────── | ||||||||||
|
|
||||||||||
| const makeService = (liveness: "ok" | "error", readiness: "ok" | "error") => | ||||||||||
| ({ | ||||||||||
| checkLiveness: jest.fn().mockResolvedValue({ status: liveness, indicators: [] }), | ||||||||||
| checkReadiness: jest.fn().mockResolvedValue({ status: readiness, indicators: [] }), | ||||||||||
|
Comment on lines
+13
to
+14
|
||||||||||
| checkLiveness: jest.fn().mockResolvedValue({ status: liveness, indicators: [] }), | |
| checkReadiness: jest.fn().mockResolvedValue({ status: readiness, indicators: [] }), | |
| checkLiveness: jest.fn().mockResolvedValue({ status: liveness, results: [] }), | |
| checkReadiness: jest.fn().mockResolvedValue({ status: readiness, results: [] }), |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||||||
| import { | ||||||||||
| Controller, | ||||||||||
| Get, | ||||||||||
| HttpCode, | ||||||||||
| HttpStatus, | ||||||||||
| ServiceUnavailableException, | ||||||||||
| Type, | ||||||||||
| } from "@nestjs/common"; | ||||||||||
|
Comment on lines
+7
to
+8
|
||||||||||
| Type, | |
| } from "@nestjs/common"; | |
| } from "@nestjs/common"; | |
| import type { Type } from "@nestjs/common"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import "reflect-metadata"; | ||
| import { HEALTH_INDICATOR_METADATA, HealthIndicator } from "./health-indicator.decorator"; | ||
|
|
||
| class SomeIndicator {} | ||
|
Check warning on line 4 in src/decorators/health-indicator.decorator.spec.ts
|
||
| class AnotherIndicator {} | ||
|
Check warning on line 5 in src/decorators/health-indicator.decorator.spec.ts
|
||
| class UndecotratedIndicator {} | ||
|
Check warning on line 6 in src/decorators/health-indicator.decorator.spec.ts
|
||
|
|
||
|
Comment on lines
+4
to
+7
|
||
| @HealthIndicator("liveness") | ||
| class LivenessIndicator extends SomeIndicator {} | ||
|
|
||
| @HealthIndicator("readiness") | ||
| class ReadinessIndicator extends AnotherIndicator {} | ||
|
|
||
| describe("@HealthIndicator decorator", () => { | ||
| it("attaches liveness metadata to the target class", () => { | ||
| const scope = Reflect.getMetadata(HEALTH_INDICATOR_METADATA, LivenessIndicator); | ||
| expect(scope).toBe("liveness"); | ||
| }); | ||
|
|
||
| it("attaches readiness metadata to the target class", () => { | ||
| const scope = Reflect.getMetadata(HEALTH_INDICATOR_METADATA, ReadinessIndicator); | ||
| expect(scope).toBe("readiness"); | ||
| }); | ||
|
|
||
| it("returns undefined for undecorated classes", () => { | ||
| const scope = Reflect.getMetadata(HEALTH_INDICATOR_METADATA, UndecotratedIndicator); | ||
| expect(scope).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("does not affect other classes when decorating one", () => { | ||
| const livScope = Reflect.getMetadata(HEALTH_INDICATOR_METADATA, LivenessIndicator); | ||
| const readScope = Reflect.getMetadata(HEALTH_INDICATOR_METADATA, ReadinessIndicator); | ||
| expect(livScope).toBe("liveness"); | ||
| expect(readScope).toBe("readiness"); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hook no longer has a shebang or Husky bootstrap (
.husky.sh). Git executes hooks as programs; without#!/usr/bin/env shthis commonly fails with an "exec format" error, and without the Husky bootstrap you may lose environment setup. Restore the standard Husky header and then runnpx lint-staged.