Skip to content

Commit c1e9720

Browse files
committed
chore: update FE dependencies
1 parent ce1736a commit c1e9720

File tree

8 files changed

+69
-66
lines changed

8 files changed

+69
-66
lines changed
Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
import { defineConfig, defaultPlugins } from '@hey-api/openapi-ts';
1+
import {defineConfig, defaultPlugins} from '@hey-api/openapi-ts';
22

33
export default defineConfig({
4-
input:
5-
'http://localhost:54813/umbraco/swagger/default/swagger.json',
6-
plugins: [
7-
...defaultPlugins,
8-
'legacy/fetch',
9-
'@hey-api/schemas',
10-
{
11-
dates: true,
12-
name: '@hey-api/transformers',
13-
},
14-
{
15-
enums: 'javascript',
16-
name: '@hey-api/typescript',
17-
},
18-
{
19-
name: '@hey-api/sdk',
20-
transformer: true,
21-
},
22-
],
23-
output: {
24-
format: 'prettier',
25-
path: './src/api',
26-
}
4+
input: 'http://localhost:54813/umbraco/swagger/default/swagger.json',
5+
plugins: [
6+
...defaultPlugins,
7+
'legacy/fetch',
8+
'@hey-api/schemas',
9+
{
10+
dates: true,
11+
name: '@hey-api/transformers',
12+
},
13+
{
14+
enums: 'javascript',
15+
name: '@hey-api/typescript',
16+
},
17+
{
18+
name: '@hey-api/sdk',
19+
transformer: true,
20+
},
21+
],
22+
output: {
23+
format: 'prettier',
24+
path: './src/api',
25+
}
2726
});
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
export type ApiRequestOptions = {
2-
readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
3-
readonly url: string;
4-
readonly path?: Record<string, unknown>;
1+
export type ApiRequestOptions<T = unknown> = {
2+
readonly body?: any;
53
readonly cookies?: Record<string, unknown>;
4+
readonly errors?: Record<number | string, string>;
5+
readonly formData?: Record<string, unknown> | any[] | Blob | File;
66
readonly headers?: Record<string, unknown>;
7-
readonly query?: Record<string, unknown>;
8-
readonly formData?: Record<string, unknown>;
9-
readonly body?: any;
107
readonly mediaType?: string;
8+
readonly method:
9+
| 'DELETE'
10+
| 'GET'
11+
| 'HEAD'
12+
| 'OPTIONS'
13+
| 'PATCH'
14+
| 'POST'
15+
| 'PUT';
16+
readonly path?: Record<string, unknown>;
17+
readonly query?: Record<string, unknown>;
1118
readonly responseHeader?: string;
12-
readonly errors?: Record<number | string, string>;
19+
readonly responseTransformer?: (data: unknown) => Promise<T>;
20+
readonly url: string;
1321
};

src/jcdcdev.Umbraco.ReadingTime.Client/src/api/core/OpenAPI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ApiRequestOptions } from './ApiRequestOptions';
22

33
type Headers = Record<string, string>;
44
type Middleware<T> = (value: T) => T | Promise<T>;
5-
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
5+
type Resolver<T> = (options: ApiRequestOptions<T>) => Promise<T>;
66

77
export class Interceptors<T> {
88
_fns: Middleware<T>[];

src/jcdcdev.Umbraco.ReadingTime.Client/src/api/core/request.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,24 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
101101
return undefined;
102102
};
103103

104-
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
104+
type Resolver<T> = (options: ApiRequestOptions<T>) => Promise<T>;
105105

106-
export const resolve = async <T>(options: ApiRequestOptions, resolver?: T | Resolver<T>): Promise<T | undefined> => {
106+
export const resolve = async <T>(options: ApiRequestOptions<T>, resolver?: T | Resolver<T>): Promise<T | undefined> => {
107107
if (typeof resolver === 'function') {
108108
return (resolver as Resolver<T>)(options);
109109
}
110110
return resolver;
111111
};
112112

113-
export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise<Headers> => {
113+
export const getHeaders = async <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): Promise<Headers> => {
114114
const [token, username, password, additionalHeaders] = await Promise.all([
115+
// @ts-ignore
115116
resolve(options, config.TOKEN),
117+
// @ts-ignore
116118
resolve(options, config.USERNAME),
119+
// @ts-ignore
117120
resolve(options, config.PASSWORD),
121+
// @ts-ignore
118122
resolve(options, config.HEADERS),
119123
]);
120124

@@ -304,7 +308,7 @@ export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult):
304308
* @returns CancelablePromise<T>
305309
* @throws ApiError
306310
*/
307-
export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise<T> => {
311+
export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): CancelablePromise<T> => {
308312
return new CancelablePromise(async (resolve, reject, onCancel) => {
309313
try {
310314
const url = getUrl(config, options);
@@ -322,12 +326,17 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
322326
const responseBody = await getResponseBody(response);
323327
const responseHeader = getResponseHeader(response, options.responseHeader);
324328

329+
let transformedBody = responseBody;
330+
if (options.responseTransformer && response.ok) {
331+
transformedBody = await options.responseTransformer(responseBody)
332+
}
333+
325334
const result: ApiResult = {
326335
url,
327336
ok: response.ok,
328337
status: response.status,
329338
statusText: response.statusText,
330-
body: responseHeader ?? responseBody,
339+
body: responseHeader ?? transformedBody,
331340
};
332341

333342
catchErrorCodes(options, result);

src/jcdcdev.Umbraco.ReadingTime.Client/src/api/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
export { ApiError } from './core/ApiError';
33
export { CancelablePromise, CancelError } from './core/CancelablePromise';
44
export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI';
5-
export * from './schemas.gen';
6-
export * from './services.gen';
5+
export * from './sdk.gen';
76
export * from './types.gen';

src/jcdcdev.Umbraco.ReadingTime.Client/src/api/schemas.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3-
export const $ReadingTimeResponse = {
3+
export const ReadingTimeResponseSchema = {
44
required: ['readingTime', 'updateDate'],
55
type: 'object',
66
properties: {

src/jcdcdev.Umbraco.ReadingTime.Client/src/api/services.gen.ts renamed to src/jcdcdev.Umbraco.ReadingTime.Client/src/api/sdk.gen.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ import type { GetUmbracoReadingtimeApiData, GetUmbracoReadingtimeApiResponse } f
1313
* @returns unknown OK
1414
* @throws ApiError
1515
*/
16-
export const getUmbracoReadingtimeApi = (data: GetUmbracoReadingtimeApiData = {}): CancelablePromise<GetUmbracoReadingtimeApiResponse> => { return __request(OpenAPI, {
17-
method: 'GET',
18-
url: '/umbraco/readingtime/api',
19-
query: {
20-
contentKey: data.contentKey,
21-
dataTypeKey: data.dataTypeKey,
22-
culture: data.culture
23-
}
24-
}); };
16+
export const getUmbracoReadingtimeApi = (data: GetUmbracoReadingtimeApiData = {}): CancelablePromise<GetUmbracoReadingtimeApiResponse> => {
17+
return __request(OpenAPI, {
18+
method: 'GET',
19+
url: '/umbraco/readingtime/api',
20+
query: {
21+
contentKey: data.contentKey,
22+
dataTypeKey: data.dataTypeKey,
23+
culture: data.culture
24+
}
25+
});
26+
};
Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

33
export type ReadingTimeResponse = {
4-
updateDate: string;
4+
updateDate: Date;
55
readingTime: string;
66
};
77

@@ -11,18 +11,4 @@ export type GetUmbracoReadingtimeApiData = {
1111
dataTypeKey?: string;
1212
};
1313

14-
export type GetUmbracoReadingtimeApiResponse = ReadingTimeResponse;
15-
16-
export type $OpenApiTs = {
17-
'/umbraco/readingtime/api': {
18-
get: {
19-
req: GetUmbracoReadingtimeApiData;
20-
res: {
21-
/**
22-
* OK
23-
*/
24-
200: ReadingTimeResponse;
25-
};
26-
};
27-
};
28-
};
14+
export type GetUmbracoReadingtimeApiResponse = ((ReadingTimeResponse));

0 commit comments

Comments
 (0)