Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.0.4] - 2026-06-24

### Added
- **TypeScript declarations**: Published first-class root declarations for the async v3 public API and wired the package `types` export to `index.d.ts`.

## [3.0.3] - 2026-05-06

### Fixed
Expand Down
183 changes: 183 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
import type { ZodSchema } from 'zod';

export interface GitTrailerJson {
key: string;
value: string;
}

export interface GitCommitMessageInput {
title: string;
body?: string;
trailers?: Array<GitTrailerJson | GitTrailer>;
}

export interface MessageFormatters {
titleFormatter?: (value: string) => string;
bodyFormatter?: (value: string) => string;
}

export interface GitCommitMessageOptions {
trailerSchema?: ZodSchema;
formatters?: MessageFormatters;
}

export class GitCommitMessage {
constructor(payload: GitCommitMessageInput, options?: GitCommitMessageOptions);

readonly title: string;
readonly body: string;
readonly trailers: GitTrailer[];

toString(): string;
toJSON(): {
title: string;
body: string;
trailers: GitTrailerJson[];
};
}

export class GitTrailer {
constructor(key: string, value: string, schema?: ZodSchema);

readonly key: string;
readonly value: string;

toString(): string;
toJSON(): GitTrailerJson;
}

export class TrailerCodecError extends Error {
constructor(message: string, meta?: Record<string, unknown>);

readonly meta: Record<string, unknown>;
}

export interface TrailerSchemaBundle {
schema: ZodSchema<GitTrailerJson>;
keyPattern: string;
keyRegex: RegExp;
}

export interface TrailerSchemaBundleOptions {
keyPattern?: string | RegExp;
keyMaxLength?: number;
}

export function createGitTrailerSchemaBundle(
options?: TrailerSchemaBundleOptions
): TrailerSchemaBundle;

export const TRAILER_KEY_RAW_PATTERN_STRING: string;
export const TRAILER_KEY_REGEX: RegExp;

export interface TrailerParserOptions {
keyPattern?: string;
}

export interface TrailerParserSplitResult {
trailerStart: number;
bodyLines: string[];
trailerLines: string[];
}

export class TrailerParser {
constructor(options?: TrailerParserOptions);

readonly lineRegex: RegExp;

split(lines: string[]): TrailerParserSplitResult;
}

export interface TrailerCodecServiceOptions {
schemaBundle?: TrailerSchemaBundle;
trailerFactory?: (key: string, value: string, schema: ZodSchema) => GitTrailer;
parser?: TrailerParser | null;
messageNormalizer?: {
normalizeLines(message: string): string[];
guardMessageSize(message: string): void;
};
titleExtractor?: (lines: string[]) => { title: string; nextIndex: number };
bodyComposer?: (lines: string[]) => string;
formatters?: MessageFormatters;
}

export class TrailerCodecService {
constructor(options?: TrailerCodecServiceOptions);

readonly schemaBundle: TrailerSchemaBundle;
readonly parser: TrailerParser;

decode(message: string): Promise<GitCommitMessage>;
encode(messageEntity: GitCommitMessage | GitCommitMessageInput): Promise<string>;
}

export interface BodyFormatOptions {
keepTrailingNewline?: boolean;
}

export function formatBodySegment(body?: string | null, options?: BodyFormatOptions): string;

export interface TrailerCodecPayload {
title: string;
body?: string;
trailers?: Record<string, string>;
}

export interface TrailerCodecDecodedMessage {
title: string;
body: string;
trailers: Record<string, string>;
}

export interface TrailerMessageHelpers {
decodeMessage(input: string): Promise<TrailerCodecDecodedMessage>;
encodeMessage(payload: TrailerCodecPayload): Promise<string>;
}

export interface CreateMessageHelpersOptions {
service?: Pick<TrailerCodecService, 'decode' | 'encode'>;
bodyFormatOptions?: BodyFormatOptions;
}

export function createMessageHelpers(options?: CreateMessageHelpersOptions): TrailerMessageHelpers;

export interface TrailerCodecOptions {
service: TrailerCodecService;
bodyFormatOptions?: BodyFormatOptions;
}

export class TrailerCodec {
constructor(options: TrailerCodecOptions);

decodeMessage(input: string): Promise<TrailerCodecDecodedMessage>;
encodeMessage(payload: TrailerCodecPayload): Promise<string>;
decode(input: string): Promise<TrailerCodecDecodedMessage>;
encode(payload: TrailerCodecPayload): Promise<string>;
}

export function decodeMessage(
message: string,
bodyFormatOptions?: BodyFormatOptions
): Promise<TrailerCodecDecodedMessage>;

export function encodeMessage(
payload: TrailerCodecPayload,
bodyFormatOptions?: BodyFormatOptions
): Promise<string>;

export interface ConfiguredCodecOptions {
keyPattern?: string | RegExp;
keyMaxLength?: number;
parserOptions?: TrailerParserOptions;
formatters?: MessageFormatters;
bodyFormatOptions?: BodyFormatOptions;
}

export interface ConfiguredCodec {
service: TrailerCodecService;
helpers: TrailerMessageHelpers;
decodeMessage: TrailerMessageHelpers['decodeMessage'];
encodeMessage: TrailerMessageHelpers['encodeMessage'];
}

export function createConfiguredCodec(options?: ConfiguredCodecOptions): ConfiguredCodec;
Loading
Loading