Skip to content

Commit

Permalink
fix: ts errors
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackDark committed Apr 1, 2024
1 parent 781e2f5 commit 38cda51
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 167 deletions.
10 changes: 5 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const pipeline = async (value: YamlConfigInstance, arrType: ArrType) => {
console.log("DryRun: Would update QualityDefinitions.");
} else {
console.log(`Diffs in quality definitions found`, changeMap.values());
await api.v3QualitydefinitionUpdateUpdate(restData);
await api.v3QualitydefinitionUpdateUpdate(restData as any); // Ignore types
console.log(`Updated QualityDefinitions`);
}
} else {
Expand Down Expand Up @@ -173,9 +173,9 @@ const pipeline = async (value: YamlConfigInstance, arrType: ArrType) => {
if (!IS_DRY_RUN) {
for (const element of create) {
try {
const newProfile = await api.v3QualityprofileCreate(element);
const newProfile = await api.v3QualityprofileCreate(element as any); // Ignore types
console.log(`Created QualityProfile: ${newProfile.data.name}`);
} catch (error) {
} catch (error: any) {
let message;

if (error.response) {
Expand All @@ -199,9 +199,9 @@ const pipeline = async (value: YamlConfigInstance, arrType: ArrType) => {

for (const element of changedQPs) {
try {
const newProfile = await api.v3QualityprofileUpdate("" + element.id, element);
const newProfile = await api.v3QualityprofileUpdate("" + element.id, element as any); // Ignore types
console.log(`Updated QualityProfile: ${newProfile.data.name}`);
} catch (error) {
} catch (error: any) {
let message;

if (error.response) {
Expand Down
9 changes: 2 additions & 7 deletions src/__generated__/generated-radarr-api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions src/__generated__/generated-sonarr-api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const configureSonarrApi = async (url: string, apiKey: string) => {

try {
await sonarrClient.v3MetadataList();
} catch (error) {
} catch (error: any) {
let message;

if (error.response) {
Expand Down Expand Up @@ -102,7 +102,7 @@ export const configureRadarrApi = async (url: string, apiKey: string) => {

try {
await radarrClient.v3MetadataList();
} catch (error) {
} catch (error: any) {
let message;

if (error.response) {
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ let config: YamlConfig;
let secrets: any;

const secretsTag = {
identify: (value) => value instanceof String,
identify: (value: any) => value instanceof String,
tag: "!secret",
resolve(str) {
resolve(str: string) {
return getSecrets()[str];
},
};
Expand Down
10 changes: 5 additions & 5 deletions src/custom-formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CustomFormatResource } from "./__generated__/generated-sonarr-api";
import { getArrApi } from "./api";
import { getConfig } from "./config";
import { CFProcessing, ConfigarrCF, DynamicImportType, TrashCF, YamlInput } from "./types";
import { IS_DRY_RUN, IS_LOCAL_SAMPLE_MODE, carrCfToValidCf, compareObjectsCarr, toCarrCF } from "./util";
import { IS_DRY_RUN, IS_LOCAL_SAMPLE_MODE, compareObjectsCarr, mapImportCfToRequestCf, toCarrCF } from "./util";

export const deleteAllCustomFormats = async () => {
const api = getArrApi();
Expand All @@ -26,7 +26,7 @@ export const loadServerCustomFormats = async (): Promise<CustomFormatResource[]>
};

export const manageCf = async (cfProcessing: CFProcessing, serverCfs: Map<string, CustomFormatResource>, cfsToManage: Set<string>) => {
const { carrIdMapping: trashIdToObject, cfNameToCarrConfig: existingCfToObject } = cfProcessing;
const { carrIdMapping: trashIdToObject } = cfProcessing;

const api = getArrApi();

Expand Down Expand Up @@ -57,7 +57,7 @@ export const manageCf = async (cfProcessing: CFProcessing, serverCfs: Map<string
});
console.log(`Updated CF ${tr.requestConfig.name}`);
}
} catch (err) {
} catch (err: any) {
console.log(`Failed updating CF ${tr.requestConfig.name}`, err.response.data);
}
} else {
Expand All @@ -72,7 +72,7 @@ export const manageCf = async (cfProcessing: CFProcessing, serverCfs: Map<string
const createResult = await api.v3CustomformatCreate(tr.requestConfig);
console.log(`Created CF ${tr.requestConfig.name}`);
}
} catch (err) {
} catch (err: any) {
throw new Error(`Failed creating CF '${tr.requestConfig.name}'. Message: ${err.response.data?.message}`);
}
}
Expand Down Expand Up @@ -109,7 +109,7 @@ export const loadLocalCfs = async (): Promise<CFProcessing | null> => {

carrIdToObject.set(cfD.configarr_id, {
carrConfig: cfD,
requestConfig: carrCfToValidCf(cfD),
requestConfig: mapImportCfToRequestCf(cfD),
});

if (cfD.name) {
Expand Down
86 changes: 78 additions & 8 deletions src/example.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,78 @@
import { describe, expect, test } from "vitest";
import { CustomFormatResource, PrivacyLevel, QualityDefinitionResource, QualitySource } from "./__generated__/MySuperbApi";
import { calculateQualityDefinitionDiff, loadQualityDefinitionFromSonarr } from "./qualityDefinition";
import { CustomFormatResource, PrivacyLevel, QualityDefinitionResource, QualitySource } from "./__generated__/generated-sonarr-api";
import { calculateQualityDefinitionDiff, loadQualityDefinitionFromServer } from "./quality-definitions";
import { TrashCF, TrashCFSpF, TrashQualityDefintion } from "./types";
import { carrCfToValidCf, compareObjectsCarr, toCarrCF } from "./util";
import { compareObjectsCarr, mapImportCfToRequestCf, toCarrCF } from "./util";

const exampleCFImplementations = {
name: "TestSpec",
includeCustomFormatWhenRenaming: false,
specifications: [
{
name: "ReleaseTitleSpec",
implementation: "ReleaseTitleSpecification",
negate: false,
required: false,
fields: {
value: "expres",
},
},
{
name: "LanguageUnknown",
implementation: "LanguageSpecification",
negate: false,
required: false,
fields: {
value: 0,
},
},
{
name: "LanguageOrgi",
implementation: "LanguageSpecification",
negate: false,
required: false,
fields: {
value: -2,
},
},
{
name: "IndexerFlag",
implementation: "IndexerFlagSpecification",
negate: false,
required: false,
fields: {
value: 1,
},
},
{
name: "SourceSpec",
implementation: "SourceSpecification",
negate: false,
required: false,
fields: {
value: 6,
},
},
{
name: "Resolution",
implementation: "ResolutionSpecification",
negate: false,
required: false,
fields: {
value: 540,
},
},
{
name: "ReleaseGroup",
implementation: "ReleaseGroupSpecification",
negate: false,
required: false,
fields: {
value: "regex",
},
},
],
};

describe("SizeSpecification", async () => {
const serverResponse: CustomFormatResource = {
Expand Down Expand Up @@ -72,31 +142,31 @@ describe("SizeSpecification", async () => {
test("equal", async () => {
const copied: typeof custom = JSON.parse(JSON.stringify(custom));

const result = compareObjectsCarr(serverResponse, carrCfToValidCf(toCarrCF(copied)));
const result = compareObjectsCarr(serverResponse, mapImportCfToRequestCf(toCarrCF(copied)));
expect(result.equal).toBe(true);
});

test("mismatch negate", async () => {
const copied = JSON.parse(JSON.stringify(custom));
copied.specifications![0].negate = true;

const result = compareObjectsCarr(serverResponse, carrCfToValidCf(toCarrCF(copied)));
const result = compareObjectsCarr(serverResponse, mapImportCfToRequestCf(toCarrCF(copied)));
expect(result.equal).toBe(false);
});

test("mismatch required", async () => {
const copied: typeof custom = JSON.parse(JSON.stringify(custom));
copied.specifications![0].required = true;

const result = compareObjectsCarr(serverResponse, carrCfToValidCf(toCarrCF(copied)));
const result = compareObjectsCarr(serverResponse, mapImportCfToRequestCf(toCarrCF(copied)));
expect(result.equal).toBe(false);
});

test("max differ", async () => {
const copied: typeof custom = JSON.parse(JSON.stringify(custom));
(copied.specifications![0].fields as TrashCFSpF).max = 100;

const result = compareObjectsCarr(serverResponse, carrCfToValidCf(toCarrCF(copied)));
const result = compareObjectsCarr(serverResponse, mapImportCfToRequestCf(toCarrCF(copied)));
expect(result.equal).toBe(false);
});
});
Expand Down Expand Up @@ -146,7 +216,7 @@ describe("QualityDefinitions", async () => {
],
};
test("test import", async ({}) => {
const result = await loadQualityDefinitionFromSonarr();
const result = await loadQualityDefinitionFromServer();

console.log(result);
});
Expand Down
2 changes: 1 addition & 1 deletion src/quality-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const loadQualityDefinitionFromServer = async (): Promise<QualityDefiniti
if (IS_LOCAL_SAMPLE_MODE) {
return (await import(path.resolve("./tests/samples/qualityDefinition.json"))).default;
}
return (await getArrApi().v3QualitydefinitionList()).data;
return (await getArrApi().v3QualitydefinitionList()).data as QualityDefinitionResource[];
};

export const calculateQualityDefinitionDiff = (serverQDs: QualityDefinitionResource[], trashQD: TrashQualityDefintion) => {
Expand Down
2 changes: 1 addition & 1 deletion src/quality-profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const loadQualityProfilesFromServer = async (): Promise<QualityProfileRes
const api = getArrApi();

const qualityProfiles = await api.v3QualityprofileList();
return qualityProfiles.data;
return qualityProfiles.data as QualityProfileResource[];
};

const mapQualities = (qd: QualityDefinitionResource[], value: YamlConfigQualityProfile) => {
Expand Down
4 changes: 2 additions & 2 deletions src/trash-guide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
TrashCF,
TrashQualityDefintion,
} from "./types";
import { carrCfToValidCf, toCarrCF, trashRepoPaths } from "./util";
import { mapImportCfToRequestCf, toCarrCF, trashRepoPaths } from "./util";

const DEFAULT_TRASH_GIT_URL = "https://github.com/TRaSH-Guides/Guides";

Expand Down Expand Up @@ -70,7 +70,7 @@ export const loadSonarrTrashCFs = async (arrType: ArrType): Promise<CFProcessing

carrIdToObject.set(carrConfig.configarr_id, {
carrConfig: carrConfig,
requestConfig: carrCfToValidCf(carrConfig),
requestConfig: mapImportCfToRequestCf(carrConfig),
});

if (carrConfig.name) {
Expand Down
22 changes: 18 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ export type UserFriendlyField = {

export type TrashCFSpF = { min: number; max: number };

/*
Language values:
0 = Unknown
-2 = Original
*/
export type CustomFormatImportImplementation =
| "ReleaseTitleSpecification" // Value string
| "LanguageSpecification" // value number
| "SizeSpecification" // special
| "IndexerFlagSpecification" // value number
| "SourceSpecification" // value number
| "ResolutionSpecification" // value number
| "ReleaseGroupSpecification"; // value string

export type TC1 = Omit<CustomFormatSpecificationSchema, "fields"> & {
implementation: "ReleaseTitleSpecification" | "LanguageSpecification";
fields?: UserFriendlyField | null;
Expand All @@ -22,7 +36,7 @@ export type TC2 = Omit<CustomFormatSpecificationSchema, "fields"> & {

export type TCM = TC1 | TC2;

export type TrashCFResource = Omit<CustomFormatResource, "specifications"> & {
export type ImportCF = Omit<CustomFormatResource, "specifications"> & {
specifications?: TCM[] | null;
};

Expand All @@ -42,12 +56,12 @@ export type TrashCF = {
};
trash_regex?: string;
trash_description?: string;
} & TrashCFResource;
} & ImportCF;

export type ConfigarrCF = {
configarr_id: string;
configarr_scores?: TrashCF["trash_scores"];
} & TrashCFResource;
} & ImportCF;

export type CFProcessing = {
carrIdMapping: Map<
Expand Down Expand Up @@ -105,7 +119,7 @@ export type YamlConfigQualityProfile = {
until_score: number;
};
min_format_score: number;
score_set: string;
score_set: keyof TrashCF["trash_scores"];
quality_sort: string;
qualities: YamlConfigQualityProfileItems[];
};
Expand Down
Loading

0 comments on commit 38cda51

Please sign in to comment.