# contractdiff/core

> Every export of contractdiff/core, with its signature and doc comment: DIRECTIONS, RefError, pointerGet, inline, plus 7 types.

Source: https://contractdiff.interlace.tools/docs/api/core

<!-- Generated by scripts/api-reference.ts from the built dist/*.d.ts. Do not edit; run `npx tsx scripts/api-reference.ts`. -->

```ts
import { DIRECTIONS, RefError, pointerGet, … } from 'contractdiff/core';
```

## Classes

### RefError

A reference that cannot be followed. The message ends in a `fix:` line.

```ts
class RefError extends Error {
    readonly ref: string;
    constructor(ref: string, reason: string, fix: string);
}
```

## Constants

### DIRECTIONS

```ts
const DIRECTIONS: readonly ["request", "response", "publish", "subscribe", "tool-call", "tool-result", "argv"];
```

### inline

Inline every local reference under `node`.

```ts
const inline: (document: unknown, node: unknown) => Inlined;
```

### pointerGet

The value a local reference (`#`, `#/a/b`) points at, by RFC 6901.

```ts
const pointerGet: (document: unknown, ref: string) => unknown;
```

## Interfaces

### Contract

```ts
interface Contract {
    /** The input format's name, e.g. `openapi`. */
    readonly format: string;
    /** The parsed source, untouched: a generator that must reproduce an incumbent's output reads it. */
    readonly document: unknown;
    readonly operations: readonly Operation[];
    /** What the reader had to translate or could not read exactly. */
    readonly findings?: readonly ContractFinding[];
}
```

### ContractFinding

Something a reader or a generator could not carry over exactly. Never a silent loss: a keyword
dropped, a construct translated, a value synthesised (program.md, definition of done 7).

```ts
interface ContractFinding {
    /** Stable, kebab-case, e.g. `keyword-dropped`. */
    readonly code: string;
    /** JSON Pointer into the source document. */
    readonly pointer: string;
    readonly message: string;
    readonly fix: string;
}
```

### Inlined

```ts
interface Inlined {
    /** A copy of the input with every followed reference replaced by its target. */
    readonly value: unknown;
    /** References kept because their target was already open: the cycles. */
    readonly cycles: readonly string[];
    /** References kept because they point outside the document. */
    readonly external: readonly string[];
}
```

### Operation

```ts
interface Operation {
    /** Stable across runs: the spec's own id where it has one. */
    readonly id: string;
    /** JSON Pointer to where the operation is declared in the source document. */
    readonly source: string;
    readonly payloads: readonly Payload[];
}
```

### Payload

```ts
interface Payload {
    /** Stable within its operation, e.g. `body:application/json` or `response:200:application/json`. */
    readonly name: string;
    readonly direction: Direction;
    readonly schema: JsonSchema;
    readonly required: boolean;
}
```

## Types

### Direction

Who sends a payload. Compatibility is decided per direction (spec.md R3), so it lives here.

```ts
type Direction = (typeof DIRECTIONS)[number];
```

### JsonSchema

A JSON Schema as it appears in a document: `true`, `false`, or an object of keywords.

```ts
type JsonSchema = boolean | {
    readonly [keyword: string]: unknown;
};
```
