@webpieces/pr-gate 0.4.811 → 0.4.812

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.
Files changed (28) hide show
  1. package/package.json +3 -3
  2. package/src/index.d.ts +0 -8
  3. package/src/index.js +1 -27
  4. package/src/index.js.map +1 -1
  5. package/src/scripts/commands/finish-upsert-pr-command.d.ts +1 -10
  6. package/src/scripts/commands/finish-upsert-pr-command.js +6 -38
  7. package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
  8. package/src/scripts/workflow/contract/consumer-bin-resolver.d.ts +0 -62
  9. package/src/scripts/workflow/contract/consumer-bin-resolver.js +0 -152
  10. package/src/scripts/workflow/contract/consumer-bin-resolver.js.map +0 -1
  11. package/src/scripts/workflow/contract/contract-diff-renderer.d.ts +0 -53
  12. package/src/scripts/workflow/contract/contract-diff-renderer.js +0 -103
  13. package/src/scripts/workflow/contract/contract-diff-renderer.js.map +0 -1
  14. package/src/scripts/workflow/contract/contract-diff-step.d.ts +0 -67
  15. package/src/scripts/workflow/contract/contract-diff-step.js +0 -192
  16. package/src/scripts/workflow/contract/contract-diff-step.js.map +0 -1
  17. package/src/scripts/workflow/contract/generator-package.d.ts +0 -29
  18. package/src/scripts/workflow/contract/generator-package.js +0 -38
  19. package/src/scripts/workflow/contract/generator-package.js.map +0 -1
  20. package/src/scripts/workflow/contract/generator-runner.d.ts +0 -22
  21. package/src/scripts/workflow/contract/generator-runner.js +0 -44
  22. package/src/scripts/workflow/contract/generator-runner.js.map +0 -1
  23. package/src/scripts/workflow/contract/json-value.d.ts +0 -6
  24. package/src/scripts/workflow/contract/json-value.js +0 -3
  25. package/src/scripts/workflow/contract/json-value.js.map +0 -1
  26. package/src/scripts/workflow/contract/openapi-contract-diff.d.ts +0 -45
  27. package/src/scripts/workflow/contract/openapi-contract-diff.js +0 -158
  28. package/src/scripts/workflow/contract/openapi-contract-diff.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"contract-diff-step.js","sourceRoot":"","sources":["../../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/contract/contract-diff-step.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAgE;AAChE,yCAA2D;AAC3D,0CAAsC;AACtC,mEAA+F;AAC/F,qEAAqF;AACrF,yDAAmE;AACnE,2DAAqG;AAErG,mEAA8D;AAE9D,MAAM,SAAS,GAAG,eAAe,CAAC;AAElC,oGAAoG;AACpG,MAAa,gBAAgB;IAEZ;IAEA;IAEA;IALb,YACa,WAAmB;IAC5B,uCAAuC;IAC9B,WAAmB;IAC5B,8FAA8F;IACrF,QAAgB;QAJhB,gBAAW,GAAX,WAAW,CAAQ;QAEnB,gBAAW,GAAX,WAAW,CAAQ;QAEnB,aAAQ,GAAR,QAAQ,CAAQ;IAC1B,CAAC;CACP;AARD,4CAQC;AAED,wEAAwE;AACxE,MAAM,cAAc;IAGH;IACA;IAHb;IACI,oGAAoG;IAC3F,QAAgB,EAChB,MAAc;QADd,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAQ;IACxB,CAAC;CACP;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAEJ;IACA;IACA;IACA;IACA;IALrB,YACqB,OAAgB,EAChB,QAA6B,EAC7B,MAAuB,EACvB,MAA2B,EAC3B,QAA8B;QAJ9B,YAAO,GAAP,OAAO,CAAS;QAChB,aAAQ,GAAR,QAAQ,CAAqB;QAC7B,WAAM,GAAN,MAAM,CAAiB;QACvB,WAAM,GAAN,MAAM,CAAqB;QAC3B,aAAQ,GAAR,QAAQ,CAAsB;IAChD,CAAC;IAEJ,yGAAyG;IACzG,WAAW,CAAC,QAAgB,EAAE,UAAkB;QAC5C,MAAM,SAAS,GAAG,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QACnD,IAA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AAM,KAAK,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,4BAAa,CAAC,SAAS,EAAE,oCAAoC,OAAO,SAAS,IAAI,KAAK,KAAK,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC,CAAC;QAC1H,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAEO,MAAM,CAAC,KAAqC;QAChD,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7F,CAAC;CACJ,CAAA;AAtHY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGP,kBAAO;QACN,2CAAmB;QACrB,kCAAe;QACf,2CAAmB;QACjB,6CAAoB;GAN1C,gBAAgB,CAsH5B","sourcesContent":["import { spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { Option, RuleFailError } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { GitExec } from '../git-exec';\nimport { ConsumerBin, ConsumerBinRequest, ConsumerBinResolver } from './consumer-bin-resolver';\nimport { ContractDiffRenderer, ContractDiffSection } from './contract-diff-renderer';\nimport { GeneratorRun, GeneratorRunner } from './generator-runner';\nimport { OPENAPI_GENERATE_EXECUTOR, OPENAPI_GENERATOR, PARTNER_DOCUMENT } from './generator-package';\nimport { JsonObject } from './json-value';\nimport { OpenApiContractDiff } from './openapi-contract-diff';\n\nconst RULE_NAME = 'contract-diff';\n\n/** One project that declared an `openapi-generate` target, and the manifest it names. Data-only. */\nexport class DeclaredContract {\n constructor(\n readonly projectName: string,\n /** Workspace-relative project root. */\n readonly projectRoot: string,\n /** Workspace-relative manifest path, exactly as the target's `options.manifest` states it. */\n readonly manifest: string,\n ) {}\n}\n\n/** Where one side of the diff is generated from and into. Data-only. */\nclass GenerationSide {\n constructor(\n /** The tree the manifest's relative paths resolve against: the repo, or an extracted merge-base. */\n readonly treeRoot: string,\n readonly outDir: string,\n ) {}\n}\n\n/**\n * The PR-gate step that replaced committing generated documents (#986): for every project that\n * declares an `openapi-generate` target, generate the partner-facing document at the MERGE-BASE and at\n * HEAD, diff the two, and render the result as a PR comment.\n *\n * ## Which contracts\n *\n * Exactly the ones a `project.json` declares with the `openapi-generate` executor — the same\n * declaration that makes the build generate and publish the document. There is no second list to keep\n * in step, and a repo that declares none gets no comment and pays nothing.\n *\n * ## One reader, two sources\n *\n * Both sides run the CONSUMER's installed generator (never a bundled copy — see\n * {@link ConsumerBinResolver}). So the diff isolates what the SOURCE changed; a generator upgrade\n * landing in the same PR is not reported as a contract change on every endpoint.\n *\n * The merge-base is extracted with `git archive` INSIDE the repo (under the branch's scratch dir, which\n * is gitignored with the rest of `.webpieces/`), so its imports resolve through the same\n * `node_modules` by walking up — no second install, no worktree bookkeeping for `wp-cleanup` to reap.\n *\n * ## Failure\n *\n * HEAD failing to generate THROWS, before anything is pushed: the build publishes that document, so a\n * contract that cannot be generated is not a PR to post. The merge-base failing is not this PR's defect\n * (today's generator may refuse a shape an older one accepted) — it is REPORTED in the comment, and the\n * diff then reads every HEAD item as added.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ContractDiffStep {\n constructor(\n private readonly gitExec: GitExec,\n private readonly resolver: ConsumerBinResolver,\n private readonly runner: GeneratorRunner,\n private readonly differ: OpenApiContractDiff,\n private readonly renderer: ContractDiffRenderer,\n ) {}\n\n /** The comment body, or '' when no project declares a contract. `scratchDir` must be inside the repo. */\n commentBody(repoRoot: string, scratchDir: string): string {\n const contracts = this.declaredContracts(repoRoot);\n if (contracts.length === 0) return '';\n const headSha = this.gitExec.gitQuery(['rev-parse', 'HEAD'], repoRoot, 'git rev-parse HEAD failed');\n const baseSha = this.gitExec.gitQuery(['merge-base', 'origin/main', 'HEAD'], repoRoot, 'git merge-base origin/main HEAD failed');\n fs.rmSync(scratchDir, { recursive: true, force: true });\n const baseTree = path.join(scratchDir, 'merge-base');\n const sections: ContractDiffSection[] = [];\n // webpieces-disable no-unmanaged-exceptions -- try/FINALLY only, nothing is caught: the extracted\n // merge-base tree is removed however this ends, and any throw still reaches the top-level handler\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const extracted = this.extractIfNeeded(repoRoot, baseSha, contracts, baseTree);\n contracts.forEach((contract: DeclaredContract, index: number) => {\n const head = new GenerationSide(repoRoot, path.join(scratchDir, 'head', String(index)));\n const base = new GenerationSide(baseTree, path.join(scratchDir, 'base', String(index)));\n sections.push(this.section(repoRoot, contract, extracted, head, base, baseSha, headSha));\n });\n } finally {\n fs.rmSync(scratchDir, { recursive: true, force: true });\n }\n return this.renderer.render(sections);\n }\n\n /** Every tracked `project.json` target running {@link OPENAPI_GENERATE_EXECUTOR}. */\n declaredContracts(repoRoot: string): DeclaredContract[] {\n const listed = this.gitExec.gitQuery(['ls-files', '--', '*project.json'], repoRoot, 'git ls-files failed');\n const contracts: DeclaredContract[] = [];\n for (const file of listed.split('\\n').filter((line: string) => line.trim() !== '').sort()) {\n const project = JSON.parse(fs.readFileSync(path.join(repoRoot, file), 'utf8')) as JsonObject;\n const targets = this.object(project['targets']);\n for (const targetName of Object.keys(targets).sort()) {\n const target = this.object(targets[targetName]);\n const manifest = this.object(target['options'])['manifest'];\n if (target['executor'] !== OPENAPI_GENERATE_EXECUTOR || typeof manifest !== 'string') continue;\n const name = typeof project['name'] === 'string' ? project['name'] : path.dirname(file);\n contracts.push(new DeclaredContract(name, path.dirname(file), manifest));\n }\n }\n return contracts;\n }\n\n // eslint-disable-next-line @typescript-eslint/max-params\n private section(\n repoRoot: string, contract: DeclaredContract, extracted: boolean,\n head: GenerationSide, base: GenerationSide, baseSha: string, headSha: string,\n ): ContractDiffSection {\n const bin = this.resolver.resolve(new ConsumerBinRequest(\n RULE_NAME, OPENAPI_GENERATOR, [path.join(repoRoot, contract.projectRoot), repoRoot]));\n const headRun = this.generate(bin, contract, head);\n if (!headRun.ok) {\n throw new RuleFailError(\n RULE_NAME,\n `${contract.manifest} does not generate at HEAD, so there is no partner-facing document to ` +\n `diff or to publish.\\n${headRun.output}`,\n undefined,\n undefined,\n [new Option(`Fix the contract, then re-run: pnpm nx run ${contract.projectName}:openapi-generate`, true)],\n );\n }\n const after = this.readDocument(head.outDir);\n let baseNote = '';\n let before: JsonObject | undefined;\n if (!extracted || !fs.existsSync(path.join(base.treeRoot, contract.manifest))) {\n baseNote = 'The merge-base has no such manifest — a new contract, so everything below is new.';\n } else {\n const baseRun = this.generate(bin, contract, base);\n if (baseRun.ok) before = this.readDocument(base.outDir);\n else baseNote = `The merge-base does not generate with ${bin.packageName} ${bin.version}, so every HEAD item reads as added:\\n> ${baseRun.output.split('\\n').join('\\n> ')}`;\n }\n return new ContractDiffSection(\n contract.projectName, contract.manifest, PARTNER_DOCUMENT, baseSha, headSha, baseNote,\n after === undefined, this.differ.diff(before, after));\n }\n\n private generate(bin: ConsumerBin, contract: DeclaredContract, side: GenerationSide): GeneratorRun {\n fs.mkdirSync(side.outDir, { recursive: true });\n return this.runner.run(bin, [\n '--manifest', path.join(side.treeRoot, contract.manifest), '--out', side.outDir, '--format', 'json',\n ], side.treeRoot);\n }\n\n private readDocument(outDir: string): JsonObject | undefined {\n const file = path.join(outDir, PARTNER_DOCUMENT);\n return fs.existsSync(file) ? (JSON.parse(fs.readFileSync(file, 'utf8')) as JsonObject) : undefined;\n }\n\n /**\n * Extract the merge-base tree, unless no declared manifest existed there — a PR that ADDS its first\n * contract needs no 14 MB archive to learn that everything is new.\n */\n private extractIfNeeded(repoRoot: string, baseSha: string, contracts: readonly DeclaredContract[], into: string): boolean {\n const anyAtBase = contracts.some((contract: DeclaredContract) =>\n this.gitExec.tryGit(['cat-file', '-e', `${baseSha}:${contract.manifest}`], repoRoot).status === 0);\n if (!anyAtBase) return false;\n fs.mkdirSync(into, { recursive: true });\n const tarFile = `${into}.tar`;\n this.gitExec.gitQuery(['archive', '--format=tar', '-o', tarFile, baseSha], repoRoot, `git archive ${baseSha} failed`);\n const untar = spawnSync('tar', ['-xf', tarFile, '-C', into], { encoding: 'utf8' });\n if (untar.status !== 0) {\n throw new RuleFailError(RULE_NAME, `Could not extract the merge-base ${baseSha} into ${into}: ${untar.stderr ?? ''}`);\n }\n return true;\n }\n\n private object(value: JsonObject[string] | undefined): JsonObject {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : {};\n }\n}\n"]}
@@ -1,29 +0,0 @@
1
- /**
2
- * A generator this tooling RUNS but never bundles, and the oldest release of it that has every
3
- * capability the tooling relies on. Data-only.
4
- *
5
- * `minimumVersion` is the version handshake. A capability ships in the generator (the server stream)
6
- * first; the tooling that relies on it follows, and raises this number in the same change. Keep it the
7
- * FIRST release carrying the capability, not the latest one — raising it further forces a consumer bump
8
- * that buys nothing.
9
- */
10
- export declare class GeneratorPackage {
11
- readonly packageName: string;
12
- readonly binName: string;
13
- readonly minimumVersion: string;
14
- constructor(packageName: string, binName: string, minimumVersion: string);
15
- }
16
- /**
17
- * `wp-openapi` with `--manifest/--out/--format` and the `mcp-tools.json` runtime catalog: 0.4.807 is
18
- * the first release carrying #1008, which is when `mcp-tools.json` became part of what a run writes.
19
- */
20
- export declare const OPENAPI_GENERATOR: GeneratorPackage;
21
- /** `wp-docs-site --spec/--prose/--out`: 0.4.807 is the first release carrying the docs site (#1007). */
22
- export declare const DOCS_SITE: GeneratorPackage;
23
- /** The executor a project declares to have its documents generated — and therefore diffed in its PRs. */
24
- export declare const OPENAPI_GENERATE_EXECUTOR = "@webpieces/nx-webpieces-rules:openapi-generate";
25
- /**
26
- * The partner-facing document: every contract declaring `EXTERNAL_CUSTOMER`, minus hidden methods. It is
27
- * the one the PR gate diffs, because it is the one that leaves the building as a published contract.
28
- */
29
- export declare const PARTNER_DOCUMENT = "public-openapi.json";
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PARTNER_DOCUMENT = exports.OPENAPI_GENERATE_EXECUTOR = exports.DOCS_SITE = exports.OPENAPI_GENERATOR = exports.GeneratorPackage = void 0;
4
- /**
5
- * A generator this tooling RUNS but never bundles, and the oldest release of it that has every
6
- * capability the tooling relies on. Data-only.
7
- *
8
- * `minimumVersion` is the version handshake. A capability ships in the generator (the server stream)
9
- * first; the tooling that relies on it follows, and raises this number in the same change. Keep it the
10
- * FIRST release carrying the capability, not the latest one — raising it further forces a consumer bump
11
- * that buys nothing.
12
- */
13
- class GeneratorPackage {
14
- packageName;
15
- binName;
16
- minimumVersion;
17
- constructor(packageName, binName, minimumVersion) {
18
- this.packageName = packageName;
19
- this.binName = binName;
20
- this.minimumVersion = minimumVersion;
21
- }
22
- }
23
- exports.GeneratorPackage = GeneratorPackage;
24
- /**
25
- * `wp-openapi` with `--manifest/--out/--format` and the `mcp-tools.json` runtime catalog: 0.4.807 is
26
- * the first release carrying #1008, which is when `mcp-tools.json` became part of what a run writes.
27
- */
28
- exports.OPENAPI_GENERATOR = new GeneratorPackage('@webpieces/openapi-generator', 'wp-openapi', '0.4.807');
29
- /** `wp-docs-site --spec/--prose/--out`: 0.4.807 is the first release carrying the docs site (#1007). */
30
- exports.DOCS_SITE = new GeneratorPackage('@webpieces/docs-site', 'wp-docs-site', '0.4.807');
31
- /** The executor a project declares to have its documents generated — and therefore diffed in its PRs. */
32
- exports.OPENAPI_GENERATE_EXECUTOR = '@webpieces/nx-webpieces-rules:openapi-generate';
33
- /**
34
- * The partner-facing document: every contract declaring `EXTERNAL_CUSTOMER`, minus hidden methods. It is
35
- * the one the PR gate diffs, because it is the one that leaves the building as a published contract.
36
- */
37
- exports.PARTNER_DOCUMENT = 'public-openapi.json';
38
- //# sourceMappingURL=generator-package.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generator-package.js","sourceRoot":"","sources":["../../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/contract/generator-package.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACH,MAAa,gBAAgB;IAEZ;IACA;IACA;IAHb,YACa,WAAmB,EACnB,OAAe,EACf,cAAsB;QAFtB,gBAAW,GAAX,WAAW,CAAQ;QACnB,YAAO,GAAP,OAAO,CAAQ;QACf,mBAAc,GAAd,cAAc,CAAQ;IAChC,CAAC;CACP;AAND,4CAMC;AAED;;;GAGG;AACU,QAAA,iBAAiB,GAAG,IAAI,gBAAgB,CAAC,8BAA8B,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;AAE/G,wGAAwG;AAC3F,QAAA,SAAS,GAAG,IAAI,gBAAgB,CAAC,sBAAsB,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC;AAEjG,yGAAyG;AAC5F,QAAA,yBAAyB,GAAG,gDAAgD,CAAC;AAE1F;;;GAGG;AACU,QAAA,gBAAgB,GAAG,qBAAqB,CAAC","sourcesContent":["/**\n * A generator this tooling RUNS but never bundles, and the oldest release of it that has every\n * capability the tooling relies on. Data-only.\n *\n * `minimumVersion` is the version handshake. A capability ships in the generator (the server stream)\n * first; the tooling that relies on it follows, and raises this number in the same change. Keep it the\n * FIRST release carrying the capability, not the latest one — raising it further forces a consumer bump\n * that buys nothing.\n */\nexport class GeneratorPackage {\n constructor(\n readonly packageName: string,\n readonly binName: string,\n readonly minimumVersion: string,\n ) {}\n}\n\n/**\n * `wp-openapi` with `--manifest/--out/--format` and the `mcp-tools.json` runtime catalog: 0.4.807 is\n * the first release carrying #1008, which is when `mcp-tools.json` became part of what a run writes.\n */\nexport const OPENAPI_GENERATOR = new GeneratorPackage('@webpieces/openapi-generator', 'wp-openapi', '0.4.807');\n\n/** `wp-docs-site --spec/--prose/--out`: 0.4.807 is the first release carrying the docs site (#1007). */\nexport const DOCS_SITE = new GeneratorPackage('@webpieces/docs-site', 'wp-docs-site', '0.4.807');\n\n/** The executor a project declares to have its documents generated — and therefore diffed in its PRs. */\nexport const OPENAPI_GENERATE_EXECUTOR = '@webpieces/nx-webpieces-rules:openapi-generate';\n\n/**\n * The partner-facing document: every contract declaring `EXTERNAL_CUSTOMER`, minus hidden methods. It is\n * the one the PR gate diffs, because it is the one that leaves the building as a published contract.\n */\nexport const PARTNER_DOCUMENT = 'public-openapi.json';\n"]}
@@ -1,22 +0,0 @@
1
- import { ConsumerBin } from './consumer-bin-resolver';
2
- /** One finished generator process. Data-only. */
3
- export declare class GeneratorRun {
4
- readonly exitCode: number;
5
- /** stdout and stderr, in that order — the generator reports its refusals on stdout. */
6
- readonly output: string;
7
- constructor(exitCode: number,
8
- /** stdout and stderr, in that order — the generator reports its refusals on stdout. */
9
- output: string);
10
- get ok(): boolean;
11
- }
12
- /**
13
- * Runs a resolved {@link ConsumerBin} with the node that is running US, so the generator gets the
14
- * consumer's `node_modules` (it lives there) without depending on a `.bin` shim or on `PATH`.
15
- *
16
- * It REPORTS the outcome rather than throwing on a non-zero exit, because the two callers mean
17
- * different things by one: the nx executor refuses the build, while the PR gate's merge-base run
18
- * records "the merge-base does not generate with today's generator" and says so in the PR.
19
- */
20
- export declare class GeneratorRunner {
21
- run(bin: ConsumerBin, args: readonly string[], cwd: string): GeneratorRun;
22
- }
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GeneratorRunner = exports.GeneratorRun = void 0;
4
- const tslib_1 = require("tslib");
5
- const child_process_1 = require("child_process");
6
- const inversify_1 = require("inversify");
7
- /** One finished generator process. Data-only. */
8
- class GeneratorRun {
9
- exitCode;
10
- output;
11
- constructor(exitCode,
12
- /** stdout and stderr, in that order — the generator reports its refusals on stdout. */
13
- output) {
14
- this.exitCode = exitCode;
15
- this.output = output;
16
- }
17
- get ok() {
18
- return this.exitCode === 0;
19
- }
20
- }
21
- exports.GeneratorRun = GeneratorRun;
22
- /**
23
- * Runs a resolved {@link ConsumerBin} with the node that is running US, so the generator gets the
24
- * consumer's `node_modules` (it lives there) without depending on a `.bin` shim or on `PATH`.
25
- *
26
- * It REPORTS the outcome rather than throwing on a non-zero exit, because the two callers mean
27
- * different things by one: the nx executor refuses the build, while the PR gate's merge-base run
28
- * records "the merge-base does not generate with today's generator" and says so in the PR.
29
- */
30
- let GeneratorRunner = class GeneratorRunner {
31
- run(bin, args, cwd) {
32
- const result = (0, child_process_1.spawnSync)(process.execPath, [bin.binPath, ...args], { cwd, encoding: 'utf8' });
33
- const output = [result.stdout ?? '', result.stderr ?? '', result.error?.message ?? '']
34
- .filter((part) => part.trim() !== '')
35
- .join('\n')
36
- .trim();
37
- return new GeneratorRun(result.status ?? 1, output);
38
- }
39
- };
40
- exports.GeneratorRunner = GeneratorRunner;
41
- exports.GeneratorRunner = GeneratorRunner = tslib_1.__decorate([
42
- (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
43
- ], GeneratorRunner);
44
- //# sourceMappingURL=generator-runner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generator-runner.js","sourceRoot":"","sources":["../../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/contract/generator-runner.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,yCAA2D;AAG3D,iDAAiD;AACjD,MAAa,YAAY;IAER;IAEA;IAHb,YACa,QAAgB;IACzB,uFAAuF;IAC9E,MAAc;QAFd,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,WAAM,GAAN,MAAM,CAAQ;IACxB,CAAC;IAEJ,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,QAAQ,KAAK,CAAC,CAAC;IAC/B,CAAC;CACJ;AAVD,oCAUC;AAED;;;;;;;GAOG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IACxB,GAAG,CAAC,GAAgB,EAAE,IAAuB,EAAE,GAAW;QACtD,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QAC9F,MAAM,MAAM,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,IAAI,EAAE,CAAC;aACjF,MAAM,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;aAC5C,IAAI,CAAC,IAAI,CAAC;aACV,IAAI,EAAE,CAAC;QACZ,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;CACJ,CAAA;AATY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,eAAe,CAS3B","sourcesContent":["import { spawnSync } from 'child_process';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ConsumerBin } from './consumer-bin-resolver';\n\n/** One finished generator process. Data-only. */\nexport class GeneratorRun {\n constructor(\n readonly exitCode: number,\n /** stdout and stderr, in that order — the generator reports its refusals on stdout. */\n readonly output: string,\n ) {}\n\n get ok(): boolean {\n return this.exitCode === 0;\n }\n}\n\n/**\n * Runs a resolved {@link ConsumerBin} with the node that is running US, so the generator gets the\n * consumer's `node_modules` (it lives there) without depending on a `.bin` shim or on `PATH`.\n *\n * It REPORTS the outcome rather than throwing on a non-zero exit, because the two callers mean\n * different things by one: the nx executor refuses the build, while the PR gate's merge-base run\n * records \"the merge-base does not generate with today's generator\" and says so in the PR.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class GeneratorRunner {\n run(bin: ConsumerBin, args: readonly string[], cwd: string): GeneratorRun {\n const result = spawnSync(process.execPath, [bin.binPath, ...args], { cwd, encoding: 'utf8' });\n const output = [result.stdout ?? '', result.stderr ?? '', result.error?.message ?? '']\n .filter((part: string) => part.trim() !== '')\n .join('\\n')\n .trim();\n return new GeneratorRun(result.status ?? 1, output);\n }\n}\n"]}
@@ -1,6 +0,0 @@
1
- /** Everything a JSON document can hold — a parsed OpenAPI document or package.json is exactly this. */
2
- export type JsonValue = string | number | boolean | null | JsonValue[] | JsonObject;
3
- /** The object case of {@link JsonValue}, named so the recursive alias can refer to it. */
4
- export type JsonObject = {
5
- [key: string]: JsonValue;
6
- };
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=json-value.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"json-value.js","sourceRoot":"","sources":["../../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/contract/json-value.ts"],"names":[],"mappings":"","sourcesContent":["/** Everything a JSON document can hold — a parsed OpenAPI document or package.json is exactly this. */\nexport type JsonValue = string | number | boolean | null | JsonValue[] | JsonObject;\n\n/** The object case of {@link JsonValue}, named so the recursive alias can refer to it. */\nexport type JsonObject = { [key: string]: JsonValue };\n"]}
@@ -1,45 +0,0 @@
1
- import { JsonObject } from './json-value';
2
- export type ContractChangeKind = 'added' | 'removed' | 'changed';
3
- /** One partner-visible difference between two OpenAPI documents. Data-only. */
4
- export declare class ContractChange {
5
- readonly kind: ContractChangeKind;
6
- /** What moved, as a reviewer names it: `POST /orders/fetch`, `webhook order.state-changed`, `schema Order`. */
7
- readonly subject: string;
8
- /** For `changed`: which parts of it moved, e.g. `+ field window`, `requestBody`. Empty otherwise. */
9
- readonly details: readonly string[];
10
- constructor(kind: ContractChangeKind,
11
- /** What moved, as a reviewer names it: `POST /orders/fetch`, `webhook order.state-changed`, `schema Order`. */
12
- subject: string,
13
- /** For `changed`: which parts of it moved, e.g. `+ field window`, `requestBody`. Empty otherwise. */
14
- details: readonly string[]);
15
- }
16
- /**
17
- * The partner-visible difference between two OpenAPI documents, item by item: operations, webhooks,
18
- * named schemas, and every other top-level section (info, servers, security, tags).
19
- *
20
- * It compares STRUCTURE, never text: a key reordering is not a change, and a changed operation reports
21
- * WHICH of its parts moved, so the PR comment says "the 200 response changed" rather than dumping two
22
- * JSON blobs for a reviewer to diff by eye.
23
- *
24
- * `before` is `undefined` when the merge-base had no document — a brand-new contract — which makes
25
- * every item `added`; `after` is `undefined` when HEAD dropped the document.
26
- */
27
- export declare class OpenApiContractDiff {
28
- diff(before: JsonObject | undefined, after: JsonObject | undefined): ContractChange[];
29
- private operations;
30
- /** `paths` → one entry per `<METHOD> <path>`, so an added method on an existing path is its own line. */
31
- private flatten;
32
- private schemas;
33
- private componentsOtherThanSchemas;
34
- private topLevel;
35
- /** Field-level detail for a changed object schema; anything else about it by key. */
36
- private schemaDetails;
37
- private compare;
38
- private changedKeys;
39
- private union;
40
- /** Structural equality: object key ORDER never counts, array order does. */
41
- private same;
42
- private canonical;
43
- private object;
44
- private strings;
45
- }
@@ -1,158 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpenApiContractDiff = exports.ContractChange = void 0;
4
- const tslib_1 = require("tslib");
5
- const inversify_1 = require("inversify");
6
- /** One partner-visible difference between two OpenAPI documents. Data-only. */
7
- class ContractChange {
8
- kind;
9
- subject;
10
- details;
11
- constructor(kind,
12
- /** What moved, as a reviewer names it: `POST /orders/fetch`, `webhook order.state-changed`, `schema Order`. */
13
- subject,
14
- /** For `changed`: which parts of it moved, e.g. `+ field window`, `requestBody`. Empty otherwise. */
15
- details) {
16
- this.kind = kind;
17
- this.subject = subject;
18
- this.details = details;
19
- }
20
- }
21
- exports.ContractChange = ContractChange;
22
- const METHODS = ['get', 'put', 'post', 'delete', 'patch', 'options', 'head', 'trace'];
23
- /** The document sections walked item by item; everything else is compared as one value per key. */
24
- const WALKED = new Set(['paths', 'webhooks', 'components']);
25
- /**
26
- * The partner-visible difference between two OpenAPI documents, item by item: operations, webhooks,
27
- * named schemas, and every other top-level section (info, servers, security, tags).
28
- *
29
- * It compares STRUCTURE, never text: a key reordering is not a change, and a changed operation reports
30
- * WHICH of its parts moved, so the PR comment says "the 200 response changed" rather than dumping two
31
- * JSON blobs for a reviewer to diff by eye.
32
- *
33
- * `before` is `undefined` when the merge-base had no document — a brand-new contract — which makes
34
- * every item `added`; `after` is `undefined` when HEAD dropped the document.
35
- */
36
- let OpenApiContractDiff = class OpenApiContractDiff {
37
- diff(before, after) {
38
- const base = before ?? {};
39
- const head = after ?? {};
40
- return [
41
- ...this.operations(base, head, 'paths', (key, method) => `${method.toUpperCase()} ${key}`),
42
- ...this.operations(base, head, 'webhooks', (key, method) => `webhook ${key} (${method.toUpperCase()})`),
43
- ...this.schemas(base, head),
44
- ...this.topLevel(base, head),
45
- ];
46
- }
47
- operations(base, head, section, name) {
48
- const before = this.flatten(this.object(base[section]), name);
49
- const after = this.flatten(this.object(head[section]), name);
50
- return this.compare(before, after, (was, now) => this.changedKeys(this.object(was), this.object(now)));
51
- }
52
- /** `paths` → one entry per `<METHOD> <path>`, so an added method on an existing path is its own line. */
53
- flatten(section, name) {
54
- const out = new Map();
55
- for (const key of Object.keys(section).sort()) {
56
- const item = this.object(section[key]);
57
- for (const method of METHODS) {
58
- if (item[method] !== undefined)
59
- out.set(name(key, method), item[method]);
60
- }
61
- }
62
- return out;
63
- }
64
- schemas(base, head) {
65
- const named = (doc) => {
66
- const schemas = this.object(this.object(doc['components'])['schemas']);
67
- return new Map(Object.keys(schemas).sort().map((key) => [`schema ${key}`, schemas[key]]));
68
- };
69
- const componentsRest = this.compare(this.componentsOtherThanSchemas(base), this.componentsOtherThanSchemas(head), () => []);
70
- return [
71
- ...this.compare(named(base), named(head), (was, now) => this.schemaDetails(this.object(was), this.object(now))),
72
- ...componentsRest,
73
- ];
74
- }
75
- componentsOtherThanSchemas(doc) {
76
- const components = this.object(doc['components']);
77
- return new Map(Object.keys(components).filter((key) => key !== 'schemas').sort()
78
- .map((key) => [`components.${key}`, components[key]]));
79
- }
80
- topLevel(base, head) {
81
- const rest = (doc) => new Map(Object.keys(doc)
82
- .filter((key) => !WALKED.has(key)).sort()
83
- .map((key) => [`document ${key}`, doc[key]]));
84
- return this.compare(rest(base), rest(head), () => []);
85
- }
86
- /** Field-level detail for a changed object schema; anything else about it by key. */
87
- schemaDetails(was, now) {
88
- const wasProps = this.object(was['properties']);
89
- const nowProps = this.object(now['properties']);
90
- const details = [];
91
- for (const key of this.union(wasProps, nowProps)) {
92
- if (!(key in nowProps))
93
- details.push(`- field ${key}`);
94
- else if (!(key in wasProps))
95
- details.push(`+ field ${key}`);
96
- else if (!this.same(wasProps[key], nowProps[key]))
97
- details.push(`~ field ${key}`);
98
- }
99
- const wasRequired = this.strings(was['required']);
100
- const nowRequired = this.strings(now['required']);
101
- for (const key of nowRequired.filter((each) => !wasRequired.includes(each)))
102
- details.push(`now required: ${key}`);
103
- for (const key of wasRequired.filter((each) => !nowRequired.includes(each)))
104
- details.push(`now optional: ${key}`);
105
- const rest = (schema) => {
106
- const copy = { ...schema };
107
- delete copy['properties'];
108
- delete copy['required'];
109
- return copy;
110
- };
111
- return [...details, ...this.changedKeys(rest(was), rest(now))];
112
- }
113
- compare(before, after, detail) {
114
- const changes = [];
115
- for (const subject of after.keys()) {
116
- const now = after.get(subject);
117
- if (!before.has(subject))
118
- changes.push(new ContractChange('added', subject, []));
119
- else if (!this.same(before.get(subject), now))
120
- changes.push(new ContractChange('changed', subject, detail(before.get(subject), now)));
121
- }
122
- for (const subject of before.keys()) {
123
- if (!after.has(subject))
124
- changes.push(new ContractChange('removed', subject, []));
125
- }
126
- return changes;
127
- }
128
- changedKeys(was, now) {
129
- return this.union(was, now).filter((key) => !this.same(was[key], now[key]));
130
- }
131
- union(a, b) {
132
- return [...new Set([...Object.keys(a), ...Object.keys(b)])].sort();
133
- }
134
- /** Structural equality: object key ORDER never counts, array order does. */
135
- same(a, b) {
136
- return this.canonical(a) === this.canonical(b);
137
- }
138
- canonical(value) {
139
- if (Array.isArray(value))
140
- return `[${value.map((each) => this.canonical(each)).join(',')}]`;
141
- if (value !== null && typeof value === 'object') {
142
- const obj = value;
143
- return `{${Object.keys(obj).sort().map((key) => `${JSON.stringify(key)}:${this.canonical(obj[key])}`).join(',')}}`;
144
- }
145
- return JSON.stringify(value) ?? 'undefined';
146
- }
147
- object(value) {
148
- return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : {};
149
- }
150
- strings(value) {
151
- return Array.isArray(value) ? value.filter((each) => typeof each === 'string') : [];
152
- }
153
- };
154
- exports.OpenApiContractDiff = OpenApiContractDiff;
155
- exports.OpenApiContractDiff = OpenApiContractDiff = tslib_1.__decorate([
156
- (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
157
- ], OpenApiContractDiff);
158
- //# sourceMappingURL=openapi-contract-diff.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"openapi-contract-diff.js","sourceRoot":"","sources":["../../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/contract/openapi-contract-diff.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAK3D,+EAA+E;AAC/E,MAAa,cAAc;IAEV;IAEA;IAEA;IALb,YACa,IAAwB;IACjC,+GAA+G;IACtG,OAAe;IACxB,qGAAqG;IAC5F,OAA0B;QAJ1B,SAAI,GAAJ,IAAI,CAAoB;QAExB,YAAO,GAAP,OAAO,CAAQ;QAEf,YAAO,GAAP,OAAO,CAAmB;IACpC,CAAC;CACP;AARD,wCAQC;AAID,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAEtF,mGAAmG;AACnG,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;AAE5D;;;;;;;;;;GAUG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC5B,IAAI,CAAC,MAA8B,EAAE,KAA6B;QAC9D,MAAM,IAAI,GAAG,MAAM,IAAI,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,KAAK,IAA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AAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC;IAChD,CAAC;IAEO,MAAM,CAAC,KAA4B;QACvC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAE,KAAoB,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7G,CAAC;IAEO,OAAO,CAAC,KAA4B;QACxC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAe,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACnH,CAAC;CACJ,CAAA;AAjIY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,mBAAmB,CAiI/B","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport { JsonObject, JsonValue } from './json-value';\n\nexport type ContractChangeKind = 'added' | 'removed' | 'changed';\n\n/** One partner-visible difference between two OpenAPI documents. Data-only. */\nexport class ContractChange {\n constructor(\n readonly kind: ContractChangeKind,\n /** What moved, as a reviewer names it: `POST /orders/fetch`, `webhook order.state-changed`, `schema Order`. */\n readonly subject: string,\n /** For `changed`: which parts of it moved, e.g. `+ field window`, `requestBody`. Empty otherwise. */\n readonly details: readonly string[],\n ) {}\n}\n\ntype Entry = [string, JsonValue];\n\nconst METHODS = ['get', 'put', 'post', 'delete', 'patch', 'options', 'head', 'trace'];\n\n/** The document sections walked item by item; everything else is compared as one value per key. */\nconst WALKED = new Set(['paths', 'webhooks', 'components']);\n\n/**\n * The partner-visible difference between two OpenAPI documents, item by item: operations, webhooks,\n * named schemas, and every other top-level section (info, servers, security, tags).\n *\n * It compares STRUCTURE, never text: a key reordering is not a change, and a changed operation reports\n * WHICH of its parts moved, so the PR comment says \"the 200 response changed\" rather than dumping two\n * JSON blobs for a reviewer to diff by eye.\n *\n * `before` is `undefined` when the merge-base had no document — a brand-new contract — which makes\n * every item `added`; `after` is `undefined` when HEAD dropped the document.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class OpenApiContractDiff {\n diff(before: JsonObject | undefined, after: JsonObject | undefined): ContractChange[] {\n const base = before ?? {};\n const head = after ?? {};\n return [\n ...this.operations(base, head, 'paths', (key: string, method: string): string => `${method.toUpperCase()} ${key}`),\n ...this.operations(base, head, 'webhooks', (key: string, method: string): string => `webhook ${key} (${method.toUpperCase()})`),\n ...this.schemas(base, head),\n ...this.topLevel(base, head),\n ];\n }\n\n private operations(\n base: JsonObject, head: JsonObject, section: string, name: (key: string, method: string) => string,\n ): ContractChange[] {\n const before = this.flatten(this.object(base[section]), name);\n const after = this.flatten(this.object(head[section]), name);\n return this.compare(before, after, (was: JsonValue | undefined, now: JsonValue | undefined): string[] =>\n this.changedKeys(this.object(was), this.object(now)));\n }\n\n /** `paths` → one entry per `<METHOD> <path>`, so an added method on an existing path is its own line. */\n private flatten(section: JsonObject, name: (key: string, method: string) => string): Map<string, JsonValue> {\n const out = new Map<string, JsonValue>();\n for (const key of Object.keys(section).sort()) {\n const item = this.object(section[key]);\n for (const method of METHODS) {\n if (item[method] !== undefined) out.set(name(key, method), item[method]);\n }\n }\n return out;\n }\n\n private schemas(base: JsonObject, head: JsonObject): ContractChange[] {\n const named = (doc: JsonObject): Map<string, JsonValue> => {\n const schemas = this.object(this.object(doc['components'])['schemas']);\n return new Map(Object.keys(schemas).sort().map((key: string): Entry => [`schema ${key}`, schemas[key]]));\n };\n const componentsRest = this.compare(\n this.componentsOtherThanSchemas(base), this.componentsOtherThanSchemas(head),\n (): string[] => [],\n );\n return [\n ...this.compare(named(base), named(head), (was: JsonValue | undefined, now: JsonValue | undefined): string[] =>\n this.schemaDetails(this.object(was), this.object(now))),\n ...componentsRest,\n ];\n }\n\n private componentsOtherThanSchemas(doc: JsonObject): Map<string, JsonValue> {\n const components = this.object(doc['components']);\n return new Map(Object.keys(components).filter((key: string) => key !== 'schemas').sort()\n .map((key: string): Entry => [`components.${key}`, components[key]]));\n }\n\n private topLevel(base: JsonObject, head: JsonObject): ContractChange[] {\n const rest = (doc: JsonObject): Map<string, JsonValue> => new Map(Object.keys(doc)\n .filter((key: string) => !WALKED.has(key)).sort()\n .map((key: string): Entry => [`document ${key}`, doc[key]]));\n return this.compare(rest(base), rest(head), (): string[] => []);\n }\n\n /** Field-level detail for a changed object schema; anything else about it by key. */\n private schemaDetails(was: JsonObject, now: JsonObject): string[] {\n const wasProps = this.object(was['properties']);\n const nowProps = this.object(now['properties']);\n const details: string[] = [];\n for (const key of this.union(wasProps, nowProps)) {\n if (!(key in nowProps)) details.push(`- field ${key}`);\n else if (!(key in wasProps)) details.push(`+ field ${key}`);\n else if (!this.same(wasProps[key], nowProps[key])) details.push(`~ field ${key}`);\n }\n const wasRequired = this.strings(was['required']);\n const nowRequired = this.strings(now['required']);\n for (const key of nowRequired.filter((each: string) => !wasRequired.includes(each))) details.push(`now required: ${key}`);\n for (const key of wasRequired.filter((each: string) => !nowRequired.includes(each))) details.push(`now optional: ${key}`);\n const rest = (schema: JsonObject): JsonObject => {\n const copy: JsonObject = { ...schema };\n delete copy['properties'];\n delete copy['required'];\n return copy;\n };\n return [...details, ...this.changedKeys(rest(was), rest(now))];\n }\n\n private compare(\n before: Map<string, JsonValue>, after: Map<string, JsonValue>, detail: (was: JsonValue | undefined, now: JsonValue | undefined) => string[],\n ): ContractChange[] {\n const changes: ContractChange[] = [];\n for (const subject of after.keys()) {\n const now = after.get(subject);\n if (!before.has(subject)) changes.push(new ContractChange('added', subject, []));\n else if (!this.same(before.get(subject), now)) changes.push(new ContractChange('changed', subject, detail(before.get(subject), now)));\n }\n for (const subject of before.keys()) {\n if (!after.has(subject)) changes.push(new ContractChange('removed', subject, []));\n }\n return changes;\n }\n\n private changedKeys(was: JsonObject, now: JsonObject): string[] {\n return this.union(was, now).filter((key: string) => !this.same(was[key], now[key]));\n }\n\n private union(a: JsonObject, b: JsonObject): string[] {\n return [...new Set([...Object.keys(a), ...Object.keys(b)])].sort();\n }\n\n /** Structural equality: object key ORDER never counts, array order does. */\n private same(a: JsonValue | undefined, b: JsonValue | undefined): boolean {\n return this.canonical(a) === this.canonical(b);\n }\n\n private canonical(value: JsonValue | undefined): string {\n if (Array.isArray(value)) return `[${value.map((each: JsonValue) => this.canonical(each)).join(',')}]`;\n if (value !== null && typeof value === 'object') {\n const obj = value as JsonObject;\n return `{${Object.keys(obj).sort().map((key: string) => `${JSON.stringify(key)}:${this.canonical(obj[key])}`).join(',')}}`;\n }\n return JSON.stringify(value) ?? 'undefined';\n }\n\n private object(value: JsonValue | undefined): JsonObject {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? (value as JsonObject) : {};\n }\n\n private strings(value: JsonValue | undefined): string[] {\n return Array.isArray(value) ? value.filter((each: JsonValue): each is string => typeof each === 'string') : [];\n }\n}\n"]}