@@ -4,6 +4,7 @@ import JsonEncoder from "$lib/server/JsonEncoder";
44import { getMongo } from "$lib/server/mongo" ;
55import { isEmptyObject } from "$lib/utils/isEmptyObject" ;
66import { parseJSON } from "$lib/utils/jsonParser" ;
7+ import { logger } from "$lib/utils/logger" ;
78import { error } from "@sveltejs/kit" ;
89import { ObjectId , type Document } from "mongodb" ;
910import { z } from "zod" ;
@@ -21,6 +22,7 @@ export const addServer = command(
2122 url : z . string ( ) ,
2223 } ) ,
2324 async ( { url } ) => {
25+ logger . log ( "addServer called with payload:" , { url } ) ;
2426 const mongo = await getMongo ( ) ;
2527 await mongo . addServer ( url ) ;
2628 return { ok : true } ;
@@ -29,6 +31,7 @@ export const addServer = command(
2931
3032// Remove a server
3133export const removeServer = command ( z . string ( ) , async ( serverName ) => {
34+ logger . log ( "removeServer called with payload:" , { serverName } ) ;
3235 const mongo = await getMongo ( ) ;
3336 await mongo . removeServer ( serverName ) ;
3437 return { ok : true } ;
@@ -46,6 +49,7 @@ export const updateDocument = command(
4649 upsert : z . boolean ( ) . optional ( ) . default ( false ) ,
4750 } ) ,
4851 async ( { server, database, collection, document, value, partial, upsert } ) => {
52+ logger . log ( "updateDocument called with payload:" , { server, database, collection, document, partial, upsert } ) ;
4953 checkReadOnly ( ) ;
5054
5155 const mongo = await getMongo ( ) ;
@@ -96,6 +100,7 @@ export const insertDocument = command(
96100 value : z . unknown ( ) ,
97101 } ) ,
98102 async ( { server, database, collection, document, value } ) => {
103+ logger . log ( "insertDocument called with payload:" , { server, database, collection, document } ) ;
99104 checkReadOnly ( ) ;
100105
101106 const mongo = await getMongo ( ) ;
@@ -130,6 +135,7 @@ export const deleteDocument = command(
130135 document : z . string ( ) ,
131136 } ) ,
132137 async ( { server, database, collection, document } ) => {
138+ logger . log ( "deleteDocument called with payload:" , { server, database, collection, document } ) ;
133139 checkReadOnly ( ) ;
134140
135141 const mongo = await getMongo ( ) ;
@@ -162,6 +168,7 @@ export const updateMany = command(
162168 update : z . string ( ) ,
163169 } ) ,
164170 async ( { server, database, collection, filter, update } ) => {
171+ logger . log ( "updateMany called with payload:" , { server, database, collection, filter, update } ) ;
165172 checkReadOnly ( ) ;
166173
167174 const mongo = await getMongo ( ) ;
@@ -190,6 +197,7 @@ export const hideIndex = command(
190197 index : z . string ( ) ,
191198 } ) ,
192199 async ( { server, database, collection, index } ) => {
200+ logger . log ( "hideIndex called with payload:" , { server, database, collection, index } ) ;
193201 checkReadOnly ( ) ;
194202
195203 const mongo = await getMongo ( ) ;
@@ -218,6 +226,7 @@ export const unhideIndex = command(
218226 index : z . string ( ) ,
219227 } ) ,
220228 async ( { server, database, collection, index } ) => {
229+ logger . log ( "unhideIndex called with payload:" , { server, database, collection, index } ) ;
221230 checkReadOnly ( ) ;
222231
223232 const mongo = await getMongo ( ) ;
@@ -246,6 +255,7 @@ export const dropIndex = command(
246255 index : z . string ( ) ,
247256 } ) ,
248257 async ( { server, database, collection, index } ) => {
258+ logger . log ( "dropIndex called with payload:" , { server, database, collection, index } ) ;
249259 checkReadOnly ( ) ;
250260
251261 const mongo = await getMongo ( ) ;
@@ -270,6 +280,7 @@ export const dropCollection = command(
270280 collection : z . string ( ) ,
271281 } ) ,
272282 async ( { server, database, collection } ) => {
283+ logger . log ( "dropCollection called with payload:" , { server, database, collection } ) ;
273284 checkReadOnly ( ) ;
274285
275286 const mongo = await getMongo ( ) ;
@@ -286,6 +297,7 @@ export const dropCollection = command(
286297
287298// Retry connection to a server
288299export const retryConnection = command ( z . string ( ) , async ( serverName ) => {
300+ logger . log ( "retryConnection called with payload:" , { serverName } ) ;
289301 const mongo = await getMongo ( ) ;
290302
291303 // Reconnect the client (closes old connection and creates a new one)
@@ -368,7 +380,7 @@ export const loadDocuments = query(
368380 isAggregation : true ,
369381 } ;
370382 } catch ( err ) {
371- console . error ( "Error executing aggregation:" , err ) ;
383+ logger . error ( "Error executing aggregation:" , err ) ;
372384 error ( 500 , `Failed to execute aggregation: ${ err instanceof Error ? err . message : String ( err ) } ` ) ;
373385 }
374386 }
@@ -390,7 +402,7 @@ export const loadDocuments = query(
390402 isAggregation : false ,
391403 } ;
392404 } catch ( err ) {
393- console . error ( "Error fetching query results:" , err ) ;
405+ logger . error ( "Error fetching query results:" , err ) ;
394406 error ( 500 , `Failed to fetch query results: ${ err instanceof Error ? err . message : String ( err ) } ` ) ;
395407 }
396408 } ,
@@ -431,7 +443,7 @@ export const fetchMappedDocument = query(
431443 } ;
432444 }
433445 } catch ( err ) {
434- console . error ( `Error fetching mapped document from ${ mapping . collection } .${ mapping . on } :` , err ) ;
446+ logger . error ( `Error fetching mapped document from ${ mapping . collection } .${ mapping . on } :` , err ) ;
435447 // Continue to next mapping on error
436448 continue ;
437449 }
0 commit comments