The `pg-proto-parser` library is a TypeScript project designed to parse Protocol Buffers (`.proto`) definitions specifically for `pganalyze/libpg_query` PostgreSQL Abstract Syntax Tree (AST) structures. It does not parse raw SQL queries or the PostgreSQL wire protocol directly. Instead, its primary function is to generate TypeScript interfaces, utility functions, and JSON mappings for the enums and messages defined within these PostgreSQL-related protobuf schemas. This generated code facilitates the creation of type-safe AST nodes and simplifies enum value conversions, serving as a foundational tool for other PostgreSQL tooling like `launchql/pgsql-parser` for maintainable upgrades. The package is currently at version 1.30.5 and appears to be actively maintained, offering a crucial layer for developers working with PostgreSQL's internal query representation in a type-safe TypeScript environment.
npm install pg-proto-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `PgProtoParser` with a dummy protobuf schema, configure output options, and generate corresponding TypeScript interfaces, enums, and utility files into a specified directory.
Verify that your use case specifically involves working with the protobuf schemas that define PostgreSQL's AST or internal messages. If you need to parse SQL, consider `@pgsql/parser` or `pgsql-parser`. If you need to interact with the PostgreSQL wire protocol, `pg-protocol` is the appropriate library.
Regularly regenerate your types and utilities with `pg-proto-parser` after updating the source PostgreSQL protobuf definitions. Implement robust versioning and compatibility checks for your generated code consumers, as per standard Protocol Buffers schema evolution best practices. Consider using tools like `proto-break` to detect breaking changes in `.proto` files before deployment.
Ensure the package is installed (`npm install pg-proto-parser` or `yarn add pg-proto-parser`). If using ESM `import` syntax in a CommonJS project, ensure your `package.json` has `"type": "module"` or use a bundler. For TypeScript, check `tsconfig.json` for `moduleResolution` and `target` settings, and confirm the package's type declarations are correctly linked.
When initializing `PgProtoParser`, pass a valid path to your primary `.proto` file as the first argument, and an options object containing at least `outDir` where the generated files should be placed. For example: `new PgProtoParser('path/to/your.proto', { outDir: './generated' });`No dependency data recorded yet.