-
Notifications
You must be signed in to change notification settings - Fork 173
fix(schema): support complex Drizzle method chaining patterns #3614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5fb89ca
f7a1816
2d2b473
7ab817b
f7cc245
ccf607b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@liam-hq/schema": patch | ||
--- | ||
|
||
🐛 fix(Drizzle parser): support chained methods like pgTable().enableRLS().$comment() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,9 +111,32 @@ export const isMemberExpression = ( | |
/** | ||
* Check if a call expression is a pgTable call | ||
*/ | ||
export const isPgTableCall = (callExpr: CallExpression): boolean => { | ||
const isPgTableCall = (callExpr: CallExpression): boolean => { | ||
FunamaYukina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return isIdentifierWithName(callExpr.callee, 'pgTable') | ||
} | ||
/** | ||
* Extract the base pgTable call from method chaining patterns | ||
* Handles patterns like: pgTable(...).enableRLS(), pgTable(...).comment(...), etc. | ||
*/ | ||
export const extractPgTableFromChain = ( | ||
callExpr: CallExpression, | ||
): CallExpression | null => { | ||
// If it's already a direct pgTable call, return it | ||
if (isPgTableCall(callExpr)) { | ||
return callExpr | ||
} | ||
|
||
// If it's a method call on another expression, check the object | ||
if (callExpr.callee.type === 'MemberExpression') { | ||
const baseCall = callExpr.callee.object | ||
if (baseCall.type === 'CallExpression') { | ||
// Recursively check if the base call is or contains a pgTable call | ||
return extractPgTableFromChain(baseCall) | ||
} | ||
} | ||
|
||
return null | ||
} | ||
Comment on lines
+114
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Broaden chain unwrapping utility to include schema.table(...). extractPgTableFromChain only finds pgTable; callers miss schema.table chains. Provide a general extractor that returns either pgTable(...) or schema.table(...). Apply (place after isSchemaTableCall to avoid TDZ): +/**
+ * Extract the base table call (pgTable(...) or schema.table(...)) from a chain.
+ */
+export const extractTableCallFromChain = (
+ callExpr: CallExpression,
+): CallExpression | null => {
+ if (isPgTableCall(callExpr) || isSchemaTableCall(callExpr)) {
+ return callExpr
+ }
+ if (callExpr.callee.type === 'MemberExpression') {
+ const base = callExpr.callee.object
+ if (base.type === 'CallExpression') {
+ return extractTableCallFromChain(base)
+ }
+ }
+ return null
+} Then use this in mainParser/tableParser (see suggested patches there). This keeps isPgTableCall private while enabling broader support. Based on learnings. 🤖 Prompt for AI Agents
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @coderabbitai |
||
|
||
/** | ||
* Check if a call expression is a schema.table() call | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for not only implementing
.enableRLS()
but also investigating Drizzle's syntax and making a universal fix! Great work!