Skip to content

Commit de3d2f3

Browse files
committed
fix(code-gen): various type issues in the TS postgres generator
1 parent c40137e commit de3d2f3

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

packages/code-gen/src/database/ts-postgres.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export function tsPostgresGenerateUtils(generateContext) {
5454
JavascriptImportCollector.getImportCollector(indexFile);
5555

5656
helperImportCollector.destructure("@compas/stdlib", "AppError");
57+
helperTypeImportCollector.destructure("@compas/store", "Postgres");
5758
helperTypeImportCollector.destructure("@compas/store", "QueryPart");
5859
helperTypeImportCollector.destructure("@compas/store", "WrappedQueryPart");
5960
helperTypeImportCollector.destructure("@compas/store", "WrappedQueryResult");
@@ -1172,13 +1173,13 @@ export function tsPostgresGenerateQueryBuilder(
11721173
// Function
11731174
fileBlockStart(
11741175
file,
1175-
`export function query${upperCaseFirst(model.name)}<QueryBuilder extends ${contextNames.queryBuilderType.inputType}>(input: QueryBuilder = {}): WrappedQueryResult<${fullTypeName}QueryResolver<QueryBuilder>>`,
1176+
`export function query${upperCaseFirst(model.name)}<QueryBuilder extends ${contextNames.queryBuilderType.inputType}>(input?: QueryBuilder): WrappedQueryResult<${fullTypeName}QueryResolver<QueryBuilder>>`,
11761177
);
11771178

11781179
// Input validation
11791180
fileWrite(
11801181
file,
1181-
`const { error, value: validatedInput } = ${contextNames.queryBuilderType.validatorFunction}(input);`,
1182+
`const { error, value: validatedInput } = ${contextNames.queryBuilderType.validatorFunction}(input ?? {});`,
11821183
);
11831184
fileBlockStart(file, `if (error)`);
11841185
fileWrite(
@@ -1198,7 +1199,7 @@ export function tsPostgresGenerateQueryBuilder(
11981199
contextNames.queryResultType.validatorFunction
11991200
}, { hasCustomReturning: validatedInput.select?.length !== ${
12001201
Object.keys(model.keys).length
1201-
}, });`,
1202+
}, }) as unknown as WrappedQueryResult<${fullTypeName}QueryResolver<QueryBuilder>>;`,
12021203
);
12031204

12041205
fileBlockEnd(file);

packages/code-gen/src/processors/models.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export function modelQueryPartType() {
3838
tsPostgres: {
3939
validatorImport: `import { isQueryPart } from "@compas/store";\nimport type { QueryPart } from "@compas/store";`,
4040
validatorExpression: `isQueryPart($value$)`,
41-
validatorInputType: `(QueryPart)`,
42-
validatorOutputType: `(QueryPart)`,
41+
validatorInputType: `(import("@compas/store").QueryPart)`,
42+
validatorOutputType: `(import("@compas/store").QueryPart)`,
4343
},
4444
});
4545
}

0 commit comments

Comments
 (0)