fork of hey-api/openapi-ts because I need some additional things

docs: add migration notes for 0.89.0

Lubos 5898775b b6afac90

+4745 -57
+10 -8
dev/openapi-ts.config.ts
··· 107 107 // indexFile: false, 108 108 // lint: 'eslint', 109 109 nameConflictResolver({ attempt, baseName }) { 110 - console.log('resolving conflict for:', { attempt, baseName }); 110 + // console.log('resolving conflict for:', { attempt, baseName }); 111 111 return attempt === 0 ? baseName : `${baseName}_N${attempt + 1}`; 112 112 }, 113 113 path: path.resolve(__dirname, '.gen'), 114 - preferExportAll: true, 114 + // preferExportAll: true, 115 115 resolveModuleName: (moduleName) => { 116 116 if (moduleName === 'valibot') { 117 117 return 'valibot'; ··· 146 146 }, 147 147 hooks: { 148 148 events: { 149 + // 'node:set:after': ({ node, plugin }) => { 150 + // if (node) { 151 + // console.log(`(${plugin.name}) set node:`, node.symbol); 152 + // } 153 + // }, 154 + // 'node:set:before': ({ node, plugin }) => { 155 + // console.log(`(${plugin.name}) setting node:`, node?.symbol?.id); 156 + // }, 149 157 // 'plugin:handler:after': ({ plugin }) => { 150 158 // console.log(`(${plugin.name}): handler finished`); 151 159 // }, ··· 171 179 // ); 172 180 // } 173 181 }, 174 - // 'symbol:setValue:after': ({ plugin, symbol }) => { 175 - // console.log(`(${plugin.name}) set value:`, symbol.id); 176 - // }, 177 - // 'symbol:setValue:before': ({ plugin, symbol }) => { 178 - // console.log(`(${plugin.name}) setting value:`, symbol.id); 179 - // }, 180 182 }, 181 183 operations: { 182 184 getKind() {
+29 -2
docs/openapi-ts/configuration/output.md
··· 108 108 109 109 ::: 110 110 111 - ## Import File Extension 111 + ## Module Extension 112 112 113 - You can customize the extension used for imported TypeScript files. 113 + You can customize the extension used for TypeScript modules. 114 114 115 115 ::: code-group 116 116 ··· 257 257 ::: 258 258 259 259 You can also prevent your output from being linted by adding your output path to the linter's ignore file. 260 + 261 + ## Name Conflicts 262 + 263 + As your project grows, the chances of name conflicts increase. We use a simple conflict resolver that appends numeric suffixes to duplicate identifiers. If you prefer a different strategy, you can provide your own `nameConflictResolver` function. 264 + 265 + ::: code-group 266 + 267 + ```js [config] 268 + export default { 269 + input: 'hey-api/backend', // sign up at app.heyapi.dev 270 + output: { 271 + nameConflictResolver({ attempt, baseName }) { 272 + // [!code ++] 273 + return attempt === 0 ? baseName : `${baseName}_N${attempt + 1}`; // [!code ++] 274 + }, // [!code ++] 275 + path: 'src/client', 276 + }, 277 + }; 278 + ``` 279 + 280 + ```ts [example] 281 + export type ChatCompletion = string; 282 + 283 + export type ChatCompletion_N2 = number; 284 + ``` 285 + 286 + ::: 260 287 261 288 ## TSConfig Path 262 289
+22
docs/openapi-ts/migrating.md
··· 7 7 8 8 While we try to avoid breaking changes, sometimes it's unavoidable in order to offer you the latest features. This page lists changes that require updates to your code. If you run into a problem with migration, please [open an issue](https://github.com/hey-api/openapi-ts/issues). 9 9 10 + ## v0.89.0 11 + 12 + ### Prefer named exports 13 + 14 + This release changes the default for `index.ts` to prefer named exports. Named exports may lead to better IDE and bundler performance compared to asterisk (`*`) as your tooling doesn't have to inspect the underlying module to discover exports. 15 + 16 + While this change is merely cosmetic, you can set `output.preferExportAll` to `true` if you prefer to use the asterisk. 17 + 18 + ```js 19 + export default { 20 + input: 'hey-api/backend', // sign up at app.heyapi.dev 21 + output: { 22 + path: 'src/client', 23 + preferExportAll: true, // [!code ++] 24 + }, 25 + }; 26 + ``` 27 + 28 + ### Removed `symbol:setValue:*` events 29 + 30 + These events have been removed in favor of `node:set:*` events. 31 + 10 32 ## v0.88.0 11 33 12 34 ### Removed `compiler` and `tsc` exports
-4
docs/openapi-ts/output.md
··· 111 111 }; 112 112 ``` 113 113 114 - ::: warning 115 - Re-exporting additional files from index file may result in broken output due to naming conflicts. 116 - ::: 117 - 118 114 <!--@include: ../partials/examples.md--> 119 115 <!--@include: ../partials/sponsors.md-->
+3 -3
packages/codegen-core/src/planner/planner.ts
··· 384 384 const ok = kinds.every((kind) => canShareName(symbol.kind, kind)); 385 385 if (ok) break; 386 386 387 + const language = symbol.node?.language || symbol.file?.language; 387 388 const resolver = 388 - (symbol.node?.language 389 - ? this.project.nameConflictResolvers[symbol.node.language] 390 - : undefined) ?? this.project.defaultNameConflictResolver; 389 + (language ? this.project.nameConflictResolvers[language] : undefined) ?? 390 + this.project.defaultNameConflictResolver; 391 391 const resolvedName = resolver({ attempt, baseName }); 392 392 if (!resolvedName) { 393 393 throw new Error(`Unresolvable name conflict: ${symbol.toString()}`);
+16
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/client.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import { type ClientOptions, type Config, createClient, createConfig } from './client'; 4 + import type { ClientOptions as ClientOptions2 } from './types.gen'; 5 + 6 + /** 7 + * The `createClientConfig()` function will be called on client initialization 8 + * and the returned object will become the client's initial configuration. 9 + * 10 + * You may want to initialize your client this way instead of calling 11 + * `setConfig()`. This is useful for example if you're using Next.js 12 + * to ensure your client always has the correct values. 13 + */ 14 + export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>; 15 + 16 + export const client = createClient(createConfig<ClientOptions2>());
+301
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/client/client.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import { createSseClient } from '../core/serverSentEvents.gen'; 4 + import type { HttpMethod } from '../core/types.gen'; 5 + import { getValidRequestBody } from '../core/utils.gen'; 6 + import type { 7 + Client, 8 + Config, 9 + RequestOptions, 10 + ResolvedRequestOptions, 11 + } from './types.gen'; 12 + import { 13 + buildUrl, 14 + createConfig, 15 + createInterceptors, 16 + getParseAs, 17 + mergeConfigs, 18 + mergeHeaders, 19 + setAuthParams, 20 + } from './utils.gen'; 21 + 22 + type ReqInit = Omit<RequestInit, 'body' | 'headers'> & { 23 + body?: any; 24 + headers: ReturnType<typeof mergeHeaders>; 25 + }; 26 + 27 + export const createClient = (config: Config = {}): Client => { 28 + let _config = mergeConfigs(createConfig(), config); 29 + 30 + const getConfig = (): Config => ({ ..._config }); 31 + 32 + const setConfig = (config: Config): Config => { 33 + _config = mergeConfigs(_config, config); 34 + return getConfig(); 35 + }; 36 + 37 + const interceptors = createInterceptors< 38 + Request, 39 + Response, 40 + unknown, 41 + ResolvedRequestOptions 42 + >(); 43 + 44 + const beforeRequest = async (options: RequestOptions) => { 45 + const opts = { 46 + ..._config, 47 + ...options, 48 + fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, 49 + headers: mergeHeaders(_config.headers, options.headers), 50 + serializedBody: undefined, 51 + }; 52 + 53 + if (opts.security) { 54 + await setAuthParams({ 55 + ...opts, 56 + security: opts.security, 57 + }); 58 + } 59 + 60 + if (opts.requestValidator) { 61 + await opts.requestValidator(opts); 62 + } 63 + 64 + if (opts.body !== undefined && opts.bodySerializer) { 65 + opts.serializedBody = opts.bodySerializer(opts.body); 66 + } 67 + 68 + // remove Content-Type header if body is empty to avoid sending invalid requests 69 + if (opts.body === undefined || opts.serializedBody === '') { 70 + opts.headers.delete('Content-Type'); 71 + } 72 + 73 + const url = buildUrl(opts); 74 + 75 + return { opts, url }; 76 + }; 77 + 78 + const request: Client['request'] = async (options) => { 79 + // @ts-expect-error 80 + const { opts, url } = await beforeRequest(options); 81 + const requestInit: ReqInit = { 82 + redirect: 'follow', 83 + ...opts, 84 + body: getValidRequestBody(opts), 85 + }; 86 + 87 + let request = new Request(url, requestInit); 88 + 89 + for (const fn of interceptors.request.fns) { 90 + if (fn) { 91 + request = await fn(request, opts); 92 + } 93 + } 94 + 95 + // fetch must be assigned here, otherwise it would throw the error: 96 + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation 97 + const _fetch = opts.fetch!; 98 + let response: Response; 99 + 100 + try { 101 + response = await _fetch(request); 102 + } catch (error) { 103 + // Handle fetch exceptions (AbortError, network errors, etc.) 104 + let finalError = error; 105 + 106 + for (const fn of interceptors.error.fns) { 107 + if (fn) { 108 + finalError = (await fn( 109 + error, 110 + undefined as any, 111 + request, 112 + opts, 113 + )) as unknown; 114 + } 115 + } 116 + 117 + finalError = finalError || ({} as unknown); 118 + 119 + if (opts.throwOnError) { 120 + throw finalError; 121 + } 122 + 123 + // Return error response 124 + return opts.responseStyle === 'data' 125 + ? undefined 126 + : { 127 + error: finalError, 128 + request, 129 + response: undefined as any, 130 + }; 131 + } 132 + 133 + for (const fn of interceptors.response.fns) { 134 + if (fn) { 135 + response = await fn(response, request, opts); 136 + } 137 + } 138 + 139 + const result = { 140 + request, 141 + response, 142 + }; 143 + 144 + if (response.ok) { 145 + const parseAs = 146 + (opts.parseAs === 'auto' 147 + ? getParseAs(response.headers.get('Content-Type')) 148 + : opts.parseAs) ?? 'json'; 149 + 150 + if ( 151 + response.status === 204 || 152 + response.headers.get('Content-Length') === '0' 153 + ) { 154 + let emptyData: any; 155 + switch (parseAs) { 156 + case 'arrayBuffer': 157 + case 'blob': 158 + case 'text': 159 + emptyData = await response[parseAs](); 160 + break; 161 + case 'formData': 162 + emptyData = new FormData(); 163 + break; 164 + case 'stream': 165 + emptyData = response.body; 166 + break; 167 + case 'json': 168 + default: 169 + emptyData = {}; 170 + break; 171 + } 172 + return opts.responseStyle === 'data' 173 + ? emptyData 174 + : { 175 + data: emptyData, 176 + ...result, 177 + }; 178 + } 179 + 180 + let data: any; 181 + switch (parseAs) { 182 + case 'arrayBuffer': 183 + case 'blob': 184 + case 'formData': 185 + case 'json': 186 + case 'text': 187 + data = await response[parseAs](); 188 + break; 189 + case 'stream': 190 + return opts.responseStyle === 'data' 191 + ? response.body 192 + : { 193 + data: response.body, 194 + ...result, 195 + }; 196 + } 197 + 198 + if (parseAs === 'json') { 199 + if (opts.responseValidator) { 200 + await opts.responseValidator(data); 201 + } 202 + 203 + if (opts.responseTransformer) { 204 + data = await opts.responseTransformer(data); 205 + } 206 + } 207 + 208 + return opts.responseStyle === 'data' 209 + ? data 210 + : { 211 + data, 212 + ...result, 213 + }; 214 + } 215 + 216 + const textError = await response.text(); 217 + let jsonError: unknown; 218 + 219 + try { 220 + jsonError = JSON.parse(textError); 221 + } catch { 222 + // noop 223 + } 224 + 225 + const error = jsonError ?? textError; 226 + let finalError = error; 227 + 228 + for (const fn of interceptors.error.fns) { 229 + if (fn) { 230 + finalError = (await fn(error, response, request, opts)) as string; 231 + } 232 + } 233 + 234 + finalError = finalError || ({} as string); 235 + 236 + if (opts.throwOnError) { 237 + throw finalError; 238 + } 239 + 240 + // TODO: we probably want to return error and improve types 241 + return opts.responseStyle === 'data' 242 + ? undefined 243 + : { 244 + error: finalError, 245 + ...result, 246 + }; 247 + }; 248 + 249 + const makeMethodFn = 250 + (method: Uppercase<HttpMethod>) => (options: RequestOptions) => 251 + request({ ...options, method }); 252 + 253 + const makeSseFn = 254 + (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => { 255 + const { opts, url } = await beforeRequest(options); 256 + return createSseClient({ 257 + ...opts, 258 + body: opts.body as BodyInit | null | undefined, 259 + headers: opts.headers as unknown as Record<string, string>, 260 + method, 261 + onRequest: async (url, init) => { 262 + let request = new Request(url, init); 263 + for (const fn of interceptors.request.fns) { 264 + if (fn) { 265 + request = await fn(request, opts); 266 + } 267 + } 268 + return request; 269 + }, 270 + url, 271 + }); 272 + }; 273 + 274 + return { 275 + buildUrl, 276 + connect: makeMethodFn('CONNECT'), 277 + delete: makeMethodFn('DELETE'), 278 + get: makeMethodFn('GET'), 279 + getConfig, 280 + head: makeMethodFn('HEAD'), 281 + interceptors, 282 + options: makeMethodFn('OPTIONS'), 283 + patch: makeMethodFn('PATCH'), 284 + post: makeMethodFn('POST'), 285 + put: makeMethodFn('PUT'), 286 + request, 287 + setConfig, 288 + sse: { 289 + connect: makeSseFn('CONNECT'), 290 + delete: makeSseFn('DELETE'), 291 + get: makeSseFn('GET'), 292 + head: makeSseFn('HEAD'), 293 + options: makeSseFn('OPTIONS'), 294 + patch: makeSseFn('PATCH'), 295 + post: makeSseFn('POST'), 296 + put: makeSseFn('PUT'), 297 + trace: makeSseFn('TRACE'), 298 + }, 299 + trace: makeMethodFn('TRACE'), 300 + } as Client; 301 + };
+25
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/client/index.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + export type { Auth } from '../core/auth.gen'; 4 + export type { QuerySerializerOptions } from '../core/bodySerializer.gen'; 5 + export { 6 + formDataBodySerializer, 7 + jsonBodySerializer, 8 + urlSearchParamsBodySerializer, 9 + } from '../core/bodySerializer.gen'; 10 + export { buildClientParams } from '../core/params.gen'; 11 + export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen'; 12 + export { createClient } from './client.gen'; 13 + export type { 14 + Client, 15 + ClientOptions, 16 + Config, 17 + CreateClientConfig, 18 + Options, 19 + RequestOptions, 20 + RequestResult, 21 + ResolvedRequestOptions, 22 + ResponseStyle, 23 + TDataShape, 24 + } from './types.gen'; 25 + export { createConfig, mergeHeaders } from './utils.gen';
+241
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/client/types.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import type { Auth } from '../core/auth.gen'; 4 + import type { 5 + ServerSentEventsOptions, 6 + ServerSentEventsResult, 7 + } from '../core/serverSentEvents.gen'; 8 + import type { 9 + Client as CoreClient, 10 + Config as CoreConfig, 11 + } from '../core/types.gen'; 12 + import type { Middleware } from './utils.gen'; 13 + 14 + export type ResponseStyle = 'data' | 'fields'; 15 + 16 + export interface Config<T extends ClientOptions = ClientOptions> 17 + extends Omit<RequestInit, 'body' | 'headers' | 'method'>, 18 + CoreConfig { 19 + /** 20 + * Base URL for all requests made by this client. 21 + */ 22 + baseUrl?: T['baseUrl']; 23 + /** 24 + * Fetch API implementation. You can use this option to provide a custom 25 + * fetch instance. 26 + * 27 + * @default globalThis.fetch 28 + */ 29 + fetch?: typeof fetch; 30 + /** 31 + * Please don't use the Fetch client for Next.js applications. The `next` 32 + * options won't have any effect. 33 + * 34 + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. 35 + */ 36 + next?: never; 37 + /** 38 + * Return the response data parsed in a specified format. By default, `auto` 39 + * will infer the appropriate method from the `Content-Type` response header. 40 + * You can override this behavior with any of the {@link Body} methods. 41 + * Select `stream` if you don't want to parse response data at all. 42 + * 43 + * @default 'auto' 44 + */ 45 + parseAs?: 46 + | 'arrayBuffer' 47 + | 'auto' 48 + | 'blob' 49 + | 'formData' 50 + | 'json' 51 + | 'stream' 52 + | 'text'; 53 + /** 54 + * Should we return only data or multiple fields (data, error, response, etc.)? 55 + * 56 + * @default 'fields' 57 + */ 58 + responseStyle?: ResponseStyle; 59 + /** 60 + * Throw an error instead of returning it in the response? 61 + * 62 + * @default false 63 + */ 64 + throwOnError?: T['throwOnError']; 65 + } 66 + 67 + export interface RequestOptions< 68 + TData = unknown, 69 + TResponseStyle extends ResponseStyle = 'fields', 70 + ThrowOnError extends boolean = boolean, 71 + Url extends string = string, 72 + > extends Config<{ 73 + responseStyle: TResponseStyle; 74 + throwOnError: ThrowOnError; 75 + }>, 76 + Pick< 77 + ServerSentEventsOptions<TData>, 78 + | 'onSseError' 79 + | 'onSseEvent' 80 + | 'sseDefaultRetryDelay' 81 + | 'sseMaxRetryAttempts' 82 + | 'sseMaxRetryDelay' 83 + > { 84 + /** 85 + * Any body that you want to add to your request. 86 + * 87 + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} 88 + */ 89 + body?: unknown; 90 + path?: Record<string, unknown>; 91 + query?: Record<string, unknown>; 92 + /** 93 + * Security mechanism(s) to use for the request. 94 + */ 95 + security?: ReadonlyArray<Auth>; 96 + url: Url; 97 + } 98 + 99 + export interface ResolvedRequestOptions< 100 + TResponseStyle extends ResponseStyle = 'fields', 101 + ThrowOnError extends boolean = boolean, 102 + Url extends string = string, 103 + > extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> { 104 + serializedBody?: string; 105 + } 106 + 107 + export type RequestResult< 108 + TData = unknown, 109 + TError = unknown, 110 + ThrowOnError extends boolean = boolean, 111 + TResponseStyle extends ResponseStyle = 'fields', 112 + > = ThrowOnError extends true 113 + ? Promise< 114 + TResponseStyle extends 'data' 115 + ? TData extends Record<string, unknown> 116 + ? TData[keyof TData] 117 + : TData 118 + : { 119 + data: TData extends Record<string, unknown> 120 + ? TData[keyof TData] 121 + : TData; 122 + request: Request; 123 + response: Response; 124 + } 125 + > 126 + : Promise< 127 + TResponseStyle extends 'data' 128 + ? 129 + | (TData extends Record<string, unknown> 130 + ? TData[keyof TData] 131 + : TData) 132 + | undefined 133 + : ( 134 + | { 135 + data: TData extends Record<string, unknown> 136 + ? TData[keyof TData] 137 + : TData; 138 + error: undefined; 139 + } 140 + | { 141 + data: undefined; 142 + error: TError extends Record<string, unknown> 143 + ? TError[keyof TError] 144 + : TError; 145 + } 146 + ) & { 147 + request: Request; 148 + response: Response; 149 + } 150 + >; 151 + 152 + export interface ClientOptions { 153 + baseUrl?: string; 154 + responseStyle?: ResponseStyle; 155 + throwOnError?: boolean; 156 + } 157 + 158 + type MethodFn = < 159 + TData = unknown, 160 + TError = unknown, 161 + ThrowOnError extends boolean = false, 162 + TResponseStyle extends ResponseStyle = 'fields', 163 + >( 164 + options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>, 165 + ) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>; 166 + 167 + type SseFn = < 168 + TData = unknown, 169 + TError = unknown, 170 + ThrowOnError extends boolean = false, 171 + TResponseStyle extends ResponseStyle = 'fields', 172 + >( 173 + options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>, 174 + ) => Promise<ServerSentEventsResult<TData, TError>>; 175 + 176 + type RequestFn = < 177 + TData = unknown, 178 + TError = unknown, 179 + ThrowOnError extends boolean = false, 180 + TResponseStyle extends ResponseStyle = 'fields', 181 + >( 182 + options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> & 183 + Pick< 184 + Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, 185 + 'method' 186 + >, 187 + ) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>; 188 + 189 + type BuildUrlFn = < 190 + TData extends { 191 + body?: unknown; 192 + path?: Record<string, unknown>; 193 + query?: Record<string, unknown>; 194 + url: string; 195 + }, 196 + >( 197 + options: TData & Options<TData>, 198 + ) => string; 199 + 200 + export type Client = CoreClient< 201 + RequestFn, 202 + Config, 203 + MethodFn, 204 + BuildUrlFn, 205 + SseFn 206 + > & { 207 + interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>; 208 + }; 209 + 210 + /** 211 + * The `createClientConfig()` function will be called on client initialization 212 + * and the returned object will become the client's initial configuration. 213 + * 214 + * You may want to initialize your client this way instead of calling 215 + * `setConfig()`. This is useful for example if you're using Next.js 216 + * to ensure your client always has the correct values. 217 + */ 218 + export type CreateClientConfig<T extends ClientOptions = ClientOptions> = ( 219 + override?: Config<ClientOptions & T>, 220 + ) => Config<Required<ClientOptions> & T>; 221 + 222 + export interface TDataShape { 223 + body?: unknown; 224 + headers?: unknown; 225 + path?: unknown; 226 + query?: unknown; 227 + url: string; 228 + } 229 + 230 + type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>; 231 + 232 + export type Options< 233 + TData extends TDataShape = TDataShape, 234 + ThrowOnError extends boolean = boolean, 235 + TResponse = unknown, 236 + TResponseStyle extends ResponseStyle = 'fields', 237 + > = OmitKeys< 238 + RequestOptions<TResponse, TResponseStyle, ThrowOnError>, 239 + 'body' | 'path' | 'query' | 'url' 240 + > & 241 + ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
+332
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/client/utils.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import { getAuthToken } from '../core/auth.gen'; 4 + import type { QuerySerializerOptions } from '../core/bodySerializer.gen'; 5 + import { jsonBodySerializer } from '../core/bodySerializer.gen'; 6 + import { 7 + serializeArrayParam, 8 + serializeObjectParam, 9 + serializePrimitiveParam, 10 + } from '../core/pathSerializer.gen'; 11 + import { getUrl } from '../core/utils.gen'; 12 + import type { Client, ClientOptions, Config, RequestOptions } from './types.gen'; 13 + 14 + export const createQuerySerializer = <T = unknown>({ 15 + parameters = {}, 16 + ...args 17 + }: QuerySerializerOptions = {}) => { 18 + const querySerializer = (queryParams: T) => { 19 + const search: string[] = []; 20 + if (queryParams && typeof queryParams === 'object') { 21 + for (const name in queryParams) { 22 + const value = queryParams[name]; 23 + 24 + if (value === undefined || value === null) { 25 + continue; 26 + } 27 + 28 + const options = parameters[name] || args; 29 + 30 + if (Array.isArray(value)) { 31 + const serializedArray = serializeArrayParam({ 32 + allowReserved: options.allowReserved, 33 + explode: true, 34 + name, 35 + style: 'form', 36 + value, 37 + ...options.array, 38 + }); 39 + if (serializedArray) search.push(serializedArray); 40 + } else if (typeof value === 'object') { 41 + const serializedObject = serializeObjectParam({ 42 + allowReserved: options.allowReserved, 43 + explode: true, 44 + name, 45 + style: 'deepObject', 46 + value: value as Record<string, unknown>, 47 + ...options.object, 48 + }); 49 + if (serializedObject) search.push(serializedObject); 50 + } else { 51 + const serializedPrimitive = serializePrimitiveParam({ 52 + allowReserved: options.allowReserved, 53 + name, 54 + value: value as string, 55 + }); 56 + if (serializedPrimitive) search.push(serializedPrimitive); 57 + } 58 + } 59 + } 60 + return search.join('&'); 61 + }; 62 + return querySerializer; 63 + }; 64 + 65 + /** 66 + * Infers parseAs value from provided Content-Type header. 67 + */ 68 + export const getParseAs = ( 69 + contentType: string | null, 70 + ): Exclude<Config['parseAs'], 'auto'> => { 71 + if (!contentType) { 72 + // If no Content-Type header is provided, the best we can do is return the raw response body, 73 + // which is effectively the same as the 'stream' option. 74 + return 'stream'; 75 + } 76 + 77 + const cleanContent = contentType.split(';')[0]?.trim(); 78 + 79 + if (!cleanContent) { 80 + return; 81 + } 82 + 83 + if ( 84 + cleanContent.startsWith('application/json') || 85 + cleanContent.endsWith('+json') 86 + ) { 87 + return 'json'; 88 + } 89 + 90 + if (cleanContent === 'multipart/form-data') { 91 + return 'formData'; 92 + } 93 + 94 + if ( 95 + ['application/', 'audio/', 'image/', 'video/'].some((type) => 96 + cleanContent.startsWith(type), 97 + ) 98 + ) { 99 + return 'blob'; 100 + } 101 + 102 + if (cleanContent.startsWith('text/')) { 103 + return 'text'; 104 + } 105 + 106 + return; 107 + }; 108 + 109 + const checkForExistence = ( 110 + options: Pick<RequestOptions, 'auth' | 'query'> & { 111 + headers: Headers; 112 + }, 113 + name?: string, 114 + ): boolean => { 115 + if (!name) { 116 + return false; 117 + } 118 + if ( 119 + options.headers.has(name) || 120 + options.query?.[name] || 121 + options.headers.get('Cookie')?.includes(`${name}=`) 122 + ) { 123 + return true; 124 + } 125 + return false; 126 + }; 127 + 128 + export const setAuthParams = async ({ 129 + security, 130 + ...options 131 + }: Pick<Required<RequestOptions>, 'security'> & 132 + Pick<RequestOptions, 'auth' | 'query'> & { 133 + headers: Headers; 134 + }) => { 135 + for (const auth of security) { 136 + if (checkForExistence(options, auth.name)) { 137 + continue; 138 + } 139 + 140 + const token = await getAuthToken(auth, options.auth); 141 + 142 + if (!token) { 143 + continue; 144 + } 145 + 146 + const name = auth.name ?? 'Authorization'; 147 + 148 + switch (auth.in) { 149 + case 'query': 150 + if (!options.query) { 151 + options.query = {}; 152 + } 153 + options.query[name] = token; 154 + break; 155 + case 'cookie': 156 + options.headers.append('Cookie', `${name}=${token}`); 157 + break; 158 + case 'header': 159 + default: 160 + options.headers.set(name, token); 161 + break; 162 + } 163 + } 164 + }; 165 + 166 + export const buildUrl: Client['buildUrl'] = (options) => 167 + getUrl({ 168 + baseUrl: options.baseUrl as string, 169 + path: options.path, 170 + query: options.query, 171 + querySerializer: 172 + typeof options.querySerializer === 'function' 173 + ? options.querySerializer 174 + : createQuerySerializer(options.querySerializer), 175 + url: options.url, 176 + }); 177 + 178 + export const mergeConfigs = (a: Config, b: Config): Config => { 179 + const config = { ...a, ...b }; 180 + if (config.baseUrl?.endsWith('/')) { 181 + config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1); 182 + } 183 + config.headers = mergeHeaders(a.headers, b.headers); 184 + return config; 185 + }; 186 + 187 + const headersEntries = (headers: Headers): Array<[string, string]> => { 188 + const entries: Array<[string, string]> = []; 189 + headers.forEach((value, key) => { 190 + entries.push([key, value]); 191 + }); 192 + return entries; 193 + }; 194 + 195 + export const mergeHeaders = ( 196 + ...headers: Array<Required<Config>['headers'] | undefined> 197 + ): Headers => { 198 + const mergedHeaders = new Headers(); 199 + for (const header of headers) { 200 + if (!header) { 201 + continue; 202 + } 203 + 204 + const iterator = 205 + header instanceof Headers 206 + ? headersEntries(header) 207 + : Object.entries(header); 208 + 209 + for (const [key, value] of iterator) { 210 + if (value === null) { 211 + mergedHeaders.delete(key); 212 + } else if (Array.isArray(value)) { 213 + for (const v of value) { 214 + mergedHeaders.append(key, v as string); 215 + } 216 + } else if (value !== undefined) { 217 + // assume object headers are meant to be JSON stringified, i.e. their 218 + // content value in OpenAPI specification is 'application/json' 219 + mergedHeaders.set( 220 + key, 221 + typeof value === 'object' ? JSON.stringify(value) : (value as string), 222 + ); 223 + } 224 + } 225 + } 226 + return mergedHeaders; 227 + }; 228 + 229 + type ErrInterceptor<Err, Res, Req, Options> = ( 230 + error: Err, 231 + response: Res, 232 + request: Req, 233 + options: Options, 234 + ) => Err | Promise<Err>; 235 + 236 + type ReqInterceptor<Req, Options> = ( 237 + request: Req, 238 + options: Options, 239 + ) => Req | Promise<Req>; 240 + 241 + type ResInterceptor<Res, Req, Options> = ( 242 + response: Res, 243 + request: Req, 244 + options: Options, 245 + ) => Res | Promise<Res>; 246 + 247 + class Interceptors<Interceptor> { 248 + fns: Array<Interceptor | null> = []; 249 + 250 + clear(): void { 251 + this.fns = []; 252 + } 253 + 254 + eject(id: number | Interceptor): void { 255 + const index = this.getInterceptorIndex(id); 256 + if (this.fns[index]) { 257 + this.fns[index] = null; 258 + } 259 + } 260 + 261 + exists(id: number | Interceptor): boolean { 262 + const index = this.getInterceptorIndex(id); 263 + return Boolean(this.fns[index]); 264 + } 265 + 266 + getInterceptorIndex(id: number | Interceptor): number { 267 + if (typeof id === 'number') { 268 + return this.fns[id] ? id : -1; 269 + } 270 + return this.fns.indexOf(id); 271 + } 272 + 273 + update( 274 + id: number | Interceptor, 275 + fn: Interceptor, 276 + ): number | Interceptor | false { 277 + const index = this.getInterceptorIndex(id); 278 + if (this.fns[index]) { 279 + this.fns[index] = fn; 280 + return id; 281 + } 282 + return false; 283 + } 284 + 285 + use(fn: Interceptor): number { 286 + this.fns.push(fn); 287 + return this.fns.length - 1; 288 + } 289 + } 290 + 291 + export interface Middleware<Req, Res, Err, Options> { 292 + error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>; 293 + request: Interceptors<ReqInterceptor<Req, Options>>; 294 + response: Interceptors<ResInterceptor<Res, Req, Options>>; 295 + } 296 + 297 + export const createInterceptors = <Req, Res, Err, Options>(): Middleware< 298 + Req, 299 + Res, 300 + Err, 301 + Options 302 + > => ({ 303 + error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(), 304 + request: new Interceptors<ReqInterceptor<Req, Options>>(), 305 + response: new Interceptors<ResInterceptor<Res, Req, Options>>(), 306 + }); 307 + 308 + const defaultQuerySerializer = createQuerySerializer({ 309 + allowReserved: false, 310 + array: { 311 + explode: true, 312 + style: 'form', 313 + }, 314 + object: { 315 + explode: true, 316 + style: 'deepObject', 317 + }, 318 + }); 319 + 320 + const defaultHeaders = { 321 + 'Content-Type': 'application/json', 322 + }; 323 + 324 + export const createConfig = <T extends ClientOptions = ClientOptions>( 325 + override: Config<Omit<ClientOptions, keyof T> & T> = {}, 326 + ): Config<Omit<ClientOptions, keyof T> & T> => ({ 327 + ...jsonBodySerializer, 328 + headers: defaultHeaders, 329 + parseAs: 'auto', 330 + querySerializer: defaultQuerySerializer, 331 + ...override, 332 + });
+42
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/core/auth.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + export type AuthToken = string | undefined; 4 + 5 + export interface Auth { 6 + /** 7 + * Which part of the request do we use to send the auth? 8 + * 9 + * @default 'header' 10 + */ 11 + in?: 'header' | 'query' | 'cookie'; 12 + /** 13 + * Header or query parameter name. 14 + * 15 + * @default 'Authorization' 16 + */ 17 + name?: string; 18 + scheme?: 'basic' | 'bearer'; 19 + type: 'apiKey' | 'http'; 20 + } 21 + 22 + export const getAuthToken = async ( 23 + auth: Auth, 24 + callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken, 25 + ): Promise<string | undefined> => { 26 + const token = 27 + typeof callback === 'function' ? await callback(auth) : callback; 28 + 29 + if (!token) { 30 + return; 31 + } 32 + 33 + if (auth.scheme === 'bearer') { 34 + return `Bearer ${token}`; 35 + } 36 + 37 + if (auth.scheme === 'basic') { 38 + return `Basic ${btoa(token)}`; 39 + } 40 + 41 + return token; 42 + };
+100
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/core/bodySerializer.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import type { 4 + ArrayStyle, 5 + ObjectStyle, 6 + SerializerOptions, 7 + } from './pathSerializer.gen'; 8 + 9 + export type QuerySerializer = (query: Record<string, unknown>) => string; 10 + 11 + export type BodySerializer = (body: any) => any; 12 + 13 + type QuerySerializerOptionsObject = { 14 + allowReserved?: boolean; 15 + array?: Partial<SerializerOptions<ArrayStyle>>; 16 + object?: Partial<SerializerOptions<ObjectStyle>>; 17 + }; 18 + 19 + export type QuerySerializerOptions = QuerySerializerOptionsObject & { 20 + /** 21 + * Per-parameter serialization overrides. When provided, these settings 22 + * override the global array/object settings for specific parameter names. 23 + */ 24 + parameters?: Record<string, QuerySerializerOptionsObject>; 25 + }; 26 + 27 + const serializeFormDataPair = ( 28 + data: FormData, 29 + key: string, 30 + value: unknown, 31 + ): void => { 32 + if (typeof value === 'string' || value instanceof Blob) { 33 + data.append(key, value); 34 + } else if (value instanceof Date) { 35 + data.append(key, value.toISOString()); 36 + } else { 37 + data.append(key, JSON.stringify(value)); 38 + } 39 + }; 40 + 41 + const serializeUrlSearchParamsPair = ( 42 + data: URLSearchParams, 43 + key: string, 44 + value: unknown, 45 + ): void => { 46 + if (typeof value === 'string') { 47 + data.append(key, value); 48 + } else { 49 + data.append(key, JSON.stringify(value)); 50 + } 51 + }; 52 + 53 + export const formDataBodySerializer = { 54 + bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>( 55 + body: T, 56 + ): FormData => { 57 + const data = new FormData(); 58 + 59 + Object.entries(body).forEach(([key, value]) => { 60 + if (value === undefined || value === null) { 61 + return; 62 + } 63 + if (Array.isArray(value)) { 64 + value.forEach((v) => serializeFormDataPair(data, key, v)); 65 + } else { 66 + serializeFormDataPair(data, key, value); 67 + } 68 + }); 69 + 70 + return data; 71 + }, 72 + }; 73 + 74 + export const jsonBodySerializer = { 75 + bodySerializer: <T>(body: T): string => 76 + JSON.stringify(body, (_key, value) => 77 + typeof value === 'bigint' ? value.toString() : value, 78 + ), 79 + }; 80 + 81 + export const urlSearchParamsBodySerializer = { 82 + bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>( 83 + body: T, 84 + ): string => { 85 + const data = new URLSearchParams(); 86 + 87 + Object.entries(body).forEach(([key, value]) => { 88 + if (value === undefined || value === null) { 89 + return; 90 + } 91 + if (Array.isArray(value)) { 92 + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); 93 + } else { 94 + serializeUrlSearchParamsPair(data, key, value); 95 + } 96 + }); 97 + 98 + return data.toString(); 99 + }, 100 + };
+176
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/core/params.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + type Slot = 'body' | 'headers' | 'path' | 'query'; 4 + 5 + export type Field = 6 + | { 7 + in: Exclude<Slot, 'body'>; 8 + /** 9 + * Field name. This is the name we want the user to see and use. 10 + */ 11 + key: string; 12 + /** 13 + * Field mapped name. This is the name we want to use in the request. 14 + * If omitted, we use the same value as `key`. 15 + */ 16 + map?: string; 17 + } 18 + | { 19 + in: Extract<Slot, 'body'>; 20 + /** 21 + * Key isn't required for bodies. 22 + */ 23 + key?: string; 24 + map?: string; 25 + } 26 + | { 27 + /** 28 + * Field name. This is the name we want the user to see and use. 29 + */ 30 + key: string; 31 + /** 32 + * Field mapped name. This is the name we want to use in the request. 33 + * If `in` is omitted, `map` aliases `key` to the transport layer. 34 + */ 35 + map: Slot; 36 + }; 37 + 38 + export interface Fields { 39 + allowExtra?: Partial<Record<Slot, boolean>>; 40 + args?: ReadonlyArray<Field>; 41 + } 42 + 43 + export type FieldsConfig = ReadonlyArray<Field | Fields>; 44 + 45 + const extraPrefixesMap: Record<string, Slot> = { 46 + $body_: 'body', 47 + $headers_: 'headers', 48 + $path_: 'path', 49 + $query_: 'query', 50 + }; 51 + const extraPrefixes = Object.entries(extraPrefixesMap); 52 + 53 + type KeyMap = Map< 54 + string, 55 + | { 56 + in: Slot; 57 + map?: string; 58 + } 59 + | { 60 + in?: never; 61 + map: Slot; 62 + } 63 + >; 64 + 65 + const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { 66 + if (!map) { 67 + map = new Map(); 68 + } 69 + 70 + for (const config of fields) { 71 + if ('in' in config) { 72 + if (config.key) { 73 + map.set(config.key, { 74 + in: config.in, 75 + map: config.map, 76 + }); 77 + } 78 + } else if ('key' in config) { 79 + map.set(config.key, { 80 + map: config.map, 81 + }); 82 + } else if (config.args) { 83 + buildKeyMap(config.args, map); 84 + } 85 + } 86 + 87 + return map; 88 + }; 89 + 90 + interface Params { 91 + body: unknown; 92 + headers: Record<string, unknown>; 93 + path: Record<string, unknown>; 94 + query: Record<string, unknown>; 95 + } 96 + 97 + const stripEmptySlots = (params: Params) => { 98 + for (const [slot, value] of Object.entries(params)) { 99 + if (value && typeof value === 'object' && !Object.keys(value).length) { 100 + delete params[slot as Slot]; 101 + } 102 + } 103 + }; 104 + 105 + export const buildClientParams = ( 106 + args: ReadonlyArray<unknown>, 107 + fields: FieldsConfig, 108 + ) => { 109 + const params: Params = { 110 + body: {}, 111 + headers: {}, 112 + path: {}, 113 + query: {}, 114 + }; 115 + 116 + const map = buildKeyMap(fields); 117 + 118 + let config: FieldsConfig[number] | undefined; 119 + 120 + for (const [index, arg] of args.entries()) { 121 + if (fields[index]) { 122 + config = fields[index]; 123 + } 124 + 125 + if (!config) { 126 + continue; 127 + } 128 + 129 + if ('in' in config) { 130 + if (config.key) { 131 + const field = map.get(config.key)!; 132 + const name = field.map || config.key; 133 + if (field.in) { 134 + (params[field.in] as Record<string, unknown>)[name] = arg; 135 + } 136 + } else { 137 + params.body = arg; 138 + } 139 + } else { 140 + for (const [key, value] of Object.entries(arg ?? {})) { 141 + const field = map.get(key); 142 + 143 + if (field) { 144 + if (field.in) { 145 + const name = field.map || key; 146 + (params[field.in] as Record<string, unknown>)[name] = value; 147 + } else { 148 + params[field.map] = value; 149 + } 150 + } else { 151 + const extra = extraPrefixes.find(([prefix]) => 152 + key.startsWith(prefix), 153 + ); 154 + 155 + if (extra) { 156 + const [prefix, slot] = extra; 157 + (params[slot] as Record<string, unknown>)[ 158 + key.slice(prefix.length) 159 + ] = value; 160 + } else if ('allowExtra' in config && config.allowExtra) { 161 + for (const [slot, allowed] of Object.entries(config.allowExtra)) { 162 + if (allowed) { 163 + (params[slot as Slot] as Record<string, unknown>)[key] = value; 164 + break; 165 + } 166 + } 167 + } 168 + } 169 + } 170 + } 171 + } 172 + 173 + stripEmptySlots(params); 174 + 175 + return params; 176 + };
+181
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/core/pathSerializer.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + interface SerializeOptions<T> 4 + extends SerializePrimitiveOptions, 5 + SerializerOptions<T> {} 6 + 7 + interface SerializePrimitiveOptions { 8 + allowReserved?: boolean; 9 + name: string; 10 + } 11 + 12 + export interface SerializerOptions<T> { 13 + /** 14 + * @default true 15 + */ 16 + explode: boolean; 17 + style: T; 18 + } 19 + 20 + export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; 21 + export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; 22 + type MatrixStyle = 'label' | 'matrix' | 'simple'; 23 + export type ObjectStyle = 'form' | 'deepObject'; 24 + type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; 25 + 26 + interface SerializePrimitiveParam extends SerializePrimitiveOptions { 27 + value: string; 28 + } 29 + 30 + export const separatorArrayExplode = (style: ArraySeparatorStyle) => { 31 + switch (style) { 32 + case 'label': 33 + return '.'; 34 + case 'matrix': 35 + return ';'; 36 + case 'simple': 37 + return ','; 38 + default: 39 + return '&'; 40 + } 41 + }; 42 + 43 + export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { 44 + switch (style) { 45 + case 'form': 46 + return ','; 47 + case 'pipeDelimited': 48 + return '|'; 49 + case 'spaceDelimited': 50 + return '%20'; 51 + default: 52 + return ','; 53 + } 54 + }; 55 + 56 + export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { 57 + switch (style) { 58 + case 'label': 59 + return '.'; 60 + case 'matrix': 61 + return ';'; 62 + case 'simple': 63 + return ','; 64 + default: 65 + return '&'; 66 + } 67 + }; 68 + 69 + export const serializeArrayParam = ({ 70 + allowReserved, 71 + explode, 72 + name, 73 + style, 74 + value, 75 + }: SerializeOptions<ArraySeparatorStyle> & { 76 + value: unknown[]; 77 + }) => { 78 + if (!explode) { 79 + const joinedValues = ( 80 + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) 81 + ).join(separatorArrayNoExplode(style)); 82 + switch (style) { 83 + case 'label': 84 + return `.${joinedValues}`; 85 + case 'matrix': 86 + return `;${name}=${joinedValues}`; 87 + case 'simple': 88 + return joinedValues; 89 + default: 90 + return `${name}=${joinedValues}`; 91 + } 92 + } 93 + 94 + const separator = separatorArrayExplode(style); 95 + const joinedValues = value 96 + .map((v) => { 97 + if (style === 'label' || style === 'simple') { 98 + return allowReserved ? v : encodeURIComponent(v as string); 99 + } 100 + 101 + return serializePrimitiveParam({ 102 + allowReserved, 103 + name, 104 + value: v as string, 105 + }); 106 + }) 107 + .join(separator); 108 + return style === 'label' || style === 'matrix' 109 + ? separator + joinedValues 110 + : joinedValues; 111 + }; 112 + 113 + export const serializePrimitiveParam = ({ 114 + allowReserved, 115 + name, 116 + value, 117 + }: SerializePrimitiveParam) => { 118 + if (value === undefined || value === null) { 119 + return ''; 120 + } 121 + 122 + if (typeof value === 'object') { 123 + throw new Error( 124 + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', 125 + ); 126 + } 127 + 128 + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; 129 + }; 130 + 131 + export const serializeObjectParam = ({ 132 + allowReserved, 133 + explode, 134 + name, 135 + style, 136 + value, 137 + valueOnly, 138 + }: SerializeOptions<ObjectSeparatorStyle> & { 139 + value: Record<string, unknown> | Date; 140 + valueOnly?: boolean; 141 + }) => { 142 + if (value instanceof Date) { 143 + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; 144 + } 145 + 146 + if (style !== 'deepObject' && !explode) { 147 + let values: string[] = []; 148 + Object.entries(value).forEach(([key, v]) => { 149 + values = [ 150 + ...values, 151 + key, 152 + allowReserved ? (v as string) : encodeURIComponent(v as string), 153 + ]; 154 + }); 155 + const joinedValues = values.join(','); 156 + switch (style) { 157 + case 'form': 158 + return `${name}=${joinedValues}`; 159 + case 'label': 160 + return `.${joinedValues}`; 161 + case 'matrix': 162 + return `;${name}=${joinedValues}`; 163 + default: 164 + return joinedValues; 165 + } 166 + } 167 + 168 + const separator = separatorObjectExplode(style); 169 + const joinedValues = Object.entries(value) 170 + .map(([key, v]) => 171 + serializePrimitiveParam({ 172 + allowReserved, 173 + name: style === 'deepObject' ? `${name}[${key}]` : key, 174 + value: v as string, 175 + }), 176 + ) 177 + .join(separator); 178 + return style === 'label' || style === 'matrix' 179 + ? separator + joinedValues 180 + : joinedValues; 181 + };
+136
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/core/queryKeySerializer.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + /** 4 + * JSON-friendly union that mirrors what Pinia Colada can hash. 5 + */ 6 + export type JsonValue = 7 + | null 8 + | string 9 + | number 10 + | boolean 11 + | JsonValue[] 12 + | { [key: string]: JsonValue }; 13 + 14 + /** 15 + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. 16 + */ 17 + export const queryKeyJsonReplacer = (_key: string, value: unknown) => { 18 + if ( 19 + value === undefined || 20 + typeof value === 'function' || 21 + typeof value === 'symbol' 22 + ) { 23 + return undefined; 24 + } 25 + if (typeof value === 'bigint') { 26 + return value.toString(); 27 + } 28 + if (value instanceof Date) { 29 + return value.toISOString(); 30 + } 31 + return value; 32 + }; 33 + 34 + /** 35 + * Safely stringifies a value and parses it back into a JsonValue. 36 + */ 37 + export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { 38 + try { 39 + const json = JSON.stringify(input, queryKeyJsonReplacer); 40 + if (json === undefined) { 41 + return undefined; 42 + } 43 + return JSON.parse(json) as JsonValue; 44 + } catch { 45 + return undefined; 46 + } 47 + }; 48 + 49 + /** 50 + * Detects plain objects (including objects with a null prototype). 51 + */ 52 + const isPlainObject = (value: unknown): value is Record<string, unknown> => { 53 + if (value === null || typeof value !== 'object') { 54 + return false; 55 + } 56 + const prototype = Object.getPrototypeOf(value as object); 57 + return prototype === Object.prototype || prototype === null; 58 + }; 59 + 60 + /** 61 + * Turns URLSearchParams into a sorted JSON object for deterministic keys. 62 + */ 63 + const serializeSearchParams = (params: URLSearchParams): JsonValue => { 64 + const entries = Array.from(params.entries()).sort(([a], [b]) => 65 + a.localeCompare(b), 66 + ); 67 + const result: Record<string, JsonValue> = {}; 68 + 69 + for (const [key, value] of entries) { 70 + const existing = result[key]; 71 + if (existing === undefined) { 72 + result[key] = value; 73 + continue; 74 + } 75 + 76 + if (Array.isArray(existing)) { 77 + (existing as string[]).push(value); 78 + } else { 79 + result[key] = [existing, value]; 80 + } 81 + } 82 + 83 + return result; 84 + }; 85 + 86 + /** 87 + * Normalizes any accepted value into a JSON-friendly shape for query keys. 88 + */ 89 + export const serializeQueryKeyValue = ( 90 + value: unknown, 91 + ): JsonValue | undefined => { 92 + if (value === null) { 93 + return null; 94 + } 95 + 96 + if ( 97 + typeof value === 'string' || 98 + typeof value === 'number' || 99 + typeof value === 'boolean' 100 + ) { 101 + return value; 102 + } 103 + 104 + if ( 105 + value === undefined || 106 + typeof value === 'function' || 107 + typeof value === 'symbol' 108 + ) { 109 + return undefined; 110 + } 111 + 112 + if (typeof value === 'bigint') { 113 + return value.toString(); 114 + } 115 + 116 + if (value instanceof Date) { 117 + return value.toISOString(); 118 + } 119 + 120 + if (Array.isArray(value)) { 121 + return stringifyToJsonValue(value); 122 + } 123 + 124 + if ( 125 + typeof URLSearchParams !== 'undefined' && 126 + value instanceof URLSearchParams 127 + ) { 128 + return serializeSearchParams(value); 129 + } 130 + 131 + if (isPlainObject(value)) { 132 + return stringifyToJsonValue(value); 133 + } 134 + 135 + return undefined; 136 + };
+266
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/core/serverSentEvents.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import type { Config } from './types.gen'; 4 + 5 + export type ServerSentEventsOptions<TData = unknown> = Omit< 6 + RequestInit, 7 + 'method' 8 + > & 9 + Pick<Config, 'method' | 'responseTransformer' | 'responseValidator'> & { 10 + /** 11 + * Fetch API implementation. You can use this option to provide a custom 12 + * fetch instance. 13 + * 14 + * @default globalThis.fetch 15 + */ 16 + fetch?: typeof fetch; 17 + /** 18 + * Implementing clients can call request interceptors inside this hook. 19 + */ 20 + onRequest?: (url: string, init: RequestInit) => Promise<Request>; 21 + /** 22 + * Callback invoked when a network or parsing error occurs during streaming. 23 + * 24 + * This option applies only if the endpoint returns a stream of events. 25 + * 26 + * @param error The error that occurred. 27 + */ 28 + onSseError?: (error: unknown) => void; 29 + /** 30 + * Callback invoked when an event is streamed from the server. 31 + * 32 + * This option applies only if the endpoint returns a stream of events. 33 + * 34 + * @param event Event streamed from the server. 35 + * @returns Nothing (void). 36 + */ 37 + onSseEvent?: (event: StreamEvent<TData>) => void; 38 + serializedBody?: RequestInit['body']; 39 + /** 40 + * Default retry delay in milliseconds. 41 + * 42 + * This option applies only if the endpoint returns a stream of events. 43 + * 44 + * @default 3000 45 + */ 46 + sseDefaultRetryDelay?: number; 47 + /** 48 + * Maximum number of retry attempts before giving up. 49 + */ 50 + sseMaxRetryAttempts?: number; 51 + /** 52 + * Maximum retry delay in milliseconds. 53 + * 54 + * Applies only when exponential backoff is used. 55 + * 56 + * This option applies only if the endpoint returns a stream of events. 57 + * 58 + * @default 30000 59 + */ 60 + sseMaxRetryDelay?: number; 61 + /** 62 + * Optional sleep function for retry backoff. 63 + * 64 + * Defaults to using `setTimeout`. 65 + */ 66 + sseSleepFn?: (ms: number) => Promise<void>; 67 + url: string; 68 + }; 69 + 70 + export interface StreamEvent<TData = unknown> { 71 + data: TData; 72 + event?: string; 73 + id?: string; 74 + retry?: number; 75 + } 76 + 77 + export type ServerSentEventsResult< 78 + TData = unknown, 79 + TReturn = void, 80 + TNext = unknown, 81 + > = { 82 + stream: AsyncGenerator< 83 + TData extends Record<string, unknown> ? TData[keyof TData] : TData, 84 + TReturn, 85 + TNext 86 + >; 87 + }; 88 + 89 + export const createSseClient = <TData = unknown>({ 90 + onRequest, 91 + onSseError, 92 + onSseEvent, 93 + responseTransformer, 94 + responseValidator, 95 + sseDefaultRetryDelay, 96 + sseMaxRetryAttempts, 97 + sseMaxRetryDelay, 98 + sseSleepFn, 99 + url, 100 + ...options 101 + }: ServerSentEventsOptions): ServerSentEventsResult<TData> => { 102 + let lastEventId: string | undefined; 103 + 104 + const sleep = 105 + sseSleepFn ?? 106 + ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); 107 + 108 + const createStream = async function* () { 109 + let retryDelay: number = sseDefaultRetryDelay ?? 3000; 110 + let attempt = 0; 111 + const signal = options.signal ?? new AbortController().signal; 112 + 113 + while (true) { 114 + if (signal.aborted) break; 115 + 116 + attempt++; 117 + 118 + const headers = 119 + options.headers instanceof Headers 120 + ? options.headers 121 + : new Headers(options.headers as Record<string, string> | undefined); 122 + 123 + if (lastEventId !== undefined) { 124 + headers.set('Last-Event-ID', lastEventId); 125 + } 126 + 127 + try { 128 + const requestInit: RequestInit = { 129 + redirect: 'follow', 130 + ...options, 131 + body: options.serializedBody, 132 + headers, 133 + signal, 134 + }; 135 + let request = new Request(url, requestInit); 136 + if (onRequest) { 137 + request = await onRequest(url, requestInit); 138 + } 139 + // fetch must be assigned here, otherwise it would throw the error: 140 + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation 141 + const _fetch = options.fetch ?? globalThis.fetch; 142 + const response = await _fetch(request); 143 + 144 + if (!response.ok) 145 + throw new Error( 146 + `SSE failed: ${response.status} ${response.statusText}`, 147 + ); 148 + 149 + if (!response.body) throw new Error('No body in SSE response'); 150 + 151 + const reader = response.body 152 + .pipeThrough(new TextDecoderStream()) 153 + .getReader(); 154 + 155 + let buffer = ''; 156 + 157 + const abortHandler = () => { 158 + try { 159 + reader.cancel(); 160 + } catch { 161 + // noop 162 + } 163 + }; 164 + 165 + signal.addEventListener('abort', abortHandler); 166 + 167 + try { 168 + while (true) { 169 + const { done, value } = await reader.read(); 170 + if (done) break; 171 + buffer += value; 172 + // Normalize line endings: CRLF -> LF, then CR -> LF 173 + buffer = buffer.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); 174 + 175 + const chunks = buffer.split('\n\n'); 176 + buffer = chunks.pop() ?? ''; 177 + 178 + for (const chunk of chunks) { 179 + const lines = chunk.split('\n'); 180 + const dataLines: Array<string> = []; 181 + let eventName: string | undefined; 182 + 183 + for (const line of lines) { 184 + if (line.startsWith('data:')) { 185 + dataLines.push(line.replace(/^data:\s*/, '')); 186 + } else if (line.startsWith('event:')) { 187 + eventName = line.replace(/^event:\s*/, ''); 188 + } else if (line.startsWith('id:')) { 189 + lastEventId = line.replace(/^id:\s*/, ''); 190 + } else if (line.startsWith('retry:')) { 191 + const parsed = Number.parseInt( 192 + line.replace(/^retry:\s*/, ''), 193 + 10, 194 + ); 195 + if (!Number.isNaN(parsed)) { 196 + retryDelay = parsed; 197 + } 198 + } 199 + } 200 + 201 + let data: unknown; 202 + let parsedJson = false; 203 + 204 + if (dataLines.length) { 205 + const rawData = dataLines.join('\n'); 206 + try { 207 + data = JSON.parse(rawData); 208 + parsedJson = true; 209 + } catch { 210 + data = rawData; 211 + } 212 + } 213 + 214 + if (parsedJson) { 215 + if (responseValidator) { 216 + await responseValidator(data); 217 + } 218 + 219 + if (responseTransformer) { 220 + data = await responseTransformer(data); 221 + } 222 + } 223 + 224 + onSseEvent?.({ 225 + data, 226 + event: eventName, 227 + id: lastEventId, 228 + retry: retryDelay, 229 + }); 230 + 231 + if (dataLines.length) { 232 + yield data as any; 233 + } 234 + } 235 + } 236 + } finally { 237 + signal.removeEventListener('abort', abortHandler); 238 + reader.releaseLock(); 239 + } 240 + 241 + break; // exit loop on normal completion 242 + } catch (error) { 243 + // connection failed or aborted; retry after delay 244 + onSseError?.(error); 245 + 246 + if ( 247 + sseMaxRetryAttempts !== undefined && 248 + attempt >= sseMaxRetryAttempts 249 + ) { 250 + break; // stop after firing error 251 + } 252 + 253 + // exponential backoff: double retry each attempt, cap at 30s 254 + const backoff = Math.min( 255 + retryDelay * 2 ** (attempt - 1), 256 + sseMaxRetryDelay ?? 30000, 257 + ); 258 + await sleep(backoff); 259 + } 260 + } 261 + }; 262 + 263 + const stream = createStream(); 264 + 265 + return { stream }; 266 + };
+118
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/core/types.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import type { Auth, AuthToken } from './auth.gen'; 4 + import type { 5 + BodySerializer, 6 + QuerySerializer, 7 + QuerySerializerOptions, 8 + } from './bodySerializer.gen'; 9 + 10 + export type HttpMethod = 11 + | 'connect' 12 + | 'delete' 13 + | 'get' 14 + | 'head' 15 + | 'options' 16 + | 'patch' 17 + | 'post' 18 + | 'put' 19 + | 'trace'; 20 + 21 + export type Client< 22 + RequestFn = never, 23 + Config = unknown, 24 + MethodFn = never, 25 + BuildUrlFn = never, 26 + SseFn = never, 27 + > = { 28 + /** 29 + * Returns the final request URL. 30 + */ 31 + buildUrl: BuildUrlFn; 32 + getConfig: () => Config; 33 + request: RequestFn; 34 + setConfig: (config: Config) => Config; 35 + } & { 36 + [K in HttpMethod]: MethodFn; 37 + } & ([SseFn] extends [never] 38 + ? { sse?: never } 39 + : { sse: { [K in HttpMethod]: SseFn } }); 40 + 41 + export interface Config { 42 + /** 43 + * Auth token or a function returning auth token. The resolved value will be 44 + * added to the request payload as defined by its `security` array. 45 + */ 46 + auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken; 47 + /** 48 + * A function for serializing request body parameter. By default, 49 + * {@link JSON.stringify()} will be used. 50 + */ 51 + bodySerializer?: BodySerializer | null; 52 + /** 53 + * An object containing any HTTP headers that you want to pre-populate your 54 + * `Headers` object with. 55 + * 56 + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} 57 + */ 58 + headers?: 59 + | RequestInit['headers'] 60 + | Record< 61 + string, 62 + | string 63 + | number 64 + | boolean 65 + | (string | number | boolean)[] 66 + | null 67 + | undefined 68 + | unknown 69 + >; 70 + /** 71 + * The request method. 72 + * 73 + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} 74 + */ 75 + method?: Uppercase<HttpMethod>; 76 + /** 77 + * A function for serializing request query parameters. By default, arrays 78 + * will be exploded in form style, objects will be exploded in deepObject 79 + * style, and reserved characters are percent-encoded. 80 + * 81 + * This method will have no effect if the native `paramsSerializer()` Axios 82 + * API function is used. 83 + * 84 + * {@link https://swagger.io/docs/specification/serialization/#query View examples} 85 + */ 86 + querySerializer?: QuerySerializer | QuerySerializerOptions; 87 + /** 88 + * A function validating request data. This is useful if you want to ensure 89 + * the request conforms to the desired shape, so it can be safely sent to 90 + * the server. 91 + */ 92 + requestValidator?: (data: unknown) => Promise<unknown>; 93 + /** 94 + * A function transforming response data before it's returned. This is useful 95 + * for post-processing data, e.g. converting ISO strings into Date objects. 96 + */ 97 + responseTransformer?: (data: unknown) => Promise<unknown>; 98 + /** 99 + * A function validating response data. This is useful if you want to ensure 100 + * the response conforms to the desired shape, so it can be safely passed to 101 + * the transformers and returned to the user. 102 + */ 103 + responseValidator?: (data: unknown) => Promise<unknown>; 104 + } 105 + 106 + type IsExactlyNeverOrNeverUndefined<T> = [T] extends [never] 107 + ? true 108 + : [T] extends [never | undefined] 109 + ? [undefined] extends [T] 110 + ? false 111 + : true 112 + : false; 113 + 114 + export type OmitNever<T extends Record<string, unknown>> = { 115 + [K in keyof T as IsExactlyNeverOrNeverUndefined<T[K]> extends true 116 + ? never 117 + : K]: T[K]; 118 + };
+143
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/core/utils.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; 4 + import { 5 + type ArraySeparatorStyle, 6 + serializeArrayParam, 7 + serializeObjectParam, 8 + serializePrimitiveParam, 9 + } from './pathSerializer.gen'; 10 + 11 + export interface PathSerializer { 12 + path: Record<string, unknown>; 13 + url: string; 14 + } 15 + 16 + export const PATH_PARAM_RE = /\{[^{}]+\}/g; 17 + 18 + export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { 19 + let url = _url; 20 + const matches = _url.match(PATH_PARAM_RE); 21 + if (matches) { 22 + for (const match of matches) { 23 + let explode = false; 24 + let name = match.substring(1, match.length - 1); 25 + let style: ArraySeparatorStyle = 'simple'; 26 + 27 + if (name.endsWith('*')) { 28 + explode = true; 29 + name = name.substring(0, name.length - 1); 30 + } 31 + 32 + if (name.startsWith('.')) { 33 + name = name.substring(1); 34 + style = 'label'; 35 + } else if (name.startsWith(';')) { 36 + name = name.substring(1); 37 + style = 'matrix'; 38 + } 39 + 40 + const value = path[name]; 41 + 42 + if (value === undefined || value === null) { 43 + continue; 44 + } 45 + 46 + if (Array.isArray(value)) { 47 + url = url.replace( 48 + match, 49 + serializeArrayParam({ explode, name, style, value }), 50 + ); 51 + continue; 52 + } 53 + 54 + if (typeof value === 'object') { 55 + url = url.replace( 56 + match, 57 + serializeObjectParam({ 58 + explode, 59 + name, 60 + style, 61 + value: value as Record<string, unknown>, 62 + valueOnly: true, 63 + }), 64 + ); 65 + continue; 66 + } 67 + 68 + if (style === 'matrix') { 69 + url = url.replace( 70 + match, 71 + `;${serializePrimitiveParam({ 72 + name, 73 + value: value as string, 74 + })}`, 75 + ); 76 + continue; 77 + } 78 + 79 + const replaceValue = encodeURIComponent( 80 + style === 'label' ? `.${value as string}` : (value as string), 81 + ); 82 + url = url.replace(match, replaceValue); 83 + } 84 + } 85 + return url; 86 + }; 87 + 88 + export const getUrl = ({ 89 + baseUrl, 90 + path, 91 + query, 92 + querySerializer, 93 + url: _url, 94 + }: { 95 + baseUrl?: string; 96 + path?: Record<string, unknown>; 97 + query?: Record<string, unknown>; 98 + querySerializer: QuerySerializer; 99 + url: string; 100 + }) => { 101 + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; 102 + let url = (baseUrl ?? '') + pathUrl; 103 + if (path) { 104 + url = defaultPathSerializer({ path, url }); 105 + } 106 + let search = query ? querySerializer(query) : ''; 107 + if (search.startsWith('?')) { 108 + search = search.substring(1); 109 + } 110 + if (search) { 111 + url += `?${search}`; 112 + } 113 + return url; 114 + }; 115 + 116 + export function getValidRequestBody(options: { 117 + body?: unknown; 118 + bodySerializer?: BodySerializer | null; 119 + serializedBody?: unknown; 120 + }) { 121 + const hasBody = options.body !== undefined; 122 + const isSerializedBody = hasBody && options.bodySerializer; 123 + 124 + if (isSerializedBody) { 125 + if ('serializedBody' in options) { 126 + const hasSerializedBody = 127 + options.serializedBody !== undefined && options.serializedBody !== ''; 128 + 129 + return hasSerializedBody ? options.serializedBody : null; 130 + } 131 + 132 + // not all clients implement a serializedBody property (i.e. client-axios) 133 + return options.body !== '' ? options.body : null; 134 + } 135 + 136 + // plain/text body 137 + if (hasBody) { 138 + return options.body; 139 + } 140 + 141 + // no body was provided 142 + return undefined; 143 + }
+4
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/index.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + export * from './sdk.gen'; 4 + export type * from './types.gen';
+594
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/sdk.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import { buildClientParams, type Client, type Options as Options2, type TDataShape } from './client'; 4 + import { client } from './client.gen'; 5 + import type { AgentPartInput, AppAgentsResponses, AppGetResponses, AppInitResponses, AppLogResponses, Auth, AuthSetErrors, AuthSetResponses, ConfigGetResponses, ConfigProvidersResponses, EventSubscribeResponses, FilePartInput, FileReadResponses, FileStatusResponses, FindFilesResponses, FindSymbolsResponses, FindTextResponses, PostSessionByIdPermissionsByPermissionIdResponses, SessionAbortResponses, SessionChatResponses, SessionChildrenResponses, SessionCreateErrors, SessionCreateResponses, SessionDeleteResponses, SessionGetResponses, SessionInitResponses, SessionListResponses, SessionMessageResponses, SessionMessagesResponses, SessionRevertResponses, SessionShareResponses, SessionShellResponses, SessionSummarizeResponses, SessionUnrevertResponses, SessionUnshareResponses, SessionUpdateResponses, TextPartInput, TuiAppendPromptResponses, TuiClearPromptResponses, TuiExecuteCommandResponses, TuiOpenHelpResponses, TuiOpenModelsResponses, TuiOpenSessionsResponses, TuiOpenThemesResponses, TuiShowToastResponses, TuiSubmitPromptResponses } from './types.gen'; 6 + 7 + export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = Options2<TData, ThrowOnError> & { 8 + /** 9 + * You can provide a client instance returned by `createClient()` instead of 10 + * individual options. This might be also useful if you want to implement a 11 + * custom client. 12 + */ 13 + client?: Client; 14 + /** 15 + * You can pass arbitrary values through the `meta` object. This can be 16 + * used to access values that aren't defined as part of the SDK function. 17 + */ 18 + meta?: Record<string, unknown>; 19 + }; 20 + 21 + /** 22 + * Get events 23 + */ 24 + export const eventSubscribe = <ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>) => (options?.client ?? client).sse.get<EventSubscribeResponses, unknown, ThrowOnError>({ url: '/event', ...options }); 25 + 26 + /** 27 + * Get app info 28 + */ 29 + export const appGet = <ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>) => (options?.client ?? client).get<AppGetResponses, unknown, ThrowOnError>({ url: '/app', ...options }); 30 + 31 + /** 32 + * Initialize the app 33 + */ 34 + export const appInit = <ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>) => (options?.client ?? client).post<AppInitResponses, unknown, ThrowOnError>({ url: '/app/init', ...options }); 35 + 36 + /** 37 + * Get config info 38 + */ 39 + export const configGet = <ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>) => (options?.client ?? client).get<ConfigGetResponses, unknown, ThrowOnError>({ url: '/config', ...options }); 40 + 41 + /** 42 + * List all sessions 43 + */ 44 + export const sessionList = <ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>) => (options?.client ?? client).get<SessionListResponses, unknown, ThrowOnError>({ url: '/session', ...options }); 45 + 46 + /** 47 + * Create a new session 48 + */ 49 + export const sessionCreate = <ThrowOnError extends boolean = false>(parameters?: { 50 + parentID?: string; 51 + title?: string; 52 + }, options?: Options<never, ThrowOnError>) => { 53 + const params = buildClientParams([parameters], [{ args: [{ in: 'body', key: 'parentID' }, { in: 'body', key: 'title' }] }]); 54 + return (options?.client ?? client).post<SessionCreateResponses, SessionCreateErrors, ThrowOnError>({ 55 + url: '/session', 56 + ...options, 57 + ...params, 58 + headers: { 59 + 'Content-Type': 'application/json', 60 + ...options?.headers, 61 + ...params.headers 62 + } 63 + }); 64 + }; 65 + 66 + /** 67 + * Delete a session and all its data 68 + */ 69 + export const sessionDelete = <ThrowOnError extends boolean = false>(parameters: { 70 + id: string; 71 + }, options?: Options<never, ThrowOnError>) => { 72 + const params = buildClientParams([parameters], [{ args: [{ in: 'path', key: 'id' }] }]); 73 + return (options?.client ?? client).delete<SessionDeleteResponses, unknown, ThrowOnError>({ 74 + url: '/session/{id}', 75 + ...options, 76 + ...params 77 + }); 78 + }; 79 + 80 + /** 81 + * Get session 82 + */ 83 + export const sessionGet = <ThrowOnError extends boolean = false>(parameters: { 84 + id: string; 85 + }, options?: Options<never, ThrowOnError>) => { 86 + const params = buildClientParams([parameters], [{ args: [{ in: 'path', key: 'id' }] }]); 87 + return (options?.client ?? client).get<SessionGetResponses, unknown, ThrowOnError>({ 88 + url: '/session/{id}', 89 + ...options, 90 + ...params 91 + }); 92 + }; 93 + 94 + /** 95 + * Update session properties 96 + */ 97 + export const sessionUpdate = <ThrowOnError extends boolean = false>(parameters: { 98 + id: string; 99 + title?: string; 100 + }, options?: Options<never, ThrowOnError>) => { 101 + const params = buildClientParams([parameters], [{ args: [{ in: 'path', key: 'id' }, { in: 'body', key: 'title' }] }]); 102 + return (options?.client ?? client).patch<SessionUpdateResponses, unknown, ThrowOnError>({ 103 + url: '/session/{id}', 104 + ...options, 105 + ...params, 106 + headers: { 107 + 'Content-Type': 'application/json', 108 + ...options?.headers, 109 + ...params.headers 110 + } 111 + }); 112 + }; 113 + 114 + /** 115 + * Get a session's children 116 + */ 117 + export const sessionChildren = <ThrowOnError extends boolean = false>(parameters: { 118 + id: string; 119 + }, options?: Options<never, ThrowOnError>) => { 120 + const params = buildClientParams([parameters], [{ args: [{ in: 'path', key: 'id' }] }]); 121 + return (options?.client ?? client).get<SessionChildrenResponses, unknown, ThrowOnError>({ 122 + url: '/session/{id}/children', 123 + ...options, 124 + ...params 125 + }); 126 + }; 127 + 128 + /** 129 + * Analyze the app and create an AGENTS.md file 130 + */ 131 + export const sessionInit = <ThrowOnError extends boolean = false>(parameters: { 132 + id: string; 133 + messageID?: string; 134 + providerID?: string; 135 + modelID?: string; 136 + }, options?: Options<never, ThrowOnError>) => { 137 + const params = buildClientParams([parameters], [{ args: [ 138 + { in: 'path', key: 'id' }, 139 + { in: 'body', key: 'messageID' }, 140 + { in: 'body', key: 'providerID' }, 141 + { in: 'body', key: 'modelID' } 142 + ] }]); 143 + return (options?.client ?? client).post<SessionInitResponses, unknown, ThrowOnError>({ 144 + url: '/session/{id}/init', 145 + ...options, 146 + ...params, 147 + headers: { 148 + 'Content-Type': 'application/json', 149 + ...options?.headers, 150 + ...params.headers 151 + } 152 + }); 153 + }; 154 + 155 + /** 156 + * Abort a session 157 + */ 158 + export const sessionAbort = <ThrowOnError extends boolean = false>(parameters: { 159 + id: string; 160 + }, options?: Options<never, ThrowOnError>) => { 161 + const params = buildClientParams([parameters], [{ args: [{ in: 'path', key: 'id' }] }]); 162 + return (options?.client ?? client).post<SessionAbortResponses, unknown, ThrowOnError>({ 163 + url: '/session/{id}/abort', 164 + ...options, 165 + ...params 166 + }); 167 + }; 168 + 169 + /** 170 + * Unshare the session 171 + */ 172 + export const sessionUnshare = <ThrowOnError extends boolean = false>(parameters: { 173 + id: string; 174 + }, options?: Options<never, ThrowOnError>) => { 175 + const params = buildClientParams([parameters], [{ args: [{ in: 'path', key: 'id' }] }]); 176 + return (options?.client ?? client).delete<SessionUnshareResponses, unknown, ThrowOnError>({ 177 + url: '/session/{id}/share', 178 + ...options, 179 + ...params 180 + }); 181 + }; 182 + 183 + /** 184 + * Share a session 185 + */ 186 + export const sessionShare = <ThrowOnError extends boolean = false>(parameters: { 187 + id: string; 188 + }, options?: Options<never, ThrowOnError>) => { 189 + const params = buildClientParams([parameters], [{ args: [{ in: 'path', key: 'id' }] }]); 190 + return (options?.client ?? client).post<SessionShareResponses, unknown, ThrowOnError>({ 191 + url: '/session/{id}/share', 192 + ...options, 193 + ...params 194 + }); 195 + }; 196 + 197 + /** 198 + * Summarize the session 199 + */ 200 + export const sessionSummarize = <ThrowOnError extends boolean = false>(parameters: { 201 + id: string; 202 + providerID?: string; 203 + modelID?: string; 204 + }, options?: Options<never, ThrowOnError>) => { 205 + const params = buildClientParams([parameters], [{ args: [ 206 + { in: 'path', key: 'id' }, 207 + { in: 'body', key: 'providerID' }, 208 + { in: 'body', key: 'modelID' } 209 + ] }]); 210 + return (options?.client ?? client).post<SessionSummarizeResponses, unknown, ThrowOnError>({ 211 + url: '/session/{id}/summarize', 212 + ...options, 213 + ...params, 214 + headers: { 215 + 'Content-Type': 'application/json', 216 + ...options?.headers, 217 + ...params.headers 218 + } 219 + }); 220 + }; 221 + 222 + /** 223 + * List messages for a session 224 + */ 225 + export const sessionMessages = <ThrowOnError extends boolean = false>(parameters: { 226 + id: string; 227 + }, options?: Options<never, ThrowOnError>) => { 228 + const params = buildClientParams([parameters], [{ args: [{ in: 'path', key: 'id' }] }]); 229 + return (options?.client ?? client).get<SessionMessagesResponses, unknown, ThrowOnError>({ 230 + url: '/session/{id}/message', 231 + ...options, 232 + ...params 233 + }); 234 + }; 235 + 236 + /** 237 + * Create and send a new message to a session 238 + */ 239 + export const sessionChat = <ThrowOnError extends boolean = false>(parameters: { 240 + id: string; 241 + messageID?: string; 242 + providerID?: string; 243 + modelID?: string; 244 + agent?: string; 245 + system?: string; 246 + tools?: { 247 + [key: string]: boolean; 248 + }; 249 + parts?: Array<({ 250 + type: 'text'; 251 + } & TextPartInput) | ({ 252 + type: 'file'; 253 + } & FilePartInput) | ({ 254 + type: 'agent'; 255 + } & AgentPartInput)>; 256 + }, options?: Options<never, ThrowOnError>) => { 257 + const params = buildClientParams([parameters], [{ args: [ 258 + { in: 'path', key: 'id' }, 259 + { in: 'body', key: 'messageID' }, 260 + { in: 'body', key: 'providerID' }, 261 + { in: 'body', key: 'modelID' }, 262 + { in: 'body', key: 'agent' }, 263 + { in: 'body', key: 'system' }, 264 + { in: 'body', key: 'tools' }, 265 + { in: 'body', key: 'parts' } 266 + ] }]); 267 + return (options?.client ?? client).post<SessionChatResponses, unknown, ThrowOnError>({ 268 + url: '/session/{id}/message', 269 + ...options, 270 + ...params, 271 + headers: { 272 + 'Content-Type': 'application/json', 273 + ...options?.headers, 274 + ...params.headers 275 + } 276 + }); 277 + }; 278 + 279 + /** 280 + * Get a message from a session 281 + */ 282 + export const sessionMessage = <ThrowOnError extends boolean = false>(parameters: { 283 + id: string; 284 + messageID: string; 285 + }, options?: Options<never, ThrowOnError>) => { 286 + const params = buildClientParams([parameters], [{ args: [{ in: 'path', key: 'id' }, { in: 'path', key: 'messageID' }] }]); 287 + return (options?.client ?? client).get<SessionMessageResponses, unknown, ThrowOnError>({ 288 + url: '/session/{id}/message/{messageID}', 289 + ...options, 290 + ...params 291 + }); 292 + }; 293 + 294 + /** 295 + * Run a shell command 296 + */ 297 + export const sessionShell = <ThrowOnError extends boolean = false>(parameters: { 298 + id: string; 299 + agent?: string; 300 + command?: string; 301 + }, options?: Options<never, ThrowOnError>) => { 302 + const params = buildClientParams([parameters], [{ args: [ 303 + { in: 'path', key: 'id' }, 304 + { in: 'body', key: 'agent' }, 305 + { in: 'body', key: 'command' } 306 + ] }]); 307 + return (options?.client ?? client).post<SessionShellResponses, unknown, ThrowOnError>({ 308 + url: '/session/{id}/shell', 309 + ...options, 310 + ...params, 311 + headers: { 312 + 'Content-Type': 'application/json', 313 + ...options?.headers, 314 + ...params.headers 315 + } 316 + }); 317 + }; 318 + 319 + /** 320 + * Revert a message 321 + */ 322 + export const sessionRevert = <ThrowOnError extends boolean = false>(parameters: { 323 + id: string; 324 + messageID?: string; 325 + partID?: string; 326 + }, options?: Options<never, ThrowOnError>) => { 327 + const params = buildClientParams([parameters], [{ args: [ 328 + { in: 'path', key: 'id' }, 329 + { in: 'body', key: 'messageID' }, 330 + { in: 'body', key: 'partID' } 331 + ] }]); 332 + return (options?.client ?? client).post<SessionRevertResponses, unknown, ThrowOnError>({ 333 + url: '/session/{id}/revert', 334 + ...options, 335 + ...params, 336 + headers: { 337 + 'Content-Type': 'application/json', 338 + ...options?.headers, 339 + ...params.headers 340 + } 341 + }); 342 + }; 343 + 344 + /** 345 + * Restore all reverted messages 346 + */ 347 + export const sessionUnrevert = <ThrowOnError extends boolean = false>(parameters: { 348 + id: string; 349 + }, options?: Options<never, ThrowOnError>) => { 350 + const params = buildClientParams([parameters], [{ args: [{ in: 'path', key: 'id' }] }]); 351 + return (options?.client ?? client).post<SessionUnrevertResponses, unknown, ThrowOnError>({ 352 + url: '/session/{id}/unrevert', 353 + ...options, 354 + ...params 355 + }); 356 + }; 357 + 358 + /** 359 + * Respond to a permission request 360 + */ 361 + export const postSessionByIdPermissionsByPermissionId = <ThrowOnError extends boolean = false>(parameters: { 362 + id: string; 363 + permissionID: string; 364 + response?: 'once' | 'always' | 'reject'; 365 + }, options?: Options<never, ThrowOnError>) => { 366 + const params = buildClientParams([parameters], [{ args: [ 367 + { in: 'path', key: 'id' }, 368 + { in: 'path', key: 'permissionID' }, 369 + { in: 'body', key: 'response' } 370 + ] }]); 371 + return (options?.client ?? client).post<PostSessionByIdPermissionsByPermissionIdResponses, unknown, ThrowOnError>({ 372 + url: '/session/{id}/permissions/{permissionID}', 373 + ...options, 374 + ...params, 375 + headers: { 376 + 'Content-Type': 'application/json', 377 + ...options?.headers, 378 + ...params.headers 379 + } 380 + }); 381 + }; 382 + 383 + /** 384 + * List all providers 385 + */ 386 + export const configProviders = <ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>) => (options?.client ?? client).get<ConfigProvidersResponses, unknown, ThrowOnError>({ url: '/config/providers', ...options }); 387 + 388 + /** 389 + * Find text in files 390 + */ 391 + export const findText = <ThrowOnError extends boolean = false>(parameters: { 392 + pattern: string; 393 + }, options?: Options<never, ThrowOnError>) => { 394 + const params = buildClientParams([parameters], [{ args: [{ in: 'query', key: 'pattern' }] }]); 395 + return (options?.client ?? client).get<FindTextResponses, unknown, ThrowOnError>({ 396 + url: '/find', 397 + ...options, 398 + ...params 399 + }); 400 + }; 401 + 402 + /** 403 + * Find files 404 + */ 405 + export const findFiles = <ThrowOnError extends boolean = false>(parameters: { 406 + query: string; 407 + }, options?: Options<never, ThrowOnError>) => { 408 + const params = buildClientParams([parameters], [{ args: [{ in: 'query', key: 'query' }] }]); 409 + return (options?.client ?? client).get<FindFilesResponses, unknown, ThrowOnError>({ 410 + url: '/find/file', 411 + ...options, 412 + ...params 413 + }); 414 + }; 415 + 416 + /** 417 + * Find workspace symbols 418 + */ 419 + export const findSymbols = <ThrowOnError extends boolean = false>(parameters: { 420 + query: string; 421 + }, options?: Options<never, ThrowOnError>) => { 422 + const params = buildClientParams([parameters], [{ args: [{ in: 'query', key: 'query' }] }]); 423 + return (options?.client ?? client).get<FindSymbolsResponses, unknown, ThrowOnError>({ 424 + url: '/find/symbol', 425 + ...options, 426 + ...params 427 + }); 428 + }; 429 + 430 + /** 431 + * Read a file 432 + */ 433 + export const fileRead = <ThrowOnError extends boolean = false>(parameters: { 434 + path: string; 435 + }, options?: Options<never, ThrowOnError>) => { 436 + const params = buildClientParams([parameters], [{ args: [{ in: 'query', key: 'path' }] }]); 437 + return (options?.client ?? client).get<FileReadResponses, unknown, ThrowOnError>({ 438 + url: '/file', 439 + ...options, 440 + ...params 441 + }); 442 + }; 443 + 444 + /** 445 + * Get file status 446 + */ 447 + export const fileStatus = <ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>) => (options?.client ?? client).get<FileStatusResponses, unknown, ThrowOnError>({ url: '/file/status', ...options }); 448 + 449 + /** 450 + * Write a log entry to the server logs 451 + */ 452 + export const appLog = <ThrowOnError extends boolean = false>(parameters?: { 453 + service?: string; 454 + level?: 'debug' | 'info' | 'error' | 'warn'; 455 + message?: string; 456 + extra?: { 457 + [key: string]: unknown; 458 + }; 459 + }, options?: Options<never, ThrowOnError>) => { 460 + const params = buildClientParams([parameters], [{ args: [ 461 + { in: 'body', key: 'service' }, 462 + { in: 'body', key: 'level' }, 463 + { in: 'body', key: 'message' }, 464 + { in: 'body', key: 'extra' } 465 + ] }]); 466 + return (options?.client ?? client).post<AppLogResponses, unknown, ThrowOnError>({ 467 + url: '/log', 468 + ...options, 469 + ...params, 470 + headers: { 471 + 'Content-Type': 'application/json', 472 + ...options?.headers, 473 + ...params.headers 474 + } 475 + }); 476 + }; 477 + 478 + /** 479 + * List all agents 480 + */ 481 + export const appAgents = <ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>) => (options?.client ?? client).get<AppAgentsResponses, unknown, ThrowOnError>({ url: '/agent', ...options }); 482 + 483 + /** 484 + * Append prompt to the TUI 485 + */ 486 + export const tuiAppendPrompt = <ThrowOnError extends boolean = false>(parameters?: { 487 + text?: string; 488 + }, options?: Options<never, ThrowOnError>) => { 489 + const params = buildClientParams([parameters], [{ args: [{ in: 'body', key: 'text' }] }]); 490 + return (options?.client ?? client).post<TuiAppendPromptResponses, unknown, ThrowOnError>({ 491 + url: '/tui/append-prompt', 492 + ...options, 493 + ...params, 494 + headers: { 495 + 'Content-Type': 'application/json', 496 + ...options?.headers, 497 + ...params.headers 498 + } 499 + }); 500 + }; 501 + 502 + /** 503 + * Open the help dialog 504 + */ 505 + export const tuiOpenHelp = <ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>) => (options?.client ?? client).post<TuiOpenHelpResponses, unknown, ThrowOnError>({ url: '/tui/open-help', ...options }); 506 + 507 + /** 508 + * Open the session dialog 509 + */ 510 + export const tuiOpenSessions = <ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>) => (options?.client ?? client).post<TuiOpenSessionsResponses, unknown, ThrowOnError>({ url: '/tui/open-sessions', ...options }); 511 + 512 + /** 513 + * Open the theme dialog 514 + */ 515 + export const tuiOpenThemes = <ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>) => (options?.client ?? client).post<TuiOpenThemesResponses, unknown, ThrowOnError>({ url: '/tui/open-themes', ...options }); 516 + 517 + /** 518 + * Open the model dialog 519 + */ 520 + export const tuiOpenModels = <ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>) => (options?.client ?? client).post<TuiOpenModelsResponses, unknown, ThrowOnError>({ url: '/tui/open-models', ...options }); 521 + 522 + /** 523 + * Submit the prompt 524 + */ 525 + export const tuiSubmitPrompt = <ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>) => (options?.client ?? client).post<TuiSubmitPromptResponses, unknown, ThrowOnError>({ url: '/tui/submit-prompt', ...options }); 526 + 527 + /** 528 + * Clear the prompt 529 + */ 530 + export const tuiClearPrompt = <ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>) => (options?.client ?? client).post<TuiClearPromptResponses, unknown, ThrowOnError>({ url: '/tui/clear-prompt', ...options }); 531 + 532 + /** 533 + * Execute a TUI command (e.g. agent_cycle) 534 + */ 535 + export const tuiExecuteCommand = <ThrowOnError extends boolean = false>(parameters?: { 536 + command?: string; 537 + }, options?: Options<never, ThrowOnError>) => { 538 + const params = buildClientParams([parameters], [{ args: [{ in: 'body', key: 'command' }] }]); 539 + return (options?.client ?? client).post<TuiExecuteCommandResponses, unknown, ThrowOnError>({ 540 + url: '/tui/execute-command', 541 + ...options, 542 + ...params, 543 + headers: { 544 + 'Content-Type': 'application/json', 545 + ...options?.headers, 546 + ...params.headers 547 + } 548 + }); 549 + }; 550 + 551 + /** 552 + * Show a toast notification in the TUI 553 + */ 554 + export const tuiShowToast = <ThrowOnError extends boolean = false>(parameters?: { 555 + title?: string; 556 + message?: string; 557 + variant?: 'info' | 'success' | 'warning' | 'error'; 558 + }, options?: Options<never, ThrowOnError>) => { 559 + const params = buildClientParams([parameters], [{ args: [ 560 + { in: 'body', key: 'title' }, 561 + { in: 'body', key: 'message' }, 562 + { in: 'body', key: 'variant' } 563 + ] }]); 564 + return (options?.client ?? client).post<TuiShowToastResponses, unknown, ThrowOnError>({ 565 + url: '/tui/show-toast', 566 + ...options, 567 + ...params, 568 + headers: { 569 + 'Content-Type': 'application/json', 570 + ...options?.headers, 571 + ...params.headers 572 + } 573 + }); 574 + }; 575 + 576 + /** 577 + * Set authentication credentials 578 + */ 579 + export const authSet = <ThrowOnError extends boolean = false>(parameters: { 580 + id: string; 581 + auth?: Auth; 582 + }, options?: Options<never, ThrowOnError>) => { 583 + const params = buildClientParams([parameters], [{ args: [{ in: 'path', key: 'id' }, { key: 'auth', map: 'body' }] }]); 584 + return (options?.client ?? client).put<AuthSetResponses, AuthSetErrors, ThrowOnError>({ 585 + url: '/auth/{id}', 586 + ...options, 587 + ...params, 588 + headers: { 589 + 'Content-Type': 'application/json', 590 + ...options?.headers, 591 + ...params.headers 592 + } 593 + }); 594 + };
+1943
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/types.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + export type ClientOptions = { 4 + baseUrl: `${string}://${string}` | (string & {}); 5 + }; 6 + 7 + export type Event = ({ 8 + type: 'installation.updated'; 9 + } & EventInstallationUpdated) | ({ 10 + type: 'lsp.client.diagnostics'; 11 + } & EventLspClientDiagnostics) | ({ 12 + type: 'message.updated'; 13 + } & EventMessageUpdated) | ({ 14 + type: 'message.removed'; 15 + } & EventMessageRemoved) | ({ 16 + type: 'message.part.updated'; 17 + } & EventMessagePartUpdated) | ({ 18 + type: 'message.part.removed'; 19 + } & EventMessagePartRemoved) | ({ 20 + type: 'storage.write'; 21 + } & EventStorageWrite) | ({ 22 + type: 'permission.updated'; 23 + } & EventPermissionUpdated) | ({ 24 + type: 'permission.replied'; 25 + } & EventPermissionReplied) | ({ 26 + type: 'file.edited'; 27 + } & EventFileEdited) | ({ 28 + type: 'session.updated'; 29 + } & EventSessionUpdated) | ({ 30 + type: 'session.deleted'; 31 + } & EventSessionDeleted) | ({ 32 + type: 'session.idle'; 33 + } & EventSessionIdle) | ({ 34 + type: 'session.error'; 35 + } & EventSessionError) | ({ 36 + type: 'server.connected'; 37 + } & EventServerConnected) | ({ 38 + type: 'file.watcher.updated'; 39 + } & EventFileWatcherUpdated) | ({ 40 + type: 'ide.installed'; 41 + } & EventIdeInstalled); 42 + 43 + export type EventInstallationUpdated = { 44 + type: 'installation.updated'; 45 + properties: { 46 + version: string; 47 + }; 48 + }; 49 + 50 + export type EventLspClientDiagnostics = { 51 + type: 'lsp.client.diagnostics'; 52 + properties: { 53 + serverID: string; 54 + path: string; 55 + }; 56 + }; 57 + 58 + export type EventMessageUpdated = { 59 + type: 'message.updated'; 60 + properties: { 61 + info: Message; 62 + }; 63 + }; 64 + 65 + export type Message = ({ 66 + role: 'user'; 67 + } & UserMessage) | ({ 68 + role: 'assistant'; 69 + } & AssistantMessage); 70 + 71 + export type UserMessage = { 72 + id: string; 73 + sessionID: string; 74 + role: 'user'; 75 + time: { 76 + created: number; 77 + }; 78 + }; 79 + 80 + export type AssistantMessage = { 81 + id: string; 82 + sessionID: string; 83 + role: 'assistant'; 84 + time: { 85 + created: number; 86 + completed?: number; 87 + }; 88 + error?: ({ 89 + name: 'ProviderAuthError'; 90 + } & ProviderAuthError) | ({ 91 + name: 'UnknownError'; 92 + } & UnknownError) | ({ 93 + name: 'MessageOutputLengthError'; 94 + } & MessageOutputLengthError) | ({ 95 + name: 'MessageAbortedError'; 96 + } & MessageAbortedError); 97 + system: Array<string>; 98 + modelID: string; 99 + providerID: string; 100 + mode: string; 101 + path: { 102 + cwd: string; 103 + root: string; 104 + }; 105 + summary?: boolean; 106 + cost: number; 107 + tokens: { 108 + input: number; 109 + output: number; 110 + reasoning: number; 111 + cache: { 112 + read: number; 113 + write: number; 114 + }; 115 + }; 116 + }; 117 + 118 + export type ProviderAuthError = { 119 + name: 'ProviderAuthError'; 120 + data: { 121 + providerID: string; 122 + message: string; 123 + }; 124 + }; 125 + 126 + export type UnknownError = { 127 + name: 'UnknownError'; 128 + data: { 129 + message: string; 130 + }; 131 + }; 132 + 133 + export type MessageOutputLengthError = { 134 + name: 'MessageOutputLengthError'; 135 + data: { 136 + [key: string]: unknown; 137 + }; 138 + }; 139 + 140 + export type MessageAbortedError = { 141 + name: 'MessageAbortedError'; 142 + data: { 143 + [key: string]: unknown; 144 + }; 145 + }; 146 + 147 + export type EventMessageRemoved = { 148 + type: 'message.removed'; 149 + properties: { 150 + sessionID: string; 151 + messageID: string; 152 + }; 153 + }; 154 + 155 + export type EventMessagePartUpdated = { 156 + type: 'message.part.updated'; 157 + properties: { 158 + part: Part; 159 + }; 160 + }; 161 + 162 + export type Part = ({ 163 + type: 'text'; 164 + } & TextPart) | ({ 165 + type: 'reasoning'; 166 + } & ReasoningPart) | ({ 167 + type: 'file'; 168 + } & FilePart) | ({ 169 + type: 'tool'; 170 + } & ToolPart) | ({ 171 + type: 'step-start'; 172 + } & StepStartPart) | ({ 173 + type: 'step-finish'; 174 + } & StepFinishPart) | ({ 175 + type: 'snapshot'; 176 + } & SnapshotPart) | ({ 177 + type: 'patch'; 178 + } & PatchPart) | ({ 179 + type: 'agent'; 180 + } & AgentPart); 181 + 182 + export type TextPart = { 183 + id: string; 184 + sessionID: string; 185 + messageID: string; 186 + type: 'text'; 187 + text: string; 188 + synthetic?: boolean; 189 + time?: { 190 + start: number; 191 + end?: number; 192 + }; 193 + }; 194 + 195 + export type ReasoningPart = { 196 + id: string; 197 + sessionID: string; 198 + messageID: string; 199 + type: 'reasoning'; 200 + text: string; 201 + metadata?: { 202 + [key: string]: unknown; 203 + }; 204 + time: { 205 + start: number; 206 + end?: number; 207 + }; 208 + }; 209 + 210 + export type FilePart = { 211 + id: string; 212 + sessionID: string; 213 + messageID: string; 214 + type: 'file'; 215 + mime: string; 216 + filename?: string; 217 + url: string; 218 + source?: FilePartSource; 219 + }; 220 + 221 + export type FilePartSource = ({ 222 + type: 'file'; 223 + } & FileSource) | ({ 224 + type: 'symbol'; 225 + } & SymbolSource); 226 + 227 + export type FileSource = { 228 + text: FilePartSourceText; 229 + type: 'file'; 230 + path: string; 231 + }; 232 + 233 + export type FilePartSourceText = { 234 + value: string; 235 + start: number; 236 + end: number; 237 + }; 238 + 239 + export type SymbolSource = { 240 + text: FilePartSourceText; 241 + type: 'symbol'; 242 + path: string; 243 + range: Range; 244 + name: string; 245 + kind: number; 246 + }; 247 + 248 + export type Range = { 249 + start: { 250 + line: number; 251 + character: number; 252 + }; 253 + end: { 254 + line: number; 255 + character: number; 256 + }; 257 + }; 258 + 259 + export type ToolPart = { 260 + id: string; 261 + sessionID: string; 262 + messageID: string; 263 + type: 'tool'; 264 + callID: string; 265 + tool: string; 266 + state: ToolState; 267 + }; 268 + 269 + export type ToolState = ({ 270 + status: 'pending'; 271 + } & ToolStatePending) | ({ 272 + status: 'running'; 273 + } & ToolStateRunning) | ({ 274 + status: 'completed'; 275 + } & ToolStateCompleted) | ({ 276 + status: 'error'; 277 + } & ToolStateError); 278 + 279 + export type ToolStatePending = { 280 + status: 'pending'; 281 + }; 282 + 283 + export type ToolStateRunning = { 284 + status: 'running'; 285 + input?: unknown; 286 + title?: string; 287 + metadata?: { 288 + [key: string]: unknown; 289 + }; 290 + time: { 291 + start: number; 292 + }; 293 + }; 294 + 295 + export type ToolStateCompleted = { 296 + status: 'completed'; 297 + input: { 298 + [key: string]: unknown; 299 + }; 300 + output: string; 301 + title: string; 302 + metadata: { 303 + [key: string]: unknown; 304 + }; 305 + time: { 306 + start: number; 307 + end: number; 308 + }; 309 + }; 310 + 311 + export type ToolStateError = { 312 + status: 'error'; 313 + input: { 314 + [key: string]: unknown; 315 + }; 316 + error: string; 317 + metadata?: { 318 + [key: string]: unknown; 319 + }; 320 + time: { 321 + start: number; 322 + end: number; 323 + }; 324 + }; 325 + 326 + export type StepStartPart = { 327 + id: string; 328 + sessionID: string; 329 + messageID: string; 330 + type: 'step-start'; 331 + }; 332 + 333 + export type StepFinishPart = { 334 + id: string; 335 + sessionID: string; 336 + messageID: string; 337 + type: 'step-finish'; 338 + cost: number; 339 + tokens: { 340 + input: number; 341 + output: number; 342 + reasoning: number; 343 + cache: { 344 + read: number; 345 + write: number; 346 + }; 347 + }; 348 + }; 349 + 350 + export type SnapshotPart = { 351 + id: string; 352 + sessionID: string; 353 + messageID: string; 354 + type: 'snapshot'; 355 + snapshot: string; 356 + }; 357 + 358 + export type PatchPart = { 359 + id: string; 360 + sessionID: string; 361 + messageID: string; 362 + type: 'patch'; 363 + hash: string; 364 + files: Array<string>; 365 + }; 366 + 367 + export type AgentPart = { 368 + id: string; 369 + sessionID: string; 370 + messageID: string; 371 + type: 'agent'; 372 + name: string; 373 + source?: { 374 + value: string; 375 + start: number; 376 + end: number; 377 + }; 378 + }; 379 + 380 + export type EventMessagePartRemoved = { 381 + type: 'message.part.removed'; 382 + properties: { 383 + sessionID: string; 384 + messageID: string; 385 + partID: string; 386 + }; 387 + }; 388 + 389 + export type EventStorageWrite = { 390 + type: 'storage.write'; 391 + properties: { 392 + key: string; 393 + content?: unknown; 394 + }; 395 + }; 396 + 397 + export type EventPermissionUpdated = { 398 + type: 'permission.updated'; 399 + properties: Permission; 400 + }; 401 + 402 + export type Permission = { 403 + id: string; 404 + type: string; 405 + pattern?: string; 406 + sessionID: string; 407 + messageID: string; 408 + callID?: string; 409 + title: string; 410 + metadata: { 411 + [key: string]: unknown; 412 + }; 413 + time: { 414 + created: number; 415 + }; 416 + }; 417 + 418 + export type EventPermissionReplied = { 419 + type: 'permission.replied'; 420 + properties: { 421 + sessionID: string; 422 + permissionID: string; 423 + response: string; 424 + }; 425 + }; 426 + 427 + export type EventFileEdited = { 428 + type: 'file.edited'; 429 + properties: { 430 + file: string; 431 + }; 432 + }; 433 + 434 + export type EventSessionUpdated = { 435 + type: 'session.updated'; 436 + properties: { 437 + info: Session; 438 + }; 439 + }; 440 + 441 + export type Session = { 442 + id: string; 443 + parentID?: string; 444 + share?: { 445 + url: string; 446 + }; 447 + title: string; 448 + version: string; 449 + time: { 450 + created: number; 451 + updated: number; 452 + }; 453 + revert?: { 454 + messageID: string; 455 + partID?: string; 456 + snapshot?: string; 457 + diff?: string; 458 + }; 459 + }; 460 + 461 + export type EventSessionDeleted = { 462 + type: 'session.deleted'; 463 + properties: { 464 + info: Session; 465 + }; 466 + }; 467 + 468 + export type EventSessionIdle = { 469 + type: 'session.idle'; 470 + properties: { 471 + sessionID: string; 472 + }; 473 + }; 474 + 475 + export type EventSessionError = { 476 + type: 'session.error'; 477 + properties: { 478 + sessionID?: string; 479 + error?: ({ 480 + name: 'ProviderAuthError'; 481 + } & ProviderAuthError) | ({ 482 + name: 'UnknownError'; 483 + } & UnknownError) | ({ 484 + name: 'MessageOutputLengthError'; 485 + } & MessageOutputLengthError) | ({ 486 + name: 'MessageAbortedError'; 487 + } & MessageAbortedError); 488 + }; 489 + }; 490 + 491 + export type EventServerConnected = { 492 + type: 'server.connected'; 493 + properties: { 494 + [key: string]: unknown; 495 + }; 496 + }; 497 + 498 + export type EventFileWatcherUpdated = { 499 + type: 'file.watcher.updated'; 500 + properties: { 501 + file: string; 502 + event: 'rename' | 'change'; 503 + }; 504 + }; 505 + 506 + export type EventIdeInstalled = { 507 + type: 'ide.installed'; 508 + properties: { 509 + ide: string; 510 + }; 511 + }; 512 + 513 + export type App = { 514 + hostname: string; 515 + git: boolean; 516 + path: { 517 + config: string; 518 + data: string; 519 + root: string; 520 + cwd: string; 521 + state: string; 522 + }; 523 + time: { 524 + initialized?: number; 525 + }; 526 + }; 527 + 528 + export type Config = { 529 + /** 530 + * JSON schema reference for configuration validation 531 + */ 532 + $schema?: string; 533 + /** 534 + * Theme name to use for the interface 535 + */ 536 + theme?: string; 537 + /** 538 + * Custom keybind configurations 539 + */ 540 + keybinds?: KeybindsConfig; 541 + /** 542 + * TUI specific settings 543 + */ 544 + tui?: { 545 + /** 546 + * TUI scroll speed 547 + */ 548 + scroll_speed: number; 549 + }; 550 + plugin?: Array<string>; 551 + snapshot?: boolean; 552 + /** 553 + * Control sharing behavior:'manual' allows manual sharing via commands, 'auto' enables automatic sharing, 'disabled' disables all sharing 554 + */ 555 + share?: 'manual' | 'auto' | 'disabled'; 556 + /** 557 + * @deprecated Use 'share' field instead. Share newly created sessions automatically 558 + */ 559 + autoshare?: boolean; 560 + /** 561 + * Automatically update to the latest version 562 + */ 563 + autoupdate?: boolean; 564 + /** 565 + * Disable providers that are loaded automatically 566 + */ 567 + disabled_providers?: Array<string>; 568 + /** 569 + * Model to use in the format of provider/model, eg anthropic/claude-2 570 + */ 571 + model?: string; 572 + /** 573 + * Small model to use for tasks like title generation in the format of provider/model 574 + */ 575 + small_model?: string; 576 + /** 577 + * Custom username to display in conversations instead of system username 578 + */ 579 + username?: string; 580 + /** 581 + * @deprecated Use `agent` field instead. 582 + */ 583 + mode?: { 584 + build?: AgentConfig; 585 + plan?: AgentConfig; 586 + [key: string]: AgentConfig | undefined; 587 + }; 588 + /** 589 + * Agent configuration, see https://opencode.ai/docs/agent 590 + */ 591 + agent?: { 592 + plan?: AgentConfig; 593 + build?: AgentConfig; 594 + general?: AgentConfig; 595 + [key: string]: AgentConfig | undefined; 596 + }; 597 + /** 598 + * Custom provider configurations and model overrides 599 + */ 600 + provider?: { 601 + [key: string]: { 602 + api?: string; 603 + name?: string; 604 + env?: Array<string>; 605 + id?: string; 606 + npm?: string; 607 + models?: { 608 + [key: string]: { 609 + id?: string; 610 + name?: string; 611 + release_date?: string; 612 + attachment?: boolean; 613 + reasoning?: boolean; 614 + temperature?: boolean; 615 + tool_call?: boolean; 616 + cost?: { 617 + input: number; 618 + output: number; 619 + cache_read?: number; 620 + cache_write?: number; 621 + }; 622 + limit?: { 623 + context: number; 624 + output: number; 625 + }; 626 + options?: { 627 + [key: string]: unknown; 628 + }; 629 + }; 630 + }; 631 + options?: { 632 + apiKey?: string; 633 + baseURL?: string; 634 + [key: string]: unknown | string | undefined; 635 + }; 636 + }; 637 + }; 638 + /** 639 + * MCP (Model Context Protocol) server configurations 640 + */ 641 + mcp?: { 642 + [key: string]: ({ 643 + type: 'local'; 644 + } & McpLocalConfig) | ({ 645 + type: 'remote'; 646 + } & McpRemoteConfig); 647 + }; 648 + formatter?: { 649 + [key: string]: { 650 + disabled?: boolean; 651 + command?: Array<string>; 652 + environment?: { 653 + [key: string]: string; 654 + }; 655 + extensions?: Array<string>; 656 + }; 657 + }; 658 + lsp?: { 659 + [key: string]: { 660 + disabled: true; 661 + } | { 662 + command: Array<string>; 663 + extensions?: Array<string>; 664 + disabled?: boolean; 665 + env?: { 666 + [key: string]: string; 667 + }; 668 + initialization?: { 669 + [key: string]: unknown; 670 + }; 671 + }; 672 + }; 673 + /** 674 + * Additional instruction files or patterns to include 675 + */ 676 + instructions?: Array<string>; 677 + /** 678 + * @deprecated Always uses stretch layout. 679 + */ 680 + layout?: LayoutConfig; 681 + permission?: { 682 + edit?: 'ask' | 'allow' | 'deny'; 683 + bash?: 'ask' | 'allow' | 'deny' | { 684 + [key: string]: 'ask' | 'allow' | 'deny'; 685 + }; 686 + webfetch?: 'ask' | 'allow' | 'deny'; 687 + }; 688 + tools?: { 689 + [key: string]: boolean; 690 + }; 691 + experimental?: { 692 + hook?: { 693 + file_edited?: { 694 + [key: string]: Array<{ 695 + command: Array<string>; 696 + environment?: { 697 + [key: string]: string; 698 + }; 699 + }>; 700 + }; 701 + session_completed?: Array<{ 702 + command: Array<string>; 703 + environment?: { 704 + [key: string]: string; 705 + }; 706 + }>; 707 + }; 708 + }; 709 + }; 710 + 711 + export type KeybindsConfig = { 712 + /** 713 + * Leader key for keybind combinations 714 + */ 715 + leader: string; 716 + /** 717 + * Show help dialog 718 + */ 719 + app_help: string; 720 + /** 721 + * Exit the application 722 + */ 723 + app_exit: string; 724 + /** 725 + * Open external editor 726 + */ 727 + editor_open: string; 728 + /** 729 + * List available themes 730 + */ 731 + theme_list: string; 732 + /** 733 + * Create/update AGENTS.md 734 + */ 735 + project_init: string; 736 + /** 737 + * Toggle tool details 738 + */ 739 + tool_details: string; 740 + /** 741 + * Toggle thinking blocks 742 + */ 743 + thinking_blocks: string; 744 + /** 745 + * Export session to editor 746 + */ 747 + session_export: string; 748 + /** 749 + * Create a new session 750 + */ 751 + session_new: string; 752 + /** 753 + * List all sessions 754 + */ 755 + session_list: string; 756 + /** 757 + * Show session timeline 758 + */ 759 + session_timeline: string; 760 + /** 761 + * Share current session 762 + */ 763 + session_share: string; 764 + /** 765 + * Unshare current session 766 + */ 767 + session_unshare: string; 768 + /** 769 + * Interrupt current session 770 + */ 771 + session_interrupt: string; 772 + /** 773 + * Compact the session 774 + */ 775 + session_compact: string; 776 + /** 777 + * Cycle to next child session 778 + */ 779 + session_child_cycle: string; 780 + /** 781 + * Cycle to previous child session 782 + */ 783 + session_child_cycle_reverse: string; 784 + /** 785 + * Scroll messages up by one page 786 + */ 787 + messages_page_up: string; 788 + /** 789 + * Scroll messages down by one page 790 + */ 791 + messages_page_down: string; 792 + /** 793 + * Scroll messages up by half page 794 + */ 795 + messages_half_page_up: string; 796 + /** 797 + * Scroll messages down by half page 798 + */ 799 + messages_half_page_down: string; 800 + /** 801 + * Navigate to first message 802 + */ 803 + messages_first: string; 804 + /** 805 + * Navigate to last message 806 + */ 807 + messages_last: string; 808 + /** 809 + * Copy message 810 + */ 811 + messages_copy: string; 812 + /** 813 + * Undo message 814 + */ 815 + messages_undo: string; 816 + /** 817 + * Redo message 818 + */ 819 + messages_redo: string; 820 + /** 821 + * List available models 822 + */ 823 + model_list: string; 824 + /** 825 + * Next recent model 826 + */ 827 + model_cycle_recent: string; 828 + /** 829 + * Previous recent model 830 + */ 831 + model_cycle_recent_reverse: string; 832 + /** 833 + * List agents 834 + */ 835 + agent_list: string; 836 + /** 837 + * Next agent 838 + */ 839 + agent_cycle: string; 840 + /** 841 + * Previous agent 842 + */ 843 + agent_cycle_reverse: string; 844 + /** 845 + * Clear input field 846 + */ 847 + input_clear: string; 848 + /** 849 + * Paste from clipboard 850 + */ 851 + input_paste: string; 852 + /** 853 + * Submit input 854 + */ 855 + input_submit: string; 856 + /** 857 + * Insert newline in input 858 + */ 859 + input_newline: string; 860 + /** 861 + * @deprecated use agent_cycle. Next mode 862 + */ 863 + switch_mode: string; 864 + /** 865 + * @deprecated use agent_cycle_reverse. Previous mode 866 + */ 867 + switch_mode_reverse: string; 868 + /** 869 + * @deprecated use agent_cycle. Next agent 870 + */ 871 + switch_agent: string; 872 + /** 873 + * @deprecated use agent_cycle_reverse. Previous agent 874 + */ 875 + switch_agent_reverse: string; 876 + /** 877 + * @deprecated Currently not available. List files 878 + */ 879 + file_list: string; 880 + /** 881 + * @deprecated Close file 882 + */ 883 + file_close: string; 884 + /** 885 + * @deprecated Search file 886 + */ 887 + file_search: string; 888 + /** 889 + * @deprecated Split/unified diff 890 + */ 891 + file_diff_toggle: string; 892 + /** 893 + * @deprecated Navigate to previous message 894 + */ 895 + messages_previous: string; 896 + /** 897 + * @deprecated Navigate to next message 898 + */ 899 + messages_next: string; 900 + /** 901 + * @deprecated Toggle layout 902 + */ 903 + messages_layout_toggle: string; 904 + /** 905 + * @deprecated use messages_undo. Revert message 906 + */ 907 + messages_revert: string; 908 + }; 909 + 910 + export type AgentConfig = { 911 + model?: string; 912 + temperature?: number; 913 + top_p?: number; 914 + prompt?: string; 915 + tools?: { 916 + [key: string]: boolean; 917 + }; 918 + disable?: boolean; 919 + /** 920 + * Description of when to use the agent 921 + */ 922 + description?: string; 923 + mode?: 'subagent' | 'primary' | 'all'; 924 + permission?: { 925 + edit?: 'ask' | 'allow' | 'deny'; 926 + bash?: 'ask' | 'allow' | 'deny' | { 927 + [key: string]: 'ask' | 'allow' | 'deny'; 928 + }; 929 + webfetch?: 'ask' | 'allow' | 'deny'; 930 + }; 931 + [key: string]: unknown | string | number | { 932 + [key: string]: boolean; 933 + } | boolean | 'subagent' | 'primary' | 'all' | { 934 + edit?: 'ask' | 'allow' | 'deny'; 935 + bash?: 'ask' | 'allow' | 'deny' | { 936 + [key: string]: 'ask' | 'allow' | 'deny'; 937 + }; 938 + webfetch?: 'ask' | 'allow' | 'deny'; 939 + } | undefined; 940 + }; 941 + 942 + export type Provider = { 943 + api?: string; 944 + name: string; 945 + env: Array<string>; 946 + id: string; 947 + npm?: string; 948 + models: { 949 + [key: string]: Model; 950 + }; 951 + }; 952 + 953 + export type Model = { 954 + id: string; 955 + name: string; 956 + release_date: string; 957 + attachment: boolean; 958 + reasoning: boolean; 959 + temperature: boolean; 960 + tool_call: boolean; 961 + cost: { 962 + input: number; 963 + output: number; 964 + cache_read?: number; 965 + cache_write?: number; 966 + }; 967 + limit: { 968 + context: number; 969 + output: number; 970 + }; 971 + options: { 972 + [key: string]: unknown; 973 + }; 974 + }; 975 + 976 + export type McpLocalConfig = { 977 + /** 978 + * Type of MCP server connection 979 + */ 980 + type: 'local'; 981 + /** 982 + * Command and arguments to run the MCP server 983 + */ 984 + command: Array<string>; 985 + /** 986 + * Environment variables to set when running the MCP server 987 + */ 988 + environment?: { 989 + [key: string]: string; 990 + }; 991 + /** 992 + * Enable or disable the MCP server on startup 993 + */ 994 + enabled?: boolean; 995 + }; 996 + 997 + export type McpRemoteConfig = { 998 + /** 999 + * Type of MCP server connection 1000 + */ 1001 + type: 'remote'; 1002 + /** 1003 + * URL of the remote MCP server 1004 + */ 1005 + url: string; 1006 + /** 1007 + * Enable or disable the MCP server on startup 1008 + */ 1009 + enabled?: boolean; 1010 + /** 1011 + * Headers to send with the request 1012 + */ 1013 + headers?: { 1014 + [key: string]: string; 1015 + }; 1016 + }; 1017 + 1018 + export type LayoutConfig = 'auto' | 'stretch'; 1019 + 1020 + export type Error = { 1021 + data: { 1022 + [key: string]: unknown; 1023 + }; 1024 + }; 1025 + 1026 + export type TextPartInput = { 1027 + id?: string; 1028 + type: 'text'; 1029 + text: string; 1030 + synthetic?: boolean; 1031 + time?: { 1032 + start: number; 1033 + end?: number; 1034 + }; 1035 + }; 1036 + 1037 + export type FilePartInput = { 1038 + id?: string; 1039 + type: 'file'; 1040 + mime: string; 1041 + filename?: string; 1042 + url: string; 1043 + source?: FilePartSource; 1044 + }; 1045 + 1046 + export type AgentPartInput = { 1047 + id?: string; 1048 + type: 'agent'; 1049 + name: string; 1050 + source?: { 1051 + value: string; 1052 + start: number; 1053 + end: number; 1054 + }; 1055 + }; 1056 + 1057 + export type Symbol = { 1058 + name: string; 1059 + kind: number; 1060 + location: { 1061 + uri: string; 1062 + range: Range; 1063 + }; 1064 + }; 1065 + 1066 + export type File = { 1067 + path: string; 1068 + added: number; 1069 + removed: number; 1070 + status: 'added' | 'deleted' | 'modified'; 1071 + }; 1072 + 1073 + export type Agent = { 1074 + name: string; 1075 + description?: string; 1076 + mode: 'subagent' | 'primary' | 'all'; 1077 + builtIn: boolean; 1078 + topP?: number; 1079 + temperature?: number; 1080 + permission: { 1081 + edit: 'ask' | 'allow' | 'deny'; 1082 + bash: { 1083 + [key: string]: 'ask' | 'allow' | 'deny'; 1084 + }; 1085 + webfetch?: 'ask' | 'allow' | 'deny'; 1086 + }; 1087 + model?: { 1088 + modelID: string; 1089 + providerID: string; 1090 + }; 1091 + prompt?: string; 1092 + tools: { 1093 + [key: string]: boolean; 1094 + }; 1095 + options: { 1096 + [key: string]: unknown; 1097 + }; 1098 + }; 1099 + 1100 + export type Auth = ({ 1101 + type: 'oauth'; 1102 + } & OAuth) | ({ 1103 + type: 'api'; 1104 + } & ApiAuth) | ({ 1105 + type: 'wellknown'; 1106 + } & WellKnownAuth); 1107 + 1108 + export type OAuth = { 1109 + type: 'oauth'; 1110 + refresh: string; 1111 + access: string; 1112 + expires: number; 1113 + }; 1114 + 1115 + export type ApiAuth = { 1116 + type: 'api'; 1117 + key: string; 1118 + }; 1119 + 1120 + export type WellKnownAuth = { 1121 + type: 'wellknown'; 1122 + key: string; 1123 + token: string; 1124 + }; 1125 + 1126 + export type EventSubscribeData = { 1127 + body?: never; 1128 + path?: never; 1129 + query?: never; 1130 + url: '/event'; 1131 + }; 1132 + 1133 + export type EventSubscribeResponses = { 1134 + /** 1135 + * Event stream 1136 + */ 1137 + 200: Event; 1138 + }; 1139 + 1140 + export type EventSubscribeResponse = EventSubscribeResponses[keyof EventSubscribeResponses]; 1141 + 1142 + export type AppGetData = { 1143 + body?: never; 1144 + path?: never; 1145 + query?: never; 1146 + url: '/app'; 1147 + }; 1148 + 1149 + export type AppGetResponses = { 1150 + /** 1151 + * 200 1152 + */ 1153 + 200: App; 1154 + }; 1155 + 1156 + export type AppGetResponse = AppGetResponses[keyof AppGetResponses]; 1157 + 1158 + export type AppInitData = { 1159 + body?: never; 1160 + path?: never; 1161 + query?: never; 1162 + url: '/app/init'; 1163 + }; 1164 + 1165 + export type AppInitResponses = { 1166 + /** 1167 + * Initialize the app 1168 + */ 1169 + 200: boolean; 1170 + }; 1171 + 1172 + export type AppInitResponse = AppInitResponses[keyof AppInitResponses]; 1173 + 1174 + export type ConfigGetData = { 1175 + body?: never; 1176 + path?: never; 1177 + query?: never; 1178 + url: '/config'; 1179 + }; 1180 + 1181 + export type ConfigGetResponses = { 1182 + /** 1183 + * Get config info 1184 + */ 1185 + 200: Config; 1186 + }; 1187 + 1188 + export type ConfigGetResponse = ConfigGetResponses[keyof ConfigGetResponses]; 1189 + 1190 + export type SessionListData = { 1191 + body?: never; 1192 + path?: never; 1193 + query?: never; 1194 + url: '/session'; 1195 + }; 1196 + 1197 + export type SessionListResponses = { 1198 + /** 1199 + * List of sessions 1200 + */ 1201 + 200: Array<Session>; 1202 + }; 1203 + 1204 + export type SessionListResponse = SessionListResponses[keyof SessionListResponses]; 1205 + 1206 + export type SessionCreateData = { 1207 + body?: { 1208 + parentID?: string; 1209 + title?: string; 1210 + }; 1211 + path?: never; 1212 + query?: never; 1213 + url: '/session'; 1214 + }; 1215 + 1216 + export type SessionCreateErrors = { 1217 + /** 1218 + * Bad request 1219 + */ 1220 + 400: Error; 1221 + }; 1222 + 1223 + export type SessionCreateError = SessionCreateErrors[keyof SessionCreateErrors]; 1224 + 1225 + export type SessionCreateResponses = { 1226 + /** 1227 + * Successfully created session 1228 + */ 1229 + 200: Session; 1230 + }; 1231 + 1232 + export type SessionCreateResponse = SessionCreateResponses[keyof SessionCreateResponses]; 1233 + 1234 + export type SessionDeleteData = { 1235 + body?: never; 1236 + path: { 1237 + id: string; 1238 + }; 1239 + query?: never; 1240 + url: '/session/{id}'; 1241 + }; 1242 + 1243 + export type SessionDeleteResponses = { 1244 + /** 1245 + * Successfully deleted session 1246 + */ 1247 + 200: boolean; 1248 + }; 1249 + 1250 + export type SessionDeleteResponse = SessionDeleteResponses[keyof SessionDeleteResponses]; 1251 + 1252 + export type SessionGetData = { 1253 + body?: never; 1254 + path: { 1255 + id: string; 1256 + }; 1257 + query?: never; 1258 + url: '/session/{id}'; 1259 + }; 1260 + 1261 + export type SessionGetResponses = { 1262 + /** 1263 + * Get session 1264 + */ 1265 + 200: Session; 1266 + }; 1267 + 1268 + export type SessionGetResponse = SessionGetResponses[keyof SessionGetResponses]; 1269 + 1270 + export type SessionUpdateData = { 1271 + body?: { 1272 + title?: string; 1273 + }; 1274 + path: { 1275 + id: string; 1276 + }; 1277 + query?: never; 1278 + url: '/session/{id}'; 1279 + }; 1280 + 1281 + export type SessionUpdateResponses = { 1282 + /** 1283 + * Successfully updated session 1284 + */ 1285 + 200: Session; 1286 + }; 1287 + 1288 + export type SessionUpdateResponse = SessionUpdateResponses[keyof SessionUpdateResponses]; 1289 + 1290 + export type SessionChildrenData = { 1291 + body?: never; 1292 + path: { 1293 + id: string; 1294 + }; 1295 + query?: never; 1296 + url: '/session/{id}/children'; 1297 + }; 1298 + 1299 + export type SessionChildrenResponses = { 1300 + /** 1301 + * List of children 1302 + */ 1303 + 200: Array<Session>; 1304 + }; 1305 + 1306 + export type SessionChildrenResponse = SessionChildrenResponses[keyof SessionChildrenResponses]; 1307 + 1308 + export type SessionInitData = { 1309 + body?: { 1310 + messageID: string; 1311 + providerID: string; 1312 + modelID: string; 1313 + }; 1314 + path: { 1315 + /** 1316 + * Session ID 1317 + */ 1318 + id: string; 1319 + }; 1320 + query?: never; 1321 + url: '/session/{id}/init'; 1322 + }; 1323 + 1324 + export type SessionInitResponses = { 1325 + /** 1326 + * 200 1327 + */ 1328 + 200: boolean; 1329 + }; 1330 + 1331 + export type SessionInitResponse = SessionInitResponses[keyof SessionInitResponses]; 1332 + 1333 + export type SessionAbortData = { 1334 + body?: never; 1335 + path: { 1336 + id: string; 1337 + }; 1338 + query?: never; 1339 + url: '/session/{id}/abort'; 1340 + }; 1341 + 1342 + export type SessionAbortResponses = { 1343 + /** 1344 + * Aborted session 1345 + */ 1346 + 200: boolean; 1347 + }; 1348 + 1349 + export type SessionAbortResponse = SessionAbortResponses[keyof SessionAbortResponses]; 1350 + 1351 + export type SessionUnshareData = { 1352 + body?: never; 1353 + path: { 1354 + id: string; 1355 + }; 1356 + query?: never; 1357 + url: '/session/{id}/share'; 1358 + }; 1359 + 1360 + export type SessionUnshareResponses = { 1361 + /** 1362 + * Successfully unshared session 1363 + */ 1364 + 200: Session; 1365 + }; 1366 + 1367 + export type SessionUnshareResponse = SessionUnshareResponses[keyof SessionUnshareResponses]; 1368 + 1369 + export type SessionShareData = { 1370 + body?: never; 1371 + path: { 1372 + id: string; 1373 + }; 1374 + query?: never; 1375 + url: '/session/{id}/share'; 1376 + }; 1377 + 1378 + export type SessionShareResponses = { 1379 + /** 1380 + * Successfully shared session 1381 + */ 1382 + 200: Session; 1383 + }; 1384 + 1385 + export type SessionShareResponse = SessionShareResponses[keyof SessionShareResponses]; 1386 + 1387 + export type SessionSummarizeData = { 1388 + body?: { 1389 + providerID: string; 1390 + modelID: string; 1391 + }; 1392 + path: { 1393 + /** 1394 + * Session ID 1395 + */ 1396 + id: string; 1397 + }; 1398 + query?: never; 1399 + url: '/session/{id}/summarize'; 1400 + }; 1401 + 1402 + export type SessionSummarizeResponses = { 1403 + /** 1404 + * Summarized session 1405 + */ 1406 + 200: boolean; 1407 + }; 1408 + 1409 + export type SessionSummarizeResponse = SessionSummarizeResponses[keyof SessionSummarizeResponses]; 1410 + 1411 + export type SessionMessagesData = { 1412 + body?: never; 1413 + path: { 1414 + /** 1415 + * Session ID 1416 + */ 1417 + id: string; 1418 + }; 1419 + query?: never; 1420 + url: '/session/{id}/message'; 1421 + }; 1422 + 1423 + export type SessionMessagesResponses = { 1424 + /** 1425 + * List of messages 1426 + */ 1427 + 200: Array<{ 1428 + info: Message; 1429 + parts: Array<Part>; 1430 + }>; 1431 + }; 1432 + 1433 + export type SessionMessagesResponse = SessionMessagesResponses[keyof SessionMessagesResponses]; 1434 + 1435 + export type SessionChatData = { 1436 + body?: { 1437 + messageID?: string; 1438 + providerID: string; 1439 + modelID: string; 1440 + agent?: string; 1441 + system?: string; 1442 + tools?: { 1443 + [key: string]: boolean; 1444 + }; 1445 + parts: Array<({ 1446 + type: 'text'; 1447 + } & TextPartInput) | ({ 1448 + type: 'file'; 1449 + } & FilePartInput) | ({ 1450 + type: 'agent'; 1451 + } & AgentPartInput)>; 1452 + }; 1453 + path: { 1454 + /** 1455 + * Session ID 1456 + */ 1457 + id: string; 1458 + }; 1459 + query?: never; 1460 + url: '/session/{id}/message'; 1461 + }; 1462 + 1463 + export type SessionChatResponses = { 1464 + /** 1465 + * Created message 1466 + */ 1467 + 200: { 1468 + info: AssistantMessage; 1469 + parts: Array<Part>; 1470 + }; 1471 + }; 1472 + 1473 + export type SessionChatResponse = SessionChatResponses[keyof SessionChatResponses]; 1474 + 1475 + export type SessionMessageData = { 1476 + body?: never; 1477 + path: { 1478 + /** 1479 + * Session ID 1480 + */ 1481 + id: string; 1482 + /** 1483 + * Message ID 1484 + */ 1485 + messageID: string; 1486 + }; 1487 + query?: never; 1488 + url: '/session/{id}/message/{messageID}'; 1489 + }; 1490 + 1491 + export type SessionMessageResponses = { 1492 + /** 1493 + * Message 1494 + */ 1495 + 200: { 1496 + info: Message; 1497 + parts: Array<Part>; 1498 + }; 1499 + }; 1500 + 1501 + export type SessionMessageResponse = SessionMessageResponses[keyof SessionMessageResponses]; 1502 + 1503 + export type SessionShellData = { 1504 + body?: { 1505 + agent: string; 1506 + command: string; 1507 + }; 1508 + path: { 1509 + /** 1510 + * Session ID 1511 + */ 1512 + id: string; 1513 + }; 1514 + query?: never; 1515 + url: '/session/{id}/shell'; 1516 + }; 1517 + 1518 + export type SessionShellResponses = { 1519 + /** 1520 + * Created message 1521 + */ 1522 + 200: AssistantMessage; 1523 + }; 1524 + 1525 + export type SessionShellResponse = SessionShellResponses[keyof SessionShellResponses]; 1526 + 1527 + export type SessionRevertData = { 1528 + body?: { 1529 + messageID: string; 1530 + partID?: string; 1531 + }; 1532 + path: { 1533 + id: string; 1534 + }; 1535 + query?: never; 1536 + url: '/session/{id}/revert'; 1537 + }; 1538 + 1539 + export type SessionRevertResponses = { 1540 + /** 1541 + * Updated session 1542 + */ 1543 + 200: Session; 1544 + }; 1545 + 1546 + export type SessionRevertResponse = SessionRevertResponses[keyof SessionRevertResponses]; 1547 + 1548 + export type SessionUnrevertData = { 1549 + body?: never; 1550 + path: { 1551 + id: string; 1552 + }; 1553 + query?: never; 1554 + url: '/session/{id}/unrevert'; 1555 + }; 1556 + 1557 + export type SessionUnrevertResponses = { 1558 + /** 1559 + * Updated session 1560 + */ 1561 + 200: Session; 1562 + }; 1563 + 1564 + export type SessionUnrevertResponse = SessionUnrevertResponses[keyof SessionUnrevertResponses]; 1565 + 1566 + export type PostSessionByIdPermissionsByPermissionIdData = { 1567 + body?: { 1568 + response: 'once' | 'always' | 'reject'; 1569 + }; 1570 + path: { 1571 + id: string; 1572 + permissionID: string; 1573 + }; 1574 + query?: never; 1575 + url: '/session/{id}/permissions/{permissionID}'; 1576 + }; 1577 + 1578 + export type PostSessionByIdPermissionsByPermissionIdResponses = { 1579 + /** 1580 + * Permission processed successfully 1581 + */ 1582 + 200: boolean; 1583 + }; 1584 + 1585 + export type PostSessionByIdPermissionsByPermissionIdResponse = PostSessionByIdPermissionsByPermissionIdResponses[keyof PostSessionByIdPermissionsByPermissionIdResponses]; 1586 + 1587 + export type ConfigProvidersData = { 1588 + body?: never; 1589 + path?: never; 1590 + query?: never; 1591 + url: '/config/providers'; 1592 + }; 1593 + 1594 + export type ConfigProvidersResponses = { 1595 + /** 1596 + * List of providers 1597 + */ 1598 + 200: { 1599 + providers: Array<Provider>; 1600 + default: { 1601 + [key: string]: string; 1602 + }; 1603 + }; 1604 + }; 1605 + 1606 + export type ConfigProvidersResponse = ConfigProvidersResponses[keyof ConfigProvidersResponses]; 1607 + 1608 + export type FindTextData = { 1609 + body?: never; 1610 + path?: never; 1611 + query: { 1612 + pattern: string; 1613 + }; 1614 + url: '/find'; 1615 + }; 1616 + 1617 + export type FindTextResponses = { 1618 + /** 1619 + * Matches 1620 + */ 1621 + 200: Array<{ 1622 + path: { 1623 + text: string; 1624 + }; 1625 + lines: { 1626 + text: string; 1627 + }; 1628 + line_number: number; 1629 + absolute_offset: number; 1630 + submatches: Array<{ 1631 + match: { 1632 + text: string; 1633 + }; 1634 + start: number; 1635 + end: number; 1636 + }>; 1637 + }>; 1638 + }; 1639 + 1640 + export type FindTextResponse = FindTextResponses[keyof FindTextResponses]; 1641 + 1642 + export type FindFilesData = { 1643 + body?: never; 1644 + path?: never; 1645 + query: { 1646 + query: string; 1647 + }; 1648 + url: '/find/file'; 1649 + }; 1650 + 1651 + export type FindFilesResponses = { 1652 + /** 1653 + * File paths 1654 + */ 1655 + 200: Array<string>; 1656 + }; 1657 + 1658 + export type FindFilesResponse = FindFilesResponses[keyof FindFilesResponses]; 1659 + 1660 + export type FindSymbolsData = { 1661 + body?: never; 1662 + path?: never; 1663 + query: { 1664 + query: string; 1665 + }; 1666 + url: '/find/symbol'; 1667 + }; 1668 + 1669 + export type FindSymbolsResponses = { 1670 + /** 1671 + * Symbols 1672 + */ 1673 + 200: Array<Symbol>; 1674 + }; 1675 + 1676 + export type FindSymbolsResponse = FindSymbolsResponses[keyof FindSymbolsResponses]; 1677 + 1678 + export type FileReadData = { 1679 + body?: never; 1680 + path?: never; 1681 + query: { 1682 + path: string; 1683 + }; 1684 + url: '/file'; 1685 + }; 1686 + 1687 + export type FileReadResponses = { 1688 + /** 1689 + * File content 1690 + */ 1691 + 200: { 1692 + type: 'raw' | 'patch'; 1693 + content: string; 1694 + }; 1695 + }; 1696 + 1697 + export type FileReadResponse = FileReadResponses[keyof FileReadResponses]; 1698 + 1699 + export type FileStatusData = { 1700 + body?: never; 1701 + path?: never; 1702 + query?: never; 1703 + url: '/file/status'; 1704 + }; 1705 + 1706 + export type FileStatusResponses = { 1707 + /** 1708 + * File status 1709 + */ 1710 + 200: Array<File>; 1711 + }; 1712 + 1713 + export type FileStatusResponse = FileStatusResponses[keyof FileStatusResponses]; 1714 + 1715 + export type AppLogData = { 1716 + body?: { 1717 + /** 1718 + * Service name for the log entry 1719 + */ 1720 + service: string; 1721 + /** 1722 + * Log level 1723 + */ 1724 + level: 'debug' | 'info' | 'error' | 'warn'; 1725 + /** 1726 + * Log message 1727 + */ 1728 + message: string; 1729 + /** 1730 + * Additional metadata for the log entry 1731 + */ 1732 + extra?: { 1733 + [key: string]: unknown; 1734 + }; 1735 + }; 1736 + path?: never; 1737 + query?: never; 1738 + url: '/log'; 1739 + }; 1740 + 1741 + export type AppLogResponses = { 1742 + /** 1743 + * Log entry written successfully 1744 + */ 1745 + 200: boolean; 1746 + }; 1747 + 1748 + export type AppLogResponse = AppLogResponses[keyof AppLogResponses]; 1749 + 1750 + export type AppAgentsData = { 1751 + body?: never; 1752 + path?: never; 1753 + query?: never; 1754 + url: '/agent'; 1755 + }; 1756 + 1757 + export type AppAgentsResponses = { 1758 + /** 1759 + * List of agents 1760 + */ 1761 + 200: Array<Agent>; 1762 + }; 1763 + 1764 + export type AppAgentsResponse = AppAgentsResponses[keyof AppAgentsResponses]; 1765 + 1766 + export type TuiAppendPromptData = { 1767 + body?: { 1768 + text: string; 1769 + }; 1770 + path?: never; 1771 + query?: never; 1772 + url: '/tui/append-prompt'; 1773 + }; 1774 + 1775 + export type TuiAppendPromptResponses = { 1776 + /** 1777 + * Prompt processed successfully 1778 + */ 1779 + 200: boolean; 1780 + }; 1781 + 1782 + export type TuiAppendPromptResponse = TuiAppendPromptResponses[keyof TuiAppendPromptResponses]; 1783 + 1784 + export type TuiOpenHelpData = { 1785 + body?: never; 1786 + path?: never; 1787 + query?: never; 1788 + url: '/tui/open-help'; 1789 + }; 1790 + 1791 + export type TuiOpenHelpResponses = { 1792 + /** 1793 + * Help dialog opened successfully 1794 + */ 1795 + 200: boolean; 1796 + }; 1797 + 1798 + export type TuiOpenHelpResponse = TuiOpenHelpResponses[keyof TuiOpenHelpResponses]; 1799 + 1800 + export type TuiOpenSessionsData = { 1801 + body?: never; 1802 + path?: never; 1803 + query?: never; 1804 + url: '/tui/open-sessions'; 1805 + }; 1806 + 1807 + export type TuiOpenSessionsResponses = { 1808 + /** 1809 + * Session dialog opened successfully 1810 + */ 1811 + 200: boolean; 1812 + }; 1813 + 1814 + export type TuiOpenSessionsResponse = TuiOpenSessionsResponses[keyof TuiOpenSessionsResponses]; 1815 + 1816 + export type TuiOpenThemesData = { 1817 + body?: never; 1818 + path?: never; 1819 + query?: never; 1820 + url: '/tui/open-themes'; 1821 + }; 1822 + 1823 + export type TuiOpenThemesResponses = { 1824 + /** 1825 + * Theme dialog opened successfully 1826 + */ 1827 + 200: boolean; 1828 + }; 1829 + 1830 + export type TuiOpenThemesResponse = TuiOpenThemesResponses[keyof TuiOpenThemesResponses]; 1831 + 1832 + export type TuiOpenModelsData = { 1833 + body?: never; 1834 + path?: never; 1835 + query?: never; 1836 + url: '/tui/open-models'; 1837 + }; 1838 + 1839 + export type TuiOpenModelsResponses = { 1840 + /** 1841 + * Model dialog opened successfully 1842 + */ 1843 + 200: boolean; 1844 + }; 1845 + 1846 + export type TuiOpenModelsResponse = TuiOpenModelsResponses[keyof TuiOpenModelsResponses]; 1847 + 1848 + export type TuiSubmitPromptData = { 1849 + body?: never; 1850 + path?: never; 1851 + query?: never; 1852 + url: '/tui/submit-prompt'; 1853 + }; 1854 + 1855 + export type TuiSubmitPromptResponses = { 1856 + /** 1857 + * Prompt submitted successfully 1858 + */ 1859 + 200: boolean; 1860 + }; 1861 + 1862 + export type TuiSubmitPromptResponse = TuiSubmitPromptResponses[keyof TuiSubmitPromptResponses]; 1863 + 1864 + export type TuiClearPromptData = { 1865 + body?: never; 1866 + path?: never; 1867 + query?: never; 1868 + url: '/tui/clear-prompt'; 1869 + }; 1870 + 1871 + export type TuiClearPromptResponses = { 1872 + /** 1873 + * Prompt cleared successfully 1874 + */ 1875 + 200: boolean; 1876 + }; 1877 + 1878 + export type TuiClearPromptResponse = TuiClearPromptResponses[keyof TuiClearPromptResponses]; 1879 + 1880 + export type TuiExecuteCommandData = { 1881 + body?: { 1882 + command: string; 1883 + }; 1884 + path?: never; 1885 + query?: never; 1886 + url: '/tui/execute-command'; 1887 + }; 1888 + 1889 + export type TuiExecuteCommandResponses = { 1890 + /** 1891 + * Command executed successfully 1892 + */ 1893 + 200: boolean; 1894 + }; 1895 + 1896 + export type TuiExecuteCommandResponse = TuiExecuteCommandResponses[keyof TuiExecuteCommandResponses]; 1897 + 1898 + export type TuiShowToastData = { 1899 + body?: { 1900 + title?: string; 1901 + message: string; 1902 + variant: 'info' | 'success' | 'warning' | 'error'; 1903 + }; 1904 + path?: never; 1905 + query?: never; 1906 + url: '/tui/show-toast'; 1907 + }; 1908 + 1909 + export type TuiShowToastResponses = { 1910 + /** 1911 + * Toast notification shown successfully 1912 + */ 1913 + 200: boolean; 1914 + }; 1915 + 1916 + export type TuiShowToastResponse = TuiShowToastResponses[keyof TuiShowToastResponses]; 1917 + 1918 + export type AuthSetData = { 1919 + body?: Auth; 1920 + path: { 1921 + id: string; 1922 + }; 1923 + query?: never; 1924 + url: '/auth/{id}'; 1925 + }; 1926 + 1927 + export type AuthSetErrors = { 1928 + /** 1929 + * Bad request 1930 + */ 1931 + 400: Error; 1932 + }; 1933 + 1934 + export type AuthSetError = AuthSetErrors[keyof AuthSetErrors]; 1935 + 1936 + export type AuthSetResponses = { 1937 + /** 1938 + * Successfully set authentication credentials 1939 + */ 1940 + 200: boolean; 1941 + }; 1942 + 1943 + export type AuthSetResponse = AuthSetResponses[keyof AuthSetResponses];
+16
packages/openapi-ts-tests/sdks/test/opencode.test.ts
··· 27 27 { 28 28 config: createConfig({ 29 29 input: specPath, 30 + output: { 31 + path: 'export-all', 32 + preferExportAll: true, 33 + }, 34 + plugins: [ 35 + { 36 + name: '@hey-api/sdk', 37 + paramsStructure: 'flat', 38 + }, 39 + ], 40 + }), 41 + description: 'export all', 42 + }, 43 + { 44 + config: createConfig({ 45 + input: specPath, 30 46 output: 'flat', 31 47 plugins: [ 32 48 {
+29 -33
packages/openapi-ts/src/parser/types/hooks.d.ts
··· 1 - import type { Symbol, SymbolIn } from '@hey-api/codegen-core'; 1 + import type { Node, Symbol, SymbolIn } from '@hey-api/codegen-core'; 2 2 3 3 import type { IROperationObject } from '~/ir/types'; 4 4 import type { PluginInstance } from '~/plugins/shared/utils/instance'; ··· 8 8 * Event hooks. 9 9 */ 10 10 events?: { 11 + /** 12 + * Triggered after adding or updating a node. 13 + * 14 + * You can use this to perform actions after a node is added or updated. 15 + * 16 + * @param args Arguments object. 17 + * @returns void 18 + */ 19 + 'node:set:after'?: (args: { 20 + /** The node added or updated. */ 21 + node: Node | null; 22 + /** Plugin that added or updated the node. */ 23 + plugin: PluginInstance; 24 + }) => void; 25 + /** 26 + * Triggered before adding or updating a node. 27 + * 28 + * You can use this to modify the node before it's added or updated. 29 + * 30 + * @param args Arguments object. 31 + * @returns void 32 + */ 33 + 'node:set:before'?: (args: { 34 + /** The node to be added or updated. */ 35 + node: Node | null; 36 + /** Plugin adding or updating the node. */ 37 + plugin: PluginInstance; 38 + }) => void; 11 39 /** 12 40 * Triggered after executing a plugin handler. 13 41 * ··· 55 83 plugin: PluginInstance; 56 84 /** Symbol to register. */ 57 85 symbol: SymbolIn; 58 - }) => void; 59 - /** 60 - * Triggered after setting a symbol value. 61 - * 62 - * You can use this to perform actions after a symbol's value is set. 63 - * 64 - * @param args Arguments object. 65 - * @returns void 66 - */ 67 - 'symbol:setValue:after'?: (args: { 68 - /** Plugin that set the symbol value. */ 69 - plugin: PluginInstance; 70 - /** The symbol. */ 71 - symbol: Symbol; 72 - /** The value that was set. */ 73 - value: unknown; 74 - }) => void; 75 - /** 76 - * Triggered before setting a symbol value. 77 - * 78 - * You can use this to modify the value before it's set. 79 - * 80 - * @param args Arguments object. 81 - * @returns void 82 - */ 83 - 'symbol:setValue:before'?: (args: { 84 - /** Plugin setting the symbol value. */ 85 - plugin: PluginInstance; 86 - /** The symbol. */ 87 - symbol: Symbol; 88 - /** The value to set. */ 89 - value: unknown; 90 86 }) => void; 91 87 }; 92 88 /**
+18 -7
packages/openapi-ts/src/plugins/shared/utils/instance.ts
··· 107 107 } 108 108 109 109 addNode(node: Node | null): number { 110 - return this.gen.nodes.add(node); 111 - } 112 - removeNode(index: number): void { 113 - return this.gen.nodes.remove(index); 110 + for (const hook of this.eventHooks['node:set:before']) { 111 + hook({ node, plugin: this }); 112 + } 113 + const index = this.gen.nodes.add(node); 114 + for (const hook of this.eventHooks['node:set:after']) { 115 + hook({ node, plugin: this }); 116 + } 117 + return index; 114 118 } 115 119 updateNode(index: number, node: Node | null): void { 116 - return this.gen.nodes.update(index, node); 120 + for (const hook of this.eventHooks['node:set:before']) { 121 + hook({ node, plugin: this }); 122 + } 123 + const result = this.gen.nodes.update(index, node); 124 + for (const hook of this.eventHooks['node:set:after']) { 125 + hook({ node, plugin: this }); 126 + } 127 + return result; 117 128 } 118 129 119 130 /** ··· 366 377 367 378 private buildEventHooks(): EventHooks { 368 379 const result: EventHooks = { 380 + 'node:set:after': [], 381 + 'node:set:before': [], 369 382 'plugin:handler:after': [], 370 383 'plugin:handler:before': [], 371 384 'symbol:register:after': [], 372 385 'symbol:register:before': [], 373 - 'symbol:setValue:after': [], 374 - 'symbol:setValue:before': [], 375 386 }; 376 387 const scopes = [ 377 388 this.config['~hooks']?.events,