Skip to content

Commit

Permalink
feat(renterd-libs): add patch methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Nov 19, 2024
1 parent e5f19b0 commit f9c8748
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/moody-rocks-flow.md
Original file line number Diff line number Diff line change
@@ -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.
32 changes: 32 additions & 0 deletions libs/renterd-js/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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<AlertsParams, AlertsPayload, AlertsResponse>(
axios,
'get',
Expand Down
4 changes: 2 additions & 2 deletions libs/renterd-react/src/autopilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ 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)
Expand Down
85 changes: 85 additions & 0 deletions libs/renterd-react/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
HookArgsCallback,
HookArgsWithPayloadSwr,
delay,
usePatchFunc,
} from '@siafoundation/react-core'
import {
getMainnetBlockHeight,
Expand Down Expand Up @@ -239,6 +240,18 @@ import {
SettingsUploadUpdateParams,
SettingsUploadUpdatePayload,
SettingsUploadUpdateResponse,
SettingsGougingPatchResponse,
SettingsGougingPatchPayload,
SettingsGougingPatchParams,
SettingsPinnedPatchParams,
SettingsPinnedPatchPayload,
SettingsPinnedPatchResponse,
SettingsS3PatchParams,
SettingsS3PatchPayload,
SettingsS3PatchResponse,
SettingsUploadPatchParams,
SettingsUploadPatchPayload,
SettingsUploadPatchResponse,
SettingsPinnedResponse,
busObjectsRemoveRoute,
ConsensusNetworkParams,
Expand Down Expand Up @@ -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<AlertsParams, AlertsResponse>) {
return useGetSwr({ ...args, route: busAlertsRoute })
Expand Down
17 changes: 17 additions & 0 deletions libs/renterd-types/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
SettingsUpload,
SlabSlice,
} from './types'
import { DeepPartial } from './utils'

export const busStateRoute = '/bus/state'
export const busAutopilotsRoute = '/bus/autopilots'
Expand Down Expand Up @@ -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<SettingsGouging>
export type SettingsGougingPatchResponse = SettingsGouging

export type SettingsPinnedPatchParams = void
export type SettingsPinnedPatchPayload = DeepPartial<SettingsPinned>
export type SettingsPinnedPatchResponse = SettingsPinned

export type SettingsS3PatchParams = void
export type SettingsS3PatchPayload = DeepPartial<SettingsS3>
export type SettingsS3PatchResponse = SettingsS3

export type SettingsUploadPatchParams = void
export type SettingsUploadPatchPayload = DeepPartial<SettingsUpload>
export type SettingsUploadPatchResponse = SettingsUpload
3 changes: 3 additions & 0 deletions libs/renterd-types/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object | undefined ? DeepPartial<T[P]> : T[P]
}

0 comments on commit f9c8748

Please sign in to comment.