/** * Constraint applicability guard — host-checker Role-B equivalent for the * snapshot consumer. * * The build consumer (`tsdoc-parser.ts`) calls `supportsConstraintCapability()` * before argument validation to emit `TYPE_MISMATCH` when a constraint's * required semantic capability is absent from the field type (e.g. `@minimum 0` * on a `string` field has no `numeric-comparable` capability). * * This module ports that guard into `@stripe/formspec-analysis` so the snapshot * consumer can apply the same check without depending on the build package. * * Ordering invariants (for callers in `file-snapshots.ts:buildTagDiagnostics`): * 1. Integer-brand bypass MUST run before this check. Integer-branded types * (`number & { [__integerBrand]: true }`) look like plain numbers for * capability purposes but should bypass entirely (Phase 4A). If the brand * bypass is not applied first, `_supportsConstraintCapability` will still * return `true` for numeric-comparable on integer types (correct), but the * guard ordering must match the build path's ordering. * 2. This check runs BEFORE the typed-parser Role-C call (matching the build * path's guard order). For a bad-arg AND wrong-type input (e.g. `@minimum * "hello" on string`), Role B emits TYPE_MISMATCH before Role C inspects * the argument — ensuring both consumers produce the same diagnostic code. * * @internal */ import * as ts from "typescript"; import type { JsonValue } from "@stripe/formspec-core/internals"; import { type SemanticCapability } from "./tag-registry.js"; /** * Maps a {@link SemanticCapability} to a human-readable type name for use in * diagnostic messages (e.g. `"numeric-comparable"` → `"number"`). * * Both the build consumer (`tsdoc-parser.ts`) and the snapshot consumer * (`file-snapshots.ts`) use this helper so their TYPE_MISMATCH messages are * identical. * * @internal */ export declare function _capabilityLabel(capability: SemanticCapability | undefined): string; /** * Selects the type against which a constraint capability is evaluated. * * `array-like` capabilities target the field/container type. Every other * value, including `undefined`, targets exactly one immediate array item when * the field resolves to an array, or the field type otherwise. Callers that * know the tag capability should pass it rather than relying on the * `undefined` fallback. * * @internal */ export declare function _getConstraintTargetType(capability: SemanticCapability | undefined, fieldType: ts.Type, checker: ts.TypeChecker): ts.Type; /** * Returns whether `fieldType` satisfies `capability`. * * `undefined` means the tag has no type requirement and is accepted * unconditionally. Integer-brand bypass remains the caller's responsibility. * * @internal */ export declare function _supportsConstraintCapability(capability: SemanticCapability | undefined, fieldType: ts.Type, checker: ts.TypeChecker): boolean; /** * Validates an `@const` tag's value against the field type, or against the * immediate item type when the field resolves to an array. * * Ports the three sub-checks from `semantic-targets.ts` `case "const":` * (~lines 1255-1301) to the snapshot consumer path. The build path validates * `@const` at IR validation time (on `effectiveType`); the snapshot consumer * does not build an IR, so this helper performs the equivalent checks * * Returns a TYPE_MISMATCH descriptor when any check fails, or `null` when the * value is compatible with the field type. The returned object is shaped so * callers can push it into their diagnostic array without re-deriving the * code/message pair. * * Checks (in order): * 1. **Placement.** Effective target type must be a primitive (`string`, * `number`, `integer`, `bigint`, `boolean`, `null`) or a string-literal * enum. Otherwise: `constraint "const" is only valid on primitive or enum * fields, but field type is "