fix: improve types for callback-related config (#135)
* fix: allow partial callbacks in config types * fix: allow non-async callback functions in config types * fix: specify type of monitor argument in callback type * fix: use generics type for env argument in callback typepull/140/head^2
parent
7156fd83f2
commit
5769a52f0c
|
|
@ -1,3 +1,5 @@
|
|||
import type { Env } from '../worker/src'
|
||||
|
||||
export type PageConfig = {
|
||||
title?: string
|
||||
links?: PageConfigLink[]
|
||||
|
|
@ -39,12 +41,12 @@ export type MonitorTarget = {
|
|||
checkProxyFallback?: boolean
|
||||
}
|
||||
|
||||
export type WorkerConfig = {
|
||||
export type WorkerConfig<TEnv = Env> = {
|
||||
kvWriteCooldownMinutes: number
|
||||
passwordProtection?: string
|
||||
monitors: MonitorTarget[]
|
||||
notification?: Notification
|
||||
callbacks?: Callbacks
|
||||
callbacks?: Callbacks<TEnv>
|
||||
}
|
||||
|
||||
export type Notification = {
|
||||
|
|
@ -55,22 +57,22 @@ export type Notification = {
|
|||
skipNotificationIds?: string[]
|
||||
}
|
||||
|
||||
export type Callbacks = {
|
||||
onStatusChange: (
|
||||
env: any,
|
||||
monitor: any,
|
||||
export type Callbacks<TEnv = Env> = {
|
||||
onStatusChange?: (
|
||||
env: TEnv,
|
||||
monitor: MonitorTarget,
|
||||
isUp: boolean,
|
||||
timeIncidentStart: number,
|
||||
timeNow: number,
|
||||
reason: string
|
||||
) => Promise<any>
|
||||
onIncident: (
|
||||
env: any,
|
||||
monitor: any,
|
||||
) => Promise<any> | any
|
||||
onIncident?: (
|
||||
env: TEnv,
|
||||
monitor: MonitorTarget,
|
||||
timeIncidentStart: number,
|
||||
timeNow: number,
|
||||
reason: string
|
||||
) => Promise<any>
|
||||
) => Promise<any> | any
|
||||
}
|
||||
|
||||
export type MonitorState = {
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ const Worker = {
|
|||
}
|
||||
|
||||
console.log('Calling config onStatusChange callback...')
|
||||
await workerConfig.callbacks?.onStatusChange(
|
||||
await workerConfig.callbacks?.onStatusChange?.(
|
||||
env,
|
||||
monitor,
|
||||
true,
|
||||
|
|
@ -250,7 +250,7 @@ const Worker = {
|
|||
|
||||
if (monitorStatusChanged) {
|
||||
console.log('Calling config onStatusChange callback...')
|
||||
await workerConfig.callbacks?.onStatusChange(
|
||||
await workerConfig.callbacks?.onStatusChange?.(
|
||||
env,
|
||||
monitor,
|
||||
false,
|
||||
|
|
@ -266,7 +266,7 @@ const Worker = {
|
|||
|
||||
try {
|
||||
console.log('Calling config onIncident callback...')
|
||||
await workerConfig.callbacks?.onIncident(
|
||||
await workerConfig.callbacks?.onIncident?.(
|
||||
env,
|
||||
monitor,
|
||||
currentIncident.start[0],
|
||||
|
|
|
|||
Loading…
Reference in New Issue