Skip to content

Commit f7d68a8

Browse files
committed
updates
1 parent 3d86f39 commit f7d68a8

File tree

12 files changed

+3600
-1129
lines changed

12 files changed

+3600
-1129
lines changed

packages/transform/AST_PLAN.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,83 @@ These fixtures now serve as the foundation for:
6868
2. Testing our transformation logic
6969
3. Validating that transformations preserve semantic meaning
7070

71+
## Version-Specific Type System
72+
73+
Each PostgreSQL version (13-17) has its own directory under `src/` containing essential type information and utilities:
74+
75+
### File Structure
76+
```
77+
src/
78+
├── 13/
79+
│ ├── enum-to-int.ts # Convert enum strings to integer values
80+
│ ├── enum-to-str.ts # Convert enum integers to string values
81+
│ ├── enums.ts # Enum definitions for this version
82+
│ ├── runtime-schema.ts # Runtime schema for node structure validation
83+
│ └── types.ts # TypeScript type definitions
84+
├── 14/
85+
│ └── (same files)
86+
├── 15/
87+
│ └── (same files)
88+
├── 16/
89+
│ └── (same files)
90+
└── 17/
91+
└── (same files)
92+
```
93+
94+
### File Descriptions
95+
96+
1. **types.ts** (PREFERRED)
97+
- Contains TypeScript type definitions for all AST nodes in that version
98+
- Should be used for type checking and IDE support
99+
- Lightweight and doesn't increase bundle size
100+
- Example: `PG13.SelectStmt`, `PG14.A_Const`
101+
102+
2. **enums.ts**
103+
- Defines all enum types used in the AST for that version
104+
- Maps enum names to their possible values
105+
- Critical for understanding valid values for enum fields
106+
107+
3. **enum-to-int.ts** & **enum-to-str.ts**
108+
- Utility functions for enum conversion
109+
- `enum-to-int.ts`: Converts string enum values to integers (for v13/v14 compatibility)
110+
- `enum-to-str.ts`: Converts integer enum values to strings (for v15+ compatibility)
111+
- Essential for transforming between pre-v15 (integer enums) and v15+ (string enums)
112+
113+
4. **runtime-schema.ts** (USE SPARINGLY)
114+
- Contains runtime schema information about node structures
115+
- Can detect if a node is wrapped or inline when it's a field of another node
116+
- **WARNING**: Importing runtime schema increases memory usage and bundle size
117+
- Only use when absolutely necessary for complex node structure validation
118+
119+
### Best Practices
120+
121+
1. **Prefer Static Types**: Always use `types.ts` over `runtime-schema.ts` when possible
122+
2. **Enum Conversions**: Use the enum conversion utilities when transforming between versions
123+
3. **Memory Efficiency**: Avoid importing runtime schemas unless required for specific validation
124+
4. **Type Safety**: Import version-specific types as namespaces (e.g., `import * as PG13 from '../13/types'`)
125+
126+
### Usage in Transformers
127+
128+
When implementing version transformers, these utilities are used as follows:
129+
130+
```typescript
131+
// Example: v14-to-v15 transformer
132+
import * as PG14 from '../14/types';
133+
import * as PG15 from '../15/types';
134+
// Only import enum utilities if needed for specific transformations
135+
// import { enumToStr } from '../14/enum-to-str';
136+
137+
export class V14ToV15Transformer extends BaseTransformer {
138+
// Transform methods using the type definitions
139+
A_Const(node: any, context?: TransformerContext): any {
140+
// Use types for documentation, but 'any' where types don't match reality
141+
// due to limitations in generated type definitions
142+
}
143+
}
144+
```
145+
146+
**Note**: The current transformers use `any` types in many places because the generated type definitions don't accurately reflect the actual parser output structure. This is documented in `TYPING_STATUS.md`.
147+
71148
## Phase 2: Implement Core Transformation Infrastructure
72149

73150
### Base Types and Interfaces

packages/transform/AST_TASK.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
we are a building transformers so we can upgrade PG13 ASTs to PG17, stepwise, so one major version at a time.
3+
4+
First only work on packages/transform/src/transformers/v13-to-v14.ts
5+
6+
and only work by testing like this to only run tests inside of the PG13 -> PG14 :
7+
8+
yarn test:watch __tests__/kitchen-sink/13-14
9+
10+
More info:
11+
review packages/transform/AST_TEST_STRATEGY.md
12+
review packages/transform/AST_NOTES.md
13+
review packages/transform/AST_PLAN.md
14+
review packages/transform/AST_RESEARCH.md
15+
review packages/transform/AST_TRANSLATION.md
16+
review packages/transform/AST_PLAN.md
17+
18+
to test first, in root
19+
20+
yarn
21+
yarn build
22+
23+
then
24+
25+
cd packages/transform
26+
27+
then to test you can use this:
28+
yarn test
29+
or
30+
yarn test:watch
31+
32+
Rule:
33+
34+
DO not remove type types from the Transformers,
35+
DO not do any special cases for TypeName or RangeVar — you must understand how to properly and dynamically return the proper type, either wrapped node or not (wrapped: { Type: Type } and inline: Type ) — based on either by studying the types, letting the type system help you, or as a last resort, using the runtime schema, and looking it up at runtime based on the FieldSpec.
File renamed without changes.

packages/transform/TRANSFORM_GUIDE.md

Lines changed: 0 additions & 228 deletions
This file was deleted.

packages/transform/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ export { V13ToV14Transformer } from './transformers/v13-to-v14';
1515
export { V14ToV15Transformer } from './transformers/v14-to-v15';
1616
export { V15ToV16Transformer } from './transformers/v15-to-v16';
1717
export { V16ToV17Transformer } from './transformers/v16-to-v17';
18-
export { BaseTransformer, TransformerVisitor, TransformerContext } from './visitors/base';
1918

2019
export { PG13Node, PG14Node, PG15Node, PG16Node, PG17Node, PG13Types, PG14Types, PG15Types, PG16Types, PG17Types };

0 commit comments

Comments
 (0)