This commit unifies the concepts of executables having same ID structure. It paves the way for more complex ID structure and using IDs in collection files as part of new ID solution (#262). Using string IDs also leads to more expressive test code. This commit also refactors the rest of the code to adopt to the changes. This commit: - Separate concerns from entities for data access (in repositories) and executables. Executables use `Identifiable` meanwhile repositories use `RepositoryEntity`. - Refactor unnecessary generic parameters for enttities and ids, enforcing string gtype everwyhere. - Changes numeric IDs to string IDs for categories to unify the retrieval and construction for executables, using pseudo-ids (their names) just like scripts. - Remove `BaseEntity` for simplicity. - Simplify usage and construction of executable objects. Move factories responsible for creation of category/scripts to domain layer. Do not longer export `CollectionCategorY` and `CollectionScript`. - Use named typed for string IDs for better differentation of different ID contexts in code.
52 lines
1.9 KiB
TypeScript
52 lines
1.9 KiB
TypeScript
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
|
import { OperatingSystem } from '@/domain/OperatingSystem';
|
|
import { AdaptiveFilterContext } from './Filter/AdaptiveFilterContext';
|
|
import { ApplicationCode } from './Code/ApplicationCode';
|
|
import { UserSelectionFacade } from './Selection/UserSelectionFacade';
|
|
import type { FilterContext } from './Filter/FilterContext';
|
|
import type { UserSelection } from './Selection/UserSelection';
|
|
import type { ICategoryCollectionState } from './ICategoryCollectionState';
|
|
import type { IApplicationCode } from './Code/IApplicationCode';
|
|
|
|
export class CategoryCollectionState implements ICategoryCollectionState {
|
|
public readonly os: OperatingSystem;
|
|
|
|
public readonly code: IApplicationCode;
|
|
|
|
public readonly selection: UserSelection;
|
|
|
|
public readonly filter: FilterContext;
|
|
|
|
public constructor(
|
|
public readonly collection: ICategoryCollection,
|
|
selectionFactory = DefaultSelectionFactory,
|
|
codeFactory = DefaultCodeFactory,
|
|
filterFactory = DefaultFilterFactory,
|
|
) {
|
|
this.selection = selectionFactory(collection, []);
|
|
this.code = codeFactory(this.selection.scripts, collection.scripting);
|
|
this.filter = filterFactory(collection);
|
|
this.os = collection.os;
|
|
}
|
|
}
|
|
|
|
export type CodeFactory = (
|
|
...params: ConstructorParameters<typeof ApplicationCode>
|
|
) => IApplicationCode;
|
|
|
|
const DefaultCodeFactory: CodeFactory = (...params) => new ApplicationCode(...params);
|
|
|
|
export type SelectionFactory = (
|
|
...params: ConstructorParameters<typeof UserSelectionFacade>
|
|
) => UserSelection;
|
|
|
|
const DefaultSelectionFactory: SelectionFactory = (
|
|
...params
|
|
) => new UserSelectionFacade(...params);
|
|
|
|
export type FilterFactory = (
|
|
...params: ConstructorParameters<typeof AdaptiveFilterContext>
|
|
) => FilterContext;
|
|
|
|
const DefaultFilterFactory: FilterFactory = (...params) => new AdaptiveFilterContext(...params);
|