Skip to content

Commit f18c809

Browse files
committed
docs: clarify RawStmt is a Node type but appears inline in ParseResult
- Update comments to reference protobuf 'repeated RawStmt' definition - Clarify that RawStmt IS a Node type (in Node oneof) - Explain why ParseResult.stmts contains RawStmt objects inline - Add protobuf message definitions to ENTRY_POINT.md for clarity
1 parent 053ebe4 commit f18c809

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

ENTRY_POINT.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,25 @@
4444

4545
### Key Clarification:
4646

47-
The structure from libpg-query is:
47+
The structure from libpg-query is based on the protobuf definition:
48+
```protobuf
49+
message ParseResult {
50+
int32 version = 1;
51+
repeated RawStmt stmts = 2; // "repeated" means array contains RawStmt inline
52+
}
53+
54+
message RawStmt {
55+
Node stmt = 1;
56+
int32 stmt_location = 2;
57+
int32 stmt_len = 3;
58+
}
59+
```
60+
61+
This translates to:
4862
```typescript
4963
ParseResult {
5064
version: number;
51-
stmts: RawStmt[]; // Array of RawStmt objects directly (NOT wrapped)
65+
stmts: RawStmt[]; // Array contains RawStmt objects inline (not wrapped as nodes)
5266
}
5367

5468
// Each RawStmt in the array has this structure:
@@ -59,7 +73,7 @@ RawStmt {
5973
}
6074
```
6175

62-
This is different from wrapped nodes like `{ RawStmt: {...} }` which are used when explicitly creating a Node.
76+
Important: While RawStmt IS a Node type (listed in the Node oneof), when it appears in ParseResult.stmts, it's inline due to the "repeated RawStmt" protobuf definition. This is different from wrapped nodes like `{ RawStmt: {...} }` which are used when explicitly creating a Node for the deparser.
6377

6478
## Overview
6579

packages/deparser/src/deparser.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export interface DeparserOptions {
1818
function isParseResult(obj: any): obj is t.ParseResult {
1919
// A ParseResult is an object that could have stmts (but not required)
2020
// and is not already wrapped as a Node
21-
// IMPORTANT: ParseResult.stmts contains RawStmt objects directly (not wrapped)
21+
// IMPORTANT: ParseResult.stmts is "repeated RawStmt" in protobuf, meaning
22+
// the array contains RawStmt objects inline (not wrapped as { RawStmt: ... })
2223
// Example: { version: 170004, stmts: [{ stmt: {...}, stmt_len: 32 }] }
2324
return obj && typeof obj === 'object' &&
2425
!Array.isArray(obj) &&
@@ -38,7 +39,8 @@ function isWrappedParseResult(obj: any): obj is { ParseResult: t.ParseResult } {
3839
* Entry Points:
3940
* 1. ParseResult (from libpg-query) - The complete parse result
4041
* Structure: { version: number, stmts: RawStmt[] }
41-
* Note: stmts contains RawStmt objects directly, NOT wrapped as { RawStmt: ... }
42+
* Note: stmts is "repeated RawStmt" in protobuf, so array contains RawStmt
43+
* objects inline (not wrapped as { RawStmt: ... } nodes)
4244
* Example: { version: 170004, stmts: [{ stmt: {...}, stmt_len: 32 }] }
4345
*
4446
* 2. Wrapped ParseResult - When explicitly wrapped as a Node
@@ -184,7 +186,7 @@ export class Deparser implements DeparserVisitor {
184186
}
185187

186188
// Deparse each RawStmt in the ParseResult
187-
// Note: node.stmts contains RawStmt objects directly (not wrapped)
189+
// Note: node.stmts is "repeated RawStmt" so contains RawStmt objects inline
188190
// Each element has structure: { stmt: Node, stmt_len?: number, stmt_location?: number }
189191
return node.stmts
190192
.filter((rawStmt: t.RawStmt) => rawStmt != null)

0 commit comments

Comments
 (0)