/** * Unified parse context for both OAS and GraphQL inputs. * * One class, two protocol-specific states behind a discriminated union. * Universal capabilities (issue collection, logger mirroring, * dependency-ref tracking) live at the top of the class and apply to * both protocols. Protocol-specific state (`oasDocument` vs * `schema`/`registry`) sits on `this.protocol`, narrowed by * `this.protocol.type`. The OAS-flavored logging surface * (`logIssue`/`logIssueNoKey`/`logSkippedFields`) accepts a * {@link StackTrail} for location; the GQL-flavored surface (`log`, * `logSkippedFields` with a pre-computed `location` string) accepts a * raw string. Both funnel into the shared {@link ParseContext.logIssueAt}. * * `removeErroredItems` is universal; the removal it runs dispatches on * `protocol.type` because the cleanup step is document-shaped. */ import "../_dnt.polyfills.js"; import type { OpenAPIV3 } from 'openapi-types'; import { type GraphQLSchema } from 'graphql'; import type { SystemSettings } from '../types/Settings.js'; import { OasDocument } from '../oas/document/Document.js'; import { GqlRegistry } from '../gql/registry/GqlRegistry.js'; import { GqlDocument } from '../gql/document/GqlDocument.js'; import type { Logger } from '../types/Logger.js'; export type { AttributionState } from '../types/AttributionState.js'; import { StackTrail } from './StackTrail.js'; import type { SkmtcDocumentInput, SkmtcParsedDocument } from '../types/SkmtcDocument.js'; import type { GqlParseOptions, LogAtArgs, LogIssueArgs, LogIssueAtArgs, LogIssueNoKeyArgs, LogSkippedValuesArgs } from './parseTypes.js'; import type { ParseIssue } from './ParseIssue.js'; import type { OasRef } from '../oas/ref/Ref.js'; import type { OasRefData } from '../oas/ref/ref-types.js'; import { DanglingRefError } from '../oas/ref/DanglingRefError.js'; export type { ParseIssue, GqlIssueType } from './ParseIssue.js'; export type { GqlParseOptions, LogAtArgs, LogIssueArgs, LogIssueAtArgs, LogIssueNoKeyArgs, LogSkippedValuesArgs, ParseContextType, ParseErrorInput, ParseIssueInput, ParseWarningInput } from './parseTypes.js'; type OasProtocolState = { type: 'oas'; documentObject: OpenAPIV3.Document; oasDocument: OasDocument; }; type GqlProtocolState = { type: 'gql'; schema: GraphQLSchema; registry: GqlRegistry; /** * Empty-at-construction `GqlDocument` that refs resolve through. * Populated by `parse()` at the end of the walk via * `gqlDocument.fields = { registry, operations, rootTypes }`. See the * forward-declared-refs section on `OasDocument` for why this is the * shape. */ gqlDocument: GqlDocument; options: GqlParseOptions; }; type ProtocolState = OasProtocolState | GqlProtocolState; type ToDanglingAllOfMemberArgs = { /** Why the member names nothing: no schema has its name, or its `$ref`s loop. */ error: DanglingRefError; /** The schema that holds the `allOf`. */ stackTrail: StackTrail; }; type ConstructorArgs = { input: SkmtcDocumentInput; logger: Logger; silent?: boolean; /** * Protocol-specific parse options. Only the matching protocol's * entry is consulted; the rest are ignored. Today only GQL uses * this; adding more is additive. */ options?: { gql?: GqlParseOptions; }; /** `client.json#settings.system`: how the OpenAPI parsers treat what they cannot read faithfully. */ system?: SystemSettings; }; export declare class ParseContext { #private; issues: ParseIssue[]; logger: Logger; silent: boolean; protocol: ProtocolState; /** * The StackTrail of the currently-traversed position. Set by * factories via {@link ParseContext.withStackTrail} just before * constructing the node so the `OasBase` base can snapshot it. * `undefined` outside an active `withStackTrail` scope. */ currentStackTrail: StackTrail | undefined; /** * How the OpenAPI parsers treat what they cannot read faithfully * (`client.json#settings.system`). Each setting left out is `strict`. */ system: SystemSettings; constructor({ input, logger, silent, options, system }: ConstructorArgs); /** * OAS-only accessor. Throws when called on a GQL-protocol context — * deliberate, because OAS parser code uses this and a misroute is a * real bug, not a recoverable situation. */ get oasDocument(): OasDocument; /** OAS-only accessor; symmetric reason to {@link oasDocument}. */ get documentObject(): OpenAPIV3.Document; /** GQL-only accessor; throws if called on an OAS context. */ get schema(): GraphQLSchema; /** GQL-only accessor; throws if called on an OAS context. */ get registry(): GqlRegistry; /** * GQL-only accessor returning the in-flight `GqlDocument` (empty * during parse, populated at the end). Parsers use this when * constructing `OasRef`s via `registry.createRef(refName, context)` * so the resulting refs point at the right document instance. */ get gqlDocument(): GqlDocument; /** * Convenience: returns the discriminated `SkmtcParsedDocument` for * the active protocol. Useful for parser code that needs to hand a * document to `OasRef` (or `registry.createRef`) without manually * constructing the wrapper. */ get parsedDocument(): SkmtcParsedDocument; /** * Runs the protocol-appropriate parse step and returns the result * wrapped in {@link SkmtcParsedDocument}. Both protocols walk under * `stackTrail`, so issue locations start with its frames; pruning * removes those frames before it reads a trail as a document address. */ parse(stackTrail: StackTrail): SkmtcParsedDocument; /** * Removes every item that depends on a ref with a registered error. * * OAS: a component with an error is removed, even when the error is in * one of its properties. Each consumer of a removed component is removed * too. A consumer that is itself a component (its trail starts * `components::`) has its own consumers removed next, at any * depth. GraphQL removes the consuming field, union member or operation, * which leaves no ref to follow. * * Each removed consumer yields one `INVALID_DEPENDENCY_REF` at its * location. The message names the ref it depends on and the error that * started the removal; that error is the `cause`. * * A `paths:P:M:…` consumer trail resolves to the whole operation, so an * operation is removed even when the ref is only in a response it does * not generate from. */ removeErroredItems(): void; /** * Run `fn` with `currentStackTrail` set to the given trail; restore * the previous value afterwards (try/finally semantics). Factories * wrap schema-construction in this so `OasBase` can snapshot the * trail off the context without each factory threading it * explicitly into the constructor. * * @example * ```ts * return context.withStackTrail(stackTrail, () => * new OasBoolean({ title, ... }, context) * ) * ``` */ withStackTrail(stackTrail: StackTrail, fn: () => T): T; /** * Register a `$ref`-style consumer site. The key encoding is up to * the caller — OAS uses `#/components/schemas/User` strings, GQL * would use type names or qualified field paths. */ registerRef(consumer: StackTrail, refKey: string): void; /** * Register an OAS `$ref` at its consumer site, as {@link registerRef} * does, under the key {@link toRefKey} gives its `$ref`, and keep the ref * with that site, so that once the document is parsed `#checkRefs` can * resolve it there. */ registerOasRef(consumer: StackTrail, ref: OasRef): void; /** * What a merge reads in place of a `$ref` that names nothing: an `allOf` * member, or in a `oneOf` or `anyOf`, a member's own `allOf` member or a * member merged with the keywords beside the union. When * `system.danglingRefs` lists `allOfMember`, it is `{}`, which * adds nothing to the merge (`A & unknown` is `A`), and a `DANGLING_REF` * warning at `stackTrail`: the model has no properties from that member. * Otherwise it throws `DanglingRefError`, and what holds the `allOf` is * removed. It is separate from `schema`: here core decides, at parse, and * the generator never sees the member. */ toDanglingAllOfMember({ error, stackTrail }: ToDanglingAllOfMemberArgs): OpenAPIV3.SchemaObject; /** * Register an error against a ref key — typically called when the * target of a `$ref` (or type reference) fails to parse. `undefined` * `refKey` is a deliberate no-op: callers may pass the result of * `StackTrail.toStackRef()` directly, which is `undefined` for * non-component stack trails. `location` is where the error was logged; * each `INVALID_DEPENDENCY_REF` it causes names it. */ registerRefError(error: unknown, refKey: string | undefined, location?: string): void; /** * Universal issue recorder. Pushes to `issues` and (when not silent) * mirrors to the logger. Both protocols' surface methods funnel * here. * * `parent` is an optional log-time-only field — surface methods * forward the surrounding object so log readers see its shape, not * just the leaf address. Stringified here so the logger payload * stays JSON-clonable. It is intentionally **not** stored on the * persisted `ParseIssue` (which would require clone-safe * serialization across the worker boundary and would bloat the * manifest). */ logIssueAt(issue: LogIssueAtArgs, parent?: unknown): void; logIssue({ key, parent, type, stackTrail, ...issue }: LogIssueArgs): void; logIssueNoKey({ parent, type, stackTrail, ...issue }: LogIssueNoKeyArgs): void; /** * Thin convenience for recording an issue at a pre-computed string * `location` rather than threading a {@link StackTrail}. Use this * for issues whose natural address isn't a tree position: * * - Schema-level directive definitions (`@auth`) — flat namespace, * no parent type. * - Catch-all error paths where the parsed entity doesn't exist * yet (the parse threw before producing one). * * For tree-position issues, prefer {@link logIssueNoKey} so the * stack trail composes with the surrounding traces. * * Internally constructs a `StackTrail` with `StackTrail.fromString(location)` * and delegates to {@link logIssueNoKey} — the underlying issue * recording logic (protocol tagging, optional ref-error * auto-registration, logger mirror with parent context) is shared. */ log({ location, parent, type, ...issue }: LogAtArgs): void; /** * Records one warning per unrecognized key under `parent`. * * Each skipped key is traced as a child of `stackTrail` so the * resulting issue locations point at the offending property, not * the parent. `parentType` is used in the message text * (`Unexpected property 'foo' in 'SchemaObject'`); `type` defaults * to `UNEXPECTED_PROPERTY` (the OAS convention) but GQL callers can * pass a more specific category like `SKIPPED_FIELD_ARGUMENTS`. */ logSkippedFields({ skipped, stackTrail, parent, parentType, type }: LogSkippedValuesArgs): void; }