Skip to content

Commit da907f8

Browse files
committed
fix(pgsql-types): add enum imports to generated types
1 parent 3578008 commit da907f8

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

packages/pgsql-types/scripts/generate-types.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,26 @@ function isPrimitiveType(type: string): boolean {
3636
return type in primitiveTypeMap;
3737
}
3838

39+
function isEnumType(type: string): boolean {
40+
return !isPrimitiveType(type) && !schemaMap.has(type) && type !== 'Node';
41+
}
42+
3943
function getTsType(type: string): string {
4044
return primitiveTypeMap[type] || type;
4145
}
4246

47+
function collectEnumTypes(): Set<string> {
48+
const enumTypes = new Set<string>();
49+
for (const nodeSpec of runtimeSchema) {
50+
for (const field of nodeSpec.fields) {
51+
if (isEnumType(field.type)) {
52+
enumTypes.add(field.type);
53+
}
54+
}
55+
}
56+
return enumTypes;
57+
}
58+
4359
function generateWrappedUnion(tags: string[]): string {
4460
if (tags.length === 0) {
4561
return 'Node';
@@ -118,7 +134,13 @@ function generateTypes(metadata: AllFieldMetadata): string {
118134
lines.push(' */');
119135
lines.push('');
120136

137+
const enumTypes = collectEnumTypes();
138+
const sortedEnums = [...enumTypes].sort();
139+
121140
lines.push("import type { Node } from '@pgsql/types';");
141+
if (sortedEnums.length > 0) {
142+
lines.push(`import { ${sortedEnums.join(', ')} } from '@pgsql/enums';`);
143+
}
122144
lines.push("export type { Node } from '@pgsql/types';");
123145
lines.push("export * from '@pgsql/enums';");
124146
lines.push('');

packages/pgsql-types/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import type { Node } from '@pgsql/types';
10+
import { A_Expr_Kind, AggSplit, AlterPublicationAction, AlterSubscriptionType, AlterTSConfigType, AlterTableType, BoolExprType, BoolTestType, CTEMaterialize, CmdType, CoercionContext, CoercionForm, ConstrType, DefElemAction, DiscardMode, DropBehavior, FetchDirection, FunctionParameterMode, GrantTargetType, GroupingSetKind, ImportForeignSchemaType, JoinType, JsonBehaviorType, JsonConstructorType, JsonEncoding, JsonExprOp, JsonFormatType, JsonQuotes, JsonTableColumnType, JsonValueType, JsonWrapper, KeywordKind, LimitOption, LockClauseStrength, LockWaitPolicy, MergeMatchKind, MinMaxOp, NullTestType, ObjectType, OnCommitAction, OnConflictAction, OverridingKind, ParamKind, PartitionRangeDatumKind, PartitionStrategy, PublicationObjSpecType, QuerySource, RTEKind, ReindexObjectType, RoleSpecType, RoleStmtType, RowCompareType, SQLValueFunctionOp, SetOperation, SortByDir, SortByNulls, SubLinkType, TableFuncType, Token, TransactionStmtKind, VariableSetKind, ViewCheckOption, WCOKind, XmlExprOp, XmlOptionType } from '@pgsql/enums';
1011
export type { Node } from '@pgsql/types';
1112
export * from '@pgsql/enums';
1213

0 commit comments

Comments
 (0)