@@ -23,6 +23,7 @@ export async function generateQueryBuilder({
23
23
addJsExtensionDeepPathsOfEdgedbLibrary ( qbDir ) ;
24
24
changeCustomScalars ( qbDir ) ;
25
25
updateEdgeQLRenderingForOurCustomScalars ( qbDir ) ;
26
+ updateCastMapsForOurCustomScalars ( qbDir ) ;
26
27
changeImplicitIDType ( qbDir ) ;
27
28
allowOrderingByEnums ( qbDir ) ;
28
29
mergeDefaultTypesWithModuleNames ( qbDir ) ;
@@ -67,6 +68,40 @@ function changeImplicitIDType(qbDir: Directory) {
67
68
) ;
68
69
}
69
70
71
+ function updateCastMapsForOurCustomScalars ( qbDir : Directory ) {
72
+ const file = qbDir . addSourceFileAtPath ( 'castMaps.ts' ) ;
73
+ file . insertImportDeclaration ( 1 , {
74
+ namedImports : [ 'DateTime' ] ,
75
+ moduleSpecifier : 'luxon' ,
76
+ } ) ;
77
+ file . insertImportDeclaration ( 1 , {
78
+ namedImports : [ 'CalendarDate' ] ,
79
+ moduleSpecifier : '~/common' ,
80
+ leadingTrivia : '\n' ,
81
+ } ) ;
82
+ const updated = file
83
+ . getText ( )
84
+ // Update Luxon instances to point to correct scalar UUIDs
85
+ . replace (
86
+ '(type instanceof Date)' ,
87
+ '(type instanceof Date || (type instanceof DateTime && !(type instanceof CalendarDate)))' ,
88
+ )
89
+ . replace (
90
+ '(type instanceof edgedb.LocalDate)' ,
91
+ '(type instanceof edgedb.LocalDate || type instanceof CalendarDate)' ,
92
+ ) ;
93
+ // Attempting to pick the right type based on shape.
94
+ // This doesn't fix any errors, and currently we are unable to distinguish
95
+ // CalendarDate from DateTime based on shape since they are the same.
96
+ // import * as _std from '../generated-client/modules/std';
97
+ // .replace(
98
+ // ' T extends Date ? scalarWithConstType<_std.$datetime, T> :\n',
99
+ // ' T extends CalendarDate ? scalarWithConstType<_cal.$local_date, T> :\n' +
100
+ // ' T extends Date | DateTime ? scalarWithConstType<_std.$datetime, T> :\n',
101
+ // )
102
+ file . replaceWithText ( updated ) ;
103
+ }
104
+
70
105
function updateEdgeQLRenderingForOurCustomScalars ( qbDir : Directory ) {
71
106
const file = qbDir . addSourceFileAtPath ( 'toEdgeQL.ts' ) ;
72
107
file . insertImportDeclaration ( 1 , {
0 commit comments