1- import { type SupabaseContext } from "./supabaseContext" ;
2- // https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm
3- type DGSupabaseClient = any ;
1+ import type { SupabaseContext } from "./supabaseContext" ;
2+ import type { DGSupabaseClient } from "@repo/database/lib/client" ;
43
54const getAllNodesFromSupabase = async (
65 supabaseClient : DGSupabaseClient ,
@@ -22,7 +21,7 @@ const getAllNodesFromSupabase = async (
2221 return [ ] ;
2322 }
2423
25- const schemaIds = schemas . map ( ( s : { id : string } ) => s . id ) ;
24+ const schemaIds = schemas . map ( ( s : { id : number } ) => s . id ) ;
2625 let nodeResult : string [ ] = [ ] ;
2726
2827 if ( schemaIds . length > 0 ) {
@@ -50,10 +49,10 @@ const getAllNodesFromSupabase = async (
5049 nodeResult =
5150 conceptResponse . data
5251 ?. map (
53- ( c : { Content ?: { source_local_id : string } } ) =>
54- c . Content ?. source_local_id ,
52+ ( c : { Content ?: { source_local_id : string | null } } ) =>
53+ c . Content ?. source_local_id || null ,
5554 )
56- . filter ( ( id : string ) : id is string => ! ! id ) || [ ] ;
55+ . filter ( ( id : string | null ) : id is string => ! ! id ) || [ ] ;
5756 }
5857
5958 const blockContentResponse = await supabaseClient
@@ -73,8 +72,8 @@ const getAllNodesFromSupabase = async (
7372
7473 const blockResult =
7574 blockContentResponse . data
76- ?. map ( ( c : { source_local_id : string } ) => c . source_local_id )
77- . filter ( ( id : string ) : id is string => ! ! id ) || [ ] ;
75+ ?. map ( ( c : { source_local_id : string | null } ) => c . source_local_id )
76+ . filter ( ( id : string | null ) : id is string => ! ! id ) || [ ] ;
7877
7978 const result = [ ...new Set ( [ ...nodeResult , ...blockResult ] ) ] ;
8079
@@ -115,10 +114,10 @@ const getAllNodeSchemasFromSupabase = async (
115114 return (
116115 data
117116 ?. map (
118- ( c : { Content ?: { source_local_id : string } } ) =>
119- c . Content ?. source_local_id ,
117+ ( c : { Content ?: { source_local_id : string | null } } ) =>
118+ c . Content ?. source_local_id || null ,
120119 )
121- . filter ( ( id : string ) : id is string => ! ! id ) || [ ]
120+ . filter ( ( id : string | null ) : id is string => ! ! id ) || [ ]
122121 ) ;
123122 } catch ( error ) {
124123 console . error ( "Error in getAllNodeSchemasFromSupabase:" , error ) ;
@@ -133,7 +132,7 @@ const getNonExistentRoamUids = (nodeUids: string[]): string[] => {
133132 }
134133
135134 const results = window . roamAlphaAPI . q (
136- `[:find ?uid
135+ `[:find ?uid
137136 :in $ [?uid ...]
138137 :where (not [_ :block/uid ?uid])]` ,
139138 nodeUids ,
@@ -162,7 +161,7 @@ const deleteNodesFromSupabase = async (
162161 console . error ( "Failed to get content from Supabase:" , contentError ) ;
163162 }
164163
165- const contentIds = contentData ?. map ( ( c : { id : string } ) => c . id ) || [ ] ;
164+ const contentIds = contentData ?. map ( ( c : { id : number } ) => c . id ) || [ ] ;
166165
167166 if ( contentIds . length > 0 ) {
168167 const { error : conceptError } = await supabaseClient
@@ -219,7 +218,7 @@ const deleteNodeSchemasFromSupabase = async (
219218 return 0 ;
220219 }
221220
222- const schemaContentIds = schemaContentData . map ( ( c : { id : string } ) => c . id ) ;
221+ const schemaContentIds = schemaContentData . map ( ( c : { id : number } ) => c . id ) ;
223222
224223 const { data : schemaConceptData , error : schemaConceptError } =
225224 await supabaseClient
@@ -238,7 +237,7 @@ const deleteNodeSchemasFromSupabase = async (
238237 }
239238
240239 const schemaConceptIds = ( schemaConceptData || [ ] ) . map (
241- ( c : { id : string } ) => c . id ,
240+ ( c : { id : number } ) => c . id ,
242241 ) ;
243242
244243 let instanceConceptIds : number [ ] = [ ] ;
@@ -263,11 +262,11 @@ const deleteNodeSchemasFromSupabase = async (
263262 }
264263
265264 instanceConceptIds = ( instanceConceptData || [ ] ) . map (
266- ( ic : { id : string } ) => ic . id ,
265+ ( ic : { id : number } ) => ic . id ,
267266 ) ;
268267 instanceContentIds = ( instanceConceptData || [ ] )
269- . map ( ( ic : { represented_by_id : number } ) => ic . represented_by_id )
270- . filter ( ( x : number ) : x is number => typeof x === "number" ) ;
268+ . map ( ( ic : { represented_by_id : number | null } ) => ic . represented_by_id )
269+ . filter ( ( x : number | null ) : x is number => typeof x === "number" ) ;
271270
272271 if ( instanceContentIds . length > 0 ) {
273272 const { data : instanceContentData , error : instanceContentLookupError } =
@@ -284,8 +283,8 @@ const deleteNodeSchemasFromSupabase = async (
284283 return 0 ;
285284 }
286285 instanceSourceLocalIds = ( instanceContentData || [ ] )
287- . map ( ( c : { source_local_id : string } ) => c . source_local_id )
288- . filter ( ( id : string ) : id is string => ! ! id ) ;
286+ . map ( ( c : { source_local_id : string | null } ) => c . source_local_id )
287+ . filter ( ( id : string | null ) : id is string => ! ! id ) ;
289288 }
290289 }
291290
0 commit comments