@webpieces/nx-webpieces-rules 0.4.832 ā 0.4.834
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/package.json +8 -8
- package/src/executors/generate/executor.js +2 -0
- package/src/executors/generate/executor.js.map +1 -1
- package/src/executors/openapi-components-generate/executor.d.ts +2 -1
- package/src/executors/openapi-components-generate/executor.js +5 -2
- package/src/executors/openapi-components-generate/executor.js.map +1 -1
- package/src/executors/openapi-generate/executor.d.ts +15 -1
- package/src/executors/openapi-generate/executor.js +30 -2
- package/src/executors/openapi-generate/executor.js.map +1 -1
- package/src/executors/validate-api-lib-tag/executor.d.ts +5 -3
- package/src/executors/validate-api-lib-tag/executor.js +7 -5
- package/src/executors/validate-api-lib-tag/executor.js.map +1 -1
- package/src/executors/validate-architecture-unchanged/executor.js +2 -0
- package/src/executors/validate-architecture-unchanged/executor.js.map +1 -1
- package/src/lib/api-docs/components-wiring.d.ts +6 -0
- package/src/lib/api-docs/components-wiring.js +18 -1
- package/src/lib/api-docs/components-wiring.js.map +1 -1
- package/src/lib/api-usage/api-doc-rules-scan.d.ts +17 -1
- package/src/lib/api-usage/api-doc-rules-scan.js +28 -3
- package/src/lib/api-usage/api-doc-rules-scan.js.map +1 -1
- package/src/lib/api-usage/api-lib-tag-validator.d.ts +51 -14
- package/src/lib/api-usage/api-lib-tag-validator.js +272 -22
- package/src/lib/api-usage/api-lib-tag-validator.js.map +1 -1
- package/src/lib/api-usage/api-scanner.d.ts +3 -1
- package/src/lib/api-usage/api-scanner.js +6 -3
- package/src/lib/api-usage/api-scanner.js.map +1 -1
- package/src/lib/api-usage/wire-closure.d.ts +49 -0
- package/src/lib/api-usage/wire-closure.js +126 -0
- package/src/lib/api-usage/wire-closure.js.map +1 -0
- package/src/lib/dep-usage-scanner.d.ts +6 -2
- package/src/lib/dep-usage-scanner.js +45 -28
- package/src/lib/dep-usage-scanner.js.map +1 -1
- package/src/lib/di-graph/analyzer-strategy.d.ts +1 -0
- package/src/lib/di-graph/analyzer-strategy.js +3 -0
- package/src/lib/di-graph/analyzer-strategy.js.map +1 -1
- package/src/lib/framework-resolver.d.ts +1 -1
- package/src/lib/framework-resolver.js +5 -2
- package/src/lib/framework-resolver.js.map +1 -1
- package/src/lib/graph-metadata.d.ts +9 -2
- package/src/lib/graph-metadata.js +12 -3
- package/src/lib/graph-metadata.js.map +1 -1
- package/src/lib/graph-visualizer.js +6 -0
- package/src/lib/graph-visualizer.js.map +1 -1
- package/src/lib/role-resolver.d.ts +9 -3
- package/src/lib/role-resolver.js +12 -4
- package/src/lib/role-resolver.js.map +1 -1
- package/src/lib/tag-truth.d.ts +106 -0
- package/src/lib/tag-truth.js +323 -0
- package/src/lib/tag-truth.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/nx-webpieces-rules",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.834",
|
|
4
4
|
"description": "Nx-specific webpieces validation rules and graph tooling. Bundles all @webpieces rule packages with Nx graph validators and an inference plugin.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@webpieces/ai-hook-rules": "0.4.
|
|
22
|
-
"@webpieces/api-doc-model": "0.4.
|
|
23
|
-
"@webpieces/code-rules": "0.4.
|
|
24
|
-
"@webpieces/core-util": "0.4.
|
|
25
|
-
"@webpieces/eslint-rules": "0.4.
|
|
26
|
-
"@webpieces/pr-gate": "0.4.
|
|
27
|
-
"@webpieces/rules-config": "0.4.
|
|
21
|
+
"@webpieces/ai-hook-rules": "0.4.834",
|
|
22
|
+
"@webpieces/api-doc-model": "0.4.834",
|
|
23
|
+
"@webpieces/code-rules": "0.4.834",
|
|
24
|
+
"@webpieces/core-util": "0.4.834",
|
|
25
|
+
"@webpieces/eslint-rules": "0.4.834",
|
|
26
|
+
"@webpieces/pr-gate": "0.4.834",
|
|
27
|
+
"@webpieces/rules-config": "0.4.834",
|
|
28
28
|
"madge": "8.0.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
@@ -17,6 +17,7 @@ const graph_cycles_1 = require("../../lib/graph-cycles");
|
|
|
17
17
|
const graph_loader_1 = require("../../lib/graph-loader");
|
|
18
18
|
const api_contract_files_1 = require("../../lib/api-contract-files");
|
|
19
19
|
const graph_metadata_1 = require("../../lib/graph-metadata");
|
|
20
|
+
const tag_truth_1 = require("../../lib/tag-truth");
|
|
20
21
|
const api_scanner_1 = require("../../lib/api-usage/api-scanner");
|
|
21
22
|
// The unresolved-contract report moved beside the other contract reports when api-scanner.ts reached
|
|
22
23
|
// its file-size limit.
|
|
@@ -153,6 +154,7 @@ async function generateEverything(workspaceRoot, graphPath) {
|
|
|
153
154
|
console.log('š·ļø Enriching graph with framework + responsibilities metadata...');
|
|
154
155
|
const projectInfos = await (0, graph_metadata_1.collectProjectInfo)();
|
|
155
156
|
(0, graph_metadata_1.enrichGraph)(enhancedGraph, projectInfos, workspaceRoot);
|
|
157
|
+
new tag_truth_1.TagTruthCheck().assertTrue(enhancedGraph, projectInfos, workspaceRoot); // #1064, before any write
|
|
156
158
|
// Step 3b: Classify each api-lib edge (implements/uses + rpc/pubsub) by
|
|
157
159
|
// scanning source, so dependencies.json + the viz + the runtime graph all
|
|
158
160
|
// read the same derived truth.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/executors/generate/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AA8NH,8BA2BC;AAtPD,0DAA+F;AAC/F,+DAAiE;AACjE,yDAAgE;AAChE,yDAA8D;AAC9D,yDAAuE;AACvE,qEAAgE;AAChE,6DAAoG;AAEpG,iEAKyC;AACzC,qGAAqG;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,CAAC","sourcesContent":["/**\n * Generate Executor\n *\n * Generates the architecture dependency graph and saves it to architecture/dependencies.json, plus\n * one contract file per API under architecture/apis/ (stale ones are deleted).\n *\n * Usage:\n * nx run architecture:generate\n */\n\nimport type { ExecutorContext } from '@nx/devkit';\nimport { writeTemplate, RuleFailError, renderRuleFailForHuman } from '@webpieces/rules-config';\nimport { generateReducedGraph } from '../../lib/graph-generator';\nimport { sortGraphTopologically } from '../../lib/graph-sorter';\nimport { ProjectCycleDetector } from '../../lib/graph-cycles';\nimport { saveGraph, DEFAULT_GRAPH_PATH } from '../../lib/graph-loader';\nimport { ApiContractFiles } from '../../lib/api-contract-files';\nimport { collectProjectInfo, enrichGraph, MetadataValidationError } from '../../lib/graph-metadata';\nimport { ProjectInfo } from '../../lib/project-info';\nimport {\n scanAndAttachApiRelations,\n describeNonLiteralDecoratorArgs,\n buildApiContracts,\n describeMismatchedEndpointKinds,\n} from '../../lib/api-usage/api-scanner';\n// The unresolved-contract report moved beside the other contract reports when api-scanner.ts reached\n// its file-size limit.\nimport {\n describeMcpExclusions,\n describeUnresolvedApiCalls,\n} from '../../lib/api-usage/api-contract-errors';\nimport { buildExternalSystems } from '../../lib/api-usage/external-systems';\nimport type { ApiContracts, ExternalSystemDecls } from '../../lib/api-usage/api-relations';\nimport { loadRuntimeConfig } from '../../lib/runtime-config';\nimport type { EnhancedGraph, GraphEntry } from '../../lib/graph-sorter';\nimport { GraphVisualizer } from '../../lib/graph-visualizer';\nimport { deriveRuntimeGraphReport, saveRuntimeGraph } from '../../lib/runtime-graph';\nimport { printAutoHiddenServers } from '../../lib/runtime-participant-resolver';\nimport { toError } from '../../toError';\n\nexport interface GenerateExecutorOptions {\n graphPath?: string;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\n/**\n * Generate the runtime microservice graph alongside the compile-time graph, DERIVED from the same\n * dependencies.json (its per-project apiRelations) ā one regenerate produces both committed files, and\n * validate derives from the SAME source so they can't diverge. rpc APIs become direct runtime edges;\n * pubsub APIs become edges the viz draws through a queue.\n */\n// webpieces-disable no-function-outside-class -- executor step helper, like the rest of this executor file\nfunction generateRuntimeGraph(\n workspaceRoot: string,\n graph: EnhancedGraph,\n hiddenProjects: Set<string>,\n apiContracts: ApiContracts,\n externalSystems: ExternalSystemDecls,\n): void {\n console.log('š” Deriving runtime graph from dependencies.json (implements Ć uses per API)...');\n const report = deriveRuntimeGraphReport(graph, hiddenProjects, apiContracts, externalSystems);\n saveRuntimeGraph(report.graph, workspaceRoot);\n const serviceCount = Object.keys(report.graph.services).length;\n const queueCount = Object.keys(report.graph.queues).length;\n console.log(\n `ā
Runtime graph saved (${serviceCount} services, ${report.graph.runtimeEdges.length} runtime edges, ` +\n `${queueCount} queues, ${report.graph.triggers.length} cron/external triggers)`,\n );\n // Every edge the derivation had to GUESS at. Loud on purpose: a fanned-out edge is committed and\n // then reasoned about as if it were derived, which is how a fictional call survives for months.\n printRuntimeWarnings(report.warnings);\n printAutoHiddenServers(report.autoHidden);\n // Printed here, FAILED by validate-runtime-architecture: generate must still write the graph,\n // or the validator would have nothing to compare against and the error would be unfixable.\n if (report.problems.length > 0) {\n console.error(`ā ${report.problems.length} client call(s) name a service no module answers to:`);\n for (const problem of report.problems) console.error(` ⢠${problem}`);\n console.error(' This FAILS architecture:validate-runtime-architecture.');\n }\n}\n\n/** Print the derivation's guessed-edge warnings (nothing at all when the graph is fully targeted). */\n// webpieces-disable no-function-outside-class -- executor step helper, like the rest of this executor file\nfunction printRuntimeWarnings(warnings: string[]): void {\n if (warnings.length === 0) return;\n console.warn(`ā ļø ${warnings.length} runtime edge(s) could not be targeted to ONE service:`);\n for (const warning of warnings) console.warn(` ⢠${warning}`);\n}\n\n/**\n * Scan for api relations and attach them, surfacing any contract we could NOT map back to source.\n * Unresolved contracts mean the graph we are about to WRITE is incomplete, so they must be loud ā\n * a green run that quietly omits a service gets committed, rendered, and trusted.\n */\n// webpieces-disable no-function-outside-class -- executor step helper, like the rest of this executor file\nfunction scanApiRelations(\n workspaceRoot: string,\n graph: EnhancedGraph,\n projectInfos: Map<string, ProjectInfo>,\n): ScannedTables {\n console.log('š Scanning source for implements/uses API relations...');\n const externalApiPaths = loadRuntimeConfig(workspaceRoot).externalApiPaths;\n const scan = scanAndAttachApiRelations(workspaceRoot, graph, projectInfos, externalApiPaths);\n if (scan.unresolvedApiCalls.length > 0) console.warn(describeUnresolvedApiCalls(scan.unresolvedApiCalls));\n // #1014: restated on EVERY run, green or red. An exclusion announced once, at the moment\n // somebody adds it, is read by the one person who already knows the decision.\n if (scan.apiDocRules.mcpExclusions.length > 0) {\n console.log(describeMcpExclusions(scan.apiDocRules.mcpExclusions));\n }\n // A decorator argument we could not read costs the graph a basePath, a method, or a whole\n // contract ā none of which leaves a trace in the output. Name them before anything is written.\n if (scan.nonLiteralDecoratorArgs.length > 0) {\n console.warn(describeNonLiteralDecoratorArgs(scan.nonLiteralDecoratorArgs));\n }\n const contracts = buildApiContracts(scan);\n // An endpoint whose declared trigger its api kind cannot deliver would silently draw a queue or a\n // clock that nothing could ever fire ā name it here, where the fix is one decorator away.\n const mismatches = describeMismatchedEndpointKinds(contracts);\n if (mismatches.length > 0) {\n console.error(`ā ${mismatches.length} @Endpoint kind(s) conflict with their api kind:`);\n for (const mismatch of mismatches) console.error(` ⢠${mismatch}`);\n }\n return new ScannedTables(contracts, buildExternalSystems(scan.apiIndex, projectInfos));\n}\n\n/** The two committed tables one scan produces, kept together so callers cannot persist just one. */\nclass ScannedTables {\n constructor(\n public readonly apiContracts: ApiContracts,\n public readonly externalSystems: ExternalSystemDecls,\n ) {}\n}\n\n/** Projects tagged drawOnGraph:false ā kept in the JSON, omitted from every rendered graph. */\n// webpieces-disable no-function-outside-class -- executor step helper, like the rest of this executor file\nfunction hiddenProjectsIn(graph: EnhancedGraph): Set<string> {\n const hidden = new Set<string>();\n for (const name of Object.keys(graph)) {\n if (graph[name].drawOnGraph === false) hidden.add(name);\n }\n return hidden;\n}\n\n// webpieces-disable no-function-outside-class -- executor step helper, like the rest of this executor file\nfunction printGraphSummary(graph: EnhancedGraph): void {\n const levels = new Set(Object.values(graph).map((entry: GraphEntry) => entry.level));\n console.log(`\\nš Graph Summary:`);\n console.log(` Projects: ${Object.keys(graph).length}`);\n console.log(` Levels: ${levels.size} (0-${Math.max(...levels)})`);\n}\n\n/**\n * The whole generation pipeline. Split out of runExecutor so that function stays a thin\n * try/catch-and-report shell ā the error reporting is what a caller reads on failure, and it should\n * not be separated from the throw by fifty lines of steps.\n */\n// webpieces-disable no-function-outside-class -- executor step helper, like the rest of this executor file\nasync function generateEverything(workspaceRoot: string, graphPath: string | undefined): Promise<void> {\n // Step 1: Build the full graph from nx, then transitively reduce it to the view\n console.log(\"š Generating dependency graph from nx's project graph...\");\n const reducedGraph = await generateReducedGraph();\n\n // Step 1b: The graph is a BUILD graph ā refuse a cyclic one, naming EVERY cycle. This runs\n // before the sort deliberately: the sort also refuses, but reports one cycle and an\n // undifferentiated list of everything tangled with it, so a repo with several cycles pays one\n // full regeneration per cycle to discover them.\n console.log('š Checking the project graph is acyclic...');\n const cycles = new ProjectCycleDetector();\n cycles.assertAcyclic(reducedGraph, 'the nx project graph');\n\n // Step 2: Topological sort (to assign levels for visualization)\n console.log('š Computing topological layers...');\n const enhancedGraph = sortGraphTopologically(reducedGraph);\n // ...and assert the stratification it just produced actually holds: every dependency strictly\n // below its dependent. Safe to assert only because the graph was sorted a line ago ā a stale\n // committed file is never checked this way.\n cycles.assertLevelsDescend(reducedGraph, cycles.levelsOf(enhancedGraph), 'the freshly sorted graph');\n\n // Step 3: Enrich with AI metadata (framework, shortDescription, file\n // pointers). This VALIDATES (responsibilities.md required per project)\n // and throws before any write, so a failure never clobbers the file.\n console.log('š·ļø Enriching graph with framework + responsibilities metadata...');\n const projectInfos = await collectProjectInfo();\n enrichGraph(enhancedGraph, projectInfos, workspaceRoot);\n\n // Step 3b: Classify each api-lib edge (implements/uses + rpc/pubsub) by\n // scanning source, so dependencies.json + the viz + the runtime graph all\n // read the same derived truth.\n const scanned = scanApiRelations(workspaceRoot, enhancedGraph, projectInfos);\n const apiContracts = scanned.apiContracts;\n\n // Step 4: Write one contract file per API (architecture/apis/<Api>.json) and delete the files of\n // APIs that no longer exist. dependencies.json only LINKS to them, so an endpoint change rewrites\n // an api file and never the dependency graph. The runtime validator reads these files back.\n const effectiveGraphPath = graphPath ?? DEFAULT_GRAPH_PATH;\n const contractFiles = new ApiContractFiles();\n const written = contractFiles.write(workspaceRoot, effectiveGraphPath, apiContracts);\n console.log(`ā
Wrote ${written.written.length} api contract file(s)`);\n for (const deleted of written.deleted) console.log(`šļø Deleted stale api contract file ${deleted}`);\n\n // Step 4a: Save the graph, INCLUDING the contract-file links and the external-system\n // declarations the runtime derivation reads back ā generate derives from the in-memory graph,\n // validate from the files, so anything not written here would make the two disagree.\n console.log('š¾ Saving graph to architecture/dependencies.json...');\n const contractRefs = contractFiles.refsFor(apiContracts);\n saveGraph(enhancedGraph, workspaceRoot, effectiveGraphPath, contractRefs, scanned.externalSystems);\n console.log('ā
Graph saved successfully');\n\n // Step 4b: Write the committed, clickable HTML view next to the JSON so\n // dependencies.html regenerates in lock-step with dependencies.json.\n const vizPaths = new GraphVisualizer().writeVisualization(enhancedGraph, workspaceRoot);\n console.log(`ā
Wrote ${vizPaths.htmlPath}`);\n\n // Step 5: Generate the runtime microservice graph from the same scan.\n // Projects tagged drawOnGraph:false are threaded through so the runtime\n // graph hides them too (they stay flagged in runtime-dependencies.json).\n generateRuntimeGraph(\n workspaceRoot,\n enhancedGraph,\n hiddenProjectsIn(enhancedGraph),\n apiContracts,\n scanned.externalSystems,\n );\n\n printGraphSummary(enhancedGraph);\n}\n\nexport default async function runExecutor(\n options: GenerateExecutorOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const graphPath = options.graphPath;\n const workspaceRoot = context.root;\n\n console.log('\\nš Architecture Graph Generator\\n');\n\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n await generateEverything(workspaceRoot, graphPath);\n return { success: true };\n } catch (err: unknown) {\n const error = toError(err);\n // A RuleFailError carries its cures as Option[]; `Error.message` is only the aiMessage, so\n // printing that alone silently drops them. renderRuleFailForHuman is the ONE renderer that\n // numbers them, and this catch is the top-level handler for the nx target.\n const rendered = error instanceof RuleFailError ? renderRuleFailForHuman(error) : error.message;\n console.error('ā Graph generation failed:', rendered);\n if (error instanceof MetadataValidationError) {\n const mdPath = writeTemplate(workspaceRoot, 'webpieces.responsibilities.md');\n console.error('');\n console.error('ā ļø *** Refer to ' + mdPath + ' for how to author responsibilities.md files *** ā ļø');\n }\n return { success: false };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/executors/generate/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAgOH,8BA2BC;AAxPD,0DAA+F;AAC/F,+DAAiE;AACjE,yDAAgE;AAChE,yDAA8D;AAC9D,yDAAuE;AACvE,qEAAgE;AAChE,6DAAoG;AACpG,mDAAoD;AAEpD,iEAKyC;AACzC,qGAAqG;AACrG,uBAAuB;AACvB,iFAGiD;AACjD,2EAA4E;AAE5E,6DAA6D;AAE7D,iEAA6D;AAC7D,2DAAqF;AACrF,yFAAgF;AAChF,2CAAwC;AAUxC;;;;;GAKG;AACH,2GAA2G;AAC3G,SAAS,oBAAoB,CACzB,aAAqB,EACrB,KAAoB,EACpB,cAA2B,EAC3B,YAA0B,EAC1B,eAAoC;IAEpC,OAAO,CAAC,GAAG,CAAC,iFAAiF,CAAC,CAAC;IAC/F,MAAM,MAAM,GAAG,IAAA,wCAAwB,EAAC,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,CAAC,CAAC;IAC9F,IAAA,gCAAgB,EAAC,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAC9C,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,C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I,CAAC;QACD,MAAM,kBAAkB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;QACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC7B,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,IAAA,iBAAO,EAAC,GAAG,CAAC,CAAC;QAC3B,2FAA2F;QAC3F,2FAA2F;QAC3F,2EAA2E;QAC3E,MAAM,QAAQ,GAAG,KAAK,YAAY,4BAAa,CAAC,CAAC,CAAC,IAAA,qCAAsB,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;QAChG,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,QAAQ,CAAC,CAAC;QACtD,IAAI,KAAK,YAAY,wCAAuB,EAAE,CAAC;YAC3C,MAAM,MAAM,GAAG,IAAA,4BAAa,EAAC,aAAa,EAAE,+BAA+B,CAAC,CAAC;YAC7E,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAClB,OAAO,CAAC,KAAK,CAAC,mBAAmB,GAAG,MAAM,GAAG,qDAAqD,CAAC,CAAC;QACxG,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;AACL,CAAC","sourcesContent":["/**\n * Generate Executor\n *\n * Generates the architecture dependency graph and saves it to architecture/dependencies.json, plus\n * one contract file per API under architecture/apis/ (stale ones are deleted).\n *\n * Usage:\n * nx run architecture:generate\n */\n\nimport type { ExecutorContext } from '@nx/devkit';\nimport { writeTemplate, RuleFailError, renderRuleFailForHuman } from '@webpieces/rules-config';\nimport { generateReducedGraph } from '../../lib/graph-generator';\nimport { sortGraphTopologically } from '../../lib/graph-sorter';\nimport { ProjectCycleDetector } from '../../lib/graph-cycles';\nimport { saveGraph, DEFAULT_GRAPH_PATH } from '../../lib/graph-loader';\nimport { ApiContractFiles } from '../../lib/api-contract-files';\nimport { collectProjectInfo, enrichGraph, MetadataValidationError } from '../../lib/graph-metadata';\nimport { TagTruthCheck } from '../../lib/tag-truth';\nimport { ProjectInfo } from '../../lib/project-info';\nimport {\n scanAndAttachApiRelations,\n describeNonLiteralDecoratorArgs,\n buildApiContracts,\n describeMismatchedEndpointKinds,\n} from '../../lib/api-usage/api-scanner';\n// The unresolved-contract report moved beside the other contract reports when api-scanner.ts reached\n// its file-size limit.\nimport {\n describeMcpExclusions,\n describeUnresolvedApiCalls,\n} from '../../lib/api-usage/api-contract-errors';\nimport { buildExternalSystems } from '../../lib/api-usage/external-systems';\nimport type { ApiContracts, ExternalSystemDecls } from '../../lib/api-usage/api-relations';\nimport { loadRuntimeConfig } from '../../lib/runtime-config';\nimport type { EnhancedGraph, GraphEntry } from '../../lib/graph-sorter';\nimport { GraphVisualizer } from '../../lib/graph-visualizer';\nimport { deriveRuntimeGraphReport, saveRuntimeGraph } from '../../lib/runtime-graph';\nimport { printAutoHiddenServers } from '../../lib/runtime-participant-resolver';\nimport { toError } from '../../toError';\n\nexport interface GenerateExecutorOptions {\n graphPath?: string;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\n/**\n * Generate the runtime microservice graph alongside the compile-time graph, DERIVED from the same\n * dependencies.json (its per-project apiRelations) ā one regenerate produces both committed files, and\n * validate derives from the SAME source so they can't diverge. rpc APIs become direct runtime edges;\n * pubsub APIs become edges the viz draws through a queue.\n */\n// webpieces-disable no-function-outside-class -- executor step helper, like the rest of this executor file\nfunction generateRuntimeGraph(\n workspaceRoot: string,\n graph: EnhancedGraph,\n hiddenProjects: Set<string>,\n apiContracts: ApiContracts,\n externalSystems: ExternalSystemDecls,\n): void {\n console.log('š” Deriving runtime graph from dependencies.json (implements Ć uses per API)...');\n const report = deriveRuntimeGraphReport(graph, hiddenProjects, apiContracts, externalSystems);\n saveRuntimeGraph(report.graph, workspaceRoot);\n const serviceCount = Object.keys(report.graph.services).length;\n const queueCount = Object.keys(report.graph.queues).length;\n console.log(\n `ā
Runtime graph saved (${serviceCount} services, ${report.graph.runtimeEdges.length} runtime edges, ` +\n `${queueCount} queues, ${report.graph.triggers.length} cron/external triggers)`,\n );\n // Every edge the derivation had to GUESS at. Loud on purpose: a fanned-out edge is committed and\n // then reasoned about as if it were derived, which is how a fictional call survives for months.\n printRuntimeWarnings(report.warnings);\n printAutoHiddenServers(report.autoHidden);\n // Printed here, FAILED by validate-runtime-architecture: generate must still write the graph,\n // or the validator would have nothing to compare against and the error would be unfixable.\n if (report.problems.length > 0) {\n console.error(`ā ${report.problems.length} client call(s) name a service no module answers to:`);\n for (const problem of report.problems) console.error(` ⢠${problem}`);\n console.error(' This FAILS architecture:validate-runtime-architecture.');\n }\n}\n\n/** Print the derivation's guessed-edge warnings (nothing at all when the graph is fully targeted). */\n// webpieces-disable no-function-outside-class -- executor step helper, like the rest of this executor file\nfunction printRuntimeWarnings(warnings: string[]): void {\n if (warnings.length === 0) return;\n console.warn(`ā ļø ${warnings.length} runtime edge(s) could not be targeted to ONE service:`);\n for (const warning of warnings) console.warn(` ⢠${warning}`);\n}\n\n/**\n * Scan for api relations and attach them, surfacing any contract we could NOT map back to source.\n * Unresolved contracts mean the graph we are about to WRITE is incomplete, so they must be loud ā\n * a green run that quietly omits a service gets committed, rendered, and trusted.\n */\n// webpieces-disable no-function-outside-class -- executor step helper, like the rest of this executor file\nfunction scanApiRelations(\n workspaceRoot: string,\n graph: EnhancedGraph,\n projectInfos: Map<string, ProjectInfo>,\n): ScannedTables {\n console.log('š Scanning source for implements/uses API relations...');\n const externalApiPaths = loadRuntimeConfig(workspaceRoot).externalApiPaths;\n const scan = scanAndAttachApiRelations(workspaceRoot, graph, projectInfos, externalApiPaths);\n if (scan.unresolvedApiCalls.length > 0) console.warn(describeUnresolvedApiCalls(scan.unresolvedApiCalls));\n // #1014: restated on EVERY run, green or red. An exclusion announced once, at the moment\n // somebody adds it, is read by the one person who already knows the decision.\n if (scan.apiDocRules.mcpExclusions.length > 0) {\n console.log(describeMcpExclusions(scan.apiDocRules.mcpExclusions));\n }\n // A decorator argument we could not read costs the graph a basePath, a method, or a whole\n // contract ā none of which leaves a trace in the output. Name them before anything is written.\n if (scan.nonLiteralDecoratorArgs.length > 0) {\n console.warn(describeNonLiteralDecoratorArgs(scan.nonLiteralDecoratorArgs));\n }\n const contracts = buildApiContracts(scan);\n // An endpoint whose declared trigger its api kind cannot deliver would silently draw a queue or a\n // clock that nothing could ever fire ā name it here, where the fix is one decorator away.\n const mismatches = describeMismatchedEndpointKinds(contracts);\n if (mismatches.length > 0) {\n console.error(`ā ${mismatches.length} @Endpoint kind(s) conflict with their api kind:`);\n for (const mismatch of mismatches) console.error(` ⢠${mismatch}`);\n }\n return new ScannedTables(contracts, buildExternalSystems(scan.apiIndex, projectInfos));\n}\n\n/** The two committed tables one scan produces, kept together so callers cannot persist just one. */\nclass ScannedTables {\n constructor(\n public readonly apiContracts: ApiContracts,\n public readonly externalSystems: ExternalSystemDecls,\n ) {}\n}\n\n/** Projects tagged drawOnGraph:false ā kept in the JSON, omitted from every rendered graph. */\n// webpieces-disable no-function-outside-class -- executor step helper, like the rest of this executor file\nfunction hiddenProjectsIn(graph: EnhancedGraph): Set<string> {\n const hidden = new Set<string>();\n for (const name of Object.keys(graph)) {\n if (graph[name].drawOnGraph === false) hidden.add(name);\n }\n return hidden;\n}\n\n// webpieces-disable no-function-outside-class -- executor step helper, like the rest of this executor file\nfunction printGraphSummary(graph: EnhancedGraph): void {\n const levels = new Set(Object.values(graph).map((entry: GraphEntry) => entry.level));\n console.log(`\\nš Graph Summary:`);\n console.log(` Projects: ${Object.keys(graph).length}`);\n console.log(` Levels: ${levels.size} (0-${Math.max(...levels)})`);\n}\n\n/**\n * The whole generation pipeline. Split out of runExecutor so that function stays a thin\n * try/catch-and-report shell ā the error reporting is what a caller reads on failure, and it should\n * not be separated from the throw by fifty lines of steps.\n */\n// webpieces-disable no-function-outside-class -- executor step helper, like the rest of this executor file\nasync function generateEverything(workspaceRoot: string, graphPath: string | undefined): Promise<void> {\n // Step 1: Build the full graph from nx, then transitively reduce it to the view\n console.log(\"š Generating dependency graph from nx's project graph...\");\n const reducedGraph = await generateReducedGraph();\n\n // Step 1b: The graph is a BUILD graph ā refuse a cyclic one, naming EVERY cycle. This runs\n // before the sort deliberately: the sort also refuses, but reports one cycle and an\n // undifferentiated list of everything tangled with it, so a repo with several cycles pays one\n // full regeneration per cycle to discover them.\n console.log('š Checking the project graph is acyclic...');\n const cycles = new ProjectCycleDetector();\n cycles.assertAcyclic(reducedGraph, 'the nx project graph');\n\n // Step 2: Topological sort (to assign levels for visualization)\n console.log('š Computing topological layers...');\n const enhancedGraph = sortGraphTopologically(reducedGraph);\n // ...and assert the stratification it just produced actually holds: every dependency strictly\n // below its dependent. Safe to assert only because the graph was sorted a line ago ā a stale\n // committed file is never checked this way.\n cycles.assertLevelsDescend(reducedGraph, cycles.levelsOf(enhancedGraph), 'the freshly sorted graph');\n\n // Step 3: Enrich with AI metadata (framework, shortDescription, file\n // pointers). This VALIDATES (responsibilities.md required per project)\n // and throws before any write, so a failure never clobbers the file.\n console.log('š·ļø Enriching graph with framework + responsibilities metadata...');\n const projectInfos = await collectProjectInfo();\n enrichGraph(enhancedGraph, projectInfos, workspaceRoot);\n new TagTruthCheck().assertTrue(enhancedGraph, projectInfos, workspaceRoot); // #1064, before any write\n\n // Step 3b: Classify each api-lib edge (implements/uses + rpc/pubsub) by\n // scanning source, so dependencies.json + the viz + the runtime graph all\n // read the same derived truth.\n const scanned = scanApiRelations(workspaceRoot, enhancedGraph, projectInfos);\n const apiContracts = scanned.apiContracts;\n\n // Step 4: Write one contract file per API (architecture/apis/<Api>.json) and delete the files of\n // APIs that no longer exist. dependencies.json only LINKS to them, so an endpoint change rewrites\n // an api file and never the dependency graph. The runtime validator reads these files back.\n const effectiveGraphPath = graphPath ?? DEFAULT_GRAPH_PATH;\n const contractFiles = new ApiContractFiles();\n const written = contractFiles.write(workspaceRoot, effectiveGraphPath, apiContracts);\n console.log(`ā
Wrote ${written.written.length} api contract file(s)`);\n for (const deleted of written.deleted) console.log(`šļø Deleted stale api contract file ${deleted}`);\n\n // Step 4a: Save the graph, INCLUDING the contract-file links and the external-system\n // declarations the runtime derivation reads back ā generate derives from the in-memory graph,\n // validate from the files, so anything not written here would make the two disagree.\n console.log('š¾ Saving graph to architecture/dependencies.json...');\n const contractRefs = contractFiles.refsFor(apiContracts);\n saveGraph(enhancedGraph, workspaceRoot, effectiveGraphPath, contractRefs, scanned.externalSystems);\n console.log('ā
Graph saved successfully');\n\n // Step 4b: Write the committed, clickable HTML view next to the JSON so\n // dependencies.html regenerates in lock-step with dependencies.json.\n const vizPaths = new GraphVisualizer().writeVisualization(enhancedGraph, workspaceRoot);\n console.log(`ā
Wrote ${vizPaths.htmlPath}`);\n\n // Step 5: Generate the runtime microservice graph from the same scan.\n // Projects tagged drawOnGraph:false are threaded through so the runtime\n // graph hides them too (they stay flagged in runtime-dependencies.json).\n generateRuntimeGraph(\n workspaceRoot,\n enhancedGraph,\n hiddenProjectsIn(enhancedGraph),\n apiContracts,\n scanned.externalSystems,\n );\n\n printGraphSummary(enhancedGraph);\n}\n\nexport default async function runExecutor(\n options: GenerateExecutorOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const graphPath = options.graphPath;\n const workspaceRoot = context.root;\n\n console.log('\\nš Architecture Graph Generator\\n');\n\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n await generateEverything(workspaceRoot, graphPath);\n return { success: true };\n } catch (err: unknown) {\n const error = toError(err);\n // A RuleFailError carries its cures as Option[]; `Error.message` is only the aiMessage, so\n // printing that alone silently drops them. renderRuleFailForHuman is the ONE renderer that\n // numbers them, and this catch is the top-level handler for the nx target.\n const rendered = error instanceof RuleFailError ? renderRuleFailForHuman(error) : error.message;\n console.error('ā Graph generation failed:', rendered);\n if (error instanceof MetadataValidationError) {\n const mdPath = writeTemplate(workspaceRoot, 'webpieces.responsibilities.md');\n console.error('');\n console.error('ā ļø *** Refer to ' + mdPath + ' for how to author responsibilities.md files *** ā ļø');\n }\n return { success: false };\n }\n}\n"]}
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
* }
|
|
18
18
|
* }
|
|
19
19
|
*
|
|
20
|
-
* where the manifest declares `"kind": "components"` and names the library's entry files.
|
|
20
|
+
* where the manifest declares `"kind": "components"` and names the library's entry files. Only a
|
|
21
|
+
* `role:api-lib` project may carry the tag (#1064, D5) ā it is refused here and in validate-nx-wiring. The
|
|
21
22
|
* `^openapi-components-generate` edge orders a chain of DTO libraries; a contract library's
|
|
22
23
|
* `openapi-generate` carries the same edge. validate-nx-wiring enforces both (ComponentsWiring).
|
|
23
24
|
*
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
* }
|
|
19
19
|
* }
|
|
20
20
|
*
|
|
21
|
-
* where the manifest declares `"kind": "components"` and names the library's entry files.
|
|
21
|
+
* where the manifest declares `"kind": "components"` and names the library's entry files. Only a
|
|
22
|
+
* `role:api-lib` project may carry the tag (#1064, D5) ā it is refused here and in validate-nx-wiring. The
|
|
22
23
|
* `^openapi-components-generate` edge orders a chain of DTO libraries; a contract library's
|
|
23
24
|
* `openapi-generate` carries the same edge. validate-nx-wiring enforces both (ComponentsWiring).
|
|
24
25
|
*
|
|
@@ -32,7 +33,9 @@ const core_util_1 = require("@webpieces/core-util");
|
|
|
32
33
|
const generator_package_1 = require("../../lib/api-docs/generator-package");
|
|
33
34
|
const executor_1 = require("../openapi-generate/executor");
|
|
34
35
|
/** `openapi-components-generate`: a DTO library's `components.openapi.json`. */
|
|
35
|
-
exports.COMPONENTS_DOCUMENT = new executor_1.GenerateSpec(core_util_1.GeneratedApiDocsLayout.COMPONENTS_TARGET, generator_package_1.OPENAPI_COMPONENTS_GENERATOR
|
|
36
|
+
exports.COMPONENTS_DOCUMENT = new executor_1.GenerateSpec(core_util_1.GeneratedApiDocsLayout.COMPONENTS_TARGET, generator_package_1.OPENAPI_COMPONENTS_GENERATOR,
|
|
37
|
+
// #1064 (D5): only a role:api-lib publishes the schemas contract documents $ref.
|
|
38
|
+
'api-lib');
|
|
36
39
|
// webpieces-disable no-function-outside-class -- nx executor module: nx resolves a default-export function here
|
|
37
40
|
async function runExecutor(options, context) {
|
|
38
41
|
return executor_1.GenerateExecutorMain.run(exports.COMPONENTS_DOCUMENT, options, context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/executors/openapi-components-generate/executor.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/executors/openapi-components-generate/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;;AAqBH,8BAKC;AAvBD,oDAA8D;AAE9D,4EAAoF;AACpF,2DAIsC;AAEtC,gFAAgF;AACnE,QAAA,mBAAmB,GAAG,IAAI,uBAAY,CAC/C,kCAAsB,CAAC,iBAAiB,EACxC,gDAA4B;AAC5B,iFAAiF;AACjF,SAAS,CACZ,CAAC;AAEF,gHAAgH;AACjG,KAAK,UAAU,WAAW,CACrC,OAA+B,EAC/B,OAAwB;IAExB,OAAO,+BAAoB,CAAC,GAAG,CAAC,2BAAmB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["/**\n * openapi-components-generate Executor (#1058)\n *\n * Renders a DTO library's components-only OpenAPI document, `components.openapi.json` ā every type\n * the library exports and declares, `info.version` = the package version ā INTO the outputPath of the\n * target it dependsOn (the library's `build`), so it ships inside the library's npm package exactly as\n * a contract library's documents do. Contract documents `$ref` its schemas instead of copying them.\n *\n * Consumers do not declare this executor. The nx-webpieces-rules plugin INFERS the target on a project\n * tagged `generate:openapi-components`; project.json states only the consumer's values:\n *\n * \"tags\": [\"generate:openapi-components\"],\n * \"targets\": {\n * \"openapi-components-generate\": {\n * \"dependsOn\": [\"build\", \"^openapi-components-generate\"],\n * \"options\": { \"manifest\": \"<project>/openapi.manifest.json\", \"format\": \"json\" }\n * }\n * }\n *\n * where the manifest declares `\"kind\": \"components\"` and names the library's entry files. Only a\n * `role:api-lib` project may carry the tag (#1064, D5) ā it is refused here and in validate-nx-wiring. The\n * `^openapi-components-generate` edge orders a chain of DTO libraries; a contract library's\n * `openapi-generate` carries the same edge. validate-nx-wiring enforces both (ComponentsWiring).\n *\n * It is the openapi-generate executor body with its own target name and generator minimum: `wp-openapi`\n * reads the manifest's `kind` and decides what to render.\n */\n\nimport type { ExecutorContext } from '@nx/devkit';\nimport { GeneratedApiDocsLayout } from '@webpieces/core-util';\nimport { ExecutorResult } from '../../executor-result';\nimport { OPENAPI_COMPONENTS_GENERATOR } from '../../lib/api-docs/generator-package';\nimport {\n GenerateExecutorMain,\n GenerateSpec,\n OpenApiGenerateOptions,\n} from '../openapi-generate/executor';\n\n/** `openapi-components-generate`: a DTO library's `components.openapi.json`. */\nexport const COMPONENTS_DOCUMENT = new GenerateSpec(\n GeneratedApiDocsLayout.COMPONENTS_TARGET,\n OPENAPI_COMPONENTS_GENERATOR,\n // #1064 (D5): only a role:api-lib publishes the schemas contract documents $ref.\n 'api-lib',\n);\n\n// webpieces-disable no-function-outside-class -- nx executor module: nx resolves a default-export function here\nexport default async function runExecutor(\n options: OpenApiGenerateOptions,\n context: ExecutorContext,\n): Promise<ExecutorResult> {\n return GenerateExecutorMain.run(COMPONENTS_DOCUMENT, options, context);\n}\n"]}
|
|
@@ -53,7 +53,19 @@ export interface OpenApiGenerateOptions {
|
|
|
53
53
|
export declare class GenerateSpec {
|
|
54
54
|
readonly targetName: string;
|
|
55
55
|
readonly generator: GeneratorPackage;
|
|
56
|
-
|
|
56
|
+
/**
|
|
57
|
+
* The `role:` tag the project must carry, or null when any role may run it. A components
|
|
58
|
+
* document is published only by a `role:api-lib` (#1064, D5): tagging a general library so its
|
|
59
|
+
* types can be `$ref`ed is not a way to put them on the wire.
|
|
60
|
+
*/
|
|
61
|
+
readonly requiredRole: string | null;
|
|
62
|
+
constructor(targetName: string, generator: GeneratorPackage,
|
|
63
|
+
/**
|
|
64
|
+
* The `role:` tag the project must carry, or null when any role may run it. A components
|
|
65
|
+
* document is published only by a `role:api-lib` (#1064, D5): tagging a general library so its
|
|
66
|
+
* types can be `$ref`ed is not a way to put them on the wire.
|
|
67
|
+
*/
|
|
68
|
+
requiredRole: string | null);
|
|
57
69
|
}
|
|
58
70
|
/** `openapi-generate`: a contract library's documents and MCP tool catalogs. */
|
|
59
71
|
export declare const CONTRACT_DOCUMENTS: GenerateSpec;
|
|
@@ -69,6 +81,8 @@ export declare class OpenApiGenerate {
|
|
|
69
81
|
spec: GenerateSpec, resolver?: ConsumerBinResolver, runner?: GeneratorRunner, scratch?: RepoScratchDirs);
|
|
70
82
|
/** @returns the files written, absolute. Throws RuleFailError on every refusal. */
|
|
71
83
|
run(options: OpenApiGenerateOptions, context: ExecutorContext): string[];
|
|
84
|
+
/** Refuses to run for a project that does not carry the spec's required role. */
|
|
85
|
+
private assertRole;
|
|
72
86
|
}
|
|
73
87
|
/** The single top-level handler both generating executors report through. */
|
|
74
88
|
export declare class GenerateExecutorMain {
|
|
@@ -56,14 +56,22 @@ const toError_1 = require("../../toError");
|
|
|
56
56
|
class GenerateSpec {
|
|
57
57
|
targetName;
|
|
58
58
|
generator;
|
|
59
|
-
|
|
59
|
+
requiredRole;
|
|
60
|
+
constructor(targetName, generator,
|
|
61
|
+
/**
|
|
62
|
+
* The `role:` tag the project must carry, or null when any role may run it. A components
|
|
63
|
+
* document is published only by a `role:api-lib` (#1064, D5): tagging a general library so its
|
|
64
|
+
* types can be `$ref`ed is not a way to put them on the wire.
|
|
65
|
+
*/
|
|
66
|
+
requiredRole) {
|
|
60
67
|
this.targetName = targetName;
|
|
61
68
|
this.generator = generator;
|
|
69
|
+
this.requiredRole = requiredRole;
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
exports.GenerateSpec = GenerateSpec;
|
|
65
73
|
/** `openapi-generate`: a contract library's documents and MCP tool catalogs. */
|
|
66
|
-
exports.CONTRACT_DOCUMENTS = new GenerateSpec(core_util_1.GeneratedApiDocsLayout.OPENAPI_TARGET, generator_package_1.OPENAPI_GENERATOR);
|
|
74
|
+
exports.CONTRACT_DOCUMENTS = new GenerateSpec(core_util_1.GeneratedApiDocsLayout.OPENAPI_TARGET, generator_package_1.OPENAPI_GENERATOR, null);
|
|
67
75
|
/** Everything except the process-facing reporting, so the suite drives it exactly as nx does. */
|
|
68
76
|
class OpenApiGenerate {
|
|
69
77
|
spec;
|
|
@@ -82,6 +90,7 @@ class OpenApiGenerate {
|
|
|
82
90
|
run(options, context) {
|
|
83
91
|
const ruleName = this.spec.targetName;
|
|
84
92
|
const target = generator_target_1.GeneratorTarget.of(ruleName, context);
|
|
93
|
+
this.assertRole(context);
|
|
85
94
|
const outDir = target.documentsDir(ruleName);
|
|
86
95
|
const manifest = target.requiredOption(options.manifest, 'manifest');
|
|
87
96
|
const format = target.requiredOption(options.format, 'format');
|
|
@@ -105,6 +114,25 @@ class OpenApiGenerate {
|
|
|
105
114
|
fs.rmSync(staging, { recursive: true, force: true });
|
|
106
115
|
}
|
|
107
116
|
}
|
|
117
|
+
/** Refuses to run for a project that does not carry the spec's required role. */
|
|
118
|
+
assertRole(context) {
|
|
119
|
+
const required = this.spec.requiredRole;
|
|
120
|
+
if (required === null)
|
|
121
|
+
return;
|
|
122
|
+
const projectName = context.projectName ?? '';
|
|
123
|
+
const tags = context.projectsConfigurations?.projects[projectName]?.tags ?? [];
|
|
124
|
+
if (tags.includes(`role:${required}`))
|
|
125
|
+
return;
|
|
126
|
+
const carried = tags.filter((tag) => tag.startsWith('role:')).join(', ') || 'no role tag';
|
|
127
|
+
throw new rules_config_1.RuleFailError(this.spec.targetName, `${projectName} runs ${this.spec.targetName} but carries ${carried} ā a components document is ` +
|
|
128
|
+
`published only by a role:${required} project. Tagging a general library is not a way to put ` +
|
|
129
|
+
'its types on the wire: every type a contract reaches is declared in an api library.', undefined, undefined, [
|
|
130
|
+
new rules_config_1.Option(`Move the wire types into a role:${required} DTO library and tag THAT one ` +
|
|
131
|
+
'"generate:openapi-components"; drop the tag from this project.', true),
|
|
132
|
+
new rules_config_1.Option(`If this project holds only contracts and wire types, retag it role:${required} ` +
|
|
133
|
+
'(validate-api-lib-tag checks that it does).'),
|
|
134
|
+
]);
|
|
135
|
+
}
|
|
108
136
|
}
|
|
109
137
|
exports.OpenApiGenerate = OpenApiGenerate;
|
|
110
138
|
/** The single top-level handler both generating executors report through. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/executors/openapi-generate/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;;;AAoGH,8BAKC;;AAtGD,oDAA8D;AAC9D,0DAAiG;AACjG,+CAAyB;AACzB,mDAA6B;AAC7B,2DAAuD;AACvD,oFAAmG;AACnG,4EAA2F;AAC3F,0EAAsE;AACtE,0EAAoF;AACpF,2CAAwC;AASxC;;;;;;;GAOG;AACH,MAAa,YAAY;IAER;IACA;IAFb,YACa,UAAkB,EAClB,SAA2B;QAD3B,eAAU,GAAV,UAAU,CAAQ;QAClB,cAAS,GAAT,SAAS,CAAkB;IACrC,CAAC;CACP;AALD,oCAKC;AAED,gFAAgF;AACnE,QAAA,kBAAkB,GAAG,IAAI,YAAY,CAAC,kCAAsB,CAAC,cAAc,EAAE,qCAAiB,CAAC,CAAC;AAE7G,iGAAiG;AACjG,MAAa,eAAe;IAGH;IACA;IACA;IACA;IALrB;IACI,mFAAmF;IAClE,IAAkB,EAClB,WAAgC,IAAI,2CAAmB,EAAE,EACzD,SAA0B,IAAI,kCAAe,EAAE,EAC/C,UAA2B,IAAI,8BAAe,EAAE;QAHhD,SAAI,GAAJ,IAAI,CAAc;QAClB,aAAQ,GAAR,QAAQ,CAAiD;QACzD,WAAM,GAA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,EAAE,CAAC,CAAC;YACzH,OAAO,IAAI,gCAAc,CAAC,KAAK,CAAC,CAAC;QACrC,CAAC;IACL,CAAC;CACJ;AAdD,oDAcC;AAED,gHAAgH;AACjG,KAAK,UAAU,WAAW,CACrC,OAA+B,EAC/B,OAAwB;IAExB,OAAO,oBAAoB,CAAC,GAAG,CAAC,0BAAkB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["/**\n * openapi-generate Executor\n *\n * Renders a project's contracts to OpenAPI, plus ONE MCP tool catalog per contract\n * (`mcp-<ContractClass>-tools.json`), INTO the outputPath of the target it dependsOn ā the api\n * library's `build` (its @nx/js:tsc step) ā so the documents are packed and published inside the api library's npm\n * package: a consumer installs the library and has the contract. They are build output, never\n * committed.\n *\n * Consumers do not declare this executor. The nx-webpieces-rules plugin INFERS the target on a project\n * tagged `generate:openapi` (executor, cache, inputs, outputs); project.json states only what is the\n * consumer's to decide, under the same target name:\n *\n * \"tags\": [\"generate:openapi\"],\n * \"targets\": {\n * \"build\": { \"executor\": \"@nx/js:tsc\", \"outputs\": [\"{options.outputPath}\"],\n * \"options\": { \"outputPath\": \"dist/<project>\", ... } },\n * \"openapi-generate\": {\n * \"dependsOn\": [\"build\"],\n * \"options\": { \"manifest\": \"<project>/openapi.manifest.json\", \"format\": \"both\" }\n * }\n * }\n *\n * and dependents pull it in through nx.json: `\"^openapi-generate\"` in every targetDefaults entry\n * governing a `build` or `test` (#1023 ā see GenerateWiring).\n *\n * The output directory is the outputPath of the ONE target `dependsOn` names (GeneratedApiDocsLayout\n * in @webpieces/core-util ā the same lookup the MCP server reads with), never a hardcoded target name\n * and never an assumed dist/. `outputs` are CHECKED against what a run wrote ā see GeneratorTarget. The\n * generator itself is the CONSUMER's `@webpieces/openapi-generator`, resolved from its node_modules and\n * version-checked; this plugin bundles no copy of it (see ConsumerBinResolver).\n */\n\nimport type { ExecutorContext } from '@nx/devkit';\nimport { GeneratedApiDocsLayout } from '@webpieces/core-util';\nimport { RepoScratchDirs, RuleFailError, renderRuleFailForHuman } from '@webpieces/rules-config';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { ExecutorResult } from '../../executor-result';\nimport { ConsumerBinRequest, ConsumerBinResolver } from '../../lib/api-docs/consumer-bin-resolver';\nimport { GeneratorPackage, OPENAPI_GENERATOR } from '../../lib/api-docs/generator-package';\nimport { GeneratorRunner } from '../../lib/api-docs/generator-runner';\nimport { GeneratorTarget, StagedOutput } from '../../lib/api-docs/generator-target';\nimport { toError } from '../../toError';\n\nexport interface OpenApiGenerateOptions {\n /** Workspace-relative path to the project's `openapi.manifest.json`. Required; no default. */\n manifest?: string;\n /** `json`, `yaml` or `both`. Required; no default ā it decides what the package ships. */\n format?: string;\n}\n\n/**\n * WHICH generating target an {@link OpenApiGenerate} runs as: the target name (what its refusals are\n * reported under, and whose dependsOn names the output directory) and the oldest generator release\n * carrying what that target needs. Data-only.\n *\n * `wp-openapi` decides what to render from the manifest's own `kind`, so the contract documents and a\n * DTO library's components document (#1058) are one executor body with two of these.\n */\nexport class GenerateSpec {\n constructor(\n readonly targetName: string,\n readonly generator: GeneratorPackage,\n ) {}\n}\n\n/** `openapi-generate`: a contract library's documents and MCP tool catalogs. */\nexport const CONTRACT_DOCUMENTS = new GenerateSpec(GeneratedApiDocsLayout.OPENAPI_TARGET, OPENAPI_GENERATOR);\n\n/** Everything except the process-facing reporting, so the suite drives it exactly as nx does. */\nexport class OpenApiGenerate {\n constructor(\n /** Which generating target this run is ā stated by every caller, never implied. */\n private readonly spec: GenerateSpec,\n private readonly resolver: ConsumerBinResolver = new ConsumerBinResolver(),\n private readonly runner: GeneratorRunner = new GeneratorRunner(),\n private readonly scratch: RepoScratchDirs = new RepoScratchDirs(),\n ) {}\n\n /** @returns the files written, absolute. Throws RuleFailError on every refusal. */\n run(options: OpenApiGenerateOptions, context: ExecutorContext): string[] {\n const ruleName = this.spec.targetName;\n const target = GeneratorTarget.of(ruleName, context);\n const outDir = target.documentsDir(ruleName);\n const manifest = target.requiredOption(options.manifest, 'manifest');\n const format = target.requiredOption(options.format, 'format');\n const bin = this.resolver.resolve(new ConsumerBinRequest(\n ruleName, this.spec.generator, [path.join(context.root, target.projectRoot), context.root]));\n\n const staging = this.scratch.make(context.root, 'wp-openapi-generate-');\n // webpieces-disable no-unmanaged-exceptions -- try/FINALLY only, nothing is caught: the staging\n // directory is removed however this ends, and every throw still reaches runExecutor below\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const run = this.runner.run(bin, [\n '--manifest', path.resolve(context.root, manifest), '--out', staging, '--format', format,\n ], context.root);\n if (!run.ok) {\n throw new RuleFailError(\n ruleName,\n `${bin.packageName} ${bin.version} refused ${manifest}:\\n${run.output}`,\n );\n }\n const written = new StagedOutput().publish(staging, outDir);\n target.assertOutputsCover(written);\n return written;\n } finally {\n fs.rmSync(staging, { recursive: true, force: true });\n }\n }\n}\n\n/** The single top-level handler both generating executors report through. */\nexport class GenerateExecutorMain {\n // webpieces-disable no-function-outside-class -- static entry point of this class\n static async run(spec: GenerateSpec, options: OpenApiGenerateOptions, context: ExecutorContext): Promise<ExecutorResult> {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- this IS the executor's single top-level handler\n try {\n const written = new OpenApiGenerate(spec).run(options, context);\n for (const file of written) console.log(`wrote ${path.relative(context.root, file)}`);\n return new ExecutorResult(true);\n } catch (err: unknown) {\n const error = toError(err);\n console.error(`ā ${spec.targetName}: ${error instanceof RuleFailError ? renderRuleFailForHuman(error) : error.message}`);\n return new ExecutorResult(false);\n }\n }\n}\n\n// webpieces-disable no-function-outside-class -- nx executor module: nx resolves a default-export function here\nexport default async function runExecutor(\n options: OpenApiGenerateOptions,\n context: ExecutorContext,\n): Promise<ExecutorResult> {\n return GenerateExecutorMain.run(CONTRACT_DOCUMENTS, options, context);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/execut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EAAE,OAA+B,EAAE,OAAwB;QAC1F,iHAAiH;QACjH,IAAI,CAAC;YACD,MAAM,OAAO,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAChE,KAAK,MAAM,IAAI,IAAI,OAAO;gBAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;YACtF,OAAO,IAAI,gCAAc,CAAC,IAAI,CAAC,CAAC;QACpC,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,iBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,UAAU,KAAK,KAAK,YAAY,4BAAa,CAAC,CAAC,CAAC,IAAA,qCAAsB,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YACzH,OAAO,IAAI,gCAAc,CAAC,KAAK,CAAC,CAAC;QACrC,CAAC;IACL,CAAC;CACJ;AAdD,oDAcC;AAED,gHAAgH;AACjG,KAAK,UAAU,WAAW,CACrC,OAA+B,EAC/B,OAAwB;IAExB,OAAO,oBAAoB,CAAC,GAAG,CAAC,0BAAkB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["/**\n * openapi-generate Executor\n *\n * Renders a project's contracts to OpenAPI, plus ONE MCP tool catalog per contract\n * (`mcp-<ContractClass>-tools.json`), INTO the outputPath of the target it dependsOn ā the api\n * library's `build` (its @nx/js:tsc step) ā so the documents are packed and published inside the api library's npm\n * package: a consumer installs the library and has the contract. They are build output, never\n * committed.\n *\n * Consumers do not declare this executor. The nx-webpieces-rules plugin INFERS the target on a project\n * tagged `generate:openapi` (executor, cache, inputs, outputs); project.json states only what is the\n * consumer's to decide, under the same target name:\n *\n * \"tags\": [\"generate:openapi\"],\n * \"targets\": {\n * \"build\": { \"executor\": \"@nx/js:tsc\", \"outputs\": [\"{options.outputPath}\"],\n * \"options\": { \"outputPath\": \"dist/<project>\", ... } },\n * \"openapi-generate\": {\n * \"dependsOn\": [\"build\"],\n * \"options\": { \"manifest\": \"<project>/openapi.manifest.json\", \"format\": \"both\" }\n * }\n * }\n *\n * and dependents pull it in through nx.json: `\"^openapi-generate\"` in every targetDefaults entry\n * governing a `build` or `test` (#1023 ā see GenerateWiring).\n *\n * The output directory is the outputPath of the ONE target `dependsOn` names (GeneratedApiDocsLayout\n * in @webpieces/core-util ā the same lookup the MCP server reads with), never a hardcoded target name\n * and never an assumed dist/. `outputs` are CHECKED against what a run wrote ā see GeneratorTarget. The\n * generator itself is the CONSUMER's `@webpieces/openapi-generator`, resolved from its node_modules and\n * version-checked; this plugin bundles no copy of it (see ConsumerBinResolver).\n */\n\nimport type { ExecutorContext } from '@nx/devkit';\nimport { GeneratedApiDocsLayout } from '@webpieces/core-util';\nimport { Option, RepoScratchDirs, RuleFailError, renderRuleFailForHuman } from '@webpieces/rules-config';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { ExecutorResult } from '../../executor-result';\nimport { ConsumerBinRequest, ConsumerBinResolver } from '../../lib/api-docs/consumer-bin-resolver';\nimport { GeneratorPackage, OPENAPI_GENERATOR } from '../../lib/api-docs/generator-package';\nimport { GeneratorRunner } from '../../lib/api-docs/generator-runner';\nimport { GeneratorTarget, StagedOutput } from '../../lib/api-docs/generator-target';\nimport { toError } from '../../toError';\n\nexport interface OpenApiGenerateOptions {\n /** Workspace-relative path to the project's `openapi.manifest.json`. Required; no default. */\n manifest?: string;\n /** `json`, `yaml` or `both`. Required; no default ā it decides what the package ships. */\n format?: string;\n}\n\n/**\n * WHICH generating target an {@link OpenApiGenerate} runs as: the target name (what its refusals are\n * reported under, and whose dependsOn names the output directory) and the oldest generator release\n * carrying what that target needs. Data-only.\n *\n * `wp-openapi` decides what to render from the manifest's own `kind`, so the contract documents and a\n * DTO library's components document (#1058) are one executor body with two of these.\n */\nexport class GenerateSpec {\n constructor(\n readonly targetName: string,\n readonly generator: GeneratorPackage,\n /**\n * The `role:` tag the project must carry, or null when any role may run it. A components\n * document is published only by a `role:api-lib` (#1064, D5): tagging a general library so its\n * types can be `$ref`ed is not a way to put them on the wire.\n */\n readonly requiredRole: string | null,\n ) {}\n}\n\n/** `openapi-generate`: a contract library's documents and MCP tool catalogs. */\nexport const CONTRACT_DOCUMENTS = new GenerateSpec(GeneratedApiDocsLayout.OPENAPI_TARGET, OPENAPI_GENERATOR, null);\n\n/** Everything except the process-facing reporting, so the suite drives it exactly as nx does. */\nexport class OpenApiGenerate {\n constructor(\n /** Which generating target this run is ā stated by every caller, never implied. */\n private readonly spec: GenerateSpec,\n private readonly resolver: ConsumerBinResolver = new ConsumerBinResolver(),\n private readonly runner: GeneratorRunner = new GeneratorRunner(),\n private readonly scratch: RepoScratchDirs = new RepoScratchDirs(),\n ) {}\n\n /** @returns the files written, absolute. Throws RuleFailError on every refusal. */\n run(options: OpenApiGenerateOptions, context: ExecutorContext): string[] {\n const ruleName = this.spec.targetName;\n const target = GeneratorTarget.of(ruleName, context);\n this.assertRole(context);\n const outDir = target.documentsDir(ruleName);\n const manifest = target.requiredOption(options.manifest, 'manifest');\n const format = target.requiredOption(options.format, 'format');\n const bin = this.resolver.resolve(new ConsumerBinRequest(\n ruleName, this.spec.generator, [path.join(context.root, target.projectRoot), context.root]));\n\n const staging = this.scratch.make(context.root, 'wp-openapi-generate-');\n // webpieces-disable no-unmanaged-exceptions -- try/FINALLY only, nothing is caught: the staging\n // directory is removed however this ends, and every throw still reaches runExecutor below\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const run = this.runner.run(bin, [\n '--manifest', path.resolve(context.root, manifest), '--out', staging, '--format', format,\n ], context.root);\n if (!run.ok) {\n throw new RuleFailError(\n ruleName,\n `${bin.packageName} ${bin.version} refused ${manifest}:\\n${run.output}`,\n );\n }\n const written = new StagedOutput().publish(staging, outDir);\n target.assertOutputsCover(written);\n return written;\n } finally {\n fs.rmSync(staging, { recursive: true, force: true });\n }\n }\n\n /** Refuses to run for a project that does not carry the spec's required role. */\n private assertRole(context: ExecutorContext): void {\n const required = this.spec.requiredRole;\n if (required === null) return;\n const projectName = context.projectName ?? '';\n const tags = context.projectsConfigurations?.projects[projectName]?.tags ?? [];\n if (tags.includes(`role:${required}`)) return;\n const carried = tags.filter((tag: string) => tag.startsWith('role:')).join(', ') || 'no role tag';\n throw new RuleFailError(\n this.spec.targetName,\n `${projectName} runs ${this.spec.targetName} but carries ${carried} ā a components document is ` +\n `published only by a role:${required} project. Tagging a general library is not a way to put ` +\n 'its types on the wire: every type a contract reaches is declared in an api library.',\n undefined,\n undefined,\n [\n new Option(\n `Move the wire types into a role:${required} DTO library and tag THAT one ` +\n '\"generate:openapi-components\"; drop the tag from this project.',\n true,\n ),\n new Option(\n `If this project holds only contracts and wire types, retag it role:${required} ` +\n '(validate-api-lib-tag checks that it does).',\n ),\n ],\n );\n }\n}\n\n/** The single top-level handler both generating executors report through. */\nexport class GenerateExecutorMain {\n // webpieces-disable no-function-outside-class -- static entry point of this class\n static async run(spec: GenerateSpec, options: OpenApiGenerateOptions, context: ExecutorContext): Promise<ExecutorResult> {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- this IS the executor's single top-level handler\n try {\n const written = new OpenApiGenerate(spec).run(options, context);\n for (const file of written) console.log(`wrote ${path.relative(context.root, file)}`);\n return new ExecutorResult(true);\n } catch (err: unknown) {\n const error = toError(err);\n console.error(`ā ${spec.targetName}: ${error instanceof RuleFailError ? renderRuleFailForHuman(error) : error.message}`);\n return new ExecutorResult(false);\n }\n }\n}\n\n// webpieces-disable no-function-outside-class -- nx executor module: nx resolves a default-export function here\nexport default async function runExecutor(\n options: OpenApiGenerateOptions,\n context: ExecutorContext,\n): Promise<ExecutorResult> {\n return GenerateExecutorMain.run(CONTRACT_DOCUMENTS, options, context);\n}\n"]}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Validate API-lib Tag Executor
|
|
3
3
|
*
|
|
4
|
-
* Fails when the
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Fails when the api roles and the code disagree, in either direction: a project
|
|
5
|
+
* tagged role:api-lib that exports neither a contract (@ApiPath/@Rpc/@PubSub,
|
|
6
|
+
* @WpInternal/@WpIpcEndpoint, or an in-process abstract ā¦Api) nor only wire types,
|
|
7
|
+
* a role:api-client that exports no contract, or a project that exports an
|
|
8
|
+
* @ApiPath/@Rpc/@PubSub abstract class but carries neither api role (#1064, D3).
|
|
7
9
|
*
|
|
8
10
|
* Usage:
|
|
9
11
|
* nx run architecture:validate-api-lib-tag
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Validate API-lib Tag Executor
|
|
4
4
|
*
|
|
5
|
-
* Fails when the
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Fails when the api roles and the code disagree, in either direction: a project
|
|
6
|
+
* tagged role:api-lib that exports neither a contract (@ApiPath/@Rpc/@PubSub,
|
|
7
|
+
* @WpInternal/@WpIpcEndpoint, or an in-process abstract ā¦Api) nor only wire types,
|
|
8
|
+
* a role:api-client that exports no contract, or a project that exports an
|
|
9
|
+
* @ApiPath/@Rpc/@PubSub abstract class but carries neither api role (#1064, D3).
|
|
8
10
|
*
|
|
9
11
|
* Usage:
|
|
10
12
|
* nx run architecture:validate-api-lib-tag
|
|
@@ -23,9 +25,9 @@ async function runExecutor(_options, context) {
|
|
|
23
25
|
try {
|
|
24
26
|
const projectInfos = await (0, graph_metadata_1.collectProjectInfo)();
|
|
25
27
|
const scan = new api_scanner_1.ApiUsageScanner(workspaceRoot, projectInfos).scan();
|
|
26
|
-
const violations = (0, api_lib_tag_validator_1.findApiLibTagViolations)(projectInfos, scan);
|
|
28
|
+
const violations = (0, api_lib_tag_validator_1.findApiLibTagViolations)(projectInfos, scan, workspaceRoot);
|
|
27
29
|
if (violations.length === 0) {
|
|
28
|
-
console.log('ā
role:api-lib
|
|
30
|
+
console.log('ā
role:api-lib / role:api-client match the code (every api library exports a contract or only wire types, and vice-versa).');
|
|
29
31
|
return { success: true };
|
|
30
32
|
}
|
|
31
33
|
console.error(`ā ${violations.length} role:api-lib tag/code mismatch(es):\n`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/executors/validate-api-lib-tag/executor.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/executors/validate-api-lib-tag/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;AAiBH,8BA8BC;AA5CD,6DAA8D;AAC9D,iEAAkE;AAClE,qFAAgH;AAChH,2CAAwC;AAUxC,uHAAuH;AACxG,KAAK,UAAU,WAAW,CACrC,QAAkC,EAClC,OAAwB;IAExB,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAEnC,OAAO,CAAC,GAAG,CAAC,6DAA6D,CAAC,CAAC;IAE3E,8DAA8D;IAC9D,IAAI,CAAC;QACD,MAAM,YAAY,GAAG,MAAM,IAAA,mCAAkB,GAAE,CAAC;QAChD,MAAM,IAAI,GAAG,IAAI,6BAAe,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC,IAAI,EAAE,CAAC;QACrE,MAAM,UAAU,GAAG,IAAA,+CAAuB,EAAC,YAAY,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;QAE9E,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,GAAG,CAAC,4HAA4H,CAAC,CAAC;YAC1I,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;QAED,OAAO,CAAC,KAAK,CAAC,KAAK,UAAU,CAAC,MAAM,wCAAwC,CAAC,CAAC;QAC9E,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACjC,OAAO,CAAC,KAAK,CAAC,IAAA,kDAA0B,EAAC,SAAS,CAAC,CAAC,CAAC;YACrD,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACtB,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,IAAA,iBAAO,EAAC,GAAG,CAAC,CAAC;QAC3B,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QACjE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;AACL,CAAC","sourcesContent":["/**\n * Validate API-lib Tag Executor\n *\n * Fails when the api roles and the code disagree, in either direction: a project\n * tagged role:api-lib that exports neither a contract (@ApiPath/@Rpc/@PubSub,\n * @WpInternal/@WpIpcEndpoint, or an in-process abstract ā¦Api) nor only wire types,\n * a role:api-client that exports no contract, or a project that exports an\n * @ApiPath/@Rpc/@PubSub abstract class but carries neither api role (#1064, D3).\n *\n * Usage:\n * nx run architecture:validate-api-lib-tag\n */\n\nimport type { ExecutorContext } from '@nx/devkit';\nimport { collectProjectInfo } from '../../lib/graph-metadata';\nimport { ApiUsageScanner } from '../../lib/api-usage/api-scanner';\nimport { findApiLibTagViolations, describeApiLibTagViolation } from '../../lib/api-usage/api-lib-tag-validator';\nimport { toError } from '../../toError';\n\nexport interface ValidateApiLibTagOptions {\n // No options needed\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\n// webpieces-disable no-function-outside-class -- nx executor entry point (default export), like every sibling executor\nexport default async function runExecutor(\n _options: ValidateApiLibTagOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const workspaceRoot = context.root;\n\n console.log('\\nš·ļø Validating role:api-lib tag ā API contract exports\\n');\n\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const projectInfos = await collectProjectInfo();\n const scan = new ApiUsageScanner(workspaceRoot, projectInfos).scan();\n const violations = findApiLibTagViolations(projectInfos, scan, workspaceRoot);\n\n if (violations.length === 0) {\n console.log('ā
role:api-lib / role:api-client match the code (every api library exports a contract or only wire types, and vice-versa).');\n return { success: true };\n }\n\n console.error(`ā ${violations.length} role:api-lib tag/code mismatch(es):\\n`);\n for (const violation of violations) {\n console.error(describeApiLibTagViolation(violation));\n console.error('');\n }\n return { success: false };\n } catch (err: unknown) {\n const error = toError(err);\n console.error('ā api-lib tag validation failed:', error.message);\n return { success: false };\n }\n}\n"]}
|
|
@@ -18,6 +18,7 @@ const graph_sorter_1 = require("../../lib/graph-sorter");
|
|
|
18
18
|
const graph_comparator_1 = require("../../lib/graph-comparator");
|
|
19
19
|
const graph_loader_1 = require("../../lib/graph-loader");
|
|
20
20
|
const graph_metadata_1 = require("../../lib/graph-metadata");
|
|
21
|
+
const tag_truth_1 = require("../../lib/tag-truth");
|
|
21
22
|
const api_scanner_1 = require("../../lib/api-usage/api-scanner");
|
|
22
23
|
const external_systems_1 = require("../../lib/api-usage/external-systems");
|
|
23
24
|
const api_contract_files_1 = require("../../lib/api-contract-files");
|
|
@@ -120,6 +121,7 @@ async function buildCurrentGraph(workspaceRoot) {
|
|
|
120
121
|
console.log('š·ļø Enriching graph with framework + responsibilities metadata...');
|
|
121
122
|
const projectInfos = await (0, graph_metadata_1.collectProjectInfo)();
|
|
122
123
|
(0, graph_metadata_1.enrichGraph)(currentGraph, projectInfos, workspaceRoot);
|
|
124
|
+
new tag_truth_1.TagTruthCheck().assertTrue(currentGraph, projectInfos, workspaceRoot);
|
|
123
125
|
console.log('š Scanning source for implements/uses API relations...');
|
|
124
126
|
// The SAME externalApiPaths the generator uses: scanning without them would drop every vendor
|
|
125
127
|
// relation from the regenerated graph and report drift against a perfectly fresh file.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/executors/validate-architecture-unchanged/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAoFH,gDAIC;AAoED,8BAqEC;AA9ND,0DAA+F;AAC/F,+DAAiE;AACjE,yDAAgE;AAChE,iEAA2D;AAC3D,yDAA2E;AAE3E,6DAAoG;AACpG,iEAA+F;AAC/F,2EAA4E;AAE5E,qEAAgE;AAEhE,6DAA6D;AAC7D,mDAA+C;AAE/C,2CAAwC;AAUxC,MAAM,WAAW,GAAG,2BAA2B,CAAC;AAEhD;;;GAGG;AACH,SAAS,wBAAwB,CAAC,aAAqB;IACnD,MAAM,MAAM,GAAG,IAAA,4BAAa,EAAC,aAAa,EAAE,WAAW,CAAC,CAAC;IAEzD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,OAAe,EAAE,aAAqB;IAC1D,MAAM,MAAM,GAAG,wBAAwB,CAAC,aAAa,CAAC,CAAC;IAEvD,OAAO,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;IAC/D,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACvB,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAClB,OAAO,CAAC,KAAK,CAAC,mBAAmB,GAAG,MAAM,GAAG,wCAAwC,CAAC,CAAC;IACvF,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAClB,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACzB,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAC/C,OAAO,CAAC,KAAK,CAAC,oGAAoG,CAAC,CAAC;IACpH,OAAO,CAAC,KAAK,CAAC,wDAAwD,CAAC,CAAC;AAC5E,CAAC;AAED;;;;GAIG;AACH,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cesContent":["/**\n * Validate Architecture Unchanged Executor\n *\n * Validates that the current architecture graph matches the saved blessed graph.\n * This ensures no unapproved architecture changes have been made.\n *\n * Usage:\n * nx run architecture:validate-architecture-unchanged\n */\n\nimport type { ExecutorContext } from '@nx/devkit';\nimport { writeTemplate, RuleFailError, renderRuleFailForHuman } from '@webpieces/rules-config';\nimport { generateReducedGraph } from '../../lib/graph-generator';\nimport { sortGraphTopologically } from '../../lib/graph-sorter';\nimport { compareGraphs } from '../../lib/graph-comparator';\nimport { loadBlessedGraph, graphFileExists } from '../../lib/graph-loader';\nimport type { DependenciesFile } from '../../lib/graph-loader';\nimport { collectProjectInfo, enrichGraph, MetadataValidationError } from '../../lib/graph-metadata';\nimport { scanAndAttachApiRelations, buildApiContracts } from '../../lib/api-usage/api-scanner';\nimport { buildExternalSystems } from '../../lib/api-usage/external-systems';\nimport type { ExternalSystemDecls } from '../../lib/api-usage/api-relations';\nimport { ApiContractFiles } from '../../lib/api-contract-files';\nimport type { ApiContractFileRefs } from '../../lib/api-contract-files';\nimport { loadRuntimeConfig } from '../../lib/runtime-config';\nimport { RuleGate } from '../../lib/rule-gate';\nimport type { EnhancedGraph } from '../../lib/graph-sorter';\nimport { toError } from '../../toError';\n\nexport interface ValidateArchitectureUnchangedOptions {\n graphPath?: string;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\nconst TMP_MD_FILE = 'webpieces.dependencies.md';\n\n/**\n * Write the instructions documentation to .webpieces/instruct-ai/.\n * Sourced from @webpieces/rules-config.\n */\nfunction writeTmpInstructionsFile(workspaceRoot: string): string {\n const mdPath = writeTemplate(workspaceRoot, TMP_MD_FILE);\n\n return mdPath;\n}\n\n/**\n * Report a current-vs-saved graph mismatch and write the AI instructions file.\n */\nfunction reportMismatch(summary: string, workspaceRoot: string): void {\n const mdPath = writeTmpInstructionsFile(workspaceRoot);\n\n console.error('ā Architecture has changed since last update!');\n console.error('\\nDifferences:');\n console.error(summary);\n console.error('');\n console.error('ā ļø *** Refer to ' + mdPath + ' for instructions on how to fix *** ā ļø');\n console.error('');\n console.error('To fix:');\n console.error(' 1. Review the changes above');\n console.error(' 2. If intentional, ASK USER to run: nx run architecture:generate since this is a critical change');\n console.error(' 3. Commit the updated architecture/dependencies.json');\n}\n\n/**\n * Which APIs dependencies.json links to a contract file, compared by LINK only ā an added or removed\n * API. The endpoints inside `architecture/apis/<Api>.json` are deliberately NOT compared (#949): an\n * endpoint change must not fail this rule. Null when the links match.\n */\n// webpieces-disable no-function-outside-class -- executor step helper, matches reportMismatch in this file\nfunction describeContractLinkDrift(current: ApiContractFileRefs, saved: ApiContractFileRefs): string | null {\n const names = [...new Set([...Object.keys(current), ...Object.keys(saved)])].sort();\n const changes: string[] = [];\n for (const name of names) {\n const a = current[name];\n const b = saved[name];\n if (a === undefined) changes.push(` - ${name}: linked in dependencies.json but no longer in source`);\n else if (b === undefined) changes.push(` + ${name}: in source but not linked from dependencies.json`);\n else if (a !== b) changes.push(` ~ ${name}: contract file link changed (${b} -> ${a})`);\n }\n if (changes.length === 0) return null;\n return `apiContractFiles drift (${changes.length} api(s)):\\n${changes.join('\\n')}`;\n}\n\n/**\n * Drift in EITHER side table of dependencies.json ā the api contract-file links or the\n * external-system declarations ā or null when both match. The first difference found is reported;\n * fixing it is the same single command either way, so listing both adds noise rather than information.\n */\n// webpieces-disable no-function-outside-class -- executor step helper, matches describeContractLinkDrift above\nexport function describeTableDrift(current: CurrentArchitecture, saved: DependenciesFile): string | null {\n const linkDrift = describeContractLinkDrift(current.apiContractFiles, saved.apiContractFiles);\n if (linkDrift !== null) return linkDrift;\n return describeExternalSystemDrift(current.externalSystems, saved.externalSystems);\n}\n\n/**\n * The same drift report for the declared external systems, or null when they match. Named per\n * system so the message points at the database that changed rather than dumping two JSON blobs.\n */\n// webpieces-disable no-function-outside-class -- executor step helper, matches describeContractLinkDrift above\nfunction describeExternalSystemDrift(current: ExternalSystemDecls, saved: ExternalSystemDecls): string | null {\n const names = [...new Set([...Object.keys(current), ...Object.keys(saved)])].sort();\n const changes: string[] = [];\n for (const name of names) {\n const a = current[name];\n const b = saved[name];\n if (a === undefined) changes.push(` - ${name}: in dependencies.json but no longer declared in source`);\n else if (b === undefined) changes.push(` + ${name}: declared in source but missing from dependencies.json`);\n else if (JSON.stringify(a) !== JSON.stringify(b)) changes.push(` ~ ${name}: kind/label/declarers changed`);\n }\n if (changes.length === 0) return null;\n return `externalSystems drift (${changes.length} system(s)):\\n${changes.join('\\n')}`;\n}\n\n/**\n * Build the current dependency graph exactly as the generator does: reduce the nx\n * graph, sort into levels, enrich with metadata, and attach the derived\n * apiRelations ā so this validator compares like-for-like against the committed file.\n */\n// webpieces-disable no-function-outside-class -- executor step helper, matches reportMismatch/writeTmpInstructionsFile in this file\nasync function buildCurrentGraph(workspaceRoot: string): Promise<CurrentArchitecture> {\n console.log('š Generating current dependency graph...');\n const reducedGraph = await generateReducedGraph();\n console.log('š Computing topological layers...');\n const currentGraph = sortGraphTopologically(reducedGraph);\n console.log('š·ļø Enriching graph with framework + responsibilities metadata...');\n const projectInfos = await collectProjectInfo();\n enrichGraph(currentGraph, projectInfos, workspaceRoot);\n console.log('š Scanning source for implements/uses API relations...');\n // The SAME externalApiPaths the generator uses: scanning without them would drop every vendor\n // relation from the regenerated graph and report drift against a perfectly fresh file.\n const externalApiPaths = loadRuntimeConfig(workspaceRoot).externalApiPaths;\n const scan = scanAndAttachApiRelations(workspaceRoot, currentGraph, projectInfos, externalApiPaths);\n return new CurrentArchitecture(\n currentGraph,\n new ApiContractFiles().refsFor(buildApiContracts(scan)),\n buildExternalSystems(scan.apiIndex, projectInfos),\n );\n}\n\n/** The regenerated graph plus the two tables beside it ā everything dependencies.json holds. */\nexport class CurrentArchitecture {\n constructor(\n public readonly graph: EnhancedGraph,\n public readonly apiContractFiles: ApiContractFileRefs,\n public readonly externalSystems: ExternalSystemDecls,\n ) {}\n}\n\n/** The bootstrap path: there is nothing to diff against yet, so say how to create it. */\n// webpieces-disable no-function-outside-class -- executor step helper, matches reportMismatch in this file\nfunction reportMissingGraph(): void {\n console.error('ā No saved graph found at architecture/dependencies.json');\n console.error('');\n console.error('To initialize:');\n console.error(' 1. Run: nx run architecture:generate');\n console.error(' 2. Run: nx run architecture:visualize');\n console.error(' 3. Manually inspect the generated graph to confirm it is the desired architecture');\n console.error(' 4. Commit architecture/dependencies.json');\n}\n\nexport default async function runExecutor(\n options: ValidateArchitectureUnchangedOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const graphPath = options.graphPath;\n const workspaceRoot = context.root;\n\n // Epoch-gateable: this rule diffs against the blessed architecture/dependencies.json, so\n // \"grandfather the current drift until <epoch>\" is meaningful ā hence honorEpoch = true.\n if (new RuleGate().isDisabled(workspaceRoot, 'validate-architecture-unchanged', true)) {\n return { success: true };\n }\n\n console.log('\\nš Validating Architecture Unchanged\\n');\n\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // Check if saved graph exists\n if (!graphFileExists(workspaceRoot, graphPath)) {\n reportMissingGraph();\n return { success: false };\n }\n\n // Steps 1-3: build + enrich + scan the current graph (same pipeline the\n // generator runs, so any drift is caught).\n const currentGraph = await buildCurrentGraph(workspaceRoot);\n\n // Step 4: Load saved graph\n console.log('š Loading saved graph...');\n const savedGraph = loadBlessedGraph(workspaceRoot, graphPath);\n\n if (!savedGraph) {\n console.error('ā Could not load saved graph');\n return { success: false };\n }\n\n // Step 5: Compare graphs\n console.log('š Comparing current graph to saved graph...');\n const comparison = compareGraphs(currentGraph.graph, savedGraph.projects);\n\n if (!comparison.identical) {\n reportMismatch(comparison.summary, workspaceRoot);\n return { success: false };\n }\n\n // Step 6: Compare the two side tables as well: which APIs are linked to a contract file, and\n // the external-system declarations. The endpoints inside architecture/apis/<Api>.json are\n // NOT compared ā an endpoint change must never fail this rule (#949).\n const tableDrift = describeTableDrift(currentGraph, savedGraph);\n if (tableDrift !== null) {\n reportMismatch(tableDrift, workspaceRoot);\n return { success: false };\n }\n\n console.log('ā
Architecture unchanged - current graph matches saved graph');\n return { success: true };\n } catch (err: unknown) {\n const error = toError(err);\n // A RuleFailError (e.g. a dependencies.json still carrying the moved `apiContracts` key)\n // carries its cures in Option[]; render them rather than dropping them with `.message`.\n const rendered = error instanceof RuleFailError ? renderRuleFailForHuman(error) : error.message;\n console.error('ā Architecture validation failed:', rendered);\n if (error instanceof MetadataValidationError) {\n const mdPath = writeTemplate(workspaceRoot, 'webpieces.responsibilities.md');\n console.error('');\n console.error('ā ļø *** Refer to ' + mdPath + ' for how to author responsibilities.md files *** ā ļø');\n }\n return { success: false };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/executors/validate-architecture-unchanged/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAqFH,gDAIC;AAqED,8BAqEC;AAhOD,0DAA+F;AAC/F,+DAAiE;AACjE,yDAAgE;AAChE,iEAA2D;AAC3D,yDAA2E;AAE3E,6DAAoG;AACpG,mDAAoD;AACpD,iEAA+F;AAC/F,2EAA4E;AAE5E,qEAAgE;AAEhE,6DAA6D;AAC7D,mDAA+C;AAE/C,2CAAwC;AAUxC,MAAM,WAAW,GAAG,2BAA2B,CAAC;AAEhD;;;GAGG;AACH,SAAS,wBAAwB,CAAC,aAAqB;IACnD,MAAM,MAAM,GAAG,IAAA,4BAAa,EAAC,aAAa,EAAE,WAAW,CAAC,CAAC;IAEzD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,OAAe,EAAE,aAAqB;IAC1D,MAAM,MAAM,GAAG,wBAAwB,CAAC,aAAa,CAAC,CAAC;IAEvD,OAAO,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;IAC/D,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACvB,OAAO,CAAC,KAAK,CAAC,E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sB,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;QAChG,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,QAAQ,CAAC,CAAC;QAC7D,IAAI,KAAK,YAAY,wCAAuB,EAAE,CAAC;YAC3C,MAAM,MAAM,GAAG,IAAA,4BAAa,EAAC,aAAa,EAAE,+BAA+B,CAAC,CAAC;YAC7E,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAClB,OAAO,CAAC,KAAK,CAAC,mBAAmB,GAAG,MAAM,GAAG,qDAAqD,CAAC,CAAC;QACxG,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;AACL,CAAC","sourcesContent":["/**\n * Validate Architecture Unchanged Executor\n *\n * Validates that the current architecture graph matches the saved blessed graph.\n * This ensures no unapproved architecture changes have been made.\n *\n * Usage:\n * nx run architecture:validate-architecture-unchanged\n */\n\nimport type { ExecutorContext } from '@nx/devkit';\nimport { writeTemplate, RuleFailError, renderRuleFailForHuman } from '@webpieces/rules-config';\nimport { generateReducedGraph } from '../../lib/graph-generator';\nimport { sortGraphTopologically } from '../../lib/graph-sorter';\nimport { compareGraphs } from '../../lib/graph-comparator';\nimport { loadBlessedGraph, graphFileExists } from '../../lib/graph-loader';\nimport type { DependenciesFile } from '../../lib/graph-loader';\nimport { collectProjectInfo, enrichGraph, MetadataValidationError } from '../../lib/graph-metadata';\nimport { TagTruthCheck } from '../../lib/tag-truth';\nimport { scanAndAttachApiRelations, buildApiContracts } from '../../lib/api-usage/api-scanner';\nimport { buildExternalSystems } from '../../lib/api-usage/external-systems';\nimport type { ExternalSystemDecls } from '../../lib/api-usage/api-relations';\nimport { ApiContractFiles } from '../../lib/api-contract-files';\nimport type { ApiContractFileRefs } from '../../lib/api-contract-files';\nimport { loadRuntimeConfig } from '../../lib/runtime-config';\nimport { RuleGate } from '../../lib/rule-gate';\nimport type { EnhancedGraph } from '../../lib/graph-sorter';\nimport { toError } from '../../toError';\n\nexport interface ValidateArchitectureUnchangedOptions {\n graphPath?: string;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\nconst TMP_MD_FILE = 'webpieces.dependencies.md';\n\n/**\n * Write the instructions documentation to .webpieces/instruct-ai/.\n * Sourced from @webpieces/rules-config.\n */\nfunction writeTmpInstructionsFile(workspaceRoot: string): string {\n const mdPath = writeTemplate(workspaceRoot, TMP_MD_FILE);\n\n return mdPath;\n}\n\n/**\n * Report a current-vs-saved graph mismatch and write the AI instructions file.\n */\nfunction reportMismatch(summary: string, workspaceRoot: string): void {\n const mdPath = writeTmpInstructionsFile(workspaceRoot);\n\n console.error('ā Architecture has changed since last update!');\n console.error('\\nDifferences:');\n console.error(summary);\n console.error('');\n console.error('ā ļø *** Refer to ' + mdPath + ' for instructions on how to fix *** ā ļø');\n console.error('');\n console.error('To fix:');\n console.error(' 1. Review the changes above');\n console.error(' 2. If intentional, ASK USER to run: nx run architecture:generate since this is a critical change');\n console.error(' 3. Commit the updated architecture/dependencies.json');\n}\n\n/**\n * Which APIs dependencies.json links to a contract file, compared by LINK only ā an added or removed\n * API. The endpoints inside `architecture/apis/<Api>.json` are deliberately NOT compared (#949): an\n * endpoint change must not fail this rule. Null when the links match.\n */\n// webpieces-disable no-function-outside-class -- executor step helper, matches reportMismatch in this file\nfunction describeContractLinkDrift(current: ApiContractFileRefs, saved: ApiContractFileRefs): string | null {\n const names = [...new Set([...Object.keys(current), ...Object.keys(saved)])].sort();\n const changes: string[] = [];\n for (const name of names) {\n const a = current[name];\n const b = saved[name];\n if (a === undefined) changes.push(` - ${name}: linked in dependencies.json but no longer in source`);\n else if (b === undefined) changes.push(` + ${name}: in source but not linked from dependencies.json`);\n else if (a !== b) changes.push(` ~ ${name}: contract file link changed (${b} -> ${a})`);\n }\n if (changes.length === 0) return null;\n return `apiContractFiles drift (${changes.length} api(s)):\\n${changes.join('\\n')}`;\n}\n\n/**\n * Drift in EITHER side table of dependencies.json ā the api contract-file links or the\n * external-system declarations ā or null when both match. The first difference found is reported;\n * fixing it is the same single command either way, so listing both adds noise rather than information.\n */\n// webpieces-disable no-function-outside-class -- executor step helper, matches describeContractLinkDrift above\nexport function describeTableDrift(current: CurrentArchitecture, saved: DependenciesFile): string | null {\n const linkDrift = describeContractLinkDrift(current.apiContractFiles, saved.apiContractFiles);\n if (linkDrift !== null) return linkDrift;\n return describeExternalSystemDrift(current.externalSystems, saved.externalSystems);\n}\n\n/**\n * The same drift report for the declared external systems, or null when they match. Named per\n * system so the message points at the database that changed rather than dumping two JSON blobs.\n */\n// webpieces-disable no-function-outside-class -- executor step helper, matches describeContractLinkDrift above\nfunction describeExternalSystemDrift(current: ExternalSystemDecls, saved: ExternalSystemDecls): string | null {\n const names = [...new Set([...Object.keys(current), ...Object.keys(saved)])].sort();\n const changes: string[] = [];\n for (const name of names) {\n const a = current[name];\n const b = saved[name];\n if (a === undefined) changes.push(` - ${name}: in dependencies.json but no longer declared in source`);\n else if (b === undefined) changes.push(` + ${name}: declared in source but missing from dependencies.json`);\n else if (JSON.stringify(a) !== JSON.stringify(b)) changes.push(` ~ ${name}: kind/label/declarers changed`);\n }\n if (changes.length === 0) return null;\n return `externalSystems drift (${changes.length} system(s)):\\n${changes.join('\\n')}`;\n}\n\n/**\n * Build the current dependency graph exactly as the generator does: reduce the nx\n * graph, sort into levels, enrich with metadata, and attach the derived\n * apiRelations ā so this validator compares like-for-like against the committed file.\n */\n// webpieces-disable no-function-outside-class -- executor step helper, matches reportMismatch/writeTmpInstructionsFile in this file\nasync function buildCurrentGraph(workspaceRoot: string): Promise<CurrentArchitecture> {\n console.log('š Generating current dependency graph...');\n const reducedGraph = await generateReducedGraph();\n console.log('š Computing topological layers...');\n const currentGraph = sortGraphTopologically(reducedGraph);\n console.log('š·ļø Enriching graph with framework + responsibilities metadata...');\n const projectInfos = await collectProjectInfo();\n enrichGraph(currentGraph, projectInfos, workspaceRoot);\n new TagTruthCheck().assertTrue(currentGraph, projectInfos, workspaceRoot);\n console.log('š Scanning source for implements/uses API relations...');\n // The SAME externalApiPaths the generator uses: scanning without them would drop every vendor\n // relation from the regenerated graph and report drift against a perfectly fresh file.\n const externalApiPaths = loadRuntimeConfig(workspaceRoot).externalApiPaths;\n const scan = scanAndAttachApiRelations(workspaceRoot, currentGraph, projectInfos, externalApiPaths);\n return new CurrentArchitecture(\n currentGraph,\n new ApiContractFiles().refsFor(buildApiContracts(scan)),\n buildExternalSystems(scan.apiIndex, projectInfos),\n );\n}\n\n/** The regenerated graph plus the two tables beside it ā everything dependencies.json holds. */\nexport class CurrentArchitecture {\n constructor(\n public readonly graph: EnhancedGraph,\n public readonly apiContractFiles: ApiContractFileRefs,\n public readonly externalSystems: ExternalSystemDecls,\n ) {}\n}\n\n/** The bootstrap path: there is nothing to diff against yet, so say how to create it. */\n// webpieces-disable no-function-outside-class -- executor step helper, matches reportMismatch in this file\nfunction reportMissingGraph(): void {\n console.error('ā No saved graph found at architecture/dependencies.json');\n console.error('');\n console.error('To initialize:');\n console.error(' 1. Run: nx run architecture:generate');\n console.error(' 2. Run: nx run architecture:visualize');\n console.error(' 3. Manually inspect the generated graph to confirm it is the desired architecture');\n console.error(' 4. Commit architecture/dependencies.json');\n}\n\nexport default async function runExecutor(\n options: ValidateArchitectureUnchangedOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const graphPath = options.graphPath;\n const workspaceRoot = context.root;\n\n // Epoch-gateable: this rule diffs against the blessed architecture/dependencies.json, so\n // \"grandfather the current drift until <epoch>\" is meaningful ā hence honorEpoch = true.\n if (new RuleGate().isDisabled(workspaceRoot, 'validate-architecture-unchanged', true)) {\n return { success: true };\n }\n\n console.log('\\nš Validating Architecture Unchanged\\n');\n\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // Check if saved graph exists\n if (!graphFileExists(workspaceRoot, graphPath)) {\n reportMissingGraph();\n return { success: false };\n }\n\n // Steps 1-3: build + enrich + scan the current graph (same pipeline the\n // generator runs, so any drift is caught).\n const currentGraph = await buildCurrentGraph(workspaceRoot);\n\n // Step 4: Load saved graph\n console.log('š Loading saved graph...');\n const savedGraph = loadBlessedGraph(workspaceRoot, graphPath);\n\n if (!savedGraph) {\n console.error('ā Could not load saved graph');\n return { success: false };\n }\n\n // Step 5: Compare graphs\n console.log('š Comparing current graph to saved graph...');\n const comparison = compareGraphs(currentGraph.graph, savedGraph.projects);\n\n if (!comparison.identical) {\n reportMismatch(comparison.summary, workspaceRoot);\n return { success: false };\n }\n\n // Step 6: Compare the two side tables as well: which APIs are linked to a contract file, and\n // the external-system declarations. The endpoints inside architecture/apis/<Api>.json are\n // NOT compared ā an endpoint change must never fail this rule (#949).\n const tableDrift = describeTableDrift(currentGraph, savedGraph);\n if (tableDrift !== null) {\n reportMismatch(tableDrift, workspaceRoot);\n return { success: false };\n }\n\n console.log('ā
Architecture unchanged - current graph matches saved graph');\n return { success: true };\n } catch (err: unknown) {\n const error = toError(err);\n // A RuleFailError (e.g. a dependencies.json still carrying the moved `apiContracts` key)\n // carries its cures in Option[]; render them rather than dropping them with `.message`.\n const rendered = error instanceof RuleFailError ? renderRuleFailForHuman(error) : error.message;\n console.error('ā Architecture validation failed:', rendered);\n if (error instanceof MetadataValidationError) {\n const mdPath = writeTemplate(workspaceRoot, 'webpieces.responsibilities.md');\n console.error('');\n console.error('ā ļø *** Refer to ' + mdPath + ' for how to author responsibilities.md files *** ā ļø');\n }\n return { success: false };\n }\n}\n"]}
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
* a contract document before the library document it references exists, and the generator's
|
|
13
13
|
* fail-closed refusal ("never generated") fires intermittently, mostly in CI. So it is refused here,
|
|
14
14
|
* on the resolved graph, with the exact `dependsOn` to write.
|
|
15
|
+
*
|
|
16
|
+
* The tag itself is allowed only on a `role:api-lib` project (#1064, D5): a components document puts a
|
|
17
|
+
* library's types on the wire, and every wire type is declared in an api library. Tagging a general
|
|
18
|
+
* library such as `company-core` must not be a way out of moving the type.
|
|
15
19
|
*/
|
|
16
20
|
import type { ProjectConfiguration } from '@nx/devkit';
|
|
17
21
|
import { DeclaredDependsOn, GenerateWiringProblem, ProjectDependency } from './generate-wiring';
|
|
@@ -23,6 +27,8 @@ export declare class ComponentsWiring {
|
|
|
23
27
|
/** The DTO libraries tagged to publish a components document. */
|
|
24
28
|
libraries(): string[];
|
|
25
29
|
problems(): GenerateWiringProblem[];
|
|
30
|
+
/** Only a `role:api-lib` publishes a components document (D5). */
|
|
31
|
+
private roleOf;
|
|
26
32
|
/** `openapi-components-generate` dependsOn exactly the library's own `build`, the tsc target. */
|
|
27
33
|
private shapeOf;
|
|
28
34
|
private missingEdge;
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
* a contract document before the library document it references exists, and the generator's
|
|
14
14
|
* fail-closed refusal ("never generated") fires intermittently, mostly in CI. So it is refused here,
|
|
15
15
|
* on the resolved graph, with the exact `dependsOn` to write.
|
|
16
|
+
*
|
|
17
|
+
* The tag itself is allowed only on a `role:api-lib` project (#1064, D5): a components document puts a
|
|
18
|
+
* library's types on the wire, and every wire type is declared in an api library. Tagging a general
|
|
19
|
+
* library such as `company-core` must not be a way out of moving the type.
|
|
16
20
|
*/
|
|
17
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
22
|
exports.ComponentsWiring = void 0;
|
|
@@ -23,6 +27,7 @@ const generate_wiring_1 = require("./generate-wiring");
|
|
|
23
27
|
const BUILD_TARGET = 'build';
|
|
24
28
|
const COMPONENTS_TARGET = core_util_1.GeneratedApiDocsLayout.COMPONENTS_TARGET;
|
|
25
29
|
const UPSTREAM_COMPONENTS = `^${COMPONENTS_TARGET}`;
|
|
30
|
+
const API_LIB_ROLE_TAG = 'role:api-lib';
|
|
26
31
|
/** The targets that READ upstream components documents, and so must run after them. */
|
|
27
32
|
const READING_TARGETS = [COMPONENTS_TARGET, core_util_1.GeneratedApiDocsLayout.OPENAPI_TARGET];
|
|
28
33
|
class ComponentsWiring {
|
|
@@ -44,7 +49,7 @@ class ComponentsWiring {
|
|
|
44
49
|
const libraries = new Set(this.libraries());
|
|
45
50
|
const problems = [];
|
|
46
51
|
for (const name of this.libraries())
|
|
47
|
-
problems.push(...this.shapeOf(name));
|
|
52
|
+
problems.push(...this.roleOf(name), ...this.shapeOf(name));
|
|
48
53
|
for (const name of Object.keys(this.projects).sort()) {
|
|
49
54
|
const upstream = this.librariesUpstreamOf(name, libraries);
|
|
50
55
|
if (upstream.length === 0)
|
|
@@ -58,6 +63,18 @@ class ComponentsWiring {
|
|
|
58
63
|
}
|
|
59
64
|
return problems;
|
|
60
65
|
}
|
|
66
|
+
/** Only a `role:api-lib` publishes a components document (D5). */
|
|
67
|
+
roleOf(name) {
|
|
68
|
+
const project = this.projects[name];
|
|
69
|
+
const tags = project.tags ?? [];
|
|
70
|
+
if (tags.includes(API_LIB_ROLE_TAG))
|
|
71
|
+
return [];
|
|
72
|
+
const carried = tags.filter((tag) => tag.startsWith('role:')).join(', ') || 'no role tag';
|
|
73
|
+
return [new generate_wiring_1.GenerateWiringProblem(name, `${name} is tagged "${generate_targets_1.GENERATE_OPENAPI_COMPONENTS_TAG}" but carries ${carried} ā only a role:api-lib ` +
|
|
74
|
+
'publishes a components document, because every type a contract reaches is declared in an api library.', `${name}: in ${project.root}/project.json, drop "${generate_targets_1.GENERATE_OPENAPI_COMPONENTS_TAG}" and move the wire ` +
|
|
75
|
+
`types into a role:api-lib DTO library tagged with it ā or, when ${name} holds only contracts and ` +
|
|
76
|
+
'wire types, retag it role:api-lib.')];
|
|
77
|
+
}
|
|
61
78
|
/** `openapi-components-generate` dependsOn exactly the library's own `build`, the tsc target. */
|
|
62
79
|
shapeOf(name) {
|
|
63
80
|
const project = this.projects[name];
|