@@ -103,7 +103,9 @@ export const createDeconfigResource = <
103103 } ) ;
104104
105105 // Filter files that end with .json
106- const allFiles = Object . entries ( filesList . files )
106+ const allFiles = Object . entries (
107+ ( filesList as { files : Record < string , unknown > } ) . files ,
108+ )
107109 . filter ( ( [ path ] ) => path . endsWith ( ".json" ) )
108110 . map ( ( [ path , metadata ] ) => ( {
109111 path,
@@ -189,8 +191,20 @@ export const createDeconfigResource = <
189191 aValue = getMetadataString ( a . metadata , "description" ) || "" ;
190192 bValue = getMetadataString ( b . metadata , "description" ) || "" ;
191193 } else {
192- aValue = a . metadata . mtime ;
193- bValue = b . metadata . mtime ;
194+ aValue =
195+ typeof a . metadata === "object" &&
196+ a . metadata &&
197+ "mtime" in a . metadata &&
198+ typeof a . metadata . mtime === "number"
199+ ? a . metadata . mtime
200+ : 0 ;
201+ bValue =
202+ typeof b . metadata === "object" &&
203+ b . metadata &&
204+ "mtime" in b . metadata &&
205+ typeof b . metadata . mtime === "number"
206+ ? b . metadata . mtime
207+ : 0 ;
194208 }
195209
196210 if ( sortOrder === "desc" ) {
@@ -226,11 +240,17 @@ export const createDeconfigResource = <
226240 uri,
227241 data : { name, description } ,
228242 created_at :
229- "ctime" in metadata && typeof metadata . ctime === "number"
243+ typeof metadata === "object" &&
244+ metadata &&
245+ "ctime" in metadata &&
246+ typeof metadata . ctime === "number"
230247 ? new Date ( metadata . ctime ) . toISOString ( )
231248 : undefined ,
232249 updated_at :
233- "mtime" in metadata && typeof metadata . mtime === "number"
250+ typeof metadata === "object" &&
251+ metadata &&
252+ "mtime" in metadata &&
253+ typeof metadata . mtime === "number"
234254 ? new Date ( metadata . mtime ) . toISOString ( )
235255 : undefined ,
236256 created_by : getMetadataString ( metadata , "createdBy" ) ,
@@ -264,12 +284,16 @@ export const createDeconfigResource = <
264284 const filePath = ResourcePath . build ( directory , resourceId ) ;
265285
266286 try {
267- const fileData = await deconfig . READ_FILE ( {
287+ const fileData = ( await deconfig . READ_FILE ( {
268288 path : filePath ,
269289 format : "plainString" ,
270- } ) ;
290+ } ) ) as {
291+ content : string ;
292+ ctime : number ;
293+ mtime : number ;
294+ } ;
271295
272- const content = fileData . content as string ;
296+ const content = fileData . content ;
273297
274298 // Parse the JSON content
275299 let parsedData : Record < string , unknown > = { } ;
@@ -285,8 +309,14 @@ export const createDeconfigResource = <
285309 return {
286310 uri,
287311 data : validatedData ,
288- created_at : new Date ( fileData . ctime ) . toISOString ( ) ,
289- updated_at : new Date ( fileData . mtime ) . toISOString ( ) ,
312+ created_at :
313+ typeof fileData . ctime === "number"
314+ ? new Date ( fileData . ctime ) . toISOString ( )
315+ : new Date ( ) . toISOString ( ) ,
316+ updated_at :
317+ typeof fileData . mtime === "number"
318+ ? new Date ( fileData . mtime ) . toISOString ( )
319+ : new Date ( ) . toISOString ( ) ,
290320 created_by :
291321 parsedData &&
292322 "created_by" in parsedData &&
@@ -347,7 +377,7 @@ export const createDeconfigResource = <
347377 } ;
348378
349379 const fileContent = JSON . stringify ( resourceData , null , 2 ) ;
350- const putResult = await deconfig . PUT_FILE ( {
380+ const putResult = ( await deconfig . PUT_FILE ( {
351381 path : filePath ,
352382 content : fileContent ,
353383 metadata : {
@@ -357,7 +387,7 @@ export const createDeconfigResource = <
357387 name : validatedData . name || resourceId ,
358388 description : validatedData . description || "" ,
359389 } ,
360- } ) ;
390+ } ) ) as { conflict ?: boolean } ;
361391
362392 if ( putResult . conflict ) {
363393 throw new UserInputError (
@@ -393,11 +423,11 @@ export const createDeconfigResource = <
393423 // Read existing file to get current data
394424 let existingData : Record < string , unknown > = { } ;
395425 try {
396- const fileData = await deconfig . READ_FILE ( {
426+ const fileData = ( await deconfig . READ_FILE ( {
397427 path : filePath ,
398428 format : "plainString" ,
399- } ) ;
400- existingData = JSON . parse ( fileData . content as string ) ;
429+ } ) ) as { content : string } ;
430+ existingData = JSON . parse ( fileData . content ) ;
401431 } catch {
402432 throw new NotFoundError ( `Resource not found: ${ uri } ` ) ;
403433 }
@@ -429,7 +459,7 @@ export const createDeconfigResource = <
429459
430460 const fileContent = JSON . stringify ( updatedData , null , 2 ) ;
431461
432- const putResult = await deconfig . PUT_FILE ( {
462+ const putResult = ( await deconfig . PUT_FILE ( {
433463 path : filePath ,
434464 content : fileContent ,
435465 metadata : {
@@ -439,7 +469,7 @@ export const createDeconfigResource = <
439469 name : validatedData . name || resourceId ,
440470 description : validatedData . description || "" ,
441471 } ,
442- } ) ;
472+ } ) ) as { conflict ?: boolean } ;
443473
444474 if ( putResult . conflict ) {
445475 throw new UserInputError (
0 commit comments