Skip to content

Commit ed38d93

Browse files
committed
fix: dont throw on missing performance marks
1 parent 9eccf4b commit ed38d93

File tree

9 files changed

+530
-233
lines changed

9 files changed

+530
-233
lines changed

.changeset/chilled-tips-lie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
fix: don't throw on missing performance marks

packages/openapi-ts/bin/index.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ async function start() {
117117
userConfig.watch = Number.parseInt(params.watch, 10);
118118
}
119119

120+
if (!Object.keys(userConfig.logs).length) {
121+
delete userConfig.logs;
122+
}
123+
120124
const context = await createClient(userConfig);
121125
if (!context[0] || !context[0].config.watch) {
122126
process.exit(0);

packages/openapi-ts/src/utils/performance.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@ export class PerformanceReport {
3232
);
3333

3434
marks.forEach((mark) => {
35-
const markMeasure = Performance.measure(mark);
36-
const markDuration = Math.ceil(markMeasure.duration * 100) / 100;
37-
const percentage =
38-
Math.ceil(
39-
(markMeasure.duration / this.totalMeasure.duration) * 100 * 100,
40-
) / 100;
41-
console.warn(
42-
`${mark}: ${markDuration.toFixed(2)}ms (${percentage.toFixed(2)}%)`,
43-
);
35+
try {
36+
const markMeasure = Performance.measure(mark);
37+
const markDuration = Math.ceil(markMeasure.duration * 100) / 100;
38+
const percentage =
39+
Math.ceil(
40+
(markMeasure.duration / this.totalMeasure.duration) * 100 * 100,
41+
) / 100;
42+
console.warn(
43+
`${mark}: ${markDuration.toFixed(2)}ms (${percentage.toFixed(2)}%)`,
44+
);
45+
} catch {
46+
// noop
47+
}
4448
});
4549
}
4650
}

packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.cjs

Lines changed: 499 additions & 1 deletion
Large diffs are not rendered by default.

packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.cts

Lines changed: 3 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,5 @@
1-
type AuthToken = string | undefined;
2-
interface Auth {
3-
/**
4-
* Which part of the request do we use to send the auth?
5-
*
6-
* @default 'header'
7-
*/
8-
in?: 'header' | 'query';
9-
/**
10-
* Header or query parameter name.
11-
*
12-
* @default 'Authorization'
13-
*/
14-
name?: string;
15-
scheme?: 'basic' | 'bearer';
16-
type: 'apiKey' | 'http';
17-
}
18-
interface SerializerOptions<T> {
19-
/**
20-
* @default true
21-
*/
22-
explode: boolean;
23-
style: T;
24-
}
25-
type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
26-
type ObjectStyle = 'form' | 'deepObject';
27-
28-
type QuerySerializer = (query: Record<string, unknown>) => string;
29-
type BodySerializer = (body: any) => any;
30-
interface QuerySerializerOptions {
31-
allowReserved?: boolean;
32-
array?: SerializerOptions<ArrayStyle>;
33-
object?: SerializerOptions<ObjectStyle>;
34-
}
35-
declare const formDataBodySerializer: {
36-
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => FormData;
37-
};
38-
declare const jsonBodySerializer: {
39-
bodySerializer: <T>(body: T) => string;
40-
};
41-
declare const urlSearchParamsBodySerializer: {
42-
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => string;
43-
};
44-
45-
interface Client$1<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never> {
46-
/**
47-
* Returns the final request URL.
48-
*/
49-
buildUrl: BuildUrlFn;
50-
connect: MethodFn;
51-
delete: MethodFn;
52-
get: MethodFn;
53-
getConfig: () => Config;
54-
head: MethodFn;
55-
options: MethodFn;
56-
patch: MethodFn;
57-
post: MethodFn;
58-
put: MethodFn;
59-
request: RequestFn;
60-
setConfig: (config: Config) => Config;
61-
trace: MethodFn;
62-
}
63-
interface Config$1 {
64-
/**
65-
* Auth token or a function returning auth token. The resolved value will be
66-
* added to the request payload as defined by its `security` array.
67-
*/
68-
auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
69-
/**
70-
* A function for serializing request body parameter. By default,
71-
* {@link JSON.stringify()} will be used.
72-
*/
73-
bodySerializer?: BodySerializer | null;
74-
/**
75-
* An object containing any HTTP headers that you want to pre-populate your
76-
* `Headers` object with.
77-
*
78-
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
79-
*/
80-
headers?: RequestInit['headers'] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
81-
/**
82-
* The request method.
83-
*
84-
* {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
85-
*/
86-
method?: 'CONNECT' | 'DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'PUT' | 'TRACE';
87-
/**
88-
* A function for serializing request query parameters. By default, arrays
89-
* will be exploded in form style, objects will be exploded in deepObject
90-
* style, and reserved characters are percent-encoded.
91-
*
92-
* This method will have no effect if the native `paramsSerializer()` Axios
93-
* API function is used.
94-
*
95-
* {@link https://swagger.io/docs/specification/serialization/#query View examples}
96-
*/
97-
querySerializer?: QuerySerializer | QuerySerializerOptions;
98-
/**
99-
* A function transforming response data before it's returned. This is useful
100-
* for post-processing data, e.g. converting ISO strings into Date objects.
101-
*/
102-
responseTransformer?: (data: unknown) => Promise<unknown>;
103-
/**
104-
* A function validating response data. This is useful if you want to ensure
105-
* the response conforms to the desired shape, so it can be safely passed to
106-
* the transformers and returned to the user.
107-
*/
108-
responseValidator?: (data: unknown) => Promise<unknown>;
109-
}
1+
import { Config as Config$1, Auth, Client as Client$1 } from '@hey-api/client-core';
2+
export { Auth, QuerySerializerOptions, formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer } from '@hey-api/client-core';
1103

1114
type ErrInterceptor<Err, Res, Req, Options> = (error: Err, response: Res, request: Req, options: Options) => Err | Promise<Err>;
1125
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
@@ -228,4 +121,4 @@ type OptionsLegacyParser<TData = unknown, ThrowOnError extends boolean = boolean
228121

229122
declare const createClient: (config?: Config) => Client;
230123

231-
export { type Auth, type Client, type ClientOptions, type Config, type CreateClientConfig, type Options, type OptionsLegacyParser, type QuerySerializerOptions, type RequestOptions, type RequestResult, type TDataShape, createClient, createConfig, formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer };
124+
export { type Client, type ClientOptions, type Config, type CreateClientConfig, type Options, type OptionsLegacyParser, type RequestOptions, type RequestResult, type TDataShape, createClient, createConfig };

packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.ts

Lines changed: 3 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,5 @@
1-
type AuthToken = string | undefined;
2-
interface Auth {
3-
/**
4-
* Which part of the request do we use to send the auth?
5-
*
6-
* @default 'header'
7-
*/
8-
in?: 'header' | 'query';
9-
/**
10-
* Header or query parameter name.
11-
*
12-
* @default 'Authorization'
13-
*/
14-
name?: string;
15-
scheme?: 'basic' | 'bearer';
16-
type: 'apiKey' | 'http';
17-
}
18-
interface SerializerOptions<T> {
19-
/**
20-
* @default true
21-
*/
22-
explode: boolean;
23-
style: T;
24-
}
25-
type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
26-
type ObjectStyle = 'form' | 'deepObject';
27-
28-
type QuerySerializer = (query: Record<string, unknown>) => string;
29-
type BodySerializer = (body: any) => any;
30-
interface QuerySerializerOptions {
31-
allowReserved?: boolean;
32-
array?: SerializerOptions<ArrayStyle>;
33-
object?: SerializerOptions<ObjectStyle>;
34-
}
35-
declare const formDataBodySerializer: {
36-
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => FormData;
37-
};
38-
declare const jsonBodySerializer: {
39-
bodySerializer: <T>(body: T) => string;
40-
};
41-
declare const urlSearchParamsBodySerializer: {
42-
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => string;
43-
};
44-
45-
interface Client$1<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never> {
46-
/**
47-
* Returns the final request URL.
48-
*/
49-
buildUrl: BuildUrlFn;
50-
connect: MethodFn;
51-
delete: MethodFn;
52-
get: MethodFn;
53-
getConfig: () => Config;
54-
head: MethodFn;
55-
options: MethodFn;
56-
patch: MethodFn;
57-
post: MethodFn;
58-
put: MethodFn;
59-
request: RequestFn;
60-
setConfig: (config: Config) => Config;
61-
trace: MethodFn;
62-
}
63-
interface Config$1 {
64-
/**
65-
* Auth token or a function returning auth token. The resolved value will be
66-
* added to the request payload as defined by its `security` array.
67-
*/
68-
auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
69-
/**
70-
* A function for serializing request body parameter. By default,
71-
* {@link JSON.stringify()} will be used.
72-
*/
73-
bodySerializer?: BodySerializer | null;
74-
/**
75-
* An object containing any HTTP headers that you want to pre-populate your
76-
* `Headers` object with.
77-
*
78-
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
79-
*/
80-
headers?: RequestInit['headers'] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
81-
/**
82-
* The request method.
83-
*
84-
* {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
85-
*/
86-
method?: 'CONNECT' | 'DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'PUT' | 'TRACE';
87-
/**
88-
* A function for serializing request query parameters. By default, arrays
89-
* will be exploded in form style, objects will be exploded in deepObject
90-
* style, and reserved characters are percent-encoded.
91-
*
92-
* This method will have no effect if the native `paramsSerializer()` Axios
93-
* API function is used.
94-
*
95-
* {@link https://swagger.io/docs/specification/serialization/#query View examples}
96-
*/
97-
querySerializer?: QuerySerializer | QuerySerializerOptions;
98-
/**
99-
* A function transforming response data before it's returned. This is useful
100-
* for post-processing data, e.g. converting ISO strings into Date objects.
101-
*/
102-
responseTransformer?: (data: unknown) => Promise<unknown>;
103-
/**
104-
* A function validating response data. This is useful if you want to ensure
105-
* the response conforms to the desired shape, so it can be safely passed to
106-
* the transformers and returned to the user.
107-
*/
108-
responseValidator?: (data: unknown) => Promise<unknown>;
109-
}
1+
import { Config as Config$1, Auth, Client as Client$1 } from '@hey-api/client-core';
2+
export { Auth, QuerySerializerOptions, formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer } from '@hey-api/client-core';
1103

1114
type ErrInterceptor<Err, Res, Req, Options> = (error: Err, response: Res, request: Req, options: Options) => Err | Promise<Err>;
1125
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
@@ -228,4 +121,4 @@ type OptionsLegacyParser<TData = unknown, ThrowOnError extends boolean = boolean
228121

229122
declare const createClient: (config?: Config) => Client;
230123

231-
export { type Auth, type Client, type ClientOptions, type Config, type CreateClientConfig, type Options, type OptionsLegacyParser, type QuerySerializerOptions, type RequestOptions, type RequestResult, type TDataShape, createClient, createConfig, formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer };
124+
export { type Client, type ClientOptions, type Config, type CreateClientConfig, type Options, type OptionsLegacyParser, type RequestOptions, type RequestResult, type TDataShape, createClient, createConfig };

0 commit comments

Comments
 (0)