Convert runMany and runManySync to use injectManyWithMeta + move to seperate package (#7244)

* Convert runMany and runManySync to use injectManyWithMeta

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup type errors due to new Runnable requirements

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Add documentation for verifyRunnablesAreDAG

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Simplify convertToWithIdWith

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Move all utility functions to separate package

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Move testing utilities to separate package

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Move run-many and run-many-sync to separate package

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Replace all internal uses of utilities with new packages

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Use new @k8slens/run-many package in core

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Add dep to open-lens

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup uses of @k8slens/test-utils

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup getGlobalOverride

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Move tests to new package too

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup uses of AsyncResult and autoBind

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup remaining import issues

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Finial fixups to fix build

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix lint

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Revert moving "testUsingFakeTime" to separate package

- This fixes tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix integration tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix unit test failing due to spelling fix

Signed-off-by: Sebastian Malton <sebastian@malton.name>

---------

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2023-03-10 10:07:28 +02:00
1 parent ad9bafe2a5
commit 2789bcebcb
754 files changed
+2715 -2752

No files matched your search

+16 -15
View File
@@ -15,8 +15,8 @@ import type { PartialDeep, ValueOf } from "type-fest";
import { EventEmitter } from "../../common/event-emitter";
import type { Logger } from "../../common/logger";
import type { Fetch } from "../fetch/fetch.injectable";
import type { Defaulted } from "../utils";
import { json } from "../utils";
import type { Defaulted } from "@k8slens/utilities";
import { isObject, isString, json } from "@k8slens/utilities";
export interface JsonApiData {}
@@ -184,20 +184,17 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
const res = await this.dependencies.fetch(reqUrl, reqInit);
return this.parseResponse<OutData>(res, infoLog);
return await this.parseResponse(res, infoLog) as OutData;
}
protected async parseResponse<OutData>(res: Response, log: JsonApiLog): Promise<OutData> {
protected async parseResponse(res: Response, log: JsonApiLog): Promise<Data> {
const { status } = res;
const text = await res.text();
let data: any;
try {
data = text ? json.parse(text) : ""; // DELETE-requests might not have response-body
} catch (e) {
data = text;
}
const parseResponse = json.parse(text || "{}");
const data = parseResponse.callWasSuccessful
? parseResponse.response as Data
: text as Data;
if (status >= 200 && status < 300) {
this.onData.emit(data, res);
@@ -211,7 +208,7 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
throw data;
}
const error = new JsonApiErrorParsed(data, this.parseError(data, res));
const error = new JsonApiErrorParsed(data as JsonApiError, this.parseError(data, res));
this.onError.emit(error, res);
this.writeLog({ ...log, error });
@@ -219,16 +216,20 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
throw error;
}
protected parseError(error: JsonApiError | string, res: Response): string[] {
if (typeof error === "string") {
protected parseError(error: unknown, res: Response): string[] {
if (isString(error)) {
return [error];
}
if (!isObject(error)) {
return [];
}
if (Array.isArray(error.errors)) {
return error.errors.map(error => error.title);
}
if (error.message) {
if (isString(error.message)) {
return [error.message];
}