Skip to content

Commit

Permalink
fix: mark fields as optional if their comment contains "if any"
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Nov 6, 2024
1 parent a198989 commit 1fdb431
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion scripts/generateTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ async function main() {
const nullable =
(fieldMetadata
? fieldMetadata[fieldName]?.[0] ?? true
: /\b(NULL|NIL)\b/.test(field.comment ?? '')) ||
: /\b(NULL|NIL|if any)\b/.test(field.comment ?? '')) ||
nullableFields.has(fieldPath)

fieldTsDef += ` ${fieldName}${nullable ? '?' : ''}: ${fieldType}\n`
Expand Down
24 changes: 12 additions & 12 deletions src/lib/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2271,17 +2271,17 @@ export type WindowClause = {
/** window name (NULL in an OVER clause) */
name?: string
/** referenced window name, if any */
refname: string
refname?: string
/** PARTITION BY list */
partitionClause: any[]
/** ORDER BY list */
orderClause: any[]
/** frame_clause options, see WindowDef */
frameOptions: number
/** expression for starting bound, if any */
startOffset: Node
startOffset?: Node
/** expression for ending bound, if any */
endOffset: Node
endOffset?: Node
/** qual to help short-circuit execution */
runCondition: any[]
/** in_range function for startOffset */
Expand Down Expand Up @@ -2571,13 +2571,13 @@ export type JsonArrayQueryConstructor = {
*/
export type JsonAggConstructor = {
/** RETURNING clause, if any */
output: JsonOutput
output?: JsonOutput
/** FILTER clause, if any */
agg_filter: Node
agg_filter?: Node
/** ORDER BY clause, if any */
agg_order: any[]
agg_order?: any[]
/** OVER clause, if any */
over: WindowDef
over?: WindowDef
/** token location, or -1 if unknown */
location: number
}
Expand Down Expand Up @@ -2863,7 +2863,7 @@ export type PLAssignStmt = {
/** initial column name */
name: string
/** subscripts and field names, if any */
indirection: any[]
indirection?: any[]
/** number of names to use in ColumnRef */
nnames: number
/** the PL/pgSQL expression to assign */
Expand Down Expand Up @@ -4899,7 +4899,7 @@ export type Const = {
/** pg_type OID of the constant's datatype */
consttype: Oid
/** typmod value, if any */
consttypmod: number
consttypmod?: number
/** OID of collation, or InvalidOid if none */
constcollid: Oid
/** typlen of the constant's datatype */
Expand Down Expand Up @@ -5039,7 +5039,7 @@ export type Aggref = {
/** DISTINCT (list of SortGroupClause) */
aggdistinct: any[]
/** FILTER expression, if any */
aggfilter: Expr
aggfilter?: Expr
/** true if argument list was really '*' */
aggstar: boolean
/**
Expand Down Expand Up @@ -5119,7 +5119,7 @@ export type WindowFunc = {
/** arguments to the window function */
args: any[]
/** FILTER expression, if any */
aggfilter: Expr
aggfilter?: Expr
/** index of associated WindowClause */
winref: Index
/** true if argument list was really '*' */
Expand Down Expand Up @@ -6314,7 +6314,7 @@ export type FromExpr = {
/** List of join subtrees */
fromlist: any[]
/** qualifiers on join, if any */
quals: Node
quals?: Node
}

/**----------
Expand Down

0 comments on commit 1fdb431

Please sign in to comment.