Skip to content

Commit

Permalink
fix: check for {} type in inferFieldMetadata script
Browse files Browse the repository at this point in the history
Closes #3
  • Loading branch information
aleclarson committed Nov 6, 2024
1 parent eaa1634 commit 3e43e8f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
3 changes: 3 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"extends": ["@radashi-org/biome-config"],
"linter": {
"rules": {
"complexity": {
"noBannedTypes": "off"
},
"performance": {
"noDelete": "off"
},
Expand Down
17 changes: 13 additions & 4 deletions nodeFields.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"distinctClause": [
true,
[
"{}",
"ColumnRef",
"A_Const"
],
Expand Down Expand Up @@ -313,7 +314,9 @@
"A_Const": {
"ival": [
true,
null,
[
"{}"
],
null
],
"location": [
Expand All @@ -338,7 +341,9 @@
],
"boolval": [
true,
null,
[
"{}"
],
null
],
"bsval": [
Expand Down Expand Up @@ -668,6 +673,7 @@
[
"A_Const",
"FuncCall",
"{}",
"String",
"SubLink",
"ColumnRef",
Expand Down Expand Up @@ -733,6 +739,7 @@
],
[
"FuncCall",
"{}",
"List",
"SQLValueFunction",
"TypeCast",
Expand Down Expand Up @@ -1606,7 +1613,8 @@
true,
[
"List",
"Integer"
"Integer",
"{}"
],
[
"FunctionParameter"
Expand Down Expand Up @@ -1957,7 +1965,8 @@
"objargs": [
true,
[
"TypeName"
"TypeName",
"{}"
],
null
],
Expand Down
30 changes: 9 additions & 21 deletions scripts/generateTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ async function main() {
}
}

const renderTagType = (tag: string) =>
tag === '{}' ? tag : `{ ${tag}: ${tag} }`

const renderTagTypes = (tags: string[]) =>
tags.sort().map(renderTagType).join(' | ')

delete structsByModule['../backend/parser/gram']
delete structsByModule['../backend/parser/gramparse']
delete structsByModule['commands/vacuum']
Expand Down Expand Up @@ -337,13 +343,7 @@ async function main() {
fieldName,
inferredTags,
)
fieldType =
'(' +
inferredTags
.sort()
.map(tag => `{ ${tag}: ${tag} }`)
.join(' | ') +
')'
fieldType = '(' + renderTagTypes(inferredTags) + ')'
}
} else if (fieldType === 'any[]') {
const inferredListTags = fieldMetadata?.[fieldName]?.[2]
Expand All @@ -356,13 +356,7 @@ async function main() {
inferredListTags,
)

fieldType =
'List<' +
inferredListTags
.sort()
.map(tag => `{ ${tag}: ${tag} }`)
.join(' | ') +
'>'
fieldType = 'List<' + renderTagTypes(inferredListTags) + '>'

if (field.c_type === 'List*') {
fieldType += '[]'
Expand All @@ -379,13 +373,7 @@ async function main() {
inferredTags,
)

fieldType =
'(' +
inferredTags
.sort()
.map(tag => `{ ${tag}: ${tag} }`)
.join(' | ') +
')[]'
fieldType = '(' + renderTagTypes(inferredTags) + ')[]'
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions scripts/inferFieldMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const toNodeTag = (value: unknown) => {
if (keys.length === 1 && /^[A-Z]/.test(keys[0])) {
return keys[0]
}
if (keys.length === 0) {
return '{}'
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/lib/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,7 @@ export type RangeFunction = {
| { List: List }
| { SQLValueFunction: SQLValueFunction }
| { TypeCast: TypeCast }
| {}
>[]
/** table alias & optional column aliases */
alias?: Alias
Expand Down Expand Up @@ -2865,7 +2866,7 @@ export type SelectStmt = {
*/
/** NULL, list of DISTINCT ON exprs, or
* lcons(NIL,NIL) for all (SELECT DISTINCT) */
distinctClause?: ({ A_Const: A_Const } | { ColumnRef: ColumnRef })[]
distinctClause?: ({ A_Const: A_Const } | { ColumnRef: ColumnRef } | {})[]
/** target for SELECT INTO */
intoClause?: IntoClause
/** the target list (of ResTarget) */
Expand Down Expand Up @@ -3203,7 +3204,7 @@ export type ObjectWithArgs = {
/** qualified name of function/operator */
objname: QualifiedName
/** list of Typename nodes (input args only) */
objargs?: { TypeName: TypeName }[]
objargs?: ({ TypeName: TypeName } | {})[]
/** list of FunctionParameter nodes */
objfuncargs?: { FunctionParameter: FunctionParameter }[]
/** argument list was omitted? */
Expand Down

0 comments on commit 3e43e8f

Please sign in to comment.