diff --git a/.changeset/moody-rocks-flow.md b/.changeset/moody-rocks-flow.md new file mode 100644 index 000000000..f1fa60aab --- /dev/null +++ b/.changeset/moody-rocks-flow.md @@ -0,0 +1,7 @@ +--- +'@siafoundation/renterd-js': minor +'@siafoundation/renterd-react': minor +'@siafoundation/renterd-types': minor +--- + +Add settings gouging, pinned, s3, and upload patch APIs. diff --git a/.changeset/tiny-islands-fry.md b/.changeset/tiny-islands-fry.md new file mode 100644 index 000000000..9b0bd7031 --- /dev/null +++ b/.changeset/tiny-islands-fry.md @@ -0,0 +1,7 @@ +--- +'@siafoundation/renterd-js': minor +'@siafoundation/renterd-react': minor +'@siafoundation/renterd-types': minor +--- + +Add autopilot config patch API. diff --git a/libs/renterd-js/src/autopilot.ts b/libs/renterd-js/src/autopilot.ts index 49f4077d9..82bc40812 100644 --- a/libs/renterd-js/src/autopilot.ts +++ b/libs/renterd-js/src/autopilot.ts @@ -3,6 +3,9 @@ import { AutopilotConfigEvaluatePayload, AutopilotConfigEvaluateResponse, AutopilotConfigParams, + AutopilotConfigPatchParams, + AutopilotConfigPatchPayload, + AutopilotConfigPatchResponse, AutopilotConfigPayload, AutopilotConfigResponse, AutopilotConfigUpdateParams, @@ -45,6 +48,11 @@ export function Autopilot({ AutopilotConfigUpdatePayload, AutopilotConfigUpdateResponse >(axios, 'put', autopilotConfigRoute), + configPatch: buildRequestHandler< + AutopilotConfigPatchParams, + AutopilotConfigPatchPayload, + AutopilotConfigPatchResponse + >(axios, 'patch', autopilotConfigRoute), configEvaluate: buildRequestHandler< AutopilotConfigEvaluateParams, AutopilotConfigEvaluatePayload, diff --git a/libs/renterd-js/src/bus.ts b/libs/renterd-js/src/bus.ts index e52e659f9..d9f7b5a38 100644 --- a/libs/renterd-js/src/bus.ts +++ b/libs/renterd-js/src/bus.ts @@ -256,6 +256,18 @@ import { ConsensusNetworkPayload, ConsensusNetworkResponse, busConsensusNetworkRoute, + SettingsGougingPatchParams, + SettingsGougingPatchPayload, + SettingsGougingPatchResponse, + SettingsPinnedPatchParams, + SettingsPinnedPatchPayload, + SettingsPinnedPatchResponse, + SettingsS3PatchParams, + SettingsS3PatchPayload, + SettingsS3PatchResponse, + SettingsUploadPatchParams, + SettingsUploadPatchPayload, + SettingsUploadPatchResponse, } from '@siafoundation/renterd-types' import { buildRequestHandler, initAxios } from '@siafoundation/request' @@ -533,6 +545,26 @@ export function Bus({ api, password }: { api: string; password?: string }) { SettingsUploadUpdatePayload, SettingsUploadUpdateResponse >(axios, 'put', busSettingsUploadRoute), + settingsGougingPatch: buildRequestHandler< + SettingsGougingPatchParams, + SettingsGougingPatchPayload, + SettingsGougingPatchResponse + >(axios, 'patch', busSettingsGougingRoute), + settingsPinnedPatch: buildRequestHandler< + SettingsPinnedPatchParams, + SettingsPinnedPatchPayload, + SettingsPinnedPatchResponse + >(axios, 'patch', busSettingsPinnedRoute), + settingsS3Patch: buildRequestHandler< + SettingsS3PatchParams, + SettingsS3PatchPayload, + SettingsS3PatchResponse + >(axios, 'patch', busSettingsS3Route), + settingsUploadPatch: buildRequestHandler< + SettingsUploadPatchParams, + SettingsUploadPatchPayload, + SettingsUploadPatchResponse + >(axios, 'patch', busSettingsUploadRoute), alerts: buildRequestHandler( axios, 'get', diff --git a/libs/renterd-react/src/autopilot.ts b/libs/renterd-react/src/autopilot.ts index fed9bd0fb..db89483e1 100644 --- a/libs/renterd-react/src/autopilot.ts +++ b/libs/renterd-react/src/autopilot.ts @@ -7,6 +7,7 @@ import { HookArgsWithPayloadSwr, delay, usePostFunc, + usePatchFunc, } from '@siafoundation/react-core' import { AutopilotConfigParams, @@ -25,6 +26,9 @@ import { autopilotConfigRoute, autopilotStateRoute, autopilotTriggerRoute, + AutopilotConfigPatchParams, + AutopilotConfigPatchPayload, + AutopilotConfigPatchResponse, } from '@siafoundation/renterd-types' export function useAutopilotState( @@ -56,8 +60,30 @@ export function useAutopilotConfigUpdate( { ...args, route: autopilotConfigRoute }, async (mutate) => { mutate((key) => key === autopilotConfigRoute) - // might need a delay before revalidating status which returns whether - // or not autopilot is configured + // Might need a delay before revalidating status which returns whether + // or not autopilot is configured. + const func = async () => { + await delay(1000) + mutate((key) => key === autopilotStateRoute) + } + func() + } + ) +} + +export function useAutopilotConfigPatch( + args?: HookArgsCallback< + AutopilotConfigPatchParams, + AutopilotConfigPatchPayload, + AutopilotConfigPatchResponse + > +) { + return usePatchFunc( + { ...args, route: autopilotConfigRoute }, + async (mutate) => { + mutate((key) => key === autopilotConfigRoute) + // Might need a delay before revalidating status which returns whether + // or not autopilot is configured. const func = async () => { await delay(1000) mutate((key) => key === autopilotStateRoute) diff --git a/libs/renterd-react/src/bus.ts b/libs/renterd-react/src/bus.ts index 57d96f468..b621c788f 100644 --- a/libs/renterd-react/src/bus.ts +++ b/libs/renterd-react/src/bus.ts @@ -9,6 +9,7 @@ import { HookArgsCallback, HookArgsWithPayloadSwr, delay, + usePatchFunc, } from '@siafoundation/react-core' import { getMainnetBlockHeight, @@ -239,6 +240,18 @@ import { SettingsUploadUpdateParams, SettingsUploadUpdatePayload, SettingsUploadUpdateResponse, + SettingsGougingPatchResponse, + SettingsGougingPatchPayload, + SettingsGougingPatchParams, + SettingsPinnedPatchParams, + SettingsPinnedPatchPayload, + SettingsPinnedPatchResponse, + SettingsS3PatchParams, + SettingsS3PatchPayload, + SettingsS3PatchResponse, + SettingsUploadPatchParams, + SettingsUploadPatchPayload, + SettingsUploadPatchResponse, SettingsPinnedResponse, busObjectsRemoveRoute, ConsensusNetworkParams, @@ -833,6 +846,78 @@ export function useSettingsUploadUpdate( ) } +export function useSettingsGougingPatch( + args?: HookArgsCallback< + SettingsGougingPatchParams, + SettingsGougingPatchPayload, + SettingsGougingPatchResponse + > +) { + return usePatchFunc( + { + ...args, + route: busSettingsGougingRoute, + }, + async (mutate) => { + mutate((key) => key.startsWith(busSettingsGougingRoute)) + } + ) +} + +export function useSettingsPinnedPatch( + args?: HookArgsCallback< + SettingsPinnedPatchParams, + SettingsPinnedPatchPayload, + SettingsPinnedPatchResponse + > +) { + return usePatchFunc( + { + ...args, + route: busSettingsPinnedRoute, + }, + async (mutate) => { + mutate((key) => key.startsWith(busSettingsPinnedRoute)) + } + ) +} + +export function useSettingsS3Patch( + args?: HookArgsCallback< + SettingsS3PatchParams, + SettingsS3PatchPayload, + SettingsS3PatchResponse + > +) { + return usePatchFunc( + { + ...args, + route: busSettingsS3Route, + }, + async (mutate) => { + mutate((key) => key.startsWith(busSettingsS3Route)) + } + ) +} + +export function useSettingsUploadPatch( + args?: HookArgsCallback< + SettingsUploadPatchParams, + SettingsUploadPatchPayload, + SettingsUploadPatchResponse + > +) { + return usePatchFunc( + { + ...args, + route: busSettingsUploadRoute, + }, + async (mutate) => { + mutate((key) => key.startsWith(busSettingsUploadRoute)) + } + ) +} + // params are required because omitting them returns a deprecated response structure export function useAlerts(args?: HookArgsSwr) { return useGetSwr({ ...args, route: busAlertsRoute }) diff --git a/libs/renterd-types/src/autopilot.ts b/libs/renterd-types/src/autopilot.ts index 127742715..aacb0ba20 100644 --- a/libs/renterd-types/src/autopilot.ts +++ b/libs/renterd-types/src/autopilot.ts @@ -1,5 +1,6 @@ import { AutopilotConfig, SettingsGouging, SettingsRedundancy } from './types' import { BusStateResponse } from './bus' +import { DeepPartial } from './utils' export const autopilotStateRoute = '/autopilot/state' export const autopilotConfigRoute = '/autopilot/config' @@ -30,6 +31,10 @@ export type AutopilotConfigUpdateParams = void export type AutopilotConfigUpdatePayload = AutopilotConfig export type AutopilotConfigUpdateResponse = void +export type AutopilotConfigPatchParams = void +export type AutopilotConfigPatchPayload = DeepPartial +export type AutopilotConfigPatchResponse = AutopilotConfig + export type ConfigRecommendation = { gougingSettings: SettingsGouging } diff --git a/libs/renterd-types/src/bus.ts b/libs/renterd-types/src/bus.ts index 1c7a8ae5b..3d5551711 100644 --- a/libs/renterd-types/src/bus.ts +++ b/libs/renterd-types/src/bus.ts @@ -23,6 +23,7 @@ import { SettingsUpload, SlabSlice, } from './types' +import { DeepPartial } from './utils' export const busStateRoute = '/bus/state' export const busAutopilotsRoute = '/bus/autopilots' @@ -685,3 +686,19 @@ export type SettingsS3UpdateResponse = void export type SettingsUploadUpdateParams = void export type SettingsUploadUpdatePayload = SettingsUpload export type SettingsUploadUpdateResponse = void + +export type SettingsGougingPatchParams = void +export type SettingsGougingPatchPayload = DeepPartial +export type SettingsGougingPatchResponse = SettingsGouging + +export type SettingsPinnedPatchParams = void +export type SettingsPinnedPatchPayload = DeepPartial +export type SettingsPinnedPatchResponse = SettingsPinned + +export type SettingsS3PatchParams = void +export type SettingsS3PatchPayload = DeepPartial +export type SettingsS3PatchResponse = SettingsS3 + +export type SettingsUploadPatchParams = void +export type SettingsUploadPatchPayload = DeepPartial +export type SettingsUploadPatchResponse = SettingsUpload diff --git a/libs/renterd-types/src/utils.ts b/libs/renterd-types/src/utils.ts new file mode 100644 index 000000000..5323ec791 --- /dev/null +++ b/libs/renterd-types/src/utils.ts @@ -0,0 +1,3 @@ +export type DeepPartial = { + [P in keyof T]?: T[P] extends object | undefined ? DeepPartial : T[P] +}