contractdiff
API reference

contractdiff

Every export of contractdiff, with its signature and doc comment: program, VERSION, configSchema, extract, gen, MAP_FILE, plus 8 types.

import { program, VERSION, configSchema, … } from 'contractdiff';

Constants

configSchema

The JSON Schema contractdiff.config.json validates against.

const configSchema: {
    readonly $schema: "https://json-schema.org/draft/2020-12/schema";
    readonly title: "contractdiff.config.json";
    readonly type: "object";
    readonly additionalProperties: false;
    readonly properties: {
        readonly $schema: {
            readonly type: "string";
        };
        readonly input: {
            readonly type: "string";
            readonly minLength: 1;
            readonly description: "The spec, relative to this file: JSON or YAML";
        };
        readonly overlays: {
            readonly type: "array";
            readonly items: {
                readonly type: "string";
                readonly minLength: 1;
            };
            readonly description: "OpenAPI Overlays applied to the input, in order";
        };
        readonly plugins: {
            readonly type: "array";
            readonly items: {
                readonly type: "string";
                readonly minLength: 1;
            };
            readonly description: "Package names or relative paths; nothing else is loaded";
        };
        readonly targets: {
            readonly type: "object";
            readonly additionalProperties: {
                readonly type: "object";
                readonly additionalProperties: false;
                readonly required: readonly ["generator", "out"];
                readonly properties: {
                    readonly generator: {
                        readonly type: "string";
                        readonly minLength: 1;
                    };
                    readonly out: {
                        readonly type: "string";
                        readonly minLength: 1;
                    };
                    readonly options: {
                        readonly type: "object";
                    };
                };
            };
        };
        readonly extract: {
            readonly type: "object";
            readonly additionalProperties: false;
            readonly properties: {
                readonly from: {
                    readonly type: "string";
                    readonly minLength: 1;
                };
                readonly out: {
                    readonly type: "string";
                    readonly minLength: 1;
                };
                readonly options: {
                    readonly type: "object";
                };
            };
        };
        readonly diff: {
            readonly type: "object";
            readonly additionalProperties: false;
            readonly properties: {
                readonly decisions: {
                    readonly enum: readonly ["warn", "error", "off"];
                    readonly description: "How `contractdiff diff` holds a change to the decision written in the contract. The base ref's value wins over the working tree's; `--decisions` wins over both";
                };
            };
        };
        readonly lint: {
            readonly type: "object";
            readonly additionalProperties: false;
            readonly properties: {
                readonly extends: {
                    readonly type: "array";
                    readonly items: {
                        readonly type: "string";
                        readonly minLength: 1;
                    };
                    readonly description: "Rulesets, in order: `recommended`, `agent-ready`";
                };
                readonly rules: {
                    readonly type: "object";
                    readonly additionalProperties: {
                        readonly enum: readonly ["error", "warn", "off"];
                    };
                    readonly description: "A level per rule id, over the rulesets";
                };
                readonly warnFor: {
                    readonly type: "string";
                    readonly pattern: "^\\d+d$";
                    readonly description: "How long a rule new at error warns first, by the date it entered the ruleset: `\"14d\"` (the default); `\"0d\"` turns it off";
                };
                readonly since: {
                    readonly type: "string";
                    readonly minLength: 1;
                    readonly description: "The git ref `--since` defaults to: only operations added or changed since it run every rule; `merge-base` is the base with origin/main";
                };
                readonly legacy: {
                    readonly type: "array";
                    readonly items: {
                        readonly type: "string";
                        readonly minLength: 1;
                    };
                    readonly description: "Rule ids that still run on operations `since` leaves untouched; none by default";
                };
            };
        };
    };
};

extract

const extract: (options: ExtractOptions) => Promise<Report>;

gen

const gen: (options: GenOptions) => Promise<Report>;

MAP_FILE

const MAP_FILE = "contractdiff.map.json";

program

const program: import("burgee").Manifest;

VERSION

The published version, read from the manifest beside dist/ so --version cannot drift from npm.

const VERSION: string;

Interfaces

Config

interface Config {
    /** The folder the config file is in: every path in it is relative to this. */
    readonly root: string;
    readonly file: string;
    readonly input?: string;
    readonly overlays: readonly string[];
    readonly plugins: readonly string[];
    readonly targets: Readonly<Record<string, Target>>;
    readonly extract: ExtractConfig;
    /** Absent when the config has no `diff` section. */
    readonly diff?: DiffConfig;
    /** `contractdiff lint`'s rulesets and per-rule levels; absent when the config has no `lint` section. */
    readonly lint?: LintConfig;
}

ContractMap

interface ContractMap {
    readonly version: 1;
    readonly operations: Readonly<Record<string, readonly MapEntry[]>>;
    readonly files: Readonly<Record<string, MapFile>>;
}

ExtractOptions

interface ExtractOptions {
    readonly cwd: string;
    readonly config?: string | undefined;
    /** The extractor's name; the config's `extract.from` when absent. */
    readonly from?: string | undefined;
    /** The spec file to write; the config's `extract.out`, else `spec.json`. */
    readonly out?: string | undefined;
    readonly check?: boolean | undefined;
    readonly dryRun?: boolean | undefined;
    readonly force?: boolean | undefined;
}

FileReport

interface FileReport {
    readonly path: string;
    readonly owner: Owner;
    readonly action: Action;
    /** The target that produced it; absent for the map itself. */
    readonly target?: string;
}

GenOptions

interface GenOptions {
    /** Where a config is looked for, and what `--config` is relative to. */
    readonly cwd: string;
    readonly config?: string | undefined;
    /** Run only these targets; every target when absent or empty. */
    readonly targets?: readonly string[] | undefined;
    readonly check?: boolean | undefined;
    readonly dryRun?: boolean | undefined;
    readonly force?: boolean | undefined;
}

MapEntry

interface MapEntry {
    readonly file: string;
    readonly symbol: string;
    readonly target: string;
    /**
     * `user` for the symbol the user owns that implements the operation (R-BL1): a method of the
     * controller class or a member of the handlers object a target wrote once. Absent for a generated one.
     */
    readonly owner?: 'user';
}

Report

interface Report {
    readonly files: readonly FileReport[];
    /** Whether a file was written or deleted, or would be under `--check` and `--dry-run`: what burgee asks of an idempotent command (N7). */
    readonly changed: boolean;
    /** How many files were written or deleted, or would be. */
    readonly changes: number;
    readonly unchanged: number;
    /** User files left as they are. */
    readonly skipped: number;
    readonly findings: readonly (ContractFinding & {
        readonly target: string;
    })[];
    /** `--dry-run`: the unified diff of every change. */
    readonly diff?: string;
    /** `--check`: the files that are not what a run would write. */
    readonly stale?: readonly string[];
    readonly exitCode?: 1;
    readonly fix?: string;
}

Target

interface Target {
    /** The generator's name, as a plugin registers it. */
    readonly generator: string;
    /** The output folder, relative to the project root, with `/` separators. */
    readonly out: string;
    readonly options: Options;
}

On this page