@webpieces/nx-webpieces-rules 0.4.993 → 0.4.995

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.
@@ -1 +1 @@
1
- {"version":3,"file":"api-contract-errors.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/lib/api-usage/api-contract-errors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AA8BH,sDAcC;AA2ID,gEAgBC;AArMD,mDAQyB;AACzB,uDAAyF;AACzF,mDAMyB;AAEzB;;;;;;;;GAQG;AACH,oGAAoG;AACpG,SAAgB,qBAAqB,CAAC,UAAmC;IACrE,MAAM,KAAK,GAAG;QACV,OAAO,UAAU,CAAC,MAAM,oEAAoE;KAC/F,CAAC;IACF,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,UAAU,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,OAAO,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;QAC3D,KAAK,CAAC,IAAI,CAAC,UAAU,GAAG,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1F,CAAC;IACD,KAAK,CAAC,IAAI,CACN,6FAA6F,EAC7F,8FAA8F,EAC9F,6FAA6F,CAChG,CAAC;IACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC;AAED,wFAAwF;AACxF,8FAA8F;AAC9F,SAAS,gBAAgB,CAAC,OAAe,EAAE,UAAmC;IAC1E,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IAC5C,OAAO,GAAG,OAAO,OAAO,qBAAqB,CAAC,UAAU,CAAC,EAAE,CAAC;AAChE,CAAC;AAED;;;;;;;GAOG;AACH,wFAAwF;AACxF,SAA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KAAK,CACD,GAAG,SAAS,CAAC,MAAM,4EAA4E;YAC3F,SAAS;iBACJ,GAAG,CACA,CAAC,CAAqB,EAAE,EAAE,CACtB,UAAU,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,QAAQ,+CAA+C,CAAC,CAAC,EAAE,EAAE,CAC3F;iBACA,IAAI,CAAC,IAAI,CAAC;YACf,6FAA6F;YAC7F,uFAAuF;YACvF,mFAAmF;YACnF,yGAAyG;YACzG,mGAAmG;YACnG,mCAAmC,CAC1C,CAAC;QAfsB,cAAS,GAAT,SAAS,CAA+B;QAgBhE,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IAC1C,CAAC;CACJ;AAnBD,0DAmBC","sourcesContent":["/**\n * The ways `buildApiContracts` refuses to emit a green, wrong api contract table.\n *\n * They share one rule: an entry that is PRESENT but incomplete is worse than an absent one.\n * Every other entry in the table is complete, so a consumer has no reason to suspect the one that\n * lost a field — it just computes a confidently wrong URL, or draws a service with no queues.\n *\n * Each aggregates EVERY offender into one message rather than throwing on the first: an author who\n * moved a constants module broke five decorators at once and wants all five named in one run.\n *\n * Split out of api-scanner.ts, which owns the scan itself and is at its file-size limit.\n */\n\nimport {\n EmptiedApiContract,\n UndeclaredEndpointOperation,\n UndeclaredExternalCaller,\n UnresolvedApiCall,\n UnresolvedEndpointPath,\n VoidResponseMismatch,\n VoidResponseProblem,\n} from './api-relations';\nimport { RootUnionApiType, RootUnionFindings, ROOT_UNION_RULE } from './root-union-scan';\nimport {\n ApiContractDefect,\n ApiRuleFindings,\n McpExclusion,\n MCP_RULE,\n OPENAPI_RULE,\n} from './api-doc-rules';\n\n/**\n * The endpoints declared PERMANENTLY outside MCP, with their reasons — restated on EVERY run of\n * `api-rules-for-mcp`, green or red (#1014).\n *\n * Not a warning and not a finding. #1014 asked whether adding an `@InvalidEndpointForMcp` should\n * warn, and the answer is that a one-off warning is read by the one person who already knows the\n * decision. A list restated on every run is read by whoever comes next, which is who the reason was\n * written for. Printed by the caller, exactly like `describeUnresolvedApiCalls`.\n */\n// webpieces-disable no-function-outside-class -- pure formatter, mirrors describeUnresolvedApiCalls\nexport function describeMcpExclusions(exclusions: readonly McpExclusion[]): string {\n const lines = [\n `ℹ️ ${exclusions.length} endpoint(s) are PERMANENTLY outside MCP (@InvalidEndpointForMcp):`,\n ];\n for (const one of exclusions) {\n lines.push(` • ${one.api}.${one.method} at ${one.at}`);\n lines.push(` ${one.reason === '' ? '<reason could not be read>' : one.reason}`);\n }\n lines.push(\n ` These are DECLARATIONS, not suppressions: each says the endpoint can never be a tool and`,\n ` why. They are restated every run rather than announced once, so the reasons stay readable`,\n ` by whoever comes next. \\`grep -rn InvalidEndpointForMcp\\` is the same list from a shell.`,\n );\n return lines.join('\\n');\n}\n\n/** The rule's message with its PERMANENT-exclusion list appended, when there is one. */\n// webpieces-disable no-function-outside-class -- pure formatter beside the error that uses it\nfunction appendExclusions(message: string, exclusions: readonly McpExclusion[]): string {\n if (exclusions.length === 0) return message;\n return `${message}\\n\\n${describeMcpExclusions(exclusions)}`;\n}\n\n/**\n * One defect per line, with its cure INDENTED under it rather than collected into a footer.\n *\n * Every other error in this file prints one shared cure because its offenders share one root cause —\n * an unreadable constant, a missing `calledBy`. These two do not: an open enum, an `unknown` value\n * and a `void` RPC are three different edits, and a footer would make the reader work out which of\n * the three applies to which line.\n */\n// webpieces-disable no-function-outside-class -- pure formatter, mirrors rootUnionLines\nfunction apiDefectLines(found: readonly ApiContractDefect[]): string {\n return found\n .map((one: ApiContractDefect) => {\n const exposure = one.isExternal() ? ' [PARTNER-FACING]' : '';\n return (\n ` • ${one.where()}${exposure} — ${one.what}\\n` +\n ` at ${one.at}\\n` +\n ` cure: ${one.cure}`\n );\n })\n .join('\\n');\n}\n\n/** The two halves every api-doc rule prints, so both refusals say the reasonless part identically. */\n// webpieces-disable no-function-outside-class -- pure formatter shared by the two errors below\nfunction apiRuleMessage(\n rule: string,\n headline: string,\n findings: ApiRuleFindings,\n why: string,\n): string {\n const parts: string[] = [];\n if (findings.violations.length > 0) {\n parts.push(\n `${findings.violations.length} ${headline}:\\n` +\n apiDefectLines(findings.violations) +\n `\\n${why}\\n` +\n ` This runs on EVERY @ApiPath contract, with or without @ApiType: @ApiType is a\\n` +\n ` PUBLISHING decision added later, so a shape that is not expressible must fail on the\\n` +\n ` first line rather than on the day somebody annotates it — by which time the type is\\n` +\n ` in partners' generated clients and cannot be changed.\\n` +\n ` Last resort, per site: // webpieces-disable ${rule} -- <reason>`,\n );\n }\n if (findings.reasonlessDisables.length > 0) {\n parts.push(\n `${findings.reasonlessDisables.length} disable(s) of ${rule} give NO reason:\\n` +\n apiDefectLines(findings.reasonlessDisables) +\n `\\n The reason is MANDATORY — a reasonless disable is itself a violation. Write it as\\n` +\n ` // webpieces-disable ${rule} -- <why this contract is published like this>\\n` +\n ` The hatch is per-site and argued on purpose: the next reader needs the argument,\\n` +\n ` not just the suppression.`,\n );\n }\n return parts.join('\\n\\n');\n}\n\n/**\n * `api-rules-for-openapi`: a contract that cannot produce an OpenAPI document.\n *\n * Fatal because the failure it prevents is DOCUMENT-WIDE and arrives late. One field with no shape\n * fails the whole document, so no partner can generate a client for ANY operation of that API — six\n * of 98 endpoints in a measured upstream repo, from exactly two root causes, and five of those six\n * were one field. The author who wrote that field had no way to know, because nothing looked at the\n * contract until somebody added `@ApiType` months later.\n *\n * Its verdict is the GENERATOR'S: the scan drives `ApiDocExtractor` rather than restating what is\n * expressible, so a contract that passes this is one where adding `@ApiType` then generates.\n */\nexport class ApiRulesForOpenApiError extends Error {\n constructor(public readonly findings: ApiRuleFindings) {\n super(\n apiRuleMessage(\n OPENAPI_RULE,\n '@ApiPath contract defect(s) would block the OpenAPI document',\n findings,\n ` An OpenAPI failure is DOCUMENT-WIDE: one field with no shape blocks client generation\\n` +\n ` for every operation of that API, not just the one that declares it.`,\n ),\n );\n this.name = 'ApiRulesForOpenApiError';\n }\n}\n\n/**\n * `api-rules-for-mcp`: a `@WpMcpTool` that could not be served.\n *\n * Every one of these is something `McpToolRegistry` refuses to BOOT on — a tool it cannot find a\n * schema for is a tool whose schema nobody checked — so the choice is only WHERE it is discovered.\n * Here it names the method; at boot it names a process that will not start, in an environment where\n * nobody is editing the contract.\n *\n * Separate from the OpenAPI error because the blast radii are different: this blocks ONE tool, where\n * an OpenAPI defect blocks a whole document. A team publishing a partner API and no tools runs the\n * first rule and not this one, which is only possible if they are two rules.\n */\nexport class ApiRulesForMcpError extends Error {\n constructor(\n public readonly findings: ApiRuleFindings,\n /**\n * The `@InvalidEndpointForMcp` endpoints, appended to the message.\n *\n * A red run is exactly when somebody is looking at this output, so it is also when the\n * PERMANENT exclusions are most worth restating: the next question after \"why is this tool\n * blocked\" is \"which endpoints did we already decide can never be tools, and why\".\n */\n public readonly exclusions: readonly McpExclusion[] = [],\n ) {\n super(\n appendExclusions(\n apiRuleMessage(\n MCP_RULE,\n '@WpMcpTool declaration(s) could not be served as MCP tools',\n findings,\n ` Each of these makes McpToolRegistry REFUSE TO BOOT: a registered tool the build never\\n` +\n ` published is a tool whose schema nobody checked. Caught here, it names the method;\\n` +\n ` caught at boot, it names a process that will not start.`,\n ),\n exclusions,\n ),\n );\n this.name = 'ApiRulesForMcpError';\n }\n}\n\n/**\n * Loud, actionable report for contracts the scan could not map to source. Callers print this\n * instead of emitting a green graph that is quietly missing relations. Not fatal: a contract\n * from a genuinely EXTERNAL (published, non-workspace) api-lib legitimately has no source here.\n */\n// webpieces-disable no-function-outside-class -- pure formatter, mirrors describeUnclassifiedApiDep\nexport function describeUnresolvedApiCalls(calls: UnresolvedApiCall[]): string {\n const lines = [\n `⚠️ ${calls.length} API contract(s) resolved to a declaration file with no matching workspace source.`,\n ` Decorators (@ApiPath) are ERASED in .d.ts output, so these relations are MISSING from the graph:`,\n ];\n for (const call of calls) {\n lines.push(\n ` • ${call.api} at ${call.at} (${call.project}) → resolved to ${call.declaredIn}`,\n );\n }\n lines.push(\n ` If the api-lib IS in this workspace, add a tsconfig.base.json 'paths' entry mapping it to its`,\n ` src/index.ts, or confirm its project root is registered. If it is a published external package,`,\n ` this relation cannot be derived and the graph edge will not appear.`,\n );\n return lines.join('\\n');\n}\n\n/** One line per offender, in the shape every error in this file uses. */\n// webpieces-disable no-function-outside-class -- pure formatter shared by the one error below\nfunction rootUnionLines(found: readonly RootUnionApiType[]): string {\n return found\n .map(\n (one: RootUnionApiType) =>\n ` • ${one.api}.${one.method} — ${one.side} type '${one.typeName}' at ${one.at}`,\n )\n .join('\\n');\n}\n\n/**\n * `no-root-union-api-type`: a request or response type that IS a union, on ANY `@ApiPath` contract.\n *\n * Fatal, and fatal EARLY, because the failure it prevents is discovered by somebody else at runtime\n * and does not look like this contract's fault: a top-level `oneOf` is rejected by both the OpenAI\n * and the Anthropic function-calling APIs, a server sends its whole tool list on every request, and\n * so ONE such tool makes EVERY request 400. The user's report is \"all the other tools broke\".\n *\n * The second list is reasonless disables. A disable for this rule must carry an argument somebody\n * wrote down: the escape hatch is deliberately per-site and never a blanket switch, because the\n * blast radius is a whole session rather than one call.\n */\nexport class RootUnionApiTypeError extends Error {\n constructor(public readonly findings: RootUnionFindings) {\n super(RootUnionApiTypeError.render(findings));\n this.name = 'RootUnionApiTypeError';\n }\n\n // webpieces-disable no-function-outside-class, max-lines-new-methods -- private static renderer of this class, and splitting one message hides what a reader actually sees\n private static render(findings: RootUnionFindings): string {\n const parts: string[] = [];\n if (findings.violations.length > 0) {\n parts.push(\n `${findings.violations.length} @ApiPath method(s) declare a request or response type that IS a union:\\n` +\n rootUnionLines(findings.violations) +\n `\\n A union at the TOP LEVEL of a tool's parameter schema is rejected by BOTH the OpenAI and\\n` +\n ` the Anthropic function-calling APIs. A server sends its WHOLE tool list on every request, so\\n` +\n ` ONE of these makes EVERY request 400 and the entire client session unusable — not just that\\n` +\n ` tool. Nested composition, INSIDE a property, is fine and publishes as oneOf.\\n` +\n ` Fix it by wrapping the union in a property of an object:\\n` +\n ` export interface MoveWindowRequest { window: ScheduledWindow | AsapWindow }\\n` +\n ` This runs on EVERY @ApiPath contract, with or without @ApiType: @ApiType is a publishing\\n` +\n ` decision added later, so a shape that is not expressible must fail on the first line rather\\n` +\n ` than on the day somebody annotates it.\\n` +\n ` Last resort, per site: // webpieces-disable ${ROOT_UNION_RULE} -- <reason>`,\n );\n }\n if (findings.reasonlessDisables.length > 0) {\n parts.push(\n `${findings.reasonlessDisables.length} disable(s) of ${ROOT_UNION_RULE} give NO reason:\\n` +\n rootUnionLines(findings.reasonlessDisables) +\n `\\n The reason is MANDATORY — a reasonless disable is itself a violation. Write it as\\n` +\n ` // webpieces-disable ${ROOT_UNION_RULE} -- <why this root union is deliberate>\\n` +\n ` The hatch is per-site and argued on purpose: this defect costs a whole client session, so\\n` +\n ` the next reader needs the argument, not just the suppression.`,\n );\n }\n return parts.join('\\n\\n');\n }\n}\n\n/**\n * Endpoints whose response-body declaration disagrees with their kind or their signature (#1339,\n * #1348): CLOUDTASKS / CRON are void BY KIND, EXTERNAL_OUTBOUND is the vendor's to shape, and RPC /\n * EXTERNAL_INBOUND declare `responseBody: NONE`.\n */\nexport class VoidResponseMismatchError extends Error {\n constructor(public readonly endpoints: readonly VoidResponseMismatch[]) {\n super(\n `${endpoints.length} @Endpoint(s) disagree with their kind or return type about a response body:\\n` +\n endpoints\n .map((e: VoidResponseMismatch) => ` • ${VoidResponseMismatchError.line(e)} — at ${e.at}`)\n .join('\\n') +\n `\\n A Promise<void> endpoint answers 204 with 0 bytes, and the runtime cannot see 'void'\\n` +\n ` (design:returntype is just Promise). A CLOUDTASKS or CRON endpoint is fire-and-forget, so its\\n` +\n ` KIND already means no response body: it returns Promise<void> and writes no responseBody option.\\n` +\n ` An EXTERNAL_OUTBOUND endpoint is served by the vendor, which shapes its own responses, so it writes\\n` +\n ` no responseBody option either (its client accepts any 2xx). RPC and EXTERNAL_INBOUND add\\n` +\n ` { responseBody: NONE } to @Endpoint's options on every Promise<void> method, and only on those.`,\n );\n this.name = 'VoidResponseMismatchError';\n }\n\n // webpieces-disable no-function-outside-class -- builds the super() message, which runs before `this` exists (parameter property)\n private static line(e: VoidResponseMismatch): string {\n const kind = e.kind.toUpperCase();\n switch (e.problem) {\n case VoidResponseProblem.NONE_WITHOUT_VOID:\n return `${e.api}.${e.method} declares responseBody: NONE but does not return Promise<void>`;\n case VoidResponseProblem.VOID_WITHOUT_NONE:\n return `${e.api}.${e.method} returns Promise<void> but does not declare responseBody: NONE`;\n case VoidResponseProblem.REDUNDANT_NONE:\n return (\n `${e.api}.${e.method} is a ${kind} endpoint and declares responseBody: NONE, which is redundant: ` +\n `the ${kind} kind already means no response body — delete responseBody: NONE`\n );\n case VoidResponseProblem.OUTBOUND_NONE:\n return (\n `${e.api}.${e.method} is an EXTERNAL_OUTBOUND endpoint and declares responseBody: NONE, which does not apply: ` +\n `NONE describes what OUR server sends, and the vendor shapes an outbound response — delete responseBody: NONE`\n );\n case VoidResponseProblem.TRIGGER_NOT_VOID:\n return (\n `${e.api}.${e.method} is a ${kind} endpoint but does not return Promise<void>: ` +\n `a ${kind} endpoint is fire-and-forget and its caller reads only the status — return Promise<void>`\n );\n }\n }\n}\n\n/** Endpoints missing the operation declaration that drives retry safety and MCP annotations. */\nexport class UndeclaredEndpointOperationError extends Error {\n constructor(public readonly endpoints: readonly UndeclaredEndpointOperation[]) {\n super(\n `${endpoints.length} @Endpoint(s) do not declare a readable operation:\\n` +\n endpoints\n .map(\n (e: UndeclaredEndpointOperation) =>\n ` • ${e.api}.${e.method} — ${e.argument} at ${e.at}`,\n )\n .join('\\n') +\n `\\n operation is REQUIRED because it controls retry safety and generated MCP hints.\\n` +\n ` Pass exactly one of READ, WRITE_IDEMPOTENT, or WRITE as the third argument.\\n` +\n ` Do not infer operation semantics from the HTTP verb.`,\n );\n this.name = 'UndeclaredEndpointOperationError';\n }\n}\n\n/**\n * A routed contract whose `@ApiPath` argument the scan could not read. Fatal on purpose: shipping the\n * entry without its basePath is what made `/whatsapp/test` render as `/test` in a downstream runbook.\n */\nexport class MissingBasePathError extends Error {\n constructor(public readonly contracts: readonly string[]) {\n super(\n `${contracts.length} API contract(s) have @Endpoint methods but no readable @ApiPath basePath:\\n` +\n contracts.map((c: string) => ` • ${c}`).join('\\n') +\n `\\n basePath is REQUIRED in every api contract — an entry without it makes every consumer\\n` +\n ` compute basePath + path as just path, silently. Inline the @ApiPath string literal,\\n` +\n ` or move the constant into the same module as the contract class.`,\n );\n this.name = 'MissingBasePathError';\n }\n}\n\n/**\n * `@Endpoint` paths the scan could not read. Fatal for the same reason MissingBasePathError is: the\n * two arguments are the two halves of ONE url. An http client builds its request as\n * `basePath + path`, so a contract shipped without a method's path is missing routing information,\n * and the consumer computes a confidently wrong URL. Skipping the method instead was worse still —\n * a class whose every path was an unreadable constant lost every method and vanished from the graph.\n */\nexport class UnresolvedEndpointPathError extends Error {\n constructor(public readonly paths: readonly UnresolvedEndpointPath[]) {\n super(\n `${paths.length} @Endpoint path(s) could not be read as a string:\\n` +\n paths\n .map(\n (p: UnresolvedEndpointPath) =>\n ` • ${p.api}.${p.method} — @Endpoint(${p.argument}, ...) at ${p.at}`,\n )\n .join('\\n') +\n `\\n path is REQUIRED in every api contract — every consumer builds its request URL as\\n` +\n ` basePath + path, so an unreadable path is MISSING ROUTING, not cosmetic metadata,\\n` +\n ` and a class whose every path is unreadable drops out of the graph entirely.\\n` +\n ` Inline the @Endpoint string literal, or move the constant into the SAME module as\\n` +\n ` the contract class — a same-module const IS resolved, one imported from another\\n` +\n ` module is NOT (this scan is parser-only by design: module resolution can land on a\\n` +\n ` decorator-erased .d.ts).`,\n );\n this.name = 'UnresolvedEndpointPathError';\n }\n}\n\n/**\n * `external` endpoints whose CALLER the scan could not read. Fatal, like the two above, because the\n * alternative is a diagram that lies by omission: the inbound box exists solely to name the system\n * calling us from outside, and with nothing to name it falls back to restating our own contract\n * name — which the reader already sees on the service box the arrow points at.\n *\n * `@Endpoint`'s TS overloads make `calledBy` a compile error to omit, so a scan reaching here saw a\n * JS caller, an `as any`, a cross-module constant this parser-only pass cannot fold, or a\n * `callerKind` that is not one of the declared kinds.\n */\nexport class UndeclaredExternalCallerError extends Error {\n constructor(public readonly callers: readonly UndeclaredExternalCaller[]) {\n super(\n `${callers.length} 'external-inbound' @Endpoint(s) do not declare WHO calls them:\\n` +\n callers\n .map(\n (c: UndeclaredExternalCaller) =>\n ` • ${c.api}.${c.method} — ${c.argument} at ${c.at}`,\n )\n .join('\\n') +\n `\\n An EXTERNAL_INBOUND endpoint is driven by a system OUTSIDE this repo, and the runtime\\n` +\n ` architecture graph draws that system as an inbound box. Name it:\\n` +\n ` @Endpoint(POST, '/hook', WRITE, EXTERNAL_INBOUND, { calledBy: 'twilio' })\\n` +\n ` Add callerKind for anything that is not a vendor SaaS — database | cache | queue |\\n` +\n ` storage | saas | system — e.g. a GCP Pub/Sub push subscription:\\n` +\n ` @Endpoint(POST, '/push', WRITE, EXTERNAL_INBOUND, { calledBy: 'pubsub-push', callerKind: 'system' })\\n` +\n ` Use a string LITERAL or a SAME-module const: this scan is parser-only by design.`,\n );\n this.name = 'UndeclaredExternalCallerError';\n }\n}\n\n/**\n * Contract classes that declared `@Endpoint` methods and kept none of them. Fatal because the\n * alternative is the silent drop the api scan exists to close: buildApiContracts legitimately skips\n * a zero-method class (a vendor seam has no routes), and a class gutted by unreadable decorator\n * arguments used the very same exit — which is how a service lost two real Cloud Tasks queues and an\n * inbound webhook without a single line of output.\n */\nexport class EmptiedApiContractError extends Error {\n constructor(public readonly contracts: readonly EmptiedApiContract[]) {\n super(\n `${contracts.length} API contract class(es) declare @Endpoint methods but kept NONE of them:\\n` +\n contracts\n .map(\n (c: EmptiedApiContract) =>\n ` • ${c.api} — ${c.declared} @Endpoint method(s) declared, 0 usable, at ${c.at}`,\n )\n .join('\\n') +\n `\\n A contract with zero usable methods is DROPPED from the api contracts, so the class,\\n` +\n ` its queues and its triggers disappear from the architecture graph with no error.\\n` +\n ` Every @Endpoint argument must be readable: the path as a string literal or a\\n` +\n ` SAME-module const, the kind as RPC | CLOUDTASKS | CRON | EXTERNAL_INBOUND | EXTERNAL_OUTBOUND, and\\n` +\n ` the options must declare operation. Fix the arguments above, or remove the decorators if the\\n` +\n ` class is genuinely not routed.`,\n );\n this.name = 'EmptiedApiContractError';\n }\n}\n"]}
1
+ {"version":3,"file":"api-contract-errors.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/lib/api-usage/api-contract-errors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AA+BH,sDAcC;AA2ID,gEAgBC;AAtMD,mDASyB;AACzB,uDAAyF;AACzF,mDAMyB;AAEzB;;;;;;;;GAQG;AACH,oGAAoG;AACpG,SAAgB,qBAAqB,CAAC,UAAmC;IACrE,MAAM,KAAK,GAAG;QACV,OAAO,UAAU,CAAC,MAAM,oEAAoE;KAC/F,CAAC;IACF,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,UAAU,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,OAAO,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;QAC3D,KAAK,CAAC,IAAI,CAAC,UAAU,GAAG,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1F,CAAC;IACD,KAAK,CAAC,IAAI,CACN,6FAA6F,EAC7F,8FAA8F,EAC9F,6FAA6F,CAChG,CAAC;IACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC;AAED,wFAAwF;AACxF,8FAA8F;AAC9F,SAAS,gBAAgB,CAAC,OAAe,EAAE,UAAmC;IAC1E,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IAC5C,OAAO,GAAG,OAAO,OAAO,qBAAqB,CAAC,UAAU,CAAC,EAAE,CAAC;AAChE,CAAC;AAED;;;;;;;GAOG;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G,CACA,CAAC,CAA2B,EAAE,EAAE,CAC5B,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC,QAAQ,OAAO,CAAC,CAAC,EAAE,EAAE,CAC/D;iBACA,IAAI,CAAC,IAAI,CAAC;YACf,8FAA8F;YAC9F,uEAAuE;YACvE,kFAAkF;YAClF,yFAAyF;YACzF,sEAAsE;YACtE,6GAA6G;YAC7G,qFAAqF,CAC5F,CAAC;QAhBsB,YAAO,GAAP,OAAO,CAAqC;QAiBpE,IAAI,CAAC,IAAI,GAAG,+BAA+B,CAAC;IAChD,CAAC;CACJ;AApBD,sEAoBC;AAED;;;;;;GAMG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAClB;IAA5B,YAA4B,SAAwC;QAChE,KAAK,CACD,GAAG,SAAS,CAAC,MAAM,4EAA4E;YAC3F,SAAS;iBACJ,GAAG,CACA,CAAC,CAAqB,EAAE,EAAE,CACtB,UAAU,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,QAAQ,+CAA+C,CAAC,CAAC,EAAE,EAAE,CAC3F;iBACA,IAAI,CAAC,IAAI,CAAC;YACf,6FAA6F;YAC7F,uFAAuF;YACvF,mFAAmF;YACnF,yGAAyG;YACzG,mGAAmG;YACnG,mCAAmC,CAC1C,CAAC;QAfsB,cAAS,GAAT,SAAS,CAA+B;QAgBhE,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IAC1C,CAAC;CACJ;AAnBD,0DAmBC","sourcesContent":["/**\n * The ways `buildApiContracts` refuses to emit a green, wrong api contract table.\n *\n * They share one rule: an entry that is PRESENT but incomplete is worse than an absent one.\n * Every other entry in the table is complete, so a consumer has no reason to suspect the one that\n * lost a field — it just computes a confidently wrong URL, or draws a service with no queues.\n *\n * Each aggregates EVERY offender into one message rather than throwing on the first: an author who\n * moved a constants module broke five decorators at once and wants all five named in one run.\n *\n * Split out of api-scanner.ts, which owns the scan itself and is at its file-size limit.\n */\n\nimport {\n AdditiveReadEndpoint,\n EmptiedApiContract,\n UndeclaredEndpointOperation,\n UndeclaredExternalCaller,\n UnresolvedApiCall,\n UnresolvedEndpointPath,\n VoidResponseMismatch,\n VoidResponseProblem,\n} from './api-relations';\nimport { RootUnionApiType, RootUnionFindings, ROOT_UNION_RULE } from './root-union-scan';\nimport {\n ApiContractDefect,\n ApiRuleFindings,\n McpExclusion,\n MCP_RULE,\n OPENAPI_RULE,\n} from './api-doc-rules';\n\n/**\n * The endpoints declared PERMANENTLY outside MCP, with their reasons — restated on EVERY run of\n * `api-rules-for-mcp`, green or red (#1014).\n *\n * Not a warning and not a finding. #1014 asked whether adding an `@InvalidEndpointForMcp` should\n * warn, and the answer is that a one-off warning is read by the one person who already knows the\n * decision. A list restated on every run is read by whoever comes next, which is who the reason was\n * written for. Printed by the caller, exactly like `describeUnresolvedApiCalls`.\n */\n// webpieces-disable no-function-outside-class -- pure formatter, mirrors describeUnresolvedApiCalls\nexport function describeMcpExclusions(exclusions: readonly McpExclusion[]): string {\n const lines = [\n `ℹ️ ${exclusions.length} endpoint(s) are PERMANENTLY outside MCP (@InvalidEndpointForMcp):`,\n ];\n for (const one of exclusions) {\n lines.push(` • ${one.api}.${one.method} at ${one.at}`);\n lines.push(` ${one.reason === '' ? '<reason could not be read>' : one.reason}`);\n }\n lines.push(\n ` These are DECLARATIONS, not suppressions: each says the endpoint can never be a tool and`,\n ` why. They are restated every run rather than announced once, so the reasons stay readable`,\n ` by whoever comes next. \\`grep -rn InvalidEndpointForMcp\\` is the same list from a shell.`,\n );\n return lines.join('\\n');\n}\n\n/** The rule's message with its PERMANENT-exclusion list appended, when there is one. */\n// webpieces-disable no-function-outside-class -- pure formatter beside the error that uses it\nfunction appendExclusions(message: string, exclusions: readonly McpExclusion[]): string {\n if (exclusions.length === 0) return message;\n return `${message}\\n\\n${describeMcpExclusions(exclusions)}`;\n}\n\n/**\n * One defect per line, with its cure INDENTED under it rather than collected into a footer.\n *\n * Every other error in this file prints one shared cure because its offenders share one root cause —\n * an unreadable constant, a missing `calledBy`. These two do not: an open enum, an `unknown` value\n * and a `void` RPC are three different edits, and a footer would make the reader work out which of\n * the three applies to which line.\n */\n// webpieces-disable no-function-outside-class -- pure formatter, mirrors rootUnionLines\nfunction apiDefectLines(found: readonly ApiContractDefect[]): string {\n return found\n .map((one: ApiContractDefect) => {\n const exposure = one.isExternal() ? ' [PARTNER-FACING]' : '';\n return (\n ` • ${one.where()}${exposure} — ${one.what}\\n` +\n ` at ${one.at}\\n` +\n ` cure: ${one.cure}`\n );\n })\n .join('\\n');\n}\n\n/** The two halves every api-doc rule prints, so both refusals say the reasonless part identically. */\n// webpieces-disable no-function-outside-class -- pure formatter shared by the two errors below\nfunction apiRuleMessage(\n rule: string,\n headline: string,\n findings: ApiRuleFindings,\n why: string,\n): string {\n const parts: string[] = [];\n if (findings.violations.length > 0) {\n parts.push(\n `${findings.violations.length} ${headline}:\\n` +\n apiDefectLines(findings.violations) +\n `\\n${why}\\n` +\n ` This runs on EVERY @ApiPath contract, with or without @ApiType: @ApiType is a\\n` +\n ` PUBLISHING decision added later, so a shape that is not expressible must fail on the\\n` +\n ` first line rather than on the day somebody annotates it — by which time the type is\\n` +\n ` in partners' generated clients and cannot be changed.\\n` +\n ` Last resort, per site: // webpieces-disable ${rule} -- <reason>`,\n );\n }\n if (findings.reasonlessDisables.length > 0) {\n parts.push(\n `${findings.reasonlessDisables.length} disable(s) of ${rule} give NO reason:\\n` +\n apiDefectLines(findings.reasonlessDisables) +\n `\\n The reason is MANDATORY — a reasonless disable is itself a violation. Write it as\\n` +\n ` // webpieces-disable ${rule} -- <why this contract is published like this>\\n` +\n ` The hatch is per-site and argued on purpose: the next reader needs the argument,\\n` +\n ` not just the suppression.`,\n );\n }\n return parts.join('\\n\\n');\n}\n\n/**\n * `api-rules-for-openapi`: a contract that cannot produce an OpenAPI document.\n *\n * Fatal because the failure it prevents is DOCUMENT-WIDE and arrives late. One field with no shape\n * fails the whole document, so no partner can generate a client for ANY operation of that API — six\n * of 98 endpoints in a measured upstream repo, from exactly two root causes, and five of those six\n * were one field. The author who wrote that field had no way to know, because nothing looked at the\n * contract until somebody added `@ApiType` months later.\n *\n * Its verdict is the GENERATOR'S: the scan drives `ApiDocExtractor` rather than restating what is\n * expressible, so a contract that passes this is one where adding `@ApiType` then generates.\n */\nexport class ApiRulesForOpenApiError extends Error {\n constructor(public readonly findings: ApiRuleFindings) {\n super(\n apiRuleMessage(\n OPENAPI_RULE,\n '@ApiPath contract defect(s) would block the OpenAPI document',\n findings,\n ` An OpenAPI failure is DOCUMENT-WIDE: one field with no shape blocks client generation\\n` +\n ` for every operation of that API, not just the one that declares it.`,\n ),\n );\n this.name = 'ApiRulesForOpenApiError';\n }\n}\n\n/**\n * `api-rules-for-mcp`: a `@WpMcpTool` that could not be served.\n *\n * Every one of these is something `McpToolRegistry` refuses to BOOT on — a tool it cannot find a\n * schema for is a tool whose schema nobody checked — so the choice is only WHERE it is discovered.\n * Here it names the method; at boot it names a process that will not start, in an environment where\n * nobody is editing the contract.\n *\n * Separate from the OpenAPI error because the blast radii are different: this blocks ONE tool, where\n * an OpenAPI defect blocks a whole document. A team publishing a partner API and no tools runs the\n * first rule and not this one, which is only possible if they are two rules.\n */\nexport class ApiRulesForMcpError extends Error {\n constructor(\n public readonly findings: ApiRuleFindings,\n /**\n * The `@InvalidEndpointForMcp` endpoints, appended to the message.\n *\n * A red run is exactly when somebody is looking at this output, so it is also when the\n * PERMANENT exclusions are most worth restating: the next question after \"why is this tool\n * blocked\" is \"which endpoints did we already decide can never be tools, and why\".\n */\n public readonly exclusions: readonly McpExclusion[] = [],\n ) {\n super(\n appendExclusions(\n apiRuleMessage(\n MCP_RULE,\n '@WpMcpTool declaration(s) could not be served as MCP tools',\n findings,\n ` Each of these makes McpToolRegistry REFUSE TO BOOT: a registered tool the build never\\n` +\n ` published is a tool whose schema nobody checked. Caught here, it names the method;\\n` +\n ` caught at boot, it names a process that will not start.`,\n ),\n exclusions,\n ),\n );\n this.name = 'ApiRulesForMcpError';\n }\n}\n\n/**\n * Loud, actionable report for contracts the scan could not map to source. Callers print this\n * instead of emitting a green graph that is quietly missing relations. Not fatal: a contract\n * from a genuinely EXTERNAL (published, non-workspace) api-lib legitimately has no source here.\n */\n// webpieces-disable no-function-outside-class -- pure formatter, mirrors describeUnclassifiedApiDep\nexport function describeUnresolvedApiCalls(calls: UnresolvedApiCall[]): string {\n const lines = [\n `⚠️ ${calls.length} API contract(s) resolved to a declaration file with no matching workspace source.`,\n ` Decorators (@ApiPath) are ERASED in .d.ts output, so these relations are MISSING from the graph:`,\n ];\n for (const call of calls) {\n lines.push(\n ` • ${call.api} at ${call.at} (${call.project}) → resolved to ${call.declaredIn}`,\n );\n }\n lines.push(\n ` If the api-lib IS in this workspace, add a tsconfig.base.json 'paths' entry mapping it to its`,\n ` src/index.ts, or confirm its project root is registered. If it is a published external package,`,\n ` this relation cannot be derived and the graph edge will not appear.`,\n );\n return lines.join('\\n');\n}\n\n/** One line per offender, in the shape every error in this file uses. */\n// webpieces-disable no-function-outside-class -- pure formatter shared by the one error below\nfunction rootUnionLines(found: readonly RootUnionApiType[]): string {\n return found\n .map(\n (one: RootUnionApiType) =>\n ` • ${one.api}.${one.method} — ${one.side} type '${one.typeName}' at ${one.at}`,\n )\n .join('\\n');\n}\n\n/**\n * `no-root-union-api-type`: a request or response type that IS a union, on ANY `@ApiPath` contract.\n *\n * Fatal, and fatal EARLY, because the failure it prevents is discovered by somebody else at runtime\n * and does not look like this contract's fault: a top-level `oneOf` is rejected by both the OpenAI\n * and the Anthropic function-calling APIs, a server sends its whole tool list on every request, and\n * so ONE such tool makes EVERY request 400. The user's report is \"all the other tools broke\".\n *\n * The second list is reasonless disables. A disable for this rule must carry an argument somebody\n * wrote down: the escape hatch is deliberately per-site and never a blanket switch, because the\n * blast radius is a whole session rather than one call.\n */\nexport class RootUnionApiTypeError extends Error {\n constructor(public readonly findings: RootUnionFindings) {\n super(RootUnionApiTypeError.render(findings));\n this.name = 'RootUnionApiTypeError';\n }\n\n // webpieces-disable no-function-outside-class, max-lines-new-methods -- private static renderer of this class, and splitting one message hides what a reader actually sees\n private static render(findings: RootUnionFindings): string {\n const parts: string[] = [];\n if (findings.violations.length > 0) {\n parts.push(\n `${findings.violations.length} @ApiPath method(s) declare a request or response type that IS a union:\\n` +\n rootUnionLines(findings.violations) +\n `\\n A union at the TOP LEVEL of a tool's parameter schema is rejected by BOTH the OpenAI and\\n` +\n ` the Anthropic function-calling APIs. A server sends its WHOLE tool list on every request, so\\n` +\n ` ONE of these makes EVERY request 400 and the entire client session unusable — not just that\\n` +\n ` tool. Nested composition, INSIDE a property, is fine and publishes as oneOf.\\n` +\n ` Fix it by wrapping the union in a property of an object:\\n` +\n ` export interface MoveWindowRequest { window: ScheduledWindow | AsapWindow }\\n` +\n ` This runs on EVERY @ApiPath contract, with or without @ApiType: @ApiType is a publishing\\n` +\n ` decision added later, so a shape that is not expressible must fail on the first line rather\\n` +\n ` than on the day somebody annotates it.\\n` +\n ` Last resort, per site: // webpieces-disable ${ROOT_UNION_RULE} -- <reason>`,\n );\n }\n if (findings.reasonlessDisables.length > 0) {\n parts.push(\n `${findings.reasonlessDisables.length} disable(s) of ${ROOT_UNION_RULE} give NO reason:\\n` +\n rootUnionLines(findings.reasonlessDisables) +\n `\\n The reason is MANDATORY — a reasonless disable is itself a violation. Write it as\\n` +\n ` // webpieces-disable ${ROOT_UNION_RULE} -- <why this root union is deliberate>\\n` +\n ` The hatch is per-site and argued on purpose: this defect costs a whole client session, so\\n` +\n ` the next reader needs the argument, not just the suppression.`,\n );\n }\n return parts.join('\\n\\n');\n }\n}\n\n/**\n * Endpoints whose response-body declaration disagrees with their kind or their signature (#1339,\n * #1348): CLOUDTASKS / CRON are void BY KIND, EXTERNAL_OUTBOUND is the vendor's to shape, and RPC /\n * EXTERNAL_INBOUND declare `responseBody: NONE`.\n */\nexport class VoidResponseMismatchError extends Error {\n constructor(public readonly endpoints: readonly VoidResponseMismatch[]) {\n super(\n `${endpoints.length} @Endpoint(s) disagree with their kind or return type about a response body:\\n` +\n endpoints\n .map((e: VoidResponseMismatch) => ` • ${VoidResponseMismatchError.line(e)} — at ${e.at}`)\n .join('\\n') +\n `\\n A Promise<void> endpoint answers 204 with 0 bytes, and the runtime cannot see 'void'\\n` +\n ` (design:returntype is just Promise). A CLOUDTASKS or CRON endpoint is fire-and-forget, so its\\n` +\n ` KIND already means no response body: it returns Promise<void> and writes no responseBody option.\\n` +\n ` An EXTERNAL_OUTBOUND endpoint is served by the vendor, which shapes its own responses, so it writes\\n` +\n ` no responseBody option either (its client accepts any 2xx). RPC and EXTERNAL_INBOUND add\\n` +\n ` { responseBody: NONE } to @Endpoint's options on every Promise<void> method, and only on those.`,\n );\n this.name = 'VoidResponseMismatchError';\n }\n\n // webpieces-disable no-function-outside-class -- builds the super() message, which runs before `this` exists (parameter property)\n private static line(e: VoidResponseMismatch): string {\n const kind = e.kind.toUpperCase();\n switch (e.problem) {\n case VoidResponseProblem.NONE_WITHOUT_VOID:\n return `${e.api}.${e.method} declares responseBody: NONE but does not return Promise<void>`;\n case VoidResponseProblem.VOID_WITHOUT_NONE:\n return `${e.api}.${e.method} returns Promise<void> but does not declare responseBody: NONE`;\n case VoidResponseProblem.REDUNDANT_NONE:\n return (\n `${e.api}.${e.method} is a ${kind} endpoint and declares responseBody: NONE, which is redundant: ` +\n `the ${kind} kind already means no response body — delete responseBody: NONE`\n );\n case VoidResponseProblem.OUTBOUND_NONE:\n return (\n `${e.api}.${e.method} is an EXTERNAL_OUTBOUND endpoint and declares responseBody: NONE, which does not apply: ` +\n `NONE describes what OUR server sends, and the vendor shapes an outbound response — delete responseBody: NONE`\n );\n case VoidResponseProblem.TRIGGER_NOT_VOID:\n return (\n `${e.api}.${e.method} is a ${kind} endpoint but does not return Promise<void>: ` +\n `a ${kind} endpoint is fire-and-forget and its caller reads only the status — return Promise<void>`\n );\n }\n }\n}\n\n/** Endpoints missing the operation declaration that drives retry safety and MCP annotations. */\nexport class UndeclaredEndpointOperationError extends Error {\n constructor(public readonly endpoints: readonly UndeclaredEndpointOperation[]) {\n super(\n `${endpoints.length} @Endpoint(s) do not declare a readable operation:\\n` +\n endpoints\n .map(\n (e: UndeclaredEndpointOperation) =>\n ` • ${e.api}.${e.method} — ${e.argument} at ${e.at}`,\n )\n .join('\\n') +\n `\\n operation is REQUIRED because it controls retry safety and generated MCP hints.\\n` +\n ` Pass exactly one of READ, WRITE_IDEMPOTENT, or WRITE as the third argument.\\n` +\n ` Do not infer operation semantics from the HTTP verb.`,\n );\n this.name = 'UndeclaredEndpointOperationError';\n }\n}\n\n/** READ endpoints declaring `{ additive }` (#1423): a read changes nothing to be additive about. */\nexport class AdditiveReadEndpointError extends Error {\n constructor(public readonly endpoints: readonly AdditiveReadEndpoint[]) {\n super(\n `${endpoints.length} READ @Endpoint(s) declare { additive }:\\n` +\n endpoints\n .map((e: AdditiveReadEndpoint) => ` • ${e.api}.${e.method} at ${e.at}`)\n .join('\\n') +\n `\\n A read changes nothing, so it has nothing to be additive about, and @Endpoint's\\n` +\n ` types already refuse it. Remove \\`additive\\` from the READ endpoint, or declare the\\n` +\n ` operation WRITE / WRITE_IDEMPOTENT if the endpoint really adds state.`,\n );\n this.name = 'AdditiveReadEndpointError';\n }\n}\n\n/**\n * A routed contract whose `@ApiPath` argument the scan could not read. Fatal on purpose: shipping the\n * entry without its basePath is what made `/whatsapp/test` render as `/test` in a downstream runbook.\n */\nexport class MissingBasePathError extends Error {\n constructor(public readonly contracts: readonly string[]) {\n super(\n `${contracts.length} API contract(s) have @Endpoint methods but no readable @ApiPath basePath:\\n` +\n contracts.map((c: string) => ` • ${c}`).join('\\n') +\n `\\n basePath is REQUIRED in every api contract — an entry without it makes every consumer\\n` +\n ` compute basePath + path as just path, silently. Inline the @ApiPath string literal,\\n` +\n ` or move the constant into the same module as the contract class.`,\n );\n this.name = 'MissingBasePathError';\n }\n}\n\n/**\n * `@Endpoint` paths the scan could not read. Fatal for the same reason MissingBasePathError is: the\n * two arguments are the two halves of ONE url. An http client builds its request as\n * `basePath + path`, so a contract shipped without a method's path is missing routing information,\n * and the consumer computes a confidently wrong URL. Skipping the method instead was worse still —\n * a class whose every path was an unreadable constant lost every method and vanished from the graph.\n */\nexport class UnresolvedEndpointPathError extends Error {\n constructor(public readonly paths: readonly UnresolvedEndpointPath[]) {\n super(\n `${paths.length} @Endpoint path(s) could not be read as a string:\\n` +\n paths\n .map(\n (p: UnresolvedEndpointPath) =>\n ` • ${p.api}.${p.method} — @Endpoint(${p.argument}, ...) at ${p.at}`,\n )\n .join('\\n') +\n `\\n path is REQUIRED in every api contract — every consumer builds its request URL as\\n` +\n ` basePath + path, so an unreadable path is MISSING ROUTING, not cosmetic metadata,\\n` +\n ` and a class whose every path is unreadable drops out of the graph entirely.\\n` +\n ` Inline the @Endpoint string literal, or move the constant into the SAME module as\\n` +\n ` the contract class — a same-module const IS resolved, one imported from another\\n` +\n ` module is NOT (this scan is parser-only by design: module resolution can land on a\\n` +\n ` decorator-erased .d.ts).`,\n );\n this.name = 'UnresolvedEndpointPathError';\n }\n}\n\n/**\n * `external` endpoints whose CALLER the scan could not read. Fatal, like the two above, because the\n * alternative is a diagram that lies by omission: the inbound box exists solely to name the system\n * calling us from outside, and with nothing to name it falls back to restating our own contract\n * name — which the reader already sees on the service box the arrow points at.\n *\n * `@Endpoint`'s TS overloads make `calledBy` a compile error to omit, so a scan reaching here saw a\n * JS caller, an `as any`, a cross-module constant this parser-only pass cannot fold, or a\n * `callerKind` that is not one of the declared kinds.\n */\nexport class UndeclaredExternalCallerError extends Error {\n constructor(public readonly callers: readonly UndeclaredExternalCaller[]) {\n super(\n `${callers.length} 'external-inbound' @Endpoint(s) do not declare WHO calls them:\\n` +\n callers\n .map(\n (c: UndeclaredExternalCaller) =>\n ` • ${c.api}.${c.method} — ${c.argument} at ${c.at}`,\n )\n .join('\\n') +\n `\\n An EXTERNAL_INBOUND endpoint is driven by a system OUTSIDE this repo, and the runtime\\n` +\n ` architecture graph draws that system as an inbound box. Name it:\\n` +\n ` @Endpoint(POST, '/hook', WRITE, EXTERNAL_INBOUND, { calledBy: 'twilio' })\\n` +\n ` Add callerKind for anything that is not a vendor SaaS — database | cache | queue |\\n` +\n ` storage | saas | system — e.g. a GCP Pub/Sub push subscription:\\n` +\n ` @Endpoint(POST, '/push', WRITE, EXTERNAL_INBOUND, { calledBy: 'pubsub-push', callerKind: 'system' })\\n` +\n ` Use a string LITERAL or a SAME-module const: this scan is parser-only by design.`,\n );\n this.name = 'UndeclaredExternalCallerError';\n }\n}\n\n/**\n * Contract classes that declared `@Endpoint` methods and kept none of them. Fatal because the\n * alternative is the silent drop the api scan exists to close: buildApiContracts legitimately skips\n * a zero-method class (a vendor seam has no routes), and a class gutted by unreadable decorator\n * arguments used the very same exit — which is how a service lost two real Cloud Tasks queues and an\n * inbound webhook without a single line of output.\n */\nexport class EmptiedApiContractError extends Error {\n constructor(public readonly contracts: readonly EmptiedApiContract[]) {\n super(\n `${contracts.length} API contract class(es) declare @Endpoint methods but kept NONE of them:\\n` +\n contracts\n .map(\n (c: EmptiedApiContract) =>\n ` • ${c.api} — ${c.declared} @Endpoint method(s) declared, 0 usable, at ${c.at}`,\n )\n .join('\\n') +\n `\\n A contract with zero usable methods is DROPPED from the api contracts, so the class,\\n` +\n ` its queues and its triggers disappear from the architecture graph with no error.\\n` +\n ` Every @Endpoint argument must be readable: the path as a string literal or a\\n` +\n ` SAME-module const, the kind as RPC | CLOUDTASKS | CRON | EXTERNAL_INBOUND | EXTERNAL_OUTBOUND, and\\n` +\n ` the options must declare operation. Fix the arguments above, or remove the decorators if the\\n` +\n ` class is genuinely not routed.`,\n );\n this.name = 'EmptiedApiContractError';\n }\n}\n"]}
@@ -31,6 +31,7 @@ class ApiContractEvidence {
31
31
  undeclaredExternalCallers: diagnostics.undeclaredExternalCallers(),
32
32
  undeclaredEndpointOperations: diagnostics.undeclaredEndpointOperations(),
33
33
  voidResponseMismatches: diagnostics.voidResponseMismatches(),
34
+ additiveReads: diagnostics.additiveReads(),
34
35
  rootUnions: new root_union_scan_1.RootUnionScan(workspaceRoot, infos, root_union_scan_1.RootUnionRule.fromConfig(workspaceRoot)).run(),
35
36
  apiDocRules: new api_doc_rules_scan_1.ApiDocRulesScan(workspaceRoot, infos, await api_doc_rules_1.ApiDocRule.fromConfig(workspaceRoot, api_doc_rules_1.OPENAPI_RULE), await api_doc_rules_1.ApiDocRule.fromConfig(workspaceRoot, api_doc_rules_1.MCP_RULE), await wire_closure_1.WireClosureRule.fromConfig(workspaceRoot)).run(),
36
37
  };
@@ -1 +1 @@
1
- {"version":3,"file":"api-contract-evidence.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/lib/api-usage/api-contract-evidence.ts"],"names":[],"mappings":";;;;AAAA,mEAA8D;AAC9D,yDAA0D;AAC1D,+CAAyB;AACzB,mDAA6B;AAC7B,+CAAyE;AACzE,uCAAoD;AACpD,uDAAiE;AACjE,mDAAqE;AACrE,6DAAuD;AACvD,iDAAiD;AAIjD,qGAAqG;AACrG,MAAa,mBAAmB;IAC5B,KAAK,CAAC,OAAO,CACT,aAAqB,EACrB,KAA+B,EAC/B,gBAAmC;QAEnC,MAAM,WAAW,GAAG,IAAI,iCAAuB,CAAC,aAAa,CAAC,CAAC;QAC/D,MAAM,KAAK,GAAG,IAAI,mCAAqB,CACnC,aAAa,EACb,KAAK,EACL,gBAAgB,EAChB,WAAW,CACd,CAAC,KAAK,EAAE,CAAC;QACV,MAAM,MAAM,GAAkB;YAC1B,kBAAkB,EAAE,IAAI,GAAG,EAAE;YAC7B,cAAc,EAAE,KAAK,CAAC,MAAM;YAC5B,QAAQ,EAAE,KAAK,CAAC,MAAM;YACtB,eAAe,EAAE,IAAI,GAAG,CACpB,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;iBACd,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;iBAC3E,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAChC;YACD,kBAAkB,EAAE,EAAE;YACtB,uBAAuB,EAAE,WAAW,CAAC,GAAG,EAAE;YAC1C,uBAAuB,EAAE,WAAW,CAAC,uBAAuB,EAAE;YAC9D,mBAAmB,EAAE,WAAW,CAAC,gBAAgB,EAAE;YACnD,yBAAyB,EAAE,WAAW,CAAC,yBAAyB,EAAE;YAClE,4BAA4B,EAAE,WAAW,CAAC,4BAA4B,EAAE;YACxE,sBAAsB,EAAE,WAAW,CAAC,sBAAsB,EAAE;YAC5D,UAAU,EAAE,IAAI,+BAAa,CACzB,aAAa,EACb,KAAK,EACL,+BAAa,CAAC,UAAU,CAAC,aAAa,CAAC,CAC1C,CAAC,GAAG,EAAE;YACP,WAAW,EAAE,IAAI,oCAAe,CAC5B,aAAa,EACb,KAAK,EACL,MAAM,0BAAU,CAAC,UAAU,CAAC,aAAa,EAAE,4BAAY,CAAC,EACxD,MAAM,0BAAU,CAAC,UAAU,CAAC,aAAa,EAAE,wBAAQ,CAAC,EACpD,MAAM,8BAAe,CAAC,UAAU,CAAC,aAAa,CAAC,CAClD,CAAC,GAAG,EAAE;SACV,CAAC;QACF,IAAI,2CAAmB,EAAE,CAAC,MAAM,CAC5B,aAAa,EACb,KAAK,EACL,IAAA,+BAAiB,EAAC,MAAM,CAAC,EACzB,IAAA,uCAAoB,EAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAC5C,CAAC,CAAC,mEAAmE;QACtE,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAlDD,kDAkDC","sourcesContent":["import { ApiContractApproval } from './api-contract-approval';\nimport { buildExternalSystems } from './external-systems';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { ApiSourceIndexBuilder, buildApiContracts } from './api-scanner';\nimport { DecoratorArgDiagnostics } from './api-ast';\nimport { RootUnionRule, RootUnionScan } from './root-union-scan';\nimport { ApiDocRule, MCP_RULE, OPENAPI_RULE } from './api-doc-rules';\nimport { ApiDocRulesScan } from './api-doc-rules-scan';\nimport { WireClosureRule } from './wire-closure';\nimport type { ApiScanResult } from './api-scanner';\nimport type { ProjectInfo } from '../project-info';\n\n/** Build evidence for API/DTO correctness. No runtime relationship scan or project compiler loop. */\nexport class ApiContractEvidence {\n async collect(\n workspaceRoot: string,\n infos: Map<string, ProjectInfo>,\n externalApiPaths: readonly string[],\n ): Promise<ApiScanResult> {\n const diagnostics = new DecoratorArgDiagnostics(workspaceRoot);\n const index = new ApiSourceIndexBuilder(\n workspaceRoot,\n infos,\n externalApiPaths,\n diagnostics,\n ).build();\n const result: ApiScanResult = {\n relationsByProject: new Map(),\n apiLibProjects: index.owners,\n apiIndex: index.byName,\n scannedProjects: new Set(\n [...infos.values()]\n .filter((info) => fs.existsSync(path.join(workspaceRoot, info.root, 'src')))\n .map((info) => info.name),\n ),\n unresolvedApiCalls: [],\n nonLiteralDecoratorArgs: diagnostics.all(),\n unresolvedEndpointPaths: diagnostics.unresolvedEndpointPaths(),\n emptiedApiContracts: diagnostics.emptiedContracts(),\n undeclaredExternalCallers: diagnostics.undeclaredExternalCallers(),\n undeclaredEndpointOperations: diagnostics.undeclaredEndpointOperations(),\n voidResponseMismatches: diagnostics.voidResponseMismatches(),\n rootUnions: new RootUnionScan(\n workspaceRoot,\n infos,\n RootUnionRule.fromConfig(workspaceRoot),\n ).run(),\n apiDocRules: new ApiDocRulesScan(\n workspaceRoot,\n infos,\n await ApiDocRule.fromConfig(workspaceRoot, OPENAPI_RULE),\n await ApiDocRule.fromConfig(workspaceRoot, MCP_RULE),\n await WireClosureRule.fromConfig(workspaceRoot),\n ).run(),\n };\n new ApiContractApproval().verify(\n workspaceRoot,\n infos,\n buildApiContracts(result),\n buildExternalSystems(index.byName, infos),\n ); // Preserves the previous generator's API/DTO correctness failures.\n return result;\n }\n}\n"]}
1
+ {"version":3,"file":"api-contract-evidence.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/lib/api-usage/api-contract-evidence.ts"],"names":[],"mappings":";;;;AAAA,mEAA8D;AAC9D,yDAA0D;AAC1D,+CAAyB;AACzB,mDAA6B;AAC7B,+CAAyE;AACzE,uCAAoD;AACpD,uDAAiE;AACjE,mDAAqE;AACrE,6DAAuD;AACvD,iDAAiD;AAIjD,qGAAqG;AACrG,MAAa,mBAAmB;IAC5B,KAAK,CAAC,OAAO,CACT,aAAqB,EACrB,KAA+B,EAC/B,gBAAmC;QAEnC,MAAM,WAAW,GAAG,IAAI,iCAAuB,CAAC,aAAa,CAAC,CAAC;QAC/D,MAAM,KAAK,GAAG,IAAI,mCAAqB,CACnC,aAAa,EACb,KAAK,EACL,gBAAgB,EAChB,WAAW,CACd,CAAC,KAAK,EAAE,CAAC;QACV,MAAM,MAAM,GAAkB;YAC1B,kBAAkB,EAAE,IAAI,GAAG,EAAE;YAC7B,cAAc,EAAE,KAAK,CAAC,MAAM;YAC5B,QAAQ,EAAE,KAAK,CAAC,MAAM;YACtB,eAAe,EAAE,IAAI,GAAG,CACpB,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;iBACd,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;iBAC3E,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAChC;YACD,kBAAkB,EAAE,EAAE;YACtB,uBAAuB,EAAE,WAAW,CAAC,GAAG,EAAE;YAC1C,uBAAuB,EAAE,WAAW,CAAC,uBAAuB,EAAE;YAC9D,mBAAmB,EAAE,WAAW,CAAC,gBAAgB,EAAE;YACnD,yBAAyB,EAAE,WAAW,CAAC,yBAAyB,EAAE;YAClE,4BAA4B,EAAE,WAAW,CAAC,4BAA4B,EAAE;YACxE,sBAAsB,EAAE,WAAW,CAAC,sBAAsB,EAAE;YAC5D,aAAa,EAAE,WAAW,CAAC,aAAa,EAAE;YAC1C,UAAU,EAAE,IAAI,+BAAa,CACzB,aAAa,EACb,KAAK,EACL,+BAAa,CAAC,UAAU,CAAC,aAAa,CAAC,CAC1C,CAAC,GAAG,EAAE;YACP,WAAW,EAAE,IAAI,oCAAe,CAC5B,aAAa,EACb,KAAK,EACL,MAAM,0BAAU,CAAC,UAAU,CAAC,aAAa,EAAE,4BAAY,CAAC,EACxD,MAAM,0BAAU,CAAC,UAAU,CAAC,aAAa,EAAE,wBAAQ,CAAC,EACpD,MAAM,8BAAe,CAAC,UAAU,CAAC,aAAa,CAAC,CAClD,CAAC,GAAG,EAAE;SACV,CAAC;QACF,IAAI,2CAAmB,EAAE,CAAC,MAAM,CAC5B,aAAa,EACb,KAAK,EACL,IAAA,+BAAiB,EAAC,MAAM,CAAC,EACzB,IAAA,uCAAoB,EAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAC5C,CAAC,CAAC,mEAAmE;QACtE,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAnDD,kDAmDC","sourcesContent":["import { ApiContractApproval } from './api-contract-approval';\nimport { buildExternalSystems } from './external-systems';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { ApiSourceIndexBuilder, buildApiContracts } from './api-scanner';\nimport { DecoratorArgDiagnostics } from './api-ast';\nimport { RootUnionRule, RootUnionScan } from './root-union-scan';\nimport { ApiDocRule, MCP_RULE, OPENAPI_RULE } from './api-doc-rules';\nimport { ApiDocRulesScan } from './api-doc-rules-scan';\nimport { WireClosureRule } from './wire-closure';\nimport type { ApiScanResult } from './api-scanner';\nimport type { ProjectInfo } from '../project-info';\n\n/** Build evidence for API/DTO correctness. No runtime relationship scan or project compiler loop. */\nexport class ApiContractEvidence {\n async collect(\n workspaceRoot: string,\n infos: Map<string, ProjectInfo>,\n externalApiPaths: readonly string[],\n ): Promise<ApiScanResult> {\n const diagnostics = new DecoratorArgDiagnostics(workspaceRoot);\n const index = new ApiSourceIndexBuilder(\n workspaceRoot,\n infos,\n externalApiPaths,\n diagnostics,\n ).build();\n const result: ApiScanResult = {\n relationsByProject: new Map(),\n apiLibProjects: index.owners,\n apiIndex: index.byName,\n scannedProjects: new Set(\n [...infos.values()]\n .filter((info) => fs.existsSync(path.join(workspaceRoot, info.root, 'src')))\n .map((info) => info.name),\n ),\n unresolvedApiCalls: [],\n nonLiteralDecoratorArgs: diagnostics.all(),\n unresolvedEndpointPaths: diagnostics.unresolvedEndpointPaths(),\n emptiedApiContracts: diagnostics.emptiedContracts(),\n undeclaredExternalCallers: diagnostics.undeclaredExternalCallers(),\n undeclaredEndpointOperations: diagnostics.undeclaredEndpointOperations(),\n voidResponseMismatches: diagnostics.voidResponseMismatches(),\n additiveReads: diagnostics.additiveReads(),\n rootUnions: new RootUnionScan(\n workspaceRoot,\n infos,\n RootUnionRule.fromConfig(workspaceRoot),\n ).run(),\n apiDocRules: new ApiDocRulesScan(\n workspaceRoot,\n infos,\n await ApiDocRule.fromConfig(workspaceRoot, OPENAPI_RULE),\n await ApiDocRule.fromConfig(workspaceRoot, MCP_RULE),\n await WireClosureRule.fromConfig(workspaceRoot),\n ).run(),\n };\n new ApiContractApproval().verify(\n workspaceRoot,\n infos,\n buildApiContracts(result),\n buildExternalSystems(index.byName, infos),\n ); // Preserves the previous generator's API/DTO correctness failures.\n return result;\n }\n}\n"]}
@@ -370,6 +370,26 @@ export declare class VoidResponseMismatch {
370
370
  /** `path/to/file.ts:LINE`, workspace-relative. */
371
371
  at: string);
372
372
  }
373
+ /**
374
+ * ONE `@Endpoint` declaring operation READ with `{ additive }` (#1423) — a contradiction, since a read
375
+ * changes nothing to be additive about. `@Endpoint`'s overloads refuse it at compile time; this catches
376
+ * the source the type could not see (a JS caller, an `as` cast, a widened operation variable).
377
+ */
378
+ export declare class AdditiveReadEndpoint {
379
+ /** The contract class the method is declared on. */
380
+ readonly api: string;
381
+ /** The method name. */
382
+ readonly method: string;
383
+ /** `path/to/file.ts:LINE`, workspace-relative. */
384
+ readonly at: string;
385
+ constructor(
386
+ /** The contract class the method is declared on. */
387
+ api: string,
388
+ /** The method name. */
389
+ method: string,
390
+ /** `path/to/file.ts:LINE`, workspace-relative. */
391
+ at: string);
392
+ }
373
393
  /** ONE `@Endpoint` whose required side-effect declaration could not be read from source. */
374
394
  export declare class UndeclaredEndpointOperation {
375
395
  /** The contract class the method is declared on. */
@@ -15,7 +15,7 @@
15
15
  * only as binding identifiers, not as member names).
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.EmptiedApiContract = exports.UndeclaredEndpointOperation = exports.VoidResponseMismatch = exports.VoidResponseProblem = exports.UndeclaredExternalCaller = exports.UnresolvedEndpointPath = exports.NonLiteralDecoratorArg = exports.UnresolvedApiCall = exports.CONTRACT_HTTP_METHODS = exports.EXTERNAL_SYSTEM_KINDS = void 0;
18
+ exports.EmptiedApiContract = exports.UndeclaredEndpointOperation = exports.AdditiveReadEndpoint = exports.VoidResponseMismatch = exports.VoidResponseProblem = exports.UndeclaredExternalCaller = exports.UnresolvedEndpointPath = exports.NonLiteralDecoratorArg = exports.UnresolvedApiCall = exports.CONTRACT_HTTP_METHODS = exports.EXTERNAL_SYSTEM_KINDS = void 0;
19
19
  exports.isExternalSystemKind = isExternalSystemKind;
20
20
  exports.apiRefKey = apiRefKey;
21
21
  exports.contractVerbCarriesBody = contractVerbCarriesBody;
@@ -235,6 +235,28 @@ class VoidResponseMismatch {
235
235
  }
236
236
  }
237
237
  exports.VoidResponseMismatch = VoidResponseMismatch;
238
+ /**
239
+ * ONE `@Endpoint` declaring operation READ with `{ additive }` (#1423) — a contradiction, since a read
240
+ * changes nothing to be additive about. `@Endpoint`'s overloads refuse it at compile time; this catches
241
+ * the source the type could not see (a JS caller, an `as` cast, a widened operation variable).
242
+ */
243
+ class AdditiveReadEndpoint {
244
+ api;
245
+ method;
246
+ at;
247
+ constructor(
248
+ /** The contract class the method is declared on. */
249
+ api,
250
+ /** The method name. */
251
+ method,
252
+ /** `path/to/file.ts:LINE`, workspace-relative. */
253
+ at) {
254
+ this.api = api;
255
+ this.method = method;
256
+ this.at = at;
257
+ }
258
+ }
259
+ exports.AdditiveReadEndpoint = AdditiveReadEndpoint;
238
260
  /** ONE `@Endpoint` whose required side-effect declaration could not be read from source. */
239
261
  class UndeclaredEndpointOperation {
240
262
  api;
@@ -1 +1 @@
1
- {"version":3,"file":"api-relations.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/nx-webpieces-rules/src/lib/api-usage/api-relations.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAiDH,oDAEC;AA0DD,8BAEC;AAkCD,0DAEC;AA+QD,sDAOC;AAOD,kCAMC;AAxaD;;;;;;GAMG;AACU,QAAA,qBAAqB,GAAG;IACjC,UAAU;IACV,OAAO;IACP,OAAO;IACP,SAAS;IACT,MAAM;IACN,QAAQ;IACR;;;;;;;;;;;;;OAaG;IACH,SAAS;CACH,CAAC;AAIX,yEAAyE;AACzE,sHAAsH;AACtH,SAAgB,oBAAoB,CAAC,KAAa;IAC9C,OAAQ,6BAA2C,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxE,CAAC;AAqDD;;;GAGG;AACH,+FAA+F;AAC/F,SAAgB,SAAS,CAAC,GAAW;IACjC,OAAO,GAAG,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,aAAa,IAAI,EAAE,EAAE,CAAC;AACnD,CAAC;AA6BD,4EAA4E;AAC/D,QAAA,qBAAqB,GAAkC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AAE9G,0GAA0G;AAC1G,6FAA6F;AAC7F,SAAgB,uBAAuB,CAAC,MAA0B;IAC9D,OAAO,MAAM,KAAK,MAAM,IAAI,M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AACH,MAAa,kBAAkB;IAGP;IAEA;IAEA;IANpB;IACI,+BAA+B;IACf,GAAW;IAC3B,0DAA0D;IAC1C,QAAgB;IAChC,+DAA+D;IAC/C,EAAU;QAJV,QAAG,GAAH,GAAG,CAAQ;QAEX,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,OAAE,GAAF,EAAE,CAAQ;IAC3B,CAAC;CACP;AATD,gDASC;AAED,oFAAoF;AACpF,+FAA+F;AAC/F,SAAgB,qBAAqB,CACjC,cAAwB,EACxB,QAAkB;IAElB,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,iBAAiB,CAAC;IAC/E,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,YAAY,CAAC;IACnD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,+FAA+F;AAC/F,SAAgB,WAAW,CAAC,IAAc;IACtC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CACjB,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CACrB,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC;QAC1B,CAAC,CAAC,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,IAAI,EAAE,CAAC,CACnE,CAAC;AACN,CAAC","sourcesContent":["/**\n * API Relations model\n *\n * The typed classification of a compile-time dependency edge P -> apiLib in\n * architecture/dependencies.json. Where the flat `dependsOn` only says \"P depends\n * on apiLib\", `apiRelations[apiLib]` says WHY: which API contracts P IMPLEMENTS\n * (serves, `class Ctrl extends XxxApi`) and which it USES (calls as a client,\n * `factory.createRpcClient(XxxApi, ...)` / `createPubSubClient(...)`), each tagged\n * with its transport.\n *\n * Interfaces + object literals here mirror the sibling runtime-graph.ts model —\n * these are serialization DTOs written verbatim into the committed JSON, and\n * `implements`/`uses` are legal interface property names (they are reserved words\n * only as binding identifiers, not as member names).\n */\n\n/**\n * Transport of an API contract:\n * - `rpc` — synchronous request/response over HTTP\n * - `pubsub` — fire-and-forget, delivered later through a Cloud Tasks queue\n * - `external` — a contract for a system OUTSIDE this repo (firestore, gmail, ...). Nothing in-repo\n * implements it, so it never becomes a service→service edge; it terminates the graph\n * at a dashed vendor node. Detected from `runtime-architecture.externalApiPaths`\n * rather than from a decorator, because a vendor contract is a plain interface bound\n * to a Symbol token, not an `abstract class` carrying @ApiPath.\n */\nexport type ApiTransport = 'rpc' | 'pubsub' | 'external';\n\n/**\n * The kinds an external system can be DECLARED as. Each draws its own shape in the runtime viz, so\n * a datastore stops looking like an HTTP service.\n *\n * Lives here rather than beside the runtime graph model because that model already imports from this\n * file; putting it there and importing back would close a module cycle.\n */\nexport const EXTERNAL_SYSTEM_KINDS = [\n 'database',\n 'cache',\n 'queue',\n 'storage',\n 'saas',\n 'system',\n /**\n * A destination whose ADDRESS is supplied at runtime — a URL a partner registered, an OAuth\n * callback, a per-tenant host. Unlike every other kind it does not name one vendor: it names the\n * PLACE in our own system where somebody else's address is dialled, which is the fact a security\n * review is looking for.\n *\n * Declared like every other kind, on the CONTRACT: `@externalSystem runtime partner-webhooks`.\n * On the contract rather than at a `createRpcClient` call site deliberately — \"the far end of\n * this contract is outside our estate\" is a property of the CONTRACT, true for every caller of\n * it, so putting it there means one declaration however many services deliver over it, and\n * nothing to keep in step when a second one appears. It also means this kind rides the exact\n * same declare → resolve → draw pipeline `saas` and `database` already ride, rather than a\n * second mechanism that reads construction sites and can disagree with the first.\n */\n 'runtime',\n] as const;\n\nexport type ExternalSystemKind = (typeof EXTERNAL_SYSTEM_KINDS)[number];\n\n/** True for a string that names one of {@link EXTERNAL_SYSTEM_KINDS}. */\n// webpieces-disable no-function-outside-class -- type guard beside the type it guards, matching this file's DTO style\nexport function isExternalSystemKind(value: string): value is ExternalSystemKind {\n return (EXTERNAL_SYSTEM_KINDS as readonly string[]).includes(value);\n}\n\n/**\n * ONE declared external system, keyed in {@link ExternalSystemDecls} by its IDENTITY.\n *\n * Identity, not display text: two projects each tagged `external:database:postgres` name the same\n * `postgres` node and converge on it with one arrow apiece, instead of drawing a database each.\n *\n * The two arrays are the two declaration sites, and a system may legitimately have both — a repo can\n * wrap a datastore behind a contract in one service and open it directly in another.\n */\nexport interface ExternalSystemDecl {\n kind: ExternalSystemKind;\n label: string;\n /** Contracts declaring it with an `@externalSystem` JSDoc tag; every user of one gets an arrow. */\n apis: string[];\n /** Projects declaring it with an `external:<kind>:<identity>` nx tag; each gets its OWN arrow. */\n projects: string[];\n}\n\n/** identity -> its declaration. Serialized as the `externalSystems` key of dependencies.json. */\nexport type ExternalSystemDecls = Record<string, ExternalSystemDecl>;\n\n/**\n * How a project relates to ONE api-lib it depends on:\n * - `implements` — it serves the api (a controller extends it)\n * - `uses` — it calls the api (generates a client)\n * - `uses-implements` — it does BOTH (implements some of the api-lib's contracts,\n * uses others)\n */\nexport type ApiRelationKind = 'implements' | 'uses' | 'uses-implements';\n\n/** One API class a project implements or uses, with its transport. */\nexport interface ApiRef {\n api: string;\n type: ApiTransport;\n /**\n * ONLY on a `uses` ref: the service the call site aims at, read from the client config literal\n * (`createRpcClient(XxxApi, new ClientConfig('helper-fsdb'))` → `helper-fsdb`). It is matched\n * against a project's DECLARED `serviceName` to pick the ONE runtime edge target, instead of\n * fanning the edge out to every implementer of the api — which is catastrophically wrong for a\n * company-wide contract registered in a shared library and therefore implemented by every server.\n *\n * Absent when the config argument is not a `new <Xxx>ClientConfig('<literal>')` (a variable, a\n * computed name, ...). Absent means \"unknown target\", NOT \"no target\" — the runtime graph then\n * falls back to the old fan-out and says so out loud.\n */\n targetService?: string;\n /** Qualified selected library export that contributed this relationship. */\n declaredVia?: string;\n conditional?: string;\n}\n\n/**\n * Identity of a ref for de-duplication: an api used twice against DIFFERENT services is two distinct\n * relations (two distinct runtime edges), so the api name alone is not the key.\n */\n// webpieces-disable no-function-outside-class -- pure data helper for these serialization DTOs\nexport function apiRefKey(ref: ApiRef): string {\n return `${ref.api} ${ref.targetService ?? ''}`;\n}\n\n/**\n * A project's relationship to ONE api-lib it depends on. Serialized verbatim into\n * architecture/dependencies.json under `apiRelations[apiLibProjectName]`.\n */\nexport interface ApiRelation {\n kind: ApiRelationKind;\n implements: ApiRef[];\n uses: ApiRef[];\n}\n\n/** apiLibProjectName -> relation. Attached to a GraphEntry as `apiRelations`. */\nexport type ProjectApiRelations = Record<string, ApiRelation>;\n\n/**\n * What triggers ONE endpoint, mirroring core-util's `EndpointKind`. Duplicated as a string union\n * rather than imported: nx-webpieces-rules is build tooling and must not take a runtime dependency\n * on the framework it inspects (it reads decorators as TEXT, from projects that may be on a\n * different @webpieces version than the tooling itself).\n */\nexport type EndpointKind = 'rpc' | 'cloudtasks' | 'cron' | 'external-inbound' | 'external-outbound';\n\n/** Side-effect semantics copied from the required third `@Endpoint` argument. */\nexport type EndpointOperation = 'read' | 'write-idempotent' | 'write';\n\n/** HTTP verbs understood by the generated contract runtime. */\nexport type ContractHttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n\n/** Every verb `@Endpoint` accepts, mirroring core-util's `HTTP_METHODS`. */\nexport const CONTRACT_HTTP_METHODS: readonly ContractHttpMethod[] = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];\n\n/** Mirrors core-util's `verbCarriesBody`: POST, PUT and PATCH carry the one unannotated body argument. */\n// webpieces-disable no-function-outside-class -- pure predicate mirroring the framework rule\nexport function contractVerbCarriesBody(method: ContractHttpMethod): boolean {\n return method === 'POST' || method === 'PUT' || method === 'PATCH';\n}\n\n/** One path/query/body mapping emitted into architecture/dependencies.json. */\nexport interface ApiParameterMeta {\n index: number;\n source: 'path' | 'query' | 'query-map' | 'body';\n /** Path/query wire name; a JSON/form body and a `@QueryString()` multimap have no key. */\n wireName?: string;\n}\n\n/**\n * One method on an API contract, as written in source: what triggers it, where it is mounted, and\n * (for a queued method) which Cloud Tasks queue delivers it.\n */\nexport interface ApiMethodMeta {\n name: string;\n /** The @Endpoint path, relative to the class's @ApiPath basePath. */\n path: string;\n kind: EndpointKind;\n /** Retry/idempotency contract; independent of the HTTP verb. */\n operation: EndpointOperation;\n /** Required in newly scanned source; optional only when reading older committed graph data. */\n httpMethod?: ContractHttpMethod;\n /** Explicit parameter mappings; absent only when the method has none. */\n parameters?: ApiParameterMeta[];\n /** Present when callers receive the transport-neutral full response. */\n responseType?: 'full';\n /**\n * Present when `@Endpoint(..., { responseBody: NONE })`: a `Promise<void>` method, 0-byte success.\n * Absent on a CLOUDTASKS / CRON method, whose KIND already means no response body (#1348).\n */\n responseBody?: 'none';\n /**\n * `@Queue(...)` override, else `${ApiClassName}-${methodName}`.\n *\n * ONLY on a `cloudtasks` or `cron` method — those are the kinds actually delivered through a\n * named queue or schedule, and Terraform matches on this string. A synchronous `rpc` (or an\n * `external-inbound`) endpoint has no queue and needs none; emitting a plausible-looking name for\n * one put every synchronous endpoint one naive `methods.map(m => m.queueName)` away from being\n * provisioned as a queue.\n */\n queueName?: string;\n /**\n * WHO outside this repo drives this endpoint, from `@Endpoint(POST, p, WRITE, EXTERNAL_INBOUND, { calledBy })`.\n *\n * ONLY on an `external-inbound` method, the same way `queueName` is only on the kinds that HAVE a queue.\n *\n * Deliberately the SAME {@link ExternalSystemDeclaration} the OUTBOUND `@externalSystem` tag\n * resolves to, not a parallel inbound-only type: an inbound `saas twilio` and an outbound\n * `saas twilio` are the same vendor, so sharing the type makes them share an IDENTITY and\n * converge on ONE node instead of drawing twilio twice facing opposite directions.\n *\n * Optional in the TYPE only for graphs generated before the caller was required — generation\n * FAILS on an `external-inbound` method whose caller cannot be read (UndeclaredExternalCallerError).\n */\n caller?: ExternalSystemDeclaration;\n}\n\n/**\n * A discovered API contract class: its name, the api-lib project that owns it, its transport, and\n * its per-method trigger table.\n */\nexport interface ApiClassInfo {\n api: string;\n owner: string;\n type: ApiTransport;\n /** The class's @ApiPath basePath; absent for an external (vendor) contract, which has no route. */\n basePath?: string;\n /**\n * Every @Endpoint method, in declaration order. Empty for an external contract (a vendor\n * interface has no endpoints — it is called through a vendor SDK, not mounted).\n */\n methods: ApiMethodMeta[];\n /**\n * Set when the contract carries an `@externalSystem <kind> [label]` JSDoc tag — a vendor seam\n * declaring WHAT it is a seam to. JSDoc rather than a decorator because these seams are plain TS\n * `interface`s, which cannot carry one.\n */\n externalSystem?: ExternalSystemDeclaration;\n}\n\n/** The `(kind, label)` pair a single declaration resolves to. */\nexport interface ExternalSystemDeclaration {\n kind: ExternalSystemKind;\n label: string;\n}\n\n/**\n * The committed, per-contract view written to `architecture/apis/<ApiName>.json` (one file per API;\n * dependencies.json only links to it under `apiContractFiles` — see ApiContractFiles).\n *\n * The runtime graph is derived from the committed files so generate and validate can never\n * diverge — which means anything the runtime graph needs must be COMMITTED, not re-scanned.\n * Per-method trigger kinds and queue names are exactly that: without this table the derivation\n * cannot tell a queued endpoint from a cron sweep, and cannot name the queue between two services.\n */\nexport interface ApiContract {\n owner: string;\n /** 'rpc' | 'pubsub' for an in-repo contract, 'external' for a vendor seam. */\n apiKind: ApiTransport;\n /**\n * REQUIRED. Every routed contract carries `@ApiPath`, so every entry in this table must carry the\n * base path its methods hang off. Optional was worse than absent: a consumer joining\n * `basePath + path` for the ONE entry that lost it computed `/test` where the real route was\n * `/whatsapp/test`, and had no reason to suspect it — every other entry had the field. Generation\n * now FAILS instead of shipping an entry that computes a confidently wrong URL.\n */\n basePath: string;\n methods: ApiMethodMeta[];\n}\n\n/** apiClassName -> its committed contract. Serialized as one `architecture/apis/<ApiName>.json` each. */\nexport type ApiContracts = Record<string, ApiContract>;\n\n/**\n * An `addRoutes`/`createRpcClient`/`createPubSubClient` first argument that resolved to an\n * abstract class in a DECLARATION file which owns no indexed contract. Unambiguously a broken\n * scan (a real api-lib whose source we never indexed), never a \"this isn't an API\" argument —\n * so it is reported loudly instead of collapsing into a silent `return null`.\n */\nexport class UnresolvedApiCall {\n constructor(\n /** The project whose source makes the call. */\n public readonly project: string,\n /** The contract class name as written at the call site. */\n public readonly api: string,\n /** `path/to/file.ts:LINE` of the call site, workspace-relative. */\n public readonly at: string,\n /** The declaration file the checker resolved to (where decorators are erased). */\n public readonly declaredIn: string,\n ) {}\n}\n\n/**\n * ONE decorator argument the scan saw but could not reduce to a string — `@ApiPath(SOME_CONST)`\n * where SOME_CONST is imported from another module, a computed expression, an enum member, ...\n *\n * Recorded rather than dropped. Before this existed, an unresolvable argument cost the contract its\n * basePath, or a method, or (when EVERY method's path was one) the whole class — with nothing\n * printed anywhere. Same-module constants now resolve, so what remains here is the genuinely\n * unresolvable, which the author can fix by inlining the literal or moving the constant in-module.\n */\nexport class NonLiteralDecoratorArg {\n constructor(\n /** The contract class the argument was written on. */\n public readonly api: string,\n /** `ApiPath` | `Endpoint` | `Queue`. */\n public readonly decorator: string,\n /** The method name for a member decorator, null for a class decorator. */\n public readonly method: string | null,\n /** The argument exactly as written, e.g. `WHATSAPP_API_PATH`. */\n public readonly argument: string,\n /** `path/to/file.ts:LINE`, workspace-relative. */\n public readonly at: string,\n ) {}\n}\n\n/**\n * ONE `@Endpoint(path, kind)` whose PATH argument was present but could not be reduced to a string.\n *\n * Split out of NonLiteralDecoratorArg (which stays a warning, covering @Queue and the rest) because\n * this one is FATAL. Upstream components need the URL: an http client builds its request as\n * `basePath + path`, so an unreadable path is missing ROUTING, not missing metadata — the same\n * reasoning that already makes basePath required. Skipping the method instead used to delete it, and\n * a class whose every path was a constant lost every method and vanished from the contract table with\n * nothing printed anywhere.\n */\nexport class UnresolvedEndpointPath {\n constructor(\n /** The contract class the method is declared on. */\n public readonly api: string,\n /** The method name. */\n public readonly method: string,\n /** The path argument exactly as written, e.g. `PROCESS_PATH`. */\n public readonly argument: string,\n /** `path/to/file.ts:LINE`, workspace-relative. */\n public readonly at: string,\n ) {}\n}\n\n/**\n * ONE `external` `@Endpoint` whose CALLER could not be read from the source.\n *\n * Fatal for the same reason {@link UnresolvedEndpointPath} is. The inbound box exists to say who is\n * calling us from outside; with no caller it can only restate our own contract name, which is the\n * exact bug this diagnostic exists to make impossible to reintroduce. `@Endpoint`'s TS overloads\n * already require `calledBy`, so anything reaching here is a JS caller, an `as any`, a cross-module\n * constant the parser-only scan cannot fold, or an unknown `callerKind`.\n */\nexport class UndeclaredExternalCaller {\n constructor(\n /** The contract class the method is declared on. */\n public readonly api: string,\n /** The method name. */\n public readonly method: string,\n /** What was wrong, as written — `<missing>`, `SOME_CONST`, `callerKind: 'vendor'`. */\n public readonly argument: string,\n /** `path/to/file.ts:LINE`, workspace-relative. */\n public readonly at: string,\n ) {}\n}\n\n/** What is wrong with one endpoint's response-body declaration (#1339, #1348). */\nexport enum VoidResponseProblem {\n /** RPC / EXTERNAL_INBOUND: declares `responseBody: NONE` but does not return `Promise<void>`. */\n NONE_WITHOUT_VOID = 'none-without-void',\n /** RPC / EXTERNAL_INBOUND: returns `Promise<void>` but does not declare `responseBody: NONE`. */\n VOID_WITHOUT_NONE = 'void-without-none',\n /** EXTERNAL_OUTBOUND: declares `responseBody: NONE`, but the VENDOR shapes an outbound response. */\n OUTBOUND_NONE = 'outbound-none',\n /** CLOUDTASKS / CRON: declares `responseBody: NONE`, which the kind already implies. */\n REDUNDANT_NONE = 'redundant-none',\n /** CLOUDTASKS / CRON: does not return `Promise<void>`, but the kind is fire-and-forget. */\n TRIGGER_NOT_VOID = 'trigger-not-void',\n}\n\n/**\n * An `@Endpoint` whose response-body declaration disagrees with its kind or its declared return\n * type. The runtime cannot see `void` (`design:returntype` is just `Promise`), so the kind (CLOUDTASKS\n * and CRON imply no body, #1348) or the `responseBody: NONE` option (RPC, EXTERNAL_INBOUND) is the\n * only thing a server and a client act on, and it must not drift from the signature. EXTERNAL_OUTBOUND\n * takes no option at all: the vendor shapes its responses and the client accepts any 2xx.\n */\nexport class VoidResponseMismatch {\n constructor(\n public readonly api: string,\n public readonly method: string,\n /** Which of the five disagreements this is. */\n public readonly problem: VoidResponseProblem,\n /** The endpoint kind as written in the graph (`rpc`, `cloudtasks`, ...). */\n public readonly kind: EndpointKind,\n /** `path/to/file.ts:LINE`, workspace-relative. */\n public readonly at: string,\n ) {}\n}\n\n/** ONE `@Endpoint` whose required side-effect declaration could not be read from source. */\nexport class UndeclaredEndpointOperation {\n constructor(\n /** The contract class the method is declared on. */\n public readonly api: string,\n /** The method name. */\n public readonly method: string,\n /** What was wrong, as written — `<missing>`, a constant name, or an invalid literal. */\n public readonly argument: string,\n /** `path/to/file.ts:LINE`, workspace-relative. */\n public readonly at: string,\n ) {}\n}\n\n/**\n * A contract class that DECLARED `@Endpoint` methods and kept none of them.\n *\n * The backstop for the mechanism that hid an entire service: `buildApiContracts` skips a zero-method\n * class (correctly — a vendor seam has no routes), so a class gutted by unreadable decorator\n * arguments left through the same door as a legitimately routeless one. A class that declared\n * endpoints and produced none is never legitimate, so it is named instead.\n */\nexport class EmptiedApiContract {\n constructor(\n /** The contract class name. */\n public readonly api: string,\n /** How many `@Endpoint` decorators were written on it. */\n public readonly declared: number,\n /** `path/to/file.ts:LINE` of the class, workspace-relative. */\n public readonly at: string,\n ) {}\n}\n\n/** Derive the relation kind from the (possibly empty) implements/uses ref lists. */\n// webpieces-disable no-function-outside-class -- pure data helper for these serialization DTOs\nexport function deriveApiRelationKind(\n implementsRefs: ApiRef[],\n usesRefs: ApiRef[],\n): ApiRelationKind {\n if (implementsRefs.length > 0 && usesRefs.length > 0) return 'uses-implements';\n if (implementsRefs.length > 0) return 'implements';\n return 'uses';\n}\n\n/**\n * Stable-sort a ref list by api name, then by target service, so the committed JSON is\n * deterministic even when one api is used against two different services.\n */\n// webpieces-disable no-function-outside-class -- pure data helper for these serialization DTOs\nexport function sortApiRefs(refs: ApiRef[]): ApiRef[] {\n return [...refs].sort(\n (a: ApiRef, b: ApiRef) =>\n a.api.localeCompare(b.api) ||\n (a.targetService ?? '').localeCompare(b.targetService ?? ''),\n );\n}\n"]}
1
+ {"version":3,"file":"api-relations.js","sourceRoot":"","sources":["../../../../../../../packages/tooling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AG,CAAQ;QAEX,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,OAAE,GAAF,EAAE,CAAQ;IAC3B,CAAC;CACP;AATD,gDASC;AAED,oFAAoF;AACpF,+FAA+F;AAC/F,SAAgB,qBAAqB,CACjC,cAAwB,EACxB,QAAkB;IAElB,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,iBAAiB,CAAC;IAC/E,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,YAAY,CAAC;IACnD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,+FAA+F;AAC/F,SAAgB,WAAW,CAAC,IAAc;IACtC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CACjB,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CACrB,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC;QAC1B,CAAC,CAAC,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,IAAI,EAAE,CAAC,CACnE,CAAC;AACN,CAAC","sourcesContent":["/**\n * API Relations model\n *\n * The typed classification of a compile-time dependency edge P -> apiLib in\n * architecture/dependencies.json. Where the flat `dependsOn` only says \"P depends\n * on apiLib\", `apiRelations[apiLib]` says WHY: which API contracts P IMPLEMENTS\n * (serves, `class Ctrl extends XxxApi`) and which it USES (calls as a client,\n * `factory.createRpcClient(XxxApi, ...)` / `createPubSubClient(...)`), each tagged\n * with its transport.\n *\n * Interfaces + object literals here mirror the sibling runtime-graph.ts model —\n * these are serialization DTOs written verbatim into the committed JSON, and\n * `implements`/`uses` are legal interface property names (they are reserved words\n * only as binding identifiers, not as member names).\n */\n\n/**\n * Transport of an API contract:\n * - `rpc` — synchronous request/response over HTTP\n * - `pubsub` — fire-and-forget, delivered later through a Cloud Tasks queue\n * - `external` — a contract for a system OUTSIDE this repo (firestore, gmail, ...). Nothing in-repo\n * implements it, so it never becomes a service→service edge; it terminates the graph\n * at a dashed vendor node. Detected from `runtime-architecture.externalApiPaths`\n * rather than from a decorator, because a vendor contract is a plain interface bound\n * to a Symbol token, not an `abstract class` carrying @ApiPath.\n */\nexport type ApiTransport = 'rpc' | 'pubsub' | 'external';\n\n/**\n * The kinds an external system can be DECLARED as. Each draws its own shape in the runtime viz, so\n * a datastore stops looking like an HTTP service.\n *\n * Lives here rather than beside the runtime graph model because that model already imports from this\n * file; putting it there and importing back would close a module cycle.\n */\nexport const EXTERNAL_SYSTEM_KINDS = [\n 'database',\n 'cache',\n 'queue',\n 'storage',\n 'saas',\n 'system',\n /**\n * A destination whose ADDRESS is supplied at runtime — a URL a partner registered, an OAuth\n * callback, a per-tenant host. Unlike every other kind it does not name one vendor: it names the\n * PLACE in our own system where somebody else's address is dialled, which is the fact a security\n * review is looking for.\n *\n * Declared like every other kind, on the CONTRACT: `@externalSystem runtime partner-webhooks`.\n * On the contract rather than at a `createRpcClient` call site deliberately — \"the far end of\n * this contract is outside our estate\" is a property of the CONTRACT, true for every caller of\n * it, so putting it there means one declaration however many services deliver over it, and\n * nothing to keep in step when a second one appears. It also means this kind rides the exact\n * same declare → resolve → draw pipeline `saas` and `database` already ride, rather than a\n * second mechanism that reads construction sites and can disagree with the first.\n */\n 'runtime',\n] as const;\n\nexport type ExternalSystemKind = (typeof EXTERNAL_SYSTEM_KINDS)[number];\n\n/** True for a string that names one of {@link EXTERNAL_SYSTEM_KINDS}. */\n// webpieces-disable no-function-outside-class -- type guard beside the type it guards, matching this file's DTO style\nexport function isExternalSystemKind(value: string): value is ExternalSystemKind {\n return (EXTERNAL_SYSTEM_KINDS as readonly string[]).includes(value);\n}\n\n/**\n * ONE declared external system, keyed in {@link ExternalSystemDecls} by its IDENTITY.\n *\n * Identity, not display text: two projects each tagged `external:database:postgres` name the same\n * `postgres` node and converge on it with one arrow apiece, instead of drawing a database each.\n *\n * The two arrays are the two declaration sites, and a system may legitimately have both — a repo can\n * wrap a datastore behind a contract in one service and open it directly in another.\n */\nexport interface ExternalSystemDecl {\n kind: ExternalSystemKind;\n label: string;\n /** Contracts declaring it with an `@externalSystem` JSDoc tag; every user of one gets an arrow. */\n apis: string[];\n /** Projects declaring it with an `external:<kind>:<identity>` nx tag; each gets its OWN arrow. */\n projects: string[];\n}\n\n/** identity -> its declaration. Serialized as the `externalSystems` key of dependencies.json. */\nexport type ExternalSystemDecls = Record<string, ExternalSystemDecl>;\n\n/**\n * How a project relates to ONE api-lib it depends on:\n * - `implements` — it serves the api (a controller extends it)\n * - `uses` — it calls the api (generates a client)\n * - `uses-implements` — it does BOTH (implements some of the api-lib's contracts,\n * uses others)\n */\nexport type ApiRelationKind = 'implements' | 'uses' | 'uses-implements';\n\n/** One API class a project implements or uses, with its transport. */\nexport interface ApiRef {\n api: string;\n type: ApiTransport;\n /**\n * ONLY on a `uses` ref: the service the call site aims at, read from the client config literal\n * (`createRpcClient(XxxApi, new ClientConfig('helper-fsdb'))` → `helper-fsdb`). It is matched\n * against a project's DECLARED `serviceName` to pick the ONE runtime edge target, instead of\n * fanning the edge out to every implementer of the api — which is catastrophically wrong for a\n * company-wide contract registered in a shared library and therefore implemented by every server.\n *\n * Absent when the config argument is not a `new <Xxx>ClientConfig('<literal>')` (a variable, a\n * computed name, ...). Absent means \"unknown target\", NOT \"no target\" — the runtime graph then\n * falls back to the old fan-out and says so out loud.\n */\n targetService?: string;\n /** Qualified selected library export that contributed this relationship. */\n declaredVia?: string;\n conditional?: string;\n}\n\n/**\n * Identity of a ref for de-duplication: an api used twice against DIFFERENT services is two distinct\n * relations (two distinct runtime edges), so the api name alone is not the key.\n */\n// webpieces-disable no-function-outside-class -- pure data helper for these serialization DTOs\nexport function apiRefKey(ref: ApiRef): string {\n return `${ref.api} ${ref.targetService ?? ''}`;\n}\n\n/**\n * A project's relationship to ONE api-lib it depends on. Serialized verbatim into\n * architecture/dependencies.json under `apiRelations[apiLibProjectName]`.\n */\nexport interface ApiRelation {\n kind: ApiRelationKind;\n implements: ApiRef[];\n uses: ApiRef[];\n}\n\n/** apiLibProjectName -> relation. Attached to a GraphEntry as `apiRelations`. */\nexport type ProjectApiRelations = Record<string, ApiRelation>;\n\n/**\n * What triggers ONE endpoint, mirroring core-util's `EndpointKind`. Duplicated as a string union\n * rather than imported: nx-webpieces-rules is build tooling and must not take a runtime dependency\n * on the framework it inspects (it reads decorators as TEXT, from projects that may be on a\n * different @webpieces version than the tooling itself).\n */\nexport type EndpointKind = 'rpc' | 'cloudtasks' | 'cron' | 'external-inbound' | 'external-outbound';\n\n/** Side-effect semantics copied from the required third `@Endpoint` argument. */\nexport type EndpointOperation = 'read' | 'write-idempotent' | 'write';\n\n/** HTTP verbs understood by the generated contract runtime. */\nexport type ContractHttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n\n/** Every verb `@Endpoint` accepts, mirroring core-util's `HTTP_METHODS`. */\nexport const CONTRACT_HTTP_METHODS: readonly ContractHttpMethod[] = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];\n\n/** Mirrors core-util's `verbCarriesBody`: POST, PUT and PATCH carry the one unannotated body argument. */\n// webpieces-disable no-function-outside-class -- pure predicate mirroring the framework rule\nexport function contractVerbCarriesBody(method: ContractHttpMethod): boolean {\n return method === 'POST' || method === 'PUT' || method === 'PATCH';\n}\n\n/** One path/query/body mapping emitted into architecture/dependencies.json. */\nexport interface ApiParameterMeta {\n index: number;\n source: 'path' | 'query' | 'query-map' | 'body';\n /** Path/query wire name; a JSON/form body and a `@QueryString()` multimap have no key. */\n wireName?: string;\n}\n\n/**\n * One method on an API contract, as written in source: what triggers it, where it is mounted, and\n * (for a queued method) which Cloud Tasks queue delivers it.\n */\nexport interface ApiMethodMeta {\n name: string;\n /** The @Endpoint path, relative to the class's @ApiPath basePath. */\n path: string;\n kind: EndpointKind;\n /** Retry/idempotency contract; independent of the HTTP verb. */\n operation: EndpointOperation;\n /** Required in newly scanned source; optional only when reading older committed graph data. */\n httpMethod?: ContractHttpMethod;\n /** Explicit parameter mappings; absent only when the method has none. */\n parameters?: ApiParameterMeta[];\n /** Present when callers receive the transport-neutral full response. */\n responseType?: 'full';\n /**\n * Present when `@Endpoint(..., { responseBody: NONE })`: a `Promise<void>` method, 0-byte success.\n * Absent on a CLOUDTASKS / CRON method, whose KIND already means no response body (#1348).\n */\n responseBody?: 'none';\n /**\n * `@Queue(...)` override, else `${ApiClassName}-${methodName}`.\n *\n * ONLY on a `cloudtasks` or `cron` method — those are the kinds actually delivered through a\n * named queue or schedule, and Terraform matches on this string. A synchronous `rpc` (or an\n * `external-inbound`) endpoint has no queue and needs none; emitting a plausible-looking name for\n * one put every synchronous endpoint one naive `methods.map(m => m.queueName)` away from being\n * provisioned as a queue.\n */\n queueName?: string;\n /**\n * WHO outside this repo drives this endpoint, from `@Endpoint(POST, p, WRITE, EXTERNAL_INBOUND, { calledBy })`.\n *\n * ONLY on an `external-inbound` method, the same way `queueName` is only on the kinds that HAVE a queue.\n *\n * Deliberately the SAME {@link ExternalSystemDeclaration} the OUTBOUND `@externalSystem` tag\n * resolves to, not a parallel inbound-only type: an inbound `saas twilio` and an outbound\n * `saas twilio` are the same vendor, so sharing the type makes them share an IDENTITY and\n * converge on ONE node instead of drawing twilio twice facing opposite directions.\n *\n * Optional in the TYPE only for graphs generated before the caller was required — generation\n * FAILS on an `external-inbound` method whose caller cannot be read (UndeclaredExternalCallerError).\n */\n caller?: ExternalSystemDeclaration;\n}\n\n/**\n * A discovered API contract class: its name, the api-lib project that owns it, its transport, and\n * its per-method trigger table.\n */\nexport interface ApiClassInfo {\n api: string;\n owner: string;\n type: ApiTransport;\n /** The class's @ApiPath basePath; absent for an external (vendor) contract, which has no route. */\n basePath?: string;\n /**\n * Every @Endpoint method, in declaration order. Empty for an external contract (a vendor\n * interface has no endpoints — it is called through a vendor SDK, not mounted).\n */\n methods: ApiMethodMeta[];\n /**\n * Set when the contract carries an `@externalSystem <kind> [label]` JSDoc tag — a vendor seam\n * declaring WHAT it is a seam to. JSDoc rather than a decorator because these seams are plain TS\n * `interface`s, which cannot carry one.\n */\n externalSystem?: ExternalSystemDeclaration;\n}\n\n/** The `(kind, label)` pair a single declaration resolves to. */\nexport interface ExternalSystemDeclaration {\n kind: ExternalSystemKind;\n label: string;\n}\n\n/**\n * The committed, per-contract view written to `architecture/apis/<ApiName>.json` (one file per API;\n * dependencies.json only links to it under `apiContractFiles` — see ApiContractFiles).\n *\n * The runtime graph is derived from the committed files so generate and validate can never\n * diverge — which means anything the runtime graph needs must be COMMITTED, not re-scanned.\n * Per-method trigger kinds and queue names are exactly that: without this table the derivation\n * cannot tell a queued endpoint from a cron sweep, and cannot name the queue between two services.\n */\nexport interface ApiContract {\n owner: string;\n /** 'rpc' | 'pubsub' for an in-repo contract, 'external' for a vendor seam. */\n apiKind: ApiTransport;\n /**\n * REQUIRED. Every routed contract carries `@ApiPath`, so every entry in this table must carry the\n * base path its methods hang off. Optional was worse than absent: a consumer joining\n * `basePath + path` for the ONE entry that lost it computed `/test` where the real route was\n * `/whatsapp/test`, and had no reason to suspect it — every other entry had the field. Generation\n * now FAILS instead of shipping an entry that computes a confidently wrong URL.\n */\n basePath: string;\n methods: ApiMethodMeta[];\n}\n\n/** apiClassName -> its committed contract. Serialized as one `architecture/apis/<ApiName>.json` each. */\nexport type ApiContracts = Record<string, ApiContract>;\n\n/**\n * An `addRoutes`/`createRpcClient`/`createPubSubClient` first argument that resolved to an\n * abstract class in a DECLARATION file which owns no indexed contract. Unambiguously a broken\n * scan (a real api-lib whose source we never indexed), never a \"this isn't an API\" argument —\n * so it is reported loudly instead of collapsing into a silent `return null`.\n */\nexport class UnresolvedApiCall {\n constructor(\n /** The project whose source makes the call. */\n public readonly project: string,\n /** The contract class name as written at the call site. */\n public readonly api: string,\n /** `path/to/file.ts:LINE` of the call site, workspace-relative. */\n public readonly at: string,\n /** The declaration file the checker resolved to (where decorators are erased). */\n public readonly declaredIn: string,\n ) {}\n}\n\n/**\n * ONE decorator argument the scan saw but could not reduce to a string — `@ApiPath(SOME_CONST)`\n * where SOME_CONST is imported from another module, a computed expression, an enum member, ...\n *\n * Recorded rather than dropped. Before this existed, an unresolvable argument cost the contract its\n * basePath, or a method, or (when EVERY method's path was one) the whole class — with nothing\n * printed anywhere. Same-module constants now resolve, so what remains here is the genuinely\n * unresolvable, which the author can fix by inlining the literal or moving the constant in-module.\n */\nexport class NonLiteralDecoratorArg {\n constructor(\n /** The contract class the argument was written on. */\n public readonly api: string,\n /** `ApiPath` | `Endpoint` | `Queue`. */\n public readonly decorator: string,\n /** The method name for a member decorator, null for a class decorator. */\n public readonly method: string | null,\n /** The argument exactly as written, e.g. `WHATSAPP_API_PATH`. */\n public readonly argument: string,\n /** `path/to/file.ts:LINE`, workspace-relative. */\n public readonly at: string,\n ) {}\n}\n\n/**\n * ONE `@Endpoint(path, kind)` whose PATH argument was present but could not be reduced to a string.\n *\n * Split out of NonLiteralDecoratorArg (which stays a warning, covering @Queue and the rest) because\n * this one is FATAL. Upstream components need the URL: an http client builds its request as\n * `basePath + path`, so an unreadable path is missing ROUTING, not missing metadata — the same\n * reasoning that already makes basePath required. Skipping the method instead used to delete it, and\n * a class whose every path was a constant lost every method and vanished from the contract table with\n * nothing printed anywhere.\n */\nexport class UnresolvedEndpointPath {\n constructor(\n /** The contract class the method is declared on. */\n public readonly api: string,\n /** The method name. */\n public readonly method: string,\n /** The path argument exactly as written, e.g. `PROCESS_PATH`. */\n public readonly argument: string,\n /** `path/to/file.ts:LINE`, workspace-relative. */\n public readonly at: string,\n ) {}\n}\n\n/**\n * ONE `external` `@Endpoint` whose CALLER could not be read from the source.\n *\n * Fatal for the same reason {@link UnresolvedEndpointPath} is. The inbound box exists to say who is\n * calling us from outside; with no caller it can only restate our own contract name, which is the\n * exact bug this diagnostic exists to make impossible to reintroduce. `@Endpoint`'s TS overloads\n * already require `calledBy`, so anything reaching here is a JS caller, an `as any`, a cross-module\n * constant the parser-only scan cannot fold, or an unknown `callerKind`.\n */\nexport class UndeclaredExternalCaller {\n constructor(\n /** The contract class the method is declared on. */\n public readonly api: string,\n /** The method name. */\n public readonly method: string,\n /** What was wrong, as written — `<missing>`, `SOME_CONST`, `callerKind: 'vendor'`. */\n public readonly argument: string,\n /** `path/to/file.ts:LINE`, workspace-relative. */\n public readonly at: string,\n ) {}\n}\n\n/** What is wrong with one endpoint's response-body declaration (#1339, #1348). */\nexport enum VoidResponseProblem {\n /** RPC / EXTERNAL_INBOUND: declares `responseBody: NONE` but does not return `Promise<void>`. */\n NONE_WITHOUT_VOID = 'none-without-void',\n /** RPC / EXTERNAL_INBOUND: returns `Promise<void>` but does not declare `responseBody: NONE`. */\n VOID_WITHOUT_NONE = 'void-without-none',\n /** EXTERNAL_OUTBOUND: declares `responseBody: NONE`, but the VENDOR shapes an outbound response. */\n OUTBOUND_NONE = 'outbound-none',\n /** CLOUDTASKS / CRON: declares `responseBody: NONE`, which the kind already implies. */\n REDUNDANT_NONE = 'redundant-none',\n /** CLOUDTASKS / CRON: does not return `Promise<void>`, but the kind is fire-and-forget. */\n TRIGGER_NOT_VOID = 'trigger-not-void',\n}\n\n/**\n * An `@Endpoint` whose response-body declaration disagrees with its kind or its declared return\n * type. The runtime cannot see `void` (`design:returntype` is just `Promise`), so the kind (CLOUDTASKS\n * and CRON imply no body, #1348) or the `responseBody: NONE` option (RPC, EXTERNAL_INBOUND) is the\n * only thing a server and a client act on, and it must not drift from the signature. EXTERNAL_OUTBOUND\n * takes no option at all: the vendor shapes its responses and the client accepts any 2xx.\n */\nexport class VoidResponseMismatch {\n constructor(\n public readonly api: string,\n public readonly method: string,\n /** Which of the five disagreements this is. */\n public readonly problem: VoidResponseProblem,\n /** The endpoint kind as written in the graph (`rpc`, `cloudtasks`, ...). */\n public readonly kind: EndpointKind,\n /** `path/to/file.ts:LINE`, workspace-relative. */\n public readonly at: string,\n ) {}\n}\n\n/**\n * ONE `@Endpoint` declaring operation READ with `{ additive }` (#1423) — a contradiction, since a read\n * changes nothing to be additive about. `@Endpoint`'s overloads refuse it at compile time; this catches\n * the source the type could not see (a JS caller, an `as` cast, a widened operation variable).\n */\nexport class AdditiveReadEndpoint {\n constructor(\n /** The contract class the method is declared on. */\n public readonly api: string,\n /** The method name. */\n public readonly method: string,\n /** `path/to/file.ts:LINE`, workspace-relative. */\n public readonly at: string,\n ) {}\n}\n\n/** ONE `@Endpoint` whose required side-effect declaration could not be read from source. */\nexport class UndeclaredEndpointOperation {\n constructor(\n /** The contract class the method is declared on. */\n public readonly api: string,\n /** The method name. */\n public readonly method: string,\n /** What was wrong, as written — `<missing>`, a constant name, or an invalid literal. */\n public readonly argument: string,\n /** `path/to/file.ts:LINE`, workspace-relative. */\n public readonly at: string,\n ) {}\n}\n\n/**\n * A contract class that DECLARED `@Endpoint` methods and kept none of them.\n *\n * The backstop for the mechanism that hid an entire service: `buildApiContracts` skips a zero-method\n * class (correctly — a vendor seam has no routes), so a class gutted by unreadable decorator\n * arguments left through the same door as a legitimately routeless one. A class that declared\n * endpoints and produced none is never legitimate, so it is named instead.\n */\nexport class EmptiedApiContract {\n constructor(\n /** The contract class name. */\n public readonly api: string,\n /** How many `@Endpoint` decorators were written on it. */\n public readonly declared: number,\n /** `path/to/file.ts:LINE` of the class, workspace-relative. */\n public readonly at: string,\n ) {}\n}\n\n/** Derive the relation kind from the (possibly empty) implements/uses ref lists. */\n// webpieces-disable no-function-outside-class -- pure data helper for these serialization DTOs\nexport function deriveApiRelationKind(\n implementsRefs: ApiRef[],\n usesRefs: ApiRef[],\n): ApiRelationKind {\n if (implementsRefs.length > 0 && usesRefs.length > 0) return 'uses-implements';\n if (implementsRefs.length > 0) return 'implements';\n return 'uses';\n}\n\n/**\n * Stable-sort a ref list by api name, then by target service, so the committed JSON is\n * deterministic even when one api is used against two different services.\n */\n// webpieces-disable no-function-outside-class -- pure data helper for these serialization DTOs\nexport function sortApiRefs(refs: ApiRef[]): ApiRef[] {\n return [...refs].sort(\n (a: ApiRef, b: ApiRef) =>\n a.api.localeCompare(b.api) ||\n (a.targetService ?? '').localeCompare(b.targetService ?? ''),\n );\n}\n"]}
@@ -29,7 +29,7 @@
29
29
  */
30
30
  import type { EnhancedGraph } from '../graph-sorter';
31
31
  import { ProjectInfo } from '../project-info';
32
- import { ApiClassInfo, ApiContracts, EmptiedApiContract, NonLiteralDecoratorArg, ProjectApiRelations, UndeclaredExternalCaller, UndeclaredEndpointOperation, VoidResponseMismatch, UnresolvedApiCall, UnresolvedEndpointPath } from './api-relations';
32
+ import { ApiClassInfo, ApiContracts, AdditiveReadEndpoint, EmptiedApiContract, NonLiteralDecoratorArg, ProjectApiRelations, UndeclaredExternalCaller, UndeclaredEndpointOperation, VoidResponseMismatch, UnresolvedApiCall, UnresolvedEndpointPath } from './api-relations';
33
33
  import { RootUnionFindings, RootUnionRule } from './root-union-scan';
34
34
  import { ApiDocRule, ApiDocRulesFindings } from './api-doc-rules';
35
35
  import { WireClosureRule } from './wire-closure';
@@ -79,6 +79,8 @@ export interface ApiScanResult {
79
79
  undeclaredEndpointOperations: UndeclaredEndpointOperation[];
80
80
  /** Endpoints whose response-body declaration disagrees with their kind or signature. Fatal. */
81
81
  voidResponseMismatches: VoidResponseMismatch[];
82
+ /** READ endpoints declaring `{ additive }` (#1423). Fatal. */
83
+ additiveReads: AdditiveReadEndpoint[];
82
84
  /** `no-root-union-api-type`'s findings. Fatal in buildApiContracts — see root-union-scan.ts. */
83
85
  rootUnions: RootUnionFindings;
84
86
  /**
@@ -214,7 +216,8 @@ export declare function scanAndAttachApiRelations(workspaceRoot: string, graph:
214
216
  * the URL a consumer computes, and the cause of most emptied contracts;
215
217
  * 2. a class that declared endpoints and kept none (EmptiedApiContractError), which would otherwise
216
218
  * leave silently through the zero-method skip above;
217
- * 3. a method without an explicit operation (UndeclaredEndpointOperationError);
219
+ * 3. a method without an explicit operation (UndeclaredEndpointOperationError), or a READ one
220
+ * declaring `{ additive }` (AdditiveReadEndpointError);
218
221
  * 4. an `external` method that never said WHO calls it (UndeclaredExternalCallerError);
219
222
  * 5. a routed contract with no basePath (MissingBasePathError).
220
223
  * All are worse than an absent entry: a consumer joining `basePath + path` computes a
@@ -264,6 +264,7 @@ class ApiUsageScanner {
264
264
  undeclaredExternalCallers: this.decoratorArgDiagnostics.undeclaredExternalCallers(),
265
265
  undeclaredEndpointOperations: this.decoratorArgDiagnostics.undeclaredEndpointOperations(),
266
266
  voidResponseMismatches: this.decoratorArgDiagnostics.voidResponseMismatches(),
267
+ additiveReads: this.decoratorArgDiagnostics.additiveReads(),
267
268
  rootUnions: new root_union_scan_1.RootUnionScan(this.workspaceRoot, this.projectInfos, this.rootUnionRule).run(),
268
269
  apiDocRules: new api_doc_rules_scan_1.ApiDocRulesScan(this.workspaceRoot, this.projectInfos, this.openApiRule, this.mcpRule, this.wireClosureRule).run(),
269
270
  };
@@ -431,7 +432,8 @@ async function scanAndAttachApiRelations(workspaceRoot, graph, projectInfos, ext
431
432
  * the URL a consumer computes, and the cause of most emptied contracts;
432
433
  * 2. a class that declared endpoints and kept none (EmptiedApiContractError), which would otherwise
433
434
  * leave silently through the zero-method skip above;
434
- * 3. a method without an explicit operation (UndeclaredEndpointOperationError);
435
+ * 3. a method without an explicit operation (UndeclaredEndpointOperationError), or a READ one
436
+ * declaring `{ additive }` (AdditiveReadEndpointError);
435
437
  * 4. an `external` method that never said WHO calls it (UndeclaredExternalCallerError);
436
438
  * 5. a routed contract with no basePath (MissingBasePathError).
437
439
  * All are worse than an absent entry: a consumer joining `basePath + path` computes a
@@ -452,6 +454,8 @@ function buildApiContracts(scan) {
452
454
  if ((scan.voidResponseMismatches ?? []).length > 0) {
453
455
  throw new api_contract_errors_1.VoidResponseMismatchError(scan.voidResponseMismatches);
454
456
  }
457
+ if (scan.additiveReads.length > 0)
458
+ throw new api_contract_errors_1.AdditiveReadEndpointError(scan.additiveReads);
455
459
  // A shape no function-calling API will accept, read perfectly well — unlike the four above, which
456
460
  // are contracts the scan could not READ at all.
457
461
  if (!scan.rootUnions.isEmpty())