Skip to content

Commit 968a591

Browse files
authored
chore: upgrade thv bin (#479)
* chore: upgrade thv * chore: update generated openapi * chore: ignore all generated files * fix: import client * chore: remove unneeded dep * leftover
1 parent 8e968ca commit 968a591

File tree

19 files changed

+1417
-24
lines changed

19 files changed

+1417
-24
lines changed

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default tseslint.config(
1111
'coverage',
1212
'.vite',
1313
'out',
14-
'renderer/src/common/api/generated',
14+
'renderer/src/common/api/generated/**',
1515
],
1616
},
1717
{

main/src/graceful-exit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { createClient } from '@hey-api/client-fetch'
21
import {
32
getApiV1BetaWorkloads,
43
postApiV1BetaWorkloadsByNameStop,
54
} from '../../renderer/src/common/api/generated/sdk.gen'
5+
import { createClient } from '../../renderer/src/common/api/generated/client'
66
import type { WorkloadsWorkload } from '../../renderer/src/common/api/generated/types.gen'
77
import Store from 'electron-store'
88
import log from './logger'

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
"@fontsource-variable/inter": "^5.2.6",
9191
"@fontsource/atkinson-hyperlegible": "^5.2.6",
9292
"@fontsource/space-mono": "^5.2.7",
93-
"@hey-api/client-fetch": "^0.13.0",
9493
"@radix-ui/react-checkbox": "^1.3.2",
9594
"@radix-ui/react-dialog": "^1.1.14",
9695
"@radix-ui/react-dropdown-menu": "^2.1.15",

pnpm-lock.yaml

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

renderer/openapi-ts.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export default defineConfig({
1010
},
1111
plugins: [
1212
...defaultPlugins,
13-
'@hey-api/client-fetch',
1413
'@tanstack/react-query',
1514
{
1615
name: '@hey-api/typescript',

renderer/src/common/api/generated/client.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
type ClientOptions as DefaultClientOptions,
77
createClient,
88
createConfig,
9-
} from '@hey-api/client-fetch'
9+
} from './client'
1010

1111
/**
1212
* The `createClientConfig()` function will be called on client initialization
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
import type { Client, Config, RequestOptions } from './types'
2+
import {
3+
buildUrl,
4+
createConfig,
5+
createInterceptors,
6+
getParseAs,
7+
mergeConfigs,
8+
mergeHeaders,
9+
setAuthParams,
10+
} from './utils'
11+
12+
type ReqInit = Omit<RequestInit, 'body' | 'headers'> & {
13+
body?: any
14+
headers: ReturnType<typeof mergeHeaders>
15+
}
16+
17+
export const createClient = (config: Config = {}): Client => {
18+
let _config = mergeConfigs(createConfig(), config)
19+
20+
const getConfig = (): Config => ({ ..._config })
21+
22+
const setConfig = (config: Config): Config => {
23+
_config = mergeConfigs(_config, config)
24+
return getConfig()
25+
}
26+
27+
const interceptors = createInterceptors<
28+
Request,
29+
Response,
30+
unknown,
31+
RequestOptions
32+
>()
33+
34+
const request: Client['request'] = async (options) => {
35+
const opts = {
36+
..._config,
37+
...options,
38+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
39+
headers: mergeHeaders(_config.headers, options.headers),
40+
}
41+
42+
if (opts.security) {
43+
await setAuthParams({
44+
...opts,
45+
security: opts.security,
46+
})
47+
}
48+
49+
if (opts.requestValidator) {
50+
await opts.requestValidator(opts)
51+
}
52+
53+
if (opts.body && opts.bodySerializer) {
54+
opts.body = opts.bodySerializer(opts.body)
55+
}
56+
57+
// remove Content-Type header if body is empty to avoid sending invalid requests
58+
if (opts.body === undefined || opts.body === '') {
59+
opts.headers.delete('Content-Type')
60+
}
61+
62+
const url = buildUrl(opts)
63+
const requestInit: ReqInit = {
64+
redirect: 'follow',
65+
...opts,
66+
}
67+
68+
let request = new Request(url, requestInit)
69+
70+
for (const fn of interceptors.request._fns) {
71+
if (fn) {
72+
request = await fn(request, opts)
73+
}
74+
}
75+
76+
// fetch must be assigned here, otherwise it would throw the error:
77+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
78+
const _fetch = opts.fetch!
79+
let response = await _fetch(request)
80+
81+
for (const fn of interceptors.response._fns) {
82+
if (fn) {
83+
response = await fn(response, request, opts)
84+
}
85+
}
86+
87+
const result = {
88+
request,
89+
response,
90+
}
91+
92+
if (response.ok) {
93+
if (
94+
response.status === 204 ||
95+
response.headers.get('Content-Length') === '0'
96+
) {
97+
return opts.responseStyle === 'data'
98+
? {}
99+
: {
100+
data: {},
101+
...result,
102+
}
103+
}
104+
105+
const parseAs =
106+
(opts.parseAs === 'auto'
107+
? getParseAs(response.headers.get('Content-Type'))
108+
: opts.parseAs) ?? 'json'
109+
110+
let data: any
111+
switch (parseAs) {
112+
case 'arrayBuffer':
113+
case 'blob':
114+
case 'formData':
115+
case 'json':
116+
case 'text':
117+
data = await response[parseAs]()
118+
break
119+
case 'stream':
120+
return opts.responseStyle === 'data'
121+
? response.body
122+
: {
123+
data: response.body,
124+
...result,
125+
}
126+
}
127+
128+
if (parseAs === 'json') {
129+
if (opts.responseValidator) {
130+
await opts.responseValidator(data)
131+
}
132+
133+
if (opts.responseTransformer) {
134+
data = await opts.responseTransformer(data)
135+
}
136+
}
137+
138+
return opts.responseStyle === 'data'
139+
? data
140+
: {
141+
data,
142+
...result,
143+
}
144+
}
145+
146+
let error = await response.text()
147+
148+
try {
149+
error = JSON.parse(error)
150+
} catch {
151+
// noop
152+
}
153+
154+
let finalError = error
155+
156+
for (const fn of interceptors.error._fns) {
157+
if (fn) {
158+
finalError = (await fn(error, response, request, opts)) as string
159+
}
160+
}
161+
162+
finalError = finalError || ({} as string)
163+
164+
if (opts.throwOnError) {
165+
throw finalError
166+
}
167+
168+
// TODO: we probably want to return error and improve types
169+
return opts.responseStyle === 'data'
170+
? undefined
171+
: {
172+
error: finalError,
173+
...result,
174+
}
175+
}
176+
177+
return {
178+
buildUrl,
179+
connect: (options) => request({ ...options, method: 'CONNECT' }),
180+
delete: (options) => request({ ...options, method: 'DELETE' }),
181+
get: (options) => request({ ...options, method: 'GET' }),
182+
getConfig,
183+
head: (options) => request({ ...options, method: 'HEAD' }),
184+
interceptors,
185+
options: (options) => request({ ...options, method: 'OPTIONS' }),
186+
patch: (options) => request({ ...options, method: 'PATCH' }),
187+
post: (options) => request({ ...options, method: 'POST' }),
188+
put: (options) => request({ ...options, method: 'PUT' }),
189+
request,
190+
setConfig,
191+
trace: (options) => request({ ...options, method: 'TRACE' }),
192+
}
193+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export type { Auth } from '../core/auth'
2+
export type { QuerySerializerOptions } from '../core/bodySerializer'
3+
export {
4+
formDataBodySerializer,
5+
jsonBodySerializer,
6+
urlSearchParamsBodySerializer,
7+
} from '../core/bodySerializer'
8+
export { buildClientParams } from '../core/params'
9+
export { createClient } from './client'
10+
export type {
11+
Client,
12+
ClientOptions,
13+
Config,
14+
CreateClientConfig,
15+
Options,
16+
OptionsLegacyParser,
17+
RequestOptions,
18+
RequestResult,
19+
ResponseStyle,
20+
TDataShape,
21+
} from './types'
22+
export { createConfig, mergeHeaders } from './utils'

0 commit comments

Comments
 (0)