@@ -10,6 +10,7 @@ import * as protobuf from 'protobufjs';
1010import { EventEmitter } from 'stream' ;
1111import { FlightClient , FlightInfo , DescriptorType , Ticket } from '../flight' ;
1212import { platform } from '../platform/node' ;
13+ import { Logger } from '../logger' ;
1314// Note: Flight SQL prepared statements are not currently supported by the Spice server.
1415// The server uses a custom protocol. For parameterized queries, we use client-side substitution.
1516// This is secure for the supported use cases and matches the HTTP API behavior.
@@ -36,9 +37,9 @@ let grpcAvailable = false;
3637/**
3738 * Downloads the Flight.proto file from the remote URL and keeps it in memory
3839 */
39- async function downloadProtoFile ( ) : Promise < string > {
40+ async function downloadProtoFile ( logger ?: Logger ) : Promise < string > {
4041 try {
41- console . log ( '[spice.js] Downloading Flight.proto from remote source...' ) ;
42+ logger ?. info ( '[spice.js] Downloading Flight.proto from remote source...' ) ;
4243 const response = await platform . fetch ( PROTO_DOWNLOAD_URL , {
4344 method : 'GET' ,
4445 headers : { } ,
@@ -51,11 +52,11 @@ async function downloadProtoFile(): Promise<string> {
5152 }
5253
5354 const content = await response . text ( ) ;
54- console . log ( '[spice.js] Flight.proto downloaded successfully' ) ;
55+ logger ?. info ( '[spice.js] Flight.proto downloaded successfully' ) ;
5556
5657 return content ;
5758 } catch ( error : any ) {
58- console . warn ( `[spice.js] Failed to download proto file: ${ error . message } ` ) ;
59+ logger ? .warn ( `[spice.js] Failed to download proto file: ${ error . message } ` ) ;
5960 throw error ;
6061 }
6162}
@@ -64,15 +65,15 @@ async function downloadProtoFile(): Promise<string> {
6465 * Loads proto content from local file or downloads it
6566 * Returns the proto content as a string
6667 */
67- async function loadProtoContent ( ) : Promise < string | null > {
68+ async function loadProtoContent ( logger ?: Logger ) : Promise < string | null > {
6869 // Try local file first
6970 if ( fs . existsSync ( fullProtoPath ) ) {
7071 return fs . readFileSync ( fullProtoPath , 'utf-8' ) ;
7172 }
7273
7374 // Try to download
7475 try {
75- return await downloadProtoFile ( ) ;
76+ return await downloadProtoFile ( logger ) ;
7677 } catch ( error ) {
7778 return null ;
7879 }
@@ -81,7 +82,7 @@ async function loadProtoContent(): Promise<string | null> {
8182/**
8283 * Loads proto definition from content in memory using protobufjs
8384 */
84- function loadProtoFromContent ( content : string ) : any {
85+ function loadProtoFromContent ( content : string , logger ?: Logger ) : any {
8586 try {
8687 // Parse the proto content directly in memory using protobufjs
8788 const root = protobuf . parse ( content , { keepCase : false } ) . root ;
@@ -101,7 +102,7 @@ function loadProtoFromContent(content: string): any {
101102 const arrow = grpc . loadPackageDefinition ( packageDefinition ) . arrow as any ;
102103 return arrow . flight . protocol ;
103104 } catch ( error : any ) {
104- console . warn (
105+ logger ?. info (
105106 '[spice.js] Failed to load proto from content:' ,
106107 error . message ,
107108 ) ;
@@ -137,17 +138,20 @@ export class GrpcFlightClient {
137138 private flightTlsEnabled : boolean ;
138139 private initPromise : Promise < void > ;
139140 private useGrpc : boolean = grpcAvailable ;
141+ private logger : Logger ;
140142
141143 constructor (
142144 apiKey : string | undefined ,
143145 flightUrl : string ,
144146 userAgent : string ,
145147 flightTlsEnabled : boolean ,
148+ logger ?: Logger ,
146149 ) {
147150 this . apiKey = apiKey ;
148151 this . flightUrl = flightUrl ;
149152 this . userAgent = userAgent ;
150153 this . flightTlsEnabled = flightTlsEnabled ;
154+ this . logger = logger || new Logger ( true ) ;
151155 this . initPromise = this . initialize ( ) ;
152156 }
153157
@@ -163,7 +167,7 @@ export class GrpcFlightClient {
163167 try {
164168 // Check if we already have proto content in memory
165169 if ( ! protoContent ) {
166- protoContent = await loadProtoContent ( ) ;
170+ protoContent = await loadProtoContent ( this . logger ) ;
167171 }
168172
169173 if ( ! protoContent ) {
@@ -172,7 +176,7 @@ export class GrpcFlightClient {
172176 }
173177
174178 // Load the proto from content
175- const proto = loadProtoFromContent ( protoContent ) ;
179+ const proto = loadProtoFromContent ( protoContent , this . logger ) ;
176180
177181 if ( ! proto ?. FlightService ) {
178182 throw new Error ( 'Invalid proto file structure' ) ;
@@ -182,7 +186,7 @@ export class GrpcFlightClient {
182186 grpcAvailable = true ;
183187 this . useGrpc = true ;
184188 } catch ( error : any ) {
185- console . warn (
189+ this . logger . warn (
186190 `[spice.js] gRPC initialization failed: ${ error . message } . Using HTTP endpoint.` ,
187191 ) ;
188192 this . useGrpc = false ;
0 commit comments