contractdiff 0.4.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,7 +18,7 @@
18
18
  <a href="https://app.codecov.io/gh/ofri-peretz/burgee/components"><img src="https://img.shields.io/codecov/c/github/ofri-peretz/burgee/main?component=contractdiff&style=flat-square" alt="contractdiff line coverage: its Codecov component" /></a>
19
19
  <a href="https://scorecard.dev/viewer/?uri=github.com/ofri-peretz/burgee"><img src="https://img.shields.io/ossf-scorecard/github.com/ofri-peretz/burgee?style=flat-square&label=OpenSSF%20Scorecard" alt="OpenSSF Scorecard for the repository" /></a>
20
20
  <a href="https://www.npmjs.com/package/contractdiff?activeTab=code"><img src="https://img.shields.io/npm/unpacked-size/contractdiff?style=flat-square" alt="Unpacked size of the latest contractdiff release on npm" /></a>
21
- <a href="https://github.com/ofri-peretz/burgee/blob/main/packages/contractdiff/package.json"><img src="https://img.shields.io/badge/dependencies-4%20in%20family%2C%200%20outside-0a6b47?style=flat-square" alt="Four dependencies, all in the burgee family (bellpull, burgee, loadline, seniority), none outside it" /></a>
21
+ <a href="https://github.com/ofri-peretz/burgee/blob/main/packages/contractdiff/package.json"><img src="https://img.shields.io/badge/dependencies-4%20in%20family%2C%200%20outside-0a6b47?style=flat-square" alt="Four dependencies, all in the burgee family (bellpull, burgee, seniority, truefit), none outside it" /></a>
22
22
  <a href="https://github.com/ofri-peretz/burgee/blob/main/packages/contractdiff/package.json"><img src="https://img.shields.io/badge/types-included-blue?style=flat-square" alt="TypeScript types included for every entry point" /></a>
23
23
  <a href="https://github.com/ofri-peretz/burgee/blob/main/packages/contractdiff/package.json"><img src="https://img.shields.io/badge/Node.js-22.13%2B-green?style=flat-square" alt="Node.js 22.13+" /></a>
24
24
  <a href="https://github.com/ofri-peretz/burgee/blob/main/packages/contractdiff/LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue?style=flat-square" alt="License: MIT" /></a>
@@ -33,7 +33,7 @@
33
33
  **contractdiff** reads an API contract (OpenAPI, Swagger 2.0, JSON Schema, AsyncAPI or an MCP tool
34
34
  list) and does four things with it. `diff` says what a change breaks and for whom, under the
35
35
  compatibility mode you pick. `lint` checks the contract's form with rules, Spectral and Redocly
36
- rulesets included. `gen` writes code from it, one plugin per target: TypeScript types, loadline
36
+ rulesets included. `gen` writes code from it, one plugin per target: TypeScript types, truefit
37
37
  validators, fetch and TanStack Query clients, MSW handlers and NestJS, Express, Fastify and Hono
38
38
  servers. `extract` writes the contract back from the code. Every finding names its fix, as the same
39
39
  record for a person, for `--json` and for a coding agent.
@@ -52,7 +52,7 @@ bun add contractdiff
52
52
  ```
53
53
 
54
54
  Install it as a dev dependency (`-D`) of the project that owns the contract. The generated
55
- validators import `loadline`, which comes with it.
55
+ validators import `truefit`, which comes with it.
56
56
 
57
57
  ## Quick start
58
58
 
@@ -131,8 +131,14 @@ The same command reads openapi-fetch, Hey API and orval configs.
131
131
 
132
132
  ## Compatibility
133
133
 
134
- Not graded: no incumbent's own suite runs against contractdiff through compat-oracle. The `types`
135
- target is measured against openapi-typescript's output on the corpus in `benchmarks/apicontract`.
134
+ Not graded on the published compatibility page yet. `contractdiff/openapi-typescript` passed 45 of 61 of openapi-typescript 7.13.0's own gated cases
135
+ when compat-oracle ran them on 2026-11-24 (openapi-typescript itself passes 61). It is not claimed as
136
+ a drop-in until it passes all 61. When the failures were last listed case by case (2026-11-18, 43
137
+ of 61), 7 passed the `transform`, `postTransform` or `transformProperty` options, which hand
138
+ TypeScript compiler nodes across and which the compiler-free generator refuses, and 9 spawned
139
+ openapi-typescript's own `./bin/cli.js`.
140
+ The `types` target is also measured against openapi-typescript's output on the corpus in
141
+ `benchmarks/apicontract`.
136
142
 
137
143
  ## Benchmarks
138
144
 
@@ -174,18 +180,18 @@ code and for `extract` from TypeScript sources.
174
180
 
175
181
  It hosts no plugin key of its own.
176
182
 
177
- Nothing in this family builds on it yet, and it builds on `bellpull`, `burgee`, `loadline`, `seniority`.
183
+ Nothing in this family builds on it yet, and it builds on `bellpull`, `burgee`, `seniority`, `truefit`.
178
184
 
179
185
  ## The family
180
186
 
181
- 14 packages, one repository, one release pipeline. Each installs and works on its own, and each owns
182
- one job. Seven of them — `bellpull`, `closeout`, `linegauge`, `loadline`, `paratext`, `roundel`,
183
- `seniority` — depend on nothing; the others depend only on packages in this table, and every
187
+ 18 packages, one repository, one release pipeline. Each installs and works on its own, and each owns
188
+ one job. Seven of them — `bellpull`, `closeout`, `linegauge`, `paratext`, `roundel`, `seniority`,
189
+ `truefit` — depend on nothing; the others depend only on packages in this table, and every
184
190
  dependency points one way, down the [layers](https://burgee.interlace.tools/docs/concepts/family).
185
191
 
186
192
  No package declares a dependency from outside the family; `react` and `react-reconciler` are
187
193
  optional peers of `controlroom`, which npm does not install; `vitest` is an optional peer of
188
- `oxmutate`, which npm does not install; `eslint` is an optional peer of `truemark`, which npm does
194
+ `oxmutate`, which npm does not install; `eslint` is an optional peer of `truepass`, which npm does
189
195
  not install.
190
196
  [`package-shape-lock`](https://github.com/ofri-peretz/burgee/blob/main/scripts/package-shape-lock.test.ts)
191
197
  holds that for every manifest, and
@@ -210,9 +216,13 @@ keeps both true.
210
216
  | [bellpull](https://bellpull.interlace.tools/docs) | Subprocesses, and which executable actually ran | cross-spawn and which |
211
217
  | [controlroom](https://controlroom.interlace.tools/docs) | Keyboard-driven terminal screens, inline or full-screen | ink |
212
218
  | [oxmutate](https://oxmutate.interlace.tools/docs) | Mutation testing on the oxc engine, inside your own Vitest | Stryker |
213
- | [truemark](https://burgee.interlace.tools/docs/packages/truemark) | Lint rules and a pre-push check that keep a test suite honest | @vitest/eslint-plugin |
219
+ | [truepass](https://burgee.interlace.tools/docs/packages/truepass) | Lint rules and a pre-push check that keep a test suite honest | @vitest/eslint-plugin |
214
220
  | **contractdiff** (this package) | API contracts: breaking-change diff, lint, and code from the spec | openapi-typescript |
215
- | [loadline](https://burgee.interlace.tools/docs/packages/loadline) | Validation whose schemas are data, with no eval | zod |
221
+ | [truefit](https://burgee.interlace.tools/docs/packages/truefit) | Validation whose schemas are data, with no eval | zod |
222
+ | [provedone](https://burgee.interlace.tools/docs/packages/provedone) | A receipt for how every change was verified, and a gate that reads it | @commitlint/cli |
223
+ | [replz](https://burgee.interlace.tools/docs/packages/replz) | Recall of a reviewer and its checks, replayed on bugs that shipped | promptfoo |
224
+ | [hookset](https://burgee.interlace.tools/docs/packages/hookset) | The same git and Claude Code hooks in every repository, pinned by tag | husky |
225
+ | [triggerlist](https://burgee.interlace.tools/docs/packages/triggerlist) | The review checklist a diff selects, read from the base branch | danger |
216
226
 
217
227
  Every migration guide, and the family-wide [compatibility](https://burgee.interlace.tools/docs/compatibility)
218
228
  and [benchmarks](https://burgee.interlace.tools/docs/benchmarks) pages, are on
@@ -1,4 +1,4 @@
1
- import { date, datetime, duration, email, hostname, ipv4, ipv6, time, uuid } from 'loadline/formats';
1
+ import { date, datetime, duration, email, hostname, ipv4, ipv6, time, uuid } from 'truefit/formats';
2
2
  export const isDict = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
3
3
  export const has = (value, key) => Object.hasOwn(value, key);
4
4
  export const canonical = (value) => JSON.stringify(value, (_key, node) => (isDict(node) ? Object.fromEntries(Object.keys(node).sort().map((key) => [key, node[key]])) : node));
@@ -1,5 +1,5 @@
1
- import { check } from 'loadline';
2
- import { fromJsonSchema } from 'loadline/json-schema';
1
+ import { check } from 'truefit';
2
+ import { fromJsonSchema } from 'truefit/json-schema';
3
3
  export const CASINGS = ['camel', 'pascal', 'kebab', 'snake', 'macro', 'flat'];
4
4
  const CASE = {
5
5
  camel: /^[a-z][a-zA-Z\d]*$/u,
@@ -1,6 +1,6 @@
1
1
  import { STATUS_CODES } from 'node:http';
2
- import { string } from 'loadline';
3
- import { standardJson } from 'loadline/json-schema';
2
+ import { string } from 'truefit';
3
+ import { standardJson } from 'truefit/json-schema';
4
4
  import { stable } from './extract-normalise.js';
5
5
  import { escape, finding, isRecord, isStandard, loadModule, placeAt, relocate, sideOf, toJsonSchema } from './extract-standard.js';
6
6
  const BASE = '#/components/schemas/';
@@ -1,5 +1,5 @@
1
- import { optional, number, object, string } from 'loadline';
2
- import { standardJson } from 'loadline/json-schema';
1
+ import { optional, number, object, string } from 'truefit';
2
+ import { standardJson } from 'truefit/json-schema';
3
3
  import { definitions, escape, isStandard, loadModule, placeAt, relocate, sideOf, toJsonSchema } from './extract-standard.js';
4
4
  export const DIALECT = 'https://json-schema.org/draft/2020-12/schema';
5
5
  export const exportsOf = (namespace, wanted) => {
@@ -1,6 +1,6 @@
1
- import { emit, emitWith, typeOf } from 'loadline/emit';
2
- import { fromJsonSchema } from 'loadline/json-schema';
3
- export const DOOR_IMPORTS = "import { check } from 'loadline';\nimport { fromJsonSchema } from 'loadline/json-schema';";
1
+ import { emit, emitWith, typeOf } from 'truefit/emit';
2
+ import { fromJsonSchema } from 'truefit/json-schema';
3
+ export const DOOR_IMPORTS = "import { check } from 'truefit';\nimport { fromJsonSchema } from 'truefit/json-schema';";
4
4
  const guard = (name) => `(value: unknown) => value is ${name}`;
5
5
  const declared = (name, schema) => {
6
6
  const { text, aliases } = typeOf(schema, name);
@@ -244,13 +244,14 @@ const FORMAT = {
244
244
  regex: (draw) => draw.random.pick(PATTERNS),
245
245
  byte: (draw) => Buffer.from(Array.from({ length: within(draw, BYTES) }, () => within(draw, BYTE))).toString('base64'),
246
246
  };
247
+ const WRITERS = new Map(Object.entries(FORMAT));
247
248
  export const isFormat = (name) => FORMATS.includes(name);
248
249
  const string = (draw, schema, pointer) => {
249
250
  reportPresent(draw, schema, REPORTED_STRING, pointer);
250
251
  if (isFormat(schema.format)) {
251
252
  if (has(schema, 'minLength') || has(schema, 'maxLength'))
252
253
  report(draw, 'format-length', pointer);
253
- const write = new Map(Object.entries(FORMAT)).get(schema.format);
254
+ const write = WRITERS.get(schema.format);
254
255
  return { value: write(draw) };
255
256
  }
256
257
  if (has(schema, 'format'))
@@ -1,15 +1,46 @@
1
- import { check, parse } from 'loadline';
2
- import { fromJsonSchema } from 'loadline/json-schema';
1
+ import { check, parse } from 'truefit';
2
+ import { fromJsonSchema, jsonSchemaReader } from 'truefit/json-schema';
3
3
  import { isDict } from './diff-normalise.js';
4
- export const validatorJudge = (document, draft) => {
5
- const read = fromJsonSchema(document, { draft }).schema;
6
- return {
7
- accepts: (value) => check(read, value),
8
- paths: (value) => {
9
- const parsed = parse(read, value);
10
- return parsed.ok ? [] : parsed.issues.map((issue) => issue.path);
11
- },
12
- };
4
+ const judgeOf = (read) => ({
5
+ accepts: (value) => check(read, value),
6
+ paths: (value) => {
7
+ const parsed = parse(read, value);
8
+ return parsed.ok ? [] : parsed.issues.map((issue) => issue.path);
9
+ },
10
+ });
11
+ export const validatorJudge = (document, draft) => judgeOf(fromJsonSchema(document, { draft }).schema);
12
+ const readers = new WeakMap();
13
+ const readerFor = (document, draft) => {
14
+ const byDraft = readers.get(document) ?? new Map();
15
+ readers.set(document, byDraft);
16
+ const known = byDraft.get(draft);
17
+ if (known !== undefined)
18
+ return known;
19
+ const reader = jsonSchemaReader(rooted({}, document), { draft });
20
+ byDraft.set(draft, reader);
21
+ return reader;
22
+ };
23
+ const intoPayload = (ref) => {
24
+ if (typeof ref !== 'string')
25
+ return false;
26
+ if (ref === '#')
27
+ return true;
28
+ if (!ref.startsWith('#/'))
29
+ return false;
30
+ return !DEFINITIONS.includes(decodeURIComponent(ref.slice(2).split('/')[0]));
31
+ };
32
+ const refersInside = (schema) => {
33
+ if (Array.isArray(schema))
34
+ return schema.some(refersInside);
35
+ if (!isDict(schema))
36
+ return false;
37
+ return intoPayload(schema.$ref) || Object.values(schema).some(refersInside);
38
+ };
39
+ const selfReferent = (schema) => DEFINITIONS.some((key) => key in schema) || refersInside(schema);
40
+ export const payloadJudge = (schema, document, draft) => {
41
+ if (!isDict(document) || (isDict(schema) && selfReferent(schema)))
42
+ return validatorJudge(rooted(schema, document), draft);
43
+ return judgeOf(readerFor(document, draft).read(rooted(schema, null)));
13
44
  };
14
45
  export const draftOf = (contract) => {
15
46
  const document = isDict(contract.document) ? contract.document : {};
package/dist/props-run.js CHANGED
@@ -2,15 +2,15 @@ import { payloadRules } from './diff-classify.js';
2
2
  import { compareContracts, pair } from './diff-contract.js';
3
3
  import { canonical, isDict, normalise } from './diff-normalise.js';
4
4
  import { drawFrom, make } from './props-generate.js';
5
- import { draftOf, rooted, validatorJudge } from './props-judge.js';
5
+ import { draftOf, payloadJudge } from './props-judge.js';
6
6
  import { mutate } from './props-mutate.js';
7
7
  import { randomFrom } from './props-random.js';
8
8
  import { shrink } from './props-shrink.js';
9
9
  export const PROPERTIES = ['agreement', 'round-trip', 'normalise', 'soundness'];
10
- export const SUBJECT = { validator: validatorJudge, normalise, encode: (value) => JSON.stringify(value), decode: (text) => JSON.parse(text), compare: compareContracts };
10
+ export const SUBJECT = { validator: payloadJudge, normalise, encode: (value) => JSON.stringify(value), decode: (text) => JSON.parse(text), compare: compareContracts };
11
11
  const judge = (subject, schema, document, draft) => {
12
12
  try {
13
- return subject.validator(rooted(schema, document), draft);
13
+ return subject.validator(schema, document, draft);
14
14
  }
15
15
  catch (error) {
16
16
  return error.message;
@@ -27,8 +27,12 @@ const fail = (run, counterexample) => {
27
27
  };
28
28
  const drawIn = (run, contract) => drawFrom(run.random, contract.document, draftOf(contract));
29
29
  const gather = (into, from) => {
30
- for (const [keyword, at] of from)
31
- into.set(keyword, new Set([...(into.get(keyword) ?? []), ...at]));
30
+ for (const [keyword, at] of from) {
31
+ const known = into.get(keyword) ?? new Set();
32
+ into.set(keyword, known);
33
+ for (const place of at)
34
+ known.add(place);
35
+ }
32
36
  };
33
37
  const agreement = (run, check, draw, value) => {
34
38
  const { where, own } = check;
@@ -60,6 +64,8 @@ const roundTrip = (run, check, value) => {
60
64
  tally(run, 'round-trip').checked += 1;
61
65
  const broken = (candidate) => {
62
66
  const back = subject.decode(subject.encode(candidate));
67
+ if (JSON.stringify(back) === JSON.stringify(candidate))
68
+ return false;
63
69
  return canonical(back) !== canonical(candidate);
64
70
  };
65
71
  if (!broken(value))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contractdiff",
3
- "version": "0.4.0",
3
+ "version": "1.0.0",
4
4
  "private": false,
5
5
  "description": "Breaking-change diff, lint and code generation for API contracts (OpenAPI, JSON Schema, AsyncAPI, MCP), and the spec back from the code. No dependency outside the burgee family. An openapi-typescript migration path.",
6
6
  "license": "MIT",
@@ -67,7 +67,7 @@
67
67
  }
68
68
  },
69
69
  "bin": {
70
- "contractdiff": "./dist/bin.js"
70
+ "contractdiff": "dist/bin.js"
71
71
  },
72
72
  "files": [
73
73
  "dist",
@@ -83,9 +83,9 @@
83
83
  },
84
84
  "dependencies": {
85
85
  "bellpull": "^2.0.3",
86
- "burgee": "^2.2.0",
86
+ "burgee": "^2.2.1",
87
87
  "seniority": "^2.0.0",
88
- "loadline": "^0.1.0"
88
+ "truefit": "^1.0.0"
89
89
  },
90
90
  "devDependencies": {
91
91
  "vitest": "^5.0.1"