Skip to content

Commit b8e9f38

Browse files
authored
Regen API client with proper nullable fields (#2821)
* manually copy over nullable change from oxide.ts for testing * fix 165 type errors * bump generator and regen client properly * put a null auto_restart_policy in the mock data
1 parent f097ec9 commit b8e9f38

File tree

20 files changed

+678
-620
lines changed

20 files changed

+678
-620
lines changed

app/api/__generated__/Api.ts

Lines changed: 299 additions & 295 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/api/__generated__/validate.ts

Lines changed: 334 additions & 292 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/api/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { navToLogin } from './nav-to-login'
3131
type Params<F> = F extends (p: infer P) => any ? P : never
3232
type Result<F> = F extends (p: any) => Promise<ApiResult<infer R>> ? R : never
3333

34-
export type ResultsPage<TItem> = { items: TItem[]; nextPage?: string }
34+
export type ResultsPage<TItem> = { items: TItem[]; nextPage?: string | null }
3535

3636
type ApiClient = Record<string, (...args: any) => Promise<ApiResult<any>>>
3737
/* eslint-enable @typescript-eslint/no-explicit-any */

app/components/InstanceAutoRestartPopover.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { CloseButton, Popover, PopoverButton, PopoverPanel } from '@headlessui/r
99
import { formatDistanceToNow } from 'date-fns'
1010
import { type ReactNode } from 'react'
1111
import { Link } from 'react-router'
12-
import { match } from 'ts-pattern'
12+
import { match, P } from 'ts-pattern'
1313

1414
import {
1515
AutoRestart12Icon,
@@ -69,7 +69,7 @@ export const InstanceAutoRestartPopover = ({ instance }: { instance: Instance })
6969
</Badge>
7070
))
7171
.with('best_effort', () => <Badge>best effort</Badge>)
72-
.with(undefined, () => <Badge color="neutral">Default</Badge>)
72+
.with(P.nullish, () => <Badge color="neutral">Default</Badge>)
7373
.exhaustive()}
7474
<div className="transition-transform group-hover:translate-x-1">
7575
<NextArrow12Icon />

app/components/form/fields/useItemsList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function customRouterFormToData(value: string): string | undefined {
2424
}
2525

2626
/** Convert value from response body to form value */
27-
export function customRouterDataToForm(value: string | undefined): string {
27+
export function customRouterDataToForm(value: string | undefined | null): string {
2828
return value || NO_ROUTER
2929
}
3030

app/components/oxql-metrics/util.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@ const utilizationQueryResult1: OxqlQueryResult = {
150150
{
151151
values: {
152152
type: 'double',
153-
// there is a bug in the client generator that makes this not allow nulls,
154-
// but we can in fact get them from the API for these values
155-
// @ts-expect-error
156153
values: [4991154550.953981, 5002306111.529594, 5005747970.58788, null],
157154
},
158155
metricType: 'gauge',

app/forms/network-interface-create.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import { useMemo } from 'react'
99
import { useForm } from 'react-hook-form'
10-
import type { SetRequired } from 'type-fest'
10+
import type { SetNonNullable, SetRequired } from 'type-fest'
1111

1212
import { useApiQuery, type ApiError, type InstanceNetworkInterfaceCreate } from '@oxide/api'
1313

@@ -20,7 +20,7 @@ import { SideModalForm } from '~/components/form/SideModalForm'
2020
import { useProjectSelector } from '~/hooks/use-params'
2121
import { FormDivider } from '~/ui/lib/Divider'
2222

23-
const defaultValues: SetRequired<InstanceNetworkInterfaceCreate, 'ip'> = {
23+
const defaultValues: SetRequired<SetNonNullable<InstanceNetworkInterfaceCreate>, 'ip'> = {
2424
name: '',
2525
description: '',
2626
ip: '',

app/forms/subnet-create.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
import { useForm } from 'react-hook-form'
99
import { useNavigate } from 'react-router'
10+
import type { SetNonNullable } from 'type-fest'
1011

1112
import { useApiMutation, useApiQueryClient, type VpcSubnetCreate } from '@oxide/api'
1213

@@ -27,7 +28,7 @@ import { addToast } from '~/stores/toast'
2728
import { FormDivider } from '~/ui/lib/Divider'
2829
import { pb } from '~/util/path-builder'
2930

30-
const defaultValues: Required<VpcSubnetCreate> = {
31+
const defaultValues: SetNonNullable<Required<VpcSubnetCreate>> = {
3132
name: '',
3233
description: '',
3334
ipv4Block: '',

app/forms/subnet-edit.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
import { useForm } from 'react-hook-form'
99
import { useNavigate, type LoaderFunctionArgs } from 'react-router'
10+
import type { SetNonNullable } from 'type-fest'
1011

1112
import {
1213
apiq,
@@ -61,7 +62,7 @@ export default function EditSubnetForm() {
6162
},
6263
})
6364

64-
const defaultValues: Required<VpcSubnetUpdate> = {
65+
const defaultValues: SetNonNullable<Required<VpcSubnetUpdate>> = {
6566
name: subnet.name,
6667
description: subnet.description,
6768
customRouter: customRouterDataToForm(subnet.customRouterId),

app/forms/vpc-router-route-common.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import type { UseFormReturn } from 'react-hook-form'
10+
import type { SetNonNullable } from 'type-fest'
1011

1112
import {
1213
usePrefetchedApiQuery,
@@ -26,7 +27,9 @@ import { Message } from '~/ui/lib/Message'
2627
import { ALL_ISH } from '~/util/consts'
2728
import { validateIp, validateIpNet } from '~/util/ip'
2829

29-
export type RouteFormValues = RouterRouteCreate | Required<RouterRouteUpdate>
30+
export type RouteFormValues =
31+
| RouterRouteCreate
32+
| SetNonNullable<Required<RouterRouteUpdate>>
3033

3134
export const routeFormMessage = {
3235
vpcSubnetNotModifiable:

0 commit comments

Comments
 (0)