/** * Protocol Buffers v3 reader (change: add-contract-graph-projection, protobuf phase). * * Reads one `.proto` file into a normalized element model: services and their RPCs, messages * (nested ones under their full name), fields with their numbers, labels and types, enums with * their values, and the `reserved` ranges and names of each. Deterministic and offline: a small * hand-written tokenizer, no grammar, no `protoc`, no network. * * Only proto3 is read. A file with no `syntax` statement is proto2 by the language's own rule, * and an `edition` file follows other rules again; both are UNREAD with that reason, never read as * declaring nothing. An element the model does not cover (`extend`, `extensions`) is listed in * `unassessed`. Type names are resolved across every file read by {@link resolveProtoTypes}, with * protobuf's own scoping rule — never by similarity. */ /** Whether a path is a protobuf definition file. */ export declare const isProtobufPath: (path: string) => boolean; /** Whether a field type is a scalar (never a reference to a message or enum). */ export declare const isProtoScalar: (type: string) => boolean; export type ProtoLabel = 'singular' | 'optional' | 'repeated' | 'map'; /** A type name as written, with the scope it was written in — resolved later, across files. */ export interface ProtoTypeRef { written: string; scope: string; } export interface ProtoField { name: string; number: number; label: ProtoLabel; /** The type as written: a scalar, a (possibly qualified) message or enum name, or `map`. */ type: string; /** For a message or enum type (or a map's value type): what to resolve. */ ref?: ProtoTypeRef; /** The full name it resolved to (`pkg.Order`), set by {@link resolveProtoTypes}. */ resolved?: string; /** The `oneof` it belongs to. */ oneof?: string; deprecated: boolean; /** A hash of the field options the rule table does not compare (`json_name`, `packed`, …). */ optionsHash: string; line: number; } export interface ProtoReserved { /** Inclusive number ranges. */ ranges: Array<[number, number]>; names: string[]; } export interface ProtoMessage { kind: 'message'; /** The full name, package included, no leading dot: `pkg.Outer.Inner`. */ name: string; /** The name as declared: `Inner`. */ simpleName: string; line: number; fields: ProtoField[]; reserved: ProtoReserved; /** A hash of the message's own options. */ optionsHash: string; } export interface ProtoEnumValue { name: string; number: number; deprecated: boolean; optionsHash: string; line: number; } export interface ProtoEnum { kind: 'enum'; name: string; simpleName: string; line: number; values: ProtoEnumValue[]; reserved: ProtoReserved; optionsHash: string; } export interface ProtoRpc { /** The gRPC method path: `/pkg.Service/Method`. Unique per RPC, and what a client puts on the wire. */ address: string; /** The full service name: `pkg.Service`. */ service: string; name: string; request: ProtoTypeRef; response: ProtoTypeRef; /** Full names, set by {@link resolveProtoTypes} when they resolve. */ requestType?: string; responseType?: string; clientStreaming: boolean; serverStreaming: boolean; deprecated: boolean; optionsHash: string; line: number; } export interface ProtoService { name: string; simpleName: string; line: number; rpcs: ProtoRpc[]; optionsHash: string; } export interface ProtoDocument { file: string; format: 'protobuf-3'; package: string; imports: string[]; /** The imports written `import public`: re-exported to whoever imports this file. */ publicImports: string[]; services: ProtoService[]; messages: ProtoMessage[]; enums: ProtoEnum[]; /** Element classes present in the file but outside the model (`extend`, `extensions`). */ unassessed: string[]; } /** Reserved ranges sorted and merged (touching ranges joined), so membership is a binary search. */ export declare function mergeRanges(ranges: ReadonlyArray): Array<[number, number]>; /** Whether `n` is in merged ranges. */ export declare function inRanges(merged: ReadonlyArray, n: number): boolean; /** * Parse one file. Returns an `error` when it cannot be read as proto3 — a syntax error, proto2, * editions, or a file past the size cap. A `.proto` file is always a specification, so there is * no "not a document" outcome. */ export declare function readProtobuf(file: string, text: string): ProtoDocument | { file: string; error: string; }; /** Why a type reference did not resolve. */ export interface UnresolvedProtoType { file: string; line: number; written: string; reason: 'undeclared' | 'ambiguous'; } /** * Resolve every message and enum type reference across `docs`, with protobuf's own scoping rule: * a qualified name's FIRST component is looked up from the innermost scope outward, and the rest * must then resolve under it — a first component that resolves to a type or package and whose * rest does not is an error, not a reason to keep looking further out. A leading dot means * "from the root". A full name declared in two files (two copies of one schema) is ambiguous and * binds nothing. * * Mutates nothing: returns new documents with `resolved` / `requestType` / `responseType` set, * plus every reference that did not resolve. */ export declare function resolveProtoTypes(docs: readonly ProtoDocument[]): { docs: ProtoDocument[]; unresolved: UnresolvedProtoType[]; }; //# sourceMappingURL=protobuf.d.ts.map