Skip to content

Commit

Permalink
refactor(ui): Regenerate query client
Browse files Browse the repository at this point in the history
OpenAPI query client library update to v1 (PR eclipse-apoapsis#157) introduced major
changes to the structure and functionality of the query client.
Moreover, PR eclipse-apoapsis#181 introduced a fix to OpenAPI generation of nullable
values, which brought major changes to the Swagger JSON.

This commit regenerates the query client from scratch to adapt to these
changes. The command used for regenerating is:

    pnpm codegen

Signed-off-by: Jyrki Keisala <[email protected]>
  • Loading branch information
Etsija committed May 16, 2024
1 parent 523cacc commit 74cdc43
Show file tree
Hide file tree
Showing 47 changed files with 8,276 additions and 3,955 deletions.
169 changes: 169 additions & 0 deletions ui/src/api/queries/common.ts

Large diffs are not rendered by default.

1,719 changes: 4 additions & 1,715 deletions ui/src/api/queries/index.ts

Large diffs are not rendered by default.

253 changes: 253 additions & 0 deletions ui/src/api/queries/prefetch.ts

Large diffs are not rendered by default.

572 changes: 572 additions & 0 deletions ui/src/api/queries/queries.ts

Large diffs are not rendered by default.

253 changes: 253 additions & 0 deletions ui/src/api/queries/suspense.ts

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions ui/src/api/requests/core/ApiError.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { ApiRequestOptions } from './ApiRequestOptions';
import type { ApiResult } from './ApiResult';

export class ApiError extends Error {
public readonly url: string;
public readonly status: number;
public readonly statusText: string;
public readonly body: any;
public readonly body: unknown;
public readonly request: ApiRequestOptions;

constructor(
Expand Down
13 changes: 5 additions & 8 deletions ui/src/api/requests/core/ApiRequestOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type ApiRequestOptions = {
readonly method:
| 'GET'
Expand All @@ -11,11 +8,11 @@ export type ApiRequestOptions = {
| 'HEAD'
| 'PATCH';
readonly url: string;
readonly path?: Record<string, any>;
readonly cookies?: Record<string, any>;
readonly headers?: Record<string, any>;
readonly query?: Record<string, any>;
readonly formData?: Record<string, any>;
readonly path?: Record<string, unknown>;
readonly cookies?: Record<string, unknown>;
readonly headers?: Record<string, unknown>;
readonly query?: Record<string, unknown>;
readonly formData?: Record<string, unknown>;
readonly body?: any;
readonly mediaType?: string;
readonly responseHeader?: string;
Expand Down
9 changes: 3 additions & 6 deletions ui/src/api/requests/core/ApiResult.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type ApiResult = {
readonly url: string;
export type ApiResult<TData = any> = {
readonly body: TData;
readonly ok: boolean;
readonly status: number;
readonly statusText: string;
readonly body: any;
readonly url: string;
};
81 changes: 39 additions & 42 deletions ui/src/api/requests/core/CancelablePromise.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export class CancelError extends Error {
constructor(message: string) {
super(message);
Expand All @@ -21,62 +18,62 @@ export interface OnCancel {
}

export class CancelablePromise<T> implements Promise<T> {
#isResolved: boolean;
#isRejected: boolean;
#isCancelled: boolean;
readonly #cancelHandlers: (() => void)[];
readonly #promise: Promise<T>;
#resolve?: (value: T | PromiseLike<T>) => void;
#reject?: (reason?: any) => void;
private _isResolved: boolean;
private _isRejected: boolean;
private _isCancelled: boolean;
readonly cancelHandlers: (() => void)[];
readonly promise: Promise<T>;
private _resolve?: (value: T | PromiseLike<T>) => void;
private _reject?: (reason?: unknown) => void;

constructor(
executor: (
resolve: (value: T | PromiseLike<T>) => void,
reject: (reason?: any) => void,
reject: (reason?: unknown) => void,
onCancel: OnCancel
) => void
) {
this.#isResolved = false;
this.#isRejected = false;
this.#isCancelled = false;
this.#cancelHandlers = [];
this.#promise = new Promise<T>((resolve, reject) => {
this.#resolve = resolve;
this.#reject = reject;
this._isResolved = false;
this._isRejected = false;
this._isCancelled = false;
this.cancelHandlers = [];
this.promise = new Promise<T>((resolve, reject) => {
this._resolve = resolve;
this._reject = reject;

const onResolve = (value: T | PromiseLike<T>): void => {
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
if (this._isResolved || this._isRejected || this._isCancelled) {
return;
}
this.#isResolved = true;
this.#resolve?.(value);
this._isResolved = true;
if (this._resolve) this._resolve(value);
};

const onReject = (reason?: any): void => {
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
const onReject = (reason?: unknown): void => {
if (this._isResolved || this._isRejected || this._isCancelled) {
return;
}
this.#isRejected = true;
this.#reject?.(reason);
this._isRejected = true;
if (this._reject) this._reject(reason);
};

const onCancel = (cancelHandler: () => void): void => {
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
if (this._isResolved || this._isRejected || this._isCancelled) {
return;
}
this.#cancelHandlers.push(cancelHandler);
this.cancelHandlers.push(cancelHandler);
};

Object.defineProperty(onCancel, 'isResolved', {
get: (): boolean => this.#isResolved,
get: (): boolean => this._isResolved,
});

Object.defineProperty(onCancel, 'isRejected', {
get: (): boolean => this.#isRejected,
get: (): boolean => this._isRejected,
});

Object.defineProperty(onCancel, 'isCancelled', {
get: (): boolean => this.#isCancelled,
get: (): boolean => this._isCancelled,
});

return executor(onResolve, onReject, onCancel as OnCancel);
Expand All @@ -89,41 +86,41 @@ export class CancelablePromise<T> implements Promise<T> {

public then<TResult1 = T, TResult2 = never>(
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null
): Promise<TResult1 | TResult2> {
return this.#promise.then(onFulfilled, onRejected);
return this.promise.then(onFulfilled, onRejected);
}

public catch<TResult = never>(
onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null
onRejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null
): Promise<T | TResult> {
return this.#promise.catch(onRejected);
return this.promise.catch(onRejected);
}

public finally(onFinally?: (() => void) | null): Promise<T> {
return this.#promise.finally(onFinally);
return this.promise.finally(onFinally);
}

public cancel(): void {
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
if (this._isResolved || this._isRejected || this._isCancelled) {
return;
}
this.#isCancelled = true;
if (this.#cancelHandlers.length) {
this._isCancelled = true;
if (this.cancelHandlers.length) {
try {
for (const cancelHandler of this.#cancelHandlers) {
for (const cancelHandler of this.cancelHandlers) {
cancelHandler();
}
} catch (error) {
console.warn('Cancellation threw an error', error);
return;
}
}
this.#cancelHandlers.length = 0;
this.#reject?.(new CancelError('Request aborted'));
this.cancelHandlers.length = 0;
if (this._reject) this._reject(new CancelError('Request aborted'));
}

public get isCancelled(): boolean {
return this.#isCancelled;
return this._isCancelled;
}
}
55 changes: 40 additions & 15 deletions ui/src/api/requests/core/OpenAPI.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,56 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { ApiRequestOptions } from './ApiRequestOptions';

type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
type Headers = Record<string, string>;
type Middleware<T> = (value: T) => T | Promise<T>;
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;

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

constructor() {
this._fns = [];
}

eject(fn: Middleware<T>) {
const index = this._fns.indexOf(fn);
if (index !== -1) {
this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)];
}
}

use(fn: Middleware<T>) {
this._fns = [...this._fns, fn];
}
}

export type OpenAPIConfig = {
BASE: string;
CREDENTIALS: 'include' | 'omit' | 'same-origin';
ENCODE_PATH?: ((path: string) => string) | undefined;
HEADERS?: Headers | Resolver<Headers> | undefined;
PASSWORD?: string | Resolver<string> | undefined;
TOKEN?: string | Resolver<string> | undefined;
USERNAME?: string | Resolver<string> | undefined;
VERSION: string;
WITH_CREDENTIALS: boolean;
CREDENTIALS: 'include' | 'omit' | 'same-origin';
TOKEN?: string | Resolver<string>;
USERNAME?: string | Resolver<string>;
PASSWORD?: string | Resolver<string>;
HEADERS?: Headers | Resolver<Headers>;
ENCODE_PATH?: (path: string) => string;
interceptors: {
request: Interceptors<RequestInit>;
response: Interceptors<Response>;
};
};

export const OpenAPI: OpenAPIConfig = {
BASE: 'http://localhost:8080',
VERSION: '1.0.0-SNAPSHOT+1918.sha.4aaf8e7',
WITH_CREDENTIALS: false,
CREDENTIALS: 'include',
ENCODE_PATH: undefined,
HEADERS: undefined,
PASSWORD: undefined,
TOKEN: undefined,
USERNAME: undefined,
PASSWORD: undefined,
HEADERS: undefined,
ENCODE_PATH: undefined,
VERSION: '0.1.0-SNAPSHOT+001.sha.523cacc',
WITH_CREDENTIALS: false,
interceptors: {
request: new Interceptors(),
response: new Interceptors(),
},
};
Loading

0 comments on commit 74cdc43

Please sign in to comment.