Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7a2465d

Browse files
committed
chore: remove jsdoctor scripts
1 parent e0360da commit 7a2465d

33 files changed

Lines changed: 505 additions & 190 deletions

API_REFERENCE.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This file catalogs every public export from `@git-stunts/trailer-codec` so you c
88
- Deprecated convenience wrapper around `new TrailerCodec().decode(message)`.
99
- Input: a raw commit payload (title, optional body, trailers) as a string.
1010
- Output: `{ title: string, body: string, trailers: Record<string, string> }` where `body` is trimmed via `formatBodySegment` (see below) and trailer keys are normalized to lowercase.
11-
- Throws `ValidationError` for invalid titles, missing blank-line separators, oversized messages, or malformed trailers.
11+
- Throws `TrailerCodecError` subclasses (e.g., `TrailerNoSeparatorError`, `TrailerValueInvalidError`, or `CommitMessageInvalidError`) for invalid titles, missing blank lines, oversized messages, or malformed trailers.
1212

1313
### `encodeMessage({ title: string, body?: string, trailers?: Record<string, string> })`
1414
-- Deprecated convenience wrapper around `new TrailerCodec().encode(payload)`.
@@ -47,7 +47,7 @@ new GitCommitMessage(
4747
### `GitTrailer`
4848
- Accepts `(key: string, value: string, schema = GitTrailerSchema)`.
4949
- Validates using `GitTrailerSchema` and normalizes the key to lowercase and the value to a trimmed string.
50-
- Throws `ValidationError` with codes `TRAILER_INVALID` or `TRAILER_VALUE_INVALID` if the provided data fails schema validation.
50+
- Throws `TrailerInvalidError` or `TrailerValueInvalidError` when the provided key/value fail schema validation.
5151

5252
## Services & parsers
5353

@@ -79,18 +79,15 @@ new GitCommitMessage(
7979
## Errors
8080

8181
### `TrailerCodecError`
82-
- Base error type used by `ValidationError`.
83-
- Signature: `(message: string, code: string, meta: Record<string, unknown> = {})`.
82+
- Base error type used throughout the codec (`index.js` re-exports it).
83+
- Signature: `(message: string, meta: Record<string, unknown> = {})`.
8484

85-
### `ValidationError`
86-
- Extends `TrailerCodecError` and introduces the following codes:
85+
### Validation error subclasses
8786

88-
| Code | Thrown by | Meaning |
87+
| Error | Thrown by | Meaning |
8988
| --- | --- | --- |
90-
| `TRAILER_TOO_LARGE` | `MessageNormalizer.guardMessageSize` (called by `TrailerCodecService.decode` and the exported `decodeMessage`) | Message exceeds the 5 MB guard in `MessageNormalizer`. |
91-
| `TRAILER_NO_SEPARATOR` | `TrailerParser.split` / `TrailerCodecService.decode` when the blank-line guard fails | A trailer block was found without a blank line separating it from the body (see `TrailerParser`). |
92-
| `TRAILER_VALUE_INVALID` | `GitTrailer` via `GitTrailerSchema.parse` when constructing trailers | A trailer value violated the `GitTrailerSchema` (e.g., contained `\n`). |
93-
| `TRAILER_INVALID` | `GitTrailer` via `GitTrailerSchema.parse` when constructing trailers | Trailer key or value failed validation (`GitTrailerSchema`). |
94-
| `COMMIT_MESSAGE_INVALID` | `GitCommitMessage` via `GitCommitMessageSchema.parse` (triggered by `TrailerCodecService.decode` or `encode`) | The `GitCommitMessageSchema` rejected the title/body/trailers combination. |
95-
96-
The thrown `ValidationError` exposes `code` and `meta` for programmatic recovery; refer to `docs/SERVICE.md` or `README.md#validation-error-codes` for how to react in your integration.
89+
| `TrailerTooLargeError` | `MessageNormalizer.guardMessageSize` (called by `TrailerCodecService.decode` and the exported `decodeMessage`) | Message exceeds the 5 MB guard in `MessageNormalizer`. |
90+
| `TrailerNoSeparatorError` | `TrailerParser.split` / `TrailerCodecService.decode` when the blank-line guard fails | A trailer block was found without a blank line separating it from the body (see `TrailerParser`). |
91+
| `TrailerValueInvalidError` | `GitTrailer` via `GitTrailerSchema.parse` when constructing trailers | A trailer value violated the `GitTrailerSchema` (e.g., contained `\n`). |
92+
| `TrailerInvalidError` | `GitTrailer` via `GitTrailerSchema.parse` when constructing trailers | Trailer key or value failed validation (`GitTrailerSchema`). |
93+
| `CommitMessageInvalidError` | `GitCommitMessage` via `GitCommitMessageSchema.parse` (triggered by `TrailerCodecService.decode` or `encode`) | The `GitCommitMessageSchema` rejected the title/body/trailers combination. |

ARCHITECTURE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The core business logic, isolated from external frameworks or I/O.
1010
- **Entities**: Mutable objects with identity and lifecycle (e.g., `GitCommitMessage`).
1111
- **Value Objects**: Immutable objects defined by their attributes (e.g., `GitTrailer`).
1212
- **Services**: Domain logic that doesn't fit naturally into an entity (e.g., `TrailerCodecService` for parsing/serializing).
13-
- **Errors**: Domain-specific error hierarchy (e.g., `TrailerCodecError`, `ValidationError`).
13+
- **Errors**: Domain-specific error hierarchy (`TrailerCodecError` plus concrete subclasses such as `TrailerNoSeparatorError` and `TrailerValueInvalidError`).
1414
- **Schemas**: Zod schemas for validation of domain objects.
1515

1616
### Ports Layer (`src/ports/`)
@@ -22,7 +22,7 @@ The core business logic, isolated from external frameworks or I/O.
2222
src/
2323
├── domain/
2424
│ ├── entities/ # GitCommitMessage
25-
│ ├── errors/ # TrailerCodecError, ValidationError
25+
│ ├── errors/ # TrailerCodecError and validation subclasses
2626
│ ├── schemas/ # Zod schemas
2727
│ ├── services/ # TrailerCodecService
2828
│ └── value-objects/ # GitTrailer
@@ -35,6 +35,6 @@ src/
3535

3636
## 🛠️ Design Decisions
3737

38-
1. **Zod for Validation**: We use Zod for runtime schema validation but wrap it in domain-specific `ValidationError`s to avoid leaking implementation details.
38+
1. **Zod for Validation**: We use Zod for runtime schema validation but wrap it in domain-specific `TrailerCodecError` subclasses to avoid leaking implementation details.
3939
2. **Case Normalization**: Git trailer keys are case-insensitive. We normalize them to lowercase in the `GitTrailer` Value Object to ensure consistency.
4040
3. **Facade Pattern**: `index.js` acts as a facade, providing a simple, backward-compatible API while exposing the rich domain model for advanced users.

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Tightened trailer validation (newline-free values) and exposed the schema bundle to service/fixtures, pairing with the new helper wrappers.
2121
- Removed the docker guard dependency so tests run locally without the external guard enforcement.
2222
- Upgraded `zod` dependency to the latest 3.25.x release.
23-
- Added ValidationError codes (TRAILER_TOO_LARGE, TRAILER_NO_SEPARATOR, TRAILER_VALUE_INVALID, TRAILER_INVALID, COMMIT_MESSAGE_INVALID) for granular error diagnostics.
23+
- Added dedicated validation error classes (`TrailerTooLargeError`, `TrailerNoSeparatorError`, `TrailerValueInvalidError`, `TrailerInvalidError`, `CommitMessageInvalidError`) for granular diagnostics.
2424
- Updated `decode()` to accept raw strings with a deprecation warning when the legacy object form is used.
2525

2626

CONTINUE.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# CONTINUE
2+
3+
## Current focus
4+
- Auditing README.md and related docs for accuracy, topic coverage, and developer onboarding completeness.
5+
- Ensuring the `docs/` tree (ADVANCED, SERVICE, INTEGRATION, etc.) reflects the actual exports/behaviors in `src/` and covers validation errors, helper exports, and the service pipeline described in the audit prompts.
6+
- Stabilizing service helpers (MessageNormalizer, TitleExtractor, BodyComposer, TrailerParser) and domain objects (ValidationError refactor to specific subclasses, GitTrailer, GitCommitMessage) before wiring them back into TrailerCodecService.
7+
- Planning the long list of fix/cleanup tasks (JSDoc coverage, README reorganizations, new docs, tests) that the prompts outlined but have not yet been committed.
8+
9+
## Progress so far
10+
- Several source files have been touched (`CodecBuilder`, `FacadeAdapter`, domain helpers/services, tests) though the work is mid-flight.
11+
- New custom error classes plus the docs mention these files, but the repo is currently a mix of trailer-codec logic and early-stage `jsdoctor` experimentation (scripts/, utils/ folder, etc.).
12+
- There is a big ongoing audit and documentation cleanup, making the codebase look unstable—this is why we need to pause here before introducing a major refactor.
13+
14+
## Why the pause
15+
- We want to **purify trailer-codec** by removing/reorganizing the `jsdoctor`-related experiments and then hand off a clean repo that can continue evolving on its own.
16+
- The user explicitly requested we shift context to the new `jsdoctor` repo, ensuring that the latest doc/LLM tooling lives there instead of being scattered here.
17+
- We need to trace whether the `jsdoctor` code already exists elsewhere (the new repo) before deleting it from this repo, to avoid losing work.
18+
19+
## Next steps when returning
20+
1. Sweep `src/`/`docs/` to finish the remaining audit points (Accuracy, docs updates, error classes, tests, etc.).
21+
2. Complete the requested README/docs/CHANGELOG updates, plus missing files (`TESTING.md`, `API_REFERENCE.md`, etc.).
22+
3. Ensure the newly created error classes/tests are in their final shape and fix test coverage regressions.
23+
4. After finishing this cleanup, determine if any `jsdoctor` code still needs migration back into trailer-codec before the final handoff.
24+
5. Re-assess `CONTINUE.md` and update it with whichever parts are unfinished at that point.
25+
26+
>> Note: We are now switching to the `jsdoctor` repo to continue the new 'Bobs' tooling work—treat this note as the single source of truth for where we left off here.

README.md

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -149,36 +149,36 @@ console.log(msg.toString());
149149
- `createMessageHelpers({ service, bodyFormatOptions })` returns `{ decodeMessage, encodeMessage }` bound to the provided `TrailerCodecService`; pass `bodyFormatOptions` to control whether decoded bodies keep their trailing newline.
150150
- `TrailerCodec` wraps `createMessageHelpers()` so you can instantiate a codec class with custom `service` or `bodyFormatOptions` and still leverage the helper contract via `encode()`/`decode()`.
151151
- `createConfiguredCodec({ keyPattern, keyMaxLength, parserOptions, formatters, bodyFormatOptions })` wires together `createGitTrailerSchemaBundle`, `TrailerParser`, `TrailerCodecService`, and the helper pair, letting you configure key validation, parser heuristics, formatting hooks, and body formatting in a single call.
152-
- `TrailerCodecService` exposes the schema bundle, parser, trailer factory, formatter hooks, and helper classes (`MessageNormalizer`, `TitleExtractor`, `BodyComposer`); see `docs/SERVICE.md` for a deeper explanation of how to customize each stage without touching the core service.
152+
- `TrailerCodecService` exposes the schema bundle, parser, trailer factory, formatter hooks, and helper utilities (`MessageNormalizer`, `extractTitle`, `composeBody`); see `docs/SERVICE.md` for a deeper explanation of how to customize each stage without touching the core service.
153153

154154
## ✅ Validation Rules
155155

156-
Trailer codec enforces strict validation:
156+
Trailer codec enforces strict validation via the concrete subclasses of `TrailerCodecError`:
157157

158-
| Rule | Constraint | Error Type |
159-
|------|-----------|------------|
160-
| **Message Size** | ≤ 5MB | `ValidationError` |
161-
| **Title** | Must be non-empty string | `ValidationError` |
162-
| **Trailer Key** | Alphanumeric, hyphens, underscores only (`/^[A-Za-z0-9_-]+$/`) | `ValidationError` |
163-
| **Key Length** | ≤ 100 characters (prevents ReDoS) | `ValidationError` |
164-
| **Trailer Value** | Must be non-empty string | `ValidationError` |
158+
| Rule | Constraint | Thrown Error |
159+
|------|------------|--------------|
160+
| **Message Size** | ≤ 5MB | `TrailerTooLargeError` |
161+
| **Title** | Must be a non-empty string | `CommitMessageInvalidError` (during entity construction) |
162+
| **Trailer Key** | Alphanumeric, hyphens, underscores only (`/^[A-Za-z0-9_-]+$/`) and ≤ 100 characters (prevents ReDoS) | `TrailerInvalidError` |
163+
| **Trailer Value** | Cannot contain carriage returns or line feeds and must not be empty | `TrailerValueInvalidError` |
165164

166165
**Key Normalization:** All trailer keys are automatically normalized to lowercase (e.g., `Signed-Off-By``signed-off-by`).
167166

168-
**Blank-Line Guard:** Trailers must be separated from the body by a blank line; committing without that empty line results in a `ValidationError`.
167+
**Blank-Line Guard:** Trailers must be separated from the body by a blank line; omitting the separator throws `TrailerNoSeparatorError`.
169168

170-
**Trailer Line Limits:** Trailer values cannot contain carriage returns or line feeds.
169+
### Validation Errors
171170

172-
### Validation Error Codes
171+
When `TrailerCodecService` or the exported helpers throw, they surface one of the following classes so you can recover with `instanceof` checks:
173172

174-
| Code | Trigger | Suggested Fix |
173+
| Error | Trigger | Suggested Fix |
175174
| --- | --- | --- |
176-
| `TRAILER_TOO_LARGE` | Message exceeds 5MB | Split the commit or remove content until the payload fits |
177-
| `TRAILER_NO_SEPARATOR` | Missing blank line before trailers | Insert an empty line between the body and the trailer metadata |
178-
| `TRAILER_VALUE_INVALID` | Trailer value contains newline characters | Remove newlines from the value before encoding |
179-
| `TRAILER_INVALID` | Trailer key or value fails schema validation | Adjust the key/value or pass a custom schema bundle via `TrailerCodecService` |
175+
| `TrailerTooLargeError` | Message exceeds 5MB while `MessageNormalizer.guardMessageSize()` runs | Split the commit or remove content until the payload fits. |
176+
| `TrailerNoSeparatorError` | Missing blank line before trailers when `TrailerParser.split()` runs | Insert the required empty line between body and trailers. |
177+
| `TrailerValueInvalidError` | Trailer value includes newline characters or fails the schema value rules | Remove or escape newline characters before encoding. |
178+
| `TrailerInvalidError` | Trailer key/value pair fails the schema validation (`GitTrailerSchema`) | Adjust the key/value or supply a custom schema bundle via `TrailerCodecService`. |
179+
| `CommitMessageInvalidError` | `GitCommitMessageSchema` rejects the full payload (title/body/trailers) | Fix the invalid field or pass a conforming payload; use formatters if needed. |
180180

181-
Each code appears on the thrown `ValidationError` (`src/domain/errors/ValidationError.js`), so you can read `error.code` and `error.meta` to respond. See `API_REFERENCE.md#validation-errors` for the class signature and recommended recovery guidance for each code.
181+
All of the above inherit from `TrailerCodecError` (`src/domain/errors/TrailerCodecError.js`) and expose `meta` for diagnostics; prefer checking the specific class instead of inspecting `code`.
182182

183183
## 🛡️ Security
184184

@@ -192,15 +192,13 @@ See [SECURITY.md](SECURITY.md) for details.
192192

193193
## 📚 Additional Documentation
194194

195-
- [`docs/ADVANCED.md`](docs/ADVANCED.md) — Custom schema injection, validation overrides, and advanced integration patterns
196-
- [`docs/PARSER.md`](docs/PARSER.md) — Step-by-step explanation of the backward-walk parser
197-
- [`docs/MIGRATION.md`](docs/MIGRATION.md) — Notes for upgrading from earlier versions
198-
- [`docs/PERFORMANCE.md`](docs/PERFORMANCE.md) — Micro-benchmark insights
199-
- [`docs/RELEASE.md`](docs/RELEASE.md) — Checklist for version bumps and npm publishing
200-
- [`docs/INTEGRATION.md`](docs/INTEGRATION.md) — Git log scripting, streaming decoder, and Git-CMS filtering recipes
201-
- [`docs/SERVICE.md`](docs/SERVICE.md) — How `TrailerCodecService` wires schema, parser, and formatter helpers for customization
202-
- [`API_REFERENCE.md`](API_REFERENCE.md) — Complete catalog of the public exports, their inputs/outputs, and notable knobs
203-
- [`TESTING.md`](TESTING.md) — How to run/extend the Vitest, lint, and format scripts plus contributor tips
195+
- [`docs/ADVANCED.md`](docs/ADVANCED.md) — Custom schema injection, validation overrides, and advanced integration patterns.
196+
- [`docs/PARSER.md`](docs/PARSER.md) — Step-by-step explanation of the backward-walk parser.
197+
- [`docs/INTEGRATION.md`](docs/INTEGRATION.md) — Git log scripting, streaming decoder, and Git-CMS filtering recipes.
198+
- [`docs/SERVICE.md`](docs/SERVICE.md) — How `TrailerCodecService` wires schema, parser, and formatter helpers for customization.
199+
- [`API_REFERENCE.md`](API_REFERENCE.md) — Complete catalog of the public exports, their inputs/outputs, and notable knobs.
200+
- [`TESTING.md`](TESTING.md) — How to run/extend the Vitest, lint, and format scripts plus contributor tips.
201+
- **Git hooks**: Run `npm run setuphooks` once per clone to point `core.hooksPath` at `scripts/`. The hook now runs just `npm run lint` and `npm run format` before each commit.
204202

205203
## 📄 License
206204

docs/INTEGRATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Integration Guide
22

3-
`decodeMessage()` returns `{ title: string, body: string, trailers: Record<string,string> }` (see `API_REFERENCE.md#encoding--decoding-helpers`). `.title` is the first commit line, `.body` trims leading/trailing blanks to provide the content between title and trailers, and `.trailers` is an object of normalized lowercase keys (empty when no trailers exist). `formatBodySegment(segment)` expects a string and returns the trimmed segment, optionally keeping a trailing newline when `keepTrailingNewline: true`. `decodeMessage()` throws `ValidationError` on malformed input instead of returning an error object, so callers should wrap calls in try/catch if they want to handle validation failures gracefully.
3+
`decodeMessage()` returns `{ title: string, body: string, trailers: Record<string,string> }` (see `API_REFERENCE.md#encoding--decoding-helpers`). `.title` is the first commit line, `.body` trims leading/trailing blanks to provide the content between title and trailers, and `.trailers` is an object of normalized lowercase keys (empty when no trailers exist). `formatBodySegment(segment)` expects a string and returns the trimmed segment, optionally keeping a trailing newline when `keepTrailingNewline: true`. `decodeMessage()` throws validation subclasses such as `TrailerNoSeparatorError`, `TrailerValueInvalidError`, or `CommitMessageInvalidError` instead of returning an error object, so callers should wrap calls in try/catch if they want to handle failures gracefully.
44

55
Blend `@git-stunts/trailer-codec` with Git history and tooling to treat commit trailers as structured metadata.
66

docs/PARSER.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The parser in `TrailerCodecService.decode()` walks **backwards** from the bottom
77
1. **Normalize line endings** to `\n` and split the message.
88
2. **Consume the title** (the first line) and drop the optional blank line that separates it from the body.
99
3. **Walk backward** with `_findTrailerStartIndex` until either a non-matching line or an empty line appears; contiguous `Key: Value` patterns form the trailer block.
10-
4. **Validate the separator**: `_validateTrailerSeparation` ensures there is a blank line before the trailers. Messages that omit the blank line now throw `ValidationError`.
10+
4. **Validate the separator**: `_validateTrailerSeparation` ensures there is a blank line before the trailers. Messages that omit the blank line now throw `TrailerNoSeparatorError`.
1111
5. **Trim the body** without double allocations: `_trimBody` trims leading/trailing blank lines via index arithmetic and one `join`.
1212
6. **Parse trailers** using the schema bundle’s `keyPattern`, instantiating trailers via the injected `trailerFactory`.
1313

0 commit comments

Comments
 (0)