Files
privacy.sexy/src/domain/Application.ts
undergroundwires a721e82a4f Bump TypeScript to 5.3 with verbatimModuleSyntax
This commit upgrades TypeScript to the latest version 5.3 and introduces
`verbatimModuleSyntax` in line with the official Vue guide
recommendatinos (vuejs/docs#2592).

By enforcing `import type` for type-only imports, this commit improves
code clarity and supports tooling optimization, ensuring imports are
only bundled when necessary for runtime.

Changes:

- Bump TypeScript to 5.3.3 across the project.
- Adjust import statements to utilize `import type` where applicable,
  promoting cleaner and more efficient code.
2024-02-27 04:20:22 +01:00

45 lines
1.5 KiB
TypeScript

import { OperatingSystem } from './OperatingSystem';
import type { IApplication } from './IApplication';
import type { ICategoryCollection } from './ICategoryCollection';
import type { ProjectDetails } from './Project/ProjectDetails';
export class Application implements IApplication {
constructor(
public projectDetails: ProjectDetails,
public collections: readonly ICategoryCollection[],
) {
validateCollections(collections);
}
public getSupportedOsList(): OperatingSystem[] {
return this.collections.map((collection) => collection.os);
}
public getCollection(operatingSystem: OperatingSystem): ICategoryCollection {
const collection = this.collections.find((c) => c.os === operatingSystem);
if (!collection) {
throw new Error(`Operating system "${OperatingSystem[operatingSystem]}" is not defined in application`);
}
return collection;
}
}
function validateCollections(collections: readonly ICategoryCollection[]) {
if (!collections.length) {
throw new Error('missing collections');
}
if (collections.filter((c) => !c).length > 0) {
throw new Error('missing collection in the list');
}
const osList = collections.map((c) => c.os);
const duplicates = getDuplicates(osList);
if (duplicates.length > 0) {
throw new Error(`multiple collections with same os: ${
duplicates.map((os) => OperatingSystem[os].toLowerCase()).join('", "')}`);
}
}
function getDuplicates(list: readonly OperatingSystem[]): OperatingSystem[] {
return list.filter((os, index) => list.indexOf(os) !== index);
}