@@ -10,10 +10,7 @@ import {
1010} from "@trigger.dev/database" ;
1111
1212// Create a schema that validates TaskRunStatus enum values
13- const TaskRunStatusSchema = z . array ( z . string ( ) ) . refine (
14- ( val ) => val . every ( ( v ) => Object . values ( TaskRunStatusEnum ) . includes ( v ) ) ,
15- { message : "Invalid TaskRunStatus values" }
16- ) as unknown as z . ZodSchema < TaskRunStatus [ ] > ;
13+ const TaskRunStatusSchema = z . array ( z . nativeEnum ( TaskRunStatusEnum ) ) ;
1714import parseDuration from "parse-duration" ;
1815import { type Direction } from "~/components/ListPagination" ;
1916import { timeFilters } from "~/components/runs/v3/SharedFilters" ;
@@ -25,7 +22,7 @@ import {
2522 convertDateToClickhouseDateTime ,
2623 convertClickhouseDateTime64ToJsDate ,
2724} from "~/v3/eventRepository/clickhouseEventRepository.server" ;
28- import { kindToLevel , type LogLevel } from "~/utils/logUtils" ;
25+ import { kindToLevel , type LogLevel , LogLevelSchema } from "~/utils/logUtils" ;
2926
3027export type { LogLevel } ;
3128
@@ -56,6 +53,7 @@ export type LogsListOptions = {
5653 queues ?: string [ ] ;
5754 machines ?: MachinePresetName [ ] ;
5855 levels ?: LogLevel [ ] ;
56+ defaultPeriod ?: string ;
5957 // search
6058 search ?: string ;
6159 includeDebugLogs ?: boolean ;
@@ -82,8 +80,9 @@ export const LogsListOptionsSchema = z.object({
8280 batchId : z . string ( ) . optional ( ) ,
8381 runId : z . array ( z . string ( ) ) . optional ( ) ,
8482 queues : z . array ( z . string ( ) ) . optional ( ) ,
85- machines : z . array ( z . string ( ) ) . optional ( ) ,
86- levels : z . array ( z . enum ( [ "TRACE" , "DEBUG" , "INFO" , "WARN" , "ERROR" , "CANCELLED" ] ) ) . optional ( ) ,
83+ machines : z . array ( MachinePresetName ) . optional ( ) ,
84+ levels : z . array ( LogLevelSchema ) . optional ( ) ,
85+ defaultPeriod : z . string ( ) . optional ( ) ,
8786 search : z . string ( ) . max ( 1000 ) . optional ( ) ,
8887 includeDebugLogs : z . boolean ( ) . optional ( ) ,
8988 direction : z . enum ( [ "forward" , "backward" ] ) . optional ( ) ,
@@ -106,14 +105,26 @@ type LogCursor = {
106105 runId : string ;
107106} ;
108107
108+ const LogCursorSchema = z . object ( {
109+ startTime : z . string ( ) ,
110+ traceId : z . string ( ) ,
111+ spanId : z . string ( ) ,
112+ runId : z . string ( ) ,
113+ } ) ;
114+
109115function encodeCursor ( cursor : LogCursor ) : string {
110116 return Buffer . from ( JSON . stringify ( cursor ) ) . toString ( "base64" ) ;
111117}
112118
113119function decodeCursor ( cursor : string ) : LogCursor | null {
114120 try {
115121 const decoded = Buffer . from ( cursor , "base64" ) . toString ( "utf-8" ) ;
116- return JSON . parse ( decoded ) as LogCursor ;
122+ const parsed = JSON . parse ( decoded ) ;
123+ const validated = LogCursorSchema . safeParse ( parsed ) ;
124+ if ( ! validated . success ) {
125+ return null ;
126+ }
127+ return validated . data ;
117128 } catch {
118129 return null ;
119130 }
@@ -189,12 +200,14 @@ export class LogsListPresenter {
189200 cursor,
190201 pageSize = DEFAULT_PAGE_SIZE ,
191202 includeDebugLogs = true ,
203+ defaultPeriod,
192204 } : LogsListOptions
193205 ) {
194206 const time = timeFilters ( {
195207 period,
196208 from,
197209 to,
210+ defaultPeriod,
198211 } ) ;
199212
200213 let effectiveFrom = time . from ;
@@ -418,7 +431,7 @@ export class LogsListPresenter {
418431
419432 if ( levels && levels . length > 0 ) {
420433 const conditions : string [ ] = [ ] ;
421- const params : Record < string , any > = { } ;
434+ const params : Record < string , string [ ] > = { } ;
422435 const hasErrorOrCancelledLevel = levels . includes ( "ERROR" ) || levels . includes ( "CANCELLED" ) ;
423436
424437 for ( const level of levels ) {
@@ -451,7 +464,7 @@ export class LogsListPresenter {
451464 }
452465
453466 if ( conditions . length > 0 ) {
454- queryBuilder . where ( `(${ conditions . join ( " OR " ) } )` , params as any ) ;
467+ queryBuilder . where ( `(${ conditions . join ( " OR " ) } )` , params ) ;
455468 }
456469 }
457470
0 commit comments