UNPKG

@typespec/versioning

Version:

TypeSpec library for declaring and emitting versioned APIs

46 lines 2.1 kB
import type { ModelProperty, Namespace, Operation, Program, Type } from "@typespec/compiler"; import { type unsafe_MutatorWithNamespace as MutatorWithNamespace } from "@typespec/compiler/experimental"; import type { Version } from "./types.js"; import { VersioningTimeline, type TimelineMoment } from "./versioning-timeline.js"; /** * When the service is versioned. */ export interface VersionedMutators { readonly kind: "versioned"; readonly snapshots: VersionSnapshotMutation[]; } /** Mutator to mutate the service to the specific version. */ export interface VersionSnapshotMutation { readonly version: Version; readonly mutator: MutatorWithNamespace; } /** * When the service itself is not versioned but use specific version from another library. */ export interface TransientVersioningMutator { readonly kind: "transient"; readonly mutator: MutatorWithNamespace; } /** * Resolve the set of mutators needed to apply versioning to the service. * @returns either: * - VersionedMutators when the service is versioned. * - TransientVersioningMutator when the service is not versioned but use specific version from another library. * - undefined when the service is not versioned. */ export declare function getVersioningMutators(program: Program, namespace: Namespace): VersionedMutators | TransientVersioningMutator | undefined; export declare function createVersionMutator(versioning: VersioningHelper, moment: TimelineMoment): MutatorWithNamespace; declare class VersioningHelper { #private; constructor(program: Program, timeline: VersioningTimeline); existsAtVersion(type: Type, moment: TimelineMoment): boolean; getNameAtVersion<T extends NameableType>(type: T, moment: TimelineMoment): T["name"]; getTypeAtVersion(type: ModelProperty, moment: TimelineMoment): Type; getReturnTypeAtVersion(type: Operation, moment: TimelineMoment): Type; getOptionalAtVersion(type: ModelProperty, moment: TimelineMoment): boolean; } type NameableType = Type & { name?: string | symbol; }; export {}; //# sourceMappingURL=mutator.d.ts.map